~mysql/mysql-server/mysql-6.0

« back to all changes in this revision

Viewing changes to include/mysql.h

  • Committer: bk at mysql
  • Date: 2000-07-31 19:29:14 UTC
  • Revision ID: sp1r-bk@work.mysql.com-20000731192914-08846
Import changeset

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
 
2
   
 
3
   This library is free software; you can redistribute it and/or
 
4
   modify it under the terms of the GNU Library General Public
 
5
   License as published by the Free Software Foundation; either
 
6
   version 2 of the License, or (at your option) any later version.
 
7
   
 
8
   This library is distributed in the hope that it will be useful,
 
9
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
   Library General Public License for more details.
 
12
   
 
13
   You should have received a copy of the GNU Library General Public
 
14
   License along with this library; if not, write to the Free
 
15
   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 
16
   MA 02111-1307, USA */
 
17
 
 
18
/* defines for the libmysql library */
 
19
 
 
20
#ifndef _mysql_h
 
21
#define _mysql_h
 
22
 
 
23
#ifndef MYSQL_SERVER
 
24
#ifdef  __cplusplus
 
25
extern "C" {
 
26
#endif
 
27
#endif
 
28
  
 
29
#ifndef _global_h                               /* If not standard header */
 
30
#include <sys/types.h>
 
31
typedef char my_bool;
 
32
#if (defined(_WIN32) || defined(_WIN64)) && !defined(__WIN__)
 
33
#define __WIN__
 
34
#endif
 
35
#if !defined(__WIN__)
 
36
#define STDCALL
 
37
#else
 
38
#define STDCALL __stdcall
 
39
#endif
 
40
typedef char * gptr;
 
41
 
 
42
#ifndef ST_USED_MEM_DEFINED
 
43
#define ST_USED_MEM_DEFINED
 
44
typedef struct st_used_mem {                    /* struct for once_alloc */
 
45
  struct st_used_mem *next;                     /* Next block in use */
 
46
  unsigned int  left;                           /* memory left in block  */
 
47
  unsigned int  size;                           /* size of block */
 
48
} USED_MEM;
 
49
typedef struct st_mem_root {
 
50
  USED_MEM *free;
 
51
  USED_MEM *used;
 
52
  unsigned int  min_malloc;
 
53
  unsigned int  block_size;
 
54
  void (*error_handler)(void);
 
55
} MEM_ROOT;
 
56
#endif
 
57
 
 
58
#ifndef my_socket_defined
 
59
#ifdef __WIN__
 
60
#define my_socket SOCKET
 
61
#else
 
62
typedef int my_socket;
 
63
#endif
 
64
#endif
 
65
#endif
 
66
#include "mysql_com.h"
 
67
#include "mysql_version.h"
 
68
 
 
69
extern unsigned int mysql_port;
 
70
extern char *mysql_unix_port;
 
71
 
 
72
#define IS_PRI_KEY(n)   ((n) & PRI_KEY_FLAG)
 
73
#define IS_NOT_NULL(n)  ((n) & NOT_NULL_FLAG)
 
74
#define IS_BLOB(n)      ((n) & BLOB_FLAG)
 
75
#define IS_NUM(t)       ((t) <= FIELD_TYPE_INT24 || (t) == FIELD_TYPE_YEAR)
 
76
 
 
77
typedef struct st_mysql_field {
 
78
  char *name;                   /* Name of column */
 
79
  char *table;                  /* Table of column if column was a field */
 
80
  char *def;                    /* Default value (set by mysql_list_fields) */
 
81
  enum enum_field_types type;   /* Type of field. Se mysql_com.h for types */
 
82
  unsigned int length;          /* Width of column */
 
83
  unsigned int max_length;      /* Max width of selected set */
 
84
  unsigned int flags;           /* Div flags */
 
85
  unsigned int decimals;        /* Number of decimals in field */
 
86
} MYSQL_FIELD;
 
87
 
 
88
typedef char **MYSQL_ROW;               /* return data as array of strings */
 
89
typedef unsigned int MYSQL_FIELD_OFFSET; /* offset to current field */
 
90
 
 
91
#if defined(NO_CLIENT_LONG_LONG)
 
92
typedef unsigned long my_ulonglong;
 
93
#elif defined (__WIN__)
 
94
typedef unsigned __int64 my_ulonglong;
 
95
#else
 
96
typedef unsigned long long my_ulonglong;
 
97
#endif
 
98
 
 
99
#define MYSQL_COUNT_ERROR (~(my_ulonglong) 0)
 
100
 
 
101
typedef struct st_mysql_rows {
 
102
  struct st_mysql_rows *next;           /* list of rows */
 
103
  MYSQL_ROW data;
 
104
} MYSQL_ROWS;
 
105
 
 
106
typedef MYSQL_ROWS *MYSQL_ROW_OFFSET;   /* offset to current row */
 
107
 
 
108
typedef struct st_mysql_data {
 
109
  my_ulonglong rows;
 
110
  unsigned int fields;
 
111
  MYSQL_ROWS *data;
 
112
  MEM_ROOT alloc;
 
113
} MYSQL_DATA;
 
114
 
 
115
struct st_mysql_options {
 
116
  unsigned int connect_timeout,client_flag;
 
117
  my_bool compress,named_pipe;
 
118
  unsigned int port;
 
119
  char *host,*init_command,*user,*password,*unix_socket,*db;
 
120
  char *my_cnf_file,*my_cnf_group, *charset_dir, *charset_name;
 
121
  my_bool use_ssl;                              /* if to use SSL or not */
 
122
  char *ssl_key;                                /* PEM key file */
 
123
  char *ssl_cert;                               /* PEM cert file */
 
124
  char *ssl_ca;                                 /* PEM CA file */
 
125
  char *ssl_capath;                             /* PEM directory of CA-s? */
 
126
};
 
127
 
 
128
enum mysql_option { MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS,
 
129
                    MYSQL_OPT_NAMED_PIPE, MYSQL_INIT_COMMAND,
 
130
                    MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP,
 
131
                    MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME};
 
132
 
 
133
enum mysql_status { MYSQL_STATUS_READY,MYSQL_STATUS_GET_RESULT,
 
134
                    MYSQL_STATUS_USE_RESULT};
 
135
 
 
136
typedef struct st_mysql {
 
137
  NET           net;                    /* Communication parameters */
 
138
  gptr          connector_fd;           /* ConnectorFd for SSL */
 
139
  char          *host,*user,*passwd,*unix_socket,*server_version,*host_info,
 
140
                *info,*db;
 
141
  unsigned int  port,client_flag,server_capabilities;
 
142
  unsigned int  protocol_version;
 
143
  unsigned int  field_count;
 
144
  unsigned int  server_status;
 
145
  unsigned long thread_id;              /* Id for connection in server */
 
146
  my_ulonglong affected_rows;
 
147
  my_ulonglong insert_id;               /* id if insert on table with NEXTNR */
 
148
  my_ulonglong extra_info;              /* Used by mysqlshow */
 
149
  unsigned long packet_length;
 
150
  enum mysql_status status;
 
151
  MYSQL_FIELD   *fields;
 
152
  MEM_ROOT      field_alloc;
 
153
  my_bool       free_me;                /* If free in mysql_close */
 
154
  my_bool       reconnect;              /* set to 1 if automatic reconnect */
 
155
  struct st_mysql_options options;
 
156
  char          scramble_buff[9];
 
157
  struct charset_info_st *charset;
 
158
  unsigned int  server_language;
 
159
} MYSQL;
 
160
 
 
161
 
 
162
typedef struct st_mysql_res {
 
163
  my_ulonglong row_count;
 
164
  unsigned int  field_count, current_field;
 
165
  MYSQL_FIELD   *fields;
 
166
  MYSQL_DATA    *data;
 
167
  MYSQL_ROWS    *data_cursor;
 
168
  MEM_ROOT      field_alloc;
 
169
  MYSQL_ROW     row;                    /* If unbuffered read */
 
170
  MYSQL_ROW     current_row;            /* buffer to current row */
 
171
  unsigned long *lengths;               /* column lengths of current row */
 
172
  MYSQL         *handle;                /* for unbuffered reads */
 
173
  my_bool       eof;                    /* Used my mysql_fetch_row */
 
174
} MYSQL_RES;
 
175
 
 
176
/* Functions to get information from the MYSQL and MYSQL_RES structures */
 
177
/* Should definitely be used if one uses shared libraries */
 
178
 
 
179
my_ulonglong STDCALL mysql_num_rows(MYSQL_RES *res);
 
180
unsigned int STDCALL mysql_num_fields(MYSQL_RES *res);
 
181
my_bool STDCALL mysql_eof(MYSQL_RES *res);
 
182
MYSQL_FIELD *STDCALL mysql_fetch_field_direct(MYSQL_RES *res,
 
183
                                              unsigned int fieldnr);
 
184
MYSQL_FIELD * STDCALL mysql_fetch_fields(MYSQL_RES *res);
 
185
MYSQL_ROWS * STDCALL mysql_row_tell(MYSQL_RES *res);
 
186
unsigned int STDCALL mysql_field_tell(MYSQL_RES *res);
 
187
 
 
188
unsigned int STDCALL mysql_field_count(MYSQL *mysql);
 
189
my_ulonglong STDCALL mysql_affected_rows(MYSQL *mysql);
 
190
my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql);
 
191
unsigned int STDCALL mysql_errno(MYSQL *mysql);
 
192
char * STDCALL mysql_error(MYSQL *mysql);
 
193
char * STDCALL mysql_info(MYSQL *mysql);
 
194
unsigned long STDCALL mysql_thread_id(MYSQL *mysql);
 
195
const char * STDCALL mysql_character_set_name(MYSQL *mysql);
 
196
 
 
197
MYSQL *         STDCALL mysql_init(MYSQL *mysql);
 
198
#ifdef HAVE_OPENSSL
 
199
int             STDCALL mysql_ssl_set(MYSQL *mysql, const char *key,
 
200
                                      const char *cert, const char *ca,
 
201
                                      const char *capath);
 
202
char *          STDCALL mysql_ssl_cipher(MYSQL *mysql);
 
203
int             STDCALL mysql_ssl_clear(MYSQL *mysql);
 
204
#endif /* HAVE_OPENSSL */
 
205
MYSQL *         STDCALL mysql_connect(MYSQL *mysql, const char *host,
 
206
                                      const char *user, const char *passwd);
 
207
my_bool         STDCALL mysql_change_user(MYSQL *mysql, const char *user, 
 
208
                                          const char *passwd, const char *db);
 
209
#if MYSQL_VERSION_ID >= 32200
 
210
MYSQL *         STDCALL mysql_real_connect(MYSQL *mysql, const char *host,
 
211
                                           const char *user,
 
212
                                           const char *passwd,
 
213
                                           const char *db,
 
214
                                           unsigned int port,
 
215
                                           const char *unix_socket,
 
216
                                           unsigned int clientflag);
 
217
#else
 
218
MYSQL *         STDCALL mysql_real_connect(MYSQL *mysql, const char *host,
 
219
                                           const char *user,
 
220
                                           const char *passwd,
 
221
                                           unsigned int port,
 
222
                                           const char *unix_socket,
 
223
                                           unsigned int clientflag);
 
224
#endif
 
225
void            STDCALL mysql_close(MYSQL *sock);
 
226
int             STDCALL mysql_select_db(MYSQL *mysql, const char *db);
 
227
int             STDCALL mysql_query(MYSQL *mysql, const char *q);
 
228
int             STDCALL mysql_real_query(MYSQL *mysql, const char *q,
 
229
                                        unsigned int length);
 
230
int             STDCALL mysql_create_db(MYSQL *mysql, const char *DB);
 
231
int             STDCALL mysql_drop_db(MYSQL *mysql, const char *DB);
 
232
int             STDCALL mysql_shutdown(MYSQL *mysql);
 
233
int             STDCALL mysql_dump_debug_info(MYSQL *mysql);
 
234
int             STDCALL mysql_refresh(MYSQL *mysql,
 
235
                                     unsigned int refresh_options);
 
236
int             STDCALL mysql_kill(MYSQL *mysql,unsigned long pid);
 
237
int             STDCALL mysql_ping(MYSQL *mysql);
 
238
char *          STDCALL mysql_stat(MYSQL *mysql);
 
239
char *          STDCALL mysql_get_server_info(MYSQL *mysql);
 
240
char *          STDCALL mysql_get_client_info(void);
 
241
char *          STDCALL mysql_get_host_info(MYSQL *mysql);
 
242
unsigned int    STDCALL mysql_get_proto_info(MYSQL *mysql);
 
243
MYSQL_RES *     STDCALL mysql_list_dbs(MYSQL *mysql,const char *wild);
 
244
MYSQL_RES *     STDCALL mysql_list_tables(MYSQL *mysql,const char *wild);
 
245
MYSQL_RES *     STDCALL mysql_list_fields(MYSQL *mysql, const char *table,
 
246
                                         const char *wild);
 
247
MYSQL_RES *     STDCALL mysql_list_processes(MYSQL *mysql);
 
248
MYSQL_RES *     STDCALL mysql_store_result(MYSQL *mysql);
 
249
MYSQL_RES *     STDCALL mysql_use_result(MYSQL *mysql);
 
250
int             STDCALL mysql_options(MYSQL *mysql,enum mysql_option option,
 
251
                                      const char *arg);
 
252
void            STDCALL mysql_free_result(MYSQL_RES *result);
 
253
void            STDCALL mysql_data_seek(MYSQL_RES *result,
 
254
                                        my_ulonglong offset);
 
255
MYSQL_ROW_OFFSET STDCALL mysql_row_seek(MYSQL_RES *result, MYSQL_ROW_OFFSET);
 
256
MYSQL_FIELD_OFFSET STDCALL mysql_field_seek(MYSQL_RES *result,
 
257
                                           MYSQL_FIELD_OFFSET offset);
 
258
MYSQL_ROW       STDCALL mysql_fetch_row(MYSQL_RES *result);
 
259
unsigned long * STDCALL mysql_fetch_lengths(MYSQL_RES *result);
 
260
MYSQL_FIELD *   STDCALL mysql_fetch_field(MYSQL_RES *result);
 
261
unsigned long   STDCALL mysql_escape_string(char *to,const char *from,
 
262
                                            unsigned long from_length);
 
263
unsigned long STDCALL mysql_real_escape_string(MYSQL *mysql,
 
264
                                               char *to,const char *from,
 
265
                                               unsigned long length);
 
266
void            STDCALL mysql_debug(const char *debug);
 
267
char *          STDCALL mysql_odbc_escape_string(MYSQL *mysql,
 
268
                                                 char *to,
 
269
                                                 unsigned long to_length,
 
270
                                                 const char *from,
 
271
                                                 unsigned long from_length,
 
272
                                                 void *param,
 
273
                                                 char *
 
274
                                                 (*extend_buffer)
 
275
                                                 (void *, char *to,
 
276
                                                  unsigned long *length));
 
277
void            STDCALL myodbc_remove_escape(MYSQL *mysql,char *name);
 
278
unsigned int    STDCALL mysql_thread_safe(void);
 
279
 
 
280
  
 
281
#define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT)
 
282
 
 
283
/* new api functions */
 
284
 
 
285
#define HAVE_MYSQL_REAL_CONNECT
 
286
 
 
287
#ifndef MYSQL_SERVER  
 
288
#ifdef  __cplusplus
 
289
}
 
290
#endif
 
291
#endif
 
292
 
 
293
#endif