Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c888c8b2
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c888c8b2
编写于
4月 27, 2022
作者:
P
Ping Xiao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test: add demo for tq
TS-1464
上级
60dc28cb
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
94 addition
and
0 deletion
+94
-0
examples/c/tqdemo.c
examples/c/tqdemo.c
+94
-0
未找到文件。
examples/c/tqdemo.c
0 → 100644
浏览文件 @
c888c8b2
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// TAOS standard API example. The same syntax as MySQL, but only a subset
// to compile: gcc -o tqdemo tqdemo.c -ltaos
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <taos.h> // TAOS header file
void
print_results
(
TAOS
*
taos
,
char
*
qstr
);
int
main
(
int
argc
,
char
*
argv
[])
{
char
qstr
[
1024
];
TAOS_RES
*
pSql
=
NULL
;
// connect to server
if
(
argc
<
2
)
{
printf
(
"please input server-ip
\n
"
);
return
0
;
}
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)*/
);
exit
(
1
);
}
TAOS_RES
*
res
;
// create topic
res
=
taos_query
(
taos
,
"create topic tq_test partitions 10"
);
taos_free_result
(
res
);
res
=
taos_query
(
taos
,
"use tq_test"
);
taos_free_result
(
res
);
print_results
(
taos
,
"show stables"
);
print_results
(
taos
,
"show tables"
);
// insert data
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
char
*
sql
=
"insert into p%d values(now + %ds, %d, 'test')"
;
sprintf
(
qstr
,
sql
,
i
,
i
,
i
);
res
=
taos_query
(
taos
,
qstr
);
taos_free_result
(
res
);
}
// query data
print_results
(
taos
,
"select * from tq_test.ps"
);
taos_close
(
taos
);
taos_cleanup
();
}
void
print_results
(
TAOS
*
taos
,
char
*
qstr
)
{
TAOS_RES
*
res
;
res
=
taos_query
(
taos
,
qstr
);
if
(
res
==
NULL
||
taos_errno
(
res
)
!=
0
)
{
printf
(
"failed to select, reason:%s
\n
"
,
taos_errstr
(
res
));
taos_free_result
(
res
);
exit
(
1
);
}
TAOS_ROW
row
;
int
rows
=
0
;
int
num_fields
=
taos_field_count
(
res
);
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
res
);
printf
(
"num_fields = %d
\n
"
,
num_fields
);
printf
(
"%s result:
\n
"
,
qstr
);
// fetch the records row by row
while
((
row
=
taos_fetch_row
(
res
)))
{
char
temp
[
1024
]
=
{
0
};
rows
++
;
taos_print_row
(
temp
,
row
,
fields
,
num_fields
);
printf
(
"%s
\n
"
,
temp
);
}
taos_free_result
(
res
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录