MXS-1275: Implement qc_[get|set]_sql_mode for qc_sqlite

This commit is contained in:
Johan Wikman
2017-05-31 15:01:41 +03:00
parent 9ae0526efb
commit 3084e95772

View File

@ -148,9 +148,10 @@ static struct
*/ */
static thread_local struct static thread_local struct
{ {
bool initialized; bool initialized; // Whether the thread specific data has been initialized.
sqlite3* db; // Thread specific database handle. sqlite3* db; // Thread specific database handle.
QC_SQLITE_INFO* info; qc_sql_mode_t sql_mode; // What sql_mode is used.
QC_SQLITE_INFO* info; // The information for the current statement being classified.
} this_thread; } this_thread;
/** /**
@ -437,7 +438,7 @@ static QC_SQLITE_INFO* info_init(QC_SQLITE_INFO* info, uint32_t collect)
info->function_infos_len = 0; info->function_infos_len = 0;
info->function_infos_capacity = 0; info->function_infos_capacity = 0;
info->initializing = false; info->initializing = false;
info->sql_mode = this_unit.sql_mode; info->sql_mode = this_thread.sql_mode;
return info; return info;
} }
@ -3297,6 +3298,8 @@ static int32_t qc_sqlite_get_canonical(GWBUF* query, char** canonical);
static int32_t qc_sqlite_query_has_clause(GWBUF* query, int32_t* has_clause); static int32_t qc_sqlite_query_has_clause(GWBUF* query, int32_t* has_clause);
static int32_t qc_sqlite_get_database_names(GWBUF* query, char*** names, int* sizep); static int32_t qc_sqlite_get_database_names(GWBUF* query, char*** names, int* sizep);
static int32_t qc_sqlite_get_preparable_stmt(GWBUF* stmt, GWBUF** preparable_stmt); static int32_t qc_sqlite_get_preparable_stmt(GWBUF* stmt, GWBUF** preparable_stmt);
static int32_t qc_sqlite_get_sql_mode(qc_sql_mode_t* sql_mode);
static int32_t qc_sqlite_set_sql_mode(qc_sql_mode_t sql_mode);
static bool get_key_and_value(char* arg, const char** pkey, const char** pvalue) static bool get_key_and_value(char* arg, const char** pkey, const char** pvalue)
{ {
@ -3495,6 +3498,7 @@ static int32_t qc_sqlite_thread_init(void)
int rc = sqlite3_open(":memory:", &this_thread.db); int rc = sqlite3_open(":memory:", &this_thread.db);
if (rc == SQLITE_OK) if (rc == SQLITE_OK)
{ {
this_thread.sql_mode = this_unit.sql_mode;
this_thread.initialized = true; this_thread.initialized = true;
MXS_INFO("In-memory sqlite database successfully opened for thread %lu.", MXS_INFO("In-memory sqlite database successfully opened for thread %lu.",
@ -3967,12 +3971,14 @@ int32_t qc_sqlite_get_preparable_stmt(GWBUF* stmt, GWBUF** preparable_stmt)
int32_t qc_sqlite_get_sql_mode(qc_sql_mode_t* sql_mode) int32_t qc_sqlite_get_sql_mode(qc_sql_mode_t* sql_mode)
{ {
return QC_RESULT_ERROR; *sql_mode = this_thread.sql_mode;
return QC_RESULT_OK;
} }
int32_t qc_sqlite_set_sql_mode(qc_sql_mode_t sql_mode) int32_t qc_sqlite_set_sql_mode(qc_sql_mode_t sql_mode)
{ {
return QC_RESULT_ERROR; this_thread.sql_mode = sql_mode;
return QC_RESULT_OK;
} }
/** /**