PageRenderTime 92ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/dep/mysqllite/include/mysql.h

https://bitbucket.org/oneb1t/crocoduckcore/
C++ Header | 869 lines | 577 code | 88 blank | 204 comment | 19 complexity | 8d559426165edc7661b725ba922def40 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. /* Copyright (C) 2000-2003 MySQL AB
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with this program; if not, write to the Free Software
  11. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
  12. /*
  13. This file defines the client API to MySQL and also the ABI of the
  14. dynamically linked libmysqlclient.
  15. The ABI should never be changed in a released product of MySQL
  16. thus you need to take great care when changing the file. In case
  17. the file is changed so the ABI is broken, you must also
  18. update the SHAREDLIB_MAJOR_VERSION in configure.in .
  19. */
  20. #ifndef _mysql_h
  21. #define _mysql_h
  22. #ifdef _AIX /* large-file support will break without this */
  23. #include <standards.h>
  24. #endif
  25. #ifdef __CYGWIN__ /* CYGWIN implements a UNIX API */
  26. #undef WIN
  27. #undef _WIN
  28. #undef _WIN32
  29. #undef _WIN64
  30. #undef __WIN__
  31. #endif
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. #ifndef _global_h /* If not standard header */
  36. #ifndef MYSQL_ABI_CHECK
  37. #include <sys/types.h>
  38. #endif
  39. #ifdef __LCC__
  40. #include <winsock2.h> /* For windows */
  41. #endif
  42. typedef char my_bool;
  43. #if (defined(_WIN32) || defined(_WIN64)) && !defined(__WIN__)
  44. #define __WIN__
  45. #endif
  46. #if !defined(__WIN__)
  47. #define STDCALL
  48. #else
  49. #define STDCALL __stdcall
  50. #endif
  51. #ifndef my_socket_defined
  52. #ifdef __WIN__
  53. #define my_socket SOCKET
  54. #else
  55. typedef int my_socket;
  56. #endif /* __WIN__ */
  57. #endif /* my_socket_defined */
  58. #endif /* _global_h */
  59. /*#include "mysql_version.h"*/
  60. #include "mysql_com.h"
  61. #include "mysql_time.h"
  62. #include "my_list.h" /* for LISTs used in 'MYSQL' and 'MYSQL_STMT' */
  63. extern unsigned int mysql_port;
  64. extern char *mysql_unix_port;
  65. #define CLIENT_NET_READ_TIMEOUT 365*24*3600 /* Timeout on read */
  66. #define CLIENT_NET_WRITE_TIMEOUT 365*24*3600 /* Timeout on write */
  67. #ifdef __NETWARE__
  68. #pragma pack(push, 8) /* 8 byte alignment */
  69. #endif
  70. #define IS_PRI_KEY(n) ((n) & PRI_KEY_FLAG)
  71. #define IS_NOT_NULL(n) ((n) & NOT_NULL_FLAG)
  72. #define IS_BLOB(n) ((n) & BLOB_FLAG)
  73. #define IS_NUM(t) ((t) <= MYSQL_TYPE_INT24 || (t) == MYSQL_TYPE_YEAR || (t) == MYSQL_TYPE_NEWDECIMAL)
  74. #define IS_NUM_FIELD(f) ((f)->flags & NUM_FLAG)
  75. #define INTERNAL_NUM_FIELD(f) (((f)->type <= MYSQL_TYPE_INT24 && ((f)->type != MYSQL_TYPE_TIMESTAMP || (f)->length == 14 || (f)->length == 8)) || (f)->type == MYSQL_TYPE_YEAR)
  76. #define IS_LONGDATA(t) ((t) >= MYSQL_TYPE_TINY_BLOB && (t) <= MYSQL_TYPE_STRING)
  77. typedef struct st_mysql_field {
  78. char *name; /* Name of column */
  79. char *org_name; /* Original column name, if an alias */
  80. char *table; /* Table of column if column was a field */
  81. char *org_table; /* Org table name, if table was an alias */
  82. char *db; /* Database for table */
  83. char *catalog; /* Catalog for table */
  84. char *def; /* Default value (set by mysql_list_fields) */
  85. unsigned long length; /* Width of column (create length) */
  86. unsigned long max_length; /* Max width for selected set */
  87. unsigned int name_length;
  88. unsigned int org_name_length;
  89. unsigned int table_length;
  90. unsigned int org_table_length;
  91. unsigned int db_length;
  92. unsigned int catalog_length;
  93. unsigned int def_length;
  94. unsigned int flags; /* Div flags */
  95. unsigned int decimals; /* Number of decimals in field */
  96. unsigned int charsetnr; /* Character set */
  97. enum enum_field_types type; /* Type of field. See mysql_com.h for types */
  98. void *extension;
  99. } MYSQL_FIELD;
  100. typedef char **MYSQL_ROW; /* return data as array of strings */
  101. typedef unsigned int MYSQL_FIELD_OFFSET; /* offset to current field */
  102. #ifndef _global_h
  103. #if defined(NO_CLIENT_LONG_LONG)
  104. typedef unsigned long my_ulonglong;
  105. #elif defined (__WIN__)
  106. typedef unsigned __int64 my_ulonglong;
  107. #else
  108. typedef unsigned long long my_ulonglong;
  109. #endif
  110. #endif
  111. #include "typelib.h"
  112. #define MYSQL_COUNT_ERROR (~(my_ulonglong) 0)
  113. /* backward compatibility define - to be removed eventually */
  114. #define ER_WARN_DATA_TRUNCATED WARN_DATA_TRUNCATED
  115. typedef struct st_mysql_rows {
  116. struct st_mysql_rows *next; /* list of rows */
  117. MYSQL_ROW data;
  118. unsigned long length;
  119. } MYSQL_ROWS;
  120. typedef MYSQL_ROWS *MYSQL_ROW_OFFSET; /* offset to current row */
  121. #include "my_alloc.h"
  122. typedef struct embedded_query_result EMBEDDED_QUERY_RESULT;
  123. typedef struct st_mysql_data {
  124. MYSQL_ROWS *data;
  125. struct embedded_query_result *embedded_info;
  126. MEM_ROOT alloc;
  127. my_ulonglong rows;
  128. unsigned int fields;
  129. /* extra info for embedded library */
  130. void *extension;
  131. } MYSQL_DATA;
  132. enum mysql_option
  133. {
  134. MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS, MYSQL_OPT_NAMED_PIPE,
  135. MYSQL_INIT_COMMAND, MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP,
  136. MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME, MYSQL_OPT_LOCAL_INFILE,
  137. MYSQL_OPT_PROTOCOL, MYSQL_SHARED_MEMORY_BASE_NAME, MYSQL_OPT_READ_TIMEOUT,
  138. MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_USE_RESULT,
  139. MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION,
  140. MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH,
  141. MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT,
  142. MYSQL_OPT_SSL_VERIFY_SERVER_CERT
  143. };
  144. struct st_mysql_options {
  145. unsigned int connect_timeout, read_timeout, write_timeout;
  146. unsigned int port, protocol;
  147. unsigned long client_flag;
  148. char *host,*user,*password,*unix_socket,*db;
  149. struct st_dynamic_array *init_commands;
  150. char *my_cnf_file,*my_cnf_group, *charset_dir, *charset_name;
  151. char *ssl_key; /* PEM key file */
  152. char *ssl_cert; /* PEM cert file */
  153. char *ssl_ca; /* PEM CA file */
  154. char *ssl_capath; /* PEM directory of CA-s? */
  155. char *ssl_cipher; /* cipher to use */
  156. char *shared_memory_base_name;
  157. unsigned long max_allowed_packet;
  158. my_bool use_ssl; /* if to use SSL or not */
  159. my_bool compress,named_pipe;
  160. /*
  161. On connect, find out the replication role of the server, and
  162. establish connections to all the peers
  163. */
  164. my_bool rpl_probe;
  165. /*
  166. Each call to mysql_real_query() will parse it to tell if it is a read
  167. or a write, and direct it to the slave or the master
  168. */
  169. my_bool rpl_parse;
  170. /*
  171. If set, never read from a master, only from slave, when doing
  172. a read that is replication-aware
  173. */
  174. my_bool no_master_reads;
  175. #if !defined(CHECK_EMBEDDED_DIFFERENCES) || defined(EMBEDDED_LIBRARY)
  176. my_bool separate_thread;
  177. #endif
  178. enum mysql_option methods_to_use;
  179. char *client_ip;
  180. /* Refuse client connecting to server if it uses old (pre-4.1.1) protocol */
  181. my_bool secure_auth;
  182. /* 0 - never report, 1 - always report (default) */
  183. my_bool report_data_truncation;
  184. /* function pointers for local infile support */
  185. int (*local_infile_init)(void **, const char *, void *);
  186. int (*local_infile_read)(void *, char *, unsigned int);
  187. void (*local_infile_end)(void *);
  188. int (*local_infile_error)(void *, char *, unsigned int);
  189. void *local_infile_userdata;
  190. void *extension;
  191. };
  192. enum mysql_status
  193. {
  194. MYSQL_STATUS_READY,MYSQL_STATUS_GET_RESULT,MYSQL_STATUS_USE_RESULT
  195. };
  196. enum mysql_protocol_type
  197. {
  198. MYSQL_PROTOCOL_DEFAULT, MYSQL_PROTOCOL_TCP, MYSQL_PROTOCOL_SOCKET,
  199. MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_MEMORY
  200. };
  201. /*
  202. There are three types of queries - the ones that have to go to
  203. the master, the ones that go to a slave, and the adminstrative
  204. type which must happen on the pivot connectioin
  205. */
  206. enum mysql_rpl_type
  207. {
  208. MYSQL_RPL_MASTER, MYSQL_RPL_SLAVE, MYSQL_RPL_ADMIN
  209. };
  210. typedef struct character_set
  211. {
  212. unsigned int number; /* character set number */
  213. unsigned int state; /* character set state */
  214. const char *csname; /* collation name */
  215. const char *name; /* character set name */
  216. const char *comment; /* comment */
  217. const char *dir; /* character set directory */
  218. unsigned int mbminlen; /* min. length for multibyte strings */
  219. unsigned int mbmaxlen; /* max. length for multibyte strings */
  220. } MY_CHARSET_INFO;
  221. struct st_mysql_methods;
  222. struct st_mysql_stmt;
  223. typedef struct st_mysql
  224. {
  225. NET net; /* Communication parameters */
  226. unsigned char *connector_fd; /* ConnectorFd for SSL */
  227. char *host,*user,*passwd,*unix_socket,*server_version,*host_info;
  228. char *info, *db;
  229. struct charset_info_st *charset;
  230. MYSQL_FIELD *fields;
  231. MEM_ROOT field_alloc;
  232. my_ulonglong affected_rows;
  233. my_ulonglong insert_id; /* id if insert on table with NEXTNR */
  234. my_ulonglong extra_info; /* Not used */
  235. unsigned long thread_id; /* Id for connection in server */
  236. unsigned long packet_length;
  237. unsigned int port;
  238. unsigned long client_flag,server_capabilities;
  239. unsigned int protocol_version;
  240. unsigned int field_count;
  241. unsigned int server_status;
  242. unsigned int server_language;
  243. unsigned int warning_count;
  244. struct st_mysql_options options;
  245. enum mysql_status status;
  246. my_bool free_me; /* If free in mysql_close */
  247. my_bool reconnect; /* set to 1 if automatic reconnect */
  248. /* session-wide random string */
  249. char scramble[SCRAMBLE_LENGTH+1];
  250. /*
  251. Set if this is the original connection, not a master or a slave we have
  252. added though mysql_rpl_probe() or mysql_set_master()/ mysql_add_slave()
  253. */
  254. my_bool rpl_pivot;
  255. /*
  256. Pointers to the master, and the next slave connections, points to
  257. itself if lone connection.
  258. */
  259. struct st_mysql* master, *next_slave;
  260. struct st_mysql* last_used_slave; /* needed for round-robin slave pick */
  261. /* needed for send/read/store/use result to work correctly with replication */
  262. struct st_mysql* last_used_con;
  263. LIST *stmts; /* list of all statements */
  264. const struct st_mysql_methods *methods;
  265. void *thd;
  266. /*
  267. Points to boolean flag in MYSQL_RES or MYSQL_STMT. We set this flag
  268. from mysql_stmt_close if close had to cancel result set of this object.
  269. */
  270. my_bool *unbuffered_fetch_owner;
  271. /* needed for embedded server - no net buffer to store the 'info' */
  272. char *info_buffer;
  273. void *extension;
  274. } MYSQL;
  275. typedef struct st_mysql_res {
  276. my_ulonglong row_count;
  277. MYSQL_FIELD *fields;
  278. MYSQL_DATA *data;
  279. MYSQL_ROWS *data_cursor;
  280. unsigned long *lengths; /* column lengths of current row */
  281. MYSQL *handle; /* for unbuffered reads */
  282. const struct st_mysql_methods *methods;
  283. MYSQL_ROW row; /* If unbuffered read */
  284. MYSQL_ROW current_row; /* buffer to current row */
  285. MEM_ROOT field_alloc;
  286. unsigned int field_count, current_field;
  287. my_bool eof; /* Used by mysql_fetch_row */
  288. /* mysql_stmt_close() had to cancel this result */
  289. my_bool unbuffered_fetch_cancelled;
  290. void *extension;
  291. } MYSQL_RES;
  292. #define MAX_MYSQL_MANAGER_ERR 256
  293. #define MAX_MYSQL_MANAGER_MSG 256
  294. #define MANAGER_OK 200
  295. #define MANAGER_INFO 250
  296. #define MANAGER_ACCESS 401
  297. #define MANAGER_CLIENT_ERR 450
  298. #define MANAGER_INTERNAL_ERR 500
  299. #if !defined(MYSQL_SERVER) && !defined(MYSQL_CLIENT)
  300. #define MYSQL_CLIENT
  301. #endif
  302. typedef struct st_mysql_manager
  303. {
  304. NET net;
  305. char *host, *user, *passwd;
  306. char *net_buf, *net_buf_pos, *net_data_end;
  307. unsigned int port;
  308. int cmd_status;
  309. int last_errno;
  310. int net_buf_size;
  311. my_bool free_me;
  312. my_bool eof;
  313. char last_error[MAX_MYSQL_MANAGER_ERR];
  314. void *extension;
  315. } MYSQL_MANAGER;
  316. typedef struct st_mysql_parameters
  317. {
  318. unsigned long *p_max_allowed_packet;
  319. unsigned long *p_net_buffer_length;
  320. void *extension;
  321. } MYSQL_PARAMETERS;
  322. #if !defined(MYSQL_SERVER) && !defined(EMBEDDED_LIBRARY)
  323. #define max_allowed_packet (*mysql_get_parameters()->p_max_allowed_packet)
  324. #define net_buffer_length (*mysql_get_parameters()->p_net_buffer_length)
  325. #endif
  326. /*
  327. Set up and bring down the server; to ensure that applications will
  328. work when linked against either the standard client library or the
  329. embedded server library, these functions should be called.
  330. */
  331. int STDCALL mysql_server_init(int argc, char **argv, char **groups);
  332. void STDCALL mysql_server_end(void);
  333. /*
  334. mysql_server_init/end need to be called when using libmysqld or
  335. libmysqlclient (exactly, mysql_server_init() is called by mysql_init() so
  336. you don't need to call it explicitely; but you need to call
  337. mysql_server_end() to free memory). The names are a bit misleading
  338. (mysql_SERVER* to be used when using libmysqlCLIENT). So we add more general
  339. names which suit well whether you're using libmysqld or libmysqlclient. We
  340. intend to promote these aliases over the mysql_server* ones.
  341. */
  342. #define mysql_library_init mysql_server_init
  343. #define mysql_library_end mysql_server_end
  344. MYSQL_PARAMETERS *STDCALL mysql_get_parameters(void);
  345. /*
  346. Set up and bring down a thread; these function should be called
  347. for each thread in an application which opens at least one MySQL
  348. connection. All uses of the connection(s) should be between these
  349. function calls.
  350. */
  351. my_bool STDCALL mysql_thread_init(void);
  352. void STDCALL mysql_thread_end(void);
  353. /*
  354. Functions to get information from the MYSQL and MYSQL_RES structures
  355. Should definitely be used if one uses shared libraries.
  356. */
  357. my_ulonglong STDCALL mysql_num_rows(MYSQL_RES *res);
  358. unsigned int STDCALL mysql_num_fields(MYSQL_RES *res);
  359. my_bool STDCALL mysql_eof(MYSQL_RES *res);
  360. MYSQL_FIELD *STDCALL mysql_fetch_field_direct(MYSQL_RES *res,
  361. unsigned int fieldnr);
  362. MYSQL_FIELD * STDCALL mysql_fetch_fields(MYSQL_RES *res);
  363. MYSQL_ROW_OFFSET STDCALL mysql_row_tell(MYSQL_RES *res);
  364. MYSQL_FIELD_OFFSET STDCALL mysql_field_tell(MYSQL_RES *res);
  365. unsigned int STDCALL mysql_field_count(MYSQL *mysql);
  366. my_ulonglong STDCALL mysql_affected_rows(MYSQL *mysql);
  367. my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql);
  368. unsigned int STDCALL mysql_errno(MYSQL *mysql);
  369. const char * STDCALL mysql_error(MYSQL *mysql);
  370. const char *STDCALL mysql_sqlstate(MYSQL *mysql);
  371. unsigned int STDCALL mysql_warning_count(MYSQL *mysql);
  372. const char * STDCALL mysql_info(MYSQL *mysql);
  373. unsigned long STDCALL mysql_thread_id(MYSQL *mysql);
  374. const char * STDCALL mysql_character_set_name(MYSQL *mysql);
  375. int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname);
  376. MYSQL * STDCALL mysql_init(MYSQL *mysql);
  377. my_bool STDCALL mysql_ssl_set(MYSQL *mysql, const char *key,
  378. const char *cert, const char *ca,
  379. const char *capath, const char *cipher);
  380. const char * STDCALL mysql_get_ssl_cipher(MYSQL *mysql);
  381. my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user,
  382. const char *passwd, const char *db);
  383. MYSQL * STDCALL mysql_real_connect(MYSQL *mysql, const char *host,
  384. const char *user,
  385. const char *passwd,
  386. const char *db,
  387. unsigned int port,
  388. const char *unix_socket,
  389. unsigned long clientflag);
  390. int STDCALL mysql_select_db(MYSQL *mysql, const char *db);
  391. int STDCALL mysql_query(MYSQL *mysql, const char *q);
  392. int STDCALL mysql_send_query(MYSQL *mysql, const char *q,
  393. unsigned long length);
  394. int STDCALL mysql_real_query(MYSQL *mysql, const char *q,
  395. unsigned long length);
  396. MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql);
  397. MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql);
  398. /* perform query on master */
  399. my_bool STDCALL mysql_master_query(MYSQL *mysql, const char *q,
  400. unsigned long length);
  401. my_bool STDCALL mysql_master_send_query(MYSQL *mysql, const char *q,
  402. unsigned long length);
  403. /* perform query on slave */
  404. my_bool STDCALL mysql_slave_query(MYSQL *mysql, const char *q,
  405. unsigned long length);
  406. my_bool STDCALL mysql_slave_send_query(MYSQL *mysql, const char *q,
  407. unsigned long length);
  408. void STDCALL mysql_get_character_set_info(MYSQL *mysql,
  409. MY_CHARSET_INFO *charset);
  410. /* local infile support */
  411. #define LOCAL_INFILE_ERROR_LEN 512
  412. void
  413. mysql_set_local_infile_handler(MYSQL *mysql,
  414. int (*local_infile_init)(void **, const char *,
  415. void *),
  416. int (*local_infile_read)(void *, char *,
  417. unsigned int),
  418. void (*local_infile_end)(void *),
  419. int (*local_infile_error)(void *, char*,
  420. unsigned int),
  421. void *);
  422. void
  423. mysql_set_local_infile_default(MYSQL *mysql);
  424. /*
  425. enable/disable parsing of all queries to decide if they go on master or
  426. slave
  427. */
  428. void STDCALL mysql_enable_rpl_parse(MYSQL* mysql);
  429. void STDCALL mysql_disable_rpl_parse(MYSQL* mysql);
  430. /* get the value of the parse flag */
  431. int STDCALL mysql_rpl_parse_enabled(MYSQL* mysql);
  432. /* enable/disable reads from master */
  433. void STDCALL mysql_enable_reads_from_master(MYSQL* mysql);
  434. void STDCALL mysql_disable_reads_from_master(MYSQL* mysql);
  435. /* get the value of the master read flag */
  436. my_bool STDCALL mysql_reads_from_master_enabled(MYSQL* mysql);
  437. enum mysql_rpl_type STDCALL mysql_rpl_query_type(const char* q, int len);
  438. /* discover the master and its slaves */
  439. my_bool STDCALL mysql_rpl_probe(MYSQL* mysql);
  440. /* set the master, close/free the old one, if it is not a pivot */
  441. int STDCALL mysql_set_master(MYSQL* mysql, const char* host,
  442. unsigned int port,
  443. const char* user,
  444. const char* passwd);
  445. int STDCALL mysql_add_slave(MYSQL* mysql, const char* host,
  446. unsigned int port,
  447. const char* user,
  448. const char* passwd);
  449. int STDCALL mysql_shutdown(MYSQL *mysql,
  450. enum mysql_enum_shutdown_level
  451. shutdown_level);
  452. int STDCALL mysql_dump_debug_info(MYSQL *mysql);
  453. int STDCALL mysql_refresh(MYSQL *mysql,
  454. unsigned int refresh_options);
  455. int STDCALL mysql_kill(MYSQL *mysql,unsigned long pid);
  456. int STDCALL mysql_set_server_option(MYSQL *mysql,
  457. enum enum_mysql_set_option
  458. option);
  459. int STDCALL mysql_ping(MYSQL *mysql);
  460. const char * STDCALL mysql_stat(MYSQL *mysql);
  461. const char * STDCALL mysql_get_server_info(MYSQL *mysql);
  462. const char * STDCALL mysql_get_client_info(void);
  463. unsigned long STDCALL mysql_get_client_version(void);
  464. const char * STDCALL mysql_get_host_info(MYSQL *mysql);
  465. unsigned long STDCALL mysql_get_server_version(MYSQL *mysql);
  466. unsigned int STDCALL mysql_get_proto_info(MYSQL *mysql);
  467. MYSQL_RES * STDCALL mysql_list_dbs(MYSQL *mysql,const char *wild);
  468. MYSQL_RES * STDCALL mysql_list_tables(MYSQL *mysql,const char *wild);
  469. MYSQL_RES * STDCALL mysql_list_processes(MYSQL *mysql);
  470. int STDCALL mysql_options(MYSQL *mysql,enum mysql_option option,
  471. const void *arg);
  472. void STDCALL mysql_free_result(MYSQL_RES *result);
  473. void STDCALL mysql_data_seek(MYSQL_RES *result,
  474. my_ulonglong offset);
  475. MYSQL_ROW_OFFSET STDCALL mysql_row_seek(MYSQL_RES *result,
  476. MYSQL_ROW_OFFSET offset);
  477. MYSQL_FIELD_OFFSET STDCALL mysql_field_seek(MYSQL_RES *result,
  478. MYSQL_FIELD_OFFSET offset);
  479. MYSQL_ROW STDCALL mysql_fetch_row(MYSQL_RES *result);
  480. unsigned long * STDCALL mysql_fetch_lengths(MYSQL_RES *result);
  481. MYSQL_FIELD * STDCALL mysql_fetch_field(MYSQL_RES *result);
  482. MYSQL_RES * STDCALL mysql_list_fields(MYSQL *mysql, const char *table,
  483. const char *wild);
  484. unsigned long STDCALL mysql_escape_string(char *to,const char *from,
  485. unsigned long from_length);
  486. unsigned long STDCALL mysql_hex_string(char *to,const char *from,
  487. unsigned long from_length);
  488. unsigned long STDCALL mysql_real_escape_string(MYSQL *mysql,
  489. char *to,const char *from,
  490. unsigned long length);
  491. void STDCALL mysql_debug(const char *debug);
  492. void STDCALL myodbc_remove_escape(MYSQL *mysql,char *name);
  493. unsigned int STDCALL mysql_thread_safe(void);
  494. my_bool STDCALL mysql_embedded(void);
  495. MYSQL_MANAGER* STDCALL mysql_manager_init(MYSQL_MANAGER* con);
  496. MYSQL_MANAGER* STDCALL mysql_manager_connect(MYSQL_MANAGER* con,
  497. const char* host,
  498. const char* user,
  499. const char* passwd,
  500. unsigned int port);
  501. void STDCALL mysql_manager_close(MYSQL_MANAGER* con);
  502. int STDCALL mysql_manager_command(MYSQL_MANAGER* con,
  503. const char* cmd, int cmd_len);
  504. int STDCALL mysql_manager_fetch_line(MYSQL_MANAGER* con,
  505. char* res_buf,
  506. int res_buf_size);
  507. my_bool STDCALL mysql_read_query_result(MYSQL *mysql);
  508. /*
  509. The following definitions are added for the enhanced
  510. client-server protocol
  511. */
  512. /* statement state */
  513. enum enum_mysql_stmt_state
  514. {
  515. MYSQL_STMT_INIT_DONE= 1, MYSQL_STMT_PREPARE_DONE, MYSQL_STMT_EXECUTE_DONE,
  516. MYSQL_STMT_FETCH_DONE
  517. };
  518. /*
  519. This structure is used to define bind information, and
  520. internally by the client library.
  521. Public members with their descriptions are listed below
  522. (conventionally `On input' refers to the binds given to
  523. mysql_stmt_bind_param, `On output' refers to the binds given
  524. to mysql_stmt_bind_result):
  525. buffer_type - One of the MYSQL_* types, used to describe
  526. the host language type of buffer.
  527. On output: if column type is different from
  528. buffer_type, column value is automatically converted
  529. to buffer_type before it is stored in the buffer.
  530. buffer - On input: points to the buffer with input data.
  531. On output: points to the buffer capable to store
  532. output data.
  533. The type of memory pointed by buffer must correspond
  534. to buffer_type. See the correspondence table in
  535. the comment to mysql_stmt_bind_param.
  536. The two above members are mandatory for any kind of bind.
  537. buffer_length - the length of the buffer. You don't have to set
  538. it for any fixed length buffer: float, double,
  539. int, etc. It must be set however for variable-length
  540. types, such as BLOBs or STRINGs.
  541. length - On input: in case when lengths of input values
  542. are different for each execute, you can set this to
  543. point at a variable containining value length. This
  544. way the value length can be different in each execute.
  545. If length is not NULL, buffer_length is not used.
  546. Note, length can even point at buffer_length if
  547. you keep bind structures around while fetching:
  548. this way you can change buffer_length before
  549. each execution, everything will work ok.
  550. On output: if length is set, mysql_stmt_fetch will
  551. write column length into it.
  552. is_null - On input: points to a boolean variable that should
  553. be set to TRUE for NULL values.
  554. This member is useful only if your data may be
  555. NULL in some but not all cases.
  556. If your data is never NULL, is_null should be set to 0.
  557. If your data is always NULL, set buffer_type
  558. to MYSQL_TYPE_NULL, and is_null will not be used.
  559. is_unsigned - On input: used to signify that values provided for one
  560. of numeric types are unsigned.
  561. On output describes signedness of the output buffer.
  562. If, taking into account is_unsigned flag, column data
  563. is out of range of the output buffer, data for this column
  564. is regarded truncated. Note that this has no correspondence
  565. to the sign of result set column, if you need to find it out
  566. use mysql_stmt_result_metadata.
  567. error - where to write a truncation error if it is present.
  568. possible error value is:
  569. 0 no truncation
  570. 1 value is out of range or buffer is too small
  571. Please note that MYSQL_BIND also has internals members.
  572. */
  573. typedef struct st_mysql_bind
  574. {
  575. unsigned long *length; /* output length pointer */
  576. my_bool *is_null; /* Pointer to null indicator */
  577. void *buffer; /* buffer to get/put data */
  578. /* set this if you want to track data truncations happened during fetch */
  579. my_bool *error;
  580. unsigned char *row_ptr; /* for the current data position */
  581. void (*store_param_func)(NET *net, struct st_mysql_bind *param);
  582. void (*fetch_result)(struct st_mysql_bind *, MYSQL_FIELD *,
  583. unsigned char **row);
  584. void (*skip_result)(struct st_mysql_bind *, MYSQL_FIELD *,
  585. unsigned char **row);
  586. /* output buffer length, must be set when fetching str/binary */
  587. unsigned long buffer_length;
  588. unsigned long offset; /* offset position for char/binary fetch */
  589. unsigned long length_value; /* Used if length is 0 */
  590. unsigned int param_number; /* For null count and error messages */
  591. unsigned int pack_length; /* Internal length for packed data */
  592. enum enum_field_types buffer_type; /* buffer type */
  593. my_bool error_value; /* used if error is 0 */
  594. my_bool is_unsigned; /* set if integer type is unsigned */
  595. my_bool long_data_used; /* If used with mysql_send_long_data */
  596. my_bool is_null_value; /* Used if is_null is 0 */
  597. void *extension;
  598. } MYSQL_BIND;
  599. /* statement handler */
  600. typedef struct st_mysql_stmt
  601. {
  602. MEM_ROOT mem_root; /* root allocations */
  603. LIST list; /* list to keep track of all stmts */
  604. MYSQL *mysql; /* connection handle */
  605. MYSQL_BIND *params; /* input parameters */
  606. MYSQL_BIND *bind; /* output parameters */
  607. MYSQL_FIELD *fields; /* result set metadata */
  608. MYSQL_DATA result; /* cached result set */
  609. MYSQL_ROWS *data_cursor; /* current row in cached result */
  610. /*
  611. mysql_stmt_fetch() calls this function to fetch one row (it's different
  612. for buffered, unbuffered and cursor fetch).
  613. */
  614. int (*read_row_func)(struct st_mysql_stmt *stmt,
  615. unsigned char **row);
  616. /* copy of mysql->affected_rows after statement execution */
  617. my_ulonglong affected_rows;
  618. my_ulonglong insert_id; /* copy of mysql->insert_id */
  619. unsigned long stmt_id; /* Id for prepared statement */
  620. unsigned long flags; /* i.e. type of cursor to open */
  621. unsigned long prefetch_rows; /* number of rows per one COM_FETCH */
  622. /*
  623. Copied from mysql->server_status after execute/fetch to know
  624. server-side cursor status for this statement.
  625. */
  626. unsigned int server_status;
  627. unsigned int last_errno; /* error code */
  628. unsigned int param_count; /* input parameter count */
  629. unsigned int field_count; /* number of columns in result set */
  630. enum enum_mysql_stmt_state state; /* statement state */
  631. char last_error[MYSQL_ERRMSG_SIZE]; /* error message */
  632. char sqlstate[SQLSTATE_LENGTH+1];
  633. /* Types of input parameters should be sent to server */
  634. my_bool send_types_to_server;
  635. my_bool bind_param_done; /* input buffers were supplied */
  636. unsigned char bind_result_done; /* output buffers were supplied */
  637. /* mysql_stmt_close() had to cancel this result */
  638. my_bool unbuffered_fetch_cancelled;
  639. /*
  640. Is set to true if we need to calculate field->max_length for
  641. metadata fields when doing mysql_stmt_store_result.
  642. */
  643. my_bool update_max_length;
  644. void *extension;
  645. } MYSQL_STMT;
  646. enum enum_stmt_attr_type
  647. {
  648. /*
  649. When doing mysql_stmt_store_result calculate max_length attribute
  650. of statement metadata. This is to be consistent with the old API,
  651. where this was done automatically.
  652. In the new API we do that only by request because it slows down
  653. mysql_stmt_store_result sufficiently.
  654. */
  655. STMT_ATTR_UPDATE_MAX_LENGTH,
  656. /*
  657. unsigned long with combination of cursor flags (read only, for update,
  658. etc)
  659. */
  660. STMT_ATTR_CURSOR_TYPE,
  661. /*
  662. Amount of rows to retrieve from server per one fetch if using cursors.
  663. Accepts unsigned long attribute in the range 1 - ulong_max
  664. */
  665. STMT_ATTR_PREFETCH_ROWS
  666. };
  667. typedef struct st_mysql_methods
  668. {
  669. my_bool (*read_query_result)(MYSQL *mysql);
  670. my_bool (*advanced_command)(MYSQL *mysql,
  671. enum enum_server_command command,
  672. const unsigned char *header,
  673. unsigned long header_length,
  674. const unsigned char *arg,
  675. unsigned long arg_length,
  676. my_bool skip_check,
  677. MYSQL_STMT *stmt);
  678. MYSQL_DATA *(*read_rows)(MYSQL *mysql,MYSQL_FIELD *mysql_fields,
  679. unsigned int fields);
  680. MYSQL_RES * (*use_result)(MYSQL *mysql);
  681. void (*fetch_lengths)(unsigned long *to,
  682. MYSQL_ROW column, unsigned int field_count);
  683. void (*flush_use_result)(MYSQL *mysql);
  684. #if !defined(MYSQL_SERVER) || defined(EMBEDDED_LIBRARY)
  685. MYSQL_FIELD * (*list_fields)(MYSQL *mysql);
  686. my_bool (*read_prepare_result)(MYSQL *mysql, MYSQL_STMT *stmt);
  687. int (*stmt_execute)(MYSQL_STMT *stmt);
  688. int (*read_binary_rows)(MYSQL_STMT *stmt);
  689. int (*unbuffered_fetch)(MYSQL *mysql, char **row);
  690. void (*free_embedded_thd)(MYSQL *mysql);
  691. const char *(*read_statistics)(MYSQL *mysql);
  692. my_bool (*next_result)(MYSQL *mysql);
  693. int (*read_change_user_result)(MYSQL *mysql, char *buff, const char *passwd);
  694. int (*read_rows_from_cursor)(MYSQL_STMT *stmt);
  695. #endif
  696. } MYSQL_METHODS;
  697. MYSQL_STMT * STDCALL mysql_stmt_init(MYSQL *mysql);
  698. int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query,
  699. unsigned long length);
  700. int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt);
  701. int STDCALL mysql_stmt_fetch(MYSQL_STMT *stmt);
  702. int STDCALL mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind_arg,
  703. unsigned int column,
  704. unsigned long offset);
  705. int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt);
  706. unsigned long STDCALL mysql_stmt_param_count(MYSQL_STMT * stmt);
  707. my_bool STDCALL mysql_stmt_attr_set(MYSQL_STMT *stmt,
  708. enum enum_stmt_attr_type attr_type,
  709. const void *attr);
  710. my_bool STDCALL mysql_stmt_attr_get(MYSQL_STMT *stmt,
  711. enum enum_stmt_attr_type attr_type,
  712. void *attr);
  713. my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT * stmt, MYSQL_BIND * bnd);
  714. my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT * stmt, MYSQL_BIND * bnd);
  715. my_bool STDCALL mysql_stmt_close(MYSQL_STMT * stmt);
  716. my_bool STDCALL mysql_stmt_reset(MYSQL_STMT * stmt);
  717. my_bool STDCALL mysql_stmt_free_result(MYSQL_STMT *stmt);
  718. my_bool STDCALL mysql_stmt_send_long_data(MYSQL_STMT *stmt,
  719. unsigned int param_number,
  720. const char *data,
  721. unsigned long length);
  722. MYSQL_RES *STDCALL mysql_stmt_result_metadata(MYSQL_STMT *stmt);
  723. MYSQL_RES *STDCALL mysql_stmt_param_metadata(MYSQL_STMT *stmt);
  724. unsigned int STDCALL mysql_stmt_errno(MYSQL_STMT * stmt);
  725. const char *STDCALL mysql_stmt_error(MYSQL_STMT * stmt);
  726. const char *STDCALL mysql_stmt_sqlstate(MYSQL_STMT * stmt);
  727. MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_seek(MYSQL_STMT *stmt,
  728. MYSQL_ROW_OFFSET offset);
  729. MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_tell(MYSQL_STMT *stmt);
  730. void STDCALL mysql_stmt_data_seek(MYSQL_STMT *stmt, my_ulonglong offset);
  731. my_ulonglong STDCALL mysql_stmt_num_rows(MYSQL_STMT *stmt);
  732. my_ulonglong STDCALL mysql_stmt_affected_rows(MYSQL_STMT *stmt);
  733. my_ulonglong STDCALL mysql_stmt_insert_id(MYSQL_STMT *stmt);
  734. unsigned int STDCALL mysql_stmt_field_count(MYSQL_STMT *stmt);
  735. my_bool STDCALL mysql_commit(MYSQL * mysql);
  736. my_bool STDCALL mysql_rollback(MYSQL * mysql);
  737. my_bool STDCALL mysql_autocommit(MYSQL * mysql, my_bool auto_mode);
  738. my_bool STDCALL mysql_more_results(MYSQL *mysql);
  739. int STDCALL mysql_next_result(MYSQL *mysql);
  740. void STDCALL mysql_close(MYSQL *sock);
  741. /* status return codes */
  742. #define MYSQL_NO_DATA 100
  743. #define MYSQL_DATA_TRUNCATED 101
  744. #define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT)
  745. #ifdef USE_OLD_FUNCTIONS
  746. MYSQL * STDCALL mysql_connect(MYSQL *mysql, const char *host,
  747. const char *user, const char *passwd);
  748. int STDCALL mysql_create_db(MYSQL *mysql, const char *DB);
  749. int STDCALL mysql_drop_db(MYSQL *mysql, const char *DB);
  750. #define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT)
  751. #endif
  752. #define HAVE_MYSQL_REAL_CONNECT
  753. /*
  754. The following functions are mainly exported because of mysqlbinlog;
  755. They are not for general usage
  756. */
  757. #define simple_command(mysql, command, arg, length, skip_check) \
  758. (*(mysql)->methods->advanced_command)(mysql, command, 0, \
  759. 0, arg, length, skip_check, NULL)
  760. #define stmt_command(mysql, command, arg, length, stmt) \
  761. (*(mysql)->methods->advanced_command)(mysql, command, 0, \
  762. 0, arg, length, 1, stmt)
  763. #ifdef __NETWARE__
  764. #pragma pack(pop) /* restore alignment */
  765. #endif
  766. #ifdef __cplusplus
  767. }
  768. #endif
  769. #endif /* _mysql_h */