Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5316ca32
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5316ca32
编写于
4月 06, 2020
作者:
H
hjxilinx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-98]
上级
fd722069
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
52 addition
and
0 deletion
+52
-0
tests/examples/c/demo.c
tests/examples/c/demo.c
+52
-0
未找到文件。
tests/examples/c/demo.c
浏览文件 @
5316ca32
...
...
@@ -24,17 +24,43 @@
void
taosMsleep
(
int
mseconds
);
static
int32_t
doQuery
(
TAOS
*
taos
,
const
char
*
sql
)
{
int32_t
code
=
taos_query
(
taos
,
sql
);
if
(
code
!=
0
)
{
printf
(
"failed to execute query, reason:%s
\n
"
,
taos_errstr
(
taos
));
return
-
1
;
}
TAOS_RES
*
res
=
taos_use_result
(
taos
);
TAOS_ROW
row
=
NULL
;
char
buf
[
512
]
=
{
0
};
int32_t
numOfFields
=
taos_num_fields
(
res
);
TAOS_FIELD
*
pFields
=
taos_fetch_fields
(
res
);
while
((
row
=
taos_fetch_row
(
res
))
!=
NULL
)
{
taos_print_row
(
buf
,
row
,
pFields
,
numOfFields
);
printf
(
"%s
\n
"
,
buf
);
memset
(
buf
,
0
,
512
);
}
taos_free_result
(
res
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
TAOS
*
taos
;
char
qstr
[
1024
];
TAOS_RES
*
result
;
// connect to server
if
(
argc
<
2
)
{
printf
(
"please input server-ip
\n
"
);
return
0
;
}
taos_options
(
TSDB_OPTION_CONFIGDIR
,
"~/sec/cfg"
);
// init TAOS
taos_init
();
...
...
@@ -45,6 +71,22 @@ int main(int argc, char *argv[]) {
}
printf
(
"success to connect to server
\n
"
);
doQuery
(
taos
,
"create database if not exists test"
);
doQuery
(
taos
,
"use test"
);
doQuery
(
taos
,
"create table if not exists tm0 (ts timestamp, k int);"
);
doQuery
(
taos
,
"insert into tm0 values('2020-1-1 1:1:1', 1);"
);
doQuery
(
taos
,
"insert into tm0 values('2020-1-1 1:1:2', 2);"
);
doQuery
(
taos
,
"insert into tm0 values('2020-1-1 1:1:3', 3);"
);
doQuery
(
taos
,
"insert into tm0 values('2020-1-1 1:1:4', 4);"
);
doQuery
(
taos
,
"insert into tm0 values('2020-1-1 1:1:5', 5);"
);
doQuery
(
taos
,
"insert into tm0 values('2020-1-1 1:1:6', 6);"
);
doQuery
(
taos
,
"insert into tm0 values('2020-1-1 1:1:7', 7);"
);
doQuery
(
taos
,
"insert into tm0 values('2020-1-1 1:1:8', 8);"
);
doQuery
(
taos
,
"insert into tm0 values('2020-1-1 1:1:9', 9);"
);
doQuery
(
taos
,
"select * from tm0;"
);
taos_close
(
taos
);
return
0
;
taos_query
(
taos
,
"drop database demo"
);
if
(
taos_query
(
taos
,
"create database demo"
)
!=
0
)
{
...
...
@@ -53,8 +95,10 @@ int main(int argc, char *argv[]) {
}
printf
(
"success to create database
\n
"
);
taos_query
(
taos
,
"use demo"
);
// create table
if
(
taos_query
(
taos
,
"create table m1 (ts timestamp, speed int)"
)
!=
0
)
{
printf
(
"failed to create table, reason:%s
\n
"
,
taos_errstr
(
taos
));
...
...
@@ -62,9 +106,11 @@ int main(int argc, char *argv[]) {
}
printf
(
"success to create table
\n
"
);
// sleep for one second to make sure table is created on data node
// taosMsleep(1000);
// insert 10 records
int
i
=
0
;
for
(
i
=
0
;
i
<
10
;
++
i
)
{
...
...
@@ -76,6 +122,7 @@ int main(int argc, char *argv[]) {
}
printf
(
"success to insert rows, total %d rows
\n
"
,
i
);
// query the records
sprintf
(
qstr
,
"SELECT * FROM m1"
);
if
(
taos_query
(
taos
,
qstr
)
!=
0
)
{
...
...
@@ -83,12 +130,16 @@ int main(int argc, char *argv[]) {
exit
(
1
);
}
result
=
taos_use_result
(
taos
);
if
(
result
==
NULL
)
{
printf
(
"failed to get result, reason:%s
\n
"
,
taos_errstr
(
taos
));
exit
(
1
);
}
// TAOS_ROW row;
TAOS_ROW
row
;
int
rows
=
0
;
...
...
@@ -96,6 +147,7 @@ int main(int argc, char *argv[]) {
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
result
);
char
temp
[
256
];
printf
(
"select * from table, result:
\n
"
);
// fetch the records row by row
while
((
row
=
taos_fetch_row
(
result
)))
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录