Fossil SCM

Update the built-in SQLite to the first 3.7.13 beta.

drh 2012-06-07 13:30 trunk
Commit 990c4d443775196da41d857c9d43d51eaf0fc387
3 files changed +8 -6 +1934 -467 +52 -14
+8 -6
--- src/shell.c
+++ src/shell.c
@@ -2182,27 +2182,29 @@
21822182
rc = SQLITE_OK;
21832183
}else{
21842184
zShellStatic = azArg[1];
21852185
rc = sqlite3_exec(p->db,
21862186
"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"
21882188
" 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) "
21902190
"WHERE lower(tbl_name) LIKE shellstatic()"
21912191
" 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",
21932194
callback, &data, &zErrMsg);
21942195
zShellStatic = 0;
21952196
}
21962197
}else{
21972198
rc = sqlite3_exec(p->db,
21982199
"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"
22002201
" 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) "
22022203
"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",
22042206
callback, &data, &zErrMsg
22052207
);
22062208
}
22072209
if( zErrMsg ){
22082210
fprintf(stderr,"Error: %s\n", zErrMsg);
22092211
--- src/shell.c
+++ src/shell.c
@@ -2182,27 +2182,29 @@
2182 rc = SQLITE_OK;
2183 }else{
2184 zShellStatic = azArg[1];
2185 rc = sqlite3_exec(p->db,
2186 "SELECT sql FROM "
2187 " (SELECT sql sql, type type, tbl_name tbl_name, name name"
2188 " FROM sqlite_master UNION ALL"
2189 " SELECT sql, type, tbl_name, name FROM sqlite_temp_master) "
2190 "WHERE lower(tbl_name) LIKE shellstatic()"
2191 " AND type!='meta' AND sql NOTNULL "
2192 "ORDER BY substr(type,2,1), name",
 
2193 callback, &data, &zErrMsg);
2194 zShellStatic = 0;
2195 }
2196 }else{
2197 rc = sqlite3_exec(p->db,
2198 "SELECT sql FROM "
2199 " (SELECT sql sql, type type, tbl_name tbl_name, name name"
2200 " FROM sqlite_master UNION ALL"
2201 " SELECT sql, type, tbl_name, name FROM sqlite_temp_master) "
2202 "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%'"
2203 "ORDER BY substr(type,2,1), name",
 
2204 callback, &data, &zErrMsg
2205 );
2206 }
2207 if( zErrMsg ){
2208 fprintf(stderr,"Error: %s\n", zErrMsg);
2209
--- src/shell.c
+++ src/shell.c
@@ -2182,27 +2182,29 @@
2182 rc = SQLITE_OK;
2183 }else{
2184 zShellStatic = azArg[1];
2185 rc = sqlite3_exec(p->db,
2186 "SELECT sql FROM "
2187 " (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
2188 " FROM sqlite_master UNION ALL"
2189 " SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_master) "
2190 "WHERE lower(tbl_name) LIKE shellstatic()"
2191 " AND type!='meta' AND sql NOTNULL "
2192 "ORDER BY substr(type,2,1), "
2193 " CASE type WHEN 'view' THEN rowid ELSE name END",
2194 callback, &data, &zErrMsg);
2195 zShellStatic = 0;
2196 }
2197 }else{
2198 rc = sqlite3_exec(p->db,
2199 "SELECT sql FROM "
2200 " (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
2201 " FROM sqlite_master UNION ALL"
2202 " SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_master) "
2203 "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%'"
2204 "ORDER BY substr(type,2,1),"
2205 " CASE type WHEN 'view' THEN rowid ELSE name END",
2206 callback, &data, &zErrMsg
2207 );
2208 }
2209 if( zErrMsg ){
2210 fprintf(stderr,"Error: %s\n", zErrMsg);
2211
+1934 -467
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** 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
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -441,18 +441,25 @@
441441
#if defined(SQLITE_TCL) || defined(TCLSH)
442442
# include <tcl.h>
443443
#endif
444444
445445
/*
446
-** Many people are failing to set -DNDEBUG=1 when compiling SQLite.
447
-** Setting NDEBUG makes the code smaller and run faster. So the following
448
-** lines are added to automatically set NDEBUG unless the -DSQLITE_DEBUG=1
449
-** option is set. Thus NDEBUG becomes an opt-in rather than an opt-out
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
+**
450
+** Setting NDEBUG makes the code smaller and run faster by disabling the
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
453
+** is set. Thus NDEBUG becomes an opt-in rather than an opt-out
450454
** feature.
451455
*/
452456
#if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
453457
# define NDEBUG 1
458
+#endif
459
+#if defined(NDEBUG) && defined(SQLITE_DEBUG)
460
+# undef NDEBUG
454461
#endif
455462
456463
/*
457464
** The testcase() macro is used to aid in coverage testing. When
458465
** doing coverage testing, the condition inside the argument to
@@ -655,13 +662,13 @@
655662
**
656663
** See also: [sqlite3_libversion()],
657664
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
658665
** [sqlite_version()] and [sqlite_source_id()].
659666
*/
660
-#define SQLITE_VERSION "3.7.12"
661
-#define SQLITE_VERSION_NUMBER 3007012
662
-#define SQLITE_SOURCE_ID "2012-05-12 18:29:53 e536ac041815b118c461ceee798f9b7283269f58"
667
+#define SQLITE_VERSION "3.7.13"
668
+#define SQLITE_VERSION_NUMBER 3007013
669
+#define SQLITE_SOURCE_ID "2012-06-07 07:24:04 506008f000ba4af0b35da023b8c52f7a3f5033bd"
663670
664671
/*
665672
** CAPI3REF: Run-Time Library Version Numbers
666673
** KEYWORDS: sqlite3_version, sqlite3_sourceid
667674
**
@@ -1026,10 +1033,11 @@
10261033
#define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
10271034
#define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
10281035
#define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */
10291036
#define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */
10301037
#define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */
1038
+#define SQLITE_OPEN_MEMORY 0x00000080 /* Ok for sqlite3_open_v2() */
10311039
#define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */
10321040
#define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */
10331041
#define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */
10341042
#define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */
10351043
#define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */
@@ -1320,11 +1328,11 @@
13201328
** into the array entry, allowing the current retry settings to be
13211329
** interrogated. The zDbName parameter is ignored.
13221330
**
13231331
** <li>[[SQLITE_FCNTL_PERSIST_WAL]]
13241332
** ^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
13261334
** write ahead log and shared memory files used for transaction control
13271335
** are automatically deleted when the latest connection to the database
13281336
** closes. Setting persistent WAL mode causes those files to persist after
13291337
** close. Persisting the files is useful when other processes that do not
13301338
** have write permission on the directory containing the database file want
@@ -2717,16 +2725,16 @@
27172725
** In SQLite version 3.5.0 and 3.5.1, it was possible to define
27182726
** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
27192727
** implementation of these routines to be omitted. That capability
27202728
** is no longer provided. Only built-in memory allocators can be used.
27212729
**
2722
-** The Windows OS interface layer calls
2730
+** Prior to SQLite version 3.7.10, the Windows OS interface layer called
27232731
** the system malloc() and free() directly when converting
27242732
** filenames between the UTF-8 encoding used by SQLite
27252733
** and whatever filename encoding is used by the particular Windows
2726
-** installation. Memory allocation errors are detected, but
2727
-** they are reported back as [SQLITE_CANTOPEN] or
2734
+** installation. Memory allocation errors were detected, but
2735
+** they were reported back as [SQLITE_CANTOPEN] or
27282736
** [SQLITE_IOERR] rather than [SQLITE_NOMEM].
27292737
**
27302738
** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
27312739
** must be either NULL or else pointers obtained from a prior
27322740
** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
@@ -3123,22 +3131,24 @@
31233131
** an empty string the default VFS object is used. ^Specifying an unknown
31243132
** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is
31253133
** present, then the VFS specified by the option takes precedence over
31263134
** the value passed as the fourth parameter to sqlite3_open_v2().
31273135
**
3128
-** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw" or
3129
-** "rwc". Attempting to set it to any other value is an error)^.
3136
+** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw",
3137
+** "rwc", or "memory". Attempting to set it to any other value is
3138
+** an error)^.
31303139
** ^If "ro" is specified, then the database is opened for read-only
31313140
** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the
31323141
** third argument to sqlite3_prepare_v2(). ^If the mode option is set to
31333142
** "rw", then the database is opened for read-write (but not create)
31343143
** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had
31353144
** been set. ^Value "rwc" is equivalent to setting both
3136
-** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If sqlite3_open_v2() is
3137
-** used, it is an error to specify a value for the mode parameter that is
3138
-** less restrictive than that specified by the flags passed as the third
3139
-** parameter.
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
3147
+** or writes from disk is used. ^It is an error to specify a value for
3148
+** the mode parameter that is less restrictive than that specified by
3149
+** the flags passed in the third parameter to sqlite3_open_v2().
31403150
**
31413151
** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or
31423152
** "private". ^Setting it to "shared" is equivalent to setting the
31433153
** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
31443154
** sqlite3_open_v2(). ^Setting the cache parameter to "private" is
@@ -4997,10 +5007,46 @@
49975007
** made NULL or made to point to memory obtained from [sqlite3_malloc]
49985008
** or else the use of the [temp_store_directory pragma] should be avoided.
49995009
*/
50005010
SQLITE_API char *sqlite3_temp_directory;
50015011
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
+
50025048
/*
50035049
** CAPI3REF: Test For Auto-Commit Mode
50045050
** KEYWORDS: {autocommit mode}
50055051
**
50065052
** ^The sqlite3_get_autocommit() interface returns non-zero or
@@ -5175,11 +5221,10 @@
51755221
void*
51765222
);
51775223
51785224
/*
51795225
** CAPI3REF: Enable Or Disable Shared Pager Cache
5180
-** KEYWORDS: {shared cache}
51815226
**
51825227
** ^(This routine enables or disables the sharing of the database cache
51835228
** and schema data structures between [database connection | connections]
51845229
** to the same database. Sharing is enabled if the argument is true
51855230
** and disabled if the argument is false.)^
@@ -9014,11 +9059,11 @@
90149059
90159060
/* Functions used to query pager state and configuration. */
90169061
SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*);
90179062
SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
90189063
SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*);
9019
-SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*);
9064
+SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*, int);
90209065
SQLITE_PRIVATE const sqlite3_vfs *sqlite3PagerVfs(Pager*);
90219066
SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*);
90229067
SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*);
90239068
SQLITE_PRIVATE int sqlite3PagerNosync(Pager*);
90249069
SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*);
@@ -9284,17 +9329,15 @@
92849329
# ifndef SQLITE_OS_WIN
92859330
# define SQLITE_OS_WIN 0
92869331
# endif
92879332
#endif
92889333
9289
-/*
9290
-** Define the maximum size of a temporary filename
9291
-*/
92929334
#if SQLITE_OS_WIN
92939335
# include <windows.h>
9294
-# define SQLITE_TEMPNAME_SIZE (MAX_PATH+50)
9295
-#elif SQLITE_OS_OS2
9336
+#endif
9337
+
9338
+#if SQLITE_OS_OS2
92969339
# if (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 3) && defined(OS2_HIGH_MEMORY)
92979340
# include <os2safe.h> /* has to be included before os2.h for linking to work */
92989341
# endif
92999342
# define INCL_DOSDATETIME
93009343
# define INCL_DOSFILEMGR
@@ -9303,13 +9346,10 @@
93039346
# define INCL_DOSPROCESS
93049347
# define INCL_DOSMODULEMGR
93059348
# define INCL_DOSSEMAPHORES
93069349
# include <os2.h>
93079350
# include <uconv.h>
9308
-# define SQLITE_TEMPNAME_SIZE (CCHMAXPATHCOMP)
9309
-#else
9310
-# define SQLITE_TEMPNAME_SIZE 200
93119351
#endif
93129352
93139353
/*
93149354
** Determine if we are dealing with Windows NT.
93159355
**
@@ -9339,10 +9379,26 @@
93399379
# define SQLITE_OS_WINCE 1
93409380
#else
93419381
# define SQLITE_OS_WINCE 0
93429382
#endif
93439383
9384
+/*
9385
+** Determine if we are dealing with WindowsRT (Metro) as this has a different and
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
+
93449400
/* If the SET_FULLSYNC macro is not defined above, then make it
93459401
** a no-op
93469402
*/
93479403
#ifndef SET_FULLSYNC
93489404
# define SET_FULLSYNC(x,y)
@@ -10933,19 +10989,25 @@
1093310989
*/
1093410990
struct NameContext {
1093510991
Parse *pParse; /* The parser */
1093610992
SrcList *pSrcList; /* One or more tables used to resolve names */
1093710993
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 */
1093810996
int nRef; /* Number of names resolved by this context */
1093910997
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 */
10943
- AggInfo *pAggInfo; /* Information about aggregates at this level */
10944
- NameContext *pNext; /* Next outer name context. NULL for outermost */
10998
+ u8 ncFlags; /* Zero or more NC_* flags defined below */
1094510999
};
1094611000
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
+
1094711009
/*
1094811010
** An instance of the following structure contains all information
1094911011
** needed to generate code for a single SELECT statement.
1095011012
**
1095111013
** nLimit is set to -1 if there is no LIMIT clause. nOffset is set to 0.
@@ -11623,11 +11685,13 @@
1162311685
SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,ExprSpan*);
1162411686
SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*);
1162511687
SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**);
1162611688
SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**);
1162711689
SQLITE_PRIVATE void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
11628
-SQLITE_PRIVATE void sqlite3ResetInternalSchema(sqlite3*, int);
11690
+SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3*);
11691
+SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3*,int);
11692
+SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3*);
1162911693
SQLITE_PRIVATE void sqlite3BeginParse(Parse*,int);
1163011694
SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3*);
1163111695
SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*);
1163211696
SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *, int);
1163311697
SQLITE_PRIVATE void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int);
@@ -12028,10 +12092,11 @@
1202812092
# define sqlite3VtabUnlockList(X)
1202912093
# define sqlite3VtabSavepoint(X, Y, Z) SQLITE_OK
1203012094
# define sqlite3GetVTable(X,Y) ((VTable*)0)
1203112095
#else
1203212096
SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*);
12097
+SQLITE_PRIVATE void sqlite3VtabDisconnect(sqlite3 *db, Table *p);
1203312098
SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **);
1203412099
SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db);
1203512100
SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db);
1203612101
SQLITE_PRIVATE void sqlite3VtabLock(VTable *);
1203712102
SQLITE_PRIVATE void sqlite3VtabUnlock(VTable *);
@@ -12481,10 +12546,13 @@
1248112546
#ifdef SQLITE_CHECK_PAGES
1248212547
"CHECK_PAGES",
1248312548
#endif
1248412549
#ifdef SQLITE_COVERAGE_TEST
1248512550
"COVERAGE_TEST",
12551
+#endif
12552
+#ifdef SQLITE_CURDIR
12553
+ "CURDIR",
1248612554
#endif
1248712555
#ifdef SQLITE_DEBUG
1248812556
"DEBUG",
1248912557
#endif
1249012558
#ifdef SQLITE_DEFAULT_LOCKING_MODE
@@ -18335,11 +18403,11 @@
1833518403
** _WIN32_WINNT defined to a value >= 0x0400. Currently, the only
1833618404
** call to TryEnterCriticalSection() is #ifdef'ed out, so #ifdef
1833718405
** this out as well.
1833818406
*/
1833918407
#if 0
18340
-#if SQLITE_OS_WINCE
18408
+#if SQLITE_OS_WINCE || SQLITE_OS_WINRT
1834118409
# define mutexIsNT() (1)
1834218410
#else
1834318411
static int mutexIsNT(void){
1834418412
static int osType = 0;
1834518413
if( osType==0 ){
@@ -18388,22 +18456,28 @@
1838818456
** processing, the "interlocked" magic is probably not
1838918457
** strictly necessary.
1839018458
*/
1839118459
static long winMutex_lock = 0;
1839218460
18461
+SQLITE_API extern void sqlite3_win32_sleep(DWORD milliseconds); /* os_win.c */
18462
+
1839318463
static int winMutexInit(void){
1839418464
/* The first to increment to 1 does actual initialization */
1839518465
if( InterlockedCompareExchange(&winMutex_lock, 1, 0)==0 ){
1839618466
int i;
1839718467
for(i=0; i<ArraySize(winMutex_staticMutexes); i++){
18468
+#if SQLITE_OS_WINRT
18469
+ InitializeCriticalSectionEx(&winMutex_staticMutexes[i].mutex, 0, 0);
18470
+#else
1839818471
InitializeCriticalSection(&winMutex_staticMutexes[i].mutex);
18472
+#endif
1839918473
}
1840018474
winMutex_isInit = 1;
1840118475
}else{
1840218476
/* Someone else is in the process of initing the static mutexes */
1840318477
while( !winMutex_isInit ){
18404
- Sleep(1);
18478
+ sqlite3_win32_sleep(1);
1840518479
}
1840618480
}
1840718481
return SQLITE_OK;
1840818482
}
1840918483
@@ -18473,11 +18547,15 @@
1847318547
p = sqlite3MallocZero( sizeof(*p) );
1847418548
if( p ){
1847518549
#ifdef SQLITE_DEBUG
1847618550
p->id = iType;
1847718551
#endif
18552
+#if SQLITE_OS_WINRT
18553
+ InitializeCriticalSectionEx(&p->mutex, 0, 0);
18554
+#else
1847818555
InitializeCriticalSection(&p->mutex);
18556
+#endif
1847918557
}
1848018558
break;
1848118559
}
1848218560
default: {
1848318561
assert( winMutex_isInit==1 );
@@ -19104,10 +19182,14 @@
1910419182
*db->pnBytesFreed += sqlite3DbMallocSize(db, p);
1910519183
return;
1910619184
}
1910719185
if( isLookaside(db, p) ){
1910819186
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
1910919191
pBuf->pNext = db->lookaside.pFree;
1911019192
db->lookaside.pFree = pBuf;
1911119193
db->lookaside.nOut--;
1911219194
return;
1911319195
}
@@ -25062,11 +25144,11 @@
2506225144
unsigned fsFlags; /* cached details from statfs() */
2506325145
#endif
2506425146
#if OS_VXWORKS
2506525147
struct vxworksFileId *pId; /* Unique file ID */
2506625148
#endif
25067
-#ifndef NDEBUG
25149
+#ifdef SQLITE_DEBUG
2506825150
/* The next group of variables are used to track whether or not the
2506925151
** transaction counter in bytes 24-27 of database files are updated
2507025152
** whenever any part of the database changes. An assertion fault will
2507125153
** occur if a file is updated without also updating the transaction
2507225154
** counter. This test is made to avoid new problems similar to the
@@ -25097,11 +25179,10 @@
2509725179
#endif
2509825180
#define UNIXFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */
2509925181
#define UNIXFILE_DELETE 0x20 /* Delete on close */
2510025182
#define UNIXFILE_URI 0x40 /* Filename might have query parameters */
2510125183
#define UNIXFILE_NOLOCK 0x80 /* Do no file locking */
25102
-#define UNIXFILE_CHOWN 0x100 /* File ownership was changed */
2510325184
2510425185
/*
2510525186
** Include code that is common to all os_*.c files
2510625187
*/
2510725188
/************** Include os_common.h in the middle of os_unix.c ***************/
@@ -25350,10 +25431,19 @@
2535025431
** which always has the same well-defined interface.
2535125432
*/
2535225433
static int posixOpen(const char *zFile, int flags, int mode){
2535325434
return open(zFile, flags, mode);
2535425435
}
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
+}
2535525445
2535625446
/* Forward reference */
2535725447
static int openDirectory(const char*, int*);
2535825448
2535925449
/*
@@ -25462,11 +25552,11 @@
2546225552
#define osMkdir ((int(*)(const char*,mode_t))aSyscall[18].pCurrent)
2546325553
2546425554
{ "rmdir", (sqlite3_syscall_ptr)rmdir, 0 },
2546525555
#define osRmdir ((int(*)(const char*))aSyscall[19].pCurrent)
2546625556
25467
- { "fchown", (sqlite3_syscall_ptr)fchown, 0 },
25557
+ { "fchown", (sqlite3_syscall_ptr)posixFchown, 0 },
2546825558
#define osFchown ((int(*)(int,uid_t,gid_t))aSyscall[20].pCurrent)
2546925559
2547025560
{ "umask", (sqlite3_syscall_ptr)umask, 0 },
2547125561
#define osUmask ((mode_t(*)(mode_t))aSyscall[21].pCurrent)
2547225562
@@ -26606,11 +26696,11 @@
2660626696
}
2660726697
}
2660826698
}
2660926699
2661026700
26611
-#ifndef NDEBUG
26701
+#ifdef SQLITE_DEBUG
2661226702
/* Set up the transaction-counter change checking flags when
2661326703
** transitioning from a SHARED to a RESERVED lock. The change
2661426704
** from SHARED to RESERVED marks the beginning of a normal
2661526705
** write operation (not a hot journal rollback).
2661626706
*/
@@ -26685,11 +26775,11 @@
2668526775
pInode = pFile->pInode;
2668626776
assert( pInode->nShared!=0 );
2668726777
if( pFile->eFileLock>SHARED_LOCK ){
2668826778
assert( pInode->eFileLock==pFile->eFileLock );
2668926779
26690
-#ifndef NDEBUG
26780
+#ifdef SQLITE_DEBUG
2669126781
/* When reducing a lock such that other processes can start
2669226782
** reading the database file again, make sure that the
2669326783
** transaction counter was updated if any part of the database
2669426784
** file changed. If the transaction counter is not updated,
2669526785
** other connections to the same file might not realize that
@@ -27884,11 +27974,11 @@
2788427974
assert( pInode->eFileLock==pFile->eFileLock );
2788527975
SimulateIOErrorBenign(1);
2788627976
SimulateIOError( h=(-1) )
2788727977
SimulateIOErrorBenign(0);
2788827978
27889
-#ifndef NDEBUG
27979
+#ifdef SQLITE_DEBUG
2789027980
/* When reducing a lock such that other processes can start
2789127981
** reading the database file again, make sure that the
2789227982
** transaction counter was updated if any part of the database
2789327983
** file changed. If the transaction counter is not updated,
2789427984
** other connections to the same file might not realize that
@@ -28188,11 +28278,11 @@
2818828278
|| offset>=PENDING_BYTE+512
2818928279
|| offset+amt<=PENDING_BYTE
2819028280
);
2819128281
#endif
2819228282
28193
-#ifndef NDEBUG
28283
+#ifdef SQLITE_DEBUG
2819428284
/* If we are doing a normal write to a database file (as opposed to
2819528285
** doing a hot-journal rollback or a write to some file other than a
2819628286
** normal database file) then record the fact that the database
2819728287
** has changed. If the transaction counter is modified, record that
2819828288
** fact too.
@@ -28479,11 +28569,11 @@
2847928569
rc = robust_ftruncate(pFile->h, (off_t)nByte);
2848028570
if( rc ){
2848128571
pFile->lastErrno = errno;
2848228572
return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
2848328573
}else{
28484
-#ifndef NDEBUG
28574
+#ifdef SQLITE_DEBUG
2848528575
/* If we are doing a normal write to a database file (as opposed to
2848628576
** doing a hot-journal rollback or a write to some file other than a
2848728577
** normal database file) and we truncate the file to zero length,
2848828578
** that effectively updates the change counter. This might happen
2848928579
** when restoring a database using the backup API from a zero-length
@@ -28636,11 +28726,11 @@
2863628726
}
2863728727
case SQLITE_FCNTL_VFSNAME: {
2863828728
*(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName);
2863928729
return SQLITE_OK;
2864028730
}
28641
-#ifndef NDEBUG
28731
+#ifdef SQLITE_DEBUG
2864228732
/* The pager calls this method to signal that it has done
2864328733
** a rollback and that the database is therefore unchanged and
2864428734
** it hence it is OK for the transaction change counter to be
2864528735
** unchanged.
2864628736
*/
@@ -28987,18 +29077,13 @@
2898729077
goto shm_open_err;
2898829078
}
2898929079
2899029080
/* If this process is running as root, make sure that the SHM file
2899129081
** 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
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.
29082
+ ** the original owner will not be able to connect.
2899629083
*/
28997
- if( osFchown(pShmNode->h, sStat.st_uid, sStat.st_gid)==0 ){
28998
- pDbFd->ctrlFlags |= UNIXFILE_CHOWN;
28999
- }
29084
+ osFchown(pShmNode->h, sStat.st_uid, sStat.st_gid);
2900029085
2900129086
/* Check to see if another process is holding the dead-man switch.
2900229087
** If not, truncate the file to zero length.
2900329088
*/
2900429089
rc = SQLITE_OK;
@@ -30200,17 +30285,14 @@
3020030285
goto open_finished;
3020130286
}
3020230287
3020330288
/* If this process is running as root and if creating a new rollback
3020430289
** 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,
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.
30290
+ ** the same as the original database.
3020930291
*/
3021030292
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);
3021230294
}
3021330295
}
3021430296
assert( fd>=0 );
3021530297
if( pOutFlags ){
3021630298
*pOutFlags = flags;
@@ -32167,16 +32249,31 @@
3216732249
#endif /* !defined(_OS_COMMON_H_) */
3216832250
3216932251
/************** End of os_common.h *******************************************/
3217032252
/************** Continuing where we left off in os_win.c *********************/
3217132253
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
+
3217232261
/*
3217332262
** Some Microsoft compilers lack this definition.
3217432263
*/
3217532264
#ifndef INVALID_FILE_ATTRIBUTES
3217632265
# define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
3217732266
#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
3217832275
3217932276
/* Forward references */
3218032277
typedef struct winShm winShm; /* A connection to shared-memory */
3218132278
typedef struct winShmNode winShmNode; /* A region of shared-memory */
3218232279
@@ -32222,15 +32319,41 @@
3222232319
** Allowed values for winFile.ctrlFlags
3222332320
*/
3222432321
#define WINFILE_PERSIST_WAL 0x04 /* Persistent WAL mode */
3222532322
#define WINFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */
3222632323
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
+
3222732331
/*
3222832332
* If compiled with SQLITE_WIN32_MALLOC on Windows, we will use the
3222932333
* various Win32 API heap functions instead of our own.
3223032334
*/
3223132335
#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
+
3223232355
/*
3223332356
* The initial size of the Win32-specific heap. This value may be zero.
3223432357
*/
3223532358
#ifndef SQLITE_WIN32_HEAP_INIT_SIZE
3223632359
# define SQLITE_WIN32_HEAP_INIT_SIZE ((SQLITE_DEFAULT_CACHE_SIZE) * \
@@ -32311,61 +32434,50 @@
3231132434
SQLITE_API int sqlite3_os_type = 0;
3231232435
#else
3231332436
static int sqlite3_os_type = 0;
3231432437
#endif
3231532438
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
3232332440
# define SQLITE_WIN32_HAS_ANSI
3232432441
#endif
3232532442
32326
-#if SQLITE_OS_WINCE || SQLITE_OS_WINNT
32443
+#if SQLITE_OS_WINCE || SQLITE_OS_WINNT || SQLITE_OS_WINRT
3232732444
# define SQLITE_WIN32_HAS_WIDE
3232832445
#endif
3232932446
3233032447
#ifndef SYSCALL
3233132448
# define SYSCALL sqlite3_syscall_ptr
3233232449
#endif
3233332450
32334
-#if SQLITE_OS_WINCE
32335
-/*
32336
-** These macros are necessary because Windows CE does not natively support the
32337
-** Win32 APIs LockFile, UnlockFile, and LockFileEx.
32338
- */
32339
-
32340
-# define LockFile(a,b,c,d,e) winceLockFile(&a, b, c, d, e)
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
-
32344
-/*
32345
-** These are the special syscall hacks for Windows CE. The locking related
32346
-** defines here refer to the macros defined just above.
32347
- */
32348
-
32349
-# define osAreFileApisANSI() 1
32350
-# define osLockFile LockFile
32351
-# define osUnlockFile UnlockFile
32352
-# define osLockFileEx LockFileEx
32353
-#endif
32354
-
32451
+/*
32452
+** This function is not available on Windows CE or WinRT.
32453
+ */
32454
+
32455
+#if SQLITE_OS_WINCE || SQLITE_OS_WINRT
32456
+# define osAreFileApisANSI() 1
32457
+#endif
32458
+
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
32462
+** testing and sandboxing. The following array holds the names and pointers
32463
+** to all overrideable system calls.
32464
+*/
3235532465
static struct win_syscall {
3235632466
const char *zName; /* Name of the sytem call */
3235732467
sqlite3_syscall_ptr pCurrent; /* Current value of the system call */
3235832468
sqlite3_syscall_ptr pDefault; /* Default value */
3235932469
} aSyscall[] = {
32360
-#if !SQLITE_OS_WINCE
32470
+#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
3236132471
{ "AreFileApisANSI", (SYSCALL)AreFileApisANSI, 0 },
32362
-
32363
-#define osAreFileApisANSI ((BOOL(WINAPI*)(VOID))aSyscall[0].pCurrent)
3236432472
#else
3236532473
{ "AreFileApisANSI", (SYSCALL)0, 0 },
3236632474
#endif
32475
+
32476
+#ifndef osAreFileApisANSI
32477
+#define osAreFileApisANSI ((BOOL(WINAPI*)(VOID))aSyscall[0].pCurrent)
32478
+#endif
3236732479
3236832480
#if SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE)
3236932481
{ "CharLowerW", (SYSCALL)CharLowerW, 0 },
3237032482
#else
3237132483
{ "CharLowerW", (SYSCALL)0, 0 },
@@ -32392,174 +32504,173 @@
3239232504
#endif
3239332505
3239432506
#define osCreateFileA ((HANDLE(WINAPI*)(LPCSTR,DWORD,DWORD, \
3239532507
LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[4].pCurrent)
3239632508
32397
-#if defined(SQLITE_WIN32_HAS_WIDE)
32509
+#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
3239832510
{ "CreateFileW", (SYSCALL)CreateFileW, 0 },
3239932511
#else
3240032512
{ "CreateFileW", (SYSCALL)0, 0 },
3240132513
#endif
3240232514
3240332515
#define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \
3240432516
LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent)
3240532517
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)
3241232519
{ "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 },
3241332520
#else
3241432521
{ "CreateFileMappingW", (SYSCALL)0, 0 },
3241532522
#endif
3241632523
3241732524
#define osCreateFileMappingW ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \
32418
- DWORD,DWORD,DWORD,LPCWSTR))aSyscall[7].pCurrent)
32525
+ DWORD,DWORD,DWORD,LPCWSTR))aSyscall[6].pCurrent)
3241932526
32420
-#if defined(SQLITE_WIN32_HAS_WIDE)
32527
+#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
3242132528
{ "CreateMutexW", (SYSCALL)CreateMutexW, 0 },
3242232529
#else
3242332530
{ "CreateMutexW", (SYSCALL)0, 0 },
3242432531
#endif
3242532532
3242632533
#define osCreateMutexW ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,BOOL, \
32427
- LPCWSTR))aSyscall[8].pCurrent)
32534
+ LPCWSTR))aSyscall[7].pCurrent)
3242832535
3242932536
#if defined(SQLITE_WIN32_HAS_ANSI)
3243032537
{ "DeleteFileA", (SYSCALL)DeleteFileA, 0 },
3243132538
#else
3243232539
{ "DeleteFileA", (SYSCALL)0, 0 },
3243332540
#endif
3243432541
32435
-#define osDeleteFileA ((BOOL(WINAPI*)(LPCSTR))aSyscall[9].pCurrent)
32542
+#define osDeleteFileA ((BOOL(WINAPI*)(LPCSTR))aSyscall[8].pCurrent)
3243632543
3243732544
#if defined(SQLITE_WIN32_HAS_WIDE)
3243832545
{ "DeleteFileW", (SYSCALL)DeleteFileW, 0 },
3243932546
#else
3244032547
{ "DeleteFileW", (SYSCALL)0, 0 },
3244132548
#endif
3244232549
32443
-#define osDeleteFileW ((BOOL(WINAPI*)(LPCWSTR))aSyscall[10].pCurrent)
32550
+#define osDeleteFileW ((BOOL(WINAPI*)(LPCWSTR))aSyscall[9].pCurrent)
3244432551
3244532552
#if SQLITE_OS_WINCE
3244632553
{ "FileTimeToLocalFileTime", (SYSCALL)FileTimeToLocalFileTime, 0 },
3244732554
#else
3244832555
{ "FileTimeToLocalFileTime", (SYSCALL)0, 0 },
3244932556
#endif
3245032557
3245132558
#define osFileTimeToLocalFileTime ((BOOL(WINAPI*)(CONST FILETIME*, \
32452
- LPFILETIME))aSyscall[11].pCurrent)
32559
+ LPFILETIME))aSyscall[10].pCurrent)
3245332560
3245432561
#if SQLITE_OS_WINCE
3245532562
{ "FileTimeToSystemTime", (SYSCALL)FileTimeToSystemTime, 0 },
3245632563
#else
3245732564
{ "FileTimeToSystemTime", (SYSCALL)0, 0 },
3245832565
#endif
3245932566
3246032567
#define osFileTimeToSystemTime ((BOOL(WINAPI*)(CONST FILETIME*, \
32461
- LPSYSTEMTIME))aSyscall[12].pCurrent)
32568
+ LPSYSTEMTIME))aSyscall[11].pCurrent)
3246232569
3246332570
{ "FlushFileBuffers", (SYSCALL)FlushFileBuffers, 0 },
3246432571
32465
-#define osFlushFileBuffers ((BOOL(WINAPI*)(HANDLE))aSyscall[13].pCurrent)
32572
+#define osFlushFileBuffers ((BOOL(WINAPI*)(HANDLE))aSyscall[12].pCurrent)
3246632573
3246732574
#if defined(SQLITE_WIN32_HAS_ANSI)
3246832575
{ "FormatMessageA", (SYSCALL)FormatMessageA, 0 },
3246932576
#else
3247032577
{ "FormatMessageA", (SYSCALL)0, 0 },
3247132578
#endif
3247232579
3247332580
#define osFormatMessageA ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPSTR, \
32474
- DWORD,va_list*))aSyscall[14].pCurrent)
32581
+ DWORD,va_list*))aSyscall[13].pCurrent)
3247532582
3247632583
#if defined(SQLITE_WIN32_HAS_WIDE)
3247732584
{ "FormatMessageW", (SYSCALL)FormatMessageW, 0 },
3247832585
#else
3247932586
{ "FormatMessageW", (SYSCALL)0, 0 },
3248032587
#endif
3248132588
3248232589
#define osFormatMessageW ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPWSTR, \
32483
- DWORD,va_list*))aSyscall[15].pCurrent)
32590
+ DWORD,va_list*))aSyscall[14].pCurrent)
3248432591
3248532592
{ "FreeLibrary", (SYSCALL)FreeLibrary, 0 },
3248632593
32487
-#define osFreeLibrary ((BOOL(WINAPI*)(HMODULE))aSyscall[16].pCurrent)
32594
+#define osFreeLibrary ((BOOL(WINAPI*)(HMODULE))aSyscall[15].pCurrent)
3248832595
3248932596
{ "GetCurrentProcessId", (SYSCALL)GetCurrentProcessId, 0 },
3249032597
32491
-#define osGetCurrentProcessId ((DWORD(WINAPI*)(VOID))aSyscall[17].pCurrent)
32598
+#define osGetCurrentProcessId ((DWORD(WINAPI*)(VOID))aSyscall[16].pCurrent)
3249232599
3249332600
#if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_ANSI)
3249432601
{ "GetDiskFreeSpaceA", (SYSCALL)GetDiskFreeSpaceA, 0 },
3249532602
#else
3249632603
{ "GetDiskFreeSpaceA", (SYSCALL)0, 0 },
3249732604
#endif
3249832605
3249932606
#define osGetDiskFreeSpaceA ((BOOL(WINAPI*)(LPCSTR,LPDWORD,LPDWORD,LPDWORD, \
32500
- LPDWORD))aSyscall[18].pCurrent)
32607
+ LPDWORD))aSyscall[17].pCurrent)
3250132608
32502
-#if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE)
32609
+#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
3250332610
{ "GetDiskFreeSpaceW", (SYSCALL)GetDiskFreeSpaceW, 0 },
3250432611
#else
3250532612
{ "GetDiskFreeSpaceW", (SYSCALL)0, 0 },
3250632613
#endif
3250732614
3250832615
#define osGetDiskFreeSpaceW ((BOOL(WINAPI*)(LPCWSTR,LPDWORD,LPDWORD,LPDWORD, \
32509
- LPDWORD))aSyscall[19].pCurrent)
32616
+ LPDWORD))aSyscall[18].pCurrent)
3251032617
3251132618
#if defined(SQLITE_WIN32_HAS_ANSI)
3251232619
{ "GetFileAttributesA", (SYSCALL)GetFileAttributesA, 0 },
3251332620
#else
3251432621
{ "GetFileAttributesA", (SYSCALL)0, 0 },
3251532622
#endif
3251632623
32517
-#define osGetFileAttributesA ((DWORD(WINAPI*)(LPCSTR))aSyscall[20].pCurrent)
32624
+#define osGetFileAttributesA ((DWORD(WINAPI*)(LPCSTR))aSyscall[19].pCurrent)
3251832625
32519
-#if defined(SQLITE_WIN32_HAS_WIDE)
32626
+#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
3252032627
{ "GetFileAttributesW", (SYSCALL)GetFileAttributesW, 0 },
3252132628
#else
3252232629
{ "GetFileAttributesW", (SYSCALL)0, 0 },
3252332630
#endif
3252432631
32525
-#define osGetFileAttributesW ((DWORD(WINAPI*)(LPCWSTR))aSyscall[21].pCurrent)
32632
+#define osGetFileAttributesW ((DWORD(WINAPI*)(LPCWSTR))aSyscall[20].pCurrent)
3252632633
3252732634
#if defined(SQLITE_WIN32_HAS_WIDE)
3252832635
{ "GetFileAttributesExW", (SYSCALL)GetFileAttributesExW, 0 },
3252932636
#else
3253032637
{ "GetFileAttributesExW", (SYSCALL)0, 0 },
3253132638
#endif
3253232639
3253332640
#define osGetFileAttributesExW ((BOOL(WINAPI*)(LPCWSTR,GET_FILEEX_INFO_LEVELS, \
32534
- LPVOID))aSyscall[22].pCurrent)
32641
+ LPVOID))aSyscall[21].pCurrent)
3253532642
32643
+#if !SQLITE_OS_WINRT
3253632644
{ "GetFileSize", (SYSCALL)GetFileSize, 0 },
32645
+#else
32646
+ { "GetFileSize", (SYSCALL)0, 0 },
32647
+#endif
3253732648
32538
-#define osGetFileSize ((DWORD(WINAPI*)(HANDLE,LPDWORD))aSyscall[23].pCurrent)
32649
+#define osGetFileSize ((DWORD(WINAPI*)(HANDLE,LPDWORD))aSyscall[22].pCurrent)
3253932650
3254032651
#if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_ANSI)
3254132652
{ "GetFullPathNameA", (SYSCALL)GetFullPathNameA, 0 },
3254232653
#else
3254332654
{ "GetFullPathNameA", (SYSCALL)0, 0 },
3254432655
#endif
3254532656
3254632657
#define osGetFullPathNameA ((DWORD(WINAPI*)(LPCSTR,DWORD,LPSTR, \
32547
- LPSTR*))aSyscall[24].pCurrent)
32658
+ LPSTR*))aSyscall[23].pCurrent)
3254832659
32549
-#if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE)
32660
+#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
3255032661
{ "GetFullPathNameW", (SYSCALL)GetFullPathNameW, 0 },
3255132662
#else
3255232663
{ "GetFullPathNameW", (SYSCALL)0, 0 },
3255332664
#endif
3255432665
3255532666
#define osGetFullPathNameW ((DWORD(WINAPI*)(LPCWSTR,DWORD,LPWSTR, \
32556
- LPWSTR*))aSyscall[25].pCurrent)
32667
+ LPWSTR*))aSyscall[24].pCurrent)
3255732668
3255832669
{ "GetLastError", (SYSCALL)GetLastError, 0 },
3255932670
32560
-#define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[26].pCurrent)
32671
+#define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[25].pCurrent)
3256132672
3256232673
#if SQLITE_OS_WINCE
3256332674
/* The GetProcAddressA() routine is only available on Windows CE. */
3256432675
{ "GetProcAddressA", (SYSCALL)GetProcAddressA, 0 },
3256532676
#else
@@ -32567,198 +32678,358 @@
3256732678
** an ANSI string regardless of the _UNICODE setting */
3256832679
{ "GetProcAddressA", (SYSCALL)GetProcAddress, 0 },
3256932680
#endif
3257032681
3257132682
#define osGetProcAddressA ((FARPROC(WINAPI*)(HMODULE, \
32572
- LPCSTR))aSyscall[27].pCurrent)
32683
+ LPCSTR))aSyscall[26].pCurrent)
3257332684
32685
+#if !SQLITE_OS_WINRT
3257432686
{ "GetSystemInfo", (SYSCALL)GetSystemInfo, 0 },
32687
+#else
32688
+ { "GetSystemInfo", (SYSCALL)0, 0 },
32689
+#endif
3257532690
32576
-#define osGetSystemInfo ((VOID(WINAPI*)(LPSYSTEM_INFO))aSyscall[28].pCurrent)
32691
+#define osGetSystemInfo ((VOID(WINAPI*)(LPSYSTEM_INFO))aSyscall[27].pCurrent)
3257732692
3257832693
{ "GetSystemTime", (SYSCALL)GetSystemTime, 0 },
3257932694
32580
-#define osGetSystemTime ((VOID(WINAPI*)(LPSYSTEMTIME))aSyscall[29].pCurrent)
32695
+#define osGetSystemTime ((VOID(WINAPI*)(LPSYSTEMTIME))aSyscall[28].pCurrent)
3258132696
3258232697
#if !SQLITE_OS_WINCE
3258332698
{ "GetSystemTimeAsFileTime", (SYSCALL)GetSystemTimeAsFileTime, 0 },
3258432699
#else
3258532700
{ "GetSystemTimeAsFileTime", (SYSCALL)0, 0 },
3258632701
#endif
3258732702
3258832703
#define osGetSystemTimeAsFileTime ((VOID(WINAPI*)( \
32589
- LPFILETIME))aSyscall[30].pCurrent)
32704
+ LPFILETIME))aSyscall[29].pCurrent)
3259032705
3259132706
#if defined(SQLITE_WIN32_HAS_ANSI)
3259232707
{ "GetTempPathA", (SYSCALL)GetTempPathA, 0 },
3259332708
#else
3259432709
{ "GetTempPathA", (SYSCALL)0, 0 },
3259532710
#endif
3259632711
32597
-#define osGetTempPathA ((DWORD(WINAPI*)(DWORD,LPSTR))aSyscall[31].pCurrent)
32712
+#define osGetTempPathA ((DWORD(WINAPI*)(DWORD,LPSTR))aSyscall[30].pCurrent)
3259832713
32599
-#if defined(SQLITE_WIN32_HAS_WIDE)
32714
+#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
3260032715
{ "GetTempPathW", (SYSCALL)GetTempPathW, 0 },
3260132716
#else
3260232717
{ "GetTempPathW", (SYSCALL)0, 0 },
3260332718
#endif
3260432719
32605
-#define osGetTempPathW ((DWORD(WINAPI*)(DWORD,LPWSTR))aSyscall[32].pCurrent)
32720
+#define osGetTempPathW ((DWORD(WINAPI*)(DWORD,LPWSTR))aSyscall[31].pCurrent)
3260632721
32722
+#if !SQLITE_OS_WINRT
3260732723
{ "GetTickCount", (SYSCALL)GetTickCount, 0 },
32724
+#else
32725
+ { "GetTickCount", (SYSCALL)0, 0 },
32726
+#endif
3260832727
32609
-#define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[33].pCurrent)
32728
+#define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[32].pCurrent)
3261032729
3261132730
#if defined(SQLITE_WIN32_HAS_ANSI)
3261232731
{ "GetVersionExA", (SYSCALL)GetVersionExA, 0 },
3261332732
#else
3261432733
{ "GetVersionExA", (SYSCALL)0, 0 },
3261532734
#endif
3261632735
3261732736
#define osGetVersionExA ((BOOL(WINAPI*)( \
32618
- LPOSVERSIONINFOA))aSyscall[34].pCurrent)
32737
+ LPOSVERSIONINFOA))aSyscall[33].pCurrent)
3261932738
3262032739
{ "HeapAlloc", (SYSCALL)HeapAlloc, 0 },
3262132740
3262232741
#define osHeapAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD, \
32623
- SIZE_T))aSyscall[35].pCurrent)
32742
+ SIZE_T))aSyscall[34].pCurrent)
3262432743
32744
+#if !SQLITE_OS_WINRT
3262532745
{ "HeapCreate", (SYSCALL)HeapCreate, 0 },
32746
+#else
32747
+ { "HeapCreate", (SYSCALL)0, 0 },
32748
+#endif
3262632749
3262732750
#define osHeapCreate ((HANDLE(WINAPI*)(DWORD,SIZE_T, \
32628
- SIZE_T))aSyscall[36].pCurrent)
32751
+ SIZE_T))aSyscall[35].pCurrent)
3262932752
32753
+#if !SQLITE_OS_WINRT
3263032754
{ "HeapDestroy", (SYSCALL)HeapDestroy, 0 },
32755
+#else
32756
+ { "HeapDestroy", (SYSCALL)0, 0 },
32757
+#endif
3263132758
32632
-#define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[37].pCurrent)
32759
+#define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[36].pCurrent)
3263332760
3263432761
{ "HeapFree", (SYSCALL)HeapFree, 0 },
3263532762
32636
-#define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[38].pCurrent)
32763
+#define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[37].pCurrent)
3263732764
3263832765
{ "HeapReAlloc", (SYSCALL)HeapReAlloc, 0 },
3263932766
3264032767
#define osHeapReAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD,LPVOID, \
32641
- SIZE_T))aSyscall[39].pCurrent)
32768
+ SIZE_T))aSyscall[38].pCurrent)
3264232769
3264332770
{ "HeapSize", (SYSCALL)HeapSize, 0 },
3264432771
3264532772
#define osHeapSize ((SIZE_T(WINAPI*)(HANDLE,DWORD, \
32646
- LPCVOID))aSyscall[40].pCurrent)
32773
+ LPCVOID))aSyscall[39].pCurrent)
3264732774
32775
+#if !SQLITE_OS_WINRT
3264832776
{ "HeapValidate", (SYSCALL)HeapValidate, 0 },
32777
+#else
32778
+ { "HeapValidate", (SYSCALL)0, 0 },
32779
+#endif
3264932780
3265032781
#define osHeapValidate ((BOOL(WINAPI*)(HANDLE,DWORD, \
32651
- LPCVOID))aSyscall[41].pCurrent)
32782
+ LPCVOID))aSyscall[40].pCurrent)
3265232783
3265332784
#if defined(SQLITE_WIN32_HAS_ANSI)
3265432785
{ "LoadLibraryA", (SYSCALL)LoadLibraryA, 0 },
3265532786
#else
3265632787
{ "LoadLibraryA", (SYSCALL)0, 0 },
3265732788
#endif
3265832789
32659
-#define osLoadLibraryA ((HMODULE(WINAPI*)(LPCSTR))aSyscall[42].pCurrent)
32790
+#define osLoadLibraryA ((HMODULE(WINAPI*)(LPCSTR))aSyscall[41].pCurrent)
3266032791
32661
-#if defined(SQLITE_WIN32_HAS_WIDE)
32792
+#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
3266232793
{ "LoadLibraryW", (SYSCALL)LoadLibraryW, 0 },
3266332794
#else
3266432795
{ "LoadLibraryW", (SYSCALL)0, 0 },
3266532796
#endif
3266632797
32667
-#define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[43].pCurrent)
32798
+#define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[42].pCurrent)
3266832799
32800
+#if !SQLITE_OS_WINRT
3266932801
{ "LocalFree", (SYSCALL)LocalFree, 0 },
32670
-
32671
-#define osLocalFree ((HLOCAL(WINAPI*)(HLOCAL))aSyscall[44].pCurrent)
32672
-
32673
-#if !SQLITE_OS_WINCE
32674
- { "LockFile", (SYSCALL)LockFile, 0 },
32675
-
32676
-#define osLockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
32677
- DWORD))aSyscall[45].pCurrent)
32802
+#else
32803
+ { "LocalFree", (SYSCALL)0, 0 },
32804
+#endif
32805
+
32806
+#define osLocalFree ((HLOCAL(WINAPI*)(HLOCAL))aSyscall[43].pCurrent)
32807
+
32808
+#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
32809
+ { "LockFile", (SYSCALL)LockFile, 0 },
3267832810
#else
3267932811
{ "LockFile", (SYSCALL)0, 0 },
3268032812
#endif
32813
+
32814
+#ifndef osLockFile
32815
+#define osLockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
32816
+ DWORD))aSyscall[44].pCurrent)
32817
+#endif
3268132818
3268232819
#if !SQLITE_OS_WINCE
3268332820
{ "LockFileEx", (SYSCALL)LockFileEx, 0 },
32684
-
32685
-#define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \
32686
- LPOVERLAPPED))aSyscall[46].pCurrent)
3268732821
#else
3268832822
{ "LockFileEx", (SYSCALL)0, 0 },
3268932823
#endif
3269032824
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
3269132831
{ "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 },
32832
+#else
32833
+ { "MapViewOfFile", (SYSCALL)0, 0 },
32834
+#endif
3269232835
3269332836
#define osMapViewOfFile ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
32694
- SIZE_T))aSyscall[47].pCurrent)
32837
+ SIZE_T))aSyscall[46].pCurrent)
3269532838
3269632839
{ "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 },
3269732840
3269832841
#define osMultiByteToWideChar ((int(WINAPI*)(UINT,DWORD,LPCSTR,int,LPWSTR, \
32699
- int))aSyscall[48].pCurrent)
32842
+ int))aSyscall[47].pCurrent)
3270032843
3270132844
{ "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 },
3270232845
3270332846
#define osQueryPerformanceCounter ((BOOL(WINAPI*)( \
32704
- LARGE_INTEGER*))aSyscall[49].pCurrent)
32847
+ LARGE_INTEGER*))aSyscall[48].pCurrent)
3270532848
3270632849
{ "ReadFile", (SYSCALL)ReadFile, 0 },
3270732850
3270832851
#define osReadFile ((BOOL(WINAPI*)(HANDLE,LPVOID,DWORD,LPDWORD, \
32709
- LPOVERLAPPED))aSyscall[50].pCurrent)
32852
+ LPOVERLAPPED))aSyscall[49].pCurrent)
3271032853
3271132854
{ "SetEndOfFile", (SYSCALL)SetEndOfFile, 0 },
3271232855
32713
-#define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[51].pCurrent)
32856
+#define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[50].pCurrent)
3271432857
32858
+#if !SQLITE_OS_WINRT
3271532859
{ "SetFilePointer", (SYSCALL)SetFilePointer, 0 },
32860
+#else
32861
+ { "SetFilePointer", (SYSCALL)0, 0 },
32862
+#endif
3271632863
3271732864
#define osSetFilePointer ((DWORD(WINAPI*)(HANDLE,LONG,PLONG, \
32718
- DWORD))aSyscall[52].pCurrent)
32865
+ DWORD))aSyscall[51].pCurrent)
3271932866
32867
+#if !SQLITE_OS_WINRT
3272032868
{ "Sleep", (SYSCALL)Sleep, 0 },
32869
+#else
32870
+ { "Sleep", (SYSCALL)0, 0 },
32871
+#endif
3272132872
32722
-#define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[53].pCurrent)
32873
+#define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[52].pCurrent)
3272332874
3272432875
{ "SystemTimeToFileTime", (SYSCALL)SystemTimeToFileTime, 0 },
3272532876
3272632877
#define osSystemTimeToFileTime ((BOOL(WINAPI*)(CONST SYSTEMTIME*, \
32727
- LPFILETIME))aSyscall[54].pCurrent)
32878
+ LPFILETIME))aSyscall[53].pCurrent)
3272832879
32729
-#if !SQLITE_OS_WINCE
32880
+#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
3273032881
{ "UnlockFile", (SYSCALL)UnlockFile, 0 },
32731
-
32732
-#define osUnlockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
32733
- DWORD))aSyscall[55].pCurrent)
3273432882
#else
3273532883
{ "UnlockFile", (SYSCALL)0, 0 },
3273632884
#endif
32885
+
32886
+#ifndef osUnlockFile
32887
+#define osUnlockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
32888
+ DWORD))aSyscall[54].pCurrent)
32889
+#endif
3273732890
3273832891
#if !SQLITE_OS_WINCE
3273932892
{ "UnlockFileEx", (SYSCALL)UnlockFileEx, 0 },
32740
-
32741
-#define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
32742
- LPOVERLAPPED))aSyscall[56].pCurrent)
3274332893
#else
3274432894
{ "UnlockFileEx", (SYSCALL)0, 0 },
3274532895
#endif
32896
+
32897
+#define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
32898
+ LPOVERLAPPED))aSyscall[55].pCurrent)
3274632899
3274732900
{ "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 },
3274832901
32749
-#define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[57].pCurrent)
32902
+#define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[56].pCurrent)
3275032903
3275132904
{ "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 },
3275232905
3275332906
#define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \
32754
- LPCSTR,LPBOOL))aSyscall[58].pCurrent)
32907
+ LPCSTR,LPBOOL))aSyscall[57].pCurrent)
3275532908
3275632909
{ "WriteFile", (SYSCALL)WriteFile, 0 },
3275732910
3275832911
#define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \
32759
- LPOVERLAPPED))aSyscall[59].pCurrent)
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, \
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)
3276033031
3276133032
}; /* End of the overrideable system calls */
3276233033
3276333034
/*
3276433035
** This is the xSetSystemCall() method of sqlite3_vfs for all of the
@@ -32840,10 +33111,68 @@
3284033111
for(i++; i<ArraySize(aSyscall); i++){
3284133112
if( aSyscall[i].pCurrent!=0 ) return aSyscall[i].zName;
3284233113
}
3284333114
return 0;
3284433115
}
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
+}
3284533174
3284633175
/*
3284733176
** Return true (non-zero) if we are running under WinNT, Win2K, WinXP,
3284833177
** or WinCE. Return false (zero) for Win95, Win98, or WinME.
3284933178
**
@@ -32852,11 +33181,11 @@
3285233181
** API as long as we don't call it when running Win95/98/ME. A call to
3285333182
** this routine is used to determine if the host is Win95/98/ME or
3285433183
** WinNT/2K/XP so that we will know whether or not we can safely call
3285533184
** the LockFileEx() API.
3285633185
*/
32857
-#if SQLITE_OS_WINCE
33186
+#if SQLITE_OS_WINCE || SQLITE_OS_WINRT
3285833187
# define isNT() (1)
3285933188
#else
3286033189
static int isNT(void){
3286133190
if( sqlite3_os_type==0 ){
3286233191
OSVERSIONINFOA sInfo;
@@ -32878,11 +33207,11 @@
3287833207
3287933208
winMemAssertMagic();
3288033209
hHeap = winMemGetHeap();
3288133210
assert( hHeap!=0 );
3288233211
assert( hHeap!=INVALID_HANDLE_VALUE );
32883
-#ifdef SQLITE_WIN32_MALLOC_VALIDATE
33212
+#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
3288433213
assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
3288533214
#endif
3288633215
assert( nBytes>=0 );
3288733216
p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
3288833217
if( !p ){
@@ -32900,11 +33229,11 @@
3290033229
3290133230
winMemAssertMagic();
3290233231
hHeap = winMemGetHeap();
3290333232
assert( hHeap!=0 );
3290433233
assert( hHeap!=INVALID_HANDLE_VALUE );
32905
-#ifdef SQLITE_WIN32_MALLOC_VALIDATE
33234
+#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
3290633235
assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) );
3290733236
#endif
3290833237
if( !pPrior ) return; /* Passing NULL to HeapFree is undefined. */
3290933238
if( !osHeapFree(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ){
3291033239
sqlite3_log(SQLITE_NOMEM, "failed to HeapFree block %p (%d), heap=%p",
@@ -32921,11 +33250,11 @@
3292133250
3292233251
winMemAssertMagic();
3292333252
hHeap = winMemGetHeap();
3292433253
assert( hHeap!=0 );
3292533254
assert( hHeap!=INVALID_HANDLE_VALUE );
32926
-#ifdef SQLITE_WIN32_MALLOC_VALIDATE
33255
+#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
3292733256
assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) );
3292833257
#endif
3292933258
assert( nBytes>=0 );
3293033259
if( !pPrior ){
3293133260
p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
@@ -32949,11 +33278,11 @@
3294933278
3295033279
winMemAssertMagic();
3295133280
hHeap = winMemGetHeap();
3295233281
assert( hHeap!=0 );
3295333282
assert( hHeap!=INVALID_HANDLE_VALUE );
32954
-#ifdef SQLITE_WIN32_MALLOC_VALIDATE
33283
+#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
3295533284
assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
3295633285
#endif
3295733286
if( !p ) return 0;
3295833287
n = osHeapSize(hHeap, SQLITE_WIN32_HEAP_FLAGS, p);
3295933288
if( n==(SIZE_T)-1 ){
@@ -32977,10 +33306,12 @@
3297733306
static int winMemInit(void *pAppData){
3297833307
winMemData *pWinMemData = (winMemData *)pAppData;
3297933308
3298033309
if( !pWinMemData ) return SQLITE_ERROR;
3298133310
assert( pWinMemData->magic==WINMEM_MAGIC );
33311
+
33312
+#if !SQLITE_OS_WINRT && SQLITE_WIN32_HEAP_CREATE
3298233313
if( !pWinMemData->hHeap ){
3298333314
pWinMemData->hHeap = osHeapCreate(SQLITE_WIN32_HEAP_FLAGS,
3298433315
SQLITE_WIN32_HEAP_INIT_SIZE,
3298533316
SQLITE_WIN32_HEAP_MAX_SIZE);
3298633317
if( !pWinMemData->hHeap ){
@@ -32989,14 +33320,25 @@
3298933320
osGetLastError(), SQLITE_WIN32_HEAP_FLAGS,
3299033321
SQLITE_WIN32_HEAP_INIT_SIZE, SQLITE_WIN32_HEAP_MAX_SIZE);
3299133322
return SQLITE_NOMEM;
3299233323
}
3299333324
pWinMemData->bOwned = TRUE;
33325
+ assert( pWinMemData->bOwned );
3299433326
}
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
3299533337
assert( pWinMemData->hHeap!=0 );
3299633338
assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE );
32997
-#ifdef SQLITE_WIN32_MALLOC_VALIDATE
33339
+#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
3299833340
assert( osHeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
3299933341
#endif
3300033342
return SQLITE_OK;
3300133343
}
3300233344
@@ -33007,11 +33349,11 @@
3300733349
winMemData *pWinMemData = (winMemData *)pAppData;
3300833350
3300933351
if( !pWinMemData ) return;
3301033352
if( pWinMemData->hHeap ){
3301133353
assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE );
33012
-#ifdef SQLITE_WIN32_MALLOC_VALIDATE
33354
+#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
3301333355
assert( osHeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
3301433356
#endif
3301533357
if( pWinMemData->bOwned ){
3301633358
if( !osHeapDestroy(pWinMemData->hHeap) ){
3301733359
sqlite3_log(SQLITE_NOMEM, "failed to HeapDestroy (%d), heap=%p",
@@ -33207,10 +33549,21 @@
3320733549
*/
3320833550
DWORD dwLen = 0;
3320933551
char *zOut = 0;
3321033552
3321133553
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
3321233565
LPWSTR zTempWide = NULL;
3321333566
dwLen = osFormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
3321433567
FORMAT_MESSAGE_FROM_SYSTEM |
3321533568
FORMAT_MESSAGE_IGNORE_INSERTS,
3321633569
NULL,
@@ -33217,24 +33570,24 @@
3321733570
lastErrno,
3321833571
0,
3321933572
(LPWSTR) &zTempWide,
3322033573
0,
3322133574
0);
33575
+#endif
3322233576
if( dwLen > 0 ){
3322333577
/* allocate a buffer and convert to UTF8 */
3322433578
sqlite3BeginBenignMalloc();
3322533579
zOut = unicodeToUtf8(zTempWide);
3322633580
sqlite3EndBenignMalloc();
33581
+#if !SQLITE_OS_WINRT
3322733582
/* free the system buffer allocated by FormatMessage */
3322833583
osLocalFree(zTempWide);
33584
+#endif
3322933585
}
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
33235
- }else{
33586
+ }
33587
+#ifdef SQLITE_WIN32_HAS_ANSI
33588
+ else{
3323633589
char *zTemp = NULL;
3323733590
dwLen = osFormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
3323833591
FORMAT_MESSAGE_FROM_SYSTEM |
3323933592
FORMAT_MESSAGE_IGNORE_INSERTS,
3324033593
NULL,
@@ -33249,12 +33602,12 @@
3324933602
zOut = sqlite3_win32_mbcs_to_utf8(zTemp);
3325033603
sqlite3EndBenignMalloc();
3325133604
/* free the system buffer allocated by FormatMessage */
3325233605
osLocalFree(zTemp);
3325333606
}
33607
+ }
3325433608
#endif
33255
- }
3325633609
if( 0 == dwLen ){
3325733610
sqlite3_snprintf(nBuf, zBuf, "OsError 0x%x (%u)", lastErrno, lastErrno);
3325833611
}else{
3325933612
/* copy a maximum of nBuf chars to output buffer */
3326033613
sqlite3_snprintf(nBuf, zBuf, "%s", zOut);
@@ -33333,11 +33686,11 @@
3333333686
return 0;
3333433687
}
3333533688
if( e==ERROR_ACCESS_DENIED ||
3333633689
e==ERROR_LOCK_VIOLATION ||
3333733690
e==ERROR_SHARING_VIOLATION ){
33338
- osSleep(win32IoerrRetryDelay*(1+*pnRetry));
33691
+ sqlite3_win32_sleep(win32IoerrRetryDelay*(1+*pnRetry));
3333933692
++*pnRetry;
3334033693
return 1;
3334133694
}
3334233695
if( pError ){
3334333696
*pError = e;
@@ -33394,11 +33747,11 @@
3339433747
** Acquire a lock on the handle h
3339533748
*/
3339633749
static void winceMutexAcquire(HANDLE h){
3339733750
DWORD dwErr;
3339833751
do {
33399
- dwErr = WaitForSingleObject(h, INFINITE);
33752
+ dwErr = osWaitForSingleObject(h, INFINITE);
3340033753
} while (dwErr != WAIT_OBJECT_0 && dwErr != WAIT_ABANDONED);
3340133754
}
3340233755
/*
3340333756
** Release a lock acquired by winceMutexAcquire()
3340433757
*/
@@ -33525,11 +33878,11 @@
3352533878
3352633879
/*
3352733880
** An implementation of the LockFile() API of Windows for CE
3352833881
*/
3352933882
static BOOL winceLockFile(
33530
- HANDLE *phFile,
33883
+ LPHANDLE phFile,
3353133884
DWORD dwFileOffsetLow,
3353233885
DWORD dwFileOffsetHigh,
3353333886
DWORD nNumberOfBytesToLockLow,
3353433887
DWORD nNumberOfBytesToLockHigh
3353533888
){
@@ -33589,11 +33942,11 @@
3358933942
3359033943
/*
3359133944
** An implementation of the UnlockFile API of Windows for CE
3359233945
*/
3359333946
static BOOL winceUnlockFile(
33594
- HANDLE *phFile,
33947
+ LPHANDLE phFile,
3359533948
DWORD dwFileOffsetLow,
3359633949
DWORD dwFileOffsetHigh,
3359733950
DWORD nNumberOfBytesToUnlockLow,
3359833951
DWORD nNumberOfBytesToUnlockHigh
3359933952
){
@@ -33646,38 +33999,77 @@
3364633999
}
3364734000
3364834001
winceMutexRelease(pFile->hMutex);
3364934002
return bReturn;
3365034003
}
33651
-
33652
-/*
33653
-** An implementation of the LockFileEx() API of Windows for CE
33654
-*/
33655
-static BOOL winceLockFileEx(
33656
- HANDLE *phFile,
33657
- DWORD dwFlags,
33658
- DWORD dwReserved,
33659
- DWORD nNumberOfBytesToLockLow,
33660
- DWORD nNumberOfBytesToLockHigh,
33661
- LPOVERLAPPED lpOverlapped
33662
-){
33663
- UNUSED_PARAMETER(dwReserved);
33664
- UNUSED_PARAMETER(nNumberOfBytesToLockHigh);
33665
-
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);
33672
- }
33673
- return FALSE;
33674
-}
3367534004
/*
3367634005
** End of the special code for wince
3367734006
*****************************************************************************/
3367834007
#endif /* SQLITE_OS_WINCE */
34008
+
34009
+/*
34010
+** Lock a file region.
34011
+*/
34012
+static BOOL winLockFile(
34013
+ LPHANDLE phFile,
34014
+ DWORD flags,
34015
+ DWORD offsetLow,
34016
+ DWORD offsetHigh,
34017
+ DWORD numBytesLow,
34018
+ DWORD numBytesHigh
34019
+){
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);
34037
+ }
34038
+#endif
34039
+}
34040
+
34041
+/*
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
+){
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
+}
3367934071
3368034072
/*****************************************************************************
3368134073
** The next group of routines implement the I/O methods specified
3368234074
** by the sqlite3_io_methods object.
3368334075
******************************************************************************/
@@ -33693,10 +34085,11 @@
3369334085
** Move the current position of the file handle passed as the first
3369434086
** argument to offset iOffset within the file. If successful, return 0.
3369534087
** Otherwise, set pFile->lastErrno and return non-zero.
3369634088
*/
3369734089
static int seekWinFile(winFile *pFile, sqlite3_int64 iOffset){
34090
+#if !SQLITE_OS_WINRT
3369834091
LONG upperBits; /* Most sig. 32 bits of new offset */
3369934092
LONG lowerBits; /* Least sig. 32 bits of new offset */
3370034093
DWORD dwRet; /* Value returned by SetFilePointer() */
3370134094
DWORD lastErrno; /* Value returned by GetLastError() */
3370234095
@@ -33719,10 +34112,30 @@
3371934112
"seekWinFile", pFile->zPath);
3372034113
return 1;
3372134114
}
3372234115
3372334116
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
3372434137
}
3372534138
3372634139
/*
3372734140
** Close a file.
3372834141
**
@@ -33742,11 +34155,11 @@
3374234155
assert( pFile->pShm==0 );
3374334156
OSTRACE(("CLOSE %d\n", pFile->h));
3374434157
do{
3374534158
rc = osCloseHandle(pFile->h);
3374634159
/* 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) );
3374834161
#if SQLITE_OS_WINCE
3374934162
#define WINCE_DELETION_ATTEMPTS 3
3375034163
winceDestroyLock(pFile);
3375134164
if( pFile->zDeleteOnClose ){
3375234165
int cnt = 0;
@@ -33753,11 +34166,11 @@
3375334166
while(
3375434167
osDeleteFileW(pFile->zDeleteOnClose)==0
3375534168
&& osGetFileAttributesW(pFile->zDeleteOnClose)!=0xffffffff
3375634169
&& cnt++ < WINCE_DELETION_ATTEMPTS
3375734170
){
33758
- osSleep(100); /* Wait a little before trying again */
34171
+ sqlite3_win32_sleep(100); /* Wait a little before trying again */
3375934172
}
3376034173
sqlite3_free(pFile->zDeleteOnClose);
3376134174
}
3376234175
#endif
3376334176
OSTRACE(("CLOSE %d %s\n", pFile->h, rc ? "ok" : "failed"));
@@ -34008,60 +34421,105 @@
3400834421
3400934422
/*
3401034423
** Determine the current size of a file in bytes
3401134424
*/
3401234425
static int winFileSize(sqlite3_file *id, sqlite3_int64 *pSize){
34013
- DWORD upperBits;
34014
- DWORD lowerBits;
3401534426
winFile *pFile = (winFile*)id;
34016
- DWORD lastErrno;
34427
+ int rc = SQLITE_OK;
3401734428
3401834429
assert( id!=0 );
3401934430
SimulateIOError(return SQLITE_IOERR_FSTAT);
34020
- lowerBits = osGetFileSize(pFile->h, &upperBits);
34021
- if( (lowerBits == INVALID_FILE_SIZE)
34022
- && ((lastErrno = osGetLastError())!=NO_ERROR) )
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
3402334444
{
34024
- pFile->lastErrno = lastErrno;
34025
- return winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno,
34445
+ DWORD upperBits;
34446
+ DWORD lowerBits;
34447
+ DWORD lastErrno;
34448
+
34449
+ lowerBits = osGetFileSize(pFile->h, &upperBits);
34450
+ *pSize = (((sqlite3_int64)upperBits)<<32) + lowerBits;
34451
+ if( (lowerBits == INVALID_FILE_SIZE)
34452
+ && ((lastErrno = osGetLastError())!=NO_ERROR) ){
34453
+ pFile->lastErrno = lastErrno;
34454
+ rc = winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno,
3402634455
"winFileSize", pFile->zPath);
34456
+ }
3402734457
}
34028
- *pSize = (((sqlite3_int64)upperBits)<<32) + lowerBits;
34029
- return SQLITE_OK;
34458
+#endif
34459
+ return rc;
3403034460
}
3403134461
3403234462
/*
3403334463
** LOCKFILE_FAIL_IMMEDIATELY is undefined on some Windows systems.
3403434464
*/
3403534465
#ifndef LOCKFILE_FAIL_IMMEDIATELY
3403634466
# define LOCKFILE_FAIL_IMMEDIATELY 1
3403734467
#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
3403834492
3403934493
/*
3404034494
** Acquire a reader lock.
3404134495
** Different API routines are called depending on whether or not this
3404234496
** is Win9x or WinNT.
3404334497
*/
3404434498
static int getReadLock(winFile *pFile){
3404534499
int res;
3404634500
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.
34054
-*/
34055
-#if SQLITE_OS_WINCE==0
34056
- }else{
34501
+#if SQLITE_OS_WINCE
34502
+ /*
34503
+ ** NOTE: Windows CE is handled differently here due its lack of the Win32
34504
+ ** API LockFileEx.
34505
+ */
34506
+ res = winceLockFile(&pFile->h, SHARED_FIRST, 0, 1, 0);
34507
+#else
34508
+ res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS, SHARED_FIRST, 0,
34509
+ SHARED_SIZE, 0);
34510
+#endif
34511
+ }
34512
+#ifdef SQLITE_WIN32_HAS_ANSI
34513
+ else{
3405734514
int lk;
3405834515
sqlite3_randomness(sizeof(lk), &lk);
3405934516
pFile->sharedLockByte = (short)((lk & 0x7fffffff)%(SHARED_SIZE - 1));
34060
- res = osLockFile(pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
34517
+ res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS,
34518
+ SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
34519
+ }
3406134520
#endif
34062
- }
3406334521
if( res == 0 ){
3406434522
pFile->lastErrno = osGetLastError();
3406534523
/* No need to log a failure to lock */
3406634524
}
3406734525
return res;
@@ -34072,18 +34530,17 @@
3407234530
*/
3407334531
static int unlockReadLock(winFile *pFile){
3407434532
int res;
3407534533
DWORD lastErrno;
3407634534
if( isNT() ){
34077
- res = osUnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
34078
-/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
34079
-*/
34080
-#if SQLITE_OS_WINCE==0
34081
- }else{
34082
- res = osUnlockFile(pFile->h, SHARED_FIRST + pFile->sharedLockByte, 0, 1, 0);
34535
+ res = winUnlockFile(&pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
34536
+ }
34537
+#ifdef SQLITE_WIN32_HAS_ANSI
34538
+ else{
34539
+ res = winUnlockFile(&pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
34540
+ }
3408334541
#endif
34084
- }
3408534542
if( res==0 && ((lastErrno = osGetLastError())!=ERROR_NOT_LOCKED) ){
3408634543
pFile->lastErrno = lastErrno;
3408734544
winLogError(SQLITE_IOERR_UNLOCK, pFile->lastErrno,
3408834545
"unlockReadLock", pFile->zPath);
3408934546
}
@@ -34150,19 +34607,20 @@
3415034607
if( (pFile->locktype==NO_LOCK)
3415134608
|| ( (locktype==EXCLUSIVE_LOCK)
3415234609
&& (pFile->locktype==RESERVED_LOCK))
3415334610
){
3415434611
int cnt = 3;
34155
- while( cnt-->0 && (res = osLockFile(pFile->h, PENDING_BYTE, 0, 1, 0))==0 ){
34612
+ while( cnt-->0 && (res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS,
34613
+ PENDING_BYTE, 0, 1, 0))==0 ){
3415634614
/* Try 3 times to get the pending lock. This is needed to work
3415734615
** around problems caused by indexing and/or anti-virus software on
3415834616
** Windows systems.
3415934617
** If you are using this code as a model for alternative VFSes, do not
3416034618
** copy this retry logic. It is a hack intended for Windows only.
3416134619
*/
3416234620
OSTRACE(("could not get a PENDING lock. cnt=%d\n", cnt));
34163
- if( cnt ) osSleep(1);
34621
+ if( cnt ) sqlite3_win32_sleep(1);
3416434622
}
3416534623
gotPendingLock = res;
3416634624
if( !res ){
3416734625
lastErrno = osGetLastError();
3416834626
}
@@ -34182,11 +34640,11 @@
3418234640
3418334641
/* Acquire a RESERVED lock
3418434642
*/
3418534643
if( locktype==RESERVED_LOCK && res ){
3418634644
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);
3418834646
if( res ){
3418934647
newLocktype = RESERVED_LOCK;
3419034648
}else{
3419134649
lastErrno = osGetLastError();
3419234650
}
@@ -34203,11 +34661,12 @@
3420334661
*/
3420434662
if( locktype==EXCLUSIVE_LOCK && res ){
3420534663
assert( pFile->locktype>=SHARED_LOCK );
3420634664
res = unlockReadLock(pFile);
3420734665
OSTRACE(("unreadlock = %d\n", res));
34208
- res = osLockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
34666
+ res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS, SHARED_FIRST, 0,
34667
+ SHARED_SIZE, 0);
3420934668
if( res ){
3421034669
newLocktype = EXCLUSIVE_LOCK;
3421134670
}else{
3421234671
lastErrno = osGetLastError();
3421334672
OSTRACE(("error-code = %d\n", lastErrno));
@@ -34217,11 +34676,11 @@
3421734676
3421834677
/* If we are holding a PENDING lock that ought to be released, then
3421934678
** release it now.
3422034679
*/
3422134680
if( gotPendingLock && locktype==SHARED_LOCK ){
34222
- osUnlockFile(pFile->h, PENDING_BYTE, 0, 1, 0);
34681
+ winUnlockFile(&pFile->h, PENDING_BYTE, 0, 1, 0);
3422334682
}
3422434683
3422534684
/* Update the state of the lock has held in the file descriptor then
3422634685
** return the appropriate result code.
3422734686
*/
@@ -34251,13 +34710,13 @@
3425134710
assert( id!=0 );
3425234711
if( pFile->locktype>=RESERVED_LOCK ){
3425334712
rc = 1;
3425434713
OSTRACE(("TEST WR-LOCK %d %d (local)\n", pFile->h, rc));
3425534714
}else{
34256
- rc = osLockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
34715
+ rc = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS, RESERVED_BYTE, 0, 1, 0);
3425734716
if( rc ){
34258
- osUnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
34717
+ winUnlockFile(&pFile->h, RESERVED_BYTE, 0, 1, 0);
3425934718
}
3426034719
rc = !rc;
3426134720
OSTRACE(("TEST WR-LOCK %d %d (remote)\n", pFile->h, rc));
3426234721
}
3426334722
*pResOut = rc;
@@ -34283,26 +34742,26 @@
3428334742
assert( locktype<=SHARED_LOCK );
3428434743
OSTRACE(("UNLOCK %d to %d was %d(%d)\n", pFile->h, locktype,
3428534744
pFile->locktype, pFile->sharedLockByte));
3428634745
type = pFile->locktype;
3428734746
if( type>=EXCLUSIVE_LOCK ){
34288
- osUnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
34747
+ winUnlockFile(&pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
3428934748
if( locktype==SHARED_LOCK && !getReadLock(pFile) ){
3429034749
/* This should never happen. We should always be able to
3429134750
** reacquire the read lock */
3429234751
rc = winLogError(SQLITE_IOERR_UNLOCK, osGetLastError(),
3429334752
"winUnlock", pFile->zPath);
3429434753
}
3429534754
}
3429634755
if( type>=RESERVED_LOCK ){
34297
- osUnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
34756
+ winUnlockFile(&pFile->h, RESERVED_BYTE, 0, 1, 0);
3429834757
}
3429934758
if( locktype==NO_LOCK && type>=SHARED_LOCK ){
3430034759
unlockReadLock(pFile);
3430134760
}
3430234761
if( type>=PENDING_LOCK ){
34303
- osUnlockFile(pFile->h, PENDING_BYTE, 0, 1, 0);
34762
+ winUnlockFile(&pFile->h, PENDING_BYTE, 0, 1, 0);
3430434763
}
3430534764
pFile->locktype = (u8)locktype;
3430634765
return rc;
3430734766
}
3430834767
@@ -34536,29 +34995,23 @@
3453634995
winShmNode *pFile, /* Apply locks to this open shared-memory segment */
3453734996
int lockType, /* _SHM_UNLCK, _SHM_RDLCK, or _SHM_WRLCK */
3453834997
int ofst, /* Offset to first byte to be locked/unlocked */
3453934998
int nByte /* Number of bytes to lock or unlock */
3454034999
){
34541
- OVERLAPPED ovlp;
34542
- DWORD dwFlags;
3454335000
int rc = 0; /* Result code form Lock/UnlockFileEx() */
3454435001
3454535002
/* Access to the winShmNode object is serialized by the caller */
3454635003
assert( sqlite3_mutex_held(pFile->mutex) || pFile->nRef==0 );
3454735004
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
-
3455535005
/* Release/Acquire the system-level lock */
3455635006
if( lockType==_SHM_UNLCK ){
34557
- rc = osUnlockFileEx(pFile->hFile.h, 0, nByte, 0, &ovlp);
35007
+ rc = winUnlockFile(&pFile->hFile.h, ofst, 0, nByte, 0);
3455835008
}else{
34559
- rc = osLockFileEx(pFile->hFile.h, dwFlags, 0, nByte, 0, &ovlp);
35009
+ /* Initialize the locking parameters */
35010
+ DWORD dwFlags = LOCKFILE_FAIL_IMMEDIATELY;
35011
+ if( lockType == _SHM_WRLCK ) dwFlags |= LOCKFILE_EXCLUSIVE_LOCK;
35012
+ rc = winLockFile(&pFile->hFile.h, dwFlags, ofst, 0, nByte, 0);
3456035013
}
3456135014
3456235015
if( rc!= 0 ){
3456335016
rc = SQLITE_OK;
3456435017
}else{
@@ -34992,22 +35445,34 @@
3499235445
3499335446
while( pShmNode->nRegion<=iRegion ){
3499435447
HANDLE hMap; /* file-mapping handle */
3499535448
void *pMap = 0; /* Mapped memory region */
3499635449
34997
- hMap = osCreateFileMapping(pShmNode->hFile.h,
35450
+#if SQLITE_OS_WINRT
35451
+ hMap = osCreateFileMappingFromApp(pShmNode->hFile.h,
35452
+ NULL, PAGE_READWRITE, nByte, NULL
35453
+ );
35454
+#else
35455
+ hMap = osCreateFileMappingW(pShmNode->hFile.h,
3499835456
NULL, PAGE_READWRITE, 0, nByte, NULL
3499935457
);
35458
+#endif
3500035459
OSTRACE(("SHM-MAP pid-%d create region=%d nbyte=%d %s\n",
3500135460
(int)osGetCurrentProcessId(), pShmNode->nRegion, nByte,
3500235461
hMap ? "ok" : "failed"));
3500335462
if( hMap ){
3500435463
int iOffset = pShmNode->nRegion*szRegion;
3500535464
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
3500635470
pMap = osMapViewOfFile(hMap, FILE_MAP_WRITE | FILE_MAP_READ,
3500735471
0, iOffset - iOffsetShift, szRegion + iOffsetShift
3500835472
);
35473
+#endif
3500935474
OSTRACE(("SHM-MAP pid-%d map region=%d offset=%d size=%d %s\n",
3501035475
(int)osGetCurrentProcessId(), pShmNode->nRegion, iOffset,
3501135476
szRegion, pMap ? "ok" : "failed"));
3501235477
}
3501335478
if( !pMap ){
@@ -35089,17 +35554,16 @@
3508935554
*/
3509035555
static void *convertUtf8Filename(const char *zFilename){
3509135556
void *zConverted = 0;
3509235557
if( isNT() ){
3509335558
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
35097
- }else{
35559
+ }
35560
+#ifdef SQLITE_WIN32_HAS_ANSI
35561
+ else{
3509835562
zConverted = sqlite3_win32_utf8_to_mbcs(zFilename);
35563
+ }
3509935564
#endif
35100
- }
3510135565
/* caller will handle out of memory */
3510235566
return zConverted;
3510335567
}
3510435568
3510535569
/*
@@ -35110,21 +35574,26 @@
3511035574
static char zChars[] =
3511135575
"abcdefghijklmnopqrstuvwxyz"
3511235576
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3511335577
"0123456789";
3511435578
size_t i, j;
35579
+ int nTempPath;
3511535580
char zTempPath[MAX_PATH+2];
3511635581
3511735582
/* It's odd to simulate an io-error here, but really this is just
3511835583
** using the io-error infrastructure to test that SQLite handles this
3511935584
** function failing.
3512035585
*/
3512135586
SimulateIOError( return SQLITE_IOERR );
3512235587
35588
+ memset(zTempPath, 0, MAX_PATH+2);
35589
+
3512335590
if( sqlite3_temp_directory ){
3512435591
sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", sqlite3_temp_directory);
35125
- }else if( isNT() ){
35592
+ }
35593
+#if !SQLITE_OS_WINRT
35594
+ else if( isNT() ){
3512635595
char *zMulti;
3512735596
WCHAR zWidePath[MAX_PATH];
3512835597
osGetTempPathW(MAX_PATH-30, zWidePath);
3512935598
zMulti = unicodeToUtf8(zWidePath);
3513035599
if( zMulti ){
@@ -35131,16 +35600,13 @@
3513135600
sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zMulti);
3513235601
sqlite3_free(zMulti);
3513335602
}else{
3513435603
return SQLITE_IOERR_NOMEM;
3513535604
}
35136
-/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
35137
-** Since the ANSI version of these Windows API do not exist for WINCE,
35138
-** it's important to not reference them for WINCE builds.
35139
-*/
35140
-#if SQLITE_OS_WINCE==0
35141
- }else{
35605
+ }
35606
+#ifdef SQLITE_WIN32_HAS_ANSI
35607
+ else{
3514235608
char *zUtf8;
3514335609
char zMbcsPath[MAX_PATH];
3514435610
osGetTempPathA(MAX_PATH-30, zMbcsPath);
3514535611
zUtf8 = sqlite3_win32_mbcs_to_utf8(zMbcsPath);
3514635612
if( zUtf8 ){
@@ -35147,25 +35613,29 @@
3514735613
sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zUtf8);
3514835614
sqlite3_free(zUtf8);
3514935615
}else{
3515035616
return SQLITE_IOERR_NOMEM;
3515135617
}
35618
+ }
3515235619
#endif
35153
- }
35620
+#endif
3515435621
3515535622
/* Check that the output buffer is large enough for the temporary file
3515635623
** name. If it is not, return SQLITE_ERROR.
3515735624
*/
35158
- if( (sqlite3Strlen30(zTempPath) + sqlite3Strlen30(SQLITE_TEMP_FILE_PREFIX) + 18) >= nBuf ){
35625
+ nTempPath = sqlite3Strlen30(zTempPath);
35626
+
35627
+ if( (nTempPath + sqlite3Strlen30(SQLITE_TEMP_FILE_PREFIX) + 18) >= nBuf ){
3515935628
return SQLITE_ERROR;
3516035629
}
3516135630
35162
- for(i=sqlite3Strlen30(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){}
35631
+ for(i=nTempPath; i>0 && zTempPath[i-1]=='\\'; i--){}
3516335632
zTempPath[i] = 0;
3516435633
35165
- sqlite3_snprintf(nBuf-18, zBuf,
35166
- "%s\\"SQLITE_TEMP_FILE_PREFIX, zTempPath);
35634
+ sqlite3_snprintf(nBuf-18, zBuf, (nTempPath > 0) ?
35635
+ "%s\\"SQLITE_TEMP_FILE_PREFIX : SQLITE_TEMP_FILE_PREFIX,
35636
+ zTempPath);
3516735637
j = sqlite3Strlen30(zBuf);
3516835638
sqlite3_randomness(15, &zBuf[j]);
3516935639
for(i=0; i<15; i++, j++){
3517035640
zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
3517135641
}
@@ -35357,33 +35827,52 @@
3535735827
#if SQLITE_OS_WINCE
3535835828
dwFlagsAndAttributes |= FILE_FLAG_RANDOM_ACCESS;
3535935829
#endif
3536035830
3536135831
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
3536235850
while( (h = osCreateFileW((LPCWSTR)zConverted,
3536335851
dwDesiredAccess,
3536435852
dwShareMode, NULL,
3536535853
dwCreationDisposition,
3536635854
dwFlagsAndAttributes,
3536735855
NULL))==INVALID_HANDLE_VALUE &&
3536835856
retryIoerr(&cnt, &lastErrno) ){
3536935857
/* Noop */
3537035858
}
35371
-#if SQLITE_OS_WINCE==0
35372
- }else{
35859
+#endif
35860
+ }
35861
+#ifdef SQLITE_WIN32_HAS_ANSI
35862
+ else{
3537335863
while( (h = osCreateFileA((LPCSTR)zConverted,
3537435864
dwDesiredAccess,
3537535865
dwShareMode, NULL,
3537635866
dwCreationDisposition,
3537735867
dwFlagsAndAttributes,
3537835868
NULL))==INVALID_HANDLE_VALUE &&
3537935869
retryIoerr(&cnt, &lastErrno) ){
3538035870
/* Noop */
3538135871
}
35872
+ }
3538235873
#endif
35383
- }
35384
-
3538535874
logIoerr(cnt);
3538635875
3538735876
OSTRACE(("OPEN %d %s 0x%lx %s\n",
3538835877
h, zName, dwDesiredAccess,
3538935878
h==INVALID_HANDLE_VALUE ? "failed" : "ok"));
@@ -35469,11 +35958,23 @@
3546935958
if( zConverted==0 ){
3547035959
return SQLITE_IOERR_NOMEM;
3547135960
}
3547235961
if( isNT() ){
3547335962
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
3547435974
attr = osGetFileAttributesW(zConverted);
35975
+#endif
3547535976
if ( attr==INVALID_FILE_ATTRIBUTES ){
3547635977
rc = SQLITE_OK; /* Already gone? */
3547735978
break;
3547835979
}
3547935980
if ( attr&FILE_ATTRIBUTE_DIRECTORY ){
@@ -35487,16 +35988,13 @@
3548735988
if ( !retryIoerr(&cnt, &lastErrno) ){
3548835989
rc = SQLITE_ERROR; /* No more retries. */
3548935990
break;
3549035991
}
3549135992
} while(1);
35492
-/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
35493
-** Since the ANSI version of these Windows API do not exist for WINCE,
35494
-** it's important to not reference them for WINCE builds.
35495
-*/
35496
-#if SQLITE_OS_WINCE==0
35497
- }else{
35993
+ }
35994
+#ifdef SQLITE_WIN32_HAS_ANSI
35995
+ else{
3549835996
do {
3549935997
attr = osGetFileAttributesA(zConverted);
3550035998
if ( attr==INVALID_FILE_ATTRIBUTES ){
3550135999
rc = SQLITE_OK; /* Already gone? */
3550236000
break;
@@ -35512,12 +36010,12 @@
3551236010
if ( !retryIoerr(&cnt, &lastErrno) ){
3551336011
rc = SQLITE_ERROR; /* No more retries. */
3551436012
break;
3551536013
}
3551636014
} while(1);
36015
+ }
3551736016
#endif
35518
- }
3551936017
if( rc ){
3552036018
rc = winLogError(SQLITE_IOERR_DELETE, lastErrno,
3552136019
"winDelete", zFilename);
3552236020
}else{
3552336021
logIoerr(cnt);
@@ -35573,19 +36071,16 @@
3557336071
return SQLITE_IOERR_ACCESS;
3557436072
}else{
3557536073
attr = INVALID_FILE_ATTRIBUTES;
3557636074
}
3557736075
}
35578
-/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
35579
-** Since the ANSI version of these Windows API do not exist for WINCE,
35580
-** it's important to not reference them for WINCE builds.
35581
-*/
35582
-#if SQLITE_OS_WINCE==0
35583
- }else{
36076
+ }
36077
+#ifdef SQLITE_WIN32_HAS_ANSI
36078
+ else{
3558436079
attr = osGetFileAttributesA((char*)zConverted);
36080
+ }
3558536081
#endif
35586
- }
3558736082
sqlite3_free(zConverted);
3558836083
switch( flags ){
3558936084
case SQLITE_ACCESS_READ:
3559036085
case SQLITE_ACCESS_EXISTS:
3559136086
rc = attr!=INVALID_FILE_ATTRIBUTES;
@@ -35599,10 +36094,47 @@
3559936094
}
3560036095
*pResOut = rc;
3560136096
return SQLITE_OK;
3560236097
}
3560336098
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
+}
3560436136
3560536137
/*
3560636138
** Turn a relative pathname into a full pathname. Write the full
3560736139
** pathname into zOut[]. zOut[] will be at least pVfs->mxPathname
3560836140
** bytes in size.
@@ -35615,23 +36147,55 @@
3561536147
){
3561636148
3561736149
#if defined(__CYGWIN__)
3561836150
SimulateIOError( return SQLITE_ERROR );
3561936151
UNUSED_PARAMETER(nFull);
35620
- cygwin_conv_to_full_win32_path(zRelative, zFull);
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
+ */
36172
+ cygwin_conv_to_full_win32_path(zRelative, zFull);
36173
+ }
3562136174
return SQLITE_OK;
3562236175
#endif
3562336176
35624
-#if SQLITE_OS_WINCE
36177
+#if (SQLITE_OS_WINCE || SQLITE_OS_WINRT) && !defined(__CYGWIN__)
3562536178
SimulateIOError( return SQLITE_ERROR );
35626
- UNUSED_PARAMETER(nFull);
3562736179
/* WinCE has no concept of a relative pathname, or so I am told. */
35628
- sqlite3_snprintf(pVfs->mxPathname, zFull, "%s", zRelative);
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{
36191
+ sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zRelative);
36192
+ }
3562936193
return SQLITE_OK;
3563036194
#endif
3563136195
35632
-#if !SQLITE_OS_WINCE && !defined(__CYGWIN__)
36196
+#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(__CYGWIN__)
3563336197
int nByte;
3563436198
void *zConverted;
3563536199
char *zOut;
3563636200
3563736201
/* If this path name begins with "/X:", where "X" is any alphabetic
@@ -35645,11 +36209,21 @@
3564536209
** using the io-error infrastructure to test that SQLite handles this
3564636210
** function failing. This function could fail if, for example, the
3564736211
** current working directory has been unlinked.
3564836212
*/
3564936213
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
+ }
3565136225
zConverted = convertUtf8Filename(zRelative);
3565236226
if( zConverted==0 ){
3565336227
return SQLITE_IOERR_NOMEM;
3565436228
}
3565536229
if( isNT() ){
@@ -35662,16 +36236,13 @@
3566236236
}
3566336237
osGetFullPathNameW((LPCWSTR)zConverted, nByte, zTemp, 0);
3566436238
sqlite3_free(zConverted);
3566536239
zOut = unicodeToUtf8(zTemp);
3566636240
sqlite3_free(zTemp);
35667
-/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
35668
-** Since the ANSI version of these Windows API do not exist for WINCE,
35669
-** it's important to not reference them for WINCE builds.
35670
-*/
35671
-#if SQLITE_OS_WINCE==0
35672
- }else{
36241
+ }
36242
+#ifdef SQLITE_WIN32_HAS_ANSI
36243
+ else{
3567336244
char *zTemp;
3567436245
nByte = osGetFullPathNameA((char*)zConverted, 0, 0, 0) + 3;
3567536246
zTemp = sqlite3_malloc( nByte*sizeof(zTemp[0]) );
3567636247
if( zTemp==0 ){
3567736248
sqlite3_free(zConverted);
@@ -35679,14 +36250,14 @@
3567936250
}
3568036251
osGetFullPathNameA((char*)zConverted, nByte, zTemp, 0);
3568136252
sqlite3_free(zConverted);
3568236253
zOut = sqlite3_win32_mbcs_to_utf8(zTemp);
3568336254
sqlite3_free(zTemp);
36255
+ }
3568436256
#endif
35685
- }
3568636257
if( zOut ){
35687
- sqlite3_snprintf(pVfs->mxPathname, zFull, "%s", zOut);
36258
+ sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zOut);
3568836259
sqlite3_free(zOut);
3568936260
return SQLITE_OK;
3569036261
}else{
3569136262
return SQLITE_IOERR_NOMEM;
3569236263
}
@@ -35708,20 +36279,21 @@
3570836279
UNUSED_PARAMETER(pVfs);
3570936280
if( zConverted==0 ){
3571036281
return 0;
3571136282
}
3571236283
if( isNT() ){
36284
+#if SQLITE_OS_WINRT
36285
+ h = osLoadPackagedLibrary((LPCWSTR)zConverted, 0);
36286
+#else
3571336287
h = osLoadLibraryW((LPCWSTR)zConverted);
35714
-/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
35715
-** Since the ANSI version of these Windows API do not exist for WINCE,
35716
-** it's important to not reference them for WINCE builds.
35717
-*/
35718
-#if SQLITE_OS_WINCE==0
35719
- }else{
36288
+#endif
36289
+ }
36290
+#ifdef SQLITE_WIN32_HAS_ANSI
36291
+ else{
3572036292
h = osLoadLibraryA((char*)zConverted);
36293
+ }
3572136294
#endif
35722
- }
3572336295
sqlite3_free(zConverted);
3572436296
return (void*)h;
3572536297
}
3572636298
static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){
3572736299
UNUSED_PARAMETER(pVfs);
@@ -35762,15 +36334,23 @@
3576236334
if( sizeof(DWORD)<=nBuf-n ){
3576336335
DWORD pid = osGetCurrentProcessId();
3576436336
memcpy(&zBuf[n], &pid, sizeof(pid));
3576536337
n += sizeof(pid);
3576636338
}
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
3576736346
if( sizeof(DWORD)<=nBuf-n ){
3576836347
DWORD cnt = osGetTickCount();
3576936348
memcpy(&zBuf[n], &cnt, sizeof(cnt));
3577036349
n += sizeof(cnt);
3577136350
}
36351
+#endif
3577236352
if( sizeof(LARGE_INTEGER)<=nBuf-n ){
3577336353
LARGE_INTEGER i;
3577436354
osQueryPerformanceCounter(&i);
3577536355
memcpy(&zBuf[n], &i, sizeof(i));
3577636356
n += sizeof(i);
@@ -35782,11 +36362,11 @@
3578236362
3578336363
/*
3578436364
** Sleep for a little while. Return the amount of time slept.
3578536365
*/
3578636366
static int winSleep(sqlite3_vfs *pVfs, int microsec){
35787
- osSleep((microsec+999)/1000);
36367
+ sqlite3_win32_sleep((microsec+999)/1000);
3578836368
UNUSED_PARAMETER(pVfs);
3578936369
return ((microsec+999)/1000)*1000;
3579036370
}
3579136371
3579236372
/*
@@ -35924,24 +36504,34 @@
3592436504
winNextSystemCall, /* xNextSystemCall */
3592536505
};
3592636506
3592736507
/* Double-check that the aSyscall[] array has been constructed
3592836508
** correctly. See ticket [bb3a86e890c8e96ab] */
35929
- assert( ArraySize(aSyscall)==60 );
36509
+ assert( ArraySize(aSyscall)==73 );
3593036510
3593136511
#ifndef SQLITE_OMIT_WAL
3593236512
/* get memory map allocation granularity */
3593336513
memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
36514
+#if SQLITE_OS_WINRT
36515
+ osGetNativeSystemInfo(&winSysInfo);
36516
+#else
3593436517
osGetSystemInfo(&winSysInfo);
36518
+#endif
3593536519
assert(winSysInfo.dwAllocationGranularity > 0);
3593636520
#endif
3593736521
3593836522
sqlite3_vfs_register(&winVfs, 1);
3593936523
return SQLITE_OK;
3594036524
}
3594136525
3594236526
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
3594336533
return SQLITE_OK;
3594436534
}
3594536535
3594636536
#endif /* SQLITE_OS_WIN */
3594736537
@@ -37189,16 +37779,18 @@
3718937779
if( p==0 ){
3719037780
/* Memory is not available in the SQLITE_CONFIG_PAGECACHE pool. Get
3719137781
** it from sqlite3Malloc instead.
3719237782
*/
3719337783
p = sqlite3Malloc(nByte);
37784
+#ifndef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
3719437785
if( p ){
3719537786
int sz = sqlite3MallocSize(p);
3719637787
sqlite3_mutex_enter(pcache1.mutex);
3719737788
sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz);
3719837789
sqlite3_mutex_leave(pcache1.mutex);
3719937790
}
37791
+#endif
3720037792
sqlite3MemdebugSetType(p, MEMTYPE_PCACHE);
3720137793
}
3720237794
return p;
3720337795
}
3720437796
@@ -37221,13 +37813,15 @@
3722137813
sqlite3_mutex_leave(pcache1.mutex);
3722237814
}else{
3722337815
assert( sqlite3MemdebugHasType(p, MEMTYPE_PCACHE) );
3722437816
sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
3722537817
nFreed = sqlite3MallocSize(p);
37818
+#ifndef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
3722637819
sqlite3_mutex_enter(pcache1.mutex);
3722737820
sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -nFreed);
3722837821
sqlite3_mutex_leave(pcache1.mutex);
37822
+#endif
3722937823
sqlite3_free(p);
3723037824
}
3723137825
return nFreed;
3723237826
}
3723337827
@@ -43006,11 +43600,16 @@
4300643600
*ppPager = 0;
4300743601
4300843602
#ifndef SQLITE_OMIT_MEMORYDB
4300943603
if( flags & PAGER_MEMORY ){
4301043604
memDb = 1;
43011
- zFilename = 0;
43605
+ if( zFilename && zFilename[0] ){
43606
+ zPathname = sqlite3DbStrDup(0, zFilename);
43607
+ if( zPathname==0 ) return SQLITE_NOMEM;
43608
+ nPathname = sqlite3Strlen30(zPathname);
43609
+ zFilename = 0;
43610
+ }
4301243611
}
4301343612
#endif
4301443613
4301543614
/* Compute and store the full pathname in an allocated buffer pointed
4301643615
** to by zPathname, length nPathname. Or, if this is a temporary file,
@@ -43017,11 +43616,11 @@
4301743616
** leave both nPathname and zPathname set to 0.
4301843617
*/
4301943618
if( zFilename && zFilename[0] ){
4302043619
const char *z;
4302143620
nPathname = pVfs->mxPathname+1;
43022
- zPathname = sqlite3Malloc(nPathname*2);
43621
+ zPathname = sqlite3DbMallocRaw(0, nPathname*2);
4302343622
if( zPathname==0 ){
4302443623
return SQLITE_NOMEM;
4302543624
}
4302643625
zPathname[0] = 0; /* Make sure initialized even if FullPathname() fails */
4302743626
rc = sqlite3OsFullPathname(pVfs, zFilename, nPathname, zPathname);
@@ -43041,11 +43640,11 @@
4304143640
** check for a hot-journal before reading.
4304243641
*/
4304343642
rc = SQLITE_CANTOPEN_BKPT;
4304443643
}
4304543644
if( rc!=SQLITE_OK ){
43046
- sqlite3_free(zPathname);
43645
+ sqlite3DbFree(0, zPathname);
4304743646
return rc;
4304843647
}
4304943648
}
4305043649
4305143650
/* Allocate memory for the Pager structure, PCache object, the
@@ -43071,11 +43670,11 @@
4307143670
+ nPathname + 4 + 2 /* zWal */
4307243671
#endif
4307343672
);
4307443673
assert( EIGHT_BYTE_ALIGNMENT(SQLITE_INT_TO_PTR(journalFileSize)) );
4307543674
if( !pPtr ){
43076
- sqlite3_free(zPathname);
43675
+ sqlite3DbFree(0, zPathname);
4307743676
return SQLITE_NOMEM;
4307843677
}
4307943678
pPager = (Pager*)(pPtr);
4308043679
pPager->pPCache = (PCache*)(pPtr += ROUND8(sizeof(*pPager)));
4308143680
pPager->fd = (sqlite3_file*)(pPtr += ROUND8(pcacheSize));
@@ -43087,21 +43686,21 @@
4308743686
/* Fill in the Pager.zFilename and Pager.zJournal buffers, if required. */
4308843687
if( zPathname ){
4308943688
assert( nPathname>0 );
4309043689
pPager->zJournal = (char*)(pPtr += nPathname + 1 + nUri);
4309143690
memcpy(pPager->zFilename, zPathname, nPathname);
43092
- memcpy(&pPager->zFilename[nPathname+1], zUri, nUri);
43691
+ if( nUri ) memcpy(&pPager->zFilename[nPathname+1], zUri, nUri);
4309343692
memcpy(pPager->zJournal, zPathname, nPathname);
4309443693
memcpy(&pPager->zJournal[nPathname], "-journal\000", 8+1);
4309543694
sqlite3FileSuffix3(pPager->zFilename, pPager->zJournal);
4309643695
#ifndef SQLITE_OMIT_WAL
4309743696
pPager->zWal = &pPager->zJournal[nPathname+8+1];
4309843697
memcpy(pPager->zWal, zPathname, nPathname);
4309943698
memcpy(&pPager->zWal[nPathname], "-wal\000", 4+1);
4310043699
sqlite3FileSuffix3(pPager->zFilename, pPager->zWal);
4310143700
#endif
43102
- sqlite3_free(zPathname);
43701
+ sqlite3DbFree(0, zPathname);
4310343702
}
4310443703
pPager->pVfs = pVfs;
4310543704
pPager->vfsFlags = vfsFlags;
4310643705
4310743706
/* Open the pager file.
@@ -44942,13 +45541,20 @@
4494245541
return rc;
4494345542
}
4494445543
4494545544
/*
4494645545
** 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.
4494745553
*/
44948
-SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager *pPager){
44949
- return pPager->zFilename;
45554
+SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager *pPager, int nullIfMemDb){
45555
+ return (nullIfMemDb && pPager->memDb) ? "" : pPager->zFilename;
4495045556
}
4495145557
4495245558
/*
4495345559
** Return the VFS structure for the pager.
4495445560
*/
@@ -51329,11 +51935,12 @@
5132951935
*/
5133051936
#ifdef SQLITE_OMIT_MEMORYDB
5133151937
const int isMemdb = 0;
5133251938
#else
5133351939
const int isMemdb = (zFilename && strcmp(zFilename, ":memory:")==0)
51334
- || (isTempDb && sqlite3TempInMemory(db));
51940
+ || (isTempDb && sqlite3TempInMemory(db))
51941
+ || (vfsFlags & SQLITE_OPEN_MEMORY)!=0;
5133551942
#endif
5133651943
5133751944
assert( db!=0 );
5133851945
assert( pVfs!=0 );
5133951946
assert( sqlite3_mutex_held(db->mutex) );
@@ -51365,35 +51972,40 @@
5136551972
#if !defined(SQLITE_OMIT_SHARED_CACHE) && !defined(SQLITE_OMIT_DISKIO)
5136651973
/*
5136751974
** If this Btree is a candidate for shared cache, try to find an
5136851975
** existing BtShared object that we can share with
5136951976
*/
51370
- if( isMemdb==0 && isTempDb==0 ){
51977
+ if( isTempDb==0 && (isMemdb==0 || (vfsFlags&SQLITE_OPEN_URI)!=0) ){
5137151978
if( vfsFlags & SQLITE_OPEN_SHAREDCACHE ){
5137251979
int nFullPathname = pVfs->mxPathname+1;
5137351980
char *zFullPathname = sqlite3Malloc(nFullPathname);
5137451981
MUTEX_LOGIC( sqlite3_mutex *mutexShared; )
5137551982
p->sharable = 1;
5137651983
if( !zFullPathname ){
5137751984
sqlite3_free(p);
5137851985
return SQLITE_NOMEM;
5137951986
}
51380
- rc = sqlite3OsFullPathname(pVfs, zFilename, nFullPathname, zFullPathname);
51381
- if( rc ){
51382
- sqlite3_free(zFullPathname);
51383
- sqlite3_free(p);
51384
- return rc;
51987
+ if( isMemdb ){
51988
+ memcpy(zFullPathname, zFilename, sqlite3Strlen30(zFilename)+1);
51989
+ }else{
51990
+ rc = sqlite3OsFullPathname(pVfs, zFilename,
51991
+ nFullPathname, zFullPathname);
51992
+ if( rc ){
51993
+ sqlite3_free(zFullPathname);
51994
+ sqlite3_free(p);
51995
+ return rc;
51996
+ }
5138551997
}
5138651998
#if SQLITE_THREADSAFE
5138751999
mutexOpen = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_OPEN);
5138852000
sqlite3_mutex_enter(mutexOpen);
5138952001
mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
5139052002
sqlite3_mutex_enter(mutexShared);
5139152003
#endif
5139252004
for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){
5139352005
assert( pBt->nRef>0 );
51394
- if( 0==strcmp(zFullPathname, sqlite3PagerFilename(pBt->pPager))
52006
+ if( 0==strcmp(zFullPathname, sqlite3PagerFilename(pBt->pPager, 0))
5139552007
&& sqlite3PagerVfs(pBt->pPager)==pVfs ){
5139652008
int iDb;
5139752009
for(iDb=db->nDb-1; iDb>=0; iDb--){
5139852010
Btree *pExisting = db->aDb[iDb].pBt;
5139952011
if( pExisting && pExisting->pBt==pBt ){
@@ -57654,18 +58266,19 @@
5765458266
return sqlite3StrAccumFinish(&sCheck.errMsg);
5765558267
}
5765658268
#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
5765758269
5765858270
/*
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.
5766058273
**
5766158274
** The pager filename is invariant as long as the pager is
5766258275
** open so it is safe to access without the BtShared mutex.
5766358276
*/
5766458277
SQLITE_PRIVATE const char *sqlite3BtreeGetFilename(Btree *p){
5766558278
assert( p->pBt->pPager!=0 );
57666
- return sqlite3PagerFilename(p->pBt->pPager);
58279
+ return sqlite3PagerFilename(p->pBt->pPager, 1);
5766758280
}
5766858281
5766958282
/*
5767058283
** Return the pathname of the journal file for this database. The return
5767158284
** value of this routine is the same regardless of whether the journal file
@@ -58312,11 +58925,11 @@
5831258925
*/
5831358926
if( rc==SQLITE_DONE ){
5831458927
rc = sqlite3BtreeUpdateMeta(p->pDest,1,p->iDestSchema+1);
5831558928
if( rc==SQLITE_OK ){
5831658929
if( p->pDestDb ){
58317
- sqlite3ResetInternalSchema(p->pDestDb, -1);
58930
+ sqlite3ResetAllSchemasOfConnection(p->pDestDb);
5831858931
}
5831958932
if( destMode==PAGER_JOURNALMODE_WAL ){
5832058933
rc = sqlite3BtreeSetVersion(p->pDest, 2);
5832158934
}
5832258935
}
@@ -64497,12 +65110,13 @@
6449765110
/*
6449865111
** Allocate a new Explain object
6449965112
*/
6450065113
SQLITE_PRIVATE void sqlite3ExplainBegin(Vdbe *pVdbe){
6450165114
if( pVdbe ){
65115
+ Explain *p;
6450265116
sqlite3BeginBenignMalloc();
64503
- Explain *p = sqlite3_malloc( sizeof(Explain) );
65117
+ p = sqlite3_malloc( sizeof(Explain) );
6450465118
if( p ){
6450565119
memset(p, 0, sizeof(*p));
6450665120
p->pVdbe = pVdbe;
6450765121
sqlite3_free(pVdbe->pExplain);
6450865122
pVdbe->pExplain = p;
@@ -67896,11 +68510,11 @@
6789668510
goto abort_due_to_error;
6789768511
}
6789868512
}
6789968513
if( u.ar.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
6790068514
sqlite3ExpirePreparedStatements(db);
67901
- sqlite3ResetInternalSchema(db, -1);
68515
+ sqlite3ResetAllSchemasOfConnection(db);
6790268516
db->flags = (db->flags | SQLITE_InternChanges);
6790368517
}
6790468518
}
6790568519
6790668520
/* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
@@ -68210,11 +68824,11 @@
6821068824
** v-table would have to be ready for the sqlite3_vtab structure itself
6821168825
** to be invalidated whenever sqlite3_step() is called from within
6821268826
** a v-table method.
6821368827
*/
6821468828
if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.aw.iMeta ){
68215
- sqlite3ResetInternalSchema(db, pOp->p1);
68829
+ sqlite3ResetOneSchema(db, pOp->p1);
6821668830
}
6821768831
6821868832
p->expired = 1;
6821968833
rc = SQLITE_SCHEMA;
6822068834
}
@@ -70079,11 +70693,11 @@
7007970693
if( rc==SQLITE_OK ) rc = u.by.initData.rc;
7008070694
sqlite3DbFree(db, u.by.zSql);
7008170695
db->init.busy = 0;
7008270696
}
7008370697
}
70084
- if( rc ) sqlite3ResetInternalSchema(db, -1);
70698
+ if( rc ) sqlite3ResetAllSchemasOfConnection(db);
7008570699
if( rc==SQLITE_NOMEM ){
7008670700
goto no_mem;
7008770701
}
7008870702
break;
7008970703
}
@@ -70746,11 +71360,11 @@
7074671360
u.ci.eOld = sqlite3PagerGetJournalMode(u.ci.pPager);
7074771361
if( u.ci.eNew==PAGER_JOURNALMODE_QUERY ) u.ci.eNew = u.ci.eOld;
7074871362
if( !sqlite3PagerOkToChangeJournalMode(u.ci.pPager) ) u.ci.eNew = u.ci.eOld;
7074971363
7075071364
#ifndef SQLITE_OMIT_WAL
70751
- u.ci.zFilename = sqlite3PagerFilename(u.ci.pPager);
71365
+ u.ci.zFilename = sqlite3PagerFilename(u.ci.pPager, 1);
7075271366
7075371367
/* Do not allow a transition to journal_mode=WAL for a database
7075471368
** in temporary storage or if the VFS does not support shared memory
7075571369
*/
7075671370
if( u.ci.eNew==PAGER_JOURNALMODE_WAL
@@ -71412,11 +72026,11 @@
7141272026
pc, p->zSql, p->zErrMsg);
7141372027
sqlite3VdbeHalt(p);
7141472028
if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1;
7141572029
rc = SQLITE_ERROR;
7141672030
if( resetSchemaOnFault>0 ){
71417
- sqlite3ResetInternalSchema(db, resetSchemaOnFault-1);
72031
+ sqlite3ResetOneSchema(db, resetSchemaOnFault-1);
7141872032
}
7141972033
7142072034
/* This is the only way out of this procedure. We have to
7142172035
** release the mutexes on btrees that were acquired at the
7142272036
** top. */
@@ -73767,11 +74381,11 @@
7376774381
Expr *pOrig;
7376874382
assert( pExpr->pLeft==0 && pExpr->pRight==0 );
7376974383
assert( pExpr->x.pList==0 );
7377074384
assert( pExpr->x.pSelect==0 );
7377174385
pOrig = pEList->a[j].pExpr;
73772
- if( !pNC->allowAgg && ExprHasProperty(pOrig, EP_Agg) ){
74386
+ if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){
7377374387
sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs);
7377474388
return WRC_Abort;
7377574389
}
7377674390
resolveAlias(pParse, pEList, j, pExpr, "");
7377774391
cnt = 1;
@@ -74012,11 +74626,11 @@
7401274626
pExpr->op = TK_NULL;
7401374627
return WRC_Prune;
7401474628
}
7401574629
}
7401674630
#endif
74017
- if( is_agg && !pNC->allowAgg ){
74631
+ if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){
7401874632
sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId);
7401974633
pNC->nErr++;
7402074634
is_agg = 0;
7402174635
}else if( no_such_func ){
7402274636
sqlite3ErrorMsg(pParse, "no such function: %.*s", nId, zId);
@@ -74026,15 +74640,15 @@
7402674640
nId, zId);
7402774641
pNC->nErr++;
7402874642
}
7402974643
if( is_agg ){
7403074644
pExpr->op = TK_AGG_FUNCTION;
74031
- pNC->hasAgg = 1;
74645
+ pNC->ncFlags |= NC_HasAgg;
7403274646
}
74033
- if( is_agg ) pNC->allowAgg = 0;
74647
+ if( is_agg ) pNC->ncFlags &= ~NC_AllowAgg;
7403474648
sqlite3WalkExprList(pWalker, pList);
74035
- if( is_agg ) pNC->allowAgg = 1;
74649
+ if( is_agg ) pNC->ncFlags |= NC_AllowAgg;
7403674650
/* FIX ME: Compute pExpr->affinity based on the expected return
7403774651
** type of the function
7403874652
*/
7403974653
return WRC_Prune;
7404074654
}
@@ -74045,11 +74659,11 @@
7404574659
case TK_IN: {
7404674660
testcase( pExpr->op==TK_IN );
7404774661
if( ExprHasProperty(pExpr, EP_xIsSelect) ){
7404874662
int nRef = pNC->nRef;
7404974663
#ifndef SQLITE_OMIT_CHECK
74050
- if( pNC->isCheck ){
74664
+ if( (pNC->ncFlags & NC_IsCheck)!=0 ){
7405174665
sqlite3ErrorMsg(pParse,"subqueries prohibited in CHECK constraints");
7405274666
}
7405374667
#endif
7405474668
sqlite3WalkSelect(pWalker, pExpr->x.pSelect);
7405574669
assert( pNC->nRef>=nRef );
@@ -74059,11 +74673,11 @@
7405974673
}
7406074674
break;
7406174675
}
7406274676
#ifndef SQLITE_OMIT_CHECK
7406374677
case TK_VARIABLE: {
74064
- if( pNC->isCheck ){
74678
+ if( (pNC->ncFlags & NC_IsCheck)!=0 ){
7406574679
sqlite3ErrorMsg(pParse,"parameters prohibited in CHECK constraints");
7406674680
}
7406774681
break;
7406874682
}
7406974683
#endif
@@ -74141,11 +74755,11 @@
7414174755
*/
7414274756
memset(&nc, 0, sizeof(nc));
7414374757
nc.pParse = pParse;
7414474758
nc.pSrcList = pSelect->pSrc;
7414574759
nc.pEList = pEList;
74146
- nc.allowAgg = 1;
74760
+ nc.ncFlags = NC_AllowAgg;
7414774761
nc.nErr = 0;
7414874762
db = pParse->db;
7414974763
savedSuppErr = db->suppressErr;
7415074764
db->suppressErr = 1;
7415174765
rc = sqlite3ResolveExprNames(&nc, pE);
@@ -74443,11 +75057,11 @@
7444375057
}
7444475058
7444575059
/* Set up the local name-context to pass to sqlite3ResolveExprNames() to
7444675060
** resolve the result-set expression list.
7444775061
*/
74448
- sNC.allowAgg = 1;
75062
+ sNC.ncFlags = NC_AllowAgg;
7444975063
sNC.pSrcList = p->pSrc;
7445075064
sNC.pNext = pOuterNC;
7445175065
7445275066
/* Resolve names in the result set. */
7445375067
pEList = p->pEList;
@@ -74489,14 +75103,14 @@
7448975103
/* If there are no aggregate functions in the result-set, and no GROUP BY
7449075104
** expression, do not allow aggregates in any of the other expressions.
7449175105
*/
7449275106
assert( (p->selFlags & SF_Aggregate)==0 );
7449375107
pGroupBy = p->pGroupBy;
74494
- if( pGroupBy || sNC.hasAgg ){
75108
+ if( pGroupBy || (sNC.ncFlags & NC_HasAgg)!=0 ){
7449575109
p->selFlags |= SF_Aggregate;
7449675110
}else{
74497
- sNC.allowAgg = 0;
75111
+ sNC.ncFlags &= ~NC_AllowAgg;
7449875112
}
7449975113
7450075114
/* If a HAVING clause is present, then there must be a GROUP BY clause.
7450175115
*/
7450275116
if( p->pHaving && !pGroupBy ){
@@ -74521,11 +75135,11 @@
7452175135
7452275136
/* The ORDER BY and GROUP BY clauses may not refer to terms in
7452375137
** outer queries
7452475138
*/
7452575139
sNC.pNext = 0;
74526
- sNC.allowAgg = 1;
75140
+ sNC.ncFlags |= NC_AllowAgg;
7452775141
7452875142
/* Process the ORDER BY clause for singleton SELECT statements.
7452975143
** The ORDER BY clause for compounds SELECT statements is handled
7453075144
** below, after all of the result-sets for all of the elements of
7453175145
** the compound have been resolved.
@@ -74609,11 +75223,11 @@
7460975223
**
7461075224
** SELECT a+b AS x, c+d AS y FROM t1 ORDER BY a+b;
7461175225
**
7461275226
** Function calls are checked to make sure that the function is
7461375227
** 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
7461575229
** set and the opcode is changed from TK_FUNCTION to TK_AGG_FUNCTION.
7461675230
** If an expression contains aggregate functions then the EP_Agg
7461775231
** property on the expression is set.
7461875232
**
7461975233
** An error message is left in pParse if anything is amiss. The number
@@ -74621,11 +75235,11 @@
7462175235
*/
7462275236
SQLITE_PRIVATE int sqlite3ResolveExprNames(
7462375237
NameContext *pNC, /* Namespace to resolve expressions in. */
7462475238
Expr *pExpr /* The expression to be analyzed. */
7462575239
){
74626
- int savedHasAgg;
75240
+ u8 savedHasAgg;
7462775241
Walker w;
7462875242
7462975243
if( pExpr==0 ) return 0;
7463075244
#if SQLITE_MAX_EXPR_DEPTH>0
7463175245
{
@@ -74634,12 +75248,12 @@
7463475248
return 1;
7463575249
}
7463675250
pParse->nHeight += pExpr->nHeight;
7463775251
}
7463875252
#endif
74639
- savedHasAgg = pNC->hasAgg;
74640
- pNC->hasAgg = 0;
75253
+ savedHasAgg = pNC->ncFlags & NC_HasAgg;
75254
+ pNC->ncFlags &= ~NC_HasAgg;
7464175255
w.xExprCallback = resolveExprStep;
7464275256
w.xSelectCallback = resolveSelectStep;
7464375257
w.pParse = pNC->pParse;
7464475258
w.u.pNC = pNC;
7464575259
sqlite3WalkExpr(&w, pExpr);
@@ -74647,14 +75261,14 @@
7464775261
pNC->pParse->nHeight -= pExpr->nHeight;
7464875262
#endif
7464975263
if( pNC->nErr>0 || w.pParse->nErr>0 ){
7465075264
ExprSetProperty(pExpr, EP_Error);
7465175265
}
74652
- if( pNC->hasAgg ){
75266
+ if( pNC->ncFlags & NC_HasAgg ){
7465375267
ExprSetProperty(pExpr, EP_Agg);
7465475268
}else if( savedHasAgg ){
74655
- pNC->hasAgg = 1;
75269
+ pNC->ncFlags |= NC_HasAgg;
7465675270
}
7465775271
return ExprHasProperty(pExpr, EP_Error);
7465875272
}
7465975273
7466075274
@@ -78464,11 +79078,11 @@
7846479078
if( pA->iTable!=pB->iTable || pA->iColumn!=pB->iColumn ) return 2;
7846579079
if( ExprHasProperty(pA, EP_IntValue) ){
7846679080
if( !ExprHasProperty(pB, EP_IntValue) || pA->u.iValue!=pB->u.iValue ){
7846779081
return 2;
7846879082
}
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){
7847079084
if( ExprHasProperty(pB, EP_IntValue) || NEVER(pB->u.zToken==0) ) return 2;
7847179085
if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){
7847279086
return 2;
7847379087
}
7847479088
}
@@ -78651,11 +79265,13 @@
7865179265
} /* end loop over pSrcList */
7865279266
}
7865379267
return WRC_Prune;
7865479268
}
7865579269
case TK_AGG_FUNCTION: {
78656
- if( !sqlite3FunctionUsesOtherSrc(pExpr, pSrcList) ){
79270
+ if( (pNC->ncFlags & NC_InAggFunc)==0
79271
+ && !sqlite3FunctionUsesOtherSrc(pExpr, pSrcList)
79272
+ ){
7865779273
/* Check to see if pExpr is a duplicate of another aggregate
7865879274
** function that is already in the pAggInfo structure
7865979275
*/
7866079276
struct AggInfo_func *pItem = pAggInfo->aFunc;
7866179277
for(i=0; i<pAggInfo->nFunc; i++, pItem++){
@@ -78688,12 +79304,12 @@
7868879304
*/
7868979305
assert( !ExprHasAnyProperty(pExpr, EP_TokenOnly|EP_Reduced) );
7869079306
ExprSetIrreducible(pExpr);
7869179307
pExpr->iAgg = (i16)i;
7869279308
pExpr->pAggInfo = pAggInfo;
78693
- return WRC_Prune;
7869479309
}
79310
+ return WRC_Prune;
7869579311
}
7869679312
}
7869779313
return WRC_Continue;
7869879314
}
7869979315
static int analyzeAggregatesInSelect(Walker *pWalker, Select *pSelect){
@@ -80973,11 +81589,11 @@
8097381589
if( db->aDb[iDb].pBt ){
8097481590
sqlite3BtreeClose(db->aDb[iDb].pBt);
8097581591
db->aDb[iDb].pBt = 0;
8097681592
db->aDb[iDb].pSchema = 0;
8097781593
}
80978
- sqlite3ResetInternalSchema(db, -1);
81594
+ sqlite3ResetAllSchemasOfConnection(db);
8097981595
db->nDb = iDb;
8098081596
if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){
8098181597
db->mallocFailed = 1;
8098281598
sqlite3DbFree(db, zErrDyn);
8098381599
zErrDyn = sqlite3MPrintf(db, "out of memory");
@@ -81045,11 +81661,11 @@
8104581661
}
8104681662
8104781663
sqlite3BtreeClose(pDb->pBt);
8104881664
pDb->pBt = 0;
8104981665
pDb->pSchema = 0;
81050
- sqlite3ResetInternalSchema(db, -1);
81666
+ sqlite3ResetAllSchemasOfConnection(db);
8105181667
return;
8105281668
8105381669
detach_error:
8105481670
sqlite3_result_error(context, zErr, -1);
8105581671
}
@@ -81961,62 +82577,19 @@
8196182577
}
8196282578
db->flags |= SQLITE_InternChanges;
8196382579
}
8196482580
8196582581
/*
81966
-** Erase all schema information from the in-memory hash tables of
81967
-** a single database. This routine is called to reclaim memory
81968
-** before the database closes. It is also called during a rollback
81969
-** if there were schema changes during the transaction or if a
81970
-** schema-cookie mismatch occurs.
82582
+** Look through the list of open database files in db->aDb[] and if
82583
+** any have been closed, remove them from the list. Reallocate the
82584
+** db->aDb[] structure to a smaller size, if possible.
8197182585
**
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.
81975
-*/
81976
-SQLITE_PRIVATE void sqlite3ResetInternalSchema(sqlite3 *db, int iDb){
81977
- 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
- */
82586
+** Entry 0 (the "main" database) and entry 1 (the "temp" database)
82587
+** are never candidates for being collapsed.
82588
+*/
82589
+SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3 *db){
82590
+ int i, j;
8201882591
for(i=j=2; i<db->nDb; i++){
8201982592
struct Db *pDb = &db->aDb[i];
8202082593
if( pDb->pBt==0 ){
8202182594
sqlite3DbFree(db, pDb->zName);
8202282595
pDb->zName = 0;
@@ -82033,10 +82606,55 @@
8203382606
memcpy(db->aDbStatic, db->aDb, 2*sizeof(db->aDb[0]));
8203482607
sqlite3DbFree(db, db->aDb);
8203582608
db->aDb = db->aDbStatic;
8203682609
}
8203782610
}
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
+}
8203882656
8203982657
/*
8204082658
** This routine is called when a commit occurs.
8204182659
*/
8204282660
SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3 *db){
@@ -82069,19 +82687,32 @@
8206982687
**
8207082688
** This routine just deletes the data structure. It does not unlink
8207182689
** the table data structure from the hash table. But it does destroy
8207282690
** memory structures of the indices and foreign keys associated with
8207382691
** 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.
8207482698
*/
8207582699
SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
8207682700
Index *pIndex, *pNext;
82701
+ TESTONLY( int nLookaside; ) /* Used to verify lookaside not used for schema */
8207782702
8207882703
assert( !pTable || pTable->nRef>0 );
8207982704
8208082705
/* Do not delete the table until the reference count reaches zero. */
8208182706
if( !pTable ) return;
8208282707
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 );
8208382714
8208482715
/* Delete all indices associated with this table. */
8208582716
for(pIndex = pTable->pIndex; pIndex; pIndex=pNext){
8208682717
pNext = pIndex->pNext;
8208782718
assert( pIndex->pSchema==pTable->pSchema );
@@ -82110,10 +82741,13 @@
8211082741
#endif
8211182742
#ifndef SQLITE_OMIT_VIRTUALTABLE
8211282743
sqlite3VtabClear(db, pTable);
8211382744
#endif
8211482745
sqlite3DbFree(db, pTable);
82746
+
82747
+ /* Verify that no lookaside memory was used by schema tables */
82748
+ assert( nLookaside==0 || nLookaside==db->lookaside.nOut );
8211582749
}
8211682750
8211782751
/*
8211882752
** Unlink the given table from the hash tables and the delete the
8211982753
** table structure with all its indices and foreign keys.
@@ -83058,11 +83692,11 @@
8305883692
sSrc.a[0].zName = p->zName;
8305983693
sSrc.a[0].pTab = p;
8306083694
sSrc.a[0].iCursor = -1;
8306183695
sNC.pParse = pParse;
8306283696
sNC.pSrcList = &sSrc;
83063
- sNC.isCheck = 1;
83697
+ sNC.ncFlags = NC_IsCheck;
8306483698
pList = p->pCheck;
8306583699
for(i=0; i<pList->nExpr; i++){
8306683700
if( sqlite3ResolveExprNames(&sNC, pList->a[i].pExpr) ){
8306783701
return;
8306883702
}
@@ -84314,11 +84948,11 @@
8431484948
zExtra += nColl;
8431584949
nExtra -= nColl;
8431684950
}else{
8431784951
zColl = pTab->aCol[j].zColl;
8431884952
if( !zColl ){
84319
- zColl = db->pDfltColl->zName;
84953
+ zColl = "BINARY";
8432084954
}
8432184955
}
8432284956
if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
8432384957
goto exit_create_index;
8432484958
}
@@ -92589,11 +93223,11 @@
9258993223
"from within a transaction");
9259093224
return SQLITE_ERROR;
9259193225
}
9259293226
sqlite3BtreeClose(db->aDb[1].pBt);
9259393227
db->aDb[1].pBt = 0;
92594
- sqlite3ResetInternalSchema(db, -1);
93228
+ sqlite3ResetAllSchemasOfConnection(db);
9259593229
}
9259693230
return SQLITE_OK;
9259793231
}
9259893232
#endif /* SQLITE_PAGER_PRAGMAS */
9259993233
@@ -93274,10 +93908,54 @@
9327493908
sqlite3_temp_directory = 0;
9327593909
}
9327693910
#endif /* SQLITE_OMIT_WSD */
9327793911
}
9327893912
}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
9327993957
9328093958
#if !defined(SQLITE_ENABLE_LOCKING_STYLE)
9328193959
# if defined(__APPLE__)
9328293960
# define SQLITE_ENABLE_LOCKING_STYLE 1
9328393961
# else
@@ -94307,11 +94985,10 @@
9430794985
u8 encoding;
9430894986
/* If opening the main database, set ENC(db). */
9430994987
encoding = (u8)meta[BTREE_TEXT_ENCODING-1] & 3;
9431094988
if( encoding==0 ) encoding = SQLITE_UTF8;
9431194989
ENC(db) = encoding;
94312
- db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 0);
9431394990
}else{
9431494991
/* If opening an attached database, the encoding much match ENC(db) */
9431594992
if( meta[BTREE_TEXT_ENCODING-1]!=ENC(db) ){
9431694993
sqlite3SetString(pzErrMsg, db, "attached databases must use the same"
9431794994
" text encoding as main database");
@@ -94387,11 +95064,11 @@
9438795064
}
9438895065
#endif
9438995066
}
9439095067
if( db->mallocFailed ){
9439195068
rc = SQLITE_NOMEM;
94392
- sqlite3ResetInternalSchema(db, -1);
95069
+ sqlite3ResetAllSchemasOfConnection(db);
9439395070
}
9439495071
if( rc==SQLITE_OK || (db->flags&SQLITE_RecoveryMode)){
9439595072
/* Black magic: If the SQLITE_RecoveryMode flag is set, then consider
9439695073
** the schema loaded, even if errors occurred. In this situation the
9439795074
** current sqlite3_prepare() operation will fail, but the following one
@@ -94440,11 +95117,11 @@
9444095117
db->init.busy = 1;
9444195118
for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
9444295119
if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue;
9444395120
rc = sqlite3InitOne(db, i, pzErrMsg);
9444495121
if( rc ){
94445
- sqlite3ResetInternalSchema(db, i);
95122
+ sqlite3ResetOneSchema(db, i);
9444695123
}
9444795124
}
9444895125
9444995126
/* Once all the other databases have been initialised, load the schema
9445095127
** for the TEMP database. This is loaded last, as the TEMP database
@@ -94453,11 +95130,11 @@
9445395130
#ifndef SQLITE_OMIT_TEMPDB
9445495131
if( rc==SQLITE_OK && ALWAYS(db->nDb>1)
9445595132
&& !DbHasProperty(db, 1, DB_SchemaLoaded) ){
9445695133
rc = sqlite3InitOne(db, 1, pzErrMsg);
9445795134
if( rc ){
94458
- sqlite3ResetInternalSchema(db, 1);
95135
+ sqlite3ResetOneSchema(db, 1);
9445995136
}
9446095137
}
9446195138
#endif
9446295139
9446395140
db->init.busy = 0;
@@ -94521,11 +95198,11 @@
9452195198
** value stored as part of the in-memory schema representation,
9452295199
** set Parse.rc to SQLITE_SCHEMA. */
9452395200
sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&cookie);
9452495201
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
9452595202
if( cookie!=db->aDb[iDb].pSchema->schema_cookie ){
94526
- sqlite3ResetInternalSchema(db, iDb);
95203
+ sqlite3ResetOneSchema(db, iDb);
9452795204
pParse->rc = SQLITE_SCHEMA;
9452895205
}
9452995206
9453095207
/* Close the transaction, if one was opened. */
9453195208
if( openedTransaction ){
@@ -94751,10 +95428,11 @@
9475195428
sqlite3_finalize(*ppStmt);
9475295429
rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail);
9475395430
}
9475495431
sqlite3BtreeLeaveAll(db);
9475595432
sqlite3_mutex_leave(db->mutex);
95433
+ assert( rc==SQLITE_OK || *ppStmt==0 );
9475695434
return rc;
9475795435
}
9475895436
9475995437
/*
9476095438
** Rerun the compilation of a statement after a schema change.
@@ -98058,10 +98736,11 @@
9805898736
pExpr = p->pEList->a[0].pExpr;
9805998737
assert( pTab && !pTab->pSelect && pExpr );
9806098738
9806198739
if( IsVirtual(pTab) ) return 0;
9806298740
if( pExpr->op!=TK_AGG_FUNCTION ) return 0;
98741
+ if( pAggInfo->nFunc==0 ) return 0;
9806398742
if( (pAggInfo->aFunc[0].pFunc->flags&SQLITE_FUNC_COUNT)==0 ) return 0;
9806498743
if( pExpr->flags&EP_Distinct ) return 0;
9806598744
9806698745
return pTab;
9806798746
}
@@ -99048,11 +99727,13 @@
9904899727
sqlite3ExprAnalyzeAggregates(&sNC, pHaving);
9904999728
}
9905099729
sAggInfo.nAccumulator = sAggInfo.nColumn;
9905199730
for(i=0; i<sAggInfo.nFunc; i++){
9905299731
assert( !ExprHasProperty(sAggInfo.aFunc[i].pExpr, EP_xIsSelect) );
99732
+ sNC.ncFlags |= NC_InAggFunc;
9905399733
sqlite3ExprAnalyzeAggList(&sNC, sAggInfo.aFunc[i].pExpr->x.pList);
99734
+ sNC.ncFlags &= ~NC_InAggFunc;
9905499735
}
9905599736
if( db->mallocFailed ) goto select_end;
9905699737
9905799738
/* Processing for aggregates with GROUP BY is very different and
9905899739
** much more complex than aggregates without a GROUP BY.
@@ -101870,11 +102551,11 @@
101870102551
pDb->pSchema = 0;
101871102552
}
101872102553
101873102554
/* This both clears the schemas and reduces the size of the db->aDb[]
101874102555
** array. */
101875
- sqlite3ResetInternalSchema(db, -1);
102556
+ sqlite3ResetAllSchemasOfConnection(db);
101876102557
101877102558
return rc;
101878102559
}
101879102560
101880102561
#endif /* SQLITE_OMIT_VACUUM && SQLITE_OMIT_ATTACH */
@@ -101902,12 +102583,12 @@
101902102583
** this struct allocated on the stack. It is used by the implementation of
101903102584
** the sqlite3_declare_vtab() and sqlite3_vtab_config() APIs, both of which
101904102585
** are invoked only from within xCreate and xConnect methods.
101905102586
*/
101906102587
struct VtabCtx {
101907
- Table *pTab;
101908
- VTable *pVTable;
102588
+ VTable *pVTable; /* The virtual table being constructed */
102589
+ Table *pTab; /* The Table object to which the virtual table belongs */
101909102590
};
101910102591
101911102592
/*
101912102593
** The actual function that does the work of creating a new module.
101913102594
** This function implements the sqlite3_create_module() and
@@ -101918,37 +102599,39 @@
101918102599
const char *zName, /* Name assigned to this module */
101919102600
const sqlite3_module *pModule, /* The definition of the module */
101920102601
void *pAux, /* Context pointer for xCreate/xConnect */
101921102602
void (*xDestroy)(void *) /* Module destructor function */
101922102603
){
101923
- int rc, nName;
101924
- Module *pMod;
102604
+ int rc = SQLITE_OK;
102605
+ int nName;
101925102606
101926102607
sqlite3_mutex_enter(db->mutex);
101927102608
nName = sqlite3Strlen30(zName);
101928
- pMod = (Module *)sqlite3DbMallocRaw(db, sizeof(Module) + nName + 1);
101929
- if( pMod ){
101930
- Module *pDel;
101931
- char *zCopy = (char *)(&pMod[1]);
101932
- memcpy(zCopy, zName, nName+1);
101933
- pMod->zName = zCopy;
101934
- pMod->pModule = pModule;
101935
- pMod->pAux = pAux;
101936
- pMod->xDestroy = xDestroy;
101937
- 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);
101943
- if( pDel==pMod ){
101944
- db->mallocFailed = 1;
101945
- }
101946
- }else if( xDestroy ){
101947
- xDestroy(pAux);
101948
- }
101949
- rc = sqlite3ApiExit(db, SQLITE_OK);
102609
+ if( sqlite3HashFind(&db->aModule, zName, nName) ){
102610
+ rc = SQLITE_MISUSE_BKPT;
102611
+ }else{
102612
+ Module *pMod;
102613
+ pMod = (Module *)sqlite3DbMallocRaw(db, sizeof(Module) + nName + 1);
102614
+ if( pMod ){
102615
+ Module *pDel;
102616
+ char *zCopy = (char *)(&pMod[1]);
102617
+ memcpy(zCopy, zName, nName+1);
102618
+ pMod->zName = zCopy;
102619
+ pMod->pModule = pModule;
102620
+ pMod->pAux = pAux;
102621
+ pMod->xDestroy = xDestroy;
102622
+ pDel = (Module *)sqlite3HashInsert(&db->aModule,zCopy,nName,(void*)pMod);
102623
+ assert( pDel==0 || pDel==pMod );
102624
+ if( pDel ){
102625
+ db->mallocFailed = 1;
102626
+ sqlite3DbFree(db, pDel);
102627
+ }
102628
+ }
102629
+ }
102630
+ rc = sqlite3ApiExit(db, rc);
102631
+ if( rc!=SQLITE_OK && xDestroy ) xDestroy(pAux);
102632
+
101950102633
sqlite3_mutex_leave(db->mutex);
101951102634
return rc;
101952102635
}
101953102636
101954102637
@@ -102059,10 +102742,35 @@
102059102742
}
102060102743
102061102744
assert( !db || pRet );
102062102745
return pRet;
102063102746
}
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
+}
102064102772
102065102773
102066102774
/*
102067102775
** Disconnect all the virtual table objects in the sqlite3.pDisconnect list.
102068102776
**
@@ -112949,10 +113657,19 @@
112949113657
**
112950113658
** See also the "PRAGMA temp_store_directory" SQL command.
112951113659
*/
112952113660
SQLITE_API char *sqlite3_temp_directory = 0;
112953113661
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
+
112954113671
/*
112955113672
** Initialize SQLite.
112956113673
**
112957113674
** This routine must be called to initialize the memory allocation,
112958113675
** VFS, and mutex subsystems prior to doing any serious work with
@@ -113147,10 +113864,22 @@
113147113864
sqlite3GlobalConfig.isPCacheInit = 0;
113148113865
}
113149113866
if( sqlite3GlobalConfig.isMallocInit ){
113150113867
sqlite3MallocEnd();
113151113868
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
113152113881
}
113153113882
if( sqlite3GlobalConfig.isMutexInit ){
113154113883
sqlite3MutexEnd();
113155113884
sqlite3GlobalConfig.isMutexInit = 0;
113156113885
}
@@ -113594,10 +114323,34 @@
113594114323
pDestructor->xDestroy(pDestructor->pUserData);
113595114324
sqlite3DbFree(db, pDestructor);
113596114325
}
113597114326
}
113598114327
}
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
+}
113599114352
113600114353
/*
113601114354
** Close an existing SQLite database
113602114355
*/
113603114356
SQLITE_API int sqlite3_close(sqlite3 *db){
@@ -113610,14 +114363,14 @@
113610114363
if( !sqlite3SafetyCheckSickOrOk(db) ){
113611114364
return SQLITE_MISUSE_BKPT;
113612114365
}
113613114366
sqlite3_mutex_enter(db->mutex);
113614114367
113615
- /* Force xDestroy calls on all virtual tables */
113616
- sqlite3ResetInternalSchema(db, -1);
114368
+ /* Force xDisconnect calls on all virtual tables */
114369
+ disconnectAllVtab(db);
113617114370
113618
- /* If a transaction is open, the ResetInternalSchema() call above
114371
+ /* If a transaction is open, the disconnectAllVtab() call above
113619114372
** will not have called the xDisconnect() method on any virtual
113620114373
** tables in the db->aVTrans[] array. The following sqlite3VtabRollback()
113621114374
** call will do so. We need to do this before the check for active
113622114375
** SQL statements below, as the v-table implementation may be storing
113623114376
** some prepared statements internally.
@@ -113644,10 +114397,11 @@
113644114397
}
113645114398
113646114399
/* Free any outstanding Savepoint structures. */
113647114400
sqlite3CloseSavepoints(db);
113648114401
114402
+ /* Close all database connections */
113649114403
for(j=0; j<db->nDb; j++){
113650114404
struct Db *pDb = &db->aDb[j];
113651114405
if( pDb->pBt ){
113652114406
sqlite3BtreeClose(pDb->pBt);
113653114407
pDb->pBt = 0;
@@ -113654,19 +114408,26 @@
113654114408
if( j!=1 ){
113655114409
pDb->pSchema = 0;
113656114410
}
113657114411
}
113658114412
}
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 );
113660114423
113661114424
/* Tell the code in notify.c that the connection no longer holds any
113662114425
** locks and does not require any further unlock-notify callbacks.
113663114426
*/
113664114427
sqlite3ConnectionClosed(db);
113665114428
113666
- assert( db->nDb<=2 );
113667
- assert( db->aDb==db->aDbStatic );
113668114429
for(j=0; j<ArraySize(db->aFunc.a); j++){
113669114430
FuncDef *pNext, *pHash, *p;
113670114431
for(p=db->aFunc.a[j]; p; p=pHash){
113671114432
pHash = p->pHash;
113672114433
while( p ){
@@ -113749,11 +114510,11 @@
113749114510
sqlite3VtabRollback(db);
113750114511
sqlite3EndBenignMalloc();
113751114512
113752114513
if( db->flags&SQLITE_InternChanges ){
113753114514
sqlite3ExpirePreparedStatements(db);
113754
- sqlite3ResetInternalSchema(db, -1);
114515
+ sqlite3ResetAllSchemasOfConnection(db);
113755114516
}
113756114517
113757114518
/* Any deferred constraint violations have now been resolved. */
113758114519
db->nDeferredCons = 0;
113759114520
@@ -114887,14 +115648,18 @@
114887115648
if( nOpt==4 && memcmp("mode", zOpt, 4)==0 ){
114888115649
static struct OpenMode aOpenMode[] = {
114889115650
{ "ro", SQLITE_OPEN_READONLY },
114890115651
{ "rw", SQLITE_OPEN_READWRITE },
114891115652
{ "rwc", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE },
115653
+ { "memory",
115654
+ SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE
115655
+ | SQLITE_OPEN_MEMORY },
114892115656
{ 0, 0 }
114893115657
};
114894115658
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;
114896115661
aMode = aOpenMode;
114897115662
limit = mask & flags;
114898115663
zModeType = "access";
114899115664
}
114900115665
@@ -114911,11 +115676,11 @@
114911115676
if( mode==0 ){
114912115677
*pzErrMsg = sqlite3_mprintf("no such %s mode: %s", zModeType, zVal);
114913115678
rc = SQLITE_ERROR;
114914115679
goto parse_uri_out;
114915115680
}
114916
- if( mode>limit ){
115681
+ if( (mode & ~SQLITE_OPEN_MEMORY)>limit ){
114917115682
*pzErrMsg = sqlite3_mprintf("%s mode not allowed: %s",
114918115683
zModeType, zVal);
114919115684
rc = SQLITE_PERM;
114920115685
goto parse_uri_out;
114921115686
}
@@ -114930,10 +115695,11 @@
114930115695
zFile = sqlite3_malloc(nUri+2);
114931115696
if( !zFile ) return SQLITE_NOMEM;
114932115697
memcpy(zFile, zUri, nUri);
114933115698
zFile[nUri] = '\0';
114934115699
zFile[nUri+1] = '\0';
115700
+ flags &= ~SQLITE_OPEN_URI;
114935115701
}
114936115702
114937115703
*ppVfs = sqlite3_vfs_find(zVfs);
114938115704
if( *ppVfs==0 ){
114939115705
*pzErrMsg = sqlite3_mprintf("no such vfs: %s", zVfs);
@@ -117374,10 +118140,17 @@
117374118140
SQLITE_PRIVATE int sqlite3Fts3EvalPhrasePoslist(Fts3Cursor *, Fts3Expr *, int iCol, char **);
117375118141
SQLITE_PRIVATE int sqlite3Fts3MsrOvfl(Fts3Cursor *, Fts3MultiSegReader *, int *);
117376118142
SQLITE_PRIVATE int sqlite3Fts3MsrIncrRestart(Fts3MultiSegReader *pCsr);
117377118143
117378118144
SQLITE_PRIVATE int sqlite3Fts3DeferredTokenList(Fts3DeferredToken *, char **, int *);
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
117379118152
117380118153
#endif /* !SQLITE_CORE || SQLITE_ENABLE_FTS3 */
117381118154
#endif /* _FTSINT_H */
117382118155
117383118156
/************** End of fts3Int.h *********************************************/
@@ -120643,10 +121416,13 @@
120643121416
** to by the argument to point to the "simple" tokenizer implementation.
120644121417
** And so on.
120645121418
*/
120646121419
SQLITE_PRIVATE void sqlite3Fts3SimpleTokenizerModule(sqlite3_tokenizer_module const**ppModule);
120647121420
SQLITE_PRIVATE void sqlite3Fts3PorterTokenizerModule(sqlite3_tokenizer_module const**ppModule);
121421
+#ifdef SQLITE_ENABLE_FTS4_UNICODE61
121422
+SQLITE_PRIVATE void sqlite3Fts3UnicodeTokenizer(sqlite3_tokenizer_module const**ppModule);
121423
+#endif
120648121424
#ifdef SQLITE_ENABLE_ICU
120649121425
SQLITE_PRIVATE void sqlite3Fts3IcuTokenizerModule(sqlite3_tokenizer_module const**ppModule);
120650121426
#endif
120651121427
120652121428
/*
@@ -120658,15 +121434,22 @@
120658121434
SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){
120659121435
int rc = SQLITE_OK;
120660121436
Fts3Hash *pHash = 0;
120661121437
const sqlite3_tokenizer_module *pSimple = 0;
120662121438
const sqlite3_tokenizer_module *pPorter = 0;
121439
+#ifdef SQLITE_ENABLE_FTS4_UNICODE61
121440
+ const sqlite3_tokenizer_module *pUnicode = 0;
121441
+#endif
120663121442
120664121443
#ifdef SQLITE_ENABLE_ICU
120665121444
const sqlite3_tokenizer_module *pIcu = 0;
120666121445
sqlite3Fts3IcuTokenizerModule(&pIcu);
120667121446
#endif
121447
+
121448
+#ifdef SQLITE_ENABLE_FTS4_UNICODE61
121449
+ sqlite3Fts3UnicodeTokenizer(&pUnicode);
121450
+#endif
120668121451
120669121452
#ifdef SQLITE_TEST
120670121453
rc = sqlite3Fts3InitTerm(db);
120671121454
if( rc!=SQLITE_OK ) return rc;
120672121455
#endif
@@ -120687,10 +121470,14 @@
120687121470
120688121471
/* Load the built-in tokenizers into the hash table */
120689121472
if( rc==SQLITE_OK ){
120690121473
if( sqlite3Fts3HashInsert(pHash, "simple", 7, (void *)pSimple)
120691121474
|| sqlite3Fts3HashInsert(pHash, "porter", 7, (void *)pPorter)
121475
+
121476
+#ifdef SQLITE_ENABLE_FTS4_UNICODE61
121477
+ || sqlite3Fts3HashInsert(pHash, "unicode61", 10, (void *)pUnicode)
121478
+#endif
120692121479
#ifdef SQLITE_ENABLE_ICU
120693121480
|| (pIcu && sqlite3Fts3HashInsert(pHash, "icu", 4, (void *)pIcu))
120694121481
#endif
120695121482
){
120696121483
rc = SQLITE_NOMEM;
@@ -128839,11 +129626,16 @@
128839129626
sqlite3_column_blob(pStmt, 0),
128840129627
sqlite3_column_bytes(pStmt, 0));
128841129628
}else{
128842129629
memset(a, 0, sizeof(u32)*(nStat) );
128843129630
}
128844
- sqlite3_reset(pStmt);
129631
+ rc = sqlite3_reset(pStmt);
129632
+ if( rc!=SQLITE_OK ){
129633
+ sqlite3_free(a);
129634
+ *pRC = rc;
129635
+ return;
129636
+ }
128845129637
if( nChng<0 && a[0]<(u32)(-nChng) ){
128846129638
a[0] = 0;
128847129639
}else{
128848129640
a[0] += nChng;
128849129641
}
@@ -132562,10 +133354,655 @@
132562133354
}
132563133355
132564133356
#endif
132565133357
132566133358
/************** 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 **ppModule){
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 ***************************************/
132567134004
/************** Begin file rtree.c *******************************************/
132568134005
/*
132569134006
** 2001 September 15
132570134007
**
132571134008
** The author disclaims copyright to this source code. In place of
@@ -135301,10 +136738,40 @@
135301136738
nodeRelease(pRtree, pRoot);
135302136739
}
135303136740
135304136741
return rc;
135305136742
}
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
+
135306136773
135307136774
/*
135308136775
** The xUpdate method for rtree module virtual tables.
135309136776
*/
135310136777
static int rtreeUpdate(
@@ -135338,12 +136805,12 @@
135338136805
/* Populate the cell.aCoord[] array. The first coordinate is azData[3]. */
135339136806
assert( nData==(pRtree->nDim*2 + 3) );
135340136807
#ifndef SQLITE_RTREE_INT_ONLY
135341136808
if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
135342136809
for(ii=0; ii<(pRtree->nDim*2); ii+=2){
135343
- cell.aCoord[ii].f = (RtreeValue)sqlite3_value_double(azData[ii+3]);
135344
- cell.aCoord[ii+1].f = (RtreeValue)sqlite3_value_double(azData[ii+4]);
136810
+ cell.aCoord[ii].f = rtreeValueDown(azData[ii+3]);
136811
+ cell.aCoord[ii+1].f = rtreeValueUp(azData[ii+4]);
135345136812
if( cell.aCoord[ii].f>cell.aCoord[ii+1].f ){
135346136813
rc = SQLITE_CONSTRAINT;
135347136814
goto constraint;
135348136815
}
135349136816
}
135350136817
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
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
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
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
8 ** translation unit.
@@ -441,18 +441,25 @@
441 #if defined(SQLITE_TCL) || defined(TCLSH)
442 # include <tcl.h>
443 #endif
444
445 /*
446 ** Many people are failing to set -DNDEBUG=1 when compiling SQLite.
447 ** Setting NDEBUG makes the code smaller and run faster. So the following
448 ** lines are added to automatically set NDEBUG unless the -DSQLITE_DEBUG=1
449 ** option is set. Thus NDEBUG becomes an opt-in rather than an opt-out
 
 
 
 
450 ** feature.
451 */
452 #if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
453 # define NDEBUG 1
 
 
 
454 #endif
455
456 /*
457 ** The testcase() macro is used to aid in coverage testing. When
458 ** doing coverage testing, the condition inside the argument to
@@ -655,13 +662,13 @@
655 **
656 ** See also: [sqlite3_libversion()],
657 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
658 ** [sqlite_version()] and [sqlite_source_id()].
659 */
660 #define SQLITE_VERSION "3.7.12"
661 #define SQLITE_VERSION_NUMBER 3007012
662 #define SQLITE_SOURCE_ID "2012-05-12 18:29:53 e536ac041815b118c461ceee798f9b7283269f58"
663
664 /*
665 ** CAPI3REF: Run-Time Library Version Numbers
666 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
667 **
@@ -1026,10 +1033,11 @@
1026 #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
1027 #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
1028 #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */
1029 #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */
1030 #define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */
 
1031 #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */
1032 #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */
1033 #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */
1034 #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */
1035 #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */
@@ -1320,11 +1328,11 @@
1320 ** into the array entry, allowing the current retry settings to be
1321 ** interrogated. The zDbName parameter is ignored.
1322 **
1323 ** <li>[[SQLITE_FCNTL_PERSIST_WAL]]
1324 ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the
1325 ** persistent [WAL | Write AHead Log] setting. By default, the auxiliary
1326 ** write ahead log and shared memory files used for transaction control
1327 ** are automatically deleted when the latest connection to the database
1328 ** closes. Setting persistent WAL mode causes those files to persist after
1329 ** close. Persisting the files is useful when other processes that do not
1330 ** have write permission on the directory containing the database file want
@@ -2717,16 +2725,16 @@
2717 ** 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
2719 ** implementation of these routines to be omitted. That capability
2720 ** is no longer provided. Only built-in memory allocators can be used.
2721 **
2722 ** The Windows OS interface layer calls
2723 ** the system malloc() and free() directly when converting
2724 ** filenames between the UTF-8 encoding used by SQLite
2725 ** and whatever filename encoding is used by the particular Windows
2726 ** installation. Memory allocation errors are detected, but
2727 ** they are reported back as [SQLITE_CANTOPEN] or
2728 ** [SQLITE_IOERR] rather than [SQLITE_NOMEM].
2729 **
2730 ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
2731 ** must be either NULL or else pointers obtained from a prior
2732 ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
@@ -3123,22 +3131,24 @@
3123 ** 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
3125 ** present, then the VFS specified by the option takes precedence over
3126 ** the value passed as the fourth parameter to sqlite3_open_v2().
3127 **
3128 ** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw" or
3129 ** "rwc". Attempting to set it to any other value is an error)^.
 
3130 ** ^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
3132 ** 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)
3134 ** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had
3135 ** been set. ^Value "rwc" is equivalent to setting both
3136 ** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If sqlite3_open_v2() is
3137 ** used, it is an error to specify a value for the mode parameter that is
3138 ** less restrictive than that specified by the flags passed as the third
3139 ** parameter.
 
3140 **
3141 ** <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
3143 ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
3144 ** sqlite3_open_v2(). ^Setting the cache parameter to "private" is
@@ -4997,10 +5007,46 @@
4997 ** 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.
4999 */
5000 SQLITE_API char *sqlite3_temp_directory;
5001
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5002 /*
5003 ** CAPI3REF: Test For Auto-Commit Mode
5004 ** KEYWORDS: {autocommit mode}
5005 **
5006 ** ^The sqlite3_get_autocommit() interface returns non-zero or
@@ -5175,11 +5221,10 @@
5175 void*
5176 );
5177
5178 /*
5179 ** CAPI3REF: Enable Or Disable Shared Pager Cache
5180 ** KEYWORDS: {shared cache}
5181 **
5182 ** ^(This routine enables or disables the sharing of the database cache
5183 ** and schema data structures between [database connection | connections]
5184 ** to the same database. Sharing is enabled if the argument is true
5185 ** and disabled if the argument is false.)^
@@ -9014,11 +9059,11 @@
9014
9015 /* Functions used to query pager state and configuration. */
9016 SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*);
9017 SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
9018 SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*);
9019 SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*);
9020 SQLITE_PRIVATE const sqlite3_vfs *sqlite3PagerVfs(Pager*);
9021 SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*);
9022 SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*);
9023 SQLITE_PRIVATE int sqlite3PagerNosync(Pager*);
9024 SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*);
@@ -9284,17 +9329,15 @@
9284 # ifndef SQLITE_OS_WIN
9285 # define SQLITE_OS_WIN 0
9286 # endif
9287 #endif
9288
9289 /*
9290 ** Define the maximum size of a temporary filename
9291 */
9292 #if SQLITE_OS_WIN
9293 # include <windows.h>
9294 # define SQLITE_TEMPNAME_SIZE (MAX_PATH+50)
9295 #elif SQLITE_OS_OS2
 
9296 # if (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 3) && defined(OS2_HIGH_MEMORY)
9297 # include <os2safe.h> /* has to be included before os2.h for linking to work */
9298 # endif
9299 # define INCL_DOSDATETIME
9300 # define INCL_DOSFILEMGR
@@ -9303,13 +9346,10 @@
9303 # define INCL_DOSPROCESS
9304 # define INCL_DOSMODULEMGR
9305 # define INCL_DOSSEMAPHORES
9306 # include <os2.h>
9307 # include <uconv.h>
9308 # define SQLITE_TEMPNAME_SIZE (CCHMAXPATHCOMP)
9309 #else
9310 # define SQLITE_TEMPNAME_SIZE 200
9311 #endif
9312
9313 /*
9314 ** Determine if we are dealing with Windows NT.
9315 **
@@ -9339,10 +9379,26 @@
9339 # define SQLITE_OS_WINCE 1
9340 #else
9341 # define SQLITE_OS_WINCE 0
9342 #endif
9343
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9344 /* If the SET_FULLSYNC macro is not defined above, then make it
9345 ** a no-op
9346 */
9347 #ifndef SET_FULLSYNC
9348 # define SET_FULLSYNC(x,y)
@@ -10933,19 +10989,25 @@
10933 */
10934 struct NameContext {
10935 Parse *pParse; /* The parser */
10936 SrcList *pSrcList; /* One or more tables used to resolve names */
10937 ExprList *pEList; /* Optional list of named expressions */
 
 
10938 int nRef; /* Number of names resolved by this context */
10939 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 */
10943 AggInfo *pAggInfo; /* Information about aggregates at this level */
10944 NameContext *pNext; /* Next outer name context. NULL for outermost */
10945 };
10946
 
 
 
 
 
 
 
 
10947 /*
10948 ** An instance of the following structure contains all information
10949 ** needed to generate code for a single SELECT statement.
10950 **
10951 ** nLimit is set to -1 if there is no LIMIT clause. nOffset is set to 0.
@@ -11623,11 +11685,13 @@
11623 SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,ExprSpan*);
11624 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*);
11625 SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**);
11626 SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**);
11627 SQLITE_PRIVATE void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
11628 SQLITE_PRIVATE void sqlite3ResetInternalSchema(sqlite3*, int);
 
 
11629 SQLITE_PRIVATE void sqlite3BeginParse(Parse*,int);
11630 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3*);
11631 SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*);
11632 SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *, int);
11633 SQLITE_PRIVATE void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int);
@@ -12028,10 +12092,11 @@
12028 # define sqlite3VtabUnlockList(X)
12029 # define sqlite3VtabSavepoint(X, Y, Z) SQLITE_OK
12030 # define sqlite3GetVTable(X,Y) ((VTable*)0)
12031 #else
12032 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*);
 
12033 SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **);
12034 SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db);
12035 SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db);
12036 SQLITE_PRIVATE void sqlite3VtabLock(VTable *);
12037 SQLITE_PRIVATE void sqlite3VtabUnlock(VTable *);
@@ -12481,10 +12546,13 @@
12481 #ifdef SQLITE_CHECK_PAGES
12482 "CHECK_PAGES",
12483 #endif
12484 #ifdef SQLITE_COVERAGE_TEST
12485 "COVERAGE_TEST",
 
 
 
12486 #endif
12487 #ifdef SQLITE_DEBUG
12488 "DEBUG",
12489 #endif
12490 #ifdef SQLITE_DEFAULT_LOCKING_MODE
@@ -18335,11 +18403,11 @@
18335 ** _WIN32_WINNT defined to a value >= 0x0400. Currently, the only
18336 ** call to TryEnterCriticalSection() is #ifdef'ed out, so #ifdef
18337 ** this out as well.
18338 */
18339 #if 0
18340 #if SQLITE_OS_WINCE
18341 # define mutexIsNT() (1)
18342 #else
18343 static int mutexIsNT(void){
18344 static int osType = 0;
18345 if( osType==0 ){
@@ -18388,22 +18456,28 @@
18388 ** processing, the "interlocked" magic is probably not
18389 ** strictly necessary.
18390 */
18391 static long winMutex_lock = 0;
18392
 
 
18393 static int winMutexInit(void){
18394 /* The first to increment to 1 does actual initialization */
18395 if( InterlockedCompareExchange(&winMutex_lock, 1, 0)==0 ){
18396 int i;
18397 for(i=0; i<ArraySize(winMutex_staticMutexes); i++){
 
 
 
18398 InitializeCriticalSection(&winMutex_staticMutexes[i].mutex);
 
18399 }
18400 winMutex_isInit = 1;
18401 }else{
18402 /* Someone else is in the process of initing the static mutexes */
18403 while( !winMutex_isInit ){
18404 Sleep(1);
18405 }
18406 }
18407 return SQLITE_OK;
18408 }
18409
@@ -18473,11 +18547,15 @@
18473 p = sqlite3MallocZero( sizeof(*p) );
18474 if( p ){
18475 #ifdef SQLITE_DEBUG
18476 p->id = iType;
18477 #endif
 
 
 
18478 InitializeCriticalSection(&p->mutex);
 
18479 }
18480 break;
18481 }
18482 default: {
18483 assert( winMutex_isInit==1 );
@@ -19104,10 +19182,14 @@
19104 *db->pnBytesFreed += sqlite3DbMallocSize(db, p);
19105 return;
19106 }
19107 if( isLookaside(db, p) ){
19108 LookasideSlot *pBuf = (LookasideSlot*)p;
 
 
 
 
19109 pBuf->pNext = db->lookaside.pFree;
19110 db->lookaside.pFree = pBuf;
19111 db->lookaside.nOut--;
19112 return;
19113 }
@@ -25062,11 +25144,11 @@
25062 unsigned fsFlags; /* cached details from statfs() */
25063 #endif
25064 #if OS_VXWORKS
25065 struct vxworksFileId *pId; /* Unique file ID */
25066 #endif
25067 #ifndef NDEBUG
25068 /* 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
25070 ** whenever any part of the database changes. An assertion fault will
25071 ** occur if a file is updated without also updating the transaction
25072 ** counter. This test is made to avoid new problems similar to the
@@ -25097,11 +25179,10 @@
25097 #endif
25098 #define UNIXFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */
25099 #define UNIXFILE_DELETE 0x20 /* Delete on close */
25100 #define UNIXFILE_URI 0x40 /* Filename might have query parameters */
25101 #define UNIXFILE_NOLOCK 0x80 /* Do no file locking */
25102 #define UNIXFILE_CHOWN 0x100 /* File ownership was changed */
25103
25104 /*
25105 ** Include code that is common to all os_*.c files
25106 */
25107 /************** Include os_common.h in the middle of os_unix.c ***************/
@@ -25350,10 +25431,19 @@
25350 ** which always has the same well-defined interface.
25351 */
25352 static int posixOpen(const char *zFile, int flags, int mode){
25353 return open(zFile, flags, mode);
25354 }
 
 
 
 
 
 
 
 
 
25355
25356 /* Forward reference */
25357 static int openDirectory(const char*, int*);
25358
25359 /*
@@ -25462,11 +25552,11 @@
25462 #define osMkdir ((int(*)(const char*,mode_t))aSyscall[18].pCurrent)
25463
25464 { "rmdir", (sqlite3_syscall_ptr)rmdir, 0 },
25465 #define osRmdir ((int(*)(const char*))aSyscall[19].pCurrent)
25466
25467 { "fchown", (sqlite3_syscall_ptr)fchown, 0 },
25468 #define osFchown ((int(*)(int,uid_t,gid_t))aSyscall[20].pCurrent)
25469
25470 { "umask", (sqlite3_syscall_ptr)umask, 0 },
25471 #define osUmask ((mode_t(*)(mode_t))aSyscall[21].pCurrent)
25472
@@ -26606,11 +26696,11 @@
26606 }
26607 }
26608 }
26609
26610
26611 #ifndef NDEBUG
26612 /* Set up the transaction-counter change checking flags when
26613 ** transitioning from a SHARED to a RESERVED lock. The change
26614 ** from SHARED to RESERVED marks the beginning of a normal
26615 ** write operation (not a hot journal rollback).
26616 */
@@ -26685,11 +26775,11 @@
26685 pInode = pFile->pInode;
26686 assert( pInode->nShared!=0 );
26687 if( pFile->eFileLock>SHARED_LOCK ){
26688 assert( pInode->eFileLock==pFile->eFileLock );
26689
26690 #ifndef NDEBUG
26691 /* When reducing a lock such that other processes can start
26692 ** reading the database file again, make sure that the
26693 ** transaction counter was updated if any part of the database
26694 ** file changed. If the transaction counter is not updated,
26695 ** other connections to the same file might not realize that
@@ -27884,11 +27974,11 @@
27884 assert( pInode->eFileLock==pFile->eFileLock );
27885 SimulateIOErrorBenign(1);
27886 SimulateIOError( h=(-1) )
27887 SimulateIOErrorBenign(0);
27888
27889 #ifndef NDEBUG
27890 /* When reducing a lock such that other processes can start
27891 ** reading the database file again, make sure that the
27892 ** transaction counter was updated if any part of the database
27893 ** file changed. If the transaction counter is not updated,
27894 ** other connections to the same file might not realize that
@@ -28188,11 +28278,11 @@
28188 || offset>=PENDING_BYTE+512
28189 || offset+amt<=PENDING_BYTE
28190 );
28191 #endif
28192
28193 #ifndef NDEBUG
28194 /* 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
28196 ** normal database file) then record the fact that the database
28197 ** has changed. If the transaction counter is modified, record that
28198 ** fact too.
@@ -28479,11 +28569,11 @@
28479 rc = robust_ftruncate(pFile->h, (off_t)nByte);
28480 if( rc ){
28481 pFile->lastErrno = errno;
28482 return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
28483 }else{
28484 #ifndef NDEBUG
28485 /* 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
28487 ** normal database file) and we truncate the file to zero length,
28488 ** that effectively updates the change counter. This might happen
28489 ** when restoring a database using the backup API from a zero-length
@@ -28636,11 +28726,11 @@
28636 }
28637 case SQLITE_FCNTL_VFSNAME: {
28638 *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName);
28639 return SQLITE_OK;
28640 }
28641 #ifndef NDEBUG
28642 /* The pager calls this method to signal that it has done
28643 ** a rollback and that the database is therefore unchanged and
28644 ** it hence it is OK for the transaction change counter to be
28645 ** unchanged.
28646 */
@@ -28987,18 +29077,13 @@
28987 goto shm_open_err;
28988 }
28989
28990 /* 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,
28992 ** the original owner will not be able to connect. If this process is
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 */
28997 if( osFchown(pShmNode->h, sStat.st_uid, sStat.st_gid)==0 ){
28998 pDbFd->ctrlFlags |= UNIXFILE_CHOWN;
28999 }
29000
29001 /* Check to see if another process is holding the dead-man switch.
29002 ** If not, truncate the file to zero length.
29003 */
29004 rc = SQLITE_OK;
@@ -30200,17 +30285,14 @@
30200 goto open_finished;
30201 }
30202
30203 /* 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
30205 ** the same as the original database. If we are not running as root,
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 */
30210 if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){
30211 if( osFchown(fd, uid, gid)==0 ){ p->ctrlFlags |= UNIXFILE_CHOWN; }
30212 }
30213 }
30214 assert( fd>=0 );
30215 if( pOutFlags ){
30216 *pOutFlags = flags;
@@ -32167,16 +32249,31 @@
32167 #endif /* !defined(_OS_COMMON_H_) */
32168
32169 /************** End of os_common.h *******************************************/
32170 /************** Continuing where we left off in os_win.c *********************/
32171
 
 
 
 
 
 
 
32172 /*
32173 ** Some Microsoft compilers lack this definition.
32174 */
32175 #ifndef INVALID_FILE_ATTRIBUTES
32176 # define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
32177 #endif
 
 
 
 
 
 
 
 
32178
32179 /* Forward references */
32180 typedef struct winShm winShm; /* A connection to shared-memory */
32181 typedef struct winShmNode winShmNode; /* A region of shared-memory */
32182
@@ -32222,15 +32319,41 @@
32222 ** Allowed values for winFile.ctrlFlags
32223 */
32224 #define WINFILE_PERSIST_WAL 0x04 /* Persistent WAL mode */
32225 #define WINFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */
32226
 
 
 
 
 
 
 
32227 /*
32228 * If compiled with SQLITE_WIN32_MALLOC on Windows, we will use the
32229 * various Win32 API heap functions instead of our own.
32230 */
32231 #ifdef SQLITE_WIN32_MALLOC
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32232 /*
32233 * The initial size of the Win32-specific heap. This value may be zero.
32234 */
32235 #ifndef SQLITE_WIN32_HEAP_INIT_SIZE
32236 # define SQLITE_WIN32_HEAP_INIT_SIZE ((SQLITE_DEFAULT_CACHE_SIZE) * \
@@ -32311,61 +32434,50 @@
32311 SQLITE_API int sqlite3_os_type = 0;
32312 #else
32313 static int sqlite3_os_type = 0;
32314 #endif
32315
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
32323 # define SQLITE_WIN32_HAS_ANSI
32324 #endif
32325
32326 #if SQLITE_OS_WINCE || SQLITE_OS_WINNT
32327 # define SQLITE_WIN32_HAS_WIDE
32328 #endif
32329
32330 #ifndef SYSCALL
32331 # define SYSCALL sqlite3_syscall_ptr
32332 #endif
32333
32334 #if SQLITE_OS_WINCE
32335 /*
32336 ** These macros are necessary because Windows CE does not natively support the
32337 ** Win32 APIs LockFile, UnlockFile, and LockFileEx.
32338 */
32339
32340 # define LockFile(a,b,c,d,e) winceLockFile(&a, b, c, d, e)
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
32344 /*
32345 ** These are the special syscall hacks for Windows CE. The locking related
32346 ** defines here refer to the macros defined just above.
32347 */
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 {
32356 const char *zName; /* Name of the sytem call */
32357 sqlite3_syscall_ptr pCurrent; /* Current value of the system call */
32358 sqlite3_syscall_ptr pDefault; /* Default value */
32359 } aSyscall[] = {
32360 #if !SQLITE_OS_WINCE
32361 { "AreFileApisANSI", (SYSCALL)AreFileApisANSI, 0 },
32362
32363 #define osAreFileApisANSI ((BOOL(WINAPI*)(VOID))aSyscall[0].pCurrent)
32364 #else
32365 { "AreFileApisANSI", (SYSCALL)0, 0 },
32366 #endif
 
 
 
 
32367
32368 #if SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE)
32369 { "CharLowerW", (SYSCALL)CharLowerW, 0 },
32370 #else
32371 { "CharLowerW", (SYSCALL)0, 0 },
@@ -32392,174 +32504,173 @@
32392 #endif
32393
32394 #define osCreateFileA ((HANDLE(WINAPI*)(LPCSTR,DWORD,DWORD, \
32395 LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[4].pCurrent)
32396
32397 #if defined(SQLITE_WIN32_HAS_WIDE)
32398 { "CreateFileW", (SYSCALL)CreateFileW, 0 },
32399 #else
32400 { "CreateFileW", (SYSCALL)0, 0 },
32401 #endif
32402
32403 #define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \
32404 LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent)
32405
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)
32412 { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 },
32413 #else
32414 { "CreateFileMappingW", (SYSCALL)0, 0 },
32415 #endif
32416
32417 #define osCreateFileMappingW ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \
32418 DWORD,DWORD,DWORD,LPCWSTR))aSyscall[7].pCurrent)
32419
32420 #if defined(SQLITE_WIN32_HAS_WIDE)
32421 { "CreateMutexW", (SYSCALL)CreateMutexW, 0 },
32422 #else
32423 { "CreateMutexW", (SYSCALL)0, 0 },
32424 #endif
32425
32426 #define osCreateMutexW ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,BOOL, \
32427 LPCWSTR))aSyscall[8].pCurrent)
32428
32429 #if defined(SQLITE_WIN32_HAS_ANSI)
32430 { "DeleteFileA", (SYSCALL)DeleteFileA, 0 },
32431 #else
32432 { "DeleteFileA", (SYSCALL)0, 0 },
32433 #endif
32434
32435 #define osDeleteFileA ((BOOL(WINAPI*)(LPCSTR))aSyscall[9].pCurrent)
32436
32437 #if defined(SQLITE_WIN32_HAS_WIDE)
32438 { "DeleteFileW", (SYSCALL)DeleteFileW, 0 },
32439 #else
32440 { "DeleteFileW", (SYSCALL)0, 0 },
32441 #endif
32442
32443 #define osDeleteFileW ((BOOL(WINAPI*)(LPCWSTR))aSyscall[10].pCurrent)
32444
32445 #if SQLITE_OS_WINCE
32446 { "FileTimeToLocalFileTime", (SYSCALL)FileTimeToLocalFileTime, 0 },
32447 #else
32448 { "FileTimeToLocalFileTime", (SYSCALL)0, 0 },
32449 #endif
32450
32451 #define osFileTimeToLocalFileTime ((BOOL(WINAPI*)(CONST FILETIME*, \
32452 LPFILETIME))aSyscall[11].pCurrent)
32453
32454 #if SQLITE_OS_WINCE
32455 { "FileTimeToSystemTime", (SYSCALL)FileTimeToSystemTime, 0 },
32456 #else
32457 { "FileTimeToSystemTime", (SYSCALL)0, 0 },
32458 #endif
32459
32460 #define osFileTimeToSystemTime ((BOOL(WINAPI*)(CONST FILETIME*, \
32461 LPSYSTEMTIME))aSyscall[12].pCurrent)
32462
32463 { "FlushFileBuffers", (SYSCALL)FlushFileBuffers, 0 },
32464
32465 #define osFlushFileBuffers ((BOOL(WINAPI*)(HANDLE))aSyscall[13].pCurrent)
32466
32467 #if defined(SQLITE_WIN32_HAS_ANSI)
32468 { "FormatMessageA", (SYSCALL)FormatMessageA, 0 },
32469 #else
32470 { "FormatMessageA", (SYSCALL)0, 0 },
32471 #endif
32472
32473 #define osFormatMessageA ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPSTR, \
32474 DWORD,va_list*))aSyscall[14].pCurrent)
32475
32476 #if defined(SQLITE_WIN32_HAS_WIDE)
32477 { "FormatMessageW", (SYSCALL)FormatMessageW, 0 },
32478 #else
32479 { "FormatMessageW", (SYSCALL)0, 0 },
32480 #endif
32481
32482 #define osFormatMessageW ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPWSTR, \
32483 DWORD,va_list*))aSyscall[15].pCurrent)
32484
32485 { "FreeLibrary", (SYSCALL)FreeLibrary, 0 },
32486
32487 #define osFreeLibrary ((BOOL(WINAPI*)(HMODULE))aSyscall[16].pCurrent)
32488
32489 { "GetCurrentProcessId", (SYSCALL)GetCurrentProcessId, 0 },
32490
32491 #define osGetCurrentProcessId ((DWORD(WINAPI*)(VOID))aSyscall[17].pCurrent)
32492
32493 #if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_ANSI)
32494 { "GetDiskFreeSpaceA", (SYSCALL)GetDiskFreeSpaceA, 0 },
32495 #else
32496 { "GetDiskFreeSpaceA", (SYSCALL)0, 0 },
32497 #endif
32498
32499 #define osGetDiskFreeSpaceA ((BOOL(WINAPI*)(LPCSTR,LPDWORD,LPDWORD,LPDWORD, \
32500 LPDWORD))aSyscall[18].pCurrent)
32501
32502 #if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE)
32503 { "GetDiskFreeSpaceW", (SYSCALL)GetDiskFreeSpaceW, 0 },
32504 #else
32505 { "GetDiskFreeSpaceW", (SYSCALL)0, 0 },
32506 #endif
32507
32508 #define osGetDiskFreeSpaceW ((BOOL(WINAPI*)(LPCWSTR,LPDWORD,LPDWORD,LPDWORD, \
32509 LPDWORD))aSyscall[19].pCurrent)
32510
32511 #if defined(SQLITE_WIN32_HAS_ANSI)
32512 { "GetFileAttributesA", (SYSCALL)GetFileAttributesA, 0 },
32513 #else
32514 { "GetFileAttributesA", (SYSCALL)0, 0 },
32515 #endif
32516
32517 #define osGetFileAttributesA ((DWORD(WINAPI*)(LPCSTR))aSyscall[20].pCurrent)
32518
32519 #if defined(SQLITE_WIN32_HAS_WIDE)
32520 { "GetFileAttributesW", (SYSCALL)GetFileAttributesW, 0 },
32521 #else
32522 { "GetFileAttributesW", (SYSCALL)0, 0 },
32523 #endif
32524
32525 #define osGetFileAttributesW ((DWORD(WINAPI*)(LPCWSTR))aSyscall[21].pCurrent)
32526
32527 #if defined(SQLITE_WIN32_HAS_WIDE)
32528 { "GetFileAttributesExW", (SYSCALL)GetFileAttributesExW, 0 },
32529 #else
32530 { "GetFileAttributesExW", (SYSCALL)0, 0 },
32531 #endif
32532
32533 #define osGetFileAttributesExW ((BOOL(WINAPI*)(LPCWSTR,GET_FILEEX_INFO_LEVELS, \
32534 LPVOID))aSyscall[22].pCurrent)
32535
 
32536 { "GetFileSize", (SYSCALL)GetFileSize, 0 },
 
 
 
32537
32538 #define osGetFileSize ((DWORD(WINAPI*)(HANDLE,LPDWORD))aSyscall[23].pCurrent)
32539
32540 #if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_ANSI)
32541 { "GetFullPathNameA", (SYSCALL)GetFullPathNameA, 0 },
32542 #else
32543 { "GetFullPathNameA", (SYSCALL)0, 0 },
32544 #endif
32545
32546 #define osGetFullPathNameA ((DWORD(WINAPI*)(LPCSTR,DWORD,LPSTR, \
32547 LPSTR*))aSyscall[24].pCurrent)
32548
32549 #if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE)
32550 { "GetFullPathNameW", (SYSCALL)GetFullPathNameW, 0 },
32551 #else
32552 { "GetFullPathNameW", (SYSCALL)0, 0 },
32553 #endif
32554
32555 #define osGetFullPathNameW ((DWORD(WINAPI*)(LPCWSTR,DWORD,LPWSTR, \
32556 LPWSTR*))aSyscall[25].pCurrent)
32557
32558 { "GetLastError", (SYSCALL)GetLastError, 0 },
32559
32560 #define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[26].pCurrent)
32561
32562 #if SQLITE_OS_WINCE
32563 /* The GetProcAddressA() routine is only available on Windows CE. */
32564 { "GetProcAddressA", (SYSCALL)GetProcAddressA, 0 },
32565 #else
@@ -32567,198 +32678,358 @@
32567 ** an ANSI string regardless of the _UNICODE setting */
32568 { "GetProcAddressA", (SYSCALL)GetProcAddress, 0 },
32569 #endif
32570
32571 #define osGetProcAddressA ((FARPROC(WINAPI*)(HMODULE, \
32572 LPCSTR))aSyscall[27].pCurrent)
32573
 
32574 { "GetSystemInfo", (SYSCALL)GetSystemInfo, 0 },
 
 
 
32575
32576 #define osGetSystemInfo ((VOID(WINAPI*)(LPSYSTEM_INFO))aSyscall[28].pCurrent)
32577
32578 { "GetSystemTime", (SYSCALL)GetSystemTime, 0 },
32579
32580 #define osGetSystemTime ((VOID(WINAPI*)(LPSYSTEMTIME))aSyscall[29].pCurrent)
32581
32582 #if !SQLITE_OS_WINCE
32583 { "GetSystemTimeAsFileTime", (SYSCALL)GetSystemTimeAsFileTime, 0 },
32584 #else
32585 { "GetSystemTimeAsFileTime", (SYSCALL)0, 0 },
32586 #endif
32587
32588 #define osGetSystemTimeAsFileTime ((VOID(WINAPI*)( \
32589 LPFILETIME))aSyscall[30].pCurrent)
32590
32591 #if defined(SQLITE_WIN32_HAS_ANSI)
32592 { "GetTempPathA", (SYSCALL)GetTempPathA, 0 },
32593 #else
32594 { "GetTempPathA", (SYSCALL)0, 0 },
32595 #endif
32596
32597 #define osGetTempPathA ((DWORD(WINAPI*)(DWORD,LPSTR))aSyscall[31].pCurrent)
32598
32599 #if defined(SQLITE_WIN32_HAS_WIDE)
32600 { "GetTempPathW", (SYSCALL)GetTempPathW, 0 },
32601 #else
32602 { "GetTempPathW", (SYSCALL)0, 0 },
32603 #endif
32604
32605 #define osGetTempPathW ((DWORD(WINAPI*)(DWORD,LPWSTR))aSyscall[32].pCurrent)
32606
 
32607 { "GetTickCount", (SYSCALL)GetTickCount, 0 },
 
 
 
32608
32609 #define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[33].pCurrent)
32610
32611 #if defined(SQLITE_WIN32_HAS_ANSI)
32612 { "GetVersionExA", (SYSCALL)GetVersionExA, 0 },
32613 #else
32614 { "GetVersionExA", (SYSCALL)0, 0 },
32615 #endif
32616
32617 #define osGetVersionExA ((BOOL(WINAPI*)( \
32618 LPOSVERSIONINFOA))aSyscall[34].pCurrent)
32619
32620 { "HeapAlloc", (SYSCALL)HeapAlloc, 0 },
32621
32622 #define osHeapAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD, \
32623 SIZE_T))aSyscall[35].pCurrent)
32624
 
32625 { "HeapCreate", (SYSCALL)HeapCreate, 0 },
 
 
 
32626
32627 #define osHeapCreate ((HANDLE(WINAPI*)(DWORD,SIZE_T, \
32628 SIZE_T))aSyscall[36].pCurrent)
32629
 
32630 { "HeapDestroy", (SYSCALL)HeapDestroy, 0 },
 
 
 
32631
32632 #define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[37].pCurrent)
32633
32634 { "HeapFree", (SYSCALL)HeapFree, 0 },
32635
32636 #define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[38].pCurrent)
32637
32638 { "HeapReAlloc", (SYSCALL)HeapReAlloc, 0 },
32639
32640 #define osHeapReAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD,LPVOID, \
32641 SIZE_T))aSyscall[39].pCurrent)
32642
32643 { "HeapSize", (SYSCALL)HeapSize, 0 },
32644
32645 #define osHeapSize ((SIZE_T(WINAPI*)(HANDLE,DWORD, \
32646 LPCVOID))aSyscall[40].pCurrent)
32647
 
32648 { "HeapValidate", (SYSCALL)HeapValidate, 0 },
 
 
 
32649
32650 #define osHeapValidate ((BOOL(WINAPI*)(HANDLE,DWORD, \
32651 LPCVOID))aSyscall[41].pCurrent)
32652
32653 #if defined(SQLITE_WIN32_HAS_ANSI)
32654 { "LoadLibraryA", (SYSCALL)LoadLibraryA, 0 },
32655 #else
32656 { "LoadLibraryA", (SYSCALL)0, 0 },
32657 #endif
32658
32659 #define osLoadLibraryA ((HMODULE(WINAPI*)(LPCSTR))aSyscall[42].pCurrent)
32660
32661 #if defined(SQLITE_WIN32_HAS_WIDE)
32662 { "LoadLibraryW", (SYSCALL)LoadLibraryW, 0 },
32663 #else
32664 { "LoadLibraryW", (SYSCALL)0, 0 },
32665 #endif
32666
32667 #define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[43].pCurrent)
32668
 
32669 { "LocalFree", (SYSCALL)LocalFree, 0 },
32670
32671 #define osLocalFree ((HLOCAL(WINAPI*)(HLOCAL))aSyscall[44].pCurrent)
32672
32673 #if !SQLITE_OS_WINCE
32674 { "LockFile", (SYSCALL)LockFile, 0 },
32675
32676 #define osLockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
32677 DWORD))aSyscall[45].pCurrent)
32678 #else
32679 { "LockFile", (SYSCALL)0, 0 },
32680 #endif
 
 
 
 
 
32681
32682 #if !SQLITE_OS_WINCE
32683 { "LockFileEx", (SYSCALL)LockFileEx, 0 },
32684
32685 #define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \
32686 LPOVERLAPPED))aSyscall[46].pCurrent)
32687 #else
32688 { "LockFileEx", (SYSCALL)0, 0 },
32689 #endif
32690
 
 
 
 
 
 
32691 { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 },
 
 
 
32692
32693 #define osMapViewOfFile ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
32694 SIZE_T))aSyscall[47].pCurrent)
32695
32696 { "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 },
32697
32698 #define osMultiByteToWideChar ((int(WINAPI*)(UINT,DWORD,LPCSTR,int,LPWSTR, \
32699 int))aSyscall[48].pCurrent)
32700
32701 { "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 },
32702
32703 #define osQueryPerformanceCounter ((BOOL(WINAPI*)( \
32704 LARGE_INTEGER*))aSyscall[49].pCurrent)
32705
32706 { "ReadFile", (SYSCALL)ReadFile, 0 },
32707
32708 #define osReadFile ((BOOL(WINAPI*)(HANDLE,LPVOID,DWORD,LPDWORD, \
32709 LPOVERLAPPED))aSyscall[50].pCurrent)
32710
32711 { "SetEndOfFile", (SYSCALL)SetEndOfFile, 0 },
32712
32713 #define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[51].pCurrent)
32714
 
32715 { "SetFilePointer", (SYSCALL)SetFilePointer, 0 },
 
 
 
32716
32717 #define osSetFilePointer ((DWORD(WINAPI*)(HANDLE,LONG,PLONG, \
32718 DWORD))aSyscall[52].pCurrent)
32719
 
32720 { "Sleep", (SYSCALL)Sleep, 0 },
 
 
 
32721
32722 #define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[53].pCurrent)
32723
32724 { "SystemTimeToFileTime", (SYSCALL)SystemTimeToFileTime, 0 },
32725
32726 #define osSystemTimeToFileTime ((BOOL(WINAPI*)(CONST SYSTEMTIME*, \
32727 LPFILETIME))aSyscall[54].pCurrent)
32728
32729 #if !SQLITE_OS_WINCE
32730 { "UnlockFile", (SYSCALL)UnlockFile, 0 },
32731
32732 #define osUnlockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
32733 DWORD))aSyscall[55].pCurrent)
32734 #else
32735 { "UnlockFile", (SYSCALL)0, 0 },
32736 #endif
 
 
 
 
 
32737
32738 #if !SQLITE_OS_WINCE
32739 { "UnlockFileEx", (SYSCALL)UnlockFileEx, 0 },
32740
32741 #define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
32742 LPOVERLAPPED))aSyscall[56].pCurrent)
32743 #else
32744 { "UnlockFileEx", (SYSCALL)0, 0 },
32745 #endif
 
 
 
32746
32747 { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 },
32748
32749 #define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[57].pCurrent)
32750
32751 { "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 },
32752
32753 #define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \
32754 LPCSTR,LPBOOL))aSyscall[58].pCurrent)
32755
32756 { "WriteFile", (SYSCALL)WriteFile, 0 },
32757
32758 #define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \
32759 LPOVERLAPPED))aSyscall[59].pCurrent)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32760
32761 }; /* End of the overrideable system calls */
32762
32763 /*
32764 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
@@ -32840,10 +33111,68 @@
32840 for(i++; i<ArraySize(aSyscall); i++){
32841 if( aSyscall[i].pCurrent!=0 ) return aSyscall[i].zName;
32842 }
32843 return 0;
32844 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32845
32846 /*
32847 ** Return true (non-zero) if we are running under WinNT, Win2K, WinXP,
32848 ** or WinCE. Return false (zero) for Win95, Win98, or WinME.
32849 **
@@ -32852,11 +33181,11 @@
32852 ** 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
32854 ** WinNT/2K/XP so that we will know whether or not we can safely call
32855 ** the LockFileEx() API.
32856 */
32857 #if SQLITE_OS_WINCE
32858 # define isNT() (1)
32859 #else
32860 static int isNT(void){
32861 if( sqlite3_os_type==0 ){
32862 OSVERSIONINFOA sInfo;
@@ -32878,11 +33207,11 @@
32878
32879 winMemAssertMagic();
32880 hHeap = winMemGetHeap();
32881 assert( hHeap!=0 );
32882 assert( hHeap!=INVALID_HANDLE_VALUE );
32883 #ifdef SQLITE_WIN32_MALLOC_VALIDATE
32884 assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
32885 #endif
32886 assert( nBytes>=0 );
32887 p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
32888 if( !p ){
@@ -32900,11 +33229,11 @@
32900
32901 winMemAssertMagic();
32902 hHeap = winMemGetHeap();
32903 assert( hHeap!=0 );
32904 assert( hHeap!=INVALID_HANDLE_VALUE );
32905 #ifdef SQLITE_WIN32_MALLOC_VALIDATE
32906 assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) );
32907 #endif
32908 if( !pPrior ) return; /* Passing NULL to HeapFree is undefined. */
32909 if( !osHeapFree(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ){
32910 sqlite3_log(SQLITE_NOMEM, "failed to HeapFree block %p (%d), heap=%p",
@@ -32921,11 +33250,11 @@
32921
32922 winMemAssertMagic();
32923 hHeap = winMemGetHeap();
32924 assert( hHeap!=0 );
32925 assert( hHeap!=INVALID_HANDLE_VALUE );
32926 #ifdef SQLITE_WIN32_MALLOC_VALIDATE
32927 assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) );
32928 #endif
32929 assert( nBytes>=0 );
32930 if( !pPrior ){
32931 p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
@@ -32949,11 +33278,11 @@
32949
32950 winMemAssertMagic();
32951 hHeap = winMemGetHeap();
32952 assert( hHeap!=0 );
32953 assert( hHeap!=INVALID_HANDLE_VALUE );
32954 #ifdef SQLITE_WIN32_MALLOC_VALIDATE
32955 assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
32956 #endif
32957 if( !p ) return 0;
32958 n = osHeapSize(hHeap, SQLITE_WIN32_HEAP_FLAGS, p);
32959 if( n==(SIZE_T)-1 ){
@@ -32977,10 +33306,12 @@
32977 static int winMemInit(void *pAppData){
32978 winMemData *pWinMemData = (winMemData *)pAppData;
32979
32980 if( !pWinMemData ) return SQLITE_ERROR;
32981 assert( pWinMemData->magic==WINMEM_MAGIC );
 
 
32982 if( !pWinMemData->hHeap ){
32983 pWinMemData->hHeap = osHeapCreate(SQLITE_WIN32_HEAP_FLAGS,
32984 SQLITE_WIN32_HEAP_INIT_SIZE,
32985 SQLITE_WIN32_HEAP_MAX_SIZE);
32986 if( !pWinMemData->hHeap ){
@@ -32989,14 +33320,25 @@
32989 osGetLastError(), SQLITE_WIN32_HEAP_FLAGS,
32990 SQLITE_WIN32_HEAP_INIT_SIZE, SQLITE_WIN32_HEAP_MAX_SIZE);
32991 return SQLITE_NOMEM;
32992 }
32993 pWinMemData->bOwned = TRUE;
 
32994 }
 
 
 
 
 
 
 
 
 
 
32995 assert( pWinMemData->hHeap!=0 );
32996 assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE );
32997 #ifdef SQLITE_WIN32_MALLOC_VALIDATE
32998 assert( osHeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
32999 #endif
33000 return SQLITE_OK;
33001 }
33002
@@ -33007,11 +33349,11 @@
33007 winMemData *pWinMemData = (winMemData *)pAppData;
33008
33009 if( !pWinMemData ) return;
33010 if( pWinMemData->hHeap ){
33011 assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE );
33012 #ifdef SQLITE_WIN32_MALLOC_VALIDATE
33013 assert( osHeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
33014 #endif
33015 if( pWinMemData->bOwned ){
33016 if( !osHeapDestroy(pWinMemData->hHeap) ){
33017 sqlite3_log(SQLITE_NOMEM, "failed to HeapDestroy (%d), heap=%p",
@@ -33207,10 +33549,21 @@
33207 */
33208 DWORD dwLen = 0;
33209 char *zOut = 0;
33210
33211 if( isNT() ){
 
 
 
 
 
 
 
 
 
 
 
33212 LPWSTR zTempWide = NULL;
33213 dwLen = osFormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
33214 FORMAT_MESSAGE_FROM_SYSTEM |
33215 FORMAT_MESSAGE_IGNORE_INSERTS,
33216 NULL,
@@ -33217,24 +33570,24 @@
33217 lastErrno,
33218 0,
33219 (LPWSTR) &zTempWide,
33220 0,
33221 0);
 
33222 if( dwLen > 0 ){
33223 /* allocate a buffer and convert to UTF8 */
33224 sqlite3BeginBenignMalloc();
33225 zOut = unicodeToUtf8(zTempWide);
33226 sqlite3EndBenignMalloc();
 
33227 /* free the system buffer allocated by FormatMessage */
33228 osLocalFree(zTempWide);
 
33229 }
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
33235 }else{
33236 char *zTemp = NULL;
33237 dwLen = osFormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
33238 FORMAT_MESSAGE_FROM_SYSTEM |
33239 FORMAT_MESSAGE_IGNORE_INSERTS,
33240 NULL,
@@ -33249,12 +33602,12 @@
33249 zOut = sqlite3_win32_mbcs_to_utf8(zTemp);
33250 sqlite3EndBenignMalloc();
33251 /* free the system buffer allocated by FormatMessage */
33252 osLocalFree(zTemp);
33253 }
 
33254 #endif
33255 }
33256 if( 0 == dwLen ){
33257 sqlite3_snprintf(nBuf, zBuf, "OsError 0x%x (%u)", lastErrno, lastErrno);
33258 }else{
33259 /* copy a maximum of nBuf chars to output buffer */
33260 sqlite3_snprintf(nBuf, zBuf, "%s", zOut);
@@ -33333,11 +33686,11 @@
33333 return 0;
33334 }
33335 if( e==ERROR_ACCESS_DENIED ||
33336 e==ERROR_LOCK_VIOLATION ||
33337 e==ERROR_SHARING_VIOLATION ){
33338 osSleep(win32IoerrRetryDelay*(1+*pnRetry));
33339 ++*pnRetry;
33340 return 1;
33341 }
33342 if( pError ){
33343 *pError = e;
@@ -33394,11 +33747,11 @@
33394 ** Acquire a lock on the handle h
33395 */
33396 static void winceMutexAcquire(HANDLE h){
33397 DWORD dwErr;
33398 do {
33399 dwErr = WaitForSingleObject(h, INFINITE);
33400 } while (dwErr != WAIT_OBJECT_0 && dwErr != WAIT_ABANDONED);
33401 }
33402 /*
33403 ** Release a lock acquired by winceMutexAcquire()
33404 */
@@ -33525,11 +33878,11 @@
33525
33526 /*
33527 ** An implementation of the LockFile() API of Windows for CE
33528 */
33529 static BOOL winceLockFile(
33530 HANDLE *phFile,
33531 DWORD dwFileOffsetLow,
33532 DWORD dwFileOffsetHigh,
33533 DWORD nNumberOfBytesToLockLow,
33534 DWORD nNumberOfBytesToLockHigh
33535 ){
@@ -33589,11 +33942,11 @@
33589
33590 /*
33591 ** An implementation of the UnlockFile API of Windows for CE
33592 */
33593 static BOOL winceUnlockFile(
33594 HANDLE *phFile,
33595 DWORD dwFileOffsetLow,
33596 DWORD dwFileOffsetHigh,
33597 DWORD nNumberOfBytesToUnlockLow,
33598 DWORD nNumberOfBytesToUnlockHigh
33599 ){
@@ -33646,38 +33999,77 @@
33646 }
33647
33648 winceMutexRelease(pFile->hMutex);
33649 return bReturn;
33650 }
33651
33652 /*
33653 ** An implementation of the LockFileEx() API of Windows for CE
33654 */
33655 static BOOL winceLockFileEx(
33656 HANDLE *phFile,
33657 DWORD dwFlags,
33658 DWORD dwReserved,
33659 DWORD nNumberOfBytesToLockLow,
33660 DWORD nNumberOfBytesToLockHigh,
33661 LPOVERLAPPED lpOverlapped
33662 ){
33663 UNUSED_PARAMETER(dwReserved);
33664 UNUSED_PARAMETER(nNumberOfBytesToLockHigh);
33665
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);
33672 }
33673 return FALSE;
33674 }
33675 /*
33676 ** End of the special code for wince
33677 *****************************************************************************/
33678 #endif /* SQLITE_OS_WINCE */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33679
33680 /*****************************************************************************
33681 ** The next group of routines implement the I/O methods specified
33682 ** by the sqlite3_io_methods object.
33683 ******************************************************************************/
@@ -33693,10 +34085,11 @@
33693 ** Move the current position of the file handle passed as the first
33694 ** argument to offset iOffset within the file. If successful, return 0.
33695 ** Otherwise, set pFile->lastErrno and return non-zero.
33696 */
33697 static int seekWinFile(winFile *pFile, sqlite3_int64 iOffset){
 
33698 LONG upperBits; /* Most sig. 32 bits of new offset */
33699 LONG lowerBits; /* Least sig. 32 bits of new offset */
33700 DWORD dwRet; /* Value returned by SetFilePointer() */
33701 DWORD lastErrno; /* Value returned by GetLastError() */
33702
@@ -33719,10 +34112,30 @@
33719 "seekWinFile", pFile->zPath);
33720 return 1;
33721 }
33722
33723 return 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33724 }
33725
33726 /*
33727 ** Close a file.
33728 **
@@ -33742,11 +34155,11 @@
33742 assert( pFile->pShm==0 );
33743 OSTRACE(("CLOSE %d\n", pFile->h));
33744 do{
33745 rc = osCloseHandle(pFile->h);
33746 /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */
33747 }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (osSleep(100), 1) );
33748 #if SQLITE_OS_WINCE
33749 #define WINCE_DELETION_ATTEMPTS 3
33750 winceDestroyLock(pFile);
33751 if( pFile->zDeleteOnClose ){
33752 int cnt = 0;
@@ -33753,11 +34166,11 @@
33753 while(
33754 osDeleteFileW(pFile->zDeleteOnClose)==0
33755 && osGetFileAttributesW(pFile->zDeleteOnClose)!=0xffffffff
33756 && cnt++ < WINCE_DELETION_ATTEMPTS
33757 ){
33758 osSleep(100); /* Wait a little before trying again */
33759 }
33760 sqlite3_free(pFile->zDeleteOnClose);
33761 }
33762 #endif
33763 OSTRACE(("CLOSE %d %s\n", pFile->h, rc ? "ok" : "failed"));
@@ -34008,60 +34421,105 @@
34008
34009 /*
34010 ** Determine the current size of a file in bytes
34011 */
34012 static int winFileSize(sqlite3_file *id, sqlite3_int64 *pSize){
34013 DWORD upperBits;
34014 DWORD lowerBits;
34015 winFile *pFile = (winFile*)id;
34016 DWORD lastErrno;
34017
34018 assert( id!=0 );
34019 SimulateIOError(return SQLITE_IOERR_FSTAT);
34020 lowerBits = osGetFileSize(pFile->h, &upperBits);
34021 if( (lowerBits == INVALID_FILE_SIZE)
34022 && ((lastErrno = osGetLastError())!=NO_ERROR) )
 
 
 
 
 
 
 
 
 
 
34023 {
34024 pFile->lastErrno = lastErrno;
34025 return winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno,
 
 
 
 
 
 
 
 
34026 "winFileSize", pFile->zPath);
 
34027 }
34028 *pSize = (((sqlite3_int64)upperBits)<<32) + lowerBits;
34029 return SQLITE_OK;
34030 }
34031
34032 /*
34033 ** LOCKFILE_FAIL_IMMEDIATELY is undefined on some Windows systems.
34034 */
34035 #ifndef LOCKFILE_FAIL_IMMEDIATELY
34036 # define LOCKFILE_FAIL_IMMEDIATELY 1
34037 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34038
34039 /*
34040 ** Acquire a reader lock.
34041 ** Different API routines are called depending on whether or not this
34042 ** is Win9x or WinNT.
34043 */
34044 static int getReadLock(winFile *pFile){
34045 int res;
34046 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.
34054 */
34055 #if SQLITE_OS_WINCE==0
34056 }else{
 
 
 
34057 int lk;
34058 sqlite3_randomness(sizeof(lk), &lk);
34059 pFile->sharedLockByte = (short)((lk & 0x7fffffff)%(SHARED_SIZE - 1));
34060 res = osLockFile(pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
 
 
34061 #endif
34062 }
34063 if( res == 0 ){
34064 pFile->lastErrno = osGetLastError();
34065 /* No need to log a failure to lock */
34066 }
34067 return res;
@@ -34072,18 +34530,17 @@
34072 */
34073 static int unlockReadLock(winFile *pFile){
34074 int res;
34075 DWORD lastErrno;
34076 if( isNT() ){
34077 res = osUnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
34078 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
34079 */
34080 #if SQLITE_OS_WINCE==0
34081 }else{
34082 res = osUnlockFile(pFile->h, SHARED_FIRST + pFile->sharedLockByte, 0, 1, 0);
34083 #endif
34084 }
34085 if( res==0 && ((lastErrno = osGetLastError())!=ERROR_NOT_LOCKED) ){
34086 pFile->lastErrno = lastErrno;
34087 winLogError(SQLITE_IOERR_UNLOCK, pFile->lastErrno,
34088 "unlockReadLock", pFile->zPath);
34089 }
@@ -34150,19 +34607,20 @@
34150 if( (pFile->locktype==NO_LOCK)
34151 || ( (locktype==EXCLUSIVE_LOCK)
34152 && (pFile->locktype==RESERVED_LOCK))
34153 ){
34154 int cnt = 3;
34155 while( cnt-->0 && (res = osLockFile(pFile->h, PENDING_BYTE, 0, 1, 0))==0 ){
 
34156 /* 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
34158 ** Windows systems.
34159 ** 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.
34161 */
34162 OSTRACE(("could not get a PENDING lock. cnt=%d\n", cnt));
34163 if( cnt ) osSleep(1);
34164 }
34165 gotPendingLock = res;
34166 if( !res ){
34167 lastErrno = osGetLastError();
34168 }
@@ -34182,11 +34640,11 @@
34182
34183 /* Acquire a RESERVED lock
34184 */
34185 if( locktype==RESERVED_LOCK && res ){
34186 assert( pFile->locktype==SHARED_LOCK );
34187 res = osLockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
34188 if( res ){
34189 newLocktype = RESERVED_LOCK;
34190 }else{
34191 lastErrno = osGetLastError();
34192 }
@@ -34203,11 +34661,12 @@
34203 */
34204 if( locktype==EXCLUSIVE_LOCK && res ){
34205 assert( pFile->locktype>=SHARED_LOCK );
34206 res = unlockReadLock(pFile);
34207 OSTRACE(("unreadlock = %d\n", res));
34208 res = osLockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
 
34209 if( res ){
34210 newLocktype = EXCLUSIVE_LOCK;
34211 }else{
34212 lastErrno = osGetLastError();
34213 OSTRACE(("error-code = %d\n", lastErrno));
@@ -34217,11 +34676,11 @@
34217
34218 /* If we are holding a PENDING lock that ought to be released, then
34219 ** release it now.
34220 */
34221 if( gotPendingLock && locktype==SHARED_LOCK ){
34222 osUnlockFile(pFile->h, PENDING_BYTE, 0, 1, 0);
34223 }
34224
34225 /* Update the state of the lock has held in the file descriptor then
34226 ** return the appropriate result code.
34227 */
@@ -34251,13 +34710,13 @@
34251 assert( id!=0 );
34252 if( pFile->locktype>=RESERVED_LOCK ){
34253 rc = 1;
34254 OSTRACE(("TEST WR-LOCK %d %d (local)\n", pFile->h, rc));
34255 }else{
34256 rc = osLockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
34257 if( rc ){
34258 osUnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
34259 }
34260 rc = !rc;
34261 OSTRACE(("TEST WR-LOCK %d %d (remote)\n", pFile->h, rc));
34262 }
34263 *pResOut = rc;
@@ -34283,26 +34742,26 @@
34283 assert( locktype<=SHARED_LOCK );
34284 OSTRACE(("UNLOCK %d to %d was %d(%d)\n", pFile->h, locktype,
34285 pFile->locktype, pFile->sharedLockByte));
34286 type = pFile->locktype;
34287 if( type>=EXCLUSIVE_LOCK ){
34288 osUnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
34289 if( locktype==SHARED_LOCK && !getReadLock(pFile) ){
34290 /* This should never happen. We should always be able to
34291 ** reacquire the read lock */
34292 rc = winLogError(SQLITE_IOERR_UNLOCK, osGetLastError(),
34293 "winUnlock", pFile->zPath);
34294 }
34295 }
34296 if( type>=RESERVED_LOCK ){
34297 osUnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
34298 }
34299 if( locktype==NO_LOCK && type>=SHARED_LOCK ){
34300 unlockReadLock(pFile);
34301 }
34302 if( type>=PENDING_LOCK ){
34303 osUnlockFile(pFile->h, PENDING_BYTE, 0, 1, 0);
34304 }
34305 pFile->locktype = (u8)locktype;
34306 return rc;
34307 }
34308
@@ -34536,29 +34995,23 @@
34536 winShmNode *pFile, /* Apply locks to this open shared-memory segment */
34537 int lockType, /* _SHM_UNLCK, _SHM_RDLCK, or _SHM_WRLCK */
34538 int ofst, /* Offset to first byte to be locked/unlocked */
34539 int nByte /* Number of bytes to lock or unlock */
34540 ){
34541 OVERLAPPED ovlp;
34542 DWORD dwFlags;
34543 int rc = 0; /* Result code form Lock/UnlockFileEx() */
34544
34545 /* Access to the winShmNode object is serialized by the caller */
34546 assert( sqlite3_mutex_held(pFile->mutex) || pFile->nRef==0 );
34547
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 */
34556 if( lockType==_SHM_UNLCK ){
34557 rc = osUnlockFileEx(pFile->hFile.h, 0, nByte, 0, &ovlp);
34558 }else{
34559 rc = osLockFileEx(pFile->hFile.h, dwFlags, 0, nByte, 0, &ovlp);
 
 
 
34560 }
34561
34562 if( rc!= 0 ){
34563 rc = SQLITE_OK;
34564 }else{
@@ -34992,22 +35445,34 @@
34992
34993 while( pShmNode->nRegion<=iRegion ){
34994 HANDLE hMap; /* file-mapping handle */
34995 void *pMap = 0; /* Mapped memory region */
34996
34997 hMap = osCreateFileMapping(pShmNode->hFile.h,
 
 
 
 
 
34998 NULL, PAGE_READWRITE, 0, nByte, NULL
34999 );
 
35000 OSTRACE(("SHM-MAP pid-%d create region=%d nbyte=%d %s\n",
35001 (int)osGetCurrentProcessId(), pShmNode->nRegion, nByte,
35002 hMap ? "ok" : "failed"));
35003 if( hMap ){
35004 int iOffset = pShmNode->nRegion*szRegion;
35005 int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity;
 
 
 
 
 
35006 pMap = osMapViewOfFile(hMap, FILE_MAP_WRITE | FILE_MAP_READ,
35007 0, iOffset - iOffsetShift, szRegion + iOffsetShift
35008 );
 
35009 OSTRACE(("SHM-MAP pid-%d map region=%d offset=%d size=%d %s\n",
35010 (int)osGetCurrentProcessId(), pShmNode->nRegion, iOffset,
35011 szRegion, pMap ? "ok" : "failed"));
35012 }
35013 if( !pMap ){
@@ -35089,17 +35554,16 @@
35089 */
35090 static void *convertUtf8Filename(const char *zFilename){
35091 void *zConverted = 0;
35092 if( isNT() ){
35093 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
35097 }else{
35098 zConverted = sqlite3_win32_utf8_to_mbcs(zFilename);
 
35099 #endif
35100 }
35101 /* caller will handle out of memory */
35102 return zConverted;
35103 }
35104
35105 /*
@@ -35110,21 +35574,26 @@
35110 static char zChars[] =
35111 "abcdefghijklmnopqrstuvwxyz"
35112 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
35113 "0123456789";
35114 size_t i, j;
 
35115 char zTempPath[MAX_PATH+2];
35116
35117 /* 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
35119 ** function failing.
35120 */
35121 SimulateIOError( return SQLITE_IOERR );
35122
 
 
35123 if( sqlite3_temp_directory ){
35124 sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", sqlite3_temp_directory);
35125 }else if( isNT() ){
 
 
35126 char *zMulti;
35127 WCHAR zWidePath[MAX_PATH];
35128 osGetTempPathW(MAX_PATH-30, zWidePath);
35129 zMulti = unicodeToUtf8(zWidePath);
35130 if( zMulti ){
@@ -35131,16 +35600,13 @@
35131 sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zMulti);
35132 sqlite3_free(zMulti);
35133 }else{
35134 return SQLITE_IOERR_NOMEM;
35135 }
35136 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
35137 ** Since the ANSI version of these Windows API do not exist for WINCE,
35138 ** it's important to not reference them for WINCE builds.
35139 */
35140 #if SQLITE_OS_WINCE==0
35141 }else{
35142 char *zUtf8;
35143 char zMbcsPath[MAX_PATH];
35144 osGetTempPathA(MAX_PATH-30, zMbcsPath);
35145 zUtf8 = sqlite3_win32_mbcs_to_utf8(zMbcsPath);
35146 if( zUtf8 ){
@@ -35147,25 +35613,29 @@
35147 sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zUtf8);
35148 sqlite3_free(zUtf8);
35149 }else{
35150 return SQLITE_IOERR_NOMEM;
35151 }
 
35152 #endif
35153 }
35154
35155 /* Check that the output buffer is large enough for the temporary file
35156 ** name. If it is not, return SQLITE_ERROR.
35157 */
35158 if( (sqlite3Strlen30(zTempPath) + sqlite3Strlen30(SQLITE_TEMP_FILE_PREFIX) + 18) >= nBuf ){
 
 
35159 return SQLITE_ERROR;
35160 }
35161
35162 for(i=sqlite3Strlen30(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){}
35163 zTempPath[i] = 0;
35164
35165 sqlite3_snprintf(nBuf-18, zBuf,
35166 "%s\\"SQLITE_TEMP_FILE_PREFIX, zTempPath);
 
35167 j = sqlite3Strlen30(zBuf);
35168 sqlite3_randomness(15, &zBuf[j]);
35169 for(i=0; i<15; i++, j++){
35170 zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
35171 }
@@ -35357,33 +35827,52 @@
35357 #if SQLITE_OS_WINCE
35358 dwFlagsAndAttributes |= FILE_FLAG_RANDOM_ACCESS;
35359 #endif
35360
35361 if( isNT() ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35362 while( (h = osCreateFileW((LPCWSTR)zConverted,
35363 dwDesiredAccess,
35364 dwShareMode, NULL,
35365 dwCreationDisposition,
35366 dwFlagsAndAttributes,
35367 NULL))==INVALID_HANDLE_VALUE &&
35368 retryIoerr(&cnt, &lastErrno) ){
35369 /* Noop */
35370 }
35371 #if SQLITE_OS_WINCE==0
35372 }else{
 
 
35373 while( (h = osCreateFileA((LPCSTR)zConverted,
35374 dwDesiredAccess,
35375 dwShareMode, NULL,
35376 dwCreationDisposition,
35377 dwFlagsAndAttributes,
35378 NULL))==INVALID_HANDLE_VALUE &&
35379 retryIoerr(&cnt, &lastErrno) ){
35380 /* Noop */
35381 }
 
35382 #endif
35383 }
35384
35385 logIoerr(cnt);
35386
35387 OSTRACE(("OPEN %d %s 0x%lx %s\n",
35388 h, zName, dwDesiredAccess,
35389 h==INVALID_HANDLE_VALUE ? "failed" : "ok"));
@@ -35469,11 +35958,23 @@
35469 if( zConverted==0 ){
35470 return SQLITE_IOERR_NOMEM;
35471 }
35472 if( isNT() ){
35473 do {
 
 
 
 
 
 
 
 
 
 
 
35474 attr = osGetFileAttributesW(zConverted);
 
35475 if ( attr==INVALID_FILE_ATTRIBUTES ){
35476 rc = SQLITE_OK; /* Already gone? */
35477 break;
35478 }
35479 if ( attr&FILE_ATTRIBUTE_DIRECTORY ){
@@ -35487,16 +35988,13 @@
35487 if ( !retryIoerr(&cnt, &lastErrno) ){
35488 rc = SQLITE_ERROR; /* No more retries. */
35489 break;
35490 }
35491 } while(1);
35492 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
35493 ** Since the ANSI version of these Windows API do not exist for WINCE,
35494 ** it's important to not reference them for WINCE builds.
35495 */
35496 #if SQLITE_OS_WINCE==0
35497 }else{
35498 do {
35499 attr = osGetFileAttributesA(zConverted);
35500 if ( attr==INVALID_FILE_ATTRIBUTES ){
35501 rc = SQLITE_OK; /* Already gone? */
35502 break;
@@ -35512,12 +36010,12 @@
35512 if ( !retryIoerr(&cnt, &lastErrno) ){
35513 rc = SQLITE_ERROR; /* No more retries. */
35514 break;
35515 }
35516 } while(1);
 
35517 #endif
35518 }
35519 if( rc ){
35520 rc = winLogError(SQLITE_IOERR_DELETE, lastErrno,
35521 "winDelete", zFilename);
35522 }else{
35523 logIoerr(cnt);
@@ -35573,19 +36071,16 @@
35573 return SQLITE_IOERR_ACCESS;
35574 }else{
35575 attr = INVALID_FILE_ATTRIBUTES;
35576 }
35577 }
35578 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
35579 ** Since the ANSI version of these Windows API do not exist for WINCE,
35580 ** it's important to not reference them for WINCE builds.
35581 */
35582 #if SQLITE_OS_WINCE==0
35583 }else{
35584 attr = osGetFileAttributesA((char*)zConverted);
 
35585 #endif
35586 }
35587 sqlite3_free(zConverted);
35588 switch( flags ){
35589 case SQLITE_ACCESS_READ:
35590 case SQLITE_ACCESS_EXISTS:
35591 rc = attr!=INVALID_FILE_ATTRIBUTES;
@@ -35599,10 +36094,47 @@
35599 }
35600 *pResOut = rc;
35601 return SQLITE_OK;
35602 }
35603
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35604
35605 /*
35606 ** Turn a relative pathname into a full pathname. Write the full
35607 ** pathname into zOut[]. zOut[] will be at least pVfs->mxPathname
35608 ** bytes in size.
@@ -35615,23 +36147,55 @@
35615 ){
35616
35617 #if defined(__CYGWIN__)
35618 SimulateIOError( return SQLITE_ERROR );
35619 UNUSED_PARAMETER(nFull);
35620 cygwin_conv_to_full_win32_path(zRelative, zFull);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35621 return SQLITE_OK;
35622 #endif
35623
35624 #if SQLITE_OS_WINCE
35625 SimulateIOError( return SQLITE_ERROR );
35626 UNUSED_PARAMETER(nFull);
35627 /* WinCE has no concept of a relative pathname, or so I am told. */
35628 sqlite3_snprintf(pVfs->mxPathname, zFull, "%s", zRelative);
 
 
 
 
 
 
 
 
 
 
 
 
35629 return SQLITE_OK;
35630 #endif
35631
35632 #if !SQLITE_OS_WINCE && !defined(__CYGWIN__)
35633 int nByte;
35634 void *zConverted;
35635 char *zOut;
35636
35637 /* If this path name begins with "/X:", where "X" is any alphabetic
@@ -35645,11 +36209,21 @@
35645 ** using the io-error infrastructure to test that SQLite handles this
35646 ** function failing. This function could fail if, for example, the
35647 ** current working directory has been unlinked.
35648 */
35649 SimulateIOError( return SQLITE_ERROR );
35650 UNUSED_PARAMETER(nFull);
 
 
 
 
 
 
 
 
 
 
35651 zConverted = convertUtf8Filename(zRelative);
35652 if( zConverted==0 ){
35653 return SQLITE_IOERR_NOMEM;
35654 }
35655 if( isNT() ){
@@ -35662,16 +36236,13 @@
35662 }
35663 osGetFullPathNameW((LPCWSTR)zConverted, nByte, zTemp, 0);
35664 sqlite3_free(zConverted);
35665 zOut = unicodeToUtf8(zTemp);
35666 sqlite3_free(zTemp);
35667 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
35668 ** Since the ANSI version of these Windows API do not exist for WINCE,
35669 ** it's important to not reference them for WINCE builds.
35670 */
35671 #if SQLITE_OS_WINCE==0
35672 }else{
35673 char *zTemp;
35674 nByte = osGetFullPathNameA((char*)zConverted, 0, 0, 0) + 3;
35675 zTemp = sqlite3_malloc( nByte*sizeof(zTemp[0]) );
35676 if( zTemp==0 ){
35677 sqlite3_free(zConverted);
@@ -35679,14 +36250,14 @@
35679 }
35680 osGetFullPathNameA((char*)zConverted, nByte, zTemp, 0);
35681 sqlite3_free(zConverted);
35682 zOut = sqlite3_win32_mbcs_to_utf8(zTemp);
35683 sqlite3_free(zTemp);
 
35684 #endif
35685 }
35686 if( zOut ){
35687 sqlite3_snprintf(pVfs->mxPathname, zFull, "%s", zOut);
35688 sqlite3_free(zOut);
35689 return SQLITE_OK;
35690 }else{
35691 return SQLITE_IOERR_NOMEM;
35692 }
@@ -35708,20 +36279,21 @@
35708 UNUSED_PARAMETER(pVfs);
35709 if( zConverted==0 ){
35710 return 0;
35711 }
35712 if( isNT() ){
 
 
 
35713 h = osLoadLibraryW((LPCWSTR)zConverted);
35714 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
35715 ** Since the ANSI version of these Windows API do not exist for WINCE,
35716 ** it's important to not reference them for WINCE builds.
35717 */
35718 #if SQLITE_OS_WINCE==0
35719 }else{
35720 h = osLoadLibraryA((char*)zConverted);
 
35721 #endif
35722 }
35723 sqlite3_free(zConverted);
35724 return (void*)h;
35725 }
35726 static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){
35727 UNUSED_PARAMETER(pVfs);
@@ -35762,15 +36334,23 @@
35762 if( sizeof(DWORD)<=nBuf-n ){
35763 DWORD pid = osGetCurrentProcessId();
35764 memcpy(&zBuf[n], &pid, sizeof(pid));
35765 n += sizeof(pid);
35766 }
 
 
 
 
 
 
 
35767 if( sizeof(DWORD)<=nBuf-n ){
35768 DWORD cnt = osGetTickCount();
35769 memcpy(&zBuf[n], &cnt, sizeof(cnt));
35770 n += sizeof(cnt);
35771 }
 
35772 if( sizeof(LARGE_INTEGER)<=nBuf-n ){
35773 LARGE_INTEGER i;
35774 osQueryPerformanceCounter(&i);
35775 memcpy(&zBuf[n], &i, sizeof(i));
35776 n += sizeof(i);
@@ -35782,11 +36362,11 @@
35782
35783 /*
35784 ** Sleep for a little while. Return the amount of time slept.
35785 */
35786 static int winSleep(sqlite3_vfs *pVfs, int microsec){
35787 osSleep((microsec+999)/1000);
35788 UNUSED_PARAMETER(pVfs);
35789 return ((microsec+999)/1000)*1000;
35790 }
35791
35792 /*
@@ -35924,24 +36504,34 @@
35924 winNextSystemCall, /* xNextSystemCall */
35925 };
35926
35927 /* Double-check that the aSyscall[] array has been constructed
35928 ** correctly. See ticket [bb3a86e890c8e96ab] */
35929 assert( ArraySize(aSyscall)==60 );
35930
35931 #ifndef SQLITE_OMIT_WAL
35932 /* get memory map allocation granularity */
35933 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
 
 
 
35934 osGetSystemInfo(&winSysInfo);
 
35935 assert(winSysInfo.dwAllocationGranularity > 0);
35936 #endif
35937
35938 sqlite3_vfs_register(&winVfs, 1);
35939 return SQLITE_OK;
35940 }
35941
35942 SQLITE_API int sqlite3_os_end(void){
 
 
 
 
 
 
35943 return SQLITE_OK;
35944 }
35945
35946 #endif /* SQLITE_OS_WIN */
35947
@@ -37189,16 +37779,18 @@
37189 if( p==0 ){
37190 /* Memory is not available in the SQLITE_CONFIG_PAGECACHE pool. Get
37191 ** it from sqlite3Malloc instead.
37192 */
37193 p = sqlite3Malloc(nByte);
 
37194 if( p ){
37195 int sz = sqlite3MallocSize(p);
37196 sqlite3_mutex_enter(pcache1.mutex);
37197 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz);
37198 sqlite3_mutex_leave(pcache1.mutex);
37199 }
 
37200 sqlite3MemdebugSetType(p, MEMTYPE_PCACHE);
37201 }
37202 return p;
37203 }
37204
@@ -37221,13 +37813,15 @@
37221 sqlite3_mutex_leave(pcache1.mutex);
37222 }else{
37223 assert( sqlite3MemdebugHasType(p, MEMTYPE_PCACHE) );
37224 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
37225 nFreed = sqlite3MallocSize(p);
 
37226 sqlite3_mutex_enter(pcache1.mutex);
37227 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -nFreed);
37228 sqlite3_mutex_leave(pcache1.mutex);
 
37229 sqlite3_free(p);
37230 }
37231 return nFreed;
37232 }
37233
@@ -43006,11 +43600,16 @@
43006 *ppPager = 0;
43007
43008 #ifndef SQLITE_OMIT_MEMORYDB
43009 if( flags & PAGER_MEMORY ){
43010 memDb = 1;
43011 zFilename = 0;
 
 
 
 
 
43012 }
43013 #endif
43014
43015 /* Compute and store the full pathname in an allocated buffer pointed
43016 ** to by zPathname, length nPathname. Or, if this is a temporary file,
@@ -43017,11 +43616,11 @@
43017 ** leave both nPathname and zPathname set to 0.
43018 */
43019 if( zFilename && zFilename[0] ){
43020 const char *z;
43021 nPathname = pVfs->mxPathname+1;
43022 zPathname = sqlite3Malloc(nPathname*2);
43023 if( zPathname==0 ){
43024 return SQLITE_NOMEM;
43025 }
43026 zPathname[0] = 0; /* Make sure initialized even if FullPathname() fails */
43027 rc = sqlite3OsFullPathname(pVfs, zFilename, nPathname, zPathname);
@@ -43041,11 +43640,11 @@
43041 ** check for a hot-journal before reading.
43042 */
43043 rc = SQLITE_CANTOPEN_BKPT;
43044 }
43045 if( rc!=SQLITE_OK ){
43046 sqlite3_free(zPathname);
43047 return rc;
43048 }
43049 }
43050
43051 /* Allocate memory for the Pager structure, PCache object, the
@@ -43071,11 +43670,11 @@
43071 + nPathname + 4 + 2 /* zWal */
43072 #endif
43073 );
43074 assert( EIGHT_BYTE_ALIGNMENT(SQLITE_INT_TO_PTR(journalFileSize)) );
43075 if( !pPtr ){
43076 sqlite3_free(zPathname);
43077 return SQLITE_NOMEM;
43078 }
43079 pPager = (Pager*)(pPtr);
43080 pPager->pPCache = (PCache*)(pPtr += ROUND8(sizeof(*pPager)));
43081 pPager->fd = (sqlite3_file*)(pPtr += ROUND8(pcacheSize));
@@ -43087,21 +43686,21 @@
43087 /* Fill in the Pager.zFilename and Pager.zJournal buffers, if required. */
43088 if( zPathname ){
43089 assert( nPathname>0 );
43090 pPager->zJournal = (char*)(pPtr += nPathname + 1 + nUri);
43091 memcpy(pPager->zFilename, zPathname, nPathname);
43092 memcpy(&pPager->zFilename[nPathname+1], zUri, nUri);
43093 memcpy(pPager->zJournal, zPathname, nPathname);
43094 memcpy(&pPager->zJournal[nPathname], "-journal\000", 8+1);
43095 sqlite3FileSuffix3(pPager->zFilename, pPager->zJournal);
43096 #ifndef SQLITE_OMIT_WAL
43097 pPager->zWal = &pPager->zJournal[nPathname+8+1];
43098 memcpy(pPager->zWal, zPathname, nPathname);
43099 memcpy(&pPager->zWal[nPathname], "-wal\000", 4+1);
43100 sqlite3FileSuffix3(pPager->zFilename, pPager->zWal);
43101 #endif
43102 sqlite3_free(zPathname);
43103 }
43104 pPager->pVfs = pVfs;
43105 pPager->vfsFlags = vfsFlags;
43106
43107 /* Open the pager file.
@@ -44942,13 +45541,20 @@
44942 return rc;
44943 }
44944
44945 /*
44946 ** Return the full pathname of the database file.
 
 
 
 
 
 
 
44947 */
44948 SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager *pPager){
44949 return pPager->zFilename;
44950 }
44951
44952 /*
44953 ** Return the VFS structure for the pager.
44954 */
@@ -51329,11 +51935,12 @@
51329 */
51330 #ifdef SQLITE_OMIT_MEMORYDB
51331 const int isMemdb = 0;
51332 #else
51333 const int isMemdb = (zFilename && strcmp(zFilename, ":memory:")==0)
51334 || (isTempDb && sqlite3TempInMemory(db));
 
51335 #endif
51336
51337 assert( db!=0 );
51338 assert( pVfs!=0 );
51339 assert( sqlite3_mutex_held(db->mutex) );
@@ -51365,35 +51972,40 @@
51365 #if !defined(SQLITE_OMIT_SHARED_CACHE) && !defined(SQLITE_OMIT_DISKIO)
51366 /*
51367 ** If this Btree is a candidate for shared cache, try to find an
51368 ** existing BtShared object that we can share with
51369 */
51370 if( isMemdb==0 && isTempDb==0 ){
51371 if( vfsFlags & SQLITE_OPEN_SHAREDCACHE ){
51372 int nFullPathname = pVfs->mxPathname+1;
51373 char *zFullPathname = sqlite3Malloc(nFullPathname);
51374 MUTEX_LOGIC( sqlite3_mutex *mutexShared; )
51375 p->sharable = 1;
51376 if( !zFullPathname ){
51377 sqlite3_free(p);
51378 return SQLITE_NOMEM;
51379 }
51380 rc = sqlite3OsFullPathname(pVfs, zFilename, nFullPathname, zFullPathname);
51381 if( rc ){
51382 sqlite3_free(zFullPathname);
51383 sqlite3_free(p);
51384 return rc;
 
 
 
 
 
51385 }
51386 #if SQLITE_THREADSAFE
51387 mutexOpen = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_OPEN);
51388 sqlite3_mutex_enter(mutexOpen);
51389 mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
51390 sqlite3_mutex_enter(mutexShared);
51391 #endif
51392 for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){
51393 assert( pBt->nRef>0 );
51394 if( 0==strcmp(zFullPathname, sqlite3PagerFilename(pBt->pPager))
51395 && sqlite3PagerVfs(pBt->pPager)==pVfs ){
51396 int iDb;
51397 for(iDb=db->nDb-1; iDb>=0; iDb--){
51398 Btree *pExisting = db->aDb[iDb].pBt;
51399 if( pExisting && pExisting->pBt==pBt ){
@@ -57654,18 +58266,19 @@
57654 return sqlite3StrAccumFinish(&sCheck.errMsg);
57655 }
57656 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
57657
57658 /*
57659 ** Return the full pathname of the underlying database file.
 
57660 **
57661 ** The pager filename is invariant as long as the pager is
57662 ** open so it is safe to access without the BtShared mutex.
57663 */
57664 SQLITE_PRIVATE const char *sqlite3BtreeGetFilename(Btree *p){
57665 assert( p->pBt->pPager!=0 );
57666 return sqlite3PagerFilename(p->pBt->pPager);
57667 }
57668
57669 /*
57670 ** 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
@@ -58312,11 +58925,11 @@
58312 */
58313 if( rc==SQLITE_DONE ){
58314 rc = sqlite3BtreeUpdateMeta(p->pDest,1,p->iDestSchema+1);
58315 if( rc==SQLITE_OK ){
58316 if( p->pDestDb ){
58317 sqlite3ResetInternalSchema(p->pDestDb, -1);
58318 }
58319 if( destMode==PAGER_JOURNALMODE_WAL ){
58320 rc = sqlite3BtreeSetVersion(p->pDest, 2);
58321 }
58322 }
@@ -64497,12 +65110,13 @@
64497 /*
64498 ** Allocate a new Explain object
64499 */
64500 SQLITE_PRIVATE void sqlite3ExplainBegin(Vdbe *pVdbe){
64501 if( pVdbe ){
 
64502 sqlite3BeginBenignMalloc();
64503 Explain *p = sqlite3_malloc( sizeof(Explain) );
64504 if( p ){
64505 memset(p, 0, sizeof(*p));
64506 p->pVdbe = pVdbe;
64507 sqlite3_free(pVdbe->pExplain);
64508 pVdbe->pExplain = p;
@@ -67896,11 +68510,11 @@
67896 goto abort_due_to_error;
67897 }
67898 }
67899 if( u.ar.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
67900 sqlite3ExpirePreparedStatements(db);
67901 sqlite3ResetInternalSchema(db, -1);
67902 db->flags = (db->flags | SQLITE_InternChanges);
67903 }
67904 }
67905
67906 /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
@@ -68210,11 +68824,11 @@
68210 ** v-table would have to be ready for the sqlite3_vtab structure itself
68211 ** to be invalidated whenever sqlite3_step() is called from within
68212 ** a v-table method.
68213 */
68214 if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.aw.iMeta ){
68215 sqlite3ResetInternalSchema(db, pOp->p1);
68216 }
68217
68218 p->expired = 1;
68219 rc = SQLITE_SCHEMA;
68220 }
@@ -70079,11 +70693,11 @@
70079 if( rc==SQLITE_OK ) rc = u.by.initData.rc;
70080 sqlite3DbFree(db, u.by.zSql);
70081 db->init.busy = 0;
70082 }
70083 }
70084 if( rc ) sqlite3ResetInternalSchema(db, -1);
70085 if( rc==SQLITE_NOMEM ){
70086 goto no_mem;
70087 }
70088 break;
70089 }
@@ -70746,11 +71360,11 @@
70746 u.ci.eOld = sqlite3PagerGetJournalMode(u.ci.pPager);
70747 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;
70749
70750 #ifndef SQLITE_OMIT_WAL
70751 u.ci.zFilename = sqlite3PagerFilename(u.ci.pPager);
70752
70753 /* 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
70755 */
70756 if( u.ci.eNew==PAGER_JOURNALMODE_WAL
@@ -71412,11 +72026,11 @@
71412 pc, p->zSql, p->zErrMsg);
71413 sqlite3VdbeHalt(p);
71414 if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1;
71415 rc = SQLITE_ERROR;
71416 if( resetSchemaOnFault>0 ){
71417 sqlite3ResetInternalSchema(db, resetSchemaOnFault-1);
71418 }
71419
71420 /* This is the only way out of this procedure. We have to
71421 ** release the mutexes on btrees that were acquired at the
71422 ** top. */
@@ -73767,11 +74381,11 @@
73767 Expr *pOrig;
73768 assert( pExpr->pLeft==0 && pExpr->pRight==0 );
73769 assert( pExpr->x.pList==0 );
73770 assert( pExpr->x.pSelect==0 );
73771 pOrig = pEList->a[j].pExpr;
73772 if( !pNC->allowAgg && ExprHasProperty(pOrig, EP_Agg) ){
73773 sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs);
73774 return WRC_Abort;
73775 }
73776 resolveAlias(pParse, pEList, j, pExpr, "");
73777 cnt = 1;
@@ -74012,11 +74626,11 @@
74012 pExpr->op = TK_NULL;
74013 return WRC_Prune;
74014 }
74015 }
74016 #endif
74017 if( is_agg && !pNC->allowAgg ){
74018 sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId);
74019 pNC->nErr++;
74020 is_agg = 0;
74021 }else if( no_such_func ){
74022 sqlite3ErrorMsg(pParse, "no such function: %.*s", nId, zId);
@@ -74026,15 +74640,15 @@
74026 nId, zId);
74027 pNC->nErr++;
74028 }
74029 if( is_agg ){
74030 pExpr->op = TK_AGG_FUNCTION;
74031 pNC->hasAgg = 1;
74032 }
74033 if( is_agg ) pNC->allowAgg = 0;
74034 sqlite3WalkExprList(pWalker, pList);
74035 if( is_agg ) pNC->allowAgg = 1;
74036 /* FIX ME: Compute pExpr->affinity based on the expected return
74037 ** type of the function
74038 */
74039 return WRC_Prune;
74040 }
@@ -74045,11 +74659,11 @@
74045 case TK_IN: {
74046 testcase( pExpr->op==TK_IN );
74047 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
74048 int nRef = pNC->nRef;
74049 #ifndef SQLITE_OMIT_CHECK
74050 if( pNC->isCheck ){
74051 sqlite3ErrorMsg(pParse,"subqueries prohibited in CHECK constraints");
74052 }
74053 #endif
74054 sqlite3WalkSelect(pWalker, pExpr->x.pSelect);
74055 assert( pNC->nRef>=nRef );
@@ -74059,11 +74673,11 @@
74059 }
74060 break;
74061 }
74062 #ifndef SQLITE_OMIT_CHECK
74063 case TK_VARIABLE: {
74064 if( pNC->isCheck ){
74065 sqlite3ErrorMsg(pParse,"parameters prohibited in CHECK constraints");
74066 }
74067 break;
74068 }
74069 #endif
@@ -74141,11 +74755,11 @@
74141 */
74142 memset(&nc, 0, sizeof(nc));
74143 nc.pParse = pParse;
74144 nc.pSrcList = pSelect->pSrc;
74145 nc.pEList = pEList;
74146 nc.allowAgg = 1;
74147 nc.nErr = 0;
74148 db = pParse->db;
74149 savedSuppErr = db->suppressErr;
74150 db->suppressErr = 1;
74151 rc = sqlite3ResolveExprNames(&nc, pE);
@@ -74443,11 +75057,11 @@
74443 }
74444
74445 /* Set up the local name-context to pass to sqlite3ResolveExprNames() to
74446 ** resolve the result-set expression list.
74447 */
74448 sNC.allowAgg = 1;
74449 sNC.pSrcList = p->pSrc;
74450 sNC.pNext = pOuterNC;
74451
74452 /* Resolve names in the result set. */
74453 pEList = p->pEList;
@@ -74489,14 +75103,14 @@
74489 /* 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.
74491 */
74492 assert( (p->selFlags & SF_Aggregate)==0 );
74493 pGroupBy = p->pGroupBy;
74494 if( pGroupBy || sNC.hasAgg ){
74495 p->selFlags |= SF_Aggregate;
74496 }else{
74497 sNC.allowAgg = 0;
74498 }
74499
74500 /* If a HAVING clause is present, then there must be a GROUP BY clause.
74501 */
74502 if( p->pHaving && !pGroupBy ){
@@ -74521,11 +75135,11 @@
74521
74522 /* The ORDER BY and GROUP BY clauses may not refer to terms in
74523 ** outer queries
74524 */
74525 sNC.pNext = 0;
74526 sNC.allowAgg = 1;
74527
74528 /* Process the ORDER BY clause for singleton SELECT statements.
74529 ** The ORDER BY clause for compounds SELECT statements is handled
74530 ** below, after all of the result-sets for all of the elements of
74531 ** the compound have been resolved.
@@ -74609,11 +75223,11 @@
74609 **
74610 ** SELECT a+b AS x, c+d AS y FROM t1 ORDER BY a+b;
74611 **
74612 ** Function calls are checked to make sure that the function is
74613 ** defined and that the correct number of arguments are specified.
74614 ** If the function is an aggregate function, then the pNC->hasAgg is
74615 ** set and the opcode is changed from TK_FUNCTION to TK_AGG_FUNCTION.
74616 ** If an expression contains aggregate functions then the EP_Agg
74617 ** property on the expression is set.
74618 **
74619 ** An error message is left in pParse if anything is amiss. The number
@@ -74621,11 +75235,11 @@
74621 */
74622 SQLITE_PRIVATE int sqlite3ResolveExprNames(
74623 NameContext *pNC, /* Namespace to resolve expressions in. */
74624 Expr *pExpr /* The expression to be analyzed. */
74625 ){
74626 int savedHasAgg;
74627 Walker w;
74628
74629 if( pExpr==0 ) return 0;
74630 #if SQLITE_MAX_EXPR_DEPTH>0
74631 {
@@ -74634,12 +75248,12 @@
74634 return 1;
74635 }
74636 pParse->nHeight += pExpr->nHeight;
74637 }
74638 #endif
74639 savedHasAgg = pNC->hasAgg;
74640 pNC->hasAgg = 0;
74641 w.xExprCallback = resolveExprStep;
74642 w.xSelectCallback = resolveSelectStep;
74643 w.pParse = pNC->pParse;
74644 w.u.pNC = pNC;
74645 sqlite3WalkExpr(&w, pExpr);
@@ -74647,14 +75261,14 @@
74647 pNC->pParse->nHeight -= pExpr->nHeight;
74648 #endif
74649 if( pNC->nErr>0 || w.pParse->nErr>0 ){
74650 ExprSetProperty(pExpr, EP_Error);
74651 }
74652 if( pNC->hasAgg ){
74653 ExprSetProperty(pExpr, EP_Agg);
74654 }else if( savedHasAgg ){
74655 pNC->hasAgg = 1;
74656 }
74657 return ExprHasProperty(pExpr, EP_Error);
74658 }
74659
74660
@@ -78464,11 +79078,11 @@
78464 if( pA->iTable!=pB->iTable || pA->iColumn!=pB->iColumn ) return 2;
78465 if( ExprHasProperty(pA, EP_IntValue) ){
78466 if( !ExprHasProperty(pB, EP_IntValue) || pA->u.iValue!=pB->u.iValue ){
78467 return 2;
78468 }
78469 }else if( pA->op!=TK_COLUMN && pA->op!=TK_AGG_COLUMN && pA->u.zToken ){
78470 if( ExprHasProperty(pB, EP_IntValue) || NEVER(pB->u.zToken==0) ) return 2;
78471 if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){
78472 return 2;
78473 }
78474 }
@@ -78651,11 +79265,13 @@
78651 } /* end loop over pSrcList */
78652 }
78653 return WRC_Prune;
78654 }
78655 case TK_AGG_FUNCTION: {
78656 if( !sqlite3FunctionUsesOtherSrc(pExpr, pSrcList) ){
 
 
78657 /* Check to see if pExpr is a duplicate of another aggregate
78658 ** function that is already in the pAggInfo structure
78659 */
78660 struct AggInfo_func *pItem = pAggInfo->aFunc;
78661 for(i=0; i<pAggInfo->nFunc; i++, pItem++){
@@ -78688,12 +79304,12 @@
78688 */
78689 assert( !ExprHasAnyProperty(pExpr, EP_TokenOnly|EP_Reduced) );
78690 ExprSetIrreducible(pExpr);
78691 pExpr->iAgg = (i16)i;
78692 pExpr->pAggInfo = pAggInfo;
78693 return WRC_Prune;
78694 }
 
78695 }
78696 }
78697 return WRC_Continue;
78698 }
78699 static int analyzeAggregatesInSelect(Walker *pWalker, Select *pSelect){
@@ -80973,11 +81589,11 @@
80973 if( db->aDb[iDb].pBt ){
80974 sqlite3BtreeClose(db->aDb[iDb].pBt);
80975 db->aDb[iDb].pBt = 0;
80976 db->aDb[iDb].pSchema = 0;
80977 }
80978 sqlite3ResetInternalSchema(db, -1);
80979 db->nDb = iDb;
80980 if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){
80981 db->mallocFailed = 1;
80982 sqlite3DbFree(db, zErrDyn);
80983 zErrDyn = sqlite3MPrintf(db, "out of memory");
@@ -81045,11 +81661,11 @@
81045 }
81046
81047 sqlite3BtreeClose(pDb->pBt);
81048 pDb->pBt = 0;
81049 pDb->pSchema = 0;
81050 sqlite3ResetInternalSchema(db, -1);
81051 return;
81052
81053 detach_error:
81054 sqlite3_result_error(context, zErr, -1);
81055 }
@@ -81961,62 +82577,19 @@
81961 }
81962 db->flags |= SQLITE_InternChanges;
81963 }
81964
81965 /*
81966 ** Erase all schema information from the in-memory hash tables of
81967 ** a single database. This routine is called to reclaim memory
81968 ** before the database closes. It is also called during a rollback
81969 ** if there were schema changes during the transaction or if a
81970 ** schema-cookie mismatch occurs.
81971 **
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.
81975 */
81976 SQLITE_PRIVATE void sqlite3ResetInternalSchema(sqlite3 *db, int iDb){
81977 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++){
82019 struct Db *pDb = &db->aDb[i];
82020 if( pDb->pBt==0 ){
82021 sqlite3DbFree(db, pDb->zName);
82022 pDb->zName = 0;
@@ -82033,10 +82606,55 @@
82033 memcpy(db->aDbStatic, db->aDb, 2*sizeof(db->aDb[0]));
82034 sqlite3DbFree(db, db->aDb);
82035 db->aDb = db->aDbStatic;
82036 }
82037 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82038
82039 /*
82040 ** This routine is called when a commit occurs.
82041 */
82042 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3 *db){
@@ -82069,19 +82687,32 @@
82069 **
82070 ** This routine just deletes the data structure. It does not unlink
82071 ** the table data structure from the hash table. But it does destroy
82072 ** memory structures of the indices and foreign keys associated with
82073 ** the table.
 
 
 
 
 
 
82074 */
82075 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
82076 Index *pIndex, *pNext;
 
82077
82078 assert( !pTable || pTable->nRef>0 );
82079
82080 /* Do not delete the table until the reference count reaches zero. */
82081 if( !pTable ) return;
82082 if( ((!db || db->pnBytesFreed==0) && (--pTable->nRef)>0) ) return;
 
 
 
 
 
 
82083
82084 /* Delete all indices associated with this table. */
82085 for(pIndex = pTable->pIndex; pIndex; pIndex=pNext){
82086 pNext = pIndex->pNext;
82087 assert( pIndex->pSchema==pTable->pSchema );
@@ -82110,10 +82741,13 @@
82110 #endif
82111 #ifndef SQLITE_OMIT_VIRTUALTABLE
82112 sqlite3VtabClear(db, pTable);
82113 #endif
82114 sqlite3DbFree(db, pTable);
 
 
 
82115 }
82116
82117 /*
82118 ** Unlink the given table from the hash tables and the delete the
82119 ** table structure with all its indices and foreign keys.
@@ -83058,11 +83692,11 @@
83058 sSrc.a[0].zName = p->zName;
83059 sSrc.a[0].pTab = p;
83060 sSrc.a[0].iCursor = -1;
83061 sNC.pParse = pParse;
83062 sNC.pSrcList = &sSrc;
83063 sNC.isCheck = 1;
83064 pList = p->pCheck;
83065 for(i=0; i<pList->nExpr; i++){
83066 if( sqlite3ResolveExprNames(&sNC, pList->a[i].pExpr) ){
83067 return;
83068 }
@@ -84314,11 +84948,11 @@
84314 zExtra += nColl;
84315 nExtra -= nColl;
84316 }else{
84317 zColl = pTab->aCol[j].zColl;
84318 if( !zColl ){
84319 zColl = db->pDfltColl->zName;
84320 }
84321 }
84322 if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
84323 goto exit_create_index;
84324 }
@@ -92589,11 +93223,11 @@
92589 "from within a transaction");
92590 return SQLITE_ERROR;
92591 }
92592 sqlite3BtreeClose(db->aDb[1].pBt);
92593 db->aDb[1].pBt = 0;
92594 sqlite3ResetInternalSchema(db, -1);
92595 }
92596 return SQLITE_OK;
92597 }
92598 #endif /* SQLITE_PAGER_PRAGMAS */
92599
@@ -93274,10 +93908,54 @@
93274 sqlite3_temp_directory = 0;
93275 }
93276 #endif /* SQLITE_OMIT_WSD */
93277 }
93278 }else
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93279
93280 #if !defined(SQLITE_ENABLE_LOCKING_STYLE)
93281 # if defined(__APPLE__)
93282 # define SQLITE_ENABLE_LOCKING_STYLE 1
93283 # else
@@ -94307,11 +94985,10 @@
94307 u8 encoding;
94308 /* If opening the main database, set ENC(db). */
94309 encoding = (u8)meta[BTREE_TEXT_ENCODING-1] & 3;
94310 if( encoding==0 ) encoding = SQLITE_UTF8;
94311 ENC(db) = encoding;
94312 db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 0);
94313 }else{
94314 /* If opening an attached database, the encoding much match ENC(db) */
94315 if( meta[BTREE_TEXT_ENCODING-1]!=ENC(db) ){
94316 sqlite3SetString(pzErrMsg, db, "attached databases must use the same"
94317 " text encoding as main database");
@@ -94387,11 +95064,11 @@
94387 }
94388 #endif
94389 }
94390 if( db->mallocFailed ){
94391 rc = SQLITE_NOMEM;
94392 sqlite3ResetInternalSchema(db, -1);
94393 }
94394 if( rc==SQLITE_OK || (db->flags&SQLITE_RecoveryMode)){
94395 /* Black magic: If the SQLITE_RecoveryMode flag is set, then consider
94396 ** the schema loaded, even if errors occurred. In this situation the
94397 ** current sqlite3_prepare() operation will fail, but the following one
@@ -94440,11 +95117,11 @@
94440 db->init.busy = 1;
94441 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
94442 if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue;
94443 rc = sqlite3InitOne(db, i, pzErrMsg);
94444 if( rc ){
94445 sqlite3ResetInternalSchema(db, i);
94446 }
94447 }
94448
94449 /* Once all the other databases have been initialised, load the schema
94450 ** for the TEMP database. This is loaded last, as the TEMP database
@@ -94453,11 +95130,11 @@
94453 #ifndef SQLITE_OMIT_TEMPDB
94454 if( rc==SQLITE_OK && ALWAYS(db->nDb>1)
94455 && !DbHasProperty(db, 1, DB_SchemaLoaded) ){
94456 rc = sqlite3InitOne(db, 1, pzErrMsg);
94457 if( rc ){
94458 sqlite3ResetInternalSchema(db, 1);
94459 }
94460 }
94461 #endif
94462
94463 db->init.busy = 0;
@@ -94521,11 +95198,11 @@
94521 ** value stored as part of the in-memory schema representation,
94522 ** set Parse.rc to SQLITE_SCHEMA. */
94523 sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&cookie);
94524 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
94525 if( cookie!=db->aDb[iDb].pSchema->schema_cookie ){
94526 sqlite3ResetInternalSchema(db, iDb);
94527 pParse->rc = SQLITE_SCHEMA;
94528 }
94529
94530 /* Close the transaction, if one was opened. */
94531 if( openedTransaction ){
@@ -94751,10 +95428,11 @@
94751 sqlite3_finalize(*ppStmt);
94752 rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail);
94753 }
94754 sqlite3BtreeLeaveAll(db);
94755 sqlite3_mutex_leave(db->mutex);
 
94756 return rc;
94757 }
94758
94759 /*
94760 ** Rerun the compilation of a statement after a schema change.
@@ -98058,10 +98736,11 @@
98058 pExpr = p->pEList->a[0].pExpr;
98059 assert( pTab && !pTab->pSelect && pExpr );
98060
98061 if( IsVirtual(pTab) ) return 0;
98062 if( pExpr->op!=TK_AGG_FUNCTION ) return 0;
 
98063 if( (pAggInfo->aFunc[0].pFunc->flags&SQLITE_FUNC_COUNT)==0 ) return 0;
98064 if( pExpr->flags&EP_Distinct ) return 0;
98065
98066 return pTab;
98067 }
@@ -99048,11 +99727,13 @@
99048 sqlite3ExprAnalyzeAggregates(&sNC, pHaving);
99049 }
99050 sAggInfo.nAccumulator = sAggInfo.nColumn;
99051 for(i=0; i<sAggInfo.nFunc; i++){
99052 assert( !ExprHasProperty(sAggInfo.aFunc[i].pExpr, EP_xIsSelect) );
 
99053 sqlite3ExprAnalyzeAggList(&sNC, sAggInfo.aFunc[i].pExpr->x.pList);
 
99054 }
99055 if( db->mallocFailed ) goto select_end;
99056
99057 /* Processing for aggregates with GROUP BY is very different and
99058 ** much more complex than aggregates without a GROUP BY.
@@ -101870,11 +102551,11 @@
101870 pDb->pSchema = 0;
101871 }
101872
101873 /* This both clears the schemas and reduces the size of the db->aDb[]
101874 ** array. */
101875 sqlite3ResetInternalSchema(db, -1);
101876
101877 return rc;
101878 }
101879
101880 #endif /* SQLITE_OMIT_VACUUM && SQLITE_OMIT_ATTACH */
@@ -101902,12 +102583,12 @@
101902 ** 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
101904 ** are invoked only from within xCreate and xConnect methods.
101905 */
101906 struct VtabCtx {
101907 Table *pTab;
101908 VTable *pVTable;
101909 };
101910
101911 /*
101912 ** The actual function that does the work of creating a new module.
101913 ** This function implements the sqlite3_create_module() and
@@ -101918,37 +102599,39 @@
101918 const char *zName, /* Name assigned to this module */
101919 const sqlite3_module *pModule, /* The definition of the module */
101920 void *pAux, /* Context pointer for xCreate/xConnect */
101921 void (*xDestroy)(void *) /* Module destructor function */
101922 ){
101923 int rc, nName;
101924 Module *pMod;
101925
101926 sqlite3_mutex_enter(db->mutex);
101927 nName = sqlite3Strlen30(zName);
101928 pMod = (Module *)sqlite3DbMallocRaw(db, sizeof(Module) + nName + 1);
101929 if( pMod ){
101930 Module *pDel;
101931 char *zCopy = (char *)(&pMod[1]);
101932 memcpy(zCopy, zName, nName+1);
101933 pMod->zName = zCopy;
101934 pMod->pModule = pModule;
101935 pMod->pAux = pAux;
101936 pMod->xDestroy = xDestroy;
101937 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);
101943 if( pDel==pMod ){
101944 db->mallocFailed = 1;
101945 }
101946 }else if( xDestroy ){
101947 xDestroy(pAux);
101948 }
101949 rc = sqlite3ApiExit(db, SQLITE_OK);
 
 
101950 sqlite3_mutex_leave(db->mutex);
101951 return rc;
101952 }
101953
101954
@@ -102059,10 +102742,35 @@
102059 }
102060
102061 assert( !db || pRet );
102062 return pRet;
102063 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102064
102065
102066 /*
102067 ** Disconnect all the virtual table objects in the sqlite3.pDisconnect list.
102068 **
@@ -112949,10 +113657,19 @@
112949 **
112950 ** See also the "PRAGMA temp_store_directory" SQL command.
112951 */
112952 SQLITE_API char *sqlite3_temp_directory = 0;
112953
 
 
 
 
 
 
 
 
 
112954 /*
112955 ** Initialize SQLite.
112956 **
112957 ** This routine must be called to initialize the memory allocation,
112958 ** VFS, and mutex subsystems prior to doing any serious work with
@@ -113147,10 +113864,22 @@
113147 sqlite3GlobalConfig.isPCacheInit = 0;
113148 }
113149 if( sqlite3GlobalConfig.isMallocInit ){
113150 sqlite3MallocEnd();
113151 sqlite3GlobalConfig.isMallocInit = 0;
 
 
 
 
 
 
 
 
 
 
 
 
113152 }
113153 if( sqlite3GlobalConfig.isMutexInit ){
113154 sqlite3MutexEnd();
113155 sqlite3GlobalConfig.isMutexInit = 0;
113156 }
@@ -113594,10 +114323,34 @@
113594 pDestructor->xDestroy(pDestructor->pUserData);
113595 sqlite3DbFree(db, pDestructor);
113596 }
113597 }
113598 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113599
113600 /*
113601 ** Close an existing SQLite database
113602 */
113603 SQLITE_API int sqlite3_close(sqlite3 *db){
@@ -113610,14 +114363,14 @@
113610 if( !sqlite3SafetyCheckSickOrOk(db) ){
113611 return SQLITE_MISUSE_BKPT;
113612 }
113613 sqlite3_mutex_enter(db->mutex);
113614
113615 /* Force xDestroy calls on all virtual tables */
113616 sqlite3ResetInternalSchema(db, -1);
113617
113618 /* If a transaction is open, the ResetInternalSchema() call above
113619 ** will not have called the xDisconnect() method on any virtual
113620 ** tables in the db->aVTrans[] array. The following sqlite3VtabRollback()
113621 ** 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
113623 ** some prepared statements internally.
@@ -113644,10 +114397,11 @@
113644 }
113645
113646 /* Free any outstanding Savepoint structures. */
113647 sqlite3CloseSavepoints(db);
113648
 
113649 for(j=0; j<db->nDb; j++){
113650 struct Db *pDb = &db->aDb[j];
113651 if( pDb->pBt ){
113652 sqlite3BtreeClose(pDb->pBt);
113653 pDb->pBt = 0;
@@ -113654,19 +114408,26 @@
113654 if( j!=1 ){
113655 pDb->pSchema = 0;
113656 }
113657 }
113658 }
113659 sqlite3ResetInternalSchema(db, -1);
 
 
 
 
 
 
 
 
 
113660
113661 /* Tell the code in notify.c that the connection no longer holds any
113662 ** locks and does not require any further unlock-notify callbacks.
113663 */
113664 sqlite3ConnectionClosed(db);
113665
113666 assert( db->nDb<=2 );
113667 assert( db->aDb==db->aDbStatic );
113668 for(j=0; j<ArraySize(db->aFunc.a); j++){
113669 FuncDef *pNext, *pHash, *p;
113670 for(p=db->aFunc.a[j]; p; p=pHash){
113671 pHash = p->pHash;
113672 while( p ){
@@ -113749,11 +114510,11 @@
113749 sqlite3VtabRollback(db);
113750 sqlite3EndBenignMalloc();
113751
113752 if( db->flags&SQLITE_InternChanges ){
113753 sqlite3ExpirePreparedStatements(db);
113754 sqlite3ResetInternalSchema(db, -1);
113755 }
113756
113757 /* Any deferred constraint violations have now been resolved. */
113758 db->nDeferredCons = 0;
113759
@@ -114887,14 +115648,18 @@
114887 if( nOpt==4 && memcmp("mode", zOpt, 4)==0 ){
114888 static struct OpenMode aOpenMode[] = {
114889 { "ro", SQLITE_OPEN_READONLY },
114890 { "rw", SQLITE_OPEN_READWRITE },
114891 { "rwc", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE },
 
 
 
114892 { 0, 0 }
114893 };
114894
114895 mask = SQLITE_OPEN_READONLY|SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
 
114896 aMode = aOpenMode;
114897 limit = mask & flags;
114898 zModeType = "access";
114899 }
114900
@@ -114911,11 +115676,11 @@
114911 if( mode==0 ){
114912 *pzErrMsg = sqlite3_mprintf("no such %s mode: %s", zModeType, zVal);
114913 rc = SQLITE_ERROR;
114914 goto parse_uri_out;
114915 }
114916 if( mode>limit ){
114917 *pzErrMsg = sqlite3_mprintf("%s mode not allowed: %s",
114918 zModeType, zVal);
114919 rc = SQLITE_PERM;
114920 goto parse_uri_out;
114921 }
@@ -114930,10 +115695,11 @@
114930 zFile = sqlite3_malloc(nUri+2);
114931 if( !zFile ) return SQLITE_NOMEM;
114932 memcpy(zFile, zUri, nUri);
114933 zFile[nUri] = '\0';
114934 zFile[nUri+1] = '\0';
 
114935 }
114936
114937 *ppVfs = sqlite3_vfs_find(zVfs);
114938 if( *ppVfs==0 ){
114939 *pzErrMsg = sqlite3_mprintf("no such vfs: %s", zVfs);
@@ -117374,10 +118140,17 @@
117374 SQLITE_PRIVATE int sqlite3Fts3EvalPhrasePoslist(Fts3Cursor *, Fts3Expr *, int iCol, char **);
117375 SQLITE_PRIVATE int sqlite3Fts3MsrOvfl(Fts3Cursor *, Fts3MultiSegReader *, int *);
117376 SQLITE_PRIVATE int sqlite3Fts3MsrIncrRestart(Fts3MultiSegReader *pCsr);
117377
117378 SQLITE_PRIVATE int sqlite3Fts3DeferredTokenList(Fts3DeferredToken *, char **, int *);
 
 
 
 
 
 
 
117379
117380 #endif /* !SQLITE_CORE || SQLITE_ENABLE_FTS3 */
117381 #endif /* _FTSINT_H */
117382
117383 /************** End of fts3Int.h *********************************************/
@@ -120643,10 +121416,13 @@
120643 ** to by the argument to point to the "simple" tokenizer implementation.
120644 ** And so on.
120645 */
120646 SQLITE_PRIVATE void sqlite3Fts3SimpleTokenizerModule(sqlite3_tokenizer_module const**ppModule);
120647 SQLITE_PRIVATE void sqlite3Fts3PorterTokenizerModule(sqlite3_tokenizer_module const**ppModule);
 
 
 
120648 #ifdef SQLITE_ENABLE_ICU
120649 SQLITE_PRIVATE void sqlite3Fts3IcuTokenizerModule(sqlite3_tokenizer_module const**ppModule);
120650 #endif
120651
120652 /*
@@ -120658,15 +121434,22 @@
120658 SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){
120659 int rc = SQLITE_OK;
120660 Fts3Hash *pHash = 0;
120661 const sqlite3_tokenizer_module *pSimple = 0;
120662 const sqlite3_tokenizer_module *pPorter = 0;
 
 
 
120663
120664 #ifdef SQLITE_ENABLE_ICU
120665 const sqlite3_tokenizer_module *pIcu = 0;
120666 sqlite3Fts3IcuTokenizerModule(&pIcu);
120667 #endif
 
 
 
 
120668
120669 #ifdef SQLITE_TEST
120670 rc = sqlite3Fts3InitTerm(db);
120671 if( rc!=SQLITE_OK ) return rc;
120672 #endif
@@ -120687,10 +121470,14 @@
120687
120688 /* Load the built-in tokenizers into the hash table */
120689 if( rc==SQLITE_OK ){
120690 if( sqlite3Fts3HashInsert(pHash, "simple", 7, (void *)pSimple)
120691 || sqlite3Fts3HashInsert(pHash, "porter", 7, (void *)pPorter)
 
 
 
 
120692 #ifdef SQLITE_ENABLE_ICU
120693 || (pIcu && sqlite3Fts3HashInsert(pHash, "icu", 4, (void *)pIcu))
120694 #endif
120695 ){
120696 rc = SQLITE_NOMEM;
@@ -128839,11 +129626,16 @@
128839 sqlite3_column_blob(pStmt, 0),
128840 sqlite3_column_bytes(pStmt, 0));
128841 }else{
128842 memset(a, 0, sizeof(u32)*(nStat) );
128843 }
128844 sqlite3_reset(pStmt);
 
 
 
 
 
128845 if( nChng<0 && a[0]<(u32)(-nChng) ){
128846 a[0] = 0;
128847 }else{
128848 a[0] += nChng;
128849 }
@@ -132562,10 +133354,655 @@
132562 }
132563
132564 #endif
132565
132566 /************** End of fts3_snippet.c ****************************************/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132567 /************** Begin file rtree.c *******************************************/
132568 /*
132569 ** 2001 September 15
132570 **
132571 ** The author disclaims copyright to this source code. In place of
@@ -135301,10 +136738,40 @@
135301 nodeRelease(pRtree, pRoot);
135302 }
135303
135304 return rc;
135305 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135306
135307 /*
135308 ** The xUpdate method for rtree module virtual tables.
135309 */
135310 static int rtreeUpdate(
@@ -135338,12 +136805,12 @@
135338 /* Populate the cell.aCoord[] array. The first coordinate is azData[3]. */
135339 assert( nData==(pRtree->nDim*2 + 3) );
135340 #ifndef SQLITE_RTREE_INT_ONLY
135341 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
135342 for(ii=0; ii<(pRtree->nDim*2); ii+=2){
135343 cell.aCoord[ii].f = (RtreeValue)sqlite3_value_double(azData[ii+3]);
135344 cell.aCoord[ii+1].f = (RtreeValue)sqlite3_value_double(azData[ii+4]);
135345 if( cell.aCoord[ii].f>cell.aCoord[ii+1].f ){
135346 rc = SQLITE_CONSTRAINT;
135347 goto constraint;
135348 }
135349 }
135350
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
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
5 ** unit. This allows many compilers to do optimizations that would not be
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
8 ** translation unit.
@@ -441,18 +441,25 @@
441 #if defined(SQLITE_TCL) || defined(TCLSH)
442 # include <tcl.h>
443 #endif
444
445 /*
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 **
450 ** Setting NDEBUG makes the code smaller and run faster by disabling the
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
453 ** is set. Thus NDEBUG becomes an opt-in rather than an opt-out
454 ** feature.
455 */
456 #if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
457 # define NDEBUG 1
458 #endif
459 #if defined(NDEBUG) && defined(SQLITE_DEBUG)
460 # undef NDEBUG
461 #endif
462
463 /*
464 ** The testcase() macro is used to aid in coverage testing. When
465 ** doing coverage testing, the condition inside the argument to
@@ -655,13 +662,13 @@
662 **
663 ** See also: [sqlite3_libversion()],
664 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
665 ** [sqlite_version()] and [sqlite_source_id()].
666 */
667 #define SQLITE_VERSION "3.7.13"
668 #define SQLITE_VERSION_NUMBER 3007013
669 #define SQLITE_SOURCE_ID "2012-06-07 07:24:04 506008f000ba4af0b35da023b8c52f7a3f5033bd"
670
671 /*
672 ** CAPI3REF: Run-Time Library Version Numbers
673 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
674 **
@@ -1026,10 +1033,11 @@
1033 #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
1034 #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
1035 #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */
1036 #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */
1037 #define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */
1038 #define SQLITE_OPEN_MEMORY 0x00000080 /* Ok for sqlite3_open_v2() */
1039 #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */
1040 #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */
1041 #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */
1042 #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */
1043 #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */
@@ -1320,11 +1328,11 @@
1328 ** into the array entry, allowing the current retry settings to be
1329 ** interrogated. The zDbName parameter is ignored.
1330 **
1331 ** <li>[[SQLITE_FCNTL_PERSIST_WAL]]
1332 ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the
1333 ** persistent [WAL | Write Ahead Log] setting. By default, the auxiliary
1334 ** write ahead log and shared memory files used for transaction control
1335 ** are automatically deleted when the latest connection to the database
1336 ** closes. Setting persistent WAL mode causes those files to persist after
1337 ** close. Persisting the files is useful when other processes that do not
1338 ** have write permission on the directory containing the database file want
@@ -2717,16 +2725,16 @@
2725 ** In SQLite version 3.5.0 and 3.5.1, it was possible to define
2726 ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
2727 ** implementation of these routines to be omitted. That capability
2728 ** is no longer provided. Only built-in memory allocators can be used.
2729 **
2730 ** Prior to SQLite version 3.7.10, the Windows OS interface layer called
2731 ** the system malloc() and free() directly when converting
2732 ** filenames between the UTF-8 encoding used by SQLite
2733 ** and whatever filename encoding is used by the particular Windows
2734 ** installation. Memory allocation errors were detected, but
2735 ** they were reported back as [SQLITE_CANTOPEN] or
2736 ** [SQLITE_IOERR] rather than [SQLITE_NOMEM].
2737 **
2738 ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
2739 ** must be either NULL or else pointers obtained from a prior
2740 ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
@@ -3123,22 +3131,24 @@
3131 ** an empty string the default VFS object is used. ^Specifying an unknown
3132 ** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is
3133 ** present, then the VFS specified by the option takes precedence over
3134 ** the value passed as the fourth parameter to sqlite3_open_v2().
3135 **
3136 ** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw",
3137 ** "rwc", or "memory". Attempting to set it to any other value is
3138 ** an error)^.
3139 ** ^If "ro" is specified, then the database is opened for read-only
3140 ** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the
3141 ** third argument to sqlite3_prepare_v2(). ^If the mode option is set to
3142 ** "rw", then the database is opened for read-write (but not create)
3143 ** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had
3144 ** been set. ^Value "rwc" is equivalent to setting both
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
3147 ** or writes from disk is used. ^It is an error to specify a value for
3148 ** the mode parameter that is less restrictive than that specified by
3149 ** the flags passed in the third parameter to sqlite3_open_v2().
3150 **
3151 ** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or
3152 ** "private". ^Setting it to "shared" is equivalent to setting the
3153 ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
3154 ** sqlite3_open_v2(). ^Setting the cache parameter to "private" is
@@ -4997,10 +5007,46 @@
5007 ** made NULL or made to point to memory obtained from [sqlite3_malloc]
5008 ** or else the use of the [temp_store_directory pragma] should be avoided.
5009 */
5010 SQLITE_API char *sqlite3_temp_directory;
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
5048 /*
5049 ** CAPI3REF: Test For Auto-Commit Mode
5050 ** KEYWORDS: {autocommit mode}
5051 **
5052 ** ^The sqlite3_get_autocommit() interface returns non-zero or
@@ -5175,11 +5221,10 @@
5221 void*
5222 );
5223
5224 /*
5225 ** CAPI3REF: Enable Or Disable Shared Pager Cache
 
5226 **
5227 ** ^(This routine enables or disables the sharing of the database cache
5228 ** and schema data structures between [database connection | connections]
5229 ** to the same database. Sharing is enabled if the argument is true
5230 ** and disabled if the argument is false.)^
@@ -9014,11 +9059,11 @@
9059
9060 /* Functions used to query pager state and configuration. */
9061 SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*);
9062 SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
9063 SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*);
9064 SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*, int);
9065 SQLITE_PRIVATE const sqlite3_vfs *sqlite3PagerVfs(Pager*);
9066 SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*);
9067 SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*);
9068 SQLITE_PRIVATE int sqlite3PagerNosync(Pager*);
9069 SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*);
@@ -9284,17 +9329,15 @@
9329 # ifndef SQLITE_OS_WIN
9330 # define SQLITE_OS_WIN 0
9331 # endif
9332 #endif
9333
 
 
 
9334 #if SQLITE_OS_WIN
9335 # include <windows.h>
9336 #endif
9337
9338 #if SQLITE_OS_OS2
9339 # if (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 3) && defined(OS2_HIGH_MEMORY)
9340 # include <os2safe.h> /* has to be included before os2.h for linking to work */
9341 # endif
9342 # define INCL_DOSDATETIME
9343 # define INCL_DOSFILEMGR
@@ -9303,13 +9346,10 @@
9346 # define INCL_DOSPROCESS
9347 # define INCL_DOSMODULEMGR
9348 # define INCL_DOSSEMAPHORES
9349 # include <os2.h>
9350 # include <uconv.h>
 
 
 
9351 #endif
9352
9353 /*
9354 ** Determine if we are dealing with Windows NT.
9355 **
@@ -9339,10 +9379,26 @@
9379 # define SQLITE_OS_WINCE 1
9380 #else
9381 # define SQLITE_OS_WINCE 0
9382 #endif
9383
9384 /*
9385 ** Determine if we are dealing with WindowsRT (Metro) as this has a different and
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
9400 /* If the SET_FULLSYNC macro is not defined above, then make it
9401 ** a no-op
9402 */
9403 #ifndef SET_FULLSYNC
9404 # define SET_FULLSYNC(x,y)
@@ -10933,19 +10989,25 @@
10989 */
10990 struct NameContext {
10991 Parse *pParse; /* The parser */
10992 SrcList *pSrcList; /* One or more tables used to resolve names */
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 */
10996 int nRef; /* Number of names resolved by this context */
10997 int nErr; /* Number of errors encountered while resolving names */
10998 u8 ncFlags; /* Zero or more NC_* flags defined below */
 
 
 
 
10999 };
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
11009 /*
11010 ** An instance of the following structure contains all information
11011 ** needed to generate code for a single SELECT statement.
11012 **
11013 ** nLimit is set to -1 if there is no LIMIT clause. nOffset is set to 0.
@@ -11623,11 +11685,13 @@
11685 SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,ExprSpan*);
11686 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*);
11687 SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**);
11688 SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**);
11689 SQLITE_PRIVATE void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
11690 SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3*);
11691 SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3*,int);
11692 SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3*);
11693 SQLITE_PRIVATE void sqlite3BeginParse(Parse*,int);
11694 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3*);
11695 SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*);
11696 SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *, int);
11697 SQLITE_PRIVATE void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int);
@@ -12028,10 +12092,11 @@
12092 # define sqlite3VtabUnlockList(X)
12093 # define sqlite3VtabSavepoint(X, Y, Z) SQLITE_OK
12094 # define sqlite3GetVTable(X,Y) ((VTable*)0)
12095 #else
12096 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*);
12097 SQLITE_PRIVATE void sqlite3VtabDisconnect(sqlite3 *db, Table *p);
12098 SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **);
12099 SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db);
12100 SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db);
12101 SQLITE_PRIVATE void sqlite3VtabLock(VTable *);
12102 SQLITE_PRIVATE void sqlite3VtabUnlock(VTable *);
@@ -12481,10 +12546,13 @@
12546 #ifdef SQLITE_CHECK_PAGES
12547 "CHECK_PAGES",
12548 #endif
12549 #ifdef SQLITE_COVERAGE_TEST
12550 "COVERAGE_TEST",
12551 #endif
12552 #ifdef SQLITE_CURDIR
12553 "CURDIR",
12554 #endif
12555 #ifdef SQLITE_DEBUG
12556 "DEBUG",
12557 #endif
12558 #ifdef SQLITE_DEFAULT_LOCKING_MODE
@@ -18335,11 +18403,11 @@
18403 ** _WIN32_WINNT defined to a value >= 0x0400. Currently, the only
18404 ** call to TryEnterCriticalSection() is #ifdef'ed out, so #ifdef
18405 ** this out as well.
18406 */
18407 #if 0
18408 #if SQLITE_OS_WINCE || SQLITE_OS_WINRT
18409 # define mutexIsNT() (1)
18410 #else
18411 static int mutexIsNT(void){
18412 static int osType = 0;
18413 if( osType==0 ){
@@ -18388,22 +18456,28 @@
18456 ** processing, the "interlocked" magic is probably not
18457 ** strictly necessary.
18458 */
18459 static long winMutex_lock = 0;
18460
18461 SQLITE_API extern void sqlite3_win32_sleep(DWORD milliseconds); /* os_win.c */
18462
18463 static int winMutexInit(void){
18464 /* The first to increment to 1 does actual initialization */
18465 if( InterlockedCompareExchange(&winMutex_lock, 1, 0)==0 ){
18466 int 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
18471 InitializeCriticalSection(&winMutex_staticMutexes[i].mutex);
18472 #endif
18473 }
18474 winMutex_isInit = 1;
18475 }else{
18476 /* Someone else is in the process of initing the static mutexes */
18477 while( !winMutex_isInit ){
18478 sqlite3_win32_sleep(1);
18479 }
18480 }
18481 return SQLITE_OK;
18482 }
18483
@@ -18473,11 +18547,15 @@
18547 p = sqlite3MallocZero( sizeof(*p) );
18548 if( p ){
18549 #ifdef SQLITE_DEBUG
18550 p->id = iType;
18551 #endif
18552 #if SQLITE_OS_WINRT
18553 InitializeCriticalSectionEx(&p->mutex, 0, 0);
18554 #else
18555 InitializeCriticalSection(&p->mutex);
18556 #endif
18557 }
18558 break;
18559 }
18560 default: {
18561 assert( winMutex_isInit==1 );
@@ -19104,10 +19182,14 @@
19182 *db->pnBytesFreed += sqlite3DbMallocSize(db, p);
19183 return;
19184 }
19185 if( isLookaside(db, 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
19191 pBuf->pNext = db->lookaside.pFree;
19192 db->lookaside.pFree = pBuf;
19193 db->lookaside.nOut--;
19194 return;
19195 }
@@ -25062,11 +25144,11 @@
25144 unsigned fsFlags; /* cached details from statfs() */
25145 #endif
25146 #if OS_VXWORKS
25147 struct vxworksFileId *pId; /* Unique file ID */
25148 #endif
25149 #ifdef SQLITE_DEBUG
25150 /* The next group of variables are used to track whether or not the
25151 ** transaction counter in bytes 24-27 of database files are updated
25152 ** whenever any part of the database changes. An assertion fault will
25153 ** occur if a file is updated without also updating the transaction
25154 ** counter. This test is made to avoid new problems similar to the
@@ -25097,11 +25179,10 @@
25179 #endif
25180 #define UNIXFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */
25181 #define UNIXFILE_DELETE 0x20 /* Delete on close */
25182 #define UNIXFILE_URI 0x40 /* Filename might have query parameters */
25183 #define UNIXFILE_NOLOCK 0x80 /* Do no file locking */
 
25184
25185 /*
25186 ** Include code that is common to all os_*.c files
25187 */
25188 /************** Include os_common.h in the middle of os_unix.c ***************/
@@ -25350,10 +25431,19 @@
25431 ** which always has the same well-defined interface.
25432 */
25433 static int posixOpen(const char *zFile, int flags, int mode){
25434 return open(zFile, flags, mode);
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 }
25445
25446 /* Forward reference */
25447 static int openDirectory(const char*, int*);
25448
25449 /*
@@ -25462,11 +25552,11 @@
25552 #define osMkdir ((int(*)(const char*,mode_t))aSyscall[18].pCurrent)
25553
25554 { "rmdir", (sqlite3_syscall_ptr)rmdir, 0 },
25555 #define osRmdir ((int(*)(const char*))aSyscall[19].pCurrent)
25556
25557 { "fchown", (sqlite3_syscall_ptr)posixFchown, 0 },
25558 #define osFchown ((int(*)(int,uid_t,gid_t))aSyscall[20].pCurrent)
25559
25560 { "umask", (sqlite3_syscall_ptr)umask, 0 },
25561 #define osUmask ((mode_t(*)(mode_t))aSyscall[21].pCurrent)
25562
@@ -26606,11 +26696,11 @@
26696 }
26697 }
26698 }
26699
26700
26701 #ifdef SQLITE_DEBUG
26702 /* Set up the transaction-counter change checking flags when
26703 ** transitioning from a SHARED to a RESERVED lock. The change
26704 ** from SHARED to RESERVED marks the beginning of a normal
26705 ** write operation (not a hot journal rollback).
26706 */
@@ -26685,11 +26775,11 @@
26775 pInode = pFile->pInode;
26776 assert( pInode->nShared!=0 );
26777 if( pFile->eFileLock>SHARED_LOCK ){
26778 assert( pInode->eFileLock==pFile->eFileLock );
26779
26780 #ifdef SQLITE_DEBUG
26781 /* When reducing a lock such that other processes can start
26782 ** reading the database file again, make sure that the
26783 ** transaction counter was updated if any part of the database
26784 ** file changed. If the transaction counter is not updated,
26785 ** other connections to the same file might not realize that
@@ -27884,11 +27974,11 @@
27974 assert( pInode->eFileLock==pFile->eFileLock );
27975 SimulateIOErrorBenign(1);
27976 SimulateIOError( h=(-1) )
27977 SimulateIOErrorBenign(0);
27978
27979 #ifdef SQLITE_DEBUG
27980 /* When reducing a lock such that other processes can start
27981 ** reading the database file again, make sure that the
27982 ** transaction counter was updated if any part of the database
27983 ** file changed. If the transaction counter is not updated,
27984 ** other connections to the same file might not realize that
@@ -28188,11 +28278,11 @@
28278 || offset>=PENDING_BYTE+512
28279 || offset+amt<=PENDING_BYTE
28280 );
28281 #endif
28282
28283 #ifdef SQLITE_DEBUG
28284 /* If we are doing a normal write to a database file (as opposed to
28285 ** doing a hot-journal rollback or a write to some file other than a
28286 ** normal database file) then record the fact that the database
28287 ** has changed. If the transaction counter is modified, record that
28288 ** fact too.
@@ -28479,11 +28569,11 @@
28569 rc = robust_ftruncate(pFile->h, (off_t)nByte);
28570 if( rc ){
28571 pFile->lastErrno = errno;
28572 return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
28573 }else{
28574 #ifdef SQLITE_DEBUG
28575 /* If we are doing a normal write to a database file (as opposed to
28576 ** doing a hot-journal rollback or a write to some file other than a
28577 ** normal database file) and we truncate the file to zero length,
28578 ** that effectively updates the change counter. This might happen
28579 ** when restoring a database using the backup API from a zero-length
@@ -28636,11 +28726,11 @@
28726 }
28727 case SQLITE_FCNTL_VFSNAME: {
28728 *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName);
28729 return SQLITE_OK;
28730 }
28731 #ifdef SQLITE_DEBUG
28732 /* The pager calls this method to signal that it has done
28733 ** a rollback and that the database is therefore unchanged and
28734 ** it hence it is OK for the transaction change counter to be
28735 ** unchanged.
28736 */
@@ -28987,18 +29077,13 @@
29077 goto shm_open_err;
29078 }
29079
29080 /* If this process is running as root, make sure that the SHM file
29081 ** is owned by the same user that owns the original database. Otherwise,
29082 ** the original owner will not be able to connect.
 
 
 
29083 */
29084 osFchown(pShmNode->h, sStat.st_uid, sStat.st_gid);
 
 
29085
29086 /* Check to see if another process is holding the dead-man switch.
29087 ** If not, truncate the file to zero length.
29088 */
29089 rc = SQLITE_OK;
@@ -30200,17 +30285,14 @@
30285 goto open_finished;
30286 }
30287
30288 /* If this process is running as root and if creating a new rollback
30289 ** journal or WAL file, set the ownership of the journal or WAL to be
30290 ** the same as the original database.
 
 
 
30291 */
30292 if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){
30293 osFchown(fd, uid, gid);
30294 }
30295 }
30296 assert( fd>=0 );
30297 if( pOutFlags ){
30298 *pOutFlags = flags;
@@ -32167,16 +32249,31 @@
32249 #endif /* !defined(_OS_COMMON_H_) */
32250
32251 /************** End of os_common.h *******************************************/
32252 /************** Continuing where we left off in os_win.c *********************/
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
32261 /*
32262 ** Some Microsoft compilers lack this definition.
32263 */
32264 #ifndef INVALID_FILE_ATTRIBUTES
32265 # define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
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
32275
32276 /* Forward references */
32277 typedef struct winShm winShm; /* A connection to shared-memory */
32278 typedef struct winShmNode winShmNode; /* A region of shared-memory */
32279
@@ -32222,15 +32319,41 @@
32319 ** Allowed values for winFile.ctrlFlags
32320 */
32321 #define WINFILE_PERSIST_WAL 0x04 /* Persistent WAL mode */
32322 #define WINFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */
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
32331 /*
32332 * If compiled with SQLITE_WIN32_MALLOC on Windows, we will use the
32333 * various Win32 API heap functions instead of our own.
32334 */
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
32355 /*
32356 * The initial size of the Win32-specific heap. This value may be zero.
32357 */
32358 #ifndef SQLITE_WIN32_HEAP_INIT_SIZE
32359 # define SQLITE_WIN32_HEAP_INIT_SIZE ((SQLITE_DEFAULT_CACHE_SIZE) * \
@@ -32311,61 +32434,50 @@
32434 SQLITE_API int sqlite3_os_type = 0;
32435 #else
32436 static int sqlite3_os_type = 0;
32437 #endif
32438
32439 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
 
 
 
 
 
 
32440 # define SQLITE_WIN32_HAS_ANSI
32441 #endif
32442
32443 #if SQLITE_OS_WINCE || SQLITE_OS_WINNT || SQLITE_OS_WINRT
32444 # define SQLITE_WIN32_HAS_WIDE
32445 #endif
32446
32447 #ifndef SYSCALL
32448 # define SYSCALL sqlite3_syscall_ptr
32449 #endif
32450
32451 /*
32452 ** This function is not available on Windows CE or WinRT.
32453 */
32454
32455 #if SQLITE_OS_WINCE || SQLITE_OS_WINRT
32456 # define osAreFileApisANSI() 1
32457 #endif
32458
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
32462 ** testing and sandboxing. The following array holds the names and pointers
32463 ** to all overrideable system calls.
32464 */
 
 
 
 
 
 
 
32465 static struct win_syscall {
32466 const char *zName; /* Name of the sytem call */
32467 sqlite3_syscall_ptr pCurrent; /* Current value of the system call */
32468 sqlite3_syscall_ptr pDefault; /* Default value */
32469 } aSyscall[] = {
32470 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
32471 { "AreFileApisANSI", (SYSCALL)AreFileApisANSI, 0 },
 
 
32472 #else
32473 { "AreFileApisANSI", (SYSCALL)0, 0 },
32474 #endif
32475
32476 #ifndef osAreFileApisANSI
32477 #define osAreFileApisANSI ((BOOL(WINAPI*)(VOID))aSyscall[0].pCurrent)
32478 #endif
32479
32480 #if SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE)
32481 { "CharLowerW", (SYSCALL)CharLowerW, 0 },
32482 #else
32483 { "CharLowerW", (SYSCALL)0, 0 },
@@ -32392,174 +32504,173 @@
32504 #endif
32505
32506 #define osCreateFileA ((HANDLE(WINAPI*)(LPCSTR,DWORD,DWORD, \
32507 LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[4].pCurrent)
32508
32509 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
32510 { "CreateFileW", (SYSCALL)CreateFileW, 0 },
32511 #else
32512 { "CreateFileW", (SYSCALL)0, 0 },
32513 #endif
32514
32515 #define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \
32516 LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent)
32517
32518 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
 
 
 
 
 
32519 { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 },
32520 #else
32521 { "CreateFileMappingW", (SYSCALL)0, 0 },
32522 #endif
32523
32524 #define osCreateFileMappingW ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \
32525 DWORD,DWORD,DWORD,LPCWSTR))aSyscall[6].pCurrent)
32526
32527 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
32528 { "CreateMutexW", (SYSCALL)CreateMutexW, 0 },
32529 #else
32530 { "CreateMutexW", (SYSCALL)0, 0 },
32531 #endif
32532
32533 #define osCreateMutexW ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,BOOL, \
32534 LPCWSTR))aSyscall[7].pCurrent)
32535
32536 #if defined(SQLITE_WIN32_HAS_ANSI)
32537 { "DeleteFileA", (SYSCALL)DeleteFileA, 0 },
32538 #else
32539 { "DeleteFileA", (SYSCALL)0, 0 },
32540 #endif
32541
32542 #define osDeleteFileA ((BOOL(WINAPI*)(LPCSTR))aSyscall[8].pCurrent)
32543
32544 #if defined(SQLITE_WIN32_HAS_WIDE)
32545 { "DeleteFileW", (SYSCALL)DeleteFileW, 0 },
32546 #else
32547 { "DeleteFileW", (SYSCALL)0, 0 },
32548 #endif
32549
32550 #define osDeleteFileW ((BOOL(WINAPI*)(LPCWSTR))aSyscall[9].pCurrent)
32551
32552 #if SQLITE_OS_WINCE
32553 { "FileTimeToLocalFileTime", (SYSCALL)FileTimeToLocalFileTime, 0 },
32554 #else
32555 { "FileTimeToLocalFileTime", (SYSCALL)0, 0 },
32556 #endif
32557
32558 #define osFileTimeToLocalFileTime ((BOOL(WINAPI*)(CONST FILETIME*, \
32559 LPFILETIME))aSyscall[10].pCurrent)
32560
32561 #if SQLITE_OS_WINCE
32562 { "FileTimeToSystemTime", (SYSCALL)FileTimeToSystemTime, 0 },
32563 #else
32564 { "FileTimeToSystemTime", (SYSCALL)0, 0 },
32565 #endif
32566
32567 #define osFileTimeToSystemTime ((BOOL(WINAPI*)(CONST FILETIME*, \
32568 LPSYSTEMTIME))aSyscall[11].pCurrent)
32569
32570 { "FlushFileBuffers", (SYSCALL)FlushFileBuffers, 0 },
32571
32572 #define osFlushFileBuffers ((BOOL(WINAPI*)(HANDLE))aSyscall[12].pCurrent)
32573
32574 #if defined(SQLITE_WIN32_HAS_ANSI)
32575 { "FormatMessageA", (SYSCALL)FormatMessageA, 0 },
32576 #else
32577 { "FormatMessageA", (SYSCALL)0, 0 },
32578 #endif
32579
32580 #define osFormatMessageA ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPSTR, \
32581 DWORD,va_list*))aSyscall[13].pCurrent)
32582
32583 #if defined(SQLITE_WIN32_HAS_WIDE)
32584 { "FormatMessageW", (SYSCALL)FormatMessageW, 0 },
32585 #else
32586 { "FormatMessageW", (SYSCALL)0, 0 },
32587 #endif
32588
32589 #define osFormatMessageW ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPWSTR, \
32590 DWORD,va_list*))aSyscall[14].pCurrent)
32591
32592 { "FreeLibrary", (SYSCALL)FreeLibrary, 0 },
32593
32594 #define osFreeLibrary ((BOOL(WINAPI*)(HMODULE))aSyscall[15].pCurrent)
32595
32596 { "GetCurrentProcessId", (SYSCALL)GetCurrentProcessId, 0 },
32597
32598 #define osGetCurrentProcessId ((DWORD(WINAPI*)(VOID))aSyscall[16].pCurrent)
32599
32600 #if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_ANSI)
32601 { "GetDiskFreeSpaceA", (SYSCALL)GetDiskFreeSpaceA, 0 },
32602 #else
32603 { "GetDiskFreeSpaceA", (SYSCALL)0, 0 },
32604 #endif
32605
32606 #define osGetDiskFreeSpaceA ((BOOL(WINAPI*)(LPCSTR,LPDWORD,LPDWORD,LPDWORD, \
32607 LPDWORD))aSyscall[17].pCurrent)
32608
32609 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
32610 { "GetDiskFreeSpaceW", (SYSCALL)GetDiskFreeSpaceW, 0 },
32611 #else
32612 { "GetDiskFreeSpaceW", (SYSCALL)0, 0 },
32613 #endif
32614
32615 #define osGetDiskFreeSpaceW ((BOOL(WINAPI*)(LPCWSTR,LPDWORD,LPDWORD,LPDWORD, \
32616 LPDWORD))aSyscall[18].pCurrent)
32617
32618 #if defined(SQLITE_WIN32_HAS_ANSI)
32619 { "GetFileAttributesA", (SYSCALL)GetFileAttributesA, 0 },
32620 #else
32621 { "GetFileAttributesA", (SYSCALL)0, 0 },
32622 #endif
32623
32624 #define osGetFileAttributesA ((DWORD(WINAPI*)(LPCSTR))aSyscall[19].pCurrent)
32625
32626 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
32627 { "GetFileAttributesW", (SYSCALL)GetFileAttributesW, 0 },
32628 #else
32629 { "GetFileAttributesW", (SYSCALL)0, 0 },
32630 #endif
32631
32632 #define osGetFileAttributesW ((DWORD(WINAPI*)(LPCWSTR))aSyscall[20].pCurrent)
32633
32634 #if defined(SQLITE_WIN32_HAS_WIDE)
32635 { "GetFileAttributesExW", (SYSCALL)GetFileAttributesExW, 0 },
32636 #else
32637 { "GetFileAttributesExW", (SYSCALL)0, 0 },
32638 #endif
32639
32640 #define osGetFileAttributesExW ((BOOL(WINAPI*)(LPCWSTR,GET_FILEEX_INFO_LEVELS, \
32641 LPVOID))aSyscall[21].pCurrent)
32642
32643 #if !SQLITE_OS_WINRT
32644 { "GetFileSize", (SYSCALL)GetFileSize, 0 },
32645 #else
32646 { "GetFileSize", (SYSCALL)0, 0 },
32647 #endif
32648
32649 #define osGetFileSize ((DWORD(WINAPI*)(HANDLE,LPDWORD))aSyscall[22].pCurrent)
32650
32651 #if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_ANSI)
32652 { "GetFullPathNameA", (SYSCALL)GetFullPathNameA, 0 },
32653 #else
32654 { "GetFullPathNameA", (SYSCALL)0, 0 },
32655 #endif
32656
32657 #define osGetFullPathNameA ((DWORD(WINAPI*)(LPCSTR,DWORD,LPSTR, \
32658 LPSTR*))aSyscall[23].pCurrent)
32659
32660 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
32661 { "GetFullPathNameW", (SYSCALL)GetFullPathNameW, 0 },
32662 #else
32663 { "GetFullPathNameW", (SYSCALL)0, 0 },
32664 #endif
32665
32666 #define osGetFullPathNameW ((DWORD(WINAPI*)(LPCWSTR,DWORD,LPWSTR, \
32667 LPWSTR*))aSyscall[24].pCurrent)
32668
32669 { "GetLastError", (SYSCALL)GetLastError, 0 },
32670
32671 #define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[25].pCurrent)
32672
32673 #if SQLITE_OS_WINCE
32674 /* The GetProcAddressA() routine is only available on Windows CE. */
32675 { "GetProcAddressA", (SYSCALL)GetProcAddressA, 0 },
32676 #else
@@ -32567,198 +32678,358 @@
32678 ** an ANSI string regardless of the _UNICODE setting */
32679 { "GetProcAddressA", (SYSCALL)GetProcAddress, 0 },
32680 #endif
32681
32682 #define osGetProcAddressA ((FARPROC(WINAPI*)(HMODULE, \
32683 LPCSTR))aSyscall[26].pCurrent)
32684
32685 #if !SQLITE_OS_WINRT
32686 { "GetSystemInfo", (SYSCALL)GetSystemInfo, 0 },
32687 #else
32688 { "GetSystemInfo", (SYSCALL)0, 0 },
32689 #endif
32690
32691 #define osGetSystemInfo ((VOID(WINAPI*)(LPSYSTEM_INFO))aSyscall[27].pCurrent)
32692
32693 { "GetSystemTime", (SYSCALL)GetSystemTime, 0 },
32694
32695 #define osGetSystemTime ((VOID(WINAPI*)(LPSYSTEMTIME))aSyscall[28].pCurrent)
32696
32697 #if !SQLITE_OS_WINCE
32698 { "GetSystemTimeAsFileTime", (SYSCALL)GetSystemTimeAsFileTime, 0 },
32699 #else
32700 { "GetSystemTimeAsFileTime", (SYSCALL)0, 0 },
32701 #endif
32702
32703 #define osGetSystemTimeAsFileTime ((VOID(WINAPI*)( \
32704 LPFILETIME))aSyscall[29].pCurrent)
32705
32706 #if defined(SQLITE_WIN32_HAS_ANSI)
32707 { "GetTempPathA", (SYSCALL)GetTempPathA, 0 },
32708 #else
32709 { "GetTempPathA", (SYSCALL)0, 0 },
32710 #endif
32711
32712 #define osGetTempPathA ((DWORD(WINAPI*)(DWORD,LPSTR))aSyscall[30].pCurrent)
32713
32714 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
32715 { "GetTempPathW", (SYSCALL)GetTempPathW, 0 },
32716 #else
32717 { "GetTempPathW", (SYSCALL)0, 0 },
32718 #endif
32719
32720 #define osGetTempPathW ((DWORD(WINAPI*)(DWORD,LPWSTR))aSyscall[31].pCurrent)
32721
32722 #if !SQLITE_OS_WINRT
32723 { "GetTickCount", (SYSCALL)GetTickCount, 0 },
32724 #else
32725 { "GetTickCount", (SYSCALL)0, 0 },
32726 #endif
32727
32728 #define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[32].pCurrent)
32729
32730 #if defined(SQLITE_WIN32_HAS_ANSI)
32731 { "GetVersionExA", (SYSCALL)GetVersionExA, 0 },
32732 #else
32733 { "GetVersionExA", (SYSCALL)0, 0 },
32734 #endif
32735
32736 #define osGetVersionExA ((BOOL(WINAPI*)( \
32737 LPOSVERSIONINFOA))aSyscall[33].pCurrent)
32738
32739 { "HeapAlloc", (SYSCALL)HeapAlloc, 0 },
32740
32741 #define osHeapAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD, \
32742 SIZE_T))aSyscall[34].pCurrent)
32743
32744 #if !SQLITE_OS_WINRT
32745 { "HeapCreate", (SYSCALL)HeapCreate, 0 },
32746 #else
32747 { "HeapCreate", (SYSCALL)0, 0 },
32748 #endif
32749
32750 #define osHeapCreate ((HANDLE(WINAPI*)(DWORD,SIZE_T, \
32751 SIZE_T))aSyscall[35].pCurrent)
32752
32753 #if !SQLITE_OS_WINRT
32754 { "HeapDestroy", (SYSCALL)HeapDestroy, 0 },
32755 #else
32756 { "HeapDestroy", (SYSCALL)0, 0 },
32757 #endif
32758
32759 #define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[36].pCurrent)
32760
32761 { "HeapFree", (SYSCALL)HeapFree, 0 },
32762
32763 #define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[37].pCurrent)
32764
32765 { "HeapReAlloc", (SYSCALL)HeapReAlloc, 0 },
32766
32767 #define osHeapReAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD,LPVOID, \
32768 SIZE_T))aSyscall[38].pCurrent)
32769
32770 { "HeapSize", (SYSCALL)HeapSize, 0 },
32771
32772 #define osHeapSize ((SIZE_T(WINAPI*)(HANDLE,DWORD, \
32773 LPCVOID))aSyscall[39].pCurrent)
32774
32775 #if !SQLITE_OS_WINRT
32776 { "HeapValidate", (SYSCALL)HeapValidate, 0 },
32777 #else
32778 { "HeapValidate", (SYSCALL)0, 0 },
32779 #endif
32780
32781 #define osHeapValidate ((BOOL(WINAPI*)(HANDLE,DWORD, \
32782 LPCVOID))aSyscall[40].pCurrent)
32783
32784 #if defined(SQLITE_WIN32_HAS_ANSI)
32785 { "LoadLibraryA", (SYSCALL)LoadLibraryA, 0 },
32786 #else
32787 { "LoadLibraryA", (SYSCALL)0, 0 },
32788 #endif
32789
32790 #define osLoadLibraryA ((HMODULE(WINAPI*)(LPCSTR))aSyscall[41].pCurrent)
32791
32792 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
32793 { "LoadLibraryW", (SYSCALL)LoadLibraryW, 0 },
32794 #else
32795 { "LoadLibraryW", (SYSCALL)0, 0 },
32796 #endif
32797
32798 #define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[42].pCurrent)
32799
32800 #if !SQLITE_OS_WINRT
32801 { "LocalFree", (SYSCALL)LocalFree, 0 },
32802 #else
32803 { "LocalFree", (SYSCALL)0, 0 },
32804 #endif
32805
32806 #define osLocalFree ((HLOCAL(WINAPI*)(HLOCAL))aSyscall[43].pCurrent)
32807
32808 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
32809 { "LockFile", (SYSCALL)LockFile, 0 },
32810 #else
32811 { "LockFile", (SYSCALL)0, 0 },
32812 #endif
32813
32814 #ifndef osLockFile
32815 #define osLockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
32816 DWORD))aSyscall[44].pCurrent)
32817 #endif
32818
32819 #if !SQLITE_OS_WINCE
32820 { "LockFileEx", (SYSCALL)LockFileEx, 0 },
 
 
 
32821 #else
32822 { "LockFileEx", (SYSCALL)0, 0 },
32823 #endif
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
32831 { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 },
32832 #else
32833 { "MapViewOfFile", (SYSCALL)0, 0 },
32834 #endif
32835
32836 #define osMapViewOfFile ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
32837 SIZE_T))aSyscall[46].pCurrent)
32838
32839 { "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 },
32840
32841 #define osMultiByteToWideChar ((int(WINAPI*)(UINT,DWORD,LPCSTR,int,LPWSTR, \
32842 int))aSyscall[47].pCurrent)
32843
32844 { "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 },
32845
32846 #define osQueryPerformanceCounter ((BOOL(WINAPI*)( \
32847 LARGE_INTEGER*))aSyscall[48].pCurrent)
32848
32849 { "ReadFile", (SYSCALL)ReadFile, 0 },
32850
32851 #define osReadFile ((BOOL(WINAPI*)(HANDLE,LPVOID,DWORD,LPDWORD, \
32852 LPOVERLAPPED))aSyscall[49].pCurrent)
32853
32854 { "SetEndOfFile", (SYSCALL)SetEndOfFile, 0 },
32855
32856 #define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[50].pCurrent)
32857
32858 #if !SQLITE_OS_WINRT
32859 { "SetFilePointer", (SYSCALL)SetFilePointer, 0 },
32860 #else
32861 { "SetFilePointer", (SYSCALL)0, 0 },
32862 #endif
32863
32864 #define osSetFilePointer ((DWORD(WINAPI*)(HANDLE,LONG,PLONG, \
32865 DWORD))aSyscall[51].pCurrent)
32866
32867 #if !SQLITE_OS_WINRT
32868 { "Sleep", (SYSCALL)Sleep, 0 },
32869 #else
32870 { "Sleep", (SYSCALL)0, 0 },
32871 #endif
32872
32873 #define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[52].pCurrent)
32874
32875 { "SystemTimeToFileTime", (SYSCALL)SystemTimeToFileTime, 0 },
32876
32877 #define osSystemTimeToFileTime ((BOOL(WINAPI*)(CONST SYSTEMTIME*, \
32878 LPFILETIME))aSyscall[53].pCurrent)
32879
32880 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
32881 { "UnlockFile", (SYSCALL)UnlockFile, 0 },
 
 
 
32882 #else
32883 { "UnlockFile", (SYSCALL)0, 0 },
32884 #endif
32885
32886 #ifndef osUnlockFile
32887 #define osUnlockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
32888 DWORD))aSyscall[54].pCurrent)
32889 #endif
32890
32891 #if !SQLITE_OS_WINCE
32892 { "UnlockFileEx", (SYSCALL)UnlockFileEx, 0 },
 
 
 
32893 #else
32894 { "UnlockFileEx", (SYSCALL)0, 0 },
32895 #endif
32896
32897 #define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
32898 LPOVERLAPPED))aSyscall[55].pCurrent)
32899
32900 { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 },
32901
32902 #define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[56].pCurrent)
32903
32904 { "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 },
32905
32906 #define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \
32907 LPCSTR,LPBOOL))aSyscall[57].pCurrent)
32908
32909 { "WriteFile", (SYSCALL)WriteFile, 0 },
32910
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, \
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)
33031
33032 }; /* End of the overrideable system calls */
33033
33034 /*
33035 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
@@ -32840,10 +33111,68 @@
33111 for(i++; i<ArraySize(aSyscall); i++){
33112 if( aSyscall[i].pCurrent!=0 ) return aSyscall[i].zName;
33113 }
33114 return 0;
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 }
33174
33175 /*
33176 ** Return true (non-zero) if we are running under WinNT, Win2K, WinXP,
33177 ** or WinCE. Return false (zero) for Win95, Win98, or WinME.
33178 **
@@ -32852,11 +33181,11 @@
33181 ** API as long as we don't call it when running Win95/98/ME. A call to
33182 ** this routine is used to determine if the host is Win95/98/ME or
33183 ** WinNT/2K/XP so that we will know whether or not we can safely call
33184 ** the LockFileEx() API.
33185 */
33186 #if SQLITE_OS_WINCE || SQLITE_OS_WINRT
33187 # define isNT() (1)
33188 #else
33189 static int isNT(void){
33190 if( sqlite3_os_type==0 ){
33191 OSVERSIONINFOA sInfo;
@@ -32878,11 +33207,11 @@
33207
33208 winMemAssertMagic();
33209 hHeap = winMemGetHeap();
33210 assert( hHeap!=0 );
33211 assert( hHeap!=INVALID_HANDLE_VALUE );
33212 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
33213 assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
33214 #endif
33215 assert( nBytes>=0 );
33216 p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
33217 if( !p ){
@@ -32900,11 +33229,11 @@
33229
33230 winMemAssertMagic();
33231 hHeap = winMemGetHeap();
33232 assert( hHeap!=0 );
33233 assert( hHeap!=INVALID_HANDLE_VALUE );
33234 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
33235 assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) );
33236 #endif
33237 if( !pPrior ) return; /* Passing NULL to HeapFree is undefined. */
33238 if( !osHeapFree(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ){
33239 sqlite3_log(SQLITE_NOMEM, "failed to HeapFree block %p (%d), heap=%p",
@@ -32921,11 +33250,11 @@
33250
33251 winMemAssertMagic();
33252 hHeap = winMemGetHeap();
33253 assert( hHeap!=0 );
33254 assert( hHeap!=INVALID_HANDLE_VALUE );
33255 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
33256 assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) );
33257 #endif
33258 assert( nBytes>=0 );
33259 if( !pPrior ){
33260 p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
@@ -32949,11 +33278,11 @@
33278
33279 winMemAssertMagic();
33280 hHeap = winMemGetHeap();
33281 assert( hHeap!=0 );
33282 assert( hHeap!=INVALID_HANDLE_VALUE );
33283 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
33284 assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
33285 #endif
33286 if( !p ) return 0;
33287 n = osHeapSize(hHeap, SQLITE_WIN32_HEAP_FLAGS, p);
33288 if( n==(SIZE_T)-1 ){
@@ -32977,10 +33306,12 @@
33306 static int winMemInit(void *pAppData){
33307 winMemData *pWinMemData = (winMemData *)pAppData;
33308
33309 if( !pWinMemData ) return SQLITE_ERROR;
33310 assert( pWinMemData->magic==WINMEM_MAGIC );
33311
33312 #if !SQLITE_OS_WINRT && SQLITE_WIN32_HEAP_CREATE
33313 if( !pWinMemData->hHeap ){
33314 pWinMemData->hHeap = osHeapCreate(SQLITE_WIN32_HEAP_FLAGS,
33315 SQLITE_WIN32_HEAP_INIT_SIZE,
33316 SQLITE_WIN32_HEAP_MAX_SIZE);
33317 if( !pWinMemData->hHeap ){
@@ -32989,14 +33320,25 @@
33320 osGetLastError(), SQLITE_WIN32_HEAP_FLAGS,
33321 SQLITE_WIN32_HEAP_INIT_SIZE, SQLITE_WIN32_HEAP_MAX_SIZE);
33322 return SQLITE_NOMEM;
33323 }
33324 pWinMemData->bOwned = TRUE;
33325 assert( pWinMemData->bOwned );
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
33337 assert( pWinMemData->hHeap!=0 );
33338 assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE );
33339 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
33340 assert( osHeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
33341 #endif
33342 return SQLITE_OK;
33343 }
33344
@@ -33007,11 +33349,11 @@
33349 winMemData *pWinMemData = (winMemData *)pAppData;
33350
33351 if( !pWinMemData ) return;
33352 if( pWinMemData->hHeap ){
33353 assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE );
33354 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
33355 assert( osHeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
33356 #endif
33357 if( pWinMemData->bOwned ){
33358 if( !osHeapDestroy(pWinMemData->hHeap) ){
33359 sqlite3_log(SQLITE_NOMEM, "failed to HeapDestroy (%d), heap=%p",
@@ -33207,10 +33549,21 @@
33549 */
33550 DWORD dwLen = 0;
33551 char *zOut = 0;
33552
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
33565 LPWSTR zTempWide = NULL;
33566 dwLen = osFormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
33567 FORMAT_MESSAGE_FROM_SYSTEM |
33568 FORMAT_MESSAGE_IGNORE_INSERTS,
33569 NULL,
@@ -33217,24 +33570,24 @@
33570 lastErrno,
33571 0,
33572 (LPWSTR) &zTempWide,
33573 0,
33574 0);
33575 #endif
33576 if( dwLen > 0 ){
33577 /* allocate a buffer and convert to UTF8 */
33578 sqlite3BeginBenignMalloc();
33579 zOut = unicodeToUtf8(zTempWide);
33580 sqlite3EndBenignMalloc();
33581 #if !SQLITE_OS_WINRT
33582 /* free the system buffer allocated by FormatMessage */
33583 osLocalFree(zTempWide);
33584 #endif
33585 }
33586 }
33587 #ifdef SQLITE_WIN32_HAS_ANSI
33588 else{
 
 
 
33589 char *zTemp = NULL;
33590 dwLen = osFormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
33591 FORMAT_MESSAGE_FROM_SYSTEM |
33592 FORMAT_MESSAGE_IGNORE_INSERTS,
33593 NULL,
@@ -33249,12 +33602,12 @@
33602 zOut = sqlite3_win32_mbcs_to_utf8(zTemp);
33603 sqlite3EndBenignMalloc();
33604 /* free the system buffer allocated by FormatMessage */
33605 osLocalFree(zTemp);
33606 }
33607 }
33608 #endif
 
33609 if( 0 == dwLen ){
33610 sqlite3_snprintf(nBuf, zBuf, "OsError 0x%x (%u)", lastErrno, lastErrno);
33611 }else{
33612 /* copy a maximum of nBuf chars to output buffer */
33613 sqlite3_snprintf(nBuf, zBuf, "%s", zOut);
@@ -33333,11 +33686,11 @@
33686 return 0;
33687 }
33688 if( e==ERROR_ACCESS_DENIED ||
33689 e==ERROR_LOCK_VIOLATION ||
33690 e==ERROR_SHARING_VIOLATION ){
33691 sqlite3_win32_sleep(win32IoerrRetryDelay*(1+*pnRetry));
33692 ++*pnRetry;
33693 return 1;
33694 }
33695 if( pError ){
33696 *pError = e;
@@ -33394,11 +33747,11 @@
33747 ** Acquire a lock on the handle h
33748 */
33749 static void winceMutexAcquire(HANDLE h){
33750 DWORD dwErr;
33751 do {
33752 dwErr = osWaitForSingleObject(h, INFINITE);
33753 } while (dwErr != WAIT_OBJECT_0 && dwErr != WAIT_ABANDONED);
33754 }
33755 /*
33756 ** Release a lock acquired by winceMutexAcquire()
33757 */
@@ -33525,11 +33878,11 @@
33878
33879 /*
33880 ** An implementation of the LockFile() API of Windows for CE
33881 */
33882 static BOOL winceLockFile(
33883 LPHANDLE phFile,
33884 DWORD dwFileOffsetLow,
33885 DWORD dwFileOffsetHigh,
33886 DWORD nNumberOfBytesToLockLow,
33887 DWORD nNumberOfBytesToLockHigh
33888 ){
@@ -33589,11 +33942,11 @@
33942
33943 /*
33944 ** An implementation of the UnlockFile API of Windows for CE
33945 */
33946 static BOOL winceUnlockFile(
33947 LPHANDLE phFile,
33948 DWORD dwFileOffsetLow,
33949 DWORD dwFileOffsetHigh,
33950 DWORD nNumberOfBytesToUnlockLow,
33951 DWORD nNumberOfBytesToUnlockHigh
33952 ){
@@ -33646,38 +33999,77 @@
33999 }
34000
34001 winceMutexRelease(pFile->hMutex);
34002 return bReturn;
34003 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34004 /*
34005 ** End of the special code for wince
34006 *****************************************************************************/
34007 #endif /* SQLITE_OS_WINCE */
34008
34009 /*
34010 ** Lock a file region.
34011 */
34012 static BOOL winLockFile(
34013 LPHANDLE phFile,
34014 DWORD flags,
34015 DWORD offsetLow,
34016 DWORD offsetHigh,
34017 DWORD numBytesLow,
34018 DWORD numBytesHigh
34019 ){
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);
34037 }
34038 #endif
34039 }
34040
34041 /*
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 ){
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 }
34071
34072 /*****************************************************************************
34073 ** The next group of routines implement the I/O methods specified
34074 ** by the sqlite3_io_methods object.
34075 ******************************************************************************/
@@ -33693,10 +34085,11 @@
34085 ** Move the current position of the file handle passed as the first
34086 ** argument to offset iOffset within the file. If successful, return 0.
34087 ** Otherwise, set pFile->lastErrno and return non-zero.
34088 */
34089 static int seekWinFile(winFile *pFile, sqlite3_int64 iOffset){
34090 #if !SQLITE_OS_WINRT
34091 LONG upperBits; /* Most sig. 32 bits of new offset */
34092 LONG lowerBits; /* Least sig. 32 bits of new offset */
34093 DWORD dwRet; /* Value returned by SetFilePointer() */
34094 DWORD lastErrno; /* Value returned by GetLastError() */
34095
@@ -33719,10 +34112,30 @@
34112 "seekWinFile", pFile->zPath);
34113 return 1;
34114 }
34115
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
34137 }
34138
34139 /*
34140 ** Close a file.
34141 **
@@ -33742,11 +34155,11 @@
34155 assert( pFile->pShm==0 );
34156 OSTRACE(("CLOSE %d\n", pFile->h));
34157 do{
34158 rc = osCloseHandle(pFile->h);
34159 /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */
34160 }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (sqlite3_win32_sleep(100), 1) );
34161 #if SQLITE_OS_WINCE
34162 #define WINCE_DELETION_ATTEMPTS 3
34163 winceDestroyLock(pFile);
34164 if( pFile->zDeleteOnClose ){
34165 int cnt = 0;
@@ -33753,11 +34166,11 @@
34166 while(
34167 osDeleteFileW(pFile->zDeleteOnClose)==0
34168 && osGetFileAttributesW(pFile->zDeleteOnClose)!=0xffffffff
34169 && cnt++ < WINCE_DELETION_ATTEMPTS
34170 ){
34171 sqlite3_win32_sleep(100); /* Wait a little before trying again */
34172 }
34173 sqlite3_free(pFile->zDeleteOnClose);
34174 }
34175 #endif
34176 OSTRACE(("CLOSE %d %s\n", pFile->h, rc ? "ok" : "failed"));
@@ -34008,60 +34421,105 @@
34421
34422 /*
34423 ** Determine the current size of a file in bytes
34424 */
34425 static int winFileSize(sqlite3_file *id, sqlite3_int64 *pSize){
 
 
34426 winFile *pFile = (winFile*)id;
34427 int rc = SQLITE_OK;
34428
34429 assert( id!=0 );
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
34449 lowerBits = osGetFileSize(pFile->h, &upperBits);
34450 *pSize = (((sqlite3_int64)upperBits)<<32) + lowerBits;
34451 if( (lowerBits == INVALID_FILE_SIZE)
34452 && ((lastErrno = osGetLastError())!=NO_ERROR) ){
34453 pFile->lastErrno = lastErrno;
34454 rc = winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno,
34455 "winFileSize", pFile->zPath);
34456 }
34457 }
34458 #endif
34459 return rc;
34460 }
34461
34462 /*
34463 ** LOCKFILE_FAIL_IMMEDIATELY is undefined on some Windows systems.
34464 */
34465 #ifndef LOCKFILE_FAIL_IMMEDIATELY
34466 # define LOCKFILE_FAIL_IMMEDIATELY 1
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
34492
34493 /*
34494 ** Acquire a reader lock.
34495 ** Different API routines are called depending on whether or not this
34496 ** is Win9x or WinNT.
34497 */
34498 static int getReadLock(winFile *pFile){
34499 int res;
34500 if( isNT() ){
34501 #if SQLITE_OS_WINCE
34502 /*
34503 ** NOTE: Windows CE is handled differently here due its lack of the Win32
34504 ** API LockFileEx.
34505 */
34506 res = winceLockFile(&pFile->h, SHARED_FIRST, 0, 1, 0);
34507 #else
34508 res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS, SHARED_FIRST, 0,
34509 SHARED_SIZE, 0);
34510 #endif
34511 }
34512 #ifdef SQLITE_WIN32_HAS_ANSI
34513 else{
34514 int lk;
34515 sqlite3_randomness(sizeof(lk), &lk);
34516 pFile->sharedLockByte = (short)((lk & 0x7fffffff)%(SHARED_SIZE - 1));
34517 res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS,
34518 SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
34519 }
34520 #endif
 
34521 if( res == 0 ){
34522 pFile->lastErrno = osGetLastError();
34523 /* No need to log a failure to lock */
34524 }
34525 return res;
@@ -34072,18 +34530,17 @@
34530 */
34531 static int unlockReadLock(winFile *pFile){
34532 int res;
34533 DWORD lastErrno;
34534 if( isNT() ){
34535 res = winUnlockFile(&pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
34536 }
34537 #ifdef SQLITE_WIN32_HAS_ANSI
34538 else{
34539 res = winUnlockFile(&pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
34540 }
34541 #endif
 
34542 if( res==0 && ((lastErrno = osGetLastError())!=ERROR_NOT_LOCKED) ){
34543 pFile->lastErrno = lastErrno;
34544 winLogError(SQLITE_IOERR_UNLOCK, pFile->lastErrno,
34545 "unlockReadLock", pFile->zPath);
34546 }
@@ -34150,19 +34607,20 @@
34607 if( (pFile->locktype==NO_LOCK)
34608 || ( (locktype==EXCLUSIVE_LOCK)
34609 && (pFile->locktype==RESERVED_LOCK))
34610 ){
34611 int cnt = 3;
34612 while( cnt-->0 && (res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS,
34613 PENDING_BYTE, 0, 1, 0))==0 ){
34614 /* Try 3 times to get the pending lock. This is needed to work
34615 ** around problems caused by indexing and/or anti-virus software on
34616 ** Windows systems.
34617 ** If you are using this code as a model for alternative VFSes, do not
34618 ** copy this retry logic. It is a hack intended for Windows only.
34619 */
34620 OSTRACE(("could not get a PENDING lock. cnt=%d\n", cnt));
34621 if( cnt ) sqlite3_win32_sleep(1);
34622 }
34623 gotPendingLock = res;
34624 if( !res ){
34625 lastErrno = osGetLastError();
34626 }
@@ -34182,11 +34640,11 @@
34640
34641 /* Acquire a RESERVED lock
34642 */
34643 if( locktype==RESERVED_LOCK && res ){
34644 assert( pFile->locktype==SHARED_LOCK );
34645 res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS, RESERVED_BYTE, 0, 1, 0);
34646 if( res ){
34647 newLocktype = RESERVED_LOCK;
34648 }else{
34649 lastErrno = osGetLastError();
34650 }
@@ -34203,11 +34661,12 @@
34661 */
34662 if( locktype==EXCLUSIVE_LOCK && res ){
34663 assert( pFile->locktype>=SHARED_LOCK );
34664 res = unlockReadLock(pFile);
34665 OSTRACE(("unreadlock = %d\n", res));
34666 res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS, SHARED_FIRST, 0,
34667 SHARED_SIZE, 0);
34668 if( res ){
34669 newLocktype = EXCLUSIVE_LOCK;
34670 }else{
34671 lastErrno = osGetLastError();
34672 OSTRACE(("error-code = %d\n", lastErrno));
@@ -34217,11 +34676,11 @@
34676
34677 /* If we are holding a PENDING lock that ought to be released, then
34678 ** release it now.
34679 */
34680 if( gotPendingLock && locktype==SHARED_LOCK ){
34681 winUnlockFile(&pFile->h, PENDING_BYTE, 0, 1, 0);
34682 }
34683
34684 /* Update the state of the lock has held in the file descriptor then
34685 ** return the appropriate result code.
34686 */
@@ -34251,13 +34710,13 @@
34710 assert( id!=0 );
34711 if( pFile->locktype>=RESERVED_LOCK ){
34712 rc = 1;
34713 OSTRACE(("TEST WR-LOCK %d %d (local)\n", pFile->h, rc));
34714 }else{
34715 rc = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS, RESERVED_BYTE, 0, 1, 0);
34716 if( rc ){
34717 winUnlockFile(&pFile->h, RESERVED_BYTE, 0, 1, 0);
34718 }
34719 rc = !rc;
34720 OSTRACE(("TEST WR-LOCK %d %d (remote)\n", pFile->h, rc));
34721 }
34722 *pResOut = rc;
@@ -34283,26 +34742,26 @@
34742 assert( locktype<=SHARED_LOCK );
34743 OSTRACE(("UNLOCK %d to %d was %d(%d)\n", pFile->h, locktype,
34744 pFile->locktype, pFile->sharedLockByte));
34745 type = pFile->locktype;
34746 if( type>=EXCLUSIVE_LOCK ){
34747 winUnlockFile(&pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
34748 if( locktype==SHARED_LOCK && !getReadLock(pFile) ){
34749 /* This should never happen. We should always be able to
34750 ** reacquire the read lock */
34751 rc = winLogError(SQLITE_IOERR_UNLOCK, osGetLastError(),
34752 "winUnlock", pFile->zPath);
34753 }
34754 }
34755 if( type>=RESERVED_LOCK ){
34756 winUnlockFile(&pFile->h, RESERVED_BYTE, 0, 1, 0);
34757 }
34758 if( locktype==NO_LOCK && type>=SHARED_LOCK ){
34759 unlockReadLock(pFile);
34760 }
34761 if( type>=PENDING_LOCK ){
34762 winUnlockFile(&pFile->h, PENDING_BYTE, 0, 1, 0);
34763 }
34764 pFile->locktype = (u8)locktype;
34765 return rc;
34766 }
34767
@@ -34536,29 +34995,23 @@
34995 winShmNode *pFile, /* Apply locks to this open shared-memory segment */
34996 int lockType, /* _SHM_UNLCK, _SHM_RDLCK, or _SHM_WRLCK */
34997 int ofst, /* Offset to first byte to be locked/unlocked */
34998 int nByte /* Number of bytes to lock or unlock */
34999 ){
 
 
35000 int rc = 0; /* Result code form Lock/UnlockFileEx() */
35001
35002 /* Access to the winShmNode object is serialized by the caller */
35003 assert( sqlite3_mutex_held(pFile->mutex) || pFile->nRef==0 );
35004
 
 
 
 
 
 
 
35005 /* Release/Acquire the system-level lock */
35006 if( lockType==_SHM_UNLCK ){
35007 rc = winUnlockFile(&pFile->hFile.h, ofst, 0, nByte, 0);
35008 }else{
35009 /* Initialize the locking parameters */
35010 DWORD dwFlags = LOCKFILE_FAIL_IMMEDIATELY;
35011 if( lockType == _SHM_WRLCK ) dwFlags |= LOCKFILE_EXCLUSIVE_LOCK;
35012 rc = winLockFile(&pFile->hFile.h, dwFlags, ofst, 0, nByte, 0);
35013 }
35014
35015 if( rc!= 0 ){
35016 rc = SQLITE_OK;
35017 }else{
@@ -34992,22 +35445,34 @@
35445
35446 while( pShmNode->nRegion<=iRegion ){
35447 HANDLE hMap; /* file-mapping handle */
35448 void *pMap = 0; /* Mapped memory region */
35449
35450 #if SQLITE_OS_WINRT
35451 hMap = osCreateFileMappingFromApp(pShmNode->hFile.h,
35452 NULL, PAGE_READWRITE, nByte, NULL
35453 );
35454 #else
35455 hMap = osCreateFileMappingW(pShmNode->hFile.h,
35456 NULL, PAGE_READWRITE, 0, nByte, NULL
35457 );
35458 #endif
35459 OSTRACE(("SHM-MAP pid-%d create region=%d nbyte=%d %s\n",
35460 (int)osGetCurrentProcessId(), pShmNode->nRegion, nByte,
35461 hMap ? "ok" : "failed"));
35462 if( hMap ){
35463 int iOffset = pShmNode->nRegion*szRegion;
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
35470 pMap = osMapViewOfFile(hMap, FILE_MAP_WRITE | FILE_MAP_READ,
35471 0, iOffset - iOffsetShift, szRegion + iOffsetShift
35472 );
35473 #endif
35474 OSTRACE(("SHM-MAP pid-%d map region=%d offset=%d size=%d %s\n",
35475 (int)osGetCurrentProcessId(), pShmNode->nRegion, iOffset,
35476 szRegion, pMap ? "ok" : "failed"));
35477 }
35478 if( !pMap ){
@@ -35089,17 +35554,16 @@
35554 */
35555 static void *convertUtf8Filename(const char *zFilename){
35556 void *zConverted = 0;
35557 if( isNT() ){
35558 zConverted = utf8ToUnicode(zFilename);
35559 }
35560 #ifdef SQLITE_WIN32_HAS_ANSI
35561 else{
 
35562 zConverted = sqlite3_win32_utf8_to_mbcs(zFilename);
35563 }
35564 #endif
 
35565 /* caller will handle out of memory */
35566 return zConverted;
35567 }
35568
35569 /*
@@ -35110,21 +35574,26 @@
35574 static char zChars[] =
35575 "abcdefghijklmnopqrstuvwxyz"
35576 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
35577 "0123456789";
35578 size_t i, j;
35579 int nTempPath;
35580 char zTempPath[MAX_PATH+2];
35581
35582 /* It's odd to simulate an io-error here, but really this is just
35583 ** using the io-error infrastructure to test that SQLite handles this
35584 ** function failing.
35585 */
35586 SimulateIOError( return SQLITE_IOERR );
35587
35588 memset(zTempPath, 0, MAX_PATH+2);
35589
35590 if( sqlite3_temp_directory ){
35591 sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", sqlite3_temp_directory);
35592 }
35593 #if !SQLITE_OS_WINRT
35594 else if( isNT() ){
35595 char *zMulti;
35596 WCHAR zWidePath[MAX_PATH];
35597 osGetTempPathW(MAX_PATH-30, zWidePath);
35598 zMulti = unicodeToUtf8(zWidePath);
35599 if( zMulti ){
@@ -35131,16 +35600,13 @@
35600 sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zMulti);
35601 sqlite3_free(zMulti);
35602 }else{
35603 return SQLITE_IOERR_NOMEM;
35604 }
35605 }
35606 #ifdef SQLITE_WIN32_HAS_ANSI
35607 else{
 
 
 
35608 char *zUtf8;
35609 char zMbcsPath[MAX_PATH];
35610 osGetTempPathA(MAX_PATH-30, zMbcsPath);
35611 zUtf8 = sqlite3_win32_mbcs_to_utf8(zMbcsPath);
35612 if( zUtf8 ){
@@ -35147,25 +35613,29 @@
35613 sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zUtf8);
35614 sqlite3_free(zUtf8);
35615 }else{
35616 return SQLITE_IOERR_NOMEM;
35617 }
35618 }
35619 #endif
35620 #endif
35621
35622 /* Check that the output buffer is large enough for the temporary file
35623 ** name. If it is not, return SQLITE_ERROR.
35624 */
35625 nTempPath = sqlite3Strlen30(zTempPath);
35626
35627 if( (nTempPath + sqlite3Strlen30(SQLITE_TEMP_FILE_PREFIX) + 18) >= nBuf ){
35628 return SQLITE_ERROR;
35629 }
35630
35631 for(i=nTempPath; i>0 && zTempPath[i-1]=='\\'; i--){}
35632 zTempPath[i] = 0;
35633
35634 sqlite3_snprintf(nBuf-18, zBuf, (nTempPath > 0) ?
35635 "%s\\"SQLITE_TEMP_FILE_PREFIX : SQLITE_TEMP_FILE_PREFIX,
35636 zTempPath);
35637 j = sqlite3Strlen30(zBuf);
35638 sqlite3_randomness(15, &zBuf[j]);
35639 for(i=0; i<15; i++, j++){
35640 zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
35641 }
@@ -35357,33 +35827,52 @@
35827 #if SQLITE_OS_WINCE
35828 dwFlagsAndAttributes |= FILE_FLAG_RANDOM_ACCESS;
35829 #endif
35830
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
35850 while( (h = osCreateFileW((LPCWSTR)zConverted,
35851 dwDesiredAccess,
35852 dwShareMode, NULL,
35853 dwCreationDisposition,
35854 dwFlagsAndAttributes,
35855 NULL))==INVALID_HANDLE_VALUE &&
35856 retryIoerr(&cnt, &lastErrno) ){
35857 /* Noop */
35858 }
35859 #endif
35860 }
35861 #ifdef SQLITE_WIN32_HAS_ANSI
35862 else{
35863 while( (h = osCreateFileA((LPCSTR)zConverted,
35864 dwDesiredAccess,
35865 dwShareMode, NULL,
35866 dwCreationDisposition,
35867 dwFlagsAndAttributes,
35868 NULL))==INVALID_HANDLE_VALUE &&
35869 retryIoerr(&cnt, &lastErrno) ){
35870 /* Noop */
35871 }
35872 }
35873 #endif
 
 
35874 logIoerr(cnt);
35875
35876 OSTRACE(("OPEN %d %s 0x%lx %s\n",
35877 h, zName, dwDesiredAccess,
35878 h==INVALID_HANDLE_VALUE ? "failed" : "ok"));
@@ -35469,11 +35958,23 @@
35958 if( zConverted==0 ){
35959 return SQLITE_IOERR_NOMEM;
35960 }
35961 if( isNT() ){
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
35974 attr = osGetFileAttributesW(zConverted);
35975 #endif
35976 if ( attr==INVALID_FILE_ATTRIBUTES ){
35977 rc = SQLITE_OK; /* Already gone? */
35978 break;
35979 }
35980 if ( attr&FILE_ATTRIBUTE_DIRECTORY ){
@@ -35487,16 +35988,13 @@
35988 if ( !retryIoerr(&cnt, &lastErrno) ){
35989 rc = SQLITE_ERROR; /* No more retries. */
35990 break;
35991 }
35992 } while(1);
35993 }
35994 #ifdef SQLITE_WIN32_HAS_ANSI
35995 else{
 
 
 
35996 do {
35997 attr = osGetFileAttributesA(zConverted);
35998 if ( attr==INVALID_FILE_ATTRIBUTES ){
35999 rc = SQLITE_OK; /* Already gone? */
36000 break;
@@ -35512,12 +36010,12 @@
36010 if ( !retryIoerr(&cnt, &lastErrno) ){
36011 rc = SQLITE_ERROR; /* No more retries. */
36012 break;
36013 }
36014 } while(1);
36015 }
36016 #endif
 
36017 if( rc ){
36018 rc = winLogError(SQLITE_IOERR_DELETE, lastErrno,
36019 "winDelete", zFilename);
36020 }else{
36021 logIoerr(cnt);
@@ -35573,19 +36071,16 @@
36071 return SQLITE_IOERR_ACCESS;
36072 }else{
36073 attr = INVALID_FILE_ATTRIBUTES;
36074 }
36075 }
36076 }
36077 #ifdef SQLITE_WIN32_HAS_ANSI
36078 else{
 
 
 
36079 attr = osGetFileAttributesA((char*)zConverted);
36080 }
36081 #endif
 
36082 sqlite3_free(zConverted);
36083 switch( flags ){
36084 case SQLITE_ACCESS_READ:
36085 case SQLITE_ACCESS_EXISTS:
36086 rc = attr!=INVALID_FILE_ATTRIBUTES;
@@ -35599,10 +36094,47 @@
36094 }
36095 *pResOut = rc;
36096 return SQLITE_OK;
36097 }
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 }
36136
36137 /*
36138 ** Turn a relative pathname into a full pathname. Write the full
36139 ** pathname into zOut[]. zOut[] will be at least pVfs->mxPathname
36140 ** bytes in size.
@@ -35615,23 +36147,55 @@
36147 ){
36148
36149 #if defined(__CYGWIN__)
36150 SimulateIOError( return SQLITE_ERROR );
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 */
36172 cygwin_conv_to_full_win32_path(zRelative, zFull);
36173 }
36174 return SQLITE_OK;
36175 #endif
36176
36177 #if (SQLITE_OS_WINCE || SQLITE_OS_WINRT) && !defined(__CYGWIN__)
36178 SimulateIOError( return SQLITE_ERROR );
 
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{
36191 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zRelative);
36192 }
36193 return SQLITE_OK;
36194 #endif
36195
36196 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(__CYGWIN__)
36197 int nByte;
36198 void *zConverted;
36199 char *zOut;
36200
36201 /* If this path name begins with "/X:", where "X" is any alphabetic
@@ -35645,11 +36209,21 @@
36209 ** using the io-error infrastructure to test that SQLite handles this
36210 ** function failing. This function could fail if, for example, the
36211 ** current working directory has been unlinked.
36212 */
36213 SimulateIOError( return SQLITE_ERROR );
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 }
36225 zConverted = convertUtf8Filename(zRelative);
36226 if( zConverted==0 ){
36227 return SQLITE_IOERR_NOMEM;
36228 }
36229 if( isNT() ){
@@ -35662,16 +36236,13 @@
36236 }
36237 osGetFullPathNameW((LPCWSTR)zConverted, nByte, zTemp, 0);
36238 sqlite3_free(zConverted);
36239 zOut = unicodeToUtf8(zTemp);
36240 sqlite3_free(zTemp);
36241 }
36242 #ifdef SQLITE_WIN32_HAS_ANSI
36243 else{
 
 
 
36244 char *zTemp;
36245 nByte = osGetFullPathNameA((char*)zConverted, 0, 0, 0) + 3;
36246 zTemp = sqlite3_malloc( nByte*sizeof(zTemp[0]) );
36247 if( zTemp==0 ){
36248 sqlite3_free(zConverted);
@@ -35679,14 +36250,14 @@
36250 }
36251 osGetFullPathNameA((char*)zConverted, nByte, zTemp, 0);
36252 sqlite3_free(zConverted);
36253 zOut = sqlite3_win32_mbcs_to_utf8(zTemp);
36254 sqlite3_free(zTemp);
36255 }
36256 #endif
 
36257 if( zOut ){
36258 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zOut);
36259 sqlite3_free(zOut);
36260 return SQLITE_OK;
36261 }else{
36262 return SQLITE_IOERR_NOMEM;
36263 }
@@ -35708,20 +36279,21 @@
36279 UNUSED_PARAMETER(pVfs);
36280 if( zConverted==0 ){
36281 return 0;
36282 }
36283 if( isNT() ){
36284 #if SQLITE_OS_WINRT
36285 h = osLoadPackagedLibrary((LPCWSTR)zConverted, 0);
36286 #else
36287 h = osLoadLibraryW((LPCWSTR)zConverted);
36288 #endif
36289 }
36290 #ifdef SQLITE_WIN32_HAS_ANSI
36291 else{
 
 
36292 h = osLoadLibraryA((char*)zConverted);
36293 }
36294 #endif
 
36295 sqlite3_free(zConverted);
36296 return (void*)h;
36297 }
36298 static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){
36299 UNUSED_PARAMETER(pVfs);
@@ -35762,15 +36334,23 @@
36334 if( sizeof(DWORD)<=nBuf-n ){
36335 DWORD pid = osGetCurrentProcessId();
36336 memcpy(&zBuf[n], &pid, sizeof(pid));
36337 n += sizeof(pid);
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
36346 if( sizeof(DWORD)<=nBuf-n ){
36347 DWORD cnt = osGetTickCount();
36348 memcpy(&zBuf[n], &cnt, sizeof(cnt));
36349 n += sizeof(cnt);
36350 }
36351 #endif
36352 if( sizeof(LARGE_INTEGER)<=nBuf-n ){
36353 LARGE_INTEGER i;
36354 osQueryPerformanceCounter(&i);
36355 memcpy(&zBuf[n], &i, sizeof(i));
36356 n += sizeof(i);
@@ -35782,11 +36362,11 @@
36362
36363 /*
36364 ** Sleep for a little while. Return the amount of time slept.
36365 */
36366 static int winSleep(sqlite3_vfs *pVfs, int microsec){
36367 sqlite3_win32_sleep((microsec+999)/1000);
36368 UNUSED_PARAMETER(pVfs);
36369 return ((microsec+999)/1000)*1000;
36370 }
36371
36372 /*
@@ -35924,24 +36504,34 @@
36504 winNextSystemCall, /* xNextSystemCall */
36505 };
36506
36507 /* Double-check that the aSyscall[] array has been constructed
36508 ** correctly. See ticket [bb3a86e890c8e96ab] */
36509 assert( ArraySize(aSyscall)==73 );
36510
36511 #ifndef SQLITE_OMIT_WAL
36512 /* get memory map allocation granularity */
36513 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
36514 #if SQLITE_OS_WINRT
36515 osGetNativeSystemInfo(&winSysInfo);
36516 #else
36517 osGetSystemInfo(&winSysInfo);
36518 #endif
36519 assert(winSysInfo.dwAllocationGranularity > 0);
36520 #endif
36521
36522 sqlite3_vfs_register(&winVfs, 1);
36523 return SQLITE_OK;
36524 }
36525
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
36533 return SQLITE_OK;
36534 }
36535
36536 #endif /* SQLITE_OS_WIN */
36537
@@ -37189,16 +37779,18 @@
37779 if( p==0 ){
37780 /* Memory is not available in the SQLITE_CONFIG_PAGECACHE pool. Get
37781 ** it from sqlite3Malloc instead.
37782 */
37783 p = sqlite3Malloc(nByte);
37784 #ifndef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
37785 if( p ){
37786 int sz = sqlite3MallocSize(p);
37787 sqlite3_mutex_enter(pcache1.mutex);
37788 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz);
37789 sqlite3_mutex_leave(pcache1.mutex);
37790 }
37791 #endif
37792 sqlite3MemdebugSetType(p, MEMTYPE_PCACHE);
37793 }
37794 return p;
37795 }
37796
@@ -37221,13 +37813,15 @@
37813 sqlite3_mutex_leave(pcache1.mutex);
37814 }else{
37815 assert( sqlite3MemdebugHasType(p, MEMTYPE_PCACHE) );
37816 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
37817 nFreed = sqlite3MallocSize(p);
37818 #ifndef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
37819 sqlite3_mutex_enter(pcache1.mutex);
37820 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -nFreed);
37821 sqlite3_mutex_leave(pcache1.mutex);
37822 #endif
37823 sqlite3_free(p);
37824 }
37825 return nFreed;
37826 }
37827
@@ -43006,11 +43600,16 @@
43600 *ppPager = 0;
43601
43602 #ifndef SQLITE_OMIT_MEMORYDB
43603 if( flags & PAGER_MEMORY ){
43604 memDb = 1;
43605 if( zFilename && zFilename[0] ){
43606 zPathname = sqlite3DbStrDup(0, zFilename);
43607 if( zPathname==0 ) return SQLITE_NOMEM;
43608 nPathname = sqlite3Strlen30(zPathname);
43609 zFilename = 0;
43610 }
43611 }
43612 #endif
43613
43614 /* Compute and store the full pathname in an allocated buffer pointed
43615 ** to by zPathname, length nPathname. Or, if this is a temporary file,
@@ -43017,11 +43616,11 @@
43616 ** leave both nPathname and zPathname set to 0.
43617 */
43618 if( zFilename && zFilename[0] ){
43619 const char *z;
43620 nPathname = pVfs->mxPathname+1;
43621 zPathname = sqlite3DbMallocRaw(0, nPathname*2);
43622 if( zPathname==0 ){
43623 return SQLITE_NOMEM;
43624 }
43625 zPathname[0] = 0; /* Make sure initialized even if FullPathname() fails */
43626 rc = sqlite3OsFullPathname(pVfs, zFilename, nPathname, zPathname);
@@ -43041,11 +43640,11 @@
43640 ** check for a hot-journal before reading.
43641 */
43642 rc = SQLITE_CANTOPEN_BKPT;
43643 }
43644 if( rc!=SQLITE_OK ){
43645 sqlite3DbFree(0, zPathname);
43646 return rc;
43647 }
43648 }
43649
43650 /* Allocate memory for the Pager structure, PCache object, the
@@ -43071,11 +43670,11 @@
43670 + nPathname + 4 + 2 /* zWal */
43671 #endif
43672 );
43673 assert( EIGHT_BYTE_ALIGNMENT(SQLITE_INT_TO_PTR(journalFileSize)) );
43674 if( !pPtr ){
43675 sqlite3DbFree(0, zPathname);
43676 return SQLITE_NOMEM;
43677 }
43678 pPager = (Pager*)(pPtr);
43679 pPager->pPCache = (PCache*)(pPtr += ROUND8(sizeof(*pPager)));
43680 pPager->fd = (sqlite3_file*)(pPtr += ROUND8(pcacheSize));
@@ -43087,21 +43686,21 @@
43686 /* Fill in the Pager.zFilename and Pager.zJournal buffers, if required. */
43687 if( zPathname ){
43688 assert( nPathname>0 );
43689 pPager->zJournal = (char*)(pPtr += nPathname + 1 + nUri);
43690 memcpy(pPager->zFilename, zPathname, nPathname);
43691 if( nUri ) memcpy(&pPager->zFilename[nPathname+1], zUri, nUri);
43692 memcpy(pPager->zJournal, zPathname, nPathname);
43693 memcpy(&pPager->zJournal[nPathname], "-journal\000", 8+1);
43694 sqlite3FileSuffix3(pPager->zFilename, pPager->zJournal);
43695 #ifndef SQLITE_OMIT_WAL
43696 pPager->zWal = &pPager->zJournal[nPathname+8+1];
43697 memcpy(pPager->zWal, zPathname, nPathname);
43698 memcpy(&pPager->zWal[nPathname], "-wal\000", 4+1);
43699 sqlite3FileSuffix3(pPager->zFilename, pPager->zWal);
43700 #endif
43701 sqlite3DbFree(0, zPathname);
43702 }
43703 pPager->pVfs = pVfs;
43704 pPager->vfsFlags = vfsFlags;
43705
43706 /* Open the pager file.
@@ -44942,13 +45541,20 @@
45541 return rc;
45542 }
45543
45544 /*
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.
45553 */
45554 SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager *pPager, int nullIfMemDb){
45555 return (nullIfMemDb && pPager->memDb) ? "" : pPager->zFilename;
45556 }
45557
45558 /*
45559 ** Return the VFS structure for the pager.
45560 */
@@ -51329,11 +51935,12 @@
51935 */
51936 #ifdef SQLITE_OMIT_MEMORYDB
51937 const int isMemdb = 0;
51938 #else
51939 const int isMemdb = (zFilename && strcmp(zFilename, ":memory:")==0)
51940 || (isTempDb && sqlite3TempInMemory(db))
51941 || (vfsFlags & SQLITE_OPEN_MEMORY)!=0;
51942 #endif
51943
51944 assert( db!=0 );
51945 assert( pVfs!=0 );
51946 assert( sqlite3_mutex_held(db->mutex) );
@@ -51365,35 +51972,40 @@
51972 #if !defined(SQLITE_OMIT_SHARED_CACHE) && !defined(SQLITE_OMIT_DISKIO)
51973 /*
51974 ** If this Btree is a candidate for shared cache, try to find an
51975 ** existing BtShared object that we can share with
51976 */
51977 if( isTempDb==0 && (isMemdb==0 || (vfsFlags&SQLITE_OPEN_URI)!=0) ){
51978 if( vfsFlags & SQLITE_OPEN_SHAREDCACHE ){
51979 int nFullPathname = pVfs->mxPathname+1;
51980 char *zFullPathname = sqlite3Malloc(nFullPathname);
51981 MUTEX_LOGIC( sqlite3_mutex *mutexShared; )
51982 p->sharable = 1;
51983 if( !zFullPathname ){
51984 sqlite3_free(p);
51985 return SQLITE_NOMEM;
51986 }
51987 if( isMemdb ){
51988 memcpy(zFullPathname, zFilename, sqlite3Strlen30(zFilename)+1);
51989 }else{
51990 rc = sqlite3OsFullPathname(pVfs, zFilename,
51991 nFullPathname, zFullPathname);
51992 if( rc ){
51993 sqlite3_free(zFullPathname);
51994 sqlite3_free(p);
51995 return rc;
51996 }
51997 }
51998 #if SQLITE_THREADSAFE
51999 mutexOpen = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_OPEN);
52000 sqlite3_mutex_enter(mutexOpen);
52001 mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
52002 sqlite3_mutex_enter(mutexShared);
52003 #endif
52004 for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){
52005 assert( pBt->nRef>0 );
52006 if( 0==strcmp(zFullPathname, sqlite3PagerFilename(pBt->pPager, 0))
52007 && sqlite3PagerVfs(pBt->pPager)==pVfs ){
52008 int iDb;
52009 for(iDb=db->nDb-1; iDb>=0; iDb--){
52010 Btree *pExisting = db->aDb[iDb].pBt;
52011 if( pExisting && pExisting->pBt==pBt ){
@@ -57654,18 +58266,19 @@
58266 return sqlite3StrAccumFinish(&sCheck.errMsg);
58267 }
58268 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
58269
58270 /*
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.
58273 **
58274 ** The pager filename is invariant as long as the pager is
58275 ** open so it is safe to access without the BtShared mutex.
58276 */
58277 SQLITE_PRIVATE const char *sqlite3BtreeGetFilename(Btree *p){
58278 assert( p->pBt->pPager!=0 );
58279 return sqlite3PagerFilename(p->pBt->pPager, 1);
58280 }
58281
58282 /*
58283 ** Return the pathname of the journal file for this database. The return
58284 ** value of this routine is the same regardless of whether the journal file
@@ -58312,11 +58925,11 @@
58925 */
58926 if( rc==SQLITE_DONE ){
58927 rc = sqlite3BtreeUpdateMeta(p->pDest,1,p->iDestSchema+1);
58928 if( rc==SQLITE_OK ){
58929 if( p->pDestDb ){
58930 sqlite3ResetAllSchemasOfConnection(p->pDestDb);
58931 }
58932 if( destMode==PAGER_JOURNALMODE_WAL ){
58933 rc = sqlite3BtreeSetVersion(p->pDest, 2);
58934 }
58935 }
@@ -64497,12 +65110,13 @@
65110 /*
65111 ** Allocate a new Explain object
65112 */
65113 SQLITE_PRIVATE void sqlite3ExplainBegin(Vdbe *pVdbe){
65114 if( pVdbe ){
65115 Explain *p;
65116 sqlite3BeginBenignMalloc();
65117 p = sqlite3_malloc( sizeof(Explain) );
65118 if( p ){
65119 memset(p, 0, sizeof(*p));
65120 p->pVdbe = pVdbe;
65121 sqlite3_free(pVdbe->pExplain);
65122 pVdbe->pExplain = p;
@@ -67896,11 +68510,11 @@
68510 goto abort_due_to_error;
68511 }
68512 }
68513 if( u.ar.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
68514 sqlite3ExpirePreparedStatements(db);
68515 sqlite3ResetAllSchemasOfConnection(db);
68516 db->flags = (db->flags | SQLITE_InternChanges);
68517 }
68518 }
68519
68520 /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
@@ -68210,11 +68824,11 @@
68824 ** v-table would have to be ready for the sqlite3_vtab structure itself
68825 ** to be invalidated whenever sqlite3_step() is called from within
68826 ** a v-table method.
68827 */
68828 if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.aw.iMeta ){
68829 sqlite3ResetOneSchema(db, pOp->p1);
68830 }
68831
68832 p->expired = 1;
68833 rc = SQLITE_SCHEMA;
68834 }
@@ -70079,11 +70693,11 @@
70693 if( rc==SQLITE_OK ) rc = u.by.initData.rc;
70694 sqlite3DbFree(db, u.by.zSql);
70695 db->init.busy = 0;
70696 }
70697 }
70698 if( rc ) sqlite3ResetAllSchemasOfConnection(db);
70699 if( rc==SQLITE_NOMEM ){
70700 goto no_mem;
70701 }
70702 break;
70703 }
@@ -70746,11 +71360,11 @@
71360 u.ci.eOld = sqlite3PagerGetJournalMode(u.ci.pPager);
71361 if( u.ci.eNew==PAGER_JOURNALMODE_QUERY ) u.ci.eNew = u.ci.eOld;
71362 if( !sqlite3PagerOkToChangeJournalMode(u.ci.pPager) ) u.ci.eNew = u.ci.eOld;
71363
71364 #ifndef SQLITE_OMIT_WAL
71365 u.ci.zFilename = sqlite3PagerFilename(u.ci.pPager, 1);
71366
71367 /* Do not allow a transition to journal_mode=WAL for a database
71368 ** in temporary storage or if the VFS does not support shared memory
71369 */
71370 if( u.ci.eNew==PAGER_JOURNALMODE_WAL
@@ -71412,11 +72026,11 @@
72026 pc, p->zSql, p->zErrMsg);
72027 sqlite3VdbeHalt(p);
72028 if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1;
72029 rc = SQLITE_ERROR;
72030 if( resetSchemaOnFault>0 ){
72031 sqlite3ResetOneSchema(db, resetSchemaOnFault-1);
72032 }
72033
72034 /* This is the only way out of this procedure. We have to
72035 ** release the mutexes on btrees that were acquired at the
72036 ** top. */
@@ -73767,11 +74381,11 @@
74381 Expr *pOrig;
74382 assert( pExpr->pLeft==0 && pExpr->pRight==0 );
74383 assert( pExpr->x.pList==0 );
74384 assert( pExpr->x.pSelect==0 );
74385 pOrig = pEList->a[j].pExpr;
74386 if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){
74387 sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs);
74388 return WRC_Abort;
74389 }
74390 resolveAlias(pParse, pEList, j, pExpr, "");
74391 cnt = 1;
@@ -74012,11 +74626,11 @@
74626 pExpr->op = TK_NULL;
74627 return WRC_Prune;
74628 }
74629 }
74630 #endif
74631 if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){
74632 sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId);
74633 pNC->nErr++;
74634 is_agg = 0;
74635 }else if( no_such_func ){
74636 sqlite3ErrorMsg(pParse, "no such function: %.*s", nId, zId);
@@ -74026,15 +74640,15 @@
74640 nId, zId);
74641 pNC->nErr++;
74642 }
74643 if( is_agg ){
74644 pExpr->op = TK_AGG_FUNCTION;
74645 pNC->ncFlags |= NC_HasAgg;
74646 }
74647 if( is_agg ) pNC->ncFlags &= ~NC_AllowAgg;
74648 sqlite3WalkExprList(pWalker, pList);
74649 if( is_agg ) pNC->ncFlags |= NC_AllowAgg;
74650 /* FIX ME: Compute pExpr->affinity based on the expected return
74651 ** type of the function
74652 */
74653 return WRC_Prune;
74654 }
@@ -74045,11 +74659,11 @@
74659 case TK_IN: {
74660 testcase( pExpr->op==TK_IN );
74661 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
74662 int nRef = pNC->nRef;
74663 #ifndef SQLITE_OMIT_CHECK
74664 if( (pNC->ncFlags & NC_IsCheck)!=0 ){
74665 sqlite3ErrorMsg(pParse,"subqueries prohibited in CHECK constraints");
74666 }
74667 #endif
74668 sqlite3WalkSelect(pWalker, pExpr->x.pSelect);
74669 assert( pNC->nRef>=nRef );
@@ -74059,11 +74673,11 @@
74673 }
74674 break;
74675 }
74676 #ifndef SQLITE_OMIT_CHECK
74677 case TK_VARIABLE: {
74678 if( (pNC->ncFlags & NC_IsCheck)!=0 ){
74679 sqlite3ErrorMsg(pParse,"parameters prohibited in CHECK constraints");
74680 }
74681 break;
74682 }
74683 #endif
@@ -74141,11 +74755,11 @@
74755 */
74756 memset(&nc, 0, sizeof(nc));
74757 nc.pParse = pParse;
74758 nc.pSrcList = pSelect->pSrc;
74759 nc.pEList = pEList;
74760 nc.ncFlags = NC_AllowAgg;
74761 nc.nErr = 0;
74762 db = pParse->db;
74763 savedSuppErr = db->suppressErr;
74764 db->suppressErr = 1;
74765 rc = sqlite3ResolveExprNames(&nc, pE);
@@ -74443,11 +75057,11 @@
75057 }
75058
75059 /* Set up the local name-context to pass to sqlite3ResolveExprNames() to
75060 ** resolve the result-set expression list.
75061 */
75062 sNC.ncFlags = NC_AllowAgg;
75063 sNC.pSrcList = p->pSrc;
75064 sNC.pNext = pOuterNC;
75065
75066 /* Resolve names in the result set. */
75067 pEList = p->pEList;
@@ -74489,14 +75103,14 @@
75103 /* If there are no aggregate functions in the result-set, and no GROUP BY
75104 ** expression, do not allow aggregates in any of the other expressions.
75105 */
75106 assert( (p->selFlags & SF_Aggregate)==0 );
75107 pGroupBy = p->pGroupBy;
75108 if( pGroupBy || (sNC.ncFlags & NC_HasAgg)!=0 ){
75109 p->selFlags |= SF_Aggregate;
75110 }else{
75111 sNC.ncFlags &= ~NC_AllowAgg;
75112 }
75113
75114 /* If a HAVING clause is present, then there must be a GROUP BY clause.
75115 */
75116 if( p->pHaving && !pGroupBy ){
@@ -74521,11 +75135,11 @@
75135
75136 /* The ORDER BY and GROUP BY clauses may not refer to terms in
75137 ** outer queries
75138 */
75139 sNC.pNext = 0;
75140 sNC.ncFlags |= NC_AllowAgg;
75141
75142 /* Process the ORDER BY clause for singleton SELECT statements.
75143 ** The ORDER BY clause for compounds SELECT statements is handled
75144 ** below, after all of the result-sets for all of the elements of
75145 ** the compound have been resolved.
@@ -74609,11 +75223,11 @@
75223 **
75224 ** SELECT a+b AS x, c+d AS y FROM t1 ORDER BY a+b;
75225 **
75226 ** Function calls are checked to make sure that the function is
75227 ** defined and that the correct number of arguments are specified.
75228 ** If the function is an aggregate function, then the NC_HasAgg flag is
75229 ** set and the opcode is changed from TK_FUNCTION to TK_AGG_FUNCTION.
75230 ** If an expression contains aggregate functions then the EP_Agg
75231 ** property on the expression is set.
75232 **
75233 ** An error message is left in pParse if anything is amiss. The number
@@ -74621,11 +75235,11 @@
75235 */
75236 SQLITE_PRIVATE int sqlite3ResolveExprNames(
75237 NameContext *pNC, /* Namespace to resolve expressions in. */
75238 Expr *pExpr /* The expression to be analyzed. */
75239 ){
75240 u8 savedHasAgg;
75241 Walker w;
75242
75243 if( pExpr==0 ) return 0;
75244 #if SQLITE_MAX_EXPR_DEPTH>0
75245 {
@@ -74634,12 +75248,12 @@
75248 return 1;
75249 }
75250 pParse->nHeight += pExpr->nHeight;
75251 }
75252 #endif
75253 savedHasAgg = pNC->ncFlags & NC_HasAgg;
75254 pNC->ncFlags &= ~NC_HasAgg;
75255 w.xExprCallback = resolveExprStep;
75256 w.xSelectCallback = resolveSelectStep;
75257 w.pParse = pNC->pParse;
75258 w.u.pNC = pNC;
75259 sqlite3WalkExpr(&w, pExpr);
@@ -74647,14 +75261,14 @@
75261 pNC->pParse->nHeight -= pExpr->nHeight;
75262 #endif
75263 if( pNC->nErr>0 || w.pParse->nErr>0 ){
75264 ExprSetProperty(pExpr, EP_Error);
75265 }
75266 if( pNC->ncFlags & NC_HasAgg ){
75267 ExprSetProperty(pExpr, EP_Agg);
75268 }else if( savedHasAgg ){
75269 pNC->ncFlags |= NC_HasAgg;
75270 }
75271 return ExprHasProperty(pExpr, EP_Error);
75272 }
75273
75274
@@ -78464,11 +79078,11 @@
79078 if( pA->iTable!=pB->iTable || pA->iColumn!=pB->iColumn ) return 2;
79079 if( ExprHasProperty(pA, EP_IntValue) ){
79080 if( !ExprHasProperty(pB, EP_IntValue) || pA->u.iValue!=pB->u.iValue ){
79081 return 2;
79082 }
79083 }else if( pA->op!=TK_COLUMN && ALWAYS(pA->op!=TK_AGG_COLUMN) && pA->u.zToken){
79084 if( ExprHasProperty(pB, EP_IntValue) || NEVER(pB->u.zToken==0) ) return 2;
79085 if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){
79086 return 2;
79087 }
79088 }
@@ -78651,11 +79265,13 @@
79265 } /* end loop over pSrcList */
79266 }
79267 return WRC_Prune;
79268 }
79269 case TK_AGG_FUNCTION: {
79270 if( (pNC->ncFlags & NC_InAggFunc)==0
79271 && !sqlite3FunctionUsesOtherSrc(pExpr, pSrcList)
79272 ){
79273 /* Check to see if pExpr is a duplicate of another aggregate
79274 ** function that is already in the pAggInfo structure
79275 */
79276 struct AggInfo_func *pItem = pAggInfo->aFunc;
79277 for(i=0; i<pAggInfo->nFunc; i++, pItem++){
@@ -78688,12 +79304,12 @@
79304 */
79305 assert( !ExprHasAnyProperty(pExpr, EP_TokenOnly|EP_Reduced) );
79306 ExprSetIrreducible(pExpr);
79307 pExpr->iAgg = (i16)i;
79308 pExpr->pAggInfo = pAggInfo;
 
79309 }
79310 return WRC_Prune;
79311 }
79312 }
79313 return WRC_Continue;
79314 }
79315 static int analyzeAggregatesInSelect(Walker *pWalker, Select *pSelect){
@@ -80973,11 +81589,11 @@
81589 if( db->aDb[iDb].pBt ){
81590 sqlite3BtreeClose(db->aDb[iDb].pBt);
81591 db->aDb[iDb].pBt = 0;
81592 db->aDb[iDb].pSchema = 0;
81593 }
81594 sqlite3ResetAllSchemasOfConnection(db);
81595 db->nDb = iDb;
81596 if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){
81597 db->mallocFailed = 1;
81598 sqlite3DbFree(db, zErrDyn);
81599 zErrDyn = sqlite3MPrintf(db, "out of memory");
@@ -81045,11 +81661,11 @@
81661 }
81662
81663 sqlite3BtreeClose(pDb->pBt);
81664 pDb->pBt = 0;
81665 pDb->pSchema = 0;
81666 sqlite3ResetAllSchemasOfConnection(db);
81667 return;
81668
81669 detach_error:
81670 sqlite3_result_error(context, zErr, -1);
81671 }
@@ -81961,62 +82577,19 @@
82577 }
82578 db->flags |= SQLITE_InternChanges;
82579 }
82580
82581 /*
82582 ** Look through the list of open database files in db->aDb[] and if
82583 ** any have been closed, remove them from the list. Reallocate the
82584 ** db->aDb[] structure to a smaller size, if possible.
 
 
82585 **
82586 ** Entry 0 (the "main" database) and entry 1 (the "temp" database)
82587 ** are never candidates for being collapsed.
82588 */
82589 SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3 *db){
82590 int i, j;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82591 for(i=j=2; i<db->nDb; i++){
82592 struct Db *pDb = &db->aDb[i];
82593 if( pDb->pBt==0 ){
82594 sqlite3DbFree(db, pDb->zName);
82595 pDb->zName = 0;
@@ -82033,10 +82606,55 @@
82606 memcpy(db->aDbStatic, db->aDb, 2*sizeof(db->aDb[0]));
82607 sqlite3DbFree(db, db->aDb);
82608 db->aDb = db->aDbStatic;
82609 }
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 }
82656
82657 /*
82658 ** This routine is called when a commit occurs.
82659 */
82660 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3 *db){
@@ -82069,19 +82687,32 @@
82687 **
82688 ** This routine just deletes the data structure. It does not unlink
82689 ** the table data structure from the hash table. But it does destroy
82690 ** memory structures of the indices and foreign keys associated with
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.
82698 */
82699 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
82700 Index *pIndex, *pNext;
82701 TESTONLY( int nLookaside; ) /* Used to verify lookaside not used for schema */
82702
82703 assert( !pTable || pTable->nRef>0 );
82704
82705 /* Do not delete the table until the reference count reaches zero. */
82706 if( !pTable ) 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 );
82714
82715 /* Delete all indices associated with this table. */
82716 for(pIndex = pTable->pIndex; pIndex; pIndex=pNext){
82717 pNext = pIndex->pNext;
82718 assert( pIndex->pSchema==pTable->pSchema );
@@ -82110,10 +82741,13 @@
82741 #endif
82742 #ifndef SQLITE_OMIT_VIRTUALTABLE
82743 sqlite3VtabClear(db, pTable);
82744 #endif
82745 sqlite3DbFree(db, pTable);
82746
82747 /* Verify that no lookaside memory was used by schema tables */
82748 assert( nLookaside==0 || nLookaside==db->lookaside.nOut );
82749 }
82750
82751 /*
82752 ** Unlink the given table from the hash tables and the delete the
82753 ** table structure with all its indices and foreign keys.
@@ -83058,11 +83692,11 @@
83692 sSrc.a[0].zName = p->zName;
83693 sSrc.a[0].pTab = p;
83694 sSrc.a[0].iCursor = -1;
83695 sNC.pParse = pParse;
83696 sNC.pSrcList = &sSrc;
83697 sNC.ncFlags = NC_IsCheck;
83698 pList = p->pCheck;
83699 for(i=0; i<pList->nExpr; i++){
83700 if( sqlite3ResolveExprNames(&sNC, pList->a[i].pExpr) ){
83701 return;
83702 }
@@ -84314,11 +84948,11 @@
84948 zExtra += nColl;
84949 nExtra -= nColl;
84950 }else{
84951 zColl = pTab->aCol[j].zColl;
84952 if( !zColl ){
84953 zColl = "BINARY";
84954 }
84955 }
84956 if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
84957 goto exit_create_index;
84958 }
@@ -92589,11 +93223,11 @@
93223 "from within a transaction");
93224 return SQLITE_ERROR;
93225 }
93226 sqlite3BtreeClose(db->aDb[1].pBt);
93227 db->aDb[1].pBt = 0;
93228 sqlite3ResetAllSchemasOfConnection(db);
93229 }
93230 return SQLITE_OK;
93231 }
93232 #endif /* SQLITE_PAGER_PRAGMAS */
93233
@@ -93274,10 +93908,54 @@
93908 sqlite3_temp_directory = 0;
93909 }
93910 #endif /* SQLITE_OMIT_WSD */
93911 }
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
93957
93958 #if !defined(SQLITE_ENABLE_LOCKING_STYLE)
93959 # if defined(__APPLE__)
93960 # define SQLITE_ENABLE_LOCKING_STYLE 1
93961 # else
@@ -94307,11 +94985,10 @@
94985 u8 encoding;
94986 /* If opening the main database, set ENC(db). */
94987 encoding = (u8)meta[BTREE_TEXT_ENCODING-1] & 3;
94988 if( encoding==0 ) encoding = SQLITE_UTF8;
94989 ENC(db) = encoding;
 
94990 }else{
94991 /* If opening an attached database, the encoding much match ENC(db) */
94992 if( meta[BTREE_TEXT_ENCODING-1]!=ENC(db) ){
94993 sqlite3SetString(pzErrMsg, db, "attached databases must use the same"
94994 " text encoding as main database");
@@ -94387,11 +95064,11 @@
95064 }
95065 #endif
95066 }
95067 if( db->mallocFailed ){
95068 rc = SQLITE_NOMEM;
95069 sqlite3ResetAllSchemasOfConnection(db);
95070 }
95071 if( rc==SQLITE_OK || (db->flags&SQLITE_RecoveryMode)){
95072 /* Black magic: If the SQLITE_RecoveryMode flag is set, then consider
95073 ** the schema loaded, even if errors occurred. In this situation the
95074 ** current sqlite3_prepare() operation will fail, but the following one
@@ -94440,11 +95117,11 @@
95117 db->init.busy = 1;
95118 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
95119 if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue;
95120 rc = sqlite3InitOne(db, i, pzErrMsg);
95121 if( rc ){
95122 sqlite3ResetOneSchema(db, i);
95123 }
95124 }
95125
95126 /* Once all the other databases have been initialised, load the schema
95127 ** for the TEMP database. This is loaded last, as the TEMP database
@@ -94453,11 +95130,11 @@
95130 #ifndef SQLITE_OMIT_TEMPDB
95131 if( rc==SQLITE_OK && ALWAYS(db->nDb>1)
95132 && !DbHasProperty(db, 1, DB_SchemaLoaded) ){
95133 rc = sqlite3InitOne(db, 1, pzErrMsg);
95134 if( rc ){
95135 sqlite3ResetOneSchema(db, 1);
95136 }
95137 }
95138 #endif
95139
95140 db->init.busy = 0;
@@ -94521,11 +95198,11 @@
95198 ** value stored as part of the in-memory schema representation,
95199 ** set Parse.rc to SQLITE_SCHEMA. */
95200 sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&cookie);
95201 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
95202 if( cookie!=db->aDb[iDb].pSchema->schema_cookie ){
95203 sqlite3ResetOneSchema(db, iDb);
95204 pParse->rc = SQLITE_SCHEMA;
95205 }
95206
95207 /* Close the transaction, if one was opened. */
95208 if( openedTransaction ){
@@ -94751,10 +95428,11 @@
95428 sqlite3_finalize(*ppStmt);
95429 rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail);
95430 }
95431 sqlite3BtreeLeaveAll(db);
95432 sqlite3_mutex_leave(db->mutex);
95433 assert( rc==SQLITE_OK || *ppStmt==0 );
95434 return rc;
95435 }
95436
95437 /*
95438 ** Rerun the compilation of a statement after a schema change.
@@ -98058,10 +98736,11 @@
98736 pExpr = p->pEList->a[0].pExpr;
98737 assert( pTab && !pTab->pSelect && pExpr );
98738
98739 if( IsVirtual(pTab) ) return 0;
98740 if( pExpr->op!=TK_AGG_FUNCTION ) return 0;
98741 if( pAggInfo->nFunc==0 ) return 0;
98742 if( (pAggInfo->aFunc[0].pFunc->flags&SQLITE_FUNC_COUNT)==0 ) return 0;
98743 if( pExpr->flags&EP_Distinct ) return 0;
98744
98745 return pTab;
98746 }
@@ -99048,11 +99727,13 @@
99727 sqlite3ExprAnalyzeAggregates(&sNC, pHaving);
99728 }
99729 sAggInfo.nAccumulator = sAggInfo.nColumn;
99730 for(i=0; i<sAggInfo.nFunc; i++){
99731 assert( !ExprHasProperty(sAggInfo.aFunc[i].pExpr, EP_xIsSelect) );
99732 sNC.ncFlags |= NC_InAggFunc;
99733 sqlite3ExprAnalyzeAggList(&sNC, sAggInfo.aFunc[i].pExpr->x.pList);
99734 sNC.ncFlags &= ~NC_InAggFunc;
99735 }
99736 if( db->mallocFailed ) goto select_end;
99737
99738 /* Processing for aggregates with GROUP BY is very different and
99739 ** much more complex than aggregates without a GROUP BY.
@@ -101870,11 +102551,11 @@
102551 pDb->pSchema = 0;
102552 }
102553
102554 /* This both clears the schemas and reduces the size of the db->aDb[]
102555 ** array. */
102556 sqlite3ResetAllSchemasOfConnection(db);
102557
102558 return rc;
102559 }
102560
102561 #endif /* SQLITE_OMIT_VACUUM && SQLITE_OMIT_ATTACH */
@@ -101902,12 +102583,12 @@
102583 ** this struct allocated on the stack. It is used by the implementation of
102584 ** the sqlite3_declare_vtab() and sqlite3_vtab_config() APIs, both of which
102585 ** are invoked only from within xCreate and xConnect methods.
102586 */
102587 struct VtabCtx {
102588 VTable *pVTable; /* The virtual table being constructed */
102589 Table *pTab; /* The Table object to which the virtual table belongs */
102590 };
102591
102592 /*
102593 ** The actual function that does the work of creating a new module.
102594 ** This function implements the sqlite3_create_module() and
@@ -101918,37 +102599,39 @@
102599 const char *zName, /* Name assigned to this module */
102600 const sqlite3_module *pModule, /* The definition of the module */
102601 void *pAux, /* Context pointer for xCreate/xConnect */
102602 void (*xDestroy)(void *) /* Module destructor function */
102603 ){
102604 int rc = SQLITE_OK;
102605 int nName;
102606
102607 sqlite3_mutex_enter(db->mutex);
102608 nName = sqlite3Strlen30(zName);
102609 if( sqlite3HashFind(&db->aModule, zName, nName) ){
102610 rc = SQLITE_MISUSE_BKPT;
102611 }else{
102612 Module *pMod;
102613 pMod = (Module *)sqlite3DbMallocRaw(db, sizeof(Module) + nName + 1);
102614 if( pMod ){
102615 Module *pDel;
102616 char *zCopy = (char *)(&pMod[1]);
102617 memcpy(zCopy, zName, nName+1);
102618 pMod->zName = zCopy;
102619 pMod->pModule = pModule;
102620 pMod->pAux = pAux;
102621 pMod->xDestroy = xDestroy;
102622 pDel = (Module *)sqlite3HashInsert(&db->aModule,zCopy,nName,(void*)pMod);
102623 assert( pDel==0 || pDel==pMod );
102624 if( pDel ){
102625 db->mallocFailed = 1;
102626 sqlite3DbFree(db, pDel);
102627 }
102628 }
102629 }
102630 rc = sqlite3ApiExit(db, rc);
102631 if( rc!=SQLITE_OK && xDestroy ) xDestroy(pAux);
102632
102633 sqlite3_mutex_leave(db->mutex);
102634 return rc;
102635 }
102636
102637
@@ -102059,10 +102742,35 @@
102742 }
102743
102744 assert( !db || pRet );
102745 return pRet;
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 }
102772
102773
102774 /*
102775 ** Disconnect all the virtual table objects in the sqlite3.pDisconnect list.
102776 **
@@ -112949,10 +113657,19 @@
113657 **
113658 ** See also the "PRAGMA temp_store_directory" SQL command.
113659 */
113660 SQLITE_API char *sqlite3_temp_directory = 0;
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
113671 /*
113672 ** Initialize SQLite.
113673 **
113674 ** This routine must be called to initialize the memory allocation,
113675 ** VFS, and mutex subsystems prior to doing any serious work with
@@ -113147,10 +113864,22 @@
113864 sqlite3GlobalConfig.isPCacheInit = 0;
113865 }
113866 if( sqlite3GlobalConfig.isMallocInit ){
113867 sqlite3MallocEnd();
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
113881 }
113882 if( sqlite3GlobalConfig.isMutexInit ){
113883 sqlite3MutexEnd();
113884 sqlite3GlobalConfig.isMutexInit = 0;
113885 }
@@ -113594,10 +114323,34 @@
114323 pDestructor->xDestroy(pDestructor->pUserData);
114324 sqlite3DbFree(db, pDestructor);
114325 }
114326 }
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 }
114352
114353 /*
114354 ** Close an existing SQLite database
114355 */
114356 SQLITE_API int sqlite3_close(sqlite3 *db){
@@ -113610,14 +114363,14 @@
114363 if( !sqlite3SafetyCheckSickOrOk(db) ){
114364 return SQLITE_MISUSE_BKPT;
114365 }
114366 sqlite3_mutex_enter(db->mutex);
114367
114368 /* Force xDisconnect calls on all virtual tables */
114369 disconnectAllVtab(db);
114370
114371 /* If a transaction is open, the disconnectAllVtab() call above
114372 ** will not have called the xDisconnect() method on any virtual
114373 ** tables in the db->aVTrans[] array. The following sqlite3VtabRollback()
114374 ** call will do so. We need to do this before the check for active
114375 ** SQL statements below, as the v-table implementation may be storing
114376 ** some prepared statements internally.
@@ -113644,10 +114397,11 @@
114397 }
114398
114399 /* Free any outstanding Savepoint structures. */
114400 sqlite3CloseSavepoints(db);
114401
114402 /* Close all database connections */
114403 for(j=0; j<db->nDb; j++){
114404 struct Db *pDb = &db->aDb[j];
114405 if( pDb->pBt ){
114406 sqlite3BtreeClose(pDb->pBt);
114407 pDb->pBt = 0;
@@ -113654,19 +114408,26 @@
114408 if( j!=1 ){
114409 pDb->pSchema = 0;
114410 }
114411 }
114412 }
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 );
114423
114424 /* Tell the code in notify.c that the connection no longer holds any
114425 ** locks and does not require any further unlock-notify callbacks.
114426 */
114427 sqlite3ConnectionClosed(db);
114428
 
 
114429 for(j=0; j<ArraySize(db->aFunc.a); j++){
114430 FuncDef *pNext, *pHash, *p;
114431 for(p=db->aFunc.a[j]; p; p=pHash){
114432 pHash = p->pHash;
114433 while( p ){
@@ -113749,11 +114510,11 @@
114510 sqlite3VtabRollback(db);
114511 sqlite3EndBenignMalloc();
114512
114513 if( db->flags&SQLITE_InternChanges ){
114514 sqlite3ExpirePreparedStatements(db);
114515 sqlite3ResetAllSchemasOfConnection(db);
114516 }
114517
114518 /* Any deferred constraint violations have now been resolved. */
114519 db->nDeferredCons = 0;
114520
@@ -114887,14 +115648,18 @@
115648 if( nOpt==4 && memcmp("mode", zOpt, 4)==0 ){
115649 static struct OpenMode aOpenMode[] = {
115650 { "ro", SQLITE_OPEN_READONLY },
115651 { "rw", SQLITE_OPEN_READWRITE },
115652 { "rwc", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE },
115653 { "memory",
115654 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE
115655 | SQLITE_OPEN_MEMORY },
115656 { 0, 0 }
115657 };
115658
115659 mask = SQLITE_OPEN_READONLY | SQLITE_OPEN_READWRITE
115660 | SQLITE_OPEN_CREATE | SQLITE_OPEN_MEMORY;
115661 aMode = aOpenMode;
115662 limit = mask & flags;
115663 zModeType = "access";
115664 }
115665
@@ -114911,11 +115676,11 @@
115676 if( mode==0 ){
115677 *pzErrMsg = sqlite3_mprintf("no such %s mode: %s", zModeType, zVal);
115678 rc = SQLITE_ERROR;
115679 goto parse_uri_out;
115680 }
115681 if( (mode & ~SQLITE_OPEN_MEMORY)>limit ){
115682 *pzErrMsg = sqlite3_mprintf("%s mode not allowed: %s",
115683 zModeType, zVal);
115684 rc = SQLITE_PERM;
115685 goto parse_uri_out;
115686 }
@@ -114930,10 +115695,11 @@
115695 zFile = sqlite3_malloc(nUri+2);
115696 if( !zFile ) return SQLITE_NOMEM;
115697 memcpy(zFile, zUri, nUri);
115698 zFile[nUri] = '\0';
115699 zFile[nUri+1] = '\0';
115700 flags &= ~SQLITE_OPEN_URI;
115701 }
115702
115703 *ppVfs = sqlite3_vfs_find(zVfs);
115704 if( *ppVfs==0 ){
115705 *pzErrMsg = sqlite3_mprintf("no such vfs: %s", zVfs);
@@ -117374,10 +118140,17 @@
118140 SQLITE_PRIVATE int sqlite3Fts3EvalPhrasePoslist(Fts3Cursor *, Fts3Expr *, int iCol, char **);
118141 SQLITE_PRIVATE int sqlite3Fts3MsrOvfl(Fts3Cursor *, Fts3MultiSegReader *, int *);
118142 SQLITE_PRIVATE int sqlite3Fts3MsrIncrRestart(Fts3MultiSegReader *pCsr);
118143
118144 SQLITE_PRIVATE int sqlite3Fts3DeferredTokenList(Fts3DeferredToken *, char **, int *);
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
118152
118153 #endif /* !SQLITE_CORE || SQLITE_ENABLE_FTS3 */
118154 #endif /* _FTSINT_H */
118155
118156 /************** End of fts3Int.h *********************************************/
@@ -120643,10 +121416,13 @@
121416 ** to by the argument to point to the "simple" tokenizer implementation.
121417 ** And so on.
121418 */
121419 SQLITE_PRIVATE void sqlite3Fts3SimpleTokenizerModule(sqlite3_tokenizer_module const**ppModule);
121420 SQLITE_PRIVATE void sqlite3Fts3PorterTokenizerModule(sqlite3_tokenizer_module const**ppModule);
121421 #ifdef SQLITE_ENABLE_FTS4_UNICODE61
121422 SQLITE_PRIVATE void sqlite3Fts3UnicodeTokenizer(sqlite3_tokenizer_module const**ppModule);
121423 #endif
121424 #ifdef SQLITE_ENABLE_ICU
121425 SQLITE_PRIVATE void sqlite3Fts3IcuTokenizerModule(sqlite3_tokenizer_module const**ppModule);
121426 #endif
121427
121428 /*
@@ -120658,15 +121434,22 @@
121434 SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){
121435 int rc = SQLITE_OK;
121436 Fts3Hash *pHash = 0;
121437 const sqlite3_tokenizer_module *pSimple = 0;
121438 const sqlite3_tokenizer_module *pPorter = 0;
121439 #ifdef SQLITE_ENABLE_FTS4_UNICODE61
121440 const sqlite3_tokenizer_module *pUnicode = 0;
121441 #endif
121442
121443 #ifdef SQLITE_ENABLE_ICU
121444 const sqlite3_tokenizer_module *pIcu = 0;
121445 sqlite3Fts3IcuTokenizerModule(&pIcu);
121446 #endif
121447
121448 #ifdef SQLITE_ENABLE_FTS4_UNICODE61
121449 sqlite3Fts3UnicodeTokenizer(&pUnicode);
121450 #endif
121451
121452 #ifdef SQLITE_TEST
121453 rc = sqlite3Fts3InitTerm(db);
121454 if( rc!=SQLITE_OK ) return rc;
121455 #endif
@@ -120687,10 +121470,14 @@
121470
121471 /* Load the built-in tokenizers into the hash table */
121472 if( rc==SQLITE_OK ){
121473 if( sqlite3Fts3HashInsert(pHash, "simple", 7, (void *)pSimple)
121474 || sqlite3Fts3HashInsert(pHash, "porter", 7, (void *)pPorter)
121475
121476 #ifdef SQLITE_ENABLE_FTS4_UNICODE61
121477 || sqlite3Fts3HashInsert(pHash, "unicode61", 10, (void *)pUnicode)
121478 #endif
121479 #ifdef SQLITE_ENABLE_ICU
121480 || (pIcu && sqlite3Fts3HashInsert(pHash, "icu", 4, (void *)pIcu))
121481 #endif
121482 ){
121483 rc = SQLITE_NOMEM;
@@ -128839,11 +129626,16 @@
129626 sqlite3_column_blob(pStmt, 0),
129627 sqlite3_column_bytes(pStmt, 0));
129628 }else{
129629 memset(a, 0, sizeof(u32)*(nStat) );
129630 }
129631 rc = sqlite3_reset(pStmt);
129632 if( rc!=SQLITE_OK ){
129633 sqlite3_free(a);
129634 *pRC = rc;
129635 return;
129636 }
129637 if( nChng<0 && a[0]<(u32)(-nChng) ){
129638 a[0] = 0;
129639 }else{
129640 a[0] += nChng;
129641 }
@@ -132562,10 +133354,655 @@
133354 }
133355
133356 #endif
133357
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 **ppModule){
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 ***************************************/
134004 /************** Begin file rtree.c *******************************************/
134005 /*
134006 ** 2001 September 15
134007 **
134008 ** The author disclaims copyright to this source code. In place of
@@ -135301,10 +136738,40 @@
136738 nodeRelease(pRtree, pRoot);
136739 }
136740
136741 return rc;
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
136773
136774 /*
136775 ** The xUpdate method for rtree module virtual tables.
136776 */
136777 static int rtreeUpdate(
@@ -135338,12 +136805,12 @@
136805 /* Populate the cell.aCoord[] array. The first coordinate is azData[3]. */
136806 assert( nData==(pRtree->nDim*2 + 3) );
136807 #ifndef SQLITE_RTREE_INT_ONLY
136808 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
136809 for(ii=0; ii<(pRtree->nDim*2); ii+=2){
136810 cell.aCoord[ii].f = rtreeValueDown(azData[ii+3]);
136811 cell.aCoord[ii+1].f = rtreeValueUp(azData[ii+4]);
136812 if( cell.aCoord[ii].f>cell.aCoord[ii+1].f ){
136813 rc = SQLITE_CONSTRAINT;
136814 goto constraint;
136815 }
136816 }
136817
+52 -14
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105105
**
106106
** See also: [sqlite3_libversion()],
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110
-#define SQLITE_VERSION "3.7.12"
111
-#define SQLITE_VERSION_NUMBER 3007012
112
-#define SQLITE_SOURCE_ID "2012-05-12 18:29:53 e536ac041815b118c461ceee798f9b7283269f58"
110
+#define SQLITE_VERSION "3.7.13"
111
+#define SQLITE_VERSION_NUMBER 3007013
112
+#define SQLITE_SOURCE_ID "2012-06-07 07:24:04 506008f000ba4af0b35da023b8c52f7a3f5033bd"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -476,10 +476,11 @@
476476
#define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
477477
#define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
478478
#define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */
479479
#define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */
480480
#define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */
481
+#define SQLITE_OPEN_MEMORY 0x00000080 /* Ok for sqlite3_open_v2() */
481482
#define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */
482483
#define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */
483484
#define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */
484485
#define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */
485486
#define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */
@@ -770,11 +771,11 @@
770771
** into the array entry, allowing the current retry settings to be
771772
** interrogated. The zDbName parameter is ignored.
772773
**
773774
** <li>[[SQLITE_FCNTL_PERSIST_WAL]]
774775
** ^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
776777
** write ahead log and shared memory files used for transaction control
777778
** are automatically deleted when the latest connection to the database
778779
** closes. Setting persistent WAL mode causes those files to persist after
779780
** close. Persisting the files is useful when other processes that do not
780781
** have write permission on the directory containing the database file want
@@ -2167,16 +2168,16 @@
21672168
** In SQLite version 3.5.0 and 3.5.1, it was possible to define
21682169
** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
21692170
** implementation of these routines to be omitted. That capability
21702171
** is no longer provided. Only built-in memory allocators can be used.
21712172
**
2172
-** The Windows OS interface layer calls
2173
+** Prior to SQLite version 3.7.10, the Windows OS interface layer called
21732174
** the system malloc() and free() directly when converting
21742175
** filenames between the UTF-8 encoding used by SQLite
21752176
** and whatever filename encoding is used by the particular Windows
2176
-** installation. Memory allocation errors are detected, but
2177
-** they are reported back as [SQLITE_CANTOPEN] or
2177
+** installation. Memory allocation errors were detected, but
2178
+** they were reported back as [SQLITE_CANTOPEN] or
21782179
** [SQLITE_IOERR] rather than [SQLITE_NOMEM].
21792180
**
21802181
** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
21812182
** must be either NULL or else pointers obtained from a prior
21822183
** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
@@ -2573,22 +2574,24 @@
25732574
** an empty string the default VFS object is used. ^Specifying an unknown
25742575
** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is
25752576
** present, then the VFS specified by the option takes precedence over
25762577
** the value passed as the fourth parameter to sqlite3_open_v2().
25772578
**
2578
-** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw" or
2579
-** "rwc". Attempting to set it to any other value is an error)^.
2579
+** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw",
2580
+** "rwc", or "memory". Attempting to set it to any other value is
2581
+** an error)^.
25802582
** ^If "ro" is specified, then the database is opened for read-only
25812583
** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the
25822584
** third argument to sqlite3_prepare_v2(). ^If the mode option is set to
25832585
** "rw", then the database is opened for read-write (but not create)
25842586
** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had
25852587
** been set. ^Value "rwc" is equivalent to setting both
2586
-** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If sqlite3_open_v2() is
2587
-** used, it is an error to specify a value for the mode parameter that is
2588
-** less restrictive than that specified by the flags passed as the third
2589
-** parameter.
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
2590
+** or writes from disk is used. ^It is an error to specify a value for
2591
+** the mode parameter that is less restrictive than that specified by
2592
+** the flags passed in the third parameter to sqlite3_open_v2().
25902593
**
25912594
** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or
25922595
** "private". ^Setting it to "shared" is equivalent to setting the
25932596
** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
25942597
** sqlite3_open_v2(). ^Setting the cache parameter to "private" is
@@ -4447,10 +4450,46 @@
44474450
** made NULL or made to point to memory obtained from [sqlite3_malloc]
44484451
** or else the use of the [temp_store_directory pragma] should be avoided.
44494452
*/
44504453
SQLITE_API SQLITE_EXTERN char *sqlite3_temp_directory;
44514454
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
+
44524491
/*
44534492
** CAPI3REF: Test For Auto-Commit Mode
44544493
** KEYWORDS: {autocommit mode}
44554494
**
44564495
** ^The sqlite3_get_autocommit() interface returns non-zero or
@@ -4625,11 +4664,10 @@
46254664
void*
46264665
);
46274666
46284667
/*
46294668
** CAPI3REF: Enable Or Disable Shared Pager Cache
4630
-** KEYWORDS: {shared cache}
46314669
**
46324670
** ^(This routine enables or disables the sharing of the database cache
46334671
** and schema data structures between [database connection | connections]
46344672
** to the same database. Sharing is enabled if the argument is true
46354673
** and disabled if the argument is false.)^
46364674
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.7.12"
111 #define SQLITE_VERSION_NUMBER 3007012
112 #define SQLITE_SOURCE_ID "2012-05-12 18:29:53 e536ac041815b118c461ceee798f9b7283269f58"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -476,10 +476,11 @@
476 #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
477 #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
478 #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */
479 #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */
480 #define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */
 
481 #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */
482 #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */
483 #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */
484 #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */
485 #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */
@@ -770,11 +771,11 @@
770 ** into the array entry, allowing the current retry settings to be
771 ** interrogated. The zDbName parameter is ignored.
772 **
773 ** <li>[[SQLITE_FCNTL_PERSIST_WAL]]
774 ** ^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 ** write ahead log and shared memory files used for transaction control
777 ** are automatically deleted when the latest connection to the database
778 ** 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 ** have write permission on the directory containing the database file want
@@ -2167,16 +2168,16 @@
2167 ** 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 ** implementation of these routines to be omitted. That capability
2170 ** is no longer provided. Only built-in memory allocators can be used.
2171 **
2172 ** The Windows OS interface layer calls
2173 ** the system malloc() and free() directly when converting
2174 ** filenames between the UTF-8 encoding used by SQLite
2175 ** and whatever filename encoding is used by the particular Windows
2176 ** installation. Memory allocation errors are detected, but
2177 ** they are reported back as [SQLITE_CANTOPEN] or
2178 ** [SQLITE_IOERR] rather than [SQLITE_NOMEM].
2179 **
2180 ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
2181 ** must be either NULL or else pointers obtained from a prior
2182 ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
@@ -2573,22 +2574,24 @@
2573 ** 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 ** present, then the VFS specified by the option takes precedence over
2576 ** the value passed as the fourth parameter to sqlite3_open_v2().
2577 **
2578 ** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw" or
2579 ** "rwc". Attempting to set it to any other value is an error)^.
 
2580 ** ^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
2582 ** 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)
2584 ** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had
2585 ** been set. ^Value "rwc" is equivalent to setting both
2586 ** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If sqlite3_open_v2() is
2587 ** used, it is an error to specify a value for the mode parameter that is
2588 ** less restrictive than that specified by the flags passed as the third
2589 ** parameter.
 
2590 **
2591 ** <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
2593 ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
2594 ** sqlite3_open_v2(). ^Setting the cache parameter to "private" is
@@ -4447,10 +4450,46 @@
4447 ** 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.
4449 */
4450 SQLITE_API SQLITE_EXTERN char *sqlite3_temp_directory;
4451
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4452 /*
4453 ** CAPI3REF: Test For Auto-Commit Mode
4454 ** KEYWORDS: {autocommit mode}
4455 **
4456 ** ^The sqlite3_get_autocommit() interface returns non-zero or
@@ -4625,11 +4664,10 @@
4625 void*
4626 );
4627
4628 /*
4629 ** CAPI3REF: Enable Or Disable Shared Pager Cache
4630 ** KEYWORDS: {shared cache}
4631 **
4632 ** ^(This routine enables or disables the sharing of the database cache
4633 ** and schema data structures between [database connection | connections]
4634 ** to the same database. Sharing is enabled if the argument is true
4635 ** and disabled if the argument is false.)^
4636
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.7.13"
111 #define SQLITE_VERSION_NUMBER 3007013
112 #define SQLITE_SOURCE_ID "2012-06-07 07:24:04 506008f000ba4af0b35da023b8c52f7a3f5033bd"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -476,10 +476,11 @@
476 #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
477 #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
478 #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */
479 #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */
480 #define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */
481 #define SQLITE_OPEN_MEMORY 0x00000080 /* Ok for sqlite3_open_v2() */
482 #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */
483 #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */
484 #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */
485 #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */
486 #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */
@@ -770,11 +771,11 @@
771 ** into the array entry, allowing the current retry settings to be
772 ** interrogated. The zDbName parameter is ignored.
773 **
774 ** <li>[[SQLITE_FCNTL_PERSIST_WAL]]
775 ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the
776 ** persistent [WAL | Write Ahead Log] setting. By default, the auxiliary
777 ** write ahead log and shared memory files used for transaction control
778 ** are automatically deleted when the latest connection to the database
779 ** closes. Setting persistent WAL mode causes those files to persist after
780 ** close. Persisting the files is useful when other processes that do not
781 ** have write permission on the directory containing the database file want
@@ -2167,16 +2168,16 @@
2168 ** In SQLite version 3.5.0 and 3.5.1, it was possible to define
2169 ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
2170 ** implementation of these routines to be omitted. That capability
2171 ** is no longer provided. Only built-in memory allocators can be used.
2172 **
2173 ** Prior to SQLite version 3.7.10, the Windows OS interface layer called
2174 ** the system malloc() and free() directly when converting
2175 ** filenames between the UTF-8 encoding used by SQLite
2176 ** and whatever filename encoding is used by the particular Windows
2177 ** installation. Memory allocation errors were detected, but
2178 ** they were reported back as [SQLITE_CANTOPEN] or
2179 ** [SQLITE_IOERR] rather than [SQLITE_NOMEM].
2180 **
2181 ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
2182 ** must be either NULL or else pointers obtained from a prior
2183 ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
@@ -2573,22 +2574,24 @@
2574 ** an empty string the default VFS object is used. ^Specifying an unknown
2575 ** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is
2576 ** present, then the VFS specified by the option takes precedence over
2577 ** the value passed as the fourth parameter to sqlite3_open_v2().
2578 **
2579 ** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw",
2580 ** "rwc", or "memory". Attempting to set it to any other value is
2581 ** an error)^.
2582 ** ^If "ro" is specified, then the database is opened for read-only
2583 ** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the
2584 ** third argument to sqlite3_prepare_v2(). ^If the mode option is set to
2585 ** "rw", then the database is opened for read-write (but not create)
2586 ** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had
2587 ** been set. ^Value "rwc" is equivalent to setting both
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
2590 ** or writes from disk is used. ^It is an error to specify a value for
2591 ** the mode parameter that is less restrictive than that specified by
2592 ** the flags passed in the third parameter to sqlite3_open_v2().
2593 **
2594 ** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or
2595 ** "private". ^Setting it to "shared" is equivalent to setting the
2596 ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
2597 ** sqlite3_open_v2(). ^Setting the cache parameter to "private" is
@@ -4447,10 +4450,46 @@
4450 ** made NULL or made to point to memory obtained from [sqlite3_malloc]
4451 ** or else the use of the [temp_store_directory pragma] should be avoided.
4452 */
4453 SQLITE_API SQLITE_EXTERN char *sqlite3_temp_directory;
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
4491 /*
4492 ** CAPI3REF: Test For Auto-Commit Mode
4493 ** KEYWORDS: {autocommit mode}
4494 **
4495 ** ^The sqlite3_get_autocommit() interface returns non-zero or
@@ -4625,11 +4664,10 @@
4664 void*
4665 );
4666
4667 /*
4668 ** CAPI3REF: Enable Or Disable Shared Pager Cache
 
4669 **
4670 ** ^(This routine enables or disables the sharing of the database cache
4671 ** and schema data structures between [database connection | connections]
4672 ** to the same database. Sharing is enabled if the argument is true
4673 ** and disabled if the argument is false.)^
4674

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button