9
3

mysql_com.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. /* Copyright (c) 2000, 2011, Oracle and/or its affiliates.
  2. Copyright (c) 2010, 2013, Monty Program Ab
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; version 2 of the License.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  13. /*
  14. ** Common definition between mysql server & client
  15. */
  16. #ifndef _mysql_com_h
  17. #define _mysql_com_h
  18. #define HOSTNAME_LENGTH 60
  19. #define SYSTEM_CHARSET_MBMAXLEN 3
  20. #define NAME_CHAR_LEN 64 /* Field/table name length */
  21. #define USERNAME_CHAR_LENGTH 128
  22. #define NAME_LEN (NAME_CHAR_LEN*SYSTEM_CHARSET_MBMAXLEN)
  23. #define USERNAME_LENGTH (USERNAME_CHAR_LENGTH*SYSTEM_CHARSET_MBMAXLEN)
  24. #define DEFINER_CHAR_LENGTH (USERNAME_CHAR_LENGTH + HOSTNAME_LENGTH + 1)
  25. #define DEFINER_LENGTH (USERNAME_LENGTH + HOSTNAME_LENGTH + 1)
  26. #define MYSQL_AUTODETECT_CHARSET_NAME "auto"
  27. #define MYSQL50_TABLE_NAME_PREFIX "#mysql50#"
  28. #define MYSQL50_TABLE_NAME_PREFIX_LENGTH (sizeof(MYSQL50_TABLE_NAME_PREFIX)-1)
  29. #define SAFE_NAME_LEN (NAME_LEN + MYSQL50_TABLE_NAME_PREFIX_LENGTH)
  30. /*
  31. MDEV-4088
  32. MySQL (and MariaDB 5.x before the fix) was using the first character of the
  33. server version string (as sent in the first handshake protocol packet) to
  34. decide on the replication event formats. And for 10.x the first character
  35. is "1", which the slave thought comes from some ancient 1.x version
  36. (ignoring the fact that the first ever MySQL version was 3.x).
  37. To support replication to these old clients, we fake the version in the
  38. first handshake protocol packet to start from "5.5.5-" (for example,
  39. it might be "5.5.5-10.0.1-MariaDB-debug-log".
  40. On the client side we remove this fake version prefix to restore the
  41. correct server version. The version "5.5.5" did not support
  42. pluggable authentication, so any version starting from "5.5.5-" and
  43. claiming to support pluggable auth, must be using this fake prefix.
  44. */
  45. /* this version must be the one that *does not* support pluggable auth */
  46. #define RPL_VERSION_HACK "5.5.5-"
  47. #define SERVER_VERSION_LENGTH 60
  48. #define SQLSTATE_LENGTH 5
  49. #define LIST_PROCESS_HOST_LEN 64
  50. /*
  51. Maximum length of comments
  52. */
  53. #define TABLE_COMMENT_INLINE_MAXLEN 180 /* pre 5.5: 60 characters */
  54. #define TABLE_COMMENT_MAXLEN 2048
  55. #define COLUMN_COMMENT_MAXLEN 1024
  56. #define INDEX_COMMENT_MAXLEN 1024
  57. #define TABLE_PARTITION_COMMENT_MAXLEN 1024
  58. /*
  59. USER_HOST_BUFF_SIZE -- length of string buffer, that is enough to contain
  60. username and hostname parts of the user identifier with trailing zero in
  61. MySQL standard format:
  62. user_name_part@host_name_part\0
  63. */
  64. #define USER_HOST_BUFF_SIZE HOSTNAME_LENGTH + USERNAME_LENGTH + 2
  65. #define LOCAL_HOST "localhost"
  66. #define LOCAL_HOST_NAMEDPIPE "."
  67. #if defined(__WIN__) && !defined( _CUSTOMCONFIG_)
  68. #define MYSQL_NAMEDPIPE "MySQL"
  69. #define MYSQL_SERVICENAME "MySQL"
  70. #endif /* __WIN__ */
  71. /*
  72. You should add new commands to the end of this list, otherwise old
  73. servers won't be able to handle them as 'unsupported'.
  74. */
  75. enum enum_server_command
  76. {
  77. COM_SLEEP, COM_QUIT, COM_INIT_DB, COM_QUERY, COM_FIELD_LIST,
  78. COM_CREATE_DB, COM_DROP_DB, COM_REFRESH, COM_SHUTDOWN, COM_STATISTICS,
  79. COM_PROCESS_INFO, COM_CONNECT, COM_PROCESS_KILL, COM_DEBUG, COM_PING,
  80. COM_TIME, COM_DELAYED_INSERT, COM_CHANGE_USER, COM_BINLOG_DUMP,
  81. COM_TABLE_DUMP, COM_CONNECT_OUT, COM_REGISTER_SLAVE,
  82. COM_STMT_PREPARE, COM_STMT_EXECUTE, COM_STMT_SEND_LONG_DATA, COM_STMT_CLOSE,
  83. COM_STMT_RESET, COM_SET_OPTION, COM_STMT_FETCH, COM_DAEMON,
  84. /* don't forget to update const char *command_name[] in sql_parse.cc */
  85. /* Must be last */
  86. COM_END
  87. };
  88. /* sql type stored in .frm files for virtual fields */
  89. #define MYSQL_TYPE_VIRTUAL 245
  90. /*
  91. Length of random string sent by server on handshake; this is also length of
  92. obfuscated password, received from client
  93. */
  94. #define SCRAMBLE_LENGTH 20
  95. #define SCRAMBLE_LENGTH_323 8
  96. /* length of password stored in the db: new passwords are preceeded with '*' */
  97. #define SCRAMBLED_PASSWORD_CHAR_LENGTH (SCRAMBLE_LENGTH*2+1)
  98. #define SCRAMBLED_PASSWORD_CHAR_LENGTH_323 (SCRAMBLE_LENGTH_323*2)
  99. #define NOT_NULL_FLAG 1 /* Field can't be NULL */
  100. #define PRI_KEY_FLAG 2 /* Field is part of a primary key */
  101. #define UNIQUE_KEY_FLAG 4 /* Field is part of a unique key */
  102. #define MULTIPLE_KEY_FLAG 8 /* Field is part of a key */
  103. #define BLOB_FLAG 16 /* Field is a blob */
  104. #define UNSIGNED_FLAG 32 /* Field is unsigned */
  105. #define ZEROFILL_FLAG 64 /* Field is zerofill */
  106. #define BINARY_FLAG 128 /* Field is binary */
  107. /* The following are only sent to new clients */
  108. #define ENUM_FLAG 256 /* field is an enum */
  109. #define AUTO_INCREMENT_FLAG 512 /* field is a autoincrement field */
  110. #define TIMESTAMP_FLAG 1024 /* Field is a timestamp */
  111. #define SET_FLAG 2048 /* field is a set */
  112. #define NO_DEFAULT_VALUE_FLAG 4096 /* Field doesn't have default value */
  113. #define ON_UPDATE_NOW_FLAG 8192 /* Field is set to NOW on UPDATE */
  114. #define NUM_FLAG 32768 /* Field is num (for clients) */
  115. #define PART_KEY_FLAG 16384 /* Intern; Part of some key */
  116. #define GROUP_FLAG 32768 /* Intern: Group field */
  117. #define UNIQUE_FLAG 65536 /* Intern: Used by sql_yacc */
  118. #define BINCMP_FLAG 131072 /* Intern: Used by sql_yacc */
  119. #define GET_FIXED_FIELDS_FLAG (1 << 18) /* Used to get fields in item tree */
  120. #define FIELD_IN_PART_FUNC_FLAG (1 << 19)/* Field part of partition func */
  121. /**
  122. Intern: Field in TABLE object for new version of altered table,
  123. which participates in a newly added index.
  124. */
  125. #define FIELD_IN_ADD_INDEX (1 << 20)
  126. #define FIELD_IS_RENAMED (1<< 21) /* Intern: Field is being renamed */
  127. #define FIELD_FLAGS_STORAGE_MEDIA 22 /* Field storage media, bit 22-23 */
  128. #define FIELD_FLAGS_STORAGE_MEDIA_MASK (3 << FIELD_FLAGS_STORAGE_MEDIA)
  129. #define FIELD_FLAGS_COLUMN_FORMAT 24 /* Field column format, bit 24-25 */
  130. #define FIELD_FLAGS_COLUMN_FORMAT_MASK (3 << FIELD_FLAGS_COLUMN_FORMAT)
  131. #define FIELD_IS_DROPPED (1<< 26) /* Intern: Field is being dropped */
  132. #define HAS_EXPLICIT_VALUE (1 << 27) /* An INSERT/UPDATE operation supplied
  133. an explicit default value */
  134. #define REFRESH_GRANT (1ULL << 0) /* Refresh grant tables */
  135. #define REFRESH_LOG (1ULL << 1) /* Start on new log file */
  136. #define REFRESH_TABLES (1ULL << 2) /* close all tables */
  137. #define REFRESH_HOSTS (1ULL << 3) /* Flush host cache */
  138. #define REFRESH_STATUS (1ULL << 4) /* Flush status variables */
  139. #define REFRESH_THREADS (1ULL << 5) /* Flush thread cache */
  140. #define REFRESH_SLAVE (1ULL << 6) /* Reset master info and restart slave
  141. thread */
  142. #define REFRESH_MASTER (1ULL << 7) /* Remove all bin logs in the index
  143. and truncate the index */
  144. /* The following can't be set with mysql_refresh() */
  145. #define REFRESH_ERROR_LOG (1ULL << 8) /* Rotate only the erorr log */
  146. #define REFRESH_ENGINE_LOG (1ULL << 9) /* Flush all storage engine logs */
  147. #define REFRESH_BINARY_LOG (1ULL << 10) /* Flush the binary log */
  148. #define REFRESH_RELAY_LOG (1ULL << 11) /* Flush the relay log */
  149. #define REFRESH_GENERAL_LOG (1ULL << 12) /* Flush the general log */
  150. #define REFRESH_SLOW_LOG (1ULL << 13) /* Flush the slow query log */
  151. #define REFRESH_READ_LOCK (1ULL << 14) /* Lock tables for read */
  152. #define REFRESH_CHECKPOINT (1ULL << 15) /* With REFRESH_READ_LOCK: block checkpoints too */
  153. #define REFRESH_QUERY_CACHE (1ULL << 16) /* clear the query cache */
  154. #define REFRESH_QUERY_CACHE_FREE (1ULL << 17) /* pack query cache */
  155. #define REFRESH_DES_KEY_FILE (1ULL << 18)
  156. #define REFRESH_USER_RESOURCES (1ULL << 19)
  157. #define REFRESH_FOR_EXPORT (1ULL << 20) /* FLUSH TABLES ... FOR EXPORT */
  158. #define REFRESH_GENERIC (1ULL << 30)
  159. #define REFRESH_FAST (1ULL << 31) /* Intern flag */
  160. #define CLIENT_LONG_PASSWORD 1 /* new more secure passwords */
  161. #define CLIENT_FOUND_ROWS 2 /* Found instead of affected rows */
  162. #define CLIENT_LONG_FLAG 4 /* Get all column flags */
  163. #define CLIENT_CONNECT_WITH_DB 8 /* One can specify db on connect */
  164. #define CLIENT_NO_SCHEMA 16 /* Don't allow database.table.column */
  165. #define CLIENT_COMPRESS 32 /* Can use compression protocol */
  166. #define CLIENT_ODBC 64 /* Odbc client */
  167. #define CLIENT_LOCAL_FILES 128 /* Can use LOAD DATA LOCAL */
  168. #define CLIENT_IGNORE_SPACE 256 /* Ignore spaces before '(' */
  169. #define CLIENT_PROTOCOL_41 512 /* New 4.1 protocol */
  170. #define CLIENT_INTERACTIVE 1024 /* This is an interactive client */
  171. #define CLIENT_SSL 2048 /* Switch to SSL after handshake */
  172. #define CLIENT_IGNORE_SIGPIPE 4096 /* IGNORE sigpipes */
  173. #define CLIENT_TRANSACTIONS 8192 /* Client knows about transactions */
  174. #define CLIENT_RESERVED 16384 /* Old flag for 4.1 protocol */
  175. #define CLIENT_SECURE_CONNECTION 32768 /* New 4.1 authentication */
  176. #define CLIENT_MULTI_STATEMENTS (1UL << 16) /* Enable/disable multi-stmt support */
  177. #define CLIENT_MULTI_RESULTS (1UL << 17) /* Enable/disable multi-results */
  178. #define CLIENT_PS_MULTI_RESULTS (1UL << 18) /* Multi-results in PS-protocol */
  179. #define CLIENT_PLUGIN_AUTH (1UL << 19) /* Client supports plugin authentication */
  180. #define CLIENT_CONNECT_ATTRS (1UL << 20) /* Client supports connection attributes */
  181. /* Enable authentication response packet to be larger than 255 bytes. */
  182. #define CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA (1UL << 21)
  183. /* Don't close the connection for a connection with expired password. */
  184. #define CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS (1UL << 22)
  185. #define CLIENT_PROGRESS (1UL << 29) /* Client support progress indicator */
  186. #define CLIENT_SSL_VERIFY_SERVER_CERT (1UL << 30)
  187. /*
  188. It used to be that if mysql_real_connect() failed, it would delete any
  189. options set by the client, unless the CLIENT_REMEMBER_OPTIONS flag was
  190. given.
  191. That behaviour does not appear very useful, and it seems unlikely that
  192. any applications would actually depend on this. So from MariaDB 5.5 we
  193. always preserve any options set in case of failed connect, and this
  194. option is effectively always set.
  195. */
  196. #define CLIENT_REMEMBER_OPTIONS (1UL << 31)
  197. #ifdef HAVE_COMPRESS
  198. #define CAN_CLIENT_COMPRESS CLIENT_COMPRESS
  199. #else
  200. #define CAN_CLIENT_COMPRESS 0
  201. #endif
  202. /* Gather all possible capabilites (flags) supported by the server */
  203. #define CLIENT_ALL_FLAGS (CLIENT_LONG_PASSWORD | \
  204. CLIENT_FOUND_ROWS | \
  205. CLIENT_LONG_FLAG | \
  206. CLIENT_CONNECT_WITH_DB | \
  207. CLIENT_NO_SCHEMA | \
  208. CLIENT_COMPRESS | \
  209. CLIENT_ODBC | \
  210. CLIENT_LOCAL_FILES | \
  211. CLIENT_IGNORE_SPACE | \
  212. CLIENT_PROTOCOL_41 | \
  213. CLIENT_INTERACTIVE | \
  214. CLIENT_SSL | \
  215. CLIENT_IGNORE_SIGPIPE | \
  216. CLIENT_TRANSACTIONS | \
  217. CLIENT_RESERVED | \
  218. CLIENT_SECURE_CONNECTION | \
  219. CLIENT_MULTI_STATEMENTS | \
  220. CLIENT_MULTI_RESULTS | \
  221. CLIENT_PS_MULTI_RESULTS | \
  222. CLIENT_SSL_VERIFY_SERVER_CERT | \
  223. CLIENT_REMEMBER_OPTIONS | \
  224. CLIENT_PROGRESS | \
  225. CLIENT_PLUGIN_AUTH | \
  226. CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA | \
  227. CLIENT_CONNECT_ATTRS)
  228. /*
  229. To be added later:
  230. CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS
  231. */
  232. /*
  233. Switch off the flags that are optional and depending on build flags
  234. If any of the optional flags is supported by the build it will be switched
  235. on before sending to the client during the connection handshake.
  236. */
  237. #define CLIENT_BASIC_FLAGS (((CLIENT_ALL_FLAGS & ~CLIENT_SSL) \
  238. & ~CLIENT_COMPRESS) \
  239. & ~CLIENT_SSL_VERIFY_SERVER_CERT)
  240. /**
  241. Is raised when a multi-statement transaction
  242. has been started, either explicitly, by means
  243. of BEGIN or COMMIT AND CHAIN, or
  244. implicitly, by the first transactional
  245. statement, when autocommit=off.
  246. */
  247. #define SERVER_STATUS_IN_TRANS 1
  248. #define SERVER_STATUS_AUTOCOMMIT 2 /* Server in auto_commit mode */
  249. #define SERVER_MORE_RESULTS_EXISTS 8 /* Multi query - next query exists */
  250. #define SERVER_QUERY_NO_GOOD_INDEX_USED 16
  251. #define SERVER_QUERY_NO_INDEX_USED 32
  252. /**
  253. The server was able to fulfill the clients request and opened a
  254. read-only non-scrollable cursor for a query. This flag comes
  255. in reply to COM_STMT_EXECUTE and COM_STMT_FETCH commands.
  256. */
  257. #define SERVER_STATUS_CURSOR_EXISTS 64
  258. /**
  259. This flag is sent when a read-only cursor is exhausted, in reply to
  260. COM_STMT_FETCH command.
  261. */
  262. #define SERVER_STATUS_LAST_ROW_SENT 128
  263. #define SERVER_STATUS_DB_DROPPED 256 /* A database was dropped */
  264. #define SERVER_STATUS_NO_BACKSLASH_ESCAPES 512
  265. /**
  266. Sent to the client if after a prepared statement reprepare
  267. we discovered that the new statement returns a different
  268. number of result set columns.
  269. */
  270. #define SERVER_STATUS_METADATA_CHANGED 1024
  271. #define SERVER_QUERY_WAS_SLOW 2048
  272. /**
  273. To mark ResultSet containing output parameter values.
  274. */
  275. #define SERVER_PS_OUT_PARAMS 4096
  276. /**
  277. Set at the same time as SERVER_STATUS_IN_TRANS if the started
  278. multi-statement transaction is a read-only transaction. Cleared
  279. when the transaction commits or aborts. Since this flag is sent
  280. to clients in OK and EOF packets, the flag indicates the
  281. transaction status at the end of command execution.
  282. */
  283. #define SERVER_STATUS_IN_TRANS_READONLY 8192
  284. /**
  285. Server status flags that must be cleared when starting
  286. execution of a new SQL statement.
  287. Flags from this set are only added to the
  288. current server status by the execution engine, but
  289. never removed -- the execution engine expects them
  290. to disappear automagically by the next command.
  291. */
  292. #define SERVER_STATUS_CLEAR_SET (SERVER_QUERY_NO_GOOD_INDEX_USED| \
  293. SERVER_QUERY_NO_INDEX_USED|\
  294. SERVER_MORE_RESULTS_EXISTS|\
  295. SERVER_STATUS_METADATA_CHANGED |\
  296. SERVER_QUERY_WAS_SLOW |\
  297. SERVER_STATUS_DB_DROPPED |\
  298. SERVER_STATUS_CURSOR_EXISTS|\
  299. SERVER_STATUS_LAST_ROW_SENT)
  300. #define MYSQL_ERRMSG_SIZE 512
  301. #define NET_READ_TIMEOUT 30 /* Timeout on read */
  302. #define NET_WRITE_TIMEOUT 60 /* Timeout on write */
  303. #define NET_WAIT_TIMEOUT 8*60*60 /* Wait for new query */
  304. struct st_vio; /* Only C */
  305. typedef struct st_vio Vio;
  306. #define MAX_TINYINT_WIDTH 3 /* Max width for a TINY w.o. sign */
  307. #define MAX_SMALLINT_WIDTH 5 /* Max width for a SHORT w.o. sign */
  308. #define MAX_MEDIUMINT_WIDTH 8 /* Max width for a INT24 w.o. sign */
  309. #define MAX_INT_WIDTH 10 /* Max width for a LONG w.o. sign */
  310. #define MAX_BIGINT_WIDTH 20 /* Max width for a LONGLONG */
  311. #define MAX_CHAR_WIDTH 255 /* Max length for a CHAR colum */
  312. #define MAX_BLOB_WIDTH 16777216 /* Default width for blob */
  313. typedef struct st_net {
  314. #if !defined(CHECK_EMBEDDED_DIFFERENCES) || !defined(EMBEDDED_LIBRARY)
  315. Vio *vio;
  316. unsigned char *buff,*buff_end,*write_pos,*read_pos;
  317. my_socket fd; /* For Perl DBI/dbd */
  318. /*
  319. The following variable is set if we are doing several queries in one
  320. command ( as in LOAD TABLE ... FROM MASTER ),
  321. and do not want to confuse the client with OK at the wrong time
  322. */
  323. unsigned long remain_in_buf,length, buf_length, where_b;
  324. unsigned long max_packet,max_packet_size;
  325. unsigned int pkt_nr,compress_pkt_nr;
  326. unsigned int write_timeout, read_timeout, retry_count;
  327. int fcntl;
  328. unsigned int *return_status;
  329. unsigned char reading_or_writing;
  330. char save_char;
  331. char net_skip_rest_factor;
  332. my_bool thread_specific_malloc;
  333. unsigned char compress;
  334. my_bool unused3; /* Please remove with the next incompatible ABI change. */
  335. /*
  336. Pointer to query object in query cache, do not equal NULL (0) for
  337. queries in cache that have not stored its results yet
  338. */
  339. #endif
  340. void *thd; /* Used by MariaDB server to avoid calling current_thd */
  341. unsigned int last_errno;
  342. unsigned char error;
  343. my_bool unused4; /* Please remove with the next incompatible ABI change. */
  344. my_bool unused5; /* Please remove with the next incompatible ABI change. */
  345. /** Client library error message buffer. Actually belongs to struct MYSQL. */
  346. char last_error[MYSQL_ERRMSG_SIZE];
  347. /** Client library sqlstate buffer. Set along with the error message. */
  348. char sqlstate[SQLSTATE_LENGTH+1];
  349. void *extension;
  350. } NET;
  351. #define packet_error (~(unsigned long) 0)
  352. enum enum_field_types { MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY,
  353. MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG,
  354. MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE,
  355. MYSQL_TYPE_NULL, MYSQL_TYPE_TIMESTAMP,
  356. MYSQL_TYPE_LONGLONG,MYSQL_TYPE_INT24,
  357. MYSQL_TYPE_DATE, MYSQL_TYPE_TIME,
  358. MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR,
  359. MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
  360. MYSQL_TYPE_BIT,
  361. /*
  362. mysql-5.6 compatibility temporal types.
  363. They're only used internally for reading RBR
  364. mysql-5.6 binary log events and mysql-5.6 frm files.
  365. They're never sent to the client.
  366. */
  367. MYSQL_TYPE_TIMESTAMP2,
  368. MYSQL_TYPE_DATETIME2,
  369. MYSQL_TYPE_TIME2,
  370. MYSQL_TYPE_NEWDECIMAL=246,
  371. MYSQL_TYPE_ENUM=247,
  372. MYSQL_TYPE_SET=248,
  373. MYSQL_TYPE_TINY_BLOB=249,
  374. MYSQL_TYPE_MEDIUM_BLOB=250,
  375. MYSQL_TYPE_LONG_BLOB=251,
  376. MYSQL_TYPE_BLOB=252,
  377. MYSQL_TYPE_VAR_STRING=253,
  378. MYSQL_TYPE_STRING=254,
  379. MYSQL_TYPE_GEOMETRY=255
  380. };
  381. /* For backward compatibility */
  382. #define CLIENT_MULTI_QUERIES CLIENT_MULTI_STATEMENTS
  383. #define FIELD_TYPE_DECIMAL MYSQL_TYPE_DECIMAL
  384. #define FIELD_TYPE_NEWDECIMAL MYSQL_TYPE_NEWDECIMAL
  385. #define FIELD_TYPE_TINY MYSQL_TYPE_TINY
  386. #define FIELD_TYPE_SHORT MYSQL_TYPE_SHORT
  387. #define FIELD_TYPE_LONG MYSQL_TYPE_LONG
  388. #define FIELD_TYPE_FLOAT MYSQL_TYPE_FLOAT
  389. #define FIELD_TYPE_DOUBLE MYSQL_TYPE_DOUBLE
  390. #define FIELD_TYPE_NULL MYSQL_TYPE_NULL
  391. #define FIELD_TYPE_TIMESTAMP MYSQL_TYPE_TIMESTAMP
  392. #define FIELD_TYPE_LONGLONG MYSQL_TYPE_LONGLONG
  393. #define FIELD_TYPE_INT24 MYSQL_TYPE_INT24
  394. #define FIELD_TYPE_DATE MYSQL_TYPE_DATE
  395. #define FIELD_TYPE_TIME MYSQL_TYPE_TIME
  396. #define FIELD_TYPE_DATETIME MYSQL_TYPE_DATETIME
  397. #define FIELD_TYPE_YEAR MYSQL_TYPE_YEAR
  398. #define FIELD_TYPE_NEWDATE MYSQL_TYPE_NEWDATE
  399. #define FIELD_TYPE_ENUM MYSQL_TYPE_ENUM
  400. #define FIELD_TYPE_SET MYSQL_TYPE_SET
  401. #define FIELD_TYPE_TINY_BLOB MYSQL_TYPE_TINY_BLOB
  402. #define FIELD_TYPE_MEDIUM_BLOB MYSQL_TYPE_MEDIUM_BLOB
  403. #define FIELD_TYPE_LONG_BLOB MYSQL_TYPE_LONG_BLOB
  404. #define FIELD_TYPE_BLOB MYSQL_TYPE_BLOB
  405. #define FIELD_TYPE_VAR_STRING MYSQL_TYPE_VAR_STRING
  406. #define FIELD_TYPE_STRING MYSQL_TYPE_STRING
  407. #define FIELD_TYPE_CHAR MYSQL_TYPE_TINY
  408. #define FIELD_TYPE_INTERVAL MYSQL_TYPE_ENUM
  409. #define FIELD_TYPE_GEOMETRY MYSQL_TYPE_GEOMETRY
  410. #define FIELD_TYPE_BIT MYSQL_TYPE_BIT
  411. /* Shutdown/kill enums and constants */
  412. /* Bits for THD::killable. */
  413. #define MYSQL_SHUTDOWN_KILLABLE_CONNECT (unsigned char)(1 << 0)
  414. #define MYSQL_SHUTDOWN_KILLABLE_TRANS (unsigned char)(1 << 1)
  415. #define MYSQL_SHUTDOWN_KILLABLE_LOCK_TABLE (unsigned char)(1 << 2)
  416. #define MYSQL_SHUTDOWN_KILLABLE_UPDATE (unsigned char)(1 << 3)
  417. enum mysql_enum_shutdown_level {
  418. /*
  419. We want levels to be in growing order of hardness (because we use number
  420. comparisons). Note that DEFAULT does not respect the growing property, but
  421. it's ok.
  422. */
  423. SHUTDOWN_DEFAULT = 0,
  424. /* wait for existing connections to finish */
  425. SHUTDOWN_WAIT_CONNECTIONS= MYSQL_SHUTDOWN_KILLABLE_CONNECT,
  426. /* wait for existing trans to finish */
  427. SHUTDOWN_WAIT_TRANSACTIONS= MYSQL_SHUTDOWN_KILLABLE_TRANS,
  428. /* wait for existing updates to finish (=> no partial MyISAM update) */
  429. SHUTDOWN_WAIT_UPDATES= MYSQL_SHUTDOWN_KILLABLE_UPDATE,
  430. /* flush InnoDB buffers and other storage engines' buffers*/
  431. SHUTDOWN_WAIT_ALL_BUFFERS= (MYSQL_SHUTDOWN_KILLABLE_UPDATE << 1),
  432. /* don't flush InnoDB buffers, flush other storage engines' buffers*/
  433. SHUTDOWN_WAIT_CRITICAL_BUFFERS= (MYSQL_SHUTDOWN_KILLABLE_UPDATE << 1) + 1
  434. };
  435. enum enum_cursor_type
  436. {
  437. CURSOR_TYPE_NO_CURSOR= 0,
  438. CURSOR_TYPE_READ_ONLY= 1,
  439. CURSOR_TYPE_FOR_UPDATE= 2,
  440. CURSOR_TYPE_SCROLLABLE= 4
  441. };
  442. /* options for mysql_set_option */
  443. enum enum_mysql_set_option
  444. {
  445. MYSQL_OPTION_MULTI_STATEMENTS_ON,
  446. MYSQL_OPTION_MULTI_STATEMENTS_OFF
  447. };
  448. #define net_new_transaction(net) ((net)->pkt_nr=0)
  449. #ifdef __cplusplus
  450. extern "C" {
  451. #endif
  452. my_bool my_net_init(NET *net, Vio* vio, void *thd, unsigned int my_flags);
  453. void my_net_local_init(NET *net);
  454. void net_end(NET *net);
  455. void net_clear(NET *net, my_bool clear_buffer);
  456. my_bool net_realloc(NET *net, size_t length);
  457. my_bool net_flush(NET *net);
  458. my_bool my_net_write(NET *net,const unsigned char *packet, size_t len);
  459. my_bool net_write_command(NET *net,unsigned char command,
  460. const unsigned char *header, size_t head_len,
  461. const unsigned char *packet, size_t len);
  462. int net_real_write(NET *net,const unsigned char *packet, size_t len);
  463. unsigned long my_net_read_packet(NET *net, my_bool read_from_server);
  464. #define my_net_read(A) my_net_read_packet((A), 0)
  465. #ifdef MY_GLOBAL_INCLUDED
  466. void my_net_set_write_timeout(NET *net, uint timeout);
  467. void my_net_set_read_timeout(NET *net, uint timeout);
  468. #endif
  469. struct sockaddr;
  470. int my_connect(my_socket s, const struct sockaddr *name, unsigned int namelen,
  471. unsigned int timeout);
  472. struct my_rnd_struct;
  473. #ifdef __cplusplus
  474. }
  475. #endif
  476. /* The following is for user defined functions */
  477. enum Item_result
  478. {
  479. STRING_RESULT=0, REAL_RESULT, INT_RESULT, ROW_RESULT, DECIMAL_RESULT,
  480. TIME_RESULT
  481. };
  482. typedef struct st_udf_args
  483. {
  484. unsigned int arg_count; /* Number of arguments */
  485. enum Item_result *arg_type; /* Pointer to item_results */
  486. char **args; /* Pointer to argument */
  487. unsigned long *lengths; /* Length of string arguments */
  488. char *maybe_null; /* Set to 1 for all maybe_null args */
  489. char **attributes; /* Pointer to attribute name */
  490. unsigned long *attribute_lengths; /* Length of attribute arguments */
  491. void *extension;
  492. } UDF_ARGS;
  493. /* This holds information about the result */
  494. typedef struct st_udf_init
  495. {
  496. my_bool maybe_null; /* 1 if function can return NULL */
  497. unsigned int decimals; /* for real functions */
  498. unsigned long max_length; /* For string functions */
  499. char *ptr; /* free pointer for function data */
  500. my_bool const_item; /* 1 if function always returns the same value */
  501. void *extension;
  502. } UDF_INIT;
  503. /*
  504. TODO: add a notion for determinism of the UDF.
  505. See Item_udf_func::update_used_tables ()
  506. */
  507. /* Constants when using compression */
  508. #define NET_HEADER_SIZE 4 /* standard header size */
  509. #define COMP_HEADER_SIZE 3 /* compression header extra size */
  510. /* Prototypes to password functions */
  511. #ifdef __cplusplus
  512. extern "C" {
  513. #endif
  514. /*
  515. These functions are used for authentication by client and server and
  516. implemented in sql/password.c
  517. */
  518. void create_random_string(char *to, unsigned int length,
  519. struct my_rnd_struct *rand_st);
  520. void hash_password(unsigned long *to, const char *password, unsigned int password_len);
  521. void make_scrambled_password_323(char *to, const char *password);
  522. void scramble_323(char *to, const char *message, const char *password);
  523. my_bool check_scramble_323(const unsigned char *reply, const char *message,
  524. unsigned long *salt);
  525. void get_salt_from_password_323(unsigned long *res, const char *password);
  526. void make_scrambled_password(char *to, const char *password);
  527. void scramble(char *to, const char *message, const char *password);
  528. my_bool check_scramble(const unsigned char *reply, const char *message,
  529. const unsigned char *hash_stage2);
  530. void get_salt_from_password(unsigned char *res, const char *password);
  531. char *octet2hex(char *to, const char *str, unsigned int len);
  532. /* end of password.c */
  533. char *get_tty_password(const char *opt_message);
  534. void get_tty_password_buff(const char *opt_message, char *to, size_t length);
  535. const char *mysql_errno_to_sqlstate(unsigned int mysql_errno);
  536. /* Some other useful functions */
  537. my_bool my_thread_init(void);
  538. void my_thread_end(void);
  539. #ifdef MY_GLOBAL_INCLUDED
  540. ulong STDCALL net_field_length(uchar **packet);
  541. my_ulonglong net_field_length_ll(uchar **packet);
  542. my_ulonglong safe_net_field_length_ll(uchar **packet, size_t packet_len);
  543. uchar *net_store_length(uchar *pkg, ulonglong length);
  544. uchar *safe_net_store_length(uchar *pkg, size_t pkg_len, ulonglong length);
  545. #endif
  546. #ifdef __cplusplus
  547. }
  548. #endif
  549. #define NULL_LENGTH ((unsigned long) ~0) /* For net_store_length */
  550. #define MYSQL_STMT_HEADER 4
  551. #define MYSQL_LONG_DATA_HEADER 6
  552. #define NOT_FIXED_DEC 31
  553. #endif