added detection of drop table targeting a temporary table

This commit is contained in:
Markus Makela 2014-08-31 20:19:47 +03:00
parent ecc89a823b
commit 58e8c05c8a
3 changed files with 40 additions and 19 deletions

View File

@ -540,7 +540,13 @@ static skygw_query_type_t resolve_query_type(
{
type |= QUERY_TYPE_CREATE_TMP_TABLE;
}
}
if(lex->sql_command == SQLCOM_DROP_TABLE)
{
type |= QUERY_TYPE_DROP_TABLE;
}
goto return_qtype;
}

View File

@ -46,7 +46,8 @@ typedef enum {
QUERY_TYPE_PREPARE_STMT = 0x0800, /*< Prepared stmt with id provided by server */
QUERY_TYPE_EXEC_STMT = 0x1000, /*< Execute prepared statement */
QUERY_TYPE_CREATE_TMP_TABLE = 0x2000, /*< Create temporary table */
QUERY_TYPE_READ_TMP_TABLE = 0x4000 /*< Read temporary table */
QUERY_TYPE_READ_TMP_TABLE = 0x4000, /*< Read temporary table */
QUERY_TYPE_DROP_TABLE = 0x8000
} skygw_query_type_t;

View File

@ -1364,6 +1364,31 @@ static int routeQuery(
* doesn't exist then create it first.
*/
if(QUERY_IS_TYPE(qtype, QUERY_TYPE_CREATE_TMP_TABLE) ||
QUERY_IS_TYPE(qtype, QUERY_TYPE_DROP_TABLE)){
tbl = skygw_get_table_names(querybuf,&tsize);
if(tsize == 1 && tbl[0])
{ /**One valid table created*/
klen = strlen(dbname) + strlen(tbl[0]) + 2;
hkey = calloc(klen,sizeof(char));
strcpy(hkey,dbname);
strcat(hkey,".");
strcat(hkey,tbl[0]);
}
if(tsize > 0){
for(i = 0;i<tsize;i++){
free(tbl[i]);
}
free(tbl);
}
}
if(QUERY_IS_TYPE(qtype, QUERY_TYPE_CREATE_TMP_TABLE)){
bool is_temp = true;
@ -1396,17 +1421,6 @@ static int routeQuery(
}
tbl = skygw_get_table_names(querybuf,&tsize);
if(tsize == 1 && tbl[0])
{ /**One valid table created*/
klen = strlen(dbname) + strlen(tbl[0]) + 2;
hkey = calloc(klen,sizeof(char));
strcpy(hkey,dbname);
strcat(hkey,".");
strcat(hkey,tbl[0]);
if(
hashtable_add(
rses_prop_tmp->rses_prop_data.temp_tables,
@ -1431,15 +1445,15 @@ static int routeQuery(
#endif
}
if(tsize > 0){
for(i = 0;i<tsize;i++){
free(tbl[i]);
}
free(tbl);
free(hkey);
/**Check if DROP TABLE... targets a temporary table*/
if(QUERY_IS_TYPE(qtype, QUERY_TYPE_DROP_TABLE)){
if(rses_prop_tmp && rses_prop_tmp->rses_prop_data.temp_tables){
hashtable_delete(rses_prop_tmp->rses_prop_data.temp_tables, (void *)hkey);
}
}
free(hkey);
if (master_dcb == NULL)
{
succp = get_dcb(&master_dcb, router_cli_ses, BE_MASTER);