stmt2/meta: tbname (multi-insert) parameterized or not
This commit is contained in:
parent
1cfb58e7fe
commit
4cab7ea4f7
|
@ -199,6 +199,7 @@ typedef enum {
|
|||
TAOS_FIELD_COL = 1,
|
||||
TAOS_FIELD_TAG,
|
||||
TAOS_FIELD_QUERY,
|
||||
TAOS_FIELD_TBNAME,
|
||||
} TAOS_FIELD_T;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -218,12 +218,13 @@ int stmtExec2(TAOS_STMT2 *stmt, int *affected_rows);
|
|||
int stmtPrepare2(TAOS_STMT2 *stmt, const char *sql, unsigned long length);
|
||||
int stmtSetTbName2(TAOS_STMT2 *stmt, const char *tbName);
|
||||
int stmtSetTbTags2(TAOS_STMT2 *stmt, TAOS_STMT2_BIND *tags);
|
||||
int stmtBindBatch2(TAOS_STMT2 *stmt, TAOS_STMT2_BIND *bind, int32_t colIdx);
|
||||
int stmtGetTagFields2(TAOS_STMT2 *stmt, int *nums, TAOS_FIELD_E **fields);
|
||||
int stmtGetColFields2(TAOS_STMT2 *stmt, int *nums, TAOS_FIELD_E **fields);
|
||||
int stmtIsInsert2(TAOS_STMT2 *stmt, int *insert);
|
||||
int stmtGetParamNum2(TAOS_STMT2 *stmt, int *nums);
|
||||
int stmtGetParamTbName(TAOS_STMT2 *stmt, int *nums);
|
||||
int stmtIsInsert2(TAOS_STMT2 *stmt, int *insert);
|
||||
TAOS_RES *stmtUseResult2(TAOS_STMT2 *stmt);
|
||||
int stmtBindBatch2(TAOS_STMT2 *stmt, TAOS_STMT2_BIND *bind, int32_t colIdx);
|
||||
const char *stmtErrstr2(TAOS_STMT2 *stmt);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -2005,6 +2005,8 @@ int taos_stmt2_get_fields(TAOS_STMT2 *stmt, TAOS_FIELD_T field_type, int *count,
|
|||
return stmtGetTagFields2(stmt, count, fields);
|
||||
} else if (field_type == TAOS_FIELD_QUERY) {
|
||||
return stmtGetParamNum2(stmt, count);
|
||||
} else if (field_type == TAOS_FIELD_TBNAME) {
|
||||
return stmtGetParamTbName(stmt, count);
|
||||
} else {
|
||||
tscError("invalid parameter for %s", __FUNCTION__);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
|
|
|
@ -1829,6 +1829,38 @@ int stmtGetParamNum2(TAOS_STMT2* stmt, int* nums) {
|
|||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int stmtGetParamTbName(TAOS_STMT2* stmt, int* nums) {
|
||||
STscStmt2* pStmt = (STscStmt2*)stmt;
|
||||
|
||||
STMT_DLOG_E("start to get param num");
|
||||
|
||||
if (pStmt->errCode != TSDB_CODE_SUCCESS) {
|
||||
return pStmt->errCode;
|
||||
}
|
||||
|
||||
STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_FETCH_FIELDS));
|
||||
|
||||
if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 &&
|
||||
STMT_TYPE_MULTI_INSERT != pStmt->sql.type) {
|
||||
pStmt->bInfo.needParse = false;
|
||||
}
|
||||
|
||||
if (pStmt->exec.pRequest && STMT_TYPE_QUERY == pStmt->sql.type && pStmt->sql.runTimes) {
|
||||
taos_free_result(pStmt->exec.pRequest);
|
||||
pStmt->exec.pRequest = NULL;
|
||||
}
|
||||
|
||||
STMT_ERR_RET(stmtCreateRequest(pStmt));
|
||||
|
||||
if (pStmt->bInfo.needParse) {
|
||||
STMT_ERR_RET(stmtParseSql(pStmt));
|
||||
}
|
||||
|
||||
*nums = STMT_TYPE_MULTI_INSERT == pStmt->sql.type ? 1 : 0;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
/*
|
||||
int stmtGetParam(TAOS_STMT* stmt, int idx, int* type, int* bytes) {
|
||||
STscStmt2* pStmt = (STscStmt2*)stmt;
|
||||
|
|
|
@ -70,6 +70,18 @@ void veriry_stmt(TAOS* taos) {
|
|||
}
|
||||
taos_free_result(result);
|
||||
|
||||
sql =
|
||||
"create table m2 (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, blob2 "
|
||||
"nchar(10), blob nchar(10))";
|
||||
result = taos_query(taos, sql);
|
||||
code = taos_errno(result);
|
||||
if (code != 0) {
|
||||
printf("\033[31mfailed to create table, reason:%s\033[0m\n", taos_errstr(result));
|
||||
taos_free_result(result);
|
||||
return;
|
||||
}
|
||||
taos_free_result(result);
|
||||
|
||||
// insert 10 records
|
||||
struct {
|
||||
int64_t ts[10];
|
||||
|
@ -254,7 +266,7 @@ void veriry_stmt(TAOS* taos) {
|
|||
blob2_buffer += blob_len2[i];
|
||||
}
|
||||
|
||||
char* tbname = "m1";
|
||||
char* tbname = "m2";
|
||||
TAOS_STMT2_BIND* bind_cols[1] = {¶ms[0]};
|
||||
TAOS_STMT2_BINDV bindv = {1, &tbname, NULL, &bind_cols[0]};
|
||||
start = clock();
|
||||
|
@ -277,7 +289,7 @@ void veriry_stmt(TAOS* taos) {
|
|||
TAOS_FIELD_E* fields = NULL;
|
||||
int field_count = -1;
|
||||
start = clock();
|
||||
code = taos_stmt2_get_fields(stmt, TAOS_FIELD_COL, &field_count, NULL);
|
||||
code = taos_stmt2_get_fields(stmt, TAOS_FIELD_TBNAME, &field_count, NULL);
|
||||
end = clock();
|
||||
printf("get fields time:%f\n", (double)(end - start) / CLOCKS_PER_SEC);
|
||||
if (code != 0) {
|
||||
|
|
Loading…
Reference in New Issue