1 | /* |
2 | * This Source Code Form is subject to the terms of the Mozilla Public |
3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
5 | * |
6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V. |
7 | */ |
8 | |
9 | #ifndef _MAPI_H_INCLUDED |
10 | #define _MAPI_H_INCLUDED 1 |
11 | |
12 | #include <stdio.h> /* for FILE * */ |
13 | #include <stdint.h> /* for int64_t */ |
14 | #include <stdbool.h> /* for bool */ |
15 | |
16 | #define MAPI_AUTO 0 /* automatic type detection */ |
17 | #define MAPI_TINY 1 |
18 | #define MAPI_UTINY 2 |
19 | #define MAPI_SHORT 3 |
20 | #define MAPI_USHORT 4 |
21 | #define MAPI_INT 5 |
22 | #define MAPI_UINT 6 |
23 | #define MAPI_LONG 7 |
24 | #define MAPI_ULONG 8 |
25 | #define MAPI_LONGLONG 9 |
26 | #define MAPI_ULONGLONG 10 |
27 | #define MAPI_CHAR 11 |
28 | #define MAPI_VARCHAR 12 |
29 | #define MAPI_FLOAT 13 |
30 | #define MAPI_DOUBLE 14 |
31 | #define MAPI_DATE 15 |
32 | #define MAPI_TIME 16 |
33 | #define MAPI_DATETIME 17 |
34 | #define MAPI_NUMERIC 18 |
35 | |
36 | #define PLACEHOLDER '?' |
37 | |
38 | #define MAPI_SEEK_SET 0 |
39 | #define MAPI_SEEK_CUR 1 |
40 | #define MAPI_SEEK_END 2 |
41 | |
42 | typedef int MapiMsg; |
43 | |
44 | #define MOK 0 |
45 | #define MERROR (-1) |
46 | #define MTIMEOUT (-2) |
47 | #define MMORE (-3) |
48 | #define MSERVER (-4) |
49 | |
50 | /* prompts for MAPI protocol, also in monetdb_config.h.in */ |
51 | #define PROMPTBEG '\001' /* start prompt bracket */ |
52 | #define PROMPT1 "\001\001\n" /* prompt: ready for new query */ |
53 | #define PROMPT2 "\001\002\n" /* prompt: more data needed */ |
54 | #define PROMPT3 "\001\003\n" /* prompt: get file content */ |
55 | |
56 | /* |
57 | * The table field information is extracted from the table headers |
58 | * obtained from the server. This list may be extended in the future. |
59 | * The type of both the 'param' and 'binding' |
60 | * variables refer to their underlying C-type. They are used for |
61 | * automatic type coercion between back-end and application. |
62 | */ |
63 | typedef struct MapiStruct *Mapi; |
64 | |
65 | /* this definition is a straight copy from sql/include/sql_query.h */ |
66 | typedef enum sql_query_t { |
67 | Q_PARSE = 0, |
68 | Q_TABLE = 1, |
69 | Q_UPDATE = 2, |
70 | Q_SCHEMA = 3, |
71 | Q_TRANS = 4, |
72 | Q_PREPARE = 5, |
73 | Q_BLOCK = 6 |
74 | } sql_query_t; |
75 | |
76 | typedef struct MapiStatement *MapiHdl; |
77 | |
78 | #ifdef __cplusplus |
79 | extern "C" { |
80 | #endif |
81 | |
82 | /* avoid using "#ifdef WIN32" so that this file does not need our config.h */ |
83 | #if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) |
84 | #ifndef LIBMAPI |
85 | #define mapi_export extern __declspec(dllimport) |
86 | #else |
87 | #define mapi_export extern __declspec(dllexport) |
88 | #endif |
89 | #else |
90 | #define mapi_export extern |
91 | #endif |
92 | |
93 | /* three structures used for communicating date/time information */ |
94 | /* these structs are deliberately compatible with the ODBC versions |
95 | SQL_DATE_STRUCT, SQL_TIME_STRUCT, and SQL_TIMESTAMP_STRUCT */ |
96 | typedef struct { /* used by MAPI_DATE */ |
97 | short year; |
98 | unsigned short month; |
99 | unsigned short day; |
100 | } MapiDate; |
101 | |
102 | typedef struct { /* used by MAPI_TIME */ |
103 | unsigned short hour; |
104 | unsigned short minute; |
105 | unsigned short second; |
106 | } MapiTime; |
107 | |
108 | typedef struct { /* used by MAPI_DATETIME */ |
109 | short year; |
110 | unsigned short month; |
111 | unsigned short day; |
112 | unsigned short hour; |
113 | unsigned short minute; |
114 | unsigned short second; |
115 | unsigned int fraction; /* in 1000 millionths of a second (10e-9) */ |
116 | } MapiDateTime; |
117 | |
118 | /* connection-oriented functions */ |
119 | mapi_export Mapi mapi_mapi(const char *host, int port, const char *username, const char *password, const char *lang, const char *dbname); |
120 | mapi_export Mapi mapi_mapiuri(const char *url, const char *user, const char *pass, const char *lang); |
121 | mapi_export MapiMsg mapi_destroy(Mapi mid); |
122 | mapi_export MapiMsg mapi_start_talking(Mapi mid); |
123 | mapi_export Mapi mapi_connect(const char *host, int port, const char *username, const char *password, const char *lang, const char *dbname); |
124 | mapi_export char **mapi_resolve(const char *host, int port, const char *pattern); |
125 | mapi_export MapiMsg mapi_disconnect(Mapi mid); |
126 | mapi_export MapiMsg mapi_reconnect(Mapi mid); |
127 | mapi_export MapiMsg mapi_ping(Mapi mid); |
128 | mapi_export void mapi_setfilecallback( |
129 | Mapi mid, |
130 | char *(*getfunc)(void *priv, const char *filename, |
131 | bool binary, uint64_t offset, size_t *size), |
132 | char *(*putfunc)(void *priv, const char *filename, |
133 | const void *data, size_t size), |
134 | void *priv); |
135 | |
136 | mapi_export MapiMsg mapi_error(Mapi mid); |
137 | mapi_export const char *mapi_error_str(Mapi mid); |
138 | mapi_export void mapi_noexplain(Mapi mid, const char *errorprefix); |
139 | mapi_export void mapi_explain(Mapi mid, FILE *fd); |
140 | mapi_export void mapi_explain_query(MapiHdl hdl, FILE *fd); |
141 | mapi_export void mapi_explain_result(MapiHdl hdl, FILE *fd); |
142 | mapi_export void mapi_trace(Mapi mid, bool flag); |
143 | #ifdef _STREAM_H_ /* if stream.h was included */ |
144 | mapi_export stream *mapi_get_from(Mapi mid); |
145 | mapi_export stream *mapi_get_to(Mapi mid); |
146 | #endif |
147 | mapi_export bool mapi_get_trace(Mapi mid); |
148 | mapi_export bool mapi_get_autocommit(Mapi mid); |
149 | mapi_export MapiMsg mapi_log(Mapi mid, const char *nme); |
150 | mapi_export MapiMsg mapi_setAutocommit(Mapi mid, bool autocommit); |
151 | mapi_export MapiMsg (Mapi mid, bool value); |
152 | mapi_export MapiMsg mapi_release_id(Mapi mid, int id); |
153 | mapi_export const char *mapi_result_error(MapiHdl hdl); |
154 | mapi_export const char *mapi_result_errorcode(MapiHdl hdl); |
155 | mapi_export MapiMsg mapi_next_result(MapiHdl hdl); |
156 | mapi_export MapiMsg mapi_needmore(MapiHdl hdl); |
157 | mapi_export bool mapi_more_results(MapiHdl hdl); |
158 | mapi_export MapiHdl mapi_new_handle(Mapi mid); |
159 | mapi_export MapiMsg mapi_close_handle(MapiHdl hdl); |
160 | mapi_export MapiMsg mapi_bind(MapiHdl hdl, int fnr, char **ptr); |
161 | mapi_export MapiMsg mapi_bind_var(MapiHdl hdl, int fnr, int type, void *ptr); |
162 | mapi_export MapiMsg mapi_bind_numeric(MapiHdl hdl, int fnr, int scale, int precision, void *ptr); |
163 | mapi_export MapiMsg mapi_clear_bindings(MapiHdl hdl); |
164 | mapi_export MapiMsg mapi_param_type(MapiHdl hdl, int fnr, int ctype, int sqltype, void *ptr); |
165 | mapi_export MapiMsg mapi_param_string(MapiHdl hdl, int fnr, int sqltype, char *ptr, int *sizeptr); |
166 | mapi_export MapiMsg mapi_param(MapiHdl hdl, int fnr, char **ptr); |
167 | mapi_export MapiMsg mapi_param_numeric(MapiHdl hdl, int fnr, int scale, int precision, void *ptr); |
168 | mapi_export MapiMsg mapi_clear_params(MapiHdl hdl); |
169 | mapi_export MapiHdl mapi_prepare(Mapi mid, const char *cmd); |
170 | mapi_export MapiMsg mapi_prepare_handle(MapiHdl hdl, const char *cmd); |
171 | mapi_export MapiMsg mapi_execute(MapiHdl hdl); |
172 | mapi_export MapiMsg mapi_fetch_reset(MapiHdl hdl); |
173 | mapi_export MapiMsg mapi_finish(MapiHdl hdl); |
174 | mapi_export MapiHdl mapi_query(Mapi mid, const char *cmd); |
175 | mapi_export MapiMsg mapi_query_handle(MapiHdl hdl, const char *cmd); |
176 | mapi_export MapiHdl mapi_query_prep(Mapi mid); |
177 | mapi_export MapiMsg mapi_query_part(MapiHdl hdl, const char *cmd, size_t size); |
178 | mapi_export MapiMsg mapi_query_done(MapiHdl hdl); |
179 | mapi_export MapiHdl mapi_send(Mapi mid, const char *cmd); |
180 | mapi_export MapiMsg mapi_read_response(MapiHdl hdl); |
181 | mapi_export MapiMsg mapi_cache_limit(Mapi mid, int limit); |
182 | mapi_export MapiMsg mapi_cache_freeup(MapiHdl hdl, int percentage); |
183 | mapi_export MapiMsg mapi_seek_row(MapiHdl hdl, int64_t rowne, int whence); |
184 | |
185 | mapi_export MapiMsg mapi_timeout(Mapi mid, unsigned int time); |
186 | mapi_export int mapi_fetch_row(MapiHdl hdl); |
187 | mapi_export int64_t mapi_fetch_all_rows(MapiHdl hdl); |
188 | mapi_export int mapi_get_field_count(MapiHdl hdl); |
189 | mapi_export int64_t mapi_get_row_count(MapiHdl hdl); |
190 | mapi_export int64_t mapi_get_last_id(MapiHdl hdl); |
191 | mapi_export int64_t mapi_rows_affected(MapiHdl hdl); |
192 | mapi_export int64_t mapi_get_querytime(MapiHdl hdl); |
193 | mapi_export int64_t mapi_get_maloptimizertime(MapiHdl hdl); |
194 | mapi_export int64_t mapi_get_sqloptimizertime(MapiHdl hdl); |
195 | |
196 | mapi_export char *mapi_fetch_field(MapiHdl hdl, int fnr); |
197 | mapi_export size_t mapi_fetch_field_len(MapiHdl hdl, int fnr); |
198 | mapi_export MapiMsg mapi_store_field(MapiHdl hdl, int fnr, int outtype, void *outparam); |
199 | mapi_export char *mapi_fetch_line(MapiHdl hdl); |
200 | mapi_export int mapi_split_line(MapiHdl hdl); |
201 | mapi_export const char *mapi_get_lang(Mapi mid); |
202 | mapi_export const char *mapi_get_uri(Mapi mid); |
203 | mapi_export const char *mapi_get_dbname(Mapi mid); |
204 | mapi_export const char *mapi_get_host(Mapi mid); |
205 | mapi_export const char *mapi_get_user(Mapi mid); |
206 | mapi_export const char *mapi_get_mapi_version(Mapi mid); |
207 | mapi_export const char *mapi_get_monet_version(Mapi mid); |
208 | mapi_export const char *mapi_get_motd(Mapi mid); |
209 | mapi_export bool mapi_is_connected(Mapi mid); |
210 | mapi_export char *mapi_get_table(MapiHdl hdl, int fnr); |
211 | mapi_export char *mapi_get_name(MapiHdl hdl, int fnr); |
212 | mapi_export char *mapi_get_type(MapiHdl hdl, int fnr); |
213 | mapi_export int mapi_get_len(MapiHdl hdl, int fnr); |
214 | mapi_export int mapi_get_digits(MapiHdl hdl, int fnr); |
215 | mapi_export int mapi_get_scale(MapiHdl hdl, int fnr); |
216 | mapi_export char *mapi_get_query(MapiHdl hdl); |
217 | mapi_export int mapi_get_querytype(MapiHdl hdl); |
218 | mapi_export int mapi_get_tableid(MapiHdl hdl); |
219 | mapi_export char *mapi_quote(const char *msg, int size); |
220 | mapi_export char *mapi_unquote(char *msg); |
221 | mapi_export MapiHdl mapi_get_active(Mapi mid); |
222 | #ifdef _MSC_VER |
223 | mapi_export const char *wsaerror(int); |
224 | #endif |
225 | |
226 | #ifdef __cplusplus |
227 | } |
228 | #endif |
229 | #endif /* _MAPI_H_INCLUDED */ |
230 | |