未验证 提交 ed834ce8 编写于 作者: D dapan1121 提交者: GitHub

Merge pull request #9746 from taosdata/feature/TD-12252-new

[TD-12252]<feature>(connector,query,insert,other,tools,taosAdapter):d…
...@@ -5046,20 +5046,10 @@ static int32_t validateMatchExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_ ...@@ -5046,20 +5046,10 @@ static int32_t validateMatchExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_
regex_t regex; regex_t regex;
char regErrBuf[256] = {0}; 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; int cflags = REG_EXTENDED;
if ((errCode = regcomp(&regex, pattern, cflags)) != 0) { if ((errCode = regcomp(&regex, pRight->value.pz, cflags)) != 0) {
regerror(errCode, &regex, regErrBuf, sizeof(regErrBuf)); regerror(errCode, &regex, 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); return invalidOperationMsg(msgBuf, msg3);
} }
regfree(&regex); regfree(&regex);
......
...@@ -60,6 +60,10 @@ class TDTestCase: ...@@ -60,6 +60,10 @@ class TDTestCase:
tdSql.query(r'show tables like "zz\\ "') tdSql.query(r'show tables like "zz\\ "')
tdSql.checkRows(1) tdSql.checkRows(1)
tdSql.execute(r"insert into `zz\\ ` values(1591060658000, 1)")
tdSql.query(r'select * from `zz\\ `')
tdSql.checkRows(1)
# [TD-11071] # [TD-11071]
tdSql.execute('create table es (ts timestamp, s int) tags(j int)') tdSql.execute('create table es (ts timestamp, s int) tags(j int)')
tdSql.execute(r'create table `zz\t` using es tags(11)') tdSql.execute(r'create table `zz\t` using es tags(11)')
...@@ -73,45 +77,87 @@ class TDTestCase: ...@@ -73,45 +77,87 @@ class TDTestCase:
tdSql.checkData(3, 0, r' ') tdSql.checkData(3, 0, r' ')
# [TD-6232] # [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(1591060628000, '\t')")
tdSql.execute(r"insert into tt values(1591060638000, '\n')") 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(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(1591060668000, '\"')")
tdSql.execute(r"insert into tt values(1591060678000, '\'')") tdSql.execute(r"insert into tt values(1591060678000, '\'')")
tdSql.execute(r"insert into tt values(1591060688000, '\%')") 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(1591060698000, '\_')")
tdSql.execute(r"insert into tt values(1591060708000, '\9')") 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.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.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.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.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.checkRows(1)
tdSql.query(r"select * from tt where i='\''") tdSql.query(r"select * from tt where `i\t`='\''")
tdSql.checkRows(1) 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.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.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.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.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 # [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(1591070708000, 'h%d')")
tdSql.execute(r"insert into tt values(1591080708000, 'h_j')") 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.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) 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): def stop(self):
tdSql.close() tdSql.close()
tdLog.success("%s successfully executed" % __file__) tdLog.success("%s successfully executed" % __file__)
......
...@@ -92,10 +92,10 @@ class TDTestCase: ...@@ -92,10 +92,10 @@ class TDTestCase:
tdSql.error('select * from stb_test where c0 nmatch abc') 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.checkRows(1)
tdSql.query("select * from stb_1 where c0 nmatch '\\\\'") tdSql.query(r"select * from stb_1 where c0 nmatch '\\\\'")
tdSql.checkRows(3) tdSql.checkRows(3)
#2021-10-20 for https://jira.taosdata.com:18080/browse/TD-10708 #2021-10-20 for https://jira.taosdata.com:18080/browse/TD-10708
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册