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

Function my_xpath_parse_VariableReference

sql/item_xmlfunc.cc:2462–2508  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2460*/
2461
2462static int
2463my_xpath_parse_VariableReference(MY_XPATH *xpath)
2464{
2465 LEX_STRING name;
2466 int user_var;
2467 const char *dollar_pos;
2468 if (!my_xpath_parse_term(xpath, MY_XPATH_LEX_DOLLAR) ||
2469 (!(dollar_pos= xpath->prevtok.beg)) ||
2470 (!((user_var= my_xpath_parse_term(xpath, MY_XPATH_LEX_AT) &&
2471 my_xpath_parse_term(xpath, MY_XPATH_LEX_IDENT))) &&
2472 !my_xpath_parse_term(xpath, MY_XPATH_LEX_IDENT)))
2473 return 0;
2474
2475 name.length= xpath->prevtok.end - xpath->prevtok.beg;
2476 name.str= (char*) xpath->prevtok.beg;
2477
2478 if (user_var)
2479 xpath->item= new Item_func_get_user_var(Name_string(name, false));
2480 else
2481 {
2482 sp_variable *spv;
2483 sp_pcontext *spc;
2484 LEX *lex;
2485 if ((lex= current_thd->lex) &&
2486 (spc= lex->get_sp_current_parsing_ctx()) &&
2487 (spv= spc->find_variable(name, false)))
2488 {
2489 Item_splocal *splocal= new Item_splocal(Name_string(name, false),
2490 spv->offset, spv->type, 0);
2491#ifndef DBUG_OFF
2492 if (splocal)
2493 splocal->m_sp= lex->sphead;
2494#endif
2495 xpath->item= (Item*) splocal;
2496 }
2497 else
2498 {
2499 xpath->item= NULL;
2500 DBUG_ASSERT(xpath->query.end > dollar_pos);
2501 uint len= xpath->query.end - dollar_pos;
2502 set_if_smaller(len, 32);
2503 my_printf_error(ER_UNKNOWN_ERROR, "Unknown XPATH variable at: '%.*s'",
2504 MYF(0), len, dollar_pos);
2505 }
2506 }
2507 return xpath->item ? 1 : 0;
2508}
2509
2510
2511/*

Callers 1

Calls 5

my_xpath_parse_termFunction · 0.85
Name_stringClass · 0.85
my_printf_errorFunction · 0.85
find_variableMethod · 0.80

Tested by

no test coverage detected