From 1f6f4df25bb171d5550cf2c15d488ef43e08dbf4 Mon Sep 17 00:00:00 2001 From: sheyanjie-qq <249478495@qq.com> Date: Sun, 4 Aug 2024 10:08:25 +0800 Subject: [PATCH] improve doc --- docs/examples/c/with_reqid_demo.c | 110 ++++++++++--------------- docs/zh/08-develop/01-connect/index.md | 8 +- 2 files changed, 52 insertions(+), 66 deletions(-) diff --git a/docs/examples/c/with_reqid_demo.c b/docs/examples/c/with_reqid_demo.c index 3091b647c7..50d29805f9 100644 --- a/docs/examples/c/with_reqid_demo.c +++ b/docs/examples/c/with_reqid_demo.c @@ -22,76 +22,56 @@ #include #include "taos.h" - static int DemoWithReqId() { -// ANCHOR: with_reqid -const char *ip = "localhost"; -const char *user = "root"; -const char *password = "taosdata"; + // ANCHOR: with_reqid + const char *ip = "localhost"; + const char *user = "root"; + const char *password = "taosdata"; -// connect -TAOS *taos = taos_connect(ip, user, password, NULL, 0); -if (taos == NULL) { - printf("failed to connect to server %s, reason: %s\n", ip, taos_errstr(NULL)); - taos_cleanup(); - return -1; -} -printf("success to connect server %s\n", ip); + // connect + TAOS *taos = taos_connect(ip, user, password, NULL, 0); + if (taos == NULL) { + printf("failed to connect to server %s, reason: %s\n", ip, taos_errstr(NULL)); + taos_cleanup(); + return -1; + } + printf("success to connect server %s\n", ip); -// create database -TAOS_RES *result = taos_query_with_reqid(taos, "CREATE DATABASE IF NOT EXISTS power", 1L); -int code = taos_errno(result); -if (code != 0) { - printf("failed to create database power, reason: %s\n", taos_errstr(result)); + const char *sql = "SELECT ts, current, location FROM power.meters limit 1"; + // query data with reqid + TAOS_RES *result = taos_query_with_reqid(taos, sql, 3L); + int code = taos_errno(result); + if (code != 0) { + printf("failed to query data from power.meters, ip: %s, reason: %s\n", ip, taos_errstr(result)); + taos_close(taos); + taos_cleanup(); + return -1; + } + + TAOS_ROW row = NULL; + int rows = 0; + int num_fields = taos_field_count(result); + TAOS_FIELD *fields = taos_fetch_fields(result); + + printf("fields: %d\n", num_fields); + printf("sql: %s, result:\n", sql); + + // fetch the records row by row + while ((row = taos_fetch_row(result))) { + char temp[1024] = {0}; + rows++; + taos_print_row(temp, row, fields, num_fields); + printf("%s\n", temp); + } + printf("total rows: %d\n", rows); taos_free_result(result); + printf("success to query data from power.meters\n"); + + // close & clean taos_close(taos); taos_cleanup(); - return -1; -} -taos_free_result(result); -printf("success to create database power\n"); - -// use database -result = taos_query_with_reqid(taos, "USE power", 2L); -taos_free_result(result); - -// query data -const char* sql = "SELECT ts, current, location FROM power.meters limit 1"; -result = taos_query_with_reqid(taos, sql, 3L); -code = taos_errno(result); -if (code != 0) { - printf("failed to query data from power.meters, ip: %s, reason: %s\n", ip, taos_errstr(result)); - taos_close(taos); - taos_cleanup(); - return -1; + return 0; + // ANCHOR_END: with_reqid } -TAOS_ROW row = NULL; -int rows = 0; -int num_fields = taos_field_count(result); -TAOS_FIELD *fields = taos_fetch_fields(result); - -printf("fields: %d\n", num_fields); -printf("sql: %s, result:\n", sql); - -// fetch the records row by row -while ((row = taos_fetch_row(result))) { - char temp[1024] = {0}; - rows++; - taos_print_row(temp, row, fields, num_fields); - printf("%s\n", temp); -} -printf("total rows: %d\n", rows); -taos_free_result(result); -printf("success to query data from power.meters\n"); - -// close & clean -taos_close(taos); -taos_cleanup(); -return 0; -// ANCHOR_END: with_reqid -} - -int main(int argc, char *argv[]) { - return DemoWithReqId(); -} +int main(int argc, char *argv[]) { return DemoWithReqId(); } diff --git a/docs/zh/08-develop/01-connect/index.md b/docs/zh/08-develop/01-connect/index.md index 7fbd3f20a4..2e0f284eeb 100644 --- a/docs/zh/08-develop/01-connect/index.md +++ b/docs/zh/08-develop/01-connect/index.md @@ -273,6 +273,12 @@ URL 和 Properties 的详细参数说明和如何使用详见 [url 规范](../.. + Python 连接器使用 `connect()` 方法来建立连接,下面是连接参数的具体说明: + - url: `taosAdapter` REST 服务的 URL。默认是 `localhost` 的 `6041` 端口。 + - user: TDengine 用户名。默认是 `root`。 + - password: TDengine 用户密码。默认是 `taosdata`。 + - timeout: HTTP 请求超时时间。单位为秒。默认为 `socket._GLOBAL_DEFAULT_TIMEOUT`。一般无需配置。 + @@ -448,7 +454,7 @@ C/C++ 语言连接器使用 `taos_connect()` 函数用于建立与 TDengine 数 ``` -```csharp title="WebSocket 连接" +```csharp {{#include docs/examples/csharp/connect/Program.cs:main}} ```