From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 7C3FD240EE for ; Sat, 15 Dec 2018 07:06:12 -0500 (EST) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nfW0yumd28Ga for ; Sat, 15 Dec 2018 07:06:12 -0500 (EST) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id C190A23B85 for ; Sat, 15 Dec 2018 07:06:10 -0500 (EST) From: imeevma@tarantool.org Subject: [tarantool-patches] [PATCH v2 4/6] sql: fix "PRAGMA case_sensitive_like" result Date: Sat, 15 Dec 2018 15:03:43 +0300 Message-Id: In-Reply-To: References: Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: v.shpilevoy@tarantool.org, tarantool-patches@freelists.org Currently PRAGMA case_sensitive_like returns nothing. This seems wrong, since other similar pragmas return their status. Fixed in the current patch. Part of #3832 --- src/box/sql/pragma.c | 19 +++++++++++++------ src/box/sql/pragma.h | 4 ++-- src/box/sql/sqliteInt.h | 2 ++ test/sql/misc.result | 17 +++++++++++++++++ test/sql/misc.test.lua | 13 +++++++++++++ 5 files changed, 47 insertions(+), 8 deletions(-) diff --git a/src/box/sql/pragma.c b/src/box/sql/pragma.c index f34e7b8..9390f6f 100644 --- a/src/box/sql/pragma.c +++ b/src/box/sql/pragma.c @@ -591,13 +591,20 @@ sqlite3Pragma(Parse * pParse, Token * pId, /* First part of [schema.]id field */ * depending on the RHS. */ case PragTyp_CASE_SENSITIVE_LIKE:{ - if (zRight) { - int is_like_ci = - !(sqlite3GetBoolean(zRight, 0)); - sqlite3RegisterLikeFunctions(db, is_like_ci); - } - break; + int mask = pPragma->iArg; + if (zRight == NULL) { + returnSingleInt(v, + (user_session->sql_flags & mask) != 0); + } else { + int is_like_ci = !(sqlite3GetBoolean(zRight, 0)); + if (!is_like_ci) + user_session->sql_flags |= mask; + else + user_session->sql_flags &= ~mask; + sqlite3RegisterLikeFunctions(db, is_like_ci); } + break; + } case PragTyp_DEFAULT_ENGINE: { if (zRight == NULL) { diff --git a/src/box/sql/pragma.h b/src/box/sql/pragma.h index 59e0e1e..11a2e05 100644 --- a/src/box/sql/pragma.h +++ b/src/box/sql/pragma.h @@ -94,9 +94,9 @@ static const PragmaName aPragmaName[] = { /* iArg: */ 0}, { /* zName: */ "case_sensitive_like", /* ePragTyp: */ PragTyp_CASE_SENSITIVE_LIKE, - /* ePragFlg: */ PragFlg_NoColumns, + /* ePragFlg: */ PragFlg_Result0 | PragFlg_NoColumns1, /* ColNames: */ 0, 0, - /* iArg: */ 0}, + /* iArg: */ SQLITE_LikeIsCaseSens}, { /* zName: */ "collation_list", /* ePragTyp: */ PragTyp_COLLATION_LIST, /* ePragFlg: */ PragFlg_Result0, diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h index 3d4dead..17fb281 100644 --- a/src/box/sql/sqliteInt.h +++ b/src/box/sql/sqliteInt.h @@ -1565,6 +1565,8 @@ struct sqlite3 { #define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */ /* Debug print info about SQL query as it parsed */ #define SQLITE_ParserTrace 0x00000002 +/* True if LIKE is case sensitive. */ +#define SQLITE_LikeIsCaseSens 0x00000008 #define SQLITE_FullColNames 0x00000004 /* Show full column names on SELECT */ #define SQLITE_ShortColNames 0x00000040 /* Show short columns names */ #define SQLITE_CountRows 0x00000080 /* Count rows changed by INSERT, */ diff --git a/test/sql/misc.result b/test/sql/misc.result index ef104c1..f1031f7 100644 --- a/test/sql/misc.result +++ b/test/sql/misc.result @@ -40,3 +40,20 @@ box.sql.execute('\n\n\n\t\t\t ') --- - error: 'syntax error: empty request' ... +-- +-- gh-3832: Some statements do not return column type +-- Check that "PRAGMA case_sensitive_like" returns 0 or 1 if +-- called without parameter. +result = box.sql.execute('PRAGMA case_sensitive_like') +--- +... +-- Should be TRUE. +result[1][1] == 0 or result[1][1] == 1 +--- +- true +... +-- Check that "PRAGMA case_sensitive_like" returns nothing if +-- called with parameter. +box.sql.execute('PRAGMA case_sensitive_like = '.. result[1][1]) +--- +... diff --git a/test/sql/misc.test.lua b/test/sql/misc.test.lua index 994e64f..5952035 100644 --- a/test/sql/misc.test.lua +++ b/test/sql/misc.test.lua @@ -11,3 +11,16 @@ box.sql.execute(';') box.sql.execute('') box.sql.execute(' ;') box.sql.execute('\n\n\n\t\t\t ') + +-- +-- gh-3832: Some statements do not return column type + +-- Check that "PRAGMA case_sensitive_like" returns 0 or 1 if +-- called without parameter. +result = box.sql.execute('PRAGMA case_sensitive_like') +-- Should be TRUE. +result[1][1] == 0 or result[1][1] == 1 + +-- Check that "PRAGMA case_sensitive_like" returns nothing if +-- called with parameter. +box.sql.execute('PRAGMA case_sensitive_like = '.. result[1][1]) -- 2.7.4