Completed skygw_get_canonical by adding NULL checks and debug assertions. Replacable literal types are now INT_ITEM, STRING_ITEM, DECIMAL_ITEM, REAL_ITEM, VARBIN_ITEM and NULL_ITEM.

This commit is contained in:
VilhoRaatikka
2014-08-19 09:07:18 +03:00
parent 544e64a301
commit fb3a950a18

View File

@ -817,6 +817,20 @@ char* skygw_query_classifier_get_stmtname(
} }
/**
* Replace user-provided literals with question marks. Return a copy of the
* querystr with replacements.
*
* @param mysql Database pointer
* @param querystr Query string
*
* @return Copy of querystr where literals are replaces with question marks or
* NULL if querystr is NULL, thread context or lex are NULL or if replacement
* function fails.
*
* Replaced literal types are STRING_ITEM,INT_ITEM,DECIMAL_ITEM,REAL_ITEM,
* VARBIN_ITEM,NULL_ITEM
*/
char* skygw_get_canonical( char* skygw_get_canonical(
MYSQL* mysql, MYSQL* mysql,
char* querystr) char* querystr)
@ -824,37 +838,47 @@ char* skygw_get_canonical(
THD* thd; THD* thd;
LEX* lex; LEX* lex;
bool found = false; bool found = false;
char* newstr; char* newstr = NULL;
thd = (THD *)mysql->thd;
lex = thd->lex;
Item* item; Item* item;
ss_dassert(mysql != NULL && querystr != NULL);
if (querystr == NULL ||
mysql == NULL ||
(thd = (THD *)mysql->thd) == NULL ||
(lex = thd->lex) == NULL)
{
ss_dassert(thd != NULL && lex != NULL);
goto retblock;
}
for (item=thd->free_list; item != NULL; item=item->next) for (item=thd->free_list; item != NULL; item=item->next)
{ {
Item::Type itype; Item::Type itype;
itype = item->type(); itype = item->type();
if (itype == Item::STRING_ITEM || itype == Item::INT_ITEM) if (itype == Item::STRING_ITEM ||
itype == Item::INT_ITEM ||
itype == Item::DECIMAL_ITEM ||
itype == Item::REAL_ITEM ||
itype == Item::VARBIN_ITEM ||
itype == Item::NULL_ITEM)
{ {
if (!found) if (!found)
{ {
newstr = replace_str(querystr, newstr = replace_str(querystr, item->name, "?");
item->name,
"?");
found = true; found = true;
} }
else else
{ {
char* prevstr = newstr; char* prevstr = newstr;
newstr = replace_str(prevstr, newstr = replace_str(prevstr, item->name, "?");
item->name,
"?");
free(prevstr); free(prevstr);
} }
} }
} /*< for */ } /*< for */
retblock:
return newstr; return newstr;
} }