diff --git a/src/client/inc/tscParseLine.h b/src/client/inc/tscParseLine.h index 52697298896d18a85fef23f1a142ad13df83aabc..d77185233c71d86ddc54443d6504b25d0768d846 100644 --- a/src/client/inc/tscParseLine.h +++ b/src/client/inc/tscParseLine.h @@ -64,6 +64,8 @@ typedef struct { SMLProtocolType protocol; SMLTimeStampType tsType; SHashObj* smlDataToSchema; + + int64_t affectedRows; } SSmlLinesInfo; int tscSmlInsert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint, SSmlLinesInfo* info); diff --git a/src/client/src/tscParseLineProtocol.c b/src/client/src/tscParseLineProtocol.c index a0cb3d2b1c76f98862d0fa7675bde1be17bcdd05..238647eb4357c6a416e020863b799887db69e5c3 100644 --- a/src/client/src/tscParseLineProtocol.c +++ b/src/client/src/tscParseLineProtocol.c @@ -784,7 +784,7 @@ static int32_t insertChildTableBatch(TAOS* taos, char* cTableName, SArray* cols tfree(sql); 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); return code; } @@ -794,7 +794,11 @@ static int32_t insertChildTableBatch(TAOS* taos, char* cTableName, SArray* cols do { code = taos_stmt_set_tbname(stmt, cTableName); 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); return code; } @@ -804,13 +808,21 @@ static int32_t insertChildTableBatch(TAOS* taos, char* cTableName, SArray* cols TAOS_BIND* colsBinds = taosArrayGetP(rowsBind, i); code = taos_stmt_bind_param(stmt, colsBinds); 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); return code; } code = taos_stmt_add_batch(stmt); 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); return code; } @@ -818,9 +830,10 @@ static int32_t insertChildTableBatch(TAOS* taos, char* cTableName, SArray* cols code = taos_stmt_execute(stmt); 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; if ((code == TSDB_CODE_TDB_INVALID_TABLE_ID || code == TSDB_CODE_VND_INVALID_VGROUP_ID @@ -848,6 +861,8 @@ static int32_t insertChildTableBatch(TAOS* taos, char* cTableName, SArray* cols } } while (tryAgain); + int affectedRows = taos_stmt_affected_rows(stmt); + info->affectedRows += affectedRows; taos_stmt_close(stmt); return code; @@ -1048,6 +1063,7 @@ int tscSmlInsert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint, SSmlLine int32_t code = TSDB_CODE_SUCCESS; info->smlDataToSchema = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), true, false); + info->affectedRows = 0; tscDebug("SML:0x%"PRIx64" build data point schemas", info->id); SArray* stableSchemas = taosArrayInit(32, sizeof(SSmlSTableSchema)); // SArray diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 38e90f5ac6a7b78e244dbe45cd1626d5a68d7f1b..83805744cfc5ae4f35387e52a449ff5ce26f2cf6 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -1972,6 +1972,17 @@ int taos_stmt_execute(TAOS_STMT* stmt) { STMT_RET(ret); } +int taos_stmt_affected_rows(TAOS_STMT* stmt) { + STscStmt* pStmt = (STscStmt*)stmt; + + if (pStmt == NULL || pStmt->pSql == NULL || pStmt->pSql->signature != pStmt->pSql) { + tscError("statement is invalid"); + return 0; + } + + return pStmt->pSql->res.numOfRows; +} + TAOS_RES *taos_stmt_use_result(TAOS_STMT* stmt) { if (stmt == NULL) { tscError("statement is invalid."); diff --git a/src/inc/taos.h b/src/inc/taos.h index 4a7f3ae99b7c543a1dd6d20d66eeb3b2a69f38ce..da91ed16c8186d15e109aaf03b18c6ca4ce86837 100644 --- a/src/inc/taos.h +++ b/src/inc/taos.h @@ -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_add_batch(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 int taos_stmt_close(TAOS_STMT *stmt); DLL_EXPORT char * taos_stmt_errstr(TAOS_STMT *stmt);