improve doc

This commit is contained in:
sheyanjie-qq 2024-08-04 10:08:25 +08:00
parent ed99f12573
commit 1f6f4df25b
2 changed files with 52 additions and 66 deletions

View File

@ -22,76 +22,56 @@
#include <string.h> #include <string.h>
#include "taos.h" #include "taos.h"
static int DemoWithReqId() { static int DemoWithReqId() {
// ANCHOR: with_reqid // ANCHOR: with_reqid
const char *ip = "localhost"; const char *ip = "localhost";
const char *user = "root"; const char *user = "root";
const char *password = "taosdata"; const char *password = "taosdata";
// connect // connect
TAOS *taos = taos_connect(ip, user, password, NULL, 0); TAOS *taos = taos_connect(ip, user, password, NULL, 0);
if (taos == NULL) { if (taos == NULL) {
printf("failed to connect to server %s, reason: %s\n", ip, taos_errstr(NULL)); printf("failed to connect to server %s, reason: %s\n", ip, taos_errstr(NULL));
taos_cleanup(); taos_cleanup();
return -1; return -1;
} }
printf("success to connect server %s\n", ip); printf("success to connect server %s\n", ip);
// create database const char *sql = "SELECT ts, current, location FROM power.meters limit 1";
TAOS_RES *result = taos_query_with_reqid(taos, "CREATE DATABASE IF NOT EXISTS power", 1L); // query data with reqid
int code = taos_errno(result); TAOS_RES *result = taos_query_with_reqid(taos, sql, 3L);
if (code != 0) { int code = taos_errno(result);
printf("failed to create database power, reason: %s\n", taos_errstr(result)); if (code != 0) {
taos_free_result(result);
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)); printf("failed to query data from power.meters, ip: %s, reason: %s\n", ip, taos_errstr(result));
taos_close(taos); taos_close(taos);
taos_cleanup(); taos_cleanup();
return -1; return -1;
} }
TAOS_ROW row = NULL; TAOS_ROW row = NULL;
int rows = 0; int rows = 0;
int num_fields = taos_field_count(result); int num_fields = taos_field_count(result);
TAOS_FIELD *fields = taos_fetch_fields(result); TAOS_FIELD *fields = taos_fetch_fields(result);
printf("fields: %d\n", num_fields); printf("fields: %d\n", num_fields);
printf("sql: %s, result:\n", sql); printf("sql: %s, result:\n", sql);
// fetch the records row by row // fetch the records row by row
while ((row = taos_fetch_row(result))) { while ((row = taos_fetch_row(result))) {
char temp[1024] = {0}; char temp[1024] = {0};
rows++; rows++;
taos_print_row(temp, row, fields, num_fields); taos_print_row(temp, row, fields, num_fields);
printf("%s\n", temp); printf("%s\n", temp);
} }
printf("total rows: %d\n", rows); printf("total rows: %d\n", rows);
taos_free_result(result); taos_free_result(result);
printf("success to query data from power.meters\n"); printf("success to query data from power.meters\n");
// close & clean // close & clean
taos_close(taos); taos_close(taos);
taos_cleanup(); taos_cleanup();
return 0; return 0;
// ANCHOR_END: with_reqid // ANCHOR_END: with_reqid
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) { return DemoWithReqId(); }
return DemoWithReqId();
}

View File

@ -273,6 +273,12 @@ URL 和 Properties 的详细参数说明和如何使用详见 [url 规范](../..
</TabItem> </TabItem>
<TabItem label="Python" value="python"> <TabItem label="Python" value="python">
Python 连接器使用 `connect()` 方法来建立连接,下面是连接参数的具体说明:
- url `taosAdapter` REST 服务的 URL。默认是 `localhost``6041` 端口。
- user TDengine 用户名。默认是 `root`
- password TDengine 用户密码。默认是 `taosdata`
- timeout HTTP 请求超时时间。单位为秒。默认为 `socket._GLOBAL_DEFAULT_TIMEOUT`。一般无需配置。
</TabItem> </TabItem>
<TabItem label="Go" value="go"> <TabItem label="Go" value="go">
@ -448,7 +454,7 @@ C/C++ 语言连接器使用 `taos_connect()` 函数用于建立与 TDengine 数
``` ```
</TabItem> </TabItem>
<TabItem label="C#" value="csharp"> <TabItem label="C#" value="csharp">
```csharp title="WebSocket 连接" ```csharp
{{#include docs/examples/csharp/connect/Program.cs:main}} {{#include docs/examples/csharp/connect/Program.cs:main}}
``` ```
</TabItem> </TabItem>