Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
40c2824b
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
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看板
提交
40c2824b
编写于
12月 07, 2021
作者:
wmmhello
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add stmt test case
上级
ffac7038
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
151 addition
and
1 deletion
+151
-1
tests/script/api/stmt.c
tests/script/api/stmt.c
+151
-1
未找到文件。
tests/script/api/stmt.c
浏览文件 @
40c2824b
...
...
@@ -173,6 +173,44 @@ void taos_stmt_set_tbname_tags_test() {
printf
(
"finish taos_stmt_set_tbname_tags test
\n
"
);
}
void
taos_stmt_set_tbname_tags_json_test
()
{
printf
(
"start taos_stmt_set_tbname_tags_json_test test
\n
"
);
TAOS_STMT
*
stmt
=
NULL
;
char
*
name
=
calloc
(
1
,
20
);
TAOS_BIND
*
tags
=
calloc
(
1
,
sizeof
(
TAOS_BIND
));
// ASM ERROR
assert
(
taos_stmt_set_tbname_tags
(
stmt
,
name
,
tags
)
!=
0
);
void
*
taos
=
taos_connect
(
"127.0.0.1"
,
"root"
,
"taosdata"
,
NULL
,
0
);
if
(
taos
==
NULL
)
{
printf
(
"Cannot connect to tdengine server
\n
"
);
exit
(
EXIT_FAILURE
);
}
execute_simple_sql
(
taos
,
"drop database if exists stmt_test_json"
);
execute_simple_sql
(
taos
,
"create database stmt_test_json"
);
execute_simple_sql
(
taos
,
"use stmt_test_json"
);
execute_simple_sql
(
taos
,
"create stable super(ts timestamp, c1 int) tags (jtag json)"
);
stmt
=
taos_stmt_init
(
taos
);
assert
(
stmt
!=
NULL
);
char
*
stmt_sql
=
calloc
(
1
,
1000
);
sprintf
(
stmt_sql
,
"insert into ? using super tags (?) values (?,?)"
);
assert
(
taos_stmt_prepare
(
stmt
,
stmt_sql
,
0
)
==
0
);
assert
(
taos_stmt_set_tbname_tags
(
stmt
,
name
,
tags
)
!=
0
);
sprintf
(
name
,
"tb"
);
assert
(
taos_stmt_set_tbname_tags
(
stmt
,
name
,
tags
)
!=
0
);
tags
->
buffer_type
=
TSDB_DATA_TYPE_JSON
;
tags
->
buffer
=
"{
\\\"
key1
\\\"
:
\\\"
value1
\\\"
,
\\\"
key2
\\\"
:null,
\\\"
key3
\\\"
:3,
\\\"
key4
\\\"
:3.2}"
;
tags
->
buffer_length
=
strlen
(
tags
->
buffer
);
tags
->
length
=
&
tags
->
buffer_length
;
tags
->
is_null
=
NULL
;
assert
(
taos_stmt_set_tbname_tags
(
stmt
,
name
,
tags
)
==
0
);
free
(
stmt_sql
);
free
(
name
);
free
(
tags
);
assert
(
taos_stmt_affected_rows
(
stmt
)
==
0
);
taos_stmt_close
(
stmt
);
printf
(
"finish taos_stmt_set_tbname_tags_json_test test
\n
"
);
}
void
taos_stmt_set_sub_tbname_test
()
{
printf
(
"start taos_stmt_set_sub_tbname test
\n
"
);
TAOS_STMT
*
stmt
=
NULL
;
...
...
@@ -492,6 +530,76 @@ void taos_stmt_use_result_query(void *taos, char *col, int type) {
free
(
stmt_sql
);
}
void
taos_stmt_use_result_query_json
(
void
*
taos
,
char
*
col
,
int
type
)
{
TAOS_STMT
*
stmt
=
taos_stmt_init
(
taos
);
assert
(
stmt
!=
NULL
);
char
*
stmt_sql
=
calloc
(
1
,
1024
);
sprintf
(
stmt_sql
,
"select * from t1 where jtag->? = ?"
);
printf
(
"stmt_sql: %s
\n
"
,
stmt_sql
);
assert
(
taos_stmt_prepare
(
stmt
,
stmt_sql
,
0
)
==
0
);
struct
{
int64_t
long_value
;
double
double_value
;
char
nchar_value
[
32
];
}
v
=
{
0
};
v
.
long_value
=
4
;
v
.
double_value
=
3
.
3
;
strcpy
(
v
.
nchar_value
,
"一二三四五六七八"
);
TAOS_BIND
params
[
2
]
=
{
0
};
// char jsonTag[32] = "jtag";
// params[0].buffer_type = TSDB_DATA_TYPE_NCHAR;
// params[0].buffer_length = strlen(jsonTag);
// params[0].buffer = &jsonTag;
// params[0].length = ¶ms[0].buffer_length;
// params[0].is_null = NULL;
params
[
0
].
buffer_type
=
TSDB_DATA_TYPE_NCHAR
;
params
[
0
].
buffer_length
=
strlen
(
col
);
params
[
0
].
buffer
=
&
col
;
params
[
0
].
length
=
&
params
[
0
].
buffer_length
;
params
[
0
].
is_null
=
NULL
;
switch
(
type
)
{
case
TSDB_DATA_TYPE_BIGINT
:
params
[
1
].
buffer_type
=
type
;
params
[
1
].
buffer_length
=
sizeof
(
v
.
long_value
);
params
[
1
].
buffer
=
&
v
.
long_value
;
params
[
1
].
length
=
&
params
[
1
].
buffer_length
;
params
[
1
].
is_null
=
NULL
;
break
;
case
TSDB_DATA_TYPE_NCHAR
:
params
[
1
].
buffer_type
=
type
;
params
[
1
].
buffer_length
=
strlen
(
v
.
nchar_value
);
params
[
1
].
buffer
=
&
v
.
nchar_value
;
params
[
1
].
length
=
&
params
[
1
].
buffer_length
;
params
[
1
].
is_null
=
NULL
;
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
params
[
1
].
buffer_type
=
type
;
params
[
1
].
buffer_length
=
sizeof
(
v
.
double_value
);
params
[
1
].
buffer
=
&
v
.
double_value
;
params
[
1
].
length
=
&
params
[
1
].
buffer_length
;
params
[
1
].
is_null
=
NULL
;
break
;
default:
printf
(
"Cannnot find type: %d
\n
"
,
type
);
break
;
}
assert
(
taos_stmt_bind_param
(
stmt
,
params
)
==
0
);
assert
(
taos_stmt_execute
(
stmt
)
==
0
);
TAOS_RES
*
result
=
taos_stmt_use_result
(
stmt
);
assert
(
result
!=
NULL
);
print_result
(
result
);
taos_free_result
(
result
);
assert
(
taos_stmt_close
(
stmt
)
==
0
);
free
(
stmt_sql
);
}
void
taos_stmt_use_result_test
()
{
printf
(
"start taos_stmt_use_result test
\n
"
);
void
*
taos
=
taos_connect
(
"127.0.0.1"
,
"root"
,
"taosdata"
,
NULL
,
0
);
...
...
@@ -534,6 +642,47 @@ void taos_stmt_use_result_test() {
printf
(
"finish taos_stmt_use_result test
\n
"
);
}
void
taos_stmt_use_result_json_test
()
{
printf
(
"start taos_stmt_use_result_json_test test
\n
"
);
void
*
taos
=
taos_connect
(
"127.0.0.1"
,
"root"
,
"taosdata"
,
NULL
,
0
);
if
(
taos
==
NULL
)
{
printf
(
"Cannot connect to tdengine server
\n
"
);
exit
(
EXIT_FAILURE
);
}
execute_simple_sql
(
taos
,
"drop database if exists stmt_test_json"
);
execute_simple_sql
(
taos
,
"create database stmt_test_json"
);
execute_simple_sql
(
taos
,
"use stmt_test_json"
);
execute_simple_sql
(
taos
,
"create table super(ts timestamp, c1 int) tags (jtag json)"
);
execute_simple_sql
(
taos
,
"create table t1 using super tags ('{
\\\"
key1
\\\"
:
\\\"
一二三四五六七八
\\\"
,
\\\"
key2
\\\"
:null,
\\\"
key3
\\\"
:3,
\\\"
key4
\\\"
:3.1}')"
);
execute_simple_sql
(
taos
,
"insert into t1 values (1591060628000, 1)"
);
execute_simple_sql
(
taos
,
"insert into t1 values (1591060628001, 2)"
);
execute_simple_sql
(
taos
,
"create table t2 using super tags ('{
\\\"
key1
\\\"
:5,
\\\"
key2
\\\"
:null,
\\\"
key3
\\\"
:4,
\\\"
key4
\\\"
:3.2}')"
);
execute_simple_sql
(
taos
,
"insert into t2 values (1591060628003, 21)"
);
execute_simple_sql
(
taos
,
"insert into t2 values (1591060628004, 22)"
);
execute_simple_sql
(
taos
,
"create table t3 using super tags ('{
\\\"
key1
\\\"
:
\\\"
一二
\\\"
,
\\\"
key2
\\\"
:null,
\\\"
key3
\\\"
:null,
\\\"
key4
\\\"
:3.3}')"
);
execute_simple_sql
(
taos
,
"insert into t3 values (1591060628005, 31)"
);
execute_simple_sql
(
taos
,
"insert into t3 values (1591060628006, 32)"
);
taos_stmt_use_result_query_json
(
taos
,
"key1"
,
TSDB_DATA_TYPE_NCHAR
);
taos_stmt_use_result_query_json
(
taos
,
"key3"
,
TSDB_DATA_TYPE_BIGINT
);
taos_stmt_use_result_query_json
(
taos
,
"key4"
,
TSDB_DATA_TYPE_DOUBLE
);
printf
(
"finish taos_stmt_use_result_json_test test
\n
"
);
}
void
taos_stmt_close_test
()
{
printf
(
"start taos_stmt_close test
\n
"
);
// ASM ERROR
...
...
@@ -548,6 +697,7 @@ void test_api_reliability() {
taos_stmt_preprare_test
();
taos_stmt_set_tbname_test
();
taos_stmt_set_tbname_tags_test
();
taos_stmt_set_tbname_tags_json_test
();
taos_stmt_set_sub_tbname_test
();
taos_stmt_bind_param_test
();
taos_stmt_bind_single_param_batch_test
();
...
...
@@ -557,7 +707,7 @@ void test_api_reliability() {
taos_stmt_close_test
();
}
void
test_query
()
{
taos_stmt_use_result_test
();
}
void
test_query
()
{
taos_stmt_use_result_test
();
taos_stmt_use_result_json_test
();
}
int
main
(
int
argc
,
char
*
argv
[])
{
test_api_reliability
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录