update log

This commit is contained in:
sheyanjie-qq 2024-08-12 20:56:20 +08:00
parent 29df00a89d
commit c6e7d69bb4
8 changed files with 65 additions and 63 deletions

View File

@ -22,55 +22,57 @@
#include <string.h>
#include "taos.h"
static int DemoCreateDB() {
// ANCHOR: create_db_and_table
const char *host = "localhost";
const char *user = "root";
const char *password = "taosdata";
uint16_t port = 6030;
int code = 0;
// ANCHOR: create_db_and_table
const char *host = "localhost";
const char *user = "root";
const char *password = "taosdata";
uint16_t port = 6030;
int code = 0;
// connect
TAOS *taos = taos_connect(host, user, password, NULL, port);
if (taos == NULL) {
printf("Failed to connect to %s:%hu, ErrCode: 0x%x, ErrMessage: %s.\n", host, port, taos_errno(NULL), taos_errstr(NULL));
taos_cleanup();
return -1;
}
// connect
TAOS *taos = taos_connect(host, user, password, NULL, port);
if (taos == NULL) {
printf("Failed to connect to %s:%hu, ErrCode: 0x%x, ErrMessage: %s.\n", host, port, taos_errno(NULL),
taos_errstr(NULL));
taos_cleanup();
return -1;
}
// create database
TAOS_RES *result = taos_query(taos, "CREATE DATABASE IF NOT EXISTS power");
code = taos_errno(result);
if (code != 0) {
printf("Failed to create database power, Server: %s:%hu, ErrCode: 0x%x, ErrMessage: %s.\n", host, port, code, taos_errstr(result));
// create database
TAOS_RES *result = taos_query(taos, "CREATE DATABASE IF NOT EXISTS power");
code = taos_errno(result);
if (code != 0) {
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_cleanup();
return -1;
}
taos_free_result(result);
printf("Create database power successfully.\n");
// 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))";
result = taos_query(taos, sql);
code = taos_errno(result);
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));
taos_close(taos);
taos_cleanup();
return -1;
}
taos_free_result(result);
printf("Create stable power.meters successfully.\n");
// close & clean
taos_close(taos);
taos_cleanup();
return -1;
}
taos_free_result(result);
printf("Create database power successfully.\n");
// 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))";
result = taos_query(taos, sql);
code = taos_errno(result);
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));
taos_close(taos);
taos_cleanup();
return -1;
}
taos_free_result(result);
printf("Create stable meters successfully.\n");
// close & clean
taos_close(taos);
taos_cleanup();
return 0;
// ANCHOR_END: create_db_and_table
return 0;
// ANCHOR_END: create_db_and_table
}
int main(int argc, char *argv[]) {
return DemoCreateDB();
}
int main(int argc, char *argv[]) { return DemoCreateDB(); }

View File

@ -66,7 +66,7 @@ async function subscribe(consumer) {
console.log("Commit offset manually successfully.");
}
} 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;
}
// ANCHOR_END: commit

View File

@ -18,11 +18,11 @@ async function createConsumer() {
]);
try {
return await taos.tmqConnect(configMap);
}catch (err) {
} catch (err) {
console.log(err);
throw err;
}
}
// ANCHOR_END: create_consumer
@ -33,7 +33,7 @@ async function prepare() {
conf.setDb('power');
const createDB = `CREATE DATABASE IF NOT EXISTS POWER ${db} KEEP 3650 DURATION 10 BUFFER 16 WAL_LEVEL 1;`;
const createStable = `CREATE STABLE IF NOT EXISTS ${db}.${stable} (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int);`;
let wsSql = await taos.sqlConnect(conf);
await wsSql.exec(createDB);
await wsSql.exec(createStable);
@ -57,9 +57,9 @@ async function subscribe(consumer) {
for (let [key, value] of res) {
console.log(key, value);
}
}
}catch (err) {
console.error("Failed to poll data; err.code, ErrCode:" + err.code + "; ErrMessage: " + err.message);
}
} catch (err) {
console.error("Failed to poll data; ErrCode:" + err.code + "; ErrMessage: " + err.message);
throw err;
}
@ -76,7 +76,7 @@ async function test() {
let res = new Map();
while (res.size == 0) {
res = await consumer.poll(100);
}
}
let assignment = await consumer.assignment();
await consumer.seekToBeginning(assignment);

View File

@ -1,7 +1,7 @@
import taos
conn = None
reqId = 1
reqId = 3
host="localhost"
port=6030
try:
@ -21,4 +21,4 @@ except Exception as err:
finally:
if conn:
conn.close()
conn.close()

View File

@ -2,7 +2,7 @@ import taosrest
client = None
url="http://localhost:6041"
reqId = 1
reqId = 3
try:
client = taosrest.RestClient(url=url,
user="root",

View File

@ -1,7 +1,7 @@
import taosws
conn = None
reqId = 1
reqId = 3
host="localhost"
port=6041
try:
@ -12,7 +12,7 @@ try:
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
for row in result:
print(f"ts: {row[0]}, current: {row[1]}, location: {row[2]}")
@ -21,4 +21,4 @@ except Exception as err:
print(f"Failed to execute sql with reqId:{reqId}, db addr:{host}:{port} ; ErrMessage:{err}")
finally:
if conn:
conn.close()
conn.close()

View File

@ -42,10 +42,10 @@ public class ConsumerLoopFull {
return consumer;
} catch (SQLException ex) {
// handle any errors, please refer to the JDBC specifications for detailed exceptions info
System.out.println("Failed to create native consumer, host : " + config.getProperty("bootstrap.servers") + "; ErrCode:" + ex.getErrorCode() + "; ErrMessage: " + ex.getMessage());
System.out.println("Failed to create native consumer, host: " + config.getProperty("bootstrap.servers") + "; ErrCode:" + ex.getErrorCode() + "; ErrMessage: " + ex.getMessage());
throw new SQLException("Failed to create consumer", ex);
} catch (Exception ex) {
System.out.println("Failed to create native consumer, host : " + config.getProperty("bootstrap.servers")
System.out.println("Failed to create native consumer, host: " + config.getProperty("bootstrap.servers")
+ "; ErrMessage: " + ex.getMessage());
throw new SQLException("Failed to create consumer", ex);
}

View File

@ -40,10 +40,10 @@ public class WsConsumerLoopFull {
return consumer;
} catch (SQLException ex) {
// handle any errors, please refer to the JDBC specifications for detailed exceptions info
System.out.println("Failed to create websocket consumer, host : " + config.getProperty("bootstrap.servers") + "; ErrCode:" + ex.getErrorCode() + "; ErrMessage: " + ex.getMessage());
System.out.println("Failed to create websocket consumer, host: " + config.getProperty("bootstrap.servers") + "; ErrCode:" + ex.getErrorCode() + "; ErrMessage: " + ex.getMessage());
throw new SQLException("Failed to create consumer", ex);
} catch (Exception ex) {
System.out.println("Failed to create websocket consumer, host : " + config.getProperty("bootstrap.servers")
System.out.println("Failed to create websocket consumer, host: " + config.getProperty("bootstrap.servers")
+ "; ErrMessage: " + ex.getMessage());
throw new SQLException("Failed to create consumer", ex);
}