From 3084e95772e0fa96434844bd45f9f48f879639da Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Wed, 31 May 2017 15:01:41 +0300 Subject: [PATCH] MXS-1275: Implement qc_[get|set]_sql_mode for qc_sqlite --- query_classifier/qc_sqlite/qc_sqlite.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/query_classifier/qc_sqlite/qc_sqlite.c b/query_classifier/qc_sqlite/qc_sqlite.c index 8b2dfb083..bb5924059 100644 --- a/query_classifier/qc_sqlite/qc_sqlite.c +++ b/query_classifier/qc_sqlite/qc_sqlite.c @@ -148,9 +148,10 @@ static struct */ static thread_local struct { - bool initialized; - sqlite3* db; // Thread specific database handle. - QC_SQLITE_INFO* info; + bool initialized; // Whether the thread specific data has been initialized. + sqlite3* db; // Thread specific database handle. + 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; /** @@ -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_capacity = 0; info->initializing = false; - info->sql_mode = this_unit.sql_mode; + info->sql_mode = this_thread.sql_mode; 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_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_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) { @@ -3495,6 +3498,7 @@ static int32_t qc_sqlite_thread_init(void) int rc = sqlite3_open(":memory:", &this_thread.db); if (rc == SQLITE_OK) { + this_thread.sql_mode = this_unit.sql_mode; this_thread.initialized = true; 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) { - 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) { - return QC_RESULT_ERROR; + this_thread.sql_mode = sql_mode; + return QC_RESULT_OK; } /**