mariadb_com.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. /************************************************************************************
  2. Copyright (C) 2000, 2012 MySQL AB & MySQL Finland AB & TCX DataKonsult AB,
  3. Monty Program AB
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public
  13. License along with this library; if not see <http://www.gnu.org/licenses>
  14. or write to the Free Software Foundation, Inc.,
  15. 51 Franklin St., Fifth Floor, Boston, MA 02110, USA
  16. Part of this code includes code from the PHP project which
  17. is freely available from http://www.php.net
  18. *************************************************************************************/
  19. /*
  20. ** Common definition between mysql server & client
  21. */
  22. #ifndef _mysql_com_h
  23. #define _mysql_com_h
  24. #define NAME_CHAR_LEN 64
  25. #define NAME_LEN 256 /* Field/table name length */
  26. #define HOSTNAME_LENGTH 60
  27. #define SYSTEM_MB_MAX_CHAR_LENGTH 4
  28. #define USERNAME_CHAR_LENGTH 128
  29. #define USERNAME_LENGTH USERNAME_CHAR_LENGTH * SYSTEM_MB_MAX_CHAR_LENGTH
  30. #define SERVER_VERSION_LENGTH 60
  31. #define SQLSTATE_LENGTH 5
  32. #define SCRAMBLE_LENGTH 20
  33. #define SCRAMBLE_LENGTH_323 8
  34. #define LOCAL_HOST "localhost"
  35. #define LOCAL_HOST_NAMEDPIPE "."
  36. #if defined(_WIN32) && !defined( _CUSTOMCONFIG_)
  37. #define MARIADB_NAMEDPIPE "MySQL"
  38. #define MYSQL_SERVICENAME "MySql"
  39. #endif /* _WIN32 */
  40. /* for use in mysql client tools only */
  41. #define MYSQL_AUTODETECT_CHARSET_NAME "auto"
  42. #define BINCMP_FLAG 131072
  43. enum mysql_enum_shutdown_level
  44. {
  45. SHUTDOWN_DEFAULT = 0,
  46. KILL_QUERY= 254,
  47. KILL_CONNECTION= 255
  48. };
  49. enum enum_server_command
  50. {
  51. COM_SLEEP = 0,
  52. COM_QUIT,
  53. COM_INIT_DB,
  54. COM_QUERY,
  55. COM_FIELD_LIST,
  56. COM_CREATE_DB,
  57. COM_DROP_DB,
  58. COM_REFRESH,
  59. COM_SHUTDOWN,
  60. COM_STATISTICS,
  61. COM_PROCESS_INFO,
  62. COM_CONNECT,
  63. COM_PROCESS_KILL,
  64. COM_DEBUG,
  65. COM_PING,
  66. COM_TIME = 15,
  67. COM_DELAYED_INSERT,
  68. COM_CHANGE_USER,
  69. COM_BINLOG_DUMP,
  70. COM_TABLE_DUMP,
  71. COM_CONNECT_OUT = 20,
  72. COM_REGISTER_SLAVE,
  73. COM_STMT_PREPARE = 22,
  74. COM_STMT_EXECUTE = 23,
  75. COM_STMT_SEND_LONG_DATA = 24,
  76. COM_STMT_CLOSE = 25,
  77. COM_STMT_RESET = 26,
  78. COM_SET_OPTION = 27,
  79. COM_STMT_FETCH = 28,
  80. COM_DAEMON= 29,
  81. COM_UNSUPPORTED= 30,
  82. COM_RESET_CONNECTION = 31,
  83. COM_STMT_BULK_EXECUTE = 250,
  84. COM_MULTI = 254,
  85. COM_END
  86. };
  87. #define NOT_NULL_FLAG 1 /* Field can't be NULL */
  88. #define PRI_KEY_FLAG 2 /* Field is part of a primary key */
  89. #define UNIQUE_KEY_FLAG 4 /* Field is part of a unique key */
  90. #define MULTIPLE_KEY_FLAG 8 /* Field is part of a key */
  91. #define BLOB_FLAG 16 /* Field is a blob */
  92. #define UNSIGNED_FLAG 32 /* Field is unsigned */
  93. #define ZEROFILL_FLAG 64 /* Field is zerofill */
  94. #define BINARY_FLAG 128
  95. /* The following are only sent to new clients */
  96. #define ENUM_FLAG 256 /* field is an enum */
  97. #define AUTO_INCREMENT_FLAG 512 /* field is a autoincrement field */
  98. #define TIMESTAMP_FLAG 1024 /* Field is a timestamp */
  99. #define SET_FLAG 2048 /* field is a set */
  100. /* new since 3.23.58 */
  101. #define NO_DEFAULT_VALUE_FLAG 4096 /* Field doesn't have default value */
  102. #define ON_UPDATE_NOW_FLAG 8192 /* Field is set to NOW on UPDATE */
  103. /* end new */
  104. #define NUM_FLAG 32768 /* Field is num (for clients) */
  105. #define PART_KEY_FLAG 16384 /* Intern; Part of some key */
  106. #define GROUP_FLAG 32768 /* Intern: Group field */
  107. #define UNIQUE_FLAG 65536 /* Intern: Used by sql_yacc */
  108. #define REFRESH_GRANT 1 /* Refresh grant tables */
  109. #define REFRESH_LOG 2 /* Start on new log file */
  110. #define REFRESH_TABLES 4 /* close all tables */
  111. #define REFRESH_HOSTS 8 /* Flush host cache */
  112. #define REFRESH_STATUS 16 /* Flush status variables */
  113. #define REFRESH_THREADS 32 /* Flush thread cache */
  114. #define REFRESH_SLAVE 64 /* Reset master info and restart slave
  115. thread */
  116. #define REFRESH_MASTER 128 /* Remove all bin logs in the index
  117. and truncate the index */
  118. /* The following can't be set with mysql_refresh() */
  119. #define REFRESH_READ_LOCK 16384 /* Lock tables for read */
  120. #define REFRESH_FAST 32768 /* Intern flag */
  121. #define CLIENT_MYSQL 1
  122. #define CLIENT_FOUND_ROWS 2 /* Found instead of affected rows */
  123. #define CLIENT_LONG_FLAG 4 /* Get all column flags */
  124. #define CLIENT_CONNECT_WITH_DB 8 /* One can specify db on connect */
  125. #define CLIENT_NO_SCHEMA 16 /* Don't allow database.table.column */
  126. #define CLIENT_COMPRESS 32 /* Can use compression protocol */
  127. #define CLIENT_ODBC 64 /* Odbc client */
  128. #define CLIENT_LOCAL_FILES 128 /* Can use LOAD DATA LOCAL */
  129. #define CLIENT_IGNORE_SPACE 256 /* Ignore spaces before '(' */
  130. #define CLIENT_INTERACTIVE 1024 /* This is an interactive client */
  131. #define CLIENT_SSL 2048 /* Switch to SSL after handshake */
  132. #define CLIENT_IGNORE_SIGPIPE 4096 /* IGNORE sigpipes */
  133. #define CLIENT_TRANSACTIONS 8192 /* Client knows about transactions */
  134. /* added in 4.x */
  135. #define CLIENT_PROTOCOL_41 512
  136. #define CLIENT_RESERVED 16384
  137. #define CLIENT_SECURE_CONNECTION 32768
  138. #define CLIENT_MULTI_STATEMENTS (1UL << 16)
  139. #define CLIENT_MULTI_RESULTS (1UL << 17)
  140. #define CLIENT_PS_MULTI_RESULTS (1UL << 18)
  141. #define CLIENT_PLUGIN_AUTH (1UL << 19)
  142. #define CLIENT_CONNECT_ATTRS (1UL << 20)
  143. #define CLIENT_SESSION_TRACKING (1UL << 23)
  144. #define CLIENT_PROGRESS (1UL << 29) /* client supports progress indicator */
  145. #define CLIENT_PROGRESS_OBSOLETE CLIENT_PROGRESS
  146. #define CLIENT_SSL_VERIFY_SERVER_CERT (1UL << 30)
  147. #define CLIENT_REMEMBER_OPTIONS (1UL << 31)
  148. /* MariaDB specific capabilities */
  149. #define MARIADB_CLIENT_FLAGS 0xFFFFFFFF00000000ULL
  150. #define MARIADB_CLIENT_PROGRESS (1ULL << 32)
  151. #define MARIADB_CLIENT_COM_MULTI (1ULL << 33)
  152. #define MARIADB_CLIENT_STMT_BULK_OPERATIONS (1ULL << 34)
  153. #define IS_MARIADB_EXTENDED_SERVER(mysql)\
  154. !(mysql->server_capabilities & CLIENT_MYSQL)
  155. #define MARIADB_CLIENT_SUPPORTED_FLAGS (MARIADB_CLIENT_PROGRESS |\
  156. MARIADB_CLIENT_COM_MULTI |\
  157. MARIADB_CLIENT_STMT_BULK_OPERATIONS)
  158. #define CLIENT_SUPPORTED_FLAGS (CLIENT_MYSQL |\
  159. CLIENT_FOUND_ROWS |\
  160. CLIENT_LONG_FLAG |\
  161. CLIENT_CONNECT_WITH_DB |\
  162. CLIENT_NO_SCHEMA |\
  163. CLIENT_COMPRESS |\
  164. CLIENT_ODBC |\
  165. CLIENT_LOCAL_FILES |\
  166. CLIENT_IGNORE_SPACE |\
  167. CLIENT_INTERACTIVE |\
  168. CLIENT_SSL |\
  169. CLIENT_IGNORE_SIGPIPE |\
  170. CLIENT_TRANSACTIONS |\
  171. CLIENT_PROTOCOL_41 |\
  172. CLIENT_RESERVED |\
  173. CLIENT_SECURE_CONNECTION |\
  174. CLIENT_MULTI_STATEMENTS |\
  175. CLIENT_MULTI_RESULTS |\
  176. CLIENT_PROGRESS |\
  177. CLIENT_SSL_VERIFY_SERVER_CERT |\
  178. CLIENT_REMEMBER_OPTIONS |\
  179. CLIENT_PLUGIN_AUTH |\
  180. CLIENT_SESSION_TRACKING |\
  181. CLIENT_CONNECT_ATTRS)
  182. #define CLIENT_CAPABILITIES (CLIENT_MYSQL | \
  183. CLIENT_LONG_FLAG |\
  184. CLIENT_TRANSACTIONS |\
  185. CLIENT_SECURE_CONNECTION |\
  186. CLIENT_MULTI_RESULTS | \
  187. CLIENT_PS_MULTI_RESULTS |\
  188. CLIENT_PROTOCOL_41 |\
  189. CLIENT_PLUGIN_AUTH |\
  190. CLIENT_SESSION_TRACKING |\
  191. CLIENT_CONNECT_ATTRS)
  192. #define CLIENT_DEFAULT_FLAGS ((CLIENT_SUPPORTED_FLAGS & ~CLIENT_COMPRESS)\
  193. & ~CLIENT_SSL)
  194. #define SERVER_STATUS_IN_TRANS 1 /* Transaction has started */
  195. #define SERVER_STATUS_AUTOCOMMIT 2 /* Server in auto_commit mode */
  196. #define SERVER_MORE_RESULTS_EXIST 8
  197. #define SERVER_QUERY_NO_GOOD_INDEX_USED 16
  198. #define SERVER_QUERY_NO_INDEX_USED 32
  199. #define SERVER_STATUS_CURSOR_EXISTS 64
  200. #define SERVER_STATUS_LAST_ROW_SENT 128
  201. #define SERVER_STATUS_DB_DROPPED 256
  202. #define SERVER_STATUS_NO_BACKSLASH_ESCAPES 512
  203. #define SERVER_STATUS_METADATA_CHANGED 1024
  204. #define SERVER_QUERY_WAS_SLOW 2048
  205. #define SERVER_PS_OUT_PARAMS 4096
  206. #define SERVER_SESSION_STATE_CHANGED (1UL << 14)
  207. #define MYSQL_ERRMSG_SIZE 512
  208. #define NET_READ_TIMEOUT 30 /* Timeout on read */
  209. #define NET_WRITE_TIMEOUT 60 /* Timeout on write */
  210. #define NET_WAIT_TIMEOUT 8*60*60 /* Wait for new query */
  211. /* for server integration (mysqlbinlog) */
  212. #define LIST_PROCESS_HOST_LEN 64
  213. #define MYSQL50_TABLE_NAME_PREFIX "#mysql50#"
  214. #define MYSQL50_TABLE_NAME_PREFIX_LENGTH (sizeof(MYSQL50_TABLE_NAME_PREFIX)-1)
  215. #define SAFE_NAME_LEN (NAME_LEN + MYSQL50_TABLE_NAME_PREFIX_LENGTH)
  216. struct st_ma_pvio;
  217. typedef struct st_ma_pvio MARIADB_PVIO;
  218. #define MAX_CHAR_WIDTH 255 /* Max length for a CHAR colum */
  219. #define MAX_BLOB_WIDTH 8192 /* Default width for blob */
  220. /* the following defines were added for PHP's mysqli and pdo extensions:
  221. see: CONC-56
  222. */
  223. #define MAX_TINYINT_WIDTH 3
  224. #define MAX_SMALLINT_WIDTH 5
  225. #define MAX_MEDIUMINT_WIDTH 8
  226. #define MAX_INT_WIDTH 10
  227. #define MAX_BIGINT_WIDTH 20
  228. struct st_ma_connection_plugin;
  229. typedef struct st_net {
  230. MARIADB_PVIO *pvio;
  231. unsigned char *buff;
  232. unsigned char *buff_end,*write_pos,*read_pos;
  233. my_socket fd; /* For Perl DBI/dbd */
  234. unsigned long remain_in_buf,length;
  235. unsigned long buf_length, where_b;
  236. unsigned long max_packet, max_packet_size;
  237. unsigned int pkt_nr, compress_pkt_nr;
  238. unsigned int write_timeout, read_timeout, retry_count;
  239. int fcntl;
  240. unsigned int *return_status;
  241. unsigned char reading_or_writing;
  242. char save_char;
  243. char unused_1;
  244. my_bool unused_2;
  245. my_bool compress;
  246. my_bool unused_3;
  247. void *unused_4;
  248. unsigned int last_errno;
  249. unsigned char error;
  250. my_bool unused_5;
  251. my_bool unused_6;
  252. char last_error[MYSQL_ERRMSG_SIZE];
  253. char sqlstate[SQLSTATE_LENGTH+1];
  254. struct st_mariadb_net_extension *extension;
  255. } NET;
  256. #define packet_error ((unsigned int) -1)
  257. /* used by mysql_set_server_option */
  258. enum enum_mysql_set_option
  259. {
  260. MYSQL_OPTION_MULTI_STATEMENTS_ON,
  261. MYSQL_OPTION_MULTI_STATEMENTS_OFF
  262. };
  263. enum enum_session_state_type
  264. {
  265. SESSION_TRACK_SYSTEM_VARIABLES= 0,
  266. SESSION_TRACK_SCHEMA,
  267. SESSION_TRACK_STATE_CHANGE,
  268. /* currently not supported by MariaDB Server */
  269. SESSION_TRACK_GTIDS,
  270. SESSION_TRACK_TRANSACTION_CHARACTERISTICS,
  271. SESSION_TRACK_TRANSACTION_TYPE /* make sure that SESSION_TRACK_END always points
  272. to last element of enum !! */
  273. };
  274. #define SESSION_TRACK_BEGIN 0
  275. #define SESSION_TRACK_END SESSION_TRACK_TRANSACTION_TYPE
  276. #define SESSION_TRACK_TYPES SESSION_TRACK_END + 1
  277. enum enum_field_types { MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY,
  278. MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG,
  279. MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE,
  280. MYSQL_TYPE_NULL, MYSQL_TYPE_TIMESTAMP,
  281. MYSQL_TYPE_LONGLONG,MYSQL_TYPE_INT24,
  282. MYSQL_TYPE_DATE, MYSQL_TYPE_TIME,
  283. MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR,
  284. MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
  285. MYSQL_TYPE_BIT,
  286. /*
  287. the following types are not used by client,
  288. only for mysqlbinlog!!
  289. */
  290. MYSQL_TYPE_TIMESTAMP2,
  291. MYSQL_TYPE_DATETIME2,
  292. MYSQL_TYPE_TIME2,
  293. /* --------------------------------------------- */
  294. MYSQL_TYPE_JSON=245,
  295. MYSQL_TYPE_NEWDECIMAL=246,
  296. MYSQL_TYPE_ENUM=247,
  297. MYSQL_TYPE_SET=248,
  298. MYSQL_TYPE_TINY_BLOB=249,
  299. MYSQL_TYPE_MEDIUM_BLOB=250,
  300. MYSQL_TYPE_LONG_BLOB=251,
  301. MYSQL_TYPE_BLOB=252,
  302. MYSQL_TYPE_VAR_STRING=253,
  303. MYSQL_TYPE_STRING=254,
  304. MYSQL_TYPE_GEOMETRY=255,
  305. MAX_NO_FIELD_TYPES };
  306. #define FIELD_TYPE_CHAR FIELD_TYPE_TINY /* For compability */
  307. #define FIELD_TYPE_INTERVAL FIELD_TYPE_ENUM /* For compability */
  308. #define FIELD_TYPE_DECIMAL MYSQL_TYPE_DECIMAL
  309. #define FIELD_TYPE_NEWDECIMAL MYSQL_TYPE_NEWDECIMAL
  310. #define FIELD_TYPE_TINY MYSQL_TYPE_TINY
  311. #define FIELD_TYPE_SHORT MYSQL_TYPE_SHORT
  312. #define FIELD_TYPE_LONG MYSQL_TYPE_LONG
  313. #define FIELD_TYPE_FLOAT MYSQL_TYPE_FLOAT
  314. #define FIELD_TYPE_DOUBLE MYSQL_TYPE_DOUBLE
  315. #define FIELD_TYPE_NULL MYSQL_TYPE_NULL
  316. #define FIELD_TYPE_TIMESTAMP MYSQL_TYPE_TIMESTAMP
  317. #define FIELD_TYPE_LONGLONG MYSQL_TYPE_LONGLONG
  318. #define FIELD_TYPE_INT24 MYSQL_TYPE_INT24
  319. #define FIELD_TYPE_DATE MYSQL_TYPE_DATE
  320. #define FIELD_TYPE_TIME MYSQL_TYPE_TIME
  321. #define FIELD_TYPE_DATETIME MYSQL_TYPE_DATETIME
  322. #define FIELD_TYPE_YEAR MYSQL_TYPE_YEAR
  323. #define FIELD_TYPE_NEWDATE MYSQL_TYPE_NEWDATE
  324. #define FIELD_TYPE_ENUM MYSQL_TYPE_ENUM
  325. #define FIELD_TYPE_SET MYSQL_TYPE_SET
  326. #define FIELD_TYPE_TINY_BLOB MYSQL_TYPE_TINY_BLOB
  327. #define FIELD_TYPE_MEDIUM_BLOB MYSQL_TYPE_MEDIUM_BLOB
  328. #define FIELD_TYPE_LONG_BLOB MYSQL_TYPE_LONG_BLOB
  329. #define FIELD_TYPE_BLOB MYSQL_TYPE_BLOB
  330. #define FIELD_TYPE_VAR_STRING MYSQL_TYPE_VAR_STRING
  331. #define FIELD_TYPE_STRING MYSQL_TYPE_STRING
  332. #define FIELD_TYPE_GEOMETRY MYSQL_TYPE_GEOMETRY
  333. #define FIELD_TYPE_BIT MYSQL_TYPE_BIT
  334. extern unsigned long max_allowed_packet;
  335. extern unsigned long net_buffer_length;
  336. #define net_new_transaction(net) ((net)->pkt_nr=0)
  337. int ma_net_init(NET *net, MARIADB_PVIO *pvio);
  338. void ma_net_end(NET *net);
  339. void ma_net_clear(NET *net);
  340. int ma_net_flush(NET *net);
  341. int ma_net_write(NET *net,const unsigned char *packet, size_t len);
  342. int ma_net_write_command(NET *net,unsigned char command,const char *packet,
  343. size_t len, my_bool disable_flush);
  344. int ma_net_real_write(NET *net,const char *packet, size_t len);
  345. extern unsigned long ma_net_read(NET *net);
  346. struct rand_struct {
  347. unsigned long seed1,seed2,max_value;
  348. double max_value_dbl;
  349. };
  350. /* The following is for user defined functions */
  351. enum Item_result {STRING_RESULT,REAL_RESULT,INT_RESULT,ROW_RESULT,DECIMAL_RESULT};
  352. typedef struct st_udf_args
  353. {
  354. unsigned int arg_count; /* Number of arguments */
  355. enum Item_result *arg_type; /* Pointer to item_results */
  356. char **args; /* Pointer to argument */
  357. unsigned long *lengths; /* Length of string arguments */
  358. char *maybe_null; /* Set to 1 for all maybe_null args */
  359. } UDF_ARGS;
  360. /* This holds information about the result */
  361. typedef struct st_udf_init
  362. {
  363. my_bool maybe_null; /* 1 if function can return NULL */
  364. unsigned int decimals; /* for real functions */
  365. unsigned int max_length; /* For string functions */
  366. char *ptr; /* free pointer for function data */
  367. my_bool const_item; /* 0 if result is independent of arguments */
  368. } UDF_INIT;
  369. /* Connection types */
  370. #define MARIADB_CONNECTION_UNIXSOCKET 0
  371. #define MARIADB_CONNECTION_TCP 1
  372. #define MARIADB_CONNECTION_NAMEDPIPE 2
  373. #define MARIADB_CONNECTION_SHAREDMEM 3
  374. /* Constants when using compression */
  375. #define NET_HEADER_SIZE 4 /* standard header size */
  376. #define COMP_HEADER_SIZE 3 /* compression header extra size */
  377. /* Prototypes to password functions */
  378. #define native_password_plugin_name "mysql_native_password"
  379. #define old_password_plugin_name "mysql_old_password"
  380. #ifdef __cplusplus
  381. extern "C" {
  382. #endif
  383. char *ma_scramble_323(char *to,const char *message,const char *password);
  384. void ma_scramble_41(const unsigned char *buffer, const char *scramble, const char *password);
  385. void ma_hash_password(unsigned long *result, const char *password, size_t len);
  386. void ma_make_scrambled_password(char *to,const char *password);
  387. /* Some other useful functions */
  388. void mariadb_load_defaults(const char *conf_file, const char **groups,
  389. int *argc, char ***argv);
  390. my_bool ma_thread_init(void);
  391. void ma_thread_end(void);
  392. #ifdef __cplusplus
  393. }
  394. #endif
  395. #define NULL_LENGTH ((unsigned long) ~0) /* For net_store_length */
  396. #endif