Mysql H
Mysql H
Mysql H
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
/**
@file include/mysql.h
This file defines the client API to MySQL and also the ABI of the
dynamically linked libmysqlclient.
#ifndef _mysql_h
#define _mysql_h
#ifndef MYSQL_ABI_CHECK
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
#endif
// Legacy definition for the benefit of old code. Use uint64_t in new code.
// If you get warnings from printf, use the PRIu64 macro, or, if you need
// compatibility with older versions of the client library, cast
// before printing.
typedef uint64_t my_ulonglong;
#ifndef my_socket_defined
#define my_socket_defined
#if defined(_WIN32) && !defined(MYSQL_ABI_CHECK)
#include <windows.h>
#ifdef WIN32_LEAN_AND_MEAN
#include <winsock2.h>
#endif
#define my_socket SOCKET
#else
typedef int my_socket;
#endif /* _WIN32 && ! MYSQL_ABI_CHECK */
#endif /* my_socket_defined */
#include "field_types.h"
#include "my_list.h"
#include "mysql_com.h"
/*
The client should be able to know which version it is compiled against,
even if mysql.h doesn't use this information directly.
*/
#include "mysql_version.h" // IWYU pragma: keep
#ifdef __cplusplus
extern "C" {
#endif
struct MEM_ROOT;
enum mysql_option {
MYSQL_OPT_CONNECT_TIMEOUT,
MYSQL_OPT_COMPRESS,
MYSQL_OPT_NAMED_PIPE,
MYSQL_INIT_COMMAND,
MYSQL_READ_DEFAULT_FILE,
MYSQL_READ_DEFAULT_GROUP,
MYSQL_SET_CHARSET_DIR,
MYSQL_SET_CHARSET_NAME,
MYSQL_OPT_LOCAL_INFILE,
MYSQL_OPT_PROTOCOL,
MYSQL_SHARED_MEMORY_BASE_NAME,
MYSQL_OPT_READ_TIMEOUT,
MYSQL_OPT_WRITE_TIMEOUT,
MYSQL_OPT_USE_RESULT,
MYSQL_REPORT_DATA_TRUNCATION,
MYSQL_OPT_RECONNECT,
MYSQL_PLUGIN_DIR,
MYSQL_DEFAULT_AUTH,
MYSQL_OPT_BIND,
MYSQL_OPT_SSL_KEY,
MYSQL_OPT_SSL_CERT,
MYSQL_OPT_SSL_CA,
MYSQL_OPT_SSL_CAPATH,
MYSQL_OPT_SSL_CIPHER,
MYSQL_OPT_SSL_CRL,
MYSQL_OPT_SSL_CRLPATH,
MYSQL_OPT_CONNECT_ATTR_RESET,
MYSQL_OPT_CONNECT_ATTR_ADD,
MYSQL_OPT_CONNECT_ATTR_DELETE,
MYSQL_SERVER_PUBLIC_KEY,
MYSQL_ENABLE_CLEARTEXT_PLUGIN,
MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS,
MYSQL_OPT_MAX_ALLOWED_PACKET,
MYSQL_OPT_NET_BUFFER_LENGTH,
MYSQL_OPT_TLS_VERSION,
MYSQL_OPT_SSL_MODE,
MYSQL_OPT_GET_SERVER_PUBLIC_KEY,
MYSQL_OPT_RETRY_COUNT,
MYSQL_OPT_OPTIONAL_RESULTSET_METADATA,
MYSQL_OPT_SSL_FIPS_MODE,
MYSQL_OPT_TLS_CIPHERSUITES,
MYSQL_OPT_COMPRESSION_ALGORITHMS,
MYSQL_OPT_ZSTD_COMPRESSION_LEVEL,
MYSQL_OPT_LOAD_DATA_LOCAL_DIR,
MYSQL_OPT_USER_PASSWORD,
MYSQL_OPT_SSL_SESSION_DATA,
MYSQL_OPT_TLS_SNI_SERVERNAME
};
/**
@todo remove the "extension", move st_mysql_options completely
out of mysql.h
*/
struct st_mysql_options_extention;
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 Init_commands_array *init_commands;
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 *ssl_cipher; /* cipher to use */
char *shared_memory_base_name;
unsigned long max_allowed_packet;
bool compress, named_pipe;
/**
The local address to bind when connecting to remote server.
*/
char *bind_address;
/* 0 - never report, 1 - always report (default) */
bool report_data_truncation;
enum mysql_status {
MYSQL_STATUS_READY,
MYSQL_STATUS_GET_RESULT,
MYSQL_STATUS_USE_RESULT,
MYSQL_STATUS_STATEMENT_GET_RESULT
};
enum mysql_protocol_type {
MYSQL_PROTOCOL_DEFAULT,
MYSQL_PROTOCOL_TCP,
MYSQL_PROTOCOL_SOCKET,
MYSQL_PROTOCOL_PIPE,
MYSQL_PROTOCOL_MEMORY
};
enum mysql_ssl_mode {
SSL_MODE_DISABLED = 1,
SSL_MODE_PREFERRED,
SSL_MODE_REQUIRED,
SSL_MODE_VERIFY_CA,
SSL_MODE_VERIFY_IDENTITY
};
enum mysql_ssl_fips_mode {
SSL_FIPS_MODE_OFF = 0,
SSL_FIPS_MODE_ON = 1,
SSL_FIPS_MODE_STRICT
};
struct MYSQL_METHODS;
struct MYSQL_STMT;
typedef struct MYSQL {
NET net; /* Communication parameters */
unsigned char *connector_fd; /* ConnectorFd for SSL */
char *host, *user, *passwd, *unix_socket, *server_version, *host_info;
char *info, *db;
struct CHARSET_INFO *charset;
MYSQL_FIELD *fields;
struct MEM_ROOT *field_alloc;
uint64_t affected_rows;
uint64_t insert_id; /* id if insert on table with NEXTNR */
uint64_t extra_info; /* Not used */
unsigned long thread_id; /* Id for connection in server */
unsigned long packet_length;
unsigned int port;
unsigned long client_flag, server_capabilities;
unsigned int protocol_version;
unsigned int field_count;
unsigned int server_status;
unsigned int server_language;
unsigned int warning_count;
struct st_mysql_options options;
enum mysql_status status;
enum enum_resultset_metadata resultset_metadata;
bool free_me; /* If free in mysql_close */
bool reconnect; /* set to 1 if automatic reconnect */
/**
Flag to indicate that the heartbeat_event being generated
is using the class Heartbeat_event_v2
*/
#define USE_HEARTBEAT_EVENT_V2 (1 << 1)
/**
Flag to indicate that tagged GTIDS will be skipped in COM_BINLOG_DUMP_GTIDS
*/
#define MYSQL_RPL_SKIP_TAGGED_GTIDS (1 << 2)
/**
Tagged GTIDS are supported starting from below version of MySQL
*/
#define MYSQL_TAGGED_GTIDS_VERSION_SUPPORT 80300
/**
Struct for information about a replication stream.
@sa mysql_binlog_open()
@sa mysql_binlog_fetch()
@sa mysql_binlog_close()
*/
typedef struct MYSQL_RPL {
size_t file_name_length; /** Length of the 'file_name' or 0 */
const char *file_name; /** Filename of the binary log to read */
uint64_t start_position; /** Position in the binary log to */
/* start reading from */
unsigned int server_id; /** Server ID to use when identifying */
/* with the master */
unsigned int flags; /** Flags, e.g. MYSQL_RPL_GTID */
/*
Set up and bring down the server; to ensure that applications will
work when linked against either the standard client library or the
embedded server library, these functions should be called.
*/
int STDCALL mysql_server_init(int argc, char **argv, char **groups);
void STDCALL mysql_server_end(void);
/*
mysql_server_init/end need to be called when using libmysqld or
libmysqlclient (exactly, mysql_server_init() is called by mysql_init() so
you don't need to call it explicitly; but you need to call
mysql_server_end() to free memory). The names are a bit misleading
(mysql_SERVER* to be used when using libmysqlCLIENT). So we add more general
names which suit well whether you're using libmysqld or libmysqlclient. We
intend to promote these aliases over the mysql_server* ones.
*/
#define mysql_library_init mysql_server_init
#define mysql_library_end mysql_server_end
/*
Set up and bring down a thread; these function should be called
for each thread in an application which opens at least one MySQL
connection. All uses of the connection(s) should be between these
function calls.
*/
bool STDCALL mysql_thread_init(void);
void STDCALL mysql_thread_end(void);
/*
Functions to get information from the MYSQL and MYSQL_RES structures
Should definitely be used if one uses shared libraries.
*/
void 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 *),
int (*local_infile_error)(void *, char *, unsigned int), void *);
/*
The following definitions are added for the enhanced
client-server protocol
*/
/* statement state */
enum enum_mysql_stmt_state {
MYSQL_STMT_INIT_DONE = 1,
MYSQL_STMT_PREPARE_DONE,
MYSQL_STMT_EXECUTE_DONE,
MYSQL_STMT_FETCH_DONE
};
/*
This structure is used to define bind information, and
internally by the client library.
Public members with their descriptions are listed below
(conventionally `On input' refers to the binds given to
mysql_stmt_bind_param, `On output' refers to the binds given
to mysql_stmt_bind_result):
The two above members are mandatory for any kind of bind.
struct MYSQL_STMT_EXT;
/* statement handler */
typedef struct MYSQL_STMT {
struct MEM_ROOT *mem_root; /* root allocations */
LIST list; /* list to keep track of all stmts */
MYSQL *mysql; /* connection handle */
MYSQL_BIND *params; /* input parameters */
MYSQL_BIND *bind; /* output parameters */
MYSQL_FIELD *fields; /* result set metadata */
MYSQL_DATA result; /* cached result set */
MYSQL_ROWS *data_cursor; /* current row in cached result */
/*
mysql_stmt_fetch() calls this function to fetch one row (it's different
for buffered, unbuffered and cursor fetch).
*/
int (*read_row_func)(struct MYSQL_STMT *stmt, unsigned char **row);
/* copy of mysql->affected_rows after statement execution */
uint64_t affected_rows;
uint64_t insert_id; /* copy of mysql->insert_id */
unsigned long stmt_id; /* Id for prepared statement */
unsigned long flags; /* i.e. type of cursor to open */
unsigned long prefetch_rows; /* number of rows per one COM_FETCH */
/*
Copied from mysql->server_status after execute/fetch to know
server-side cursor status for this statement.
*/
unsigned int server_status;
unsigned int last_errno; /* error code */
unsigned int param_count; /* input parameter count */
unsigned int field_count; /* number of columns in result set */
enum enum_mysql_stmt_state state; /* statement state */
char last_error[MYSQL_ERRMSG_SIZE]; /* error message */
char sqlstate[SQLSTATE_LENGTH + 1];
/* Types of input parameters should be sent to server */
bool send_types_to_server;
bool bind_param_done; /* input buffers were supplied */
unsigned char bind_result_done; /* output buffers were supplied */
/* mysql_stmt_close() had to cancel this result */
bool unbuffered_fetch_cancelled;
/*
Is set to true if we need to calculate field->max_length for
metadata fields when doing mysql_stmt_store_result.
*/
bool update_max_length;
struct MYSQL_STMT_EXT *extension;
} MYSQL_STMT;
enum enum_stmt_attr_type {
/*
When doing mysql_stmt_store_result calculate max_length attribute
of statement metadata. This is to be consistent with the old API,
where this was done automatically.
In the new API we do that only by request because it slows down
mysql_stmt_store_result sufficiently.
*/
STMT_ATTR_UPDATE_MAX_LENGTH,
/*
unsigned long with combination of cursor flags (read only, for update,
etc)
*/
STMT_ATTR_CURSOR_TYPE,
/*
Amount of rows to retrieve from server per one fetch if using cursors.
Accepts unsigned long attribute in the range 1 - ulong_max
*/
STMT_ATTR_PREFETCH_ROWS
};
#define HAVE_MYSQL_REAL_CONNECT
#ifdef __cplusplus
}
#endif
#endif /* _mysql_h */