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

Function net_send_error_packet

sql/protocol.cc:360–402  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

358*/
359
360bool net_send_error_packet(THD *thd, uint sql_errno, const char *err,
361 const char* sqlstate)
362
363{
364 NET *net= &thd->net;
365 uint length;
366 /*
367 buff[]: sql_errno:2 + ('#':1 + SQLSTATE_LENGTH:5) + MYSQL_ERRMSG_SIZE:512
368 */
369 uint error;
370 char converted_err[MYSQL_ERRMSG_SIZE];
371 char buff[2+1+SQLSTATE_LENGTH+MYSQL_ERRMSG_SIZE], *pos;
372
373 DBUG_ENTER("send_error_packet");
374
375 if (net->vio == 0)
376 {
377 if (thd->bootstrap)
378 {
379 /* In bootstrap it's ok to print on stderr */
380 fprintf(stderr,"ERROR: %d %s\n",sql_errno,err);
381 }
382 DBUG_RETURN(FALSE);
383 }
384
385 int2store(buff,sql_errno);
386 pos= buff+2;
387 if (thd->client_capabilities & CLIENT_PROTOCOL_41)
388 {
389 /* The first # is to make the protocol backward compatible */
390 buff[2]= '#';
391 pos= strmov(buff+3, sqlstate);
392 }
393
394 convert_error_message(converted_err, sizeof(converted_err),
395 thd->variables.character_set_results,
396 err, strlen(err), system_charset_info, &error);
397 /* Converted error message is always null-terminated. */
398 length= (uint) (strmake(pos, converted_err, MYSQL_ERRMSG_SIZE - 1) - buff);
399
400 DBUG_RETURN(net_write_command(net,(uchar) 255, (uchar*) "", 0, (uchar*) buff,
401 length));
402}
403
404#endif /* EMBEDDED_LIBRARY */
405

Callers 2

net_send_errorFunction · 0.85
send_errorMethod · 0.85

Calls 3

strmovFunction · 0.85
convert_error_messageFunction · 0.85
strmakeFunction · 0.85

Tested by

no test coverage detected