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

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

#ifdef __cplusplus
extern "C" {
#endif

S
Shengliang Guan 已提交
26 27 28
typedef void   TAOS;
typedef void   TAOS_STMT;
typedef void   TAOS_RES;
L
Liu Jicong 已提交
29 30
typedef void **TAOS_ROW;
#if 0
S
Shengliang Guan 已提交
31
typedef void   TAOS_STREAM;
L
Liu Jicong 已提交
32
#endif
33
typedef void   TAOS_SUB;
H
hzcheng 已提交
34

H
hzcheng 已提交
35
// Data type definition
L
Liu Jicong 已提交
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
#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_VARCHAR    8   // string, alias for varchar
#define TSDB_DATA_TYPE_TIMESTAMP  9   // 8 bytes
#define TSDB_DATA_TYPE_NCHAR      10  // unicode string
#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
#define TSDB_DATA_TYPE_JSON       15  // json string
#define TSDB_DATA_TYPE_VARBINARY  16  // binary
#define TSDB_DATA_TYPE_DECIMAL    17  // decimal
#define TSDB_DATA_TYPE_BLOB       18  // binary
H
Haojun Liao 已提交
55
#define TSDB_DATA_TYPE_MEDIUMBLOB 19
L
Liu Jicong 已提交
56
#define TSDB_DATA_TYPE_BINARY     TSDB_DATA_TYPE_VARCHAR  // string
H
hzcheng 已提交
57

H
hzcheng 已提交
58 59 60 61 62 63 64 65 66
typedef enum {
  TSDB_OPTION_LOCALE,
  TSDB_OPTION_CHARSET,
  TSDB_OPTION_TIMEZONE,
  TSDB_OPTION_CONFIGDIR,
  TSDB_OPTION_SHELL_ACTIVITY_TIMER,
  TSDB_MAX_OPTIONS
} TSDB_OPTION;

H
Haojun Liao 已提交
67 68
typedef enum {
  TSDB_SML_UNKNOWN_PROTOCOL = 0,
L
Liu Jicong 已提交
69 70 71
  TSDB_SML_LINE_PROTOCOL = 1,
  TSDB_SML_TELNET_PROTOCOL = 2,
  TSDB_SML_JSON_PROTOCOL = 3,
H
Haojun Liao 已提交
72 73 74 75 76 77 78 79 80 81 82 83
} TSDB_SML_PROTOCOL_TYPE;

typedef enum {
  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;

S
slguan 已提交
84
typedef struct taosField {
L
Liu Jicong 已提交
85 86 87
  char    name[65];
  int8_t  type;
  int32_t bytes;
H
hzcheng 已提交
88 89
} TAOS_FIELD;

L
Liu Jicong 已提交
90
#define DLL_EXPORT
L
[#1054]  
lihui 已提交
91

92 93
typedef void (*__taos_async_fn_t)(void *param, TAOS_RES *, int code);

S
slguan 已提交
94
typedef struct TAOS_BIND {
L
Liu Jicong 已提交
95 96 97 98 99 100 101 102
  int        buffer_type;
  void      *buffer;
  uintptr_t  buffer_length;  // unused
  uintptr_t *length;
  int       *is_null;

  int  is_unsigned;  // unused
  int *error;        // unused
F
freemine 已提交
103 104 105 106 107 108 109 110 111 112 113 114
  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;
L
Liu Jicong 已提交
115
  unsigned int allocated;
S
slguan 已提交
116 117
} TAOS_BIND;

D
fix bug  
dapan1121 已提交
118
typedef struct TAOS_MULTI_BIND {
L
Liu Jicong 已提交
119 120 121 122 123 124
  int       buffer_type;
  void     *buffer;
  uintptr_t buffer_length;
  int32_t  *length;
  char     *is_null;
  int       num;
D
fix bug  
dapan1121 已提交
125 126
} TAOS_MULTI_BIND;

127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
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;

#define RET_MSG_LENGTH 1024
typedef struct setConfRet {
  SET_CONF_RET_CODE retCode;
  char   retMsg[RET_MSG_LENGTH];
} setConfRet;

143 144
DLL_EXPORT void  taos_cleanup(void);
DLL_EXPORT int   taos_options(TSDB_OPTION option, const void *arg, ...);
145
DLL_EXPORT setConfRet   taos_set_config(const char *config);
146
DLL_EXPORT TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port);
L
Liu Jicong 已提交
147 148
DLL_EXPORT TAOS *taos_connect_l(const char *ip, int ipLen, const char *user, int userLen, const char *pass, int passLen,
                                const char *db, int dbLen, uint16_t port);
149 150 151 152 153
DLL_EXPORT TAOS *taos_connect_auth(const char *ip, const char *user, const char *auth, const char *db, uint16_t port);
DLL_EXPORT void  taos_close(TAOS *taos);

const char *taos_data_type(int type);

154 155
DLL_EXPORT TAOS_STMT *taos_stmt_init(TAOS *taos);
DLL_EXPORT int        taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsigned long length);
L
Liu Jicong 已提交
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
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);
DLL_EXPORT int        taos_stmt_set_sub_tbname(TAOS_STMT *stmt, const char *name);

DLL_EXPORT int       taos_stmt_is_insert(TAOS_STMT *stmt, int *insert);
DLL_EXPORT int       taos_stmt_num_params(TAOS_STMT *stmt, int *nums);
DLL_EXPORT int       taos_stmt_get_param(TAOS_STMT *stmt, int idx, int *type, int *bytes);
DLL_EXPORT int       taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_BIND *bind);
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);
DLL_EXPORT int       taos_stmt_add_batch(TAOS_STMT *stmt);
DLL_EXPORT int       taos_stmt_execute(TAOS_STMT *stmt);
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);
L
Liu Jicong 已提交
171
DLL_EXPORT int       taos_stmt_affected_rows(TAOS_STMT *stmt);
S
slguan 已提交
172

H
Haojun Liao 已提交
173
DLL_EXPORT TAOS_RES *taos_query(TAOS *taos, const char *sql);
H
Haojun Liao 已提交
174
DLL_EXPORT TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen);
H
Haojun Liao 已提交
175

L
[#1054]  
lihui 已提交
176
DLL_EXPORT TAOS_ROW taos_fetch_row(TAOS_RES *res);
L
Liu Jicong 已提交
177 178 179 180 181
DLL_EXPORT int      taos_result_precision(TAOS_RES *res);  // get the time precision of result
DLL_EXPORT void     taos_free_result(TAOS_RES *res);
DLL_EXPORT int      taos_field_count(TAOS_RES *res);
DLL_EXPORT int      taos_num_fields(TAOS_RES *res);
DLL_EXPORT int      taos_affected_rows(TAOS_RES *res);
H
Haojun Liao 已提交
182

L
[#1054]  
lihui 已提交
183
DLL_EXPORT TAOS_FIELD *taos_fetch_fields(TAOS_RES *res);
L
Liu Jicong 已提交
184 185 186 187
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);
DLL_EXPORT bool        taos_is_null(TAOS_RES *res, int32_t row, int32_t col);
188
DLL_EXPORT bool        taos_is_update_query(TAOS_RES *res);
L
Liu Jicong 已提交
189 190
DLL_EXPORT int         taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows);
DLL_EXPORT int         taos_validate_sql(TAOS *taos, const char *sql);
191
DLL_EXPORT void taos_reset_current_db(TAOS *taos);
H
hzcheng 已提交
192

L
Liu Jicong 已提交
193
DLL_EXPORT int *taos_fetch_lengths(TAOS_RES *res);
194
DLL_EXPORT TAOS_ROW *taos_result_block(TAOS_RES *res);
195

196 197
DLL_EXPORT const char *taos_get_server_info(TAOS *taos);
DLL_EXPORT const char *taos_get_client_info();
S
slguan 已提交
198

H
Haojun Liao 已提交
199
DLL_EXPORT const char *taos_errstr(TAOS_RES *tres);
L
Liu Jicong 已提交
200
DLL_EXPORT int         taos_errno(TAOS_RES *tres);
H
hzcheng 已提交
201

202 203
DLL_EXPORT void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param);
DLL_EXPORT void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param);
H
hzcheng 已提交
204

205 206
// Shuduo: temporary enable for app build
#if 1
L
Liu Jicong 已提交
207 208 209
typedef void (*__taos_sub_fn_t)(TAOS_SUB *tsub, TAOS_RES *res, void *param, int code);
DLL_EXPORT TAOS_SUB *taos_subscribe(TAOS *taos, int restart, const char *topic, const char *sql, __taos_sub_fn_t fp,
                                    void *param, int interval);
weixin_48148422's avatar
weixin_48148422 已提交
210
DLL_EXPORT TAOS_RES *taos_consume(TAOS_SUB *tsub);
weixin_48148422's avatar
weixin_48148422 已提交
211
DLL_EXPORT void      taos_unsubscribe(TAOS_SUB *tsub, int keepProgress);
212
#endif
H
hzcheng 已提交
213

214
#if 0
L
[#1054]  
lihui 已提交
215
DLL_EXPORT TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sql, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row),
L
Liu Jicong 已提交
216 217
                                         int64_t stime, void *param, void (*callback)(void *));
DLL_EXPORT void         taos_close_stream(TAOS_STREAM *tstr);
L
Liu Jicong 已提交
218
#endif
H
hzcheng 已提交
219

L
Liu Jicong 已提交
220 221
DLL_EXPORT int       taos_load_table_info(TAOS *taos, const char *tableNameList);
DLL_EXPORT TAOS_RES *taos_schemaless_insert(TAOS *taos, char *lines[], int numLines, int protocol, int precision);
L
Liu Jicong 已提交
222

L
Liu Jicong 已提交
223
/* --------------------------TMQ INTERFACE------------------------------- */
L
Liu Jicong 已提交
224 225

enum tmq_resp_err_t {
L
Liu Jicong 已提交
226
  TMQ_RESP_ERR__FAIL = -1,
L
Liu Jicong 已提交
227 228 229 230 231
  TMQ_RESP_ERR__SUCCESS = 0,
};

typedef enum tmq_resp_err_t tmq_resp_err_t;

L
Liu Jicong 已提交
232 233
typedef struct tmq_t                   tmq_t;
typedef struct tmq_topic_vgroup_t      tmq_topic_vgroup_t;
L
Liu Jicong 已提交
234 235
typedef struct tmq_topic_vgroup_list_t tmq_topic_vgroup_list_t;

L
Liu Jicong 已提交
236 237 238
typedef struct tmq_conf_t    tmq_conf_t;
typedef struct tmq_list_t    tmq_list_t;
typedef struct tmq_message_t tmq_message_t;
L
Liu Jicong 已提交
239

L
Liu Jicong 已提交
240
typedef void(tmq_commit_cb(tmq_t *, tmq_resp_err_t, tmq_topic_vgroup_list_t *, void *param));
L
Liu Jicong 已提交
241

L
Liu Jicong 已提交
242
DLL_EXPORT tmq_list_t *tmq_list_new();
L
Liu Jicong 已提交
243
DLL_EXPORT int32_t     tmq_list_append(tmq_list_t *, const char *);
L
Liu Jicong 已提交
244
DLL_EXPORT void        tmq_list_destroy(tmq_list_t *);
L
Liu Jicong 已提交
245

L
Liu Jicong 已提交
246 247 248 249 250 251
// will be removed in 3.0
DLL_EXPORT tmq_t *tmq_consumer_new(void *conn, tmq_conf_t *conf, char *errstr, int32_t errstrLen);

// will replace last one
DLL_EXPORT tmq_t *tmq_consumer_new1(tmq_conf_t *conf, char *errstr, int32_t errstrLen);

L
Liu Jicong 已提交
252
DLL_EXPORT const char *tmq_err2str(tmq_resp_err_t);
L
Liu Jicong 已提交
253

L
Liu Jicong 已提交
254
/* ------------------------TMQ CONSUMER INTERFACE------------------------ */
L
Liu Jicong 已提交
255
DLL_EXPORT tmq_resp_err_t tmq_subscribe(tmq_t *tmq, tmq_list_t *topic_list);
L
Liu Jicong 已提交
256 257
DLL_EXPORT tmq_resp_err_t tmq_unsubscribe(tmq_t *tmq);
DLL_EXPORT tmq_resp_err_t tmq_subscription(tmq_t *tmq, tmq_list_t **topics);
L
Liu Jicong 已提交
258
DLL_EXPORT tmq_message_t *tmq_consumer_poll(tmq_t *tmq, int64_t blocking_time);
L
Liu Jicong 已提交
259
DLL_EXPORT tmq_resp_err_t tmq_consumer_close(tmq_t *tmq);
L
Liu Jicong 已提交
260
#if 0
L
Liu Jicong 已提交
261 262 263
DLL_EXPORT tmq_resp_err_t tmq_assign(tmq_t* tmq, const tmq_topic_vgroup_list_t* vgroups);
DLL_EXPORT tmq_resp_err_t tmq_assignment(tmq_t* tmq, tmq_topic_vgroup_list_t** vgroups);
#endif
L
Liu Jicong 已提交
264
DLL_EXPORT tmq_resp_err_t tmq_commit(tmq_t *tmq, const tmq_topic_vgroup_list_t *offsets, int32_t async);
L
Liu Jicong 已提交
265 266 267
#if 0
DLL_EXPORT tmq_resp_err_t tmq_commit_message(tmq_t* tmq, const tmq_message_t* tmqmessage, int32_t async);
#endif
L
Liu Jicong 已提交
268
DLL_EXPORT tmq_resp_err_t tmq_seek(tmq_t *tmq, const tmq_topic_vgroup_t *offset);
L
Liu Jicong 已提交
269 270 271 272 273 274 275 276 277 278
/* ----------------------TMQ CONFIGURATION INTERFACE---------------------- */

enum tmq_conf_res_t {
  TMQ_CONF_UNKNOWN = -2,
  TMQ_CONF_INVALID = -1,
  TMQ_CONF_OK = 0,
};

typedef enum tmq_conf_res_t tmq_conf_res_t;

L
Liu Jicong 已提交
279 280
DLL_EXPORT tmq_conf_t    *tmq_conf_new();
DLL_EXPORT tmq_conf_res_t tmq_conf_set(tmq_conf_t *conf, const char *key, const char *value);
L
Liu Jicong 已提交
281
DLL_EXPORT void           tmq_conf_destroy(tmq_conf_t *conf);
L
Liu Jicong 已提交
282 283
DLL_EXPORT void           tmq_conf_set_offset_commit_cb(tmq_conf_t *conf, tmq_commit_cb *cb);

L
Liu Jicong 已提交
284 285 286
// temporary used function for demo only
void    tmqShowMsg(tmq_message_t *tmq_message);
int32_t tmqGetSkipLogNum(tmq_message_t *tmq_message);
L
Liu Jicong 已提交
287

L
Liu Jicong 已提交
288
/* -------------------------TMQ MSG HANDLE INTERFACE---------------------- */
289

L
Liu Jicong 已提交
290 291 292 293 294 295 296 297
DLL_EXPORT TAOS_ROW    tmq_get_row(tmq_message_t *message);
DLL_EXPORT char       *tmq_get_topic_name(tmq_message_t *message);
DLL_EXPORT int32_t     tmq_get_vgroup_id(tmq_message_t *message);
DLL_EXPORT int64_t     tmq_get_request_offset(tmq_message_t *message);
DLL_EXPORT int64_t     tmq_get_response_offset(tmq_message_t *message);
DLL_EXPORT TAOS_FIELD *tmq_get_fields(tmq_t *tmq, const char *topic);
DLL_EXPORT int32_t     tmq_field_count(tmq_t *tmq, const char *topic);
DLL_EXPORT void        tmq_message_destroy(tmq_message_t *tmq_message);
L
Liu Jicong 已提交
298

L
Liu Jicong 已提交
299
/* --------------------TMPORARY INTERFACE FOR TESTING--------------------- */
L
Liu Jicong 已提交
300
#if 0
L
Liu Jicong 已提交
301
DLL_EXPORT TAOS_RES *tmq_create_topic(TAOS *taos, const char *name, const char *sql, int sqlLen);
L
Liu Jicong 已提交
302
#endif
L
Liu Jicong 已提交
303 304 305

DLL_EXPORT TAOS_RES *tmq_create_stream(TAOS *taos, const char *streamName, const char *tbName, const char *sql);

L
Liu Jicong 已提交
306
/* ------------------------------ TMQ END -------------------------------- */
307
#if 1 // Shuduo: temporary enable for app build
L
Liu Jicong 已提交
308
typedef void (*TAOS_SUBSCRIBE_CALLBACK)(TAOS_SUB *tsub, TAOS_RES *res, void *param, int code);
L
Liu Jicong 已提交
309
#endif
310

H
hzcheng 已提交
311 312 313 314 315
#ifdef __cplusplus
}
#endif

#endif