Fossil SCM

Update the built-in SQLite to the latest version on the fullscan-covering-index branch. This is for the purpose of testing SQLite changes.

drh 2012-09-18 12:52 trunk
Commit ac2d29326be52d3298e1986d554a94d3b7366f8a
2 files changed +426 -261 +24 -4
+426 -261
--- 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.14. By combining all the individual C code files into this
3
+** version 3.7.15. 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.
@@ -671,13 +671,13 @@
671671
**
672672
** See also: [sqlite3_libversion()],
673673
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
674674
** [sqlite_version()] and [sqlite_source_id()].
675675
*/
676
-#define SQLITE_VERSION "3.7.14"
677
-#define SQLITE_VERSION_NUMBER 3007014
678
-#define SQLITE_SOURCE_ID "2012-09-03 15:42:36 c0d89d4a9752922f9e367362366efde4f1b06f2a"
676
+#define SQLITE_VERSION "3.7.15"
677
+#define SQLITE_VERSION_NUMBER 3007015
678
+#define SQLITE_SOURCE_ID "2012-09-17 21:24:01 698b2a28004a9a2f0eabaadf36d833da4400b2bf"
679679
680680
/*
681681
** CAPI3REF: Run-Time Library Version Numbers
682682
** KEYWORDS: sqlite3_version, sqlite3_sourceid
683683
**
@@ -1042,10 +1042,11 @@
10421042
#define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
10431043
#define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
10441044
#define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
10451045
#define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
10461046
#define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
1047
+#define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
10471048
#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
10481049
#define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
10491050
#define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
10501051
#define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
10511052
@@ -2130,10 +2131,22 @@
21302131
** connection is opened. If it is globally disabled, filenames are
21312132
** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
21322133
** database connection is opened. By default, URI handling is globally
21332134
** disabled. The default value may be changed by compiling with the
21342135
** [SQLITE_USE_URI] symbol defined.
2136
+**
2137
+** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
2138
+** <dd> This option taks a single integer argument which is interpreted as
2139
+** a boolean in order to enable or disable the use of covering indices for
2140
+** full table scans in the query optimizer. The default setting is determined
2141
+** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
2142
+** if that compile-time option is omitted.
2143
+** The ability to disable the use of covering indices for full table scans
2144
+** is because some incorrectly coded legacy applications might malfunction
2145
+** malfunction when the optimization is enabled. Providing the ability to
2146
+** disable the optimization allows the older, buggy application code to work
2147
+** without change even with newer versions of SQLite.
21352148
**
21362149
** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]]
21372150
** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE
21382151
** <dd> These options are obsolete and should not be used by new code.
21392152
** They are retained for backwards compatibility but are now no-ops.
@@ -2156,10 +2169,11 @@
21562169
#define SQLITE_CONFIG_GETPCACHE 15 /* no-op */
21572170
#define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
21582171
#define SQLITE_CONFIG_URI 17 /* int */
21592172
#define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */
21602173
#define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
2174
+#define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
21612175
21622176
/*
21632177
** CAPI3REF: Database Connection Configuration Options
21642178
**
21652179
** These constants are the available integer configuration options that
@@ -3164,11 +3178,11 @@
31643178
** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw",
31653179
** "rwc", or "memory". Attempting to set it to any other value is
31663180
** an error)^.
31673181
** ^If "ro" is specified, then the database is opened for read-only
31683182
** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the
3169
-** third argument to sqlite3_prepare_v2(). ^If the mode option is set to
3183
+** third argument to sqlite3_open_v2(). ^If the mode option is set to
31703184
** "rw", then the database is opened for read-write (but not create)
31713185
** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had
31723186
** been set. ^Value "rwc" is equivalent to setting both
31733187
** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If the mode option is
31743188
** set to "memory" then a pure [in-memory database] that never reads
@@ -3315,10 +3329,15 @@
33153329
** text that describes the error, as either UTF-8 or UTF-16 respectively.
33163330
** ^(Memory to hold the error message string is managed internally.
33173331
** The application does not need to worry about freeing the result.
33183332
** However, the error string might be overwritten or deallocated by
33193333
** subsequent calls to other SQLite interface functions.)^
3334
+**
3335
+** ^The sqlite3_errstr() interface returns the English-language text
3336
+** that describes the [result code], as UTF-8.
3337
+** ^(Memory to hold the error message string is managed internally
3338
+** and must not be freed by the application)^.
33203339
**
33213340
** When the serialized [threading mode] is in use, it might be the
33223341
** case that a second error occurs on a separate thread in between
33233342
** the time of the first error and the call to these interfaces.
33243343
** When that happens, the second error will be reported since these
@@ -3334,10 +3353,11 @@
33343353
*/
33353354
SQLITE_API int sqlite3_errcode(sqlite3 *db);
33363355
SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
33373356
SQLITE_API const char *sqlite3_errmsg(sqlite3*);
33383357
SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
3358
+SQLITE_API const char *sqlite3_errstr(int);
33393359
33403360
/*
33413361
** CAPI3REF: SQL Statement Object
33423362
** KEYWORDS: {prepared statement} {prepared statements}
33433363
**
@@ -9959,20 +9979,18 @@
99599979
/*
99609980
** Bits of the sqlite3.flags field that are used by the
99619981
** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface.
99629982
** These must be the low-order bits of the flags field.
99639983
*/
9964
-#define SQLITE_QueryFlattener 0x01 /* Disable query flattening */
9965
-#define SQLITE_ColumnCache 0x02 /* Disable the column cache */
9966
-#define SQLITE_IndexSort 0x04 /* Disable indexes for sorting */
9967
-#define SQLITE_IndexSearch 0x08 /* Disable indexes for searching */
9968
-#define SQLITE_IndexCover 0x10 /* Disable index covering table */
9969
-#define SQLITE_GroupByOrder 0x20 /* Disable GROUPBY cover of ORDERBY */
9970
-#define SQLITE_FactorOutConst 0x40 /* Disable factoring out constants */
9971
-#define SQLITE_IdxRealAsInt 0x80 /* Store REAL as INT in indices */
9972
-#define SQLITE_DistinctOpt 0x80 /* DISTINCT using indexes */
9973
-#define SQLITE_OptMask 0xff /* Mask of all disablable opts */
9984
+#define SQLITE_QueryFlattener 0x01 /* Disable query flattening */
9985
+#define SQLITE_ColumnCache 0x02 /* Disable the column cache */
9986
+#define SQLITE_GroupByOrder 0x04 /* Disable GROUPBY cover of ORDERBY */
9987
+#define SQLITE_FactorOutConst 0x08 /* Disable factoring out constants */
9988
+#define SQLITE_IdxRealAsInt 0x10 /* Store REAL as INT in indices */
9989
+#define SQLITE_DistinctOpt 0x20 /* DISTINCT using indexes */
9990
+#define SQLITE_CoverIdxScan 0x40 /* Disable covering index scans */
9991
+#define SQLITE_OptMask 0xff /* Mask of all disablable opts */
99749992
99759993
/*
99769994
** Possible values for the sqlite.magic field.
99779995
** The numbers are obtained at random and have no special meaning, other
99789996
** than being distinct from one another.
@@ -10119,18 +10137,20 @@
1011910137
char *zName; /* Name of this column */
1012010138
Expr *pDflt; /* Default value of this column */
1012110139
char *zDflt; /* Original text of the default value */
1012210140
char *zType; /* Data type for this column */
1012310141
char *zColl; /* Collating sequence. If NULL, use the default */
10124
- u8 notNull; /* True if there is a NOT NULL constraint */
10125
- u8 isPrimKey; /* True if this column is part of the PRIMARY KEY */
10142
+ u8 notNull; /* An OE_ code for handling a NOT NULL constraint */
1012610143
char affinity; /* One of the SQLITE_AFF_... values */
10127
-#ifndef SQLITE_OMIT_VIRTUALTABLE
10128
- u8 isHidden; /* True if this column is 'hidden' */
10129
-#endif
10144
+ u16 colFlags; /* Boolean properties. See COLFLAG_ defines below */
1013010145
};
1013110146
10147
+/* Allowed values for Column.colFlags:
10148
+*/
10149
+#define COLFLAG_PRIMKEY 0x0001 /* Column is part of the primary key */
10150
+#define COLFLAG_HIDDEN 0x0002 /* A hidden column in a virtual table */
10151
+
1013210152
/*
1013310153
** A "Collating Sequence" is defined by an instance of the following
1013410154
** structure. Conceptually, a collating sequence consists of a name and
1013510155
** a comparison routine that defines the order of that sequence.
1013610156
**
@@ -10282,32 +10302,32 @@
1028210302
** sub-query that appears instead of a real table name in the FROM clause
1028310303
** of a SELECT statement.
1028410304
*/
1028510305
struct Table {
1028610306
char *zName; /* Name of the table or view */
10287
- int iPKey; /* If not negative, use aCol[iPKey] as the primary key */
10288
- int nCol; /* Number of columns in this table */
1028910307
Column *aCol; /* Information about each column */
1029010308
Index *pIndex; /* List of SQL indexes on this table. */
10291
- int tnum; /* Root BTree node for this table (see note above) */
10292
- tRowcnt nRowEst; /* Estimated rows in table - from sqlite_stat1 table */
1029310309
Select *pSelect; /* NULL for tables. Points to definition if a view. */
10294
- u16 nRef; /* Number of pointers to this Table */
10295
- u8 tabFlags; /* Mask of TF_* values */
10296
- u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
1029710310
FKey *pFKey; /* Linked list of all foreign keys in this table */
1029810311
char *zColAff; /* String defining the affinity of each column */
1029910312
#ifndef SQLITE_OMIT_CHECK
1030010313
ExprList *pCheck; /* All CHECK constraints */
1030110314
#endif
10315
+ tRowcnt nRowEst; /* Estimated rows in table - from sqlite_stat1 table */
10316
+ int tnum; /* Root BTree node for this table (see note above) */
10317
+ i16 iPKey; /* If not negative, use aCol[iPKey] as the primary key */
10318
+ i16 nCol; /* Number of columns in this table */
10319
+ u16 nRef; /* Number of pointers to this Table */
10320
+ u8 tabFlags; /* Mask of TF_* values */
10321
+ u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
1030210322
#ifndef SQLITE_OMIT_ALTERTABLE
1030310323
int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */
1030410324
#endif
1030510325
#ifndef SQLITE_OMIT_VIRTUALTABLE
10306
- VTable *pVTable; /* List of VTable objects. */
1030710326
int nModuleArg; /* Number of arguments to the module */
1030810327
char **azModuleArg; /* Text of all module args. [0] is module name */
10328
+ VTable *pVTable; /* List of VTable objects. */
1030910329
#endif
1031010330
Trigger *pTrigger; /* List of triggers stored in pSchema */
1031110331
Schema *pSchema; /* Schema that contains this table */
1031210332
Table *pNextZombie; /* Next on the Parse.pZombieTab list */
1031310333
};
@@ -10327,11 +10347,11 @@
1032710347
** done as a macro so that it will be optimized out when virtual
1032810348
** table support is omitted from the build.
1032910349
*/
1033010350
#ifndef SQLITE_OMIT_VIRTUALTABLE
1033110351
# define IsVirtual(X) (((X)->tabFlags & TF_Virtual)!=0)
10332
-# define IsHiddenColumn(X) ((X)->isHidden)
10352
+# define IsHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0)
1033310353
#else
1033410354
# define IsVirtual(X) 0
1033510355
# define IsHiddenColumn(X) 0
1033610356
#endif
1033710357
@@ -10679,10 +10699,13 @@
1067910699
/* If the EP_Reduced flag is set in the Expr.flags mask, then no
1068010700
** space is allocated for the fields below this point. An attempt to
1068110701
** access them will result in a segfault or malfunction.
1068210702
*********************************************************************/
1068310703
10704
+#if SQLITE_MAX_EXPR_DEPTH>0
10705
+ int nHeight; /* Height of the tree headed by this node */
10706
+#endif
1068410707
int iTable; /* TK_COLUMN: cursor number of table holding column
1068510708
** TK_REGISTER: register number
1068610709
** TK_TRIGGER: 1 -> new, 0 -> old */
1068710710
ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
1068810711
** TK_VARIABLE: variable number (always >= 1). */
@@ -10692,13 +10715,10 @@
1069210715
u8 op2; /* TK_REGISTER: original value of Expr.op
1069310716
** TK_COLUMN: the value of p5 for OP_Column
1069410717
** TK_AGG_FUNCTION: nesting depth */
1069510718
AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
1069610719
Table *pTab; /* Table for TK_COLUMN expressions. */
10697
-#if SQLITE_MAX_EXPR_DEPTH>0
10698
- int nHeight; /* Height of the tree headed by this node */
10699
-#endif
1070010720
};
1070110721
1070210722
/*
1070310723
** The following are the meanings of bits in the Expr.flags field.
1070410724
*/
@@ -11459,10 +11479,11 @@
1145911479
struct Sqlite3Config {
1146011480
int bMemstat; /* True to enable memory status */
1146111481
int bCoreMutex; /* True to enable core mutexing */
1146211482
int bFullMutex; /* True to enable full mutexing */
1146311483
int bOpenUri; /* True to interpret filenames as URIs */
11484
+ int bUseCis; /* Use covering indices for full-scans */
1146411485
int mxStrlen; /* Maximum string length */
1146511486
int szLookaside; /* Default lookaside buffer size */
1146611487
int nLookaside; /* Default lookaside buffer count */
1146711488
sqlite3_mem_methods m; /* Low-level memory allocation interface */
1146811489
sqlite3_mutex_methods mutex; /* Low-level mutex interface */
@@ -11775,10 +11796,11 @@
1177511796
SQLITE_PRIVATE void sqlite3AutoincrementEnd(Parse *pParse);
1177611797
#else
1177711798
# define sqlite3AutoincrementBegin(X)
1177811799
# define sqlite3AutoincrementEnd(X)
1177911800
#endif
11801
+SQLITE_PRIVATE int sqlite3CodeCoroutine(Parse*, Select*, SelectDest*);
1178011802
SQLITE_PRIVATE void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int);
1178111803
SQLITE_PRIVATE void *sqlite3ArrayAllocate(sqlite3*,void*,int,int*,int*);
1178211804
SQLITE_PRIVATE IdList *sqlite3IdListAppend(sqlite3*, IdList*, Token*);
1178311805
SQLITE_PRIVATE int sqlite3IdListIndex(IdList*,const char*);
1178411806
SQLITE_PRIVATE SrcList *sqlite3SrcListEnlarge(sqlite3*, SrcList*, int, int);
@@ -11950,11 +11972,11 @@
1195011972
SQLITE_PRIVATE int sqlite3AtoF(const char *z, double*, int, u8);
1195111973
SQLITE_PRIVATE int sqlite3GetInt32(const char *, int*);
1195211974
SQLITE_PRIVATE int sqlite3Atoi(const char*);
1195311975
SQLITE_PRIVATE int sqlite3Utf16ByteLen(const void *pData, int nChar);
1195411976
SQLITE_PRIVATE int sqlite3Utf8CharLen(const char *pData, int nByte);
11955
-SQLITE_PRIVATE u32 sqlite3Utf8Read(const u8*, const u8**);
11977
+SQLITE_PRIVATE u32 sqlite3Utf8Read(const u8**);
1195611978
1195711979
/*
1195811980
** Routines to read and write variable-length integers. These used to
1195911981
** be defined locally, but now we use the varint routines in the util.c
1196011982
** file. Code should use the MACRO forms below, as the Varint32 versions
@@ -12450,19 +12472,24 @@
1245012472
1245112473
#ifndef SQLITE_USE_URI
1245212474
# define SQLITE_USE_URI 0
1245312475
#endif
1245412476
12477
+#ifndef SQLITE_ALLOW_COVERING_INDEX_SCAN
12478
+# define SQLITE_ALLOW_COVERING_INDEX_SCAN 1
12479
+#endif
12480
+
1245512481
/*
1245612482
** The following singleton contains the global configuration for
1245712483
** the SQLite library.
1245812484
*/
1245912485
SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = {
1246012486
SQLITE_DEFAULT_MEMSTATUS, /* bMemstat */
1246112487
1, /* bCoreMutex */
1246212488
SQLITE_THREADSAFE==1, /* bFullMutex */
1246312489
SQLITE_USE_URI, /* bOpenUri */
12490
+ SQLITE_ALLOW_COVERING_INDEX_SCAN, /* bUseCis */
1246412491
0x7ffffffe, /* mxStrlen */
1246512492
128, /* szLookaside */
1246612493
500, /* nLookaside */
1246712494
{0,0,0,0,0,0,0,0}, /* m */
1246812495
{0,0,0,0,0,0,0,0,0}, /* mutex */
@@ -12876,10 +12903,13 @@
1287612903
#ifdef SQLITE_PERFORMANCE_TRACE
1287712904
"PERFORMANCE_TRACE",
1287812905
#endif
1287912906
#ifdef SQLITE_PROXY_DEBUG
1288012907
"PROXY_DEBUG",
12908
+#endif
12909
+#ifdef SQLITE_RTREE_INT_ONLY
12910
+ "RTREE_INT_ONLY",
1288112911
#endif
1288212912
#ifdef SQLITE_SECURE_DELETE
1288312913
"SECURE_DELETE",
1288412914
#endif
1288512915
#ifdef SQLITE_SMALL_STACK
@@ -13234,10 +13264,15 @@
1323413264
int nIndent; /* Number of elements in aIndent */
1323513265
u16 aIndent[100]; /* Levels of indentation */
1323613266
char zBase[100]; /* Initial space */
1323713267
};
1323813268
13269
+/* A bitfield type for use inside of structures. Always follow with :N where
13270
+** N is the number of bits.
13271
+*/
13272
+typedef unsigned bft; /* Bit Field Type */
13273
+
1323913274
/*
1324013275
** An instance of the virtual machine. This structure contains the complete
1324113276
** state of the virtual machine.
1324213277
**
1324313278
** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare()
@@ -13275,19 +13310,20 @@
1327513310
ynVar nzVar; /* Number of entries in azVar[] */
1327613311
u32 cacheCtr; /* VdbeCursor row cache generation counter */
1327713312
int pc; /* The program counter */
1327813313
int rc; /* Value to return */
1327913314
u8 errorAction; /* Recovery action to do in case of an error */
13280
- u8 explain; /* True if EXPLAIN present on SQL command */
13281
- u8 changeCntOn; /* True to update the change-counter */
13282
- u8 expired; /* True if the VM needs to be recompiled */
13283
- u8 runOnlyOnce; /* Automatically expire on reset */
1328413315
u8 minWriteFileFormat; /* Minimum file format for writable database files */
13285
- u8 inVtabMethod; /* See comments above */
13286
- u8 usesStmtJournal; /* True if uses a statement journal */
13287
- u8 readOnly; /* True for read-only statements */
13288
- u8 isPrepareV2; /* True if prepared with prepare_v2() */
13316
+ bft explain:2; /* True if EXPLAIN present on SQL command */
13317
+ bft inVtabMethod:2; /* See comments above */
13318
+ bft changeCntOn:1; /* True to update the change-counter */
13319
+ bft expired:1; /* True if the VM needs to be recompiled */
13320
+ bft runOnlyOnce:1; /* Automatically expire on reset */
13321
+ bft usesStmtJournal:1; /* True if uses a statement journal */
13322
+ bft readOnly:1; /* True for read-only statements */
13323
+ bft isPrepareV2:1; /* True if prepared with prepare_v2() */
13324
+ bft doingRerun:1; /* True if rerunning after an auto-reprepare */
1328913325
int nChange; /* Number of db changes made since last reset */
1329013326
yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */
1329113327
yDbMask lockMask; /* Subset of btreeMask that requires a lock */
1329213328
int iStatement; /* Statement number (or 0 if has not opened stmt) */
1329313329
int aCounter[3]; /* Counters used by sqlite3_stmt_status() */
@@ -20525,29 +20561,27 @@
2052520561
if( c<0x80 \
2052620562
|| (c&0xFFFFF800)==0xD800 \
2052720563
|| (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } \
2052820564
}
2052920565
SQLITE_PRIVATE u32 sqlite3Utf8Read(
20530
- const unsigned char *zIn, /* First byte of UTF-8 character */
20531
- const unsigned char **pzNext /* Write first byte past UTF-8 char here */
20566
+ const unsigned char **pz /* Pointer to string from which to read char */
2053220567
){
2053320568
unsigned int c;
2053420569
2053520570
/* Same as READ_UTF8() above but without the zTerm parameter.
2053620571
** For this routine, we assume the UTF8 string is always zero-terminated.
2053720572
*/
20538
- c = *(zIn++);
20573
+ c = *((*pz)++);
2053920574
if( c>=0xc0 ){
2054020575
c = sqlite3Utf8Trans1[c-0xc0];
20541
- while( (*zIn & 0xc0)==0x80 ){
20542
- c = (c<<6) + (0x3f & *(zIn++));
20576
+ while( (*(*pz) & 0xc0)==0x80 ){
20577
+ c = (c<<6) + (0x3f & *((*pz)++));
2054320578
}
2054420579
if( c<0x80
2054520580
|| (c&0xFFFFF800)==0xD800
2054620581
|| (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; }
2054720582
}
20548
- *pzNext = zIn;
2054920583
return c;
2055020584
}
2055120585
2055220586
2055320587
@@ -20644,19 +20678,17 @@
2064420678
2064520679
if( pMem->enc==SQLITE_UTF8 ){
2064620680
if( desiredEnc==SQLITE_UTF16LE ){
2064720681
/* UTF-8 -> UTF-16 Little-endian */
2064820682
while( zIn<zTerm ){
20649
- /* c = sqlite3Utf8Read(zIn, zTerm, (const u8**)&zIn); */
2065020683
READ_UTF8(zIn, zTerm, c);
2065120684
WRITE_UTF16LE(z, c);
2065220685
}
2065320686
}else{
2065420687
assert( desiredEnc==SQLITE_UTF16BE );
2065520688
/* UTF-8 -> UTF-16 Big-endian */
2065620689
while( zIn<zTerm ){
20657
- /* c = sqlite3Utf8Read(zIn, zTerm, (const u8**)&zIn); */
2065820690
READ_UTF8(zIn, zTerm, c);
2065920691
WRITE_UTF16BE(z, c);
2066020692
}
2066120693
}
2066220694
pMem->n = (int)(z - zOut);
@@ -20780,11 +20812,11 @@
2078020812
unsigned char *zOut = zIn;
2078120813
unsigned char *zStart = zIn;
2078220814
u32 c;
2078320815
2078420816
while( zIn[0] && zOut<=zIn ){
20785
- c = sqlite3Utf8Read(zIn, (const u8**)&zIn);
20817
+ c = sqlite3Utf8Read((const u8**)&zIn);
2078620818
if( c!=0xfffd ){
2078720819
WRITE_UTF8(zOut, c);
2078820820
}
2078920821
}
2079020822
*zOut = 0;
@@ -20885,11 +20917,11 @@
2088520917
WRITE_UTF8(z, i);
2088620918
n = (int)(z-zBuf);
2088720919
assert( n>0 && n<=4 );
2088820920
z[0] = 0;
2088920921
z = zBuf;
20890
- c = sqlite3Utf8Read(z, (const u8**)&z);
20922
+ c = sqlite3Utf8Read((const u8**)&z);
2089120923
t = i;
2089220924
if( i>=0xD800 && i<=0xDFFF ) t = 0xFFFD;
2089320925
if( (i&0xFFFFFFFE)==0xFFFE ) t = 0xFFFD;
2089420926
assert( c==t );
2089520927
assert( (z-zBuf)==n );
@@ -29887,10 +29919,19 @@
2988729919
#endif /* !defined(_OS_COMMON_H_) */
2988829920
2988929921
/************** End of os_common.h *******************************************/
2989029922
/************** Continuing where we left off in os_win.c *********************/
2989129923
29924
+/*
29925
+** Compiling and using WAL mode requires several APIs that are only
29926
+** available in Windows platforms based on the NT kernel.
29927
+*/
29928
+#if !SQLITE_OS_WINNT && !defined(SQLITE_OMIT_WAL)
29929
+# error "WAL mode requires support from the Windows NT kernel, compile\
29930
+ with SQLITE_OMIT_WAL."
29931
+#endif
29932
+
2989229933
/*
2989329934
** Macro to find the minimum of two numeric values.
2989429935
*/
2989529936
#ifndef MIN
2989629937
# define MIN(x,y) ((x)<(y)?(x):(y))
@@ -30170,166 +30211,176 @@
3017030211
{ "CreateFileW", (SYSCALL)0, 0 },
3017130212
#endif
3017230213
3017330214
#define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \
3017430215
LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent)
30216
+
30217
+#if (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_ANSI) && \
30218
+ !defined(SQLITE_OMIT_WAL))
30219
+ { "CreateFileMappingA", (SYSCALL)CreateFileMappingA, 0 },
30220
+#else
30221
+ { "CreateFileMappingA", (SYSCALL)0, 0 },
30222
+#endif
30223
+
30224
+#define osCreateFileMappingA ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \
30225
+ DWORD,DWORD,DWORD,LPCSTR))aSyscall[6].pCurrent)
3017530226
3017630227
#if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \
3017730228
!defined(SQLITE_OMIT_WAL))
3017830229
{ "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 },
3017930230
#else
3018030231
{ "CreateFileMappingW", (SYSCALL)0, 0 },
3018130232
#endif
3018230233
3018330234
#define osCreateFileMappingW ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \
30184
- DWORD,DWORD,DWORD,LPCWSTR))aSyscall[6].pCurrent)
30235
+ DWORD,DWORD,DWORD,LPCWSTR))aSyscall[7].pCurrent)
3018530236
3018630237
#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
3018730238
{ "CreateMutexW", (SYSCALL)CreateMutexW, 0 },
3018830239
#else
3018930240
{ "CreateMutexW", (SYSCALL)0, 0 },
3019030241
#endif
3019130242
3019230243
#define osCreateMutexW ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,BOOL, \
30193
- LPCWSTR))aSyscall[7].pCurrent)
30244
+ LPCWSTR))aSyscall[8].pCurrent)
3019430245
3019530246
#if defined(SQLITE_WIN32_HAS_ANSI)
3019630247
{ "DeleteFileA", (SYSCALL)DeleteFileA, 0 },
3019730248
#else
3019830249
{ "DeleteFileA", (SYSCALL)0, 0 },
3019930250
#endif
3020030251
30201
-#define osDeleteFileA ((BOOL(WINAPI*)(LPCSTR))aSyscall[8].pCurrent)
30252
+#define osDeleteFileA ((BOOL(WINAPI*)(LPCSTR))aSyscall[9].pCurrent)
3020230253
3020330254
#if defined(SQLITE_WIN32_HAS_WIDE)
3020430255
{ "DeleteFileW", (SYSCALL)DeleteFileW, 0 },
3020530256
#else
3020630257
{ "DeleteFileW", (SYSCALL)0, 0 },
3020730258
#endif
3020830259
30209
-#define osDeleteFileW ((BOOL(WINAPI*)(LPCWSTR))aSyscall[9].pCurrent)
30260
+#define osDeleteFileW ((BOOL(WINAPI*)(LPCWSTR))aSyscall[10].pCurrent)
3021030261
3021130262
#if SQLITE_OS_WINCE
3021230263
{ "FileTimeToLocalFileTime", (SYSCALL)FileTimeToLocalFileTime, 0 },
3021330264
#else
3021430265
{ "FileTimeToLocalFileTime", (SYSCALL)0, 0 },
3021530266
#endif
3021630267
3021730268
#define osFileTimeToLocalFileTime ((BOOL(WINAPI*)(CONST FILETIME*, \
30218
- LPFILETIME))aSyscall[10].pCurrent)
30269
+ LPFILETIME))aSyscall[11].pCurrent)
3021930270
3022030271
#if SQLITE_OS_WINCE
3022130272
{ "FileTimeToSystemTime", (SYSCALL)FileTimeToSystemTime, 0 },
3022230273
#else
3022330274
{ "FileTimeToSystemTime", (SYSCALL)0, 0 },
3022430275
#endif
3022530276
3022630277
#define osFileTimeToSystemTime ((BOOL(WINAPI*)(CONST FILETIME*, \
30227
- LPSYSTEMTIME))aSyscall[11].pCurrent)
30278
+ LPSYSTEMTIME))aSyscall[12].pCurrent)
3022830279
3022930280
{ "FlushFileBuffers", (SYSCALL)FlushFileBuffers, 0 },
3023030281
30231
-#define osFlushFileBuffers ((BOOL(WINAPI*)(HANDLE))aSyscall[12].pCurrent)
30282
+#define osFlushFileBuffers ((BOOL(WINAPI*)(HANDLE))aSyscall[13].pCurrent)
3023230283
3023330284
#if defined(SQLITE_WIN32_HAS_ANSI)
3023430285
{ "FormatMessageA", (SYSCALL)FormatMessageA, 0 },
3023530286
#else
3023630287
{ "FormatMessageA", (SYSCALL)0, 0 },
3023730288
#endif
3023830289
3023930290
#define osFormatMessageA ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPSTR, \
30240
- DWORD,va_list*))aSyscall[13].pCurrent)
30291
+ DWORD,va_list*))aSyscall[14].pCurrent)
3024130292
3024230293
#if defined(SQLITE_WIN32_HAS_WIDE)
3024330294
{ "FormatMessageW", (SYSCALL)FormatMessageW, 0 },
3024430295
#else
3024530296
{ "FormatMessageW", (SYSCALL)0, 0 },
3024630297
#endif
3024730298
3024830299
#define osFormatMessageW ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPWSTR, \
30249
- DWORD,va_list*))aSyscall[14].pCurrent)
30300
+ DWORD,va_list*))aSyscall[15].pCurrent)
3025030301
3025130302
{ "FreeLibrary", (SYSCALL)FreeLibrary, 0 },
3025230303
30253
-#define osFreeLibrary ((BOOL(WINAPI*)(HMODULE))aSyscall[15].pCurrent)
30304
+#define osFreeLibrary ((BOOL(WINAPI*)(HMODULE))aSyscall[16].pCurrent)
3025430305
3025530306
{ "GetCurrentProcessId", (SYSCALL)GetCurrentProcessId, 0 },
3025630307
30257
-#define osGetCurrentProcessId ((DWORD(WINAPI*)(VOID))aSyscall[16].pCurrent)
30308
+#define osGetCurrentProcessId ((DWORD(WINAPI*)(VOID))aSyscall[17].pCurrent)
3025830309
3025930310
#if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_ANSI)
3026030311
{ "GetDiskFreeSpaceA", (SYSCALL)GetDiskFreeSpaceA, 0 },
3026130312
#else
3026230313
{ "GetDiskFreeSpaceA", (SYSCALL)0, 0 },
3026330314
#endif
3026430315
3026530316
#define osGetDiskFreeSpaceA ((BOOL(WINAPI*)(LPCSTR,LPDWORD,LPDWORD,LPDWORD, \
30266
- LPDWORD))aSyscall[17].pCurrent)
30317
+ LPDWORD))aSyscall[18].pCurrent)
3026730318
3026830319
#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
3026930320
{ "GetDiskFreeSpaceW", (SYSCALL)GetDiskFreeSpaceW, 0 },
3027030321
#else
3027130322
{ "GetDiskFreeSpaceW", (SYSCALL)0, 0 },
3027230323
#endif
3027330324
3027430325
#define osGetDiskFreeSpaceW ((BOOL(WINAPI*)(LPCWSTR,LPDWORD,LPDWORD,LPDWORD, \
30275
- LPDWORD))aSyscall[18].pCurrent)
30326
+ LPDWORD))aSyscall[19].pCurrent)
3027630327
3027730328
#if defined(SQLITE_WIN32_HAS_ANSI)
3027830329
{ "GetFileAttributesA", (SYSCALL)GetFileAttributesA, 0 },
3027930330
#else
3028030331
{ "GetFileAttributesA", (SYSCALL)0, 0 },
3028130332
#endif
3028230333
30283
-#define osGetFileAttributesA ((DWORD(WINAPI*)(LPCSTR))aSyscall[19].pCurrent)
30334
+#define osGetFileAttributesA ((DWORD(WINAPI*)(LPCSTR))aSyscall[20].pCurrent)
3028430335
3028530336
#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
3028630337
{ "GetFileAttributesW", (SYSCALL)GetFileAttributesW, 0 },
3028730338
#else
3028830339
{ "GetFileAttributesW", (SYSCALL)0, 0 },
3028930340
#endif
3029030341
30291
-#define osGetFileAttributesW ((DWORD(WINAPI*)(LPCWSTR))aSyscall[20].pCurrent)
30342
+#define osGetFileAttributesW ((DWORD(WINAPI*)(LPCWSTR))aSyscall[21].pCurrent)
3029230343
3029330344
#if defined(SQLITE_WIN32_HAS_WIDE)
3029430345
{ "GetFileAttributesExW", (SYSCALL)GetFileAttributesExW, 0 },
3029530346
#else
3029630347
{ "GetFileAttributesExW", (SYSCALL)0, 0 },
3029730348
#endif
3029830349
3029930350
#define osGetFileAttributesExW ((BOOL(WINAPI*)(LPCWSTR,GET_FILEEX_INFO_LEVELS, \
30300
- LPVOID))aSyscall[21].pCurrent)
30351
+ LPVOID))aSyscall[22].pCurrent)
3030130352
3030230353
#if !SQLITE_OS_WINRT
3030330354
{ "GetFileSize", (SYSCALL)GetFileSize, 0 },
3030430355
#else
3030530356
{ "GetFileSize", (SYSCALL)0, 0 },
3030630357
#endif
3030730358
30308
-#define osGetFileSize ((DWORD(WINAPI*)(HANDLE,LPDWORD))aSyscall[22].pCurrent)
30359
+#define osGetFileSize ((DWORD(WINAPI*)(HANDLE,LPDWORD))aSyscall[23].pCurrent)
3030930360
3031030361
#if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_ANSI)
3031130362
{ "GetFullPathNameA", (SYSCALL)GetFullPathNameA, 0 },
3031230363
#else
3031330364
{ "GetFullPathNameA", (SYSCALL)0, 0 },
3031430365
#endif
3031530366
3031630367
#define osGetFullPathNameA ((DWORD(WINAPI*)(LPCSTR,DWORD,LPSTR, \
30317
- LPSTR*))aSyscall[23].pCurrent)
30368
+ LPSTR*))aSyscall[24].pCurrent)
3031830369
3031930370
#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
3032030371
{ "GetFullPathNameW", (SYSCALL)GetFullPathNameW, 0 },
3032130372
#else
3032230373
{ "GetFullPathNameW", (SYSCALL)0, 0 },
3032330374
#endif
3032430375
3032530376
#define osGetFullPathNameW ((DWORD(WINAPI*)(LPCWSTR,DWORD,LPWSTR, \
30326
- LPWSTR*))aSyscall[24].pCurrent)
30377
+ LPWSTR*))aSyscall[25].pCurrent)
3032730378
3032830379
{ "GetLastError", (SYSCALL)GetLastError, 0 },
3032930380
30330
-#define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[25].pCurrent)
30381
+#define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[26].pCurrent)
3033130382
3033230383
#if SQLITE_OS_WINCE
3033330384
/* The GetProcAddressA() routine is only available on Windows CE. */
3033430385
{ "GetProcAddressA", (SYSCALL)GetProcAddressA, 0 },
3033530386
#else
@@ -30337,144 +30388,144 @@
3033730388
** an ANSI string regardless of the _UNICODE setting */
3033830389
{ "GetProcAddressA", (SYSCALL)GetProcAddress, 0 },
3033930390
#endif
3034030391
3034130392
#define osGetProcAddressA ((FARPROC(WINAPI*)(HMODULE, \
30342
- LPCSTR))aSyscall[26].pCurrent)
30393
+ LPCSTR))aSyscall[27].pCurrent)
3034330394
3034430395
#if !SQLITE_OS_WINRT
3034530396
{ "GetSystemInfo", (SYSCALL)GetSystemInfo, 0 },
3034630397
#else
3034730398
{ "GetSystemInfo", (SYSCALL)0, 0 },
3034830399
#endif
3034930400
30350
-#define osGetSystemInfo ((VOID(WINAPI*)(LPSYSTEM_INFO))aSyscall[27].pCurrent)
30401
+#define osGetSystemInfo ((VOID(WINAPI*)(LPSYSTEM_INFO))aSyscall[28].pCurrent)
3035130402
3035230403
{ "GetSystemTime", (SYSCALL)GetSystemTime, 0 },
3035330404
30354
-#define osGetSystemTime ((VOID(WINAPI*)(LPSYSTEMTIME))aSyscall[28].pCurrent)
30405
+#define osGetSystemTime ((VOID(WINAPI*)(LPSYSTEMTIME))aSyscall[29].pCurrent)
3035530406
3035630407
#if !SQLITE_OS_WINCE
3035730408
{ "GetSystemTimeAsFileTime", (SYSCALL)GetSystemTimeAsFileTime, 0 },
3035830409
#else
3035930410
{ "GetSystemTimeAsFileTime", (SYSCALL)0, 0 },
3036030411
#endif
3036130412
3036230413
#define osGetSystemTimeAsFileTime ((VOID(WINAPI*)( \
30363
- LPFILETIME))aSyscall[29].pCurrent)
30414
+ LPFILETIME))aSyscall[30].pCurrent)
3036430415
3036530416
#if defined(SQLITE_WIN32_HAS_ANSI)
3036630417
{ "GetTempPathA", (SYSCALL)GetTempPathA, 0 },
3036730418
#else
3036830419
{ "GetTempPathA", (SYSCALL)0, 0 },
3036930420
#endif
3037030421
30371
-#define osGetTempPathA ((DWORD(WINAPI*)(DWORD,LPSTR))aSyscall[30].pCurrent)
30422
+#define osGetTempPathA ((DWORD(WINAPI*)(DWORD,LPSTR))aSyscall[31].pCurrent)
3037230423
3037330424
#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
3037430425
{ "GetTempPathW", (SYSCALL)GetTempPathW, 0 },
3037530426
#else
3037630427
{ "GetTempPathW", (SYSCALL)0, 0 },
3037730428
#endif
3037830429
30379
-#define osGetTempPathW ((DWORD(WINAPI*)(DWORD,LPWSTR))aSyscall[31].pCurrent)
30430
+#define osGetTempPathW ((DWORD(WINAPI*)(DWORD,LPWSTR))aSyscall[32].pCurrent)
3038030431
3038130432
#if !SQLITE_OS_WINRT
3038230433
{ "GetTickCount", (SYSCALL)GetTickCount, 0 },
3038330434
#else
3038430435
{ "GetTickCount", (SYSCALL)0, 0 },
3038530436
#endif
3038630437
30387
-#define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[32].pCurrent)
30438
+#define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[33].pCurrent)
3038830439
3038930440
#if defined(SQLITE_WIN32_HAS_ANSI)
3039030441
{ "GetVersionExA", (SYSCALL)GetVersionExA, 0 },
3039130442
#else
3039230443
{ "GetVersionExA", (SYSCALL)0, 0 },
3039330444
#endif
3039430445
3039530446
#define osGetVersionExA ((BOOL(WINAPI*)( \
30396
- LPOSVERSIONINFOA))aSyscall[33].pCurrent)
30447
+ LPOSVERSIONINFOA))aSyscall[34].pCurrent)
3039730448
3039830449
{ "HeapAlloc", (SYSCALL)HeapAlloc, 0 },
3039930450
3040030451
#define osHeapAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD, \
30401
- SIZE_T))aSyscall[34].pCurrent)
30452
+ SIZE_T))aSyscall[35].pCurrent)
3040230453
3040330454
#if !SQLITE_OS_WINRT
3040430455
{ "HeapCreate", (SYSCALL)HeapCreate, 0 },
3040530456
#else
3040630457
{ "HeapCreate", (SYSCALL)0, 0 },
3040730458
#endif
3040830459
3040930460
#define osHeapCreate ((HANDLE(WINAPI*)(DWORD,SIZE_T, \
30410
- SIZE_T))aSyscall[35].pCurrent)
30461
+ SIZE_T))aSyscall[36].pCurrent)
3041130462
3041230463
#if !SQLITE_OS_WINRT
3041330464
{ "HeapDestroy", (SYSCALL)HeapDestroy, 0 },
3041430465
#else
3041530466
{ "HeapDestroy", (SYSCALL)0, 0 },
3041630467
#endif
3041730468
30418
-#define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[36].pCurrent)
30469
+#define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[37].pCurrent)
3041930470
3042030471
{ "HeapFree", (SYSCALL)HeapFree, 0 },
3042130472
30422
-#define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[37].pCurrent)
30473
+#define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[38].pCurrent)
3042330474
3042430475
{ "HeapReAlloc", (SYSCALL)HeapReAlloc, 0 },
3042530476
3042630477
#define osHeapReAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD,LPVOID, \
30427
- SIZE_T))aSyscall[38].pCurrent)
30478
+ SIZE_T))aSyscall[39].pCurrent)
3042830479
3042930480
{ "HeapSize", (SYSCALL)HeapSize, 0 },
3043030481
3043130482
#define osHeapSize ((SIZE_T(WINAPI*)(HANDLE,DWORD, \
30432
- LPCVOID))aSyscall[39].pCurrent)
30483
+ LPCVOID))aSyscall[40].pCurrent)
3043330484
3043430485
#if !SQLITE_OS_WINRT
3043530486
{ "HeapValidate", (SYSCALL)HeapValidate, 0 },
3043630487
#else
3043730488
{ "HeapValidate", (SYSCALL)0, 0 },
3043830489
#endif
3043930490
3044030491
#define osHeapValidate ((BOOL(WINAPI*)(HANDLE,DWORD, \
30441
- LPCVOID))aSyscall[40].pCurrent)
30492
+ LPCVOID))aSyscall[41].pCurrent)
3044230493
3044330494
#if defined(SQLITE_WIN32_HAS_ANSI)
3044430495
{ "LoadLibraryA", (SYSCALL)LoadLibraryA, 0 },
3044530496
#else
3044630497
{ "LoadLibraryA", (SYSCALL)0, 0 },
3044730498
#endif
3044830499
30449
-#define osLoadLibraryA ((HMODULE(WINAPI*)(LPCSTR))aSyscall[41].pCurrent)
30500
+#define osLoadLibraryA ((HMODULE(WINAPI*)(LPCSTR))aSyscall[42].pCurrent)
3045030501
3045130502
#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
3045230503
{ "LoadLibraryW", (SYSCALL)LoadLibraryW, 0 },
3045330504
#else
3045430505
{ "LoadLibraryW", (SYSCALL)0, 0 },
3045530506
#endif
3045630507
30457
-#define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[42].pCurrent)
30508
+#define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[43].pCurrent)
3045830509
3045930510
#if !SQLITE_OS_WINRT
3046030511
{ "LocalFree", (SYSCALL)LocalFree, 0 },
3046130512
#else
3046230513
{ "LocalFree", (SYSCALL)0, 0 },
3046330514
#endif
3046430515
30465
-#define osLocalFree ((HLOCAL(WINAPI*)(HLOCAL))aSyscall[43].pCurrent)
30516
+#define osLocalFree ((HLOCAL(WINAPI*)(HLOCAL))aSyscall[44].pCurrent)
3046630517
3046730518
#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
3046830519
{ "LockFile", (SYSCALL)LockFile, 0 },
3046930520
#else
3047030521
{ "LockFile", (SYSCALL)0, 0 },
3047130522
#endif
3047230523
3047330524
#ifndef osLockFile
3047430525
#define osLockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
30475
- DWORD))aSyscall[44].pCurrent)
30526
+ DWORD))aSyscall[45].pCurrent)
3047630527
#endif
3047730528
3047830529
#if !SQLITE_OS_WINCE
3047930530
{ "LockFileEx", (SYSCALL)LockFileEx, 0 },
3048030531
#else
@@ -30481,218 +30532,218 @@
3048130532
{ "LockFileEx", (SYSCALL)0, 0 },
3048230533
#endif
3048330534
3048430535
#ifndef osLockFileEx
3048530536
#define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \
30486
- LPOVERLAPPED))aSyscall[45].pCurrent)
30537
+ LPOVERLAPPED))aSyscall[46].pCurrent)
3048730538
#endif
3048830539
3048930540
#if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL))
3049030541
{ "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 },
3049130542
#else
3049230543
{ "MapViewOfFile", (SYSCALL)0, 0 },
3049330544
#endif
3049430545
3049530546
#define osMapViewOfFile ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
30496
- SIZE_T))aSyscall[46].pCurrent)
30547
+ SIZE_T))aSyscall[47].pCurrent)
3049730548
3049830549
{ "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 },
3049930550
3050030551
#define osMultiByteToWideChar ((int(WINAPI*)(UINT,DWORD,LPCSTR,int,LPWSTR, \
30501
- int))aSyscall[47].pCurrent)
30552
+ int))aSyscall[48].pCurrent)
3050230553
3050330554
{ "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 },
3050430555
3050530556
#define osQueryPerformanceCounter ((BOOL(WINAPI*)( \
30506
- LARGE_INTEGER*))aSyscall[48].pCurrent)
30557
+ LARGE_INTEGER*))aSyscall[49].pCurrent)
3050730558
3050830559
{ "ReadFile", (SYSCALL)ReadFile, 0 },
3050930560
3051030561
#define osReadFile ((BOOL(WINAPI*)(HANDLE,LPVOID,DWORD,LPDWORD, \
30511
- LPOVERLAPPED))aSyscall[49].pCurrent)
30562
+ LPOVERLAPPED))aSyscall[50].pCurrent)
3051230563
3051330564
{ "SetEndOfFile", (SYSCALL)SetEndOfFile, 0 },
3051430565
30515
-#define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[50].pCurrent)
30566
+#define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[51].pCurrent)
3051630567
3051730568
#if !SQLITE_OS_WINRT
3051830569
{ "SetFilePointer", (SYSCALL)SetFilePointer, 0 },
3051930570
#else
3052030571
{ "SetFilePointer", (SYSCALL)0, 0 },
3052130572
#endif
3052230573
3052330574
#define osSetFilePointer ((DWORD(WINAPI*)(HANDLE,LONG,PLONG, \
30524
- DWORD))aSyscall[51].pCurrent)
30575
+ DWORD))aSyscall[52].pCurrent)
3052530576
3052630577
#if !SQLITE_OS_WINRT
3052730578
{ "Sleep", (SYSCALL)Sleep, 0 },
3052830579
#else
3052930580
{ "Sleep", (SYSCALL)0, 0 },
3053030581
#endif
3053130582
30532
-#define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[52].pCurrent)
30583
+#define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[53].pCurrent)
3053330584
3053430585
{ "SystemTimeToFileTime", (SYSCALL)SystemTimeToFileTime, 0 },
3053530586
3053630587
#define osSystemTimeToFileTime ((BOOL(WINAPI*)(CONST SYSTEMTIME*, \
30537
- LPFILETIME))aSyscall[53].pCurrent)
30588
+ LPFILETIME))aSyscall[54].pCurrent)
3053830589
3053930590
#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
3054030591
{ "UnlockFile", (SYSCALL)UnlockFile, 0 },
3054130592
#else
3054230593
{ "UnlockFile", (SYSCALL)0, 0 },
3054330594
#endif
3054430595
3054530596
#ifndef osUnlockFile
3054630597
#define osUnlockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
30547
- DWORD))aSyscall[54].pCurrent)
30598
+ DWORD))aSyscall[55].pCurrent)
3054830599
#endif
3054930600
3055030601
#if !SQLITE_OS_WINCE
3055130602
{ "UnlockFileEx", (SYSCALL)UnlockFileEx, 0 },
3055230603
#else
3055330604
{ "UnlockFileEx", (SYSCALL)0, 0 },
3055430605
#endif
3055530606
3055630607
#define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
30557
- LPOVERLAPPED))aSyscall[55].pCurrent)
30608
+ LPOVERLAPPED))aSyscall[56].pCurrent)
3055830609
3055930610
#if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL)
3056030611
{ "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 },
3056130612
#else
3056230613
{ "UnmapViewOfFile", (SYSCALL)0, 0 },
3056330614
#endif
3056430615
30565
-#define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[56].pCurrent)
30616
+#define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[57].pCurrent)
3056630617
3056730618
{ "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 },
3056830619
3056930620
#define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \
30570
- LPCSTR,LPBOOL))aSyscall[57].pCurrent)
30621
+ LPCSTR,LPBOOL))aSyscall[58].pCurrent)
3057130622
3057230623
{ "WriteFile", (SYSCALL)WriteFile, 0 },
3057330624
3057430625
#define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \
30575
- LPOVERLAPPED))aSyscall[58].pCurrent)
30626
+ LPOVERLAPPED))aSyscall[59].pCurrent)
3057630627
3057730628
#if SQLITE_OS_WINRT
3057830629
{ "CreateEventExW", (SYSCALL)CreateEventExW, 0 },
3057930630
#else
3058030631
{ "CreateEventExW", (SYSCALL)0, 0 },
3058130632
#endif
3058230633
3058330634
#define osCreateEventExW ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,LPCWSTR, \
30584
- DWORD,DWORD))aSyscall[59].pCurrent)
30635
+ DWORD,DWORD))aSyscall[60].pCurrent)
3058530636
3058630637
#if !SQLITE_OS_WINRT
3058730638
{ "WaitForSingleObject", (SYSCALL)WaitForSingleObject, 0 },
3058830639
#else
3058930640
{ "WaitForSingleObject", (SYSCALL)0, 0 },
3059030641
#endif
3059130642
3059230643
#define osWaitForSingleObject ((DWORD(WINAPI*)(HANDLE, \
30593
- DWORD))aSyscall[60].pCurrent)
30644
+ DWORD))aSyscall[61].pCurrent)
3059430645
3059530646
#if SQLITE_OS_WINRT
3059630647
{ "WaitForSingleObjectEx", (SYSCALL)WaitForSingleObjectEx, 0 },
3059730648
#else
3059830649
{ "WaitForSingleObjectEx", (SYSCALL)0, 0 },
3059930650
#endif
3060030651
3060130652
#define osWaitForSingleObjectEx ((DWORD(WINAPI*)(HANDLE,DWORD, \
30602
- BOOL))aSyscall[61].pCurrent)
30653
+ BOOL))aSyscall[62].pCurrent)
3060330654
3060430655
#if SQLITE_OS_WINRT
3060530656
{ "SetFilePointerEx", (SYSCALL)SetFilePointerEx, 0 },
3060630657
#else
3060730658
{ "SetFilePointerEx", (SYSCALL)0, 0 },
3060830659
#endif
3060930660
3061030661
#define osSetFilePointerEx ((BOOL(WINAPI*)(HANDLE,LARGE_INTEGER, \
30611
- PLARGE_INTEGER,DWORD))aSyscall[62].pCurrent)
30662
+ PLARGE_INTEGER,DWORD))aSyscall[63].pCurrent)
3061230663
3061330664
#if SQLITE_OS_WINRT
3061430665
{ "GetFileInformationByHandleEx", (SYSCALL)GetFileInformationByHandleEx, 0 },
3061530666
#else
3061630667
{ "GetFileInformationByHandleEx", (SYSCALL)0, 0 },
3061730668
#endif
3061830669
3061930670
#define osGetFileInformationByHandleEx ((BOOL(WINAPI*)(HANDLE, \
30620
- FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[63].pCurrent)
30671
+ FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[64].pCurrent)
3062130672
3062230673
#if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)
3062330674
{ "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 },
3062430675
#else
3062530676
{ "MapViewOfFileFromApp", (SYSCALL)0, 0 },
3062630677
#endif
3062730678
3062830679
#define osMapViewOfFileFromApp ((LPVOID(WINAPI*)(HANDLE,ULONG,ULONG64, \
30629
- SIZE_T))aSyscall[64].pCurrent)
30680
+ SIZE_T))aSyscall[65].pCurrent)
3063030681
3063130682
#if SQLITE_OS_WINRT
3063230683
{ "CreateFile2", (SYSCALL)CreateFile2, 0 },
3063330684
#else
3063430685
{ "CreateFile2", (SYSCALL)0, 0 },
3063530686
#endif
3063630687
3063730688
#define osCreateFile2 ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD,DWORD, \
30638
- LPCREATEFILE2_EXTENDED_PARAMETERS))aSyscall[65].pCurrent)
30689
+ LPCREATEFILE2_EXTENDED_PARAMETERS))aSyscall[66].pCurrent)
3063930690
3064030691
#if SQLITE_OS_WINRT
3064130692
{ "LoadPackagedLibrary", (SYSCALL)LoadPackagedLibrary, 0 },
3064230693
#else
3064330694
{ "LoadPackagedLibrary", (SYSCALL)0, 0 },
3064430695
#endif
3064530696
3064630697
#define osLoadPackagedLibrary ((HMODULE(WINAPI*)(LPCWSTR, \
30647
- DWORD))aSyscall[66].pCurrent)
30698
+ DWORD))aSyscall[67].pCurrent)
3064830699
3064930700
#if SQLITE_OS_WINRT
3065030701
{ "GetTickCount64", (SYSCALL)GetTickCount64, 0 },
3065130702
#else
3065230703
{ "GetTickCount64", (SYSCALL)0, 0 },
3065330704
#endif
3065430705
30655
-#define osGetTickCount64 ((ULONGLONG(WINAPI*)(VOID))aSyscall[67].pCurrent)
30706
+#define osGetTickCount64 ((ULONGLONG(WINAPI*)(VOID))aSyscall[68].pCurrent)
3065630707
3065730708
#if SQLITE_OS_WINRT
3065830709
{ "GetNativeSystemInfo", (SYSCALL)GetNativeSystemInfo, 0 },
3065930710
#else
3066030711
{ "GetNativeSystemInfo", (SYSCALL)0, 0 },
3066130712
#endif
3066230713
3066330714
#define osGetNativeSystemInfo ((VOID(WINAPI*)( \
30664
- LPSYSTEM_INFO))aSyscall[68].pCurrent)
30715
+ LPSYSTEM_INFO))aSyscall[69].pCurrent)
3066530716
3066630717
#if defined(SQLITE_WIN32_HAS_ANSI)
3066730718
{ "OutputDebugStringA", (SYSCALL)OutputDebugStringA, 0 },
3066830719
#else
3066930720
{ "OutputDebugStringA", (SYSCALL)0, 0 },
3067030721
#endif
3067130722
30672
-#define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[69].pCurrent)
30723
+#define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[70].pCurrent)
3067330724
3067430725
#if defined(SQLITE_WIN32_HAS_WIDE)
3067530726
{ "OutputDebugStringW", (SYSCALL)OutputDebugStringW, 0 },
3067630727
#else
3067730728
{ "OutputDebugStringW", (SYSCALL)0, 0 },
3067830729
#endif
3067930730
30680
-#define osOutputDebugStringW ((VOID(WINAPI*)(LPCWSTR))aSyscall[70].pCurrent)
30731
+#define osOutputDebugStringW ((VOID(WINAPI*)(LPCWSTR))aSyscall[71].pCurrent)
3068130732
3068230733
{ "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 },
3068330734
30684
-#define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[71].pCurrent)
30735
+#define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[72].pCurrent)
3068530736
3068630737
#if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)
3068730738
{ "CreateFileMappingFromApp", (SYSCALL)CreateFileMappingFromApp, 0 },
3068830739
#else
3068930740
{ "CreateFileMappingFromApp", (SYSCALL)0, 0 },
3069030741
#endif
3069130742
3069230743
#define osCreateFileMappingFromApp ((HANDLE(WINAPI*)(HANDLE, \
30693
- LPSECURITY_ATTRIBUTES,ULONG,ULONG64,LPCWSTR))aSyscall[72].pCurrent)
30744
+ LPSECURITY_ATTRIBUTES,ULONG,ULONG64,LPCWSTR))aSyscall[73].pCurrent)
3069430745
3069530746
}; /* End of the overrideable system calls */
3069630747
3069730748
/*
3069830749
** This is the xSetSystemCall() method of sqlite3_vfs for all of the
@@ -30846,10 +30897,12 @@
3084630897
** WinNT/2K/XP so that we will know whether or not we can safely call
3084730898
** the LockFileEx() API.
3084830899
*/
3084930900
#if SQLITE_OS_WINCE || SQLITE_OS_WINRT
3085030901
# define isNT() (1)
30902
+#elif !defined(SQLITE_WIN32_HAS_WIDE)
30903
+# define isNT() (0)
3085130904
#else
3085230905
static int isNT(void){
3085330906
if( sqlite3_os_type==0 ){
3085430907
OSVERSIONINFOA sInfo;
3085530908
sInfo.dwOSVersionInfoSize = sizeof(sInfo);
@@ -30856,11 +30909,11 @@
3085630909
osGetVersionExA(&sInfo);
3085730910
sqlite3_os_type = sInfo.dwPlatformId==VER_PLATFORM_WIN32_NT ? 2 : 1;
3085830911
}
3085930912
return sqlite3_os_type==2;
3086030913
}
30861
-#endif /* SQLITE_OS_WINCE */
30914
+#endif
3086230915
3086330916
#ifdef SQLITE_WIN32_MALLOC
3086430917
/*
3086530918
** Allocate nBytes of memory.
3086630919
*/
@@ -31066,11 +31119,11 @@
3106631119
3106731120
nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0);
3106831121
if( nChar==0 ){
3106931122
return 0;
3107031123
}
31071
- zWideFilename = sqlite3_malloc( nChar*sizeof(zWideFilename[0]) );
31124
+ zWideFilename = sqlite3MallocZero( nChar*sizeof(zWideFilename[0]) );
3107231125
if( zWideFilename==0 ){
3107331126
return 0;
3107431127
}
3107531128
nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, zWideFilename,
3107631129
nChar);
@@ -31091,11 +31144,11 @@
3109131144
3109231145
nByte = osWideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, 0, 0, 0, 0);
3109331146
if( nByte == 0 ){
3109431147
return 0;
3109531148
}
31096
- zFilename = sqlite3_malloc( nByte );
31149
+ zFilename = sqlite3MallocZero( nByte );
3109731150
if( zFilename==0 ){
3109831151
return 0;
3109931152
}
3110031153
nByte = osWideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, zFilename, nByte,
3110131154
0, 0);
@@ -31121,11 +31174,11 @@
3112131174
nByte = osMultiByteToWideChar(codepage, 0, zFilename, -1, NULL,
3112231175
0)*sizeof(WCHAR);
3112331176
if( nByte==0 ){
3112431177
return 0;
3112531178
}
31126
- zMbcsFilename = sqlite3_malloc( nByte*sizeof(zMbcsFilename[0]) );
31179
+ zMbcsFilename = sqlite3MallocZero( nByte*sizeof(zMbcsFilename[0]) );
3112731180
if( zMbcsFilename==0 ){
3112831181
return 0;
3112931182
}
3113031183
nByte = osMultiByteToWideChar(codepage, 0, zFilename, -1, zMbcsFilename,
3113131184
nByte);
@@ -31150,11 +31203,11 @@
3115031203
3115131204
nByte = osWideCharToMultiByte(codepage, 0, zWideFilename, -1, 0, 0, 0, 0);
3115231205
if( nByte == 0 ){
3115331206
return 0;
3115431207
}
31155
- zFilename = sqlite3_malloc( nByte );
31208
+ zFilename = sqlite3MallocZero( nByte );
3115631209
if( zFilename==0 ){
3115731210
return 0;
3115831211
}
3115931212
nByte = osWideCharToMultiByte(codepage, 0, zWideFilename, -1, zFilename,
3116031213
nByte, 0, 0);
@@ -32797,20 +32850,18 @@
3279732850
assert( pDbFd->pShm==0 ); /* Not previously opened */
3279832851
3279932852
/* Allocate space for the new sqlite3_shm object. Also speculatively
3280032853
** allocate space for a new winShmNode and filename.
3280132854
*/
32802
- p = sqlite3_malloc( sizeof(*p) );
32855
+ p = sqlite3MallocZero( sizeof(*p) );
3280332856
if( p==0 ) return SQLITE_IOERR_NOMEM;
32804
- memset(p, 0, sizeof(*p));
3280532857
nName = sqlite3Strlen30(pDbFd->zPath);
32806
- pNew = sqlite3_malloc( sizeof(*pShmNode) + nName + 17 );
32858
+ pNew = sqlite3MallocZero( sizeof(*pShmNode) + nName + 17 );
3280732859
if( pNew==0 ){
3280832860
sqlite3_free(p);
3280932861
return SQLITE_IOERR_NOMEM;
3281032862
}
32811
- memset(pNew, 0, sizeof(*pNew) + nName + 17);
3281232863
pNew->zFilename = (char*)&pNew[1];
3281332864
sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath);
3281432865
sqlite3FileSuffix3(pDbFd->zPath, pNew->zFilename);
3281532866
3281632867
/* Look to see if there is an existing winShmNode that can be used.
@@ -33143,21 +33194,25 @@
3314333194
goto shmpage_out;
3314433195
}
3314533196
pShmNode->aRegion = apNew;
3314633197
3314733198
while( pShmNode->nRegion<=iRegion ){
33148
- HANDLE hMap; /* file-mapping handle */
33199
+ HANDLE hMap = NULL; /* file-mapping handle */
3314933200
void *pMap = 0; /* Mapped memory region */
3315033201
3315133202
#if SQLITE_OS_WINRT
3315233203
hMap = osCreateFileMappingFromApp(pShmNode->hFile.h,
3315333204
NULL, PAGE_READWRITE, nByte, NULL
3315433205
);
33155
-#else
33206
+#elif defined(SQLITE_WIN32_HAS_WIDE)
3315633207
hMap = osCreateFileMappingW(pShmNode->hFile.h,
3315733208
NULL, PAGE_READWRITE, 0, nByte, NULL
3315833209
);
33210
+#elif defined(SQLITE_WIN32_HAS_ANSI)
33211
+ hMap = osCreateFileMappingA(pShmNode->hFile.h,
33212
+ NULL, PAGE_READWRITE, 0, nByte, NULL
33213
+ );
3315933214
#endif
3316033215
OSTRACE(("SHM-MAP pid-%d create region=%d nbyte=%d %s\n",
3316133216
(int)osGetCurrentProcessId(), pShmNode->nRegion, nByte,
3316233217
hMap ? "ok" : "failed"));
3316333218
if( hMap ){
@@ -33902,11 +33957,11 @@
3390233957
}
3390333958
return SQLITE_OK;
3390433959
#endif
3390533960
3390633961
#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(__CYGWIN__)
33907
- int nByte;
33962
+ DWORD nByte;
3390833963
void *zConverted;
3390933964
char *zOut;
3391033965
3391133966
/* If this path name begins with "/X:", where "X" is any alphabetic
3391233967
** character, discard the initial "/" from the pathname.
@@ -33936,31 +33991,59 @@
3393633991
if( zConverted==0 ){
3393733992
return SQLITE_IOERR_NOMEM;
3393833993
}
3393933994
if( isNT() ){
3394033995
LPWSTR zTemp;
33941
- nByte = osGetFullPathNameW((LPCWSTR)zConverted, 0, 0, 0) + 3;
33942
- zTemp = sqlite3_malloc( nByte*sizeof(zTemp[0]) );
33996
+ nByte = osGetFullPathNameW((LPCWSTR)zConverted, 0, 0, 0);
33997
+ if( nByte==0 ){
33998
+ winLogError(SQLITE_ERROR, osGetLastError(),
33999
+ "GetFullPathNameW1", zConverted);
34000
+ sqlite3_free(zConverted);
34001
+ return SQLITE_CANTOPEN_FULLPATH;
34002
+ }
34003
+ nByte += 3;
34004
+ zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) );
3394334005
if( zTemp==0 ){
3394434006
sqlite3_free(zConverted);
3394534007
return SQLITE_IOERR_NOMEM;
3394634008
}
33947
- osGetFullPathNameW((LPCWSTR)zConverted, nByte, zTemp, 0);
34009
+ nByte = osGetFullPathNameW((LPCWSTR)zConverted, nByte, zTemp, 0);
34010
+ if( nByte==0 ){
34011
+ winLogError(SQLITE_ERROR, osGetLastError(),
34012
+ "GetFullPathNameW2", zConverted);
34013
+ sqlite3_free(zConverted);
34014
+ sqlite3_free(zTemp);
34015
+ return SQLITE_CANTOPEN_FULLPATH;
34016
+ }
3394834017
sqlite3_free(zConverted);
3394934018
zOut = unicodeToUtf8(zTemp);
3395034019
sqlite3_free(zTemp);
3395134020
}
3395234021
#ifdef SQLITE_WIN32_HAS_ANSI
3395334022
else{
3395434023
char *zTemp;
33955
- nByte = osGetFullPathNameA((char*)zConverted, 0, 0, 0) + 3;
33956
- zTemp = sqlite3_malloc( nByte*sizeof(zTemp[0]) );
34024
+ nByte = osGetFullPathNameA((char*)zConverted, 0, 0, 0);
34025
+ if( nByte==0 ){
34026
+ winLogError(SQLITE_ERROR, osGetLastError(),
34027
+ "GetFullPathNameA1", zConverted);
34028
+ sqlite3_free(zConverted);
34029
+ return SQLITE_CANTOPEN_FULLPATH;
34030
+ }
34031
+ nByte += 3;
34032
+ zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) );
3395734033
if( zTemp==0 ){
3395834034
sqlite3_free(zConverted);
3395934035
return SQLITE_IOERR_NOMEM;
3396034036
}
33961
- osGetFullPathNameA((char*)zConverted, nByte, zTemp, 0);
34037
+ nByte = osGetFullPathNameA((char*)zConverted, nByte, zTemp, 0);
34038
+ if( nByte==0 ){
34039
+ winLogError(SQLITE_ERROR, osGetLastError(),
34040
+ "GetFullPathNameA2", zConverted);
34041
+ sqlite3_free(zConverted);
34042
+ sqlite3_free(zTemp);
34043
+ return SQLITE_CANTOPEN_FULLPATH;
34044
+ }
3396234045
sqlite3_free(zConverted);
3396334046
zOut = sqlite3_win32_mbcs_to_utf8(zTemp);
3396434047
sqlite3_free(zTemp);
3396534048
}
3396634049
#endif
@@ -34214,11 +34297,11 @@
3421434297
winNextSystemCall, /* xNextSystemCall */
3421534298
};
3421634299
3421734300
/* Double-check that the aSyscall[] array has been constructed
3421834301
** correctly. See ticket [bb3a86e890c8e96ab] */
34219
- assert( ArraySize(aSyscall)==73 );
34302
+ assert( ArraySize(aSyscall)==74 );
3422034303
3422134304
#ifndef SQLITE_OMIT_WAL
3422234305
/* get memory map allocation granularity */
3422334306
memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
3422434307
#if SQLITE_OS_WINRT
@@ -34233,11 +34316,11 @@
3423334316
return SQLITE_OK;
3423434317
}
3423534318
3423634319
SQLITE_API int sqlite3_os_end(void){
3423734320
#if SQLITE_OS_WINRT
34238
- if( sleepObj != NULL ){
34321
+ if( sleepObj!=NULL ){
3423934322
osCloseHandle(sleepObj);
3424034323
sleepObj = NULL;
3424134324
}
3424234325
#endif
3424334326
return SQLITE_OK;
@@ -41395,11 +41478,11 @@
4139541478
assert( nPathname>0 );
4139641479
pPager->zJournal = (char*)(pPtr += nPathname + 1 + nUri);
4139741480
memcpy(pPager->zFilename, zPathname, nPathname);
4139841481
if( nUri ) memcpy(&pPager->zFilename[nPathname+1], zUri, nUri);
4139941482
memcpy(pPager->zJournal, zPathname, nPathname);
41400
- memcpy(&pPager->zJournal[nPathname], "-journal\000", 8+1);
41483
+ memcpy(&pPager->zJournal[nPathname], "-journal\000", 8+2);
4140141484
sqlite3FileSuffix3(pPager->zFilename, pPager->zJournal);
4140241485
#ifndef SQLITE_OMIT_WAL
4140341486
pPager->zWal = &pPager->zJournal[nPathname+8+1];
4140441487
memcpy(pPager->zWal, zPathname, nPathname);
4140541488
memcpy(&pPager->zWal[nPathname], "-wal\000", 4+1);
@@ -58860,14 +58943,13 @@
5886058943
pOp->p4.pKeyInfo = pKeyInfo;
5886158944
if( pKeyInfo ){
5886258945
u8 *aSortOrder;
5886358946
memcpy((char*)pKeyInfo, zP4, nByte - nField);
5886458947
aSortOrder = pKeyInfo->aSortOrder;
58865
- if( aSortOrder ){
58866
- pKeyInfo->aSortOrder = (unsigned char*)&pKeyInfo->aColl[nField];
58867
- memcpy(pKeyInfo->aSortOrder, aSortOrder, nField);
58868
- }
58948
+ assert( aSortOrder!=0 );
58949
+ pKeyInfo->aSortOrder = (unsigned char*)&pKeyInfo->aColl[nField];
58950
+ memcpy(pKeyInfo->aSortOrder, aSortOrder, nField);
5886958951
pOp->p4type = P4_KEYINFO;
5887058952
}else{
5887158953
p->db->mallocFailed = 1;
5887258954
pOp->p4type = P4_NOTUSED;
5887358955
}
@@ -58976,10 +59058,11 @@
5897659058
switch( pOp->p4type ){
5897759059
case P4_KEYINFO_STATIC:
5897859060
case P4_KEYINFO: {
5897959061
int i, j;
5898059062
KeyInfo *pKeyInfo = pOp->p4.pKeyInfo;
59063
+ assert( pKeyInfo->aSortOrder!=0 );
5898159064
sqlite3_snprintf(nTemp, zTemp, "keyinfo(%d", pKeyInfo->nField);
5898259065
i = sqlite3Strlen30(zTemp);
5898359066
for(j=0; j<pKeyInfo->nField; j++){
5898459067
CollSeq *pColl = pKeyInfo->aColl[j];
5898559068
if( pColl ){
@@ -58987,11 +59070,11 @@
5898759070
if( i+n>nTemp-6 ){
5898859071
memcpy(&zTemp[i],",...",4);
5898959072
break;
5899059073
}
5899159074
zTemp[i++] = ',';
58992
- if( pKeyInfo->aSortOrder && pKeyInfo->aSortOrder[j] ){
59075
+ if( pKeyInfo->aSortOrder[j] ){
5899359076
zTemp[i++] = '-';
5899459077
}
5899559078
memcpy(&zTemp[i], pColl->zName,n+1);
5899659079
i += n;
5899759080
}else if( i+4<nTemp-6 ){
@@ -60698,21 +60781,20 @@
6069860781
if( flags&MEM_Int ){
6069960782
/* Figure out whether to use 1, 2, 4, 6 or 8 bytes. */
6070060783
# define MAX_6BYTE ((((i64)0x00008000)<<32)-1)
6070160784
i64 i = pMem->u.i;
6070260785
u64 u;
60703
- if( file_format>=4 && (i&1)==i ){
60704
- return 8+(u32)i;
60705
- }
6070660786
if( i<0 ){
6070760787
if( i<(-MAX_6BYTE) ) return 6;
6070860788
/* Previous test prevents: u = -(-9223372036854775808) */
6070960789
u = -i;
6071060790
}else{
6071160791
u = i;
6071260792
}
60713
- if( u<=127 ) return 1;
60793
+ if( u<=127 ){
60794
+ return ((i&1)==i && file_format>=4) ? 8+(u32)u : 1;
60795
+ }
6071460796
if( u<=32767 ) return 2;
6071560797
if( u<=8388607 ) return 3;
6071660798
if( u<=2147483647 ) return 4;
6071760799
if( u<=MAX_6BYTE ) return 5;
6071860800
return 6;
@@ -60993,10 +61075,11 @@
6099361075
p = (UnpackedRecord*)&pSpace[nOff];
6099461076
*ppFree = 0;
6099561077
}
6099661078
6099761079
p->aMem = (Mem*)&((char*)p)[ROUND8(sizeof(UnpackedRecord))];
61080
+ assert( pKeyInfo->aSortOrder!=0 );
6099861081
p->pKeyInfo = pKeyInfo;
6099961082
p->nField = pKeyInfo->nField + 1;
6100061083
return p;
6100161084
}
6100261085
@@ -61086,10 +61169,11 @@
6108661169
/* mem1.u.i = 0; // not needed, here to silence compiler warning */
6108761170
6108861171
idx1 = getVarint32(aKey1, szHdr1);
6108961172
d1 = szHdr1;
6109061173
nField = pKeyInfo->nField;
61174
+ assert( pKeyInfo->aSortOrder!=0 );
6109161175
while( idx1<szHdr1 && i<pPKey2->nField ){
6109261176
u32 serial_type1;
6109361177
6109461178
/* Read the serial types for the next element in each key. */
6109561179
idx1 += getVarint32( aKey1+idx1, serial_type1 );
@@ -61105,11 +61189,11 @@
6110561189
i<nField ? pKeyInfo->aColl[i] : 0);
6110661190
if( rc!=0 ){
6110761191
assert( mem1.zMalloc==0 ); /* See comment below */
6110861192
6110961193
/* Invert the result if we are using DESC sort order. */
61110
- if( pKeyInfo->aSortOrder && i<nField && pKeyInfo->aSortOrder[i] ){
61194
+ if( i<nField && pKeyInfo->aSortOrder[i] ){
6111161195
rc = -rc;
6111261196
}
6111361197
6111461198
/* If the PREFIX_SEARCH flag is set and all fields except the final
6111561199
** rowid field were equal, then clear the PREFIX_SEARCH flag and set
@@ -61831,14 +61915,16 @@
6183161915
if( vdbeSafetyNotNull(v) ){
6183261916
return SQLITE_MISUSE_BKPT;
6183361917
}
6183461918
db = v->db;
6183561919
sqlite3_mutex_enter(db->mutex);
61920
+ v->doingRerun = 0;
6183661921
while( (rc = sqlite3Step(v))==SQLITE_SCHEMA
6183761922
&& cnt++ < SQLITE_MAX_SCHEMA_RETRY
6183861923
&& (rc2 = rc = sqlite3Reprepare(v))==SQLITE_OK ){
6183961924
sqlite3_reset(pStmt);
61925
+ v->doingRerun = 1;
6184061926
assert( v->expired==0 );
6184161927
}
6184261928
if( rc2!=SQLITE_OK && ALWAYS(v->isPrepareV2) && ALWAYS(db->pErr) ){
6184361929
/* This case occurs after failing to recompile an sql statement.
6184461930
** The error message from the SQL compiler has already been loaded
@@ -63957,11 +64043,10 @@
6395764043
struct OP_JournalMode_stack_vars {
6395864044
Btree *pBt; /* Btree to change journal mode of */
6395964045
Pager *pPager; /* Pager associated with pBt */
6396064046
int eNew; /* New journal mode */
6396164047
int eOld; /* The old journal mode */
63962
- const char *zFilename; /* Name of database file for pPager */
6396364048
} ci;
6396464049
struct OP_IncrVacuum_stack_vars {
6396564050
Btree *pBt;
6396664051
} cj;
6396764052
struct OP_VBegin_stack_vars {
@@ -69061,12 +69146,14 @@
6906169146
#if 0 /* local variables moved into u.ci */
6906269147
Btree *pBt; /* Btree to change journal mode of */
6906369148
Pager *pPager; /* Pager associated with pBt */
6906469149
int eNew; /* New journal mode */
6906569150
int eOld; /* The old journal mode */
69066
- const char *zFilename; /* Name of database file for pPager */
6906769151
#endif /* local variables moved into u.ci */
69152
+#ifndef SQLITE_OMIT_WAL
69153
+ const char *zFilename; /* Name of database file for u.ci.pPager */
69154
+#endif
6906869155
6906969156
u.ci.eNew = pOp->p3;
6907069157
assert( u.ci.eNew==PAGER_JOURNALMODE_DELETE
6907169158
|| u.ci.eNew==PAGER_JOURNALMODE_TRUNCATE
6907269159
|| u.ci.eNew==PAGER_JOURNALMODE_PERSIST
@@ -69082,17 +69169,17 @@
6908269169
u.ci.eOld = sqlite3PagerGetJournalMode(u.ci.pPager);
6908369170
if( u.ci.eNew==PAGER_JOURNALMODE_QUERY ) u.ci.eNew = u.ci.eOld;
6908469171
if( !sqlite3PagerOkToChangeJournalMode(u.ci.pPager) ) u.ci.eNew = u.ci.eOld;
6908569172
6908669173
#ifndef SQLITE_OMIT_WAL
69087
- u.ci.zFilename = sqlite3PagerFilename(u.ci.pPager, 1);
69174
+ zFilename = sqlite3PagerFilename(u.ci.pPager, 1);
6908869175
6908969176
/* Do not allow a transition to journal_mode=WAL for a database
6909069177
** in temporary storage or if the VFS does not support shared memory
6909169178
*/
6909269179
if( u.ci.eNew==PAGER_JOURNALMODE_WAL
69093
- && (sqlite3Strlen30(u.ci.zFilename)==0 /* Temp file */
69180
+ && (sqlite3Strlen30(zFilename)==0 /* Temp file */
6909469181
|| !sqlite3PagerWalSupported(u.ci.pPager)) /* No shared-memory support */
6909569182
){
6909669183
u.ci.eNew = u.ci.eOld;
6909769184
}
6909869185
@@ -69660,11 +69747,14 @@
6966069747
#if 0 /* local variables moved into u.cr */
6966169748
char *zTrace;
6966269749
char *z;
6966369750
#endif /* local variables moved into u.cr */
6966469751
69665
- if( db->xTrace && (u.cr.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 ){
69752
+ if( db->xTrace
69753
+ && !p->doingRerun
69754
+ && (u.cr.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
69755
+ ){
6966669756
u.cr.z = sqlite3VdbeExpandSql(p, u.cr.zTrace);
6966769757
db->xTrace(db->pTraceArg, u.cr.z);
6966869758
sqlite3DbFree(db, u.cr.z);
6966969759
}
6967069760
#ifdef SQLITE_DEBUG
@@ -74885,10 +74975,11 @@
7488574975
7488674976
switch( pExpr->op ){
7488774977
case TK_IN: {
7488874978
char affinity; /* Affinity of the LHS of the IN */
7488974979
KeyInfo keyInfo; /* Keyinfo for the generated table */
74980
+ static u8 sortOrder = 0; /* Fake aSortOrder for keyInfo */
7489074981
int addr; /* Address of OP_OpenEphemeral instruction */
7489174982
Expr *pLeft = pExpr->pLeft; /* the LHS of the IN operator */
7489274983
7489374984
if( rMayHaveNull ){
7489474985
sqlite3VdbeAddOp2(v, OP_Null, 0, rMayHaveNull);
@@ -74912,10 +75003,11 @@
7491275003
pExpr->iTable = pParse->nTab++;
7491375004
addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, !isRowid);
7491475005
if( rMayHaveNull==0 ) sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
7491575006
memset(&keyInfo, 0, sizeof(keyInfo));
7491675007
keyInfo.nField = 1;
75008
+ keyInfo.aSortOrder = &sortOrder;
7491775009
7491875010
if( ExprHasProperty(pExpr, EP_xIsSelect) ){
7491975011
/* Case 1: expr IN (SELECT ...)
7492075012
**
7492175013
** Generate code to write the results of the select into the temporary
@@ -74952,10 +75044,11 @@
7495275044
7495375045
if( !affinity ){
7495475046
affinity = SQLITE_AFF_NONE;
7495575047
}
7495675048
keyInfo.aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
75049
+ keyInfo.aSortOrder = &sortOrder;
7495775050
7495875051
/* Loop through each expression in <exprlist>. */
7495975052
r1 = sqlite3GetTempReg(pParse);
7496075053
r2 = sqlite3GetTempReg(pParse);
7496175054
sqlite3VdbeAddOp2(v, OP_Null, 0, r2);
@@ -78030,11 +78123,11 @@
7803078123
7803178124
/* Check that the new column is not specified as PRIMARY KEY or UNIQUE.
7803278125
** If there is a NOT NULL constraint, then the default value for the
7803378126
** column must not be NULL.
7803478127
*/
78035
- if( pCol->isPrimKey ){
78128
+ if( pCol->colFlags & COLFLAG_PRIMKEY ){
7803678129
sqlite3ErrorMsg(pParse, "Cannot add a PRIMARY KEY column");
7803778130
return;
7803878131
}
7803978132
if( pNew->pIndex ){
7804078133
sqlite3ErrorMsg(pParse, "Cannot add a UNIQUE column");
@@ -81299,20 +81392,20 @@
8129981392
goto primary_key_exit;
8130081393
}
8130181394
pTab->tabFlags |= TF_HasPrimaryKey;
8130281395
if( pList==0 ){
8130381396
iCol = pTab->nCol - 1;
81304
- pTab->aCol[iCol].isPrimKey = 1;
81397
+ pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY;
8130581398
}else{
8130681399
for(i=0; i<pList->nExpr; i++){
8130781400
for(iCol=0; iCol<pTab->nCol; iCol++){
8130881401
if( sqlite3StrICmp(pList->a[i].zName, pTab->aCol[iCol].zName)==0 ){
8130981402
break;
8131081403
}
8131181404
}
8131281405
if( iCol<pTab->nCol ){
81313
- pTab->aCol[iCol].isPrimKey = 1;
81406
+ pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY;
8131481407
}
8131581408
}
8131681409
if( pList->nExpr>1 ) iCol = -1;
8131781410
}
8131881411
if( iCol>=0 && iCol<pTab->nCol ){
@@ -85468,37 +85561,18 @@
8546885561
sqlite3_result_text(context, z1, n, sqlite3_free);
8546985562
}
8547085563
}
8547185564
}
8547285565
85473
-
85474
-#if 0 /* This function is never used. */
85475
-/*
85476
-** The COALESCE() and IFNULL() functions used to be implemented as shown
85477
-** here. But now they are implemented as VDBE code so that unused arguments
85478
-** do not have to be computed. This legacy implementation is retained as
85479
-** comment.
85480
-*/
85481
-/*
85482
-** Implementation of the IFNULL(), NVL(), and COALESCE() functions.
85483
-** All three do the same thing. They return the first non-NULL
85484
-** argument.
85485
-*/
85486
-static void ifnullFunc(
85487
- sqlite3_context *context,
85488
- int argc,
85489
- sqlite3_value **argv
85490
-){
85491
- int i;
85492
- for(i=0; i<argc; i++){
85493
- if( SQLITE_NULL!=sqlite3_value_type(argv[i]) ){
85494
- sqlite3_result_value(context, argv[i]);
85495
- break;
85496
- }
85497
- }
85498
-}
85499
-#endif /* NOT USED */
85566
+/*
85567
+** The COALESCE() and IFNULL() functions are implemented as VDBE code so
85568
+** that unused argument values do not have to be computed. However, we
85569
+** still need some kind of function implementation for this routines in
85570
+** the function table. That function implementation will never be called
85571
+** so it doesn't matter what the implementation is. We might as well use
85572
+** the "version()" function as a substitute.
85573
+*/
8550085574
#define ifnullFunc versionFunc /* Substitute function - never called */
8550185575
8550285576
/*
8550385577
** Implementation of random(). Return a random integer.
8550485578
*/
@@ -85613,11 +85687,11 @@
8561385687
** character is exactly one byte in size. Also, all characters are
8561485688
** able to participate in upper-case-to-lower-case mappings in EBCDIC
8561585689
** whereas only characters less than 0x80 do in ASCII.
8561685690
*/
8561785691
#if defined(SQLITE_EBCDIC)
85618
-# define sqlite3Utf8Read(A,C) (*(A++))
85692
+# define sqlite3Utf8Read(A) (*((*A)++))
8561985693
# define GlogUpperToLower(A) A = sqlite3UpperToLower[A]
8562085694
#else
8562185695
# define GlogUpperToLower(A) if( !((A)&~0x7f) ){ A = sqlite3UpperToLower[A]; }
8562285696
#endif
8562385697
@@ -85670,22 +85744,22 @@
8567085744
u8 matchAll = pInfo->matchAll;
8567185745
u8 matchSet = pInfo->matchSet;
8567285746
u8 noCase = pInfo->noCase;
8567385747
int prevEscape = 0; /* True if the previous character was 'escape' */
8567485748
85675
- while( (c = sqlite3Utf8Read(zPattern,&zPattern))!=0 ){
85676
- if( !prevEscape && c==matchAll ){
85677
- while( (c=sqlite3Utf8Read(zPattern,&zPattern)) == matchAll
85749
+ while( (c = sqlite3Utf8Read(&zPattern))!=0 ){
85750
+ if( c==matchAll && !prevEscape ){
85751
+ while( (c=sqlite3Utf8Read(&zPattern)) == matchAll
8567885752
|| c == matchOne ){
85679
- if( c==matchOne && sqlite3Utf8Read(zString, &zString)==0 ){
85753
+ if( c==matchOne && sqlite3Utf8Read(&zString)==0 ){
8568085754
return 0;
8568185755
}
8568285756
}
8568385757
if( c==0 ){
8568485758
return 1;
8568585759
}else if( c==esc ){
85686
- c = sqlite3Utf8Read(zPattern, &zPattern);
85760
+ c = sqlite3Utf8Read(&zPattern);
8568785761
if( c==0 ){
8568885762
return 0;
8568985763
}
8569085764
}else if( c==matchSet ){
8569185765
assert( esc==0 ); /* This is GLOB, not LIKE */
@@ -85693,67 +85767,67 @@
8569385767
while( *zString && patternCompare(&zPattern[-1],zString,pInfo,esc)==0 ){
8569485768
SQLITE_SKIP_UTF8(zString);
8569585769
}
8569685770
return *zString!=0;
8569785771
}
85698
- while( (c2 = sqlite3Utf8Read(zString,&zString))!=0 ){
85772
+ while( (c2 = sqlite3Utf8Read(&zString))!=0 ){
8569985773
if( noCase ){
8570085774
GlogUpperToLower(c2);
8570185775
GlogUpperToLower(c);
8570285776
while( c2 != 0 && c2 != c ){
85703
- c2 = sqlite3Utf8Read(zString, &zString);
85777
+ c2 = sqlite3Utf8Read(&zString);
8570485778
GlogUpperToLower(c2);
8570585779
}
8570685780
}else{
8570785781
while( c2 != 0 && c2 != c ){
85708
- c2 = sqlite3Utf8Read(zString, &zString);
85782
+ c2 = sqlite3Utf8Read(&zString);
8570985783
}
8571085784
}
8571185785
if( c2==0 ) return 0;
8571285786
if( patternCompare(zPattern,zString,pInfo,esc) ) return 1;
8571385787
}
8571485788
return 0;
85715
- }else if( !prevEscape && c==matchOne ){
85716
- if( sqlite3Utf8Read(zString, &zString)==0 ){
85789
+ }else if( c==matchOne && !prevEscape ){
85790
+ if( sqlite3Utf8Read(&zString)==0 ){
8571785791
return 0;
8571885792
}
8571985793
}else if( c==matchSet ){
8572085794
u32 prior_c = 0;
8572185795
assert( esc==0 ); /* This only occurs for GLOB, not LIKE */
8572285796
seen = 0;
8572385797
invert = 0;
85724
- c = sqlite3Utf8Read(zString, &zString);
85798
+ c = sqlite3Utf8Read(&zString);
8572585799
if( c==0 ) return 0;
85726
- c2 = sqlite3Utf8Read(zPattern, &zPattern);
85800
+ c2 = sqlite3Utf8Read(&zPattern);
8572785801
if( c2=='^' ){
8572885802
invert = 1;
85729
- c2 = sqlite3Utf8Read(zPattern, &zPattern);
85803
+ c2 = sqlite3Utf8Read(&zPattern);
8573085804
}
8573185805
if( c2==']' ){
8573285806
if( c==']' ) seen = 1;
85733
- c2 = sqlite3Utf8Read(zPattern, &zPattern);
85807
+ c2 = sqlite3Utf8Read(&zPattern);
8573485808
}
8573585809
while( c2 && c2!=']' ){
8573685810
if( c2=='-' && zPattern[0]!=']' && zPattern[0]!=0 && prior_c>0 ){
85737
- c2 = sqlite3Utf8Read(zPattern, &zPattern);
85811
+ c2 = sqlite3Utf8Read(&zPattern);
8573885812
if( c>=prior_c && c<=c2 ) seen = 1;
8573985813
prior_c = 0;
8574085814
}else{
8574185815
if( c==c2 ){
8574285816
seen = 1;
8574385817
}
8574485818
prior_c = c2;
8574585819
}
85746
- c2 = sqlite3Utf8Read(zPattern, &zPattern);
85820
+ c2 = sqlite3Utf8Read(&zPattern);
8574785821
}
8574885822
if( c2==0 || (seen ^ invert)==0 ){
8574985823
return 0;
8575085824
}
8575185825
}else if( esc==c && !prevEscape ){
8575285826
prevEscape = 1;
8575385827
}else{
85754
- c2 = sqlite3Utf8Read(zString, &zString);
85828
+ c2 = sqlite3Utf8Read(&zString);
8575585829
if( noCase ){
8575685830
GlogUpperToLower(c);
8575785831
GlogUpperToLower(c2);
8575885832
}
8575985833
if( c!=c2 ){
@@ -85821,11 +85895,11 @@
8582185895
if( sqlite3Utf8CharLen((char*)zEsc, -1)!=1 ){
8582285896
sqlite3_result_error(context,
8582385897
"ESCAPE expression must be a single character", -1);
8582485898
return;
8582585899
}
85826
- escape = sqlite3Utf8Read(zEsc, &zEsc);
85900
+ escape = sqlite3Utf8Read(&zEsc);
8582785901
}
8582885902
if( zA && zB ){
8582985903
struct compareInfo *pInfo = sqlite3_user_data(context);
8583085904
#ifdef SQLITE_TEST
8583185905
sqlite3_like_count++;
@@ -87653,11 +87727,12 @@
8765387727
for(i=0; i<p->nCol; i++){
8765487728
char *zKey = p->aCol[i].zCol;
8765587729
int iKey;
8765687730
for(iKey=0; iKey<pTab->nCol; iKey++){
8765787731
Column *pCol = &pTab->aCol[iKey];
87658
- if( (zKey ? !sqlite3StrICmp(pCol->zName, zKey) : pCol->isPrimKey) ){
87732
+ if( (zKey ? !sqlite3StrICmp(pCol->zName, zKey)
87733
+ : (pCol->colFlags & COLFLAG_PRIMKEY)!=0) ){
8765987734
if( aChange[iKey]>=0 ) return 1;
8766087735
if( iKey==pTab->iPKey && chngRowid ) return 1;
8766187736
}
8766287737
}
8766387738
}
@@ -88268,10 +88343,101 @@
8826888343
*/
8826988344
# define autoIncBegin(A,B,C) (0)
8827088345
# define autoIncStep(A,B,C)
8827188346
#endif /* SQLITE_OMIT_AUTOINCREMENT */
8827288347
88348
+
88349
+/*
88350
+** Generate code for a co-routine that will evaluate a subquery one
88351
+** row at a time.
88352
+**
88353
+** The pSelect parameter is the subquery that the co-routine will evaluation.
88354
+** Information about the location of co-routine and the registers it will use
88355
+** is returned by filling in the pDest object.
88356
+**
88357
+** Registers are allocated as follows:
88358
+**
88359
+** pDest->iSDParm The register holding the next entry-point of the
88360
+** co-routine. Run the co-routine to its next breakpoint
88361
+** by calling "OP_Yield $X" where $X is pDest->iSDParm.
88362
+**
88363
+** pDest->iSDParm+1 The register holding the "completed" flag for the
88364
+** co-routine. This register is 0 if the previous Yield
88365
+** generated a new result row, or 1 if the subquery
88366
+** has completed. If the Yield is called again
88367
+** after this register becomes 1, then the VDBE will
88368
+** halt with an SQLITE_INTERNAL error.
88369
+**
88370
+** pDest->iSdst First result register.
88371
+**
88372
+** pDest->nSdst Number of result registers.
88373
+**
88374
+** This routine handles all of the register allocation and fills in the
88375
+** pDest structure appropriately.
88376
+**
88377
+** Here is a schematic of the generated code assuming that X is the
88378
+** co-routine entry-point register reg[pDest->iSDParm], that EOF is the
88379
+** completed flag reg[pDest->iSDParm+1], and R and S are the range of
88380
+** registers that hold the result set, reg[pDest->iSdst] through
88381
+** reg[pDest->iSdst+pDest->nSdst-1]:
88382
+**
88383
+** X <- A
88384
+** EOF <- 0
88385
+** goto B
88386
+** A: setup for the SELECT
88387
+** loop rows in the SELECT
88388
+** load results into registers R..S
88389
+** yield X
88390
+** end loop
88391
+** cleanup after the SELECT
88392
+** EOF <- 1
88393
+** yield X
88394
+** halt-error
88395
+** B:
88396
+**
88397
+** To use this subroutine, the caller generates code as follows:
88398
+**
88399
+** [ Co-routine generated by this subroutine, shown above ]
88400
+** S: yield X
88401
+** if EOF goto E
88402
+** if skip this row, goto C
88403
+** if terminate loop, goto E
88404
+** deal with this row
88405
+** C: goto S
88406
+** E:
88407
+*/
88408
+SQLITE_PRIVATE int sqlite3CodeCoroutine(Parse *pParse, Select *pSelect, SelectDest *pDest){
88409
+ int regYield; /* Register holding co-routine entry-point */
88410
+ int regEof; /* Register holding co-routine completion flag */
88411
+ int addrTop; /* Top of the co-routine */
88412
+ int j1; /* Jump instruction */
88413
+ int rc; /* Result code */
88414
+ Vdbe *v; /* VDBE under construction */
88415
+
88416
+ regYield = ++pParse->nMem;
88417
+ regEof = ++pParse->nMem;
88418
+ v = sqlite3GetVdbe(pParse);
88419
+ addrTop = sqlite3VdbeCurrentAddr(v);
88420
+ sqlite3VdbeAddOp2(v, OP_Integer, addrTop+2, regYield); /* X <- A */
88421
+ VdbeComment((v, "Co-routine entry point"));
88422
+ sqlite3VdbeAddOp2(v, OP_Integer, 0, regEof); /* EOF <- 0 */
88423
+ VdbeComment((v, "Co-routine completion flag"));
88424
+ sqlite3SelectDestInit(pDest, SRT_Coroutine, regYield);
88425
+ j1 = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);
88426
+ rc = sqlite3Select(pParse, pSelect, pDest);
88427
+ assert( pParse->nErr==0 || rc );
88428
+ if( pParse->db->mallocFailed && rc==SQLITE_OK ) rc = SQLITE_NOMEM;
88429
+ if( rc ) return rc;
88430
+ sqlite3VdbeAddOp2(v, OP_Integer, 1, regEof); /* EOF <- 1 */
88431
+ sqlite3VdbeAddOp1(v, OP_Yield, regYield); /* yield X */
88432
+ sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_INTERNAL, OE_Abort);
88433
+ VdbeComment((v, "End of coroutine"));
88434
+ sqlite3VdbeJumpHere(v, j1); /* label B: */
88435
+ return rc;
88436
+}
88437
+
88438
+
8827388439
8827488440
/* Forward declaration */
8827588441
static int xferOptimization(
8827688442
Parse *pParse, /* Parser context */
8827788443
Table *pDest, /* The table we are inserting into */
@@ -88517,55 +88683,16 @@
8851788683
** is coming from a SELECT statement, then generate a co-routine that
8851888684
** produces a single row of the SELECT on each invocation. The
8851988685
** co-routine is the common header to the 3rd and 4th templates.
8852088686
*/
8852188687
if( pSelect ){
88522
- /* Data is coming from a SELECT. Generate code to implement that SELECT
88523
- ** as a co-routine. The code is common to both the 3rd and 4th
88524
- ** templates:
88525
- **
88526
- ** EOF <- 0
88527
- ** X <- A
88528
- ** goto B
88529
- ** A: setup for the SELECT
88530
- ** loop over the tables in the SELECT
88531
- ** load value into register R..R+n
88532
- ** yield X
88533
- ** end loop
88534
- ** cleanup after the SELECT
88535
- ** EOF <- 1
88536
- ** yield X
88537
- ** halt-error
88538
- **
88539
- ** On each invocation of the co-routine, it puts a single row of the
88540
- ** SELECT result into registers dest.iMem...dest.iMem+dest.nMem-1.
88541
- ** (These output registers are allocated by sqlite3Select().) When
88542
- ** the SELECT completes, it sets the EOF flag stored in regEof.
88543
- */
88544
- int rc, j1;
88545
-
88546
- regEof = ++pParse->nMem;
88547
- sqlite3VdbeAddOp2(v, OP_Integer, 0, regEof); /* EOF <- 0 */
88548
- VdbeComment((v, "SELECT eof flag"));
88549
- sqlite3SelectDestInit(&dest, SRT_Coroutine, ++pParse->nMem);
88550
- addrSelect = sqlite3VdbeCurrentAddr(v)+2;
88551
- sqlite3VdbeAddOp2(v, OP_Integer, addrSelect-1, dest.iSDParm);
88552
- j1 = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);
88553
- VdbeComment((v, "Jump over SELECT coroutine"));
88554
-
88555
- /* Resolve the expressions in the SELECT statement and execute it. */
88556
- rc = sqlite3Select(pParse, pSelect, &dest);
88557
- assert( pParse->nErr==0 || rc );
88558
- if( rc || NEVER(pParse->nErr) || db->mallocFailed ){
88559
- goto insert_cleanup;
88560
- }
88561
- sqlite3VdbeAddOp2(v, OP_Integer, 1, regEof); /* EOF <- 1 */
88562
- sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm); /* yield X */
88563
- sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_INTERNAL, OE_Abort);
88564
- VdbeComment((v, "End of SELECT coroutine"));
88565
- sqlite3VdbeJumpHere(v, j1); /* label B: */
88566
-
88688
+ /* Data is coming from a SELECT. Generate a co-routine to run that
88689
+ ** SELECT. */
88690
+ int rc = sqlite3CodeCoroutine(pParse, pSelect, &dest);
88691
+ if( rc ) goto insert_cleanup;
88692
+
88693
+ regEof = dest.iSDParm + 1;
8856788694
regFromSelect = dest.iSdst;
8856888695
assert( pSelect->pEList );
8856988696
nColumn = pSelect->pEList->nExpr;
8857088697
assert( dest.nSdst==nColumn );
8857188698
@@ -92035,11 +92162,12 @@
9203592162
if( pCol->zDflt ){
9203692163
sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, (char*)pCol->zDflt, 0);
9203792164
}else{
9203892165
sqlite3VdbeAddOp2(v, OP_Null, 0, 5);
9203992166
}
92040
- sqlite3VdbeAddOp2(v, OP_Integer, pCol->isPrimKey, 6);
92167
+ sqlite3VdbeAddOp2(v, OP_Integer,
92168
+ (pCol->colFlags&COLFLAG_PRIMKEY)!=0, 6);
9204192169
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
9204292170
}
9204392171
}
9204492172
}else
9204592173
@@ -94803,11 +94931,11 @@
9480394931
** store NULL in *paCol and 0 in *pnCol and return SQLITE_NOMEM.
9480494932
*/
9480594933
static int selectColumnsFromExprList(
9480694934
Parse *pParse, /* Parsing context */
9480794935
ExprList *pEList, /* Expr list from which to derive column names */
94808
- int *pnCol, /* Write the number of columns here */
94936
+ i16 *pnCol, /* Write the number of columns here */
9480994937
Column **paCol /* Write the new column list here */
9481094938
){
9481194939
sqlite3 *db = pParse->db; /* Database connection */
9481294940
int i, j; /* Loop counters */
9481394941
int cnt; /* Index added to make the name unique */
@@ -95449,10 +95577,11 @@
9544995577
*apColl = multiSelectCollSeq(pParse, p, i);
9545095578
if( 0==*apColl ){
9545195579
*apColl = db->pDfltColl;
9545295580
}
9545395581
}
95582
+ pKeyInfo->aSortOrder = (u8*)apColl;
9545495583
9545595584
for(pLoop=p; pLoop; pLoop=pLoop->pPrior){
9545695585
for(i=0; i<2; i++){
9545795586
int addr = pLoop->addrOpenEphm[i];
9545895587
if( addr<0 ){
@@ -101068,11 +101197,11 @@
101068101197
}else{
101069101198
int iCol;
101070101199
/* If everything went according to plan, link the new VTable structure
101071101200
** into the linked list headed by pTab->pVTable. Then loop through the
101072101201
** columns of the table to see if any of them contain the token "hidden".
101073
- ** If so, set the Column.isHidden flag and remove the token from
101202
+ ** If so, set the Column COLFLAG_HIDDEN flag and remove the token from
101074101203
** the type string. */
101075101204
pVTable->pNext = pTab->pVTable;
101076101205
pTab->pVTable = pVTable;
101077101206
101078101207
for(iCol=0; iCol<pTab->nCol; iCol++){
@@ -101099,11 +101228,11 @@
101099101228
}
101100101229
if( zType[i]=='\0' && i>0 ){
101101101230
assert(zType[i-1]==' ');
101102101231
zType[i-1] = '\0';
101103101232
}
101104
- pTab->aCol[iCol].isHidden = 1;
101233
+ pTab->aCol[iCol].colFlags |= COLFLAG_HIDDEN;
101105101234
}
101106101235
}
101107101236
}
101108101237
}
101109101238
@@ -101901,10 +102030,11 @@
101901102030
#define WHERE_UNIQUE 0x04000000 /* Selects no more than one row */
101902102031
#define WHERE_VIRTUALTABLE 0x08000000 /* Use virtual-table processing */
101903102032
#define WHERE_MULTI_OR 0x10000000 /* OR using multiple indices */
101904102033
#define WHERE_TEMP_INDEX 0x20000000 /* Uses an ephemeral index */
101905102034
#define WHERE_DISTINCT 0x40000000 /* Correct order for DISTINCT */
102035
+#define WHERE_COVER_SCAN 0x80000000 /* Full scan of a covering index */
101906102036
101907102037
/*
101908102038
** Initialize a preallocated WhereClause structure.
101909102039
*/
101910102040
static void whereClauseInit(
@@ -104770,11 +104900,11 @@
104770104900
/* If currently calculating the cost of using an index (not the IPK
104771104901
** index), determine if all required column data may be obtained without
104772104902
** using the main table (i.e. if the index is a covering
104773104903
** index for this query). If it is, set the WHERE_IDX_ONLY flag in
104774104904
** wsFlags. Otherwise, set the bLookup variable to true. */
104775
- if( pIdx && wsFlags ){
104905
+ if( pIdx ){
104776104906
Bitmask m = pSrc->colUsed;
104777104907
int j;
104778104908
for(j=0; j<pIdx->nColumn; j++){
104779104909
int x = pIdx->aiColumn[j];
104780104910
if( x<BMS-1 ){
@@ -104835,11 +104965,24 @@
104835104965
** The ANALYZE command and the sqlite_stat1 and sqlite_stat3 tables do
104836104966
** not give us data on the relative sizes of table and index records.
104837104967
** So this computation assumes table records are about twice as big
104838104968
** as index records
104839104969
*/
104840
- if( (wsFlags & WHERE_NOT_FULLSCAN)==0 ){
104970
+ if( wsFlags==WHERE_IDX_ONLY
104971
+ && (pWC->wctrlFlags & WHERE_ONEPASS_DESIRED)==0
104972
+ && sqlite3GlobalConfig.bUseCis
104973
+#ifndef SQLITE_OMIT_BUILTIN_TEST
104974
+ && (pParse->db->flags & SQLITE_CoverIdxScan)==0
104975
+#endif
104976
+ ){
104977
+ /* This index is not useful for indexing, but it is a covering index.
104978
+ ** A full-scan of the index might be a little faster than a full-scan
104979
+ ** of the table, so give this case a cost slightly less than a table
104980
+ ** scan. */
104981
+ cost = aiRowEst[0]*3 + pProbe->nColumn;
104982
+ wsFlags |= WHERE_COVER_SCAN|WHERE_COLUMN_RANGE;
104983
+ }else if( (wsFlags & WHERE_NOT_FULLSCAN)==0 ){
104841104984
/* The cost of a full table scan is a number of move operations equal
104842104985
** to the number of rows in the table.
104843104986
**
104844104987
** We add an additional 4x penalty to full table scans. This causes
104845104988
** the cost function to err on the side of choosing an index over
@@ -104846,10 +104989,11 @@
104846104989
** choosing a full scan. This 4x full-scan penalty is an arguable
104847104990
** decision and one which we expect to revisit in the future. But
104848104991
** it seems to be working well enough at the moment.
104849104992
*/
104850104993
cost = aiRowEst[0]*4;
104994
+ wsFlags &= ~WHERE_IDX_ONLY;
104851104995
}else{
104852104996
log10N = estLog(aiRowEst[0]);
104853104997
cost = nRow;
104854104998
if( pIdx ){
104855104999
if( bLookup ){
@@ -105889,10 +106033,15 @@
105889106033
pLevel->op = OP_Prev;
105890106034
}else{
105891106035
pLevel->op = OP_Next;
105892106036
}
105893106037
pLevel->p1 = iIdxCur;
106038
+ if( pLevel->plan.wsFlags & WHERE_COVER_SCAN ){
106039
+ pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
106040
+ }else{
106041
+ assert( pLevel->p5==0 );
106042
+ }
105894106043
}else
105895106044
105896106045
#ifndef SQLITE_OMIT_OR_OPTIMIZATION
105897106046
if( pLevel->plan.wsFlags & WHERE_MULTI_OR ){
105898106047
/* Case 4: Two or more separately indexed terms connected by OR
@@ -106765,31 +106914,33 @@
106765106914
** index name is '*'.
106766106915
*/
106767106916
for(i=0; i<nTabList; i++){
106768106917
char *z;
106769106918
int n;
106919
+ int w;
106770106920
pLevel = &pWInfo->a[i];
106921
+ w = pLevel->plan.wsFlags;
106771106922
pTabItem = &pTabList->a[pLevel->iFrom];
106772106923
z = pTabItem->zAlias;
106773106924
if( z==0 ) z = pTabItem->pTab->zName;
106774106925
n = sqlite3Strlen30(z);
106775106926
if( n+nQPlan < sizeof(sqlite3_query_plan)-10 ){
106776
- if( pLevel->plan.wsFlags & WHERE_IDX_ONLY ){
106927
+ if( (w & WHERE_IDX_ONLY)!=0 && (w & WHERE_COVER_SCAN)==0 ){
106777106928
memcpy(&sqlite3_query_plan[nQPlan], "{}", 2);
106778106929
nQPlan += 2;
106779106930
}else{
106780106931
memcpy(&sqlite3_query_plan[nQPlan], z, n);
106781106932
nQPlan += n;
106782106933
}
106783106934
sqlite3_query_plan[nQPlan++] = ' ';
106784106935
}
106785
- testcase( pLevel->plan.wsFlags & WHERE_ROWID_EQ );
106786
- testcase( pLevel->plan.wsFlags & WHERE_ROWID_RANGE );
106787
- if( pLevel->plan.wsFlags & (WHERE_ROWID_EQ|WHERE_ROWID_RANGE) ){
106936
+ testcase( w & WHERE_ROWID_EQ );
106937
+ testcase( w & WHERE_ROWID_RANGE );
106938
+ if( w & (WHERE_ROWID_EQ|WHERE_ROWID_RANGE) ){
106788106939
memcpy(&sqlite3_query_plan[nQPlan], "* ", 2);
106789106940
nQPlan += 2;
106790
- }else if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
106941
+ }else if( (w & WHERE_INDEXED)!=0 && (w & WHERE_COVER_SCAN)==0 ){
106791106942
n = sqlite3Strlen30(pLevel->plan.u.pIdx->zName);
106792106943
if( n+nQPlan < sizeof(sqlite3_query_plan)-2 ){
106793106944
memcpy(&sqlite3_query_plan[nQPlan], pLevel->plan.u.pIdx->zName, n);
106794106945
nQPlan += n;
106795106946
sqlite3_query_plan[nQPlan++] = ' ';
@@ -112076,10 +112227,15 @@
112076112227
112077112228
case SQLITE_CONFIG_URI: {
112078112229
sqlite3GlobalConfig.bOpenUri = va_arg(ap, int);
112079112230
break;
112080112231
}
112232
+
112233
+ case SQLITE_CONFIG_COVERING_INDEX_SCAN: {
112234
+ sqlite3GlobalConfig.bUseCis = va_arg(ap, int);
112235
+ break;
112236
+ }
112081112237
112082112238
default: {
112083112239
rc = SQLITE_ERROR;
112084112240
break;
112085112241
}
@@ -113368,10 +113524,19 @@
113368113524
if( !db || db->mallocFailed ){
113369113525
return SQLITE_NOMEM;
113370113526
}
113371113527
return db->errCode;
113372113528
}
113529
+
113530
+/*
113531
+** Return a string that describes the kind of error specified in the
113532
+** argument. For now, this simply calls the internal sqlite3ErrStr()
113533
+** function.
113534
+*/
113535
+SQLITE_API const char *sqlite3_errstr(int rc){
113536
+ return sqlite3ErrStr(rc);
113537
+}
113373113538
113374113539
/*
113375113540
** Create a new collating function for database "db". The name is zName
113376113541
** and the encoding is enc.
113377113542
*/
@@ -114343,11 +114508,11 @@
114343114508
*/
114344114509
if( pCol ){
114345114510
zDataType = pCol->zType;
114346114511
zCollSeq = pCol->zColl;
114347114512
notnull = pCol->notNull!=0;
114348
- primarykey = pCol->isPrimKey!=0;
114513
+ primarykey = (pCol->colFlags & COLFLAG_PRIMKEY)!=0;
114349114514
autoinc = pTab->iPKey==iCol && (pTab->tabFlags & TF_Autoincrement)!=0;
114350114515
}else{
114351114516
zDataType = "INTEGER";
114352114517
primarykey = 1;
114353114518
}
114354114519
--- 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.14. 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.
@@ -671,13 +671,13 @@
671 **
672 ** See also: [sqlite3_libversion()],
673 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
674 ** [sqlite_version()] and [sqlite_source_id()].
675 */
676 #define SQLITE_VERSION "3.7.14"
677 #define SQLITE_VERSION_NUMBER 3007014
678 #define SQLITE_SOURCE_ID "2012-09-03 15:42:36 c0d89d4a9752922f9e367362366efde4f1b06f2a"
679
680 /*
681 ** CAPI3REF: Run-Time Library Version Numbers
682 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
683 **
@@ -1042,10 +1042,11 @@
1042 #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
1043 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
1044 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
1045 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
1046 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
 
1047 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
1048 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
1049 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
1050 #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
1051
@@ -2130,10 +2131,22 @@
2130 ** connection is opened. If it is globally disabled, filenames are
2131 ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
2132 ** database connection is opened. By default, URI handling is globally
2133 ** disabled. The default value may be changed by compiling with the
2134 ** [SQLITE_USE_URI] symbol defined.
 
 
 
 
 
 
 
 
 
 
 
 
2135 **
2136 ** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]]
2137 ** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE
2138 ** <dd> These options are obsolete and should not be used by new code.
2139 ** They are retained for backwards compatibility but are now no-ops.
@@ -2156,10 +2169,11 @@
2156 #define SQLITE_CONFIG_GETPCACHE 15 /* no-op */
2157 #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
2158 #define SQLITE_CONFIG_URI 17 /* int */
2159 #define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */
2160 #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
 
2161
2162 /*
2163 ** CAPI3REF: Database Connection Configuration Options
2164 **
2165 ** These constants are the available integer configuration options that
@@ -3164,11 +3178,11 @@
3164 ** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw",
3165 ** "rwc", or "memory". Attempting to set it to any other value is
3166 ** an error)^.
3167 ** ^If "ro" is specified, then the database is opened for read-only
3168 ** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the
3169 ** third argument to sqlite3_prepare_v2(). ^If the mode option is set to
3170 ** "rw", then the database is opened for read-write (but not create)
3171 ** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had
3172 ** been set. ^Value "rwc" is equivalent to setting both
3173 ** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If the mode option is
3174 ** set to "memory" then a pure [in-memory database] that never reads
@@ -3315,10 +3329,15 @@
3315 ** text that describes the error, as either UTF-8 or UTF-16 respectively.
3316 ** ^(Memory to hold the error message string is managed internally.
3317 ** The application does not need to worry about freeing the result.
3318 ** However, the error string might be overwritten or deallocated by
3319 ** subsequent calls to other SQLite interface functions.)^
 
 
 
 
 
3320 **
3321 ** When the serialized [threading mode] is in use, it might be the
3322 ** case that a second error occurs on a separate thread in between
3323 ** the time of the first error and the call to these interfaces.
3324 ** When that happens, the second error will be reported since these
@@ -3334,10 +3353,11 @@
3334 */
3335 SQLITE_API int sqlite3_errcode(sqlite3 *db);
3336 SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
3337 SQLITE_API const char *sqlite3_errmsg(sqlite3*);
3338 SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
 
3339
3340 /*
3341 ** CAPI3REF: SQL Statement Object
3342 ** KEYWORDS: {prepared statement} {prepared statements}
3343 **
@@ -9959,20 +9979,18 @@
9959 /*
9960 ** Bits of the sqlite3.flags field that are used by the
9961 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface.
9962 ** These must be the low-order bits of the flags field.
9963 */
9964 #define SQLITE_QueryFlattener 0x01 /* Disable query flattening */
9965 #define SQLITE_ColumnCache 0x02 /* Disable the column cache */
9966 #define SQLITE_IndexSort 0x04 /* Disable indexes for sorting */
9967 #define SQLITE_IndexSearch 0x08 /* Disable indexes for searching */
9968 #define SQLITE_IndexCover 0x10 /* Disable index covering table */
9969 #define SQLITE_GroupByOrder 0x20 /* Disable GROUPBY cover of ORDERBY */
9970 #define SQLITE_FactorOutConst 0x40 /* Disable factoring out constants */
9971 #define SQLITE_IdxRealAsInt 0x80 /* Store REAL as INT in indices */
9972 #define SQLITE_DistinctOpt 0x80 /* DISTINCT using indexes */
9973 #define SQLITE_OptMask 0xff /* Mask of all disablable opts */
9974
9975 /*
9976 ** Possible values for the sqlite.magic field.
9977 ** The numbers are obtained at random and have no special meaning, other
9978 ** than being distinct from one another.
@@ -10119,18 +10137,20 @@
10119 char *zName; /* Name of this column */
10120 Expr *pDflt; /* Default value of this column */
10121 char *zDflt; /* Original text of the default value */
10122 char *zType; /* Data type for this column */
10123 char *zColl; /* Collating sequence. If NULL, use the default */
10124 u8 notNull; /* True if there is a NOT NULL constraint */
10125 u8 isPrimKey; /* True if this column is part of the PRIMARY KEY */
10126 char affinity; /* One of the SQLITE_AFF_... values */
10127 #ifndef SQLITE_OMIT_VIRTUALTABLE
10128 u8 isHidden; /* True if this column is 'hidden' */
10129 #endif
10130 };
10131
 
 
 
 
 
10132 /*
10133 ** A "Collating Sequence" is defined by an instance of the following
10134 ** structure. Conceptually, a collating sequence consists of a name and
10135 ** a comparison routine that defines the order of that sequence.
10136 **
@@ -10282,32 +10302,32 @@
10282 ** sub-query that appears instead of a real table name in the FROM clause
10283 ** of a SELECT statement.
10284 */
10285 struct Table {
10286 char *zName; /* Name of the table or view */
10287 int iPKey; /* If not negative, use aCol[iPKey] as the primary key */
10288 int nCol; /* Number of columns in this table */
10289 Column *aCol; /* Information about each column */
10290 Index *pIndex; /* List of SQL indexes on this table. */
10291 int tnum; /* Root BTree node for this table (see note above) */
10292 tRowcnt nRowEst; /* Estimated rows in table - from sqlite_stat1 table */
10293 Select *pSelect; /* NULL for tables. Points to definition if a view. */
10294 u16 nRef; /* Number of pointers to this Table */
10295 u8 tabFlags; /* Mask of TF_* values */
10296 u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
10297 FKey *pFKey; /* Linked list of all foreign keys in this table */
10298 char *zColAff; /* String defining the affinity of each column */
10299 #ifndef SQLITE_OMIT_CHECK
10300 ExprList *pCheck; /* All CHECK constraints */
10301 #endif
 
 
 
 
 
 
 
10302 #ifndef SQLITE_OMIT_ALTERTABLE
10303 int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */
10304 #endif
10305 #ifndef SQLITE_OMIT_VIRTUALTABLE
10306 VTable *pVTable; /* List of VTable objects. */
10307 int nModuleArg; /* Number of arguments to the module */
10308 char **azModuleArg; /* Text of all module args. [0] is module name */
 
10309 #endif
10310 Trigger *pTrigger; /* List of triggers stored in pSchema */
10311 Schema *pSchema; /* Schema that contains this table */
10312 Table *pNextZombie; /* Next on the Parse.pZombieTab list */
10313 };
@@ -10327,11 +10347,11 @@
10327 ** done as a macro so that it will be optimized out when virtual
10328 ** table support is omitted from the build.
10329 */
10330 #ifndef SQLITE_OMIT_VIRTUALTABLE
10331 # define IsVirtual(X) (((X)->tabFlags & TF_Virtual)!=0)
10332 # define IsHiddenColumn(X) ((X)->isHidden)
10333 #else
10334 # define IsVirtual(X) 0
10335 # define IsHiddenColumn(X) 0
10336 #endif
10337
@@ -10679,10 +10699,13 @@
10679 /* If the EP_Reduced flag is set in the Expr.flags mask, then no
10680 ** space is allocated for the fields below this point. An attempt to
10681 ** access them will result in a segfault or malfunction.
10682 *********************************************************************/
10683
 
 
 
10684 int iTable; /* TK_COLUMN: cursor number of table holding column
10685 ** TK_REGISTER: register number
10686 ** TK_TRIGGER: 1 -> new, 0 -> old */
10687 ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
10688 ** TK_VARIABLE: variable number (always >= 1). */
@@ -10692,13 +10715,10 @@
10692 u8 op2; /* TK_REGISTER: original value of Expr.op
10693 ** TK_COLUMN: the value of p5 for OP_Column
10694 ** TK_AGG_FUNCTION: nesting depth */
10695 AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
10696 Table *pTab; /* Table for TK_COLUMN expressions. */
10697 #if SQLITE_MAX_EXPR_DEPTH>0
10698 int nHeight; /* Height of the tree headed by this node */
10699 #endif
10700 };
10701
10702 /*
10703 ** The following are the meanings of bits in the Expr.flags field.
10704 */
@@ -11459,10 +11479,11 @@
11459 struct Sqlite3Config {
11460 int bMemstat; /* True to enable memory status */
11461 int bCoreMutex; /* True to enable core mutexing */
11462 int bFullMutex; /* True to enable full mutexing */
11463 int bOpenUri; /* True to interpret filenames as URIs */
 
11464 int mxStrlen; /* Maximum string length */
11465 int szLookaside; /* Default lookaside buffer size */
11466 int nLookaside; /* Default lookaside buffer count */
11467 sqlite3_mem_methods m; /* Low-level memory allocation interface */
11468 sqlite3_mutex_methods mutex; /* Low-level mutex interface */
@@ -11775,10 +11796,11 @@
11775 SQLITE_PRIVATE void sqlite3AutoincrementEnd(Parse *pParse);
11776 #else
11777 # define sqlite3AutoincrementBegin(X)
11778 # define sqlite3AutoincrementEnd(X)
11779 #endif
 
11780 SQLITE_PRIVATE void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int);
11781 SQLITE_PRIVATE void *sqlite3ArrayAllocate(sqlite3*,void*,int,int*,int*);
11782 SQLITE_PRIVATE IdList *sqlite3IdListAppend(sqlite3*, IdList*, Token*);
11783 SQLITE_PRIVATE int sqlite3IdListIndex(IdList*,const char*);
11784 SQLITE_PRIVATE SrcList *sqlite3SrcListEnlarge(sqlite3*, SrcList*, int, int);
@@ -11950,11 +11972,11 @@
11950 SQLITE_PRIVATE int sqlite3AtoF(const char *z, double*, int, u8);
11951 SQLITE_PRIVATE int sqlite3GetInt32(const char *, int*);
11952 SQLITE_PRIVATE int sqlite3Atoi(const char*);
11953 SQLITE_PRIVATE int sqlite3Utf16ByteLen(const void *pData, int nChar);
11954 SQLITE_PRIVATE int sqlite3Utf8CharLen(const char *pData, int nByte);
11955 SQLITE_PRIVATE u32 sqlite3Utf8Read(const u8*, const u8**);
11956
11957 /*
11958 ** Routines to read and write variable-length integers. These used to
11959 ** be defined locally, but now we use the varint routines in the util.c
11960 ** file. Code should use the MACRO forms below, as the Varint32 versions
@@ -12450,19 +12472,24 @@
12450
12451 #ifndef SQLITE_USE_URI
12452 # define SQLITE_USE_URI 0
12453 #endif
12454
 
 
 
 
12455 /*
12456 ** The following singleton contains the global configuration for
12457 ** the SQLite library.
12458 */
12459 SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = {
12460 SQLITE_DEFAULT_MEMSTATUS, /* bMemstat */
12461 1, /* bCoreMutex */
12462 SQLITE_THREADSAFE==1, /* bFullMutex */
12463 SQLITE_USE_URI, /* bOpenUri */
 
12464 0x7ffffffe, /* mxStrlen */
12465 128, /* szLookaside */
12466 500, /* nLookaside */
12467 {0,0,0,0,0,0,0,0}, /* m */
12468 {0,0,0,0,0,0,0,0,0}, /* mutex */
@@ -12876,10 +12903,13 @@
12876 #ifdef SQLITE_PERFORMANCE_TRACE
12877 "PERFORMANCE_TRACE",
12878 #endif
12879 #ifdef SQLITE_PROXY_DEBUG
12880 "PROXY_DEBUG",
 
 
 
12881 #endif
12882 #ifdef SQLITE_SECURE_DELETE
12883 "SECURE_DELETE",
12884 #endif
12885 #ifdef SQLITE_SMALL_STACK
@@ -13234,10 +13264,15 @@
13234 int nIndent; /* Number of elements in aIndent */
13235 u16 aIndent[100]; /* Levels of indentation */
13236 char zBase[100]; /* Initial space */
13237 };
13238
 
 
 
 
 
13239 /*
13240 ** An instance of the virtual machine. This structure contains the complete
13241 ** state of the virtual machine.
13242 **
13243 ** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare()
@@ -13275,19 +13310,20 @@
13275 ynVar nzVar; /* Number of entries in azVar[] */
13276 u32 cacheCtr; /* VdbeCursor row cache generation counter */
13277 int pc; /* The program counter */
13278 int rc; /* Value to return */
13279 u8 errorAction; /* Recovery action to do in case of an error */
13280 u8 explain; /* True if EXPLAIN present on SQL command */
13281 u8 changeCntOn; /* True to update the change-counter */
13282 u8 expired; /* True if the VM needs to be recompiled */
13283 u8 runOnlyOnce; /* Automatically expire on reset */
13284 u8 minWriteFileFormat; /* Minimum file format for writable database files */
13285 u8 inVtabMethod; /* See comments above */
13286 u8 usesStmtJournal; /* True if uses a statement journal */
13287 u8 readOnly; /* True for read-only statements */
13288 u8 isPrepareV2; /* True if prepared with prepare_v2() */
 
 
 
 
 
13289 int nChange; /* Number of db changes made since last reset */
13290 yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */
13291 yDbMask lockMask; /* Subset of btreeMask that requires a lock */
13292 int iStatement; /* Statement number (or 0 if has not opened stmt) */
13293 int aCounter[3]; /* Counters used by sqlite3_stmt_status() */
@@ -20525,29 +20561,27 @@
20525 if( c<0x80 \
20526 || (c&0xFFFFF800)==0xD800 \
20527 || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } \
20528 }
20529 SQLITE_PRIVATE u32 sqlite3Utf8Read(
20530 const unsigned char *zIn, /* First byte of UTF-8 character */
20531 const unsigned char **pzNext /* Write first byte past UTF-8 char here */
20532 ){
20533 unsigned int c;
20534
20535 /* Same as READ_UTF8() above but without the zTerm parameter.
20536 ** For this routine, we assume the UTF8 string is always zero-terminated.
20537 */
20538 c = *(zIn++);
20539 if( c>=0xc0 ){
20540 c = sqlite3Utf8Trans1[c-0xc0];
20541 while( (*zIn & 0xc0)==0x80 ){
20542 c = (c<<6) + (0x3f & *(zIn++));
20543 }
20544 if( c<0x80
20545 || (c&0xFFFFF800)==0xD800
20546 || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; }
20547 }
20548 *pzNext = zIn;
20549 return c;
20550 }
20551
20552
20553
@@ -20644,19 +20678,17 @@
20644
20645 if( pMem->enc==SQLITE_UTF8 ){
20646 if( desiredEnc==SQLITE_UTF16LE ){
20647 /* UTF-8 -> UTF-16 Little-endian */
20648 while( zIn<zTerm ){
20649 /* c = sqlite3Utf8Read(zIn, zTerm, (const u8**)&zIn); */
20650 READ_UTF8(zIn, zTerm, c);
20651 WRITE_UTF16LE(z, c);
20652 }
20653 }else{
20654 assert( desiredEnc==SQLITE_UTF16BE );
20655 /* UTF-8 -> UTF-16 Big-endian */
20656 while( zIn<zTerm ){
20657 /* c = sqlite3Utf8Read(zIn, zTerm, (const u8**)&zIn); */
20658 READ_UTF8(zIn, zTerm, c);
20659 WRITE_UTF16BE(z, c);
20660 }
20661 }
20662 pMem->n = (int)(z - zOut);
@@ -20780,11 +20812,11 @@
20780 unsigned char *zOut = zIn;
20781 unsigned char *zStart = zIn;
20782 u32 c;
20783
20784 while( zIn[0] && zOut<=zIn ){
20785 c = sqlite3Utf8Read(zIn, (const u8**)&zIn);
20786 if( c!=0xfffd ){
20787 WRITE_UTF8(zOut, c);
20788 }
20789 }
20790 *zOut = 0;
@@ -20885,11 +20917,11 @@
20885 WRITE_UTF8(z, i);
20886 n = (int)(z-zBuf);
20887 assert( n>0 && n<=4 );
20888 z[0] = 0;
20889 z = zBuf;
20890 c = sqlite3Utf8Read(z, (const u8**)&z);
20891 t = i;
20892 if( i>=0xD800 && i<=0xDFFF ) t = 0xFFFD;
20893 if( (i&0xFFFFFFFE)==0xFFFE ) t = 0xFFFD;
20894 assert( c==t );
20895 assert( (z-zBuf)==n );
@@ -29887,10 +29919,19 @@
29887 #endif /* !defined(_OS_COMMON_H_) */
29888
29889 /************** End of os_common.h *******************************************/
29890 /************** Continuing where we left off in os_win.c *********************/
29891
 
 
 
 
 
 
 
 
 
29892 /*
29893 ** Macro to find the minimum of two numeric values.
29894 */
29895 #ifndef MIN
29896 # define MIN(x,y) ((x)<(y)?(x):(y))
@@ -30170,166 +30211,176 @@
30170 { "CreateFileW", (SYSCALL)0, 0 },
30171 #endif
30172
30173 #define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \
30174 LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent)
 
 
 
 
 
 
 
 
 
 
30175
30176 #if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \
30177 !defined(SQLITE_OMIT_WAL))
30178 { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 },
30179 #else
30180 { "CreateFileMappingW", (SYSCALL)0, 0 },
30181 #endif
30182
30183 #define osCreateFileMappingW ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \
30184 DWORD,DWORD,DWORD,LPCWSTR))aSyscall[6].pCurrent)
30185
30186 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
30187 { "CreateMutexW", (SYSCALL)CreateMutexW, 0 },
30188 #else
30189 { "CreateMutexW", (SYSCALL)0, 0 },
30190 #endif
30191
30192 #define osCreateMutexW ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,BOOL, \
30193 LPCWSTR))aSyscall[7].pCurrent)
30194
30195 #if defined(SQLITE_WIN32_HAS_ANSI)
30196 { "DeleteFileA", (SYSCALL)DeleteFileA, 0 },
30197 #else
30198 { "DeleteFileA", (SYSCALL)0, 0 },
30199 #endif
30200
30201 #define osDeleteFileA ((BOOL(WINAPI*)(LPCSTR))aSyscall[8].pCurrent)
30202
30203 #if defined(SQLITE_WIN32_HAS_WIDE)
30204 { "DeleteFileW", (SYSCALL)DeleteFileW, 0 },
30205 #else
30206 { "DeleteFileW", (SYSCALL)0, 0 },
30207 #endif
30208
30209 #define osDeleteFileW ((BOOL(WINAPI*)(LPCWSTR))aSyscall[9].pCurrent)
30210
30211 #if SQLITE_OS_WINCE
30212 { "FileTimeToLocalFileTime", (SYSCALL)FileTimeToLocalFileTime, 0 },
30213 #else
30214 { "FileTimeToLocalFileTime", (SYSCALL)0, 0 },
30215 #endif
30216
30217 #define osFileTimeToLocalFileTime ((BOOL(WINAPI*)(CONST FILETIME*, \
30218 LPFILETIME))aSyscall[10].pCurrent)
30219
30220 #if SQLITE_OS_WINCE
30221 { "FileTimeToSystemTime", (SYSCALL)FileTimeToSystemTime, 0 },
30222 #else
30223 { "FileTimeToSystemTime", (SYSCALL)0, 0 },
30224 #endif
30225
30226 #define osFileTimeToSystemTime ((BOOL(WINAPI*)(CONST FILETIME*, \
30227 LPSYSTEMTIME))aSyscall[11].pCurrent)
30228
30229 { "FlushFileBuffers", (SYSCALL)FlushFileBuffers, 0 },
30230
30231 #define osFlushFileBuffers ((BOOL(WINAPI*)(HANDLE))aSyscall[12].pCurrent)
30232
30233 #if defined(SQLITE_WIN32_HAS_ANSI)
30234 { "FormatMessageA", (SYSCALL)FormatMessageA, 0 },
30235 #else
30236 { "FormatMessageA", (SYSCALL)0, 0 },
30237 #endif
30238
30239 #define osFormatMessageA ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPSTR, \
30240 DWORD,va_list*))aSyscall[13].pCurrent)
30241
30242 #if defined(SQLITE_WIN32_HAS_WIDE)
30243 { "FormatMessageW", (SYSCALL)FormatMessageW, 0 },
30244 #else
30245 { "FormatMessageW", (SYSCALL)0, 0 },
30246 #endif
30247
30248 #define osFormatMessageW ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPWSTR, \
30249 DWORD,va_list*))aSyscall[14].pCurrent)
30250
30251 { "FreeLibrary", (SYSCALL)FreeLibrary, 0 },
30252
30253 #define osFreeLibrary ((BOOL(WINAPI*)(HMODULE))aSyscall[15].pCurrent)
30254
30255 { "GetCurrentProcessId", (SYSCALL)GetCurrentProcessId, 0 },
30256
30257 #define osGetCurrentProcessId ((DWORD(WINAPI*)(VOID))aSyscall[16].pCurrent)
30258
30259 #if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_ANSI)
30260 { "GetDiskFreeSpaceA", (SYSCALL)GetDiskFreeSpaceA, 0 },
30261 #else
30262 { "GetDiskFreeSpaceA", (SYSCALL)0, 0 },
30263 #endif
30264
30265 #define osGetDiskFreeSpaceA ((BOOL(WINAPI*)(LPCSTR,LPDWORD,LPDWORD,LPDWORD, \
30266 LPDWORD))aSyscall[17].pCurrent)
30267
30268 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
30269 { "GetDiskFreeSpaceW", (SYSCALL)GetDiskFreeSpaceW, 0 },
30270 #else
30271 { "GetDiskFreeSpaceW", (SYSCALL)0, 0 },
30272 #endif
30273
30274 #define osGetDiskFreeSpaceW ((BOOL(WINAPI*)(LPCWSTR,LPDWORD,LPDWORD,LPDWORD, \
30275 LPDWORD))aSyscall[18].pCurrent)
30276
30277 #if defined(SQLITE_WIN32_HAS_ANSI)
30278 { "GetFileAttributesA", (SYSCALL)GetFileAttributesA, 0 },
30279 #else
30280 { "GetFileAttributesA", (SYSCALL)0, 0 },
30281 #endif
30282
30283 #define osGetFileAttributesA ((DWORD(WINAPI*)(LPCSTR))aSyscall[19].pCurrent)
30284
30285 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
30286 { "GetFileAttributesW", (SYSCALL)GetFileAttributesW, 0 },
30287 #else
30288 { "GetFileAttributesW", (SYSCALL)0, 0 },
30289 #endif
30290
30291 #define osGetFileAttributesW ((DWORD(WINAPI*)(LPCWSTR))aSyscall[20].pCurrent)
30292
30293 #if defined(SQLITE_WIN32_HAS_WIDE)
30294 { "GetFileAttributesExW", (SYSCALL)GetFileAttributesExW, 0 },
30295 #else
30296 { "GetFileAttributesExW", (SYSCALL)0, 0 },
30297 #endif
30298
30299 #define osGetFileAttributesExW ((BOOL(WINAPI*)(LPCWSTR,GET_FILEEX_INFO_LEVELS, \
30300 LPVOID))aSyscall[21].pCurrent)
30301
30302 #if !SQLITE_OS_WINRT
30303 { "GetFileSize", (SYSCALL)GetFileSize, 0 },
30304 #else
30305 { "GetFileSize", (SYSCALL)0, 0 },
30306 #endif
30307
30308 #define osGetFileSize ((DWORD(WINAPI*)(HANDLE,LPDWORD))aSyscall[22].pCurrent)
30309
30310 #if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_ANSI)
30311 { "GetFullPathNameA", (SYSCALL)GetFullPathNameA, 0 },
30312 #else
30313 { "GetFullPathNameA", (SYSCALL)0, 0 },
30314 #endif
30315
30316 #define osGetFullPathNameA ((DWORD(WINAPI*)(LPCSTR,DWORD,LPSTR, \
30317 LPSTR*))aSyscall[23].pCurrent)
30318
30319 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
30320 { "GetFullPathNameW", (SYSCALL)GetFullPathNameW, 0 },
30321 #else
30322 { "GetFullPathNameW", (SYSCALL)0, 0 },
30323 #endif
30324
30325 #define osGetFullPathNameW ((DWORD(WINAPI*)(LPCWSTR,DWORD,LPWSTR, \
30326 LPWSTR*))aSyscall[24].pCurrent)
30327
30328 { "GetLastError", (SYSCALL)GetLastError, 0 },
30329
30330 #define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[25].pCurrent)
30331
30332 #if SQLITE_OS_WINCE
30333 /* The GetProcAddressA() routine is only available on Windows CE. */
30334 { "GetProcAddressA", (SYSCALL)GetProcAddressA, 0 },
30335 #else
@@ -30337,144 +30388,144 @@
30337 ** an ANSI string regardless of the _UNICODE setting */
30338 { "GetProcAddressA", (SYSCALL)GetProcAddress, 0 },
30339 #endif
30340
30341 #define osGetProcAddressA ((FARPROC(WINAPI*)(HMODULE, \
30342 LPCSTR))aSyscall[26].pCurrent)
30343
30344 #if !SQLITE_OS_WINRT
30345 { "GetSystemInfo", (SYSCALL)GetSystemInfo, 0 },
30346 #else
30347 { "GetSystemInfo", (SYSCALL)0, 0 },
30348 #endif
30349
30350 #define osGetSystemInfo ((VOID(WINAPI*)(LPSYSTEM_INFO))aSyscall[27].pCurrent)
30351
30352 { "GetSystemTime", (SYSCALL)GetSystemTime, 0 },
30353
30354 #define osGetSystemTime ((VOID(WINAPI*)(LPSYSTEMTIME))aSyscall[28].pCurrent)
30355
30356 #if !SQLITE_OS_WINCE
30357 { "GetSystemTimeAsFileTime", (SYSCALL)GetSystemTimeAsFileTime, 0 },
30358 #else
30359 { "GetSystemTimeAsFileTime", (SYSCALL)0, 0 },
30360 #endif
30361
30362 #define osGetSystemTimeAsFileTime ((VOID(WINAPI*)( \
30363 LPFILETIME))aSyscall[29].pCurrent)
30364
30365 #if defined(SQLITE_WIN32_HAS_ANSI)
30366 { "GetTempPathA", (SYSCALL)GetTempPathA, 0 },
30367 #else
30368 { "GetTempPathA", (SYSCALL)0, 0 },
30369 #endif
30370
30371 #define osGetTempPathA ((DWORD(WINAPI*)(DWORD,LPSTR))aSyscall[30].pCurrent)
30372
30373 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
30374 { "GetTempPathW", (SYSCALL)GetTempPathW, 0 },
30375 #else
30376 { "GetTempPathW", (SYSCALL)0, 0 },
30377 #endif
30378
30379 #define osGetTempPathW ((DWORD(WINAPI*)(DWORD,LPWSTR))aSyscall[31].pCurrent)
30380
30381 #if !SQLITE_OS_WINRT
30382 { "GetTickCount", (SYSCALL)GetTickCount, 0 },
30383 #else
30384 { "GetTickCount", (SYSCALL)0, 0 },
30385 #endif
30386
30387 #define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[32].pCurrent)
30388
30389 #if defined(SQLITE_WIN32_HAS_ANSI)
30390 { "GetVersionExA", (SYSCALL)GetVersionExA, 0 },
30391 #else
30392 { "GetVersionExA", (SYSCALL)0, 0 },
30393 #endif
30394
30395 #define osGetVersionExA ((BOOL(WINAPI*)( \
30396 LPOSVERSIONINFOA))aSyscall[33].pCurrent)
30397
30398 { "HeapAlloc", (SYSCALL)HeapAlloc, 0 },
30399
30400 #define osHeapAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD, \
30401 SIZE_T))aSyscall[34].pCurrent)
30402
30403 #if !SQLITE_OS_WINRT
30404 { "HeapCreate", (SYSCALL)HeapCreate, 0 },
30405 #else
30406 { "HeapCreate", (SYSCALL)0, 0 },
30407 #endif
30408
30409 #define osHeapCreate ((HANDLE(WINAPI*)(DWORD,SIZE_T, \
30410 SIZE_T))aSyscall[35].pCurrent)
30411
30412 #if !SQLITE_OS_WINRT
30413 { "HeapDestroy", (SYSCALL)HeapDestroy, 0 },
30414 #else
30415 { "HeapDestroy", (SYSCALL)0, 0 },
30416 #endif
30417
30418 #define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[36].pCurrent)
30419
30420 { "HeapFree", (SYSCALL)HeapFree, 0 },
30421
30422 #define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[37].pCurrent)
30423
30424 { "HeapReAlloc", (SYSCALL)HeapReAlloc, 0 },
30425
30426 #define osHeapReAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD,LPVOID, \
30427 SIZE_T))aSyscall[38].pCurrent)
30428
30429 { "HeapSize", (SYSCALL)HeapSize, 0 },
30430
30431 #define osHeapSize ((SIZE_T(WINAPI*)(HANDLE,DWORD, \
30432 LPCVOID))aSyscall[39].pCurrent)
30433
30434 #if !SQLITE_OS_WINRT
30435 { "HeapValidate", (SYSCALL)HeapValidate, 0 },
30436 #else
30437 { "HeapValidate", (SYSCALL)0, 0 },
30438 #endif
30439
30440 #define osHeapValidate ((BOOL(WINAPI*)(HANDLE,DWORD, \
30441 LPCVOID))aSyscall[40].pCurrent)
30442
30443 #if defined(SQLITE_WIN32_HAS_ANSI)
30444 { "LoadLibraryA", (SYSCALL)LoadLibraryA, 0 },
30445 #else
30446 { "LoadLibraryA", (SYSCALL)0, 0 },
30447 #endif
30448
30449 #define osLoadLibraryA ((HMODULE(WINAPI*)(LPCSTR))aSyscall[41].pCurrent)
30450
30451 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
30452 { "LoadLibraryW", (SYSCALL)LoadLibraryW, 0 },
30453 #else
30454 { "LoadLibraryW", (SYSCALL)0, 0 },
30455 #endif
30456
30457 #define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[42].pCurrent)
30458
30459 #if !SQLITE_OS_WINRT
30460 { "LocalFree", (SYSCALL)LocalFree, 0 },
30461 #else
30462 { "LocalFree", (SYSCALL)0, 0 },
30463 #endif
30464
30465 #define osLocalFree ((HLOCAL(WINAPI*)(HLOCAL))aSyscall[43].pCurrent)
30466
30467 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
30468 { "LockFile", (SYSCALL)LockFile, 0 },
30469 #else
30470 { "LockFile", (SYSCALL)0, 0 },
30471 #endif
30472
30473 #ifndef osLockFile
30474 #define osLockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
30475 DWORD))aSyscall[44].pCurrent)
30476 #endif
30477
30478 #if !SQLITE_OS_WINCE
30479 { "LockFileEx", (SYSCALL)LockFileEx, 0 },
30480 #else
@@ -30481,218 +30532,218 @@
30481 { "LockFileEx", (SYSCALL)0, 0 },
30482 #endif
30483
30484 #ifndef osLockFileEx
30485 #define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \
30486 LPOVERLAPPED))aSyscall[45].pCurrent)
30487 #endif
30488
30489 #if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL))
30490 { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 },
30491 #else
30492 { "MapViewOfFile", (SYSCALL)0, 0 },
30493 #endif
30494
30495 #define osMapViewOfFile ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
30496 SIZE_T))aSyscall[46].pCurrent)
30497
30498 { "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 },
30499
30500 #define osMultiByteToWideChar ((int(WINAPI*)(UINT,DWORD,LPCSTR,int,LPWSTR, \
30501 int))aSyscall[47].pCurrent)
30502
30503 { "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 },
30504
30505 #define osQueryPerformanceCounter ((BOOL(WINAPI*)( \
30506 LARGE_INTEGER*))aSyscall[48].pCurrent)
30507
30508 { "ReadFile", (SYSCALL)ReadFile, 0 },
30509
30510 #define osReadFile ((BOOL(WINAPI*)(HANDLE,LPVOID,DWORD,LPDWORD, \
30511 LPOVERLAPPED))aSyscall[49].pCurrent)
30512
30513 { "SetEndOfFile", (SYSCALL)SetEndOfFile, 0 },
30514
30515 #define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[50].pCurrent)
30516
30517 #if !SQLITE_OS_WINRT
30518 { "SetFilePointer", (SYSCALL)SetFilePointer, 0 },
30519 #else
30520 { "SetFilePointer", (SYSCALL)0, 0 },
30521 #endif
30522
30523 #define osSetFilePointer ((DWORD(WINAPI*)(HANDLE,LONG,PLONG, \
30524 DWORD))aSyscall[51].pCurrent)
30525
30526 #if !SQLITE_OS_WINRT
30527 { "Sleep", (SYSCALL)Sleep, 0 },
30528 #else
30529 { "Sleep", (SYSCALL)0, 0 },
30530 #endif
30531
30532 #define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[52].pCurrent)
30533
30534 { "SystemTimeToFileTime", (SYSCALL)SystemTimeToFileTime, 0 },
30535
30536 #define osSystemTimeToFileTime ((BOOL(WINAPI*)(CONST SYSTEMTIME*, \
30537 LPFILETIME))aSyscall[53].pCurrent)
30538
30539 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
30540 { "UnlockFile", (SYSCALL)UnlockFile, 0 },
30541 #else
30542 { "UnlockFile", (SYSCALL)0, 0 },
30543 #endif
30544
30545 #ifndef osUnlockFile
30546 #define osUnlockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
30547 DWORD))aSyscall[54].pCurrent)
30548 #endif
30549
30550 #if !SQLITE_OS_WINCE
30551 { "UnlockFileEx", (SYSCALL)UnlockFileEx, 0 },
30552 #else
30553 { "UnlockFileEx", (SYSCALL)0, 0 },
30554 #endif
30555
30556 #define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
30557 LPOVERLAPPED))aSyscall[55].pCurrent)
30558
30559 #if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL)
30560 { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 },
30561 #else
30562 { "UnmapViewOfFile", (SYSCALL)0, 0 },
30563 #endif
30564
30565 #define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[56].pCurrent)
30566
30567 { "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 },
30568
30569 #define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \
30570 LPCSTR,LPBOOL))aSyscall[57].pCurrent)
30571
30572 { "WriteFile", (SYSCALL)WriteFile, 0 },
30573
30574 #define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \
30575 LPOVERLAPPED))aSyscall[58].pCurrent)
30576
30577 #if SQLITE_OS_WINRT
30578 { "CreateEventExW", (SYSCALL)CreateEventExW, 0 },
30579 #else
30580 { "CreateEventExW", (SYSCALL)0, 0 },
30581 #endif
30582
30583 #define osCreateEventExW ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,LPCWSTR, \
30584 DWORD,DWORD))aSyscall[59].pCurrent)
30585
30586 #if !SQLITE_OS_WINRT
30587 { "WaitForSingleObject", (SYSCALL)WaitForSingleObject, 0 },
30588 #else
30589 { "WaitForSingleObject", (SYSCALL)0, 0 },
30590 #endif
30591
30592 #define osWaitForSingleObject ((DWORD(WINAPI*)(HANDLE, \
30593 DWORD))aSyscall[60].pCurrent)
30594
30595 #if SQLITE_OS_WINRT
30596 { "WaitForSingleObjectEx", (SYSCALL)WaitForSingleObjectEx, 0 },
30597 #else
30598 { "WaitForSingleObjectEx", (SYSCALL)0, 0 },
30599 #endif
30600
30601 #define osWaitForSingleObjectEx ((DWORD(WINAPI*)(HANDLE,DWORD, \
30602 BOOL))aSyscall[61].pCurrent)
30603
30604 #if SQLITE_OS_WINRT
30605 { "SetFilePointerEx", (SYSCALL)SetFilePointerEx, 0 },
30606 #else
30607 { "SetFilePointerEx", (SYSCALL)0, 0 },
30608 #endif
30609
30610 #define osSetFilePointerEx ((BOOL(WINAPI*)(HANDLE,LARGE_INTEGER, \
30611 PLARGE_INTEGER,DWORD))aSyscall[62].pCurrent)
30612
30613 #if SQLITE_OS_WINRT
30614 { "GetFileInformationByHandleEx", (SYSCALL)GetFileInformationByHandleEx, 0 },
30615 #else
30616 { "GetFileInformationByHandleEx", (SYSCALL)0, 0 },
30617 #endif
30618
30619 #define osGetFileInformationByHandleEx ((BOOL(WINAPI*)(HANDLE, \
30620 FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[63].pCurrent)
30621
30622 #if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)
30623 { "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 },
30624 #else
30625 { "MapViewOfFileFromApp", (SYSCALL)0, 0 },
30626 #endif
30627
30628 #define osMapViewOfFileFromApp ((LPVOID(WINAPI*)(HANDLE,ULONG,ULONG64, \
30629 SIZE_T))aSyscall[64].pCurrent)
30630
30631 #if SQLITE_OS_WINRT
30632 { "CreateFile2", (SYSCALL)CreateFile2, 0 },
30633 #else
30634 { "CreateFile2", (SYSCALL)0, 0 },
30635 #endif
30636
30637 #define osCreateFile2 ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD,DWORD, \
30638 LPCREATEFILE2_EXTENDED_PARAMETERS))aSyscall[65].pCurrent)
30639
30640 #if SQLITE_OS_WINRT
30641 { "LoadPackagedLibrary", (SYSCALL)LoadPackagedLibrary, 0 },
30642 #else
30643 { "LoadPackagedLibrary", (SYSCALL)0, 0 },
30644 #endif
30645
30646 #define osLoadPackagedLibrary ((HMODULE(WINAPI*)(LPCWSTR, \
30647 DWORD))aSyscall[66].pCurrent)
30648
30649 #if SQLITE_OS_WINRT
30650 { "GetTickCount64", (SYSCALL)GetTickCount64, 0 },
30651 #else
30652 { "GetTickCount64", (SYSCALL)0, 0 },
30653 #endif
30654
30655 #define osGetTickCount64 ((ULONGLONG(WINAPI*)(VOID))aSyscall[67].pCurrent)
30656
30657 #if SQLITE_OS_WINRT
30658 { "GetNativeSystemInfo", (SYSCALL)GetNativeSystemInfo, 0 },
30659 #else
30660 { "GetNativeSystemInfo", (SYSCALL)0, 0 },
30661 #endif
30662
30663 #define osGetNativeSystemInfo ((VOID(WINAPI*)( \
30664 LPSYSTEM_INFO))aSyscall[68].pCurrent)
30665
30666 #if defined(SQLITE_WIN32_HAS_ANSI)
30667 { "OutputDebugStringA", (SYSCALL)OutputDebugStringA, 0 },
30668 #else
30669 { "OutputDebugStringA", (SYSCALL)0, 0 },
30670 #endif
30671
30672 #define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[69].pCurrent)
30673
30674 #if defined(SQLITE_WIN32_HAS_WIDE)
30675 { "OutputDebugStringW", (SYSCALL)OutputDebugStringW, 0 },
30676 #else
30677 { "OutputDebugStringW", (SYSCALL)0, 0 },
30678 #endif
30679
30680 #define osOutputDebugStringW ((VOID(WINAPI*)(LPCWSTR))aSyscall[70].pCurrent)
30681
30682 { "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 },
30683
30684 #define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[71].pCurrent)
30685
30686 #if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)
30687 { "CreateFileMappingFromApp", (SYSCALL)CreateFileMappingFromApp, 0 },
30688 #else
30689 { "CreateFileMappingFromApp", (SYSCALL)0, 0 },
30690 #endif
30691
30692 #define osCreateFileMappingFromApp ((HANDLE(WINAPI*)(HANDLE, \
30693 LPSECURITY_ATTRIBUTES,ULONG,ULONG64,LPCWSTR))aSyscall[72].pCurrent)
30694
30695 }; /* End of the overrideable system calls */
30696
30697 /*
30698 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
@@ -30846,10 +30897,12 @@
30846 ** WinNT/2K/XP so that we will know whether or not we can safely call
30847 ** the LockFileEx() API.
30848 */
30849 #if SQLITE_OS_WINCE || SQLITE_OS_WINRT
30850 # define isNT() (1)
 
 
30851 #else
30852 static int isNT(void){
30853 if( sqlite3_os_type==0 ){
30854 OSVERSIONINFOA sInfo;
30855 sInfo.dwOSVersionInfoSize = sizeof(sInfo);
@@ -30856,11 +30909,11 @@
30856 osGetVersionExA(&sInfo);
30857 sqlite3_os_type = sInfo.dwPlatformId==VER_PLATFORM_WIN32_NT ? 2 : 1;
30858 }
30859 return sqlite3_os_type==2;
30860 }
30861 #endif /* SQLITE_OS_WINCE */
30862
30863 #ifdef SQLITE_WIN32_MALLOC
30864 /*
30865 ** Allocate nBytes of memory.
30866 */
@@ -31066,11 +31119,11 @@
31066
31067 nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0);
31068 if( nChar==0 ){
31069 return 0;
31070 }
31071 zWideFilename = sqlite3_malloc( nChar*sizeof(zWideFilename[0]) );
31072 if( zWideFilename==0 ){
31073 return 0;
31074 }
31075 nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, zWideFilename,
31076 nChar);
@@ -31091,11 +31144,11 @@
31091
31092 nByte = osWideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, 0, 0, 0, 0);
31093 if( nByte == 0 ){
31094 return 0;
31095 }
31096 zFilename = sqlite3_malloc( nByte );
31097 if( zFilename==0 ){
31098 return 0;
31099 }
31100 nByte = osWideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, zFilename, nByte,
31101 0, 0);
@@ -31121,11 +31174,11 @@
31121 nByte = osMultiByteToWideChar(codepage, 0, zFilename, -1, NULL,
31122 0)*sizeof(WCHAR);
31123 if( nByte==0 ){
31124 return 0;
31125 }
31126 zMbcsFilename = sqlite3_malloc( nByte*sizeof(zMbcsFilename[0]) );
31127 if( zMbcsFilename==0 ){
31128 return 0;
31129 }
31130 nByte = osMultiByteToWideChar(codepage, 0, zFilename, -1, zMbcsFilename,
31131 nByte);
@@ -31150,11 +31203,11 @@
31150
31151 nByte = osWideCharToMultiByte(codepage, 0, zWideFilename, -1, 0, 0, 0, 0);
31152 if( nByte == 0 ){
31153 return 0;
31154 }
31155 zFilename = sqlite3_malloc( nByte );
31156 if( zFilename==0 ){
31157 return 0;
31158 }
31159 nByte = osWideCharToMultiByte(codepage, 0, zWideFilename, -1, zFilename,
31160 nByte, 0, 0);
@@ -32797,20 +32850,18 @@
32797 assert( pDbFd->pShm==0 ); /* Not previously opened */
32798
32799 /* Allocate space for the new sqlite3_shm object. Also speculatively
32800 ** allocate space for a new winShmNode and filename.
32801 */
32802 p = sqlite3_malloc( sizeof(*p) );
32803 if( p==0 ) return SQLITE_IOERR_NOMEM;
32804 memset(p, 0, sizeof(*p));
32805 nName = sqlite3Strlen30(pDbFd->zPath);
32806 pNew = sqlite3_malloc( sizeof(*pShmNode) + nName + 17 );
32807 if( pNew==0 ){
32808 sqlite3_free(p);
32809 return SQLITE_IOERR_NOMEM;
32810 }
32811 memset(pNew, 0, sizeof(*pNew) + nName + 17);
32812 pNew->zFilename = (char*)&pNew[1];
32813 sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath);
32814 sqlite3FileSuffix3(pDbFd->zPath, pNew->zFilename);
32815
32816 /* Look to see if there is an existing winShmNode that can be used.
@@ -33143,21 +33194,25 @@
33143 goto shmpage_out;
33144 }
33145 pShmNode->aRegion = apNew;
33146
33147 while( pShmNode->nRegion<=iRegion ){
33148 HANDLE hMap; /* file-mapping handle */
33149 void *pMap = 0; /* Mapped memory region */
33150
33151 #if SQLITE_OS_WINRT
33152 hMap = osCreateFileMappingFromApp(pShmNode->hFile.h,
33153 NULL, PAGE_READWRITE, nByte, NULL
33154 );
33155 #else
33156 hMap = osCreateFileMappingW(pShmNode->hFile.h,
33157 NULL, PAGE_READWRITE, 0, nByte, NULL
33158 );
 
 
 
 
33159 #endif
33160 OSTRACE(("SHM-MAP pid-%d create region=%d nbyte=%d %s\n",
33161 (int)osGetCurrentProcessId(), pShmNode->nRegion, nByte,
33162 hMap ? "ok" : "failed"));
33163 if( hMap ){
@@ -33902,11 +33957,11 @@
33902 }
33903 return SQLITE_OK;
33904 #endif
33905
33906 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(__CYGWIN__)
33907 int nByte;
33908 void *zConverted;
33909 char *zOut;
33910
33911 /* If this path name begins with "/X:", where "X" is any alphabetic
33912 ** character, discard the initial "/" from the pathname.
@@ -33936,31 +33991,59 @@
33936 if( zConverted==0 ){
33937 return SQLITE_IOERR_NOMEM;
33938 }
33939 if( isNT() ){
33940 LPWSTR zTemp;
33941 nByte = osGetFullPathNameW((LPCWSTR)zConverted, 0, 0, 0) + 3;
33942 zTemp = sqlite3_malloc( nByte*sizeof(zTemp[0]) );
 
 
 
 
 
 
 
33943 if( zTemp==0 ){
33944 sqlite3_free(zConverted);
33945 return SQLITE_IOERR_NOMEM;
33946 }
33947 osGetFullPathNameW((LPCWSTR)zConverted, nByte, zTemp, 0);
 
 
 
 
 
 
 
33948 sqlite3_free(zConverted);
33949 zOut = unicodeToUtf8(zTemp);
33950 sqlite3_free(zTemp);
33951 }
33952 #ifdef SQLITE_WIN32_HAS_ANSI
33953 else{
33954 char *zTemp;
33955 nByte = osGetFullPathNameA((char*)zConverted, 0, 0, 0) + 3;
33956 zTemp = sqlite3_malloc( nByte*sizeof(zTemp[0]) );
 
 
 
 
 
 
 
33957 if( zTemp==0 ){
33958 sqlite3_free(zConverted);
33959 return SQLITE_IOERR_NOMEM;
33960 }
33961 osGetFullPathNameA((char*)zConverted, nByte, zTemp, 0);
 
 
 
 
 
 
 
33962 sqlite3_free(zConverted);
33963 zOut = sqlite3_win32_mbcs_to_utf8(zTemp);
33964 sqlite3_free(zTemp);
33965 }
33966 #endif
@@ -34214,11 +34297,11 @@
34214 winNextSystemCall, /* xNextSystemCall */
34215 };
34216
34217 /* Double-check that the aSyscall[] array has been constructed
34218 ** correctly. See ticket [bb3a86e890c8e96ab] */
34219 assert( ArraySize(aSyscall)==73 );
34220
34221 #ifndef SQLITE_OMIT_WAL
34222 /* get memory map allocation granularity */
34223 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
34224 #if SQLITE_OS_WINRT
@@ -34233,11 +34316,11 @@
34233 return SQLITE_OK;
34234 }
34235
34236 SQLITE_API int sqlite3_os_end(void){
34237 #if SQLITE_OS_WINRT
34238 if( sleepObj != NULL ){
34239 osCloseHandle(sleepObj);
34240 sleepObj = NULL;
34241 }
34242 #endif
34243 return SQLITE_OK;
@@ -41395,11 +41478,11 @@
41395 assert( nPathname>0 );
41396 pPager->zJournal = (char*)(pPtr += nPathname + 1 + nUri);
41397 memcpy(pPager->zFilename, zPathname, nPathname);
41398 if( nUri ) memcpy(&pPager->zFilename[nPathname+1], zUri, nUri);
41399 memcpy(pPager->zJournal, zPathname, nPathname);
41400 memcpy(&pPager->zJournal[nPathname], "-journal\000", 8+1);
41401 sqlite3FileSuffix3(pPager->zFilename, pPager->zJournal);
41402 #ifndef SQLITE_OMIT_WAL
41403 pPager->zWal = &pPager->zJournal[nPathname+8+1];
41404 memcpy(pPager->zWal, zPathname, nPathname);
41405 memcpy(&pPager->zWal[nPathname], "-wal\000", 4+1);
@@ -58860,14 +58943,13 @@
58860 pOp->p4.pKeyInfo = pKeyInfo;
58861 if( pKeyInfo ){
58862 u8 *aSortOrder;
58863 memcpy((char*)pKeyInfo, zP4, nByte - nField);
58864 aSortOrder = pKeyInfo->aSortOrder;
58865 if( aSortOrder ){
58866 pKeyInfo->aSortOrder = (unsigned char*)&pKeyInfo->aColl[nField];
58867 memcpy(pKeyInfo->aSortOrder, aSortOrder, nField);
58868 }
58869 pOp->p4type = P4_KEYINFO;
58870 }else{
58871 p->db->mallocFailed = 1;
58872 pOp->p4type = P4_NOTUSED;
58873 }
@@ -58976,10 +59058,11 @@
58976 switch( pOp->p4type ){
58977 case P4_KEYINFO_STATIC:
58978 case P4_KEYINFO: {
58979 int i, j;
58980 KeyInfo *pKeyInfo = pOp->p4.pKeyInfo;
 
58981 sqlite3_snprintf(nTemp, zTemp, "keyinfo(%d", pKeyInfo->nField);
58982 i = sqlite3Strlen30(zTemp);
58983 for(j=0; j<pKeyInfo->nField; j++){
58984 CollSeq *pColl = pKeyInfo->aColl[j];
58985 if( pColl ){
@@ -58987,11 +59070,11 @@
58987 if( i+n>nTemp-6 ){
58988 memcpy(&zTemp[i],",...",4);
58989 break;
58990 }
58991 zTemp[i++] = ',';
58992 if( pKeyInfo->aSortOrder && pKeyInfo->aSortOrder[j] ){
58993 zTemp[i++] = '-';
58994 }
58995 memcpy(&zTemp[i], pColl->zName,n+1);
58996 i += n;
58997 }else if( i+4<nTemp-6 ){
@@ -60698,21 +60781,20 @@
60698 if( flags&MEM_Int ){
60699 /* Figure out whether to use 1, 2, 4, 6 or 8 bytes. */
60700 # define MAX_6BYTE ((((i64)0x00008000)<<32)-1)
60701 i64 i = pMem->u.i;
60702 u64 u;
60703 if( file_format>=4 && (i&1)==i ){
60704 return 8+(u32)i;
60705 }
60706 if( i<0 ){
60707 if( i<(-MAX_6BYTE) ) return 6;
60708 /* Previous test prevents: u = -(-9223372036854775808) */
60709 u = -i;
60710 }else{
60711 u = i;
60712 }
60713 if( u<=127 ) return 1;
 
 
60714 if( u<=32767 ) return 2;
60715 if( u<=8388607 ) return 3;
60716 if( u<=2147483647 ) return 4;
60717 if( u<=MAX_6BYTE ) return 5;
60718 return 6;
@@ -60993,10 +61075,11 @@
60993 p = (UnpackedRecord*)&pSpace[nOff];
60994 *ppFree = 0;
60995 }
60996
60997 p->aMem = (Mem*)&((char*)p)[ROUND8(sizeof(UnpackedRecord))];
 
60998 p->pKeyInfo = pKeyInfo;
60999 p->nField = pKeyInfo->nField + 1;
61000 return p;
61001 }
61002
@@ -61086,10 +61169,11 @@
61086 /* mem1.u.i = 0; // not needed, here to silence compiler warning */
61087
61088 idx1 = getVarint32(aKey1, szHdr1);
61089 d1 = szHdr1;
61090 nField = pKeyInfo->nField;
 
61091 while( idx1<szHdr1 && i<pPKey2->nField ){
61092 u32 serial_type1;
61093
61094 /* Read the serial types for the next element in each key. */
61095 idx1 += getVarint32( aKey1+idx1, serial_type1 );
@@ -61105,11 +61189,11 @@
61105 i<nField ? pKeyInfo->aColl[i] : 0);
61106 if( rc!=0 ){
61107 assert( mem1.zMalloc==0 ); /* See comment below */
61108
61109 /* Invert the result if we are using DESC sort order. */
61110 if( pKeyInfo->aSortOrder && i<nField && pKeyInfo->aSortOrder[i] ){
61111 rc = -rc;
61112 }
61113
61114 /* If the PREFIX_SEARCH flag is set and all fields except the final
61115 ** rowid field were equal, then clear the PREFIX_SEARCH flag and set
@@ -61831,14 +61915,16 @@
61831 if( vdbeSafetyNotNull(v) ){
61832 return SQLITE_MISUSE_BKPT;
61833 }
61834 db = v->db;
61835 sqlite3_mutex_enter(db->mutex);
 
61836 while( (rc = sqlite3Step(v))==SQLITE_SCHEMA
61837 && cnt++ < SQLITE_MAX_SCHEMA_RETRY
61838 && (rc2 = rc = sqlite3Reprepare(v))==SQLITE_OK ){
61839 sqlite3_reset(pStmt);
 
61840 assert( v->expired==0 );
61841 }
61842 if( rc2!=SQLITE_OK && ALWAYS(v->isPrepareV2) && ALWAYS(db->pErr) ){
61843 /* This case occurs after failing to recompile an sql statement.
61844 ** The error message from the SQL compiler has already been loaded
@@ -63957,11 +64043,10 @@
63957 struct OP_JournalMode_stack_vars {
63958 Btree *pBt; /* Btree to change journal mode of */
63959 Pager *pPager; /* Pager associated with pBt */
63960 int eNew; /* New journal mode */
63961 int eOld; /* The old journal mode */
63962 const char *zFilename; /* Name of database file for pPager */
63963 } ci;
63964 struct OP_IncrVacuum_stack_vars {
63965 Btree *pBt;
63966 } cj;
63967 struct OP_VBegin_stack_vars {
@@ -69061,12 +69146,14 @@
69061 #if 0 /* local variables moved into u.ci */
69062 Btree *pBt; /* Btree to change journal mode of */
69063 Pager *pPager; /* Pager associated with pBt */
69064 int eNew; /* New journal mode */
69065 int eOld; /* The old journal mode */
69066 const char *zFilename; /* Name of database file for pPager */
69067 #endif /* local variables moved into u.ci */
 
 
 
69068
69069 u.ci.eNew = pOp->p3;
69070 assert( u.ci.eNew==PAGER_JOURNALMODE_DELETE
69071 || u.ci.eNew==PAGER_JOURNALMODE_TRUNCATE
69072 || u.ci.eNew==PAGER_JOURNALMODE_PERSIST
@@ -69082,17 +69169,17 @@
69082 u.ci.eOld = sqlite3PagerGetJournalMode(u.ci.pPager);
69083 if( u.ci.eNew==PAGER_JOURNALMODE_QUERY ) u.ci.eNew = u.ci.eOld;
69084 if( !sqlite3PagerOkToChangeJournalMode(u.ci.pPager) ) u.ci.eNew = u.ci.eOld;
69085
69086 #ifndef SQLITE_OMIT_WAL
69087 u.ci.zFilename = sqlite3PagerFilename(u.ci.pPager, 1);
69088
69089 /* Do not allow a transition to journal_mode=WAL for a database
69090 ** in temporary storage or if the VFS does not support shared memory
69091 */
69092 if( u.ci.eNew==PAGER_JOURNALMODE_WAL
69093 && (sqlite3Strlen30(u.ci.zFilename)==0 /* Temp file */
69094 || !sqlite3PagerWalSupported(u.ci.pPager)) /* No shared-memory support */
69095 ){
69096 u.ci.eNew = u.ci.eOld;
69097 }
69098
@@ -69660,11 +69747,14 @@
69660 #if 0 /* local variables moved into u.cr */
69661 char *zTrace;
69662 char *z;
69663 #endif /* local variables moved into u.cr */
69664
69665 if( db->xTrace && (u.cr.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 ){
 
 
 
69666 u.cr.z = sqlite3VdbeExpandSql(p, u.cr.zTrace);
69667 db->xTrace(db->pTraceArg, u.cr.z);
69668 sqlite3DbFree(db, u.cr.z);
69669 }
69670 #ifdef SQLITE_DEBUG
@@ -74885,10 +74975,11 @@
74885
74886 switch( pExpr->op ){
74887 case TK_IN: {
74888 char affinity; /* Affinity of the LHS of the IN */
74889 KeyInfo keyInfo; /* Keyinfo for the generated table */
 
74890 int addr; /* Address of OP_OpenEphemeral instruction */
74891 Expr *pLeft = pExpr->pLeft; /* the LHS of the IN operator */
74892
74893 if( rMayHaveNull ){
74894 sqlite3VdbeAddOp2(v, OP_Null, 0, rMayHaveNull);
@@ -74912,10 +75003,11 @@
74912 pExpr->iTable = pParse->nTab++;
74913 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, !isRowid);
74914 if( rMayHaveNull==0 ) sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
74915 memset(&keyInfo, 0, sizeof(keyInfo));
74916 keyInfo.nField = 1;
 
74917
74918 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
74919 /* Case 1: expr IN (SELECT ...)
74920 **
74921 ** Generate code to write the results of the select into the temporary
@@ -74952,10 +75044,11 @@
74952
74953 if( !affinity ){
74954 affinity = SQLITE_AFF_NONE;
74955 }
74956 keyInfo.aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
 
74957
74958 /* Loop through each expression in <exprlist>. */
74959 r1 = sqlite3GetTempReg(pParse);
74960 r2 = sqlite3GetTempReg(pParse);
74961 sqlite3VdbeAddOp2(v, OP_Null, 0, r2);
@@ -78030,11 +78123,11 @@
78030
78031 /* Check that the new column is not specified as PRIMARY KEY or UNIQUE.
78032 ** If there is a NOT NULL constraint, then the default value for the
78033 ** column must not be NULL.
78034 */
78035 if( pCol->isPrimKey ){
78036 sqlite3ErrorMsg(pParse, "Cannot add a PRIMARY KEY column");
78037 return;
78038 }
78039 if( pNew->pIndex ){
78040 sqlite3ErrorMsg(pParse, "Cannot add a UNIQUE column");
@@ -81299,20 +81392,20 @@
81299 goto primary_key_exit;
81300 }
81301 pTab->tabFlags |= TF_HasPrimaryKey;
81302 if( pList==0 ){
81303 iCol = pTab->nCol - 1;
81304 pTab->aCol[iCol].isPrimKey = 1;
81305 }else{
81306 for(i=0; i<pList->nExpr; i++){
81307 for(iCol=0; iCol<pTab->nCol; iCol++){
81308 if( sqlite3StrICmp(pList->a[i].zName, pTab->aCol[iCol].zName)==0 ){
81309 break;
81310 }
81311 }
81312 if( iCol<pTab->nCol ){
81313 pTab->aCol[iCol].isPrimKey = 1;
81314 }
81315 }
81316 if( pList->nExpr>1 ) iCol = -1;
81317 }
81318 if( iCol>=0 && iCol<pTab->nCol ){
@@ -85468,37 +85561,18 @@
85468 sqlite3_result_text(context, z1, n, sqlite3_free);
85469 }
85470 }
85471 }
85472
85473
85474 #if 0 /* This function is never used. */
85475 /*
85476 ** The COALESCE() and IFNULL() functions used to be implemented as shown
85477 ** here. But now they are implemented as VDBE code so that unused arguments
85478 ** do not have to be computed. This legacy implementation is retained as
85479 ** comment.
85480 */
85481 /*
85482 ** Implementation of the IFNULL(), NVL(), and COALESCE() functions.
85483 ** All three do the same thing. They return the first non-NULL
85484 ** argument.
85485 */
85486 static void ifnullFunc(
85487 sqlite3_context *context,
85488 int argc,
85489 sqlite3_value **argv
85490 ){
85491 int i;
85492 for(i=0; i<argc; i++){
85493 if( SQLITE_NULL!=sqlite3_value_type(argv[i]) ){
85494 sqlite3_result_value(context, argv[i]);
85495 break;
85496 }
85497 }
85498 }
85499 #endif /* NOT USED */
85500 #define ifnullFunc versionFunc /* Substitute function - never called */
85501
85502 /*
85503 ** Implementation of random(). Return a random integer.
85504 */
@@ -85613,11 +85687,11 @@
85613 ** character is exactly one byte in size. Also, all characters are
85614 ** able to participate in upper-case-to-lower-case mappings in EBCDIC
85615 ** whereas only characters less than 0x80 do in ASCII.
85616 */
85617 #if defined(SQLITE_EBCDIC)
85618 # define sqlite3Utf8Read(A,C) (*(A++))
85619 # define GlogUpperToLower(A) A = sqlite3UpperToLower[A]
85620 #else
85621 # define GlogUpperToLower(A) if( !((A)&~0x7f) ){ A = sqlite3UpperToLower[A]; }
85622 #endif
85623
@@ -85670,22 +85744,22 @@
85670 u8 matchAll = pInfo->matchAll;
85671 u8 matchSet = pInfo->matchSet;
85672 u8 noCase = pInfo->noCase;
85673 int prevEscape = 0; /* True if the previous character was 'escape' */
85674
85675 while( (c = sqlite3Utf8Read(zPattern,&zPattern))!=0 ){
85676 if( !prevEscape && c==matchAll ){
85677 while( (c=sqlite3Utf8Read(zPattern,&zPattern)) == matchAll
85678 || c == matchOne ){
85679 if( c==matchOne && sqlite3Utf8Read(zString, &zString)==0 ){
85680 return 0;
85681 }
85682 }
85683 if( c==0 ){
85684 return 1;
85685 }else if( c==esc ){
85686 c = sqlite3Utf8Read(zPattern, &zPattern);
85687 if( c==0 ){
85688 return 0;
85689 }
85690 }else if( c==matchSet ){
85691 assert( esc==0 ); /* This is GLOB, not LIKE */
@@ -85693,67 +85767,67 @@
85693 while( *zString && patternCompare(&zPattern[-1],zString,pInfo,esc)==0 ){
85694 SQLITE_SKIP_UTF8(zString);
85695 }
85696 return *zString!=0;
85697 }
85698 while( (c2 = sqlite3Utf8Read(zString,&zString))!=0 ){
85699 if( noCase ){
85700 GlogUpperToLower(c2);
85701 GlogUpperToLower(c);
85702 while( c2 != 0 && c2 != c ){
85703 c2 = sqlite3Utf8Read(zString, &zString);
85704 GlogUpperToLower(c2);
85705 }
85706 }else{
85707 while( c2 != 0 && c2 != c ){
85708 c2 = sqlite3Utf8Read(zString, &zString);
85709 }
85710 }
85711 if( c2==0 ) return 0;
85712 if( patternCompare(zPattern,zString,pInfo,esc) ) return 1;
85713 }
85714 return 0;
85715 }else if( !prevEscape && c==matchOne ){
85716 if( sqlite3Utf8Read(zString, &zString)==0 ){
85717 return 0;
85718 }
85719 }else if( c==matchSet ){
85720 u32 prior_c = 0;
85721 assert( esc==0 ); /* This only occurs for GLOB, not LIKE */
85722 seen = 0;
85723 invert = 0;
85724 c = sqlite3Utf8Read(zString, &zString);
85725 if( c==0 ) return 0;
85726 c2 = sqlite3Utf8Read(zPattern, &zPattern);
85727 if( c2=='^' ){
85728 invert = 1;
85729 c2 = sqlite3Utf8Read(zPattern, &zPattern);
85730 }
85731 if( c2==']' ){
85732 if( c==']' ) seen = 1;
85733 c2 = sqlite3Utf8Read(zPattern, &zPattern);
85734 }
85735 while( c2 && c2!=']' ){
85736 if( c2=='-' && zPattern[0]!=']' && zPattern[0]!=0 && prior_c>0 ){
85737 c2 = sqlite3Utf8Read(zPattern, &zPattern);
85738 if( c>=prior_c && c<=c2 ) seen = 1;
85739 prior_c = 0;
85740 }else{
85741 if( c==c2 ){
85742 seen = 1;
85743 }
85744 prior_c = c2;
85745 }
85746 c2 = sqlite3Utf8Read(zPattern, &zPattern);
85747 }
85748 if( c2==0 || (seen ^ invert)==0 ){
85749 return 0;
85750 }
85751 }else if( esc==c && !prevEscape ){
85752 prevEscape = 1;
85753 }else{
85754 c2 = sqlite3Utf8Read(zString, &zString);
85755 if( noCase ){
85756 GlogUpperToLower(c);
85757 GlogUpperToLower(c2);
85758 }
85759 if( c!=c2 ){
@@ -85821,11 +85895,11 @@
85821 if( sqlite3Utf8CharLen((char*)zEsc, -1)!=1 ){
85822 sqlite3_result_error(context,
85823 "ESCAPE expression must be a single character", -1);
85824 return;
85825 }
85826 escape = sqlite3Utf8Read(zEsc, &zEsc);
85827 }
85828 if( zA && zB ){
85829 struct compareInfo *pInfo = sqlite3_user_data(context);
85830 #ifdef SQLITE_TEST
85831 sqlite3_like_count++;
@@ -87653,11 +87727,12 @@
87653 for(i=0; i<p->nCol; i++){
87654 char *zKey = p->aCol[i].zCol;
87655 int iKey;
87656 for(iKey=0; iKey<pTab->nCol; iKey++){
87657 Column *pCol = &pTab->aCol[iKey];
87658 if( (zKey ? !sqlite3StrICmp(pCol->zName, zKey) : pCol->isPrimKey) ){
 
87659 if( aChange[iKey]>=0 ) return 1;
87660 if( iKey==pTab->iPKey && chngRowid ) return 1;
87661 }
87662 }
87663 }
@@ -88268,10 +88343,101 @@
88268 */
88269 # define autoIncBegin(A,B,C) (0)
88270 # define autoIncStep(A,B,C)
88271 #endif /* SQLITE_OMIT_AUTOINCREMENT */
88272
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88273
88274 /* Forward declaration */
88275 static int xferOptimization(
88276 Parse *pParse, /* Parser context */
88277 Table *pDest, /* The table we are inserting into */
@@ -88517,55 +88683,16 @@
88517 ** is coming from a SELECT statement, then generate a co-routine that
88518 ** produces a single row of the SELECT on each invocation. The
88519 ** co-routine is the common header to the 3rd and 4th templates.
88520 */
88521 if( pSelect ){
88522 /* Data is coming from a SELECT. Generate code to implement that SELECT
88523 ** as a co-routine. The code is common to both the 3rd and 4th
88524 ** templates:
88525 **
88526 ** EOF <- 0
88527 ** X <- A
88528 ** goto B
88529 ** A: setup for the SELECT
88530 ** loop over the tables in the SELECT
88531 ** load value into register R..R+n
88532 ** yield X
88533 ** end loop
88534 ** cleanup after the SELECT
88535 ** EOF <- 1
88536 ** yield X
88537 ** halt-error
88538 **
88539 ** On each invocation of the co-routine, it puts a single row of the
88540 ** SELECT result into registers dest.iMem...dest.iMem+dest.nMem-1.
88541 ** (These output registers are allocated by sqlite3Select().) When
88542 ** the SELECT completes, it sets the EOF flag stored in regEof.
88543 */
88544 int rc, j1;
88545
88546 regEof = ++pParse->nMem;
88547 sqlite3VdbeAddOp2(v, OP_Integer, 0, regEof); /* EOF <- 0 */
88548 VdbeComment((v, "SELECT eof flag"));
88549 sqlite3SelectDestInit(&dest, SRT_Coroutine, ++pParse->nMem);
88550 addrSelect = sqlite3VdbeCurrentAddr(v)+2;
88551 sqlite3VdbeAddOp2(v, OP_Integer, addrSelect-1, dest.iSDParm);
88552 j1 = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);
88553 VdbeComment((v, "Jump over SELECT coroutine"));
88554
88555 /* Resolve the expressions in the SELECT statement and execute it. */
88556 rc = sqlite3Select(pParse, pSelect, &dest);
88557 assert( pParse->nErr==0 || rc );
88558 if( rc || NEVER(pParse->nErr) || db->mallocFailed ){
88559 goto insert_cleanup;
88560 }
88561 sqlite3VdbeAddOp2(v, OP_Integer, 1, regEof); /* EOF <- 1 */
88562 sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm); /* yield X */
88563 sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_INTERNAL, OE_Abort);
88564 VdbeComment((v, "End of SELECT coroutine"));
88565 sqlite3VdbeJumpHere(v, j1); /* label B: */
88566
88567 regFromSelect = dest.iSdst;
88568 assert( pSelect->pEList );
88569 nColumn = pSelect->pEList->nExpr;
88570 assert( dest.nSdst==nColumn );
88571
@@ -92035,11 +92162,12 @@
92035 if( pCol->zDflt ){
92036 sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, (char*)pCol->zDflt, 0);
92037 }else{
92038 sqlite3VdbeAddOp2(v, OP_Null, 0, 5);
92039 }
92040 sqlite3VdbeAddOp2(v, OP_Integer, pCol->isPrimKey, 6);
 
92041 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
92042 }
92043 }
92044 }else
92045
@@ -94803,11 +94931,11 @@
94803 ** store NULL in *paCol and 0 in *pnCol and return SQLITE_NOMEM.
94804 */
94805 static int selectColumnsFromExprList(
94806 Parse *pParse, /* Parsing context */
94807 ExprList *pEList, /* Expr list from which to derive column names */
94808 int *pnCol, /* Write the number of columns here */
94809 Column **paCol /* Write the new column list here */
94810 ){
94811 sqlite3 *db = pParse->db; /* Database connection */
94812 int i, j; /* Loop counters */
94813 int cnt; /* Index added to make the name unique */
@@ -95449,10 +95577,11 @@
95449 *apColl = multiSelectCollSeq(pParse, p, i);
95450 if( 0==*apColl ){
95451 *apColl = db->pDfltColl;
95452 }
95453 }
 
95454
95455 for(pLoop=p; pLoop; pLoop=pLoop->pPrior){
95456 for(i=0; i<2; i++){
95457 int addr = pLoop->addrOpenEphm[i];
95458 if( addr<0 ){
@@ -101068,11 +101197,11 @@
101068 }else{
101069 int iCol;
101070 /* If everything went according to plan, link the new VTable structure
101071 ** into the linked list headed by pTab->pVTable. Then loop through the
101072 ** columns of the table to see if any of them contain the token "hidden".
101073 ** If so, set the Column.isHidden flag and remove the token from
101074 ** the type string. */
101075 pVTable->pNext = pTab->pVTable;
101076 pTab->pVTable = pVTable;
101077
101078 for(iCol=0; iCol<pTab->nCol; iCol++){
@@ -101099,11 +101228,11 @@
101099 }
101100 if( zType[i]=='\0' && i>0 ){
101101 assert(zType[i-1]==' ');
101102 zType[i-1] = '\0';
101103 }
101104 pTab->aCol[iCol].isHidden = 1;
101105 }
101106 }
101107 }
101108 }
101109
@@ -101901,10 +102030,11 @@
101901 #define WHERE_UNIQUE 0x04000000 /* Selects no more than one row */
101902 #define WHERE_VIRTUALTABLE 0x08000000 /* Use virtual-table processing */
101903 #define WHERE_MULTI_OR 0x10000000 /* OR using multiple indices */
101904 #define WHERE_TEMP_INDEX 0x20000000 /* Uses an ephemeral index */
101905 #define WHERE_DISTINCT 0x40000000 /* Correct order for DISTINCT */
 
101906
101907 /*
101908 ** Initialize a preallocated WhereClause structure.
101909 */
101910 static void whereClauseInit(
@@ -104770,11 +104900,11 @@
104770 /* If currently calculating the cost of using an index (not the IPK
104771 ** index), determine if all required column data may be obtained without
104772 ** using the main table (i.e. if the index is a covering
104773 ** index for this query). If it is, set the WHERE_IDX_ONLY flag in
104774 ** wsFlags. Otherwise, set the bLookup variable to true. */
104775 if( pIdx && wsFlags ){
104776 Bitmask m = pSrc->colUsed;
104777 int j;
104778 for(j=0; j<pIdx->nColumn; j++){
104779 int x = pIdx->aiColumn[j];
104780 if( x<BMS-1 ){
@@ -104835,11 +104965,24 @@
104835 ** The ANALYZE command and the sqlite_stat1 and sqlite_stat3 tables do
104836 ** not give us data on the relative sizes of table and index records.
104837 ** So this computation assumes table records are about twice as big
104838 ** as index records
104839 */
104840 if( (wsFlags & WHERE_NOT_FULLSCAN)==0 ){
 
 
 
 
 
 
 
 
 
 
 
 
 
104841 /* The cost of a full table scan is a number of move operations equal
104842 ** to the number of rows in the table.
104843 **
104844 ** We add an additional 4x penalty to full table scans. This causes
104845 ** the cost function to err on the side of choosing an index over
@@ -104846,10 +104989,11 @@
104846 ** choosing a full scan. This 4x full-scan penalty is an arguable
104847 ** decision and one which we expect to revisit in the future. But
104848 ** it seems to be working well enough at the moment.
104849 */
104850 cost = aiRowEst[0]*4;
 
104851 }else{
104852 log10N = estLog(aiRowEst[0]);
104853 cost = nRow;
104854 if( pIdx ){
104855 if( bLookup ){
@@ -105889,10 +106033,15 @@
105889 pLevel->op = OP_Prev;
105890 }else{
105891 pLevel->op = OP_Next;
105892 }
105893 pLevel->p1 = iIdxCur;
 
 
 
 
 
105894 }else
105895
105896 #ifndef SQLITE_OMIT_OR_OPTIMIZATION
105897 if( pLevel->plan.wsFlags & WHERE_MULTI_OR ){
105898 /* Case 4: Two or more separately indexed terms connected by OR
@@ -106765,31 +106914,33 @@
106765 ** index name is '*'.
106766 */
106767 for(i=0; i<nTabList; i++){
106768 char *z;
106769 int n;
 
106770 pLevel = &pWInfo->a[i];
 
106771 pTabItem = &pTabList->a[pLevel->iFrom];
106772 z = pTabItem->zAlias;
106773 if( z==0 ) z = pTabItem->pTab->zName;
106774 n = sqlite3Strlen30(z);
106775 if( n+nQPlan < sizeof(sqlite3_query_plan)-10 ){
106776 if( pLevel->plan.wsFlags & WHERE_IDX_ONLY ){
106777 memcpy(&sqlite3_query_plan[nQPlan], "{}", 2);
106778 nQPlan += 2;
106779 }else{
106780 memcpy(&sqlite3_query_plan[nQPlan], z, n);
106781 nQPlan += n;
106782 }
106783 sqlite3_query_plan[nQPlan++] = ' ';
106784 }
106785 testcase( pLevel->plan.wsFlags & WHERE_ROWID_EQ );
106786 testcase( pLevel->plan.wsFlags & WHERE_ROWID_RANGE );
106787 if( pLevel->plan.wsFlags & (WHERE_ROWID_EQ|WHERE_ROWID_RANGE) ){
106788 memcpy(&sqlite3_query_plan[nQPlan], "* ", 2);
106789 nQPlan += 2;
106790 }else if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
106791 n = sqlite3Strlen30(pLevel->plan.u.pIdx->zName);
106792 if( n+nQPlan < sizeof(sqlite3_query_plan)-2 ){
106793 memcpy(&sqlite3_query_plan[nQPlan], pLevel->plan.u.pIdx->zName, n);
106794 nQPlan += n;
106795 sqlite3_query_plan[nQPlan++] = ' ';
@@ -112076,10 +112227,15 @@
112076
112077 case SQLITE_CONFIG_URI: {
112078 sqlite3GlobalConfig.bOpenUri = va_arg(ap, int);
112079 break;
112080 }
 
 
 
 
 
112081
112082 default: {
112083 rc = SQLITE_ERROR;
112084 break;
112085 }
@@ -113368,10 +113524,19 @@
113368 if( !db || db->mallocFailed ){
113369 return SQLITE_NOMEM;
113370 }
113371 return db->errCode;
113372 }
 
 
 
 
 
 
 
 
 
113373
113374 /*
113375 ** Create a new collating function for database "db". The name is zName
113376 ** and the encoding is enc.
113377 */
@@ -114343,11 +114508,11 @@
114343 */
114344 if( pCol ){
114345 zDataType = pCol->zType;
114346 zCollSeq = pCol->zColl;
114347 notnull = pCol->notNull!=0;
114348 primarykey = pCol->isPrimKey!=0;
114349 autoinc = pTab->iPKey==iCol && (pTab->tabFlags & TF_Autoincrement)!=0;
114350 }else{
114351 zDataType = "INTEGER";
114352 primarykey = 1;
114353 }
114354
--- 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.15. 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.
@@ -671,13 +671,13 @@
671 **
672 ** See also: [sqlite3_libversion()],
673 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
674 ** [sqlite_version()] and [sqlite_source_id()].
675 */
676 #define SQLITE_VERSION "3.7.15"
677 #define SQLITE_VERSION_NUMBER 3007015
678 #define SQLITE_SOURCE_ID "2012-09-17 21:24:01 698b2a28004a9a2f0eabaadf36d833da4400b2bf"
679
680 /*
681 ** CAPI3REF: Run-Time Library Version Numbers
682 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
683 **
@@ -1042,10 +1042,11 @@
1042 #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
1043 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
1044 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
1045 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
1046 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
1047 #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
1048 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
1049 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
1050 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
1051 #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
1052
@@ -2130,10 +2131,22 @@
2131 ** connection is opened. If it is globally disabled, filenames are
2132 ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
2133 ** database connection is opened. By default, URI handling is globally
2134 ** disabled. The default value may be changed by compiling with the
2135 ** [SQLITE_USE_URI] symbol defined.
2136 **
2137 ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
2138 ** <dd> This option taks a single integer argument which is interpreted as
2139 ** a boolean in order to enable or disable the use of covering indices for
2140 ** full table scans in the query optimizer. The default setting is determined
2141 ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
2142 ** if that compile-time option is omitted.
2143 ** The ability to disable the use of covering indices for full table scans
2144 ** is because some incorrectly coded legacy applications might malfunction
2145 ** malfunction when the optimization is enabled. Providing the ability to
2146 ** disable the optimization allows the older, buggy application code to work
2147 ** without change even with newer versions of SQLite.
2148 **
2149 ** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]]
2150 ** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE
2151 ** <dd> These options are obsolete and should not be used by new code.
2152 ** They are retained for backwards compatibility but are now no-ops.
@@ -2156,10 +2169,11 @@
2169 #define SQLITE_CONFIG_GETPCACHE 15 /* no-op */
2170 #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
2171 #define SQLITE_CONFIG_URI 17 /* int */
2172 #define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */
2173 #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
2174 #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
2175
2176 /*
2177 ** CAPI3REF: Database Connection Configuration Options
2178 **
2179 ** These constants are the available integer configuration options that
@@ -3164,11 +3178,11 @@
3178 ** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw",
3179 ** "rwc", or "memory". Attempting to set it to any other value is
3180 ** an error)^.
3181 ** ^If "ro" is specified, then the database is opened for read-only
3182 ** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the
3183 ** third argument to sqlite3_open_v2(). ^If the mode option is set to
3184 ** "rw", then the database is opened for read-write (but not create)
3185 ** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had
3186 ** been set. ^Value "rwc" is equivalent to setting both
3187 ** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If the mode option is
3188 ** set to "memory" then a pure [in-memory database] that never reads
@@ -3315,10 +3329,15 @@
3329 ** text that describes the error, as either UTF-8 or UTF-16 respectively.
3330 ** ^(Memory to hold the error message string is managed internally.
3331 ** The application does not need to worry about freeing the result.
3332 ** However, the error string might be overwritten or deallocated by
3333 ** subsequent calls to other SQLite interface functions.)^
3334 **
3335 ** ^The sqlite3_errstr() interface returns the English-language text
3336 ** that describes the [result code], as UTF-8.
3337 ** ^(Memory to hold the error message string is managed internally
3338 ** and must not be freed by the application)^.
3339 **
3340 ** When the serialized [threading mode] is in use, it might be the
3341 ** case that a second error occurs on a separate thread in between
3342 ** the time of the first error and the call to these interfaces.
3343 ** When that happens, the second error will be reported since these
@@ -3334,10 +3353,11 @@
3353 */
3354 SQLITE_API int sqlite3_errcode(sqlite3 *db);
3355 SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
3356 SQLITE_API const char *sqlite3_errmsg(sqlite3*);
3357 SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
3358 SQLITE_API const char *sqlite3_errstr(int);
3359
3360 /*
3361 ** CAPI3REF: SQL Statement Object
3362 ** KEYWORDS: {prepared statement} {prepared statements}
3363 **
@@ -9959,20 +9979,18 @@
9979 /*
9980 ** Bits of the sqlite3.flags field that are used by the
9981 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface.
9982 ** These must be the low-order bits of the flags field.
9983 */
9984 #define SQLITE_QueryFlattener 0x01 /* Disable query flattening */
9985 #define SQLITE_ColumnCache 0x02 /* Disable the column cache */
9986 #define SQLITE_GroupByOrder 0x04 /* Disable GROUPBY cover of ORDERBY */
9987 #define SQLITE_FactorOutConst 0x08 /* Disable factoring out constants */
9988 #define SQLITE_IdxRealAsInt 0x10 /* Store REAL as INT in indices */
9989 #define SQLITE_DistinctOpt 0x20 /* DISTINCT using indexes */
9990 #define SQLITE_CoverIdxScan 0x40 /* Disable covering index scans */
9991 #define SQLITE_OptMask 0xff /* Mask of all disablable opts */
 
 
9992
9993 /*
9994 ** Possible values for the sqlite.magic field.
9995 ** The numbers are obtained at random and have no special meaning, other
9996 ** than being distinct from one another.
@@ -10119,18 +10137,20 @@
10137 char *zName; /* Name of this column */
10138 Expr *pDflt; /* Default value of this column */
10139 char *zDflt; /* Original text of the default value */
10140 char *zType; /* Data type for this column */
10141 char *zColl; /* Collating sequence. If NULL, use the default */
10142 u8 notNull; /* An OE_ code for handling a NOT NULL constraint */
 
10143 char affinity; /* One of the SQLITE_AFF_... values */
10144 u16 colFlags; /* Boolean properties. See COLFLAG_ defines below */
 
 
10145 };
10146
10147 /* Allowed values for Column.colFlags:
10148 */
10149 #define COLFLAG_PRIMKEY 0x0001 /* Column is part of the primary key */
10150 #define COLFLAG_HIDDEN 0x0002 /* A hidden column in a virtual table */
10151
10152 /*
10153 ** A "Collating Sequence" is defined by an instance of the following
10154 ** structure. Conceptually, a collating sequence consists of a name and
10155 ** a comparison routine that defines the order of that sequence.
10156 **
@@ -10282,32 +10302,32 @@
10302 ** sub-query that appears instead of a real table name in the FROM clause
10303 ** of a SELECT statement.
10304 */
10305 struct Table {
10306 char *zName; /* Name of the table or view */
 
 
10307 Column *aCol; /* Information about each column */
10308 Index *pIndex; /* List of SQL indexes on this table. */
 
 
10309 Select *pSelect; /* NULL for tables. Points to definition if a view. */
 
 
 
10310 FKey *pFKey; /* Linked list of all foreign keys in this table */
10311 char *zColAff; /* String defining the affinity of each column */
10312 #ifndef SQLITE_OMIT_CHECK
10313 ExprList *pCheck; /* All CHECK constraints */
10314 #endif
10315 tRowcnt nRowEst; /* Estimated rows in table - from sqlite_stat1 table */
10316 int tnum; /* Root BTree node for this table (see note above) */
10317 i16 iPKey; /* If not negative, use aCol[iPKey] as the primary key */
10318 i16 nCol; /* Number of columns in this table */
10319 u16 nRef; /* Number of pointers to this Table */
10320 u8 tabFlags; /* Mask of TF_* values */
10321 u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
10322 #ifndef SQLITE_OMIT_ALTERTABLE
10323 int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */
10324 #endif
10325 #ifndef SQLITE_OMIT_VIRTUALTABLE
 
10326 int nModuleArg; /* Number of arguments to the module */
10327 char **azModuleArg; /* Text of all module args. [0] is module name */
10328 VTable *pVTable; /* List of VTable objects. */
10329 #endif
10330 Trigger *pTrigger; /* List of triggers stored in pSchema */
10331 Schema *pSchema; /* Schema that contains this table */
10332 Table *pNextZombie; /* Next on the Parse.pZombieTab list */
10333 };
@@ -10327,11 +10347,11 @@
10347 ** done as a macro so that it will be optimized out when virtual
10348 ** table support is omitted from the build.
10349 */
10350 #ifndef SQLITE_OMIT_VIRTUALTABLE
10351 # define IsVirtual(X) (((X)->tabFlags & TF_Virtual)!=0)
10352 # define IsHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0)
10353 #else
10354 # define IsVirtual(X) 0
10355 # define IsHiddenColumn(X) 0
10356 #endif
10357
@@ -10679,10 +10699,13 @@
10699 /* If the EP_Reduced flag is set in the Expr.flags mask, then no
10700 ** space is allocated for the fields below this point. An attempt to
10701 ** access them will result in a segfault or malfunction.
10702 *********************************************************************/
10703
10704 #if SQLITE_MAX_EXPR_DEPTH>0
10705 int nHeight; /* Height of the tree headed by this node */
10706 #endif
10707 int iTable; /* TK_COLUMN: cursor number of table holding column
10708 ** TK_REGISTER: register number
10709 ** TK_TRIGGER: 1 -> new, 0 -> old */
10710 ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
10711 ** TK_VARIABLE: variable number (always >= 1). */
@@ -10692,13 +10715,10 @@
10715 u8 op2; /* TK_REGISTER: original value of Expr.op
10716 ** TK_COLUMN: the value of p5 for OP_Column
10717 ** TK_AGG_FUNCTION: nesting depth */
10718 AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
10719 Table *pTab; /* Table for TK_COLUMN expressions. */
 
 
 
10720 };
10721
10722 /*
10723 ** The following are the meanings of bits in the Expr.flags field.
10724 */
@@ -11459,10 +11479,11 @@
11479 struct Sqlite3Config {
11480 int bMemstat; /* True to enable memory status */
11481 int bCoreMutex; /* True to enable core mutexing */
11482 int bFullMutex; /* True to enable full mutexing */
11483 int bOpenUri; /* True to interpret filenames as URIs */
11484 int bUseCis; /* Use covering indices for full-scans */
11485 int mxStrlen; /* Maximum string length */
11486 int szLookaside; /* Default lookaside buffer size */
11487 int nLookaside; /* Default lookaside buffer count */
11488 sqlite3_mem_methods m; /* Low-level memory allocation interface */
11489 sqlite3_mutex_methods mutex; /* Low-level mutex interface */
@@ -11775,10 +11796,11 @@
11796 SQLITE_PRIVATE void sqlite3AutoincrementEnd(Parse *pParse);
11797 #else
11798 # define sqlite3AutoincrementBegin(X)
11799 # define sqlite3AutoincrementEnd(X)
11800 #endif
11801 SQLITE_PRIVATE int sqlite3CodeCoroutine(Parse*, Select*, SelectDest*);
11802 SQLITE_PRIVATE void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int);
11803 SQLITE_PRIVATE void *sqlite3ArrayAllocate(sqlite3*,void*,int,int*,int*);
11804 SQLITE_PRIVATE IdList *sqlite3IdListAppend(sqlite3*, IdList*, Token*);
11805 SQLITE_PRIVATE int sqlite3IdListIndex(IdList*,const char*);
11806 SQLITE_PRIVATE SrcList *sqlite3SrcListEnlarge(sqlite3*, SrcList*, int, int);
@@ -11950,11 +11972,11 @@
11972 SQLITE_PRIVATE int sqlite3AtoF(const char *z, double*, int, u8);
11973 SQLITE_PRIVATE int sqlite3GetInt32(const char *, int*);
11974 SQLITE_PRIVATE int sqlite3Atoi(const char*);
11975 SQLITE_PRIVATE int sqlite3Utf16ByteLen(const void *pData, int nChar);
11976 SQLITE_PRIVATE int sqlite3Utf8CharLen(const char *pData, int nByte);
11977 SQLITE_PRIVATE u32 sqlite3Utf8Read(const u8**);
11978
11979 /*
11980 ** Routines to read and write variable-length integers. These used to
11981 ** be defined locally, but now we use the varint routines in the util.c
11982 ** file. Code should use the MACRO forms below, as the Varint32 versions
@@ -12450,19 +12472,24 @@
12472
12473 #ifndef SQLITE_USE_URI
12474 # define SQLITE_USE_URI 0
12475 #endif
12476
12477 #ifndef SQLITE_ALLOW_COVERING_INDEX_SCAN
12478 # define SQLITE_ALLOW_COVERING_INDEX_SCAN 1
12479 #endif
12480
12481 /*
12482 ** The following singleton contains the global configuration for
12483 ** the SQLite library.
12484 */
12485 SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = {
12486 SQLITE_DEFAULT_MEMSTATUS, /* bMemstat */
12487 1, /* bCoreMutex */
12488 SQLITE_THREADSAFE==1, /* bFullMutex */
12489 SQLITE_USE_URI, /* bOpenUri */
12490 SQLITE_ALLOW_COVERING_INDEX_SCAN, /* bUseCis */
12491 0x7ffffffe, /* mxStrlen */
12492 128, /* szLookaside */
12493 500, /* nLookaside */
12494 {0,0,0,0,0,0,0,0}, /* m */
12495 {0,0,0,0,0,0,0,0,0}, /* mutex */
@@ -12876,10 +12903,13 @@
12903 #ifdef SQLITE_PERFORMANCE_TRACE
12904 "PERFORMANCE_TRACE",
12905 #endif
12906 #ifdef SQLITE_PROXY_DEBUG
12907 "PROXY_DEBUG",
12908 #endif
12909 #ifdef SQLITE_RTREE_INT_ONLY
12910 "RTREE_INT_ONLY",
12911 #endif
12912 #ifdef SQLITE_SECURE_DELETE
12913 "SECURE_DELETE",
12914 #endif
12915 #ifdef SQLITE_SMALL_STACK
@@ -13234,10 +13264,15 @@
13264 int nIndent; /* Number of elements in aIndent */
13265 u16 aIndent[100]; /* Levels of indentation */
13266 char zBase[100]; /* Initial space */
13267 };
13268
13269 /* A bitfield type for use inside of structures. Always follow with :N where
13270 ** N is the number of bits.
13271 */
13272 typedef unsigned bft; /* Bit Field Type */
13273
13274 /*
13275 ** An instance of the virtual machine. This structure contains the complete
13276 ** state of the virtual machine.
13277 **
13278 ** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare()
@@ -13275,19 +13310,20 @@
13310 ynVar nzVar; /* Number of entries in azVar[] */
13311 u32 cacheCtr; /* VdbeCursor row cache generation counter */
13312 int pc; /* The program counter */
13313 int rc; /* Value to return */
13314 u8 errorAction; /* Recovery action to do in case of an error */
 
 
 
 
13315 u8 minWriteFileFormat; /* Minimum file format for writable database files */
13316 bft explain:2; /* True if EXPLAIN present on SQL command */
13317 bft inVtabMethod:2; /* See comments above */
13318 bft changeCntOn:1; /* True to update the change-counter */
13319 bft expired:1; /* True if the VM needs to be recompiled */
13320 bft runOnlyOnce:1; /* Automatically expire on reset */
13321 bft usesStmtJournal:1; /* True if uses a statement journal */
13322 bft readOnly:1; /* True for read-only statements */
13323 bft isPrepareV2:1; /* True if prepared with prepare_v2() */
13324 bft doingRerun:1; /* True if rerunning after an auto-reprepare */
13325 int nChange; /* Number of db changes made since last reset */
13326 yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */
13327 yDbMask lockMask; /* Subset of btreeMask that requires a lock */
13328 int iStatement; /* Statement number (or 0 if has not opened stmt) */
13329 int aCounter[3]; /* Counters used by sqlite3_stmt_status() */
@@ -20525,29 +20561,27 @@
20561 if( c<0x80 \
20562 || (c&0xFFFFF800)==0xD800 \
20563 || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } \
20564 }
20565 SQLITE_PRIVATE u32 sqlite3Utf8Read(
20566 const unsigned char **pz /* Pointer to string from which to read char */
 
20567 ){
20568 unsigned int c;
20569
20570 /* Same as READ_UTF8() above but without the zTerm parameter.
20571 ** For this routine, we assume the UTF8 string is always zero-terminated.
20572 */
20573 c = *((*pz)++);
20574 if( c>=0xc0 ){
20575 c = sqlite3Utf8Trans1[c-0xc0];
20576 while( (*(*pz) & 0xc0)==0x80 ){
20577 c = (c<<6) + (0x3f & *((*pz)++));
20578 }
20579 if( c<0x80
20580 || (c&0xFFFFF800)==0xD800
20581 || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; }
20582 }
 
20583 return c;
20584 }
20585
20586
20587
@@ -20644,19 +20678,17 @@
20678
20679 if( pMem->enc==SQLITE_UTF8 ){
20680 if( desiredEnc==SQLITE_UTF16LE ){
20681 /* UTF-8 -> UTF-16 Little-endian */
20682 while( zIn<zTerm ){
 
20683 READ_UTF8(zIn, zTerm, c);
20684 WRITE_UTF16LE(z, c);
20685 }
20686 }else{
20687 assert( desiredEnc==SQLITE_UTF16BE );
20688 /* UTF-8 -> UTF-16 Big-endian */
20689 while( zIn<zTerm ){
 
20690 READ_UTF8(zIn, zTerm, c);
20691 WRITE_UTF16BE(z, c);
20692 }
20693 }
20694 pMem->n = (int)(z - zOut);
@@ -20780,11 +20812,11 @@
20812 unsigned char *zOut = zIn;
20813 unsigned char *zStart = zIn;
20814 u32 c;
20815
20816 while( zIn[0] && zOut<=zIn ){
20817 c = sqlite3Utf8Read((const u8**)&zIn);
20818 if( c!=0xfffd ){
20819 WRITE_UTF8(zOut, c);
20820 }
20821 }
20822 *zOut = 0;
@@ -20885,11 +20917,11 @@
20917 WRITE_UTF8(z, i);
20918 n = (int)(z-zBuf);
20919 assert( n>0 && n<=4 );
20920 z[0] = 0;
20921 z = zBuf;
20922 c = sqlite3Utf8Read((const u8**)&z);
20923 t = i;
20924 if( i>=0xD800 && i<=0xDFFF ) t = 0xFFFD;
20925 if( (i&0xFFFFFFFE)==0xFFFE ) t = 0xFFFD;
20926 assert( c==t );
20927 assert( (z-zBuf)==n );
@@ -29887,10 +29919,19 @@
29919 #endif /* !defined(_OS_COMMON_H_) */
29920
29921 /************** End of os_common.h *******************************************/
29922 /************** Continuing where we left off in os_win.c *********************/
29923
29924 /*
29925 ** Compiling and using WAL mode requires several APIs that are only
29926 ** available in Windows platforms based on the NT kernel.
29927 */
29928 #if !SQLITE_OS_WINNT && !defined(SQLITE_OMIT_WAL)
29929 # error "WAL mode requires support from the Windows NT kernel, compile\
29930 with SQLITE_OMIT_WAL."
29931 #endif
29932
29933 /*
29934 ** Macro to find the minimum of two numeric values.
29935 */
29936 #ifndef MIN
29937 # define MIN(x,y) ((x)<(y)?(x):(y))
@@ -30170,166 +30211,176 @@
30211 { "CreateFileW", (SYSCALL)0, 0 },
30212 #endif
30213
30214 #define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \
30215 LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent)
30216
30217 #if (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_ANSI) && \
30218 !defined(SQLITE_OMIT_WAL))
30219 { "CreateFileMappingA", (SYSCALL)CreateFileMappingA, 0 },
30220 #else
30221 { "CreateFileMappingA", (SYSCALL)0, 0 },
30222 #endif
30223
30224 #define osCreateFileMappingA ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \
30225 DWORD,DWORD,DWORD,LPCSTR))aSyscall[6].pCurrent)
30226
30227 #if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \
30228 !defined(SQLITE_OMIT_WAL))
30229 { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 },
30230 #else
30231 { "CreateFileMappingW", (SYSCALL)0, 0 },
30232 #endif
30233
30234 #define osCreateFileMappingW ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \
30235 DWORD,DWORD,DWORD,LPCWSTR))aSyscall[7].pCurrent)
30236
30237 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
30238 { "CreateMutexW", (SYSCALL)CreateMutexW, 0 },
30239 #else
30240 { "CreateMutexW", (SYSCALL)0, 0 },
30241 #endif
30242
30243 #define osCreateMutexW ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,BOOL, \
30244 LPCWSTR))aSyscall[8].pCurrent)
30245
30246 #if defined(SQLITE_WIN32_HAS_ANSI)
30247 { "DeleteFileA", (SYSCALL)DeleteFileA, 0 },
30248 #else
30249 { "DeleteFileA", (SYSCALL)0, 0 },
30250 #endif
30251
30252 #define osDeleteFileA ((BOOL(WINAPI*)(LPCSTR))aSyscall[9].pCurrent)
30253
30254 #if defined(SQLITE_WIN32_HAS_WIDE)
30255 { "DeleteFileW", (SYSCALL)DeleteFileW, 0 },
30256 #else
30257 { "DeleteFileW", (SYSCALL)0, 0 },
30258 #endif
30259
30260 #define osDeleteFileW ((BOOL(WINAPI*)(LPCWSTR))aSyscall[10].pCurrent)
30261
30262 #if SQLITE_OS_WINCE
30263 { "FileTimeToLocalFileTime", (SYSCALL)FileTimeToLocalFileTime, 0 },
30264 #else
30265 { "FileTimeToLocalFileTime", (SYSCALL)0, 0 },
30266 #endif
30267
30268 #define osFileTimeToLocalFileTime ((BOOL(WINAPI*)(CONST FILETIME*, \
30269 LPFILETIME))aSyscall[11].pCurrent)
30270
30271 #if SQLITE_OS_WINCE
30272 { "FileTimeToSystemTime", (SYSCALL)FileTimeToSystemTime, 0 },
30273 #else
30274 { "FileTimeToSystemTime", (SYSCALL)0, 0 },
30275 #endif
30276
30277 #define osFileTimeToSystemTime ((BOOL(WINAPI*)(CONST FILETIME*, \
30278 LPSYSTEMTIME))aSyscall[12].pCurrent)
30279
30280 { "FlushFileBuffers", (SYSCALL)FlushFileBuffers, 0 },
30281
30282 #define osFlushFileBuffers ((BOOL(WINAPI*)(HANDLE))aSyscall[13].pCurrent)
30283
30284 #if defined(SQLITE_WIN32_HAS_ANSI)
30285 { "FormatMessageA", (SYSCALL)FormatMessageA, 0 },
30286 #else
30287 { "FormatMessageA", (SYSCALL)0, 0 },
30288 #endif
30289
30290 #define osFormatMessageA ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPSTR, \
30291 DWORD,va_list*))aSyscall[14].pCurrent)
30292
30293 #if defined(SQLITE_WIN32_HAS_WIDE)
30294 { "FormatMessageW", (SYSCALL)FormatMessageW, 0 },
30295 #else
30296 { "FormatMessageW", (SYSCALL)0, 0 },
30297 #endif
30298
30299 #define osFormatMessageW ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPWSTR, \
30300 DWORD,va_list*))aSyscall[15].pCurrent)
30301
30302 { "FreeLibrary", (SYSCALL)FreeLibrary, 0 },
30303
30304 #define osFreeLibrary ((BOOL(WINAPI*)(HMODULE))aSyscall[16].pCurrent)
30305
30306 { "GetCurrentProcessId", (SYSCALL)GetCurrentProcessId, 0 },
30307
30308 #define osGetCurrentProcessId ((DWORD(WINAPI*)(VOID))aSyscall[17].pCurrent)
30309
30310 #if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_ANSI)
30311 { "GetDiskFreeSpaceA", (SYSCALL)GetDiskFreeSpaceA, 0 },
30312 #else
30313 { "GetDiskFreeSpaceA", (SYSCALL)0, 0 },
30314 #endif
30315
30316 #define osGetDiskFreeSpaceA ((BOOL(WINAPI*)(LPCSTR,LPDWORD,LPDWORD,LPDWORD, \
30317 LPDWORD))aSyscall[18].pCurrent)
30318
30319 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
30320 { "GetDiskFreeSpaceW", (SYSCALL)GetDiskFreeSpaceW, 0 },
30321 #else
30322 { "GetDiskFreeSpaceW", (SYSCALL)0, 0 },
30323 #endif
30324
30325 #define osGetDiskFreeSpaceW ((BOOL(WINAPI*)(LPCWSTR,LPDWORD,LPDWORD,LPDWORD, \
30326 LPDWORD))aSyscall[19].pCurrent)
30327
30328 #if defined(SQLITE_WIN32_HAS_ANSI)
30329 { "GetFileAttributesA", (SYSCALL)GetFileAttributesA, 0 },
30330 #else
30331 { "GetFileAttributesA", (SYSCALL)0, 0 },
30332 #endif
30333
30334 #define osGetFileAttributesA ((DWORD(WINAPI*)(LPCSTR))aSyscall[20].pCurrent)
30335
30336 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
30337 { "GetFileAttributesW", (SYSCALL)GetFileAttributesW, 0 },
30338 #else
30339 { "GetFileAttributesW", (SYSCALL)0, 0 },
30340 #endif
30341
30342 #define osGetFileAttributesW ((DWORD(WINAPI*)(LPCWSTR))aSyscall[21].pCurrent)
30343
30344 #if defined(SQLITE_WIN32_HAS_WIDE)
30345 { "GetFileAttributesExW", (SYSCALL)GetFileAttributesExW, 0 },
30346 #else
30347 { "GetFileAttributesExW", (SYSCALL)0, 0 },
30348 #endif
30349
30350 #define osGetFileAttributesExW ((BOOL(WINAPI*)(LPCWSTR,GET_FILEEX_INFO_LEVELS, \
30351 LPVOID))aSyscall[22].pCurrent)
30352
30353 #if !SQLITE_OS_WINRT
30354 { "GetFileSize", (SYSCALL)GetFileSize, 0 },
30355 #else
30356 { "GetFileSize", (SYSCALL)0, 0 },
30357 #endif
30358
30359 #define osGetFileSize ((DWORD(WINAPI*)(HANDLE,LPDWORD))aSyscall[23].pCurrent)
30360
30361 #if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_ANSI)
30362 { "GetFullPathNameA", (SYSCALL)GetFullPathNameA, 0 },
30363 #else
30364 { "GetFullPathNameA", (SYSCALL)0, 0 },
30365 #endif
30366
30367 #define osGetFullPathNameA ((DWORD(WINAPI*)(LPCSTR,DWORD,LPSTR, \
30368 LPSTR*))aSyscall[24].pCurrent)
30369
30370 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
30371 { "GetFullPathNameW", (SYSCALL)GetFullPathNameW, 0 },
30372 #else
30373 { "GetFullPathNameW", (SYSCALL)0, 0 },
30374 #endif
30375
30376 #define osGetFullPathNameW ((DWORD(WINAPI*)(LPCWSTR,DWORD,LPWSTR, \
30377 LPWSTR*))aSyscall[25].pCurrent)
30378
30379 { "GetLastError", (SYSCALL)GetLastError, 0 },
30380
30381 #define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[26].pCurrent)
30382
30383 #if SQLITE_OS_WINCE
30384 /* The GetProcAddressA() routine is only available on Windows CE. */
30385 { "GetProcAddressA", (SYSCALL)GetProcAddressA, 0 },
30386 #else
@@ -30337,144 +30388,144 @@
30388 ** an ANSI string regardless of the _UNICODE setting */
30389 { "GetProcAddressA", (SYSCALL)GetProcAddress, 0 },
30390 #endif
30391
30392 #define osGetProcAddressA ((FARPROC(WINAPI*)(HMODULE, \
30393 LPCSTR))aSyscall[27].pCurrent)
30394
30395 #if !SQLITE_OS_WINRT
30396 { "GetSystemInfo", (SYSCALL)GetSystemInfo, 0 },
30397 #else
30398 { "GetSystemInfo", (SYSCALL)0, 0 },
30399 #endif
30400
30401 #define osGetSystemInfo ((VOID(WINAPI*)(LPSYSTEM_INFO))aSyscall[28].pCurrent)
30402
30403 { "GetSystemTime", (SYSCALL)GetSystemTime, 0 },
30404
30405 #define osGetSystemTime ((VOID(WINAPI*)(LPSYSTEMTIME))aSyscall[29].pCurrent)
30406
30407 #if !SQLITE_OS_WINCE
30408 { "GetSystemTimeAsFileTime", (SYSCALL)GetSystemTimeAsFileTime, 0 },
30409 #else
30410 { "GetSystemTimeAsFileTime", (SYSCALL)0, 0 },
30411 #endif
30412
30413 #define osGetSystemTimeAsFileTime ((VOID(WINAPI*)( \
30414 LPFILETIME))aSyscall[30].pCurrent)
30415
30416 #if defined(SQLITE_WIN32_HAS_ANSI)
30417 { "GetTempPathA", (SYSCALL)GetTempPathA, 0 },
30418 #else
30419 { "GetTempPathA", (SYSCALL)0, 0 },
30420 #endif
30421
30422 #define osGetTempPathA ((DWORD(WINAPI*)(DWORD,LPSTR))aSyscall[31].pCurrent)
30423
30424 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
30425 { "GetTempPathW", (SYSCALL)GetTempPathW, 0 },
30426 #else
30427 { "GetTempPathW", (SYSCALL)0, 0 },
30428 #endif
30429
30430 #define osGetTempPathW ((DWORD(WINAPI*)(DWORD,LPWSTR))aSyscall[32].pCurrent)
30431
30432 #if !SQLITE_OS_WINRT
30433 { "GetTickCount", (SYSCALL)GetTickCount, 0 },
30434 #else
30435 { "GetTickCount", (SYSCALL)0, 0 },
30436 #endif
30437
30438 #define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[33].pCurrent)
30439
30440 #if defined(SQLITE_WIN32_HAS_ANSI)
30441 { "GetVersionExA", (SYSCALL)GetVersionExA, 0 },
30442 #else
30443 { "GetVersionExA", (SYSCALL)0, 0 },
30444 #endif
30445
30446 #define osGetVersionExA ((BOOL(WINAPI*)( \
30447 LPOSVERSIONINFOA))aSyscall[34].pCurrent)
30448
30449 { "HeapAlloc", (SYSCALL)HeapAlloc, 0 },
30450
30451 #define osHeapAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD, \
30452 SIZE_T))aSyscall[35].pCurrent)
30453
30454 #if !SQLITE_OS_WINRT
30455 { "HeapCreate", (SYSCALL)HeapCreate, 0 },
30456 #else
30457 { "HeapCreate", (SYSCALL)0, 0 },
30458 #endif
30459
30460 #define osHeapCreate ((HANDLE(WINAPI*)(DWORD,SIZE_T, \
30461 SIZE_T))aSyscall[36].pCurrent)
30462
30463 #if !SQLITE_OS_WINRT
30464 { "HeapDestroy", (SYSCALL)HeapDestroy, 0 },
30465 #else
30466 { "HeapDestroy", (SYSCALL)0, 0 },
30467 #endif
30468
30469 #define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[37].pCurrent)
30470
30471 { "HeapFree", (SYSCALL)HeapFree, 0 },
30472
30473 #define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[38].pCurrent)
30474
30475 { "HeapReAlloc", (SYSCALL)HeapReAlloc, 0 },
30476
30477 #define osHeapReAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD,LPVOID, \
30478 SIZE_T))aSyscall[39].pCurrent)
30479
30480 { "HeapSize", (SYSCALL)HeapSize, 0 },
30481
30482 #define osHeapSize ((SIZE_T(WINAPI*)(HANDLE,DWORD, \
30483 LPCVOID))aSyscall[40].pCurrent)
30484
30485 #if !SQLITE_OS_WINRT
30486 { "HeapValidate", (SYSCALL)HeapValidate, 0 },
30487 #else
30488 { "HeapValidate", (SYSCALL)0, 0 },
30489 #endif
30490
30491 #define osHeapValidate ((BOOL(WINAPI*)(HANDLE,DWORD, \
30492 LPCVOID))aSyscall[41].pCurrent)
30493
30494 #if defined(SQLITE_WIN32_HAS_ANSI)
30495 { "LoadLibraryA", (SYSCALL)LoadLibraryA, 0 },
30496 #else
30497 { "LoadLibraryA", (SYSCALL)0, 0 },
30498 #endif
30499
30500 #define osLoadLibraryA ((HMODULE(WINAPI*)(LPCSTR))aSyscall[42].pCurrent)
30501
30502 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
30503 { "LoadLibraryW", (SYSCALL)LoadLibraryW, 0 },
30504 #else
30505 { "LoadLibraryW", (SYSCALL)0, 0 },
30506 #endif
30507
30508 #define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[43].pCurrent)
30509
30510 #if !SQLITE_OS_WINRT
30511 { "LocalFree", (SYSCALL)LocalFree, 0 },
30512 #else
30513 { "LocalFree", (SYSCALL)0, 0 },
30514 #endif
30515
30516 #define osLocalFree ((HLOCAL(WINAPI*)(HLOCAL))aSyscall[44].pCurrent)
30517
30518 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
30519 { "LockFile", (SYSCALL)LockFile, 0 },
30520 #else
30521 { "LockFile", (SYSCALL)0, 0 },
30522 #endif
30523
30524 #ifndef osLockFile
30525 #define osLockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
30526 DWORD))aSyscall[45].pCurrent)
30527 #endif
30528
30529 #if !SQLITE_OS_WINCE
30530 { "LockFileEx", (SYSCALL)LockFileEx, 0 },
30531 #else
@@ -30481,218 +30532,218 @@
30532 { "LockFileEx", (SYSCALL)0, 0 },
30533 #endif
30534
30535 #ifndef osLockFileEx
30536 #define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \
30537 LPOVERLAPPED))aSyscall[46].pCurrent)
30538 #endif
30539
30540 #if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL))
30541 { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 },
30542 #else
30543 { "MapViewOfFile", (SYSCALL)0, 0 },
30544 #endif
30545
30546 #define osMapViewOfFile ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
30547 SIZE_T))aSyscall[47].pCurrent)
30548
30549 { "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 },
30550
30551 #define osMultiByteToWideChar ((int(WINAPI*)(UINT,DWORD,LPCSTR,int,LPWSTR, \
30552 int))aSyscall[48].pCurrent)
30553
30554 { "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 },
30555
30556 #define osQueryPerformanceCounter ((BOOL(WINAPI*)( \
30557 LARGE_INTEGER*))aSyscall[49].pCurrent)
30558
30559 { "ReadFile", (SYSCALL)ReadFile, 0 },
30560
30561 #define osReadFile ((BOOL(WINAPI*)(HANDLE,LPVOID,DWORD,LPDWORD, \
30562 LPOVERLAPPED))aSyscall[50].pCurrent)
30563
30564 { "SetEndOfFile", (SYSCALL)SetEndOfFile, 0 },
30565
30566 #define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[51].pCurrent)
30567
30568 #if !SQLITE_OS_WINRT
30569 { "SetFilePointer", (SYSCALL)SetFilePointer, 0 },
30570 #else
30571 { "SetFilePointer", (SYSCALL)0, 0 },
30572 #endif
30573
30574 #define osSetFilePointer ((DWORD(WINAPI*)(HANDLE,LONG,PLONG, \
30575 DWORD))aSyscall[52].pCurrent)
30576
30577 #if !SQLITE_OS_WINRT
30578 { "Sleep", (SYSCALL)Sleep, 0 },
30579 #else
30580 { "Sleep", (SYSCALL)0, 0 },
30581 #endif
30582
30583 #define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[53].pCurrent)
30584
30585 { "SystemTimeToFileTime", (SYSCALL)SystemTimeToFileTime, 0 },
30586
30587 #define osSystemTimeToFileTime ((BOOL(WINAPI*)(CONST SYSTEMTIME*, \
30588 LPFILETIME))aSyscall[54].pCurrent)
30589
30590 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
30591 { "UnlockFile", (SYSCALL)UnlockFile, 0 },
30592 #else
30593 { "UnlockFile", (SYSCALL)0, 0 },
30594 #endif
30595
30596 #ifndef osUnlockFile
30597 #define osUnlockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
30598 DWORD))aSyscall[55].pCurrent)
30599 #endif
30600
30601 #if !SQLITE_OS_WINCE
30602 { "UnlockFileEx", (SYSCALL)UnlockFileEx, 0 },
30603 #else
30604 { "UnlockFileEx", (SYSCALL)0, 0 },
30605 #endif
30606
30607 #define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
30608 LPOVERLAPPED))aSyscall[56].pCurrent)
30609
30610 #if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL)
30611 { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 },
30612 #else
30613 { "UnmapViewOfFile", (SYSCALL)0, 0 },
30614 #endif
30615
30616 #define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[57].pCurrent)
30617
30618 { "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 },
30619
30620 #define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \
30621 LPCSTR,LPBOOL))aSyscall[58].pCurrent)
30622
30623 { "WriteFile", (SYSCALL)WriteFile, 0 },
30624
30625 #define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \
30626 LPOVERLAPPED))aSyscall[59].pCurrent)
30627
30628 #if SQLITE_OS_WINRT
30629 { "CreateEventExW", (SYSCALL)CreateEventExW, 0 },
30630 #else
30631 { "CreateEventExW", (SYSCALL)0, 0 },
30632 #endif
30633
30634 #define osCreateEventExW ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,LPCWSTR, \
30635 DWORD,DWORD))aSyscall[60].pCurrent)
30636
30637 #if !SQLITE_OS_WINRT
30638 { "WaitForSingleObject", (SYSCALL)WaitForSingleObject, 0 },
30639 #else
30640 { "WaitForSingleObject", (SYSCALL)0, 0 },
30641 #endif
30642
30643 #define osWaitForSingleObject ((DWORD(WINAPI*)(HANDLE, \
30644 DWORD))aSyscall[61].pCurrent)
30645
30646 #if SQLITE_OS_WINRT
30647 { "WaitForSingleObjectEx", (SYSCALL)WaitForSingleObjectEx, 0 },
30648 #else
30649 { "WaitForSingleObjectEx", (SYSCALL)0, 0 },
30650 #endif
30651
30652 #define osWaitForSingleObjectEx ((DWORD(WINAPI*)(HANDLE,DWORD, \
30653 BOOL))aSyscall[62].pCurrent)
30654
30655 #if SQLITE_OS_WINRT
30656 { "SetFilePointerEx", (SYSCALL)SetFilePointerEx, 0 },
30657 #else
30658 { "SetFilePointerEx", (SYSCALL)0, 0 },
30659 #endif
30660
30661 #define osSetFilePointerEx ((BOOL(WINAPI*)(HANDLE,LARGE_INTEGER, \
30662 PLARGE_INTEGER,DWORD))aSyscall[63].pCurrent)
30663
30664 #if SQLITE_OS_WINRT
30665 { "GetFileInformationByHandleEx", (SYSCALL)GetFileInformationByHandleEx, 0 },
30666 #else
30667 { "GetFileInformationByHandleEx", (SYSCALL)0, 0 },
30668 #endif
30669
30670 #define osGetFileInformationByHandleEx ((BOOL(WINAPI*)(HANDLE, \
30671 FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[64].pCurrent)
30672
30673 #if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)
30674 { "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 },
30675 #else
30676 { "MapViewOfFileFromApp", (SYSCALL)0, 0 },
30677 #endif
30678
30679 #define osMapViewOfFileFromApp ((LPVOID(WINAPI*)(HANDLE,ULONG,ULONG64, \
30680 SIZE_T))aSyscall[65].pCurrent)
30681
30682 #if SQLITE_OS_WINRT
30683 { "CreateFile2", (SYSCALL)CreateFile2, 0 },
30684 #else
30685 { "CreateFile2", (SYSCALL)0, 0 },
30686 #endif
30687
30688 #define osCreateFile2 ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD,DWORD, \
30689 LPCREATEFILE2_EXTENDED_PARAMETERS))aSyscall[66].pCurrent)
30690
30691 #if SQLITE_OS_WINRT
30692 { "LoadPackagedLibrary", (SYSCALL)LoadPackagedLibrary, 0 },
30693 #else
30694 { "LoadPackagedLibrary", (SYSCALL)0, 0 },
30695 #endif
30696
30697 #define osLoadPackagedLibrary ((HMODULE(WINAPI*)(LPCWSTR, \
30698 DWORD))aSyscall[67].pCurrent)
30699
30700 #if SQLITE_OS_WINRT
30701 { "GetTickCount64", (SYSCALL)GetTickCount64, 0 },
30702 #else
30703 { "GetTickCount64", (SYSCALL)0, 0 },
30704 #endif
30705
30706 #define osGetTickCount64 ((ULONGLONG(WINAPI*)(VOID))aSyscall[68].pCurrent)
30707
30708 #if SQLITE_OS_WINRT
30709 { "GetNativeSystemInfo", (SYSCALL)GetNativeSystemInfo, 0 },
30710 #else
30711 { "GetNativeSystemInfo", (SYSCALL)0, 0 },
30712 #endif
30713
30714 #define osGetNativeSystemInfo ((VOID(WINAPI*)( \
30715 LPSYSTEM_INFO))aSyscall[69].pCurrent)
30716
30717 #if defined(SQLITE_WIN32_HAS_ANSI)
30718 { "OutputDebugStringA", (SYSCALL)OutputDebugStringA, 0 },
30719 #else
30720 { "OutputDebugStringA", (SYSCALL)0, 0 },
30721 #endif
30722
30723 #define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[70].pCurrent)
30724
30725 #if defined(SQLITE_WIN32_HAS_WIDE)
30726 { "OutputDebugStringW", (SYSCALL)OutputDebugStringW, 0 },
30727 #else
30728 { "OutputDebugStringW", (SYSCALL)0, 0 },
30729 #endif
30730
30731 #define osOutputDebugStringW ((VOID(WINAPI*)(LPCWSTR))aSyscall[71].pCurrent)
30732
30733 { "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 },
30734
30735 #define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[72].pCurrent)
30736
30737 #if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)
30738 { "CreateFileMappingFromApp", (SYSCALL)CreateFileMappingFromApp, 0 },
30739 #else
30740 { "CreateFileMappingFromApp", (SYSCALL)0, 0 },
30741 #endif
30742
30743 #define osCreateFileMappingFromApp ((HANDLE(WINAPI*)(HANDLE, \
30744 LPSECURITY_ATTRIBUTES,ULONG,ULONG64,LPCWSTR))aSyscall[73].pCurrent)
30745
30746 }; /* End of the overrideable system calls */
30747
30748 /*
30749 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
@@ -30846,10 +30897,12 @@
30897 ** WinNT/2K/XP so that we will know whether or not we can safely call
30898 ** the LockFileEx() API.
30899 */
30900 #if SQLITE_OS_WINCE || SQLITE_OS_WINRT
30901 # define isNT() (1)
30902 #elif !defined(SQLITE_WIN32_HAS_WIDE)
30903 # define isNT() (0)
30904 #else
30905 static int isNT(void){
30906 if( sqlite3_os_type==0 ){
30907 OSVERSIONINFOA sInfo;
30908 sInfo.dwOSVersionInfoSize = sizeof(sInfo);
@@ -30856,11 +30909,11 @@
30909 osGetVersionExA(&sInfo);
30910 sqlite3_os_type = sInfo.dwPlatformId==VER_PLATFORM_WIN32_NT ? 2 : 1;
30911 }
30912 return sqlite3_os_type==2;
30913 }
30914 #endif
30915
30916 #ifdef SQLITE_WIN32_MALLOC
30917 /*
30918 ** Allocate nBytes of memory.
30919 */
@@ -31066,11 +31119,11 @@
31119
31120 nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0);
31121 if( nChar==0 ){
31122 return 0;
31123 }
31124 zWideFilename = sqlite3MallocZero( nChar*sizeof(zWideFilename[0]) );
31125 if( zWideFilename==0 ){
31126 return 0;
31127 }
31128 nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, zWideFilename,
31129 nChar);
@@ -31091,11 +31144,11 @@
31144
31145 nByte = osWideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, 0, 0, 0, 0);
31146 if( nByte == 0 ){
31147 return 0;
31148 }
31149 zFilename = sqlite3MallocZero( nByte );
31150 if( zFilename==0 ){
31151 return 0;
31152 }
31153 nByte = osWideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, zFilename, nByte,
31154 0, 0);
@@ -31121,11 +31174,11 @@
31174 nByte = osMultiByteToWideChar(codepage, 0, zFilename, -1, NULL,
31175 0)*sizeof(WCHAR);
31176 if( nByte==0 ){
31177 return 0;
31178 }
31179 zMbcsFilename = sqlite3MallocZero( nByte*sizeof(zMbcsFilename[0]) );
31180 if( zMbcsFilename==0 ){
31181 return 0;
31182 }
31183 nByte = osMultiByteToWideChar(codepage, 0, zFilename, -1, zMbcsFilename,
31184 nByte);
@@ -31150,11 +31203,11 @@
31203
31204 nByte = osWideCharToMultiByte(codepage, 0, zWideFilename, -1, 0, 0, 0, 0);
31205 if( nByte == 0 ){
31206 return 0;
31207 }
31208 zFilename = sqlite3MallocZero( nByte );
31209 if( zFilename==0 ){
31210 return 0;
31211 }
31212 nByte = osWideCharToMultiByte(codepage, 0, zWideFilename, -1, zFilename,
31213 nByte, 0, 0);
@@ -32797,20 +32850,18 @@
32850 assert( pDbFd->pShm==0 ); /* Not previously opened */
32851
32852 /* Allocate space for the new sqlite3_shm object. Also speculatively
32853 ** allocate space for a new winShmNode and filename.
32854 */
32855 p = sqlite3MallocZero( sizeof(*p) );
32856 if( p==0 ) return SQLITE_IOERR_NOMEM;
 
32857 nName = sqlite3Strlen30(pDbFd->zPath);
32858 pNew = sqlite3MallocZero( sizeof(*pShmNode) + nName + 17 );
32859 if( pNew==0 ){
32860 sqlite3_free(p);
32861 return SQLITE_IOERR_NOMEM;
32862 }
 
32863 pNew->zFilename = (char*)&pNew[1];
32864 sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath);
32865 sqlite3FileSuffix3(pDbFd->zPath, pNew->zFilename);
32866
32867 /* Look to see if there is an existing winShmNode that can be used.
@@ -33143,21 +33194,25 @@
33194 goto shmpage_out;
33195 }
33196 pShmNode->aRegion = apNew;
33197
33198 while( pShmNode->nRegion<=iRegion ){
33199 HANDLE hMap = NULL; /* file-mapping handle */
33200 void *pMap = 0; /* Mapped memory region */
33201
33202 #if SQLITE_OS_WINRT
33203 hMap = osCreateFileMappingFromApp(pShmNode->hFile.h,
33204 NULL, PAGE_READWRITE, nByte, NULL
33205 );
33206 #elif defined(SQLITE_WIN32_HAS_WIDE)
33207 hMap = osCreateFileMappingW(pShmNode->hFile.h,
33208 NULL, PAGE_READWRITE, 0, nByte, NULL
33209 );
33210 #elif defined(SQLITE_WIN32_HAS_ANSI)
33211 hMap = osCreateFileMappingA(pShmNode->hFile.h,
33212 NULL, PAGE_READWRITE, 0, nByte, NULL
33213 );
33214 #endif
33215 OSTRACE(("SHM-MAP pid-%d create region=%d nbyte=%d %s\n",
33216 (int)osGetCurrentProcessId(), pShmNode->nRegion, nByte,
33217 hMap ? "ok" : "failed"));
33218 if( hMap ){
@@ -33902,11 +33957,11 @@
33957 }
33958 return SQLITE_OK;
33959 #endif
33960
33961 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(__CYGWIN__)
33962 DWORD nByte;
33963 void *zConverted;
33964 char *zOut;
33965
33966 /* If this path name begins with "/X:", where "X" is any alphabetic
33967 ** character, discard the initial "/" from the pathname.
@@ -33936,31 +33991,59 @@
33991 if( zConverted==0 ){
33992 return SQLITE_IOERR_NOMEM;
33993 }
33994 if( isNT() ){
33995 LPWSTR zTemp;
33996 nByte = osGetFullPathNameW((LPCWSTR)zConverted, 0, 0, 0);
33997 if( nByte==0 ){
33998 winLogError(SQLITE_ERROR, osGetLastError(),
33999 "GetFullPathNameW1", zConverted);
34000 sqlite3_free(zConverted);
34001 return SQLITE_CANTOPEN_FULLPATH;
34002 }
34003 nByte += 3;
34004 zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) );
34005 if( zTemp==0 ){
34006 sqlite3_free(zConverted);
34007 return SQLITE_IOERR_NOMEM;
34008 }
34009 nByte = osGetFullPathNameW((LPCWSTR)zConverted, nByte, zTemp, 0);
34010 if( nByte==0 ){
34011 winLogError(SQLITE_ERROR, osGetLastError(),
34012 "GetFullPathNameW2", zConverted);
34013 sqlite3_free(zConverted);
34014 sqlite3_free(zTemp);
34015 return SQLITE_CANTOPEN_FULLPATH;
34016 }
34017 sqlite3_free(zConverted);
34018 zOut = unicodeToUtf8(zTemp);
34019 sqlite3_free(zTemp);
34020 }
34021 #ifdef SQLITE_WIN32_HAS_ANSI
34022 else{
34023 char *zTemp;
34024 nByte = osGetFullPathNameA((char*)zConverted, 0, 0, 0);
34025 if( nByte==0 ){
34026 winLogError(SQLITE_ERROR, osGetLastError(),
34027 "GetFullPathNameA1", zConverted);
34028 sqlite3_free(zConverted);
34029 return SQLITE_CANTOPEN_FULLPATH;
34030 }
34031 nByte += 3;
34032 zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) );
34033 if( zTemp==0 ){
34034 sqlite3_free(zConverted);
34035 return SQLITE_IOERR_NOMEM;
34036 }
34037 nByte = osGetFullPathNameA((char*)zConverted, nByte, zTemp, 0);
34038 if( nByte==0 ){
34039 winLogError(SQLITE_ERROR, osGetLastError(),
34040 "GetFullPathNameA2", zConverted);
34041 sqlite3_free(zConverted);
34042 sqlite3_free(zTemp);
34043 return SQLITE_CANTOPEN_FULLPATH;
34044 }
34045 sqlite3_free(zConverted);
34046 zOut = sqlite3_win32_mbcs_to_utf8(zTemp);
34047 sqlite3_free(zTemp);
34048 }
34049 #endif
@@ -34214,11 +34297,11 @@
34297 winNextSystemCall, /* xNextSystemCall */
34298 };
34299
34300 /* Double-check that the aSyscall[] array has been constructed
34301 ** correctly. See ticket [bb3a86e890c8e96ab] */
34302 assert( ArraySize(aSyscall)==74 );
34303
34304 #ifndef SQLITE_OMIT_WAL
34305 /* get memory map allocation granularity */
34306 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
34307 #if SQLITE_OS_WINRT
@@ -34233,11 +34316,11 @@
34316 return SQLITE_OK;
34317 }
34318
34319 SQLITE_API int sqlite3_os_end(void){
34320 #if SQLITE_OS_WINRT
34321 if( sleepObj!=NULL ){
34322 osCloseHandle(sleepObj);
34323 sleepObj = NULL;
34324 }
34325 #endif
34326 return SQLITE_OK;
@@ -41395,11 +41478,11 @@
41478 assert( nPathname>0 );
41479 pPager->zJournal = (char*)(pPtr += nPathname + 1 + nUri);
41480 memcpy(pPager->zFilename, zPathname, nPathname);
41481 if( nUri ) memcpy(&pPager->zFilename[nPathname+1], zUri, nUri);
41482 memcpy(pPager->zJournal, zPathname, nPathname);
41483 memcpy(&pPager->zJournal[nPathname], "-journal\000", 8+2);
41484 sqlite3FileSuffix3(pPager->zFilename, pPager->zJournal);
41485 #ifndef SQLITE_OMIT_WAL
41486 pPager->zWal = &pPager->zJournal[nPathname+8+1];
41487 memcpy(pPager->zWal, zPathname, nPathname);
41488 memcpy(&pPager->zWal[nPathname], "-wal\000", 4+1);
@@ -58860,14 +58943,13 @@
58943 pOp->p4.pKeyInfo = pKeyInfo;
58944 if( pKeyInfo ){
58945 u8 *aSortOrder;
58946 memcpy((char*)pKeyInfo, zP4, nByte - nField);
58947 aSortOrder = pKeyInfo->aSortOrder;
58948 assert( aSortOrder!=0 );
58949 pKeyInfo->aSortOrder = (unsigned char*)&pKeyInfo->aColl[nField];
58950 memcpy(pKeyInfo->aSortOrder, aSortOrder, nField);
 
58951 pOp->p4type = P4_KEYINFO;
58952 }else{
58953 p->db->mallocFailed = 1;
58954 pOp->p4type = P4_NOTUSED;
58955 }
@@ -58976,10 +59058,11 @@
59058 switch( pOp->p4type ){
59059 case P4_KEYINFO_STATIC:
59060 case P4_KEYINFO: {
59061 int i, j;
59062 KeyInfo *pKeyInfo = pOp->p4.pKeyInfo;
59063 assert( pKeyInfo->aSortOrder!=0 );
59064 sqlite3_snprintf(nTemp, zTemp, "keyinfo(%d", pKeyInfo->nField);
59065 i = sqlite3Strlen30(zTemp);
59066 for(j=0; j<pKeyInfo->nField; j++){
59067 CollSeq *pColl = pKeyInfo->aColl[j];
59068 if( pColl ){
@@ -58987,11 +59070,11 @@
59070 if( i+n>nTemp-6 ){
59071 memcpy(&zTemp[i],",...",4);
59072 break;
59073 }
59074 zTemp[i++] = ',';
59075 if( pKeyInfo->aSortOrder[j] ){
59076 zTemp[i++] = '-';
59077 }
59078 memcpy(&zTemp[i], pColl->zName,n+1);
59079 i += n;
59080 }else if( i+4<nTemp-6 ){
@@ -60698,21 +60781,20 @@
60781 if( flags&MEM_Int ){
60782 /* Figure out whether to use 1, 2, 4, 6 or 8 bytes. */
60783 # define MAX_6BYTE ((((i64)0x00008000)<<32)-1)
60784 i64 i = pMem->u.i;
60785 u64 u;
 
 
 
60786 if( i<0 ){
60787 if( i<(-MAX_6BYTE) ) return 6;
60788 /* Previous test prevents: u = -(-9223372036854775808) */
60789 u = -i;
60790 }else{
60791 u = i;
60792 }
60793 if( u<=127 ){
60794 return ((i&1)==i && file_format>=4) ? 8+(u32)u : 1;
60795 }
60796 if( u<=32767 ) return 2;
60797 if( u<=8388607 ) return 3;
60798 if( u<=2147483647 ) return 4;
60799 if( u<=MAX_6BYTE ) return 5;
60800 return 6;
@@ -60993,10 +61075,11 @@
61075 p = (UnpackedRecord*)&pSpace[nOff];
61076 *ppFree = 0;
61077 }
61078
61079 p->aMem = (Mem*)&((char*)p)[ROUND8(sizeof(UnpackedRecord))];
61080 assert( pKeyInfo->aSortOrder!=0 );
61081 p->pKeyInfo = pKeyInfo;
61082 p->nField = pKeyInfo->nField + 1;
61083 return p;
61084 }
61085
@@ -61086,10 +61169,11 @@
61169 /* mem1.u.i = 0; // not needed, here to silence compiler warning */
61170
61171 idx1 = getVarint32(aKey1, szHdr1);
61172 d1 = szHdr1;
61173 nField = pKeyInfo->nField;
61174 assert( pKeyInfo->aSortOrder!=0 );
61175 while( idx1<szHdr1 && i<pPKey2->nField ){
61176 u32 serial_type1;
61177
61178 /* Read the serial types for the next element in each key. */
61179 idx1 += getVarint32( aKey1+idx1, serial_type1 );
@@ -61105,11 +61189,11 @@
61189 i<nField ? pKeyInfo->aColl[i] : 0);
61190 if( rc!=0 ){
61191 assert( mem1.zMalloc==0 ); /* See comment below */
61192
61193 /* Invert the result if we are using DESC sort order. */
61194 if( i<nField && pKeyInfo->aSortOrder[i] ){
61195 rc = -rc;
61196 }
61197
61198 /* If the PREFIX_SEARCH flag is set and all fields except the final
61199 ** rowid field were equal, then clear the PREFIX_SEARCH flag and set
@@ -61831,14 +61915,16 @@
61915 if( vdbeSafetyNotNull(v) ){
61916 return SQLITE_MISUSE_BKPT;
61917 }
61918 db = v->db;
61919 sqlite3_mutex_enter(db->mutex);
61920 v->doingRerun = 0;
61921 while( (rc = sqlite3Step(v))==SQLITE_SCHEMA
61922 && cnt++ < SQLITE_MAX_SCHEMA_RETRY
61923 && (rc2 = rc = sqlite3Reprepare(v))==SQLITE_OK ){
61924 sqlite3_reset(pStmt);
61925 v->doingRerun = 1;
61926 assert( v->expired==0 );
61927 }
61928 if( rc2!=SQLITE_OK && ALWAYS(v->isPrepareV2) && ALWAYS(db->pErr) ){
61929 /* This case occurs after failing to recompile an sql statement.
61930 ** The error message from the SQL compiler has already been loaded
@@ -63957,11 +64043,10 @@
64043 struct OP_JournalMode_stack_vars {
64044 Btree *pBt; /* Btree to change journal mode of */
64045 Pager *pPager; /* Pager associated with pBt */
64046 int eNew; /* New journal mode */
64047 int eOld; /* The old journal mode */
 
64048 } ci;
64049 struct OP_IncrVacuum_stack_vars {
64050 Btree *pBt;
64051 } cj;
64052 struct OP_VBegin_stack_vars {
@@ -69061,12 +69146,14 @@
69146 #if 0 /* local variables moved into u.ci */
69147 Btree *pBt; /* Btree to change journal mode of */
69148 Pager *pPager; /* Pager associated with pBt */
69149 int eNew; /* New journal mode */
69150 int eOld; /* The old journal mode */
 
69151 #endif /* local variables moved into u.ci */
69152 #ifndef SQLITE_OMIT_WAL
69153 const char *zFilename; /* Name of database file for u.ci.pPager */
69154 #endif
69155
69156 u.ci.eNew = pOp->p3;
69157 assert( u.ci.eNew==PAGER_JOURNALMODE_DELETE
69158 || u.ci.eNew==PAGER_JOURNALMODE_TRUNCATE
69159 || u.ci.eNew==PAGER_JOURNALMODE_PERSIST
@@ -69082,17 +69169,17 @@
69169 u.ci.eOld = sqlite3PagerGetJournalMode(u.ci.pPager);
69170 if( u.ci.eNew==PAGER_JOURNALMODE_QUERY ) u.ci.eNew = u.ci.eOld;
69171 if( !sqlite3PagerOkToChangeJournalMode(u.ci.pPager) ) u.ci.eNew = u.ci.eOld;
69172
69173 #ifndef SQLITE_OMIT_WAL
69174 zFilename = sqlite3PagerFilename(u.ci.pPager, 1);
69175
69176 /* Do not allow a transition to journal_mode=WAL for a database
69177 ** in temporary storage or if the VFS does not support shared memory
69178 */
69179 if( u.ci.eNew==PAGER_JOURNALMODE_WAL
69180 && (sqlite3Strlen30(zFilename)==0 /* Temp file */
69181 || !sqlite3PagerWalSupported(u.ci.pPager)) /* No shared-memory support */
69182 ){
69183 u.ci.eNew = u.ci.eOld;
69184 }
69185
@@ -69660,11 +69747,14 @@
69747 #if 0 /* local variables moved into u.cr */
69748 char *zTrace;
69749 char *z;
69750 #endif /* local variables moved into u.cr */
69751
69752 if( db->xTrace
69753 && !p->doingRerun
69754 && (u.cr.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
69755 ){
69756 u.cr.z = sqlite3VdbeExpandSql(p, u.cr.zTrace);
69757 db->xTrace(db->pTraceArg, u.cr.z);
69758 sqlite3DbFree(db, u.cr.z);
69759 }
69760 #ifdef SQLITE_DEBUG
@@ -74885,10 +74975,11 @@
74975
74976 switch( pExpr->op ){
74977 case TK_IN: {
74978 char affinity; /* Affinity of the LHS of the IN */
74979 KeyInfo keyInfo; /* Keyinfo for the generated table */
74980 static u8 sortOrder = 0; /* Fake aSortOrder for keyInfo */
74981 int addr; /* Address of OP_OpenEphemeral instruction */
74982 Expr *pLeft = pExpr->pLeft; /* the LHS of the IN operator */
74983
74984 if( rMayHaveNull ){
74985 sqlite3VdbeAddOp2(v, OP_Null, 0, rMayHaveNull);
@@ -74912,10 +75003,11 @@
75003 pExpr->iTable = pParse->nTab++;
75004 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, !isRowid);
75005 if( rMayHaveNull==0 ) sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
75006 memset(&keyInfo, 0, sizeof(keyInfo));
75007 keyInfo.nField = 1;
75008 keyInfo.aSortOrder = &sortOrder;
75009
75010 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
75011 /* Case 1: expr IN (SELECT ...)
75012 **
75013 ** Generate code to write the results of the select into the temporary
@@ -74952,10 +75044,11 @@
75044
75045 if( !affinity ){
75046 affinity = SQLITE_AFF_NONE;
75047 }
75048 keyInfo.aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
75049 keyInfo.aSortOrder = &sortOrder;
75050
75051 /* Loop through each expression in <exprlist>. */
75052 r1 = sqlite3GetTempReg(pParse);
75053 r2 = sqlite3GetTempReg(pParse);
75054 sqlite3VdbeAddOp2(v, OP_Null, 0, r2);
@@ -78030,11 +78123,11 @@
78123
78124 /* Check that the new column is not specified as PRIMARY KEY or UNIQUE.
78125 ** If there is a NOT NULL constraint, then the default value for the
78126 ** column must not be NULL.
78127 */
78128 if( pCol->colFlags & COLFLAG_PRIMKEY ){
78129 sqlite3ErrorMsg(pParse, "Cannot add a PRIMARY KEY column");
78130 return;
78131 }
78132 if( pNew->pIndex ){
78133 sqlite3ErrorMsg(pParse, "Cannot add a UNIQUE column");
@@ -81299,20 +81392,20 @@
81392 goto primary_key_exit;
81393 }
81394 pTab->tabFlags |= TF_HasPrimaryKey;
81395 if( pList==0 ){
81396 iCol = pTab->nCol - 1;
81397 pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY;
81398 }else{
81399 for(i=0; i<pList->nExpr; i++){
81400 for(iCol=0; iCol<pTab->nCol; iCol++){
81401 if( sqlite3StrICmp(pList->a[i].zName, pTab->aCol[iCol].zName)==0 ){
81402 break;
81403 }
81404 }
81405 if( iCol<pTab->nCol ){
81406 pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY;
81407 }
81408 }
81409 if( pList->nExpr>1 ) iCol = -1;
81410 }
81411 if( iCol>=0 && iCol<pTab->nCol ){
@@ -85468,37 +85561,18 @@
85561 sqlite3_result_text(context, z1, n, sqlite3_free);
85562 }
85563 }
85564 }
85565
85566 /*
85567 ** The COALESCE() and IFNULL() functions are implemented as VDBE code so
85568 ** that unused argument values do not have to be computed. However, we
85569 ** still need some kind of function implementation for this routines in
85570 ** the function table. That function implementation will never be called
85571 ** so it doesn't matter what the implementation is. We might as well use
85572 ** the "version()" function as a substitute.
85573 */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85574 #define ifnullFunc versionFunc /* Substitute function - never called */
85575
85576 /*
85577 ** Implementation of random(). Return a random integer.
85578 */
@@ -85613,11 +85687,11 @@
85687 ** character is exactly one byte in size. Also, all characters are
85688 ** able to participate in upper-case-to-lower-case mappings in EBCDIC
85689 ** whereas only characters less than 0x80 do in ASCII.
85690 */
85691 #if defined(SQLITE_EBCDIC)
85692 # define sqlite3Utf8Read(A) (*((*A)++))
85693 # define GlogUpperToLower(A) A = sqlite3UpperToLower[A]
85694 #else
85695 # define GlogUpperToLower(A) if( !((A)&~0x7f) ){ A = sqlite3UpperToLower[A]; }
85696 #endif
85697
@@ -85670,22 +85744,22 @@
85744 u8 matchAll = pInfo->matchAll;
85745 u8 matchSet = pInfo->matchSet;
85746 u8 noCase = pInfo->noCase;
85747 int prevEscape = 0; /* True if the previous character was 'escape' */
85748
85749 while( (c = sqlite3Utf8Read(&zPattern))!=0 ){
85750 if( c==matchAll && !prevEscape ){
85751 while( (c=sqlite3Utf8Read(&zPattern)) == matchAll
85752 || c == matchOne ){
85753 if( c==matchOne && sqlite3Utf8Read(&zString)==0 ){
85754 return 0;
85755 }
85756 }
85757 if( c==0 ){
85758 return 1;
85759 }else if( c==esc ){
85760 c = sqlite3Utf8Read(&zPattern);
85761 if( c==0 ){
85762 return 0;
85763 }
85764 }else if( c==matchSet ){
85765 assert( esc==0 ); /* This is GLOB, not LIKE */
@@ -85693,67 +85767,67 @@
85767 while( *zString && patternCompare(&zPattern[-1],zString,pInfo,esc)==0 ){
85768 SQLITE_SKIP_UTF8(zString);
85769 }
85770 return *zString!=0;
85771 }
85772 while( (c2 = sqlite3Utf8Read(&zString))!=0 ){
85773 if( noCase ){
85774 GlogUpperToLower(c2);
85775 GlogUpperToLower(c);
85776 while( c2 != 0 && c2 != c ){
85777 c2 = sqlite3Utf8Read(&zString);
85778 GlogUpperToLower(c2);
85779 }
85780 }else{
85781 while( c2 != 0 && c2 != c ){
85782 c2 = sqlite3Utf8Read(&zString);
85783 }
85784 }
85785 if( c2==0 ) return 0;
85786 if( patternCompare(zPattern,zString,pInfo,esc) ) return 1;
85787 }
85788 return 0;
85789 }else if( c==matchOne && !prevEscape ){
85790 if( sqlite3Utf8Read(&zString)==0 ){
85791 return 0;
85792 }
85793 }else if( c==matchSet ){
85794 u32 prior_c = 0;
85795 assert( esc==0 ); /* This only occurs for GLOB, not LIKE */
85796 seen = 0;
85797 invert = 0;
85798 c = sqlite3Utf8Read(&zString);
85799 if( c==0 ) return 0;
85800 c2 = sqlite3Utf8Read(&zPattern);
85801 if( c2=='^' ){
85802 invert = 1;
85803 c2 = sqlite3Utf8Read(&zPattern);
85804 }
85805 if( c2==']' ){
85806 if( c==']' ) seen = 1;
85807 c2 = sqlite3Utf8Read(&zPattern);
85808 }
85809 while( c2 && c2!=']' ){
85810 if( c2=='-' && zPattern[0]!=']' && zPattern[0]!=0 && prior_c>0 ){
85811 c2 = sqlite3Utf8Read(&zPattern);
85812 if( c>=prior_c && c<=c2 ) seen = 1;
85813 prior_c = 0;
85814 }else{
85815 if( c==c2 ){
85816 seen = 1;
85817 }
85818 prior_c = c2;
85819 }
85820 c2 = sqlite3Utf8Read(&zPattern);
85821 }
85822 if( c2==0 || (seen ^ invert)==0 ){
85823 return 0;
85824 }
85825 }else if( esc==c && !prevEscape ){
85826 prevEscape = 1;
85827 }else{
85828 c2 = sqlite3Utf8Read(&zString);
85829 if( noCase ){
85830 GlogUpperToLower(c);
85831 GlogUpperToLower(c2);
85832 }
85833 if( c!=c2 ){
@@ -85821,11 +85895,11 @@
85895 if( sqlite3Utf8CharLen((char*)zEsc, -1)!=1 ){
85896 sqlite3_result_error(context,
85897 "ESCAPE expression must be a single character", -1);
85898 return;
85899 }
85900 escape = sqlite3Utf8Read(&zEsc);
85901 }
85902 if( zA && zB ){
85903 struct compareInfo *pInfo = sqlite3_user_data(context);
85904 #ifdef SQLITE_TEST
85905 sqlite3_like_count++;
@@ -87653,11 +87727,12 @@
87727 for(i=0; i<p->nCol; i++){
87728 char *zKey = p->aCol[i].zCol;
87729 int iKey;
87730 for(iKey=0; iKey<pTab->nCol; iKey++){
87731 Column *pCol = &pTab->aCol[iKey];
87732 if( (zKey ? !sqlite3StrICmp(pCol->zName, zKey)
87733 : (pCol->colFlags & COLFLAG_PRIMKEY)!=0) ){
87734 if( aChange[iKey]>=0 ) return 1;
87735 if( iKey==pTab->iPKey && chngRowid ) return 1;
87736 }
87737 }
87738 }
@@ -88268,10 +88343,101 @@
88343 */
88344 # define autoIncBegin(A,B,C) (0)
88345 # define autoIncStep(A,B,C)
88346 #endif /* SQLITE_OMIT_AUTOINCREMENT */
88347
88348
88349 /*
88350 ** Generate code for a co-routine that will evaluate a subquery one
88351 ** row at a time.
88352 **
88353 ** The pSelect parameter is the subquery that the co-routine will evaluation.
88354 ** Information about the location of co-routine and the registers it will use
88355 ** is returned by filling in the pDest object.
88356 **
88357 ** Registers are allocated as follows:
88358 **
88359 ** pDest->iSDParm The register holding the next entry-point of the
88360 ** co-routine. Run the co-routine to its next breakpoint
88361 ** by calling "OP_Yield $X" where $X is pDest->iSDParm.
88362 **
88363 ** pDest->iSDParm+1 The register holding the "completed" flag for the
88364 ** co-routine. This register is 0 if the previous Yield
88365 ** generated a new result row, or 1 if the subquery
88366 ** has completed. If the Yield is called again
88367 ** after this register becomes 1, then the VDBE will
88368 ** halt with an SQLITE_INTERNAL error.
88369 **
88370 ** pDest->iSdst First result register.
88371 **
88372 ** pDest->nSdst Number of result registers.
88373 **
88374 ** This routine handles all of the register allocation and fills in the
88375 ** pDest structure appropriately.
88376 **
88377 ** Here is a schematic of the generated code assuming that X is the
88378 ** co-routine entry-point register reg[pDest->iSDParm], that EOF is the
88379 ** completed flag reg[pDest->iSDParm+1], and R and S are the range of
88380 ** registers that hold the result set, reg[pDest->iSdst] through
88381 ** reg[pDest->iSdst+pDest->nSdst-1]:
88382 **
88383 ** X <- A
88384 ** EOF <- 0
88385 ** goto B
88386 ** A: setup for the SELECT
88387 ** loop rows in the SELECT
88388 ** load results into registers R..S
88389 ** yield X
88390 ** end loop
88391 ** cleanup after the SELECT
88392 ** EOF <- 1
88393 ** yield X
88394 ** halt-error
88395 ** B:
88396 **
88397 ** To use this subroutine, the caller generates code as follows:
88398 **
88399 ** [ Co-routine generated by this subroutine, shown above ]
88400 ** S: yield X
88401 ** if EOF goto E
88402 ** if skip this row, goto C
88403 ** if terminate loop, goto E
88404 ** deal with this row
88405 ** C: goto S
88406 ** E:
88407 */
88408 SQLITE_PRIVATE int sqlite3CodeCoroutine(Parse *pParse, Select *pSelect, SelectDest *pDest){
88409 int regYield; /* Register holding co-routine entry-point */
88410 int regEof; /* Register holding co-routine completion flag */
88411 int addrTop; /* Top of the co-routine */
88412 int j1; /* Jump instruction */
88413 int rc; /* Result code */
88414 Vdbe *v; /* VDBE under construction */
88415
88416 regYield = ++pParse->nMem;
88417 regEof = ++pParse->nMem;
88418 v = sqlite3GetVdbe(pParse);
88419 addrTop = sqlite3VdbeCurrentAddr(v);
88420 sqlite3VdbeAddOp2(v, OP_Integer, addrTop+2, regYield); /* X <- A */
88421 VdbeComment((v, "Co-routine entry point"));
88422 sqlite3VdbeAddOp2(v, OP_Integer, 0, regEof); /* EOF <- 0 */
88423 VdbeComment((v, "Co-routine completion flag"));
88424 sqlite3SelectDestInit(pDest, SRT_Coroutine, regYield);
88425 j1 = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);
88426 rc = sqlite3Select(pParse, pSelect, pDest);
88427 assert( pParse->nErr==0 || rc );
88428 if( pParse->db->mallocFailed && rc==SQLITE_OK ) rc = SQLITE_NOMEM;
88429 if( rc ) return rc;
88430 sqlite3VdbeAddOp2(v, OP_Integer, 1, regEof); /* EOF <- 1 */
88431 sqlite3VdbeAddOp1(v, OP_Yield, regYield); /* yield X */
88432 sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_INTERNAL, OE_Abort);
88433 VdbeComment((v, "End of coroutine"));
88434 sqlite3VdbeJumpHere(v, j1); /* label B: */
88435 return rc;
88436 }
88437
88438
88439
88440 /* Forward declaration */
88441 static int xferOptimization(
88442 Parse *pParse, /* Parser context */
88443 Table *pDest, /* The table we are inserting into */
@@ -88517,55 +88683,16 @@
88683 ** is coming from a SELECT statement, then generate a co-routine that
88684 ** produces a single row of the SELECT on each invocation. The
88685 ** co-routine is the common header to the 3rd and 4th templates.
88686 */
88687 if( pSelect ){
88688 /* Data is coming from a SELECT. Generate a co-routine to run that
88689 ** SELECT. */
88690 int rc = sqlite3CodeCoroutine(pParse, pSelect, &dest);
88691 if( rc ) goto insert_cleanup;
88692
88693 regEof = dest.iSDParm + 1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88694 regFromSelect = dest.iSdst;
88695 assert( pSelect->pEList );
88696 nColumn = pSelect->pEList->nExpr;
88697 assert( dest.nSdst==nColumn );
88698
@@ -92035,11 +92162,12 @@
92162 if( pCol->zDflt ){
92163 sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, (char*)pCol->zDflt, 0);
92164 }else{
92165 sqlite3VdbeAddOp2(v, OP_Null, 0, 5);
92166 }
92167 sqlite3VdbeAddOp2(v, OP_Integer,
92168 (pCol->colFlags&COLFLAG_PRIMKEY)!=0, 6);
92169 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
92170 }
92171 }
92172 }else
92173
@@ -94803,11 +94931,11 @@
94931 ** store NULL in *paCol and 0 in *pnCol and return SQLITE_NOMEM.
94932 */
94933 static int selectColumnsFromExprList(
94934 Parse *pParse, /* Parsing context */
94935 ExprList *pEList, /* Expr list from which to derive column names */
94936 i16 *pnCol, /* Write the number of columns here */
94937 Column **paCol /* Write the new column list here */
94938 ){
94939 sqlite3 *db = pParse->db; /* Database connection */
94940 int i, j; /* Loop counters */
94941 int cnt; /* Index added to make the name unique */
@@ -95449,10 +95577,11 @@
95577 *apColl = multiSelectCollSeq(pParse, p, i);
95578 if( 0==*apColl ){
95579 *apColl = db->pDfltColl;
95580 }
95581 }
95582 pKeyInfo->aSortOrder = (u8*)apColl;
95583
95584 for(pLoop=p; pLoop; pLoop=pLoop->pPrior){
95585 for(i=0; i<2; i++){
95586 int addr = pLoop->addrOpenEphm[i];
95587 if( addr<0 ){
@@ -101068,11 +101197,11 @@
101197 }else{
101198 int iCol;
101199 /* If everything went according to plan, link the new VTable structure
101200 ** into the linked list headed by pTab->pVTable. Then loop through the
101201 ** columns of the table to see if any of them contain the token "hidden".
101202 ** If so, set the Column COLFLAG_HIDDEN flag and remove the token from
101203 ** the type string. */
101204 pVTable->pNext = pTab->pVTable;
101205 pTab->pVTable = pVTable;
101206
101207 for(iCol=0; iCol<pTab->nCol; iCol++){
@@ -101099,11 +101228,11 @@
101228 }
101229 if( zType[i]=='\0' && i>0 ){
101230 assert(zType[i-1]==' ');
101231 zType[i-1] = '\0';
101232 }
101233 pTab->aCol[iCol].colFlags |= COLFLAG_HIDDEN;
101234 }
101235 }
101236 }
101237 }
101238
@@ -101901,10 +102030,11 @@
102030 #define WHERE_UNIQUE 0x04000000 /* Selects no more than one row */
102031 #define WHERE_VIRTUALTABLE 0x08000000 /* Use virtual-table processing */
102032 #define WHERE_MULTI_OR 0x10000000 /* OR using multiple indices */
102033 #define WHERE_TEMP_INDEX 0x20000000 /* Uses an ephemeral index */
102034 #define WHERE_DISTINCT 0x40000000 /* Correct order for DISTINCT */
102035 #define WHERE_COVER_SCAN 0x80000000 /* Full scan of a covering index */
102036
102037 /*
102038 ** Initialize a preallocated WhereClause structure.
102039 */
102040 static void whereClauseInit(
@@ -104770,11 +104900,11 @@
104900 /* If currently calculating the cost of using an index (not the IPK
104901 ** index), determine if all required column data may be obtained without
104902 ** using the main table (i.e. if the index is a covering
104903 ** index for this query). If it is, set the WHERE_IDX_ONLY flag in
104904 ** wsFlags. Otherwise, set the bLookup variable to true. */
104905 if( pIdx ){
104906 Bitmask m = pSrc->colUsed;
104907 int j;
104908 for(j=0; j<pIdx->nColumn; j++){
104909 int x = pIdx->aiColumn[j];
104910 if( x<BMS-1 ){
@@ -104835,11 +104965,24 @@
104965 ** The ANALYZE command and the sqlite_stat1 and sqlite_stat3 tables do
104966 ** not give us data on the relative sizes of table and index records.
104967 ** So this computation assumes table records are about twice as big
104968 ** as index records
104969 */
104970 if( wsFlags==WHERE_IDX_ONLY
104971 && (pWC->wctrlFlags & WHERE_ONEPASS_DESIRED)==0
104972 && sqlite3GlobalConfig.bUseCis
104973 #ifndef SQLITE_OMIT_BUILTIN_TEST
104974 && (pParse->db->flags & SQLITE_CoverIdxScan)==0
104975 #endif
104976 ){
104977 /* This index is not useful for indexing, but it is a covering index.
104978 ** A full-scan of the index might be a little faster than a full-scan
104979 ** of the table, so give this case a cost slightly less than a table
104980 ** scan. */
104981 cost = aiRowEst[0]*3 + pProbe->nColumn;
104982 wsFlags |= WHERE_COVER_SCAN|WHERE_COLUMN_RANGE;
104983 }else if( (wsFlags & WHERE_NOT_FULLSCAN)==0 ){
104984 /* The cost of a full table scan is a number of move operations equal
104985 ** to the number of rows in the table.
104986 **
104987 ** We add an additional 4x penalty to full table scans. This causes
104988 ** the cost function to err on the side of choosing an index over
@@ -104846,10 +104989,11 @@
104989 ** choosing a full scan. This 4x full-scan penalty is an arguable
104990 ** decision and one which we expect to revisit in the future. But
104991 ** it seems to be working well enough at the moment.
104992 */
104993 cost = aiRowEst[0]*4;
104994 wsFlags &= ~WHERE_IDX_ONLY;
104995 }else{
104996 log10N = estLog(aiRowEst[0]);
104997 cost = nRow;
104998 if( pIdx ){
104999 if( bLookup ){
@@ -105889,10 +106033,15 @@
106033 pLevel->op = OP_Prev;
106034 }else{
106035 pLevel->op = OP_Next;
106036 }
106037 pLevel->p1 = iIdxCur;
106038 if( pLevel->plan.wsFlags & WHERE_COVER_SCAN ){
106039 pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
106040 }else{
106041 assert( pLevel->p5==0 );
106042 }
106043 }else
106044
106045 #ifndef SQLITE_OMIT_OR_OPTIMIZATION
106046 if( pLevel->plan.wsFlags & WHERE_MULTI_OR ){
106047 /* Case 4: Two or more separately indexed terms connected by OR
@@ -106765,31 +106914,33 @@
106914 ** index name is '*'.
106915 */
106916 for(i=0; i<nTabList; i++){
106917 char *z;
106918 int n;
106919 int w;
106920 pLevel = &pWInfo->a[i];
106921 w = pLevel->plan.wsFlags;
106922 pTabItem = &pTabList->a[pLevel->iFrom];
106923 z = pTabItem->zAlias;
106924 if( z==0 ) z = pTabItem->pTab->zName;
106925 n = sqlite3Strlen30(z);
106926 if( n+nQPlan < sizeof(sqlite3_query_plan)-10 ){
106927 if( (w & WHERE_IDX_ONLY)!=0 && (w & WHERE_COVER_SCAN)==0 ){
106928 memcpy(&sqlite3_query_plan[nQPlan], "{}", 2);
106929 nQPlan += 2;
106930 }else{
106931 memcpy(&sqlite3_query_plan[nQPlan], z, n);
106932 nQPlan += n;
106933 }
106934 sqlite3_query_plan[nQPlan++] = ' ';
106935 }
106936 testcase( w & WHERE_ROWID_EQ );
106937 testcase( w & WHERE_ROWID_RANGE );
106938 if( w & (WHERE_ROWID_EQ|WHERE_ROWID_RANGE) ){
106939 memcpy(&sqlite3_query_plan[nQPlan], "* ", 2);
106940 nQPlan += 2;
106941 }else if( (w & WHERE_INDEXED)!=0 && (w & WHERE_COVER_SCAN)==0 ){
106942 n = sqlite3Strlen30(pLevel->plan.u.pIdx->zName);
106943 if( n+nQPlan < sizeof(sqlite3_query_plan)-2 ){
106944 memcpy(&sqlite3_query_plan[nQPlan], pLevel->plan.u.pIdx->zName, n);
106945 nQPlan += n;
106946 sqlite3_query_plan[nQPlan++] = ' ';
@@ -112076,10 +112227,15 @@
112227
112228 case SQLITE_CONFIG_URI: {
112229 sqlite3GlobalConfig.bOpenUri = va_arg(ap, int);
112230 break;
112231 }
112232
112233 case SQLITE_CONFIG_COVERING_INDEX_SCAN: {
112234 sqlite3GlobalConfig.bUseCis = va_arg(ap, int);
112235 break;
112236 }
112237
112238 default: {
112239 rc = SQLITE_ERROR;
112240 break;
112241 }
@@ -113368,10 +113524,19 @@
113524 if( !db || db->mallocFailed ){
113525 return SQLITE_NOMEM;
113526 }
113527 return db->errCode;
113528 }
113529
113530 /*
113531 ** Return a string that describes the kind of error specified in the
113532 ** argument. For now, this simply calls the internal sqlite3ErrStr()
113533 ** function.
113534 */
113535 SQLITE_API const char *sqlite3_errstr(int rc){
113536 return sqlite3ErrStr(rc);
113537 }
113538
113539 /*
113540 ** Create a new collating function for database "db". The name is zName
113541 ** and the encoding is enc.
113542 */
@@ -114343,11 +114508,11 @@
114508 */
114509 if( pCol ){
114510 zDataType = pCol->zType;
114511 zCollSeq = pCol->zColl;
114512 notnull = pCol->notNull!=0;
114513 primarykey = (pCol->colFlags & COLFLAG_PRIMKEY)!=0;
114514 autoinc = pTab->iPKey==iCol && (pTab->tabFlags & TF_Autoincrement)!=0;
114515 }else{
114516 zDataType = "INTEGER";
114517 primarykey = 1;
114518 }
114519
+24 -4
--- 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.14"
111
-#define SQLITE_VERSION_NUMBER 3007014
112
-#define SQLITE_SOURCE_ID "2012-09-03 15:42:36 c0d89d4a9752922f9e367362366efde4f1b06f2a"
110
+#define SQLITE_VERSION "3.7.15"
111
+#define SQLITE_VERSION_NUMBER 3007015
112
+#define SQLITE_SOURCE_ID "2012-09-17 21:24:01 698b2a28004a9a2f0eabaadf36d833da4400b2bf"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -476,10 +476,11 @@
476476
#define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
477477
#define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
478478
#define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
479479
#define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
480480
#define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
481
+#define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
481482
#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
482483
#define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
483484
#define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
484485
#define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
485486
@@ -1564,10 +1565,22 @@
15641565
** connection is opened. If it is globally disabled, filenames are
15651566
** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
15661567
** database connection is opened. By default, URI handling is globally
15671568
** disabled. The default value may be changed by compiling with the
15681569
** [SQLITE_USE_URI] symbol defined.
1570
+**
1571
+** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
1572
+** <dd> This option taks a single integer argument which is interpreted as
1573
+** a boolean in order to enable or disable the use of covering indices for
1574
+** full table scans in the query optimizer. The default setting is determined
1575
+** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
1576
+** if that compile-time option is omitted.
1577
+** The ability to disable the use of covering indices for full table scans
1578
+** is because some incorrectly coded legacy applications might malfunction
1579
+** malfunction when the optimization is enabled. Providing the ability to
1580
+** disable the optimization allows the older, buggy application code to work
1581
+** without change even with newer versions of SQLite.
15691582
**
15701583
** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]]
15711584
** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE
15721585
** <dd> These options are obsolete and should not be used by new code.
15731586
** They are retained for backwards compatibility but are now no-ops.
@@ -1590,10 +1603,11 @@
15901603
#define SQLITE_CONFIG_GETPCACHE 15 /* no-op */
15911604
#define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
15921605
#define SQLITE_CONFIG_URI 17 /* int */
15931606
#define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */
15941607
#define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
1608
+#define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
15951609
15961610
/*
15971611
** CAPI3REF: Database Connection Configuration Options
15981612
**
15991613
** These constants are the available integer configuration options that
@@ -2598,11 +2612,11 @@
25982612
** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw",
25992613
** "rwc", or "memory". Attempting to set it to any other value is
26002614
** an error)^.
26012615
** ^If "ro" is specified, then the database is opened for read-only
26022616
** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the
2603
-** third argument to sqlite3_prepare_v2(). ^If the mode option is set to
2617
+** third argument to sqlite3_open_v2(). ^If the mode option is set to
26042618
** "rw", then the database is opened for read-write (but not create)
26052619
** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had
26062620
** been set. ^Value "rwc" is equivalent to setting both
26072621
** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If the mode option is
26082622
** set to "memory" then a pure [in-memory database] that never reads
@@ -2749,10 +2763,15 @@
27492763
** text that describes the error, as either UTF-8 or UTF-16 respectively.
27502764
** ^(Memory to hold the error message string is managed internally.
27512765
** The application does not need to worry about freeing the result.
27522766
** However, the error string might be overwritten or deallocated by
27532767
** subsequent calls to other SQLite interface functions.)^
2768
+**
2769
+** ^The sqlite3_errstr() interface returns the English-language text
2770
+** that describes the [result code], as UTF-8.
2771
+** ^(Memory to hold the error message string is managed internally
2772
+** and must not be freed by the application)^.
27542773
**
27552774
** When the serialized [threading mode] is in use, it might be the
27562775
** case that a second error occurs on a separate thread in between
27572776
** the time of the first error and the call to these interfaces.
27582777
** When that happens, the second error will be reported since these
@@ -2768,10 +2787,11 @@
27682787
*/
27692788
SQLITE_API int sqlite3_errcode(sqlite3 *db);
27702789
SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
27712790
SQLITE_API const char *sqlite3_errmsg(sqlite3*);
27722791
SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
2792
+SQLITE_API const char *sqlite3_errstr(int);
27732793
27742794
/*
27752795
** CAPI3REF: SQL Statement Object
27762796
** KEYWORDS: {prepared statement} {prepared statements}
27772797
**
27782798
--- 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.14"
111 #define SQLITE_VERSION_NUMBER 3007014
112 #define SQLITE_SOURCE_ID "2012-09-03 15:42:36 c0d89d4a9752922f9e367362366efde4f1b06f2a"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -476,10 +476,11 @@
476 #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
477 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
478 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
479 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
480 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
 
481 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
482 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
483 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
484 #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
485
@@ -1564,10 +1565,22 @@
1564 ** connection is opened. If it is globally disabled, filenames are
1565 ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
1566 ** database connection is opened. By default, URI handling is globally
1567 ** disabled. The default value may be changed by compiling with the
1568 ** [SQLITE_USE_URI] symbol defined.
 
 
 
 
 
 
 
 
 
 
 
 
1569 **
1570 ** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]]
1571 ** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE
1572 ** <dd> These options are obsolete and should not be used by new code.
1573 ** They are retained for backwards compatibility but are now no-ops.
@@ -1590,10 +1603,11 @@
1590 #define SQLITE_CONFIG_GETPCACHE 15 /* no-op */
1591 #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
1592 #define SQLITE_CONFIG_URI 17 /* int */
1593 #define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */
1594 #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
 
1595
1596 /*
1597 ** CAPI3REF: Database Connection Configuration Options
1598 **
1599 ** These constants are the available integer configuration options that
@@ -2598,11 +2612,11 @@
2598 ** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw",
2599 ** "rwc", or "memory". Attempting to set it to any other value is
2600 ** an error)^.
2601 ** ^If "ro" is specified, then the database is opened for read-only
2602 ** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the
2603 ** third argument to sqlite3_prepare_v2(). ^If the mode option is set to
2604 ** "rw", then the database is opened for read-write (but not create)
2605 ** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had
2606 ** been set. ^Value "rwc" is equivalent to setting both
2607 ** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If the mode option is
2608 ** set to "memory" then a pure [in-memory database] that never reads
@@ -2749,10 +2763,15 @@
2749 ** text that describes the error, as either UTF-8 or UTF-16 respectively.
2750 ** ^(Memory to hold the error message string is managed internally.
2751 ** The application does not need to worry about freeing the result.
2752 ** However, the error string might be overwritten or deallocated by
2753 ** subsequent calls to other SQLite interface functions.)^
 
 
 
 
 
2754 **
2755 ** When the serialized [threading mode] is in use, it might be the
2756 ** case that a second error occurs on a separate thread in between
2757 ** the time of the first error and the call to these interfaces.
2758 ** When that happens, the second error will be reported since these
@@ -2768,10 +2787,11 @@
2768 */
2769 SQLITE_API int sqlite3_errcode(sqlite3 *db);
2770 SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
2771 SQLITE_API const char *sqlite3_errmsg(sqlite3*);
2772 SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
 
2773
2774 /*
2775 ** CAPI3REF: SQL Statement Object
2776 ** KEYWORDS: {prepared statement} {prepared statements}
2777 **
2778
--- 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.15"
111 #define SQLITE_VERSION_NUMBER 3007015
112 #define SQLITE_SOURCE_ID "2012-09-17 21:24:01 698b2a28004a9a2f0eabaadf36d833da4400b2bf"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -476,10 +476,11 @@
476 #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
477 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
478 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
479 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
480 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
481 #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
482 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
483 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
484 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
485 #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
486
@@ -1564,10 +1565,22 @@
1565 ** connection is opened. If it is globally disabled, filenames are
1566 ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
1567 ** database connection is opened. By default, URI handling is globally
1568 ** disabled. The default value may be changed by compiling with the
1569 ** [SQLITE_USE_URI] symbol defined.
1570 **
1571 ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
1572 ** <dd> This option taks a single integer argument which is interpreted as
1573 ** a boolean in order to enable or disable the use of covering indices for
1574 ** full table scans in the query optimizer. The default setting is determined
1575 ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
1576 ** if that compile-time option is omitted.
1577 ** The ability to disable the use of covering indices for full table scans
1578 ** is because some incorrectly coded legacy applications might malfunction
1579 ** malfunction when the optimization is enabled. Providing the ability to
1580 ** disable the optimization allows the older, buggy application code to work
1581 ** without change even with newer versions of SQLite.
1582 **
1583 ** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]]
1584 ** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE
1585 ** <dd> These options are obsolete and should not be used by new code.
1586 ** They are retained for backwards compatibility but are now no-ops.
@@ -1590,10 +1603,11 @@
1603 #define SQLITE_CONFIG_GETPCACHE 15 /* no-op */
1604 #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
1605 #define SQLITE_CONFIG_URI 17 /* int */
1606 #define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */
1607 #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
1608 #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
1609
1610 /*
1611 ** CAPI3REF: Database Connection Configuration Options
1612 **
1613 ** These constants are the available integer configuration options that
@@ -2598,11 +2612,11 @@
2612 ** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw",
2613 ** "rwc", or "memory". Attempting to set it to any other value is
2614 ** an error)^.
2615 ** ^If "ro" is specified, then the database is opened for read-only
2616 ** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the
2617 ** third argument to sqlite3_open_v2(). ^If the mode option is set to
2618 ** "rw", then the database is opened for read-write (but not create)
2619 ** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had
2620 ** been set. ^Value "rwc" is equivalent to setting both
2621 ** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If the mode option is
2622 ** set to "memory" then a pure [in-memory database] that never reads
@@ -2749,10 +2763,15 @@
2763 ** text that describes the error, as either UTF-8 or UTF-16 respectively.
2764 ** ^(Memory to hold the error message string is managed internally.
2765 ** The application does not need to worry about freeing the result.
2766 ** However, the error string might be overwritten or deallocated by
2767 ** subsequent calls to other SQLite interface functions.)^
2768 **
2769 ** ^The sqlite3_errstr() interface returns the English-language text
2770 ** that describes the [result code], as UTF-8.
2771 ** ^(Memory to hold the error message string is managed internally
2772 ** and must not be freed by the application)^.
2773 **
2774 ** When the serialized [threading mode] is in use, it might be the
2775 ** case that a second error occurs on a separate thread in between
2776 ** the time of the first error and the call to these interfaces.
2777 ** When that happens, the second error will be reported since these
@@ -2768,10 +2787,11 @@
2787 */
2788 SQLITE_API int sqlite3_errcode(sqlite3 *db);
2789 SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
2790 SQLITE_API const char *sqlite3_errmsg(sqlite3*);
2791 SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
2792 SQLITE_API const char *sqlite3_errstr(int);
2793
2794 /*
2795 ** CAPI3REF: SQL Statement Object
2796 ** KEYWORDS: {prepared statement} {prepared statements}
2797 **
2798

Keyboard Shortcuts

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