1 module monetdb.binding; 2 3 import std.string; 4 import core.stdc.stdio: FILE; 5 6 enum { 7 MAPI_AUTO = 0, 8 MAPI_TINY = 1, 9 MAPI_UTINY = 2, 10 MAPI_SHORT = 3, 11 MAPI_USHORT = 4, 12 MAPI_INT = 5, 13 MAPI_UINT = 6, 14 MAPI_LONG = 7, 15 MAPI_ULONG = 8, 16 MAPI_LONGLONG = 9, 17 MAPI_ULONGLONG = 10, 18 MAPI_CHAR = 11, 19 MAPI_VARCHAR = 12, 20 MAPI_FLOAT = 13, 21 MAPI_DOUBLE = 14, 22 MAPI_DATE = 15, 23 MAPI_TIME = 16, 24 MAPI_DATETIME = 17, 25 MAPI_NUMERIC = 18 26 } 27 28 enum int PLACEHOLDER = '?'; 29 30 enum { 31 MAPI_SEEK_SET = 0, 32 MAPI_SEEK_CUR = 1, 33 MAPI_SEEK_END = 2 34 } 35 36 alias MapiMsg = int; 37 38 enum { 39 MOK = 0, 40 MERROR = -1, 41 MTIMEOUT = -2, 42 MMORE = -3, 43 MSERVER = -4 44 } 45 46 enum int PROMPTBEG = '\001'; 47 enum const(char*) PROMPT1 = "\001\001\n".ptr; 48 enum const(char*) PROMPT2 = "\001\002\n".ptr; 49 enum const(char*) PROMPT3 = "\001\003\n".ptr; 50 51 struct MapiStruct; 52 alias Mapi = MapiStruct*; 53 54 enum sql_query_t { 55 Q_PARSE = 0, 56 Q_TABLE = 1, 57 Q_UPDATE = 2, 58 Q_SCHEMA = 3, 59 Q_TRANS = 4, 60 Q_PREPARE = 5, 61 Q_BLOCK = 6 62 } 63 64 65 struct MapiStatement; 66 alias MapiHdl = MapiStatement*; 67 68 struct MapiDate { 69 short year; 70 ushort month; 71 ushort day; 72 } 73 74 struct MapiTime { 75 ushort hour; 76 ushort minute; 77 ushort second; 78 } 79 80 struct MapiDateTime { 81 short year; 82 ushort month; 83 ushort day; 84 ushort hour; 85 ushort minute; 86 ushort second; 87 uint fraction; 88 } 89 90 extern(C) { 91 Mapi mapi_mapi (const(char)* host, int port, const(char)* username, const(char)* password, const(char)* lang, const(char)* dbname); 92 Mapi mapi_mapiuri (const(char)* url, const(char)* user, const(char)* pass, const(char)* lang); 93 MapiMsg mapi_destroy (Mapi mid); 94 MapiMsg mapi_start_talking (Mapi mid); 95 Mapi mapi_connect (const(char)* host, int port, const(char)* username, const(char)* password, const(char)* lang, const(char)* dbname); 96 char** mapi_resolve (const(char)* host, int port, const(char)* pattern); 97 MapiMsg mapi_disconnect (Mapi mid); 98 MapiMsg mapi_reconnect (Mapi mid); 99 MapiMsg mapi_ping (Mapi mid); 100 void mapi_setfilecallback ( 101 Mapi mid, 102 char* function (void* priv, const(char)* filename, bool binary, ulong offset, size_t* size) getfunc, 103 char* function (void* priv, const(char)* filename, const(void)* data, size_t size) putfunc, 104 void* priv); 105 106 MapiMsg mapi_error (Mapi mid); 107 const(char)* mapi_error_str (Mapi mid); 108 void mapi_noexplain (Mapi mid, const(char)* errorprefix); 109 void mapi_explain (Mapi mid, FILE* fd); 110 void mapi_explain_query (MapiHdl hdl, FILE* fd); 111 void mapi_explain_result (MapiHdl hdl, FILE* fd); 112 void mapi_trace (Mapi mid, bool flag); 113 114 bool mapi_get_trace (Mapi mid); 115 bool mapi_get_autocommit (Mapi mid); 116 MapiMsg mapi_log (Mapi mid, const(char)* nme); 117 MapiMsg mapi_setAutocommit (Mapi mid, bool autocommit); 118 MapiMsg mapi_set_size_header (Mapi mid, bool value); 119 MapiMsg mapi_release_id (Mapi mid, int id); 120 const(char)* mapi_result_error (MapiHdl hdl); 121 const(char)* mapi_result_errorcode (MapiHdl hdl); 122 MapiMsg mapi_next_result (MapiHdl hdl); 123 MapiMsg mapi_needmore (MapiHdl hdl); 124 bool mapi_more_results (MapiHdl hdl); 125 MapiHdl mapi_new_handle (Mapi mid); 126 MapiMsg mapi_close_handle (MapiHdl hdl); 127 MapiMsg mapi_bind (MapiHdl hdl, int fnr, char** ptr); 128 MapiMsg mapi_bind_var (MapiHdl hdl, int fnr, int type, void* ptr); 129 MapiMsg mapi_bind_numeric (MapiHdl hdl, int fnr, int scale, int precision, void* ptr); 130 MapiMsg mapi_clear_bindings (MapiHdl hdl); 131 MapiMsg mapi_param_type (MapiHdl hdl, int fnr, int ctype, int sqltype, void* ptr); 132 MapiMsg mapi_param_string (MapiHdl hdl, int fnr, int sqltype, char* ptr, int* sizeptr); 133 MapiMsg mapi_param (MapiHdl hdl, int fnr, char** ptr); 134 MapiMsg mapi_param_numeric (MapiHdl hdl, int fnr, int scale, int precision, void* ptr); 135 MapiMsg mapi_clear_params (MapiHdl hdl); 136 MapiHdl mapi_prepare (Mapi mid, const(char)* cmd); 137 MapiMsg mapi_prepare_handle (MapiHdl hdl, const(char)* cmd); 138 MapiMsg mapi_execute (MapiHdl hdl); 139 MapiMsg mapi_fetch_reset (MapiHdl hdl); 140 MapiMsg mapi_finish (MapiHdl hdl); 141 MapiHdl mapi_query (Mapi mid, const(char)* cmd); 142 MapiMsg mapi_query_handle (MapiHdl hdl, const(char)* cmd); 143 MapiHdl mapi_query_prep (Mapi mid); 144 MapiMsg mapi_query_part (MapiHdl hdl, const(char)* cmd, size_t size); 145 MapiMsg mapi_query_done (MapiHdl hdl); 146 MapiHdl mapi_send (Mapi mid, const(char)* cmd); 147 MapiMsg mapi_read_response (MapiHdl hdl); 148 MapiMsg mapi_cache_limit (Mapi mid, int limit); 149 MapiMsg mapi_cache_freeup (MapiHdl hdl, int percentage); 150 MapiMsg mapi_seek_row (MapiHdl hdl, long rowne, int whence); 151 152 MapiMsg mapi_timeout (Mapi mid, uint time); 153 int mapi_fetch_row (MapiHdl hdl); 154 long mapi_fetch_all_rows (MapiHdl hdl); 155 int mapi_get_field_count (MapiHdl hdl); 156 long mapi_get_row_count (MapiHdl hdl); 157 long mapi_get_last_id (MapiHdl hdl); 158 long mapi_rows_affected (MapiHdl hdl); 159 long mapi_get_querytime (MapiHdl hdl); 160 long mapi_get_maloptimizertime (MapiHdl hdl); 161 long mapi_get_sqloptimizertime (MapiHdl hdl); 162 163 char* mapi_fetch_field (MapiHdl hdl, int fnr); 164 size_t mapi_fetch_field_len (MapiHdl hdl, int fnr); 165 MapiMsg mapi_store_field (MapiHdl hdl, int fnr, int outtype, void* outparam); 166 char* mapi_fetch_line (MapiHdl hdl); 167 int mapi_split_line (MapiHdl hdl); 168 const(char)* mapi_get_lang (Mapi mid); 169 const(char)* mapi_get_uri (Mapi mid); 170 const(char)* mapi_get_dbname (Mapi mid); 171 const(char)* mapi_get_host (Mapi mid); 172 const(char)* mapi_get_user (Mapi mid); 173 const(char)* mapi_get_mapi_version (Mapi mid); 174 const(char)* mapi_get_monet_version (Mapi mid); 175 const(char)* mapi_get_motd (Mapi mid); 176 bool mapi_is_connected (Mapi mid); 177 char* mapi_get_table (MapiHdl hdl, int fnr); 178 char* mapi_get_name (MapiHdl hdl, int fnr); 179 char* mapi_get_type (MapiHdl hdl, int fnr); 180 int mapi_get_len (MapiHdl hdl, int fnr); 181 int mapi_get_digits (MapiHdl hdl, int fnr); 182 int mapi_get_scale (MapiHdl hdl, int fnr); 183 char* mapi_get_query (MapiHdl hdl); 184 int mapi_get_querytype (MapiHdl hdl); 185 int mapi_get_tableid (MapiHdl hdl); 186 char* mapi_quote (const(char)* msg, int size); 187 char* mapi_unquote (char* msg); 188 MapiHdl mapi_get_active (Mapi mid); 189 }