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
42typedef 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 */
63typedef struct MapiStruct *Mapi;
64
65/* this definition is a straight copy from sql/include/sql_query.h */
66typedef 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
76typedef struct MapiStatement *MapiHdl;
77
78#ifdef __cplusplus
79extern "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 */
96typedef struct { /* used by MAPI_DATE */
97 short year;
98 unsigned short month;
99 unsigned short day;
100} MapiDate;
101
102typedef struct { /* used by MAPI_TIME */
103 unsigned short hour;
104 unsigned short minute;
105 unsigned short second;
106} MapiTime;
107
108typedef 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 */
119mapi_export Mapi mapi_mapi(const char *host, int port, const char *username, const char *password, const char *lang, const char *dbname);
120mapi_export Mapi mapi_mapiuri(const char *url, const char *user, const char *pass, const char *lang);
121mapi_export MapiMsg mapi_destroy(Mapi mid);
122mapi_export MapiMsg mapi_start_talking(Mapi mid);
123mapi_export Mapi mapi_connect(const char *host, int port, const char *username, const char *password, const char *lang, const char *dbname);
124mapi_export char **mapi_resolve(const char *host, int port, const char *pattern);
125mapi_export MapiMsg mapi_disconnect(Mapi mid);
126mapi_export MapiMsg mapi_reconnect(Mapi mid);
127mapi_export MapiMsg mapi_ping(Mapi mid);
128mapi_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
136mapi_export MapiMsg mapi_error(Mapi mid);
137mapi_export const char *mapi_error_str(Mapi mid);
138mapi_export void mapi_noexplain(Mapi mid, const char *errorprefix);
139mapi_export void mapi_explain(Mapi mid, FILE *fd);
140mapi_export void mapi_explain_query(MapiHdl hdl, FILE *fd);
141mapi_export void mapi_explain_result(MapiHdl hdl, FILE *fd);
142mapi_export void mapi_trace(Mapi mid, bool flag);
143#ifdef _STREAM_H_ /* if stream.h was included */
144mapi_export stream *mapi_get_from(Mapi mid);
145mapi_export stream *mapi_get_to(Mapi mid);
146#endif
147mapi_export bool mapi_get_trace(Mapi mid);
148mapi_export bool mapi_get_autocommit(Mapi mid);
149mapi_export MapiMsg mapi_log(Mapi mid, const char *nme);
150mapi_export MapiMsg mapi_setAutocommit(Mapi mid, bool autocommit);
151mapi_export MapiMsg mapi_set_size_header(Mapi mid, bool value);
152mapi_export MapiMsg mapi_release_id(Mapi mid, int id);
153mapi_export const char *mapi_result_error(MapiHdl hdl);
154mapi_export const char *mapi_result_errorcode(MapiHdl hdl);
155mapi_export MapiMsg mapi_next_result(MapiHdl hdl);
156mapi_export MapiMsg mapi_needmore(MapiHdl hdl);
157mapi_export bool mapi_more_results(MapiHdl hdl);
158mapi_export MapiHdl mapi_new_handle(Mapi mid);
159mapi_export MapiMsg mapi_close_handle(MapiHdl hdl);
160mapi_export MapiMsg mapi_bind(MapiHdl hdl, int fnr, char **ptr);
161mapi_export MapiMsg mapi_bind_var(MapiHdl hdl, int fnr, int type, void *ptr);
162mapi_export MapiMsg mapi_bind_numeric(MapiHdl hdl, int fnr, int scale, int precision, void *ptr);
163mapi_export MapiMsg mapi_clear_bindings(MapiHdl hdl);
164mapi_export MapiMsg mapi_param_type(MapiHdl hdl, int fnr, int ctype, int sqltype, void *ptr);
165mapi_export MapiMsg mapi_param_string(MapiHdl hdl, int fnr, int sqltype, char *ptr, int *sizeptr);
166mapi_export MapiMsg mapi_param(MapiHdl hdl, int fnr, char **ptr);
167mapi_export MapiMsg mapi_param_numeric(MapiHdl hdl, int fnr, int scale, int precision, void *ptr);
168mapi_export MapiMsg mapi_clear_params(MapiHdl hdl);
169mapi_export MapiHdl mapi_prepare(Mapi mid, const char *cmd);
170mapi_export MapiMsg mapi_prepare_handle(MapiHdl hdl, const char *cmd);
171mapi_export MapiMsg mapi_execute(MapiHdl hdl);
172mapi_export MapiMsg mapi_fetch_reset(MapiHdl hdl);
173mapi_export MapiMsg mapi_finish(MapiHdl hdl);
174mapi_export MapiHdl mapi_query(Mapi mid, const char *cmd);
175mapi_export MapiMsg mapi_query_handle(MapiHdl hdl, const char *cmd);
176mapi_export MapiHdl mapi_query_prep(Mapi mid);
177mapi_export MapiMsg mapi_query_part(MapiHdl hdl, const char *cmd, size_t size);
178mapi_export MapiMsg mapi_query_done(MapiHdl hdl);
179mapi_export MapiHdl mapi_send(Mapi mid, const char *cmd);
180mapi_export MapiMsg mapi_read_response(MapiHdl hdl);
181mapi_export MapiMsg mapi_cache_limit(Mapi mid, int limit);
182mapi_export MapiMsg mapi_cache_freeup(MapiHdl hdl, int percentage);
183mapi_export MapiMsg mapi_seek_row(MapiHdl hdl, int64_t rowne, int whence);
184
185mapi_export MapiMsg mapi_timeout(Mapi mid, unsigned int time);
186mapi_export int mapi_fetch_row(MapiHdl hdl);
187mapi_export int64_t mapi_fetch_all_rows(MapiHdl hdl);
188mapi_export int mapi_get_field_count(MapiHdl hdl);
189mapi_export int64_t mapi_get_row_count(MapiHdl hdl);
190mapi_export int64_t mapi_get_last_id(MapiHdl hdl);
191mapi_export int64_t mapi_rows_affected(MapiHdl hdl);
192mapi_export int64_t mapi_get_querytime(MapiHdl hdl);
193mapi_export int64_t mapi_get_maloptimizertime(MapiHdl hdl);
194mapi_export int64_t mapi_get_sqloptimizertime(MapiHdl hdl);
195
196mapi_export char *mapi_fetch_field(MapiHdl hdl, int fnr);
197mapi_export size_t mapi_fetch_field_len(MapiHdl hdl, int fnr);
198mapi_export MapiMsg mapi_store_field(MapiHdl hdl, int fnr, int outtype, void *outparam);
199mapi_export char *mapi_fetch_line(MapiHdl hdl);
200mapi_export int mapi_split_line(MapiHdl hdl);
201mapi_export const char *mapi_get_lang(Mapi mid);
202mapi_export const char *mapi_get_uri(Mapi mid);
203mapi_export const char *mapi_get_dbname(Mapi mid);
204mapi_export const char *mapi_get_host(Mapi mid);
205mapi_export const char *mapi_get_user(Mapi mid);
206mapi_export const char *mapi_get_mapi_version(Mapi mid);
207mapi_export const char *mapi_get_monet_version(Mapi mid);
208mapi_export const char *mapi_get_motd(Mapi mid);
209mapi_export bool mapi_is_connected(Mapi mid);
210mapi_export char *mapi_get_table(MapiHdl hdl, int fnr);
211mapi_export char *mapi_get_name(MapiHdl hdl, int fnr);
212mapi_export char *mapi_get_type(MapiHdl hdl, int fnr);
213mapi_export int mapi_get_len(MapiHdl hdl, int fnr);
214mapi_export int mapi_get_digits(MapiHdl hdl, int fnr);
215mapi_export int mapi_get_scale(MapiHdl hdl, int fnr);
216mapi_export char *mapi_get_query(MapiHdl hdl);
217mapi_export int mapi_get_querytype(MapiHdl hdl);
218mapi_export int mapi_get_tableid(MapiHdl hdl);
219mapi_export char *mapi_quote(const char *msg, int size);
220mapi_export char *mapi_unquote(char *msg);
221mapi_export MapiHdl mapi_get_active(Mapi mid);
222#ifdef _MSC_VER
223mapi_export const char *wsaerror(int);
224#endif
225
226#ifdef __cplusplus
227}
228#endif
229#endif /* _MAPI_H_INCLUDED */
230