clientStmt.h 3.6 KB
Newer Older
D
stmt  
dapan1121 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * 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
D
stmt  
dapan1121 已提交
22 23 24
#include "catalog.h"

typedef void STableDataBlocks;
D
stmt  
dapan1121 已提交
25 26 27 28

typedef enum {
  STMT_TYPE_INSERT = 1,
  STMT_TYPE_MULTI_INSERT,
D
stmt  
dapan1121 已提交
29
  STMT_TYPE_QUERY,
D
stmt  
dapan1121 已提交
30 31
} STMT_TYPE;

D
stmt  
dapan1121 已提交
32 33 34 35
typedef enum {
  STMT_INIT = 1,
  STMT_PREPARE,
  STMT_SETTBNAME,
D
stmt  
dapan1121 已提交
36
  STMT_SETTAGS,
D
dapan1121 已提交
37
  STMT_FETCH_FIELDS,
D
stmt  
dapan1121 已提交
38 39 40
  STMT_BIND,
  STMT_BIND_COL,
  STMT_ADD_BATCH,
D
stmt  
dapan1121 已提交
41
  STMT_EXECUTE,
D
stmt  
dapan1121 已提交
42 43
} STMT_STATUS;

D
stmt  
dapan1121 已提交
44 45 46 47 48
typedef struct SStmtTableCache {
  STableDataBlocks* pDataBlock;
  void*             boundTags;
} SStmtTableCache;

D
dapan1121 已提交
49
typedef struct SStmtQueryResInfo {
D
dapan1121 已提交
50 51 52
  TAOS_FIELD*    fields;
  TAOS_FIELD*    userFields;
  uint32_t       numOfCols;
D
dapan1121 已提交
53 54
  int32_t        precision;
} SStmtQueryResInfo;
D
dapan1121 已提交
55

D
stmt  
dapan1121 已提交
56 57
typedef struct SStmtBindInfo {
  bool         needParse;
D
dapan 已提交
58
  bool         inExecCache;
D
stmt  
dapan1121 已提交
59 60
  uint64_t     tbUid;
  uint64_t     tbSuid;
D
stmt  
dapan1121 已提交
61 62
  int32_t      sBindRowNum;
  int32_t      sBindLastIdx;
D
stmt  
dapan1121 已提交
63
  int8_t       tbType;
D
dapan1121 已提交
64
  bool         tagsCached;
D
stmt  
dapan1121 已提交
65
  void*        boundTags;  
66
  char         tbName[TSDB_TABLE_FNAME_LEN];
D
dapan 已提交
67
  char         tbFName[TSDB_TABLE_FNAME_LEN];
D
dapan 已提交
68
  char         stbFName[TSDB_TABLE_FNAME_LEN];
D
stmt  
dapan1121 已提交
69 70
  SName        sname;
} SStmtBindInfo;
D
stmt  
dapan1121 已提交
71

D
stmt  
dapan1121 已提交
72
typedef struct SStmtExecInfo {
D
dapan1121 已提交
73
  int32_t      affectedRows;
D
stmt  
dapan1121 已提交
74 75 76
  SRequestObj* pRequest;
  SHashObj*    pVgHash;
  SHashObj*    pBlockHash;
D
dapan 已提交
77
  bool         autoCreateTbl;
D
stmt  
dapan1121 已提交
78
} SStmtExecInfo;
D
stmt  
dapan1121 已提交
79

D
stmt  
dapan1121 已提交
80
typedef struct SStmtSQLInfo {
D
dapan1121 已提交
81 82 83 84 85 86 87 88 89
  STMT_TYPE         type;
  STMT_STATUS       status;
  uint64_t          runTimes;
  SHashObj*         pTableCache;   //SHash<SStmtTableCache>
  SQuery*           pQuery;
  char*             sqlStr;
  int32_t           sqlLen;
  SArray*           nodeList;
  SStmtQueryResInfo queryRes;
D
dapan 已提交
90
  bool              autoCreateTbl;
D
stmt  
dapan1121 已提交
91 92 93 94 95
} SStmtSQLInfo;

typedef struct STscStmt {
  STscObj*      taos;
  SCatalog*     pCatalog;
D
stmt  
dapan1121 已提交
96
  int32_t       affectedRows;
D
stmt  
dapan1121 已提交
97 98 99

  SStmtSQLInfo  sql;
  SStmtExecInfo exec;
D
stmt  
dapan1121 已提交
100
  SStmtBindInfo bInfo;
D
stmt  
dapan1121 已提交
101 102
} STscStmt;

D
dapan1121 已提交
103 104
#define STMT_STATUS_NE(S) (pStmt->sql.status != STMT_##S)
#define STMT_STATUS_EQ(S) (pStmt->sql.status == STMT_##S)
D
stmt  
dapan1121 已提交
105

D
stmt  
dapan1121 已提交
106 107 108 109 110 111 112
#define STMT_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0)
#define STMT_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0)
#define STMT_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0)

TAOS_STMT *stmtInit(TAOS *taos);
int stmtClose(TAOS_STMT *stmt);
int stmtExec(TAOS_STMT *stmt);
D
stmt  
dapan1121 已提交
113
const char *stmtErrstr(TAOS_STMT *stmt);
D
stmt  
dapan1121 已提交
114
int stmtAffectedRows(TAOS_STMT *stmt);
D
dapan1121 已提交
115
int stmtAffectedRowsOnce(TAOS_STMT *stmt);
D
stmt  
dapan1121 已提交
116
int stmtPrepare(TAOS_STMT *stmt, const char *sql, unsigned long length);
D
stmt  
dapan1121 已提交
117
int stmtSetTbName(TAOS_STMT *stmt, const char *tbName);
D
dapan1121 已提交
118
int stmtSetTbTags(TAOS_STMT *stmt, TAOS_MULTI_BIND *tags);
D
stmt  
dapan1121 已提交
119 120 121 122
int stmtIsInsert(TAOS_STMT *stmt, int *insert);
int stmtGetParamNum(TAOS_STMT *stmt, int *nums);
int stmtAddBatch(TAOS_STMT *stmt);
TAOS_RES *stmtUseResult(TAOS_STMT *stmt);
D
dapan1121 已提交
123
int stmtBindBatch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind, int32_t colIdx);
D
stmt  
dapan1121 已提交
124

D
stmt  
dapan1121 已提交
125 126 127 128 129 130

#ifdef __cplusplus
}
#endif

#endif  // TDENGINE_CLIENTSTMT_H