9
3

mysql.h 33 KB

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