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