MySQL  8.0.16
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"

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  st_mysql_options_extention
 
struct  MYSQL_METHODS
 

Macros

#define SQL_COMMON_INCLUDED
 
#define MYSQL_EXTENSION_PTR(H)
 
#define ASYNC_DATA(M)   (NULL != (M) ? (MYSQL_EXTENSION_PTR(M)->mysql_async_context) : NULL)
 
#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)
 

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 *)
 
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)
 Read metadata resultset from server Memory allocated in a given allocator root. More...
 
MYSQL_FIELDcli_read_metadata (MYSQL *mysql, unsigned long field_count, unsigned int fields)
 Read metadata resultset from server. More...
 
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, const char *err)
 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)
 Read Ok packet along with the server state change information. 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)

◆ MYSQL_EXTENSION_PTR

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

◆ 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, 0, 0, arg, \
length, skip_check, NULL) \
1))
void set_mysql_error(MYSQL *mysql, int errcode, const char *sqlstate)
Set the internal error message to mysql handler.
Definition: client.cc:296
Sergei Dialog Client Authentication NULL
Definition: dialog.cc:352
#define CR_COMMANDS_OUT_OF_SYNC
Definition: errmsg.h:72
command
Definition: version_token.cc:278
static MYSQL mysql
Definition: mysql.cc:150
const char * unknown_sqlstate
Definition: client.cc:196
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:75

◆ simple_command_nonblocking

#define simple_command_nonblocking (   mysql,
  command,
  arg,
  length,
  skip_check,
  error 
)
Value:
(*(mysql)->methods->advanced_command_nonblocking)( \
mysql, command, 0, 0, arg, length, skip_check, NULL, error)
Sergei Dialog Client Authentication NULL
Definition: dialog.cc:352
command
Definition: version_token.cc:278
static MYSQL mysql
Definition: mysql.cc:150
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:75
Log error(cerr, "ERROR")

◆ SQL_COMMON_INCLUDED

#define SQL_COMMON_INCLUDED

◆ stmt_command

#define stmt_command (   mysql,
  command,
  arg,
  length,
  stmt 
)
Value:
((mysql)->methods \
? (*(mysql)->methods->advanced_command)(mysql, command, 0, 0, arg, \
length, 1, stmt) \
1))
void set_mysql_error(MYSQL *mysql, int errcode, const char *sqlstate)
Set the internal error message to mysql handler.
Definition: client.cc:296
#define CR_COMMANDS_OUT_OF_SYNC
Definition: errmsg.h:72
command
Definition: version_token.cc:278
static MYSQL mysql
Definition: mysql.cc:150
const char * unknown_sqlstate
Definition: client.cc:196
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:75

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,
ulong  field_count,
unsigned int  field 
)

Read metadata resultset from server.

Parameters
[in]mysqlconnection handle
[in]field_counttotal number of fields
[in]fieldnumber of columns in single field descriptor
Return values
anarray of field rows

◆ cli_read_metadata_ex()

MYSQL_FIELD* cli_read_metadata_ex ( MYSQL mysql,
MEM_ROOT alloc,
ulong  field_count,
unsigned int  field 
)

Read metadata resultset from server Memory allocated in a given allocator root.

Parameters
[in]mysqlconnection handle
[in]allocmemory allocator root
[in]field_counttotal number of fields
[in]fieldnumber of columns in single field descriptor
Return values
anarray of field rows

◆ 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.

◆ end_server()

void end_server ( MYSQL mysql)

◆ 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 occured

◆ mysql_close_free()

void mysql_close_free ( MYSQL mysql)

◆ mysql_close_free_options()

void mysql_close_free_options ( MYSQL mysql)

◆ mysql_extension_free()

void mysql_extension_free ( MYSQL_EXTENSION )

◆ mysql_extension_init()

MYSQL_EXTENSION* mysql_extension_init ( MYSQL )

◆ 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 
)

Read Ok packet along with the server state change information.

◆ 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,
const char *  err 
)

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 
)

Variable Documentation

◆ cant_connect_sqlstate

const char* cant_connect_sqlstate

◆ default_client_charset_info

CHARSET_INFO* default_client_charset_info

◆ libmysql_cleartext_plugin_enabled

bool libmysql_cleartext_plugin_enabled

◆ mysql_client_builtins

struct st_mysql_client_plugin* mysql_client_builtins[]

◆ not_error_sqlstate

const char* not_error_sqlstate

◆ unknown_sqlstate

const char* unknown_sqlstate