9
3

mysql.h 38 KB

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