MXS-1196: Recognize builtin Oracle functions
This commit is contained in:
@ -368,6 +368,16 @@ static const char* BUILTIN_FUNCTIONS[] =
|
|||||||
|
|
||||||
const size_t N_BUILTIN_FUNCTIONS = sizeof(BUILTIN_FUNCTIONS) / sizeof(BUILTIN_FUNCTIONS[0]);
|
const size_t N_BUILTIN_FUNCTIONS = sizeof(BUILTIN_FUNCTIONS) / sizeof(BUILTIN_FUNCTIONS[0]);
|
||||||
|
|
||||||
|
|
||||||
|
static const char* ORACLE_FUNCTIONS[] =
|
||||||
|
{
|
||||||
|
"nvl",
|
||||||
|
"nvl2"
|
||||||
|
};
|
||||||
|
|
||||||
|
const size_t N_ORACLE_FUNCTIONS = sizeof(ORACLE_FUNCTIONS) / sizeof(ORACLE_FUNCTIONS[0]);
|
||||||
|
|
||||||
|
|
||||||
// NOTE: sort_compare and search_compare are not identical, so don't
|
// NOTE: sort_compare and search_compare are not identical, so don't
|
||||||
// NOTE: optimize either of them away.
|
// NOTE: optimize either of them away.
|
||||||
static int sort_compare(const void* key, const void* value)
|
static int sort_compare(const void* key, const void* value)
|
||||||
@ -389,6 +399,7 @@ void init_builtin_functions()
|
|||||||
ss_dassert(!unit.inited);
|
ss_dassert(!unit.inited);
|
||||||
|
|
||||||
qsort(BUILTIN_FUNCTIONS, N_BUILTIN_FUNCTIONS, sizeof(char*), sort_compare);
|
qsort(BUILTIN_FUNCTIONS, N_BUILTIN_FUNCTIONS, sizeof(char*), sort_compare);
|
||||||
|
qsort(ORACLE_FUNCTIONS, N_ORACLE_FUNCTIONS, sizeof(char*), sort_compare);
|
||||||
|
|
||||||
unit.inited = true;
|
unit.inited = true;
|
||||||
}
|
}
|
||||||
@ -399,11 +410,16 @@ void finish_builtin_functions()
|
|||||||
unit.inited = false;
|
unit.inited = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_builtin_readonly_function(const char* key)
|
bool is_builtin_readonly_function(const char* key, bool check_oracle)
|
||||||
{
|
{
|
||||||
ss_dassert(unit.inited);
|
ss_dassert(unit.inited);
|
||||||
|
|
||||||
char* value = bsearch(key, BUILTIN_FUNCTIONS, N_BUILTIN_FUNCTIONS, sizeof(char*), search_compare);
|
char* value = bsearch(key, BUILTIN_FUNCTIONS, N_BUILTIN_FUNCTIONS, sizeof(char*), search_compare);
|
||||||
|
|
||||||
|
if (!value && check_oracle)
|
||||||
|
{
|
||||||
|
value = bsearch(key, ORACLE_FUNCTIONS, N_ORACLE_FUNCTIONS, sizeof(char*), search_compare);
|
||||||
|
}
|
||||||
|
|
||||||
return value ? true : false;
|
return value ? true : false;
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ extern "C" {
|
|||||||
void init_builtin_functions();
|
void init_builtin_functions();
|
||||||
void finish_builtin_functions();
|
void finish_builtin_functions();
|
||||||
|
|
||||||
bool is_builtin_readonly_function(const char* zToken);
|
bool is_builtin_readonly_function(const char* zToken, bool check_oracle);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -1187,7 +1187,7 @@ static void update_field_infos(QC_SQLITE_INFO* info,
|
|||||||
{
|
{
|
||||||
info->type_mask |= (QUERY_TYPE_READ | QUERY_TYPE_MASTER_READ);
|
info->type_mask |= (QUERY_TYPE_READ | QUERY_TYPE_MASTER_READ);
|
||||||
}
|
}
|
||||||
else if (!is_builtin_readonly_function(zToken))
|
else if (!is_builtin_readonly_function(zToken, this_unit.sql_mode == QC_SQL_MODE_ORACLE))
|
||||||
{
|
{
|
||||||
info->type_mask |= QUERY_TYPE_WRITE;
|
info->type_mask |= QUERY_TYPE_WRITE;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user