Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
718bf8d9
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
718bf8d9
编写于
6月 05, 2021
作者:
D
dapan1121
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support error msg
上级
5e40ac37
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
580 addition
and
75 deletion
+580
-75
src/client/src/tscPrepare.c
src/client/src/tscPrepare.c
+87
-71
src/inc/taos.h
src/inc/taos.h
+1
-0
tests/script/api/batchprepare.c
tests/script/api/batchprepare.c
+492
-4
未找到文件。
src/client/src/tscPrepare.c
浏览文件 @
718bf8d9
...
...
@@ -78,6 +78,16 @@ typedef struct STscStmt {
SNormalStmt
normal
;
}
STscStmt
;
#define STMT_RET(c) do { \
int32_t _code = c; \
if (pStmt && pStmt->pSql) { pStmt->pSql->res.code = _code; } else {terrno = _code;} \
return _code; \
} while (0)
static
int32_t
invalidOperationMsg
(
char
*
dstBuffer
,
const
char
*
errMsg
)
{
return
tscInvalidOperationMsg
(
dstBuffer
,
errMsg
,
NULL
);
}
static
int
normalStmtAddPart
(
SNormalStmt
*
stmt
,
bool
isParam
,
char
*
str
,
uint32_t
len
)
{
uint16_t
size
=
stmt
->
numParts
+
1
;
if
(
size
>
stmt
->
sizeParts
)
{
...
...
@@ -1401,13 +1411,15 @@ int stmtGenInsertStatement(SSqlObj* pSql, STscStmt* pStmt, const char* name, TAO
TAOS_STMT
*
taos_stmt_init
(
TAOS
*
taos
)
{
STscObj
*
pObj
=
(
STscObj
*
)
taos
;
STscStmt
*
pStmt
=
NULL
;
if
(
pObj
==
NULL
||
pObj
->
signature
!=
pObj
)
{
terrno
=
TSDB_CODE_TSC_DISCONNECTED
;
tscError
(
"connection disconnected"
);
return
NULL
;
}
STscStmt
*
pStmt
=
calloc
(
1
,
sizeof
(
STscStmt
));
pStmt
=
calloc
(
1
,
sizeof
(
STscStmt
));
if
(
pStmt
==
NULL
)
{
terrno
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
tscError
(
"failed to allocate memory for statement"
);
...
...
@@ -1425,8 +1437,11 @@ TAOS_STMT* taos_stmt_init(TAOS* taos) {
}
if
(
TSDB_CODE_SUCCESS
!=
tscAllocPayload
(
&
pSql
->
cmd
,
TSDB_DEFAULT_PAYLOAD_SIZE
))
{
tscError
(
"%p failed to malloc payload buffer"
,
pSql
);
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
free
(
pSql
);
free
(
pStmt
);
terrno
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
tscError
(
"failed to malloc payload buffer"
);
return
NULL
;
}
tsem_init
(
&
pSql
->
rspSem
,
0
,
0
);
...
...
@@ -1444,13 +1459,12 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) {
STscStmt
*
pStmt
=
(
STscStmt
*
)
stmt
;
if
(
stmt
==
NULL
||
pStmt
->
taos
==
NULL
||
pStmt
->
pSql
==
NULL
)
{
terrno
=
TSDB_CODE_TSC_DISCONNECTED
;
return
TSDB_CODE_TSC_DISCONNECTED
;
STMT_RET
(
TSDB_CODE_TSC_DISCONNECTED
);
}
if
(
pStmt
->
last
!=
STMT_INIT
)
{
tscError
(
"prepare status error, last:%d"
,
pStmt
->
last
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
"prepare status error"
);
STMT_RET
(
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"prepare status error"
)
);
}
pStmt
->
last
=
STMT_PREPARE
;
...
...
@@ -1470,8 +1484,7 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) {
if
(
pSql
->
sqlstr
==
NULL
)
{
tscError
(
"%p failed to malloc sql string buffer"
,
pSql
);
free
(
pCmd
->
payload
);
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
STMT_RET
(
TSDB_CODE_TSC_OUT_OF_MEMORY
);
}
pRes
->
qId
=
0
;
...
...
@@ -1490,11 +1503,11 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) {
int32_t
ret
=
stmtParseInsertTbTags
(
pSql
,
pStmt
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
STMT_RET
(
ret
)
;
}
if
(
pStmt
->
multiTbInsert
)
{
return
TSDB_CODE_SUCCESS
;
STMT_RET
(
TSDB_CODE_SUCCESS
)
;
}
memset
(
&
pStmt
->
mtb
,
0
,
sizeof
(
pStmt
->
mtb
));
...
...
@@ -1503,15 +1516,14 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) {
if
(
code
==
TSDB_CODE_TSC_ACTION_IN_PROGRESS
)
{
// wait for the callback function to post the semaphore
tsem_wait
(
&
pSql
->
rspSem
);
pSql
->
res
.
code
=
code
;
return
pSql
->
res
.
code
;
STMT_RET
(
pSql
->
res
.
code
);
}
return
code
;
STMT_RET
(
code
)
;
}
pStmt
->
isInsert
=
false
;
return
normalStmtPrepare
(
pStmt
);
STMT_RET
(
normalStmtPrepare
(
pStmt
)
);
}
int
taos_stmt_set_tbname_tags
(
TAOS_STMT
*
stmt
,
const
char
*
name
,
TAOS_BIND
*
tags
)
{
...
...
@@ -1520,23 +1532,22 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
if
(
stmt
==
NULL
||
pStmt
->
pSql
==
NULL
||
pStmt
->
taos
==
NULL
)
{
terrno
=
TSDB_CODE_TSC_DISCONNECTED
;
return
TSDB_CODE_TSC_DISCONNECTED
;
STMT_RET
(
TSDB_CODE_TSC_DISCONNECTED
);
}
if
(
name
==
NULL
)
{
tscError
(
"0x%"
PRIx64
" name is NULL"
,
pSql
->
self
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"name is NULL"
);
STMT_RET
(
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"name is NULL"
)
);
}
if
(
pStmt
->
multiTbInsert
==
false
||
!
tscIsInsertData
(
pSql
->
sqlstr
))
{
tscError
(
"0x%"
PRIx64
" not multiple table insert"
,
pSql
->
self
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"not multiple table insert"
);
STMT_RET
(
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"not multiple table insert"
)
);
}
if
(
pStmt
->
last
==
STMT_INIT
||
pStmt
->
last
==
STMT_BIND
||
pStmt
->
last
==
STMT_BIND_COL
)
{
tscError
(
"0x%"
PRIx64
" set_tbname_tags status error, last:%d"
,
pSql
->
self
,
pStmt
->
last
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"set_tbname_tags status error"
);
STMT_RET
(
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"set_tbname_tags status error"
)
);
}
pStmt
->
last
=
STMT_SETTBNAME
;
...
...
@@ -1548,7 +1559,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
);
return
TSDB_CODE_TSC_APP_ERROR
;
STMT_RET
(
TSDB_CODE_TSC_APP_ERROR
)
;
}
SSubmitBlk
*
pBlk
=
(
SSubmitBlk
*
)
(
*
t1
)
->
pData
;
...
...
@@ -1557,7 +1568,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
);
return
TSDB_CODE_SUCCESS
;
STMT_RET
(
TSDB_CODE_SUCCESS
)
;
}
if
(
pStmt
->
mtb
.
tagSet
)
{
...
...
@@ -1565,12 +1576,12 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags
}
else
{
if
(
tags
==
NULL
)
{
tscError
(
"No tags set"
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"no tags set"
);
STMT_RET
(
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"no tags set"
)
);
}
int32_t
ret
=
stmtGenInsertStatement
(
pSql
,
pStmt
,
name
,
tags
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
STMT_RET
(
ret
)
;
}
}
...
...
@@ -1604,7 +1615,7 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags
code
=
tscGetDataBlockFromList
(
pCmd
->
insertParam
.
pTableBlockHashList
,
pTableMeta
->
id
.
uid
,
TSDB_PAYLOAD_SIZE
,
sizeof
(
SSubmitBlk
),
pTableMeta
->
tableInfo
.
rowSize
,
&
pTableMetaInfo
->
name
,
pTableMeta
,
&
pBlock
,
NULL
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
STMT_RET
(
code
)
;
}
SSubmitBlk
*
blk
=
(
SSubmitBlk
*
)
pBlock
->
pData
;
...
...
@@ -1619,7 +1630,7 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags
tscDebug
(
"0x%"
PRIx64
" table:%s is prepared, uid:%"
PRIx64
,
pSql
->
self
,
name
,
pStmt
->
mtb
.
currentUid
);
}
return
code
;
STMT_RET
(
code
)
;
}
...
...
@@ -1652,35 +1663,34 @@ int taos_stmt_close(TAOS_STMT* stmt) {
}
taos_free_result
(
pStmt
->
pSql
);
free
(
pStmt
);
return
TSDB_CODE_SUCCESS
;
t
free
(
pStmt
);
STMT_RET
(
TSDB_CODE_SUCCESS
)
;
}
int
taos_stmt_bind_param
(
TAOS_STMT
*
stmt
,
TAOS_BIND
*
bind
)
{
STscStmt
*
pStmt
=
(
STscStmt
*
)
stmt
;
if
(
stmt
==
NULL
||
pStmt
->
pSql
==
NULL
||
pStmt
->
taos
==
NULL
)
{
terrno
=
TSDB_CODE_TSC_DISCONNECTED
;
return
TSDB_CODE_TSC_DISCONNECTED
;
STMT_RET
(
TSDB_CODE_TSC_DISCONNECTED
);
}
if
(
pStmt
->
isInsert
)
{
if
(
pStmt
->
multiTbInsert
)
{
if
(
pStmt
->
last
!=
STMT_SETTBNAME
&&
pStmt
->
last
!=
STMT_ADD_BATCH
)
{
tscError
(
"0x%"
PRIx64
" bind param status error, last:%d"
,
pStmt
->
pSql
->
self
,
pStmt
->
last
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"bind param status error"
);
STMT_RET
(
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"bind param status error"
)
);
}
}
else
{
if
(
pStmt
->
last
!=
STMT_PREPARE
&&
pStmt
->
last
!=
STMT_ADD_BATCH
&&
pStmt
->
last
!=
STMT_EXECUTE
)
{
tscError
(
"0x%"
PRIx64
" bind param status error, last:%d"
,
pStmt
->
pSql
->
self
,
pStmt
->
last
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"bind param status error"
);
STMT_RET
(
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"bind param status error"
)
);
}
}
pStmt
->
last
=
STMT_BIND
;
return
insertStmtBindParam
(
pStmt
,
bind
);
STMT_RET
(
insertStmtBindParam
(
pStmt
,
bind
)
);
}
else
{
return
normalStmtBindParam
(
pStmt
,
bind
);
STMT_RET
(
normalStmtBindParam
(
pStmt
,
bind
)
);
}
}
...
...
@@ -1689,69 +1699,67 @@ int taos_stmt_bind_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind) {
STscStmt
*
pStmt
=
(
STscStmt
*
)
stmt
;
if
(
stmt
==
NULL
||
pStmt
->
pSql
==
NULL
||
pStmt
->
taos
==
NULL
)
{
terrno
=
TSDB_CODE_TSC_DISCONNECTED
;
return
TSDB_CODE_TSC_DISCONNECTED
;
STMT_RET
(
TSDB_CODE_TSC_DISCONNECTED
);
}
if
(
bind
==
NULL
||
bind
->
num
<=
0
||
bind
->
num
>
INT16_MAX
)
{
tscError
(
"0x%"
PRIx64
" invalid parameter"
,
pStmt
->
pSql
->
self
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"invalid bind param"
);
STMT_RET
(
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"invalid bind param"
)
);
}
if
(
!
pStmt
->
isInsert
)
{
tscError
(
"0x%"
PRIx64
" not or invalid batch insert"
,
pStmt
->
pSql
->
self
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"not or invalid batch insert"
);
STMT_RET
(
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"not or invalid batch insert"
)
);
}
if
(
pStmt
->
multiTbInsert
)
{
if
(
pStmt
->
last
!=
STMT_SETTBNAME
&&
pStmt
->
last
!=
STMT_ADD_BATCH
)
{
tscError
(
"0x%"
PRIx64
" bind param status error, last:%d"
,
pStmt
->
pSql
->
self
,
pStmt
->
last
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"bind param status error"
);
STMT_RET
(
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"bind param status error"
)
);
}
}
else
{
if
(
pStmt
->
last
!=
STMT_PREPARE
&&
pStmt
->
last
!=
STMT_ADD_BATCH
&&
pStmt
->
last
!=
STMT_EXECUTE
)
{
tscError
(
"0x%"
PRIx64
" bind param status error, last:%d"
,
pStmt
->
pSql
->
self
,
pStmt
->
last
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"bind param status error"
);
STMT_RET
(
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"bind param status error"
)
);
}
}
pStmt
->
last
=
STMT_BIND
;
return
insertStmtBindParamBatch
(
pStmt
,
bind
,
-
1
);
STMT_RET
(
insertStmtBindParamBatch
(
pStmt
,
bind
,
-
1
)
);
}
int
taos_stmt_bind_single_param_batch
(
TAOS_STMT
*
stmt
,
TAOS_MULTI_BIND
*
bind
,
int
colIdx
)
{
STscStmt
*
pStmt
=
(
STscStmt
*
)
stmt
;
if
(
stmt
==
NULL
||
pStmt
->
pSql
==
NULL
||
pStmt
->
taos
==
NULL
)
{
terrno
=
TSDB_CODE_TSC_DISCONNECTED
;
return
TSDB_CODE_TSC_DISCONNECTED
;
STMT_RET
(
TSDB_CODE_TSC_DISCONNECTED
);
}
if
(
bind
==
NULL
||
bind
->
num
<=
0
||
bind
->
num
>
INT16_MAX
)
{
tscError
(
"0x%"
PRIx64
" invalid parameter"
,
pStmt
->
pSql
->
self
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"invalid bind param"
);
STMT_RET
(
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"invalid bind param"
)
);
}
if
(
!
pStmt
->
isInsert
)
{
tscError
(
"0x%"
PRIx64
" not or invalid batch insert"
,
pStmt
->
pSql
->
self
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"not or invalid batch insert"
);
STMT_RET
(
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"not or invalid batch insert"
)
);
}
if
(
pStmt
->
multiTbInsert
)
{
if
(
pStmt
->
last
!=
STMT_SETTBNAME
&&
pStmt
->
last
!=
STMT_ADD_BATCH
&&
pStmt
->
last
!=
STMT_BIND_COL
)
{
tscError
(
"0x%"
PRIx64
" bind param status error, last:%d"
,
pStmt
->
pSql
->
self
,
pStmt
->
last
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"bind param status error"
);
STMT_RET
(
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"bind param status error"
)
);
}
}
else
{
if
(
pStmt
->
last
!=
STMT_PREPARE
&&
pStmt
->
last
!=
STMT_ADD_BATCH
&&
pStmt
->
last
!=
STMT_BIND_COL
&&
pStmt
->
last
!=
STMT_EXECUTE
)
{
tscError
(
"0x%"
PRIx64
" bind param status error, last:%d"
,
pStmt
->
pSql
->
self
,
pStmt
->
last
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"bind param status error"
);
STMT_RET
(
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"bind param status error"
)
);
}
}
pStmt
->
last
=
STMT_BIND_COL
;
return
insertStmtBindParamBatch
(
pStmt
,
bind
,
colIdx
);
STMT_RET
(
insertStmtBindParamBatch
(
pStmt
,
bind
,
colIdx
)
);
}
...
...
@@ -1759,44 +1767,42 @@ int taos_stmt_bind_single_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind, in
int
taos_stmt_add_batch
(
TAOS_STMT
*
stmt
)
{
STscStmt
*
pStmt
=
(
STscStmt
*
)
stmt
;
if
(
stmt
==
NULL
||
pStmt
->
pSql
==
NULL
||
pStmt
->
taos
==
NULL
)
{
terrno
=
TSDB_CODE_TSC_DISCONNECTED
;
return
TSDB_CODE_TSC_DISCONNECTED
;
STMT_RET
(
TSDB_CODE_TSC_DISCONNECTED
);
}
if
(
pStmt
->
isInsert
)
{
if
(
pStmt
->
last
!=
STMT_BIND
&&
pStmt
->
last
!=
STMT_BIND_COL
)
{
tscError
(
"0x%"
PRIx64
" add batch status error, last:%d"
,
pStmt
->
pSql
->
self
,
pStmt
->
last
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"add batch status error"
);
STMT_RET
(
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"add batch status error"
)
);
}
pStmt
->
last
=
STMT_ADD_BATCH
;
return
insertStmtAddBatch
(
pStmt
);
STMT_RET
(
insertStmtAddBatch
(
pStmt
)
);
}
return
TSDB_CODE_COM_OPS_NOT_SUPPORT
;
STMT_RET
(
TSDB_CODE_COM_OPS_NOT_SUPPORT
)
;
}
int
taos_stmt_reset
(
TAOS_STMT
*
stmt
)
{
STscStmt
*
pStmt
=
(
STscStmt
*
)
stmt
;
if
(
pStmt
->
isInsert
)
{
return
insertStmtReset
(
pStmt
);
STMT_RET
(
insertStmtReset
(
pStmt
)
);
}
return
TSDB_CODE_SUCCESS
;
STMT_RET
(
TSDB_CODE_SUCCESS
)
;
}
int
taos_stmt_execute
(
TAOS_STMT
*
stmt
)
{
int
ret
=
0
;
STscStmt
*
pStmt
=
(
STscStmt
*
)
stmt
;
if
(
stmt
==
NULL
||
pStmt
->
pSql
==
NULL
||
pStmt
->
taos
==
NULL
)
{
terrno
=
TSDB_CODE_TSC_DISCONNECTED
;
return
TSDB_CODE_TSC_DISCONNECTED
;
STMT_RET
(
TSDB_CODE_TSC_DISCONNECTED
);
}
if
(
pStmt
->
isInsert
)
{
if
(
pStmt
->
last
!=
STMT_ADD_BATCH
)
{
tscError
(
"0x%"
PRIx64
" exec status error, last:%d"
,
pStmt
->
pSql
->
self
,
pStmt
->
last
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"exec status error"
);
STMT_RET
(
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"exec status error"
)
);
}
pStmt
->
last
=
STMT_EXECUTE
;
...
...
@@ -1822,7 +1828,7 @@ int taos_stmt_execute(TAOS_STMT* stmt) {
}
}
return
ret
;
STMT_RET
(
ret
)
;
}
TAOS_RES
*
taos_stmt_use_result
(
TAOS_STMT
*
stmt
)
{
...
...
@@ -1846,32 +1852,30 @@ int taos_stmt_is_insert(TAOS_STMT *stmt, int *insert) {
STscStmt
*
pStmt
=
(
STscStmt
*
)
stmt
;
if
(
stmt
==
NULL
||
pStmt
->
taos
==
NULL
||
pStmt
->
pSql
==
NULL
)
{
terrno
=
TSDB_CODE_TSC_DISCONNECTED
;
return
TSDB_CODE_TSC_DISCONNECTED
;
STMT_RET
(
TSDB_CODE_TSC_DISCONNECTED
);
}
if
(
insert
)
*
insert
=
pStmt
->
isInsert
;
return
TSDB_CODE_SUCCESS
;
STMT_RET
(
TSDB_CODE_SUCCESS
)
;
}
int
taos_stmt_num_params
(
TAOS_STMT
*
stmt
,
int
*
nums
)
{
STscStmt
*
pStmt
=
(
STscStmt
*
)
stmt
;
if
(
stmt
==
NULL
||
pStmt
->
taos
==
NULL
||
pStmt
->
pSql
==
NULL
)
{
terrno
=
TSDB_CODE_TSC_DISCONNECTED
;
return
TSDB_CODE_TSC_DISCONNECTED
;
STMT_RET
(
TSDB_CODE_TSC_DISCONNECTED
);
}
if
(
pStmt
->
isInsert
)
{
SSqlObj
*
pSql
=
pStmt
->
pSql
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
*
nums
=
pCmd
->
insertParam
.
numOfParams
;
return
TSDB_CODE_SUCCESS
;
STMT_RET
(
TSDB_CODE_SUCCESS
)
;
}
else
{
SNormalStmt
*
normal
=
&
pStmt
->
normal
;
*
nums
=
normal
->
numParams
;
return
TSDB_CODE_SUCCESS
;
STMT_RET
(
TSDB_CODE_SUCCESS
)
;
}
}
...
...
@@ -1879,8 +1883,7 @@ int taos_stmt_get_param(TAOS_STMT *stmt, int idx, int *type, int *bytes) {
STscStmt
*
pStmt
=
(
STscStmt
*
)
stmt
;
if
(
stmt
==
NULL
||
pStmt
->
taos
==
NULL
||
pStmt
->
pSql
==
NULL
)
{
terrno
=
TSDB_CODE_TSC_DISCONNECTED
;
return
TSDB_CODE_TSC_DISCONNECTED
;
STMT_RET
(
TSDB_CODE_TSC_DISCONNECTED
);
}
if
(
pStmt
->
isInsert
)
{
...
...
@@ -1897,24 +1900,37 @@ int taos_stmt_get_param(TAOS_STMT *stmt, int idx, int *type, int *bytes) {
tscGetDataBlockFromList
(
pCmd
->
insertParam
.
pTableBlockHashList
,
pTableMeta
->
id
.
uid
,
TSDB_PAYLOAD_SIZE
,
sizeof
(
SSubmitBlk
),
pTableMeta
->
tableInfo
.
rowSize
,
&
pTableMetaInfo
->
name
,
pTableMeta
,
&
pBlock
,
NULL
);
if
(
ret
!=
0
)
{
// todo handle error
STMT_RET
(
ret
);
}
if
(
idx
<
0
||
idx
>=
pBlock
->
numOfParams
)
{
tscError
(
"0x%"
PRIx64
" param %d: out of range"
,
pStmt
->
pSql
->
self
,
idx
);
abort
(
);
STMT_RET
(
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pStmt
->
pSql
->
cmd
),
"idx out of range"
)
);
}
SParamInfo
*
param
=
&
pBlock
->
params
[
idx
];
if
(
type
)
*
type
=
param
->
type
;
if
(
bytes
)
*
bytes
=
param
->
bytes
;
return
TSDB_CODE_SUCCESS
;
STMT_RET
(
TSDB_CODE_SUCCESS
)
;
}
else
{
return
TSDB_CODE_TSC_APP_ERROR
;
STMT_RET
(
TSDB_CODE_COM_OPS_NOT_SUPPORT
)
;
}
}
char
*
taos_stmt_errstr
(
TAOS_STMT
*
stmt
)
{
STscStmt
*
pStmt
=
(
STscStmt
*
)
stmt
;
if
(
stmt
==
NULL
)
{
return
(
char
*
)
tstrerror
(
terrno
);
}
return
taos_errstr
(
pStmt
->
pSql
);
}
const
char
*
taos_data_type
(
int
type
)
{
switch
(
type
)
{
case
TSDB_DATA_TYPE_NULL
:
return
"TSDB_DATA_TYPE_NULL"
;
...
...
src/inc/taos.h
浏览文件 @
718bf8d9
...
...
@@ -124,6 +124,7 @@ int taos_stmt_add_batch(TAOS_STMT *stmt);
int
taos_stmt_execute
(
TAOS_STMT
*
stmt
);
TAOS_RES
*
taos_stmt_use_result
(
TAOS_STMT
*
stmt
);
int
taos_stmt_close
(
TAOS_STMT
*
stmt
);
char
*
taos_stmt_errstr
(
TAOS_STMT
*
stmt
);
DLL_EXPORT
TAOS_RES
*
taos_query
(
TAOS
*
taos
,
const
char
*
sql
);
DLL_EXPORT
TAOS_ROW
taos_fetch_row
(
TAOS_RES
*
res
);
...
...
tests/script/api/batchprepare.c
浏览文件 @
718bf8d9
...
...
@@ -1606,7 +1606,7 @@ int stmt_funcb_autoctb_e1(TAOS_STMT *stmt) {
char
*
sql
=
"insert into ? using stb1 (id1,id2,id3,id4,id5,id6,id7,id8,id9) tags(1,?,2,?,4,?,6.0,?,'b') values(?,?,?,?,?,?,?,?,?,?)"
;
int
code
=
taos_stmt_prepare
(
stmt
,
sql
,
0
);
if
(
code
!=
0
){
printf
(
"failed to execute taos_stmt_prepare.
code:0x%x
\n
"
,
code
);
printf
(
"failed to execute taos_stmt_prepare.
error:%s
\n
"
,
taos_stmt_errstr
(
stmt
)
);
return
-
1
;
}
...
...
@@ -1830,7 +1830,7 @@ int stmt_funcb_autoctb_e2(TAOS_STMT *stmt) {
sprintf
(
buf
,
"m%d"
,
zz
);
code
=
taos_stmt_set_tbname_tags
(
stmt
,
buf
,
NULL
);
if
(
code
!=
0
){
printf
(
"failed to execute taos_stmt_set_tbname_tags. code:
0x%x
\n
"
,
code
);
printf
(
"failed to execute taos_stmt_set_tbname_tags. code:
%s
\n
"
,
taos_stmt_errstr
(
stmt
)
);
return
-
1
;
}
...
...
@@ -2037,7 +2037,7 @@ int stmt_funcb_autoctb_e3(TAOS_STMT *stmt) {
char
*
sql
=
"insert into ? using stb1 (id1,id2,id3,id4,id5,id6,id7,id8,id9) tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)"
;
int
code
=
taos_stmt_prepare
(
stmt
,
sql
,
0
);
if
(
code
!=
0
){
printf
(
"failed to execute taos_stmt_prepare. code:
0x%x
\n
"
,
code
);
printf
(
"failed to execute taos_stmt_prepare. code:
%s
\n
"
,
taos_stmt_errstr
(
stmt
)
);
return
-
1
;
//exit(1);
}
...
...
@@ -2078,6 +2078,458 @@ int stmt_funcb_autoctb_e3(TAOS_STMT *stmt) {
//1 tables 10 records
int
stmt_funcb_autoctb_e4
(
TAOS_STMT
*
stmt
)
{
struct
{
int64_t
*
ts
;
int8_t
b
[
10
];
int8_t
v1
[
10
];
int16_t
v2
[
10
];
int32_t
v4
[
10
];
int64_t
v8
[
10
];
float
f4
[
10
];
double
f8
[
10
];
char
bin
[
10
][
40
];
}
v
=
{
0
};
v
.
ts
=
malloc
(
sizeof
(
int64_t
)
*
1
*
10
);
int
*
lb
=
malloc
(
10
*
sizeof
(
int
));
TAOS_BIND
*
tags
=
calloc
(
1
,
sizeof
(
TAOS_BIND
)
*
9
*
1
);
TAOS_MULTI_BIND
*
params
=
calloc
(
1
,
sizeof
(
TAOS_MULTI_BIND
)
*
1
*
10
);
// int one_null = 1;
int
one_not_null
=
0
;
char
*
is_null
=
malloc
(
sizeof
(
char
)
*
10
);
char
*
no_null
=
malloc
(
sizeof
(
char
)
*
10
);
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
lb
[
i
]
=
40
;
no_null
[
i
]
=
0
;
is_null
[
i
]
=
(
i
%
10
==
2
)
?
1
:
0
;
v
.
b
[
i
]
=
(
int8_t
)(
i
%
2
);
v
.
v1
[
i
]
=
(
int8_t
)((
i
+
1
)
%
2
);
v
.
v2
[
i
]
=
(
int16_t
)
i
;
v
.
v4
[
i
]
=
(
int32_t
)(
i
+
1
);
v
.
v8
[
i
]
=
(
int64_t
)(
i
+
2
);
v
.
f4
[
i
]
=
(
float
)(
i
+
3
);
v
.
f8
[
i
]
=
(
double
)(
i
+
4
);
memset
(
v
.
bin
[
i
],
'0'
+
i
%
10
,
40
);
}
for
(
int
i
=
0
;
i
<
10
;
i
+=
10
)
{
params
[
i
+
0
].
buffer_type
=
TSDB_DATA_TYPE_TIMESTAMP
;
params
[
i
+
0
].
buffer_length
=
sizeof
(
int64_t
);
params
[
i
+
0
].
buffer
=
&
v
.
ts
[
10
*
i
/
10
];
params
[
i
+
0
].
length
=
NULL
;
params
[
i
+
0
].
is_null
=
no_null
;
params
[
i
+
0
].
num
=
10
;
params
[
i
+
1
].
buffer_type
=
TSDB_DATA_TYPE_BOOL
;
params
[
i
+
1
].
buffer_length
=
sizeof
(
int8_t
);
params
[
i
+
1
].
buffer
=
v
.
b
;
params
[
i
+
1
].
length
=
NULL
;
params
[
i
+
1
].
is_null
=
is_null
;
params
[
i
+
1
].
num
=
10
;
params
[
i
+
2
].
buffer_type
=
TSDB_DATA_TYPE_TINYINT
;
params
[
i
+
2
].
buffer_length
=
sizeof
(
int8_t
);
params
[
i
+
2
].
buffer
=
v
.
v1
;
params
[
i
+
2
].
length
=
NULL
;
params
[
i
+
2
].
is_null
=
is_null
;
params
[
i
+
2
].
num
=
10
;
params
[
i
+
3
].
buffer_type
=
TSDB_DATA_TYPE_SMALLINT
;
params
[
i
+
3
].
buffer_length
=
sizeof
(
int16_t
);
params
[
i
+
3
].
buffer
=
v
.
v2
;
params
[
i
+
3
].
length
=
NULL
;
params
[
i
+
3
].
is_null
=
is_null
;
params
[
i
+
3
].
num
=
10
;
params
[
i
+
4
].
buffer_type
=
TSDB_DATA_TYPE_INT
;
params
[
i
+
4
].
buffer_length
=
sizeof
(
int32_t
);
params
[
i
+
4
].
buffer
=
v
.
v4
;
params
[
i
+
4
].
length
=
NULL
;
params
[
i
+
4
].
is_null
=
is_null
;
params
[
i
+
4
].
num
=
10
;
params
[
i
+
5
].
buffer_type
=
TSDB_DATA_TYPE_BIGINT
;
params
[
i
+
5
].
buffer_length
=
sizeof
(
int64_t
);
params
[
i
+
5
].
buffer
=
v
.
v8
;
params
[
i
+
5
].
length
=
NULL
;
params
[
i
+
5
].
is_null
=
is_null
;
params
[
i
+
5
].
num
=
10
;
params
[
i
+
6
].
buffer_type
=
TSDB_DATA_TYPE_FLOAT
;
params
[
i
+
6
].
buffer_length
=
sizeof
(
float
);
params
[
i
+
6
].
buffer
=
v
.
f4
;
params
[
i
+
6
].
length
=
NULL
;
params
[
i
+
6
].
is_null
=
is_null
;
params
[
i
+
6
].
num
=
10
;
params
[
i
+
7
].
buffer_type
=
TSDB_DATA_TYPE_DOUBLE
;
params
[
i
+
7
].
buffer_length
=
sizeof
(
double
);
params
[
i
+
7
].
buffer
=
v
.
f8
;
params
[
i
+
7
].
length
=
NULL
;
params
[
i
+
7
].
is_null
=
is_null
;
params
[
i
+
7
].
num
=
10
;
params
[
i
+
8
].
buffer_type
=
TSDB_DATA_TYPE_BINARY
;
params
[
i
+
8
].
buffer_length
=
40
;
params
[
i
+
8
].
buffer
=
v
.
bin
;
params
[
i
+
8
].
length
=
lb
;
params
[
i
+
8
].
is_null
=
is_null
;
params
[
i
+
8
].
num
=
10
;
params
[
i
+
9
].
buffer_type
=
TSDB_DATA_TYPE_BINARY
;
params
[
i
+
9
].
buffer_length
=
40
;
params
[
i
+
9
].
buffer
=
v
.
bin
;
params
[
i
+
9
].
length
=
lb
;
params
[
i
+
9
].
is_null
=
is_null
;
params
[
i
+
9
].
num
=
10
;
}
int64_t
tts
=
1591060628000
;
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
v
.
ts
[
i
]
=
tts
+
i
;
}
for
(
int
i
=
0
;
i
<
1
;
++
i
)
{
tags
[
i
+
0
].
buffer_type
=
TSDB_DATA_TYPE_INT
;
tags
[
i
+
0
].
buffer
=
v
.
v4
;
tags
[
i
+
0
].
is_null
=
&
one_not_null
;
tags
[
i
+
0
].
length
=
NULL
;
tags
[
i
+
1
].
buffer_type
=
TSDB_DATA_TYPE_BOOL
;
tags
[
i
+
1
].
buffer
=
v
.
b
;
tags
[
i
+
1
].
is_null
=
&
one_not_null
;
tags
[
i
+
1
].
length
=
NULL
;
tags
[
i
+
2
].
buffer_type
=
TSDB_DATA_TYPE_TINYINT
;
tags
[
i
+
2
].
buffer
=
v
.
v1
;
tags
[
i
+
2
].
is_null
=
&
one_not_null
;
tags
[
i
+
2
].
length
=
NULL
;
tags
[
i
+
3
].
buffer_type
=
TSDB_DATA_TYPE_SMALLINT
;
tags
[
i
+
3
].
buffer
=
v
.
v2
;
tags
[
i
+
3
].
is_null
=
&
one_not_null
;
tags
[
i
+
3
].
length
=
NULL
;
tags
[
i
+
4
].
buffer_type
=
TSDB_DATA_TYPE_BIGINT
;
tags
[
i
+
4
].
buffer
=
v
.
v8
;
tags
[
i
+
4
].
is_null
=
&
one_not_null
;
tags
[
i
+
4
].
length
=
NULL
;
tags
[
i
+
5
].
buffer_type
=
TSDB_DATA_TYPE_FLOAT
;
tags
[
i
+
5
].
buffer
=
v
.
f4
;
tags
[
i
+
5
].
is_null
=
&
one_not_null
;
tags
[
i
+
5
].
length
=
NULL
;
tags
[
i
+
6
].
buffer_type
=
TSDB_DATA_TYPE_DOUBLE
;
tags
[
i
+
6
].
buffer
=
v
.
f8
;
tags
[
i
+
6
].
is_null
=
&
one_not_null
;
tags
[
i
+
6
].
length
=
NULL
;
tags
[
i
+
7
].
buffer_type
=
TSDB_DATA_TYPE_BINARY
;
tags
[
i
+
7
].
buffer
=
v
.
bin
;
tags
[
i
+
7
].
is_null
=
&
one_not_null
;
tags
[
i
+
7
].
length
=
(
uintptr_t
*
)
lb
;
tags
[
i
+
8
].
buffer_type
=
TSDB_DATA_TYPE_NCHAR
;
tags
[
i
+
8
].
buffer
=
v
.
bin
;
tags
[
i
+
8
].
is_null
=
&
one_not_null
;
tags
[
i
+
8
].
length
=
(
uintptr_t
*
)
lb
;
}
unsigned
long
long
starttime
=
getCurrentTime
();
char
*
sql
=
"insert into ? using stb1 tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)"
;
int
code
=
taos_stmt_prepare
(
stmt
,
sql
,
0
);
if
(
code
!=
0
){
printf
(
"failed to execute taos_stmt_prepare. code:%s
\n
"
,
taos_stmt_errstr
(
stmt
));
exit
(
1
);
}
int
id
=
0
;
for
(
int
zz
=
0
;
zz
<
1
;
zz
++
)
{
char
buf
[
32
];
sprintf
(
buf
,
"m%d"
,
zz
);
code
=
taos_stmt_set_tbname_tags
(
stmt
,
buf
,
tags
);
if
(
code
!=
0
){
printf
(
"failed to execute taos_stmt_set_tbname_tags. error:%s
\n
"
,
taos_stmt_errstr
(
stmt
));
exit
(
1
);
}
code
=
taos_stmt_bind_param_batch
(
stmt
,
params
+
id
*
10
);
if
(
code
!=
0
)
{
printf
(
"failed to execute taos_stmt_bind_param_batch. error:%s
\n
"
,
taos_stmt_errstr
(
stmt
));
exit
(
1
);
}
code
=
taos_stmt_bind_param_batch
(
stmt
,
params
+
id
*
10
);
if
(
code
!=
0
)
{
printf
(
"failed to execute taos_stmt_bind_param_batch. error:%s
\n
"
,
taos_stmt_errstr
(
stmt
));
return
-
1
;
}
taos_stmt_add_batch
(
stmt
);
}
if
(
taos_stmt_execute
(
stmt
)
!=
0
)
{
printf
(
"failed to execute insert statement.
\n
"
);
exit
(
1
);
}
++
id
;
unsigned
long
long
endtime
=
getCurrentTime
();
printf
(
"insert total %d records, used %u seconds, avg:%u useconds
\n
"
,
10
,
(
endtime
-
starttime
)
/
1000000UL
,
(
endtime
-
starttime
)
/
(
10
));
free
(
v
.
ts
);
free
(
lb
);
free
(
params
);
free
(
is_null
);
free
(
no_null
);
free
(
tags
);
return
0
;
}
//1 tables 10 records
int
stmt_funcb_autoctb_e5
(
TAOS_STMT
*
stmt
)
{
struct
{
int64_t
*
ts
;
int8_t
b
[
10
];
int8_t
v1
[
10
];
int16_t
v2
[
10
];
int32_t
v4
[
10
];
int64_t
v8
[
10
];
float
f4
[
10
];
double
f8
[
10
];
char
bin
[
10
][
40
];
}
v
=
{
0
};
v
.
ts
=
malloc
(
sizeof
(
int64_t
)
*
1
*
10
);
int
*
lb
=
malloc
(
10
*
sizeof
(
int
));
TAOS_BIND
*
tags
=
calloc
(
1
,
sizeof
(
TAOS_BIND
)
*
9
*
1
);
TAOS_MULTI_BIND
*
params
=
calloc
(
1
,
sizeof
(
TAOS_MULTI_BIND
)
*
1
*
10
);
// int one_null = 1;
int
one_not_null
=
0
;
char
*
is_null
=
malloc
(
sizeof
(
char
)
*
10
);
char
*
no_null
=
malloc
(
sizeof
(
char
)
*
10
);
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
lb
[
i
]
=
40
;
no_null
[
i
]
=
0
;
is_null
[
i
]
=
(
i
%
10
==
2
)
?
1
:
0
;
v
.
b
[
i
]
=
(
int8_t
)(
i
%
2
);
v
.
v1
[
i
]
=
(
int8_t
)((
i
+
1
)
%
2
);
v
.
v2
[
i
]
=
(
int16_t
)
i
;
v
.
v4
[
i
]
=
(
int32_t
)(
i
+
1
);
v
.
v8
[
i
]
=
(
int64_t
)(
i
+
2
);
v
.
f4
[
i
]
=
(
float
)(
i
+
3
);
v
.
f8
[
i
]
=
(
double
)(
i
+
4
);
memset
(
v
.
bin
[
i
],
'0'
+
i
%
10
,
40
);
}
for
(
int
i
=
0
;
i
<
10
;
i
+=
10
)
{
params
[
i
+
0
].
buffer_type
=
TSDB_DATA_TYPE_TIMESTAMP
;
params
[
i
+
0
].
buffer_length
=
sizeof
(
int64_t
);
params
[
i
+
0
].
buffer
=
&
v
.
ts
[
10
*
i
/
10
];
params
[
i
+
0
].
length
=
NULL
;
params
[
i
+
0
].
is_null
=
no_null
;
params
[
i
+
0
].
num
=
10
;
params
[
i
+
1
].
buffer_type
=
TSDB_DATA_TYPE_BOOL
;
params
[
i
+
1
].
buffer_length
=
sizeof
(
int8_t
);
params
[
i
+
1
].
buffer
=
v
.
b
;
params
[
i
+
1
].
length
=
NULL
;
params
[
i
+
1
].
is_null
=
is_null
;
params
[
i
+
1
].
num
=
10
;
params
[
i
+
2
].
buffer_type
=
TSDB_DATA_TYPE_TINYINT
;
params
[
i
+
2
].
buffer_length
=
sizeof
(
int8_t
);
params
[
i
+
2
].
buffer
=
v
.
v1
;
params
[
i
+
2
].
length
=
NULL
;
params
[
i
+
2
].
is_null
=
is_null
;
params
[
i
+
2
].
num
=
10
;
params
[
i
+
3
].
buffer_type
=
TSDB_DATA_TYPE_SMALLINT
;
params
[
i
+
3
].
buffer_length
=
sizeof
(
int16_t
);
params
[
i
+
3
].
buffer
=
v
.
v2
;
params
[
i
+
3
].
length
=
NULL
;
params
[
i
+
3
].
is_null
=
is_null
;
params
[
i
+
3
].
num
=
10
;
params
[
i
+
4
].
buffer_type
=
TSDB_DATA_TYPE_INT
;
params
[
i
+
4
].
buffer_length
=
sizeof
(
int32_t
);
params
[
i
+
4
].
buffer
=
v
.
v4
;
params
[
i
+
4
].
length
=
NULL
;
params
[
i
+
4
].
is_null
=
is_null
;
params
[
i
+
4
].
num
=
10
;
params
[
i
+
5
].
buffer_type
=
TSDB_DATA_TYPE_BIGINT
;
params
[
i
+
5
].
buffer_length
=
sizeof
(
int64_t
);
params
[
i
+
5
].
buffer
=
v
.
v8
;
params
[
i
+
5
].
length
=
NULL
;
params
[
i
+
5
].
is_null
=
is_null
;
params
[
i
+
5
].
num
=
10
;
params
[
i
+
6
].
buffer_type
=
TSDB_DATA_TYPE_FLOAT
;
params
[
i
+
6
].
buffer_length
=
sizeof
(
float
);
params
[
i
+
6
].
buffer
=
v
.
f4
;
params
[
i
+
6
].
length
=
NULL
;
params
[
i
+
6
].
is_null
=
is_null
;
params
[
i
+
6
].
num
=
10
;
params
[
i
+
7
].
buffer_type
=
TSDB_DATA_TYPE_DOUBLE
;
params
[
i
+
7
].
buffer_length
=
sizeof
(
double
);
params
[
i
+
7
].
buffer
=
v
.
f8
;
params
[
i
+
7
].
length
=
NULL
;
params
[
i
+
7
].
is_null
=
is_null
;
params
[
i
+
7
].
num
=
10
;
params
[
i
+
8
].
buffer_type
=
TSDB_DATA_TYPE_BINARY
;
params
[
i
+
8
].
buffer_length
=
40
;
params
[
i
+
8
].
buffer
=
v
.
bin
;
params
[
i
+
8
].
length
=
lb
;
params
[
i
+
8
].
is_null
=
is_null
;
params
[
i
+
8
].
num
=
10
;
params
[
i
+
9
].
buffer_type
=
TSDB_DATA_TYPE_BINARY
;
params
[
i
+
9
].
buffer_length
=
40
;
params
[
i
+
9
].
buffer
=
v
.
bin
;
params
[
i
+
9
].
length
=
lb
;
params
[
i
+
9
].
is_null
=
is_null
;
params
[
i
+
9
].
num
=
10
;
}
int64_t
tts
=
1591060628000
;
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
v
.
ts
[
i
]
=
tts
+
i
;
}
for
(
int
i
=
0
;
i
<
1
;
++
i
)
{
tags
[
i
+
0
].
buffer_type
=
TSDB_DATA_TYPE_INT
;
tags
[
i
+
0
].
buffer
=
v
.
v4
;
tags
[
i
+
0
].
is_null
=
&
one_not_null
;
tags
[
i
+
0
].
length
=
NULL
;
tags
[
i
+
1
].
buffer_type
=
TSDB_DATA_TYPE_BOOL
;
tags
[
i
+
1
].
buffer
=
v
.
b
;
tags
[
i
+
1
].
is_null
=
&
one_not_null
;
tags
[
i
+
1
].
length
=
NULL
;
tags
[
i
+
2
].
buffer_type
=
TSDB_DATA_TYPE_TINYINT
;
tags
[
i
+
2
].
buffer
=
v
.
v1
;
tags
[
i
+
2
].
is_null
=
&
one_not_null
;
tags
[
i
+
2
].
length
=
NULL
;
tags
[
i
+
3
].
buffer_type
=
TSDB_DATA_TYPE_SMALLINT
;
tags
[
i
+
3
].
buffer
=
v
.
v2
;
tags
[
i
+
3
].
is_null
=
&
one_not_null
;
tags
[
i
+
3
].
length
=
NULL
;
tags
[
i
+
4
].
buffer_type
=
TSDB_DATA_TYPE_BIGINT
;
tags
[
i
+
4
].
buffer
=
v
.
v8
;
tags
[
i
+
4
].
is_null
=
&
one_not_null
;
tags
[
i
+
4
].
length
=
NULL
;
tags
[
i
+
5
].
buffer_type
=
TSDB_DATA_TYPE_FLOAT
;
tags
[
i
+
5
].
buffer
=
v
.
f4
;
tags
[
i
+
5
].
is_null
=
&
one_not_null
;
tags
[
i
+
5
].
length
=
NULL
;
tags
[
i
+
6
].
buffer_type
=
TSDB_DATA_TYPE_DOUBLE
;
tags
[
i
+
6
].
buffer
=
v
.
f8
;
tags
[
i
+
6
].
is_null
=
&
one_not_null
;
tags
[
i
+
6
].
length
=
NULL
;
tags
[
i
+
7
].
buffer_type
=
TSDB_DATA_TYPE_BINARY
;
tags
[
i
+
7
].
buffer
=
v
.
bin
;
tags
[
i
+
7
].
is_null
=
&
one_not_null
;
tags
[
i
+
7
].
length
=
(
uintptr_t
*
)
lb
;
tags
[
i
+
8
].
buffer_type
=
TSDB_DATA_TYPE_NCHAR
;
tags
[
i
+
8
].
buffer
=
v
.
bin
;
tags
[
i
+
8
].
is_null
=
&
one_not_null
;
tags
[
i
+
8
].
length
=
(
uintptr_t
*
)
lb
;
}
unsigned
long
long
starttime
=
getCurrentTime
();
char
*
sql
=
"insert into ? using stb1 tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)"
;
int
code
=
taos_stmt_prepare
(
NULL
,
sql
,
0
);
if
(
code
!=
0
){
printf
(
"failed to execute taos_stmt_prepare. code:%s
\n
"
,
taos_stmt_errstr
(
NULL
));
return
-
1
;
}
int
id
=
0
;
for
(
int
zz
=
0
;
zz
<
1
;
zz
++
)
{
char
buf
[
32
];
sprintf
(
buf
,
"m%d"
,
zz
);
code
=
taos_stmt_set_tbname_tags
(
stmt
,
buf
,
tags
);
if
(
code
!=
0
){
printf
(
"failed to execute taos_stmt_set_tbname_tags. error:%s
\n
"
,
taos_stmt_errstr
(
stmt
));
exit
(
1
);
}
code
=
taos_stmt_bind_param_batch
(
stmt
,
params
+
id
*
10
);
if
(
code
!=
0
)
{
printf
(
"failed to execute taos_stmt_bind_param_batch. error:%s
\n
"
,
taos_stmt_errstr
(
stmt
));
exit
(
1
);
}
code
=
taos_stmt_bind_param_batch
(
stmt
,
params
+
id
*
10
);
if
(
code
!=
0
)
{
printf
(
"failed to execute taos_stmt_bind_param_batch. error:%s
\n
"
,
taos_stmt_errstr
(
stmt
));
return
-
1
;
}
taos_stmt_add_batch
(
stmt
);
}
if
(
taos_stmt_execute
(
stmt
)
!=
0
)
{
printf
(
"failed to execute insert statement.
\n
"
);
exit
(
1
);
}
++
id
;
unsigned
long
long
endtime
=
getCurrentTime
();
printf
(
"insert total %d records, used %u seconds, avg:%u useconds
\n
"
,
10
,
(
endtime
-
starttime
)
/
1000000UL
,
(
endtime
-
starttime
)
/
(
10
));
free
(
v
.
ts
);
free
(
lb
);
free
(
params
);
free
(
is_null
);
free
(
no_null
);
free
(
tags
);
return
0
;
}
//300 tables 60 records
int
stmt_funcb1
(
TAOS_STMT
*
stmt
)
{
struct
{
...
...
@@ -3593,6 +4045,9 @@ void check_result(TAOS *taos, char *tname, int printr, int expected) {
char
sql
[
255
]
=
"SELECT * FROM "
;
TAOS_RES
*
result
;
//FORCE NO PRINT
printr
=
0
;
strcat
(
sql
,
tname
);
result
=
taos_query
(
taos
,
sql
);
...
...
@@ -3896,7 +4351,6 @@ void* runcase(void *par) {
(
void
)
idx
;
#if 1
prepare
(
taos
,
1
,
1
);
...
...
@@ -4118,6 +4572,7 @@ void* runcase(void *par) {
#endif
#if 1
prepare
(
taos
,
1
,
0
);
...
...
@@ -4164,6 +4619,37 @@ void* runcase(void *par) {
#endif
#if 1
prepare
(
taos
,
1
,
0
);
stmt
=
taos_stmt_init
(
taos
);
printf
(
"1t+10r+bm+autoctb+e4 start
\n
"
);
stmt_funcb_autoctb_e4
(
stmt
);
printf
(
"1t+10r+bm+autoctb+e4 end
\n
"
);
printf
(
"check result start
\n
"
);
//check_result(taos, "m0", 1, 0);
printf
(
"check result end
\n
"
);
taos_stmt_close
(
stmt
);
#endif
#if 1
prepare
(
taos
,
1
,
0
);
stmt
=
taos_stmt_init
(
taos
);
printf
(
"1t+10r+bm+autoctb+e5 start
\n
"
);
stmt_funcb_autoctb_e5
(
stmt
);
printf
(
"1t+10r+bm+autoctb+e5 end
\n
"
);
printf
(
"check result start
\n
"
);
//check_result(taos, "m0", 1, 0);
printf
(
"check result end
\n
"
);
taos_stmt_close
(
stmt
);
#endif
#if 1
prepare
(
taos
,
1
,
1
);
...
...
@@ -4371,6 +4857,8 @@ void* runcase(void *par) {
#endif
printf
(
"test end
\n
"
);
return
NULL
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录