Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
804b5812
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
804b5812
编写于
12月 27, 2019
作者:
weixin_48148422
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TBASE-917: update subscription example
上级
192ad4df
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
69 addition
and
30 deletion
+69
-30
tests/examples/c/makefile
tests/examples/c/makefile
+13
-12
tests/examples/c/subscribe.c
tests/examples/c/subscribe.c
+56
-18
未找到文件。
tests/examples/c/makefile
浏览文件 @
804b5812
...
...
@@ -3,21 +3,22 @@
ROOT
=
./
TARGET
=
exe
LFLAGS
=
'-Wl,-rpath,/usr/local/taos/driver'
-ltaos
-lpthread
-lm
-lrt
CFLAGS
=
-O3
-g
-Wall
-Wno-deprecated
-fPIC
-Wno-unused-result
-Wconversion
-Wno-char-subscripts
-D_REENTRANT
-Wno-format
-D_REENTRANT
-DLINUX
-msse4
.2
-Wno-unused-function
-D_M_X64
-std
=
gnu99
LFLAGS
=
'-Wl,-rpath,/usr/local/taos/driver/'
-ltaos
-lpthread
-lm
-lrt
CFLAGS
=
-O3
-g
-Wall
-Wno-deprecated
-fPIC
-Wno-unused-result
-Wconversion
-Wno-char-subscripts
-D_REENTRANT
-Wno-format
-D_REENTRANT
-DLINUX
-msse4
.2
-Wno-unused-function
-D_M_X64
\
-I
/usr/local/taos/include
-std
=
gnu99
all
:
$(TARGET)
exe
:
gcc
$(CFLAGS)
./asyncdemo.c
-o
$(ROOT)
/asyncdemo
$(LFLAGS)
gcc
$(CFLAGS)
./demo.c
-o
$(ROOT)
/demo
$(LFLAGS)
gcc
$(CFLAGS)
./stream.c
-o
$(ROOT)
/stream
$(LFLAGS)
gcc
$(CFLAGS)
./subscribe.c
-o
$(ROOT)
/subscribe
$(LFLAGS)
gcc
$(CFLAGS)
./asyncdemo.c
-o
$(ROOT)/asyncdemo
$(LFLAGS)
gcc
$(CFLAGS)
./demo.c
-o
$(ROOT)/demo
$(LFLAGS)
gcc
$(CFLAGS)
./prepare.c
-o
$(ROOT)/prepare
$(LFLAGS)
gcc
$(CFLAGS)
./stream.c
-o
$(ROOT)/stream
$(LFLAGS)
gcc
$(CFLAGS)
./subscribe.c
-o
$(ROOT)subscribe
$(LFLAGS)
clean
:
rm
$(ROOT)
asyncdemo
rm
$(ROOT)
demo
rm
$(ROOT)
stream
rm
$(ROOT)
subscribe
\ No newline at end of file
rm
$(ROOT)
/asyncdemo
rm
$(ROOT)
/demo
rm
$(ROOT)
/prepare
rm
$(ROOT)
/stream
rm
$(ROOT)
/subscribe
tests/examples/c/subscribe.c
浏览文件 @
804b5812
...
...
@@ -6,38 +6,76 @@
#include <string.h>
#include <taos.h> // include TDengine header file
void
print_result
(
TAOS_RES
*
res
)
{
TAOS_ROW
row
;
int
num_fields
=
taos_num_fields
(
res
);
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
res
);
while
((
row
=
taos_fetch_row
(
res
)))
{
char
temp
[
256
];
taos_print_row
(
temp
,
row
,
fields
,
num_fields
);
puts
(
temp
);
}
}
void
subscribe_callback
(
TAOS_SUB
*
tsub
,
TAOS_RES
*
res
,
void
*
param
,
int
code
)
{
print_result
(
res
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
const
char
*
host
=
"127.0.0.1"
;
const
char
*
user
=
"root"
;
const
char
*
passwd
=
"taosdata"
;
int
async
=
1
;
TAOS_SUB
*
tsub
=
NULL
;
for
(
int
i
=
1
;
i
<
argc
;
i
++
)
{
if
(
strncmp
(
argv
[
i
],
"-h="
,
3
)
==
0
)
{
host
=
argv
[
i
]
+
3
;
continue
;
}
if
(
strncmp
(
argv
[
i
],
"-u="
,
3
)
==
0
)
{
user
=
argv
[
i
]
+
3
;
continue
;
}
if
(
strncmp
(
argv
[
i
],
"-p="
,
3
)
==
0
)
{
passwd
=
argv
[
i
]
+
3
;
continue
;
}
if
(
strncmp
(
argv
[
i
],
"-m="
,
3
)
==
0
)
{
async
=
strcmp
(
argv
[
i
]
+
3
,
"sync"
);
continue
;
}
}
// init TAOS
taos_init
();
TAOS
*
taos
=
taos_connect
(
argv
[
1
],
"root"
,
"taosdata"
,
"test"
,
0
);
TAOS
*
taos
=
taos_connect
(
host
,
user
,
passwd
,
"test"
,
0
);
if
(
taos
==
NULL
)
{
printf
(
"failed to connect to db, reason:%s
\n
"
,
taos_errstr
(
taos
));
exit
(
1
);
}
TAOS_SUB
*
tsub
=
taos_subscribe
(
taos
,
"select * from meters;"
,
NULL
,
NULL
,
0
);
if
(
tsub
==
NULL
)
{
if
(
async
)
{
tsub
=
taos_subscribe
(
taos
,
"select * from meters;"
,
subscribe_callback
,
NULL
,
1000
);
}
else
{
tsub
=
taos_subscribe
(
taos
,
"select * from meters;"
,
NULL
,
NULL
,
0
);
}
if
(
tsub
==
NULL
)
{
printf
(
"failed to create subscription.
\n
"
);
exit
(
0
);
}
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
if
(
async
)
{
getchar
();
}
else
while
(
1
)
{
TAOS_RES
*
res
=
taos_consume
(
tsub
);
TAOS_ROW
row
;
int
rows
=
0
;
int
num_fields
=
taos_subfields_count
(
tsub
);
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
res
);
char
temp
[
256
];
// fetch the records row by row
while
((
row
=
taos_fetch_row
(
res
)))
{
rows
++
;
taos_print_row
(
temp
,
row
,
fields
,
num_fields
);
printf
(
"%s
\n
"
,
temp
);
}
printf
(
"
\n
"
);
print_result
(
res
);
getchar
();
}
taos_unsubscribe
(
tsub
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录