optimized the cpp connector sample code page

This commit is contained in:
Yaming Pei 2024-08-22 11:26:11 +08:00
parent 456f0d888a
commit 9ddfefc6bf
10 changed files with 347 additions and 469 deletions

View File

@ -71,9 +71,7 @@ This section shows sample code for standard access methods to TDengine clusters
<details>
<summary>Synchronous query</summary>
```c
{{#include examples/c/demo.c}}
```
[C example] (https://github.com/taosdata/TDengine/tree/3.0/docs/examples/c/demo.c)
</details>
@ -82,9 +80,7 @@ This section shows sample code for standard access methods to TDengine clusters
<details>
<summary>Asynchronous queries</summary>
```c
{{#include examples/c/asyncdemo.c}}
```
[C example] (https://github.com/taosdata/TDengine/tree/3.0/docs/examples/c/asyncdemo.c)
</details>
@ -93,9 +89,7 @@ This section shows sample code for standard access methods to TDengine clusters
<details>
<summary>Parameter Binding</summary>
```c
{{#include examples/c/prepare.c}}
```
[C example] (https://github.com/taosdata/TDengine/tree/3.0/docs/examples/c/prepare.c)
</details>
@ -104,9 +98,7 @@ This section shows sample code for standard access methods to TDengine clusters
<details>
<summary>Mode free write</summary>
```c
{{#include examples/c/schemaless.c}}
```
[C example] (https://github.com/taosdata/TDengine/tree/3.0/docs/examples/c/schemaless.c)
</details>
@ -121,7 +113,7 @@ This section shows sample code for standard access methods to TDengine clusters
</details>
:::info
More example code and downloads are available at [GitHub](https://github.com/taosdata/TDengine/tree/develop/examples/c).
More example code and downloads are available at [GitHub](https://github.com/taosdata/TDengine/tree/develop/docs/examples/c).
You can find it in the installation directory under the `examples/c` path. This directory has a makefile and can be compiled under Linux/macOS by executing `make` directly.
**Hint:** When compiling in an ARM environment, please remove `-msse4.2` from the makefile. This option is only supported on the x64/x86 hardware platforms.
@ -311,7 +303,7 @@ Starting with versions 2.1.1.0 and 2.1.2.0, TDengine has significantly improved
Note: If `taos_stmt_execute()` succeeds, you can reuse the parsed result of `taos_stmt_prepare()` to bind new data in steps 3 to 6 if you don't need to change the SQL command. However, if there is an execution error, it is not recommended to continue working in the current context but release the resources and start again with `taos_stmt_init()` steps.
The specific functions related to the interface are as follows (see also the [prepare.c](https://github.com/taosdata/TDengine/blob/develop/examples/c/prepare.c) file for the way to use the corresponding functions)
The specific functions related to the interface are as follows (see also the [prepare.c](https://github.com/taosdata/TDengine/blob/develop/docs/examples/c/prepare.c) file for the way to use the corresponding functions)
- `TAOS_STMT* taos_stmt_init(TAOS *taos)`

View File

@ -45,9 +45,8 @@ TDengine 客户端驱动的版本号与 TDengine 服务端的版本号是一一
<details>
<summary>同步查询</summary>
```c
{{#include examples/c/demo.c}}
```
请参考:[C example](https://github.com/taosdata/TDengine/tree/3.0/docs/examples/c/demo.c)
格式化输出不同类型字段函数 taos_print_row
```c
int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields) {
@ -144,9 +143,7 @@ int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields)
<details>
<summary>异步查询</summary>
```c
{{#include examples/c/asyncdemo.c}}
```
请参考:[C example](https://github.com/taosdata/TDengine/tree/3.0/docs/examples/c/asyncdemo.c)
</details>
@ -155,9 +152,7 @@ int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields)
<details>
<summary>参数绑定</summary>
```c
{{#include examples/c/prepare.c}}
```
请参考:[C example](https://github.com/taosdata/TDengine/tree/3.0/docs/examples/c/prepare.c)
</details>
@ -166,9 +161,7 @@ int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields)
<details>
<summary>无模式写入</summary>
```c
{{#include examples/c/schemaless.c}}
```
请参考:[C example](https://github.com/taosdata/TDengine/tree/3.0/docs/examples/c/schemaless.c)
</details>
@ -177,14 +170,12 @@ int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields)
<details>
<summary>订阅和消费</summary>
```c
{{#include examples/c/tmq.c}}
```
请参考:[C example](https://github.com/taosdata/TDengine/tree/3.0/docs/examples/c/tmq.c)
</details>
:::info
更多示例代码及下载请见 [GitHub](https://github.com/taosdata/TDengine/tree/develop/examples/c)。
更多示例代码及下载请见 [GitHub](https://github.com/taosdata/TDengine/tree/develop/docs/examples/c)。
也可以在安装目录下的 `examples/c` 路径下找到。 该目录下有 makefile在 Linux/macOS 环境下,直接执行 make 就可以编译得到执行文件。
**提示:**在 ARM 环境下编译时,请将 makefile 中的 `-msse4.2` 去掉,这个选项只有在 x64/x86 硬件平台上才能支持。
@ -403,7 +394,7 @@ TDengine 的异步 API 均采用非阻塞调用模式。应用程序可以用多
说明:如果 `taos_stmt_execute()` 执行成功,假如不需要改变 SQL 语句的话,那么是可以复用 `taos_stmt_prepare()` 的解析结果,直接进行第 3 6 步绑定新数据的。但如果执行出错,那么并不建议继续在当前的环境上下文下继续工作,而是建议释放资源,然后从 `taos_stmt_init()` 步骤重新开始。
接口相关的具体函数如下(也可以参考 [prepare.c](https://github.com/taosdata/TDengine/blob/develop/examples/c/prepare.c) 文件中使用对应函数的方式):
接口相关的具体函数如下(也可以参考 [prepare.c](https://github.com/taosdata/TDengine/blob/develop/docs/examples/c/prepare.c) 文件中使用对应函数的方式):
- `TAOS_STMT* taos_stmt_init(TAOS *taos)`
- **接口说明**:初始化一个预编译的 SQL 语句对象。

View File

@ -1,78 +0,0 @@
PROJECT(TDengine)
IF (TD_LINUX)
INCLUDE_DIRECTORIES(. ${TD_SOURCE_DIR}/src/inc ${TD_SOURCE_DIR}/src/client/inc ${TD_SOURCE_DIR}/inc)
AUX_SOURCE_DIRECTORY(. SRC)
add_executable(tmq "")
add_executable(stream_demo "")
add_executable(schemaless "")
add_executable(prepare "")
add_executable(demo "")
add_executable(asyncdemo "")
target_sources(tmq
PRIVATE
"tmq.c"
)
target_sources(stream_demo
PRIVATE
"stream_demo.c"
)
target_sources(schemaless
PRIVATE
"schemaless.c"
)
target_sources(prepare
PRIVATE
"prepare.c"
)
target_sources(demo
PRIVATE
"demo.c"
)
target_sources(asyncdemo
PRIVATE
"asyncdemo.c"
)
target_link_libraries(tmq
taos
)
target_link_libraries(stream_demo
taos
)
target_link_libraries(schemaless
taos
)
target_link_libraries(prepare
taos
)
target_link_libraries(demo
taos
)
target_link_libraries(asyncdemo
taos
)
SET_TARGET_PROPERTIES(tmq PROPERTIES OUTPUT_NAME tmq)
SET_TARGET_PROPERTIES(stream_demo PROPERTIES OUTPUT_NAME stream_demo)
SET_TARGET_PROPERTIES(schemaless PROPERTIES OUTPUT_NAME schemaless)
SET_TARGET_PROPERTIES(prepare PROPERTIES OUTPUT_NAME prepare)
SET_TARGET_PROPERTIES(demo PROPERTIES OUTPUT_NAME demo)
SET_TARGET_PROPERTIES(asyncdemo PROPERTIES OUTPUT_NAME asyncdemo)
ENDIF ()
IF (TD_DARWIN)
INCLUDE_DIRECTORIES(. ${TD_SOURCE_DIR}/src/inc ${TD_SOURCE_DIR}/src/client/inc ${TD_SOURCE_DIR}/inc)
AUX_SOURCE_DIRECTORY(. SRC)
ENDIF ()

View File

@ -1,27 +0,0 @@
# Copyright (c) 2017 by TAOS Technologies, Inc.
# todo: library dependency, header file dependency
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 \
-Wno-unused-function -D_M_X64 -I/usr/local/taos/include -std=gnu99 \
-I/usr/local/include/cjson
all: $(TARGET)
exe:
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_demo.c -o $(ROOT)stream_demo $(LFLAGS)
gcc $(CFLAGS) ./tmq.c -o $(ROOT)tmq $(LFLAGS)
gcc $(CFLAGS) ./schemaless.c -o $(ROOT)schemaless $(LFLAGS)
clean:
rm $(ROOT)asyncdemo
rm $(ROOT)demo
rm $(ROOT)prepare
rm $(ROOT)stream_demo
rm $(ROOT)tmq
rm $(ROOT)schemaless