fakemysql.h 8.7 KB

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