taos.h 8.0 KB
Newer Older
H
hzcheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * 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_TAOS_H
#define TDENGINE_TAOS_H

#include <stdint.h>
H
Haojun Liao 已提交
20
#include <stdbool.h>
H
hzcheng 已提交
21 22 23 24 25

#ifdef __cplusplus
extern "C" {
#endif

S
Shengliang Guan 已提交
26 27 28 29 30 31
typedef void   TAOS;
typedef void   TAOS_STMT;
typedef void   TAOS_RES;
typedef void   TAOS_STREAM;
typedef void   TAOS_SUB;
typedef void **TAOS_ROW;
H
hzcheng 已提交
32

H
hzcheng 已提交
33 34 35 36 37 38 39 40 41 42 43 44
// Data type definition
#define TSDB_DATA_TYPE_NULL       0     // 1 bytes
#define TSDB_DATA_TYPE_BOOL       1     // 1 bytes
#define TSDB_DATA_TYPE_TINYINT    2     // 1 byte
#define TSDB_DATA_TYPE_SMALLINT   3     // 2 bytes
#define TSDB_DATA_TYPE_INT        4     // 4 bytes
#define TSDB_DATA_TYPE_BIGINT     5     // 8 bytes
#define TSDB_DATA_TYPE_FLOAT      6     // 4 bytes
#define TSDB_DATA_TYPE_DOUBLE     7     // 8 bytes
#define TSDB_DATA_TYPE_BINARY     8     // string
#define TSDB_DATA_TYPE_TIMESTAMP  9     // 8 bytes
#define TSDB_DATA_TYPE_NCHAR      10    // unicode string
45 46 47 48
#define TSDB_DATA_TYPE_UTINYINT   11    // 1 byte
#define TSDB_DATA_TYPE_USMALLINT  12    // 2 bytes
#define TSDB_DATA_TYPE_UINT       13    // 4 bytes
#define TSDB_DATA_TYPE_UBIGINT    14    // 8 bytes
49
#define TSDB_DATA_TYPE_JSON       15    // json string
H
hzcheng 已提交
50

H
hzcheng 已提交
51 52 53 54 55 56 57 58 59
typedef enum {
  TSDB_OPTION_LOCALE,
  TSDB_OPTION_CHARSET,
  TSDB_OPTION_TIMEZONE,
  TSDB_OPTION_CONFIGDIR,
  TSDB_OPTION_SHELL_ACTIVITY_TIMER,
  TSDB_MAX_OPTIONS
} TSDB_OPTION;

S
slguan 已提交
60
typedef struct taosField {
B
Bomin Zhang 已提交
61
  char     name[65];
62
  uint8_t  type;
63
  int16_t  bytes;
H
hzcheng 已提交
64 65
} TAOS_FIELD;

wmmhello's avatar
wmmhello 已提交
66 67 68 69 70 71 72 73 74 75
typedef enum {
  SET_CONF_RET_SUCC = 0,
  SET_CONF_RET_ERR_PART = -1,
  SET_CONF_RET_ERR_INNER = -2,
  SET_CONF_RET_ERR_JSON_INVALID = -3,
  SET_CONF_RET_ERR_JSON_PARSE = -4,
  SET_CONF_RET_ERR_ONLY_ONCE = -5,
  SET_CONF_RET_ERR_TOO_LONG = -6
} SET_CONF_RET_CODE;

G
Ganlin Zhao 已提交
76
typedef enum {
G
Ganlin Zhao 已提交
77 78 79 80 81
  TSDB_SML_UNKNOWN_PROTOCOL = 0,
  TSDB_SML_LINE_PROTOCOL = 1,
  TSDB_SML_TELNET_PROTOCOL = 2,
  TSDB_SML_JSON_PROTOCOL = 3,
} TSDB_SML_PROTOCOL_TYPE;
G
Ganlin Zhao 已提交
82 83

typedef enum {
G
Ganlin Zhao 已提交
84 85 86 87 88 89 90 91
  TSDB_SML_TIMESTAMP_NOT_CONFIGURED = 0,
  TSDB_SML_TIMESTAMP_HOURS,
  TSDB_SML_TIMESTAMP_MINUTES,
  TSDB_SML_TIMESTAMP_SECONDS,
  TSDB_SML_TIMESTAMP_MILLI_SECONDS,
  TSDB_SML_TIMESTAMP_MICRO_SECONDS,
  TSDB_SML_TIMESTAMP_NANO_SECONDS,
} TSDB_SML_TIMESTAMP_TYPE;
G
Ganlin Zhao 已提交
92

wmmhello's avatar
wmmhello 已提交
93
#define RET_MSG_LENGTH 1024
wmmhello's avatar
wmmhello 已提交
94
typedef struct setConfRet {
wmmhello's avatar
wmmhello 已提交
95 96
  SET_CONF_RET_CODE retCode;
  char   retMsg[RET_MSG_LENGTH];
wmmhello's avatar
wmmhello 已提交
97 98
} setConfRet;

L
[#1054]  
lihui 已提交
99 100 101 102 103 104
#ifdef _TD_GO_DLL_
  #define DLL_EXPORT    __declspec(dllexport)
#else
  #define DLL_EXPORT 
#endif

D
fix bug  
dapan1121 已提交
105
DLL_EXPORT int  taos_init();
S
Shengliang Guan 已提交
106
DLL_EXPORT void  taos_cleanup(void);
L
[#1054]  
lihui 已提交
107
DLL_EXPORT int   taos_options(TSDB_OPTION option, const void *arg, ...);
wmmhello's avatar
wmmhello 已提交
108
DLL_EXPORT setConfRet   taos_set_config(const char *config);
L
[#1054]  
lihui 已提交
109
DLL_EXPORT TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port);
110
DLL_EXPORT TAOS *taos_connect_auth(const char *ip, const char *user, const char *auth, const char *db, uint16_t port);
L
[#1054]  
lihui 已提交
111
DLL_EXPORT void  taos_close(TAOS *taos);
S
slguan 已提交
112

F
freemine 已提交
113 114
const char *taos_data_type(int type);

S
slguan 已提交
115 116 117
typedef struct TAOS_BIND {
  int            buffer_type;
  void *         buffer;
118 119
  uintptr_t      buffer_length;  // unused
  uintptr_t      *length;
S
slguan 已提交
120
  int *          is_null;
D
fix bug  
dapan1121 已提交
121

S
slguan 已提交
122 123
  int            is_unsigned;  // unused
  int *          error;        // unused
F
freemine 已提交
124 125 126 127 128 129 130 131 132 133 134 135 136
  union {
    int64_t        ts;
    int8_t         b;
    int8_t         v1;
    int16_t        v2;
    int32_t        v4;
    int64_t        v8;
    float          f4;
    double         f8;
    unsigned char *bin;
    char          *nchar;
  } u;
  unsigned int     allocated;
S
slguan 已提交
137 138
} TAOS_BIND;

D
fix bug  
dapan1121 已提交
139 140
typedef struct TAOS_MULTI_BIND {
  int            buffer_type;
H
Haojun Liao 已提交
141 142
  void          *buffer;
  uintptr_t      buffer_length;
143 144
  int32_t       *length;
  char          *is_null;
D
fix bug  
dapan1121 已提交
145 146 147
  int            num;
} TAOS_MULTI_BIND;

148 149 150 151
DLL_EXPORT TAOS_STMT *taos_stmt_init(TAOS *taos);
DLL_EXPORT int        taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsigned long length);
DLL_EXPORT int        taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags);
DLL_EXPORT int        taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name);
152
DLL_EXPORT int        taos_stmt_set_sub_tbname(TAOS_STMT* stmt, const char* name);
S
Shengliang Guan 已提交
153

154 155
DLL_EXPORT int        taos_stmt_is_insert(TAOS_STMT *stmt, int *insert);
DLL_EXPORT int        taos_stmt_num_params(TAOS_STMT *stmt, int *nums);
S
Shengliang Guan 已提交
156
DLL_EXPORT int        taos_stmt_get_param(TAOS_STMT *stmt, int idx, int *type, int *bytes);
157
DLL_EXPORT int        taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_BIND *bind);
S
Shengliang Guan 已提交
158 159
DLL_EXPORT int        taos_stmt_bind_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind);
DLL_EXPORT int        taos_stmt_bind_single_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind, int colIdx);
160 161
DLL_EXPORT int        taos_stmt_add_batch(TAOS_STMT *stmt);
DLL_EXPORT int        taos_stmt_execute(TAOS_STMT *stmt);
162
DLL_EXPORT int        taos_stmt_affected_rows(TAOS_STMT *stmt);
163 164 165
DLL_EXPORT TAOS_RES * taos_stmt_use_result(TAOS_STMT *stmt);
DLL_EXPORT int        taos_stmt_close(TAOS_STMT *stmt);
DLL_EXPORT char *     taos_stmt_errstr(TAOS_STMT *stmt);
S
slguan 已提交
166

H
Haojun Liao 已提交
167
DLL_EXPORT TAOS_RES *taos_query(TAOS *taos, const char *sql);
L
[#1054]  
lihui 已提交
168 169 170
DLL_EXPORT TAOS_ROW taos_fetch_row(TAOS_RES *res);
DLL_EXPORT int taos_result_precision(TAOS_RES *res);  // get the time precision of result
DLL_EXPORT void taos_free_result(TAOS_RES *res);
H
Haojun Liao 已提交
171
DLL_EXPORT int taos_field_count(TAOS_RES *res);
L
[#1054]  
lihui 已提交
172
DLL_EXPORT int taos_num_fields(TAOS_RES *res);
173
DLL_EXPORT int taos_affected_rows(TAOS_RES *res);
L
[#1054]  
lihui 已提交
174 175 176 177
DLL_EXPORT TAOS_FIELD *taos_fetch_fields(TAOS_RES *res);
DLL_EXPORT int taos_select_db(TAOS *taos, const char *db);
DLL_EXPORT int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields);
DLL_EXPORT void taos_stop_query(TAOS_RES *res);
H
Haojun Liao 已提交
178
DLL_EXPORT bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col);
179
DLL_EXPORT bool taos_is_update_query(TAOS_RES *res);
180 181
DLL_EXPORT int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows);
DLL_EXPORT int* taos_fetch_lengths(TAOS_RES *res);
182
DLL_EXPORT TAOS_ROW *taos_result_block(TAOS_RES *res);
183

184 185 186
DLL_EXPORT int taos_validate_sql(TAOS *taos, const char *sql);
DLL_EXPORT void taos_reset_current_db(TAOS *taos);

H
hzcheng 已提交
187 188 189
// TAOS_RES   *taos_list_tables(TAOS *mysql, const char *wild);
// TAOS_RES   *taos_list_dbs(TAOS *mysql, const char *wild);

S
slguan 已提交
190
// TODO: the return value should be `const`
L
[#1054]  
lihui 已提交
191 192
DLL_EXPORT char *taos_get_server_info(TAOS *taos);
DLL_EXPORT char *taos_get_client_info();
H
Haojun Liao 已提交
193
DLL_EXPORT char *taos_errstr(TAOS_RES *tres);
S
slguan 已提交
194

H
Haojun Liao 已提交
195
DLL_EXPORT int taos_errno(TAOS_RES *tres);
H
hzcheng 已提交
196

L
[#1054]  
lihui 已提交
197 198
DLL_EXPORT void taos_query_a(TAOS *taos, const char *sql, void (*fp)(void *param, TAOS_RES *, int code), void *param);
DLL_EXPORT void taos_fetch_rows_a(TAOS_RES *res, void (*fp)(void *param, TAOS_RES *, int numOfRows), void *param);
H
hzcheng 已提交
199

weixin_48148422's avatar
weixin_48148422 已提交
200
typedef void (*TAOS_SUBSCRIBE_CALLBACK)(TAOS_SUB* tsub, TAOS_RES *res, void* param, int code);
weixin_48148422's avatar
weixin_48148422 已提交
201
DLL_EXPORT TAOS_SUB *taos_subscribe(TAOS* taos, int restart, const char* topic, const char *sql, TAOS_SUBSCRIBE_CALLBACK fp, void *param, int interval);
weixin_48148422's avatar
weixin_48148422 已提交
202
DLL_EXPORT TAOS_RES *taos_consume(TAOS_SUB *tsub);
weixin_48148422's avatar
weixin_48148422 已提交
203
DLL_EXPORT void      taos_unsubscribe(TAOS_SUB *tsub, int keepProgress);
H
hzcheng 已提交
204

L
[#1054]  
lihui 已提交
205
DLL_EXPORT TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sql, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row),
H
hzcheng 已提交
206
                              int64_t stime, void *param, void (*callback)(void *));
L
[#1054]  
lihui 已提交
207
DLL_EXPORT void taos_close_stream(TAOS_STREAM *tstr);
H
hzcheng 已提交
208

L
[#1054]  
lihui 已提交
209
DLL_EXPORT int taos_load_table_info(TAOS *taos, const char* tableNameList);
S
slguan 已提交
210

G
Ganlin Zhao 已提交
211
DLL_EXPORT TAOS_RES *taos_schemaless_insert(TAOS* taos, char* lines[], int numLines, int protocol, int precision);
212

213 214
DLL_EXPORT int32_t taos_parse_time(char* timestr, int64_t* time, int32_t len, int32_t timePrec, int8_t dayligth);

H
hzcheng 已提交
215 216 217 218 219
#ifdef __cplusplus
}
#endif

#endif