diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index c2492b2bd06d357e087f4605e49e4976af770211..e671c931590c8cfda84abb6a8fab6cdd3a4db0e5 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -5046,20 +5046,10 @@ static int32_t validateMatchExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_ regex_t regex; char regErrBuf[256] = {0}; - //remove the quote at the begin end of original sql string. - uint32_t lenPattern = pRight->exprToken.n - 2; - char* pattern = malloc(lenPattern + 1); - strncpy(pattern, pRight->exprToken.z+1, lenPattern); - pattern[lenPattern] = '\0'; - - tfree(pRight->value.pz); - pRight->value.pz = pattern; - pRight->value.nLen = lenPattern; - int cflags = REG_EXTENDED; - if ((errCode = regcomp(®ex, pattern, cflags)) != 0) { + if ((errCode = regcomp(®ex, pRight->value.pz, cflags)) != 0) { regerror(errCode, ®ex, regErrBuf, sizeof(regErrBuf)); - tscError("Failed to compile regex pattern %s. reason %s", pattern, regErrBuf); + tscError("Failed to compile regex pattern %s. reason %s", pRight->value.pz, regErrBuf); return invalidOperationMsg(msgBuf, msg3); } regfree(®ex); diff --git a/tests/develop-test/2-query/escape.py b/tests/develop-test/2-query/escape.py index d9995773b850ff17ff390e33dcf15fba180f68e8..ab023a839eaee8217e29c2a488ec7803fb23636f 100644 --- a/tests/develop-test/2-query/escape.py +++ b/tests/develop-test/2-query/escape.py @@ -60,6 +60,10 @@ class TDTestCase: tdSql.query(r'show tables like "zz\\ "') tdSql.checkRows(1) + tdSql.execute(r"insert into `zz\\ ` values(1591060658000, 1)") + tdSql.query(r'select * from `zz\\ `') + tdSql.checkRows(1) + # [TD-11071] tdSql.execute('create table es (ts timestamp, s int) tags(j int)') tdSql.execute(r'create table `zz\t` using es tags(11)') @@ -73,45 +77,87 @@ class TDTestCase: tdSql.checkData(3, 0, r' ') # [TD-6232] - tdSql.execute('create table tt(ts timestamp, i nchar(128))') + tdSql.execute(r'create table tt(ts timestamp, `i\t` nchar(128))') tdSql.execute(r"insert into tt values(1591060628000, '\t')") tdSql.execute(r"insert into tt values(1591060638000, '\n')") tdSql.execute(r"insert into tt values(1591060648000, '\r')") - tdSql.execute(r"insert into tt values(1591060658000, '\\')") + tdSql.execute(r"insert into tt values(1591060658000, '\\t')") tdSql.execute(r"insert into tt values(1591060668000, '\"')") tdSql.execute(r"insert into tt values(1591060678000, '\'')") tdSql.execute(r"insert into tt values(1591060688000, '\%')") + tdSql.execute(r"insert into tt values(1591060688100, '\\%')") + tdSql.execute(r"insert into tt values(1591060688200, '\\\%')") tdSql.execute(r"insert into tt values(1591060698000, '\_')") tdSql.execute(r"insert into tt values(1591060708000, '\9')") - tdSql.query(r"select * from tt where i='\t'") + tdSql.query(r"select * from tt where `i\t`='\t'") tdSql.checkRows(1) - tdSql.query(r"select * from tt where i='\n'") + tdSql.query(r"select * from tt where `i\t`='\n'") tdSql.checkRows(1) - tdSql.query(r"select * from tt where i='\r'") + tdSql.query(r"select * from tt where `i\t`='\r'") tdSql.checkRows(1) - tdSql.query(r"select * from tt where i='\\'") + tdSql.checkData(0, 1, '\r') + tdSql.query(r"select * from tt where `i\t`='\\t'") tdSql.checkRows(1) - tdSql.query(r"select * from tt where i='\"'") + tdSql.checkData(0, 1, r'\t') + tdSql.query(r"select * from tt where `i\t`='\"'") tdSql.checkRows(1) - tdSql.query(r"select * from tt where i='\''") + tdSql.query(r"select * from tt where `i\t`='\''") tdSql.checkRows(1) - tdSql.query(r"select * from tt where i='\%'") + tdSql.query(r"select * from tt where `i\t`='\%'") + tdSql.checkRows(2) + tdSql.checkData(0, 1, r'\%') + tdSql.query(r"select * from tt where `i\t`='\\%'") + tdSql.checkRows(2) + tdSql.checkData(0, 1, r'\%') + tdSql.query(r"select * from tt where `i\t`='\\\%'") tdSql.checkRows(1) - tdSql.query(r"select * from tt where i='\_'") + tdSql.checkData(0, 1, r'\\%') + tdSql.query(r"select * from tt where `i\t`='\_'") tdSql.checkRows(1) - tdSql.query(r"select * from tt where i='\9'") + tdSql.checkData(0, 1, r'\_') + tdSql.query(r"select * from tt where `i\t`='\9'") tdSql.checkRows(1) - tdSql.query(r"select * from tt where i='9'") + tdSql.query(r"select * from tt where `i\t`='9'") tdSql.checkRows(1) + tdSql.execute(r'create table tb(ts timestamp, `i\t` binary(128))') + tdSql.execute(r"insert into tb values(1591060628000, '\t')") + tdSql.query(r"select * from tb where `i\t`='\t'") + tdSql.checkRows(1) + tdSql.execute(r"insert into tb values(1591060629000, '\\%')") + tdSql.query(r"select * from tb where `i\t`='\%'") + tdSql.checkRows(1) + tdSql.checkData(0, 1, r'\%') + # [TD-12815] like wildcard(%, _) are not supported nchar tdSql.execute(r"insert into tt values(1591070708000, 'h%d')") tdSql.execute(r"insert into tt values(1591080708000, 'h_j')") - tdSql.query(r"select * from tt where i like 'h\%d'") + tdSql.execute(r"insert into tt values(1591090708000, 'h\\j')") + tdSql.query(r"select * from tt where `i\t` like 'h\%d'") + tdSql.checkRows(1) + tdSql.query(r"select * from tt where `i\t` like 'h\_j'") + tdSql.checkRows(1) + tdSql.query(r"select * from tt where `i\t` like 'h\\j'") tdSql.checkRows(1) - tdSql.query(r"select * from tt where i like 'h\_j'") + tdSql.query(r"select * from tt where `i\t` match 'h\\\\j'") tdSql.checkRows(1) + + # normal test + tdSql.error(r"select * from tt where i\t='\t'") + tdSql.error(r"select * from zz\t where s=1") + tdSql.error(r"select i\t from tt where `i\t`='\t'") + + tdSql.execute(r'create table `\n`(ts timestamp, `i\"` nchar(128))') + tdSql.execute(r"insert into `\n` values(1591060708000, 'js')") + tdSql.query(r"select `i\"` from `\n` where `i\"`='js'") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 'js') + + tdSql.query(r'show tables like "\\n"') + tdSql.checkRows(1) + tdSql.checkData(0, 0, r"\n") + def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) diff --git a/tests/pytest/query/queryRegex.py b/tests/pytest/query/queryRegex.py index 9edc1db60d5b406b765108bb4ed96c4cda017664..977155bfe48762f52955e488ef9938e266e38ceb 100644 --- a/tests/pytest/query/queryRegex.py +++ b/tests/pytest/query/queryRegex.py @@ -92,10 +92,10 @@ class TDTestCase: tdSql.error('select * from stb_test where c0 nmatch abc') - tdSql.query("select * from stb_1 where c0 match '\\\\'") + tdSql.query(r"select * from stb_1 where c0 match '\\\\'") tdSql.checkRows(1) - tdSql.query("select * from stb_1 where c0 nmatch '\\\\'") + tdSql.query(r"select * from stb_1 where c0 nmatch '\\\\'") tdSql.checkRows(3) #2021-10-20 for https://jira.taosdata.com:18080/browse/TD-10708