|
| 1 | +/* |
| 2 | + * fakemysql.h -- |
| 3 | + * |
| 4 | + * Fake definitions of the MySQL API sufficient to build tdbc::mysql |
| 5 | + * without having an MySQL installation on the build system. This file |
| 6 | + * comprises only data type, constant and function definitions. |
| 7 | + * |
| 8 | + * The programmers of this file believe that it contains material not |
| 9 | + * subject to copyright under the doctrines of scenes a faire and |
| 10 | + * of merger of idea and expression. Accordingly, this file is in the |
| 11 | + * public domain. |
| 12 | + * |
| 13 | + *----------------------------------------------------------------------------- |
| 14 | + */ |
| 15 | + |
| 16 | +#ifndef FAKEMYSQL_H_INCLUDED |
| 17 | +#define FAKEMYSQL_H_INCLUDED |
| 18 | + |
| 19 | +#include <stddef.h> |
| 20 | + |
| 21 | +#ifndef MODULE_SCOPE |
| 22 | +#define MODULE_SCOPE extern |
| 23 | +#endif |
| 24 | + |
| 25 | +MODULE_SCOPE Tcl_LoadHandle MysqlInitStubs(Tcl_Interp*); |
| 26 | + |
| 27 | +#ifdef _WIN32 |
| 28 | +#define STDCALL __stdcall |
| 29 | +#else |
| 30 | +#define STDCALL /* nothing */ |
| 31 | +#endif |
| 32 | + |
| 33 | +enum enum_field_types { |
| 34 | + MYSQL_TYPE_DECIMAL=0, |
| 35 | + MYSQL_TYPE_TINY=1, |
| 36 | + MYSQL_TYPE_SHORT=2, |
| 37 | + MYSQL_TYPE_LONG=3, |
| 38 | + MYSQL_TYPE_FLOAT=4, |
| 39 | + MYSQL_TYPE_DOUBLE=5, |
| 40 | + MYSQL_TYPE_NULL=6, |
| 41 | + MYSQL_TYPE_TIMESTAMP=7, |
| 42 | + MYSQL_TYPE_LONGLONG=8, |
| 43 | + MYSQL_TYPE_INT24=9, |
| 44 | + MYSQL_TYPE_DATE=10, |
| 45 | + MYSQL_TYPE_TIME=11, |
| 46 | + MYSQL_TYPE_DATETIME=12, |
| 47 | + MYSQL_TYPE_YEAR=13, |
| 48 | + MYSQL_TYPE_NEWDATE=14, |
| 49 | + MYSQL_TYPE_VARCHAR=15, |
| 50 | + MYSQL_TYPE_BIT=16, |
| 51 | + MYSQL_TYPE_NEWDECIMAL=246, |
| 52 | + MYSQL_TYPE_ENUM=247, |
| 53 | + MYSQL_TYPE_SET=248, |
| 54 | + MYSQL_TYPE_TINY_BLOB=249, |
| 55 | + MYSQL_TYPE_MEDIUM_BLOB=250, |
| 56 | + MYSQL_TYPE_LONG_BLOB=251, |
| 57 | + MYSQL_TYPE_BLOB=252, |
| 58 | + MYSQL_TYPE_VAR_STRING=253, |
| 59 | + MYSQL_TYPE_STRING=254, |
| 60 | + MYSQL_TYPE_GEOMETRY=255 |
| 61 | +}; |
| 62 | + |
| 63 | +enum mysql_option { |
| 64 | + MYSQL_SET_CHARSET_NAME=7, |
| 65 | +}; |
| 66 | + |
| 67 | +enum mysql_status { |
| 68 | + MYSQL_STATUS_READY=0, |
| 69 | +}; |
| 70 | + |
| 71 | +#define CLIENT_COMPRESS 32 |
| 72 | +#define CLIENT_INTERACTIVE 1024 |
| 73 | +#define MYSQL_DATA_TRUNCATED 101 |
| 74 | +#define MYSQL_ERRMSG_SIZE 512 |
| 75 | +#define MYSQL_NO_DATA 100 |
| 76 | +#define SCRAMBLE_LENGTH 20 |
| 77 | +#define SQLSTATE_LENGTH 5 |
| 78 | + |
| 79 | +typedef struct st_list LIST; |
| 80 | +typedef struct st_mem_root MEM_ROOT; |
| 81 | +typedef struct st_mysql MYSQL; |
| 82 | +typedef struct st_mysql_bind MYSQL_BIND; |
| 83 | +typedef struct st_mysql_field MYSQL_FIELD; |
| 84 | +typedef struct st_mysql_res MYSQL_RES; |
| 85 | +typedef char** MYSQL_ROW; |
| 86 | +typedef struct st_mysql_stmt MYSQL_STMT; |
| 87 | +typedef char my_bool; |
| 88 | +#ifndef Socket_defined |
| 89 | +typedef int my_socket; |
| 90 | +#define INVALID_SOCKET -1 |
| 91 | +#endif |
| 92 | +typedef Tcl_WideUInt my_ulonglong; |
| 93 | +typedef struct st_net NET; |
| 94 | +typedef struct st_used_mem USED_MEM; |
| 95 | +typedef struct st_vio Vio; |
| 96 | + |
| 97 | +struct st_mem_root { |
| 98 | + USED_MEM *free; |
| 99 | + USED_MEM *used; |
| 100 | + USED_MEM *pre_alloc; |
| 101 | + size_t min_malloc; |
| 102 | + size_t block_size; |
| 103 | + unsigned int block_num; |
| 104 | + unsigned int first_block_usage; |
| 105 | + void (*error_handler)(void); |
| 106 | +}; |
| 107 | + |
| 108 | +struct st_mysql_options { |
| 109 | + unsigned int connect_timeout; |
| 110 | + unsigned int read_timeout; |
| 111 | + unsigned int write_timeout; |
| 112 | + unsigned int port; |
| 113 | + unsigned int protocol; |
| 114 | + unsigned long client_flag; |
| 115 | + char *host; |
| 116 | + char *user; |
| 117 | + char *password; |
| 118 | + char *unix_socket; |
| 119 | + char *db; |
| 120 | + struct st_dynamic_array *init_commands; |
| 121 | + char *my_cnf_file; |
| 122 | + char *my_cnf_group; |
| 123 | + char *charset_dir; |
| 124 | + char *charset_name; |
| 125 | + char *ssl_key; |
| 126 | + char *ssl_cert; |
| 127 | + char *ssl_ca; |
| 128 | + char *ssl_capath; |
| 129 | + char *ssl_cipher; |
| 130 | + char *shared_memory_base_name; |
| 131 | + unsigned long max_allowed_packet; |
| 132 | + my_bool use_ssl; |
| 133 | + my_bool compress,named_pipe; |
| 134 | + my_bool rpl_probe; |
| 135 | + my_bool rpl_parse; |
| 136 | + my_bool no_master_reads; |
| 137 | +#if !defined(CHECK_EMBEDDED_DIFFERENCES) || defined(EMBEDDED_LIBRARY) |
| 138 | + my_bool separate_thread; |
| 139 | +#endif |
| 140 | + enum mysql_option methods_to_use; |
| 141 | + char *client_ip; |
| 142 | + my_bool secure_auth; |
| 143 | + my_bool report_data_truncation; |
| 144 | + int (*local_infile_init)(void **, const char *, void *); |
| 145 | + int (*local_infile_read)(void *, char *, unsigned int); |
| 146 | + void (*local_infile_end)(void *); |
| 147 | + int (*local_infile_error)(void *, char *, unsigned int); |
| 148 | + void *local_infile_userdata; |
| 149 | + void *extension; |
| 150 | +}; |
| 151 | + |
| 152 | +struct st_net { |
| 153 | +#if !defined(CHECK_EMBEDDED_DIFFERENCES) || !defined(EMBEDDED_LIBRARY) |
| 154 | + Vio *vio; |
| 155 | + unsigned char *buff; |
| 156 | + unsigned char *buff_end; |
| 157 | + unsigned char *write_pos; |
| 158 | + unsigned char *read_pos; |
| 159 | + my_socket fd; |
| 160 | + unsigned long remain_in_buf; |
| 161 | + unsigned long length; |
| 162 | + unsigned long buf_length; |
| 163 | + unsigned long where_b; |
| 164 | + unsigned long max_packet; |
| 165 | + unsigned long max_packet_size; |
| 166 | + unsigned int pkt_nr; |
| 167 | + unsigned int compress_pkt_nr; |
| 168 | + unsigned int write_timeout; |
| 169 | + unsigned int read_timeout; |
| 170 | + unsigned int retry_count; |
| 171 | + int fcntl; |
| 172 | + unsigned int *return_status; |
| 173 | + unsigned char reading_or_writing; |
| 174 | + char save_char; |
| 175 | + my_bool unused0; |
| 176 | + my_bool unused; |
| 177 | + my_bool compress; |
| 178 | + my_bool unused1; |
| 179 | +#endif |
| 180 | + unsigned char *query_cache_query; |
| 181 | + unsigned int last_errno; |
| 182 | + unsigned char error; |
| 183 | + my_bool unused2; |
| 184 | + my_bool return_errno; |
| 185 | + char last_error[MYSQL_ERRMSG_SIZE]; |
| 186 | + char sqlstate[SQLSTATE_LENGTH+1]; |
| 187 | + void *extension; |
| 188 | +#if defined(MYSQL_SERVER) && !defined(EMBEDDED_LIBRARY) |
| 189 | + my_bool skip_big_packet; |
| 190 | +#endif |
| 191 | +}; |
| 192 | + |
| 193 | +/* |
| 194 | + * st_mysql differs between 5.0 and 5.1, but the 5.0 version is a |
| 195 | + * strict subset, we don't use any of the 5.1 fields, and we don't |
| 196 | + * ever allocate the structure ourselves. |
| 197 | + */ |
| 198 | + |
| 199 | +struct st_mysql { |
| 200 | + NET net; |
| 201 | + unsigned char *connector_fd; |
| 202 | + char *host; |
| 203 | + char *user; |
| 204 | + char *passwd; |
| 205 | + char *unix_socket; |
| 206 | + char *server_version; |
| 207 | + char *host_info; |
| 208 | + char *info; |
| 209 | + char *db; |
| 210 | + struct charset_info_st *charset; |
| 211 | + MYSQL_FIELD *fields; |
| 212 | + MEM_ROOT field_alloc; |
| 213 | + my_ulonglong affected_rows; |
| 214 | + my_ulonglong insert_id; |
| 215 | + my_ulonglong extra_info; |
| 216 | + unsigned long thread_id; |
| 217 | + unsigned long packet_length; |
| 218 | + unsigned int port; |
| 219 | + unsigned long client_flag; |
| 220 | + unsigned long server_capabilities; |
| 221 | + unsigned int protocol_version; |
| 222 | + unsigned int field_count; |
| 223 | + unsigned int server_status; |
| 224 | + unsigned int server_language; |
| 225 | + unsigned int warning_count; |
| 226 | + struct st_mysql_options options; |
| 227 | + enum mysql_status status; |
| 228 | + my_bool free_me; |
| 229 | + my_bool reconnect; |
| 230 | + char scramble[SCRAMBLE_LENGTH+1]; |
| 231 | + my_bool rpl_pivot; |
| 232 | + struct st_mysql *master; |
| 233 | + struct st_mysql *next_slave; |
| 234 | + struct st_mysql* last_used_slave; |
| 235 | + struct st_mysql* last_used_con; |
| 236 | + LIST *stmts; |
| 237 | + const struct st_mysql_methods *methods; |
| 238 | + void *thd; |
| 239 | + my_bool *unbuffered_fetch_owner; |
| 240 | + char *info_buffer; |
| 241 | +}; |
| 242 | + |
| 243 | +/* |
| 244 | + * There are different version of the MYSQL_BIND structure before and after |
| 245 | + * MySQL 5.1. We go after the fields of the structure using accessor functions |
| 246 | + * so that the code in this file is compatible with both versions. |
| 247 | + */ |
| 248 | + |
| 249 | +struct st_mysql_bind_51 { /* Post-5.1 */ |
| 250 | + unsigned long* length; |
| 251 | + my_bool* is_null; |
| 252 | + void* buffer; |
| 253 | + my_bool* error; |
| 254 | + unsigned char* row_ptr; |
| 255 | + void (*store_param_func)(NET* net, MYSQL_BIND* param); |
| 256 | + void (*fetch_result)(MYSQL_BIND*, MYSQL_FIELD*, unsigned char**); |
| 257 | + void (*skip_result)(MYSQL_BIND*, MYSQL_FIELD*, unsigned char**); |
| 258 | + unsigned long buffer_length; |
| 259 | + unsigned long offset; |
| 260 | + unsigned long length_value; |
| 261 | + unsigned int param_number; |
| 262 | + unsigned int pack_length; |
| 263 | + enum enum_field_types buffer_type; |
| 264 | + my_bool error_value; |
| 265 | + my_bool is_unsigned; |
| 266 | + my_bool long_data_used; |
| 267 | + my_bool is_null_value; |
| 268 | + void* extension; |
| 269 | +}; |
| 270 | + |
| 271 | +struct st_mysql_bind_50 { /* Pre-5.1 */ |
| 272 | + unsigned long* length; |
| 273 | + my_bool* is_null; |
| 274 | + void* buffer; |
| 275 | + my_bool* error; |
| 276 | + enum enum_field_types buffer_type; |
| 277 | + unsigned long buffer_length; |
| 278 | + unsigned char* row_ptr; |
| 279 | + unsigned long offset; |
| 280 | + unsigned long length_value; |
| 281 | + unsigned int param_number; |
| 282 | + unsigned int pack_length; |
| 283 | + my_bool error_value; |
| 284 | + my_bool is_unsigned; |
| 285 | + my_bool long_data_used; |
| 286 | + my_bool is_null_value; |
| 287 | + void (*store_param_func)(NET* net, MYSQL_BIND* param); |
| 288 | + void (*fetch_result)(MYSQL_BIND*, MYSQL_FIELD*, unsigned char**); |
| 289 | + void (*skip_result)(MYSQL_BIND*, MYSQL_FIELD*, unsigned char**); |
| 290 | +}; |
| 291 | + |
| 292 | +/* |
| 293 | + * There are also different versions of the MYSQL_FIELD structure; fortunately, |
| 294 | + * the 5.1 version is a strict extension of the 5.0 version. |
| 295 | + */ |
| 296 | + |
| 297 | +struct st_mysql_field { |
| 298 | + char* name; |
| 299 | + char *org_name; |
| 300 | + char* table; |
| 301 | + char* org_table; |
| 302 | + char* db; |
| 303 | + char* catalog; |
| 304 | + char* def; |
| 305 | + unsigned long length; |
| 306 | + unsigned long max_length; |
| 307 | + unsigned int name_length; |
| 308 | + unsigned int org_name_length; |
| 309 | + unsigned int table_length; |
| 310 | + unsigned int org_table_length; |
| 311 | + unsigned int db_length; |
| 312 | + unsigned int catalog_length; |
| 313 | + unsigned int def_length; |
| 314 | + unsigned int flags; |
| 315 | + unsigned int decimals; |
| 316 | + unsigned int charsetnr; |
| 317 | + enum enum_field_types type; |
| 318 | +}; |
| 319 | +struct st_mysql_field_50 { |
| 320 | + struct st_mysql_field field; |
| 321 | +}; |
| 322 | +struct st_mysql_field_51 { |
| 323 | + struct st_mysql_field field; |
| 324 | + void* extension; |
| 325 | +}; |
| 326 | +#define NOT_NULL_FLAG 1 |
| 327 | + |
| 328 | +#define IS_NUM(t) ((t) <= MYSQL_TYPE_INT24 || (t) == MYSQL_TYPE_YEAR || (t) == MYSQL_TYPE_NEWDECIMAL) |
| 329 | + |
| 330 | +#define mysql_library_init mysql_server_init |
| 331 | +#define mysql_library_end mysql_server_end |
| 332 | + |
| 333 | +#include "mysqlStubs.h" |
| 334 | + |
| 335 | +#endif /* not FAKEMYSQL_H_INCLUDED */ |
0 commit comments