update log
This commit is contained in:
parent
29df00a89d
commit
c6e7d69bb4
|
@ -22,7 +22,6 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "taos.h"
|
#include "taos.h"
|
||||||
|
|
||||||
|
|
||||||
static int DemoCreateDB() {
|
static int DemoCreateDB() {
|
||||||
// ANCHOR: create_db_and_table
|
// ANCHOR: create_db_and_table
|
||||||
const char *host = "localhost";
|
const char *host = "localhost";
|
||||||
|
@ -34,7 +33,8 @@ int code = 0;
|
||||||
// connect
|
// connect
|
||||||
TAOS *taos = taos_connect(host, user, password, NULL, port);
|
TAOS *taos = taos_connect(host, user, password, NULL, port);
|
||||||
if (taos == NULL) {
|
if (taos == NULL) {
|
||||||
printf("Failed to connect to %s:%hu, ErrCode: 0x%x, ErrMessage: %s.\n", host, port, taos_errno(NULL), taos_errstr(NULL));
|
printf("Failed to connect to %s:%hu, ErrCode: 0x%x, ErrMessage: %s.\n", host, port, taos_errno(NULL),
|
||||||
|
taos_errstr(NULL));
|
||||||
taos_cleanup();
|
taos_cleanup();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,8 @@ if (taos == NULL) {
|
||||||
TAOS_RES *result = taos_query(taos, "CREATE DATABASE IF NOT EXISTS power");
|
TAOS_RES *result = taos_query(taos, "CREATE DATABASE IF NOT EXISTS power");
|
||||||
code = taos_errno(result);
|
code = taos_errno(result);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
printf("Failed to create database power, Server: %s:%hu, ErrCode: 0x%x, ErrMessage: %s.\n", host, port, code, taos_errstr(result));
|
printf("Failed to create database power, Server: %s:%hu, ErrCode: 0x%x, ErrMessage: %s.\n", host, port, code,
|
||||||
|
taos_errstr(result));
|
||||||
taos_close(taos);
|
taos_close(taos);
|
||||||
taos_cleanup();
|
taos_cleanup();
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -52,17 +53,20 @@ taos_free_result(result);
|
||||||
printf("Create database power successfully.\n");
|
printf("Create database power successfully.\n");
|
||||||
|
|
||||||
// create table
|
// create table
|
||||||
const char* sql = "CREATE STABLE IF NOT EXISTS power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (groupId INT, location BINARY(24))";
|
const char *sql =
|
||||||
|
"CREATE STABLE IF NOT EXISTS power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (groupId "
|
||||||
|
"INT, location BINARY(24))";
|
||||||
result = taos_query(taos, sql);
|
result = taos_query(taos, sql);
|
||||||
code = taos_errno(result);
|
code = taos_errno(result);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
printf("Failed to create stable power.meters, Server: %s:%hu, ErrCode: 0x%x, ErrMessage: %s\n.", host, port, code, taos_errstr(result));
|
printf("Failed to create stable power.meters, Server: %s:%hu, ErrCode: 0x%x, ErrMessage: %s\n.", host, port, code,
|
||||||
|
taos_errstr(result));
|
||||||
taos_close(taos);
|
taos_close(taos);
|
||||||
taos_cleanup();
|
taos_cleanup();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
taos_free_result(result);
|
taos_free_result(result);
|
||||||
printf("Create stable meters successfully.\n");
|
printf("Create stable power.meters successfully.\n");
|
||||||
|
|
||||||
// close & clean
|
// close & clean
|
||||||
taos_close(taos);
|
taos_close(taos);
|
||||||
|
@ -71,6 +75,4 @@ return 0;
|
||||||
// ANCHOR_END: create_db_and_table
|
// ANCHOR_END: create_db_and_table
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) { return DemoCreateDB(); }
|
||||||
return DemoCreateDB();
|
|
||||||
}
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ async function subscribe(consumer) {
|
||||||
console.log("Commit offset manually successfully.");
|
console.log("Commit offset manually successfully.");
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Failed to poll data; err.code, ErrCode:" + err.code + "; ErrMessage: " + err.message);
|
console.error("Failed to poll data; ErrCode:" + err.code + "; ErrMessage: " + err.message);
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
// ANCHOR_END: commit
|
// ANCHOR_END: commit
|
||||||
|
|
|
@ -59,7 +59,7 @@ async function subscribe(consumer) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Failed to poll data; err.code, ErrCode:" + err.code + "; ErrMessage: " + err.message);
|
console.error("Failed to poll data; ErrCode:" + err.code + "; ErrMessage: " + err.message);
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import taos
|
import taos
|
||||||
|
|
||||||
conn = None
|
conn = None
|
||||||
reqId = 1
|
reqId = 3
|
||||||
host="localhost"
|
host="localhost"
|
||||||
port=6030
|
port=6030
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -2,7 +2,7 @@ import taosrest
|
||||||
|
|
||||||
client = None
|
client = None
|
||||||
url="http://localhost:6041"
|
url="http://localhost:6041"
|
||||||
reqId = 1
|
reqId = 3
|
||||||
try:
|
try:
|
||||||
client = taosrest.RestClient(url=url,
|
client = taosrest.RestClient(url=url,
|
||||||
user="root",
|
user="root",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import taosws
|
import taosws
|
||||||
|
|
||||||
conn = None
|
conn = None
|
||||||
reqId = 1
|
reqId = 3
|
||||||
host="localhost"
|
host="localhost"
|
||||||
port=6041
|
port=6041
|
||||||
try:
|
try:
|
||||||
|
@ -12,7 +12,7 @@ try:
|
||||||
port=port,
|
port=port,
|
||||||
)
|
)
|
||||||
|
|
||||||
result = conn.query_with_req_id("SELECT ts, current, location FROM power.meters limit 100", req_id=1)
|
result = conn.query_with_req_id("SELECT ts, current, location FROM power.meters limit 100", req_id=3)
|
||||||
# Get data from result as list of tuple
|
# Get data from result as list of tuple
|
||||||
for row in result:
|
for row in result:
|
||||||
print(f"ts: {row[0]}, current: {row[1]}, location: {row[2]}")
|
print(f"ts: {row[0]}, current: {row[1]}, location: {row[2]}")
|
||||||
|
|
Loading…
Reference in New Issue