1
/* Copyright (C) 2000-2003 DRIZZLE AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
This file defines the client API to DRIZZLE and also the ABI of the
18
dynamically linked libdrizzleclient.
20
The ABI should never be changed in a released product of MySQL
21
thus you need to take great care when changing the file. In case
22
the file is changed so the ABI is broken, you must also
23
update the SHAREDLIB_MAJOR_VERSION in configure.in .
34
#ifndef _global_h /* If not standard header */
35
#include <sys/types.h>
37
#include <winsock2.h> /* For windows */
42
#ifndef my_socket_defined
43
typedef int my_socket;
44
#endif /* my_socket_defined */
45
#endif /* _global_h */
47
#include "drizzle_version.h"
48
#include "drizzle_com.h"
49
#include "drizzle_time.h"
51
#include "my_list.h" /* for LISTs used in 'MYSQL' */
53
extern unsigned int drizzle_port;
54
extern char *drizzle_unix_port;
56
#define CLIENT_NET_READ_TIMEOUT 365*24*3600 /* Timeout on read */
57
#define CLIENT_NET_WRITE_TIMEOUT 365*24*3600 /* Timeout on write */
59
#define IS_PRI_KEY(n) ((n) & PRI_KEY_FLAG)
60
#define IS_NOT_NULL(n) ((n) & NOT_NULL_FLAG)
61
#define IS_BLOB(n) ((n) & BLOB_FLAG)
62
#define IS_NUM(t) ((t) <= MYSQL_TYPE_LONGLONG || (t) == MYSQL_TYPE_YEAR || (t) == MYSQL_TYPE_NEWDECIMAL)
63
#define IS_NUM_FIELD(f) ((f)->flags & NUM_FLAG)
64
#define INTERNAL_NUM_FIELD(f) (((f)->type <= MYSQL_TYPE_LONGLONG && ((f)->type != MYSQL_TYPE_TIMESTAMP || (f)->length == 14 || (f)->length == 8)) || (f)->type == MYSQL_TYPE_YEAR)
65
#define IS_LONGDATA(t) ((t) >= MYSQL_TYPE_TINY_BLOB && (t) <= MYSQL_TYPE_STRING)
68
typedef struct st_drizzle_field {
69
char *name; /* Name of column */
70
char *org_name; /* Original column name, if an alias */
71
char *table; /* Table of column if column was a field */
72
char *org_table; /* Org table name, if table was an alias */
73
char *db; /* Database for table */
74
char *catalog; /* Catalog for table */
75
char *def; /* Default value (set by drizzle_list_fields) */
76
unsigned long length; /* Width of column (create length) */
77
unsigned long max_length; /* Max width for selected set */
78
unsigned int name_length;
79
unsigned int org_name_length;
80
unsigned int table_length;
81
unsigned int org_table_length;
82
unsigned int db_length;
83
unsigned int catalog_length;
84
unsigned int def_length;
85
unsigned int flags; /* Div flags */
86
unsigned int decimals; /* Number of decimals in field */
87
unsigned int charsetnr; /* Character set */
88
enum enum_field_types type; /* Type of field. See drizzle_com.h for types */
92
typedef char **DRIZZLE_ROW; /* return data as array of strings */
93
typedef unsigned int DRIZZLE_FIELD_OFFSET; /* offset to current field */
97
#define DRIZZLE_COUNT_ERROR (~(uint64_t) 0)
99
/* backward compatibility define - to be removed eventually */
100
#define ER_WARN_DATA_TRUNCATED WARN_DATA_TRUNCATED
102
typedef struct st_drizzle_rows {
103
struct st_drizzle_rows *next; /* list of rows */
105
unsigned long length;
108
typedef DRIZZLE_ROWS *DRIZZLE_ROW_OFFSET; /* offset to current row */
110
#include "my_alloc.h"
112
typedef struct embedded_query_result EMBEDDED_QUERY_RESULT;
113
typedef struct st_drizzle_data {
115
struct embedded_query_result *embedded_info;
119
/* extra info for embedded library */
125
DRIZZLE_OPT_CONNECT_TIMEOUT, DRIZZLE_OPT_COMPRESS, DRIZZLE_OPT_NAMED_PIPE,
126
DRIZZLE_INIT_COMMAND, DRIZZLE_READ_DEFAULT_FILE, DRIZZLE_READ_DEFAULT_GROUP,
127
DRIZZLE_SET_CHARSET_DIR, DRIZZLE_SET_CHARSET_NAME, DRIZZLE_OPT_LOCAL_INFILE,
128
DRIZZLE_OPT_PROTOCOL, DRIZZLE_SHARED_MEMORY_BASE_NAME, DRIZZLE_OPT_READ_TIMEOUT,
129
DRIZZLE_OPT_WRITE_TIMEOUT, DRIZZLE_OPT_USE_RESULT,
130
DRIZZLE_OPT_USE_REMOTE_CONNECTION, DRIZZLE_OPT_USE_EMBEDDED_CONNECTION,
131
DRIZZLE_OPT_GUESS_CONNECTION, DRIZZLE_SET_CLIENT_IP, DRIZZLE_SECURE_AUTH,
132
DRIZZLE_REPORT_DATA_TRUNCATION, DRIZZLE_OPT_RECONNECT,
133
DRIZZLE_OPT_SSL_VERIFY_SERVER_CERT
136
struct st_drizzle_options {
137
unsigned int connect_timeout, read_timeout, write_timeout;
138
unsigned int port, protocol;
139
unsigned long client_flag;
140
char *host,*user,*password,*unix_socket,*db;
141
struct st_dynamic_array *init_commands;
142
char *my_cnf_file,*my_cnf_group, *charset_dir, *charset_name;
143
char *ssl_key; /* PEM key file */
144
char *ssl_cert; /* PEM cert file */
145
char *ssl_ca; /* PEM CA file */
146
char *ssl_capath; /* PEM directory of CA-s? */
147
char *ssl_cipher; /* cipher to use */
148
char *shared_memory_base_name;
149
unsigned long max_allowed_packet;
150
my_bool use_ssl; /* if to use SSL or not */
151
my_bool compress,named_pipe;
156
enum drizzle_option methods_to_use;
158
/* Refuse client connecting to server if it uses old (pre-4.1.1) protocol */
160
/* 0 - never report, 1 - always report (default) */
161
my_bool report_data_truncation;
163
/* function pointers for local infile support */
164
int (*local_infile_init)(void **, const char *, void *);
165
int (*local_infile_read)(void *, char *, unsigned int);
166
void (*local_infile_end)(void *);
167
int (*local_infile_error)(void *, char *, unsigned int);
168
void *local_infile_userdata;
174
DRIZZLE_STATUS_READY,DRIZZLE_STATUS_GET_RESULT,DRIZZLE_STATUS_USE_RESULT
177
enum drizzle_protocol_type
179
DRIZZLE_PROTOCOL_DEFAULT, DRIZZLE_PROTOCOL_TCP, DRIZZLE_PROTOCOL_SOCKET,
180
DRIZZLE_PROTOCOL_PIPE, DRIZZLE_PROTOCOL_MEMORY
183
typedef struct character_set
185
unsigned int number; /* character set number */
186
unsigned int state; /* character set state */
187
const char *csname; /* collation name */
188
const char *name; /* character set name */
189
const char *comment; /* comment */
190
const char *dir; /* character set directory */
191
unsigned int mbminlen; /* min. length for multibyte strings */
192
unsigned int mbmaxlen; /* max. length for multibyte strings */
195
struct st_drizzle_methods;
196
struct st_drizzle_stmt;
198
typedef struct st_drizzle
200
NET net; /* Communication parameters */
201
unsigned char *connector_fd; /* ConnectorFd for SSL */
202
char *host,*user,*passwd,*unix_socket,*server_version,*host_info;
204
struct charset_info_st *charset;
205
DRIZZLE_FIELD *fields;
206
MEM_ROOT field_alloc;
207
uint64_t affected_rows;
208
uint64_t insert_id; /* id if insert on table with NEXTNR */
209
uint64_t extra_info; /* Not used */
210
uint32_t thread_id; /* Id for connection in server */
211
uint32_t packet_length;
213
uint32_t client_flag,server_capabilities;
214
uint32_t protocol_version;
215
uint32_t field_count;
216
uint32_t server_status;
217
uint32_t server_language;
218
uint32_t warning_count;
219
struct st_drizzle_options options;
220
enum drizzle_status status;
221
bool free_me; /* If free in drizzle_close */
222
bool reconnect; /* set to 1 if automatic reconnect */
224
/* session-wide random string */
225
char scramble[SCRAMBLE_LENGTH+1];
227
void *unused2, *unused3, *unused4, *unused5;
229
LIST *stmts; /* list of all statements */
230
const struct st_drizzle_methods *methods;
233
Points to boolean flag in DRIZZLE_RES or MYSQL_STMT. We set this flag
234
from drizzle_stmt_close if close had to cancel result set of this object.
236
bool *unbuffered_fetch_owner;
237
/* needed for embedded server - no net buffer to store the 'info' */
243
typedef struct st_drizzle_res {
245
DRIZZLE_FIELD *fields;
247
DRIZZLE_ROWS *data_cursor;
248
uint32_t *lengths; /* column lengths of current row */
249
DRIZZLE *handle; /* for unbuffered reads */
250
const struct st_drizzle_methods *methods;
251
DRIZZLE_ROW row; /* If unbuffered read */
252
DRIZZLE_ROW current_row; /* buffer to current row */
253
MEM_ROOT field_alloc;
254
uint32_t field_count, current_field;
255
bool eof; /* Used by drizzle_fetch_row */
256
/* drizzle_stmt_close() had to cancel this result */
257
bool unbuffered_fetch_cancelled;
262
#if !defined(MYSQL_SERVER) && !defined(MYSQL_CLIENT)
267
typedef struct st_drizzle_parameters
269
uint32_t *p_max_allowed_packet;
270
uint32_t *p_net_buffer_length;
272
} DRIZZLE_PARAMETERS;
274
#if !defined(MYSQL_SERVER)
275
#define max_allowed_packet (*drizzle_get_parameters()->p_max_allowed_packet)
276
#define net_buffer_length (*drizzle_get_parameters()->p_net_buffer_length)
280
Set up and bring down the server; to ensure that applications will
281
work when linked against either the standard client library or the
282
embedded server library, these functions should be called.
284
void STDCALL drizzle_server_end(void);
287
drizzle_server_init/end need to be called when using libdrizzle or
288
libdrizzleclient (exactly, drizzle_server_init() is called by drizzle_init() so
289
you don't need to call it explicitely; but you need to call
290
drizzle_server_end() to free memory). The names are a bit misleading
291
(drizzle_SERVER* to be used when using libdrizzleCLIENT). So we add more general
292
names which suit well whether you're using libdrizzled or libdrizzleclient. We
293
intend to promote these aliases over the drizzle_server* ones.
295
#define drizzle_library_end drizzle_server_end
297
DRIZZLE_PARAMETERS *STDCALL drizzle_get_parameters(void);
300
Set up and bring down a thread; these function should be called
301
for each thread in an application which opens at least one MySQL
302
connection. All uses of the connection(s) should be between these
305
my_bool STDCALL drizzle_thread_init(void);
306
void STDCALL drizzle_thread_end(void);
309
Functions to get information from the DRIZZLE and DRIZZLE_RES structures
310
Should definitely be used if one uses shared libraries.
313
uint64_t STDCALL drizzle_num_rows(DRIZZLE_RES *res);
314
unsigned int STDCALL drizzle_num_fields(DRIZZLE_RES *res);
315
my_bool STDCALL drizzle_eof(DRIZZLE_RES *res);
316
DRIZZLE_FIELD *STDCALL drizzle_fetch_field_direct(DRIZZLE_RES *res,
317
unsigned int fieldnr);
318
DRIZZLE_FIELD * STDCALL drizzle_fetch_fields(DRIZZLE_RES *res);
319
DRIZZLE_ROW_OFFSET STDCALL DRIZZLE_ROW_tell(DRIZZLE_RES *res);
320
DRIZZLE_FIELD_OFFSET STDCALL drizzle_field_tell(DRIZZLE_RES *res);
322
uint32_t STDCALL drizzle_field_count(DRIZZLE *drizzle);
323
uint64_t STDCALL drizzle_affected_rows(DRIZZLE *drizzle);
324
uint64_t STDCALL drizzle_insert_id(DRIZZLE *drizzle);
325
uint32_t STDCALL drizzle_errno(DRIZZLE *drizzle);
326
const char * STDCALL drizzle_error(DRIZZLE *drizzle);
327
const char *STDCALL drizzle_sqlstate(DRIZZLE *drizzle);
328
uint32_t STDCALL drizzle_warning_count(DRIZZLE *drizzle);
329
const char * STDCALL drizzle_info(DRIZZLE *drizzle);
330
uint32_t STDCALL drizzle_thread_id(DRIZZLE *drizzle);
331
const char * STDCALL drizzle_character_set_name(DRIZZLE *drizzle);
332
int32_t STDCALL drizzle_set_character_set(DRIZZLE *drizzle, const char *csname);
334
DRIZZLE * STDCALL drizzle_create(DRIZZLE *drizzle);
335
my_bool STDCALL drizzle_change_user(DRIZZLE *drizzle, const char *user,
336
const char *passwd, const char *db);
337
DRIZZLE * STDCALL drizzle_connect(DRIZZLE *drizzle, const char *host,
342
const char *unix_socket,
343
uint32_t clientflag);
344
int32_t STDCALL drizzle_select_db(DRIZZLE *drizzle, const char *db);
345
int32_t STDCALL drizzle_query(DRIZZLE *drizzle, const char *q);
346
int32_t STDCALL drizzle_send_query(DRIZZLE *drizzle, const char *q, uint32_t length);
347
int32_t STDCALL drizzle_real_query(DRIZZLE *drizzle, const char *q, uint32_t length);
348
DRIZZLE_RES * STDCALL drizzle_store_result(DRIZZLE *drizzle);
349
DRIZZLE_RES * STDCALL drizzle_use_result(DRIZZLE *drizzle);
351
void STDCALL drizzle_get_character_set_info(DRIZZLE *drizzle,
352
MY_CHARSET_INFO *charset);
354
/* local infile support */
356
#define LOCAL_INFILE_ERROR_LEN 512
359
drizzle_set_local_infile_handler(DRIZZLE *drizzle,
360
int (*local_infile_init)(void **, const char *, void *),
361
int (*local_infile_read)(void *, char *, unsigned int),
362
void (*local_infile_end)(void *),int (*local_infile_error)
363
(void *, char*, unsigned int), void *);
366
drizzle_set_local_infile_default(DRIZZLE *drizzle);
368
int32_t STDCALL drizzle_shutdown(DRIZZLE *drizzle, enum drizzle_enum_shutdown_level shutdown_level);
369
int32_t STDCALL drizzle_dump_debug_info(DRIZZLE *drizzle);
370
int32_t STDCALL drizzle_refresh(DRIZZLE *drizzle, uint32_t refresh_options);
371
int32_t STDCALL drizzle_kill(DRIZZLE *drizzle, uint32_t pid);
372
int32_t STDCALL drizzle_set_server_option(DRIZZLE *drizzle, enum enum_drizzle_set_option option);
373
int32_t STDCALL drizzle_ping(DRIZZLE *drizzle);
374
const char * STDCALL drizzle_stat(DRIZZLE *drizzle);
375
const char * STDCALL drizzle_get_server_info(DRIZZLE *drizzle);
376
const char * STDCALL drizzle_get_client_info(void);
377
uint32_t STDCALL drizzle_get_client_version(void);
378
const char * STDCALL drizzle_get_host_info(DRIZZLE *drizzle);
379
uint32_t STDCALL drizzle_get_server_version(DRIZZLE *drizzle);
380
uint32_t STDCALL drizzle_get_proto_info(DRIZZLE *drizzle);
381
DRIZZLE_RES * STDCALL drizzle_list_dbs(DRIZZLE *drizzle,const char *wild);
382
DRIZZLE_RES * STDCALL drizzle_list_tables(DRIZZLE *drizzle,const char *wild);
383
DRIZZLE_RES * STDCALL drizzle_list_processes(DRIZZLE *drizzle);
384
int32_t STDCALL drizzle_options(DRIZZLE *drizzle,enum drizzle_option option, const void *arg);
385
void STDCALL drizzle_free_result(DRIZZLE_RES *result);
386
void STDCALL drizzle_data_seek(DRIZZLE_RES *result, uint64_t offset);
387
DRIZZLE_ROW_OFFSET STDCALL drizzle_row_seek(DRIZZLE_RES *result, DRIZZLE_ROW_OFFSET offset);
388
DRIZZLE_FIELD_OFFSET STDCALL drizzle_field_seek(DRIZZLE_RES *result, DRIZZLE_FIELD_OFFSET offset);
389
DRIZZLE_ROW STDCALL drizzle_fetch_row(DRIZZLE_RES *result);
390
uint32_t * STDCALL drizzle_fetch_lengths(DRIZZLE_RES *result);
391
DRIZZLE_FIELD * STDCALL drizzle_fetch_field(DRIZZLE_RES *result);
392
DRIZZLE_RES * STDCALL drizzle_list_fields(DRIZZLE *drizzle, const char *table, const char *wild);
393
uint32_t STDCALL drizzle_escape_string(char *to,const char *from, uint32_t from_length);
394
uint32_t STDCALL drizzle_hex_string(char *to,const char *from, uint32_t from_length);
395
uint32_t STDCALL drizzle_real_escape_string(DRIZZLE *drizzle, char *to, const char *from, uint32_t length);
396
void STDCALL myodbc_remove_escape(DRIZZLE *drizzle,char *name);
397
uint32_t STDCALL drizzle_thread_safe(void);
398
my_bool STDCALL drizzle_embedded(void);
399
my_bool STDCALL drizzle_read_query_result(DRIZZLE *drizzle);
403
typedef struct st_drizzle_methods
405
bool (*read_query_result)(DRIZZLE *drizzle);
406
bool (*advanced_command)(DRIZZLE *drizzle,
407
enum enum_server_command command,
408
const unsigned char *header,
409
uint32_t header_length,
410
const unsigned char *arg,
413
DRIZZLE_DATA *(*read_rows)(DRIZZLE *drizzle,DRIZZLE_FIELD *drizzle_fields, uint32_t fields);
414
DRIZZLE_RES * (*use_result)(DRIZZLE *drizzle);
415
void (*fetch_lengths)(uint32_t *to, DRIZZLE_ROW column, uint32_t field_count);
416
void (*flush_use_result)(DRIZZLE *drizzle);
417
DRIZZLE_FIELD * (*list_fields)(DRIZZLE *drizzle);
418
int32_t (*unbuffered_fetch)(DRIZZLE *drizzle, char **row);
419
const char *(*read_statistics)(DRIZZLE *drizzle);
420
bool (*next_result)(DRIZZLE *drizzle);
421
int32_t (*read_change_user_result)(DRIZZLE *drizzle, char *buff, const char *passwd);
425
my_bool STDCALL drizzle_commit(DRIZZLE *drizzle);
426
my_bool STDCALL drizzle_rollback(DRIZZLE *drizzle);
427
my_bool STDCALL drizzle_autocommit(DRIZZLE *drizzle, my_bool auto_mode);
428
my_bool STDCALL drizzle_more_results(DRIZZLE *drizzle);
429
int STDCALL drizzle_next_result(DRIZZLE *drizzle);
430
void STDCALL drizzle_close(DRIZZLE *sock);
433
/* status return codes */
434
#define DRIZZLE_NO_DATA 100
435
#define DRIZZLE_DATA_TRUNCATED 101
437
#define drizzle_reload(drizzle) drizzle_refresh((drizzle),REFRESH_GRANT)
440
The following functions are mainly exported because of binlog;
441
They are not for general usage
444
#define simple_command(drizzle, command, arg, length, skip_check) \
445
(*(drizzle)->methods->advanced_command)(drizzle, command, 0, \
446
0, arg, length, skip_check)
452
#endif /* _drizzle_h */