Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
068938fb
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
068938fb
编写于
10月 12, 2021
作者:
D
dapan1121
提交者:
GitHub
10月 12, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #8084 from taosdata/feature/TD-10396
Feature/td 10396
上级
3c408c72
964d1ea6
变更
31
展开全部
隐藏空白更改
内联
并排
Showing
31 changed file
with
1035 addition
and
627 deletion
+1035
-627
src/client/inc/tscUtil.h
src/client/inc/tscUtil.h
+2
-2
src/client/src/tscLocal.c
src/client/src/tscLocal.c
+8
-6
src/client/src/tscParseInsert.c
src/client/src/tscParseInsert.c
+37
-16
src/client/src/tscParseLineProtocol.c
src/client/src/tscParseLineProtocol.c
+4
-2
src/client/src/tscParseOpenTSDB.c
src/client/src/tscParseOpenTSDB.c
+1
-13
src/client/src/tscPrepare.c
src/client/src/tscPrepare.c
+24
-8
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+101
-38
src/client/src/tscServer.c
src/client/src/tscServer.c
+3
-3
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+98
-18
src/common/inc/tname.h
src/common/inc/tname.h
+4
-0
src/common/src/tname.c
src/common/src/tname.c
+67
-5
src/common/src/tvariant.c
src/common/src/tvariant.c
+1
-1
src/inc/taosdef.h
src/inc/taosdef.h
+1
-0
src/inc/ttokendef.h
src/inc/ttokendef.h
+2
-0
src/kit/shell/src/shellEngine.c
src/kit/shell/src/shellEngine.c
+6
-5
src/mnode/src/mnodeTable.c
src/mnode/src/mnodeTable.c
+1
-1
src/query/inc/sql.y
src/query/inc/sql.y
+2
-1
src/query/src/qFilter.c
src/query/src/qFilter.c
+1
-4
src/query/src/sql.c
src/query/src/sql.c
+1
-472
src/query/tests/unitTest.cpp
src/query/tests/unitTest.cpp
+1
-1
src/util/inc/tutil.h
src/util/inc/tutil.h
+2
-0
src/util/src/ttokenizer.c
src/util/src/ttokenizer.c
+12
-1
src/util/src/tutil.c
src/util/src/tutil.c
+59
-2
tests/pytest/client/twoClients.py
tests/pytest/client/twoClients.py
+3
-3
tests/pytest/insert/insertJSONPayload.py
tests/pytest/insert/insertJSONPayload.py
+2
-2
tests/pytest/insert/insertTelnetLines.py
tests/pytest/insert/insertTelnetLines.py
+2
-2
tests/pytest/query/queryTbnameUpperLower.py
tests/pytest/query/queryTbnameUpperLower.py
+6
-6
tests/pytest/table/create.py
tests/pytest/table/create.py
+291
-1
tests/script/fullGeneralSuite.sim
tests/script/fullGeneralSuite.sim
+1
-0
tests/script/general/parser/tbnameIn_query.sim
tests/script/general/parser/tbnameIn_query.sim
+2
-14
tests/script/general/parser/tbname_escape.sim
tests/script/general/parser/tbname_escape.sim
+290
-0
未找到文件。
src/client/inc/tscUtil.h
浏览文件 @
068938fb
...
...
@@ -180,7 +180,7 @@ bool tscQueryBlockInfo(SQueryInfo* pQueryInfo);
SExprInfo
*
tscAddFuncInSelectClause
(
SQueryInfo
*
pQueryInfo
,
int32_t
outputColIndex
,
int16_t
functionId
,
SColumnIndex
*
pIndex
,
SSchema
*
pColSchema
,
int16_t
colType
,
int16_t
colId
);
int32_t
tscSetTableFullName
(
SName
*
pName
,
SStrToken
*
pzTableName
,
SSqlObj
*
pSql
);
int32_t
tscSetTableFullName
(
SName
*
pName
,
SStrToken
*
pzTableName
,
SSqlObj
*
pSql
,
bool
dbIncluded
);
void
tscClearInterpInfo
(
SQueryInfo
*
pQueryInfo
);
bool
tscIsInsertData
(
char
*
sqlstr
);
...
...
@@ -251,7 +251,7 @@ void tscColumnListCopyAll(SArray* dst, const SArray* src);
void
convertQueryResult
(
SSqlRes
*
pRes
,
SQueryInfo
*
pQueryInfo
,
uint64_t
objId
,
bool
convertNchar
);
void
tscDequoteAndTrimToken
(
SStrToken
*
pToken
);
int32_t
tscValidateName
(
SStrToken
*
pToken
);
int32_t
tscValidateName
(
SStrToken
*
pToken
,
bool
escapeEnabled
,
bool
*
dbIncluded
);
void
tscIncStreamExecutionCount
(
void
*
pStream
);
...
...
src/client/src/tscLocal.c
浏览文件 @
068938fb
...
...
@@ -398,7 +398,7 @@ static int32_t tscSCreateBuildResultFields(SSqlObj *pSql, BuildType type, const
TAOS_FIELD
f
;
if
(
type
==
SCREATE_BUILD_TABLE
)
{
f
.
type
=
TSDB_DATA_TYPE_BINARY
;
f
.
bytes
=
(
TSDB_
COL
_NAME_LEN
-
1
)
+
VARSTR_HEADER_SIZE
;
f
.
bytes
=
(
TSDB_
TABLE
_NAME_LEN
-
1
)
+
VARSTR_HEADER_SIZE
;
tstrncpy
(
f
.
name
,
"Table"
,
sizeof
(
f
.
name
));
}
else
{
f
.
type
=
TSDB_DATA_TYPE_BINARY
;
...
...
@@ -465,7 +465,7 @@ int32_t tscRebuildCreateTableStatement(void *param,char *result) {
code
=
tscGetTableTagValue
(
builder
,
buf
);
if
(
code
==
TSDB_CODE_SUCCESS
)
{
snprintf
(
result
+
strlen
(
result
),
TSDB_MAX_BINARY_LEN
-
strlen
(
result
),
"CREATE TABLE
%s USING %s
TAGS %s"
,
builder
->
buf
,
builder
->
sTableName
,
buf
);
snprintf
(
result
+
strlen
(
result
),
TSDB_MAX_BINARY_LEN
-
strlen
(
result
),
"CREATE TABLE
`%s` USING `%s`
TAGS %s"
,
builder
->
buf
,
builder
->
sTableName
,
buf
);
code
=
tscSCreateBuildResult
(
builder
->
pParentSql
,
SCREATE_BUILD_TABLE
,
builder
->
buf
,
result
);
}
free
(
buf
);
...
...
@@ -574,12 +574,14 @@ static int32_t tscRebuildDDLForSubTable(SSqlObj *pSql, const char *tableName, ch
}
char
fullName
[
TSDB_TABLE_FNAME_LEN
*
2
]
=
{
0
};
char
tblName
[
TSDB_TABLE_NAME_LEN
+
1
]
=
{
0
};
tNameGetDbName
(
&
pTableMetaInfo
->
name
,
fullName
);
extractTableName
(
pMeta
->
sTableName
,
param
->
sTableName
);
snprintf
(
fullName
+
strlen
(
fullName
),
TSDB_TABLE_FNAME_LEN
-
strlen
(
fullName
),
".
%s
"
,
param
->
sTableName
);
snprintf
(
fullName
+
strlen
(
fullName
),
TSDB_TABLE_FNAME_LEN
-
strlen
(
fullName
),
".
`%s`
"
,
param
->
sTableName
);
strncpy
(
param
->
buf
,
tNameGetTableName
(
&
pTableMetaInfo
->
name
),
TSDB_TABLE_NAME_LEN
);
tableNameToStr
(
tblName
,
param
->
buf
,
'\''
);
param
->
pParentSql
=
pSql
;
param
->
pInterSql
=
pInterSql
;
...
...
@@ -602,7 +604,7 @@ static int32_t tscRebuildDDLForSubTable(SSqlObj *pSql, const char *tableName, ch
return
code
;
}
snprintf
(
query
+
strlen
(
query
),
TSDB_MAX_BINARY_LEN
-
strlen
(
query
),
"SELECT %s FROM %s WHERE TBNAME IN(
\'
%s
\'
)"
,
columns
,
fullName
,
param
->
buf
);
snprintf
(
query
+
strlen
(
query
),
TSDB_MAX_BINARY_LEN
-
strlen
(
query
),
"SELECT %s FROM %s WHERE TBNAME IN(
\'
%s
\'
)"
,
columns
,
fullName
,
tblName
);
doAsyncQuery
(
pSql
->
pTscObj
,
pInterSql
,
tscSCreateCallBack
,
param
,
query
,
strlen
(
query
));
free
(
query
);
free
(
columns
);
...
...
@@ -619,7 +621,7 @@ static int32_t tscRebuildDDLForNormalTable(SSqlObj *pSql, const char *tableName,
SSchema
*
pSchema
=
tscGetTableSchema
(
pMeta
);
char
*
result
=
ddl
;
sprintf
(
result
,
"create table
%s
("
,
tableName
);
sprintf
(
result
,
"create table
`%s`
("
,
tableName
);
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
uint8_t
type
=
pSchema
[
i
].
type
;
if
(
type
==
TSDB_DATA_TYPE_BINARY
||
type
==
TSDB_DATA_TYPE_NCHAR
)
{
...
...
@@ -646,7 +648,7 @@ static int32_t tscRebuildDDLForSuperTable(SSqlObj *pSql, const char *tableName,
int32_t
totalRows
=
numOfRows
+
tscGetNumOfTags
(
pMeta
);
SSchema
*
pSchema
=
tscGetTableSchema
(
pMeta
);
sprintf
(
result
,
"create table
%s
("
,
tableName
);
sprintf
(
result
,
"create table
`%s`
("
,
tableName
);
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
uint8_t
type
=
pSchema
[
i
].
type
;
if
(
type
==
TSDB_DATA_TYPE_BINARY
||
type
==
TSDB_DATA_TYPE_NCHAR
)
{
...
...
src/client/src/tscParseInsert.c
浏览文件 @
068938fb
...
...
@@ -906,6 +906,18 @@ static int32_t doParseInsertStatement(SInsertStatementParam *pInsertParam, char
return
TSDB_CODE_SUCCESS
;
}
int
validateTableName
(
char
*
tblName
,
int
len
,
SStrToken
*
psTblToken
,
bool
*
dbIncluded
)
{
tstrncpy
(
psTblToken
->
z
,
tblName
,
TSDB_TABLE_FNAME_LEN
);
psTblToken
->
n
=
len
;
psTblToken
->
type
=
TK_ID
;
tGetToken
(
psTblToken
->
z
,
&
psTblToken
->
type
);
return
tscValidateName
(
psTblToken
,
true
,
dbIncluded
);
}
static
int32_t
tscCheckIfCreateTable
(
char
**
sqlstr
,
SSqlObj
*
pSql
,
char
**
boundColumn
)
{
int32_t
index
=
0
;
SStrToken
sToken
=
{
0
};
...
...
@@ -968,13 +980,27 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC
sToken
=
tStrGetToken
(
sql
,
&
index
,
false
);
sql
+=
index
;
if
(
sToken
.
type
==
TK_ILLEGAL
)
{
return
tscSQLSyntaxErrMsg
(
pCmd
->
payload
,
NULL
,
sql
);
}
//the source super table is moved to the secondary position of the pTableMetaInfo list
if
(
pQueryInfo
->
numOfTables
<
2
)
{
tscAddEmptyMetaInfo
(
pQueryInfo
);
}
bool
dbIncluded1
=
false
;
char
buf
[
TSDB_TABLE_FNAME_LEN
];
SStrToken
sTblToken
;
sTblToken
.
z
=
buf
;
code
=
validateTableName
(
sToken
.
z
,
sToken
.
n
,
&
sTblToken
,
&
dbIncluded1
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
STableMetaInfo
*
pSTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
STABLE_INDEX
);
code
=
tscSetTableFullName
(
&
pSTableMetaInfo
->
name
,
&
sT
oken
,
pSql
);
code
=
tscSetTableFullName
(
&
pSTableMetaInfo
->
name
,
&
sT
blToken
,
pSql
,
dbIncluded1
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
...
...
@@ -988,7 +1014,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC
}
if
(
!
UTIL_TABLE_IS_SUPER_TABLE
(
pSTableMetaInfo
))
{
return
tscInvalidOperationMsg
(
pInsertParam
->
msg
,
"create table only from super table is allowed"
,
sToken
.
z
);
return
tscInvalidOperationMsg
(
pInsertParam
->
msg
,
"create table only from super table is allowed"
,
sT
blT
oken
.
z
);
}
SSchema
*
pTagSchema
=
tscGetTableTagSchema
(
pSTableMetaInfo
->
pTableMeta
);
...
...
@@ -1144,12 +1170,16 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC
}
sql
=
sToken
.
z
;
bool
dbIncluded2
=
false
;
if
(
tscValidateName
(
&
tableToken
)
!=
TSDB_CODE_SUCCESS
)
{
sTblToken
.
z
=
buf
;
code
=
validateTableName
(
tableToken
.
z
,
tableToken
.
n
,
&
sTblToken
,
&
dbIncluded2
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
tscInvalidOperationMsg
(
pInsertParam
->
msg
,
"invalid table name"
,
*
sqlstr
);
}
int32_t
ret
=
tscSetTableFullName
(
&
pTableMetaInfo
->
name
,
&
tableToken
,
pSql
);
int32_t
ret
=
tscSetTableFullName
(
&
pTableMetaInfo
->
name
,
&
sTblToken
,
pSql
,
dbIncluded2
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
...
...
@@ -1179,16 +1209,6 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC
return
code
;
}
int
validateTableName
(
char
*
tblName
,
int
len
,
SStrToken
*
psTblToken
)
{
tstrncpy
(
psTblToken
->
z
,
tblName
,
TSDB_TABLE_FNAME_LEN
);
psTblToken
->
n
=
len
;
psTblToken
->
type
=
TK_ID
;
tGetToken
(
psTblToken
->
z
,
&
psTblToken
->
type
);
return
tscValidateName
(
psTblToken
);
}
static
int32_t
validateDataSource
(
SInsertStatementParam
*
pInsertParam
,
int32_t
type
,
const
char
*
sql
)
{
uint32_t
*
insertType
=
&
pInsertParam
->
insertType
;
if
(
*
insertType
==
TSDB_QUERY_TYPE_STMT_INSERT
&&
type
==
TSDB_QUERY_TYPE_INSERT
)
{
...
...
@@ -1409,13 +1429,14 @@ int tsParseInsertSql(SSqlObj *pSql) {
char
buf
[
TSDB_TABLE_FNAME_LEN
];
SStrToken
sTblToken
;
sTblToken
.
z
=
buf
;
bool
dbIncluded
=
false
;
// Check if the table name available or not
if
(
validateTableName
(
sToken
.
z
,
sToken
.
n
,
&
sTblToken
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
validateTableName
(
sToken
.
z
,
sToken
.
n
,
&
sTblToken
,
&
dbIncluded
)
!=
TSDB_CODE_SUCCESS
)
{
code
=
tscInvalidOperationMsg
(
pInsertParam
->
msg
,
"table name invalid"
,
sToken
.
z
);
goto
_clean
;
}
if
((
code
=
tscSetTableFullName
(
&
pTableMetaInfo
->
name
,
&
sTblToken
,
pSql
))
!=
TSDB_CODE_SUCCESS
)
{
if
((
code
=
tscSetTableFullName
(
&
pTableMetaInfo
->
name
,
&
sTblToken
,
pSql
,
dbIncluded
))
!=
TSDB_CODE_SUCCESS
)
{
goto
_clean
;
}
...
...
src/client/src/tscParseLineProtocol.c
浏览文件 @
068938fb
...
...
@@ -558,8 +558,10 @@ static int32_t retrieveTableMeta(TAOS* taos, char* tableName, STableMeta** pTabl
registerSqlObj
(
pSql
);
SStrToken
tableToken
=
{.
z
=
tableNameLowerCase
,
.
n
=
(
uint32_t
)
strlen
(
tableNameLowerCase
),
.
type
=
TK_ID
};
tGetToken
(
tableNameLowerCase
,
&
tableToken
.
type
);
bool
dbIncluded
=
false
;
// Check if the table name available or not
if
(
tscValidateName
(
&
tableToken
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscValidateName
(
&
tableToken
,
true
,
&
dbIncluded
)
!=
TSDB_CODE_SUCCESS
)
{
code
=
TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH
;
sprintf
(
pSql
->
cmd
.
payload
,
"table name is invalid"
);
tscFreeRegisteredSqlObj
(
pSql
);
...
...
@@ -567,7 +569,7 @@ static int32_t retrieveTableMeta(TAOS* taos, char* tableName, STableMeta** pTabl
}
SName
sname
=
{
0
};
if
((
code
=
tscSetTableFullName
(
&
sname
,
&
tableToken
,
pSql
))
!=
TSDB_CODE_SUCCESS
)
{
if
((
code
=
tscSetTableFullName
(
&
sname
,
&
tableToken
,
pSql
,
dbIncluded
))
!=
TSDB_CODE_SUCCESS
)
{
tscFreeRegisteredSqlObj
(
pSql
);
return
code
;
}
...
...
src/client/src/tscParseOpenTSDB.c
浏览文件 @
068938fb
...
...
@@ -58,12 +58,7 @@ static int32_t parseTelnetMetric(TAOS_SML_DATA_POINT *pSml, const char **index,
break
;
}
//convert dot to underscore for now, will be removed once dot is allowed in tbname.
if
(
*
cur
==
'.'
)
{
pSml
->
stableName
[
len
]
=
'_'
;
}
else
{
pSml
->
stableName
[
len
]
=
tolower
(
*
cur
);
}
pSml
->
stableName
[
len
]
=
*
cur
;
cur
++
;
len
++
;
...
...
@@ -462,13 +457,6 @@ static int32_t parseMetricFromJSON(cJSON *root, TAOS_SML_DATA_POINT* pSml, SSmlL
return
TSDB_CODE_TSC_INVALID_JSON
;
}
//convert dot to underscore for now, will be removed once dot is allowed in tbname.
for
(
int
i
=
0
;
i
<
stableLen
;
++
i
)
{
if
(
metric
->
valuestring
[
i
]
==
'.'
)
{
metric
->
valuestring
[
i
]
=
'_'
;
}
}
tstrncpy
(
pSml
->
stableName
,
metric
->
valuestring
,
stableLen
+
1
);
strntolower_s
(
pSml
->
stableName
,
pSml
->
stableName
,
(
int32_t
)
stableLen
);
...
...
src/client/src/tscPrepare.c
浏览文件 @
068938fb
...
...
@@ -1585,9 +1585,10 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags
SSqlObj
*
pSql
=
pStmt
->
pSql
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
uint32_t
nameLen
=
(
uint32_t
)
strlen
(
name
);
if
(
name
==
NULL
)
{
tscError
(
"0x%"
PRIx64
" name is NULL"
,
pSql
->
self
);
if
(
name
==
NULL
||
nameLen
<=
0
)
{
tscError
(
"0x%"
PRIx64
"
tb
name is NULL"
,
pSql
->
self
);
STMT_RET
(
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"name is NULL"
));
}
...
...
@@ -1603,6 +1604,20 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags
pStmt
->
last
=
STMT_SETTBNAME
;
SStrToken
tname
=
{
0
};
tname
.
type
=
TK_STRING
;
tname
.
z
=
(
char
*
)
strdup
(
name
);
tname
.
n
=
(
uint32_t
)
strlen
(
name
);
bool
dbIncluded
=
false
;
// Check if the table name available or not
if
(
tscValidateName
(
&
tname
,
true
,
&
dbIncluded
)
!=
TSDB_CODE_SUCCESS
)
{
tscError
(
"0x%"
PRIx64
" tbname[%s] is invalid"
,
pSql
->
self
,
name
);
free
(
tname
.
z
);
STMT_RET
(
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"name is invalid"
));
}
uint64_t
*
uid
=
(
uint64_t
*
)
taosHashGet
(
pStmt
->
mtb
.
pTableHash
,
name
,
strlen
(
name
));
if
(
uid
!=
NULL
)
{
pStmt
->
mtb
.
currentUid
=
*
uid
;
...
...
@@ -1610,6 +1625,7 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags
STableDataBlocks
**
t1
=
(
STableDataBlocks
**
)
taosHashGet
(
pStmt
->
mtb
.
pTableBlockHashList
,
(
const
char
*
)
&
pStmt
->
mtb
.
currentUid
,
sizeof
(
pStmt
->
mtb
.
currentUid
));
if
(
t1
==
NULL
)
{
tscError
(
"0x%"
PRIx64
" no table data block in hash list, uid:%"
PRId64
,
pSql
->
self
,
pStmt
->
mtb
.
currentUid
);
free
(
tname
.
z
);
STMT_RET
(
TSDB_CODE_TSC_APP_ERROR
);
}
...
...
@@ -1624,6 +1640,7 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags
taosHashPut
(
pCmd
->
insertParam
.
pTableBlockHashList
,
(
void
*
)
&
pStmt
->
mtb
.
currentUid
,
sizeof
(
pStmt
->
mtb
.
currentUid
),
(
void
*
)
t1
,
POINTER_BYTES
);
tscDebug
(
"0x%"
PRIx64
" table:%s is already prepared, uid:%"
PRIu64
,
pSql
->
self
,
name
,
pStmt
->
mtb
.
currentUid
);
free
(
tname
.
z
);
STMT_RET
(
TSDB_CODE_SUCCESS
);
}
...
...
@@ -1632,13 +1649,10 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
char
sTableName
[
TSDB_TABLE_FNAME_LEN
]
=
{
0
};
tstrncpy
(
sTableName
,
pTableMeta
->
sTableName
,
sizeof
(
sTableName
));
SStrToken
tname
=
{
0
};
tname
.
type
=
TK_STRING
;
tname
.
z
=
(
char
*
)
name
;
tname
.
n
=
(
uint32_t
)
strlen
(
name
);
SName
fullname
=
{
0
};
tscSetTableFullName
(
&
fullname
,
&
tname
,
pSql
);
tscSetTableFullName
(
&
fullname
,
&
tname
,
pSql
,
dbIncluded
);
free
(
tname
.
z
);
memcpy
(
&
pTableMetaInfo
->
name
,
&
fullname
,
sizeof
(
fullname
));
...
...
@@ -1672,6 +1686,8 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags
STMT_RET
(
TSDB_CODE_SUCCESS
);
}
free
(
tname
.
z
);
if
(
pStmt
->
mtb
.
tagSet
)
{
pStmt
->
mtb
.
tbname
=
tscReplaceStrToken
(
&
pSql
->
sqlstr
,
&
pStmt
->
mtb
.
tbname
,
name
);
}
else
{
...
...
src/client/src/tscSQLParser.c
浏览文件 @
068938fb
...
...
@@ -142,6 +142,8 @@ static int32_t checkQueryRangeForFill(SSqlCmd* pCmd, SQueryInfo* pQueryInfo);
static
int32_t
loadAllTableMeta
(
SSqlObj
*
pSql
,
struct
SSqlInfo
*
pInfo
);
static
tSqlExpr
*
extractExprForSTable
(
SSqlCmd
*
pCmd
,
tSqlExpr
**
pExpr
,
SQueryInfo
*
pQueryInfo
,
int32_t
tableIndex
);
int
validateTableName
(
char
*
tblName
,
int
len
,
SStrToken
*
psTblToken
,
bool
*
dbIncluded
);
static
bool
isTimeWindowQuery
(
SQueryInfo
*
pQueryInfo
)
{
return
pQueryInfo
->
interval
.
interval
>
0
||
pQueryInfo
->
sessionWindow
.
gap
>
0
;
}
...
...
@@ -567,8 +569,18 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
const
char
*
msg3
=
"param name too long"
;
SStrToken
*
pzName
=
taosArrayGet
(
pInfo
->
pMiscInfo
->
a
,
0
);
if
((
pInfo
->
type
!=
TSDB_SQL_DROP_DNODE
)
&&
(
tscValidateName
(
pzName
)
!=
TSDB_CODE_SUCCESS
))
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
bool
escapeEnabled
=
(
pInfo
->
type
==
TSDB_SQL_DROP_TABLE
)
?
true
:
false
;
bool
dbIncluded
=
false
;
char
buf
[
TSDB_TABLE_FNAME_LEN
];
SStrToken
sTblToken
;
sTblToken
.
z
=
buf
;
if
(
pInfo
->
type
!=
TSDB_SQL_DROP_DNODE
)
{
if
((
escapeEnabled
&&
(
validateTableName
(
pzName
->
z
,
pzName
->
n
,
&
sTblToken
,
&
dbIncluded
)
!=
TSDB_CODE_SUCCESS
))
||
((
!
escapeEnabled
)
&&
(
tscValidateName
(
pzName
,
escapeEnabled
,
&
dbIncluded
)
!=
TSDB_CODE_SUCCESS
))){
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
}
if
(
pInfo
->
type
==
TSDB_SQL_DROP_DB
)
{
...
...
@@ -581,7 +593,7 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
}
else
if
(
pInfo
->
type
==
TSDB_SQL_DROP_TABLE
)
{
assert
(
taosArrayGetSize
(
pInfo
->
pMiscInfo
->
a
)
==
1
);
code
=
tscSetTableFullName
(
&
pTableMetaInfo
->
name
,
pzName
,
pSql
);
code
=
tscSetTableFullName
(
&
pTableMetaInfo
->
name
,
&
sTblToken
,
pSql
,
dbIncluded
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
...
...
@@ -605,7 +617,7 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
const
char
*
msg
=
"invalid db name"
;
SStrToken
*
pToken
=
taosArrayGet
(
pInfo
->
pMiscInfo
->
a
,
0
);
if
(
tscValidateName
(
pToken
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscValidateName
(
pToken
,
false
,
NULL
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg
);
}
...
...
@@ -652,7 +664,7 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
char
buf
[
TSDB_DB_NAME_LEN
]
=
{
0
};
SStrToken
token
=
taosTokenDup
(
&
pCreateDB
->
dbname
,
buf
,
tListLen
(
buf
));
if
(
tscValidateName
(
&
token
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscValidateName
(
&
token
,
false
,
NULL
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
...
...
@@ -699,7 +711,7 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
if
(
tscValidateName
(
pName
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscValidateName
(
pName
,
false
,
NULL
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
...
...
@@ -721,11 +733,17 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
const
char
*
msg1
=
"invalid table name"
;
SStrToken
*
pToken
=
taosArrayGet
(
pInfo
->
pMiscInfo
->
a
,
0
);
if
(
tscValidateName
(
pToken
)
!=
TSDB_CODE_SUCCESS
)
{
bool
dbIncluded
=
false
;
char
buf
[
TSDB_TABLE_FNAME_LEN
];
SStrToken
sTblToken
;
sTblToken
.
z
=
buf
;
if
(
validateTableName
(
pToken
->
z
,
pToken
->
n
,
&
sTblToken
,
&
dbIncluded
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
// additional msg has been attached already
code
=
tscSetTableFullName
(
&
pTableMetaInfo
->
name
,
pToken
,
pSql
);
code
=
tscSetTableFullName
(
&
pTableMetaInfo
->
name
,
&
sTblToken
,
pSql
,
dbIncluded
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
...
...
@@ -737,11 +755,17 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
const
char
*
msg1
=
"invalid table name"
;
SStrToken
*
pToken
=
taosArrayGet
(
pInfo
->
pMiscInfo
->
a
,
0
);
if
(
tscValidateName
(
pToken
)
!=
TSDB_CODE_SUCCESS
)
{
bool
dbIncluded
=
false
;
char
buf
[
TSDB_TABLE_FNAME_LEN
];
SStrToken
sTblToken
;
sTblToken
.
z
=
buf
;
if
(
validateTableName
(
pToken
->
z
,
pToken
->
n
,
&
sTblToken
,
&
dbIncluded
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
code
=
tscSetTableFullName
(
&
pTableMetaInfo
->
name
,
pToken
,
pSql
);
code
=
tscSetTableFullName
(
&
pTableMetaInfo
->
name
,
&
sTblToken
,
pSql
,
dbIncluded
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
...
...
@@ -752,7 +776,8 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
const
char
*
msg1
=
"invalid database name"
;
SStrToken
*
pToken
=
taosArrayGet
(
pInfo
->
pMiscInfo
->
a
,
0
);
if
(
tscValidateName
(
pToken
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscValidateName
(
pToken
,
false
,
NULL
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
...
...
@@ -816,7 +841,7 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
if
(
tscValidateName
(
pName
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscValidateName
(
pName
,
false
,
NULL
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
...
...
@@ -1336,7 +1361,7 @@ int32_t parseSlidingClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SStrToken* pSl
return
TSDB_CODE_SUCCESS
;
}
int32_t
tscSetTableFullName
(
SName
*
pName
,
SStrToken
*
pTableName
,
SSqlObj
*
pSql
)
{
int32_t
tscSetTableFullName
(
SName
*
pName
,
SStrToken
*
pTableName
,
SSqlObj
*
pSql
,
bool
dbIncluded
)
{
const
char
*
msg1
=
"name too long"
;
const
char
*
msg2
=
"acctId too long"
;
const
char
*
msg3
=
"no acctId"
;
...
...
@@ -1345,7 +1370,12 @@ int32_t tscSetTableFullName(SName* pName, SStrToken* pTableName, SSqlObj* pSql)
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
idx
=
getDelimiterIndex
(
pTableName
);
int32_t
idx
=
-
1
;
if
(
dbIncluded
)
{
idx
=
getDelimiterIndex
(
pTableName
);
}
if
(
idx
!=
-
1
)
{
// db has been specified in sql string so we ignore current db path
char
*
acctId
=
getAccountId
(
pSql
);
if
(
acctId
==
NULL
||
strlen
(
acctId
)
<=
0
)
{
...
...
@@ -3216,6 +3246,7 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
const
char
*
msg3
=
"database name too long"
;
const
char
*
msg5
=
"database name is empty"
;
const
char
*
msg6
=
"pattern string is empty"
;
const
char
*
msg7
=
"pattern is invalid"
;
/*
* database prefix in pInfo->pMiscInfo->a[0]
...
...
@@ -3235,8 +3266,7 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
if
(
pDbPrefixToken
->
n
<=
0
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg5
);
}
if
(
tscValidateName
(
pDbPrefixToken
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscValidateName
(
pDbPrefixToken
,
false
,
NULL
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
...
...
@@ -3249,6 +3279,10 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
// show table/stable like 'xxxx', set the like pattern for show tables
SStrToken
*
pPattern
=
&
pShowInfo
->
pattern
;
if
(
pPattern
->
type
!=
0
)
{
if
(
pPattern
->
type
==
TK_ID
&&
pPattern
->
z
[
0
]
==
TS_ESCAPE_CHAR
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg7
);
}
pPattern
->
n
=
strdequote
(
pPattern
->
z
);
if
(
pPattern
->
n
<=
0
)
{
...
...
@@ -5898,12 +5932,13 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfo
(
pCmd
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
DEFAULT_TABLE_INDEX
);
bool
dbIncluded
=
false
;
if
(
tscValidateName
(
&
(
pAlterSQL
->
name
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscValidateName
(
&
(
pAlterSQL
->
name
)
,
true
,
&
dbIncluded
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
code
=
tscSetTableFullName
(
&
pTableMetaInfo
->
name
,
&
(
pAlterSQL
->
name
),
pSql
);
code
=
tscSetTableFullName
(
&
pTableMetaInfo
->
name
,
&
(
pAlterSQL
->
name
),
pSql
,
dbIncluded
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
...
...
@@ -7456,12 +7491,13 @@ int32_t doCheckForCreateTable(SSqlObj* pSql, int32_t subClauseIndex, SSqlInfo* p
// if sql specifies db, use it, otherwise use default db
SStrToken
*
pzTableName
=
&
(
pCreateTable
->
name
);
if
(
tscValidateName
(
pzTableName
)
!=
TSDB_CODE_SUCCESS
)
{
bool
dbIncluded
=
false
;
if
(
tscValidateName
(
pzTableName
,
true
,
&
dbIncluded
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
int32_t
code
=
tscSetTableFullName
(
&
pTableMetaInfo
->
name
,
pzTableName
,
pSql
);
int32_t
code
=
tscSetTableFullName
(
&
pTableMetaInfo
->
name
,
pzTableName
,
pSql
,
dbIncluded
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
...
...
@@ -7521,11 +7557,18 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
SCreatedTableInfo
*
pCreateTableInfo
=
taosArrayGet
(
pCreateTable
->
childTableInfo
,
j
);
SStrToken
*
pToken
=
&
pCreateTableInfo
->
stableName
;
if
(
tscValidateName
(
pToken
)
!=
TSDB_CODE_SUCCESS
)
{
bool
dbIncluded
=
false
;
char
buf
[
TSDB_TABLE_FNAME_LEN
];
SStrToken
sTblToken
;
sTblToken
.
z
=
buf
;
int32_t
code
=
validateTableName
(
pToken
->
z
,
pToken
->
n
,
&
sTblToken
,
&
dbIncluded
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
int32_t
code
=
tscSetTableFullName
(
&
pStableMetaInfo
->
name
,
pToken
,
pSql
);
code
=
tscSetTableFullName
(
&
pStableMetaInfo
->
name
,
&
sTblToken
,
pSql
,
dbIncluded
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
...
...
@@ -7694,14 +7737,15 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
kvRowCpy
(
pTag
->
data
,
row
);
free
(
row
);
bool
dbIncluded2
=
false
;
// table name
if
(
tscValidateName
(
&
(
pCreateTableInfo
->
name
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscValidateName
(
&
(
pCreateTableInfo
->
name
)
,
true
,
&
dbIncluded2
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
TABLE_INDEX
);
ret
=
tscSetTableFullName
(
&
pTableMetaInfo
->
name
,
&
pCreateTableInfo
->
name
,
pSql
);
ret
=
tscSetTableFullName
(
&
pTableMetaInfo
->
name
,
&
pCreateTableInfo
->
name
,
pSql
,
dbIncluded2
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
...
...
@@ -7738,8 +7782,9 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
// if sql specifies db, use it, otherwise use default db
SStrToken
*
pName
=
&
(
pCreateTable
->
name
);
SSqlNode
*
pSqlNode
=
pCreateTable
->
pSelect
;
bool
dbIncluded1
=
false
;
if
(
tscValidateName
(
pName
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscValidateName
(
pName
,
true
,
&
dbIncluded1
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
...
...
@@ -7753,12 +7798,19 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
}
SRelElementPair
*
p1
=
taosArrayGet
(
pFromInfo
->
list
,
0
);
SStrToken
srcToken
=
{.
z
=
p1
->
tableName
.
z
,
.
n
=
p1
->
tableName
.
n
,
.
type
=
TK_STRING
};
if
(
tscValidateName
(
&
srcToken
)
!=
TSDB_CODE_SUCCESS
)
{
SStrToken
srcToken
=
{.
z
=
p1
->
tableName
.
z
,
.
n
=
p1
->
tableName
.
n
,
.
type
=
p1
->
tableName
.
type
};
bool
dbIncluded2
=
false
;
char
buf
[
TSDB_TABLE_FNAME_LEN
];
SStrToken
sTblToken
;
sTblToken
.
z
=
buf
;
int32_t
code
=
validateTableName
(
srcToken
.
z
,
srcToken
.
n
,
&
sTblToken
,
&
dbIncluded2
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
int32_t
code
=
tscSetTableFullName
(
&
pTableMetaInfo
->
name
,
&
srcToken
,
pSql
);
code
=
tscSetTableFullName
(
&
pTableMetaInfo
->
name
,
&
sTblToken
,
pSql
,
dbIncluded2
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
...
...
@@ -7800,7 +7852,7 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
}
// set the created table[stream] name
code
=
tscSetTableFullName
(
&
pTableMetaInfo
->
name
,
pName
,
pSql
);
code
=
tscSetTableFullName
(
&
pTableMetaInfo
->
name
,
pName
,
pSql
,
dbIncluded1
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
...
...
@@ -8191,14 +8243,18 @@ static int32_t getTableNameFromSqlNode(SSqlNode* pSqlNode, SArray* tableNameList
if
(
t
->
type
==
TK_INTEGER
||
t
->
type
==
TK_FLOAT
)
{
return
invalidOperationMsg
(
msgBuf
,
msg1
);
}
tscDequoteAndTrimToken
(
t
);
if
(
tscValidateName
(
t
)
!=
TSDB_CODE_SUCCESS
)
{
bool
dbIncluded
=
false
;
char
buf
[
TSDB_TABLE_FNAME_LEN
];
SStrToken
sTblToken
;
sTblToken
.
z
=
buf
;
if
(
validateTableName
(
t
->
z
,
t
->
n
,
&
sTblToken
,
&
dbIncluded
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
msgBuf
,
msg1
);
}
SName
name
=
{
0
};
int32_t
code
=
tscSetTableFullName
(
&
name
,
t
,
pSql
);
int32_t
code
=
tscSetTableFullName
(
&
name
,
&
sTblToken
,
pSql
,
dbIncluded
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
...
...
@@ -8453,12 +8509,18 @@ static int32_t doLoadAllTableMeta(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNod
}
tscDequoteAndTrimToken
(
oriName
);
if
(
tscValidateName
(
oriName
)
!=
TSDB_CODE_SUCCESS
)
{
bool
dbIncluded
=
false
;
char
buf
[
TSDB_TABLE_FNAME_LEN
];
SStrToken
sTblToken
;
sTblToken
.
z
=
buf
;
if
(
validateTableName
(
oriName
->
z
,
oriName
->
n
,
&
sTblToken
,
&
dbIncluded
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
i
);
code
=
tscSetTableFullName
(
&
pTableMetaInfo
->
name
,
oriName
,
pSql
);
code
=
tscSetTableFullName
(
&
pTableMetaInfo
->
name
,
&
sTblToken
,
pSql
,
dbIncluded
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
...
...
@@ -8470,7 +8532,7 @@ static int32_t doLoadAllTableMeta(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNod
}
tscDequoteAndTrimToken
(
aliasName
);
if
(
tscValidateName
(
aliasName
)
!=
TSDB_CODE_SUCCESS
||
aliasName
->
n
>=
TSDB_TABLE_NAME_LEN
)
{
if
(
tscValidateName
(
aliasName
,
false
,
NULL
)
!=
TSDB_CODE_SUCCESS
||
aliasName
->
n
>=
TSDB_TABLE_NAME_LEN
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
...
...
@@ -9004,6 +9066,7 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS
if
(
colSize
>
0
)
{
SColIndex
*
idx
=
taosArrayGet
(
pCols
,
colSize
-
1
);
SSchema
*
pSchema
=
tscGetTableColumnSchema
(
pTableMeta
,
idx
->
colIndex
);
// convert time by precision
if
(
pSchema
!=
NULL
&&
TSDB_DATA_TYPE_TIMESTAMP
==
pSchema
->
type
&&
TSDB_DATA_TYPE_BINARY
==
(
*
pExpr
)
->
pVal
->
nType
)
{
...
...
src/client/src/tscServer.c
浏览文件 @
068938fb
...
...
@@ -2870,7 +2870,7 @@ int32_t getMultiTableMetaFromMnode(SSqlObj *pSql, SArray* pNameList, SArray* pVg
for
(
int32_t
i
=
0
;
i
<
numOfTable
;
++
i
)
{
char
*
name
=
taosArrayGetP
(
pNameList
,
i
);
if
(
i
<
numOfTable
-
1
||
numOfVgroupList
>
0
||
numOfUdf
>
0
)
{
len
=
sprintf
(
start
,
"%s
,
"
,
name
);
len
=
sprintf
(
start
,
"%s
`
"
,
name
);
}
else
{
len
=
sprintf
(
start
,
"%s"
,
name
);
}
...
...
@@ -2881,7 +2881,7 @@ int32_t getMultiTableMetaFromMnode(SSqlObj *pSql, SArray* pNameList, SArray* pVg
for
(
int32_t
i
=
0
;
i
<
numOfVgroupList
;
++
i
)
{
char
*
name
=
taosArrayGetP
(
pVgroupNameList
,
i
);
if
(
i
<
numOfVgroupList
-
1
||
numOfUdf
>
0
)
{
len
=
sprintf
(
start
,
"%s
,
"
,
name
);
len
=
sprintf
(
start
,
"%s
`
"
,
name
);
}
else
{
len
=
sprintf
(
start
,
"%s"
,
name
);
}
...
...
@@ -2892,7 +2892,7 @@ int32_t getMultiTableMetaFromMnode(SSqlObj *pSql, SArray* pNameList, SArray* pVg
for
(
int32_t
i
=
0
;
i
<
numOfUdf
;
++
i
)
{
SUdfInfo
*
u
=
taosArrayGet
(
pUdfList
,
i
);
if
(
i
<
numOfUdf
-
1
)
{
len
=
sprintf
(
start
,
"%s
,
"
,
u
->
name
);
len
=
sprintf
(
start
,
"%s
`
"
,
u
->
name
);
}
else
{
len
=
sprintf
(
start
,
"%s"
,
u
->
name
);
}
...
...
src/client/src/tscUtil.c
浏览文件 @
068938fb
...
...
@@ -2759,13 +2759,13 @@ void tscColumnListDestroy(SArray* pColumnList) {
* 'first_part.second_part'
*
*/
static
int32_t
validateQuoteToken
(
SStrToken
*
pToken
)
{
static
int32_t
validateQuoteToken
(
SStrToken
*
pToken
,
bool
escapeEnabled
,
bool
*
dbIncluded
)
{
tscDequoteAndTrimToken
(
pToken
);
int32_t
k
=
tGetToken
(
pToken
->
z
,
&
pToken
->
type
);
if
(
pToken
->
type
==
TK_STRING
)
{
return
tscValidateName
(
pToken
);
return
tscValidateName
(
pToken
,
escapeEnabled
,
dbIncluded
);
}
if
(
k
!=
pToken
->
n
||
pToken
->
type
!=
TK_ID
)
{
...
...
@@ -2817,14 +2817,74 @@ void tscDequoteAndTrimToken(SStrToken* pToken) {
pToken
->
n
=
last
-
first
;
}
int32_t
tscValidateName
(
SStrToken
*
pToken
)
{
if
(
pToken
==
NULL
||
pToken
->
z
==
NULL
||
(
pToken
->
type
!=
TK_STRING
&&
pToken
->
type
!=
TK_ID
))
{
void
tscRmEscapeAndTrimToken
(
SStrToken
*
pToken
)
{
uint32_t
first
=
0
,
last
=
pToken
->
n
;
// trim leading spaces
while
(
first
<
last
)
{
char
c
=
pToken
->
z
[
first
];
if
(
c
!=
' '
&&
c
!=
'\t'
)
{
break
;
}
first
++
;
}
// trim ending spaces
while
(
first
<
last
)
{
char
c
=
pToken
->
z
[
last
-
1
];
if
(
c
!=
' '
&&
c
!=
'\t'
)
{
break
;
}
last
--
;
}
// there are still at least two characters
if
(
first
<
last
-
1
)
{
char
c
=
pToken
->
z
[
first
];
// dequote
if
((
c
==
'`'
)
&&
c
==
pToken
->
z
[
last
-
1
])
{
first
++
;
last
--
;
}
}
// left shift the string and pad spaces
for
(
uint32_t
i
=
0
;
i
+
first
<
last
;
i
++
)
{
pToken
->
z
[
i
]
=
pToken
->
z
[
first
+
i
];
}
for
(
uint32_t
i
=
last
-
first
;
i
<
pToken
->
n
;
i
++
)
{
pToken
->
z
[
i
]
=
' '
;
}
// adjust token length
pToken
->
n
=
last
-
first
;
}
int32_t
tscValidateName
(
SStrToken
*
pToken
,
bool
escapeEnabled
,
bool
*
dbIncluded
)
{
if
(
pToken
==
NULL
||
pToken
->
z
==
NULL
||
(
pToken
->
type
!=
TK_STRING
&&
pToken
->
type
!=
TK_ID
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
char
*
sep
=
strnchr
(
pToken
->
z
,
TS_PATH_DELIMITER
[
0
],
pToken
->
n
,
true
);
if
((
!
escapeEnabled
)
&&
pToken
->
type
==
TK_ID
)
{
if
(
pToken
->
z
[
0
]
==
TS_ESCAPE_CHAR
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
char
*
sep
=
NULL
;
if
(
escapeEnabled
)
{
sep
=
tableNameGetPosition
(
pToken
,
TS_PATH_DELIMITER
[
0
]);
}
else
{
sep
=
strnchr
(
pToken
->
z
,
TS_PATH_DELIMITER
[
0
],
pToken
->
n
,
true
);
}
if
(
sep
==
NULL
)
{
// single part
if
(
dbIncluded
)
*
dbIncluded
=
false
;
if
(
pToken
->
type
==
TK_STRING
)
{
tscDequoteAndTrimToken
(
pToken
);
...
...
@@ -2835,23 +2895,30 @@ int32_t tscValidateName(SStrToken* pToken) {
// single token, validate it
if
(
len
==
pToken
->
n
)
{
return
validateQuoteToken
(
pToken
);
return
validateQuoteToken
(
pToken
,
escapeEnabled
,
NULL
);
}
else
{
sep
=
strnchr
(
pToken
->
z
,
TS_PATH_DELIMITER
[
0
],
pToken
->
n
,
true
);
if
(
sep
==
NULL
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
*
dbIncluded
=
true
;
return
tscValidateName
(
pToken
);
return
tscValidateName
(
pToken
,
escapeEnabled
,
NULL
);
}
}
else
if
(
pToken
->
type
==
TK_ID
)
{
tscRmEscapeAndTrimToken
(
pToken
);
return
TSDB_CODE_SUCCESS
;
}
else
{
if
(
isNumber
(
pToken
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
}
}
else
{
// two part
int32_t
oldLen
=
pToken
->
n
;
char
*
pStr
=
pToken
->
z
;
bool
firstPartQuote
=
false
;
if
(
dbIncluded
)
*
dbIncluded
=
true
;
if
(
pToken
->
type
==
TK_SPACE
)
{
pToken
->
n
=
(
uint32_t
)
strtrim
(
pToken
->
z
);
...
...
@@ -2866,8 +2933,13 @@ int32_t tscValidateName(SStrToken* pToken) {
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
if
(
pToken
->
type
==
TK_STRING
&&
validateQuoteToken
(
pToken
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
if
(
pToken
->
type
==
TK_STRING
)
{
if
(
validateQuoteToken
(
pToken
,
escapeEnabled
,
NULL
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
else
{
tscStrToLower
(
pToken
->
z
,
pToken
->
n
);
firstPartQuote
=
true
;
}
}
int32_t
firstPartLen
=
pToken
->
n
;
...
...
@@ -2879,12 +2951,20 @@ int32_t tscValidateName(SStrToken* pToken) {
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
if
(
pToken
->
type
==
TK_STRING
&&
validateQuoteToken
(
pToken
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
if
(
pToken
->
type
==
TK_STRING
)
{
if
(
validateQuoteToken
(
pToken
,
escapeEnabled
,
NULL
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
else
{
tscStrToLower
(
pToken
->
z
,
pToken
->
n
);
}
}
if
(
escapeEnabled
&&
pToken
->
type
==
TK_ID
)
{
tscRmEscapeAndTrimToken
(
pToken
);
}
// re-build the whole name string
if
(
pStr
[
firstPartLen
]
==
TS_PATH_DELIMITER
[
0
]
)
{
if
(
!
firstPartQuote
)
{
// first part do not have quote do nothing
}
else
{
pStr
[
firstPartLen
]
=
TS_PATH_DELIMITER
[
0
];
...
...
@@ -2894,8 +2974,6 @@ int32_t tscValidateName(SStrToken* pToken) {
}
pToken
->
n
+=
(
firstPartLen
+
sizeof
(
TS_PATH_DELIMITER
[
0
]));
pToken
->
z
=
pStr
;
tscStrToLower
(
pToken
->
z
,
pToken
->
n
);
}
return
TSDB_CODE_SUCCESS
;
...
...
@@ -5009,14 +5087,16 @@ static int32_t doAddTableName(char* nextStr, char** str, SArray* pNameArray, SSq
SStrToken
sToken
=
{.
n
=
len
,
.
type
=
TK_ID
,
.
z
=
tablename
};
tGetToken
(
tablename
,
&
sToken
.
type
);
bool
dbIncluded
=
false
;
// Check if the table name available or not
if
(
tscValidateName
(
&
sToken
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscValidateName
(
&
sToken
,
true
,
&
dbIncluded
)
!=
TSDB_CODE_SUCCESS
)
{
sprintf
(
pCmd
->
payload
,
"table name is invalid"
);
return
TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH
;
}
SName
name
=
{
0
};
if
((
code
=
tscSetTableFullName
(
&
name
,
&
sToken
,
pSql
))
!=
TSDB_CODE_SUCCESS
)
{
if
((
code
=
tscSetTableFullName
(
&
name
,
&
sToken
,
pSql
,
dbIncluded
))
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
...
...
src/common/inc/tname.h
浏览文件 @
068938fb
...
...
@@ -92,6 +92,10 @@ size_t tableIdPrefix(const char* name, char* prefix, int32_t len);
void
extractTableNameFromToken
(
SStrToken
*
pToken
,
SStrToken
*
pTable
);
char
*
tableNameGetPosition
(
SStrToken
*
pToken
,
char
target
);
char
*
tableNameToStr
(
char
*
dst
,
char
*
src
,
char
quote
);
SSchema
tGetUserSpecifiedColumnSchema
(
tVariant
*
pVal
,
SStrToken
*
exprStr
,
const
char
*
name
);
bool
tscValidateTableNameLength
(
size_t
len
);
...
...
src/common/src/tname.c
浏览文件 @
068938fb
...
...
@@ -151,6 +151,63 @@ int64_t taosGetIntervalStartTimestamp(int64_t startTime, int64_t slidingTime, in
#endif
char
*
tableNameGetPosition
(
SStrToken
*
pToken
,
char
target
)
{
bool
inEscape
=
false
;
bool
inQuote
=
false
;
char
quotaStr
=
0
;
for
(
uint32_t
i
=
0
;
i
<
pToken
->
n
;
++
i
)
{
if
(
*
(
pToken
->
z
+
i
)
==
target
&&
(
!
inEscape
)
&&
(
!
inQuote
))
{
return
pToken
->
z
+
i
;
}
if
(
*
(
pToken
->
z
+
i
)
==
TS_ESCAPE_CHAR
)
{
if
(
!
inQuote
)
{
inEscape
=
!
inEscape
;
}
}
if
(
*
(
pToken
->
z
+
i
)
==
'\''
||
*
(
pToken
->
z
+
i
)
==
'"'
)
{
if
(
!
inEscape
)
{
if
(
!
inQuote
)
{
quotaStr
=
*
(
pToken
->
z
+
i
);
inQuote
=
!
inQuote
;
}
else
if
(
quotaStr
==
*
(
pToken
->
z
+
i
))
{
inQuote
=
!
inQuote
;
}
}
}
}
return
NULL
;
}
char
*
tableNameToStr
(
char
*
dst
,
char
*
src
,
char
quote
)
{
*
dst
=
0
;
if
(
src
==
NULL
)
{
return
NULL
;
}
int32_t
len
=
(
int32_t
)
strlen
(
src
);
if
(
len
<=
0
)
{
return
NULL
;
}
int32_t
j
=
0
;
for
(
int32_t
i
=
0
;
i
<
len
;
++
i
)
{
if
(
*
(
src
+
i
)
==
quote
)
{
*
(
dst
+
j
++
)
=
'\\'
;
}
*
(
dst
+
j
++
)
=
*
(
src
+
i
);
}
return
dst
;
}
/*
* tablePrefix.columnName
* extract table name and save it in pTable, with only column name in pToken
...
...
@@ -162,12 +219,17 @@ void extractTableNameFromToken(SStrToken* pToken, SStrToken* pTable) {
return
;
}
char
*
r
=
strnchr
(
pToken
->
z
,
sep
,
pToken
->
n
,
false
);
if
(
r
!=
NULL
)
{
// record the table name token
pTable
->
n
=
(
uint32_t
)(
r
-
pToken
->
z
);
pTable
->
z
=
pToken
->
z
;
char
*
r
=
tableNameGetPosition
(
pToken
,
sep
);
if
(
r
!=
NULL
)
{
// record the table name token
if
(
pToken
->
z
[
0
]
==
TS_ESCAPE_CHAR
&&
*
(
r
-
1
)
==
TS_ESCAPE_CHAR
)
{
pTable
->
n
=
(
uint32_t
)(
r
-
pToken
->
z
-
2
);
pTable
->
z
=
pToken
->
z
+
1
;
}
else
{
pTable
->
n
=
(
uint32_t
)(
r
-
pToken
->
z
);
pTable
->
z
=
pToken
->
z
;
}
r
+=
1
;
pToken
->
n
-=
(
uint32_t
)(
r
-
pToken
->
z
);
pToken
->
z
=
r
;
...
...
src/common/src/tvariant.c
浏览文件 @
068938fb
...
...
@@ -81,7 +81,7 @@ void tVariantCreate(tVariant *pVar, SStrToken *token) {
case
TSDB_DATA_TYPE_BINARY
:
{
pVar
->
pz
=
strndup
(
token
->
z
,
token
->
n
);
pVar
->
nLen
=
strRmquote
(
pVar
->
pz
,
token
->
n
);
pVar
->
nLen
=
strRmquote
Escape
(
pVar
->
pz
,
token
->
n
);
break
;
}
case
TSDB_DATA_TYPE_TIMESTAMP
:
{
...
...
src/inc/taosdef.h
浏览文件 @
068938fb
...
...
@@ -98,6 +98,7 @@ extern const int32_t TYPE_BYTES[15];
#define TSDB_ERR -1
#define TS_PATH_DELIMITER "."
#define TS_ESCAPE_CHAR '`'
#define TSDB_TIME_PRECISION_MILLI 0
#define TSDB_TIME_PRECISION_MICRO 1
...
...
src/inc/ttokendef.h
浏览文件 @
068938fb
...
...
@@ -214,6 +214,8 @@
#define TK_VALUES 196
#define TK_SPACE 300
#define TK_COMMENT 301
#define TK_ILLEGAL 302
...
...
src/kit/shell/src/shellEngine.c
浏览文件 @
068938fb
...
...
@@ -250,6 +250,7 @@ int32_t shellRunCommand(TAOS* con, char* command) {
break
;
case
'\''
:
case
'"'
:
case
'`'
:
if
(
quote
)
{
*
p
++
=
'\\'
;
}
...
...
@@ -271,7 +272,7 @@ int32_t shellRunCommand(TAOS* con, char* command) {
if
(
quote
==
c
)
{
quote
=
0
;
}
else
if
(
quote
==
0
&&
(
c
==
'\''
||
c
==
'"'
))
{
}
else
if
(
quote
==
0
&&
(
c
==
'\''
||
c
==
'"'
||
c
==
'`'
))
{
quote
=
c
;
}
...
...
@@ -308,8 +309,8 @@ void shellRunCommandOnServer(TAOS *con, char command[]) {
char
*
fname
=
NULL
;
bool
printMode
=
false
;
if
((
sptr
=
strstr
(
command
,
">>"
))
!=
NULL
)
{
cptr
=
strstr
(
command
,
";"
);
if
((
sptr
=
tstrstr
(
command
,
">>"
,
true
))
!=
NULL
)
{
cptr
=
tstrstr
(
command
,
";"
,
true
);
if
(
cptr
!=
NULL
)
{
*
cptr
=
'\0'
;
}
...
...
@@ -322,8 +323,8 @@ void shellRunCommandOnServer(TAOS *con, char command[]) {
fname
=
full_path
.
we_wordv
[
0
];
}
if
((
sptr
=
strstr
(
command
,
"
\\
G"
))
!=
NULL
)
{
cptr
=
strstr
(
command
,
";"
);
if
((
sptr
=
tstrstr
(
command
,
"
\\
G"
,
true
))
!=
NULL
)
{
cptr
=
tstrstr
(
command
,
";"
,
true
);
if
(
cptr
!=
NULL
)
{
*
cptr
=
'\0'
;
}
...
...
src/mnode/src/mnodeTable.c
浏览文件 @
068938fb
...
...
@@ -2975,7 +2975,7 @@ static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) {
int32_t
num
=
0
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
char
*
str
=
strndup
(
pInfo
->
tableNames
,
contLen
);
char
**
nameList
=
strsplit
(
str
,
"
,
"
,
&
num
);
char
**
nameList
=
strsplit
(
str
,
"
`
"
,
&
num
);
SArray
*
pList
=
taosArrayInit
(
4
,
POINTER_BYTES
);
SMultiTableMeta
*
pMultiMeta
=
NULL
;
...
...
src/query/inc/sql.y
浏览文件 @
068938fb
...
...
@@ -94,7 +94,7 @@ cpxName(A) ::= DOT ids(Y). {A = Y; A.n += 1; }
cmd ::= SHOW CREATE TABLE ids(X) cpxName(Y). {
X.n += Y.n;
setDCLSqlElems(pInfo, TSDB_SQL_SHOW_CREATE_TABLE, 1, &X);
}
}
cmd ::= SHOW CREATE STABLE ids(X) cpxName(Y). {
X.n += Y.n;
setDCLSqlElems(pInfo, TSDB_SQL_SHOW_CREATE_STABLE, 1, &X);
...
...
@@ -162,6 +162,7 @@ cmd ::= DESCRIBE ids(X) cpxName(Y). {
X.n += Y.n;
setDCLSqlElems(pInfo, TSDB_SQL_DESCRIBE_TABLE, 1, &X);
}
cmd ::= DESC ids(X) cpxName(Y). {
X.n += Y.n;
setDCLSqlElems(pInfo, TSDB_SQL_DESCRIBE_TABLE, 1, &X);
...
...
src/query/src/qFilter.c
浏览文件 @
068938fb
...
...
@@ -1802,10 +1802,7 @@ int32_t filterInitValFieldData(SFilterInfo *info) {
}
if
(
unit
->
compare
.
optr
==
TSDB_RELATION_IN
)
{
SSchema
*
sch
=
FILTER_UNIT_COL_DESC
(
info
,
unit
);
bool
tolower
=
(
sch
->
colId
==
-
1
)
?
true
:
false
;
filterConvertSetFromBinary
((
void
**
)
&
fi
->
data
,
var
->
pz
,
var
->
nLen
,
type
,
tolower
);
filterConvertSetFromBinary
((
void
**
)
&
fi
->
data
,
var
->
pz
,
var
->
nLen
,
type
,
false
);
CHK_LRET
(
fi
->
data
==
NULL
,
TSDB_CODE_QRY_APP_ERROR
,
"failed to convert in param"
);
FILTER_SET_FLAG
(
fi
->
flag
,
FLD_DATA_IS_HASH
);
...
...
src/query/src/sql.c
浏览文件 @
068938fb
此差异已折叠。
点击以展开。
src/query/tests/unitTest.cpp
浏览文件 @
068938fb
...
...
@@ -23,7 +23,7 @@ int32_t testValidateName(char* name) {
token
.
type
=
0
;
tGetToken
(
name
,
&
token
.
type
);
return
tscValidateName
(
&
token
);
return
tscValidateName
(
&
token
,
false
,
NULL
);
}
}
...
...
src/util/inc/tutil.h
浏览文件 @
068938fb
...
...
@@ -27,7 +27,9 @@ extern "C" {
int32_t
strdequote
(
char
*
src
);
int32_t
strRmquote
(
char
*
z
,
int32_t
len
);
int32_t
strRmquoteEscape
(
char
*
z
,
int32_t
len
);
size_t
strtrim
(
char
*
src
);
char
*
tstrstr
(
char
*
src
,
char
*
dst
,
bool
ignoreInEsc
);
char
*
strnchr
(
char
*
haystack
,
char
needle
,
int32_t
len
,
bool
skipquote
);
char
**
strsplit
(
char
*
src
,
const
char
*
delim
,
int32_t
*
num
);
char
*
strtolower
(
char
*
dst
,
const
char
*
src
);
...
...
src/util/src/ttokenizer.c
浏览文件 @
068938fb
...
...
@@ -228,7 +228,7 @@ static SKeyword keywordTable[] = {
{
"FUNCTIONS"
,
TK_FUNCTIONS
},
{
"OUTPUTTYPE"
,
TK_OUTPUTTYPE
},
{
"AGGREGATE"
,
TK_AGGREGATE
},
{
"BUFSIZE"
,
TK_BUFSIZE
}
,
{
"BUFSIZE"
,
TK_BUFSIZE
}
};
static
const
char
isIdChar
[]
=
{
...
...
@@ -442,6 +442,17 @@ uint32_t tGetToken(char* z, uint32_t* tokenId) {
break
;
}
case
'`'
:
{
for
(
i
=
1
;
z
[
i
];
i
++
)
{
if
(
z
[
i
]
==
'`'
)
{
i
++
;
*
tokenId
=
TK_ID
;
return
i
;
}
}
break
;
}
case
'.'
:
{
/*
* handle the the float number with out integer part
...
...
src/util/src/tutil.c
浏览文件 @
068938fb
...
...
@@ -84,6 +84,20 @@ int32_t strRmquote(char *z, int32_t len){
return
len
-
2
-
cnt
;
}
int32_t
strRmquoteEscape
(
char
*
z
,
int32_t
len
)
{
if
(
len
<=
0
)
return
len
;
if
(
z
[
0
]
==
'\''
||
z
[
0
]
==
'\"'
)
{
return
strRmquote
(
z
,
len
);
}
else
if
(
len
>
1
&&
z
[
0
]
==
TS_ESCAPE_CHAR
&&
z
[
len
-
1
]
==
TS_ESCAPE_CHAR
)
{
memmove
(
z
,
z
+
1
,
len
-
2
);
return
len
-
2
;
}
return
len
;
}
size_t
strtrim
(
char
*
z
)
{
int32_t
i
=
0
;
...
...
@@ -165,6 +179,43 @@ char *strnchr(char *haystack, char needle, int32_t len, bool skipquote) {
return
NULL
;
}
char
*
tstrstr
(
char
*
src
,
char
*
dst
,
bool
ignoreInEsc
)
{
if
(
!
ignoreInEsc
)
{
return
strstr
(
src
,
dst
);
}
int32_t
len
=
(
int32_t
)
strlen
(
src
);
bool
inEsc
=
false
;
char
escChar
=
0
;
char
*
str
=
src
,
*
res
=
NULL
;
for
(
int32_t
i
=
0
;
i
<
len
;
++
i
)
{
if
(
src
[
i
]
==
TS_ESCAPE_CHAR
||
src
[
i
]
==
'\''
||
src
[
i
]
==
'\"'
)
{
if
(
!
inEsc
)
{
escChar
=
src
[
i
];
src
[
i
]
=
0
;
res
=
strstr
(
str
,
dst
);
src
[
i
]
=
escChar
;
if
(
res
)
{
return
res
;
}
str
=
NULL
;
}
else
{
if
(
src
[
i
]
!=
escChar
)
{
continue
;
}
str
=
src
+
i
+
1
;
}
inEsc
=
!
inEsc
;
continue
;
}
}
return
str
?
strstr
(
str
,
dst
)
:
NULL
;
}
char
*
strtolower
(
char
*
dst
,
const
char
*
src
)
{
...
...
@@ -195,7 +246,7 @@ char* strtolower(char *dst, const char *src) {
}
char
*
strntolower
(
char
*
dst
,
const
char
*
src
,
int32_t
n
)
{
int
esc
=
0
;
int
esc
=
0
,
inEsc
=
0
;
char
quote
=
0
,
*
p
=
dst
,
c
;
assert
(
dst
!=
NULL
);
...
...
@@ -212,10 +263,16 @@ char* strntolower(char *dst, const char *src, int32_t n) {
}
else
if
(
c
==
quote
)
{
quote
=
0
;
}
}
else
if
(
inEsc
)
{
if
(
c
==
'`'
)
{
inEsc
=
0
;
}
}
else
if
(
c
>=
'A'
&&
c
<=
'Z'
)
{
c
-=
'A'
-
'a'
;
}
else
if
(
c
==
'\''
||
c
==
'"'
)
{
}
else
if
(
inEsc
==
0
&&
(
c
==
'\''
||
c
==
'"'
)
)
{
quote
=
c
;
}
else
if
(
c
==
'`'
&&
quote
==
0
)
{
inEsc
=
1
;
}
*
p
++
=
c
;
}
...
...
tests/pytest/client/twoClients.py
浏览文件 @
068938fb
...
...
@@ -17,6 +17,7 @@ sys.path.insert(0, os.getcwd())
from
util.log
import
*
from
util.sql
import
*
from
util.dnodes
import
*
import
multiprocessing
as
mp
import
taos
...
...
@@ -25,7 +26,6 @@ class TwoClients:
self
.
host
=
"127.0.0.1"
self
.
user
=
"root"
self
.
password
=
"taosdata"
self
.
config
=
"/home/xp/git/TDengine/sim/dnode1/cfg"
def
run
(
self
):
tdDnodes
.
init
(
""
)
...
...
@@ -37,7 +37,7 @@ class TwoClients:
tdDnodes
.
start
(
1
)
# first client create a stable and insert data
conn1
=
taos
.
connect
(
self
.
host
,
self
.
user
,
self
.
password
,
self
.
config
)
conn1
=
taos
.
connect
(
host
=
self
.
host
,
user
=
self
.
user
,
password
=
self
.
password
,
config
=
tdDnodes
.
getSimCfgPath
()
)
cursor1
=
conn1
.
cursor
()
cursor1
.
execute
(
"drop database if exists db"
)
cursor1
.
execute
(
"create database db"
)
...
...
@@ -46,7 +46,7 @@ class TwoClients:
cursor1
.
execute
(
"insert into t0 using tb tags('beijing') values(now, 1)"
)
# second client alter the table created by cleint
conn2
=
taos
.
connect
(
self
.
host
,
self
.
user
,
self
.
password
,
self
.
config
)
conn2
=
taos
.
connect
(
host
=
self
.
host
,
user
=
self
.
user
,
password
=
self
.
password
,
config
=
tdDnodes
.
getSimCfgPath
()
)
cursor2
=
conn2
.
cursor
()
cursor2
.
execute
(
"use db"
)
cursor2
.
execute
(
"alter table tb add column name nchar(30)"
)
...
...
tests/pytest/insert/insertJSONPayload.py
浏览文件 @
068938fb
...
...
@@ -35,7 +35,7 @@ class TDTestCase:
print
(
"============= step0 : test metric ================"
)
payload
=
[
'''
{
"metric": "
.stb.0.
",
"metric": "
`.stb.0.`
",
"timestamp": 1626006833610123,
"value": 10,
"tags": {
...
...
@@ -49,7 +49,7 @@ class TDTestCase:
code
=
self
.
_conn
.
schemaless_insert
(
payload
,
2
)
print
(
"schemaless_insert result {}"
.
format
(
code
))
tdSql
.
query
(
"describe
_stb_0_
"
)
tdSql
.
query
(
"describe
`.stb.0.`
"
)
tdSql
.
checkRows
(
6
)
### metric value ###
...
...
tests/pytest/insert/insertTelnetLines.py
浏览文件 @
068938fb
...
...
@@ -36,7 +36,7 @@ class TDTestCase:
"stb0_0 1626006833639000000ns 4i8 host=
\"
host0
\"
interface=
\"
eth0
\"
"
,
"stb0_1 1626006833639000000ns 4i8 host=
\"
host0
\"
interface=
\"
eth0
\"
"
,
"stb0_2 1626006833639000000ns 4i8 host=
\"
host0
\"
interface=
\"
eth0
\"
"
,
"
.stb0.3.
1626006833639000000ns 4i8 host=
\"
host0
\"
interface=
\"
eth0
\"
"
,
"
`.stb0.3.`
1626006833639000000ns 4i8 host=
\"
host0
\"
interface=
\"
eth0
\"
"
,
]
code
=
self
.
_conn
.
schemaless_insert
(
lines0
,
1
)
...
...
@@ -54,7 +54,7 @@ class TDTestCase:
tdSql
.
query
(
"describe stb0_2"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"describe
_stb0_3_
"
)
tdSql
.
query
(
"describe
`.stb0.3.`
"
)
tdSql
.
checkRows
(
4
)
### timestamp ###
...
...
tests/pytest/query/queryTbnameUpperLower.py
浏览文件 @
068938fb
...
...
@@ -46,17 +46,17 @@ class TDTestCase:
## query where tbname in single
tdSql
.
query
(
f
'select * from
{
table_name
}
where tbname in ("
{
table_name_sub
}
1")'
)
tdSql
.
checkRows
(
1
)
tdSql
.
checkRows
(
0
)
tdSql
.
query
(
f
'select * from
{
table_name
}
where tbname in ("
{
table_name_sub
.
upper
()
}
1")'
)
tdSql
.
checkRows
(
1
)
tdSql
.
checkRows
(
0
)
tdSql
.
query
(
f
'select * from
{
table_name
}
where tbname in ("
{
table_name_sub
.
lower
()
}
1")'
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
f
'select * from
{
table_name
}
where tbname in ("
{
tb_name_lower
}
2")'
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
f
'select * from
{
table_name
}
where tbname in ("
{
tb_name_lower
.
upper
()
}
2")'
)
tdSql
.
checkRows
(
2
)
tdSql
.
checkRows
(
0
)
tdSql
.
query
(
f
'select * from
{
table_name
}
where tbname in ("
{
tb_name_upper
}
3")'
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkRows
(
0
)
tdSql
.
query
(
f
'select * from
{
table_name
}
where tbname in ("
{
tb_name_upper
.
lower
()
}
3")'
)
tdSql
.
checkRows
(
3
)
...
...
@@ -64,7 +64,7 @@ class TDTestCase:
tdSql
.
query
(
f
'select * from
{
table_name
}
where id=5 and tbname in ("
{
table_name_sub
}
1", "
{
tb_name_lower
.
upper
()
}
2", "
{
tb_name_upper
.
lower
()
}
3")'
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
f
'select * from
{
table_name
}
where tbname in ("
{
table_name_sub
}
1", "
{
tb_name_lower
.
upper
()
}
2", "
{
tb_name_upper
.
lower
()
}
3")'
)
tdSql
.
checkRows
(
6
)
tdSql
.
checkRows
(
3
)
def
run
(
self
):
tdSql
.
prepare
()
...
...
@@ -75,4 +75,4 @@ class TDTestCase:
tdLog
.
success
(
"%s successfully executed"
%
__file__
)
tdCases
.
addWindows
(
__file__
,
TDTestCase
())
tdCases
.
addLinux
(
__file__
,
TDTestCase
())
\ No newline at end of file
tdCases
.
addLinux
(
__file__
,
TDTestCase
())
tests/pytest/table/create.py
浏览文件 @
068938fb
...
...
@@ -13,6 +13,8 @@
import
sys
import
taos
import
time
import
os
from
util.log
import
tdLog
from
util.cases
import
tdCases
from
util.sql
import
tdSql
...
...
@@ -23,7 +25,34 @@ class TDTestCase:
tdLog
.
debug
(
"start to execute %s"
%
__file__
)
tdSql
.
init
(
conn
.
cursor
(),
logSql
)
now
=
time
.
time
()
self
.
ts
=
int
(
round
(
now
*
1000
))
def
getBuildPath
(
self
):
selfPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
(
"community"
in
selfPath
):
projPath
=
selfPath
[:
selfPath
.
find
(
"community"
)]
else
:
projPath
=
selfPath
[:
selfPath
.
find
(
"tests"
)]
for
root
,
dirs
,
files
in
os
.
walk
(
projPath
):
if
(
"taosd"
in
files
):
rootRealPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
root
))
if
(
"packaging"
not
in
rootRealPath
):
buildPath
=
root
[:
len
(
root
)
-
len
(
"/build/bin"
)]
break
return
buildPath
def
run
(
self
):
buildPath
=
self
.
getBuildPath
()
if
(
buildPath
==
""
):
tdLog
.
exit
(
"taosd not found!"
)
else
:
tdLog
.
info
(
"taosd found in %s"
%
buildPath
)
binPath
=
buildPath
+
"/build/bin/"
os
.
system
(
"rm -rf table/create1.py.sql"
)
tdSql
.
prepare
()
print
(
"==============step1"
)
...
...
@@ -55,13 +84,274 @@ class TDTestCase:
tdSql
.
query
(
"show stables like 'st%' "
)
tdSql
.
checkRows
(
3
)
# case for defect: https://jira.taosdata.com:18080/browse/TD-2693
tdSql
.
execute
(
"create database db2"
)
tdSql
.
execute
(
"use db2"
)
tdSql
.
execute
(
"create table stb(ts timestamp, c int) tags(t int)"
)
tdSql
.
error
(
"insert into db2.tb6 using db2.stb tags(1) values(now 1) tb2 using db2. tags( )values(now 2)"
)
print
(
"==============new version [escape character] for stable=============="
)
print
(
"==============step1,#create db.stable,db.table; insert db.table; show db.table; select db.table; drop db.table;"
)
print
(
"prepare data"
)
self
.
stb1
=
"stable_1~!@#$%^&*()-_+=[]{}':,<.>/?stST13579"
self
.
tb1
=
"table_1~!@#$%^&*()-_+=[]{}':,<.>/?stST13579"
tdSql
.
execute
(
"create stable db.`%s` (ts timestamp, i int) tags(j int)"
%
self
.
stb1
)
tdSql
.
query
(
"describe db.`%s` ; "
%
self
.
stb1
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
"select _block_dist() from db.`%s` ; "
%
self
.
stb1
)
tdSql
.
checkRows
(
0
)
tdSql
.
query
(
"show create stable db.`%s` ; "
%
self
.
stb1
)
tdSql
.
checkData
(
0
,
0
,
self
.
stb1
)
tdSql
.
checkData
(
0
,
1
,
"create table `%s` (ts TIMESTAMP,i INT) TAGS (j INT)"
%
self
.
stb1
)
tdSql
.
execute
(
"create table db.`table!1` using db.`%s` tags(1)"
%
self
.
stb1
)
tdSql
.
query
(
"describe db.`table!1` ; "
)
tdSql
.
checkRows
(
3
)
time
.
sleep
(
10
)
tdSql
.
query
(
"show create table db.`table!1` ; "
)
tdSql
.
checkData
(
0
,
0
,
"table!1"
)
tdSql
.
checkData
(
0
,
1
,
"CREATE TABLE `table!1` USING `%s` TAGS (1)"
%
self
.
stb1
)
tdSql
.
execute
(
"insert into db.`table!1` values(now, 1)"
)
tdSql
.
query
(
"select * from db.`table!1`; "
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select count(*) from db.`table!1`; "
)
tdSql
.
checkData
(
0
,
0
,
1
)
tdSql
.
query
(
"select _block_dist() from db.`%s` ; "
%
self
.
stb1
)
tdSql
.
checkRows
(
1
)
tdSql
.
execute
(
"create table db.`%s` using db.`%s` tags(1)"
%
(
self
.
tb1
,
self
.
stb1
))
tdSql
.
query
(
"describe db.`%s` ; "
%
self
.
tb1
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
"show create table db.`%s` ; "
%
self
.
tb1
)
tdSql
.
checkData
(
0
,
0
,
self
.
tb1
)
tdSql
.
checkData
(
0
,
1
,
"CREATE TABLE `%s` USING `%s` TAGS (1)"
%
(
self
.
tb1
,
self
.
stb1
))
tdSql
.
execute
(
"insert into db.`%s` values(now, 1)"
%
self
.
tb1
)
tdSql
.
query
(
"select * from db.`%s` ; "
%
self
.
tb1
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select count(*) from db.`%s`; "
%
self
.
tb1
)
tdSql
.
checkData
(
0
,
0
,
1
)
#time.sleep(10)
tdSql
.
query
(
"select * from db.`%s` ; "
%
self
.
stb1
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
"select count(*) from db.`%s`; "
%
self
.
stb1
)
tdSql
.
checkData
(
0
,
0
,
2
)
tdSql
.
query
(
"select * from (select * from db.`%s`) ; "
%
self
.
stb1
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
"select count(*) from (select * from db.`%s`) ; "
%
self
.
stb1
)
tdSql
.
checkData
(
0
,
0
,
2
)
tdSql
.
query
(
"show db.stables like 'stable_1%' "
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show db.tables like 'table%' "
)
tdSql
.
checkRows
(
2
)
#TD-10531 tbname is not support
# tdSql.execute("select * from db.`%s` where tbname = db.`%s`;" %(self.stb1,self.tb1))
# tdSql.checkRows(1)
# tdSql.execute("select count(*) from db.`%s` where tbname in (db.`%s`,db.`table!1`);" %(self.stb1,self.tb1))
# tdSql.checkRows(4)
print
(
"==============old scene is not change, max length : database.name + table.name <= 192"
)
self
.
tb192old
=
"table192table192oldtable192oldtable192oldtable192oldtable192oldtable192oldtable192oldtable192oldtable192oldtable192oldtable192oldtable192oldtable192oldtable192oldtable192oldtable192oldtable192"
tdSql
.
execute
(
"create table db.%s using db.st tags(1)"
%
self
.
tb192old
)
tdSql
.
query
(
"describe db.%s ; "
%
self
.
tb192old
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
"show db.tables like 'table192%' "
)
tdSql
.
checkRows
(
1
)
self
.
tb193old
=
"table193table192oldtable192oldtable192oldtable192oldtable192oldtable192oldtable192oldtable192oldtable192oldtable192oldtable192oldtable192oldtable192oldtable192oldtable192oldtable192oldtable192o"
tdSql
.
error
(
"create table db.%s using db.st tags(1)"
%
self
.
tb193old
)
print
(
"==============new scene `***` is change, max length : `table.name` <= 192 ,not include database.name"
)
self
.
tb192new
=
"table_192~!@#$%^&*()-_+=[]{}':,<.>/?stST0123456789table_192~!@#$%^&*()-_+=[]{}':,<.>/?stST0123456789table_192~!@#$%^&*()-_+=[]{}':,<.>/?stST0123456789table_192~!@#$%^&*()-_+=[]{}':,<.>/?stST12"
tdSql
.
execute
(
"create table db.`%s` using db.`%s` tags(1)"
%
(
self
.
tb192new
,
self
.
stb1
))
tdSql
.
query
(
"describe db.`%s` ; "
%
self
.
tb192new
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
"show db.tables like 'table_192%' "
)
tdSql
.
checkRows
(
1
)
self
.
tb193new
=
"table_193~!@#$%^&*()-_+=[]{}':,<.>/?stST0123456789table_192~!@#$%^&*()-_+=[]{}':,<.>/?stST0123456789table_192~!@#$%^&*()-_+=[]{}':,<.>/?stST0123456789table_192~!@#$%^&*()-_+=[]{}':,<.>/?stST123"
tdSql
.
error
(
"create table db.`%s` using db.`%s` tags(1)"
%
(
self
.
tb193new
,
self
.
stb1
))
self
.
cr_tb1
=
"create_table_1~!@#$%^&*()-_+=[]{}':,<.>/?stST13579"
tdSql
.
execute
(
"create table db.`%s` as select avg(i) from db.`%s` where ts > now interval(1m) sliding(30s);"
%
(
self
.
cr_tb1
,
self
.
stb1
))
tdSql
.
query
(
"show db.tables like 'create_table_%' "
)
tdSql
.
checkRows
(
1
)
print
(
"==============drop table\stable"
)
try
:
tdSql
.
execute
(
"drop table db.`%s` "
%
self
.
tb1
)
except
Exception
as
e
:
tdLog
.
exit
(
e
)
tdSql
.
error
(
"select * from db.`%s`"
%
self
.
tb1
)
tdSql
.
query
(
"show db.stables like 'stable_1%' "
)
tdSql
.
checkRows
(
1
)
try
:
tdSql
.
execute
(
"drop table db.`%s` "
%
self
.
stb1
)
except
Exception
as
e
:
tdLog
.
exit
(
e
)
tdSql
.
error
(
"select * from db.`%s`"
%
self
.
tb1
)
tdSql
.
error
(
"select * from db.`%s`"
%
self
.
stb1
)
print
(
"==============step2,#create stable,table; insert table; show table; select table; drop table"
)
self
.
stb2
=
"stable_2~!@#$%^&*()-_+=[]{}';:,<.>/?stST24680~!@#$%^&*()-_+=[]{}"
self
.
tb2
=
"table_2~!@#$%^&*()-_+=[]{}';:,<.>/?stST24680~!@#$%^&*()-_+=[]{}"
tdSql
.
execute
(
"create stable `%s` (ts timestamp, i int) tags(j int);"
%
self
.
stb2
)
tdSql
.
query
(
"describe `%s` ; "
%
self
.
stb2
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
"select _block_dist() from `%s` ; "
%
self
.
stb2
)
tdSql
.
checkRows
(
0
)
tdSql
.
query
(
"show create stable `%s` ; "
%
self
.
stb2
)
tdSql
.
checkData
(
0
,
0
,
self
.
stb2
)
tdSql
.
checkData
(
0
,
1
,
"create table `%s` (ts TIMESTAMP,i INT) TAGS (j INT)"
%
self
.
stb2
)
tdSql
.
execute
(
"create table `table!2` using `%s` tags(1)"
%
self
.
stb2
)
tdSql
.
query
(
"describe `table!2` ; "
)
tdSql
.
checkRows
(
3
)
time
.
sleep
(
10
)
tdSql
.
query
(
"show create table `table!2` ; "
)
tdSql
.
checkData
(
0
,
0
,
"table!2"
)
tdSql
.
checkData
(
0
,
1
,
"CREATE TABLE `table!2` USING `%s` TAGS (1)"
%
self
.
stb2
)
tdSql
.
execute
(
"insert into `table!2` values(now, 1)"
)
tdSql
.
query
(
"select * from `table!2`; "
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select count(*) from `table!2`; "
)
tdSql
.
checkData
(
0
,
0
,
1
)
tdSql
.
query
(
"select _block_dist() from `%s` ; "
%
self
.
stb2
)
tdSql
.
checkRows
(
1
)
tdSql
.
execute
(
"create table `%s` using `%s` tags(1)"
%
(
self
.
tb2
,
self
.
stb2
))
tdSql
.
query
(
"describe `%s` ; "
%
self
.
tb2
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
"show create table `%s` ; "
%
self
.
tb2
)
tdSql
.
checkData
(
0
,
0
,
self
.
tb2
)
tdSql
.
checkData
(
0
,
1
,
"CREATE TABLE `%s` USING `%s` TAGS (1)"
%
(
self
.
tb2
,
self
.
stb2
))
tdSql
.
execute
(
"insert into `%s` values(now, 1)"
%
self
.
tb2
)
tdSql
.
query
(
"select * from `%s` ; "
%
self
.
tb2
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select count(*) from `%s`; "
%
self
.
tb2
)
tdSql
.
checkData
(
0
,
0
,
1
)
tdSql
.
query
(
"select * from `%s` ; "
%
self
.
stb2
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
"select count(*) from `%s`; "
%
self
.
stb2
)
tdSql
.
checkData
(
0
,
0
,
2
)
tdSql
.
query
(
"select * from (select * from `%s`) ; "
%
self
.
stb2
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
"select count(*) from (select * from `%s` ); "
%
self
.
stb2
)
tdSql
.
checkData
(
0
,
0
,
2
)
tdSql
.
query
(
"show stables like 'stable_2%' "
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show tables like 'table%' "
)
tdSql
.
checkRows
(
2
)
#TD-10531 tbname is not support
# tdSql.execute("select * from db.`%s` where tbname = db.`%s`;" %(self.stb1,self.tb1))
# tdSql.checkRows(1)
# tdSql.execute("select count(*) from db.`%s` where tbname in (db.`%s`,db.`table!1`);" %(self.stb1,self.tb1))
# tdSql.checkRows(4)
#TD-10536
self
.
cr_tb2
=
"create_table_2~!@#$%^&*()-_+=[]{}';:,<.>/?stST24680~!@#$%^&*()-_+=[]{}"
tdSql
.
execute
(
"create table `%s` as select * from `%s` ;"
%
(
self
.
cr_tb2
,
self
.
stb2
))
tdSql
.
query
(
"show db.tables like 'create_table_%' "
)
tdSql
.
checkRows
(
1
)
print
(
"==============drop table\stable"
)
try
:
tdSql
.
execute
(
"drop table `%s` "
%
self
.
tb2
)
except
Exception
as
e
:
tdLog
.
exit
(
e
)
tdSql
.
error
(
"select * from `%s`"
%
self
.
tb2
)
tdSql
.
query
(
"show stables like 'stable_2%' "
)
tdSql
.
checkRows
(
1
)
try
:
tdSql
.
execute
(
"drop table `%s` "
%
self
.
stb2
)
except
Exception
as
e
:
tdLog
.
exit
(
e
)
tdSql
.
error
(
"select * from `%s`"
%
self
.
tb2
)
tdSql
.
error
(
"select * from `%s`"
%
self
.
stb2
)
print
(
"==============step3,#create regular_table; insert regular_table; show regular_table; select regular_table; drop regular_table"
)
self
.
regular_table
=
"regular_table~!@#$%^&*()-_+=[]{}';:,<.>/?stST24680~!@#$%^&*()-_+=[]{}"
#self.regular_table = "regular_table~!@#$%^&*()-_+=[]{}';:,<.>/?stST24680~!@#$%^&*()-_+=[]{}"
tdSql
.
execute
(
"create table `%s` (ts timestamp,i int) ;"
%
self
.
regular_table
)
tdSql
.
query
(
"describe `%s` ; "
%
self
.
regular_table
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
"select _block_dist() from `%s` ; "
%
self
.
regular_table
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table `%s` ; "
%
self
.
regular_table
)
tdSql
.
checkData
(
0
,
0
,
self
.
regular_table
)
tdSql
.
checkData
(
0
,
1
,
"create table `%s` (ts TIMESTAMP,i INT)"
%
self
.
regular_table
)
tdSql
.
execute
(
"insert into `%s` values(now, 1)"
%
self
.
regular_table
)
tdSql
.
query
(
"select * from `%s` ; "
%
self
.
regular_table
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select count(*) from `%s`; "
%
self
.
regular_table
)
tdSql
.
checkData
(
0
,
0
,
1
)
tdSql
.
query
(
"select _block_dist() from `%s` ; "
%
self
.
regular_table
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select * from (select * from `%s`) ; "
%
self
.
regular_table
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select count(*) from (select * from `%s` ); "
%
self
.
regular_table
)
tdSql
.
checkData
(
0
,
0
,
1
)
tdSql
.
query
(
"show tables like 'regular_table%' "
)
tdSql
.
checkRows
(
1
)
self
.
crr_tb
=
"create_r_table~!@#$%^&*()-_+=[]{}';:,<.>/?stST24680~!@#$%^&*()-_+=[]{}"
# tdSql.execute("create table `%s` as select * from `%s` ;" %(self.crr_tb,self.regular_table))
# tdSql.query("show db.tables like 'create_r_table%' ")
# tdSql.checkRows(1)
print
(
"==============drop table\stable"
)
try
:
tdSql
.
execute
(
"drop table `%s` "
%
self
.
regular_table
)
except
Exception
as
e
:
tdLog
.
exit
(
e
)
tdSql
.
error
(
"select * from `%s`"
%
self
.
regular_table
)
#表名:192个字符,还要包含前面的数据库名
#taosdemo 建数据库表 # 单独放
# self.tsdemo = "tsdemo~!@#$%^&*()-_+=[]{}"
# os.system("%staosdemo -d test -m `%s` -t 10 -n 100 -l 10 -y " % (binPath,self.tsdemo))
# tdSql.execute("use #!#!#!")
# tdSql.query("select count (tbname) from #!#!#!")
# tdSql.checkData(0, 0, 1000)
def
stop
(
self
):
tdSql
.
close
()
tdLog
.
success
(
"%s successfully executed"
%
__file__
)
...
...
tests/script/fullGeneralSuite.sim
浏览文件 @
068938fb
...
...
@@ -227,3 +227,4 @@ run general/db/show_create_db.sim
run general/db/show_create_table.sim
run general/parser/like.sim
run general/parser/regex.sim
run general/parser/tbname_escape.sim
tests/script/general/parser/tbnameIn_query.sim
浏览文件 @
068938fb
...
...
@@ -101,9 +101,9 @@ if $data11 != 2 then
return -1
endi
##
tbname in can accpet Upper case table nam
e
##
no support tbname in Upper cas
e
sql select count(*) from $stb where tbname in ('ti_tb0', 'TI_tb1', 'TI_TB2') group by t1 order by t1
if $rows !=
3
then
if $rows !=
1
then
return -1
endi
if $data00 != 10 then
...
...
@@ -112,18 +112,6 @@ endi
if $data01 != 0 then
return -1
endi
if $data10 != 10 then
return -1
endi
if $data11 != 1 then
return -1
endi
if $data20 != 10 then
return -1
endi
if $data21 != 2 then
return -1
endi
sql select count(*) from $stb where tbname in ('ti_tb1', 'ti_tb300') and tbname in ('ti_tb5', 'ti_tb1000') group by t1 order by t1 asc
if $rows != 0 then
...
...
tests/script/general/parser/tbname_escape.sim
0 → 100644
浏览文件 @
068938fb
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c walLevel -v 1
system sh/exec.sh -n dnode1 -s start
sleep 100
sql connect
print ======================== dnode1 start
sql create database dbesc;
sql use dbesc;
sql_error create stable `dbesc`.stba (ts timestamp, f1 int) tags(t1 int);
sql create stable `!.!.!` (ts timestamp, f1 int) tags(t1 int);
sql create stable 'st1' (ts timestamp, f1 int) tags(t1 int) ;
sql create stable `st2` (ts timestamp, f1 int) tags(t1 int) ;
sql create stable dbesc.`st3` (ts timestamp, f1 int) tags(t1 int) ;
sql create table `***` (ts timestamp, f1 int) tags(t1 int);
sql create table `.,@` (ts timestamp, f1 int);
sql_error create table ',?,?,?' using dbesc.`!.!.!` tags(1);
sql_error create table `ab`` using dbesc.`!.!.!` tags(2);
sql create table `,?,?,?` using dbesc.`!.!.!` tags(1);
sql create table `~!@#\$%^&*()_+|\][{}a,./<>?0` using dbesc.`!.!.!` tags(2);
sql_error create table 'tb1' using `dbesc`.`!.!.!` tags(2);
sql create table 'tb2' using `!.!.!` tags(2);
sql create table 'tb3' using 'dbesc'.`!.!.!` tags(3);
sql create table 'tb4' using "dbesc".`!.!.!` tags(3);
sql insert into 'tb5' using 'st1' tags (3) values ('2021-09-22 10:10:11', 1);
sql insert into dbesc.'tb6' using dbesc.'st1' tags (3) values ('2021-09-22 10:10:12', 2);
sql insert into `.....` using `!.!.!` tags (3) values ('2021-09-22 10:10:13', 3);
sql insert into dbesc.`.....,` using dbesc.`!.!.!` tags (4) values ('2021-09-22 10:10:13', 4);
sql insert into "dbesc".`.....,,` using 'dbesc'.`!.!.!` tags (5) values ('2021-09-22 10:10:14', 5);
sql_error insert into `dbesc`.`.....,,,` using 'dbesc'.`!.!.!` tags (6) values ('2021-09-22 10:10:15', 6);
sql_error insert into dbesc.`.....,,,` using `dbesc`.`!.!.!` tags (7) values ('2021-09-22 10:10:16', 7);
sql insert into dbesc.`.....,,,1` using "dbesc".`!.!.!` tags (8) values ('2021-09-22 10:10:17', 8);
sql select * from `.....`;
if $rows != 1 then
return -1
endi
if $data00 != @21-09-22 10:10:13.000@ then
return -1
endi
sql select `.....`.* from `.....`;
if $rows != 1 then
return -1
endi
if $data00 != @21-09-22 10:10:13.000@ then
return -1
endi
sql select `.....`.*, `.....,`.* from `.....`,`.....,` where `.....`.ts=`.....,`.ts;
if $rows != 1 then
return -1
endi
if $data00 != @21-09-22 10:10:13.000@ then
return -1
endi
sql select `.....`.*, `.....,`.* from dbesc.`.....`,dbesc.`.....,` where `.....`.ts=`.....,`.ts;
if $rows != 1 then
return -1
endi
if $data00 != @21-09-22 10:10:13.000@ then
return -1
endi
sql select a.*, b.* from dbesc.`.....` a,dbesc.`.....,` b where a.ts=b.ts;
if $rows != 1 then
return -1
endi
if $data00 != @21-09-22 10:10:13.000@ then
return -1
endi
#!!!!
sql select a.*, b.* from dbesc.`.....` 'a',dbesc.`.....,` 'b' where a.ts=b.ts;
if $rows != 1 then
return -1
endi
if $data00 != @21-09-22 10:10:13.000@ then
return -1
endi
sql select a.*, b.* from `.....` a,`.....,` b where a.ts=b.ts;
if $rows != 1 then
return -1
endi
if $data00 != @21-09-22 10:10:13.000@ then
return -1
endi
sql insert into dbesc.`.....` values ('2021-09-22 10:10:18', 9);
sql insert into 'dbesc'.`.....` values ('2021-09-22 10:10:19', 10);
sql insert into "dbesc".`.....` values ('2021-09-22 10:10:20', 11);
sql_error select * from `!.!.!` where tbname = `.....`;
sql select * from `!.!.!` where tbname = '.....';
if $rows != 4 then
return -1
endi
if $data00 != @21-09-22 10:10:13.000@ then
return -1
endi
if $data10 != @21-09-22 10:10:18.000@ then
return -1
endi
if $data20 != @21-09-22 10:10:19.000@ then
return -1
endi
if $data30 != @21-09-22 10:10:20.000@ then
return -1
endi
sql select * from `!.!.!` where tbname = ".....";
if $rows != 4 then
return -1
endi
if $data00 != @21-09-22 10:10:13.000@ then
return -1
endi
if $data10 != @21-09-22 10:10:18.000@ then
return -1
endi
if $data20 != @21-09-22 10:10:19.000@ then
return -1
endi
if $data30 != @21-09-22 10:10:20.000@ then
return -1
endi
sql select * from `!.!.!` where tbname in (".....");
if $rows != 4 then
return -1
endi
if $data00 != @21-09-22 10:10:13.000@ then
return -1
endi
if $data10 != @21-09-22 10:10:18.000@ then
return -1
endi
if $data20 != @21-09-22 10:10:19.000@ then
return -1
endi
if $data30 != @21-09-22 10:10:20.000@ then
return -1
endi
sql select * from `!.!.!` where tbname like ".....";
if $rows != 4 then
return -1
endi
if $data00 != @21-09-22 10:10:13.000@ then
return -1
endi
if $data10 != @21-09-22 10:10:18.000@ then
return -1
endi
if $data20 != @21-09-22 10:10:19.000@ then
return -1
endi
if $data30 != @21-09-22 10:10:20.000@ then
return -1
endi
sql select * from `!.!.!` where tbname like "....%";
if $rows != 7 then
return -1
endi
if $data00 != @21-09-22 10:10:13.000@ then
return -1
endi
if $data10 != @21-09-22 10:10:18.000@ then
return -1
endi
if $data20 != @21-09-22 10:10:19.000@ then
return -1
endi
if $data30 != @21-09-22 10:10:20.000@ then
return -1
endi
if $data40 != @21-09-22 10:10:13.000@ then
return -1
endi
if $data50 != @21-09-22 10:10:14.000@ then
return -1
endi
if $data60 != @21-09-22 10:10:17.000@ then
return -1
endi
sql create table `select * from st1` (ts timestamp, f1 int);
sql create table `'"'"` (ts timestamp, f1 int);
sql create table `''""` using `!.!.!` tags (9);
sql SHOW CREATE TABLE `.....`;
sql SHOW CREATE TABLE dbesc.`.....`;
sql SHOW CREATE TABLE 'dbesc'.`.....`;
sql SHOW CREATE TABLE `!.!.!`;
sql SHOW CREATE TABLE `select * from st1`;
sql SHOW CREATE TABLE `'"'"`;
sql show create table `''""`;
sql_error SHOW CREATE STABLE `.....`;
sql SHOW CREATE STABLE `!.!.!`;
sql SHOW dbesc.TABLES LIKE '***';
if $rows != 0 then
return -1
endi
sql SHOW dbesc.STABLES LIKE '***';
if $rows != 1 then
return -1
endi
sql SHOW dbesc.TABLES LIKE '.....';
if $rows != 1 then
return -1
endi
sql SHOW dbesc.STABLES LIKE '.....';
if $rows != 0 then
return -1
endi
sql_error SHOW dbesc.TABLES LIKE `.....`;
sql_error SHOW dbesc.STABLES LIKE `***`;
sql show tables;
if $rows != 15 then
return -1
endi
sql_error drop table dbesc.'.....,,,1';
sql drop table dbesc.`.....,,,1`;
sql_error drop table dbesc.'.....,,';
sql drop table `.....,,`;
sql drop stable dbesc.'st1';
sql drop stable dbesc.`st2`;
sql drop stable dbesc.st3;
sql describe `.....`;
sql_error desc '.....';
sql_error ALTER TABLE `.....` ADD COLUMN f2 float;
sql ALTER TABLE `!.!.!` ADD COLUMN f2 float;
sql describe `!.!.!`;
if $rows != 4 then
return -1
endi
sql ALTER TABLE `!.!.!` DROP COLUMN f2;
sql_error ALTER TABLE `!.!.!` MODIFY COLUMN f2 int;
sql ALTER TABLE `!.!.!` ADD COLUMN f3 binary(10);
sql ALTER TABLE `!.!.!` MODIFY COLUMN f3 binary(11);
sql ALTER TABLE `!.!.!` ADD TAG t2 int;
sql ALTER TABLE `!.!.!` DROP TAG t2;
sql ALTER TABLE `!.!.!` ADD TAG ta binary(10);
sql ALTER TABLE `!.!.!` CHANGE TAG ta tb;
sql_error ALTER TABLE `!.!.!` SET TAG t1=99;
sql ALTER TABLE `.....` SET TAG t1=99;
sql ALTER TABLE `!.!.!` ADD TAG t3 binary(10);
sql ALTER TABLE `!.!.!` MODIFY TAG t3 binary(11);
sql ALTER STABLE `!.!.!` ADD COLUMN f4 binary(10);
sql ALTER STABLE `!.!.!` DROP COLUMN f4;
sql ALTER STABLE `!.!.!` ADD COLUMN f5 binary(10);
sql ALTER STABLE `!.!.!` MODIFY COLUMN f5 binary(12);
sql ALTER STABLE `!.!.!` ADD TAG t4 double;
sql ALTER STABLE `!.!.!` DROP TAG t4;
sql ALTER STABLE `!.!.!` ADD TAG t5 binary(1);
sql ALTER STABLE `!.!.!` CHANGE TAG t5 t6;
sql_error ALTER STABLE `!.!.!` SET TAG t6=999;
sql ALTER STABLE `!.!.!` MODIFY TAG t6 binary(12);
system sh/exec.sh -n dnode1 -s stop -x SIGINT
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录