From eff7a2d6517bf1115a046742a0b019c98e5b43df Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 5 Aug 2020 15:41:32 +0000 Subject: [PATCH 1/3] fixbug java connector --- .../com/taosdata/jdbc/TSDBJNIConnector.java | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java index e9acffe0e3..13fa2eda81 100755 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java @@ -97,7 +97,7 @@ public class TSDBJNIConnector { this.taos = this.connectImp(host, port, dbName, user, password); if (this.taos == TSDBConstants.JNI_NULL_POINTER) { - throw new SQLException(TSDBConstants.WrapErrMsg(this.getErrMsg(null)), "", this.getErrCode(null)); + throw new SQLException(TSDBConstants.WrapErrMsg(this.getErrMsg(0L)), "", this.getErrCode(0l)); } return true; @@ -115,7 +115,7 @@ public class TSDBJNIConnector { freeResultSet(taosResultSetPointer); } - long pSql = 0l; + Long pSql = 0l; try { pSql = this.executeQueryImp(sql.getBytes(TaosGlobalConfig.getCharset()), this.taos); } catch (Exception e) { @@ -124,16 +124,11 @@ public class TSDBJNIConnector { throw new SQLException(TSDBConstants.WrapErrMsg("Unsupported encoding")); } int code = this.getErrCode(pSql); - - if (code < 0) { + if (code != 0) { affectedRows = -1; - if (code == TSDBConstants.JNI_TDENGINE_ERROR) { - this.freeResultSet(pSql); - throw new SQLException(TSDBConstants.WrapErrMsg(this.getErrMsg(pSql)), "", this.getErrCode(pSql)); - } else { - this.freeResultSet(pSql); - throw new SQLException(TSDBConstants.FixErrMsg(code), "", this.getErrCode(pSql)); - } + String err_msg = this.getErrMsg(pSql); + this.freeResultSet(pSql); + throw new SQLException(TSDBConstants.WrapErrMsg(err_msg), "", code); } // Try retrieving result set for the executed SQL using the current connection pointer. If the executed @@ -151,20 +146,20 @@ public class TSDBJNIConnector { /** * Get recent error code by connection */ - public int getErrCode(Long pSql) { - return Math.abs(this.getErrCodeImp(this.taos, pSql)); + public int getErrCode(long pSql) { + return this.getErrCodeImp(this.taos, pSql); } - private native int getErrCodeImp(long connection, Long pSql); + private native int getErrCodeImp(long connection, long pSql); /** * Get recent error message by connection */ - public String getErrMsg(Long pSql) { - return this.getErrMsgImp(this.taos, pSql); + public String getErrMsg(long pSql) { + return this.getErrMsgImp(pSql); } - private native String getErrMsgImp(long connection, Long pSql); + private native String getErrMsgImp(long pSql); /** * Get resultset pointer @@ -248,7 +243,7 @@ public class TSDBJNIConnector { public void closeConnection() throws SQLException { int code = this.closeConnectionImp(this.taos); if (code < 0) { - throw new SQLException(TSDBConstants.FixErrMsg(code), "", this.getErrCode(null)); + throw new SQLException(TSDBConstants.FixErrMsg(code), "", this.getErrCode(0l)); } else if (code == 0) { this.taos = TSDBConstants.JNI_NULL_POINTER; } else { From 4425db183c55f8875654d3712fd4aff17faaa82a Mon Sep 17 00:00:00 2001 From: Liu Tao Date: Thu, 6 Aug 2020 13:17:37 +0800 Subject: [PATCH 2/3] [TD-1063] support more cols --- src/kit/taosdemo/taosdemo.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index bebcf26277..99d3175551 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -42,8 +42,8 @@ extern char configDir[]; #define BUFFER_SIZE 65536 #define MAX_DB_NAME_SIZE 64 #define MAX_TB_NAME_SIZE 64 -#define MAX_DATA_SIZE 1024 -#define MAX_NUM_DATATYPE 30 +#define MAX_DATA_SIZE 16000 +#define MAX_NUM_DATATYPE 10 #define OPT_ABORT 1 /* –abort */ #define STRING_LEN 512 #define MAX_PREPARED_RAND 1000000 @@ -155,7 +155,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { strcasecmp(arg, "TINYINT") != 0 && strcasecmp(arg, "BOOL") != 0 && strcasecmp(arg, "SMALLINT") != 0 && strcasecmp(arg, "BIGINT") != 0 && strcasecmp(arg, "DOUBLE") != 0 && - strcasecmp(arg, "BINARY")) { + strcasecmp(arg, "BINARY") && strcasecmp(arg, "NCHAR")) { argp_error(state, "Invalid data_type!"); } sptr[0] = arg; @@ -171,7 +171,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { strcasecmp(token, "BOOL") != 0 && strcasecmp(token, "SMALLINT") != 0 && strcasecmp(token, "BIGINT") != 0 && - strcasecmp(token, "DOUBLE") != 0 && strcasecmp(token, "BINARY")) { + strcasecmp(token, "DOUBLE") != 0 && strcasecmp(token, "BINARY") && strcasecmp(arg, "NCHAR")) { argp_error(state, "Invalid data_type!"); } sptr[index++] = token; @@ -412,7 +412,7 @@ int main(int argc, char *argv[]) { memset(dataString, 0, STRING_LEN); int len = 0; - if (strcasecmp(data_type[0], "BINARY") == 0 || strcasecmp(data_type[0], "BOOL") == 0) { + if (strcasecmp(data_type[0], "BINARY") == 0 || strcasecmp(data_type[0], "BOOL") == 0 || strcasecmp(data_type[0], "NCHAR") == 0 ) { do_aggreFunc = false; } for (; count_data_type <= MAX_NUM_DATATYPE; count_data_type++) { @@ -438,7 +438,7 @@ int main(int argc, char *argv[]) { printf("# Use metric: %s\n", use_metric ? "true" : "false"); printf("# Datatype of Columns: %s\n", dataString); printf("# Binary Length(If applicable): %d\n", - (strcasestr(dataString, "BINARY") != NULL) ? len_of_binary : -1); + (strcasestr(dataString, "BINARY") != NULL || strcasestr(dataString, "NCHAR") != NULL ) ? len_of_binary : -1); printf("# Number of Columns per record: %d\n", ncols_per_record); printf("# Number of Threads: %d\n", threads); printf("# Number of Tables: %d\n", ntables); @@ -466,7 +466,7 @@ int main(int argc, char *argv[]) { fprintf(fp, "# Use metric: %s\n", use_metric ? "true" : "false"); fprintf(fp, "# Datatype of Columns: %s\n", dataString); fprintf(fp, "# Binary Length(If applicable): %d\n", - (strcasestr(dataString, "BINARY") != NULL) ? len_of_binary : -1); + (strcasestr(dataString, "BINARY") != NULL || strcasestr(dataString, "NCHAR") != NULL ) ? len_of_binary : -1); fprintf(fp, "# Number of Columns per record: %d\n", ncols_per_record); fprintf(fp, "# Number of Threads: %d\n", threads); fprintf(fp, "# Number of Tables: %d\n", ntables); @@ -506,7 +506,7 @@ int main(int argc, char *argv[]) { len = 0; for (; colIndex < ncols_per_record - 1; colIndex++) { - if (strcasecmp(data_type[colIndex % count_data_type], "BINARY") != 0) { + if (strcasecmp(data_type[colIndex % count_data_type], "BINARY") != 0 && strcasecmp(data_type[colIndex % count_data_type], "NCHAR") != 0) { len += snprintf(cols + len, STRING_LEN - len, ",f%d %s", colIndex + 1, data_type[colIndex % count_data_type]); } else { len += snprintf(cols + len, STRING_LEN - len, ",f%d %s(%d)", colIndex + 1, data_type[colIndex % count_data_type], len_of_binary); @@ -522,7 +522,7 @@ int main(int argc, char *argv[]) { if (use_metric) { /* Create metric table */ printf("Creating meters super table...\n"); - snprintf(command, BUFFER_SIZE, "create table if not exists %s.meters (ts timestamp%s tags (areaid int, loc binary(10))", db_name, cols); + snprintf(command, BUFFER_SIZE, "create table if not exists %s.meters (ts timestamp%s) tags (areaid int, loc binary(10)", db_name, cols); queryDB(taos, command); printf("meters created!\n"); } @@ -1272,6 +1272,10 @@ int32_t generateData(char *res, char **data_type, int num_of_cols, int64_t times char s[len_of_binary]; rand_string(s, len_of_binary); pstr += sprintf(pstr, ", \"%s\"", s); + }else if (strcasecmp(data_type[i % c], "nchar") == 0) { + char s[len_of_binary]; + rand_string(s, len_of_binary); + pstr += sprintf(pstr, ", \"%s\"", s); } if (pstr - res > MAX_DATA_SIZE) { From 44111892426533b7d9a54e530ad3615cf04b3b89 Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Thu, 6 Aug 2020 06:01:19 +0000 Subject: [PATCH 3/3] [TD-1063] fix bugs --- src/kit/taosdemo/taosdemo.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index 99d3175551..153abcf16f 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -45,7 +45,7 @@ extern char configDir[]; #define MAX_DATA_SIZE 16000 #define MAX_NUM_DATATYPE 10 #define OPT_ABORT 1 /* –abort */ -#define STRING_LEN 512 +#define STRING_LEN 60000 #define MAX_PREPARED_RAND 1000000 /* The options we understand. */ @@ -171,11 +171,11 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { strcasecmp(token, "BOOL") != 0 && strcasecmp(token, "SMALLINT") != 0 && strcasecmp(token, "BIGINT") != 0 && - strcasecmp(token, "DOUBLE") != 0 && strcasecmp(token, "BINARY") && strcasecmp(arg, "NCHAR")) { + strcasecmp(token, "DOUBLE") != 0 && strcasecmp(token, "BINARY") && strcasecmp(token, "NCHAR")) { argp_error(state, "Invalid data_type!"); } sptr[index++] = token; - token = strsep(&running, ", "); + token = strsep(&running, ","); if (index >= MAX_NUM_DATATYPE) break; } } @@ -513,16 +513,16 @@ int main(int argc, char *argv[]) { } } - if (strcasecmp(data_type[colIndex % count_data_type], "BINARY") != 0) { - len += snprintf(cols + len, STRING_LEN - len, ",f%d %s)", colIndex + 1, data_type[colIndex % count_data_type]); + if (strcasecmp(data_type[colIndex % count_data_type], "BINARY") != 0 && strcasecmp(data_type[colIndex % count_data_type], "NCHAR") != 0){ + len += snprintf(cols + len, STRING_LEN - len, ",f%d %s", colIndex + 1, data_type[colIndex % count_data_type]); } else { - len += snprintf(cols + len, STRING_LEN - len, ",f%d %s(%d))", colIndex + 1, data_type[colIndex % count_data_type], len_of_binary); + len += snprintf(cols + len, STRING_LEN - len, ",f%d %s(%d)", colIndex + 1, data_type[colIndex % count_data_type], len_of_binary); } if (use_metric) { /* Create metric table */ printf("Creating meters super table...\n"); - snprintf(command, BUFFER_SIZE, "create table if not exists %s.meters (ts timestamp%s) tags (areaid int, loc binary(10)", db_name, cols); + snprintf(command, BUFFER_SIZE, "create table if not exists %s.meters (ts timestamp%s) tags (areaid int, loc binary(10))", db_name, cols); queryDB(taos, command); printf("meters created!\n"); }