added detection of drop table targeting a temporary table
This commit is contained in:
@ -540,6 +540,12 @@ static skygw_query_type_t resolve_query_type(
|
|||||||
{
|
{
|
||||||
type |= QUERY_TYPE_CREATE_TMP_TABLE;
|
type |= QUERY_TYPE_CREATE_TMP_TABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(lex->sql_command == SQLCOM_DROP_TABLE)
|
||||||
|
{
|
||||||
|
type |= QUERY_TYPE_DROP_TABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
goto return_qtype;
|
goto return_qtype;
|
||||||
|
|||||||
@ -46,7 +46,8 @@ typedef enum {
|
|||||||
QUERY_TYPE_PREPARE_STMT = 0x0800, /*< Prepared stmt with id provided by server */
|
QUERY_TYPE_PREPARE_STMT = 0x0800, /*< Prepared stmt with id provided by server */
|
||||||
QUERY_TYPE_EXEC_STMT = 0x1000, /*< Execute prepared statement */
|
QUERY_TYPE_EXEC_STMT = 0x1000, /*< Execute prepared statement */
|
||||||
QUERY_TYPE_CREATE_TMP_TABLE = 0x2000, /*< Create temporary table */
|
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;
|
} skygw_query_type_t;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1364,6 +1364,31 @@ static int routeQuery(
|
|||||||
* doesn't exist then create it first.
|
* 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)){
|
if(QUERY_IS_TYPE(qtype, QUERY_TYPE_CREATE_TMP_TABLE)){
|
||||||
|
|
||||||
bool is_temp = true;
|
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(
|
if(
|
||||||
hashtable_add(
|
hashtable_add(
|
||||||
rses_prop_tmp->rses_prop_data.temp_tables,
|
rses_prop_tmp->rses_prop_data.temp_tables,
|
||||||
@ -1431,14 +1445,14 @@ static int routeQuery(
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tsize > 0){
|
/**Check if DROP TABLE... targets a temporary table*/
|
||||||
for(i = 0;i<tsize;i++){
|
if(QUERY_IS_TYPE(qtype, QUERY_TYPE_DROP_TABLE)){
|
||||||
free(tbl[i]);
|
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(tbl);
|
}
|
||||||
|
|
||||||
free(hkey);
|
free(hkey);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (master_dcb == NULL)
|
if (master_dcb == NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user