TDengine/source/client/inc/clientStmt.h

239 lines
7 KiB
C
Raw Normal View History

2022-04-13 09:52:26 +00:00
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_CLIENTSTMT_H
#define TDENGINE_CLIENTSTMT_H
#ifdef __cplusplus
extern "C" {
#endif
2022-04-18 02:19:15 +00:00
#include "catalog.h"
2022-04-13 09:52:26 +00:00
typedef enum {
STMT_TYPE_INSERT = 1,
STMT_TYPE_MULTI_INSERT,
2022-04-18 05:22:47 +00:00
STMT_TYPE_QUERY,
2022-04-13 09:52:26 +00:00
} STMT_TYPE;
2022-04-14 12:14:52 +00:00
typedef enum {
STMT_INIT = 1,
STMT_PREPARE,
STMT_SETTBNAME,
2022-04-18 11:08:27 +00:00
STMT_SETTAGS,
2022-04-25 12:03:28 +00:00
STMT_FETCH_FIELDS,
2022-04-14 12:14:52 +00:00
STMT_BIND,
STMT_BIND_COL,
STMT_ADD_BATCH,
2022-04-18 05:22:47 +00:00
STMT_EXECUTE,
STMT_MAX,
2022-04-14 12:14:52 +00:00
} STMT_STATUS;
2024-05-30 05:26:17 +00:00
#define STMT_TABLE_COLS_NUM 1000
2022-04-16 07:59:19 +00:00
typedef struct SStmtTableCache {
2022-11-30 08:57:24 +00:00
STableDataCxt *pDataCtx;
void *boundTags;
2022-04-16 07:59:19 +00:00
} SStmtTableCache;
2022-04-28 09:09:21 +00:00
typedef struct SStmtQueryResInfo {
2022-10-13 06:37:03 +00:00
TAOS_FIELD *fields;
TAOS_FIELD *userFields;
uint32_t numOfCols;
int32_t precision;
2022-04-28 09:09:21 +00:00
} SStmtQueryResInfo;
2022-04-28 03:47:55 +00:00
2022-04-16 07:59:19 +00:00
typedef struct SStmtBindInfo {
2022-10-13 06:37:03 +00:00
bool needParse;
bool inExecCache;
uint64_t tbUid;
uint64_t tbSuid;
2024-05-30 05:26:17 +00:00
int32_t tbVgId;
2022-10-13 06:37:03 +00:00
int32_t sBindRowNum;
int32_t sBindLastIdx;
int8_t tbType;
bool tagsCached;
void *boundTags;
char tbName[TSDB_TABLE_FNAME_LEN];
char tbFName[TSDB_TABLE_FNAME_LEN];
char stbFName[TSDB_TABLE_FNAME_LEN];
SName sname;
2024-05-30 05:26:17 +00:00
char statbName[TSDB_TABLE_FNAME_LEN];
2022-04-16 07:59:19 +00:00
} SStmtBindInfo;
2022-04-15 12:10:51 +00:00
2024-05-30 05:26:17 +00:00
typedef struct SStmtAsyncParam {
STableColsData *pTbData;
void* pStmt;
} SStmtAsyncParam;
2022-04-16 07:59:19 +00:00
typedef struct SStmtExecInfo {
2022-12-03 06:56:51 +00:00
int32_t affectedRows;
SRequestObj *pRequest;
SHashObj *pBlockHash;
STableDataCxt *pCurrBlock;
SSubmitTbData *pCurrTbData;
2022-04-16 07:59:19 +00:00
} SStmtExecInfo;
2022-04-15 12:10:51 +00:00
2022-04-16 07:59:19 +00:00
typedef struct SStmtSQLInfo {
2024-05-30 05:26:17 +00:00
bool stbInterlaceMode;
2022-04-28 09:09:21 +00:00
STMT_TYPE type;
STMT_STATUS status;
2024-05-30 05:26:17 +00:00
uint64_t suid;
2022-04-28 09:09:21 +00:00
uint64_t runTimes;
2022-10-13 06:37:03 +00:00
SHashObj *pTableCache; // SHash<SStmtTableCache>
SQuery *pQuery;
char *sqlStr;
2022-04-28 09:09:21 +00:00
int32_t sqlLen;
2022-10-13 06:37:03 +00:00
SArray *nodeList;
2022-04-28 09:09:21 +00:00
SStmtQueryResInfo queryRes;
2022-05-11 03:44:09 +00:00
bool autoCreateTbl;
2022-10-13 06:37:03 +00:00
SHashObj *pVgHash;
2024-06-07 01:25:17 +00:00
SBindInfo *pBindInfo;
2024-05-30 05:26:17 +00:00
SStbInterlaceInfo siInfo;
2022-04-16 07:59:19 +00:00
} SStmtSQLInfo;
2024-05-30 05:26:17 +00:00
typedef struct SStmtStatInfo {
int64_t ctgGetTbMetaNum;
int64_t getCacheTbInfo;
int64_t parseSqlNum;
int64_t bindDataNum;
int64_t setTbNameUs;
int64_t bindDataUs1;
int64_t bindDataUs2;
int64_t bindDataUs3;
int64_t bindDataUs4;
int64_t addBatchUs;
int64_t execWaitUs;
int64_t execUseUs;
} SStmtStatInfo;
typedef struct SStmtQNode {
2024-06-07 05:50:57 +00:00
bool restoreTbCols;
2024-05-30 05:26:17 +00:00
STableColsData tblData;
struct SStmtQNode* next;
} SStmtQNode;
typedef struct SStmtQueue {
bool stopQueue;
SStmtQNode* head;
SStmtQNode* tail;
uint64_t qRemainNum;
} SStmtQueue;
2022-04-16 07:59:19 +00:00
typedef struct STscStmt {
2024-05-30 05:26:17 +00:00
STscObj *taos;
SCatalog *pCatalog;
int32_t affectedRows;
uint32_t seqId;
uint32_t seqIds[STMT_MAX];
bool bindThreadInUse;
TdThread bindThread;
TAOS_STMT_OPTIONS options;
bool stbInterlaceMode;
SStmtQueue queue;
SStmtSQLInfo sql;
SStmtExecInfo exec;
SStmtBindInfo bInfo;
int64_t reqid;
int32_t errCode;
SStmtStatInfo stat;
2022-04-13 09:52:26 +00:00
} STscStmt;
extern char *gStmtStatusStr[];
2022-11-03 12:08:30 +00:00
#define STMT_LOG_SEQ(n) \
do { \
(pStmt)->seqId++; \
(pStmt)->seqIds[n]++; \
STMT_DLOG("the %dth:%d %s", (pStmt)->seqIds[n], (pStmt)->seqId, gStmtStatusStr[n]); \
} while (0)
2022-04-25 12:03:28 +00:00
#define STMT_STATUS_NE(S) (pStmt->sql.status != STMT_##S)
#define STMT_STATUS_EQ(S) (pStmt->sql.status == STMT_##S)
2022-04-14 12:14:52 +00:00
2022-10-13 06:37:03 +00:00
#define STMT_ERR_RET(c) \
do { \
int32_t _code = c; \
if (_code != TSDB_CODE_SUCCESS) { \
terrno = _code; \
2023-04-04 00:54:28 +00:00
pStmt->errCode = _code; \
2022-10-13 06:37:03 +00:00
return _code; \
} \
} while (0)
#define STMT_RET(c) \
do { \
int32_t _code = c; \
if (_code != TSDB_CODE_SUCCESS) { \
terrno = _code; \
2023-04-04 00:54:28 +00:00
pStmt->errCode = _code; \
2022-10-13 06:37:03 +00:00
} \
return _code; \
} while (0)
#define STMT_ERR_JRET(c) \
do { \
code = c; \
if (code != TSDB_CODE_SUCCESS) { \
terrno = code; \
2023-04-04 00:54:28 +00:00
pStmt->errCode = code; \
2022-10-13 06:37:03 +00:00
goto _return; \
} \
} while (0)
2023-04-11 02:22:47 +00:00
#define STMT_ERRI_JRET(c) \
do { \
code = c; \
if (code != TSDB_CODE_SUCCESS) { \
terrno = code; \
goto _return; \
} \
} while (0)
2022-10-13 06:37:03 +00:00
2024-05-30 05:26:17 +00:00
#define STMT_FLOG(param, ...) qFatal("stmt:%p " param, pStmt, __VA_ARGS__)
#define STMT_ELOG(param, ...) qError("stmt:%p " param, pStmt, __VA_ARGS__)
#define STMT_DLOG(param, ...) qDebug("stmt:%p " param, pStmt, __VA_ARGS__)
#define STMT_ELOG_E(param) qError("stmt:%p " param, pStmt)
#define STMT_DLOG_E(param) qDebug("stmt:%p " param, pStmt)
2024-05-30 05:26:17 +00:00
TAOS_STMT *stmtInit(STscObj* taos, int64_t reqid, TAOS_STMT_OPTIONS* pOptions);
2022-10-13 06:37:03 +00:00
int stmtClose(TAOS_STMT *stmt);
int stmtExec(TAOS_STMT *stmt);
2022-04-18 02:19:15 +00:00
const char *stmtErrstr(TAOS_STMT *stmt);
2022-10-13 06:37:03 +00:00
int stmtAffectedRows(TAOS_STMT *stmt);
int stmtAffectedRowsOnce(TAOS_STMT *stmt);
int stmtPrepare(TAOS_STMT *stmt, const char *sql, unsigned long length);
2024-06-25 08:16:32 +00:00
int stmtSetDbName(TAOS_STMT* stmt, const char* dbName);
2022-10-13 06:37:03 +00:00
int stmtSetTbName(TAOS_STMT *stmt, const char *tbName);
int stmtSetTbTags(TAOS_STMT *stmt, TAOS_MULTI_BIND *tags);
int stmtGetTagFields(TAOS_STMT *stmt, int *nums, TAOS_FIELD_E **fields);
int stmtGetColFields(TAOS_STMT *stmt, int *nums, TAOS_FIELD_E **fields);
int stmtIsInsert(TAOS_STMT *stmt, int *insert);
int stmtGetParamNum(TAOS_STMT *stmt, int *nums);
int stmtGetParam(TAOS_STMT *stmt, int idx, int *type, int *bytes);
int stmtAddBatch(TAOS_STMT *stmt);
TAOS_RES *stmtUseResult(TAOS_STMT *stmt);
int stmtBindBatch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind, int32_t colIdx);
2022-04-13 09:52:26 +00:00
#ifdef __cplusplus
}
#endif
#endif // TDENGINE_CLIENTSTMT_H