Revert "enh(stmt2):add api taos_stmt2_get_all_fields"
This commit is contained in:
parent
c5d258ac1e
commit
e260eb7a07
|
@ -81,13 +81,6 @@ typedef enum {
|
||||||
TSDB_SML_TIMESTAMP_NANO_SECONDS,
|
TSDB_SML_TIMESTAMP_NANO_SECONDS,
|
||||||
} TSDB_SML_TIMESTAMP_TYPE;
|
} TSDB_SML_TIMESTAMP_TYPE;
|
||||||
|
|
||||||
typedef enum TAOS_FIELD_T {
|
|
||||||
TAOS_FIELD_COL = 1,
|
|
||||||
TAOS_FIELD_TAG,
|
|
||||||
TAOS_FIELD_QUERY,
|
|
||||||
TAOS_FIELD_TBNAME,
|
|
||||||
} TAOS_FIELD_T;
|
|
||||||
|
|
||||||
typedef struct taosField {
|
typedef struct taosField {
|
||||||
char name[65];
|
char name[65];
|
||||||
int8_t type;
|
int8_t type;
|
||||||
|
@ -102,15 +95,6 @@ typedef struct TAOS_FIELD_E {
|
||||||
int32_t bytes;
|
int32_t bytes;
|
||||||
} TAOS_FIELD_E;
|
} TAOS_FIELD_E;
|
||||||
|
|
||||||
typedef struct TAOS_FIELD_ALL {
|
|
||||||
char name[65];
|
|
||||||
int8_t type;
|
|
||||||
uint8_t precision;
|
|
||||||
uint8_t scale;
|
|
||||||
int32_t bytes;
|
|
||||||
TAOS_FIELD_T field_type;
|
|
||||||
} TAOS_FIELD_ALL;
|
|
||||||
|
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
#define DLL_EXPORT __declspec(dllexport)
|
#define DLL_EXPORT __declspec(dllexport)
|
||||||
#else
|
#else
|
||||||
|
@ -211,6 +195,13 @@ DLL_EXPORT int taos_stmt_affected_rows_once(TAOS_STMT *stmt);
|
||||||
|
|
||||||
typedef void TAOS_STMT2;
|
typedef void TAOS_STMT2;
|
||||||
|
|
||||||
|
typedef enum TAOS_FIELD_T {
|
||||||
|
TAOS_FIELD_COL = 1,
|
||||||
|
TAOS_FIELD_TAG,
|
||||||
|
TAOS_FIELD_QUERY,
|
||||||
|
TAOS_FIELD_TBNAME,
|
||||||
|
} TAOS_FIELD_T;
|
||||||
|
|
||||||
typedef struct TAOS_STMT2_OPTION {
|
typedef struct TAOS_STMT2_OPTION {
|
||||||
int64_t reqid;
|
int64_t reqid;
|
||||||
bool singleStbInsert;
|
bool singleStbInsert;
|
||||||
|
@ -241,9 +232,7 @@ DLL_EXPORT int taos_stmt2_exec(TAOS_STMT2 *stmt, int *affected_rows);
|
||||||
DLL_EXPORT int taos_stmt2_close(TAOS_STMT2 *stmt);
|
DLL_EXPORT int taos_stmt2_close(TAOS_STMT2 *stmt);
|
||||||
DLL_EXPORT int taos_stmt2_is_insert(TAOS_STMT2 *stmt, int *insert);
|
DLL_EXPORT int taos_stmt2_is_insert(TAOS_STMT2 *stmt, int *insert);
|
||||||
DLL_EXPORT int taos_stmt2_get_fields(TAOS_STMT2 *stmt, TAOS_FIELD_T field_type, int *count, TAOS_FIELD_E **fields);
|
DLL_EXPORT int taos_stmt2_get_fields(TAOS_STMT2 *stmt, TAOS_FIELD_T field_type, int *count, TAOS_FIELD_E **fields);
|
||||||
DLL_EXPORT int taos_stmt2_get_all_fields(TAOS_STMT2 *stmt, int *count, TAOS_FIELD_ALL **fields);
|
|
||||||
DLL_EXPORT void taos_stmt2_free_fields(TAOS_STMT2 *stmt, TAOS_FIELD_E *fields);
|
DLL_EXPORT void taos_stmt2_free_fields(TAOS_STMT2 *stmt, TAOS_FIELD_E *fields);
|
||||||
DLL_EXPORT void taos_stmt2_free_all_fields(TAOS_STMT2 *stmt, TAOS_FIELD_ALL *fields);
|
|
||||||
DLL_EXPORT TAOS_RES *taos_stmt2_result(TAOS_STMT2 *stmt);
|
DLL_EXPORT TAOS_RES *taos_stmt2_result(TAOS_STMT2 *stmt);
|
||||||
DLL_EXPORT char *taos_stmt2_error(TAOS_STMT2 *stmt);
|
DLL_EXPORT char *taos_stmt2_error(TAOS_STMT2 *stmt);
|
||||||
|
|
||||||
|
|
|
@ -222,7 +222,6 @@ int stmtSetTbTags2(TAOS_STMT2 *stmt, TAOS_STMT2_BIND *tags);
|
||||||
int stmtBindBatch2(TAOS_STMT2 *stmt, TAOS_STMT2_BIND *bind, int32_t colIdx);
|
int stmtBindBatch2(TAOS_STMT2 *stmt, TAOS_STMT2_BIND *bind, int32_t colIdx);
|
||||||
int stmtGetTagFields2(TAOS_STMT2 *stmt, int *nums, TAOS_FIELD_E **fields);
|
int stmtGetTagFields2(TAOS_STMT2 *stmt, int *nums, TAOS_FIELD_E **fields);
|
||||||
int stmtGetColFields2(TAOS_STMT2 *stmt, int *nums, TAOS_FIELD_E **fields);
|
int stmtGetColFields2(TAOS_STMT2 *stmt, int *nums, TAOS_FIELD_E **fields);
|
||||||
int stmtGetColFieldsALL2(TAOS_STMT2 *stmt, int *nums, TAOS_FIELD_ALL **fields);
|
|
||||||
int stmtGetParamNum2(TAOS_STMT2 *stmt, int *nums);
|
int stmtGetParamNum2(TAOS_STMT2 *stmt, int *nums);
|
||||||
int stmtGetParamTbName(TAOS_STMT2 *stmt, int *nums);
|
int stmtGetParamTbName(TAOS_STMT2 *stmt, int *nums);
|
||||||
int stmtIsInsert2(TAOS_STMT2 *stmt, int *insert);
|
int stmtIsInsert2(TAOS_STMT2 *stmt, int *insert);
|
||||||
|
|
|
@ -388,6 +388,7 @@ void taos_free_result(TAOS_RES *res) {
|
||||||
tDeleteMqBatchMetaRsp(&pRsp->batchMetaRsp);
|
tDeleteMqBatchMetaRsp(&pRsp->batchMetaRsp);
|
||||||
}
|
}
|
||||||
taosMemoryFree(pRsp);
|
taosMemoryFree(pRsp);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void taos_kill_query(TAOS *taos) {
|
void taos_kill_query(TAOS *taos) {
|
||||||
|
@ -2081,7 +2082,7 @@ int taos_stmt2_is_insert(TAOS_STMT2 *stmt, int *insert) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int taos_stmt2_get_fields(TAOS_STMT2 *stmt, TAOS_FIELD_T field_type, int *count, TAOS_FIELD_E **fields) {
|
int taos_stmt2_get_fields(TAOS_STMT2 *stmt, TAOS_FIELD_T field_type, int *count, TAOS_FIELD_E **fields) {
|
||||||
if (stmt == NULL || count == NULL) {
|
if (stmt == NULL || NULL == count) {
|
||||||
tscError("NULL parameter for %s", __FUNCTION__);
|
tscError("NULL parameter for %s", __FUNCTION__);
|
||||||
terrno = TSDB_CODE_INVALID_PARA;
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
return terrno;
|
return terrno;
|
||||||
|
@ -2102,28 +2103,12 @@ int taos_stmt2_get_fields(TAOS_STMT2 *stmt, TAOS_FIELD_T field_type, int *count,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int taos_stmt2_get_all_fields(TAOS_STMT2 *stmt, int *count, TAOS_FIELD_ALL **fields) {
|
|
||||||
if (stmt == NULL || count == NULL) {
|
|
||||||
tscError("NULL parameter for %s", __FUNCTION__);
|
|
||||||
terrno = TSDB_CODE_INVALID_PARA;
|
|
||||||
return terrno;
|
|
||||||
}
|
|
||||||
|
|
||||||
return stmtGetColFieldsALL2(stmt, count, fields);
|
|
||||||
}
|
|
||||||
|
|
||||||
void taos_stmt2_free_fields(TAOS_STMT2 *stmt, TAOS_FIELD_E *fields) {
|
void taos_stmt2_free_fields(TAOS_STMT2 *stmt, TAOS_FIELD_E *fields) {
|
||||||
(void)stmt;
|
(void)stmt;
|
||||||
if (!fields) return;
|
if (!fields) return;
|
||||||
taosMemoryFree(fields);
|
taosMemoryFree(fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
DLL_EXPORT void taos_stmt2_free_all_fields(TAOS_STMT2 *stmt, TAOS_FIELD_ALL *fields) {
|
|
||||||
(void)stmt;
|
|
||||||
if (!fields) return;
|
|
||||||
taosMemoryFree(fields);
|
|
||||||
}
|
|
||||||
|
|
||||||
TAOS_RES *taos_stmt2_result(TAOS_STMT2 *stmt) {
|
TAOS_RES *taos_stmt2_result(TAOS_STMT2 *stmt) {
|
||||||
if (stmt == NULL) {
|
if (stmt == NULL) {
|
||||||
tscError("NULL parameter for %s", __FUNCTION__);
|
tscError("NULL parameter for %s", __FUNCTION__);
|
||||||
|
|
|
@ -1068,48 +1068,6 @@ static int stmtFetchColFields2(STscStmt2* pStmt, int32_t* fieldNum, TAOS_FIELD_E
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int stmtFetchFields2(STscStmt2* pStmt, int32_t* fieldNum, TAOS_FIELD_ALL** fields) {
|
|
||||||
SBoundColInfo* tags = (SBoundColInfo*)pStmt->bInfo.boundTags;
|
|
||||||
STableMeta* meta = ((SVnodeModifyOpStmt*)(pStmt->sql.pQuery->pRoot))->pTableMeta;
|
|
||||||
if (tags == NULL || meta == NULL || (meta->schema == NULL && tags->numOfBound != 0)) {
|
|
||||||
return TSDB_CODE_INVALID_PARA;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fields != NULL) {
|
|
||||||
*fields = taosMemoryCalloc(tags->numOfBound, sizeof(TAOS_FIELD_ALL));
|
|
||||||
if (NULL == *fields) {
|
|
||||||
return terrno;
|
|
||||||
}
|
|
||||||
|
|
||||||
SSchema* pSchema = meta->schema;
|
|
||||||
int32_t tbnameIdx = meta->tableInfo.numOfTags + meta->tableInfo.numOfColumns;
|
|
||||||
for (int32_t i = 0; i < tags->numOfBound; ++i) {
|
|
||||||
int16_t idx = tags->pColIndex[i];
|
|
||||||
if (idx == tbnameIdx) {
|
|
||||||
(*fields)[i].field_type = TAOS_FIELD_TBNAME;
|
|
||||||
tstrncpy((*fields)[i].name, "tbname", sizeof((*fields)[i].name));
|
|
||||||
continue;
|
|
||||||
} else if (idx < meta->tableInfo.numOfColumns) {
|
|
||||||
(*fields)[i].field_type = TAOS_FIELD_COL;
|
|
||||||
} else {
|
|
||||||
(*fields)[i].field_type = TAOS_FIELD_TAG;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TSDB_DATA_TYPE_TIMESTAMP == pSchema[tags->pColIndex[i]].type) {
|
|
||||||
(*fields)[i].precision = meta->tableInfo.precision;
|
|
||||||
}
|
|
||||||
|
|
||||||
tstrncpy((*fields)[i].name, pSchema[tags->pColIndex[i]].name, sizeof((*fields)[i].name));
|
|
||||||
(*fields)[i].type = pSchema[tags->pColIndex[i]].type;
|
|
||||||
(*fields)[i].bytes = pSchema[tags->pColIndex[i]].bytes;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*fieldNum = tags->numOfBound;
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
SArray* stmtGetFreeCol(STscStmt2* pStmt, int32_t* idx) {
|
SArray* stmtGetFreeCol(STscStmt2* pStmt, int32_t* idx) {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -1893,50 +1851,6 @@ _return:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int stmtGetColFieldsALL2(TAOS_STMT2* stmt, int* nums, TAOS_FIELD_ALL** fields) {
|
|
||||||
int32_t code = 0;
|
|
||||||
STscStmt2* pStmt = (STscStmt2*)stmt;
|
|
||||||
int32_t preCode = pStmt->errCode;
|
|
||||||
|
|
||||||
STMT_DLOG_E("start to get col fields");
|
|
||||||
|
|
||||||
if (pStmt->errCode != TSDB_CODE_SUCCESS) {
|
|
||||||
return pStmt->errCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (STMT_TYPE_QUERY == pStmt->sql.type) {
|
|
||||||
STMT_ERRI_JRET(TSDB_CODE_TSC_STMT_API_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
STMT_ERRI_JRET(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));
|
|
||||||
}
|
|
||||||
|
|
||||||
STMT_ERRI_JRET(stmtCreateRequest(pStmt));
|
|
||||||
|
|
||||||
if (pStmt->bInfo.needParse) {
|
|
||||||
STMT_ERRI_JRET(stmtParseSql(pStmt));
|
|
||||||
}
|
|
||||||
|
|
||||||
_return:
|
|
||||||
|
|
||||||
pStmt->errCode = preCode;
|
|
||||||
if (code == TSDB_CODE_TSC_INVALID_OPERATION) {
|
|
||||||
return stmtFetchFields2(stmt, nums, fields);
|
|
||||||
}
|
|
||||||
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
int stmtGetParamNum2(TAOS_STMT2* stmt, int* nums) {
|
int stmtGetParamNum2(TAOS_STMT2* stmt, int* nums) {
|
||||||
STscStmt2* pStmt = (STscStmt2*)stmt;
|
STscStmt2* pStmt = (STscStmt2*)stmt;
|
||||||
|
|
||||||
|
|
|
@ -780,9 +780,6 @@ static int32_t buildCreateTbReq(SVnodeModifyOpStmt* pStmt, STag* pTag, SArray* p
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t checkAndTrimValue(SToken* pToken, char* tmpTokenBuf, SMsgBuf* pMsgBuf, int8_t type) {
|
int32_t checkAndTrimValue(SToken* pToken, char* tmpTokenBuf, SMsgBuf* pMsgBuf, int8_t type) {
|
||||||
if (pToken->type == TK_NK_QUESTION) {
|
|
||||||
return buildInvalidOperationMsg(pMsgBuf, "insert into super table syntax is not supported for stmt");
|
|
||||||
}
|
|
||||||
if ((pToken->type != TK_NOW && pToken->type != TK_TODAY && pToken->type != TK_NK_INTEGER &&
|
if ((pToken->type != TK_NOW && pToken->type != TK_TODAY && pToken->type != TK_NK_INTEGER &&
|
||||||
pToken->type != TK_NK_STRING && pToken->type != TK_NK_FLOAT && pToken->type != TK_NK_BOOL &&
|
pToken->type != TK_NK_STRING && pToken->type != TK_NK_FLOAT && pToken->type != TK_NK_BOOL &&
|
||||||
pToken->type != TK_NULL && pToken->type != TK_NK_HEX && pToken->type != TK_NK_OCT && pToken->type != TK_NK_BIN &&
|
pToken->type != TK_NULL && pToken->type != TK_NK_HEX && pToken->type != TK_NK_OCT && pToken->type != TK_NK_BIN &&
|
||||||
|
@ -2179,8 +2176,8 @@ static int32_t parseCsvFile(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt
|
||||||
if (code == TSDB_CODE_SUCCESS) {
|
if (code == TSDB_CODE_SUCCESS) {
|
||||||
SStbRowsDataContext* pStbRowsCxt = rowsDataCxt.pStbRowsCxt;
|
SStbRowsDataContext* pStbRowsCxt = rowsDataCxt.pStbRowsCxt;
|
||||||
void* pData = pTableDataCxt;
|
void* pData = pTableDataCxt;
|
||||||
code = taosHashPut(pStmt->pTableCxtHashObj, &pStbRowsCxt->pCtbMeta->uid, sizeof(pStbRowsCxt->pCtbMeta->uid),
|
code = taosHashPut(pStmt->pTableCxtHashObj, &pStbRowsCxt->pCtbMeta->uid, sizeof(pStbRowsCxt->pCtbMeta->uid), &pData,
|
||||||
&pData, POINTER_BYTES);
|
POINTER_BYTES);
|
||||||
if (TSDB_CODE_SUCCESS != code) {
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2366,7 +2363,8 @@ static int32_t constructStbRowsDataContext(SVnodeModifyOpStmt* pStmt, SStbRowsDa
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
// col values and bound cols info of STableDataContext is not used
|
// col values and bound cols info of STableDataContext is not used
|
||||||
pStbRowsCxt->aColVals = taosArrayInit(getNumOfColumns(pStbRowsCxt->pStbMeta), sizeof(SColVal));
|
pStbRowsCxt->aColVals = taosArrayInit(getNumOfColumns(pStbRowsCxt->pStbMeta), sizeof(SColVal));
|
||||||
if (!pStbRowsCxt->aColVals) code = terrno;
|
if (!pStbRowsCxt->aColVals)
|
||||||
|
code = terrno;
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = insInitColValues(pStbRowsCxt->pStbMeta, pStbRowsCxt->aColVals);
|
code = insInitColValues(pStbRowsCxt->pStbMeta, pStbRowsCxt->aColVals);
|
||||||
|
@ -2424,6 +2422,9 @@ static int32_t parseInsertStbClauseBottom(SInsertParseContext* pCxt, SVnodeModif
|
||||||
// 1. [(tag1_name, ...)] ...
|
// 1. [(tag1_name, ...)] ...
|
||||||
// 2. VALUES ... | FILE ...
|
// 2. VALUES ... | FILE ...
|
||||||
static int32_t parseInsertTableClauseBottom(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt) {
|
static int32_t parseInsertTableClauseBottom(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt) {
|
||||||
|
if (pStmt->stbSyntax && TSDB_QUERY_HAS_TYPE(pStmt->insertType, TSDB_QUERY_TYPE_STMT_INSERT)) {
|
||||||
|
return buildInvalidOperationMsg(&pCxt->msg, "insert into super table syntax is not supported for stmt");
|
||||||
|
}
|
||||||
if (!pStmt->stbSyntax) {
|
if (!pStmt->stbSyntax) {
|
||||||
STableDataCxt* pTableCxt = NULL;
|
STableDataCxt* pTableCxt = NULL;
|
||||||
int32_t code = parseSchemaClauseBottom(pCxt, pStmt, &pTableCxt);
|
int32_t code = parseSchemaClauseBottom(pCxt, pStmt, &pTableCxt);
|
||||||
|
@ -2527,8 +2528,7 @@ static int32_t checkTableClauseFirstToken(SInsertParseContext* pCxt, SVnodeModif
|
||||||
if (pCxt->isStmtBind) {
|
if (pCxt->isStmtBind) {
|
||||||
if (TK_NK_ID == pTbName->type || (tbNameAfterDbName != NULL && *(tbNameAfterDbName + 1) != '?')) {
|
if (TK_NK_ID == pTbName->type || (tbNameAfterDbName != NULL && *(tbNameAfterDbName + 1) != '?')) {
|
||||||
// In SQL statements, the table name has already been specified.
|
// In SQL statements, the table name has already been specified.
|
||||||
parserWarn("0x%" PRIx64 " table name is specified in sql, ignore the table name in bind param",
|
parserWarn("0x%" PRIx64 " table name is specified in sql, ignore the table name in bind param", pCxt->pComCxt->requestId);
|
||||||
pCxt->pComCxt->requestId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3066,9 +3066,8 @@ int32_t parseInsertSql(SParseContext* pCxt, SQuery** pQuery, SCatalogReq* pCatal
|
||||||
.isStmtBind = pCxt->isStmtBind};
|
.isStmtBind = pCxt->isStmtBind};
|
||||||
|
|
||||||
int32_t code = initInsertQuery(&context, pCatalogReq, pMetaData, pQuery);
|
int32_t code = initInsertQuery(&context, pCatalogReq, pMetaData, pQuery);
|
||||||
SVnodeModifyOpStmt* pStmt = (SVnodeModifyOpStmt*)((*pQuery)->pRoot);
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = parseInsertSqlImpl(&context, pStmt);
|
code = parseInsertSqlImpl(&context, (SVnodeModifyOpStmt*)(*pQuery)->pRoot);
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = setNextStageInfo(&context, *pQuery, pCatalogReq);
|
code = setNextStageInfo(&context, *pQuery, pCatalogReq);
|
||||||
|
@ -3077,27 +3076,8 @@ int32_t parseInsertSql(SParseContext* pCxt, SQuery** pQuery, SCatalogReq* pCatal
|
||||||
QUERY_EXEC_STAGE_SCHEDULE == (*pQuery)->execStage) {
|
QUERY_EXEC_STAGE_SCHEDULE == (*pQuery)->execStage) {
|
||||||
code = setRefreshMeta(*pQuery);
|
code = setRefreshMeta(*pQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pStmt->stbSyntax && TSDB_QUERY_HAS_TYPE(pStmt->insertType, TSDB_QUERY_TYPE_STMT_INSERT) &&
|
|
||||||
code == TSDB_CODE_TSC_INVALID_OPERATION) {
|
|
||||||
context.tags.numOfBound = pStmt->pStbRowsCxt->boundColsInfo.numOfBound;
|
|
||||||
context.tags.numOfCols = pStmt->pStbRowsCxt->boundColsInfo.numOfCols;
|
|
||||||
context.tags.hasBoundCols = pStmt->pStbRowsCxt->boundColsInfo.hasBoundCols;
|
|
||||||
context.tags.pColIndex = taosMemoryMalloc(sizeof(int16_t) * context.tags.numOfBound);
|
|
||||||
if (NULL == context.tags.pColIndex) {
|
|
||||||
return terrno;
|
|
||||||
}
|
|
||||||
|
|
||||||
(void)memcpy(context.tags.pColIndex, pStmt->pStbRowsCxt->boundColsInfo.pColIndex,
|
|
||||||
sizeof(int16_t) * pStmt->pStbRowsCxt->boundColsInfo.numOfBound);
|
|
||||||
code = setStmtInfo(&context, pStmt);
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
|
||||||
insDestroyBoundColInfo(&context.tags);
|
insDestroyBoundColInfo(&context.tags);
|
||||||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
insDestroyBoundColInfo(&context.tags);
|
|
||||||
// if no data to insert, set emptyMode to avoid request server
|
// if no data to insert, set emptyMode to avoid request server
|
||||||
if (!context.needRequest) {
|
if (!context.needRequest) {
|
||||||
(*pQuery)->execMode = QUERY_EXEC_MODE_EMPTY_RESULT;
|
(*pQuery)->execMode = QUERY_EXEC_MODE_EMPTY_RESULT;
|
||||||
|
|
|
@ -886,7 +886,7 @@ _return:
|
||||||
|
|
||||||
int32_t buildBoundFields(int32_t numOfBound, int16_t* boundColumns, SSchema* pSchema, int32_t* fieldNum,
|
int32_t buildBoundFields(int32_t numOfBound, int16_t* boundColumns, SSchema* pSchema, int32_t* fieldNum,
|
||||||
TAOS_FIELD_E** fields, uint8_t timePrec) {
|
TAOS_FIELD_E** fields, uint8_t timePrec) {
|
||||||
if (fields != NULL) {
|
if (fields) {
|
||||||
*fields = taosMemoryCalloc(numOfBound, sizeof(TAOS_FIELD_E));
|
*fields = taosMemoryCalloc(numOfBound, sizeof(TAOS_FIELD_E));
|
||||||
if (NULL == *fields) {
|
if (NULL == *fields) {
|
||||||
return terrno;
|
return terrno;
|
||||||
|
@ -939,7 +939,7 @@ int32_t qBuildStmtColFields(void* pBlock, int32_t* fieldNum, TAOS_FIELD_E** fiel
|
||||||
SSchema* pSchema = getTableColumnSchema(pDataBlock->pMeta);
|
SSchema* pSchema = getTableColumnSchema(pDataBlock->pMeta);
|
||||||
if (pDataBlock->boundColsInfo.numOfBound <= 0) {
|
if (pDataBlock->boundColsInfo.numOfBound <= 0) {
|
||||||
*fieldNum = 0;
|
*fieldNum = 0;
|
||||||
if (fields != NULL) {
|
if (fields) {
|
||||||
*fields = NULL;
|
*fields = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,6 @@ exe:
|
||||||
gcc $(CFLAGS) ./stmt.c -o $(ROOT)stmt $(LFLAGS)
|
gcc $(CFLAGS) ./stmt.c -o $(ROOT)stmt $(LFLAGS)
|
||||||
gcc $(CFLAGS) ./stmt2.c -o $(ROOT)stmt2 $(LFLAGS)
|
gcc $(CFLAGS) ./stmt2.c -o $(ROOT)stmt2 $(LFLAGS)
|
||||||
gcc $(CFLAGS) ./stmt2-example.c -o $(ROOT)stmt2-example $(LFLAGS)
|
gcc $(CFLAGS) ./stmt2-example.c -o $(ROOT)stmt2-example $(LFLAGS)
|
||||||
gcc $(CFLAGS) ./stmt2-get-fields.c -o $(ROOT)stmt2-get-fields $(LFLAGS)
|
|
||||||
gcc $(CFLAGS) ./stmt2-nohole.c -o $(ROOT)stmt2-nohole $(LFLAGS)
|
gcc $(CFLAGS) ./stmt2-nohole.c -o $(ROOT)stmt2-nohole $(LFLAGS)
|
||||||
gcc $(CFLAGS) ./stmt-crash.c -o $(ROOT)stmt-crash $(LFLAGS)
|
gcc $(CFLAGS) ./stmt-crash.c -o $(ROOT)stmt-crash $(LFLAGS)
|
||||||
|
|
||||||
|
@ -43,6 +42,5 @@ clean:
|
||||||
rm $(ROOT)stmt
|
rm $(ROOT)stmt
|
||||||
rm $(ROOT)stmt2
|
rm $(ROOT)stmt2
|
||||||
rm $(ROOT)stmt2-example
|
rm $(ROOT)stmt2-example
|
||||||
rm $(ROOT)stmt2-get-fields
|
|
||||||
rm $(ROOT)stmt2-nohole
|
rm $(ROOT)stmt2-nohole
|
||||||
rm $(ROOT)stmt-crash
|
rm $(ROOT)stmt-crash
|
||||||
|
|
|
@ -1,63 +0,0 @@
|
||||||
// TAOS standard API example. The same syntax as MySQL, but only a subet
|
|
||||||
// to compile: gcc -o stmt2-get-fields stmt2-get-fields.c -ltaos
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "taos.h"
|
|
||||||
|
|
||||||
void do_query(TAOS *taos, const char *sql) {
|
|
||||||
TAOS_RES *result = taos_query(taos, sql);
|
|
||||||
int code = taos_errno(result);
|
|
||||||
if (code) {
|
|
||||||
printf("failed to query: %s, reason:%s\n", sql, taos_errstr(result));
|
|
||||||
taos_free_result(result);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
taos_free_result(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
void do_stmt(TAOS *taos) {
|
|
||||||
do_query(taos, "drop database if exists db");
|
|
||||||
do_query(taos, "create database db");
|
|
||||||
do_query(taos,
|
|
||||||
"create table db.stb (ts timestamp, b binary(10)) tags(t1 "
|
|
||||||
"int, t2 binary(10))");
|
|
||||||
|
|
||||||
TAOS_STMT2_OPTION option = {0};
|
|
||||||
TAOS_STMT2 *stmt = taos_stmt2_init(taos, &option);
|
|
||||||
const char *sql = "insert into db.stb(t1,t2,ts,b,tbname) values(?,?,?,?,?)";
|
|
||||||
|
|
||||||
int code = taos_stmt2_prepare(stmt, sql, 0);
|
|
||||||
if (code != 0) {
|
|
||||||
printf("failed to execute taos_stmt2_prepare. error:%s\n", taos_stmt2_error(stmt));
|
|
||||||
taos_stmt2_close(stmt);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int fieldNum = 0;
|
|
||||||
TAOS_FIELD_ALL *pFields = NULL;
|
|
||||||
code = taos_stmt2_get_all_fields(stmt, &fieldNum, &pFields);
|
|
||||||
if (code != 0) {
|
|
||||||
printf("failed get col,ErrCode: 0x%x, ErrMessage: %s.\n", code, taos_stmt2_error(stmt));
|
|
||||||
} else {
|
|
||||||
printf("col nums:%d\n", fieldNum);
|
|
||||||
for (int i = 0; i < fieldNum; i++) {
|
|
||||||
printf("field[%d]: %s,type:%d\n", i, pFields[i].name, pFields[i].field_type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
taos_stmt2_close(stmt);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", "", 0);
|
|
||||||
if (!taos) {
|
|
||||||
printf("failed to connect to db, reason:%s\n", taos_errstr(taos));
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
do_stmt(taos);
|
|
||||||
taos_close(taos);
|
|
||||||
taos_cleanup();
|
|
||||||
}
|
|
Loading…
Reference in New Issue