未验证 提交 385f9fd8 编写于 作者: D dapan1121 提交者: GitHub

Merge pull request #7663 from taosdata/test/TD-6167

Test/td 6167 fix stmt error
...@@ -1522,6 +1522,7 @@ TAOS_STMT* taos_stmt_init(TAOS* taos) { ...@@ -1522,6 +1522,7 @@ TAOS_STMT* taos_stmt_init(TAOS* taos) {
pSql->isBind = true; pSql->isBind = true;
pStmt->pSql = pSql; pStmt->pSql = pSql;
pStmt->last = STMT_INIT; pStmt->last = STMT_INIT;
registerSqlObj(pSql);
return pStmt; return pStmt;
} }
...@@ -1783,7 +1784,9 @@ int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name) { ...@@ -1783,7 +1784,9 @@ int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name) {
int taos_stmt_close(TAOS_STMT* stmt) { int taos_stmt_close(TAOS_STMT* stmt) {
STscStmt* pStmt = (STscStmt*)stmt; STscStmt* pStmt = (STscStmt*)stmt;
STMT_CHECK if (pStmt == NULL || pStmt->taos == NULL) {
STMT_RET(TSDB_CODE_TSC_DISCONNECTED);
}
if (!pStmt->isInsert) { if (!pStmt->isInsert) {
SNormalStmt* normal = &pStmt->normal; SNormalStmt* normal = &pStmt->normal;
if (normal->params != NULL) { if (normal->params != NULL) {
...@@ -1805,14 +1808,15 @@ int taos_stmt_close(TAOS_STMT* stmt) { ...@@ -1805,14 +1808,15 @@ int taos_stmt_close(TAOS_STMT* stmt) {
pStmt->mtb.pTableBlockHashList = tscDestroyBlockHashTable(pStmt->mtb.pTableBlockHashList, rmMeta); pStmt->mtb.pTableBlockHashList = tscDestroyBlockHashTable(pStmt->mtb.pTableBlockHashList, rmMeta);
if (pStmt->pSql){ if (pStmt->pSql){
taosHashCleanup(pStmt->pSql->cmd.insertParam.pTableBlockHashList); taosHashCleanup(pStmt->pSql->cmd.insertParam.pTableBlockHashList);
pStmt->pSql->cmd.insertParam.pTableBlockHashList = NULL;
} }
pStmt->pSql->cmd.insertParam.pTableBlockHashList = NULL;
taosArrayDestroy(pStmt->mtb.tags); taosArrayDestroy(pStmt->mtb.tags);
tfree(pStmt->mtb.sqlstr); tfree(pStmt->mtb.sqlstr);
} }
} }
tscFreeSqlObj(pStmt->pSql); taos_free_result(pStmt->pSql);
tfree(pStmt); tfree(pStmt);
STMT_RET(TSDB_CODE_SUCCESS); STMT_RET(TSDB_CODE_SUCCESS);
} }
...@@ -1960,11 +1964,7 @@ int taos_stmt_execute(TAOS_STMT* stmt) { ...@@ -1960,11 +1964,7 @@ int taos_stmt_execute(TAOS_STMT* stmt) {
if (sql == NULL) { if (sql == NULL) {
ret = TSDB_CODE_TSC_OUT_OF_MEMORY; ret = TSDB_CODE_TSC_OUT_OF_MEMORY;
} else { } else {
if (pStmt->pSql != NULL) { taosReleaseRef(tscObjRef, pStmt->pSql->self);
tscFreeSqlObj(pStmt->pSql);
pStmt->pSql = NULL;
}
pStmt->pSql = taos_query((TAOS*)pStmt->taos, sql); pStmt->pSql = taos_query((TAOS*)pStmt->taos, sql);
ret = taos_errno(pStmt->pSql); ret = taos_errno(pStmt->pSql);
free(sql); free(sql);
...@@ -1986,6 +1986,7 @@ TAOS_RES *taos_stmt_use_result(TAOS_STMT* stmt) { ...@@ -1986,6 +1986,7 @@ TAOS_RES *taos_stmt_use_result(TAOS_STMT* stmt) {
return NULL; return NULL;
} }
TAOS_RES* result = pStmt->pSql; TAOS_RES* result = pStmt->pSql;
pStmt->pSql = NULL;
return result; return result;
} }
......
...@@ -465,6 +465,7 @@ void taos_stmt_use_result_query(void *taos, char *col, int type) { ...@@ -465,6 +465,7 @@ void taos_stmt_use_result_query(void *taos, char *col, int type) {
TAOS_RES *result = taos_stmt_use_result(stmt); TAOS_RES *result = taos_stmt_use_result(stmt);
assert(result != NULL); assert(result != NULL);
print_result(result); print_result(result);
taos_free_result(result);
assert(taos_stmt_close(stmt) == 0); assert(taos_stmt_close(stmt) == 0);
free(params); free(params);
free(stmt_sql); free(stmt_sql);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册