query_classifier: implemented skygw_get_canonical which returns a copy of original string with given substrings being replaced with questionmarks.

skygw_utils.cc: added string replacement function for use of skygw_get_canonical
This commit is contained in:
VilhoRaatikka
2014-08-18 14:19:46 +03:00
parent 087c4720bb
commit 544e64a301
4 changed files with 114 additions and 2 deletions

View File

@ -412,7 +412,7 @@ static skygw_query_type_t resolve_query_type(
ss_info_dassert(thd != NULL, ("thd is NULL\n"));
force_data_modify_op_replication = FALSE;
force_data_modify_op_replication = FALSE;
lex = thd->lex;
/** SELECT ..INTO variable|OUTFILE|DUMPFILE */
@ -816,3 +816,45 @@ char* skygw_query_classifier_get_stmtname(
return ((THD *)(mysql->thd))->lex->prepared_stmt_name.str;
}
char* skygw_get_canonical(
MYSQL* mysql,
char* querystr)
{
THD* thd;
LEX* lex;
bool found = false;
char* newstr;
thd = (THD *)mysql->thd;
lex = thd->lex;
Item* item;
for (item=thd->free_list; item != NULL; item=item->next)
{
Item::Type itype;
itype = item->type();
if (itype == Item::STRING_ITEM || itype == Item::INT_ITEM)
{
if (!found)
{
newstr = replace_str(querystr,
item->name,
"?");
found = true;
}
else
{
char* prevstr = newstr;
newstr = replace_str(prevstr,
item->name,
"?");
free(prevstr);
}
}
} /*< for */
return newstr;
}

View File

@ -60,6 +60,8 @@ skygw_query_type_t skygw_query_classifier_get_type(
/** Free THD context and close MYSQL */
void skygw_query_classifier_free(MYSQL* mysql);
char* skygw_query_classifier_get_stmtname(MYSQL* mysql);
char* skygw_get_canonical(MYSQL* mysql, char* querystr);
EXTERN_C_BLOCK_END