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

Merge pull request #9747 from taosdata/feature/TD-12252-2.4

[TD-12252]<feature>(connector,query,insert,other,tools,taosAdapter):d…
......@@ -5052,20 +5052,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(&regex, pattern, cflags)) != 0) {
if ((errCode = regcomp(&regex, pRight->value.pz, cflags)) != 0) {
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);
}
regfree(&regex);
......
......@@ -23,7 +23,6 @@ class TDTestCase:
case1: [TD-12251] json type containing single quotes cannot be inserted
case2: [TD-12334] '\' escape unknown
case3: [TD-11071] escape table creation problem
case4: [TD-6232] fix abnormal escaping results about '\'
case5: [TD-12815] like wildcards (% _) are not supported nchar type
'''
return
......@@ -61,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)')
......@@ -74,49 +77,91 @@ 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__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
\ No newline at end of file
tdCases.addLinux(__file__, TDTestCase())
......@@ -32,7 +32,7 @@ class TDTestCase:
tb_str = ""
for tbname in tbname_list:
globals()[tbname] = tdCom.getLongName(8, "letters_mixed")
globals()[tbname] = tdCom.getLongName(8, "letters_mixed").upper()
tdSql.execute(f'CREATE TABLE {table_name} (ts timestamp, {table_name_sub1} tinyint, \
{table_name_sub2} smallint, {table_name_sub3} int, {table_name_sub4} bigint, \
{table_name_sub5} float, {table_name_sub6} double, {table_name_sub7} binary(20),\
......@@ -44,7 +44,7 @@ class TDTestCase:
for i in range(10):
for tbname in tbname_list:
tdSql.execute(f'insert into {globals()[tbname]} values (now, 1, 2, 3, 4, 1.1, 2.2, "{globals()[tbname]}", "{globals()[tbname]}", True)')
tdSql.execute(f'insert into {globals()[tbname]} values (now-{i*i}s, 1, 2, 3, 4, 1.1, 2.2, "{globals()[tbname]}", "{globals()[tbname]}", True)')
for i in range(100):
tdSql.query(f'select {table_name_sub1},{table_name_sub2},{table_name_sub3},{table_name_sub4},{table_name_sub5},{table_name_sub6},{table_name_sub7},{table_name_sub8},{table_name_sub9} from {table_name} where tbname in ("{table_name_sub1}","{table_name_sub2}","{table_name_sub3}","{table_name_sub4}","{table_name_sub5}","{table_name_sub6}","{table_name_sub7}","{table_name_sub8}","{table_name_sub9}") and ts >= "1980-01-01 00:00:00.000"')
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册