[tarantool-patches] [PATCH v6 4/7] sql: fix "PRAGMA case_sensitive_like" result

imeevma at tarantool.org imeevma at tarantool.org
Thu Feb 21 16:00:50 MSK 2019


Currently PRAGMA case_sensitive_like returns nothing. This seems
wrong, since other similar pragmas return their status. Fixed in
the current patch.
---
 src/box/sql/pragma.c         | 21 +++++++--------------
 src/box/sql/pragma.h         |  7 +++----
 src/box/sql/sqlInt.h         |  2 ++
 test/sql-tap/pragma.test.lua | 18 +++++++++++++++++-
 4 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/src/box/sql/pragma.c b/src/box/sql/pragma.c
index 097f22b..c2431bf 100644
--- a/src/box/sql/pragma.c
+++ b/src/box/sql/pragma.c
@@ -503,6 +503,13 @@ sqlPragma(Parse * pParse, Token * pId,	/* First part of [schema.]id field */
 					sqlParserTrace(0, 0);
 			}
 #endif
+			/*
+			 * Reinstall the LIKE and functions. The
+			 * variant of LIKE * used will be case
+			 * sensitive or not depending on the RHS.
+			 */
+			if (mask == LIKE_CASE_SENS_FLAG)
+				sqlRegisterLikeFunctions(db, !is_pragma_set);
 		}
 		break;
 	}
@@ -583,20 +590,6 @@ sqlPragma(Parse * pParse, Token * pId,	/* First part of [schema.]id field */
 		break;
 	}
 
-		/*
-		 * Reinstall the LIKE and functions. The variant
-		 * of LIKE * used will be case sensitive or not
-		 * depending on the RHS.
-		 */
-	case PragTyp_CASE_SENSITIVE_LIKE:{
-			if (zRight) {
-				int is_like_ci =
-					!(sqlGetBoolean(zRight, 0));
-				sqlRegisterLikeFunctions(db, is_like_ci);
-			}
-			break;
-		}
-
 	case PragTyp_DEFAULT_ENGINE: {
 		if (!token_is_string(pValue)) {
 			diag_set(ClientError, ER_ILLEGAL_PARAMS,
diff --git a/src/box/sql/pragma.h b/src/box/sql/pragma.h
index 9c8e79c..31c83b5 100644
--- a/src/box/sql/pragma.h
+++ b/src/box/sql/pragma.h
@@ -5,7 +5,6 @@
  */
 
 /* The various pragma types */
-#define PragTyp_CASE_SENSITIVE_LIKE            2
 #define PragTyp_COLLATION_LIST                 3
 #define PragTyp_FLAG                           5
 #define PragTyp_FOREIGN_KEY_LIST               9
@@ -82,10 +81,10 @@ typedef struct PragmaName {
  */
 static const PragmaName aPragmaName[] = {
 	{ /* zName:     */ "case_sensitive_like",
-	 /* ePragTyp:  */ PragTyp_CASE_SENSITIVE_LIKE,
-	 /* ePragFlg:  */ PragFlg_NoColumns,
+	 /* ePragTyp:  */ PragTyp_FLAG,
+	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
 	 /* ColNames:  */ 0, 0,
-	 /* iArg:      */ 0},
+	 /* iArg:      */ LIKE_CASE_SENS_FLAG},
 	{ /* zName:     */ "collation_list",
 	 /* ePragTyp:  */ PragTyp_COLLATION_LIST,
 	 /* ePragFlg:  */ PragFlg_Result0,
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 0d8945d..ace9b0d 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -1525,6 +1525,8 @@ struct sql {
 /* Debug print info about SQL query as it parsed */
 #define PARSER_TRACE_FLAG  0x00000002
 #define SQL_FullColNames   0x00000004	/* Show full column names on SELECT */
+/* True if LIKE is case sensitive. */
+#define LIKE_CASE_SENS_FLAG 0x00000008
 #define SQL_ShortColNames  0x00000040	/* Show short columns names */
 #define SQL_CountRows      0x00000080	/* Count rows changed by INSERT, */
 					  /*   DELETE, or UPDATE and return */
diff --git a/test/sql-tap/pragma.test.lua b/test/sql-tap/pragma.test.lua
index 5055ba7..935cb96 100755
--- a/test/sql-tap/pragma.test.lua
+++ b/test/sql-tap/pragma.test.lua
@@ -1,7 +1,7 @@
 #!/usr/bin/env tarantool
 test = require("sqltester")
 
-test:plan(8)
+test:plan(9)
 
 test:do_catchsql_test(
 	"pragma-1.3",
@@ -81,4 +81,20 @@ test:do_execsql_test(
 	-- <pragma-3.2>
 })
 
+-- Check that "PRAGMA case_sensitive_like" returns its status
+-- (0 or 1) if called without parameter.
+test:do_test(
+	"pragma-3.3",
+	function()
+		old_value = box.sql.execute('PRAGMA case_sensitive_like')
+		box.sql.execute('PRAGMA case_sensitive_like = 1')
+		new_value = box.sql.execute('PRAGMA case_sensitive_like')
+		box.sql.execute('PRAGMA case_sensitive_like = '.. old_value[1][1])
+		return new_value[1][1]
+	end,
+	-- <pragma-3.3>
+	1
+	-- <pragma-3.3>
+	)
+
 test:finish_test()
-- 
2.7.4





More information about the Tarantool-patches mailing list