Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
de59ed95
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看板
提交
de59ed95
编写于
8月 25, 2021
作者:
Z
zhaoyanggh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
format prettier
上级
13b93963
变更
10
显示空白变更内容
内联
并排
Showing
10 changed file
with
518 addition
and
496 deletion
+518
-496
tests/examples/c/apitest.c
tests/examples/c/apitest.c
+179
-148
tests/examples/c/asyncdemo.c
tests/examples/c/asyncdemo.c
+57
-72
tests/examples/c/demo.c
tests/examples/c/demo.c
+14
-13
tests/examples/c/epoll.c
tests/examples/c/epoll.c
+110
-113
tests/examples/c/makefile
tests/examples/c/makefile
+0
-3
tests/examples/c/prepare.c
tests/examples/c/prepare.c
+21
-22
tests/examples/c/schemaless.c
tests/examples/c/schemaless.c
+78
-56
tests/examples/c/stream.c
tests/examples/c/stream.c
+38
-44
tests/examples/c/subscribe.c
tests/examples/c/subscribe.c
+19
-25
tests/script/api/makefile
tests/script/api/makefile
+2
-0
未找到文件。
tests/examples/c/apitest.c
浏览文件 @
de59ed95
...
...
@@ -8,7 +8,7 @@
#include <unistd.h>
static
void
prepare_data
(
TAOS
*
taos
)
{
TAOS_RES
*
result
;
TAOS_RES
*
result
;
result
=
taos_query
(
taos
,
"drop database if exists test;"
);
taos_free_result
(
result
);
usleep
(
100000
);
...
...
@@ -41,7 +41,8 @@ static void prepare_data(TAOS* taos) {
result
=
taos_query
(
taos
,
"create table t9 using meters tags(9);"
);
taos_free_result
(
result
);
result
=
taos_query
(
taos
,
"insert into t0 values('2020-01-01 00:00:00.000', 0)"
result
=
taos_query
(
taos
,
"insert into t0 values('2020-01-01 00:00:00.000', 0)"
" ('2020-01-01 00:01:00.000', 0)"
" ('2020-01-01 00:02:00.000', 0)"
" t1 values('2020-01-01 00:00:00.000', 0)"
...
...
@@ -77,7 +78,7 @@ static int print_result(TAOS_RES* res, int blockFetch) {
if
(
blockFetch
)
{
int
rows
=
0
;
while
((
rows
=
taos_fetch_block
(
res
,
&
row
)))
{
//for (int i = 0; i < rows; i++) {
//
for (int i = 0; i < rows; i++) {
// char temp[256];
// taos_print_row(temp, row + i, fields, num_fields);
// puts(temp);
...
...
@@ -149,7 +150,7 @@ static void verify_query(TAOS* taos) {
taos_free_result
(
res
);
}
void
subscribe_callback
(
TAOS_SUB
*
tsub
,
TAOS_RES
*
res
,
void
*
param
,
int
code
)
{
void
subscribe_callback
(
TAOS_SUB
*
tsub
,
TAOS_RES
*
res
,
void
*
param
,
int
code
)
{
int
rows
=
print_result
(
res
,
*
(
int
*
)
param
);
printf
(
"%d rows consumed in subscribe_callback
\n
"
,
rows
);
}
...
...
@@ -164,7 +165,7 @@ static void verify_subscribe(TAOS* taos) {
res
=
taos_consume
(
tsub
);
check_row_count
(
__LINE__
,
res
,
0
);
TAOS_RES
*
result
;
TAOS_RES
*
result
;
result
=
taos_query
(
taos
,
"insert into t0 values('2020-01-01 00:02:00.001', 0);"
);
taos_free_result
(
result
);
result
=
taos_query
(
taos
,
"insert into t8 values('2020-01-01 00:01:03.000', 0);"
);
...
...
@@ -250,7 +251,9 @@ void verify_prepare(TAOS* taos) {
taos_select_db
(
taos
,
"test"
);
// create table
const
char
*
sql
=
"create table m1 (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin binary(40), blob nchar(10))"
;
const
char
*
sql
=
"create table m1 (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin "
"binary(40), blob nchar(10), u1 tinyint unsigned, u2 smallint unsigned, u4 int unsigned, u8 bigint unsigned)"
;
result
=
taos_query
(
taos
,
sql
);
code
=
taos_errno
(
result
);
if
(
code
!=
0
)
{
...
...
@@ -272,10 +275,14 @@ void verify_prepare(TAOS* taos) {
double
f8
;
char
bin
[
40
];
char
blob
[
80
];
uint8_t
u1
;
uint16_t
u2
;
uint32_t
u4
;
uint64_t
u8
;
}
v
=
{
0
};
TAOS_STMT
*
stmt
=
taos_stmt_init
(
taos
);
TAOS_BIND
params
[
10
];
TAOS_BIND
params
[
14
];
params
[
0
].
buffer_type
=
TSDB_DATA_TYPE_TIMESTAMP
;
params
[
0
].
buffer_length
=
sizeof
(
v
.
ts
);
params
[
0
].
buffer
=
&
v
.
ts
;
...
...
@@ -337,11 +344,35 @@ void verify_prepare(TAOS* taos) {
params
[
9
].
length
=
&
params
[
9
].
buffer_length
;
params
[
9
].
is_null
=
NULL
;
params
[
10
].
buffer_type
=
TSDB_DATA_TYPE_UTINYINT
;
params
[
10
].
buffer_length
=
sizeof
(
v
.
u1
);
params
[
10
].
buffer
=
&
v
.
u1
;
params
[
10
].
length
=
&
params
[
10
].
buffer_length
;
params
[
10
].
is_null
=
NULL
;
params
[
11
].
buffer_type
=
TSDB_DATA_TYPE_USMALLINT
;
params
[
11
].
buffer_length
=
sizeof
(
v
.
u2
);
params
[
11
].
buffer
=
&
v
.
u2
;
params
[
11
].
length
=
&
params
[
11
].
buffer_length
;
params
[
11
].
is_null
=
NULL
;
params
[
12
].
buffer_type
=
TSDB_DATA_TYPE_UINT
;
params
[
12
].
buffer_length
=
sizeof
(
v
.
u4
);
params
[
12
].
buffer
=
&
v
.
u4
;
params
[
12
].
length
=
&
params
[
12
].
buffer_length
;
params
[
12
].
is_null
=
NULL
;
params
[
13
].
buffer_type
=
TSDB_DATA_TYPE_UBIGINT
;
params
[
13
].
buffer_length
=
sizeof
(
v
.
u8
);
params
[
13
].
buffer
=
&
v
.
u8
;
params
[
13
].
length
=
&
params
[
13
].
buffer_length
;
params
[
13
].
is_null
=
NULL
;
int
is_null
=
1
;
sql
=
"insert into m1 values(?,?,?,?,?,?,?,?,?,?)"
;
sql
=
"insert into m1 values(?,?,?,?,?,?,?,?,?,?
,?,?,?,?
)"
;
code
=
taos_stmt_prepare
(
stmt
,
sql
,
0
);
if
(
code
!=
0
){
if
(
code
!=
0
)
{
printf
(
"
\033
[31mfailed to execute taos_stmt_prepare. error:%s
\033
[0m
\n
"
,
taos_stmt_errstr
(
stmt
));
taos_stmt_close
(
stmt
);
return
;
...
...
@@ -362,6 +393,10 @@ void verify_prepare(TAOS* taos) {
for
(
int
j
=
0
;
j
<
sizeof
(
v
.
bin
);
++
j
)
{
v
.
bin
[
j
]
=
(
char
)(
i
+
'0'
);
}
v
.
u1
=
(
uint8_t
)
i
;
v
.
u2
=
(
uint16_t
)(
i
*
2
);
v
.
u4
=
(
uint32_t
)(
i
*
4
);
v
.
u8
=
(
uint64_t
)(
i
*
8
);
taos_stmt_bind_param
(
stmt
,
params
);
taos_stmt_add_batch
(
stmt
);
...
...
@@ -390,7 +425,7 @@ void verify_prepare(TAOS* taos) {
TAOS_ROW
row
;
int
rows
=
0
;
int
num_fields
=
taos_num_fields
(
result
);
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
result
);
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
result
);
// fetch the records row by row
while
((
row
=
taos_fetch_row
(
result
)))
{
...
...
@@ -422,7 +457,9 @@ void verify_prepare2(TAOS* taos) {
taos_select_db
(
taos
,
"test"
);
// create table
const
char
*
sql
=
"create table m1 (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin binary(40), blob nchar(10))"
;
const
char
*
sql
=
"create table m1 (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin "
"binary(40), blob nchar(10))"
;
result
=
taos_query
(
taos
,
sql
);
code
=
taos_errno
(
result
);
if
(
code
!=
0
)
{
...
...
@@ -446,14 +483,14 @@ void verify_prepare2(TAOS* taos) {
char
blob
[
10
][
80
];
}
v
;
int32_t
*
t8_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
int32_t
*
t16_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
int32_t
*
t32_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
int32_t
*
t64_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
int32_t
*
float_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
int32_t
*
double_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
int32_t
*
bin_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
int32_t
*
blob_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
int32_t
*
t8_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
int32_t
*
t16_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
int32_t
*
t32_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
int32_t
*
t64_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
int32_t
*
float_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
int32_t
*
double_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
int32_t
*
bin_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
int32_t
*
blob_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
TAOS_STMT
*
stmt
=
taos_stmt_init
(
taos
);
TAOS_MULTI_BIND
params
[
10
];
...
...
@@ -538,7 +575,7 @@ void verify_prepare2(TAOS* taos) {
}
code
=
taos_stmt_set_tbname
(
stmt
,
"m1"
);
if
(
code
!=
0
){
if
(
code
!=
0
)
{
printf
(
"
\033
[31mfailed to execute taos_stmt_prepare. error:%s
\033
[0m
\n
"
,
taos_stmt_errstr
(
stmt
));
taos_stmt_close
(
stmt
);
return
;
...
...
@@ -613,7 +650,7 @@ void verify_prepare2(TAOS* taos) {
TAOS_ROW
row
;
int
rows
=
0
;
int
num_fields
=
taos_num_fields
(
result
);
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
result
);
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
result
);
// fetch the records row by row
while
((
row
=
taos_fetch_row
(
result
)))
{
...
...
@@ -654,7 +691,9 @@ void verify_prepare3(TAOS* taos) {
taos_select_db
(
taos
,
"test"
);
// create table
const
char
*
sql
=
"create stable st1 (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin binary(40), blob nchar(10)) tags (id1 int, id2 binary(40))"
;
const
char
*
sql
=
"create stable st1 (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin "
"binary(40), blob nchar(10)) tags (id1 int, id2 binary(40))"
;
result
=
taos_query
(
taos
,
sql
);
code
=
taos_errno
(
result
);
if
(
code
!=
0
)
{
...
...
@@ -682,7 +721,6 @@ void verify_prepare3(TAOS* taos) {
tags
[
1
].
length
=
&
id2_len
;
tags
[
1
].
is_null
=
NULL
;
// insert 10 records
struct
{
int64_t
ts
[
10
];
...
...
@@ -697,14 +735,14 @@ void verify_prepare3(TAOS* taos) {
char
blob
[
10
][
80
];
}
v
;
int32_t
*
t8_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
int32_t
*
t16_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
int32_t
*
t32_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
int32_t
*
t64_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
int32_t
*
float_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
int32_t
*
double_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
int32_t
*
bin_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
int32_t
*
blob_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
int32_t
*
t8_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
int32_t
*
t16_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
int32_t
*
t32_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
int32_t
*
t64_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
int32_t
*
float_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
int32_t
*
double_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
int32_t
*
bin_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
int32_t
*
blob_len
=
malloc
(
sizeof
(
int32_t
)
*
10
);
TAOS_STMT
*
stmt
=
taos_stmt_init
(
taos
);
TAOS_MULTI_BIND
params
[
10
];
...
...
@@ -780,17 +818,16 @@ void verify_prepare3(TAOS* taos) {
params
[
9
].
is_null
=
is_null
;
params
[
9
].
num
=
10
;
sql
=
"insert into ? using st1 tags(?,?) values(?,?,?,?,?,?,?,?,?,?)"
;
code
=
taos_stmt_prepare
(
stmt
,
sql
,
0
);
if
(
code
!=
0
){
if
(
code
!=
0
)
{
printf
(
"
\033
[31mfailed to execute taos_stmt_prepare. error:%s
\033
[0m
\n
"
,
taos_stmt_errstr
(
stmt
));
taos_stmt_close
(
stmt
);
return
;
}
code
=
taos_stmt_set_tbname_tags
(
stmt
,
"m1"
,
tags
);
if
(
code
!=
0
){
if
(
code
!=
0
)
{
printf
(
"
\033
[31mfailed to execute taos_stmt_prepare. error:%s
\033
[0m
\n
"
,
taos_stmt_errstr
(
stmt
));
taos_stmt_close
(
stmt
);
return
;
...
...
@@ -865,7 +902,7 @@ void verify_prepare3(TAOS* taos) {
TAOS_ROW
row
;
int
rows
=
0
;
int
num_fields
=
taos_num_fields
(
result
);
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
result
);
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
result
);
// fetch the records row by row
while
((
row
=
taos_fetch_row
(
result
)))
{
...
...
@@ -888,8 +925,7 @@ void verify_prepare3(TAOS* taos) {
free
(
blob_len
);
}
void
retrieve_callback
(
void
*
param
,
TAOS_RES
*
tres
,
int
numOfRows
)
{
void
retrieve_callback
(
void
*
param
,
TAOS_RES
*
tres
,
int
numOfRows
)
{
if
(
numOfRows
>
0
)
{
printf
(
"%d rows async retrieved
\n
"
,
numOfRows
);
taos_fetch_rows_a
(
tres
,
retrieve_callback
,
param
);
...
...
@@ -903,8 +939,7 @@ void retrieve_callback(void *param, TAOS_RES *tres, int numOfRows)
}
}
void
select_callback
(
void
*
param
,
TAOS_RES
*
tres
,
int
code
)
{
void
select_callback
(
void
*
param
,
TAOS_RES
*
tres
,
int
code
)
{
if
(
code
==
0
&&
tres
)
{
taos_fetch_rows_a
(
tres
,
retrieve_callback
,
param
);
}
else
{
...
...
@@ -918,7 +953,7 @@ void verify_async(TAOS* taos) {
usleep
(
1000000
);
}
void
stream_callback
(
void
*
param
,
TAOS_RES
*
res
,
TAOS_ROW
row
)
{
void
stream_callback
(
void
*
param
,
TAOS_RES
*
res
,
TAOS_ROW
row
)
{
if
(
res
==
NULL
||
row
==
NULL
)
{
return
;
}
...
...
@@ -934,13 +969,8 @@ void stream_callback(void *param, TAOS_RES *res, TAOS_ROW row) {
void
verify_stream
(
TAOS
*
taos
)
{
prepare_data
(
taos
);
TAOS_STREAM
*
strm
=
taos_open_stream
(
taos
,
"select count(*) from meters interval(1m)"
,
stream_callback
,
0
,
NULL
,
NULL
);
TAOS_STREAM
*
strm
=
taos_open_stream
(
taos
,
"select count(*) from meters interval(1m)"
,
stream_callback
,
0
,
NULL
,
NULL
);
printf
(
"waiting for stream data
\n
"
);
usleep
(
100000
);
TAOS_RES
*
result
=
taos_query
(
taos
,
"insert into t0 values(now, 0)(now+5s,1)(now+10s, 2);"
);
...
...
@@ -950,7 +980,7 @@ void verify_stream(TAOS* taos) {
}
int32_t
verify_schema_less
(
TAOS
*
taos
)
{
TAOS_RES
*
result
;
TAOS_RES
*
result
;
result
=
taos_query
(
taos
,
"drop database if exists test;"
);
taos_free_result
(
result
);
usleep
(
100000
);
...
...
@@ -972,49 +1002,51 @@ int32_t verify_schema_less(TAOS* taos) {
"st,t1=4i64,t2=5f64,t3=
\"
t4
\"
c1=3i64,c3=L
\"
passitagain
\"
,c2=true,c4=5f64 1626006833642000000ns"
,
"ste,t2=5f64,t3=L
\"
ste2
\"
c3=
\"
iamszhou
\"
,c4=false 1626056811843316532ns"
,
"ste,t2=5f64,t3=L
\"
ste2
\"
c3=
\"
iamszhou
\"
,c4=false,c5=32i8,c6=64i16,c7=32i32,c8=88.88f32 1626056812843316532ns"
,
"st,t1=4i64,t3=
\"
t4
\"
,t2=5f64,t4=5f64 c1=3i64,c3=L
\"
passitagin
\"
,c2=true,c4=5f64,c5=5f64,c6=7u64 1626006933640000000ns"
,
"stf,t1=4i64,t3=
\"
t4
\"
,t2=5f64,t4=5f64 c1=3i64,c3=L
\"
passitagin
\"
,c2=true,c4=5f64,c5=5f64,c6=7u64 1626006933640000000ns"
,
"stf,t1=4i64,t3=
\"
t4
\"
,t2=5f64,t4=5f64 c1=3i64,c3=L
\"
passitagin_stf
\"
,c2=false,c5=5f64,c6=7u64 1626006933641000000ns"
};
"st,t1=4i64,t3=
\"
t4
\"
,t2=5f64,t4=5f64 c1=3i64,c3=L
\"
passitagin
\"
,c2=true,c4=5f64,c5=5f64,c6=7u64 "
"1626006933640000000ns"
,
"stf,t1=4i64,t3=
\"
t4
\"
,t2=5f64,t4=5f64 c1=3i64,c3=L
\"
passitagin
\"
,c2=true,c4=5f64,c5=5f64,c6=7u64 "
"1626006933640000000ns"
,
"stf,t1=4i64,t3=
\"
t4
\"
,t2=5f64,t4=5f64 c1=3i64,c3=L
\"
passitagin_stf
\"
,c2=false,c5=5f64,c6=7u64 "
"1626006933641000000ns"
};
code
=
taos_insert_lines
(
taos
,
lines
,
sizeof
(
lines
)
/
sizeof
(
char
*
));
code
=
taos_insert_lines
(
taos
,
lines
,
sizeof
(
lines
)
/
sizeof
(
char
*
));
char
*
lines2
[]
=
{
"stg,t1=3i64,t2=4f64,t3=
\"
t3
\"
c1=3i64,c3=L
\"
passit
\"
,c2=false,c4=4f64 1626006833639000000ns"
,
"stg,t1=4i64,t3=
\"
t4
\"
,t2=5f64,t4=5f64 c1=3i64,c3=L
\"
passitagin
\"
,c2=true,c4=5f64,c5=5f64 1626006833640000000ns"
};
"stg,t1=4i64,t3=
\"
t4
\"
,t2=5f64,t4=5f64 c1=3i64,c3=L
\"
passitagin
\"
,c2=true,c4=5f64,c5=5f64 1626006833640000000ns"
};
code
=
taos_insert_lines
(
taos
,
&
lines2
[
0
],
1
);
code
=
taos_insert_lines
(
taos
,
&
lines2
[
1
],
1
);
char
*
lines3
[]
=
{
"sth,t1=4i64,t2=5f64,t4=5f64,ID=
\"
childtable
\"
c1=3i64,c3=L
\"
passitagin_stf
\"
,c2=false,c5=5f64,c6=7u64
1626006933641ms"
,
"
sth,t1=4i64,t2=5f64,t4=5f64 c1=3i64,c3=L
\"
passitagin_stf
\"
,c2=false,c5=5f64,c6=7u64 1626006933654ms"
};
"sth,t1=4i64,t2=5f64,t4=5f64,ID=
\"
childtable
\"
c1=3i64,c3=L
\"
passitagin_stf
\"
,c2=false,c5=5f64,c6=7u64
"
"
1626006933641ms"
,
"sth,t1=4i64,t2=5f64,t4=5f64 c1=3i64,c3=L
\"
passitagin_stf
\"
,c2=false,c5=5f64,c6=7u64 1626006933654ms"
};
code
=
taos_insert_lines
(
taos
,
lines3
,
2
);
char
*
lines4
[]
=
{
"st123456,t1=3i64,t2=4f64,t3=
\"
t3
\"
c1=3i64,c3=L
\"
passit
\"
,c2=false,c4=4f64 1626006833639000000ns"
,
"dgtyqodr,t2=5f64,t3=L
\"
ste
\"
c1=tRue,c2=4i64,c3=
\"
iam
\"
1626056811823316532ns"
};
char
*
lines4
[]
=
{
"st123456,t1=3i64,t2=4f64,t3=
\"
t3
\"
c1=3i64,c3=L
\"
passit
\"
,c2=false,c4=4f64 1626006833639000000ns"
,
"dgtyqodr,t2=5f64,t3=L
\"
ste
\"
c1=tRue,c2=4i64,c3=
\"
iam
\"
1626056811823316532ns"
};
code
=
taos_insert_lines
(
taos
,
lines4
,
2
);
char
*
lines5
[]
=
{
"zqlbgs,id=
\"
zqlbgs_39302_21680
\"
,t0=f,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=
\"
binaryTagValue
\"
,t8=L
\"
ncharTagValue
\"
c0=f,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=
\"
binaryColValue
\"
,c8=L
\"
ncharColValue
\"
,c9=7u64 1626006833639000000ns"
,
"zqlbgs,t9=f,id=
\"
zqlbgs_39302_21680
\"
,t0=f,t1=127i8,t11=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=
\"
binaryTagValue
\"
,t8=L
\"
ncharTagValue
\"
,t10=L
\"
ncharTagValue
\"
c10=f,c0=f,c1=127i8,c12=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=
\"
binaryColValue
\"
,c8=L
\"
ncharColValue
\"
,c9=7u64,c11=L
\"
ncharColValue
\"
1626006833639000000ns"
};
"zqlbgs,id=
\"
zqlbgs_39302_21680
\"
,t0=f,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11."
"12345f32,t6=22.123456789f64,t7=
\"
binaryTagValue
\"
,t8=L
\"
ncharTagValue
\"
"
"c0=f,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7="
"
\"
binaryColValue
\"
,c8=L
\"
ncharColValue
\"
,c9=7u64 1626006833639000000ns"
,
"zqlbgs,t9=f,id=
\"
zqlbgs_39302_21680
\"
,t0=f,t1=127i8,t11=127i8,t2=32767i16,t3=2147483647i32,t4="
"9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=
\"
binaryTagValue
\"
,t8=L
\"
ncharTagValue
\"
,t10="
"L
\"
ncharTagValue
\"
"
"c10=f,c0=f,c1=127i8,c12=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22."
"123456789f64,c7=
\"
binaryColValue
\"
,c8=L
\"
ncharColValue
\"
,c9=7u64,c11=L
\"
ncharColValue
\"
1626006833639000000ns"
};
code
=
taos_insert_lines
(
taos
,
&
lines5
[
0
],
1
);
code
=
taos_insert_lines
(
taos
,
&
lines5
[
1
],
1
);
char
*
lines6
[]
=
{
"st123456,t1=3i64,t2=4f64,t3=
\"
t3
\"
c1=3i64,c3=L
\"
passit
\"
,c2=false,c4=4f64 1626006833639000000ns"
,
"dgtyqodr,t2=5f64,t3=L
\"
ste
\"
c1=tRue,c2=4i64,c3=
\"
iam
\"
1626056811823316532ns"
};
char
*
lines6
[]
=
{
"st123456,t1=3i64,t2=4f64,t3=
\"
t3
\"
c1=3i64,c3=L
\"
passit
\"
,c2=false,c4=4f64 1626006833639000000ns"
,
"dgtyqodr,t2=5f64,t3=L
\"
ste
\"
c1=tRue,c2=4i64,c3=
\"
iam
\"
1626056811823316532ns"
};
code
=
taos_insert_lines
(
taos
,
lines6
,
2
);
return
(
code
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
const
char
*
host
=
"127.0.0.1"
;
const
char
*
user
=
"root"
;
const
char
*
passwd
=
"taosdata"
;
...
...
@@ -1034,7 +1066,6 @@ int main(int argc, char *argv[]) {
printf
(
"************ verify schema-less *************
\n
"
);
verify_schema_less
(
taos
);
printf
(
"************ verify query *************
\n
"
);
verify_query
(
taos
);
...
...
@@ -1053,7 +1084,7 @@ int main(int argc, char *argv[]) {
verify_prepare3
(
taos
);
printf
(
"************ verify stream *************
\n
"
);
verify_stream
(
taos
);
//
verify_stream(taos);
printf
(
"done
\n
"
);
taos_close
(
taos
);
taos_cleanup
();
...
...
tests/examples/c/asyncdemo.c
浏览文件 @
de59ed95
...
...
@@ -20,9 +20,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <unistd.h>
#include <string.h>
#include <taos.h>
...
...
@@ -34,7 +34,7 @@ int64_t st, et;
typedef
struct
{
int
id
;
TAOS
*
taos
;
TAOS
*
taos
;
char
name
[
16
];
time_t
timeStamp
;
int
value
;
...
...
@@ -76,15 +76,14 @@ static void queryDB(TAOS *taos, char *command) {
taos_free_result
(
pSql
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
TAOS
*
taos
;
int
main
(
int
argc
,
char
*
argv
[])
{
TAOS
*
taos
;
struct
timeval
systemTime
;
int
i
;
char
sql
[
1024
]
=
{
0
};
char
prefix
[
20
]
=
{
0
};
char
db
[
128
]
=
{
0
};
STable
*
tableList
;
char
sql
[
1024
]
=
{
0
};
char
prefix
[
20
]
=
{
0
};
char
db
[
128
]
=
{
0
};
STable
*
tableList
;
if
(
argc
!=
5
)
{
printf
(
"usage: %s server-ip dbname rowsPerTable numOfTables
\n
"
,
argv
[
0
]);
...
...
@@ -101,8 +100,7 @@ int main(int argc, char *argv[])
memset
(
tableList
,
0
,
size
);
taos
=
taos_connect
(
argv
[
1
],
"root"
,
"taosdata"
,
NULL
,
0
);
if
(
taos
==
NULL
)
taos_error
(
taos
);
if
(
taos
==
NULL
)
taos_error
(
taos
);
printf
(
"success to connect to server
\n
"
);
...
...
@@ -138,7 +136,7 @@ int main(int argc, char *argv[])
tablesInsertProcessed
=
0
;
tablesSelectProcessed
=
0
;
for
(
i
=
0
;
i
<
numOfTables
;
++
i
)
{
for
(
i
=
0
;
i
<
numOfTables
;
++
i
)
{
// insert records in asynchronous API
sprintf
(
sql
,
"insert into %s values(%ld, 0)"
,
tableList
[
i
].
name
,
1546300800000
+
i
);
taos_query_a
(
taos
,
sql
,
taos_insert_call_back
,
(
void
*
)(
tableList
+
i
));
...
...
@@ -147,7 +145,7 @@ int main(int argc, char *argv[])
printf
(
"once insert finished, presse any key to query
\n
"
);
getchar
();
while
(
1
)
{
while
(
1
)
{
if
(
tablesInsertProcessed
<
numOfTables
)
{
printf
(
"wait for process finished
\n
"
);
sleep
(
1
);
...
...
@@ -161,7 +159,6 @@ int main(int argc, char *argv[])
gettimeofday
(
&
systemTime
,
NULL
);
st
=
systemTime
.
tv_sec
*
1000000
+
systemTime
.
tv_usec
;
for
(
i
=
0
;
i
<
numOfTables
;
++
i
)
{
// select records in asynchronous API
sprintf
(
sql
,
"select * from %s"
,
tableList
[
i
].
name
);
...
...
@@ -171,7 +168,7 @@ int main(int argc, char *argv[])
printf
(
"
\n
once finished, press any key to exit
\n
"
);
getchar
();
while
(
1
)
{
while
(
1
)
{
if
(
tablesSelectProcessed
<
numOfTables
)
{
printf
(
"wait for process finished
\n
"
);
sleep
(
1
);
...
...
@@ -181,7 +178,7 @@ int main(int argc, char *argv[])
break
;
}
for
(
i
=
0
;
i
<
numOfTables
;
++
i
)
{
for
(
i
=
0
;
i
<
numOfTables
;
++
i
)
{
printf
(
"%s inserted:%d retrieved:%d
\n
"
,
tableList
[
i
].
name
,
tableList
[
i
].
rowsInserted
,
tableList
[
i
].
rowsRetrieved
);
}
...
...
@@ -193,17 +190,15 @@ int main(int argc, char *argv[])
return
0
;
}
void
taos_error
(
TAOS
*
con
)
{
void
taos_error
(
TAOS
*
con
)
{
fprintf
(
stderr
,
"TDengine error: %s
\n
"
,
taos_errstr
(
con
));
taos_close
(
con
);
taos_cleanup
();
exit
(
1
);
}
void
taos_insert_call_back
(
void
*
param
,
TAOS_RES
*
tres
,
int
code
)
{
STable
*
pTable
=
(
STable
*
)
param
;
void
taos_insert_call_back
(
void
*
param
,
TAOS_RES
*
tres
,
int
code
)
{
STable
*
pTable
=
(
STable
*
)
param
;
struct
timeval
systemTime
;
char
sql
[
128
];
...
...
@@ -211,42 +206,38 @@ void taos_insert_call_back(void *param, TAOS_RES *tres, int code)
if
(
code
<
0
)
{
printf
(
"%s insert failed, code:%d, rows:%d
\n
"
,
pTable
->
name
,
code
,
pTable
->
rowsTried
);
}
else
if
(
code
==
0
)
{
}
else
if
(
code
==
0
)
{
printf
(
"%s not inserted
\n
"
,
pTable
->
name
);
}
else
{
}
else
{
pTable
->
rowsInserted
++
;
}
if
(
pTable
->
rowsTried
<
points
)
{
// for this demo, insert another record
sprintf
(
sql
,
"insert into %s values(%ld, %d)"
,
pTable
->
name
,
1546300800000
+
pTable
->
rowsTried
*
1000
,
pTable
->
rowsTried
);
sprintf
(
sql
,
"insert into %s values(%ld, %d)"
,
pTable
->
name
,
1546300800000
+
pTable
->
rowsTried
*
1000
,
pTable
->
rowsTried
);
taos_query_a
(
pTable
->
taos
,
sql
,
taos_insert_call_back
,
(
void
*
)
pTable
);
}
else
{
}
else
{
printf
(
"%d rows data are inserted into %s
\n
"
,
points
,
pTable
->
name
);
tablesInsertProcessed
++
;
if
(
tablesInsertProcessed
>=
numOfTables
)
{
gettimeofday
(
&
systemTime
,
NULL
);
et
=
systemTime
.
tv_sec
*
1000000
+
systemTime
.
tv_usec
;
printf
(
"%lld mseconds to insert %d data points
\n
"
,
(
et
-
st
)
/
1000
,
points
*
numOfTables
);
printf
(
"%lld mseconds to insert %d data points
\n
"
,
(
et
-
st
)
/
1000
,
points
*
numOfTables
);
}
}
taos_free_result
(
tres
);
}
void
taos_retrieve_call_back
(
void
*
param
,
TAOS_RES
*
tres
,
int
numOfRows
)
{
STable
*
pTable
=
(
STable
*
)
param
;
void
taos_retrieve_call_back
(
void
*
param
,
TAOS_RES
*
tres
,
int
numOfRows
)
{
STable
*
pTable
=
(
STable
*
)
param
;
struct
timeval
systemTime
;
if
(
numOfRows
>
0
)
{
for
(
int
i
=
0
;
i
<
numOfRows
;
++
i
)
{
for
(
int
i
=
0
;
i
<
numOfRows
;
++
i
)
{
// synchronous API to retrieve a row from batch of records
/*TAOS_ROW row = */
(
void
)
taos_fetch_row
(
tres
);
/*TAOS_ROW row = */
(
void
)
taos_fetch_row
(
tres
);
// process row
}
...
...
@@ -255,12 +246,10 @@ void taos_retrieve_call_back(void *param, TAOS_RES *tres, int numOfRows)
// retrieve next batch of rows
taos_fetch_rows_a
(
tres
,
taos_retrieve_call_back
,
pTable
);
}
else
{
if
(
numOfRows
<
0
)
printf
(
"%s retrieve failed, code:%d
\n
"
,
pTable
->
name
,
numOfRows
);
}
else
{
if
(
numOfRows
<
0
)
printf
(
"%s retrieve failed, code:%d
\n
"
,
pTable
->
name
,
numOfRows
);
//taos_free_result(tres);
//
taos_free_result(tres);
printf
(
"%d rows data retrieved from %s
\n
"
,
pTable
->
rowsRetrieved
,
pTable
->
name
);
tablesSelectProcessed
++
;
...
...
@@ -272,19 +261,15 @@ void taos_retrieve_call_back(void *param, TAOS_RES *tres, int numOfRows)
taos_free_result
(
tres
);
}
}
void
taos_select_call_back
(
void
*
param
,
TAOS_RES
*
tres
,
int
code
)
{
void
taos_select_call_back
(
void
*
param
,
TAOS_RES
*
tres
,
int
code
)
{
STable
*
pTable
=
(
STable
*
)
param
;
if
(
code
==
0
&&
tres
)
{
// asynchronous API to fetch a batch of records
taos_fetch_rows_a
(
tres
,
taos_retrieve_call_back
,
pTable
);
}
else
{
}
else
{
printf
(
"%s select failed, code:%d
\n
"
,
pTable
->
name
,
code
);
taos_free_result
(
tres
);
taos_cleanup
();
...
...
tests/examples/c/demo.c
浏览文件 @
de59ed95
...
...
@@ -16,10 +16,10 @@
// TAOS standard API example. The same syntax as MySQL, but only a subset
// to compile: gcc -o demo demo.c -ltaos
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <taos.h> // TAOS header file
static
void
queryDB
(
TAOS
*
taos
,
char
*
command
)
{
...
...
@@ -63,7 +63,7 @@ int main(int argc, char *argv[]) {
TAOS
*
taos
=
taos_connect
(
argv
[
1
],
"root"
,
"taosdata"
,
NULL
,
0
);
if
(
taos
==
NULL
)
{
printf
(
"failed to connect to server, reason:%s
\n
"
,
"null taos"
/*taos_errstr(taos)*/
);
printf
(
"failed to connect to server, reason:%s
\n
"
,
"null taos"
/*taos_errstr(taos)*/
);
exit
(
1
);
}
for
(
int
i
=
0
;
i
<
100
;
i
++
)
{
...
...
@@ -79,12 +79,14 @@ void Test(TAOS *taos, char *qstr, int index) {
TAOS_RES
*
result
;
queryDB
(
taos
,
"use demo"
);
queryDB
(
taos
,
"create table m1 (ts timestamp, ti tinyint, si smallint, i int, bi bigint, f float, d double, b binary(10))"
);
queryDB
(
taos
,
"create table m1 (ts timestamp, ti tinyint, si smallint, i int, bi bigint, f float, d double, b binary(10))"
);
printf
(
"success to create table
\n
"
);
int
i
=
0
;
for
(
i
=
0
;
i
<
10
;
++
i
)
{
sprintf
(
qstr
,
"insert into m1 values (%"
PRId64
", %d, %d, %d, %d, %f, %lf, '%s')"
,
(
uint64_t
)(
1546300800000
+
i
*
1000
),
i
,
i
,
i
,
i
*
10000000
,
i
*
1
.
0
,
i
*
2
.
0
,
"hello"
);
sprintf
(
qstr
,
"insert into m1 values (%"
PRId64
", %d, %d, %d, %d, %f, %lf, '%s')"
,
(
uint64_t
)(
1546300800000
+
i
*
1000
),
i
,
i
,
i
,
i
*
10000000
,
i
*
1
.
0
,
i
*
2
.
0
,
"hello"
);
printf
(
"qstr: %s
\n
"
,
qstr
);
// note: how do you wanna do if taos_query returns non-NULL
...
...
@@ -130,4 +132,3 @@ void Test(TAOS *taos, char *qstr, int index) {
taos_free_result
(
result
);
printf
(
"====demo end====
\n\n
"
);
}
tests/examples/c/epoll.c
浏览文件 @
de59ed95
...
...
@@ -24,39 +24,36 @@
#else // __APPLE__
#include <sys/epoll.h>
#endif // __APPLE__
#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <libgen.h>
#include <locale.h>
#include <netdb.h>
#include <netinet/in.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#define D(fmt, ...) fprintf(stderr, "%s[%d]%s(): " fmt "\n", basename(__FILE__), __LINE__, __func__, ##__VA_ARGS__)
#define A(statement, fmt, ...) do { \
#define A(statement, fmt, ...) \
do { \
if (statement) break; \
fprintf(stderr, "%s[%d]%s(): assert [%s] failed: %d[%s]: " fmt "\n", \
basename(__FILE__), __LINE__, __func__, \
#statement, errno, strerror(errno), \
##__VA_ARGS__); \
fprintf(stderr, "%s[%d]%s(): assert [%s] failed: %d[%s]: " fmt "\n", basename(__FILE__), __LINE__, __func__, \
#statement, errno, strerror(errno), ##__VA_ARGS__); \
abort(); \
} while (0)
} while (0)
#define E(fmt, ...) do { \
fprintf(stderr, "%s[%d]%s(): %d[%s]: " fmt "\n", \
basename(__FILE__), __LINE__, __func__, \
errno, strerror(errno), \
#define E(fmt, ...) \
do { \
fprintf(stderr, "%s[%d]%s(): %d[%s]: " fmt "\n", basename(__FILE__), __LINE__, __func__, errno, strerror(errno), \
##__VA_ARGS__); \
} while (0)
} while (0)
#include "os.h"
...
...
@@ -68,16 +65,16 @@ struct ep_s {
int
sv
[
2
];
// 0 for read, 1 for write;
pthread_t
thread
;
volatile
unsigned
int
stopping
:
1
;
volatile
unsigned
int
waiting
:
1
;
volatile
unsigned
int
wakenup
:
1
;
volatile
unsigned
int
stopping
:
1
;
volatile
unsigned
int
waiting
:
1
;
volatile
unsigned
int
wakenup
:
1
;
};
static
int
ep_dummy
=
0
;
static
ep_t
*
ep_create
(
void
);
static
ep_t
*
ep_create
(
void
);
static
void
ep_destroy
(
ep_t
*
ep
);
static
void
*
routine
(
void
*
arg
);
static
void
*
routine
(
void
*
arg
);
static
int
open_listen
(
unsigned
short
port
);
typedef
struct
fde_s
fde_t
;
...
...
@@ -89,35 +86,36 @@ struct fde_s {
static
void
listen_event
(
ep_t
*
ep
,
struct
epoll_event
*
ev
,
fde_t
*
client
);
static
void
null_event
(
ep_t
*
ep
,
struct
epoll_event
*
ev
,
fde_t
*
client
);
#define usage(arg0, fmt, ...) do { \
#define usage(arg0, fmt, ...) \
do { \
if (fmt[0]) { \
fprintf(stderr, "" fmt "\n", ##__VA_ARGS__); \
} \
fprintf(stderr, "usage:\n"); \
fprintf(stderr, " %s -l <port> : specify listenning port\n", arg0); \
} while (0)
} while (0)
int
main
(
int
argc
,
char
*
argv
[])
{
char
*
prg
=
basename
(
argv
[
0
]);
if
(
argc
==
1
)
{
if
(
argc
==
1
)
{
usage
(
prg
,
""
);
return
0
;
}
ep_t
*
ep
=
ep_create
();
ep_t
*
ep
=
ep_create
();
A
(
ep
,
"failed"
);
for
(
int
i
=
1
;
i
<
argc
;
++
i
)
{
for
(
int
i
=
1
;
i
<
argc
;
++
i
)
{
const
char
*
arg
=
argv
[
i
];
if
(
0
==
strcmp
(
arg
,
"-l"
))
{
if
(
0
==
strcmp
(
arg
,
"-l"
))
{
++
i
;
if
(
i
>=
argc
)
{
if
(
i
>=
argc
)
{
usage
(
prg
,
"expecting <port> after -l, but got nothing"
);
return
1
;
// confirmed potential leakage
}
arg
=
argv
[
i
];
int
port
=
atoi
(
arg
);
int
skt
=
open_listen
(
port
);
if
(
skt
==
-
1
)
continue
;
fde_t
*
client
=
(
fde_t
*
)
calloc
(
1
,
sizeof
(
*
client
));
if
(
skt
==
-
1
)
continue
;
fde_t
*
client
=
(
fde_t
*
)
calloc
(
1
,
sizeof
(
*
client
));
if
(
!
client
)
{
E
(
"out of memory"
);
close
(
skt
);
...
...
@@ -128,30 +126,30 @@ int main(int argc, char *argv[]) {
struct
epoll_event
ev
=
{
0
};
ev
.
events
=
EPOLLIN
|
EPOLLERR
|
EPOLLHUP
|
EPOLLRDHUP
;
ev
.
data
.
ptr
=
client
;
A
(
0
==
epoll_ctl
(
ep
->
ep
,
EPOLL_CTL_ADD
,
skt
,
&
ev
),
""
);
A
(
0
==
epoll_ctl
(
ep
->
ep
,
EPOLL_CTL_ADD
,
skt
,
&
ev
),
""
);
continue
;
}
usage
(
prg
,
"unknown argument: [%s]"
,
arg
);
return
1
;
}
char
*
line
=
NULL
;
char
*
line
=
NULL
;
size_t
linecap
=
0
;
ssize_t
linelen
;
while
((
linelen
=
getline
(
&
line
,
&
linecap
,
stdin
))
>
0
)
{
line
[
strlen
(
line
)
-
1
]
=
'\0'
;
if
(
0
==
strcmp
(
line
,
"exit"
))
break
;
if
(
0
==
strcmp
(
line
,
"quit"
))
break
;
if
(
line
==
strstr
(
line
,
"close"
))
{
line
[
strlen
(
line
)
-
1
]
=
'\0'
;
if
(
0
==
strcmp
(
line
,
"exit"
))
break
;
if
(
0
==
strcmp
(
line
,
"quit"
))
break
;
if
(
line
==
strstr
(
line
,
"close"
))
{
int
fd
=
0
;
sscanf
(
line
,
"close %d"
,
&
fd
);
if
(
fd
<=
2
)
{
if
(
fd
<=
2
)
{
fprintf
(
stderr
,
"fd [%d] invalid
\n
"
,
fd
);
continue
;
}
A
(
0
==
epoll_ctl
(
ep
->
ep
,
EPOLL_CTL_DEL
,
fd
,
NULL
),
""
);
A
(
0
==
epoll_ctl
(
ep
->
ep
,
EPOLL_CTL_DEL
,
fd
,
NULL
),
""
);
continue
;
}
if
(
strlen
(
line
)
==
0
)
continue
;
if
(
strlen
(
line
)
==
0
)
continue
;
fprintf
(
stderr
,
"unknown cmd:[%s]
\n
"
,
line
);
}
ep_destroy
(
ep
);
...
...
@@ -159,69 +157,69 @@ int main(int argc, char *argv[]) {
return
0
;
}
ep_t
*
ep_create
(
void
)
{
ep_t
*
ep
=
(
ep_t
*
)
calloc
(
1
,
sizeof
(
*
ep
));
ep_t
*
ep_create
(
void
)
{
ep_t
*
ep
=
(
ep_t
*
)
calloc
(
1
,
sizeof
(
*
ep
));
A
(
ep
,
"out of memory"
);
A
(
-
1
!=
(
ep
->
ep
=
epoll_create
(
1
)),
""
);
A
(
-
1
!=
(
ep
->
ep
=
epoll_create
(
1
)),
""
);
ep
->
sv
[
0
]
=
-
1
;
ep
->
sv
[
1
]
=
-
1
;
A
(
0
==
socketpair
(
AF_LOCAL
,
SOCK_STREAM
,
0
,
ep
->
sv
),
""
);
A
(
0
==
pthread_mutex_init
(
&
ep
->
lock
,
NULL
),
""
);
A
(
0
==
pthread_mutex_lock
(
&
ep
->
lock
),
""
);
A
(
0
==
socketpair
(
AF_LOCAL
,
SOCK_STREAM
,
0
,
ep
->
sv
),
""
);
A
(
0
==
pthread_mutex_init
(
&
ep
->
lock
,
NULL
),
""
);
A
(
0
==
pthread_mutex_lock
(
&
ep
->
lock
),
""
);
struct
epoll_event
ev
=
{
0
};
ev
.
events
=
EPOLLIN
;
ev
.
data
.
ptr
=
&
ep_dummy
;
A
(
0
==
epoll_ctl
(
ep
->
ep
,
EPOLL_CTL_ADD
,
ep
->
sv
[
0
],
&
ev
),
""
);
A
(
0
==
pthread_create
(
&
ep
->
thread
,
NULL
,
routine
,
ep
),
""
);
A
(
0
==
pthread_mutex_unlock
(
&
ep
->
lock
),
""
);
A
(
0
==
epoll_ctl
(
ep
->
ep
,
EPOLL_CTL_ADD
,
ep
->
sv
[
0
],
&
ev
),
""
);
A
(
0
==
pthread_create
(
&
ep
->
thread
,
NULL
,
routine
,
ep
),
""
);
A
(
0
==
pthread_mutex_unlock
(
&
ep
->
lock
),
""
);
return
ep
;
}
static
void
ep_destroy
(
ep_t
*
ep
)
{
A
(
ep
,
"invalid argument"
);
ep
->
stopping
=
1
;
A
(
1
==
send
(
ep
->
sv
[
1
],
"1"
,
1
,
0
),
""
);
A
(
0
==
pthread_join
(
ep
->
thread
,
NULL
),
""
);
A
(
0
==
pthread_mutex_destroy
(
&
ep
->
lock
),
""
);
A
(
0
==
close
(
ep
->
sv
[
0
]),
""
);
A
(
0
==
close
(
ep
->
sv
[
1
]),
""
);
A
(
0
==
close
(
ep
->
ep
),
""
);
A
(
1
==
send
(
ep
->
sv
[
1
],
"1"
,
1
,
0
),
""
);
A
(
0
==
pthread_join
(
ep
->
thread
,
NULL
),
""
);
A
(
0
==
pthread_mutex_destroy
(
&
ep
->
lock
),
""
);
A
(
0
==
close
(
ep
->
sv
[
0
]),
""
);
A
(
0
==
close
(
ep
->
sv
[
1
]),
""
);
A
(
0
==
close
(
ep
->
ep
),
""
);
free
(
ep
);
}
static
void
*
routine
(
void
*
arg
)
{
static
void
*
routine
(
void
*
arg
)
{
A
(
arg
,
"invalid argument"
);
ep_t
*
ep
=
(
ep_t
*
)
arg
;
ep_t
*
ep
=
(
ep_t
*
)
arg
;
while
(
!
ep
->
stopping
)
{
struct
epoll_event
evs
[
10
];
memset
(
evs
,
0
,
sizeof
(
evs
));
A
(
0
==
pthread_mutex_lock
(
&
ep
->
lock
),
""
);
A
(
ep
->
waiting
==
0
,
"internal logic error"
);
A
(
0
==
pthread_mutex_lock
(
&
ep
->
lock
),
""
);
A
(
ep
->
waiting
==
0
,
"internal logic error"
);
ep
->
waiting
=
1
;
A
(
0
==
pthread_mutex_unlock
(
&
ep
->
lock
),
""
);
A
(
0
==
pthread_mutex_unlock
(
&
ep
->
lock
),
""
);
int
r
=
epoll_wait
(
ep
->
ep
,
evs
,
sizeof
(
evs
)
/
sizeof
(
evs
[
0
]),
-
1
);
A
(
r
>
0
,
"indefinite epoll_wait shall not timeout:[%d]"
,
r
);
int
r
=
epoll_wait
(
ep
->
ep
,
evs
,
sizeof
(
evs
)
/
sizeof
(
evs
[
0
]),
-
1
);
A
(
r
>
0
,
"indefinite epoll_wait shall not timeout:[%d]"
,
r
);
A
(
0
==
pthread_mutex_lock
(
&
ep
->
lock
),
""
);
A
(
ep
->
waiting
==
1
,
"internal logic error"
);
A
(
0
==
pthread_mutex_lock
(
&
ep
->
lock
),
""
);
A
(
ep
->
waiting
==
1
,
"internal logic error"
);
ep
->
waiting
=
0
;
A
(
0
==
pthread_mutex_unlock
(
&
ep
->
lock
),
""
);
A
(
0
==
pthread_mutex_unlock
(
&
ep
->
lock
),
""
);
for
(
int
i
=
0
;
i
<
r
;
++
i
)
{
for
(
int
i
=
0
;
i
<
r
;
++
i
)
{
struct
epoll_event
*
ev
=
evs
+
i
;
if
(
ev
->
data
.
ptr
==
&
ep_dummy
)
{
char
c
=
'\0'
;
A
(
1
==
recv
(
ep
->
sv
[
0
],
&
c
,
1
,
0
),
"internal logic error"
);
A
(
0
==
pthread_mutex_lock
(
&
ep
->
lock
),
""
);
A
(
1
==
recv
(
ep
->
sv
[
0
],
&
c
,
1
,
0
),
"internal logic error"
);
A
(
0
==
pthread_mutex_lock
(
&
ep
->
lock
),
""
);
ep
->
wakenup
=
0
;
A
(
0
==
pthread_mutex_unlock
(
&
ep
->
lock
),
""
);
A
(
0
==
pthread_mutex_unlock
(
&
ep
->
lock
),
""
);
continue
;
}
A
(
ev
->
data
.
ptr
,
"internal logic error"
);
fde_t
*
client
=
(
fde_t
*
)
ev
->
data
.
ptr
;
fde_t
*
client
=
(
fde_t
*
)
ev
->
data
.
ptr
;
client
->
on_event
(
ep
,
ev
,
client
);
continue
;
}
...
...
@@ -232,7 +230,7 @@ static void* routine(void* arg) {
static
int
open_listen
(
unsigned
short
port
)
{
int
r
=
0
;
int
skt
=
socket
(
AF_INET
,
SOCK_STREAM
,
IPPROTO_TCP
);
if
(
skt
==
-
1
)
{
if
(
skt
==
-
1
)
{
E
(
"socket() failed"
);
return
-
1
;
}
...
...
@@ -241,7 +239,7 @@ static int open_listen(unsigned short port) {
si
.
sin_family
=
AF_INET
;
si
.
sin_addr
.
s_addr
=
inet_addr
(
"0.0.0.0"
);
si
.
sin_port
=
htons
(
port
);
r
=
bind
(
skt
,
(
struct
sockaddr
*
)
&
si
,
sizeof
(
si
));
r
=
bind
(
skt
,
(
struct
sockaddr
*
)
&
si
,
sizeof
(
si
));
if
(
r
)
{
E
(
"bind(%u) failed"
,
port
);
break
;
...
...
@@ -257,7 +255,7 @@ static int open_listen(unsigned short port) {
if
(
r
)
{
E
(
"getsockname() failed"
);
}
A
(
len
==
sizeof
(
si
),
"internal logic error"
);
A
(
len
==
sizeof
(
si
),
"internal logic error"
);
D
(
"listenning at: %d"
,
ntohs
(
si
.
sin_port
));
return
skt
;
}
while
(
0
);
...
...
@@ -269,9 +267,9 @@ static void listen_event(ep_t *ep, struct epoll_event *ev, fde_t *client) {
A
(
ev
->
events
&
EPOLLIN
,
"internal logic error"
);
struct
sockaddr_in
si
=
{
0
};
socklen_t
silen
=
sizeof
(
si
);
int
skt
=
accept
(
client
->
skt
,
(
struct
sockaddr
*
)
&
si
,
&
silen
);
A
(
skt
!=
-
1
,
"internal logic error"
);
fde_t
*
server
=
(
fde_t
*
)
calloc
(
1
,
sizeof
(
*
server
));
int
skt
=
accept
(
client
->
skt
,
(
struct
sockaddr
*
)
&
si
,
&
silen
);
A
(
skt
!=
-
1
,
"internal logic error"
);
fde_t
*
server
=
(
fde_t
*
)
calloc
(
1
,
sizeof
(
*
server
));
if
(
!
server
)
{
close
(
skt
);
return
;
...
...
@@ -281,24 +279,23 @@ static void listen_event(ep_t *ep, struct epoll_event *ev, fde_t *client) {
struct
epoll_event
ee
=
{
0
};
ee
.
events
=
EPOLLIN
|
EPOLLERR
|
EPOLLHUP
|
EPOLLRDHUP
;
ee
.
data
.
ptr
=
server
;
A
(
0
==
epoll_ctl
(
ep
->
ep
,
EPOLL_CTL_ADD
,
skt
,
&
ee
),
""
);
A
(
0
==
epoll_ctl
(
ep
->
ep
,
EPOLL_CTL_ADD
,
skt
,
&
ee
),
""
);
}
static
void
null_event
(
ep_t
*
ep
,
struct
epoll_event
*
ev
,
fde_t
*
client
)
{
if
(
ev
->
events
&
EPOLLIN
)
{
char
buf
[
8192
];
int
n
=
recv
(
client
->
skt
,
buf
,
sizeof
(
buf
),
0
);
A
(
n
>=
0
&&
n
<=
sizeof
(
buf
),
"internal logic error:[%d]"
,
n
);
A
(
n
==
fwrite
(
buf
,
1
,
n
,
stdout
),
"internal logic error"
);
A
(
n
>=
0
&&
n
<=
sizeof
(
buf
),
"internal logic error:[%d]"
,
n
);
A
(
n
==
fwrite
(
buf
,
1
,
n
,
stdout
),
"internal logic error"
);
}
if
(
ev
->
events
&
(
EPOLLERR
|
EPOLLHUP
|
EPOLLRDHUP
))
{
A
(
0
==
pthread_mutex_lock
(
&
ep
->
lock
),
""
);
A
(
0
==
epoll_ctl
(
ep
->
ep
,
EPOLL_CTL_DEL
,
client
->
skt
,
NULL
),
""
);
A
(
0
==
pthread_mutex_unlock
(
&
ep
->
lock
),
""
);
A
(
0
==
pthread_mutex_lock
(
&
ep
->
lock
),
""
);
A
(
0
==
epoll_ctl
(
ep
->
ep
,
EPOLL_CTL_DEL
,
client
->
skt
,
NULL
),
""
);
A
(
0
==
pthread_mutex_unlock
(
&
ep
->
lock
),
""
);
close
(
client
->
skt
);
client
->
skt
=
-
1
;
client
->
on_event
=
NULL
;
free
(
client
);
}
}
tests/examples/c/makefile
浏览文件 @
de59ed95
...
...
@@ -17,14 +17,11 @@ exe:
gcc
$(CFLAGS)
./stream.c
-o
$(ROOT)
stream
$(LFLAGS)
gcc
$(CFLAGS)
./subscribe.c
-o
$(ROOT)
subscribe
$(LFLAGS)
gcc
$(CFLAGS)
./apitest.c
-o
$(ROOT)
apitest
$(LFLAGS)
gcc
$(CFLAGS)
./stmt.c
-o
$(ROOT)
stmt
$(LFLAGS)
clean
:
rm
$(ROOT)
asyncdemo
rm
$(ROOT)
demo
rm
$(ROOT)
prepare
rm
$(ROOT)
batchprepare
rm
$(ROOT)
stream
rm
$(ROOT)
subscribe
rm
$(ROOT)
apitest
rm
$(ROOT)
stmt
tests/examples/c/prepare.c
浏览文件 @
de59ed95
...
...
@@ -6,13 +6,11 @@
#include <string.h>
#include "taos.h"
void
taosMsleep
(
int
mseconds
);
int
main
(
int
argc
,
char
*
argv
[])
{
TAOS
*
taos
;
TAOS_RES
*
result
;
int
main
(
int
argc
,
char
*
argv
[])
{
TAOS
*
taos
;
TAOS_RES
*
result
;
int
code
;
TAOS_STMT
*
stmt
;
...
...
@@ -44,7 +42,9 @@ int main(int argc, char *argv[])
taos_free_result
(
result
);
// create table
const
char
*
sql
=
"create table m1 (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin binary(40), blob nchar(10))"
;
const
char
*
sql
=
"create table m1 (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin "
"binary(40), blob nchar(10))"
;
result
=
taos_query
(
taos
,
sql
);
code
=
taos_errno
(
result
);
if
(
code
!=
0
)
{
...
...
@@ -138,7 +138,7 @@ int main(int argc, char *argv[])
sql
=
"insert into m1 values(?,?,?,?,?,?,?,?,?,?)"
;
code
=
taos_stmt_prepare
(
stmt
,
sql
,
0
);
if
(
code
!=
0
){
if
(
code
!=
0
)
{
printf
(
"failed to execute taos_stmt_prepare. code:0x%x
\n
"
,
code
);
}
v
.
ts
=
1591060628000
;
...
...
@@ -203,4 +203,3 @@ int main(int argc, char *argv[])
return
0
;
}
tests/examples/c/schemaless.c
浏览文件 @
de59ed95
#include "os.h"
#include "taos.h"
#include "taoserror.h"
#include "os.h"
#include <stdio.h>
#include <stdlib.h>
...
...
@@ -12,13 +12,10 @@ int numSuperTables = 8;
int
numChildTables
=
4
;
int
numRowsPerChildTable
=
2048
;
void
shuffle
(
char
**
lines
,
size_t
n
)
{
if
(
n
>
1
)
{
void
shuffle
(
char
**
lines
,
size_t
n
)
{
if
(
n
>
1
)
{
size_t
i
;
for
(
i
=
0
;
i
<
n
-
1
;
i
++
)
{
for
(
i
=
0
;
i
<
n
-
1
;
i
++
)
{
size_t
j
=
i
+
rand
()
/
(
RAND_MAX
/
(
n
-
i
)
+
1
);
char
*
t
=
lines
[
j
];
lines
[
j
]
=
lines
[
i
];
...
...
@@ -34,7 +31,7 @@ static int64_t getTimeInUs() {
}
int
main
(
int
argc
,
char
*
argv
[])
{
TAOS_RES
*
result
;
TAOS_RES
*
result
;
const
char
*
host
=
"127.0.0.1"
;
const
char
*
user
=
"root"
;
const
char
*
passwd
=
"taosdata"
;
...
...
@@ -61,7 +58,11 @@ int main(int argc, char* argv[]) {
time_t
ct
=
time
(
0
);
int64_t
ts
=
ct
*
1000
;
char
*
lineFormat
=
"sta%d,t0=true,t1=127i8,t2=32767i16,t3=%di32,t4=9223372036854775807i64,t9=11.12345f32,t10=22.123456789f64,t11=
\"
binaryTagValue
\"
,t12=L
\"
ncharTagValue
\"
c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=255u8,c6=32770u16,c7=2147483699u32,c8=9223372036854775899u64,c9=11.12345f32,c10=22.123456789f64,c11=
\"
binaryValue
\"
,c12=L
\"
ncharValue
\"
%lldms"
;
char
*
lineFormat
=
"sta%d,t0=true,t1=127i8,t2=32767i16,t3=%di32,t4=9223372036854775807i64,t9=11.12345f32,t10=22.123456789f64,t11="
"
\"
binaryTagValue
\"
,t12=L
\"
ncharTagValue
\"
"
"c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=255u8,c6=32770u16,c7=2147483699u32,"
"c8=9223372036854775899u64,c9=11.12345f32,c10=22.123456789f64,c11=
\"
binaryValue
\"
,c12=L
\"
ncharValue
\"
%lldms"
;
char
**
lines
=
calloc
(
numSuperTables
*
numChildTables
*
numRowsPerChildTable
,
sizeof
(
char
*
));
int
l
=
0
;
...
...
@@ -81,118 +82,139 @@ int main(int argc, char* argv[]) {
int64_t
begin
=
getTimeInUs
();
int32_t
code
=
taos_insert_lines
(
taos
,
lines
,
numSuperTables
*
numChildTables
*
numRowsPerChildTable
);
int64_t
end
=
getTimeInUs
();
printf
(
"code: %d, %s. time used: %"
PRId64
"
\n
"
,
code
,
tstrerror
(
code
),
end
-
begin
);
printf
(
"code: %d, %s. time used: %"
PRId64
"
\n
"
,
code
,
tstrerror
(
code
),
end
-
begin
);
char
*
lines_000_0
[]
=
{
"sta1,id=sta1_1,t0=true,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=255u8,t6=32770u16,t7=2147483699u32,t8=9223372036854775899u64,t9=11.12345f32,t10=22.123456789f64,t11=
\"
binaryTagValue
\"
,t12=L
\"
ncharTagValue
\"
c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=255u8,c6=32770u16,c7=2147483699u32,c8=9223372036854775899u64,c9=11.12345f32,c10=22.123456789f64,c11=
\"
binaryValue
\"
,c12=L
\"
ncharValue
\"
1626006833639000us"
};
code
=
taos_insert_lines
(
taos
,
lines_000_0
,
sizeof
(
lines_000_0
)
/
sizeof
(
char
*
));
"sta1,id=sta1_1,t0=true,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=255u8,t6=32770u16,t7="
"2147483699u32,t8=9223372036854775899u64,t9=11.12345f32,t10=22.123456789f64,t11=
\"
binaryTagValue
\"
,t12="
"L
\"
ncharTagValue
\"
"
"c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=255u8,c6=32770u16,c7=2147483699u32,"
"c8=9223372036854775899u64,c9=11.12345f32,c10=22.123456789f64,c11=
\"
binaryValue
\"
,c12=L
\"
ncharValue
\"
"
"1626006833639000us"
};
code
=
taos_insert_lines
(
taos
,
lines_000_0
,
sizeof
(
lines_000_0
)
/
sizeof
(
char
*
));
if
(
0
==
code
)
{
printf
(
"taos_insert_lines() lines_000_0 should return error
\n
"
);
return
-
1
;
}
char
*
lines_000_1
[]
=
{
"sta2,id=
\"
sta2_1
\"
,t0=true,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=255u8,t6=32770u16,t7=2147483699u32,t8=9223372036854775899u64,t9=11.12345f32,t10=22.123456789f64,t11=
\"
binaryTagValue
\"
,t12=L
\"
ncharTagValue
\"
c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=255u8,c6=32770u16,c7=2147483699u32,c8=9223372036854775899u64,c9=11.12345f32,c10=22.123456789f64,c11=
\"
binaryValue
\"
,c12=L
\"
ncharValue
\"
1626006833639001"
};
code
=
taos_insert_lines
(
taos
,
lines_000_1
,
sizeof
(
lines_000_1
)
/
sizeof
(
char
*
));
"sta2,id=
\"
sta2_1
\"
,t0=true,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=255u8,t6=32770u16,"
"t7=2147483699u32,t8=9223372036854775899u64,t9=11.12345f32,t10=22.123456789f64,t11=
\"
binaryTagValue
\"
,t12="
"L
\"
ncharTagValue
\"
"
"c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=255u8,c6=32770u16,c7=2147483699u32,"
"c8=9223372036854775899u64,c9=11.12345f32,c10=22.123456789f64,c11=
\"
binaryValue
\"
,c12=L
\"
ncharValue
\"
"
"1626006833639001"
};
code
=
taos_insert_lines
(
taos
,
lines_000_1
,
sizeof
(
lines_000_1
)
/
sizeof
(
char
*
));
if
(
0
==
code
)
{
printf
(
"taos_insert_lines() lines_000_1 should return error
\n
"
);
return
-
1
;
}
char
*
lines_000_2
[]
=
{
"sta3,id=
\"
sta3_1
\"
,t0=true,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t9=11.12345f32,t10=22.123456789f64,t11=
\"
binaryTagValue
\"
,t12=L
\"
ncharTagValue
\"
c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=255u8,c6=32770u16,c7=2147483699u32,c8=9223372036854775899u64,c9=11.12345f32,c10=22.123456789f64,c11=
\"
binaryValue
\"
,c12=L
\"
ncharValue
\"
0"
};
"sta3,id=
\"
sta3_1
\"
,t0=true,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t9=11.12345f32,t10="
"22.123456789f64,t11=
\"
binaryTagValue
\"
,t12=L
\"
ncharTagValue
\"
"
"c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=255u8,c6=32770u16,c7=2147483699u32,"
"c8=9223372036854775899u64,c9=11.12345f32,c10=22.123456789f64,c11=
\"
binaryValue
\"
,c12=L
\"
ncharValue
\"
0"
};
code
=
taos_insert_lines
(
taos
,
lines_000_2
,
sizeof
(
lines_000_2
)
/
sizeof
(
char
*
));
code
=
taos_insert_lines
(
taos
,
lines_000_2
,
sizeof
(
lines_000_2
)
/
sizeof
(
char
*
));
if
(
0
!=
code
)
{
printf
(
"taos_insert_lines() lines_000_2 return code:%d (%s)
\n
"
,
code
,
(
char
*
)
tstrerror
(
code
));
return
-
1
;
}
char
*
lines_001_0
[]
=
{
"sta4,t0=true,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t9=11.12345f32,t10=22.123456789f64,t11=
\"
binaryTagValue
\"
,t12=L
\"
ncharTagValue
\"
c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c9=11.12345f32,c10=22.123456789f64,c11=
\"
binaryValue
\"
,c12=L
\"
ncharValue
\"
1626006833639000us"
,
"sta4,t0=true,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t9=11.12345f32,t10=22.123456789f64,"
"t11=
\"
binaryTagValue
\"
,t12=L
\"
ncharTagValue
\"
"
"c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c9=11.12345f32,c10=22.123456789f64,c11="
"
\"
binaryValue
\"
,c12=L
\"
ncharValue
\"
1626006833639000us"
,
};
code
=
taos_insert_lines
(
taos
,
lines_001_0
,
sizeof
(
lines_001_0
)
/
sizeof
(
char
*
));
code
=
taos_insert_lines
(
taos
,
lines_001_0
,
sizeof
(
lines_001_0
)
/
sizeof
(
char
*
));
if
(
0
!=
code
)
{
printf
(
"taos_insert_lines() lines_001_0 return code:%d (%s)
\n
"
,
code
,
(
char
*
)
tstrerror
(
code
));
return
-
1
;
}
char
*
lines_001_1
[]
=
{
"sta5,id=
\"
sta5_1
\"
,t0=true,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t9=11.12345f32,t10=22.123456789f64,t11=
\"
binaryTagValue
\"
,t12=L
\"
ncharTagValue
\"
c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c9=11.12345f32,c10=22.123456789f64,c11=
\"
binaryValue
\"
,c12=L
\"
ncharValue
\"
1626006833639001"
};
"sta5,id=
\"
sta5_1
\"
,t0=true,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t9=11.12345f32,t10="
"22.123456789f64,t11=
\"
binaryTagValue
\"
,t12=L
\"
ncharTagValue
\"
"
"c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c9=11.12345f32,c10=22.123456789f64,c11="
"
\"
binaryValue
\"
,c12=L
\"
ncharValue
\"
1626006833639001"
};
code
=
taos_insert_lines
(
taos
,
lines_001_1
,
sizeof
(
lines_001_1
)
/
sizeof
(
char
*
));
code
=
taos_insert_lines
(
taos
,
lines_001_1
,
sizeof
(
lines_001_1
)
/
sizeof
(
char
*
));
if
(
0
!=
code
)
{
printf
(
"taos_insert_lines() lines_001_1 return code:%d (%s)
\n
"
,
code
,
(
char
*
)
tstrerror
(
code
));
return
-
1
;
}
char
*
lines_001_2
[]
=
{
"sta6,id=
\"
sta6_1
\"
,t0=true,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t9=11.12345f32,t10=22.123456789f64,t11=
\"
binaryTagValue
\"
,t12=L
\"
ncharTagValue
\"
c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c9=11.12345f32,c10=22.123456789f64,c11=
\"
binaryValue
\"
,c12=L
\"
ncharValue
\"
0"
};
"sta6,id=
\"
sta6_1
\"
,t0=true,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t9=11.12345f32,t10="
"22.123456789f64,t11=
\"
binaryTagValue
\"
,t12=L
\"
ncharTagValue
\"
"
"c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c9=11.12345f32,c10=22.123456789f64,c11="
"
\"
binaryValue
\"
,c12=L
\"
ncharValue
\"
0"
};
code
=
taos_insert_lines
(
taos
,
lines_001_2
,
sizeof
(
lines_001_2
)
/
sizeof
(
char
*
));
code
=
taos_insert_lines
(
taos
,
lines_001_2
,
sizeof
(
lines_001_2
)
/
sizeof
(
char
*
));
if
(
0
!=
code
)
{
printf
(
"taos_insert_lines() lines_001_2 return code:%d (%s)
\n
"
,
code
,
(
char
*
)
tstrerror
(
code
));
return
-
1
;
}
char
*
lines_002
[]
=
{
"stb,id=
\"
stb_1
\"
,t20=t,t21=T,t22=true,t23=True,t24=TRUE,t25=f,t26=F,t27=false,t28=False,t29=FALSE,t10=33.12345,t11=
\"
binaryTagValue
\"
,t12=L
\"
ncharTagValue
\"
c20=t,c21=T,c22=true,c23=True,c24=TRUE,c25=f,c26=F,c27=false,c28=False,c29=FALSE,c10=33.12345,c11=
\"
binaryValue
\"
,c12=L
\"
ncharValue
\"
1626006833639000000ns"
,
"stc,id=
\"
stc_1
\"
,t20=t,t21=T,t22=true,t23=True,t24=TRUE,t25=f,t26=F,t27=false,t28=False,t29=FALSE,t10=33.12345,t11=
\"
binaryTagValue
\"
,t12=L
\"
ncharTagValue
\"
c20=t,c21=T,c22=true,c23=True,c24=TRUE,c25=f,c26=F,c27=false,c28=False,c29=FALSE,c10=33.12345,c11=
\"
binaryValue
\"
,c12=L
\"
ncharValue
\"
1626006833639019us"
,
"stc,id=
\"
stc_1
\"
,t20=t,t21=T,t22=true,t23=True,t24=TRUE,t25=f,t26=F,t27=false,t28=False,t29=FALSE,t10=33.12345,t11=
\"
binaryTagValue
\"
,t12=L
\"
ncharTagValue
\"
c20=t,c21=T,c22=true,c23=True,c24=TRUE,c25=f,c26=F,c27=false,c28=False,c29=FALSE,c10=33.12345,c11=
\"
binaryValue
\"
,c12=L
\"
ncharValue
\"
1626006833640ms"
,
"stc,id=
\"
stc_1
\"
,t20=t,t21=T,t22=true,t23=True,t24=TRUE,t25=f,t26=F,t27=false,t28=False,t29=FALSE,t10=33.12345,t11=
\"
binaryTagValue
\"
,t12=L
\"
ncharTagValue
\"
c20=t,c21=T,c22=true,c23=True,c24=TRUE,c25=f,c26=F,c27=false,c28=False,c29=FALSE,c10=33.12345,c11=
\"
binaryValue
\"
,c12=L
\"
ncharValue
\"
1626006834s"
};
code
=
taos_insert_lines
(
taos
,
lines_002
,
sizeof
(
lines_002
)
/
sizeof
(
char
*
));
"stb,id=
\"
stb_1
\"
,t20=t,t21=T,t22=true,t23=True,t24=TRUE,t25=f,t26=F,t27=false,t28=False,t29=FALSE,t10=33.12345,"
"t11=
\"
binaryTagValue
\"
,t12=L
\"
ncharTagValue
\"
"
"c20=t,c21=T,c22=true,c23=True,c24=TRUE,c25=f,c26=F,c27=false,c28=False,c29=FALSE,c10=33.12345,c11="
"
\"
binaryValue
\"
,c12=L
\"
ncharValue
\"
1626006833639000000ns"
,
"stc,id=
\"
stc_1
\"
,t20=t,t21=T,t22=true,t23=True,t24=TRUE,t25=f,t26=F,t27=false,t28=False,t29=FALSE,t10=33.12345,"
"t11=
\"
binaryTagValue
\"
,t12=L
\"
ncharTagValue
\"
"
"c20=t,c21=T,c22=true,c23=True,c24=TRUE,c25=f,c26=F,c27=false,c28=False,c29=FALSE,c10=33.12345,c11="
"
\"
binaryValue
\"
,c12=L
\"
ncharValue
\"
1626006833639019us"
,
"stc,id=
\"
stc_1
\"
,t20=t,t21=T,t22=true,t23=True,t24=TRUE,t25=f,t26=F,t27=false,t28=False,t29=FALSE,t10=33.12345,"
"t11=
\"
binaryTagValue
\"
,t12=L
\"
ncharTagValue
\"
"
"c20=t,c21=T,c22=true,c23=True,c24=TRUE,c25=f,c26=F,c27=false,c28=False,c29=FALSE,c10=33.12345,c11="
"
\"
binaryValue
\"
,c12=L
\"
ncharValue
\"
1626006833640ms"
,
"stc,id=
\"
stc_1
\"
,t20=t,t21=T,t22=true,t23=True,t24=TRUE,t25=f,t26=F,t27=false,t28=False,t29=FALSE,t10=33.12345,"
"t11=
\"
binaryTagValue
\"
,t12=L
\"
ncharTagValue
\"
"
"c20=t,c21=T,c22=true,c23=True,c24=TRUE,c25=f,c26=F,c27=false,c28=False,c29=FALSE,c10=33.12345,c11="
"
\"
binaryValue
\"
,c12=L
\"
ncharValue
\"
1626006834s"
};
code
=
taos_insert_lines
(
taos
,
lines_002
,
sizeof
(
lines_002
)
/
sizeof
(
char
*
));
if
(
0
!=
code
)
{
printf
(
"taos_insert_lines() lines_002 return code:%d (%s)
\n
"
,
code
,
(
char
*
)
tstrerror
(
code
));
return
-
1
;
}
//Duplicate key check;
char
*
lines_003_1
[]
=
{
"std,id=
\"
std_3_1
\"
,t1=4i64,Id=
\"
std
\"
,t2=true c1=true 1626006834s"
};
// Duplicate key check;
char
*
lines_003_1
[]
=
{
"std,id=
\"
std_3_1
\"
,t1=4i64,Id=
\"
std
\"
,t2=true c1=true 1626006834s"
};
code
=
taos_insert_lines
(
taos
,
lines_003_1
,
sizeof
(
lines_003_1
)
/
sizeof
(
char
*
));
code
=
taos_insert_lines
(
taos
,
lines_003_1
,
sizeof
(
lines_003_1
)
/
sizeof
(
char
*
));
if
(
0
==
code
)
{
printf
(
"taos_insert_lines() lines_003_1 return code:%d (%s)
\n
"
,
code
,
(
char
*
)
tstrerror
(
code
));
return
-
1
;
}
char
*
lines_003_2
[]
=
{
"std,id=
\"
std_3_2
\"
,tag1=4i64,Tag2=true,tAg3=2,TaG2=
\"
dup!
\"
c1=true 1626006834s"
};
char
*
lines_003_2
[]
=
{
"std,id=
\"
std_3_2
\"
,tag1=4i64,Tag2=true,tAg3=2,TaG2=
\"
dup!
\"
c1=true 1626006834s"
};
code
=
taos_insert_lines
(
taos
,
lines_003_2
,
sizeof
(
lines_003_2
)
/
sizeof
(
char
*
));
code
=
taos_insert_lines
(
taos
,
lines_003_2
,
sizeof
(
lines_003_2
)
/
sizeof
(
char
*
));
if
(
0
==
code
)
{
printf
(
"taos_insert_lines() lines_003_2 return code:%d (%s)
\n
"
,
code
,
(
char
*
)
tstrerror
(
code
));
return
-
1
;
}
char
*
lines_003_3
[]
=
{
"std,id=
\"
std_3_3
\"
,tag1=4i64 field1=true,Field2=2,FIElD1=
\"
dup!
\"
,fIeLd4=true 1626006834s"
};
char
*
lines_003_3
[]
=
{
"std,id=
\"
std_3_3
\"
,tag1=4i64 field1=true,Field2=2,FIElD1=
\"
dup!
\"
,fIeLd4=true 1626006834s"
};
code
=
taos_insert_lines
(
taos
,
lines_003_3
,
sizeof
(
lines_003_3
)
/
sizeof
(
char
*
));
code
=
taos_insert_lines
(
taos
,
lines_003_3
,
sizeof
(
lines_003_3
)
/
sizeof
(
char
*
));
if
(
0
==
code
)
{
printf
(
"taos_insert_lines() lines_003_3 return code:%d (%s)
\n
"
,
code
,
(
char
*
)
tstrerror
(
code
));
return
-
1
;
}
char
*
lines_003_4
[]
=
{
"std,id=
\"
std_3_4
\"
,tag1=4i64,dupkey=4i16,tag2=T field1=true,dUpkEy=1e3f32,field2=
\"
1234
\"
1626006834s"
};
"std,id=
\"
std_3_4
\"
,tag1=4i64,dupkey=4i16,tag2=T field1=true,dUpkEy=1e3f32,field2=
\"
1234
\"
1626006834s"
};
code
=
taos_insert_lines
(
taos
,
lines_003_4
,
sizeof
(
lines_003_4
)
/
sizeof
(
char
*
));
code
=
taos_insert_lines
(
taos
,
lines_003_4
,
sizeof
(
lines_003_4
)
/
sizeof
(
char
*
));
if
(
0
==
code
)
{
printf
(
"taos_insert_lines() lines_003_4 return code:%d (%s)
\n
"
,
code
,
(
char
*
)
tstrerror
(
code
));
return
-
1
;
...
...
tests/examples/c/stream.c
浏览文件 @
de59ed95
...
...
@@ -13,12 +13,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
#include <taos.h> // include TDengine header file
#include <unistd.h>
typedef
struct
{
char
server_ip
[
64
];
...
...
@@ -27,10 +27,9 @@ typedef struct {
}
param
;
int
g_thread_exit_flag
=
0
;
void
*
insert_rows
(
void
*
sarg
);
void
*
insert_rows
(
void
*
sarg
);
void
streamCallBack
(
void
*
param
,
TAOS_RES
*
res
,
TAOS_ROW
row
)
{
void
streamCallBack
(
void
*
param
,
TAOS_RES
*
res
,
TAOS_ROW
row
)
{
// in this simple demo, it just print out the result
char
temp
[
128
];
...
...
@@ -42,12 +41,11 @@ void streamCallBack(void *param, TAOS_RES *res, TAOS_ROW row)
printf
(
"
\n
%s
\n
"
,
temp
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
TAOS
*
taos
;
char
db_name
[
64
];
char
tbl_name
[
64
];
char
sql
[
1024
]
=
{
0
};
char
sql
[
1024
]
=
{
0
};
if
(
argc
!=
4
)
{
printf
(
"usage: %s server-ip dbname tblname
\n
"
,
argv
[
0
]);
...
...
@@ -59,8 +57,7 @@ int main(int argc, char *argv[])
// create pthread to insert into row per second for stream calc
param
*
t_param
=
(
param
*
)
malloc
(
sizeof
(
param
));
if
(
NULL
==
t_param
)
{
if
(
NULL
==
t_param
)
{
printf
(
"failed to malloc
\n
"
);
exit
(
1
);
}
...
...
@@ -70,7 +67,7 @@ int main(int argc, char *argv[])
strcpy
(
t_param
->
tbl_name
,
tbl_name
);
pthread_t
pid
;
pthread_create
(
&
pid
,
NULL
,
(
void
*
(
*
)(
void
*
))
insert_rows
,
t_param
);
pthread_create
(
&
pid
,
NULL
,
(
void
*
(
*
)(
void
*
))
insert_rows
,
t_param
);
sleep
(
3
);
// waiting for database is created.
// open connection to database
...
...
@@ -112,14 +109,12 @@ int main(int argc, char *argv[])
return
0
;
}
void
*
insert_rows
(
void
*
sarg
)
{
TAOS
*
taos
;
char
command
[
1024
]
=
{
0
};
param
*
winfo
=
(
param
*
)
sarg
;
void
*
insert_rows
(
void
*
sarg
)
{
TAOS
*
taos
;
char
command
[
1024
]
=
{
0
};
param
*
winfo
=
(
param
*
)
sarg
;
if
(
NULL
==
winfo
){
if
(
NULL
==
winfo
)
{
printf
(
"para is null!
\n
"
);
exit
(
1
);
}
...
...
@@ -175,4 +170,3 @@ void* insert_rows(void *sarg)
taos_close
(
taos
);
return
0
;
}
tests/examples/c/subscribe.c
浏览文件 @
de59ed95
...
...
@@ -17,7 +17,7 @@ void print_result(TAOS_RES* res, int blockFetch) {
if
(
blockFetch
)
{
nRows
=
taos_fetch_block
(
res
,
&
row
);
//for (int i = 0; i < nRows; i++) {
//
for (int i = 0; i < nRows; i++) {
// taos_print_row(buf, row + i, fields, num_fields);
// puts(buf);
//}
...
...
@@ -34,11 +34,7 @@ void print_result(TAOS_RES* res, int blockFetch) {
printf
(
"%d rows consumed.
\n
"
,
nRows
);
}
void
subscribe_callback
(
TAOS_SUB
*
tsub
,
TAOS_RES
*
res
,
void
*
param
,
int
code
)
{
print_result
(
res
,
*
(
int
*
)
param
);
}
void
subscribe_callback
(
TAOS_SUB
*
tsub
,
TAOS_RES
*
res
,
void
*
param
,
int
code
)
{
print_result
(
res
,
*
(
int
*
)
param
);
}
void
check_row_count
(
int
line
,
TAOS_RES
*
res
,
int
expected
)
{
int
actual
=
0
;
...
...
@@ -53,13 +49,11 @@ void check_row_count(int line, TAOS_RES* res, int expected) {
}
}
void
do_query
(
TAOS
*
taos
,
const
char
*
sql
)
{
TAOS_RES
*
res
=
taos_query
(
taos
,
sql
);
taos_free_result
(
res
);
}
void
run_test
(
TAOS
*
taos
)
{
do_query
(
taos
,
"drop database if exists test;"
);
...
...
@@ -161,8 +155,7 @@ void run_test(TAOS* taos) {
taos_unsubscribe
(
tsub
,
0
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
const
char
*
host
=
"127.0.0.1"
;
const
char
*
user
=
"root"
;
const
char
*
passwd
=
"taosdata"
;
...
...
@@ -244,7 +237,8 @@ int main(int argc, char *argv[]) {
if
(
async
)
{
getchar
();
}
else
while
(
1
)
{
}
else
while
(
1
)
{
TAOS_RES
*
res
=
taos_consume
(
tsub
);
if
(
res
==
NULL
)
{
printf
(
"failed to consume data."
);
...
...
tests/script/api/makefile
浏览文件 @
de59ed95
...
...
@@ -15,8 +15,10 @@ exe:
gcc
$(CFLAGS)
./batchprepare.c
-o
$(ROOT)
batchprepare
$(LFLAGS)
gcc
$(CFLAGS)
./stmtBatchTest.c
-o
$(ROOT)
stmtBatchTest
$(LFLAGS)
gcc
$(CFLAGS)
./stmtTest.c
-o
$(ROOT)
stmtTest
$(LFLAGS)
gcc
$(CFLAGS)
./stmt.c
-o
$(ROOT)
stmt
$(LFLAGS)
clean
:
rm
$(ROOT)
batchprepare
rm
$(ROOT)
stmtBatchTest
rm
$(ROOT)
stmtTest
rm
$(ROOT)
stmt
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录