Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
719cebdd
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
719cebdd
编写于
5月 31, 2022
作者:
D
dapan1121
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
stmt new api
上级
78bdcdd7
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
184 addition
and
18 deletion
+184
-18
include/client/taos.h
include/client/taos.h
+10
-0
include/libs/parser/parser.h
include/libs/parser/parser.h
+2
-2
source/client/inc/clientStmt.h
source/client/inc/clientStmt.h
+3
-0
source/client/src/clientMain.c
source/client/src/clientMain.c
+41
-0
source/client/src/clientStmt.c
source/client/src/clientStmt.c
+114
-7
source/libs/parser/src/parInsert.c
source/libs/parser/src/parInsert.c
+14
-9
未找到文件。
include/client/taos.h
浏览文件 @
719cebdd
...
...
@@ -85,6 +85,14 @@ typedef struct taosField {
int32_t
bytes
;
}
TAOS_FIELD
;
typedef
struct
TAOS_FIELD_E
{
char
name
[
65
];
int8_t
type
;
uint8_t
precision
;
uint8_t
scale
;
int32_t
bytes
;
}
TAOS_FIELD_E
;
#ifdef WINDOWS
#define DLL_EXPORT __declspec(dllexport)
#else
...
...
@@ -135,6 +143,8 @@ DLL_EXPORT int taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsign
DLL_EXPORT
int
taos_stmt_set_tbname_tags
(
TAOS_STMT
*
stmt
,
const
char
*
name
,
TAOS_MULTI_BIND
*
tags
);
DLL_EXPORT
int
taos_stmt_set_tbname
(
TAOS_STMT
*
stmt
,
const
char
*
name
);
DLL_EXPORT
int
taos_stmt_set_sub_tbname
(
TAOS_STMT
*
stmt
,
const
char
*
name
);
DLL_EXPORT
int
taos_stmt_get_tag_fields
(
TAOS_STMT
*
stmt
,
int
*
fieldNum
,
TAOS_FIELD_E
**
fields
);
DLL_EXPORT
int
taos_stmt_get_col_fields
(
TAOS_STMT
*
stmt
,
int
*
fieldNum
,
TAOS_FIELD_E
**
fields
);
DLL_EXPORT
int
taos_stmt_is_insert
(
TAOS_STMT
*
stmt
,
int
*
insert
);
DLL_EXPORT
int
taos_stmt_num_params
(
TAOS_STMT
*
stmt
,
int
*
nums
);
...
...
include/libs/parser/parser.h
浏览文件 @
719cebdd
...
...
@@ -77,8 +77,8 @@ int32_t qStmtParseQuerySql(SParseContext* pCxt, SQuery* pQuery);
int32_t
qBindStmtColsValue
(
void
*
pBlock
,
TAOS_MULTI_BIND
*
bind
,
char
*
msgBuf
,
int32_t
msgBufLen
);
int32_t
qBindStmtSingleColValue
(
void
*
pBlock
,
TAOS_MULTI_BIND
*
bind
,
char
*
msgBuf
,
int32_t
msgBufLen
,
int32_t
colIdx
,
int32_t
rowNum
);
int32_t
qBuildStmtColFields
(
void
*
pDataBlock
,
int32_t
*
fieldNum
,
TAOS_FIELD
**
fields
);
int32_t
qBuildStmtTagFields
(
void
*
pBlock
,
void
*
boundTags
,
int32_t
*
fieldNum
,
TAOS_FIELD
**
fields
);
int32_t
qBuildStmtColFields
(
void
*
pDataBlock
,
int32_t
*
fieldNum
,
TAOS_FIELD
_E
**
fields
);
int32_t
qBuildStmtTagFields
(
void
*
pBlock
,
void
*
boundTags
,
int32_t
*
fieldNum
,
TAOS_FIELD
_E
**
fields
);
int32_t
qBindStmtTagsValue
(
void
*
pBlock
,
void
*
boundTags
,
int64_t
suid
,
char
*
tName
,
TAOS_MULTI_BIND
*
bind
,
char
*
msgBuf
,
int32_t
msgBufLen
);
void
destroyBoundColumnInfo
(
void
*
pBoundInfo
);
...
...
source/client/inc/clientStmt.h
浏览文件 @
719cebdd
...
...
@@ -116,8 +116,11 @@ int stmtAffectedRowsOnce(TAOS_STMT *stmt);
int
stmtPrepare
(
TAOS_STMT
*
stmt
,
const
char
*
sql
,
unsigned
long
length
);
int
stmtSetTbName
(
TAOS_STMT
*
stmt
,
const
char
*
tbName
);
int
stmtSetTbTags
(
TAOS_STMT
*
stmt
,
TAOS_MULTI_BIND
*
tags
);
int
stmtGetTagFields
(
TAOS_STMT
*
stmt
,
int
*
nums
,
TAOS_FIELD_E
**
fields
);
int
stmtGetColFields
(
TAOS_STMT
*
stmt
,
int
*
nums
,
TAOS_FIELD_E
**
fields
);
int
stmtIsInsert
(
TAOS_STMT
*
stmt
,
int
*
insert
);
int
stmtGetParamNum
(
TAOS_STMT
*
stmt
,
int
*
nums
);
int
stmtGetParam
(
TAOS_STMT
*
stmt
,
int
idx
,
int
*
type
,
int
*
bytes
);
int
stmtAddBatch
(
TAOS_STMT
*
stmt
);
TAOS_RES
*
stmtUseResult
(
TAOS_STMT
*
stmt
);
int
stmtBindBatch
(
TAOS_STMT
*
stmt
,
TAOS_MULTI_BIND
*
bind
,
int32_t
colIdx
);
...
...
source/client/src/clientMain.c
浏览文件 @
719cebdd
...
...
@@ -666,8 +666,39 @@ int taos_stmt_set_tbname(TAOS_STMT *stmt, const char *name) {
return
stmtSetTbName
(
stmt
,
name
);
}
int
taos_stmt_set_tags
(
TAOS_STMT
*
stmt
,
TAOS_MULTI_BIND
*
tags
)
{
if
(
stmt
==
NULL
||
tags
==
NULL
)
{
tscError
(
"NULL parameter for %s"
,
__FUNCTION__
);
terrno
=
TSDB_CODE_INVALID_PARA
;
return
terrno
;
}
return
stmtSetTbTags
(
stmt
,
tags
);
}
int
taos_stmt_set_sub_tbname
(
TAOS_STMT
*
stmt
,
const
char
*
name
)
{
return
taos_stmt_set_tbname
(
stmt
,
name
);
}
int
taos_stmt_get_tag_fields
(
TAOS_STMT
*
stmt
,
int
*
fieldNum
,
TAOS_FIELD_E
**
fields
)
{
if
(
stmt
==
NULL
||
NULL
==
fieldNum
)
{
tscError
(
"NULL parameter for %s"
,
__FUNCTION__
);
terrno
=
TSDB_CODE_INVALID_PARA
;
return
terrno
;
}
return
stmtGetTagFields
(
stmt
,
fieldNum
,
fields
);
}
int
taos_stmt_get_col_fields
(
TAOS_STMT
*
stmt
,
int
*
fieldNum
,
TAOS_FIELD_E
**
fields
)
{
if
(
stmt
==
NULL
||
NULL
==
fieldNum
)
{
tscError
(
"NULL parameter for %s"
,
__FUNCTION__
);
terrno
=
TSDB_CODE_INVALID_PARA
;
return
terrno
;
}
return
stmtGetColFields
(
stmt
,
fieldNum
,
fields
);
}
int
taos_stmt_bind_param
(
TAOS_STMT
*
stmt
,
TAOS_MULTI_BIND
*
bind
)
{
if
(
stmt
==
NULL
||
bind
==
NULL
)
{
tscError
(
"NULL parameter for %s"
,
__FUNCTION__
);
...
...
@@ -772,6 +803,16 @@ int taos_stmt_num_params(TAOS_STMT *stmt, int *nums) {
return
stmtGetParamNum
(
stmt
,
nums
);
}
int
taos_stmt_get_param
(
TAOS_STMT
*
stmt
,
int
idx
,
int
*
type
,
int
*
bytes
)
{
if
(
stmt
==
NULL
||
type
==
NULL
||
NULL
==
bytes
||
idx
<
0
)
{
tscError
(
"invalid parameter for %s"
,
__FUNCTION__
);
terrno
=
TSDB_CODE_INVALID_PARA
;
return
terrno
;
}
return
stmtGetParam
(
stmt
,
idx
,
type
,
bytes
);
}
TAOS_RES
*
taos_stmt_use_result
(
TAOS_STMT
*
stmt
)
{
if
(
stmt
==
NULL
)
{
tscError
(
"NULL parameter for %s"
,
__FUNCTION__
);
...
...
source/client/src/clientStmt.c
浏览文件 @
719cebdd
...
...
@@ -17,7 +17,7 @@ int32_t stmtSwitchStatus(STscStmt* pStmt, STMT_STATUS newStatus) {
}
break
;
case
STMT_SETTAGS
:
if
(
STMT_STATUS_NE
(
SETTBNAME
))
{
if
(
STMT_STATUS_NE
(
SETTBNAME
)
&&
STMT_STATUS_NE
(
FETCH_FIELDS
)
)
{
code
=
TSDB_CODE_TSC_STMT_API_ERROR
;
}
break
;
...
...
@@ -540,6 +540,8 @@ int stmtSetTbName(TAOS_STMT* stmt, const char* tbName) {
if
(
pStmt
->
bInfo
.
needParse
)
{
strncpy
(
pStmt
->
bInfo
.
tbName
,
tbName
,
sizeof
(
pStmt
->
bInfo
.
tbName
)
-
1
);
pStmt
->
bInfo
.
tbName
[
sizeof
(
pStmt
->
bInfo
.
tbName
)
-
1
]
=
0
;
STMT_ERR_RET
(
stmtParseSql
(
pStmt
));
}
return
TSDB_CODE_SUCCESS
;
...
...
@@ -550,10 +552,6 @@ int stmtSetTbTags(TAOS_STMT* stmt, TAOS_MULTI_BIND* tags) {
STMT_ERR_RET
(
stmtSwitchStatus
(
pStmt
,
STMT_SETTAGS
));
if
(
pStmt
->
bInfo
.
needParse
)
{
STMT_ERR_RET
(
stmtParseSql
(
pStmt
));
}
if
(
pStmt
->
bInfo
.
inExecCache
)
{
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -571,7 +569,7 @@ int stmtSetTbTags(TAOS_STMT* stmt, TAOS_MULTI_BIND* tags) {
return
TSDB_CODE_SUCCESS
;
}
int
32_t
stmtFetchTagFields
(
STscStmt
*
pStmt
,
int32_t
*
fieldNum
,
TAOS_FIELD
**
fields
)
{
int
stmtFetchTagFields
(
STscStmt
*
pStmt
,
int32_t
*
fieldNum
,
TAOS_FIELD_E
**
fields
)
{
if
(
STMT_TYPE_QUERY
==
pStmt
->
sql
.
type
)
{
tscError
(
"invalid operation to get query tag fileds"
);
STMT_ERR_RET
(
TSDB_CODE_TSC_STMT_API_ERROR
);
...
...
@@ -589,7 +587,7 @@ int32_t stmtFetchTagFields(STscStmt* pStmt, int32_t* fieldNum, TAOS_FIELD** fiel
return
TSDB_CODE_SUCCESS
;
}
int
32_t
stmtFetchColFields
(
STscStmt
*
pStmt
,
int32_t
*
fieldNum
,
TAOS_FIELD
**
fields
)
{
int
stmtFetchColFields
(
STscStmt
*
pStmt
,
int32_t
*
fieldNum
,
TAOS_FIELD_E
**
fields
)
{
if
(
STMT_TYPE_QUERY
==
pStmt
->
sql
.
type
)
{
tscError
(
"invalid operation to get query column fileds"
);
STMT_ERR_RET
(
TSDB_CODE_TSC_STMT_API_ERROR
);
...
...
@@ -852,6 +850,71 @@ int stmtIsInsert(TAOS_STMT* stmt, int* insert) {
return
TSDB_CODE_SUCCESS
;
}
int
stmtGetTagFields
(
TAOS_STMT
*
stmt
,
int
*
nums
,
TAOS_FIELD_E
**
fields
)
{
STscStmt
*
pStmt
=
(
STscStmt
*
)
stmt
;
if
(
STMT_TYPE_QUERY
==
pStmt
->
sql
.
type
)
{
STMT_RET
(
TSDB_CODE_TSC_STMT_API_ERROR
);
}
STMT_ERR_RET
(
stmtSwitchStatus
(
pStmt
,
STMT_FETCH_FIELDS
));
if
(
pStmt
->
bInfo
.
needParse
&&
pStmt
->
sql
.
runTimes
&&
pStmt
->
sql
.
type
>
0
&&
STMT_TYPE_MULTI_INSERT
!=
pStmt
->
sql
.
type
)
{
pStmt
->
bInfo
.
needParse
=
false
;
}
if
(
pStmt
->
exec
.
pRequest
&&
STMT_TYPE_QUERY
==
pStmt
->
sql
.
type
&&
pStmt
->
sql
.
runTimes
)
{
taos_free_result
(
pStmt
->
exec
.
pRequest
);
pStmt
->
exec
.
pRequest
=
NULL
;
}
if
(
NULL
==
pStmt
->
exec
.
pRequest
)
{
STMT_ERR_RET
(
buildRequest
(
pStmt
->
taos
,
pStmt
->
sql
.
sqlStr
,
pStmt
->
sql
.
sqlLen
,
&
pStmt
->
exec
.
pRequest
));
}
if
(
pStmt
->
bInfo
.
needParse
)
{
STMT_ERR_RET
(
stmtParseSql
(
pStmt
));
}
STMT_ERR_RET
(
stmtFetchTagFields
(
stmt
,
nums
,
fields
));
return
TSDB_CODE_SUCCESS
;
}
int
stmtGetColFields
(
TAOS_STMT
*
stmt
,
int
*
nums
,
TAOS_FIELD_E
**
fields
)
{
STscStmt
*
pStmt
=
(
STscStmt
*
)
stmt
;
if
(
STMT_TYPE_QUERY
==
pStmt
->
sql
.
type
)
{
STMT_RET
(
TSDB_CODE_TSC_STMT_API_ERROR
);
}
STMT_ERR_RET
(
stmtSwitchStatus
(
pStmt
,
STMT_FETCH_FIELDS
));
if
(
pStmt
->
bInfo
.
needParse
&&
pStmt
->
sql
.
runTimes
&&
pStmt
->
sql
.
type
>
0
&&
STMT_TYPE_MULTI_INSERT
!=
pStmt
->
sql
.
type
)
{
pStmt
->
bInfo
.
needParse
=
false
;
}
if
(
pStmt
->
exec
.
pRequest
&&
STMT_TYPE_QUERY
==
pStmt
->
sql
.
type
&&
pStmt
->
sql
.
runTimes
)
{
taos_free_result
(
pStmt
->
exec
.
pRequest
);
pStmt
->
exec
.
pRequest
=
NULL
;
}
if
(
NULL
==
pStmt
->
exec
.
pRequest
)
{
STMT_ERR_RET
(
buildRequest
(
pStmt
->
taos
,
pStmt
->
sql
.
sqlStr
,
pStmt
->
sql
.
sqlLen
,
&
pStmt
->
exec
.
pRequest
));
}
if
(
pStmt
->
bInfo
.
needParse
)
{
STMT_ERR_RET
(
stmtParseSql
(
pStmt
));
}
STMT_ERR_RET
(
stmtFetchColFields
(
stmt
,
nums
,
fields
));
return
TSDB_CODE_SUCCESS
;
}
int
stmtGetParamNum
(
TAOS_STMT
*
stmt
,
int
*
nums
)
{
STscStmt
*
pStmt
=
(
STscStmt
*
)
stmt
;
...
...
@@ -884,6 +947,50 @@ int stmtGetParamNum(TAOS_STMT* stmt, int* nums) {
return
TSDB_CODE_SUCCESS
;
}
int
stmtGetParam
(
TAOS_STMT
*
stmt
,
int
idx
,
int
*
type
,
int
*
bytes
)
{
STscStmt
*
pStmt
=
(
STscStmt
*
)
stmt
;
if
(
STMT_TYPE_QUERY
==
pStmt
->
sql
.
type
)
{
STMT_RET
(
TSDB_CODE_TSC_STMT_API_ERROR
);
}
STMT_ERR_RET
(
stmtSwitchStatus
(
pStmt
,
STMT_FETCH_FIELDS
));
if
(
pStmt
->
bInfo
.
needParse
&&
pStmt
->
sql
.
runTimes
&&
pStmt
->
sql
.
type
>
0
&&
STMT_TYPE_MULTI_INSERT
!=
pStmt
->
sql
.
type
)
{
pStmt
->
bInfo
.
needParse
=
false
;
}
if
(
pStmt
->
exec
.
pRequest
&&
STMT_TYPE_QUERY
==
pStmt
->
sql
.
type
&&
pStmt
->
sql
.
runTimes
)
{
taos_free_result
(
pStmt
->
exec
.
pRequest
);
pStmt
->
exec
.
pRequest
=
NULL
;
}
if
(
NULL
==
pStmt
->
exec
.
pRequest
)
{
STMT_ERR_RET
(
buildRequest
(
pStmt
->
taos
,
pStmt
->
sql
.
sqlStr
,
pStmt
->
sql
.
sqlLen
,
&
pStmt
->
exec
.
pRequest
));
}
if
(
pStmt
->
bInfo
.
needParse
)
{
STMT_ERR_RET
(
stmtParseSql
(
pStmt
));
}
int32_t
nums
=
0
;
TAOS_FIELD_E
*
pField
=
NULL
;
STMT_ERR_RET
(
stmtFetchColFields
(
stmt
,
&
nums
,
&
pField
));
if
(
idx
>=
nums
)
{
tscError
(
"idx %d is too big"
,
idx
);
taosMemoryFree
(
pField
);
STMT_ERR_RET
(
TSDB_CODE_INVALID_PARA
);
}
*
type
=
pField
[
idx
].
type
;
*
bytes
=
pField
[
idx
].
bytes
;
taosMemoryFree
(
pField
);
return
TSDB_CODE_SUCCESS
;
}
TAOS_RES
*
stmtUseResult
(
TAOS_STMT
*
stmt
)
{
STscStmt
*
pStmt
=
(
STscStmt
*
)
stmt
;
...
...
source/libs/parser/src/parInsert.c
浏览文件 @
719cebdd
...
...
@@ -1724,18 +1724,23 @@ int32_t qBindStmtSingleColValue(void* pBlock, TAOS_MULTI_BIND* bind, char* msgBu
return
TSDB_CODE_SUCCESS
;
}
int32_t
buildBoundFields
(
SParsedDataColInfo
*
boundInfo
,
SSchema
*
pSchema
,
int32_t
*
fieldNum
,
TAOS_FIELD
**
fields
)
{
int32_t
buildBoundFields
(
SParsedDataColInfo
*
boundInfo
,
SSchema
*
pSchema
,
int32_t
*
fieldNum
,
TAOS_FIELD
_E
**
fields
,
uint8_t
timePrec
)
{
if
(
fields
)
{
*
fields
=
taosMemoryCalloc
(
boundInfo
->
numOfBound
,
sizeof
(
TAOS_FIELD
));
if
(
NULL
==
*
fields
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
SSchema
*
pSchema
=
&
pSchema
[
boundInfo
->
boundColumns
[
0
]];
if
(
TSDB_DATA_TYPE_TIMESTAMP
==
pSchema
->
type
)
{
(
*
fields
)[
0
].
precision
=
timePrec
;
}
for
(
int32_t
i
=
0
;
i
<
boundInfo
->
numOfBound
;
++
i
)
{
SSchema
*
p
Tag
Schema
=
&
pSchema
[
boundInfo
->
boundColumns
[
i
]];
strcpy
((
*
fields
)[
i
].
name
,
p
Tag
Schema
->
name
);
(
*
fields
)[
i
].
type
=
p
Tag
Schema
->
type
;
(
*
fields
)[
i
].
bytes
=
p
Tag
Schema
->
bytes
;
SSchema
*
pSchema
=
&
pSchema
[
boundInfo
->
boundColumns
[
i
]];
strcpy
((
*
fields
)[
i
].
name
,
pSchema
->
name
);
(
*
fields
)[
i
].
type
=
pSchema
->
type
;
(
*
fields
)[
i
].
bytes
=
pSchema
->
bytes
;
}
}
...
...
@@ -1744,7 +1749,7 @@ int32_t buildBoundFields(SParsedDataColInfo* boundInfo, SSchema* pSchema, int32_
return
TSDB_CODE_SUCCESS
;
}
int32_t
qBuildStmtTagFields
(
void
*
pBlock
,
void
*
boundTags
,
int32_t
*
fieldNum
,
TAOS_FIELD
**
fields
)
{
int32_t
qBuildStmtTagFields
(
void
*
pBlock
,
void
*
boundTags
,
int32_t
*
fieldNum
,
TAOS_FIELD
_E
**
fields
)
{
STableDataBlocks
*
pDataBlock
=
(
STableDataBlocks
*
)
pBlock
;
SParsedDataColInfo
*
tags
=
(
SParsedDataColInfo
*
)
boundTags
;
if
(
NULL
==
tags
)
{
...
...
@@ -1759,12 +1764,12 @@ int32_t qBuildStmtTagFields(void* pBlock, void* boundTags, int32_t* fieldNum, TA
return
TSDB_CODE_SUCCESS
;
}
CHECK_CODE
(
buildBoundFields
(
tags
,
pSchema
,
fieldNum
,
fields
));
CHECK_CODE
(
buildBoundFields
(
tags
,
pSchema
,
fieldNum
,
fields
,
0
));
return
TSDB_CODE_SUCCESS
;
}
int32_t
qBuildStmtColFields
(
void
*
pBlock
,
int32_t
*
fieldNum
,
TAOS_FIELD
**
fields
)
{
int32_t
qBuildStmtColFields
(
void
*
pBlock
,
int32_t
*
fieldNum
,
TAOS_FIELD
_E
**
fields
)
{
STableDataBlocks
*
pDataBlock
=
(
STableDataBlocks
*
)
pBlock
;
SSchema
*
pSchema
=
getTableColumnSchema
(
pDataBlock
->
pTableMeta
);
if
(
pDataBlock
->
boundColumnInfo
.
numOfBound
<=
0
)
{
...
...
@@ -1776,7 +1781,7 @@ int32_t qBuildStmtColFields(void* pBlock, int32_t* fieldNum, TAOS_FIELD** fields
return
TSDB_CODE_SUCCESS
;
}
CHECK_CODE
(
buildBoundFields
(
&
pDataBlock
->
boundColumnInfo
,
pSchema
,
fieldNum
,
fields
));
CHECK_CODE
(
buildBoundFields
(
&
pDataBlock
->
boundColumnInfo
,
pSchema
,
fieldNum
,
fields
,
pDataBlock
->
pTableMeta
->
tableInfo
.
precision
));
return
TSDB_CODE_SUCCESS
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录