MySQL 9.0.0
Source Code Documentation
sql_common.h File Reference
#include <mysql.h>
#include <stddef.h>
#include <sys/types.h>
#include "errmsg.h"
#include "my_command.h"
#include "my_compiler.h"
#include "my_inttypes.h"
#include "my_list.h"
#include "mysql_com.h"
#include "mysql_com_server.h"

Go to the source code of this file.

Classes

struct  STATE_INFO_NODE
 The structure is used to hold the state change information received from the server. More...
 
struct  STATE_INFO
 Store the change info received from the server in an array of linked lists with STATE_INFO_NODE elements (one per state type). More...
 
struct  MYSQL_EXTENSION
 
struct  client_authentication_info
 
struct  st_mysql_options_extention
 
struct  MYSQL_METHODS
 

Macros

#define MYSQL_EXTENSION_PTR(H)
 
#define ASYNC_DATA(M)    (NULL != (M) ? (MYSQL_EXTENSION_PTR(M)->mysql_async_context) : NULL)
 
#define MAX_AUTHENTICATION_FACTOR   3
 
#define MYSQL_OPTIONS_EXTENSION_PTR(H, what)    ((H)->options.extension ? (H)->options.extension->what : nullptr)
 
#define simple_command(mysql, command, arg, length, skip_check)
 
#define simple_command_nonblocking(mysql, command, arg, length, skip_check, error)
 
#define stmt_command(mysql, command, arg, length, stmt)
 
#define protocol_41(A)   ((A)->server_capabilities & CLIENT_PROTOCOL_41)
 
#define AUTH_NEXT_FACTOR_PACKETTYPE   2
 

Functions

void mysql_close_free (MYSQL *mysql)
 
void mysql_close_free_options (MYSQL *mysql)
 
MYSQL_EXTENSIONmysql_extension_init (MYSQL *)
 
void mysql_extension_free (MYSQL_EXTENSION *)
 
void mysql_extension_bind_free (MYSQL_EXTENSION *ext)
 
void mysql_extension_set_server_extn (MYSQL *mysql, NET_SERVER *extn)
 Sets the MYSQL_EXTENSION::server_extn attribute by the use of NET_SERVER which contains information about compression context and compression attributes. More...
 
MYSQL_FIELDunpack_fields (MYSQL *mysql, MYSQL_ROWS *data, MEM_ROOT *alloc, uint fields, bool default_value, uint server_capabilities)
 
MYSQL_FIELDcli_read_metadata_ex (MYSQL *mysql, MEM_ROOT *alloc, unsigned long field_count, unsigned int fields)
 
MYSQL_FIELDcli_read_metadata (MYSQL *mysql, unsigned long field_count, unsigned int fields)
 
MYSQL_RESuse_result (MYSQL *mysql)
 
MYSQLconnect_helper (mysql_async_connect *ctx)
 
void free_rows (MYSQL_DATA *cur)
 
void free_old_query (MYSQL *mysql)
 
void end_server (MYSQL *mysql)
 
bool mysql_reconnect (MYSQL *mysql)
 
void mysql_read_default_options (struct st_mysql_options *options, const char *filename, const char *group)
 
bool cli_advanced_command (MYSQL *mysql, enum enum_server_command command, const unsigned char *header, size_t header_length, const unsigned char *arg, size_t arg_length, bool skip_check, MYSQL_STMT *stmt)
 
unsigned long cli_safe_read (MYSQL *mysql, bool *is_data_packet)
 Read a packet from server. More...
 
enum net_async_status cli_safe_read_nonblocking (MYSQL *mysql, bool *is_data_packet, ulong *res)
 Its a non blocking version of cli_safe_read. More...
 
unsigned long cli_safe_read_with_ok (MYSQL *mysql, bool parse_ok, bool *is_data_packet)
 Read a packet from server. More...
 
void net_clear_error (NET *net)
 Clear possible error state of struct NET. More...
 
void set_stmt_errmsg (MYSQL_STMT *stmt, NET *net)
 Set statement error code, sqlstate, and error message from NET. More...
 
void set_stmt_error (MYSQL_STMT *stmt, int errcode, const char *sqlstate)
 Set statement error code, sqlstate, and error message from given errcode and sqlstate. More...
 
void set_stmt_extended_error (MYSQL_STMT *stmt, int errcode, const char *sqlstate, const char *format,...)
 Set statement error code, sqlstate, and error message from given errcode and sqlstate. More...
 
void set_mysql_error (MYSQL *mysql, int errcode, const char *sqlstate)
 Set the internal error message to mysql handler. More...
 
void set_mysql_extended_error (MYSQL *mysql, int errcode, const char *sqlstate, const char *format,...)
 Set an error message on the client. More...
 
void mpvio_info (MYSQL_VIO vio, MYSQL_PLUGIN_VIO_INFO *info)
 
int run_plugin_auth (MYSQL *mysql, char *data, uint data_len, const char *data_plugin, const char *db)
 Client side of the plugin driver authentication. More...
 
int mysql_client_plugin_init ()
 Initializes the client plugin layer. More...
 
void mysql_client_plugin_deinit ()
 Deinitializes the client plugin layer. More...
 
ucharsend_client_connect_attrs (MYSQL *mysql, uchar *buf)
 
int is_file_or_dir_world_writable (const char *filepath)
 Check if a file/dir is world-writable (only on non-Windows platforms) More...
 
void read_ok_ex (MYSQL *mysql, unsigned long len)
 
bool fix_param_bind (MYSQL_BIND *param, uint idx)
 
bool mysql_int_serialize_param_data (NET *net, unsigned int param_count, MYSQL_BIND *params, const char **names, unsigned long n_param_sets, uchar **ret_data, ulong *ret_length, uchar send_types_to_server, bool send_named_params, bool send_parameter_set_count, bool send_parameter_count_when_zero)
 Serialize the query parameters. More...
 

Variables

const char * unknown_sqlstate
 
const char * cant_connect_sqlstate
 
const char * not_error_sqlstate
 
CHARSET_INFOdefault_client_charset_info
 
struct st_mysql_client_pluginmysql_client_builtins []
 
bool libmysql_cleartext_plugin_enabled
 

Macro Definition Documentation

◆ ASYNC_DATA

#define ASYNC_DATA (   M)     (NULL != (M) ? (MYSQL_EXTENSION_PTR(M)->mysql_async_context) : NULL)

◆ AUTH_NEXT_FACTOR_PACKETTYPE

#define AUTH_NEXT_FACTOR_PACKETTYPE   2

◆ MAX_AUTHENTICATION_FACTOR

#define MAX_AUTHENTICATION_FACTOR   3

◆ MYSQL_EXTENSION_PTR

#define MYSQL_EXTENSION_PTR (   H)
Value:
((MYSQL_EXTENSION *)((H)->extension \
? (H)->extension \
: ((H)->extension = mysql_extension_init(H))))
MYSQL_EXTENSION * mysql_extension_init(MYSQL *)
Definition: client.cc:3344
Definition: sql_common.h:101

◆ MYSQL_OPTIONS_EXTENSION_PTR

#define MYSQL_OPTIONS_EXTENSION_PTR (   H,
  what 
)     ((H)->options.extension ? (H)->options.extension->what : nullptr)

◆ protocol_41

#define protocol_41 (   A)    ((A)->server_capabilities & CLIENT_PROTOCOL_41)

◆ simple_command

#define simple_command (   mysql,
  command,
  arg,
  length,
  skip_check 
)
Value:
((mysql)->methods \
? (*(mysql)->methods->advanced_command)(mysql, command, nullptr, 0, \
arg, length, skip_check, NULL) \
1))
#define CR_COMMANDS_OUT_OF_SYNC
Definition: errmsg.h:73
static MYSQL * mysql
Definition: mysqldump.cc:147
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
Definition: instrumented_condition_variable.h:32
const char * unknown_sqlstate
Definition: client.cc:220
void set_mysql_error(MYSQL *mysql, int errcode, const char *sqlstate)
Set the internal error message to mysql handler.
Definition: client.cc:343
#define NULL
Definition: types.h:55
command
Definition: version_token.cc:280

◆ simple_command_nonblocking

#define simple_command_nonblocking (   mysql,
  command,
  arg,
  length,
  skip_check,
  error 
)
Value:
(*(mysql)->methods->advanced_command_nonblocking)( \
mysql, command, nullptr, 0, arg, length, skip_check, nullptr, error)
void error(const char *format,...)

◆ stmt_command

#define stmt_command (   mysql,
  command,
  arg,
  length,
  stmt 
)
Value:
((mysql)->methods \
? (*(mysql)->methods->advanced_command)(mysql, command, nullptr, 0, \
arg, length, 1, stmt) \
1))

Function Documentation

◆ cli_advanced_command()

bool cli_advanced_command ( MYSQL mysql,
enum enum_server_command  command,
const unsigned char *  header,
size_t  header_length,
const unsigned char *  arg,
size_t  arg_length,
bool  skip_check,
MYSQL_STMT stmt 
)

◆ cli_read_metadata()

MYSQL_FIELD * cli_read_metadata ( MYSQL mysql,
unsigned long  field_count,
unsigned int  fields 
)

◆ cli_read_metadata_ex()

MYSQL_FIELD * cli_read_metadata_ex ( MYSQL mysql,
MEM_ROOT alloc,
unsigned long  field_count,
unsigned int  fields 
)

◆ cli_safe_read()

unsigned long cli_safe_read ( MYSQL mysql,
bool *  is_data_packet 
)

Read a packet from server.

Give error message if connection was broken or ERR packet was received. Detect if the packet received was an OK, ERR or something else (a "data packet").

Parameters
[in]mysqlconnection handle
[out]is_data_packetif set to true then the packet received was a "data packet".
Return values
Thelength of the packet that was read or packet_error in case of error. In case of error its description is stored in mysql handle.

◆ cli_safe_read_nonblocking()

enum net_async_status cli_safe_read_nonblocking ( MYSQL mysql,
bool *  is_data_packet,
ulong *  res 
)

Its a non blocking version of cli_safe_read.

◆ cli_safe_read_with_ok()

unsigned long cli_safe_read_with_ok ( MYSQL mysql,
bool  parse_ok,
bool *  is_data_packet 
)

Read a packet from server.

Give error message if socket was down or packet is an error message

Parameters
[in]mysqlconnection handle
[in]parse_okif set to true then parse OK packet if it is received
[out]is_data_packetif set to true then packet received is a "data packet", that is not OK or ERR packet or EOF in case of old servers
Returns
The length of the packet that was read or packet_error in case of error. In case of error its description is stored in mysql handle.

◆ connect_helper()

MYSQL * connect_helper ( mysql_async_connect ctx)

◆ end_server()

void end_server ( MYSQL mysql)

◆ fix_param_bind()

bool fix_param_bind ( MYSQL_BIND param,
uint  idx 
)

◆ free_old_query()

void free_old_query ( MYSQL mysql)

◆ free_rows()

void free_rows ( MYSQL_DATA cur)

◆ is_file_or_dir_world_writable()

int is_file_or_dir_world_writable ( const char *  path)

Check if a file/dir is world-writable (only on non-Windows platforms)

Parameters
[in]pathPath of the file/dir to be checked
Returns
Status of the file/dir check
Return values
-2Permission denied to check attributes of file/dir
-1Error in reading file/dir
0File/dir is not world-writable
1File/dir is world-writable

◆ mpvio_info()

void mpvio_info ( MYSQL_VIO  vio,
MYSQL_PLUGIN_VIO_INFO info 
)

◆ mysql_client_plugin_deinit()

void mysql_client_plugin_deinit ( )

Deinitializes the client plugin layer.

Unloades all client plugins and frees any associated resources.

◆ mysql_client_plugin_init()

int mysql_client_plugin_init ( )

Initializes the client plugin layer.

This function must be called before any other client plugin function.

Return values
0successful
!=0 error occurred

◆ mysql_close_free()

void mysql_close_free ( MYSQL mysql)

◆ mysql_close_free_options()

void mysql_close_free_options ( MYSQL mysql)

◆ mysql_extension_bind_free()

void mysql_extension_bind_free ( MYSQL_EXTENSION ext)

◆ mysql_extension_free()

void mysql_extension_free ( MYSQL_EXTENSION ext)

◆ mysql_extension_init()

MYSQL_EXTENSION * mysql_extension_init ( MYSQL mysql)

◆ mysql_extension_set_server_extn()

void mysql_extension_set_server_extn ( MYSQL mysql,
NET_SERVER extn 
)
inline

Sets the MYSQL_EXTENSION::server_extn attribute by the use of NET_SERVER which contains information about compression context and compression attributes.

This attribute needs to be set each time mysql_real_connect() is called to make a connection. When a connection attempt fails or when a connection is closed, as part of the MYSQL handle cleanup, mysql_close_free() is called and that will free MYSQL_EXTENSION::server_extn.

mysql_close_free() will free all the memory allocated in the MYSQL handle but preserves MYSQL::options. These options are later free'd by mysql_close_free_options() unless the client flag CLIENT_REMEMBER_OPTIONS is set.

Parameters
mysqlThe MYSQL handle
extnThe NET_SERVER handle that contains compression context info.

◆ mysql_int_serialize_param_data()

bool mysql_int_serialize_param_data ( NET net,
unsigned int  param_count,
MYSQL_BIND params,
const char **  names,
unsigned long  n_param_sets,
uchar **  ret_data,
ulong *  ret_length,
uchar  send_types_to_server,
bool  send_named_params,
bool  send_parameter_set_count,
bool  send_parameter_count_when_zero 
)

Serialize the query parameters.

Used by mysql_real_query, mysql_real_query_nonblocking and mysql_stmt_execute()

Must be called on connected sessions only.

Parameters
netthe NET to use as a string buffer serializing the params. It's cleared at start.
param_countthe number of parameters to send
paramsthe filled in MYSQL_BIND structure to retrieve the values from
namesthe names of the parameters in the params argument
n_param_setsthe number of sets of values to set
[out]ret_datathe buffer to the serialized parameter representation
[out]ret_lengththe number of bytes stored into the buffer
send_types_to_server: whether to send the parameter types to the server or not
send_named_params: whether the names of the parameters should be sent
send_parameter_set_count: whether to send 1 as parameter count or not
send_parameter_count_when_zeroON to send the param count even when it's zero
Return values
trueexecution failed. Error in NET
falseexecution succeeded

◆ mysql_read_default_options()

void mysql_read_default_options ( struct st_mysql_options options,
const char *  filename,
const char *  group 
)

◆ mysql_reconnect()

bool mysql_reconnect ( MYSQL mysql)

◆ net_clear_error()

void net_clear_error ( NET net)

Clear possible error state of struct NET.

Parameters
netclear the state of the argument

◆ read_ok_ex()

void read_ok_ex ( MYSQL mysql,
unsigned long  len 
)

◆ run_plugin_auth()

int run_plugin_auth ( MYSQL mysql,
char *  data,
uint  data_len,
const char *  data_plugin,
const char *  db 
)

Client side of the plugin driver authentication.

Note
this is used by both the mysql_real_connect and mysql_change_user
Parameters
mysqlmysql
datapointer to the plugin auth data (scramble) in the handshake packet
data_lenthe length of the data
data_plugina plugin that data were prepared for or 0 if it's mysql_change_user()
dbinitial db to use, can be 0
Return values
0ok
1error

◆ send_client_connect_attrs()

uchar * send_client_connect_attrs ( MYSQL mysql,
uchar buf 
)

◆ set_mysql_error()

void set_mysql_error ( MYSQL mysql,
int  errcode,
const char *  sqlstate 
)

Set the internal error message to mysql handler.

Parameters
mysqlconnection handle (client side)
errcodeCR_ error code, passed to ER macro to get error text
sqlstateSQL standard sqlstate

◆ set_mysql_extended_error()

void set_mysql_extended_error ( MYSQL mysql,
int  errcode,
const char *  sqlstate,
const char *  format,
  ... 
)

Set an error message on the client.

Parameters
mysqlconnection handle
errcodeCR_* errcode, for client errors
sqlstateSQL standard sql state, unknown_sqlstate for the majority of client errors.
formaterror message template, in sprintf format
...variable number of arguments

◆ set_stmt_errmsg()

void set_stmt_errmsg ( MYSQL_STMT stmt,
NET net 
)

Set statement error code, sqlstate, and error message from NET.

Parameters
stmta statement handle. Copy the error here.
netmysql->net. Source of the error.

◆ set_stmt_error()

void set_stmt_error ( MYSQL_STMT stmt,
int  errcode,
const char *  sqlstate 
)

Set statement error code, sqlstate, and error message from given errcode and sqlstate.

◆ set_stmt_extended_error()

void set_stmt_extended_error ( MYSQL_STMT stmt,
int  errcode,
const char *  sqlstate,
const char *  format,
  ... 
)

Set statement error code, sqlstate, and error message from given errcode and sqlstate.

◆ unpack_fields()

MYSQL_FIELD * unpack_fields ( MYSQL mysql,
MYSQL_ROWS data,
MEM_ROOT alloc,
uint  fields,
bool  default_value,
uint  server_capabilities 
)

◆ use_result()

MYSQL_RES * use_result ( MYSQL mysql)

Variable Documentation

◆ cant_connect_sqlstate

const char* cant_connect_sqlstate
extern

◆ default_client_charset_info

CHARSET_INFO* default_client_charset_info
extern

◆ libmysql_cleartext_plugin_enabled

bool libmysql_cleartext_plugin_enabled
extern

◆ mysql_client_builtins

struct st_mysql_client_plugin* mysql_client_builtins[]
extern

◆ not_error_sqlstate

const char* not_error_sqlstate
extern

◆ unknown_sqlstate

const char* unknown_sqlstate
extern