Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

312 lines
10 KiB

  1. /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
  2. This library is free software; you can redistribute it and/or
  3. modify it under the terms of the GNU Library General Public
  4. License as published by the Free Software Foundation; either
  5. version 2 of the License, or (at your option) any later version.
  6. This library is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9. Library General Public License for more details.
  10. You should have received a copy of the GNU Library General Public
  11. License along with this library; if not, write to the Free
  12. Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  13. MA 02111-1307, USA */
  14. /* defines for the libmysql library */
  15. #ifndef _mysql_h
  16. #define _mysql_h
  17. #ifdef __CYGWIN__ /* CYGWIN implements a UNIX API */
  18. #undef WIN
  19. #undef _WIN
  20. #undef _WIN32
  21. #undef _WIN64
  22. #undef __WIN__
  23. #endif
  24. #ifndef MYSQL_SERVER
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. #endif
  29. #ifndef _global_h /* If not standard header */
  30. #include <sys/types.h>
  31. #ifdef __LCC__
  32. #include <winsock.h> /* For windows */
  33. #endif
  34. typedef char my_bool;
  35. #if (defined(_WIN32) || defined(_WIN64)) && !defined(__WIN__)
  36. #define __WIN__
  37. #endif
  38. #if !defined(__WIN__)
  39. #define STDCALL
  40. #else
  41. #define STDCALL __stdcall
  42. #endif
  43. typedef char * gptr;
  44. #ifndef ST_USED_MEM_DEFINED
  45. #define ST_USED_MEM_DEFINED
  46. typedef struct st_used_mem { /* struct for once_alloc */
  47. struct st_used_mem *next; /* Next block in use */
  48. unsigned int left; /* memory left in block */
  49. unsigned int size; /* size of block */
  50. } USED_MEM;
  51. typedef struct st_mem_root {
  52. USED_MEM *free;
  53. USED_MEM *used;
  54. USED_MEM *pre_alloc;
  55. unsigned int min_malloc;
  56. unsigned int block_size;
  57. void (*error_handler)(void);
  58. } MEM_ROOT;
  59. #endif
  60. #ifndef my_socket_defined
  61. #ifdef __WIN__
  62. #define my_socket SOCKET
  63. #else
  64. typedef int my_socket;
  65. #endif
  66. #endif
  67. #endif
  68. #include "mysql_com.h"
  69. #include "mysql_version.h"
  70. extern unsigned int mysql_port;
  71. extern char *mysql_unix_port;
  72. #define IS_PRI_KEY(n) ((n) & PRI_KEY_FLAG)
  73. #define IS_NOT_NULL(n) ((n) & NOT_NULL_FLAG)
  74. #define IS_BLOB(n) ((n) & BLOB_FLAG)
  75. #define IS_NUM(t) ((t) <= FIELD_TYPE_INT24 || (t) == FIELD_TYPE_YEAR)
  76. #define IS_NUM_FIELD(f) ((f)->flags & NUM_FLAG)
  77. #define INTERNAL_NUM_FIELD(f) (((f)->type <= FIELD_TYPE_INT24 && ((f)->type != FIELD_TYPE_TIMESTAMP || (f)->length == 14 || (f)->length == 8)) || (f)->type == FIELD_TYPE_YEAR)
  78. typedef struct st_mysql_field {
  79. char *name; /* Name of column */
  80. char *table; /* Table of column if column was a field */
  81. char *def; /* Default value (set by mysql_list_fields) */
  82. enum enum_field_types type; /* Type of field. Se mysql_com.h for types */
  83. unsigned int length; /* Width of column */
  84. unsigned int max_length; /* Max width of selected set */
  85. unsigned int flags; /* Div flags */
  86. unsigned int decimals; /* Number of decimals in field */
  87. } MYSQL_FIELD;
  88. typedef char **MYSQL_ROW; /* return data as array of strings */
  89. typedef unsigned int MYSQL_FIELD_OFFSET; /* offset to current field */
  90. #if defined(NO_CLIENT_LONG_LONG)
  91. typedef unsigned long my_ulonglong;
  92. #elif defined (__WIN__)
  93. typedef unsigned __int64 my_ulonglong;
  94. #else
  95. typedef unsigned long long my_ulonglong;
  96. #endif
  97. #define MYSQL_COUNT_ERROR (~(my_ulonglong) 0)
  98. typedef struct st_mysql_rows {
  99. struct st_mysql_rows *next; /* list of rows */
  100. MYSQL_ROW data;
  101. } MYSQL_ROWS;
  102. typedef MYSQL_ROWS *MYSQL_ROW_OFFSET; /* offset to current row */
  103. typedef struct st_mysql_data {
  104. my_ulonglong rows;
  105. unsigned int fields;
  106. MYSQL_ROWS *data;
  107. MEM_ROOT alloc;
  108. } MYSQL_DATA;
  109. struct st_mysql_options {
  110. unsigned int connect_timeout,client_flag;
  111. my_bool compress,named_pipe;
  112. unsigned int port;
  113. char *host,*init_command,*user,*password,*unix_socket,*db;
  114. char *my_cnf_file,*my_cnf_group, *charset_dir, *charset_name;
  115. my_bool use_ssl; /* if to use SSL or not */
  116. char *ssl_key; /* PEM key file */
  117. char *ssl_cert; /* PEM cert file */
  118. char *ssl_ca; /* PEM CA file */
  119. char *ssl_capath; /* PEM directory of CA-s? */
  120. };
  121. enum mysql_option { MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS,
  122. MYSQL_OPT_NAMED_PIPE, MYSQL_INIT_COMMAND,
  123. MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP,
  124. MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME,
  125. MYSQL_OPT_LOCAL_INFILE};
  126. enum mysql_status { MYSQL_STATUS_READY,MYSQL_STATUS_GET_RESULT,
  127. MYSQL_STATUS_USE_RESULT};
  128. typedef struct st_mysql {
  129. NET net; /* Communication parameters */
  130. gptr connector_fd; /* ConnectorFd for SSL */
  131. char *host,*user,*passwd,*unix_socket,*server_version,*host_info,
  132. *info,*db;
  133. unsigned int port,client_flag,server_capabilities;
  134. unsigned int protocol_version;
  135. unsigned int field_count;
  136. unsigned int server_status;
  137. unsigned long thread_id; /* Id for connection in server */
  138. my_ulonglong affected_rows;
  139. my_ulonglong insert_id; /* id if insert on table with NEXTNR */
  140. my_ulonglong extra_info; /* Used by mysqlshow */
  141. unsigned long packet_length;
  142. enum mysql_status status;
  143. MYSQL_FIELD *fields;
  144. MEM_ROOT field_alloc;
  145. my_bool free_me; /* If free in mysql_close */
  146. my_bool reconnect; /* set to 1 if automatic reconnect */
  147. struct st_mysql_options options;
  148. char scramble_buff[9];
  149. struct charset_info_st *charset;
  150. unsigned int server_language;
  151. } MYSQL;
  152. typedef struct st_mysql_res {
  153. my_ulonglong row_count;
  154. unsigned int field_count, current_field;
  155. MYSQL_FIELD *fields;
  156. MYSQL_DATA *data;
  157. MYSQL_ROWS *data_cursor;
  158. MEM_ROOT field_alloc;
  159. MYSQL_ROW row; /* If unbuffered read */
  160. MYSQL_ROW current_row; /* buffer to current row */
  161. unsigned long *lengths; /* column lengths of current row */
  162. MYSQL *handle; /* for unbuffered reads */
  163. my_bool eof; /* Used my mysql_fetch_row */
  164. } MYSQL_RES;
  165. /* Functions to get information from the MYSQL and MYSQL_RES structures */
  166. /* Should definitely be used if one uses shared libraries */
  167. my_ulonglong STDCALL mysql_num_rows(MYSQL_RES *res);
  168. unsigned int STDCALL mysql_num_fields(MYSQL_RES *res);
  169. my_bool STDCALL mysql_eof(MYSQL_RES *res);
  170. MYSQL_FIELD *STDCALL mysql_fetch_field_direct(MYSQL_RES *res,
  171. unsigned int fieldnr);
  172. MYSQL_FIELD * STDCALL mysql_fetch_fields(MYSQL_RES *res);
  173. MYSQL_ROWS * STDCALL mysql_row_tell(MYSQL_RES *res);
  174. unsigned int STDCALL mysql_field_tell(MYSQL_RES *res);
  175. unsigned int STDCALL mysql_field_count(MYSQL *mysql);
  176. my_ulonglong STDCALL mysql_affected_rows(MYSQL *mysql);
  177. my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql);
  178. unsigned int STDCALL mysql_errno(MYSQL *mysql);
  179. char * STDCALL mysql_error(MYSQL *mysql);
  180. char * STDCALL mysql_info(MYSQL *mysql);
  181. unsigned long STDCALL mysql_thread_id(MYSQL *mysql);
  182. const char * STDCALL mysql_character_set_name(MYSQL *mysql);
  183. MYSQL * STDCALL mysql_init(MYSQL *mysql);
  184. #ifdef HAVE_OPENSSL
  185. int STDCALL mysql_ssl_set(MYSQL *mysql, const char *key,
  186. const char *cert, const char *ca,
  187. const char *capath);
  188. char * STDCALL mysql_ssl_cipher(MYSQL *mysql);
  189. int STDCALL mysql_ssl_clear(MYSQL *mysql);
  190. #endif /* HAVE_OPENSSL */
  191. MYSQL * STDCALL mysql_connect(MYSQL *mysql, const char *host,
  192. const char *user, const char *passwd);
  193. my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user,
  194. const char *passwd, const char *db);
  195. #if MYSQL_VERSION_ID >= 32200
  196. MYSQL * STDCALL mysql_real_connect(MYSQL *mysql, const char *host,
  197. const char *user,
  198. const char *passwd,
  199. const char *db,
  200. unsigned int port,
  201. const char *unix_socket,
  202. unsigned int clientflag);
  203. #else
  204. MYSQL * STDCALL mysql_real_connect(MYSQL *mysql, const char *host,
  205. const char *user,
  206. const char *passwd,
  207. unsigned int port,
  208. const char *unix_socket,
  209. unsigned int clientflag);
  210. #endif
  211. void STDCALL mysql_close(MYSQL *sock);
  212. int STDCALL mysql_select_db(MYSQL *mysql, const char *db);
  213. int STDCALL mysql_query(MYSQL *mysql, const char *q);
  214. int STDCALL mysql_send_query(MYSQL *mysql, const char *q,
  215. unsigned int length);
  216. int STDCALL mysql_read_query_result(MYSQL *mysql);
  217. int STDCALL mysql_real_query(MYSQL *mysql, const char *q,
  218. unsigned int length);
  219. int STDCALL mysql_create_db(MYSQL *mysql, const char *DB);
  220. int STDCALL mysql_drop_db(MYSQL *mysql, const char *DB);
  221. int STDCALL mysql_shutdown(MYSQL *mysql);
  222. int STDCALL mysql_dump_debug_info(MYSQL *mysql);
  223. int STDCALL mysql_refresh(MYSQL *mysql,
  224. unsigned int refresh_options);
  225. int STDCALL mysql_kill(MYSQL *mysql,unsigned long pid);
  226. int STDCALL mysql_ping(MYSQL *mysql);
  227. char * STDCALL mysql_stat(MYSQL *mysql);
  228. char * STDCALL mysql_get_server_info(MYSQL *mysql);
  229. char * STDCALL mysql_get_client_info(void);
  230. char * STDCALL mysql_get_host_info(MYSQL *mysql);
  231. unsigned int STDCALL mysql_get_proto_info(MYSQL *mysql);
  232. MYSQL_RES * STDCALL mysql_list_dbs(MYSQL *mysql,const char *wild);
  233. MYSQL_RES * STDCALL mysql_list_tables(MYSQL *mysql,const char *wild);
  234. MYSQL_RES * STDCALL mysql_list_fields(MYSQL *mysql, const char *table,
  235. const char *wild);
  236. MYSQL_RES * STDCALL mysql_list_processes(MYSQL *mysql);
  237. MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql);
  238. MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql);
  239. int STDCALL mysql_options(MYSQL *mysql,enum mysql_option option,
  240. const char *arg);
  241. void STDCALL mysql_free_result(MYSQL_RES *result);
  242. void STDCALL mysql_data_seek(MYSQL_RES *result,
  243. my_ulonglong offset);
  244. MYSQL_ROW_OFFSET STDCALL mysql_row_seek(MYSQL_RES *result, MYSQL_ROW_OFFSET);
  245. MYSQL_FIELD_OFFSET STDCALL mysql_field_seek(MYSQL_RES *result,
  246. MYSQL_FIELD_OFFSET offset);
  247. MYSQL_ROW STDCALL mysql_fetch_row(MYSQL_RES *result);
  248. unsigned long * STDCALL mysql_fetch_lengths(MYSQL_RES *result);
  249. MYSQL_FIELD * STDCALL mysql_fetch_field(MYSQL_RES *result);
  250. unsigned long STDCALL mysql_escape_string(char *to,const char *from,
  251. unsigned long from_length);
  252. unsigned long STDCALL mysql_real_escape_string(MYSQL *mysql,
  253. char *to,const char *from,
  254. unsigned long length);
  255. void STDCALL mysql_debug(const char *debug);
  256. char * STDCALL mysql_odbc_escape_string(MYSQL *mysql,
  257. char *to,
  258. unsigned long to_length,
  259. const char *from,
  260. unsigned long from_length,
  261. void *param,
  262. char *
  263. (*extend_buffer)
  264. (void *, char *to,
  265. unsigned long *length));
  266. void STDCALL myodbc_remove_escape(MYSQL *mysql,char *name);
  267. unsigned int STDCALL mysql_thread_safe(void);
  268. #define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT)
  269. /* new api functions */
  270. #define HAVE_MYSQL_REAL_CONNECT
  271. #ifndef MYSQL_SERVER
  272. #ifdef __cplusplus
  273. }
  274. #endif
  275. #endif
  276. #endif