MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / cli_advanced_command

Function cli_advanced_command

sql-common/client.c:692–768  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

690}
691
692my_bool
693cli_advanced_command(MYSQL *mysql, enum enum_server_command command,
694 const uchar *header, ulong header_length,
695 const uchar *arg, ulong arg_length, my_bool skip_check,
696 MYSQL_STMT *stmt)
697{
698 NET *net= &mysql->net;
699 my_bool result= 1;
700 my_bool stmt_skip= stmt ? stmt->state != MYSQL_STMT_INIT_DONE : FALSE;
701 DBUG_ENTER("cli_advanced_command");
702
703 if (mysql->net.vio == 0)
704 { /* Do reconnect if possible */
705 if (mysql_reconnect(mysql) || stmt_skip)
706 DBUG_RETURN(1);
707 }
708 if (mysql->status != MYSQL_STATUS_READY ||
709 mysql->server_status & SERVER_MORE_RESULTS_EXISTS)
710 {
711 DBUG_PRINT("error",("state: %d", mysql->status));
712 set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
713 DBUG_RETURN(1);
714 }
715
716 net_clear_error(net);
717 mysql->info=0;
718 mysql->affected_rows= ~(my_ulonglong) 0;
719 /*
720 Do not check the socket/protocol buffer on COM_QUIT as the
721 result of a previous command might not have been read. This
722 can happen if a client sends a query but does not reap the
723 result before attempting to close the connection.
724 */
725 net_clear(&mysql->net, (command != COM_QUIT));
726
727#if !defined(EMBEDDED_LIBRARY)
728 /*
729 If auto-reconnect mode is enabled check if connection is still alive before
730 sending new command. Otherwise, send() might not notice that connection was
731 closed by the server (for example, due to KILL statement), and the fact that
732 connection is gone will be noticed only on attempt to read command's result,
733 when it is too late to reconnect. Note that such scenario can still occur if
734 connection gets killed after this check but before command is sent to
735 server. But this should be rare.
736 */
737 if ((command != COM_QUIT) && mysql->reconnect && !vio_is_connected(net->vio))
738 net->error= 2;
739#endif
740
741 if (net_write_command(net,(uchar) command, header, header_length,
742 arg, arg_length))
743 {
744 DBUG_PRINT("error",("Can't send command to server. Error: %d",
745 socket_errno));
746 if (net->last_errno == ER_NET_PACKET_TOO_LARGE)
747 {
748 set_mysql_error(mysql, CR_NET_PACKET_TOO_LARGE, unknown_sqlstate);
749 goto end;

Callers

nothing calls this directly

Calls 5

mysql_reconnectFunction · 0.85
set_mysql_errorFunction · 0.85
net_clear_errorFunction · 0.85
end_serverFunction · 0.85
cli_safe_readFunction · 0.85

Tested by

no test coverage detected