clientStmt.h 3.2 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 22 23 24 25 26 27 28
/*
 * 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

typedef enum {
  STMT_TYPE_INSERT = 1,
  STMT_TYPE_MULTI_INSERT,
  STMT_TYPE_QUERY,
} STMT_TYPE;

D
stmt  
dapan1121 已提交
29 30 31 32
typedef enum {
  STMT_INIT = 1,
  STMT_PREPARE,
  STMT_SETTBNAME,
D
stmt  
dapan1121 已提交
33 34
  STMT_FETCH_TAG_FIELDS,
  STMT_FETCH_COL_FIELDS,
D
stmt  
dapan1121 已提交
35 36 37 38 39 40
  STMT_BIND,
  STMT_BIND_COL,
  STMT_ADD_BATCH,
  STMT_EXECUTE
} STMT_STATUS;

D
stmt  
dapan1121 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54
typedef struct SStmtTableCache {
  STableDataBlocks* pDataBlock;
  void*             boundTags;
} SStmtTableCache;

typedef struct SStmtBindInfo {
  bool         needParse;
  uint64_t     tbUid;
  uint64_t     tbSuid;
  int8_t       tbType;
  void*        boundTags;  
  char*        tbName;
  SName        sname;
} SStmtBindInfo;
D
stmt  
dapan1121 已提交
55

D
stmt  
dapan1121 已提交
56 57 58 59 60
typedef struct SStmtExecInfo {
  SRequestObj* pRequest;
  SHashObj*    pVgHash;
  SHashObj*    pBlockHash;
} SStmtExecInfo;
D
stmt  
dapan1121 已提交
61

D
stmt  
dapan1121 已提交
62
typedef struct SStmtSQLInfo {
D
stmt  
dapan1121 已提交
63 64
  STMT_TYPE    type;
  STMT_STATUS  status;
D
stmt  
dapan1121 已提交
65 66
  bool         autoCreate;
  uint64_t     runTimes;
D
stmt  
dapan1121 已提交
67
  SHashObj*    pTableCache;   //SHash<SStmtTableCache>
D
stmt  
dapan1121 已提交
68
  SQuery*      pQuery;
D
stmt  
dapan1121 已提交
69
  char*        sqlStr;
D
stmt  
dapan1121 已提交
70
  int32_t      sqlLen;
D
stmt  
dapan1121 已提交
71 72 73 74 75 76 77 78 79
} SStmtSQLInfo;

typedef struct STscStmt {
  STscObj*      taos;
  SCatalog*     pCatalog;

  SStmtSQLInfo  sql;
  SStmtExecInfo exec;
  SStmtBindInfo bind;
D
stmt  
dapan1121 已提交
80 81
} STscStmt;

D
stmt  
dapan1121 已提交
82

D
stmt  
dapan1121 已提交
83 84 85 86
#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)

D
stmt  
dapan1121 已提交
87 88
#define STMT_SWITCH_STATUS(_stmt, _newstatus, _errcode) do {
  switch (_newstatus) {
D
stmt  
dapan1121 已提交
89
    case STMT_INIT:
D
stmt  
dapan1121 已提交
90
      if ((_stmt)->status != 0) return (_errcode);
D
stmt  
dapan1121 已提交
91 92
      break;
    case STMT_PREPARE:
D
stmt  
dapan1121 已提交
93
      if ((_stmt)->status != STMT_INIT) STMT_ERR_RET(_errcode);
D
stmt  
dapan1121 已提交
94 95 96
      break;
    case STMT_SETTBNAME:
      break;
D
stmt  
dapan1121 已提交
97 98 99
    default:
      STMT_ERR_RET(_errcode);
      break;
D
stmt  
dapan1121 已提交
100 101 102 103
  }
} while (0)


D
stmt  
dapan1121 已提交
104 105 106 107 108 109 110 111 112 113 114 115 116 117
TAOS_STMT *stmtInit(TAOS *taos);
int stmtClose(TAOS_STMT *stmt);
int stmtExec(TAOS_STMT *stmt);
char *stmtErrstr(TAOS_STMT *stmt);
int stmtAffectedRows(TAOS_STMT *stmt);
int stmtBind(TAOS_STMT *stmt, TAOS_BIND *bind);
int stmtPrepare(TAOS_STMT *stmt, const char *sql, unsigned long length);
int stmtSetTbNameTags(TAOS_STMT *stmt, const char *name, TAOS_BIND *tags);
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);
int stmtBindBatch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind);

D
stmt  
dapan1121 已提交
118 119 120 121 122 123

#ifdef __cplusplus
}
#endif

#endif  // TDENGINE_CLIENTSTMT_H