mORMot and Open Source friends
Check-in [1865cf8a0b]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
SHA1 Hash:1865cf8a0b78397c4ba759fee8be1c37356e237a
Date: 2012-01-18 13:05:57
User: G018869
Comment:updated SQLite3 engine to version 3.7.10
Tags And Properties
Changes
hide diffs unified diffs patch

Changes to SQLite3/SQLite3.pas

179 - now TSQLRestServerDB will unregister any TSQLVirtualTableModuleServerDB 179 - now TSQLRestServerDB will unregister any TSQLVirtualTableModuleServerDB 180 to avoid random GPF in TSQLVirtualTable.Destroy 180 to avoid random GPF in TSQLVirtualTable.Destroy 181 - TSQLRestClientDB and TSQLRestServerDB constructors now accept an optional 181 - TSQLRestClientDB and TSQLRestServerDB constructors now accept an optional 182 Password parameter, associated to the supplied file name, in order to 182 Password parameter, associated to the supplied file name, in order to 183 use database encryption 183 use database encryption 184 184 185 Version 1.16 185 Version 1.16 186 - updated SQLite3 engine to version 3.7.9 | 186 - updated SQLite3 engine to version 3.7.10 187 - fixed TSQLRestServerDB.UpdateField(ByID=true) implementation 187 - fixed TSQLRestServerDB.UpdateField(ByID=true) implementation 188 - new overloaded TSQLRestServerDB.UpdateField method 188 - new overloaded TSQLRestServerDB.UpdateField method 189 - TSQLRestServerDB.EngineList() method now handles an optional integer 189 - TSQLRestServerDB.EngineList() method now handles an optional integer 190 pointer, to return the count of row data 190 pointer, to return the count of row data 191 - the TSQLRestServerCallBack method prototype has been modified to supply 191 - the TSQLRestServerCallBack method prototype has been modified to supply 192 an addition aSession: cardinal parameter: this is a CODE BREAK change and 192 an addition aSession: cardinal parameter: this is a CODE BREAK change and 193 you shall refresh ALL your server-side code to match the new signature 193 you shall refresh ALL your server-side code to match the new signature

Changes to SQLite3/sqlite3.c

25 #define SQLITE_OMIT_PROGRESS_CALLBACK 1 25 #define SQLITE_OMIT_PROGRESS_CALLBACK 1 26 // we don't need sqlite3_progress_handler() API function 26 // we don't need sqlite3_progress_handler() API function 27 #define SQLITE_ENABLE_RTREE 1 27 #define SQLITE_ENABLE_RTREE 1 28 // the RTREE extension is now (from v.1.8/3.7) compiled into the engine 28 // the RTREE extension is now (from v.1.8/3.7) compiled into the engine 29 //#define SQLITE_OMIT_LOOKASIDE 29 //#define SQLITE_OMIT_LOOKASIDE 30 // since we use FastMM4, LookAside is not needed but seems mandatory in c source 30 // since we use FastMM4, LookAside is not needed but seems mandatory in c source 31 31 32 < 33 /****************************************************************************** 32 /****************************************************************************** 34 ** This file is an amalgamation of many separate C source files from SQLite 33 ** This file is an amalgamation of many separate C source files from SQLite 35 ** version 3.7.9. By combining all the individual C code files into this | 34 ** version 3.7.10. By combining all the individual C code files into this 36 ** single large file, the entire code can be compiled as a single translation 35 ** single large file, the entire code can be compiled as a single translation 37 ** unit. This allows many compilers to do optimizations that would not be 36 ** unit. This allows many compilers to do optimizations that would not be 38 ** possible if the files were compiled separately. Performance improvements 37 ** possible if the files were compiled separately. Performance improvements 39 ** of 5% or more are commonly seen when SQLite is compiled as a single 38 ** of 5% or more are commonly seen when SQLite is compiled as a single 40 ** translation unit. 39 ** translation unit. 41 ** 40 ** 42 ** This file is all you need to compile SQLite. To use SQLite in other 41 ** This file is all you need to compile SQLite. To use SQLite in other ................................................................................................................................................................................ 393 #if defined(THREADSAFE) 392 #if defined(THREADSAFE) 394 # define SQLITE_THREADSAFE THREADSAFE 393 # define SQLITE_THREADSAFE THREADSAFE 395 #else 394 #else 396 # define SQLITE_THREADSAFE 1 /* IMP: R-07272-22309 */ 395 # define SQLITE_THREADSAFE 1 /* IMP: R-07272-22309 */ 397 #endif 396 #endif 398 #endif 397 #endif 399 398 > 399 /* > 400 ** Powersafe overwrite is on by default. But can be turned off using > 401 ** the -DSQLITE_POWERSAFE_OVERWRITE=0 command-line option. > 402 */ > 403 #ifndef SQLITE_POWERSAFE_OVERWRITE > 404 # define SQLITE_POWERSAFE_OVERWRITE 1 > 405 #endif > 406 400 /* 407 /* 401 ** The SQLITE_DEFAULT_MEMSTATUS macro must be defined as either 0 or 1. 408 ** The SQLITE_DEFAULT_MEMSTATUS macro must be defined as either 0 or 1. 402 ** It determines whether or not the features related to 409 ** It determines whether or not the features related to 403 ** SQLITE_CONFIG_MEMSTATUS are available by default or not. This value can 410 ** SQLITE_CONFIG_MEMSTATUS are available by default or not. This value can 404 ** be overridden at runtime using the sqlite3_config() API. 411 ** be overridden at runtime using the sqlite3_config() API. 405 */ 412 */ 406 #if !defined(SQLITE_DEFAULT_MEMSTATUS) 413 #if !defined(SQLITE_DEFAULT_MEMSTATUS) ................................................................................................................................................................................ 677 ** string contains the date and time of the check-in (UTC) and an SHA1 684 ** string contains the date and time of the check-in (UTC) and an SHA1 678 ** hash of the entire source tree. 685 ** hash of the entire source tree. 679 ** 686 ** 680 ** See also: [sqlite3_libversion()], 687 ** See also: [sqlite3_libversion()], 681 ** [sqlite3_libversion_number()], [sqlite3_sourceid()], 688 ** [sqlite3_libversion_number()], [sqlite3_sourceid()], 682 ** [sqlite_version()] and [sqlite_source_id()]. 689 ** [sqlite_version()] and [sqlite_source_id()]. 683 */ 690 */ 684 #define SQLITE_VERSION "3.7.9" | 691 #define SQLITE_VERSION "3.7.10" 685 #define SQLITE_VERSION_NUMBER 3007009 | 692 #define SQLITE_VERSION_NUMBER 3007010 686 #define SQLITE_SOURCE_ID "2011-11-01 00:52:41 c7c6050ef060877ebe77b41d959e9 | 693 #define SQLITE_SOURCE_ID "2012-01-16 13:28:40 ebd01a8deffb5024a5d7494eef800 687 694 688 /* 695 /* 689 ** CAPI3REF: Run-Time Library Version Numbers 696 ** CAPI3REF: Run-Time Library Version Numbers 690 ** KEYWORDS: sqlite3_version, sqlite3_sourceid 697 ** KEYWORDS: sqlite3_version, sqlite3_sourceid 691 ** 698 ** 692 ** These interfaces provide the same information as the [SQLITE_VERSION], 699 ** These interfaces provide the same information as the [SQLITE_VERSION], 693 ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros 700 ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros ................................................................................................................................................................................ 747 SQLITE_API const char *sqlite3_compileoption_get(int N); 754 SQLITE_API const char *sqlite3_compileoption_get(int N); 748 #endif 755 #endif 749 756 750 /* 757 /* 751 ** CAPI3REF: Test To See If The Library Is Threadsafe 758 ** CAPI3REF: Test To See If The Library Is Threadsafe 752 ** 759 ** 753 ** ^The sqlite3_threadsafe() function returns zero if and only if 760 ** ^The sqlite3_threadsafe() function returns zero if and only if 754 ** SQLite was compiled mutexing code omitted due to the | 761 ** SQLite was compiled with mutexing code omitted due to the 755 ** [SQLITE_THREADSAFE] compile-time option being set to 0. 762 ** [SQLITE_THREADSAFE] compile-time option being set to 0. 756 ** 763 ** 757 ** SQLite can be compiled with or without mutexes. When 764 ** SQLite can be compiled with or without mutexes. When 758 ** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes 765 ** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes 759 ** are enabled and SQLite is threadsafe. When the 766 ** are enabled and SQLite is threadsafe. When the 760 ** [SQLITE_THREADSAFE] macro is 0, 767 ** [SQLITE_THREADSAFE] macro is 0, 761 ** the mutexes are omitted. Without the mutexes, it is not safe 768 ** the mutexes are omitted. Without the mutexes, it is not safe ................................................................................................................................................................................ 941 948 942 /* 949 /* 943 ** CAPI3REF: Result Codes 950 ** CAPI3REF: Result Codes 944 ** KEYWORDS: SQLITE_OK {error code} {error codes} 951 ** KEYWORDS: SQLITE_OK {error code} {error codes} 945 ** KEYWORDS: {result code} {result codes} 952 ** KEYWORDS: {result code} {result codes} 946 ** 953 ** 947 ** Many SQLite functions return an integer result code from the set shown 954 ** Many SQLite functions return an integer result code from the set shown 948 ** here in order to indicates success or failure. | 955 ** here in order to indicate success or failure. 949 ** 956 ** 950 ** New error codes may be added in future versions of SQLite. 957 ** New error codes may be added in future versions of SQLite. 951 ** 958 ** 952 ** See also: [SQLITE_IOERR_READ | extended result codes], 959 ** See also: [SQLITE_IOERR_READ | extended result codes], 953 ** [sqlite3_vtab_on_conflict()] [SQLITE_ROLLBACK | result codes]. 960 ** [sqlite3_vtab_on_conflict()] [SQLITE_ROLLBACK | result codes]. 954 */ 961 */ 955 #define SQLITE_OK 0 /* Successful result */ 962 #define SQLITE_OK 0 /* Successful result */ ................................................................................................................................................................................ 1079 ** mean that writes of blocks that are nnn bytes in size and 1086 ** mean that writes of blocks that are nnn bytes in size and 1080 ** are aligned to an address which is an integer multiple of 1087 ** are aligned to an address which is an integer multiple of 1081 ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means 1088 ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means 1082 ** that when data is appended to a file, the data is appended 1089 ** that when data is appended to a file, the data is appended 1083 ** first then the size of the file is extended, never the other 1090 ** first then the size of the file is extended, never the other 1084 ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that 1091 ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that 1085 ** information is written to disk in the same order as calls 1092 ** information is written to disk in the same order as calls 1086 ** to xWrite(). | 1093 ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that > 1094 ** after reboot following a crash or power loss, the only bytes in a > 1095 ** file that were written at the application level might have changed > 1096 ** and that adjacent bytes, even bytes within the same sector are > 1097 ** guaranteed to be unchanged. 1087 */ 1098 */ 1088 #define SQLITE_IOCAP_ATOMIC 0x00000001 1099 #define SQLITE_IOCAP_ATOMIC 0x00000001 1089 #define SQLITE_IOCAP_ATOMIC512 0x00000002 1100 #define SQLITE_IOCAP_ATOMIC512 0x00000002 1090 #define SQLITE_IOCAP_ATOMIC1K 0x00000004 1101 #define SQLITE_IOCAP_ATOMIC1K 0x00000004 1091 #define SQLITE_IOCAP_ATOMIC2K 0x00000008 1102 #define SQLITE_IOCAP_ATOMIC2K 0x00000008 1092 #define SQLITE_IOCAP_ATOMIC4K 0x00000010 1103 #define SQLITE_IOCAP_ATOMIC4K 0x00000010 1093 #define SQLITE_IOCAP_ATOMIC8K 0x00000020 1104 #define SQLITE_IOCAP_ATOMIC8K 0x00000020 1094 #define SQLITE_IOCAP_ATOMIC16K 0x00000040 1105 #define SQLITE_IOCAP_ATOMIC16K 0x00000040 1095 #define SQLITE_IOCAP_ATOMIC32K 0x00000080 1106 #define SQLITE_IOCAP_ATOMIC32K 0x00000080 1096 #define SQLITE_IOCAP_ATOMIC64K 0x00000100 1107 #define SQLITE_IOCAP_ATOMIC64K 0x00000100 1097 #define SQLITE_IOCAP_SAFE_APPEND 0x00000200 1108 #define SQLITE_IOCAP_SAFE_APPEND 0x00000200 1098 #define SQLITE_IOCAP_SEQUENTIAL 0x00000400 1109 #define SQLITE_IOCAP_SEQUENTIAL 0x00000400 1099 #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800 1110 #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800 > 1111 #define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000 1100 1112 1101 /* 1113 /* 1102 ** CAPI3REF: File Locking Levels 1114 ** CAPI3REF: File Locking Levels 1103 ** 1115 ** 1104 ** SQLite uses one of these integer values as the second 1116 ** SQLite uses one of these integer values as the second 1105 ** argument to calls it makes to the xLock() and xUnlock() methods 1117 ** argument to calls it makes to the xLock() and xUnlock() methods 1106 ** of an [sqlite3_io_methods] object. 1118 ** of an [sqlite3_io_methods] object. ................................................................................................................................................................................ 1314 ** VFSes do not need this signal and should silently ignore this opcode. 1326 ** VFSes do not need this signal and should silently ignore this opcode. 1315 ** Applications should not call [sqlite3_file_control()] with this 1327 ** Applications should not call [sqlite3_file_control()] with this 1316 ** opcode as doing so may disrupt the operation of the specialized VFSes 1328 ** opcode as doing so may disrupt the operation of the specialized VFSes 1317 ** that do require it. 1329 ** that do require it. 1318 ** 1330 ** 1319 ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic 1331 ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic 1320 ** retry counts and intervals for certain disk I/O operations for the 1332 ** retry counts and intervals for certain disk I/O operations for the 1321 ** windows [VFS] in order to work to provide robustness against | 1333 ** windows [VFS] in order to provide robustness in the presence of 1322 ** anti-virus programs. By default, the windows VFS will retry file read, 1334 ** anti-virus programs. By default, the windows VFS will retry file read, 1323 ** file write, and file delete operations up to 10 times, with a delay 1335 ** file write, and file delete operations up to 10 times, with a delay 1324 ** of 25 milliseconds before the first retry and with the delay increasing 1336 ** of 25 milliseconds before the first retry and with the delay increasing 1325 ** by an additional 25 milliseconds with each subsequent retry. This 1337 ** by an additional 25 milliseconds with each subsequent retry. This 1326 ** opcode allows those to values (10 retries and 25 milliseconds of delay) | 1338 ** opcode allows these two values (10 retries and 25 milliseconds of delay) 1327 ** to be adjusted. The values are changed for all database connections 1339 ** to be adjusted. The values are changed for all database connections 1328 ** within the same process. The argument is a pointer to an array of two 1340 ** within the same process. The argument is a pointer to an array of two 1329 ** integers where the first integer i the new retry count and the second 1341 ** integers where the first integer i the new retry count and the second 1330 ** integer is the delay. If either integer is negative, then the setting 1342 ** integer is the delay. If either integer is negative, then the setting 1331 ** is not changed but instead the prior value of that setting is written 1343 ** is not changed but instead the prior value of that setting is written 1332 ** into the array entry, allowing the current retry settings to be 1344 ** into the array entry, allowing the current retry settings to be 1333 ** interrogated. The zDbName parameter is ignored. 1345 ** interrogated. The zDbName parameter is ignored. ................................................................................................................................................................................ 1341 ** have write permission on the directory containing the database file want 1353 ** have write permission on the directory containing the database file want 1342 ** to read the database file, as the WAL and shared memory files must exist 1354 ** to read the database file, as the WAL and shared memory files must exist 1343 ** in order for the database to be readable. The fourth parameter to 1355 ** in order for the database to be readable. The fourth parameter to 1344 ** [sqlite3_file_control()] for this opcode should be a pointer to an integer. 1356 ** [sqlite3_file_control()] for this opcode should be a pointer to an integer. 1345 ** That integer is 0 to disable persistent WAL mode or 1 to enable persistent 1357 ** That integer is 0 to disable persistent WAL mode or 1 to enable persistent 1346 ** WAL mode. If the integer is -1, then it is overwritten with the current 1358 ** WAL mode. If the integer is -1, then it is overwritten with the current 1347 ** WAL persistence setting. 1359 ** WAL persistence setting. > 1360 ** > 1361 ** ^The [SQLITE_FCNTL_POWERSAFE_OVERWRITE] opcode is used to set or query the > 1362 ** persistent "powersafe-overwrite" or "PSOW" setting. The PSOW setting > 1363 ** determines the [SQLITE_IOCAP_POWERSAFE_OVERWRITE] bit of the > 1364 ** xDeviceCharacteristics methods. The fourth parameter to > 1365 ** [sqlite3_file_control()] for this opcode should be a pointer to an integer. > 1366 ** That integer is 0 to disable zero-damage mode or 1 to enable zero-damage > 1367 ** mode. If the integer is -1, then it is overwritten with the current > 1368 ** zero-damage mode setting. 1348 ** 1369 ** 1349 ** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening 1370 ** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening 1350 ** a write transaction to indicate that, unless it is rolled back for some 1371 ** a write transaction to indicate that, unless it is rolled back for some 1351 ** reason, the entire database file will be overwritten by the current 1372 ** reason, the entire database file will be overwritten by the current 1352 ** transaction. This is used by VACUUM operations. 1373 ** transaction. This is used by VACUUM operations. > 1374 ** > 1375 ** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of > 1376 ** all [VFSes] in the VFS stack. The names are of all VFS shims and the > 1377 ** final bottom-level VFS are written into memory obtained from > 1378 ** [sqlite3_malloc()] and the result is stored in the char* variable > 1379 ** that the fourth parameter of [sqlite3_file_control()] points to. > 1380 ** The caller is responsible for freeing the memory when done. As with > 1381 ** all file-control actions, there is no guarantee that this will actually > 1382 ** do anything. Callers should initialize the char* variable to a NULL > 1383 ** pointer in case this file-control is not implemented. This file-control > 1384 ** is intended for diagnostic use only. 1353 */ 1385 */ 1354 #define SQLITE_FCNTL_LOCKSTATE 1 | 1386 #define SQLITE_FCNTL_LOCKSTATE 1 1355 #define SQLITE_GET_LOCKPROXYFILE 2 | 1387 #define SQLITE_GET_LOCKPROXYFILE 2 1356 #define SQLITE_SET_LOCKPROXYFILE 3 | 1388 #define SQLITE_SET_LOCKPROXYFILE 3 1357 #define SQLITE_LAST_ERRNO 4 | 1389 #define SQLITE_LAST_ERRNO 4 1358 #define SQLITE_FCNTL_SIZE_HINT 5 | 1390 #define SQLITE_FCNTL_SIZE_HINT 5 1359 #define SQLITE_FCNTL_CHUNK_SIZE 6 | 1391 #define SQLITE_FCNTL_CHUNK_SIZE 6 1360 #define SQLITE_FCNTL_FILE_POINTER 7 | 1392 #define SQLITE_FCNTL_FILE_POINTER 7 1361 #define SQLITE_FCNTL_SYNC_OMITTED 8 | 1393 #define SQLITE_FCNTL_SYNC_OMITTED 8 1362 #define SQLITE_FCNTL_WIN32_AV_RETRY 9 | 1394 #define SQLITE_FCNTL_WIN32_AV_RETRY 9 1363 #define SQLITE_FCNTL_PERSIST_WAL 10 | 1395 #define SQLITE_FCNTL_PERSIST_WAL 10 1364 #define SQLITE_FCNTL_OVERWRITE 11 | 1396 #define SQLITE_FCNTL_OVERWRITE 11 > 1397 #define SQLITE_FCNTL_VFSNAME 12 > 1398 #define SQLITE_FCNTL_POWERSAFE_OVERWRITE 13 1365 1399 1366 /* 1400 /* 1367 ** CAPI3REF: Mutex Handle 1401 ** CAPI3REF: Mutex Handle 1368 ** 1402 ** 1369 ** The mutex module within SQLite defines [sqlite3_mutex] to be an 1403 ** The mutex module within SQLite defines [sqlite3_mutex] to be an 1370 ** abstract type for a mutex object. The SQLite core never looks 1404 ** abstract type for a mutex object. The SQLite core never looks 1371 ** at the internal representation of an [sqlite3_mutex]. It only 1405 ** at the internal representation of an [sqlite3_mutex]. It only ................................................................................................................................................................................ 1412 ** 1446 ** 1413 ** [[sqlite3_vfs.xOpen]] 1447 ** [[sqlite3_vfs.xOpen]] 1414 ** ^SQLite guarantees that the zFilename parameter to xOpen 1448 ** ^SQLite guarantees that the zFilename parameter to xOpen 1415 ** is either a NULL pointer or string obtained 1449 ** is either a NULL pointer or string obtained 1416 ** from xFullPathname() with an optional suffix added. 1450 ** from xFullPathname() with an optional suffix added. 1417 ** ^If a suffix is added to the zFilename parameter, it will 1451 ** ^If a suffix is added to the zFilename parameter, it will 1418 ** consist of a single "-" character followed by no more than 1452 ** consist of a single "-" character followed by no more than 1419 ** 10 alphanumeric and/or "-" characters. | 1453 ** 11 alphanumeric and/or "-" characters. 1420 ** ^SQLite further guarantees that 1454 ** ^SQLite further guarantees that 1421 ** the string will be valid and unchanged until xClose() is 1455 ** the string will be valid and unchanged until xClose() is 1422 ** called. Because of the previous sentence, 1456 ** called. Because of the previous sentence, 1423 ** the [sqlite3_file] can safely store a pointer to the 1457 ** the [sqlite3_file] can safely store a pointer to the 1424 ** filename if it needs to remember the filename for some reason. 1458 ** filename if it needs to remember the filename for some reason. 1425 ** If the zFilename parameter to xOpen is a NULL pointer then xOpen 1459 ** If the zFilename parameter to xOpen is a NULL pointer then xOpen 1426 ** must invent its own temporary name for the file. ^Whenever the 1460 ** must invent its own temporary name for the file. ^Whenever the ................................................................................................................................................................................ 1943 ** scratch memory beyond what is provided by this configuration option, then 1977 ** scratch memory beyond what is provided by this configuration option, then 1944 ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd> 1978 ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd> 1945 ** 1979 ** 1946 ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt> 1980 ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt> 1947 ** <dd> ^This option specifies a static memory buffer that SQLite can use for 1981 ** <dd> ^This option specifies a static memory buffer that SQLite can use for 1948 ** the database page cache with the default page cache implementation. 1982 ** the database page cache with the default page cache implementation. 1949 ** This configuration should not be used if an application-define page 1983 ** This configuration should not be used if an application-define page 1950 ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option. | 1984 ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE2 option. 1951 ** There are three arguments to this option: A pointer to 8-byte aligned 1985 ** There are three arguments to this option: A pointer to 8-byte aligned 1952 ** memory, the size of each page buffer (sz), and the number of pages (N). 1986 ** memory, the size of each page buffer (sz), and the number of pages (N). 1953 ** The sz argument should be the size of the largest database page 1987 ** The sz argument should be the size of the largest database page 1954 ** (a power of two between 512 and 32768) plus a little extra for each 1988 ** (a power of two between 512 and 32768) plus a little extra for each 1955 ** page header. ^The page header size is 20 to 40 bytes depending on 1989 ** page header. ^The page header size is 20 to 40 bytes depending on 1956 ** the host architecture. ^It is harmless, apart from the wasted memory, 1990 ** the host architecture. ^It is harmless, apart from the wasted memory, 1957 ** to make sz a little too large. The first 1991 ** to make sz a little too large. The first ................................................................................................................................................................................ 2012 ** [database connection]. The first argument is the 2046 ** [database connection]. The first argument is the 2013 ** size of each lookaside buffer slot and the second is the number of 2047 ** size of each lookaside buffer slot and the second is the number of 2014 ** slots allocated to each database connection.)^ ^(This option sets the 2048 ** slots allocated to each database connection.)^ ^(This option sets the 2015 ** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE] 2049 ** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE] 2016 ** verb to [sqlite3_db_config()] can be used to change the lookaside 2050 ** verb to [sqlite3_db_config()] can be used to change the lookaside 2017 ** configuration on individual connections.)^ </dd> 2051 ** configuration on individual connections.)^ </dd> 2018 ** 2052 ** 2019 ** [[SQLITE_CONFIG_PCACHE]] <dt>SQLITE_CONFIG_PCACHE</dt> | 2053 ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt> 2020 ** <dd> ^(This option takes a single argument which is a pointer to 2054 ** <dd> ^(This option takes a single argument which is a pointer to 2021 ** an [sqlite3_pcache_methods] object. This object specifies the interface | 2055 ** an [sqlite3_pcache_methods2] object. This object specifies the interface 2022 ** to a custom page cache implementation.)^ ^SQLite makes a copy of the 2056 ** to a custom page cache implementation.)^ ^SQLite makes a copy of the 2023 ** object and uses it for page cache memory allocations.</dd> 2057 ** object and uses it for page cache memory allocations.</dd> 2024 ** 2058 ** 2025 ** [[SQLITE_CONFIG_GETPCACHE]] <dt>SQLITE_CONFIG_GETPCACHE</dt> | 2059 ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt> 2026 ** <dd> ^(This option takes a single argument which is a pointer to an 2060 ** <dd> ^(This option takes a single argument which is a pointer to an 2027 ** [sqlite3_pcache_methods] object. SQLite copies of the current | 2061 ** [sqlite3_pcache_methods2] object. SQLite copies of the current 2028 ** page cache implementation into that object.)^ </dd> 2062 ** page cache implementation into that object.)^ </dd> 2029 ** 2063 ** 2030 ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt> 2064 ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt> 2031 ** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a 2065 ** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a 2032 ** function with a call signature of void(*)(void*,int,const char*), 2066 ** function with a call signature of void(*)(void*,int,const char*), 2033 ** and a pointer to void. ^If the function pointer is not NULL, it is 2067 ** and a pointer to void. ^If the function pointer is not NULL, it is 2034 ** invoked by [sqlite3_log()] to process each logging event. ^If the 2068 ** invoked by [sqlite3_log()] to process each logging event. ^If the ................................................................................................................................................................................ 2053 ** specified as part of [ATTACH] commands are interpreted as URIs, regardless 2087 ** specified as part of [ATTACH] commands are interpreted as URIs, regardless 2054 ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database 2088 ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database 2055 ** connection is opened. If it is globally disabled, filenames are 2089 ** connection is opened. If it is globally disabled, filenames are 2056 ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the 2090 ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the 2057 ** database connection is opened. By default, URI handling is globally 2091 ** database connection is opened. By default, URI handling is globally 2058 ** disabled. The default value may be changed by compiling with the 2092 ** disabled. The default value may be changed by compiling with the 2059 ** [SQLITE_USE_URI] symbol defined. 2093 ** [SQLITE_USE_URI] symbol defined. > 2094 ** > 2095 ** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]] > 2096 ** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFNIG_GETPCACHE > 2097 ** <dd> These options are obsolete and should not be used by new code. > 2098 ** They are retained for backwards compatibility but are now no-ops. 2060 ** </dl> 2099 ** </dl> 2061 */ 2100 */ 2062 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ 2101 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ 2063 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ 2102 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ 2064 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ 2103 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ 2065 #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */ 2104 #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */ 2066 #define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */ 2105 #define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */ ................................................................................................................................................................................ 2068 #define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */ 2107 #define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */ 2069 #define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */ 2108 #define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */ 2070 #define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */ 2109 #define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */ 2071 #define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */ 2110 #define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */ 2072 #define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */ 2111 #define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */ 2073 /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */ 2112 /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */ 2074 #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */ 2113 #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */ 2075 #define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */ | 2114 #define SQLITE_CONFIG_PCACHE 14 /* no-op */ 2076 #define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */ | 2115 #define SQLITE_CONFIG_GETPCACHE 15 /* no-op */ 2077 #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */ 2116 #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */ 2078 #define SQLITE_CONFIG_URI 17 /* int */ 2117 #define SQLITE_CONFIG_URI 17 /* int */ > 2118 #define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */ > 2119 #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */ 2079 2120 2080 /* 2121 /* 2081 ** CAPI3REF: Database Connection Configuration Options 2122 ** CAPI3REF: Database Connection Configuration Options 2082 ** 2123 ** 2083 ** These constants are the available integer configuration options that 2124 ** These constants are the available integer configuration options that 2084 ** can be passed as the second argument to the [sqlite3_db_config()] interface. 2125 ** can be passed as the second argument to the [sqlite3_db_config()] interface. 2085 ** 2126 ** ................................................................................................................................................................................ 2556 ** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf(). 2597 ** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf(). 2557 ** 2598 ** 2558 ** These routines all implement some additional formatting 2599 ** These routines all implement some additional formatting 2559 ** options that are useful for constructing SQL statements. 2600 ** options that are useful for constructing SQL statements. 2560 ** All of the usual printf() formatting options apply. In addition, there 2601 ** All of the usual printf() formatting options apply. In addition, there 2561 ** is are "%q", "%Q", and "%z" options. 2602 ** is are "%q", "%Q", and "%z" options. 2562 ** 2603 ** 2563 ** ^(The %q option works like %s in that it substitutes a null-terminated | 2604 ** ^(The %q option works like %s in that it substitutes a nul-terminated 2564 ** string from the argument list. But %q also doubles every '\'' character. 2605 ** string from the argument list. But %q also doubles every '\'' character. 2565 ** %q is designed for use inside a string literal.)^ By doubling each '\'' 2606 ** %q is designed for use inside a string literal.)^ By doubling each '\'' 2566 ** character it escapes that character and allows it to be inserted into 2607 ** character it escapes that character and allows it to be inserted into 2567 ** the string. 2608 ** the string. 2568 ** 2609 ** 2569 ** For example, assume the string variable zText contains text as follows: 2610 ** For example, assume the string variable zText contains text as follows: 2570 ** 2611 ** ................................................................................................................................................................................ 3164 int flags, /* Flags */ 3205 int flags, /* Flags */ 3165 const char *zVfs /* Name of VFS module to use */ 3206 const char *zVfs /* Name of VFS module to use */ 3166 ); 3207 ); 3167 3208 3168 /* 3209 /* 3169 ** CAPI3REF: Obtain Values For URI Parameters 3210 ** CAPI3REF: Obtain Values For URI Parameters 3170 ** 3211 ** 3171 ** This is a utility routine, useful to VFS implementations, that checks | 3212 ** These are utility routines, useful to VFS implementations, that check 3172 ** to see if a database file was a URI that contained a specific query 3213 ** to see if a database file was a URI that contained a specific query 3173 ** parameter, and if so obtains the value of the query parameter. | 3214 ** parameter, and if so obtains the value of that query parameter. 3174 ** 3215 ** 3175 ** The zFilename argument is the filename pointer passed into the xOpen() | 3216 ** If F is the database filename pointer passed into the xOpen() method of 3176 ** method of a VFS implementation. The zParam argument is the name of the | 3217 ** a VFS implementation when the flags parameter to xOpen() has one or > 3218 ** more of the [SQLITE_OPEN_URI] or [SQLITE_OPEN_MAIN_DB] bits set and > 3219 ** P is the name of the query parameter, then 3177 ** query parameter we seek. This routine returns the value of the zParam | 3220 ** sqlite3_uri_parameter(F,P) returns the value of the P 3178 ** parameter if it exists. If the parameter does not exist, this routine | 3221 ** parameter if it exists or a NULL pointer if P does not appear as a 3179 ** returns a NULL pointer. < > 3222 ** query parameter on F. If P is a query parameter of F > 3223 ** has no explicit value, then sqlite3_uri_parameter(F,P) returns > 3224 ** a pointer to an empty string. 3180 ** 3225 ** 3181 ** If the zFilename argument to this function is not a pointer that SQLite | 3226 ** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean > 3227 ** parameter and returns true (1) or false (0) according to the value > 3228 ** of P. The value of P is true if it is "yes" or "true" or "on" or > 3229 ** a non-zero number and is false otherwise. If P is not a query parameter > 3230 ** on F then sqlite3_uri_boolean(F,P,B) returns (B!=0). > 3231 ** > 3232 ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a > 3233 ** 64-bit signed integer and returns that integer, or D if P does not > 3234 ** exist. If the value of P is something other than an integer, then > 3235 ** zero is returned. > 3236 ** > 3237 ** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and > 3238 ** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and > 3239 ** is not a database file pathname pointer that SQLite passed into the xOpen 3182 ** passed into the xOpen VFS method, then the behavior of this routine | 3240 ** VFS method, then the behavior of this routine is undefined and probably 3183 ** is undefined and probably undesirable. | 3241 ** undesirable. 3184 */ 3242 */ 3185 SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char * 3243 SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char * > 3244 SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bD > 3245 SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int 3186 3246 3187 3247 3188 /* 3248 /* 3189 ** CAPI3REF: Error Codes And Messages 3249 ** CAPI3REF: Error Codes And Messages 3190 ** 3250 ** 3191 ** ^The sqlite3_errcode() interface returns the numeric [result code] or 3251 ** ^The sqlite3_errcode() interface returns the numeric [result code] or 3192 ** [extended result code] for the most recent failed sqlite3_* API call 3252 ** [extended result code] for the most recent failed sqlite3_* API call ................................................................................................................................................................................ 3500 ** database. ^The [ATTACH] and [DETACH] statements also cause 3560 ** database. ^The [ATTACH] and [DETACH] statements also cause 3501 ** sqlite3_stmt_readonly() to return true since, while those statements 3561 ** sqlite3_stmt_readonly() to return true since, while those statements 3502 ** change the configuration of a database connection, they do not make 3562 ** change the configuration of a database connection, they do not make 3503 ** changes to the content of the database files on disk. 3563 ** changes to the content of the database files on disk. 3504 */ 3564 */ 3505 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt); 3565 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt); 3506 3566 > 3567 /* > 3568 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset > 3569 ** > 3570 ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the > 3571 ** [prepared statement] S has been stepped at least once using > 3572 ** [sqlite3_step(S)] but has not run to completion and/or has not > 3573 ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S) > 3574 ** interface returns false if S is a NULL pointer. If S is not a > 3575 ** NULL pointer and is not a pointer to a valid [prepared statement] > 3576 ** object, then the behavior is undefined and probably undesirable. > 3577 ** > 3578 ** This interface can be used in combination [sqlite3_next_stmt()] > 3579 ** to locate all prepared statements associated with a database > 3580 ** connection that are in need of being reset. This can be used, > 3581 ** for example, in diagnostic routines to search for prepared > 3582 ** statements that are holding a transaction open. > 3583 */ > 3584 SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt*); > 3585 3507 /* 3586 /* 3508 ** CAPI3REF: Dynamically Typed Value Object 3587 ** CAPI3REF: Dynamically Typed Value Object 3509 ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value} 3588 ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value} 3510 ** 3589 ** 3511 ** SQLite uses the sqlite3_value object to represent all values 3590 ** SQLite uses the sqlite3_value object to represent all values 3512 ** that can be stored in a database table. SQLite uses dynamic typing 3591 ** that can be stored in a database table. SQLite uses dynamic typing 3513 ** for the values it stores. ^Values stored in sqlite3_value objects 3592 ** for the values it stores. ^Values stored in sqlite3_value objects ................................................................................................................................................................................ 4041 ** ^The values returned by [sqlite3_column_bytes()] and 4120 ** ^The values returned by [sqlite3_column_bytes()] and 4042 ** [sqlite3_column_bytes16()] do not include the zero terminators at the end 4121 ** [sqlite3_column_bytes16()] do not include the zero terminators at the end 4043 ** of the string. ^For clarity: the values returned by 4122 ** of the string. ^For clarity: the values returned by 4044 ** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of 4123 ** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of 4045 ** bytes in the string, not the number of characters. 4124 ** bytes in the string, not the number of characters. 4046 ** 4125 ** 4047 ** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(), 4126 ** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(), 4048 ** even empty strings, are always zero terminated. ^The return | 4127 ** even empty strings, are always zero-terminated. ^The return 4049 ** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer. 4128 ** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer. 4050 ** 4129 ** 4051 ** ^The object returned by [sqlite3_column_value()] is an 4130 ** ^The object returned by [sqlite3_column_value()] is an 4052 ** [unprotected sqlite3_value] object. An unprotected sqlite3_value object 4131 ** [unprotected sqlite3_value] object. An unprotected sqlite3_value object 4053 ** may only be used with [sqlite3_bind_value()] and [sqlite3_result_value()]. 4132 ** may only be used with [sqlite3_bind_value()] and [sqlite3_result_value()]. 4054 ** If the [unprotected sqlite3_value] object returned by 4133 ** If the [unprotected sqlite3_value] object returned by 4055 ** [sqlite3_column_value()] is used in any other way, including calls 4134 ** [sqlite3_column_value()] is used in any other way, including calls ................................................................................................................................................................................ 4941 ** returned by sqlite3_db_handle is the same [database connection] 5020 ** returned by sqlite3_db_handle is the same [database connection] 4942 ** that was the first argument 5021 ** that was the first argument 4943 ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to 5022 ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to 4944 ** create the statement in the first place. 5023 ** create the statement in the first place. 4945 */ 5024 */ 4946 SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*); 5025 SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*); 4947 5026 > 5027 /* > 5028 ** CAPI3REF: Return The Filename For A Database Connection > 5029 ** > 5030 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename > 5031 ** associated with database N of connection D. ^The main database file > 5032 ** has the name "main". If there is no attached database N on the database > 5033 ** connection D, or if database N is a temporary or in-memory database, then > 5034 ** a NULL pointer is returned. > 5035 ** > 5036 ** ^The filename returned by this function is the output of the > 5037 ** xFullPathname method of the [VFS]. ^In other words, the filename > 5038 ** will be an absolute pathname, even if the filename used > 5039 ** to open the database originally was a URI or relative pathname. > 5040 */ > 5041 SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName); > 5042 4948 /* 5043 /* 4949 ** CAPI3REF: Find the next prepared statement 5044 ** CAPI3REF: Find the next prepared statement 4950 ** 5045 ** 4951 ** ^This interface returns a pointer to the next [prepared statement] after 5046 ** ^This interface returns a pointer to the next [prepared statement] after 4952 ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL 5047 ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL 4953 ** then this interface returns a pointer to the first prepared statement 5048 ** then this interface returns a pointer to the first prepared statement 4954 ** associated with the database connection pDb. ^If no prepared statement 5049 ** associated with the database connection pDb. ^If no prepared statement ................................................................................................................................................................................ 4976 ** then the commit is converted into a rollback. 5071 ** then the commit is converted into a rollback. 4977 ** 5072 ** 4978 ** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions 5073 ** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions 4979 ** return the P argument from the previous call of the same function 5074 ** return the P argument from the previous call of the same function 4980 ** on the same [database connection] D, or NULL for 5075 ** on the same [database connection] D, or NULL for 4981 ** the first call for each function on D. 5076 ** the first call for each function on D. 4982 ** 5077 ** > 5078 ** The commit and rollback hook callbacks are not reentrant. 4983 ** The callback implementation must not do anything that will modify 5079 ** The callback implementation must not do anything that will modify 4984 ** the database connection that invoked the callback. Any actions 5080 ** the database connection that invoked the callback. Any actions 4985 ** to modify the database connection must be deferred until after the 5081 ** to modify the database connection must be deferred until after the 4986 ** completion of the [sqlite3_step()] call that triggered the commit 5082 ** completion of the [sqlite3_step()] call that triggered the commit 4987 ** or rollback hook in the first place. 5083 ** or rollback hook in the first place. > 5084 ** Note that running any other SQL statements, including SELECT statements, 4988 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their | 5085 ** or merely calling [sqlite3_prepare_v2()] and [sqlite3_step()] will modify 4989 ** database connections for the meaning of "modify" in this paragraph. | 5086 ** the database connections for the meaning of "modify" in this paragraph. 4990 ** 5087 ** 4991 ** ^Registering a NULL function disables the callback. 5088 ** ^Registering a NULL function disables the callback. 4992 ** 5089 ** 4993 ** ^When the commit hook callback routine returns zero, the [COMMIT] 5090 ** ^When the commit hook callback routine returns zero, the [COMMIT] 4994 ** operation is allowed to continue normally. ^If the commit hook 5091 ** operation is allowed to continue normally. ^If the commit hook 4995 ** returns non-zero, then the [COMMIT] is converted into a [ROLLBACK]. 5092 ** returns non-zero, then the [COMMIT] is converted into a [ROLLBACK]. 4996 ** ^The rollback hook is invoked on a rollback that results from a commit 5093 ** ^The rollback hook is invoked on a rollback that results from a commit ................................................................................................................................................................................ 5095 ** of heap memory by deallocating non-essential memory allocations 5192 ** of heap memory by deallocating non-essential memory allocations 5096 ** held by the database library. Memory used to cache database 5193 ** held by the database library. Memory used to cache database 5097 ** pages to improve performance is an example of non-essential memory. 5194 ** pages to improve performance is an example of non-essential memory. 5098 ** ^sqlite3_release_memory() returns the number of bytes actually freed, 5195 ** ^sqlite3_release_memory() returns the number of bytes actually freed, 5099 ** which might be more or less than the amount requested. 5196 ** which might be more or less than the amount requested. 5100 ** ^The sqlite3_release_memory() routine is a no-op returning zero 5197 ** ^The sqlite3_release_memory() routine is a no-op returning zero 5101 ** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT]. 5198 ** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT]. > 5199 ** > 5200 ** See also: [sqlite3_db_release_memory()] 5102 */ 5201 */ 5103 SQLITE_API int sqlite3_release_memory(int); 5202 SQLITE_API int sqlite3_release_memory(int); 5104 5203 > 5204 /* > 5205 ** CAPI3REF: Free Memory Used By A Database Connection > 5206 ** > 5207 ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap > 5208 ** memory as possible from database connection D. Unlike the > 5209 ** [sqlite3_release_memory()] interface, this interface is effect even > 5210 ** when then [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is > 5211 ** omitted. > 5212 ** > 5213 ** See also: [sqlite3_release_memory()] > 5214 */ > 5215 SQLITE_API int sqlite3_db_release_memory(sqlite3*); > 5216 5105 /* 5217 /* 5106 ** CAPI3REF: Impose A Limit On Heap Size 5218 ** CAPI3REF: Impose A Limit On Heap Size 5107 ** 5219 ** 5108 ** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the 5220 ** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the 5109 ** soft limit on the amount of heap memory that may be allocated by SQLite. 5221 ** soft limit on the amount of heap memory that may be allocated by SQLite. 5110 ** ^SQLite strives to keep heap memory utilization below the soft heap 5222 ** ^SQLite strives to keep heap memory utilization below the soft heap 5111 ** limit by reducing the number of pages held in the page cache 5223 ** limit by reducing the number of pages held in the page cache ................................................................................................................................................................................ 5112 ** as heap memory usages approaches the limit. 5224 ** as heap memory usages approaches the limit. 5113 ** ^The soft heap limit is "soft" because even though SQLite strives to stay 5225 ** ^The soft heap limit is "soft" because even though SQLite strives to stay 5114 ** below the limit, it will exceed the limit rather than generate 5226 ** below the limit, it will exceed the limit rather than generate 5115 ** an [SQLITE_NOMEM] error. In other words, the soft heap limit 5227 ** an [SQLITE_NOMEM] error. In other words, the soft heap limit 5116 ** is advisory only. 5228 ** is advisory only. 5117 ** 5229 ** 5118 ** ^The return value from sqlite3_soft_heap_limit64() is the size of 5230 ** ^The return value from sqlite3_soft_heap_limit64() is the size of > 5231 ** the soft heap limit prior to the call, or negative in the case of an 5119 ** the soft heap limit prior to the call. ^If the argument N is negative | 5232 ** error. ^If the argument N is negative 5120 ** then no change is made to the soft heap limit. Hence, the current 5233 ** then no change is made to the soft heap limit. Hence, the current 5121 ** size of the soft heap limit can be determined by invoking 5234 ** size of the soft heap limit can be determined by invoking 5122 ** sqlite3_soft_heap_limit64() with a negative argument. 5235 ** sqlite3_soft_heap_limit64() with a negative argument. 5123 ** 5236 ** 5124 ** ^If the argument N is zero then the soft heap limit is disabled. 5237 ** ^If the argument N is zero then the soft heap limit is disabled. 5125 ** 5238 ** 5126 ** ^(The soft heap limit is not enforced in the current implementation 5239 ** ^(The soft heap limit is not enforced in the current implementation ................................................................................................................................................................................ 5128 ** 5241 ** 5129 ** <ul> 5242 ** <ul> 5130 ** <li> The soft heap limit is set to zero. 5243 ** <li> The soft heap limit is set to zero. 5131 ** <li> Memory accounting is disabled using a combination of the 5244 ** <li> Memory accounting is disabled using a combination of the 5132 ** [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and 5245 ** [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and 5133 ** the [SQLITE_DEFAULT_MEMSTATUS] compile-time option. 5246 ** the [SQLITE_DEFAULT_MEMSTATUS] compile-time option. 5134 ** <li> An alternative page cache implementation is specified using 5247 ** <li> An alternative page cache implementation is specified using 5135 ** [sqlite3_config]([SQLITE_CONFIG_PCACHE],...). | 5248 ** [sqlite3_config]([SQLITE_CONFIG_PCACHE2],...). 5136 ** <li> The page cache allocates from its own memory pool supplied 5249 ** <li> The page cache allocates from its own memory pool supplied 5137 ** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than 5250 ** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than 5138 ** from the heap. 5251 ** from the heap. 5139 ** </ul>)^ 5252 ** </ul>)^ 5140 ** 5253 ** 5141 ** Beginning with SQLite version 3.7.3, the soft heap limit is enforced 5254 ** Beginning with SQLite version 3.7.3, the soft heap limit is enforced 5142 ** regardless of whether or not the [SQLITE_ENABLE_MEMORY_MANAGEMENT] 5255 ** regardless of whether or not the [SQLITE_ENABLE_MEMORY_MANAGEMENT] ................................................................................................................................................................................ 5870 ** The SQLite source code contains multiple implementations 5983 ** The SQLite source code contains multiple implementations 5871 ** of these mutex routines. An appropriate implementation 5984 ** of these mutex routines. An appropriate implementation 5872 ** is selected automatically at compile-time. ^(The following 5985 ** is selected automatically at compile-time. ^(The following 5873 ** implementations are available in the SQLite core: 5986 ** implementations are available in the SQLite core: 5874 ** 5987 ** 5875 ** <ul> 5988 ** <ul> 5876 ** <li> SQLITE_MUTEX_OS2 5989 ** <li> SQLITE_MUTEX_OS2 5877 ** <li> SQLITE_MUTEX_PTHREAD | 5990 ** <li> SQLITE_MUTEX_PTHREADS 5878 ** <li> SQLITE_MUTEX_W32 5991 ** <li> SQLITE_MUTEX_W32 5879 ** <li> SQLITE_MUTEX_NOOP 5992 ** <li> SQLITE_MUTEX_NOOP 5880 ** </ul>)^ 5993 ** </ul>)^ 5881 ** 5994 ** 5882 ** ^The SQLITE_MUTEX_NOOP implementation is a set of routines 5995 ** ^The SQLITE_MUTEX_NOOP implementation is a set of routines 5883 ** that does no real locking and is appropriate for use in 5996 ** that does no real locking and is appropriate for use in 5884 ** a single-threaded application. ^The SQLITE_MUTEX_OS2, 5997 ** a single-threaded application. ^The SQLITE_MUTEX_OS2, 5885 ** SQLITE_MUTEX_PTHREAD, and SQLITE_MUTEX_W32 implementations | 5998 ** SQLITE_MUTEX_PTHREADS, and SQLITE_MUTEX_W32 implementations 5886 ** are appropriate for use on OS/2, Unix, and Windows. 5999 ** are appropriate for use on OS/2, Unix, and Windows. 5887 ** 6000 ** 5888 ** ^(If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor 6001 ** ^(If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor 5889 ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex 6002 ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex 5890 ** implementation is included with the library. In this case the 6003 ** implementation is included with the library. In this case the 5891 ** application must supply a custom mutex implementation using the 6004 ** application must supply a custom mutex implementation using the 5892 ** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function 6005 ** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function ................................................................................................................................................................................ 6068 ** with the SQLITE_DEBUG flag. ^External mutex implementations 6181 ** with the SQLITE_DEBUG flag. ^External mutex implementations 6069 ** are only required to provide these routines if SQLITE_DEBUG is 6182 ** are only required to provide these routines if SQLITE_DEBUG is 6070 ** defined and if NDEBUG is not defined. 6183 ** defined and if NDEBUG is not defined. 6071 ** 6184 ** 6072 ** ^These routines should return true if the mutex in their argument 6185 ** ^These routines should return true if the mutex in their argument 6073 ** is held or not held, respectively, by the calling thread. 6186 ** is held or not held, respectively, by the calling thread. 6074 ** 6187 ** 6075 ** ^The implementation is not required to provided versions of these | 6188 ** ^The implementation is not required to provide versions of these 6076 ** routines that actually work. If the implementation does not provide working 6189 ** routines that actually work. If the implementation does not provide working 6077 ** versions of these routines, it should at least provide stubs that always 6190 ** versions of these routines, it should at least provide stubs that always 6078 ** return true so that one does not get spurious assertion failures. 6191 ** return true so that one does not get spurious assertion failures. 6079 ** 6192 ** 6080 ** ^If the argument to sqlite3_mutex_held() is a NULL pointer then 6193 ** ^If the argument to sqlite3_mutex_held() is a NULL pointer then 6081 ** the routine should return 1. This seems counter-intuitive since 6194 ** the routine should return 1. This seems counter-intuitive since 6082 ** clearly the mutex cannot be held if it does not exist. But 6195 ** clearly the mutex cannot be held if it does not exist. But ................................................................................................................................................................................ 6196 #define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS 10 6309 #define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS 10 6197 #define SQLITE_TESTCTRL_PENDING_BYTE 11 6310 #define SQLITE_TESTCTRL_PENDING_BYTE 11 6198 #define SQLITE_TESTCTRL_ASSERT 12 6311 #define SQLITE_TESTCTRL_ASSERT 12 6199 #define SQLITE_TESTCTRL_ALWAYS 13 6312 #define SQLITE_TESTCTRL_ALWAYS 13 6200 #define SQLITE_TESTCTRL_RESERVE 14 6313 #define SQLITE_TESTCTRL_RESERVE 14 6201 #define SQLITE_TESTCTRL_OPTIMIZATIONS 15 6314 #define SQLITE_TESTCTRL_OPTIMIZATIONS 15 6202 #define SQLITE_TESTCTRL_ISKEYWORD 16 6315 #define SQLITE_TESTCTRL_ISKEYWORD 16 6203 #define SQLITE_TESTCTRL_PGHDRSZ 17 < 6204 #define SQLITE_TESTCTRL_SCRATCHMALLOC 18 | 6316 #define SQLITE_TESTCTRL_SCRATCHMALLOC 17 6205 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 19 | 6317 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18 > 6318 #define SQLITE_TESTCTRL_EXPLAIN_STMT 19 6206 #define SQLITE_TESTCTRL_LAST 19 6319 #define SQLITE_TESTCTRL_LAST 19 6207 6320 6208 /* 6321 /* 6209 ** CAPI3REF: SQLite Runtime Status 6322 ** CAPI3REF: SQLite Runtime Status 6210 ** 6323 ** 6211 ** ^This interface is used to retrieve runtime status information 6324 ** ^This interface is used to retrieve runtime status information 6212 ** about the performance of SQLite, and optionally to reset various 6325 ** about the performance of SQLite, and optionally to reset various ................................................................................................................................................................................ 6501 ** 6614 ** 6502 ** The sqlite3_pcache type is opaque. It is implemented by 6615 ** The sqlite3_pcache type is opaque. It is implemented by 6503 ** the pluggable module. The SQLite core has no knowledge of 6616 ** the pluggable module. The SQLite core has no knowledge of 6504 ** its size or internal structure and never deals with the 6617 ** its size or internal structure and never deals with the 6505 ** sqlite3_pcache object except by holding and passing pointers 6618 ** sqlite3_pcache object except by holding and passing pointers 6506 ** to the object. 6619 ** to the object. 6507 ** 6620 ** 6508 ** See [sqlite3_pcache_methods] for additional information. | 6621 ** See [sqlite3_pcache_methods2] for additional information. 6509 */ 6622 */ 6510 typedef struct sqlite3_pcache sqlite3_pcache; 6623 typedef struct sqlite3_pcache sqlite3_pcache; > 6624 > 6625 /* > 6626 ** CAPI3REF: Custom Page Cache Object > 6627 ** > 6628 ** The sqlite3_pcache_page object represents a single page in the > 6629 ** page cache. The page cache will allocate instances of this > 6630 ** object. Various methods of the page cache use pointers to instances > 6631 ** of this object as parameters or as their return value. > 6632 ** > 6633 ** See [sqlite3_pcache_methods2] for additional information. > 6634 */ > 6635 typedef struct sqlite3_pcache_page sqlite3_pcache_page; > 6636 struct sqlite3_pcache_page { > 6637 void *pBuf; /* The content of the page */ > 6638 void *pExtra; /* Extra information associated with the page */ > 6639 }; 6511 6640 6512 /* 6641 /* 6513 ** CAPI3REF: Application Defined Page Cache. 6642 ** CAPI3REF: Application Defined Page Cache. 6514 ** KEYWORDS: {page cache} 6643 ** KEYWORDS: {page cache} 6515 ** 6644 ** 6516 ** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can | 6645 ** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE2], ...) interface can 6517 ** register an alternative page cache implementation by passing in an 6646 ** register an alternative page cache implementation by passing in an 6518 ** instance of the sqlite3_pcache_methods structure.)^ | 6647 ** instance of the sqlite3_pcache_methods2 structure.)^ 6519 ** In many applications, most of the heap memory allocated by 6648 ** In many applications, most of the heap memory allocated by 6520 ** SQLite is used for the page cache. 6649 ** SQLite is used for the page cache. 6521 ** By implementing a 6650 ** By implementing a 6522 ** custom page cache using this API, an application can better control 6651 ** custom page cache using this API, an application can better control 6523 ** the amount of memory consumed by SQLite, the way in which 6652 ** the amount of memory consumed by SQLite, the way in which 6524 ** that memory is allocated and released, and the policies used to 6653 ** that memory is allocated and released, and the policies used to 6525 ** determine exactly which parts of a database file are cached and for 6654 ** determine exactly which parts of a database file are cached and for 6526 ** how long. 6655 ** how long. 6527 ** 6656 ** 6528 ** The alternative page cache mechanism is an 6657 ** The alternative page cache mechanism is an 6529 ** extreme measure that is only needed by the most demanding applications. 6658 ** extreme measure that is only needed by the most demanding applications. 6530 ** The built-in page cache is recommended for most uses. 6659 ** The built-in page cache is recommended for most uses. 6531 ** 6660 ** 6532 ** ^(The contents of the sqlite3_pcache_methods structure are copied to an | 6661 ** ^(The contents of the sqlite3_pcache_methods2 structure are copied to an 6533 ** internal buffer by SQLite within the call to [sqlite3_config]. Hence 6662 ** internal buffer by SQLite within the call to [sqlite3_config]. Hence 6534 ** the application may discard the parameter after the call to 6663 ** the application may discard the parameter after the call to 6535 ** [sqlite3_config()] returns.)^ 6664 ** [sqlite3_config()] returns.)^ 6536 ** 6665 ** 6537 ** [[the xInit() page cache method]] 6666 ** [[the xInit() page cache method]] 6538 ** ^(The xInit() method is called once for each effective 6667 ** ^(The xInit() method is called once for each effective 6539 ** call to [sqlite3_initialize()])^ 6668 ** call to [sqlite3_initialize()])^ 6540 ** (usually only once during the lifetime of the process). ^(The xInit() 6669 ** (usually only once during the lifetime of the process). ^(The xInit() 6541 ** method is passed a copy of the sqlite3_pcache_methods.pArg value.)^ | 6670 ** method is passed a copy of the sqlite3_pcache_methods2.pArg value.)^ 6542 ** The intent of the xInit() method is to set up global data structures 6671 ** The intent of the xInit() method is to set up global data structures 6543 ** required by the custom page cache implementation. 6672 ** required by the custom page cache implementation. 6544 ** ^(If the xInit() method is NULL, then the 6673 ** ^(If the xInit() method is NULL, then the 6545 ** built-in default page cache is used instead of the application defined 6674 ** built-in default page cache is used instead of the application defined 6546 ** page cache.)^ 6675 ** page cache.)^ 6547 ** 6676 ** 6548 ** [[the xShutdown() page cache method]] 6677 ** [[the xShutdown() page cache method]] ................................................................................................................................................................................ 6561 ** call to xShutdown(). 6690 ** call to xShutdown(). 6562 ** 6691 ** 6563 ** [[the xCreate() page cache methods]] 6692 ** [[the xCreate() page cache methods]] 6564 ** ^SQLite invokes the xCreate() method to construct a new cache instance. 6693 ** ^SQLite invokes the xCreate() method to construct a new cache instance. 6565 ** SQLite will typically create one cache instance for each open database file, 6694 ** SQLite will typically create one cache instance for each open database file, 6566 ** though this is not guaranteed. ^The 6695 ** though this is not guaranteed. ^The 6567 ** first parameter, szPage, is the size in bytes of the pages that must 6696 ** first parameter, szPage, is the size in bytes of the pages that must 6568 ** be allocated by the cache. ^szPage will not be a power of two. ^szPage | 6697 ** be allocated by the cache. ^szPage will always a power of two. ^The 6569 ** will the page size of the database file that is to be cached plus an | 6698 ** second parameter szExtra is a number of bytes of extra storage > 6699 ** associated with each page cache entry. ^The szExtra parameter will 6570 ** increment (here called "R") of less than 250. SQLite will use the | 6700 ** a number less than 250. SQLite will use the 6571 ** extra R bytes on each page to store metadata about the underlying | 6701 ** extra szExtra bytes on each page to store metadata about the underlying 6572 ** database page on disk. The value of R depends | 6702 ** database page on disk. The value passed into szExtra depends 6573 ** on the SQLite version, the target platform, and how SQLite was compiled. 6703 ** on the SQLite version, the target platform, and how SQLite was compiled. 6574 ** ^(R is constant for a particular build of SQLite. Except, there are two < 6575 ** distinct values of R when SQLite is compiled with the proprietary < 6576 ** ZIPVFS extension.)^ ^The second argument to < 6577 ** xCreate(), bPurgeable, is true if the cache being created will | 6704 ** ^The third argument to xCreate(), bPurgeable, is true if the cache being 6578 ** be used to cache database pages of a file stored on disk, or | 6705 ** created will be used to cache database pages of a file stored on disk, or 6579 ** false if it is used for an in-memory database. The cache implementation 6706 ** false if it is used for an in-memory database. The cache implementation 6580 ** does not have to do anything special based with the value of bPurgeable; 6707 ** does not have to do anything special based with the value of bPurgeable; 6581 ** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will 6708 ** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will 6582 ** never invoke xUnpin() except to deliberately delete a page. 6709 ** never invoke xUnpin() except to deliberately delete a page. 6583 ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to 6710 ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to 6584 ** false will always have the "discard" flag set to true. 6711 ** false will always have the "discard" flag set to true. 6585 ** ^Hence, a cache created with bPurgeable false will 6712 ** ^Hence, a cache created with bPurgeable false will ................................................................................................................................................................................ 6595 ** 6722 ** 6596 ** [[the xPagecount() page cache methods]] 6723 ** [[the xPagecount() page cache methods]] 6597 ** The xPagecount() method must return the number of pages currently 6724 ** The xPagecount() method must return the number of pages currently 6598 ** stored in the cache, both pinned and unpinned. 6725 ** stored in the cache, both pinned and unpinned. 6599 ** 6726 ** 6600 ** [[the xFetch() page cache methods]] 6727 ** [[the xFetch() page cache methods]] 6601 ** The xFetch() method locates a page in the cache and returns a pointer to 6728 ** The xFetch() method locates a page in the cache and returns a pointer to 6602 ** the page, or a NULL pointer. | 6729 ** an sqlite3_pcache_page object associated with that page, or a NULL pointer. > 6730 ** The pBuf element of the returned sqlite3_pcache_page object will be a 6603 ** A "page", in this context, means a buffer of szPage bytes aligned at an | 6731 ** pointer to a buffer of szPage bytes used to store the content of a > 6732 ** single database page. The pExtra element of sqlite3_pcache_page will be > 6733 ** a pointer to the szExtra bytes of extra storage that SQLite has requested > 6734 ** for each entry in the page cache. > 6735 ** 6604 ** 8-byte boundary. The page to be fetched is determined by the key. ^The | 6736 ** The page to be fetched is determined by the key. ^The minimum key value 6605 ** minimum key value is 1. After it has been retrieved using xFetch, the page | 6737 ** is 1. After it has been retrieved using xFetch, the page is considered 6606 ** is considered to be "pinned". | 6738 ** to be "pinned". 6607 ** 6739 ** 6608 ** If the requested page is already in the page cache, then the page cache 6740 ** If the requested page is already in the page cache, then the page cache 6609 ** implementation must return a pointer to the page buffer with its content 6741 ** implementation must return a pointer to the page buffer with its content 6610 ** intact. If the requested page is not already in the cache, then the 6742 ** intact. If the requested page is not already in the cache, then the 6611 ** cache implementation should use the value of the createFlag 6743 ** cache implementation should use the value of the createFlag 6612 ** parameter to help it determined what action to take: 6744 ** parameter to help it determined what action to take: 6613 ** 6745 ** ................................................................................................................................................................................ 6652 ** of these pages are pinned, they are implicitly unpinned, meaning that 6784 ** of these pages are pinned, they are implicitly unpinned, meaning that 6653 ** they can be safely discarded. 6785 ** they can be safely discarded. 6654 ** 6786 ** 6655 ** [[the xDestroy() page cache method]] 6787 ** [[the xDestroy() page cache method]] 6656 ** ^The xDestroy() method is used to delete a cache allocated by xCreate(). 6788 ** ^The xDestroy() method is used to delete a cache allocated by xCreate(). 6657 ** All resources associated with the specified cache should be freed. ^After 6789 ** All resources associated with the specified cache should be freed. ^After 6658 ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*] 6790 ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*] 6659 ** handle invalid, and will not use it with any other sqlite3_pcache_methods | 6791 ** handle invalid, and will not use it with any other sqlite3_pcache_methods2 6660 ** functions. 6792 ** functions. > 6793 ** > 6794 ** [[the xShrink() page cache method]] > 6795 ** ^SQLite invokes the xShrink() method when it wants the page cache to > 6796 ** free up as much of heap memory as possible. The page cache implementation > 6797 ** is not obligated to free any memory, but well-behaved implementations should > 6798 ** do their best. > 6799 */ > 6800 typedef struct sqlite3_pcache_methods2 sqlite3_pcache_methods2; > 6801 struct sqlite3_pcache_methods2 { > 6802 int iVersion; > 6803 void *pArg; > 6804 int (*xInit)(void*); > 6805 void (*xShutdown)(void*); > 6806 sqlite3_pcache *(*xCreate)(int szPage, int szExtra, int bPurgeable); > 6807 void (*xCachesize)(sqlite3_pcache*, int nCachesize); > 6808 int (*xPagecount)(sqlite3_pcache*); > 6809 sqlite3_pcache_page *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag); > 6810 void (*xUnpin)(sqlite3_pcache*, sqlite3_pcache_page*, int discard); > 6811 void (*xRekey)(sqlite3_pcache*, sqlite3_pcache_page*, > 6812 unsigned oldKey, unsigned newKey); > 6813 void (*xTruncate)(sqlite3_pcache*, unsigned iLimit); > 6814 void (*xDestroy)(sqlite3_pcache*); > 6815 void (*xShrink)(sqlite3_pcache*); > 6816 }; > 6817 > 6818 /* > 6819 ** This is the obsolete pcache_methods object that has now been replaced > 6820 ** by sqlite3_pcache_methods2. This object is not used by SQLite. It is > 6821 ** retained in the header file for backwards compatibility only. 6661 */ 6822 */ 6662 typedef struct sqlite3_pcache_methods sqlite3_pcache_methods; 6823 typedef struct sqlite3_pcache_methods sqlite3_pcache_methods; 6663 struct sqlite3_pcache_methods { 6824 struct sqlite3_pcache_methods { 6664 void *pArg; 6825 void *pArg; 6665 int (*xInit)(void*); 6826 int (*xInit)(void*); 6666 void (*xShutdown)(void*); 6827 void (*xShutdown)(void*); 6667 sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable); 6828 sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable); ................................................................................................................................................................................ 6669 int (*xPagecount)(sqlite3_pcache*); 6830 int (*xPagecount)(sqlite3_pcache*); 6670 void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag); 6831 void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag); 6671 void (*xUnpin)(sqlite3_pcache*, void*, int discard); 6832 void (*xUnpin)(sqlite3_pcache*, void*, int discard); 6672 void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey); 6833 void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey); 6673 void (*xTruncate)(sqlite3_pcache*, unsigned iLimit); 6834 void (*xTruncate)(sqlite3_pcache*, unsigned iLimit); 6674 void (*xDestroy)(sqlite3_pcache*); 6835 void (*xDestroy)(sqlite3_pcache*); 6675 }; 6836 }; > 6837 6676 6838 6677 /* 6839 /* 6678 ** CAPI3REF: Online Backup Object 6840 ** CAPI3REF: Online Backup Object 6679 ** 6841 ** 6680 ** The sqlite3_backup object records state information about an ongoing 6842 ** The sqlite3_backup object records state information about an ongoing 6681 ** online backup operation. ^The sqlite3_backup object is created by 6843 ** online backup operation. ^The sqlite3_backup object is created by 6682 ** a call to [sqlite3_backup_init()] and is destroyed by a call to 6844 ** a call to [sqlite3_backup_init()] and is destroyed by a call to ................................................................................................................................................................................ 7673 ** The "file format" number is an integer that is incremented whenever 7835 ** The "file format" number is an integer that is incremented whenever 7674 ** the VDBE-level file format changes. The following macros define the 7836 ** the VDBE-level file format changes. The following macros define the 7675 ** the default file format for new databases and the maximum file format 7837 ** the default file format for new databases and the maximum file format 7676 ** that the library can read. 7838 ** that the library can read. 7677 */ 7839 */ 7678 #define SQLITE_MAX_FILE_FORMAT 4 7840 #define SQLITE_MAX_FILE_FORMAT 4 7679 #ifndef SQLITE_DEFAULT_FILE_FORMAT 7841 #ifndef SQLITE_DEFAULT_FILE_FORMAT 7680 # define SQLITE_DEFAULT_FILE_FORMAT 1 | 7842 # define SQLITE_DEFAULT_FILE_FORMAT 4 7681 #endif 7843 #endif 7682 7844 7683 /* 7845 /* 7684 ** Determine whether triggers are recursive by default. This can be 7846 ** Determine whether triggers are recursive by default. This can be 7685 ** changed at run-time using a pragma. 7847 ** changed at run-time using a pragma. 7686 */ 7848 */ 7687 #ifndef SQLITE_DEFAULT_RECURSIVE_TRIGGERS 7849 #ifndef SQLITE_DEFAULT_RECURSIVE_TRIGGERS ................................................................................................................................................................................ 8313 ** A sub-routine used to implement a trigger program. 8475 ** A sub-routine used to implement a trigger program. 8314 */ 8476 */ 8315 struct SubProgram { 8477 struct SubProgram { 8316 VdbeOp *aOp; /* Array of opcodes for sub-program */ 8478 VdbeOp *aOp; /* Array of opcodes for sub-program */ 8317 int nOp; /* Elements in aOp[] */ 8479 int nOp; /* Elements in aOp[] */ 8318 int nMem; /* Number of memory cells required */ 8480 int nMem; /* Number of memory cells required */ 8319 int nCsr; /* Number of cursors required */ 8481 int nCsr; /* Number of cursors required */ > 8482 int nOnce; /* Number of OP_Once instructions */ 8320 void *token; /* id that may be used to recursive triggers */ 8483 void *token; /* id that may be used to recursive triggers */ 8321 SubProgram *pNext; /* Next sub-program already visited */ 8484 SubProgram *pNext; /* Next sub-program already visited */ 8322 }; 8485 }; 8323 8486 8324 /* 8487 /* 8325 ** A smaller version of VdbeOp used for the VdbeAddOpList() function because 8488 ** A smaller version of VdbeOp used for the VdbeAddOpList() function because 8326 ** it takes up less space. 8489 ** it takes up less space. ................................................................................................................................................................................ 8559 #define OPFLG_OUT2_PRERELEASE 0x0002 /* out2-prerelease: */ 8722 #define OPFLG_OUT2_PRERELEASE 0x0002 /* out2-prerelease: */ 8560 #define OPFLG_IN1 0x0004 /* in1: P1 is an input */ 8723 #define OPFLG_IN1 0x0004 /* in1: P1 is an input */ 8561 #define OPFLG_IN2 0x0008 /* in2: P2 is an input */ 8724 #define OPFLG_IN2 0x0008 /* in2: P2 is an input */ 8562 #define OPFLG_IN3 0x0010 /* in3: P3 is an input */ 8725 #define OPFLG_IN3 0x0010 /* in3: P3 is an input */ 8563 #define OPFLG_OUT2 0x0020 /* out2: P2 is an output */ 8726 #define OPFLG_OUT2 0x0020 /* out2: P2 is an output */ 8564 #define OPFLG_OUT3 0x0040 /* out3: P3 is an output */ 8727 #define OPFLG_OUT3 0x0040 /* out3: P3 is an output */ 8565 #define OPFLG_INITIALIZER {\ 8728 #define OPFLG_INITIALIZER {\ 8566 /* 0 */ 0x00, 0x01, 0x05, 0x04, 0x04, 0x10, 0x00, 0x02,\ | 8729 /* 0 */ 0x00, 0x01, 0x01, 0x04, 0x04, 0x10, 0x00, 0x02,\ 8567 /* 8 */ 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x24, 0x24,\ 8730 /* 8 */ 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x24, 0x24,\ 8568 /* 16 */ 0x00, 0x00, 0x00, 0x24, 0x04, 0x05, 0x04, 0x00,\ 8731 /* 16 */ 0x00, 0x00, 0x00, 0x24, 0x04, 0x05, 0x04, 0x00,\ 8569 /* 24 */ 0x00, 0x01, 0x05, 0x05, 0x05, 0x00, 0x00, 0x00,\ | 8732 /* 24 */ 0x00, 0x01, 0x01, 0x05, 0x05, 0x00, 0x00, 0x00,\ 8570 /* 32 */ 0x02, 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00,\ 8733 /* 32 */ 0x02, 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00,\ 8571 /* 40 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11,\ 8734 /* 40 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11,\ 8572 /* 48 */ 0x11, 0x11, 0x08, 0x11, 0x11, 0x11, 0x11, 0x02,\ 8735 /* 48 */ 0x11, 0x11, 0x08, 0x11, 0x11, 0x11, 0x11, 0x02,\ 8573 /* 56 */ 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ 8736 /* 56 */ 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ 8574 /* 64 */ 0x00, 0x02, 0x00, 0x01, 0x4c, 0x4c, 0x01, 0x01,\ 8737 /* 64 */ 0x00, 0x02, 0x00, 0x01, 0x4c, 0x4c, 0x01, 0x01,\ 8575 /* 72 */ 0x01, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15, 0x15,\ 8738 /* 72 */ 0x01, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15, 0x15,\ 8576 /* 80 */ 0x15, 0x01, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,\ 8739 /* 80 */ 0x15, 0x01, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,\ ................................................................................................................................................................................ 8762 SQLITE_PRIVATE int sqlite3PagerReadFileheader(Pager*, int, unsigned char*); 8925 SQLITE_PRIVATE int sqlite3PagerReadFileheader(Pager*, int, unsigned char*); 8763 8926 8764 /* Functions used to configure a Pager object. */ 8927 /* Functions used to configure a Pager object. */ 8765 SQLITE_PRIVATE void sqlite3PagerSetBusyhandler(Pager*, int(*)(void *), void *); 8928 SQLITE_PRIVATE void sqlite3PagerSetBusyhandler(Pager*, int(*)(void *), void *); 8766 SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager*, u32*, int); 8929 SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager*, u32*, int); 8767 SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager*, int); 8930 SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager*, int); 8768 SQLITE_PRIVATE void sqlite3PagerSetCachesize(Pager*, int); 8931 SQLITE_PRIVATE void sqlite3PagerSetCachesize(Pager*, int); > 8932 SQLITE_PRIVATE void sqlite3PagerShrink(Pager*); 8769 SQLITE_PRIVATE void sqlite3PagerSetSafetyLevel(Pager*,int,int,int); 8933 SQLITE_PRIVATE void sqlite3PagerSetSafetyLevel(Pager*,int,int,int); 8770 SQLITE_PRIVATE int sqlite3PagerLockingMode(Pager *, int); 8934 SQLITE_PRIVATE int sqlite3PagerLockingMode(Pager *, int); 8771 SQLITE_PRIVATE int sqlite3PagerSetJournalMode(Pager *, int); 8935 SQLITE_PRIVATE int sqlite3PagerSetJournalMode(Pager *, int); 8772 SQLITE_PRIVATE int sqlite3PagerGetJournalMode(Pager*); 8936 SQLITE_PRIVATE int sqlite3PagerGetJournalMode(Pager*); 8773 SQLITE_PRIVATE int sqlite3PagerOkToChangeJournalMode(Pager*); 8937 SQLITE_PRIVATE int sqlite3PagerOkToChangeJournalMode(Pager*); 8774 SQLITE_PRIVATE i64 sqlite3PagerJournalSizeLimit(Pager *, i64); 8938 SQLITE_PRIVATE i64 sqlite3PagerJournalSizeLimit(Pager *, i64); 8775 SQLITE_PRIVATE sqlite3_backup **sqlite3PagerBackupPtr(Pager*); 8939 SQLITE_PRIVATE sqlite3_backup **sqlite3PagerBackupPtr(Pager*); ................................................................................................................................................................................ 8870 typedef struct PCache PCache; 9034 typedef struct PCache PCache; 8871 9035 8872 /* 9036 /* 8873 ** Every page in the cache is controlled by an instance of the following 9037 ** Every page in the cache is controlled by an instance of the following 8874 ** structure. 9038 ** structure. 8875 */ 9039 */ 8876 struct PgHdr { 9040 struct PgHdr { > 9041 sqlite3_pcache_page *pPage; /* Pcache object page handle */ 8877 void *pData; /* Content of this page */ | 9042 void *pData; /* Page data */ 8878 void *pExtra; /* Extra content */ 9043 void *pExtra; /* Extra content */ 8879 PgHdr *pDirty; /* Transient list of dirty pages */ 9044 PgHdr *pDirty; /* Transient list of dirty pages */ 8880 Pgno pgno; /* Page number for this page */ 9045 Pgno pgno; /* Page number for this page */ 8881 Pager *pPager; /* The pager this page is part of */ 9046 Pager *pPager; /* The pager this page is part of */ 8882 #ifdef SQLITE_CHECK_PAGES 9047 #ifdef SQLITE_CHECK_PAGES 8883 u32 pageHash; /* Hash of page content */ 9048 u32 pageHash; /* Hash of page content */ 8884 #endif 9049 #endif ................................................................................................................................................................................ 8988 ** of the suggested cache-sizes. 9153 ** of the suggested cache-sizes. 8989 */ 9154 */ 8990 SQLITE_PRIVATE void sqlite3PcacheSetCachesize(PCache *, int); 9155 SQLITE_PRIVATE void sqlite3PcacheSetCachesize(PCache *, int); 8991 #ifdef SQLITE_TEST 9156 #ifdef SQLITE_TEST 8992 SQLITE_PRIVATE int sqlite3PcacheGetCachesize(PCache *); 9157 SQLITE_PRIVATE int sqlite3PcacheGetCachesize(PCache *); 8993 #endif 9158 #endif 8994 9159 > 9160 /* Free up as much memory as possible from the page cache */ > 9161 SQLITE_PRIVATE void sqlite3PcacheShrink(PCache*); > 9162 8995 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT 9163 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT 8996 /* Try to return memory used by the pcache module to the main memory heap */ 9164 /* Try to return memory used by the pcache module to the main memory heap */ 8997 SQLITE_PRIVATE int sqlite3PcacheReleaseMemory(int); 9165 SQLITE_PRIVATE int sqlite3PcacheReleaseMemory(int); 8998 #endif 9166 #endif 8999 9167 9000 #ifdef SQLITE_TEST 9168 #ifdef SQLITE_TEST 9001 SQLITE_PRIVATE void sqlite3PcacheStats(int*,int*,int*,int*); 9169 SQLITE_PRIVATE void sqlite3PcacheStats(int*,int*,int*,int*); ................................................................................................................................................................................ 9072 # define SQLITE_OS_OS2 0 9240 # define SQLITE_OS_OS2 0 9073 # endif 9241 # endif 9074 #else 9242 #else 9075 # ifndef SQLITE_OS_WIN 9243 # ifndef SQLITE_OS_WIN 9076 # define SQLITE_OS_WIN 0 9244 # define SQLITE_OS_WIN 0 9077 # endif 9245 # endif 9078 #endif 9246 #endif 9079 < 9080 /* < 9081 ** Determine if we are dealing with WindowsCE - which has a much < 9082 ** reduced API. < 9083 */ < 9084 #if defined(_WIN32_WCE) < 9085 # define SQLITE_OS_WINCE 1 < 9086 #else < 9087 # define SQLITE_OS_WINCE 0 < 9088 #endif < 9089 < 9090 9247 9091 /* 9248 /* 9092 ** Define the maximum size of a temporary filename 9249 ** Define the maximum size of a temporary filename 9093 */ 9250 */ 9094 #if SQLITE_OS_WIN 9251 #if SQLITE_OS_WIN 9095 # include <windows.h> 9252 # include <windows.h> 9096 # define SQLITE_TEMPNAME_SIZE (MAX_PATH+50) 9253 # define SQLITE_TEMPNAME_SIZE (MAX_PATH+50) ................................................................................................................................................................................ 9108 # include <os2.h> 9265 # include <os2.h> 9109 # include <uconv.h> 9266 # include <uconv.h> 9110 # define SQLITE_TEMPNAME_SIZE (CCHMAXPATHCOMP) 9267 # define SQLITE_TEMPNAME_SIZE (CCHMAXPATHCOMP) 9111 #else 9268 #else 9112 # define SQLITE_TEMPNAME_SIZE 200 9269 # define SQLITE_TEMPNAME_SIZE 200 9113 #endif 9270 #endif 9114 9271 > 9272 /* > 9273 ** Determine if we are dealing with Windows NT. > 9274 */ > 9275 #if defined(_WIN32_WINNT) > 9276 # define SQLITE_OS_WINNT 1 > 9277 #else > 9278 # define SQLITE_OS_WINNT 0 > 9279 #endif > 9280 > 9281 /* > 9282 ** Determine if we are dealing with WindowsCE - which has a much > 9283 ** reduced API. > 9284 */ > 9285 #if defined(_WIN32_WCE) > 9286 # define SQLITE_OS_WINCE 1 > 9287 #else > 9288 # define SQLITE_OS_WINCE 0 > 9289 #endif > 9290 9115 /* If the SET_FULLSYNC macro is not defined above, then make it 9291 /* If the SET_FULLSYNC macro is not defined above, then make it 9116 ** a no-op 9292 ** a no-op 9117 */ 9293 */ 9118 #ifndef SET_FULLSYNC 9294 #ifndef SET_FULLSYNC 9119 # define SET_FULLSYNC(x,y) 9295 # define SET_FULLSYNC(x,y) 9120 #endif 9296 #endif 9121 9297 9122 /* 9298 /* 9123 ** The default size of a disk sector 9299 ** The default size of a disk sector 9124 */ 9300 */ 9125 #ifndef SQLITE_DEFAULT_SECTOR_SIZE 9301 #ifndef SQLITE_DEFAULT_SECTOR_SIZE 9126 # define SQLITE_DEFAULT_SECTOR_SIZE 512 | 9302 # define SQLITE_DEFAULT_SECTOR_SIZE 4096 9127 #endif 9303 #endif 9128 9304 9129 /* 9305 /* 9130 ** Temporary files are named starting with this prefix followed by 16 random 9306 ** Temporary files are named starting with this prefix followed by 16 random 9131 ** alphanumeric characters, and no file extension. They are stored in the 9307 ** alphanumeric characters, and no file extension. They are stored in the 9132 ** OS's standard temporary file directory, and are deleted prior to exit. 9308 ** OS's standard temporary file directory, and are deleted prior to exit. 9133 ** If sqlite is being embedded in another program, you may wish to change the 9309 ** If sqlite is being embedded in another program, you may wish to change the ................................................................................................................................................................................ 9252 SQLITE_PRIVATE int sqlite3OsTruncate(sqlite3_file*, i64 size); 9428 SQLITE_PRIVATE int sqlite3OsTruncate(sqlite3_file*, i64 size); 9253 SQLITE_PRIVATE int sqlite3OsSync(sqlite3_file*, int); 9429 SQLITE_PRIVATE int sqlite3OsSync(sqlite3_file*, int); 9254 SQLITE_PRIVATE int sqlite3OsFileSize(sqlite3_file*, i64 *pSize); 9430 SQLITE_PRIVATE int sqlite3OsFileSize(sqlite3_file*, i64 *pSize); 9255 SQLITE_PRIVATE int sqlite3OsLock(sqlite3_file*, int); 9431 SQLITE_PRIVATE int sqlite3OsLock(sqlite3_file*, int); 9256 SQLITE_PRIVATE int sqlite3OsUnlock(sqlite3_file*, int); 9432 SQLITE_PRIVATE int sqlite3OsUnlock(sqlite3_file*, int); 9257 SQLITE_PRIVATE int sqlite3OsCheckReservedLock(sqlite3_file *id, int *pResOut); 9433 SQLITE_PRIVATE int sqlite3OsCheckReservedLock(sqlite3_file *id, int *pResOut); 9258 SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file*,int,void*); 9434 SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file*,int,void*); > 9435 SQLITE_PRIVATE void sqlite3OsFileControlHint(sqlite3_file*,int,void*); 9259 #define SQLITE_FCNTL_DB_UNCHANGED 0xca093fa0 9436 #define SQLITE_FCNTL_DB_UNCHANGED 0xca093fa0 9260 SQLITE_PRIVATE int sqlite3OsSectorSize(sqlite3_file *id); 9437 SQLITE_PRIVATE int sqlite3OsSectorSize(sqlite3_file *id); 9261 SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id); 9438 SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id); 9262 SQLITE_PRIVATE int sqlite3OsShmMap(sqlite3_file *,int,int,int,void volatile **); 9439 SQLITE_PRIVATE int sqlite3OsShmMap(sqlite3_file *,int,int,int,void volatile **); 9263 SQLITE_PRIVATE int sqlite3OsShmLock(sqlite3_file *id, int, int, int); 9440 SQLITE_PRIVATE int sqlite3OsShmLock(sqlite3_file *id, int, int, int); 9264 SQLITE_PRIVATE void sqlite3OsShmBarrier(sqlite3_file *id); 9441 SQLITE_PRIVATE void sqlite3OsShmBarrier(sqlite3_file *id); 9265 SQLITE_PRIVATE int sqlite3OsShmUnmap(sqlite3_file *id, int); 9442 SQLITE_PRIVATE int sqlite3OsShmUnmap(sqlite3_file *id, int); > 9443 9266 9444 9267 /* 9445 /* 9268 ** Functions for accessing sqlite3_vfs methods 9446 ** Functions for accessing sqlite3_vfs methods 9269 */ 9447 */ 9270 SQLITE_PRIVATE int sqlite3OsOpen(sqlite3_vfs *, const char *, sqlite3_file*, int 9448 SQLITE_PRIVATE int sqlite3OsOpen(sqlite3_vfs *, const char *, sqlite3_file*, int 9271 SQLITE_PRIVATE int sqlite3OsDelete(sqlite3_vfs *, const char *, int); 9449 SQLITE_PRIVATE int sqlite3OsDelete(sqlite3_vfs *, const char *, int); 9272 SQLITE_PRIVATE int sqlite3OsAccess(sqlite3_vfs *, const char *, int, int *pResOu 9450 SQLITE_PRIVATE int sqlite3OsAccess(sqlite3_vfs *, const char *, int, int *pResOu ................................................................................................................................................................................ 9850 ** If both CollSeq.xCmp and CollSeq.xCmp16 are NULL, it means that the 10028 ** If both CollSeq.xCmp and CollSeq.xCmp16 are NULL, it means that the 9851 ** collating sequence is undefined. Indices built on an undefined 10029 ** collating sequence is undefined. Indices built on an undefined 9852 ** collating sequence may not be read or written. 10030 ** collating sequence may not be read or written. 9853 */ 10031 */ 9854 struct CollSeq { 10032 struct CollSeq { 9855 char *zName; /* Name of the collating sequence, UTF-8 encoded */ 10033 char *zName; /* Name of the collating sequence, UTF-8 encoded */ 9856 u8 enc; /* Text encoding handled by xCmp() */ 10034 u8 enc; /* Text encoding handled by xCmp() */ 9857 u8 type; /* One of the SQLITE_COLL_... values below */ < 9858 void *pUser; /* First argument to xCmp() */ 10035 void *pUser; /* First argument to xCmp() */ 9859 int (*xCmp)(void*,int, const void*, int, const void*); 10036 int (*xCmp)(void*,int, const void*, int, const void*); 9860 void (*xDel)(void*); /* Destructor for pUser */ 10037 void (*xDel)(void*); /* Destructor for pUser */ 9861 }; 10038 }; 9862 10039 9863 /* < 9864 ** Allowed values of CollSeq.type: < 9865 */ < 9866 #define SQLITE_COLL_BINARY 1 /* The default memcmp() collating sequence */ < 9867 #define SQLITE_COLL_NOCASE 2 /* The built-in NOCASE collating sequence */ < 9868 #define SQLITE_COLL_REVERSE 3 /* The built-in REVERSE collating sequence */ < 9869 #define SQLITE_COLL_USER 0 /* Any other user-defined collating sequence */ < 9870 < 9871 /* 10040 /* 9872 ** A sort order can be either ASC or DESC. 10041 ** A sort order can be either ASC or DESC. 9873 */ 10042 */ 9874 #define SQLITE_SO_ASC 0 /* Sort in ascending order */ 10043 #define SQLITE_SO_ASC 0 /* Sort in ascending order */ 9875 #define SQLITE_SO_DESC 1 /* Sort in ascending order */ 10044 #define SQLITE_SO_DESC 1 /* Sort in ascending order */ 9876 10045 9877 /* 10046 /* ................................................................................................................................................................................ 10149 ** 10318 ** 10150 ** This structure holds a record that has already been disassembled 10319 ** This structure holds a record that has already been disassembled 10151 ** into its constituent fields. 10320 ** into its constituent fields. 10152 */ 10321 */ 10153 struct UnpackedRecord { 10322 struct UnpackedRecord { 10154 KeyInfo *pKeyInfo; /* Collation and sort-order information */ 10323 KeyInfo *pKeyInfo; /* Collation and sort-order information */ 10155 u16 nField; /* Number of entries in apMem[] */ 10324 u16 nField; /* Number of entries in apMem[] */ 10156 u16 flags; /* Boolean settings. UNPACKED_... below */ | 10325 u8 flags; /* Boolean settings. UNPACKED_... below */ 10157 i64 rowid; /* Used by UNPACKED_PREFIX_SEARCH */ 10326 i64 rowid; /* Used by UNPACKED_PREFIX_SEARCH */ 10158 Mem *aMem; /* Values */ 10327 Mem *aMem; /* Values */ 10159 }; 10328 }; 10160 10329 10161 /* 10330 /* 10162 ** Allowed values of UnpackedRecord.flags 10331 ** Allowed values of UnpackedRecord.flags 10163 */ 10332 */ 10164 #define UNPACKED_NEED_FREE 0x0001 /* Memory is from sqlite3Malloc() */ < 10165 #define UNPACKED_NEED_DESTROY 0x0002 /* apMem[]s should all be destroyed */ < 10166 #define UNPACKED_IGNORE_ROWID 0x0004 /* Ignore trailing rowid on key1 */ < 10167 #define UNPACKED_INCRKEY 0x0008 /* Make this key an epsilon larger */ | 10333 #define UNPACKED_INCRKEY 0x01 /* Make this key an epsilon larger */ 10168 #define UNPACKED_PREFIX_MATCH 0x0010 /* A prefix match is considered OK */ | 10334 #define UNPACKED_PREFIX_MATCH 0x02 /* A prefix match is considered OK */ 10169 #define UNPACKED_PREFIX_SEARCH 0x0020 /* A prefix match is considered OK */ | 10335 #define UNPACKED_PREFIX_SEARCH 0x04 /* Ignore final (rowid) field */ 10170 10336 10171 /* 10337 /* 10172 ** Each SQL index is represented in memory by an 10338 ** Each SQL index is represented in memory by an 10173 ** instance of the following structure. 10339 ** instance of the following structure. 10174 ** 10340 ** 10175 ** The columns of the table that are to be indexed are described 10341 ** The columns of the table that are to be indexed are described 10176 ** by the aiColumn[] field of this structure. For example, suppose 10342 ** by the aiColumn[] field of this structure. For example, suppose ................................................................................................................................................................................ 10425 #define EP_VarSelect 0x0020 /* pSelect is correlated, not constant */ 10591 #define EP_VarSelect 0x0020 /* pSelect is correlated, not constant */ 10426 #define EP_DblQuoted 0x0040 /* token.z was originally in "..." */ 10592 #define EP_DblQuoted 0x0040 /* token.z was originally in "..." */ 10427 #define EP_InfixFunc 0x0080 /* True for an infix function: LIKE, GLOB, etc */ 10593 #define EP_InfixFunc 0x0080 /* True for an infix function: LIKE, GLOB, etc */ 10428 #define EP_ExpCollate 0x0100 /* Collating sequence specified explicitly */ 10594 #define EP_ExpCollate 0x0100 /* Collating sequence specified explicitly */ 10429 #define EP_FixedDest 0x0200 /* Result needed in a specific register */ 10595 #define EP_FixedDest 0x0200 /* Result needed in a specific register */ 10430 #define EP_IntValue 0x0400 /* Integer value contained in u.iValue */ 10596 #define EP_IntValue 0x0400 /* Integer value contained in u.iValue */ 10431 #define EP_xIsSelect 0x0800 /* x.pSelect is valid (otherwise x.pList is) */ 10597 #define EP_xIsSelect 0x0800 /* x.pSelect is valid (otherwise x.pList is) */ 10432 < > 10598 #define EP_Hint 0x1000 /* Optimizer hint. Not required for correctness */ 10433 #define EP_Reduced 0x1000 /* Expr struct is EXPR_REDUCEDSIZE bytes only */ | 10599 #define EP_Reduced 0x2000 /* Expr struct is EXPR_REDUCEDSIZE bytes only */ 10434 #define EP_TokenOnly 0x2000 /* Expr struct is EXPR_TOKENONLYSIZE bytes only */ | 10600 #define EP_TokenOnly 0x4000 /* Expr struct is EXPR_TOKENONLYSIZE bytes only */ 10435 #define EP_Static 0x4000 /* Held in memory not obtained from malloc() */ | 10601 #define EP_Static 0x8000 /* Held in memory not obtained from malloc() */ 10436 10602 10437 /* 10603 /* 10438 ** The following are the meanings of bits in the Expr.flags2 field. 10604 ** The following are the meanings of bits in the Expr.flags2 field. 10439 */ 10605 */ 10440 #define EP2_MallocedToken 0x0001 /* Need to sqlite3DbFree() Expr.zToken */ 10606 #define EP2_MallocedToken 0x0001 /* Need to sqlite3DbFree() Expr.zToken */ 10441 #define EP2_Irreducible 0x0002 /* Cannot EXPRDUP_REDUCE this Expr */ 10607 #define EP2_Irreducible 0x0002 /* Cannot EXPRDUP_REDUCE this Expr */ 10442 10608 ................................................................................................................................................................................ 10490 int iECursor; /* VDBE Cursor associated with this ExprList */ 10656 int iECursor; /* VDBE Cursor associated with this ExprList */ 10491 struct ExprList_item { 10657 struct ExprList_item { 10492 Expr *pExpr; /* The list of expressions */ 10658 Expr *pExpr; /* The list of expressions */ 10493 char *zName; /* Token associated with this expression */ 10659 char *zName; /* Token associated with this expression */ 10494 char *zSpan; /* Original text of the expression */ 10660 char *zSpan; /* Original text of the expression */ 10495 u8 sortOrder; /* 1 for DESC or 0 for ASC */ 10661 u8 sortOrder; /* 1 for DESC or 0 for ASC */ 10496 u8 done; /* A flag to indicate when processing is finished */ 10662 u8 done; /* A flag to indicate when processing is finished */ 10497 u16 iCol; /* For ORDER BY, column number in result set */ | 10663 u16 iOrderByCol; /* For ORDER BY, column number in result set */ 10498 u16 iAlias; /* Index into Parse.aAlias[] for zName */ 10664 u16 iAlias; /* Index into Parse.aAlias[] for zName */ 10499 } *a; /* One entry for each expression */ 10665 } *a; /* One entry for each expression */ 10500 }; 10666 }; 10501 10667 10502 /* 10668 /* 10503 ** An instance of this structure is used by the parser to record both 10669 ** An instance of this structure is used by the parser to record both 10504 ** the parse tree for an expression and the span of input text for an 10670 ** the parse tree for an expression and the span of input text for an ................................................................................................................................................................................ 10790 double nSelectRow; /* Estimated number of result rows */ 10956 double nSelectRow; /* Estimated number of result rows */ 10791 }; 10957 }; 10792 10958 10793 /* 10959 /* 10794 ** Allowed values for Select.selFlags. The "SF" prefix stands for 10960 ** Allowed values for Select.selFlags. The "SF" prefix stands for 10795 ** "Select Flag". 10961 ** "Select Flag". 10796 */ 10962 */ 10797 #define SF_Distinct 0x0001 /* Output should be DISTINCT */ | 10963 #define SF_Distinct 0x01 /* Output should be DISTINCT */ 10798 #define SF_Resolved 0x0002 /* Identifiers have been resolved */ | 10964 #define SF_Resolved 0x02 /* Identifiers have been resolved */ 10799 #define SF_Aggregate 0x0004 /* Contains aggregate functions */ | 10965 #define SF_Aggregate 0x04 /* Contains aggregate functions */ 10800 #define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */ | 10966 #define SF_UsesEphemeral 0x08 /* Uses the OpenEphemeral opcode */ 10801 #define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */ | 10967 #define SF_Expanded 0x10 /* sqlite3SelectExpand() called on this */ 10802 #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */ | 10968 #define SF_HasTypeInfo 0x20 /* FROM subqueries have Table metadata */ 10803 #define SF_UseSorter 0x0040 /* Sort using a sorter */ | 10969 #define SF_UseSorter 0x40 /* Sort using a sorter */ 10804 10970 10805 10971 10806 /* 10972 /* 10807 ** The results of a select can be distributed in several ways. The 10973 ** The results of a select can be distributed in several ways. The 10808 ** "SRT" prefix means "SELECT Result Type". 10974 ** "SRT" prefix means "SELECT Result Type". 10809 */ 10975 */ 10810 #define SRT_Union 1 /* Store result as keys in an index */ 10976 #define SRT_Union 1 /* Store result as keys in an index */ ................................................................................................................................................................................ 10911 */ 11077 */ 10912 struct Parse { 11078 struct Parse { 10913 sqlite3 *db; /* The main database structure */ 11079 sqlite3 *db; /* The main database structure */ 10914 int rc; /* Return code from execution */ 11080 int rc; /* Return code from execution */ 10915 char *zErrMsg; /* An error message */ 11081 char *zErrMsg; /* An error message */ 10916 Vdbe *pVdbe; /* An engine for executing database bytecode */ 11082 Vdbe *pVdbe; /* An engine for executing database bytecode */ 10917 u8 colNamesSet; /* TRUE after OP_ColumnName has been issued to pVdbe */ 11083 u8 colNamesSet; /* TRUE after OP_ColumnName has been issued to pVdbe */ 10918 u8 nameClash; /* A permanent table name clashes with temp table name */ < 10919 u8 checkSchema; /* Causes schema cookie check after an error */ 11084 u8 checkSchema; /* Causes schema cookie check after an error */ 10920 u8 nested; /* Number of nested calls to the parser/code generator */ 11085 u8 nested; /* Number of nested calls to the parser/code generator */ 10921 u8 parseError; /* True after a parsing error. Ticket #1794 */ < 10922 u8 nTempReg; /* Number of temporary registers in aTempReg[] */ 11086 u8 nTempReg; /* Number of temporary registers in aTempReg[] */ 10923 u8 nTempInUse; /* Number of aTempReg[] currently checked out */ 11087 u8 nTempInUse; /* Number of aTempReg[] currently checked out */ 10924 int aTempReg[8]; /* Holding area for temporary registers */ 11088 int aTempReg[8]; /* Holding area for temporary registers */ 10925 int nRangeReg; /* Size of the temporary register block */ 11089 int nRangeReg; /* Size of the temporary register block */ 10926 int iRangeReg; /* First register in temporary register block */ 11090 int iRangeReg; /* First register in temporary register block */ 10927 int nErr; /* Number of errors seen */ 11091 int nErr; /* Number of errors seen */ 10928 int nTab; /* Number of previously allocated VDBE cursors */ 11092 int nTab; /* Number of previously allocated VDBE cursors */ 10929 int nMem; /* Number of memory cells used so far */ 11093 int nMem; /* Number of memory cells used so far */ 10930 int nSet; /* Number of sets used so far */ 11094 int nSet; /* Number of sets used so far */ > 11095 int nOnce; /* Number of OP_Once instructions so far */ 10931 int ckBase; /* Base register of data during check constraints */ 11096 int ckBase; /* Base register of data during check constraints */ 10932 int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */ 11097 int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */ 10933 int iCacheCnt; /* Counter used to generate aColCache[].lru values */ 11098 int iCacheCnt; /* Counter used to generate aColCache[].lru values */ 10934 u8 nColCache; /* Number of entries in the column cache */ | 11099 u8 nColCache; /* Number of entries in aColCache[] */ 10935 u8 iColCache; /* Next entry of the cache to replace */ | 11100 u8 iColCache; /* Next entry in aColCache[] to replace */ 10936 struct yColCache { 11101 struct yColCache { 10937 int iTable; /* Table cursor number */ 11102 int iTable; /* Table cursor number */ 10938 int iColumn; /* Table column number */ 11103 int iColumn; /* Table column number */ 10939 u8 tempReg; /* iReg is a temp register that needs to be freed */ 11104 u8 tempReg; /* iReg is a temp register that needs to be freed */ 10940 int iLevel; /* Nesting level */ 11105 int iLevel; /* Nesting level */ 10941 int iReg; /* Reg with value of this column. 0 means none. */ 11106 int iReg; /* Reg with value of this column. 0 means none. */ 10942 int lru; /* Least recently used entry has the smallest value */ 11107 int lru; /* Least recently used entry has the smallest value */ ................................................................................................................................................................................ 10970 ** each recursion */ 11135 ** each recursion */ 10971 11136 10972 int nVar; /* Number of '?' variables seen in the SQL so far */ 11137 int nVar; /* Number of '?' variables seen in the SQL so far */ 10973 int nzVar; /* Number of available slots in azVar[] */ 11138 int nzVar; /* Number of available slots in azVar[] */ 10974 char **azVar; /* Pointers to names of parameters */ 11139 char **azVar; /* Pointers to names of parameters */ 10975 Vdbe *pReprepare; /* VM being reprepared (sqlite3Reprepare()) */ 11140 Vdbe *pReprepare; /* VM being reprepared (sqlite3Reprepare()) */ 10976 int nAlias; /* Number of aliased result set columns */ 11141 int nAlias; /* Number of aliased result set columns */ 10977 int nAliasAlloc; /* Number of allocated slots for aAlias[] */ < 10978 int *aAlias; /* Register used to hold aliased result */ 11142 int *aAlias; /* Register used to hold aliased result */ 10979 u8 explain; /* True if the EXPLAIN flag is found on the query */ 11143 u8 explain; /* True if the EXPLAIN flag is found on the query */ 10980 Token sNameToken; /* Token with unqualified schema object name */ 11144 Token sNameToken; /* Token with unqualified schema object name */ 10981 Token sLastToken; /* The last token parsed */ 11145 Token sLastToken; /* The last token parsed */ 10982 const char *zTail; /* All SQL text past the last semicolon parsed */ 11146 const char *zTail; /* All SQL text past the last semicolon parsed */ 10983 Table *pNewTable; /* A table being constructed by CREATE TABLE */ 11147 Table *pNewTable; /* A table being constructed by CREATE TABLE */ 10984 Trigger *pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */ 11148 Trigger *pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */ ................................................................................................................................................................................ 11165 int bFullMutex; /* True to enable full mutexing */ 11329 int bFullMutex; /* True to enable full mutexing */ 11166 int bOpenUri; /* True to interpret filenames as URIs */ 11330 int bOpenUri; /* True to interpret filenames as URIs */ 11167 int mxStrlen; /* Maximum string length */ 11331 int mxStrlen; /* Maximum string length */ 11168 int szLookaside; /* Default lookaside buffer size */ 11332 int szLookaside; /* Default lookaside buffer size */ 11169 int nLookaside; /* Default lookaside buffer count */ 11333 int nLookaside; /* Default lookaside buffer count */ 11170 sqlite3_mem_methods m; /* Low-level memory allocation interface */ 11334 sqlite3_mem_methods m; /* Low-level memory allocation interface */ 11171 sqlite3_mutex_methods mutex; /* Low-level mutex interface */ 11335 sqlite3_mutex_methods mutex; /* Low-level mutex interface */ 11172 sqlite3_pcache_methods pcache; /* Low-level page-cache interface */ | 11336 sqlite3_pcache_methods2 pcache2; /* Low-level page-cache interface */ 11173 void *pHeap; /* Heap storage space */ 11337 void *pHeap; /* Heap storage space */ 11174 int nHeap; /* Size of pHeap[] */ 11338 int nHeap; /* Size of pHeap[] */ 11175 int mnReq, mxReq; /* Min and max heap requests sizes */ 11339 int mnReq, mxReq; /* Min and max heap requests sizes */ 11176 void *pScratch; /* Scratch memory */ 11340 void *pScratch; /* Scratch memory */ 11177 int szScratch; /* Size of each scratch buffer */ 11341 int szScratch; /* Size of each scratch buffer */ 11178 int nScratch; /* Number of scratch buffers */ 11342 int nScratch; /* Number of scratch buffers */ 11179 void *pPage; /* Page cache memory */ 11343 void *pPage; /* Page cache memory */ ................................................................................................................................................................................ 11371 SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3*,char*,const char*,...); 11535 SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3*,char*,const char*,...); 11372 #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG) 11536 #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG) 11373 SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...); 11537 SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...); 11374 #endif 11538 #endif 11375 #if defined(SQLITE_TEST) 11539 #if defined(SQLITE_TEST) 11376 SQLITE_PRIVATE void *sqlite3TestTextToPtr(const char*); 11540 SQLITE_PRIVATE void *sqlite3TestTextToPtr(const char*); 11377 #endif 11541 #endif > 11542 > 11543 /* Output formatting for SQLITE_TESTCTRL_EXPLAIN */ > 11544 #if defined(SQLITE_ENABLE_TREE_EXPLAIN) > 11545 SQLITE_PRIVATE void sqlite3ExplainBegin(Vdbe*); > 11546 SQLITE_PRIVATE void sqlite3ExplainPrintf(Vdbe*, const char*, ...); > 11547 SQLITE_PRIVATE void sqlite3ExplainNL(Vdbe*); > 11548 SQLITE_PRIVATE void sqlite3ExplainPush(Vdbe*); > 11549 SQLITE_PRIVATE void sqlite3ExplainPop(Vdbe*); > 11550 SQLITE_PRIVATE void sqlite3ExplainFinish(Vdbe*); > 11551 SQLITE_PRIVATE void sqlite3ExplainSelect(Vdbe*, Select*); > 11552 SQLITE_PRIVATE void sqlite3ExplainExpr(Vdbe*, Expr*); > 11553 SQLITE_PRIVATE void sqlite3ExplainExprList(Vdbe*, ExprList*); > 11554 SQLITE_PRIVATE const char *sqlite3VdbeExplanation(Vdbe*); > 11555 #else > 11556 # define sqlite3ExplainBegin(X) > 11557 # define sqlite3ExplainSelect(A,B) > 11558 # define sqlite3ExplainExpr(A,B) > 11559 # define sqlite3ExplainExprList(A,B) > 11560 # define sqlite3ExplainFinish(X) > 11561 # define sqlite3VdbeExplanation(X) 0 > 11562 #endif > 11563 > 11564 11378 SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*, ...); 11565 SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*, ...); 11379 SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...); 11566 SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...); 11380 SQLITE_PRIVATE int sqlite3Dequote(char*); 11567 SQLITE_PRIVATE int sqlite3Dequote(char*); 11381 SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char*, int); 11568 SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char*, int); 11382 SQLITE_PRIVATE int sqlite3RunParser(Parse*, const char*, char **); 11569 SQLITE_PRIVATE int sqlite3RunParser(Parse*, const char*, char **); 11383 SQLITE_PRIVATE void sqlite3FinishCoding(Parse*); 11570 SQLITE_PRIVATE void sqlite3FinishCoding(Parse*); 11384 SQLITE_PRIVATE int sqlite3GetTempReg(Parse*); 11571 SQLITE_PRIVATE int sqlite3GetTempReg(Parse*); 11385 SQLITE_PRIVATE void sqlite3ReleaseTempReg(Parse*,int); 11572 SQLITE_PRIVATE void sqlite3ReleaseTempReg(Parse*,int); 11386 SQLITE_PRIVATE int sqlite3GetTempRange(Parse*,int); 11573 SQLITE_PRIVATE int sqlite3GetTempRange(Parse*,int); 11387 SQLITE_PRIVATE void sqlite3ReleaseTempRange(Parse*,int,int); 11574 SQLITE_PRIVATE void sqlite3ReleaseTempRange(Parse*,int,int); > 11575 SQLITE_PRIVATE void sqlite3ClearTempRegCache(Parse*); 11388 SQLITE_PRIVATE Expr *sqlite3ExprAlloc(sqlite3*,int,const Token*,int); 11576 SQLITE_PRIVATE Expr *sqlite3ExprAlloc(sqlite3*,int,const Token*,int); 11389 SQLITE_PRIVATE Expr *sqlite3Expr(sqlite3*,int,const char*); 11577 SQLITE_PRIVATE Expr *sqlite3Expr(sqlite3*,int,const char*); 11390 SQLITE_PRIVATE void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*); 11578 SQLITE_PRIVATE void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*); 11391 SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*); 11579 SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*); 11392 SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*); 11580 SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*); 11393 SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*); 11581 SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*); 11394 SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*); 11582 SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*); ................................................................................................................................................................................ 11412 SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*); 11600 SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*); 11413 SQLITE_PRIVATE void sqlite3AddColumnType(Parse*,Token*); 11601 SQLITE_PRIVATE void sqlite3AddColumnType(Parse*,Token*); 11414 SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,ExprSpan*); 11602 SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,ExprSpan*); 11415 SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*); 11603 SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*); 11416 SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,Select*); 11604 SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,Select*); 11417 SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*, 11605 SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*, 11418 sqlite3_vfs**,char**,char **); 11606 sqlite3_vfs**,char**,char **); > 11607 SQLITE_PRIVATE int sqlite3CodeOnce(Parse *); 11419 11608 11420 SQLITE_PRIVATE Bitvec *sqlite3BitvecCreate(u32); 11609 SQLITE_PRIVATE Bitvec *sqlite3BitvecCreate(u32); 11421 SQLITE_PRIVATE int sqlite3BitvecTest(Bitvec*, u32); 11610 SQLITE_PRIVATE int sqlite3BitvecTest(Bitvec*, u32); 11422 SQLITE_PRIVATE int sqlite3BitvecSet(Bitvec*, u32); 11611 SQLITE_PRIVATE int sqlite3BitvecSet(Bitvec*, u32); 11423 SQLITE_PRIVATE void sqlite3BitvecClear(Bitvec*, u32, void*); 11612 SQLITE_PRIVATE void sqlite3BitvecClear(Bitvec*, u32, void*); 11424 SQLITE_PRIVATE void sqlite3BitvecDestroy(Bitvec*); 11613 SQLITE_PRIVATE void sqlite3BitvecDestroy(Bitvec*); 11425 SQLITE_PRIVATE u32 sqlite3BitvecSize(Bitvec*); 11614 SQLITE_PRIVATE u32 sqlite3BitvecSize(Bitvec*); ................................................................................................................................................................................ 11750 FuncDestructor *pDestructor 11939 FuncDestructor *pDestructor 11751 ); 11940 ); 11752 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int); 11941 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int); 11753 SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *); 11942 SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *); 11754 11943 11755 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, char*, int, int); 11944 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, char*, int, int); 11756 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int); 11945 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int); > 11946 SQLITE_PRIVATE void sqlite3AppendSpace(StrAccum*,int); 11757 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*); 11947 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*); 11758 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*); 11948 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*); 11759 SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int); 11949 SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int); 11760 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int); 11950 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int); 11761 11951 11762 SQLITE_PRIVATE void sqlite3BackupRestart(sqlite3_backup *); 11952 SQLITE_PRIVATE void sqlite3BackupRestart(sqlite3_backup *); 11763 SQLITE_PRIVATE void sqlite3BackupUpdate(sqlite3_backup *, Pgno, const u8 *); 11953 SQLITE_PRIVATE void sqlite3BackupUpdate(sqlite3_backup *, Pgno, const u8 *); ................................................................................................................................................................................ 12129 SQLITE_THREADSAFE==1, /* bFullMutex */ 12319 SQLITE_THREADSAFE==1, /* bFullMutex */ 12130 SQLITE_USE_URI, /* bOpenUri */ 12320 SQLITE_USE_URI, /* bOpenUri */ 12131 0x7ffffffe, /* mxStrlen */ 12321 0x7ffffffe, /* mxStrlen */ 12132 128, /* szLookaside */ 12322 128, /* szLookaside */ 12133 500, /* nLookaside */ 12323 500, /* nLookaside */ 12134 {0,0,0,0,0,0,0,0}, /* m */ 12324 {0,0,0,0,0,0,0,0}, /* m */ 12135 {0,0,0,0,0,0,0,0,0}, /* mutex */ 12325 {0,0,0,0,0,0,0,0,0}, /* mutex */ 12136 {0,0,0,0,0,0,0,0,0,0,0}, /* pcache */ | 12326 {0,0,0,0,0,0,0,0,0,0,0,0,0},/* pcache2 */ 12137 (void*)0, /* pHeap */ 12327 (void*)0, /* pHeap */ 12138 0, /* nHeap */ 12328 0, /* nHeap */ 12139 0, 0, /* mnHeap, mxHeap */ 12329 0, 0, /* mnHeap, mxHeap */ 12140 (void*)0, /* pScratch */ 12330 (void*)0, /* pScratch */ 12141 0, /* szScratch */ 12331 0, /* szScratch */ 12142 0, /* nScratch */ 12332 0, /* nScratch */ 12143 (void*)0, /* pPage */ 12333 (void*)0, /* pPage */ ................................................................................................................................................................................ 12656 ** Boolean values 12846 ** Boolean values 12657 */ 12847 */ 12658 typedef unsigned char Bool; 12848 typedef unsigned char Bool; 12659 12849 12660 /* Opaque type used by code in vdbesort.c */ 12850 /* Opaque type used by code in vdbesort.c */ 12661 typedef struct VdbeSorter VdbeSorter; 12851 typedef struct VdbeSorter VdbeSorter; 12662 12852 > 12853 /* Opaque type used by the explainer */ > 12854 typedef struct Explain Explain; > 12855 12663 /* 12856 /* 12664 ** A cursor is a pointer into a single BTree within a database file. 12857 ** A cursor is a pointer into a single BTree within a database file. 12665 ** The cursor can seek to a BTree entry with a particular key, or 12858 ** The cursor can seek to a BTree entry with a particular key, or 12666 ** loop over all entries of the Btree. You can also insert new BTree 12859 ** loop over all entries of the Btree. You can also insert new BTree 12667 ** entries or retrieve the key or data from the entry that the cursor 12860 ** entries or retrieve the key or data from the entry that the cursor 12668 ** is currently pointing to. 12861 ** is currently pointing to. 12669 ** 12862 ** ................................................................................................................................................................................ 12740 struct VdbeFrame { 12933 struct VdbeFrame { 12741 Vdbe *v; /* VM this frame belongs to */ 12934 Vdbe *v; /* VM this frame belongs to */ 12742 int pc; /* Program Counter in parent (calling) frame */ 12935 int pc; /* Program Counter in parent (calling) frame */ 12743 Op *aOp; /* Program instructions for parent frame */ 12936 Op *aOp; /* Program instructions for parent frame */ 12744 int nOp; /* Size of aOp array */ 12937 int nOp; /* Size of aOp array */ 12745 Mem *aMem; /* Array of memory cells for parent frame */ 12938 Mem *aMem; /* Array of memory cells for parent frame */ 12746 int nMem; /* Number of entries in aMem */ 12939 int nMem; /* Number of entries in aMem */ > 12940 u8 *aOnceFlag; /* Array of OP_Once flags for parent frame */ > 12941 int nOnceFlag; /* Number of entries in aOnceFlag */ 12747 VdbeCursor **apCsr; /* Array of Vdbe cursors for parent frame */ 12942 VdbeCursor **apCsr; /* Array of Vdbe cursors for parent frame */ 12748 u16 nCursor; /* Number of entries in apCsr */ 12943 u16 nCursor; /* Number of entries in apCsr */ 12749 void *token; /* Copy of SubProgram.token */ 12944 void *token; /* Copy of SubProgram.token */ 12750 int nChildMem; /* Number of memory cells for child frame */ 12945 int nChildMem; /* Number of memory cells for child frame */ 12751 int nChildCsr; /* Number of cursors for child frame */ 12946 int nChildCsr; /* Number of cursors for child frame */ 12752 i64 lastRowid; /* Last insert rowid (sqlite3.lastRowid) */ 12947 i64 lastRowid; /* Last insert rowid (sqlite3.lastRowid) */ 12753 int nChange; /* Statement changes (Vdbe.nChanges) */ 12948 int nChange; /* Statement changes (Vdbe.nChanges) */ ................................................................................................................................................................................ 12878 VdbeFunc *pVdbeFunc; /* Auxilary data, if created. */ 13073 VdbeFunc *pVdbeFunc; /* Auxilary data, if created. */ 12879 Mem s; /* The return value is stored here */ 13074 Mem s; /* The return value is stored here */ 12880 Mem *pMem; /* Memory cell used to store aggregate context */ 13075 Mem *pMem; /* Memory cell used to store aggregate context */ 12881 int isError; /* Error code returned by the function. */ 13076 int isError; /* Error code returned by the function. */ 12882 CollSeq *pColl; /* Collating sequence */ 13077 CollSeq *pColl; /* Collating sequence */ 12883 }; 13078 }; 12884 13079 > 13080 /* > 13081 ** An Explain object accumulates indented output which is helpful > 13082 ** in describing recursive data structures. > 13083 */ > 13084 struct Explain { > 13085 Vdbe *pVdbe; /* Attach the explanation to this Vdbe */ > 13086 StrAccum str; /* The string being accumulated */ > 13087 int nIndent; /* Number of elements in aIndent */ > 13088 u16 aIndent[100]; /* Levels of indentation */ > 13089 char zBase[100]; /* Initial space */ > 13090 }; > 13091 12885 /* 13092 /* 12886 ** An instance of the virtual machine. This structure contains the complete 13093 ** An instance of the virtual machine. This structure contains the complete 12887 ** state of the virtual machine. 13094 ** state of the virtual machine. 12888 ** 13095 ** 12889 ** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare() 13096 ** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare() 12890 ** is really a pointer to an instance of this structure. 13097 ** is really a pointer to an instance of this structure. 12891 ** 13098 ** ................................................................................................................................................................................ 12944 i64 nFkConstraint; /* Number of imm. FK constraints this VM */ 13151 i64 nFkConstraint; /* Number of imm. FK constraints this VM */ 12945 i64 nStmtDefCons; /* Number of def. constraints when stmt started */ 13152 i64 nStmtDefCons; /* Number of def. constraints when stmt started */ 12946 char *zSql; /* Text of the SQL statement that generated this */ 13153 char *zSql; /* Text of the SQL statement that generated this */ 12947 void *pFree; /* Free this when deleting the vdbe */ 13154 void *pFree; /* Free this when deleting the vdbe */ 12948 #ifdef SQLITE_DEBUG 13155 #ifdef SQLITE_DEBUG 12949 FILE *trace; /* Write an execution trace here, if not NULL */ 13156 FILE *trace; /* Write an execution trace here, if not NULL */ 12950 #endif 13157 #endif > 13158 #ifdef SQLITE_ENABLE_TREE_EXPLAIN > 13159 Explain *pExplain; /* The explainer */ > 13160 char *zExplain; /* Explanation of data structures */ > 13161 #endif 12951 VdbeFrame *pFrame; /* Parent frame */ 13162 VdbeFrame *pFrame; /* Parent frame */ 12952 VdbeFrame *pDelFrame; /* List of frame objects to free on VM reset */ 13163 VdbeFrame *pDelFrame; /* List of frame objects to free on VM reset */ 12953 int nFrame; /* Number of frames in pFrame list */ 13164 int nFrame; /* Number of frames in pFrame list */ 12954 u32 expmask; /* Binding to these vars invalidates VM */ 13165 u32 expmask; /* Binding to these vars invalidates VM */ 12955 SubProgram *pProgram; /* Linked list of all sub-programs used by VM */ 13166 SubProgram *pProgram; /* Linked list of all sub-programs used by VM */ > 13167 int nOnceFlag; /* Size of array aOnceFlag[] */ > 13168 u8 *aOnceFlag; /* Flags for OP_Once */ 12956 }; 13169 }; 12957 13170 12958 /* 13171 /* 12959 ** The following are allowed values for Vdbe.magic 13172 ** The following are allowed values for Vdbe.magic 12960 */ 13173 */ 12961 #define VDBE_MAGIC_INIT 0x26bceaa5 /* Building a VDBE program */ 13174 #define VDBE_MAGIC_INIT 0x26bceaa5 /* Building a VDBE program */ 12962 #define VDBE_MAGIC_RUN 0xbdf20da3 /* VDBE is ready to execute */ 13175 #define VDBE_MAGIC_RUN 0xbdf20da3 /* VDBE is ready to execute */ ................................................................................................................................................................................ 13008 SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*); 13221 SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*); 13009 SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*); 13222 SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*); 13010 SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*); 13223 SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*); 13011 SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*); 13224 SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*); 13012 SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,int,int,int,Mem*); 13225 SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,int,int,int,Mem*); 13013 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p); 13226 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p); 13014 SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p); 13227 SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p); 13015 #define MemReleaseExt(X) \ | 13228 #define VdbeMemRelease(X) \ 13016 if((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame)) \ 13229 if((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame)) \ 13017 sqlite3VdbeMemReleaseExternal(X); 13230 sqlite3VdbeMemReleaseExternal(X); 13018 SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*); 13231 SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*); 13019 SQLITE_PRIVATE const char *sqlite3OpcodeName(int); 13232 SQLITE_PRIVATE const char *sqlite3OpcodeName(int); 13020 SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve); 13233 SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve); 13021 SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int); 13234 SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int); 13022 SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*); 13235 SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*); ................................................................................................................................................................................ 13047 SQLITE_PRIVATE void sqlite3VdbeLeave(Vdbe*); 13260 SQLITE_PRIVATE void sqlite3VdbeLeave(Vdbe*); 13048 #else 13261 #else 13049 # define sqlite3VdbeEnter(X) 13262 # define sqlite3VdbeEnter(X) 13050 # define sqlite3VdbeLeave(X) 13263 # define sqlite3VdbeLeave(X) 13051 #endif 13264 #endif 13052 13265 13053 #ifdef SQLITE_DEBUG 13266 #ifdef SQLITE_DEBUG 13054 SQLITE_PRIVATE void sqlite3VdbeMemPrepareToChange(Vdbe*,Mem*); | 13267 SQLITE_PRIVATE void sqlite3VdbeMemAboutToChange(Vdbe*,Mem*); 13055 #endif 13268 #endif 13056 13269 13057 #ifndef SQLITE_OMIT_FOREIGN_KEY 13270 #ifndef SQLITE_OMIT_FOREIGN_KEY 13058 SQLITE_PRIVATE int sqlite3VdbeCheckFk(Vdbe *, int); 13271 SQLITE_PRIVATE int sqlite3VdbeCheckFk(Vdbe *, int); 13059 #else 13272 #else 13060 # define sqlite3VdbeCheckFk(p,i) 0 13273 # define sqlite3VdbeCheckFk(p,i) 0 13061 #endif 13274 #endif ................................................................................................................................................................................ 13065 SQLITE_PRIVATE void sqlite3VdbePrintSql(Vdbe*); 13278 SQLITE_PRIVATE void sqlite3VdbePrintSql(Vdbe*); 13066 SQLITE_PRIVATE void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf); 13279 SQLITE_PRIVATE void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf); 13067 #endif 13280 #endif 13068 SQLITE_PRIVATE int sqlite3VdbeMemHandleBom(Mem *pMem); 13281 SQLITE_PRIVATE int sqlite3VdbeMemHandleBom(Mem *pMem); 13069 13282 13070 #ifndef SQLITE_OMIT_INCRBLOB 13283 #ifndef SQLITE_OMIT_INCRBLOB 13071 SQLITE_PRIVATE int sqlite3VdbeMemExpandBlob(Mem *); 13284 SQLITE_PRIVATE int sqlite3VdbeMemExpandBlob(Mem *); > 13285 #define ExpandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0) 13072 #else 13286 #else 13073 #define sqlite3VdbeMemExpandBlob(x) SQLITE_OK 13287 #define sqlite3VdbeMemExpandBlob(x) SQLITE_OK > 13288 #define ExpandBlob(P) SQLITE_OK 13074 #endif 13289 #endif 13075 13290 13076 #endif /* !defined(_VDBEINT_H_) */ 13291 #endif /* !defined(_VDBEINT_H_) */ 13077 13292 13078 /************** End of vdbeInt.h *********************************************/ 13293 /************** End of vdbeInt.h *********************************************/ 13079 /************** Continuing where we left off in status.c *********************/ 13294 /************** Continuing where we left off in status.c *********************/ 13080 13295 ................................................................................................................................................................................ 14466 ** from within OsOpen()), but some third-party implementations may. 14681 ** from within OsOpen()), but some third-party implementations may. 14467 ** So we test the effects of a malloc() failing and the sqlite3OsXXX() 14682 ** So we test the effects of a malloc() failing and the sqlite3OsXXX() 14468 ** function returning SQLITE_IOERR_NOMEM using the DO_OS_MALLOC_TEST macro. 14683 ** function returning SQLITE_IOERR_NOMEM using the DO_OS_MALLOC_TEST macro. 14469 ** 14684 ** 14470 ** The following functions are instrumented for malloc() failure 14685 ** The following functions are instrumented for malloc() failure 14471 ** testing: 14686 ** testing: 14472 ** 14687 ** 14473 ** sqlite3OsOpen() < 14474 ** sqlite3OsRead() 14688 ** sqlite3OsRead() 14475 ** sqlite3OsWrite() 14689 ** sqlite3OsWrite() 14476 ** sqlite3OsSync() 14690 ** sqlite3OsSync() > 14691 ** sqlite3OsFileSize() 14477 ** sqlite3OsLock() 14692 ** sqlite3OsLock() > 14693 ** sqlite3OsCheckReservedLock() > 14694 ** sqlite3OsFileControl() > 14695 ** sqlite3OsShmMap() > 14696 ** sqlite3OsOpen() > 14697 ** sqlite3OsDelete() > 14698 ** sqlite3OsAccess() > 14699 ** sqlite3OsFullPathname() 14478 ** 14700 ** 14479 */ 14701 */ 14480 #if defined(SQLITE_TEST) 14702 #if defined(SQLITE_TEST) 14481 SQLITE_API int sqlite3_memdebug_vfs_oom_test = 1; 14703 SQLITE_API int sqlite3_memdebug_vfs_oom_test = 1; 14482 #define DO_OS_MALLOC_TEST(x) \ 14704 #define DO_OS_MALLOC_TEST(x) \ 14483 if (sqlite3_memdebug_vfs_oom_test && (!x || !sqlite3IsMemJournal(x))) { \ 14705 if (sqlite3_memdebug_vfs_oom_test && (!x || !sqlite3IsMemJournal(x))) { \ 14484 void *pTstAlloc = sqlite3Malloc(10); \ 14706 void *pTstAlloc = sqlite3Malloc(10); \ ................................................................................................................................................................................ 14529 SQLITE_PRIVATE int sqlite3OsUnlock(sqlite3_file *id, int lockType){ 14751 SQLITE_PRIVATE int sqlite3OsUnlock(sqlite3_file *id, int lockType){ 14530 return id->pMethods->xUnlock(id, lockType); 14752 return id->pMethods->xUnlock(id, lockType); 14531 } 14753 } 14532 SQLITE_PRIVATE int sqlite3OsCheckReservedLock(sqlite3_file *id, int *pResOut){ 14754 SQLITE_PRIVATE int sqlite3OsCheckReservedLock(sqlite3_file *id, int *pResOut){ 14533 DO_OS_MALLOC_TEST(id); 14755 DO_OS_MALLOC_TEST(id); 14534 return id->pMethods->xCheckReservedLock(id, pResOut); 14756 return id->pMethods->xCheckReservedLock(id, pResOut); 14535 } 14757 } > 14758 > 14759 /* > 14760 ** Use sqlite3OsFileControl() when we are doing something that might fail > 14761 ** and we need to know about the failures. Use sqlite3OsFileControlHint() > 14762 ** when simply tossing information over the wall to the VFS and we do not > 14763 ** really care if the VFS receives and understands the information since it > 14764 ** is only a hint and can be safely ignored. The sqlite3OsFileControlHint() > 14765 ** routine has no return value since the return value would be meaningless. > 14766 */ 14536 SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file *id, int op, void *pArg){ 14767 SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file *id, int op, void *pArg){ > 14768 DO_OS_MALLOC_TEST(id); 14537 return id->pMethods->xFileControl(id, op, pArg); 14769 return id->pMethods->xFileControl(id, op, pArg); 14538 } 14770 } > 14771 SQLITE_PRIVATE void sqlite3OsFileControlHint(sqlite3_file *id, int op, void *pAr > 14772 (void)id->pMethods->xFileControl(id, op, pArg); > 14773 } > 14774 14539 SQLITE_PRIVATE int sqlite3OsSectorSize(sqlite3_file *id){ 14775 SQLITE_PRIVATE int sqlite3OsSectorSize(sqlite3_file *id){ 14540 int (*xSectorSize)(sqlite3_file*) = id->pMethods->xSectorSize; 14776 int (*xSectorSize)(sqlite3_file*) = id->pMethods->xSectorSize; 14541 return (xSectorSize ? xSectorSize(id) : SQLITE_DEFAULT_SECTOR_SIZE); 14777 return (xSectorSize ? xSectorSize(id) : SQLITE_DEFAULT_SECTOR_SIZE); 14542 } 14778 } 14543 SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id){ 14779 SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id){ 14544 return id->pMethods->xDeviceCharacteristics(id); 14780 return id->pMethods->xDeviceCharacteristics(id); 14545 } 14781 } ................................................................................................................................................................................ 14555 SQLITE_PRIVATE int sqlite3OsShmMap( 14791 SQLITE_PRIVATE int sqlite3OsShmMap( 14556 sqlite3_file *id, /* Database file handle */ 14792 sqlite3_file *id, /* Database file handle */ 14557 int iPage, 14793 int iPage, 14558 int pgsz, 14794 int pgsz, 14559 int bExtend, /* True to extend file if necessary */ 14795 int bExtend, /* True to extend file if necessary */ 14560 void volatile **pp /* OUT: Pointer to mapping */ 14796 void volatile **pp /* OUT: Pointer to mapping */ 14561 ){ 14797 ){ > 14798 DO_OS_MALLOC_TEST(id); 14562 return id->pMethods->xShmMap(id, iPage, pgsz, bExtend, pp); 14799 return id->pMethods->xShmMap(id, iPage, pgsz, bExtend, pp); 14563 } 14800 } 14564 14801 14565 /* 14802 /* 14566 ** The next group of routines are convenience wrappers around the 14803 ** The next group of routines are convenience wrappers around the 14567 ** VFS methods. 14804 ** VFS methods. 14568 */ 14805 */ ................................................................................................................................................................................ 14571 const char *zPath, 14808 const char *zPath, 14572 sqlite3_file *pFile, 14809 sqlite3_file *pFile, 14573 int flags, 14810 int flags, 14574 int *pFlagsOut 14811 int *pFlagsOut 14575 ){ 14812 ){ 14576 int rc; 14813 int rc; 14577 DO_OS_MALLOC_TEST(0); 14814 DO_OS_MALLOC_TEST(0); 14578 /* 0x87f3f is a mask of SQLITE_OPEN_ flags that are valid to be passed | 14815 /* 0x87f7f is a mask of SQLITE_OPEN_ flags that are valid to be passed 14579 ** down into the VFS layer. Some SQLITE_OPEN_ flags (for example, 14816 ** down into the VFS layer. Some SQLITE_OPEN_ flags (for example, 14580 ** SQLITE_OPEN_FULLMUTEX or SQLITE_OPEN_SHAREDCACHE) are blocked before 14817 ** SQLITE_OPEN_FULLMUTEX or SQLITE_OPEN_SHAREDCACHE) are blocked before 14581 ** reaching the VFS. */ 14818 ** reaching the VFS. */ 14582 rc = pVfs->xOpen(pVfs, zPath, pFile, flags & 0x87f7f, pFlagsOut); 14819 rc = pVfs->xOpen(pVfs, zPath, pFile, flags & 0x87f7f, pFlagsOut); 14583 assert( rc==SQLITE_OK || pFile->pMethods==0 ); 14820 assert( rc==SQLITE_OK || pFile->pMethods==0 ); 14584 return rc; 14821 return rc; 14585 } 14822 } 14586 SQLITE_PRIVATE int sqlite3OsDelete(sqlite3_vfs *pVfs, const char *zPath, int dir 14823 SQLITE_PRIVATE int sqlite3OsDelete(sqlite3_vfs *pVfs, const char *zPath, int dir > 14824 DO_OS_MALLOC_TEST(0); > 14825 assert( dirSync==0 || dirSync==1 ); 14587 return pVfs->xDelete(pVfs, zPath, dirSync); 14826 return pVfs->xDelete(pVfs, zPath, dirSync); 14588 } 14827 } 14589 SQLITE_PRIVATE int sqlite3OsAccess( 14828 SQLITE_PRIVATE int sqlite3OsAccess( 14590 sqlite3_vfs *pVfs, 14829 sqlite3_vfs *pVfs, 14591 const char *zPath, 14830 const char *zPath, 14592 int flags, 14831 int flags, 14593 int *pResOut 14832 int *pResOut ................................................................................................................................................................................ 14597 } 14836 } 14598 SQLITE_PRIVATE int sqlite3OsFullPathname( 14837 SQLITE_PRIVATE int sqlite3OsFullPathname( 14599 sqlite3_vfs *pVfs, 14838 sqlite3_vfs *pVfs, 14600 const char *zPath, 14839 const char *zPath, 14601 int nPathOut, 14840 int nPathOut, 14602 char *zPathOut 14841 char *zPathOut 14603 ){ 14842 ){ > 14843 DO_OS_MALLOC_TEST(0); 14604 zPathOut[0] = 0; 14844 zPathOut[0] = 0; 14605 return pVfs->xFullPathname(pVfs, zPath, nPathOut, zPathOut); 14845 return pVfs->xFullPathname(pVfs, zPath, nPathOut, zPathOut); 14606 } 14846 } 14607 #ifndef SQLITE_OMIT_LOAD_EXTENSION 14847 #ifndef SQLITE_OMIT_LOAD_EXTENSION 14608 SQLITE_PRIVATE void *sqlite3OsDlOpen(sqlite3_vfs *pVfs, const char *zPath){ 14848 SQLITE_PRIVATE void *sqlite3OsDlOpen(sqlite3_vfs *pVfs, const char *zPath){ 14609 return pVfs->xDlOpen(pVfs, zPath); 14849 return pVfs->xDlOpen(pVfs, zPath); 14610 } 14850 } ................................................................................................................................................................................ 14948 /* 15188 /* 14949 ** This version of the memory allocator is the default. It is 15189 ** This version of the memory allocator is the default. It is 14950 ** used when no other memory allocator is specified using compile-time 15190 ** used when no other memory allocator is specified using compile-time 14951 ** macros. 15191 ** macros. 14952 */ 15192 */ 14953 #ifdef SQLITE_SYSTEM_MALLOC 15193 #ifdef SQLITE_SYSTEM_MALLOC 14954 15194 > 15195 /* > 15196 ** Windows systems have malloc_usable_size() but it is called _msize() > 15197 #if !defined(HAVE_MALLOC_USABLE_SIZE) && SQLITE_OS_WIN > 15198 # define HAVE_MALLOC_USABLE_SIZE 1 > 15199 # define malloc_usable_size _msize > 15200 #endif > 15201 */ > 15202 > 15203 #if defined(__APPLE__) > 15204 > 15205 /* > 15206 ** Use the zone allocator available on apple products > 15207 */ > 15208 #include <sys/sysctl.h> > 15209 #include <malloc/malloc.h> > 15210 #include <libkern/OSAtomic.h> > 15211 static malloc_zone_t* _sqliteZone_; > 15212 #define SQLITE_MALLOC(x) malloc_zone_malloc(_sqliteZone_, (x)) > 15213 #define SQLITE_FREE(x) malloc_zone_free(_sqliteZone_, (x)); > 15214 #define SQLITE_REALLOC(x,y) malloc_zone_realloc(_sqliteZone_, (x), (y)) > 15215 #define SQLITE_MALLOCSIZE(x) \ > 15216 (_sqliteZone_ ? _sqliteZone_->size(_sqliteZone_,x) : malloc_size(x)) > 15217 > 15218 #else /* if not __APPLE__ */ > 15219 > 15220 /* > 15221 ** Use standard C library malloc and free on non-Apple systems. > 15222 */ > 15223 #define SQLITE_MALLOC(x) malloc(x) > 15224 #define SQLITE_FREE(x) free(x) > 15225 #define SQLITE_REALLOC(x,y) realloc((x),(y)) > 15226 > 15227 #ifdef HAVE_MALLOC_USABLE_SIZE > 15228 #include <malloc.h> > 15229 #define SQLITE_MALLOCSIZE(x) malloc_usable_size(x) > 15230 #else > 15231 #undef SQLITE_MALLOCSIZE > 15232 #endif > 15233 > 15234 #endif /* __APPLE__ or not __APPLE__ */ > 15235 14955 /* 15236 /* 14956 ** Like malloc(), but remember the size of the allocation 15237 ** Like malloc(), but remember the size of the allocation 14957 ** so that we can find it later using sqlite3MemSize(). 15238 ** so that we can find it later using sqlite3MemSize(). 14958 ** 15239 ** 14959 ** For this low-level routine, we are guaranteed that nByte>0 because 15240 ** For this low-level routine, we are guaranteed that nByte>0 because 14960 ** cases of nByte<=0 will be intercepted and dealt with by higher level 15241 ** cases of nByte<=0 will be intercepted and dealt with by higher level 14961 ** routines. 15242 ** routines. 14962 */ 15243 */ 14963 static void *sqlite3MemMalloc(int nByte){ 15244 static void *sqlite3MemMalloc(int nByte){ > 15245 #ifdef SQLITE_MALLOCSIZE > 15246 void *p = SQLITE_MALLOC( nByte ); > 15247 if( p==0 ){ > 15248 testcase( sqlite3GlobalConfig.xLog!=0 ); > 15249 sqlite3_log(SQLITE_NOMEM, "failed to allocate %u bytes of memory", nByte); > 15250 } > 15251 return p; > 15252 #else 14964 sqlite3_int64 *p; 15253 sqlite3_int64 *p; 14965 assert( nByte>0 ); 15254 assert( nByte>0 ); 14966 nByte = ROUND8(nByte); 15255 nByte = ROUND8(nByte); 14967 p = malloc( nByte+8 ); | 15256 p = SQLITE_MALLOC( nByte+8 ); 14968 if( p ){ 15257 if( p ){ 14969 p[0] = nByte; 15258 p[0] = nByte; 14970 p++; 15259 p++; 14971 }else{ 15260 }else{ 14972 testcase( sqlite3GlobalConfig.xLog!=0 ); 15261 testcase( sqlite3GlobalConfig.xLog!=0 ); 14973 sqlite3_log(SQLITE_NOMEM, "failed to allocate %u bytes of memory", nByte); 15262 sqlite3_log(SQLITE_NOMEM, "failed to allocate %u bytes of memory", nByte); 14974 } 15263 } 14975 return (void *)p; 15264 return (void *)p; > 15265 #endif 14976 } 15266 } 14977 15267 14978 /* 15268 /* 14979 ** Like free() but works for allocations obtained from sqlite3MemMalloc() 15269 ** Like free() but works for allocations obtained from sqlite3MemMalloc() 14980 ** or sqlite3MemRealloc(). 15270 ** or sqlite3MemRealloc(). 14981 ** 15271 ** 14982 ** For this low-level routine, we already know that pPrior!=0 since 15272 ** For this low-level routine, we already know that pPrior!=0 since 14983 ** cases where pPrior==0 will have been intecepted and dealt with 15273 ** cases where pPrior==0 will have been intecepted and dealt with 14984 ** by higher-level routines. 15274 ** by higher-level routines. 14985 */ 15275 */ 14986 static void sqlite3MemFree(void *pPrior){ 15276 static void sqlite3MemFree(void *pPrior){ > 15277 #ifdef SQLITE_MALLOCSIZE > 15278 SQLITE_FREE(pPrior); > 15279 #else 14987 sqlite3_int64 *p = (sqlite3_int64*)pPrior; 15280 sqlite3_int64 *p = (sqlite3_int64*)pPrior; 14988 assert( pPrior!=0 ); 15281 assert( pPrior!=0 ); 14989 p--; 15282 p--; 14990 free(p); | 15283 SQLITE_FREE(p); > 15284 #endif 14991 } 15285 } 14992 15286 14993 /* 15287 /* 14994 ** Report the allocated size of a prior return from xMalloc() 15288 ** Report the allocated size of a prior return from xMalloc() 14995 ** or xRealloc(). 15289 ** or xRealloc(). 14996 */ 15290 */ 14997 static int sqlite3MemSize(void *pPrior){ 15291 static int sqlite3MemSize(void *pPrior){ > 15292 #ifdef SQLITE_MALLOCSIZE > 15293 return pPrior ? (int)SQLITE_MALLOCSIZE(pPrior) : 0; > 15294 #else 14998 sqlite3_int64 *p; 15295 sqlite3_int64 *p; 14999 if( pPrior==0 ) return 0; 15296 if( pPrior==0 ) return 0; 15000 p = (sqlite3_int64*)pPrior; 15297 p = (sqlite3_int64*)pPrior; 15001 p--; 15298 p--; 15002 return (int)p[0]; 15299 return (int)p[0]; > 15300 #endif 15003 } 15301 } 15004 15302 15005 /* 15303 /* 15006 ** Like realloc(). Resize an allocation previously obtained from 15304 ** Like realloc(). Resize an allocation previously obtained from 15007 ** sqlite3MemMalloc(). 15305 ** sqlite3MemMalloc(). 15008 ** 15306 ** 15009 ** For this low-level interface, we know that pPrior!=0. Cases where 15307 ** For this low-level interface, we know that pPrior!=0. Cases where 15010 ** pPrior==0 while have been intercepted by higher-level routine and 15308 ** pPrior==0 while have been intercepted by higher-level routine and 15011 ** redirected to xMalloc. Similarly, we know that nByte>0 becauses 15309 ** redirected to xMalloc. Similarly, we know that nByte>0 becauses 15012 ** cases where nByte<=0 will have been intercepted by higher-level 15310 ** cases where nByte<=0 will have been intercepted by higher-level 15013 ** routines and redirected to xFree. 15311 ** routines and redirected to xFree. 15014 */ 15312 */ 15015 static void *sqlite3MemRealloc(void *pPrior, int nByte){ 15313 static void *sqlite3MemRealloc(void *pPrior, int nByte){ > 15314 #ifdef SQLITE_MALLOCSIZE > 15315 void *p = SQLITE_REALLOC(pPrior, nByte); > 15316 if( p==0 ){ > 15317 testcase( sqlite3GlobalConfig.xLog!=0 ); > 15318 sqlite3_log(SQLITE_NOMEM, > 15319 "failed memory resize %u to %u bytes", > 15320 SQLITE_MALLOCSIZE(pPrior), nByte); > 15321 } > 15322 return p; > 15323 #else 15016 sqlite3_int64 *p = (sqlite3_int64*)pPrior; 15324 sqlite3_int64 *p = (sqlite3_int64*)pPrior; 15017 assert( pPrior!=0 && nByte>0 ); 15325 assert( pPrior!=0 && nByte>0 ); 15018 assert( nByte==ROUND8(nByte) ); /* EV: R-46199-30249 */ 15326 assert( nByte==ROUND8(nByte) ); /* EV: R-46199-30249 */ 15019 p--; 15327 p--; 15020 p = realloc(p, nByte+8 ); | 15328 p = SQLITE_REALLOC(p, nByte+8 ); 15021 if( p ){ 15329 if( p ){ 15022 p[0] = nByte; 15330 p[0] = nByte; 15023 p++; 15331 p++; 15024 }else{ 15332 }else{ 15025 testcase( sqlite3GlobalConfig.xLog!=0 ); 15333 testcase( sqlite3GlobalConfig.xLog!=0 ); 15026 sqlite3_log(SQLITE_NOMEM, 15334 sqlite3_log(SQLITE_NOMEM, 15027 "failed memory resize %u to %u bytes", 15335 "failed memory resize %u to %u bytes", 15028 sqlite3MemSize(pPrior), nByte); 15336 sqlite3MemSize(pPrior), nByte); 15029 } 15337 } 15030 return (void*)p; 15338 return (void*)p; > 15339 #endif 15031 } 15340 } 15032 15341 15033 /* 15342 /* 15034 ** Round up a request size to the next valid allocation size. 15343 ** Round up a request size to the next valid allocation size. 15035 */ 15344 */ 15036 static int sqlite3MemRoundup(int n){ 15345 static int sqlite3MemRoundup(int n){ 15037 return ROUND8(n); 15346 return ROUND8(n); 15038 } 15347 } 15039 15348 15040 /* 15349 /* 15041 ** Initialize this module. 15350 ** Initialize this module. 15042 */ 15351 */ 15043 static int sqlite3MemInit(void *NotUsed){ 15352 static int sqlite3MemInit(void *NotUsed){ > 15353 #if defined(__APPLE__) > 15354 int cpuCount; > 15355 size_t len; > 15356 if( _sqliteZone_ ){ > 15357 return SQLITE_OK; > 15358 } > 15359 len = sizeof(cpuCount); > 15360 /* One usually wants to use hw.acctivecpu for MT decisions, but not here */ > 15361 sysctlbyname("hw.ncpu", &cpuCount, &len, NULL, 0); > 15362 if( cpuCount>1 ){ > 15363 /* defer MT decisions to system malloc */ > 15364 _sqliteZone_ = malloc_default_zone(); > 15365 }else{ > 15366 /* only 1 core, use our own zone to contention over global locks, > 15367 ** e.g. we have our own dedicated locks */ > 15368 bool success; > 15369 malloc_zone_t* newzone = malloc_create_zone(4096, 0); > 15370 malloc_set_zone_name(newzone, "Sqlite_Heap"); > 15371 do{ > 15372 success = OSAtomicCompareAndSwapPtrBarrier(NULL, newzone, > 15373 (void * volatile *)&_sqliteZone_); > 15374 }while(!_sqliteZone_); > 15375 if( !success ){ > 15376 /* somebody registered a zone first */ > 15377 malloc_destroy_zone(newzone); > 15378 } > 15379 } > 15380 #endif 15044 UNUSED_PARAMETER(NotUsed); 15381 UNUSED_PARAMETER(NotUsed); 15045 return SQLITE_OK; 15382 return SQLITE_OK; 15046 } 15383 } 15047 15384 15048 /* 15385 /* 15049 ** Deinitialize this module. 15386 ** Deinitialize this module. 15050 */ 15387 */ ................................................................................................................................................................................ 17026 return p==0 || sqlite3GlobalConfig.mutex.xMutexHeld(p); 17363 return p==0 || sqlite3GlobalConfig.mutex.xMutexHeld(p); 17027 } 17364 } 17028 SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex *p){ 17365 SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex *p){ 17029 return p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld(p); 17366 return p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld(p); 17030 } 17367 } 17031 #endif 17368 #endif 17032 17369 17033 #endif /* SQLITE_MUTEX_OMIT */ | 17370 #endif /* !defined(SQLITE_MUTEX_OMIT) */ 17034 17371 17035 /************** End of mutex.c ***********************************************/ 17372 /************** End of mutex.c ***********************************************/ 17036 /************** Begin file mutex_noop.c **************************************/ 17373 /************** Begin file mutex_noop.c **************************************/ 17037 /* 17374 /* 17038 ** 2008 October 07 17375 ** 2008 October 07 17039 ** 17376 ** 17040 ** The author disclaims copyright to this source code. In place of 17377 ** The author disclaims copyright to this source code. In place of ................................................................................................................................................................................ 17233 ** If compiled with SQLITE_MUTEX_NOOP, then the no-op mutex implementation 17570 ** If compiled with SQLITE_MUTEX_NOOP, then the no-op mutex implementation 17234 ** is used regardless of the run-time threadsafety setting. 17571 ** is used regardless of the run-time threadsafety setting. 17235 */ 17572 */ 17236 #ifdef SQLITE_MUTEX_NOOP 17573 #ifdef SQLITE_MUTEX_NOOP 17237 SQLITE_PRIVATE sqlite3_mutex_methods const *sqlite3DefaultMutex(void){ 17574 SQLITE_PRIVATE sqlite3_mutex_methods const *sqlite3DefaultMutex(void){ 17238 return sqlite3NoopMutex(); 17575 return sqlite3NoopMutex(); 17239 } 17576 } 17240 #endif /* SQLITE_MUTEX_NOOP */ | 17577 #endif /* defined(SQLITE_MUTEX_NOOP) */ 17241 #endif /* SQLITE_MUTEX_OMIT */ | 17578 #endif /* !defined(SQLITE_MUTEX_OMIT) */ 17242 17579 17243 /************** End of mutex_noop.c ******************************************/ 17580 /************** End of mutex_noop.c ******************************************/ 17244 /************** Begin file mutex_os2.c ***************************************/ 17581 /************** Begin file mutex_os2.c ***************************************/ 17245 /* 17582 /* 17246 ** 2007 August 28 17583 ** 2007 August 28 17247 ** 17584 ** 17248 ** The author disclaims copyright to this source code. In place of 17585 ** The author disclaims copyright to this source code. In place of ................................................................................................................................................................................ 17863 0 18200 0 17864 #endif 18201 #endif 17865 }; 18202 }; 17866 18203 17867 return &sMutex; 18204 return &sMutex; 17868 } 18205 } 17869 18206 17870 #endif /* SQLITE_MUTEX_PTHREAD */ | 18207 #endif /* SQLITE_MUTEX_PTHREADS */ 17871 18208 17872 /************** End of mutex_unix.c ******************************************/ 18209 /************** End of mutex_unix.c ******************************************/ 17873 /************** Begin file mutex_w32.c ***************************************/ 18210 /************** Begin file mutex_w32.c ***************************************/ 17874 /* 18211 /* 17875 ** 2007 August 14 18212 ** 2007 August 14 17876 ** 18213 ** 17877 ** The author disclaims copyright to this source code. In place of 18214 ** The author disclaims copyright to this source code. In place of ................................................................................................................................................................................ 18332 ** Set the soft heap-size limit for the library. Passing a zero or 18669 ** Set the soft heap-size limit for the library. Passing a zero or 18333 ** negative value indicates no limit. 18670 ** negative value indicates no limit. 18334 */ 18671 */ 18335 SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 n){ 18672 SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 n){ 18336 sqlite3_int64 priorLimit; 18673 sqlite3_int64 priorLimit; 18337 sqlite3_int64 excess; 18674 sqlite3_int64 excess; 18338 #ifndef SQLITE_OMIT_AUTOINIT 18675 #ifndef SQLITE_OMIT_AUTOINIT 18339 sqlite3_initialize(); | 18676 int rc = sqlite3_initialize(); > 18677 if( rc ) return -1; 18340 #endif 18678 #endif 18341 sqlite3_mutex_enter(mem0.mutex); 18679 sqlite3_mutex_enter(mem0.mutex); 18342 priorLimit = mem0.alarmThreshold; 18680 priorLimit = mem0.alarmThreshold; 18343 sqlite3_mutex_leave(mem0.mutex); 18681 sqlite3_mutex_leave(mem0.mutex); 18344 if( n<0 ) return priorLimit; 18682 if( n<0 ) return priorLimit; 18345 if( n>0 ){ 18683 if( n>0 ){ 18346 sqlite3MemoryAlarm(softHeapLimitEnforcer, 0, n); 18684 sqlite3MemoryAlarm(softHeapLimitEnforcer, 0, n); ................................................................................................................................................................................ 19117 return (char)digit; 19455 return (char)digit; 19118 } 19456 } 19119 #endif /* SQLITE_OMIT_FLOATING_POINT */ 19457 #endif /* SQLITE_OMIT_FLOATING_POINT */ 19120 19458 19121 /* 19459 /* 19122 ** Append N space characters to the given string buffer. 19460 ** Append N space characters to the given string buffer. 19123 */ 19461 */ 19124 static void appendSpace(StrAccum *pAccum, int N){ | 19462 SQLITE_PRIVATE void sqlite3AppendSpace(StrAccum *pAccum, int N){ 19125 static const char zSpaces[] = " "; 19463 static const char zSpaces[] = " "; 19126 while( N>=(int)sizeof(zSpaces)-1 ){ 19464 while( N>=(int)sizeof(zSpaces)-1 ){ 19127 sqlite3StrAccumAppend(pAccum, zSpaces, sizeof(zSpaces)-1); 19465 sqlite3StrAccumAppend(pAccum, zSpaces, sizeof(zSpaces)-1); 19128 N -= sizeof(zSpaces)-1; 19466 N -= sizeof(zSpaces)-1; 19129 } 19467 } 19130 if( N>0 ){ 19468 if( N>0 ){ 19131 sqlite3StrAccumAppend(pAccum, zSpaces, N); 19469 sqlite3StrAccumAppend(pAccum, zSpaces, N); ................................................................................................................................................................................ 19645 ** "length" characters long. The field width is "width". Do 19983 ** "length" characters long. The field width is "width". Do 19646 ** the output. 19984 ** the output. 19647 */ 19985 */ 19648 if( !flag_leftjustify ){ 19986 if( !flag_leftjustify ){ 19649 register int nspace; 19987 register int nspace; 19650 nspace = width-length; 19988 nspace = width-length; 19651 if( nspace>0 ){ 19989 if( nspace>0 ){ 19652 appendSpace(pAccum, nspace); | 19990 sqlite3AppendSpace(pAccum, nspace); 19653 } 19991 } 19654 } 19992 } 19655 if( length>0 ){ 19993 if( length>0 ){ 19656 sqlite3StrAccumAppend(pAccum, bufpt, length); 19994 sqlite3StrAccumAppend(pAccum, bufpt, length); 19657 } 19995 } 19658 if( flag_leftjustify ){ 19996 if( flag_leftjustify ){ 19659 register int nspace; 19997 register int nspace; 19660 nspace = width-length; 19998 nspace = width-length; 19661 if( nspace>0 ){ 19999 if( nspace>0 ){ 19662 appendSpace(pAccum, nspace); | 20000 sqlite3AppendSpace(pAccum, nspace); 19663 } 20001 } 19664 } 20002 } 19665 sqlite3_free(zExtra); 20003 sqlite3_free(zExtra); 19666 }/* End for loop over the format string */ 20004 }/* End for loop over the format string */ 19667 } /* End of function */ 20005 } /* End of function */ 19668 20006 19669 /* 20007 /* ................................................................................................................................................................................ 21830 ** do the suffix shortening regardless of URI parameter. 22168 ** do the suffix shortening regardless of URI parameter. 21831 ** 22169 ** 21832 ** Examples: 22170 ** Examples: 21833 ** 22171 ** 21834 ** test.db-journal => test.nal 22172 ** test.db-journal => test.nal 21835 ** test.db-wal => test.wal 22173 ** test.db-wal => test.wal 21836 ** test.db-shm => test.shm 22174 ** test.db-shm => test.shm > 22175 ** test.db-mj7f3319fa => test.9fa 21837 */ 22176 */ 21838 SQLITE_PRIVATE void sqlite3FileSuffix3(const char *zBaseFilename, char *z){ 22177 SQLITE_PRIVATE void sqlite3FileSuffix3(const char *zBaseFilename, char *z){ 21839 #if SQLITE_ENABLE_8_3_NAMES<2 22178 #if SQLITE_ENABLE_8_3_NAMES<2 21840 const char *zOk; < 21841 zOk = sqlite3_uri_parameter(zBaseFilename, "8_3_names"); | 22179 if( sqlite3_uri_boolean(zBaseFilename, "8_3_names", 0) ) 21842 if( zOk && sqlite3GetBoolean(zOk) ) < 21843 #endif 22180 #endif 21844 { 22181 { 21845 int i, sz; 22182 int i, sz; 21846 sz = sqlite3Strlen30(z); 22183 sz = sqlite3Strlen30(z); 21847 for(i=sz-1; i>0 && z[i]!='/' && z[i]!='.'; i--){} 22184 for(i=sz-1; i>0 && z[i]!='/' && z[i]!='.'; i--){} 21848 if( z[i]=='.' && ALWAYS(sz>i+4) ) memcpy(&z[i+1], &z[sz-3], 4); | 22185 if( z[i]=='.' && ALWAYS(sz>i+4) ) memmove(&z[i+1], &z[sz-3], 4); 21849 } 22186 } 21850 } 22187 } 21851 #endif 22188 #endif 21852 22189 21853 /************** End of util.c ************************************************/ 22190 /************** End of util.c ************************************************/ 21854 /************** Begin file hash.c ********************************************/ 22191 /************** Begin file hash.c ********************************************/ 21855 /* 22192 /* ................................................................................................................................................................................ 24546 #include <unistd.h> 24883 #include <unistd.h> 24547 /* #include <time.h> */ 24884 /* #include <time.h> */ 24548 #include <sys/time.h> 24885 #include <sys/time.h> 24549 #include <errno.h> 24886 #include <errno.h> 24550 #ifndef SQLITE_OMIT_WAL 24887 #ifndef SQLITE_OMIT_WAL 24551 #include <sys/mman.h> 24888 #include <sys/mman.h> 24552 #endif 24889 #endif > 24890 24553 24891 24554 #if SQLITE_ENABLE_LOCKING_STYLE 24892 #if SQLITE_ENABLE_LOCKING_STYLE 24555 # include <sys/ioctl.h> 24893 # include <sys/ioctl.h> 24556 # if OS_VXWORKS 24894 # if OS_VXWORKS 24557 # include <semaphore.h> 24895 # include <semaphore.h> 24558 # include <limits.h> 24896 # include <limits.h> 24559 # else 24897 # else ................................................................................................................................................................................ 24630 /* 24968 /* 24631 ** The unixFile structure is subclass of sqlite3_file specific to the unix 24969 ** The unixFile structure is subclass of sqlite3_file specific to the unix 24632 ** VFS implementations. 24970 ** VFS implementations. 24633 */ 24971 */ 24634 typedef struct unixFile unixFile; 24972 typedef struct unixFile unixFile; 24635 struct unixFile { 24973 struct unixFile { 24636 sqlite3_io_methods const *pMethod; /* Always the first entry */ 24974 sqlite3_io_methods const *pMethod; /* Always the first entry */ > 24975 sqlite3_vfs *pVfs; /* The VFS that created this unixFile */ 24637 unixInodeInfo *pInode; /* Info about locks on this inode */ 24976 unixInodeInfo *pInode; /* Info about locks on this inode */ 24638 int h; /* The file descriptor */ 24977 int h; /* The file descriptor */ 24639 unsigned char eFileLock; /* The type of lock held on this fd */ 24978 unsigned char eFileLock; /* The type of lock held on this fd */ 24640 unsigned char ctrlFlags; /* Behavioral bits. UNIXFILE_* flags */ 24979 unsigned char ctrlFlags; /* Behavioral bits. UNIXFILE_* flags */ 24641 int lastErrno; /* The unix errno from last I/O error */ 24980 int lastErrno; /* The unix errno from last I/O error */ 24642 void *lockingContext; /* Locking style specific state */ 24981 void *lockingContext; /* Locking style specific state */ 24643 UnixUnusedFd *pUnused; /* Pre-allocated UnixUnusedFd */ 24982 UnixUnusedFd *pUnused; /* Pre-allocated UnixUnusedFd */ ................................................................................................................................................................................ 24647 #if SQLITE_ENABLE_LOCKING_STYLE 24986 #if SQLITE_ENABLE_LOCKING_STYLE 24648 int openFlags; /* The flags specified at open() */ 24987 int openFlags; /* The flags specified at open() */ 24649 #endif 24988 #endif 24650 #if SQLITE_ENABLE_LOCKING_STYLE || defined(__APPLE__) 24989 #if SQLITE_ENABLE_LOCKING_STYLE || defined(__APPLE__) 24651 unsigned fsFlags; /* cached details from statfs() */ 24990 unsigned fsFlags; /* cached details from statfs() */ 24652 #endif 24991 #endif 24653 #if OS_VXWORKS 24992 #if OS_VXWORKS 24654 int isDelete; /* Delete on close if true */ < 24655 struct vxworksFileId *pId; /* Unique file ID */ 24993 struct vxworksFileId *pId; /* Unique file ID */ 24656 #endif 24994 #endif 24657 #ifndef NDEBUG 24995 #ifndef NDEBUG 24658 /* The next group of variables are used to track whether or not the 24996 /* The next group of variables are used to track whether or not the 24659 ** transaction counter in bytes 24-27 of database files are updated 24997 ** transaction counter in bytes 24-27 of database files are updated 24660 ** whenever any part of the database changes. An assertion fault will 24998 ** whenever any part of the database changes. An assertion fault will 24661 ** occur if a file is updated without also updating the transaction 24999 ** occur if a file is updated without also updating the transaction ................................................................................................................................................................................ 24681 #define UNIXFILE_RDONLY 0x02 /* Connection is read only */ 25019 #define UNIXFILE_RDONLY 0x02 /* Connection is read only */ 24682 #define UNIXFILE_PERSIST_WAL 0x04 /* Persistent WAL mode */ 25020 #define UNIXFILE_PERSIST_WAL 0x04 /* Persistent WAL mode */ 24683 #ifndef SQLITE_DISABLE_DIRSYNC 25021 #ifndef SQLITE_DISABLE_DIRSYNC 24684 # define UNIXFILE_DIRSYNC 0x08 /* Directory sync needed */ 25022 # define UNIXFILE_DIRSYNC 0x08 /* Directory sync needed */ 24685 #else 25023 #else 24686 # define UNIXFILE_DIRSYNC 0x00 25024 # define UNIXFILE_DIRSYNC 0x00 24687 #endif 25025 #endif > 25026 #define UNIXFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */ > 25027 #define UNIXFILE_DELETE 0x20 /* Delete on close */ > 25028 #define UNIXFILE_URI 0x40 /* Filename might have query parameters */ > 25029 #define UNIXFILE_NOLOCK 0x80 /* Do no file locking */ 24688 25030 24689 /* 25031 /* 24690 ** Include code that is common to all os_*.c files 25032 ** Include code that is common to all os_*.c files 24691 */ 25033 */ 24692 /************** Include os_common.h in the middle of os_unix.c ***************/ 25034 /************** Include os_common.h in the middle of os_unix.c ***************/ 24693 /************** Begin file os_common.h ***************************************/ 25035 /************** Begin file os_common.h ***************************************/ 24694 /* 25036 /* ................................................................................................................................................................................ 25039 25381 25040 { "unlink", (sqlite3_syscall_ptr)unlink, 0 }, 25382 { "unlink", (sqlite3_syscall_ptr)unlink, 0 }, 25041 #define osUnlink ((int(*)(const char*))aSyscall[16].pCurrent) 25383 #define osUnlink ((int(*)(const char*))aSyscall[16].pCurrent) 25042 25384 25043 { "openDirectory", (sqlite3_syscall_ptr)openDirectory, 0 }, 25385 { "openDirectory", (sqlite3_syscall_ptr)openDirectory, 0 }, 25044 #define osOpenDirectory ((int(*)(const char*,int*))aSyscall[17].pCurrent) 25386 #define osOpenDirectory ((int(*)(const char*,int*))aSyscall[17].pCurrent) 25045 25387 > 25388 { "mkdir", (sqlite3_syscall_ptr)mkdir, 0 }, > 25389 #define osMkdir ((int(*)(const char*,mode_t))aSyscall[18].pCurrent) > 25390 > 25391 { "rmdir", (sqlite3_syscall_ptr)rmdir, 0 }, > 25392 #define osRmdir ((int(*)(const char*))aSyscall[19].pCurrent) > 25393 25046 }; /* End of the overrideable system calls */ 25394 }; /* End of the overrideable system calls */ 25047 25395 25048 /* 25396 /* 25049 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the 25397 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the 25050 ** "unix" VFSes. Return SQLITE_OK opon successfully updating the 25398 ** "unix" VFSes. Return SQLITE_OK opon successfully updating the 25051 ** system call pointer, or SQLITE_NOTFOUND if there is no configurable 25399 ** system call pointer, or SQLITE_NOTFOUND if there is no configurable 25052 ** system call named zName. 25400 ** system call named zName. ................................................................................................................................................................................ 26388 unixFile *pFile = (unixFile*)id; 26736 unixFile *pFile = (unixFile*)id; 26389 if( pFile->h>=0 ){ 26737 if( pFile->h>=0 ){ 26390 robust_close(pFile, pFile->h, __LINE__); 26738 robust_close(pFile, pFile->h, __LINE__); 26391 pFile->h = -1; 26739 pFile->h = -1; 26392 } 26740 } 26393 #if OS_VXWORKS 26741 #if OS_VXWORKS 26394 if( pFile->pId ){ 26742 if( pFile->pId ){ 26395 if( pFile->isDelete ){ | 26743 if( pFile->ctrlFlags & UNIXFILE_DELETE ){ 26396 osUnlink(pFile->pId->zCanonicalName); 26744 osUnlink(pFile->pId->zCanonicalName); 26397 } 26745 } 26398 vxworksReleaseFileId(pFile->pId); 26746 vxworksReleaseFileId(pFile->pId); 26399 pFile->pId = 0; 26747 pFile->pId = 0; 26400 } 26748 } 26401 #endif 26749 #endif 26402 OSTRACE(("CLOSE %-3d\n", pFile->h)); 26750 OSTRACE(("CLOSE %-3d\n", pFile->h)); ................................................................................................................................................................................ 26477 /******************* End of the no-op lock implementation ********************* 26825 /******************* End of the no-op lock implementation ********************* 26478 ******************************************************************************/ 26826 ******************************************************************************/ 26479 26827 26480 /****************************************************************************** 26828 /****************************************************************************** 26481 ************************* Begin dot-file Locking ****************************** 26829 ************************* Begin dot-file Locking ****************************** 26482 ** 26830 ** 26483 ** The dotfile locking implementation uses the existance of separate lock 26831 ** The dotfile locking implementation uses the existance of separate lock 26484 ** files in order to control access to the database. This works on just | 26832 ** files (really a directory) to control access to the database. This works 26485 ** about every filesystem imaginable. But there are serious downsides: | 26833 ** on just about every filesystem imaginable. But there are serious downsides: 26486 ** 26834 ** 26487 ** (1) There is zero concurrency. A single reader blocks all other 26835 ** (1) There is zero concurrency. A single reader blocks all other 26488 ** connections from reading or writing the database. 26836 ** connections from reading or writing the database. 26489 ** 26837 ** 26490 ** (2) An application crash or power loss can leave stale lock files 26838 ** (2) An application crash or power loss can leave stale lock files 26491 ** sitting around that need to be cleared manually. 26839 ** sitting around that need to be cleared manually. 26492 ** 26840 ** 26493 ** Nevertheless, a dotlock is an appropriate locking mode for use if no 26841 ** Nevertheless, a dotlock is an appropriate locking mode for use if no 26494 ** other locking strategy is available. 26842 ** other locking strategy is available. 26495 ** 26843 ** 26496 ** Dotfile locking works by creating a file in the same directory as the | 26844 ** Dotfile locking works by creating a subdirectory in the same directory as 26497 ** database and with the same name but with a ".lock" extension added. | 26845 ** the database and with the same name but with a ".lock" extension added. 26498 ** The existance of a lock file implies an EXCLUSIVE lock. All other lock | 26846 ** The existance of a lock directory implies an EXCLUSIVE lock. All other 26499 ** types (SHARED, RESERVED, PENDING) are mapped into EXCLUSIVE. | 26847 ** lock types (SHARED, RESERVED, PENDING) are mapped into EXCLUSIVE. 26500 */ 26848 */ 26501 26849 26502 /* 26850 /* 26503 ** The file suffix added to the data base filename in order to create the 26851 ** The file suffix added to the data base filename in order to create the 26504 ** lock file. | 26852 ** lock directory. 26505 */ 26853 */ 26506 #define DOTLOCK_SUFFIX ".lock" 26854 #define DOTLOCK_SUFFIX ".lock" 26507 26855 26508 /* 26856 /* 26509 ** This routine checks if there is a RESERVED lock held on the specified 26857 ** This routine checks if there is a RESERVED lock held on the specified 26510 ** file by this or any other process. If such a lock is held, set *pResOut 26858 ** file by this or any other process. If such a lock is held, set *pResOut 26511 ** to a non-zero value otherwise *pResOut is set to zero. The return value 26859 ** to a non-zero value otherwise *pResOut is set to zero. The return value ................................................................................................................................................................................ 26564 ** routine to lower a locking level. 26912 ** routine to lower a locking level. 26565 ** 26913 ** 26566 ** With dotfile locking, we really only support state (4): EXCLUSIVE. 26914 ** With dotfile locking, we really only support state (4): EXCLUSIVE. 26567 ** But we track the other locking levels internally. 26915 ** But we track the other locking levels internally. 26568 */ 26916 */ 26569 static int dotlockLock(sqlite3_file *id, int eFileLock) { 26917 static int dotlockLock(sqlite3_file *id, int eFileLock) { 26570 unixFile *pFile = (unixFile*)id; 26918 unixFile *pFile = (unixFile*)id; 26571 int fd; < 26572 char *zLockFile = (char *)pFile->lockingContext; 26919 char *zLockFile = (char *)pFile->lockingContext; 26573 int rc = SQLITE_OK; 26920 int rc = SQLITE_OK; 26574 26921 26575 26922 26576 /* If we have any lock, then the lock file already exists. All we have 26923 /* If we have any lock, then the lock file already exists. All we have 26577 ** to do is adjust our internal record of the lock level. 26924 ** to do is adjust our internal record of the lock level. 26578 */ 26925 */ ................................................................................................................................................................................ 26584 #else 26931 #else 26585 utimes(zLockFile, NULL); 26932 utimes(zLockFile, NULL); 26586 #endif 26933 #endif 26587 return SQLITE_OK; 26934 return SQLITE_OK; 26588 } 26935 } 26589 26936 26590 /* grab an exclusive lock */ 26937 /* grab an exclusive lock */ 26591 fd = robust_open(zLockFile,O_RDONLY|O_CREAT|O_EXCL,0600); | 26938 rc = osMkdir(zLockFile, 0777); 26592 if( fd<0 ){ | 26939 if( rc<0 ){ 26593 /* failed to open/create the file, someone else may have stolen the lock */ | 26940 /* failed to open/create the lock directory */ 26594 int tErrno = errno; 26941 int tErrno = errno; 26595 if( EEXIST == tErrno ){ 26942 if( EEXIST == tErrno ){ 26596 rc = SQLITE_BUSY; 26943 rc = SQLITE_BUSY; 26597 } else { 26944 } else { 26598 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK); 26945 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK); 26599 if( IS_LOCK_ERROR(rc) ){ 26946 if( IS_LOCK_ERROR(rc) ){ 26600 pFile->lastErrno = tErrno; 26947 pFile->lastErrno = tErrno; 26601 } 26948 } 26602 } 26949 } 26603 return rc; 26950 return rc; 26604 } 26951 } 26605 robust_close(pFile, fd, __LINE__); < 26606 26952 26607 /* got it, set the type and return ok */ 26953 /* got it, set the type and return ok */ 26608 pFile->eFileLock = eFileLock; 26954 pFile->eFileLock = eFileLock; 26609 return rc; 26955 return rc; 26610 } 26956 } 26611 26957 26612 /* 26958 /* ................................................................................................................................................................................ 26617 ** the requested locking level, this routine is a no-op. 26963 ** the requested locking level, this routine is a no-op. 26618 ** 26964 ** 26619 ** When the locking level reaches NO_LOCK, delete the lock file. 26965 ** When the locking level reaches NO_LOCK, delete the lock file. 26620 */ 26966 */ 26621 static int dotlockUnlock(sqlite3_file *id, int eFileLock) { 26967 static int dotlockUnlock(sqlite3_file *id, int eFileLock) { 26622 unixFile *pFile = (unixFile*)id; 26968 unixFile *pFile = (unixFile*)id; 26623 char *zLockFile = (char *)pFile->lockingContext; 26969 char *zLockFile = (char *)pFile->lockingContext; > 26970 int rc; 26624 26971 26625 assert( pFile ); 26972 assert( pFile ); 26626 OSTRACE(("UNLOCK %d %d was %d pid=%d (dotlock)\n", pFile->h, eFileLock, 26973 OSTRACE(("UNLOCK %d %d was %d pid=%d (dotlock)\n", pFile->h, eFileLock, 26627 pFile->eFileLock, getpid())); 26974 pFile->eFileLock, getpid())); 26628 assert( eFileLock<=SHARED_LOCK ); 26975 assert( eFileLock<=SHARED_LOCK ); 26629 26976 26630 /* no-op if possible */ 26977 /* no-op if possible */ ................................................................................................................................................................................ 26638 if( eFileLock==SHARED_LOCK ){ 26985 if( eFileLock==SHARED_LOCK ){ 26639 pFile->eFileLock = SHARED_LOCK; 26986 pFile->eFileLock = SHARED_LOCK; 26640 return SQLITE_OK; 26987 return SQLITE_OK; 26641 } 26988 } 26642 26989 26643 /* To fully unlock the database, delete the lock file */ 26990 /* To fully unlock the database, delete the lock file */ 26644 assert( eFileLock==NO_LOCK ); 26991 assert( eFileLock==NO_LOCK ); 26645 if( osUnlink(zLockFile) ){ | 26992 rc = osRmdir(zLockFile); 26646 int rc = 0; | 26993 if( rc<0 && errno==ENOTDIR ) rc = osUnlink(zLockFile); > 26994 if( rc<0 ){ 26647 int tErrno = errno; 26995 int tErrno = errno; > 26996 rc = 0; 26648 if( ENOENT != tErrno ){ 26997 if( ENOENT != tErrno ){ 26649 rc = SQLITE_IOERR_UNLOCK; 26998 rc = SQLITE_IOERR_UNLOCK; 26650 } 26999 } 26651 if( IS_LOCK_ERROR(rc) ){ 27000 if( IS_LOCK_ERROR(rc) ){ 26652 pFile->lastErrno = tErrno; 27001 pFile->lastErrno = tErrno; 26653 } 27002 } 26654 return rc; 27003 return rc; ................................................................................................................................................................................ 27576 ** See tickets #2741 and #2681. 27925 ** See tickets #2741 and #2681. 27577 ** 27926 ** 27578 ** To avoid stomping the errno value on a failed read the lastErrno value 27927 ** To avoid stomping the errno value on a failed read the lastErrno value 27579 ** is set before returning. 27928 ** is set before returning. 27580 */ 27929 */ 27581 static int seekAndRead(unixFile *id, sqlite3_int64 offset, void *pBuf, int cnt){ 27930 static int seekAndRead(unixFile *id, sqlite3_int64 offset, void *pBuf, int cnt){ 27582 int got; 27931 int got; > 27932 int prior = 0; 27583 #if (!defined(USE_PREAD) && !defined(USE_PREAD64)) 27933 #if (!defined(USE_PREAD) && !defined(USE_PREAD64)) 27584 i64 newOffset; 27934 i64 newOffset; 27585 #endif 27935 #endif 27586 TIMER_START; 27936 TIMER_START; > 27937 do{ 27587 #if defined(USE_PREAD) 27938 #if defined(USE_PREAD) 27588 do{ got = osPread(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR ); | 27939 got = osPread(id->h, pBuf, cnt, offset); 27589 SimulateIOError( got = -1 ); | 27940 SimulateIOError( got = -1 ); 27590 #elif defined(USE_PREAD64) 27941 #elif defined(USE_PREAD64) 27591 do{ got = osPread64(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR); | 27942 got = osPread64(id->h, pBuf, cnt, offset); 27592 SimulateIOError( got = -1 ); | 27943 SimulateIOError( got = -1 ); 27593 #else 27944 #else 27594 newOffset = lseek(id->h, offset, SEEK_SET); | 27945 newOffset = lseek(id->h, offset, SEEK_SET); 27595 SimulateIOError( newOffset-- ); | 27946 SimulateIOError( newOffset-- ); 27596 if( newOffset!=offset ){ | 27947 if( newOffset!=offset ){ 27597 if( newOffset == -1 ){ | 27948 if( newOffset == -1 ){ > 27949 ((unixFile*)id)->lastErrno = errno; > 27950 }else{ > 27951 ((unixFile*)id)->lastErrno = 0; > 27952 } > 27953 return -1; > 27954 } > 27955 got = osRead(id->h, pBuf, cnt); > 27956 #endif > 27957 if( got==cnt ) break; > 27958 if( got<0 ){ > 27959 if( errno==EINTR ){ got = 1; continue; } > 27960 prior = 0; 27598 ((unixFile*)id)->lastErrno = errno; 27961 ((unixFile*)id)->lastErrno = errno; > 27962 break; 27599 }else{ | 27963 }else if( got>0 ){ 27600 ((unixFile*)id)->lastErrno = 0; < > 27964 cnt -= got; > 27965 offset += got; > 27966 prior += got; > 27967 pBuf = (void*)(got + (char*)pBuf); 27601 } 27968 } 27602 return -1; | 27969 }while( got>0 ); 27603 } < 27604 do{ got = osRead(id->h, pBuf, cnt); }while( got<0 && errno==EINTR ); < 27605 #endif < 27606 TIMER_END; 27970 TIMER_END; 27607 if( got<0 ){ < 27608 ((unixFile*)id)->lastErrno = errno; < 27609 } < 27610 OSTRACE(("READ %-3d %5d %7lld %llu\n", id->h, got, offset, TIMER_ELAPSED)); | 27971 OSTRACE(("READ %-3d %5d %7lld %llu\n", > 27972 id->h, got+prior, offset-prior, TIMER_ELAPSED)); 27611 return got; | 27973 return got+prior; 27612 } 27974 } 27613 27975 27614 /* 27976 /* 27615 ** Read data from a file into a buffer. Return SQLITE_OK if all 27977 ** Read data from a file into a buffer. Return SQLITE_OK if all 27616 ** bytes were read successfully and SQLITE_IOERR if anything goes 27978 ** bytes were read successfully and SQLITE_IOERR if anything goes 27617 ** wrong. 27979 ** wrong. 27618 */ 27980 */ ................................................................................................................................................................................ 28108 } 28470 } 28109 #endif 28471 #endif 28110 } 28472 } 28111 } 28473 } 28112 28474 28113 return SQLITE_OK; 28475 return SQLITE_OK; 28114 } 28476 } > 28477 > 28478 /* > 28479 ** If *pArg is inititially negative then this is a query. Set *pArg to > 28480 ** 1 or 0 depending on whether or not bit mask of pFile->ctrlFlags is set. > 28481 ** > 28482 ** If *pArg is 0 or 1, then clear or set the mask bit of pFile->ctrlFlags. > 28483 */ > 28484 static void unixModeBit(unixFile *pFile, unsigned char mask, int *pArg){ > 28485 if( *pArg<0 ){ > 28486 *pArg = (pFile->ctrlFlags & mask)!=0; > 28487 }else if( (*pArg)==0 ){ > 28488 pFile->ctrlFlags &= ~mask; > 28489 }else{ > 28490 pFile->ctrlFlags |= mask; > 28491 } > 28492 } 28115 28493 28116 /* 28494 /* 28117 ** Information and control of an open file handle. 28495 ** Information and control of an open file handle. 28118 */ 28496 */ 28119 static int unixFileControl(sqlite3_file *id, int op, void *pArg){ 28497 static int unixFileControl(sqlite3_file *id, int op, void *pArg){ 28120 unixFile *pFile = (unixFile*)id; 28498 unixFile *pFile = (unixFile*)id; 28121 switch( op ){ 28499 switch( op ){ ................................................................................................................................................................................ 28135 int rc; 28513 int rc; 28136 SimulateIOErrorBenign(1); 28514 SimulateIOErrorBenign(1); 28137 rc = fcntlSizeHint(pFile, *(i64 *)pArg); 28515 rc = fcntlSizeHint(pFile, *(i64 *)pArg); 28138 SimulateIOErrorBenign(0); 28516 SimulateIOErrorBenign(0); 28139 return rc; 28517 return rc; 28140 } 28518 } 28141 case SQLITE_FCNTL_PERSIST_WAL: { 28519 case SQLITE_FCNTL_PERSIST_WAL: { 28142 int bPersist = *(int*)pArg; < 28143 if( bPersist<0 ){ < 28144 *(int*)pArg = (pFile->ctrlFlags & UNIXFILE_PERSIST_WAL)!=0; | 28520 unixModeBit(pFile, UNIXFILE_PERSIST_WAL, (int*)pArg); > 28521 return SQLITE_OK; > 28522 } 28145 }else if( bPersist==0 ){ | 28523 case SQLITE_FCNTL_POWERSAFE_OVERWRITE: { 28146 pFile->ctrlFlags &= ~UNIXFILE_PERSIST_WAL; | 28524 unixModeBit(pFile, UNIXFILE_PSOW, (int*)pArg); 28147 }else{ | 28525 return SQLITE_OK; 28148 pFile->ctrlFlags |= UNIXFILE_PERSIST_WAL; < 28149 } | 28526 } > 28527 case SQLITE_FCNTL_VFSNAME: { > 28528 *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName); 28150 return SQLITE_OK; 28529 return SQLITE_OK; 28151 } 28530 } 28152 #ifndef NDEBUG 28531 #ifndef NDEBUG 28153 /* The pager calls this method to signal that it has done 28532 /* The pager calls this method to signal that it has done 28154 ** a rollback and that the database is therefore unchanged and 28533 ** a rollback and that the database is therefore unchanged and 28155 ** it hence it is OK for the transaction change counter to be 28534 ** it hence it is OK for the transaction change counter to be 28156 ** unchanged. 28535 ** unchanged. ................................................................................................................................................................................ 28162 #endif 28541 #endif 28163 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) 28542 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) 28164 case SQLITE_SET_LOCKPROXYFILE: 28543 case SQLITE_SET_LOCKPROXYFILE: 28165 case SQLITE_GET_LOCKPROXYFILE: { 28544 case SQLITE_GET_LOCKPROXYFILE: { 28166 return proxyFileControl(id,op,pArg); 28545 return proxyFileControl(id,op,pArg); 28167 } 28546 } 28168 #endif /* SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) */ 28547 #endif /* SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) */ 28169 case SQLITE_FCNTL_SYNC_OMITTED: { < 28170 return SQLITE_OK; /* A no-op */ < 28171 } < 28172 } 28548 } 28173 return SQLITE_NOTFOUND; 28549 return SQLITE_NOTFOUND; 28174 } 28550 } 28175 28551 28176 /* 28552 /* 28177 ** Return the sector size in bytes of the underlying block device for 28553 ** Return the sector size in bytes of the underlying block device for 28178 ** the specified file. This is almost always 512 bytes, but may be 28554 ** the specified file. This is almost always 512 bytes, but may be ................................................................................................................................................................................ 28179 ** larger for some devices. 28555 ** larger for some devices. 28180 ** 28556 ** 28181 ** SQLite code assumes this function cannot fail. It also assumes that 28557 ** SQLite code assumes this function cannot fail. It also assumes that 28182 ** if two files are created in the same file-system directory (i.e. 28558 ** if two files are created in the same file-system directory (i.e. 28183 ** a database and its journal file) that the sector size will be the 28559 ** a database and its journal file) that the sector size will be the 28184 ** same for both. 28560 ** same for both. 28185 */ 28561 */ 28186 static int unixSectorSize(sqlite3_file *NotUsed){ | 28562 static int unixSectorSize(sqlite3_file *pFile){ 28187 UNUSED_PARAMETER(NotUsed); | 28563 (void)pFile; 28188 return SQLITE_DEFAULT_SECTOR_SIZE; 28564 return SQLITE_DEFAULT_SECTOR_SIZE; 28189 } 28565 } 28190 28566 28191 /* 28567 /* 28192 ** Return the device characteristics for the file. This is always 0 for unix. | 28568 ** Return the device characteristics for the file. > 28569 ** > 28570 ** This VFS is set up to return SQLITE_IOCAP_POWERSAFE_OVERWRITE by default. > 28571 ** However, that choice is contraversial since technically the underlying > 28572 ** file system does not always provide powersafe overwrites. (In other > 28573 ** words, after a power-loss event, parts of the file that were never > 28574 ** written might end up being altered.) However, non-PSOW behavior is very, > 28575 ** very rare. And asserting PSOW makes a large reduction in the amount > 28576 ** of required I/O for journaling, since a lot of padding is eliminated. > 28577 ** Hence, while POWERSAFE_OVERWRITE is on by default, there is a file-control > 28578 ** available to turn it off and URI query parameter available to turn it off. 28193 */ 28579 */ 28194 static int unixDeviceCharacteristics(sqlite3_file *NotUsed){ | 28580 static int unixDeviceCharacteristics(sqlite3_file *id){ 28195 UNUSED_PARAMETER(NotUsed); | 28581 unixFile *p = (unixFile*)id; > 28582 if( p->ctrlFlags & UNIXFILE_PSOW ){ > 28583 return SQLITE_IOCAP_POWERSAFE_OVERWRITE; > 28584 }else{ 28196 return 0; | 28585 return 0; > 28586 } 28197 } 28587 } 28198 28588 28199 #ifndef SQLITE_OMIT_WAL 28589 #ifndef SQLITE_OMIT_WAL 28200 28590 28201 28591 28202 /* 28592 /* 28203 ** Object used to represent an shared memory buffer. 28593 ** Object used to represent an shared memory buffer. ................................................................................................................................................................................ 28444 */ 28834 */ 28445 if( osFstat(pDbFd->h, &sStat) && pInode->bProcessLock==0 ){ 28835 if( osFstat(pDbFd->h, &sStat) && pInode->bProcessLock==0 ){ 28446 rc = SQLITE_IOERR_FSTAT; 28836 rc = SQLITE_IOERR_FSTAT; 28447 goto shm_open_err; 28837 goto shm_open_err; 28448 } 28838 } 28449 28839 28450 #ifdef SQLITE_SHM_DIRECTORY 28840 #ifdef SQLITE_SHM_DIRECTORY 28451 nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 30; | 28841 nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 31; 28452 #else 28842 #else 28453 nShmFilename = 5 + (int)strlen(pDbFd->zPath); | 28843 nShmFilename = 6 + (int)strlen(pDbFd->zPath); 28454 #endif 28844 #endif 28455 pShmNode = sqlite3_malloc( sizeof(*pShmNode) + nShmFilename ); 28845 pShmNode = sqlite3_malloc( sizeof(*pShmNode) + nShmFilename ); 28456 if( pShmNode==0 ){ 28846 if( pShmNode==0 ){ 28457 rc = SQLITE_NOMEM; 28847 rc = SQLITE_NOMEM; 28458 goto shm_open_err; 28848 goto shm_open_err; 28459 } 28849 } 28460 memset(pShmNode, 0, sizeof(*pShmNode)); | 28850 memset(pShmNode, 0, sizeof(*pShmNode)+nShmFilename); 28461 zShmFilename = pShmNode->zFilename = (char*)&pShmNode[1]; 28851 zShmFilename = pShmNode->zFilename = (char*)&pShmNode[1]; 28462 #ifdef SQLITE_SHM_DIRECTORY 28852 #ifdef SQLITE_SHM_DIRECTORY 28463 sqlite3_snprintf(nShmFilename, zShmFilename, 28853 sqlite3_snprintf(nShmFilename, zShmFilename, 28464 SQLITE_SHM_DIRECTORY "/sqlite-shm-%x-%x", 28854 SQLITE_SHM_DIRECTORY "/sqlite-shm-%x-%x", 28465 (u32)sStat.st_ino, (u32)sStat.st_dev); 28855 (u32)sStat.st_ino, (u32)sStat.st_dev); 28466 #else 28856 #else 28467 sqlite3_snprintf(nShmFilename, zShmFilename, "%s-shm", pDbFd->zPath); 28857 sqlite3_snprintf(nShmFilename, zShmFilename, "%s-shm", pDbFd->zPath); ................................................................................................................................................................................ 28473 pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST); 28863 pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST); 28474 if( pShmNode->mutex==0 ){ 28864 if( pShmNode->mutex==0 ){ 28475 rc = SQLITE_NOMEM; 28865 rc = SQLITE_NOMEM; 28476 goto shm_open_err; 28866 goto shm_open_err; 28477 } 28867 } 28478 28868 28479 if( pInode->bProcessLock==0 ){ 28869 if( pInode->bProcessLock==0 ){ 28480 const char *zRO; < 28481 int openFlags = O_RDWR | O_CREAT; 28870 int openFlags = O_RDWR | O_CREAT; 28482 zRO = sqlite3_uri_parameter(pDbFd->zPath, "readonly_shm"); | 28871 if( sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){ 28483 if( zRO && sqlite3GetBoolean(zRO) ){ < 28484 openFlags = O_RDONLY; 28872 openFlags = O_RDONLY; 28485 pShmNode->isReadonly = 1; 28873 pShmNode->isReadonly = 1; 28486 } 28874 } 28487 pShmNode->h = robust_open(zShmFilename, openFlags, (sStat.st_mode&0777)); 28875 pShmNode->h = robust_open(zShmFilename, openFlags, (sStat.st_mode&0777)); 28488 if( pShmNode->h<0 ){ 28876 if( pShmNode->h<0 ){ 28489 if( pShmNode->h<0 ){ 28877 if( pShmNode->h<0 ){ 28490 rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShmFilename); 28878 rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShmFilename); ................................................................................................................................................................................ 29138 29526 29139 /* 29527 /* 29140 ** Initialize the contents of the unixFile structure pointed to by pId. 29528 ** Initialize the contents of the unixFile structure pointed to by pId. 29141 */ 29529 */ 29142 static int fillInUnixFile( 29530 static int fillInUnixFile( 29143 sqlite3_vfs *pVfs, /* Pointer to vfs object */ 29531 sqlite3_vfs *pVfs, /* Pointer to vfs object */ 29144 int h, /* Open file descriptor of file being opened */ 29532 int h, /* Open file descriptor of file being opened */ 29145 int syncDir, /* True to sync directory on first sync */ < 29146 sqlite3_file *pId, /* Write to the unixFile structure here */ 29533 sqlite3_file *pId, /* Write to the unixFile structure here */ 29147 const char *zFilename, /* Name of the file being opened */ 29534 const char *zFilename, /* Name of the file being opened */ 29148 int noLock, /* Omit locking if true */ | 29535 int ctrlFlags /* Zero or more UNIXFILE_* values */ 29149 int isDelete, /* Delete on close if true */ < 29150 int isReadOnly /* True if the file is opened read-only */ < 29151 ){ 29536 ){ 29152 const sqlite3_io_methods *pLockingStyle; 29537 const sqlite3_io_methods *pLockingStyle; 29153 unixFile *pNew = (unixFile *)pId; 29538 unixFile *pNew = (unixFile *)pId; 29154 int rc = SQLITE_OK; 29539 int rc = SQLITE_OK; 29155 29540 29156 assert( pNew->pInode==NULL ); 29541 assert( pNew->pInode==NULL ); 29157 29542 29158 /* Parameter isDelete is only used on vxworks. Express this explicitly < 29159 ** here to prevent compiler warnings about unused parameters. < 29160 */ < 29161 UNUSED_PARAMETER(isDelete); < 29162 < 29163 /* Usually the path zFilename should not be a relative pathname. The 29543 /* Usually the path zFilename should not be a relative pathname. The 29164 ** exception is when opening the proxy "conch" file in builds that 29544 ** exception is when opening the proxy "conch" file in builds that 29165 ** include the special Apple locking styles. 29545 ** include the special Apple locking styles. 29166 */ 29546 */ 29167 #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE 29547 #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE 29168 assert( zFilename==0 || zFilename[0]=='/' 29548 assert( zFilename==0 || zFilename[0]=='/' 29169 || pVfs->pAppData==(void*)&autolockIoFinder ); 29549 || pVfs->pAppData==(void*)&autolockIoFinder ); 29170 #else 29550 #else 29171 assert( zFilename==0 || zFilename[0]=='/' ); 29551 assert( zFilename==0 || zFilename[0]=='/' ); 29172 #endif 29552 #endif 29173 29553 29174 /* No locking occurs in temporary files */ 29554 /* No locking occurs in temporary files */ 29175 assert( zFilename!=0 || noLock ); | 29555 assert( zFilename!=0 || (ctrlFlags & UNIXFILE_NOLOCK)!=0 ); 29176 29556 29177 OSTRACE(("OPEN %-3d %s\n", h, zFilename)); 29557 OSTRACE(("OPEN %-3d %s\n", h, zFilename)); 29178 pNew->h = h; 29558 pNew->h = h; > 29559 pNew->pVfs = pVfs; 29179 pNew->zPath = zFilename; 29560 pNew->zPath = zFilename; > 29561 pNew->ctrlFlags = (u8)ctrlFlags; > 29562 if( sqlite3_uri_boolean(((ctrlFlags & UNIXFILE_URI) ? zFilename : 0), > 29563 "psow", SQLITE_POWERSAFE_OVERWRITE) ){ > 29564 pNew->ctrlFlags |= UNIXFILE_PSOW; > 29565 } 29180 if( memcmp(pVfs->zName,"unix-excl",10)==0 ){ 29566 if( memcmp(pVfs->zName,"unix-excl",10)==0 ){ 29181 pNew->ctrlFlags = UNIXFILE_EXCL; < 29182 }else{ < 29183 pNew->ctrlFlags = 0; < 29184 } < 29185 if( isReadOnly ){ < 29186 pNew->ctrlFlags |= UNIXFILE_RDONLY; | 29567 pNew->ctrlFlags |= UNIXFILE_EXCL; 29187 } < 29188 if( syncDir ){ < 29189 pNew->ctrlFlags |= UNIXFILE_DIRSYNC; < 29190 } 29568 } 29191 29569 29192 #if OS_VXWORKS 29570 #if OS_VXWORKS 29193 pNew->pId = vxworksFindFileId(zFilename); 29571 pNew->pId = vxworksFindFileId(zFilename); 29194 if( pNew->pId==0 ){ 29572 if( pNew->pId==0 ){ 29195 noLock = 1; | 29573 ctrlFlags |= UNIXFILE_NOLOCK; 29196 rc = SQLITE_NOMEM; 29574 rc = SQLITE_NOMEM; 29197 } 29575 } 29198 #endif 29576 #endif 29199 29577 29200 if( noLock ){ | 29578 if( ctrlFlags & UNIXFILE_NOLOCK ){ 29201 pLockingStyle = &nolockIoMethods; 29579 pLockingStyle = &nolockIoMethods; 29202 }else{ 29580 }else{ 29203 pLockingStyle = (**(finder_type*)pVfs->pAppData)(zFilename, pNew); 29581 pLockingStyle = (**(finder_type*)pVfs->pAppData)(zFilename, pNew); 29204 #if SQLITE_ENABLE_LOCKING_STYLE 29582 #if SQLITE_ENABLE_LOCKING_STYLE 29205 /* Cache zFilename in the locking context (AFP and dotlock override) for 29583 /* Cache zFilename in the locking context (AFP and dotlock override) for 29206 ** proxyLock activation is possible (remote proxy is based on db name) 29584 ** proxyLock activation is possible (remote proxy is based on db name) 29207 ** zFilename remains valid until file is closed, to support */ 29585 ** zFilename remains valid until file is closed, to support */ ................................................................................................................................................................................ 29314 #if OS_VXWORKS 29692 #if OS_VXWORKS 29315 if( rc!=SQLITE_OK ){ 29693 if( rc!=SQLITE_OK ){ 29316 if( h>=0 ) robust_close(pNew, h, __LINE__); 29694 if( h>=0 ) robust_close(pNew, h, __LINE__); 29317 h = -1; 29695 h = -1; 29318 osUnlink(zFilename); 29696 osUnlink(zFilename); 29319 isDelete = 0; 29697 isDelete = 0; 29320 } 29698 } 29321 pNew->isDelete = isDelete; | 29699 if( isDelete ) pNew->ctrlFlags |= UNIXFILE_DELETE; 29322 #endif 29700 #endif 29323 if( rc!=SQLITE_OK ){ 29701 if( rc!=SQLITE_OK ){ 29324 if( h>=0 ) robust_close(pNew, h, __LINE__); 29702 if( h>=0 ) robust_close(pNew, h, __LINE__); 29325 }else{ 29703 }else{ 29326 pNew->pMethod = pLockingStyle; 29704 pNew->pMethod = pLockingStyle; 29327 OpenCounter(+1); 29705 OpenCounter(+1); 29328 } 29706 } ................................................................................................................................................................................ 29379 29757 29380 zDir = unixTempFileDir(); 29758 zDir = unixTempFileDir(); 29381 if( zDir==0 ) zDir = "."; 29759 if( zDir==0 ) zDir = "."; 29382 29760 29383 /* Check that the output buffer is large enough for the temporary file 29761 /* Check that the output buffer is large enough for the temporary file 29384 ** name. If it is not, return SQLITE_ERROR. 29762 ** name. If it is not, return SQLITE_ERROR. 29385 */ 29763 */ 29386 if( (strlen(zDir) + strlen(SQLITE_TEMP_FILE_PREFIX) + 17) >= (size_t)nBuf ){ | 29764 if( (strlen(zDir) + strlen(SQLITE_TEMP_FILE_PREFIX) + 18) >= (size_t)nBuf ){ 29387 return SQLITE_ERROR; 29765 return SQLITE_ERROR; 29388 } 29766 } 29389 29767 29390 do{ 29768 do{ 29391 sqlite3_snprintf(nBuf-17, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX, zDir); | 29769 sqlite3_snprintf(nBuf-18, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX, zDir); 29392 j = (int)strlen(zBuf); 29770 j = (int)strlen(zBuf); 29393 sqlite3_randomness(15, &zBuf[j]); 29771 sqlite3_randomness(15, &zBuf[j]); 29394 for(i=0; i<15; i++, j++){ 29772 for(i=0; i<15; i++, j++){ 29395 zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ]; 29773 zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ]; 29396 } 29774 } 29397 zBuf[j] = 0; 29775 zBuf[j] = 0; > 29776 zBuf[j+1] = 0; 29398 }while( osAccess(zBuf,0)==0 ); 29777 }while( osAccess(zBuf,0)==0 ); 29399 return SQLITE_OK; 29778 return SQLITE_OK; 29400 } 29779 } 29401 29780 29402 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) 29781 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) 29403 /* 29782 /* 29404 ** Routine to transform a unixFile into a proxy-locking unixFile. 29783 ** Routine to transform a unixFile into a proxy-locking unixFile. ................................................................................................................................................................................ 29511 ** "<path to db>-walNN" 29890 ** "<path to db>-walNN" 29512 ** 29891 ** 29513 ** where NN is a decimal number. The NN naming schemes are 29892 ** where NN is a decimal number. The NN naming schemes are 29514 ** used by the test_multiplex.c module. 29893 ** used by the test_multiplex.c module. 29515 */ 29894 */ 29516 nDb = sqlite3Strlen30(zPath) - 1; 29895 nDb = sqlite3Strlen30(zPath) - 1; 29517 #ifdef SQLITE_ENABLE_8_3_NAMES 29896 #ifdef SQLITE_ENABLE_8_3_NAMES 29518 while( nDb>0 && !sqlite3Isalnum(zPath[nDb]) ) nDb--; | 29897 while( nDb>0 && sqlite3Isalnum(zPath[nDb]) ) nDb--; 29519 if( nDb==0 || zPath[nDb]!='-' ) return SQLITE_OK; 29898 if( nDb==0 || zPath[nDb]!='-' ) return SQLITE_OK; 29520 #else 29899 #else 29521 while( zPath[nDb]!='-' ){ 29900 while( zPath[nDb]!='-' ){ 29522 assert( nDb>0 ); 29901 assert( nDb>0 ); 29523 assert( zPath[nDb]!='\n' ); 29902 assert( zPath[nDb]!='\n' ); 29524 nDb--; 29903 nDb--; 29525 } 29904 } ................................................................................................................................................................................ 29569 ){ 29948 ){ 29570 unixFile *p = (unixFile *)pFile; 29949 unixFile *p = (unixFile *)pFile; 29571 int fd = -1; /* File descriptor returned by open() */ 29950 int fd = -1; /* File descriptor returned by open() */ 29572 int openFlags = 0; /* Flags to pass to open() */ 29951 int openFlags = 0; /* Flags to pass to open() */ 29573 int eType = flags&0xFFFFFF00; /* Type of file to open */ 29952 int eType = flags&0xFFFFFF00; /* Type of file to open */ 29574 int noLock; /* True to omit locking primitives */ 29953 int noLock; /* True to omit locking primitives */ 29575 int rc = SQLITE_OK; /* Function Return Code */ 29954 int rc = SQLITE_OK; /* Function Return Code */ > 29955 int ctrlFlags = 0; /* UNIXFILE_* flags */ 29576 29956 29577 int isExclusive = (flags & SQLITE_OPEN_EXCLUSIVE); 29957 int isExclusive = (flags & SQLITE_OPEN_EXCLUSIVE); 29578 int isDelete = (flags & SQLITE_OPEN_DELETEONCLOSE); 29958 int isDelete = (flags & SQLITE_OPEN_DELETEONCLOSE); 29579 int isCreate = (flags & SQLITE_OPEN_CREATE); 29959 int isCreate = (flags & SQLITE_OPEN_CREATE); 29580 int isReadonly = (flags & SQLITE_OPEN_READONLY); 29960 int isReadonly = (flags & SQLITE_OPEN_READONLY); 29581 int isReadWrite = (flags & SQLITE_OPEN_READWRITE); 29961 int isReadWrite = (flags & SQLITE_OPEN_READWRITE); 29582 #if SQLITE_ENABLE_LOCKING_STYLE 29962 #if SQLITE_ENABLE_LOCKING_STYLE ................................................................................................................................................................................ 29595 || eType==SQLITE_OPEN_MAIN_JOURNAL 29975 || eType==SQLITE_OPEN_MAIN_JOURNAL 29596 || eType==SQLITE_OPEN_WAL 29976 || eType==SQLITE_OPEN_WAL 29597 )); 29977 )); 29598 29978 29599 /* If argument zPath is a NULL pointer, this function is required to open 29979 /* If argument zPath is a NULL pointer, this function is required to open 29600 ** a temporary file. Use this buffer to store the file name in. 29980 ** a temporary file. Use this buffer to store the file name in. 29601 */ 29981 */ 29602 char zTmpname[MAX_PATHNAME+1]; | 29982 char zTmpname[MAX_PATHNAME+2]; 29603 const char *zName = zPath; 29983 const char *zName = zPath; 29604 29984 29605 /* Check the following statements are true: 29985 /* Check the following statements are true: 29606 ** 29986 ** 29607 ** (a) Exactly one of the READWRITE and READONLY flags must be set, and 29987 ** (a) Exactly one of the READWRITE and READONLY flags must be set, and 29608 ** (b) if CREATE is set, then READWRITE must also be set, and 29988 ** (b) if CREATE is set, then READWRITE must also be set, and 29609 ** (c) if EXCLUSIVE is set, then CREATE must also be set. 29989 ** (c) if EXCLUSIVE is set, then CREATE must also be set. ................................................................................................................................................................................ 29638 }else{ 30018 }else{ 29639 pUnused = sqlite3_malloc(sizeof(*pUnused)); 30019 pUnused = sqlite3_malloc(sizeof(*pUnused)); 29640 if( !pUnused ){ 30020 if( !pUnused ){ 29641 return SQLITE_NOMEM; 30021 return SQLITE_NOMEM; 29642 } 30022 } 29643 } 30023 } 29644 p->pUnused = pUnused; 30024 p->pUnused = pUnused; > 30025 > 30026 /* Database filenames are double-zero terminated if they are not > 30027 ** URIs with parameters. Hence, they can always be passed into > 30028 ** sqlite3_uri_parameter(). */ > 30029 assert( (flags & SQLITE_OPEN_URI) || zName[strlen(zName)+1]==0 ); > 30030 29645 }else if( !zName ){ 30031 }else if( !zName ){ 29646 /* If zName is NULL, the upper layer is requesting a temp file. */ 30032 /* If zName is NULL, the upper layer is requesting a temp file. */ 29647 assert(isDelete && !syncDir); 30033 assert(isDelete && !syncDir); 29648 rc = unixGetTempname(MAX_PATHNAME+1, zTmpname); | 30034 rc = unixGetTempname(MAX_PATHNAME+2, zTmpname); 29649 if( rc!=SQLITE_OK ){ 30035 if( rc!=SQLITE_OK ){ 29650 return rc; 30036 return rc; 29651 } 30037 } 29652 zName = zTmpname; 30038 zName = zTmpname; > 30039 > 30040 /* Generated temporary filenames are always double-zero terminated > 30041 ** for use by sqlite3_uri_parameter(). */ > 30042 assert( zName[strlen(zName)+1]==0 ); 29653 } 30043 } 29654 30044 29655 /* Determine the value of the flags parameter passed to POSIX function 30045 /* Determine the value of the flags parameter passed to POSIX function 29656 ** open(). These must be calculated even if open() is not called, as 30046 ** open(). These must be calculated even if open() is not called, as 29657 ** they may be stored as part of the file handle and used by the 30047 ** they may be stored as part of the file handle and used by the 29658 ** 'conch file' locking functions later on. */ 30048 ** 'conch file' locking functions later on. */ 29659 if( isReadonly ) openFlags |= O_RDONLY; 30049 if( isReadonly ) openFlags |= O_RDONLY; ................................................................................................................................................................................ 29723 return SQLITE_IOERR_ACCESS; 30113 return SQLITE_IOERR_ACCESS; 29724 } 30114 } 29725 if (0 == strncmp("msdos", fsInfo.f_fstypename, 5)) { 30115 if (0 == strncmp("msdos", fsInfo.f_fstypename, 5)) { 29726 ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS; 30116 ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS; 29727 } 30117 } 29728 #endif 30118 #endif 29729 30119 > 30120 /* Set up appropriate ctrlFlags */ > 30121 if( isDelete ) ctrlFlags |= UNIXFILE_DELETE; > 30122 if( isReadonly ) ctrlFlags |= UNIXFILE_RDONLY; > 30123 if( noLock ) ctrlFlags |= UNIXFILE_NOLOCK; > 30124 if( syncDir ) ctrlFlags |= UNIXFILE_DIRSYNC; > 30125 if( flags & SQLITE_OPEN_URI ) ctrlFlags |= UNIXFILE_URI; > 30126 29730 #if SQLITE_ENABLE_LOCKING_STYLE 30127 #if SQLITE_ENABLE_LOCKING_STYLE 29731 #if SQLITE_PREFER_PROXY_LOCKING 30128 #if SQLITE_PREFER_PROXY_LOCKING 29732 isAutoProxy = 1; 30129 isAutoProxy = 1; 29733 #endif 30130 #endif 29734 if( isAutoProxy && (zPath!=NULL) && (!noLock) && pVfs->xOpen ){ 30131 if( isAutoProxy && (zPath!=NULL) && (!noLock) && pVfs->xOpen ){ 29735 char *envforce = getenv("SQLITE_FORCE_PROXY_LOCKING"); 30132 char *envforce = getenv("SQLITE_FORCE_PROXY_LOCKING"); 29736 int useProxy = 0; 30133 int useProxy = 0; ................................................................................................................................................................................ 29752 robust_close(p, fd, __LINE__); 30149 robust_close(p, fd, __LINE__); 29753 rc = SQLITE_IOERR_ACCESS; 30150 rc = SQLITE_IOERR_ACCESS; 29754 goto open_finished; 30151 goto open_finished; 29755 } 30152 } 29756 useProxy = !(fsInfo.f_flags&MNT_LOCAL); 30153 useProxy = !(fsInfo.f_flags&MNT_LOCAL); 29757 } 30154 } 29758 if( useProxy ){ 30155 if( useProxy ){ 29759 rc = fillInUnixFile(pVfs, fd, syncDir, pFile, zPath, noLock, | 30156 rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags); 29760 isDelete, isReadonly); < 29761 if( rc==SQLITE_OK ){ 30157 if( rc==SQLITE_OK ){ 29762 rc = proxyTransformUnixFile((unixFile*)pFile, ":auto:"); 30158 rc = proxyTransformUnixFile((unixFile*)pFile, ":auto:"); 29763 if( rc!=SQLITE_OK ){ 30159 if( rc!=SQLITE_OK ){ 29764 /* Use unixClose to clean up the resources added in fillInUnixFile 30160 /* Use unixClose to clean up the resources added in fillInUnixFile 29765 ** and clear all the structure's references. Specifically, 30161 ** and clear all the structure's references. Specifically, 29766 ** pFile->pMethods will be NULL so sqlite3OsClose will be a no-op 30162 ** pFile->pMethods will be NULL so sqlite3OsClose will be a no-op 29767 */ 30163 */ ................................................................................................................................................................................ 29770 } 30166 } 29771 } 30167 } 29772 goto open_finished; 30168 goto open_finished; 29773 } 30169 } 29774 } 30170 } 29775 #endif 30171 #endif 29776 30172 29777 rc = fillInUnixFile(pVfs, fd, syncDir, pFile, zPath, noLock, | 30173 rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags); 29778 isDelete, isReadonly); < > 30174 29779 open_finished: 30175 open_finished: 29780 if( rc!=SQLITE_OK ){ 30176 if( rc!=SQLITE_OK ){ 29781 sqlite3_free(p->pUnused); 30177 sqlite3_free(p->pUnused); 29782 } 30178 } 29783 return rc; 30179 return rc; 29784 } 30180 } 29785 30181 ................................................................................................................................................................................ 29796 int rc = SQLITE_OK; 30192 int rc = SQLITE_OK; 29797 UNUSED_PARAMETER(NotUsed); 30193 UNUSED_PARAMETER(NotUsed); 29798 SimulateIOError(return SQLITE_IOERR_DELETE); 30194 SimulateIOError(return SQLITE_IOERR_DELETE); 29799 if( osUnlink(zPath)==(-1) && errno!=ENOENT ){ 30195 if( osUnlink(zPath)==(-1) && errno!=ENOENT ){ 29800 return unixLogError(SQLITE_IOERR_DELETE, "unlink", zPath); 30196 return unixLogError(SQLITE_IOERR_DELETE, "unlink", zPath); 29801 } 30197 } 29802 #ifndef SQLITE_DISABLE_DIRSYNC 30198 #ifndef SQLITE_DISABLE_DIRSYNC 29803 if( dirSync ){ | 30199 if( (dirSync & 1)!=0 ){ 29804 int fd; 30200 int fd; 29805 rc = osOpenDirectory(zPath, &fd); 30201 rc = osOpenDirectory(zPath, &fd); 29806 if( rc==SQLITE_OK ){ 30202 if( rc==SQLITE_OK ){ 29807 #if OS_VXWORKS 30203 #if OS_VXWORKS 29808 if( fsync(fd)==-1 ) 30204 if( fsync(fd)==-1 ) 29809 #else 30205 #else 29810 if( fsync(fd) ) 30206 if( fsync(fd) ) ................................................................................................................................................................................ 30347 buf[0] = lockPath[0]; 30743 buf[0] = lockPath[0]; 30348 for( i=1; i<len; i++ ){ 30744 for( i=1; i<len; i++ ){ 30349 if( lockPath[i] == '/' && (i - start > 0) ){ 30745 if( lockPath[i] == '/' && (i - start > 0) ){ 30350 /* only mkdir if leaf dir != "." or "/" or ".." */ 30746 /* only mkdir if leaf dir != "." or "/" or ".." */ 30351 if( i-start>2 || (i-start==1 && buf[start] != '.' && buf[start] != '/') 30747 if( i-start>2 || (i-start==1 && buf[start] != '.' && buf[start] != '/') 30352 || (i-start==2 && buf[start] != '.' && buf[start+1] != '.') ){ 30748 || (i-start==2 && buf[start] != '.' && buf[start+1] != '.') ){ 30353 buf[i]='\0'; 30749 buf[i]='\0'; 30354 if( mkdir(buf, SQLITE_DEFAULT_PROXYDIR_PERMISSIONS) ){ | 30750 if( osMkdir(buf, SQLITE_DEFAULT_PROXYDIR_PERMISSIONS) ){ 30355 int err=errno; 30751 int err=errno; 30356 if( err!=EEXIST ) { 30752 if( err!=EEXIST ) { 30357 OSTRACE(("CREATELOCKPATH FAILED creating %s, " 30753 OSTRACE(("CREATELOCKPATH FAILED creating %s, " 30358 "'%s' proxy lock path=%s pid=%d\n", 30754 "'%s' proxy lock path=%s pid=%d\n", 30359 buf, strerror(err), lockPath, getpid())); 30755 buf, strerror(err), lockPath, getpid())); 30360 return err; 30756 return err; 30361 } 30757 } ................................................................................................................................................................................ 30442 memset(&dummyVfs, 0, sizeof(dummyVfs)); 30838 memset(&dummyVfs, 0, sizeof(dummyVfs)); 30443 dummyVfs.pAppData = (void*)&autolockIoFinder; 30839 dummyVfs.pAppData = (void*)&autolockIoFinder; 30444 dummyVfs.zName = "dummy"; 30840 dummyVfs.zName = "dummy"; 30445 pUnused->fd = fd; 30841 pUnused->fd = fd; 30446 pUnused->flags = openFlags; 30842 pUnused->flags = openFlags; 30447 pNew->pUnused = pUnused; 30843 pNew->pUnused = pUnused; 30448 30844 30449 rc = fillInUnixFile(&dummyVfs, fd, 0, (sqlite3_file*)pNew, path, 0, 0, 0); | 30845 rc = fillInUnixFile(&dummyVfs, fd, (sqlite3_file*)pNew, path, 0); 30450 if( rc==SQLITE_OK ){ 30846 if( rc==SQLITE_OK ){ 30451 *ppFile = pNew; 30847 *ppFile = pNew; 30452 return SQLITE_OK; 30848 return SQLITE_OK; 30453 } 30849 } 30454 end_create_proxy: 30850 end_create_proxy: 30455 robust_close(pNew, fd, __LINE__); 30851 robust_close(pNew, fd, __LINE__); 30456 sqlite3_free(pNew); 30852 sqlite3_free(pNew); ................................................................................................................................................................................ 31383 UNIXVFS("unix-proxy", proxyIoFinder ), 31779 UNIXVFS("unix-proxy", proxyIoFinder ), 31384 #endif 31780 #endif 31385 }; 31781 }; 31386 unsigned int i; /* Loop counter */ 31782 unsigned int i; /* Loop counter */ 31387 31783 31388 /* Double-check that the aSyscall[] array has been constructed 31784 /* Double-check that the aSyscall[] array has been constructed 31389 ** correctly. See ticket [bb3a86e890c8e96ab] */ 31785 ** correctly. See ticket [bb3a86e890c8e96ab] */ 31390 assert( ArraySize(aSyscall)==18 ); | 31786 assert( ArraySize(aSyscall)==20 ); 31391 31787 31392 /* Register all VFSes defined in the aVfs[] array */ 31788 /* Register all VFSes defined in the aVfs[] array */ 31393 for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){ 31789 for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){ 31394 sqlite3_vfs_register(&aVfs[i], i==0); 31790 sqlite3_vfs_register(&aVfs[i], i==0); 31395 } 31791 } 31396 return SQLITE_OK; 31792 return SQLITE_OK; 31397 } 31793 } ................................................................................................................................................................................ 31419 ** 31815 ** 31420 ** May you do good and not evil. 31816 ** May you do good and not evil. 31421 ** May you find forgiveness for yourself and forgive others. 31817 ** May you find forgiveness for yourself and forgive others. 31422 ** May you share freely, never taking more than you give. 31818 ** May you share freely, never taking more than you give. 31423 ** 31819 ** 31424 ****************************************************************************** 31820 ****************************************************************************** 31425 ** 31821 ** 31426 ** This file contains code that is specific to windows. | 31822 ** This file contains code that is specific to Windows. 31427 */ 31823 */ 31428 #if SQLITE_OS_WIN /* This file is used for windows only */ | 31824 #if SQLITE_OS_WIN /* This file is used for Windows only */ 31429 < 31430 < 31431 /* < 31432 ** A Note About Memory Allocation: < 31433 ** < 31434 ** This driver uses malloc()/free() directly rather than going through < 31435 ** the SQLite-wrappers sqlite3_malloc()/sqlite3_free(). Those wrappers < 31436 ** are designed for use on embedded systems where memory is scarce and < 31437 ** malloc failures happen frequently. Win32 does not typically run on < 31438 ** embedded systems, and when it does the developers normally have bigger < 31439 ** problems to worry about than running out of memory. So there is not < 31440 ** a compelling need to use the wrappers. < 31441 ** < 31442 ** But there is a good reason to not use the wrappers. If we use the < 31443 ** wrappers then we will get simulated malloc() failures within this < 31444 ** driver. And that causes all kinds of problems for our tests. We < 31445 ** could enhance SQLite to deal with simulated malloc failures within < 31446 ** the OS driver, but the code to deal with those failure would not < 31447 ** be exercised on Linux (which does not need to malloc() in the driver) < 31448 ** and so we would have difficulty writing coverage tests for that < 31449 ** code. Better to leave the code out, we think. < 31450 ** < 31451 ** The point of this discussion is as follows: When creating a new < 31452 ** OS layer for an embedded system, if you use this file as an example, < 31453 ** avoid the use of malloc()/free(). Those routines work ok on windows < 31454 ** desktops but not so well in embedded systems. < 31455 */ < 31456 < 31457 #include <winbase.h> < 31458 31825 31459 #ifdef __CYGWIN__ 31826 #ifdef __CYGWIN__ 31460 # include <sys/cygwin.h> 31827 # include <sys/cygwin.h> 31461 #endif 31828 #endif 31462 31829 31463 /* < 31464 ** Macros used to determine whether or not to use threads. < 31465 */ < 31466 #if defined(THREADSAFE) && THREADSAFE < 31467 # define SQLITE_W32_THREADS 1 < 31468 #endif < 31469 < 31470 /* 31830 /* 31471 ** Include code that is common to all os_*.c files 31831 ** Include code that is common to all os_*.c files 31472 */ 31832 */ 31473 /************** Include os_common.h in the middle of os_win.c ****************/ 31833 /************** Include os_common.h in the middle of os_win.c ****************/ 31474 /************** Begin file os_common.h ***************************************/ 31834 /************** Begin file os_common.h ***************************************/ 31475 /* 31835 /* 31476 ** 2004 May 22 31836 ** 2004 May 22 ................................................................................................................................................................................ 31677 32037 31678 #endif /* !defined(_OS_COMMON_H_) */ 32038 #endif /* !defined(_OS_COMMON_H_) */ 31679 32039 31680 /************** End of os_common.h *******************************************/ 32040 /************** End of os_common.h *******************************************/ 31681 /************** Continuing where we left off in os_win.c *********************/ 32041 /************** Continuing where we left off in os_win.c *********************/ 31682 32042 31683 /* 32043 /* 31684 ** Some microsoft compilers lack this definition. | 32044 ** Some Microsoft compilers lack this definition. 31685 */ 32045 */ 31686 #ifndef INVALID_FILE_ATTRIBUTES 32046 #ifndef INVALID_FILE_ATTRIBUTES 31687 # define INVALID_FILE_ATTRIBUTES ((DWORD)-1) 32047 # define INVALID_FILE_ATTRIBUTES ((DWORD)-1) 31688 #endif 32048 #endif 31689 32049 31690 /* < 31691 ** Determine if we are dealing with WindowsCE - which has a much < 31692 ** reduced API. < 31693 */ < 31694 #if SQLITE_OS_WINCE < 31695 # define AreFileApisANSI() 1 < 31696 # define FormatMessageW(a,b,c,d,e,f,g) 0 < 31697 #endif < 31698 < 31699 /* Forward references */ 32050 /* Forward references */ 31700 typedef struct winShm winShm; /* A connection to shared-memory */ 32051 typedef struct winShm winShm; /* A connection to shared-memory */ 31701 typedef struct winShmNode winShmNode; /* A region of shared-memory */ 32052 typedef struct winShmNode winShmNode; /* A region of shared-memory */ 31702 32053 31703 /* 32054 /* 31704 ** WinCE lacks native support for file locking so we have to fake it 32055 ** WinCE lacks native support for file locking so we have to fake it 31705 ** with some code of our own. 32056 ** with some code of our own. ................................................................................................................................................................................ 31720 typedef struct winFile winFile; 32071 typedef struct winFile winFile; 31721 struct winFile { 32072 struct winFile { 31722 const sqlite3_io_methods *pMethod; /*** Must be first ***/ 32073 const sqlite3_io_methods *pMethod; /*** Must be first ***/ 31723 sqlite3_vfs *pVfs; /* The VFS used to open this file */ 32074 sqlite3_vfs *pVfs; /* The VFS used to open this file */ 31724 HANDLE h; /* Handle for accessing the file */ 32075 HANDLE h; /* Handle for accessing the file */ 31725 u8 locktype; /* Type of lock currently held on this file */ 32076 u8 locktype; /* Type of lock currently held on this file */ 31726 short sharedLockByte; /* Randomly chosen byte used as a shared lock */ 32077 short sharedLockByte; /* Randomly chosen byte used as a shared lock */ 31727 u8 bPersistWal; /* True to persist WAL files */ | 32078 u8 ctrlFlags; /* Flags. See WINFILE_* below */ 31728 DWORD lastErrno; /* The Windows errno from the last I/O error */ 32079 DWORD lastErrno; /* The Windows errno from the last I/O error */ 31729 DWORD sectorSize; /* Sector size of the device file is on */ < 31730 winShm *pShm; /* Instance of shared memory on this file */ 32080 winShm *pShm; /* Instance of shared memory on this file */ 31731 const char *zPath; /* Full pathname of this file */ 32081 const char *zPath; /* Full pathname of this file */ 31732 int szChunk; /* Chunk size configured by FCNTL_CHUNK_SIZE */ 32082 int szChunk; /* Chunk size configured by FCNTL_CHUNK_SIZE */ 31733 #if SQLITE_OS_WINCE 32083 #if SQLITE_OS_WINCE 31734 WCHAR *zDeleteOnClose; /* Name of file to delete when closing */ | 32084 LPWSTR zDeleteOnClose; /* Name of file to delete when closing */ 31735 HANDLE hMutex; /* Mutex used to control access to shared lock */ 32085 HANDLE hMutex; /* Mutex used to control access to shared lock */ 31736 HANDLE hShared; /* Shared memory segment used for locking */ 32086 HANDLE hShared; /* Shared memory segment used for locking */ 31737 winceLock local; /* Locks obtained by this instance of winFile */ 32087 winceLock local; /* Locks obtained by this instance of winFile */ 31738 winceLock *shared; /* Global shared lock memory for the file */ 32088 winceLock *shared; /* Global shared lock memory for the file */ 31739 #endif 32089 #endif 31740 }; 32090 }; 31741 32091 > 32092 /* > 32093 ** Allowed values for winFile.ctrlFlags > 32094 */ > 32095 #define WINFILE_PERSIST_WAL 0x04 /* Persistent WAL mode */ > 32096 #define WINFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */ > 32097 31742 /* 32098 /* 31743 * If compiled with SQLITE_WIN32_MALLOC on Windows, we will use the 32099 * If compiled with SQLITE_WIN32_MALLOC on Windows, we will use the 31744 * various Win32 API heap functions instead of our own. 32100 * various Win32 API heap functions instead of our own. 31745 */ 32101 */ 31746 #ifdef SQLITE_WIN32_MALLOC 32102 #ifdef SQLITE_WIN32_MALLOC 31747 /* 32103 /* 31748 * The initial size of the Win32-specific heap. This value may be zero. 32104 * The initial size of the Win32-specific heap. This value may be zero. ................................................................................................................................................................................ 31806 static int winMemRoundup(int n); 32162 static int winMemRoundup(int n); 31807 static int winMemInit(void *pAppData); 32163 static int winMemInit(void *pAppData); 31808 static void winMemShutdown(void *pAppData); 32164 static void winMemShutdown(void *pAppData); 31809 32165 31810 SQLITE_PRIVATE const sqlite3_mem_methods *sqlite3MemGetWin32(void); 32166 SQLITE_PRIVATE const sqlite3_mem_methods *sqlite3MemGetWin32(void); 31811 #endif /* SQLITE_WIN32_MALLOC */ 32167 #endif /* SQLITE_WIN32_MALLOC */ 31812 32168 31813 /* < 31814 ** Forward prototypes. < 31815 */ < 31816 static int getSectorSize( < 31817 sqlite3_vfs *pVfs, < 31818 const char *zRelative /* UTF-8 file name */ < 31819 ); < 31820 < 31821 /* 32169 /* 31822 ** The following variable is (normally) set once and never changes 32170 ** The following variable is (normally) set once and never changes 31823 ** thereafter. It records whether the operating system is Win95 | 32171 ** thereafter. It records whether the operating system is Win9x 31824 ** or WinNT. 32172 ** or WinNT. 31825 ** 32173 ** 31826 ** 0: Operating system unknown. 32174 ** 0: Operating system unknown. 31827 ** 1: Operating system is Win95. | 32175 ** 1: Operating system is Win9x. 31828 ** 2: Operating system is WinNT. 32176 ** 2: Operating system is WinNT. 31829 ** 32177 ** 31830 ** In order to facilitate testing on a WinNT system, the test fixture 32178 ** In order to facilitate testing on a WinNT system, the test fixture 31831 ** can manually set this value to 1 to emulate Win98 behavior. 32179 ** can manually set this value to 1 to emulate Win98 behavior. 31832 */ 32180 */ 31833 #ifdef SQLITE_TEST 32181 #ifdef SQLITE_TEST 31834 SQLITE_API int sqlite3_os_type = 0; 32182 SQLITE_API int sqlite3_os_type = 0; 31835 #else 32183 #else 31836 static int sqlite3_os_type = 0; 32184 static int sqlite3_os_type = 0; 31837 #endif 32185 #endif > 32186 > 32187 /* > 32188 ** Many system calls are accessed through pointer-to-functions so that > 32189 ** they may be overridden at runtime to facilitate fault injection during > 32190 ** testing and sandboxing. The following array holds the names and pointers > 32191 ** to all overrideable system calls. > 32192 */ > 32193 #if !SQLITE_OS_WINCE > 32194 # define SQLITE_WIN32_HAS_ANSI > 32195 #endif > 32196 > 32197 #if SQLITE_OS_WINCE || SQLITE_OS_WINNT > 32198 # define SQLITE_WIN32_HAS_WIDE > 32199 #endif > 32200 > 32201 #ifndef SYSCALL > 32202 # define SYSCALL sqlite3_syscall_ptr > 32203 #endif > 32204 > 32205 #if SQLITE_OS_WINCE > 32206 /* > 32207 ** These macros are necessary because Windows CE does not natively support the > 32208 ** Win32 APIs LockFile, UnlockFile, and LockFileEx. > 32209 */ > 32210 > 32211 # define LockFile(a,b,c,d,e) winceLockFile(&a, b, c, d, e) > 32212 # define UnlockFile(a,b,c,d,e) winceUnlockFile(&a, b, c, d, e) > 32213 # define LockFileEx(a,b,c,d,e,f) winceLockFileEx(&a, b, c, d, e, f) > 32214 > 32215 /* > 32216 ** These are the special syscall hacks for Windows CE. The locking related > 32217 ** defines here refer to the macros defined just above. > 32218 */ > 32219 > 32220 # define osAreFileApisANSI() 1 > 32221 # define osLockFile LockFile > 32222 # define osUnlockFile UnlockFile > 32223 # define osLockFileEx LockFileEx > 32224 #endif > 32225 > 32226 static struct win_syscall { > 32227 const char *zName; /* Name of the sytem call */ > 32228 sqlite3_syscall_ptr pCurrent; /* Current value of the system call */ > 32229 sqlite3_syscall_ptr pDefault; /* Default value */ > 32230 } aSyscall[] = { > 32231 #if !SQLITE_OS_WINCE > 32232 { "AreFileApisANSI", (SYSCALL)AreFileApisANSI, 0 }, > 32233 > 32234 #define osAreFileApisANSI ((BOOL(WINAPI*)(VOID))aSyscall[0].pCurrent) > 32235 #else > 32236 { "AreFileApisANSI", (SYSCALL)0, 0 }, > 32237 #endif > 32238 > 32239 #if SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE) > 32240 { "CharLowerW", (SYSCALL)CharLowerW, 0 }, > 32241 #else > 32242 { "CharLowerW", (SYSCALL)0, 0 }, > 32243 #endif > 32244 > 32245 #define osCharLowerW ((LPWSTR(WINAPI*)(LPWSTR))aSyscall[1].pCurrent) > 32246 > 32247 #if SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE) > 32248 { "CharUpperW", (SYSCALL)CharUpperW, 0 }, > 32249 #else > 32250 { "CharUpperW", (SYSCALL)0, 0 }, > 32251 #endif > 32252 > 32253 #define osCharUpperW ((LPWSTR(WINAPI*)(LPWSTR))aSyscall[2].pCurrent) > 32254 > 32255 { "CloseHandle", (SYSCALL)CloseHandle, 0 }, > 32256 > 32257 #define osCloseHandle ((BOOL(WINAPI*)(HANDLE))aSyscall[3].pCurrent) > 32258 > 32259 #if defined(SQLITE_WIN32_HAS_ANSI) > 32260 { "CreateFileA", (SYSCALL)CreateFileA, 0 }, > 32261 #else > 32262 { "CreateFileA", (SYSCALL)0, 0 }, > 32263 #endif > 32264 > 32265 #define osCreateFileA ((HANDLE(WINAPI*)(LPCSTR,DWORD,DWORD, \ > 32266 LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[4].pCurrent) > 32267 > 32268 #if defined(SQLITE_WIN32_HAS_WIDE) > 32269 { "CreateFileW", (SYSCALL)CreateFileW, 0 }, > 32270 #else > 32271 { "CreateFileW", (SYSCALL)0, 0 }, > 32272 #endif > 32273 > 32274 #define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \ > 32275 LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent) > 32276 > 32277 { "CreateFileMapping", (SYSCALL)CreateFileMapping, 0 }, > 32278 > 32279 #define osCreateFileMapping ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \ > 32280 DWORD,DWORD,DWORD,LPCTSTR))aSyscall[6].pCurrent) > 32281 > 32282 #if defined(SQLITE_WIN32_HAS_WIDE) > 32283 { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 }, > 32284 #else > 32285 { "CreateFileMappingW", (SYSCALL)0, 0 }, > 32286 #endif > 32287 > 32288 #define osCreateFileMappingW ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \ > 32289 DWORD,DWORD,DWORD,LPCWSTR))aSyscall[7].pCurrent) > 32290 > 32291 #if defined(SQLITE_WIN32_HAS_WIDE) > 32292 { "CreateMutexW", (SYSCALL)CreateMutexW, 0 }, > 32293 #else > 32294 { "CreateMutexW", (SYSCALL)0, 0 }, > 32295 #endif > 32296 > 32297 #define osCreateMutexW ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,BOOL, \ > 32298 LPCWSTR))aSyscall[8].pCurrent) > 32299 > 32300 #if defined(SQLITE_WIN32_HAS_ANSI) > 32301 { "DeleteFileA", (SYSCALL)DeleteFileA, 0 }, > 32302 #else > 32303 { "DeleteFileA", (SYSCALL)0, 0 }, > 32304 #endif > 32305 > 32306 #define osDeleteFileA ((BOOL(WINAPI*)(LPCSTR))aSyscall[9].pCurrent) > 32307 > 32308 #if defined(SQLITE_WIN32_HAS_WIDE) > 32309 { "DeleteFileW", (SYSCALL)DeleteFileW, 0 }, > 32310 #else > 32311 { "DeleteFileW", (SYSCALL)0, 0 }, > 32312 #endif > 32313 > 32314 #define osDeleteFileW ((BOOL(WINAPI*)(LPCWSTR))aSyscall[10].pCurrent) > 32315 > 32316 #if SQLITE_OS_WINCE > 32317 { "FileTimeToLocalFileTime", (SYSCALL)FileTimeToLocalFileTime, 0 }, > 32318 #else > 32319 { "FileTimeToLocalFileTime", (SYSCALL)0, 0 }, > 32320 #endif > 32321 > 32322 #define osFileTimeToLocalFileTime ((BOOL(WINAPI*)(CONST FILETIME*, \ > 32323 LPFILETIME))aSyscall[11].pCurrent) > 32324 > 32325 #if SQLITE_OS_WINCE > 32326 { "FileTimeToSystemTime", (SYSCALL)FileTimeToSystemTime, 0 }, > 32327 #else > 32328 { "FileTimeToSystemTime", (SYSCALL)0, 0 }, > 32329 #endif > 32330 > 32331 #define osFileTimeToSystemTime ((BOOL(WINAPI*)(CONST FILETIME*, \ > 32332 LPSYSTEMTIME))aSyscall[12].pCurrent) > 32333 > 32334 { "FlushFileBuffers", (SYSCALL)FlushFileBuffers, 0 }, > 32335 > 32336 #define osFlushFileBuffers ((BOOL(WINAPI*)(HANDLE))aSyscall[13].pCurrent) > 32337 > 32338 #if defined(SQLITE_WIN32_HAS_ANSI) > 32339 { "FormatMessageA", (SYSCALL)FormatMessageA, 0 }, > 32340 #else > 32341 { "FormatMessageA", (SYSCALL)0, 0 }, > 32342 #endif > 32343 > 32344 #define osFormatMessageA ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPSTR, \ > 32345 DWORD,va_list*))aSyscall[14].pCurrent) > 32346 > 32347 #if defined(SQLITE_WIN32_HAS_WIDE) > 32348 { "FormatMessageW", (SYSCALL)FormatMessageW, 0 }, > 32349 #else > 32350 { "FormatMessageW", (SYSCALL)0, 0 }, > 32351 #endif > 32352 > 32353 #define osFormatMessageW ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPWSTR, \ > 32354 DWORD,va_list*))aSyscall[15].pCurrent) > 32355 > 32356 { "FreeLibrary", (SYSCALL)FreeLibrary, 0 }, > 32357 > 32358 #define osFreeLibrary ((BOOL(WINAPI*)(HMODULE))aSyscall[16].pCurrent) > 32359 > 32360 { "GetCurrentProcessId", (SYSCALL)GetCurrentProcessId, 0 }, > 32361 > 32362 #define osGetCurrentProcessId ((DWORD(WINAPI*)(VOID))aSyscall[17].pCurrent) > 32363 > 32364 #if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_ANSI) > 32365 { "GetDiskFreeSpaceA", (SYSCALL)GetDiskFreeSpaceA, 0 }, > 32366 #else > 32367 { "GetDiskFreeSpaceA", (SYSCALL)0, 0 }, > 32368 #endif > 32369 > 32370 #define osGetDiskFreeSpaceA ((BOOL(WINAPI*)(LPCSTR,LPDWORD,LPDWORD,LPDWORD, \ > 32371 LPDWORD))aSyscall[18].pCurrent) > 32372 > 32373 #if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE) > 32374 { "GetDiskFreeSpaceW", (SYSCALL)GetDiskFreeSpaceW, 0 }, > 32375 #else > 32376 { "GetDiskFreeSpaceW", (SYSCALL)0, 0 }, > 32377 #endif > 32378 > 32379 #define osGetDiskFreeSpaceW ((BOOL(WINAPI*)(LPCWSTR,LPDWORD,LPDWORD,LPDWORD, \ > 32380 LPDWORD))aSyscall[19].pCurrent) > 32381 > 32382 #if defined(SQLITE_WIN32_HAS_ANSI) > 32383 { "GetFileAttributesA", (SYSCALL)GetFileAttributesA, 0 }, > 32384 #else > 32385 { "GetFileAttributesA", (SYSCALL)0, 0 }, > 32386 #endif > 32387 > 32388 #define osGetFileAttributesA ((DWORD(WINAPI*)(LPCSTR))aSyscall[20].pCurrent) > 32389 > 32390 #if defined(SQLITE_WIN32_HAS_WIDE) > 32391 { "GetFileAttributesW", (SYSCALL)GetFileAttributesW, 0 }, > 32392 #else > 32393 { "GetFileAttributesW", (SYSCALL)0, 0 }, > 32394 #endif > 32395 > 32396 #define osGetFileAttributesW ((DWORD(WINAPI*)(LPCWSTR))aSyscall[21].pCurrent) > 32397 > 32398 #if defined(SQLITE_WIN32_HAS_WIDE) > 32399 { "GetFileAttributesExW", (SYSCALL)GetFileAttributesExW, 0 }, > 32400 #else > 32401 { "GetFileAttributesExW", (SYSCALL)0, 0 }, > 32402 #endif > 32403 > 32404 #define osGetFileAttributesExW ((BOOL(WINAPI*)(LPCWSTR,GET_FILEEX_INFO_LEVELS, \ > 32405 LPVOID))aSyscall[22].pCurrent) > 32406 > 32407 { "GetFileSize", (SYSCALL)GetFileSize, 0 }, > 32408 > 32409 #define osGetFileSize ((DWORD(WINAPI*)(HANDLE,LPDWORD))aSyscall[23].pCurrent) > 32410 > 32411 #if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_ANSI) > 32412 { "GetFullPathNameA", (SYSCALL)GetFullPathNameA, 0 }, > 32413 #else > 32414 { "GetFullPathNameA", (SYSCALL)0, 0 }, > 32415 #endif > 32416 > 32417 #define osGetFullPathNameA ((DWORD(WINAPI*)(LPCSTR,DWORD,LPSTR, \ > 32418 LPSTR*))aSyscall[24].pCurrent) > 32419 > 32420 #if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE) > 32421 { "GetFullPathNameW", (SYSCALL)GetFullPathNameW, 0 }, > 32422 #else > 32423 { "GetFullPathNameW", (SYSCALL)0, 0 }, > 32424 #endif > 32425 > 32426 #define osGetFullPathNameW ((DWORD(WINAPI*)(LPCWSTR,DWORD,LPWSTR, \ > 32427 LPWSTR*))aSyscall[25].pCurrent) > 32428 > 32429 { "GetLastError", (SYSCALL)GetLastError, 0 }, > 32430 > 32431 #define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[26].pCurrent) > 32432 > 32433 #if SQLITE_OS_WINCE > 32434 /* The GetProcAddressA() routine is only available on Windows CE. */ > 32435 { "GetProcAddressA", (SYSCALL)GetProcAddressA, 0 }, > 32436 #else > 32437 /* All other Windows platforms expect GetProcAddress() to take > 32438 ** an ANSI string regardless of the _UNICODE setting */ > 32439 { "GetProcAddressA", (SYSCALL)GetProcAddress, 0 }, > 32440 #endif > 32441 > 32442 #define osGetProcAddressA ((FARPROC(WINAPI*)(HMODULE, \ > 32443 LPCSTR))aSyscall[27].pCurrent) > 32444 > 32445 { "GetSystemInfo", (SYSCALL)GetSystemInfo, 0 }, > 32446 > 32447 #define osGetSystemInfo ((VOID(WINAPI*)(LPSYSTEM_INFO))aSyscall[28].pCurrent) > 32448 > 32449 { "GetSystemTime", (SYSCALL)GetSystemTime, 0 }, > 32450 > 32451 #define osGetSystemTime ((VOID(WINAPI*)(LPSYSTEMTIME))aSyscall[29].pCurrent) > 32452 > 32453 #if !SQLITE_OS_WINCE > 32454 { "GetSystemTimeAsFileTime", (SYSCALL)GetSystemTimeAsFileTime, 0 }, > 32455 #else > 32456 { "GetSystemTimeAsFileTime", (SYSCALL)0, 0 }, > 32457 #endif > 32458 > 32459 #define osGetSystemTimeAsFileTime ((VOID(WINAPI*)( \ > 32460 LPFILETIME))aSyscall[30].pCurrent) > 32461 > 32462 #if defined(SQLITE_WIN32_HAS_ANSI) > 32463 { "GetTempPathA", (SYSCALL)GetTempPathA, 0 }, > 32464 #else > 32465 { "GetTempPathA", (SYSCALL)0, 0 }, > 32466 #endif > 32467 > 32468 #define osGetTempPathA ((DWORD(WINAPI*)(DWORD,LPSTR))aSyscall[31].pCurrent) > 32469 > 32470 #if defined(SQLITE_WIN32_HAS_WIDE) > 32471 { "GetTempPathW", (SYSCALL)GetTempPathW, 0 }, > 32472 #else > 32473 { "GetTempPathW", (SYSCALL)0, 0 }, > 32474 #endif > 32475 > 32476 #define osGetTempPathW ((DWORD(WINAPI*)(DWORD,LPWSTR))aSyscall[32].pCurrent) > 32477 > 32478 { "GetTickCount", (SYSCALL)GetTickCount, 0 }, > 32479 > 32480 #define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[33].pCurrent) > 32481 > 32482 #if defined(SQLITE_WIN32_HAS_ANSI) > 32483 { "GetVersionExA", (SYSCALL)GetVersionExA, 0 }, > 32484 #else > 32485 { "GetVersionExA", (SYSCALL)0, 0 }, > 32486 #endif > 32487 > 32488 #define osGetVersionExA ((BOOL(WINAPI*)( \ > 32489 LPOSVERSIONINFOA))aSyscall[34].pCurrent) > 32490 > 32491 { "HeapAlloc", (SYSCALL)HeapAlloc, 0 }, > 32492 > 32493 #define osHeapAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD, \ > 32494 SIZE_T))aSyscall[35].pCurrent) > 32495 > 32496 { "HeapCreate", (SYSCALL)HeapCreate, 0 }, > 32497 > 32498 #define osHeapCreate ((HANDLE(WINAPI*)(DWORD,SIZE_T, \ > 32499 SIZE_T))aSyscall[36].pCurrent) > 32500 > 32501 { "HeapDestroy", (SYSCALL)HeapDestroy, 0 }, > 32502 > 32503 #define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[37].pCurrent) > 32504 > 32505 { "HeapFree", (SYSCALL)HeapFree, 0 }, > 32506 > 32507 #define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[38].pCurrent) > 32508 > 32509 { "HeapReAlloc", (SYSCALL)HeapReAlloc, 0 }, > 32510 > 32511 #define osHeapReAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD,LPVOID, \ > 32512 SIZE_T))aSyscall[39].pCurrent) > 32513 > 32514 { "HeapSize", (SYSCALL)HeapSize, 0 }, > 32515 > 32516 #define osHeapSize ((SIZE_T(WINAPI*)(HANDLE,DWORD, \ > 32517 LPCVOID))aSyscall[40].pCurrent) > 32518 > 32519 { "HeapValidate", (SYSCALL)HeapValidate, 0 }, > 32520 > 32521 #define osHeapValidate ((BOOL(WINAPI*)(HANDLE,DWORD, \ > 32522 LPCVOID))aSyscall[41].pCurrent) > 32523 > 32524 #if defined(SQLITE_WIN32_HAS_ANSI) > 32525 { "LoadLibraryA", (SYSCALL)LoadLibraryA, 0 }, > 32526 #else > 32527 { "LoadLibraryA", (SYSCALL)0, 0 }, > 32528 #endif > 32529 > 32530 #define osLoadLibraryA ((HMODULE(WINAPI*)(LPCSTR))aSyscall[42].pCurrent) > 32531 > 32532 #if defined(SQLITE_WIN32_HAS_WIDE) > 32533 { "LoadLibraryW", (SYSCALL)LoadLibraryW, 0 }, > 32534 #else > 32535 { "LoadLibraryW", (SYSCALL)0, 0 }, > 32536 #endif > 32537 > 32538 #define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[43].pCurrent) > 32539 > 32540 { "LocalFree", (SYSCALL)LocalFree, 0 }, > 32541 > 32542 #define osLocalFree ((HLOCAL(WINAPI*)(HLOCAL))aSyscall[44].pCurrent) > 32543 > 32544 #if !SQLITE_OS_WINCE > 32545 { "LockFile", (SYSCALL)LockFile, 0 }, > 32546 > 32547 #define osLockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \ > 32548 DWORD))aSyscall[45].pCurrent) > 32549 #else > 32550 { "LockFile", (SYSCALL)0, 0 }, > 32551 #endif > 32552 > 32553 #if !SQLITE_OS_WINCE > 32554 { "LockFileEx", (SYSCALL)LockFileEx, 0 }, > 32555 > 32556 #define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \ > 32557 LPOVERLAPPED))aSyscall[46].pCurrent) > 32558 #else > 32559 { "LockFileEx", (SYSCALL)0, 0 }, > 32560 #endif > 32561 > 32562 { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 }, > 32563 > 32564 #define osMapViewOfFile ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \ > 32565 SIZE_T))aSyscall[47].pCurrent) > 32566 > 32567 { "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 }, > 32568 > 32569 #define osMultiByteToWideChar ((int(WINAPI*)(UINT,DWORD,LPCSTR,int,LPWSTR, \ > 32570 int))aSyscall[48].pCurrent) > 32571 > 32572 { "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 }, > 32573 > 32574 #define osQueryPerformanceCounter ((BOOL(WINAPI*)( \ > 32575 LARGE_INTEGER*))aSyscall[49].pCurrent) > 32576 > 32577 { "ReadFile", (SYSCALL)ReadFile, 0 }, > 32578 > 32579 #define osReadFile ((BOOL(WINAPI*)(HANDLE,LPVOID,DWORD,LPDWORD, \ > 32580 LPOVERLAPPED))aSyscall[50].pCurrent) > 32581 > 32582 { "SetEndOfFile", (SYSCALL)SetEndOfFile, 0 }, > 32583 > 32584 #define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[51].pCurrent) > 32585 > 32586 { "SetFilePointer", (SYSCALL)SetFilePointer, 0 }, > 32587 > 32588 #define osSetFilePointer ((DWORD(WINAPI*)(HANDLE,LONG,PLONG, \ > 32589 DWORD))aSyscall[52].pCurrent) > 32590 > 32591 { "Sleep", (SYSCALL)Sleep, 0 }, > 32592 > 32593 #define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[53].pCurrent) > 32594 > 32595 { "SystemTimeToFileTime", (SYSCALL)SystemTimeToFileTime, 0 }, > 32596 > 32597 #define osSystemTimeToFileTime ((BOOL(WINAPI*)(CONST SYSTEMTIME*, \ > 32598 LPFILETIME))aSyscall[54].pCurrent) > 32599 > 32600 #if !SQLITE_OS_WINCE > 32601 { "UnlockFile", (SYSCALL)UnlockFile, 0 }, > 32602 > 32603 #define osUnlockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \ > 32604 DWORD))aSyscall[55].pCurrent) > 32605 #else > 32606 { "UnlockFile", (SYSCALL)0, 0 }, > 32607 #endif > 32608 > 32609 #if !SQLITE_OS_WINCE > 32610 { "UnlockFileEx", (SYSCALL)UnlockFileEx, 0 }, > 32611 > 32612 #define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \ > 32613 LPOVERLAPPED))aSyscall[56].pCurrent) > 32614 #else > 32615 { "UnlockFileEx", (SYSCALL)0, 0 }, > 32616 #endif > 32617 > 32618 { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 }, > 32619 > 32620 #define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[57].pCurrent) > 32621 > 32622 { "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 }, > 32623 > 32624 #define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \ > 32625 LPCSTR,LPBOOL))aSyscall[58].pCurrent) > 32626 > 32627 { "WriteFile", (SYSCALL)WriteFile, 0 }, > 32628 > 32629 #define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \ > 32630 LPOVERLAPPED))aSyscall[59].pCurrent) > 32631 > 32632 }; /* End of the overrideable system calls */ > 32633 > 32634 /* > 32635 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the > 32636 ** "win32" VFSes. Return SQLITE_OK opon successfully updating the > 32637 ** system call pointer, or SQLITE_NOTFOUND if there is no configurable > 32638 ** system call named zName. > 32639 */ > 32640 static int winSetSystemCall( > 32641 sqlite3_vfs *pNotUsed, /* The VFS pointer. Not used */ > 32642 const char *zName, /* Name of system call to override */ > 32643 sqlite3_syscall_ptr pNewFunc /* Pointer to new system call value */ > 32644 ){ > 32645 unsigned int i; > 32646 int rc = SQLITE_NOTFOUND; > 32647 > 32648 UNUSED_PARAMETER(pNotUsed); > 32649 if( zName==0 ){ > 32650 /* If no zName is given, restore all system calls to their default > 32651 ** settings and return NULL > 32652 */ > 32653 rc = SQLITE_OK; > 32654 for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){ > 32655 if( aSyscall[i].pDefault ){ > 32656 aSyscall[i].pCurrent = aSyscall[i].pDefault; > 32657 } > 32658 } > 32659 }else{ > 32660 /* If zName is specified, operate on only the one system call > 32661 ** specified. > 32662 */ > 32663 for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){ > 32664 if( strcmp(zName, aSyscall[i].zName)==0 ){ > 32665 if( aSyscall[i].pDefault==0 ){ > 32666 aSyscall[i].pDefault = aSyscall[i].pCurrent; > 32667 } > 32668 rc = SQLITE_OK; > 32669 if( pNewFunc==0 ) pNewFunc = aSyscall[i].pDefault; > 32670 aSyscall[i].pCurrent = pNewFunc; > 32671 break; > 32672 } > 32673 } > 32674 } > 32675 return rc; > 32676 } > 32677 > 32678 /* > 32679 ** Return the value of a system call. Return NULL if zName is not a > 32680 ** recognized system call name. NULL is also returned if the system call > 32681 ** is currently undefined. > 32682 */ > 32683 static sqlite3_syscall_ptr winGetSystemCall( > 32684 sqlite3_vfs *pNotUsed, > 32685 const char *zName > 32686 ){ > 32687 unsigned int i; > 32688 > 32689 UNUSED_PARAMETER(pNotUsed); > 32690 for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){ > 32691 if( strcmp(zName, aSyscall[i].zName)==0 ) return aSyscall[i].pCurrent; > 32692 } > 32693 return 0; > 32694 } > 32695 > 32696 /* > 32697 ** Return the name of the first system call after zName. If zName==NULL > 32698 ** then return the name of the first system call. Return NULL if zName > 32699 ** is the last system call or if zName is not the name of a valid > 32700 ** system call. > 32701 */ > 32702 static const char *winNextSystemCall(sqlite3_vfs *p, const char *zName){ > 32703 int i = -1; > 32704 > 32705 UNUSED_PARAMETER(p); > 32706 if( zName ){ > 32707 for(i=0; i<ArraySize(aSyscall)-1; i++){ > 32708 if( strcmp(zName, aSyscall[i].zName)==0 ) break; > 32709 } > 32710 } > 32711 for(i++; i<ArraySize(aSyscall); i++){ > 32712 if( aSyscall[i].pCurrent!=0 ) return aSyscall[i].zName; > 32713 } > 32714 return 0; > 32715 } 31838 32716 31839 /* 32717 /* 31840 ** Return true (non-zero) if we are running under WinNT, Win2K, WinXP, 32718 ** Return true (non-zero) if we are running under WinNT, Win2K, WinXP, 31841 ** or WinCE. Return false (zero) for Win95, Win98, or WinME. 32719 ** or WinCE. Return false (zero) for Win95, Win98, or WinME. 31842 ** 32720 ** 31843 ** Here is an interesting observation: Win95, Win98, and WinME lack 32721 ** Here is an interesting observation: Win95, Win98, and WinME lack 31844 ** the LockFileEx() API. But we can still statically link against that 32722 ** the LockFileEx() API. But we can still statically link against that ................................................................................................................................................................................ 31848 ** the LockFileEx() API. 32726 ** the LockFileEx() API. 31849 */ 32727 */ 31850 #if SQLITE_OS_WINCE 32728 #if SQLITE_OS_WINCE 31851 # define isNT() (1) 32729 # define isNT() (1) 31852 #else 32730 #else 31853 static int isNT(void){ 32731 static int isNT(void){ 31854 if( sqlite3_os_type==0 ){ 32732 if( sqlite3_os_type==0 ){ 31855 OSVERSIONINFO sInfo; | 32733 OSVERSIONINFOA sInfo; 31856 sInfo.dwOSVersionInfoSize = sizeof(sInfo); 32734 sInfo.dwOSVersionInfoSize = sizeof(sInfo); 31857 GetVersionEx(&sInfo); | 32735 osGetVersionExA(&sInfo); 31858 sqlite3_os_type = sInfo.dwPlatformId==VER_PLATFORM_WIN32_NT ? 2 : 1; 32736 sqlite3_os_type = sInfo.dwPlatformId==VER_PLATFORM_WIN32_NT ? 2 : 1; 31859 } 32737 } 31860 return sqlite3_os_type==2; 32738 return sqlite3_os_type==2; 31861 } 32739 } 31862 #endif /* SQLITE_OS_WINCE */ 32740 #endif /* SQLITE_OS_WINCE */ 31863 32741 31864 #ifdef SQLITE_WIN32_MALLOC 32742 #ifdef SQLITE_WIN32_MALLOC ................................................................................................................................................................................ 31870 void *p; 32748 void *p; 31871 32749 31872 winMemAssertMagic(); 32750 winMemAssertMagic(); 31873 hHeap = winMemGetHeap(); 32751 hHeap = winMemGetHeap(); 31874 assert( hHeap!=0 ); 32752 assert( hHeap!=0 ); 31875 assert( hHeap!=INVALID_HANDLE_VALUE ); 32753 assert( hHeap!=INVALID_HANDLE_VALUE ); 31876 #ifdef SQLITE_WIN32_MALLOC_VALIDATE 32754 #ifdef SQLITE_WIN32_MALLOC_VALIDATE 31877 assert ( HeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) ); | 32755 assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) ); 31878 #endif 32756 #endif 31879 assert( nBytes>=0 ); 32757 assert( nBytes>=0 ); 31880 p = HeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes); | 32758 p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes); 31881 if( !p ){ 32759 if( !p ){ 31882 sqlite3_log(SQLITE_NOMEM, "failed to HeapAlloc %u bytes (%d), heap=%p", 32760 sqlite3_log(SQLITE_NOMEM, "failed to HeapAlloc %u bytes (%d), heap=%p", 31883 nBytes, GetLastError(), (void*)hHeap); | 32761 nBytes, osGetLastError(), (void*)hHeap); 31884 } 32762 } 31885 return p; 32763 return p; 31886 } 32764 } 31887 32765 31888 /* 32766 /* 31889 ** Free memory. 32767 ** Free memory. 31890 */ 32768 */ ................................................................................................................................................................................ 31892 HANDLE hHeap; 32770 HANDLE hHeap; 31893 32771 31894 winMemAssertMagic(); 32772 winMemAssertMagic(); 31895 hHeap = winMemGetHeap(); 32773 hHeap = winMemGetHeap(); 31896 assert( hHeap!=0 ); 32774 assert( hHeap!=0 ); 31897 assert( hHeap!=INVALID_HANDLE_VALUE ); 32775 assert( hHeap!=INVALID_HANDLE_VALUE ); 31898 #ifdef SQLITE_WIN32_MALLOC_VALIDATE 32776 #ifdef SQLITE_WIN32_MALLOC_VALIDATE 31899 assert ( HeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ); | 32777 assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ); 31900 #endif 32778 #endif 31901 if( !pPrior ) return; /* Passing NULL to HeapFree is undefined. */ 32779 if( !pPrior ) return; /* Passing NULL to HeapFree is undefined. */ 31902 if( !HeapFree(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ){ | 32780 if( !osHeapFree(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ){ 31903 sqlite3_log(SQLITE_NOMEM, "failed to HeapFree block %p (%d), heap=%p", 32781 sqlite3_log(SQLITE_NOMEM, "failed to HeapFree block %p (%d), heap=%p", 31904 pPrior, GetLastError(), (void*)hHeap); | 32782 pPrior, osGetLastError(), (void*)hHeap); 31905 } 32783 } 31906 } 32784 } 31907 32785 31908 /* 32786 /* 31909 ** Change the size of an existing memory allocation 32787 ** Change the size of an existing memory allocation 31910 */ 32788 */ 31911 static void *winMemRealloc(void *pPrior, int nBytes){ 32789 static void *winMemRealloc(void *pPrior, int nBytes){ ................................................................................................................................................................................ 31913 void *p; 32791 void *p; 31914 32792 31915 winMemAssertMagic(); 32793 winMemAssertMagic(); 31916 hHeap = winMemGetHeap(); 32794 hHeap = winMemGetHeap(); 31917 assert( hHeap!=0 ); 32795 assert( hHeap!=0 ); 31918 assert( hHeap!=INVALID_HANDLE_VALUE ); 32796 assert( hHeap!=INVALID_HANDLE_VALUE ); 31919 #ifdef SQLITE_WIN32_MALLOC_VALIDATE 32797 #ifdef SQLITE_WIN32_MALLOC_VALIDATE 31920 assert ( HeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ); | 32798 assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ); 31921 #endif 32799 #endif 31922 assert( nBytes>=0 ); 32800 assert( nBytes>=0 ); 31923 if( !pPrior ){ 32801 if( !pPrior ){ 31924 p = HeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes); | 32802 p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes); 31925 }else{ 32803 }else{ 31926 p = HeapReAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior, (SIZE_T)nBytes); | 32804 p = osHeapReAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior, (SIZE_T)nBytes); 31927 } 32805 } 31928 if( !p ){ 32806 if( !p ){ 31929 sqlite3_log(SQLITE_NOMEM, "failed to %s %u bytes (%d), heap=%p", 32807 sqlite3_log(SQLITE_NOMEM, "failed to %s %u bytes (%d), heap=%p", 31930 pPrior ? "HeapReAlloc" : "HeapAlloc", nBytes, GetLastError(), | 32808 pPrior ? "HeapReAlloc" : "HeapAlloc", nBytes, osGetLastError(), 31931 (void*)hHeap); | 32809 (void*)hHeap); 31932 } 32810 } 31933 return p; 32811 return p; 31934 } 32812 } 31935 32813 31936 /* 32814 /* 31937 ** Return the size of an outstanding allocation, in bytes. 32815 ** Return the size of an outstanding allocation, in bytes. 31938 */ 32816 */ ................................................................................................................................................................................ 31941 SIZE_T n; 32819 SIZE_T n; 31942 32820 31943 winMemAssertMagic(); 32821 winMemAssertMagic(); 31944 hHeap = winMemGetHeap(); 32822 hHeap = winMemGetHeap(); 31945 assert( hHeap!=0 ); 32823 assert( hHeap!=0 ); 31946 assert( hHeap!=INVALID_HANDLE_VALUE ); 32824 assert( hHeap!=INVALID_HANDLE_VALUE ); 31947 #ifdef SQLITE_WIN32_MALLOC_VALIDATE 32825 #ifdef SQLITE_WIN32_MALLOC_VALIDATE 31948 assert ( HeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) ); | 32826 assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) ); 31949 #endif 32827 #endif 31950 if( !p ) return 0; 32828 if( !p ) return 0; 31951 n = HeapSize(hHeap, SQLITE_WIN32_HEAP_FLAGS, p); | 32829 n = osHeapSize(hHeap, SQLITE_WIN32_HEAP_FLAGS, p); 31952 if( n==(SIZE_T)-1 ){ 32830 if( n==(SIZE_T)-1 ){ 31953 sqlite3_log(SQLITE_NOMEM, "failed to HeapSize block %p (%d), heap=%p", 32831 sqlite3_log(SQLITE_NOMEM, "failed to HeapSize block %p (%d), heap=%p", 31954 p, GetLastError(), (void*)hHeap); | 32832 p, osGetLastError(), (void*)hHeap); 31955 return 0; 32833 return 0; 31956 } 32834 } 31957 return (int)n; 32835 return (int)n; 31958 } 32836 } 31959 32837 31960 /* 32838 /* 31961 ** Round up a request size to the next valid allocation size. 32839 ** Round up a request size to the next valid allocation size. ................................................................................................................................................................................ 31969 */ 32847 */ 31970 static int winMemInit(void *pAppData){ 32848 static int winMemInit(void *pAppData){ 31971 winMemData *pWinMemData = (winMemData *)pAppData; 32849 winMemData *pWinMemData = (winMemData *)pAppData; 31972 32850 31973 if( !pWinMemData ) return SQLITE_ERROR; 32851 if( !pWinMemData ) return SQLITE_ERROR; 31974 assert( pWinMemData->magic==WINMEM_MAGIC ); 32852 assert( pWinMemData->magic==WINMEM_MAGIC ); 31975 if( !pWinMemData->hHeap ){ 32853 if( !pWinMemData->hHeap ){ 31976 pWinMemData->hHeap = HeapCreate(SQLITE_WIN32_HEAP_FLAGS, | 32854 pWinMemData->hHeap = osHeapCreate(SQLITE_WIN32_HEAP_FLAGS, 31977 SQLITE_WIN32_HEAP_INIT_SIZE, | 32855 SQLITE_WIN32_HEAP_INIT_SIZE, 31978 SQLITE_WIN32_HEAP_MAX_SIZE); | 32856 SQLITE_WIN32_HEAP_MAX_SIZE); 31979 if( !pWinMemData->hHeap ){ 32857 if( !pWinMemData->hHeap ){ 31980 sqlite3_log(SQLITE_NOMEM, 32858 sqlite3_log(SQLITE_NOMEM, 31981 "failed to HeapCreate (%d), flags=%u, initSize=%u, maxSize=%u", 32859 "failed to HeapCreate (%d), flags=%u, initSize=%u, maxSize=%u", 31982 GetLastError(), SQLITE_WIN32_HEAP_FLAGS, SQLITE_WIN32_HEAP_INIT_SIZE, | 32860 osGetLastError(), SQLITE_WIN32_HEAP_FLAGS, 31983 SQLITE_WIN32_HEAP_MAX_SIZE); | 32861 SQLITE_WIN32_HEAP_INIT_SIZE, SQLITE_WIN32_HEAP_MAX_SIZE); 31984 return SQLITE_NOMEM; 32862 return SQLITE_NOMEM; 31985 } 32863 } 31986 pWinMemData->bOwned = TRUE; 32864 pWinMemData->bOwned = TRUE; 31987 } 32865 } 31988 assert( pWinMemData->hHeap!=0 ); 32866 assert( pWinMemData->hHeap!=0 ); 31989 assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE ); 32867 assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE ); 31990 #ifdef SQLITE_WIN32_MALLOC_VALIDATE 32868 #ifdef SQLITE_WIN32_MALLOC_VALIDATE 31991 assert( HeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) ); | 32869 assert( osHeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) ); 31992 #endif 32870 #endif 31993 return SQLITE_OK; 32871 return SQLITE_OK; 31994 } 32872 } 31995 32873 31996 /* 32874 /* 31997 ** Deinitialize this module. 32875 ** Deinitialize this module. 31998 */ 32876 */ ................................................................................................................................................................................ 31999 static void winMemShutdown(void *pAppData){ 32877 static void winMemShutdown(void *pAppData){ 32000 winMemData *pWinMemData = (winMemData *)pAppData; 32878 winMemData *pWinMemData = (winMemData *)pAppData; 32001 32879 32002 if( !pWinMemData ) return; 32880 if( !pWinMemData ) return; 32003 if( pWinMemData->hHeap ){ 32881 if( pWinMemData->hHeap ){ 32004 assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE ); 32882 assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE ); 32005 #ifdef SQLITE_WIN32_MALLOC_VALIDATE 32883 #ifdef SQLITE_WIN32_MALLOC_VALIDATE 32006 assert( HeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) ); | 32884 assert( osHeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) ); 32007 #endif 32885 #endif 32008 if( pWinMemData->bOwned ){ 32886 if( pWinMemData->bOwned ){ 32009 if( !HeapDestroy(pWinMemData->hHeap) ){ | 32887 if( !osHeapDestroy(pWinMemData->hHeap) ){ 32010 sqlite3_log(SQLITE_NOMEM, "failed to HeapDestroy (%d), heap=%p", 32888 sqlite3_log(SQLITE_NOMEM, "failed to HeapDestroy (%d), heap=%p", 32011 GetLastError(), (void*)pWinMemData->hHeap); | 32889 osGetLastError(), (void*)pWinMemData->hHeap); 32012 } 32890 } 32013 pWinMemData->bOwned = FALSE; 32891 pWinMemData->bOwned = FALSE; 32014 } 32892 } 32015 pWinMemData->hHeap = NULL; 32893 pWinMemData->hHeap = NULL; 32016 } 32894 } 32017 } 32895 } 32018 32896 ................................................................................................................................................................................ 32040 32918 32041 SQLITE_PRIVATE void sqlite3MemSetDefault(void){ 32919 SQLITE_PRIVATE void sqlite3MemSetDefault(void){ 32042 sqlite3_config(SQLITE_CONFIG_MALLOC, sqlite3MemGetWin32()); 32920 sqlite3_config(SQLITE_CONFIG_MALLOC, sqlite3MemGetWin32()); 32043 } 32921 } 32044 #endif /* SQLITE_WIN32_MALLOC */ 32922 #endif /* SQLITE_WIN32_MALLOC */ 32045 32923 32046 /* 32924 /* 32047 ** Convert a UTF-8 string to microsoft unicode (UTF-16?). | 32925 ** Convert a UTF-8 string to Microsoft Unicode (UTF-16?). 32048 ** 32926 ** 32049 ** Space to hold the returned string is obtained from malloc. 32927 ** Space to hold the returned string is obtained from malloc. 32050 */ 32928 */ 32051 static WCHAR *utf8ToUnicode(const char *zFilename){ | 32929 static LPWSTR utf8ToUnicode(const char *zFilename){ 32052 int nChar; 32930 int nChar; 32053 WCHAR *zWideFilename; | 32931 LPWSTR zWideFilename; 32054 32932 32055 nChar = MultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0); | 32933 nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0); > 32934 if( nChar==0 ){ > 32935 return 0; > 32936 } 32056 zWideFilename = malloc( nChar*sizeof(zWideFilename[0]) ); | 32937 zWideFilename = sqlite3_malloc( nChar*sizeof(zWideFilename[0]) ); 32057 if( zWideFilename==0 ){ 32938 if( zWideFilename==0 ){ 32058 return 0; 32939 return 0; 32059 } 32940 } 32060 nChar = MultiByteToWideChar(CP_UTF8, 0, zFilename, -1, zWideFilename, nChar); | 32941 nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, zWideFilename, > 32942 nChar); 32061 if( nChar==0 ){ 32943 if( nChar==0 ){ 32062 free(zWideFilename); | 32944 sqlite3_free(zWideFilename); 32063 zWideFilename = 0; 32945 zWideFilename = 0; 32064 } 32946 } 32065 return zWideFilename; 32947 return zWideFilename; 32066 } 32948 } 32067 32949 32068 /* 32950 /* 32069 ** Convert microsoft unicode to UTF-8. Space to hold the returned string is | 32951 ** Convert Microsoft Unicode to UTF-8. Space to hold the returned string is 32070 ** obtained from malloc(). | 32952 ** obtained from sqlite3_malloc(). 32071 */ 32953 */ 32072 static char *unicodeToUtf8(const WCHAR *zWideFilename){ | 32954 static char *unicodeToUtf8(LPCWSTR zWideFilename){ 32073 int nByte; 32955 int nByte; 32074 char *zFilename; 32956 char *zFilename; 32075 32957 32076 nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, 0, 0, 0, 0); | 32958 nByte = osWideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, 0, 0, 0, 0); > 32959 if( nByte == 0 ){ > 32960 return 0; > 32961 } 32077 zFilename = malloc( nByte ); | 32962 zFilename = sqlite3_malloc( nByte ); 32078 if( zFilename==0 ){ 32963 if( zFilename==0 ){ 32079 return 0; 32964 return 0; 32080 } 32965 } 32081 nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, zFilename, nByte, | 32966 nByte = osWideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, zFilename, nByte, 32082 0, 0); | 32967 0, 0); 32083 if( nByte == 0 ){ 32968 if( nByte == 0 ){ 32084 free(zFilename); | 32969 sqlite3_free(zFilename); 32085 zFilename = 0; 32970 zFilename = 0; 32086 } 32971 } 32087 return zFilename; 32972 return zFilename; 32088 } 32973 } 32089 32974 32090 /* 32975 /* 32091 ** Convert an ansi string to microsoft unicode, based on the | 32976 ** Convert an ANSI string to Microsoft Unicode, based on the 32092 ** current codepage settings for file apis. 32977 ** current codepage settings for file apis. 32093 ** 32978 ** 32094 ** Space to hold the returned string is obtained 32979 ** Space to hold the returned string is obtained 32095 ** from malloc. | 32980 ** from sqlite3_malloc. 32096 */ 32981 */ 32097 static WCHAR *mbcsToUnicode(const char *zFilename){ | 32982 static LPWSTR mbcsToUnicode(const char *zFilename){ 32098 int nByte; 32983 int nByte; 32099 WCHAR *zMbcsFilename; | 32984 LPWSTR zMbcsFilename; 32100 int codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP; | 32985 int codepage = osAreFileApisANSI() ? CP_ACP : CP_OEMCP; 32101 32986 32102 nByte = MultiByteToWideChar(codepage, 0, zFilename, -1, NULL,0)*sizeof(WCHAR); | 32987 nByte = osMultiByteToWideChar(codepage, 0, zFilename, -1, NULL, > 32988 0)*sizeof(WCHAR); > 32989 if( nByte==0 ){ > 32990 return 0; > 32991 } 32103 zMbcsFilename = malloc( nByte*sizeof(zMbcsFilename[0]) ); | 32992 zMbcsFilename = sqlite3_malloc( nByte*sizeof(zMbcsFilename[0]) ); 32104 if( zMbcsFilename==0 ){ 32993 if( zMbcsFilename==0 ){ 32105 return 0; 32994 return 0; 32106 } 32995 } 32107 nByte = MultiByteToWideChar(codepage, 0, zFilename, -1, zMbcsFilename, nByte); | 32996 nByte = osMultiByteToWideChar(codepage, 0, zFilename, -1, zMbcsFilename, > 32997 nByte); 32108 if( nByte==0 ){ 32998 if( nByte==0 ){ 32109 free(zMbcsFilename); | 32999 sqlite3_free(zMbcsFilename); 32110 zMbcsFilename = 0; 33000 zMbcsFilename = 0; 32111 } 33001 } 32112 return zMbcsFilename; 33002 return zMbcsFilename; 32113 } 33003 } 32114 33004 32115 /* 33005 /* 32116 ** Convert microsoft unicode to multibyte character string, based on the | 33006 ** Convert Microsoft Unicode to multi-byte character string, based on the 32117 ** user's Ansi codepage. | 33007 ** user's ANSI codepage. 32118 ** 33008 ** 32119 ** Space to hold the returned string is obtained from 33009 ** Space to hold the returned string is obtained from 32120 ** malloc(). | 33010 ** sqlite3_malloc(). 32121 */ 33011 */ 32122 static char *unicodeToMbcs(const WCHAR *zWideFilename){ | 33012 static char *unicodeToMbcs(LPCWSTR zWideFilename){ 32123 int nByte; 33013 int nByte; 32124 char *zFilename; 33014 char *zFilename; 32125 int codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP; | 33015 int codepage = osAreFileApisANSI() ? CP_ACP : CP_OEMCP; 32126 33016 32127 nByte = WideCharToMultiByte(codepage, 0, zWideFilename, -1, 0, 0, 0, 0); | 33017 nByte = osWideCharToMultiByte(codepage, 0, zWideFilename, -1, 0, 0, 0, 0); > 33018 if( nByte == 0 ){ > 33019 return 0; > 33020 } 32128 zFilename = malloc( nByte ); | 33021 zFilename = sqlite3_malloc( nByte ); 32129 if( zFilename==0 ){ 33022 if( zFilename==0 ){ 32130 return 0; 33023 return 0; 32131 } 33024 } 32132 nByte = WideCharToMultiByte(codepage, 0, zWideFilename, -1, zFilename, nByte, | 33025 nByte = osWideCharToMultiByte(codepage, 0, zWideFilename, -1, zFilename, 32133 0, 0); | 33026 nByte, 0, 0); 32134 if( nByte == 0 ){ 33027 if( nByte == 0 ){ 32135 free(zFilename); | 33028 sqlite3_free(zFilename); 32136 zFilename = 0; 33029 zFilename = 0; 32137 } 33030 } 32138 return zFilename; 33031 return zFilename; 32139 } 33032 } 32140 33033 32141 /* 33034 /* 32142 ** Convert multibyte character string to UTF-8. Space to hold the 33035 ** Convert multibyte character string to UTF-8. Space to hold the 32143 ** returned string is obtained from malloc(). | 33036 ** returned string is obtained from sqlite3_malloc(). 32144 */ 33037 */ 32145 SQLITE_API char *sqlite3_win32_mbcs_to_utf8(const char *zFilename){ 33038 SQLITE_API char *sqlite3_win32_mbcs_to_utf8(const char *zFilename){ 32146 char *zFilenameUtf8; 33039 char *zFilenameUtf8; 32147 WCHAR *zTmpWide; | 33040 LPWSTR zTmpWide; 32148 33041 32149 zTmpWide = mbcsToUnicode(zFilename); 33042 zTmpWide = mbcsToUnicode(zFilename); 32150 if( zTmpWide==0 ){ 33043 if( zTmpWide==0 ){ 32151 return 0; 33044 return 0; 32152 } 33045 } 32153 zFilenameUtf8 = unicodeToUtf8(zTmpWide); 33046 zFilenameUtf8 = unicodeToUtf8(zTmpWide); 32154 free(zTmpWide); | 33047 sqlite3_free(zTmpWide); 32155 return zFilenameUtf8; 33048 return zFilenameUtf8; 32156 } 33049 } 32157 33050 32158 /* 33051 /* 32159 ** Convert UTF-8 to multibyte character string. Space to hold the 33052 ** Convert UTF-8 to multibyte character string. Space to hold the 32160 ** returned string is obtained from malloc(). | 33053 ** returned string is obtained from sqlite3_malloc(). 32161 */ 33054 */ 32162 SQLITE_API char *sqlite3_win32_utf8_to_mbcs(const char *zFilename){ 33055 SQLITE_API char *sqlite3_win32_utf8_to_mbcs(const char *zFilename){ 32163 char *zFilenameMbcs; 33056 char *zFilenameMbcs; 32164 WCHAR *zTmpWide; | 33057 LPWSTR zTmpWide; 32165 33058 32166 zTmpWide = utf8ToUnicode(zFilename); 33059 zTmpWide = utf8ToUnicode(zFilename); 32167 if( zTmpWide==0 ){ 33060 if( zTmpWide==0 ){ 32168 return 0; 33061 return 0; 32169 } 33062 } 32170 zFilenameMbcs = unicodeToMbcs(zTmpWide); 33063 zFilenameMbcs = unicodeToMbcs(zTmpWide); 32171 free(zTmpWide); | 33064 sqlite3_free(zTmpWide); 32172 return zFilenameMbcs; 33065 return zFilenameMbcs; 32173 } 33066 } 32174 33067 32175 33068 32176 /* 33069 /* 32177 ** The return value of getLastErrorMsg 33070 ** The return value of getLastErrorMsg 32178 ** is zero if the error message fits in the buffer, or non-zero 33071 ** is zero if the error message fits in the buffer, or non-zero 32179 ** otherwise (if the message was truncated). 33072 ** otherwise (if the message was truncated). 32180 */ 33073 */ 32181 static int getLastErrorMsg(int nBuf, char *zBuf){ | 33074 static int getLastErrorMsg(DWORD lastErrno, int nBuf, char *zBuf){ 32182 /* FormatMessage returns 0 on failure. Otherwise it 33075 /* FormatMessage returns 0 on failure. Otherwise it 32183 ** returns the number of TCHARs written to the output 33076 ** returns the number of TCHARs written to the output 32184 ** buffer, excluding the terminating null char. 33077 ** buffer, excluding the terminating null char. 32185 */ 33078 */ 32186 DWORD error = GetLastError(); < 32187 DWORD dwLen = 0; 33079 DWORD dwLen = 0; 32188 char *zOut = 0; 33080 char *zOut = 0; 32189 33081 32190 if( isNT() ){ 33082 if( isNT() ){ 32191 WCHAR *zTempWide = NULL; | 33083 LPWSTR zTempWide = NULL; 32192 dwLen = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_ | 33084 dwLen = osFormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | > 33085 FORMAT_MESSAGE_FROM_SYSTEM | > 33086 FORMAT_MESSAGE_IGNORE_INSERTS, 32193 NULL, | 33087 NULL, 32194 error, < > 33088 lastErrno, 32195 0, | 33089 0, 32196 (LPWSTR) &zTempWide, | 33090 (LPWSTR) &zTempWide, 32197 0, | 33091 0, 32198 0); | 33092 0); 32199 if( dwLen > 0 ){ 33093 if( dwLen > 0 ){ 32200 /* allocate a buffer and convert to UTF8 */ 33094 /* allocate a buffer and convert to UTF8 */ > 33095 sqlite3BeginBenignMalloc(); 32201 zOut = unicodeToUtf8(zTempWide); 33096 zOut = unicodeToUtf8(zTempWide); > 33097 sqlite3EndBenignMalloc(); 32202 /* free the system buffer allocated by FormatMessage */ 33098 /* free the system buffer allocated by FormatMessage */ 32203 LocalFree(zTempWide); | 33099 osLocalFree(zTempWide); 32204 } 33100 } 32205 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 33101 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 32206 ** Since the ASCII version of these Windows API do not exist for WINCE, | 33102 ** Since the ANSI version of these Windows API do not exist for WINCE, 32207 ** it's important to not reference them for WINCE builds. 33103 ** it's important to not reference them for WINCE builds. 32208 */ 33104 */ 32209 #if SQLITE_OS_WINCE==0 33105 #if SQLITE_OS_WINCE==0 32210 }else{ 33106 }else{ 32211 char *zTemp = NULL; 33107 char *zTemp = NULL; 32212 dwLen = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_ | 33108 dwLen = osFormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | > 33109 FORMAT_MESSAGE_FROM_SYSTEM | > 33110 FORMAT_MESSAGE_IGNORE_INSERTS, 32213 NULL, | 33111 NULL, 32214 error, < > 33112 lastErrno, 32215 0, | 33113 0, 32216 (LPSTR) &zTemp, | 33114 (LPSTR) &zTemp, 32217 0, | 33115 0, 32218 0); | 33116 0); 32219 if( dwLen > 0 ){ 33117 if( dwLen > 0 ){ 32220 /* allocate a buffer and convert to UTF8 */ 33118 /* allocate a buffer and convert to UTF8 */ > 33119 sqlite3BeginBenignMalloc(); 32221 zOut = sqlite3_win32_mbcs_to_utf8(zTemp); 33120 zOut = sqlite3_win32_mbcs_to_utf8(zTemp); > 33121 sqlite3EndBenignMalloc(); 32222 /* free the system buffer allocated by FormatMessage */ 33122 /* free the system buffer allocated by FormatMessage */ 32223 LocalFree(zTemp); | 33123 osLocalFree(zTemp); 32224 } 33124 } 32225 #endif 33125 #endif 32226 } 33126 } 32227 if( 0 == dwLen ){ 33127 if( 0 == dwLen ){ 32228 sqlite3_snprintf(nBuf, zBuf, "OsError 0x%x (%u)", error, error); | 33128 sqlite3_snprintf(nBuf, zBuf, "OsError 0x%x (%u)", lastErrno, lastErrno); 32229 }else{ 33129 }else{ 32230 /* copy a maximum of nBuf chars to output buffer */ 33130 /* copy a maximum of nBuf chars to output buffer */ 32231 sqlite3_snprintf(nBuf, zBuf, "%s", zOut); 33131 sqlite3_snprintf(nBuf, zBuf, "%s", zOut); 32232 /* free the UTF8 buffer */ 33132 /* free the UTF8 buffer */ 32233 free(zOut); | 33133 sqlite3_free(zOut); 32234 } 33134 } 32235 return 0; 33135 return 0; 32236 } 33136 } 32237 33137 32238 /* 33138 /* 32239 ** 33139 ** 32240 ** This function - winLogErrorAtLine() - is only ever called via the macro 33140 ** This function - winLogErrorAtLine() - is only ever called via the macro ................................................................................................................................................................................ 32246 ** FormatMessage. 33146 ** FormatMessage. 32247 ** 33147 ** 32248 ** The first argument passed to the macro should be the error code that 33148 ** The first argument passed to the macro should be the error code that 32249 ** will be returned to SQLite (e.g. SQLITE_IOERR_DELETE, SQLITE_CANTOPEN). 33149 ** will be returned to SQLite (e.g. SQLITE_IOERR_DELETE, SQLITE_CANTOPEN). 32250 ** The two subsequent arguments should be the name of the OS function that 33150 ** The two subsequent arguments should be the name of the OS function that 32251 ** failed and the the associated file-system path, if any. 33151 ** failed and the the associated file-system path, if any. 32252 */ 33152 */ 32253 #define winLogError(a,b,c) winLogErrorAtLine(a,b,c,__LINE__) | 33153 #define winLogError(a,b,c,d) winLogErrorAtLine(a,b,c,d,__LINE__) 32254 static int winLogErrorAtLine( 33154 static int winLogErrorAtLine( 32255 int errcode, /* SQLite error code */ 33155 int errcode, /* SQLite error code */ > 33156 DWORD lastErrno, /* Win32 last error */ 32256 const char *zFunc, /* Name of OS function that failed */ 33157 const char *zFunc, /* Name of OS function that failed */ 32257 const char *zPath, /* File path associated with error */ 33158 const char *zPath, /* File path associated with error */ 32258 int iLine /* Source line number where error occurred */ 33159 int iLine /* Source line number where error occurred */ 32259 ){ 33160 ){ 32260 char zMsg[500]; /* Human readable error text */ 33161 char zMsg[500]; /* Human readable error text */ 32261 int i; /* Loop counter */ 33162 int i; /* Loop counter */ 32262 DWORD iErrno = GetLastError(); /* Error code */ < 32263 33163 32264 zMsg[0] = 0; 33164 zMsg[0] = 0; 32265 getLastErrorMsg(sizeof(zMsg), zMsg); | 33165 getLastErrorMsg(lastErrno, sizeof(zMsg), zMsg); 32266 assert( errcode!=SQLITE_OK ); 33166 assert( errcode!=SQLITE_OK ); 32267 if( zPath==0 ) zPath = ""; 33167 if( zPath==0 ) zPath = ""; 32268 for(i=0; zMsg[i] && zMsg[i]!='\r' && zMsg[i]!='\n'; i++){} 33168 for(i=0; zMsg[i] && zMsg[i]!='\r' && zMsg[i]!='\n'; i++){} 32269 zMsg[i] = 0; 33169 zMsg[i] = 0; 32270 sqlite3_log(errcode, 33170 sqlite3_log(errcode, 32271 "os_win.c:%d: (%d) %s(%s) - %s", 33171 "os_win.c:%d: (%d) %s(%s) - %s", 32272 iLine, iErrno, zFunc, zPath, zMsg | 33172 iLine, lastErrno, zFunc, zPath, zMsg 32273 ); 33173 ); 32274 33174 32275 return errcode; 33175 return errcode; 32276 } 33176 } 32277 33177 32278 /* 33178 /* 32279 ** The number of times that a ReadFile(), WriteFile(), and DeleteFile() 33179 ** The number of times that a ReadFile(), WriteFile(), and DeleteFile() ................................................................................................................................................................................ 32291 static int win32IoerrRetryDelay = SQLITE_WIN32_IOERR_RETRY_DELAY; 33191 static int win32IoerrRetryDelay = SQLITE_WIN32_IOERR_RETRY_DELAY; 32292 33192 32293 /* 33193 /* 32294 ** If a ReadFile() or WriteFile() error occurs, invoke this routine 33194 ** If a ReadFile() or WriteFile() error occurs, invoke this routine 32295 ** to see if it should be retried. Return TRUE to retry. Return FALSE 33195 ** to see if it should be retried. Return TRUE to retry. Return FALSE 32296 ** to give up with an error. 33196 ** to give up with an error. 32297 */ 33197 */ 32298 static int retryIoerr(int *pnRetry){ | 33198 static int retryIoerr(int *pnRetry, DWORD *pError){ 32299 DWORD e; | 33199 DWORD e = osGetLastError(); 32300 if( *pnRetry>=win32IoerrRetry ){ 33200 if( *pnRetry>=win32IoerrRetry ){ > 33201 if( pError ){ > 33202 *pError = e; > 33203 } 32301 return 0; 33204 return 0; 32302 } 33205 } 32303 e = GetLastError(); < 32304 if( e==ERROR_ACCESS_DENIED || 33206 if( e==ERROR_ACCESS_DENIED || 32305 e==ERROR_LOCK_VIOLATION || 33207 e==ERROR_LOCK_VIOLATION || 32306 e==ERROR_SHARING_VIOLATION ){ 33208 e==ERROR_SHARING_VIOLATION ){ 32307 Sleep(win32IoerrRetryDelay*(1+*pnRetry)); | 33209 osSleep(win32IoerrRetryDelay*(1+*pnRetry)); 32308 ++*pnRetry; 33210 ++*pnRetry; 32309 return 1; 33211 return 1; 32310 } 33212 } > 33213 if( pError ){ > 33214 *pError = e; > 33215 } 32311 return 0; 33216 return 0; 32312 } 33217 } 32313 33218 32314 /* 33219 /* 32315 ** Log a I/O error retry episode. 33220 ** Log a I/O error retry episode. 32316 */ 33221 */ 32317 static void logIoerr(int nRetry){ 33222 static void logIoerr(int nRetry){ ................................................................................................................................................................................ 32324 } 33229 } 32325 33230 32326 #if SQLITE_OS_WINCE 33231 #if SQLITE_OS_WINCE 32327 /************************************************************************* 33232 /************************************************************************* 32328 ** This section contains code for WinCE only. 33233 ** This section contains code for WinCE only. 32329 */ 33234 */ 32330 /* 33235 /* 32331 ** WindowsCE does not have a localtime() function. So create a | 33236 ** Windows CE does not have a localtime() function. So create a 32332 ** substitute. 33237 ** substitute. 32333 */ 33238 */ 32334 /* #include <time.h> */ 33239 /* #include <time.h> */ 32335 struct tm *__cdecl localtime(const time_t *t) 33240 struct tm *__cdecl localtime(const time_t *t) 32336 { 33241 { 32337 static struct tm y; 33242 static struct tm y; 32338 FILETIME uTm, lTm; 33243 FILETIME uTm, lTm; 32339 SYSTEMTIME pTm; 33244 SYSTEMTIME pTm; 32340 sqlite3_int64 t64; 33245 sqlite3_int64 t64; 32341 t64 = *t; 33246 t64 = *t; 32342 t64 = (t64 + 11644473600)*10000000; 33247 t64 = (t64 + 11644473600)*10000000; 32343 uTm.dwLowDateTime = (DWORD)(t64 & 0xFFFFFFFF); 33248 uTm.dwLowDateTime = (DWORD)(t64 & 0xFFFFFFFF); 32344 uTm.dwHighDateTime= (DWORD)(t64 >> 32); 33249 uTm.dwHighDateTime= (DWORD)(t64 >> 32); 32345 FileTimeToLocalFileTime(&uTm,&lTm); | 33250 osFileTimeToLocalFileTime(&uTm,&lTm); 32346 FileTimeToSystemTime(&lTm,&pTm); | 33251 osFileTimeToSystemTime(&lTm,&pTm); 32347 y.tm_year = pTm.wYear - 1900; 33252 y.tm_year = pTm.wYear - 1900; 32348 y.tm_mon = pTm.wMonth - 1; 33253 y.tm_mon = pTm.wMonth - 1; 32349 y.tm_wday = pTm.wDayOfWeek; 33254 y.tm_wday = pTm.wDayOfWeek; 32350 y.tm_mday = pTm.wDay; 33255 y.tm_mday = pTm.wDay; 32351 y.tm_hour = pTm.wHour; 33256 y.tm_hour = pTm.wHour; 32352 y.tm_min = pTm.wMinute; 33257 y.tm_min = pTm.wMinute; 32353 y.tm_sec = pTm.wSecond; 33258 y.tm_sec = pTm.wSecond; 32354 return &y; 33259 return &y; 32355 } 33260 } 32356 33261 32357 /* This will never be called, but defined to make the code compile */ < 32358 #define GetTempPathA(a,b) < 32359 < 32360 #define LockFile(a,b,c,d,e) winceLockFile(&a, b, c, d, e) < 32361 #define UnlockFile(a,b,c,d,e) winceUnlockFile(&a, b, c, d, e) < 32362 #define LockFileEx(a,b,c,d,e,f) winceLockFileEx(&a, b, c, d, e, f) < 32363 < 32364 #define HANDLE_TO_WINFILE(a) (winFile*)&((char*)a)[-(int)offsetof(winFile,h)] 33262 #define HANDLE_TO_WINFILE(a) (winFile*)&((char*)a)[-(int)offsetof(winFile,h)] 32365 33263 32366 /* 33264 /* 32367 ** Acquire a lock on the handle h 33265 ** Acquire a lock on the handle h 32368 */ 33266 */ 32369 static void winceMutexAcquire(HANDLE h){ 33267 static void winceMutexAcquire(HANDLE h){ 32370 DWORD dwErr; 33268 DWORD dwErr; ................................................................................................................................................................................ 32378 #define winceMutexRelease(h) ReleaseMutex(h) 33276 #define winceMutexRelease(h) ReleaseMutex(h) 32379 33277 32380 /* 33278 /* 32381 ** Create the mutex and shared memory used for locking in the file 33279 ** Create the mutex and shared memory used for locking in the file 32382 ** descriptor pFile 33280 ** descriptor pFile 32383 */ 33281 */ 32384 static BOOL winceCreateLock(const char *zFilename, winFile *pFile){ 33282 static BOOL winceCreateLock(const char *zFilename, winFile *pFile){ 32385 WCHAR *zTok; | 33283 LPWSTR zTok; 32386 WCHAR *zName = utf8ToUnicode(zFilename); | 33284 LPWSTR zName; 32387 BOOL bInit = TRUE; 33285 BOOL bInit = TRUE; > 33286 > 33287 zName = utf8ToUnicode(zFilename); > 33288 if( zName==0 ){ > 33289 /* out of memory */ > 33290 return FALSE; > 33291 } 32388 33292 32389 /* Initialize the local lockdata */ 33293 /* Initialize the local lockdata */ 32390 ZeroMemory(&pFile->local, sizeof(pFile->local)); | 33294 memset(&pFile->local, 0, sizeof(pFile->local)); 32391 33295 32392 /* Replace the backslashes from the filename and lowercase it 33296 /* Replace the backslashes from the filename and lowercase it 32393 ** to derive a mutex name. */ 33297 ** to derive a mutex name. */ 32394 zTok = CharLowerW(zName); | 33298 zTok = osCharLowerW(zName); 32395 for (;*zTok;zTok++){ 33299 for (;*zTok;zTok++){ 32396 if (*zTok == '\\') *zTok = '_'; 33300 if (*zTok == '\\') *zTok = '_'; 32397 } 33301 } 32398 33302 32399 /* Create/open the named mutex */ 33303 /* Create/open the named mutex */ 32400 pFile->hMutex = CreateMutexW(NULL, FALSE, zName); | 33304 pFile->hMutex = osCreateMutexW(NULL, FALSE, zName); 32401 if (!pFile->hMutex){ 33305 if (!pFile->hMutex){ 32402 pFile->lastErrno = GetLastError(); | 33306 pFile->lastErrno = osGetLastError(); 32403 winLogError(SQLITE_ERROR, "winceCreateLock1", zFilename); | 33307 winLogError(SQLITE_ERROR, pFile->lastErrno, "winceCreateLock1", zFilename); 32404 free(zName); | 33308 sqlite3_free(zName); 32405 return FALSE; 33309 return FALSE; 32406 } 33310 } 32407 33311 32408 /* Acquire the mutex before continuing */ 33312 /* Acquire the mutex before continuing */ 32409 winceMutexAcquire(pFile->hMutex); 33313 winceMutexAcquire(pFile->hMutex); 32410 33314 32411 /* Since the names of named mutexes, semaphores, file mappings etc are 33315 /* Since the names of named mutexes, semaphores, file mappings etc are 32412 ** case-sensitive, take advantage of that by uppercasing the mutex name 33316 ** case-sensitive, take advantage of that by uppercasing the mutex name 32413 ** and using that as the shared filemapping name. 33317 ** and using that as the shared filemapping name. 32414 */ 33318 */ 32415 CharUpperW(zName); | 33319 osCharUpperW(zName); 32416 pFile->hShared = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, | 33320 pFile->hShared = osCreateFileMappingW(INVALID_HANDLE_VALUE, NULL, 32417 PAGE_READWRITE, 0, sizeof(winceLock), | 33321 PAGE_READWRITE, 0, sizeof(winceLock), 32418 zName); | 33322 zName); 32419 33323 32420 /* Set a flag that indicates we're the first to create the memory so it 33324 /* Set a flag that indicates we're the first to create the memory so it 32421 ** must be zero-initialized */ 33325 ** must be zero-initialized */ 32422 if (GetLastError() == ERROR_ALREADY_EXISTS){ | 33326 if (osGetLastError() == ERROR_ALREADY_EXISTS){ 32423 bInit = FALSE; 33327 bInit = FALSE; 32424 } 33328 } 32425 33329 32426 free(zName); | 33330 sqlite3_free(zName); 32427 33331 32428 /* If we succeeded in making the shared memory handle, map it. */ 33332 /* If we succeeded in making the shared memory handle, map it. */ 32429 if (pFile->hShared){ 33333 if (pFile->hShared){ 32430 pFile->shared = (winceLock*)MapViewOfFile(pFile->hShared, | 33334 pFile->shared = (winceLock*)osMapViewOfFile(pFile->hShared, 32431 FILE_MAP_READ|FILE_MAP_WRITE, 0, 0, sizeof(winceLock)); 33335 FILE_MAP_READ|FILE_MAP_WRITE, 0, 0, sizeof(winceLock)); 32432 /* If mapping failed, close the shared memory handle and erase it */ 33336 /* If mapping failed, close the shared memory handle and erase it */ 32433 if (!pFile->shared){ 33337 if (!pFile->shared){ 32434 pFile->lastErrno = GetLastError(); | 33338 pFile->lastErrno = osGetLastError(); > 33339 winLogError(SQLITE_ERROR, pFile->lastErrno, 32435 winLogError(SQLITE_ERROR, "winceCreateLock2", zFilename); | 33340 "winceCreateLock2", zFilename); 32436 CloseHandle(pFile->hShared); | 33341 osCloseHandle(pFile->hShared); 32437 pFile->hShared = NULL; 33342 pFile->hShared = NULL; 32438 } 33343 } 32439 } 33344 } 32440 33345 32441 /* If shared memory could not be created, then close the mutex and fail */ 33346 /* If shared memory could not be created, then close the mutex and fail */ 32442 if (pFile->hShared == NULL){ 33347 if (pFile->hShared == NULL){ 32443 winceMutexRelease(pFile->hMutex); 33348 winceMutexRelease(pFile->hMutex); 32444 CloseHandle(pFile->hMutex); | 33349 osCloseHandle(pFile->hMutex); 32445 pFile->hMutex = NULL; 33350 pFile->hMutex = NULL; 32446 return FALSE; 33351 return FALSE; 32447 } 33352 } 32448 33353 32449 /* Initialize the shared memory if we're supposed to */ 33354 /* Initialize the shared memory if we're supposed to */ 32450 if (bInit) { 33355 if (bInit) { 32451 ZeroMemory(pFile->shared, sizeof(winceLock)); | 33356 memset(pFile->shared, 0, sizeof(winceLock)); 32452 } 33357 } 32453 33358 32454 winceMutexRelease(pFile->hMutex); 33359 winceMutexRelease(pFile->hMutex); 32455 return TRUE; 33360 return TRUE; 32456 } 33361 } 32457 33362 32458 /* 33363 /* ................................................................................................................................................................................ 32475 pFile->shared->bPending = FALSE; 33380 pFile->shared->bPending = FALSE; 32476 } 33381 } 32477 if (pFile->local.bExclusive){ 33382 if (pFile->local.bExclusive){ 32478 pFile->shared->bExclusive = FALSE; 33383 pFile->shared->bExclusive = FALSE; 32479 } 33384 } 32480 33385 32481 /* De-reference and close our copy of the shared memory handle */ 33386 /* De-reference and close our copy of the shared memory handle */ 32482 UnmapViewOfFile(pFile->shared); | 33387 osUnmapViewOfFile(pFile->shared); 32483 CloseHandle(pFile->hShared); | 33388 osCloseHandle(pFile->hShared); 32484 33389 32485 /* Done with the mutex */ 33390 /* Done with the mutex */ 32486 winceMutexRelease(pFile->hMutex); 33391 winceMutexRelease(pFile->hMutex); 32487 CloseHandle(pFile->hMutex); | 33392 osCloseHandle(pFile->hMutex); 32488 pFile->hMutex = NULL; 33393 pFile->hMutex = NULL; 32489 } 33394 } 32490 } 33395 } 32491 33396 32492 /* 33397 /* 32493 ** An implementation of the LockFile() API of windows for wince | 33398 ** An implementation of the LockFile() API of Windows for CE 32494 */ 33399 */ 32495 static BOOL winceLockFile( 33400 static BOOL winceLockFile( 32496 HANDLE *phFile, 33401 HANDLE *phFile, 32497 DWORD dwFileOffsetLow, 33402 DWORD dwFileOffsetLow, 32498 DWORD dwFileOffsetHigh, 33403 DWORD dwFileOffsetHigh, 32499 DWORD nNumberOfBytesToLockLow, 33404 DWORD nNumberOfBytesToLockLow, 32500 DWORD nNumberOfBytesToLockHigh 33405 DWORD nNumberOfBytesToLockHigh ................................................................................................................................................................................ 32550 } 33455 } 32551 33456 32552 winceMutexRelease(pFile->hMutex); 33457 winceMutexRelease(pFile->hMutex); 32553 return bReturn; 33458 return bReturn; 32554 } 33459 } 32555 33460 32556 /* 33461 /* 32557 ** An implementation of the UnlockFile API of windows for wince | 33462 ** An implementation of the UnlockFile API of Windows for CE 32558 */ 33463 */ 32559 static BOOL winceUnlockFile( 33464 static BOOL winceUnlockFile( 32560 HANDLE *phFile, 33465 HANDLE *phFile, 32561 DWORD dwFileOffsetLow, 33466 DWORD dwFileOffsetLow, 32562 DWORD dwFileOffsetHigh, 33467 DWORD dwFileOffsetHigh, 32563 DWORD nNumberOfBytesToUnlockLow, 33468 DWORD nNumberOfBytesToUnlockLow, 32564 DWORD nNumberOfBytesToUnlockHigh 33469 DWORD nNumberOfBytesToUnlockHigh ................................................................................................................................................................................ 32612 } 33517 } 32613 33518 32614 winceMutexRelease(pFile->hMutex); 33519 winceMutexRelease(pFile->hMutex); 32615 return bReturn; 33520 return bReturn; 32616 } 33521 } 32617 33522 32618 /* 33523 /* 32619 ** An implementation of the LockFileEx() API of windows for wince | 33524 ** An implementation of the LockFileEx() API of Windows for CE 32620 */ 33525 */ 32621 static BOOL winceLockFileEx( 33526 static BOOL winceLockFileEx( 32622 HANDLE *phFile, 33527 HANDLE *phFile, 32623 DWORD dwFlags, 33528 DWORD dwFlags, 32624 DWORD dwReserved, 33529 DWORD dwReserved, 32625 DWORD nNumberOfBytesToLockLow, 33530 DWORD nNumberOfBytesToLockLow, 32626 DWORD nNumberOfBytesToLockHigh, 33531 DWORD nNumberOfBytesToLockHigh, ................................................................................................................................................................................ 32645 33550 32646 /***************************************************************************** 33551 /***************************************************************************** 32647 ** The next group of routines implement the I/O methods specified 33552 ** The next group of routines implement the I/O methods specified 32648 ** by the sqlite3_io_methods object. 33553 ** by the sqlite3_io_methods object. 32649 ******************************************************************************/ 33554 ******************************************************************************/ 32650 33555 32651 /* 33556 /* 32652 ** Some microsoft compilers lack this definition. | 33557 ** Some Microsoft compilers lack this definition. 32653 */ 33558 */ 32654 #ifndef INVALID_SET_FILE_POINTER 33559 #ifndef INVALID_SET_FILE_POINTER 32655 # define INVALID_SET_FILE_POINTER ((DWORD)-1) 33560 # define INVALID_SET_FILE_POINTER ((DWORD)-1) 32656 #endif 33561 #endif 32657 33562 32658 /* 33563 /* 32659 ** Move the current position of the file handle passed as the first 33564 ** Move the current position of the file handle passed as the first ................................................................................................................................................................................ 32660 ** argument to offset iOffset within the file. If successful, return 0. 33565 ** argument to offset iOffset within the file. If successful, return 0. 32661 ** Otherwise, set pFile->lastErrno and return non-zero. 33566 ** Otherwise, set pFile->lastErrno and return non-zero. 32662 */ 33567 */ 32663 static int seekWinFile(winFile *pFile, sqlite3_int64 iOffset){ 33568 static int seekWinFile(winFile *pFile, sqlite3_int64 iOffset){ 32664 LONG upperBits; /* Most sig. 32 bits of new offset */ 33569 LONG upperBits; /* Most sig. 32 bits of new offset */ 32665 LONG lowerBits; /* Least sig. 32 bits of new offset */ 33570 LONG lowerBits; /* Least sig. 32 bits of new offset */ 32666 DWORD dwRet; /* Value returned by SetFilePointer() */ 33571 DWORD dwRet; /* Value returned by SetFilePointer() */ > 33572 DWORD lastErrno; /* Value returned by GetLastError() */ 32667 33573 32668 upperBits = (LONG)((iOffset>>32) & 0x7fffffff); 33574 upperBits = (LONG)((iOffset>>32) & 0x7fffffff); 32669 lowerBits = (LONG)(iOffset & 0xffffffff); 33575 lowerBits = (LONG)(iOffset & 0xffffffff); 32670 33576 32671 /* API oddity: If successful, SetFilePointer() returns a dword 33577 /* API oddity: If successful, SetFilePointer() returns a dword 32672 ** containing the lower 32-bits of the new file-offset. Or, if it fails, 33578 ** containing the lower 32-bits of the new file-offset. Or, if it fails, 32673 ** it returns INVALID_SET_FILE_POINTER. However according to MSDN, 33579 ** it returns INVALID_SET_FILE_POINTER. However according to MSDN, 32674 ** INVALID_SET_FILE_POINTER may also be a valid new offset. So to determine 33580 ** INVALID_SET_FILE_POINTER may also be a valid new offset. So to determine 32675 ** whether an error has actually occured, it is also necessary to call 33581 ** whether an error has actually occured, it is also necessary to call 32676 ** GetLastError(). 33582 ** GetLastError(). 32677 */ 33583 */ 32678 dwRet = SetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN); | 33584 dwRet = osSetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN); > 33585 32679 if( (dwRet==INVALID_SET_FILE_POINTER && GetLastError()!=NO_ERROR) ){ | 33586 if( (dwRet==INVALID_SET_FILE_POINTER > 33587 && ((lastErrno = osGetLastError())!=NO_ERROR)) ){ 32680 pFile->lastErrno = GetLastError(); | 33588 pFile->lastErrno = lastErrno; > 33589 winLogError(SQLITE_IOERR_SEEK, pFile->lastErrno, 32681 winLogError(SQLITE_IOERR_SEEK, "seekWinFile", pFile->zPath); | 33590 "seekWinFile", pFile->zPath); 32682 return 1; 33591 return 1; 32683 } 33592 } 32684 33593 32685 return 0; 33594 return 0; 32686 } 33595 } 32687 33596 32688 /* 33597 /* 32689 ** Close a file. 33598 ** Close a file. 32690 ** 33599 ** 32691 ** It is reported that an attempt to close a handle might sometimes 33600 ** It is reported that an attempt to close a handle might sometimes 32692 ** fail. This is a very unreasonable result, but windows is notorious | 33601 ** fail. This is a very unreasonable result, but Windows is notorious 32693 ** for being unreasonable so I do not doubt that it might happen. If 33602 ** for being unreasonable so I do not doubt that it might happen. If 32694 ** the close fails, we pause for 100 milliseconds and try again. As 33603 ** the close fails, we pause for 100 milliseconds and try again. As 32695 ** many as MX_CLOSE_ATTEMPT attempts to close the handle are made before 33604 ** many as MX_CLOSE_ATTEMPT attempts to close the handle are made before 32696 ** giving up and returning an error. 33605 ** giving up and returning an error. 32697 */ 33606 */ 32698 #define MX_CLOSE_ATTEMPT 3 33607 #define MX_CLOSE_ATTEMPT 3 32699 static int winClose(sqlite3_file *id){ 33608 static int winClose(sqlite3_file *id){ ................................................................................................................................................................................ 32700 int rc, cnt = 0; 33609 int rc, cnt = 0; 32701 winFile *pFile = (winFile*)id; 33610 winFile *pFile = (winFile*)id; 32702 33611 32703 assert( id!=0 ); 33612 assert( id!=0 ); 32704 assert( pFile->pShm==0 ); 33613 assert( pFile->pShm==0 ); 32705 OSTRACE(("CLOSE %d\n", pFile->h)); 33614 OSTRACE(("CLOSE %d\n", pFile->h)); 32706 do{ 33615 do{ 32707 rc = CloseHandle(pFile->h); | 33616 rc = osCloseHandle(pFile->h); 32708 /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */ 33617 /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */ 32709 }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (Sleep(100), 1) ); | 33618 }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (osSleep(100), 1) ); 32710 #if SQLITE_OS_WINCE 33619 #if SQLITE_OS_WINCE 32711 #define WINCE_DELETION_ATTEMPTS 3 33620 #define WINCE_DELETION_ATTEMPTS 3 32712 winceDestroyLock(pFile); 33621 winceDestroyLock(pFile); 32713 if( pFile->zDeleteOnClose ){ 33622 if( pFile->zDeleteOnClose ){ 32714 int cnt = 0; 33623 int cnt = 0; 32715 while( 33624 while( 32716 DeleteFileW(pFile->zDeleteOnClose)==0 | 33625 osDeleteFileW(pFile->zDeleteOnClose)==0 32717 && GetFileAttributesW(pFile->zDeleteOnClose)!=0xffffffff | 33626 && osGetFileAttributesW(pFile->zDeleteOnClose)!=0xffffffff 32718 && cnt++ < WINCE_DELETION_ATTEMPTS 33627 && cnt++ < WINCE_DELETION_ATTEMPTS 32719 ){ 33628 ){ 32720 Sleep(100); /* Wait a little before trying again */ | 33629 osSleep(100); /* Wait a little before trying again */ 32721 } 33630 } 32722 free(pFile->zDeleteOnClose); | 33631 sqlite3_free(pFile->zDeleteOnClose); 32723 } 33632 } 32724 #endif 33633 #endif 32725 OSTRACE(("CLOSE %d %s\n", pFile->h, rc ? "ok" : "failed")); 33634 OSTRACE(("CLOSE %d %s\n", pFile->h, rc ? "ok" : "failed")); 32726 OpenCounter(-1); 33635 OpenCounter(-1); 32727 return rc ? SQLITE_OK 33636 return rc ? SQLITE_OK 32728 : winLogError(SQLITE_IOERR_CLOSE, "winClose", pFile->zPath); | 33637 : winLogError(SQLITE_IOERR_CLOSE, osGetLastError(), > 33638 "winClose", pFile->zPath); 32729 } 33639 } 32730 33640 32731 /* 33641 /* 32732 ** Read data from a file into a buffer. Return SQLITE_OK if all 33642 ** Read data from a file into a buffer. Return SQLITE_OK if all 32733 ** bytes were read successfully and SQLITE_IOERR if anything goes 33643 ** bytes were read successfully and SQLITE_IOERR if anything goes 32734 ** wrong. 33644 ** wrong. 32735 */ 33645 */ ................................................................................................................................................................................ 32770 */ 33680 */ 32771 if( pFile->szChunk>0 ){ 33681 if( pFile->szChunk>0 ){ 32772 nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk; 33682 nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk; 32773 } 33683 } 32774 33684 32775 /* SetEndOfFile() returns non-zero when successful, or zero when it fails. */ 33685 /* SetEndOfFile() returns non-zero when successful, or zero when it fails. */ 32776 if( seekWinFile(pFile, nByte) ){ 33686 if( seekWinFile(pFile, nByte) ){ 32777 rc = winLogError(SQLITE_IOERR_TRUNCATE, "winTruncate1", pFile->zPath); | 33687 rc = winLogError(SQLITE_IOERR_TRUNCATE, pFile->lastErrno, > 33688 "winTruncate1", pFile->zPath); 32778 }else if( 0==SetEndOfFile(pFile->h) ){ | 33689 }else if( 0==osSetEndOfFile(pFile->h) ){ 32779 pFile->lastErrno = GetLastError(); | 33690 pFile->lastErrno = osGetLastError(); 32780 rc = winLogError(SQLITE_IOERR_TRUNCATE, "winTruncate2", pFile->zPath); | 33691 rc = winLogError(SQLITE_IOERR_TRUNCATE, pFile->lastErrno, > 33692 "winTruncate2", pFile->zPath); 32781 } 33693 } 32782 33694 32783 OSTRACE(("TRUNCATE %d %lld %s\n", pFile->h, nByte, rc ? "failed" : "ok")); 33695 OSTRACE(("TRUNCATE %d %lld %s\n", pFile->h, nByte, rc ? "failed" : "ok")); 32784 return rc; 33696 return rc; 32785 } 33697 } 32786 33698 32787 #ifdef SQLITE_TEST 33699 #ifdef SQLITE_TEST ................................................................................................................................................................................ 32838 33750 32839 /* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a 33751 /* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a 32840 ** no-op 33752 ** no-op 32841 */ 33753 */ 32842 #ifdef SQLITE_NO_SYNC 33754 #ifdef SQLITE_NO_SYNC 32843 return SQLITE_OK; 33755 return SQLITE_OK; 32844 #else 33756 #else 32845 rc = FlushFileBuffers(pFile->h); | 33757 rc = osFlushFileBuffers(pFile->h); 32846 SimulateIOError( rc=FALSE ); 33758 SimulateIOError( rc=FALSE ); 32847 if( rc ){ 33759 if( rc ){ 32848 return SQLITE_OK; 33760 return SQLITE_OK; 32849 }else{ 33761 }else{ 32850 pFile->lastErrno = GetLastError(); | 33762 pFile->lastErrno = osGetLastError(); 32851 return winLogError(SQLITE_IOERR_FSYNC, "winSync", pFile->zPath); | 33763 return winLogError(SQLITE_IOERR_FSYNC, pFile->lastErrno, > 33764 "winSync", pFile->zPath); 32852 } 33765 } 32853 #endif 33766 #endif 32854 } 33767 } 32855 33768 32856 /* 33769 /* 32857 ** Determine the current size of a file in bytes 33770 ** Determine the current size of a file in bytes 32858 */ 33771 */ 32859 static int winFileSize(sqlite3_file *id, sqlite3_int64 *pSize){ 33772 static int winFileSize(sqlite3_file *id, sqlite3_int64 *pSize){ 32860 DWORD upperBits; 33773 DWORD upperBits; 32861 DWORD lowerBits; 33774 DWORD lowerBits; 32862 winFile *pFile = (winFile*)id; 33775 winFile *pFile = (winFile*)id; 32863 DWORD error; | 33776 DWORD lastErrno; 32864 33777 32865 assert( id!=0 ); 33778 assert( id!=0 ); 32866 SimulateIOError(return SQLITE_IOERR_FSTAT); 33779 SimulateIOError(return SQLITE_IOERR_FSTAT); 32867 lowerBits = GetFileSize(pFile->h, &upperBits); | 33780 lowerBits = osGetFileSize(pFile->h, &upperBits); 32868 if( (lowerBits == INVALID_FILE_SIZE) 33781 if( (lowerBits == INVALID_FILE_SIZE) 32869 && ((error = GetLastError()) != NO_ERROR) ) | 33782 && ((lastErrno = osGetLastError())!=NO_ERROR) ) 32870 { 33783 { 32871 pFile->lastErrno = error; | 33784 pFile->lastErrno = lastErrno; 32872 return winLogError(SQLITE_IOERR_FSTAT, "winFileSize", pFile->zPath); | 33785 return winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno, > 33786 "winFileSize", pFile->zPath); 32873 } 33787 } 32874 *pSize = (((sqlite3_int64)upperBits)<<32) + lowerBits; 33788 *pSize = (((sqlite3_int64)upperBits)<<32) + lowerBits; 32875 return SQLITE_OK; 33789 return SQLITE_OK; 32876 } 33790 } 32877 33791 32878 /* 33792 /* 32879 ** LOCKFILE_FAIL_IMMEDIATELY is undefined on some Windows systems. 33793 ** LOCKFILE_FAIL_IMMEDIATELY is undefined on some Windows systems. ................................................................................................................................................................................ 32881 #ifndef LOCKFILE_FAIL_IMMEDIATELY 33795 #ifndef LOCKFILE_FAIL_IMMEDIATELY 32882 # define LOCKFILE_FAIL_IMMEDIATELY 1 33796 # define LOCKFILE_FAIL_IMMEDIATELY 1 32883 #endif 33797 #endif 32884 33798 32885 /* 33799 /* 32886 ** Acquire a reader lock. 33800 ** Acquire a reader lock. 32887 ** Different API routines are called depending on whether or not this 33801 ** Different API routines are called depending on whether or not this 32888 ** is Win95 or WinNT. | 33802 ** is Win9x or WinNT. 32889 */ 33803 */ 32890 static int getReadLock(winFile *pFile){ 33804 static int getReadLock(winFile *pFile){ 32891 int res; 33805 int res; 32892 if( isNT() ){ 33806 if( isNT() ){ 32893 OVERLAPPED ovlp; 33807 OVERLAPPED ovlp; 32894 ovlp.Offset = SHARED_FIRST; 33808 ovlp.Offset = SHARED_FIRST; 32895 ovlp.OffsetHigh = 0; 33809 ovlp.OffsetHigh = 0; 32896 ovlp.hEvent = 0; 33810 ovlp.hEvent = 0; 32897 res = LockFileEx(pFile->h, LOCKFILE_FAIL_IMMEDIATELY, | 33811 res = osLockFileEx(pFile->h, LOCKFILE_FAIL_IMMEDIATELY, 32898 0, SHARED_SIZE, 0, &ovlp); | 33812 0, SHARED_SIZE, 0, &ovlp); 32899 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 33813 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 32900 */ 33814 */ 32901 #if SQLITE_OS_WINCE==0 33815 #if SQLITE_OS_WINCE==0 32902 }else{ 33816 }else{ 32903 int lk; 33817 int lk; 32904 sqlite3_randomness(sizeof(lk), &lk); 33818 sqlite3_randomness(sizeof(lk), &lk); 32905 pFile->sharedLockByte = (short)((lk & 0x7fffffff)%(SHARED_SIZE - 1)); 33819 pFile->sharedLockByte = (short)((lk & 0x7fffffff)%(SHARED_SIZE - 1)); 32906 res = LockFile(pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0); | 33820 res = osLockFile(pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0); 32907 #endif 33821 #endif 32908 } 33822 } 32909 if( res == 0 ){ 33823 if( res == 0 ){ 32910 pFile->lastErrno = GetLastError(); | 33824 pFile->lastErrno = osGetLastError(); 32911 /* No need to log a failure to lock */ 33825 /* No need to log a failure to lock */ 32912 } 33826 } 32913 return res; 33827 return res; 32914 } 33828 } 32915 33829 32916 /* 33830 /* 32917 ** Undo a readlock 33831 ** Undo a readlock 32918 */ 33832 */ 32919 static int unlockReadLock(winFile *pFile){ 33833 static int unlockReadLock(winFile *pFile){ 32920 int res; 33834 int res; > 33835 DWORD lastErrno; 32921 if( isNT() ){ 33836 if( isNT() ){ 32922 res = UnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0); | 33837 res = osUnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0); 32923 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 33838 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 32924 */ 33839 */ 32925 #if SQLITE_OS_WINCE==0 33840 #if SQLITE_OS_WINCE==0 32926 }else{ 33841 }else{ 32927 res = UnlockFile(pFile->h, SHARED_FIRST + pFile->sharedLockByte, 0, 1, 0); | 33842 res = osUnlockFile(pFile->h, SHARED_FIRST + pFile->sharedLockByte, 0, 1, 0); 32928 #endif 33843 #endif 32929 } 33844 } 32930 if( res==0 && GetLastError()!=ERROR_NOT_LOCKED ){ | 33845 if( res==0 && ((lastErrno = osGetLastError())!=ERROR_NOT_LOCKED) ){ 32931 pFile->lastErrno = GetLastError(); | 33846 pFile->lastErrno = lastErrno; > 33847 winLogError(SQLITE_IOERR_UNLOCK, pFile->lastErrno, 32932 winLogError(SQLITE_IOERR_UNLOCK, "unlockReadLock", pFile->zPath); | 33848 "unlockReadLock", pFile->zPath); 32933 } 33849 } 32934 return res; 33850 return res; 32935 } 33851 } 32936 33852 32937 /* 33853 /* 32938 ** Lock the file with the lock specified by parameter locktype - one 33854 ** Lock the file with the lock specified by parameter locktype - one 32939 ** of the following: 33855 ** of the following: ................................................................................................................................................................................ 32958 ** This routine will only increase a lock. The winUnlock() routine 33874 ** This routine will only increase a lock. The winUnlock() routine 32959 ** erases all locks at once and returns us immediately to locking level 0. 33875 ** erases all locks at once and returns us immediately to locking level 0. 32960 ** It is not possible to lower the locking level one step at a time. You 33876 ** It is not possible to lower the locking level one step at a time. You 32961 ** must go straight to locking level 0. 33877 ** must go straight to locking level 0. 32962 */ 33878 */ 32963 static int winLock(sqlite3_file *id, int locktype){ 33879 static int winLock(sqlite3_file *id, int locktype){ 32964 int rc = SQLITE_OK; /* Return code from subroutines */ 33880 int rc = SQLITE_OK; /* Return code from subroutines */ 32965 int res = 1; /* Result of a windows lock call */ | 33881 int res = 1; /* Result of a Windows lock call */ 32966 int newLocktype; /* Set pFile->locktype to this value before exiting */ 33882 int newLocktype; /* Set pFile->locktype to this value before exiting */ 32967 int gotPendingLock = 0;/* True if we acquired a PENDING lock this time */ 33883 int gotPendingLock = 0;/* True if we acquired a PENDING lock this time */ 32968 winFile *pFile = (winFile*)id; 33884 winFile *pFile = (winFile*)id; 32969 DWORD error = NO_ERROR; | 33885 DWORD lastErrno = NO_ERROR; 32970 33886 32971 assert( id!=0 ); 33887 assert( id!=0 ); 32972 OSTRACE(("LOCK %d %d was %d(%d)\n", 33888 OSTRACE(("LOCK %d %d was %d(%d)\n", 32973 pFile->h, locktype, pFile->locktype, pFile->sharedLockByte)); 33889 pFile->h, locktype, pFile->locktype, pFile->sharedLockByte)); 32974 33890 32975 /* If there is already a lock of this type or more restrictive on the 33891 /* If there is already a lock of this type or more restrictive on the 32976 ** OsFile, do nothing. Don't use the end_lock: exit path, as 33892 ** OsFile, do nothing. Don't use the end_lock: exit path, as ................................................................................................................................................................................ 32992 */ 33908 */ 32993 newLocktype = pFile->locktype; 33909 newLocktype = pFile->locktype; 32994 if( (pFile->locktype==NO_LOCK) 33910 if( (pFile->locktype==NO_LOCK) 32995 || ( (locktype==EXCLUSIVE_LOCK) 33911 || ( (locktype==EXCLUSIVE_LOCK) 32996 && (pFile->locktype==RESERVED_LOCK)) 33912 && (pFile->locktype==RESERVED_LOCK)) 32997 ){ 33913 ){ 32998 int cnt = 3; 33914 int cnt = 3; 32999 while( cnt-->0 && (res = LockFile(pFile->h, PENDING_BYTE, 0, 1, 0))==0 ){ | 33915 while( cnt-->0 && (res = osLockFile(pFile->h, PENDING_BYTE, 0, 1, 0))==0 ){ 33000 /* Try 3 times to get the pending lock. The pending lock might be | 33916 /* Try 3 times to get the pending lock. This is needed to work 33001 ** held by another reader process who will release it momentarily. | 33917 ** around problems caused by indexing and/or anti-virus software on > 33918 ** Windows systems. > 33919 ** If you are using this code as a model for alternative VFSes, do not > 33920 ** copy this retry logic. It is a hack intended for Windows only. 33002 */ 33921 */ 33003 OSTRACE(("could not get a PENDING lock. cnt=%d\n", cnt)); 33922 OSTRACE(("could not get a PENDING lock. cnt=%d\n", cnt)); 33004 Sleep(1); | 33923 if( cnt ) osSleep(1); 33005 } 33924 } 33006 gotPendingLock = res; 33925 gotPendingLock = res; 33007 if( !res ){ 33926 if( !res ){ 33008 error = GetLastError(); | 33927 lastErrno = osGetLastError(); 33009 } 33928 } 33010 } 33929 } 33011 33930 33012 /* Acquire a shared lock 33931 /* Acquire a shared lock 33013 */ 33932 */ 33014 if( locktype==SHARED_LOCK && res ){ 33933 if( locktype==SHARED_LOCK && res ){ 33015 assert( pFile->locktype==NO_LOCK ); 33934 assert( pFile->locktype==NO_LOCK ); 33016 res = getReadLock(pFile); 33935 res = getReadLock(pFile); 33017 if( res ){ 33936 if( res ){ 33018 newLocktype = SHARED_LOCK; 33937 newLocktype = SHARED_LOCK; 33019 }else{ 33938 }else{ 33020 error = GetLastError(); | 33939 lastErrno = osGetLastError(); 33021 } 33940 } 33022 } 33941 } 33023 33942 33024 /* Acquire a RESERVED lock 33943 /* Acquire a RESERVED lock 33025 */ 33944 */ 33026 if( locktype==RESERVED_LOCK && res ){ 33945 if( locktype==RESERVED_LOCK && res ){ 33027 assert( pFile->locktype==SHARED_LOCK ); 33946 assert( pFile->locktype==SHARED_LOCK ); 33028 res = LockFile(pFile->h, RESERVED_BYTE, 0, 1, 0); | 33947 res = osLockFile(pFile->h, RESERVED_BYTE, 0, 1, 0); 33029 if( res ){ 33948 if( res ){ 33030 newLocktype = RESERVED_LOCK; 33949 newLocktype = RESERVED_LOCK; 33031 }else{ 33950 }else{ 33032 error = GetLastError(); | 33951 lastErrno = osGetLastError(); 33033 } 33952 } 33034 } 33953 } 33035 33954 33036 /* Acquire a PENDING lock 33955 /* Acquire a PENDING lock 33037 */ 33956 */ 33038 if( locktype==EXCLUSIVE_LOCK && res ){ 33957 if( locktype==EXCLUSIVE_LOCK && res ){ 33039 newLocktype = PENDING_LOCK; 33958 newLocktype = PENDING_LOCK; ................................................................................................................................................................................ 33042 33961 33043 /* Acquire an EXCLUSIVE lock 33962 /* Acquire an EXCLUSIVE lock 33044 */ 33963 */ 33045 if( locktype==EXCLUSIVE_LOCK && res ){ 33964 if( locktype==EXCLUSIVE_LOCK && res ){ 33046 assert( pFile->locktype>=SHARED_LOCK ); 33965 assert( pFile->locktype>=SHARED_LOCK ); 33047 res = unlockReadLock(pFile); 33966 res = unlockReadLock(pFile); 33048 OSTRACE(("unreadlock = %d\n", res)); 33967 OSTRACE(("unreadlock = %d\n", res)); 33049 res = LockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0); | 33968 res = osLockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0); 33050 if( res ){ 33969 if( res ){ 33051 newLocktype = EXCLUSIVE_LOCK; 33970 newLocktype = EXCLUSIVE_LOCK; 33052 }else{ 33971 }else{ 33053 error = GetLastError(); | 33972 lastErrno = osGetLastError(); 33054 OSTRACE(("error-code = %d\n", error)); | 33973 OSTRACE(("error-code = %d\n", lastErrno)); 33055 getReadLock(pFile); 33974 getReadLock(pFile); 33056 } 33975 } 33057 } 33976 } 33058 33977 33059 /* If we are holding a PENDING lock that ought to be released, then 33978 /* If we are holding a PENDING lock that ought to be released, then 33060 ** release it now. 33979 ** release it now. 33061 */ 33980 */ 33062 if( gotPendingLock && locktype==SHARED_LOCK ){ 33981 if( gotPendingLock && locktype==SHARED_LOCK ){ 33063 UnlockFile(pFile->h, PENDING_BYTE, 0, 1, 0); | 33982 osUnlockFile(pFile->h, PENDING_BYTE, 0, 1, 0); 33064 } 33983 } 33065 33984 33066 /* Update the state of the lock has held in the file descriptor then 33985 /* Update the state of the lock has held in the file descriptor then 33067 ** return the appropriate result code. 33986 ** return the appropriate result code. 33068 */ 33987 */ 33069 if( res ){ 33988 if( res ){ 33070 rc = SQLITE_OK; 33989 rc = SQLITE_OK; 33071 }else{ 33990 }else{ 33072 OSTRACE(("LOCK FAILED %d trying for %d but got %d\n", pFile->h, 33991 OSTRACE(("LOCK FAILED %d trying for %d but got %d\n", pFile->h, 33073 locktype, newLocktype)); 33992 locktype, newLocktype)); 33074 pFile->lastErrno = error; | 33993 pFile->lastErrno = lastErrno; 33075 rc = SQLITE_BUSY; 33994 rc = SQLITE_BUSY; 33076 } 33995 } 33077 pFile->locktype = (u8)newLocktype; 33996 pFile->locktype = (u8)newLocktype; 33078 return rc; 33997 return rc; 33079 } 33998 } 33080 33999 33081 /* 34000 /* ................................................................................................................................................................................ 33090 SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; ); 34009 SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; ); 33091 34010 33092 assert( id!=0 ); 34011 assert( id!=0 ); 33093 if( pFile->locktype>=RESERVED_LOCK ){ 34012 if( pFile->locktype>=RESERVED_LOCK ){ 33094 rc = 1; 34013 rc = 1; 33095 OSTRACE(("TEST WR-LOCK %d %d (local)\n", pFile->h, rc)); 34014 OSTRACE(("TEST WR-LOCK %d %d (local)\n", pFile->h, rc)); 33096 }else{ 34015 }else{ 33097 rc = LockFile(pFile->h, RESERVED_BYTE, 0, 1, 0); | 34016 rc = osLockFile(pFile->h, RESERVED_BYTE, 0, 1, 0); 33098 if( rc ){ 34017 if( rc ){ 33099 UnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0); | 34018 osUnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0); 33100 } 34019 } 33101 rc = !rc; 34020 rc = !rc; 33102 OSTRACE(("TEST WR-LOCK %d %d (remote)\n", pFile->h, rc)); 34021 OSTRACE(("TEST WR-LOCK %d %d (remote)\n", pFile->h, rc)); 33103 } 34022 } 33104 *pResOut = rc; 34023 *pResOut = rc; 33105 return SQLITE_OK; 34024 return SQLITE_OK; 33106 } 34025 } ................................................................................................................................................................................ 33122 int rc = SQLITE_OK; 34041 int rc = SQLITE_OK; 33123 assert( pFile!=0 ); 34042 assert( pFile!=0 ); 33124 assert( locktype<=SHARED_LOCK ); 34043 assert( locktype<=SHARED_LOCK ); 33125 OSTRACE(("UNLOCK %d to %d was %d(%d)\n", pFile->h, locktype, 34044 OSTRACE(("UNLOCK %d to %d was %d(%d)\n", pFile->h, locktype, 33126 pFile->locktype, pFile->sharedLockByte)); 34045 pFile->locktype, pFile->sharedLockByte)); 33127 type = pFile->locktype; 34046 type = pFile->locktype; 33128 if( type>=EXCLUSIVE_LOCK ){ 34047 if( type>=EXCLUSIVE_LOCK ){ 33129 UnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0); | 34048 osUnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0); 33130 if( locktype==SHARED_LOCK && !getReadLock(pFile) ){ 34049 if( locktype==SHARED_LOCK && !getReadLock(pFile) ){ 33131 /* This should never happen. We should always be able to 34050 /* This should never happen. We should always be able to 33132 ** reacquire the read lock */ 34051 ** reacquire the read lock */ 33133 rc = winLogError(SQLITE_IOERR_UNLOCK, "winUnlock", pFile->zPath); | 34052 rc = winLogError(SQLITE_IOERR_UNLOCK, osGetLastError(), > 34053 "winUnlock", pFile->zPath); 33134 } 34054 } 33135 } 34055 } 33136 if( type>=RESERVED_LOCK ){ 34056 if( type>=RESERVED_LOCK ){ 33137 UnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0); | 34057 osUnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0); 33138 } 34058 } 33139 if( locktype==NO_LOCK && type>=SHARED_LOCK ){ 34059 if( locktype==NO_LOCK && type>=SHARED_LOCK ){ 33140 unlockReadLock(pFile); 34060 unlockReadLock(pFile); 33141 } 34061 } 33142 if( type>=PENDING_LOCK ){ 34062 if( type>=PENDING_LOCK ){ 33143 UnlockFile(pFile->h, PENDING_BYTE, 0, 1, 0); | 34063 osUnlockFile(pFile->h, PENDING_BYTE, 0, 1, 0); 33144 } 34064 } 33145 pFile->locktype = (u8)locktype; 34065 pFile->locktype = (u8)locktype; 33146 return rc; 34066 return rc; 33147 } 34067 } > 34068 > 34069 /* > 34070 ** If *pArg is inititially negative then this is a query. Set *pArg to > 34071 ** 1 or 0 depending on whether or not bit mask of pFile->ctrlFlags is set. > 34072 ** > 34073 ** If *pArg is 0 or 1, then clear or set the mask bit of pFile->ctrlFlags. > 34074 */ > 34075 static void winModeBit(winFile *pFile, unsigned char mask, int *pArg){ > 34076 if( *pArg<0 ){ > 34077 *pArg = (pFile->ctrlFlags & mask)!=0; > 34078 }else if( (*pArg)==0 ){ > 34079 pFile->ctrlFlags &= ~mask; > 34080 }else{ > 34081 pFile->ctrlFlags |= mask; > 34082 } > 34083 } 33148 34084 33149 /* 34085 /* 33150 ** Control and query of the open file handle. 34086 ** Control and query of the open file handle. 33151 */ 34087 */ 33152 static int winFileControl(sqlite3_file *id, int op, void *pArg){ 34088 static int winFileControl(sqlite3_file *id, int op, void *pArg){ 33153 winFile *pFile = (winFile*)id; 34089 winFile *pFile = (winFile*)id; 33154 switch( op ){ 34090 switch( op ){ ................................................................................................................................................................................ 33177 } 34113 } 33178 } 34114 } 33179 return rc; 34115 return rc; 33180 } 34116 } 33181 return SQLITE_OK; 34117 return SQLITE_OK; 33182 } 34118 } 33183 case SQLITE_FCNTL_PERSIST_WAL: { 34119 case SQLITE_FCNTL_PERSIST_WAL: { 33184 int bPersist = *(int*)pArg; | 34120 winModeBit(pFile, WINFILE_PERSIST_WAL, (int*)pArg); 33185 if( bPersist<0 ){ < 33186 *(int*)pArg = pFile->bPersistWal; < 33187 }else{ < 33188 pFile->bPersistWal = bPersist!=0; < 33189 } < 33190 return SQLITE_OK; 34121 return SQLITE_OK; 33191 } 34122 } > 34123 case SQLITE_FCNTL_POWERSAFE_OVERWRITE: { > 34124 winModeBit(pFile, WINFILE_PSOW, (int*)pArg); > 34125 return SQLITE_OK; > 34126 } 33192 case SQLITE_FCNTL_SYNC_OMITTED: { | 34127 case SQLITE_FCNTL_VFSNAME: { > 34128 *(char**)pArg = sqlite3_mprintf("win32"); 33193 return SQLITE_OK; 34129 return SQLITE_OK; 33194 } 34130 } 33195 case SQLITE_FCNTL_WIN32_AV_RETRY: { 34131 case SQLITE_FCNTL_WIN32_AV_RETRY: { 33196 int *a = (int*)pArg; 34132 int *a = (int*)pArg; 33197 if( a[0]>0 ){ 34133 if( a[0]>0 ){ 33198 win32IoerrRetry = a[0]; 34134 win32IoerrRetry = a[0]; 33199 }else{ 34135 }else{ ................................................................................................................................................................................ 33217 ** 34153 ** 33218 ** SQLite code assumes this function cannot fail. It also assumes that 34154 ** SQLite code assumes this function cannot fail. It also assumes that 33219 ** if two files are created in the same file-system directory (i.e. 34155 ** if two files are created in the same file-system directory (i.e. 33220 ** a database and its journal file) that the sector size will be the 34156 ** a database and its journal file) that the sector size will be the 33221 ** same for both. 34157 ** same for both. 33222 */ 34158 */ 33223 static int winSectorSize(sqlite3_file *id){ 34159 static int winSectorSize(sqlite3_file *id){ 33224 assert( id!=0 ); | 34160 (void)id; 33225 return (int)(((winFile*)id)->sectorSize); | 34161 return SQLITE_DEFAULT_SECTOR_SIZE; 33226 } 34162 } 33227 34163 33228 /* 34164 /* 33229 ** Return a vector of device characteristics. 34165 ** Return a vector of device characteristics. 33230 */ 34166 */ 33231 static int winDeviceCharacteristics(sqlite3_file *id){ 34167 static int winDeviceCharacteristics(sqlite3_file *id){ 33232 UNUSED_PARAMETER(id); | 34168 winFile *p = (winFile*)id; 33233 return SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN; | 34169 return SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN | > 34170 ((p->ctrlFlags & WINFILE_PSOW)?SQLITE_IOCAP_POWERSAFE_OVERWRITE:0); 33234 } 34171 } 33235 34172 33236 #ifndef SQLITE_OMIT_WAL 34173 #ifndef SQLITE_OMIT_WAL 33237 34174 33238 /* 34175 /* 33239 ** Windows will only let you create file view mappings 34176 ** Windows will only let you create file view mappings 33240 ** on allocation size granularity boundaries. 34177 ** on allocation size granularity boundaries. ................................................................................................................................................................................ 33373 if( lockType == _SHM_WRLCK ) dwFlags |= LOCKFILE_EXCLUSIVE_LOCK; 34310 if( lockType == _SHM_WRLCK ) dwFlags |= LOCKFILE_EXCLUSIVE_LOCK; 33374 34311 33375 memset(&ovlp, 0, sizeof(OVERLAPPED)); 34312 memset(&ovlp, 0, sizeof(OVERLAPPED)); 33376 ovlp.Offset = ofst; 34313 ovlp.Offset = ofst; 33377 34314 33378 /* Release/Acquire the system-level lock */ 34315 /* Release/Acquire the system-level lock */ 33379 if( lockType==_SHM_UNLCK ){ 34316 if( lockType==_SHM_UNLCK ){ 33380 rc = UnlockFileEx(pFile->hFile.h, 0, nByte, 0, &ovlp); | 34317 rc = osUnlockFileEx(pFile->hFile.h, 0, nByte, 0, &ovlp); 33381 }else{ 34318 }else{ 33382 rc = LockFileEx(pFile->hFile.h, dwFlags, 0, nByte, 0, &ovlp); | 34319 rc = osLockFileEx(pFile->hFile.h, dwFlags, 0, nByte, 0, &ovlp); 33383 } 34320 } 33384 34321 33385 if( rc!= 0 ){ 34322 if( rc!= 0 ){ 33386 rc = SQLITE_OK; 34323 rc = SQLITE_OK; 33387 }else{ 34324 }else{ 33388 pFile->lastErrno = GetLastError(); | 34325 pFile->lastErrno = osGetLastError(); 33389 rc = SQLITE_BUSY; 34326 rc = SQLITE_BUSY; 33390 } 34327 } 33391 34328 33392 OSTRACE(("SHM-LOCK %d %s %s 0x%08lx\n", 34329 OSTRACE(("SHM-LOCK %d %s %s 0x%08lx\n", 33393 pFile->hFile.h, 34330 pFile->hFile.h, 33394 rc==SQLITE_OK ? "ok" : "failed", 34331 rc==SQLITE_OK ? "ok" : "failed", 33395 lockType==_SHM_UNLCK ? "UnlockFileEx" : "LockFileEx", 34332 lockType==_SHM_UNLCK ? "UnlockFileEx" : "LockFileEx", ................................................................................................................................................................................ 33415 assert( winShmMutexHeld() ); 34352 assert( winShmMutexHeld() ); 33416 pp = &winShmNodeList; 34353 pp = &winShmNodeList; 33417 while( (p = *pp)!=0 ){ 34354 while( (p = *pp)!=0 ){ 33418 if( p->nRef==0 ){ 34355 if( p->nRef==0 ){ 33419 int i; 34356 int i; 33420 if( p->mutex ) sqlite3_mutex_free(p->mutex); 34357 if( p->mutex ) sqlite3_mutex_free(p->mutex); 33421 for(i=0; i<p->nRegion; i++){ 34358 for(i=0; i<p->nRegion; i++){ 33422 bRc = UnmapViewOfFile(p->aRegion[i].pMap); | 34359 bRc = osUnmapViewOfFile(p->aRegion[i].pMap); 33423 OSTRACE(("SHM-PURGE pid-%d unmap region=%d %s\n", 34360 OSTRACE(("SHM-PURGE pid-%d unmap region=%d %s\n", 33424 (int)GetCurrentProcessId(), i, | 34361 (int)osGetCurrentProcessId(), i, 33425 bRc ? "ok" : "failed")); 34362 bRc ? "ok" : "failed")); 33426 bRc = CloseHandle(p->aRegion[i].hMap); | 34363 bRc = osCloseHandle(p->aRegion[i].hMap); 33427 OSTRACE(("SHM-PURGE pid-%d close region=%d %s\n", 34364 OSTRACE(("SHM-PURGE pid-%d close region=%d %s\n", 33428 (int)GetCurrentProcessId(), i, | 34365 (int)osGetCurrentProcessId(), i, 33429 bRc ? "ok" : "failed")); 34366 bRc ? "ok" : "failed")); 33430 } 34367 } 33431 if( p->hFile.h != INVALID_HANDLE_VALUE ){ 34368 if( p->hFile.h != INVALID_HANDLE_VALUE ){ 33432 SimulateIOErrorBenign(1); 34369 SimulateIOErrorBenign(1); 33433 winClose((sqlite3_file *)&p->hFile); 34370 winClose((sqlite3_file *)&p->hFile); 33434 SimulateIOErrorBenign(0); 34371 SimulateIOErrorBenign(0); 33435 } 34372 } 33436 if( deleteFlag ){ 34373 if( deleteFlag ){ 33437 SimulateIOErrorBenign(1); 34374 SimulateIOErrorBenign(1); > 34375 sqlite3BeginBenignMalloc(); 33438 winDelete(pVfs, p->zFilename, 0); 34376 winDelete(pVfs, p->zFilename, 0); > 34377 sqlite3EndBenignMalloc(); 33439 SimulateIOErrorBenign(0); 34378 SimulateIOErrorBenign(0); 33440 } 34379 } 33441 *pp = p->pNext; 34380 *pp = p->pNext; 33442 sqlite3_free(p->aRegion); 34381 sqlite3_free(p->aRegion); 33443 sqlite3_free(p); 34382 sqlite3_free(p); 33444 }else{ 34383 }else{ 33445 pp = &p->pNext; 34384 pp = &p->pNext; ................................................................................................................................................................................ 33463 34402 33464 assert( pDbFd->pShm==0 ); /* Not previously opened */ 34403 assert( pDbFd->pShm==0 ); /* Not previously opened */ 33465 34404 33466 /* Allocate space for the new sqlite3_shm object. Also speculatively 34405 /* Allocate space for the new sqlite3_shm object. Also speculatively 33467 ** allocate space for a new winShmNode and filename. 34406 ** allocate space for a new winShmNode and filename. 33468 */ 34407 */ 33469 p = sqlite3_malloc( sizeof(*p) ); 34408 p = sqlite3_malloc( sizeof(*p) ); 33470 if( p==0 ) return SQLITE_NOMEM; | 34409 if( p==0 ) return SQLITE_IOERR_NOMEM; 33471 memset(p, 0, sizeof(*p)); 34410 memset(p, 0, sizeof(*p)); 33472 nName = sqlite3Strlen30(pDbFd->zPath); 34411 nName = sqlite3Strlen30(pDbFd->zPath); 33473 pNew = sqlite3_malloc( sizeof(*pShmNode) + nName + 15 ); | 34412 pNew = sqlite3_malloc( sizeof(*pShmNode) + nName + 17 ); 33474 if( pNew==0 ){ 34413 if( pNew==0 ){ 33475 sqlite3_free(p); 34414 sqlite3_free(p); 33476 return SQLITE_NOMEM; | 34415 return SQLITE_IOERR_NOMEM; 33477 } 34416 } 33478 memset(pNew, 0, sizeof(*pNew)); | 34417 memset(pNew, 0, sizeof(*pNew) + nName + 17); 33479 pNew->zFilename = (char*)&pNew[1]; 34418 pNew->zFilename = (char*)&pNew[1]; 33480 sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath); 34419 sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath); 33481 sqlite3FileSuffix3(pDbFd->zPath, pNew->zFilename); 34420 sqlite3FileSuffix3(pDbFd->zPath, pNew->zFilename); 33482 34421 33483 /* Look to see if there is an existing winShmNode that can be used. 34422 /* Look to see if there is an existing winShmNode that can be used. 33484 ** If no matching winShmNode currently exists, create a new one. 34423 ** If no matching winShmNode currently exists, create a new one. 33485 */ 34424 */ ................................................................................................................................................................................ 33497 pNew = 0; 34436 pNew = 0; 33498 ((winFile*)(&pShmNode->hFile))->h = INVALID_HANDLE_VALUE; 34437 ((winFile*)(&pShmNode->hFile))->h = INVALID_HANDLE_VALUE; 33499 pShmNode->pNext = winShmNodeList; 34438 pShmNode->pNext = winShmNodeList; 33500 winShmNodeList = pShmNode; 34439 winShmNodeList = pShmNode; 33501 34440 33502 pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST); 34441 pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST); 33503 if( pShmNode->mutex==0 ){ 34442 if( pShmNode->mutex==0 ){ 33504 rc = SQLITE_NOMEM; | 34443 rc = SQLITE_IOERR_NOMEM; 33505 goto shm_open_err; 34444 goto shm_open_err; 33506 } 34445 } 33507 34446 33508 rc = winOpen(pDbFd->pVfs, 34447 rc = winOpen(pDbFd->pVfs, 33509 pShmNode->zFilename, /* Name of the file (UTF-8) */ 34448 pShmNode->zFilename, /* Name of the file (UTF-8) */ 33510 (sqlite3_file*)&pShmNode->hFile, /* File handle here */ 34449 (sqlite3_file*)&pShmNode->hFile, /* File handle here */ 33511 SQLITE_OPEN_WAL | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, / 34450 SQLITE_OPEN_WAL | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, / 33512 0); 34451 0); 33513 if( SQLITE_OK!=rc ){ 34452 if( SQLITE_OK!=rc ){ 33514 rc = SQLITE_CANTOPEN_BKPT; < 33515 goto shm_open_err; 34453 goto shm_open_err; 33516 } 34454 } 33517 34455 33518 /* Check to see if another process is holding the dead-man switch. 34456 /* Check to see if another process is holding the dead-man switch. 33519 ** If not, truncate the file to zero length. 34457 ** If not, truncate the file to zero length. 33520 */ 34458 */ 33521 if( winShmSystemLock(pShmNode, _SHM_WRLCK, WIN_SHM_DMS, 1)==SQLITE_OK ){ 34459 if( winShmSystemLock(pShmNode, _SHM_WRLCK, WIN_SHM_DMS, 1)==SQLITE_OK ){ 33522 rc = winTruncate((sqlite3_file *)&pShmNode->hFile, 0); 34460 rc = winTruncate((sqlite3_file *)&pShmNode->hFile, 0); 33523 if( rc!=SQLITE_OK ){ 34461 if( rc!=SQLITE_OK ){ 33524 rc = winLogError(SQLITE_IOERR_SHMOPEN, "winOpenShm", pDbFd->zPath); | 34462 rc = winLogError(SQLITE_IOERR_SHMOPEN, osGetLastError(), > 34463 "winOpenShm", pDbFd->zPath); 33525 } 34464 } 33526 } 34465 } 33527 if( rc==SQLITE_OK ){ 34466 if( rc==SQLITE_OK ){ 33528 winShmSystemLock(pShmNode, _SHM_UNLCK, WIN_SHM_DMS, 1); 34467 winShmSystemLock(pShmNode, _SHM_UNLCK, WIN_SHM_DMS, 1); 33529 rc = winShmSystemLock(pShmNode, _SHM_RDLCK, WIN_SHM_DMS, 1); 34468 rc = winShmSystemLock(pShmNode, _SHM_RDLCK, WIN_SHM_DMS, 1); 33530 } 34469 } 33531 if( rc ) goto shm_open_err; 34470 if( rc ) goto shm_open_err; ................................................................................................................................................................................ 33702 assert( (p->sharedMask & mask)==0 ); 34641 assert( (p->sharedMask & mask)==0 ); 33703 p->exclMask |= mask; 34642 p->exclMask |= mask; 33704 } 34643 } 33705 } 34644 } 33706 } 34645 } 33707 sqlite3_mutex_leave(pShmNode->mutex); 34646 sqlite3_mutex_leave(pShmNode->mutex); 33708 OSTRACE(("SHM-LOCK shmid-%d, pid-%d got %03x,%03x %s\n", 34647 OSTRACE(("SHM-LOCK shmid-%d, pid-%d got %03x,%03x %s\n", 33709 p->id, (int)GetCurrentProcessId(), p->sharedMask, p->exclMask, | 34648 p->id, (int)osGetCurrentProcessId(), p->sharedMask, p->exclMask, 33710 rc ? "failed" : "ok")); 34649 rc ? "failed" : "ok")); 33711 return rc; 34650 return rc; 33712 } 34651 } 33713 34652 33714 /* 34653 /* 33715 ** Implement a memory barrier or memory fence on shared memory. 34654 ** Implement a memory barrier or memory fence on shared memory. 33716 ** 34655 ** ................................................................................................................................................................................ 33776 34715 33777 /* The requested region is not mapped into this processes address space. 34716 /* The requested region is not mapped into this processes address space. 33778 ** Check to see if it has been allocated (i.e. if the wal-index file is 34717 ** Check to see if it has been allocated (i.e. if the wal-index file is 33779 ** large enough to contain the requested region). 34718 ** large enough to contain the requested region). 33780 */ 34719 */ 33781 rc = winFileSize((sqlite3_file *)&pShmNode->hFile, &sz); 34720 rc = winFileSize((sqlite3_file *)&pShmNode->hFile, &sz); 33782 if( rc!=SQLITE_OK ){ 34721 if( rc!=SQLITE_OK ){ 33783 rc = winLogError(SQLITE_IOERR_SHMSIZE, "winShmMap1", pDbFd->zPath); | 34722 rc = winLogError(SQLITE_IOERR_SHMSIZE, osGetLastError(), > 34723 "winShmMap1", pDbFd->zPath); 33784 goto shmpage_out; 34724 goto shmpage_out; 33785 } 34725 } 33786 34726 33787 if( sz<nByte ){ 34727 if( sz<nByte ){ 33788 /* The requested memory region does not exist. If isWrite is set to 34728 /* The requested memory region does not exist. If isWrite is set to 33789 ** zero, exit early. *pp will be set to NULL and SQLITE_OK returned. 34729 ** zero, exit early. *pp will be set to NULL and SQLITE_OK returned. 33790 ** 34730 ** 33791 ** Alternatively, if isWrite is non-zero, use ftruncate() to allocate 34731 ** Alternatively, if isWrite is non-zero, use ftruncate() to allocate 33792 ** the requested memory region. 34732 ** the requested memory region. 33793 */ 34733 */ 33794 if( !isWrite ) goto shmpage_out; 34734 if( !isWrite ) goto shmpage_out; 33795 rc = winTruncate((sqlite3_file *)&pShmNode->hFile, nByte); 34735 rc = winTruncate((sqlite3_file *)&pShmNode->hFile, nByte); 33796 if( rc!=SQLITE_OK ){ 34736 if( rc!=SQLITE_OK ){ 33797 rc = winLogError(SQLITE_IOERR_SHMSIZE, "winShmMap2", pDbFd->zPath); | 34737 rc = winLogError(SQLITE_IOERR_SHMSIZE, osGetLastError(), > 34738 "winShmMap2", pDbFd->zPath); 33798 goto shmpage_out; 34739 goto shmpage_out; 33799 } 34740 } 33800 } 34741 } 33801 34742 33802 /* Map the requested memory region into this processes address space. */ 34743 /* Map the requested memory region into this processes address space. */ 33803 apNew = (struct ShmRegion *)sqlite3_realloc( 34744 apNew = (struct ShmRegion *)sqlite3_realloc( 33804 pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0]) 34745 pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0]) ................................................................................................................................................................................ 33809 } 34750 } 33810 pShmNode->aRegion = apNew; 34751 pShmNode->aRegion = apNew; 33811 34752 33812 while( pShmNode->nRegion<=iRegion ){ 34753 while( pShmNode->nRegion<=iRegion ){ 33813 HANDLE hMap; /* file-mapping handle */ 34754 HANDLE hMap; /* file-mapping handle */ 33814 void *pMap = 0; /* Mapped memory region */ 34755 void *pMap = 0; /* Mapped memory region */ 33815 34756 33816 hMap = CreateFileMapping(pShmNode->hFile.h, | 34757 hMap = osCreateFileMapping(pShmNode->hFile.h, 33817 NULL, PAGE_READWRITE, 0, nByte, NULL 34758 NULL, PAGE_READWRITE, 0, nByte, NULL 33818 ); 34759 ); 33819 OSTRACE(("SHM-MAP pid-%d create region=%d nbyte=%d %s\n", 34760 OSTRACE(("SHM-MAP pid-%d create region=%d nbyte=%d %s\n", 33820 (int)GetCurrentProcessId(), pShmNode->nRegion, nByte, | 34761 (int)osGetCurrentProcessId(), pShmNode->nRegion, nByte, 33821 hMap ? "ok" : "failed")); 34762 hMap ? "ok" : "failed")); 33822 if( hMap ){ 34763 if( hMap ){ 33823 int iOffset = pShmNode->nRegion*szRegion; 34764 int iOffset = pShmNode->nRegion*szRegion; 33824 int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity; 34765 int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity; 33825 pMap = MapViewOfFile(hMap, FILE_MAP_WRITE | FILE_MAP_READ, | 34766 pMap = osMapViewOfFile(hMap, FILE_MAP_WRITE | FILE_MAP_READ, 33826 0, iOffset - iOffsetShift, szRegion + iOffsetShift 34767 0, iOffset - iOffsetShift, szRegion + iOffsetShift 33827 ); 34768 ); 33828 OSTRACE(("SHM-MAP pid-%d map region=%d offset=%d size=%d %s\n", 34769 OSTRACE(("SHM-MAP pid-%d map region=%d offset=%d size=%d %s\n", 33829 (int)GetCurrentProcessId(), pShmNode->nRegion, iOffset, szRegio | 34770 (int)osGetCurrentProcessId(), pShmNode->nRegion, iOffset, 33830 pMap ? "ok" : "failed")); | 34771 szRegion, pMap ? "ok" : "failed")); 33831 } 34772 } 33832 if( !pMap ){ 34773 if( !pMap ){ 33833 pShmNode->lastErrno = GetLastError(); | 34774 pShmNode->lastErrno = osGetLastError(); 33834 rc = winLogError(SQLITE_IOERR_SHMMAP, "winShmMap3", pDbFd->zPath); | 34775 rc = winLogError(SQLITE_IOERR_SHMMAP, pShmNode->lastErrno, > 34776 "winShmMap3", pDbFd->zPath); 33835 if( hMap ) CloseHandle(hMap); | 34777 if( hMap ) osCloseHandle(hMap); 33836 goto shmpage_out; 34778 goto shmpage_out; 33837 } 34779 } 33838 34780 33839 pShmNode->aRegion[pShmNode->nRegion].pMap = pMap; 34781 pShmNode->aRegion[pShmNode->nRegion].pMap = pMap; 33840 pShmNode->aRegion[pShmNode->nRegion].hMap = hMap; 34782 pShmNode->aRegion[pShmNode->nRegion].hMap = hMap; 33841 pShmNode->nRegion++; 34783 pShmNode->nRegion++; 33842 } 34784 } ................................................................................................................................................................................ 33926 */ 34868 */ 33927 static int getTempname(int nBuf, char *zBuf){ 34869 static int getTempname(int nBuf, char *zBuf){ 33928 static char zChars[] = 34870 static char zChars[] = 33929 "abcdefghijklmnopqrstuvwxyz" 34871 "abcdefghijklmnopqrstuvwxyz" 33930 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 34872 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 33931 "0123456789"; 34873 "0123456789"; 33932 size_t i, j; 34874 size_t i, j; 33933 char zTempPath[MAX_PATH+1]; | 34875 char zTempPath[MAX_PATH+2]; 33934 34876 33935 /* It's odd to simulate an io-error here, but really this is just 34877 /* It's odd to simulate an io-error here, but really this is just 33936 ** using the io-error infrastructure to test that SQLite handles this 34878 ** using the io-error infrastructure to test that SQLite handles this 33937 ** function failing. 34879 ** function failing. 33938 */ 34880 */ 33939 SimulateIOError( return SQLITE_IOERR ); 34881 SimulateIOError( return SQLITE_IOERR ); 33940 34882 33941 if( sqlite3_temp_directory ){ 34883 if( sqlite3_temp_directory ){ 33942 sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", sqlite3_temp_directory); 34884 sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", sqlite3_temp_directory); 33943 }else if( isNT() ){ 34885 }else if( isNT() ){ 33944 char *zMulti; 34886 char *zMulti; 33945 WCHAR zWidePath[MAX_PATH]; 34887 WCHAR zWidePath[MAX_PATH]; 33946 GetTempPathW(MAX_PATH-30, zWidePath); | 34888 osGetTempPathW(MAX_PATH-30, zWidePath); 33947 zMulti = unicodeToUtf8(zWidePath); 34889 zMulti = unicodeToUtf8(zWidePath); 33948 if( zMulti ){ 34890 if( zMulti ){ 33949 sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zMulti); 34891 sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zMulti); 33950 free(zMulti); | 34892 sqlite3_free(zMulti); 33951 }else{ 34893 }else{ 33952 return SQLITE_NOMEM; | 34894 return SQLITE_IOERR_NOMEM; 33953 } 34895 } 33954 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 34896 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 33955 ** Since the ASCII version of these Windows API do not exist for WINCE, | 34897 ** Since the ANSI version of these Windows API do not exist for WINCE, 33956 ** it's important to not reference them for WINCE builds. 34898 ** it's important to not reference them for WINCE builds. 33957 */ 34899 */ 33958 #if SQLITE_OS_WINCE==0 34900 #if SQLITE_OS_WINCE==0 33959 }else{ 34901 }else{ 33960 char *zUtf8; 34902 char *zUtf8; 33961 char zMbcsPath[MAX_PATH]; 34903 char zMbcsPath[MAX_PATH]; 33962 GetTempPathA(MAX_PATH-30, zMbcsPath); | 34904 osGetTempPathA(MAX_PATH-30, zMbcsPath); 33963 zUtf8 = sqlite3_win32_mbcs_to_utf8(zMbcsPath); 34905 zUtf8 = sqlite3_win32_mbcs_to_utf8(zMbcsPath); 33964 if( zUtf8 ){ 34906 if( zUtf8 ){ 33965 sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zUtf8); 34907 sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zUtf8); 33966 free(zUtf8); | 34908 sqlite3_free(zUtf8); 33967 }else{ 34909 }else{ 33968 return SQLITE_NOMEM; | 34910 return SQLITE_IOERR_NOMEM; 33969 } 34911 } 33970 #endif 34912 #endif 33971 } 34913 } 33972 34914 33973 /* Check that the output buffer is large enough for the temporary file 34915 /* Check that the output buffer is large enough for the temporary file 33974 ** name. If it is not, return SQLITE_ERROR. 34916 ** name. If it is not, return SQLITE_ERROR. 33975 */ 34917 */ 33976 if( (sqlite3Strlen30(zTempPath) + sqlite3Strlen30(SQLITE_TEMP_FILE_PREFIX) + 1 | 34918 if( (sqlite3Strlen30(zTempPath) + sqlite3Strlen30(SQLITE_TEMP_FILE_PREFIX) + 1 33977 return SQLITE_ERROR; 34919 return SQLITE_ERROR; 33978 } 34920 } 33979 34921 33980 for(i=sqlite3Strlen30(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){} 34922 for(i=sqlite3Strlen30(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){} 33981 zTempPath[i] = 0; 34923 zTempPath[i] = 0; 33982 34924 33983 sqlite3_snprintf(nBuf-17, zBuf, | 34925 sqlite3_snprintf(nBuf-18, zBuf, 33984 "%s\\"SQLITE_TEMP_FILE_PREFIX, zTempPath); 34926 "%s\\"SQLITE_TEMP_FILE_PREFIX, zTempPath); 33985 j = sqlite3Strlen30(zBuf); 34927 j = sqlite3Strlen30(zBuf); 33986 sqlite3_randomness(15, &zBuf[j]); 34928 sqlite3_randomness(15, &zBuf[j]); 33987 for(i=0; i<15; i++, j++){ 34929 for(i=0; i<15; i++, j++){ 33988 zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ]; 34930 zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ]; 33989 } 34931 } 33990 zBuf[j] = 0; 34932 zBuf[j] = 0; > 34933 zBuf[j+1] = 0; 33991 34934 33992 OSTRACE(("TEMP FILENAME: %s\n", zBuf)); 34935 OSTRACE(("TEMP FILENAME: %s\n", zBuf)); 33993 return SQLITE_OK; 34936 return SQLITE_OK; 33994 } 34937 } 33995 34938 33996 /* 34939 /* 33997 ** Open a file. 34940 ** Open a file. ................................................................................................................................................................................ 34000 sqlite3_vfs *pVfs, /* Not used */ 34943 sqlite3_vfs *pVfs, /* Not used */ 34001 const char *zName, /* Name of the file (UTF-8) */ 34944 const char *zName, /* Name of the file (UTF-8) */ 34002 sqlite3_file *id, /* Write the SQLite file handle here */ 34945 sqlite3_file *id, /* Write the SQLite file handle here */ 34003 int flags, /* Open mode flags */ 34946 int flags, /* Open mode flags */ 34004 int *pOutFlags /* Status return flags */ 34947 int *pOutFlags /* Status return flags */ 34005 ){ 34948 ){ 34006 HANDLE h; 34949 HANDLE h; > 34950 DWORD lastErrno; 34007 DWORD dwDesiredAccess; 34951 DWORD dwDesiredAccess; 34008 DWORD dwShareMode; 34952 DWORD dwShareMode; 34009 DWORD dwCreationDisposition; 34953 DWORD dwCreationDisposition; 34010 DWORD dwFlagsAndAttributes = 0; 34954 DWORD dwFlagsAndAttributes = 0; 34011 #if SQLITE_OS_WINCE 34955 #if SQLITE_OS_WINCE 34012 int isTemp = 0; 34956 int isTemp = 0; 34013 #endif 34957 #endif ................................................................................................................................................................................ 34015 void *zConverted; /* Filename in OS encoding */ 34959 void *zConverted; /* Filename in OS encoding */ 34016 const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */ 34960 const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */ 34017 int cnt = 0; 34961 int cnt = 0; 34018 34962 34019 /* If argument zPath is a NULL pointer, this function is required to open 34963 /* If argument zPath is a NULL pointer, this function is required to open 34020 ** a temporary file. Use this buffer to store the file name in. 34964 ** a temporary file. Use this buffer to store the file name in. 34021 */ 34965 */ 34022 char zTmpname[MAX_PATH+1]; /* Buffer used to create temp filename */ | 34966 char zTmpname[MAX_PATH+2]; /* Buffer used to create temp filename */ 34023 34967 34024 int rc = SQLITE_OK; /* Function Return Code */ 34968 int rc = SQLITE_OK; /* Function Return Code */ 34025 #if !defined(NDEBUG) || SQLITE_OS_WINCE 34969 #if !defined(NDEBUG) || SQLITE_OS_WINCE 34026 int eType = flags&0xFFFFFF00; /* Type of file to open */ 34970 int eType = flags&0xFFFFFF00; /* Type of file to open */ 34027 #endif 34971 #endif 34028 34972 34029 int isExclusive = (flags & SQLITE_OPEN_EXCLUSIVE); 34973 int isExclusive = (flags & SQLITE_OPEN_EXCLUSIVE); ................................................................................................................................................................................ 34074 pFile->h = INVALID_HANDLE_VALUE; 35018 pFile->h = INVALID_HANDLE_VALUE; 34075 35019 34076 /* If the second argument to this function is NULL, generate a 35020 /* If the second argument to this function is NULL, generate a 34077 ** temporary file name to use 35021 ** temporary file name to use 34078 */ 35022 */ 34079 if( !zUtf8Name ){ 35023 if( !zUtf8Name ){ 34080 assert(isDelete && !isOpenJournal); 35024 assert(isDelete && !isOpenJournal); 34081 rc = getTempname(MAX_PATH+1, zTmpname); | 35025 rc = getTempname(MAX_PATH+2, zTmpname); 34082 if( rc!=SQLITE_OK ){ 35026 if( rc!=SQLITE_OK ){ 34083 return rc; 35027 return rc; 34084 } 35028 } 34085 zUtf8Name = zTmpname; 35029 zUtf8Name = zTmpname; 34086 } 35030 } > 35031 > 35032 /* Database filenames are double-zero terminated if they are not > 35033 ** URIs with parameters. Hence, they can always be passed into > 35034 ** sqlite3_uri_parameter(). > 35035 */ > 35036 assert( (eType!=SQLITE_OPEN_MAIN_DB) || (flags & SQLITE_OPEN_URI) || > 35037 zUtf8Name[strlen(zUtf8Name)+1]==0 ); 34087 35038 34088 /* Convert the filename to the system encoding. */ 35039 /* Convert the filename to the system encoding. */ 34089 zConverted = convertUtf8Filename(zUtf8Name); 35040 zConverted = convertUtf8Filename(zUtf8Name); 34090 if( zConverted==0 ){ 35041 if( zConverted==0 ){ 34091 return SQLITE_NOMEM; | 35042 return SQLITE_IOERR_NOMEM; 34092 } 35043 } 34093 35044 34094 if( isReadWrite ){ 35045 if( isReadWrite ){ 34095 dwDesiredAccess = GENERIC_READ | GENERIC_WRITE; 35046 dwDesiredAccess = GENERIC_READ | GENERIC_WRITE; 34096 }else{ 35047 }else{ 34097 dwDesiredAccess = GENERIC_READ; 35048 dwDesiredAccess = GENERIC_READ; 34098 } 35049 } ................................................................................................................................................................................ 34130 /* Reports from the internet are that performance is always 35081 /* Reports from the internet are that performance is always 34131 ** better if FILE_FLAG_RANDOM_ACCESS is used. Ticket #2699. */ 35082 ** better if FILE_FLAG_RANDOM_ACCESS is used. Ticket #2699. */ 34132 #if SQLITE_OS_WINCE 35083 #if SQLITE_OS_WINCE 34133 dwFlagsAndAttributes |= FILE_FLAG_RANDOM_ACCESS; 35084 dwFlagsAndAttributes |= FILE_FLAG_RANDOM_ACCESS; 34134 #endif 35085 #endif 34135 35086 34136 if( isNT() ){ 35087 if( isNT() ){ 34137 while( (h = CreateFileW((WCHAR*)zConverted, | 35088 while( (h = osCreateFileW((LPCWSTR)zConverted, 34138 dwDesiredAccess, | 35089 dwDesiredAccess, 34139 dwShareMode, NULL, | 35090 dwShareMode, NULL, 34140 dwCreationDisposition, | 35091 dwCreationDisposition, 34141 dwFlagsAndAttributes, | 35092 dwFlagsAndAttributes, 34142 NULL))==INVALID_HANDLE_VALUE && | 35093 NULL))==INVALID_HANDLE_VALUE && 34143 retryIoerr(&cnt) ){} | 35094 retryIoerr(&cnt, &lastErrno) ){} 34144 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 35095 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 34145 ** Since the ASCII version of these Windows API do not exist for WINCE, | 35096 ** Since the ANSI version of these Windows API do not exist for WINCE, 34146 ** it's important to not reference them for WINCE builds. 35097 ** it's important to not reference them for WINCE builds. 34147 */ 35098 */ 34148 #if SQLITE_OS_WINCE==0 35099 #if SQLITE_OS_WINCE==0 34149 }else{ 35100 }else{ 34150 while( (h = CreateFileA((char*)zConverted, | 35101 while( (h = osCreateFileA((LPCSTR)zConverted, 34151 dwDesiredAccess, | 35102 dwDesiredAccess, 34152 dwShareMode, NULL, | 35103 dwShareMode, NULL, 34153 dwCreationDisposition, | 35104 dwCreationDisposition, 34154 dwFlagsAndAttributes, | 35105 dwFlagsAndAttributes, 34155 NULL))==INVALID_HANDLE_VALUE && | 35106 NULL))==INVALID_HANDLE_VALUE && 34156 retryIoerr(&cnt) ){} | 35107 retryIoerr(&cnt, &lastErrno) ){} 34157 #endif 35108 #endif 34158 } 35109 } 34159 35110 34160 logIoerr(cnt); 35111 logIoerr(cnt); 34161 35112 34162 OSTRACE(("OPEN %d %s 0x%lx %s\n", 35113 OSTRACE(("OPEN %d %s 0x%lx %s\n", 34163 h, zName, dwDesiredAccess, 35114 h, zName, dwDesiredAccess, 34164 h==INVALID_HANDLE_VALUE ? "failed" : "ok")); 35115 h==INVALID_HANDLE_VALUE ? "failed" : "ok")); 34165 35116 34166 if( h==INVALID_HANDLE_VALUE ){ 35117 if( h==INVALID_HANDLE_VALUE ){ 34167 pFile->lastErrno = GetLastError(); | 35118 pFile->lastErrno = lastErrno; 34168 winLogError(SQLITE_CANTOPEN, "winOpen", zUtf8Name); | 35119 winLogError(SQLITE_CANTOPEN, pFile->lastErrno, "winOpen", zUtf8Name); 34169 free(zConverted); | 35120 sqlite3_free(zConverted); 34170 if( isReadWrite && !isExclusive ){ 35121 if( isReadWrite && !isExclusive ){ 34171 return winOpen(pVfs, zName, id, 35122 return winOpen(pVfs, zName, id, 34172 ((flags|SQLITE_OPEN_READONLY)&~(SQLITE_OPEN_CREATE|SQLITE_OPEN_READ 35123 ((flags|SQLITE_OPEN_READONLY)&~(SQLITE_OPEN_CREATE|SQLITE_OPEN_READ 34173 }else{ 35124 }else{ 34174 return SQLITE_CANTOPEN_BKPT; 35125 return SQLITE_CANTOPEN_BKPT; 34175 } 35126 } 34176 } 35127 } ................................................................................................................................................................................ 34186 memset(pFile, 0, sizeof(*pFile)); 35137 memset(pFile, 0, sizeof(*pFile)); 34187 pFile->pMethod = &winIoMethod; 35138 pFile->pMethod = &winIoMethod; 34188 pFile->h = h; 35139 pFile->h = h; 34189 pFile->lastErrno = NO_ERROR; 35140 pFile->lastErrno = NO_ERROR; 34190 pFile->pVfs = pVfs; 35141 pFile->pVfs = pVfs; 34191 pFile->pShm = 0; 35142 pFile->pShm = 0; 34192 pFile->zPath = zName; 35143 pFile->zPath = zName; 34193 pFile->sectorSize = getSectorSize(pVfs, zUtf8Name); | 35144 if( sqlite3_uri_boolean(zName, "psow", SQLITE_POWERSAFE_OVERWRITE) ){ > 35145 pFile->ctrlFlags |= WINFILE_PSOW; > 35146 } 34194 35147 34195 #if SQLITE_OS_WINCE 35148 #if SQLITE_OS_WINCE 34196 if( isReadWrite && eType==SQLITE_OPEN_MAIN_DB 35149 if( isReadWrite && eType==SQLITE_OPEN_MAIN_DB 34197 && !winceCreateLock(zName, pFile) 35150 && !winceCreateLock(zName, pFile) 34198 ){ 35151 ){ 34199 CloseHandle(h); | 35152 osCloseHandle(h); 34200 free(zConverted); | 35153 sqlite3_free(zConverted); 34201 return SQLITE_CANTOPEN_BKPT; 35154 return SQLITE_CANTOPEN_BKPT; 34202 } 35155 } 34203 if( isTemp ){ 35156 if( isTemp ){ 34204 pFile->zDeleteOnClose = zConverted; 35157 pFile->zDeleteOnClose = zConverted; 34205 }else 35158 }else 34206 #endif 35159 #endif 34207 { 35160 { 34208 free(zConverted); | 35161 sqlite3_free(zConverted); 34209 } 35162 } 34210 35163 34211 OpenCounter(+1); 35164 OpenCounter(+1); 34212 return rc; 35165 return rc; 34213 } 35166 } 34214 35167 34215 /* 35168 /* 34216 ** Delete the named file. 35169 ** Delete the named file. 34217 ** 35170 ** 34218 ** Note that windows does not allow a file to be deleted if some other | 35171 ** Note that Windows does not allow a file to be deleted if some other 34219 ** process has it open. Sometimes a virus scanner or indexing program 35172 ** process has it open. Sometimes a virus scanner or indexing program 34220 ** will open a journal file shortly after it is created in order to do 35173 ** will open a journal file shortly after it is created in order to do 34221 ** whatever it does. While this other process is holding the 35174 ** whatever it does. While this other process is holding the 34222 ** file open, we will be unable to delete it. To work around this 35175 ** file open, we will be unable to delete it. To work around this 34223 ** problem, we delay 100 milliseconds and try to delete again. Up 35176 ** problem, we delay 100 milliseconds and try to delete again. Up 34224 ** to MX_DELETION_ATTEMPTs deletion attempts are run before giving 35177 ** to MX_DELETION_ATTEMPTs deletion attempts are run before giving 34225 ** up and returning an error. 35178 ** up and returning an error. ................................................................................................................................................................................ 34227 static int winDelete( 35180 static int winDelete( 34228 sqlite3_vfs *pVfs, /* Not used on win32 */ 35181 sqlite3_vfs *pVfs, /* Not used on win32 */ 34229 const char *zFilename, /* Name of file to delete */ 35182 const char *zFilename, /* Name of file to delete */ 34230 int syncDir /* Not used on win32 */ 35183 int syncDir /* Not used on win32 */ 34231 ){ 35184 ){ 34232 int cnt = 0; 35185 int cnt = 0; 34233 int rc; 35186 int rc; > 35187 DWORD lastErrno; 34234 void *zConverted; 35188 void *zConverted; 34235 UNUSED_PARAMETER(pVfs); 35189 UNUSED_PARAMETER(pVfs); 34236 UNUSED_PARAMETER(syncDir); 35190 UNUSED_PARAMETER(syncDir); 34237 35191 34238 SimulateIOError(return SQLITE_IOERR_DELETE); 35192 SimulateIOError(return SQLITE_IOERR_DELETE); 34239 zConverted = convertUtf8Filename(zFilename); 35193 zConverted = convertUtf8Filename(zFilename); 34240 if( zConverted==0 ){ 35194 if( zConverted==0 ){ 34241 return SQLITE_NOMEM; | 35195 return SQLITE_IOERR_NOMEM; 34242 } 35196 } 34243 if( isNT() ){ 35197 if( isNT() ){ 34244 rc = 1; 35198 rc = 1; 34245 while( GetFileAttributesW(zConverted)!=INVALID_FILE_ATTRIBUTES && | 35199 while( osGetFileAttributesW(zConverted)!=INVALID_FILE_ATTRIBUTES && 34246 (rc = DeleteFileW(zConverted))==0 && retryIoerr(&cnt) ){} | 35200 (rc = osDeleteFileW(zConverted))==0 && retryIoerr(&cnt, &lastErrno) ){} 34247 rc = rc ? SQLITE_OK : SQLITE_ERROR; 35201 rc = rc ? SQLITE_OK : SQLITE_ERROR; 34248 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 35202 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 34249 ** Since the ASCII version of these Windows API do not exist for WINCE, | 35203 ** Since the ANSI version of these Windows API do not exist for WINCE, 34250 ** it's important to not reference them for WINCE builds. 35204 ** it's important to not reference them for WINCE builds. 34251 */ 35205 */ 34252 #if SQLITE_OS_WINCE==0 35206 #if SQLITE_OS_WINCE==0 34253 }else{ 35207 }else{ 34254 rc = 1; 35208 rc = 1; 34255 while( GetFileAttributesA(zConverted)!=INVALID_FILE_ATTRIBUTES && | 35209 while( osGetFileAttributesA(zConverted)!=INVALID_FILE_ATTRIBUTES && 34256 (rc = DeleteFileA(zConverted))==0 && retryIoerr(&cnt) ){} | 35210 (rc = osDeleteFileA(zConverted))==0 && retryIoerr(&cnt, &lastErrno) ){} 34257 rc = rc ? SQLITE_OK : SQLITE_ERROR; 35211 rc = rc ? SQLITE_OK : SQLITE_ERROR; 34258 #endif 35212 #endif 34259 } 35213 } 34260 if( rc ){ 35214 if( rc ){ 34261 rc = winLogError(SQLITE_IOERR_DELETE, "winDelete", zFilename); | 35215 rc = winLogError(SQLITE_IOERR_DELETE, lastErrno, > 35216 "winDelete", zFilename); 34262 }else{ 35217 }else{ 34263 logIoerr(cnt); 35218 logIoerr(cnt); 34264 } 35219 } 34265 free(zConverted); | 35220 sqlite3_free(zConverted); 34266 OSTRACE(("DELETE \"%s\" %s\n", zFilename, (rc ? "failed" : "ok" ))); 35221 OSTRACE(("DELETE \"%s\" %s\n", zFilename, (rc ? "failed" : "ok" ))); 34267 return rc; 35222 return rc; 34268 } 35223 } 34269 35224 34270 /* 35225 /* 34271 ** Check the existance and status of a file. 35226 ** Check the existance and status of a file. 34272 */ 35227 */ ................................................................................................................................................................................ 34274 sqlite3_vfs *pVfs, /* Not used on win32 */ 35229 sqlite3_vfs *pVfs, /* Not used on win32 */ 34275 const char *zFilename, /* Name of file to check */ 35230 const char *zFilename, /* Name of file to check */ 34276 int flags, /* Type of test to make on this file */ 35231 int flags, /* Type of test to make on this file */ 34277 int *pResOut /* OUT: Result */ 35232 int *pResOut /* OUT: Result */ 34278 ){ 35233 ){ 34279 DWORD attr; 35234 DWORD attr; 34280 int rc = 0; 35235 int rc = 0; > 35236 DWORD lastErrno; 34281 void *zConverted; 35237 void *zConverted; 34282 UNUSED_PARAMETER(pVfs); 35238 UNUSED_PARAMETER(pVfs); 34283 35239 34284 SimulateIOError( return SQLITE_IOERR_ACCESS; ); 35240 SimulateIOError( return SQLITE_IOERR_ACCESS; ); 34285 zConverted = convertUtf8Filename(zFilename); 35241 zConverted = convertUtf8Filename(zFilename); 34286 if( zConverted==0 ){ 35242 if( zConverted==0 ){ 34287 return SQLITE_NOMEM; | 35243 return SQLITE_IOERR_NOMEM; 34288 } 35244 } 34289 if( isNT() ){ 35245 if( isNT() ){ 34290 int cnt = 0; 35246 int cnt = 0; 34291 WIN32_FILE_ATTRIBUTE_DATA sAttrData; 35247 WIN32_FILE_ATTRIBUTE_DATA sAttrData; 34292 memset(&sAttrData, 0, sizeof(sAttrData)); 35248 memset(&sAttrData, 0, sizeof(sAttrData)); 34293 while( !(rc = GetFileAttributesExW((WCHAR*)zConverted, | 35249 while( !(rc = osGetFileAttributesExW((LPCWSTR)zConverted, 34294 GetFileExInfoStandard, 35250 GetFileExInfoStandard, 34295 &sAttrData)) && retryIoerr(&cnt) ){} | 35251 &sAttrData)) && retryIoerr(&cnt, &lastErrno) ){} 34296 if( rc ){ 35252 if( rc ){ 34297 /* For an SQLITE_ACCESS_EXISTS query, treat a zero-length file 35253 /* For an SQLITE_ACCESS_EXISTS query, treat a zero-length file 34298 ** as if it does not exist. 35254 ** as if it does not exist. 34299 */ 35255 */ 34300 if( flags==SQLITE_ACCESS_EXISTS 35256 if( flags==SQLITE_ACCESS_EXISTS 34301 && sAttrData.nFileSizeHigh==0 35257 && sAttrData.nFileSizeHigh==0 34302 && sAttrData.nFileSizeLow==0 ){ 35258 && sAttrData.nFileSizeLow==0 ){ 34303 attr = INVALID_FILE_ATTRIBUTES; 35259 attr = INVALID_FILE_ATTRIBUTES; 34304 }else{ 35260 }else{ 34305 attr = sAttrData.dwFileAttributes; 35261 attr = sAttrData.dwFileAttributes; 34306 } 35262 } 34307 }else{ 35263 }else{ 34308 logIoerr(cnt); 35264 logIoerr(cnt); 34309 if( GetLastError()!=ERROR_FILE_NOT_FOUND ){ | 35265 if( lastErrno!=ERROR_FILE_NOT_FOUND ){ 34310 winLogError(SQLITE_IOERR_ACCESS, "winAccess", zFilename); | 35266 winLogError(SQLITE_IOERR_ACCESS, lastErrno, "winAccess", zFilename); 34311 free(zConverted); | 35267 sqlite3_free(zConverted); 34312 return SQLITE_IOERR_ACCESS; 35268 return SQLITE_IOERR_ACCESS; 34313 }else{ 35269 }else{ 34314 attr = INVALID_FILE_ATTRIBUTES; 35270 attr = INVALID_FILE_ATTRIBUTES; 34315 } 35271 } 34316 } 35272 } 34317 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 35273 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 34318 ** Since the ASCII version of these Windows API do not exist for WINCE, | 35274 ** Since the ANSI version of these Windows API do not exist for WINCE, 34319 ** it's important to not reference them for WINCE builds. 35275 ** it's important to not reference them for WINCE builds. 34320 */ 35276 */ 34321 #if SQLITE_OS_WINCE==0 35277 #if SQLITE_OS_WINCE==0 34322 }else{ 35278 }else{ 34323 attr = GetFileAttributesA((char*)zConverted); | 35279 attr = osGetFileAttributesA((char*)zConverted); 34324 #endif 35280 #endif 34325 } 35281 } 34326 free(zConverted); | 35282 sqlite3_free(zConverted); 34327 switch( flags ){ 35283 switch( flags ){ 34328 case SQLITE_ACCESS_READ: 35284 case SQLITE_ACCESS_READ: 34329 case SQLITE_ACCESS_EXISTS: 35285 case SQLITE_ACCESS_EXISTS: 34330 rc = attr!=INVALID_FILE_ATTRIBUTES; 35286 rc = attr!=INVALID_FILE_ATTRIBUTES; 34331 break; 35287 break; 34332 case SQLITE_ACCESS_READWRITE: 35288 case SQLITE_ACCESS_READWRITE: 34333 rc = attr!=INVALID_FILE_ATTRIBUTES && 35289 rc = attr!=INVALID_FILE_ATTRIBUTES && ................................................................................................................................................................................ 34384 ** using the io-error infrastructure to test that SQLite handles this 35340 ** using the io-error infrastructure to test that SQLite handles this 34385 ** function failing. This function could fail if, for example, the 35341 ** function failing. This function could fail if, for example, the 34386 ** current working directory has been unlinked. 35342 ** current working directory has been unlinked. 34387 */ 35343 */ 34388 SimulateIOError( return SQLITE_ERROR ); 35344 SimulateIOError( return SQLITE_ERROR ); 34389 UNUSED_PARAMETER(nFull); 35345 UNUSED_PARAMETER(nFull); 34390 zConverted = convertUtf8Filename(zRelative); 35346 zConverted = convertUtf8Filename(zRelative); > 35347 if( zConverted==0 ){ > 35348 return SQLITE_IOERR_NOMEM; > 35349 } 34391 if( isNT() ){ 35350 if( isNT() ){ 34392 WCHAR *zTemp; | 35351 LPWSTR zTemp; 34393 nByte = GetFullPathNameW((WCHAR*)zConverted, 0, 0, 0) + 3; | 35352 nByte = osGetFullPathNameW((LPCWSTR)zConverted, 0, 0, 0) + 3; 34394 zTemp = malloc( nByte*sizeof(zTemp[0]) ); | 35353 zTemp = sqlite3_malloc( nByte*sizeof(zTemp[0]) ); 34395 if( zTemp==0 ){ 35354 if( zTemp==0 ){ 34396 free(zConverted); | 35355 sqlite3_free(zConverted); 34397 return SQLITE_NOMEM; | 35356 return SQLITE_IOERR_NOMEM; 34398 } 35357 } 34399 GetFullPathNameW((WCHAR*)zConverted, nByte, zTemp, 0); | 35358 osGetFullPathNameW((LPCWSTR)zConverted, nByte, zTemp, 0); 34400 free(zConverted); | 35359 sqlite3_free(zConverted); 34401 zOut = unicodeToUtf8(zTemp); 35360 zOut = unicodeToUtf8(zTemp); 34402 free(zTemp); | 35361 sqlite3_free(zTemp); 34403 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 35362 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 34404 ** Since the ASCII version of these Windows API do not exist for WINCE, | 35363 ** Since the ANSI version of these Windows API do not exist for WINCE, 34405 ** it's important to not reference them for WINCE builds. 35364 ** it's important to not reference them for WINCE builds. 34406 */ 35365 */ 34407 #if SQLITE_OS_WINCE==0 35366 #if SQLITE_OS_WINCE==0 34408 }else{ 35367 }else{ 34409 char *zTemp; 35368 char *zTemp; 34410 nByte = GetFullPathNameA((char*)zConverted, 0, 0, 0) + 3; | 35369 nByte = osGetFullPathNameA((char*)zConverted, 0, 0, 0) + 3; 34411 zTemp = malloc( nByte*sizeof(zTemp[0]) ); | 35370 zTemp = sqlite3_malloc( nByte*sizeof(zTemp[0]) ); 34412 if( zTemp==0 ){ 35371 if( zTemp==0 ){ 34413 free(zConverted); | 35372 sqlite3_free(zConverted); 34414 return SQLITE_NOMEM; | 35373 return SQLITE_IOERR_NOMEM; 34415 } 35374 } 34416 GetFullPathNameA((char*)zConverted, nByte, zTemp, 0); | 35375 osGetFullPathNameA((char*)zConverted, nByte, zTemp, 0); 34417 free(zConverted); | 35376 sqlite3_free(zConverted); 34418 zOut = sqlite3_win32_mbcs_to_utf8(zTemp); 35377 zOut = sqlite3_win32_mbcs_to_utf8(zTemp); 34419 free(zTemp); | 35378 sqlite3_free(zTemp); 34420 #endif 35379 #endif 34421 } 35380 } 34422 if( zOut ){ 35381 if( zOut ){ 34423 sqlite3_snprintf(pVfs->mxPathname, zFull, "%s", zOut); 35382 sqlite3_snprintf(pVfs->mxPathname, zFull, "%s", zOut); 34424 free(zOut); | 35383 sqlite3_free(zOut); 34425 return SQLITE_OK; | 35384 return SQLITE_OK; 34426 }else{ | 35385 }else{ 34427 return SQLITE_NOMEM; | 35386 return SQLITE_IOERR_NOMEM; 34428 } | 35387 } 34429 #endif | 35388 #endif 34430 } < 34431 < 34432 /* < 34433 ** Get the sector size of the device used to store < 34434 ** file. < 34435 */ < 34436 static int getSectorSize( < 34437 sqlite3_vfs *pVfs, < 34438 const char *zRelative /* UTF-8 file name */ < 34439 ){ < 34440 DWORD bytesPerSector = SQLITE_DEFAULT_SECTOR_SIZE; < 34441 /* GetDiskFreeSpace is not supported under WINCE */ < 34442 #if SQLITE_OS_WINCE < 34443 UNUSED_PARAMETER(pVfs); < 34444 UNUSED_PARAMETER(zRelative); < 34445 #else < 34446 char zFullpath[MAX_PATH+1]; < 34447 int rc; < 34448 DWORD dwRet = 0; < 34449 DWORD dwDummy; < 34450 < 34451 /* < 34452 ** We need to get the full path name of the file < 34453 ** to get the drive letter to look up the sector < 34454 ** size. < 34455 */ < 34456 SimulateIOErrorBenign(1); < 34457 rc = winFullPathname(pVfs, zRelative, MAX_PATH, zFullpath); < 34458 SimulateIOErrorBenign(0); < 34459 if( rc == SQLITE_OK ) < 34460 { < 34461 void *zConverted = convertUtf8Filename(zFullpath); < 34462 if( zConverted ){ < 34463 if( isNT() ){ < 34464 /* trim path to just drive reference */ < 34465 WCHAR *p = zConverted; < 34466 for(;*p;p++){ < 34467 if( *p == '\\' ){ < 34468 *p = '\0'; < 34469 break; < 34470 } < 34471 } < 34472 dwRet = GetDiskFreeSpaceW((WCHAR*)zConverted, < 34473 &dwDummy, < 34474 &bytesPerSector, < 34475 &dwDummy, < 34476 &dwDummy); < 34477 }else{ < 34478 /* trim path to just drive reference */ < 34479 char *p = (char *)zConverted; < 34480 for(;*p;p++){ < 34481 if( *p == '\\' ){ < 34482 *p = '\0'; < 34483 break; < 34484 } < 34485 } < 34486 dwRet = GetDiskFreeSpaceA((char*)zConverted, < 34487 &dwDummy, < 34488 &bytesPerSector, < 34489 &dwDummy, < 34490 &dwDummy); < 34491 } < 34492 free(zConverted); < 34493 } < 34494 if( !dwRet ){ < 34495 bytesPerSector = SQLITE_DEFAULT_SECTOR_SIZE; < 34496 } < 34497 } < 34498 #endif < 34499 return (int) bytesPerSector; < 34500 } 35389 } 34501 35390 34502 #ifndef SQLITE_OMIT_LOAD_EXTENSION 35391 #ifndef SQLITE_OMIT_LOAD_EXTENSION 34503 /* 35392 /* 34504 ** Interfaces for opening a shared library, finding entry points 35393 ** Interfaces for opening a shared library, finding entry points 34505 ** within the shared library, and closing the shared library. 35394 ** within the shared library, and closing the shared library. 34506 */ 35395 */ ................................................................................................................................................................................ 34512 HANDLE h; 35401 HANDLE h; 34513 void *zConverted = convertUtf8Filename(zFilename); 35402 void *zConverted = convertUtf8Filename(zFilename); 34514 UNUSED_PARAMETER(pVfs); 35403 UNUSED_PARAMETER(pVfs); 34515 if( zConverted==0 ){ 35404 if( zConverted==0 ){ 34516 return 0; 35405 return 0; 34517 } 35406 } 34518 if( isNT() ){ 35407 if( isNT() ){ 34519 h = LoadLibraryW((WCHAR*)zConverted); | 35408 h = osLoadLibraryW((LPCWSTR)zConverted); 34520 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 35409 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 34521 ** Since the ASCII version of these Windows API do not exist for WINCE, | 35410 ** Since the ANSI version of these Windows API do not exist for WINCE, 34522 ** it's important to not reference them for WINCE builds. 35411 ** it's important to not reference them for WINCE builds. 34523 */ 35412 */ 34524 #if SQLITE_OS_WINCE==0 35413 #if SQLITE_OS_WINCE==0 34525 }else{ 35414 }else{ 34526 h = LoadLibraryA((char*)zConverted); | 35415 h = osLoadLibraryA((char*)zConverted); 34527 #endif 35416 #endif 34528 } 35417 } 34529 free(zConverted); | 35418 sqlite3_free(zConverted); 34530 return (void*)h; 35419 return (void*)h; 34531 } 35420 } 34532 static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){ 35421 static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){ 34533 UNUSED_PARAMETER(pVfs); 35422 UNUSED_PARAMETER(pVfs); 34534 getLastErrorMsg(nBuf, zBufOut); | 35423 getLastErrorMsg(osGetLastError(), nBuf, zBufOut); 34535 } 35424 } 34536 static void (*winDlSym(sqlite3_vfs *pVfs, void *pHandle, const char *zSymbol))(v 35425 static void (*winDlSym(sqlite3_vfs *pVfs, void *pHandle, const char *zSymbol))(v 34537 UNUSED_PARAMETER(pVfs); 35426 UNUSED_PARAMETER(pVfs); 34538 #if SQLITE_OS_WINCE < 34539 /* The GetProcAddressA() routine is only available on wince. */ < 34540 return (void(*)(void))GetProcAddressA((HANDLE)pHandle, zSymbol); | 35427 return (void(*)(void))osGetProcAddressA((HANDLE)pHandle, zSymbol); 34541 #else < 34542 /* All other windows platforms expect GetProcAddress() to take < 34543 ** an Ansi string regardless of the _UNICODE setting */ < 34544 return (void(*)(void))GetProcAddress((HANDLE)pHandle, zSymbol); < 34545 #endif < 34546 } 35428 } 34547 static void winDlClose(sqlite3_vfs *pVfs, void *pHandle){ 35429 static void winDlClose(sqlite3_vfs *pVfs, void *pHandle){ 34548 UNUSED_PARAMETER(pVfs); 35430 UNUSED_PARAMETER(pVfs); 34549 FreeLibrary((HANDLE)pHandle); | 35431 osFreeLibrary((HANDLE)pHandle); 34550 } 35432 } 34551 #else /* if SQLITE_OMIT_LOAD_EXTENSION is defined: */ 35433 #else /* if SQLITE_OMIT_LOAD_EXTENSION is defined: */ 34552 #define winDlOpen 0 35434 #define winDlOpen 0 34553 #define winDlError 0 35435 #define winDlError 0 34554 #define winDlSym 0 35436 #define winDlSym 0 34555 #define winDlClose 0 35437 #define winDlClose 0 34556 #endif 35438 #endif ................................................................................................................................................................................ 34564 UNUSED_PARAMETER(pVfs); 35446 UNUSED_PARAMETER(pVfs); 34565 #if defined(SQLITE_TEST) 35447 #if defined(SQLITE_TEST) 34566 n = nBuf; 35448 n = nBuf; 34567 memset(zBuf, 0, nBuf); 35449 memset(zBuf, 0, nBuf); 34568 #else 35450 #else 34569 if( sizeof(SYSTEMTIME)<=nBuf-n ){ 35451 if( sizeof(SYSTEMTIME)<=nBuf-n ){ 34570 SYSTEMTIME x; 35452 SYSTEMTIME x; 34571 GetSystemTime(&x); | 35453 osGetSystemTime(&x); 34572 memcpy(&zBuf[n], &x, sizeof(x)); 35454 memcpy(&zBuf[n], &x, sizeof(x)); 34573 n += sizeof(x); 35455 n += sizeof(x); 34574 } 35456 } 34575 if( sizeof(DWORD)<=nBuf-n ){ 35457 if( sizeof(DWORD)<=nBuf-n ){ 34576 DWORD pid = GetCurrentProcessId(); | 35458 DWORD pid = osGetCurrentProcessId(); 34577 memcpy(&zBuf[n], &pid, sizeof(pid)); 35459 memcpy(&zBuf[n], &pid, sizeof(pid)); 34578 n += sizeof(pid); 35460 n += sizeof(pid); 34579 } 35461 } 34580 if( sizeof(DWORD)<=nBuf-n ){ 35462 if( sizeof(DWORD)<=nBuf-n ){ 34581 DWORD cnt = GetTickCount(); | 35463 DWORD cnt = osGetTickCount(); 34582 memcpy(&zBuf[n], &cnt, sizeof(cnt)); 35464 memcpy(&zBuf[n], &cnt, sizeof(cnt)); 34583 n += sizeof(cnt); 35465 n += sizeof(cnt); 34584 } 35466 } 34585 if( sizeof(LARGE_INTEGER)<=nBuf-n ){ 35467 if( sizeof(LARGE_INTEGER)<=nBuf-n ){ 34586 LARGE_INTEGER i; 35468 LARGE_INTEGER i; 34587 QueryPerformanceCounter(&i); | 35469 osQueryPerformanceCounter(&i); 34588 memcpy(&zBuf[n], &i, sizeof(i)); 35470 memcpy(&zBuf[n], &i, sizeof(i)); 34589 n += sizeof(i); 35471 n += sizeof(i); 34590 } 35472 } 34591 #endif 35473 #endif 34592 return n; 35474 return n; 34593 } 35475 } 34594 35476 34595 35477 34596 /* 35478 /* 34597 ** Sleep for a little while. Return the amount of time slept. 35479 ** Sleep for a little while. Return the amount of time slept. 34598 */ 35480 */ 34599 static int winSleep(sqlite3_vfs *pVfs, int microsec){ 35481 static int winSleep(sqlite3_vfs *pVfs, int microsec){ 34600 Sleep((microsec+999)/1000); | 35482 osSleep((microsec+999)/1000); 34601 UNUSED_PARAMETER(pVfs); 35483 UNUSED_PARAMETER(pVfs); 34602 return ((microsec+999)/1000)*1000; 35484 return ((microsec+999)/1000)*1000; 34603 } 35485 } 34604 35486 34605 /* 35487 /* 34606 ** The following variable, if set to a non-zero value, is interpreted as 35488 ** The following variable, if set to a non-zero value, is interpreted as 34607 ** the number of seconds since 1970 and is used to set the result of 35489 ** the number of seconds since 1970 and is used to set the result of ................................................................................................................................................................................ 34632 #endif 35514 #endif 34633 /* 2^32 - to avoid use of LL and warnings in gcc */ 35515 /* 2^32 - to avoid use of LL and warnings in gcc */ 34634 static const sqlite3_int64 max32BitValue = 35516 static const sqlite3_int64 max32BitValue = 34635 (sqlite3_int64)2000000000 + (sqlite3_int64)2000000000 + (sqlite3_int64)294 35517 (sqlite3_int64)2000000000 + (sqlite3_int64)2000000000 + (sqlite3_int64)294 34636 35518 34637 #if SQLITE_OS_WINCE 35519 #if SQLITE_OS_WINCE 34638 SYSTEMTIME time; 35520 SYSTEMTIME time; 34639 GetSystemTime(&time); | 35521 osGetSystemTime(&time); 34640 /* if SystemTimeToFileTime() fails, it returns zero. */ 35522 /* if SystemTimeToFileTime() fails, it returns zero. */ 34641 if (!SystemTimeToFileTime(&time,&ft)){ | 35523 if (!osSystemTimeToFileTime(&time,&ft)){ 34642 return SQLITE_ERROR; 35524 return SQLITE_ERROR; 34643 } 35525 } 34644 #else 35526 #else 34645 GetSystemTimeAsFileTime( &ft ); | 35527 osGetSystemTimeAsFileTime( &ft ); 34646 #endif 35528 #endif 34647 35529 34648 *piNow = winFiletimeEpoch + 35530 *piNow = winFiletimeEpoch + 34649 ((((sqlite3_int64)ft.dwHighDateTime)*max32BitValue) + 35531 ((((sqlite3_int64)ft.dwHighDateTime)*max32BitValue) + 34650 (sqlite3_int64)ft.dwLowDateTime)/(sqlite3_int64)10000; 35532 (sqlite3_int64)ft.dwLowDateTime)/(sqlite3_int64)10000; 34651 35533 34652 #ifdef SQLITE_TEST 35534 #ifdef SQLITE_TEST ................................................................................................................................................................................ 34671 *prNow = i/86400000.0; 35553 *prNow = i/86400000.0; 34672 } 35554 } 34673 return rc; 35555 return rc; 34674 } 35556 } 34675 35557 34676 /* 35558 /* 34677 ** The idea is that this function works like a combination of 35559 ** The idea is that this function works like a combination of 34678 ** GetLastError() and FormatMessage() on windows (or errno and | 35560 ** GetLastError() and FormatMessage() on Windows (or errno and 34679 ** strerror_r() on unix). After an error is returned by an OS | 35561 ** strerror_r() on Unix). After an error is returned by an OS 34680 ** function, SQLite calls this function with zBuf pointing to 35562 ** function, SQLite calls this function with zBuf pointing to 34681 ** a buffer of nBuf bytes. The OS layer should populate the 35563 ** a buffer of nBuf bytes. The OS layer should populate the 34682 ** buffer with a nul-terminated UTF-8 encoded error message 35564 ** buffer with a nul-terminated UTF-8 encoded error message 34683 ** describing the last IO error to have occurred within the calling 35565 ** describing the last IO error to have occurred within the calling 34684 ** thread. 35566 ** thread. 34685 ** 35567 ** 34686 ** If the error message is too large for the supplied buffer, 35568 ** If the error message is too large for the supplied buffer, ................................................................................................................................................................................ 34701 ** 35583 ** 34702 ** However if an error message is supplied, it will be incorporated 35584 ** However if an error message is supplied, it will be incorporated 34703 ** by sqlite into the error message available to the user using 35585 ** by sqlite into the error message available to the user using 34704 ** sqlite3_errmsg(), possibly making IO errors easier to debug. 35586 ** sqlite3_errmsg(), possibly making IO errors easier to debug. 34705 */ 35587 */ 34706 static int winGetLastError(sqlite3_vfs *pVfs, int nBuf, char *zBuf){ 35588 static int winGetLastError(sqlite3_vfs *pVfs, int nBuf, char *zBuf){ 34707 UNUSED_PARAMETER(pVfs); 35589 UNUSED_PARAMETER(pVfs); 34708 return getLastErrorMsg(nBuf, zBuf); | 35590 return getLastErrorMsg(osGetLastError(), nBuf, zBuf); 34709 } 35591 } 34710 < 34711 < 34712 35592 34713 /* 35593 /* 34714 ** Initialize and deinitialize the operating system interface. 35594 ** Initialize and deinitialize the operating system interface. 34715 */ 35595 */ 34716 SQLITE_API int sqlite3_os_init(void){ 35596 SQLITE_API int sqlite3_os_init(void){ 34717 static sqlite3_vfs winVfs = { 35597 static sqlite3_vfs winVfs = { 34718 3, /* iVersion */ 35598 3, /* iVersion */ ................................................................................................................................................................................ 34730 winDlSym, /* xDlSym */ 35610 winDlSym, /* xDlSym */ 34731 winDlClose, /* xDlClose */ 35611 winDlClose, /* xDlClose */ 34732 winRandomness, /* xRandomness */ 35612 winRandomness, /* xRandomness */ 34733 winSleep, /* xSleep */ 35613 winSleep, /* xSleep */ 34734 winCurrentTime, /* xCurrentTime */ 35614 winCurrentTime, /* xCurrentTime */ 34735 winGetLastError, /* xGetLastError */ 35615 winGetLastError, /* xGetLastError */ 34736 winCurrentTimeInt64, /* xCurrentTimeInt64 */ 35616 winCurrentTimeInt64, /* xCurrentTimeInt64 */ 34737 0, /* xSetSystemCall */ | 35617 winSetSystemCall, /* xSetSystemCall */ 34738 0, /* xGetSystemCall */ | 35618 winGetSystemCall, /* xGetSystemCall */ 34739 0, /* xNextSystemCall */ | 35619 winNextSystemCall, /* xNextSystemCall */ 34740 }; 35620 }; > 35621 > 35622 /* Double-check that the aSyscall[] array has been constructed > 35623 ** correctly. See ticket [bb3a86e890c8e96ab] */ > 35624 assert( ArraySize(aSyscall)==60 ); 34741 35625 34742 #ifndef SQLITE_OMIT_WAL 35626 #ifndef SQLITE_OMIT_WAL 34743 /* get memory map allocation granularity */ 35627 /* get memory map allocation granularity */ 34744 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO)); 35628 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO)); 34745 GetSystemInfo(&winSysInfo); | 35629 osGetSystemInfo(&winSysInfo); 34746 assert(winSysInfo.dwAllocationGranularity > 0); 35630 assert(winSysInfo.dwAllocationGranularity > 0); 34747 #endif 35631 #endif 34748 35632 34749 sqlite3_vfs_register(&winVfs, 1); 35633 sqlite3_vfs_register(&winVfs, 1); 34750 return SQLITE_OK; 35634 return SQLITE_OK; 34751 } 35635 } > 35636 34752 SQLITE_API int sqlite3_os_end(void){ 35637 SQLITE_API int sqlite3_os_end(void){ 34753 return SQLITE_OK; 35638 return SQLITE_OK; 34754 } 35639 } 34755 35640 34756 #endif /* SQLITE_OS_WIN */ 35641 #endif /* SQLITE_OS_WIN */ 34757 35642 34758 /************** End of os_win.c **********************************************/ 35643 /************** End of os_win.c **********************************************/ ................................................................................................................................................................................ 35184 /* 36069 /* 35185 ** A complete page cache is an instance of this structure. 36070 ** A complete page cache is an instance of this structure. 35186 */ 36071 */ 35187 struct PCache { 36072 struct PCache { 35188 PgHdr *pDirty, *pDirtyTail; /* List of dirty pages in LRU order */ 36073 PgHdr *pDirty, *pDirtyTail; /* List of dirty pages in LRU order */ 35189 PgHdr *pSynced; /* Last synced page in dirty page list */ 36074 PgHdr *pSynced; /* Last synced page in dirty page list */ 35190 int nRef; /* Number of referenced pages */ 36075 int nRef; /* Number of referenced pages */ 35191 int nMax; /* Configured cache size */ | 36076 int szCache; /* Configured cache size */ 35192 int szPage; /* Size of every page in this cache */ 36077 int szPage; /* Size of every page in this cache */ 35193 int szExtra; /* Size of extra space for each page */ 36078 int szExtra; /* Size of extra space for each page */ 35194 int bPurgeable; /* True if pages are on backing store */ 36079 int bPurgeable; /* True if pages are on backing store */ 35195 int (*xStress)(void*,PgHdr*); /* Call to try make a page clean */ 36080 int (*xStress)(void*,PgHdr*); /* Call to try make a page clean */ 35196 void *pStress; /* Argument to xStress */ 36081 void *pStress; /* Argument to xStress */ 35197 sqlite3_pcache *pCache; /* Pluggable cache module */ 36082 sqlite3_pcache *pCache; /* Pluggable cache module */ 35198 PgHdr *pPage1; /* Reference to page 1 */ 36083 PgHdr *pPage1; /* Reference to page 1 */ ................................................................................................................................................................................ 35295 */ 36180 */ 35296 static void pcacheUnpin(PgHdr *p){ 36181 static void pcacheUnpin(PgHdr *p){ 35297 PCache *pCache = p->pCache; 36182 PCache *pCache = p->pCache; 35298 if( pCache->bPurgeable ){ 36183 if( pCache->bPurgeable ){ 35299 if( p->pgno==1 ){ 36184 if( p->pgno==1 ){ 35300 pCache->pPage1 = 0; 36185 pCache->pPage1 = 0; 35301 } 36186 } 35302 sqlite3GlobalConfig.pcache.xUnpin(pCache->pCache, p, 0); | 36187 sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, p->pPage, 0); 35303 } 36188 } 35304 } 36189 } 35305 36190 35306 /*************************************************** General Interfaces ****** 36191 /*************************************************** General Interfaces ****** 35307 ** 36192 ** 35308 ** Initialize and shutdown the page cache subsystem. Neither of these 36193 ** Initialize and shutdown the page cache subsystem. Neither of these 35309 ** functions are threadsafe. 36194 ** functions are threadsafe. 35310 */ 36195 */ 35311 SQLITE_PRIVATE int sqlite3PcacheInitialize(void){ 36196 SQLITE_PRIVATE int sqlite3PcacheInitialize(void){ 35312 if( sqlite3GlobalConfig.pcache.xInit==0 ){ | 36197 if( sqlite3GlobalConfig.pcache2.xInit==0 ){ 35313 /* IMPLEMENTATION-OF: R-26801-64137 If the xInit() method is NULL, then the 36198 /* IMPLEMENTATION-OF: R-26801-64137 If the xInit() method is NULL, then the 35314 ** built-in default page cache is used instead of the application defined 36199 ** built-in default page cache is used instead of the application defined 35315 ** page cache. */ 36200 ** page cache. */ 35316 sqlite3PCacheSetDefault(); 36201 sqlite3PCacheSetDefault(); 35317 } 36202 } 35318 return sqlite3GlobalConfig.pcache.xInit(sqlite3GlobalConfig.pcache.pArg); | 36203 return sqlite3GlobalConfig.pcache2.xInit(sqlite3GlobalConfig.pcache2.pArg); 35319 } 36204 } 35320 SQLITE_PRIVATE void sqlite3PcacheShutdown(void){ 36205 SQLITE_PRIVATE void sqlite3PcacheShutdown(void){ 35321 if( sqlite3GlobalConfig.pcache.xShutdown ){ | 36206 if( sqlite3GlobalConfig.pcache2.xShutdown ){ 35322 /* IMPLEMENTATION-OF: R-26000-56589 The xShutdown() method may be NULL. */ 36207 /* IMPLEMENTATION-OF: R-26000-56589 The xShutdown() method may be NULL. */ 35323 sqlite3GlobalConfig.pcache.xShutdown(sqlite3GlobalConfig.pcache.pArg); | 36208 sqlite3GlobalConfig.pcache2.xShutdown(sqlite3GlobalConfig.pcache2.pArg); 35324 } 36209 } 35325 } 36210 } 35326 36211 35327 /* 36212 /* 35328 ** Return the size in bytes of a PCache object. 36213 ** Return the size in bytes of a PCache object. 35329 */ 36214 */ 35330 SQLITE_PRIVATE int sqlite3PcacheSize(void){ return sizeof(PCache); } 36215 SQLITE_PRIVATE int sqlite3PcacheSize(void){ return sizeof(PCache); } ................................................................................................................................................................................ 35345 ){ 36230 ){ 35346 memset(p, 0, sizeof(PCache)); 36231 memset(p, 0, sizeof(PCache)); 35347 p->szPage = szPage; 36232 p->szPage = szPage; 35348 p->szExtra = szExtra; 36233 p->szExtra = szExtra; 35349 p->bPurgeable = bPurgeable; 36234 p->bPurgeable = bPurgeable; 35350 p->xStress = xStress; 36235 p->xStress = xStress; 35351 p->pStress = pStress; 36236 p->pStress = pStress; 35352 p->nMax = 100; | 36237 p->szCache = 100; 35353 } 36238 } 35354 36239 35355 /* 36240 /* 35356 ** Change the page size for PCache object. The caller must ensure that there 36241 ** Change the page size for PCache object. The caller must ensure that there 35357 ** are no outstanding page references when this function is called. 36242 ** are no outstanding page references when this function is called. 35358 */ 36243 */ 35359 SQLITE_PRIVATE void sqlite3PcacheSetPageSize(PCache *pCache, int szPage){ 36244 SQLITE_PRIVATE void sqlite3PcacheSetPageSize(PCache *pCache, int szPage){ 35360 assert( pCache->nRef==0 && pCache->pDirty==0 ); 36245 assert( pCache->nRef==0 && pCache->pDirty==0 ); 35361 if( pCache->pCache ){ 36246 if( pCache->pCache ){ 35362 sqlite3GlobalConfig.pcache.xDestroy(pCache->pCache); | 36247 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache); 35363 pCache->pCache = 0; 36248 pCache->pCache = 0; 35364 pCache->pPage1 = 0; 36249 pCache->pPage1 = 0; 35365 } 36250 } 35366 pCache->szPage = szPage; 36251 pCache->szPage = szPage; 35367 } 36252 } > 36253 > 36254 /* > 36255 ** Compute the number of pages of cache requested. > 36256 */ > 36257 static int numberOfCachePages(PCache *p){ > 36258 if( p->szCache>=0 ){ > 36259 return p->szCache; > 36260 }else{ > 36261 return (int)((-1024*(i64)p->szCache)/(p->szPage+p->szExtra)); > 36262 } > 36263 } 35368 36264 35369 /* 36265 /* 35370 ** Try to obtain a page from the cache. 36266 ** Try to obtain a page from the cache. 35371 */ 36267 */ 35372 SQLITE_PRIVATE int sqlite3PcacheFetch( 36268 SQLITE_PRIVATE int sqlite3PcacheFetch( 35373 PCache *pCache, /* Obtain the page from this cache */ 36269 PCache *pCache, /* Obtain the page from this cache */ 35374 Pgno pgno, /* Page number to obtain */ 36270 Pgno pgno, /* Page number to obtain */ 35375 int createFlag, /* If true, create page if it does not exist already */ 36271 int createFlag, /* If true, create page if it does not exist already */ 35376 PgHdr **ppPage /* Write the page here */ 36272 PgHdr **ppPage /* Write the page here */ 35377 ){ 36273 ){ > 36274 sqlite3_pcache_page *pPage = 0; 35378 PgHdr *pPage = 0; | 36275 PgHdr *pPgHdr = 0; 35379 int eCreate; 36276 int eCreate; 35380 36277 35381 assert( pCache!=0 ); 36278 assert( pCache!=0 ); 35382 assert( createFlag==1 || createFlag==0 ); 36279 assert( createFlag==1 || createFlag==0 ); 35383 assert( pgno>0 ); 36280 assert( pgno>0 ); 35384 36281 35385 /* If the pluggable cache (sqlite3_pcache*) has not been allocated, 36282 /* If the pluggable cache (sqlite3_pcache*) has not been allocated, 35386 ** allocate it now. 36283 ** allocate it now. 35387 */ 36284 */ 35388 if( !pCache->pCache && createFlag ){ 36285 if( !pCache->pCache && createFlag ){ 35389 sqlite3_pcache *p; 36286 sqlite3_pcache *p; 35390 int nByte; | 36287