mysql Lua+ffi binding http://luapower.com/mysql
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

572 lines
21KB

  1. --result of `cpp mysql.h` with lots of cleanup and defines from other headers.
  2. --Written by Cosmin Apreutesei. MySQL Connector/C 6.1.
  3. --NOTE: MySQL Connector/C is GPL software. Is this "derived work" then?
  4. local ffi = require'ffi'
  5. ffi.cdef[[
  6. typedef char my_bool;
  7. typedef unsigned long long my_ulonglong;
  8. enum {
  9. MYSQL_PORT = 3306,
  10. MYSQL_ERRMSG_SIZE = 512,
  11. // status return codes
  12. MYSQL_NO_DATA = 100,
  13. MYSQL_DATA_TRUNCATED = 101
  14. };
  15. // ----------------------------------------------------------- error constants
  16. // NOTE: added MYSQL_ prefix to these.
  17. enum mysql_error_code {
  18. MYSQL_CR_UNKNOWN_ERROR = 2000,
  19. MYSQL_CR_SOCKET_CREATE_ERROR = 2001,
  20. MYSQL_CR_CONNECTION_ERROR = 2002,
  21. MYSQL_CR_CONN_HOST_ERROR = 2003,
  22. MYSQL_CR_IPSOCK_ERROR = 2004,
  23. MYSQL_CR_UNKNOWN_HOST = 2005,
  24. MYSQL_CR_SERVER_GONE_ERROR = 2006,
  25. MYSQL_CR_VERSION_ERROR = 2007,
  26. MYSQL_CR_OUT_OF_MEMORY = 2008,
  27. MYSQL_CR_WRONG_HOST_INFO = 2009,
  28. MYSQL_CR_LOCALHOST_CONNECTION = 2010,
  29. MYSQL_CR_TCP_CONNECTION = 2011,
  30. MYSQL_CR_SERVER_HANDSHAKE_ERR = 2012,
  31. MYSQL_CR_SERVER_LOST = 2013,
  32. MYSQL_CR_COMMANDS_OUT_OF_SYNC = 2014,
  33. MYSQL_CR_NAMEDPIPE_CONNECTION = 2015,
  34. MYSQL_CR_NAMEDPIPEWAIT_ERROR = 2016,
  35. MYSQL_CR_NAMEDPIPEOPEN_ERROR = 2017,
  36. MYSQL_CR_NAMEDPIPESETSTATE_ERROR = 2018,
  37. MYSQL_CR_CANT_READ_CHARSET = 2019,
  38. MYSQL_CR_NET_PACKET_TOO_LARGE = 2020,
  39. MYSQL_CR_EMBEDDED_CONNECTION = 2021,
  40. MYSQL_CR_PROBE_SLAVE_STATUS = 2022,
  41. MYSQL_CR_PROBE_SLAVE_HOSTS = 2023,
  42. MYSQL_CR_PROBE_SLAVE_CONNECT = 2024,
  43. MYSQL_CR_PROBE_MASTER_CONNECT = 2025,
  44. MYSQL_CR_SSL_CONNECTION_ERROR = 2026,
  45. MYSQL_CR_MALFORMED_PACKET = 2027,
  46. MYSQL_CR_WRONG_LICENSE = 2028,
  47. /* new 4.1 error codes */
  48. MYSQL_CR_NULL_POINTER = 2029,
  49. MYSQL_CR_NO_PREPARE_STMT = 2030,
  50. MYSQL_CR_PARAMS_NOT_BOUND = 2031,
  51. MYSQL_CR_DATA_TRUNCATED = 2032,
  52. MYSQL_CR_NO_PARAMETERS_EXISTS = 2033,
  53. MYSQL_CR_INVALID_PARAMETER_NO = 2034,
  54. MYSQL_CR_INVALID_BUFFER_USE = 2035,
  55. MYSQL_CR_UNSUPPORTED_PARAM_TYPE = 2036,
  56. MYSQL_CR_SHARED_MEMORY_CONNECTION = 2037,
  57. MYSQL_CR_SHARED_MEMORY_CONNECT_REQUEST_ERROR = 2038,
  58. MYSQL_CR_SHARED_MEMORY_CONNECT_ANSWER_ERROR = 2039,
  59. MYSQL_CR_SHARED_MEMORY_CONNECT_FILE_MAP_ERROR = 2040,
  60. MYSQL_CR_SHARED_MEMORY_CONNECT_MAP_ERROR = 2041,
  61. MYSQL_CR_SHARED_MEMORY_FILE_MAP_ERROR = 2042,
  62. MYSQL_CR_SHARED_MEMORY_MAP_ERROR = 2043,
  63. MYSQL_CR_SHARED_MEMORY_EVENT_ERROR = 2044,
  64. MYSQL_CR_SHARED_MEMORY_CONNECT_ABANDONED_ERROR = 2045,
  65. MYSQL_CR_SHARED_MEMORY_CONNECT_SET_ERROR = 2046,
  66. MYSQL_CR_CONN_UNKNOW_PROTOCOL = 2047,
  67. MYSQL_CR_INVALID_CONN_HANDLE = 2048,
  68. MYSQL_CR_SECURE_AUTH = 2049,
  69. MYSQL_CR_FETCH_CANCELED = 2050,
  70. MYSQL_CR_NO_DATA = 2051,
  71. MYSQL_CR_NO_STMT_METADATA = 2052,
  72. MYSQL_CR_NO_RESULT_SET = 2053,
  73. MYSQL_CR_NOT_IMPLEMENTED = 2054,
  74. MYSQL_CR_SERVER_LOST_EXTENDED = 2055,
  75. MYSQL_CR_STMT_CLOSED = 2056,
  76. MYSQL_CR_NEW_STMT_METADATA = 2057,
  77. MYSQL_CR_ALREADY_CONNECTED = 2058,
  78. MYSQL_CR_AUTH_PLUGIN_CANNOT_LOAD = 2059,
  79. MYSQL_CR_DUPLICATE_CONNECTION_ATTR = 2060,
  80. MYSQL_CR_AUTH_PLUGIN_ERR = 2061
  81. };
  82. // ------------------------------------------------------------ client library
  83. unsigned int mysql_thread_safe(void); // is the client library thread safe?
  84. const char *mysql_get_client_info(void);
  85. unsigned long mysql_get_client_version(void);
  86. // --------------------------------------------------------------- connections
  87. typedef struct MYSQL_ MYSQL;
  88. MYSQL * mysql_init(MYSQL *mysql);
  89. enum mysql_protocol_type
  90. {
  91. MYSQL_PROTOCOL_DEFAULT, MYSQL_PROTOCOL_TCP, MYSQL_PROTOCOL_SOCKET,
  92. MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_MEMORY
  93. };
  94. enum mysql_option
  95. {
  96. MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS, MYSQL_OPT_NAMED_PIPE,
  97. MYSQL_INIT_COMMAND, MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP,
  98. MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME, MYSQL_OPT_LOCAL_INFILE,
  99. MYSQL_OPT_PROTOCOL, MYSQL_SHARED_MEMORY_BASE_NAME, MYSQL_OPT_READ_TIMEOUT,
  100. MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_USE_RESULT,
  101. MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION,
  102. MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH,
  103. MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT,
  104. MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH,
  105. MYSQL_OPT_BIND,
  106. MYSQL_OPT_SSL_KEY, MYSQL_OPT_SSL_CERT,
  107. MYSQL_OPT_SSL_CA, MYSQL_OPT_SSL_CAPATH, MYSQL_OPT_SSL_CIPHER,
  108. MYSQL_OPT_SSL_CRL, MYSQL_OPT_SSL_CRLPATH,
  109. MYSQL_OPT_CONNECT_ATTR_RESET, MYSQL_OPT_CONNECT_ATTR_ADD,
  110. MYSQL_OPT_CONNECT_ATTR_DELETE,
  111. MYSQL_SERVER_PUBLIC_KEY,
  112. MYSQL_ENABLE_CLEARTEXT_PLUGIN,
  113. MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS
  114. };
  115. int mysql_options(MYSQL *mysql, enum mysql_option option, const void *arg);
  116. int mysql_options4(MYSQL *mysql, enum mysql_option option, const void *arg1, const void *arg2);
  117. // NOTE: added MYSQL_ prefix to these. Also, these are bit flags not exclusive enum values.
  118. enum {
  119. MYSQL_CLIENT_LONG_PASSWORD = 1, /* new more secure passwords */
  120. MYSQL_CLIENT_FOUND_ROWS = 2, /* Found instead of affected rows */
  121. MYSQL_CLIENT_LONG_FLAG = 4, /* Get all column flags */
  122. MYSQL_CLIENT_CONNECT_WITH_DB = 8, /* One can specify db on connect */
  123. MYSQL_CLIENT_NO_SCHEMA = 16, /* Don't allow database.table.column */
  124. MYSQL_CLIENT_COMPRESS = 32, /* Can use compression protocol */
  125. MYSQL_CLIENT_ODBC = 64, /* ODBC client */
  126. MYSQL_CLIENT_LOCAL_FILES = 128, /* Can use LOAD DATA LOCAL */
  127. MYSQL_CLIENT_IGNORE_SPACE = 256, /* Ignore spaces before '(' */
  128. MYSQL_CLIENT_PROTOCOL_41 = 512, /* New 4.1 protocol */
  129. MYSQL_CLIENT_INTERACTIVE = 1024, /* This is an interactive client */
  130. MYSQL_CLIENT_SSL = 2048, /* Switch to SSL after handshake */
  131. MYSQL_CLIENT_IGNORE_SIGPIPE = 4096, /* IGNORE sigpipes */
  132. MYSQL_CLIENT_TRANSACTIONS = 8192, /* Client knows about transactions */
  133. MYSQL_CLIENT_RESERVED = 16384, /* Old flag for 4.1 protocol */
  134. MYSQL_CLIENT_SECURE_CONNECTION = (1U << 15), /* New 4.1 authentication */
  135. MYSQL_CLIENT_MULTI_STATEMENTS = (1U << 16), /* Enable/disable multi-stmt support */
  136. MYSQL_CLIENT_MULTI_RESULTS = (1U << 17), /* Enable/disable multi-results */
  137. MYSQL_CLIENT_PS_MULTI_RESULTS = (1U << 18), /* Multi-results in PS-protocol */
  138. MYSQL_CLIENT_PLUGIN_AUTH = (1U << 19), /* Client supports plugin authentication */
  139. MYSQL_CLIENT_CONNECT_ATTRS = (1U << 20), /* Client supports connection attributes */
  140. /* Enable authentication response packet to be larger than 255 bytes. */
  141. MYSQL_CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA = (1U << 21),
  142. /* Don't close the connection for a connection with expired password. */
  143. MYSQL_CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS = (1U << 22),
  144. MYSQL_CLIENT_SSL_VERIFY_SERVER_CERT = (1U << 30),
  145. MYSQL_CLIENT_REMEMBER_OPTIONS = (1U << 31)
  146. };
  147. MYSQL * mysql_real_connect(MYSQL *mysql, const char *host,
  148. const char *user,
  149. const char *passwd,
  150. const char *db,
  151. unsigned int port,
  152. const char *unix_socket,
  153. unsigned long clientflag);
  154. void mysql_close(MYSQL *sock);
  155. int mysql_set_character_set(MYSQL *mysql, const char *csname);
  156. int mysql_select_db(MYSQL *mysql, const char *db);
  157. my_bool mysql_change_user(MYSQL *mysql, const char *user, const char *passwd,
  158. const char *db);
  159. my_bool mysql_ssl_set(MYSQL *mysql, const char *key,
  160. const char *cert, const char *ca,
  161. const char *capath, const char *cipher);
  162. enum enum_mysql_set_option
  163. {
  164. MYSQL_OPTION_MULTI_STATEMENTS_ON,
  165. MYSQL_OPTION_MULTI_STATEMENTS_OFF
  166. };
  167. int mysql_set_server_option(MYSQL *mysql, enum enum_mysql_set_option option);
  168. // ----------------------------------------------------------- connection info
  169. const char * mysql_character_set_name(MYSQL *mysql);
  170. typedef struct character_set
  171. {
  172. unsigned int number;
  173. unsigned int state;
  174. const char *csname;
  175. const char *name;
  176. const char *comment;
  177. const char *dir;
  178. unsigned int mbminlen;
  179. unsigned int mbmaxlen;
  180. } MY_CHARSET_INFO;
  181. void mysql_get_character_set_info(MYSQL *mysql, MY_CHARSET_INFO *charset);
  182. int mysql_ping(MYSQL *mysql);
  183. unsigned long mysql_thread_id(MYSQL *mysql);
  184. const char * mysql_stat(MYSQL *mysql);
  185. const char * mysql_get_server_info(MYSQL *mysql);
  186. const char * mysql_get_host_info(MYSQL *mysql);
  187. unsigned long mysql_get_server_version(MYSQL *mysql);
  188. unsigned int mysql_get_proto_info(MYSQL *mysql);
  189. const char * mysql_get_ssl_cipher(MYSQL *mysql);
  190. // -------------------------------------------------------------- transactions
  191. my_bool mysql_commit(MYSQL * mysql);
  192. my_bool mysql_rollback(MYSQL * mysql);
  193. my_bool mysql_autocommit(MYSQL * mysql, my_bool auto_mode);
  194. // ------------------------------------------------------------------- queries
  195. unsigned long mysql_real_escape_string(MYSQL *mysql, char *to,
  196. const char *from, unsigned long length);
  197. int mysql_real_query(MYSQL *mysql, const char *q, unsigned long length);
  198. // ---------------------------------------------------------------- query info
  199. unsigned int mysql_field_count(MYSQL *mysql);
  200. my_ulonglong mysql_affected_rows(MYSQL *mysql);
  201. my_ulonglong mysql_insert_id(MYSQL *mysql);
  202. unsigned int mysql_errno(MYSQL *mysql);
  203. const char * mysql_error(MYSQL *mysql);
  204. const char * mysql_sqlstate(MYSQL *mysql);
  205. unsigned int mysql_warning_count(MYSQL *mysql);
  206. const char * mysql_info(MYSQL *mysql);
  207. // ------------------------------------------------------------- query results
  208. int mysql_next_result(MYSQL *mysql);
  209. my_bool mysql_more_results(MYSQL *mysql);
  210. // NOTE: normally we would've made this an opaque handle, but we need to expose
  211. // the connection handle from it so we can report errors for unbuffered reads.
  212. typedef struct st_mysql_res {
  213. my_ulonglong __row_count;
  214. void *__fields;
  215. void *__data;
  216. void *__data_cursor;
  217. void *__lengths;
  218. MYSQL *conn; /* for unbuffered reads */
  219. } MYSQL_RES;
  220. MYSQL_RES *mysql_store_result(MYSQL *mysql);
  221. MYSQL_RES *mysql_use_result(MYSQL *mysql);
  222. void mysql_free_result(MYSQL_RES *result);
  223. my_ulonglong mysql_num_rows(MYSQL_RES *res);
  224. unsigned int mysql_num_fields(MYSQL_RES *res);
  225. my_bool mysql_eof(MYSQL_RES *res);
  226. unsigned long * mysql_fetch_lengths(MYSQL_RES *result);
  227. typedef char **MYSQL_ROW;
  228. MYSQL_ROW mysql_fetch_row(MYSQL_RES *result);
  229. void mysql_data_seek(MYSQL_RES *result, my_ulonglong offset);
  230. typedef struct MYSQL_ROWS_ MYSQL_ROWS;
  231. typedef MYSQL_ROWS *MYSQL_ROW_OFFSET;
  232. MYSQL_ROW_OFFSET mysql_row_tell(MYSQL_RES *res);
  233. MYSQL_ROW_OFFSET mysql_row_seek(MYSQL_RES *result, MYSQL_ROW_OFFSET offset);
  234. // ---------------------------------------------------------- query field info
  235. enum enum_field_types {
  236. MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY,
  237. MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG,
  238. MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE,
  239. MYSQL_TYPE_NULL, MYSQL_TYPE_TIMESTAMP,
  240. MYSQL_TYPE_LONGLONG,MYSQL_TYPE_INT24,
  241. MYSQL_TYPE_DATE, MYSQL_TYPE_TIME,
  242. MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR,
  243. MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
  244. MYSQL_TYPE_BIT,
  245. MYSQL_TYPE_TIMESTAMP2,
  246. MYSQL_TYPE_DATETIME2,
  247. MYSQL_TYPE_TIME2,
  248. MYSQL_TYPE_NEWDECIMAL=246,
  249. MYSQL_TYPE_ENUM=247,
  250. MYSQL_TYPE_SET=248,
  251. MYSQL_TYPE_TINY_BLOB=249,
  252. MYSQL_TYPE_MEDIUM_BLOB=250,
  253. MYSQL_TYPE_LONG_BLOB=251,
  254. MYSQL_TYPE_BLOB=252,
  255. MYSQL_TYPE_VAR_STRING=253,
  256. MYSQL_TYPE_STRING=254,
  257. MYSQL_TYPE_GEOMETRY=255
  258. };
  259. // NOTE: added MYSQL_ prefix to these. Also, these are bit flags, not exclusive enum values.
  260. enum {
  261. MYSQL_NOT_NULL_FLAG = 1, /* Field can't be NULL */
  262. MYSQL_PRI_KEY_FLAG = 2, /* Field is part of a primary key */
  263. MYSQL_UNIQUE_KEY_FLAG = 4, /* Field is part of a unique key */
  264. MYSQL_MULTIPLE_KEY_FLAG = 8, /* Field is part of a key */
  265. MYSQL_BLOB_FLAG = 16, /* Field is a blob */
  266. MYSQL_UNSIGNED_FLAG = 32, /* Field is unsigned */
  267. MYSQL_ZEROFILL_FLAG = 64, /* Field is zerofill */
  268. MYSQL_BINARY_FLAG = 128, /* Field is binary */
  269. /* The following are only sent to new clients */
  270. MYSQL_ENUM_FLAG = 256, /* field is an enum */
  271. MYSQL_AUTO_INCREMENT_FLAG = 512, /* field is a autoincrement field */
  272. MYSQL_TIMESTAMP_FLAG = 1024, /* Field is a timestamp */
  273. MYSQL_SET_FLAG = 2048, /* field is a set */
  274. MYSQL_NO_DEFAULT_VALUE_FLAG = 4096, /* Field doesn't have default value */
  275. MYSQL_ON_UPDATE_NOW_FLAG = 8192, /* Field is set to NOW on UPDATE */
  276. MYSQL_NUM_FLAG = 32768, /* Field is num (for clients) */
  277. MYSQL_PART_KEY_FLAG = 16384, /* Intern; Part of some key */
  278. MYSQL_GROUP_FLAG = 32768, /* Intern: Group field */
  279. MYSQL_UNIQUE_FLAG = 65536, /* Intern: Used by sql_yacc */
  280. MYSQL_BINCMP_FLAG = 131072, /* Intern: Used by sql_yacc */
  281. MYSQL_GET_FIXED_FIELDS_FLAG = (1 << 18), /* Used to get fields in item tree */
  282. MYSQL_FIELD_IN_PART_FUNC_FLAG = (1 << 19) /* Field part of partition func */
  283. };
  284. typedef struct st_mysql_field {
  285. char *name;
  286. char *org_name;
  287. char *table;
  288. char *org_table;
  289. char *db;
  290. char *catalog;
  291. char *def;
  292. unsigned long length;
  293. unsigned long max_length;
  294. unsigned int name_length;
  295. unsigned int org_name_length;
  296. unsigned int table_length;
  297. unsigned int org_table_length;
  298. unsigned int db_length;
  299. unsigned int catalog_length;
  300. unsigned int def_length;
  301. unsigned int flags;
  302. unsigned int decimals;
  303. unsigned int charsetnr;
  304. enum enum_field_types type;
  305. void *extension;
  306. } MYSQL_FIELD;
  307. MYSQL_FIELD *mysql_fetch_field_direct(MYSQL_RES *res, unsigned int fieldnr);
  308. // ---------------------------------------------------------------- reflection
  309. MYSQL_RES *mysql_list_dbs(MYSQL *mysql, const char *wild);
  310. MYSQL_RES *mysql_list_tables(MYSQL *mysql, const char *wild);
  311. MYSQL_RES *mysql_list_processes(MYSQL *mysql);
  312. // ------------------------------------------------------------ remote control
  313. int mysql_kill(MYSQL *mysql, unsigned long pid);
  314. // NOTE: added MYSQL_ prefix.
  315. enum mysql_enum_shutdown_level {
  316. MYSQL_SHUTDOWN_DEFAULT = 0,
  317. MYSQL_SHUTDOWN_WAIT_CONNECTIONS = 1,
  318. MYSQL_SHUTDOWN_WAIT_TRANSACTIONS = 2,
  319. MYSQL_SHUTDOWN_WAIT_UPDATES = 8,
  320. MYSQL_SHUTDOWN_WAIT_ALL_BUFFERS = 16,
  321. MYSQL_SHUTDOWN_WAIT_CRITICAL_BUFFERS = 17,
  322. MYSQL_KILL_QUERY = 254,
  323. MYSQL_KILL_CONNECTION = 255
  324. };
  325. int mysql_shutdown(MYSQL *mysql, enum mysql_enum_shutdown_level shutdown_level); // needs SHUTDOWN priviledge
  326. // NOTE: added MYSQL_ prefix. not really enum values either, just bit flags.
  327. enum {
  328. MYSQL_REFRESH_GRANT = 1, /* Refresh grant tables */
  329. MYSQL_REFRESH_LOG = 2, /* Start on new log file */
  330. MYSQL_REFRESH_TABLES = 4, /* close all tables */
  331. MYSQL_REFRESH_HOSTS = 8, /* Flush host cache */
  332. MYSQL_REFRESH_STATUS = 16, /* Flush status variables */
  333. MYSQL_REFRESH_THREADS = 32, /* Flush thread cache */
  334. MYSQL_REFRESH_SLAVE = 64, /* Reset master info and restart slave thread */
  335. MYSQL_REFRESH_MASTER = 128, /* Remove all bin logs in the index and truncate the index */
  336. MYSQL_REFRESH_ERROR_LOG = 256, /* Rotate only the erorr log */
  337. MYSQL_REFRESH_ENGINE_LOG = 512, /* Flush all storage engine logs */
  338. MYSQL_REFRESH_BINARY_LOG = 1024, /* Flush the binary log */
  339. MYSQL_REFRESH_RELAY_LOG = 2048, /* Flush the relay log */
  340. MYSQL_REFRESH_GENERAL_LOG = 4096, /* Flush the general log */
  341. MYSQL_REFRESH_SLOW_LOG = 8192, /* Flush the slow query log */
  342. /* The following can't be set with mysql_refresh() */
  343. MYSQL_REFRESH_READ_LOCK = 16384, /* Lock tables for read */
  344. MYSQL_REFRESH_FAST = 32768, /* Intern flag */
  345. /* RESET (remove all queries) from query cache */
  346. MYSQL_REFRESH_QUERY_CACHE = 65536,
  347. MYSQL_REFRESH_QUERY_CACHE_FREE = 0x20000, /* pack query cache */
  348. MYSQL_REFRESH_DES_KEY_FILE = 0x40000,
  349. MYSQL_REFRESH_USER_RESOURCES = 0x80000,
  350. MYSQL_REFRESH_FOR_EXPORT = 0x100000, /* FLUSH TABLES ... FOR EXPORT */
  351. };
  352. int mysql_refresh(MYSQL *mysql, unsigned int refresh_options); // needs RELOAD priviledge
  353. int mysql_dump_debug_info(MYSQL *mysql); // needs SUPER priviledge
  354. // ------------------------------------------------------- prepared statements
  355. typedef struct MYSQL_STMT_ MYSQL_STMT;
  356. MYSQL_STMT * mysql_stmt_init(MYSQL *mysql);
  357. my_bool mysql_stmt_close(MYSQL_STMT * stmt);
  358. int mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, unsigned long length);
  359. int mysql_stmt_execute(MYSQL_STMT *stmt);
  360. int mysql_stmt_next_result(MYSQL_STMT *stmt);
  361. int mysql_stmt_store_result(MYSQL_STMT *stmt);
  362. my_bool mysql_stmt_free_result(MYSQL_STMT *stmt);
  363. MYSQL_RES *mysql_stmt_result_metadata(MYSQL_STMT *stmt);
  364. my_ulonglong mysql_stmt_num_rows(MYSQL_STMT *stmt);
  365. my_ulonglong mysql_stmt_affected_rows(MYSQL_STMT *stmt);
  366. my_ulonglong mysql_stmt_insert_id(MYSQL_STMT *stmt);
  367. unsigned int mysql_stmt_field_count(MYSQL_STMT *stmt);
  368. unsigned int mysql_stmt_errno(MYSQL_STMT * stmt);
  369. const char *mysql_stmt_error(MYSQL_STMT * stmt);
  370. const char *mysql_stmt_sqlstate(MYSQL_STMT * stmt);
  371. int mysql_stmt_fetch(MYSQL_STMT *stmt);
  372. my_bool mysql_stmt_reset(MYSQL_STMT * stmt);
  373. void mysql_stmt_data_seek(MYSQL_STMT *stmt, my_ulonglong offset);
  374. MYSQL_ROW_OFFSET mysql_stmt_row_tell(MYSQL_STMT *stmt);
  375. MYSQL_ROW_OFFSET mysql_stmt_row_seek(MYSQL_STMT *stmt, MYSQL_ROW_OFFSET offset);
  376. // NOTE: added MYSQL_ prefix to these.
  377. enum enum_cursor_type
  378. {
  379. MYSQL_CURSOR_TYPE_NO_CURSOR= 0,
  380. MYSQL_CURSOR_TYPE_READ_ONLY= 1,
  381. MYSQL_CURSOR_TYPE_FOR_UPDATE= 2,
  382. MYSQL_CURSOR_TYPE_SCROLLABLE= 4
  383. };
  384. enum enum_stmt_attr_type
  385. {
  386. STMT_ATTR_UPDATE_MAX_LENGTH,
  387. STMT_ATTR_CURSOR_TYPE,
  388. STMT_ATTR_PREFETCH_ROWS
  389. };
  390. my_bool mysql_stmt_attr_set(MYSQL_STMT *stmt, enum enum_stmt_attr_type attr_type, const void *attr);
  391. my_bool mysql_stmt_attr_get(MYSQL_STMT *stmt, enum enum_stmt_attr_type attr_type, void *attr);
  392. my_bool mysql_stmt_send_long_data(MYSQL_STMT *stmt,
  393. unsigned int param_number,
  394. const char *data,
  395. unsigned long length);
  396. // -------------------------------------------- prepared statements / bindings
  397. enum enum_mysql_timestamp_type
  398. {
  399. MYSQL_TIMESTAMP_NONE= -2, MYSQL_TIMESTAMP_ERROR= -1,
  400. MYSQL_TIMESTAMP_DATE= 0, MYSQL_TIMESTAMP_DATETIME= 1, MYSQL_TIMESTAMP_TIME= 2
  401. };
  402. typedef struct st_mysql_time
  403. {
  404. unsigned int year, month, day, hour, minute, second;
  405. unsigned long second_part; /**< microseconds */
  406. my_bool neg;
  407. enum enum_mysql_timestamp_type time_type;
  408. } MYSQL_TIME;
  409. unsigned long mysql_stmt_param_count(MYSQL_STMT * stmt);
  410. typedef struct NET_ NET;
  411. typedef struct st_mysql_bind
  412. {
  413. unsigned long *length;
  414. my_bool *is_null;
  415. void *buffer;
  416. my_bool *error;
  417. unsigned char *row_ptr;
  418. void (*store_param_func)(NET *net, struct st_mysql_bind *param);
  419. void (*fetch_result)(struct st_mysql_bind *, MYSQL_FIELD *,
  420. unsigned char **row);
  421. void (*skip_result)(struct st_mysql_bind *, MYSQL_FIELD *,
  422. unsigned char **row);
  423. unsigned long buffer_length;
  424. unsigned long offset;
  425. unsigned long length_value;
  426. unsigned int param_number;
  427. unsigned int pack_length;
  428. enum enum_field_types buffer_type;
  429. my_bool error_value;
  430. my_bool is_unsigned;
  431. my_bool long_data_used;
  432. my_bool is_null_value;
  433. void *extension;
  434. } MYSQL_BIND;
  435. my_bool mysql_stmt_bind_param(MYSQL_STMT * stmt, MYSQL_BIND * bnd);
  436. my_bool mysql_stmt_bind_result(MYSQL_STMT * stmt, MYSQL_BIND * bnd);
  437. int mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind_arg,
  438. unsigned int column,
  439. unsigned long offset);
  440. // ---------------------------------------------- LOAD DATA LOCAL INFILE hooks
  441. void mysql_set_local_infile_handler(MYSQL *mysql,
  442. int (*local_infile_init)(void **, const char *, void *),
  443. int (*local_infile_read)(void *, char *, unsigned int),
  444. void (*local_infile_end)(void *),
  445. int (*local_infile_error)(void *, char*, unsigned int),
  446. void *);
  447. void mysql_set_local_infile_default(MYSQL *mysql);
  448. // ----------------------------------------------------- mysql proxy scripting
  449. my_bool mysql_read_query_result(MYSQL *mysql);
  450. // ----------------------------------------------------------------- debugging
  451. void mysql_debug(const char *debug);
  452. // ------------------------------------------------ present but not documented
  453. int mysql_server_init(int argc, char **argv, char **groups);
  454. void mysql_server_end(void);
  455. char *get_tty_password(const char *opt_message);
  456. void myodbc_remove_escape(MYSQL *mysql, char *name);
  457. my_bool mysql_embedded(void);
  458. int mysql_send_query(MYSQL *mysql, const char *q, unsigned long length);
  459. // ------------------------------------------------------- redundant functions
  460. my_bool mysql_thread_init(void); // called anyway
  461. void mysql_thread_end(void); // called anyway
  462. const char *mysql_errno_to_sqlstate(unsigned int mysql_errno); // use mysql_sqlstate
  463. unsigned long mysql_hex_string(char *to, const char *from,
  464. unsigned long from_length); // bad taste
  465. // redundant ways to get field info.
  466. // we use use mysql_field_count and mysql_fetch_field_direct instead.
  467. MYSQL_FIELD *mysql_fetch_field(MYSQL_RES *result);
  468. MYSQL_FIELD *mysql_fetch_fields(MYSQL_RES *res);
  469. typedef unsigned int MYSQL_FIELD_OFFSET;
  470. MYSQL_FIELD_OFFSET mysql_field_tell(MYSQL_RES *res);
  471. MYSQL_FIELD_OFFSET mysql_field_seek(MYSQL_RES *result, MYSQL_FIELD_OFFSET offset);
  472. MYSQL_RES *mysql_stmt_param_metadata(MYSQL_STMT *stmt);
  473. // ------------------------------------------------------ deprecated functions
  474. unsigned long mysql_escape_string(char *to, const char *from,
  475. unsigned long from_length); // use mysql_real_escape_string
  476. int mysql_query(MYSQL *mysql, const char *q); // use mysql_real_query
  477. MYSQL_RES *mysql_list_fields(MYSQL *mysql, const char *table,
  478. const char *wild); // use "SHOW COLUMNS FROM table"
  479. ]]