update log
This commit is contained in:
parent
29df00a89d
commit
c6e7d69bb4
|
@ -22,55 +22,57 @@
|
||||||
#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";
|
||||||
const char *user = "root";
|
const char *user = "root";
|
||||||
const char *password = "taosdata";
|
const char *password = "taosdata";
|
||||||
uint16_t port = 6030;
|
uint16_t port = 6030;
|
||||||
int code = 0;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
// create database
|
// create database
|
||||||
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;
|
||||||
}
|
}
|
||||||
taos_free_result(result);
|
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 =
|
||||||
result = taos_query(taos, sql);
|
"CREATE STABLE IF NOT EXISTS power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (groupId "
|
||||||
code = taos_errno(result);
|
"INT, location BINARY(24))";
|
||||||
if (code != 0) {
|
result = taos_query(taos, sql);
|
||||||
printf("Failed to create stable power.meters, Server: %s:%hu, ErrCode: 0x%x, ErrMessage: %s\n.", host, port, code, taos_errstr(result));
|
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_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);
|
||||||
taos_cleanup();
|
taos_cleanup();
|
||||||
return 0;
|
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
|
||||||
|
|
|
@ -18,7 +18,7 @@ async function createConsumer() {
|
||||||
]);
|
]);
|
||||||
try {
|
try {
|
||||||
return await taos.tmqConnect(configMap);
|
return await taos.tmqConnect(configMap);
|
||||||
}catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
@ -58,8 +58,8 @@ async function subscribe(consumer) {
|
||||||
console.log(key, value);
|
console.log(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}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]}")
|
||||||
|
|
|
@ -42,10 +42,10 @@ public class ConsumerLoopFull {
|
||||||
return consumer;
|
return consumer;
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
// handle any errors, please refer to the JDBC specifications for detailed exceptions info
|
// 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);
|
throw new SQLException("Failed to create consumer", ex);
|
||||||
} catch (Exception 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());
|
+ "; ErrMessage: " + ex.getMessage());
|
||||||
throw new SQLException("Failed to create consumer", ex);
|
throw new SQLException("Failed to create consumer", ex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,10 +40,10 @@ public class WsConsumerLoopFull {
|
||||||
return consumer;
|
return consumer;
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
// handle any errors, please refer to the JDBC specifications for detailed exceptions info
|
// 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);
|
throw new SQLException("Failed to create consumer", ex);
|
||||||
} catch (Exception 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());
|
+ "; ErrMessage: " + ex.getMessage());
|
||||||
throw new SQLException("Failed to create consumer", ex);
|
throw new SQLException("Failed to create consumer", ex);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue