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

Function cli_safe_read

sql-common/client.c:613–681  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

611*/
612
613ulong
614cli_safe_read(MYSQL *mysql)
615{
616 NET *net= &mysql->net;
617 ulong len=0;
618
619 if (net->vio != 0)
620 len=my_net_read(net);
621
622 if (len == packet_error || len == 0)
623 {
624 DBUG_PRINT("error",("Wrong connection or packet. fd: %s len: %lu",
625 vio_description(net->vio),len));
626#ifdef MYSQL_SERVER
627 if (net->vio && (net->last_errno == ER_NET_READ_INTERRUPTED))
628 return (packet_error);
629#endif /*MYSQL_SERVER*/
630 end_server(mysql);
631 set_mysql_error(mysql, net->last_errno == ER_NET_PACKET_TOO_LARGE ?
632 CR_NET_PACKET_TOO_LARGE: CR_SERVER_LOST, unknown_sqlstate);
633 return (packet_error);
634 }
635 if (net->read_pos[0] == 255)
636 {
637 if (len > 3)
638 {
639 char *pos=(char*) net->read_pos+1;
640 net->last_errno=uint2korr(pos);
641 pos+=2;
642 len-=2;
643 if (protocol_41(mysql) && pos[0] == '#')
644 {
645 strmake(net->sqlstate, pos+1, SQLSTATE_LENGTH);
646 pos+= SQLSTATE_LENGTH+1;
647 }
648 else
649 {
650 /*
651 The SQL state hasn't been received -- it should be reset to HY000
652 (unknown error sql state).
653 */
654
655 strmov(net->sqlstate, unknown_sqlstate);
656 }
657
658 (void) strmake(net->last_error,(char*) pos,
659 MY_MIN((uint) len,(uint) sizeof(net->last_error)-1));
660 }
661 else
662 set_mysql_error(mysql, CR_UNKNOWN_ERROR, unknown_sqlstate);
663 /*
664 Cover a protocol design error: error packet does not
665 contain the server status. Therefore, the client has no way
666 to find out whether there are more result sets of
667 a multiple-result-set statement pending. Luckily, in 5.0 an
668 error always aborts execution of a statement, wherever it is
669 a multi-statement or a stored procedure, so it should be
670 safe to unconditionally turn off the flag here.

Callers 9

cli_advanced_commandFunction · 0.85
flush_one_resultFunction · 0.85
opt_flush_ok_packetFunction · 0.85
cli_read_rowsFunction · 0.85
read_one_rowFunction · 0.85
run_plugin_authFunction · 0.85
client.cFile · 0.85
cli_read_query_resultFunction · 0.85

Calls 4

end_serverFunction · 0.85
set_mysql_errorFunction · 0.85
strmakeFunction · 0.85
strmovFunction · 0.85

Tested by

no test coverage detected