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

#ifdef __cplusplus
extern "C" {
#endif

S
slguan 已提交
25 26 27 28 29 30
typedef void    TAOS;
typedef void**  TAOS_ROW;
typedef void    TAOS_RES;
typedef void    TAOS_SUB;
typedef void    TAOS_STREAM;
typedef void    TAOS_STMT;
H
hzcheng 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

#define TSDB_DATA_TYPE_NULL       0
#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    // multibyte string

typedef enum {
  TSDB_OPTION_LOCALE,
  TSDB_OPTION_CHARSET,
  TSDB_OPTION_TIMEZONE,
  TSDB_OPTION_CONFIGDIR,
  TSDB_OPTION_SHELL_ACTIVITY_TIMER,
50
  TSDB_OPTION_SOCKET_TYPE,
H
hzcheng 已提交
51 52 53
  TSDB_MAX_OPTIONS
} TSDB_OPTION;

S
slguan 已提交
54
typedef struct taosField {
H
hzcheng 已提交
55 56 57 58 59
  char  name[64];
  short bytes;
  char  type;
} TAOS_FIELD;

T
CGO DLL  
tanxuefeng 已提交
60 61 62 63
__declspec(dllexport) void  taos_init();
__declspec(dllexport) int   taos_options(TSDB_OPTION option, const void *arg, ...);
__declspec(dllexport) TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port);
__declspec(dllexport) void  taos_close(TAOS *taos);
S
slguan 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

typedef struct TAOS_BIND {
  int            buffer_type;
  void *         buffer;
  unsigned long  buffer_length;  // unused
  unsigned long *length;
  int *          is_null;
  int            is_unsigned;  // unused
  int *          error;        // unused
} TAOS_BIND;

TAOS_STMT *taos_stmt_init(TAOS *taos);
int        taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsigned long length);
int        taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_BIND *bind);
int        taos_stmt_add_batch(TAOS_STMT *stmt);
int        taos_stmt_execute(TAOS_STMT *stmt);
TAOS_RES * taos_stmt_use_result(TAOS_STMT *stmt);
int        taos_stmt_close(TAOS_STMT *stmt);

T
CGO DLL  
tanxuefeng 已提交
83 84 85 86 87 88 89 90 91 92 93 94
__declspec(dllexport) int taos_query(TAOS *taos, const char *sql);
__declspec(dllexport) TAOS_RES *taos_use_result(TAOS *taos);
__declspec(dllexport) TAOS_ROW taos_fetch_row(TAOS_RES *res);
__declspec(dllexport) int taos_result_precision(TAOS_RES *res);  // get the time precision of result
__declspec(dllexport) void taos_free_result(TAOS_RES *res);
__declspec(dllexport) int taos_field_count(TAOS *taos);
__declspec(dllexport) int taos_num_fields(TAOS_RES *res);
__declspec(dllexport) int taos_affected_rows(TAOS *taos);
__declspec(dllexport) TAOS_FIELD *taos_fetch_fields(TAOS_RES *res);
__declspec(dllexport) int taos_select_db(TAOS *taos, const char *db);
__declspec(dllexport) int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields);
__declspec(dllexport) void taos_stop_query(TAOS_RES *res);
H
hzcheng 已提交
95 96

int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows);
S
slguan 已提交
97
int taos_validate_sql(TAOS *taos, const char *sql);
H
hzcheng 已提交
98 99 100 101

// TAOS_RES   *taos_list_tables(TAOS *mysql, const char *wild);
// TAOS_RES   *taos_list_dbs(TAOS *mysql, const char *wild);

S
slguan 已提交
102
// TODO: the return value should be `const`
T
CGO DLL  
tanxuefeng 已提交
103 104 105
__declspec(dllexport) char *taos_get_server_info(TAOS *taos);
__declspec(dllexport) char *taos_get_client_info();
__declspec(dllexport) char *taos_errstr(TAOS *taos);
S
slguan 已提交
106

T
CGO DLL  
tanxuefeng 已提交
107
__declspec(dllexport) int taos_errno(TAOS *taos);
H
hzcheng 已提交
108

T
CGO DLL  
tanxuefeng 已提交
109 110 111
__declspec(dllexport) void taos_query_a(TAOS *taos, const char *sql, void (*fp)(void *param, TAOS_RES *, int code), void *param);
__declspec(dllexport) void taos_fetch_rows_a(TAOS_RES *res, void (*fp)(void *param, TAOS_RES *, int numOfRows), void *param);
__declspec(dllexport) void taos_fetch_row_a(TAOS_RES *res, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row), void *param);
H
hzcheng 已提交
112

T
CGO DLL  
tanxuefeng 已提交
113 114 115 116 117
__declspec(dllexport) TAOS_SUB *taos_subscribe(const char *host, const char *user, const char *pass, const char *db, const char *table, int64_t time, int mseconds);
__declspec(dllexport) TAOS_ROW taos_consume(TAOS_SUB *tsub);
__declspec(dllexport) void taos_unsubscribe(TAOS_SUB *tsub);
__declspec(dllexport) int taos_subfields_count(TAOS_SUB *tsub);
__declspec(dllexport) TAOS_FIELD *taos_fetch_subfields(TAOS_SUB *tsub);
H
hzcheng 已提交
118

T
CGO DLL  
tanxuefeng 已提交
119
__declspec(dllexport) TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sql, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row),
H
hzcheng 已提交
120
                              int64_t stime, void *param, void (*callback)(void *));
T
CGO DLL  
tanxuefeng 已提交
121
__declspec(dllexport) void taos_close_stream(TAOS_STREAM *tstr);
H
hzcheng 已提交
122

T
CGO DLL  
tanxuefeng 已提交
123
__declspec(dllexport) int taos_load_table_info(TAOS *taos, const char* tableNameList);
S
slguan 已提交
124

H
hzcheng 已提交
125 126 127 128 129
#ifdef __cplusplus
}
#endif

#endif