提交 6369d442 编写于 作者: haoranc's avatar haoranc

Merge branch 'develop' of github.com:taosdata/TDengine into dev/chr

...@@ -1601,7 +1601,7 @@ SELECT AVG(current), MAX(current), LEASTSQUARES(current, start_val, step_val), P ...@@ -1601,7 +1601,7 @@ SELECT AVG(current), MAX(current), LEASTSQUARES(current, start_val, step_val), P
**GROUP BY的限制** **GROUP BY的限制**
TAOS SQL 支持对标签、TBNAME 进行 GROUP BY 操作,也支持普通列进行 GROUP BY,前提是:仅限一列且该列的唯一值小于 10 万个。 TAOS SQL 支持对标签、TBNAME 进行 GROUP BY 操作,也支持普通列进行 GROUP BY,前提是:仅限一列且该列的唯一值小于 10 万个。注意:group by 不支持float,double 类型。
**IS NOT NULL 与不为空的表达式适用范围** **IS NOT NULL 与不为空的表达式适用范围**
......
...@@ -67,6 +67,8 @@ typedef struct { ...@@ -67,6 +67,8 @@ typedef struct {
SMLProtocolType protocol; SMLProtocolType protocol;
SMLTimeStampType tsType; SMLTimeStampType tsType;
SHashObj* smlDataToSchema; SHashObj* smlDataToSchema;
int64_t affectedRows;
} SSmlLinesInfo; } SSmlLinesInfo;
int tscSmlInsert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint, SSmlLinesInfo* info); int tscSmlInsert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint, SSmlLinesInfo* info);
......
...@@ -761,7 +761,7 @@ static int32_t doInsertChildTableWithStmt(TAOS* taos, char* sql, char* cTableNam ...@@ -761,7 +761,7 @@ static int32_t doInsertChildTableWithStmt(TAOS* taos, char* sql, char* cTableNam
code = taos_stmt_prepare(stmt, sql, (unsigned long)strlen(sql)); code = taos_stmt_prepare(stmt, sql, (unsigned long)strlen(sql));
if (code != 0) { if (code != 0) {
tscError("SML:0x%"PRIx64" taos_stmt_prepare return %d:%s", info->id, code, tstrerror(code)); tscError("SML:0x%"PRIx64" taos_stmt_prepare return %d:%s", info->id, code, taos_stmt_errstr(stmt));
taos_stmt_close(stmt); taos_stmt_close(stmt);
return code; return code;
} }
...@@ -771,7 +771,11 @@ static int32_t doInsertChildTableWithStmt(TAOS* taos, char* sql, char* cTableNam ...@@ -771,7 +771,11 @@ static int32_t doInsertChildTableWithStmt(TAOS* taos, char* sql, char* cTableNam
do { do {
code = taos_stmt_set_tbname(stmt, cTableName); code = taos_stmt_set_tbname(stmt, cTableName);
if (code != 0) { if (code != 0) {
tscError("SML:0x%"PRIx64" taos_stmt_set_tbname return %d:%s", info->id, code, tstrerror(code)); tscError("SML:0x%"PRIx64" taos_stmt_set_tbname return %d:%s", info->id, code, taos_stmt_errstr(stmt));
int affectedRows = taos_stmt_affected_rows(stmt);
info->affectedRows += affectedRows;
taos_stmt_close(stmt); taos_stmt_close(stmt);
return code; return code;
} }
...@@ -781,13 +785,21 @@ static int32_t doInsertChildTableWithStmt(TAOS* taos, char* sql, char* cTableNam ...@@ -781,13 +785,21 @@ static int32_t doInsertChildTableWithStmt(TAOS* taos, char* sql, char* cTableNam
TAOS_BIND* colsBinds = taosArrayGetP(batchBind, i); TAOS_BIND* colsBinds = taosArrayGetP(batchBind, i);
code = taos_stmt_bind_param(stmt, colsBinds); code = taos_stmt_bind_param(stmt, colsBinds);
if (code != 0) { if (code != 0) {
tscError("SML:0x%"PRIx64" taos_stmt_bind_param return %d:%s", info->id, code, tstrerror(code)); tscError("SML:0x%"PRIx64" taos_stmt_bind_param return %d:%s", info->id, code, taos_stmt_errstr(stmt));
int affectedRows = taos_stmt_affected_rows(stmt);
info->affectedRows += affectedRows;
taos_stmt_close(stmt); taos_stmt_close(stmt);
return code; return code;
} }
code = taos_stmt_add_batch(stmt); code = taos_stmt_add_batch(stmt);
if (code != 0) { if (code != 0) {
tscError("SML:0x%"PRIx64" taos_stmt_add_batch return %d:%s", info->id, code, tstrerror(code)); tscError("SML:0x%"PRIx64" taos_stmt_add_batch return %d:%s", info->id, code, taos_stmt_errstr(stmt));
int affectedRows = taos_stmt_affected_rows(stmt);
info->affectedRows += affectedRows;
taos_stmt_close(stmt); taos_stmt_close(stmt);
return code; return code;
} }
...@@ -795,9 +807,10 @@ static int32_t doInsertChildTableWithStmt(TAOS* taos, char* sql, char* cTableNam ...@@ -795,9 +807,10 @@ static int32_t doInsertChildTableWithStmt(TAOS* taos, char* sql, char* cTableNam
code = taos_stmt_execute(stmt); code = taos_stmt_execute(stmt);
if (code != 0) { if (code != 0) {
tscError("SML:0x%"PRIx64" taos_stmt_execute return %d:%s, try:%d", info->id, code, tstrerror(code), try); tscError("SML:0x%"PRIx64" taos_stmt_execute return %d:%s, try:%d", info->id, code, taos_stmt_errstr(stmt), try);
} }
tscDebug("SML:0x%"PRIx64" taos_stmt_execute inserted %d rows", info->id, taos_stmt_affected_rows(stmt));
tryAgain = false; tryAgain = false;
if ((code == TSDB_CODE_TDB_INVALID_TABLE_ID if ((code == TSDB_CODE_TDB_INVALID_TABLE_ID
|| code == TSDB_CODE_VND_INVALID_VGROUP_ID || code == TSDB_CODE_VND_INVALID_VGROUP_ID
...@@ -825,6 +838,8 @@ static int32_t doInsertChildTableWithStmt(TAOS* taos, char* sql, char* cTableNam ...@@ -825,6 +838,8 @@ static int32_t doInsertChildTableWithStmt(TAOS* taos, char* sql, char* cTableNam
} }
} while (tryAgain); } while (tryAgain);
int affectedRows = taos_stmt_affected_rows(stmt);
info->affectedRows += affectedRows;
taos_stmt_close(stmt); taos_stmt_close(stmt);
return code; return code;
...@@ -1069,6 +1084,8 @@ int tscSmlInsert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint, SSmlLine ...@@ -1069,6 +1084,8 @@ int tscSmlInsert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint, SSmlLine
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
info->affectedRows = 0;
tscDebug("SML:0x%"PRIx64" build data point schemas", info->id); tscDebug("SML:0x%"PRIx64" build data point schemas", info->id);
SArray* stableSchemas = taosArrayInit(32, sizeof(SSmlSTableSchema)); // SArray<STableColumnsSchema> SArray* stableSchemas = taosArrayInit(32, sizeof(SSmlSTableSchema)); // SArray<STableColumnsSchema>
code = buildDataPointSchemas(points, numPoint, stableSchemas, info); code = buildDataPointSchemas(points, numPoint, stableSchemas, info);
...@@ -1871,7 +1888,7 @@ static int32_t parseSmlKey(TAOS_SML_KV *pKV, const char **index, SHashObj *pHash ...@@ -1871,7 +1888,7 @@ static int32_t parseSmlKey(TAOS_SML_KV *pKV, const char **index, SHashObj *pHash
//key field cannot start with digit //key field cannot start with digit
if (isdigit(*cur)) { if (isdigit(*cur)) {
tscError("SML:0x%"PRIx64" Tag key cannnot start with digit", info->id); tscError("SML:0x%"PRIx64" Tag key cannot start with digit", info->id);
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR; return TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
} }
while (*cur != '\0') { while (*cur != '\0') {
...@@ -1885,6 +1902,8 @@ static int32_t parseSmlKey(TAOS_SML_KV *pKV, const char **index, SHashObj *pHash ...@@ -1885,6 +1902,8 @@ static int32_t parseSmlKey(TAOS_SML_KV *pKV, const char **index, SHashObj *pHash
} }
//Escape special character //Escape special character
if (*cur == '\\') { if (*cur == '\\') {
//TODO: escape will work after column & tag
//support spcial characters
escapeSpecialCharacter(2, &cur); escapeSpecialCharacter(2, &cur);
} }
key[len] = *cur; key[len] = *cur;
...@@ -1911,13 +1930,42 @@ static int32_t parseSmlKey(TAOS_SML_KV *pKV, const char **index, SHashObj *pHash ...@@ -1911,13 +1930,42 @@ static int32_t parseSmlKey(TAOS_SML_KV *pKV, const char **index, SHashObj *pHash
static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **index, static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **index,
bool *is_last_kv, SSmlLinesInfo* info, bool isTag) { bool *is_last_kv, SSmlLinesInfo* info, bool isTag) {
const char *start, *cur; const char *start, *cur;
int32_t ret = TSDB_CODE_SUCCESS;
char *value = NULL; char *value = NULL;
uint16_t len = 0; uint16_t len = 0;
bool searchQuote = false;
start = cur = *index; start = cur = *index;
//if field value is string
if (!isTag) {
if (*cur == '"') {
searchQuote = true;
cur += 1;
len += 1;
} else if (*cur == 'L' && *(cur + 1) == '"') {
searchQuote = true;
cur += 2;
len += 2;
}
}
while (1) { while (1) {
// unescaped ',' or ' ' or '\0' identifies a value // unescaped ',' or ' ' or '\0' identifies a value
if ((*cur == ',' || *cur == ' ' || *cur == '\0') && *(cur - 1) != '\\') { if (((*cur == ',' || *cur == ' ' ) && *(cur - 1) != '\\') || *cur == '\0') {
if (searchQuote == true) {
//first quote ignored while searching
if (*(cur - 1) == '"' && len != 1 && len != 2) {
*is_last_kv = (*cur == ' ' || *cur == '\0') ? true : false;
break;
} else if (*cur == '\0') {
ret = TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
goto error;
} else {
cur++;
len++;
continue;
}
}
//unescaped ' ' or '\0' indicates end of value //unescaped ' ' or '\0' indicates end of value
*is_last_kv = (*cur == ' ' || *cur == '\0') ? true : false; *is_last_kv = (*cur == ' ' || *cur == '\0') ? true : false;
if (*cur == ' ' && *(cur + 1) == ' ') { if (*cur == ' ' && *(cur + 1) == ' ') {
...@@ -1929,7 +1977,7 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **index, ...@@ -1929,7 +1977,7 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **index,
} }
//Escape special character //Escape special character
if (*cur == '\\') { if (*cur == '\\') {
escapeSpecialCharacter(2, &cur); escapeSpecialCharacter(isTag ? 2 : 3, &cur);
} }
cur++; cur++;
len++; len++;
...@@ -1946,16 +1994,20 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **index, ...@@ -1946,16 +1994,20 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **index,
if (!convertSmlValueType(pKV, value, len, info, isTag)) { if (!convertSmlValueType(pKV, value, len, info, isTag)) {
tscError("SML:0x%"PRIx64" Failed to convert sml value string(%s) to any type", tscError("SML:0x%"PRIx64" Failed to convert sml value string(%s) to any type",
info->id, value); info->id, value);
//free previous alocated key field
free(pKV->key);
pKV->key = NULL;
free(value); free(value);
return TSDB_CODE_TSC_INVALID_VALUE; ret = TSDB_CODE_TSC_INVALID_VALUE;
goto error;
} }
free(value); free(value);
*index = (*cur == '\0') ? cur : cur + 1; *index = (*cur == '\0') ? cur : cur + 1;
return TSDB_CODE_SUCCESS; return ret;
error:
//free previous alocated key field
free(pKV->key);
pKV->key = NULL;
return ret;
} }
static int32_t parseSmlMeasurement(TAOS_SML_DATA_POINT *pSml, const char **index, static int32_t parseSmlMeasurement(TAOS_SML_DATA_POINT *pSml, const char **index,
......
...@@ -138,21 +138,41 @@ static int32_t parseTelnetMetricValue(TAOS_SML_KV **pKVs, int *num_kvs, const ch ...@@ -138,21 +138,41 @@ static int32_t parseTelnetMetricValue(TAOS_SML_KV **pKVs, int *num_kvs, const ch
const char *start, *cur; const char *start, *cur;
int32_t ret = TSDB_CODE_SUCCESS; int32_t ret = TSDB_CODE_SUCCESS;
int len = 0; int len = 0;
bool searchQuote = false;
char key[] = OTD_METRIC_VALUE_COLUMN_NAME; char key[] = OTD_METRIC_VALUE_COLUMN_NAME;
char *value = NULL; char *value = NULL;
start = cur = *index; start = cur = *index;
//if metric value is string
if (*cur == '"') {
searchQuote = true;
cur += 1;
len += 1;
} else if (*cur == 'L' && *(cur + 1) == '"') {
searchQuote = true;
cur += 2;
len += 2;
}
while(*cur != '\0') { while(*cur != '\0') {
if (*cur == ' ') { if (*cur == ' ') {
if (*cur == ' ') { if (searchQuote == true) {
if (*(cur + 1) != ' ') { if (*(cur - 1) == '"' && len != 1 && len != 2) {
break; searchQuote = false;
} else { } else {
cur++; cur++;
len++;
continue; continue;
} }
} }
if (*(cur + 1) != ' ') {
break;
} else {
cur++;
continue;
}
} }
cur++; cur++;
len++; len++;
......
...@@ -78,6 +78,8 @@ typedef struct STscStmt { ...@@ -78,6 +78,8 @@ typedef struct STscStmt {
SSqlObj* pSql; SSqlObj* pSql;
SMultiTbStmt mtb; SMultiTbStmt mtb;
SNormalStmt normal; SNormalStmt normal;
int numOfRows;
} STscStmt; } STscStmt;
#define STMT_RET(c) do { \ #define STMT_RET(c) do { \
...@@ -1212,6 +1214,8 @@ static int insertStmtExecute(STscStmt* stmt) { ...@@ -1212,6 +1214,8 @@ static int insertStmtExecute(STscStmt* stmt) {
// wait for the callback function to post the semaphore // wait for the callback function to post the semaphore
tsem_wait(&pSql->rspSem); tsem_wait(&pSql->rspSem);
stmt->numOfRows += pSql->res.numOfRows;
// data block reset // data block reset
pCmd->batchSize = 0; pCmd->batchSize = 0;
for(int32_t i = 0; i < pCmd->insertParam.numOfTables; ++i) { for(int32_t i = 0; i < pCmd->insertParam.numOfTables; ++i) {
...@@ -1284,7 +1288,9 @@ static int insertBatchStmtExecute(STscStmt* pStmt) { ...@@ -1284,7 +1288,9 @@ static int insertBatchStmtExecute(STscStmt* pStmt) {
tsem_wait(&pStmt->pSql->rspSem); tsem_wait(&pStmt->pSql->rspSem);
code = pStmt->pSql->res.code; code = pStmt->pSql->res.code;
pStmt->numOfRows += pStmt->pSql->res.numOfRows;
insertBatchClean(pStmt); insertBatchClean(pStmt);
return code; return code;
...@@ -1516,11 +1522,12 @@ TAOS_STMT* taos_stmt_init(TAOS* taos) { ...@@ -1516,11 +1522,12 @@ TAOS_STMT* taos_stmt_init(TAOS* taos) {
} }
tsem_init(&pSql->rspSem, 0, 0); tsem_init(&pSql->rspSem, 0, 0);
pSql->signature = pSql; pSql->signature = pSql;
pSql->pTscObj = pObj; pSql->pTscObj = pObj;
pSql->maxRetry = TSDB_MAX_REPLICA; pSql->maxRetry = TSDB_MAX_REPLICA;
pStmt->pSql = pSql; pStmt->pSql = pSql;
pStmt->last = STMT_INIT; pStmt->last = STMT_INIT;
pStmt->numOfRows = 0;
registerSqlObj(pSql); registerSqlObj(pSql);
return pStmt; return pStmt;
...@@ -1564,9 +1571,7 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { ...@@ -1564,9 +1571,7 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) {
} }
pRes->qId = 0; pRes->qId = 0;
pRes->numOfRows = 1; pRes->numOfRows = 0;
registerSqlObj(pSql);
strtolower(pSql->sqlstr, sql); strtolower(pSql->sqlstr, sql);
tscDebugL("0x%"PRIx64" SQL: %s", pSql->self, pSql->sqlstr); tscDebugL("0x%"PRIx64" SQL: %s", pSql->self, pSql->sqlstr);
...@@ -1981,6 +1986,7 @@ int taos_stmt_execute(TAOS_STMT* stmt) { ...@@ -1981,6 +1986,7 @@ int taos_stmt_execute(TAOS_STMT* stmt) {
} else { } else {
taosReleaseRef(tscObjRef, pStmt->pSql->self); taosReleaseRef(tscObjRef, pStmt->pSql->self);
pStmt->pSql = taos_query((TAOS*)pStmt->taos, sql); pStmt->pSql = taos_query((TAOS*)pStmt->taos, sql);
pStmt->numOfRows += taos_affected_rows(pStmt->pSql);
ret = taos_errno(pStmt->pSql); ret = taos_errno(pStmt->pSql);
free(sql); free(sql);
} }
...@@ -1989,6 +1995,17 @@ int taos_stmt_execute(TAOS_STMT* stmt) { ...@@ -1989,6 +1995,17 @@ int taos_stmt_execute(TAOS_STMT* stmt) {
STMT_RET(ret); STMT_RET(ret);
} }
int taos_stmt_affected_rows(TAOS_STMT* stmt) {
STscStmt* pStmt = (STscStmt*)stmt;
if (pStmt == NULL) {
tscError("statement is invalid");
return 0;
}
return pStmt->numOfRows;
}
TAOS_RES *taos_stmt_use_result(TAOS_STMT* stmt) { TAOS_RES *taos_stmt_use_result(TAOS_STMT* stmt) {
if (stmt == NULL) { if (stmt == NULL) {
tscError("statement is invalid."); tscError("statement is invalid.");
......
...@@ -562,25 +562,27 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da ...@@ -562,25 +562,27 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da
List<TSDBResultSetRowData> rowDataList = new ArrayList<>(); List<TSDBResultSetRowData> rowDataList = new ArrayList<>();
try (Statement stmt = connection.createStatement()) { try (Statement stmt = connection.createStatement()) {
stmt.execute("use " + catalog); stmt.execute("use " + catalog);
ResultSet tables = stmt.executeQuery("show tables"); try (ResultSet tables = stmt.executeQuery("show tables")) {
while (tables.next()) { while (tables.next()) {
TSDBResultSetRowData rowData = new TSDBResultSetRowData(10); TSDBResultSetRowData rowData = new TSDBResultSetRowData(10);
rowData.setStringValue(1, catalog); //TABLE_CAT rowData.setStringValue(1, catalog); //TABLE_CAT
rowData.setStringValue(2, null); //TABLE_SCHEM rowData.setStringValue(2, null); //TABLE_SCHEM
rowData.setStringValue(3, tables.getString("table_name")); //TABLE_NAME rowData.setStringValue(3, tables.getString("table_name")); //TABLE_NAME
rowData.setStringValue(4, "TABLE"); //TABLE_TYPE rowData.setStringValue(4, "TABLE"); //TABLE_TYPE
rowData.setStringValue(5, ""); //REMARKS rowData.setStringValue(5, ""); //REMARKS
rowDataList.add(rowData); rowDataList.add(rowData);
}
} }
ResultSet stables = stmt.executeQuery("show stables"); try (ResultSet stables = stmt.executeQuery("show stables")) {
while (stables.next()) { while (stables.next()) {
TSDBResultSetRowData rowData = new TSDBResultSetRowData(10); TSDBResultSetRowData rowData = new TSDBResultSetRowData(10);
rowData.setStringValue(1, catalog); //TABLE_CAT rowData.setStringValue(1, catalog); //TABLE_CAT
rowData.setStringValue(2, null); //TABLE_SCHEM rowData.setStringValue(2, null); //TABLE_SCHEM
rowData.setStringValue(3, stables.getString("name")); //TABLE_NAME rowData.setStringValue(3, stables.getString("name")); //TABLE_NAME
rowData.setStringValue(4, "TABLE"); //TABLE_TYPE rowData.setStringValue(4, "TABLE"); //TABLE_TYPE
rowData.setStringValue(5, "STABLE"); //REMARKS rowData.setStringValue(5, "STABLE"); //REMARKS
rowDataList.add(rowData); rowDataList.add(rowData);
}
} }
resultSet.setRowDataList(rowDataList); resultSet.setRowDataList(rowDataList);
} }
...@@ -638,8 +640,9 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da ...@@ -638,8 +640,9 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da
resultSet.setColumnMetaDataList(buildGetColumnsColumnMetaDataList()); resultSet.setColumnMetaDataList(buildGetColumnsColumnMetaDataList());
// set up rowDataList // set up rowDataList
List<TSDBResultSetRowData> rowDataList = new ArrayList<>(); List<TSDBResultSetRowData> rowDataList = new ArrayList<>();
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("describe " + catalog + "." + tableNamePattern); ResultSet rs = stmt.executeQuery("describe " + catalog + "." + tableNamePattern)) {
int rowIndex = 0; int rowIndex = 0;
while (rs.next()) { while (rs.next()) {
TSDBResultSetRowData rowData = new TSDBResultSetRowData(24); TSDBResultSetRowData rowData = new TSDBResultSetRowData(24);
...@@ -1147,9 +1150,9 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da ...@@ -1147,9 +1150,9 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da
columnMetaDataList.add(buildTableCatalogMeta(1)); // 1. TABLE_CAT columnMetaDataList.add(buildTableCatalogMeta(1)); // 1. TABLE_CAT
resultSet.setColumnMetaDataList(columnMetaDataList); resultSet.setColumnMetaDataList(columnMetaDataList);
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("show databases")) {
List<TSDBResultSetRowData> rowDataList = new ArrayList<>(); List<TSDBResultSetRowData> rowDataList = new ArrayList<>();
ResultSet rs = stmt.executeQuery("show databases");
while (rs.next()) { while (rs.next()) {
TSDBResultSetRowData rowData = new TSDBResultSetRowData(1); TSDBResultSetRowData rowData = new TSDBResultSetRowData(1);
rowData.setStringValue(1, rs.getString("name")); rowData.setStringValue(1, rs.getString("name"));
...@@ -1168,12 +1171,13 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da ...@@ -1168,12 +1171,13 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da
return new EmptyResultSet(); return new EmptyResultSet();
DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet();
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("describe " + catalog + "." + table)) {
// set up ColumnMetaDataList // set up ColumnMetaDataList
resultSet.setColumnMetaDataList(buildGetPrimaryKeysMetadataList()); resultSet.setColumnMetaDataList(buildGetPrimaryKeysMetadataList());
// set rowData // set rowData
List<TSDBResultSetRowData> rowDataList = new ArrayList<>(); List<TSDBResultSetRowData> rowDataList = new ArrayList<>();
ResultSet rs = stmt.executeQuery("describe " + catalog + "." + table);
rs.next(); rs.next();
TSDBResultSetRowData rowData = new TSDBResultSetRowData(6); TSDBResultSetRowData rowData = new TSDBResultSetRowData(6);
rowData.setStringValue(1, catalog); rowData.setStringValue(1, catalog);
...@@ -1217,15 +1221,14 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da ...@@ -1217,15 +1221,14 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da
} }
private boolean isAvailableCatalog(Connection connection, String catalog) { private boolean isAvailableCatalog(Connection connection, String catalog) {
try (Statement stmt = connection.createStatement()) { try (Statement stmt = connection.createStatement();
ResultSet databases = stmt.executeQuery("show databases"); ResultSet databases = stmt.executeQuery("show databases")) {
while (databases.next()) { while (databases.next()) {
String dbname = databases.getString("name"); String dbname = databases.getString("name");
this.precision = databases.getString("precision"); this.precision = databases.getString("precision");
if (dbname.equalsIgnoreCase(catalog)) if (dbname.equalsIgnoreCase(catalog))
return true; return true;
} }
databases.close();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -1246,17 +1249,18 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da ...@@ -1246,17 +1249,18 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da
resultSet.setColumnMetaDataList(buildGetSuperTablesColumnMetaDataList()); resultSet.setColumnMetaDataList(buildGetSuperTablesColumnMetaDataList());
// set result set row data // set result set row data
stmt.execute("use " + catalog); stmt.execute("use " + catalog);
ResultSet rs = stmt.executeQuery("show tables like '" + tableNamePattern + "'"); try (ResultSet rs = stmt.executeQuery("show tables like '" + tableNamePattern + "'")) {
List<TSDBResultSetRowData> rowDataList = new ArrayList<>(); List<TSDBResultSetRowData> rowDataList = new ArrayList<>();
while (rs.next()) { while (rs.next()) {
TSDBResultSetRowData rowData = new TSDBResultSetRowData(4); TSDBResultSetRowData rowData = new TSDBResultSetRowData(4);
rowData.setStringValue(1, catalog); rowData.setStringValue(1, catalog);
rowData.setStringValue(2, null); rowData.setStringValue(2, null);
rowData.setStringValue(3, rs.getString("table_name")); rowData.setStringValue(3, rs.getString("table_name"));
rowData.setStringValue(4, rs.getString("stable_name")); rowData.setStringValue(4, rs.getString("stable_name"));
rowDataList.add(rowData); rowDataList.add(rowData);
}
resultSet.setRowDataList(rowDataList);
} }
resultSet.setRowDataList(rowDataList);
} }
return resultSet; return resultSet;
} }
......
...@@ -189,7 +189,7 @@ public class TSDBResultSetRowData { ...@@ -189,7 +189,7 @@ public class TSDBResultSetRowData {
long value = (long) obj; long value = (long) obj;
if (value < 0) if (value < 0)
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE);
return Long.valueOf(value).intValue(); return (int) value;
} }
......
...@@ -64,9 +64,9 @@ public class RestfulDriver extends AbstractDriver { ...@@ -64,9 +64,9 @@ public class RestfulDriver extends AbstractDriver {
RestfulConnection conn = new RestfulConnection(host, port, props, database, url, token); RestfulConnection conn = new RestfulConnection(host, port, props, database, url, token);
if (database != null && !database.trim().replaceAll("\\s", "").isEmpty()) { if (database != null && !database.trim().replaceAll("\\s", "").isEmpty()) {
Statement stmt = conn.createStatement(); try (Statement stmt = conn.createStatement()) {
stmt.execute("use " + database); stmt.execute("use " + database);
stmt.close(); }
} }
return conn; return conn;
} }
......
...@@ -141,6 +141,7 @@ DLL_EXPORT int taos_stmt_bind_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIN ...@@ -141,6 +141,7 @@ DLL_EXPORT int taos_stmt_bind_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIN
DLL_EXPORT int taos_stmt_bind_single_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind, int colIdx); DLL_EXPORT int taos_stmt_bind_single_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind, int colIdx);
DLL_EXPORT int taos_stmt_add_batch(TAOS_STMT *stmt); DLL_EXPORT int taos_stmt_add_batch(TAOS_STMT *stmt);
DLL_EXPORT int taos_stmt_execute(TAOS_STMT *stmt); DLL_EXPORT int taos_stmt_execute(TAOS_STMT *stmt);
DLL_EXPORT int taos_stmt_affected_rows(TAOS_STMT *stmt);
DLL_EXPORT TAOS_RES * taos_stmt_use_result(TAOS_STMT *stmt); DLL_EXPORT TAOS_RES * taos_stmt_use_result(TAOS_STMT *stmt);
DLL_EXPORT int taos_stmt_close(TAOS_STMT *stmt); DLL_EXPORT int taos_stmt_close(TAOS_STMT *stmt);
DLL_EXPORT char * taos_stmt_errstr(TAOS_STMT *stmt); DLL_EXPORT char * taos_stmt_errstr(TAOS_STMT *stmt);
......
...@@ -245,6 +245,7 @@ typedef struct SArguments_S { ...@@ -245,6 +245,7 @@ typedef struct SArguments_S {
uint64_t insert_interval; uint64_t insert_interval;
uint64_t timestamp_step; uint64_t timestamp_step;
int64_t query_times; int64_t query_times;
int64_t prepared_rand;
uint32_t interlaceRows; uint32_t interlaceRows;
uint32_t reqPerReq; // num_of_records_per_req uint32_t reqPerReq; // num_of_records_per_req
uint64_t max_sql_len; uint64_t max_sql_len;
...@@ -366,7 +367,7 @@ typedef struct SDataBase_S { ...@@ -366,7 +367,7 @@ typedef struct SDataBase_S {
bool drop; // 0: use exists, 1: if exists, drop then new create bool drop; // 0: use exists, 1: if exists, drop then new create
SDbCfg dbCfg; SDbCfg dbCfg;
uint64_t superTblCount; uint64_t superTblCount;
SSuperTable superTbls[MAX_SUPER_TABLE_COUNT]; SSuperTable* superTbls;
} SDataBase; } SDataBase;
typedef struct SDbs_S { typedef struct SDbs_S {
...@@ -385,12 +386,11 @@ typedef struct SDbs_S { ...@@ -385,12 +386,11 @@ typedef struct SDbs_S {
uint32_t threadCount; uint32_t threadCount;
uint32_t threadCountForCreateTbl; uint32_t threadCountForCreateTbl;
uint32_t dbCount; uint32_t dbCount;
SDataBase db[MAX_DB_COUNT];
// statistics // statistics
uint64_t totalInsertRows; uint64_t totalInsertRows;
uint64_t totalAffectedRows; uint64_t totalAffectedRows;
SDataBase* db;
} SDbs; } SDbs;
typedef struct SpecifiedQueryInfo_S { typedef struct SpecifiedQueryInfo_S {
...@@ -593,12 +593,12 @@ static int regexMatch(const char *s, const char *reg, int cflags); ...@@ -593,12 +593,12 @@ static int regexMatch(const char *s, const char *reg, int cflags);
/* ************ Global variables ************ */ /* ************ Global variables ************ */
int32_t g_randint[MAX_PREPARED_RAND]; int32_t* g_randint;
uint32_t g_randuint[MAX_PREPARED_RAND]; uint32_t* g_randuint;
int64_t g_randbigint[MAX_PREPARED_RAND]; int64_t* g_randbigint;
uint64_t g_randubigint[MAX_PREPARED_RAND]; uint64_t* g_randubigint;
float g_randfloat[MAX_PREPARED_RAND]; float* g_randfloat;
double g_randdouble[MAX_PREPARED_RAND]; double* g_randdouble;
char *g_randbool_buff = NULL; char *g_randbool_buff = NULL;
char *g_randint_buff = NULL; char *g_randint_buff = NULL;
...@@ -666,6 +666,7 @@ SArguments g_args = { ...@@ -666,6 +666,7 @@ SArguments g_args = {
0, // insert_interval 0, // insert_interval
DEFAULT_TIMESTAMP_STEP, // timestamp_step DEFAULT_TIMESTAMP_STEP, // timestamp_step
1, // query_times 1, // query_times
10000, // prepared_rand
DEFAULT_INTERLACE_ROWS, // interlaceRows; DEFAULT_INTERLACE_ROWS, // interlaceRows;
30000, // reqPerReq 30000, // reqPerReq
(1024*1024), // max_sql_len (1024*1024), // max_sql_len
...@@ -800,6 +801,8 @@ static void printHelp() { ...@@ -800,6 +801,8 @@ static void printHelp() {
"Set the replica parameters of the database, By default use 1, min: 1, max: 3."); "Set the replica parameters of the database, By default use 1, min: 1, max: 3.");
printf("%s%s%s%s\n", indent, "-m, --table-prefix=TABLEPREFIX", "\t", printf("%s%s%s%s\n", indent, "-m, --table-prefix=TABLEPREFIX", "\t",
"Table prefix name. By default use 'd'."); "Table prefix name. By default use 'd'.");
printf("%s%s%s%s\n", indent, "-E, --escape-character", "\t",
"Use escape character for Both Stable and normmal table name");
printf("%s%s%s%s\n", indent, "-s, --sql-file=FILE", "\t\t", printf("%s%s%s%s\n", indent, "-s, --sql-file=FILE", "\t\t",
"The select sql file."); "The select sql file.");
printf("%s%s%s%s\n", indent, "-N, --normal-table", "\t\t", "Use normal table flag."); printf("%s%s%s%s\n", indent, "-N, --normal-table", "\t\t", "Use normal table flag.");
...@@ -1893,12 +1896,6 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) { ...@@ -1893,12 +1896,6 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
arguments->disorderRatio, 50); arguments->disorderRatio, 50);
arguments->disorderRatio = 50; arguments->disorderRatio = 50;
} }
if (arguments->disorderRatio < 0) {
errorPrint("Invalid disorder ratio %d, will be set to %d\n",
arguments->disorderRatio, 0);
arguments->disorderRatio = 0;
}
} else if ((0 == strncmp(argv[i], "-a", strlen("-a"))) } else if ((0 == strncmp(argv[i], "-a", strlen("-a")))
|| (0 == strncmp(argv[i], "--replica", || (0 == strncmp(argv[i], "--replica",
strlen("--replica")))) { strlen("--replica")))) {
...@@ -2110,7 +2107,7 @@ static void tmfclose(FILE *fp) { ...@@ -2110,7 +2107,7 @@ static void tmfclose(FILE *fp) {
} }
} }
static void tmfree(char *buf) { static void tmfree(void *buf) {
if (NULL != buf) { if (NULL != buf) {
free(buf); free(buf);
buf = NULL; buf = NULL;
...@@ -2234,157 +2231,157 @@ static void selectAndGetResult( ...@@ -2234,157 +2231,157 @@ static void selectAndGetResult(
static char *rand_bool_str() { static char *rand_bool_str() {
static int cursor; static int cursor;
cursor++; cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0; if (cursor > (g_args.prepared_rand - 1)) cursor = 0;
return g_randbool_buff + ((cursor % MAX_PREPARED_RAND) * BOOL_BUFF_LEN); return g_randbool_buff + ((cursor % g_args.prepared_rand) * BOOL_BUFF_LEN);
} }
static int32_t rand_bool() { static int32_t rand_bool() {
static int cursor; static int cursor;
cursor++; cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0; if (cursor > (g_args.prepared_rand - 1)) cursor = 0;
return g_randint[cursor % MAX_PREPARED_RAND] % 2; return g_randint[cursor % g_args.prepared_rand] % 2;
} }
static char *rand_tinyint_str() static char *rand_tinyint_str()
{ {
static int cursor; static int cursor;
cursor++; cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0; if (cursor > (g_args.prepared_rand - 1)) cursor = 0;
return g_randtinyint_buff + return g_randtinyint_buff +
((cursor % MAX_PREPARED_RAND) * TINYINT_BUFF_LEN); ((cursor % g_args.prepared_rand) * TINYINT_BUFF_LEN);
} }
static int32_t rand_tinyint() static int32_t rand_tinyint()
{ {
static int cursor; static int cursor;
cursor++; cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0; if (cursor > (g_args.prepared_rand - 1)) cursor = 0;
return g_randint[cursor % MAX_PREPARED_RAND] % 128; return g_randint[cursor % g_args.prepared_rand] % 128;
} }
static char *rand_utinyint_str() static char *rand_utinyint_str()
{ {
static int cursor; static int cursor;
cursor++; cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0; if (cursor > (g_args.prepared_rand - 1)) cursor = 0;
return g_randutinyint_buff + return g_randutinyint_buff +
((cursor % MAX_PREPARED_RAND) * TINYINT_BUFF_LEN); ((cursor % g_args.prepared_rand) * TINYINT_BUFF_LEN);
} }
static int32_t rand_utinyint() static int32_t rand_utinyint()
{ {
static int cursor; static int cursor;
cursor++; cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0; if (cursor > (g_args.prepared_rand - 1)) cursor = 0;
return g_randuint[cursor % MAX_PREPARED_RAND] % 255; return g_randuint[cursor % g_args.prepared_rand] % 255;
} }
static char *rand_smallint_str() static char *rand_smallint_str()
{ {
static int cursor; static int cursor;
cursor++; cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0; if (cursor > (g_args.prepared_rand - 1)) cursor = 0;
return g_randsmallint_buff + return g_randsmallint_buff +
((cursor % MAX_PREPARED_RAND) * SMALLINT_BUFF_LEN); ((cursor % g_args.prepared_rand) * SMALLINT_BUFF_LEN);
} }
static int32_t rand_smallint() static int32_t rand_smallint()
{ {
static int cursor; static int cursor;
cursor++; cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0; if (cursor > (g_args.prepared_rand - 1)) cursor = 0;
return g_randint[cursor % MAX_PREPARED_RAND] % 32768; return g_randint[cursor % g_args.prepared_rand] % 32768;
} }
static char *rand_usmallint_str() static char *rand_usmallint_str()
{ {
static int cursor; static int cursor;
cursor++; cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0; if (cursor > (g_args.prepared_rand - 1)) cursor = 0;
return g_randusmallint_buff + return g_randusmallint_buff +
((cursor % MAX_PREPARED_RAND) * SMALLINT_BUFF_LEN); ((cursor % g_args.prepared_rand) * SMALLINT_BUFF_LEN);
} }
static int32_t rand_usmallint() static int32_t rand_usmallint()
{ {
static int cursor; static int cursor;
cursor++; cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0; if (cursor > (g_args.prepared_rand - 1)) cursor = 0;
return g_randuint[cursor % MAX_PREPARED_RAND] % 65535; return g_randuint[cursor % g_args.prepared_rand] % 65535;
} }
static char *rand_int_str() static char *rand_int_str()
{ {
static int cursor; static int cursor;
cursor++; cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0; if (cursor > (g_args.prepared_rand - 1)) cursor = 0;
return g_randint_buff + ((cursor % MAX_PREPARED_RAND) * INT_BUFF_LEN); return g_randint_buff + ((cursor % g_args.prepared_rand) * INT_BUFF_LEN);
} }
static int32_t rand_int() static int32_t rand_int()
{ {
static int cursor; static int cursor;
cursor++; cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0; if (cursor > (g_args.prepared_rand - 1)) cursor = 0;
return g_randint[cursor % MAX_PREPARED_RAND]; return g_randint[cursor % g_args.prepared_rand];
} }
static char *rand_uint_str() static char *rand_uint_str()
{ {
static int cursor; static int cursor;
cursor++; cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0; if (cursor > (g_args.prepared_rand - 1)) cursor = 0;
return g_randuint_buff + ((cursor % MAX_PREPARED_RAND) * INT_BUFF_LEN); return g_randuint_buff + ((cursor % g_args.prepared_rand) * INT_BUFF_LEN);
} }
static int32_t rand_uint() static int32_t rand_uint()
{ {
static int cursor; static int cursor;
cursor++; cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0; if (cursor > (g_args.prepared_rand - 1)) cursor = 0;
return g_randuint[cursor % MAX_PREPARED_RAND]; return g_randuint[cursor % g_args.prepared_rand];
} }
static char *rand_bigint_str() static char *rand_bigint_str()
{ {
static int cursor; static int cursor;
cursor++; cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0; if (cursor > (g_args.prepared_rand - 1)) cursor = 0;
return g_randbigint_buff + return g_randbigint_buff +
((cursor % MAX_PREPARED_RAND) * BIGINT_BUFF_LEN); ((cursor % g_args.prepared_rand) * BIGINT_BUFF_LEN);
} }
static int64_t rand_bigint() static int64_t rand_bigint()
{ {
static int cursor; static int cursor;
cursor++; cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0; if (cursor > (g_args.prepared_rand - 1)) cursor = 0;
return g_randbigint[cursor % MAX_PREPARED_RAND]; return g_randbigint[cursor % g_args.prepared_rand];
} }
static char *rand_ubigint_str() static char *rand_ubigint_str()
{ {
static int cursor; static int cursor;
cursor++; cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0; if (cursor > (g_args.prepared_rand - 1)) cursor = 0;
return g_randubigint_buff + return g_randubigint_buff +
((cursor % MAX_PREPARED_RAND) * BIGINT_BUFF_LEN); ((cursor % g_args.prepared_rand) * BIGINT_BUFF_LEN);
} }
static int64_t rand_ubigint() static int64_t rand_ubigint()
{ {
static int cursor; static int cursor;
cursor++; cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0; if (cursor > (g_args.prepared_rand - 1)) cursor = 0;
return g_randubigint[cursor % MAX_PREPARED_RAND]; return g_randubigint[cursor % g_args.prepared_rand];
} }
static char *rand_float_str() static char *rand_float_str()
{ {
static int cursor; static int cursor;
cursor++; cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0; if (cursor > (g_args.prepared_rand - 1)) cursor = 0;
return g_randfloat_buff + ((cursor % MAX_PREPARED_RAND) * FLOAT_BUFF_LEN); return g_randfloat_buff + ((cursor % g_args.prepared_rand) * FLOAT_BUFF_LEN);
} }
...@@ -2392,58 +2389,58 @@ static float rand_float() ...@@ -2392,58 +2389,58 @@ static float rand_float()
{ {
static int cursor; static int cursor;
cursor++; cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0; if (cursor > (g_args.prepared_rand - 1)) cursor = 0;
return g_randfloat[cursor % MAX_PREPARED_RAND]; return g_randfloat[cursor % g_args.prepared_rand];
} }
static char *demo_current_float_str() static char *demo_current_float_str()
{ {
static int cursor; static int cursor;
cursor++; cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0; if (cursor > (g_args.prepared_rand - 1)) cursor = 0;
return g_rand_current_buff + return g_rand_current_buff +
((cursor % MAX_PREPARED_RAND) * FLOAT_BUFF_LEN); ((cursor % g_args.prepared_rand) * FLOAT_BUFF_LEN);
} }
static float UNUSED_FUNC demo_current_float() static float UNUSED_FUNC demo_current_float()
{ {
static int cursor; static int cursor;
cursor++; cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0; if (cursor > (g_args.prepared_rand - 1)) cursor = 0;
return (float)(9.8 + 0.04 * (g_randint[cursor % MAX_PREPARED_RAND] % 10) return (float)(9.8 + 0.04 * (g_randint[cursor % g_args.prepared_rand] % 10)
+ g_randfloat[cursor % MAX_PREPARED_RAND]/1000000000); + g_randfloat[cursor % g_args.prepared_rand]/1000000000);
} }
static char *demo_voltage_int_str() static char *demo_voltage_int_str()
{ {
static int cursor; static int cursor;
cursor++; cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0; if (cursor > (g_args.prepared_rand - 1)) cursor = 0;
return g_rand_voltage_buff + return g_rand_voltage_buff +
((cursor % MAX_PREPARED_RAND) * INT_BUFF_LEN); ((cursor % g_args.prepared_rand) * INT_BUFF_LEN);
} }
static int32_t UNUSED_FUNC demo_voltage_int() static int32_t UNUSED_FUNC demo_voltage_int()
{ {
static int cursor; static int cursor;
cursor++; cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0; if (cursor > (g_args.prepared_rand - 1)) cursor = 0;
return 215 + g_randint[cursor % MAX_PREPARED_RAND] % 10; return 215 + g_randint[cursor % g_args.prepared_rand] % 10;
} }
static char *demo_phase_float_str() { static char *demo_phase_float_str() {
static int cursor; static int cursor;
cursor++; cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0; if (cursor > (g_args.prepared_rand - 1)) cursor = 0;
return g_rand_phase_buff + ((cursor % MAX_PREPARED_RAND) * FLOAT_BUFF_LEN); return g_rand_phase_buff + ((cursor % g_args.prepared_rand) * FLOAT_BUFF_LEN);
} }
static float UNUSED_FUNC demo_phase_float() { static float UNUSED_FUNC demo_phase_float() {
static int cursor; static int cursor;
cursor++; cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0; if (cursor > (g_args.prepared_rand - 1)) cursor = 0;
return (float)((115 + g_randint[cursor % MAX_PREPARED_RAND] % 10 return (float)((115 + g_randint[cursor % g_args.prepared_rand] % 10
+ g_randfloat[cursor % MAX_PREPARED_RAND]/1000000000)/360); + g_randfloat[cursor % g_args.prepared_rand]/1000000000)/360);
} }
#if 0 #if 0
...@@ -2482,7 +2479,7 @@ static char *rand_double_str() ...@@ -2482,7 +2479,7 @@ static char *rand_double_str()
{ {
static int cursor; static int cursor;
cursor++; cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0; if (cursor > (g_args.prepared_rand - 1)) cursor = 0;
return g_randdouble_buff + (cursor * DOUBLE_BUFF_LEN); return g_randdouble_buff + (cursor * DOUBLE_BUFF_LEN);
} }
...@@ -2490,42 +2487,54 @@ static double rand_double() ...@@ -2490,42 +2487,54 @@ static double rand_double()
{ {
static int cursor; static int cursor;
cursor++; cursor++;
cursor = cursor % MAX_PREPARED_RAND; cursor = cursor % g_args.prepared_rand;
return g_randdouble[cursor]; return g_randdouble[cursor];
} }
static void init_rand_data() { static void init_rand_data() {
g_randint_buff = calloc(1, INT_BUFF_LEN * MAX_PREPARED_RAND); g_randint_buff = calloc(1, INT_BUFF_LEN * g_args.prepared_rand);
assert(g_randint_buff); assert(g_randint_buff);
g_rand_voltage_buff = calloc(1, INT_BUFF_LEN * MAX_PREPARED_RAND); g_rand_voltage_buff = calloc(1, INT_BUFF_LEN * g_args.prepared_rand);
assert(g_rand_voltage_buff); assert(g_rand_voltage_buff);
g_randbigint_buff = calloc(1, BIGINT_BUFF_LEN * MAX_PREPARED_RAND); g_randbigint_buff = calloc(1, BIGINT_BUFF_LEN * g_args.prepared_rand);
assert(g_randbigint_buff); assert(g_randbigint_buff);
g_randsmallint_buff = calloc(1, SMALLINT_BUFF_LEN * MAX_PREPARED_RAND); g_randsmallint_buff = calloc(1, SMALLINT_BUFF_LEN * g_args.prepared_rand);
assert(g_randsmallint_buff); assert(g_randsmallint_buff);
g_randtinyint_buff = calloc(1, TINYINT_BUFF_LEN * MAX_PREPARED_RAND); g_randtinyint_buff = calloc(1, TINYINT_BUFF_LEN * g_args.prepared_rand);
assert(g_randtinyint_buff); assert(g_randtinyint_buff);
g_randbool_buff = calloc(1, BOOL_BUFF_LEN * MAX_PREPARED_RAND); g_randbool_buff = calloc(1, BOOL_BUFF_LEN * g_args.prepared_rand);
assert(g_randbool_buff); assert(g_randbool_buff);
g_randfloat_buff = calloc(1, FLOAT_BUFF_LEN * MAX_PREPARED_RAND); g_randfloat_buff = calloc(1, FLOAT_BUFF_LEN * g_args.prepared_rand);
assert(g_randfloat_buff); assert(g_randfloat_buff);
g_rand_current_buff = calloc(1, FLOAT_BUFF_LEN * MAX_PREPARED_RAND); g_rand_current_buff = calloc(1, FLOAT_BUFF_LEN * g_args.prepared_rand);
assert(g_rand_current_buff); assert(g_rand_current_buff);
g_rand_phase_buff = calloc(1, FLOAT_BUFF_LEN * MAX_PREPARED_RAND); g_rand_phase_buff = calloc(1, FLOAT_BUFF_LEN * g_args.prepared_rand);
assert(g_rand_phase_buff); assert(g_rand_phase_buff);
g_randdouble_buff = calloc(1, DOUBLE_BUFF_LEN * MAX_PREPARED_RAND); g_randdouble_buff = calloc(1, DOUBLE_BUFF_LEN * g_args.prepared_rand);
assert(g_randdouble_buff); assert(g_randdouble_buff);
g_randuint_buff = calloc(1, INT_BUFF_LEN * MAX_PREPARED_RAND); g_randuint_buff = calloc(1, INT_BUFF_LEN * g_args.prepared_rand);
assert(g_randuint_buff); assert(g_randuint_buff);
g_randutinyint_buff = calloc(1, TINYINT_BUFF_LEN * MAX_PREPARED_RAND); g_randutinyint_buff = calloc(1, TINYINT_BUFF_LEN * g_args.prepared_rand);
assert(g_randutinyint_buff); assert(g_randutinyint_buff);
g_randusmallint_buff = calloc(1, SMALLINT_BUFF_LEN * MAX_PREPARED_RAND); g_randusmallint_buff = calloc(1, SMALLINT_BUFF_LEN * g_args.prepared_rand);
assert(g_randusmallint_buff); assert(g_randusmallint_buff);
g_randubigint_buff = calloc(1, BIGINT_BUFF_LEN * MAX_PREPARED_RAND); g_randubigint_buff = calloc(1, BIGINT_BUFF_LEN * g_args.prepared_rand);
assert(g_randubigint_buff); assert(g_randubigint_buff);
g_randint = calloc(1, sizeof(int32_t) * g_args.prepared_rand);
for (int i = 0; i < MAX_PREPARED_RAND; i++) { assert(g_randint);
g_randuint = calloc(1, sizeof(uint32_t) * g_args.prepared_rand);
assert(g_randuint);
g_randbigint = calloc(1, sizeof(int64_t) * g_args.prepared_rand);
assert(g_randbigint);
g_randubigint = calloc(1, sizeof(uint64_t) * g_args.prepared_rand);
assert(g_randubigint);
g_randfloat = calloc(1, sizeof(float) * g_args.prepared_rand);
assert(g_randfloat);
g_randdouble = calloc(1, sizeof(double) * g_args.prepared_rand);
assert(g_randdouble);
for (int i = 0; i < g_args.prepared_rand; i++) {
g_randint[i] = (int)(taosRandom() % RAND_MAX - (RAND_MAX >> 1)); g_randint[i] = (int)(taosRandom() % RAND_MAX - (RAND_MAX >> 1));
g_randuint[i] = (int)(taosRandom()); g_randuint[i] = (int)(taosRandom());
sprintf(g_randint_buff + i * INT_BUFF_LEN, "%d", sprintf(g_randint_buff + i * INT_BUFF_LEN, "%d",
...@@ -3783,7 +3792,7 @@ static int calcRowLen(SSuperTable* superTbls) { ...@@ -3783,7 +3792,7 @@ static int calcRowLen(SSuperTable* superTbls) {
static int getChildNameOfSuperTableWithLimitAndOffset(TAOS * taos, static int getChildNameOfSuperTableWithLimitAndOffset(TAOS * taos,
char* dbName, char* stbName, char** childTblNameOfSuperTbl, char* dbName, char* stbName, char** childTblNameOfSuperTbl,
int64_t* childTblCountOfSuperTbl, int64_t limit, uint64_t offset) { int64_t* childTblCountOfSuperTbl, int64_t limit, uint64_t offset, bool escapChar) {
char command[1024] = "\0"; char command[1024] = "\0";
char limitBuf[100] = "\0"; char limitBuf[100] = "\0";
...@@ -3797,8 +3806,8 @@ static int getChildNameOfSuperTableWithLimitAndOffset(TAOS * taos, ...@@ -3797,8 +3806,8 @@ static int getChildNameOfSuperTableWithLimitAndOffset(TAOS * taos,
limit, offset); limit, offset);
//get all child table name use cmd: select tbname from superTblName; //get all child table name use cmd: select tbname from superTblName;
snprintf(command, 1024, "select tbname from %s.%s %s", snprintf(command, 1024, escapChar ? "select tbname from %s.`%s` %s" :
dbName, stbName, limitBuf); "select tbname from %s.%s %s", dbName, stbName, limitBuf);
res = taos_query(taos, command); res = taos_query(taos, command);
int32_t code = taos_errno(res); int32_t code = taos_errno(res);
...@@ -3869,7 +3878,7 @@ static int getAllChildNameOfSuperTable(TAOS * taos, char* dbName, ...@@ -3869,7 +3878,7 @@ static int getAllChildNameOfSuperTable(TAOS * taos, char* dbName,
return getChildNameOfSuperTableWithLimitAndOffset(taos, dbName, stbName, return getChildNameOfSuperTableWithLimitAndOffset(taos, dbName, stbName,
childTblNameOfSuperTbl, childTblCountOfSuperTbl, childTblNameOfSuperTbl, childTblCountOfSuperTbl,
-1, 0); -1, 0, false);
} }
static int getSuperTableFromServer(TAOS * taos, char* dbName, static int getSuperTableFromServer(TAOS * taos, char* dbName,
...@@ -4326,9 +4335,12 @@ static int createSuperTable( ...@@ -4326,9 +4335,12 @@ static int createSuperTable(
superTbl->lenOfTagOfOneRow = lenOfTagOfOneRow; superTbl->lenOfTagOfOneRow = lenOfTagOfOneRow;
snprintf(command, BUFFER_SIZE, snprintf(command, BUFFER_SIZE,
"CREATE TABLE IF NOT EXISTS %s.%s (ts TIMESTAMP%s) TAGS %s", superTbl->escapeChar ?
dbName, superTbl->stbName, cols, tags); "CREATE TABLE IF NOT EXISTS %s.`%s` (ts TIMESTAMP%s) TAGS %s":
"CREATE TABLE IF NOT EXISTS %s.%s (ts TIMESTAMP%s) TAGS %s",
dbName, superTbl->stbName, cols, tags);
if (0 != queryDbExec(taos, command, NO_INSERT_TYPE, false)) { if (0 != queryDbExec(taos, command, NO_INSERT_TYPE, false)) {
errorPrint2("create supertable %s failed!\n\n", errorPrint2("create supertable %s failed!\n\n",
superTbl->stbName); superTbl->stbName);
...@@ -5268,6 +5280,22 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -5268,6 +5280,22 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
goto PARSE_OVER; goto PARSE_OVER;
} }
cJSON* prepareRand = cJSON_GetObjectItem(root, "prepared_rand");
if (prepareRand && prepareRand->type == cJSON_Number) {
if (prepareRand->valueint <= 0) {
errorPrint("%s() LN%d, failed to read json, prepared_rand input mistake\n",
__func__, __LINE__);
goto PARSE_OVER;
}
g_args.prepared_rand = prepareRand->valueint;
} else if (!prepareRand) {
g_args.prepared_rand = 10000;
} else {
errorPrint("%s() LN%d, failed to read json, prepared_rand not found\n",
__func__, __LINE__);
goto PARSE_OVER;
}
cJSON *answerPrompt = cJSON_GetObjectItem(root, "confirm_parameter_prompt"); // yes, no, cJSON *answerPrompt = cJSON_GetObjectItem(root, "confirm_parameter_prompt"); // yes, no,
if (answerPrompt if (answerPrompt
&& answerPrompt->type == cJSON_String && answerPrompt->type == cJSON_String
...@@ -5309,7 +5337,8 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -5309,7 +5337,8 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
MAX_DB_COUNT); MAX_DB_COUNT);
goto PARSE_OVER; goto PARSE_OVER;
} }
g_Dbs.db = calloc(1, sizeof(SDataBase)*dbSize);
assert(g_Dbs.db);
g_Dbs.dbCount = dbSize; g_Dbs.dbCount = dbSize;
for (int i = 0; i < dbSize; ++i) { for (int i = 0; i < dbSize; ++i) {
cJSON* dbinfos = cJSON_GetArrayItem(dbs, i); cJSON* dbinfos = cJSON_GetArrayItem(dbs, i);
...@@ -5509,7 +5538,8 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -5509,7 +5538,8 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
MAX_SUPER_TABLE_COUNT); MAX_SUPER_TABLE_COUNT);
goto PARSE_OVER; goto PARSE_OVER;
} }
g_Dbs.db[i].superTbls = calloc(1, stbSize * sizeof(SSuperTable));
assert(g_Dbs.db[i].superTbls);
g_Dbs.db[i].superTblCount = stbSize; g_Dbs.db[i].superTblCount = stbSize;
for (int j = 0; j < stbSize; ++j) { for (int j = 0; j < stbSize; ++j) {
cJSON* stbInfo = cJSON_GetArrayItem(stables, j); cJSON* stbInfo = cJSON_GetArrayItem(stables, j);
...@@ -6400,9 +6430,12 @@ static bool getInfoFromJsonFile(char* file) { ...@@ -6400,9 +6430,12 @@ static bool getInfoFromJsonFile(char* file) {
} }
if (INSERT_TEST == g_args.test_mode) { if (INSERT_TEST == g_args.test_mode) {
memset(&g_Dbs, 0, sizeof(SDbs));
g_Dbs.use_metric = g_args.use_metric;
ret = getMetaFromInsertJsonFile(root); ret = getMetaFromInsertJsonFile(root);
} else if ((QUERY_TEST == g_args.test_mode) } else if ((QUERY_TEST == g_args.test_mode)
|| (SUBSCRIBE_TEST == g_args.test_mode)) { || (SUBSCRIBE_TEST == g_args.test_mode)) {
memset(&g_queryInfo, 0, sizeof(SQueryMetaInfo));
ret = getMetaFromQueryJsonFile(root); ret = getMetaFromQueryJsonFile(root);
} else { } else {
errorPrint("%s", errorPrint("%s",
...@@ -6467,8 +6500,9 @@ static void postFreeResource() { ...@@ -6467,8 +6500,9 @@ static void postFreeResource() {
g_Dbs.db[i].superTbls[j].childTblName = NULL; g_Dbs.db[i].superTbls[j].childTblName = NULL;
} }
} }
tmfree(g_Dbs.db[i].superTbls);
} }
tmfree(g_Dbs.db);
tmfree(g_randbool_buff); tmfree(g_randbool_buff);
tmfree(g_randint_buff); tmfree(g_randint_buff);
tmfree(g_rand_voltage_buff); tmfree(g_rand_voltage_buff);
...@@ -6491,6 +6525,7 @@ static void postFreeResource() { ...@@ -6491,6 +6525,7 @@ static void postFreeResource() {
} }
} }
tmfree(g_sampleBindBatchArray); tmfree(g_sampleBindBatchArray);
#endif #endif
} }
...@@ -10370,7 +10405,7 @@ static void startMultiThreadInsertData(int threads, char* db_name, ...@@ -10370,7 +10405,7 @@ static void startMultiThreadInsertData(int threads, char* db_name,
db_name, stbInfo->stbName, db_name, stbInfo->stbName,
&stbInfo->childTblName, &childTblCount, &stbInfo->childTblName, &childTblCount,
limit, limit,
offset); offset, stbInfo->escapeChar);
ntables = childTblCount; ntables = childTblCount;
} else { } else {
ntables = g_args.ntables; ntables = g_args.ntables;
...@@ -11920,29 +11955,6 @@ static int subscribeTestProcess() { ...@@ -11920,29 +11955,6 @@ static int subscribeTestProcess() {
return 0; return 0;
} }
static void initOfInsertMeta() {
memset(&g_Dbs, 0, sizeof(SDbs));
// set default values
tstrncpy(g_Dbs.host, "127.0.0.1", MAX_HOSTNAME_SIZE);
g_Dbs.port = 6030;
tstrncpy(g_Dbs.user, TSDB_DEFAULT_USER, MAX_USERNAME_SIZE);
tstrncpy(g_Dbs.password, TSDB_DEFAULT_PASS, SHELL_MAX_PASSWORD_LEN);
g_Dbs.threadCount = 2;
g_Dbs.use_metric = g_args.use_metric;
}
static void initOfQueryMeta() {
memset(&g_queryInfo, 0, sizeof(SQueryMetaInfo));
// set default values
tstrncpy(g_queryInfo.host, "127.0.0.1", MAX_HOSTNAME_SIZE);
g_queryInfo.port = 6030;
tstrncpy(g_queryInfo.user, TSDB_DEFAULT_USER, MAX_USERNAME_SIZE);
tstrncpy(g_queryInfo.password, TSDB_DEFAULT_PASS, SHELL_MAX_PASSWORD_LEN);
}
static void setParaFromArg() { static void setParaFromArg() {
char type[20]; char type[20];
char length[20]; char length[20];
...@@ -11975,7 +11987,7 @@ static void setParaFromArg() { ...@@ -11975,7 +11987,7 @@ static void setParaFromArg() {
tstrncpy(g_Dbs.resultFile, g_args.output_file, MAX_FILE_NAME_LEN); tstrncpy(g_Dbs.resultFile, g_args.output_file, MAX_FILE_NAME_LEN);
g_Dbs.use_metric = g_args.use_metric; g_Dbs.use_metric = g_args.use_metric;
g_args.prepared_rand = min(g_args.insertRows, MAX_PREPARED_RAND);
g_Dbs.aggr_func = g_args.aggr_func; g_Dbs.aggr_func = g_args.aggr_func;
char dataString[TSDB_MAX_BYTES_PER_ROW]; char dataString[TSDB_MAX_BYTES_PER_ROW];
...@@ -12252,8 +12264,6 @@ int main(int argc, char *argv[]) { ...@@ -12252,8 +12264,6 @@ int main(int argc, char *argv[]) {
if (g_args.metaFile) { if (g_args.metaFile) {
g_totalChildTables = 0; g_totalChildTables = 0;
initOfInsertMeta();
initOfQueryMeta();
if (false == getInfoFromJsonFile(g_args.metaFile)) { if (false == getInfoFromJsonFile(g_args.metaFile)) {
printf("Failed to read %s\n", g_args.metaFile); printf("Failed to read %s\n", g_args.metaFile);
...@@ -12263,6 +12273,10 @@ int main(int argc, char *argv[]) { ...@@ -12263,6 +12273,10 @@ int main(int argc, char *argv[]) {
testMetaFile(); testMetaFile();
} else { } else {
memset(&g_Dbs, 0, sizeof(SDbs)); memset(&g_Dbs, 0, sizeof(SDbs));
g_Dbs.db = calloc(1, sizeof(SDataBase));
assert(g_Dbs.db);
g_Dbs.db[0].superTbls = calloc(1, sizeof(SSuperTable));
assert(g_Dbs.db[0].superTbls);
setParaFromArg(); setParaFromArg();
if (NULL != g_args.sqlFile) { if (NULL != g_args.sqlFile) {
......
...@@ -638,11 +638,6 @@ static int queryDbImpl(TAOS *taos, char *command) { ...@@ -638,11 +638,6 @@ static int queryDbImpl(TAOS *taos, char *command) {
TAOS_RES *res = NULL; TAOS_RES *res = NULL;
int32_t code = -1; int32_t code = -1;
if (NULL != res) {
taos_free_result(res);
res = NULL;
}
res = taos_query(taos, command); res = taos_query(taos, command);
code = taos_errno(res); code = taos_errno(res);
...@@ -1193,6 +1188,7 @@ static int64_t dumpNormalTable( ...@@ -1193,6 +1188,7 @@ static int64_t dumpNormalTable(
jsonAvroSchema); jsonAvroSchema);
} }
tfree(jsonAvroSchema);
freeTbDes(tableDes); freeTbDes(tableDes);
return ret; return ret;
} }
......
...@@ -204,6 +204,7 @@ static void monBuildMonitorSql(char *sql, int32_t cmd) { ...@@ -204,6 +204,7 @@ static void monBuildMonitorSql(char *sql, int32_t cmd) {
", disk_used float, disk_total int" ", disk_used float, disk_total int"
", band_speed float" ", band_speed float"
", io_read float, io_write float" ", io_read float, io_write float"
", io_read_rate float, io_write_rate float"
", req_http int, req_select int, req_insert int" ", req_http int, req_select int, req_insert int"
") tags (dnodeid int, fqdn binary(%d))", ") tags (dnodeid int, fqdn binary(%d))",
tsMonitorDbName, TSDB_FQDN_LEN); tsMonitorDbName, TSDB_FQDN_LEN);
...@@ -325,7 +326,10 @@ static int32_t monBuildIoSql(char *sql) { ...@@ -325,7 +326,10 @@ static int32_t monBuildIoSql(char *sql) {
monDebug("failed to get io info"); monDebug("failed to get io info");
} }
return sprintf(sql, ", %f, %f", readKB, writeKB); float readRate = readKB/tsMonitorInterval;
float writeRate = writeKB/tsMonitorInterval;
return sprintf(sql, ", %f, %f, %f, %f", readKB, writeKB, readRate, writeRate);
} }
static void monSaveSystemInfo() { static void monSaveSystemInfo() {
......
...@@ -365,7 +365,8 @@ int32_t getNumOfResult(SQueryRuntimeEnv *pRuntimeEnv, SQLFunctionCtx* pCtx, int3 ...@@ -365,7 +365,8 @@ int32_t getNumOfResult(SQueryRuntimeEnv *pRuntimeEnv, SQLFunctionCtx* pCtx, int3
* ts, tag, tagprj function can not decide the output number of current query * ts, tag, tagprj function can not decide the output number of current query
* the number of output result is decided by main output * the number of output result is decided by main output
*/ */
if (hasMainFunction && (id == TSDB_FUNC_TS || id == TSDB_FUNC_TAG || id == TSDB_FUNC_TAGPRJ)) { if (hasMainFunction && (id == TSDB_FUNC_TS || id == TSDB_FUNC_TAG || id == TSDB_FUNC_TAGPRJ ||
id == TSDB_FUNC_TS_DUMMY || id == TSDB_FUNC_TAG_DUMMY)) {
continue; continue;
} }
......
...@@ -29,7 +29,3 @@ clean: ...@@ -29,7 +29,3 @@ clean:
rm $(ROOT)stream rm $(ROOT)stream
rm $(ROOT)subscribe rm $(ROOT)subscribe
rm $(ROOT)apitest rm $(ROOT)apitest
...@@ -184,6 +184,10 @@ void verify_prepare(TAOS* taos) { ...@@ -184,6 +184,10 @@ void verify_prepare(TAOS* taos) {
taos_stmt_close(stmt); taos_stmt_close(stmt);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
int affectedRows = taos_stmt_affected_rows(stmt);
printf("sucessfully inserted %d rows\n", affectedRows);
taos_stmt_close(stmt); taos_stmt_close(stmt);
// query the records // query the records
...@@ -400,6 +404,9 @@ void verify_prepare2(TAOS* taos) { ...@@ -400,6 +404,9 @@ void verify_prepare2(TAOS* taos) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
int affectedRows = taos_stmt_affected_rows(stmt);
printf("sucessfully inserted %d rows\n", affectedRows);
taos_stmt_close(stmt); taos_stmt_close(stmt);
// query the records // query the records
...@@ -784,6 +791,10 @@ void verify_prepare3(TAOS* taos) { ...@@ -784,6 +791,10 @@ void verify_prepare3(TAOS* taos) {
taos_stmt_close(stmt); taos_stmt_close(stmt);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
int affectedRows = taos_stmt_affected_rows(stmt);
printf("successfully inserted %d rows\n", affectedRows);
taos_stmt_close(stmt); taos_stmt_close(stmt);
// query the records // query the records
......
...@@ -29,7 +29,6 @@ class TDTestCase: ...@@ -29,7 +29,6 @@ class TDTestCase:
tdSql.execute("create database if not exists test precision 'us'") tdSql.execute("create database if not exists test precision 'us'")
tdSql.execute('use test') tdSql.execute('use test')
### metric ### ### metric ###
print("============= step1 : test metric ================") print("============= step1 : test metric ================")
lines0 = [ lines0 = [
...@@ -215,7 +214,7 @@ class TDTestCase: ...@@ -215,7 +214,7 @@ class TDTestCase:
#binary #binary
lines2_7 = [ lines2_7 = [
"stb2_7 1626006833610ms \"binary_val.!@#$%^&*\" host=\"host0\"", "stb2_7 1626006833610ms \" binary_val .!@#$%^&* \" host=\"host0\"",
"stb2_7 1626006833620ms \"binary_val.:;,./?|+-=\" host=\"host0\"", "stb2_7 1626006833620ms \"binary_val.:;,./?|+-=\" host=\"host0\"",
"stb2_7 1626006833630ms \"binary_val.()[]{}<>\" host=\"host0\"" "stb2_7 1626006833630ms \"binary_val.()[]{}<>\" host=\"host0\""
] ]
...@@ -232,7 +231,7 @@ class TDTestCase: ...@@ -232,7 +231,7 @@ class TDTestCase:
#nchar #nchar
lines2_8 = [ lines2_8 = [
"stb2_8 1626006833610ms L\"nchar_val数值一\" host=\"host0\"", "stb2_8 1626006833610ms L\" nchar_val 数值一 \" host=\"host0\"",
"stb2_8 1626006833620ms L\"nchar_val数值二\" host=\"host0\"" "stb2_8 1626006833620ms L\"nchar_val数值二\" host=\"host0\""
] ]
......
...@@ -31,9 +31,9 @@ class TDTestCase: ...@@ -31,9 +31,9 @@ class TDTestCase:
tdSql.execute('create stable ste(ts timestamp, f int) tags(t1 bigint)') tdSql.execute('create stable ste(ts timestamp, f int) tags(t1 bigint)')
lines = [ "st,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000", lines = [ "st,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"\"\"a pa,\"s si,t \"\"\",c2=false,c4=4f64 1626006833639000000",
"st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000", "st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000",
"ste,t2=5f64,t3=L\"ste\" c1=true,c2=4i64,c3=\"iam\" 1626056811823316532", "ste,t2=5f64,t3=L\"ste\" c1=true,c2=4i64,c3=\" i,\"a \"m,\"\"\" 1626056811823316532",
"stf,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64,c6=7u64 1626006933640000000", "stf,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64,c6=7u64 1626006933640000000",
"st,t1=4i64,t2=5f64,t3=\"t4\" c1=3i64,c3=L\"passitagain\",c2=true,c4=5f64 1626006833642000000", "st,t1=4i64,t2=5f64,t3=\"t4\" c1=3i64,c3=L\"passitagain\",c2=true,c4=5f64 1626006833642000000",
"ste,t2=5f64,t3=L\"ste2\" c3=\"iamszhou\",c4=false 1626056811843316532", "ste,t2=5f64,t3=L\"ste2\" c3=\"iamszhou\",c4=false 1626056811843316532",
......
...@@ -119,7 +119,11 @@ int stmt_scol_func1(TAOS_STMT *stmt) { ...@@ -119,7 +119,11 @@ int stmt_scol_func1(TAOS_STMT *stmt) {
printf("failed to execute insert statement.\n"); printf("failed to execute insert statement.\n");
exit(1); exit(1);
} }
int affectedRows = taos_stmt_affected_rows(stmt);
if (affectedRows != 100) {
printf("failed to insert 100 rows");
}
return 0; return 0;
} }
......
...@@ -46,6 +46,7 @@ void taos_stmt_init_test() { ...@@ -46,6 +46,7 @@ void taos_stmt_init_test() {
} }
stmt = taos_stmt_init(taos); stmt = taos_stmt_init(taos);
assert(stmt != NULL); assert(stmt != NULL);
assert(taos_stmt_affected_rows(stmt) == 0);
assert(taos_stmt_close(stmt) == 0); assert(taos_stmt_close(stmt) == 0);
printf("finish taos_stmt_init test\n"); printf("finish taos_stmt_init test\n");
} }
...@@ -127,6 +128,7 @@ void taos_stmt_set_tbname_test() { ...@@ -127,6 +128,7 @@ void taos_stmt_set_tbname_test() {
assert(taos_stmt_set_tbname(stmt, name) == 0); assert(taos_stmt_set_tbname(stmt, name) == 0);
free(name); free(name);
free(stmt_sql); free(stmt_sql);
assert(taos_stmt_affected_rows(stmt) == 0);
taos_stmt_close(stmt); taos_stmt_close(stmt);
printf("finish taos_stmt_set_tbname test\n"); printf("finish taos_stmt_set_tbname test\n");
} }
...@@ -166,6 +168,7 @@ void taos_stmt_set_tbname_tags_test() { ...@@ -166,6 +168,7 @@ void taos_stmt_set_tbname_tags_test() {
free(stmt_sql); free(stmt_sql);
free(name); free(name);
free(tags); free(tags);
assert(taos_stmt_affected_rows(stmt) == 0);
taos_stmt_close(stmt); taos_stmt_close(stmt);
printf("finish taos_stmt_set_tbname_tags test\n"); printf("finish taos_stmt_set_tbname_tags test\n");
} }
...@@ -194,8 +197,10 @@ void taos_stmt_set_sub_tbname_test() { ...@@ -194,8 +197,10 @@ void taos_stmt_set_sub_tbname_test() {
assert(taos_stmt_set_sub_tbname(stmt, name) != 0); assert(taos_stmt_set_sub_tbname(stmt, name) != 0);
sprintf(name, "tb"); sprintf(name, "tb");
assert(taos_stmt_set_sub_tbname(stmt, name) == 0); assert(taos_stmt_set_sub_tbname(stmt, name) == 0);
assert(taos_stmt_affected_rows(stmt) == 0);
assert(taos_load_table_info(taos, "super, tb") == 0); assert(taos_load_table_info(taos, "super, tb") == 0);
assert(taos_stmt_set_sub_tbname(stmt, name) == 0); assert(taos_stmt_set_sub_tbname(stmt, name) == 0);
assert(taos_stmt_affected_rows(stmt) == 0);
free(name); free(name);
free(stmt_sql); free(stmt_sql);
assert(taos_stmt_close(stmt) == 0); assert(taos_stmt_close(stmt) == 0);
...@@ -238,6 +243,7 @@ void taos_stmt_bind_param_test() { ...@@ -238,6 +243,7 @@ void taos_stmt_bind_param_test() {
assert(taos_stmt_bind_param(stmt, params) != 0); assert(taos_stmt_bind_param(stmt, params) != 0);
assert(taos_stmt_set_tbname(stmt, "super") == 0); assert(taos_stmt_set_tbname(stmt, "super") == 0);
assert(taos_stmt_bind_param(stmt, params) == 0); assert(taos_stmt_bind_param(stmt, params) == 0);
assert(taos_stmt_affected_rows(stmt) == 0);
free(params); free(params);
free(stmt_sql); free(stmt_sql);
taos_stmt_close(stmt); taos_stmt_close(stmt);
...@@ -249,6 +255,7 @@ void taos_stmt_bind_single_param_batch_test() { ...@@ -249,6 +255,7 @@ void taos_stmt_bind_single_param_batch_test() {
TAOS_STMT * stmt = NULL; TAOS_STMT * stmt = NULL;
TAOS_MULTI_BIND *bind = NULL; TAOS_MULTI_BIND *bind = NULL;
assert(taos_stmt_bind_single_param_batch(stmt, bind, 0) != 0); assert(taos_stmt_bind_single_param_batch(stmt, bind, 0) != 0);
assert(taos_stmt_affected_rows(stmt) == 0);
printf("finish taos_stmt_bind_single_param_batch test\n"); printf("finish taos_stmt_bind_single_param_batch test\n");
} }
...@@ -257,6 +264,7 @@ void taos_stmt_bind_param_batch_test() { ...@@ -257,6 +264,7 @@ void taos_stmt_bind_param_batch_test() {
TAOS_STMT * stmt = NULL; TAOS_STMT * stmt = NULL;
TAOS_MULTI_BIND *bind = NULL; TAOS_MULTI_BIND *bind = NULL;
assert(taos_stmt_bind_param_batch(stmt, bind) != 0); assert(taos_stmt_bind_param_batch(stmt, bind) != 0);
assert(taos_stmt_affected_rows(stmt) == 0);
printf("finish taos_stmt_bind_param_batch test\n"); printf("finish taos_stmt_bind_param_batch test\n");
} }
...@@ -293,10 +301,14 @@ void taos_stmt_add_batch_test() { ...@@ -293,10 +301,14 @@ void taos_stmt_add_batch_test() {
params[1].length = &params[1].buffer_length; params[1].length = &params[1].buffer_length;
params[1].is_null = NULL; params[1].is_null = NULL;
assert(taos_stmt_set_tbname(stmt, "super") == 0); assert(taos_stmt_set_tbname(stmt, "super") == 0);
assert(taos_stmt_affected_rows(stmt) == 0);
assert(taos_stmt_bind_param(stmt, params) == 0); assert(taos_stmt_bind_param(stmt, params) == 0);
assert(taos_stmt_affected_rows(stmt) == 0);
assert(taos_stmt_add_batch(stmt) == 0); assert(taos_stmt_add_batch(stmt) == 0);
assert(taos_stmt_affected_rows(stmt) == 0);
free(params); free(params);
free(stmt_sql); free(stmt_sql);
assert(taos_stmt_affected_rows(stmt) == 0);
assert(taos_stmt_close(stmt) == 0); assert(taos_stmt_close(stmt) == 0);
printf("finish taos_stmt_add_batch test\n"); printf("finish taos_stmt_add_batch test\n");
} }
...@@ -317,10 +329,13 @@ void taos_stmt_execute_test() { ...@@ -317,10 +329,13 @@ void taos_stmt_execute_test() {
stmt = taos_stmt_init(taos); stmt = taos_stmt_init(taos);
assert(stmt != NULL); assert(stmt != NULL);
assert(taos_stmt_execute(stmt) != 0); assert(taos_stmt_execute(stmt) != 0);
assert(taos_stmt_affected_rows(stmt) == 0);
char *stmt_sql = calloc(1, 1000); char *stmt_sql = calloc(1, 1000);
sprintf(stmt_sql, "insert into ? values (?,?)"); sprintf(stmt_sql, "insert into ? values (?,?)");
assert(taos_stmt_prepare(stmt, stmt_sql, 0) == 0); assert(taos_stmt_prepare(stmt, stmt_sql, 0) == 0);
assert(taos_stmt_affected_rows(stmt) == 0);
assert(taos_stmt_execute(stmt) != 0); assert(taos_stmt_execute(stmt) != 0);
assert(taos_stmt_affected_rows(stmt) == 0);
TAOS_BIND *params = calloc(2, sizeof(TAOS_BIND)); TAOS_BIND *params = calloc(2, sizeof(TAOS_BIND));
int64_t ts = (int64_t)1591060628000; int64_t ts = (int64_t)1591060628000;
params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
...@@ -335,11 +350,17 @@ void taos_stmt_execute_test() { ...@@ -335,11 +350,17 @@ void taos_stmt_execute_test() {
params[1].length = &params[1].buffer_length; params[1].length = &params[1].buffer_length;
params[1].is_null = NULL; params[1].is_null = NULL;
assert(taos_stmt_set_tbname(stmt, "super") == 0); assert(taos_stmt_set_tbname(stmt, "super") == 0);
assert(taos_stmt_affected_rows(stmt) == 0);
assert(taos_stmt_execute(stmt) != 0); assert(taos_stmt_execute(stmt) != 0);
assert(taos_stmt_affected_rows(stmt) == 0);
assert(taos_stmt_bind_param(stmt, params) == 0); assert(taos_stmt_bind_param(stmt, params) == 0);
assert(taos_stmt_affected_rows(stmt) == 0);
assert(taos_stmt_execute(stmt) != 0); assert(taos_stmt_execute(stmt) != 0);
assert(taos_stmt_affected_rows(stmt) == 0);
assert(taos_stmt_add_batch(stmt) == 0); assert(taos_stmt_add_batch(stmt) == 0);
assert(taos_stmt_affected_rows(stmt) == 0);
assert(taos_stmt_execute(stmt) == 0); assert(taos_stmt_execute(stmt) == 0);
assert(taos_stmt_affected_rows(stmt) == 1);
free(params); free(params);
free(stmt_sql); free(stmt_sql);
assert(taos_stmt_close(stmt) == 0); assert(taos_stmt_close(stmt) == 0);
...@@ -542,4 +563,4 @@ int main(int argc, char *argv[]) { ...@@ -542,4 +563,4 @@ int main(int argc, char *argv[]) {
test_api_reliability(); test_api_reliability();
test_query(); test_query();
return 0; return 0;
} }
\ No newline at end of file
...@@ -229,6 +229,14 @@ int main(int argc, char *argv[]) { ...@@ -229,6 +229,14 @@ int main(int argc, char *argv[]) {
PRINT_SUCCESS PRINT_SUCCESS
printf("Successfully execute insert statement.\n"); printf("Successfully execute insert statement.\n");
int affectedRows = taos_stmt_affected_rows(stmt);
printf("Successfully inserted %d rows\n", affectedRows);
if (affectedRows != 10) {
PRINT_ERROR
printf("failed to insert 10 rows\n");
exit(EXIT_FAILURE);
}
taos_stmt_close(stmt); taos_stmt_close(stmt);
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
check_result(taos, i, 1); check_result(taos, i, 1);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册