diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index 40c5a5da8170c43315fe2657a91be64fe8a58b87..8ab9bfcf4e7685081cd6f09990f5365d94c4094b 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -262,7 +262,7 @@ int32_t shellRunCommand(TAOS* con, char* command) { } if (c == '\\') { - if (quote != 0 && (*command == '_' || *command == '\\')) { + if (quote != 0 && (*command == '_' || *command == '%' || *command == '\\')) { //DO nothing } else { esc = true; diff --git a/src/util/src/tcompare.c b/src/util/src/tcompare.c index 4bed561f71aef6aafcf4ec2af814c0a2c7e6b63f..23bb73ff860a2b0c4bd5a81005089910faa7792a 100644 --- a/src/util/src/tcompare.c +++ b/src/util/src/tcompare.c @@ -278,6 +278,7 @@ int patternMatch(const char *patterStr, const char *str, size_t size, const SPat if (j <= size) { if (c == '\\' && patterStr[i] == '_' && c1 == '_') { i++; continue; } + if (c == '\\' && patterStr[i] == '%' && c1 == '%') { i++; continue; } if (c == c1 || tolower(c) == tolower(c1) || (c == pInfo->matchOne && c1 != 0)) { continue; } diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c index 31556b83d06224d285db29650eba82c4d3acab5e..c8172fc0aff010332de7d13071a28303f37cf7f5 100644 --- a/src/util/src/tutil.c +++ b/src/util/src/tutil.c @@ -64,7 +64,7 @@ int32_t strRmquote(char *z, int32_t len){ int32_t j = 0; for (uint32_t k = 1; k < len - 1; ++k) { if (z[k] == '\\' || (z[k] == delim && z[k + 1] == delim)) { - if (z[k] == '\\' && z[k + 1] == '_') { + if ((z[k] == '\\' && z[k + 1] == '_') || (z[k] == '\\' && z[k + 1] == '%')) { //match '_' self } else { z[j] = z[k + 1]; diff --git a/tests/script/general/parser/like.sim b/tests/script/general/parser/like.sim index fce996ebee37d887e2f86fc2a8566d844e8d04f5..382240c91141a19e28bc4a25d81cea54737b6a55 100644 --- a/tests/script/general/parser/like.sim +++ b/tests/script/general/parser/like.sim @@ -23,7 +23,7 @@ sql create table $table2 (ts timestamp, b binary(20)) sql insert into $table1 values(now, "table_name") sql insert into $table1 values(now-1m, "tablexname") sql insert into $table1 values(now-2m, "tablexxx") -sql insert into $table1 values(now-2m, "table") +sql insert into $table1 values(now-3m, "table") sql select b from $table1 if $rows != 4 then @@ -56,6 +56,45 @@ if $rows != 1 then return -1 endi +sql create database escape_percentage; +sql use escape_percentage; +$table1 = tablename +$table2 = `table%` + +sql create table $table1 (ts timestamp, b binary(20)) +sql create table $table2 (ts timestamp, b binary(20)) + +sql insert into $table1 values(now, "table%name") +sql insert into $table1 values(now-1m, "table%") +sql insert into $table1 values(now-2m, "table%%%") +sql insert into $table1 values(now-3m, "table") + +sql select b from $table1 where b like 'table\%' +print $rows +if $rows != 1 then + return -1 +endi +sql select b from $table1 where b like 'table\%\%\%' +print $rows +if $rows != 1 then + return -1 +endi +sql select b from $table1 where b like 'table%' +print $rows +if $rows != 4 then + return -1 +endi +sql show tables like 'table\%' +print $rows +if $rows != 1 then + return -1 +endi +sql show tables like 'table%' +print $rows +if $rows != 2 then + return -1 +endi +sql drop database escape_percentage system sh/exec.sh -n dnode1 -s stop -x SIGINT