MCPcopy Create free account
hub / github.com/MariaDB/server / net_send_error_packet

Method net_send_error_packet

sql/protocol.cc:411–476  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

409*/
410
411bool Protocol::net_send_error_packet(THD *thd, uint sql_errno, const char *err,
412 const char* sqlstate)
413{
414 NET *net= &thd->net;
415 uint length;
416 /*
417 buff[]: sql_errno:2 + ('#':1 + SQLSTATE_LENGTH:5) + MYSQL_ERRMSG_SIZE:512
418 */
419 uint error;
420 char converted_err[MYSQL_ERRMSG_SIZE];
421 char buff[2+1+SQLSTATE_LENGTH+MYSQL_ERRMSG_SIZE], *pos;
422 my_bool ret;
423 uint8 save_compress;
424 DBUG_ENTER("Protocol::send_error_packet");
425
426 if (net->vio == 0)
427 {
428 if (thd->bootstrap)
429 {
430 /* In bootstrap it's ok to print on stderr */
431 fprintf(stderr,"ERROR: %d %s\n",sql_errno,err);
432 }
433 DBUG_RETURN(FALSE);
434 }
435
436 int2store(buff,sql_errno);
437 pos= buff+2;
438 if (thd->client_capabilities & CLIENT_PROTOCOL_41)
439 {
440 /* The first # is to make the protocol backward compatible */
441 buff[2]= '#';
442 pos= strmov(buff+3, sqlstate);
443 }
444
445 convert_error_message(converted_err, sizeof(converted_err),
446 thd->variables.character_set_results,
447 err, strlen(err), system_charset_info, &error);
448 /* Converted error message is always null-terminated. */
449 length= (uint) (strmake(pos, converted_err, MYSQL_ERRMSG_SIZE - 1) - buff);
450
451 /*
452 Ensure that errors are not compressed. This is to ensure we can
453 detect out of bands error messages in the client
454 */
455 if ((save_compress= net->compress))
456 net->compress= 2;
457
458 /*
459 Sometimes, we send errors "out-of-band", e.g ER_CONNECTION_KILLED
460 on an idle connection. The current protocol "sequence number" is 0,
461 however some client drivers would however always expect packets
462 coming from server to have seq_no > 0, due to missing awareness
463 of "out-of-band" operations. Make these clients happy.
464 */
465 if (!net->pkt_nr &&
466 (sql_errno == ER_CONNECTION_KILLED || sql_errno == ER_SERVER_SHUTDOWN ||
467 sql_errno == ER_QUERY_INTERRUPTED))
468 {

Callers

nothing calls this directly

Calls 5

int2storeFunction · 0.85
strmovFunction · 0.85
convert_error_messageFunction · 0.85
strmakeFunction · 0.85
net_write_commandFunction · 0.85

Tested by

no test coverage detected