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
37
#ifndef _global_h /* If not standard header */
38
#include <sys/types.h>
42
#ifndef my_socket_defined
43
typedef int my_socket;
44
#endif /* my_socket_defined */
45
#endif /* _global_h */
47
#include <drizzled/version.h>
48
#include "drizzle_com.h"
49
#include "drizzle_time.h"
51
#include <mysys/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) <= DRIZZLE_TYPE_LONGLONG || (t) == DRIZZLE_TYPE_NEWDECIMAL)
63
#define IS_NUM_FIELD(f) ((f)->flags & NUM_FLAG)
64
#define INTERNAL_NUM_FIELD(f) (((f)->type <= DRIZZLE_TYPE_LONGLONG && ((f)->type != DRIZZLE_TYPE_TIMESTAMP || (f)->length == 14 || (f)->length == 8)))
65
#define IS_LONGDATA(t) ((t) == DRIZZLE_TYPE_TINY_BLOB)
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 */
95
#include <mysys/typelib.h>
97
#define DRIZZLE_COUNT_ERROR (~(uint64_t) 0)
99
typedef struct st_drizzle_rows {
100
struct st_drizzle_rows *next; /* list of rows */
102
unsigned long length;
105
typedef DRIZZLE_ROWS *DRIZZLE_ROW_OFFSET; /* offset to current row */
107
#include <mysys/my_alloc.h>
109
typedef struct embedded_query_result EMBEDDED_QUERY_RESULT;
110
typedef struct st_drizzle_data {
112
struct embedded_query_result *embedded_info;
116
/* extra info for embedded library */
122
DRIZZLE_OPT_CONNECT_TIMEOUT, DRIZZLE_OPT_COMPRESS, DRIZZLE_OPT_NAMED_PIPE,
123
DRIZZLE_INIT_COMMAND, DRIZZLE_READ_DEFAULT_FILE, DRIZZLE_READ_DEFAULT_GROUP,
124
DRIZZLE_SET_CHARSET_DIR, DRIZZLE_SET_CHARSET_NAME, DRIZZLE_OPT_LOCAL_INFILE,
125
DRIZZLE_OPT_PROTOCOL, DRIZZLE_SHARED_MEMORY_BASE_NAME, DRIZZLE_OPT_READ_TIMEOUT,
126
DRIZZLE_OPT_WRITE_TIMEOUT, DRIZZLE_OPT_USE_RESULT,
127
DRIZZLE_OPT_USE_REMOTE_CONNECTION, DRIZZLE_OPT_USE_EMBEDDED_CONNECTION,
128
DRIZZLE_OPT_GUESS_CONNECTION, DRIZZLE_SET_CLIENT_IP, DRIZZLE_SECURE_AUTH,
129
DRIZZLE_REPORT_DATA_TRUNCATION, DRIZZLE_OPT_RECONNECT,
130
DRIZZLE_OPT_SSL_VERIFY_SERVER_CERT
133
struct st_drizzle_options {
134
unsigned int connect_timeout, read_timeout, write_timeout;
135
unsigned int port, protocol;
136
unsigned long client_flag;
137
char *host,*user,*password,*unix_socket,*db;
138
struct st_dynamic_array *init_commands;
139
char *my_cnf_file,*my_cnf_group, *charset_dir, *charset_name;
140
char *ssl_key; /* PEM key file */
141
char *ssl_cert; /* PEM cert file */
142
char *ssl_ca; /* PEM CA file */
143
char *ssl_capath; /* PEM directory of CA-s? */
144
char *ssl_cipher; /* cipher to use */
145
char *shared_memory_base_name;
146
unsigned long max_allowed_packet;
147
my_bool use_ssl; /* if to use SSL or not */
148
my_bool compress,named_pipe;
153
enum drizzle_option methods_to_use;
155
/* Refuse client connecting to server if it uses old (pre-4.1.1) protocol */
157
/* 0 - never report, 1 - always report (default) */
158
my_bool report_data_truncation;
160
/* function pointers for local infile support */
161
int (*local_infile_init)(void **, const char *, void *);
162
int (*local_infile_read)(void *, char *, unsigned int);
163
void (*local_infile_end)(void *);
164
int (*local_infile_error)(void *, char *, unsigned int);
165
void *local_infile_userdata;
171
DRIZZLE_STATUS_READY,DRIZZLE_STATUS_GET_RESULT,DRIZZLE_STATUS_USE_RESULT
174
enum drizzle_protocol_type
176
DRIZZLE_PROTOCOL_DEFAULT, DRIZZLE_PROTOCOL_TCP, DRIZZLE_PROTOCOL_SOCKET,
177
DRIZZLE_PROTOCOL_PIPE, DRIZZLE_PROTOCOL_MEMORY
180
typedef struct character_set
182
unsigned int number; /* character set number */
183
unsigned int state; /* character set state */
184
const char *csname; /* collation name */
185
const char *name; /* character set name */
186
const char *comment; /* comment */
187
const char *dir; /* character set directory */
188
unsigned int mbminlen; /* min. length for multibyte strings */
189
unsigned int mbmaxlen; /* max. length for multibyte strings */
192
struct st_drizzle_methods;
193
struct st_drizzle_stmt;
195
typedef struct st_drizzle
197
NET net; /* Communication parameters */
198
unsigned char *connector_fd; /* ConnectorFd for SSL */
199
char *host,*user,*passwd,*unix_socket,*server_version,*host_info;
201
const struct charset_info_st *charset;
202
DRIZZLE_FIELD *fields;
203
MEM_ROOT field_alloc;
204
uint64_t affected_rows;
205
uint64_t insert_id; /* id if insert on table with NEXTNR */
206
uint64_t extra_info; /* Not used */
207
uint32_t thread_id; /* Id for connection in server */
208
uint32_t packet_length;
210
uint32_t client_flag,server_capabilities;
211
uint32_t protocol_version;
212
uint32_t field_count;
213
uint32_t server_status;
214
uint32_t server_language;
215
uint32_t warning_count;
216
struct st_drizzle_options options;
217
enum drizzle_status status;
218
bool free_me; /* If free in drizzle_close */
219
bool reconnect; /* set to 1 if automatic reconnect */
221
/* session-wide random string */
222
char scramble[SCRAMBLE_LENGTH+1];
224
void *unused2, *unused3, *unused4, *unused5;
226
LIST *stmts; /* list of all statements */
227
const struct st_drizzle_methods *methods;
230
Points to boolean flag in DRIZZLE_RES or MYSQL_STMT. We set this flag
231
from drizzle_stmt_close if close had to cancel result set of this object.
233
bool *unbuffered_fetch_owner;
234
/* needed for embedded server - no net buffer to store the 'info' */
240
typedef struct st_drizzle_res {
242
DRIZZLE_FIELD *fields;
244
DRIZZLE_ROWS *data_cursor;
245
uint32_t *lengths; /* column lengths of current row */
246
DRIZZLE *handle; /* for unbuffered reads */
247
const struct st_drizzle_methods *methods;
248
DRIZZLE_ROW row; /* If unbuffered read */
249
DRIZZLE_ROW current_row; /* buffer to current row */
250
MEM_ROOT field_alloc;
251
uint32_t field_count, current_field;
252
bool eof; /* Used by drizzle_fetch_row */
253
/* drizzle_stmt_close() had to cancel this result */
254
bool unbuffered_fetch_cancelled;
259
#if !defined(MYSQL_SERVER) && !defined(MYSQL_CLIENT)
264
typedef struct st_drizzle_parameters
266
uint32_t *p_max_allowed_packet;
267
uint32_t *p_net_buffer_length;
269
} DRIZZLE_PARAMETERS;
271
#if !defined(MYSQL_SERVER)
272
#define max_allowed_packet (*drizzle_get_parameters()->p_max_allowed_packet)
273
#define net_buffer_length (*drizzle_get_parameters()->p_net_buffer_length)
277
Set up and bring down the server; to ensure that applications will
278
work when linked against either the standard client library or the
279
embedded server library, these functions should be called.
281
void STDCALL drizzle_server_end(void);
284
drizzle_server_init/end need to be called when using libdrizzle or
285
libdrizzleclient (exactly, drizzle_server_init() is called by drizzle_init() so
286
you don't need to call it explicitely; but you need to call
287
drizzle_server_end() to free memory). The names are a bit misleading
288
(drizzle_SERVER* to be used when using libdrizzleCLIENT). So we add more general
289
names which suit well whether you're using libdrizzled or libdrizzleclient. We
290
intend to promote these aliases over the drizzle_server* ones.
292
#define drizzle_library_end drizzle_server_end
294
const DRIZZLE_PARAMETERS *STDCALL drizzle_get_parameters(void);
297
Set up and bring down a thread; these function should be called
298
for each thread in an application which opens at least one MySQL
299
connection. All uses of the connection(s) should be between these
302
bool STDCALL drizzle_thread_init(void);
303
void STDCALL drizzle_thread_end(void);
306
Functions to get information from the DRIZZLE and DRIZZLE_RES structures
307
Should definitely be used if one uses shared libraries.
310
uint64_t STDCALL drizzle_num_rows(const DRIZZLE_RES *res);
311
unsigned int STDCALL drizzle_num_fields(const DRIZZLE_RES *res);
312
bool STDCALL drizzle_eof(const DRIZZLE_RES *res);
313
const DRIZZLE_FIELD *STDCALL drizzle_fetch_field_direct(const DRIZZLE_RES *res,
314
unsigned int fieldnr);
315
const DRIZZLE_FIELD * STDCALL drizzle_fetch_fields(const DRIZZLE_RES *res);
316
DRIZZLE_ROW_OFFSET STDCALL drizzle_row_tell(const DRIZZLE_RES *res);
317
DRIZZLE_FIELD_OFFSET STDCALL drizzle_field_tell(const DRIZZLE_RES *res);
319
uint32_t STDCALL drizzle_field_count(const DRIZZLE *drizzle);
320
uint64_t STDCALL drizzle_affected_rows(const DRIZZLE *drizzle);
321
uint64_t STDCALL drizzle_insert_id(const DRIZZLE *drizzle);
322
uint32_t STDCALL drizzle_errno(const DRIZZLE *drizzle);
323
const char * STDCALL drizzle_error(const DRIZZLE *drizzle);
324
const char *STDCALL drizzle_sqlstate(const DRIZZLE *drizzle);
325
uint32_t STDCALL drizzle_warning_count(const DRIZZLE *drizzle);
326
const char * STDCALL drizzle_info(const DRIZZLE *drizzle);
327
uint32_t STDCALL drizzle_thread_id(const DRIZZLE *drizzle);
328
const char * STDCALL drizzle_character_set_name(const DRIZZLE *drizzle);
329
int32_t STDCALL drizzle_set_character_set(DRIZZLE *drizzle, const char *csname);
331
DRIZZLE * STDCALL drizzle_create(DRIZZLE *drizzle);
332
bool STDCALL drizzle_change_user(DRIZZLE *drizzle, const char *user,
333
const char *passwd, const char *db);
334
DRIZZLE * STDCALL drizzle_connect(DRIZZLE *drizzle, const char *host,
339
const char *unix_socket,
340
uint32_t clientflag);
341
int32_t STDCALL drizzle_select_db(DRIZZLE *drizzle, const char *db);
342
int32_t STDCALL drizzle_query(DRIZZLE *drizzle, const char *q);
343
int32_t STDCALL drizzle_send_query(DRIZZLE *drizzle, const char *q, uint32_t length);
344
int32_t STDCALL drizzle_real_query(DRIZZLE *drizzle, const char *q, uint32_t length);
345
DRIZZLE_RES * STDCALL drizzle_store_result(DRIZZLE *drizzle);
346
DRIZZLE_RES * STDCALL drizzle_use_result(DRIZZLE *drizzle);
348
void STDCALL drizzle_get_character_set_info(const DRIZZLE *drizzle,
349
MY_CHARSET_INFO *charset);
351
/* local infile support */
353
#define LOCAL_INFILE_ERROR_LEN 512
356
drizzle_set_local_infile_handler(DRIZZLE *drizzle,
357
int (*local_infile_init)(void **, const char *, void *),
358
int (*local_infile_read)(void *, char *, unsigned int),
359
void (*local_infile_end)(void *),int (*local_infile_error)
360
(void *, char*, unsigned int), void *);
363
drizzle_set_local_infile_default(DRIZZLE *drizzle);
365
int32_t STDCALL drizzle_shutdown(DRIZZLE *drizzle, enum drizzle_enum_shutdown_level shutdown_level);
366
int32_t STDCALL drizzle_dump_debug_info(DRIZZLE *drizzle);
367
int32_t STDCALL drizzle_refresh(DRIZZLE *drizzle, uint32_t refresh_options);
368
int32_t STDCALL drizzle_kill(DRIZZLE *drizzle, uint32_t pid);
369
int32_t STDCALL drizzle_set_server_option(DRIZZLE *drizzle, enum enum_drizzle_set_option option);
370
int32_t STDCALL drizzle_ping(DRIZZLE *drizzle);
371
const char * STDCALL drizzle_stat(DRIZZLE *drizzle);
372
const char * STDCALL drizzle_get_server_info(const DRIZZLE *drizzle);
373
const char * STDCALL drizzle_get_client_info(void);
374
uint32_t STDCALL drizzle_get_client_version(void);
375
const char * STDCALL drizzle_get_host_info(const DRIZZLE *drizzle);
376
uint32_t STDCALL drizzle_get_server_version(const DRIZZLE *drizzle);
377
uint32_t STDCALL drizzle_get_proto_info(const DRIZZLE *drizzle);
378
DRIZZLE_RES * STDCALL drizzle_list_dbs(DRIZZLE *drizzle,const char *wild);
379
DRIZZLE_RES * STDCALL drizzle_list_tables(DRIZZLE *drizzle,const char *wild);
380
DRIZZLE_RES * STDCALL drizzle_list_processes(DRIZZLE *drizzle);
381
int32_t STDCALL drizzle_options(DRIZZLE *drizzle,enum drizzle_option option, const void *arg);
382
void STDCALL drizzle_free_result(DRIZZLE_RES *result);
383
void STDCALL drizzle_data_seek(DRIZZLE_RES *result, uint64_t offset);
384
DRIZZLE_ROW_OFFSET STDCALL drizzle_row_seek(DRIZZLE_RES *result, DRIZZLE_ROW_OFFSET offset);
385
DRIZZLE_FIELD_OFFSET STDCALL drizzle_field_seek(DRIZZLE_RES *result, DRIZZLE_FIELD_OFFSET offset);
386
DRIZZLE_ROW STDCALL drizzle_fetch_row(DRIZZLE_RES *result);
387
uint32_t * STDCALL drizzle_fetch_lengths(DRIZZLE_RES *result);
388
DRIZZLE_FIELD * STDCALL drizzle_fetch_field(DRIZZLE_RES *result);
389
DRIZZLE_RES * STDCALL drizzle_list_fields(DRIZZLE *drizzle, const char *table, const char *wild);
390
uint32_t STDCALL drizzle_escape_string(char *to,const char *from, uint32_t from_length);
391
uint32_t STDCALL drizzle_hex_string(char *to,const char *from, uint32_t from_length);
392
uint32_t STDCALL drizzle_real_escape_string(DRIZZLE *drizzle, char *to, const char *from, uint32_t length);
393
void STDCALL myodbc_remove_escape(const DRIZZLE *drizzle, char *name);
394
uint32_t STDCALL drizzle_thread_safe(void);
395
bool STDCALL drizzle_embedded(void);
396
bool STDCALL drizzle_read_query_result(DRIZZLE *drizzle);
400
typedef struct st_drizzle_methods
402
bool (*read_query_result)(DRIZZLE *drizzle);
403
bool (*advanced_command)(DRIZZLE *drizzle,
404
enum enum_server_command command,
405
const unsigned char *header,
406
uint32_t header_length,
407
const unsigned char *arg,
410
DRIZZLE_DATA *(*read_rows)(DRIZZLE *drizzle,DRIZZLE_FIELD *drizzle_fields, uint32_t fields);
411
DRIZZLE_RES * (*use_result)(DRIZZLE *drizzle);
412
void (*fetch_lengths)(uint32_t *to, DRIZZLE_ROW column, uint32_t field_count);
413
void (*flush_use_result)(DRIZZLE *drizzle);
414
DRIZZLE_FIELD * (*list_fields)(DRIZZLE *drizzle);
415
int32_t (*unbuffered_fetch)(DRIZZLE *drizzle, char **row);
416
const char *(*read_statistics)(DRIZZLE *drizzle);
417
bool (*next_result)(DRIZZLE *drizzle);
418
int32_t (*read_change_user_result)(DRIZZLE *drizzle);
422
bool STDCALL drizzle_commit(DRIZZLE *drizzle);
423
bool STDCALL drizzle_rollback(DRIZZLE *drizzle);
424
bool STDCALL drizzle_autocommit(DRIZZLE *drizzle, bool auto_mode);
425
bool STDCALL drizzle_more_results(const DRIZZLE *drizzle);
426
int STDCALL drizzle_next_result(DRIZZLE *drizzle);
427
void STDCALL drizzle_close(DRIZZLE *sock);
430
/* status return codes */
431
#define DRIZZLE_NO_DATA 100
432
#define DRIZZLE_DATA_TRUNCATED 101
435
#define DRIZZLE_PROTOCOL_NO_MORE_DATA 0xFE
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 /* _libdrizzle_drizzle_h */