/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
/* defines for the libmariadb library */
#if !defined (_global_h) && !defined (MY_GLOBAL_INCLUDED) /* If not standard header */
typedef unsigned long long my_ulonglong;
#define STDCALL __stdcall
#ifndef my_socket_defined
#define my_socket_defined
#define my_socket unsigned long long
#define my_socket unsigned int
#include "mariadb_version.h"
#include "mariadb_ctype.h"
typedef struct st_ma_const_string
typedef struct st_ma_const_data
const unsigned char *data;
#ifndef ST_MA_USED_MEM_DEFINED
#define ST_MA_USED_MEM_DEFINED
typedef struct st_ma_used_mem { /* struct for once_alloc */
struct st_ma_used_mem *next; /* Next block in use */
size_t left; /* memory left in block */
size_t size; /* Size of block */
typedef struct st_ma_mem_root {
unsigned int first_block_usage;
void (*error_handler)(void);
extern unsigned int mysql_port;
extern char *mysql_unix_port;
extern unsigned int mariadb_deinitialize_ssl;
#define IS_PRI_KEY(n) ((n) & PRI_KEY_FLAG)
#define IS_NOT_NULL(n) ((n) & NOT_NULL_FLAG)
#define IS_BLOB(n) ((n) & BLOB_FLAG)
#define IS_NUM(t) (((t) <= MYSQL_TYPE_INT24 && (t) != MYSQL_TYPE_TIMESTAMP) || (t) == MYSQL_TYPE_YEAR || (t) == MYSQL_TYPE_NEWDECIMAL)
#define IS_NUM_FIELD(f) ((f)->flags & NUM_FLAG)
#define INTERNAL_NUM_FIELD(f) (((f)->type <= MYSQL_TYPE_INT24 && ((f)->type != MYSQL_TYPE_TIMESTAMP || (f)->length == 14 || (f)->length == 8)) || (f)->type == MYSQL_TYPE_YEAR || (f)->type == MYSQL_TYPE_NEWDECIMAL || (f)->type == MYSQL_TYPE_DECIMAL)
typedef struct st_mysql_field {
char *name; /* Name of column */
char *org_name; /* Name of original column (added after 3.23.58) */
char *table; /* Table of column if column was a field */
char *org_table; /* Name of original table (added after 3.23.58 */
char *db; /* table schema (added after 3.23.58) */
char *catalog; /* table catalog (added after 3.23.58) */
char *def; /* Default value (set by mysql_list_fields) */
unsigned long length; /* Width of column */
unsigned long max_length; /* Max width of selected set */
/* added after 3.23.58 */
unsigned int name_length;
unsigned int org_name_length;
unsigned int table_length;
unsigned int org_table_length;
unsigned int catalog_length;
/***********************/
unsigned int flags; /* Div flags */
unsigned int decimals; /* Number of decimals in field */
unsigned int charsetnr; /* char set number (added in 4.1) */
enum enum_field_types type; /* Type of field. Se mysql_com.h for types */
void *extension; /* added in 4.1 */
typedef char **MYSQL_ROW; /* return data as array of strings */
typedef unsigned int MYSQL_FIELD_OFFSET; /* offset to current field */
#define SET_CLIENT_ERROR(a, b, c, d) \
(a)->net.last_errno= (b);\
strncpy((a)->net.sqlstate, (c), SQLSTATE_LENGTH);\
(a)->net.sqlstate[SQLSTATE_LENGTH]= 0;\
strncpy((a)->net.last_error, (d) ? (d) : ER((b)), MYSQL_ERRMSG_SIZE - 1);\
(a)->net.last_error[MYSQL_ERRMSG_SIZE - 1]= 0;\
#define set_mariadb_error(A,B,C) SET_CLIENT_ERROR((A),(B),(C),0)
extern const char *SQLSTATE_UNKNOWN;
#define unknown_sqlstate SQLSTATE_UNKNOWN
#define CLEAR_CLIENT_ERROR(a) \
strcpy((a)->net.sqlstate, "00000");\
(a)->net.last_error[0]= '\0';\
(a)->net.extension->extended_errno= 0;\
#define MYSQL_COUNT_ERROR (~(unsigned long long) 0)
typedef struct st_mysql_rows {
struct st_mysql_rows *next; /* list of rows */
typedef MYSQL_ROWS *MYSQL_ROW_OFFSET; /* offset to current row */
typedef struct st_mysql_data {
MYSQL_OPT_CONNECT_TIMEOUT,
MYSQL_READ_DEFAULT_GROUP,
MYSQL_SHARED_MEMORY_BASE_NAME,
MYSQL_OPT_USE_REMOTE_CONNECTION,
MYSQL_OPT_USE_EMBEDDED_CONNECTION,
MYSQL_OPT_GUESS_CONNECTION,
MYSQL_REPORT_DATA_TRUNCATION,
MYSQL_OPT_SSL_VERIFY_SERVER_CERT,
/* Connection attribute options */
MYSQL_OPT_CONNECT_ATTR_RESET,
MYSQL_OPT_CONNECT_ATTR_ADD,
MYSQL_OPT_CONNECT_ATTR_DELETE,
MYSQL_ENABLE_CLEARTEXT_PLUGIN,
MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS,
MYSQL_OPT_MAX_ALLOWED_PACKET,
MYSQL_OPT_NET_BUFFER_LENGTH,
MYSQL_PROGRESS_CALLBACK=5999,
/* MariaDB Connector/C specific */
MYSQL_DATABASE_DRIVER=7000,
MARIADB_OPT_SSL_FP, /* deprecated, use MARIADB_OPT_TLS_PEER_FP instead */
MARIADB_OPT_SSL_FP_LIST, /* deprecated, use MARIADB_OPT_TLS_PEER_FP_LIST instead */
MARIADB_OPT_TLS_PASSPHRASE, /* passphrase for encrypted certificates */
MARIADB_OPT_TLS_CIPHER_STRENGTH,
MARIADB_OPT_TLS_PEER_FP, /* single finger print for server certificate verification */
MARIADB_OPT_TLS_PEER_FP_LIST, /* finger print white list for server certificate verification */
MARIADB_OPT_CONNECTION_READ_ONLY,
MYSQL_OPT_CONNECT_ATTRS, /* for mysql_get_optionv */
MARIADB_OPT_CONNECTION_HANDLER,
MARIADB_OPT_MULTI_RESULTS,
MARIADB_OPT_MULTI_STATEMENTS,
MARIADB_OPT_PROXY_HEADER,
MARIADB_OPT_SKIP_READ_RESPONSE,
MARIADB_OPT_RESTRICTED_AUTH,
MARIADB_OPT_RPL_REGISTER_REPLICA,
MARIADB_OPT_STATUS_CALLBACK,
MARIADB_OPT_SERVER_PLUGINS
MARIADB_CLIENT_VERSION_ID,
MARIADB_CONNECTION_ASYNC_TIMEOUT,
MARIADB_CONNECTION_ASYNC_TIMEOUT_MS,
MARIADB_CONNECTION_MARIADB_CHARSET_INFO,
MARIADB_CONNECTION_ERROR,
MARIADB_CONNECTION_ERROR_ID,
MARIADB_CONNECTION_PROTOCOL_VERSION_ID,
MARIADB_CONNECTION_PVIO_TYPE,
MARIADB_CONNECTION_SCHEMA,
MARIADB_CONNECTION_SERVER_TYPE,
MARIADB_CONNECTION_SERVER_VERSION,
MARIADB_CONNECTION_SERVER_VERSION_ID,
MARIADB_CONNECTION_SOCKET,
MARIADB_CONNECTION_SQLSTATE,
MARIADB_CONNECTION_SSL_CIPHER,
MARIADB_CONNECTION_TLS_VERSION,
MARIADB_CONNECTION_TLS_VERSION_ID,
MARIADB_CONNECTION_UNIX_SOCKET,
MARIADB_MAX_ALLOWED_PACKET,
MARIADB_NET_BUFFER_LENGTH,
MARIADB_CONNECTION_SERVER_STATUS,
MARIADB_CONNECTION_SERVER_CAPABILITIES,
MARIADB_CONNECTION_EXTENDED_SERVER_CAPABILITIES,
MARIADB_CONNECTION_CLIENT_CAPABILITIES,
MARIADB_CONNECTION_BYTES_READ,
MARIADB_CONNECTION_BYTES_SENT
enum mysql_status { MYSQL_STATUS_READY,
MYSQL_STATUS_SENDING_LOAD_DATA,
MYSQL_STATUS_FETCHING_DATA,
MYSQL_STATUS_NEXT_RESULT_PENDING,
MYSQL_STATUS_QUIT_SENT, /* object is "destroyed" at this stage */
MYSQL_PROTOCOL_DEFAULT, MYSQL_PROTOCOL_TCP, MYSQL_PROTOCOL_SOCKET,
MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_MEMORY
struct st_mysql_options {
unsigned int connect_timeout, read_timeout, write_timeout;
unsigned int port, protocol;
unsigned long client_flag;
char *host,*user,*password,*unix_socket,*db;
struct st_dynamic_array *init_command;
char *my_cnf_file,*my_cnf_group, *charset_dir, *charset_name;
char *ssl_key; /* PEM key file */
char *ssl_cert; /* PEM cert file */
char *ssl_ca; /* PEM CA file */
char *ssl_capath; /* PEM directory of CA-s? */
char *shared_memory_base_name;
unsigned long max_allowed_packet;
my_bool use_ssl; /* if to use SSL or not */
my_bool compress,named_pipe;
my_bool reconnect, unused_1, unused_2, unused_3;
enum mysql_option methods_to_use;
my_bool report_data_truncation;
/* function pointers for local infile support */
int (*local_infile_init)(void **, const char *, void *);
int (*local_infile_read)(void *, char *, unsigned int);
void (*local_infile_end)(void *);
int (*local_infile_error)(void *, char *, unsigned int);
void *local_infile_userdata;
struct st_mysql_options_extension *extension;
typedef struct st_mysql {
NET net; /* Communication parameters */
char *host,*user,*passwd,*unix_socket,*server_version,*host_info;
const struct ma_charset_info_st *charset; /* character set */
unsigned long long affected_rows;
unsigned long long insert_id; /* id if insert on table with NEXTNR */
unsigned long long extra_info; /* Used by mysqlshow */
unsigned long thread_id; /* Id for connection in server */
unsigned long packet_length;
unsigned long client_flag;
unsigned long server_capabilities;
unsigned int protocol_version;
unsigned int field_count;
unsigned int server_status;
unsigned int server_language;
unsigned int warning_count; /* warning count, added in 4.1 protocol */
struct st_mysql_options options;
enum mysql_status status;
my_bool free_me; /* If free in mysql_close */
char scramble_buff[20+ 1];
/* madded after 3.23.58 */
void *unused_3, *unused_4, *unused_5, *unused_6;
const struct st_mariadb_methods *methods;
my_bool *unbuffered_fetch_owner;
struct st_mariadb_extension *extension;
typedef struct st_mysql_res {
unsigned long long row_count;
unsigned int field_count, current_field;
MYSQL_ROW row; /* If unbuffered read */
MYSQL_ROW current_row; /* buffer to current row */
unsigned long *lengths; /* column lengths of current row */
MYSQL *handle; /* for unbuffered reads */
my_bool eof; /* Used my mysql_fetch_row */
unsigned long *p_max_allowed_packet;
unsigned long *p_net_buffer_length;
enum mariadb_field_attr_t
MARIADB_FIELD_ATTR_DATA_TYPE_NAME= 0,
MARIADB_FIELD_ATTR_FORMAT_NAME= 1
#define MARIADB_FIELD_ATTR_LAST MARIADB_FIELD_ATTR_FORMAT_NAME
int STDCALL mariadb_field_attr(MARIADB_CONST_STRING *attr,
const MYSQL_FIELD *field,
enum mariadb_field_attr_t type);
enum enum_mysql_timestamp_type
MYSQL_TIMESTAMP_NONE= -2, MYSQL_TIMESTAMP_ERROR= -1,
MYSQL_TIMESTAMP_DATE= 0, MYSQL_TIMESTAMP_DATETIME= 1, MYSQL_TIMESTAMP_TIME= 2
typedef struct st_mysql_time
unsigned int year, month, day, hour, minute, second;
unsigned long second_part;
enum enum_mysql_timestamp_type time_type;
#define AUTO_SEC_PART_DIGITS 39
#define SEC_PART_DIGITS 6
#define MARIADB_INVALID_SOCKET -1
/* Asynchronous API constants */
#define MYSQL_WAIT_READ 1
#define MYSQL_WAIT_WRITE 2
#define MYSQL_WAIT_EXCEPT 4
#define MYSQL_WAIT_TIMEOUT 8
typedef struct character_set
unsigned int number; /* character set number */
unsigned int state; /* character set state */
const char *csname; /* character set name */
const char *name; /* collation name */
const char *comment; /* comment */
const char *dir; /* character set directory */
unsigned int mbminlen; /* min. length for multibyte strings */
unsigned int mbmaxlen; /* max. length for multibyte strings */
/* Local infile support functions */
#define LOCAL_INFILE_ERROR_LEN 512
#include "mariadb_stmt.h"
#ifndef MYSQL_CLIENT_PLUGIN_HEADER
#define MYSQL_CLIENT_PLUGIN_HEADER \
unsigned int interface_version; \
unsigned int version[3]; \
int (*init)(char *, size_t, int, va_list); \
int (*options)(const char *option, const void *);
struct st_mysql_client_plugin
MYSQL_CLIENT_PLUGIN_HEADER
struct st_mysql_client_plugin *
mysql_load_plugin(struct st_mysql *mysql, const char *name, int type,
struct st_mysql_client_plugin * STDCALL
mysql_load_plugin_v(struct st_mysql *mysql, const char *name, int type,
struct st_mysql_client_plugin * STDCALL
mysql_client_find_plugin(struct st_mysql *mysql, const char *name, int type);
struct st_mysql_client_plugin * STDCALL
mysql_client_register_plugin(struct st_mysql *mysql,
struct st_mysql_client_plugin *plugin);
void STDCALL mysql_set_local_infile_handler(MYSQL *mysql,
int (*local_infile_init)(void **, const char *, void *),
int (*local_infile_read)(void *, char *, unsigned int),
void (*local_infile_end)(void *),