fix review

This commit is contained in:
Pengrongkun 2024-12-13 23:43:20 +08:00
parent e20b6c1188
commit 997af901f9
3 changed files with 29 additions and 17 deletions

View File

@ -150,6 +150,7 @@ typedef struct {
SStmtExecInfo exec; SStmtExecInfo exec;
SStmtBindInfo bInfo; SStmtBindInfo bInfo;
char *db;
int64_t reqid; int64_t reqid;
int32_t errCode; int32_t errCode;
tsem_t asyncQuerySem; tsem_t asyncQuerySem;

View File

@ -2175,6 +2175,13 @@ int taos_stmt2_bind_param(TAOS_STMT2 *stmt, TAOS_STMT2_BINDV *bindv, int32_t col
} }
} }
if (bindv->tags && bindv->tags[i]) {
code = stmtSetTbTags2(stmt, bindv->tags[i]);
if (code) {
return code;
}
}
if (bindv->bind_cols && bindv->bind_cols[i]) { if (bindv->bind_cols && bindv->bind_cols[i]) {
TAOS_STMT2_BIND *bind = bindv->bind_cols[i]; TAOS_STMT2_BIND *bind = bindv->bind_cols[i];
@ -2197,13 +2204,6 @@ int taos_stmt2_bind_param(TAOS_STMT2 *stmt, TAOS_STMT2_BINDV *bindv, int32_t col
return code; return code;
} }
} }
if (bindv->tags && bindv->tags[i]) {
code = stmtSetTbTags2(stmt, bindv->tags[i]);
if (code) {
return code;
}
}
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;

View File

@ -75,6 +75,10 @@ static int32_t stmtCreateRequest(STscStmt2* pStmt) {
if (pStmt->reqid != 0) { if (pStmt->reqid != 0) {
pStmt->reqid++; pStmt->reqid++;
} }
if (pStmt->db != NULL) {
taosMemoryFreeClear(pStmt->exec.pRequest->pDb);
pStmt->exec.pRequest->pDb = strdup(pStmt->db);
}
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
pStmt->exec.pRequest->syncQuery = true; pStmt->exec.pRequest->syncQuery = true;
pStmt->exec.pRequest->isStmtBind = true; pStmt->exec.pRequest->isStmtBind = true;
@ -109,7 +113,7 @@ static int32_t stmtSwitchStatus(STscStmt2* pStmt, STMT_STATUS newStatus) {
} }
break; break;
case STMT_SETTAGS: case STMT_SETTAGS:
if (STMT_STATUS_NE(SETTBNAME) && STMT_STATUS_NE(FETCH_FIELDS) && STMT_STATUS_NE(ADD_BATCH)) { if (STMT_STATUS_EQ(INIT)) {
code = TSDB_CODE_TSC_STMT_API_ERROR; code = TSDB_CODE_TSC_STMT_API_ERROR;
} }
break; break;
@ -145,7 +149,7 @@ static int32_t stmtSwitchStatus(STscStmt2* pStmt, STMT_STATUS newStatus) {
code = TSDB_CODE_TSC_STMT_API_ERROR; code = TSDB_CODE_TSC_STMT_API_ERROR;
} }
} else { } else {
if (STMT_STATUS_NE(ADD_BATCH) && STMT_STATUS_NE(FETCH_FIELDS) && STMT_STATUS_NE(SETTAGS)) { if (STMT_STATUS_NE(ADD_BATCH) && STMT_STATUS_NE(FETCH_FIELDS)) {
code = TSDB_CODE_TSC_STMT_API_ERROR; code = TSDB_CODE_TSC_STMT_API_ERROR;
} }
} }
@ -412,6 +416,7 @@ static void stmtFreeTbCols(void* buf) {
static int32_t stmtCleanSQLInfo(STscStmt2* pStmt) { static int32_t stmtCleanSQLInfo(STscStmt2* pStmt) {
STMT_DLOG_E("start to free SQL info"); STMT_DLOG_E("start to free SQL info");
taosMemoryFreeClear(pStmt->db);
taosMemoryFree(pStmt->sql.pBindInfo); taosMemoryFree(pStmt->sql.pBindInfo);
taosMemoryFree(pStmt->sql.queryRes.fields); taosMemoryFree(pStmt->sql.queryRes.fields);
taosMemoryFree(pStmt->sql.queryRes.userFields); taosMemoryFree(pStmt->sql.queryRes.userFields);
@ -842,6 +847,7 @@ static int stmtSetDbName2(TAOS_STMT2* stmt, const char* dbName) {
STMT_DLOG("start to set dbName: %s", dbName); STMT_DLOG("start to set dbName: %s", dbName);
pStmt->db = taosStrdup(dbName);
STMT_ERR_RET(stmtCreateRequest(pStmt)); STMT_ERR_RET(stmtCreateRequest(pStmt));
// The SQL statement specifies a database name, overriding the previously specified database // The SQL statement specifies a database name, overriding the previously specified database
@ -952,14 +958,6 @@ int stmtSetTbName2(TAOS_STMT2* stmt, const char* tbName) {
if (!pStmt->sql.stbInterlaceMode || NULL == pStmt->sql.siInfo.pDataCtx) { if (!pStmt->sql.stbInterlaceMode || NULL == pStmt->sql.siInfo.pDataCtx) {
STMT_ERR_RET(stmtCreateRequest(pStmt)); STMT_ERR_RET(stmtCreateRequest(pStmt));
if (pStmt->exec.pRequest->pDb == NULL) {
char* dbName = NULL;
if (qParseDbName(pStmt->exec.pRequest->sqlstr, pStmt->exec.pRequest->sqlLen, &dbName)) {
STMT_ERR_RET(stmtSetDbName2(pStmt, dbName));
taosMemoryFreeClear(dbName);
}
}
STMT_ERR_RET(qCreateSName(&pStmt->bInfo.sname, tbName, pStmt->taos->acctId, pStmt->exec.pRequest->pDb, STMT_ERR_RET(qCreateSName(&pStmt->bInfo.sname, tbName, pStmt->taos->acctId, pStmt->exec.pRequest->pDb,
pStmt->exec.pRequest->msgBuf, pStmt->exec.pRequest->msgBufLen)); pStmt->exec.pRequest->msgBuf, pStmt->exec.pRequest->msgBufLen));
STMT_ERR_RET(tNameExtractFullName(&pStmt->bInfo.sname, pStmt->bInfo.tbFName)); STMT_ERR_RET(tNameExtractFullName(&pStmt->bInfo.sname, pStmt->bInfo.tbFName));
@ -1000,6 +998,19 @@ int stmtSetTbTags2(TAOS_STMT2* stmt, TAOS_STMT2_BIND* tags) {
STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_SETTAGS)); STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_SETTAGS));
if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 &&
STMT_TYPE_MULTI_INSERT != pStmt->sql.type) {
pStmt->bInfo.needParse = false;
}
STMT_ERR_RET(stmtCreateRequest(pStmt));
if (pStmt->bInfo.needParse) {
STMT_ERR_RET(stmtParseSql(pStmt));
}
if (pStmt->sql.stbInterlaceMode && NULL == pStmt->sql.siInfo.pDataCtx) {
STMT_ERR_RET(stmtInitStbInterlaceTableInfo(pStmt));
}
SBoundColInfo* tags_info = (SBoundColInfo*)pStmt->bInfo.boundTags; SBoundColInfo* tags_info = (SBoundColInfo*)pStmt->bInfo.boundTags;
if (tags_info->numOfBound <= 0 || tags_info->numOfCols <= 0) { if (tags_info->numOfBound <= 0 || tags_info->numOfCols <= 0) {
tscWarn("no tags or cols bound in sql, will not bound tags"); tscWarn("no tags or cols bound in sql, will not bound tags");