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

Function parse_sql

sql/sql_parse.cc:2437–2495  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2435*/
2436
2437bool parse_sql(THD *thd,
2438 Parser_state *parser_state,
2439 Object_creation_ctx *creation_ctx)
2440{
2441 bool ret_value;
2442 DBUG_ASSERT(thd->m_parser_state == NULL);
2443 DBUG_ASSERT(thd->lex->m_sql_cmd == NULL);
2444
2445 MYSQL_QUERY_PARSE_START(thd->query());
2446 /* Backup creation context. */
2447
2448 Object_creation_ctx *backup_ctx= NULL;
2449
2450 if (creation_ctx)
2451 backup_ctx= creation_ctx->set_n_backup(thd);
2452
2453 /* Set parser state. */
2454
2455 thd->m_parser_state= parser_state;
2456
2457#ifdef HAVE_PSI_STATEMENT_DIGEST_INTERFACE
2458 /* Start Digest */
2459 thd->m_parser_state->m_lip.m_digest_psi= MYSQL_DIGEST_START(thd->m_statement_psi);
2460#endif
2461
2462 /* Parse the query. */
2463
2464 bool mysql_parse_status= MYSQLparse(thd) != 0;
2465
2466 /*
2467 Check that if MYSQLparse() failed either thd->is_error() is set, or an
2468 internal error handler is set.
2469
2470 The assert will not catch a situation where parsing fails without an
2471 error reported if an error handler exists. The problem is that the
2472 error handler might have intercepted the error, so thd->is_error() is
2473 not set. However, there is no way to be 100% sure here (the error
2474 handler might be for other errors than parsing one).
2475 */
2476
2477 DBUG_ASSERT(!mysql_parse_status ||
2478 (mysql_parse_status && thd->is_error()) ||
2479 (mysql_parse_status && thd->get_internal_handler()));
2480
2481 /* Reset parser state. */
2482
2483 thd->m_parser_state= NULL;
2484
2485 /* Restore creation context. */
2486
2487 if (creation_ctx)
2488 creation_ctx->restore_env(thd, backup_ctx);
2489
2490 /* That's it. */
2491
2492 ret_value= mysql_parse_status || thd->is_fatal_error;
2493 MYSQL_QUERY_PARSE_DONE(ret_value);
2494 return ret_value;

Callers 1

mysql_parseFunction · 0.85

Calls 5

set_n_backupMethod · 0.80
get_internal_handlerMethod · 0.80
restore_envMethod · 0.80
queryMethod · 0.45
is_errorMethod · 0.45

Tested by

no test coverage detected