Check-in [990c4d4437]
Not logged in

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

Overview
SHA1 Hash:990c4d443775196da41d857c9d43d51eaf0fc387
Date: 2012-06-07 13:30:26
User: drh
Comment:Update the built-in SQLite to the first 3.7.13 beta.
Tags And Properties
Changes

Changes to src/shell.c

2180 new_colv[1] = 0; 2180 new_colv[1] = 0; 2181 callback(&data, 1, new_argv, new_colv); 2181 callback(&data, 1, new_argv, new_colv); 2182 rc = SQLITE_OK; 2182 rc = SQLITE_OK; 2183 }else{ 2183 }else{ 2184 zShellStatic = azArg[1]; 2184 zShellStatic = azArg[1]; 2185 rc = sqlite3_exec(p->db, 2185 rc = sqlite3_exec(p->db, 2186 "SELECT sql FROM " 2186 "SELECT sql FROM " 2187 " (SELECT sql sql, type type, tbl_name tbl_name, name name" | 2187 " (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x" 2188 " FROM sqlite_master UNION ALL" 2188 " FROM sqlite_master UNION ALL" 2189 " SELECT sql, type, tbl_name, name FROM sqlite_temp_master) " | 2189 " SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_master) " 2190 "WHERE lower(tbl_name) LIKE shellstatic()" 2190 "WHERE lower(tbl_name) LIKE shellstatic()" 2191 " AND type!='meta' AND sql NOTNULL " 2191 " AND type!='meta' AND sql NOTNULL " 2192 "ORDER BY substr(type,2,1), name", | 2192 "ORDER BY substr(type,2,1), " > 2193 " CASE type WHEN 'view' THEN rowid ELSE name END", 2193 callback, &data, &zErrMsg); 2194 callback, &data, &zErrMsg); 2194 zShellStatic = 0; 2195 zShellStatic = 0; 2195 } 2196 } 2196 }else{ 2197 }else{ 2197 rc = sqlite3_exec(p->db, 2198 rc = sqlite3_exec(p->db, 2198 "SELECT sql FROM " 2199 "SELECT sql FROM " 2199 " (SELECT sql sql, type type, tbl_name tbl_name, name name" | 2200 " (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x" 2200 " FROM sqlite_master UNION ALL" 2201 " FROM sqlite_master UNION ALL" 2201 " SELECT sql, type, tbl_name, name FROM sqlite_temp_master) " | 2202 " SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_master) " 2202 "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%'" 2203 "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%'" 2203 "ORDER BY substr(type,2,1), name", | 2204 "ORDER BY substr(type,2,1)," > 2205 " CASE type WHEN 'view' THEN rowid ELSE name END", 2204 callback, &data, &zErrMsg 2206 callback, &data, &zErrMsg 2205 ); 2207 ); 2206 } 2208 } 2207 if( zErrMsg ){ 2209 if( zErrMsg ){ 2208 fprintf(stderr,"Error: %s\n", zErrMsg); 2210 fprintf(stderr,"Error: %s\n", zErrMsg); 2209 sqlite3_free(zErrMsg); 2211 sqlite3_free(zErrMsg); 2210 rc = 1; 2212 rc = 1;

Changes to src/sqlite3.c

1 /****************************************************************************** 1 /****************************************************************************** 2 ** This file is an amalgamation of many separate C source files from SQLite 2 ** This file is an amalgamation of many separate C source files from SQLite 3 ** version 3.7.12. By combining all the individual C code files into this | 3 ** version 3.7.13. By combining all the individual C code files into this 4 ** single large file, the entire code can be compiled as a single translation 4 ** single large file, the entire code can be compiled as a single translation 5 ** unit. This allows many compilers to do optimizations that would not be 5 ** unit. This allows many compilers to do optimizations that would not be 6 ** possible if the files were compiled separately. Performance improvements 6 ** possible if the files were compiled separately. Performance improvements 7 ** of 5% or more are commonly seen when SQLite is compiled as a single 7 ** of 5% or more are commonly seen when SQLite is compiled as a single 8 ** translation unit. 8 ** translation unit. 9 ** 9 ** 10 ** This file is all you need to compile SQLite. To use SQLite in other 10 ** This file is all you need to compile SQLite. To use SQLite in other ................................................................................................................................................................................ 439 ** The TCL headers are only needed when compiling the TCL bindings. 439 ** The TCL headers are only needed when compiling the TCL bindings. 440 */ 440 */ 441 #if defined(SQLITE_TCL) || defined(TCLSH) 441 #if defined(SQLITE_TCL) || defined(TCLSH) 442 # include <tcl.h> 442 # include <tcl.h> 443 #endif 443 #endif 444 444 445 /* 445 /* 446 ** Many people are failing to set -DNDEBUG=1 when compiling SQLite. | 446 ** NDEBUG and SQLITE_DEBUG are opposites. It should always be true that > 447 ** defined(NDEBUG)==!defined(SQLITE_DEBUG). If this is not currently true, > 448 ** make it true by defining or undefining NDEBUG. > 449 ** 447 ** Setting NDEBUG makes the code smaller and run faster. So the following | 450 ** Setting NDEBUG makes the code smaller and run faster by disabling the 448 ** lines are added to automatically set NDEBUG unless the -DSQLITE_DEBUG=1 < > 451 ** number assert() statements in the code. So we want the default action > 452 ** to be for NDEBUG to be set and NDEBUG to be undefined only if SQLITE_DEBUG 449 ** option is set. Thus NDEBUG becomes an opt-in rather than an opt-out | 453 ** is set. Thus NDEBUG becomes an opt-in rather than an opt-out 450 ** feature. 454 ** feature. 451 */ 455 */ 452 #if !defined(NDEBUG) && !defined(SQLITE_DEBUG) 456 #if !defined(NDEBUG) && !defined(SQLITE_DEBUG) 453 # define NDEBUG 1 457 # define NDEBUG 1 > 458 #endif > 459 #if defined(NDEBUG) && defined(SQLITE_DEBUG) > 460 # undef NDEBUG 454 #endif 461 #endif 455 462 456 /* 463 /* 457 ** The testcase() macro is used to aid in coverage testing. When 464 ** The testcase() macro is used to aid in coverage testing. When 458 ** doing coverage testing, the condition inside the argument to 465 ** doing coverage testing, the condition inside the argument to 459 ** testcase() must be evaluated both true and false in order to 466 ** testcase() must be evaluated both true and false in order to 460 ** get full branch coverage. The testcase() macro is inserted 467 ** get full branch coverage. The testcase() macro is inserted ................................................................................................................................................................................ 653 ** string contains the date and time of the check-in (UTC) and an SHA1 660 ** string contains the date and time of the check-in (UTC) and an SHA1 654 ** hash of the entire source tree. 661 ** hash of the entire source tree. 655 ** 662 ** 656 ** See also: [sqlite3_libversion()], 663 ** See also: [sqlite3_libversion()], 657 ** [sqlite3_libversion_number()], [sqlite3_sourceid()], 664 ** [sqlite3_libversion_number()], [sqlite3_sourceid()], 658 ** [sqlite_version()] and [sqlite_source_id()]. 665 ** [sqlite_version()] and [sqlite_source_id()]. 659 */ 666 */ 660 #define SQLITE_VERSION "3.7.12" | 667 #define SQLITE_VERSION "3.7.13" 661 #define SQLITE_VERSION_NUMBER 3007012 | 668 #define SQLITE_VERSION_NUMBER 3007013 662 #define SQLITE_SOURCE_ID "2012-05-12 18:29:53 e536ac041815b118c461ceee798f9 | 669 #define SQLITE_SOURCE_ID "2012-06-07 07:24:04 506008f000ba4af0b35da023b8c52 663 670 664 /* 671 /* 665 ** CAPI3REF: Run-Time Library Version Numbers 672 ** CAPI3REF: Run-Time Library Version Numbers 666 ** KEYWORDS: sqlite3_version, sqlite3_sourceid 673 ** KEYWORDS: sqlite3_version, sqlite3_sourceid 667 ** 674 ** 668 ** These interfaces provide the same information as the [SQLITE_VERSION], 675 ** These interfaces provide the same information as the [SQLITE_VERSION], 669 ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros 676 ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros ................................................................................................................................................................................ 1024 #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */ 1031 #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */ 1025 #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */ 1032 #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */ 1026 #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */ 1033 #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */ 1027 #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */ 1034 #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */ 1028 #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */ 1035 #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */ 1029 #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */ 1036 #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */ 1030 #define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */ 1037 #define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */ > 1038 #define SQLITE_OPEN_MEMORY 0x00000080 /* Ok for sqlite3_open_v2() */ 1031 #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */ 1039 #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */ 1032 #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */ 1040 #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */ 1033 #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */ 1041 #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */ 1034 #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */ 1042 #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */ 1035 #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */ 1043 #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */ 1036 #define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */ 1044 #define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */ 1037 #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */ 1045 #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */ ................................................................................................................................................................................ 1318 ** integer is the delay. If either integer is negative, then the setting 1326 ** integer is the delay. If either integer is negative, then the setting 1319 ** is not changed but instead the prior value of that setting is written 1327 ** is not changed but instead the prior value of that setting is written 1320 ** into the array entry, allowing the current retry settings to be 1328 ** into the array entry, allowing the current retry settings to be 1321 ** interrogated. The zDbName parameter is ignored. 1329 ** interrogated. The zDbName parameter is ignored. 1322 ** 1330 ** 1323 ** <li>[[SQLITE_FCNTL_PERSIST_WAL]] 1331 ** <li>[[SQLITE_FCNTL_PERSIST_WAL]] 1324 ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the 1332 ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the 1325 ** persistent [WAL | Write AHead Log] setting. By default, the auxiliary | 1333 ** persistent [WAL | Write Ahead Log] setting. By default, the auxiliary 1326 ** write ahead log and shared memory files used for transaction control 1334 ** write ahead log and shared memory files used for transaction control 1327 ** are automatically deleted when the latest connection to the database 1335 ** are automatically deleted when the latest connection to the database 1328 ** closes. Setting persistent WAL mode causes those files to persist after 1336 ** closes. Setting persistent WAL mode causes those files to persist after 1329 ** close. Persisting the files is useful when other processes that do not 1337 ** close. Persisting the files is useful when other processes that do not 1330 ** have write permission on the directory containing the database file want 1338 ** have write permission on the directory containing the database file want 1331 ** to read the database file, as the WAL and shared memory files must exist 1339 ** to read the database file, as the WAL and shared memory files must exist 1332 ** in order for the database to be readable. The fourth parameter to 1340 ** in order for the database to be readable. The fourth parameter to ................................................................................................................................................................................ 2715 ** option is used. 2723 ** option is used. 2716 ** 2724 ** 2717 ** In SQLite version 3.5.0 and 3.5.1, it was possible to define 2725 ** In SQLite version 3.5.0 and 3.5.1, it was possible to define 2718 ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in 2726 ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in 2719 ** implementation of these routines to be omitted. That capability 2727 ** implementation of these routines to be omitted. That capability 2720 ** is no longer provided. Only built-in memory allocators can be used. 2728 ** is no longer provided. Only built-in memory allocators can be used. 2721 ** 2729 ** 2722 ** The Windows OS interface layer calls | 2730 ** Prior to SQLite version 3.7.10, the Windows OS interface layer called 2723 ** the system malloc() and free() directly when converting 2731 ** the system malloc() and free() directly when converting 2724 ** filenames between the UTF-8 encoding used by SQLite 2732 ** filenames between the UTF-8 encoding used by SQLite 2725 ** and whatever filename encoding is used by the particular Windows 2733 ** and whatever filename encoding is used by the particular Windows 2726 ** installation. Memory allocation errors are detected, but | 2734 ** installation. Memory allocation errors were detected, but 2727 ** they are reported back as [SQLITE_CANTOPEN] or | 2735 ** they were reported back as [SQLITE_CANTOPEN] or 2728 ** [SQLITE_IOERR] rather than [SQLITE_NOMEM]. 2736 ** [SQLITE_IOERR] rather than [SQLITE_NOMEM]. 2729 ** 2737 ** 2730 ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()] 2738 ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()] 2731 ** must be either NULL or else pointers obtained from a prior 2739 ** must be either NULL or else pointers obtained from a prior 2732 ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have 2740 ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have 2733 ** not yet been released. 2741 ** not yet been released. 2734 ** 2742 ** ................................................................................................................................................................................ 3121 ** a VFS object that provides the operating system interface that should 3129 ** a VFS object that provides the operating system interface that should 3122 ** be used to access the database file on disk. ^If this option is set to 3130 ** be used to access the database file on disk. ^If this option is set to 3123 ** an empty string the default VFS object is used. ^Specifying an unknown 3131 ** an empty string the default VFS object is used. ^Specifying an unknown 3124 ** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is 3132 ** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is 3125 ** present, then the VFS specified by the option takes precedence over 3133 ** present, then the VFS specified by the option takes precedence over 3126 ** the value passed as the fourth parameter to sqlite3_open_v2(). 3134 ** the value passed as the fourth parameter to sqlite3_open_v2(). 3127 ** 3135 ** 3128 ** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw" or | 3136 ** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw", 3129 ** "rwc". Attempting to set it to any other value is an error)^. | 3137 ** "rwc", or "memory". Attempting to set it to any other value is > 3138 ** an error)^. 3130 ** ^If "ro" is specified, then the database is opened for read-only 3139 ** ^If "ro" is specified, then the database is opened for read-only 3131 ** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the 3140 ** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the 3132 ** third argument to sqlite3_prepare_v2(). ^If the mode option is set to 3141 ** third argument to sqlite3_prepare_v2(). ^If the mode option is set to 3133 ** "rw", then the database is opened for read-write (but not create) 3142 ** "rw", then the database is opened for read-write (but not create) 3134 ** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had 3143 ** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had 3135 ** been set. ^Value "rwc" is equivalent to setting both 3144 ** been set. ^Value "rwc" is equivalent to setting both 3136 ** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If sqlite3_open_v2() is | 3145 ** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If the mode option is > 3146 ** set to "memory" then a pure [in-memory database] that never reads 3137 ** used, it is an error to specify a value for the mode parameter that is | 3147 ** or writes from disk is used. ^It is an error to specify a value for 3138 ** less restrictive than that specified by the flags passed as the third | 3148 ** the mode parameter that is less restrictive than that specified by 3139 ** parameter. < > 3149 ** the flags passed in the third parameter to sqlite3_open_v2(). 3140 ** 3150 ** 3141 ** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or 3151 ** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or 3142 ** "private". ^Setting it to "shared" is equivalent to setting the 3152 ** "private". ^Setting it to "shared" is equivalent to setting the 3143 ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to 3153 ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to 3144 ** sqlite3_open_v2(). ^Setting the cache parameter to "private" is 3154 ** sqlite3_open_v2(). ^Setting the cache parameter to "private" is 3145 ** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit. 3155 ** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit. 3146 ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in 3156 ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in ................................................................................................................................................................................ 4995 ** using [sqlite3_free]. 5005 ** using [sqlite3_free]. 4996 ** Hence, if this variable is modified directly, either it should be 5006 ** Hence, if this variable is modified directly, either it should be 4997 ** made NULL or made to point to memory obtained from [sqlite3_malloc] 5007 ** made NULL or made to point to memory obtained from [sqlite3_malloc] 4998 ** or else the use of the [temp_store_directory pragma] should be avoided. 5008 ** or else the use of the [temp_store_directory pragma] should be avoided. 4999 */ 5009 */ 5000 SQLITE_API char *sqlite3_temp_directory; 5010 SQLITE_API char *sqlite3_temp_directory; 5001 5011 > 5012 /* > 5013 ** CAPI3REF: Name Of The Folder Holding Database Files > 5014 ** > 5015 ** ^(If this global variable is made to point to a string which is > 5016 ** the name of a folder (a.k.a. directory), then all database files > 5017 ** specified with a relative pathname and created or accessed by > 5018 ** SQLite when using a built-in [sqlite3_vfs | VFS] will be assumed > 5019 ** to be relative to that directory.)^ ^If this variable is a NULL > 5020 ** pointer, then SQLite assumes that all database files specified > 5021 ** with a relative pathname are relative to the current directory > 5022 ** for the process. > 5023 ** > 5024 ** Changing the value of this variable while a database connection is > 5025 ** open can result in a corrupt database. > 5026 ** > 5027 ** It is not safe to read or modify this variable in more than one > 5028 ** thread at a time. It is not safe to read or modify this variable > 5029 ** if a [database connection] is being used at the same time in a separate > 5030 ** thread. > 5031 ** It is intended that this variable be set once > 5032 ** as part of process initialization and before any SQLite interface > 5033 ** routines have been called and that this variable remain unchanged > 5034 ** thereafter. > 5035 ** > 5036 ** ^The [data_store_directory pragma] may modify this variable and cause > 5037 ** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore, > 5038 ** the [data_store_directory pragma] always assumes that any string > 5039 ** that this variable points to is held in memory obtained from > 5040 ** [sqlite3_malloc] and the pragma may attempt to free that memory > 5041 ** using [sqlite3_free]. > 5042 ** Hence, if this variable is modified directly, either it should be > 5043 ** made NULL or made to point to memory obtained from [sqlite3_malloc] > 5044 ** or else the use of the [data_store_directory pragma] should be avoided. > 5045 */ > 5046 SQLITE_API char *sqlite3_data_directory; > 5047 5002 /* 5048 /* 5003 ** CAPI3REF: Test For Auto-Commit Mode 5049 ** CAPI3REF: Test For Auto-Commit Mode 5004 ** KEYWORDS: {autocommit mode} 5050 ** KEYWORDS: {autocommit mode} 5005 ** 5051 ** 5006 ** ^The sqlite3_get_autocommit() interface returns non-zero or 5052 ** ^The sqlite3_get_autocommit() interface returns non-zero or 5007 ** zero if the given database connection is or is not in autocommit mode, 5053 ** zero if the given database connection is or is not in autocommit mode, 5008 ** respectively. ^Autocommit mode is on by default. 5054 ** respectively. ^Autocommit mode is on by default. ................................................................................................................................................................................ 5173 sqlite3*, 5219 sqlite3*, 5174 void(*)(void *,int ,char const *,char const *,sqlite3_int64), 5220 void(*)(void *,int ,char const *,char const *,sqlite3_int64), 5175 void* 5221 void* 5176 ); 5222 ); 5177 5223 5178 /* 5224 /* 5179 ** CAPI3REF: Enable Or Disable Shared Pager Cache 5225 ** CAPI3REF: Enable Or Disable Shared Pager Cache 5180 ** KEYWORDS: {shared cache} < 5181 ** 5226 ** 5182 ** ^(This routine enables or disables the sharing of the database cache 5227 ** ^(This routine enables or disables the sharing of the database cache 5183 ** and schema data structures between [database connection | connections] 5228 ** and schema data structures between [database connection | connections] 5184 ** to the same database. Sharing is enabled if the argument is true 5229 ** to the same database. Sharing is enabled if the argument is true 5185 ** and disabled if the argument is false.)^ 5230 ** and disabled if the argument is false.)^ 5186 ** 5231 ** 5187 ** ^Cache sharing is enabled and disabled for an entire process. 5232 ** ^Cache sharing is enabled and disabled for an entire process. ................................................................................................................................................................................ 9012 SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager); 9057 SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager); 9013 #endif 9058 #endif 9014 9059 9015 /* Functions used to query pager state and configuration. */ 9060 /* Functions used to query pager state and configuration. */ 9016 SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*); 9061 SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*); 9017 SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*); 9062 SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*); 9018 SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*); 9063 SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*); 9019 SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*); | 9064 SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*, int); 9020 SQLITE_PRIVATE const sqlite3_vfs *sqlite3PagerVfs(Pager*); 9065 SQLITE_PRIVATE const sqlite3_vfs *sqlite3PagerVfs(Pager*); 9021 SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*); 9066 SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*); 9022 SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*); 9067 SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*); 9023 SQLITE_PRIVATE int sqlite3PagerNosync(Pager*); 9068 SQLITE_PRIVATE int sqlite3PagerNosync(Pager*); 9024 SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*); 9069 SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*); 9025 SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager*); 9070 SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager*); 9026 SQLITE_PRIVATE void sqlite3PagerCacheStat(Pager *, int, int, int *); 9071 SQLITE_PRIVATE void sqlite3PagerCacheStat(Pager *, int, int, int *); ................................................................................................................................................................................ 9282 # endif 9327 # endif 9283 #else 9328 #else 9284 # ifndef SQLITE_OS_WIN 9329 # ifndef SQLITE_OS_WIN 9285 # define SQLITE_OS_WIN 0 9330 # define SQLITE_OS_WIN 0 9286 # endif 9331 # endif 9287 #endif 9332 #endif 9288 9333 9289 /* < 9290 ** Define the maximum size of a temporary filename < 9291 */ < 9292 #if SQLITE_OS_WIN 9334 #if SQLITE_OS_WIN 9293 # include <windows.h> 9335 # include <windows.h> 9294 # define SQLITE_TEMPNAME_SIZE (MAX_PATH+50) < > 9336 #endif > 9337 9295 #elif SQLITE_OS_OS2 | 9338 #if SQLITE_OS_OS2 9296 # if (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 3) && defined(OS2_HIGH_ 9339 # if (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 3) && defined(OS2_HIGH_ 9297 # include <os2safe.h> /* has to be included before os2.h for linking to work */ 9340 # include <os2safe.h> /* has to be included before os2.h for linking to work */ 9298 # endif 9341 # endif 9299 # define INCL_DOSDATETIME 9342 # define INCL_DOSDATETIME 9300 # define INCL_DOSFILEMGR 9343 # define INCL_DOSFILEMGR 9301 # define INCL_DOSERRORS 9344 # define INCL_DOSERRORS 9302 # define INCL_DOSMISC 9345 # define INCL_DOSMISC 9303 # define INCL_DOSPROCESS 9346 # define INCL_DOSPROCESS 9304 # define INCL_DOSMODULEMGR 9347 # define INCL_DOSMODULEMGR 9305 # define INCL_DOSSEMAPHORES 9348 # define INCL_DOSSEMAPHORES 9306 # include <os2.h> 9349 # include <os2.h> 9307 # include <uconv.h> 9350 # include <uconv.h> 9308 # define SQLITE_TEMPNAME_SIZE (CCHMAXPATHCOMP) < 9309 #else < 9310 # define SQLITE_TEMPNAME_SIZE 200 < 9311 #endif 9351 #endif 9312 9352 9313 /* 9353 /* 9314 ** Determine if we are dealing with Windows NT. 9354 ** Determine if we are dealing with Windows NT. 9315 ** 9355 ** 9316 ** We ought to be able to determine if we are compiling for win98 or winNT 9356 ** We ought to be able to determine if we are compiling for win98 or winNT 9317 ** using the _WIN32_WINNT macro as follows: 9357 ** using the _WIN32_WINNT macro as follows: ................................................................................................................................................................................ 9337 */ 9377 */ 9338 #if defined(_WIN32_WCE) 9378 #if defined(_WIN32_WCE) 9339 # define SQLITE_OS_WINCE 1 9379 # define SQLITE_OS_WINCE 1 9340 #else 9380 #else 9341 # define SQLITE_OS_WINCE 0 9381 # define SQLITE_OS_WINCE 0 9342 #endif 9382 #endif 9343 9383 > 9384 /* > 9385 ** Determine if we are dealing with WindowsRT (Metro) as this has a different an > 9386 ** incompatible API from win32. > 9387 */ > 9388 #if !defined(SQLITE_OS_WINRT) > 9389 # define SQLITE_OS_WINRT 0 > 9390 #endif > 9391 > 9392 /* > 9393 ** When compiled for WinCE or WinRT, there is no concept of the current > 9394 ** directory. > 9395 */ > 9396 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT > 9397 # define SQLITE_CURDIR 1 > 9398 #endif > 9399 9344 /* If the SET_FULLSYNC macro is not defined above, then make it 9400 /* If the SET_FULLSYNC macro is not defined above, then make it 9345 ** a no-op 9401 ** a no-op 9346 */ 9402 */ 9347 #ifndef SET_FULLSYNC 9403 #ifndef SET_FULLSYNC 9348 # define SET_FULLSYNC(x,y) 9404 # define SET_FULLSYNC(x,y) 9349 #endif 9405 #endif 9350 9406 ................................................................................................................................................................................ 10931 ** NameContext list corresponds to searching through successively outer 10987 ** NameContext list corresponds to searching through successively outer 10932 ** subqueries looking for a match. 10988 ** subqueries looking for a match. 10933 */ 10989 */ 10934 struct NameContext { 10990 struct NameContext { 10935 Parse *pParse; /* The parser */ 10991 Parse *pParse; /* The parser */ 10936 SrcList *pSrcList; /* One or more tables used to resolve names */ 10992 SrcList *pSrcList; /* One or more tables used to resolve names */ 10937 ExprList *pEList; /* Optional list of named expressions */ 10993 ExprList *pEList; /* Optional list of named expressions */ > 10994 AggInfo *pAggInfo; /* Information about aggregates at this level */ > 10995 NameContext *pNext; /* Next outer name context. NULL for outermost */ 10938 int nRef; /* Number of names resolved by this context */ 10996 int nRef; /* Number of names resolved by this context */ 10939 int nErr; /* Number of errors encountered while resolving names */ 10997 int nErr; /* Number of errors encountered while resolving names */ 10940 u8 allowAgg; /* Aggregate functions allowed here */ < 10941 u8 hasAgg; /* True if aggregates are seen */ < 10942 u8 isCheck; /* True if resolving names in a CHECK constraint */ | 10998 u8 ncFlags; /* Zero or more NC_* flags defined below */ 10943 AggInfo *pAggInfo; /* Information about aggregates at this level */ < 10944 NameContext *pNext; /* Next outer name context. NULL for outermost */ < 10945 }; 10999 }; 10946 11000 > 11001 /* > 11002 ** Allowed values for the NameContext, ncFlags field. > 11003 */ > 11004 #define NC_AllowAgg 0x01 /* Aggregate functions are allowed here */ > 11005 #define NC_HasAgg 0x02 /* One or more aggregate functions seen */ > 11006 #define NC_IsCheck 0x04 /* True if resolving names in a CHECK constraint */ > 11007 #define NC_InAggFunc 0x08 /* True if analyzing arguments to an agg func */ > 11008 10947 /* 11009 /* 10948 ** An instance of the following structure contains all information 11010 ** An instance of the following structure contains all information 10949 ** needed to generate code for a single SELECT statement. 11011 ** needed to generate code for a single SELECT statement. 10950 ** 11012 ** 10951 ** nLimit is set to -1 if there is no LIMIT clause. nOffset is set to 0. 11013 ** nLimit is set to -1 if there is no LIMIT clause. nOffset is set to 0. 10952 ** If there is a LIMIT clause, the parser sets nLimit to the value of the 11014 ** If there is a LIMIT clause, the parser sets nLimit to the value of the 10953 ** limit and nOffset to the value of the offset (or 0 if there is not 11015 ** limit and nOffset to the value of the offset (or 0 if there is not ................................................................................................................................................................................ 11621 SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*); 11683 SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*); 11622 SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int); 11684 SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int); 11623 SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,ExprSpan*); 11685 SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,ExprSpan*); 11624 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*); 11686 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*); 11625 SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**); 11687 SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**); 11626 SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**); 11688 SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**); 11627 SQLITE_PRIVATE void sqlite3Pragma(Parse*,Token*,Token*,Token*,int); 11689 SQLITE_PRIVATE void sqlite3Pragma(Parse*,Token*,Token*,Token*,int); > 11690 SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3*); 11628 SQLITE_PRIVATE void sqlite3ResetInternalSchema(sqlite3*, int); | 11691 SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3*,int); > 11692 SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3*); 11629 SQLITE_PRIVATE void sqlite3BeginParse(Parse*,int); 11693 SQLITE_PRIVATE void sqlite3BeginParse(Parse*,int); 11630 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3*); 11694 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3*); 11631 SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*); 11695 SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*); 11632 SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *, int); 11696 SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *, int); 11633 SQLITE_PRIVATE void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int); 11697 SQLITE_PRIVATE void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int); 11634 SQLITE_PRIVATE void sqlite3AddColumn(Parse*,Token*); 11698 SQLITE_PRIVATE void sqlite3AddColumn(Parse*,Token*); 11635 SQLITE_PRIVATE void sqlite3AddNotNull(Parse*, int); 11699 SQLITE_PRIVATE void sqlite3AddNotNull(Parse*, int); ................................................................................................................................................................................ 12026 # define sqlite3VtabLock(X) 12090 # define sqlite3VtabLock(X) 12027 # define sqlite3VtabUnlock(X) 12091 # define sqlite3VtabUnlock(X) 12028 # define sqlite3VtabUnlockList(X) 12092 # define sqlite3VtabUnlockList(X) 12029 # define sqlite3VtabSavepoint(X, Y, Z) SQLITE_OK 12093 # define sqlite3VtabSavepoint(X, Y, Z) SQLITE_OK 12030 # define sqlite3GetVTable(X,Y) ((VTable*)0) 12094 # define sqlite3GetVTable(X,Y) ((VTable*)0) 12031 #else 12095 #else 12032 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*); 12096 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*); > 12097 SQLITE_PRIVATE void sqlite3VtabDisconnect(sqlite3 *db, Table *p); 12033 SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **); 12098 SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **); 12034 SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db); 12099 SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db); 12035 SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db); 12100 SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db); 12036 SQLITE_PRIVATE void sqlite3VtabLock(VTable *); 12101 SQLITE_PRIVATE void sqlite3VtabLock(VTable *); 12037 SQLITE_PRIVATE void sqlite3VtabUnlock(VTable *); 12102 SQLITE_PRIVATE void sqlite3VtabUnlock(VTable *); 12038 SQLITE_PRIVATE void sqlite3VtabUnlockList(sqlite3*); 12103 SQLITE_PRIVATE void sqlite3VtabUnlockList(sqlite3*); 12039 SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *, int, int); 12104 SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *, int, int); ................................................................................................................................................................................ 12479 "CASE_SENSITIVE_LIKE", 12544 "CASE_SENSITIVE_LIKE", 12480 #endif 12545 #endif 12481 #ifdef SQLITE_CHECK_PAGES 12546 #ifdef SQLITE_CHECK_PAGES 12482 "CHECK_PAGES", 12547 "CHECK_PAGES", 12483 #endif 12548 #endif 12484 #ifdef SQLITE_COVERAGE_TEST 12549 #ifdef SQLITE_COVERAGE_TEST 12485 "COVERAGE_TEST", 12550 "COVERAGE_TEST", > 12551 #endif > 12552 #ifdef SQLITE_CURDIR > 12553 "CURDIR", 12486 #endif 12554 #endif 12487 #ifdef SQLITE_DEBUG 12555 #ifdef SQLITE_DEBUG 12488 "DEBUG", 12556 "DEBUG", 12489 #endif 12557 #endif 12490 #ifdef SQLITE_DEFAULT_LOCKING_MODE 12558 #ifdef SQLITE_DEFAULT_LOCKING_MODE 12491 "DEFAULT_LOCKING_MODE=" CTIMEOPT_VAL(SQLITE_DEFAULT_LOCKING_MODE), 12559 "DEFAULT_LOCKING_MODE=" CTIMEOPT_VAL(SQLITE_DEFAULT_LOCKING_MODE), 12492 #endif 12560 #endif ................................................................................................................................................................................ 18333 ** mutexIsNT() is only used for the TryEnterCriticalSection() API call, 18401 ** mutexIsNT() is only used for the TryEnterCriticalSection() API call, 18334 ** which is only available if your application was compiled with 18402 ** which is only available if your application was compiled with 18335 ** _WIN32_WINNT defined to a value >= 0x0400. Currently, the only 18403 ** _WIN32_WINNT defined to a value >= 0x0400. Currently, the only 18336 ** call to TryEnterCriticalSection() is #ifdef'ed out, so #ifdef 18404 ** call to TryEnterCriticalSection() is #ifdef'ed out, so #ifdef 18337 ** this out as well. 18405 ** this out as well. 18338 */ 18406 */ 18339 #if 0 18407 #if 0 18340 #if SQLITE_OS_WINCE | 18408 #if SQLITE_OS_WINCE || SQLITE_OS_WINRT 18341 # define mutexIsNT() (1) 18409 # define mutexIsNT() (1) 18342 #else 18410 #else 18343 static int mutexIsNT(void){ 18411 static int mutexIsNT(void){ 18344 static int osType = 0; 18412 static int osType = 0; 18345 if( osType==0 ){ 18413 if( osType==0 ){ 18346 OSVERSIONINFO sInfo; 18414 OSVERSIONINFO sInfo; 18347 sInfo.dwOSVersionInfoSize = sizeof(sInfo); 18415 sInfo.dwOSVersionInfoSize = sizeof(sInfo); ................................................................................................................................................................................ 18386 /* As winMutexInit() and winMutexEnd() are called as part 18454 /* As winMutexInit() and winMutexEnd() are called as part 18387 ** of the sqlite3_initialize and sqlite3_shutdown() 18455 ** of the sqlite3_initialize and sqlite3_shutdown() 18388 ** processing, the "interlocked" magic is probably not 18456 ** processing, the "interlocked" magic is probably not 18389 ** strictly necessary. 18457 ** strictly necessary. 18390 */ 18458 */ 18391 static long winMutex_lock = 0; 18459 static long winMutex_lock = 0; 18392 18460 > 18461 SQLITE_API extern void sqlite3_win32_sleep(DWORD milliseconds); /* os_win.c */ > 18462 18393 static int winMutexInit(void){ 18463 static int winMutexInit(void){ 18394 /* The first to increment to 1 does actual initialization */ 18464 /* The first to increment to 1 does actual initialization */ 18395 if( InterlockedCompareExchange(&winMutex_lock, 1, 0)==0 ){ 18465 if( InterlockedCompareExchange(&winMutex_lock, 1, 0)==0 ){ 18396 int i; 18466 int i; 18397 for(i=0; i<ArraySize(winMutex_staticMutexes); i++){ 18467 for(i=0; i<ArraySize(winMutex_staticMutexes); i++){ > 18468 #if SQLITE_OS_WINRT > 18469 InitializeCriticalSectionEx(&winMutex_staticMutexes[i].mutex, 0, 0); > 18470 #else 18398 InitializeCriticalSection(&winMutex_staticMutexes[i].mutex); 18471 InitializeCriticalSection(&winMutex_staticMutexes[i].mutex); > 18472 #endif 18399 } 18473 } 18400 winMutex_isInit = 1; 18474 winMutex_isInit = 1; 18401 }else{ 18475 }else{ 18402 /* Someone else is in the process of initing the static mutexes */ 18476 /* Someone else is in the process of initing the static mutexes */ 18403 while( !winMutex_isInit ){ 18477 while( !winMutex_isInit ){ 18404 Sleep(1); | 18478 sqlite3_win32_sleep(1); 18405 } 18479 } 18406 } 18480 } 18407 return SQLITE_OK; 18481 return SQLITE_OK; 18408 } 18482 } 18409 18483 18410 static int winMutexEnd(void){ 18484 static int winMutexEnd(void){ 18411 /* The first to decrement to 0 does actual shutdown 18485 /* The first to decrement to 0 does actual shutdown ................................................................................................................................................................................ 18471 case SQLITE_MUTEX_FAST: 18545 case SQLITE_MUTEX_FAST: 18472 case SQLITE_MUTEX_RECURSIVE: { 18546 case SQLITE_MUTEX_RECURSIVE: { 18473 p = sqlite3MallocZero( sizeof(*p) ); 18547 p = sqlite3MallocZero( sizeof(*p) ); 18474 if( p ){ 18548 if( p ){ 18475 #ifdef SQLITE_DEBUG 18549 #ifdef SQLITE_DEBUG 18476 p->id = iType; 18550 p->id = iType; 18477 #endif 18551 #endif > 18552 #if SQLITE_OS_WINRT > 18553 InitializeCriticalSectionEx(&p->mutex, 0, 0); > 18554 #else 18478 InitializeCriticalSection(&p->mutex); 18555 InitializeCriticalSection(&p->mutex); > 18556 #endif 18479 } 18557 } 18480 break; 18558 break; 18481 } 18559 } 18482 default: { 18560 default: { 18483 assert( winMutex_isInit==1 ); 18561 assert( winMutex_isInit==1 ); 18484 assert( iType-2 >= 0 ); 18562 assert( iType-2 >= 0 ); 18485 assert( iType-2 < ArraySize(winMutex_staticMutexes) ); 18563 assert( iType-2 < ArraySize(winMutex_staticMutexes) ); ................................................................................................................................................................................ 19102 if( db ){ 19180 if( db ){ 19103 if( db->pnBytesFreed ){ 19181 if( db->pnBytesFreed ){ 19104 *db->pnBytesFreed += sqlite3DbMallocSize(db, p); 19182 *db->pnBytesFreed += sqlite3DbMallocSize(db, p); 19105 return; 19183 return; 19106 } 19184 } 19107 if( isLookaside(db, p) ){ 19185 if( isLookaside(db, p) ){ 19108 LookasideSlot *pBuf = (LookasideSlot*)p; 19186 LookasideSlot *pBuf = (LookasideSlot*)p; > 19187 #if SQLITE_DEBUG > 19188 /* Trash all content in the buffer being freed */ > 19189 memset(p, 0xaa, db->lookaside.sz); > 19190 #endif 19109 pBuf->pNext = db->lookaside.pFree; 19191 pBuf->pNext = db->lookaside.pFree; 19110 db->lookaside.pFree = pBuf; 19192 db->lookaside.pFree = pBuf; 19111 db->lookaside.nOut--; 19193 db->lookaside.nOut--; 19112 return; 19194 return; 19113 } 19195 } 19114 } 19196 } 19115 assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) ); 19197 assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) ); ................................................................................................................................................................................ 25060 #endif 25142 #endif 25061 #if SQLITE_ENABLE_LOCKING_STYLE || defined(__APPLE__) 25143 #if SQLITE_ENABLE_LOCKING_STYLE || defined(__APPLE__) 25062 unsigned fsFlags; /* cached details from statfs() */ 25144 unsigned fsFlags; /* cached details from statfs() */ 25063 #endif 25145 #endif 25064 #if OS_VXWORKS 25146 #if OS_VXWORKS 25065 struct vxworksFileId *pId; /* Unique file ID */ 25147 struct vxworksFileId *pId; /* Unique file ID */ 25066 #endif 25148 #endif 25067 #ifndef NDEBUG | 25149 #ifdef SQLITE_DEBUG 25068 /* The next group of variables are used to track whether or not the 25150 /* The next group of variables are used to track whether or not the 25069 ** transaction counter in bytes 24-27 of database files are updated 25151 ** transaction counter in bytes 24-27 of database files are updated 25070 ** whenever any part of the database changes. An assertion fault will 25152 ** whenever any part of the database changes. An assertion fault will 25071 ** occur if a file is updated without also updating the transaction 25153 ** occur if a file is updated without also updating the transaction 25072 ** counter. This test is made to avoid new problems similar to the 25154 ** counter. This test is made to avoid new problems similar to the 25073 ** one described by ticket #3584. 25155 ** one described by ticket #3584. 25074 */ 25156 */ ................................................................................................................................................................................ 25095 #else 25177 #else 25096 # define UNIXFILE_DIRSYNC 0x00 25178 # define UNIXFILE_DIRSYNC 0x00 25097 #endif 25179 #endif 25098 #define UNIXFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */ 25180 #define UNIXFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */ 25099 #define UNIXFILE_DELETE 0x20 /* Delete on close */ 25181 #define UNIXFILE_DELETE 0x20 /* Delete on close */ 25100 #define UNIXFILE_URI 0x40 /* Filename might have query parameters */ 25182 #define UNIXFILE_URI 0x40 /* Filename might have query parameters */ 25101 #define UNIXFILE_NOLOCK 0x80 /* Do no file locking */ 25183 #define UNIXFILE_NOLOCK 0x80 /* Do no file locking */ 25102 #define UNIXFILE_CHOWN 0x100 /* File ownership was changed */ < 25103 25184 25104 /* 25185 /* 25105 ** Include code that is common to all os_*.c files 25186 ** Include code that is common to all os_*.c files 25106 */ 25187 */ 25107 /************** Include os_common.h in the middle of os_unix.c ***************/ 25188 /************** Include os_common.h in the middle of os_unix.c ***************/ 25108 /************** Begin file os_common.h ***************************************/ 25189 /************** Begin file os_common.h ***************************************/ 25109 /* 25190 /* ................................................................................................................................................................................ 25348 ** 25429 ** 25349 ** The safest way to deal with the problem is to always use this wrapper 25430 ** The safest way to deal with the problem is to always use this wrapper 25350 ** which always has the same well-defined interface. 25431 ** which always has the same well-defined interface. 25351 */ 25432 */ 25352 static int posixOpen(const char *zFile, int flags, int mode){ 25433 static int posixOpen(const char *zFile, int flags, int mode){ 25353 return open(zFile, flags, mode); 25434 return open(zFile, flags, mode); 25354 } 25435 } > 25436 > 25437 /* > 25438 ** On some systems, calls to fchown() will trigger a message in a security > 25439 ** log if they come from non-root processes. So avoid calling fchown() if > 25440 ** we are not running as root. > 25441 */ > 25442 static int posixFchown(int fd, uid_t uid, gid_t gid){ > 25443 return geteuid() ? 0 : fchown(fd,uid,gid); > 25444 } 25355 25445 25356 /* Forward reference */ 25446 /* Forward reference */ 25357 static int openDirectory(const char*, int*); 25447 static int openDirectory(const char*, int*); 25358 25448 25359 /* 25449 /* 25360 ** Many system calls are accessed through pointer-to-functions so that 25450 ** Many system calls are accessed through pointer-to-functions so that 25361 ** they may be overridden at runtime to facilitate fault injection during 25451 ** they may be overridden at runtime to facilitate fault injection during ................................................................................................................................................................................ 25460 25550 25461 { "mkdir", (sqlite3_syscall_ptr)mkdir, 0 }, 25551 { "mkdir", (sqlite3_syscall_ptr)mkdir, 0 }, 25462 #define osMkdir ((int(*)(const char*,mode_t))aSyscall[18].pCurrent) 25552 #define osMkdir ((int(*)(const char*,mode_t))aSyscall[18].pCurrent) 25463 25553 25464 { "rmdir", (sqlite3_syscall_ptr)rmdir, 0 }, 25554 { "rmdir", (sqlite3_syscall_ptr)rmdir, 0 }, 25465 #define osRmdir ((int(*)(const char*))aSyscall[19].pCurrent) 25555 #define osRmdir ((int(*)(const char*))aSyscall[19].pCurrent) 25466 25556 25467 { "fchown", (sqlite3_syscall_ptr)fchown, 0 }, | 25557 { "fchown", (sqlite3_syscall_ptr)posixFchown, 0 }, 25468 #define osFchown ((int(*)(int,uid_t,gid_t))aSyscall[20].pCurrent) 25558 #define osFchown ((int(*)(int,uid_t,gid_t))aSyscall[20].pCurrent) 25469 25559 25470 { "umask", (sqlite3_syscall_ptr)umask, 0 }, 25560 { "umask", (sqlite3_syscall_ptr)umask, 0 }, 25471 #define osUmask ((mode_t(*)(mode_t))aSyscall[21].pCurrent) 25561 #define osUmask ((mode_t(*)(mode_t))aSyscall[21].pCurrent) 25472 25562 25473 }; /* End of the overrideable system calls */ 25563 }; /* End of the overrideable system calls */ 25474 25564 ................................................................................................................................................................................ 26604 if( rc!=SQLITE_BUSY ){ 26694 if( rc!=SQLITE_BUSY ){ 26605 pFile->lastErrno = tErrno; 26695 pFile->lastErrno = tErrno; 26606 } 26696 } 26607 } 26697 } 26608 } 26698 } 26609 26699 26610 26700 26611 #ifndef NDEBUG | 26701 #ifdef SQLITE_DEBUG 26612 /* Set up the transaction-counter change checking flags when 26702 /* Set up the transaction-counter change checking flags when 26613 ** transitioning from a SHARED to a RESERVED lock. The change 26703 ** transitioning from a SHARED to a RESERVED lock. The change 26614 ** from SHARED to RESERVED marks the beginning of a normal 26704 ** from SHARED to RESERVED marks the beginning of a normal 26615 ** write operation (not a hot journal rollback). 26705 ** write operation (not a hot journal rollback). 26616 */ 26706 */ 26617 if( rc==SQLITE_OK 26707 if( rc==SQLITE_OK 26618 && pFile->eFileLock<=SHARED_LOCK 26708 && pFile->eFileLock<=SHARED_LOCK ................................................................................................................................................................................ 26683 } 26773 } 26684 unixEnterMutex(); 26774 unixEnterMutex(); 26685 pInode = pFile->pInode; 26775 pInode = pFile->pInode; 26686 assert( pInode->nShared!=0 ); 26776 assert( pInode->nShared!=0 ); 26687 if( pFile->eFileLock>SHARED_LOCK ){ 26777 if( pFile->eFileLock>SHARED_LOCK ){ 26688 assert( pInode->eFileLock==pFile->eFileLock ); 26778 assert( pInode->eFileLock==pFile->eFileLock ); 26689 26779 26690 #ifndef NDEBUG | 26780 #ifdef SQLITE_DEBUG 26691 /* When reducing a lock such that other processes can start 26781 /* When reducing a lock such that other processes can start 26692 ** reading the database file again, make sure that the 26782 ** reading the database file again, make sure that the 26693 ** transaction counter was updated if any part of the database 26783 ** transaction counter was updated if any part of the database 26694 ** file changed. If the transaction counter is not updated, 26784 ** file changed. If the transaction counter is not updated, 26695 ** other connections to the same file might not realize that 26785 ** other connections to the same file might not realize that 26696 ** the file has changed and hence might not know to flush their 26786 ** the file has changed and hence might not know to flush their 26697 ** cache. The use of a stale cache can lead to database corruption. 26787 ** cache. The use of a stale cache can lead to database corruption. ................................................................................................................................................................................ 27882 assert( pInode->nShared!=0 ); 27972 assert( pInode->nShared!=0 ); 27883 if( pFile->eFileLock>SHARED_LOCK ){ 27973 if( pFile->eFileLock>SHARED_LOCK ){ 27884 assert( pInode->eFileLock==pFile->eFileLock ); 27974 assert( pInode->eFileLock==pFile->eFileLock ); 27885 SimulateIOErrorBenign(1); 27975 SimulateIOErrorBenign(1); 27886 SimulateIOError( h=(-1) ) 27976 SimulateIOError( h=(-1) ) 27887 SimulateIOErrorBenign(0); 27977 SimulateIOErrorBenign(0); 27888 27978 27889 #ifndef NDEBUG | 27979 #ifdef SQLITE_DEBUG 27890 /* When reducing a lock such that other processes can start 27980 /* When reducing a lock such that other processes can start 27891 ** reading the database file again, make sure that the 27981 ** reading the database file again, make sure that the 27892 ** transaction counter was updated if any part of the database 27982 ** transaction counter was updated if any part of the database 27893 ** file changed. If the transaction counter is not updated, 27983 ** file changed. If the transaction counter is not updated, 27894 ** other connections to the same file might not realize that 27984 ** other connections to the same file might not realize that 27895 ** the file has changed and hence might not know to flush their 27985 ** the file has changed and hence might not know to flush their 27896 ** cache. The use of a stale cache can lead to database corruption. 27986 ** cache. The use of a stale cache can lead to database corruption. ................................................................................................................................................................................ 28186 #if 0 28276 #if 0 28187 assert( pFile->pUnused==0 28277 assert( pFile->pUnused==0 28188 || offset>=PENDING_BYTE+512 28278 || offset>=PENDING_BYTE+512 28189 || offset+amt<=PENDING_BYTE 28279 || offset+amt<=PENDING_BYTE 28190 ); 28280 ); 28191 #endif 28281 #endif 28192 28282 28193 #ifndef NDEBUG | 28283 #ifdef SQLITE_DEBUG 28194 /* If we are doing a normal write to a database file (as opposed to 28284 /* If we are doing a normal write to a database file (as opposed to 28195 ** doing a hot-journal rollback or a write to some file other than a 28285 ** doing a hot-journal rollback or a write to some file other than a 28196 ** normal database file) then record the fact that the database 28286 ** normal database file) then record the fact that the database 28197 ** has changed. If the transaction counter is modified, record that 28287 ** has changed. If the transaction counter is modified, record that 28198 ** fact too. 28288 ** fact too. 28199 */ 28289 */ 28200 if( pFile->inNormalWrite ){ 28290 if( pFile->inNormalWrite ){ ................................................................................................................................................................................ 28477 } 28567 } 28478 28568 28479 rc = robust_ftruncate(pFile->h, (off_t)nByte); 28569 rc = robust_ftruncate(pFile->h, (off_t)nByte); 28480 if( rc ){ 28570 if( rc ){ 28481 pFile->lastErrno = errno; 28571 pFile->lastErrno = errno; 28482 return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath); 28572 return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath); 28483 }else{ 28573 }else{ 28484 #ifndef NDEBUG | 28574 #ifdef SQLITE_DEBUG 28485 /* If we are doing a normal write to a database file (as opposed to 28575 /* If we are doing a normal write to a database file (as opposed to 28486 ** doing a hot-journal rollback or a write to some file other than a 28576 ** doing a hot-journal rollback or a write to some file other than a 28487 ** normal database file) and we truncate the file to zero length, 28577 ** normal database file) and we truncate the file to zero length, 28488 ** that effectively updates the change counter. This might happen 28578 ** that effectively updates the change counter. This might happen 28489 ** when restoring a database using the backup API from a zero-length 28579 ** when restoring a database using the backup API from a zero-length 28490 ** source. 28580 ** source. 28491 */ 28581 */ ................................................................................................................................................................................ 28634 unixModeBit(pFile, UNIXFILE_PSOW, (int*)pArg); 28724 unixModeBit(pFile, UNIXFILE_PSOW, (int*)pArg); 28635 return SQLITE_OK; 28725 return SQLITE_OK; 28636 } 28726 } 28637 case SQLITE_FCNTL_VFSNAME: { 28727 case SQLITE_FCNTL_VFSNAME: { 28638 *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName); 28728 *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName); 28639 return SQLITE_OK; 28729 return SQLITE_OK; 28640 } 28730 } 28641 #ifndef NDEBUG | 28731 #ifdef SQLITE_DEBUG 28642 /* The pager calls this method to signal that it has done 28732 /* The pager calls this method to signal that it has done 28643 ** a rollback and that the database is therefore unchanged and 28733 ** a rollback and that the database is therefore unchanged and 28644 ** it hence it is OK for the transaction change counter to be 28734 ** it hence it is OK for the transaction change counter to be 28645 ** unchanged. 28735 ** unchanged. 28646 */ 28736 */ 28647 case SQLITE_FCNTL_DB_UNCHANGED: { 28737 case SQLITE_FCNTL_DB_UNCHANGED: { 28648 ((unixFile*)id)->dbUpdate = 0; 28738 ((unixFile*)id)->dbUpdate = 0; ................................................................................................................................................................................ 28985 if( pShmNode->h<0 ){ 29075 if( pShmNode->h<0 ){ 28986 rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShmFilename); 29076 rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShmFilename); 28987 goto shm_open_err; 29077 goto shm_open_err; 28988 } 29078 } 28989 29079 28990 /* If this process is running as root, make sure that the SHM file 29080 /* If this process is running as root, make sure that the SHM file 28991 ** is owned by the same user that owns the original database. Otherwise, 29081 ** is owned by the same user that owns the original database. Otherwise, 28992 ** the original owner will not be able to connect. If this process is | 29082 ** the original owner will not be able to connect. 28993 ** not root, the following fchown() will fail, but we don't care. The < 28994 ** if(){..} and the UNIXFILE_CHOWN flag are purely to silence compiler < 28995 ** warnings. < 28996 */ 29083 */ 28997 if( osFchown(pShmNode->h, sStat.st_uid, sStat.st_gid)==0 ){ | 29084 osFchown(pShmNode->h, sStat.st_uid, sStat.st_gid); 28998 pDbFd->ctrlFlags |= UNIXFILE_CHOWN; < 28999 } < 29000 29085 29001 /* Check to see if another process is holding the dead-man switch. 29086 /* Check to see if another process is holding the dead-man switch. 29002 ** If not, truncate the file to zero length. 29087 ** If not, truncate the file to zero length. 29003 */ 29088 */ 29004 rc = SQLITE_OK; 29089 rc = SQLITE_OK; 29005 if( unixShmSystemLock(pShmNode, F_WRLCK, UNIX_SHM_DMS, 1)==SQLITE_OK ){ 29090 if( unixShmSystemLock(pShmNode, F_WRLCK, UNIX_SHM_DMS, 1)==SQLITE_OK ){ 29006 if( robust_ftruncate(pShmNode->h, 0) ){ 29091 if( robust_ftruncate(pShmNode->h, 0) ){ ................................................................................................................................................................................ 30198 if( fd<0 ){ 30283 if( fd<0 ){ 30199 rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zName); 30284 rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zName); 30200 goto open_finished; 30285 goto open_finished; 30201 } 30286 } 30202 30287 30203 /* If this process is running as root and if creating a new rollback 30288 /* If this process is running as root and if creating a new rollback 30204 ** journal or WAL file, set the ownership of the journal or WAL to be 30289 ** journal or WAL file, set the ownership of the journal or WAL to be 30205 ** the same as the original database. If we are not running as root, | 30290 ** the same as the original database. 30206 ** then the fchown() call will fail, but that's ok. The "if(){}" and < 30207 ** the setting of the UNIXFILE_CHOWN flag are purely to silence compiler < 30208 ** warnings from gcc. < 30209 */ 30291 */ 30210 if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){ 30292 if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){ 30211 if( osFchown(fd, uid, gid)==0 ){ p->ctrlFlags |= UNIXFILE_CHOWN; } | 30293 osFchown(fd, uid, gid); 30212 } 30294 } 30213 } 30295 } 30214 assert( fd>=0 ); 30296 assert( fd>=0 ); 30215 if( pOutFlags ){ 30297 if( pOutFlags ){ 30216 *pOutFlags = flags; 30298 *pOutFlags = flags; 30217 } 30299 } 30218 30300 ................................................................................................................................................................................ 32165 #endif 32247 #endif 32166 32248 32167 #endif /* !defined(_OS_COMMON_H_) */ 32249 #endif /* !defined(_OS_COMMON_H_) */ 32168 32250 32169 /************** End of os_common.h *******************************************/ 32251 /************** End of os_common.h *******************************************/ 32170 /************** Continuing where we left off in os_win.c *********************/ 32252 /************** Continuing where we left off in os_win.c *********************/ 32171 32253 > 32254 /* > 32255 ** Macro to find the minimum of two numeric values. > 32256 */ > 32257 #ifndef MIN > 32258 # define MIN(x,y) ((x)<(y)?(x):(y)) > 32259 #endif > 32260 32172 /* 32261 /* 32173 ** Some Microsoft compilers lack this definition. 32262 ** Some Microsoft compilers lack this definition. 32174 */ 32263 */ 32175 #ifndef INVALID_FILE_ATTRIBUTES 32264 #ifndef INVALID_FILE_ATTRIBUTES 32176 # define INVALID_FILE_ATTRIBUTES ((DWORD)-1) 32265 # define INVALID_FILE_ATTRIBUTES ((DWORD)-1) 32177 #endif 32266 #endif > 32267 > 32268 #ifndef FILE_FLAG_MASK > 32269 # define FILE_FLAG_MASK (0xFF3C0000) > 32270 #endif > 32271 > 32272 #ifndef FILE_ATTRIBUTE_MASK > 32273 # define FILE_ATTRIBUTE_MASK (0x0003FFF7) > 32274 #endif 32178 32275 32179 /* Forward references */ 32276 /* Forward references */ 32180 typedef struct winShm winShm; /* A connection to shared-memory */ 32277 typedef struct winShm winShm; /* A connection to shared-memory */ 32181 typedef struct winShmNode winShmNode; /* A region of shared-memory */ 32278 typedef struct winShmNode winShmNode; /* A region of shared-memory */ 32182 32279 32183 /* 32280 /* 32184 ** WinCE lacks native support for file locking so we have to fake it 32281 ** WinCE lacks native support for file locking so we have to fake it ................................................................................................................................................................................ 32220 32317 32221 /* 32318 /* 32222 ** Allowed values for winFile.ctrlFlags 32319 ** Allowed values for winFile.ctrlFlags 32223 */ 32320 */ 32224 #define WINFILE_PERSIST_WAL 0x04 /* Persistent WAL mode */ 32321 #define WINFILE_PERSIST_WAL 0x04 /* Persistent WAL mode */ 32225 #define WINFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */ 32322 #define WINFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */ 32226 32323 > 32324 /* > 32325 * The size of the buffer used by sqlite3_win32_write_debug(). > 32326 */ > 32327 #ifndef SQLITE_WIN32_DBG_BUF_SIZE > 32328 # define SQLITE_WIN32_DBG_BUF_SIZE ((int)(4096-sizeof(DWORD))) > 32329 #endif > 32330 32227 /* 32331 /* 32228 * If compiled with SQLITE_WIN32_MALLOC on Windows, we will use the 32332 * If compiled with SQLITE_WIN32_MALLOC on Windows, we will use the 32229 * various Win32 API heap functions instead of our own. 32333 * various Win32 API heap functions instead of our own. 32230 */ 32334 */ 32231 #ifdef SQLITE_WIN32_MALLOC 32335 #ifdef SQLITE_WIN32_MALLOC > 32336 > 32337 /* > 32338 * If this is non-zero, an isolated heap will be created by the native Win32 > 32339 * allocator subsystem; otherwise, the default process heap will be used. This > 32340 * setting has no effect when compiling for WinRT. By default, this is enabled > 32341 * and an isolated heap will be created to store all allocated data. > 32342 * > 32343 ****************************************************************************** > 32344 * WARNING: It is important to note that when this setting is non-zero and the > 32345 * winMemShutdown function is called (e.g. by the sqlite3_shutdown > 32346 * function), all data that was allocated using the isolated heap will > 32347 * be freed immediately and any attempt to access any of that freed > 32348 * data will almost certainly result in an immediate access violation. > 32349 ****************************************************************************** > 32350 */ > 32351 #ifndef SQLITE_WIN32_HEAP_CREATE > 32352 # define SQLITE_WIN32_HEAP_CREATE (TRUE) > 32353 #endif > 32354 32232 /* 32355 /* 32233 * The initial size of the Win32-specific heap. This value may be zero. 32356 * The initial size of the Win32-specific heap. This value may be zero. 32234 */ 32357 */ 32235 #ifndef SQLITE_WIN32_HEAP_INIT_SIZE 32358 #ifndef SQLITE_WIN32_HEAP_INIT_SIZE 32236 # define SQLITE_WIN32_HEAP_INIT_SIZE ((SQLITE_DEFAULT_CACHE_SIZE) * \ 32359 # define SQLITE_WIN32_HEAP_INIT_SIZE ((SQLITE_DEFAULT_CACHE_SIZE) * \ 32237 (SQLITE_DEFAULT_PAGE_SIZE) + 4194304) 32360 (SQLITE_DEFAULT_PAGE_SIZE) + 4194304) 32238 #endif 32361 #endif ................................................................................................................................................................................ 32309 */ 32432 */ 32310 #ifdef SQLITE_TEST 32433 #ifdef SQLITE_TEST 32311 SQLITE_API int sqlite3_os_type = 0; 32434 SQLITE_API int sqlite3_os_type = 0; 32312 #else 32435 #else 32313 static int sqlite3_os_type = 0; 32436 static int sqlite3_os_type = 0; 32314 #endif 32437 #endif 32315 32438 32316 /* < 32317 ** Many system calls are accessed through pointer-to-functions so that < 32318 ** they may be overridden at runtime to facilitate fault injection during < 32319 ** testing and sandboxing. The following array holds the names and pointers < 32320 ** to all overrideable system calls. < 32321 */ < 32322 #if !SQLITE_OS_WINCE | 32439 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT 32323 # define SQLITE_WIN32_HAS_ANSI 32440 # define SQLITE_WIN32_HAS_ANSI 32324 #endif 32441 #endif 32325 32442 32326 #if SQLITE_OS_WINCE || SQLITE_OS_WINNT | 32443 #if SQLITE_OS_WINCE || SQLITE_OS_WINNT || SQLITE_OS_WINRT 32327 # define SQLITE_WIN32_HAS_WIDE 32444 # define SQLITE_WIN32_HAS_WIDE 32328 #endif 32445 #endif 32329 32446 32330 #ifndef SYSCALL 32447 #ifndef SYSCALL 32331 # define SYSCALL sqlite3_syscall_ptr 32448 # define SYSCALL sqlite3_syscall_ptr 32332 #endif 32449 #endif 32333 32450 32334 #if SQLITE_OS_WINCE < 32335 /* 32451 /* 32336 ** These macros are necessary because Windows CE does not natively support the < 32337 ** Win32 APIs LockFile, UnlockFile, and LockFileEx. < > 32452 ** This function is not available on Windows CE or WinRT. 32338 */ 32453 */ 32339 32454 > 32455 #if SQLITE_OS_WINCE || SQLITE_OS_WINRT > 32456 # define osAreFileApisANSI() 1 32340 # define LockFile(a,b,c,d,e) winceLockFile(&a, b, c, d, e) | 32457 #endif 32341 # define UnlockFile(a,b,c,d,e) winceUnlockFile(&a, b, c, d, e) < 32342 # define LockFileEx(a,b,c,d,e,f) winceLockFileEx(&a, b, c, d, e, f) < 32343 32458 32344 /* 32459 /* > 32460 ** Many system calls are accessed through pointer-to-functions so that > 32461 ** they may be overridden at runtime to facilitate fault injection during 32345 ** These are the special syscall hacks for Windows CE. The locking related | 32462 ** testing and sandboxing. The following array holds the names and pointers 32346 ** defines here refer to the macros defined just above. | 32463 ** to all overrideable system calls. 32347 */ | 32464 */ 32348 < 32349 # define osAreFileApisANSI() 1 < 32350 # define osLockFile LockFile < 32351 # define osUnlockFile UnlockFile < 32352 # define osLockFileEx LockFileEx < 32353 #endif < 32354 < 32355 static struct win_syscall { 32465 static struct win_syscall { 32356 const char *zName; /* Name of the sytem call */ 32466 const char *zName; /* Name of the sytem call */ 32357 sqlite3_syscall_ptr pCurrent; /* Current value of the system call */ 32467 sqlite3_syscall_ptr pCurrent; /* Current value of the system call */ 32358 sqlite3_syscall_ptr pDefault; /* Default value */ 32468 sqlite3_syscall_ptr pDefault; /* Default value */ 32359 } aSyscall[] = { 32469 } aSyscall[] = { 32360 #if !SQLITE_OS_WINCE | 32470 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT 32361 { "AreFileApisANSI", (SYSCALL)AreFileApisANSI, 0 }, 32471 { "AreFileApisANSI", (SYSCALL)AreFileApisANSI, 0 }, 32362 < 32363 #define osAreFileApisANSI ((BOOL(WINAPI*)(VOID))aSyscall[0].pCurrent) < 32364 #else 32472 #else 32365 { "AreFileApisANSI", (SYSCALL)0, 0 }, 32473 { "AreFileApisANSI", (SYSCALL)0, 0 }, 32366 #endif 32474 #endif > 32475 > 32476 #ifndef osAreFileApisANSI > 32477 #define osAreFileApisANSI ((BOOL(WINAPI*)(VOID))aSyscall[0].pCurrent) > 32478 #endif 32367 32479 32368 #if SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE) 32480 #if SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE) 32369 { "CharLowerW", (SYSCALL)CharLowerW, 0 }, 32481 { "CharLowerW", (SYSCALL)CharLowerW, 0 }, 32370 #else 32482 #else 32371 { "CharLowerW", (SYSCALL)0, 0 }, 32483 { "CharLowerW", (SYSCALL)0, 0 }, 32372 #endif 32484 #endif 32373 32485 ................................................................................................................................................................................ 32390 #else 32502 #else 32391 { "CreateFileA", (SYSCALL)0, 0 }, 32503 { "CreateFileA", (SYSCALL)0, 0 }, 32392 #endif 32504 #endif 32393 32505 32394 #define osCreateFileA ((HANDLE(WINAPI*)(LPCSTR,DWORD,DWORD, \ 32506 #define osCreateFileA ((HANDLE(WINAPI*)(LPCSTR,DWORD,DWORD, \ 32395 LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[4].pCurrent) 32507 LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[4].pCurrent) 32396 32508 32397 #if defined(SQLITE_WIN32_HAS_WIDE) | 32509 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) 32398 { "CreateFileW", (SYSCALL)CreateFileW, 0 }, 32510 { "CreateFileW", (SYSCALL)CreateFileW, 0 }, 32399 #else 32511 #else 32400 { "CreateFileW", (SYSCALL)0, 0 }, 32512 { "CreateFileW", (SYSCALL)0, 0 }, 32401 #endif 32513 #endif 32402 32514 32403 #define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \ 32515 #define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \ 32404 LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent) 32516 LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent) 32405 32517 32406 { "CreateFileMapping", (SYSCALL)CreateFileMapping, 0 }, < 32407 < 32408 #define osCreateFileMapping ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \ < 32409 DWORD,DWORD,DWORD,LPCTSTR))aSyscall[6].pCurrent) < 32410 < 32411 #if defined(SQLITE_WIN32_HAS_WIDE) | 32518 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) 32412 { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 }, 32519 { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 }, 32413 #else 32520 #else 32414 { "CreateFileMappingW", (SYSCALL)0, 0 }, 32521 { "CreateFileMappingW", (SYSCALL)0, 0 }, 32415 #endif 32522 #endif 32416 32523 32417 #define osCreateFileMappingW ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \ 32524 #define osCreateFileMappingW ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \ 32418 DWORD,DWORD,DWORD,LPCWSTR))aSyscall[7].pCurrent) | 32525 DWORD,DWORD,DWORD,LPCWSTR))aSyscall[6].pCurrent) 32419 32526 32420 #if defined(SQLITE_WIN32_HAS_WIDE) | 32527 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) 32421 { "CreateMutexW", (SYSCALL)CreateMutexW, 0 }, 32528 { "CreateMutexW", (SYSCALL)CreateMutexW, 0 }, 32422 #else 32529 #else 32423 { "CreateMutexW", (SYSCALL)0, 0 }, 32530 { "CreateMutexW", (SYSCALL)0, 0 }, 32424 #endif 32531 #endif 32425 32532 32426 #define osCreateMutexW ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,BOOL, \ 32533 #define osCreateMutexW ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,BOOL, \ 32427 LPCWSTR))aSyscall[8].pCurrent) | 32534 LPCWSTR))aSyscall[7].pCurrent) 32428 32535 32429 #if defined(SQLITE_WIN32_HAS_ANSI) 32536 #if defined(SQLITE_WIN32_HAS_ANSI) 32430 { "DeleteFileA", (SYSCALL)DeleteFileA, 0 }, 32537 { "DeleteFileA", (SYSCALL)DeleteFileA, 0 }, 32431 #else 32538 #else 32432 { "DeleteFileA", (SYSCALL)0, 0 }, 32539 { "DeleteFileA", (SYSCALL)0, 0 }, 32433 #endif 32540 #endif 32434 32541 32435 #define osDeleteFileA ((BOOL(WINAPI*)(LPCSTR))aSyscall[9].pCurrent) | 32542 #define osDeleteFileA ((BOOL(WINAPI*)(LPCSTR))aSyscall[8].pCurrent) 32436 32543 32437 #if defined(SQLITE_WIN32_HAS_WIDE) 32544 #if defined(SQLITE_WIN32_HAS_WIDE) 32438 { "DeleteFileW", (SYSCALL)DeleteFileW, 0 }, 32545 { "DeleteFileW", (SYSCALL)DeleteFileW, 0 }, 32439 #else 32546 #else 32440 { "DeleteFileW", (SYSCALL)0, 0 }, 32547 { "DeleteFileW", (SYSCALL)0, 0 }, 32441 #endif 32548 #endif 32442 32549 32443 #define osDeleteFileW ((BOOL(WINAPI*)(LPCWSTR))aSyscall[10].pCurrent) | 32550 #define osDeleteFileW ((BOOL(WINAPI*)(LPCWSTR))aSyscall[9].pCurrent) 32444 32551 32445 #if SQLITE_OS_WINCE 32552 #if SQLITE_OS_WINCE 32446 { "FileTimeToLocalFileTime", (SYSCALL)FileTimeToLocalFileTime, 0 }, 32553 { "FileTimeToLocalFileTime", (SYSCALL)FileTimeToLocalFileTime, 0 }, 32447 #else 32554 #else 32448 { "FileTimeToLocalFileTime", (SYSCALL)0, 0 }, 32555 { "FileTimeToLocalFileTime", (SYSCALL)0, 0 }, 32449 #endif 32556 #endif 32450 32557 32451 #define osFileTimeToLocalFileTime ((BOOL(WINAPI*)(CONST FILETIME*, \ 32558 #define osFileTimeToLocalFileTime ((BOOL(WINAPI*)(CONST FILETIME*, \ 32452 LPFILETIME))aSyscall[11].pCurrent) | 32559 LPFILETIME))aSyscall[10].pCurrent) 32453 32560 32454 #if SQLITE_OS_WINCE 32561 #if SQLITE_OS_WINCE 32455 { "FileTimeToSystemTime", (SYSCALL)FileTimeToSystemTime, 0 }, 32562 { "FileTimeToSystemTime", (SYSCALL)FileTimeToSystemTime, 0 }, 32456 #else 32563 #else 32457 { "FileTimeToSystemTime", (SYSCALL)0, 0 }, 32564 { "FileTimeToSystemTime", (SYSCALL)0, 0 }, 32458 #endif 32565 #endif 32459 32566 32460 #define osFileTimeToSystemTime ((BOOL(WINAPI*)(CONST FILETIME*, \ 32567 #define osFileTimeToSystemTime ((BOOL(WINAPI*)(CONST FILETIME*, \ 32461 LPSYSTEMTIME))aSyscall[12].pCurrent) | 32568 LPSYSTEMTIME))aSyscall[11].pCurrent) 32462 32569 32463 { "FlushFileBuffers", (SYSCALL)FlushFileBuffers, 0 }, 32570 { "FlushFileBuffers", (SYSCALL)FlushFileBuffers, 0 }, 32464 32571 32465 #define osFlushFileBuffers ((BOOL(WINAPI*)(HANDLE))aSyscall[13].pCurrent) | 32572 #define osFlushFileBuffers ((BOOL(WINAPI*)(HANDLE))aSyscall[12].pCurrent) 32466 32573 32467 #if defined(SQLITE_WIN32_HAS_ANSI) 32574 #if defined(SQLITE_WIN32_HAS_ANSI) 32468 { "FormatMessageA", (SYSCALL)FormatMessageA, 0 }, 32575 { "FormatMessageA", (SYSCALL)FormatMessageA, 0 }, 32469 #else 32576 #else 32470 { "FormatMessageA", (SYSCALL)0, 0 }, 32577 { "FormatMessageA", (SYSCALL)0, 0 }, 32471 #endif 32578 #endif 32472 32579 32473 #define osFormatMessageA ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPSTR, \ 32580 #define osFormatMessageA ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPSTR, \ 32474 DWORD,va_list*))aSyscall[14].pCurrent) | 32581 DWORD,va_list*))aSyscall[13].pCurrent) 32475 32582 32476 #if defined(SQLITE_WIN32_HAS_WIDE) 32583 #if defined(SQLITE_WIN32_HAS_WIDE) 32477 { "FormatMessageW", (SYSCALL)FormatMessageW, 0 }, 32584 { "FormatMessageW", (SYSCALL)FormatMessageW, 0 }, 32478 #else 32585 #else 32479 { "FormatMessageW", (SYSCALL)0, 0 }, 32586 { "FormatMessageW", (SYSCALL)0, 0 }, 32480 #endif 32587 #endif 32481 32588 32482 #define osFormatMessageW ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPWSTR, \ 32589 #define osFormatMessageW ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPWSTR, \ 32483 DWORD,va_list*))aSyscall[15].pCurrent) | 32590 DWORD,va_list*))aSyscall[14].pCurrent) 32484 32591 32485 { "FreeLibrary", (SYSCALL)FreeLibrary, 0 }, 32592 { "FreeLibrary", (SYSCALL)FreeLibrary, 0 }, 32486 32593 32487 #define osFreeLibrary ((BOOL(WINAPI*)(HMODULE))aSyscall[16].pCurrent) | 32594 #define osFreeLibrary ((BOOL(WINAPI*)(HMODULE))aSyscall[15].pCurrent) 32488 32595 32489 { "GetCurrentProcessId", (SYSCALL)GetCurrentProcessId, 0 }, 32596 { "GetCurrentProcessId", (SYSCALL)GetCurrentProcessId, 0 }, 32490 32597 32491 #define osGetCurrentProcessId ((DWORD(WINAPI*)(VOID))aSyscall[17].pCurrent) | 32598 #define osGetCurrentProcessId ((DWORD(WINAPI*)(VOID))aSyscall[16].pCurrent) 32492 32599 32493 #if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_ANSI) 32600 #if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_ANSI) 32494 { "GetDiskFreeSpaceA", (SYSCALL)GetDiskFreeSpaceA, 0 }, 32601 { "GetDiskFreeSpaceA", (SYSCALL)GetDiskFreeSpaceA, 0 }, 32495 #else 32602 #else 32496 { "GetDiskFreeSpaceA", (SYSCALL)0, 0 }, 32603 { "GetDiskFreeSpaceA", (SYSCALL)0, 0 }, 32497 #endif 32604 #endif 32498 32605 32499 #define osGetDiskFreeSpaceA ((BOOL(WINAPI*)(LPCSTR,LPDWORD,LPDWORD,LPDWORD, \ 32606 #define osGetDiskFreeSpaceA ((BOOL(WINAPI*)(LPCSTR,LPDWORD,LPDWORD,LPDWORD, \ 32500 LPDWORD))aSyscall[18].pCurrent) | 32607 LPDWORD))aSyscall[17].pCurrent) 32501 32608 32502 #if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE) | 32609 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) 32503 { "GetDiskFreeSpaceW", (SYSCALL)GetDiskFreeSpaceW, 0 }, 32610 { "GetDiskFreeSpaceW", (SYSCALL)GetDiskFreeSpaceW, 0 }, 32504 #else 32611 #else 32505 { "GetDiskFreeSpaceW", (SYSCALL)0, 0 }, 32612 { "GetDiskFreeSpaceW", (SYSCALL)0, 0 }, 32506 #endif 32613 #endif 32507 32614 32508 #define osGetDiskFreeSpaceW ((BOOL(WINAPI*)(LPCWSTR,LPDWORD,LPDWORD,LPDWORD, \ 32615 #define osGetDiskFreeSpaceW ((BOOL(WINAPI*)(LPCWSTR,LPDWORD,LPDWORD,LPDWORD, \ 32509 LPDWORD))aSyscall[19].pCurrent) | 32616 LPDWORD))aSyscall[18].pCurrent) 32510 32617 32511 #if defined(SQLITE_WIN32_HAS_ANSI) 32618 #if defined(SQLITE_WIN32_HAS_ANSI) 32512 { "GetFileAttributesA", (SYSCALL)GetFileAttributesA, 0 }, 32619 { "GetFileAttributesA", (SYSCALL)GetFileAttributesA, 0 }, 32513 #else 32620 #else 32514 { "GetFileAttributesA", (SYSCALL)0, 0 }, 32621 { "GetFileAttributesA", (SYSCALL)0, 0 }, 32515 #endif 32622 #endif 32516 32623 32517 #define osGetFileAttributesA ((DWORD(WINAPI*)(LPCSTR))aSyscall[20].pCurrent) | 32624 #define osGetFileAttributesA ((DWORD(WINAPI*)(LPCSTR))aSyscall[19].pCurrent) 32518 32625 32519 #if defined(SQLITE_WIN32_HAS_WIDE) | 32626 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) 32520 { "GetFileAttributesW", (SYSCALL)GetFileAttributesW, 0 }, 32627 { "GetFileAttributesW", (SYSCALL)GetFileAttributesW, 0 }, 32521 #else 32628 #else 32522 { "GetFileAttributesW", (SYSCALL)0, 0 }, 32629 { "GetFileAttributesW", (SYSCALL)0, 0 }, 32523 #endif 32630 #endif 32524 32631 32525 #define osGetFileAttributesW ((DWORD(WINAPI*)(LPCWSTR))aSyscall[21].pCurrent) | 32632 #define osGetFileAttributesW ((DWORD(WINAPI*)(LPCWSTR))aSyscall[20].pCurrent) 32526 32633 32527 #if defined(SQLITE_WIN32_HAS_WIDE) 32634 #if defined(SQLITE_WIN32_HAS_WIDE) 32528 { "GetFileAttributesExW", (SYSCALL)GetFileAttributesExW, 0 }, 32635 { "GetFileAttributesExW", (SYSCALL)GetFileAttributesExW, 0 }, 32529 #else 32636 #else 32530 { "GetFileAttributesExW", (SYSCALL)0, 0 }, 32637 { "GetFileAttributesExW", (SYSCALL)0, 0 }, 32531 #endif 32638 #endif 32532 32639 32533 #define osGetFileAttributesExW ((BOOL(WINAPI*)(LPCWSTR,GET_FILEEX_INFO_LEVELS, \ 32640 #define osGetFileAttributesExW ((BOOL(WINAPI*)(LPCWSTR,GET_FILEEX_INFO_LEVELS, \ 32534 LPVOID))aSyscall[22].pCurrent) | 32641 LPVOID))aSyscall[21].pCurrent) 32535 32642 > 32643 #if !SQLITE_OS_WINRT 32536 { "GetFileSize", (SYSCALL)GetFileSize, 0 }, 32644 { "GetFileSize", (SYSCALL)GetFileSize, 0 }, > 32645 #else > 32646 { "GetFileSize", (SYSCALL)0, 0 }, > 32647 #endif 32537 32648 32538 #define osGetFileSize ((DWORD(WINAPI*)(HANDLE,LPDWORD))aSyscall[23].pCurrent) | 32649 #define osGetFileSize ((DWORD(WINAPI*)(HANDLE,LPDWORD))aSyscall[22].pCurrent) 32539 32650 32540 #if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_ANSI) 32651 #if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_ANSI) 32541 { "GetFullPathNameA", (SYSCALL)GetFullPathNameA, 0 }, 32652 { "GetFullPathNameA", (SYSCALL)GetFullPathNameA, 0 }, 32542 #else 32653 #else 32543 { "GetFullPathNameA", (SYSCALL)0, 0 }, 32654 { "GetFullPathNameA", (SYSCALL)0, 0 }, 32544 #endif 32655 #endif 32545 32656 32546 #define osGetFullPathNameA ((DWORD(WINAPI*)(LPCSTR,DWORD,LPSTR, \ 32657 #define osGetFullPathNameA ((DWORD(WINAPI*)(LPCSTR,DWORD,LPSTR, \ 32547 LPSTR*))aSyscall[24].pCurrent) | 32658 LPSTR*))aSyscall[23].pCurrent) 32548 32659 32549 #if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE) | 32660 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) 32550 { "GetFullPathNameW", (SYSCALL)GetFullPathNameW, 0 }, 32661 { "GetFullPathNameW", (SYSCALL)GetFullPathNameW, 0 }, 32551 #else 32662 #else 32552 { "GetFullPathNameW", (SYSCALL)0, 0 }, 32663 { "GetFullPathNameW", (SYSCALL)0, 0 }, 32553 #endif 32664 #endif 32554 32665 32555 #define osGetFullPathNameW ((DWORD(WINAPI*)(LPCWSTR,DWORD,LPWSTR, \ 32666 #define osGetFullPathNameW ((DWORD(WINAPI*)(LPCWSTR,DWORD,LPWSTR, \ 32556 LPWSTR*))aSyscall[25].pCurrent) | 32667 LPWSTR*))aSyscall[24].pCurrent) 32557 32668 32558 { "GetLastError", (SYSCALL)GetLastError, 0 }, 32669 { "GetLastError", (SYSCALL)GetLastError, 0 }, 32559 32670 32560 #define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[26].pCurrent) | 32671 #define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[25].pCurrent) 32561 32672 32562 #if SQLITE_OS_WINCE 32673 #if SQLITE_OS_WINCE 32563 /* The GetProcAddressA() routine is only available on Windows CE. */ 32674 /* The GetProcAddressA() routine is only available on Windows CE. */ 32564 { "GetProcAddressA", (SYSCALL)GetProcAddressA, 0 }, 32675 { "GetProcAddressA", (SYSCALL)GetProcAddressA, 0 }, 32565 #else 32676 #else 32566 /* All other Windows platforms expect GetProcAddress() to take 32677 /* All other Windows platforms expect GetProcAddress() to take 32567 ** an ANSI string regardless of the _UNICODE setting */ 32678 ** an ANSI string regardless of the _UNICODE setting */ 32568 { "GetProcAddressA", (SYSCALL)GetProcAddress, 0 }, 32679 { "GetProcAddressA", (SYSCALL)GetProcAddress, 0 }, 32569 #endif 32680 #endif 32570 32681 32571 #define osGetProcAddressA ((FARPROC(WINAPI*)(HMODULE, \ 32682 #define osGetProcAddressA ((FARPROC(WINAPI*)(HMODULE, \ 32572 LPCSTR))aSyscall[27].pCurrent) | 32683 LPCSTR))aSyscall[26].pCurrent) 32573 32684 > 32685 #if !SQLITE_OS_WINRT 32574 { "GetSystemInfo", (SYSCALL)GetSystemInfo, 0 }, 32686 { "GetSystemInfo", (SYSCALL)GetSystemInfo, 0 }, > 32687 #else > 32688 { "GetSystemInfo", (SYSCALL)0, 0 }, > 32689 #endif 32575 32690 32576 #define osGetSystemInfo ((VOID(WINAPI*)(LPSYSTEM_INFO))aSyscall[28].pCurrent) | 32691 #define osGetSystemInfo ((VOID(WINAPI*)(LPSYSTEM_INFO))aSyscall[27].pCurrent) 32577 32692 32578 { "GetSystemTime", (SYSCALL)GetSystemTime, 0 }, 32693 { "GetSystemTime", (SYSCALL)GetSystemTime, 0 }, 32579 32694 32580 #define osGetSystemTime ((VOID(WINAPI*)(LPSYSTEMTIME))aSyscall[29].pCurrent) | 32695 #define osGetSystemTime ((VOID(WINAPI*)(LPSYSTEMTIME))aSyscall[28].pCurrent) 32581 32696 32582 #if !SQLITE_OS_WINCE 32697 #if !SQLITE_OS_WINCE 32583 { "GetSystemTimeAsFileTime", (SYSCALL)GetSystemTimeAsFileTime, 0 }, 32698 { "GetSystemTimeAsFileTime", (SYSCALL)GetSystemTimeAsFileTime, 0 }, 32584 #else 32699 #else 32585 { "GetSystemTimeAsFileTime", (SYSCALL)0, 0 }, 32700 { "GetSystemTimeAsFileTime", (SYSCALL)0, 0 }, 32586 #endif 32701 #endif 32587 32702 32588 #define osGetSystemTimeAsFileTime ((VOID(WINAPI*)( \ 32703 #define osGetSystemTimeAsFileTime ((VOID(WINAPI*)( \ 32589 LPFILETIME))aSyscall[30].pCurrent) | 32704 LPFILETIME))aSyscall[29].pCurrent) 32590 32705 32591 #if defined(SQLITE_WIN32_HAS_ANSI) 32706 #if defined(SQLITE_WIN32_HAS_ANSI) 32592 { "GetTempPathA", (SYSCALL)GetTempPathA, 0 }, 32707 { "GetTempPathA", (SYSCALL)GetTempPathA, 0 }, 32593 #else 32708 #else 32594 { "GetTempPathA", (SYSCALL)0, 0 }, 32709 { "GetTempPathA", (SYSCALL)0, 0 }, 32595 #endif 32710 #endif 32596 32711 32597 #define osGetTempPathA ((DWORD(WINAPI*)(DWORD,LPSTR))aSyscall[31].pCurrent) | 32712 #define osGetTempPathA ((DWORD(WINAPI*)(DWORD,LPSTR))aSyscall[30].pCurrent) 32598 32713 32599 #if defined(SQLITE_WIN32_HAS_WIDE) | 32714 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) 32600 { "GetTempPathW", (SYSCALL)GetTempPathW, 0 }, 32715 { "GetTempPathW", (SYSCALL)GetTempPathW, 0 }, 32601 #else 32716 #else 32602 { "GetTempPathW", (SYSCALL)0, 0 }, 32717 { "GetTempPathW", (SYSCALL)0, 0 }, 32603 #endif 32718 #endif 32604 32719 32605 #define osGetTempPathW ((DWORD(WINAPI*)(DWORD,LPWSTR))aSyscall[32].pCurrent) | 32720 #define osGetTempPathW ((DWORD(WINAPI*)(DWORD,LPWSTR))aSyscall[31].pCurrent) 32606 32721 > 32722 #if !SQLITE_OS_WINRT 32607 { "GetTickCount", (SYSCALL)GetTickCount, 0 }, 32723 { "GetTickCount", (SYSCALL)GetTickCount, 0 }, > 32724 #else > 32725 { "GetTickCount", (SYSCALL)0, 0 }, > 32726 #endif 32608 32727 32609 #define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[33].pCurrent) | 32728 #define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[32].pCurrent) 32610 32729 32611 #if defined(SQLITE_WIN32_HAS_ANSI) 32730 #if defined(SQLITE_WIN32_HAS_ANSI) 32612 { "GetVersionExA", (SYSCALL)GetVersionExA, 0 }, 32731 { "GetVersionExA", (SYSCALL)GetVersionExA, 0 }, 32613 #else 32732 #else 32614 { "GetVersionExA", (SYSCALL)0, 0 }, 32733 { "GetVersionExA", (SYSCALL)0, 0 }, 32615 #endif 32734 #endif 32616 32735 32617 #define osGetVersionExA ((BOOL(WINAPI*)( \ 32736 #define osGetVersionExA ((BOOL(WINAPI*)( \ 32618 LPOSVERSIONINFOA))aSyscall[34].pCurrent) | 32737 LPOSVERSIONINFOA))aSyscall[33].pCurrent) 32619 32738 32620 { "HeapAlloc", (SYSCALL)HeapAlloc, 0 }, 32739 { "HeapAlloc", (SYSCALL)HeapAlloc, 0 }, 32621 32740 32622 #define osHeapAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD, \ 32741 #define osHeapAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD, \ 32623 SIZE_T))aSyscall[35].pCurrent) | 32742 SIZE_T))aSyscall[34].pCurrent) 32624 32743 > 32744 #if !SQLITE_OS_WINRT 32625 { "HeapCreate", (SYSCALL)HeapCreate, 0 }, 32745 { "HeapCreate", (SYSCALL)HeapCreate, 0 }, > 32746 #else > 32747 { "HeapCreate", (SYSCALL)0, 0 }, > 32748 #endif 32626 32749 32627 #define osHeapCreate ((HANDLE(WINAPI*)(DWORD,SIZE_T, \ 32750 #define osHeapCreate ((HANDLE(WINAPI*)(DWORD,SIZE_T, \ 32628 SIZE_T))aSyscall[36].pCurrent) | 32751 SIZE_T))aSyscall[35].pCurrent) 32629 32752 > 32753 #if !SQLITE_OS_WINRT 32630 { "HeapDestroy", (SYSCALL)HeapDestroy, 0 }, 32754 { "HeapDestroy", (SYSCALL)HeapDestroy, 0 }, > 32755 #else > 32756 { "HeapDestroy", (SYSCALL)0, 0 }, > 32757 #endif 32631 32758 32632 #define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[37].pCurrent) | 32759 #define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[36].pCurrent) 32633 32760 32634 { "HeapFree", (SYSCALL)HeapFree, 0 }, 32761 { "HeapFree", (SYSCALL)HeapFree, 0 }, 32635 32762 32636 #define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[38].pCurrent) | 32763 #define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[37].pCurrent) 32637 32764 32638 { "HeapReAlloc", (SYSCALL)HeapReAlloc, 0 }, 32765 { "HeapReAlloc", (SYSCALL)HeapReAlloc, 0 }, 32639 32766 32640 #define osHeapReAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD,LPVOID, \ 32767 #define osHeapReAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD,LPVOID, \ 32641 SIZE_T))aSyscall[39].pCurrent) | 32768 SIZE_T))aSyscall[38].pCurrent) 32642 32769 32643 { "HeapSize", (SYSCALL)HeapSize, 0 }, 32770 { "HeapSize", (SYSCALL)HeapSize, 0 }, 32644 32771 32645 #define osHeapSize ((SIZE_T(WINAPI*)(HANDLE,DWORD, \ 32772 #define osHeapSize ((SIZE_T(WINAPI*)(HANDLE,DWORD, \ 32646 LPCVOID))aSyscall[40].pCurrent) | 32773 LPCVOID))aSyscall[39].pCurrent) 32647 32774 > 32775 #if !SQLITE_OS_WINRT 32648 { "HeapValidate", (SYSCALL)HeapValidate, 0 }, 32776 { "HeapValidate", (SYSCALL)HeapValidate, 0 }, > 32777 #else > 32778 { "HeapValidate", (SYSCALL)0, 0 }, > 32779 #endif 32649 32780 32650 #define osHeapValidate ((BOOL(WINAPI*)(HANDLE,DWORD, \ 32781 #define osHeapValidate ((BOOL(WINAPI*)(HANDLE,DWORD, \ 32651 LPCVOID))aSyscall[41].pCurrent) | 32782 LPCVOID))aSyscall[40].pCurrent) 32652 32783 32653 #if defined(SQLITE_WIN32_HAS_ANSI) 32784 #if defined(SQLITE_WIN32_HAS_ANSI) 32654 { "LoadLibraryA", (SYSCALL)LoadLibraryA, 0 }, 32785 { "LoadLibraryA", (SYSCALL)LoadLibraryA, 0 }, 32655 #else 32786 #else 32656 { "LoadLibraryA", (SYSCALL)0, 0 }, 32787 { "LoadLibraryA", (SYSCALL)0, 0 }, 32657 #endif 32788 #endif 32658 32789 32659 #define osLoadLibraryA ((HMODULE(WINAPI*)(LPCSTR))aSyscall[42].pCurrent) | 32790 #define osLoadLibraryA ((HMODULE(WINAPI*)(LPCSTR))aSyscall[41].pCurrent) 32660 32791 32661 #if defined(SQLITE_WIN32_HAS_WIDE) | 32792 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) 32662 { "LoadLibraryW", (SYSCALL)LoadLibraryW, 0 }, 32793 { "LoadLibraryW", (SYSCALL)LoadLibraryW, 0 }, 32663 #else 32794 #else 32664 { "LoadLibraryW", (SYSCALL)0, 0 }, 32795 { "LoadLibraryW", (SYSCALL)0, 0 }, 32665 #endif 32796 #endif 32666 32797 32667 #define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[43].pCurrent) | 32798 #define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[42].pCurrent) 32668 32799 > 32800 #if !SQLITE_OS_WINRT 32669 { "LocalFree", (SYSCALL)LocalFree, 0 }, 32801 { "LocalFree", (SYSCALL)LocalFree, 0 }, > 32802 #else > 32803 { "LocalFree", (SYSCALL)0, 0 }, > 32804 #endif 32670 32805 32671 #define osLocalFree ((HLOCAL(WINAPI*)(HLOCAL))aSyscall[44].pCurrent) | 32806 #define osLocalFree ((HLOCAL(WINAPI*)(HLOCAL))aSyscall[43].pCurrent) 32672 32807 32673 #if !SQLITE_OS_WINCE | 32808 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT 32674 { "LockFile", (SYSCALL)LockFile, 0 }, 32809 { "LockFile", (SYSCALL)LockFile, 0 }, 32675 < 32676 #define osLockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \ < 32677 DWORD))aSyscall[45].pCurrent) < 32678 #else 32810 #else 32679 { "LockFile", (SYSCALL)0, 0 }, 32811 { "LockFile", (SYSCALL)0, 0 }, 32680 #endif 32812 #endif > 32813 > 32814 #ifndef osLockFile > 32815 #define osLockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \ > 32816 DWORD))aSyscall[44].pCurrent) > 32817 #endif 32681 32818 32682 #if !SQLITE_OS_WINCE 32819 #if !SQLITE_OS_WINCE 32683 { "LockFileEx", (SYSCALL)LockFileEx, 0 }, 32820 { "LockFileEx", (SYSCALL)LockFileEx, 0 }, 32684 < 32685 #define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \ < 32686 LPOVERLAPPED))aSyscall[46].pCurrent) < 32687 #else 32821 #else 32688 { "LockFileEx", (SYSCALL)0, 0 }, 32822 { "LockFileEx", (SYSCALL)0, 0 }, 32689 #endif 32823 #endif 32690 32824 > 32825 #ifndef osLockFileEx > 32826 #define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \ > 32827 LPOVERLAPPED))aSyscall[45].pCurrent) > 32828 #endif > 32829 > 32830 #if !SQLITE_OS_WINRT 32691 { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 }, 32831 { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 }, > 32832 #else > 32833 { "MapViewOfFile", (SYSCALL)0, 0 }, > 32834 #endif 32692 32835 32693 #define osMapViewOfFile ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \ 32836 #define osMapViewOfFile ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \ 32694 SIZE_T))aSyscall[47].pCurrent) | 32837 SIZE_T))aSyscall[46].pCurrent) 32695 32838 32696 { "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 }, 32839 { "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 }, 32697 32840 32698 #define osMultiByteToWideChar ((int(WINAPI*)(UINT,DWORD,LPCSTR,int,LPWSTR, \ 32841 #define osMultiByteToWideChar ((int(WINAPI*)(UINT,DWORD,LPCSTR,int,LPWSTR, \ 32699 int))aSyscall[48].pCurrent) | 32842 int))aSyscall[47].pCurrent) 32700 32843 32701 { "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 }, 32844 { "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 }, 32702 32845 32703 #define osQueryPerformanceCounter ((BOOL(WINAPI*)( \ 32846 #define osQueryPerformanceCounter ((BOOL(WINAPI*)( \ 32704 LARGE_INTEGER*))aSyscall[49].pCurrent) | 32847 LARGE_INTEGER*))aSyscall[48].pCurrent) 32705 32848 32706 { "ReadFile", (SYSCALL)ReadFile, 0 }, 32849 { "ReadFile", (SYSCALL)ReadFile, 0 }, 32707 32850 32708 #define osReadFile ((BOOL(WINAPI*)(HANDLE,LPVOID,DWORD,LPDWORD, \ 32851 #define osReadFile ((BOOL(WINAPI*)(HANDLE,LPVOID,DWORD,LPDWORD, \ 32709 LPOVERLAPPED))aSyscall[50].pCurrent) | 32852 LPOVERLAPPED))aSyscall[49].pCurrent) 32710 32853 32711 { "SetEndOfFile", (SYSCALL)SetEndOfFile, 0 }, 32854 { "SetEndOfFile", (SYSCALL)SetEndOfFile, 0 }, 32712 32855 32713 #define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[51].pCurrent) | 32856 #define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[50].pCurrent) 32714 32857 > 32858 #if !SQLITE_OS_WINRT 32715 { "SetFilePointer", (SYSCALL)SetFilePointer, 0 }, 32859 { "SetFilePointer", (SYSCALL)SetFilePointer, 0 }, > 32860 #else > 32861 { "SetFilePointer", (SYSCALL)0, 0 }, > 32862 #endif 32716 32863 32717 #define osSetFilePointer ((DWORD(WINAPI*)(HANDLE,LONG,PLONG, \ 32864 #define osSetFilePointer ((DWORD(WINAPI*)(HANDLE,LONG,PLONG, \ 32718 DWORD))aSyscall[52].pCurrent) | 32865 DWORD))aSyscall[51].pCurrent) 32719 32866 > 32867 #if !SQLITE_OS_WINRT 32720 { "Sleep", (SYSCALL)Sleep, 0 }, 32868 { "Sleep", (SYSCALL)Sleep, 0 }, > 32869 #else > 32870 { "Sleep", (SYSCALL)0, 0 }, > 32871 #endif 32721 32872 32722 #define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[53].pCurrent) | 32873 #define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[52].pCurrent) 32723 32874 32724 { "SystemTimeToFileTime", (SYSCALL)SystemTimeToFileTime, 0 }, 32875 { "SystemTimeToFileTime", (SYSCALL)SystemTimeToFileTime, 0 }, 32725 32876 32726 #define osSystemTimeToFileTime ((BOOL(WINAPI*)(CONST SYSTEMTIME*, \ 32877 #define osSystemTimeToFileTime ((BOOL(WINAPI*)(CONST SYSTEMTIME*, \ 32727 LPFILETIME))aSyscall[54].pCurrent) | 32878 LPFILETIME))aSyscall[53].pCurrent) 32728 32879 32729 #if !SQLITE_OS_WINCE | 32880 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT 32730 { "UnlockFile", (SYSCALL)UnlockFile, 0 }, 32881 { "UnlockFile", (SYSCALL)UnlockFile, 0 }, 32731 < 32732 #define osUnlockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \ < 32733 DWORD))aSyscall[55].pCurrent) < 32734 #else 32882 #else 32735 { "UnlockFile", (SYSCALL)0, 0 }, 32883 { "UnlockFile", (SYSCALL)0, 0 }, 32736 #endif 32884 #endif > 32885 > 32886 #ifndef osUnlockFile > 32887 #define osUnlockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \ > 32888 DWORD))aSyscall[54].pCurrent) > 32889 #endif 32737 32890 32738 #if !SQLITE_OS_WINCE 32891 #if !SQLITE_OS_WINCE 32739 { "UnlockFileEx", (SYSCALL)UnlockFileEx, 0 }, 32892 { "UnlockFileEx", (SYSCALL)UnlockFileEx, 0 }, 32740 < 32741 #define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \ < 32742 LPOVERLAPPED))aSyscall[56].pCurrent) < 32743 #else 32893 #else 32744 { "UnlockFileEx", (SYSCALL)0, 0 }, 32894 { "UnlockFileEx", (SYSCALL)0, 0 }, 32745 #endif 32895 #endif > 32896 > 32897 #define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \ > 32898 LPOVERLAPPED))aSyscall[55].pCurrent) 32746 32899 32747 { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 }, 32900 { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 }, 32748 32901 32749 #define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[57].pCurrent) | 32902 #define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[56].pCurrent) 32750 32903 32751 { "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 }, 32904 { "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 }, 32752 32905 32753 #define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \ 32906 #define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \ 32754 LPCSTR,LPBOOL))aSyscall[58].pCurrent) | 32907 LPCSTR,LPBOOL))aSyscall[57].pCurrent) 32755 32908 32756 { "WriteFile", (SYSCALL)WriteFile, 0 }, 32909 { "WriteFile", (SYSCALL)WriteFile, 0 }, 32757 32910 32758 #define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \ 32911 #define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \ > 32912 LPOVERLAPPED))aSyscall[58].pCurrent) > 32913 > 32914 #if SQLITE_OS_WINRT > 32915 { "CreateEventExW", (SYSCALL)CreateEventExW, 0 }, > 32916 #else > 32917 { "CreateEventExW", (SYSCALL)0, 0 }, > 32918 #endif > 32919 > 32920 #define osCreateEventExW ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,LPCWSTR, \ 32759 LPOVERLAPPED))aSyscall[59].pCurrent) | 32921 DWORD,DWORD))aSyscall[59].pCurrent) > 32922 > 32923 #if !SQLITE_OS_WINRT > 32924 { "WaitForSingleObject", (SYSCALL)WaitForSingleObject, 0 }, > 32925 #else > 32926 { "WaitForSingleObject", (SYSCALL)0, 0 }, > 32927 #endif > 32928 > 32929 #define osWaitForSingleObject ((DWORD(WINAPI*)(HANDLE, \ > 32930 DWORD))aSyscall[60].pCurrent) > 32931 > 32932 #if !SQLITE_OS_WINCE > 32933 { "WaitForSingleObjectEx", (SYSCALL)WaitForSingleObjectEx, 0 }, > 32934 #else > 32935 { "WaitForSingleObjectEx", (SYSCALL)0, 0 }, > 32936 #endif > 32937 > 32938 #define osWaitForSingleObjectEx ((DWORD(WINAPI*)(HANDLE,DWORD, \ > 32939 BOOL))aSyscall[61].pCurrent) > 32940 > 32941 #if !SQLITE_OS_WINCE > 32942 { "SetFilePointerEx", (SYSCALL)SetFilePointerEx, 0 }, > 32943 #else > 32944 { "SetFilePointerEx", (SYSCALL)0, 0 }, > 32945 #endif > 32946 > 32947 #define osSetFilePointerEx ((BOOL(WINAPI*)(HANDLE,LARGE_INTEGER, \ > 32948 PLARGE_INTEGER,DWORD))aSyscall[62].pCurrent) > 32949 > 32950 #if SQLITE_OS_WINRT > 32951 { "GetFileInformationByHandleEx", (SYSCALL)GetFileInformationByHandleEx, 0 }, > 32952 #else > 32953 { "GetFileInformationByHandleEx", (SYSCALL)0, 0 }, > 32954 #endif > 32955 > 32956 #define osGetFileInformationByHandleEx ((BOOL(WINAPI*)(HANDLE, \ > 32957 FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[63].pCurrent) > 32958 > 32959 #if SQLITE_OS_WINRT > 32960 { "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 }, > 32961 #else > 32962 { "MapViewOfFileFromApp", (SYSCALL)0, 0 }, > 32963 #endif > 32964 > 32965 #define osMapViewOfFileFromApp ((LPVOID(WINAPI*)(HANDLE,ULONG,ULONG64, \ > 32966 SIZE_T))aSyscall[64].pCurrent) > 32967 > 32968 #if SQLITE_OS_WINRT > 32969 { "CreateFile2", (SYSCALL)CreateFile2, 0 }, > 32970 #else > 32971 { "CreateFile2", (SYSCALL)0, 0 }, > 32972 #endif > 32973 > 32974 #define osCreateFile2 ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD,DWORD, \ > 32975 LPCREATEFILE2_EXTENDED_PARAMETERS))aSyscall[65].pCurrent) > 32976 > 32977 #if SQLITE_OS_WINRT > 32978 { "LoadPackagedLibrary", (SYSCALL)LoadPackagedLibrary, 0 }, > 32979 #else > 32980 { "LoadPackagedLibrary", (SYSCALL)0, 0 }, > 32981 #endif > 32982 > 32983 #define osLoadPackagedLibrary ((HMODULE(WINAPI*)(LPCWSTR, \ > 32984 DWORD))aSyscall[66].pCurrent) > 32985 > 32986 #if SQLITE_OS_WINRT > 32987 { "GetTickCount64", (SYSCALL)GetTickCount64, 0 }, > 32988 #else > 32989 { "GetTickCount64", (SYSCALL)0, 0 }, > 32990 #endif > 32991 > 32992 #define osGetTickCount64 ((ULONGLONG(WINAPI*)(VOID))aSyscall[67].pCurrent) > 32993 > 32994 #if SQLITE_OS_WINRT > 32995 { "GetNativeSystemInfo", (SYSCALL)GetNativeSystemInfo, 0 }, > 32996 #else > 32997 { "GetNativeSystemInfo", (SYSCALL)0, 0 }, > 32998 #endif > 32999 > 33000 #define osGetNativeSystemInfo ((VOID(WINAPI*)( \ > 33001 LPSYSTEM_INFO))aSyscall[68].pCurrent) > 33002 > 33003 #if defined(SQLITE_WIN32_HAS_ANSI) > 33004 { "OutputDebugStringA", (SYSCALL)OutputDebugStringA, 0 }, > 33005 #else > 33006 { "OutputDebugStringA", (SYSCALL)0, 0 }, > 33007 #endif > 33008 > 33009 #define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[69].pCurrent) > 33010 > 33011 #if defined(SQLITE_WIN32_HAS_WIDE) > 33012 { "OutputDebugStringW", (SYSCALL)OutputDebugStringW, 0 }, > 33013 #else > 33014 { "OutputDebugStringW", (SYSCALL)0, 0 }, > 33015 #endif > 33016 > 33017 #define osOutputDebugStringW ((VOID(WINAPI*)(LPCWSTR))aSyscall[70].pCurrent) > 33018 > 33019 { "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 }, > 33020 > 33021 #define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[71].pCurrent) > 33022 > 33023 #if SQLITE_OS_WINRT > 33024 { "CreateFileMappingFromApp", (SYSCALL)CreateFileMappingFromApp, 0 }, > 33025 #else > 33026 { "CreateFileMappingFromApp", (SYSCALL)0, 0 }, > 33027 #endif > 33028 > 33029 #define osCreateFileMappingFromApp ((HANDLE(WINAPI*)(HANDLE, \ > 33030 LPSECURITY_ATTRIBUTES,ULONG,ULONG64,LPCWSTR))aSyscall[72].pCurrent) 32760 33031 32761 }; /* End of the overrideable system calls */ 33032 }; /* End of the overrideable system calls */ 32762 33033 32763 /* 33034 /* 32764 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the 33035 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the 32765 ** "win32" VFSes. Return SQLITE_OK opon successfully updating the 33036 ** "win32" VFSes. Return SQLITE_OK opon successfully updating the 32766 ** system call pointer, or SQLITE_NOTFOUND if there is no configurable 33037 ** system call pointer, or SQLITE_NOTFOUND if there is no configurable ................................................................................................................................................................................ 32838 } 33109 } 32839 } 33110 } 32840 for(i++; i<ArraySize(aSyscall); i++){ 33111 for(i++; i<ArraySize(aSyscall); i++){ 32841 if( aSyscall[i].pCurrent!=0 ) return aSyscall[i].zName; 33112 if( aSyscall[i].pCurrent!=0 ) return aSyscall[i].zName; 32842 } 33113 } 32843 return 0; 33114 return 0; 32844 } 33115 } > 33116 > 33117 /* > 33118 ** This function outputs the specified (ANSI) string to the Win32 debugger > 33119 ** (if available). > 33120 */ > 33121 > 33122 SQLITE_API void sqlite3_win32_write_debug(char *zBuf, int nBuf){ > 33123 char zDbgBuf[SQLITE_WIN32_DBG_BUF_SIZE]; > 33124 int nMin = MIN(nBuf, (SQLITE_WIN32_DBG_BUF_SIZE - 1)); /* may be negative. */ > 33125 if( nMin<-1 ) nMin = -1; /* all negative values become -1. */ > 33126 assert( nMin==-1 || nMin==0 || nMin<SQLITE_WIN32_DBG_BUF_SIZE ); > 33127 #if defined(SQLITE_WIN32_HAS_ANSI) > 33128 if( nMin>0 ){ > 33129 memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE); > 33130 memcpy(zDbgBuf, zBuf, nMin); > 33131 osOutputDebugStringA(zDbgBuf); > 33132 }else{ > 33133 osOutputDebugStringA(zBuf); > 33134 } > 33135 #elif defined(SQLITE_WIN32_HAS_WIDE) > 33136 memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE); > 33137 if ( osMultiByteToWideChar( > 33138 osAreFileApisANSI() ? CP_ACP : CP_OEMCP, 0, zBuf, > 33139 nMin, (LPWSTR)zDbgBuf, SQLITE_WIN32_DBG_BUF_SIZE/sizeof(WCHAR))<=0 ){ > 33140 return; > 33141 } > 33142 osOutputDebugStringW((LPCWSTR)zDbgBuf); > 33143 #else > 33144 if( nMin>0 ){ > 33145 memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE); > 33146 memcpy(zDbgBuf, zBuf, nMin); > 33147 fprintf(stderr, "%s", zDbgBuf); > 33148 }else{ > 33149 fprintf(stderr, "%s", zBuf); > 33150 } > 33151 #endif > 33152 } > 33153 > 33154 /* > 33155 ** The following routine suspends the current thread for at least ms > 33156 ** milliseconds. This is equivalent to the Win32 Sleep() interface. > 33157 */ > 33158 #if SQLITE_OS_WINRT > 33159 static HANDLE sleepObj = NULL; > 33160 #endif > 33161 > 33162 SQLITE_API void sqlite3_win32_sleep(DWORD milliseconds){ > 33163 #if SQLITE_OS_WINRT > 33164 if ( sleepObj==NULL ){ > 33165 sleepObj = osCreateEventExW(NULL, NULL, CREATE_EVENT_MANUAL_RESET, > 33166 SYNCHRONIZE); > 33167 } > 33168 assert( sleepObj!=NULL ); > 33169 osWaitForSingleObjectEx(sleepObj, milliseconds, FALSE); > 33170 #else > 33171 osSleep(milliseconds); > 33172 #endif > 33173 } 32845 33174 32846 /* 33175 /* 32847 ** Return true (non-zero) if we are running under WinNT, Win2K, WinXP, 33176 ** Return true (non-zero) if we are running under WinNT, Win2K, WinXP, 32848 ** or WinCE. Return false (zero) for Win95, Win98, or WinME. 33177 ** or WinCE. Return false (zero) for Win95, Win98, or WinME. 32849 ** 33178 ** 32850 ** Here is an interesting observation: Win95, Win98, and WinME lack 33179 ** Here is an interesting observation: Win95, Win98, and WinME lack 32851 ** the LockFileEx() API. But we can still statically link against that 33180 ** the LockFileEx() API. But we can still statically link against that 32852 ** API as long as we don't call it when running Win95/98/ME. A call to 33181 ** API as long as we don't call it when running Win95/98/ME. A call to 32853 ** this routine is used to determine if the host is Win95/98/ME or 33182 ** this routine is used to determine if the host is Win95/98/ME or 32854 ** WinNT/2K/XP so that we will know whether or not we can safely call 33183 ** WinNT/2K/XP so that we will know whether or not we can safely call 32855 ** the LockFileEx() API. 33184 ** the LockFileEx() API. 32856 */ 33185 */ 32857 #if SQLITE_OS_WINCE | 33186 #if SQLITE_OS_WINCE || SQLITE_OS_WINRT 32858 # define isNT() (1) 33187 # define isNT() (1) 32859 #else 33188 #else 32860 static int isNT(void){ 33189 static int isNT(void){ 32861 if( sqlite3_os_type==0 ){ 33190 if( sqlite3_os_type==0 ){ 32862 OSVERSIONINFOA sInfo; 33191 OSVERSIONINFOA sInfo; 32863 sInfo.dwOSVersionInfoSize = sizeof(sInfo); 33192 sInfo.dwOSVersionInfoSize = sizeof(sInfo); 32864 osGetVersionExA(&sInfo); 33193 osGetVersionExA(&sInfo); ................................................................................................................................................................................ 32876 HANDLE hHeap; 33205 HANDLE hHeap; 32877 void *p; 33206 void *p; 32878 33207 32879 winMemAssertMagic(); 33208 winMemAssertMagic(); 32880 hHeap = winMemGetHeap(); 33209 hHeap = winMemGetHeap(); 32881 assert( hHeap!=0 ); 33210 assert( hHeap!=0 ); 32882 assert( hHeap!=INVALID_HANDLE_VALUE ); 33211 assert( hHeap!=INVALID_HANDLE_VALUE ); 32883 #ifdef SQLITE_WIN32_MALLOC_VALIDATE | 33212 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE) 32884 assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) ); 33213 assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) ); 32885 #endif 33214 #endif 32886 assert( nBytes>=0 ); 33215 assert( nBytes>=0 ); 32887 p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes); 33216 p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes); 32888 if( !p ){ 33217 if( !p ){ 32889 sqlite3_log(SQLITE_NOMEM, "failed to HeapAlloc %u bytes (%d), heap=%p", 33218 sqlite3_log(SQLITE_NOMEM, "failed to HeapAlloc %u bytes (%d), heap=%p", 32890 nBytes, osGetLastError(), (void*)hHeap); 33219 nBytes, osGetLastError(), (void*)hHeap); ................................................................................................................................................................................ 32898 static void winMemFree(void *pPrior){ 33227 static void winMemFree(void *pPrior){ 32899 HANDLE hHeap; 33228 HANDLE hHeap; 32900 33229 32901 winMemAssertMagic(); 33230 winMemAssertMagic(); 32902 hHeap = winMemGetHeap(); 33231 hHeap = winMemGetHeap(); 32903 assert( hHeap!=0 ); 33232 assert( hHeap!=0 ); 32904 assert( hHeap!=INVALID_HANDLE_VALUE ); 33233 assert( hHeap!=INVALID_HANDLE_VALUE ); 32905 #ifdef SQLITE_WIN32_MALLOC_VALIDATE | 33234 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE) 32906 assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ); 33235 assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ); 32907 #endif 33236 #endif 32908 if( !pPrior ) return; /* Passing NULL to HeapFree is undefined. */ 33237 if( !pPrior ) return; /* Passing NULL to HeapFree is undefined. */ 32909 if( !osHeapFree(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ){ 33238 if( !osHeapFree(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ){ 32910 sqlite3_log(SQLITE_NOMEM, "failed to HeapFree block %p (%d), heap=%p", 33239 sqlite3_log(SQLITE_NOMEM, "failed to HeapFree block %p (%d), heap=%p", 32911 pPrior, osGetLastError(), (void*)hHeap); 33240 pPrior, osGetLastError(), (void*)hHeap); 32912 } 33241 } ................................................................................................................................................................................ 32919 HANDLE hHeap; 33248 HANDLE hHeap; 32920 void *p; 33249 void *p; 32921 33250 32922 winMemAssertMagic(); 33251 winMemAssertMagic(); 32923 hHeap = winMemGetHeap(); 33252 hHeap = winMemGetHeap(); 32924 assert( hHeap!=0 ); 33253 assert( hHeap!=0 ); 32925 assert( hHeap!=INVALID_HANDLE_VALUE ); 33254 assert( hHeap!=INVALID_HANDLE_VALUE ); 32926 #ifdef SQLITE_WIN32_MALLOC_VALIDATE | 33255 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE) 32927 assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ); 33256 assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ); 32928 #endif 33257 #endif 32929 assert( nBytes>=0 ); 33258 assert( nBytes>=0 ); 32930 if( !pPrior ){ 33259 if( !pPrior ){ 32931 p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes); 33260 p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes); 32932 }else{ 33261 }else{ 32933 p = osHeapReAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior, (SIZE_T)nBytes); 33262 p = osHeapReAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior, (SIZE_T)nBytes); ................................................................................................................................................................................ 32947 HANDLE hHeap; 33276 HANDLE hHeap; 32948 SIZE_T n; 33277 SIZE_T n; 32949 33278 32950 winMemAssertMagic(); 33279 winMemAssertMagic(); 32951 hHeap = winMemGetHeap(); 33280 hHeap = winMemGetHeap(); 32952 assert( hHeap!=0 ); 33281 assert( hHeap!=0 ); 32953 assert( hHeap!=INVALID_HANDLE_VALUE ); 33282 assert( hHeap!=INVALID_HANDLE_VALUE ); 32954 #ifdef SQLITE_WIN32_MALLOC_VALIDATE | 33283 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE) 32955 assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) ); 33284 assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) ); 32956 #endif 33285 #endif 32957 if( !p ) return 0; 33286 if( !p ) return 0; 32958 n = osHeapSize(hHeap, SQLITE_WIN32_HEAP_FLAGS, p); 33287 n = osHeapSize(hHeap, SQLITE_WIN32_HEAP_FLAGS, p); 32959 if( n==(SIZE_T)-1 ){ 33288 if( n==(SIZE_T)-1 ){ 32960 sqlite3_log(SQLITE_NOMEM, "failed to HeapSize block %p (%d), heap=%p", 33289 sqlite3_log(SQLITE_NOMEM, "failed to HeapSize block %p (%d), heap=%p", 32961 p, osGetLastError(), (void*)hHeap); 33290 p, osGetLastError(), (void*)hHeap); ................................................................................................................................................................................ 32975 ** Initialize this module. 33304 ** Initialize this module. 32976 */ 33305 */ 32977 static int winMemInit(void *pAppData){ 33306 static int winMemInit(void *pAppData){ 32978 winMemData *pWinMemData = (winMemData *)pAppData; 33307 winMemData *pWinMemData = (winMemData *)pAppData; 32979 33308 32980 if( !pWinMemData ) return SQLITE_ERROR; 33309 if( !pWinMemData ) return SQLITE_ERROR; 32981 assert( pWinMemData->magic==WINMEM_MAGIC ); 33310 assert( pWinMemData->magic==WINMEM_MAGIC ); > 33311 > 33312 #if !SQLITE_OS_WINRT && SQLITE_WIN32_HEAP_CREATE 32982 if( !pWinMemData->hHeap ){ 33313 if( !pWinMemData->hHeap ){ 32983 pWinMemData->hHeap = osHeapCreate(SQLITE_WIN32_HEAP_FLAGS, 33314 pWinMemData->hHeap = osHeapCreate(SQLITE_WIN32_HEAP_FLAGS, 32984 SQLITE_WIN32_HEAP_INIT_SIZE, 33315 SQLITE_WIN32_HEAP_INIT_SIZE, 32985 SQLITE_WIN32_HEAP_MAX_SIZE); 33316 SQLITE_WIN32_HEAP_MAX_SIZE); 32986 if( !pWinMemData->hHeap ){ 33317 if( !pWinMemData->hHeap ){ 32987 sqlite3_log(SQLITE_NOMEM, 33318 sqlite3_log(SQLITE_NOMEM, 32988 "failed to HeapCreate (%d), flags=%u, initSize=%u, maxSize=%u", 33319 "failed to HeapCreate (%d), flags=%u, initSize=%u, maxSize=%u", 32989 osGetLastError(), SQLITE_WIN32_HEAP_FLAGS, 33320 osGetLastError(), SQLITE_WIN32_HEAP_FLAGS, 32990 SQLITE_WIN32_HEAP_INIT_SIZE, SQLITE_WIN32_HEAP_MAX_SIZE); 33321 SQLITE_WIN32_HEAP_INIT_SIZE, SQLITE_WIN32_HEAP_MAX_SIZE); 32991 return SQLITE_NOMEM; 33322 return SQLITE_NOMEM; 32992 } 33323 } 32993 pWinMemData->bOwned = TRUE; 33324 pWinMemData->bOwned = TRUE; > 33325 assert( pWinMemData->bOwned ); 32994 } 33326 } > 33327 #else > 33328 pWinMemData->hHeap = osGetProcessHeap(); > 33329 if( !pWinMemData->hHeap ){ > 33330 sqlite3_log(SQLITE_NOMEM, > 33331 "failed to GetProcessHeap (%d)", osGetLastError()); > 33332 return SQLITE_NOMEM; > 33333 } > 33334 pWinMemData->bOwned = FALSE; > 33335 assert( !pWinMemData->bOwned ); > 33336 #endif 32995 assert( pWinMemData->hHeap!=0 ); 33337 assert( pWinMemData->hHeap!=0 ); 32996 assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE ); 33338 assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE ); 32997 #ifdef SQLITE_WIN32_MALLOC_VALIDATE | 33339 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE) 32998 assert( osHeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) ); 33340 assert( osHeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) ); 32999 #endif 33341 #endif 33000 return SQLITE_OK; 33342 return SQLITE_OK; 33001 } 33343 } 33002 33344 33003 /* 33345 /* 33004 ** Deinitialize this module. 33346 ** Deinitialize this module. ................................................................................................................................................................................ 33005 */ 33347 */ 33006 static void winMemShutdown(void *pAppData){ 33348 static void winMemShutdown(void *pAppData){ 33007 winMemData *pWinMemData = (winMemData *)pAppData; 33349 winMemData *pWinMemData = (winMemData *)pAppData; 33008 33350 33009 if( !pWinMemData ) return; 33351 if( !pWinMemData ) return; 33010 if( pWinMemData->hHeap ){ 33352 if( pWinMemData->hHeap ){ 33011 assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE ); 33353 assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE ); 33012 #ifdef SQLITE_WIN32_MALLOC_VALIDATE | 33354 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE) 33013 assert( osHeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) ); 33355 assert( osHeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) ); 33014 #endif 33356 #endif 33015 if( pWinMemData->bOwned ){ 33357 if( pWinMemData->bOwned ){ 33016 if( !osHeapDestroy(pWinMemData->hHeap) ){ 33358 if( !osHeapDestroy(pWinMemData->hHeap) ){ 33017 sqlite3_log(SQLITE_NOMEM, "failed to HeapDestroy (%d), heap=%p", 33359 sqlite3_log(SQLITE_NOMEM, "failed to HeapDestroy (%d), heap=%p", 33018 osGetLastError(), (void*)pWinMemData->hHeap); 33360 osGetLastError(), (void*)pWinMemData->hHeap); 33019 } 33361 } ................................................................................................................................................................................ 33205 ** returns the number of TCHARs written to the output 33547 ** returns the number of TCHARs written to the output 33206 ** buffer, excluding the terminating null char. 33548 ** buffer, excluding the terminating null char. 33207 */ 33549 */ 33208 DWORD dwLen = 0; 33550 DWORD dwLen = 0; 33209 char *zOut = 0; 33551 char *zOut = 0; 33210 33552 33211 if( isNT() ){ 33553 if( isNT() ){ > 33554 #if SQLITE_OS_WINRT > 33555 WCHAR zTempWide[MAX_PATH+1]; /* NOTE: Somewhat arbitrary. */ > 33556 dwLen = osFormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | > 33557 FORMAT_MESSAGE_IGNORE_INSERTS, > 33558 NULL, > 33559 lastErrno, > 33560 0, > 33561 zTempWide, > 33562 MAX_PATH, > 33563 0); > 33564 #else 33212 LPWSTR zTempWide = NULL; 33565 LPWSTR zTempWide = NULL; 33213 dwLen = osFormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | 33566 dwLen = osFormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | 33214 FORMAT_MESSAGE_FROM_SYSTEM | 33567 FORMAT_MESSAGE_FROM_SYSTEM | 33215 FORMAT_MESSAGE_IGNORE_INSERTS, 33568 FORMAT_MESSAGE_IGNORE_INSERTS, 33216 NULL, 33569 NULL, 33217 lastErrno, 33570 lastErrno, 33218 0, 33571 0, 33219 (LPWSTR) &zTempWide, 33572 (LPWSTR) &zTempWide, 33220 0, 33573 0, 33221 0); 33574 0); > 33575 #endif 33222 if( dwLen > 0 ){ 33576 if( dwLen > 0 ){ 33223 /* allocate a buffer and convert to UTF8 */ 33577 /* allocate a buffer and convert to UTF8 */ 33224 sqlite3BeginBenignMalloc(); 33578 sqlite3BeginBenignMalloc(); 33225 zOut = unicodeToUtf8(zTempWide); 33579 zOut = unicodeToUtf8(zTempWide); 33226 sqlite3EndBenignMalloc(); 33580 sqlite3EndBenignMalloc(); > 33581 #if !SQLITE_OS_WINRT 33227 /* free the system buffer allocated by FormatMessage */ 33582 /* free the system buffer allocated by FormatMessage */ 33228 osLocalFree(zTempWide); 33583 osLocalFree(zTempWide); > 33584 #endif 33229 } 33585 } 33230 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. < 33231 ** Since the ANSI version of these Windows API do not exist for WINCE, < 33232 ** it's important to not reference them for WINCE builds. < 33233 */ < 33234 #if SQLITE_OS_WINCE==0 < > 33586 } > 33587 #ifdef SQLITE_WIN32_HAS_ANSI 33235 }else{ | 33588 else{ 33236 char *zTemp = NULL; 33589 char *zTemp = NULL; 33237 dwLen = osFormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | 33590 dwLen = osFormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | 33238 FORMAT_MESSAGE_FROM_SYSTEM | 33591 FORMAT_MESSAGE_FROM_SYSTEM | 33239 FORMAT_MESSAGE_IGNORE_INSERTS, 33592 FORMAT_MESSAGE_IGNORE_INSERTS, 33240 NULL, 33593 NULL, 33241 lastErrno, 33594 lastErrno, 33242 0, 33595 0, ................................................................................................................................................................................ 33247 /* allocate a buffer and convert to UTF8 */ 33600 /* allocate a buffer and convert to UTF8 */ 33248 sqlite3BeginBenignMalloc(); 33601 sqlite3BeginBenignMalloc(); 33249 zOut = sqlite3_win32_mbcs_to_utf8(zTemp); 33602 zOut = sqlite3_win32_mbcs_to_utf8(zTemp); 33250 sqlite3EndBenignMalloc(); 33603 sqlite3EndBenignMalloc(); 33251 /* free the system buffer allocated by FormatMessage */ 33604 /* free the system buffer allocated by FormatMessage */ 33252 osLocalFree(zTemp); 33605 osLocalFree(zTemp); 33253 } 33606 } 33254 #endif < 33255 } 33607 } > 33608 #endif 33256 if( 0 == dwLen ){ 33609 if( 0 == dwLen ){ 33257 sqlite3_snprintf(nBuf, zBuf, "OsError 0x%x (%u)", lastErrno, lastErrno); 33610 sqlite3_snprintf(nBuf, zBuf, "OsError 0x%x (%u)", lastErrno, lastErrno); 33258 }else{ 33611 }else{ 33259 /* copy a maximum of nBuf chars to output buffer */ 33612 /* copy a maximum of nBuf chars to output buffer */ 33260 sqlite3_snprintf(nBuf, zBuf, "%s", zOut); 33613 sqlite3_snprintf(nBuf, zBuf, "%s", zOut); 33261 /* free the UTF8 buffer */ 33614 /* free the UTF8 buffer */ 33262 sqlite3_free(zOut); 33615 sqlite3_free(zOut); ................................................................................................................................................................................ 33331 *pError = e; 33684 *pError = e; 33332 } 33685 } 33333 return 0; 33686 return 0; 33334 } 33687 } 33335 if( e==ERROR_ACCESS_DENIED || 33688 if( e==ERROR_ACCESS_DENIED || 33336 e==ERROR_LOCK_VIOLATION || 33689 e==ERROR_LOCK_VIOLATION || 33337 e==ERROR_SHARING_VIOLATION ){ 33690 e==ERROR_SHARING_VIOLATION ){ 33338 osSleep(win32IoerrRetryDelay*(1+*pnRetry)); | 33691 sqlite3_win32_sleep(win32IoerrRetryDelay*(1+*pnRetry)); 33339 ++*pnRetry; 33692 ++*pnRetry; 33340 return 1; 33693 return 1; 33341 } 33694 } 33342 if( pError ){ 33695 if( pError ){ 33343 *pError = e; 33696 *pError = e; 33344 } 33697 } 33345 return 0; 33698 return 0; ................................................................................................................................................................................ 33392 33745 33393 /* 33746 /* 33394 ** Acquire a lock on the handle h 33747 ** Acquire a lock on the handle h 33395 */ 33748 */ 33396 static void winceMutexAcquire(HANDLE h){ 33749 static void winceMutexAcquire(HANDLE h){ 33397 DWORD dwErr; 33750 DWORD dwErr; 33398 do { 33751 do { 33399 dwErr = WaitForSingleObject(h, INFINITE); | 33752 dwErr = osWaitForSingleObject(h, INFINITE); 33400 } while (dwErr != WAIT_OBJECT_0 && dwErr != WAIT_ABANDONED); 33753 } while (dwErr != WAIT_OBJECT_0 && dwErr != WAIT_ABANDONED); 33401 } 33754 } 33402 /* 33755 /* 33403 ** Release a lock acquired by winceMutexAcquire() 33756 ** Release a lock acquired by winceMutexAcquire() 33404 */ 33757 */ 33405 #define winceMutexRelease(h) ReleaseMutex(h) 33758 #define winceMutexRelease(h) ReleaseMutex(h) 33406 33759 ................................................................................................................................................................................ 33523 } 33876 } 33524 } 33877 } 33525 33878 33526 /* 33879 /* 33527 ** An implementation of the LockFile() API of Windows for CE 33880 ** An implementation of the LockFile() API of Windows for CE 33528 */ 33881 */ 33529 static BOOL winceLockFile( 33882 static BOOL winceLockFile( 33530 HANDLE *phFile, | 33883 LPHANDLE phFile, 33531 DWORD dwFileOffsetLow, 33884 DWORD dwFileOffsetLow, 33532 DWORD dwFileOffsetHigh, 33885 DWORD dwFileOffsetHigh, 33533 DWORD nNumberOfBytesToLockLow, 33886 DWORD nNumberOfBytesToLockLow, 33534 DWORD nNumberOfBytesToLockHigh 33887 DWORD nNumberOfBytesToLockHigh 33535 ){ 33888 ){ 33536 winFile *pFile = HANDLE_TO_WINFILE(phFile); 33889 winFile *pFile = HANDLE_TO_WINFILE(phFile); 33537 BOOL bReturn = FALSE; 33890 BOOL bReturn = FALSE; ................................................................................................................................................................................ 33587 return bReturn; 33940 return bReturn; 33588 } 33941 } 33589 33942 33590 /* 33943 /* 33591 ** An implementation of the UnlockFile API of Windows for CE 33944 ** An implementation of the UnlockFile API of Windows for CE 33592 */ 33945 */ 33593 static BOOL winceUnlockFile( 33946 static BOOL winceUnlockFile( 33594 HANDLE *phFile, | 33947 LPHANDLE phFile, 33595 DWORD dwFileOffsetLow, 33948 DWORD dwFileOffsetLow, 33596 DWORD dwFileOffsetHigh, 33949 DWORD dwFileOffsetHigh, 33597 DWORD nNumberOfBytesToUnlockLow, 33950 DWORD nNumberOfBytesToUnlockLow, 33598 DWORD nNumberOfBytesToUnlockHigh 33951 DWORD nNumberOfBytesToUnlockHigh 33599 ){ 33952 ){ 33600 winFile *pFile = HANDLE_TO_WINFILE(phFile); 33953 winFile *pFile = HANDLE_TO_WINFILE(phFile); 33601 BOOL bReturn = FALSE; 33954 BOOL bReturn = FALSE; ................................................................................................................................................................................ 33644 bReturn = TRUE; 33997 bReturn = TRUE; 33645 } 33998 } 33646 } 33999 } 33647 34000 33648 winceMutexRelease(pFile->hMutex); 34001 winceMutexRelease(pFile->hMutex); 33649 return bReturn; 34002 return bReturn; 33650 } 34003 } > 34004 /* > 34005 ** End of the special code for wince > 34006 *****************************************************************************/ > 34007 #endif /* SQLITE_OS_WINCE */ 33651 34008 33652 /* 34009 /* 33653 ** An implementation of the LockFileEx() API of Windows for CE < > 34010 ** Lock a file region. 33654 */ 34011 */ 33655 static BOOL winceLockFileEx( | 34012 static BOOL winLockFile( 33656 HANDLE *phFile, | 34013 LPHANDLE phFile, 33657 DWORD dwFlags, | 34014 DWORD flags, 33658 DWORD dwReserved, | 34015 DWORD offsetLow, 33659 DWORD nNumberOfBytesToLockLow, < 33660 DWORD nNumberOfBytesToLockHigh, < 33661 LPOVERLAPPED lpOverlapped < > 34016 DWORD offsetHigh, > 34017 DWORD numBytesLow, > 34018 DWORD numBytesHigh 33662 ){ 34019 ){ 33663 UNUSED_PARAMETER(dwReserved); < 33664 UNUSED_PARAMETER(nNumberOfBytesToLockHigh); < > 34020 #if SQLITE_OS_WINCE > 34021 /* > 34022 ** NOTE: Windows CE is handled differently here due its lack of the Win32 > 34023 ** API LockFile. > 34024 */ > 34025 return winceLockFile(phFile, offsetLow, offsetHigh, > 34026 numBytesLow, numBytesHigh); > 34027 #else > 34028 if( isNT() ){ > 34029 OVERLAPPED ovlp; > 34030 memset(&ovlp, 0, sizeof(OVERLAPPED)); > 34031 ovlp.Offset = offsetLow; > 34032 ovlp.OffsetHigh = offsetHigh; > 34033 return osLockFileEx(*phFile, flags, 0, numBytesLow, numBytesHigh, &ovlp); > 34034 }else{ > 34035 return osLockFile(*phFile, offsetLow, offsetHigh, numBytesLow, > 34036 numBytesHigh); 33665 | 34037 } 33666 /* If the caller wants a shared read lock, forward this call < 33667 ** to winceLockFile */ < 33668 if (lpOverlapped->Offset == (DWORD)SHARED_FIRST && < 33669 dwFlags == 1 && < 33670 nNumberOfBytesToLockLow == (DWORD)SHARED_SIZE){ < 33671 return winceLockFile(phFile, SHARED_FIRST, 0, 1, 0); < > 34038 #endif 33672 } | 34039 } 33673 return FALSE; < 33674 } | 34040 33675 /* 34041 /* 33676 ** End of the special code for wince < 33677 *****************************************************************************/ < > 34042 ** Unlock a file region. > 34043 */ > 34044 static BOOL winUnlockFile( > 34045 LPHANDLE phFile, > 34046 DWORD offsetLow, > 34047 DWORD offsetHigh, > 34048 DWORD numBytesLow, > 34049 DWORD numBytesHigh > 34050 ){ 33678 #endif /* SQLITE_OS_WINCE */ | 34051 #if SQLITE_OS_WINCE > 34052 /* > 34053 ** NOTE: Windows CE is handled differently here due its lack of the Win32 > 34054 ** API UnlockFile. > 34055 */ > 34056 return winceUnlockFile(phFile, offsetLow, offsetHigh, > 34057 numBytesLow, numBytesHigh); > 34058 #else > 34059 if( isNT() ){ > 34060 OVERLAPPED ovlp; > 34061 memset(&ovlp, 0, sizeof(OVERLAPPED)); > 34062 ovlp.Offset = offsetLow; > 34063 ovlp.OffsetHigh = offsetHigh; > 34064 return osUnlockFileEx(*phFile, 0, numBytesLow, numBytesHigh, &ovlp); > 34065 }else{ > 34066 return osUnlockFile(*phFile, offsetLow, offsetHigh, numBytesLow, > 34067 numBytesHigh); > 34068 } > 34069 #endif > 34070 } 33679 34071 33680 /***************************************************************************** 34072 /***************************************************************************** 33681 ** The next group of routines implement the I/O methods specified 34073 ** The next group of routines implement the I/O methods specified 33682 ** by the sqlite3_io_methods object. 34074 ** by the sqlite3_io_methods object. 33683 ******************************************************************************/ 34075 ******************************************************************************/ 33684 34076 33685 /* 34077 /* ................................................................................................................................................................................ 33691 34083 33692 /* 34084 /* 33693 ** Move the current position of the file handle passed as the first 34085 ** Move the current position of the file handle passed as the first 33694 ** argument to offset iOffset within the file. If successful, return 0. 34086 ** argument to offset iOffset within the file. If successful, return 0. 33695 ** Otherwise, set pFile->lastErrno and return non-zero. 34087 ** Otherwise, set pFile->lastErrno and return non-zero. 33696 */ 34088 */ 33697 static int seekWinFile(winFile *pFile, sqlite3_int64 iOffset){ 34089 static int seekWinFile(winFile *pFile, sqlite3_int64 iOffset){ > 34090 #if !SQLITE_OS_WINRT 33698 LONG upperBits; /* Most sig. 32 bits of new offset */ 34091 LONG upperBits; /* Most sig. 32 bits of new offset */ 33699 LONG lowerBits; /* Least sig. 32 bits of new offset */ 34092 LONG lowerBits; /* Least sig. 32 bits of new offset */ 33700 DWORD dwRet; /* Value returned by SetFilePointer() */ 34093 DWORD dwRet; /* Value returned by SetFilePointer() */ 33701 DWORD lastErrno; /* Value returned by GetLastError() */ 34094 DWORD lastErrno; /* Value returned by GetLastError() */ 33702 34095 33703 upperBits = (LONG)((iOffset>>32) & 0x7fffffff); 34096 upperBits = (LONG)((iOffset>>32) & 0x7fffffff); 33704 lowerBits = (LONG)(iOffset & 0xffffffff); 34097 lowerBits = (LONG)(iOffset & 0xffffffff); ................................................................................................................................................................................ 33717 pFile->lastErrno = lastErrno; 34110 pFile->lastErrno = lastErrno; 33718 winLogError(SQLITE_IOERR_SEEK, pFile->lastErrno, 34111 winLogError(SQLITE_IOERR_SEEK, pFile->lastErrno, 33719 "seekWinFile", pFile->zPath); 34112 "seekWinFile", pFile->zPath); 33720 return 1; 34113 return 1; 33721 } 34114 } 33722 34115 33723 return 0; 34116 return 0; > 34117 #else > 34118 /* > 34119 ** Same as above, except that this implementation works for WinRT. > 34120 */ > 34121 > 34122 LARGE_INTEGER x; /* The new offset */ > 34123 BOOL bRet; /* Value returned by SetFilePointerEx() */ > 34124 > 34125 x.QuadPart = iOffset; > 34126 bRet = osSetFilePointerEx(pFile->h, x, 0, FILE_BEGIN); > 34127 > 34128 if(!bRet){ > 34129 pFile->lastErrno = osGetLastError(); > 34130 winLogError(SQLITE_IOERR_SEEK, pFile->lastErrno, > 34131 "seekWinFile", pFile->zPath); > 34132 return 1; > 34133 } > 34134 > 34135 return 0; > 34136 #endif 33724 } 34137 } 33725 34138 33726 /* 34139 /* 33727 ** Close a file. 34140 ** Close a file. 33728 ** 34141 ** 33729 ** It is reported that an attempt to close a handle might sometimes 34142 ** It is reported that an attempt to close a handle might sometimes 33730 ** fail. This is a very unreasonable result, but Windows is notorious 34143 ** fail. This is a very unreasonable result, but Windows is notorious ................................................................................................................................................................................ 33740 34153 33741 assert( id!=0 ); 34154 assert( id!=0 ); 33742 assert( pFile->pShm==0 ); 34155 assert( pFile->pShm==0 ); 33743 OSTRACE(("CLOSE %d\n", pFile->h)); 34156 OSTRACE(("CLOSE %d\n", pFile->h)); 33744 do{ 34157 do{ 33745 rc = osCloseHandle(pFile->h); 34158 rc = osCloseHandle(pFile->h); 33746 /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */ 34159 /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */ 33747 }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (osSleep(100), 1) ); | 34160 }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (sqlite3_win32_sleep(100), 1) ); 33748 #if SQLITE_OS_WINCE 34161 #if SQLITE_OS_WINCE 33749 #define WINCE_DELETION_ATTEMPTS 3 34162 #define WINCE_DELETION_ATTEMPTS 3 33750 winceDestroyLock(pFile); 34163 winceDestroyLock(pFile); 33751 if( pFile->zDeleteOnClose ){ 34164 if( pFile->zDeleteOnClose ){ 33752 int cnt = 0; 34165 int cnt = 0; 33753 while( 34166 while( 33754 osDeleteFileW(pFile->zDeleteOnClose)==0 34167 osDeleteFileW(pFile->zDeleteOnClose)==0 33755 && osGetFileAttributesW(pFile->zDeleteOnClose)!=0xffffffff 34168 && osGetFileAttributesW(pFile->zDeleteOnClose)!=0xffffffff 33756 && cnt++ < WINCE_DELETION_ATTEMPTS 34169 && cnt++ < WINCE_DELETION_ATTEMPTS 33757 ){ 34170 ){ 33758 osSleep(100); /* Wait a little before trying again */ | 34171 sqlite3_win32_sleep(100); /* Wait a little before trying again */ 33759 } 34172 } 33760 sqlite3_free(pFile->zDeleteOnClose); 34173 sqlite3_free(pFile->zDeleteOnClose); 33761 } 34174 } 33762 #endif 34175 #endif 33763 OSTRACE(("CLOSE %d %s\n", pFile->h, rc ? "ok" : "failed")); 34176 OSTRACE(("CLOSE %d %s\n", pFile->h, rc ? "ok" : "failed")); 33764 if( rc ){ 34177 if( rc ){ 33765 pFile->h = NULL; 34178 pFile->h = NULL; ................................................................................................................................................................................ 34006 #endif 34419 #endif 34007 } 34420 } 34008 34421 34009 /* 34422 /* 34010 ** Determine the current size of a file in bytes 34423 ** Determine the current size of a file in bytes 34011 */ 34424 */ 34012 static int winFileSize(sqlite3_file *id, sqlite3_int64 *pSize){ 34425 static int winFileSize(sqlite3_file *id, sqlite3_int64 *pSize){ 34013 DWORD upperBits; < 34014 DWORD lowerBits; < 34015 winFile *pFile = (winFile*)id; 34426 winFile *pFile = (winFile*)id; 34016 DWORD lastErrno; < > 34427 int rc = SQLITE_OK; 34017 34428 34018 assert( id!=0 ); 34429 assert( id!=0 ); 34019 SimulateIOError(return SQLITE_IOERR_FSTAT); 34430 SimulateIOError(return SQLITE_IOERR_FSTAT); > 34431 #if SQLITE_OS_WINRT > 34432 { > 34433 FILE_STANDARD_INFO info; > 34434 if( osGetFileInformationByHandleEx(pFile->h, FileStandardInfo, > 34435 &info, sizeof(info)) ){ > 34436 *pSize = info.EndOfFile.QuadPart; > 34437 }else{ > 34438 pFile->lastErrno = osGetLastError(); > 34439 rc = winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno, > 34440 "winFileSize", pFile->zPath); > 34441 } > 34442 } > 34443 #else > 34444 { > 34445 DWORD upperBits; > 34446 DWORD lowerBits; > 34447 DWORD lastErrno; > 34448 34020 lowerBits = osGetFileSize(pFile->h, &upperBits); | 34449 lowerBits = osGetFileSize(pFile->h, &upperBits); > 34450 *pSize = (((sqlite3_int64)upperBits)<<32) + lowerBits; 34021 if( (lowerBits == INVALID_FILE_SIZE) | 34451 if( (lowerBits == INVALID_FILE_SIZE) 34022 && ((lastErrno = osGetLastError())!=NO_ERROR) ) | 34452 && ((lastErrno = osGetLastError())!=NO_ERROR) ){ 34023 { < 34024 pFile->lastErrno = lastErrno; | 34453 pFile->lastErrno = lastErrno; 34025 return winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno, | 34454 rc = winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno, 34026 "winFileSize", pFile->zPath); 34455 "winFileSize", pFile->zPath); 34027 } | 34456 } 34028 *pSize = (((sqlite3_int64)upperBits)<<32) + lowerBits; < > 34457 } > 34458 #endif 34029 return SQLITE_OK; | 34459 return rc; 34030 } 34460 } 34031 34461 34032 /* 34462 /* 34033 ** LOCKFILE_FAIL_IMMEDIATELY is undefined on some Windows systems. 34463 ** LOCKFILE_FAIL_IMMEDIATELY is undefined on some Windows systems. 34034 */ 34464 */ 34035 #ifndef LOCKFILE_FAIL_IMMEDIATELY 34465 #ifndef LOCKFILE_FAIL_IMMEDIATELY 34036 # define LOCKFILE_FAIL_IMMEDIATELY 1 34466 # define LOCKFILE_FAIL_IMMEDIATELY 1 34037 #endif 34467 #endif > 34468 > 34469 #ifndef LOCKFILE_EXCLUSIVE_LOCK > 34470 # define LOCKFILE_EXCLUSIVE_LOCK 2 > 34471 #endif > 34472 > 34473 /* > 34474 ** Historically, SQLite has used both the LockFile and LockFileEx functions. > 34475 ** When the LockFile function was used, it was always expected to fail > 34476 ** immediately if the lock could not be obtained. Also, it always expected to > 34477 ** obtain an exclusive lock. These flags are used with the LockFileEx function > 34478 ** and reflect those expectations; therefore, they should not be changed. > 34479 */ > 34480 #ifndef SQLITE_LOCKFILE_FLAGS > 34481 # define SQLITE_LOCKFILE_FLAGS (LOCKFILE_FAIL_IMMEDIATELY | \ > 34482 LOCKFILE_EXCLUSIVE_LOCK) > 34483 #endif > 34484 > 34485 /* > 34486 ** Currently, SQLite never calls the LockFileEx function without wanting the > 34487 ** call to fail immediately if the lock cannot be obtained. > 34488 */ > 34489 #ifndef SQLITE_LOCKFILEEX_FLAGS > 34490 # define SQLITE_LOCKFILEEX_FLAGS (LOCKFILE_FAIL_IMMEDIATELY) > 34491 #endif 34038 34492 34039 /* 34493 /* 34040 ** Acquire a reader lock. 34494 ** Acquire a reader lock. 34041 ** Different API routines are called depending on whether or not this 34495 ** Different API routines are called depending on whether or not this 34042 ** is Win9x or WinNT. 34496 ** is Win9x or WinNT. 34043 */ 34497 */ 34044 static int getReadLock(winFile *pFile){ 34498 static int getReadLock(winFile *pFile){ 34045 int res; 34499 int res; 34046 if( isNT() ){ 34500 if( isNT() ){ 34047 OVERLAPPED ovlp; < 34048 ovlp.Offset = SHARED_FIRST; < 34049 ovlp.OffsetHigh = 0; < 34050 ovlp.hEvent = 0; < 34051 res = osLockFileEx(pFile->h, LOCKFILE_FAIL_IMMEDIATELY, < 34052 0, SHARED_SIZE, 0, &ovlp); < 34053 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. | 34501 #if SQLITE_OS_WINCE > 34502 /* > 34503 ** NOTE: Windows CE is handled differently here due its lack of the Win32 > 34504 ** API LockFileEx. 34054 */ | 34505 */ > 34506 res = winceLockFile(&pFile->h, SHARED_FIRST, 0, 1, 0); > 34507 #else > 34508 res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS, SHARED_FIRST, 0, 34055 #if SQLITE_OS_WINCE==0 | 34509 SHARED_SIZE, 0); > 34510 #endif > 34511 } > 34512 #ifdef SQLITE_WIN32_HAS_ANSI 34056 }else{ | 34513 else{ 34057 int lk; 34514 int lk; 34058 sqlite3_randomness(sizeof(lk), &lk); 34515 sqlite3_randomness(sizeof(lk), &lk); 34059 pFile->sharedLockByte = (short)((lk & 0x7fffffff)%(SHARED_SIZE - 1)); 34516 pFile->sharedLockByte = (short)((lk & 0x7fffffff)%(SHARED_SIZE - 1)); > 34517 res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS, 34060 res = osLockFile(pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0); | 34518 SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0); 34061 #endif < 34062 } 34519 } > 34520 #endif 34063 if( res == 0 ){ 34521 if( res == 0 ){ 34064 pFile->lastErrno = osGetLastError(); 34522 pFile->lastErrno = osGetLastError(); 34065 /* No need to log a failure to lock */ 34523 /* No need to log a failure to lock */ 34066 } 34524 } 34067 return res; 34525 return res; 34068 } 34526 } 34069 34527 ................................................................................................................................................................................ 34070 /* 34528 /* 34071 ** Undo a readlock 34529 ** Undo a readlock 34072 */ 34530 */ 34073 static int unlockReadLock(winFile *pFile){ 34531 static int unlockReadLock(winFile *pFile){ 34074 int res; 34532 int res; 34075 DWORD lastErrno; 34533 DWORD lastErrno; 34076 if( isNT() ){ 34534 if( isNT() ){ 34077 res = osUnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0); | 34535 res = winUnlockFile(&pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0); 34078 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. | 34536 } 34079 */ | 34537 #ifdef SQLITE_WIN32_HAS_ANSI 34080 #if SQLITE_OS_WINCE==0 | 34538 else{ 34081 }else{ | 34539 res = winUnlockFile(&pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0); 34082 res = osUnlockFile(pFile->h, SHARED_FIRST + pFile->sharedLockByte, 0, 1, 0); | 34540 } 34083 #endif | 34541 #endif 34084 } < 34085 if( res==0 && ((lastErrno = osGetLastError())!=ERROR_NOT_LOCKED) ){ 34542 if( res==0 && ((lastErrno = osGetLastError())!=ERROR_NOT_LOCKED) ){ 34086 pFile->lastErrno = lastErrno; 34543 pFile->lastErrno = lastErrno; 34087 winLogError(SQLITE_IOERR_UNLOCK, pFile->lastErrno, 34544 winLogError(SQLITE_IOERR_UNLOCK, pFile->lastErrno, 34088 "unlockReadLock", pFile->zPath); 34545 "unlockReadLock", pFile->zPath); 34089 } 34546 } 34090 return res; 34547 return res; 34091 } 34548 } ................................................................................................................................................................................ 34148 */ 34605 */ 34149 newLocktype = pFile->locktype; 34606 newLocktype = pFile->locktype; 34150 if( (pFile->locktype==NO_LOCK) 34607 if( (pFile->locktype==NO_LOCK) 34151 || ( (locktype==EXCLUSIVE_LOCK) 34608 || ( (locktype==EXCLUSIVE_LOCK) 34152 && (pFile->locktype==RESERVED_LOCK)) 34609 && (pFile->locktype==RESERVED_LOCK)) 34153 ){ 34610 ){ 34154 int cnt = 3; 34611 int cnt = 3; > 34612 while( cnt-->0 && (res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS, 34155 while( cnt-->0 && (res = osLockFile(pFile->h, PENDING_BYTE, 0, 1, 0))==0 ){ | 34613 PENDING_BYTE, 0, 1, 0))==0 ){ 34156 /* Try 3 times to get the pending lock. This is needed to work 34614 /* Try 3 times to get the pending lock. This is needed to work 34157 ** around problems caused by indexing and/or anti-virus software on 34615 ** around problems caused by indexing and/or anti-virus software on 34158 ** Windows systems. 34616 ** Windows systems. 34159 ** If you are using this code as a model for alternative VFSes, do not 34617 ** If you are using this code as a model for alternative VFSes, do not 34160 ** copy this retry logic. It is a hack intended for Windows only. 34618 ** copy this retry logic. It is a hack intended for Windows only. 34161 */ 34619 */ 34162 OSTRACE(("could not get a PENDING lock. cnt=%d\n", cnt)); 34620 OSTRACE(("could not get a PENDING lock. cnt=%d\n", cnt)); 34163 if( cnt ) osSleep(1); | 34621 if( cnt ) sqlite3_win32_sleep(1); 34164 } 34622 } 34165 gotPendingLock = res; 34623 gotPendingLock = res; 34166 if( !res ){ 34624 if( !res ){ 34167 lastErrno = osGetLastError(); 34625 lastErrno = osGetLastError(); 34168 } 34626 } 34169 } 34627 } 34170 34628 ................................................................................................................................................................................ 34180 } 34638 } 34181 } 34639 } 34182 34640 34183 /* Acquire a RESERVED lock 34641 /* Acquire a RESERVED lock 34184 */ 34642 */ 34185 if( locktype==RESERVED_LOCK && res ){ 34643 if( locktype==RESERVED_LOCK && res ){ 34186 assert( pFile->locktype==SHARED_LOCK ); 34644 assert( pFile->locktype==SHARED_LOCK ); 34187 res = osLockFile(pFile->h, RESERVED_BYTE, 0, 1, 0); | 34645 res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS, RESERVED_BYTE, 0, 1, 0); 34188 if( res ){ 34646 if( res ){ 34189 newLocktype = RESERVED_LOCK; 34647 newLocktype = RESERVED_LOCK; 34190 }else{ 34648 }else{ 34191 lastErrno = osGetLastError(); 34649 lastErrno = osGetLastError(); 34192 } 34650 } 34193 } 34651 } 34194 34652 ................................................................................................................................................................................ 34201 34659 34202 /* Acquire an EXCLUSIVE lock 34660 /* Acquire an EXCLUSIVE lock 34203 */ 34661 */ 34204 if( locktype==EXCLUSIVE_LOCK && res ){ 34662 if( locktype==EXCLUSIVE_LOCK && res ){ 34205 assert( pFile->locktype>=SHARED_LOCK ); 34663 assert( pFile->locktype>=SHARED_LOCK ); 34206 res = unlockReadLock(pFile); 34664 res = unlockReadLock(pFile); 34207 OSTRACE(("unreadlock = %d\n", res)); 34665 OSTRACE(("unreadlock = %d\n", res)); > 34666 res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS, SHARED_FIRST, 0, 34208 res = osLockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0); | 34667 SHARED_SIZE, 0); 34209 if( res ){ 34668 if( res ){ 34210 newLocktype = EXCLUSIVE_LOCK; 34669 newLocktype = EXCLUSIVE_LOCK; 34211 }else{ 34670 }else{ 34212 lastErrno = osGetLastError(); 34671 lastErrno = osGetLastError(); 34213 OSTRACE(("error-code = %d\n", lastErrno)); 34672 OSTRACE(("error-code = %d\n", lastErrno)); 34214 getReadLock(pFile); 34673 getReadLock(pFile); 34215 } 34674 } 34216 } 34675 } 34217 34676 34218 /* If we are holding a PENDING lock that ought to be released, then 34677 /* If we are holding a PENDING lock that ought to be released, then 34219 ** release it now. 34678 ** release it now. 34220 */ 34679 */ 34221 if( gotPendingLock && locktype==SHARED_LOCK ){ 34680 if( gotPendingLock && locktype==SHARED_LOCK ){ 34222 osUnlockFile(pFile->h, PENDING_BYTE, 0, 1, 0); | 34681 winUnlockFile(&pFile->h, PENDING_BYTE, 0, 1, 0); 34223 } 34682 } 34224 34683 34225 /* Update the state of the lock has held in the file descriptor then 34684 /* Update the state of the lock has held in the file descriptor then 34226 ** return the appropriate result code. 34685 ** return the appropriate result code. 34227 */ 34686 */ 34228 if( res ){ 34687 if( res ){ 34229 rc = SQLITE_OK; 34688 rc = SQLITE_OK; ................................................................................................................................................................................ 34249 SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; ); 34708 SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; ); 34250 34709 34251 assert( id!=0 ); 34710 assert( id!=0 ); 34252 if( pFile->locktype>=RESERVED_LOCK ){ 34711 if( pFile->locktype>=RESERVED_LOCK ){ 34253 rc = 1; 34712 rc = 1; 34254 OSTRACE(("TEST WR-LOCK %d %d (local)\n", pFile->h, rc)); 34713 OSTRACE(("TEST WR-LOCK %d %d (local)\n", pFile->h, rc)); 34255 }else{ 34714 }else{ 34256 rc = osLockFile(pFile->h, RESERVED_BYTE, 0, 1, 0); | 34715 rc = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS, RESERVED_BYTE, 0, 1, 0); 34257 if( rc ){ 34716 if( rc ){ 34258 osUnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0); | 34717 winUnlockFile(&pFile->h, RESERVED_BYTE, 0, 1, 0); 34259 } 34718 } 34260 rc = !rc; 34719 rc = !rc; 34261 OSTRACE(("TEST WR-LOCK %d %d (remote)\n", pFile->h, rc)); 34720 OSTRACE(("TEST WR-LOCK %d %d (remote)\n", pFile->h, rc)); 34262 } 34721 } 34263 *pResOut = rc; 34722 *pResOut = rc; 34264 return SQLITE_OK; 34723 return SQLITE_OK; 34265 } 34724 } ................................................................................................................................................................................ 34281 int rc = SQLITE_OK; 34740 int rc = SQLITE_OK; 34282 assert( pFile!=0 ); 34741 assert( pFile!=0 ); 34283 assert( locktype<=SHARED_LOCK ); 34742 assert( locktype<=SHARED_LOCK ); 34284 OSTRACE(("UNLOCK %d to %d was %d(%d)\n", pFile->h, locktype, 34743 OSTRACE(("UNLOCK %d to %d was %d(%d)\n", pFile->h, locktype, 34285 pFile->locktype, pFile->sharedLockByte)); 34744 pFile->locktype, pFile->sharedLockByte)); 34286 type = pFile->locktype; 34745 type = pFile->locktype; 34287 if( type>=EXCLUSIVE_LOCK ){ 34746 if( type>=EXCLUSIVE_LOCK ){ 34288 osUnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0); | 34747 winUnlockFile(&pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0); 34289 if( locktype==SHARED_LOCK && !getReadLock(pFile) ){ 34748 if( locktype==SHARED_LOCK && !getReadLock(pFile) ){ 34290 /* This should never happen. We should always be able to 34749 /* This should never happen. We should always be able to 34291 ** reacquire the read lock */ 34750 ** reacquire the read lock */ 34292 rc = winLogError(SQLITE_IOERR_UNLOCK, osGetLastError(), 34751 rc = winLogError(SQLITE_IOERR_UNLOCK, osGetLastError(), 34293 "winUnlock", pFile->zPath); 34752 "winUnlock", pFile->zPath); 34294 } 34753 } 34295 } 34754 } 34296 if( type>=RESERVED_LOCK ){ 34755 if( type>=RESERVED_LOCK ){ 34297 osUnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0); | 34756 winUnlockFile(&pFile->h, RESERVED_BYTE, 0, 1, 0); 34298 } 34757 } 34299 if( locktype==NO_LOCK && type>=SHARED_LOCK ){ 34758 if( locktype==NO_LOCK && type>=SHARED_LOCK ){ 34300 unlockReadLock(pFile); 34759 unlockReadLock(pFile); 34301 } 34760 } 34302 if( type>=PENDING_LOCK ){ 34761 if( type>=PENDING_LOCK ){ 34303 osUnlockFile(pFile->h, PENDING_BYTE, 0, 1, 0); | 34762 winUnlockFile(&pFile->h, PENDING_BYTE, 0, 1, 0); 34304 } 34763 } 34305 pFile->locktype = (u8)locktype; 34764 pFile->locktype = (u8)locktype; 34306 return rc; 34765 return rc; 34307 } 34766 } 34308 34767 34309 /* 34768 /* 34310 ** If *pArg is inititially negative then this is a query. Set *pArg to 34769 ** If *pArg is inititially negative then this is a query. Set *pArg to ................................................................................................................................................................................ 34534 #define _SHM_WRLCK 3 34993 #define _SHM_WRLCK 3 34535 static int winShmSystemLock( 34994 static int winShmSystemLock( 34536 winShmNode *pFile, /* Apply locks to this open shared-memory segment */ 34995 winShmNode *pFile, /* Apply locks to this open shared-memory segment */ 34537 int lockType, /* _SHM_UNLCK, _SHM_RDLCK, or _SHM_WRLCK */ 34996 int lockType, /* _SHM_UNLCK, _SHM_RDLCK, or _SHM_WRLCK */ 34538 int ofst, /* Offset to first byte to be locked/unlocked */ 34997 int ofst, /* Offset to first byte to be locked/unlocked */ 34539 int nByte /* Number of bytes to lock or unlock */ 34998 int nByte /* Number of bytes to lock or unlock */ 34540 ){ 34999 ){ 34541 OVERLAPPED ovlp; < 34542 DWORD dwFlags; < 34543 int rc = 0; /* Result code form Lock/UnlockFileEx() */ 35000 int rc = 0; /* Result code form Lock/UnlockFileEx() */ 34544 35001 34545 /* Access to the winShmNode object is serialized by the caller */ 35002 /* Access to the winShmNode object is serialized by the caller */ 34546 assert( sqlite3_mutex_held(pFile->mutex) || pFile->nRef==0 ); 35003 assert( sqlite3_mutex_held(pFile->mutex) || pFile->nRef==0 ); 34547 35004 34548 /* Initialize the locking parameters */ < 34549 dwFlags = LOCKFILE_FAIL_IMMEDIATELY; < 34550 if( lockType == _SHM_WRLCK ) dwFlags |= LOCKFILE_EXCLUSIVE_LOCK; < 34551 < 34552 memset(&ovlp, 0, sizeof(OVERLAPPED)); < 34553 ovlp.Offset = ofst; < 34554 < 34555 /* Release/Acquire the system-level lock */ 35005 /* Release/Acquire the system-level lock */ 34556 if( lockType==_SHM_UNLCK ){ 35006 if( lockType==_SHM_UNLCK ){ 34557 rc = osUnlockFileEx(pFile->hFile.h, 0, nByte, 0, &ovlp); < > 35007 rc = winUnlockFile(&pFile->hFile.h, ofst, 0, nByte, 0); 34558 }else{ 35008 }else{ > 35009 /* Initialize the locking parameters */ > 35010 DWORD dwFlags = LOCKFILE_FAIL_IMMEDIATELY; > 35011 if( lockType == _SHM_WRLCK ) dwFlags |= LOCKFILE_EXCLUSIVE_LOCK; 34559 rc = osLockFileEx(pFile->hFile.h, dwFlags, 0, nByte, 0, &ovlp); | 35012 rc = winLockFile(&pFile->hFile.h, dwFlags, ofst, 0, nByte, 0); 34560 } 35013 } 34561 35014 34562 if( rc!= 0 ){ 35015 if( rc!= 0 ){ 34563 rc = SQLITE_OK; 35016 rc = SQLITE_OK; 34564 }else{ 35017 }else{ 34565 pFile->lastErrno = osGetLastError(); 35018 pFile->lastErrno = osGetLastError(); 34566 rc = SQLITE_BUSY; 35019 rc = SQLITE_BUSY; ................................................................................................................................................................................ 34990 } 35443 } 34991 pShmNode->aRegion = apNew; 35444 pShmNode->aRegion = apNew; 34992 35445 34993 while( pShmNode->nRegion<=iRegion ){ 35446 while( pShmNode->nRegion<=iRegion ){ 34994 HANDLE hMap; /* file-mapping handle */ 35447 HANDLE hMap; /* file-mapping handle */ 34995 void *pMap = 0; /* Mapped memory region */ 35448 void *pMap = 0; /* Mapped memory region */ 34996 35449 > 35450 #if SQLITE_OS_WINRT > 35451 hMap = osCreateFileMappingFromApp(pShmNode->hFile.h, > 35452 NULL, PAGE_READWRITE, nByte, NULL > 35453 ); > 35454 #else 34997 hMap = osCreateFileMapping(pShmNode->hFile.h, | 35455 hMap = osCreateFileMappingW(pShmNode->hFile.h, 34998 NULL, PAGE_READWRITE, 0, nByte, NULL 35456 NULL, PAGE_READWRITE, 0, nByte, NULL 34999 ); 35457 ); > 35458 #endif 35000 OSTRACE(("SHM-MAP pid-%d create region=%d nbyte=%d %s\n", 35459 OSTRACE(("SHM-MAP pid-%d create region=%d nbyte=%d %s\n", 35001 (int)osGetCurrentProcessId(), pShmNode->nRegion, nByte, 35460 (int)osGetCurrentProcessId(), pShmNode->nRegion, nByte, 35002 hMap ? "ok" : "failed")); 35461 hMap ? "ok" : "failed")); 35003 if( hMap ){ 35462 if( hMap ){ 35004 int iOffset = pShmNode->nRegion*szRegion; 35463 int iOffset = pShmNode->nRegion*szRegion; 35005 int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity; 35464 int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity; > 35465 #if SQLITE_OS_WINRT > 35466 pMap = osMapViewOfFileFromApp(hMap, FILE_MAP_WRITE | FILE_MAP_READ, > 35467 iOffset - iOffsetShift, szRegion + iOffsetShift > 35468 ); > 35469 #else 35006 pMap = osMapViewOfFile(hMap, FILE_MAP_WRITE | FILE_MAP_READ, 35470 pMap = osMapViewOfFile(hMap, FILE_MAP_WRITE | FILE_MAP_READ, 35007 0, iOffset - iOffsetShift, szRegion + iOffsetShift 35471 0, iOffset - iOffsetShift, szRegion + iOffsetShift 35008 ); 35472 ); > 35473 #endif 35009 OSTRACE(("SHM-MAP pid-%d map region=%d offset=%d size=%d %s\n", 35474 OSTRACE(("SHM-MAP pid-%d map region=%d offset=%d size=%d %s\n", 35010 (int)osGetCurrentProcessId(), pShmNode->nRegion, iOffset, 35475 (int)osGetCurrentProcessId(), pShmNode->nRegion, iOffset, 35011 szRegion, pMap ? "ok" : "failed")); 35476 szRegion, pMap ? "ok" : "failed")); 35012 } 35477 } 35013 if( !pMap ){ 35478 if( !pMap ){ 35014 pShmNode->lastErrno = osGetLastError(); 35479 pShmNode->lastErrno = osGetLastError(); 35015 rc = winLogError(SQLITE_IOERR_SHMMAP, pShmNode->lastErrno, 35480 rc = winLogError(SQLITE_IOERR_SHMMAP, pShmNode->lastErrno, ................................................................................................................................................................................ 35087 ** is obtained from malloc and must be freed by the calling 35552 ** is obtained from malloc and must be freed by the calling 35088 ** function. 35553 ** function. 35089 */ 35554 */ 35090 static void *convertUtf8Filename(const char *zFilename){ 35555 static void *convertUtf8Filename(const char *zFilename){ 35091 void *zConverted = 0; 35556 void *zConverted = 0; 35092 if( isNT() ){ 35557 if( isNT() ){ 35093 zConverted = utf8ToUnicode(zFilename); 35558 zConverted = utf8ToUnicode(zFilename); 35094 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. < 35095 */ < 35096 #if SQLITE_OS_WINCE==0 < > 35559 } > 35560 #ifdef SQLITE_WIN32_HAS_ANSI 35097 }else{ | 35561 else{ 35098 zConverted = sqlite3_win32_utf8_to_mbcs(zFilename); 35562 zConverted = sqlite3_win32_utf8_to_mbcs(zFilename); 35099 #endif < 35100 } 35563 } > 35564 #endif 35101 /* caller will handle out of memory */ 35565 /* caller will handle out of memory */ 35102 return zConverted; 35566 return zConverted; 35103 } 35567 } 35104 35568 35105 /* 35569 /* 35106 ** Create a temporary file name in zBuf. zBuf must be big enough to 35570 ** Create a temporary file name in zBuf. zBuf must be big enough to 35107 ** hold at pVfs->mxPathname characters. 35571 ** hold at pVfs->mxPathname characters. ................................................................................................................................................................................ 35108 */ 35572 */ 35109 static int getTempname(int nBuf, char *zBuf){ 35573 static int getTempname(int nBuf, char *zBuf){ 35110 static char zChars[] = 35574 static char zChars[] = 35111 "abcdefghijklmnopqrstuvwxyz" 35575 "abcdefghijklmnopqrstuvwxyz" 35112 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 35576 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 35113 "0123456789"; 35577 "0123456789"; 35114 size_t i, j; 35578 size_t i, j; > 35579 int nTempPath; 35115 char zTempPath[MAX_PATH+2]; 35580 char zTempPath[MAX_PATH+2]; 35116 35581 35117 /* It's odd to simulate an io-error here, but really this is just 35582 /* It's odd to simulate an io-error here, but really this is just 35118 ** using the io-error infrastructure to test that SQLite handles this 35583 ** using the io-error infrastructure to test that SQLite handles this 35119 ** function failing. 35584 ** function failing. 35120 */ 35585 */ 35121 SimulateIOError( return SQLITE_IOERR ); 35586 SimulateIOError( return SQLITE_IOERR ); 35122 35587 > 35588 memset(zTempPath, 0, MAX_PATH+2); > 35589 35123 if( sqlite3_temp_directory ){ 35590 if( sqlite3_temp_directory ){ 35124 sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", sqlite3_temp_directory); 35591 sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", sqlite3_temp_directory); > 35592 } > 35593 #if !SQLITE_OS_WINRT 35125 }else if( isNT() ){ | 35594 else if( isNT() ){ 35126 char *zMulti; 35595 char *zMulti; 35127 WCHAR zWidePath[MAX_PATH]; 35596 WCHAR zWidePath[MAX_PATH]; 35128 osGetTempPathW(MAX_PATH-30, zWidePath); 35597 osGetTempPathW(MAX_PATH-30, zWidePath); 35129 zMulti = unicodeToUtf8(zWidePath); 35598 zMulti = unicodeToUtf8(zWidePath); 35130 if( zMulti ){ 35599 if( zMulti ){ 35131 sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zMulti); 35600 sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zMulti); 35132 sqlite3_free(zMulti); 35601 sqlite3_free(zMulti); 35133 }else{ 35602 }else{ 35134 return SQLITE_IOERR_NOMEM; 35603 return SQLITE_IOERR_NOMEM; 35135 } 35604 } 35136 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. < > 35605 } 35137 ** Since the ANSI version of these Windows API do not exist for WINCE, | 35606 #ifdef SQLITE_WIN32_HAS_ANSI 35138 ** it's important to not reference them for WINCE builds. < 35139 */ < 35140 #if SQLITE_OS_WINCE==0 < 35141 }else{ | 35607 else{ 35142 char *zUtf8; 35608 char *zUtf8; 35143 char zMbcsPath[MAX_PATH]; 35609 char zMbcsPath[MAX_PATH]; 35144 osGetTempPathA(MAX_PATH-30, zMbcsPath); 35610 osGetTempPathA(MAX_PATH-30, zMbcsPath); 35145 zUtf8 = sqlite3_win32_mbcs_to_utf8(zMbcsPath); 35611 zUtf8 = sqlite3_win32_mbcs_to_utf8(zMbcsPath); 35146 if( zUtf8 ){ 35612 if( zUtf8 ){ 35147 sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zUtf8); 35613 sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zUtf8); 35148 sqlite3_free(zUtf8); 35614 sqlite3_free(zUtf8); 35149 }else{ 35615 }else{ 35150 return SQLITE_IOERR_NOMEM; 35616 return SQLITE_IOERR_NOMEM; 35151 } 35617 } 35152 #endif < 35153 } 35618 } > 35619 #endif > 35620 #endif 35154 35621 35155 /* Check that the output buffer is large enough for the temporary file 35622 /* Check that the output buffer is large enough for the temporary file 35156 ** name. If it is not, return SQLITE_ERROR. 35623 ** name. If it is not, return SQLITE_ERROR. 35157 */ 35624 */ > 35625 nTempPath = sqlite3Strlen30(zTempPath); > 35626 35158 if( (sqlite3Strlen30(zTempPath) + sqlite3Strlen30(SQLITE_TEMP_FILE_PREFIX) + 1 | 35627 if( (nTempPath + sqlite3Strlen30(SQLITE_TEMP_FILE_PREFIX) + 18) >= nBuf ){ 35159 return SQLITE_ERROR; 35628 return SQLITE_ERROR; 35160 } 35629 } 35161 35630 35162 for(i=sqlite3Strlen30(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){} | 35631 for(i=nTempPath; i>0 && zTempPath[i-1]=='\\'; i--){} 35163 zTempPath[i] = 0; 35632 zTempPath[i] = 0; 35164 35633 35165 sqlite3_snprintf(nBuf-18, zBuf, | 35634 sqlite3_snprintf(nBuf-18, zBuf, (nTempPath > 0) ? 35166 "%s\\"SQLITE_TEMP_FILE_PREFIX, zTempPath); | 35635 "%s\\"SQLITE_TEMP_FILE_PREFIX : SQLITE_TEMP_FILE_PREFIX, > 35636 zTempPath); 35167 j = sqlite3Strlen30(zBuf); 35637 j = sqlite3Strlen30(zBuf); 35168 sqlite3_randomness(15, &zBuf[j]); 35638 sqlite3_randomness(15, &zBuf[j]); 35169 for(i=0; i<15; i++, j++){ 35639 for(i=0; i<15; i++, j++){ 35170 zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ]; 35640 zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ]; 35171 } 35641 } 35172 zBuf[j] = 0; 35642 zBuf[j] = 0; 35173 zBuf[j+1] = 0; 35643 zBuf[j+1] = 0; ................................................................................................................................................................................ 35355 /* Reports from the internet are that performance is always 35825 /* Reports from the internet are that performance is always 35356 ** better if FILE_FLAG_RANDOM_ACCESS is used. Ticket #2699. */ 35826 ** better if FILE_FLAG_RANDOM_ACCESS is used. Ticket #2699. */ 35357 #if SQLITE_OS_WINCE 35827 #if SQLITE_OS_WINCE 35358 dwFlagsAndAttributes |= FILE_FLAG_RANDOM_ACCESS; 35828 dwFlagsAndAttributes |= FILE_FLAG_RANDOM_ACCESS; 35359 #endif 35829 #endif 35360 35830 35361 if( isNT() ){ 35831 if( isNT() ){ > 35832 #if SQLITE_OS_WINRT > 35833 CREATEFILE2_EXTENDED_PARAMETERS extendedParameters; > 35834 extendedParameters.dwSize = sizeof(CREATEFILE2_EXTENDED_PARAMETERS); > 35835 extendedParameters.dwFileAttributes = > 35836 dwFlagsAndAttributes & FILE_ATTRIBUTE_MASK; > 35837 extendedParameters.dwFileFlags = dwFlagsAndAttributes & FILE_FLAG_MASK; > 35838 extendedParameters.dwSecurityQosFlags = SECURITY_ANONYMOUS; > 35839 extendedParameters.lpSecurityAttributes = NULL; > 35840 extendedParameters.hTemplateFile = NULL; > 35841 while( (h = osCreateFile2((LPCWSTR)zConverted, > 35842 dwDesiredAccess, > 35843 dwShareMode, > 35844 dwCreationDisposition, > 35845 &extendedParameters))==INVALID_HANDLE_VALUE && > 35846 retryIoerr(&cnt, &lastErrno) ){ > 35847 /* Noop */ > 35848 } > 35849 #else 35362 while( (h = osCreateFileW((LPCWSTR)zConverted, 35850 while( (h = osCreateFileW((LPCWSTR)zConverted, 35363 dwDesiredAccess, 35851 dwDesiredAccess, 35364 dwShareMode, NULL, 35852 dwShareMode, NULL, 35365 dwCreationDisposition, 35853 dwCreationDisposition, 35366 dwFlagsAndAttributes, 35854 dwFlagsAndAttributes, 35367 NULL))==INVALID_HANDLE_VALUE && 35855 NULL))==INVALID_HANDLE_VALUE && 35368 retryIoerr(&cnt, &lastErrno) ){ 35856 retryIoerr(&cnt, &lastErrno) ){ 35369 /* Noop */ 35857 /* Noop */ 35370 } 35858 } 35371 #if SQLITE_OS_WINCE==0 | 35859 #endif > 35860 } > 35861 #ifdef SQLITE_WIN32_HAS_ANSI 35372 }else{ | 35862 else{ 35373 while( (h = osCreateFileA((LPCSTR)zConverted, 35863 while( (h = osCreateFileA((LPCSTR)zConverted, 35374 dwDesiredAccess, 35864 dwDesiredAccess, 35375 dwShareMode, NULL, 35865 dwShareMode, NULL, 35376 dwCreationDisposition, 35866 dwCreationDisposition, 35377 dwFlagsAndAttributes, 35867 dwFlagsAndAttributes, 35378 NULL))==INVALID_HANDLE_VALUE && 35868 NULL))==INVALID_HANDLE_VALUE && 35379 retryIoerr(&cnt, &lastErrno) ){ 35869 retryIoerr(&cnt, &lastErrno) ){ 35380 /* Noop */ 35870 /* Noop */ 35381 } 35871 } 35382 #endif < 35383 } 35872 } 35384 < > 35873 #endif 35385 logIoerr(cnt); 35874 logIoerr(cnt); 35386 35875 35387 OSTRACE(("OPEN %d %s 0x%lx %s\n", 35876 OSTRACE(("OPEN %d %s 0x%lx %s\n", 35388 h, zName, dwDesiredAccess, 35877 h, zName, dwDesiredAccess, 35389 h==INVALID_HANDLE_VALUE ? "failed" : "ok")); 35878 h==INVALID_HANDLE_VALUE ? "failed" : "ok")); 35390 35879 35391 if( h==INVALID_HANDLE_VALUE ){ 35880 if( h==INVALID_HANDLE_VALUE ){ ................................................................................................................................................................................ 35467 SimulateIOError(return SQLITE_IOERR_DELETE); 35956 SimulateIOError(return SQLITE_IOERR_DELETE); 35468 zConverted = convertUtf8Filename(zFilename); 35957 zConverted = convertUtf8Filename(zFilename); 35469 if( zConverted==0 ){ 35958 if( zConverted==0 ){ 35470 return SQLITE_IOERR_NOMEM; 35959 return SQLITE_IOERR_NOMEM; 35471 } 35960 } 35472 if( isNT() ){ 35961 if( isNT() ){ 35473 do { 35962 do { > 35963 #if SQLITE_OS_WINRT > 35964 WIN32_FILE_ATTRIBUTE_DATA sAttrData; > 35965 memset(&sAttrData, 0, sizeof(sAttrData)); > 35966 if ( osGetFileAttributesExW(zConverted, GetFileExInfoStandard, > 35967 &sAttrData) ){ > 35968 attr = sAttrData.dwFileAttributes; > 35969 }else{ > 35970 rc = SQLITE_OK; /* Already gone? */ > 35971 break; > 35972 } > 35973 #else 35474 attr = osGetFileAttributesW(zConverted); 35974 attr = osGetFileAttributesW(zConverted); > 35975 #endif 35475 if ( attr==INVALID_FILE_ATTRIBUTES ){ 35976 if ( attr==INVALID_FILE_ATTRIBUTES ){ 35476 rc = SQLITE_OK; /* Already gone? */ 35977 rc = SQLITE_OK; /* Already gone? */ 35477 break; 35978 break; 35478 } 35979 } 35479 if ( attr&FILE_ATTRIBUTE_DIRECTORY ){ 35980 if ( attr&FILE_ATTRIBUTE_DIRECTORY ){ 35480 rc = SQLITE_ERROR; /* Files only. */ 35981 rc = SQLITE_ERROR; /* Files only. */ 35481 break; 35982 break; ................................................................................................................................................................................ 35485 break; 35986 break; 35486 } 35987 } 35487 if ( !retryIoerr(&cnt, &lastErrno) ){ 35988 if ( !retryIoerr(&cnt, &lastErrno) ){ 35488 rc = SQLITE_ERROR; /* No more retries. */ 35989 rc = SQLITE_ERROR; /* No more retries. */ 35489 break; 35990 break; 35490 } 35991 } 35491 } while(1); 35992 } while(1); 35492 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. < > 35993 } 35493 ** Since the ANSI version of these Windows API do not exist for WINCE, | 35994 #ifdef SQLITE_WIN32_HAS_ANSI 35494 ** it's important to not reference them for WINCE builds. < 35495 */ < 35496 #if SQLITE_OS_WINCE==0 < 35497 }else{ | 35995 else{ 35498 do { 35996 do { 35499 attr = osGetFileAttributesA(zConverted); 35997 attr = osGetFileAttributesA(zConverted); 35500 if ( attr==INVALID_FILE_ATTRIBUTES ){ 35998 if ( attr==INVALID_FILE_ATTRIBUTES ){ 35501 rc = SQLITE_OK; /* Already gone? */ 35999 rc = SQLITE_OK; /* Already gone? */ 35502 break; 36000 break; 35503 } 36001 } 35504 if ( attr&FILE_ATTRIBUTE_DIRECTORY ){ 36002 if ( attr&FILE_ATTRIBUTE_DIRECTORY ){ ................................................................................................................................................................................ 35510 break; 36008 break; 35511 } 36009 } 35512 if ( !retryIoerr(&cnt, &lastErrno) ){ 36010 if ( !retryIoerr(&cnt, &lastErrno) ){ 35513 rc = SQLITE_ERROR; /* No more retries. */ 36011 rc = SQLITE_ERROR; /* No more retries. */ 35514 break; 36012 break; 35515 } 36013 } 35516 } while(1); 36014 } while(1); 35517 #endif < 35518 } 36015 } > 36016 #endif 35519 if( rc ){ 36017 if( rc ){ 35520 rc = winLogError(SQLITE_IOERR_DELETE, lastErrno, 36018 rc = winLogError(SQLITE_IOERR_DELETE, lastErrno, 35521 "winDelete", zFilename); 36019 "winDelete", zFilename); 35522 }else{ 36020 }else{ 35523 logIoerr(cnt); 36021 logIoerr(cnt); 35524 } 36022 } 35525 sqlite3_free(zConverted); 36023 sqlite3_free(zConverted); ................................................................................................................................................................................ 35571 winLogError(SQLITE_IOERR_ACCESS, lastErrno, "winAccess", zFilename); 36069 winLogError(SQLITE_IOERR_ACCESS, lastErrno, "winAccess", zFilename); 35572 sqlite3_free(zConverted); 36070 sqlite3_free(zConverted); 35573 return SQLITE_IOERR_ACCESS; 36071 return SQLITE_IOERR_ACCESS; 35574 }else{ 36072 }else{ 35575 attr = INVALID_FILE_ATTRIBUTES; 36073 attr = INVALID_FILE_ATTRIBUTES; 35576 } 36074 } 35577 } 36075 } 35578 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. < > 36076 } 35579 ** Since the ANSI version of these Windows API do not exist for WINCE, | 36077 #ifdef SQLITE_WIN32_HAS_ANSI 35580 ** it's important to not reference them for WINCE builds. < 35581 */ < 35582 #if SQLITE_OS_WINCE==0 < 35583 }else{ | 36078 else{ 35584 attr = osGetFileAttributesA((char*)zConverted); 36079 attr = osGetFileAttributesA((char*)zConverted); 35585 #endif < 35586 } 36080 } > 36081 #endif 35587 sqlite3_free(zConverted); 36082 sqlite3_free(zConverted); 35588 switch( flags ){ 36083 switch( flags ){ 35589 case SQLITE_ACCESS_READ: 36084 case SQLITE_ACCESS_READ: 35590 case SQLITE_ACCESS_EXISTS: 36085 case SQLITE_ACCESS_EXISTS: 35591 rc = attr!=INVALID_FILE_ATTRIBUTES; 36086 rc = attr!=INVALID_FILE_ATTRIBUTES; 35592 break; 36087 break; 35593 case SQLITE_ACCESS_READWRITE: 36088 case SQLITE_ACCESS_READWRITE: ................................................................................................................................................................................ 35597 default: 36092 default: 35598 assert(!"Invalid flags argument"); 36093 assert(!"Invalid flags argument"); 35599 } 36094 } 35600 *pResOut = rc; 36095 *pResOut = rc; 35601 return SQLITE_OK; 36096 return SQLITE_OK; 35602 } 36097 } 35603 36098 > 36099 > 36100 /* > 36101 ** Returns non-zero if the specified path name should be used verbatim. If > 36102 ** non-zero is returned from this function, the calling function must simply > 36103 ** use the provided path name verbatim -OR- resolve it into a full path name > 36104 ** using the GetFullPathName Win32 API function (if available). > 36105 */ > 36106 static BOOL winIsVerbatimPathname( > 36107 const char *zPathname > 36108 ){ > 36109 /* > 36110 ** If the path name starts with a forward slash or a backslash, it is either > 36111 ** a legal UNC name, a volume relative path, or an absolute path name in the > 36112 ** "Unix" format on Windows. There is no easy way to differentiate between > 36113 ** the final two cases; therefore, we return the safer return value of TRUE > 36114 ** so that callers of this function will simply use it verbatim. > 36115 */ > 36116 if ( zPathname[0]=='/' || zPathname[0]=='\\' ){ > 36117 return TRUE; > 36118 } > 36119 > 36120 /* > 36121 ** If the path name starts with a letter and a colon it is either a volume > 36122 ** relative path or an absolute path. Callers of this function must not > 36123 ** attempt to treat it as a relative path name (i.e. they should simply use > 36124 ** it verbatim). > 36125 */ > 36126 if ( sqlite3Isalpha(zPathname[0]) && zPathname[1]==':' ){ > 36127 return TRUE; > 36128 } > 36129 > 36130 /* > 36131 ** If we get to this point, the path name should almost certainly be a purely > 36132 ** relative one (i.e. not a UNC name, not absolute, and not volume relative). > 36133 */ > 36134 return FALSE; > 36135 } 35604 36136 35605 /* 36137 /* 35606 ** Turn a relative pathname into a full pathname. Write the full 36138 ** Turn a relative pathname into a full pathname. Write the full 35607 ** pathname into zOut[]. zOut[] will be at least pVfs->mxPathname 36139 ** pathname into zOut[]. zOut[] will be at least pVfs->mxPathname 35608 ** bytes in size. 36140 ** bytes in size. 35609 */ 36141 */ 35610 static int winFullPathname( 36142 static int winFullPathname( ................................................................................................................................................................................ 35613 int nFull, /* Size of output buffer in bytes */ 36145 int nFull, /* Size of output buffer in bytes */ 35614 char *zFull /* Output buffer */ 36146 char *zFull /* Output buffer */ 35615 ){ 36147 ){ 35616 36148 35617 #if defined(__CYGWIN__) 36149 #if defined(__CYGWIN__) 35618 SimulateIOError( return SQLITE_ERROR ); 36150 SimulateIOError( return SQLITE_ERROR ); 35619 UNUSED_PARAMETER(nFull); 36151 UNUSED_PARAMETER(nFull); > 36152 assert( pVfs->mxPathname>=MAX_PATH ); > 36153 assert( nFull>=pVfs->mxPathname ); > 36154 if ( sqlite3_data_directory && !winIsVerbatimPathname(zRelative) ){ > 36155 /* > 36156 ** NOTE: We are dealing with a relative path name and the data > 36157 ** directory has been set. Therefore, use it as the basis > 36158 ** for converting the relative path name to an absolute > 36159 ** one by prepending the data directory and a slash. > 36160 */ > 36161 char zOut[MAX_PATH+1]; > 36162 memset(zOut, 0, MAX_PATH+1); > 36163 cygwin_conv_to_win32_path(zRelative, zOut); /* POSIX to Win32 */ > 36164 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s\\%s", > 36165 sqlite3_data_directory, zOut); > 36166 }else{ > 36167 /* > 36168 ** NOTE: The Cygwin docs state that the maximum length needed > 36169 ** for the buffer passed to cygwin_conv_to_full_win32_path > 36170 ** is MAX_PATH. > 36171 */ 35620 cygwin_conv_to_full_win32_path(zRelative, zFull); | 36172 cygwin_conv_to_full_win32_path(zRelative, zFull); > 36173 } 35621 return SQLITE_OK; 36174 return SQLITE_OK; 35622 #endif 36175 #endif 35623 36176 35624 #if SQLITE_OS_WINCE | 36177 #if (SQLITE_OS_WINCE || SQLITE_OS_WINRT) && !defined(__CYGWIN__) 35625 SimulateIOError( return SQLITE_ERROR ); 36178 SimulateIOError( return SQLITE_ERROR ); 35626 UNUSED_PARAMETER(nFull); < 35627 /* WinCE has no concept of a relative pathname, or so I am told. */ 36179 /* WinCE has no concept of a relative pathname, or so I am told. */ > 36180 /* WinRT has no way to convert a relative path to an absolute one. */ > 36181 if ( sqlite3_data_directory && !winIsVerbatimPathname(zRelative) ){ > 36182 /* > 36183 ** NOTE: We are dealing with a relative path name and the data > 36184 ** directory has been set. Therefore, use it as the basis > 36185 ** for converting the relative path name to an absolute > 36186 ** one by prepending the data directory and a backslash. > 36187 */ > 36188 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s\\%s", > 36189 sqlite3_data_directory, zRelative); > 36190 }else{ 35628 sqlite3_snprintf(pVfs->mxPathname, zFull, "%s", zRelative); | 36191 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zRelative); > 36192 } 35629 return SQLITE_OK; 36193 return SQLITE_OK; 35630 #endif 36194 #endif 35631 36195 35632 #if !SQLITE_OS_WINCE && !defined(__CYGWIN__) | 36196 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(__CYGWIN__) 35633 int nByte; 36197 int nByte; 35634 void *zConverted; 36198 void *zConverted; 35635 char *zOut; 36199 char *zOut; 35636 36200 35637 /* If this path name begins with "/X:", where "X" is any alphabetic 36201 /* If this path name begins with "/X:", where "X" is any alphabetic 35638 ** character, discard the initial "/" from the pathname. 36202 ** character, discard the initial "/" from the pathname. 35639 */ 36203 */ ................................................................................................................................................................................ 35643 36207 35644 /* It's odd to simulate an io-error here, but really this is just 36208 /* It's odd to simulate an io-error here, but really this is just 35645 ** using the io-error infrastructure to test that SQLite handles this 36209 ** using the io-error infrastructure to test that SQLite handles this 35646 ** function failing. This function could fail if, for example, the 36210 ** function failing. This function could fail if, for example, the 35647 ** current working directory has been unlinked. 36211 ** current working directory has been unlinked. 35648 */ 36212 */ 35649 SimulateIOError( return SQLITE_ERROR ); 36213 SimulateIOError( return SQLITE_ERROR ); 35650 UNUSED_PARAMETER(nFull); | 36214 if ( sqlite3_data_directory && !winIsVerbatimPathname(zRelative) ){ > 36215 /* > 36216 ** NOTE: We are dealing with a relative path name and the data > 36217 ** directory has been set. Therefore, use it as the basis > 36218 ** for converting the relative path name to an absolute > 36219 ** one by prepending the data directory and a backslash. > 36220 */ > 36221 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s\\%s", > 36222 sqlite3_data_directory, zRelative); > 36223 return SQLITE_OK; > 36224 } 35651 zConverted = convertUtf8Filename(zRelative); 36225 zConverted = convertUtf8Filename(zRelative); 35652 if( zConverted==0 ){ 36226 if( zConverted==0 ){ 35653 return SQLITE_IOERR_NOMEM; 36227 return SQLITE_IOERR_NOMEM; 35654 } 36228 } 35655 if( isNT() ){ 36229 if( isNT() ){ 35656 LPWSTR zTemp; 36230 LPWSTR zTemp; 35657 nByte = osGetFullPathNameW((LPCWSTR)zConverted, 0, 0, 0) + 3; 36231 nByte = osGetFullPathNameW((LPCWSTR)zConverted, 0, 0, 0) + 3; ................................................................................................................................................................................ 35660 sqlite3_free(zConverted); 36234 sqlite3_free(zConverted); 35661 return SQLITE_IOERR_NOMEM; 36235 return SQLITE_IOERR_NOMEM; 35662 } 36236 } 35663 osGetFullPathNameW((LPCWSTR)zConverted, nByte, zTemp, 0); 36237 osGetFullPathNameW((LPCWSTR)zConverted, nByte, zTemp, 0); 35664 sqlite3_free(zConverted); 36238 sqlite3_free(zConverted); 35665 zOut = unicodeToUtf8(zTemp); 36239 zOut = unicodeToUtf8(zTemp); 35666 sqlite3_free(zTemp); 36240 sqlite3_free(zTemp); 35667 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. < > 36241 } 35668 ** Since the ANSI version of these Windows API do not exist for WINCE, | 36242 #ifdef SQLITE_WIN32_HAS_ANSI 35669 ** it's important to not reference them for WINCE builds. < 35670 */ < 35671 #if SQLITE_OS_WINCE==0 < 35672 }else{ | 36243 else{ 35673 char *zTemp; 36244 char *zTemp; 35674 nByte = osGetFullPathNameA((char*)zConverted, 0, 0, 0) + 3; 36245 nByte = osGetFullPathNameA((char*)zConverted, 0, 0, 0) + 3; 35675 zTemp = sqlite3_malloc( nByte*sizeof(zTemp[0]) ); 36246 zTemp = sqlite3_malloc( nByte*sizeof(zTemp[0]) ); 35676 if( zTemp==0 ){ 36247 if( zTemp==0 ){ 35677 sqlite3_free(zConverted); 36248 sqlite3_free(zConverted); 35678 return SQLITE_IOERR_NOMEM; 36249 return SQLITE_IOERR_NOMEM; 35679 } 36250 } 35680 osGetFullPathNameA((char*)zConverted, nByte, zTemp, 0); 36251 osGetFullPathNameA((char*)zConverted, nByte, zTemp, 0); 35681 sqlite3_free(zConverted); 36252 sqlite3_free(zConverted); 35682 zOut = sqlite3_win32_mbcs_to_utf8(zTemp); 36253 zOut = sqlite3_win32_mbcs_to_utf8(zTemp); 35683 sqlite3_free(zTemp); 36254 sqlite3_free(zTemp); 35684 #endif < 35685 } 36255 } > 36256 #endif 35686 if( zOut ){ 36257 if( zOut ){ 35687 sqlite3_snprintf(pVfs->mxPathname, zFull, "%s", zOut); | 36258 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zOut); 35688 sqlite3_free(zOut); 36259 sqlite3_free(zOut); 35689 return SQLITE_OK; 36260 return SQLITE_OK; 35690 }else{ 36261 }else{ 35691 return SQLITE_IOERR_NOMEM; 36262 return SQLITE_IOERR_NOMEM; 35692 } 36263 } 35693 #endif 36264 #endif 35694 } 36265 } ................................................................................................................................................................................ 35706 HANDLE h; 36277 HANDLE h; 35707 void *zConverted = convertUtf8Filename(zFilename); 36278 void *zConverted = convertUtf8Filename(zFilename); 35708 UNUSED_PARAMETER(pVfs); 36279 UNUSED_PARAMETER(pVfs); 35709 if( zConverted==0 ){ 36280 if( zConverted==0 ){ 35710 return 0; 36281 return 0; 35711 } 36282 } 35712 if( isNT() ){ 36283 if( isNT() ){ 35713 h = osLoadLibraryW((LPCWSTR)zConverted); | 36284 #if SQLITE_OS_WINRT 35714 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. | 36285 h = osLoadPackagedLibrary((LPCWSTR)zConverted, 0); 35715 ** Since the ANSI version of these Windows API do not exist for WINCE, | 36286 #else 35716 ** it's important to not reference them for WINCE builds. | 36287 h = osLoadLibraryW((LPCWSTR)zConverted); 35717 */ | 36288 #endif 35718 #if SQLITE_OS_WINCE==0 | 36289 } 35719 }else{ | 36290 #ifdef SQLITE_WIN32_HAS_ANSI 35720 h = osLoadLibraryA((char*)zConverted); | 36291 else{ 35721 #endif | 36292 h = osLoadLibraryA((char*)zConverted); 35722 } | 36293 } > 36294 #endif 35723 sqlite3_free(zConverted); 36295 sqlite3_free(zConverted); 35724 return (void*)h; 36296 return (void*)h; 35725 } 36297 } 35726 static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){ 36298 static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){ 35727 UNUSED_PARAMETER(pVfs); 36299 UNUSED_PARAMETER(pVfs); 35728 getLastErrorMsg(osGetLastError(), nBuf, zBufOut); 36300 getLastErrorMsg(osGetLastError(), nBuf, zBufOut); 35729 } 36301 } ................................................................................................................................................................................ 35760 n += sizeof(x); 36332 n += sizeof(x); 35761 } 36333 } 35762 if( sizeof(DWORD)<=nBuf-n ){ 36334 if( sizeof(DWORD)<=nBuf-n ){ 35763 DWORD pid = osGetCurrentProcessId(); 36335 DWORD pid = osGetCurrentProcessId(); 35764 memcpy(&zBuf[n], &pid, sizeof(pid)); 36336 memcpy(&zBuf[n], &pid, sizeof(pid)); 35765 n += sizeof(pid); 36337 n += sizeof(pid); 35766 } 36338 } > 36339 #if SQLITE_OS_WINRT > 36340 if( sizeof(ULONGLONG)<=nBuf-n ){ > 36341 ULONGLONG cnt = osGetTickCount64(); > 36342 memcpy(&zBuf[n], &cnt, sizeof(cnt)); > 36343 n += sizeof(cnt); > 36344 } > 36345 #else 35767 if( sizeof(DWORD)<=nBuf-n ){ 36346 if( sizeof(DWORD)<=nBuf-n ){ 35768 DWORD cnt = osGetTickCount(); 36347 DWORD cnt = osGetTickCount(); 35769 memcpy(&zBuf[n], &cnt, sizeof(cnt)); 36348 memcpy(&zBuf[n], &cnt, sizeof(cnt)); 35770 n += sizeof(cnt); 36349 n += sizeof(cnt); 35771 } 36350 } > 36351 #endif 35772 if( sizeof(LARGE_INTEGER)<=nBuf-n ){ 36352 if( sizeof(LARGE_INTEGER)<=nBuf-n ){ 35773 LARGE_INTEGER i; 36353 LARGE_INTEGER i; 35774 osQueryPerformanceCounter(&i); 36354 osQueryPerformanceCounter(&i); 35775 memcpy(&zBuf[n], &i, sizeof(i)); 36355 memcpy(&zBuf[n], &i, sizeof(i)); 35776 n += sizeof(i); 36356 n += sizeof(i); 35777 } 36357 } 35778 #endif 36358 #endif ................................................................................................................................................................................ 35780 } 36360 } 35781 36361 35782 36362 35783 /* 36363 /* 35784 ** Sleep for a little while. Return the amount of time slept. 36364 ** Sleep for a little while. Return the amount of time slept. 35785 */ 36365 */ 35786 static int winSleep(sqlite3_vfs *pVfs, int microsec){ 36366 static int winSleep(sqlite3_vfs *pVfs, int microsec){ 35787 osSleep((microsec+999)/1000); | 36367 sqlite3_win32_sleep((microsec+999)/1000); 35788 UNUSED_PARAMETER(pVfs); 36368 UNUSED_PARAMETER(pVfs); 35789 return ((microsec+999)/1000)*1000; 36369 return ((microsec+999)/1000)*1000; 35790 } 36370 } 35791 36371 35792 /* 36372 /* 35793 ** The following variable, if set to a non-zero value, is interpreted as 36373 ** The following variable, if set to a non-zero value, is interpreted as 35794 ** the number of seconds since 1970 and is used to set the result of 36374 ** the number of seconds since 1970 and is used to set the result of ................................................................................................................................................................................ 35922 winSetSystemCall, /* xSetSystemCall */ 36502 winSetSystemCall, /* xSetSystemCall */ 35923 winGetSystemCall, /* xGetSystemCall */ 36503 winGetSystemCall, /* xGetSystemCall */ 35924 winNextSystemCall, /* xNextSystemCall */ 36504 winNextSystemCall, /* xNextSystemCall */ 35925 }; 36505 }; 35926 36506 35927 /* Double-check that the aSyscall[] array has been constructed 36507 /* Double-check that the aSyscall[] array has been constructed 35928 ** correctly. See ticket [bb3a86e890c8e96ab] */ 36508 ** correctly. See ticket [bb3a86e890c8e96ab] */ 35929 assert( ArraySize(aSyscall)==60 ); | 36509 assert( ArraySize(aSyscall)==73 ); 35930 36510 35931 #ifndef SQLITE_OMIT_WAL 36511 #ifndef SQLITE_OMIT_WAL 35932 /* get memory map allocation granularity */ 36512 /* get memory map allocation granularity */ 35933 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO)); 36513 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO)); > 36514 #if SQLITE_OS_WINRT > 36515 osGetNativeSystemInfo(&winSysInfo); > 36516 #else 35934 osGetSystemInfo(&winSysInfo); 36517 osGetSystemInfo(&winSysInfo); > 36518 #endif 35935 assert(winSysInfo.dwAllocationGranularity > 0); 36519 assert(winSysInfo.dwAllocationGranularity > 0); 35936 #endif 36520 #endif 35937 36521 35938 sqlite3_vfs_register(&winVfs, 1); 36522 sqlite3_vfs_register(&winVfs, 1); 35939 return SQLITE_OK; 36523 return SQLITE_OK; 35940 } 36524 } 35941 36525 35942 SQLITE_API int sqlite3_os_end(void){ 36526 SQLITE_API int sqlite3_os_end(void){ > 36527 #if SQLITE_OS_WINRT > 36528 if( sleepObj != NULL ){ > 36529 osCloseHandle(sleepObj); > 36530 sleepObj = NULL; > 36531 } > 36532 #endif 35943 return SQLITE_OK; 36533 return SQLITE_OK; 35944 } 36534 } 35945 36535 35946 #endif /* SQLITE_OS_WIN */ 36536 #endif /* SQLITE_OS_WIN */ 35947 36537 35948 /************** End of os_win.c **********************************************/ 36538 /************** End of os_win.c **********************************************/ 35949 /************** Begin file bitvec.c ******************************************/ 36539 /************** Begin file bitvec.c ******************************************/ ................................................................................................................................................................................ 37187 sqlite3_mutex_leave(pcache1.mutex); 37777 sqlite3_mutex_leave(pcache1.mutex); 37188 } 37778 } 37189 if( p==0 ){ 37779 if( p==0 ){ 37190 /* Memory is not available in the SQLITE_CONFIG_PAGECACHE pool. Get 37780 /* Memory is not available in the SQLITE_CONFIG_PAGECACHE pool. Get 37191 ** it from sqlite3Malloc instead. 37781 ** it from sqlite3Malloc instead. 37192 */ 37782 */ 37193 p = sqlite3Malloc(nByte); 37783 p = sqlite3Malloc(nByte); > 37784 #ifndef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS 37194 if( p ){ 37785 if( p ){ 37195 int sz = sqlite3MallocSize(p); 37786 int sz = sqlite3MallocSize(p); 37196 sqlite3_mutex_enter(pcache1.mutex); 37787 sqlite3_mutex_enter(pcache1.mutex); 37197 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz); 37788 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz); 37198 sqlite3_mutex_leave(pcache1.mutex); 37789 sqlite3_mutex_leave(pcache1.mutex); 37199 } 37790 } > 37791 #endif 37200 sqlite3MemdebugSetType(p, MEMTYPE_PCACHE); 37792 sqlite3MemdebugSetType(p, MEMTYPE_PCACHE); 37201 } 37793 } 37202 return p; 37794 return p; 37203 } 37795 } 37204 37796 37205 /* 37797 /* 37206 ** Free an allocated buffer obtained from pcache1Alloc(). 37798 ** Free an allocated buffer obtained from pcache1Alloc(). ................................................................................................................................................................................ 37219 pcache1.bUnderPressure = pcache1.nFreeSlot<pcache1.nReserve; 37811 pcache1.bUnderPressure = pcache1.nFreeSlot<pcache1.nReserve; 37220 assert( pcache1.nFreeSlot<=pcache1.nSlot ); 37812 assert( pcache1.nFreeSlot<=pcache1.nSlot ); 37221 sqlite3_mutex_leave(pcache1.mutex); 37813 sqlite3_mutex_leave(pcache1.mutex); 37222 }else{ 37814 }else{ 37223 assert( sqlite3MemdebugHasType(p, MEMTYPE_PCACHE) ); 37815 assert( sqlite3MemdebugHasType(p, MEMTYPE_PCACHE) ); 37224 sqlite3MemdebugSetType(p, MEMTYPE_HEAP); 37816 sqlite3MemdebugSetType(p, MEMTYPE_HEAP); 37225 nFreed = sqlite3MallocSize(p); 37817 nFreed = sqlite3MallocSize(p); > 37818 #ifndef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS 37226 sqlite3_mutex_enter(pcache1.mutex); 37819 sqlite3_mutex_enter(pcache1.mutex); 37227 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -nFreed); 37820 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -nFreed); 37228 sqlite3_mutex_leave(pcache1.mutex); 37821 sqlite3_mutex_leave(pcache1.mutex); > 37822 #endif 37229 sqlite3_free(p); 37823 sqlite3_free(p); 37230 } 37824 } 37231 return nFreed; 37825 return nFreed; 37232 } 37826 } 37233 37827 37234 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT 37828 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT 37235 /* 37829 /* ................................................................................................................................................................................ 43004 43598 43005 /* Set the output variable to NULL in case an error occurs. */ 43599 /* Set the output variable to NULL in case an error occurs. */ 43006 *ppPager = 0; 43600 *ppPager = 0; 43007 43601 43008 #ifndef SQLITE_OMIT_MEMORYDB 43602 #ifndef SQLITE_OMIT_MEMORYDB 43009 if( flags & PAGER_MEMORY ){ 43603 if( flags & PAGER_MEMORY ){ 43010 memDb = 1; 43604 memDb = 1; > 43605 if( zFilename && zFilename[0] ){ > 43606 zPathname = sqlite3DbStrDup(0, zFilename); > 43607 if( zPathname==0 ) return SQLITE_NOMEM; > 43608 nPathname = sqlite3Strlen30(zPathname); 43011 zFilename = 0; | 43609 zFilename = 0; > 43610 } 43012 } 43611 } 43013 #endif 43612 #endif 43014 43613 43015 /* Compute and store the full pathname in an allocated buffer pointed 43614 /* Compute and store the full pathname in an allocated buffer pointed 43016 ** to by zPathname, length nPathname. Or, if this is a temporary file, 43615 ** to by zPathname, length nPathname. Or, if this is a temporary file, 43017 ** leave both nPathname and zPathname set to 0. 43616 ** leave both nPathname and zPathname set to 0. 43018 */ 43617 */ 43019 if( zFilename && zFilename[0] ){ 43618 if( zFilename && zFilename[0] ){ 43020 const char *z; 43619 const char *z; 43021 nPathname = pVfs->mxPathname+1; 43620 nPathname = pVfs->mxPathname+1; 43022 zPathname = sqlite3Malloc(nPathname*2); | 43621 zPathname = sqlite3DbMallocRaw(0, nPathname*2); 43023 if( zPathname==0 ){ 43622 if( zPathname==0 ){ 43024 return SQLITE_NOMEM; 43623 return SQLITE_NOMEM; 43025 } 43624 } 43026 zPathname[0] = 0; /* Make sure initialized even if FullPathname() fails */ 43625 zPathname[0] = 0; /* Make sure initialized even if FullPathname() fails */ 43027 rc = sqlite3OsFullPathname(pVfs, zFilename, nPathname, zPathname); 43626 rc = sqlite3OsFullPathname(pVfs, zFilename, nPathname, zPathname); 43028 nPathname = sqlite3Strlen30(zPathname); 43627 nPathname = sqlite3Strlen30(zPathname); 43029 z = zUri = &zFilename[sqlite3Strlen30(zFilename)+1]; 43628 z = zUri = &zFilename[sqlite3Strlen30(zFilename)+1]; ................................................................................................................................................................................ 43039 ** bytes in length. This means the database cannot be opened, 43638 ** bytes in length. This means the database cannot be opened, 43040 ** as it will not be possible to open the journal file or even 43639 ** as it will not be possible to open the journal file or even 43041 ** check for a hot-journal before reading. 43640 ** check for a hot-journal before reading. 43042 */ 43641 */ 43043 rc = SQLITE_CANTOPEN_BKPT; 43642 rc = SQLITE_CANTOPEN_BKPT; 43044 } 43643 } 43045 if( rc!=SQLITE_OK ){ 43644 if( rc!=SQLITE_OK ){ 43046 sqlite3_free(zPathname); | 43645 sqlite3DbFree(0, zPathname); 43047 return rc; 43646 return rc; 43048 } 43647 } 43049 } 43648 } 43050 43649 43051 /* Allocate memory for the Pager structure, PCache object, the 43650 /* Allocate memory for the Pager structure, PCache object, the 43052 ** three file descriptors, the database file name and the journal 43651 ** three file descriptors, the database file name and the journal 43053 ** file name. The layout in memory is as follows: 43652 ** file name. The layout in memory is as follows: ................................................................................................................................................................................ 43069 nPathname + 8 + 2 /* zJournal */ 43668 nPathname + 8 + 2 /* zJournal */ 43070 #ifndef SQLITE_OMIT_WAL 43669 #ifndef SQLITE_OMIT_WAL 43071 + nPathname + 4 + 2 /* zWal */ 43670 + nPathname + 4 + 2 /* zWal */ 43072 #endif 43671 #endif 43073 ); 43672 ); 43074 assert( EIGHT_BYTE_ALIGNMENT(SQLITE_INT_TO_PTR(journalFileSize)) ); 43673 assert( EIGHT_BYTE_ALIGNMENT(SQLITE_INT_TO_PTR(journalFileSize)) ); 43075 if( !pPtr ){ 43674 if( !pPtr ){ 43076 sqlite3_free(zPathname); | 43675 sqlite3DbFree(0, zPathname); 43077 return SQLITE_NOMEM; 43676 return SQLITE_NOMEM; 43078 } 43677 } 43079 pPager = (Pager*)(pPtr); 43678 pPager = (Pager*)(pPtr); 43080 pPager->pPCache = (PCache*)(pPtr += ROUND8(sizeof(*pPager))); 43679 pPager->pPCache = (PCache*)(pPtr += ROUND8(sizeof(*pPager))); 43081 pPager->fd = (sqlite3_file*)(pPtr += ROUND8(pcacheSize)); 43680 pPager->fd = (sqlite3_file*)(pPtr += ROUND8(pcacheSize)); 43082 pPager->sjfd = (sqlite3_file*)(pPtr += ROUND8(pVfs->szOsFile)); 43681 pPager->sjfd = (sqlite3_file*)(pPtr += ROUND8(pVfs->szOsFile)); 43083 pPager->jfd = (sqlite3_file*)(pPtr += journalFileSize); 43682 pPager->jfd = (sqlite3_file*)(pPtr += journalFileSize); ................................................................................................................................................................................ 43085 assert( EIGHT_BYTE_ALIGNMENT(pPager->jfd) ); 43684 assert( EIGHT_BYTE_ALIGNMENT(pPager->jfd) ); 43086 43685 43087 /* Fill in the Pager.zFilename and Pager.zJournal buffers, if required. */ 43686 /* Fill in the Pager.zFilename and Pager.zJournal buffers, if required. */ 43088 if( zPathname ){ 43687 if( zPathname ){ 43089 assert( nPathname>0 ); 43688 assert( nPathname>0 ); 43090 pPager->zJournal = (char*)(pPtr += nPathname + 1 + nUri); 43689 pPager->zJournal = (char*)(pPtr += nPathname + 1 + nUri); 43091 memcpy(pPager->zFilename, zPathname, nPathname); 43690 memcpy(pPager->zFilename, zPathname, nPathname); 43092 memcpy(&pPager->zFilename[nPathname+1], zUri, nUri); | 43691 if( nUri ) memcpy(&pPager->zFilename[nPathname+1], zUri, nUri); 43093 memcpy(pPager->zJournal, zPathname, nPathname); 43692 memcpy(pPager->zJournal, zPathname, nPathname); 43094 memcpy(&pPager->zJournal[nPathname], "-journal\000", 8+1); 43693 memcpy(&pPager->zJournal[nPathname], "-journal\000", 8+1); 43095 sqlite3FileSuffix3(pPager->zFilename, pPager->zJournal); 43694 sqlite3FileSuffix3(pPager->zFilename, pPager->zJournal); 43096 #ifndef SQLITE_OMIT_WAL 43695 #ifndef SQLITE_OMIT_WAL 43097 pPager->zWal = &pPager->zJournal[nPathname+8+1]; 43696 pPager->zWal = &pPager->zJournal[nPathname+8+1]; 43098 memcpy(pPager->zWal, zPathname, nPathname); 43697 memcpy(pPager->zWal, zPathname, nPathname); 43099 memcpy(&pPager->zWal[nPathname], "-wal\000", 4+1); 43698 memcpy(&pPager->zWal[nPathname], "-wal\000", 4+1); 43100 sqlite3FileSuffix3(pPager->zFilename, pPager->zWal); 43699 sqlite3FileSuffix3(pPager->zFilename, pPager->zWal); 43101 #endif 43700 #endif 43102 sqlite3_free(zPathname); | 43701 sqlite3DbFree(0, zPathname); 43103 } 43702 } 43104 pPager->pVfs = pVfs; 43703 pPager->pVfs = pVfs; 43105 pPager->vfsFlags = vfsFlags; 43704 pPager->vfsFlags = vfsFlags; 43106 43705 43107 /* Open the pager file. 43706 /* Open the pager file. 43108 */ 43707 */ 43109 if( zFilename && zFilename[0] ){ 43708 if( zFilename && zFilename[0] ){ ................................................................................................................................................................................ 44940 } 45539 } 44941 45540 44942 return rc; 45541 return rc; 44943 } 45542 } 44944 45543 44945 /* 45544 /* 44946 ** Return the full pathname of the database file. 45545 ** Return the full pathname of the database file. > 45546 ** > 45547 ** Except, if the pager is in-memory only, then return an empty string if > 45548 ** nullIfMemDb is true. This routine is called with nullIfMemDb==1 when > 45549 ** used to report the filename to the user, for compatibility with legacy > 45550 ** behavior. But when the Btree needs to know the filename for matching to > 45551 ** shared cache, it uses nullIfMemDb==0 so that in-memory databases can > 45552 ** participate in shared-cache. 44947 */ 45553 */ 44948 SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager *pPager){ | 45554 SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager *pPager, int nullIfMemDb){ 44949 return pPager->zFilename; | 45555 return (nullIfMemDb && pPager->memDb) ? "" : pPager->zFilename; 44950 } 45556 } 44951 45557 44952 /* 45558 /* 44953 ** Return the VFS structure for the pager. 45559 ** Return the VFS structure for the pager. 44954 */ 45560 */ 44955 SQLITE_PRIVATE const sqlite3_vfs *sqlite3PagerVfs(Pager *pPager){ 45561 SQLITE_PRIVATE const sqlite3_vfs *sqlite3PagerVfs(Pager *pPager){ 44956 return pPager->pVfs; 45562 return pPager->pVfs; ................................................................................................................................................................................ 51327 /* Set the variable isMemdb to true for an in-memory database, or 51933 /* Set the variable isMemdb to true for an in-memory database, or 51328 ** false for a file-based database. 51934 ** false for a file-based database. 51329 */ 51935 */ 51330 #ifdef SQLITE_OMIT_MEMORYDB 51936 #ifdef SQLITE_OMIT_MEMORYDB 51331 const int isMemdb = 0; 51937 const int isMemdb = 0; 51332 #else 51938 #else 51333 const int isMemdb = (zFilename && strcmp(zFilename, ":memory:")==0) 51939 const int isMemdb = (zFilename && strcmp(zFilename, ":memory:")==0) 51334 || (isTempDb && sqlite3TempInMemory(db)); | 51940 || (isTempDb && sqlite3TempInMemory(db)) > 51941 || (vfsFlags & SQLITE_OPEN_MEMORY)!=0; 51335 #endif 51942 #endif 51336 51943 51337 assert( db!=0 ); 51944 assert( db!=0 ); 51338 assert( pVfs!=0 ); 51945 assert( pVfs!=0 ); 51339 assert( sqlite3_mutex_held(db->mutex) ); 51946 assert( sqlite3_mutex_held(db->mutex) ); 51340 assert( (flags&0xff)==flags ); /* flags fit in 8 bits */ 51947 assert( (flags&0xff)==flags ); /* flags fit in 8 bits */ 51341 51948 ................................................................................................................................................................................ 51363 #endif 51970 #endif 51364 51971 51365 #if !defined(SQLITE_OMIT_SHARED_CACHE) && !defined(SQLITE_OMIT_DISKIO) 51972 #if !defined(SQLITE_OMIT_SHARED_CACHE) && !defined(SQLITE_OMIT_DISKIO) 51366 /* 51973 /* 51367 ** If this Btree is a candidate for shared cache, try to find an 51974 ** If this Btree is a candidate for shared cache, try to find an 51368 ** existing BtShared object that we can share with 51975 ** existing BtShared object that we can share with 51369 */ 51976 */ 51370 if( isMemdb==0 && isTempDb==0 ){ | 51977 if( isTempDb==0 && (isMemdb==0 || (vfsFlags&SQLITE_OPEN_URI)!=0) ){ 51371 if( vfsFlags & SQLITE_OPEN_SHAREDCACHE ){ 51978 if( vfsFlags & SQLITE_OPEN_SHAREDCACHE ){ 51372 int nFullPathname = pVfs->mxPathname+1; 51979 int nFullPathname = pVfs->mxPathname+1; 51373 char *zFullPathname = sqlite3Malloc(nFullPathname); 51980 char *zFullPathname = sqlite3Malloc(nFullPathname); 51374 MUTEX_LOGIC( sqlite3_mutex *mutexShared; ) 51981 MUTEX_LOGIC( sqlite3_mutex *mutexShared; ) 51375 p->sharable = 1; 51982 p->sharable = 1; 51376 if( !zFullPathname ){ 51983 if( !zFullPathname ){ 51377 sqlite3_free(p); 51984 sqlite3_free(p); 51378 return SQLITE_NOMEM; 51985 return SQLITE_NOMEM; 51379 } 51986 } > 51987 if( isMemdb ){ > 51988 memcpy(zFullPathname, zFilename, sqlite3Strlen30(zFilename)+1); > 51989 }else{ 51380 rc = sqlite3OsFullPathname(pVfs, zFilename, nFullPathname, zFullPathname); | 51990 rc = sqlite3OsFullPathname(pVfs, zFilename, > 51991 nFullPathname, zFullPathname); 51381 if( rc ){ | 51992 if( rc ){ 51382 sqlite3_free(zFullPathname); | 51993 sqlite3_free(zFullPathname); 51383 sqlite3_free(p); | 51994 sqlite3_free(p); 51384 return rc; | 51995 return rc; > 51996 } 51385 } 51997 } 51386 #if SQLITE_THREADSAFE 51998 #if SQLITE_THREADSAFE 51387 mutexOpen = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_OPEN); 51999 mutexOpen = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_OPEN); 51388 sqlite3_mutex_enter(mutexOpen); 52000 sqlite3_mutex_enter(mutexOpen); 51389 mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); 52001 mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); 51390 sqlite3_mutex_enter(mutexShared); 52002 sqlite3_mutex_enter(mutexShared); 51391 #endif 52003 #endif 51392 for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){ 52004 for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){ 51393 assert( pBt->nRef>0 ); 52005 assert( pBt->nRef>0 ); 51394 if( 0==strcmp(zFullPathname, sqlite3PagerFilename(pBt->pPager)) | 52006 if( 0==strcmp(zFullPathname, sqlite3PagerFilename(pBt->pPager, 0)) 51395 && sqlite3PagerVfs(pBt->pPager)==pVfs ){ 52007 && sqlite3PagerVfs(pBt->pPager)==pVfs ){ 51396 int iDb; 52008 int iDb; 51397 for(iDb=db->nDb-1; iDb>=0; iDb--){ 52009 for(iDb=db->nDb-1; iDb>=0; iDb--){ 51398 Btree *pExisting = db->aDb[iDb].pBt; 52010 Btree *pExisting = db->aDb[iDb].pBt; 51399 if( pExisting && pExisting->pBt==pBt ){ 52011 if( pExisting && pExisting->pBt==pBt ){ 51400 sqlite3_mutex_leave(mutexShared); 52012 sqlite3_mutex_leave(mutexShared); 51401 sqlite3_mutex_leave(mutexOpen); 52013 sqlite3_mutex_leave(mutexOpen); ................................................................................................................................................................................ 57652 *pnErr = sCheck.nErr; 58264 *pnErr = sCheck.nErr; 57653 if( sCheck.nErr==0 ) sqlite3StrAccumReset(&sCheck.errMsg); 58265 if( sCheck.nErr==0 ) sqlite3StrAccumReset(&sCheck.errMsg); 57654 return sqlite3StrAccumFinish(&sCheck.errMsg); 58266 return sqlite3StrAccumFinish(&sCheck.errMsg); 57655 } 58267 } 57656 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ 58268 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ 57657 58269 57658 /* 58270 /* 57659 ** Return the full pathname of the underlying database file. | 58271 ** Return the full pathname of the underlying database file. Return > 58272 ** an empty string if the database is in-memory or a TEMP database. 57660 ** 58273 ** 57661 ** The pager filename is invariant as long as the pager is 58274 ** The pager filename is invariant as long as the pager is 57662 ** open so it is safe to access without the BtShared mutex. 58275 ** open so it is safe to access without the BtShared mutex. 57663 */ 58276 */ 57664 SQLITE_PRIVATE const char *sqlite3BtreeGetFilename(Btree *p){ 58277 SQLITE_PRIVATE const char *sqlite3BtreeGetFilename(Btree *p){ 57665 assert( p->pBt->pPager!=0 ); 58278 assert( p->pBt->pPager!=0 ); 57666 return sqlite3PagerFilename(p->pBt->pPager); | 58279 return sqlite3PagerFilename(p->pBt->pPager, 1); 57667 } 58280 } 57668 58281 57669 /* 58282 /* 57670 ** Return the pathname of the journal file for this database. The return 58283 ** Return the pathname of the journal file for this database. The return 57671 ** value of this routine is the same regardless of whether the journal file 58284 ** value of this routine is the same regardless of whether the journal file 57672 ** has been created or not. 58285 ** has been created or not. 57673 ** 58286 ** ................................................................................................................................................................................ 58310 ** the case where the source and destination databases have the 58923 ** the case where the source and destination databases have the 58311 ** same schema version. 58924 ** same schema version. 58312 */ 58925 */ 58313 if( rc==SQLITE_DONE ){ 58926 if( rc==SQLITE_DONE ){ 58314 rc = sqlite3BtreeUpdateMeta(p->pDest,1,p->iDestSchema+1); 58927 rc = sqlite3BtreeUpdateMeta(p->pDest,1,p->iDestSchema+1); 58315 if( rc==SQLITE_OK ){ 58928 if( rc==SQLITE_OK ){ 58316 if( p->pDestDb ){ 58929 if( p->pDestDb ){ 58317 sqlite3ResetInternalSchema(p->pDestDb, -1); | 58930 sqlite3ResetAllSchemasOfConnection(p->pDestDb); 58318 } 58931 } 58319 if( destMode==PAGER_JOURNALMODE_WAL ){ 58932 if( destMode==PAGER_JOURNALMODE_WAL ){ 58320 rc = sqlite3BtreeSetVersion(p->pDest, 2); 58933 rc = sqlite3BtreeSetVersion(p->pDest, 2); 58321 } 58934 } 58322 } 58935 } 58323 if( rc==SQLITE_OK ){ 58936 if( rc==SQLITE_OK ){ 58324 int nDestTruncate; 58937 int nDestTruncate; ................................................................................................................................................................................ 64495 #if defined(SQLITE_ENABLE_TREE_EXPLAIN) 65108 #if defined(SQLITE_ENABLE_TREE_EXPLAIN) 64496 65109 64497 /* 65110 /* 64498 ** Allocate a new Explain object 65111 ** Allocate a new Explain object 64499 */ 65112 */ 64500 SQLITE_PRIVATE void sqlite3ExplainBegin(Vdbe *pVdbe){ 65113 SQLITE_PRIVATE void sqlite3ExplainBegin(Vdbe *pVdbe){ 64501 if( pVdbe ){ 65114 if( pVdbe ){ > 65115 Explain *p; 64502 sqlite3BeginBenignMalloc(); 65116 sqlite3BeginBenignMalloc(); 64503 Explain *p = sqlite3_malloc( sizeof(Explain) ); | 65117 p = sqlite3_malloc( sizeof(Explain) ); 64504 if( p ){ 65118 if( p ){ 64505 memset(p, 0, sizeof(*p)); 65119 memset(p, 0, sizeof(*p)); 64506 p->pVdbe = pVdbe; 65120 p->pVdbe = pVdbe; 64507 sqlite3_free(pVdbe->pExplain); 65121 sqlite3_free(pVdbe->pExplain); 64508 pVdbe->pExplain = p; 65122 pVdbe->pExplain = p; 64509 sqlite3StrAccumInit(&p->str, p->zBase, sizeof(p->zBase), 65123 sqlite3StrAccumInit(&p->str, p->zBase, sizeof(p->zBase), 64510 SQLITE_MAX_LENGTH); 65124 SQLITE_MAX_LENGTH); ................................................................................................................................................................................ 67894 rc = sqlite3BtreeSavepoint(db->aDb[u.ar.ii].pBt, u.ar.p1, u.ar.iSavepo 68508 rc = sqlite3BtreeSavepoint(db->aDb[u.ar.ii].pBt, u.ar.p1, u.ar.iSavepo 67895 if( rc!=SQLITE_OK ){ 68509 if( rc!=SQLITE_OK ){ 67896 goto abort_due_to_error; 68510 goto abort_due_to_error; 67897 } 68511 } 67898 } 68512 } 67899 if( u.ar.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ) 68513 if( u.ar.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ) 67900 sqlite3ExpirePreparedStatements(db); 68514 sqlite3ExpirePreparedStatements(db); 67901 sqlite3ResetInternalSchema(db, -1); | 68515 sqlite3ResetAllSchemasOfConnection(db); 67902 db->flags = (db->flags | SQLITE_InternChanges); 68516 db->flags = (db->flags | SQLITE_InternChanges); 67903 } 68517 } 67904 } 68518 } 67905 68519 67906 /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all 68520 /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all 67907 ** savepoints nested inside of the savepoint being operated on. */ 68521 ** savepoints nested inside of the savepoint being operated on. */ 67908 while( db->pSavepoint!=u.ar.pSavepoint ){ 68522 while( db->pSavepoint!=u.ar.pSavepoint ){ ................................................................................................................................................................................ 68208 ** prepared queries. If such a query is out-of-date, we do not want to 68822 ** prepared queries. If such a query is out-of-date, we do not want to 68209 ** discard the database schema, as the user code implementing the 68823 ** discard the database schema, as the user code implementing the 68210 ** v-table would have to be ready for the sqlite3_vtab structure itself 68824 ** v-table would have to be ready for the sqlite3_vtab structure itself 68211 ** to be invalidated whenever sqlite3_step() is called from within 68825 ** to be invalidated whenever sqlite3_step() is called from within 68212 ** a v-table method. 68826 ** a v-table method. 68213 */ 68827 */ 68214 if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.aw.iMeta ){ 68828 if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.aw.iMeta ){ 68215 sqlite3ResetInternalSchema(db, pOp->p1); | 68829 sqlite3ResetOneSchema(db, pOp->p1); 68216 } 68830 } 68217 68831 68218 p->expired = 1; 68832 p->expired = 1; 68219 rc = SQLITE_SCHEMA; 68833 rc = SQLITE_SCHEMA; 68220 } 68834 } 68221 break; 68835 break; 68222 } 68836 } ................................................................................................................................................................................ 70077 assert( !db->mallocFailed ); 70691 assert( !db->mallocFailed ); 70078 rc = sqlite3_exec(db, u.by.zSql, sqlite3InitCallback, &u.by.initData, 0); 70692 rc = sqlite3_exec(db, u.by.zSql, sqlite3InitCallback, &u.by.initData, 0); 70079 if( rc==SQLITE_OK ) rc = u.by.initData.rc; 70693 if( rc==SQLITE_OK ) rc = u.by.initData.rc; 70080 sqlite3DbFree(db, u.by.zSql); 70694 sqlite3DbFree(db, u.by.zSql); 70081 db->init.busy = 0; 70695 db->init.busy = 0; 70082 } 70696 } 70083 } 70697 } 70084 if( rc ) sqlite3ResetInternalSchema(db, -1); | 70698 if( rc ) sqlite3ResetAllSchemasOfConnection(db); 70085 if( rc==SQLITE_NOMEM ){ 70699 if( rc==SQLITE_NOMEM ){ 70086 goto no_mem; 70700 goto no_mem; 70087 } 70701 } 70088 break; 70702 break; 70089 } 70703 } 70090 70704 70091 #if !defined(SQLITE_OMIT_ANALYZE) 70705 #if !defined(SQLITE_OMIT_ANALYZE) ................................................................................................................................................................................ 70744 u.ci.pBt = db->aDb[pOp->p1].pBt; 71358 u.ci.pBt = db->aDb[pOp->p1].pBt; 70745 u.ci.pPager = sqlite3BtreePager(u.ci.pBt); 71359 u.ci.pPager = sqlite3BtreePager(u.ci.pBt); 70746 u.ci.eOld = sqlite3PagerGetJournalMode(u.ci.pPager); 71360 u.ci.eOld = sqlite3PagerGetJournalMode(u.ci.pPager); 70747 if( u.ci.eNew==PAGER_JOURNALMODE_QUERY ) u.ci.eNew = u.ci.eOld; 71361 if( u.ci.eNew==PAGER_JOURNALMODE_QUERY ) u.ci.eNew = u.ci.eOld; 70748 if( !sqlite3PagerOkToChangeJournalMode(u.ci.pPager) ) u.ci.eNew = u.ci.eOld; 71362 if( !sqlite3PagerOkToChangeJournalMode(u.ci.pPager) ) u.ci.eNew = u.ci.eOld; 70749 71363 70750 #ifndef SQLITE_OMIT_WAL 71364 #ifndef SQLITE_OMIT_WAL 70751 u.ci.zFilename = sqlite3PagerFilename(u.ci.pPager); | 71365 u.ci.zFilename = sqlite3PagerFilename(u.ci.pPager, 1); 70752 71366 70753 /* Do not allow a transition to journal_mode=WAL for a database 71367 /* Do not allow a transition to journal_mode=WAL for a database 70754 ** in temporary storage or if the VFS does not support shared memory 71368 ** in temporary storage or if the VFS does not support shared memory 70755 */ 71369 */ 70756 if( u.ci.eNew==PAGER_JOURNALMODE_WAL 71370 if( u.ci.eNew==PAGER_JOURNALMODE_WAL 70757 && (sqlite3Strlen30(u.ci.zFilename)==0 /* Temp file */ 71371 && (sqlite3Strlen30(u.ci.zFilename)==0 /* Temp file */ 70758 || !sqlite3PagerWalSupported(u.ci.pPager)) /* No shared-memory support 71372 || !sqlite3PagerWalSupported(u.ci.pPager)) /* No shared-memory support ................................................................................................................................................................................ 71410 testcase( sqlite3GlobalConfig.xLog!=0 ); 72024 testcase( sqlite3GlobalConfig.xLog!=0 ); 71411 sqlite3_log(rc, "statement aborts at %d: [%s] %s", 72025 sqlite3_log(rc, "statement aborts at %d: [%s] %s", 71412 pc, p->zSql, p->zErrMsg); 72026 pc, p->zSql, p->zErrMsg); 71413 sqlite3VdbeHalt(p); 72027 sqlite3VdbeHalt(p); 71414 if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1; 72028 if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1; 71415 rc = SQLITE_ERROR; 72029 rc = SQLITE_ERROR; 71416 if( resetSchemaOnFault>0 ){ 72030 if( resetSchemaOnFault>0 ){ 71417 sqlite3ResetInternalSchema(db, resetSchemaOnFault-1); | 72031 sqlite3ResetOneSchema(db, resetSchemaOnFault-1); 71418 } 72032 } 71419 72033 71420 /* This is the only way out of this procedure. We have to 72034 /* This is the only way out of this procedure. We have to 71421 ** release the mutexes on btrees that were acquired at the 72035 ** release the mutexes on btrees that were acquired at the 71422 ** top. */ 72036 ** top. */ 71423 vdbe_return: 72037 vdbe_return: 71424 db->lastRowid = lastRowid; 72038 db->lastRowid = lastRowid; ................................................................................................................................................................................ 73765 char *zAs = pEList->a[j].zName; 74379 char *zAs = pEList->a[j].zName; 73766 if( zAs!=0 && sqlite3StrICmp(zAs, zCol)==0 ){ 74380 if( zAs!=0 && sqlite3StrICmp(zAs, zCol)==0 ){ 73767 Expr *pOrig; 74381 Expr *pOrig; 73768 assert( pExpr->pLeft==0 && pExpr->pRight==0 ); 74382 assert( pExpr->pLeft==0 && pExpr->pRight==0 ); 73769 assert( pExpr->x.pList==0 ); 74383 assert( pExpr->x.pList==0 ); 73770 assert( pExpr->x.pSelect==0 ); 74384 assert( pExpr->x.pSelect==0 ); 73771 pOrig = pEList->a[j].pExpr; 74385 pOrig = pEList->a[j].pExpr; 73772 if( !pNC->allowAgg && ExprHasProperty(pOrig, EP_Agg) ){ | 74386 if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){ 73773 sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs); 74387 sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs); 73774 return WRC_Abort; 74388 return WRC_Abort; 73775 } 74389 } 73776 resolveAlias(pParse, pEList, j, pExpr, ""); 74390 resolveAlias(pParse, pEList, j, pExpr, ""); 73777 cnt = 1; 74391 cnt = 1; 73778 pMatch = 0; 74392 pMatch = 0; 73779 assert( zTab==0 && zDb==0 ); 74393 assert( zTab==0 && zDb==0 ); ................................................................................................................................................................................ 74010 pNC->nErr++; 74624 pNC->nErr++; 74011 } 74625 } 74012 pExpr->op = TK_NULL; 74626 pExpr->op = TK_NULL; 74013 return WRC_Prune; 74627 return WRC_Prune; 74014 } 74628 } 74015 } 74629 } 74016 #endif 74630 #endif 74017 if( is_agg && !pNC->allowAgg ){ | 74631 if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){ 74018 sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId); 74632 sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId); 74019 pNC->nErr++; 74633 pNC->nErr++; 74020 is_agg = 0; 74634 is_agg = 0; 74021 }else if( no_such_func ){ 74635 }else if( no_such_func ){ 74022 sqlite3ErrorMsg(pParse, "no such function: %.*s", nId, zId); 74636 sqlite3ErrorMsg(pParse, "no such function: %.*s", nId, zId); 74023 pNC->nErr++; 74637 pNC->nErr++; 74024 }else if( wrong_num_args ){ 74638 }else if( wrong_num_args ){ 74025 sqlite3ErrorMsg(pParse,"wrong number of arguments to function %.*s()", 74639 sqlite3ErrorMsg(pParse,"wrong number of arguments to function %.*s()", 74026 nId, zId); 74640 nId, zId); 74027 pNC->nErr++; 74641 pNC->nErr++; 74028 } 74642 } 74029 if( is_agg ){ 74643 if( is_agg ){ 74030 pExpr->op = TK_AGG_FUNCTION; 74644 pExpr->op = TK_AGG_FUNCTION; 74031 pNC->hasAgg = 1; | 74645 pNC->ncFlags |= NC_HasAgg; 74032 } 74646 } 74033 if( is_agg ) pNC->allowAgg = 0; | 74647 if( is_agg ) pNC->ncFlags &= ~NC_AllowAgg; 74034 sqlite3WalkExprList(pWalker, pList); 74648 sqlite3WalkExprList(pWalker, pList); 74035 if( is_agg ) pNC->allowAgg = 1; | 74649 if( is_agg ) pNC->ncFlags |= NC_AllowAgg; 74036 /* FIX ME: Compute pExpr->affinity based on the expected return 74650 /* FIX ME: Compute pExpr->affinity based on the expected return 74037 ** type of the function 74651 ** type of the function 74038 */ 74652 */ 74039 return WRC_Prune; 74653 return WRC_Prune; 74040 } 74654 } 74041 #ifndef SQLITE_OMIT_SUBQUERY 74655 #ifndef SQLITE_OMIT_SUBQUERY 74042 case TK_SELECT: 74656 case TK_SELECT: ................................................................................................................................................................................ 74043 case TK_EXISTS: testcase( pExpr->op==TK_EXISTS ); 74657 case TK_EXISTS: testcase( pExpr->op==TK_EXISTS ); 74044 #endif 74658 #endif 74045 case TK_IN: { 74659 case TK_IN: { 74046 testcase( pExpr->op==TK_IN ); 74660 testcase( pExpr->op==TK_IN ); 74047 if( ExprHasProperty(pExpr, EP_xIsSelect) ){ 74661 if( ExprHasProperty(pExpr, EP_xIsSelect) ){ 74048 int nRef = pNC->nRef; 74662 int nRef = pNC->nRef; 74049 #ifndef SQLITE_OMIT_CHECK 74663 #ifndef SQLITE_OMIT_CHECK 74050 if( pNC->isCheck ){ | 74664 if( (pNC->ncFlags & NC_IsCheck)!=0 ){ 74051 sqlite3ErrorMsg(pParse,"subqueries prohibited in CHECK constraints"); 74665 sqlite3ErrorMsg(pParse,"subqueries prohibited in CHECK constraints"); 74052 } 74666 } 74053 #endif 74667 #endif 74054 sqlite3WalkSelect(pWalker, pExpr->x.pSelect); 74668 sqlite3WalkSelect(pWalker, pExpr->x.pSelect); 74055 assert( pNC->nRef>=nRef ); 74669 assert( pNC->nRef>=nRef ); 74056 if( nRef!=pNC->nRef ){ 74670 if( nRef!=pNC->nRef ){ 74057 ExprSetProperty(pExpr, EP_VarSelect); 74671 ExprSetProperty(pExpr, EP_VarSelect); 74058 } 74672 } 74059 } 74673 } 74060 break; 74674 break; 74061 } 74675 } 74062 #ifndef SQLITE_OMIT_CHECK 74676 #ifndef SQLITE_OMIT_CHECK 74063 case TK_VARIABLE: { 74677 case TK_VARIABLE: { 74064 if( pNC->isCheck ){ | 74678 if( (pNC->ncFlags & NC_IsCheck)!=0 ){ 74065 sqlite3ErrorMsg(pParse,"parameters prohibited in CHECK constraints"); 74679 sqlite3ErrorMsg(pParse,"parameters prohibited in CHECK constraints"); 74066 } 74680 } 74067 break; 74681 break; 74068 } 74682 } 74069 #endif 74683 #endif 74070 } 74684 } 74071 return (pParse->nErr || pParse->db->mallocFailed) ? WRC_Abort : WRC_Continue; 74685 return (pParse->nErr || pParse->db->mallocFailed) ? WRC_Abort : WRC_Continue; ................................................................................................................................................................................ 74139 74753 74140 /* Resolve all names in the ORDER BY term expression 74754 /* Resolve all names in the ORDER BY term expression 74141 */ 74755 */ 74142 memset(&nc, 0, sizeof(nc)); 74756 memset(&nc, 0, sizeof(nc)); 74143 nc.pParse = pParse; 74757 nc.pParse = pParse; 74144 nc.pSrcList = pSelect->pSrc; 74758 nc.pSrcList = pSelect->pSrc; 74145 nc.pEList = pEList; 74759 nc.pEList = pEList; 74146 nc.allowAgg = 1; | 74760 nc.ncFlags = NC_AllowAgg; 74147 nc.nErr = 0; 74761 nc.nErr = 0; 74148 db = pParse->db; 74762 db = pParse->db; 74149 savedSuppErr = db->suppressErr; 74763 savedSuppErr = db->suppressErr; 74150 db->suppressErr = 1; 74764 db->suppressErr = 1; 74151 rc = sqlite3ResolveExprNames(&nc, pE); 74765 rc = sqlite3ResolveExprNames(&nc, pE); 74152 db->suppressErr = savedSuppErr; 74766 db->suppressErr = savedSuppErr; 74153 if( rc ) return 0; 74767 if( rc ) return 0; ................................................................................................................................................................................ 74441 sqlite3ResolveExprNames(&sNC, p->pOffset) ){ 75055 sqlite3ResolveExprNames(&sNC, p->pOffset) ){ 74442 return WRC_Abort; 75056 return WRC_Abort; 74443 } 75057 } 74444 75058 74445 /* Set up the local name-context to pass to sqlite3ResolveExprNames() to 75059 /* Set up the local name-context to pass to sqlite3ResolveExprNames() to 74446 ** resolve the result-set expression list. 75060 ** resolve the result-set expression list. 74447 */ 75061 */ 74448 sNC.allowAgg = 1; | 75062 sNC.ncFlags = NC_AllowAgg; 74449 sNC.pSrcList = p->pSrc; 75063 sNC.pSrcList = p->pSrc; 74450 sNC.pNext = pOuterNC; 75064 sNC.pNext = pOuterNC; 74451 75065 74452 /* Resolve names in the result set. */ 75066 /* Resolve names in the result set. */ 74453 pEList = p->pEList; 75067 pEList = p->pEList; 74454 assert( pEList!=0 ); 75068 assert( pEList!=0 ); 74455 for(i=0; i<pEList->nExpr; i++){ 75069 for(i=0; i<pEList->nExpr; i++){ ................................................................................................................................................................................ 74487 } 75101 } 74488 75102 74489 /* If there are no aggregate functions in the result-set, and no GROUP BY 75103 /* If there are no aggregate functions in the result-set, and no GROUP BY 74490 ** expression, do not allow aggregates in any of the other expressions. 75104 ** expression, do not allow aggregates in any of the other expressions. 74491 */ 75105 */ 74492 assert( (p->selFlags & SF_Aggregate)==0 ); 75106 assert( (p->selFlags & SF_Aggregate)==0 ); 74493 pGroupBy = p->pGroupBy; 75107 pGroupBy = p->pGroupBy; 74494 if( pGroupBy || sNC.hasAgg ){ | 75108 if( pGroupBy || (sNC.ncFlags & NC_HasAgg)!=0 ){ 74495 p->selFlags |= SF_Aggregate; 75109 p->selFlags |= SF_Aggregate; 74496 }else{ 75110 }else{ 74497 sNC.allowAgg = 0; | 75111 sNC.ncFlags &= ~NC_AllowAgg; 74498 } 75112 } 74499 75113 74500 /* If a HAVING clause is present, then there must be a GROUP BY clause. 75114 /* If a HAVING clause is present, then there must be a GROUP BY clause. 74501 */ 75115 */ 74502 if( p->pHaving && !pGroupBy ){ 75116 if( p->pHaving && !pGroupBy ){ 74503 sqlite3ErrorMsg(pParse, "a GROUP BY clause is required before HAVING"); 75117 sqlite3ErrorMsg(pParse, "a GROUP BY clause is required before HAVING"); 74504 return WRC_Abort; 75118 return WRC_Abort; ................................................................................................................................................................................ 74519 return WRC_Abort; 75133 return WRC_Abort; 74520 } 75134 } 74521 75135 74522 /* The ORDER BY and GROUP BY clauses may not refer to terms in 75136 /* The ORDER BY and GROUP BY clauses may not refer to terms in 74523 ** outer queries 75137 ** outer queries 74524 */ 75138 */ 74525 sNC.pNext = 0; 75139 sNC.pNext = 0; 74526 sNC.allowAgg = 1; | 75140 sNC.ncFlags |= NC_AllowAgg; 74527 75141 74528 /* Process the ORDER BY clause for singleton SELECT statements. 75142 /* Process the ORDER BY clause for singleton SELECT statements. 74529 ** The ORDER BY clause for compounds SELECT statements is handled 75143 ** The ORDER BY clause for compounds SELECT statements is handled 74530 ** below, after all of the result-sets for all of the elements of 75144 ** below, after all of the result-sets for all of the elements of 74531 ** the compound have been resolved. 75145 ** the compound have been resolved. 74532 */ 75146 */ 74533 if( !isCompound && resolveOrderGroupBy(&sNC, p, p->pOrderBy, "ORDER") ){ 75147 if( !isCompound && resolveOrderGroupBy(&sNC, p, p->pOrderBy, "ORDER") ){ ................................................................................................................................................................................ 74607 ** 75221 ** 74608 ** The "x" term of the order by is replaced by "a+b" to render: 75222 ** The "x" term of the order by is replaced by "a+b" to render: 74609 ** 75223 ** 74610 ** SELECT a+b AS x, c+d AS y FROM t1 ORDER BY a+b; 75224 ** SELECT a+b AS x, c+d AS y FROM t1 ORDER BY a+b; 74611 ** 75225 ** 74612 ** Function calls are checked to make sure that the function is 75226 ** Function calls are checked to make sure that the function is 74613 ** defined and that the correct number of arguments are specified. 75227 ** defined and that the correct number of arguments are specified. 74614 ** If the function is an aggregate function, then the pNC->hasAgg is | 75228 ** If the function is an aggregate function, then the NC_HasAgg flag is 74615 ** set and the opcode is changed from TK_FUNCTION to TK_AGG_FUNCTION. 75229 ** set and the opcode is changed from TK_FUNCTION to TK_AGG_FUNCTION. 74616 ** If an expression contains aggregate functions then the EP_Agg 75230 ** If an expression contains aggregate functions then the EP_Agg 74617 ** property on the expression is set. 75231 ** property on the expression is set. 74618 ** 75232 ** 74619 ** An error message is left in pParse if anything is amiss. The number 75233 ** An error message is left in pParse if anything is amiss. The number 74620 ** if errors is returned. 75234 ** if errors is returned. 74621 */ 75235 */ 74622 SQLITE_PRIVATE int sqlite3ResolveExprNames( 75236 SQLITE_PRIVATE int sqlite3ResolveExprNames( 74623 NameContext *pNC, /* Namespace to resolve expressions in. */ 75237 NameContext *pNC, /* Namespace to resolve expressions in. */ 74624 Expr *pExpr /* The expression to be analyzed. */ 75238 Expr *pExpr /* The expression to be analyzed. */ 74625 ){ 75239 ){ 74626 int savedHasAgg; | 75240 u8 savedHasAgg; 74627 Walker w; 75241 Walker w; 74628 75242 74629 if( pExpr==0 ) return 0; 75243 if( pExpr==0 ) return 0; 74630 #if SQLITE_MAX_EXPR_DEPTH>0 75244 #if SQLITE_MAX_EXPR_DEPTH>0 74631 { 75245 { 74632 Parse *pParse = pNC->pParse; 75246 Parse *pParse = pNC->pParse; 74633 if( sqlite3ExprCheckHeight(pParse, pExpr->nHeight+pNC->pParse->nHeight) ){ 75247 if( sqlite3ExprCheckHeight(pParse, pExpr->nHeight+pNC->pParse->nHeight) ){ 74634 return 1; 75248 return 1; 74635 } 75249 } 74636 pParse->nHeight += pExpr->nHeight; 75250 pParse->nHeight += pExpr->nHeight; 74637 } 75251 } 74638 #endif 75252 #endif 74639 savedHasAgg = pNC->hasAgg; | 75253 savedHasAgg = pNC->ncFlags & NC_HasAgg; 74640 pNC->hasAgg = 0; | 75254 pNC->ncFlags &= ~NC_HasAgg; 74641 w.xExprCallback = resolveExprStep; 75255 w.xExprCallback = resolveExprStep; 74642 w.xSelectCallback = resolveSelectStep; 75256 w.xSelectCallback = resolveSelectStep; 74643 w.pParse = pNC->pParse; 75257 w.pParse = pNC->pParse; 74644 w.u.pNC = pNC; 75258 w.u.pNC = pNC; 74645 sqlite3WalkExpr(&w, pExpr); 75259 sqlite3WalkExpr(&w, pExpr); 74646 #if SQLITE_MAX_EXPR_DEPTH>0 75260 #if SQLITE_MAX_EXPR_DEPTH>0 74647 pNC->pParse->nHeight -= pExpr->nHeight; 75261 pNC->pParse->nHeight -= pExpr->nHeight; 74648 #endif 75262 #endif 74649 if( pNC->nErr>0 || w.pParse->nErr>0 ){ 75263 if( pNC->nErr>0 || w.pParse->nErr>0 ){ 74650 ExprSetProperty(pExpr, EP_Error); 75264 ExprSetProperty(pExpr, EP_Error); 74651 } 75265 } 74652 if( pNC->hasAgg ){ | 75266 if( pNC->ncFlags & NC_HasAgg ){ 74653 ExprSetProperty(pExpr, EP_Agg); 75267 ExprSetProperty(pExpr, EP_Agg); 74654 }else if( savedHasAgg ){ 75268 }else if( savedHasAgg ){ 74655 pNC->hasAgg = 1; | 75269 pNC->ncFlags |= NC_HasAgg; 74656 } 75270 } 74657 return ExprHasProperty(pExpr, EP_Error); 75271 return ExprHasProperty(pExpr, EP_Error); 74658 } 75272 } 74659 75273 74660 75274 74661 /* 75275 /* 74662 ** Resolve all names in all expressions of a SELECT and in all 75276 ** Resolve all names in all expressions of a SELECT and in all ................................................................................................................................................................................ 78462 if( sqlite3ExprCompare(pA->pRight, pB->pRight) ) return 2; 79076 if( sqlite3ExprCompare(pA->pRight, pB->pRight) ) return 2; 78463 if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList) ) return 2; 79077 if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList) ) return 2; 78464 if( pA->iTable!=pB->iTable || pA->iColumn!=pB->iColumn ) return 2; 79078 if( pA->iTable!=pB->iTable || pA->iColumn!=pB->iColumn ) return 2; 78465 if( ExprHasProperty(pA, EP_IntValue) ){ 79079 if( ExprHasProperty(pA, EP_IntValue) ){ 78466 if( !ExprHasProperty(pB, EP_IntValue) || pA->u.iValue!=pB->u.iValue ){ 79080 if( !ExprHasProperty(pB, EP_IntValue) || pA->u.iValue!=pB->u.iValue ){ 78467 return 2; 79081 return 2; 78468 } 79082 } 78469 }else if( pA->op!=TK_COLUMN && pA->op!=TK_AGG_COLUMN && pA->u.zToken ){ | 79083 }else if( pA->op!=TK_COLUMN && ALWAYS(pA->op!=TK_AGG_COLUMN) && pA->u.zToken){ 78470 if( ExprHasProperty(pB, EP_IntValue) || NEVER(pB->u.zToken==0) ) return 2; 79084 if( ExprHasProperty(pB, EP_IntValue) || NEVER(pB->u.zToken==0) ) return 2; 78471 if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){ 79085 if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){ 78472 return 2; 79086 return 2; 78473 } 79087 } 78474 } 79088 } 78475 if( (pA->flags & EP_ExpCollate)!=(pB->flags & EP_ExpCollate) ) return 1; 79089 if( (pA->flags & EP_ExpCollate)!=(pB->flags & EP_ExpCollate) ) return 1; 78476 if( (pA->flags & EP_ExpCollate)!=0 && pA->pColl!=pB->pColl ) return 2; 79090 if( (pA->flags & EP_ExpCollate)!=0 && pA->pColl!=pB->pColl ) return 2; ................................................................................................................................................................................ 78649 break; 79263 break; 78650 } /* endif pExpr->iTable==pItem->iCursor */ 79264 } /* endif pExpr->iTable==pItem->iCursor */ 78651 } /* end loop over pSrcList */ 79265 } /* end loop over pSrcList */ 78652 } 79266 } 78653 return WRC_Prune; 79267 return WRC_Prune; 78654 } 79268 } 78655 case TK_AGG_FUNCTION: { 79269 case TK_AGG_FUNCTION: { > 79270 if( (pNC->ncFlags & NC_InAggFunc)==0 78656 if( !sqlite3FunctionUsesOtherSrc(pExpr, pSrcList) ){ | 79271 && !sqlite3FunctionUsesOtherSrc(pExpr, pSrcList) > 79272 ){ 78657 /* Check to see if pExpr is a duplicate of another aggregate 79273 /* Check to see if pExpr is a duplicate of another aggregate 78658 ** function that is already in the pAggInfo structure 79274 ** function that is already in the pAggInfo structure 78659 */ 79275 */ 78660 struct AggInfo_func *pItem = pAggInfo->aFunc; 79276 struct AggInfo_func *pItem = pAggInfo->aFunc; 78661 for(i=0; i<pAggInfo->nFunc; i++, pItem++){ 79277 for(i=0; i<pAggInfo->nFunc; i++, pItem++){ 78662 if( sqlite3ExprCompare(pItem->pExpr, pExpr)==0 ){ 79278 if( sqlite3ExprCompare(pItem->pExpr, pExpr)==0 ){ 78663 break; 79279 break; ................................................................................................................................................................................ 78686 } 79302 } 78687 /* Make pExpr point to the appropriate pAggInfo->aFunc[] entry 79303 /* Make pExpr point to the appropriate pAggInfo->aFunc[] entry 78688 */ 79304 */ 78689 assert( !ExprHasAnyProperty(pExpr, EP_TokenOnly|EP_Reduced) ); 79305 assert( !ExprHasAnyProperty(pExpr, EP_TokenOnly|EP_Reduced) ); 78690 ExprSetIrreducible(pExpr); 79306 ExprSetIrreducible(pExpr); 78691 pExpr->iAgg = (i16)i; 79307 pExpr->iAgg = (i16)i; 78692 pExpr->pAggInfo = pAggInfo; 79308 pExpr->pAggInfo = pAggInfo; 78693 return WRC_Prune; < 78694 } 79309 } > 79310 return WRC_Prune; 78695 } 79311 } 78696 } 79312 } 78697 return WRC_Continue; 79313 return WRC_Continue; 78698 } 79314 } 78699 static int analyzeAggregatesInSelect(Walker *pWalker, Select *pSelect){ 79315 static int analyzeAggregatesInSelect(Walker *pWalker, Select *pSelect){ 78700 UNUSED_PARAMETER(pWalker); 79316 UNUSED_PARAMETER(pWalker); 78701 UNUSED_PARAMETER(pSelect); 79317 UNUSED_PARAMETER(pSelect); ................................................................................................................................................................................ 80971 int iDb = db->nDb - 1; 81587 int iDb = db->nDb - 1; 80972 assert( iDb>=2 ); 81588 assert( iDb>=2 ); 80973 if( db->aDb[iDb].pBt ){ 81589 if( db->aDb[iDb].pBt ){ 80974 sqlite3BtreeClose(db->aDb[iDb].pBt); 81590 sqlite3BtreeClose(db->aDb[iDb].pBt); 80975 db->aDb[iDb].pBt = 0; 81591 db->aDb[iDb].pBt = 0; 80976 db->aDb[iDb].pSchema = 0; 81592 db->aDb[iDb].pSchema = 0; 80977 } 81593 } 80978 sqlite3ResetInternalSchema(db, -1); | 81594 sqlite3ResetAllSchemasOfConnection(db); 80979 db->nDb = iDb; 81595 db->nDb = iDb; 80980 if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){ 81596 if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){ 80981 db->mallocFailed = 1; 81597 db->mallocFailed = 1; 80982 sqlite3DbFree(db, zErrDyn); 81598 sqlite3DbFree(db, zErrDyn); 80983 zErrDyn = sqlite3MPrintf(db, "out of memory"); 81599 zErrDyn = sqlite3MPrintf(db, "out of memory"); 80984 }else if( zErrDyn==0 ){ 81600 }else if( zErrDyn==0 ){ 80985 zErrDyn = sqlite3MPrintf(db, "unable to open database: %s", zFile); 81601 zErrDyn = sqlite3MPrintf(db, "unable to open database: %s", zFile); ................................................................................................................................................................................ 81043 sqlite3_snprintf(sizeof(zErr),zErr, "database %s is locked", zName); 81659 sqlite3_snprintf(sizeof(zErr),zErr, "database %s is locked", zName); 81044 goto detach_error; 81660 goto detach_error; 81045 } 81661 } 81046 81662 81047 sqlite3BtreeClose(pDb->pBt); 81663 sqlite3BtreeClose(pDb->pBt); 81048 pDb->pBt = 0; 81664 pDb->pBt = 0; 81049 pDb->pSchema = 0; 81665 pDb->pSchema = 0; 81050 sqlite3ResetInternalSchema(db, -1); | 81666 sqlite3ResetAllSchemasOfConnection(db); 81051 return; 81667 return; 81052 81668 81053 detach_error: 81669 detach_error: 81054 sqlite3_result_error(context, zErr, -1); 81670 sqlite3_result_error(context, zErr, -1); 81055 } 81671 } 81056 81672 81057 /* 81673 /* ................................................................................................................................................................................ 81959 } 82575 } 81960 freeIndex(db, pIndex); 82576 freeIndex(db, pIndex); 81961 } 82577 } 81962 db->flags |= SQLITE_InternChanges; 82578 db->flags |= SQLITE_InternChanges; 81963 } 82579 } 81964 82580 81965 /* 82581 /* 81966 ** Erase all schema information from the in-memory hash tables of | 82582 ** Look through the list of open database files in db->aDb[] and if 81967 ** a single database. This routine is called to reclaim memory | 82583 ** any have been closed, remove them from the list. Reallocate the 81968 ** before the database closes. It is also called during a rollback | 82584 ** db->aDb[] structure to a smaller size, if possible. 81969 ** if there were schema changes during the transaction or if a < 81970 ** schema-cookie mismatch occurs. < 81971 ** 82585 ** 81972 ** If iDb<0 then reset the internal schema tables for all database < 81973 ** files. If iDb>=0 then reset the internal schema for only the < 81974 ** single file indicated. < > 82586 ** Entry 0 (the "main" database) and entry 1 (the "temp" database) > 82587 ** are never candidates for being collapsed. 81975 */ 82588 */ 81976 SQLITE_PRIVATE void sqlite3ResetInternalSchema(sqlite3 *db, int iDb){ | 82589 SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3 *db){ 81977 int i, j; 82590 int i, j; 81978 assert( iDb<db->nDb ); < 81979 < 81980 if( iDb>=0 ){ < 81981 /* Case 1: Reset the single schema identified by iDb */ < 81982 Db *pDb = &db->aDb[iDb]; < 81983 assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); < 81984 assert( pDb->pSchema!=0 ); < 81985 sqlite3SchemaClear(pDb->pSchema); < 81986 < 81987 /* If any database other than TEMP is reset, then also reset TEMP < 81988 ** since TEMP might be holding triggers that reference tables in the < 81989 ** other database. < 81990 */ < 81991 if( iDb!=1 ){ < 81992 pDb = &db->aDb[1]; < 81993 assert( pDb->pSchema!=0 ); < 81994 sqlite3SchemaClear(pDb->pSchema); < 81995 } < 81996 return; < 81997 } < 81998 /* Case 2 (from here to the end): Reset all schemas for all attached < 81999 ** databases. */ < 82000 assert( iDb<0 ); < 82001 sqlite3BtreeEnterAll(db); < 82002 for(i=0; i<db->nDb; i++){ < 82003 Db *pDb = &db->aDb[i]; < 82004 if( pDb->pSchema ){ < 82005 sqlite3SchemaClear(pDb->pSchema); < 82006 } < 82007 } < 82008 db->flags &= ~SQLITE_InternChanges; < 82009 sqlite3VtabUnlockList(db); < 82010 sqlite3BtreeLeaveAll(db); < 82011 < 82012 /* If one or more of the auxiliary database files has been closed, < 82013 ** then remove them from the auxiliary database list. We take the < 82014 ** opportunity to do this here since we have just deleted all of the < 82015 ** schema hash tables and therefore do not have to make any changes < 82016 ** to any of those tables. < 82017 */ < 82018 for(i=j=2; i<db->nDb; i++){ 82591 for(i=j=2; i<db->nDb; i++){ 82019 struct Db *pDb = &db->aDb[i]; 82592 struct Db *pDb = &db->aDb[i]; 82020 if( pDb->pBt==0 ){ 82593 if( pDb->pBt==0 ){ 82021 sqlite3DbFree(db, pDb->zName); 82594 sqlite3DbFree(db, pDb->zName); 82022 pDb->zName = 0; 82595 pDb->zName = 0; 82023 continue; 82596 continue; 82024 } 82597 } ................................................................................................................................................................................ 82031 db->nDb = j; 82604 db->nDb = j; 82032 if( db->nDb<=2 && db->aDb!=db->aDbStatic ){ 82605 if( db->nDb<=2 && db->aDb!=db->aDbStatic ){ 82033 memcpy(db->aDbStatic, db->aDb, 2*sizeof(db->aDb[0])); 82606 memcpy(db->aDbStatic, db->aDb, 2*sizeof(db->aDb[0])); 82034 sqlite3DbFree(db, db->aDb); 82607 sqlite3DbFree(db, db->aDb); 82035 db->aDb = db->aDbStatic; 82608 db->aDb = db->aDbStatic; 82036 } 82609 } 82037 } 82610 } > 82611 > 82612 /* > 82613 ** Reset the schema for the database at index iDb. Also reset the > 82614 ** TEMP schema. > 82615 */ > 82616 SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3 *db, int iDb){ > 82617 Db *pDb; > 82618 assert( iDb<db->nDb ); > 82619 > 82620 /* Case 1: Reset the single schema identified by iDb */ > 82621 pDb = &db->aDb[iDb]; > 82622 assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); > 82623 assert( pDb->pSchema!=0 ); > 82624 sqlite3SchemaClear(pDb->pSchema); > 82625 > 82626 /* If any database other than TEMP is reset, then also reset TEMP > 82627 ** since TEMP might be holding triggers that reference tables in the > 82628 ** other database. > 82629 */ > 82630 if( iDb!=1 ){ > 82631 pDb = &db->aDb[1]; > 82632 assert( pDb->pSchema!=0 ); > 82633 sqlite3SchemaClear(pDb->pSchema); > 82634 } > 82635 return; > 82636 } > 82637 > 82638 /* > 82639 ** Erase all schema information from all attached databases (including > 82640 ** "main" and "temp") for a single database connection. > 82641 */ > 82642 SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3 *db){ > 82643 int i; > 82644 sqlite3BtreeEnterAll(db); > 82645 for(i=0; i<db->nDb; i++){ > 82646 Db *pDb = &db->aDb[i]; > 82647 if( pDb->pSchema ){ > 82648 sqlite3SchemaClear(pDb->pSchema); > 82649 } > 82650 } > 82651 db->flags &= ~SQLITE_InternChanges; > 82652 sqlite3VtabUnlockList(db); > 82653 sqlite3BtreeLeaveAll(db); > 82654 sqlite3CollapseDatabaseArray(db); > 82655 } 82038 82656 82039 /* 82657 /* 82040 ** This routine is called when a commit occurs. 82658 ** This routine is called when a commit occurs. 82041 */ 82659 */ 82042 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3 *db){ 82660 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3 *db){ 82043 db->flags &= ~SQLITE_InternChanges; 82661 db->flags &= ~SQLITE_InternChanges; 82044 } 82662 } ................................................................................................................................................................................ 82067 ** Remove the memory data structures associated with the given 82685 ** Remove the memory data structures associated with the given 82068 ** Table. No changes are made to disk by this routine. 82686 ** Table. No changes are made to disk by this routine. 82069 ** 82687 ** 82070 ** This routine just deletes the data structure. It does not unlink 82688 ** This routine just deletes the data structure. It does not unlink 82071 ** the table data structure from the hash table. But it does destroy 82689 ** the table data structure from the hash table. But it does destroy 82072 ** memory structures of the indices and foreign keys associated with 82690 ** memory structures of the indices and foreign keys associated with 82073 ** the table. 82691 ** the table. > 82692 ** > 82693 ** The db parameter is optional. It is needed if the Table object > 82694 ** contains lookaside memory. (Table objects in the schema do not use > 82695 ** lookaside memory, but some ephemeral Table objects do.) Or the > 82696 ** db parameter can be used with db->pnBytesFreed to measure the memory > 82697 ** used by the Table object. 82074 */ 82698 */ 82075 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){ 82699 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){ 82076 Index *pIndex, *pNext; 82700 Index *pIndex, *pNext; > 82701 TESTONLY( int nLookaside; ) /* Used to verify lookaside not used for schema */ 82077 82702 82078 assert( !pTable || pTable->nRef>0 ); 82703 assert( !pTable || pTable->nRef>0 ); 82079 82704 82080 /* Do not delete the table until the reference count reaches zero. */ 82705 /* Do not delete the table until the reference count reaches zero. */ 82081 if( !pTable ) return; 82706 if( !pTable ) return; 82082 if( ((!db || db->pnBytesFreed==0) && (--pTable->nRef)>0) ) return; 82707 if( ((!db || db->pnBytesFreed==0) && (--pTable->nRef)>0) ) return; > 82708 > 82709 /* Record the number of outstanding lookaside allocations in schema Tables > 82710 ** prior to doing any free() operations. Since schema Tables do not use > 82711 ** lookaside, this number should not change. */ > 82712 TESTONLY( nLookaside = (db && (pTable->tabFlags & TF_Ephemeral)==0) ? > 82713 db->lookaside.nOut : 0 ); 82083 82714 82084 /* Delete all indices associated with this table. */ 82715 /* Delete all indices associated with this table. */ 82085 for(pIndex = pTable->pIndex; pIndex; pIndex=pNext){ 82716 for(pIndex = pTable->pIndex; pIndex; pIndex=pNext){ 82086 pNext = pIndex->pNext; 82717 pNext = pIndex->pNext; 82087 assert( pIndex->pSchema==pTable->pSchema ); 82718 assert( pIndex->pSchema==pTable->pSchema ); 82088 if( !db || db->pnBytesFreed==0 ){ 82719 if( !db || db->pnBytesFreed==0 ){ 82089 char *zName = pIndex->zName; 82720 char *zName = pIndex->zName; ................................................................................................................................................................................ 82108 #ifndef SQLITE_OMIT_CHECK 82739 #ifndef SQLITE_OMIT_CHECK 82109 sqlite3ExprListDelete(db, pTable->pCheck); 82740 sqlite3ExprListDelete(db, pTable->pCheck); 82110 #endif 82741 #endif 82111 #ifndef SQLITE_OMIT_VIRTUALTABLE 82742 #ifndef SQLITE_OMIT_VIRTUALTABLE 82112 sqlite3VtabClear(db, pTable); 82743 sqlite3VtabClear(db, pTable); 82113 #endif 82744 #endif 82114 sqlite3DbFree(db, pTable); 82745 sqlite3DbFree(db, pTable); > 82746 > 82747 /* Verify that no lookaside memory was used by schema tables */ > 82748 assert( nLookaside==0 || nLookaside==db->lookaside.nOut ); 82115 } 82749 } 82116 82750 82117 /* 82751 /* 82118 ** Unlink the given table from the hash tables and the delete the 82752 ** Unlink the given table from the hash tables and the delete the 82119 ** table structure with all its indices and foreign keys. 82753 ** table structure with all its indices and foreign keys. 82120 */ 82754 */ 82121 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable(sqlite3 *db, int iDb, const char 82755 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable(sqlite3 *db, int iDb, const char ................................................................................................................................................................................ 83056 memset(&sSrc, 0, sizeof(sSrc)); 83690 memset(&sSrc, 0, sizeof(sSrc)); 83057 sSrc.nSrc = 1; 83691 sSrc.nSrc = 1; 83058 sSrc.a[0].zName = p->zName; 83692 sSrc.a[0].zName = p->zName; 83059 sSrc.a[0].pTab = p; 83693 sSrc.a[0].pTab = p; 83060 sSrc.a[0].iCursor = -1; 83694 sSrc.a[0].iCursor = -1; 83061 sNC.pParse = pParse; 83695 sNC.pParse = pParse; 83062 sNC.pSrcList = &sSrc; 83696 sNC.pSrcList = &sSrc; 83063 sNC.isCheck = 1; | 83697 sNC.ncFlags = NC_IsCheck; 83064 pList = p->pCheck; 83698 pList = p->pCheck; 83065 for(i=0; i<pList->nExpr; i++){ 83699 for(i=0; i<pList->nExpr; i++){ 83066 if( sqlite3ResolveExprNames(&sNC, pList->a[i].pExpr) ){ 83700 if( sqlite3ResolveExprNames(&sNC, pList->a[i].pExpr) ){ 83067 return; 83701 return; 83068 } 83702 } 83069 } 83703 } 83070 } 83704 } ................................................................................................................................................................................ 84312 memcpy(zExtra, zColl, nColl); 84946 memcpy(zExtra, zColl, nColl); 84313 zColl = zExtra; 84947 zColl = zExtra; 84314 zExtra += nColl; 84948 zExtra += nColl; 84315 nExtra -= nColl; 84949 nExtra -= nColl; 84316 }else{ 84950 }else{ 84317 zColl = pTab->aCol[j].zColl; 84951 zColl = pTab->aCol[j].zColl; 84318 if( !zColl ){ 84952 if( !zColl ){ 84319 zColl = db->pDfltColl->zName; | 84953 zColl = "BINARY"; 84320 } 84954 } 84321 } 84955 } 84322 if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){ 84956 if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){ 84323 goto exit_create_index; 84957 goto exit_create_index; 84324 } 84958 } 84325 pIndex->azColl[i] = zColl; 84959 pIndex->azColl[i] = zColl; 84326 requestedSortOrder = pListItem->sortOrder & sortOrderMask; 84960 requestedSortOrder = pListItem->sortOrder & sortOrderMask; ................................................................................................................................................................................ 92587 if( !db->autoCommit || sqlite3BtreeIsInReadTrans(db->aDb[1].pBt) ){ 93221 if( !db->autoCommit || sqlite3BtreeIsInReadTrans(db->aDb[1].pBt) ){ 92588 sqlite3ErrorMsg(pParse, "temporary storage cannot be changed " 93222 sqlite3ErrorMsg(pParse, "temporary storage cannot be changed " 92589 "from within a transaction"); 93223 "from within a transaction"); 92590 return SQLITE_ERROR; 93224 return SQLITE_ERROR; 92591 } 93225 } 92592 sqlite3BtreeClose(db->aDb[1].pBt); 93226 sqlite3BtreeClose(db->aDb[1].pBt); 92593 db->aDb[1].pBt = 0; 93227 db->aDb[1].pBt = 0; 92594 sqlite3ResetInternalSchema(db, -1); | 93228 sqlite3ResetAllSchemasOfConnection(db); 92595 } 93229 } 92596 return SQLITE_OK; 93230 return SQLITE_OK; 92597 } 93231 } 92598 #endif /* SQLITE_PAGER_PRAGMAS */ 93232 #endif /* SQLITE_PAGER_PRAGMAS */ 92599 93233 92600 #ifndef SQLITE_OMIT_PAGER_PRAGMAS 93234 #ifndef SQLITE_OMIT_PAGER_PRAGMAS 92601 /* 93235 /* ................................................................................................................................................................................ 93272 sqlite3_temp_directory = sqlite3_mprintf("%s", zRight); 93906 sqlite3_temp_directory = sqlite3_mprintf("%s", zRight); 93273 }else{ 93907 }else{ 93274 sqlite3_temp_directory = 0; 93908 sqlite3_temp_directory = 0; 93275 } 93909 } 93276 #endif /* SQLITE_OMIT_WSD */ 93910 #endif /* SQLITE_OMIT_WSD */ 93277 } 93911 } 93278 }else 93912 }else > 93913 > 93914 #if SQLITE_OS_WIN > 93915 /* > 93916 ** PRAGMA data_store_directory > 93917 ** PRAGMA data_store_directory = ""|"directory_name" > 93918 ** > 93919 ** Return or set the local value of the data_store_directory flag. Changing > 93920 ** the value sets a specific directory to be used for database files that > 93921 ** were specified with a relative pathname. Setting to a null string reverts > 93922 ** to the default database directory, which for database files specified with > 93923 ** a relative path will probably be based on the current directory for the > 93924 ** process. Database file specified with an absolute path are not impacted > 93925 ** by this setting, regardless of its value. > 93926 ** > 93927 */ > 93928 if( sqlite3StrICmp(zLeft, "data_store_directory")==0 ){ > 93929 if( !zRight ){ > 93930 if( sqlite3_data_directory ){ > 93931 sqlite3VdbeSetNumCols(v, 1); > 93932 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, > 93933 "data_store_directory", SQLITE_STATIC); > 93934 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, sqlite3_data_directory, 0); > 93935 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); > 93936 } > 93937 }else{ > 93938 #ifndef SQLITE_OMIT_WSD > 93939 if( zRight[0] ){ > 93940 int res; > 93941 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res); > 93942 if( rc!=SQLITE_OK || res==0 ){ > 93943 sqlite3ErrorMsg(pParse, "not a writable directory"); > 93944 goto pragma_out; > 93945 } > 93946 } > 93947 sqlite3_free(sqlite3_data_directory); > 93948 if( zRight[0] ){ > 93949 sqlite3_data_directory = sqlite3_mprintf("%s", zRight); > 93950 }else{ > 93951 sqlite3_data_directory = 0; > 93952 } > 93953 #endif /* SQLITE_OMIT_WSD */ > 93954 } > 93955 }else > 93956 #endif 93279 93957 93280 #if !defined(SQLITE_ENABLE_LOCKING_STYLE) 93958 #if !defined(SQLITE_ENABLE_LOCKING_STYLE) 93281 # if defined(__APPLE__) 93959 # if defined(__APPLE__) 93282 # define SQLITE_ENABLE_LOCKING_STYLE 1 93960 # define SQLITE_ENABLE_LOCKING_STYLE 1 93283 # else 93961 # else 93284 # define SQLITE_ENABLE_LOCKING_STYLE 0 93962 # define SQLITE_ENABLE_LOCKING_STYLE 0 93285 # endif 93963 # endif ................................................................................................................................................................................ 94305 if( meta[BTREE_TEXT_ENCODING-1] ){ /* text encoding */ 94983 if( meta[BTREE_TEXT_ENCODING-1] ){ /* text encoding */ 94306 if( iDb==0 ){ 94984 if( iDb==0 ){ 94307 u8 encoding; 94985 u8 encoding; 94308 /* If opening the main database, set ENC(db). */ 94986 /* If opening the main database, set ENC(db). */ 94309 encoding = (u8)meta[BTREE_TEXT_ENCODING-1] & 3; 94987 encoding = (u8)meta[BTREE_TEXT_ENCODING-1] & 3; 94310 if( encoding==0 ) encoding = SQLITE_UTF8; 94988 if( encoding==0 ) encoding = SQLITE_UTF8; 94311 ENC(db) = encoding; 94989 ENC(db) = encoding; 94312 db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 0); < 94313 }else{ 94990 }else{ 94314 /* If opening an attached database, the encoding much match ENC(db) */ 94991 /* If opening an attached database, the encoding much match ENC(db) */ 94315 if( meta[BTREE_TEXT_ENCODING-1]!=ENC(db) ){ 94992 if( meta[BTREE_TEXT_ENCODING-1]!=ENC(db) ){ 94316 sqlite3SetString(pzErrMsg, db, "attached databases must use the same" 94993 sqlite3SetString(pzErrMsg, db, "attached databases must use the same" 94317 " text encoding as main database"); 94994 " text encoding as main database"); 94318 rc = SQLITE_ERROR; 94995 rc = SQLITE_ERROR; 94319 goto initone_error_out; 94996 goto initone_error_out; ................................................................................................................................................................................ 94385 if( rc==SQLITE_OK ){ 95062 if( rc==SQLITE_OK ){ 94386 sqlite3AnalysisLoad(db, iDb); 95063 sqlite3AnalysisLoad(db, iDb); 94387 } 95064 } 94388 #endif 95065 #endif 94389 } 95066 } 94390 if( db->mallocFailed ){ 95067 if( db->mallocFailed ){ 94391 rc = SQLITE_NOMEM; 95068 rc = SQLITE_NOMEM; 94392 sqlite3ResetInternalSchema(db, -1); | 95069 sqlite3ResetAllSchemasOfConnection(db); 94393 } 95070 } 94394 if( rc==SQLITE_OK || (db->flags&SQLITE_RecoveryMode)){ 95071 if( rc==SQLITE_OK || (db->flags&SQLITE_RecoveryMode)){ 94395 /* Black magic: If the SQLITE_RecoveryMode flag is set, then consider 95072 /* Black magic: If the SQLITE_RecoveryMode flag is set, then consider 94396 ** the schema loaded, even if errors occurred. In this situation the 95073 ** the schema loaded, even if errors occurred. In this situation the 94397 ** current sqlite3_prepare() operation will fail, but the following one 95074 ** current sqlite3_prepare() operation will fail, but the following one 94398 ** will attempt to compile the supplied statement against whatever subset 95075 ** will attempt to compile the supplied statement against whatever subset 94399 ** of the schema was loaded before the error occurred. The primary 95076 ** of the schema was loaded before the error occurred. The primary ................................................................................................................................................................................ 94438 assert( sqlite3_mutex_held(db->mutex) ); 95115 assert( sqlite3_mutex_held(db->mutex) ); 94439 rc = SQLITE_OK; 95116 rc = SQLITE_OK; 94440 db->init.busy = 1; 95117 db->init.busy = 1; 94441 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){ 95118 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){ 94442 if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue; 95119 if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue; 94443 rc = sqlite3InitOne(db, i, pzErrMsg); 95120 rc = sqlite3InitOne(db, i, pzErrMsg); 94444 if( rc ){ 95121 if( rc ){ 94445 sqlite3ResetInternalSchema(db, i); | 95122 sqlite3ResetOneSchema(db, i); 94446 } 95123 } 94447 } 95124 } 94448 95125 94449 /* Once all the other databases have been initialised, load the schema 95126 /* Once all the other databases have been initialised, load the schema 94450 ** for the TEMP database. This is loaded last, as the TEMP database 95127 ** for the TEMP database. This is loaded last, as the TEMP database 94451 ** schema may contain references to objects in other databases. 95128 ** schema may contain references to objects in other databases. 94452 */ 95129 */ 94453 #ifndef SQLITE_OMIT_TEMPDB 95130 #ifndef SQLITE_OMIT_TEMPDB 94454 if( rc==SQLITE_OK && ALWAYS(db->nDb>1) 95131 if( rc==SQLITE_OK && ALWAYS(db->nDb>1) 94455 && !DbHasProperty(db, 1, DB_SchemaLoaded) ){ 95132 && !DbHasProperty(db, 1, DB_SchemaLoaded) ){ 94456 rc = sqlite3InitOne(db, 1, pzErrMsg); 95133 rc = sqlite3InitOne(db, 1, pzErrMsg); 94457 if( rc ){ 95134 if( rc ){ 94458 sqlite3ResetInternalSchema(db, 1); | 95135 sqlite3ResetOneSchema(db, 1); 94459 } 95136 } 94460 } 95137 } 94461 #endif 95138 #endif 94462 95139 94463 db->init.busy = 0; 95140 db->init.busy = 0; 94464 if( rc==SQLITE_OK && commit_internal ){ 95141 if( rc==SQLITE_OK && commit_internal ){ 94465 sqlite3CommitInternalChanges(db); 95142 sqlite3CommitInternalChanges(db); ................................................................................................................................................................................ 94519 95196 94520 /* Read the schema cookie from the database. If it does not match the 95197 /* Read the schema cookie from the database. If it does not match the 94521 ** value stored as part of the in-memory schema representation, 95198 ** value stored as part of the in-memory schema representation, 94522 ** set Parse.rc to SQLITE_SCHEMA. */ 95199 ** set Parse.rc to SQLITE_SCHEMA. */ 94523 sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&cookie); 95200 sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&cookie); 94524 assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); 95201 assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); 94525 if( cookie!=db->aDb[iDb].pSchema->schema_cookie ){ 95202 if( cookie!=db->aDb[iDb].pSchema->schema_cookie ){ 94526 sqlite3ResetInternalSchema(db, iDb); | 95203 sqlite3ResetOneSchema(db, iDb); 94527 pParse->rc = SQLITE_SCHEMA; 95204 pParse->rc = SQLITE_SCHEMA; 94528 } 95205 } 94529 95206 94530 /* Close the transaction, if one was opened. */ 95207 /* Close the transaction, if one was opened. */ 94531 if( openedTransaction ){ 95208 if( openedTransaction ){ 94532 sqlite3BtreeCommit(pBt); 95209 sqlite3BtreeCommit(pBt); 94533 } 95210 } ................................................................................................................................................................................ 94749 rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail); 95426 rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail); 94750 if( rc==SQLITE_SCHEMA ){ 95427 if( rc==SQLITE_SCHEMA ){ 94751 sqlite3_finalize(*ppStmt); 95428 sqlite3_finalize(*ppStmt); 94752 rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail); 95429 rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail); 94753 } 95430 } 94754 sqlite3BtreeLeaveAll(db); 95431 sqlite3BtreeLeaveAll(db); 94755 sqlite3_mutex_leave(db->mutex); 95432 sqlite3_mutex_leave(db->mutex); > 95433 assert( rc==SQLITE_OK || *ppStmt==0 ); 94756 return rc; 95434 return rc; 94757 } 95435 } 94758 95436 94759 /* 95437 /* 94760 ** Rerun the compilation of a statement after a schema change. 95438 ** Rerun the compilation of a statement after a schema change. 94761 ** 95439 ** 94762 ** If the statement is successfully recompiled, return SQLITE_OK. Otherwise, 95440 ** If the statement is successfully recompiled, return SQLITE_OK. Otherwise, ................................................................................................................................................................................ 98056 } 98734 } 98057 pTab = p->pSrc->a[0].pTab; 98735 pTab = p->pSrc->a[0].pTab; 98058 pExpr = p->pEList->a[0].pExpr; 98736 pExpr = p->pEList->a[0].pExpr; 98059 assert( pTab && !pTab->pSelect && pExpr ); 98737 assert( pTab && !pTab->pSelect && pExpr ); 98060 98738 98061 if( IsVirtual(pTab) ) return 0; 98739 if( IsVirtual(pTab) ) return 0; 98062 if( pExpr->op!=TK_AGG_FUNCTION ) return 0; 98740 if( pExpr->op!=TK_AGG_FUNCTION ) return 0; > 98741 if( pAggInfo->nFunc==0 ) return 0; 98063 if( (pAggInfo->aFunc[0].pFunc->flags&SQLITE_FUNC_COUNT)==0 ) return 0; 98742 if( (pAggInfo->aFunc[0].pFunc->flags&SQLITE_FUNC_COUNT)==0 ) return 0; 98064 if( pExpr->flags&EP_Distinct ) return 0; 98743 if( pExpr->flags&EP_Distinct ) return 0; 98065 98744 98066 return pTab; 98745 return pTab; 98067 } 98746 } 98068 98747 98069 /* 98748 /* ................................................................................................................................................................................ 99046 sqlite3ExprAnalyzeAggList(&sNC, pOrderBy); 99725 sqlite3ExprAnalyzeAggList(&sNC, pOrderBy); 99047 if( pHaving ){ 99726 if( pHaving ){ 99048 sqlite3ExprAnalyzeAggregates(&sNC, pHaving); 99727 sqlite3ExprAnalyzeAggregates(&sNC, pHaving); 99049 } 99728 } 99050 sAggInfo.nAccumulator = sAggInfo.nColumn; 99729 sAggInfo.nAccumulator = sAggInfo.nColumn; 99051 for(i=0; i<sAggInfo.nFunc; i++){ 99730 for(i=0; i<sAggInfo.nFunc; i++){ 99052 assert( !ExprHasProperty(sAggInfo.aFunc[i].pExpr, EP_xIsSelect) ); 99731 assert( !ExprHasProperty(sAggInfo.aFunc[i].pExpr, EP_xIsSelect) ); > 99732 sNC.ncFlags |= NC_InAggFunc; 99053 sqlite3ExprAnalyzeAggList(&sNC, sAggInfo.aFunc[i].pExpr->x.pList); 99733 sqlite3ExprAnalyzeAggList(&sNC, sAggInfo.aFunc[i].pExpr->x.pList); > 99734 sNC.ncFlags &= ~NC_InAggFunc; 99054 } 99735 } 99055 if( db->mallocFailed ) goto select_end; 99736 if( db->mallocFailed ) goto select_end; 99056 99737 99057 /* Processing for aggregates with GROUP BY is very different and 99738 /* Processing for aggregates with GROUP BY is very different and 99058 ** much more complex than aggregates without a GROUP BY. 99739 ** much more complex than aggregates without a GROUP BY. 99059 */ 99740 */ 99060 if( pGroupBy ){ 99741 if( pGroupBy ){ ................................................................................................................................................................................ 101868 sqlite3BtreeClose(pDb->pBt); 102549 sqlite3BtreeClose(pDb->pBt); 101869 pDb->pBt = 0; 102550 pDb->pBt = 0; 101870 pDb->pSchema = 0; 102551 pDb->pSchema = 0; 101871 } 102552 } 101872 102553 101873 /* This both clears the schemas and reduces the size of the db->aDb[] 102554 /* This both clears the schemas and reduces the size of the db->aDb[] 101874 ** array. */ 102555 ** array. */ 101875 sqlite3ResetInternalSchema(db, -1); | 102556 sqlite3ResetAllSchemasOfConnection(db); 101876 102557 101877 return rc; 102558 return rc; 101878 } 102559 } 101879 102560 101880 #endif /* SQLITE_OMIT_VACUUM && SQLITE_OMIT_ATTACH */ 102561 #endif /* SQLITE_OMIT_VACUUM && SQLITE_OMIT_ATTACH */ 101881 102562 101882 /************** End of vacuum.c **********************************************/ 102563 /************** End of vacuum.c **********************************************/ ................................................................................................................................................................................ 101900 ** Before a virtual table xCreate() or xConnect() method is invoked, the 102581 ** Before a virtual table xCreate() or xConnect() method is invoked, the 101901 ** sqlite3.pVtabCtx member variable is set to point to an instance of 102582 ** sqlite3.pVtabCtx member variable is set to point to an instance of 101902 ** this struct allocated on the stack. It is used by the implementation of 102583 ** this struct allocated on the stack. It is used by the implementation of 101903 ** the sqlite3_declare_vtab() and sqlite3_vtab_config() APIs, both of which 102584 ** the sqlite3_declare_vtab() and sqlite3_vtab_config() APIs, both of which 101904 ** are invoked only from within xCreate and xConnect methods. 102585 ** are invoked only from within xCreate and xConnect methods. 101905 */ 102586 */ 101906 struct VtabCtx { 102587 struct VtabCtx { 101907 Table *pTab; | 102588 VTable *pVTable; /* The virtual table being constructed */ 101908 VTable *pVTable; | 102589 Table *pTab; /* The Table object to which the virtual table belongs */ 101909 }; 102590 }; 101910 102591 101911 /* 102592 /* 101912 ** The actual function that does the work of creating a new module. 102593 ** The actual function that does the work of creating a new module. 101913 ** This function implements the sqlite3_create_module() and 102594 ** This function implements the sqlite3_create_module() and 101914 ** sqlite3_create_module_v2() interfaces. 102595 ** sqlite3_create_module_v2() interfaces. 101915 */ 102596 */ ................................................................................................................................................................................ 101916 static int createModule( 102597 static int createModule( 101917 sqlite3 *db, /* Database in which module is registered */ 102598 sqlite3 *db, /* Database in which module is registered */ 101918 const char *zName, /* Name assigned to this module */ 102599 const char *zName, /* Name assigned to this module */ 101919 const sqlite3_module *pModule, /* The definition of the module */ 102600 const sqlite3_module *pModule, /* The definition of the module */ 101920 void *pAux, /* Context pointer for xCreate/xConnect */ 102601 void *pAux, /* Context pointer for xCreate/xConnect */ 101921 void (*xDestroy)(void *) /* Module destructor function */ 102602 void (*xDestroy)(void *) /* Module destructor function */ 101922 ){ 102603 ){ > 102604 int rc = SQLITE_OK; 101923 int rc, nName; | 102605 int nName; 101924 Module *pMod; < 101925 102606 101926 sqlite3_mutex_enter(db->mutex); 102607 sqlite3_mutex_enter(db->mutex); 101927 nName = sqlite3Strlen30(zName); 102608 nName = sqlite3Strlen30(zName); > 102609 if( sqlite3HashFind(&db->aModule, zName, nName) ){ > 102610 rc = SQLITE_MISUSE_BKPT; > 102611 }else{ > 102612 Module *pMod; 101928 pMod = (Module *)sqlite3DbMallocRaw(db, sizeof(Module) + nName + 1); | 102613 pMod = (Module *)sqlite3DbMallocRaw(db, sizeof(Module) + nName + 1); 101929 if( pMod ){ | 102614 if( pMod ){ 101930 Module *pDel; | 102615 Module *pDel; 101931 char *zCopy = (char *)(&pMod[1]); | 102616 char *zCopy = (char *)(&pMod[1]); 101932 memcpy(zCopy, zName, nName+1); | 102617 memcpy(zCopy, zName, nName+1); 101933 pMod->zName = zCopy; | 102618 pMod->zName = zCopy; 101934 pMod->pModule = pModule; | 102619 pMod->pModule = pModule; 101935 pMod->pAux = pAux; | 102620 pMod->pAux = pAux; 101936 pMod->xDestroy = xDestroy; | 102621 pMod->xDestroy = xDestroy; 101937 pDel = (Module *)sqlite3HashInsert(&db->aModule, zCopy, nName, (void*)pMod); | 102622 pDel = (Module *)sqlite3HashInsert(&db->aModule,zCopy,nName,(void*)pMod); 101938 if( pDel && pDel->xDestroy ){ < 101939 sqlite3ResetInternalSchema(db, -1); < 101940 pDel->xDestroy(pDel->pAux); < 101941 } < 101942 sqlite3DbFree(db, pDel); | 102623 assert( pDel==0 || pDel==pMod ); 101943 if( pDel==pMod ){ | 102624 if( pDel ){ 101944 db->mallocFailed = 1; | 102625 db->mallocFailed = 1; > 102626 sqlite3DbFree(db, pDel); 101945 } | 102627 } 101946 }else if( xDestroy ){ < 101947 xDestroy(pAux); < 101948 } | 102628 } > 102629 } 101949 rc = sqlite3ApiExit(db, SQLITE_OK); | 102630 rc = sqlite3ApiExit(db, rc); > 102631 if( rc!=SQLITE_OK && xDestroy ) xDestroy(pAux); > 102632 101950 sqlite3_mutex_leave(db->mutex); 102633 sqlite3_mutex_leave(db->mutex); 101951 return rc; 102634 return rc; 101952 } 102635 } 101953 102636 101954 102637 101955 /* 102638 /* 101956 ** External API function used to create a new virtual-table module. 102639 ** External API function used to create a new virtual-table module. ................................................................................................................................................................................ 102057 } 102740 } 102058 pVTable = pNext; 102741 pVTable = pNext; 102059 } 102742 } 102060 102743 102061 assert( !db || pRet ); 102744 assert( !db || pRet ); 102062 return pRet; 102745 return pRet; 102063 } 102746 } > 102747 > 102748 /* > 102749 ** Table *p is a virtual table. This function removes the VTable object > 102750 ** for table *p associated with database connection db from the linked > 102751 ** list in p->pVTab. It also decrements the VTable ref count. This is > 102752 ** used when closing database connection db to free all of its VTable > 102753 ** objects without disturbing the rest of the Schema object (which may > 102754 ** be being used by other shared-cache connections). > 102755 */ > 102756 SQLITE_PRIVATE void sqlite3VtabDisconnect(sqlite3 *db, Table *p){ > 102757 VTable **ppVTab; > 102758 > 102759 assert( IsVirtual(p) ); > 102760 assert( sqlite3BtreeHoldsAllMutexes(db) ); > 102761 assert( sqlite3_mutex_held(db->mutex) ); > 102762 > 102763 for(ppVTab=&p->pVTable; *ppVTab; ppVTab=&(*ppVTab)->pNext){ > 102764 if( (*ppVTab)->db==db ){ > 102765 VTable *pVTab = *ppVTab; > 102766 *ppVTab = pVTab->pNext; > 102767 sqlite3VtabUnlock(pVTab); > 102768 break; > 102769 } > 102770 } > 102771 } 102064 102772 102065 102773 102066 /* 102774 /* 102067 ** Disconnect all the virtual table objects in the sqlite3.pDisconnect list. 102775 ** Disconnect all the virtual table objects in the sqlite3.pDisconnect list. 102068 ** 102776 ** 102069 ** This function may only be called when the mutexes associated with all 102777 ** This function may only be called when the mutexes associated with all 102070 ** shared b-tree databases opened using connection db are held by the 102778 ** shared b-tree databases opened using connection db are held by the ................................................................................................................................................................................ 112947 ** name of a directory, then that directory will be used to store 113655 ** name of a directory, then that directory will be used to store 112948 ** temporary files. 113656 ** temporary files. 112949 ** 113657 ** 112950 ** See also the "PRAGMA temp_store_directory" SQL command. 113658 ** See also the "PRAGMA temp_store_directory" SQL command. 112951 */ 113659 */ 112952 SQLITE_API char *sqlite3_temp_directory = 0; 113660 SQLITE_API char *sqlite3_temp_directory = 0; 112953 113661 > 113662 /* > 113663 ** If the following global variable points to a string which is the > 113664 ** name of a directory, then that directory will be used to store > 113665 ** all database files specified with a relative pathname. > 113666 ** > 113667 ** See also the "PRAGMA data_store_directory" SQL command. > 113668 */ > 113669 SQLITE_API char *sqlite3_data_directory = 0; > 113670 112954 /* 113671 /* 112955 ** Initialize SQLite. 113672 ** Initialize SQLite. 112956 ** 113673 ** 112957 ** This routine must be called to initialize the memory allocation, 113674 ** This routine must be called to initialize the memory allocation, 112958 ** VFS, and mutex subsystems prior to doing any serious work with 113675 ** VFS, and mutex subsystems prior to doing any serious work with 112959 ** SQLite. But as long as you do not compile with SQLITE_OMIT_AUTOINIT 113676 ** SQLite. But as long as you do not compile with SQLITE_OMIT_AUTOINIT 112960 ** this routine will be called automatically by key routines such as 113677 ** this routine will be called automatically by key routines such as ................................................................................................................................................................................ 113145 if( sqlite3GlobalConfig.isPCacheInit ){ 113862 if( sqlite3GlobalConfig.isPCacheInit ){ 113146 sqlite3PcacheShutdown(); 113863 sqlite3PcacheShutdown(); 113147 sqlite3GlobalConfig.isPCacheInit = 0; 113864 sqlite3GlobalConfig.isPCacheInit = 0; 113148 } 113865 } 113149 if( sqlite3GlobalConfig.isMallocInit ){ 113866 if( sqlite3GlobalConfig.isMallocInit ){ 113150 sqlite3MallocEnd(); 113867 sqlite3MallocEnd(); 113151 sqlite3GlobalConfig.isMallocInit = 0; 113868 sqlite3GlobalConfig.isMallocInit = 0; > 113869 > 113870 #ifndef SQLITE_OMIT_SHUTDOWN_DIRECTORIES > 113871 /* The heap subsystem has now been shutdown and these values are supposed > 113872 ** to be NULL or point to memory that was obtained from sqlite3_malloc(), > 113873 ** which would rely on that heap subsystem; therefore, make sure these > 113874 ** values cannot refer to heap memory that was just invalidated when the > 113875 ** heap subsystem was shutdown. This is only done if the current call to > 113876 ** this function resulted in the heap subsystem actually being shutdown. > 113877 */ > 113878 sqlite3_data_directory = 0; > 113879 sqlite3_temp_directory = 0; > 113880 #endif 113152 } 113881 } 113153 if( sqlite3GlobalConfig.isMutexInit ){ 113882 if( sqlite3GlobalConfig.isMutexInit ){ 113154 sqlite3MutexEnd(); 113883 sqlite3MutexEnd(); 113155 sqlite3GlobalConfig.isMutexInit = 0; 113884 sqlite3GlobalConfig.isMutexInit = 0; 113156 } 113885 } 113157 113886 113158 return SQLITE_OK; 113887 return SQLITE_OK; ................................................................................................................................................................................ 113592 pDestructor->nRef--; 114321 pDestructor->nRef--; 113593 if( pDestructor->nRef==0 ){ 114322 if( pDestructor->nRef==0 ){ 113594 pDestructor->xDestroy(pDestructor->pUserData); 114323 pDestructor->xDestroy(pDestructor->pUserData); 113595 sqlite3DbFree(db, pDestructor); 114324 sqlite3DbFree(db, pDestructor); 113596 } 114325 } 113597 } 114326 } 113598 } 114327 } > 114328 > 114329 /* > 114330 ** Disconnect all sqlite3_vtab objects that belong to database connection > 114331 ** db. This is called when db is being closed. > 114332 */ > 114333 static void disconnectAllVtab(sqlite3 *db){ > 114334 #ifndef SQLITE_OMIT_VIRTUALTABLE > 114335 int i; > 114336 sqlite3BtreeEnterAll(db); > 114337 for(i=0; i<db->nDb; i++){ > 114338 Schema *pSchema = db->aDb[i].pSchema; > 114339 if( db->aDb[i].pSchema ){ > 114340 HashElem *p; > 114341 for(p=sqliteHashFirst(&pSchema->tblHash); p; p=sqliteHashNext(p)){ > 114342 Table *pTab = (Table *)sqliteHashData(p); > 114343 if( IsVirtual(pTab) ) sqlite3VtabDisconnect(db, pTab); > 114344 } > 114345 } > 114346 } > 114347 sqlite3BtreeLeaveAll(db); > 114348 #else > 114349 UNUSED_PARAMETER(db); > 114350 #endif > 114351 } 113599 114352 113600 /* 114353 /* 113601 ** Close an existing SQLite database 114354 ** Close an existing SQLite database 113602 */ 114355 */ 113603 SQLITE_API int sqlite3_close(sqlite3 *db){ 114356 SQLITE_API int sqlite3_close(sqlite3 *db){ 113604 HashElem *i; /* Hash table iterator */ 114357 HashElem *i; /* Hash table iterator */ 113605 int j; 114358 int j; ................................................................................................................................................................................ 113608 return SQLITE_OK; 114361 return SQLITE_OK; 113609 } 114362 } 113610 if( !sqlite3SafetyCheckSickOrOk(db) ){ 114363 if( !sqlite3SafetyCheckSickOrOk(db) ){ 113611 return SQLITE_MISUSE_BKPT; 114364 return SQLITE_MISUSE_BKPT; 113612 } 114365 } 113613 sqlite3_mutex_enter(db->mutex); 114366 sqlite3_mutex_enter(db->mutex); 113614 114367 113615 /* Force xDestroy calls on all virtual tables */ | 114368 /* Force xDisconnect calls on all virtual tables */ 113616 sqlite3ResetInternalSchema(db, -1); | 114369 disconnectAllVtab(db); 113617 114370 113618 /* If a transaction is open, the ResetInternalSchema() call above | 114371 /* If a transaction is open, the disconnectAllVtab() call above 113619 ** will not have called the xDisconnect() method on any virtual 114372 ** will not have called the xDisconnect() method on any virtual 113620 ** tables in the db->aVTrans[] array. The following sqlite3VtabRollback() 114373 ** tables in the db->aVTrans[] array. The following sqlite3VtabRollback() 113621 ** call will do so. We need to do this before the check for active 114374 ** call will do so. We need to do this before the check for active 113622 ** SQL statements below, as the v-table implementation may be storing 114375 ** SQL statements below, as the v-table implementation may be storing 113623 ** some prepared statements internally. 114376 ** some prepared statements internally. 113624 */ 114377 */ 113625 sqlite3VtabRollback(db); 114378 sqlite3VtabRollback(db); ................................................................................................................................................................................ 113642 return SQLITE_BUSY; 114395 return SQLITE_BUSY; 113643 } 114396 } 113644 } 114397 } 113645 114398 113646 /* Free any outstanding Savepoint structures. */ 114399 /* Free any outstanding Savepoint structures. */ 113647 sqlite3CloseSavepoints(db); 114400 sqlite3CloseSavepoints(db); 113648 114401 > 114402 /* Close all database connections */ 113649 for(j=0; j<db->nDb; j++){ 114403 for(j=0; j<db->nDb; j++){ 113650 struct Db *pDb = &db->aDb[j]; 114404 struct Db *pDb = &db->aDb[j]; 113651 if( pDb->pBt ){ 114405 if( pDb->pBt ){ 113652 sqlite3BtreeClose(pDb->pBt); 114406 sqlite3BtreeClose(pDb->pBt); 113653 pDb->pBt = 0; 114407 pDb->pBt = 0; 113654 if( j!=1 ){ 114408 if( j!=1 ){ 113655 pDb->pSchema = 0; 114409 pDb->pSchema = 0; 113656 } 114410 } 113657 } 114411 } 113658 } 114412 } 113659 sqlite3ResetInternalSchema(db, -1); | 114413 /* Clear the TEMP schema separately and last */ > 114414 if( db->aDb[1].pSchema ){ > 114415 sqlite3SchemaClear(db->aDb[1].pSchema); > 114416 } > 114417 sqlite3VtabUnlockList(db); > 114418 > 114419 /* Free up the array of auxiliary databases */ > 114420 sqlite3CollapseDatabaseArray(db); > 114421 assert( db->nDb<=2 ); > 114422 assert( db->aDb==db->aDbStatic ); 113660 114423 113661 /* Tell the code in notify.c that the connection no longer holds any 114424 /* Tell the code in notify.c that the connection no longer holds any 113662 ** locks and does not require any further unlock-notify callbacks. 114425 ** locks and does not require any further unlock-notify callbacks. 113663 */ 114426 */ 113664 sqlite3ConnectionClosed(db); 114427 sqlite3ConnectionClosed(db); 113665 114428 113666 assert( db->nDb<=2 ); < 113667 assert( db->aDb==db->aDbStatic ); < 113668 for(j=0; j<ArraySize(db->aFunc.a); j++){ 114429 for(j=0; j<ArraySize(db->aFunc.a); j++){ 113669 FuncDef *pNext, *pHash, *p; 114430 FuncDef *pNext, *pHash, *p; 113670 for(p=db->aFunc.a[j]; p; p=pHash){ 114431 for(p=db->aFunc.a[j]; p; p=pHash){ 113671 pHash = p->pHash; 114432 pHash = p->pHash; 113672 while( p ){ 114433 while( p ){ 113673 functionDestroy(db, p); 114434 functionDestroy(db, p); 113674 pNext = p->pNext; 114435 pNext = p->pNext; ................................................................................................................................................................................ 113747 } 114508 } 113748 } 114509 } 113749 sqlite3VtabRollback(db); 114510 sqlite3VtabRollback(db); 113750 sqlite3EndBenignMalloc(); 114511 sqlite3EndBenignMalloc(); 113751 114512 113752 if( db->flags&SQLITE_InternChanges ){ 114513 if( db->flags&SQLITE_InternChanges ){ 113753 sqlite3ExpirePreparedStatements(db); 114514 sqlite3ExpirePreparedStatements(db); 113754 sqlite3ResetInternalSchema(db, -1); | 114515 sqlite3ResetAllSchemasOfConnection(db); 113755 } 114516 } 113756 114517 113757 /* Any deferred constraint violations have now been resolved. */ 114518 /* Any deferred constraint violations have now been resolved. */ 113758 db->nDeferredCons = 0; 114519 db->nDeferredCons = 0; 113759 114520 113760 /* If one has been configured, invoke the rollback-hook callback */ 114521 /* If one has been configured, invoke the rollback-hook callback */ 113761 if( db->xRollbackCallback && (inTrans || !db->autoCommit) ){ 114522 if( db->xRollbackCallback && (inTrans || !db->autoCommit) ){ ................................................................................................................................................................................ 114885 zModeType = "cache"; 115646 zModeType = "cache"; 114886 } 115647 } 114887 if( nOpt==4 && memcmp("mode", zOpt, 4)==0 ){ 115648 if( nOpt==4 && memcmp("mode", zOpt, 4)==0 ){ 114888 static struct OpenMode aOpenMode[] = { 115649 static struct OpenMode aOpenMode[] = { 114889 { "ro", SQLITE_OPEN_READONLY }, 115650 { "ro", SQLITE_OPEN_READONLY }, 114890 { "rw", SQLITE_OPEN_READWRITE }, 115651 { "rw", SQLITE_OPEN_READWRITE }, 114891 { "rwc", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE }, 115652 { "rwc", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE }, > 115653 { "memory", > 115654 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE > 115655 | SQLITE_OPEN_MEMORY }, 114892 { 0, 0 } 115656 { 0, 0 } 114893 }; 115657 }; 114894 115658 114895 mask = SQLITE_OPEN_READONLY|SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE; | 115659 mask = SQLITE_OPEN_READONLY | SQLITE_OPEN_READWRITE > 115660 | SQLITE_OPEN_CREATE | SQLITE_OPEN_MEMORY; 114896 aMode = aOpenMode; 115661 aMode = aOpenMode; 114897 limit = mask & flags; 115662 limit = mask & flags; 114898 zModeType = "access"; 115663 zModeType = "access"; 114899 } 115664 } 114900 115665 114901 if( aMode ){ 115666 if( aMode ){ 114902 int i; 115667 int i; ................................................................................................................................................................................ 114909 } 115674 } 114910 } 115675 } 114911 if( mode==0 ){ 115676 if( mode==0 ){ 114912 *pzErrMsg = sqlite3_mprintf("no such %s mode: %s", zModeType, zVal); 115677 *pzErrMsg = sqlite3_mprintf("no such %s mode: %s", zModeType, zVal); 114913 rc = SQLITE_ERROR; 115678 rc = SQLITE_ERROR; 114914 goto parse_uri_out; 115679 goto parse_uri_out; 114915 } 115680 } 114916 if( mode>limit ){ | 115681 if( (mode & ~SQLITE_OPEN_MEMORY)>limit ){ 114917 *pzErrMsg = sqlite3_mprintf("%s mode not allowed: %s", 115682 *pzErrMsg = sqlite3_mprintf("%s mode not allowed: %s", 114918 zModeType, zVal); 115683 zModeType, zVal); 114919 rc = SQLITE_PERM; 115684 rc = SQLITE_PERM; 114920 goto parse_uri_out; 115685 goto parse_uri_out; 114921 } 115686 } 114922 flags = (flags & ~mask) | mode; 115687 flags = (flags & ~mask) | mode; 114923 } 115688 } ................................................................................................................................................................................ 114928 115693 114929 }else{ 115694 }else{ 114930 zFile = sqlite3_malloc(nUri+2); 115695 zFile = sqlite3_malloc(nUri+2); 114931 if( !zFile ) return SQLITE_NOMEM; 115696 if( !zFile ) return SQLITE_NOMEM; 114932 memcpy(zFile, zUri, nUri); 115697 memcpy(zFile, zUri, nUri); 114933 zFile[nUri] = '\0'; 115698 zFile[nUri] = '\0'; 114934 zFile[nUri+1] = '\0'; 115699 zFile[nUri+1] = '\0'; > 115700 flags &= ~SQLITE_OPEN_URI; 114935 } 115701 } 114936 115702 114937 *ppVfs = sqlite3_vfs_find(zVfs); 115703 *ppVfs = sqlite3_vfs_find(zVfs); 114938 if( *ppVfs==0 ){ 115704 if( *ppVfs==0 ){ 114939 *pzErrMsg = sqlite3_mprintf("no such vfs: %s", zVfs); 115705 *pzErrMsg = sqlite3_mprintf("no such vfs: %s", zVfs); 114940 rc = SQLITE_ERROR; 115706 rc = SQLITE_ERROR; 114941 } 115707 } ................................................................................................................................................................................ 117372 SQLITE_PRIVATE int sqlite3Fts3MsrIncrNext( 118138 SQLITE_PRIVATE int sqlite3Fts3MsrIncrNext( 117373 Fts3Table *, Fts3MultiSegReader *, sqlite3_int64 *, char **, int *); 118139 Fts3Table *, Fts3MultiSegReader *, sqlite3_int64 *, char **, int *); 117374 SQLITE_PRIVATE int sqlite3Fts3EvalPhrasePoslist(Fts3Cursor *, Fts3Expr *, int iC 118140 SQLITE_PRIVATE int sqlite3Fts3EvalPhrasePoslist(Fts3Cursor *, Fts3Expr *, int iC 117375 SQLITE_PRIVATE int sqlite3Fts3MsrOvfl(Fts3Cursor *, Fts3MultiSegReader *, int *) 118141 SQLITE_PRIVATE int sqlite3Fts3MsrOvfl(Fts3Cursor *, Fts3MultiSegReader *, int *) 117376 SQLITE_PRIVATE int sqlite3Fts3MsrIncrRestart(Fts3MultiSegReader *pCsr); 118142 SQLITE_PRIVATE int sqlite3Fts3MsrIncrRestart(Fts3MultiSegReader *pCsr); 117377 118143 117378 SQLITE_PRIVATE int sqlite3Fts3DeferredTokenList(Fts3DeferredToken *, char **, in 118144 SQLITE_PRIVATE int sqlite3Fts3DeferredTokenList(Fts3DeferredToken *, char **, in > 118145 > 118146 /* fts3_unicode2.c (functions generated by parsing unicode text files) */ > 118147 #ifdef SQLITE_ENABLE_FTS4_UNICODE61 > 118148 SQLITE_PRIVATE int sqlite3FtsUnicodeFold(int, int); > 118149 SQLITE_PRIVATE int sqlite3FtsUnicodeIsalnum(int); > 118150 SQLITE_PRIVATE int sqlite3FtsUnicodeIsdiacritic(int); > 118151 #endif 117379 118152 117380 #endif /* !SQLITE_CORE || SQLITE_ENABLE_FTS3 */ 118153 #endif /* !SQLITE_CORE || SQLITE_ENABLE_FTS3 */ 117381 #endif /* _FTSINT_H */ 118154 #endif /* _FTSINT_H */ 117382 118155 117383 /************** End of fts3Int.h *********************************************/ 118156 /************** End of fts3Int.h *********************************************/ 117384 /************** Continuing where we left off in fts3.c ***********************/ 118157 /************** Continuing where we left off in fts3.c ***********************/ 117385 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) 118158 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) ................................................................................................................................................................................ 120641 ** 121414 ** 120642 ** Calling sqlite3Fts3SimpleTokenizerModule() sets the value pointed 121415 ** Calling sqlite3Fts3SimpleTokenizerModule() sets the value pointed 120643 ** to by the argument to point to the "simple" tokenizer implementation. 121416 ** to by the argument to point to the "simple" tokenizer implementation. 120644 ** And so on. 121417 ** And so on. 120645 */ 121418 */ 120646 SQLITE_PRIVATE void sqlite3Fts3SimpleTokenizerModule(sqlite3_tokenizer_module co 121419 SQLITE_PRIVATE void sqlite3Fts3SimpleTokenizerModule(sqlite3_tokenizer_module co 120647 SQLITE_PRIVATE void sqlite3Fts3PorterTokenizerModule(sqlite3_tokenizer_module co 121420 SQLITE_PRIVATE void sqlite3Fts3PorterTokenizerModule(sqlite3_tokenizer_module co > 121421 #ifdef SQLITE_ENABLE_FTS4_UNICODE61 > 121422 SQLITE_PRIVATE void sqlite3Fts3UnicodeTokenizer(sqlite3_tokenizer_module const** > 121423 #endif 120648 #ifdef SQLITE_ENABLE_ICU 121424 #ifdef SQLITE_ENABLE_ICU 120649 SQLITE_PRIVATE void sqlite3Fts3IcuTokenizerModule(sqlite3_tokenizer_module const 121425 SQLITE_PRIVATE void sqlite3Fts3IcuTokenizerModule(sqlite3_tokenizer_module const 120650 #endif 121426 #endif 120651 121427 120652 /* 121428 /* 120653 ** Initialise the fts3 extension. If this extension is built as part 121429 ** Initialise the fts3 extension. If this extension is built as part 120654 ** of the sqlite library, then this function is called directly by 121430 ** of the sqlite library, then this function is called directly by ................................................................................................................................................................................ 120656 ** function is called by the sqlite3_extension_init() entry point. 121432 ** function is called by the sqlite3_extension_init() entry point. 120657 */ 121433 */ 120658 SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){ 121434 SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){ 120659 int rc = SQLITE_OK; 121435 int rc = SQLITE_OK; 120660 Fts3Hash *pHash = 0; 121436 Fts3Hash *pHash = 0; 120661 const sqlite3_tokenizer_module *pSimple = 0; 121437 const sqlite3_tokenizer_module *pSimple = 0; 120662 const sqlite3_tokenizer_module *pPorter = 0; 121438 const sqlite3_tokenizer_module *pPorter = 0; > 121439 #ifdef SQLITE_ENABLE_FTS4_UNICODE61 > 121440 const sqlite3_tokenizer_module *pUnicode = 0; > 121441 #endif 120663 121442 120664 #ifdef SQLITE_ENABLE_ICU 121443 #ifdef SQLITE_ENABLE_ICU 120665 const sqlite3_tokenizer_module *pIcu = 0; 121444 const sqlite3_tokenizer_module *pIcu = 0; 120666 sqlite3Fts3IcuTokenizerModule(&pIcu); 121445 sqlite3Fts3IcuTokenizerModule(&pIcu); 120667 #endif 121446 #endif > 121447 > 121448 #ifdef SQLITE_ENABLE_FTS4_UNICODE61 > 121449 sqlite3Fts3UnicodeTokenizer(&pUnicode); > 121450 #endif 120668 121451 120669 #ifdef SQLITE_TEST 121452 #ifdef SQLITE_TEST 120670 rc = sqlite3Fts3InitTerm(db); 121453 rc = sqlite3Fts3InitTerm(db); 120671 if( rc!=SQLITE_OK ) return rc; 121454 if( rc!=SQLITE_OK ) return rc; 120672 #endif 121455 #endif 120673 121456 120674 rc = sqlite3Fts3InitAux(db); 121457 rc = sqlite3Fts3InitAux(db); ................................................................................................................................................................................ 120685 sqlite3Fts3HashInit(pHash, FTS3_HASH_STRING, 1); 121468 sqlite3Fts3HashInit(pHash, FTS3_HASH_STRING, 1); 120686 } 121469 } 120687 121470 120688 /* Load the built-in tokenizers into the hash table */ 121471 /* Load the built-in tokenizers into the hash table */ 120689 if( rc==SQLITE_OK ){ 121472 if( rc==SQLITE_OK ){ 120690 if( sqlite3Fts3HashInsert(pHash, "simple", 7, (void *)pSimple) 121473 if( sqlite3Fts3HashInsert(pHash, "simple", 7, (void *)pSimple) 120691 || sqlite3Fts3HashInsert(pHash, "porter", 7, (void *)pPorter) 121474 || sqlite3Fts3HashInsert(pHash, "porter", 7, (void *)pPorter) > 121475 > 121476 #ifdef SQLITE_ENABLE_FTS4_UNICODE61 > 121477 || sqlite3Fts3HashInsert(pHash, "unicode61", 10, (void *)pUnicode) > 121478 #endif 120692 #ifdef SQLITE_ENABLE_ICU 121479 #ifdef SQLITE_ENABLE_ICU 120693 || (pIcu && sqlite3Fts3HashInsert(pHash, "icu", 4, (void *)pIcu)) 121480 || (pIcu && sqlite3Fts3HashInsert(pHash, "icu", 4, (void *)pIcu)) 120694 #endif 121481 #endif 120695 ){ 121482 ){ 120696 rc = SQLITE_NOMEM; 121483 rc = SQLITE_NOMEM; 120697 } 121484 } 120698 } 121485 } ................................................................................................................................................................................ 128837 if( sqlite3_step(pStmt)==SQLITE_ROW ){ 129624 if( sqlite3_step(pStmt)==SQLITE_ROW ){ 128838 fts3DecodeIntArray(nStat, a, 129625 fts3DecodeIntArray(nStat, a, 128839 sqlite3_column_blob(pStmt, 0), 129626 sqlite3_column_blob(pStmt, 0), 128840 sqlite3_column_bytes(pStmt, 0)); 129627 sqlite3_column_bytes(pStmt, 0)); 128841 }else{ 129628 }else{ 128842 memset(a, 0, sizeof(u32)*(nStat) ); 129629 memset(a, 0, sizeof(u32)*(nStat) ); 128843 } 129630 } 128844 sqlite3_reset(pStmt); | 129631 rc = sqlite3_reset(pStmt); > 129632 if( rc!=SQLITE_OK ){ > 129633 sqlite3_free(a); > 129634 *pRC = rc; > 129635 return; > 129636 } 128845 if( nChng<0 && a[0]<(u32)(-nChng) ){ 129637 if( nChng<0 && a[0]<(u32)(-nChng) ){ 128846 a[0] = 0; 129638 a[0] = 0; 128847 }else{ 129639 }else{ 128848 a[0] += nChng; 129640 a[0] += nChng; 128849 } 129641 } 128850 for(i=0; i<p->nColumn+1; i++){ 129642 for(i=0; i<p->nColumn+1; i++){ 128851 u32 x = a[i+1]; 129643 u32 x = a[i+1]; ................................................................................................................................................................................ 132560 sqlite3_result_blob(pContext, pCsr->aMatchinfo, n, SQLITE_TRANSIENT); 133352 sqlite3_result_blob(pContext, pCsr->aMatchinfo, n, SQLITE_TRANSIENT); 132561 } 133353 } 132562 } 133354 } 132563 133355 132564 #endif 133356 #endif 132565 133357 132566 /************** End of fts3_snippet.c ****************************************/ 133358 /************** End of fts3_snippet.c ****************************************/ > 133359 /************** Begin file fts3_unicode.c ************************************/ > 133360 /* > 133361 ** 2012 May 24 > 133362 ** > 133363 ** The author disclaims copyright to this source code. In place of > 133364 ** a legal notice, here is a blessing: > 133365 ** > 133366 ** May you do good and not evil. > 133367 ** May you find forgiveness for yourself and forgive others. > 133368 ** May you share freely, never taking more than you give. > 133369 ** > 133370 ****************************************************************************** > 133371 ** > 133372 ** Implementation of the "unicode" full-text-search tokenizer. > 133373 */ > 133374 > 133375 #ifdef SQLITE_ENABLE_FTS4_UNICODE61 > 133376 > 133377 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) > 133378 > 133379 /* #include <assert.h> */ > 133380 /* #include <stdlib.h> */ > 133381 /* #include <stdio.h> */ > 133382 /* #include <string.h> */ > 133383 > 133384 > 133385 /* > 133386 ** The following two macros - READ_UTF8 and WRITE_UTF8 - have been copied > 133387 ** from the sqlite3 source file utf.c. If this file is compiled as part > 133388 ** of the amalgamation, they are not required. > 133389 */ > 133390 #ifndef SQLITE_AMALGAMATION > 133391 > 133392 static const unsigned char sqlite3Utf8Trans1[] = { > 133393 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, > 133394 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, > 133395 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, > 133396 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, > 133397 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, > 133398 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, > 133399 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, > 133400 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00, > 133401 }; > 133402 > 133403 #define READ_UTF8(zIn, zTerm, c) \ > 133404 c = *(zIn++); \ > 133405 if( c>=0xc0 ){ \ > 133406 c = sqlite3Utf8Trans1[c-0xc0]; \ > 133407 while( zIn!=zTerm && (*zIn & 0xc0)==0x80 ){ \ > 133408 c = (c<<6) + (0x3f & *(zIn++)); \ > 133409 } \ > 133410 if( c<0x80 \ > 133411 || (c&0xFFFFF800)==0xD800 \ > 133412 || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } \ > 133413 } > 133414 > 133415 #define WRITE_UTF8(zOut, c) { \ > 133416 if( c<0x00080 ){ \ > 133417 *zOut++ = (u8)(c&0xFF); \ > 133418 } \ > 133419 else if( c<0x00800 ){ \ > 133420 *zOut++ = 0xC0 + (u8)((c>>6)&0x1F); \ > 133421 *zOut++ = 0x80 + (u8)(c & 0x3F); \ > 133422 } \ > 133423 else if( c<0x10000 ){ \ > 133424 *zOut++ = 0xE0 + (u8)((c>>12)&0x0F); \ > 133425 *zOut++ = 0x80 + (u8)((c>>6) & 0x3F); \ > 133426 *zOut++ = 0x80 + (u8)(c & 0x3F); \ > 133427 }else{ \ > 133428 *zOut++ = 0xF0 + (u8)((c>>18) & 0x07); \ > 133429 *zOut++ = 0x80 + (u8)((c>>12) & 0x3F); \ > 133430 *zOut++ = 0x80 + (u8)((c>>6) & 0x3F); \ > 133431 *zOut++ = 0x80 + (u8)(c & 0x3F); \ > 133432 } \ > 133433 } > 133434 > 133435 #endif /* ifndef SQLITE_AMALGAMATION */ > 133436 > 133437 typedef struct unicode_tokenizer unicode_tokenizer; > 133438 typedef struct unicode_cursor unicode_cursor; > 133439 > 133440 struct unicode_tokenizer { > 133441 sqlite3_tokenizer base; > 133442 int bRemoveDiacritic; > 133443 }; > 133444 > 133445 struct unicode_cursor { > 133446 sqlite3_tokenizer_cursor base; > 133447 const unsigned char *aInput; /* Input text being tokenized */ > 133448 int nInput; /* Size of aInput[] in bytes */ > 133449 int iOff; /* Current offset within aInput[] */ > 133450 int iToken; /* Index of next token to be returned */ > 133451 char *zToken; /* storage for current token */ > 133452 int nAlloc; /* space allocated at zToken */ > 133453 }; > 133454 > 133455 /* > 133456 ** Create a new tokenizer instance. > 133457 */ > 133458 static int unicodeCreate( > 133459 int nArg, /* Size of array argv[] */ > 133460 const char * const *azArg, /* Tokenizer creation arguments */ > 133461 sqlite3_tokenizer **pp /* OUT: New tokenizer handle */ > 133462 ){ > 133463 unicode_tokenizer *pNew; /* New tokenizer object */ > 133464 int i; > 133465 pNew = (unicode_tokenizer *) sqlite3_malloc(sizeof(unicode_tokenizer)); > 133466 if( pNew==NULL ){ > 133467 return SQLITE_NOMEM; > 133468 } > 133469 memset(pNew, 0, sizeof(unicode_tokenizer)); > 133470 pNew->bRemoveDiacritic = 1; > 133471 > 133472 for(i=0; i<nArg; i++){ > 133473 const char *z = azArg[i]; > 133474 int n = strlen(z); > 133475 > 133476 if( n==19 && memcmp("remove_diacritics=1", z, 19)==0 ){ > 133477 pNew->bRemoveDiacritic = 1; > 133478 } > 133479 else if( n==19 && memcmp("remove_diacritics=0", z, 19)==0 ){ > 133480 pNew->bRemoveDiacritic = 0; > 133481 } > 133482 else{ > 133483 /* Unrecognized argument */ > 133484 return SQLITE_ERROR; > 133485 } > 133486 } > 133487 > 133488 *pp = &pNew->base; > 133489 return SQLITE_OK; > 133490 } > 133491 > 133492 /* > 133493 ** Destroy a tokenizer allocated by unicodeCreate(). > 133494 */ > 133495 static int unicodeDestroy(sqlite3_tokenizer *pTokenizer){ > 133496 sqlite3_free(pTokenizer); > 133497 return SQLITE_OK; > 133498 } > 133499 > 133500 /* > 133501 ** Prepare to begin tokenizing a particular string. The input > 133502 ** string to be tokenized is pInput[0..nBytes-1]. A cursor > 133503 ** used to incrementally tokenize this string is returned in > 133504 ** *ppCursor. > 133505 */ > 133506 static int unicodeOpen( > 133507 sqlite3_tokenizer *p, /* The tokenizer */ > 133508 const char *aInput, /* Input string */ > 133509 int nInput, /* Size of string aInput in bytes */ > 133510 sqlite3_tokenizer_cursor **pp /* OUT: New cursor object */ > 133511 ){ > 133512 unicode_cursor *pCsr; > 133513 > 133514 pCsr = (unicode_cursor *)sqlite3_malloc(sizeof(unicode_cursor)); > 133515 if( pCsr==0 ){ > 133516 return SQLITE_NOMEM; > 133517 } > 133518 memset(pCsr, 0, sizeof(unicode_cursor)); > 133519 > 133520 pCsr->aInput = (const unsigned char *)aInput; > 133521 if( aInput==0 ){ > 133522 pCsr->nInput = 0; > 133523 }else if( nInput<0 ){ > 133524 pCsr->nInput = (int)strlen(aInput); > 133525 }else{ > 133526 pCsr->nInput = nInput; > 133527 } > 133528 > 133529 *pp = &pCsr->base; > 133530 UNUSED_PARAMETER(p); > 133531 return SQLITE_OK; > 133532 } > 133533 > 133534 /* > 133535 ** Close a tokenization cursor previously opened by a call to > 133536 ** simpleOpen() above. > 133537 */ > 133538 static int unicodeClose(sqlite3_tokenizer_cursor *pCursor){ > 133539 unicode_cursor *pCsr = (unicode_cursor *) pCursor; > 133540 sqlite3_free(pCsr->zToken); > 133541 sqlite3_free(pCsr); > 133542 return SQLITE_OK; > 133543 } > 133544 > 133545 /* > 133546 ** Extract the next token from a tokenization cursor. The cursor must > 133547 ** have been opened by a prior call to simpleOpen(). > 133548 */ > 133549 static int unicodeNext( > 133550 sqlite3_tokenizer_cursor *p, /* Cursor returned by simpleOpen */ > 133551 const char **paToken, /* OUT: Token text */ > 133552 int *pnToken, /* OUT: Number of bytes at *paToken */ > 133553 int *piStart, /* OUT: Starting offset of token */ > 133554 int *piEnd, /* OUT: Ending offset of token */ > 133555 int *piPos /* OUT: Position integer of token */ > 133556 ){ > 133557 unicode_cursor *pCsr = (unicode_cursor *)p; > 133558 int iCode; > 133559 char *zOut; > 133560 const unsigned char *z = &pCsr->aInput[pCsr->iOff]; > 133561 const unsigned char *zStart = z; > 133562 const unsigned char *zEnd; > 133563 const unsigned char *zTerm = &pCsr->aInput[pCsr->nInput]; > 133564 > 133565 /* Scan past any delimiter characters before the start of the next token. > 133566 ** Return SQLITE_DONE early if this takes us all the way to the end of > 133567 ** the input. */ > 133568 while( z<zTerm ){ > 133569 READ_UTF8(z, zTerm, iCode); > 133570 if( sqlite3FtsUnicodeIsalnum(iCode) ) break; > 133571 zStart = z; > 133572 } > 133573 if( zStart>=zTerm ) return SQLITE_DONE; > 133574 > 133575 zOut = pCsr->zToken; > 133576 do { > 133577 int iOut; > 133578 > 133579 /* Grow the output buffer if required. */ > 133580 if( (zOut-pCsr->zToken)>=(pCsr->nAlloc-4) ){ > 133581 char *zNew = sqlite3_realloc(pCsr->zToken, pCsr->nAlloc+64); > 133582 if( !zNew ) return SQLITE_NOMEM; > 133583 zOut = &zNew[zOut - pCsr->zToken]; > 133584 pCsr->zToken = zNew; > 133585 pCsr->nAlloc += 64; > 133586 } > 133587 > 133588 /* Write the folded case of the last character read to the output */ > 133589 zEnd = z; > 133590 iOut = sqlite3FtsUnicodeFold(iCode, > 133591 ((unicode_tokenizer *)pCsr->base.pTokenizer)->bRemoveDiacritic > 133592 ); > 133593 if( iOut ){ > 133594 WRITE_UTF8(zOut, iOut); > 133595 } > 133596 > 133597 /* If the cursor is not at EOF, read the next character */ > 133598 if( z>=zTerm ) break; > 133599 READ_UTF8(z, zTerm, iCode); > 133600 }while( sqlite3FtsUnicodeIsalnum(iCode) > 133601 || sqlite3FtsUnicodeIsdiacritic(iCode) > 133602 ); > 133603 > 133604 /* Set the output variables and return. */ > 133605 pCsr->iOff = (z - pCsr->aInput); > 133606 *paToken = pCsr->zToken; > 133607 *pnToken = zOut - pCsr->zToken; > 133608 *piStart = (zStart - pCsr->aInput); > 133609 *piEnd = (zEnd - pCsr->aInput); > 133610 *piPos = pCsr->iToken++; > 133611 return SQLITE_OK; > 133612 } > 133613 > 133614 /* > 133615 ** Set *ppModule to a pointer to the sqlite3_tokenizer_module > 133616 ** structure for the unicode tokenizer. > 133617 */ > 133618 SQLITE_PRIVATE void sqlite3Fts3UnicodeTokenizer(sqlite3_tokenizer_module const * > 133619 static const sqlite3_tokenizer_module module = { > 133620 0, > 133621 unicodeCreate, > 133622 unicodeDestroy, > 133623 unicodeOpen, > 133624 unicodeClose, > 133625 unicodeNext, > 133626 0, > 133627 }; > 133628 *ppModule = &module; > 133629 } > 133630 > 133631 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */ > 133632 #endif /* ifndef SQLITE_ENABLE_FTS4_UNICODE61 */ > 133633 > 133634 /************** End of fts3_unicode.c ****************************************/ > 133635 /************** Begin file fts3_unicode2.c ***********************************/ > 133636 /* > 133637 ** 2012 May 25 > 133638 ** > 133639 ** The author disclaims copyright to this source code. In place of > 133640 ** a legal notice, here is a blessing: > 133641 ** > 133642 ** May you do good and not evil. > 133643 ** May you find forgiveness for yourself and forgive others. > 133644 ** May you share freely, never taking more than you give. > 133645 ** > 133646 ****************************************************************************** > 133647 */ > 133648 > 133649 /* > 133650 ** DO NOT EDIT THIS MACHINE GENERATED FILE. > 133651 */ > 133652 > 133653 #if defined(SQLITE_ENABLE_FTS4_UNICODE61) > 133654 #if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4) > 133655 > 133656 /* #include <assert.h> */ > 133657 > 133658 /* > 133659 ** Return true if the argument corresponds to a unicode codepoint > 133660 ** classified as either a letter or a number. Otherwise false. > 133661 ** > 133662 ** The results are undefined if the value passed to this function > 133663 ** is less than zero. > 133664 */ > 133665 SQLITE_PRIVATE int sqlite3FtsUnicodeIsalnum(int c){ > 133666 /* Each unsigned integer in the following array corresponds to a contiguous > 133667 ** range of unicode codepoints that are not either letters or numbers (i.e. > 133668 ** codepoints for which this function should return 0). > 133669 ** > 133670 ** The most significant 22 bits in each 32-bit value contain the first > 133671 ** codepoint in the range. The least significant 10 bits are used to store > 133672 ** the size of the range (always at least 1). In other words, the value > 133673 ** ((C<<22) + N) represents a range of N codepoints starting with codepoint > 133674 ** C. It is not possible to represent a range larger than 1023 codepoints > 133675 ** using this format. > 133676 */ > 133677 const static unsigned int aEntry[] = { > 133678 0x00000030, 0x0000E807, 0x00016C06, 0x0001EC2F, 0x0002AC07, > 133679 0x0002D001, 0x0002D803, 0x0002EC01, 0x0002FC01, 0x00035C01, > 133680 0x0003DC01, 0x000B0804, 0x000B480E, 0x000B9407, 0x000BB401, > 133681 0x000BBC81, 0x000DD401, 0x000DF801, 0x000E1002, 0x000E1C01, > 133682 0x000FD801, 0x00120808, 0x00156806, 0x00162402, 0x00163C01, > 133683 0x00164437, 0x0017CC02, 0x00180005, 0x00181816, 0x00187802, > 133684 0x00192C15, 0x0019A804, 0x0019C001, 0x001B5001, 0x001B580F, > 133685 0x001B9C07, 0x001BF402, 0x001C000E, 0x001C3C01, 0x001C4401, > 133686 0x001CC01B, 0x001E980B, 0x001FAC09, 0x001FD804, 0x00205804, > 133687 0x00206C09, 0x00209403, 0x0020A405, 0x0020C00F, 0x00216403, > 133688 0x00217801, 0x0023901B, 0x00240004, 0x0024E803, 0x0024F812, > 133689 0x00254407, 0x00258804, 0x0025C001, 0x00260403, 0x0026F001, > 133690 0x0026F807, 0x00271C02, 0x00272C03, 0x00275C01, 0x00278802, > 133691 0x0027C802, 0x0027E802, 0x00280403, 0x0028F001, 0x0028F805, > 133692 0x00291C02, 0x00292C03, 0x00294401, 0x0029C002, 0x0029D401, > 133693 0x002A0403, 0x002AF001, 0x002AF808, 0x002B1C03, 0x002B2C03, > 133694 0x002B8802, 0x002BC002, 0x002C0403, 0x002CF001, 0x002CF807, > 133695 0x002D1C02, 0x002D2C03, 0x002D5802, 0x002D8802, 0x002DC001, > 133696 0x002E0801, 0x002EF805, 0x002F1803, 0x002F2804, 0x002F5C01, > 133697 0x002FCC08, 0x00300403, 0x0030F807, 0x00311803, 0x00312804, > 133698 0x00315402, 0x00318802, 0x0031FC01, 0x00320802, 0x0032F001, > 133699 0x0032F807, 0x00331803, 0x00332804, 0x00335402, 0x00338802, > 133700 0x00340802, 0x0034F807, 0x00351803, 0x00352804, 0x00355C01, > 133701 0x00358802, 0x0035E401, 0x00360802, 0x00372801, 0x00373C06, > 133702 0x00375801, 0x00376008, 0x0037C803, 0x0038C401, 0x0038D007, > 133703 0x0038FC01, 0x00391C09, 0x00396802, 0x003AC401, 0x003AD006, > 133704 0x003AEC02, 0x003B2006, 0x003C041F, 0x003CD00C, 0x003DC417, > 133705 0x003E340B, 0x003E6424, 0x003EF80F, 0x003F380D, 0x0040AC14, > 133706 0x00412806, 0x00415804, 0x00417803, 0x00418803, 0x00419C07, > 133707 0x0041C404, 0x0042080C, 0x00423C01, 0x00426806, 0x0043EC01, > 133708 0x004D740C, 0x004E400A, 0x00500001, 0x0059B402, 0x005A0001, > 133709 0x005A6C02, 0x005BAC03, 0x005C4803, 0x005CC805, 0x005D4802, > 133710 0x005DC802, 0x005ED023, 0x005F6004, 0x005F7401, 0x0060000F, > 133711 0x0062A401, 0x0064800C, 0x0064C00C, 0x00650001, 0x00651002, > 133712 0x0066C011, 0x00672002, 0x00677822, 0x00685C05, 0x00687802, > 133713 0x0069540A, 0x0069801D, 0x0069FC01, 0x006A8007, 0x006AA006, > 133714 0x006C0005, 0x006CD011, 0x006D6823, 0x006E0003, 0x006E840D, > 133715 0x006F980E, 0x006FF004, 0x00709014, 0x0070EC05, 0x0071F802, > 133716 0x00730008, 0x00734019, 0x0073B401, 0x0073C803, 0x00770027, > 133717 0x0077F004, 0x007EF401, 0x007EFC03, 0x007F3403, 0x007F7403, > 133718 0x007FB403, 0x007FF402, 0x00800065, 0x0081A806, 0x0081E805, > 133719 0x00822805, 0x0082801A, 0x00834021, 0x00840002, 0x00840C04, > 133720 0x00842002, 0x00845001, 0x00845803, 0x00847806, 0x00849401, > 133721 0x00849C01, 0x0084A401, 0x0084B801, 0x0084E802, 0x00850005, > 133722 0x00852804, 0x00853C01, 0x00864264, 0x00900027, 0x0091000B, > 133723 0x0092704E, 0x00940200, 0x009C0475, 0x009E53B9, 0x00AD400A, > 133724 0x00B39406, 0x00B3BC03, 0x00B3E404, 0x00B3F802, 0x00B5C001, > 133725 0x00B5FC01, 0x00B7804F, 0x00B8C00C, 0x00BA001A, 0x00BA6C59, > 133726 0x00BC00D6, 0x00BFC00C, 0x00C00005, 0x00C02019, 0x00C0A807, > 133727 0x00C0D802, 0x00C0F403, 0x00C26404, 0x00C28001, 0x00C3EC01, > 133728 0x00C64002, 0x00C6580A, 0x00C70024, 0x00C8001F, 0x00C8A81E, > 133729 0x00C94001, 0x00C98020, 0x00CA2827, 0x00CB003F, 0x00CC0100, > 133730 0x01370040, 0x02924037, 0x0293F802, 0x02983403, 0x0299BC10, > 133731 0x029A7C01, 0x029BC008, 0x029C0017, 0x029C8002, 0x029E2402, > 133732 0x02A00801, 0x02A01801, 0x02A02C01, 0x02A08C09, 0x02A0D804, > 133733 0x02A1D004, 0x02A20002, 0x02A2D011, 0x02A33802, 0x02A38012, > 133734 0x02A3E003, 0x02A4980A, 0x02A51C0D, 0x02A57C01, 0x02A60004, > 133735 0x02A6CC1B, 0x02A77802, 0x02A8A40E, 0x02A90C01, 0x02A93002, > 133736 0x02A97004, 0x02A9DC03, 0x02A9EC01, 0x02AAC001, 0x02AAC803, > 133737 0x02AADC02, 0x02AAF802, 0x02AB0401, 0x02AB7802, 0x02ABAC07, > 133738 0x02ABD402, 0x02AF8C0B, 0x03600001, 0x036DFC02, 0x036FFC02, > 133739 0x037FFC02, 0x03E3FC01, 0x03EC7801, 0x03ECA401, 0x03EEC810, > 133740 0x03F4F802, 0x03F7F002, 0x03F8001A, 0x03F88007, 0x03F8C023, > 133741 0x03F95013, 0x03F9A004, 0x03FBFC01, 0x03FC040F, 0x03FC6807, > 133742 0x03FCEC06, 0x03FD6C0B, 0x03FF8007, 0x03FFA007, 0x03FFE405, > 133743 0x04040003, 0x0404DC09, 0x0405E411, 0x0406400C, 0x0407402E, > 133744 0x040E7C01, 0x040F4001, 0x04215C01, 0x04247C01, 0x0424FC01, > 133745 0x04280403, 0x04281402, 0x04283004, 0x0428E003, 0x0428FC01, > 133746 0x04294009, 0x0429FC01, 0x042CE407, 0x04400003, 0x0440E016, > 133747 0x04420003, 0x0442C012, 0x04440003, 0x04449C0E, 0x04450004, > 133748 0x04460003, 0x0446CC0E, 0x04471404, 0x045AAC0D, 0x0491C004, > 133749 0x05BD442E, 0x05BE3C04, 0x074000F6, 0x07440027, 0x0744A4B5, > 133750 0x07480046, 0x074C0057, 0x075B0401, 0x075B6C01, 0x075BEC01, > 133751 0x075C5401, 0x075CD401, 0x075D3C01, 0x075DBC01, 0x075E2401, > 133752 0x075EA401, 0x075F0C01, 0x07BBC002, 0x07C0002C, 0x07C0C064, > 133753 0x07C2800F, 0x07C2C40E, 0x07C3040F, 0x07C3440F, 0x07C4401F, > 133754 0x07C4C03C, 0x07C5C02B, 0x07C7981D, 0x07C8402B, 0x07C90009, > 133755 0x07C94002, 0x07CC0021, 0x07CCC006, 0x07CCDC46, 0x07CE0014, > 133756 0x07CE8025, 0x07CF1805, 0x07CF8011, 0x07D0003F, 0x07D10001, > 133757 0x07D108B6, 0x07D3E404, 0x07D4003E, 0x07D50004, 0x07D54018, > 133758 0x07D7EC46, 0x07D9140B, 0x07DA0046, 0x07DC0074, 0x38000401, > 133759 0x38008060, 0x380400F0, 0x3C000001, 0x3FFFF401, 0x40000001, > 133760 0x43FFF401, > 133761 }; > 133762 static const unsigned int aAscii[4] = { > 133763 0xFFFFFFFF, 0xFC00FFFF, 0xF8000001, 0xF8000001, > 133764 }; > 133765 > 133766 if( c<128 ){ > 133767 return ( (aAscii[c >> 5] & (1 << (c & 0x001F)))==0 ); > 133768 }else if( c<(1<<22) ){ > 133769 unsigned int key = (((unsigned int)c)<<10) | 0x000003FF; > 133770 int iRes; > 133771 int iHi = sizeof(aEntry)/sizeof(aEntry[0]) - 1; > 133772 int iLo = 0; > 133773 while( iHi>=iLo ){ > 133774 int iTest = (iHi + iLo) / 2; > 133775 if( key >= aEntry[iTest] ){ > 133776 iRes = iTest; > 133777 iLo = iTest+1; > 133778 }else{ > 133779 iHi = iTest-1; > 133780 } > 133781 } > 133782 assert( aEntry[0]<key ); > 133783 assert( key>=aEntry[iRes] ); > 133784 return (c >= ((aEntry[iRes]>>10) + (aEntry[iRes]&0x3FF))); > 133785 } > 133786 return 1; > 133787 } > 133788 > 133789 > 133790 /* > 133791 ** If the argument is a codepoint corresponding to a lowercase letter > 133792 ** in the ASCII range with a diacritic added, return the codepoint > 133793 ** of the ASCII letter only. For example, if passed 235 - "LATIN > 133794 ** SMALL LETTER E WITH DIAERESIS" - return 65 ("LATIN SMALL LETTER > 133795 ** E"). The resuls of passing a codepoint that corresponds to an > 133796 ** uppercase letter are undefined. > 133797 */ > 133798 static int remove_diacritic(int c){ > 133799 unsigned short aDia[] = { > 133800 0, 1797, 1848, 1859, 1891, 1928, 1940, 1995, > 133801 2024, 2040, 2060, 2110, 2168, 2206, 2264, 2286, > 133802 2344, 2383, 2472, 2488, 2516, 2596, 2668, 2732, > 133803 2782, 2842, 2894, 2954, 2984, 3000, 3028, 3336, > 133804 3456, 3696, 3712, 3728, 3744, 3896, 3912, 3928, > 133805 3968, 4008, 4040, 4106, 4138, 4170, 4202, 4234, > 133806 4266, 4296, 4312, 4344, 4408, 4424, 4472, 4504, > 133807 6148, 6198, 6264, 6280, 6360, 6429, 6505, 6529, > 133808 61448, 61468, 61534, 61592, 61642, 61688, 61704, 61726, > 133809 61784, 61800, 61836, 61880, 61914, 61948, 61998, 62122, > 133810 62154, 62200, 62218, 62302, 62364, 62442, 62478, 62536, > 133811 62554, 62584, 62604, 62640, 62648, 62656, 62664, 62730, > 133812 62924, 63050, 63082, 63274, 63390, > 133813 }; > 133814 char aChar[] = { > 133815 '\0', 'a', 'c', 'e', 'i', 'n', 'o', 'u', 'y', 'y', 'a', 'c', > 133816 'd', 'e', 'e', 'g', 'h', 'i', 'j', 'k', 'l', 'n', 'o', 'r', > 133817 's', 't', 'u', 'u', 'w', 'y', 'z', 'o', 'u', 'a', 'i', 'o', > 133818 'u', 'g', 'k', 'o', 'j', 'g', 'n', 'a', 'e', 'i', 'o', 'r', > 133819 'u', 's', 't', 'h', 'a', 'e', 'o', 'y', '\0', '\0', '\0', '\0', > 133820 '\0', '\0', '\0', '\0', 'a', 'b', 'd', 'd', 'e', 'f', 'g', 'h', > 133821 'h', 'i', 'k', 'l', 'l', 'm', 'n', 'p', 'r', 'r', 's', 't', > 133822 'u', 'v', 'w', 'w', 'x', 'y', 'z', 'h', 't', 'w', 'y', 'a', > 133823 'e', 'i', 'o', 'u', 'y', > 133824 }; > 133825 > 133826 unsigned int key = (((unsigned int)c)<<3) | 0x00000007; > 133827 int iRes = 0; > 133828 int iHi = sizeof(aDia)/sizeof(aDia[0]) - 1; > 133829 int iLo = 0; > 133830 while( iHi>=iLo ){ > 133831 int iTest = (iHi + iLo) / 2; > 133832 if( key >= aDia[iTest] ){ > 133833 iRes = iTest; > 133834 iLo = iTest+1; > 133835 }else{ > 133836 iHi = iTest-1; > 133837 } > 133838 } > 133839 assert( key>=aDia[iRes] ); > 133840 return ((c > (aDia[iRes]>>3) + (aDia[iRes]&0x07)) ? c : (int)aChar[iRes]); > 133841 }; > 133842 > 133843 > 133844 /* > 133845 ** Return true if the argument interpreted as a unicode codepoint > 133846 ** is a diacritical modifier character. > 133847 */ > 133848 SQLITE_PRIVATE int sqlite3FtsUnicodeIsdiacritic(int c){ > 133849 unsigned int mask0 = 0x08029FDF; > 133850 unsigned int mask1 = 0x000361F8; > 133851 if( c<768 || c>817 ) return 0; > 133852 return (c < 768+32) ? > 133853 (mask0 & (1 << (c-768))) : > 133854 (mask1 & (1 << (c-768-32))); > 133855 } > 133856 > 133857 > 133858 /* > 133859 ** Interpret the argument as a unicode codepoint. If the codepoint > 133860 ** is an upper case character that has a lower case equivalent, > 133861 ** return the codepoint corresponding to the lower case version. > 133862 ** Otherwise, return a copy of the argument. > 133863 ** > 133864 ** The results are undefined if the value passed to this function > 133865 ** is less than zero. > 133866 */ > 133867 SQLITE_PRIVATE int sqlite3FtsUnicodeFold(int c, int bRemoveDiacritic){ > 133868 /* Each entry in the following array defines a rule for folding a range > 133869 ** of codepoints to lower case. The rule applies to a range of nRange > 133870 ** codepoints starting at codepoint iCode. > 133871 ** > 133872 ** If the least significant bit in flags is clear, then the rule applies > 133873 ** to all nRange codepoints (i.e. all nRange codepoints are upper case and > 133874 ** need to be folded). Or, if it is set, then the rule only applies to > 133875 ** every second codepoint in the range, starting with codepoint C. > 133876 ** > 133877 ** The 7 most significant bits in flags are an index into the aiOff[] > 133878 ** array. If a specific codepoint C does require folding, then its lower > 133879 ** case equivalent is ((C + aiOff[flags>>1]) & 0xFFFF). > 133880 ** > 133881 ** The contents of this array are generated by parsing the CaseFolding.txt > 133882 ** file distributed as part of the "Unicode Character Database". See > 133883 ** http://www.unicode.org for details. > 133884 */ > 133885 static const struct TableEntry { > 133886 unsigned short iCode; > 133887 unsigned char flags; > 133888 unsigned char nRange; > 133889 } aEntry[] = { > 133890 {65, 14, 26}, {181, 64, 1}, {192, 14, 23}, > 133891 {216, 14, 7}, {256, 1, 48}, {306, 1, 6}, > 133892 {313, 1, 16}, {330, 1, 46}, {376, 116, 1}, > 133893 {377, 1, 6}, {383, 104, 1}, {385, 50, 1}, > 133894 {386, 1, 4}, {390, 44, 1}, {391, 0, 1}, > 133895 {393, 42, 2}, {395, 0, 1}, {398, 32, 1}, > 133896 {399, 38, 1}, {400, 40, 1}, {401, 0, 1}, > 133897 {403, 42, 1}, {404, 46, 1}, {406, 52, 1}, > 133898 {407, 48, 1}, {408, 0, 1}, {412, 52, 1}, > 133899 {413, 54, 1}, {415, 56, 1}, {416, 1, 6}, > 133900 {422, 60, 1}, {423, 0, 1}, {425, 60, 1}, > 133901 {428, 0, 1}, {430, 60, 1}, {431, 0, 1}, > 133902 {433, 58, 2}, {435, 1, 4}, {439, 62, 1}, > 133903 {440, 0, 1}, {444, 0, 1}, {452, 2, 1}, > 133904 {453, 0, 1}, {455, 2, 1}, {456, 0, 1}, > 133905 {458, 2, 1}, {459, 1, 18}, {478, 1, 18}, > 133906 {497, 2, 1}, {498, 1, 4}, {502, 122, 1}, > 133907 {503, 134, 1}, {504, 1, 40}, {544, 110, 1}, > 133908 {546, 1, 18}, {570, 70, 1}, {571, 0, 1}, > 133909 {573, 108, 1}, {574, 68, 1}, {577, 0, 1}, > 133910 {579, 106, 1}, {580, 28, 1}, {581, 30, 1}, > 133911 {582, 1, 10}, {837, 36, 1}, {880, 1, 4}, > 133912 {886, 0, 1}, {902, 18, 1}, {904, 16, 3}, > 133913 {908, 26, 1}, {910, 24, 2}, {913, 14, 17}, > 133914 {931, 14, 9}, {962, 0, 1}, {975, 4, 1}, > 133915 {976, 140, 1}, {977, 142, 1}, {981, 146, 1}, > 133916 {982, 144, 1}, {984, 1, 24}, {1008, 136, 1}, > 133917 {1009, 138, 1}, {1012, 130, 1}, {1013, 128, 1}, > 133918 {1015, 0, 1}, {1017, 152, 1}, {1018, 0, 1}, > 133919 {1021, 110, 3}, {1024, 34, 16}, {1040, 14, 32}, > 133920 {1120, 1, 34}, {1162, 1, 54}, {1216, 6, 1}, > 133921 {1217, 1, 14}, {1232, 1, 88}, {1329, 22, 38}, > 133922 {4256, 66, 38}, {4295, 66, 1}, {4301, 66, 1}, > 133923 {7680, 1, 150}, {7835, 132, 1}, {7838, 96, 1}, > 133924 {7840, 1, 96}, {7944, 150, 8}, {7960, 150, 6}, > 133925 {7976, 150, 8}, {7992, 150, 8}, {8008, 150, 6}, > 133926 {8025, 151, 8}, {8040, 150, 8}, {8072, 150, 8}, > 133927 {8088, 150, 8}, {8104, 150, 8}, {8120, 150, 2}, > 133928 {8122, 126, 2}, {8124, 148, 1}, {8126, 100, 1}, > 133929 {8136, 124, 4}, {8140, 148, 1}, {8152, 150, 2}, > 133930 {8154, 120, 2}, {8168, 150, 2}, {8170, 118, 2}, > 133931 {8172, 152, 1}, {8184, 112, 2}, {8186, 114, 2}, > 133932 {8188, 148, 1}, {8486, 98, 1}, {8490, 92, 1}, > 133933 {8491, 94, 1}, {8498, 12, 1}, {8544, 8, 16}, > 133934 {8579, 0, 1}, {9398, 10, 26}, {11264, 22, 47}, > 133935 {11360, 0, 1}, {11362, 88, 1}, {11363, 102, 1}, > 133936 {11364, 90, 1}, {11367, 1, 6}, {11373, 84, 1}, > 133937 {11374, 86, 1}, {11375, 80, 1}, {11376, 82, 1}, > 133938 {11378, 0, 1}, {11381, 0, 1}, {11390, 78, 2}, > 133939 {11392, 1, 100}, {11499, 1, 4}, {11506, 0, 1}, > 133940 {42560, 1, 46}, {42624, 1, 24}, {42786, 1, 14}, > 133941 {42802, 1, 62}, {42873, 1, 4}, {42877, 76, 1}, > 133942 {42878, 1, 10}, {42891, 0, 1}, {42893, 74, 1}, > 133943 {42896, 1, 4}, {42912, 1, 10}, {42922, 72, 1}, > 133944 {65313, 14, 26}, > 133945 }; > 133946 static const unsigned short aiOff[] = { > 133947 1, 2, 8, 15, 16, 26, 28, 32, > 133948 37, 38, 40, 48, 63, 64, 69, 71, > 133949 79, 80, 116, 202, 203, 205, 206, 207, > 133950 209, 210, 211, 213, 214, 217, 218, 219, > 133951 775, 7264, 10792, 10795, 23228, 23256, 30204, 54721, > 133952 54753, 54754, 54756, 54787, 54793, 54809, 57153, 57274, > 133953 57921, 58019, 58363, 61722, 65268, 65341, 65373, 65406, > 133954 65408, 65410, 65415, 65424, 65436, 65439, 65450, 65462, > 133955 65472, 65476, 65478, 65480, 65482, 65488, 65506, 65511, > 133956 65514, 65521, 65527, 65528, 65529, > 133957 }; > 133958 > 133959 int ret = c; > 133960 > 133961 assert( c>=0 ); > 133962 assert( sizeof(unsigned short)==2 && sizeof(unsigned char)==1 ); > 133963 > 133964 if( c<128 ){ > 133965 if( c>='A' && c<='Z' ) ret = c + ('a' - 'A'); > 133966 }else if( c<65536 ){ > 133967 int iHi = sizeof(aEntry)/sizeof(aEntry[0]) - 1; > 133968 int iLo = 0; > 133969 int iRes = -1; > 133970 > 133971 while( iHi>=iLo ){ > 133972 int iTest = (iHi + iLo) / 2; > 133973 int cmp = (c - aEntry[iTest].iCode); > 133974 if( cmp>=0 ){ > 133975 iRes = iTest; > 133976 iLo = iTest+1; > 133977 }else{ > 133978 iHi = iTest-1; > 133979 } > 133980 } > 133981 assert( iRes<0 || c>=aEntry[iRes].iCode ); > 133982 > 133983 if( iRes>=0 ){ > 133984 const struct TableEntry *p = &aEntry[iRes]; > 133985 if( c<(p->iCode + p->nRange) && 0==(0x01 & p->flags & (p->iCode ^ c)) ){ > 133986 ret = (c + (aiOff[p->flags>>1])) & 0x0000FFFF; > 133987 assert( ret>0 ); > 133988 } > 133989 } > 133990 > 133991 if( bRemoveDiacritic ) ret = remove_diacritic(ret); > 133992 } > 133993 > 133994 else if( c>=66560 && c<66600 ){ > 133995 ret = c + 40; > 133996 } > 133997 > 133998 return ret; > 133999 } > 134000 #endif /* defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4) */ > 134001 #endif /* !defined(SQLITE_ENABLE_FTS4_UNICODE61) */ > 134002 > 134003 /************** End of fts3_unicode2.c ***************************************/ 132567 /************** Begin file rtree.c *******************************************/ 134004 /************** Begin file rtree.c *******************************************/ 132568 /* 134005 /* 132569 ** 2001 September 15 134006 ** 2001 September 15 132570 ** 134007 ** 132571 ** The author disclaims copyright to this source code. In place of 134008 ** The author disclaims copyright to this source code. In place of 132572 ** a legal notice, here is a blessing: 134009 ** a legal notice, here is a blessing: 132573 ** 134010 ** ................................................................................................................................................................................ 135299 rc = nodeRelease(pRtree, pRoot); 136736 rc = nodeRelease(pRtree, pRoot); 135300 }else{ 136737 }else{ 135301 nodeRelease(pRtree, pRoot); 136738 nodeRelease(pRtree, pRoot); 135302 } 136739 } 135303 136740 135304 return rc; 136741 return rc; 135305 } 136742 } > 136743 > 136744 /* > 136745 ** Rounding constants for float->double conversion. > 136746 */ > 136747 #define RNDTOWARDS (1.0 - 1.0/8388608.0) /* Round towards zero */ > 136748 #define RNDAWAY (1.0 + 1.0/8388608.0) /* Round away from zero */ > 136749 > 136750 #if !defined(SQLITE_RTREE_INT_ONLY) > 136751 /* > 136752 ** Convert an sqlite3_value into an RtreeValue (presumably a float) > 136753 ** while taking care to round toward negative or positive, respectively. > 136754 */ > 136755 static RtreeValue rtreeValueDown(sqlite3_value *v){ > 136756 double d = sqlite3_value_double(v); > 136757 float f = (float)d; > 136758 if( f>d ){ > 136759 f = (float)(d*(d<0 ? RNDAWAY : RNDTOWARDS)); > 136760 } > 136761 return f; > 136762 } > 136763 static RtreeValue rtreeValueUp(sqlite3_value *v){ > 136764 double d = sqlite3_value_double(v); > 136765 float f = (float)d; > 136766 if( f<d ){ > 136767 f = (float)(d*(d<0 ? RNDTOWARDS : RNDAWAY)); > 136768 } > 136769 return f; > 136770 } > 136771 #endif /* !defined(SQLITE_RTREE_INT_ONLY) */ > 136772 135306 136773 135307 /* 136774 /* 135308 ** The xUpdate method for rtree module virtual tables. 136775 ** The xUpdate method for rtree module virtual tables. 135309 */ 136776 */ 135310 static int rtreeUpdate( 136777 static int rtreeUpdate( 135311 sqlite3_vtab *pVtab, 136778 sqlite3_vtab *pVtab, 135312 int nData, 136779 int nData, ................................................................................................................................................................................ 135336 int ii; 136803 int ii; 135337 136804 135338 /* Populate the cell.aCoord[] array. The first coordinate is azData[3]. */ 136805 /* Populate the cell.aCoord[] array. The first coordinate is azData[3]. */ 135339 assert( nData==(pRtree->nDim*2 + 3) ); 136806 assert( nData==(pRtree->nDim*2 + 3) ); 135340 #ifndef SQLITE_RTREE_INT_ONLY 136807 #ifndef SQLITE_RTREE_INT_ONLY 135341 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){ 136808 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){ 135342 for(ii=0; ii<(pRtree->nDim*2); ii+=2){ 136809 for(ii=0; ii<(pRtree->nDim*2); ii+=2){ 135343 cell.aCoord[ii].f = (RtreeValue)sqlite3_value_double(azData[ii+3]); | 136810 cell.aCoord[ii].f = rtreeValueDown(azData[ii+3]); 135344 cell.aCoord[ii+1].f = (RtreeValue)sqlite3_value_double(azData[ii+4]); | 136811 cell.aCoord[ii+1].f = rtreeValueUp(azData[ii+4]); 135345 if( cell.aCoord[ii].f>cell.aCoord[ii+1].f ){ 136812 if( cell.aCoord[ii].f>cell.aCoord[ii+1].f ){ 135346 rc = SQLITE_CONSTRAINT; 136813 rc = SQLITE_CONSTRAINT; 135347 goto constraint; 136814 goto constraint; 135348 } 136815 } 135349 } 136816 } 135350 }else 136817 }else 135351 #endif 136818 #endif

Changes to src/sqlite3.h

103 ** string contains the date and time of the check-in (UTC) and an SHA1 103 ** string contains the date and time of the check-in (UTC) and an SHA1 104 ** hash of the entire source tree. 104 ** hash of the entire source tree. 105 ** 105 ** 106 ** See also: [sqlite3_libversion()], 106 ** See also: [sqlite3_libversion()], 107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()], 107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()], 108 ** [sqlite_version()] and [sqlite_source_id()]. 108 ** [sqlite_version()] and [sqlite_source_id()]. 109 */ 109 */ 110 #define SQLITE_VERSION "3.7.12" | 110 #define SQLITE_VERSION "3.7.13" 111 #define SQLITE_VERSION_NUMBER 3007012 | 111 #define SQLITE_VERSION_NUMBER 3007013 112 #define SQLITE_SOURCE_ID "2012-05-12 18:29:53 e536ac041815b118c461ceee798f9 | 112 #define SQLITE_SOURCE_ID "2012-06-07 07:24:04 506008f000ba4af0b35da023b8c52 113 113 114 /* 114 /* 115 ** CAPI3REF: Run-Time Library Version Numbers 115 ** CAPI3REF: Run-Time Library Version Numbers 116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid 116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid 117 ** 117 ** 118 ** These interfaces provide the same information as the [SQLITE_VERSION], 118 ** These interfaces provide the same information as the [SQLITE_VERSION], 119 ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros 119 ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros ................................................................................................................................................................................ 474 #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */ 474 #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */ 475 #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */ 475 #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */ 476 #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */ 476 #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */ 477 #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */ 477 #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */ 478 #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */ 478 #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */ 479 #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */ 479 #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */ 480 #define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */ 480 #define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */ > 481 #define SQLITE_OPEN_MEMORY 0x00000080 /* Ok for sqlite3_open_v2() */ 481 #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */ 482 #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */ 482 #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */ 483 #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */ 483 #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */ 484 #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */ 484 #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */ 485 #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */ 485 #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */ 486 #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */ 486 #define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */ 487 #define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */ 487 #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */ 488 #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */ ................................................................................................................................................................................ 768 ** integer is the delay. If either integer is negative, then the setting 769 ** integer is the delay. If either integer is negative, then the setting 769 ** is not changed but instead the prior value of that setting is written 770 ** is not changed but instead the prior value of that setting is written 770 ** into the array entry, allowing the current retry settings to be 771 ** into the array entry, allowing the current retry settings to be 771 ** interrogated. The zDbName parameter is ignored. 772 ** interrogated. The zDbName parameter is ignored. 772 ** 773 ** 773 ** <li>[[SQLITE_FCNTL_PERSIST_WAL]] 774 ** <li>[[SQLITE_FCNTL_PERSIST_WAL]] 774 ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the 775 ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the 775 ** persistent [WAL | Write AHead Log] setting. By default, the auxiliary | 776 ** persistent [WAL | Write Ahead Log] setting. By default, the auxiliary 776 ** write ahead log and shared memory files used for transaction control 777 ** write ahead log and shared memory files used for transaction control 777 ** are automatically deleted when the latest connection to the database 778 ** are automatically deleted when the latest connection to the database 778 ** closes. Setting persistent WAL mode causes those files to persist after 779 ** closes. Setting persistent WAL mode causes those files to persist after 779 ** close. Persisting the files is useful when other processes that do not 780 ** close. Persisting the files is useful when other processes that do not 780 ** have write permission on the directory containing the database file want 781 ** have write permission on the directory containing the database file want 781 ** to read the database file, as the WAL and shared memory files must exist 782 ** to read the database file, as the WAL and shared memory files must exist 782 ** in order for the database to be readable. The fourth parameter to 783 ** in order for the database to be readable. The fourth parameter to ................................................................................................................................................................................ 2165 ** option is used. 2166 ** option is used. 2166 ** 2167 ** 2167 ** In SQLite version 3.5.0 and 3.5.1, it was possible to define 2168 ** In SQLite version 3.5.0 and 3.5.1, it was possible to define 2168 ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in 2169 ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in 2169 ** implementation of these routines to be omitted. That capability 2170 ** implementation of these routines to be omitted. That capability 2170 ** is no longer provided. Only built-in memory allocators can be used. 2171 ** is no longer provided. Only built-in memory allocators can be used. 2171 ** 2172 ** 2172 ** The Windows OS interface layer calls | 2173 ** Prior to SQLite version 3.7.10, the Windows OS interface layer called 2173 ** the system malloc() and free() directly when converting 2174 ** the system malloc() and free() directly when converting 2174 ** filenames between the UTF-8 encoding used by SQLite 2175 ** filenames between the UTF-8 encoding used by SQLite 2175 ** and whatever filename encoding is used by the particular Windows 2176 ** and whatever filename encoding is used by the particular Windows 2176 ** installation. Memory allocation errors are detected, but | 2177 ** installation. Memory allocation errors were detected, but 2177 ** they are reported back as [SQLITE_CANTOPEN] or | 2178 ** they were reported back as [SQLITE_CANTOPEN] or 2178 ** [SQLITE_IOERR] rather than [SQLITE_NOMEM]. 2179 ** [SQLITE_IOERR] rather than [SQLITE_NOMEM]. 2179 ** 2180 ** 2180 ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()] 2181 ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()] 2181 ** must be either NULL or else pointers obtained from a prior 2182 ** must be either NULL or else pointers obtained from a prior 2182 ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have 2183 ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have 2183 ** not yet been released. 2184 ** not yet been released. 2184 ** 2185 ** ................................................................................................................................................................................ 2571 ** a VFS object that provides the operating system interface that should 2572 ** a VFS object that provides the operating system interface that should 2572 ** be used to access the database file on disk. ^If this option is set to 2573 ** be used to access the database file on disk. ^If this option is set to 2573 ** an empty string the default VFS object is used. ^Specifying an unknown 2574 ** an empty string the default VFS object is used. ^Specifying an unknown 2574 ** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is 2575 ** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is 2575 ** present, then the VFS specified by the option takes precedence over 2576 ** present, then the VFS specified by the option takes precedence over 2576 ** the value passed as the fourth parameter to sqlite3_open_v2(). 2577 ** the value passed as the fourth parameter to sqlite3_open_v2(). 2577 ** 2578 ** 2578 ** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw" or | 2579 ** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw", 2579 ** "rwc". Attempting to set it to any other value is an error)^. | 2580 ** "rwc", or "memory". Attempting to set it to any other value is > 2581 ** an error)^. 2580 ** ^If "ro" is specified, then the database is opened for read-only 2582 ** ^If "ro" is specified, then the database is opened for read-only 2581 ** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the 2583 ** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the 2582 ** third argument to sqlite3_prepare_v2(). ^If the mode option is set to 2584 ** third argument to sqlite3_prepare_v2(). ^If the mode option is set to 2583 ** "rw", then the database is opened for read-write (but not create) 2585 ** "rw", then the database is opened for read-write (but not create) 2584 ** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had 2586 ** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had 2585 ** been set. ^Value "rwc" is equivalent to setting both 2587 ** been set. ^Value "rwc" is equivalent to setting both 2586 ** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If sqlite3_open_v2() is | 2588 ** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If the mode option is > 2589 ** set to "memory" then a pure [in-memory database] that never reads 2587 ** used, it is an error to specify a value for the mode parameter that is | 2590 ** or writes from disk is used. ^It is an error to specify a value for 2588 ** less restrictive than that specified by the flags passed as the third | 2591 ** the mode parameter that is less restrictive than that specified by 2589 ** parameter. < > 2592 ** the flags passed in the third parameter to sqlite3_open_v2(). 2590 ** 2593 ** 2591 ** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or 2594 ** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or 2592 ** "private". ^Setting it to "shared" is equivalent to setting the 2595 ** "private". ^Setting it to "shared" is equivalent to setting the 2593 ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to 2596 ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to 2594 ** sqlite3_open_v2(). ^Setting the cache parameter to "private" is 2597 ** sqlite3_open_v2(). ^Setting the cache parameter to "private" is 2595 ** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit. 2598 ** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit. 2596 ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in 2599 ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in ................................................................................................................................................................................ 4445 ** using [sqlite3_free]. 4448 ** using [sqlite3_free]. 4446 ** Hence, if this variable is modified directly, either it should be 4449 ** Hence, if this variable is modified directly, either it should be 4447 ** made NULL or made to point to memory obtained from [sqlite3_malloc] 4450 ** made NULL or made to point to memory obtained from [sqlite3_malloc] 4448 ** or else the use of the [temp_store_directory pragma] should be avoided. 4451 ** or else the use of the [temp_store_directory pragma] should be avoided. 4449 */ 4452 */ 4450 SQLITE_API SQLITE_EXTERN char *sqlite3_temp_directory; 4453 SQLITE_API SQLITE_EXTERN char *sqlite3_temp_directory; 4451 4454 > 4455 /* > 4456 ** CAPI3REF: Name Of The Folder Holding Database Files > 4457 ** > 4458 ** ^(If this global variable is made to point to a string which is > 4459 ** the name of a folder (a.k.a. directory), then all database files > 4460 ** specified with a relative pathname and created or accessed by > 4461 ** SQLite when using a built-in [sqlite3_vfs | VFS] will be assumed > 4462 ** to be relative to that directory.)^ ^If this variable is a NULL > 4463 ** pointer, then SQLite assumes that all database files specified > 4464 ** with a relative pathname are relative to the current directory > 4465 ** for the process. > 4466 ** > 4467 ** Changing the value of this variable while a database connection is > 4468 ** open can result in a corrupt database. > 4469 ** > 4470 ** It is not safe to read or modify this variable in more than one > 4471 ** thread at a time. It is not safe to read or modify this variable > 4472 ** if a [database connection] is being used at the same time in a separate > 4473 ** thread. > 4474 ** It is intended that this variable be set once > 4475 ** as part of process initialization and before any SQLite interface > 4476 ** routines have been called and that this variable remain unchanged > 4477 ** thereafter. > 4478 ** > 4479 ** ^The [data_store_directory pragma] may modify this variable and cause > 4480 ** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore, > 4481 ** the [data_store_directory pragma] always assumes that any string > 4482 ** that this variable points to is held in memory obtained from > 4483 ** [sqlite3_malloc] and the pragma may attempt to free that memory > 4484 ** using [sqlite3_free]. > 4485 ** Hence, if this variable is modified directly, either it should be > 4486 ** made NULL or made to point to memory obtained from [sqlite3_malloc] > 4487 ** or else the use of the [data_store_directory pragma] should be avoided. > 4488 */ > 4489 SQLITE_API SQLITE_EXTERN char *sqlite3_data_directory; > 4490 4452 /* 4491 /* 4453 ** CAPI3REF: Test For Auto-Commit Mode 4492 ** CAPI3REF: Test For Auto-Commit Mode 4454 ** KEYWORDS: {autocommit mode} 4493 ** KEYWORDS: {autocommit mode} 4455 ** 4494 ** 4456 ** ^The sqlite3_get_autocommit() interface returns non-zero or 4495 ** ^The sqlite3_get_autocommit() interface returns non-zero or 4457 ** zero if the given database connection is or is not in autocommit mode, 4496 ** zero if the given database connection is or is not in autocommit mode, 4458 ** respectively. ^Autocommit mode is on by default. 4497 ** respectively. ^Autocommit mode is on by default. ................................................................................................................................................................................ 4623 sqlite3*, 4662 sqlite3*, 4624 void(*)(void *,int ,char const *,char const *,sqlite3_int64), 4663 void(*)(void *,int ,char const *,char const *,sqlite3_int64), 4625 void* 4664 void* 4626 ); 4665 ); 4627 4666 4628 /* 4667 /* 4629 ** CAPI3REF: Enable Or Disable Shared Pager Cache 4668 ** CAPI3REF: Enable Or Disable Shared Pager Cache 4630 ** KEYWORDS: {shared cache} < 4631 ** 4669 ** 4632 ** ^(This routine enables or disables the sharing of the database cache 4670 ** ^(This routine enables or disables the sharing of the database cache 4633 ** and schema data structures between [database connection | connections] 4671 ** and schema data structures between [database connection | connections] 4634 ** to the same database. Sharing is enabled if the argument is true 4672 ** to the same database. Sharing is enabled if the argument is true 4635 ** and disabled if the argument is false.)^ 4673 ** and disabled if the argument is false.)^ 4636 ** 4674 ** 4637 ** ^Cache sharing is enabled and disabled for an entire process. 4675 ** ^Cache sharing is enabled and disabled for an entire process.