Eneboo - Documentación para desarrolladores
|
00001 /* Copyright (C) 2000 MySQL AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 /* This file includes constants used with all databases */ 00018 /* Author: Michael Widenius */ 00019 00020 #ifndef _my_base_h 00021 #define _my_base_h 00022 00023 #ifndef stdin /* Included first in handler */ 00024 #define USES_TYPES /* my_dir with sys/types is included */ 00025 #define CHSIZE_USED 00026 #include <my_global.h> 00027 #include <my_dir.h> /* This includes types */ 00028 #include <my_sys.h> 00029 #include <m_string.h> 00030 #include <errno.h> 00031 00032 #ifndef EOVERFLOW 00033 #define EOVERFLOW 84 00034 #endif 00035 00036 #ifdef MSDOS 00037 #include <share.h> /* Neaded for sopen() */ 00038 #endif 00039 #if !defined(USE_MY_FUNC) && !defined(THREAD) 00040 #include <my_nosys.h> /* For faster code, after test */ 00041 #endif /* USE_MY_FUNC */ 00042 #endif /* stdin */ 00043 #include <my_list.h> 00044 00045 /* The following is bits in the flag parameter to ha_open() */ 00046 00047 #define HA_OPEN_ABORT_IF_LOCKED 0 /* default */ 00048 #define HA_OPEN_WAIT_IF_LOCKED 1 00049 #define HA_OPEN_IGNORE_IF_LOCKED 2 00050 #define HA_OPEN_TMP_TABLE 4 /* Table is a temp table */ 00051 #define HA_OPEN_DELAY_KEY_WRITE 8 /* Don't update index */ 00052 #define HA_OPEN_ABORT_IF_CRASHED 16 00053 #define HA_OPEN_FOR_REPAIR 32 /* open even if crashed */ 00054 00055 /* The following is parameter to ha_rkey() how to use key */ 00056 00057 /* 00058 We define a complete-field prefix of a key value as a prefix where 00059 the last included field in the prefix contains the full field, not 00060 just some bytes from the start of the field. A partial-field prefix 00061 is allowed to contain only a few first bytes from the last included 00062 field. 00063 00064 Below HA_READ_KEY_EXACT, ..., HA_READ_BEFORE_KEY can take a 00065 complete-field prefix of a key value as the search 00066 key. HA_READ_PREFIX and HA_READ_PREFIX_LAST could also take a 00067 partial-field prefix, but currently (4.0.10) they are only used with 00068 complete-field prefixes. MySQL uses a padding trick to implement 00069 LIKE 'abc%' queries. 00070 00071 NOTE that in InnoDB HA_READ_PREFIX_LAST will NOT work with a 00072 partial-field prefix because InnoDB currently strips spaces from the 00073 end of varchar fields! 00074 */ 00075 00076 enum ha_rkey_function { 00077 HA_READ_KEY_EXACT, /* Find first record else error */ 00078 HA_READ_KEY_OR_NEXT, /* Record or next record */ 00079 HA_READ_KEY_OR_PREV, /* Record or previous */ 00080 HA_READ_AFTER_KEY, /* Find next rec. after key-record */ 00081 HA_READ_BEFORE_KEY, /* Find next rec. before key-record */ 00082 HA_READ_PREFIX, /* Key which as same prefix */ 00083 HA_READ_PREFIX_LAST, /* Last key with the same prefix */ 00084 HA_READ_PREFIX_LAST_OR_PREV, /* Last or prev key with the same prefix */ 00085 HA_READ_MBR_CONTAIN, 00086 HA_READ_MBR_INTERSECT, 00087 HA_READ_MBR_WITHIN, 00088 HA_READ_MBR_DISJOINT, 00089 HA_READ_MBR_EQUAL 00090 }; 00091 00092 /* Key algorithm types */ 00093 00094 enum ha_key_alg { 00095 HA_KEY_ALG_UNDEF= 0, /* Not specified (old file) */ 00096 HA_KEY_ALG_BTREE= 1, /* B-tree, default one */ 00097 HA_KEY_ALG_RTREE= 2, /* R-tree, for spatial searches */ 00098 HA_KEY_ALG_HASH= 3, /* HASH keys (HEAP tables) */ 00099 HA_KEY_ALG_FULLTEXT= 4 /* FULLTEXT (MyISAM tables) */ 00100 }; 00101 00102 /* The following is parameter to ha_extra() */ 00103 00104 enum ha_extra_function { 00105 HA_EXTRA_NORMAL=0, /* Optimize for space (def) */ 00106 HA_EXTRA_QUICK=1, /* Optimize for speed */ 00107 HA_EXTRA_RESET=2, /* Reset database to after open */ 00108 HA_EXTRA_CACHE=3, /* Cache record in HA_rrnd() */ 00109 HA_EXTRA_NO_CACHE=4, /* End caching of records (def) */ 00110 HA_EXTRA_NO_READCHECK=5, /* No readcheck on update */ 00111 HA_EXTRA_READCHECK=6, /* Use readcheck (def) */ 00112 HA_EXTRA_KEYREAD=7, /* Read only key to database */ 00113 HA_EXTRA_NO_KEYREAD=8, /* Normal read of records (def) */ 00114 HA_EXTRA_NO_USER_CHANGE=9, /* No user is allowed to write */ 00115 HA_EXTRA_KEY_CACHE=10, 00116 HA_EXTRA_NO_KEY_CACHE=11, 00117 HA_EXTRA_WAIT_LOCK=12, /* Wait until file is avalably (def) */ 00118 HA_EXTRA_NO_WAIT_LOCK=13, /* If file is locked, return quickly */ 00119 HA_EXTRA_WRITE_CACHE=14, /* Use write cache in ha_write() */ 00120 HA_EXTRA_FLUSH_CACHE=15, /* flush write_record_cache */ 00121 HA_EXTRA_NO_KEYS=16, /* Remove all update of keys */ 00122 HA_EXTRA_KEYREAD_CHANGE_POS=17, /* Keyread, but change pos */ 00123 /* xxxxchk -r must be used */ 00124 HA_EXTRA_REMEMBER_POS=18, /* Remember pos for next/prev */ 00125 HA_EXTRA_RESTORE_POS=19, 00126 HA_EXTRA_REINIT_CACHE=20, /* init cache from current record */ 00127 HA_EXTRA_FORCE_REOPEN=21, /* Datafile have changed on disk */ 00128 HA_EXTRA_FLUSH, /* Flush tables to disk */ 00129 HA_EXTRA_NO_ROWS, /* Don't write rows */ 00130 HA_EXTRA_RESET_STATE, /* Reset positions */ 00131 HA_EXTRA_IGNORE_DUP_KEY, /* Dup keys don't rollback everything*/ 00132 HA_EXTRA_NO_IGNORE_DUP_KEY, 00133 /* 00134 Instructs InnoDB to retrieve all columns (except in key read), not just 00135 those where field->query_id is the same as the current query id 00136 */ 00137 HA_EXTRA_RETRIEVE_ALL_COLS, 00138 /* 00139 Instructs InnoDB to retrieve at least all the primary key columns 00140 */ 00141 HA_EXTRA_RETRIEVE_PRIMARY_KEY, 00142 HA_EXTRA_PREPARE_FOR_DELETE, 00143 HA_EXTRA_PREPARE_FOR_UPDATE, /* Remove read cache if problems */ 00144 HA_EXTRA_PRELOAD_BUFFER_SIZE, /* Set buffer size for preloading */ 00145 /* 00146 On-the-fly switching between unique and non-unique key inserting. 00147 */ 00148 HA_EXTRA_CHANGE_KEY_TO_UNIQUE, 00149 HA_EXTRA_CHANGE_KEY_TO_DUP 00150 }; 00151 00152 /* The following is parameter to ha_panic() */ 00153 00154 enum ha_panic_function { 00155 HA_PANIC_CLOSE, /* Close all databases */ 00156 HA_PANIC_WRITE, /* Unlock and write status */ 00157 HA_PANIC_READ /* Lock and read keyinfo */ 00158 }; 00159 00160 /* The following is parameter to ha_create(); keytypes */ 00161 00162 enum ha_base_keytype { 00163 HA_KEYTYPE_END=0, 00164 HA_KEYTYPE_TEXT=1, /* Key is sorted as letters */ 00165 HA_KEYTYPE_BINARY=2, /* Key is sorted as unsigned chars */ 00166 HA_KEYTYPE_SHORT_INT=3, 00167 HA_KEYTYPE_LONG_INT=4, 00168 HA_KEYTYPE_FLOAT=5, 00169 HA_KEYTYPE_DOUBLE=6, 00170 HA_KEYTYPE_NUM=7, /* Not packed num with pre-space */ 00171 HA_KEYTYPE_USHORT_INT=8, 00172 HA_KEYTYPE_ULONG_INT=9, 00173 HA_KEYTYPE_LONGLONG=10, 00174 HA_KEYTYPE_ULONGLONG=11, 00175 HA_KEYTYPE_INT24=12, 00176 HA_KEYTYPE_UINT24=13, 00177 HA_KEYTYPE_INT8=14, 00178 HA_KEYTYPE_VARTEXT=15, /* Key is sorted as letters */ 00179 HA_KEYTYPE_VARBINARY=16 /* Key is sorted as unsigned chars */ 00180 }; 00181 00182 #define HA_MAX_KEYTYPE 31 /* Must be log2-1 */ 00183 00184 /* These flags kan be OR:ed to key-flag */ 00185 00186 #define HA_NOSAME 1 /* Set if not dupplicated records */ 00187 #define HA_PACK_KEY 2 /* Pack string key to previous key */ 00188 #define HA_AUTO_KEY 16 00189 #define HA_BINARY_PACK_KEY 32 /* Packing of all keys to prev key */ 00190 #define HA_FULLTEXT 128 /* For full-text search */ 00191 #define HA_UNIQUE_CHECK 256 /* Check the key for uniqueness */ 00192 #define HA_SPATIAL 1024 /* For spatial search */ 00193 #define HA_NULL_ARE_EQUAL 2048 /* NULL in key are cmp as equal */ 00194 #define HA_GENERATED_KEY 8192 /* Automaticly generated key */ 00195 00196 /* Automatic bits in key-flag */ 00197 00198 #define HA_SPACE_PACK_USED 4 /* Test for if SPACE_PACK used */ 00199 #define HA_VAR_LENGTH_KEY 8 00200 #define HA_NULL_PART_KEY 64 00201 #ifndef ISAM_LIBRARY 00202 #define HA_SORT_ALLOWS_SAME 512 /* Intern bit when sorting records */ 00203 #else 00204 /* poor old NISAM has 8-bit flags :-( */ 00205 #define HA_SORT_ALLOWS_SAME 128 /* Intern bit when sorting records */ 00206 #endif 00207 /* 00208 Key has a part that can have end space. If this is an unique key 00209 we have to handle it differently from other unique keys as we can find 00210 many matching rows for one key (becaue end space are not compared) 00211 */ 00212 #define HA_END_SPACE_KEY 4096 00213 00214 /* These flags can be added to key-seg-flag */ 00215 00216 #define HA_SPACE_PACK 1 /* Pack space in key-seg */ 00217 #define HA_PART_KEY_SEG 4 /* Used by MySQL for part-key-cols */ 00218 #define HA_VAR_LENGTH 8 00219 #define HA_NULL_PART 16 00220 #define HA_BLOB_PART 32 00221 #define HA_SWAP_KEY 64 00222 #define HA_REVERSE_SORT 128 /* Sort key in reverse order */ 00223 #define HA_NO_SORT 256 /* do not bother sorting on this keyseg */ 00224 00225 /* optionbits for database */ 00226 #define HA_OPTION_PACK_RECORD 1 00227 #define HA_OPTION_PACK_KEYS 2 00228 #define HA_OPTION_COMPRESS_RECORD 4 00229 #define HA_OPTION_LONG_BLOB_PTR 8 /* new ISAM format */ 00230 #define HA_OPTION_TMP_TABLE 16 00231 #define HA_OPTION_CHECKSUM 32 00232 #define HA_OPTION_DELAY_KEY_WRITE 64 00233 #define HA_OPTION_NO_PACK_KEYS 128 /* Reserved for MySQL */ 00234 #define HA_OPTION_TEMP_COMPRESS_RECORD ((uint) 16384) /* set by isamchk */ 00235 #define HA_OPTION_READ_ONLY_DATA ((uint) 32768) /* Set by isamchk */ 00236 00237 /* Bits in flag to create() */ 00238 00239 #define HA_DONT_TOUCH_DATA 1 /* Don't empty datafile (isamchk) */ 00240 #define HA_PACK_RECORD 2 /* Request packed record format */ 00241 #define HA_CREATE_TMP_TABLE 4 00242 #define HA_CREATE_CHECKSUM 8 00243 #define HA_CREATE_DELAY_KEY_WRITE 64 00244 #define HA_CREATE_FROM_ENGINE 128 00245 00246 /* Bits in flag to _status */ 00247 00248 #define HA_STATUS_POS 1 /* Return position */ 00249 #define HA_STATUS_NO_LOCK 2 /* Don't use external lock */ 00250 #define HA_STATUS_TIME 4 /* Return update time */ 00251 #define HA_STATUS_CONST 8 /* Return constants values */ 00252 #define HA_STATUS_VARIABLE 16 00253 #define HA_STATUS_ERRKEY 32 00254 #define HA_STATUS_AUTO 64 00255 00256 /* Errorcodes given by functions */ 00257 00258 /* opt_sum_query() assumes these codes are > 1 */ 00259 #define HA_ERR_KEY_NOT_FOUND 120 /* Didn't find key on read or update */ 00260 #define HA_ERR_FOUND_DUPP_KEY 121 /* Dupplicate key on write */ 00261 #define HA_ERR_RECORD_CHANGED 123 /* Uppdate with is recoverable */ 00262 #define HA_ERR_WRONG_INDEX 124 /* Wrong index given to function */ 00263 #define HA_ERR_CRASHED 126 /* Indexfile is crashed */ 00264 #define HA_ERR_WRONG_IN_RECORD 127 /* Record-file is crashed */ 00265 #define HA_ERR_OUT_OF_MEM 128 /* Record-file is crashed */ 00266 #define HA_ERR_NOT_A_TABLE 130 /* not a MYI file - no signature */ 00267 #define HA_ERR_WRONG_COMMAND 131 /* Command not supported */ 00268 #define HA_ERR_OLD_FILE 132 /* old databasfile */ 00269 #define HA_ERR_NO_ACTIVE_RECORD 133 /* No record read in update() */ 00270 #define HA_ERR_RECORD_DELETED 134 /* Intern error-code */ 00271 #define HA_ERR_RECORD_FILE_FULL 135 /* No more room in file */ 00272 #define HA_ERR_INDEX_FILE_FULL 136 /* No more room in file */ 00273 #define HA_ERR_END_OF_FILE 137 /* end in next/prev/first/last */ 00274 #define HA_ERR_UNSUPPORTED 138 /* unsupported extension used */ 00275 #define HA_ERR_TO_BIG_ROW 139 /* Too big row */ 00276 #define HA_WRONG_CREATE_OPTION 140 /* Wrong create option */ 00277 #define HA_ERR_FOUND_DUPP_UNIQUE 141 /* Dupplicate unique on write */ 00278 #define HA_ERR_UNKNOWN_CHARSET 142 /* Can't open charset */ 00279 #define HA_ERR_WRONG_MRG_TABLE_DEF 143 /* conflicting MyISAM tables in MERGE */ 00280 #define HA_ERR_CRASHED_ON_REPAIR 144 /* Last (automatic?) repair failed */ 00281 #define HA_ERR_CRASHED_ON_USAGE 145 /* Table must be repaired */ 00282 #define HA_ERR_LOCK_WAIT_TIMEOUT 146 00283 #define HA_ERR_LOCK_TABLE_FULL 147 00284 #define HA_ERR_READ_ONLY_TRANSACTION 148 /* Updates not allowed */ 00285 #define HA_ERR_LOCK_DEADLOCK 149 00286 #define HA_ERR_CANNOT_ADD_FOREIGN 150 /* Cannot add a foreign key constr. */ 00287 #define HA_ERR_NO_REFERENCED_ROW 151 /* Cannot add a child row */ 00288 #define HA_ERR_ROW_IS_REFERENCED 152 /* Cannot delete a parent row */ 00289 #define HA_ERR_NO_SAVEPOINT 153 /* No savepoint with that name */ 00290 #define HA_ERR_NON_UNIQUE_BLOCK_SIZE 154 /* Non unique key block size */ 00291 #define HA_ERR_NO_SUCH_TABLE 155 /* The table does not exist in engine */ 00292 #define HA_ERR_TABLE_EXIST 156 /* The table existed in storage engine */ 00293 #define HA_ERR_NO_CONNECTION 157 /* Could not connect to storage engine */ 00294 #define HA_ERR_NULL_IN_SPATIAL 158 /* NULLs are not supported in spatial index */ 00295 00296 /* Other constants */ 00297 00298 #define HA_NAMELEN 64 /* Max length of saved filename */ 00299 #define NO_SUCH_KEY ((uint)~0) /* used as a key no. */ 00300 00301 /* Intern constants in databases */ 00302 00303 /* bits in _search */ 00304 #define SEARCH_FIND 1 00305 #define SEARCH_NO_FIND 2 00306 #define SEARCH_SAME 4 00307 #define SEARCH_BIGGER 8 00308 #define SEARCH_SMALLER 16 00309 #define SEARCH_SAVE_BUFF 32 00310 #define SEARCH_UPDATE 64 00311 #define SEARCH_PREFIX 128 00312 #define SEARCH_LAST 256 00313 #define MBR_CONTAIN 512 00314 #define MBR_INTERSECT 1024 00315 #define MBR_WITHIN 2048 00316 #define MBR_DISJOINT 4096 00317 #define MBR_EQUAL 8192 00318 #define MBR_DATA 16384 00319 #define SEARCH_NULL_ARE_EQUAL 32768 /* NULL in keys are equal */ 00320 #define SEARCH_NULL_ARE_NOT_EQUAL 65536 /* NULL in keys are not equal */ 00321 00322 /* bits in opt_flag */ 00323 #define QUICK_USED 1 00324 #define READ_CACHE_USED 2 00325 #define READ_CHECK_USED 4 00326 #define KEY_READ_USED 8 00327 #define WRITE_CACHE_USED 16 00328 #define OPT_NO_ROWS 32 00329 00330 /* bits in update */ 00331 #define HA_STATE_CHANGED 1 /* Database has changed */ 00332 #define HA_STATE_AKTIV 2 /* Has a current record */ 00333 #define HA_STATE_WRITTEN 4 /* Record is written */ 00334 #define HA_STATE_DELETED 8 00335 #define HA_STATE_NEXT_FOUND 16 /* Next found record (record before) */ 00336 #define HA_STATE_PREV_FOUND 32 /* Prev found record (record after) */ 00337 #define HA_STATE_NO_KEY 64 /* Last read didn't find record */ 00338 #define HA_STATE_KEY_CHANGED 128 00339 #define HA_STATE_WRITE_AT_END 256 /* set in _ps_find_writepos */ 00340 #define HA_STATE_BUFF_SAVED 512 /* If current keybuff is info->buff */ 00341 #define HA_STATE_ROW_CHANGED 1024 /* To invalide ROW cache */ 00342 #define HA_STATE_EXTEND_BLOCK 2048 00343 #define HA_STATE_RNEXT_SAME 4096 /* rnext_same was called */ 00344 00345 enum en_fieldtype { 00346 FIELD_LAST=-1,FIELD_NORMAL,FIELD_SKIP_ENDSPACE,FIELD_SKIP_PRESPACE, 00347 FIELD_SKIP_ZERO,FIELD_BLOB,FIELD_CONSTANT,FIELD_INTERVALL,FIELD_ZERO, 00348 FIELD_VARCHAR,FIELD_CHECK 00349 }; 00350 00351 enum data_file_type { 00352 STATIC_RECORD,DYNAMIC_RECORD,COMPRESSED_RECORD 00353 }; 00354 00355 /* For key ranges */ 00356 00357 typedef struct st_key_range 00358 { 00359 const byte *key; 00360 uint length; 00361 enum ha_rkey_function flag; 00362 } key_range; 00363 00364 00365 /* For number of records */ 00366 #ifdef BIG_TABLES 00367 #define rows2double(A) ulonglong2double(A) 00368 typedef my_off_t ha_rows; 00369 #else 00370 #define rows2double(A) (double) (A) 00371 typedef ulong ha_rows; 00372 #endif 00373 00374 #define HA_POS_ERROR (~ (ha_rows) 0) 00375 #define HA_OFFSET_ERROR (~ (my_off_t) 0) 00376 00377 #if SYSTEM_SIZEOF_OFF_T == 4 00378 #define MAX_FILE_SIZE INT_MAX32 00379 #else 00380 #define MAX_FILE_SIZE LONGLONG_MAX 00381 #endif 00382 00383 #endif /* _my_base_h */