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