diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index 28b435ae3..f57967bd8 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -631,12 +631,6 @@ static const int case_insensitive_like = 1;
*/
static const int case_sensitive_like = 0;
-/**
- * Wildcards.
- */
-#define match_one '_'
-#define match_all '%'
-
/**
* Possible error returns from sql_utf8_pattern_compare().
*/
@@ -693,7 +687,7 @@ sql_utf8_pattern_compare(const char *pattern,
c = Utf8Read(pattern, pattern_end);
if (c == SQL_INVALID_UTF8_SYMBOL)
return SQL_INVALID_PATTERN;
- if (c == match_all) {
+ if (c == MATCH_ALL_WILDCARD) {
/**
* Skip over multiple "%" characters in
* the pattern. If there are also "_"
@@ -705,9 +699,10 @@ sql_utf8_pattern_compare(const char *pattern,
SQL_END_OF_STRING) {
if (c == SQL_INVALID_UTF8_SYMBOL)
return SQL_INVALID_PATTERN;
- if (c != match_all && c != match_one)
+ if (c != MATCH_ALL_WILDCARD &&
+ c != MATCH_ONE_WILDCARD)
break;
- if (c == match_one &&
+ if (c == MATCH_ONE_WILDCARD &&
(c2 = Utf8Read(string, string_end)) ==
SQL_END_OF_STRING)
return SQL_NOWILDCARDMATCH;
@@ -801,7 +796,7 @@ sql_utf8_pattern_compare(const char *pattern,
c == u_tolower(c2))
continue;
}
- if (c == match_one && pattern != zEscaped &&
+ if (c == MATCH_ONE_WILDCARD && pattern != zEscaped &&
c2 != SQL_END_OF_STRING)
continue;
return SQL_NOMATCH;
@@ -894,11 +889,10 @@ likeFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
const unsigned char *zEsc = sqlite3_value_text(argv[2]);
if (zEsc == 0)
return;
+ const char *const err_msg =
+ "ESCAPE expression must be a single character";
if (sqlite3Utf8CharLen((char *)zEsc, -1) != 1) {
- sqlite3_result_error(context,
- "ESCAPE expression must be a"
- " single character",
- -1);
+ sqlite3_result_error(context, err_msg, -1);
return;
}
escape = sqlite3Utf8Read(&zEsc);
@@ -911,8 +905,9 @@ likeFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
int res;
res = sql_utf8_pattern_compare(zB, zA, *is_like_ci, escape);
if (res == SQL_INVALID_PATTERN) {
- sqlite3_result_error(context, "LIKE pattern can only contain"
- " UTF-8 characters", -1);
+ const char *const err_msg =
+ "LIKE pattern can only contain UTF-8 characters";
+ sqlite3_result_error(context, err_msg, -1);
return;
}
sqlite3_result_int(context, res == SQL_MATCH);
diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h
index a805adf22..420c76bfe 100644
--- a/src/box/sql/sqliteInt.h
+++ b/src/box/sql/sqliteInt.h
@@ -564,6 +564,12 @@ sqlite3_snprintf(int, char *, const char *, ...);
char *
sqlite3_vsnprintf(int, char *, const char *, va_list);
+/**
+ * Wildcard characters used in REGEXP-like operators.
+ */
+#define MATCH_ONE_WILDCARD '_'
+#define MATCH_ALL_WILDCARD '%'
+
int
sql_strlike_cs(const char *zLike, const char *zStr, unsigned int cEsc);
diff --git a/src/box/sql/whereexpr.c b/src/box/sql/whereexpr.c
index 2d9fb6453..616acc640 100644
--- a/src/box/sql/whereexpr.c
+++ b/src/box/sql/whereexpr.c
@@ -218,12 +218,6 @@ operatorMask(int op)
return c;
}
-/**
- * Wildcard characters.
- */
-#define match_one '_'
-#define match_all '%'
-
#ifndef SQLITE_OMIT_LIKE_OPTIMIZATION
/**
* Check to see if the given expression is a LIKE operator that
@@ -305,11 +299,13 @@ is_like(Parse *pParse,
}
if (z) {
cnt = 0;
- while ((c = z[cnt]) != 0 && c != match_one && c != match_all)
+ while ((c = z[cnt]) != 0 && c != MATCH_ONE_WILDCARD &&
+ c != MATCH_ALL_WILDCARD)
cnt++;
if (cnt != 0 && 255 != (u8) z[cnt - 1]) {
Expr *pPrefix;
- *pisComplete = c == match_all && z[cnt + 1] == 0;
+ *pisComplete = c == MATCH_ALL_WILDCARD &&
+ z[cnt + 1] == 0;
pPrefix = sqlite3Expr(db, TK_STRING, z);
if (pPrefix)
pPrefix->u.zToken[cnt] = 0;
diff --git a/test/sql-tap/e_expr.test.lua b/test/sql-tap/e_expr.test.lua
index 0d69e8535..6d1edcfd0 100755
--- a/test/sql-tap/e_expr.test.lua
+++ b/test/sql-tap/e_expr.test.lua
@@ -77,7 +77,6 @@ local operations = {
{"<>", "ne1"},
{"!=", "ne2"},
{"IS", "is"},
--- {"LIKE", "like"},
{"AND", "and"},
{"OR", "or"},
{"MATCH", "match"},
@@ -98,7 +97,7 @@ operations = {
-- Another NOTE: MATCH & REGEXP aren't supported in Tarantool &
-- are waiting for their hour, don't confuse them
-- being commented with commenting of "LIKE".
- {"=", "==", "!=", "<>"}, --"LIKE"}, --"MATCH", "REGEXP"},
+ {"=", "==", "!=", "<>"}, --"MATCH", "REGEXP"},
{"AND"},
{"OR"},
}
@@ -2278,10 +2277,12 @@ test:do_execsql_test(
-- </e_expr-17.2.0>
})
+test:execsql("PRAGMA case_sensitive_like = 0;")
+
test:do_execsql_test(
"e_expr-17.2.1",
[[
- SELECT 'abcxyz' NOT LIKE 'abc%'
+ SELECT 'abcxyz' NOT LIKE 'ABC%'
]], {
-- <e_expr-17.2.1>
0
@@ -2290,85 +2291,65 @@ test:do_execsql_test(
test:do_execsql_test(
"e_expr-17.2.2",
- [[
- PRAGMA case_sensitive_like = 0
- ]], {
- -- <e_expr-17.2.2>
-
- -- <e_expr-17.2.2>
- })
-
-test:do_execsql_test(
- "e_expr-17.2.3",
- [[
- SELECT 'abcxyz' NOT LIKE 'ABC%'
- ]], {
- -- <e_expr-17.2.3>
- 0
- -- </e_expr-17.2.3>
- })
-
-test:do_execsql_test(
- "e_expr-17.2.4",
[[
SELECT 'abcxyz' NOT LIKE 'abc%'
]], {
- -- <e_expr-17.2.4>
+ -- <e_expr-17.2.2>
0
- -- </e_expr-17.2.4>
+ -- </e_expr-17.2.2>
})
test:do_execsql_test(
- "e_expr-17.2.5",
+ "e_expr-17.2.3",
[[
SELECT 'abdxyz' NOT LIKE 'abc%'
]], {
- -- <e_expr-17.2.5>
+ -- <e_expr-17.2.3>
1
- -- </e_expr-17.2.5>
+ -- </e_expr-17.2.3>
})
-- MUST_WORK_TEST uses access to nullvalue... (sql parameters) and built in functions
if 0>0 then
db("nullvalue", "null")
test:do_execsql_test(
- "e_expr-17.2.6",
+ "e_expr-17.2.4",
[[
SELECT 'abcxyz' NOT GLOB NULL
]], {
- -- <e_expr-17.2.6>
+ -- <e_expr-17.2.4>
"null"
- -- </e_expr-17.2.6>
+ -- </e_expr-17.2.4>
})
test:do_execsql_test(
- "e_expr-17.2.7",
+ "e_expr-17.2.5",
[[
SELECT 'abcxyz' NOT LIKE NULL
]], {
- -- <e_expr-17.2.7>
+ -- <e_expr-17.2.5>
"null"
- -- </e_expr-17.2.7>
+ -- </e_expr-17.2.5>
})
test:do_execsql_test(
- "e_expr-17.2.8",
+ "e_expr-17.2.6",
[[
SELECT NULL NOT GLOB 'abc*'
]], {
- -- <e_expr-17.2.8>
+ -- <e_expr-17.2.6>
"null"
- -- </e_expr-17.2.8>
+ -- </e_expr-17.2.6>
})
test:do_execsql_test(
- "e_expr-17.2.9",
+ "e_expr-17.2.7",
[[
SELECT NULL NOT LIKE 'ABC%'
]], {
- -- <e_expr-17.2.9>
+ -- <e_expr-17.2.7>
"null"
- -- </e_expr-17.2.9>
+ -- </e_expr-17.2.7>
})
db("nullvalue", "")