- Refactor the command factory. Let the factory be exchangeable.
enum_func_status ret = FAIL;
DBG_ENTER("mysqlnd_conn_data::set_server_option");
if (PASS == conn->m->local_tx_start(conn, this_func)) {
- struct st_mysqlnd_protocol_command * command = mysqlnd_get_command(COM_SET_OPTION, conn, option);
+ struct st_mysqlnd_protocol_command * command = conn->command_factory(COM_SET_OPTION, conn, option);
if (command) {
ret = command->run(command);
command->free_command(command);
if (type == MYSQLND_SEND_QUERY_IMPLICIT || PASS == conn->m->local_tx_start(conn, this_func))
{
const MYSQLND_CSTRING query_string = {query, query_len};
- struct st_mysqlnd_protocol_command * command = mysqlnd_get_command(COM_QUERY, conn, query_string);
+ struct st_mysqlnd_protocol_command * command = conn->command_factory(COM_QUERY, conn, query_string);
if (command) {
ret = command->run(command);
command->free_command(command);
DBG_INF_FMT("conn->server_status=%u", conn->upsert_status->server_status);
if (type == MYSQLND_REAP_RESULT_IMPLICIT || PASS == conn->m->local_tx_start(conn, this_func))
{
- struct st_mysqlnd_protocol_command * command = mysqlnd_get_command(COM_REAP_RESULT, conn);
+ struct st_mysqlnd_protocol_command * command = conn->command_factory(COM_REAP_RESULT, conn);
if (command) {
ret = command->run(command);
command->free_command(command);
const MYSQLND_CSTRING tbl = {table, strlen(table)};
const MYSQLND_CSTRING wildcard = {achtung_wild, strlen(achtung_wild)};
- struct st_mysqlnd_protocol_command * command = mysqlnd_get_command(COM_FIELD_LIST, conn, tbl, wildcard);
+ struct st_mysqlnd_protocol_command * command = conn->command_factory(COM_FIELD_LIST, conn, tbl, wildcard);
if (command) {
ret = command->run(command);
command->free_command(command);
DBG_ENTER("mysqlnd_conn_data::dump_debug_info");
DBG_INF_FMT("conn=%llu", conn->thread_id);
if (PASS == conn->m->local_tx_start(conn, this_func)) {
- struct st_mysqlnd_protocol_command * command = mysqlnd_get_command(COM_DEBUG, conn);
+ struct st_mysqlnd_protocol_command * command = conn->command_factory(COM_DEBUG, conn);
if (command) {
ret = command->run(command);
command->free_command(command);
if (PASS == conn->m->local_tx_start(conn, this_func)) {
const MYSQLND_CSTRING database = {db, db_len};
- struct st_mysqlnd_protocol_command * command = mysqlnd_get_command(COM_INIT_DB, conn, database);
+ struct st_mysqlnd_protocol_command * command = conn->command_factory(COM_INIT_DB, conn, database);
if (command) {
ret = command->run(command);
command->free_command(command);
DBG_INF_FMT("conn=%llu", conn->thread_id);
if (PASS == conn->m->local_tx_start(conn, this_func)) {
- struct st_mysqlnd_protocol_command * command = mysqlnd_get_command(COM_PING, conn);
+ struct st_mysqlnd_protocol_command * command = conn->command_factory(COM_PING, conn);
if (command) {
ret = command->run(command);
command->free_command(command);
if (PASS == conn->m->local_tx_start(conn, this_func)) {
do {
- struct st_mysqlnd_protocol_command * command = mysqlnd_get_command(COM_STATISTICS, conn);
+ struct st_mysqlnd_protocol_command * command = conn->command_factory(COM_STATISTICS, conn);
if (command) {
ret = command->run(command);
command->free_command(command);
unsigned int process_id = pid;
/* 'unsigned char' is promoted to 'int' when passed through '...' */
unsigned int read_response = (pid != conn->thread_id);
- struct st_mysqlnd_protocol_command * command = mysqlnd_get_command(COM_PROCESS_KILL, conn, process_id, read_response);
+ struct st_mysqlnd_protocol_command * command = conn->command_factory(COM_PROCESS_KILL, conn, process_id, read_response);
if (command) {
ret = command->run(command);
command->free_command(command);
if (PASS == conn->m->local_tx_start(conn, this_func)) {
unsigned int options_param = (unsigned int) options;
- struct st_mysqlnd_protocol_command * command = mysqlnd_get_command(COM_REFRESH, conn, options_param);
+ struct st_mysqlnd_protocol_command * command = conn->command_factory(COM_REFRESH, conn, options_param);
if (command) {
ret = command->run(command);
command->free_command(command);
if (PASS == conn->m->local_tx_start(conn, this_func)) {
unsigned int level_param = (unsigned int) level;
- struct st_mysqlnd_protocol_command * command = mysqlnd_get_command(COM_SHUTDOWN, conn, level_param);
+ struct st_mysqlnd_protocol_command * command = conn->command_factory(COM_SHUTDOWN, conn, level_param);
if (command) {
ret = command->run(command);
command->free_command(command);
case CONN_READY:
DBG_INF("Connection clean, sending COM_QUIT");
if (net_stream) {
- struct st_mysqlnd_protocol_command * command = mysqlnd_get_command(COM_QUIT, conn);
+ struct st_mysqlnd_protocol_command * command = conn->command_factory(COM_QUIT, conn);
if (command) {
ret = command->run(command);
command->free_command(command);
/* }}} */
-struct st_mysqlnd_protocol_no_params_command
-{
- struct st_mysqlnd_protocol_command parent;
- struct st_mysqlnd_protocol_no_params_command_context
- {
- MYSQLND_CONN_DATA * conn;
- } context;
-};
-
-/* {{{ mysqlnd_com_no_params_free_command */
-static void
-mysqlnd_com_no_params_free_command(void * command)
-{
- DBG_ENTER("mysqlnd_com_no_params_free_command");
- mnd_efree(command);
- DBG_VOID_RETURN;
-}
-/* }}} */
-
-
-/************************** COM_SET_OPTION ******************************************/
-struct st_mysqlnd_protocol_com_set_option_command
-{
- struct st_mysqlnd_protocol_command parent;
- struct st_mysqlnd_com_set_option_context
- {
- MYSQLND_CONN_DATA * conn;
- enum_mysqlnd_server_option option;
- } context;
-};
-
-
-/* {{{ mysqlnd_com_set_option_run */
-enum_func_status
-mysqlnd_com_set_option_run(void *cmd)
-{
- struct st_mysqlnd_protocol_com_set_option_command * command = (struct st_mysqlnd_protocol_com_set_option_command *) cmd;
- zend_uchar buffer[2];
- enum_func_status ret = FAIL;
- MYSQLND_CONN_DATA * conn = command->context.conn;
- enum_mysqlnd_server_option option = command->context.option;
-
- DBG_ENTER("mysqlnd_com_set_option_run");
- int2store(buffer, (unsigned int) option);
-
- ret = conn->m->send_command_do_request(conn, COM_SET_OPTION, buffer, sizeof(buffer), FALSE, TRUE);
- if (PASS == ret) {
- ret = conn->m->send_command_handle_response(conn, PROT_EOF_PACKET, FALSE, COM_SET_OPTION, TRUE);
- }
-
- DBG_RETURN(ret);
-}
-/* }}} */
-
-
-/* {{{ mysqlnd_com_set_option_create_command */
-static struct st_mysqlnd_protocol_command *
-mysqlnd_com_set_option_create_command(va_list args)
-{
- struct st_mysqlnd_protocol_com_set_option_command * command;
- DBG_ENTER("mysqlnd_com_set_option_create_command");
- command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_set_option_command));
- if (command) {
- command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
- command->context.option = va_arg(args, enum_mysqlnd_server_option);
-
- command->parent.free_command = mysqlnd_com_no_params_free_command;
- command->parent.run = mysqlnd_com_set_option_run;
- }
-
- DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
-}
-/* }}} */
-
-
-/************************** COM_DEBUG ******************************************/
-/* {{{ mysqlnd_com_debug_run */
-static enum_func_status
-mysqlnd_com_debug_run(void *cmd)
-{
- struct st_mysqlnd_protocol_no_params_command * command = (struct st_mysqlnd_protocol_no_params_command *) cmd;
- enum_func_status ret = FAIL;
- MYSQLND_CONN_DATA * conn = command->context.conn;
-
- DBG_ENTER("mysqlnd_com_debug_run");
-
- ret = conn->m->send_command_do_request(conn, COM_DEBUG, NULL, 0, FALSE, TRUE);
- if (PASS == ret) {
- ret = conn->m->send_command_handle_response(conn, PROT_EOF_PACKET, COM_DEBUG, COM_DEBUG, TRUE);
- }
-
- DBG_RETURN(ret);
-}
-/* }}} */
-
-
-/* {{{ mysqlnd_com_debug_create_command */
-static struct st_mysqlnd_protocol_command *
-mysqlnd_com_debug_create_command(va_list args)
-{
- struct st_mysqlnd_protocol_no_params_command * command;
- DBG_ENTER("mysqlnd_com_debug_create_command");
- command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_no_params_command));
- if (command) {
- command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
- command->parent.free_command = mysqlnd_com_no_params_free_command;
-
- command->parent.run = mysqlnd_com_debug_run;
- }
-
- DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
-}
-/* }}} */
-
-
-/************************** COM_INIT_DB ******************************************/
-struct st_mysqlnd_protocol_com_init_db_command
-{
- struct st_mysqlnd_protocol_command parent;
- struct st_mysqlnd_com_init_db_context
- {
- MYSQLND_CONN_DATA * conn;
- MYSQLND_CSTRING db;
- } context;
-};
-
-
-/* {{{ mysqlnd_com_init_db_run */
-static enum_func_status
-mysqlnd_com_init_db_run(void *cmd)
-{
- struct st_mysqlnd_protocol_com_init_db_command * command = (struct st_mysqlnd_protocol_com_init_db_command *) cmd;
- enum_func_status ret = FAIL;
- MYSQLND_CONN_DATA * conn = command->context.conn;
-
- DBG_ENTER("mysqlnd_com_init_db_run");
-
- ret = conn->m->send_command_do_request(conn, COM_INIT_DB, (zend_uchar*) command->context.db.s, command->context.db.l, FALSE, TRUE);
- if (PASS == ret) {
- ret = conn->m->send_command_handle_response(conn, PROT_OK_PACKET, FALSE, COM_INIT_DB, TRUE);
- }
-
- DBG_RETURN(ret);
-}
-/* }}} */
-
-
-/* {{{ mysqlnd_com_init_db_create_command */
-static struct st_mysqlnd_protocol_command *
-mysqlnd_com_init_db_create_command(va_list args)
-{
- struct st_mysqlnd_protocol_com_init_db_command * command;
- DBG_ENTER("mysqlnd_com_init_db_create_command");
- command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_init_db_command));
- if (command) {
- command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
- command->context.db = va_arg(args, MYSQLND_CSTRING);
-
- command->parent.free_command = mysqlnd_com_no_params_free_command;
- command->parent.run = mysqlnd_com_init_db_run;
- }
-
- DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
-}
-/* }}} */
-
-
-/************************** COM_PING ******************************************/
-/* {{{ mysqlnd_com_ping_run */
-static enum_func_status
-mysqlnd_com_ping_run(void *cmd)
-{
- struct st_mysqlnd_protocol_no_params_command * command = (struct st_mysqlnd_protocol_no_params_command *) cmd;
- enum_func_status ret = FAIL;
- MYSQLND_CONN_DATA * conn = command->context.conn;
-
- DBG_ENTER("mysqlnd_com_ping_run");
-
- ret = conn->m->send_command_do_request(conn, COM_PING, NULL, 0, TRUE, TRUE);
- if (PASS == ret) {
- ret = conn->m->send_command_handle_response(conn, PROT_OK_PACKET, TRUE, COM_PING, TRUE);
- }
-
- DBG_RETURN(ret);
-}
-/* }}} */
-
-
-/* {{{ mysqlnd_com_ping_create_command */
-static struct st_mysqlnd_protocol_command *
-mysqlnd_com_ping_create_command(va_list args)
-{
- struct st_mysqlnd_protocol_no_params_command * command;
- DBG_ENTER("mysqlnd_com_ping_create_command");
- command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_no_params_command));
- if (command) {
- command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
- command->parent.free_command = mysqlnd_com_no_params_free_command;
-
- command->parent.run = mysqlnd_com_ping_run;
- }
-
- DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
-}
-/* }}} */
-
-/************************** COM_FIELD_LIST ******************************************/
-struct st_mysqlnd_protocol_com_field_list_command
-{
- struct st_mysqlnd_protocol_command parent;
- struct st_mysqlnd_com_field_list_context
- {
- MYSQLND_CONN_DATA * conn;
- MYSQLND_CSTRING table;
- MYSQLND_CSTRING achtung_wild;
- } context;
-};
-
-
-/* {{{ mysqlnd_com_field_list_run */
-static enum_func_status
-mysqlnd_com_field_list_run(void *cmd)
-{
- struct st_mysqlnd_protocol_com_field_list_command * command = (struct st_mysqlnd_protocol_com_field_list_command *) cmd;
- enum_func_status ret = FAIL;
- MYSQLND_CONN_DATA * conn = command->context.conn;
- /* db + \0 + wild + \0 (for wild) */
- zend_uchar buff[MYSQLND_MAX_ALLOWED_DB_LEN * 2 + 1 + 1], *p;
- size_t table_len, wild_len;
-
- DBG_ENTER("mysqlnd_com_field_list_run");
-
- if (command->context.table.s && command->context.table.l) {
- size_t to_copy = MIN(command->context.table.l, MYSQLND_MAX_ALLOWED_DB_LEN);
- memcpy(p, command->context.table.s, to_copy);
- p += to_copy;
- *p++ = '\0';
- }
-
- if (command->context.achtung_wild.s && command->context.achtung_wild.l) {
- size_t to_copy = MIN(command->context.achtung_wild.l, MYSQLND_MAX_ALLOWED_DB_LEN);
- memcpy(p, command->context.achtung_wild.s, to_copy);
- p += to_copy;
- *p++ = '\0';
- }
-
- ret = conn->m->send_command_do_request(conn, COM_FIELD_LIST, buff, p - buff, FALSE, TRUE);
-
- DBG_RETURN(ret);
-}
-/* }}} */
-
-
-/* {{{ mysqlnd_com_field_list_create_command */
-static struct st_mysqlnd_protocol_command *
-mysqlnd_com_field_list_create_command(va_list args)
-{
- struct st_mysqlnd_protocol_com_field_list_command * command;
- DBG_ENTER("mysqlnd_com_field_list_create_command");
- command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_field_list_command));
- if (command) {
- command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
- command->context.table = va_arg(args, MYSQLND_CSTRING);
- command->context.achtung_wild = va_arg(args, MYSQLND_CSTRING);
-
- command->parent.free_command = mysqlnd_com_no_params_free_command;
- command->parent.run = mysqlnd_com_field_list_run;
- }
-
- DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
-}
-/* }}} */
-
-
-/************************** COM_STATISTICS ******************************************/
-/* {{{ mysqlnd_com_statistics_run */
-static enum_func_status
-mysqlnd_com_statistics_run(void *cmd)
-{
- struct st_mysqlnd_protocol_no_params_command * command = (struct st_mysqlnd_protocol_no_params_command *) cmd;
- enum_func_status ret = FAIL;
- MYSQLND_CONN_DATA * conn = command->context.conn;
-
- DBG_ENTER("mysqlnd_com_statistics_run");
-
- ret = conn->m->send_command_do_request(conn, COM_STATISTICS, NULL, 0, FALSE, TRUE);
-
- DBG_RETURN(ret);
-}
-/* }}} */
-
-
-/* {{{ mysqlnd_com_statistics_create_command */
-static struct st_mysqlnd_protocol_command *
-mysqlnd_com_statistics_create_command(va_list args)
-{
- struct st_mysqlnd_protocol_no_params_command * command;
- DBG_ENTER("mysqlnd_com_statistics_create_command");
- command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_no_params_command));
- if (command) {
- command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
- command->parent.free_command = mysqlnd_com_no_params_free_command;
-
- command->parent.run = mysqlnd_com_statistics_run;
- }
-
- DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
-}
-/* }}} */
-
-/************************** COM_PROCESS_KILL ******************************************/
-struct st_mysqlnd_protocol_com_process_kill_command
-{
- struct st_mysqlnd_protocol_command parent;
- struct st_mysqlnd_com_process_kill_context
- {
- MYSQLND_CONN_DATA * conn;
- unsigned int process_id;
- zend_bool read_response;
- } context;
-};
-
-
-/* {{{ mysqlnd_com_process_kill_run */
-enum_func_status
-mysqlnd_com_process_kill_run(void *cmd)
-{
- struct st_mysqlnd_protocol_com_process_kill_command * command = (struct st_mysqlnd_protocol_com_process_kill_command *) cmd;
- zend_uchar buff[4];
- enum_func_status ret = FAIL;
- MYSQLND_CONN_DATA * conn = command->context.conn;
-
- DBG_ENTER("mysqlnd_com_process_kill_run");
- int4store(buff, command->context.process_id);
-
- ret = conn->m->send_command_do_request(conn, COM_PROCESS_KILL, buff, 4, FALSE, TRUE);
- if (PASS == ret && command->context.read_response) {
- ret = conn->m->send_command_handle_response(conn, PROT_OK_PACKET, FALSE, COM_PROCESS_KILL, TRUE);
- }
-
- DBG_RETURN(ret);
-}
-/* }}} */
-
-
-/* {{{ mysqlnd_com_process_kill_create_command */
-static struct st_mysqlnd_protocol_command *
-mysqlnd_com_process_kill_create_command(va_list args)
-{
- struct st_mysqlnd_protocol_com_process_kill_command * command;
- DBG_ENTER("mysqlnd_com_process_kill_create_command");
- command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_process_kill_command));
- if (command) {
- command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
- command->context.process_id = va_arg(args, unsigned int);
- command->context.read_response = va_arg(args, unsigned int)? TRUE:FALSE;
-
- command->parent.free_command = mysqlnd_com_no_params_free_command;
- command->parent.run = mysqlnd_com_process_kill_run;
- }
-
- DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
-}
-/* }}} */
-
-/************************** COM_REFRESH ******************************************/
-struct st_mysqlnd_protocol_com_refresh_command
-{
- struct st_mysqlnd_protocol_command parent;
- struct st_mysqlnd_com_refresh_context
- {
- MYSQLND_CONN_DATA * conn;
- uint8_t options;
- } context;
-};
-
-
-/* {{{ mysqlnd_com_refresh_run */
-enum_func_status
-mysqlnd_com_refresh_run(void *cmd)
-{
- struct st_mysqlnd_protocol_com_refresh_command * command = (struct st_mysqlnd_protocol_com_refresh_command *) cmd;
- zend_uchar bits[1];
- enum_func_status ret = FAIL;
- MYSQLND_CONN_DATA * conn = command->context.conn;
-
- DBG_ENTER("mysqlnd_com_refresh_run");
- int1store(bits, command->context.options);
-
- ret = conn->m->send_command_do_request(conn, COM_REFRESH, bits, 1, FALSE, TRUE);
- if (PASS == ret) {
- ret = conn->m->send_command_handle_response(conn, PROT_OK_PACKET, FALSE, COM_REFRESH, TRUE);
- }
-
- DBG_RETURN(ret);
-}
-/* }}} */
-
-
-/* {{{ mysqlnd_com_refresh_create_command */
-static struct st_mysqlnd_protocol_command *
-mysqlnd_com_refresh_create_command(va_list args)
-{
- struct st_mysqlnd_protocol_com_refresh_command * command;
- DBG_ENTER("mysqlnd_com_refresh_create_command");
- command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_refresh_command));
- if (command) {
- command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
- command->context.options = va_arg(args, unsigned int);
-
- command->parent.free_command = mysqlnd_com_no_params_free_command;
- command->parent.run = mysqlnd_com_refresh_run;
- }
-
- DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
-}
-/* }}} */
-
-
-/************************** COM_SHUTDOWN ******************************************/
-struct st_mysqlnd_protocol_com_shutdown_command
-{
- struct st_mysqlnd_protocol_command parent;
- struct st_mysqlnd_com_shutdown_context
- {
- MYSQLND_CONN_DATA * conn;
- uint8_t level;
- } context;
-};
-
-
-/* {{{ mysqlnd_com_shutdown_run */
-enum_func_status
-mysqlnd_com_shutdown_run(void *cmd)
-{
- struct st_mysqlnd_protocol_com_shutdown_command * command = (struct st_mysqlnd_protocol_com_shutdown_command *) cmd;
- zend_uchar bits[1];
- enum_func_status ret = FAIL;
- MYSQLND_CONN_DATA * conn = command->context.conn;
-
- DBG_ENTER("mysqlnd_com_shutdown_run");
- int1store(bits, command->context.level);
-
- ret = conn->m->send_command_do_request(conn, COM_SHUTDOWN, bits, 1, FALSE, TRUE);
- if (PASS == ret) {
- ret = conn->m->send_command_handle_response(conn, PROT_OK_PACKET, FALSE, COM_SHUTDOWN, TRUE);
- }
-
- DBG_RETURN(ret);
-}
-/* }}} */
-
-
-/* {{{ mysqlnd_com_shutdown_create_command */
-static struct st_mysqlnd_protocol_command *
-mysqlnd_com_shutdown_create_command(va_list args)
-{
- struct st_mysqlnd_protocol_com_shutdown_command * command;
- DBG_ENTER("mysqlnd_com_shutdown_create_command");
- command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_shutdown_command));
- if (command) {
- command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
- command->context.level = va_arg(args, unsigned int);
-
- command->parent.free_command = mysqlnd_com_no_params_free_command;
- command->parent.run = mysqlnd_com_shutdown_run;
- }
-
- DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
-}
-/* }}} */
-
-
-/************************** COM_QUIT ******************************************/
-struct st_mysqlnd_protocol_com_quit_command
-{
- struct st_mysqlnd_protocol_command parent;
- struct st_mysqlnd_com_quit_context
- {
- MYSQLND_CONN_DATA * conn;
- } context;
-};
-
-
-/* {{{ mysqlnd_com_quit_run */
-enum_func_status
-mysqlnd_com_quit_run(void *cmd)
-{
- struct st_mysqlnd_protocol_com_quit_command * command = (struct st_mysqlnd_protocol_com_quit_command *) cmd;
- zend_uchar bits[1];
- enum_func_status ret = FAIL;
- MYSQLND_CONN_DATA * conn = command->context.conn;
-
- DBG_ENTER("mysqlnd_com_quit_run");
-
- ret = conn->m->send_command_do_request(conn, COM_QUIT, NULL, 0, TRUE, TRUE);
-
- DBG_RETURN(ret);
-}
-/* }}} */
-
-
-/* {{{ mysqlnd_com_quit_create_command */
-static struct st_mysqlnd_protocol_command *
-mysqlnd_com_quit_create_command(va_list args)
-{
- struct st_mysqlnd_protocol_com_quit_command * command;
- DBG_ENTER("mysqlnd_com_quit_create_command");
- command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_quit_command));
- if (command) {
- command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
-
- command->parent.free_command = mysqlnd_com_no_params_free_command;
- command->parent.run = mysqlnd_com_quit_run;
- }
-
- DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
-}
-/* }}} */
-
-/************************** COM_QUERY ******************************************/
-struct st_mysqlnd_protocol_com_query_command
-{
- struct st_mysqlnd_protocol_command parent;
- struct st_mysqlnd_com_query_context
- {
- MYSQLND_CONN_DATA * conn;
- MYSQLND_CSTRING query;
- } context;
-};
-
-
-/* {{{ mysqlnd_com_query_run */
-static enum_func_status
-mysqlnd_com_query_run(void *cmd)
-{
- struct st_mysqlnd_protocol_com_query_command * command = (struct st_mysqlnd_protocol_com_query_command *) cmd;
- enum_func_status ret = FAIL;
- MYSQLND_CONN_DATA * conn = command->context.conn;
-
- DBG_ENTER("mysqlnd_com_query_run");
-
- ret = conn->m->send_command_do_request(conn, COM_QUERY, (zend_uchar*) command->context.query.s, command->context.query.l, FALSE, FALSE);
-
- if (PASS == ret) {
- CONN_SET_STATE(conn, CONN_QUERY_SENT);
- }
-
- DBG_RETURN(ret);
-}
-/* }}} */
-
-
-/* {{{ mysqlnd_com_query_create_command */
-static struct st_mysqlnd_protocol_command *
-mysqlnd_com_query_create_command(va_list args)
-{
- struct st_mysqlnd_protocol_com_query_command * command;
- DBG_ENTER("mysqlnd_com_query_create_command");
- command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_query_command));
- if (command) {
- command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
- command->context.query = va_arg(args, MYSQLND_CSTRING);
-
- command->parent.free_command = mysqlnd_com_no_params_free_command;
- command->parent.run = mysqlnd_com_query_run;
- }
-
- DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
-}
-/* }}} */
-
-/************************** COM_CHANGE_USER ******************************************/
-struct st_mysqlnd_protocol_com_change_user_command
-{
- struct st_mysqlnd_protocol_command parent;
- struct st_mysqlnd_com_change_user_context
- {
- MYSQLND_CONN_DATA * conn;
- MYSQLND_CSTRING payload;
- zend_bool silent;
- } context;
-};
-
-
-/* {{{ mysqlnd_com_change_user_run */
-static enum_func_status
-mysqlnd_com_change_user_run(void *cmd)
-{
- struct st_mysqlnd_protocol_com_change_user_command * command = (struct st_mysqlnd_protocol_com_change_user_command *) cmd;
- enum_func_status ret = FAIL;
- MYSQLND_CONN_DATA * conn = command->context.conn;
-
- DBG_ENTER("mysqlnd_com_change_user_run");
-
- ret = conn->m->send_command_do_request(conn, COM_CHANGE_USER, (zend_uchar*) command->context.payload.s, command->context.payload.l, command->context.silent, TRUE);
-
- DBG_RETURN(ret);
-}
-/* }}} */
-
-
-/* {{{ mysqlnd_com_change_user_create_command */
-static struct st_mysqlnd_protocol_command *
-mysqlnd_com_change_user_create_command(va_list args)
-{
- struct st_mysqlnd_protocol_com_change_user_command * command;
- DBG_ENTER("mysqlnd_com_change_user_create_command");
- command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_change_user_command));
- if (command) {
- command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
- command->context.payload = va_arg(args, MYSQLND_CSTRING);
- command->context.silent = va_arg(args, unsigned int);
-
- command->parent.free_command = mysqlnd_com_no_params_free_command;
- command->parent.run = mysqlnd_com_change_user_run;
- }
-
- DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
-}
-/* }}} */
-
-
-/************************** COM_REAP_RESULT ******************************************/
-struct st_mysqlnd_protocol_com_reap_result_command
-{
- struct st_mysqlnd_protocol_command parent;
- struct st_mysqlnd_com_reap_result_context
- {
- MYSQLND_CONN_DATA * conn;
- } context;
-};
-
-
-/* {{{ mysqlnd_com_reap_result_run */
-static enum_func_status
-mysqlnd_com_reap_result_run(void *cmd)
-{
- struct st_mysqlnd_protocol_com_reap_result_command * command = (struct st_mysqlnd_protocol_com_reap_result_command *) cmd;
- enum_func_status ret = FAIL;
- MYSQLND_CONN_DATA * conn = command->context.conn;
- enum_mysqlnd_connection_state state = CONN_GET_STATE(conn);
-
- DBG_ENTER("mysqlnd_com_reap_result_run");
- if (state <= CONN_READY || state == CONN_QUIT_SENT) {
- php_error_docref(NULL, E_WARNING, "Connection not opened, clear or has been closed");
- DBG_ERR_FMT("Connection not opened, clear or has been closed. State=%u", state);
- DBG_RETURN(ret);
- }
- ret = conn->m->query_read_result_set_header(conn, NULL);
-
- DBG_RETURN(ret);
-}
-/* }}} */
-
-
-/* {{{ mysqlnd_com_reap_result_create_command */
-static struct st_mysqlnd_protocol_command *
-mysqlnd_com_reap_result_create_command(va_list args)
-{
- struct st_mysqlnd_protocol_com_reap_result_command * command;
- DBG_ENTER("mysqlnd_com_reap_result_create_command");
- command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_reap_result_command));
- if (command) {
- command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
-
- command->parent.free_command = mysqlnd_com_no_params_free_command;
- command->parent.run = mysqlnd_com_reap_result_run;
- }
-
- DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
-}
-/* }}} */
-
-
-/************************** COM_STMT_PREPARE ******************************************/
-struct st_mysqlnd_protocol_com_stmt_prepare_command
-{
- struct st_mysqlnd_protocol_command parent;
- struct st_mysqlnd_com_stmt_prepare_context
- {
- MYSQLND_CONN_DATA * conn;
- MYSQLND_CSTRING query;
- } context;
-};
-
-
-/* {{{ mysqlnd_com_stmt_prepare_run */
-static enum_func_status
-mysqlnd_com_stmt_prepare_run(void *cmd)
-{
- struct st_mysqlnd_protocol_com_stmt_prepare_command * command = (struct st_mysqlnd_protocol_com_stmt_prepare_command *) cmd;
- enum_func_status ret = FAIL;
- MYSQLND_CONN_DATA * conn = command->context.conn;
-
- DBG_ENTER("mysqlnd_com_stmt_prepare_run");
-
- ret = conn->m->send_command_do_request(conn, COM_STMT_PREPARE, (zend_uchar*) command->context.query.s, command->context.query.l, FALSE, TRUE);
-
- DBG_RETURN(ret);
-}
-/* }}} */
-
-
-/* {{{ mysqlnd_com_stmt_prepare_create_command */
-static struct st_mysqlnd_protocol_command *
-mysqlnd_com_stmt_prepare_create_command(va_list args)
-{
- struct st_mysqlnd_protocol_com_stmt_prepare_command * command;
- DBG_ENTER("mysqlnd_com_stmt_prepare_create_command");
- command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_stmt_prepare_command));
- if (command) {
- command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
- command->context.query = va_arg(args, MYSQLND_CSTRING);
-
- command->parent.free_command = mysqlnd_com_no_params_free_command;
- command->parent.run = mysqlnd_com_stmt_prepare_run;
- }
-
- DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
-}
-/* }}} */
-
-
-/************************** COM_STMT_EXECUTE ******************************************/
-struct st_mysqlnd_protocol_com_stmt_execute_command
-{
- struct st_mysqlnd_protocol_command parent;
- struct st_mysqlnd_com_stmt_execute_context
- {
- MYSQLND_CONN_DATA * conn;
- MYSQLND_CSTRING payload;
- } context;
-};
-
-
-/* {{{ mysqlnd_com_stmt_execute_run */
-static enum_func_status
-mysqlnd_com_stmt_execute_run(void *cmd)
-{
- struct st_mysqlnd_protocol_com_stmt_execute_command * command = (struct st_mysqlnd_protocol_com_stmt_execute_command *) cmd;
- enum_func_status ret = FAIL;
- MYSQLND_CONN_DATA * conn = command->context.conn;
-
- DBG_ENTER("mysqlnd_com_stmt_execute_run");
-
- ret = conn->m->send_command_do_request(conn, COM_STMT_EXECUTE, (zend_uchar*) command->context.payload.s, command->context.payload.l, FALSE, FALSE);
-
- DBG_RETURN(ret);
-}
-/* }}} */
-
-
-/* {{{ mysqlnd_com_stmt_execute_create_command */
-static struct st_mysqlnd_protocol_command *
-mysqlnd_com_stmt_execute_create_command(va_list args)
-{
- struct st_mysqlnd_protocol_com_stmt_execute_command * command;
- DBG_ENTER("mysqlnd_com_stmt_execute_create_command");
- command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_stmt_execute_command));
- if (command) {
- command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
- command->context.payload = va_arg(args, MYSQLND_CSTRING);
-
- command->parent.free_command = mysqlnd_com_no_params_free_command;
- command->parent.run = mysqlnd_com_stmt_execute_run;
- }
-
- DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
-}
-/* }}} */
-
-
-/************************** COM_STMT_FETCH ******************************************/
-struct st_mysqlnd_protocol_com_stmt_fetch_command
-{
- struct st_mysqlnd_protocol_command parent;
- struct st_mysqlnd_com_stmt_fetch_context
- {
- MYSQLND_CONN_DATA * conn;
- MYSQLND_CSTRING payload;
- } context;
-};
-
-
-/* {{{ mysqlnd_com_stmt_fetch_run */
-static enum_func_status
-mysqlnd_com_stmt_fetch_run(void *cmd)
-{
- struct st_mysqlnd_protocol_com_stmt_fetch_command * command = (struct st_mysqlnd_protocol_com_stmt_fetch_command *) cmd;
- enum_func_status ret = FAIL;
- MYSQLND_CONN_DATA * conn = command->context.conn;
-
- DBG_ENTER("mysqlnd_com_stmt_fetch_run");
-
- ret = conn->m->send_command_do_request(conn, COM_STMT_FETCH, (zend_uchar*) command->context.payload.s, command->context.payload.l, FALSE, TRUE);
-
- DBG_RETURN(ret);
-}
-/* }}} */
-
-
-/* {{{ mysqlnd_com_stmt_fetch_create_command */
-static struct st_mysqlnd_protocol_command *
-mysqlnd_com_stmt_fetch_create_command(va_list args)
-{
- struct st_mysqlnd_protocol_com_stmt_fetch_command * command;
- DBG_ENTER("mysqlnd_com_stmt_fetch_create_command");
- command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_stmt_fetch_command));
- if (command) {
- command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
- command->context.payload = va_arg(args, MYSQLND_CSTRING);
-
- command->parent.free_command = mysqlnd_com_no_params_free_command;
- command->parent.run = mysqlnd_com_stmt_fetch_run;
- }
-
- DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
-}
-/* }}} */
-
-
-/************************** COM_STMT_RESET ******************************************/
-struct st_mysqlnd_protocol_com_stmt_reset_command
-{
- struct st_mysqlnd_protocol_command parent;
- struct st_mysqlnd_com_stmt_reset_context
- {
- MYSQLND_CONN_DATA * conn;
- MYSQLND_CSTRING payload;
- } context;
-};
-
-
-/* {{{ mysqlnd_com_stmt_reset_run */
-static enum_func_status
-mysqlnd_com_stmt_reset_run(void *cmd)
-{
- struct st_mysqlnd_protocol_com_stmt_reset_command * command = (struct st_mysqlnd_protocol_com_stmt_reset_command *) cmd;
- enum_func_status ret = FAIL;
- MYSQLND_CONN_DATA * conn = command->context.conn;
-
- DBG_ENTER("mysqlnd_com_stmt_reset_run");
-
- ret = conn->m->send_command_do_request(conn, COM_STMT_RESET, (zend_uchar*) command->context.payload.s, command->context.payload.l, FALSE, TRUE);
-
- DBG_RETURN(ret);
-}
-/* }}} */
-
-
-/* {{{ mysqlnd_com_stmt_reset_create_command */
-static struct st_mysqlnd_protocol_command *
-mysqlnd_com_stmt_reset_create_command(va_list args)
-{
- struct st_mysqlnd_protocol_com_stmt_reset_command * command;
- DBG_ENTER("mysqlnd_com_stmt_reset_create_command");
- command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_stmt_reset_command));
- if (command) {
- command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
- command->context.payload = va_arg(args, MYSQLND_CSTRING);
-
- command->parent.free_command = mysqlnd_com_no_params_free_command;
- command->parent.run = mysqlnd_com_stmt_reset_run;
- }
-
- DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
-}
-/* }}} */
-
-
-/************************** COM_STMT_SEND_LONG_DATA ******************************************/
-struct st_mysqlnd_protocol_com_stmt_send_long_data_command
-{
- struct st_mysqlnd_protocol_command parent;
- struct st_mysqlnd_com_stmt_send_long_data_context
- {
- MYSQLND_CONN_DATA * conn;
- MYSQLND_CSTRING payload;
- } context;
-};
-
-
-/* {{{ mysqlnd_com_stmt_send_long_data_run */
-static enum_func_status
-mysqlnd_com_stmt_send_long_data_run(void *cmd)
-{
- struct st_mysqlnd_protocol_com_stmt_send_long_data_command * command = (struct st_mysqlnd_protocol_com_stmt_send_long_data_command *) cmd;
- enum_func_status ret = FAIL;
- MYSQLND_CONN_DATA * conn = command->context.conn;
-
- DBG_ENTER("mysqlnd_com_stmt_send_long_data_run");
-
- ret = conn->m->send_command_do_request(conn, COM_STMT_SEND_LONG_DATA, (zend_uchar*) command->context.payload.s, command->context.payload.l, FALSE, TRUE);
-
- DBG_RETURN(ret);
-}
-/* }}} */
-
-
-/* {{{ mysqlnd_com_stmt_send_long_data_create_command */
-static struct st_mysqlnd_protocol_command *
-mysqlnd_com_stmt_send_long_data_create_command(va_list args)
-{
- struct st_mysqlnd_protocol_com_stmt_send_long_data_command * command;
- DBG_ENTER("mysqlnd_com_stmt_send_long_data_create_command");
- command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_stmt_send_long_data_command));
- if (command) {
- command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
- command->context.payload = va_arg(args, MYSQLND_CSTRING);
-
- command->parent.free_command = mysqlnd_com_no_params_free_command;
- command->parent.run = mysqlnd_com_stmt_send_long_data_run;
- }
-
- DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
-}
-/* }}} */
-
-
-/************************** COM_STMT_CLOSE ******************************************/
-struct st_mysqlnd_protocol_com_stmt_close_command
-{
- struct st_mysqlnd_protocol_command parent;
- struct st_mysqlnd_com_stmt_close_context
- {
- MYSQLND_CONN_DATA * conn;
- MYSQLND_CSTRING payload;
- } context;
-};
-
-
-/* {{{ mysqlnd_com_stmt_close_run */
-static enum_func_status
-mysqlnd_com_stmt_close_run(void *cmd)
-{
- struct st_mysqlnd_protocol_com_stmt_close_command * command = (struct st_mysqlnd_protocol_com_stmt_close_command *) cmd;
- enum_func_status ret = FAIL;
- MYSQLND_CONN_DATA * conn = command->context.conn;
-
- DBG_ENTER("mysqlnd_com_stmt_close_run");
-
- ret = conn->m->send_command_do_request(conn, COM_STMT_CLOSE, (zend_uchar*) command->context.payload.s, command->context.payload.l, FALSE, TRUE);
-
- DBG_RETURN(ret);
-}
-/* }}} */
-
-
-/* {{{ mysqlnd_com_stmt_close_create_command */
-static struct st_mysqlnd_protocol_command *
-mysqlnd_com_stmt_close_create_command(va_list args)
-{
- struct st_mysqlnd_protocol_com_stmt_close_command * command;
- DBG_ENTER("mysqlnd_com_stmt_close_create_command");
- command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_stmt_close_command));
- if (command) {
- command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
- command->context.payload = va_arg(args, MYSQLND_CSTRING);
-
- command->parent.free_command = mysqlnd_com_no_params_free_command;
- command->parent.run = mysqlnd_com_stmt_close_run;
- }
-
- DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
-}
-/* }}} */
-
-
-/* {{{ mysqlnd_get_command */
-struct st_mysqlnd_protocol_command *
-mysqlnd_get_command(enum php_mysqlnd_server_command command, ...)
-{
- struct st_mysqlnd_protocol_command * ret;
- va_list args;
- DBG_ENTER("mysqlnd_get_command");
-
- va_start(args, command);
- switch (command) {
- case COM_SET_OPTION:
- ret = mysqlnd_com_set_option_create_command(args);
- break;
- case COM_DEBUG:
- ret = mysqlnd_com_debug_create_command(args);
- break;
- case COM_INIT_DB:
- ret = mysqlnd_com_init_db_create_command(args);
- break;
- case COM_PING:
- ret = mysqlnd_com_ping_create_command(args);
- break;
- case COM_FIELD_LIST:
- ret = mysqlnd_com_field_list_create_command(args);
- break;
- case COM_STATISTICS:
- ret = mysqlnd_com_statistics_create_command(args);
- break;
- case COM_PROCESS_KILL:
- ret = mysqlnd_com_process_kill_create_command(args);
- break;
- case COM_REFRESH:
- ret = mysqlnd_com_refresh_create_command(args);
- break;
- case COM_SHUTDOWN:
- ret = mysqlnd_com_shutdown_create_command(args);
- break;
- case COM_QUIT:
- ret = mysqlnd_com_quit_create_command(args);
- break;
- case COM_QUERY:
- ret = mysqlnd_com_query_create_command(args);
- break;
- case COM_REAP_RESULT:
- ret = mysqlnd_com_reap_result_create_command(args);
- break;
- case COM_CHANGE_USER:
- ret = mysqlnd_com_change_user_create_command(args);
- break;
- case COM_STMT_PREPARE:
- ret = mysqlnd_com_stmt_prepare_create_command(args);
- break;
- case COM_STMT_EXECUTE:
- ret = mysqlnd_com_stmt_execute_create_command(args);
- break;
- case COM_STMT_FETCH:
- ret = mysqlnd_com_stmt_fetch_create_command(args);
- break;
- case COM_STMT_RESET:
- ret = mysqlnd_com_stmt_reset_create_command(args);
- break;
- case COM_STMT_SEND_LONG_DATA:
- ret = mysqlnd_com_stmt_send_long_data_create_command(args);
- break;
- case COM_STMT_CLOSE:
- ret = mysqlnd_com_stmt_close_create_command(args);
- break;
- default:
- break;
- }
- va_end(args);
- DBG_RETURN(ret);
-}
-/* }}} */
-
-
/*
* Local variables:
* tab-width: 4
data->net = mysqlnd_net_init(persistent, data->stats, data->error_info);
data->payload_decoder_factory = mysqlnd_protocol_payload_decoder_factory_init(data, persistent);
+ data->command_factory = mysqlnd_command_factory_get();
if (!data->net || !data->payload_decoder_factory) {
new_object->m->dtor(new_object);
#define MYSQLND_NET_CMD_BUFFER_MIN_SIZE 4096
#define MYSQLND_NET_CMD_BUFFER_MIN_SIZE_STR "4096"
+#define MYSQLND_STMT_ID_LENGTH 4
+
+
#define SERVER_STATUS_IN_TRANS 1 /* Transaction has started */
#define SERVER_STATUS_AUTOCOMMIT 2 /* Server in auto_commit mode */
#define SERVER_MORE_RESULTS_EXISTS 8 /* Multi query - next query exists */
/* }}} */
+/* {{{ mysqlnd_command_factory_get */
+static func_mysqlnd__command_factory
+_mysqlnd_command_factory_get()
+{
+ return mysqlnd_command_factory;
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_command_factory_set */
+static void
+_mysqlnd_command_factory_set(func_mysqlnd__command_factory factory)
+{
+ mysqlnd_command_factory = factory;
+}
+/* }}} */
+
+
+
struct st_mysqlnd_plugin_methods_xetters mysqlnd_plugin_methods_xetters =
{
{
},
{
_mysqlnd_net_get_methods,
- _mysqlnd_net_set_methods
+ _mysqlnd_net_set_methods,
+ },
+ {
+ _mysqlnd_command_factory_get,
+ _mysqlnd_command_factory_set,
},
};
void (*set)(struct st_mysqlnd_conn_data_methods * methods);
} connection_data;
- struct st_mnd_result_etters
+ struct st_mnd_result_xetters
{
struct st_mysqlnd_res_methods * (*get)();
void (*set)(struct st_mysqlnd_res_methods * methods);
struct st_mysqlnd_net_methods * (*get)();
void (*set)(struct st_mysqlnd_net_methods * methods);
} io;
+
+ struct st_mnd_command_factory_xetters
+ {
+ func_mysqlnd__command_factory (*get)();
+ void (*set)(func_mysqlnd__command_factory factory);
+ } command_factory;
};
extern struct st_mysqlnd_plugin_methods_xetters mysqlnd_plugin_methods_xetters;
#define mysqlnd_net_get_methods() mysqlnd_plugin_methods_xetters.io.get()
#define mysqlnd_net_set_methods(m) mysqlnd_plugin_methods_xetters.io.set((m))
+
+#define mysqlnd_command_factory_get() mysqlnd_plugin_methods_xetters.command_factory.get()
+#define mysqlnd_command_factory_set(m) mysqlnd_plugin_methods_xetters.command_factory.set((m))
+
#endif /* MYSQLND_EXT_PLUGIN_H */
/*
size_t * switch_to_auth_protocol_data_len
);
-/* {{{ mysqlnd_get_command */
-struct st_mysqlnd_protocol_command *
-mysqlnd_get_command(enum php_mysqlnd_server_command command, ...);
-
+extern func_mysqlnd__command_factory mysqlnd_command_factory;
#endif /* MYSQLND_PRIV_H */
{
enum_func_status ret = FAIL;
const MYSQLND_CSTRING query_string = {query, query_len};
- struct st_mysqlnd_protocol_command * command = mysqlnd_get_command(COM_STMT_PREPARE, stmt_to_prepare->conn, query_string);
+ struct st_mysqlnd_protocol_command * command = stmt_to_prepare->conn->command_factory(COM_STMT_PREPARE, stmt_to_prepare->conn, query_string);
if (command) {
ret = command->run(command);
command->free_command(command);
ret = s->m->generate_execute_request(s, &request, &request_len, &free_request);
if (ret == PASS) {
const MYSQLND_CSTRING payload = {request, request_len};
- struct st_mysqlnd_protocol_command * command = mysqlnd_get_command(COM_STMT_EXECUTE, stmt->conn, payload);
+ struct st_mysqlnd_protocol_command * command = stmt->conn->command_factory(COM_STMT_EXECUTE, stmt->conn, payload);
ret = FAIL;
if (command) {
ret = command->run(command);
/* }}} */
-#define STMT_ID_LENGTH 4
-
/* {{{ mysqlnd_fetch_row_cursor */
enum_func_status
mysqlnd_fetch_stmt_row_cursor(MYSQLND_RES * result, void * param, unsigned int flags, zend_bool * fetched_anything)
enum_func_status ret;
MYSQLND_STMT * s = (MYSQLND_STMT *) param;
MYSQLND_STMT_DATA * stmt = s? s->data:NULL;
- zend_uchar buf[STMT_ID_LENGTH /* statement id */ + 4 /* number of rows to fetch */];
+ zend_uchar buf[MYSQLND_STMT_ID_LENGTH /* statement id */ + 4 /* number of rows to fetch */];
MYSQLND_PACKET_ROW * row_packet;
DBG_ENTER("mysqlnd_fetch_stmt_row_cursor");
SET_EMPTY_ERROR(*stmt->conn->error_info);
int4store(buf, stmt->stmt_id);
- int4store(buf + STMT_ID_LENGTH, 1); /* for now fetch only one row */
+ int4store(buf + MYSQLND_STMT_ID_LENGTH, 1); /* for now fetch only one row */
{
const MYSQLND_CSTRING payload = {buf, sizeof(buf)};
- struct st_mysqlnd_protocol_command * command = mysqlnd_get_command(COM_STMT_FETCH, stmt->conn, payload);
+ struct st_mysqlnd_protocol_command * command = stmt->conn->command_factory(COM_STMT_FETCH, stmt->conn, payload);
ret = FAIL;
if (command) {
ret = command->run(command);
{
MYSQLND_STMT_DATA * stmt = s? s->data:NULL;
enum_func_status ret = PASS;
- zend_uchar cmd_buf[STMT_ID_LENGTH /* statement id */];
DBG_ENTER("mysqlnd_stmt::reset");
if (!stmt || !stmt->conn) {
be separated before that.
*/
- int4store(cmd_buf, stmt->stmt_id);
-
if (CONN_GET_STATE(conn) == CONN_READY) {
- const MYSQLND_CSTRING payload = {cmd_buf, sizeof(cmd_buf)};
- struct st_mysqlnd_protocol_command * command = mysqlnd_get_command(COM_STMT_RESET, stmt->conn, payload);
+ size_t stmt_id = stmt->stmt_id;
+ struct st_mysqlnd_protocol_command * command = stmt->conn->command_factory(COM_STMT_RESET, stmt->conn, stmt_id);
ret = FAIL;
if (command) {
ret = command->run(command);
if (CONN_GET_STATE(conn) == CONN_READY) {
size_t packet_len;
- cmd_buf = mnd_emalloc(packet_len = STMT_ID_LENGTH + 2 + length);
+ cmd_buf = mnd_emalloc(packet_len = MYSQLND_STMT_ID_LENGTH + 2 + length);
if (cmd_buf) {
stmt->param_bind[param_no].flags |= MYSQLND_PARAM_BIND_BLOB_USED;
int4store(cmd_buf, stmt->stmt_id);
- int2store(cmd_buf + STMT_ID_LENGTH, param_no);
- memcpy(cmd_buf + STMT_ID_LENGTH + 2, data, length);
+ int2store(cmd_buf + MYSQLND_STMT_ID_LENGTH, param_no);
+ memcpy(cmd_buf + MYSQLND_STMT_ID_LENGTH + 2, data, length);
/* COM_STMT_SEND_LONG_DATA doesn't send an OK packet*/
{
const MYSQLND_CSTRING payload = {cmd_buf, packet_len};
- struct st_mysqlnd_protocol_command * command = mysqlnd_get_command(COM_STMT_SEND_LONG_DATA, stmt->conn, payload);
+ struct st_mysqlnd_protocol_command * command = stmt->conn->command_factory(COM_STMT_SEND_LONG_DATA, stmt->conn, payload);
ret = FAIL;
if (command) {
ret = command->run(command);
{
MYSQLND_STMT_DATA * stmt = s? s->data:NULL;
MYSQLND_CONN_DATA * conn;
- zend_uchar cmd_buf[STMT_ID_LENGTH /* statement id */];
enum_mysqlnd_collected_stats statistic = STAT_LAST;
DBG_ENTER("mysqlnd_stmt::net_close");
MYSQLND_INC_GLOBAL_STATISTIC(implicit == TRUE? STAT_FREE_RESULT_IMPLICIT:
STAT_FREE_RESULT_EXPLICIT);
- int4store(cmd_buf, stmt->stmt_id);
if (CONN_GET_STATE(conn) == CONN_READY) {
enum_func_status ret = FAIL;
- const MYSQLND_CSTRING payload = {cmd_buf, sizeof(cmd_buf)};
- struct st_mysqlnd_protocol_command * command = mysqlnd_get_command(COM_STMT_CLOSE, conn, payload);
+ size_t stmt_id = stmt->stmt_id;
+ struct st_mysqlnd_protocol_command * command = conn->command_factory(COM_STMT_CLOSE, conn, stmt_id);
if (command) {
ret = command->run(command);
command->free_command(command);
};
+struct st_mysqlnd_protocol_command
+{
+ enum_func_status (*run)(void *cmd);
+ void (*free_command)(void * cmd);
+};
+
+typedef struct st_mysqlnd_protocol_command * (*func_mysqlnd__command_factory)(enum php_mysqlnd_server_command command, ...);
+
+
struct st_mysqlnd_connection_data
{
/* Operation related */
zend_bool in_async_err_cb;
struct st_mysqlnd_object_factory_methods object_factory;
+ func_mysqlnd__command_factory command_factory;
struct st_mysqlnd_conn_data_methods * m;
} methods;
};
-
-struct st_mysqlnd_protocol_command
-{
- enum_func_status (*run)(void *cmd);
- void (*free_command)(void * cmd);
-};
-
#endif /* MYSQLND_STRUCTS_H */
enum_func_status ret = FAIL;
const MYSQLND_CSTRING payload = {buffer + MYSQLND_HEADER_SIZE, p - (buffer + MYSQLND_HEADER_SIZE)};
const unsigned int silent = packet->silent;
- struct st_mysqlnd_protocol_command * command = mysqlnd_get_command(COM_CHANGE_USER, conn, payload, silent);
+ struct st_mysqlnd_protocol_command * command = conn->command_factory(COM_CHANGE_USER, conn, payload, silent);
if (command) {
ret = command->run(command);
command->free_command(command);
/* }}} */
+
+
+struct st_mysqlnd_protocol_no_params_command
+{
+ struct st_mysqlnd_protocol_command parent;
+ struct st_mysqlnd_protocol_no_params_command_context
+ {
+ MYSQLND_CONN_DATA * conn;
+ } context;
+};
+
+/* {{{ mysqlnd_com_no_params_free_command */
+static void
+mysqlnd_com_no_params_free_command(void * command)
+{
+ DBG_ENTER("mysqlnd_com_no_params_free_command");
+ mnd_efree(command);
+ DBG_VOID_RETURN;
+}
+/* }}} */
+
+
+/************************** COM_SET_OPTION ******************************************/
+struct st_mysqlnd_protocol_com_set_option_command
+{
+ struct st_mysqlnd_protocol_command parent;
+ struct st_mysqlnd_com_set_option_context
+ {
+ MYSQLND_CONN_DATA * conn;
+ enum_mysqlnd_server_option option;
+ } context;
+};
+
+
+/* {{{ mysqlnd_com_set_option_run */
+enum_func_status
+mysqlnd_com_set_option_run(void *cmd)
+{
+ struct st_mysqlnd_protocol_com_set_option_command * command = (struct st_mysqlnd_protocol_com_set_option_command *) cmd;
+ zend_uchar buffer[2];
+ enum_func_status ret = FAIL;
+ MYSQLND_CONN_DATA * conn = command->context.conn;
+ enum_mysqlnd_server_option option = command->context.option;
+
+ DBG_ENTER("mysqlnd_com_set_option_run");
+ int2store(buffer, (unsigned int) option);
+
+ ret = conn->m->send_command_do_request(conn, COM_SET_OPTION, buffer, sizeof(buffer), FALSE, TRUE);
+ if (PASS == ret) {
+ ret = conn->m->send_command_handle_response(conn, PROT_EOF_PACKET, FALSE, COM_SET_OPTION, TRUE);
+ }
+
+ DBG_RETURN(ret);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_com_set_option_create_command */
+static struct st_mysqlnd_protocol_command *
+mysqlnd_com_set_option_create_command(va_list args)
+{
+ struct st_mysqlnd_protocol_com_set_option_command * command;
+ DBG_ENTER("mysqlnd_com_set_option_create_command");
+ command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_set_option_command));
+ if (command) {
+ command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
+ command->context.option = va_arg(args, enum_mysqlnd_server_option);
+
+ command->parent.free_command = mysqlnd_com_no_params_free_command;
+ command->parent.run = mysqlnd_com_set_option_run;
+ }
+
+ DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
+}
+/* }}} */
+
+
+/************************** COM_DEBUG ******************************************/
+/* {{{ mysqlnd_com_debug_run */
+static enum_func_status
+mysqlnd_com_debug_run(void *cmd)
+{
+ struct st_mysqlnd_protocol_no_params_command * command = (struct st_mysqlnd_protocol_no_params_command *) cmd;
+ enum_func_status ret = FAIL;
+ MYSQLND_CONN_DATA * conn = command->context.conn;
+
+ DBG_ENTER("mysqlnd_com_debug_run");
+
+ ret = conn->m->send_command_do_request(conn, COM_DEBUG, NULL, 0, FALSE, TRUE);
+ if (PASS == ret) {
+ ret = conn->m->send_command_handle_response(conn, PROT_EOF_PACKET, COM_DEBUG, COM_DEBUG, TRUE);
+ }
+
+ DBG_RETURN(ret);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_com_debug_create_command */
+static struct st_mysqlnd_protocol_command *
+mysqlnd_com_debug_create_command(va_list args)
+{
+ struct st_mysqlnd_protocol_no_params_command * command;
+ DBG_ENTER("mysqlnd_com_debug_create_command");
+ command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_no_params_command));
+ if (command) {
+ command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
+ command->parent.free_command = mysqlnd_com_no_params_free_command;
+
+ command->parent.run = mysqlnd_com_debug_run;
+ }
+
+ DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
+}
+/* }}} */
+
+
+/************************** COM_INIT_DB ******************************************/
+struct st_mysqlnd_protocol_com_init_db_command
+{
+ struct st_mysqlnd_protocol_command parent;
+ struct st_mysqlnd_com_init_db_context
+ {
+ MYSQLND_CONN_DATA * conn;
+ MYSQLND_CSTRING db;
+ } context;
+};
+
+
+/* {{{ mysqlnd_com_init_db_run */
+static enum_func_status
+mysqlnd_com_init_db_run(void *cmd)
+{
+ struct st_mysqlnd_protocol_com_init_db_command * command = (struct st_mysqlnd_protocol_com_init_db_command *) cmd;
+ enum_func_status ret = FAIL;
+ MYSQLND_CONN_DATA * conn = command->context.conn;
+
+ DBG_ENTER("mysqlnd_com_init_db_run");
+
+ ret = conn->m->send_command_do_request(conn, COM_INIT_DB, (zend_uchar*) command->context.db.s, command->context.db.l, FALSE, TRUE);
+ if (PASS == ret) {
+ ret = conn->m->send_command_handle_response(conn, PROT_OK_PACKET, FALSE, COM_INIT_DB, TRUE);
+ }
+
+ DBG_RETURN(ret);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_com_init_db_create_command */
+static struct st_mysqlnd_protocol_command *
+mysqlnd_com_init_db_create_command(va_list args)
+{
+ struct st_mysqlnd_protocol_com_init_db_command * command;
+ DBG_ENTER("mysqlnd_com_init_db_create_command");
+ command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_init_db_command));
+ if (command) {
+ command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
+ command->context.db = va_arg(args, MYSQLND_CSTRING);
+
+ command->parent.free_command = mysqlnd_com_no_params_free_command;
+ command->parent.run = mysqlnd_com_init_db_run;
+ }
+
+ DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
+}
+/* }}} */
+
+
+/************************** COM_PING ******************************************/
+/* {{{ mysqlnd_com_ping_run */
+static enum_func_status
+mysqlnd_com_ping_run(void *cmd)
+{
+ struct st_mysqlnd_protocol_no_params_command * command = (struct st_mysqlnd_protocol_no_params_command *) cmd;
+ enum_func_status ret = FAIL;
+ MYSQLND_CONN_DATA * conn = command->context.conn;
+
+ DBG_ENTER("mysqlnd_com_ping_run");
+
+ ret = conn->m->send_command_do_request(conn, COM_PING, NULL, 0, TRUE, TRUE);
+ if (PASS == ret) {
+ ret = conn->m->send_command_handle_response(conn, PROT_OK_PACKET, TRUE, COM_PING, TRUE);
+ }
+
+ DBG_RETURN(ret);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_com_ping_create_command */
+static struct st_mysqlnd_protocol_command *
+mysqlnd_com_ping_create_command(va_list args)
+{
+ struct st_mysqlnd_protocol_no_params_command * command;
+ DBG_ENTER("mysqlnd_com_ping_create_command");
+ command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_no_params_command));
+ if (command) {
+ command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
+ command->parent.free_command = mysqlnd_com_no_params_free_command;
+
+ command->parent.run = mysqlnd_com_ping_run;
+ }
+
+ DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
+}
+/* }}} */
+
+/************************** COM_FIELD_LIST ******************************************/
+struct st_mysqlnd_protocol_com_field_list_command
+{
+ struct st_mysqlnd_protocol_command parent;
+ struct st_mysqlnd_com_field_list_context
+ {
+ MYSQLND_CONN_DATA * conn;
+ MYSQLND_CSTRING table;
+ MYSQLND_CSTRING achtung_wild;
+ } context;
+};
+
+
+/* {{{ mysqlnd_com_field_list_run */
+static enum_func_status
+mysqlnd_com_field_list_run(void *cmd)
+{
+ struct st_mysqlnd_protocol_com_field_list_command * command = (struct st_mysqlnd_protocol_com_field_list_command *) cmd;
+ enum_func_status ret = FAIL;
+ MYSQLND_CONN_DATA * conn = command->context.conn;
+ /* db + \0 + wild + \0 (for wild) */
+ zend_uchar buff[MYSQLND_MAX_ALLOWED_DB_LEN * 2 + 1 + 1], *p;
+ size_t table_len, wild_len;
+
+ DBG_ENTER("mysqlnd_com_field_list_run");
+
+ if (command->context.table.s && command->context.table.l) {
+ size_t to_copy = MIN(command->context.table.l, MYSQLND_MAX_ALLOWED_DB_LEN);
+ memcpy(p, command->context.table.s, to_copy);
+ p += to_copy;
+ *p++ = '\0';
+ }
+
+ if (command->context.achtung_wild.s && command->context.achtung_wild.l) {
+ size_t to_copy = MIN(command->context.achtung_wild.l, MYSQLND_MAX_ALLOWED_DB_LEN);
+ memcpy(p, command->context.achtung_wild.s, to_copy);
+ p += to_copy;
+ *p++ = '\0';
+ }
+
+ ret = conn->m->send_command_do_request(conn, COM_FIELD_LIST, buff, p - buff, FALSE, TRUE);
+
+ DBG_RETURN(ret);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_com_field_list_create_command */
+static struct st_mysqlnd_protocol_command *
+mysqlnd_com_field_list_create_command(va_list args)
+{
+ struct st_mysqlnd_protocol_com_field_list_command * command;
+ DBG_ENTER("mysqlnd_com_field_list_create_command");
+ command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_field_list_command));
+ if (command) {
+ command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
+ command->context.table = va_arg(args, MYSQLND_CSTRING);
+ command->context.achtung_wild = va_arg(args, MYSQLND_CSTRING);
+
+ command->parent.free_command = mysqlnd_com_no_params_free_command;
+ command->parent.run = mysqlnd_com_field_list_run;
+ }
+
+ DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
+}
+/* }}} */
+
+
+/************************** COM_STATISTICS ******************************************/
+/* {{{ mysqlnd_com_statistics_run */
+static enum_func_status
+mysqlnd_com_statistics_run(void *cmd)
+{
+ struct st_mysqlnd_protocol_no_params_command * command = (struct st_mysqlnd_protocol_no_params_command *) cmd;
+ enum_func_status ret = FAIL;
+ MYSQLND_CONN_DATA * conn = command->context.conn;
+
+ DBG_ENTER("mysqlnd_com_statistics_run");
+
+ ret = conn->m->send_command_do_request(conn, COM_STATISTICS, NULL, 0, FALSE, TRUE);
+
+ DBG_RETURN(ret);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_com_statistics_create_command */
+static struct st_mysqlnd_protocol_command *
+mysqlnd_com_statistics_create_command(va_list args)
+{
+ struct st_mysqlnd_protocol_no_params_command * command;
+ DBG_ENTER("mysqlnd_com_statistics_create_command");
+ command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_no_params_command));
+ if (command) {
+ command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
+ command->parent.free_command = mysqlnd_com_no_params_free_command;
+
+ command->parent.run = mysqlnd_com_statistics_run;
+ }
+
+ DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
+}
+/* }}} */
+
+/************************** COM_PROCESS_KILL ******************************************/
+struct st_mysqlnd_protocol_com_process_kill_command
+{
+ struct st_mysqlnd_protocol_command parent;
+ struct st_mysqlnd_com_process_kill_context
+ {
+ MYSQLND_CONN_DATA * conn;
+ unsigned int process_id;
+ zend_bool read_response;
+ } context;
+};
+
+
+/* {{{ mysqlnd_com_process_kill_run */
+enum_func_status
+mysqlnd_com_process_kill_run(void *cmd)
+{
+ struct st_mysqlnd_protocol_com_process_kill_command * command = (struct st_mysqlnd_protocol_com_process_kill_command *) cmd;
+ zend_uchar buff[4];
+ enum_func_status ret = FAIL;
+ MYSQLND_CONN_DATA * conn = command->context.conn;
+
+ DBG_ENTER("mysqlnd_com_process_kill_run");
+ int4store(buff, command->context.process_id);
+
+ ret = conn->m->send_command_do_request(conn, COM_PROCESS_KILL, buff, 4, FALSE, TRUE);
+ if (PASS == ret && command->context.read_response) {
+ ret = conn->m->send_command_handle_response(conn, PROT_OK_PACKET, FALSE, COM_PROCESS_KILL, TRUE);
+ }
+
+ DBG_RETURN(ret);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_com_process_kill_create_command */
+static struct st_mysqlnd_protocol_command *
+mysqlnd_com_process_kill_create_command(va_list args)
+{
+ struct st_mysqlnd_protocol_com_process_kill_command * command;
+ DBG_ENTER("mysqlnd_com_process_kill_create_command");
+ command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_process_kill_command));
+ if (command) {
+ command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
+ command->context.process_id = va_arg(args, unsigned int);
+ command->context.read_response = va_arg(args, unsigned int)? TRUE:FALSE;
+
+ command->parent.free_command = mysqlnd_com_no_params_free_command;
+ command->parent.run = mysqlnd_com_process_kill_run;
+ }
+
+ DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
+}
+/* }}} */
+
+/************************** COM_REFRESH ******************************************/
+struct st_mysqlnd_protocol_com_refresh_command
+{
+ struct st_mysqlnd_protocol_command parent;
+ struct st_mysqlnd_com_refresh_context
+ {
+ MYSQLND_CONN_DATA * conn;
+ uint8_t options;
+ } context;
+};
+
+
+/* {{{ mysqlnd_com_refresh_run */
+enum_func_status
+mysqlnd_com_refresh_run(void *cmd)
+{
+ struct st_mysqlnd_protocol_com_refresh_command * command = (struct st_mysqlnd_protocol_com_refresh_command *) cmd;
+ zend_uchar bits[1];
+ enum_func_status ret = FAIL;
+ MYSQLND_CONN_DATA * conn = command->context.conn;
+
+ DBG_ENTER("mysqlnd_com_refresh_run");
+ int1store(bits, command->context.options);
+
+ ret = conn->m->send_command_do_request(conn, COM_REFRESH, bits, 1, FALSE, TRUE);
+ if (PASS == ret) {
+ ret = conn->m->send_command_handle_response(conn, PROT_OK_PACKET, FALSE, COM_REFRESH, TRUE);
+ }
+
+ DBG_RETURN(ret);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_com_refresh_create_command */
+static struct st_mysqlnd_protocol_command *
+mysqlnd_com_refresh_create_command(va_list args)
+{
+ struct st_mysqlnd_protocol_com_refresh_command * command;
+ DBG_ENTER("mysqlnd_com_refresh_create_command");
+ command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_refresh_command));
+ if (command) {
+ command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
+ command->context.options = va_arg(args, unsigned int);
+
+ command->parent.free_command = mysqlnd_com_no_params_free_command;
+ command->parent.run = mysqlnd_com_refresh_run;
+ }
+
+ DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
+}
+/* }}} */
+
+
+/************************** COM_SHUTDOWN ******************************************/
+struct st_mysqlnd_protocol_com_shutdown_command
+{
+ struct st_mysqlnd_protocol_command parent;
+ struct st_mysqlnd_com_shutdown_context
+ {
+ MYSQLND_CONN_DATA * conn;
+ uint8_t level;
+ } context;
+};
+
+
+/* {{{ mysqlnd_com_shutdown_run */
+enum_func_status
+mysqlnd_com_shutdown_run(void *cmd)
+{
+ struct st_mysqlnd_protocol_com_shutdown_command * command = (struct st_mysqlnd_protocol_com_shutdown_command *) cmd;
+ zend_uchar bits[1];
+ enum_func_status ret = FAIL;
+ MYSQLND_CONN_DATA * conn = command->context.conn;
+
+ DBG_ENTER("mysqlnd_com_shutdown_run");
+ int1store(bits, command->context.level);
+
+ ret = conn->m->send_command_do_request(conn, COM_SHUTDOWN, bits, 1, FALSE, TRUE);
+ if (PASS == ret) {
+ ret = conn->m->send_command_handle_response(conn, PROT_OK_PACKET, FALSE, COM_SHUTDOWN, TRUE);
+ }
+
+ DBG_RETURN(ret);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_com_shutdown_create_command */
+static struct st_mysqlnd_protocol_command *
+mysqlnd_com_shutdown_create_command(va_list args)
+{
+ struct st_mysqlnd_protocol_com_shutdown_command * command;
+ DBG_ENTER("mysqlnd_com_shutdown_create_command");
+ command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_shutdown_command));
+ if (command) {
+ command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
+ command->context.level = va_arg(args, unsigned int);
+
+ command->parent.free_command = mysqlnd_com_no_params_free_command;
+ command->parent.run = mysqlnd_com_shutdown_run;
+ }
+
+ DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
+}
+/* }}} */
+
+
+/************************** COM_QUIT ******************************************/
+struct st_mysqlnd_protocol_com_quit_command
+{
+ struct st_mysqlnd_protocol_command parent;
+ struct st_mysqlnd_com_quit_context
+ {
+ MYSQLND_CONN_DATA * conn;
+ } context;
+};
+
+
+/* {{{ mysqlnd_com_quit_run */
+enum_func_status
+mysqlnd_com_quit_run(void *cmd)
+{
+ struct st_mysqlnd_protocol_com_quit_command * command = (struct st_mysqlnd_protocol_com_quit_command *) cmd;
+ zend_uchar bits[1];
+ enum_func_status ret = FAIL;
+ MYSQLND_CONN_DATA * conn = command->context.conn;
+
+ DBG_ENTER("mysqlnd_com_quit_run");
+
+ ret = conn->m->send_command_do_request(conn, COM_QUIT, NULL, 0, TRUE, TRUE);
+
+ DBG_RETURN(ret);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_com_quit_create_command */
+static struct st_mysqlnd_protocol_command *
+mysqlnd_com_quit_create_command(va_list args)
+{
+ struct st_mysqlnd_protocol_com_quit_command * command;
+ DBG_ENTER("mysqlnd_com_quit_create_command");
+ command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_quit_command));
+ if (command) {
+ command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
+
+ command->parent.free_command = mysqlnd_com_no_params_free_command;
+ command->parent.run = mysqlnd_com_quit_run;
+ }
+
+ DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
+}
+/* }}} */
+
+/************************** COM_QUERY ******************************************/
+struct st_mysqlnd_protocol_com_query_command
+{
+ struct st_mysqlnd_protocol_command parent;
+ struct st_mysqlnd_com_query_context
+ {
+ MYSQLND_CONN_DATA * conn;
+ MYSQLND_CSTRING query;
+ } context;
+};
+
+
+/* {{{ mysqlnd_com_query_run */
+static enum_func_status
+mysqlnd_com_query_run(void *cmd)
+{
+ struct st_mysqlnd_protocol_com_query_command * command = (struct st_mysqlnd_protocol_com_query_command *) cmd;
+ enum_func_status ret = FAIL;
+ MYSQLND_CONN_DATA * conn = command->context.conn;
+
+ DBG_ENTER("mysqlnd_com_query_run");
+
+ ret = conn->m->send_command_do_request(conn, COM_QUERY, (zend_uchar*) command->context.query.s, command->context.query.l, FALSE, FALSE);
+
+ if (PASS == ret) {
+ CONN_SET_STATE(conn, CONN_QUERY_SENT);
+ }
+
+ DBG_RETURN(ret);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_com_query_create_command */
+static struct st_mysqlnd_protocol_command *
+mysqlnd_com_query_create_command(va_list args)
+{
+ struct st_mysqlnd_protocol_com_query_command * command;
+ DBG_ENTER("mysqlnd_com_query_create_command");
+ command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_query_command));
+ if (command) {
+ command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
+ command->context.query = va_arg(args, MYSQLND_CSTRING);
+
+ command->parent.free_command = mysqlnd_com_no_params_free_command;
+ command->parent.run = mysqlnd_com_query_run;
+ }
+
+ DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
+}
+/* }}} */
+
+/************************** COM_CHANGE_USER ******************************************/
+struct st_mysqlnd_protocol_com_change_user_command
+{
+ struct st_mysqlnd_protocol_command parent;
+ struct st_mysqlnd_com_change_user_context
+ {
+ MYSQLND_CONN_DATA * conn;
+ MYSQLND_CSTRING payload;
+ zend_bool silent;
+ } context;
+};
+
+
+/* {{{ mysqlnd_com_change_user_run */
+static enum_func_status
+mysqlnd_com_change_user_run(void *cmd)
+{
+ struct st_mysqlnd_protocol_com_change_user_command * command = (struct st_mysqlnd_protocol_com_change_user_command *) cmd;
+ enum_func_status ret = FAIL;
+ MYSQLND_CONN_DATA * conn = command->context.conn;
+
+ DBG_ENTER("mysqlnd_com_change_user_run");
+
+ ret = conn->m->send_command_do_request(conn, COM_CHANGE_USER, (zend_uchar*) command->context.payload.s, command->context.payload.l, command->context.silent, TRUE);
+
+ DBG_RETURN(ret);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_com_change_user_create_command */
+static struct st_mysqlnd_protocol_command *
+mysqlnd_com_change_user_create_command(va_list args)
+{
+ struct st_mysqlnd_protocol_com_change_user_command * command;
+ DBG_ENTER("mysqlnd_com_change_user_create_command");
+ command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_change_user_command));
+ if (command) {
+ command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
+ command->context.payload = va_arg(args, MYSQLND_CSTRING);
+ command->context.silent = va_arg(args, unsigned int);
+
+ command->parent.free_command = mysqlnd_com_no_params_free_command;
+ command->parent.run = mysqlnd_com_change_user_run;
+ }
+
+ DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
+}
+/* }}} */
+
+
+/************************** COM_REAP_RESULT ******************************************/
+struct st_mysqlnd_protocol_com_reap_result_command
+{
+ struct st_mysqlnd_protocol_command parent;
+ struct st_mysqlnd_com_reap_result_context
+ {
+ MYSQLND_CONN_DATA * conn;
+ } context;
+};
+
+
+/* {{{ mysqlnd_com_reap_result_run */
+static enum_func_status
+mysqlnd_com_reap_result_run(void *cmd)
+{
+ struct st_mysqlnd_protocol_com_reap_result_command * command = (struct st_mysqlnd_protocol_com_reap_result_command *) cmd;
+ enum_func_status ret = FAIL;
+ MYSQLND_CONN_DATA * conn = command->context.conn;
+ enum_mysqlnd_connection_state state = CONN_GET_STATE(conn);
+
+ DBG_ENTER("mysqlnd_com_reap_result_run");
+ if (state <= CONN_READY || state == CONN_QUIT_SENT) {
+ php_error_docref(NULL, E_WARNING, "Connection not opened, clear or has been closed");
+ DBG_ERR_FMT("Connection not opened, clear or has been closed. State=%u", state);
+ DBG_RETURN(ret);
+ }
+ ret = conn->m->query_read_result_set_header(conn, NULL);
+
+ DBG_RETURN(ret);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_com_reap_result_create_command */
+static struct st_mysqlnd_protocol_command *
+mysqlnd_com_reap_result_create_command(va_list args)
+{
+ struct st_mysqlnd_protocol_com_reap_result_command * command;
+ DBG_ENTER("mysqlnd_com_reap_result_create_command");
+ command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_reap_result_command));
+ if (command) {
+ command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
+
+ command->parent.free_command = mysqlnd_com_no_params_free_command;
+ command->parent.run = mysqlnd_com_reap_result_run;
+ }
+
+ DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
+}
+/* }}} */
+
+
+/************************** COM_STMT_PREPARE ******************************************/
+struct st_mysqlnd_protocol_com_stmt_prepare_command
+{
+ struct st_mysqlnd_protocol_command parent;
+ struct st_mysqlnd_com_stmt_prepare_context
+ {
+ MYSQLND_CONN_DATA * conn;
+ MYSQLND_CSTRING query;
+ } context;
+};
+
+
+/* {{{ mysqlnd_com_stmt_prepare_run */
+static enum_func_status
+mysqlnd_com_stmt_prepare_run(void *cmd)
+{
+ struct st_mysqlnd_protocol_com_stmt_prepare_command * command = (struct st_mysqlnd_protocol_com_stmt_prepare_command *) cmd;
+ enum_func_status ret = FAIL;
+ MYSQLND_CONN_DATA * conn = command->context.conn;
+
+ DBG_ENTER("mysqlnd_com_stmt_prepare_run");
+
+ ret = conn->m->send_command_do_request(conn, COM_STMT_PREPARE, (zend_uchar*) command->context.query.s, command->context.query.l, FALSE, TRUE);
+
+ DBG_RETURN(ret);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_com_stmt_prepare_create_command */
+static struct st_mysqlnd_protocol_command *
+mysqlnd_com_stmt_prepare_create_command(va_list args)
+{
+ struct st_mysqlnd_protocol_com_stmt_prepare_command * command;
+ DBG_ENTER("mysqlnd_com_stmt_prepare_create_command");
+ command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_stmt_prepare_command));
+ if (command) {
+ command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
+ command->context.query = va_arg(args, MYSQLND_CSTRING);
+
+ command->parent.free_command = mysqlnd_com_no_params_free_command;
+ command->parent.run = mysqlnd_com_stmt_prepare_run;
+ }
+
+ DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
+}
+/* }}} */
+
+
+/************************** COM_STMT_EXECUTE ******************************************/
+struct st_mysqlnd_protocol_com_stmt_execute_command
+{
+ struct st_mysqlnd_protocol_command parent;
+ struct st_mysqlnd_com_stmt_execute_context
+ {
+ MYSQLND_CONN_DATA * conn;
+ MYSQLND_CSTRING payload;
+ } context;
+};
+
+
+/* {{{ mysqlnd_com_stmt_execute_run */
+static enum_func_status
+mysqlnd_com_stmt_execute_run(void *cmd)
+{
+ struct st_mysqlnd_protocol_com_stmt_execute_command * command = (struct st_mysqlnd_protocol_com_stmt_execute_command *) cmd;
+ enum_func_status ret = FAIL;
+ MYSQLND_CONN_DATA * conn = command->context.conn;
+
+ DBG_ENTER("mysqlnd_com_stmt_execute_run");
+
+ ret = conn->m->send_command_do_request(conn, COM_STMT_EXECUTE, (zend_uchar*) command->context.payload.s, command->context.payload.l, FALSE, FALSE);
+
+ DBG_RETURN(ret);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_com_stmt_execute_create_command */
+static struct st_mysqlnd_protocol_command *
+mysqlnd_com_stmt_execute_create_command(va_list args)
+{
+ struct st_mysqlnd_protocol_com_stmt_execute_command * command;
+ DBG_ENTER("mysqlnd_com_stmt_execute_create_command");
+ command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_stmt_execute_command));
+ if (command) {
+ command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
+ command->context.payload = va_arg(args, MYSQLND_CSTRING);
+
+ command->parent.free_command = mysqlnd_com_no_params_free_command;
+ command->parent.run = mysqlnd_com_stmt_execute_run;
+ }
+
+ DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
+}
+/* }}} */
+
+
+/************************** COM_STMT_FETCH ******************************************/
+struct st_mysqlnd_protocol_com_stmt_fetch_command
+{
+ struct st_mysqlnd_protocol_command parent;
+ struct st_mysqlnd_com_stmt_fetch_context
+ {
+ MYSQLND_CONN_DATA * conn;
+ MYSQLND_CSTRING payload;
+ } context;
+};
+
+
+/* {{{ mysqlnd_com_stmt_fetch_run */
+static enum_func_status
+mysqlnd_com_stmt_fetch_run(void *cmd)
+{
+ struct st_mysqlnd_protocol_com_stmt_fetch_command * command = (struct st_mysqlnd_protocol_com_stmt_fetch_command *) cmd;
+ enum_func_status ret = FAIL;
+ MYSQLND_CONN_DATA * conn = command->context.conn;
+
+ DBG_ENTER("mysqlnd_com_stmt_fetch_run");
+
+ ret = conn->m->send_command_do_request(conn, COM_STMT_FETCH, (zend_uchar*) command->context.payload.s, command->context.payload.l, FALSE, TRUE);
+
+ DBG_RETURN(ret);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_com_stmt_fetch_create_command */
+static struct st_mysqlnd_protocol_command *
+mysqlnd_com_stmt_fetch_create_command(va_list args)
+{
+ struct st_mysqlnd_protocol_com_stmt_fetch_command * command;
+ DBG_ENTER("mysqlnd_com_stmt_fetch_create_command");
+ command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_stmt_fetch_command));
+ if (command) {
+ command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
+ command->context.payload = va_arg(args, MYSQLND_CSTRING);
+
+ command->parent.free_command = mysqlnd_com_no_params_free_command;
+ command->parent.run = mysqlnd_com_stmt_fetch_run;
+ }
+
+ DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
+}
+/* }}} */
+
+
+/************************** COM_STMT_RESET ******************************************/
+struct st_mysqlnd_protocol_com_stmt_reset_command
+{
+ struct st_mysqlnd_protocol_command parent;
+ struct st_mysqlnd_com_stmt_reset_context
+ {
+ MYSQLND_CONN_DATA * conn;
+ zend_ulong stmt_id;
+ } context;
+};
+
+
+/* {{{ mysqlnd_com_stmt_reset_run */
+static enum_func_status
+mysqlnd_com_stmt_reset_run(void *cmd)
+{
+ zend_uchar cmd_buf[MYSQLND_STMT_ID_LENGTH /* statement id */];
+ struct st_mysqlnd_protocol_com_stmt_reset_command * command = (struct st_mysqlnd_protocol_com_stmt_reset_command *) cmd;
+ enum_func_status ret = FAIL;
+ MYSQLND_CONN_DATA * conn = command->context.conn;
+
+ DBG_ENTER("mysqlnd_com_stmt_reset_run");
+
+ int4store(cmd_buf, command->context.stmt_id);
+ ret = conn->m->send_command_do_request(conn, COM_STMT_RESET, cmd_buf, sizeof(cmd_buf), FALSE, TRUE);
+
+ DBG_RETURN(ret);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_com_stmt_reset_create_command */
+static struct st_mysqlnd_protocol_command *
+mysqlnd_com_stmt_reset_create_command(va_list args)
+{
+ struct st_mysqlnd_protocol_com_stmt_reset_command * command;
+ DBG_ENTER("mysqlnd_com_stmt_reset_create_command");
+ command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_stmt_reset_command));
+ if (command) {
+ command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
+ command->context.stmt_id = va_arg(args, size_t);
+
+ command->parent.free_command = mysqlnd_com_no_params_free_command;
+ command->parent.run = mysqlnd_com_stmt_reset_run;
+ }
+
+ DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
+}
+/* }}} */
+
+
+/************************** COM_STMT_SEND_LONG_DATA ******************************************/
+struct st_mysqlnd_protocol_com_stmt_send_long_data_command
+{
+ struct st_mysqlnd_protocol_command parent;
+ struct st_mysqlnd_com_stmt_send_long_data_context
+ {
+ MYSQLND_CONN_DATA * conn;
+ MYSQLND_CSTRING payload;
+ } context;
+};
+
+
+/* {{{ mysqlnd_com_stmt_send_long_data_run */
+static enum_func_status
+mysqlnd_com_stmt_send_long_data_run(void *cmd)
+{
+ struct st_mysqlnd_protocol_com_stmt_send_long_data_command * command = (struct st_mysqlnd_protocol_com_stmt_send_long_data_command *) cmd;
+ enum_func_status ret = FAIL;
+ MYSQLND_CONN_DATA * conn = command->context.conn;
+
+ DBG_ENTER("mysqlnd_com_stmt_send_long_data_run");
+
+ ret = conn->m->send_command_do_request(conn, COM_STMT_SEND_LONG_DATA, (zend_uchar*) command->context.payload.s, command->context.payload.l, FALSE, TRUE);
+
+ DBG_RETURN(ret);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_com_stmt_send_long_data_create_command */
+static struct st_mysqlnd_protocol_command *
+mysqlnd_com_stmt_send_long_data_create_command(va_list args)
+{
+ struct st_mysqlnd_protocol_com_stmt_send_long_data_command * command;
+ DBG_ENTER("mysqlnd_com_stmt_send_long_data_create_command");
+ command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_stmt_send_long_data_command));
+ if (command) {
+ command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
+ command->context.payload = va_arg(args, MYSQLND_CSTRING);
+
+ command->parent.free_command = mysqlnd_com_no_params_free_command;
+ command->parent.run = mysqlnd_com_stmt_send_long_data_run;
+ }
+
+ DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
+}
+/* }}} */
+
+
+/************************** COM_STMT_CLOSE ******************************************/
+struct st_mysqlnd_protocol_com_stmt_close_command
+{
+ struct st_mysqlnd_protocol_command parent;
+ struct st_mysqlnd_com_stmt_close_context
+ {
+ MYSQLND_CONN_DATA * conn;
+ zend_ulong stmt_id;
+ } context;
+};
+
+
+/* {{{ mysqlnd_com_stmt_close_run */
+static enum_func_status
+mysqlnd_com_stmt_close_run(void *cmd)
+{
+ zend_uchar cmd_buf[MYSQLND_STMT_ID_LENGTH /* statement id */];
+ struct st_mysqlnd_protocol_com_stmt_close_command * command = (struct st_mysqlnd_protocol_com_stmt_close_command *) cmd;
+ enum_func_status ret = FAIL;
+ MYSQLND_CONN_DATA * conn = command->context.conn;
+
+ DBG_ENTER("mysqlnd_com_stmt_close_run");
+
+ int4store(cmd_buf, command->context.stmt_id);
+ ret = conn->m->send_command_do_request(conn, COM_STMT_CLOSE, cmd_buf, sizeof(cmd_buf), FALSE, TRUE);
+
+ DBG_RETURN(ret);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_com_stmt_close_create_command */
+static struct st_mysqlnd_protocol_command *
+mysqlnd_com_stmt_close_create_command(va_list args)
+{
+ struct st_mysqlnd_protocol_com_stmt_close_command * command;
+ DBG_ENTER("mysqlnd_com_stmt_close_create_command");
+ command = mnd_ecalloc(1, sizeof(struct st_mysqlnd_protocol_com_stmt_close_command));
+ if (command) {
+ command->context.conn = va_arg(args, MYSQLND_CONN_DATA *);
+ command->context.stmt_id = va_arg(args, size_t);
+
+ command->parent.free_command = mysqlnd_com_no_params_free_command;
+ command->parent.run = mysqlnd_com_stmt_close_run;
+ }
+
+ DBG_RETURN((struct st_mysqlnd_protocol_command *) command);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_get_command */
+static struct st_mysqlnd_protocol_command *
+mysqlnd_get_command(enum php_mysqlnd_server_command command, ...)
+{
+ struct st_mysqlnd_protocol_command * ret;
+ va_list args;
+ DBG_ENTER("mysqlnd_get_command");
+
+ va_start(args, command);
+ switch (command) {
+ case COM_SET_OPTION:
+ ret = mysqlnd_com_set_option_create_command(args);
+ break;
+ case COM_DEBUG:
+ ret = mysqlnd_com_debug_create_command(args);
+ break;
+ case COM_INIT_DB:
+ ret = mysqlnd_com_init_db_create_command(args);
+ break;
+ case COM_PING:
+ ret = mysqlnd_com_ping_create_command(args);
+ break;
+ case COM_FIELD_LIST:
+ ret = mysqlnd_com_field_list_create_command(args);
+ break;
+ case COM_STATISTICS:
+ ret = mysqlnd_com_statistics_create_command(args);
+ break;
+ case COM_PROCESS_KILL:
+ ret = mysqlnd_com_process_kill_create_command(args);
+ break;
+ case COM_REFRESH:
+ ret = mysqlnd_com_refresh_create_command(args);
+ break;
+ case COM_SHUTDOWN:
+ ret = mysqlnd_com_shutdown_create_command(args);
+ break;
+ case COM_QUIT:
+ ret = mysqlnd_com_quit_create_command(args);
+ break;
+ case COM_QUERY:
+ ret = mysqlnd_com_query_create_command(args);
+ break;
+ case COM_REAP_RESULT:
+ ret = mysqlnd_com_reap_result_create_command(args);
+ break;
+ case COM_CHANGE_USER:
+ ret = mysqlnd_com_change_user_create_command(args);
+ break;
+ case COM_STMT_PREPARE:
+ ret = mysqlnd_com_stmt_prepare_create_command(args);
+ break;
+ case COM_STMT_EXECUTE:
+ ret = mysqlnd_com_stmt_execute_create_command(args);
+ break;
+ case COM_STMT_FETCH:
+ ret = mysqlnd_com_stmt_fetch_create_command(args);
+ break;
+ case COM_STMT_RESET:
+ ret = mysqlnd_com_stmt_reset_create_command(args);
+ break;
+ case COM_STMT_SEND_LONG_DATA:
+ ret = mysqlnd_com_stmt_send_long_data_create_command(args);
+ break;
+ case COM_STMT_CLOSE:
+ ret = mysqlnd_com_stmt_close_create_command(args);
+ break;
+ default:
+ break;
+ }
+ va_end(args);
+ DBG_RETURN(ret);
+}
+/* }}} */
+
+func_mysqlnd__command_factory mysqlnd_command_factory = mysqlnd_get_command;
+
/*
* Local variables:
* tab-width: 4