Clone of PhatAC @ https://github.com/floaterxk/PhatAC

mysql.h 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. /* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 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 update
  18. the SHARED_LIB_MAJOR_VERSION in cmake/mysql_version.cmake
  19. */
  20. #ifndef _mysql_h
  21. #define _mysql_h
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. #ifndef MY_GLOBAL_INCLUDED /* If not standard header */
  26. #ifndef MYSQL_ABI_CHECK
  27. #include <sys/types.h>
  28. #endif
  29. typedef char my_bool;
  30. #if !defined(_WIN32)
  31. #define STDCALL
  32. #else
  33. #define STDCALL __stdcall
  34. #endif
  35. #ifndef my_socket_defined
  36. #ifdef _WIN32
  37. #include <windows.h>
  38. #ifdef WIN32_LEAN_AND_MEAN
  39. #include <winsock2.h>
  40. #endif
  41. #define my_socket SOCKET
  42. #else
  43. typedef int my_socket;
  44. #endif /* _WIN32 */
  45. #endif /* my_socket_defined */
  46. #endif /* MY_GLOBAL_INCLUDED */
  47. #include "mysql_version.h"
  48. #include "mysql_com.h"
  49. #include "mysql_time.h"
  50. #include "my_list.h" /* for LISTs used in 'MYSQL' and 'MYSQL_STMT' */
  51. /* Include declarations of plug-in API */
  52. #include "mysql/client_plugin.h"
  53. extern unsigned int mysql_port;
  54. extern char *mysql_unix_port;
  55. #define CLIENT_NET_READ_TIMEOUT 365*24*3600 /* Timeout on read */
  56. #define CLIENT_NET_WRITE_TIMEOUT 365*24*3600 /* Timeout on write */
  57. #define IS_PRI_KEY(n) ((n) & PRI_KEY_FLAG)
  58. #define IS_NOT_NULL(n) ((n) & NOT_NULL_FLAG)
  59. #define IS_BLOB(n) ((n) & BLOB_FLAG)
  60. /**
  61. Returns true if the value is a number which does not need quotes for
  62. the sql_lex.cc parser to parse correctly.
  63. */
  64. #define IS_NUM(t) (((t) <= MYSQL_TYPE_INT24 && (t) != MYSQL_TYPE_TIMESTAMP) || (t) == MYSQL_TYPE_YEAR || (t) == MYSQL_TYPE_NEWDECIMAL)
  65. #define IS_LONGDATA(t) ((t) >= MYSQL_TYPE_TINY_BLOB && (t) <= MYSQL_TYPE_STRING)
  66. typedef struct st_mysql_field {
  67. char *name; /* Name of column */
  68. char *org_name; /* Original column name, if an alias */
  69. char *table; /* Table of column if column was a field */
  70. char *org_table; /* Org table name, if table was an alias */
  71. char *db; /* Database for table */
  72. char *catalog; /* Catalog for table */
  73. char *def; /* Default value (set by mysql_list_fields) */
  74. unsigned long length; /* Width of column (create length) */
  75. unsigned long max_length; /* Max width for selected set */
  76. unsigned int name_length;
  77. unsigned int org_name_length;
  78. unsigned int table_length;
  79. unsigned int org_table_length;
  80. unsigned int db_length;
  81. unsigned int catalog_length;
  82. unsigned int def_length;
  83. unsigned int flags; /* Div flags */
  84. unsigned int decimals; /* Number of decimals in field */
  85. unsigned int charsetnr; /* Character set */
  86. enum enum_field_types type; /* Type of field. See mysql_com.h for types */
  87. void *extension;
  88. } MYSQL_FIELD;
  89. typedef char **MYSQL_ROW; /* return data as array of strings */
  90. typedef unsigned int MYSQL_FIELD_OFFSET; /* offset to current field */
  91. #ifndef MY_GLOBAL_INCLUDED
  92. #if defined (_WIN32)
  93. typedef unsigned __int64 my_ulonglong;
  94. #else
  95. typedef unsigned long long my_ulonglong;
  96. #endif
  97. #endif
  98. #include "typelib.h"
  99. #define MYSQL_COUNT_ERROR (~(my_ulonglong) 0)
  100. /* backward compatibility define - to be removed eventually */
  101. #define ER_WARN_DATA_TRUNCATED WARN_DATA_TRUNCATED
  102. typedef struct st_mysql_rows {
  103. struct st_mysql_rows *next; /* list of rows */
  104. MYSQL_ROW data;
  105. unsigned long length;
  106. } MYSQL_ROWS;
  107. typedef MYSQL_ROWS *MYSQL_ROW_OFFSET; /* offset to current row */
  108. #include "my_alloc.h"
  109. typedef struct embedded_query_result EMBEDDED_QUERY_RESULT;
  110. typedef struct st_mysql_data {
  111. MYSQL_ROWS *data;
  112. struct embedded_query_result *embedded_info;
  113. MEM_ROOT alloc;
  114. my_ulonglong rows;
  115. unsigned int fields;
  116. /* extra info for embedded library */
  117. void *extension;
  118. } MYSQL_DATA;
  119. enum mysql_option
  120. {
  121. MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS, MYSQL_OPT_NAMED_PIPE,
  122. MYSQL_INIT_COMMAND, MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP,
  123. MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME, MYSQL_OPT_LOCAL_INFILE,
  124. MYSQL_OPT_PROTOCOL, MYSQL_SHARED_MEMORY_BASE_NAME, MYSQL_OPT_READ_TIMEOUT,
  125. MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_USE_RESULT,
  126. MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION,
  127. MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH,
  128. MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT,
  129. MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH,
  130. MYSQL_OPT_BIND,
  131. MYSQL_OPT_SSL_KEY, MYSQL_OPT_SSL_CERT,
  132. MYSQL_OPT_SSL_CA, MYSQL_OPT_SSL_CAPATH, MYSQL_OPT_SSL_CIPHER,
  133. MYSQL_OPT_SSL_CRL, MYSQL_OPT_SSL_CRLPATH,
  134. MYSQL_OPT_CONNECT_ATTR_RESET, MYSQL_OPT_CONNECT_ATTR_ADD,
  135. MYSQL_OPT_CONNECT_ATTR_DELETE,
  136. MYSQL_SERVER_PUBLIC_KEY,
  137. MYSQL_ENABLE_CLEARTEXT_PLUGIN,
  138. MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS,
  139. MYSQL_OPT_SSL_ENFORCE,
  140. MYSQL_OPT_MAX_ALLOWED_PACKET, MYSQL_OPT_NET_BUFFER_LENGTH,
  141. MYSQL_OPT_TLS_VERSION,
  142. MYSQL_OPT_SSL_MODE
  143. };
  144. /**
  145. @todo remove the "extension", move st_mysql_options completely
  146. out of mysql.h
  147. */
  148. struct st_mysql_options_extention;
  149. struct st_mysql_options {
  150. unsigned int connect_timeout, read_timeout, write_timeout;
  151. unsigned int port, protocol;
  152. unsigned long client_flag;
  153. char *host,*user,*password,*unix_socket,*db;
  154. struct st_dynamic_array *init_commands;
  155. char *my_cnf_file,*my_cnf_group, *charset_dir, *charset_name;
  156. char *ssl_key; /* PEM key file */
  157. char *ssl_cert; /* PEM cert file */
  158. char *ssl_ca; /* PEM CA file */
  159. char *ssl_capath; /* PEM directory of CA-s? */
  160. char *ssl_cipher; /* cipher to use */
  161. char *shared_memory_base_name;
  162. unsigned long max_allowed_packet;
  163. my_bool use_ssl; /* Deprecated ! Former use_ssl */
  164. my_bool compress,named_pipe;
  165. my_bool unused1;
  166. my_bool unused2;
  167. my_bool unused3;
  168. my_bool unused4;
  169. enum mysql_option methods_to_use;
  170. union {
  171. /*
  172. The ip/hostname to use when authenticating
  173. client against embedded server built with
  174. grant tables - only used in embedded server
  175. */
  176. char *client_ip;
  177. /*
  178. The local address to bind when connecting to
  179. remote server - not used in embedded server
  180. */
  181. char *bind_address;
  182. } ci;
  183. my_bool unused5;
  184. /* 0 - never report, 1 - always report (default) */
  185. my_bool report_data_truncation;
  186. /* function pointers for local infile support */
  187. int (*local_infile_init)(void **, const char *, void *);
  188. int (*local_infile_read)(void *, char *, unsigned int);
  189. void (*local_infile_end)(void *);
  190. int (*local_infile_error)(void *, char *, unsigned int);
  191. void *local_infile_userdata;
  192. struct st_mysql_options_extention *extension;
  193. };
  194. enum mysql_status
  195. {
  196. MYSQL_STATUS_READY, MYSQL_STATUS_GET_RESULT, MYSQL_STATUS_USE_RESULT,
  197. MYSQL_STATUS_STATEMENT_GET_RESULT
  198. };
  199. enum mysql_protocol_type
  200. {
  201. MYSQL_PROTOCOL_DEFAULT, MYSQL_PROTOCOL_TCP, MYSQL_PROTOCOL_SOCKET,
  202. MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_MEMORY
  203. };
  204. enum mysql_ssl_mode
  205. {
  206. SSL_MODE_DISABLED= 1, SSL_MODE_PREFERRED, SSL_MODE_REQUIRED,
  207. SSL_MODE_VERIFY_CA, SSL_MODE_VERIFY_IDENTITY
  208. };
  209. typedef struct character_set
  210. {
  211. unsigned int number; /* character set number */
  212. unsigned int state; /* character set state */
  213. const char *csname; /* collation name */
  214. const char *name; /* character set name */
  215. const char *comment; /* comment */
  216. const char *dir; /* character set directory */
  217. unsigned int mbminlen; /* min. length for multibyte strings */
  218. unsigned int mbmaxlen; /* max. length for multibyte strings */
  219. } MY_CHARSET_INFO;
  220. struct st_mysql_methods;
  221. struct st_mysql_stmt;
  222. typedef struct st_mysql
  223. {
  224. NET net; /* Communication parameters */
  225. unsigned char *connector_fd; /* ConnectorFd for SSL */
  226. char *host,*user,*passwd,*unix_socket,*server_version,*host_info;
  227. char *info, *db;
  228. struct charset_info_st *charset;
  229. MYSQL_FIELD *fields;
  230. MEM_ROOT field_alloc;
  231. my_ulonglong affected_rows;
  232. my_ulonglong insert_id; /* id if insert on table with NEXTNR */
  233. my_ulonglong extra_info; /* Not used */
  234. unsigned long thread_id; /* Id for connection in server */
  235. unsigned long packet_length;
  236. unsigned int port;
  237. unsigned long client_flag,server_capabilities;
  238. unsigned int protocol_version;
  239. unsigned int field_count;
  240. unsigned int server_status;
  241. unsigned int server_language;
  242. unsigned int warning_count;
  243. struct st_mysql_options options;
  244. enum mysql_status status;
  245. my_bool free_me; /* If free in mysql_close */
  246. my_bool reconnect; /* set to 1 if automatic reconnect */
  247. /* session-wide random string */
  248. char scramble[SCRAMBLE_LENGTH+1];
  249. my_bool unused1;
  250. void *unused2, *unused3, *unused4, *unused5;
  251. LIST *stmts; /* list of all statements */
  252. const struct st_mysql_methods *methods;
  253. void *thd;
  254. /*
  255. Points to boolean flag in MYSQL_RES or MYSQL_STMT. We set this flag
  256. from mysql_stmt_close if close had to cancel result set of this object.
  257. */
  258. my_bool *unbuffered_fetch_owner;
  259. /* needed for embedded server - no net buffer to store the 'info' */
  260. char *info_buffer;
  261. void *extension;
  262. } MYSQL;
  263. typedef struct st_mysql_res {
  264. my_ulonglong row_count;
  265. MYSQL_FIELD *fields;
  266. MYSQL_DATA *data;
  267. MYSQL_ROWS *data_cursor;
  268. unsigned long *lengths; /* column lengths of current row */
  269. MYSQL *handle; /* for unbuffered reads */
  270. const struct st_mysql_methods *methods;
  271. MYSQL_ROW row; /* If unbuffered read */
  272. MYSQL_ROW current_row; /* buffer to current row */
  273. MEM_ROOT field_alloc;
  274. unsigned int field_count, current_field;
  275. my_bool eof; /* Used by mysql_fetch_row */
  276. /* mysql_stmt_close() had to cancel this result */
  277. my_bool unbuffered_fetch_cancelled;
  278. void *extension;
  279. } MYSQL_RES;
  280. #if !defined(MYSQL_SERVER) && !defined(MYSQL_CLIENT)
  281. #define MYSQL_CLIENT
  282. #endif
  283. /*
  284. Set up and bring down the server; to ensure that applications will
  285. work when linked against either the standard client library or the
  286. embedded server library, these functions should be called.
  287. */
  288. int STDCALL mysql_server_init(int argc, char **argv, char **groups);
  289. void STDCALL mysql_server_end(void);
  290. /*
  291. mysql_server_init/end need to be called when using libmysqld or
  292. libmysqlclient (exactly, mysql_server_init() is called by mysql_init() so
  293. you don't need to call it explicitely; but you need to call
  294. mysql_server_end() to free memory). The names are a bit misleading
  295. (mysql_SERVER* to be used when using libmysqlCLIENT). So we add more general
  296. names which suit well whether you're using libmysqld or libmysqlclient. We
  297. intend to promote these aliases over the mysql_server* ones.
  298. */
  299. #define mysql_library_init mysql_server_init
  300. #define mysql_library_end mysql_server_end
  301. /*
  302. Set up and bring down a thread; these function should be called
  303. for each thread in an application which opens at least one MySQL
  304. connection. All uses of the connection(s) should be between these
  305. function calls.
  306. */
  307. my_bool STDCALL mysql_thread_init(void);
  308. void STDCALL mysql_thread_end(void);
  309. /*
  310. Functions to get information from the MYSQL and MYSQL_RES structures
  311. Should definitely be used if one uses shared libraries.
  312. */
  313. my_ulonglong STDCALL mysql_num_rows(MYSQL_RES *res);
  314. unsigned int STDCALL mysql_num_fields(MYSQL_RES *res);
  315. my_bool STDCALL mysql_eof(MYSQL_RES *res);
  316. MYSQL_FIELD *STDCALL mysql_fetch_field_direct(MYSQL_RES *res,
  317. unsigned int fieldnr);
  318. MYSQL_FIELD * STDCALL mysql_fetch_fields(MYSQL_RES *res);
  319. MYSQL_ROW_OFFSET STDCALL mysql_row_tell(MYSQL_RES *res);
  320. MYSQL_FIELD_OFFSET STDCALL mysql_field_tell(MYSQL_RES *res);
  321. unsigned int STDCALL mysql_field_count(MYSQL *mysql);
  322. my_ulonglong STDCALL mysql_affected_rows(MYSQL *mysql);
  323. my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql);
  324. unsigned int STDCALL mysql_errno(MYSQL *mysql);
  325. const char * STDCALL mysql_error(MYSQL *mysql);
  326. const char *STDCALL mysql_sqlstate(MYSQL *mysql);
  327. unsigned int STDCALL mysql_warning_count(MYSQL *mysql);
  328. const char * STDCALL mysql_info(MYSQL *mysql);
  329. unsigned long STDCALL mysql_thread_id(MYSQL *mysql);
  330. const char * STDCALL mysql_character_set_name(MYSQL *mysql);
  331. int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname);
  332. MYSQL * STDCALL mysql_init(MYSQL *mysql);
  333. my_bool STDCALL mysql_ssl_set(MYSQL *mysql, const char *key,
  334. const char *cert, const char *ca,
  335. const char *capath, const char *cipher);
  336. const char * STDCALL mysql_get_ssl_cipher(MYSQL *mysql);
  337. my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user,
  338. const char *passwd, const char *db);
  339. MYSQL * STDCALL mysql_real_connect(MYSQL *mysql, const char *host,
  340. const char *user,
  341. const char *passwd,
  342. const char *db,
  343. unsigned int port,
  344. const char *unix_socket,
  345. unsigned long clientflag);
  346. int STDCALL mysql_select_db(MYSQL *mysql, const char *db);
  347. int STDCALL mysql_query(MYSQL *mysql, const char *q);
  348. int STDCALL mysql_send_query(MYSQL *mysql, const char *q,
  349. unsigned long length);
  350. int STDCALL mysql_real_query(MYSQL *mysql, const char *q,
  351. unsigned long length);
  352. MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql);
  353. MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql);
  354. void STDCALL mysql_get_character_set_info(MYSQL *mysql,
  355. MY_CHARSET_INFO *charset);
  356. int STDCALL mysql_session_track_get_first(MYSQL *mysql,
  357. enum enum_session_state_type type,
  358. const char **data,
  359. size_t *length);
  360. int STDCALL mysql_session_track_get_next(MYSQL *mysql,
  361. enum enum_session_state_type type,
  362. const char **data,
  363. size_t *length);
  364. /* local infile support */
  365. #define LOCAL_INFILE_ERROR_LEN 512
  366. void
  367. mysql_set_local_infile_handler(MYSQL *mysql,
  368. int (*local_infile_init)(void **, const char *,
  369. void *),
  370. int (*local_infile_read)(void *, char *,
  371. unsigned int),
  372. void (*local_infile_end)(void *),
  373. int (*local_infile_error)(void *, char*,
  374. unsigned int),
  375. void *);
  376. void
  377. mysql_set_local_infile_default(MYSQL *mysql);
  378. int STDCALL mysql_shutdown(MYSQL *mysql,
  379. enum mysql_enum_shutdown_level
  380. shutdown_level);
  381. int STDCALL mysql_dump_debug_info(MYSQL *mysql);
  382. int STDCALL mysql_refresh(MYSQL *mysql,
  383. unsigned int refresh_options);
  384. int STDCALL mysql_kill(MYSQL *mysql,unsigned long pid);
  385. int STDCALL mysql_set_server_option(MYSQL *mysql,
  386. enum enum_mysql_set_option
  387. option);
  388. int STDCALL mysql_ping(MYSQL *mysql);
  389. const char * STDCALL mysql_stat(MYSQL *mysql);
  390. const char * STDCALL mysql_get_server_info(MYSQL *mysql);
  391. const char * STDCALL mysql_get_client_info(void);
  392. unsigned long STDCALL mysql_get_client_version(void);
  393. const char * STDCALL mysql_get_host_info(MYSQL *mysql);
  394. unsigned long STDCALL mysql_get_server_version(MYSQL *mysql);
  395. unsigned int STDCALL mysql_get_proto_info(MYSQL *mysql);
  396. MYSQL_RES * STDCALL mysql_list_dbs(MYSQL *mysql,const char *wild);
  397. MYSQL_RES * STDCALL mysql_list_tables(MYSQL *mysql,const char *wild);
  398. MYSQL_RES * STDCALL mysql_list_processes(MYSQL *mysql);
  399. int STDCALL mysql_options(MYSQL *mysql,enum mysql_option option,
  400. const void *arg);
  401. int STDCALL mysql_options4(MYSQL *mysql,enum mysql_option option,
  402. const void *arg1, const void *arg2);
  403. int STDCALL mysql_get_option(MYSQL *mysql, enum mysql_option option,
  404. const void *arg);
  405. void STDCALL mysql_free_result(MYSQL_RES *result);
  406. void STDCALL mysql_data_seek(MYSQL_RES *result,
  407. my_ulonglong offset);
  408. MYSQL_ROW_OFFSET STDCALL mysql_row_seek(MYSQL_RES *result,
  409. MYSQL_ROW_OFFSET offset);
  410. MYSQL_FIELD_OFFSET STDCALL mysql_field_seek(MYSQL_RES *result,
  411. MYSQL_FIELD_OFFSET offset);
  412. MYSQL_ROW STDCALL mysql_fetch_row(MYSQL_RES *result);
  413. unsigned long * STDCALL mysql_fetch_lengths(MYSQL_RES *result);
  414. MYSQL_FIELD * STDCALL mysql_fetch_field(MYSQL_RES *result);
  415. MYSQL_RES * STDCALL mysql_list_fields(MYSQL *mysql, const char *table,
  416. const char *wild);
  417. unsigned long STDCALL mysql_escape_string(char *to,const char *from,
  418. unsigned long from_length);
  419. unsigned long STDCALL mysql_hex_string(char *to,const char *from,
  420. unsigned long from_length);
  421. unsigned long STDCALL mysql_real_escape_string(MYSQL *mysql,
  422. char *to,const char *from,
  423. unsigned long length);
  424. unsigned long STDCALL mysql_real_escape_string_quote(MYSQL *mysql,
  425. char *to, const char *from,
  426. unsigned long length, char quote);
  427. void STDCALL mysql_debug(const char *debug);
  428. void STDCALL myodbc_remove_escape(MYSQL *mysql,char *name);
  429. unsigned int STDCALL mysql_thread_safe(void);
  430. my_bool STDCALL mysql_embedded(void);
  431. my_bool STDCALL mysql_read_query_result(MYSQL *mysql);
  432. int STDCALL mysql_reset_connection(MYSQL *mysql);
  433. /*
  434. The following definitions are added for the enhanced
  435. client-server protocol
  436. */
  437. /* statement state */
  438. enum enum_mysql_stmt_state
  439. {
  440. MYSQL_STMT_INIT_DONE= 1, MYSQL_STMT_PREPARE_DONE, MYSQL_STMT_EXECUTE_DONE,
  441. MYSQL_STMT_FETCH_DONE
  442. };
  443. /*
  444. This structure is used to define bind information, and
  445. internally by the client library.
  446. Public members with their descriptions are listed below
  447. (conventionally `On input' refers to the binds given to
  448. mysql_stmt_bind_param, `On output' refers to the binds given
  449. to mysql_stmt_bind_result):
  450. buffer_type - One of the MYSQL_* types, used to describe
  451. the host language type of buffer.
  452. On output: if column type is different from
  453. buffer_type, column value is automatically converted
  454. to buffer_type before it is stored in the buffer.
  455. buffer - On input: points to the buffer with input data.
  456. On output: points to the buffer capable to store
  457. output data.
  458. The type of memory pointed by buffer must correspond
  459. to buffer_type. See the correspondence table in
  460. the comment to mysql_stmt_bind_param.
  461. The two above members are mandatory for any kind of bind.
  462. buffer_length - the length of the buffer. You don't have to set
  463. it for any fixed length buffer: float, double,
  464. int, etc. It must be set however for variable-length
  465. types, such as BLOBs or STRINGs.
  466. length - On input: in case when lengths of input values
  467. are different for each execute, you can set this to
  468. point at a variable containining value length. This
  469. way the value length can be different in each execute.
  470. If length is not NULL, buffer_length is not used.
  471. Note, length can even point at buffer_length if
  472. you keep bind structures around while fetching:
  473. this way you can change buffer_length before
  474. each execution, everything will work ok.
  475. On output: if length is set, mysql_stmt_fetch will
  476. write column length into it.
  477. is_null - On input: points to a boolean variable that should
  478. be set to TRUE for NULL values.
  479. This member is useful only if your data may be
  480. NULL in some but not all cases.
  481. If your data is never NULL, is_null should be set to 0.
  482. If your data is always NULL, set buffer_type
  483. to MYSQL_TYPE_NULL, and is_null will not be used.
  484. is_unsigned - On input: used to signify that values provided for one
  485. of numeric types are unsigned.
  486. On output describes signedness of the output buffer.
  487. If, taking into account is_unsigned flag, column data
  488. is out of range of the output buffer, data for this column
  489. is regarded truncated. Note that this has no correspondence
  490. to the sign of result set column, if you need to find it out
  491. use mysql_stmt_result_metadata.
  492. error - where to write a truncation error if it is present.
  493. possible error value is:
  494. 0 no truncation
  495. 1 value is out of range or buffer is too small
  496. Please note that MYSQL_BIND also has internals members.
  497. */
  498. typedef struct st_mysql_bind
  499. {
  500. unsigned long *length; /* output length pointer */
  501. my_bool *is_null; /* Pointer to null indicator */
  502. void *buffer; /* buffer to get/put data */
  503. /* set this if you want to track data truncations happened during fetch */
  504. my_bool *error;
  505. unsigned char *row_ptr; /* for the current data position */
  506. void (*store_param_func)(NET *net, struct st_mysql_bind *param);
  507. void (*fetch_result)(struct st_mysql_bind *, MYSQL_FIELD *,
  508. unsigned char **row);
  509. void (*skip_result)(struct st_mysql_bind *, MYSQL_FIELD *,
  510. unsigned char **row);
  511. /* output buffer length, must be set when fetching str/binary */
  512. unsigned long buffer_length;
  513. unsigned long offset; /* offset position for char/binary fetch */
  514. unsigned long length_value; /* Used if length is 0 */
  515. unsigned int param_number; /* For null count and error messages */
  516. unsigned int pack_length; /* Internal length for packed data */
  517. enum enum_field_types buffer_type; /* buffer type */
  518. my_bool error_value; /* used if error is 0 */
  519. my_bool is_unsigned; /* set if integer type is unsigned */
  520. my_bool long_data_used; /* If used with mysql_send_long_data */
  521. my_bool is_null_value; /* Used if is_null is 0 */
  522. void *extension;
  523. } MYSQL_BIND;
  524. struct st_mysql_stmt_extension;
  525. /* statement handler */
  526. typedef struct st_mysql_stmt
  527. {
  528. MEM_ROOT mem_root; /* root allocations */
  529. LIST list; /* list to keep track of all stmts */
  530. MYSQL *mysql; /* connection handle */
  531. MYSQL_BIND *params; /* input parameters */
  532. MYSQL_BIND *bind; /* output parameters */
  533. MYSQL_FIELD *fields; /* result set metadata */
  534. MYSQL_DATA result; /* cached result set */
  535. MYSQL_ROWS *data_cursor; /* current row in cached result */
  536. /*
  537. mysql_stmt_fetch() calls this function to fetch one row (it's different
  538. for buffered, unbuffered and cursor fetch).
  539. */
  540. int (*read_row_func)(struct st_mysql_stmt *stmt,
  541. unsigned char **row);
  542. /* copy of mysql->affected_rows after statement execution */
  543. my_ulonglong affected_rows;
  544. my_ulonglong insert_id; /* copy of mysql->insert_id */
  545. unsigned long stmt_id; /* Id for prepared statement */
  546. unsigned long flags; /* i.e. type of cursor to open */
  547. unsigned long prefetch_rows; /* number of rows per one COM_FETCH */
  548. /*
  549. Copied from mysql->server_status after execute/fetch to know
  550. server-side cursor status for this statement.
  551. */
  552. unsigned int server_status;
  553. unsigned int last_errno; /* error code */
  554. unsigned int param_count; /* input parameter count */
  555. unsigned int field_count; /* number of columns in result set */
  556. enum enum_mysql_stmt_state state; /* statement state */
  557. char last_error[MYSQL_ERRMSG_SIZE]; /* error message */
  558. char sqlstate[SQLSTATE_LENGTH+1];
  559. /* Types of input parameters should be sent to server */
  560. my_bool send_types_to_server;
  561. my_bool bind_param_done; /* input buffers were supplied */
  562. unsigned char bind_result_done; /* output buffers were supplied */
  563. /* mysql_stmt_close() had to cancel this result */
  564. my_bool unbuffered_fetch_cancelled;
  565. /*
  566. Is set to true if we need to calculate field->max_length for
  567. metadata fields when doing mysql_stmt_store_result.
  568. */
  569. my_bool update_max_length;
  570. struct st_mysql_stmt_extension *extension;
  571. } MYSQL_STMT;
  572. enum enum_stmt_attr_type
  573. {
  574. /*
  575. When doing mysql_stmt_store_result calculate max_length attribute
  576. of statement metadata. This is to be consistent with the old API,
  577. where this was done automatically.
  578. In the new API we do that only by request because it slows down
  579. mysql_stmt_store_result sufficiently.
  580. */
  581. STMT_ATTR_UPDATE_MAX_LENGTH,
  582. /*
  583. unsigned long with combination of cursor flags (read only, for update,
  584. etc)
  585. */
  586. STMT_ATTR_CURSOR_TYPE,
  587. /*
  588. Amount of rows to retrieve from server per one fetch if using cursors.
  589. Accepts unsigned long attribute in the range 1 - ulong_max
  590. */
  591. STMT_ATTR_PREFETCH_ROWS
  592. };
  593. MYSQL_STMT * STDCALL mysql_stmt_init(MYSQL *mysql);
  594. int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query,
  595. unsigned long length);
  596. int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt);
  597. int STDCALL mysql_stmt_fetch(MYSQL_STMT *stmt);
  598. int STDCALL mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind_arg,
  599. unsigned int column,
  600. unsigned long offset);
  601. int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt);
  602. unsigned long STDCALL mysql_stmt_param_count(MYSQL_STMT * stmt);
  603. my_bool STDCALL mysql_stmt_attr_set(MYSQL_STMT *stmt,
  604. enum enum_stmt_attr_type attr_type,
  605. const void *attr);
  606. my_bool STDCALL mysql_stmt_attr_get(MYSQL_STMT *stmt,
  607. enum enum_stmt_attr_type attr_type,
  608. void *attr);
  609. my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT * stmt, MYSQL_BIND * bnd);
  610. my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT * stmt, MYSQL_BIND * bnd);
  611. my_bool STDCALL mysql_stmt_close(MYSQL_STMT * stmt);
  612. my_bool STDCALL mysql_stmt_reset(MYSQL_STMT * stmt);
  613. my_bool STDCALL mysql_stmt_free_result(MYSQL_STMT *stmt);
  614. my_bool STDCALL mysql_stmt_send_long_data(MYSQL_STMT *stmt,
  615. unsigned int param_number,
  616. const char *data,
  617. unsigned long length);
  618. MYSQL_RES *STDCALL mysql_stmt_result_metadata(MYSQL_STMT *stmt);
  619. MYSQL_RES *STDCALL mysql_stmt_param_metadata(MYSQL_STMT *stmt);
  620. unsigned int STDCALL mysql_stmt_errno(MYSQL_STMT * stmt);
  621. const char *STDCALL mysql_stmt_error(MYSQL_STMT * stmt);
  622. const char *STDCALL mysql_stmt_sqlstate(MYSQL_STMT * stmt);
  623. MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_seek(MYSQL_STMT *stmt,
  624. MYSQL_ROW_OFFSET offset);
  625. MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_tell(MYSQL_STMT *stmt);
  626. void STDCALL mysql_stmt_data_seek(MYSQL_STMT *stmt, my_ulonglong offset);
  627. my_ulonglong STDCALL mysql_stmt_num_rows(MYSQL_STMT *stmt);
  628. my_ulonglong STDCALL mysql_stmt_affected_rows(MYSQL_STMT *stmt);
  629. my_ulonglong STDCALL mysql_stmt_insert_id(MYSQL_STMT *stmt);
  630. unsigned int STDCALL mysql_stmt_field_count(MYSQL_STMT *stmt);
  631. my_bool STDCALL mysql_commit(MYSQL * mysql);
  632. my_bool STDCALL mysql_rollback(MYSQL * mysql);
  633. my_bool STDCALL mysql_autocommit(MYSQL * mysql, my_bool auto_mode);
  634. my_bool STDCALL mysql_more_results(MYSQL *mysql);
  635. int STDCALL mysql_next_result(MYSQL *mysql);
  636. int STDCALL mysql_stmt_next_result(MYSQL_STMT *stmt);
  637. void STDCALL mysql_close(MYSQL *sock);
  638. /* status return codes */
  639. #define MYSQL_NO_DATA 100
  640. #define MYSQL_DATA_TRUNCATED 101
  641. #define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT)
  642. #define HAVE_MYSQL_REAL_CONNECT
  643. #ifdef __cplusplus
  644. }
  645. #endif
  646. #endif /* _mysql_h */