clientStmt.h 2.8 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


D
stmt  
dapan1121 已提交
43
typedef struct STscStmt {
D
stmt  
dapan1121 已提交
44 45
  STMT_TYPE    type;
  STMT_STATUS  status;
D
stmt  
dapan1121 已提交
46 47
  bool         autoCreate;
  uint64_t     runTimes;
D
stmt  
dapan1121 已提交
48
  STscObj*     taos;
D
stmt  
dapan1121 已提交
49 50 51 52 53 54
  SCatalog*    pCatalog;
  SHashObj*    pTableDataBlocks;
  SHashObj*    pVgList;

  bool         tbNeedParse;
  bool         tbReuse;
D
stmt  
dapan1121 已提交
55 56 57 58 59
  SRequestObj* pRequest;
  SQuery*      pQuery;
  char*        sql;
  int32_t      sqlLen;
  char*        tbName;
D
stmt  
dapan1121 已提交
60
  SName        sname;
D
stmt  
dapan1121 已提交
61
  TAOS_BIND*   bindTags;
D
stmt  
dapan1121 已提交
62
  
D
stmt  
dapan1121 已提交
63 64
  //SMultiTbStmt mtb;
  //SNormalStmt normal;
D
stmt  
dapan1121 已提交
65

D
stmt  
dapan1121 已提交
66
  //int numOfRows;
D
stmt  
dapan1121 已提交
67 68
} STscStmt;

D
stmt  
dapan1121 已提交
69

D
stmt  
dapan1121 已提交
70 71 72 73
#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 已提交
74 75 76 77 78 79 80 81 82 83 84 85 86 87
#define STMT_CHK_STATUS(_stmt, _status, _v) do {
  switch (_status) {
    case STMT_INIT:
      if ((_stmt)->status != 0) return (_v);
      break;
    case STMT_PREPARE:
      if ((_stmt)->status != STMT_INIT) STMT_ERR_RET(_v);
      break;
    case STMT_SETTBNAME:
      break;
  }
} while (0)


D
stmt  
dapan1121 已提交
88 89 90 91 92 93 94 95 96 97 98 99 100 101
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 已提交
102 103 104 105 106 107

#ifdef __cplusplus
}
#endif

#endif  // TDENGINE_CLIENTSTMT_H