Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
003562bc
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看板
提交
003562bc
编写于
5月 08, 2021
作者:
D
dapan1121
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bug
上级
020fa3dd
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
113 addition
and
20 deletion
+113
-20
src/client/src/tscPrepare.c
src/client/src/tscPrepare.c
+100
-19
src/inc/taos.h
src/inc/taos.h
+13
-1
未找到文件。
src/client/src/tscPrepare.c
浏览文件 @
003562bc
...
...
@@ -268,12 +268,13 @@ static char* normalStmtBuildSql(STscStmt* stmt) {
////////////////////////////////////////////////////////////////////////////////
// functions for insertion statement preparation
static
int
doBindParam
(
STableDataBlocks
*
pBlock
,
char
*
data
,
SParamInfo
*
param
,
TAOS_BIND
*
bind
)
{
static
int
doBindParam
(
STableDataBlocks
*
pBlock
,
char
*
data
,
SParamInfo
*
param
,
TAOS_BIND
*
bind
,
int32_t
colNum
)
{
if
(
bind
->
is_null
!=
NULL
&&
*
(
bind
->
is_null
))
{
setNull
(
data
+
param
->
offset
,
param
->
type
,
param
->
bytes
);
return
TSDB_CODE_SUCCESS
;
}
#if 0
if (0) {
// allow user bind param data with different type
union {
...
...
@@ -654,6 +655,7 @@ static int doBindParam(STableDataBlocks* pBlock, char* data, SParamInfo* param,
}
}
}
#endif
if
(
bind
->
buffer_type
!=
param
->
type
)
{
return
TSDB_CODE_TSC_INVALID_VALUE
;
...
...
@@ -713,6 +715,85 @@ static int doBindParam(STableDataBlocks* pBlock, char* data, SParamInfo* param,
return
TSDB_CODE_SUCCESS
;
}
static
int
doBindBatchParam
(
STableDataBlocks
*
pBlock
,
SParamInfo
*
param
,
TAOS_MULTI_BIND
*
bind
,
int32_t
rowNum
)
{
if
(
bind
->
buffer_type
!=
param
->
type
)
{
return
TSDB_CODE_TSC_INVALID_VALUE
;
}
short
size
=
0
;
switch
(
param
->
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
case
TSDB_DATA_TYPE_TINYINT
:
size
=
1
;
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
size
=
2
;
break
;
case
TSDB_DATA_TYPE_INT
:
case
TSDB_DATA_TYPE_FLOAT
:
size
=
4
;
break
;
case
TSDB_DATA_TYPE_BIGINT
:
case
TSDB_DATA_TYPE_DOUBLE
:
case
TSDB_DATA_TYPE_TIMESTAMP
:
size
=
8
;
break
;
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
if
(
bind
->
length
==
NULL
)
{
tscError
(
"BINARY/NCHAR no length"
);
return
TSDB_CODE_TSC_INVALID_VALUE
;
}
break
;
default:
assert
(
false
);
return
TSDB_CODE_TSC_INVALID_VALUE
;
}
for
(
int
i
=
0
;
i
<
bind
->
num
;
++
i
)
{
char
*
data
=
pBlock
->
pData
+
sizeof
(
SSubmitBlk
)
+
pBlock
->
rowSize
*
(
rowNum
+
i
);
if
(
bind
->
is_null
!=
NULL
&&
bind
->
is_null
[
i
])
{
setNull
(
data
+
param
->
offset
,
param
->
type
,
param
->
bytes
);
return
TSDB_CODE_SUCCESS
;
}
if
(
size
>
0
)
{
memcpy
(
data
+
param
->
offset
,
bind
->
buffer
+
bind
->
buffer_length
*
i
,
size
);
if
(
param
->
offset
==
0
)
{
if
(
tsCheckTimestamp
(
pBlock
,
data
+
param
->
offset
)
!=
TSDB_CODE_SUCCESS
)
{
tscError
(
"invalid timestamp"
);
return
TSDB_CODE_TSC_INVALID_VALUE
;
}
}
}
else
if
(
param
->
type
==
TSDB_DATA_TYPE_BINARY
)
{
if
(
bind
->
length
[
i
]
>
(
uintptr_t
)
param
->
bytes
)
{
return
TSDB_CODE_TSC_INVALID_VALUE
;
}
size
=
(
short
)
bind
->
length
[
i
];
STR_WITH_SIZE_TO_VARSTR
(
data
+
param
->
offset
,
bind
->
buffer
+
bind
->
buffer_length
*
i
,
size
);
}
else
if
(
param
->
type
==
TSDB_DATA_TYPE_NCHAR
)
{
int32_t
output
=
0
;
if
(
!
taosMbsToUcs4
(
bind
->
buffer
+
bind
->
buffer_length
*
i
,
bind
->
length
[
i
],
varDataVal
(
data
+
param
->
offset
),
param
->
bytes
-
VARSTR_HEADER_SIZE
,
&
output
))
{
return
TSDB_CODE_TSC_INVALID_VALUE
;
}
varDataSetLen
(
data
+
param
->
offset
,
output
);
}
}
return
TSDB_CODE_SUCCESS
;
}
static
int
insertStmtBindParam
(
STscStmt
*
stmt
,
TAOS_BIND
*
bind
)
{
SSqlCmd
*
pCmd
=
&
stmt
->
pSql
->
cmd
;
STscStmt
*
pStmt
=
(
STscStmt
*
)
stmt
;
...
...
@@ -765,7 +846,7 @@ static int insertStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) {
for
(
uint32_t
j
=
0
;
j
<
pBlock
->
numOfParams
;
++
j
)
{
SParamInfo
*
param
=
&
pBlock
->
params
[
j
];
int
code
=
doBindParam
(
pBlock
,
data
,
param
,
&
bind
[
param
->
idx
]);
int
code
=
doBindParam
(
pBlock
,
data
,
param
,
&
bind
[
param
->
idx
]
,
1
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
tscDebug
(
"param %d: type mismatch or invalid"
,
param
->
idx
);
return
code
;
...
...
@@ -776,9 +857,10 @@ static int insertStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) {
}
static
int
insertStmtBindParamBatch
(
STscStmt
*
stmt
,
TAOS_
BIND
*
bind
,
int32_t
num
)
{
static
int
insertStmtBindParamBatch
(
STscStmt
*
stmt
,
TAOS_
MULTI_BIND
*
bind
)
{
SSqlCmd
*
pCmd
=
&
stmt
->
pSql
->
cmd
;
STscStmt
*
pStmt
=
(
STscStmt
*
)
stmt
;
int
rowNum
=
bind
->
num
;
STableDataBlocks
*
pBlock
=
NULL
;
...
...
@@ -795,7 +877,7 @@ static int insertStmtBindParamBatch(STscStmt* stmt, TAOS_BIND* bind, int32_t num
pBlock
=
*
t1
;
uint32_t
totalDataSize
=
sizeof
(
SSubmitBlk
)
+
(
pCmd
->
batchSize
+
n
um
)
*
pBlock
->
rowSize
;
uint32_t
totalDataSize
=
sizeof
(
SSubmitBlk
)
+
(
pCmd
->
batchSize
+
rowN
um
)
*
pBlock
->
rowSize
;
if
(
totalDataSize
>
pBlock
->
nAllocSize
)
{
const
double
factor
=
1
.
5
;
...
...
@@ -808,22 +890,21 @@ static int insertStmtBindParamBatch(STscStmt* stmt, TAOS_BIND* bind, int32_t num
pBlock
->
nAllocSize
=
(
uint32_t
)(
totalDataSize
*
factor
);
}
for
(
uint32_t
i
=
0
;
i
<
num
;
++
i
)
{
char
*
data
=
pBlock
->
pData
+
sizeof
(
SSubmitBlk
)
+
pBlock
->
rowSize
*
(
pCmd
->
batchSize
+
i
)
;
TAOS_BIND
*
tbind
=
bind
+
pBlock
->
numOfParams
*
i
;
for
(
uint32_t
j
=
0
;
j
<
pBlock
->
numOfParams
;
++
j
)
{
SParamInfo
*
param
=
&
pBlock
->
params
[
j
];
for
(
uint32_t
j
=
0
;
j
<
pBlock
->
numOfParams
;
++
j
)
{
SParamInfo
*
param
=
&
pBlock
->
params
[
j
]
;
if
(
bind
[
param
->
idx
].
num
!=
rowNum
)
{
tscError
(
"param %d: num[%d:%d] not match"
,
param
->
idx
,
rowNum
,
bind
[
param
->
idx
].
num
);
return
TSDB_CODE_TSC_INVALID_VALUE
;
}
int
code
=
doBindParam
(
pBlock
,
data
,
param
,
&
tbind
[
param
->
idx
]);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
tscError
(
"param %d: type mismatch or invalid"
,
param
->
idx
);
return
code
;
}
int
code
=
doBindBatchParam
(
pBlock
,
param
,
&
bind
[
param
->
idx
],
pCmd
->
batchSize
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
tscError
(
"param %d: type mismatch or invalid"
,
param
->
idx
);
return
code
;
}
}
pCmd
->
batchSize
+=
n
um
-
1
;
pCmd
->
batchSize
+=
rowN
um
-
1
;
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -1293,9 +1374,9 @@ int taos_stmt_bind_param(TAOS_STMT* stmt, TAOS_BIND* bind) {
}
int
taos_stmt_bind_param_batch
(
TAOS_STMT
*
stmt
,
TAOS_
BIND
*
bind
,
int32_t
num
)
{
int
taos_stmt_bind_param_batch
(
TAOS_STMT
*
stmt
,
TAOS_
MULTI_BIND
*
bind
)
{
STscStmt
*
pStmt
=
(
STscStmt
*
)
stmt
;
if
(
num
<=
0
||
bind
==
NULL
)
{
if
(
bind
==
NULL
||
bind
->
num
<=
0
)
{
tscError
(
"invalid parameter"
);
return
TSDB_CODE_TSC_APP_ERROR
;
}
...
...
@@ -1305,7 +1386,7 @@ int taos_stmt_bind_param_batch(TAOS_STMT* stmt, TAOS_BIND* bind, int32_t num) {
return
TSDB_CODE_TSC_APP_ERROR
;
}
return
insertStmtBindParamBatch
(
pStmt
,
bind
,
num
);
return
insertStmtBindParamBatch
(
pStmt
,
bind
);
}
...
...
src/inc/taos.h
浏览文件 @
003562bc
...
...
@@ -82,6 +82,7 @@ typedef struct TAOS_BIND {
uintptr_t
buffer_length
;
// unused
uintptr_t
*
length
;
int
*
is_null
;
int
is_unsigned
;
// unused
int
*
error
;
// unused
union
{
...
...
@@ -99,6 +100,17 @@ typedef struct TAOS_BIND {
unsigned
int
allocated
;
}
TAOS_BIND
;
typedef
struct
TAOS_MULTI_BIND
{
int
buffer_type
;
void
*
buffer
;
uintptr_t
buffer_length
;
// unused
uintptr_t
*
length
;
int
*
is_null
;
int
num
;
}
TAOS_MULTI_BIND
;
TAOS_STMT
*
taos_stmt_init
(
TAOS
*
taos
);
int
taos_stmt_prepare
(
TAOS_STMT
*
stmt
,
const
char
*
sql
,
unsigned
long
length
);
int
taos_stmt_set_tbname
(
TAOS_STMT
*
stmt
,
const
char
*
name
);
...
...
@@ -106,7 +118,7 @@ int taos_stmt_is_insert(TAOS_STMT *stmt, int *insert);
int
taos_stmt_num_params
(
TAOS_STMT
*
stmt
,
int
*
nums
);
int
taos_stmt_get_param
(
TAOS_STMT
*
stmt
,
int
idx
,
int
*
type
,
int
*
bytes
);
int
taos_stmt_bind_param
(
TAOS_STMT
*
stmt
,
TAOS_BIND
*
bind
);
int
taos_stmt_bind_param_batch
(
TAOS_STMT
*
stmt
,
TAOS_
BIND
*
bind
,
int32_t
num
);
int
taos_stmt_bind_param_batch
(
TAOS_STMT
*
stmt
,
TAOS_
MULTI_BIND
*
bind
);
int
taos_stmt_add_batch
(
TAOS_STMT
*
stmt
);
int
taos_stmt_execute
(
TAOS_STMT
*
stmt
);
TAOS_RES
*
taos_stmt_use_result
(
TAOS_STMT
*
stmt
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录