23
23
dynamically linked libdrizzleclient.
25
25
In case the file is changed so the ABI is broken, you must also
26
update the SHAREDLIB_MAJOR_VERSION in configure.ac.
26
update the SHARED_LIB_MAJOR_VERSION in configure.ac.
30
#ifndef _libdrizzle_drizzle_h
31
#define _libdrizzle_drizzle_h
30
#ifndef _libdrizzle_libdrizzle_h
31
#define _libdrizzle_libdrizzle_h
38
* @TODO cleanup global.h and include only the necessary stuff here...
41
#ifndef DRIZZLE_SERVER_GLOBAL_H /* If not standard header */
42
#include <sys/types.h>
43
#endif /* DRIZZLE_SERVER_GLOBAL_H */
45
37
#include <libdrizzle/drizzle_com.h>
47
39
extern unsigned int drizzle_port;
48
extern char *drizzle_unix_port;
50
41
#define CLIENT_NET_READ_TIMEOUT 365*24*3600 /* Timeout on read */
51
42
#define CLIENT_NET_WRITE_TIMEOUT 365*24*3600 /* Timeout on write */
53
#define IS_PRI_KEY(n) ((n) & PRI_KEY_FLAG)
54
#define IS_NOT_NULL(n) ((n) & NOT_NULL_FLAG)
55
#define IS_BLOB(n) ((n) & BLOB_FLAG)
56
#define IS_NUM(t) ((t) <= DRIZZLE_TYPE_LONGLONG || (t) == DRIZZLE_TYPE_NEWDECIMAL)
57
#define IS_NUM_FIELD(f) ((f)->flags & NUM_FLAG)
58
#define INTERNAL_NUM_FIELD(f) (((f)->type <= DRIZZLE_TYPE_LONGLONG && ((f)->type != DRIZZLE_TYPE_TIMESTAMP || (f)->length == 14 || (f)->length == 8)))
59
#define IS_LONGDATA(t) ((t) == DRIZZLE_TYPE_TINY_BLOB)
62
typedef struct st_drizzle_field {
63
char *name; /* Name of column */
64
char *org_name; /* Original column name, if an alias */
65
char *table; /* Table of column if column was a field */
66
char *org_table; /* Org table name, if table was an alias */
67
char *db; /* Database for table */
68
char *catalog; /* Catalog for table */
69
char *def; /* Default value (set by drizzle_list_fields) */
70
uint32_t length; /* Width of column (create length) */
71
uint32_t max_length; /* Max width for selected set */
72
unsigned int name_length;
73
unsigned int org_name_length;
74
unsigned int table_length;
75
unsigned int org_table_length;
76
unsigned int db_length;
77
unsigned int catalog_length;
78
unsigned int def_length;
79
unsigned int flags; /* Div flags */
80
unsigned int decimals; /* Number of decimals in field */
81
unsigned int charsetnr; /* Character set */
82
enum enum_field_types type; /* Type of field. See drizzle_com.h for types */
86
typedef char **DRIZZLE_ROW; /* return data as array of strings */
87
typedef unsigned int DRIZZLE_FIELD_OFFSET; /* offset to current field */
90
#define DRIZZLE_COUNT_ERROR (~(uint64_t) 0)
92
typedef struct st_drizzle_rows {
93
struct st_drizzle_rows *next; /* list of rows */
98
typedef DRIZZLE_ROWS *DRIZZLE_ROW_OFFSET; /* offset to current row */
100
typedef struct st_drizzle_data {
102
struct embedded_query_result *embedded_info;
105
/* extra info for embedded library */
111
DRIZZLE_OPT_CONNECT_TIMEOUT, DRIZZLE_OPT_COMPRESS, DRIZZLE_OPT_NAMED_PIPE,
112
DRIZZLE_INIT_COMMAND, DRIZZLE_READ_DEFAULT_FILE, DRIZZLE_READ_DEFAULT_GROUP,
113
DRIZZLE_OPT_LOCAL_INFILE,
114
DRIZZLE_OPT_PROTOCOL, DRIZZLE_SHARED_MEMORY_BASE_NAME, DRIZZLE_OPT_READ_TIMEOUT,
115
DRIZZLE_OPT_WRITE_TIMEOUT, DRIZZLE_OPT_USE_RESULT,
116
DRIZZLE_OPT_USE_REMOTE_CONNECTION,
117
DRIZZLE_OPT_GUESS_CONNECTION, DRIZZLE_SET_CLIENT_IP, DRIZZLE_SECURE_AUTH,
118
DRIZZLE_REPORT_DATA_TRUNCATION, DRIZZLE_OPT_RECONNECT,
119
DRIZZLE_OPT_SSL_VERIFY_SERVER_CERT
122
struct st_drizzle_options {
123
unsigned int connect_timeout, read_timeout, write_timeout;
124
unsigned int port, protocol;
125
unsigned long client_flag;
126
char *host,*user,*password,*db;
127
char *my_cnf_file,*my_cnf_group;
128
char *ssl_key; /* PEM key file */
129
char *ssl_cert; /* PEM cert file */
130
char *ssl_ca; /* PEM CA file */
131
char *ssl_capath; /* PEM directory of CA-s? */
132
char *ssl_cipher; /* cipher to use */
133
char *shared_memory_base_name;
134
unsigned long max_allowed_packet;
135
bool use_ssl; /* if to use SSL or not */
136
bool compress,named_pipe;
141
enum drizzle_option methods_to_use;
143
/* Refuse client connecting to server if it uses old (pre-4.1.1) protocol */
145
/* 0 - never report, 1 - always report (default) */
146
bool report_data_truncation;
148
/* function pointers for local infile support */
149
int (*local_infile_init)(void **, const char *, void *);
150
int (*local_infile_read)(void *, char *, unsigned int);
151
void (*local_infile_end)(void *);
152
int (*local_infile_error)(void *, char *, unsigned int);
153
void *local_infile_userdata;
159
DRIZZLE_STATUS_READY,DRIZZLE_STATUS_GET_RESULT,DRIZZLE_STATUS_USE_RESULT
162
enum drizzle_protocol_type
167
struct st_drizzle_methods;
168
struct st_drizzle_stmt;
170
typedef struct st_drizzle
172
NET net; /* Communication parameters */
173
unsigned char *connector_fd; /* ConnectorFd for SSL */
174
char *host,*user,*passwd,*unix_socket,*server_version,*host_info;
176
DRIZZLE_FIELD *fields;
177
uint64_t affected_rows;
178
uint64_t insert_id; /* id if insert on table with NEXTNR */
179
uint64_t extra_info; /* Not used */
180
uint32_t thread_id; /* Id for connection in server */
181
uint32_t packet_length;
183
uint32_t client_flag,server_capabilities;
184
uint32_t protocol_version;
185
uint32_t field_count;
186
uint32_t server_status;
187
uint32_t server_language;
188
uint32_t warning_count;
189
struct st_drizzle_options options;
190
enum drizzle_status status;
191
bool free_me; /* If free in drizzle_close */
192
bool reconnect; /* set to 1 if automatic reconnect */
194
/* session-wide random string */
195
char scramble[SCRAMBLE_LENGTH+1];
197
void *unused2, *unused3, *unused4, *unused5;
199
const struct st_drizzle_methods *methods;
202
Points to boolean flag in DRIZZLE_RES or DRIZZLE_STMT. We set this flag
203
from drizzle_stmt_close if close had to cancel result set of this object.
205
bool *unbuffered_fetch_owner;
206
/* needed for embedded server - no net buffer to store the 'info' */
212
typedef struct st_drizzle_res {
214
DRIZZLE_FIELD *fields;
216
DRIZZLE_ROWS *data_cursor;
217
uint32_t *lengths; /* column lengths of current row */
218
DRIZZLE *handle; /* for unbuffered reads */
219
const struct st_drizzle_methods *methods;
220
DRIZZLE_ROW row; /* If unbuffered read */
221
DRIZZLE_ROW current_row; /* buffer to current row */
222
uint32_t field_count, current_field;
223
bool eof; /* Used by drizzle_fetch_row */
224
/* drizzle_stmt_close() had to cancel this result */
225
bool unbuffered_fetch_cancelled;
230
#if !defined(DRIZZLE_SERVER) && !defined(DRIZZLE_CLIENT)
231
#define DRIZZLE_CLIENT
235
typedef struct st_drizzle_parameters
237
uint32_t *p_max_allowed_packet;
238
uint32_t *p_net_buffer_length;
240
} DRIZZLE_PARAMETERS;
242
#if !defined(DRIZZLE_SERVER)
243
#define max_allowed_packet (*drizzle_get_parameters()->p_max_allowed_packet)
244
#define net_buffer_length (*drizzle_get_parameters()->p_net_buffer_length)
45
#include <libdrizzle/drizzle_field.h>
46
#include <libdrizzle/drizzle_rows.h>
47
#include <libdrizzle/drizzle_data.h>
48
#include <libdrizzle/drizzle_options.h>
50
#include <libdrizzle/drizzle.h>
51
#include <libdrizzle/drizzle_parameters.h>
52
#include <libdrizzle/drizzle_methods.h>
54
const char * drizzle_get_client_info(void);
55
uint32_t drizzle_get_client_version(void);
56
uint32_t drizzle_escape_string(char *to,const char *from,
57
uint32_t from_length);
58
uint32_t drizzle_hex_string(char *to,const char *from,
59
uint32_t from_length);
248
62
Set up and bring down the server; to ensure that applications will
252
66
void drizzle_server_end(void);
255
drizzle_server_init/end need to be called when using libdrizzle or
256
libdrizzleclient (exactly, drizzle_server_init() is called by drizzle_init() so
257
you don't need to call it explicitely; but you need to call
258
drizzle_server_end() to free memory). The names are a bit misleading
259
(drizzle_SERVER* to be used when using libdrizzleCLIENT). So we add more general
260
names which suit well whether you're using libdrizzled or libdrizzleclient. We
261
intend to promote these aliases over the drizzle_server* ones.
263
#define drizzle_library_end drizzle_server_end
265
const DRIZZLE_PARAMETERS * drizzle_get_parameters(void);
269
Functions to get information from the DRIZZLE and DRIZZLE_RES structures
270
Should definitely be used if one uses shared libraries.
273
uint64_t drizzle_num_rows(const DRIZZLE_RES *res);
274
unsigned int drizzle_num_fields(const DRIZZLE_RES *res);
275
bool drizzle_eof(const DRIZZLE_RES *res);
276
const DRIZZLE_FIELD * drizzle_fetch_field_direct(const DRIZZLE_RES *res,
277
unsigned int fieldnr);
278
const DRIZZLE_FIELD * drizzle_fetch_fields(const DRIZZLE_RES *res);
279
DRIZZLE_ROW_OFFSET drizzle_row_tell(const DRIZZLE_RES *res);
280
DRIZZLE_FIELD_OFFSET drizzle_field_tell(const DRIZZLE_RES *res);
282
uint32_t drizzle_field_count(const DRIZZLE *drizzle);
283
uint64_t drizzle_affected_rows(const DRIZZLE *drizzle);
284
uint64_t drizzle_insert_id(const DRIZZLE *drizzle);
285
uint32_t drizzle_errno(const DRIZZLE *drizzle);
286
const char * drizzle_error(const DRIZZLE *drizzle);
287
const char * drizzle_sqlstate(const DRIZZLE *drizzle);
288
uint32_t drizzle_warning_count(const DRIZZLE *drizzle);
289
const char * drizzle_info(const DRIZZLE *drizzle);
290
uint32_t drizzle_thread_id(const DRIZZLE *drizzle);
291
const char * drizzle_character_set_name(const DRIZZLE *drizzle);
292
int32_t drizzle_set_character_set(DRIZZLE *drizzle, const char *csname);
294
DRIZZLE * drizzle_create(DRIZZLE *drizzle);
295
bool drizzle_change_user(DRIZZLE *drizzle, const char *user,
296
const char *passwd, const char *db);
297
DRIZZLE * drizzle_connect(DRIZZLE *drizzle, const char *host,
302
const char *unix_socket,
303
uint32_t clientflag);
304
int32_t drizzle_select_db(DRIZZLE *drizzle, const char *db);
305
int32_t drizzle_query(DRIZZLE *drizzle, const char *q);
306
int32_t drizzle_send_query(DRIZZLE *drizzle, const char *q, uint32_t length);
307
int32_t drizzle_real_query(DRIZZLE *drizzle, const char *q, uint32_t length);
308
DRIZZLE_RES * drizzle_store_result(DRIZZLE *drizzle);
309
DRIZZLE_RES * drizzle_use_result(DRIZZLE *drizzle);
311
/* local infile support */
313
#define LOCAL_INFILE_ERROR_LEN 512
316
drizzle_set_local_infile_handler(DRIZZLE *drizzle,
317
int (*local_infile_init)(void **, const char *, void *),
318
int (*local_infile_read)(void *, char *, unsigned int),
319
void (*local_infile_end)(void *),int (*local_infile_error)
320
(void *, char*, unsigned int), void *);
323
drizzle_set_local_infile_default(DRIZZLE *drizzle);
325
int32_t drizzle_shutdown(DRIZZLE *drizzle, enum drizzle_enum_shutdown_level shutdown_level);
326
int32_t drizzle_dump_debug_info(DRIZZLE *drizzle);
327
int32_t drizzle_refresh(DRIZZLE *drizzle, uint32_t refresh_options);
328
int32_t drizzle_kill(DRIZZLE *drizzle, uint32_t pid);
329
int32_t drizzle_set_server_option(DRIZZLE *drizzle, enum enum_drizzle_set_option option);
330
int32_t drizzle_ping(DRIZZLE *drizzle);
331
const char * drizzle_stat(DRIZZLE *drizzle);
332
const char * drizzle_get_server_info(const DRIZZLE *drizzle);
333
const char * drizzle_get_client_info(void);
334
uint32_t drizzle_get_client_version(void);
335
const char * drizzle_get_host_info(const DRIZZLE *drizzle);
336
uint32_t drizzle_get_server_version(const DRIZZLE *drizzle);
337
uint32_t drizzle_get_proto_info(const DRIZZLE *drizzle);
338
DRIZZLE_RES * drizzle_list_tables(DRIZZLE *drizzle,const char *wild);
339
DRIZZLE_RES * drizzle_list_processes(DRIZZLE *drizzle);
340
int32_t drizzle_options(DRIZZLE *drizzle,enum drizzle_option option, const void *arg);
341
void drizzle_free_result(DRIZZLE_RES *result);
342
void drizzle_data_seek(DRIZZLE_RES *result, uint64_t offset);
343
DRIZZLE_ROW_OFFSET drizzle_row_seek(DRIZZLE_RES *result, DRIZZLE_ROW_OFFSET offset);
344
DRIZZLE_FIELD_OFFSET drizzle_field_seek(DRIZZLE_RES *result, DRIZZLE_FIELD_OFFSET offset);
345
DRIZZLE_ROW drizzle_fetch_row(DRIZZLE_RES *result);
346
uint32_t * drizzle_fetch_lengths(DRIZZLE_RES *result);
347
DRIZZLE_FIELD * drizzle_fetch_field(DRIZZLE_RES *result);
348
DRIZZLE_RES * drizzle_list_fields(DRIZZLE *drizzle, const char *table, const char *wild);
349
uint32_t drizzle_escape_string(char *to,const char *from, uint32_t from_length);
350
uint32_t drizzle_hex_string(char *to,const char *from, uint32_t from_length);
351
bool drizzle_read_query_result(DRIZZLE *drizzle);
355
typedef struct st_drizzle_methods
357
bool (*read_query_result)(DRIZZLE *drizzle);
358
bool (*advanced_command)(DRIZZLE *drizzle,
359
enum enum_server_command command,
360
const unsigned char *header,
361
uint32_t header_length,
362
const unsigned char *arg,
365
DRIZZLE_DATA *(*read_rows)(DRIZZLE *drizzle,DRIZZLE_FIELD *drizzle_fields, uint32_t fields);
366
DRIZZLE_RES * (*use_result)(DRIZZLE *drizzle);
367
void (*fetch_lengths)(uint32_t *to, DRIZZLE_ROW column, uint32_t field_count);
368
void (*flush_use_result)(DRIZZLE *drizzle);
369
DRIZZLE_FIELD * (*list_fields)(DRIZZLE *drizzle);
370
int32_t (*unbuffered_fetch)(DRIZZLE *drizzle, char **row);
371
const char *(*read_statistics)(DRIZZLE *drizzle);
372
bool (*next_result)(DRIZZLE *drizzle);
373
int32_t (*read_change_user_result)(DRIZZLE *drizzle);
377
bool drizzle_commit(DRIZZLE *drizzle);
378
bool drizzle_rollback(DRIZZLE *drizzle);
379
bool drizzle_autocommit(DRIZZLE *drizzle, bool auto_mode);
380
bool drizzle_more_results(const DRIZZLE *drizzle);
381
int drizzle_next_result(DRIZZLE *drizzle);
382
void drizzle_close(DRIZZLE *sock);
385
/* status return codes */
386
#define DRIZZLE_NO_DATA 100
387
#define DRIZZLE_DATA_TRUNCATED 101
390
#define drizzle_reload(drizzle) drizzle_refresh((drizzle),REFRESH_GRANT)
393
The following functions are mainly exported because of binlog;
394
They are not for general usage
397
#define simple_command(drizzle, command, arg, length, skip_check) \
398
(*(drizzle)->methods->advanced_command)(drizzle, command, 0, \
399
0, arg, length, skip_check)
401
69
#ifdef __cplusplus
405
#endif /* _libdrizzle_drizzle_h */
73
#endif /* _libdrizzle_libdrizzle_h */