1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 MySQL
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
This file defines the client API to DRIZZLE and also the ABI of the
23
dynamically linked libdrizzleclient.
25
In case the file is changed so the ABI is broken, you must also
26
update the SHAREDLIB_MAJOR_VERSION in configure.ac.
30
#ifndef _libdrizzle_drizzle_h
31
#define _libdrizzle_drizzle_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
#include <libdrizzle/drizzle_com.h>
46
#include <libdrizzle/drizzle_time.h>
48
#include <mysys/my_list.h>
50
extern unsigned int drizzle_port;
51
extern char *drizzle_unix_port;
53
#define CLIENT_NET_READ_TIMEOUT 365*24*3600 /* Timeout on read */
54
#define CLIENT_NET_WRITE_TIMEOUT 365*24*3600 /* Timeout on write */
56
#define IS_PRI_KEY(n) ((n) & PRI_KEY_FLAG)
57
#define IS_NOT_NULL(n) ((n) & NOT_NULL_FLAG)
58
#define IS_BLOB(n) ((n) & BLOB_FLAG)
59
#define IS_NUM(t) ((t) <= DRIZZLE_TYPE_LONGLONG || (t) == DRIZZLE_TYPE_NEWDECIMAL)
60
#define IS_NUM_FIELD(f) ((f)->flags & NUM_FLAG)
61
#define INTERNAL_NUM_FIELD(f) (((f)->type <= DRIZZLE_TYPE_LONGLONG && ((f)->type != DRIZZLE_TYPE_TIMESTAMP || (f)->length == 14 || (f)->length == 8)))
62
#define IS_LONGDATA(t) ((t) == DRIZZLE_TYPE_TINY_BLOB)
65
typedef struct st_drizzle_field {
66
char *name; /* Name of column */
67
char *org_name; /* Original column name, if an alias */
68
char *table; /* Table of column if column was a field */
69
char *org_table; /* Org table name, if table was an alias */
70
char *db; /* Database for table */
71
char *catalog; /* Catalog for table */
72
char *def; /* Default value (set by drizzle_list_fields) */
73
uint32_t length; /* Width of column (create length) */
74
uint32_t max_length; /* Max width for selected set */
75
unsigned int name_length;
76
unsigned int org_name_length;
77
unsigned int table_length;
78
unsigned int org_table_length;
79
unsigned int db_length;
80
unsigned int catalog_length;
81
unsigned int def_length;
82
unsigned int flags; /* Div flags */
83
unsigned int decimals; /* Number of decimals in field */
84
unsigned int charsetnr; /* Character set */
85
enum enum_field_types type; /* Type of field. See drizzle_com.h for types */
89
typedef char **DRIZZLE_ROW; /* return data as array of strings */
90
typedef unsigned int DRIZZLE_FIELD_OFFSET; /* offset to current field */
92
#include <mysys/typelib.h>
94
#define DRIZZLE_COUNT_ERROR (~(uint64_t) 0)
96
typedef struct st_drizzle_rows {
97
struct st_drizzle_rows *next; /* list of rows */
102
typedef DRIZZLE_ROWS *DRIZZLE_ROW_OFFSET; /* offset to current row */
104
#include <mysys/my_alloc.h>
106
typedef struct embedded_query_result EMBEDDED_QUERY_RESULT;
107
typedef struct st_drizzle_data {
109
struct embedded_query_result *embedded_info;
113
/* extra info for embedded library */
119
DRIZZLE_OPT_CONNECT_TIMEOUT, DRIZZLE_OPT_COMPRESS, DRIZZLE_OPT_NAMED_PIPE,
120
DRIZZLE_INIT_COMMAND, DRIZZLE_READ_DEFAULT_FILE, DRIZZLE_READ_DEFAULT_GROUP,
121
DRIZZLE_SET_CHARSET_DIR, DRIZZLE_SET_CHARSET_NAME, DRIZZLE_OPT_LOCAL_INFILE,
122
DRIZZLE_OPT_PROTOCOL, DRIZZLE_SHARED_MEMORY_BASE_NAME, DRIZZLE_OPT_READ_TIMEOUT,
123
DRIZZLE_OPT_WRITE_TIMEOUT, DRIZZLE_OPT_USE_RESULT,
124
DRIZZLE_OPT_USE_REMOTE_CONNECTION,
125
DRIZZLE_OPT_GUESS_CONNECTION, DRIZZLE_SET_CLIENT_IP, DRIZZLE_SECURE_AUTH,
126
DRIZZLE_REPORT_DATA_TRUNCATION, DRIZZLE_OPT_RECONNECT,
127
DRIZZLE_OPT_SSL_VERIFY_SERVER_CERT
130
struct st_drizzle_options {
131
unsigned int connect_timeout, read_timeout, write_timeout;
132
unsigned int port, protocol;
133
unsigned long client_flag;
134
char *host,*user,*password,*unix_socket,*db;
135
struct st_dynamic_array *init_commands;
136
char *my_cnf_file,*my_cnf_group, *charset_dir, *charset_name;
137
char *ssl_key; /* PEM key file */
138
char *ssl_cert; /* PEM cert file */
139
char *ssl_ca; /* PEM CA file */
140
char *ssl_capath; /* PEM directory of CA-s? */
141
char *ssl_cipher; /* cipher to use */
142
char *shared_memory_base_name;
143
unsigned long max_allowed_packet;
144
bool use_ssl; /* if to use SSL or not */
145
bool compress,named_pipe;
150
enum drizzle_option methods_to_use;
152
/* Refuse client connecting to server if it uses old (pre-4.1.1) protocol */
154
/* 0 - never report, 1 - always report (default) */
155
bool report_data_truncation;
157
/* function pointers for local infile support */
158
int (*local_infile_init)(void **, const char *, void *);
159
int (*local_infile_read)(void *, char *, unsigned int);
160
void (*local_infile_end)(void *);
161
int (*local_infile_error)(void *, char *, unsigned int);
162
void *local_infile_userdata;
168
DRIZZLE_STATUS_READY,DRIZZLE_STATUS_GET_RESULT,DRIZZLE_STATUS_USE_RESULT
171
enum drizzle_protocol_type
176
typedef struct character_set
178
unsigned int number; /* character set number */
179
unsigned int state; /* character set state */
180
const char *csname; /* collation name */
181
const char *name; /* character set name */
182
const char *comment; /* comment */
183
const char *dir; /* character set directory */
184
unsigned int mbminlen; /* min. length for multibyte strings */
185
unsigned int mbmaxlen; /* max. length for multibyte strings */
188
struct st_drizzle_methods;
189
struct st_drizzle_stmt;
191
typedef struct st_drizzle
193
NET net; /* Communication parameters */
194
unsigned char *connector_fd; /* ConnectorFd for SSL */
195
char *host,*user,*passwd,*unix_socket,*server_version,*host_info;
197
const struct charset_info_st *charset;
198
DRIZZLE_FIELD *fields;
199
MEM_ROOT field_alloc;
200
uint64_t affected_rows;
201
uint64_t insert_id; /* id if insert on table with NEXTNR */
202
uint64_t extra_info; /* Not used */
203
uint32_t thread_id; /* Id for connection in server */
204
uint32_t packet_length;
206
uint32_t client_flag,server_capabilities;
207
uint32_t protocol_version;
208
uint32_t field_count;
209
uint32_t server_status;
210
uint32_t server_language;
211
uint32_t warning_count;
212
struct st_drizzle_options options;
213
enum drizzle_status status;
214
bool free_me; /* If free in drizzle_close */
215
bool reconnect; /* set to 1 if automatic reconnect */
217
/* session-wide random string */
218
char scramble[SCRAMBLE_LENGTH+1];
220
void *unused2, *unused3, *unused4, *unused5;
222
LIST *stmts; /* list of all statements */
223
const struct st_drizzle_methods *methods;
226
Points to boolean flag in DRIZZLE_RES or DRIZZLE_STMT. We set this flag
227
from drizzle_stmt_close if close had to cancel result set of this object.
229
bool *unbuffered_fetch_owner;
230
/* needed for embedded server - no net buffer to store the 'info' */
236
typedef struct st_drizzle_res {
238
DRIZZLE_FIELD *fields;
240
DRIZZLE_ROWS *data_cursor;
241
uint32_t *lengths; /* column lengths of current row */
242
DRIZZLE *handle; /* for unbuffered reads */
243
const struct st_drizzle_methods *methods;
244
DRIZZLE_ROW row; /* If unbuffered read */
245
DRIZZLE_ROW current_row; /* buffer to current row */
246
MEM_ROOT field_alloc;
247
uint32_t field_count, current_field;
248
bool eof; /* Used by drizzle_fetch_row */
249
/* drizzle_stmt_close() had to cancel this result */
250
bool unbuffered_fetch_cancelled;
255
#if !defined(DRIZZLE_SERVER) && !defined(DRIZZLE_CLIENT)
256
#define DRIZZLE_CLIENT
260
typedef struct st_drizzle_parameters
262
uint32_t *p_max_allowed_packet;
263
uint32_t *p_net_buffer_length;
265
} DRIZZLE_PARAMETERS;
267
#if !defined(DRIZZLE_SERVER)
268
#define max_allowed_packet (*drizzle_get_parameters()->p_max_allowed_packet)
269
#define net_buffer_length (*drizzle_get_parameters()->p_net_buffer_length)
273
Set up and bring down the server; to ensure that applications will
274
work when linked against either the standard client library or the
275
embedded server library, these functions should be called.
277
void drizzle_server_end(void);
280
drizzle_server_init/end need to be called when using libdrizzle or
281
libdrizzleclient (exactly, drizzle_server_init() is called by drizzle_init() so
282
you don't need to call it explicitely; but you need to call
283
drizzle_server_end() to free memory). The names are a bit misleading
284
(drizzle_SERVER* to be used when using libdrizzleCLIENT). So we add more general
285
names which suit well whether you're using libdrizzled or libdrizzleclient. We
286
intend to promote these aliases over the drizzle_server* ones.
288
#define drizzle_library_end drizzle_server_end
290
const DRIZZLE_PARAMETERS * drizzle_get_parameters(void);
293
Set up and bring down a thread; these function should be called
294
for each thread in an application which opens at least one MySQL
295
connection. All uses of the connection(s) should be between these
298
bool drizzle_thread_init(void);
299
void drizzle_thread_end(void);
302
Functions to get information from the DRIZZLE and DRIZZLE_RES structures
303
Should definitely be used if one uses shared libraries.
306
uint64_t drizzle_num_rows(const DRIZZLE_RES *res);
307
unsigned int drizzle_num_fields(const DRIZZLE_RES *res);
308
bool drizzle_eof(const DRIZZLE_RES *res);
309
const DRIZZLE_FIELD * drizzle_fetch_field_direct(const DRIZZLE_RES *res,
310
unsigned int fieldnr);
311
const DRIZZLE_FIELD * drizzle_fetch_fields(const DRIZZLE_RES *res);
312
DRIZZLE_ROW_OFFSET drizzle_row_tell(const DRIZZLE_RES *res);
313
DRIZZLE_FIELD_OFFSET drizzle_field_tell(const DRIZZLE_RES *res);
315
uint32_t drizzle_field_count(const DRIZZLE *drizzle);
316
uint64_t drizzle_affected_rows(const DRIZZLE *drizzle);
317
uint64_t drizzle_insert_id(const DRIZZLE *drizzle);
318
uint32_t drizzle_errno(const DRIZZLE *drizzle);
319
const char * drizzle_error(const DRIZZLE *drizzle);
320
const char * drizzle_sqlstate(const DRIZZLE *drizzle);
321
uint32_t drizzle_warning_count(const DRIZZLE *drizzle);
322
const char * drizzle_info(const DRIZZLE *drizzle);
323
uint32_t drizzle_thread_id(const DRIZZLE *drizzle);
324
const char * drizzle_character_set_name(const DRIZZLE *drizzle);
325
int32_t drizzle_set_character_set(DRIZZLE *drizzle, const char *csname);
327
DRIZZLE * drizzle_create(DRIZZLE *drizzle);
328
bool drizzle_change_user(DRIZZLE *drizzle, const char *user,
329
const char *passwd, const char *db);
330
DRIZZLE * drizzle_connect(DRIZZLE *drizzle, const char *host,
335
const char *unix_socket,
336
uint32_t clientflag);
337
int32_t drizzle_select_db(DRIZZLE *drizzle, const char *db);
338
int32_t drizzle_query(DRIZZLE *drizzle, const char *q);
339
int32_t drizzle_send_query(DRIZZLE *drizzle, const char *q, uint32_t length);
340
int32_t drizzle_real_query(DRIZZLE *drizzle, const char *q, uint32_t length);
341
DRIZZLE_RES * drizzle_store_result(DRIZZLE *drizzle);
342
DRIZZLE_RES * drizzle_use_result(DRIZZLE *drizzle);
344
void drizzle_get_character_set_info(const DRIZZLE *drizzle,
345
MY_CHARSET_INFO *charset);
347
/* local infile support */
349
#define LOCAL_INFILE_ERROR_LEN 512
352
drizzle_set_local_infile_handler(DRIZZLE *drizzle,
353
int (*local_infile_init)(void **, const char *, void *),
354
int (*local_infile_read)(void *, char *, unsigned int),
355
void (*local_infile_end)(void *),int (*local_infile_error)
356
(void *, char*, unsigned int), void *);
359
drizzle_set_local_infile_default(DRIZZLE *drizzle);
361
int32_t drizzle_shutdown(DRIZZLE *drizzle, enum drizzle_enum_shutdown_level shutdown_level);
362
int32_t drizzle_dump_debug_info(DRIZZLE *drizzle);
363
int32_t drizzle_refresh(DRIZZLE *drizzle, uint32_t refresh_options);
364
int32_t drizzle_kill(DRIZZLE *drizzle, uint32_t pid);
365
int32_t drizzle_set_server_option(DRIZZLE *drizzle, enum enum_drizzle_set_option option);
366
int32_t drizzle_ping(DRIZZLE *drizzle);
367
const char * drizzle_stat(DRIZZLE *drizzle);
368
const char * drizzle_get_server_info(const DRIZZLE *drizzle);
369
const char * drizzle_get_client_info(void);
370
uint32_t drizzle_get_client_version(void);
371
const char * drizzle_get_host_info(const DRIZZLE *drizzle);
372
uint32_t drizzle_get_server_version(const DRIZZLE *drizzle);
373
uint32_t drizzle_get_proto_info(const DRIZZLE *drizzle);
374
DRIZZLE_RES * drizzle_list_tables(DRIZZLE *drizzle,const char *wild);
375
DRIZZLE_RES * drizzle_list_processes(DRIZZLE *drizzle);
376
int32_t drizzle_options(DRIZZLE *drizzle,enum drizzle_option option, const void *arg);
377
void drizzle_free_result(DRIZZLE_RES *result);
378
void drizzle_data_seek(DRIZZLE_RES *result, uint64_t offset);
379
DRIZZLE_ROW_OFFSET drizzle_row_seek(DRIZZLE_RES *result, DRIZZLE_ROW_OFFSET offset);
380
DRIZZLE_FIELD_OFFSET drizzle_field_seek(DRIZZLE_RES *result, DRIZZLE_FIELD_OFFSET offset);
381
DRIZZLE_ROW drizzle_fetch_row(DRIZZLE_RES *result);
382
uint32_t * drizzle_fetch_lengths(DRIZZLE_RES *result);
383
DRIZZLE_FIELD * drizzle_fetch_field(DRIZZLE_RES *result);
384
DRIZZLE_RES * drizzle_list_fields(DRIZZLE *drizzle, const char *table, const char *wild);
385
uint32_t drizzle_escape_string(char *to,const char *from, uint32_t from_length);
386
uint32_t drizzle_hex_string(char *to,const char *from, uint32_t from_length);
387
uint32_t drizzle_real_escape_string(DRIZZLE *drizzle, char *to, const char *from, uint32_t length);
388
void myodbc_remove_escape(const DRIZZLE *drizzle, char *name);
389
uint32_t drizzle_thread_safe(void);
390
bool drizzle_embedded(void);
391
bool drizzle_read_query_result(DRIZZLE *drizzle);
395
typedef struct st_drizzle_methods
397
bool (*read_query_result)(DRIZZLE *drizzle);
398
bool (*advanced_command)(DRIZZLE *drizzle,
399
enum enum_server_command command,
400
const unsigned char *header,
401
uint32_t header_length,
402
const unsigned char *arg,
405
DRIZZLE_DATA *(*read_rows)(DRIZZLE *drizzle,DRIZZLE_FIELD *drizzle_fields, uint32_t fields);
406
DRIZZLE_RES * (*use_result)(DRIZZLE *drizzle);
407
void (*fetch_lengths)(uint32_t *to, DRIZZLE_ROW column, uint32_t field_count);
408
void (*flush_use_result)(DRIZZLE *drizzle);
409
DRIZZLE_FIELD * (*list_fields)(DRIZZLE *drizzle);
410
int32_t (*unbuffered_fetch)(DRIZZLE *drizzle, char **row);
411
const char *(*read_statistics)(DRIZZLE *drizzle);
412
bool (*next_result)(DRIZZLE *drizzle);
413
int32_t (*read_change_user_result)(DRIZZLE *drizzle);
417
bool drizzle_commit(DRIZZLE *drizzle);
418
bool drizzle_rollback(DRIZZLE *drizzle);
419
bool drizzle_autocommit(DRIZZLE *drizzle, bool auto_mode);
420
bool drizzle_more_results(const DRIZZLE *drizzle);
421
int drizzle_next_result(DRIZZLE *drizzle);
422
void drizzle_close(DRIZZLE *sock);
425
/* status return codes */
426
#define DRIZZLE_NO_DATA 100
427
#define DRIZZLE_DATA_TRUNCATED 101
430
#define drizzle_reload(drizzle) drizzle_refresh((drizzle),REFRESH_GRANT)
433
The following functions are mainly exported because of binlog;
434
They are not for general usage
437
#define simple_command(drizzle, command, arg, length, skip_check) \
438
(*(drizzle)->methods->advanced_command)(drizzle, command, 0, \
439
0, arg, length, skip_check)
445
#endif /* _libdrizzle_drizzle_h */