Fossil SCM

Update the built-in SQLite to the latest trunk version, as the 3.8.8.3 version contains an unused local variable and hence will not compile when -Werror is used. Add a missing space to an <input> element on the timeline submenu.

drh 2015-02-26 00:31 trunk
Commit c3d72bd99ef1144e215e6d5150c28335dff410a5
4 files changed +13 -11 +536 -255 +29 -7 +1 -1
+13 -11
--- src/shell.c
+++ src/shell.c
@@ -1507,21 +1507,10 @@
15071507
}
15081508
sqlite3_finalize(pExplain);
15091509
sqlite3_free(zEQP);
15101510
}
15111511
1512
-#if USE_SYSTEM_SQLITE+0==1
1513
- /* Output TESTCTRL_EXPLAIN text of requested */
1514
- if( pArg && pArg->mode==MODE_Explain && sqlite3_libversion_number()<3008007 ){
1515
- const char *zExplain = 0;
1516
- sqlite3_test_control(SQLITE_TESTCTRL_EXPLAIN_STMT, pStmt, &zExplain);
1517
- if( zExplain && zExplain[0] ){
1518
- fprintf(pArg->out, "%s", zExplain);
1519
- }
1520
- }
1521
-#endif
1522
-
15231512
/* If the shell is currently in ".explain" mode, gather the extra
15241513
** data required to add indents to the output.*/
15251514
if( pArg && pArg->mode==MODE_Explain ){
15261515
explain_data_prepare(pArg, pStmt);
15271516
}
@@ -3680,10 +3669,11 @@
36803669
{ "optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS },
36813670
{ "iskeyword", SQLITE_TESTCTRL_ISKEYWORD },
36823671
{ "scratchmalloc", SQLITE_TESTCTRL_SCRATCHMALLOC },
36833672
{ "byteorder", SQLITE_TESTCTRL_BYTEORDER },
36843673
{ "never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT },
3674
+ { "imposter", SQLITE_TESTCTRL_IMPOSTER },
36853675
};
36863676
int testctrl = -1;
36873677
int rc = 0;
36883678
int i, n;
36893679
open_db(p, 0);
@@ -3771,10 +3761,22 @@
37713761
fprintf(stderr,"Error: testctrl %s takes a single char * option\n",
37723762
azArg[1]);
37733763
}
37743764
break;
37753765
#endif
3766
+
3767
+ case SQLITE_TESTCTRL_IMPOSTER:
3768
+ if( nArg==5 ){
3769
+ rc = sqlite3_test_control(testctrl, p->db,
3770
+ azArg[2],
3771
+ integerValue(azArg[3]),
3772
+ integerValue(azArg[4]));
3773
+ }else{
3774
+ fprintf(stderr,"Usage: .testctrl initmode dbName onoff tnum\n");
3775
+ rc = 1;
3776
+ }
3777
+ break;
37763778
37773779
case SQLITE_TESTCTRL_BITVEC_TEST:
37783780
case SQLITE_TESTCTRL_FAULT_INSTALL:
37793781
case SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS:
37803782
case SQLITE_TESTCTRL_SCRATCHMALLOC:
37813783
--- src/shell.c
+++ src/shell.c
@@ -1507,21 +1507,10 @@
1507 }
1508 sqlite3_finalize(pExplain);
1509 sqlite3_free(zEQP);
1510 }
1511
1512 #if USE_SYSTEM_SQLITE+0==1
1513 /* Output TESTCTRL_EXPLAIN text of requested */
1514 if( pArg && pArg->mode==MODE_Explain && sqlite3_libversion_number()<3008007 ){
1515 const char *zExplain = 0;
1516 sqlite3_test_control(SQLITE_TESTCTRL_EXPLAIN_STMT, pStmt, &zExplain);
1517 if( zExplain && zExplain[0] ){
1518 fprintf(pArg->out, "%s", zExplain);
1519 }
1520 }
1521 #endif
1522
1523 /* If the shell is currently in ".explain" mode, gather the extra
1524 ** data required to add indents to the output.*/
1525 if( pArg && pArg->mode==MODE_Explain ){
1526 explain_data_prepare(pArg, pStmt);
1527 }
@@ -3680,10 +3669,11 @@
3680 { "optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS },
3681 { "iskeyword", SQLITE_TESTCTRL_ISKEYWORD },
3682 { "scratchmalloc", SQLITE_TESTCTRL_SCRATCHMALLOC },
3683 { "byteorder", SQLITE_TESTCTRL_BYTEORDER },
3684 { "never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT },
 
3685 };
3686 int testctrl = -1;
3687 int rc = 0;
3688 int i, n;
3689 open_db(p, 0);
@@ -3771,10 +3761,22 @@
3771 fprintf(stderr,"Error: testctrl %s takes a single char * option\n",
3772 azArg[1]);
3773 }
3774 break;
3775 #endif
 
 
 
 
 
 
 
 
 
 
 
 
3776
3777 case SQLITE_TESTCTRL_BITVEC_TEST:
3778 case SQLITE_TESTCTRL_FAULT_INSTALL:
3779 case SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS:
3780 case SQLITE_TESTCTRL_SCRATCHMALLOC:
3781
--- src/shell.c
+++ src/shell.c
@@ -1507,21 +1507,10 @@
1507 }
1508 sqlite3_finalize(pExplain);
1509 sqlite3_free(zEQP);
1510 }
1511
 
 
 
 
 
 
 
 
 
 
 
1512 /* If the shell is currently in ".explain" mode, gather the extra
1513 ** data required to add indents to the output.*/
1514 if( pArg && pArg->mode==MODE_Explain ){
1515 explain_data_prepare(pArg, pStmt);
1516 }
@@ -3680,10 +3669,11 @@
3669 { "optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS },
3670 { "iskeyword", SQLITE_TESTCTRL_ISKEYWORD },
3671 { "scratchmalloc", SQLITE_TESTCTRL_SCRATCHMALLOC },
3672 { "byteorder", SQLITE_TESTCTRL_BYTEORDER },
3673 { "never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT },
3674 { "imposter", SQLITE_TESTCTRL_IMPOSTER },
3675 };
3676 int testctrl = -1;
3677 int rc = 0;
3678 int i, n;
3679 open_db(p, 0);
@@ -3771,10 +3761,22 @@
3761 fprintf(stderr,"Error: testctrl %s takes a single char * option\n",
3762 azArg[1]);
3763 }
3764 break;
3765 #endif
3766
3767 case SQLITE_TESTCTRL_IMPOSTER:
3768 if( nArg==5 ){
3769 rc = sqlite3_test_control(testctrl, p->db,
3770 azArg[2],
3771 integerValue(azArg[3]),
3772 integerValue(azArg[4]));
3773 }else{
3774 fprintf(stderr,"Usage: .testctrl initmode dbName onoff tnum\n");
3775 rc = 1;
3776 }
3777 break;
3778
3779 case SQLITE_TESTCTRL_BITVEC_TEST:
3780 case SQLITE_TESTCTRL_FAULT_INSTALL:
3781 case SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS:
3782 case SQLITE_TESTCTRL_SCRATCHMALLOC:
3783
+536 -255
--- 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.8.8.3. By combining all the individual C code files into this
3
+** version 3.8.8. 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.
@@ -276,13 +276,13 @@
276276
**
277277
** See also: [sqlite3_libversion()],
278278
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
279279
** [sqlite_version()] and [sqlite_source_id()].
280280
*/
281
-#define SQLITE_VERSION "3.8.8.3"
281
+#define SQLITE_VERSION "3.8.8"
282282
#define SQLITE_VERSION_NUMBER 3008008
283
-#define SQLITE_SOURCE_ID "2015-02-25 13:29:11 9d6c1880fb75660bbabd693175579529785f8a6b"
283
+#define SQLITE_SOURCE_ID "2015-02-25 14:25:31 6d132e7a224ee68b5cefe9222944aac5760ffc20"
284284
285285
/*
286286
** CAPI3REF: Run-Time Library Version Numbers
287287
** KEYWORDS: sqlite3_version, sqlite3_sourceid
288288
**
@@ -1118,13 +1118,13 @@
11181118
** and only needs to be supported when SQLITE_TEST is defined.
11191119
**
11201120
** </ul>
11211121
*/
11221122
#define SQLITE_FCNTL_LOCKSTATE 1
1123
-#define SQLITE_GET_LOCKPROXYFILE 2
1124
-#define SQLITE_SET_LOCKPROXYFILE 3
1125
-#define SQLITE_LAST_ERRNO 4
1123
+#define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
1124
+#define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
1125
+#define SQLITE_FCNTL_LAST_ERRNO 4
11261126
#define SQLITE_FCNTL_SIZE_HINT 5
11271127
#define SQLITE_FCNTL_CHUNK_SIZE 6
11281128
#define SQLITE_FCNTL_FILE_POINTER 7
11291129
#define SQLITE_FCNTL_SYNC_OMITTED 8
11301130
#define SQLITE_FCNTL_WIN32_AV_RETRY 9
@@ -1139,10 +1139,16 @@
11391139
#define SQLITE_FCNTL_TRACE 19
11401140
#define SQLITE_FCNTL_HAS_MOVED 20
11411141
#define SQLITE_FCNTL_SYNC 21
11421142
#define SQLITE_FCNTL_COMMIT_PHASETWO 22
11431143
#define SQLITE_FCNTL_WIN32_SET_HANDLE 23
1144
+
1145
+/* deprecated names */
1146
+#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
1147
+#define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
1148
+#define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
1149
+
11441150
11451151
/*
11461152
** CAPI3REF: Mutex Handle
11471153
**
11481154
** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -2400,10 +2406,14 @@
24002406
/*
24012407
** CAPI3REF: Formatted String Printing Functions
24022408
**
24032409
** These routines are work-alikes of the "printf()" family of functions
24042410
** from the standard C library.
2411
+** These routines understand most of the common K&R formatting options,
2412
+** plus some additional non-standard formats, detailed below.
2413
+** Note that some of the more obscure formatting options from recent
2414
+** C-library standards are omitted from this implementation.
24052415
**
24062416
** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
24072417
** results into memory obtained from [sqlite3_malloc()].
24082418
** The strings returned by these two routines should be
24092419
** released by [sqlite3_free()]. ^Both routines return a
@@ -2432,11 +2442,11 @@
24322442
** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
24332443
**
24342444
** These routines all implement some additional formatting
24352445
** options that are useful for constructing SQL statements.
24362446
** All of the usual printf() formatting options apply. In addition, there
2437
-** is are "%q", "%Q", and "%z" options.
2447
+** is are "%q", "%Q", "%w" and "%z" options.
24382448
**
24392449
** ^(The %q option works like %s in that it substitutes a nul-terminated
24402450
** string from the argument list. But %q also doubles every '\'' character.
24412451
** %q is designed for use inside a string literal.)^ By doubling each '\''
24422452
** character it escapes that character and allows it to be inserted into
@@ -2484,10 +2494,16 @@
24842494
** sqlite3_free(zSQL);
24852495
** </pre></blockquote>
24862496
**
24872497
** The code above will render a correct SQL statement in the zSQL
24882498
** variable even if the zText variable is a NULL pointer.
2499
+**
2500
+** ^(The "%w" formatting option is like "%q" except that it expects to
2501
+** be contained within double-quotes instead of single quotes, and it
2502
+** escapes the double-quote character instead of the single-quote
2503
+** character.)^ The "%w" formatting option is intended for safely inserting
2504
+** table and column names into a constructed SQL statement.
24892505
**
24902506
** ^(The "%z" formatting option works like "%s" but with the
24912507
** addition that after the string has been read and copied into
24922508
** the result, [sqlite3_free()] is called on the input string.)^
24932509
*/
@@ -5234,10 +5250,15 @@
52345250
** successfully. An [error code] is returned otherwise.)^
52355251
**
52365252
** ^Shared cache is disabled by default. But this might change in
52375253
** future releases of SQLite. Applications that care about shared
52385254
** cache setting should set it explicitly.
5255
+**
5256
+** Note: This method is disabled on MacOS X 10.7 and iOS version 5.0
5257
+** and will always return SQLITE_MISUSE. On those systems,
5258
+** shared cache mode should be enabled per-database connection via
5259
+** [sqlite3_open_v2()] with [SQLITE_OPEN_SHAREDCACHE].
52395260
**
52405261
** This interface is threadsafe on processors where writing a
52415262
** 32-bit integer is atomic.
52425263
**
52435264
** See Also: [SQLite Shared-Cache Mode]
@@ -6434,11 +6455,12 @@
64346455
#define SQLITE_TESTCTRL_NEVER_CORRUPT 20
64356456
#define SQLITE_TESTCTRL_VDBE_COVERAGE 21
64366457
#define SQLITE_TESTCTRL_BYTEORDER 22
64376458
#define SQLITE_TESTCTRL_ISINIT 23
64386459
#define SQLITE_TESTCTRL_SORTER_MMAP 24
6439
-#define SQLITE_TESTCTRL_LAST 24
6460
+#define SQLITE_TESTCTRL_IMPOSTER 25
6461
+#define SQLITE_TESTCTRL_LAST 25
64406462
64416463
/*
64426464
** CAPI3REF: SQLite Runtime Status
64436465
**
64446466
** ^This interface is used to retrieve runtime status information
@@ -9219,14 +9241,12 @@
92199241
SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve, int eFix);
92209242
SQLITE_PRIVATE int sqlite3BtreeGetPageSize(Btree*);
92219243
SQLITE_PRIVATE int sqlite3BtreeMaxPageCount(Btree*,int);
92229244
SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree*);
92239245
SQLITE_PRIVATE int sqlite3BtreeSecureDelete(Btree*,int);
9224
-SQLITE_PRIVATE int sqlite3BtreeGetReserve(Btree*);
9225
-#if defined(SQLITE_HAS_CODEC) || defined(SQLITE_DEBUG)
9246
+SQLITE_PRIVATE int sqlite3BtreeGetOptimalReserve(Btree*);
92269247
SQLITE_PRIVATE int sqlite3BtreeGetReserveNoMutex(Btree *p);
9227
-#endif
92289248
SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum(Btree *, int);
92299249
SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *);
92309250
SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree*,int);
92319251
SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster);
92329252
SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree*, int);
@@ -10839,10 +10859,11 @@
1083910859
struct sqlite3InitInfo { /* Information used during initialization */
1084010860
int newTnum; /* Rootpage of table being initialized */
1084110861
u8 iDb; /* Which db file is being initialized */
1084210862
u8 busy; /* TRUE if currently initializing */
1084310863
u8 orphanTrigger; /* Last statement is orphaned TEMP trigger */
10864
+ u8 imposterTable; /* Building an imposter table */
1084410865
} init;
1084510866
int nVdbeActive; /* Number of VDBEs currently running */
1084610867
int nVdbeRead; /* Number of active VDBEs that read or write */
1084710868
int nVdbeWrite; /* Number of active VDBEs that read and write */
1084810869
int nVdbeExec; /* Number of nested calls to VdbeExec() */
@@ -11795,12 +11816,18 @@
1179511816
#define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
1179611817
#define EP_Static 0x008000 /* Held in memory not obtained from malloc() */
1179711818
#define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */
1179811819
#define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
1179911820
#define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
11800
-#define EP_Constant 0x080000 /* Node is a constant */
11821
+#define EP_ConstFunc 0x080000 /* Node is a SQLITE_FUNC_CONSTANT function */
1180111822
#define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
11823
+#define EP_Subquery 0x200000 /* Tree contains a TK_SELECT operator */
11824
+
11825
+/*
11826
+** Combinations of two or more EP_* flags
11827
+*/
11828
+#define EP_Propagate (EP_Collate|EP_Subquery) /* Propagate these bits up tree */
1180211829
1180311830
/*
1180411831
** These macros can be used to test, set, or clear bits in the
1180511832
** Expr.flags field.
1180611833
*/
@@ -12904,10 +12931,11 @@
1290412931
SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*);
1290512932
SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
1290612933
SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int);
1290712934
SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,ExprSpan*);
1290812935
SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*);
12936
+SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList*);
1290912937
SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**);
1291012938
SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**);
1291112939
SQLITE_PRIVATE void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
1291212940
SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3*);
1291312941
SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3*,int);
@@ -13487,16 +13515,15 @@
1348713515
1348813516
SQLITE_PRIVATE void sqlite3MemJournalOpen(sqlite3_file *);
1348913517
SQLITE_PRIVATE int sqlite3MemJournalSize(void);
1349013518
SQLITE_PRIVATE int sqlite3IsMemJournal(sqlite3_file *);
1349113519
13520
+SQLITE_PRIVATE void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p);
1349213521
#if SQLITE_MAX_EXPR_DEPTH>0
13493
-SQLITE_PRIVATE void sqlite3ExprSetHeight(Parse *pParse, Expr *p);
1349413522
SQLITE_PRIVATE int sqlite3SelectExprHeight(Select *);
1349513523
SQLITE_PRIVATE int sqlite3ExprCheckHeight(Parse*, int);
1349613524
#else
13497
- #define sqlite3ExprSetHeight(x,y)
1349813525
#define sqlite3SelectExprHeight(x) 0
1349913526
#define sqlite3ExprCheckHeight(x,y)
1350013527
#endif
1350113528
1350213529
SQLITE_PRIVATE u32 sqlite3Get4byte(const u8*);
@@ -13629,20 +13656,20 @@
1362913656
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, /* 1x */
1363013657
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, /* 2x */
1363113658
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, /* 3x */
1363213659
64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, /* 4x */
1363313660
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, /* 5x */
13634
- 96, 97, 66, 67, 68, 69, 70, 71, 72, 73,106,107,108,109,110,111, /* 6x */
13635
- 112, 81, 82, 83, 84, 85, 86, 87, 88, 89,122,123,124,125,126,127, /* 7x */
13661
+ 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, /* 6x */
13662
+ 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, /* 7x */
1363613663
128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, /* 8x */
13637
- 144,145,146,147,148,149,150,151,152,153,154,155,156,157,156,159, /* 9x */
13664
+ 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, /* 9x */
1363813665
160,161,162,163,164,165,166,167,168,169,170,171,140,141,142,175, /* Ax */
1363913666
176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191, /* Bx */
1364013667
192,129,130,131,132,133,134,135,136,137,202,203,204,205,206,207, /* Cx */
1364113668
208,145,146,147,148,149,150,151,152,153,218,219,220,221,222,223, /* Dx */
13642
- 224,225,162,163,164,165,166,167,168,169,232,203,204,205,206,207, /* Ex */
13643
- 239,240,241,242,243,244,245,246,247,248,249,219,220,221,222,255, /* Fx */
13669
+ 224,225,162,163,164,165,166,167,168,169,234,235,236,237,238,239, /* Ex */
13670
+ 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255, /* Fx */
1364413671
#endif
1364513672
};
1364613673
1364713674
/*
1364813675
** The following 256 byte lookup table is used to support SQLites built-in
@@ -14637,10 +14664,13 @@
1463714664
ynVar nVar; /* Number of entries in aVar[] */
1463814665
ynVar nzVar; /* Number of entries in azVar[] */
1463914666
u32 cacheCtr; /* VdbeCursor row cache generation counter */
1464014667
int pc; /* The program counter */
1464114668
int rc; /* Value to return */
14669
+#ifdef SQLITE_DEBUG
14670
+ int rcApp; /* errcode set by sqlite3_result_error_code() */
14671
+#endif
1464214672
u16 nResColumn; /* Number of columns in one row of the result set */
1464314673
u8 errorAction; /* Recovery action to do in case of an error */
1464414674
u8 minWriteFileFormat; /* Minimum file format for writable database files */
1464514675
bft explain:2; /* True if EXPLAIN present on SQL command */
1464614676
bft inVtabMethod:2; /* See comments above */
@@ -19111,12 +19141,16 @@
1911119141
pNew->cnt = 0;
1911219142
}
1911319143
break;
1911419144
}
1911519145
default: {
19116
- assert( id-2 >= 0 );
19117
- assert( id-2 < (int)(sizeof(aStatic)/sizeof(aStatic[0])) );
19146
+#ifdef SQLITE_ENABLE_API_ARMOR
19147
+ if( id-2<0 || id-2>=ArraySize(aStatic) ){
19148
+ (void)SQLITE_MISUSE_BKPT;
19149
+ return 0;
19150
+ }
19151
+#endif
1911819152
pNew = &aStatic[id-2];
1911919153
pNew->id = id;
1912019154
break;
1912119155
}
1912219156
}
@@ -19127,12 +19161,17 @@
1912719161
** This routine deallocates a previously allocated mutex.
1912819162
*/
1912919163
static void debugMutexFree(sqlite3_mutex *pX){
1913019164
sqlite3_debug_mutex *p = (sqlite3_debug_mutex*)pX;
1913119165
assert( p->cnt==0 );
19132
- assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE );
19133
- sqlite3_free(p);
19166
+ if( p->id==SQLITE_MUTEX_RECURSIVE || p->id==SQLITE_MUTEX_FAST ){
19167
+ sqlite3_free(p);
19168
+ }else{
19169
+#ifdef SQLITE_ENABLE_API_ARMOR
19170
+ (void)SQLITE_MISUSE_BKPT;
19171
+#endif
19172
+ }
1913419173
}
1913519174
1913619175
/*
1913719176
** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
1913819177
** to enter a mutex. If another thread is already within the mutex,
@@ -19239,12 +19278,14 @@
1923919278
/*
1924019279
** Each recursive mutex is an instance of the following structure.
1924119280
*/
1924219281
struct sqlite3_mutex {
1924319282
pthread_mutex_t mutex; /* Mutex controlling the lock */
19244
-#if SQLITE_MUTEX_NREF
19283
+#if SQLITE_MUTEX_NREF || defined(SQLITE_ENABLE_API_ARMOR)
1924519284
int id; /* Mutex type */
19285
+#endif
19286
+#if SQLITE_MUTEX_NREF
1924619287
volatile int nRef; /* Number of entrances */
1924719288
volatile pthread_t owner; /* Thread that is within this mutex */
1924819289
int trace; /* True to trace changes */
1924919290
#endif
1925019291
};
@@ -19357,22 +19398,16 @@
1935719398
pthread_mutexattr_init(&recursiveAttr);
1935819399
pthread_mutexattr_settype(&recursiveAttr, PTHREAD_MUTEX_RECURSIVE);
1935919400
pthread_mutex_init(&p->mutex, &recursiveAttr);
1936019401
pthread_mutexattr_destroy(&recursiveAttr);
1936119402
#endif
19362
-#if SQLITE_MUTEX_NREF
19363
- p->id = iType;
19364
-#endif
1936519403
}
1936619404
break;
1936719405
}
1936819406
case SQLITE_MUTEX_FAST: {
1936919407
p = sqlite3MallocZero( sizeof(*p) );
1937019408
if( p ){
19371
-#if SQLITE_MUTEX_NREF
19372
- p->id = iType;
19373
-#endif
1937419409
pthread_mutex_init(&p->mutex, 0);
1937519410
}
1937619411
break;
1937719412
}
1937819413
default: {
@@ -19381,16 +19416,16 @@
1938119416
(void)SQLITE_MISUSE_BKPT;
1938219417
return 0;
1938319418
}
1938419419
#endif
1938519420
p = &staticMutexes[iType-2];
19386
-#if SQLITE_MUTEX_NREF
19387
- p->id = iType;
19388
-#endif
1938919421
break;
1939019422
}
1939119423
}
19424
+#if SQLITE_MUTEX_NREF || defined(SQLITE_ENABLE_API_ARMOR)
19425
+ if( p ) p->id = iType;
19426
+#endif
1939219427
return p;
1939319428
}
1939419429
1939519430
1939619431
/*
@@ -19398,13 +19433,22 @@
1939819433
** allocated mutex. SQLite is careful to deallocate every
1939919434
** mutex that it allocates.
1940019435
*/
1940119436
static void pthreadMutexFree(sqlite3_mutex *p){
1940219437
assert( p->nRef==0 );
19403
- assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE );
19404
- pthread_mutex_destroy(&p->mutex);
19405
- sqlite3_free(p);
19438
+#if SQLITE_ENABLE_API_ARMOR
19439
+ if( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE )
19440
+#endif
19441
+ {
19442
+ pthread_mutex_destroy(&p->mutex);
19443
+ sqlite3_free(p);
19444
+ }
19445
+#ifdef SQLITE_ENABLE_API_ARMOR
19446
+ else{
19447
+ (void)SQLITE_MISUSE_BKPT;
19448
+ }
19449
+#endif
1940619450
}
1940719451
1940819452
/*
1940919453
** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
1941019454
** to enter a mutex. If another thread is already within the mutex,
@@ -19870,10 +19914,21 @@
1987019914
# define SQLITE_WIN32_VOLATILE
1987119915
#else
1987219916
# define SQLITE_WIN32_VOLATILE volatile
1987319917
#endif
1987419918
19919
+/*
19920
+** For some Windows sub-platforms, the _beginthreadex() / _endthreadex()
19921
+** functions are not available (e.g. those not using MSVC, Cygwin, etc).
19922
+*/
19923
+#if SQLITE_OS_WIN && !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && \
19924
+ SQLITE_THREADSAFE>0 && !defined(__CYGWIN__)
19925
+# define SQLITE_OS_WIN_THREADS 1
19926
+#else
19927
+# define SQLITE_OS_WIN_THREADS 0
19928
+#endif
19929
+
1987519930
#endif /* _OS_WIN_H_ */
1987619931
1987719932
/************** End of os_win.h **********************************************/
1987819933
/************** Continuing where we left off in mutex_w32.c ******************/
1987919934
#endif
@@ -20045,12 +20100,12 @@
2004520100
switch( iType ){
2004620101
case SQLITE_MUTEX_FAST:
2004720102
case SQLITE_MUTEX_RECURSIVE: {
2004820103
p = sqlite3MallocZero( sizeof(*p) );
2004920104
if( p ){
20050
-#ifdef SQLITE_DEBUG
2005120105
p->id = iType;
20106
+#ifdef SQLITE_DEBUG
2005220107
#ifdef SQLITE_WIN32_MUTEX_TRACE_DYNAMIC
2005320108
p->trace = 1;
2005420109
#endif
2005520110
#endif
2005620111
#if SQLITE_OS_WINRT
@@ -20066,16 +20121,13 @@
2006620121
if( iType-2<0 || iType-2>=ArraySize(winMutex_staticMutexes) ){
2006720122
(void)SQLITE_MISUSE_BKPT;
2006820123
return 0;
2006920124
}
2007020125
#endif
20071
- assert( iType-2 >= 0 );
20072
- assert( iType-2 < ArraySize(winMutex_staticMutexes) );
20073
- assert( winMutex_isInit==1 );
2007420126
p = &winMutex_staticMutexes[iType-2];
20075
-#ifdef SQLITE_DEBUG
2007620127
p->id = iType;
20128
+#ifdef SQLITE_DEBUG
2007720129
#ifdef SQLITE_WIN32_MUTEX_TRACE_STATIC
2007820130
p->trace = 1;
2007920131
#endif
2008020132
#endif
2008120133
break;
@@ -20090,17 +20142,19 @@
2009020142
** allocated mutex. SQLite is careful to deallocate every
2009120143
** mutex that it allocates.
2009220144
*/
2009320145
static void winMutexFree(sqlite3_mutex *p){
2009420146
assert( p );
20095
-#ifdef SQLITE_DEBUG
2009620147
assert( p->nRef==0 && p->owner==0 );
20097
- assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE );
20148
+ if( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE ){
20149
+ DeleteCriticalSection(&p->mutex);
20150
+ sqlite3_free(p);
20151
+ }else{
20152
+#ifdef SQLITE_ENABLE_API_ARMOR
20153
+ (void)SQLITE_MISUSE_BKPT;
2009820154
#endif
20099
- assert( winMutex_isInit==1 );
20100
- DeleteCriticalSection(&p->mutex);
20101
- sqlite3_free(p);
20155
+ }
2010220156
}
2010320157
2010420158
/*
2010520159
** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
2010620160
** to enter a mutex. If another thread is already within the mutex,
@@ -21260,17 +21314,10 @@
2126021314
etByte flag_rtz; /* True if trailing zeros should be removed */
2126121315
#endif
2126221316
PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */
2126321317
char buf[etBUFSIZE]; /* Conversion buffer */
2126421318
21265
-#ifdef SQLITE_ENABLE_API_ARMOR
21266
- if( ap==0 ){
21267
- (void)SQLITE_MISUSE_BKPT;
21268
- sqlite3StrAccumReset(pAccum);
21269
- return;
21270
- }
21271
-#endif
2127221319
bufpt = 0;
2127321320
if( bFlags ){
2127421321
if( (bArgList = (bFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){
2127521322
pArgList = va_arg(ap, PrintfArguments*);
2127621323
}
@@ -22050,11 +22097,11 @@
2205022097
StrAccum acc;
2205122098
if( n<=0 ) return zBuf;
2205222099
#ifdef SQLITE_ENABLE_API_ARMOR
2205322100
if( zBuf==0 || zFormat==0 ) {
2205422101
(void)SQLITE_MISUSE_BKPT;
22055
- if( zBuf && n>0 ) zBuf[0] = 0;
22102
+ if( zBuf ) zBuf[0] = 0;
2205622103
return zBuf;
2205722104
}
2205822105
#endif
2205922106
sqlite3StrAccumInit(&acc, zBuf, n, 0);
2206022107
acc.useMalloc = 0;
@@ -22433,11 +22480,11 @@
2243322480
#endif /* SQLITE_OS_UNIX && defined(SQLITE_MUTEX_PTHREADS) */
2243422481
/******************************** End Unix Pthreads *************************/
2243522482
2243622483
2243722484
/********************************* Win32 Threads ****************************/
22438
-#if SQLITE_OS_WIN && !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_THREADSAFE>0
22485
+#if SQLITE_OS_WIN_THREADS
2243922486
2244022487
#define SQLITE_THREADS_IMPLEMENTED 1 /* Prevent the single-thread code below */
2244122488
#include <process.h>
2244222489
2244322490
/* A running thread */
@@ -22526,11 +22573,11 @@
2252622573
if( rc==WAIT_OBJECT_0 ) *ppOut = p->pResult;
2252722574
sqlite3_free(p);
2252822575
return (rc==WAIT_OBJECT_0) ? SQLITE_OK : SQLITE_ERROR;
2252922576
}
2253022577
22531
-#endif /* SQLITE_OS_WIN && !SQLITE_OS_WINCE && !SQLITE_OS_WINRT */
22578
+#endif /* SQLITE_OS_WIN_THREADS */
2253222579
/******************************** End Win32 Threads *************************/
2253322580
2253422581
2253522582
/********************************* Single-Threaded **************************/
2253622583
#ifndef SQLITE_THREADS_IMPLEMENTED
@@ -25201,11 +25248,11 @@
2520125248
#endif
2520225249
#define UNIXFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */
2520325250
#define UNIXFILE_DELETE 0x20 /* Delete on close */
2520425251
#define UNIXFILE_URI 0x40 /* Filename might have query parameters */
2520525252
#define UNIXFILE_NOLOCK 0x80 /* Do no file locking */
25206
-#define UNIXFILE_WARNED 0x0100 /* verifyDbFile() warnings have been issued */
25253
+#define UNIXFILE_WARNED 0x0100 /* verifyDbFile() warnings issued */
2520725254
2520825255
/*
2520925256
** Include code that is common to all os_*.c files
2521025257
*/
2521125258
/************** Include os_common.h in the middle of os_unix.c ***************/
@@ -25872,13 +25919,13 @@
2587225919
#endif /* SQLITE_LOCK_TRACE */
2587325920
2587425921
/*
2587525922
** Retry ftruncate() calls that fail due to EINTR
2587625923
**
25877
-** All calls to ftruncate() within this file should be made through this wrapper.
25878
-** On the Android platform, bypassing the logic below could lead to a corrupt
25879
-** database.
25924
+** All calls to ftruncate() within this file should be made through
25925
+** this wrapper. On the Android platform, bypassing the logic below
25926
+** could lead to a corrupt database.
2588025927
*/
2588125928
static int robust_ftruncate(int h, sqlite3_int64 sz){
2588225929
int rc;
2588325930
#ifdef __ANDROID__
2588425931
/* On Android, ftruncate() always uses 32-bit offsets, even if
@@ -26332,10 +26379,18 @@
2633226379
if( osClose(h) ){
2633326380
unixLogErrorAtLine(SQLITE_IOERR_CLOSE, "close",
2633426381
pFile ? pFile->zPath : 0, lineno);
2633526382
}
2633626383
}
26384
+
26385
+/*
26386
+** Set the pFile->lastErrno. Do this in a subroutine as that provides
26387
+** a convenient place to set a breakpoint.
26388
+*/
26389
+static void storeLastErrno(unixFile *pFile, int error){
26390
+ pFile->lastErrno = error;
26391
+}
2633726392
2633826393
/*
2633926394
** Close all file descriptors accumuated in the unixInodeInfo->pUnused list.
2634026395
*/
2634126396
static void closePendingFds(unixFile *pFile){
@@ -26406,11 +26461,11 @@
2640626461
** create a unique name for the file.
2640726462
*/
2640826463
fd = pFile->h;
2640926464
rc = osFstat(fd, &statbuf);
2641026465
if( rc!=0 ){
26411
- pFile->lastErrno = errno;
26466
+ storeLastErrno(pFile, errno);
2641226467
#ifdef EOVERFLOW
2641326468
if( pFile->lastErrno==EOVERFLOW ) return SQLITE_NOLFS;
2641426469
#endif
2641526470
return SQLITE_IOERR;
2641626471
}
@@ -26427,16 +26482,16 @@
2642726482
** the first page of the database, no damage is done.
2642826483
*/
2642926484
if( statbuf.st_size==0 && (pFile->fsFlags & SQLITE_FSFLAGS_IS_MSDOS)!=0 ){
2643026485
do{ rc = osWrite(fd, "S", 1); }while( rc<0 && errno==EINTR );
2643126486
if( rc!=1 ){
26432
- pFile->lastErrno = errno;
26487
+ storeLastErrno(pFile, errno);
2643326488
return SQLITE_IOERR;
2643426489
}
2643526490
rc = osFstat(fd, &statbuf);
2643626491
if( rc!=0 ){
26437
- pFile->lastErrno = errno;
26492
+ storeLastErrno(pFile, errno);
2643826493
return SQLITE_IOERR;
2643926494
}
2644026495
}
2644126496
#endif
2644226497
@@ -26555,11 +26610,11 @@
2655526610
lock.l_start = RESERVED_BYTE;
2655626611
lock.l_len = 1;
2655726612
lock.l_type = F_WRLCK;
2655826613
if( osFcntl(pFile->h, F_GETLK, &lock) ){
2655926614
rc = SQLITE_IOERR_CHECKRESERVEDLOCK;
26560
- pFile->lastErrno = errno;
26615
+ storeLastErrno(pFile, errno);
2656126616
} else if( lock.l_type!=F_UNLCK ){
2656226617
reserved = 1;
2656326618
}
2656426619
}
2656526620
#endif
@@ -26755,11 +26810,11 @@
2675526810
lock.l_start = PENDING_BYTE;
2675626811
if( unixFileLock(pFile, &lock) ){
2675726812
tErrno = errno;
2675826813
rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
2675926814
if( rc!=SQLITE_BUSY ){
26760
- pFile->lastErrno = tErrno;
26815
+ storeLastErrno(pFile, tErrno);
2676126816
}
2676226817
goto end_lock;
2676326818
}
2676426819
}
2676526820
@@ -26790,11 +26845,11 @@
2679026845
rc = SQLITE_IOERR_UNLOCK;
2679126846
}
2679226847
2679326848
if( rc ){
2679426849
if( rc!=SQLITE_BUSY ){
26795
- pFile->lastErrno = tErrno;
26850
+ storeLastErrno(pFile, tErrno);
2679626851
}
2679726852
goto end_lock;
2679826853
}else{
2679926854
pFile->eFileLock = SHARED_LOCK;
2680026855
pInode->nLock++;
@@ -26823,11 +26878,11 @@
2682326878
2682426879
if( unixFileLock(pFile, &lock) ){
2682526880
tErrno = errno;
2682626881
rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
2682726882
if( rc!=SQLITE_BUSY ){
26828
- pFile->lastErrno = tErrno;
26883
+ storeLastErrno(pFile, tErrno);
2682926884
}
2683026885
}
2683126886
}
2683226887
2683326888
@@ -26930,11 +26985,10 @@
2693026985
** 2: [....W]
2693126986
** 3: [RRRRW]
2693226987
** 4: [RRRR.]
2693326988
*/
2693426989
if( eFileLock==SHARED_LOCK ){
26935
-
2693626990
#if !defined(__APPLE__) || !SQLITE_ENABLE_LOCKING_STYLE
2693726991
(void)handleNFSUnlock;
2693826992
assert( handleNFSUnlock==0 );
2693926993
#endif
2694026994
#if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
@@ -26948,11 +27002,11 @@
2694827002
lock.l_len = divSize;
2694927003
if( unixFileLock(pFile, &lock)==(-1) ){
2695027004
tErrno = errno;
2695127005
rc = SQLITE_IOERR_UNLOCK;
2695227006
if( IS_LOCK_ERROR(rc) ){
26953
- pFile->lastErrno = tErrno;
27007
+ storeLastErrno(pFile, tErrno);
2695427008
}
2695527009
goto end_unlock;
2695627010
}
2695727011
lock.l_type = F_RDLCK;
2695827012
lock.l_whence = SEEK_SET;
@@ -26960,11 +27014,11 @@
2696027014
lock.l_len = divSize;
2696127015
if( unixFileLock(pFile, &lock)==(-1) ){
2696227016
tErrno = errno;
2696327017
rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_RDLOCK);
2696427018
if( IS_LOCK_ERROR(rc) ){
26965
- pFile->lastErrno = tErrno;
27019
+ storeLastErrno(pFile, tErrno);
2696627020
}
2696727021
goto end_unlock;
2696827022
}
2696927023
lock.l_type = F_UNLCK;
2697027024
lock.l_whence = SEEK_SET;
@@ -26972,11 +27026,11 @@
2697227026
lock.l_len = SHARED_SIZE-divSize;
2697327027
if( unixFileLock(pFile, &lock)==(-1) ){
2697427028
tErrno = errno;
2697527029
rc = SQLITE_IOERR_UNLOCK;
2697627030
if( IS_LOCK_ERROR(rc) ){
26977
- pFile->lastErrno = tErrno;
27031
+ storeLastErrno(pFile, tErrno);
2697827032
}
2697927033
goto end_unlock;
2698027034
}
2698127035
}else
2698227036
#endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */
@@ -26991,11 +27045,11 @@
2699127045
** indicates that the other process is not following the locking
2699227046
** protocol. If this happens, return SQLITE_IOERR_RDLOCK. Returning
2699327047
** SQLITE_BUSY would confuse the upper layer (in practice it causes
2699427048
** an assert to fail). */
2699527049
rc = SQLITE_IOERR_RDLOCK;
26996
- pFile->lastErrno = errno;
27050
+ storeLastErrno(pFile, errno);
2699727051
goto end_unlock;
2699827052
}
2699927053
}
2700027054
}
2700127055
lock.l_type = F_UNLCK;
@@ -27004,11 +27058,11 @@
2700427058
lock.l_len = 2L; assert( PENDING_BYTE+1==RESERVED_BYTE );
2700527059
if( unixFileLock(pFile, &lock)==0 ){
2700627060
pInode->eFileLock = SHARED_LOCK;
2700727061
}else{
2700827062
rc = SQLITE_IOERR_UNLOCK;
27009
- pFile->lastErrno = errno;
27063
+ storeLastErrno(pFile, errno);
2701027064
goto end_unlock;
2701127065
}
2701227066
}
2701327067
if( eFileLock==NO_LOCK ){
2701427068
/* Decrement the shared lock counter. Release the lock using an
@@ -27022,11 +27076,11 @@
2702227076
lock.l_start = lock.l_len = 0L;
2702327077
if( unixFileLock(pFile, &lock)==0 ){
2702427078
pInode->eFileLock = NO_LOCK;
2702527079
}else{
2702627080
rc = SQLITE_IOERR_UNLOCK;
27027
- pFile->lastErrno = errno;
27081
+ storeLastErrno(pFile, errno);
2702827082
pInode->eFileLock = NO_LOCK;
2702927083
pFile->eFileLock = NO_LOCK;
2703027084
}
2703127085
}
2703227086
@@ -27297,11 +27351,11 @@
2729727351
if( EEXIST == tErrno ){
2729827352
rc = SQLITE_BUSY;
2729927353
} else {
2730027354
rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
2730127355
if( IS_LOCK_ERROR(rc) ){
27302
- pFile->lastErrno = tErrno;
27356
+ storeLastErrno(pFile, tErrno);
2730327357
}
2730427358
}
2730527359
return rc;
2730627360
}
2730727361
@@ -27351,11 +27405,11 @@
2735127405
rc = 0;
2735227406
if( ENOENT != tErrno ){
2735327407
rc = SQLITE_IOERR_UNLOCK;
2735427408
}
2735527409
if( IS_LOCK_ERROR(rc) ){
27356
- pFile->lastErrno = tErrno;
27410
+ storeLastErrno(pFile, tErrno);
2735727411
}
2735827412
return rc;
2735927413
}
2736027414
pFile->eFileLock = NO_LOCK;
2736127415
return SQLITE_OK;
@@ -27438,21 +27492,21 @@
2743827492
if ( lrc ) {
2743927493
int tErrno = errno;
2744027494
/* unlock failed with an error */
2744127495
lrc = SQLITE_IOERR_UNLOCK;
2744227496
if( IS_LOCK_ERROR(lrc) ){
27443
- pFile->lastErrno = tErrno;
27497
+ storeLastErrno(pFile, tErrno);
2744427498
rc = lrc;
2744527499
}
2744627500
}
2744727501
} else {
2744827502
int tErrno = errno;
2744927503
reserved = 1;
2745027504
/* someone else might have it reserved */
2745127505
lrc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
2745227506
if( IS_LOCK_ERROR(lrc) ){
27453
- pFile->lastErrno = tErrno;
27507
+ storeLastErrno(pFile, tErrno);
2745427508
rc = lrc;
2745527509
}
2745627510
}
2745727511
}
2745827512
OSTRACE(("TEST WR-LOCK %d %d %d (flock)\n", pFile->h, rc, reserved));
@@ -27514,11 +27568,11 @@
2751427568
if (robust_flock(pFile->h, LOCK_EX | LOCK_NB)) {
2751527569
int tErrno = errno;
2751627570
/* didn't get, must be busy */
2751727571
rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
2751827572
if( IS_LOCK_ERROR(rc) ){
27519
- pFile->lastErrno = tErrno;
27573
+ storeLastErrno(pFile, tErrno);
2752027574
}
2752127575
} else {
2752227576
/* got it, set the type and return ok */
2752327577
pFile->eFileLock = eFileLock;
2752427578
}
@@ -27626,11 +27680,11 @@
2762627680
2762727681
if( sem_trywait(pSem)==-1 ){
2762827682
int tErrno = errno;
2762927683
if( EAGAIN != tErrno ){
2763027684
rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_CHECKRESERVEDLOCK);
27631
- pFile->lastErrno = tErrno;
27685
+ storeLastErrno(pFile, tErrno);
2763227686
} else {
2763327687
/* someone else has the lock when we are in NO_LOCK */
2763427688
reserved = (pFile->eFileLock < SHARED_LOCK);
2763527689
}
2763627690
}else{
@@ -27730,11 +27784,11 @@
2773027784
/* no, really unlock. */
2773127785
if ( sem_post(pSem)==-1 ) {
2773227786
int rc, tErrno = errno;
2773327787
rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK);
2773427788
if( IS_LOCK_ERROR(rc) ){
27735
- pFile->lastErrno = tErrno;
27789
+ storeLastErrno(pFile, tErrno);
2773627790
}
2773727791
return rc;
2773827792
}
2773927793
pFile->eFileLock = NO_LOCK;
2774027794
return SQLITE_OK;
@@ -27832,11 +27886,11 @@
2783227886
#else
2783327887
rc = sqliteErrorFromPosixError(tErrno,
2783427888
setLockFlag ? SQLITE_IOERR_LOCK : SQLITE_IOERR_UNLOCK);
2783527889
#endif /* SQLITE_IGNORE_AFP_LOCK_ERRORS */
2783627890
if( IS_LOCK_ERROR(rc) ){
27837
- pFile->lastErrno = tErrno;
27891
+ storeLastErrno(pFile, tErrno);
2783827892
}
2783927893
return rc;
2784027894
} else {
2784127895
return SQLITE_OK;
2784227896
}
@@ -28015,11 +28069,11 @@
2801528069
}
2801628070
/* Drop the temporary PENDING lock */
2801728071
lrc2 = afpSetLock(context->dbPath, pFile, PENDING_BYTE, 1, 0);
2801828072
2801928073
if( IS_LOCK_ERROR(lrc1) ) {
28020
- pFile->lastErrno = lrc1Errno;
28074
+ storeLastErrno(pFile, lrc1Errno);
2802128075
rc = lrc1;
2802228076
goto afp_end_lock;
2802328077
} else if( IS_LOCK_ERROR(lrc2) ){
2802428078
rc = lrc2;
2802528079
goto afp_end_lock;
@@ -28302,23 +28356,23 @@
2830228356
#else
2830328357
newOffset = lseek(id->h, offset, SEEK_SET);
2830428358
SimulateIOError( newOffset-- );
2830528359
if( newOffset!=offset ){
2830628360
if( newOffset == -1 ){
28307
- ((unixFile*)id)->lastErrno = errno;
28361
+ storeLastErrno((unixFile*)id, errno);
2830828362
}else{
28309
- ((unixFile*)id)->lastErrno = 0;
28363
+ storeLastErrno((unixFile*)id, 0);
2831028364
}
2831128365
return -1;
2831228366
}
2831328367
got = osRead(id->h, pBuf, cnt);
2831428368
#endif
2831528369
if( got==cnt ) break;
2831628370
if( got<0 ){
2831728371
if( errno==EINTR ){ got = 1; continue; }
2831828372
prior = 0;
28319
- ((unixFile*)id)->lastErrno = errno;
28373
+ storeLastErrno((unixFile*)id, errno);
2832028374
break;
2832128375
}else if( got>0 ){
2832228376
cnt -= got;
2832328377
offset += got;
2832428378
prior += got;
@@ -28379,11 +28433,11 @@
2837928433
return SQLITE_OK;
2838028434
}else if( got<0 ){
2838128435
/* lastErrno set by seekAndRead */
2838228436
return SQLITE_IOERR_READ;
2838328437
}else{
28384
- pFile->lastErrno = 0; /* not a system error */
28438
+ storeLastErrno(pFile, 0); /* not a system error */
2838528439
/* Unread parts of the buffer must be zero-filled */
2838628440
memset(&((char*)pBuf)[got], 0, amt-got);
2838728441
return SQLITE_IOERR_SHORT_READ;
2838828442
}
2838928443
}
@@ -28408,13 +28462,13 @@
2840828462
assert( fd>2 );
2840928463
nBuf &= 0x1ffff;
2841028464
TIMER_START;
2841128465
2841228466
#if defined(USE_PREAD)
28413
- do{ rc = osPwrite(fd, pBuf, nBuf, iOff); }while( rc<0 && errno==EINTR );
28467
+ do{ rc = (int)osPwrite(fd, pBuf, nBuf, iOff); }while( rc<0 && errno==EINTR );
2841428468
#elif defined(USE_PREAD64)
28415
- do{ rc = osPwrite64(fd, pBuf, nBuf, iOff);}while( rc<0 && errno==EINTR);
28469
+ do{ rc = (int)osPwrite64(fd, pBuf, nBuf, iOff);}while( rc<0 && errno==EINTR);
2841628470
#else
2841728471
do{
2841828472
i64 iSeek = lseek(fd, iOff, SEEK_SET);
2841928473
SimulateIOError( iSeek-- );
2842028474
@@ -28520,11 +28574,11 @@
2852028574
if( amt>0 ){
2852128575
if( wrote<0 && pFile->lastErrno!=ENOSPC ){
2852228576
/* lastErrno set by seekAndWrite */
2852328577
return SQLITE_IOERR_WRITE;
2852428578
}else{
28525
- pFile->lastErrno = 0; /* not a system error */
28579
+ storeLastErrno(pFile, 0); /* not a system error */
2852628580
return SQLITE_FULL;
2852728581
}
2852828582
}
2852928583
2853028584
return SQLITE_OK;
@@ -28729,11 +28783,11 @@
2872928783
assert( pFile );
2873028784
OSTRACE(("SYNC %-3d\n", pFile->h));
2873128785
rc = full_fsync(pFile->h, isFullsync, isDataOnly);
2873228786
SimulateIOError( rc=1 );
2873328787
if( rc ){
28734
- pFile->lastErrno = errno;
28788
+ storeLastErrno(pFile, errno);
2873528789
return unixLogError(SQLITE_IOERR_FSYNC, "full_fsync", pFile->zPath);
2873628790
}
2873728791
2873828792
/* Also fsync the directory containing the file if the DIRSYNC flag
2873928793
** is set. This is a one-time occurrence. Many systems (examples: AIX)
@@ -28773,11 +28827,11 @@
2877328827
nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk;
2877428828
}
2877528829
2877628830
rc = robust_ftruncate(pFile->h, nByte);
2877728831
if( rc ){
28778
- pFile->lastErrno = errno;
28832
+ storeLastErrno(pFile, errno);
2877928833
return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
2878028834
}else{
2878128835
#ifdef SQLITE_DEBUG
2878228836
/* If we are doing a normal write to a database file (as opposed to
2878328837
** doing a hot-journal rollback or a write to some file other than a
@@ -28813,11 +28867,11 @@
2881328867
struct stat buf;
2881428868
assert( id );
2881528869
rc = osFstat(((unixFile*)id)->h, &buf);
2881628870
SimulateIOError( rc=1 );
2881728871
if( rc!=0 ){
28818
- ((unixFile*)id)->lastErrno = errno;
28872
+ storeLastErrno((unixFile*)id, errno);
2881928873
return SQLITE_IOERR_FSTAT;
2882028874
}
2882128875
*pSize = buf.st_size;
2882228876
2882328877
/* When opening a zero-size database, the findInodeInfo() procedure
@@ -28849,11 +28903,13 @@
2884928903
static int fcntlSizeHint(unixFile *pFile, i64 nByte){
2885028904
if( pFile->szChunk>0 ){
2885128905
i64 nSize; /* Required file size */
2885228906
struct stat buf; /* Used to hold return values of fstat() */
2885328907
28854
- if( osFstat(pFile->h, &buf) ) return SQLITE_IOERR_FSTAT;
28908
+ if( osFstat(pFile->h, &buf) ){
28909
+ return SQLITE_IOERR_FSTAT;
28910
+ }
2885528911
2885628912
nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
2885728913
if( nSize>(i64)buf.st_size ){
2885828914
2885928915
#if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
@@ -28896,11 +28952,11 @@
2889628952
#if SQLITE_MAX_MMAP_SIZE>0
2889728953
if( pFile->mmapSizeMax>0 && nByte>pFile->mmapSize ){
2889828954
int rc;
2889928955
if( pFile->szChunk<=0 ){
2890028956
if( robust_ftruncate(pFile->h, nByte) ){
28901
- pFile->lastErrno = errno;
28957
+ storeLastErrno(pFile, errno);
2890228958
return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
2890328959
}
2890428960
}
2890528961
2890628962
rc = unixMapfile(pFile, nByte);
@@ -28938,11 +28994,11 @@
2893828994
switch( op ){
2893928995
case SQLITE_FCNTL_LOCKSTATE: {
2894028996
*(int*)pArg = pFile->eFileLock;
2894128997
return SQLITE_OK;
2894228998
}
28943
- case SQLITE_LAST_ERRNO: {
28999
+ case SQLITE_FCNTL_LAST_ERRNO: {
2894429000
*(int*)pArg = pFile->lastErrno;
2894529001
return SQLITE_OK;
2894629002
}
2894729003
case SQLITE_FCNTL_CHUNK_SIZE: {
2894829004
pFile->szChunk = *(int *)pArg;
@@ -29007,12 +29063,12 @@
2900729063
((unixFile*)id)->dbUpdate = 0;
2900829064
return SQLITE_OK;
2900929065
}
2901029066
#endif
2901129067
#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
29012
- case SQLITE_SET_LOCKPROXYFILE:
29013
- case SQLITE_GET_LOCKPROXYFILE: {
29068
+ case SQLITE_FCNTL_SET_LOCKPROXYFILE:
29069
+ case SQLITE_FCNTL_GET_LOCKPROXYFILE: {
2901429070
return proxyFileControl(id,op,pArg);
2901529071
}
2901629072
#endif /* SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) */
2901729073
}
2901829074
return SQLITE_NOTFOUND;
@@ -29413,10 +29469,13 @@
2941329469
unixEnterMutex();
2941429470
pInode = pDbFd->pInode;
2941529471
pShmNode = pInode->pShmNode;
2941629472
if( pShmNode==0 ){
2941729473
struct stat sStat; /* fstat() info for database file */
29474
+#ifndef SQLITE_SHM_DIRECTORY
29475
+ const char *zBasePath = pDbFd->zPath;
29476
+#endif
2941829477
2941929478
/* Call fstat() to figure out the permissions on the database file. If
2942029479
** a new *-shm file is created, an attempt will be made to create it
2942129480
** with the same permissions.
2942229481
*/
@@ -29426,11 +29485,11 @@
2942629485
}
2942729486
2942829487
#ifdef SQLITE_SHM_DIRECTORY
2942929488
nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 31;
2943029489
#else
29431
- nShmFilename = 6 + (int)strlen(pDbFd->zPath);
29490
+ nShmFilename = 6 + (int)strlen(zBasePath);
2943229491
#endif
2943329492
pShmNode = sqlite3_malloc( sizeof(*pShmNode) + nShmFilename );
2943429493
if( pShmNode==0 ){
2943529494
rc = SQLITE_NOMEM;
2943629495
goto shm_open_err;
@@ -29440,11 +29499,11 @@
2944029499
#ifdef SQLITE_SHM_DIRECTORY
2944129500
sqlite3_snprintf(nShmFilename, zShmFilename,
2944229501
SQLITE_SHM_DIRECTORY "/sqlite-shm-%x-%x",
2944329502
(u32)sStat.st_ino, (u32)sStat.st_dev);
2944429503
#else
29445
- sqlite3_snprintf(nShmFilename, zShmFilename, "%s-shm", pDbFd->zPath);
29504
+ sqlite3_snprintf(nShmFilename, zShmFilename, "%s-shm", zBasePath);
2944629505
sqlite3FileSuffix3(pDbFd->zPath, zShmFilename);
2944729506
#endif
2944829507
pShmNode->h = -1;
2944929508
pDbFd->pInode->pShmNode = pShmNode;
2945029509
pShmNode->pInode = pDbFd->pInode;
@@ -29833,11 +29892,13 @@
2983329892
** shared-memory file, too */
2983429893
unixEnterMutex();
2983529894
assert( pShmNode->nRef>0 );
2983629895
pShmNode->nRef--;
2983729896
if( pShmNode->nRef==0 ){
29838
- if( deleteFlag && pShmNode->h>=0 ) osUnlink(pShmNode->zFilename);
29897
+ if( deleteFlag && pShmNode->h>=0 ){
29898
+ osUnlink(pShmNode->zFilename);
29899
+ }
2983929900
unixShmPurge(pDbFd);
2984029901
}
2984129902
unixLeaveMutex();
2984229903
2984329904
return SQLITE_OK;
@@ -30110,11 +30171,11 @@
3011030171
** methods CLOSE, LOCK, UNLOCK, CKRESLOCK.
3011130172
**
3011230173
** * An I/O method finder function called FINDER that returns a pointer
3011330174
** to the METHOD object in the previous bullet.
3011430175
*/
30115
-#define IOMETHODS(FINDER, METHOD, VERSION, CLOSE, LOCK, UNLOCK, CKLOCK, SHMMAP) \
30176
+#define IOMETHODS(FINDER,METHOD,VERSION,CLOSE,LOCK,UNLOCK,CKLOCK,SHMMAP) \
3011630177
static const sqlite3_io_methods METHOD = { \
3011730178
VERSION, /* iVersion */ \
3011830179
CLOSE, /* xClose */ \
3011930180
unixRead, /* xRead */ \
3012030181
unixWrite, /* xWrite */ \
@@ -30538,11 +30599,11 @@
3053830599
}
3053930600
unixLeaveMutex();
3054030601
}
3054130602
#endif
3054230603
30543
- pNew->lastErrno = 0;
30604
+ storeLastErrno(pNew, 0);
3054430605
#if OS_VXWORKS
3054530606
if( rc!=SQLITE_OK ){
3054630607
if( h>=0 ) robust_close(pNew, h, __LINE__);
3054730608
h = -1;
3054830609
osUnlink(zFilename);
@@ -30986,17 +31047,20 @@
3098631047
noLock = eType!=SQLITE_OPEN_MAIN_DB;
3098731048
3098831049
3098931050
#if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE
3099031051
if( fstatfs(fd, &fsInfo) == -1 ){
30991
- ((unixFile*)pFile)->lastErrno = errno;
31052
+ storeLastErrno(p, errno);
3099231053
robust_close(p, fd, __LINE__);
3099331054
return SQLITE_IOERR_ACCESS;
3099431055
}
3099531056
if (0 == strncmp("msdos", fsInfo.f_fstypename, 5)) {
3099631057
((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS;
3099731058
}
31059
+ if (0 == strncmp("exfat", fsInfo.f_fstypename, 5)) {
31060
+ ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS;
31061
+ }
3099831062
#endif
3099931063
3100031064
/* Set up appropriate ctrlFlags */
3100131065
if( isDelete ) ctrlFlags |= UNIXFILE_DELETE;
3100231066
if( isReadonly ) ctrlFlags |= UNIXFILE_RDONLY;
@@ -31015,23 +31079,10 @@
3101531079
/* SQLITE_FORCE_PROXY_LOCKING==1 means force always use proxy, 0 means
3101631080
** never use proxy, NULL means use proxy for non-local files only. */
3101731081
if( envforce!=NULL ){
3101831082
useProxy = atoi(envforce)>0;
3101931083
}else{
31020
- if( statfs(zPath, &fsInfo) == -1 ){
31021
- /* In theory, the close(fd) call is sub-optimal. If the file opened
31022
- ** with fd is a database file, and there are other connections open
31023
- ** on that file that are currently holding advisory locks on it,
31024
- ** then the call to close() will cancel those locks. In practice,
31025
- ** we're assuming that statfs() doesn't fail very often. At least
31026
- ** not while other file descriptors opened by the same process on
31027
- ** the same file are working. */
31028
- p->lastErrno = errno;
31029
- robust_close(p, fd, __LINE__);
31030
- rc = SQLITE_IOERR_ACCESS;
31031
- goto open_finished;
31032
- }
3103331084
useProxy = !(fsInfo.f_flags&MNT_LOCAL);
3103431085
}
3103531086
if( useProxy ){
3103631087
rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
3103731088
if( rc==SQLITE_OK ){
@@ -31453,13 +31504,14 @@
3145331504
** Using proxy locks
3145431505
** -----------------
3145531506
**
3145631507
** C APIs
3145731508
**
31458
-** sqlite3_file_control(db, dbname, SQLITE_SET_LOCKPROXYFILE,
31509
+** sqlite3_file_control(db, dbname, SQLITE_FCNTL_SET_LOCKPROXYFILE,
3145931510
** <proxy_path> | ":auto:");
31460
-** sqlite3_file_control(db, dbname, SQLITE_GET_LOCKPROXYFILE, &<proxy_path>);
31511
+** sqlite3_file_control(db, dbname, SQLITE_FCNTL_GET_LOCKPROXYFILE,
31512
+** &<proxy_path>);
3146131513
**
3146231514
**
3146331515
** SQL pragmas
3146431516
**
3146531517
** PRAGMA [database.]lock_proxy_file=<proxy_path> | :auto:
@@ -31548,11 +31600,11 @@
3154831600
**
3154931601
** As mentioned above, when compiled with SQLITE_PREFER_PROXY_LOCKING,
3155031602
** setting the environment variable SQLITE_FORCE_PROXY_LOCKING to 1 will
3155131603
** force proxy locking to be used for every database file opened, and 0
3155231604
** will force automatic proxy locking to be disabled for all database
31553
-** files (explicitly calling the SQLITE_SET_LOCKPROXYFILE pragma or
31605
+** files (explicitly calling the SQLITE_FCNTL_SET_LOCKPROXYFILE pragma or
3155431606
** sqlite_file_control API is not affected by SQLITE_FORCE_PROXY_LOCKING).
3155531607
*/
3155631608
3155731609
/*
3155831610
** Proxy locking is only available on MacOSX
@@ -31569,10 +31621,11 @@
3156931621
char *conchFilePath; /* Name of the conch file */
3157031622
unixFile *lockProxy; /* Open proxy lock file */
3157131623
char *lockProxyPath; /* Name of the proxy lock file */
3157231624
char *dbPath; /* Name of the open file */
3157331625
int conchHeld; /* 1 if the conch is held, -1 if lockless */
31626
+ int nFails; /* Number of conch taking failures */
3157431627
void *oldLockingContext; /* Original lockingcontext to restore on close */
3157531628
sqlite3_io_methods const *pOldMethod; /* Original I/O methods for close */
3157631629
};
3157731630
3157831631
/*
@@ -31757,14 +31810,14 @@
3175731810
** bytes of writable memory.
3175831811
*/
3175931812
static int proxyGetHostID(unsigned char *pHostID, int *pError){
3176031813
assert(PROXY_HOSTIDLEN == sizeof(uuid_t));
3176131814
memset(pHostID, 0, PROXY_HOSTIDLEN);
31762
-#if defined(__MAX_OS_X_VERSION_MIN_REQUIRED)\
31763
- && __MAC_OS_X_VERSION_MIN_REQUIRED<1050
31815
+# if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \
31816
+ (__IPHONE_OS_VERSION_MIN_REQUIRED > 2000))
3176431817
{
31765
- static const struct timespec timeout = {1, 0}; /* 1 sec timeout */
31818
+ struct timespec timeout = {1, 0}; /* 1 sec timeout */
3176631819
if( gethostuuid(pHostID, &timeout) ){
3176731820
int err = errno;
3176831821
if( pError ){
3176931822
*pError = err;
3177031823
}
@@ -31875,11 +31928,11 @@
3187531928
* 10 sec and try again
3187631929
* 3rd try: break the lock unless the mod time has changed.
3187731930
*/
3187831931
struct stat buf;
3187931932
if( osFstat(conchFile->h, &buf) ){
31880
- pFile->lastErrno = errno;
31933
+ storeLastErrno(pFile, errno);
3188131934
return SQLITE_IOERR_LOCK;
3188231935
}
3188331936
3188431937
if( nTries==1 ){
3188531938
conchModTime = buf.st_mtimespec;
@@ -31895,11 +31948,11 @@
3189531948
3189631949
if( nTries==2 ){
3189731950
char tBuf[PROXY_MAXCONCHLEN];
3189831951
int len = osPread(conchFile->h, tBuf, PROXY_MAXCONCHLEN, 0);
3189931952
if( len<0 ){
31900
- pFile->lastErrno = errno;
31953
+ storeLastErrno(pFile, errno);
3190131954
return SQLITE_IOERR_LOCK;
3190231955
}
3190331956
if( len>PROXY_PATHINDEX && tBuf[0]==(char)PROXY_CONCHVERSION){
3190431957
/* don't break the lock if the host id doesn't match */
3190531958
if( 0!=memcmp(&tBuf[PROXY_HEADERLEN], myHostID, PROXY_HOSTIDLEN) ){
@@ -31915,11 +31968,11 @@
3191531968
3191631969
assert( nTries==3 );
3191731970
if( 0==proxyBreakConchLock(pFile, myHostID) ){
3191831971
rc = SQLITE_OK;
3191931972
if( lockType==EXCLUSIVE_LOCK ){
31920
- rc = conchFile->pMethod->xLock((sqlite3_file*)conchFile, SHARED_LOCK);
31973
+ rc = conchFile->pMethod->xLock((sqlite3_file*)conchFile, SHARED_LOCK);
3192131974
}
3192231975
if( !rc ){
3192331976
rc = conchFile->pMethod->xLock((sqlite3_file*)conchFile, lockType);
3192431977
}
3192531978
}
@@ -31957,11 +32010,11 @@
3195732010
OSTRACE(("TAKECONCH %d for %s pid=%d\n", conchFile->h,
3195832011
(pCtx->lockProxyPath ? pCtx->lockProxyPath : ":auto:"), getpid()));
3195932012
3196032013
rc = proxyGetHostID(myHostID, &pError);
3196132014
if( (rc&0xff)==SQLITE_IOERR ){
31962
- pFile->lastErrno = pError;
32015
+ storeLastErrno(pFile, pError);
3196332016
goto end_takeconch;
3196432017
}
3196532018
rc = proxyConchLock(pFile, myHostID, SHARED_LOCK);
3196632019
if( rc!=SQLITE_OK ){
3196732020
goto end_takeconch;
@@ -31968,11 +32021,11 @@
3196832021
}
3196932022
/* read the existing conch file */
3197032023
readLen = seekAndRead((unixFile*)conchFile, 0, readBuf, PROXY_MAXCONCHLEN);
3197132024
if( readLen<0 ){
3197232025
/* I/O error: lastErrno set by seekAndRead */
31973
- pFile->lastErrno = conchFile->lastErrno;
32026
+ storeLastErrno(pFile, conchFile->lastErrno);
3197432027
rc = SQLITE_IOERR_READ;
3197532028
goto end_takeconch;
3197632029
}else if( readLen<=(PROXY_HEADERLEN+PROXY_HOSTIDLEN) ||
3197732030
readBuf[0]!=(char)PROXY_CONCHVERSION ){
3197832031
/* a short read or version format mismatch means we need to create a new
@@ -32041,20 +32094,21 @@
3204132094
rc = SQLITE_BUSY;
3204232095
} else {
3204332096
rc = proxyConchLock(pFile, myHostID, EXCLUSIVE_LOCK);
3204432097
}
3204532098
}else{
32046
- rc = conchFile->pMethod->xLock((sqlite3_file*)conchFile, EXCLUSIVE_LOCK);
32099
+ rc = proxyConchLock(pFile, myHostID, EXCLUSIVE_LOCK);
3204732100
}
3204832101
if( rc==SQLITE_OK ){
3204932102
char writeBuffer[PROXY_MAXCONCHLEN];
3205032103
int writeSize = 0;
3205132104
3205232105
writeBuffer[0] = (char)PROXY_CONCHVERSION;
3205332106
memcpy(&writeBuffer[PROXY_HEADERLEN], myHostID, PROXY_HOSTIDLEN);
3205432107
if( pCtx->lockProxyPath!=NULL ){
32055
- strlcpy(&writeBuffer[PROXY_PATHINDEX], pCtx->lockProxyPath, MAXPATHLEN);
32108
+ strlcpy(&writeBuffer[PROXY_PATHINDEX], pCtx->lockProxyPath,
32109
+ MAXPATHLEN);
3205632110
}else{
3205732111
strlcpy(&writeBuffer[PROXY_PATHINDEX], tempLockPath, MAXPATHLEN);
3205832112
}
3205932113
writeSize = PROXY_PATHINDEX + strlen(&writeBuffer[PROXY_PATHINDEX]);
3206032114
robust_ftruncate(conchFile->h, writeSize);
@@ -32262,11 +32316,12 @@
3226232316
#if defined(__APPLE__)
3226332317
if( pFile->pMethod == &afpIoMethods ){
3226432318
/* afp style keeps a reference to the db path in the filePath field
3226532319
** of the struct */
3226632320
assert( (int)strlen((char*)pFile->lockingContext)<=MAXPATHLEN );
32267
- strlcpy(dbPath, ((afpLockingContext *)pFile->lockingContext)->dbPath, MAXPATHLEN);
32321
+ strlcpy(dbPath, ((afpLockingContext *)pFile->lockingContext)->dbPath,
32322
+ MAXPATHLEN);
3226832323
} else
3226932324
#endif
3227032325
if( pFile->pMethod == &dotlockIoMethods ){
3227132326
/* dot lock style uses the locking context to store the dot lock
3227232327
** file path */
@@ -32375,11 +32430,11 @@
3237532430
** This routine handles sqlite3_file_control() calls that are specific
3237632431
** to proxy locking.
3237732432
*/
3237832433
static int proxyFileControl(sqlite3_file *id, int op, void *pArg){
3237932434
switch( op ){
32380
- case SQLITE_GET_LOCKPROXYFILE: {
32435
+ case SQLITE_FCNTL_GET_LOCKPROXYFILE: {
3238132436
unixFile *pFile = (unixFile*)id;
3238232437
if( pFile->pMethod == &proxyIoMethods ){
3238332438
proxyLockingContext *pCtx = (proxyLockingContext*)pFile->lockingContext;
3238432439
proxyTakeConch(pFile);
3238532440
if( pCtx->lockProxyPath ){
@@ -32390,17 +32445,20 @@
3239032445
} else {
3239132446
*(const char **)pArg = NULL;
3239232447
}
3239332448
return SQLITE_OK;
3239432449
}
32395
- case SQLITE_SET_LOCKPROXYFILE: {
32450
+ case SQLITE_FCNTL_SET_LOCKPROXYFILE: {
3239632451
unixFile *pFile = (unixFile*)id;
3239732452
int rc = SQLITE_OK;
3239832453
int isProxyStyle = (pFile->pMethod == &proxyIoMethods);
3239932454
if( pArg==NULL || (const char *)pArg==0 ){
3240032455
if( isProxyStyle ){
32401
- /* turn off proxy locking - not supported */
32456
+ /* turn off proxy locking - not supported. If support is added for
32457
+ ** switching proxy locking mode off then it will need to fail if
32458
+ ** the journal mode is WAL mode.
32459
+ */
3240232460
rc = SQLITE_ERROR /*SQLITE_PROTOCOL? SQLITE_MISUSE?*/;
3240332461
}else{
3240432462
/* turn off proxy locking - already off - NOOP */
3240532463
rc = SQLITE_OK;
3240632464
}
@@ -33965,10 +34023,27 @@
3396534023
{ "InterlockedCompareExchange", (SYSCALL)InterlockedCompareExchange, 0 },
3396634024
3396734025
#define osInterlockedCompareExchange ((LONG(WINAPI*)(LONG \
3396834026
SQLITE_WIN32_VOLATILE*, LONG,LONG))aSyscall[76].pCurrent)
3396934027
#endif /* defined(InterlockedCompareExchange) */
34028
+
34029
+#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID
34030
+ { "UuidCreate", (SYSCALL)UuidCreate, 0 },
34031
+#else
34032
+ { "UuidCreate", (SYSCALL)0, 0 },
34033
+#endif
34034
+
34035
+#define osUuidCreate ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[77].pCurrent)
34036
+
34037
+#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID
34038
+ { "UuidCreateSequential", (SYSCALL)UuidCreateSequential, 0 },
34039
+#else
34040
+ { "UuidCreateSequential", (SYSCALL)0, 0 },
34041
+#endif
34042
+
34043
+#define osUuidCreateSequential \
34044
+ ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[78].pCurrent)
3397034045
3397134046
}; /* End of the overrideable system calls */
3397234047
3397334048
/*
3397434049
** This is the xSetSystemCall() method of sqlite3_vfs for all of the
@@ -36714,20 +36789,20 @@
3671436789
int szRegion, /* Size of regions */
3671536790
int isWrite, /* True to extend file if necessary */
3671636791
void volatile **pp /* OUT: Mapped memory */
3671736792
){
3671836793
winFile *pDbFd = (winFile*)fd;
36719
- winShm *p = pDbFd->pShm;
36794
+ winShm *pShm = pDbFd->pShm;
3672036795
winShmNode *pShmNode;
3672136796
int rc = SQLITE_OK;
3672236797
36723
- if( !p ){
36798
+ if( !pShm ){
3672436799
rc = winOpenSharedMemory(pDbFd);
3672536800
if( rc!=SQLITE_OK ) return rc;
36726
- p = pDbFd->pShm;
36801
+ pShm = pDbFd->pShm;
3672736802
}
36728
- pShmNode = p->pShmNode;
36803
+ pShmNode = pShm->pShmNode;
3672936804
3673036805
sqlite3_mutex_enter(pShmNode->mutex);
3673136806
assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 );
3673236807
3673336808
if( pShmNode->nRegion<=iRegion ){
@@ -38244,10 +38319,26 @@
3824438319
LARGE_INTEGER i;
3824538320
osQueryPerformanceCounter(&i);
3824638321
memcpy(&zBuf[n], &i, sizeof(i));
3824738322
n += sizeof(i);
3824838323
}
38324
+#endif
38325
+#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID
38326
+ if( sizeof(UUID)<=nBuf-n ){
38327
+ UUID id;
38328
+ memset(&id, 0, sizeof(UUID));
38329
+ osUuidCreate(&id);
38330
+ memcpy(zBuf, &id, sizeof(UUID));
38331
+ n += sizeof(UUID);
38332
+ }
38333
+ if( sizeof(UUID)<=nBuf-n ){
38334
+ UUID id;
38335
+ memset(&id, 0, sizeof(UUID));
38336
+ osUuidCreateSequential(&id);
38337
+ memcpy(zBuf, &id, sizeof(UUID));
38338
+ n += sizeof(UUID);
38339
+ }
3824938340
#endif
3825038341
return n;
3825138342
}
3825238343
3825338344
@@ -38422,11 +38513,11 @@
3842238513
};
3842338514
#endif
3842438515
3842538516
/* Double-check that the aSyscall[] array has been constructed
3842638517
** correctly. See ticket [bb3a86e890c8e96ab] */
38427
- assert( ArraySize(aSyscall)==77 );
38518
+ assert( ArraySize(aSyscall)==79 );
3842838519
3842938520
/* get memory map allocation granularity */
3843038521
memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
3843138522
#if SQLITE_OS_WINRT
3843238523
osGetNativeSystemInfo(&winSysInfo);
@@ -52089,10 +52180,13 @@
5208952180
u8 incrVacuum; /* True if incr-vacuum is enabled */
5209052181
u8 bDoTruncate; /* True to truncate db on commit */
5209152182
#endif
5209252183
u8 inTransaction; /* Transaction state */
5209352184
u8 max1bytePayload; /* Maximum first byte of cell for a 1-byte payload */
52185
+#ifdef SQLITE_HAS_CODEC
52186
+ u8 optimalReserve; /* Desired amount of reserved space per page */
52187
+#endif
5209452188
u16 btsFlags; /* Boolean parameters. See BTS_* macros below */
5209552189
u16 maxLocal; /* Maximum local payload in non-LEAFDATA tables */
5209652190
u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */
5209752191
u16 maxLeaf; /* Maximum local payload in a LEAFDATA table */
5209852192
u16 minLeaf; /* Minimum local payload in a LEAFDATA table */
@@ -52811,10 +52905,16 @@
5281152905
if( isIndex ){
5281252906
HashElem *p;
5281352907
for(p=sqliteHashFirst(&pSchema->idxHash); p; p=sqliteHashNext(p)){
5281452908
Index *pIdx = (Index *)sqliteHashData(p);
5281552909
if( pIdx->tnum==(int)iRoot ){
52910
+ if( iTab ){
52911
+ /* Two or more indexes share the same root page. There must
52912
+ ** be imposter tables. So just return true. The assert is not
52913
+ ** useful in that case. */
52914
+ return 1;
52915
+ }
5281652916
iTab = pIdx->pTable->tnum;
5281752917
}
5281852918
}
5281952919
}else{
5282052920
iTab = iRoot;
@@ -55035,10 +55135,13 @@
5503555135
SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve, int iFix){
5503655136
int rc = SQLITE_OK;
5503755137
BtShared *pBt = p->pBt;
5503855138
assert( nReserve>=-1 && nReserve<=255 );
5503955139
sqlite3BtreeEnter(p);
55140
+#if SQLITE_HAS_CODEC
55141
+ if( nReserve>pBt->optimalReserve ) pBt->optimalReserve = (u8)nReserve;
55142
+#endif
5504055143
if( pBt->btsFlags & BTS_PAGESIZE_FIXED ){
5504155144
sqlite3BtreeLeave(p);
5504255145
return SQLITE_READONLY;
5504355146
}
5504455147
if( nReserve<0 ){
@@ -55064,11 +55167,10 @@
5506455167
*/
5506555168
SQLITE_PRIVATE int sqlite3BtreeGetPageSize(Btree *p){
5506655169
return p->pBt->pageSize;
5506755170
}
5506855171
55069
-#if defined(SQLITE_HAS_CODEC) || defined(SQLITE_DEBUG)
5507055172
/*
5507155173
** This function is similar to sqlite3BtreeGetReserve(), except that it
5507255174
** may only be called if it is guaranteed that the b-tree mutex is already
5507355175
** held.
5507455176
**
@@ -55077,28 +55179,36 @@
5507755179
** database handle that owns *p is not. In this case if sqlite3BtreeEnter()
5507855180
** were to be called, it might collide with some other operation on the
5507955181
** database handle that owns *p, causing undefined behavior.
5508055182
*/
5508155183
SQLITE_PRIVATE int sqlite3BtreeGetReserveNoMutex(Btree *p){
55184
+ int n;
5508255185
assert( sqlite3_mutex_held(p->pBt->mutex) );
55083
- return p->pBt->pageSize - p->pBt->usableSize;
55186
+ n = p->pBt->pageSize - p->pBt->usableSize;
55187
+ return n;
5508455188
}
55085
-#endif /* SQLITE_HAS_CODEC || SQLITE_DEBUG */
5508655189
55087
-#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) || !defined(SQLITE_OMIT_VACUUM)
5508855190
/*
5508955191
** Return the number of bytes of space at the end of every page that
5509055192
** are intentually left unused. This is the "reserved" space that is
5509155193
** sometimes used by extensions.
55194
+**
55195
+** If SQLITE_HAS_MUTEX is defined then the number returned is the
55196
+** greater of the current reserved space and the maximum requested
55197
+** reserve space.
5509255198
*/
55093
-SQLITE_PRIVATE int sqlite3BtreeGetReserve(Btree *p){
55199
+SQLITE_PRIVATE int sqlite3BtreeGetOptimalReserve(Btree *p){
5509455200
int n;
5509555201
sqlite3BtreeEnter(p);
55096
- n = p->pBt->pageSize - p->pBt->usableSize;
55202
+ n = sqlite3BtreeGetReserveNoMutex(p);
55203
+#ifdef SQLITE_HAS_CODEC
55204
+ if( n<p->pBt->optimalReserve ) n = p->pBt->optimalReserve;
55205
+#endif
5509755206
sqlite3BtreeLeave(p);
5509855207
return n;
5509955208
}
55209
+
5510055210
5510155211
/*
5510255212
** Set the maximum page count for a database if mxPage is positive.
5510355213
** No changes are made if mxPage is 0 or negative.
5510455214
** Regardless of the value of mxPage, return the maximum page count.
@@ -55126,11 +55236,10 @@
5512655236
}
5512755237
b = (p->pBt->btsFlags & BTS_SECURE_DELETE)!=0;
5512855238
sqlite3BtreeLeave(p);
5512955239
return b;
5513055240
}
55131
-#endif /* !defined(SQLITE_OMIT_PAGER_PRAGMAS) || !defined(SQLITE_OMIT_VACUUM) */
5513255241
5513355242
/*
5513455243
** Change the 'auto-vacuum' property of the database. If the 'autoVacuum'
5513555244
** parameter is non-zero, then auto-vacuum mode is enabled. If zero, it
5513655245
** is disabled. The default value for the auto-vacuum property is
@@ -62033,11 +62142,11 @@
6203362142
#ifdef SQLITE_HAS_CODEC
6203462143
/* Use BtreeGetReserveNoMutex() for the source b-tree, as although it is
6203562144
** guaranteed that the shared-mutex is held by this thread, handle
6203662145
** p->pSrc may not actually be the owner. */
6203762146
int nSrcReserve = sqlite3BtreeGetReserveNoMutex(p->pSrc);
62038
- int nDestReserve = sqlite3BtreeGetReserve(p->pDest);
62147
+ int nDestReserve = sqlite3BtreeGetOptimalReserve(p->pDest);
6203962148
#endif
6204062149
int rc = SQLITE_OK;
6204162150
i64 iOff;
6204262151
6204362152
assert( sqlite3BtreeGetReserveNoMutex(p->pSrc)>=0 );
@@ -67523,11 +67632,12 @@
6752367632
u32 notUsed;
6752467633
const unsigned char *aKey = (const unsigned char*)pKey;
6752567634
6752667635
if( CORRUPT_DB ) return;
6752767636
idx = getVarint32(aKey, szHdr);
67528
- assert( szHdr<=nKey );
67637
+ assert( nKey>=0 );
67638
+ assert( szHdr<=(u32)nKey );
6752967639
while( idx<szHdr ){
6753067640
idx += getVarint32(aKey+idx, notUsed);
6753167641
nField++;
6753267642
}
6753367643
assert( nField <= pKeyInfo->nField+pKeyInfo->nXField );
@@ -68700,10 +68810,13 @@
6870068810
sqlite3VdbeMemSetZeroBlob(pCtx->pOut, n);
6870168811
}
6870268812
SQLITE_API void sqlite3_result_error_code(sqlite3_context *pCtx, int errCode){
6870368813
pCtx->isError = errCode;
6870468814
pCtx->fErrorOrAux = 1;
68815
+#ifdef SQLITE_DEBUG
68816
+ pCtx->pVdbe->rcApp = errCode;
68817
+#endif
6870568818
if( pCtx->pOut->flags & MEM_Null ){
6870668819
sqlite3VdbeMemSetStr(pCtx->pOut, sqlite3ErrStr(errCode), -1,
6870768820
SQLITE_UTF8, SQLITE_STATIC);
6870868821
}
6870968822
}
@@ -68780,11 +68893,11 @@
6878068893
** legacy behavior of returning SQLITE_MISUSE for cases where the
6878168894
** previous sqlite3_step() returned something other than a SQLITE_LOCKED
6878268895
** or SQLITE_BUSY error.
6878368896
*/
6878468897
#ifdef SQLITE_OMIT_AUTORESET
68785
- if( p->rc==SQLITE_BUSY || p->rc==SQLITE_LOCKED ){
68898
+ if( (rc = p->rc&0xff)==SQLITE_BUSY || rc==SQLITE_LOCKED ){
6878668899
sqlite3_reset((sqlite3_stmt*)p);
6878768900
}else{
6878868901
return SQLITE_MISUSE_BKPT;
6878968902
}
6879068903
#else
@@ -68826,10 +68939,13 @@
6882668939
db->nVdbeActive++;
6882768940
if( p->readOnly==0 ) db->nVdbeWrite++;
6882868941
if( p->bIsReader ) db->nVdbeRead++;
6882968942
p->pc = 0;
6883068943
}
68944
+#ifdef SQLITE_DEBUG
68945
+ p->rcApp = SQLITE_OK;
68946
+#endif
6883168947
#ifndef SQLITE_OMIT_EXPLAIN
6883268948
if( p->explain ){
6883368949
rc = sqlite3VdbeList(p);
6883468950
}else
6883568951
#endif /* SQLITE_OMIT_EXPLAIN */
@@ -68870,11 +68986,11 @@
6887068986
** were called on statement p.
6887168987
*/
6887268988
assert( rc==SQLITE_ROW || rc==SQLITE_DONE || rc==SQLITE_ERROR
6887368989
|| rc==SQLITE_BUSY || rc==SQLITE_MISUSE
6887468990
);
68875
- assert( p->rc!=SQLITE_ROW && p->rc!=SQLITE_DONE );
68991
+ assert( (p->rc!=SQLITE_ROW && p->rc!=SQLITE_DONE) || p->rc==p->rcApp );
6887668992
if( p->isPrepareV2 && rc!=SQLITE_ROW && rc!=SQLITE_DONE ){
6887768993
/* If this statement was prepared using sqlite3_prepare_v2(), and an
6887868994
** error has occurred, then return the error code in p->rc to the
6887968995
** caller. Set the error code in the database handle to the same value.
6888068996
*/
@@ -76810,16 +76926,21 @@
7681076926
Table *pTab;
7681176927
Parse *pParse = 0;
7681276928
Incrblob *pBlob = 0;
7681376929
7681476930
#ifdef SQLITE_ENABLE_API_ARMOR
76815
- if( !sqlite3SafetyCheckOk(db) || ppBlob==0 || zTable==0 ){
76931
+ if( ppBlob==0 ){
7681676932
return SQLITE_MISUSE_BKPT;
7681776933
}
7681876934
#endif
76819
- flags = !!flags; /* flags = (flags ? 1 : 0); */
7682076935
*ppBlob = 0;
76936
+#ifdef SQLITE_ENABLE_API_ARMOR
76937
+ if( !sqlite3SafetyCheckOk(db) || zTable==0 ){
76938
+ return SQLITE_MISUSE_BKPT;
76939
+ }
76940
+#endif
76941
+ flags = !!flags; /* flags = (flags ? 1 : 0); */
7682176942
7682276943
sqlite3_mutex_enter(db->mutex);
7682376944
7682476945
pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob));
7682576946
if( !pBlob ) goto blob_open_out;
@@ -77029,11 +77150,11 @@
7702977150
if( p==0 ) return SQLITE_MISUSE_BKPT;
7703077151
db = p->db;
7703177152
sqlite3_mutex_enter(db->mutex);
7703277153
v = (Vdbe*)p->pStmt;
7703377154
77034
- if( n<0 || iOffset<0 || (iOffset+n)>p->nByte ){
77155
+ if( n<0 || iOffset<0 || ((sqlite3_int64)iOffset+n)>p->nByte ){
7703577156
/* Request is out of range. Return a transient error. */
7703677157
rc = SQLITE_ERROR;
7703777158
}else if( v==0 ){
7703877159
/* If there is no statement handle, then the blob-handle has
7703977160
** already been invalidated. Return SQLITE_ABORT in this case.
@@ -80573,13 +80694,14 @@
8057380694
*/
8057480695
if( zDb ){
8057580696
testcase( pNC->ncFlags & NC_PartIdx );
8057680697
testcase( pNC->ncFlags & NC_IsCheck );
8057780698
if( (pNC->ncFlags & (NC_PartIdx|NC_IsCheck))!=0 ){
80578
- /* Silently ignore database qualifiers inside CHECK constraints and partial
80579
- ** indices. Do not raise errors because that might break legacy and
80580
- ** because it does not hurt anything to just ignore the database name. */
80699
+ /* Silently ignore database qualifiers inside CHECK constraints and
80700
+ ** partial indices. Do not raise errors because that might break
80701
+ ** legacy and because it does not hurt anything to just ignore the
80702
+ ** database name. */
8058180703
zDb = 0;
8058280704
}else{
8058380705
for(i=0; i<db->nDb; i++){
8058480706
assert( db->aDb[i].zName );
8058580707
if( sqlite3StrICmp(db->aDb[i].zName,zDb)==0 ){
@@ -80646,11 +80768,12 @@
8064680768
}
8064780769
}
8064880770
if( pMatch ){
8064980771
pExpr->iTable = pMatch->iCursor;
8065080772
pExpr->pTab = pMatch->pTab;
80651
- assert( (pMatch->jointype & JT_RIGHT)==0 ); /* RIGHT JOIN not (yet) supported */
80773
+ /* RIGHT JOIN not (yet) supported */
80774
+ assert( (pMatch->jointype & JT_RIGHT)==0 );
8065280775
if( (pMatch->jointype & JT_LEFT)!=0 ){
8065380776
ExprSetProperty(pExpr, EP_CanBeNull);
8065480777
}
8065580778
pSchema = pExpr->pTab->pSchema;
8065680779
}
@@ -80967,11 +81090,12 @@
8096781090
pExpr->iTable = pItem->iCursor;
8096881091
pExpr->iColumn = -1;
8096981092
pExpr->affinity = SQLITE_AFF_INTEGER;
8097081093
break;
8097181094
}
80972
-#endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY) */
81095
+#endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT)
81096
+ && !defined(SQLITE_OMIT_SUBQUERY) */
8097381097
8097481098
/* A lone identifier is the name of a column.
8097581099
*/
8097681100
case TK_ID: {
8097781101
return lookupName(pParse, 0, 0, pExpr->u.zToken, pNC, pExpr);
@@ -81032,23 +81156,24 @@
8103281156
if( pDef->funcFlags & SQLITE_FUNC_UNLIKELY ){
8103381157
ExprSetProperty(pExpr, EP_Unlikely|EP_Skip);
8103481158
if( n==2 ){
8103581159
pExpr->iTable = exprProbability(pList->a[1].pExpr);
8103681160
if( pExpr->iTable<0 ){
81037
- sqlite3ErrorMsg(pParse, "second argument to likelihood() must be a "
81038
- "constant between 0.0 and 1.0");
81161
+ sqlite3ErrorMsg(pParse,
81162
+ "second argument to likelihood() must be a "
81163
+ "constant between 0.0 and 1.0");
8103981164
pNC->nErr++;
8104081165
}
8104181166
}else{
81042
- /* EVIDENCE-OF: R-61304-29449 The unlikely(X) function is equivalent to
81043
- ** likelihood(X, 0.0625).
81044
- ** EVIDENCE-OF: R-01283-11636 The unlikely(X) function is short-hand for
81045
- ** likelihood(X,0.0625).
81046
- ** EVIDENCE-OF: R-36850-34127 The likely(X) function is short-hand for
81047
- ** likelihood(X,0.9375).
81048
- ** EVIDENCE-OF: R-53436-40973 The likely(X) function is equivalent to
81049
- ** likelihood(X,0.9375). */
81167
+ /* EVIDENCE-OF: R-61304-29449 The unlikely(X) function is
81168
+ ** equivalent to likelihood(X, 0.0625).
81169
+ ** EVIDENCE-OF: R-01283-11636 The unlikely(X) function is
81170
+ ** short-hand for likelihood(X,0.0625).
81171
+ ** EVIDENCE-OF: R-36850-34127 The likely(X) function is short-hand
81172
+ ** for likelihood(X,0.9375).
81173
+ ** EVIDENCE-OF: R-53436-40973 The likely(X) function is equivalent
81174
+ ** to likelihood(X,0.9375). */
8105081175
/* TUNING: unlikely() probability is 0.0625. likely() is 0.9375 */
8105181176
pExpr->iTable = pDef->zName[0]=='u' ? 8388608 : 125829120;
8105281177
}
8105381178
}
8105481179
#ifndef SQLITE_OMIT_AUTHORIZATION
@@ -81061,11 +81186,13 @@
8106181186
}
8106281187
pExpr->op = TK_NULL;
8106381188
return WRC_Prune;
8106481189
}
8106581190
#endif
81066
- if( pDef->funcFlags & SQLITE_FUNC_CONSTANT ) ExprSetProperty(pExpr,EP_Constant);
81191
+ if( pDef->funcFlags & SQLITE_FUNC_CONSTANT ){
81192
+ ExprSetProperty(pExpr,EP_ConstFunc);
81193
+ }
8106781194
}
8106881195
if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){
8106981196
sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId);
8107081197
pNC->nErr++;
8107181198
is_agg = 0;
@@ -81372,11 +81499,12 @@
8137281499
if( pItem->u.x.iOrderByCol ){
8137381500
if( pItem->u.x.iOrderByCol>pEList->nExpr ){
8137481501
resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr);
8137581502
return 1;
8137681503
}
81377
- resolveAlias(pParse, pEList, pItem->u.x.iOrderByCol-1, pItem->pExpr, zType,0);
81504
+ resolveAlias(pParse, pEList, pItem->u.x.iOrderByCol-1, pItem->pExpr,
81505
+ zType,0);
8137881506
}
8137981507
}
8138081508
return 0;
8138181509
}
8138281510
@@ -81925,13 +82053,13 @@
8192582053
}
8192682054
if( op==TK_COLLATE || (op==TK_REGISTER && p->op2==TK_COLLATE) ){
8192782055
pColl = sqlite3GetCollSeq(pParse, ENC(db), 0, p->u.zToken);
8192882056
break;
8192982057
}
81930
- if( p->pTab!=0
81931
- && (op==TK_AGG_COLUMN || op==TK_COLUMN
82058
+ if( (op==TK_AGG_COLUMN || op==TK_COLUMN
8193282059
|| op==TK_REGISTER || op==TK_TRIGGER)
82060
+ && p->pTab!=0
8193382061
){
8193482062
/* op==TK_REGISTER && p->pTab!=0 happens when pExpr was originally
8193582063
** a TK_COLUMN but was previously evaluated and cached in a register */
8193682064
int j = p->iColumn;
8193782065
if( j>=0 ){
@@ -81939,14 +82067,29 @@
8193982067
pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
8194082068
}
8194182069
break;
8194282070
}
8194382071
if( p->flags & EP_Collate ){
81944
- if( ALWAYS(p->pLeft) && (p->pLeft->flags & EP_Collate)!=0 ){
82072
+ if( p->pLeft && (p->pLeft->flags & EP_Collate)!=0 ){
8194582073
p = p->pLeft;
8194682074
}else{
81947
- p = p->pRight;
82075
+ Expr *pNext = p->pRight;
82076
+ /* The Expr.x union is never used at the same time as Expr.pRight */
82077
+ assert( p->x.pList==0 || p->pRight==0 );
82078
+ /* p->flags holds EP_Collate and p->pLeft->flags does not. And
82079
+ ** p->x.pSelect cannot. So if p->x.pLeft exists, it must hold at
82080
+ ** least one EP_Collate. Thus the following two ALWAYS. */
82081
+ if( p->x.pList!=0 && ALWAYS(!ExprHasProperty(p, EP_xIsSelect)) ){
82082
+ int i;
82083
+ for(i=0; ALWAYS(i<p->x.pList->nExpr); i++){
82084
+ if( ExprHasProperty(p->x.pList->a[i].pExpr, EP_Collate) ){
82085
+ pNext = p->x.pList->a[i].pExpr;
82086
+ break;
82087
+ }
82088
+ }
82089
+ }
82090
+ p = pNext;
8194882091
}
8194982092
}else{
8195082093
break;
8195182094
}
8195282095
}
@@ -82148,29 +82291,36 @@
8214882291
** Set the Expr.nHeight variable in the structure passed as an
8214982292
** argument. An expression with no children, Expr.pList or
8215082293
** Expr.pSelect member has a height of 1. Any other expression
8215182294
** has a height equal to the maximum height of any other
8215282295
** referenced Expr plus one.
82296
+**
82297
+** Also propagate EP_Propagate flags up from Expr.x.pList to Expr.flags,
82298
+** if appropriate.
8215382299
*/
8215482300
static void exprSetHeight(Expr *p){
8215582301
int nHeight = 0;
8215682302
heightOfExpr(p->pLeft, &nHeight);
8215782303
heightOfExpr(p->pRight, &nHeight);
8215882304
if( ExprHasProperty(p, EP_xIsSelect) ){
8215982305
heightOfSelect(p->x.pSelect, &nHeight);
82160
- }else{
82306
+ }else if( p->x.pList ){
8216182307
heightOfExprList(p->x.pList, &nHeight);
82308
+ p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList);
8216282309
}
8216382310
p->nHeight = nHeight + 1;
8216482311
}
8216582312
8216682313
/*
8216782314
** Set the Expr.nHeight variable using the exprSetHeight() function. If
8216882315
** the height is greater than the maximum allowed expression depth,
8216982316
** leave an error in pParse.
82317
+**
82318
+** Also propagate all EP_Propagate flags from the Expr.x.pList into
82319
+** Expr.flags.
8217082320
*/
82171
-SQLITE_PRIVATE void sqlite3ExprSetHeight(Parse *pParse, Expr *p){
82321
+SQLITE_PRIVATE void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p){
8217282322
exprSetHeight(p);
8217382323
sqlite3ExprCheckHeight(pParse, p->nHeight);
8217482324
}
8217582325
8217682326
/*
@@ -82180,12 +82330,21 @@
8218082330
SQLITE_PRIVATE int sqlite3SelectExprHeight(Select *p){
8218182331
int nHeight = 0;
8218282332
heightOfSelect(p, &nHeight);
8218382333
return nHeight;
8218482334
}
82185
-#else
82186
- #define exprSetHeight(y)
82335
+#else /* ABOVE: Height enforcement enabled. BELOW: Height enforcement off */
82336
+/*
82337
+** Propagate all EP_Propagate flags from the Expr.x.pList into
82338
+** Expr.flags.
82339
+*/
82340
+SQLITE_PRIVATE void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p){
82341
+ if( p && p->x.pList && !ExprHasProperty(p, EP_xIsSelect) ){
82342
+ p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList);
82343
+ }
82344
+}
82345
+#define exprSetHeight(y)
8218782346
#endif /* SQLITE_MAX_EXPR_DEPTH>0 */
8218882347
8218982348
/*
8219082349
** This routine is the core allocator for Expr nodes.
8219182350
**
@@ -82283,15 +82442,15 @@
8228382442
sqlite3ExprDelete(db, pLeft);
8228482443
sqlite3ExprDelete(db, pRight);
8228582444
}else{
8228682445
if( pRight ){
8228782446
pRoot->pRight = pRight;
82288
- pRoot->flags |= EP_Collate & pRight->flags;
82447
+ pRoot->flags |= EP_Propagate & pRight->flags;
8228982448
}
8229082449
if( pLeft ){
8229182450
pRoot->pLeft = pLeft;
82292
- pRoot->flags |= EP_Collate & pLeft->flags;
82451
+ pRoot->flags |= EP_Propagate & pLeft->flags;
8229382452
}
8229482453
exprSetHeight(pRoot);
8229582454
}
8229682455
}
8229782456
@@ -82387,11 +82546,11 @@
8238782546
sqlite3ExprListDelete(db, pList); /* Avoid memory leak when malloc fails */
8238882547
return 0;
8238982548
}
8239082549
pNew->x.pList = pList;
8239182550
assert( !ExprHasProperty(pNew, EP_xIsSelect) );
82392
- sqlite3ExprSetHeight(pParse, pNew);
82551
+ sqlite3ExprSetHeightAndFlags(pParse, pNew);
8239382552
return pNew;
8239482553
}
8239582554
8239682555
/*
8239782556
** Assign a variable number to an expression that encodes a wildcard
@@ -83001,10 +83160,25 @@
8300183160
sqlite3DbFree(db, pItem->zSpan);
8300283161
}
8300383162
sqlite3DbFree(db, pList->a);
8300483163
sqlite3DbFree(db, pList);
8300583164
}
83165
+
83166
+/*
83167
+** Return the bitwise-OR of all Expr.flags fields in the given
83168
+** ExprList.
83169
+*/
83170
+SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList *pList){
83171
+ int i;
83172
+ u32 m = 0;
83173
+ if( pList ){
83174
+ for(i=0; i<pList->nExpr; i++){
83175
+ m |= pList->a[i].pExpr->flags;
83176
+ }
83177
+ }
83178
+ return m;
83179
+}
8300683180
8300783181
/*
8300883182
** These routines are Walker callbacks used to check expressions to
8300983183
** see if they are "constant" for some definition of constant. The
8301083184
** Walker.eCode value determines the type of "constant" we are looking
@@ -83042,11 +83216,11 @@
8304283216
switch( pExpr->op ){
8304383217
/* Consider functions to be constant if all their arguments are constant
8304483218
** and either pWalker->eCode==4 or 5 or the function has the
8304583219
** SQLITE_FUNC_CONST flag. */
8304683220
case TK_FUNCTION:
83047
- if( pWalker->eCode>=4 || ExprHasProperty(pExpr,EP_Constant) ){
83221
+ if( pWalker->eCode>=4 || ExprHasProperty(pExpr,EP_ConstFunc) ){
8304883222
return WRC_Continue;
8304983223
}else{
8305083224
pWalker->eCode = 0;
8305183225
return WRC_Abort;
8305283226
}
@@ -84049,11 +84223,12 @@
8404984223
int i;
8405084224
int minLru;
8405184225
int idxLru;
8405284226
struct yColCache *p;
8405384227
84054
- assert( iReg>0 ); /* Register numbers are always positive */
84228
+ /* Unless an error has occurred, register numbers are always positive. */
84229
+ assert( iReg>0 || pParse->nErr || pParse->db->mallocFailed );
8405584230
assert( iCol>=-1 && iCol<32768 ); /* Finite column numbers */
8405684231
8405784232
/* The SQLITE_ColumnCache flag disables the column cache. This is used
8405884233
** for testing only - to verify that SQLite always gets the same answer
8405984234
** with and without the column cache.
@@ -89078,11 +89253,11 @@
8907889253
break;
8907989254
8908089255
case SQLITE_NULL:
8908189256
/* No key specified. Use the key from the main database */
8908289257
sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
89083
- if( nKey>0 || sqlite3BtreeGetReserve(db->aDb[0].pBt)>0 ){
89258
+ if( nKey>0 || sqlite3BtreeGetOptimalReserve(db->aDb[0].pBt)>0 ){
8908489259
rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
8908589260
}
8908689261
break;
8908789262
}
8908889263
}
@@ -90044,14 +90219,10 @@
9004490219
*/
9004590220
SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){
9004690221
Table *p = 0;
9004790222
int i;
9004890223
90049
-#ifdef SQLITE_ENABLE_API_ARMOR
90050
- if( !sqlite3SafetyCheckOk(db) || zName==0 ) return 0;
90051
-#endif
90052
-
9005390224
/* All mutexes are required for schema access. Make sure we hold them. */
9005490225
assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) );
9005590226
#if SQLITE_USER_AUTHENTICATION
9005690227
/* Only the admin user is allowed to know that the sqlite_user table
9005790228
** exists */
@@ -91467,15 +91638,18 @@
9146791638
}
9146891639
pPk->isCovering = 1;
9146991640
assert( pPk!=0 );
9147091641
nPk = pPk->nKeyCol;
9147191642
91472
- /* Make sure every column of the PRIMARY KEY is NOT NULL */
91473
- for(i=0; i<nPk; i++){
91474
- pTab->aCol[pPk->aiColumn[i]].notNull = 1;
91643
+ /* Make sure every column of the PRIMARY KEY is NOT NULL. (Except,
91644
+ ** do not enforce this for imposter tables.) */
91645
+ if( !db->init.imposterTable ){
91646
+ for(i=0; i<nPk; i++){
91647
+ pTab->aCol[pPk->aiColumn[i]].notNull = 1;
91648
+ }
91649
+ pPk->uniqNotNull = 1;
9147591650
}
91476
- pPk->uniqNotNull = 1;
9147791651
9147891652
/* The root page of the PRIMARY KEY is the table root page */
9147991653
pPk->tnum = pTab->tnum;
9148091654
9148191655
/* Update the in-memory representation of all UNIQUE indices by converting
@@ -94706,11 +94880,11 @@
9470694880
pInClause = sqlite3PExpr(pParse, TK_IN, pWhereRowid, 0, 0);
9470794881
if( pInClause == 0 ) goto limit_where_cleanup_1;
9470894882
9470994883
pInClause->x.pSelect = pSelect;
9471094884
pInClause->flags |= EP_xIsSelect;
94711
- sqlite3ExprSetHeight(pParse, pInClause);
94885
+ sqlite3ExprSetHeightAndFlags(pParse, pInClause);
9471294886
return pInClause;
9471394887
9471494888
/* something went wrong. clean up anything allocated. */
9471594889
limit_where_cleanup_1:
9471694890
sqlite3SelectDelete(pParse->db, pSelect);
@@ -95648,10 +95822,18 @@
9564895822
for(z2=z; *z2; len++){
9564995823
SQLITE_SKIP_UTF8(z2);
9565095824
}
9565195825
}
9565295826
}
95827
+#ifdef SQLITE_SUBSTR_COMPATIBILITY
95828
+ /* If SUBSTR_COMPATIBILITY is defined then substr(X,0,N) work the same as
95829
+ ** as substr(X,1,N) - it returns the first N characters of X. This
95830
+ ** is essentially a back-out of the bug-fix in check-in [5fc125d362df4b8]
95831
+ ** from 2009-02-02 for compatibility of applications that exploited the
95832
+ ** old buggy behavior. */
95833
+ if( p1==0 ) p1 = 1; /* <rdar://problem/6778339> */
95834
+#endif
9565395835
if( argc==3 ){
9565495836
p2 = sqlite3_value_int(argv[2]);
9565595837
if( p2<0 ){
9565695838
p2 = -p2;
9565795839
negP2 = 1;
@@ -102032,15 +102214,22 @@
102032102214
# define SQLITE_ENABLE_LOCKING_STYLE 0
102033102215
# endif
102034102216
#endif
102035102217
102036102218
/***************************************************************************
102037
-** The next block of code, including the PragTyp_XXXX macro definitions and
102038
-** the aPragmaName[] object is composed of generated code. DO NOT EDIT.
102039
-**
102040
-** To add new pragmas, edit the code in ../tool/mkpragmatab.tcl and rerun
102041
-** that script. Then copy/paste the output in place of the following:
102219
+** The "pragma.h" include file is an automatically generated file that
102220
+** that includes the PragType_XXXX macro definitions and the aPragmaName[]
102221
+** object. This ensures that the aPragmaName[] table is arranged in
102222
+** lexicographical order to facility a binary search of the pragma name.
102223
+** Do not edit pragma.h directly. Edit and rerun the script in at
102224
+** ../tool/mkpragmatab.tcl. */
102225
+/************** Include pragma.h in the middle of pragma.c *******************/
102226
+/************** Begin file pragma.h ******************************************/
102227
+/* DO NOT EDIT!
102228
+** This file is automatically generated by the script at
102229
+** ../tool/mkpragmatab.tcl. To update the set of pragmas, edit
102230
+** that script and rerun it.
102042102231
*/
102043102232
#define PragTyp_HEADER_VALUE 0
102044102233
#define PragTyp_AUTO_VACUUM 1
102045102234
#define PragTyp_FLAG 2
102046102235
#define PragTyp_BUSY_TIMEOUT 3
@@ -102271,10 +102460,14 @@
102271102460
/* iArg: */ 0 },
102272102461
{ /* zName: */ "index_list",
102273102462
/* ePragTyp: */ PragTyp_INDEX_LIST,
102274102463
/* ePragFlag: */ PragFlag_NeedSchema,
102275102464
/* iArg: */ 0 },
102465
+ { /* zName: */ "index_xinfo",
102466
+ /* ePragTyp: */ PragTyp_INDEX_INFO,
102467
+ /* ePragFlag: */ PragFlag_NeedSchema,
102468
+ /* iArg: */ 1 },
102276102469
#endif
102277102470
#if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
102278102471
{ /* zName: */ "integrity_check",
102279102472
/* ePragTyp: */ PragTyp_INTEGRITY_CHECK,
102280102473
/* ePragFlag: */ PragFlag_NeedSchema,
@@ -102487,13 +102680,14 @@
102487102680
/* ePragTyp: */ PragTyp_FLAG,
102488102681
/* ePragFlag: */ 0,
102489102682
/* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode },
102490102683
#endif
102491102684
};
102492
-/* Number of pragmas: 58 on by default, 71 total. */
102493
-/* End of the automatically generated pragma table.
102494
-***************************************************************************/
102685
+/* Number of pragmas: 59 on by default, 72 total. */
102686
+
102687
+/************** End of pragma.h **********************************************/
102688
+/************** Continuing where we left off in pragma.c *********************/
102495102689
102496102690
/*
102497102691
** Interpret the given string as a safety level. Return 0 for OFF,
102498102692
** 1 for ON or NORMAL and 2 for FULL. Return 1 for an empty or
102499102693
** unrecognized string argument. The FULL option is disallowed
@@ -102742,10 +102936,11 @@
102742102936
int lwr, upr, mid = 0; /* Binary search bounds */
102743102937
int rc; /* return value form SQLITE_FCNTL_PRAGMA */
102744102938
sqlite3 *db = pParse->db; /* The database connection */
102745102939
Db *pDb; /* The specific database being pragmaed */
102746102940
Vdbe *v = sqlite3GetVdbe(pParse); /* Prepared statement */
102941
+ const struct sPragmaNames *pPragma;
102747102942
102748102943
if( v==0 ) return;
102749102944
sqlite3VdbeRunOnlyOnce(v);
102750102945
pParse->nMem = 2;
102751102946
@@ -102819,18 +103014,19 @@
102819103014
}else{
102820103015
lwr = mid + 1;
102821103016
}
102822103017
}
102823103018
if( lwr>upr ) goto pragma_out;
103019
+ pPragma = &aPragmaNames[mid];
102824103020
102825103021
/* Make sure the database schema is loaded if the pragma requires that */
102826
- if( (aPragmaNames[mid].mPragFlag & PragFlag_NeedSchema)!=0 ){
103022
+ if( (pPragma->mPragFlag & PragFlag_NeedSchema)!=0 ){
102827103023
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
102828103024
}
102829103025
102830103026
/* Jump to the appropriate pragma handler */
102831
- switch( aPragmaNames[mid].ePragTyp ){
103027
+ switch( pPragma->ePragTyp ){
102832103028
102833103029
#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
102834103030
/*
102835103031
** PRAGMA [database.]default_cache_size
102836103032
** PRAGMA [database.]default_cache_size=N
@@ -103405,14 +103601,13 @@
103405103601
#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
103406103602
103407103603
#ifndef SQLITE_OMIT_FLAG_PRAGMAS
103408103604
case PragTyp_FLAG: {
103409103605
if( zRight==0 ){
103410
- returnSingleInt(pParse, aPragmaNames[mid].zName,
103411
- (db->flags & aPragmaNames[mid].iArg)!=0 );
103606
+ returnSingleInt(pParse, pPragma->zName, (db->flags & pPragma->iArg)!=0 );
103412103607
}else{
103413
- int mask = aPragmaNames[mid].iArg; /* Mask of bits to set or clear. */
103608
+ int mask = pPragma->iArg; /* Mask of bits to set or clear. */
103414103609
if( db->autoCommit==0 ){
103415103610
/* Foreign key support may not be enabled or disabled while not
103416103611
** in auto-commit mode. */
103417103612
mask &= ~(SQLITE_ForeignKeys);
103418103613
}
@@ -103537,24 +103732,34 @@
103537103732
Index *pIdx;
103538103733
Table *pTab;
103539103734
pIdx = sqlite3FindIndex(db, zRight, zDb);
103540103735
if( pIdx ){
103541103736
int i;
103737
+ int mx = pPragma->iArg ? pIdx->nColumn : pIdx->nKeyCol;
103542103738
pTab = pIdx->pTable;
103543
- sqlite3VdbeSetNumCols(v, 3);
103544
- pParse->nMem = 3;
103739
+ sqlite3VdbeSetNumCols(v, 6);
103740
+ pParse->nMem = 6;
103545103741
sqlite3CodeVerifySchema(pParse, iDb);
103546103742
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", SQLITE_STATIC);
103547103743
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", SQLITE_STATIC);
103548103744
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", SQLITE_STATIC);
103549
- for(i=0; i<pIdx->nKeyCol; i++){
103745
+ sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "desc", SQLITE_STATIC);
103746
+ sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "coll", SQLITE_STATIC);
103747
+ sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "key", SQLITE_STATIC);
103748
+ for(i=0; i<mx; i++){
103550103749
i16 cnum = pIdx->aiColumn[i];
103551103750
sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
103552103751
sqlite3VdbeAddOp2(v, OP_Integer, cnum, 2);
103553
- assert( pTab->nCol>cnum );
103554
- sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pTab->aCol[cnum].zName, 0);
103555
- sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
103752
+ if( cnum<0 ){
103753
+ sqlite3VdbeAddOp2(v, OP_Null, 0, 3);
103754
+ }else{
103755
+ sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pTab->aCol[cnum].zName, 0);
103756
+ }
103757
+ sqlite3VdbeAddOp2(v, OP_Integer, pIdx->aSortOrder[i], 4);
103758
+ sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, pIdx->azColl[i], 0);
103759
+ sqlite3VdbeAddOp2(v, OP_Integer, i<pIdx->nKeyCol, 6);
103760
+ sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
103556103761
}
103557103762
}
103558103763
}
103559103764
break;
103560103765
@@ -103563,21 +103768,26 @@
103563103768
Table *pTab;
103564103769
int i;
103565103770
pTab = sqlite3FindTable(db, zRight, zDb);
103566103771
if( pTab ){
103567103772
v = sqlite3GetVdbe(pParse);
103568
- sqlite3VdbeSetNumCols(v, 3);
103569
- pParse->nMem = 3;
103773
+ sqlite3VdbeSetNumCols(v, 5);
103774
+ pParse->nMem = 5;
103570103775
sqlite3CodeVerifySchema(pParse, iDb);
103571103776
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
103572103777
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
103573103778
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", SQLITE_STATIC);
103779
+ sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "origin", SQLITE_STATIC);
103780
+ sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "partial", SQLITE_STATIC);
103574103781
for(pIdx=pTab->pIndex, i=0; pIdx; pIdx=pIdx->pNext, i++){
103782
+ const char *azOrigin[] = { "c", "u", "pk" };
103575103783
sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
103576103784
sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0);
103577103785
sqlite3VdbeAddOp2(v, OP_Integer, IsUniqueIndex(pIdx), 3);
103578
- sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
103786
+ sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, azOrigin[pIdx->idxType], 0);
103787
+ sqlite3VdbeAddOp2(v, OP_Integer, pIdx->pPartIdxWhere!=0, 5);
103788
+ sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 5);
103579103789
}
103580103790
}
103581103791
}
103582103792
break;
103583103793
@@ -104143,13 +104353,13 @@
104143104353
**
104144104354
** The user-version is not used internally by SQLite. It may be used by
104145104355
** applications for any purpose.
104146104356
*/
104147104357
case PragTyp_HEADER_VALUE: {
104148
- int iCookie = aPragmaNames[mid].iArg; /* Which cookie to read or write */
104358
+ int iCookie = pPragma->iArg; /* Which cookie to read or write */
104149104359
sqlite3VdbeUsesBtree(v, iDb);
104150
- if( zRight && (aPragmaNames[mid].mPragFlag & PragFlag_ReadOnly)==0 ){
104360
+ if( zRight && (pPragma->mPragFlag & PragFlag_ReadOnly)==0 ){
104151104361
/* Write the specified cookie value */
104152104362
static const VdbeOpList setCookie[] = {
104153104363
{ OP_Transaction, 0, 1, 0}, /* 0 */
104154104364
{ OP_Integer, 0, 1, 0}, /* 1 */
104155104365
{ OP_SetCookie, 0, 0, 1}, /* 2 */
@@ -104265,11 +104475,11 @@
104265104475
** if one is set. If no busy handler or a different busy handler is set
104266104476
** then 0 is returned. Setting the busy_timeout to 0 or negative
104267104477
** disables the timeout.
104268104478
*/
104269104479
/*case PragTyp_BUSY_TIMEOUT*/ default: {
104270
- assert( aPragmaNames[mid].ePragTyp==PragTyp_BUSY_TIMEOUT );
104480
+ assert( pPragma->ePragTyp==PragTyp_BUSY_TIMEOUT );
104271104481
if( zRight ){
104272104482
sqlite3_busy_timeout(db, sqlite3Atoi(zRight));
104273104483
}
104274104484
returnSingleInt(pParse, "timeout", db->busyTimeout);
104275104485
break;
@@ -108486,11 +108696,14 @@
108486108696
**
108487108697
** Flattening is only attempted if all of the following are true:
108488108698
**
108489108699
** (1) The subquery and the outer query do not both use aggregates.
108490108700
**
108491
-** (2) The subquery is not an aggregate or the outer query is not a join.
108701
+** (2) The subquery is not an aggregate or (2a) the outer query is not a join
108702
+** and (2b) the outer query does not use subqueries other than the one
108703
+** FROM-clause subquery that is a candidate for flattening. (2b is
108704
+** due to ticket [2f7170d73bf9abf80] from 2015-02-09.)
108492108705
**
108493108706
** (3) The subquery is not the right operand of a left outer join
108494108707
** (Originally ticket #306. Strengthened by ticket #3300)
108495108708
**
108496108709
** (4) The subquery is not DISTINCT.
@@ -108623,12 +108836,21 @@
108623108836
assert( pSrc && iFrom>=0 && iFrom<pSrc->nSrc );
108624108837
pSubitem = &pSrc->a[iFrom];
108625108838
iParent = pSubitem->iCursor;
108626108839
pSub = pSubitem->pSelect;
108627108840
assert( pSub!=0 );
108628
- if( isAgg && subqueryIsAgg ) return 0; /* Restriction (1) */
108629
- if( subqueryIsAgg && pSrc->nSrc>1 ) return 0; /* Restriction (2) */
108841
+ if( subqueryIsAgg ){
108842
+ if( isAgg ) return 0; /* Restriction (1) */
108843
+ if( pSrc->nSrc>1 ) return 0; /* Restriction (2a) */
108844
+ if( (p->pWhere && ExprHasProperty(p->pWhere,EP_Subquery))
108845
+ || (sqlite3ExprListFlags(p->pEList) & EP_Subquery)!=0
108846
+ || (sqlite3ExprListFlags(p->pOrderBy) & EP_Subquery)!=0
108847
+ ){
108848
+ return 0; /* Restriction (2b) */
108849
+ }
108850
+ }
108851
+
108630108852
pSubSrc = pSub->pSrc;
108631108853
assert( pSubSrc );
108632108854
/* Prior to version 3.1.2, when LIMIT and OFFSET had to be simple constants,
108633108855
** not arbitrary expressions, we allowed some combining of LIMIT and OFFSET
108634108856
** because they could be computed at compile-time. But when LIMIT and OFFSET
@@ -109445,11 +109667,11 @@
109445109667
#ifndef SQLITE_OMIT_SUBQUERY
109446109668
Select *pSel = pFrom->pSelect;
109447109669
/* A sub-query in the FROM clause of a SELECT */
109448109670
assert( pSel!=0 );
109449109671
assert( pFrom->pTab==0 );
109450
- sqlite3WalkSelect(pWalker, pSel);
109672
+ if( sqlite3WalkSelect(pWalker, pSel) ) return WRC_Abort;
109451109673
pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
109452109674
if( pTab==0 ) return WRC_Abort;
109453109675
pTab->nRef = 1;
109454109676
pTab->zName = sqlite3MPrintf(db, "sqlite_sq_%p", (void*)pTab);
109455109677
while( pSel->pPrior ){ pSel = pSel->pPrior; }
@@ -110044,10 +110266,17 @@
110044110266
if( pParse->nErr || db->mallocFailed ){
110045110267
goto select_end;
110046110268
}
110047110269
isAgg = (p->selFlags & SF_Aggregate)!=0;
110048110270
assert( pEList!=0 );
110271
+#if SELECTTRACE_ENABLED
110272
+ if( sqlite3SelectTrace & 0x100 ){
110273
+ SELECTTRACE(0x100,pParse,p, ("after name resolution:\n"));
110274
+ sqlite3TreeViewSelect(0, p, 0);
110275
+ }
110276
+#endif
110277
+
110049110278
110050110279
/* Begin generating code.
110051110280
*/
110052110281
v = sqlite3GetVdbe(pParse);
110053110282
if( v==0 ) goto select_end;
@@ -110789,13 +111018,13 @@
110789111018
** Generate a human-readable description of a the Select object.
110790111019
*/
110791111020
SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){
110792111021
int n = 0;
110793111022
pView = sqlite3TreeViewPush(pView, moreToFollow);
110794
- sqlite3TreeViewLine(pView, "SELECT%s%s",
111023
+ sqlite3TreeViewLine(pView, "SELECT%s%s (0x%p)",
110795111024
((p->selFlags & SF_Distinct) ? " DISTINCT" : ""),
110796
- ((p->selFlags & SF_Aggregate) ? " agg_flag" : "")
111025
+ ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""), p
110797111026
);
110798111027
if( p->pSrc && p->pSrc->nSrc ) n++;
110799111028
if( p->pWhere ) n++;
110800111029
if( p->pGroupBy ) n++;
110801111030
if( p->pHaving ) n++;
@@ -113161,11 +113390,11 @@
113161113390
** locked (as there was more than one active statement when the transaction
113162113391
** to read the schema was concluded. Unlock it here so that this doesn't
113163113392
** cause problems for the call to BtreeSetPageSize() below. */
113164113393
sqlite3BtreeCommit(pTemp);
113165113394
113166
- nRes = sqlite3BtreeGetReserve(pMain);
113395
+ nRes = sqlite3BtreeGetOptimalReserve(pMain);
113167113396
113168113397
/* A VACUUM cannot change the pagesize of an encrypted database. */
113169113398
#ifdef SQLITE_HAS_CODEC
113170113399
if( db->nextPagesize ){
113171113400
extern void sqlite3CodecGetKey(sqlite3*, int, void**, int*);
@@ -114058,11 +114287,13 @@
114058114287
int rc = SQLITE_OK;
114059114288
Table *pTab;
114060114289
char *zErr = 0;
114061114290
114062114291
#ifdef SQLITE_ENABLE_API_ARMOR
114063
- if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
114292
+ if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){
114293
+ return SQLITE_MISUSE_BKPT;
114294
+ }
114064114295
#endif
114065114296
sqlite3_mutex_enter(db->mutex);
114066114297
if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){
114067114298
sqlite3Error(db, SQLITE_MISUSE);
114068114299
sqlite3_mutex_leave(db->mutex);
@@ -116547,16 +116778,20 @@
116547116778
pTable = pSrc->pTab;
116548116779
pWCEnd = &pWC->a[pWC->nTerm];
116549116780
pLoop = pLevel->pWLoop;
116550116781
idxCols = 0;
116551116782
for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
116783
+ Expr *pExpr = pTerm->pExpr;
116784
+ assert( !ExprHasProperty(pExpr, EP_FromJoin) /* prereq always non-zero */
116785
+ || pExpr->iRightJoinTable!=pSrc->iCursor /* for the right-hand */
116786
+ || pLoop->prereq!=0 ); /* table of a LEFT JOIN */
116552116787
if( pLoop->prereq==0
116553116788
&& (pTerm->wtFlags & TERM_VIRTUAL)==0
116554
- && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
116555
- && sqlite3ExprIsTableConstant(pTerm->pExpr, pSrc->iCursor) ){
116789
+ && !ExprHasProperty(pExpr, EP_FromJoin)
116790
+ && sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor) ){
116556116791
pPartial = sqlite3ExprAnd(pParse->db, pPartial,
116557
- sqlite3ExprDup(pParse->db, pTerm->pExpr, 0));
116792
+ sqlite3ExprDup(pParse->db, pExpr, 0));
116558116793
}
116559116794
if( termCanDriveIndex(pTerm, pSrc, notReady) ){
116560116795
int iCol = pTerm->u.leftColumn;
116561116796
Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
116562116797
testcase( iCol==BMS );
@@ -119630,12 +119865,13 @@
119630119865
*/
119631119866
static int whereUsablePartialIndex(int iTab, WhereClause *pWC, Expr *pWhere){
119632119867
int i;
119633119868
WhereTerm *pTerm;
119634119869
for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
119635
- if( sqlite3ExprImpliesExpr(pTerm->pExpr, pWhere, iTab)
119636
- && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
119870
+ Expr *pExpr = pTerm->pExpr;
119871
+ if( sqlite3ExprImpliesExpr(pExpr, pWhere, iTab)
119872
+ && (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->iRightJoinTable==iTab)
119637119873
){
119638119874
return 1;
119639119875
}
119640119876
}
119641119877
return 0;
@@ -124576,11 +124812,11 @@
124576124812
yygotominor.yy346.pExpr = sqlite3PExpr(pParse, yymsp[-3].minor.yy328 ? TK_NE : TK_EQ, yymsp[-4].minor.yy346.pExpr, pRHS, 0);
124577124813
}else{
124578124814
yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy346.pExpr, 0, 0);
124579124815
if( yygotominor.yy346.pExpr ){
124580124816
yygotominor.yy346.pExpr->x.pList = yymsp[-1].minor.yy14;
124581
- sqlite3ExprSetHeight(pParse, yygotominor.yy346.pExpr);
124817
+ sqlite3ExprSetHeightAndFlags(pParse, yygotominor.yy346.pExpr);
124582124818
}else{
124583124819
sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy14);
124584124820
}
124585124821
if( yymsp[-3].minor.yy328 ) yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy346.pExpr, 0, 0);
124586124822
}
@@ -124591,12 +124827,12 @@
124591124827
case 224: /* expr ::= LP select RP */
124592124828
{
124593124829
yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
124594124830
if( yygotominor.yy346.pExpr ){
124595124831
yygotominor.yy346.pExpr->x.pSelect = yymsp[-1].minor.yy3;
124596
- ExprSetProperty(yygotominor.yy346.pExpr, EP_xIsSelect);
124597
- sqlite3ExprSetHeight(pParse, yygotominor.yy346.pExpr);
124832
+ ExprSetProperty(yygotominor.yy346.pExpr, EP_xIsSelect|EP_Subquery);
124833
+ sqlite3ExprSetHeightAndFlags(pParse, yygotominor.yy346.pExpr);
124598124834
}else{
124599124835
sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy3);
124600124836
}
124601124837
yygotominor.yy346.zStart = yymsp[-2].minor.yy0.z;
124602124838
yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
@@ -124605,12 +124841,12 @@
124605124841
case 225: /* expr ::= expr in_op LP select RP */
124606124842
{
124607124843
yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy346.pExpr, 0, 0);
124608124844
if( yygotominor.yy346.pExpr ){
124609124845
yygotominor.yy346.pExpr->x.pSelect = yymsp[-1].minor.yy3;
124610
- ExprSetProperty(yygotominor.yy346.pExpr, EP_xIsSelect);
124611
- sqlite3ExprSetHeight(pParse, yygotominor.yy346.pExpr);
124846
+ ExprSetProperty(yygotominor.yy346.pExpr, EP_xIsSelect|EP_Subquery);
124847
+ sqlite3ExprSetHeightAndFlags(pParse, yygotominor.yy346.pExpr);
124612124848
}else{
124613124849
sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy3);
124614124850
}
124615124851
if( yymsp[-3].minor.yy328 ) yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy346.pExpr, 0, 0);
124616124852
yygotominor.yy346.zStart = yymsp[-4].minor.yy346.zStart;
@@ -124621,12 +124857,12 @@
124621124857
{
124622124858
SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);
124623124859
yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy346.pExpr, 0, 0);
124624124860
if( yygotominor.yy346.pExpr ){
124625124861
yygotominor.yy346.pExpr->x.pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
124626
- ExprSetProperty(yygotominor.yy346.pExpr, EP_xIsSelect);
124627
- sqlite3ExprSetHeight(pParse, yygotominor.yy346.pExpr);
124862
+ ExprSetProperty(yygotominor.yy346.pExpr, EP_xIsSelect|EP_Subquery);
124863
+ sqlite3ExprSetHeightAndFlags(pParse, yygotominor.yy346.pExpr);
124628124864
}else{
124629124865
sqlite3SrcListDelete(pParse->db, pSrc);
124630124866
}
124631124867
if( yymsp[-2].minor.yy328 ) yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy346.pExpr, 0, 0);
124632124868
yygotominor.yy346.zStart = yymsp[-3].minor.yy346.zStart;
@@ -124636,12 +124872,12 @@
124636124872
case 227: /* expr ::= EXISTS LP select RP */
124637124873
{
124638124874
Expr *p = yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
124639124875
if( p ){
124640124876
p->x.pSelect = yymsp[-1].minor.yy3;
124641
- ExprSetProperty(p, EP_xIsSelect);
124642
- sqlite3ExprSetHeight(pParse, p);
124877
+ ExprSetProperty(p, EP_xIsSelect|EP_Subquery);
124878
+ sqlite3ExprSetHeightAndFlags(pParse, p);
124643124879
}else{
124644124880
sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy3);
124645124881
}
124646124882
yygotominor.yy346.zStart = yymsp[-3].minor.yy0.z;
124647124883
yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
@@ -124650,11 +124886,11 @@
124650124886
case 228: /* expr ::= CASE case_operand case_exprlist case_else END */
124651124887
{
124652124888
yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy132, 0, 0);
124653124889
if( yygotominor.yy346.pExpr ){
124654124890
yygotominor.yy346.pExpr->x.pList = yymsp[-1].minor.yy132 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy14,yymsp[-1].minor.yy132) : yymsp[-2].minor.yy14;
124655
- sqlite3ExprSetHeight(pParse, yygotominor.yy346.pExpr);
124891
+ sqlite3ExprSetHeightAndFlags(pParse, yygotominor.yy346.pExpr);
124656124892
}else{
124657124893
sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy14);
124658124894
sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy132);
124659124895
}
124660124896
yygotominor.yy346.zStart = yymsp[-4].minor.yy0.z;
@@ -125892,14 +126128,11 @@
125892126128
int lastTokenParsed = -1; /* type of the previous token */
125893126129
u8 enableLookaside; /* Saved value of db->lookaside.bEnabled */
125894126130
sqlite3 *db = pParse->db; /* The database connection */
125895126131
int mxSqlLen; /* Max length of an SQL string */
125896126132
125897
-
125898
-#ifdef SQLITE_ENABLE_API_ARMOR
125899
- if( zSql==0 || pzErrMsg==0 ) return SQLITE_MISUSE_BKPT;
125900
-#endif
126133
+ assert( zSql!=0 );
125901126134
mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
125902126135
if( db->nVdbeActive==0 ){
125903126136
db->u1.isInterrupted = 0;
125904126137
}
125905126138
pParse->rc = SQLITE_OK;
@@ -127823,11 +128056,11 @@
127823128056
sqlite3 *db,
127824128057
int (*xBusy)(void*,int),
127825128058
void *pArg
127826128059
){
127827128060
#ifdef SQLITE_ENABLE_API_ARMOR
127828
- if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE;
128061
+ if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
127829128062
#endif
127830128063
sqlite3_mutex_enter(db->mutex);
127831128064
db->busyHandler.xFunc = xBusy;
127832128065
db->busyHandler.pArg = pArg;
127833128066
db->busyHandler.nBusy = 0;
@@ -129116,10 +129349,13 @@
129116129349
db->nMaxSorterMmap = 0x7FFFFFFF;
129117129350
db->flags |= SQLITE_ShortColNames | SQLITE_EnableTrigger | SQLITE_CacheSpill
129118129351
#if !defined(SQLITE_DEFAULT_AUTOMATIC_INDEX) || SQLITE_DEFAULT_AUTOMATIC_INDEX
129119129352
| SQLITE_AutoIndex
129120129353
#endif
129354
+#if SQLITE_DEFAULT_CKPTFULLFSYNC
129355
+ | SQLITE_CkptFullFSync
129356
+#endif
129121129357
#if SQLITE_DEFAULT_FILE_FORMAT<4
129122129358
| SQLITE_LegacyFileFmt
129123129359
#endif
129124129360
#ifdef SQLITE_ENABLE_LOAD_EXTENSION
129125129361
| SQLITE_LoadExtension
@@ -129551,17 +129787,23 @@
129551129787
int rc;
129552129788
char *zErrMsg = 0;
129553129789
Table *pTab = 0;
129554129790
Column *pCol = 0;
129555129791
int iCol = 0;
129556
-
129557129792
char const *zDataType = 0;
129558129793
char const *zCollSeq = 0;
129559129794
int notnull = 0;
129560129795
int primarykey = 0;
129561129796
int autoinc = 0;
129562129797
129798
+
129799
+#ifdef SQLITE_ENABLE_API_ARMOR
129800
+ if( !sqlite3SafetyCheckOk(db) || zTableName==0 ){
129801
+ return SQLITE_MISUSE_BKPT;
129802
+ }
129803
+#endif
129804
+
129563129805
/* Ensure the database schema has been loaded */
129564129806
sqlite3_mutex_enter(db->mutex);
129565129807
sqlite3BtreeEnterAll(db);
129566129808
rc = sqlite3Init(db, &zErrMsg);
129567129809
if( SQLITE_OK!=rc ){
@@ -129704,11 +129946,11 @@
129704129946
rc = SQLITE_NOTFOUND;
129705129947
}
129706129948
sqlite3BtreeLeave(pBtree);
129707129949
}
129708129950
sqlite3_mutex_leave(db->mutex);
129709
- return rc;
129951
+ return rc;
129710129952
}
129711129953
129712129954
/*
129713129955
** Interface to the testing logic.
129714129956
*/
@@ -130007,10 +130249,39 @@
130007130249
*/
130008130250
case SQLITE_TESTCTRL_ISINIT: {
130009130251
if( sqlite3GlobalConfig.isInit==0 ) rc = SQLITE_ERROR;
130010130252
break;
130011130253
}
130254
+
130255
+ /* sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, db, dbName, onOff, tnum);
130256
+ **
130257
+ ** This test control is used to create imposter tables. "db" is a pointer
130258
+ ** to the database connection. dbName is the database name (ex: "main" or
130259
+ ** "temp") which will receive the imposter. "onOff" turns imposter mode on
130260
+ ** or off. "tnum" is the root page of the b-tree to which the imposter
130261
+ ** table should connect.
130262
+ **
130263
+ ** Enable imposter mode only when the schema has already been parsed. Then
130264
+ ** run a single CREATE TABLE statement to construct the imposter table in the
130265
+ ** parsed schema. Then turn imposter mode back off again.
130266
+ **
130267
+ ** If onOff==0 and tnum>0 then reset the schema for all databases, causing
130268
+ ** the schema to be reparsed the next time it is needed. This has the
130269
+ ** effect of erasing all imposter tables.
130270
+ */
130271
+ case SQLITE_TESTCTRL_IMPOSTER: {
130272
+ sqlite3 *db = va_arg(ap, sqlite3*);
130273
+ sqlite3_mutex_enter(db->mutex);
130274
+ db->init.iDb = sqlite3FindDbName(db, va_arg(ap,const char*));
130275
+ db->init.busy = db->init.imposterTable = va_arg(ap,int);
130276
+ db->init.newTnum = va_arg(ap,int);
130277
+ if( db->init.busy==0 && db->init.newTnum>0 ){
130278
+ sqlite3ResetAllSchemasOfConnection(db);
130279
+ }
130280
+ sqlite3_mutex_leave(db->mutex);
130281
+ break;
130282
+ }
130012130283
}
130013130284
va_end(ap);
130014130285
#endif /* SQLITE_OMIT_BUILTIN_TEST */
130015130286
return rc;
130016130287
}
@@ -134489,14 +134760,21 @@
134489134760
** statement loops through all rows of the %_content table. For a
134490134761
** full-text query or docid lookup, the statement retrieves a single
134491134762
** row by docid.
134492134763
*/
134493134764
if( eSearch==FTS3_FULLSCAN_SEARCH ){
134494
- zSql = sqlite3_mprintf(
134495
- "SELECT %s ORDER BY rowid %s",
134496
- p->zReadExprlist, (pCsr->bDesc ? "DESC" : "ASC")
134497
- );
134765
+ if( pDocidGe || pDocidLe ){
134766
+ zSql = sqlite3_mprintf(
134767
+ "SELECT %s WHERE rowid BETWEEN %lld AND %lld ORDER BY rowid %s",
134768
+ p->zReadExprlist, pCsr->iMinDocid, pCsr->iMaxDocid,
134769
+ (pCsr->bDesc ? "DESC" : "ASC")
134770
+ );
134771
+ }else{
134772
+ zSql = sqlite3_mprintf("SELECT %s ORDER BY rowid %s",
134773
+ p->zReadExprlist, (pCsr->bDesc ? "DESC" : "ASC")
134774
+ );
134775
+ }
134498134776
if( zSql ){
134499134777
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pCsr->pStmt, 0);
134500134778
sqlite3_free(zSql);
134501134779
}else{
134502134780
rc = SQLITE_NOMEM;
@@ -136981,11 +137259,10 @@
136981137259
iDocid = pExpr->iDocid;
136982137260
pIter = pPhrase->doclist.pList;
136983137261
if( iDocid!=pCsr->iPrevId || pExpr->bEof ){
136984137262
int rc = SQLITE_OK;
136985137263
int bDescDoclist = pTab->bDescIdx; /* For DOCID_CMP macro */
136986
- int iMul; /* +1 if csr dir matches index dir, else -1 */
136987137264
int bOr = 0;
136988137265
u8 bEof = 0;
136989137266
u8 bTreeEof = 0;
136990137267
Fts3Expr *p; /* Used to iterate from pExpr to root */
136991137268
Fts3Expr *pNear; /* Most senior NEAR ancestor (or pExpr) */
@@ -147528,12 +147805,16 @@
147528147805
147529147806
/* Now that the shift has been done, check if the initial "..." are
147530147807
** required. They are required if (a) this is not the first fragment,
147531147808
** or (b) this fragment does not begin at position 0 of its column.
147532147809
*/
147533
- if( rc==SQLITE_OK && (iPos>0 || iFragment>0) ){
147534
- rc = fts3StringAppend(pOut, zEllipsis, -1);
147810
+ if( rc==SQLITE_OK ){
147811
+ if( iPos>0 || iFragment>0 ){
147812
+ rc = fts3StringAppend(pOut, zEllipsis, -1);
147813
+ }else if( iBegin ){
147814
+ rc = fts3StringAppend(pOut, zDoc, iBegin);
147815
+ }
147535147816
}
147536147817
if( rc!=SQLITE_OK || iCurrent<iPos ) continue;
147537147818
}
147538147819
147539147820
if( iCurrent>=(iPos+nSnippet) ){
147540147821
--- 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.8.8.3. 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.
@@ -276,13 +276,13 @@
276 **
277 ** See also: [sqlite3_libversion()],
278 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
279 ** [sqlite_version()] and [sqlite_source_id()].
280 */
281 #define SQLITE_VERSION "3.8.8.3"
282 #define SQLITE_VERSION_NUMBER 3008008
283 #define SQLITE_SOURCE_ID "2015-02-25 13:29:11 9d6c1880fb75660bbabd693175579529785f8a6b"
284
285 /*
286 ** CAPI3REF: Run-Time Library Version Numbers
287 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
288 **
@@ -1118,13 +1118,13 @@
1118 ** and only needs to be supported when SQLITE_TEST is defined.
1119 **
1120 ** </ul>
1121 */
1122 #define SQLITE_FCNTL_LOCKSTATE 1
1123 #define SQLITE_GET_LOCKPROXYFILE 2
1124 #define SQLITE_SET_LOCKPROXYFILE 3
1125 #define SQLITE_LAST_ERRNO 4
1126 #define SQLITE_FCNTL_SIZE_HINT 5
1127 #define SQLITE_FCNTL_CHUNK_SIZE 6
1128 #define SQLITE_FCNTL_FILE_POINTER 7
1129 #define SQLITE_FCNTL_SYNC_OMITTED 8
1130 #define SQLITE_FCNTL_WIN32_AV_RETRY 9
@@ -1139,10 +1139,16 @@
1139 #define SQLITE_FCNTL_TRACE 19
1140 #define SQLITE_FCNTL_HAS_MOVED 20
1141 #define SQLITE_FCNTL_SYNC 21
1142 #define SQLITE_FCNTL_COMMIT_PHASETWO 22
1143 #define SQLITE_FCNTL_WIN32_SET_HANDLE 23
 
 
 
 
 
 
1144
1145 /*
1146 ** CAPI3REF: Mutex Handle
1147 **
1148 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -2400,10 +2406,14 @@
2400 /*
2401 ** CAPI3REF: Formatted String Printing Functions
2402 **
2403 ** These routines are work-alikes of the "printf()" family of functions
2404 ** from the standard C library.
 
 
 
 
2405 **
2406 ** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
2407 ** results into memory obtained from [sqlite3_malloc()].
2408 ** The strings returned by these two routines should be
2409 ** released by [sqlite3_free()]. ^Both routines return a
@@ -2432,11 +2442,11 @@
2432 ** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
2433 **
2434 ** These routines all implement some additional formatting
2435 ** options that are useful for constructing SQL statements.
2436 ** All of the usual printf() formatting options apply. In addition, there
2437 ** is are "%q", "%Q", and "%z" options.
2438 **
2439 ** ^(The %q option works like %s in that it substitutes a nul-terminated
2440 ** string from the argument list. But %q also doubles every '\'' character.
2441 ** %q is designed for use inside a string literal.)^ By doubling each '\''
2442 ** character it escapes that character and allows it to be inserted into
@@ -2484,10 +2494,16 @@
2484 ** sqlite3_free(zSQL);
2485 ** </pre></blockquote>
2486 **
2487 ** The code above will render a correct SQL statement in the zSQL
2488 ** variable even if the zText variable is a NULL pointer.
 
 
 
 
 
 
2489 **
2490 ** ^(The "%z" formatting option works like "%s" but with the
2491 ** addition that after the string has been read and copied into
2492 ** the result, [sqlite3_free()] is called on the input string.)^
2493 */
@@ -5234,10 +5250,15 @@
5234 ** successfully. An [error code] is returned otherwise.)^
5235 **
5236 ** ^Shared cache is disabled by default. But this might change in
5237 ** future releases of SQLite. Applications that care about shared
5238 ** cache setting should set it explicitly.
 
 
 
 
 
5239 **
5240 ** This interface is threadsafe on processors where writing a
5241 ** 32-bit integer is atomic.
5242 **
5243 ** See Also: [SQLite Shared-Cache Mode]
@@ -6434,11 +6455,12 @@
6434 #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
6435 #define SQLITE_TESTCTRL_VDBE_COVERAGE 21
6436 #define SQLITE_TESTCTRL_BYTEORDER 22
6437 #define SQLITE_TESTCTRL_ISINIT 23
6438 #define SQLITE_TESTCTRL_SORTER_MMAP 24
6439 #define SQLITE_TESTCTRL_LAST 24
 
6440
6441 /*
6442 ** CAPI3REF: SQLite Runtime Status
6443 **
6444 ** ^This interface is used to retrieve runtime status information
@@ -9219,14 +9241,12 @@
9219 SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve, int eFix);
9220 SQLITE_PRIVATE int sqlite3BtreeGetPageSize(Btree*);
9221 SQLITE_PRIVATE int sqlite3BtreeMaxPageCount(Btree*,int);
9222 SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree*);
9223 SQLITE_PRIVATE int sqlite3BtreeSecureDelete(Btree*,int);
9224 SQLITE_PRIVATE int sqlite3BtreeGetReserve(Btree*);
9225 #if defined(SQLITE_HAS_CODEC) || defined(SQLITE_DEBUG)
9226 SQLITE_PRIVATE int sqlite3BtreeGetReserveNoMutex(Btree *p);
9227 #endif
9228 SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum(Btree *, int);
9229 SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *);
9230 SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree*,int);
9231 SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster);
9232 SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree*, int);
@@ -10839,10 +10859,11 @@
10839 struct sqlite3InitInfo { /* Information used during initialization */
10840 int newTnum; /* Rootpage of table being initialized */
10841 u8 iDb; /* Which db file is being initialized */
10842 u8 busy; /* TRUE if currently initializing */
10843 u8 orphanTrigger; /* Last statement is orphaned TEMP trigger */
 
10844 } init;
10845 int nVdbeActive; /* Number of VDBEs currently running */
10846 int nVdbeRead; /* Number of active VDBEs that read or write */
10847 int nVdbeWrite; /* Number of active VDBEs that read and write */
10848 int nVdbeExec; /* Number of nested calls to VdbeExec() */
@@ -11795,12 +11816,18 @@
11795 #define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
11796 #define EP_Static 0x008000 /* Held in memory not obtained from malloc() */
11797 #define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */
11798 #define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
11799 #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
11800 #define EP_Constant 0x080000 /* Node is a constant */
11801 #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
 
 
 
 
 
 
11802
11803 /*
11804 ** These macros can be used to test, set, or clear bits in the
11805 ** Expr.flags field.
11806 */
@@ -12904,10 +12931,11 @@
12904 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*);
12905 SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
12906 SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int);
12907 SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,ExprSpan*);
12908 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*);
 
12909 SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**);
12910 SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**);
12911 SQLITE_PRIVATE void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
12912 SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3*);
12913 SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3*,int);
@@ -13487,16 +13515,15 @@
13487
13488 SQLITE_PRIVATE void sqlite3MemJournalOpen(sqlite3_file *);
13489 SQLITE_PRIVATE int sqlite3MemJournalSize(void);
13490 SQLITE_PRIVATE int sqlite3IsMemJournal(sqlite3_file *);
13491
 
13492 #if SQLITE_MAX_EXPR_DEPTH>0
13493 SQLITE_PRIVATE void sqlite3ExprSetHeight(Parse *pParse, Expr *p);
13494 SQLITE_PRIVATE int sqlite3SelectExprHeight(Select *);
13495 SQLITE_PRIVATE int sqlite3ExprCheckHeight(Parse*, int);
13496 #else
13497 #define sqlite3ExprSetHeight(x,y)
13498 #define sqlite3SelectExprHeight(x) 0
13499 #define sqlite3ExprCheckHeight(x,y)
13500 #endif
13501
13502 SQLITE_PRIVATE u32 sqlite3Get4byte(const u8*);
@@ -13629,20 +13656,20 @@
13629 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, /* 1x */
13630 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, /* 2x */
13631 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, /* 3x */
13632 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, /* 4x */
13633 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, /* 5x */
13634 96, 97, 66, 67, 68, 69, 70, 71, 72, 73,106,107,108,109,110,111, /* 6x */
13635 112, 81, 82, 83, 84, 85, 86, 87, 88, 89,122,123,124,125,126,127, /* 7x */
13636 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, /* 8x */
13637 144,145,146,147,148,149,150,151,152,153,154,155,156,157,156,159, /* 9x */
13638 160,161,162,163,164,165,166,167,168,169,170,171,140,141,142,175, /* Ax */
13639 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191, /* Bx */
13640 192,129,130,131,132,133,134,135,136,137,202,203,204,205,206,207, /* Cx */
13641 208,145,146,147,148,149,150,151,152,153,218,219,220,221,222,223, /* Dx */
13642 224,225,162,163,164,165,166,167,168,169,232,203,204,205,206,207, /* Ex */
13643 239,240,241,242,243,244,245,246,247,248,249,219,220,221,222,255, /* Fx */
13644 #endif
13645 };
13646
13647 /*
13648 ** The following 256 byte lookup table is used to support SQLites built-in
@@ -14637,10 +14664,13 @@
14637 ynVar nVar; /* Number of entries in aVar[] */
14638 ynVar nzVar; /* Number of entries in azVar[] */
14639 u32 cacheCtr; /* VdbeCursor row cache generation counter */
14640 int pc; /* The program counter */
14641 int rc; /* Value to return */
 
 
 
14642 u16 nResColumn; /* Number of columns in one row of the result set */
14643 u8 errorAction; /* Recovery action to do in case of an error */
14644 u8 minWriteFileFormat; /* Minimum file format for writable database files */
14645 bft explain:2; /* True if EXPLAIN present on SQL command */
14646 bft inVtabMethod:2; /* See comments above */
@@ -19111,12 +19141,16 @@
19111 pNew->cnt = 0;
19112 }
19113 break;
19114 }
19115 default: {
19116 assert( id-2 >= 0 );
19117 assert( id-2 < (int)(sizeof(aStatic)/sizeof(aStatic[0])) );
 
 
 
 
19118 pNew = &aStatic[id-2];
19119 pNew->id = id;
19120 break;
19121 }
19122 }
@@ -19127,12 +19161,17 @@
19127 ** This routine deallocates a previously allocated mutex.
19128 */
19129 static void debugMutexFree(sqlite3_mutex *pX){
19130 sqlite3_debug_mutex *p = (sqlite3_debug_mutex*)pX;
19131 assert( p->cnt==0 );
19132 assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE );
19133 sqlite3_free(p);
 
 
 
 
 
19134 }
19135
19136 /*
19137 ** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
19138 ** to enter a mutex. If another thread is already within the mutex,
@@ -19239,12 +19278,14 @@
19239 /*
19240 ** Each recursive mutex is an instance of the following structure.
19241 */
19242 struct sqlite3_mutex {
19243 pthread_mutex_t mutex; /* Mutex controlling the lock */
19244 #if SQLITE_MUTEX_NREF
19245 int id; /* Mutex type */
 
 
19246 volatile int nRef; /* Number of entrances */
19247 volatile pthread_t owner; /* Thread that is within this mutex */
19248 int trace; /* True to trace changes */
19249 #endif
19250 };
@@ -19357,22 +19398,16 @@
19357 pthread_mutexattr_init(&recursiveAttr);
19358 pthread_mutexattr_settype(&recursiveAttr, PTHREAD_MUTEX_RECURSIVE);
19359 pthread_mutex_init(&p->mutex, &recursiveAttr);
19360 pthread_mutexattr_destroy(&recursiveAttr);
19361 #endif
19362 #if SQLITE_MUTEX_NREF
19363 p->id = iType;
19364 #endif
19365 }
19366 break;
19367 }
19368 case SQLITE_MUTEX_FAST: {
19369 p = sqlite3MallocZero( sizeof(*p) );
19370 if( p ){
19371 #if SQLITE_MUTEX_NREF
19372 p->id = iType;
19373 #endif
19374 pthread_mutex_init(&p->mutex, 0);
19375 }
19376 break;
19377 }
19378 default: {
@@ -19381,16 +19416,16 @@
19381 (void)SQLITE_MISUSE_BKPT;
19382 return 0;
19383 }
19384 #endif
19385 p = &staticMutexes[iType-2];
19386 #if SQLITE_MUTEX_NREF
19387 p->id = iType;
19388 #endif
19389 break;
19390 }
19391 }
 
 
 
19392 return p;
19393 }
19394
19395
19396 /*
@@ -19398,13 +19433,22 @@
19398 ** allocated mutex. SQLite is careful to deallocate every
19399 ** mutex that it allocates.
19400 */
19401 static void pthreadMutexFree(sqlite3_mutex *p){
19402 assert( p->nRef==0 );
19403 assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE );
19404 pthread_mutex_destroy(&p->mutex);
19405 sqlite3_free(p);
 
 
 
 
 
 
 
 
 
19406 }
19407
19408 /*
19409 ** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
19410 ** to enter a mutex. If another thread is already within the mutex,
@@ -19870,10 +19914,21 @@
19870 # define SQLITE_WIN32_VOLATILE
19871 #else
19872 # define SQLITE_WIN32_VOLATILE volatile
19873 #endif
19874
 
 
 
 
 
 
 
 
 
 
 
19875 #endif /* _OS_WIN_H_ */
19876
19877 /************** End of os_win.h **********************************************/
19878 /************** Continuing where we left off in mutex_w32.c ******************/
19879 #endif
@@ -20045,12 +20100,12 @@
20045 switch( iType ){
20046 case SQLITE_MUTEX_FAST:
20047 case SQLITE_MUTEX_RECURSIVE: {
20048 p = sqlite3MallocZero( sizeof(*p) );
20049 if( p ){
20050 #ifdef SQLITE_DEBUG
20051 p->id = iType;
 
20052 #ifdef SQLITE_WIN32_MUTEX_TRACE_DYNAMIC
20053 p->trace = 1;
20054 #endif
20055 #endif
20056 #if SQLITE_OS_WINRT
@@ -20066,16 +20121,13 @@
20066 if( iType-2<0 || iType-2>=ArraySize(winMutex_staticMutexes) ){
20067 (void)SQLITE_MISUSE_BKPT;
20068 return 0;
20069 }
20070 #endif
20071 assert( iType-2 >= 0 );
20072 assert( iType-2 < ArraySize(winMutex_staticMutexes) );
20073 assert( winMutex_isInit==1 );
20074 p = &winMutex_staticMutexes[iType-2];
20075 #ifdef SQLITE_DEBUG
20076 p->id = iType;
 
20077 #ifdef SQLITE_WIN32_MUTEX_TRACE_STATIC
20078 p->trace = 1;
20079 #endif
20080 #endif
20081 break;
@@ -20090,17 +20142,19 @@
20090 ** allocated mutex. SQLite is careful to deallocate every
20091 ** mutex that it allocates.
20092 */
20093 static void winMutexFree(sqlite3_mutex *p){
20094 assert( p );
20095 #ifdef SQLITE_DEBUG
20096 assert( p->nRef==0 && p->owner==0 );
20097 assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE );
 
 
 
 
 
20098 #endif
20099 assert( winMutex_isInit==1 );
20100 DeleteCriticalSection(&p->mutex);
20101 sqlite3_free(p);
20102 }
20103
20104 /*
20105 ** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
20106 ** to enter a mutex. If another thread is already within the mutex,
@@ -21260,17 +21314,10 @@
21260 etByte flag_rtz; /* True if trailing zeros should be removed */
21261 #endif
21262 PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */
21263 char buf[etBUFSIZE]; /* Conversion buffer */
21264
21265 #ifdef SQLITE_ENABLE_API_ARMOR
21266 if( ap==0 ){
21267 (void)SQLITE_MISUSE_BKPT;
21268 sqlite3StrAccumReset(pAccum);
21269 return;
21270 }
21271 #endif
21272 bufpt = 0;
21273 if( bFlags ){
21274 if( (bArgList = (bFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){
21275 pArgList = va_arg(ap, PrintfArguments*);
21276 }
@@ -22050,11 +22097,11 @@
22050 StrAccum acc;
22051 if( n<=0 ) return zBuf;
22052 #ifdef SQLITE_ENABLE_API_ARMOR
22053 if( zBuf==0 || zFormat==0 ) {
22054 (void)SQLITE_MISUSE_BKPT;
22055 if( zBuf && n>0 ) zBuf[0] = 0;
22056 return zBuf;
22057 }
22058 #endif
22059 sqlite3StrAccumInit(&acc, zBuf, n, 0);
22060 acc.useMalloc = 0;
@@ -22433,11 +22480,11 @@
22433 #endif /* SQLITE_OS_UNIX && defined(SQLITE_MUTEX_PTHREADS) */
22434 /******************************** End Unix Pthreads *************************/
22435
22436
22437 /********************************* Win32 Threads ****************************/
22438 #if SQLITE_OS_WIN && !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_THREADSAFE>0
22439
22440 #define SQLITE_THREADS_IMPLEMENTED 1 /* Prevent the single-thread code below */
22441 #include <process.h>
22442
22443 /* A running thread */
@@ -22526,11 +22573,11 @@
22526 if( rc==WAIT_OBJECT_0 ) *ppOut = p->pResult;
22527 sqlite3_free(p);
22528 return (rc==WAIT_OBJECT_0) ? SQLITE_OK : SQLITE_ERROR;
22529 }
22530
22531 #endif /* SQLITE_OS_WIN && !SQLITE_OS_WINCE && !SQLITE_OS_WINRT */
22532 /******************************** End Win32 Threads *************************/
22533
22534
22535 /********************************* Single-Threaded **************************/
22536 #ifndef SQLITE_THREADS_IMPLEMENTED
@@ -25201,11 +25248,11 @@
25201 #endif
25202 #define UNIXFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */
25203 #define UNIXFILE_DELETE 0x20 /* Delete on close */
25204 #define UNIXFILE_URI 0x40 /* Filename might have query parameters */
25205 #define UNIXFILE_NOLOCK 0x80 /* Do no file locking */
25206 #define UNIXFILE_WARNED 0x0100 /* verifyDbFile() warnings have been issued */
25207
25208 /*
25209 ** Include code that is common to all os_*.c files
25210 */
25211 /************** Include os_common.h in the middle of os_unix.c ***************/
@@ -25872,13 +25919,13 @@
25872 #endif /* SQLITE_LOCK_TRACE */
25873
25874 /*
25875 ** Retry ftruncate() calls that fail due to EINTR
25876 **
25877 ** All calls to ftruncate() within this file should be made through this wrapper.
25878 ** On the Android platform, bypassing the logic below could lead to a corrupt
25879 ** database.
25880 */
25881 static int robust_ftruncate(int h, sqlite3_int64 sz){
25882 int rc;
25883 #ifdef __ANDROID__
25884 /* On Android, ftruncate() always uses 32-bit offsets, even if
@@ -26332,10 +26379,18 @@
26332 if( osClose(h) ){
26333 unixLogErrorAtLine(SQLITE_IOERR_CLOSE, "close",
26334 pFile ? pFile->zPath : 0, lineno);
26335 }
26336 }
 
 
 
 
 
 
 
 
26337
26338 /*
26339 ** Close all file descriptors accumuated in the unixInodeInfo->pUnused list.
26340 */
26341 static void closePendingFds(unixFile *pFile){
@@ -26406,11 +26461,11 @@
26406 ** create a unique name for the file.
26407 */
26408 fd = pFile->h;
26409 rc = osFstat(fd, &statbuf);
26410 if( rc!=0 ){
26411 pFile->lastErrno = errno;
26412 #ifdef EOVERFLOW
26413 if( pFile->lastErrno==EOVERFLOW ) return SQLITE_NOLFS;
26414 #endif
26415 return SQLITE_IOERR;
26416 }
@@ -26427,16 +26482,16 @@
26427 ** the first page of the database, no damage is done.
26428 */
26429 if( statbuf.st_size==0 && (pFile->fsFlags & SQLITE_FSFLAGS_IS_MSDOS)!=0 ){
26430 do{ rc = osWrite(fd, "S", 1); }while( rc<0 && errno==EINTR );
26431 if( rc!=1 ){
26432 pFile->lastErrno = errno;
26433 return SQLITE_IOERR;
26434 }
26435 rc = osFstat(fd, &statbuf);
26436 if( rc!=0 ){
26437 pFile->lastErrno = errno;
26438 return SQLITE_IOERR;
26439 }
26440 }
26441 #endif
26442
@@ -26555,11 +26610,11 @@
26555 lock.l_start = RESERVED_BYTE;
26556 lock.l_len = 1;
26557 lock.l_type = F_WRLCK;
26558 if( osFcntl(pFile->h, F_GETLK, &lock) ){
26559 rc = SQLITE_IOERR_CHECKRESERVEDLOCK;
26560 pFile->lastErrno = errno;
26561 } else if( lock.l_type!=F_UNLCK ){
26562 reserved = 1;
26563 }
26564 }
26565 #endif
@@ -26755,11 +26810,11 @@
26755 lock.l_start = PENDING_BYTE;
26756 if( unixFileLock(pFile, &lock) ){
26757 tErrno = errno;
26758 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
26759 if( rc!=SQLITE_BUSY ){
26760 pFile->lastErrno = tErrno;
26761 }
26762 goto end_lock;
26763 }
26764 }
26765
@@ -26790,11 +26845,11 @@
26790 rc = SQLITE_IOERR_UNLOCK;
26791 }
26792
26793 if( rc ){
26794 if( rc!=SQLITE_BUSY ){
26795 pFile->lastErrno = tErrno;
26796 }
26797 goto end_lock;
26798 }else{
26799 pFile->eFileLock = SHARED_LOCK;
26800 pInode->nLock++;
@@ -26823,11 +26878,11 @@
26823
26824 if( unixFileLock(pFile, &lock) ){
26825 tErrno = errno;
26826 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
26827 if( rc!=SQLITE_BUSY ){
26828 pFile->lastErrno = tErrno;
26829 }
26830 }
26831 }
26832
26833
@@ -26930,11 +26985,10 @@
26930 ** 2: [....W]
26931 ** 3: [RRRRW]
26932 ** 4: [RRRR.]
26933 */
26934 if( eFileLock==SHARED_LOCK ){
26935
26936 #if !defined(__APPLE__) || !SQLITE_ENABLE_LOCKING_STYLE
26937 (void)handleNFSUnlock;
26938 assert( handleNFSUnlock==0 );
26939 #endif
26940 #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
@@ -26948,11 +27002,11 @@
26948 lock.l_len = divSize;
26949 if( unixFileLock(pFile, &lock)==(-1) ){
26950 tErrno = errno;
26951 rc = SQLITE_IOERR_UNLOCK;
26952 if( IS_LOCK_ERROR(rc) ){
26953 pFile->lastErrno = tErrno;
26954 }
26955 goto end_unlock;
26956 }
26957 lock.l_type = F_RDLCK;
26958 lock.l_whence = SEEK_SET;
@@ -26960,11 +27014,11 @@
26960 lock.l_len = divSize;
26961 if( unixFileLock(pFile, &lock)==(-1) ){
26962 tErrno = errno;
26963 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_RDLOCK);
26964 if( IS_LOCK_ERROR(rc) ){
26965 pFile->lastErrno = tErrno;
26966 }
26967 goto end_unlock;
26968 }
26969 lock.l_type = F_UNLCK;
26970 lock.l_whence = SEEK_SET;
@@ -26972,11 +27026,11 @@
26972 lock.l_len = SHARED_SIZE-divSize;
26973 if( unixFileLock(pFile, &lock)==(-1) ){
26974 tErrno = errno;
26975 rc = SQLITE_IOERR_UNLOCK;
26976 if( IS_LOCK_ERROR(rc) ){
26977 pFile->lastErrno = tErrno;
26978 }
26979 goto end_unlock;
26980 }
26981 }else
26982 #endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */
@@ -26991,11 +27045,11 @@
26991 ** indicates that the other process is not following the locking
26992 ** protocol. If this happens, return SQLITE_IOERR_RDLOCK. Returning
26993 ** SQLITE_BUSY would confuse the upper layer (in practice it causes
26994 ** an assert to fail). */
26995 rc = SQLITE_IOERR_RDLOCK;
26996 pFile->lastErrno = errno;
26997 goto end_unlock;
26998 }
26999 }
27000 }
27001 lock.l_type = F_UNLCK;
@@ -27004,11 +27058,11 @@
27004 lock.l_len = 2L; assert( PENDING_BYTE+1==RESERVED_BYTE );
27005 if( unixFileLock(pFile, &lock)==0 ){
27006 pInode->eFileLock = SHARED_LOCK;
27007 }else{
27008 rc = SQLITE_IOERR_UNLOCK;
27009 pFile->lastErrno = errno;
27010 goto end_unlock;
27011 }
27012 }
27013 if( eFileLock==NO_LOCK ){
27014 /* Decrement the shared lock counter. Release the lock using an
@@ -27022,11 +27076,11 @@
27022 lock.l_start = lock.l_len = 0L;
27023 if( unixFileLock(pFile, &lock)==0 ){
27024 pInode->eFileLock = NO_LOCK;
27025 }else{
27026 rc = SQLITE_IOERR_UNLOCK;
27027 pFile->lastErrno = errno;
27028 pInode->eFileLock = NO_LOCK;
27029 pFile->eFileLock = NO_LOCK;
27030 }
27031 }
27032
@@ -27297,11 +27351,11 @@
27297 if( EEXIST == tErrno ){
27298 rc = SQLITE_BUSY;
27299 } else {
27300 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
27301 if( IS_LOCK_ERROR(rc) ){
27302 pFile->lastErrno = tErrno;
27303 }
27304 }
27305 return rc;
27306 }
27307
@@ -27351,11 +27405,11 @@
27351 rc = 0;
27352 if( ENOENT != tErrno ){
27353 rc = SQLITE_IOERR_UNLOCK;
27354 }
27355 if( IS_LOCK_ERROR(rc) ){
27356 pFile->lastErrno = tErrno;
27357 }
27358 return rc;
27359 }
27360 pFile->eFileLock = NO_LOCK;
27361 return SQLITE_OK;
@@ -27438,21 +27492,21 @@
27438 if ( lrc ) {
27439 int tErrno = errno;
27440 /* unlock failed with an error */
27441 lrc = SQLITE_IOERR_UNLOCK;
27442 if( IS_LOCK_ERROR(lrc) ){
27443 pFile->lastErrno = tErrno;
27444 rc = lrc;
27445 }
27446 }
27447 } else {
27448 int tErrno = errno;
27449 reserved = 1;
27450 /* someone else might have it reserved */
27451 lrc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
27452 if( IS_LOCK_ERROR(lrc) ){
27453 pFile->lastErrno = tErrno;
27454 rc = lrc;
27455 }
27456 }
27457 }
27458 OSTRACE(("TEST WR-LOCK %d %d %d (flock)\n", pFile->h, rc, reserved));
@@ -27514,11 +27568,11 @@
27514 if (robust_flock(pFile->h, LOCK_EX | LOCK_NB)) {
27515 int tErrno = errno;
27516 /* didn't get, must be busy */
27517 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
27518 if( IS_LOCK_ERROR(rc) ){
27519 pFile->lastErrno = tErrno;
27520 }
27521 } else {
27522 /* got it, set the type and return ok */
27523 pFile->eFileLock = eFileLock;
27524 }
@@ -27626,11 +27680,11 @@
27626
27627 if( sem_trywait(pSem)==-1 ){
27628 int tErrno = errno;
27629 if( EAGAIN != tErrno ){
27630 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_CHECKRESERVEDLOCK);
27631 pFile->lastErrno = tErrno;
27632 } else {
27633 /* someone else has the lock when we are in NO_LOCK */
27634 reserved = (pFile->eFileLock < SHARED_LOCK);
27635 }
27636 }else{
@@ -27730,11 +27784,11 @@
27730 /* no, really unlock. */
27731 if ( sem_post(pSem)==-1 ) {
27732 int rc, tErrno = errno;
27733 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK);
27734 if( IS_LOCK_ERROR(rc) ){
27735 pFile->lastErrno = tErrno;
27736 }
27737 return rc;
27738 }
27739 pFile->eFileLock = NO_LOCK;
27740 return SQLITE_OK;
@@ -27832,11 +27886,11 @@
27832 #else
27833 rc = sqliteErrorFromPosixError(tErrno,
27834 setLockFlag ? SQLITE_IOERR_LOCK : SQLITE_IOERR_UNLOCK);
27835 #endif /* SQLITE_IGNORE_AFP_LOCK_ERRORS */
27836 if( IS_LOCK_ERROR(rc) ){
27837 pFile->lastErrno = tErrno;
27838 }
27839 return rc;
27840 } else {
27841 return SQLITE_OK;
27842 }
@@ -28015,11 +28069,11 @@
28015 }
28016 /* Drop the temporary PENDING lock */
28017 lrc2 = afpSetLock(context->dbPath, pFile, PENDING_BYTE, 1, 0);
28018
28019 if( IS_LOCK_ERROR(lrc1) ) {
28020 pFile->lastErrno = lrc1Errno;
28021 rc = lrc1;
28022 goto afp_end_lock;
28023 } else if( IS_LOCK_ERROR(lrc2) ){
28024 rc = lrc2;
28025 goto afp_end_lock;
@@ -28302,23 +28356,23 @@
28302 #else
28303 newOffset = lseek(id->h, offset, SEEK_SET);
28304 SimulateIOError( newOffset-- );
28305 if( newOffset!=offset ){
28306 if( newOffset == -1 ){
28307 ((unixFile*)id)->lastErrno = errno;
28308 }else{
28309 ((unixFile*)id)->lastErrno = 0;
28310 }
28311 return -1;
28312 }
28313 got = osRead(id->h, pBuf, cnt);
28314 #endif
28315 if( got==cnt ) break;
28316 if( got<0 ){
28317 if( errno==EINTR ){ got = 1; continue; }
28318 prior = 0;
28319 ((unixFile*)id)->lastErrno = errno;
28320 break;
28321 }else if( got>0 ){
28322 cnt -= got;
28323 offset += got;
28324 prior += got;
@@ -28379,11 +28433,11 @@
28379 return SQLITE_OK;
28380 }else if( got<0 ){
28381 /* lastErrno set by seekAndRead */
28382 return SQLITE_IOERR_READ;
28383 }else{
28384 pFile->lastErrno = 0; /* not a system error */
28385 /* Unread parts of the buffer must be zero-filled */
28386 memset(&((char*)pBuf)[got], 0, amt-got);
28387 return SQLITE_IOERR_SHORT_READ;
28388 }
28389 }
@@ -28408,13 +28462,13 @@
28408 assert( fd>2 );
28409 nBuf &= 0x1ffff;
28410 TIMER_START;
28411
28412 #if defined(USE_PREAD)
28413 do{ rc = osPwrite(fd, pBuf, nBuf, iOff); }while( rc<0 && errno==EINTR );
28414 #elif defined(USE_PREAD64)
28415 do{ rc = osPwrite64(fd, pBuf, nBuf, iOff);}while( rc<0 && errno==EINTR);
28416 #else
28417 do{
28418 i64 iSeek = lseek(fd, iOff, SEEK_SET);
28419 SimulateIOError( iSeek-- );
28420
@@ -28520,11 +28574,11 @@
28520 if( amt>0 ){
28521 if( wrote<0 && pFile->lastErrno!=ENOSPC ){
28522 /* lastErrno set by seekAndWrite */
28523 return SQLITE_IOERR_WRITE;
28524 }else{
28525 pFile->lastErrno = 0; /* not a system error */
28526 return SQLITE_FULL;
28527 }
28528 }
28529
28530 return SQLITE_OK;
@@ -28729,11 +28783,11 @@
28729 assert( pFile );
28730 OSTRACE(("SYNC %-3d\n", pFile->h));
28731 rc = full_fsync(pFile->h, isFullsync, isDataOnly);
28732 SimulateIOError( rc=1 );
28733 if( rc ){
28734 pFile->lastErrno = errno;
28735 return unixLogError(SQLITE_IOERR_FSYNC, "full_fsync", pFile->zPath);
28736 }
28737
28738 /* Also fsync the directory containing the file if the DIRSYNC flag
28739 ** is set. This is a one-time occurrence. Many systems (examples: AIX)
@@ -28773,11 +28827,11 @@
28773 nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk;
28774 }
28775
28776 rc = robust_ftruncate(pFile->h, nByte);
28777 if( rc ){
28778 pFile->lastErrno = errno;
28779 return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
28780 }else{
28781 #ifdef SQLITE_DEBUG
28782 /* If we are doing a normal write to a database file (as opposed to
28783 ** doing a hot-journal rollback or a write to some file other than a
@@ -28813,11 +28867,11 @@
28813 struct stat buf;
28814 assert( id );
28815 rc = osFstat(((unixFile*)id)->h, &buf);
28816 SimulateIOError( rc=1 );
28817 if( rc!=0 ){
28818 ((unixFile*)id)->lastErrno = errno;
28819 return SQLITE_IOERR_FSTAT;
28820 }
28821 *pSize = buf.st_size;
28822
28823 /* When opening a zero-size database, the findInodeInfo() procedure
@@ -28849,11 +28903,13 @@
28849 static int fcntlSizeHint(unixFile *pFile, i64 nByte){
28850 if( pFile->szChunk>0 ){
28851 i64 nSize; /* Required file size */
28852 struct stat buf; /* Used to hold return values of fstat() */
28853
28854 if( osFstat(pFile->h, &buf) ) return SQLITE_IOERR_FSTAT;
 
 
28855
28856 nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
28857 if( nSize>(i64)buf.st_size ){
28858
28859 #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
@@ -28896,11 +28952,11 @@
28896 #if SQLITE_MAX_MMAP_SIZE>0
28897 if( pFile->mmapSizeMax>0 && nByte>pFile->mmapSize ){
28898 int rc;
28899 if( pFile->szChunk<=0 ){
28900 if( robust_ftruncate(pFile->h, nByte) ){
28901 pFile->lastErrno = errno;
28902 return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
28903 }
28904 }
28905
28906 rc = unixMapfile(pFile, nByte);
@@ -28938,11 +28994,11 @@
28938 switch( op ){
28939 case SQLITE_FCNTL_LOCKSTATE: {
28940 *(int*)pArg = pFile->eFileLock;
28941 return SQLITE_OK;
28942 }
28943 case SQLITE_LAST_ERRNO: {
28944 *(int*)pArg = pFile->lastErrno;
28945 return SQLITE_OK;
28946 }
28947 case SQLITE_FCNTL_CHUNK_SIZE: {
28948 pFile->szChunk = *(int *)pArg;
@@ -29007,12 +29063,12 @@
29007 ((unixFile*)id)->dbUpdate = 0;
29008 return SQLITE_OK;
29009 }
29010 #endif
29011 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
29012 case SQLITE_SET_LOCKPROXYFILE:
29013 case SQLITE_GET_LOCKPROXYFILE: {
29014 return proxyFileControl(id,op,pArg);
29015 }
29016 #endif /* SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) */
29017 }
29018 return SQLITE_NOTFOUND;
@@ -29413,10 +29469,13 @@
29413 unixEnterMutex();
29414 pInode = pDbFd->pInode;
29415 pShmNode = pInode->pShmNode;
29416 if( pShmNode==0 ){
29417 struct stat sStat; /* fstat() info for database file */
 
 
 
29418
29419 /* Call fstat() to figure out the permissions on the database file. If
29420 ** a new *-shm file is created, an attempt will be made to create it
29421 ** with the same permissions.
29422 */
@@ -29426,11 +29485,11 @@
29426 }
29427
29428 #ifdef SQLITE_SHM_DIRECTORY
29429 nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 31;
29430 #else
29431 nShmFilename = 6 + (int)strlen(pDbFd->zPath);
29432 #endif
29433 pShmNode = sqlite3_malloc( sizeof(*pShmNode) + nShmFilename );
29434 if( pShmNode==0 ){
29435 rc = SQLITE_NOMEM;
29436 goto shm_open_err;
@@ -29440,11 +29499,11 @@
29440 #ifdef SQLITE_SHM_DIRECTORY
29441 sqlite3_snprintf(nShmFilename, zShmFilename,
29442 SQLITE_SHM_DIRECTORY "/sqlite-shm-%x-%x",
29443 (u32)sStat.st_ino, (u32)sStat.st_dev);
29444 #else
29445 sqlite3_snprintf(nShmFilename, zShmFilename, "%s-shm", pDbFd->zPath);
29446 sqlite3FileSuffix3(pDbFd->zPath, zShmFilename);
29447 #endif
29448 pShmNode->h = -1;
29449 pDbFd->pInode->pShmNode = pShmNode;
29450 pShmNode->pInode = pDbFd->pInode;
@@ -29833,11 +29892,13 @@
29833 ** shared-memory file, too */
29834 unixEnterMutex();
29835 assert( pShmNode->nRef>0 );
29836 pShmNode->nRef--;
29837 if( pShmNode->nRef==0 ){
29838 if( deleteFlag && pShmNode->h>=0 ) osUnlink(pShmNode->zFilename);
 
 
29839 unixShmPurge(pDbFd);
29840 }
29841 unixLeaveMutex();
29842
29843 return SQLITE_OK;
@@ -30110,11 +30171,11 @@
30110 ** methods CLOSE, LOCK, UNLOCK, CKRESLOCK.
30111 **
30112 ** * An I/O method finder function called FINDER that returns a pointer
30113 ** to the METHOD object in the previous bullet.
30114 */
30115 #define IOMETHODS(FINDER, METHOD, VERSION, CLOSE, LOCK, UNLOCK, CKLOCK, SHMMAP) \
30116 static const sqlite3_io_methods METHOD = { \
30117 VERSION, /* iVersion */ \
30118 CLOSE, /* xClose */ \
30119 unixRead, /* xRead */ \
30120 unixWrite, /* xWrite */ \
@@ -30538,11 +30599,11 @@
30538 }
30539 unixLeaveMutex();
30540 }
30541 #endif
30542
30543 pNew->lastErrno = 0;
30544 #if OS_VXWORKS
30545 if( rc!=SQLITE_OK ){
30546 if( h>=0 ) robust_close(pNew, h, __LINE__);
30547 h = -1;
30548 osUnlink(zFilename);
@@ -30986,17 +31047,20 @@
30986 noLock = eType!=SQLITE_OPEN_MAIN_DB;
30987
30988
30989 #if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE
30990 if( fstatfs(fd, &fsInfo) == -1 ){
30991 ((unixFile*)pFile)->lastErrno = errno;
30992 robust_close(p, fd, __LINE__);
30993 return SQLITE_IOERR_ACCESS;
30994 }
30995 if (0 == strncmp("msdos", fsInfo.f_fstypename, 5)) {
30996 ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS;
30997 }
 
 
 
30998 #endif
30999
31000 /* Set up appropriate ctrlFlags */
31001 if( isDelete ) ctrlFlags |= UNIXFILE_DELETE;
31002 if( isReadonly ) ctrlFlags |= UNIXFILE_RDONLY;
@@ -31015,23 +31079,10 @@
31015 /* SQLITE_FORCE_PROXY_LOCKING==1 means force always use proxy, 0 means
31016 ** never use proxy, NULL means use proxy for non-local files only. */
31017 if( envforce!=NULL ){
31018 useProxy = atoi(envforce)>0;
31019 }else{
31020 if( statfs(zPath, &fsInfo) == -1 ){
31021 /* In theory, the close(fd) call is sub-optimal. If the file opened
31022 ** with fd is a database file, and there are other connections open
31023 ** on that file that are currently holding advisory locks on it,
31024 ** then the call to close() will cancel those locks. In practice,
31025 ** we're assuming that statfs() doesn't fail very often. At least
31026 ** not while other file descriptors opened by the same process on
31027 ** the same file are working. */
31028 p->lastErrno = errno;
31029 robust_close(p, fd, __LINE__);
31030 rc = SQLITE_IOERR_ACCESS;
31031 goto open_finished;
31032 }
31033 useProxy = !(fsInfo.f_flags&MNT_LOCAL);
31034 }
31035 if( useProxy ){
31036 rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
31037 if( rc==SQLITE_OK ){
@@ -31453,13 +31504,14 @@
31453 ** Using proxy locks
31454 ** -----------------
31455 **
31456 ** C APIs
31457 **
31458 ** sqlite3_file_control(db, dbname, SQLITE_SET_LOCKPROXYFILE,
31459 ** <proxy_path> | ":auto:");
31460 ** sqlite3_file_control(db, dbname, SQLITE_GET_LOCKPROXYFILE, &<proxy_path>);
 
31461 **
31462 **
31463 ** SQL pragmas
31464 **
31465 ** PRAGMA [database.]lock_proxy_file=<proxy_path> | :auto:
@@ -31548,11 +31600,11 @@
31548 **
31549 ** As mentioned above, when compiled with SQLITE_PREFER_PROXY_LOCKING,
31550 ** setting the environment variable SQLITE_FORCE_PROXY_LOCKING to 1 will
31551 ** force proxy locking to be used for every database file opened, and 0
31552 ** will force automatic proxy locking to be disabled for all database
31553 ** files (explicitly calling the SQLITE_SET_LOCKPROXYFILE pragma or
31554 ** sqlite_file_control API is not affected by SQLITE_FORCE_PROXY_LOCKING).
31555 */
31556
31557 /*
31558 ** Proxy locking is only available on MacOSX
@@ -31569,10 +31621,11 @@
31569 char *conchFilePath; /* Name of the conch file */
31570 unixFile *lockProxy; /* Open proxy lock file */
31571 char *lockProxyPath; /* Name of the proxy lock file */
31572 char *dbPath; /* Name of the open file */
31573 int conchHeld; /* 1 if the conch is held, -1 if lockless */
 
31574 void *oldLockingContext; /* Original lockingcontext to restore on close */
31575 sqlite3_io_methods const *pOldMethod; /* Original I/O methods for close */
31576 };
31577
31578 /*
@@ -31757,14 +31810,14 @@
31757 ** bytes of writable memory.
31758 */
31759 static int proxyGetHostID(unsigned char *pHostID, int *pError){
31760 assert(PROXY_HOSTIDLEN == sizeof(uuid_t));
31761 memset(pHostID, 0, PROXY_HOSTIDLEN);
31762 #if defined(__MAX_OS_X_VERSION_MIN_REQUIRED)\
31763 && __MAC_OS_X_VERSION_MIN_REQUIRED<1050
31764 {
31765 static const struct timespec timeout = {1, 0}; /* 1 sec timeout */
31766 if( gethostuuid(pHostID, &timeout) ){
31767 int err = errno;
31768 if( pError ){
31769 *pError = err;
31770 }
@@ -31875,11 +31928,11 @@
31875 * 10 sec and try again
31876 * 3rd try: break the lock unless the mod time has changed.
31877 */
31878 struct stat buf;
31879 if( osFstat(conchFile->h, &buf) ){
31880 pFile->lastErrno = errno;
31881 return SQLITE_IOERR_LOCK;
31882 }
31883
31884 if( nTries==1 ){
31885 conchModTime = buf.st_mtimespec;
@@ -31895,11 +31948,11 @@
31895
31896 if( nTries==2 ){
31897 char tBuf[PROXY_MAXCONCHLEN];
31898 int len = osPread(conchFile->h, tBuf, PROXY_MAXCONCHLEN, 0);
31899 if( len<0 ){
31900 pFile->lastErrno = errno;
31901 return SQLITE_IOERR_LOCK;
31902 }
31903 if( len>PROXY_PATHINDEX && tBuf[0]==(char)PROXY_CONCHVERSION){
31904 /* don't break the lock if the host id doesn't match */
31905 if( 0!=memcmp(&tBuf[PROXY_HEADERLEN], myHostID, PROXY_HOSTIDLEN) ){
@@ -31915,11 +31968,11 @@
31915
31916 assert( nTries==3 );
31917 if( 0==proxyBreakConchLock(pFile, myHostID) ){
31918 rc = SQLITE_OK;
31919 if( lockType==EXCLUSIVE_LOCK ){
31920 rc = conchFile->pMethod->xLock((sqlite3_file*)conchFile, SHARED_LOCK);
31921 }
31922 if( !rc ){
31923 rc = conchFile->pMethod->xLock((sqlite3_file*)conchFile, lockType);
31924 }
31925 }
@@ -31957,11 +32010,11 @@
31957 OSTRACE(("TAKECONCH %d for %s pid=%d\n", conchFile->h,
31958 (pCtx->lockProxyPath ? pCtx->lockProxyPath : ":auto:"), getpid()));
31959
31960 rc = proxyGetHostID(myHostID, &pError);
31961 if( (rc&0xff)==SQLITE_IOERR ){
31962 pFile->lastErrno = pError;
31963 goto end_takeconch;
31964 }
31965 rc = proxyConchLock(pFile, myHostID, SHARED_LOCK);
31966 if( rc!=SQLITE_OK ){
31967 goto end_takeconch;
@@ -31968,11 +32021,11 @@
31968 }
31969 /* read the existing conch file */
31970 readLen = seekAndRead((unixFile*)conchFile, 0, readBuf, PROXY_MAXCONCHLEN);
31971 if( readLen<0 ){
31972 /* I/O error: lastErrno set by seekAndRead */
31973 pFile->lastErrno = conchFile->lastErrno;
31974 rc = SQLITE_IOERR_READ;
31975 goto end_takeconch;
31976 }else if( readLen<=(PROXY_HEADERLEN+PROXY_HOSTIDLEN) ||
31977 readBuf[0]!=(char)PROXY_CONCHVERSION ){
31978 /* a short read or version format mismatch means we need to create a new
@@ -32041,20 +32094,21 @@
32041 rc = SQLITE_BUSY;
32042 } else {
32043 rc = proxyConchLock(pFile, myHostID, EXCLUSIVE_LOCK);
32044 }
32045 }else{
32046 rc = conchFile->pMethod->xLock((sqlite3_file*)conchFile, EXCLUSIVE_LOCK);
32047 }
32048 if( rc==SQLITE_OK ){
32049 char writeBuffer[PROXY_MAXCONCHLEN];
32050 int writeSize = 0;
32051
32052 writeBuffer[0] = (char)PROXY_CONCHVERSION;
32053 memcpy(&writeBuffer[PROXY_HEADERLEN], myHostID, PROXY_HOSTIDLEN);
32054 if( pCtx->lockProxyPath!=NULL ){
32055 strlcpy(&writeBuffer[PROXY_PATHINDEX], pCtx->lockProxyPath, MAXPATHLEN);
 
32056 }else{
32057 strlcpy(&writeBuffer[PROXY_PATHINDEX], tempLockPath, MAXPATHLEN);
32058 }
32059 writeSize = PROXY_PATHINDEX + strlen(&writeBuffer[PROXY_PATHINDEX]);
32060 robust_ftruncate(conchFile->h, writeSize);
@@ -32262,11 +32316,12 @@
32262 #if defined(__APPLE__)
32263 if( pFile->pMethod == &afpIoMethods ){
32264 /* afp style keeps a reference to the db path in the filePath field
32265 ** of the struct */
32266 assert( (int)strlen((char*)pFile->lockingContext)<=MAXPATHLEN );
32267 strlcpy(dbPath, ((afpLockingContext *)pFile->lockingContext)->dbPath, MAXPATHLEN);
 
32268 } else
32269 #endif
32270 if( pFile->pMethod == &dotlockIoMethods ){
32271 /* dot lock style uses the locking context to store the dot lock
32272 ** file path */
@@ -32375,11 +32430,11 @@
32375 ** This routine handles sqlite3_file_control() calls that are specific
32376 ** to proxy locking.
32377 */
32378 static int proxyFileControl(sqlite3_file *id, int op, void *pArg){
32379 switch( op ){
32380 case SQLITE_GET_LOCKPROXYFILE: {
32381 unixFile *pFile = (unixFile*)id;
32382 if( pFile->pMethod == &proxyIoMethods ){
32383 proxyLockingContext *pCtx = (proxyLockingContext*)pFile->lockingContext;
32384 proxyTakeConch(pFile);
32385 if( pCtx->lockProxyPath ){
@@ -32390,17 +32445,20 @@
32390 } else {
32391 *(const char **)pArg = NULL;
32392 }
32393 return SQLITE_OK;
32394 }
32395 case SQLITE_SET_LOCKPROXYFILE: {
32396 unixFile *pFile = (unixFile*)id;
32397 int rc = SQLITE_OK;
32398 int isProxyStyle = (pFile->pMethod == &proxyIoMethods);
32399 if( pArg==NULL || (const char *)pArg==0 ){
32400 if( isProxyStyle ){
32401 /* turn off proxy locking - not supported */
 
 
 
32402 rc = SQLITE_ERROR /*SQLITE_PROTOCOL? SQLITE_MISUSE?*/;
32403 }else{
32404 /* turn off proxy locking - already off - NOOP */
32405 rc = SQLITE_OK;
32406 }
@@ -33965,10 +34023,27 @@
33965 { "InterlockedCompareExchange", (SYSCALL)InterlockedCompareExchange, 0 },
33966
33967 #define osInterlockedCompareExchange ((LONG(WINAPI*)(LONG \
33968 SQLITE_WIN32_VOLATILE*, LONG,LONG))aSyscall[76].pCurrent)
33969 #endif /* defined(InterlockedCompareExchange) */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33970
33971 }; /* End of the overrideable system calls */
33972
33973 /*
33974 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
@@ -36714,20 +36789,20 @@
36714 int szRegion, /* Size of regions */
36715 int isWrite, /* True to extend file if necessary */
36716 void volatile **pp /* OUT: Mapped memory */
36717 ){
36718 winFile *pDbFd = (winFile*)fd;
36719 winShm *p = pDbFd->pShm;
36720 winShmNode *pShmNode;
36721 int rc = SQLITE_OK;
36722
36723 if( !p ){
36724 rc = winOpenSharedMemory(pDbFd);
36725 if( rc!=SQLITE_OK ) return rc;
36726 p = pDbFd->pShm;
36727 }
36728 pShmNode = p->pShmNode;
36729
36730 sqlite3_mutex_enter(pShmNode->mutex);
36731 assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 );
36732
36733 if( pShmNode->nRegion<=iRegion ){
@@ -38244,10 +38319,26 @@
38244 LARGE_INTEGER i;
38245 osQueryPerformanceCounter(&i);
38246 memcpy(&zBuf[n], &i, sizeof(i));
38247 n += sizeof(i);
38248 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38249 #endif
38250 return n;
38251 }
38252
38253
@@ -38422,11 +38513,11 @@
38422 };
38423 #endif
38424
38425 /* Double-check that the aSyscall[] array has been constructed
38426 ** correctly. See ticket [bb3a86e890c8e96ab] */
38427 assert( ArraySize(aSyscall)==77 );
38428
38429 /* get memory map allocation granularity */
38430 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
38431 #if SQLITE_OS_WINRT
38432 osGetNativeSystemInfo(&winSysInfo);
@@ -52089,10 +52180,13 @@
52089 u8 incrVacuum; /* True if incr-vacuum is enabled */
52090 u8 bDoTruncate; /* True to truncate db on commit */
52091 #endif
52092 u8 inTransaction; /* Transaction state */
52093 u8 max1bytePayload; /* Maximum first byte of cell for a 1-byte payload */
 
 
 
52094 u16 btsFlags; /* Boolean parameters. See BTS_* macros below */
52095 u16 maxLocal; /* Maximum local payload in non-LEAFDATA tables */
52096 u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */
52097 u16 maxLeaf; /* Maximum local payload in a LEAFDATA table */
52098 u16 minLeaf; /* Minimum local payload in a LEAFDATA table */
@@ -52811,10 +52905,16 @@
52811 if( isIndex ){
52812 HashElem *p;
52813 for(p=sqliteHashFirst(&pSchema->idxHash); p; p=sqliteHashNext(p)){
52814 Index *pIdx = (Index *)sqliteHashData(p);
52815 if( pIdx->tnum==(int)iRoot ){
 
 
 
 
 
 
52816 iTab = pIdx->pTable->tnum;
52817 }
52818 }
52819 }else{
52820 iTab = iRoot;
@@ -55035,10 +55135,13 @@
55035 SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve, int iFix){
55036 int rc = SQLITE_OK;
55037 BtShared *pBt = p->pBt;
55038 assert( nReserve>=-1 && nReserve<=255 );
55039 sqlite3BtreeEnter(p);
 
 
 
55040 if( pBt->btsFlags & BTS_PAGESIZE_FIXED ){
55041 sqlite3BtreeLeave(p);
55042 return SQLITE_READONLY;
55043 }
55044 if( nReserve<0 ){
@@ -55064,11 +55167,10 @@
55064 */
55065 SQLITE_PRIVATE int sqlite3BtreeGetPageSize(Btree *p){
55066 return p->pBt->pageSize;
55067 }
55068
55069 #if defined(SQLITE_HAS_CODEC) || defined(SQLITE_DEBUG)
55070 /*
55071 ** This function is similar to sqlite3BtreeGetReserve(), except that it
55072 ** may only be called if it is guaranteed that the b-tree mutex is already
55073 ** held.
55074 **
@@ -55077,28 +55179,36 @@
55077 ** database handle that owns *p is not. In this case if sqlite3BtreeEnter()
55078 ** were to be called, it might collide with some other operation on the
55079 ** database handle that owns *p, causing undefined behavior.
55080 */
55081 SQLITE_PRIVATE int sqlite3BtreeGetReserveNoMutex(Btree *p){
 
55082 assert( sqlite3_mutex_held(p->pBt->mutex) );
55083 return p->pBt->pageSize - p->pBt->usableSize;
 
55084 }
55085 #endif /* SQLITE_HAS_CODEC || SQLITE_DEBUG */
55086
55087 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) || !defined(SQLITE_OMIT_VACUUM)
55088 /*
55089 ** Return the number of bytes of space at the end of every page that
55090 ** are intentually left unused. This is the "reserved" space that is
55091 ** sometimes used by extensions.
 
 
 
 
55092 */
55093 SQLITE_PRIVATE int sqlite3BtreeGetReserve(Btree *p){
55094 int n;
55095 sqlite3BtreeEnter(p);
55096 n = p->pBt->pageSize - p->pBt->usableSize;
 
 
 
55097 sqlite3BtreeLeave(p);
55098 return n;
55099 }
 
55100
55101 /*
55102 ** Set the maximum page count for a database if mxPage is positive.
55103 ** No changes are made if mxPage is 0 or negative.
55104 ** Regardless of the value of mxPage, return the maximum page count.
@@ -55126,11 +55236,10 @@
55126 }
55127 b = (p->pBt->btsFlags & BTS_SECURE_DELETE)!=0;
55128 sqlite3BtreeLeave(p);
55129 return b;
55130 }
55131 #endif /* !defined(SQLITE_OMIT_PAGER_PRAGMAS) || !defined(SQLITE_OMIT_VACUUM) */
55132
55133 /*
55134 ** Change the 'auto-vacuum' property of the database. If the 'autoVacuum'
55135 ** parameter is non-zero, then auto-vacuum mode is enabled. If zero, it
55136 ** is disabled. The default value for the auto-vacuum property is
@@ -62033,11 +62142,11 @@
62033 #ifdef SQLITE_HAS_CODEC
62034 /* Use BtreeGetReserveNoMutex() for the source b-tree, as although it is
62035 ** guaranteed that the shared-mutex is held by this thread, handle
62036 ** p->pSrc may not actually be the owner. */
62037 int nSrcReserve = sqlite3BtreeGetReserveNoMutex(p->pSrc);
62038 int nDestReserve = sqlite3BtreeGetReserve(p->pDest);
62039 #endif
62040 int rc = SQLITE_OK;
62041 i64 iOff;
62042
62043 assert( sqlite3BtreeGetReserveNoMutex(p->pSrc)>=0 );
@@ -67523,11 +67632,12 @@
67523 u32 notUsed;
67524 const unsigned char *aKey = (const unsigned char*)pKey;
67525
67526 if( CORRUPT_DB ) return;
67527 idx = getVarint32(aKey, szHdr);
67528 assert( szHdr<=nKey );
 
67529 while( idx<szHdr ){
67530 idx += getVarint32(aKey+idx, notUsed);
67531 nField++;
67532 }
67533 assert( nField <= pKeyInfo->nField+pKeyInfo->nXField );
@@ -68700,10 +68810,13 @@
68700 sqlite3VdbeMemSetZeroBlob(pCtx->pOut, n);
68701 }
68702 SQLITE_API void sqlite3_result_error_code(sqlite3_context *pCtx, int errCode){
68703 pCtx->isError = errCode;
68704 pCtx->fErrorOrAux = 1;
 
 
 
68705 if( pCtx->pOut->flags & MEM_Null ){
68706 sqlite3VdbeMemSetStr(pCtx->pOut, sqlite3ErrStr(errCode), -1,
68707 SQLITE_UTF8, SQLITE_STATIC);
68708 }
68709 }
@@ -68780,11 +68893,11 @@
68780 ** legacy behavior of returning SQLITE_MISUSE for cases where the
68781 ** previous sqlite3_step() returned something other than a SQLITE_LOCKED
68782 ** or SQLITE_BUSY error.
68783 */
68784 #ifdef SQLITE_OMIT_AUTORESET
68785 if( p->rc==SQLITE_BUSY || p->rc==SQLITE_LOCKED ){
68786 sqlite3_reset((sqlite3_stmt*)p);
68787 }else{
68788 return SQLITE_MISUSE_BKPT;
68789 }
68790 #else
@@ -68826,10 +68939,13 @@
68826 db->nVdbeActive++;
68827 if( p->readOnly==0 ) db->nVdbeWrite++;
68828 if( p->bIsReader ) db->nVdbeRead++;
68829 p->pc = 0;
68830 }
 
 
 
68831 #ifndef SQLITE_OMIT_EXPLAIN
68832 if( p->explain ){
68833 rc = sqlite3VdbeList(p);
68834 }else
68835 #endif /* SQLITE_OMIT_EXPLAIN */
@@ -68870,11 +68986,11 @@
68870 ** were called on statement p.
68871 */
68872 assert( rc==SQLITE_ROW || rc==SQLITE_DONE || rc==SQLITE_ERROR
68873 || rc==SQLITE_BUSY || rc==SQLITE_MISUSE
68874 );
68875 assert( p->rc!=SQLITE_ROW && p->rc!=SQLITE_DONE );
68876 if( p->isPrepareV2 && rc!=SQLITE_ROW && rc!=SQLITE_DONE ){
68877 /* If this statement was prepared using sqlite3_prepare_v2(), and an
68878 ** error has occurred, then return the error code in p->rc to the
68879 ** caller. Set the error code in the database handle to the same value.
68880 */
@@ -76810,16 +76926,21 @@
76810 Table *pTab;
76811 Parse *pParse = 0;
76812 Incrblob *pBlob = 0;
76813
76814 #ifdef SQLITE_ENABLE_API_ARMOR
76815 if( !sqlite3SafetyCheckOk(db) || ppBlob==0 || zTable==0 ){
76816 return SQLITE_MISUSE_BKPT;
76817 }
76818 #endif
76819 flags = !!flags; /* flags = (flags ? 1 : 0); */
76820 *ppBlob = 0;
 
 
 
 
 
 
76821
76822 sqlite3_mutex_enter(db->mutex);
76823
76824 pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob));
76825 if( !pBlob ) goto blob_open_out;
@@ -77029,11 +77150,11 @@
77029 if( p==0 ) return SQLITE_MISUSE_BKPT;
77030 db = p->db;
77031 sqlite3_mutex_enter(db->mutex);
77032 v = (Vdbe*)p->pStmt;
77033
77034 if( n<0 || iOffset<0 || (iOffset+n)>p->nByte ){
77035 /* Request is out of range. Return a transient error. */
77036 rc = SQLITE_ERROR;
77037 }else if( v==0 ){
77038 /* If there is no statement handle, then the blob-handle has
77039 ** already been invalidated. Return SQLITE_ABORT in this case.
@@ -80573,13 +80694,14 @@
80573 */
80574 if( zDb ){
80575 testcase( pNC->ncFlags & NC_PartIdx );
80576 testcase( pNC->ncFlags & NC_IsCheck );
80577 if( (pNC->ncFlags & (NC_PartIdx|NC_IsCheck))!=0 ){
80578 /* Silently ignore database qualifiers inside CHECK constraints and partial
80579 ** indices. Do not raise errors because that might break legacy and
80580 ** because it does not hurt anything to just ignore the database name. */
 
80581 zDb = 0;
80582 }else{
80583 for(i=0; i<db->nDb; i++){
80584 assert( db->aDb[i].zName );
80585 if( sqlite3StrICmp(db->aDb[i].zName,zDb)==0 ){
@@ -80646,11 +80768,12 @@
80646 }
80647 }
80648 if( pMatch ){
80649 pExpr->iTable = pMatch->iCursor;
80650 pExpr->pTab = pMatch->pTab;
80651 assert( (pMatch->jointype & JT_RIGHT)==0 ); /* RIGHT JOIN not (yet) supported */
 
80652 if( (pMatch->jointype & JT_LEFT)!=0 ){
80653 ExprSetProperty(pExpr, EP_CanBeNull);
80654 }
80655 pSchema = pExpr->pTab->pSchema;
80656 }
@@ -80967,11 +81090,12 @@
80967 pExpr->iTable = pItem->iCursor;
80968 pExpr->iColumn = -1;
80969 pExpr->affinity = SQLITE_AFF_INTEGER;
80970 break;
80971 }
80972 #endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY) */
 
80973
80974 /* A lone identifier is the name of a column.
80975 */
80976 case TK_ID: {
80977 return lookupName(pParse, 0, 0, pExpr->u.zToken, pNC, pExpr);
@@ -81032,23 +81156,24 @@
81032 if( pDef->funcFlags & SQLITE_FUNC_UNLIKELY ){
81033 ExprSetProperty(pExpr, EP_Unlikely|EP_Skip);
81034 if( n==2 ){
81035 pExpr->iTable = exprProbability(pList->a[1].pExpr);
81036 if( pExpr->iTable<0 ){
81037 sqlite3ErrorMsg(pParse, "second argument to likelihood() must be a "
81038 "constant between 0.0 and 1.0");
 
81039 pNC->nErr++;
81040 }
81041 }else{
81042 /* EVIDENCE-OF: R-61304-29449 The unlikely(X) function is equivalent to
81043 ** likelihood(X, 0.0625).
81044 ** EVIDENCE-OF: R-01283-11636 The unlikely(X) function is short-hand for
81045 ** likelihood(X,0.0625).
81046 ** EVIDENCE-OF: R-36850-34127 The likely(X) function is short-hand for
81047 ** likelihood(X,0.9375).
81048 ** EVIDENCE-OF: R-53436-40973 The likely(X) function is equivalent to
81049 ** likelihood(X,0.9375). */
81050 /* TUNING: unlikely() probability is 0.0625. likely() is 0.9375 */
81051 pExpr->iTable = pDef->zName[0]=='u' ? 8388608 : 125829120;
81052 }
81053 }
81054 #ifndef SQLITE_OMIT_AUTHORIZATION
@@ -81061,11 +81186,13 @@
81061 }
81062 pExpr->op = TK_NULL;
81063 return WRC_Prune;
81064 }
81065 #endif
81066 if( pDef->funcFlags & SQLITE_FUNC_CONSTANT ) ExprSetProperty(pExpr,EP_Constant);
 
 
81067 }
81068 if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){
81069 sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId);
81070 pNC->nErr++;
81071 is_agg = 0;
@@ -81372,11 +81499,12 @@
81372 if( pItem->u.x.iOrderByCol ){
81373 if( pItem->u.x.iOrderByCol>pEList->nExpr ){
81374 resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr);
81375 return 1;
81376 }
81377 resolveAlias(pParse, pEList, pItem->u.x.iOrderByCol-1, pItem->pExpr, zType,0);
 
81378 }
81379 }
81380 return 0;
81381 }
81382
@@ -81925,13 +82053,13 @@
81925 }
81926 if( op==TK_COLLATE || (op==TK_REGISTER && p->op2==TK_COLLATE) ){
81927 pColl = sqlite3GetCollSeq(pParse, ENC(db), 0, p->u.zToken);
81928 break;
81929 }
81930 if( p->pTab!=0
81931 && (op==TK_AGG_COLUMN || op==TK_COLUMN
81932 || op==TK_REGISTER || op==TK_TRIGGER)
 
81933 ){
81934 /* op==TK_REGISTER && p->pTab!=0 happens when pExpr was originally
81935 ** a TK_COLUMN but was previously evaluated and cached in a register */
81936 int j = p->iColumn;
81937 if( j>=0 ){
@@ -81939,14 +82067,29 @@
81939 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
81940 }
81941 break;
81942 }
81943 if( p->flags & EP_Collate ){
81944 if( ALWAYS(p->pLeft) && (p->pLeft->flags & EP_Collate)!=0 ){
81945 p = p->pLeft;
81946 }else{
81947 p = p->pRight;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81948 }
81949 }else{
81950 break;
81951 }
81952 }
@@ -82148,29 +82291,36 @@
82148 ** Set the Expr.nHeight variable in the structure passed as an
82149 ** argument. An expression with no children, Expr.pList or
82150 ** Expr.pSelect member has a height of 1. Any other expression
82151 ** has a height equal to the maximum height of any other
82152 ** referenced Expr plus one.
 
 
 
82153 */
82154 static void exprSetHeight(Expr *p){
82155 int nHeight = 0;
82156 heightOfExpr(p->pLeft, &nHeight);
82157 heightOfExpr(p->pRight, &nHeight);
82158 if( ExprHasProperty(p, EP_xIsSelect) ){
82159 heightOfSelect(p->x.pSelect, &nHeight);
82160 }else{
82161 heightOfExprList(p->x.pList, &nHeight);
 
82162 }
82163 p->nHeight = nHeight + 1;
82164 }
82165
82166 /*
82167 ** Set the Expr.nHeight variable using the exprSetHeight() function. If
82168 ** the height is greater than the maximum allowed expression depth,
82169 ** leave an error in pParse.
 
 
 
82170 */
82171 SQLITE_PRIVATE void sqlite3ExprSetHeight(Parse *pParse, Expr *p){
82172 exprSetHeight(p);
82173 sqlite3ExprCheckHeight(pParse, p->nHeight);
82174 }
82175
82176 /*
@@ -82180,12 +82330,21 @@
82180 SQLITE_PRIVATE int sqlite3SelectExprHeight(Select *p){
82181 int nHeight = 0;
82182 heightOfSelect(p, &nHeight);
82183 return nHeight;
82184 }
82185 #else
82186 #define exprSetHeight(y)
 
 
 
 
 
 
 
 
 
82187 #endif /* SQLITE_MAX_EXPR_DEPTH>0 */
82188
82189 /*
82190 ** This routine is the core allocator for Expr nodes.
82191 **
@@ -82283,15 +82442,15 @@
82283 sqlite3ExprDelete(db, pLeft);
82284 sqlite3ExprDelete(db, pRight);
82285 }else{
82286 if( pRight ){
82287 pRoot->pRight = pRight;
82288 pRoot->flags |= EP_Collate & pRight->flags;
82289 }
82290 if( pLeft ){
82291 pRoot->pLeft = pLeft;
82292 pRoot->flags |= EP_Collate & pLeft->flags;
82293 }
82294 exprSetHeight(pRoot);
82295 }
82296 }
82297
@@ -82387,11 +82546,11 @@
82387 sqlite3ExprListDelete(db, pList); /* Avoid memory leak when malloc fails */
82388 return 0;
82389 }
82390 pNew->x.pList = pList;
82391 assert( !ExprHasProperty(pNew, EP_xIsSelect) );
82392 sqlite3ExprSetHeight(pParse, pNew);
82393 return pNew;
82394 }
82395
82396 /*
82397 ** Assign a variable number to an expression that encodes a wildcard
@@ -83001,10 +83160,25 @@
83001 sqlite3DbFree(db, pItem->zSpan);
83002 }
83003 sqlite3DbFree(db, pList->a);
83004 sqlite3DbFree(db, pList);
83005 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83006
83007 /*
83008 ** These routines are Walker callbacks used to check expressions to
83009 ** see if they are "constant" for some definition of constant. The
83010 ** Walker.eCode value determines the type of "constant" we are looking
@@ -83042,11 +83216,11 @@
83042 switch( pExpr->op ){
83043 /* Consider functions to be constant if all their arguments are constant
83044 ** and either pWalker->eCode==4 or 5 or the function has the
83045 ** SQLITE_FUNC_CONST flag. */
83046 case TK_FUNCTION:
83047 if( pWalker->eCode>=4 || ExprHasProperty(pExpr,EP_Constant) ){
83048 return WRC_Continue;
83049 }else{
83050 pWalker->eCode = 0;
83051 return WRC_Abort;
83052 }
@@ -84049,11 +84223,12 @@
84049 int i;
84050 int minLru;
84051 int idxLru;
84052 struct yColCache *p;
84053
84054 assert( iReg>0 ); /* Register numbers are always positive */
 
84055 assert( iCol>=-1 && iCol<32768 ); /* Finite column numbers */
84056
84057 /* The SQLITE_ColumnCache flag disables the column cache. This is used
84058 ** for testing only - to verify that SQLite always gets the same answer
84059 ** with and without the column cache.
@@ -89078,11 +89253,11 @@
89078 break;
89079
89080 case SQLITE_NULL:
89081 /* No key specified. Use the key from the main database */
89082 sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
89083 if( nKey>0 || sqlite3BtreeGetReserve(db->aDb[0].pBt)>0 ){
89084 rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
89085 }
89086 break;
89087 }
89088 }
@@ -90044,14 +90219,10 @@
90044 */
90045 SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){
90046 Table *p = 0;
90047 int i;
90048
90049 #ifdef SQLITE_ENABLE_API_ARMOR
90050 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return 0;
90051 #endif
90052
90053 /* All mutexes are required for schema access. Make sure we hold them. */
90054 assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) );
90055 #if SQLITE_USER_AUTHENTICATION
90056 /* Only the admin user is allowed to know that the sqlite_user table
90057 ** exists */
@@ -91467,15 +91638,18 @@
91467 }
91468 pPk->isCovering = 1;
91469 assert( pPk!=0 );
91470 nPk = pPk->nKeyCol;
91471
91472 /* Make sure every column of the PRIMARY KEY is NOT NULL */
91473 for(i=0; i<nPk; i++){
91474 pTab->aCol[pPk->aiColumn[i]].notNull = 1;
 
 
 
 
91475 }
91476 pPk->uniqNotNull = 1;
91477
91478 /* The root page of the PRIMARY KEY is the table root page */
91479 pPk->tnum = pTab->tnum;
91480
91481 /* Update the in-memory representation of all UNIQUE indices by converting
@@ -94706,11 +94880,11 @@
94706 pInClause = sqlite3PExpr(pParse, TK_IN, pWhereRowid, 0, 0);
94707 if( pInClause == 0 ) goto limit_where_cleanup_1;
94708
94709 pInClause->x.pSelect = pSelect;
94710 pInClause->flags |= EP_xIsSelect;
94711 sqlite3ExprSetHeight(pParse, pInClause);
94712 return pInClause;
94713
94714 /* something went wrong. clean up anything allocated. */
94715 limit_where_cleanup_1:
94716 sqlite3SelectDelete(pParse->db, pSelect);
@@ -95648,10 +95822,18 @@
95648 for(z2=z; *z2; len++){
95649 SQLITE_SKIP_UTF8(z2);
95650 }
95651 }
95652 }
 
 
 
 
 
 
 
 
95653 if( argc==3 ){
95654 p2 = sqlite3_value_int(argv[2]);
95655 if( p2<0 ){
95656 p2 = -p2;
95657 negP2 = 1;
@@ -102032,15 +102214,22 @@
102032 # define SQLITE_ENABLE_LOCKING_STYLE 0
102033 # endif
102034 #endif
102035
102036 /***************************************************************************
102037 ** The next block of code, including the PragTyp_XXXX macro definitions and
102038 ** the aPragmaName[] object is composed of generated code. DO NOT EDIT.
102039 **
102040 ** To add new pragmas, edit the code in ../tool/mkpragmatab.tcl and rerun
102041 ** that script. Then copy/paste the output in place of the following:
 
 
 
 
 
 
 
102042 */
102043 #define PragTyp_HEADER_VALUE 0
102044 #define PragTyp_AUTO_VACUUM 1
102045 #define PragTyp_FLAG 2
102046 #define PragTyp_BUSY_TIMEOUT 3
@@ -102271,10 +102460,14 @@
102271 /* iArg: */ 0 },
102272 { /* zName: */ "index_list",
102273 /* ePragTyp: */ PragTyp_INDEX_LIST,
102274 /* ePragFlag: */ PragFlag_NeedSchema,
102275 /* iArg: */ 0 },
 
 
 
 
102276 #endif
102277 #if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
102278 { /* zName: */ "integrity_check",
102279 /* ePragTyp: */ PragTyp_INTEGRITY_CHECK,
102280 /* ePragFlag: */ PragFlag_NeedSchema,
@@ -102487,13 +102680,14 @@
102487 /* ePragTyp: */ PragTyp_FLAG,
102488 /* ePragFlag: */ 0,
102489 /* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode },
102490 #endif
102491 };
102492 /* Number of pragmas: 58 on by default, 71 total. */
102493 /* End of the automatically generated pragma table.
102494 ***************************************************************************/
 
102495
102496 /*
102497 ** Interpret the given string as a safety level. Return 0 for OFF,
102498 ** 1 for ON or NORMAL and 2 for FULL. Return 1 for an empty or
102499 ** unrecognized string argument. The FULL option is disallowed
@@ -102742,10 +102936,11 @@
102742 int lwr, upr, mid = 0; /* Binary search bounds */
102743 int rc; /* return value form SQLITE_FCNTL_PRAGMA */
102744 sqlite3 *db = pParse->db; /* The database connection */
102745 Db *pDb; /* The specific database being pragmaed */
102746 Vdbe *v = sqlite3GetVdbe(pParse); /* Prepared statement */
 
102747
102748 if( v==0 ) return;
102749 sqlite3VdbeRunOnlyOnce(v);
102750 pParse->nMem = 2;
102751
@@ -102819,18 +103014,19 @@
102819 }else{
102820 lwr = mid + 1;
102821 }
102822 }
102823 if( lwr>upr ) goto pragma_out;
 
102824
102825 /* Make sure the database schema is loaded if the pragma requires that */
102826 if( (aPragmaNames[mid].mPragFlag & PragFlag_NeedSchema)!=0 ){
102827 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
102828 }
102829
102830 /* Jump to the appropriate pragma handler */
102831 switch( aPragmaNames[mid].ePragTyp ){
102832
102833 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
102834 /*
102835 ** PRAGMA [database.]default_cache_size
102836 ** PRAGMA [database.]default_cache_size=N
@@ -103405,14 +103601,13 @@
103405 #endif /* SQLITE_OMIT_PAGER_PRAGMAS */
103406
103407 #ifndef SQLITE_OMIT_FLAG_PRAGMAS
103408 case PragTyp_FLAG: {
103409 if( zRight==0 ){
103410 returnSingleInt(pParse, aPragmaNames[mid].zName,
103411 (db->flags & aPragmaNames[mid].iArg)!=0 );
103412 }else{
103413 int mask = aPragmaNames[mid].iArg; /* Mask of bits to set or clear. */
103414 if( db->autoCommit==0 ){
103415 /* Foreign key support may not be enabled or disabled while not
103416 ** in auto-commit mode. */
103417 mask &= ~(SQLITE_ForeignKeys);
103418 }
@@ -103537,24 +103732,34 @@
103537 Index *pIdx;
103538 Table *pTab;
103539 pIdx = sqlite3FindIndex(db, zRight, zDb);
103540 if( pIdx ){
103541 int i;
 
103542 pTab = pIdx->pTable;
103543 sqlite3VdbeSetNumCols(v, 3);
103544 pParse->nMem = 3;
103545 sqlite3CodeVerifySchema(pParse, iDb);
103546 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", SQLITE_STATIC);
103547 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", SQLITE_STATIC);
103548 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", SQLITE_STATIC);
103549 for(i=0; i<pIdx->nKeyCol; i++){
 
 
 
103550 i16 cnum = pIdx->aiColumn[i];
103551 sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
103552 sqlite3VdbeAddOp2(v, OP_Integer, cnum, 2);
103553 assert( pTab->nCol>cnum );
103554 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pTab->aCol[cnum].zName, 0);
103555 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
 
 
 
 
 
 
103556 }
103557 }
103558 }
103559 break;
103560
@@ -103563,21 +103768,26 @@
103563 Table *pTab;
103564 int i;
103565 pTab = sqlite3FindTable(db, zRight, zDb);
103566 if( pTab ){
103567 v = sqlite3GetVdbe(pParse);
103568 sqlite3VdbeSetNumCols(v, 3);
103569 pParse->nMem = 3;
103570 sqlite3CodeVerifySchema(pParse, iDb);
103571 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
103572 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
103573 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", SQLITE_STATIC);
 
 
103574 for(pIdx=pTab->pIndex, i=0; pIdx; pIdx=pIdx->pNext, i++){
 
103575 sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
103576 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0);
103577 sqlite3VdbeAddOp2(v, OP_Integer, IsUniqueIndex(pIdx), 3);
103578 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
 
 
103579 }
103580 }
103581 }
103582 break;
103583
@@ -104143,13 +104353,13 @@
104143 **
104144 ** The user-version is not used internally by SQLite. It may be used by
104145 ** applications for any purpose.
104146 */
104147 case PragTyp_HEADER_VALUE: {
104148 int iCookie = aPragmaNames[mid].iArg; /* Which cookie to read or write */
104149 sqlite3VdbeUsesBtree(v, iDb);
104150 if( zRight && (aPragmaNames[mid].mPragFlag & PragFlag_ReadOnly)==0 ){
104151 /* Write the specified cookie value */
104152 static const VdbeOpList setCookie[] = {
104153 { OP_Transaction, 0, 1, 0}, /* 0 */
104154 { OP_Integer, 0, 1, 0}, /* 1 */
104155 { OP_SetCookie, 0, 0, 1}, /* 2 */
@@ -104265,11 +104475,11 @@
104265 ** if one is set. If no busy handler or a different busy handler is set
104266 ** then 0 is returned. Setting the busy_timeout to 0 or negative
104267 ** disables the timeout.
104268 */
104269 /*case PragTyp_BUSY_TIMEOUT*/ default: {
104270 assert( aPragmaNames[mid].ePragTyp==PragTyp_BUSY_TIMEOUT );
104271 if( zRight ){
104272 sqlite3_busy_timeout(db, sqlite3Atoi(zRight));
104273 }
104274 returnSingleInt(pParse, "timeout", db->busyTimeout);
104275 break;
@@ -108486,11 +108696,14 @@
108486 **
108487 ** Flattening is only attempted if all of the following are true:
108488 **
108489 ** (1) The subquery and the outer query do not both use aggregates.
108490 **
108491 ** (2) The subquery is not an aggregate or the outer query is not a join.
 
 
 
108492 **
108493 ** (3) The subquery is not the right operand of a left outer join
108494 ** (Originally ticket #306. Strengthened by ticket #3300)
108495 **
108496 ** (4) The subquery is not DISTINCT.
@@ -108623,12 +108836,21 @@
108623 assert( pSrc && iFrom>=0 && iFrom<pSrc->nSrc );
108624 pSubitem = &pSrc->a[iFrom];
108625 iParent = pSubitem->iCursor;
108626 pSub = pSubitem->pSelect;
108627 assert( pSub!=0 );
108628 if( isAgg && subqueryIsAgg ) return 0; /* Restriction (1) */
108629 if( subqueryIsAgg && pSrc->nSrc>1 ) return 0; /* Restriction (2) */
 
 
 
 
 
 
 
 
 
108630 pSubSrc = pSub->pSrc;
108631 assert( pSubSrc );
108632 /* Prior to version 3.1.2, when LIMIT and OFFSET had to be simple constants,
108633 ** not arbitrary expressions, we allowed some combining of LIMIT and OFFSET
108634 ** because they could be computed at compile-time. But when LIMIT and OFFSET
@@ -109445,11 +109667,11 @@
109445 #ifndef SQLITE_OMIT_SUBQUERY
109446 Select *pSel = pFrom->pSelect;
109447 /* A sub-query in the FROM clause of a SELECT */
109448 assert( pSel!=0 );
109449 assert( pFrom->pTab==0 );
109450 sqlite3WalkSelect(pWalker, pSel);
109451 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
109452 if( pTab==0 ) return WRC_Abort;
109453 pTab->nRef = 1;
109454 pTab->zName = sqlite3MPrintf(db, "sqlite_sq_%p", (void*)pTab);
109455 while( pSel->pPrior ){ pSel = pSel->pPrior; }
@@ -110044,10 +110266,17 @@
110044 if( pParse->nErr || db->mallocFailed ){
110045 goto select_end;
110046 }
110047 isAgg = (p->selFlags & SF_Aggregate)!=0;
110048 assert( pEList!=0 );
 
 
 
 
 
 
 
110049
110050 /* Begin generating code.
110051 */
110052 v = sqlite3GetVdbe(pParse);
110053 if( v==0 ) goto select_end;
@@ -110789,13 +111018,13 @@
110789 ** Generate a human-readable description of a the Select object.
110790 */
110791 SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){
110792 int n = 0;
110793 pView = sqlite3TreeViewPush(pView, moreToFollow);
110794 sqlite3TreeViewLine(pView, "SELECT%s%s",
110795 ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""),
110796 ((p->selFlags & SF_Aggregate) ? " agg_flag" : "")
110797 );
110798 if( p->pSrc && p->pSrc->nSrc ) n++;
110799 if( p->pWhere ) n++;
110800 if( p->pGroupBy ) n++;
110801 if( p->pHaving ) n++;
@@ -113161,11 +113390,11 @@
113161 ** locked (as there was more than one active statement when the transaction
113162 ** to read the schema was concluded. Unlock it here so that this doesn't
113163 ** cause problems for the call to BtreeSetPageSize() below. */
113164 sqlite3BtreeCommit(pTemp);
113165
113166 nRes = sqlite3BtreeGetReserve(pMain);
113167
113168 /* A VACUUM cannot change the pagesize of an encrypted database. */
113169 #ifdef SQLITE_HAS_CODEC
113170 if( db->nextPagesize ){
113171 extern void sqlite3CodecGetKey(sqlite3*, int, void**, int*);
@@ -114058,11 +114287,13 @@
114058 int rc = SQLITE_OK;
114059 Table *pTab;
114060 char *zErr = 0;
114061
114062 #ifdef SQLITE_ENABLE_API_ARMOR
114063 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
 
 
114064 #endif
114065 sqlite3_mutex_enter(db->mutex);
114066 if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){
114067 sqlite3Error(db, SQLITE_MISUSE);
114068 sqlite3_mutex_leave(db->mutex);
@@ -116547,16 +116778,20 @@
116547 pTable = pSrc->pTab;
116548 pWCEnd = &pWC->a[pWC->nTerm];
116549 pLoop = pLevel->pWLoop;
116550 idxCols = 0;
116551 for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
 
 
 
 
116552 if( pLoop->prereq==0
116553 && (pTerm->wtFlags & TERM_VIRTUAL)==0
116554 && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
116555 && sqlite3ExprIsTableConstant(pTerm->pExpr, pSrc->iCursor) ){
116556 pPartial = sqlite3ExprAnd(pParse->db, pPartial,
116557 sqlite3ExprDup(pParse->db, pTerm->pExpr, 0));
116558 }
116559 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
116560 int iCol = pTerm->u.leftColumn;
116561 Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
116562 testcase( iCol==BMS );
@@ -119630,12 +119865,13 @@
119630 */
119631 static int whereUsablePartialIndex(int iTab, WhereClause *pWC, Expr *pWhere){
119632 int i;
119633 WhereTerm *pTerm;
119634 for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
119635 if( sqlite3ExprImpliesExpr(pTerm->pExpr, pWhere, iTab)
119636 && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
 
119637 ){
119638 return 1;
119639 }
119640 }
119641 return 0;
@@ -124576,11 +124812,11 @@
124576 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, yymsp[-3].minor.yy328 ? TK_NE : TK_EQ, yymsp[-4].minor.yy346.pExpr, pRHS, 0);
124577 }else{
124578 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy346.pExpr, 0, 0);
124579 if( yygotominor.yy346.pExpr ){
124580 yygotominor.yy346.pExpr->x.pList = yymsp[-1].minor.yy14;
124581 sqlite3ExprSetHeight(pParse, yygotominor.yy346.pExpr);
124582 }else{
124583 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy14);
124584 }
124585 if( yymsp[-3].minor.yy328 ) yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy346.pExpr, 0, 0);
124586 }
@@ -124591,12 +124827,12 @@
124591 case 224: /* expr ::= LP select RP */
124592 {
124593 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
124594 if( yygotominor.yy346.pExpr ){
124595 yygotominor.yy346.pExpr->x.pSelect = yymsp[-1].minor.yy3;
124596 ExprSetProperty(yygotominor.yy346.pExpr, EP_xIsSelect);
124597 sqlite3ExprSetHeight(pParse, yygotominor.yy346.pExpr);
124598 }else{
124599 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy3);
124600 }
124601 yygotominor.yy346.zStart = yymsp[-2].minor.yy0.z;
124602 yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
@@ -124605,12 +124841,12 @@
124605 case 225: /* expr ::= expr in_op LP select RP */
124606 {
124607 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy346.pExpr, 0, 0);
124608 if( yygotominor.yy346.pExpr ){
124609 yygotominor.yy346.pExpr->x.pSelect = yymsp[-1].minor.yy3;
124610 ExprSetProperty(yygotominor.yy346.pExpr, EP_xIsSelect);
124611 sqlite3ExprSetHeight(pParse, yygotominor.yy346.pExpr);
124612 }else{
124613 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy3);
124614 }
124615 if( yymsp[-3].minor.yy328 ) yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy346.pExpr, 0, 0);
124616 yygotominor.yy346.zStart = yymsp[-4].minor.yy346.zStart;
@@ -124621,12 +124857,12 @@
124621 {
124622 SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);
124623 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy346.pExpr, 0, 0);
124624 if( yygotominor.yy346.pExpr ){
124625 yygotominor.yy346.pExpr->x.pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
124626 ExprSetProperty(yygotominor.yy346.pExpr, EP_xIsSelect);
124627 sqlite3ExprSetHeight(pParse, yygotominor.yy346.pExpr);
124628 }else{
124629 sqlite3SrcListDelete(pParse->db, pSrc);
124630 }
124631 if( yymsp[-2].minor.yy328 ) yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy346.pExpr, 0, 0);
124632 yygotominor.yy346.zStart = yymsp[-3].minor.yy346.zStart;
@@ -124636,12 +124872,12 @@
124636 case 227: /* expr ::= EXISTS LP select RP */
124637 {
124638 Expr *p = yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
124639 if( p ){
124640 p->x.pSelect = yymsp[-1].minor.yy3;
124641 ExprSetProperty(p, EP_xIsSelect);
124642 sqlite3ExprSetHeight(pParse, p);
124643 }else{
124644 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy3);
124645 }
124646 yygotominor.yy346.zStart = yymsp[-3].minor.yy0.z;
124647 yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
@@ -124650,11 +124886,11 @@
124650 case 228: /* expr ::= CASE case_operand case_exprlist case_else END */
124651 {
124652 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy132, 0, 0);
124653 if( yygotominor.yy346.pExpr ){
124654 yygotominor.yy346.pExpr->x.pList = yymsp[-1].minor.yy132 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy14,yymsp[-1].minor.yy132) : yymsp[-2].minor.yy14;
124655 sqlite3ExprSetHeight(pParse, yygotominor.yy346.pExpr);
124656 }else{
124657 sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy14);
124658 sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy132);
124659 }
124660 yygotominor.yy346.zStart = yymsp[-4].minor.yy0.z;
@@ -125892,14 +126128,11 @@
125892 int lastTokenParsed = -1; /* type of the previous token */
125893 u8 enableLookaside; /* Saved value of db->lookaside.bEnabled */
125894 sqlite3 *db = pParse->db; /* The database connection */
125895 int mxSqlLen; /* Max length of an SQL string */
125896
125897
125898 #ifdef SQLITE_ENABLE_API_ARMOR
125899 if( zSql==0 || pzErrMsg==0 ) return SQLITE_MISUSE_BKPT;
125900 #endif
125901 mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
125902 if( db->nVdbeActive==0 ){
125903 db->u1.isInterrupted = 0;
125904 }
125905 pParse->rc = SQLITE_OK;
@@ -127823,11 +128056,11 @@
127823 sqlite3 *db,
127824 int (*xBusy)(void*,int),
127825 void *pArg
127826 ){
127827 #ifdef SQLITE_ENABLE_API_ARMOR
127828 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE;
127829 #endif
127830 sqlite3_mutex_enter(db->mutex);
127831 db->busyHandler.xFunc = xBusy;
127832 db->busyHandler.pArg = pArg;
127833 db->busyHandler.nBusy = 0;
@@ -129116,10 +129349,13 @@
129116 db->nMaxSorterMmap = 0x7FFFFFFF;
129117 db->flags |= SQLITE_ShortColNames | SQLITE_EnableTrigger | SQLITE_CacheSpill
129118 #if !defined(SQLITE_DEFAULT_AUTOMATIC_INDEX) || SQLITE_DEFAULT_AUTOMATIC_INDEX
129119 | SQLITE_AutoIndex
129120 #endif
 
 
 
129121 #if SQLITE_DEFAULT_FILE_FORMAT<4
129122 | SQLITE_LegacyFileFmt
129123 #endif
129124 #ifdef SQLITE_ENABLE_LOAD_EXTENSION
129125 | SQLITE_LoadExtension
@@ -129551,17 +129787,23 @@
129551 int rc;
129552 char *zErrMsg = 0;
129553 Table *pTab = 0;
129554 Column *pCol = 0;
129555 int iCol = 0;
129556
129557 char const *zDataType = 0;
129558 char const *zCollSeq = 0;
129559 int notnull = 0;
129560 int primarykey = 0;
129561 int autoinc = 0;
129562
 
 
 
 
 
 
 
129563 /* Ensure the database schema has been loaded */
129564 sqlite3_mutex_enter(db->mutex);
129565 sqlite3BtreeEnterAll(db);
129566 rc = sqlite3Init(db, &zErrMsg);
129567 if( SQLITE_OK!=rc ){
@@ -129704,11 +129946,11 @@
129704 rc = SQLITE_NOTFOUND;
129705 }
129706 sqlite3BtreeLeave(pBtree);
129707 }
129708 sqlite3_mutex_leave(db->mutex);
129709 return rc;
129710 }
129711
129712 /*
129713 ** Interface to the testing logic.
129714 */
@@ -130007,10 +130249,39 @@
130007 */
130008 case SQLITE_TESTCTRL_ISINIT: {
130009 if( sqlite3GlobalConfig.isInit==0 ) rc = SQLITE_ERROR;
130010 break;
130011 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130012 }
130013 va_end(ap);
130014 #endif /* SQLITE_OMIT_BUILTIN_TEST */
130015 return rc;
130016 }
@@ -134489,14 +134760,21 @@
134489 ** statement loops through all rows of the %_content table. For a
134490 ** full-text query or docid lookup, the statement retrieves a single
134491 ** row by docid.
134492 */
134493 if( eSearch==FTS3_FULLSCAN_SEARCH ){
134494 zSql = sqlite3_mprintf(
134495 "SELECT %s ORDER BY rowid %s",
134496 p->zReadExprlist, (pCsr->bDesc ? "DESC" : "ASC")
134497 );
 
 
 
 
 
 
 
134498 if( zSql ){
134499 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pCsr->pStmt, 0);
134500 sqlite3_free(zSql);
134501 }else{
134502 rc = SQLITE_NOMEM;
@@ -136981,11 +137259,10 @@
136981 iDocid = pExpr->iDocid;
136982 pIter = pPhrase->doclist.pList;
136983 if( iDocid!=pCsr->iPrevId || pExpr->bEof ){
136984 int rc = SQLITE_OK;
136985 int bDescDoclist = pTab->bDescIdx; /* For DOCID_CMP macro */
136986 int iMul; /* +1 if csr dir matches index dir, else -1 */
136987 int bOr = 0;
136988 u8 bEof = 0;
136989 u8 bTreeEof = 0;
136990 Fts3Expr *p; /* Used to iterate from pExpr to root */
136991 Fts3Expr *pNear; /* Most senior NEAR ancestor (or pExpr) */
@@ -147528,12 +147805,16 @@
147528
147529 /* Now that the shift has been done, check if the initial "..." are
147530 ** required. They are required if (a) this is not the first fragment,
147531 ** or (b) this fragment does not begin at position 0 of its column.
147532 */
147533 if( rc==SQLITE_OK && (iPos>0 || iFragment>0) ){
147534 rc = fts3StringAppend(pOut, zEllipsis, -1);
 
 
 
 
147535 }
147536 if( rc!=SQLITE_OK || iCurrent<iPos ) continue;
147537 }
147538
147539 if( iCurrent>=(iPos+nSnippet) ){
147540
--- 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.8.8. 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.
@@ -276,13 +276,13 @@
276 **
277 ** See also: [sqlite3_libversion()],
278 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
279 ** [sqlite_version()] and [sqlite_source_id()].
280 */
281 #define SQLITE_VERSION "3.8.8"
282 #define SQLITE_VERSION_NUMBER 3008008
283 #define SQLITE_SOURCE_ID "2015-02-25 14:25:31 6d132e7a224ee68b5cefe9222944aac5760ffc20"
284
285 /*
286 ** CAPI3REF: Run-Time Library Version Numbers
287 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
288 **
@@ -1118,13 +1118,13 @@
1118 ** and only needs to be supported when SQLITE_TEST is defined.
1119 **
1120 ** </ul>
1121 */
1122 #define SQLITE_FCNTL_LOCKSTATE 1
1123 #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
1124 #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
1125 #define SQLITE_FCNTL_LAST_ERRNO 4
1126 #define SQLITE_FCNTL_SIZE_HINT 5
1127 #define SQLITE_FCNTL_CHUNK_SIZE 6
1128 #define SQLITE_FCNTL_FILE_POINTER 7
1129 #define SQLITE_FCNTL_SYNC_OMITTED 8
1130 #define SQLITE_FCNTL_WIN32_AV_RETRY 9
@@ -1139,10 +1139,16 @@
1139 #define SQLITE_FCNTL_TRACE 19
1140 #define SQLITE_FCNTL_HAS_MOVED 20
1141 #define SQLITE_FCNTL_SYNC 21
1142 #define SQLITE_FCNTL_COMMIT_PHASETWO 22
1143 #define SQLITE_FCNTL_WIN32_SET_HANDLE 23
1144
1145 /* deprecated names */
1146 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
1147 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
1148 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
1149
1150
1151 /*
1152 ** CAPI3REF: Mutex Handle
1153 **
1154 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -2400,10 +2406,14 @@
2406 /*
2407 ** CAPI3REF: Formatted String Printing Functions
2408 **
2409 ** These routines are work-alikes of the "printf()" family of functions
2410 ** from the standard C library.
2411 ** These routines understand most of the common K&R formatting options,
2412 ** plus some additional non-standard formats, detailed below.
2413 ** Note that some of the more obscure formatting options from recent
2414 ** C-library standards are omitted from this implementation.
2415 **
2416 ** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
2417 ** results into memory obtained from [sqlite3_malloc()].
2418 ** The strings returned by these two routines should be
2419 ** released by [sqlite3_free()]. ^Both routines return a
@@ -2432,11 +2442,11 @@
2442 ** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
2443 **
2444 ** These routines all implement some additional formatting
2445 ** options that are useful for constructing SQL statements.
2446 ** All of the usual printf() formatting options apply. In addition, there
2447 ** is are "%q", "%Q", "%w" and "%z" options.
2448 **
2449 ** ^(The %q option works like %s in that it substitutes a nul-terminated
2450 ** string from the argument list. But %q also doubles every '\'' character.
2451 ** %q is designed for use inside a string literal.)^ By doubling each '\''
2452 ** character it escapes that character and allows it to be inserted into
@@ -2484,10 +2494,16 @@
2494 ** sqlite3_free(zSQL);
2495 ** </pre></blockquote>
2496 **
2497 ** The code above will render a correct SQL statement in the zSQL
2498 ** variable even if the zText variable is a NULL pointer.
2499 **
2500 ** ^(The "%w" formatting option is like "%q" except that it expects to
2501 ** be contained within double-quotes instead of single quotes, and it
2502 ** escapes the double-quote character instead of the single-quote
2503 ** character.)^ The "%w" formatting option is intended for safely inserting
2504 ** table and column names into a constructed SQL statement.
2505 **
2506 ** ^(The "%z" formatting option works like "%s" but with the
2507 ** addition that after the string has been read and copied into
2508 ** the result, [sqlite3_free()] is called on the input string.)^
2509 */
@@ -5234,10 +5250,15 @@
5250 ** successfully. An [error code] is returned otherwise.)^
5251 **
5252 ** ^Shared cache is disabled by default. But this might change in
5253 ** future releases of SQLite. Applications that care about shared
5254 ** cache setting should set it explicitly.
5255 **
5256 ** Note: This method is disabled on MacOS X 10.7 and iOS version 5.0
5257 ** and will always return SQLITE_MISUSE. On those systems,
5258 ** shared cache mode should be enabled per-database connection via
5259 ** [sqlite3_open_v2()] with [SQLITE_OPEN_SHAREDCACHE].
5260 **
5261 ** This interface is threadsafe on processors where writing a
5262 ** 32-bit integer is atomic.
5263 **
5264 ** See Also: [SQLite Shared-Cache Mode]
@@ -6434,11 +6455,12 @@
6455 #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
6456 #define SQLITE_TESTCTRL_VDBE_COVERAGE 21
6457 #define SQLITE_TESTCTRL_BYTEORDER 22
6458 #define SQLITE_TESTCTRL_ISINIT 23
6459 #define SQLITE_TESTCTRL_SORTER_MMAP 24
6460 #define SQLITE_TESTCTRL_IMPOSTER 25
6461 #define SQLITE_TESTCTRL_LAST 25
6462
6463 /*
6464 ** CAPI3REF: SQLite Runtime Status
6465 **
6466 ** ^This interface is used to retrieve runtime status information
@@ -9219,14 +9241,12 @@
9241 SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve, int eFix);
9242 SQLITE_PRIVATE int sqlite3BtreeGetPageSize(Btree*);
9243 SQLITE_PRIVATE int sqlite3BtreeMaxPageCount(Btree*,int);
9244 SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree*);
9245 SQLITE_PRIVATE int sqlite3BtreeSecureDelete(Btree*,int);
9246 SQLITE_PRIVATE int sqlite3BtreeGetOptimalReserve(Btree*);
 
9247 SQLITE_PRIVATE int sqlite3BtreeGetReserveNoMutex(Btree *p);
 
9248 SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum(Btree *, int);
9249 SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *);
9250 SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree*,int);
9251 SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster);
9252 SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree*, int);
@@ -10839,10 +10859,11 @@
10859 struct sqlite3InitInfo { /* Information used during initialization */
10860 int newTnum; /* Rootpage of table being initialized */
10861 u8 iDb; /* Which db file is being initialized */
10862 u8 busy; /* TRUE if currently initializing */
10863 u8 orphanTrigger; /* Last statement is orphaned TEMP trigger */
10864 u8 imposterTable; /* Building an imposter table */
10865 } init;
10866 int nVdbeActive; /* Number of VDBEs currently running */
10867 int nVdbeRead; /* Number of active VDBEs that read or write */
10868 int nVdbeWrite; /* Number of active VDBEs that read and write */
10869 int nVdbeExec; /* Number of nested calls to VdbeExec() */
@@ -11795,12 +11816,18 @@
11816 #define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
11817 #define EP_Static 0x008000 /* Held in memory not obtained from malloc() */
11818 #define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */
11819 #define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
11820 #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
11821 #define EP_ConstFunc 0x080000 /* Node is a SQLITE_FUNC_CONSTANT function */
11822 #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
11823 #define EP_Subquery 0x200000 /* Tree contains a TK_SELECT operator */
11824
11825 /*
11826 ** Combinations of two or more EP_* flags
11827 */
11828 #define EP_Propagate (EP_Collate|EP_Subquery) /* Propagate these bits up tree */
11829
11830 /*
11831 ** These macros can be used to test, set, or clear bits in the
11832 ** Expr.flags field.
11833 */
@@ -12904,10 +12931,11 @@
12931 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*);
12932 SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
12933 SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int);
12934 SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,ExprSpan*);
12935 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*);
12936 SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList*);
12937 SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**);
12938 SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**);
12939 SQLITE_PRIVATE void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
12940 SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3*);
12941 SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3*,int);
@@ -13487,16 +13515,15 @@
13515
13516 SQLITE_PRIVATE void sqlite3MemJournalOpen(sqlite3_file *);
13517 SQLITE_PRIVATE int sqlite3MemJournalSize(void);
13518 SQLITE_PRIVATE int sqlite3IsMemJournal(sqlite3_file *);
13519
13520 SQLITE_PRIVATE void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p);
13521 #if SQLITE_MAX_EXPR_DEPTH>0
 
13522 SQLITE_PRIVATE int sqlite3SelectExprHeight(Select *);
13523 SQLITE_PRIVATE int sqlite3ExprCheckHeight(Parse*, int);
13524 #else
 
13525 #define sqlite3SelectExprHeight(x) 0
13526 #define sqlite3ExprCheckHeight(x,y)
13527 #endif
13528
13529 SQLITE_PRIVATE u32 sqlite3Get4byte(const u8*);
@@ -13629,20 +13656,20 @@
13656 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, /* 1x */
13657 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, /* 2x */
13658 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, /* 3x */
13659 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, /* 4x */
13660 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, /* 5x */
13661 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, /* 6x */
13662 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, /* 7x */
13663 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, /* 8x */
13664 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, /* 9x */
13665 160,161,162,163,164,165,166,167,168,169,170,171,140,141,142,175, /* Ax */
13666 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191, /* Bx */
13667 192,129,130,131,132,133,134,135,136,137,202,203,204,205,206,207, /* Cx */
13668 208,145,146,147,148,149,150,151,152,153,218,219,220,221,222,223, /* Dx */
13669 224,225,162,163,164,165,166,167,168,169,234,235,236,237,238,239, /* Ex */
13670 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255, /* Fx */
13671 #endif
13672 };
13673
13674 /*
13675 ** The following 256 byte lookup table is used to support SQLites built-in
@@ -14637,10 +14664,13 @@
14664 ynVar nVar; /* Number of entries in aVar[] */
14665 ynVar nzVar; /* Number of entries in azVar[] */
14666 u32 cacheCtr; /* VdbeCursor row cache generation counter */
14667 int pc; /* The program counter */
14668 int rc; /* Value to return */
14669 #ifdef SQLITE_DEBUG
14670 int rcApp; /* errcode set by sqlite3_result_error_code() */
14671 #endif
14672 u16 nResColumn; /* Number of columns in one row of the result set */
14673 u8 errorAction; /* Recovery action to do in case of an error */
14674 u8 minWriteFileFormat; /* Minimum file format for writable database files */
14675 bft explain:2; /* True if EXPLAIN present on SQL command */
14676 bft inVtabMethod:2; /* See comments above */
@@ -19111,12 +19141,16 @@
19141 pNew->cnt = 0;
19142 }
19143 break;
19144 }
19145 default: {
19146 #ifdef SQLITE_ENABLE_API_ARMOR
19147 if( id-2<0 || id-2>=ArraySize(aStatic) ){
19148 (void)SQLITE_MISUSE_BKPT;
19149 return 0;
19150 }
19151 #endif
19152 pNew = &aStatic[id-2];
19153 pNew->id = id;
19154 break;
19155 }
19156 }
@@ -19127,12 +19161,17 @@
19161 ** This routine deallocates a previously allocated mutex.
19162 */
19163 static void debugMutexFree(sqlite3_mutex *pX){
19164 sqlite3_debug_mutex *p = (sqlite3_debug_mutex*)pX;
19165 assert( p->cnt==0 );
19166 if( p->id==SQLITE_MUTEX_RECURSIVE || p->id==SQLITE_MUTEX_FAST ){
19167 sqlite3_free(p);
19168 }else{
19169 #ifdef SQLITE_ENABLE_API_ARMOR
19170 (void)SQLITE_MISUSE_BKPT;
19171 #endif
19172 }
19173 }
19174
19175 /*
19176 ** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
19177 ** to enter a mutex. If another thread is already within the mutex,
@@ -19239,12 +19278,14 @@
19278 /*
19279 ** Each recursive mutex is an instance of the following structure.
19280 */
19281 struct sqlite3_mutex {
19282 pthread_mutex_t mutex; /* Mutex controlling the lock */
19283 #if SQLITE_MUTEX_NREF || defined(SQLITE_ENABLE_API_ARMOR)
19284 int id; /* Mutex type */
19285 #endif
19286 #if SQLITE_MUTEX_NREF
19287 volatile int nRef; /* Number of entrances */
19288 volatile pthread_t owner; /* Thread that is within this mutex */
19289 int trace; /* True to trace changes */
19290 #endif
19291 };
@@ -19357,22 +19398,16 @@
19398 pthread_mutexattr_init(&recursiveAttr);
19399 pthread_mutexattr_settype(&recursiveAttr, PTHREAD_MUTEX_RECURSIVE);
19400 pthread_mutex_init(&p->mutex, &recursiveAttr);
19401 pthread_mutexattr_destroy(&recursiveAttr);
19402 #endif
 
 
 
19403 }
19404 break;
19405 }
19406 case SQLITE_MUTEX_FAST: {
19407 p = sqlite3MallocZero( sizeof(*p) );
19408 if( p ){
 
 
 
19409 pthread_mutex_init(&p->mutex, 0);
19410 }
19411 break;
19412 }
19413 default: {
@@ -19381,16 +19416,16 @@
19416 (void)SQLITE_MISUSE_BKPT;
19417 return 0;
19418 }
19419 #endif
19420 p = &staticMutexes[iType-2];
 
 
 
19421 break;
19422 }
19423 }
19424 #if SQLITE_MUTEX_NREF || defined(SQLITE_ENABLE_API_ARMOR)
19425 if( p ) p->id = iType;
19426 #endif
19427 return p;
19428 }
19429
19430
19431 /*
@@ -19398,13 +19433,22 @@
19433 ** allocated mutex. SQLite is careful to deallocate every
19434 ** mutex that it allocates.
19435 */
19436 static void pthreadMutexFree(sqlite3_mutex *p){
19437 assert( p->nRef==0 );
19438 #if SQLITE_ENABLE_API_ARMOR
19439 if( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE )
19440 #endif
19441 {
19442 pthread_mutex_destroy(&p->mutex);
19443 sqlite3_free(p);
19444 }
19445 #ifdef SQLITE_ENABLE_API_ARMOR
19446 else{
19447 (void)SQLITE_MISUSE_BKPT;
19448 }
19449 #endif
19450 }
19451
19452 /*
19453 ** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
19454 ** to enter a mutex. If another thread is already within the mutex,
@@ -19870,10 +19914,21 @@
19914 # define SQLITE_WIN32_VOLATILE
19915 #else
19916 # define SQLITE_WIN32_VOLATILE volatile
19917 #endif
19918
19919 /*
19920 ** For some Windows sub-platforms, the _beginthreadex() / _endthreadex()
19921 ** functions are not available (e.g. those not using MSVC, Cygwin, etc).
19922 */
19923 #if SQLITE_OS_WIN && !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && \
19924 SQLITE_THREADSAFE>0 && !defined(__CYGWIN__)
19925 # define SQLITE_OS_WIN_THREADS 1
19926 #else
19927 # define SQLITE_OS_WIN_THREADS 0
19928 #endif
19929
19930 #endif /* _OS_WIN_H_ */
19931
19932 /************** End of os_win.h **********************************************/
19933 /************** Continuing where we left off in mutex_w32.c ******************/
19934 #endif
@@ -20045,12 +20100,12 @@
20100 switch( iType ){
20101 case SQLITE_MUTEX_FAST:
20102 case SQLITE_MUTEX_RECURSIVE: {
20103 p = sqlite3MallocZero( sizeof(*p) );
20104 if( p ){
 
20105 p->id = iType;
20106 #ifdef SQLITE_DEBUG
20107 #ifdef SQLITE_WIN32_MUTEX_TRACE_DYNAMIC
20108 p->trace = 1;
20109 #endif
20110 #endif
20111 #if SQLITE_OS_WINRT
@@ -20066,16 +20121,13 @@
20121 if( iType-2<0 || iType-2>=ArraySize(winMutex_staticMutexes) ){
20122 (void)SQLITE_MISUSE_BKPT;
20123 return 0;
20124 }
20125 #endif
 
 
 
20126 p = &winMutex_staticMutexes[iType-2];
 
20127 p->id = iType;
20128 #ifdef SQLITE_DEBUG
20129 #ifdef SQLITE_WIN32_MUTEX_TRACE_STATIC
20130 p->trace = 1;
20131 #endif
20132 #endif
20133 break;
@@ -20090,17 +20142,19 @@
20142 ** allocated mutex. SQLite is careful to deallocate every
20143 ** mutex that it allocates.
20144 */
20145 static void winMutexFree(sqlite3_mutex *p){
20146 assert( p );
 
20147 assert( p->nRef==0 && p->owner==0 );
20148 if( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE ){
20149 DeleteCriticalSection(&p->mutex);
20150 sqlite3_free(p);
20151 }else{
20152 #ifdef SQLITE_ENABLE_API_ARMOR
20153 (void)SQLITE_MISUSE_BKPT;
20154 #endif
20155 }
 
 
20156 }
20157
20158 /*
20159 ** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
20160 ** to enter a mutex. If another thread is already within the mutex,
@@ -21260,17 +21314,10 @@
21314 etByte flag_rtz; /* True if trailing zeros should be removed */
21315 #endif
21316 PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */
21317 char buf[etBUFSIZE]; /* Conversion buffer */
21318
 
 
 
 
 
 
 
21319 bufpt = 0;
21320 if( bFlags ){
21321 if( (bArgList = (bFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){
21322 pArgList = va_arg(ap, PrintfArguments*);
21323 }
@@ -22050,11 +22097,11 @@
22097 StrAccum acc;
22098 if( n<=0 ) return zBuf;
22099 #ifdef SQLITE_ENABLE_API_ARMOR
22100 if( zBuf==0 || zFormat==0 ) {
22101 (void)SQLITE_MISUSE_BKPT;
22102 if( zBuf ) zBuf[0] = 0;
22103 return zBuf;
22104 }
22105 #endif
22106 sqlite3StrAccumInit(&acc, zBuf, n, 0);
22107 acc.useMalloc = 0;
@@ -22433,11 +22480,11 @@
22480 #endif /* SQLITE_OS_UNIX && defined(SQLITE_MUTEX_PTHREADS) */
22481 /******************************** End Unix Pthreads *************************/
22482
22483
22484 /********************************* Win32 Threads ****************************/
22485 #if SQLITE_OS_WIN_THREADS
22486
22487 #define SQLITE_THREADS_IMPLEMENTED 1 /* Prevent the single-thread code below */
22488 #include <process.h>
22489
22490 /* A running thread */
@@ -22526,11 +22573,11 @@
22573 if( rc==WAIT_OBJECT_0 ) *ppOut = p->pResult;
22574 sqlite3_free(p);
22575 return (rc==WAIT_OBJECT_0) ? SQLITE_OK : SQLITE_ERROR;
22576 }
22577
22578 #endif /* SQLITE_OS_WIN_THREADS */
22579 /******************************** End Win32 Threads *************************/
22580
22581
22582 /********************************* Single-Threaded **************************/
22583 #ifndef SQLITE_THREADS_IMPLEMENTED
@@ -25201,11 +25248,11 @@
25248 #endif
25249 #define UNIXFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */
25250 #define UNIXFILE_DELETE 0x20 /* Delete on close */
25251 #define UNIXFILE_URI 0x40 /* Filename might have query parameters */
25252 #define UNIXFILE_NOLOCK 0x80 /* Do no file locking */
25253 #define UNIXFILE_WARNED 0x0100 /* verifyDbFile() warnings issued */
25254
25255 /*
25256 ** Include code that is common to all os_*.c files
25257 */
25258 /************** Include os_common.h in the middle of os_unix.c ***************/
@@ -25872,13 +25919,13 @@
25919 #endif /* SQLITE_LOCK_TRACE */
25920
25921 /*
25922 ** Retry ftruncate() calls that fail due to EINTR
25923 **
25924 ** All calls to ftruncate() within this file should be made through
25925 ** this wrapper. On the Android platform, bypassing the logic below
25926 ** could lead to a corrupt database.
25927 */
25928 static int robust_ftruncate(int h, sqlite3_int64 sz){
25929 int rc;
25930 #ifdef __ANDROID__
25931 /* On Android, ftruncate() always uses 32-bit offsets, even if
@@ -26332,10 +26379,18 @@
26379 if( osClose(h) ){
26380 unixLogErrorAtLine(SQLITE_IOERR_CLOSE, "close",
26381 pFile ? pFile->zPath : 0, lineno);
26382 }
26383 }
26384
26385 /*
26386 ** Set the pFile->lastErrno. Do this in a subroutine as that provides
26387 ** a convenient place to set a breakpoint.
26388 */
26389 static void storeLastErrno(unixFile *pFile, int error){
26390 pFile->lastErrno = error;
26391 }
26392
26393 /*
26394 ** Close all file descriptors accumuated in the unixInodeInfo->pUnused list.
26395 */
26396 static void closePendingFds(unixFile *pFile){
@@ -26406,11 +26461,11 @@
26461 ** create a unique name for the file.
26462 */
26463 fd = pFile->h;
26464 rc = osFstat(fd, &statbuf);
26465 if( rc!=0 ){
26466 storeLastErrno(pFile, errno);
26467 #ifdef EOVERFLOW
26468 if( pFile->lastErrno==EOVERFLOW ) return SQLITE_NOLFS;
26469 #endif
26470 return SQLITE_IOERR;
26471 }
@@ -26427,16 +26482,16 @@
26482 ** the first page of the database, no damage is done.
26483 */
26484 if( statbuf.st_size==0 && (pFile->fsFlags & SQLITE_FSFLAGS_IS_MSDOS)!=0 ){
26485 do{ rc = osWrite(fd, "S", 1); }while( rc<0 && errno==EINTR );
26486 if( rc!=1 ){
26487 storeLastErrno(pFile, errno);
26488 return SQLITE_IOERR;
26489 }
26490 rc = osFstat(fd, &statbuf);
26491 if( rc!=0 ){
26492 storeLastErrno(pFile, errno);
26493 return SQLITE_IOERR;
26494 }
26495 }
26496 #endif
26497
@@ -26555,11 +26610,11 @@
26610 lock.l_start = RESERVED_BYTE;
26611 lock.l_len = 1;
26612 lock.l_type = F_WRLCK;
26613 if( osFcntl(pFile->h, F_GETLK, &lock) ){
26614 rc = SQLITE_IOERR_CHECKRESERVEDLOCK;
26615 storeLastErrno(pFile, errno);
26616 } else if( lock.l_type!=F_UNLCK ){
26617 reserved = 1;
26618 }
26619 }
26620 #endif
@@ -26755,11 +26810,11 @@
26810 lock.l_start = PENDING_BYTE;
26811 if( unixFileLock(pFile, &lock) ){
26812 tErrno = errno;
26813 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
26814 if( rc!=SQLITE_BUSY ){
26815 storeLastErrno(pFile, tErrno);
26816 }
26817 goto end_lock;
26818 }
26819 }
26820
@@ -26790,11 +26845,11 @@
26845 rc = SQLITE_IOERR_UNLOCK;
26846 }
26847
26848 if( rc ){
26849 if( rc!=SQLITE_BUSY ){
26850 storeLastErrno(pFile, tErrno);
26851 }
26852 goto end_lock;
26853 }else{
26854 pFile->eFileLock = SHARED_LOCK;
26855 pInode->nLock++;
@@ -26823,11 +26878,11 @@
26878
26879 if( unixFileLock(pFile, &lock) ){
26880 tErrno = errno;
26881 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
26882 if( rc!=SQLITE_BUSY ){
26883 storeLastErrno(pFile, tErrno);
26884 }
26885 }
26886 }
26887
26888
@@ -26930,11 +26985,10 @@
26985 ** 2: [....W]
26986 ** 3: [RRRRW]
26987 ** 4: [RRRR.]
26988 */
26989 if( eFileLock==SHARED_LOCK ){
 
26990 #if !defined(__APPLE__) || !SQLITE_ENABLE_LOCKING_STYLE
26991 (void)handleNFSUnlock;
26992 assert( handleNFSUnlock==0 );
26993 #endif
26994 #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
@@ -26948,11 +27002,11 @@
27002 lock.l_len = divSize;
27003 if( unixFileLock(pFile, &lock)==(-1) ){
27004 tErrno = errno;
27005 rc = SQLITE_IOERR_UNLOCK;
27006 if( IS_LOCK_ERROR(rc) ){
27007 storeLastErrno(pFile, tErrno);
27008 }
27009 goto end_unlock;
27010 }
27011 lock.l_type = F_RDLCK;
27012 lock.l_whence = SEEK_SET;
@@ -26960,11 +27014,11 @@
27014 lock.l_len = divSize;
27015 if( unixFileLock(pFile, &lock)==(-1) ){
27016 tErrno = errno;
27017 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_RDLOCK);
27018 if( IS_LOCK_ERROR(rc) ){
27019 storeLastErrno(pFile, tErrno);
27020 }
27021 goto end_unlock;
27022 }
27023 lock.l_type = F_UNLCK;
27024 lock.l_whence = SEEK_SET;
@@ -26972,11 +27026,11 @@
27026 lock.l_len = SHARED_SIZE-divSize;
27027 if( unixFileLock(pFile, &lock)==(-1) ){
27028 tErrno = errno;
27029 rc = SQLITE_IOERR_UNLOCK;
27030 if( IS_LOCK_ERROR(rc) ){
27031 storeLastErrno(pFile, tErrno);
27032 }
27033 goto end_unlock;
27034 }
27035 }else
27036 #endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */
@@ -26991,11 +27045,11 @@
27045 ** indicates that the other process is not following the locking
27046 ** protocol. If this happens, return SQLITE_IOERR_RDLOCK. Returning
27047 ** SQLITE_BUSY would confuse the upper layer (in practice it causes
27048 ** an assert to fail). */
27049 rc = SQLITE_IOERR_RDLOCK;
27050 storeLastErrno(pFile, errno);
27051 goto end_unlock;
27052 }
27053 }
27054 }
27055 lock.l_type = F_UNLCK;
@@ -27004,11 +27058,11 @@
27058 lock.l_len = 2L; assert( PENDING_BYTE+1==RESERVED_BYTE );
27059 if( unixFileLock(pFile, &lock)==0 ){
27060 pInode->eFileLock = SHARED_LOCK;
27061 }else{
27062 rc = SQLITE_IOERR_UNLOCK;
27063 storeLastErrno(pFile, errno);
27064 goto end_unlock;
27065 }
27066 }
27067 if( eFileLock==NO_LOCK ){
27068 /* Decrement the shared lock counter. Release the lock using an
@@ -27022,11 +27076,11 @@
27076 lock.l_start = lock.l_len = 0L;
27077 if( unixFileLock(pFile, &lock)==0 ){
27078 pInode->eFileLock = NO_LOCK;
27079 }else{
27080 rc = SQLITE_IOERR_UNLOCK;
27081 storeLastErrno(pFile, errno);
27082 pInode->eFileLock = NO_LOCK;
27083 pFile->eFileLock = NO_LOCK;
27084 }
27085 }
27086
@@ -27297,11 +27351,11 @@
27351 if( EEXIST == tErrno ){
27352 rc = SQLITE_BUSY;
27353 } else {
27354 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
27355 if( IS_LOCK_ERROR(rc) ){
27356 storeLastErrno(pFile, tErrno);
27357 }
27358 }
27359 return rc;
27360 }
27361
@@ -27351,11 +27405,11 @@
27405 rc = 0;
27406 if( ENOENT != tErrno ){
27407 rc = SQLITE_IOERR_UNLOCK;
27408 }
27409 if( IS_LOCK_ERROR(rc) ){
27410 storeLastErrno(pFile, tErrno);
27411 }
27412 return rc;
27413 }
27414 pFile->eFileLock = NO_LOCK;
27415 return SQLITE_OK;
@@ -27438,21 +27492,21 @@
27492 if ( lrc ) {
27493 int tErrno = errno;
27494 /* unlock failed with an error */
27495 lrc = SQLITE_IOERR_UNLOCK;
27496 if( IS_LOCK_ERROR(lrc) ){
27497 storeLastErrno(pFile, tErrno);
27498 rc = lrc;
27499 }
27500 }
27501 } else {
27502 int tErrno = errno;
27503 reserved = 1;
27504 /* someone else might have it reserved */
27505 lrc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
27506 if( IS_LOCK_ERROR(lrc) ){
27507 storeLastErrno(pFile, tErrno);
27508 rc = lrc;
27509 }
27510 }
27511 }
27512 OSTRACE(("TEST WR-LOCK %d %d %d (flock)\n", pFile->h, rc, reserved));
@@ -27514,11 +27568,11 @@
27568 if (robust_flock(pFile->h, LOCK_EX | LOCK_NB)) {
27569 int tErrno = errno;
27570 /* didn't get, must be busy */
27571 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
27572 if( IS_LOCK_ERROR(rc) ){
27573 storeLastErrno(pFile, tErrno);
27574 }
27575 } else {
27576 /* got it, set the type and return ok */
27577 pFile->eFileLock = eFileLock;
27578 }
@@ -27626,11 +27680,11 @@
27680
27681 if( sem_trywait(pSem)==-1 ){
27682 int tErrno = errno;
27683 if( EAGAIN != tErrno ){
27684 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_CHECKRESERVEDLOCK);
27685 storeLastErrno(pFile, tErrno);
27686 } else {
27687 /* someone else has the lock when we are in NO_LOCK */
27688 reserved = (pFile->eFileLock < SHARED_LOCK);
27689 }
27690 }else{
@@ -27730,11 +27784,11 @@
27784 /* no, really unlock. */
27785 if ( sem_post(pSem)==-1 ) {
27786 int rc, tErrno = errno;
27787 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK);
27788 if( IS_LOCK_ERROR(rc) ){
27789 storeLastErrno(pFile, tErrno);
27790 }
27791 return rc;
27792 }
27793 pFile->eFileLock = NO_LOCK;
27794 return SQLITE_OK;
@@ -27832,11 +27886,11 @@
27886 #else
27887 rc = sqliteErrorFromPosixError(tErrno,
27888 setLockFlag ? SQLITE_IOERR_LOCK : SQLITE_IOERR_UNLOCK);
27889 #endif /* SQLITE_IGNORE_AFP_LOCK_ERRORS */
27890 if( IS_LOCK_ERROR(rc) ){
27891 storeLastErrno(pFile, tErrno);
27892 }
27893 return rc;
27894 } else {
27895 return SQLITE_OK;
27896 }
@@ -28015,11 +28069,11 @@
28069 }
28070 /* Drop the temporary PENDING lock */
28071 lrc2 = afpSetLock(context->dbPath, pFile, PENDING_BYTE, 1, 0);
28072
28073 if( IS_LOCK_ERROR(lrc1) ) {
28074 storeLastErrno(pFile, lrc1Errno);
28075 rc = lrc1;
28076 goto afp_end_lock;
28077 } else if( IS_LOCK_ERROR(lrc2) ){
28078 rc = lrc2;
28079 goto afp_end_lock;
@@ -28302,23 +28356,23 @@
28356 #else
28357 newOffset = lseek(id->h, offset, SEEK_SET);
28358 SimulateIOError( newOffset-- );
28359 if( newOffset!=offset ){
28360 if( newOffset == -1 ){
28361 storeLastErrno((unixFile*)id, errno);
28362 }else{
28363 storeLastErrno((unixFile*)id, 0);
28364 }
28365 return -1;
28366 }
28367 got = osRead(id->h, pBuf, cnt);
28368 #endif
28369 if( got==cnt ) break;
28370 if( got<0 ){
28371 if( errno==EINTR ){ got = 1; continue; }
28372 prior = 0;
28373 storeLastErrno((unixFile*)id, errno);
28374 break;
28375 }else if( got>0 ){
28376 cnt -= got;
28377 offset += got;
28378 prior += got;
@@ -28379,11 +28433,11 @@
28433 return SQLITE_OK;
28434 }else if( got<0 ){
28435 /* lastErrno set by seekAndRead */
28436 return SQLITE_IOERR_READ;
28437 }else{
28438 storeLastErrno(pFile, 0); /* not a system error */
28439 /* Unread parts of the buffer must be zero-filled */
28440 memset(&((char*)pBuf)[got], 0, amt-got);
28441 return SQLITE_IOERR_SHORT_READ;
28442 }
28443 }
@@ -28408,13 +28462,13 @@
28462 assert( fd>2 );
28463 nBuf &= 0x1ffff;
28464 TIMER_START;
28465
28466 #if defined(USE_PREAD)
28467 do{ rc = (int)osPwrite(fd, pBuf, nBuf, iOff); }while( rc<0 && errno==EINTR );
28468 #elif defined(USE_PREAD64)
28469 do{ rc = (int)osPwrite64(fd, pBuf, nBuf, iOff);}while( rc<0 && errno==EINTR);
28470 #else
28471 do{
28472 i64 iSeek = lseek(fd, iOff, SEEK_SET);
28473 SimulateIOError( iSeek-- );
28474
@@ -28520,11 +28574,11 @@
28574 if( amt>0 ){
28575 if( wrote<0 && pFile->lastErrno!=ENOSPC ){
28576 /* lastErrno set by seekAndWrite */
28577 return SQLITE_IOERR_WRITE;
28578 }else{
28579 storeLastErrno(pFile, 0); /* not a system error */
28580 return SQLITE_FULL;
28581 }
28582 }
28583
28584 return SQLITE_OK;
@@ -28729,11 +28783,11 @@
28783 assert( pFile );
28784 OSTRACE(("SYNC %-3d\n", pFile->h));
28785 rc = full_fsync(pFile->h, isFullsync, isDataOnly);
28786 SimulateIOError( rc=1 );
28787 if( rc ){
28788 storeLastErrno(pFile, errno);
28789 return unixLogError(SQLITE_IOERR_FSYNC, "full_fsync", pFile->zPath);
28790 }
28791
28792 /* Also fsync the directory containing the file if the DIRSYNC flag
28793 ** is set. This is a one-time occurrence. Many systems (examples: AIX)
@@ -28773,11 +28827,11 @@
28827 nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk;
28828 }
28829
28830 rc = robust_ftruncate(pFile->h, nByte);
28831 if( rc ){
28832 storeLastErrno(pFile, errno);
28833 return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
28834 }else{
28835 #ifdef SQLITE_DEBUG
28836 /* If we are doing a normal write to a database file (as opposed to
28837 ** doing a hot-journal rollback or a write to some file other than a
@@ -28813,11 +28867,11 @@
28867 struct stat buf;
28868 assert( id );
28869 rc = osFstat(((unixFile*)id)->h, &buf);
28870 SimulateIOError( rc=1 );
28871 if( rc!=0 ){
28872 storeLastErrno((unixFile*)id, errno);
28873 return SQLITE_IOERR_FSTAT;
28874 }
28875 *pSize = buf.st_size;
28876
28877 /* When opening a zero-size database, the findInodeInfo() procedure
@@ -28849,11 +28903,13 @@
28903 static int fcntlSizeHint(unixFile *pFile, i64 nByte){
28904 if( pFile->szChunk>0 ){
28905 i64 nSize; /* Required file size */
28906 struct stat buf; /* Used to hold return values of fstat() */
28907
28908 if( osFstat(pFile->h, &buf) ){
28909 return SQLITE_IOERR_FSTAT;
28910 }
28911
28912 nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
28913 if( nSize>(i64)buf.st_size ){
28914
28915 #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
@@ -28896,11 +28952,11 @@
28952 #if SQLITE_MAX_MMAP_SIZE>0
28953 if( pFile->mmapSizeMax>0 && nByte>pFile->mmapSize ){
28954 int rc;
28955 if( pFile->szChunk<=0 ){
28956 if( robust_ftruncate(pFile->h, nByte) ){
28957 storeLastErrno(pFile, errno);
28958 return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
28959 }
28960 }
28961
28962 rc = unixMapfile(pFile, nByte);
@@ -28938,11 +28994,11 @@
28994 switch( op ){
28995 case SQLITE_FCNTL_LOCKSTATE: {
28996 *(int*)pArg = pFile->eFileLock;
28997 return SQLITE_OK;
28998 }
28999 case SQLITE_FCNTL_LAST_ERRNO: {
29000 *(int*)pArg = pFile->lastErrno;
29001 return SQLITE_OK;
29002 }
29003 case SQLITE_FCNTL_CHUNK_SIZE: {
29004 pFile->szChunk = *(int *)pArg;
@@ -29007,12 +29063,12 @@
29063 ((unixFile*)id)->dbUpdate = 0;
29064 return SQLITE_OK;
29065 }
29066 #endif
29067 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
29068 case SQLITE_FCNTL_SET_LOCKPROXYFILE:
29069 case SQLITE_FCNTL_GET_LOCKPROXYFILE: {
29070 return proxyFileControl(id,op,pArg);
29071 }
29072 #endif /* SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) */
29073 }
29074 return SQLITE_NOTFOUND;
@@ -29413,10 +29469,13 @@
29469 unixEnterMutex();
29470 pInode = pDbFd->pInode;
29471 pShmNode = pInode->pShmNode;
29472 if( pShmNode==0 ){
29473 struct stat sStat; /* fstat() info for database file */
29474 #ifndef SQLITE_SHM_DIRECTORY
29475 const char *zBasePath = pDbFd->zPath;
29476 #endif
29477
29478 /* Call fstat() to figure out the permissions on the database file. If
29479 ** a new *-shm file is created, an attempt will be made to create it
29480 ** with the same permissions.
29481 */
@@ -29426,11 +29485,11 @@
29485 }
29486
29487 #ifdef SQLITE_SHM_DIRECTORY
29488 nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 31;
29489 #else
29490 nShmFilename = 6 + (int)strlen(zBasePath);
29491 #endif
29492 pShmNode = sqlite3_malloc( sizeof(*pShmNode) + nShmFilename );
29493 if( pShmNode==0 ){
29494 rc = SQLITE_NOMEM;
29495 goto shm_open_err;
@@ -29440,11 +29499,11 @@
29499 #ifdef SQLITE_SHM_DIRECTORY
29500 sqlite3_snprintf(nShmFilename, zShmFilename,
29501 SQLITE_SHM_DIRECTORY "/sqlite-shm-%x-%x",
29502 (u32)sStat.st_ino, (u32)sStat.st_dev);
29503 #else
29504 sqlite3_snprintf(nShmFilename, zShmFilename, "%s-shm", zBasePath);
29505 sqlite3FileSuffix3(pDbFd->zPath, zShmFilename);
29506 #endif
29507 pShmNode->h = -1;
29508 pDbFd->pInode->pShmNode = pShmNode;
29509 pShmNode->pInode = pDbFd->pInode;
@@ -29833,11 +29892,13 @@
29892 ** shared-memory file, too */
29893 unixEnterMutex();
29894 assert( pShmNode->nRef>0 );
29895 pShmNode->nRef--;
29896 if( pShmNode->nRef==0 ){
29897 if( deleteFlag && pShmNode->h>=0 ){
29898 osUnlink(pShmNode->zFilename);
29899 }
29900 unixShmPurge(pDbFd);
29901 }
29902 unixLeaveMutex();
29903
29904 return SQLITE_OK;
@@ -30110,11 +30171,11 @@
30171 ** methods CLOSE, LOCK, UNLOCK, CKRESLOCK.
30172 **
30173 ** * An I/O method finder function called FINDER that returns a pointer
30174 ** to the METHOD object in the previous bullet.
30175 */
30176 #define IOMETHODS(FINDER,METHOD,VERSION,CLOSE,LOCK,UNLOCK,CKLOCK,SHMMAP) \
30177 static const sqlite3_io_methods METHOD = { \
30178 VERSION, /* iVersion */ \
30179 CLOSE, /* xClose */ \
30180 unixRead, /* xRead */ \
30181 unixWrite, /* xWrite */ \
@@ -30538,11 +30599,11 @@
30599 }
30600 unixLeaveMutex();
30601 }
30602 #endif
30603
30604 storeLastErrno(pNew, 0);
30605 #if OS_VXWORKS
30606 if( rc!=SQLITE_OK ){
30607 if( h>=0 ) robust_close(pNew, h, __LINE__);
30608 h = -1;
30609 osUnlink(zFilename);
@@ -30986,17 +31047,20 @@
31047 noLock = eType!=SQLITE_OPEN_MAIN_DB;
31048
31049
31050 #if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE
31051 if( fstatfs(fd, &fsInfo) == -1 ){
31052 storeLastErrno(p, errno);
31053 robust_close(p, fd, __LINE__);
31054 return SQLITE_IOERR_ACCESS;
31055 }
31056 if (0 == strncmp("msdos", fsInfo.f_fstypename, 5)) {
31057 ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS;
31058 }
31059 if (0 == strncmp("exfat", fsInfo.f_fstypename, 5)) {
31060 ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS;
31061 }
31062 #endif
31063
31064 /* Set up appropriate ctrlFlags */
31065 if( isDelete ) ctrlFlags |= UNIXFILE_DELETE;
31066 if( isReadonly ) ctrlFlags |= UNIXFILE_RDONLY;
@@ -31015,23 +31079,10 @@
31079 /* SQLITE_FORCE_PROXY_LOCKING==1 means force always use proxy, 0 means
31080 ** never use proxy, NULL means use proxy for non-local files only. */
31081 if( envforce!=NULL ){
31082 useProxy = atoi(envforce)>0;
31083 }else{
 
 
 
 
 
 
 
 
 
 
 
 
 
31084 useProxy = !(fsInfo.f_flags&MNT_LOCAL);
31085 }
31086 if( useProxy ){
31087 rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
31088 if( rc==SQLITE_OK ){
@@ -31453,13 +31504,14 @@
31504 ** Using proxy locks
31505 ** -----------------
31506 **
31507 ** C APIs
31508 **
31509 ** sqlite3_file_control(db, dbname, SQLITE_FCNTL_SET_LOCKPROXYFILE,
31510 ** <proxy_path> | ":auto:");
31511 ** sqlite3_file_control(db, dbname, SQLITE_FCNTL_GET_LOCKPROXYFILE,
31512 ** &<proxy_path>);
31513 **
31514 **
31515 ** SQL pragmas
31516 **
31517 ** PRAGMA [database.]lock_proxy_file=<proxy_path> | :auto:
@@ -31548,11 +31600,11 @@
31600 **
31601 ** As mentioned above, when compiled with SQLITE_PREFER_PROXY_LOCKING,
31602 ** setting the environment variable SQLITE_FORCE_PROXY_LOCKING to 1 will
31603 ** force proxy locking to be used for every database file opened, and 0
31604 ** will force automatic proxy locking to be disabled for all database
31605 ** files (explicitly calling the SQLITE_FCNTL_SET_LOCKPROXYFILE pragma or
31606 ** sqlite_file_control API is not affected by SQLITE_FORCE_PROXY_LOCKING).
31607 */
31608
31609 /*
31610 ** Proxy locking is only available on MacOSX
@@ -31569,10 +31621,11 @@
31621 char *conchFilePath; /* Name of the conch file */
31622 unixFile *lockProxy; /* Open proxy lock file */
31623 char *lockProxyPath; /* Name of the proxy lock file */
31624 char *dbPath; /* Name of the open file */
31625 int conchHeld; /* 1 if the conch is held, -1 if lockless */
31626 int nFails; /* Number of conch taking failures */
31627 void *oldLockingContext; /* Original lockingcontext to restore on close */
31628 sqlite3_io_methods const *pOldMethod; /* Original I/O methods for close */
31629 };
31630
31631 /*
@@ -31757,14 +31810,14 @@
31810 ** bytes of writable memory.
31811 */
31812 static int proxyGetHostID(unsigned char *pHostID, int *pError){
31813 assert(PROXY_HOSTIDLEN == sizeof(uuid_t));
31814 memset(pHostID, 0, PROXY_HOSTIDLEN);
31815 # if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \
31816 (__IPHONE_OS_VERSION_MIN_REQUIRED > 2000))
31817 {
31818 struct timespec timeout = {1, 0}; /* 1 sec timeout */
31819 if( gethostuuid(pHostID, &timeout) ){
31820 int err = errno;
31821 if( pError ){
31822 *pError = err;
31823 }
@@ -31875,11 +31928,11 @@
31928 * 10 sec and try again
31929 * 3rd try: break the lock unless the mod time has changed.
31930 */
31931 struct stat buf;
31932 if( osFstat(conchFile->h, &buf) ){
31933 storeLastErrno(pFile, errno);
31934 return SQLITE_IOERR_LOCK;
31935 }
31936
31937 if( nTries==1 ){
31938 conchModTime = buf.st_mtimespec;
@@ -31895,11 +31948,11 @@
31948
31949 if( nTries==2 ){
31950 char tBuf[PROXY_MAXCONCHLEN];
31951 int len = osPread(conchFile->h, tBuf, PROXY_MAXCONCHLEN, 0);
31952 if( len<0 ){
31953 storeLastErrno(pFile, errno);
31954 return SQLITE_IOERR_LOCK;
31955 }
31956 if( len>PROXY_PATHINDEX && tBuf[0]==(char)PROXY_CONCHVERSION){
31957 /* don't break the lock if the host id doesn't match */
31958 if( 0!=memcmp(&tBuf[PROXY_HEADERLEN], myHostID, PROXY_HOSTIDLEN) ){
@@ -31915,11 +31968,11 @@
31968
31969 assert( nTries==3 );
31970 if( 0==proxyBreakConchLock(pFile, myHostID) ){
31971 rc = SQLITE_OK;
31972 if( lockType==EXCLUSIVE_LOCK ){
31973 rc = conchFile->pMethod->xLock((sqlite3_file*)conchFile, SHARED_LOCK);
31974 }
31975 if( !rc ){
31976 rc = conchFile->pMethod->xLock((sqlite3_file*)conchFile, lockType);
31977 }
31978 }
@@ -31957,11 +32010,11 @@
32010 OSTRACE(("TAKECONCH %d for %s pid=%d\n", conchFile->h,
32011 (pCtx->lockProxyPath ? pCtx->lockProxyPath : ":auto:"), getpid()));
32012
32013 rc = proxyGetHostID(myHostID, &pError);
32014 if( (rc&0xff)==SQLITE_IOERR ){
32015 storeLastErrno(pFile, pError);
32016 goto end_takeconch;
32017 }
32018 rc = proxyConchLock(pFile, myHostID, SHARED_LOCK);
32019 if( rc!=SQLITE_OK ){
32020 goto end_takeconch;
@@ -31968,11 +32021,11 @@
32021 }
32022 /* read the existing conch file */
32023 readLen = seekAndRead((unixFile*)conchFile, 0, readBuf, PROXY_MAXCONCHLEN);
32024 if( readLen<0 ){
32025 /* I/O error: lastErrno set by seekAndRead */
32026 storeLastErrno(pFile, conchFile->lastErrno);
32027 rc = SQLITE_IOERR_READ;
32028 goto end_takeconch;
32029 }else if( readLen<=(PROXY_HEADERLEN+PROXY_HOSTIDLEN) ||
32030 readBuf[0]!=(char)PROXY_CONCHVERSION ){
32031 /* a short read or version format mismatch means we need to create a new
@@ -32041,20 +32094,21 @@
32094 rc = SQLITE_BUSY;
32095 } else {
32096 rc = proxyConchLock(pFile, myHostID, EXCLUSIVE_LOCK);
32097 }
32098 }else{
32099 rc = proxyConchLock(pFile, myHostID, EXCLUSIVE_LOCK);
32100 }
32101 if( rc==SQLITE_OK ){
32102 char writeBuffer[PROXY_MAXCONCHLEN];
32103 int writeSize = 0;
32104
32105 writeBuffer[0] = (char)PROXY_CONCHVERSION;
32106 memcpy(&writeBuffer[PROXY_HEADERLEN], myHostID, PROXY_HOSTIDLEN);
32107 if( pCtx->lockProxyPath!=NULL ){
32108 strlcpy(&writeBuffer[PROXY_PATHINDEX], pCtx->lockProxyPath,
32109 MAXPATHLEN);
32110 }else{
32111 strlcpy(&writeBuffer[PROXY_PATHINDEX], tempLockPath, MAXPATHLEN);
32112 }
32113 writeSize = PROXY_PATHINDEX + strlen(&writeBuffer[PROXY_PATHINDEX]);
32114 robust_ftruncate(conchFile->h, writeSize);
@@ -32262,11 +32316,12 @@
32316 #if defined(__APPLE__)
32317 if( pFile->pMethod == &afpIoMethods ){
32318 /* afp style keeps a reference to the db path in the filePath field
32319 ** of the struct */
32320 assert( (int)strlen((char*)pFile->lockingContext)<=MAXPATHLEN );
32321 strlcpy(dbPath, ((afpLockingContext *)pFile->lockingContext)->dbPath,
32322 MAXPATHLEN);
32323 } else
32324 #endif
32325 if( pFile->pMethod == &dotlockIoMethods ){
32326 /* dot lock style uses the locking context to store the dot lock
32327 ** file path */
@@ -32375,11 +32430,11 @@
32430 ** This routine handles sqlite3_file_control() calls that are specific
32431 ** to proxy locking.
32432 */
32433 static int proxyFileControl(sqlite3_file *id, int op, void *pArg){
32434 switch( op ){
32435 case SQLITE_FCNTL_GET_LOCKPROXYFILE: {
32436 unixFile *pFile = (unixFile*)id;
32437 if( pFile->pMethod == &proxyIoMethods ){
32438 proxyLockingContext *pCtx = (proxyLockingContext*)pFile->lockingContext;
32439 proxyTakeConch(pFile);
32440 if( pCtx->lockProxyPath ){
@@ -32390,17 +32445,20 @@
32445 } else {
32446 *(const char **)pArg = NULL;
32447 }
32448 return SQLITE_OK;
32449 }
32450 case SQLITE_FCNTL_SET_LOCKPROXYFILE: {
32451 unixFile *pFile = (unixFile*)id;
32452 int rc = SQLITE_OK;
32453 int isProxyStyle = (pFile->pMethod == &proxyIoMethods);
32454 if( pArg==NULL || (const char *)pArg==0 ){
32455 if( isProxyStyle ){
32456 /* turn off proxy locking - not supported. If support is added for
32457 ** switching proxy locking mode off then it will need to fail if
32458 ** the journal mode is WAL mode.
32459 */
32460 rc = SQLITE_ERROR /*SQLITE_PROTOCOL? SQLITE_MISUSE?*/;
32461 }else{
32462 /* turn off proxy locking - already off - NOOP */
32463 rc = SQLITE_OK;
32464 }
@@ -33965,10 +34023,27 @@
34023 { "InterlockedCompareExchange", (SYSCALL)InterlockedCompareExchange, 0 },
34024
34025 #define osInterlockedCompareExchange ((LONG(WINAPI*)(LONG \
34026 SQLITE_WIN32_VOLATILE*, LONG,LONG))aSyscall[76].pCurrent)
34027 #endif /* defined(InterlockedCompareExchange) */
34028
34029 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID
34030 { "UuidCreate", (SYSCALL)UuidCreate, 0 },
34031 #else
34032 { "UuidCreate", (SYSCALL)0, 0 },
34033 #endif
34034
34035 #define osUuidCreate ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[77].pCurrent)
34036
34037 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID
34038 { "UuidCreateSequential", (SYSCALL)UuidCreateSequential, 0 },
34039 #else
34040 { "UuidCreateSequential", (SYSCALL)0, 0 },
34041 #endif
34042
34043 #define osUuidCreateSequential \
34044 ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[78].pCurrent)
34045
34046 }; /* End of the overrideable system calls */
34047
34048 /*
34049 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
@@ -36714,20 +36789,20 @@
36789 int szRegion, /* Size of regions */
36790 int isWrite, /* True to extend file if necessary */
36791 void volatile **pp /* OUT: Mapped memory */
36792 ){
36793 winFile *pDbFd = (winFile*)fd;
36794 winShm *pShm = pDbFd->pShm;
36795 winShmNode *pShmNode;
36796 int rc = SQLITE_OK;
36797
36798 if( !pShm ){
36799 rc = winOpenSharedMemory(pDbFd);
36800 if( rc!=SQLITE_OK ) return rc;
36801 pShm = pDbFd->pShm;
36802 }
36803 pShmNode = pShm->pShmNode;
36804
36805 sqlite3_mutex_enter(pShmNode->mutex);
36806 assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 );
36807
36808 if( pShmNode->nRegion<=iRegion ){
@@ -38244,10 +38319,26 @@
38319 LARGE_INTEGER i;
38320 osQueryPerformanceCounter(&i);
38321 memcpy(&zBuf[n], &i, sizeof(i));
38322 n += sizeof(i);
38323 }
38324 #endif
38325 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID
38326 if( sizeof(UUID)<=nBuf-n ){
38327 UUID id;
38328 memset(&id, 0, sizeof(UUID));
38329 osUuidCreate(&id);
38330 memcpy(zBuf, &id, sizeof(UUID));
38331 n += sizeof(UUID);
38332 }
38333 if( sizeof(UUID)<=nBuf-n ){
38334 UUID id;
38335 memset(&id, 0, sizeof(UUID));
38336 osUuidCreateSequential(&id);
38337 memcpy(zBuf, &id, sizeof(UUID));
38338 n += sizeof(UUID);
38339 }
38340 #endif
38341 return n;
38342 }
38343
38344
@@ -38422,11 +38513,11 @@
38513 };
38514 #endif
38515
38516 /* Double-check that the aSyscall[] array has been constructed
38517 ** correctly. See ticket [bb3a86e890c8e96ab] */
38518 assert( ArraySize(aSyscall)==79 );
38519
38520 /* get memory map allocation granularity */
38521 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
38522 #if SQLITE_OS_WINRT
38523 osGetNativeSystemInfo(&winSysInfo);
@@ -52089,10 +52180,13 @@
52180 u8 incrVacuum; /* True if incr-vacuum is enabled */
52181 u8 bDoTruncate; /* True to truncate db on commit */
52182 #endif
52183 u8 inTransaction; /* Transaction state */
52184 u8 max1bytePayload; /* Maximum first byte of cell for a 1-byte payload */
52185 #ifdef SQLITE_HAS_CODEC
52186 u8 optimalReserve; /* Desired amount of reserved space per page */
52187 #endif
52188 u16 btsFlags; /* Boolean parameters. See BTS_* macros below */
52189 u16 maxLocal; /* Maximum local payload in non-LEAFDATA tables */
52190 u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */
52191 u16 maxLeaf; /* Maximum local payload in a LEAFDATA table */
52192 u16 minLeaf; /* Minimum local payload in a LEAFDATA table */
@@ -52811,10 +52905,16 @@
52905 if( isIndex ){
52906 HashElem *p;
52907 for(p=sqliteHashFirst(&pSchema->idxHash); p; p=sqliteHashNext(p)){
52908 Index *pIdx = (Index *)sqliteHashData(p);
52909 if( pIdx->tnum==(int)iRoot ){
52910 if( iTab ){
52911 /* Two or more indexes share the same root page. There must
52912 ** be imposter tables. So just return true. The assert is not
52913 ** useful in that case. */
52914 return 1;
52915 }
52916 iTab = pIdx->pTable->tnum;
52917 }
52918 }
52919 }else{
52920 iTab = iRoot;
@@ -55035,10 +55135,13 @@
55135 SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve, int iFix){
55136 int rc = SQLITE_OK;
55137 BtShared *pBt = p->pBt;
55138 assert( nReserve>=-1 && nReserve<=255 );
55139 sqlite3BtreeEnter(p);
55140 #if SQLITE_HAS_CODEC
55141 if( nReserve>pBt->optimalReserve ) pBt->optimalReserve = (u8)nReserve;
55142 #endif
55143 if( pBt->btsFlags & BTS_PAGESIZE_FIXED ){
55144 sqlite3BtreeLeave(p);
55145 return SQLITE_READONLY;
55146 }
55147 if( nReserve<0 ){
@@ -55064,11 +55167,10 @@
55167 */
55168 SQLITE_PRIVATE int sqlite3BtreeGetPageSize(Btree *p){
55169 return p->pBt->pageSize;
55170 }
55171
 
55172 /*
55173 ** This function is similar to sqlite3BtreeGetReserve(), except that it
55174 ** may only be called if it is guaranteed that the b-tree mutex is already
55175 ** held.
55176 **
@@ -55077,28 +55179,36 @@
55179 ** database handle that owns *p is not. In this case if sqlite3BtreeEnter()
55180 ** were to be called, it might collide with some other operation on the
55181 ** database handle that owns *p, causing undefined behavior.
55182 */
55183 SQLITE_PRIVATE int sqlite3BtreeGetReserveNoMutex(Btree *p){
55184 int n;
55185 assert( sqlite3_mutex_held(p->pBt->mutex) );
55186 n = p->pBt->pageSize - p->pBt->usableSize;
55187 return n;
55188 }
 
55189
 
55190 /*
55191 ** Return the number of bytes of space at the end of every page that
55192 ** are intentually left unused. This is the "reserved" space that is
55193 ** sometimes used by extensions.
55194 **
55195 ** If SQLITE_HAS_MUTEX is defined then the number returned is the
55196 ** greater of the current reserved space and the maximum requested
55197 ** reserve space.
55198 */
55199 SQLITE_PRIVATE int sqlite3BtreeGetOptimalReserve(Btree *p){
55200 int n;
55201 sqlite3BtreeEnter(p);
55202 n = sqlite3BtreeGetReserveNoMutex(p);
55203 #ifdef SQLITE_HAS_CODEC
55204 if( n<p->pBt->optimalReserve ) n = p->pBt->optimalReserve;
55205 #endif
55206 sqlite3BtreeLeave(p);
55207 return n;
55208 }
55209
55210
55211 /*
55212 ** Set the maximum page count for a database if mxPage is positive.
55213 ** No changes are made if mxPage is 0 or negative.
55214 ** Regardless of the value of mxPage, return the maximum page count.
@@ -55126,11 +55236,10 @@
55236 }
55237 b = (p->pBt->btsFlags & BTS_SECURE_DELETE)!=0;
55238 sqlite3BtreeLeave(p);
55239 return b;
55240 }
 
55241
55242 /*
55243 ** Change the 'auto-vacuum' property of the database. If the 'autoVacuum'
55244 ** parameter is non-zero, then auto-vacuum mode is enabled. If zero, it
55245 ** is disabled. The default value for the auto-vacuum property is
@@ -62033,11 +62142,11 @@
62142 #ifdef SQLITE_HAS_CODEC
62143 /* Use BtreeGetReserveNoMutex() for the source b-tree, as although it is
62144 ** guaranteed that the shared-mutex is held by this thread, handle
62145 ** p->pSrc may not actually be the owner. */
62146 int nSrcReserve = sqlite3BtreeGetReserveNoMutex(p->pSrc);
62147 int nDestReserve = sqlite3BtreeGetOptimalReserve(p->pDest);
62148 #endif
62149 int rc = SQLITE_OK;
62150 i64 iOff;
62151
62152 assert( sqlite3BtreeGetReserveNoMutex(p->pSrc)>=0 );
@@ -67523,11 +67632,12 @@
67632 u32 notUsed;
67633 const unsigned char *aKey = (const unsigned char*)pKey;
67634
67635 if( CORRUPT_DB ) return;
67636 idx = getVarint32(aKey, szHdr);
67637 assert( nKey>=0 );
67638 assert( szHdr<=(u32)nKey );
67639 while( idx<szHdr ){
67640 idx += getVarint32(aKey+idx, notUsed);
67641 nField++;
67642 }
67643 assert( nField <= pKeyInfo->nField+pKeyInfo->nXField );
@@ -68700,10 +68810,13 @@
68810 sqlite3VdbeMemSetZeroBlob(pCtx->pOut, n);
68811 }
68812 SQLITE_API void sqlite3_result_error_code(sqlite3_context *pCtx, int errCode){
68813 pCtx->isError = errCode;
68814 pCtx->fErrorOrAux = 1;
68815 #ifdef SQLITE_DEBUG
68816 pCtx->pVdbe->rcApp = errCode;
68817 #endif
68818 if( pCtx->pOut->flags & MEM_Null ){
68819 sqlite3VdbeMemSetStr(pCtx->pOut, sqlite3ErrStr(errCode), -1,
68820 SQLITE_UTF8, SQLITE_STATIC);
68821 }
68822 }
@@ -68780,11 +68893,11 @@
68893 ** legacy behavior of returning SQLITE_MISUSE for cases where the
68894 ** previous sqlite3_step() returned something other than a SQLITE_LOCKED
68895 ** or SQLITE_BUSY error.
68896 */
68897 #ifdef SQLITE_OMIT_AUTORESET
68898 if( (rc = p->rc&0xff)==SQLITE_BUSY || rc==SQLITE_LOCKED ){
68899 sqlite3_reset((sqlite3_stmt*)p);
68900 }else{
68901 return SQLITE_MISUSE_BKPT;
68902 }
68903 #else
@@ -68826,10 +68939,13 @@
68939 db->nVdbeActive++;
68940 if( p->readOnly==0 ) db->nVdbeWrite++;
68941 if( p->bIsReader ) db->nVdbeRead++;
68942 p->pc = 0;
68943 }
68944 #ifdef SQLITE_DEBUG
68945 p->rcApp = SQLITE_OK;
68946 #endif
68947 #ifndef SQLITE_OMIT_EXPLAIN
68948 if( p->explain ){
68949 rc = sqlite3VdbeList(p);
68950 }else
68951 #endif /* SQLITE_OMIT_EXPLAIN */
@@ -68870,11 +68986,11 @@
68986 ** were called on statement p.
68987 */
68988 assert( rc==SQLITE_ROW || rc==SQLITE_DONE || rc==SQLITE_ERROR
68989 || rc==SQLITE_BUSY || rc==SQLITE_MISUSE
68990 );
68991 assert( (p->rc!=SQLITE_ROW && p->rc!=SQLITE_DONE) || p->rc==p->rcApp );
68992 if( p->isPrepareV2 && rc!=SQLITE_ROW && rc!=SQLITE_DONE ){
68993 /* If this statement was prepared using sqlite3_prepare_v2(), and an
68994 ** error has occurred, then return the error code in p->rc to the
68995 ** caller. Set the error code in the database handle to the same value.
68996 */
@@ -76810,16 +76926,21 @@
76926 Table *pTab;
76927 Parse *pParse = 0;
76928 Incrblob *pBlob = 0;
76929
76930 #ifdef SQLITE_ENABLE_API_ARMOR
76931 if( ppBlob==0 ){
76932 return SQLITE_MISUSE_BKPT;
76933 }
76934 #endif
 
76935 *ppBlob = 0;
76936 #ifdef SQLITE_ENABLE_API_ARMOR
76937 if( !sqlite3SafetyCheckOk(db) || zTable==0 ){
76938 return SQLITE_MISUSE_BKPT;
76939 }
76940 #endif
76941 flags = !!flags; /* flags = (flags ? 1 : 0); */
76942
76943 sqlite3_mutex_enter(db->mutex);
76944
76945 pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob));
76946 if( !pBlob ) goto blob_open_out;
@@ -77029,11 +77150,11 @@
77150 if( p==0 ) return SQLITE_MISUSE_BKPT;
77151 db = p->db;
77152 sqlite3_mutex_enter(db->mutex);
77153 v = (Vdbe*)p->pStmt;
77154
77155 if( n<0 || iOffset<0 || ((sqlite3_int64)iOffset+n)>p->nByte ){
77156 /* Request is out of range. Return a transient error. */
77157 rc = SQLITE_ERROR;
77158 }else if( v==0 ){
77159 /* If there is no statement handle, then the blob-handle has
77160 ** already been invalidated. Return SQLITE_ABORT in this case.
@@ -80573,13 +80694,14 @@
80694 */
80695 if( zDb ){
80696 testcase( pNC->ncFlags & NC_PartIdx );
80697 testcase( pNC->ncFlags & NC_IsCheck );
80698 if( (pNC->ncFlags & (NC_PartIdx|NC_IsCheck))!=0 ){
80699 /* Silently ignore database qualifiers inside CHECK constraints and
80700 ** partial indices. Do not raise errors because that might break
80701 ** legacy and because it does not hurt anything to just ignore the
80702 ** database name. */
80703 zDb = 0;
80704 }else{
80705 for(i=0; i<db->nDb; i++){
80706 assert( db->aDb[i].zName );
80707 if( sqlite3StrICmp(db->aDb[i].zName,zDb)==0 ){
@@ -80646,11 +80768,12 @@
80768 }
80769 }
80770 if( pMatch ){
80771 pExpr->iTable = pMatch->iCursor;
80772 pExpr->pTab = pMatch->pTab;
80773 /* RIGHT JOIN not (yet) supported */
80774 assert( (pMatch->jointype & JT_RIGHT)==0 );
80775 if( (pMatch->jointype & JT_LEFT)!=0 ){
80776 ExprSetProperty(pExpr, EP_CanBeNull);
80777 }
80778 pSchema = pExpr->pTab->pSchema;
80779 }
@@ -80967,11 +81090,12 @@
81090 pExpr->iTable = pItem->iCursor;
81091 pExpr->iColumn = -1;
81092 pExpr->affinity = SQLITE_AFF_INTEGER;
81093 break;
81094 }
81095 #endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT)
81096 && !defined(SQLITE_OMIT_SUBQUERY) */
81097
81098 /* A lone identifier is the name of a column.
81099 */
81100 case TK_ID: {
81101 return lookupName(pParse, 0, 0, pExpr->u.zToken, pNC, pExpr);
@@ -81032,23 +81156,24 @@
81156 if( pDef->funcFlags & SQLITE_FUNC_UNLIKELY ){
81157 ExprSetProperty(pExpr, EP_Unlikely|EP_Skip);
81158 if( n==2 ){
81159 pExpr->iTable = exprProbability(pList->a[1].pExpr);
81160 if( pExpr->iTable<0 ){
81161 sqlite3ErrorMsg(pParse,
81162 "second argument to likelihood() must be a "
81163 "constant between 0.0 and 1.0");
81164 pNC->nErr++;
81165 }
81166 }else{
81167 /* EVIDENCE-OF: R-61304-29449 The unlikely(X) function is
81168 ** equivalent to likelihood(X, 0.0625).
81169 ** EVIDENCE-OF: R-01283-11636 The unlikely(X) function is
81170 ** short-hand for likelihood(X,0.0625).
81171 ** EVIDENCE-OF: R-36850-34127 The likely(X) function is short-hand
81172 ** for likelihood(X,0.9375).
81173 ** EVIDENCE-OF: R-53436-40973 The likely(X) function is equivalent
81174 ** to likelihood(X,0.9375). */
81175 /* TUNING: unlikely() probability is 0.0625. likely() is 0.9375 */
81176 pExpr->iTable = pDef->zName[0]=='u' ? 8388608 : 125829120;
81177 }
81178 }
81179 #ifndef SQLITE_OMIT_AUTHORIZATION
@@ -81061,11 +81186,13 @@
81186 }
81187 pExpr->op = TK_NULL;
81188 return WRC_Prune;
81189 }
81190 #endif
81191 if( pDef->funcFlags & SQLITE_FUNC_CONSTANT ){
81192 ExprSetProperty(pExpr,EP_ConstFunc);
81193 }
81194 }
81195 if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){
81196 sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId);
81197 pNC->nErr++;
81198 is_agg = 0;
@@ -81372,11 +81499,12 @@
81499 if( pItem->u.x.iOrderByCol ){
81500 if( pItem->u.x.iOrderByCol>pEList->nExpr ){
81501 resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr);
81502 return 1;
81503 }
81504 resolveAlias(pParse, pEList, pItem->u.x.iOrderByCol-1, pItem->pExpr,
81505 zType,0);
81506 }
81507 }
81508 return 0;
81509 }
81510
@@ -81925,13 +82053,13 @@
82053 }
82054 if( op==TK_COLLATE || (op==TK_REGISTER && p->op2==TK_COLLATE) ){
82055 pColl = sqlite3GetCollSeq(pParse, ENC(db), 0, p->u.zToken);
82056 break;
82057 }
82058 if( (op==TK_AGG_COLUMN || op==TK_COLUMN
 
82059 || op==TK_REGISTER || op==TK_TRIGGER)
82060 && p->pTab!=0
82061 ){
82062 /* op==TK_REGISTER && p->pTab!=0 happens when pExpr was originally
82063 ** a TK_COLUMN but was previously evaluated and cached in a register */
82064 int j = p->iColumn;
82065 if( j>=0 ){
@@ -81939,14 +82067,29 @@
82067 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
82068 }
82069 break;
82070 }
82071 if( p->flags & EP_Collate ){
82072 if( p->pLeft && (p->pLeft->flags & EP_Collate)!=0 ){
82073 p = p->pLeft;
82074 }else{
82075 Expr *pNext = p->pRight;
82076 /* The Expr.x union is never used at the same time as Expr.pRight */
82077 assert( p->x.pList==0 || p->pRight==0 );
82078 /* p->flags holds EP_Collate and p->pLeft->flags does not. And
82079 ** p->x.pSelect cannot. So if p->x.pLeft exists, it must hold at
82080 ** least one EP_Collate. Thus the following two ALWAYS. */
82081 if( p->x.pList!=0 && ALWAYS(!ExprHasProperty(p, EP_xIsSelect)) ){
82082 int i;
82083 for(i=0; ALWAYS(i<p->x.pList->nExpr); i++){
82084 if( ExprHasProperty(p->x.pList->a[i].pExpr, EP_Collate) ){
82085 pNext = p->x.pList->a[i].pExpr;
82086 break;
82087 }
82088 }
82089 }
82090 p = pNext;
82091 }
82092 }else{
82093 break;
82094 }
82095 }
@@ -82148,29 +82291,36 @@
82291 ** Set the Expr.nHeight variable in the structure passed as an
82292 ** argument. An expression with no children, Expr.pList or
82293 ** Expr.pSelect member has a height of 1. Any other expression
82294 ** has a height equal to the maximum height of any other
82295 ** referenced Expr plus one.
82296 **
82297 ** Also propagate EP_Propagate flags up from Expr.x.pList to Expr.flags,
82298 ** if appropriate.
82299 */
82300 static void exprSetHeight(Expr *p){
82301 int nHeight = 0;
82302 heightOfExpr(p->pLeft, &nHeight);
82303 heightOfExpr(p->pRight, &nHeight);
82304 if( ExprHasProperty(p, EP_xIsSelect) ){
82305 heightOfSelect(p->x.pSelect, &nHeight);
82306 }else if( p->x.pList ){
82307 heightOfExprList(p->x.pList, &nHeight);
82308 p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList);
82309 }
82310 p->nHeight = nHeight + 1;
82311 }
82312
82313 /*
82314 ** Set the Expr.nHeight variable using the exprSetHeight() function. If
82315 ** the height is greater than the maximum allowed expression depth,
82316 ** leave an error in pParse.
82317 **
82318 ** Also propagate all EP_Propagate flags from the Expr.x.pList into
82319 ** Expr.flags.
82320 */
82321 SQLITE_PRIVATE void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p){
82322 exprSetHeight(p);
82323 sqlite3ExprCheckHeight(pParse, p->nHeight);
82324 }
82325
82326 /*
@@ -82180,12 +82330,21 @@
82330 SQLITE_PRIVATE int sqlite3SelectExprHeight(Select *p){
82331 int nHeight = 0;
82332 heightOfSelect(p, &nHeight);
82333 return nHeight;
82334 }
82335 #else /* ABOVE: Height enforcement enabled. BELOW: Height enforcement off */
82336 /*
82337 ** Propagate all EP_Propagate flags from the Expr.x.pList into
82338 ** Expr.flags.
82339 */
82340 SQLITE_PRIVATE void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p){
82341 if( p && p->x.pList && !ExprHasProperty(p, EP_xIsSelect) ){
82342 p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList);
82343 }
82344 }
82345 #define exprSetHeight(y)
82346 #endif /* SQLITE_MAX_EXPR_DEPTH>0 */
82347
82348 /*
82349 ** This routine is the core allocator for Expr nodes.
82350 **
@@ -82283,15 +82442,15 @@
82442 sqlite3ExprDelete(db, pLeft);
82443 sqlite3ExprDelete(db, pRight);
82444 }else{
82445 if( pRight ){
82446 pRoot->pRight = pRight;
82447 pRoot->flags |= EP_Propagate & pRight->flags;
82448 }
82449 if( pLeft ){
82450 pRoot->pLeft = pLeft;
82451 pRoot->flags |= EP_Propagate & pLeft->flags;
82452 }
82453 exprSetHeight(pRoot);
82454 }
82455 }
82456
@@ -82387,11 +82546,11 @@
82546 sqlite3ExprListDelete(db, pList); /* Avoid memory leak when malloc fails */
82547 return 0;
82548 }
82549 pNew->x.pList = pList;
82550 assert( !ExprHasProperty(pNew, EP_xIsSelect) );
82551 sqlite3ExprSetHeightAndFlags(pParse, pNew);
82552 return pNew;
82553 }
82554
82555 /*
82556 ** Assign a variable number to an expression that encodes a wildcard
@@ -83001,10 +83160,25 @@
83160 sqlite3DbFree(db, pItem->zSpan);
83161 }
83162 sqlite3DbFree(db, pList->a);
83163 sqlite3DbFree(db, pList);
83164 }
83165
83166 /*
83167 ** Return the bitwise-OR of all Expr.flags fields in the given
83168 ** ExprList.
83169 */
83170 SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList *pList){
83171 int i;
83172 u32 m = 0;
83173 if( pList ){
83174 for(i=0; i<pList->nExpr; i++){
83175 m |= pList->a[i].pExpr->flags;
83176 }
83177 }
83178 return m;
83179 }
83180
83181 /*
83182 ** These routines are Walker callbacks used to check expressions to
83183 ** see if they are "constant" for some definition of constant. The
83184 ** Walker.eCode value determines the type of "constant" we are looking
@@ -83042,11 +83216,11 @@
83216 switch( pExpr->op ){
83217 /* Consider functions to be constant if all their arguments are constant
83218 ** and either pWalker->eCode==4 or 5 or the function has the
83219 ** SQLITE_FUNC_CONST flag. */
83220 case TK_FUNCTION:
83221 if( pWalker->eCode>=4 || ExprHasProperty(pExpr,EP_ConstFunc) ){
83222 return WRC_Continue;
83223 }else{
83224 pWalker->eCode = 0;
83225 return WRC_Abort;
83226 }
@@ -84049,11 +84223,12 @@
84223 int i;
84224 int minLru;
84225 int idxLru;
84226 struct yColCache *p;
84227
84228 /* Unless an error has occurred, register numbers are always positive. */
84229 assert( iReg>0 || pParse->nErr || pParse->db->mallocFailed );
84230 assert( iCol>=-1 && iCol<32768 ); /* Finite column numbers */
84231
84232 /* The SQLITE_ColumnCache flag disables the column cache. This is used
84233 ** for testing only - to verify that SQLite always gets the same answer
84234 ** with and without the column cache.
@@ -89078,11 +89253,11 @@
89253 break;
89254
89255 case SQLITE_NULL:
89256 /* No key specified. Use the key from the main database */
89257 sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
89258 if( nKey>0 || sqlite3BtreeGetOptimalReserve(db->aDb[0].pBt)>0 ){
89259 rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
89260 }
89261 break;
89262 }
89263 }
@@ -90044,14 +90219,10 @@
90219 */
90220 SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){
90221 Table *p = 0;
90222 int i;
90223
 
 
 
 
90224 /* All mutexes are required for schema access. Make sure we hold them. */
90225 assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) );
90226 #if SQLITE_USER_AUTHENTICATION
90227 /* Only the admin user is allowed to know that the sqlite_user table
90228 ** exists */
@@ -91467,15 +91638,18 @@
91638 }
91639 pPk->isCovering = 1;
91640 assert( pPk!=0 );
91641 nPk = pPk->nKeyCol;
91642
91643 /* Make sure every column of the PRIMARY KEY is NOT NULL. (Except,
91644 ** do not enforce this for imposter tables.) */
91645 if( !db->init.imposterTable ){
91646 for(i=0; i<nPk; i++){
91647 pTab->aCol[pPk->aiColumn[i]].notNull = 1;
91648 }
91649 pPk->uniqNotNull = 1;
91650 }
 
91651
91652 /* The root page of the PRIMARY KEY is the table root page */
91653 pPk->tnum = pTab->tnum;
91654
91655 /* Update the in-memory representation of all UNIQUE indices by converting
@@ -94706,11 +94880,11 @@
94880 pInClause = sqlite3PExpr(pParse, TK_IN, pWhereRowid, 0, 0);
94881 if( pInClause == 0 ) goto limit_where_cleanup_1;
94882
94883 pInClause->x.pSelect = pSelect;
94884 pInClause->flags |= EP_xIsSelect;
94885 sqlite3ExprSetHeightAndFlags(pParse, pInClause);
94886 return pInClause;
94887
94888 /* something went wrong. clean up anything allocated. */
94889 limit_where_cleanup_1:
94890 sqlite3SelectDelete(pParse->db, pSelect);
@@ -95648,10 +95822,18 @@
95822 for(z2=z; *z2; len++){
95823 SQLITE_SKIP_UTF8(z2);
95824 }
95825 }
95826 }
95827 #ifdef SQLITE_SUBSTR_COMPATIBILITY
95828 /* If SUBSTR_COMPATIBILITY is defined then substr(X,0,N) work the same as
95829 ** as substr(X,1,N) - it returns the first N characters of X. This
95830 ** is essentially a back-out of the bug-fix in check-in [5fc125d362df4b8]
95831 ** from 2009-02-02 for compatibility of applications that exploited the
95832 ** old buggy behavior. */
95833 if( p1==0 ) p1 = 1; /* <rdar://problem/6778339> */
95834 #endif
95835 if( argc==3 ){
95836 p2 = sqlite3_value_int(argv[2]);
95837 if( p2<0 ){
95838 p2 = -p2;
95839 negP2 = 1;
@@ -102032,15 +102214,22 @@
102214 # define SQLITE_ENABLE_LOCKING_STYLE 0
102215 # endif
102216 #endif
102217
102218 /***************************************************************************
102219 ** The "pragma.h" include file is an automatically generated file that
102220 ** that includes the PragType_XXXX macro definitions and the aPragmaName[]
102221 ** object. This ensures that the aPragmaName[] table is arranged in
102222 ** lexicographical order to facility a binary search of the pragma name.
102223 ** Do not edit pragma.h directly. Edit and rerun the script in at
102224 ** ../tool/mkpragmatab.tcl. */
102225 /************** Include pragma.h in the middle of pragma.c *******************/
102226 /************** Begin file pragma.h ******************************************/
102227 /* DO NOT EDIT!
102228 ** This file is automatically generated by the script at
102229 ** ../tool/mkpragmatab.tcl. To update the set of pragmas, edit
102230 ** that script and rerun it.
102231 */
102232 #define PragTyp_HEADER_VALUE 0
102233 #define PragTyp_AUTO_VACUUM 1
102234 #define PragTyp_FLAG 2
102235 #define PragTyp_BUSY_TIMEOUT 3
@@ -102271,10 +102460,14 @@
102460 /* iArg: */ 0 },
102461 { /* zName: */ "index_list",
102462 /* ePragTyp: */ PragTyp_INDEX_LIST,
102463 /* ePragFlag: */ PragFlag_NeedSchema,
102464 /* iArg: */ 0 },
102465 { /* zName: */ "index_xinfo",
102466 /* ePragTyp: */ PragTyp_INDEX_INFO,
102467 /* ePragFlag: */ PragFlag_NeedSchema,
102468 /* iArg: */ 1 },
102469 #endif
102470 #if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
102471 { /* zName: */ "integrity_check",
102472 /* ePragTyp: */ PragTyp_INTEGRITY_CHECK,
102473 /* ePragFlag: */ PragFlag_NeedSchema,
@@ -102487,13 +102680,14 @@
102680 /* ePragTyp: */ PragTyp_FLAG,
102681 /* ePragFlag: */ 0,
102682 /* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode },
102683 #endif
102684 };
102685 /* Number of pragmas: 59 on by default, 72 total. */
102686
102687 /************** End of pragma.h **********************************************/
102688 /************** Continuing where we left off in pragma.c *********************/
102689
102690 /*
102691 ** Interpret the given string as a safety level. Return 0 for OFF,
102692 ** 1 for ON or NORMAL and 2 for FULL. Return 1 for an empty or
102693 ** unrecognized string argument. The FULL option is disallowed
@@ -102742,10 +102936,11 @@
102936 int lwr, upr, mid = 0; /* Binary search bounds */
102937 int rc; /* return value form SQLITE_FCNTL_PRAGMA */
102938 sqlite3 *db = pParse->db; /* The database connection */
102939 Db *pDb; /* The specific database being pragmaed */
102940 Vdbe *v = sqlite3GetVdbe(pParse); /* Prepared statement */
102941 const struct sPragmaNames *pPragma;
102942
102943 if( v==0 ) return;
102944 sqlite3VdbeRunOnlyOnce(v);
102945 pParse->nMem = 2;
102946
@@ -102819,18 +103014,19 @@
103014 }else{
103015 lwr = mid + 1;
103016 }
103017 }
103018 if( lwr>upr ) goto pragma_out;
103019 pPragma = &aPragmaNames[mid];
103020
103021 /* Make sure the database schema is loaded if the pragma requires that */
103022 if( (pPragma->mPragFlag & PragFlag_NeedSchema)!=0 ){
103023 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
103024 }
103025
103026 /* Jump to the appropriate pragma handler */
103027 switch( pPragma->ePragTyp ){
103028
103029 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
103030 /*
103031 ** PRAGMA [database.]default_cache_size
103032 ** PRAGMA [database.]default_cache_size=N
@@ -103405,14 +103601,13 @@
103601 #endif /* SQLITE_OMIT_PAGER_PRAGMAS */
103602
103603 #ifndef SQLITE_OMIT_FLAG_PRAGMAS
103604 case PragTyp_FLAG: {
103605 if( zRight==0 ){
103606 returnSingleInt(pParse, pPragma->zName, (db->flags & pPragma->iArg)!=0 );
 
103607 }else{
103608 int mask = pPragma->iArg; /* Mask of bits to set or clear. */
103609 if( db->autoCommit==0 ){
103610 /* Foreign key support may not be enabled or disabled while not
103611 ** in auto-commit mode. */
103612 mask &= ~(SQLITE_ForeignKeys);
103613 }
@@ -103537,24 +103732,34 @@
103732 Index *pIdx;
103733 Table *pTab;
103734 pIdx = sqlite3FindIndex(db, zRight, zDb);
103735 if( pIdx ){
103736 int i;
103737 int mx = pPragma->iArg ? pIdx->nColumn : pIdx->nKeyCol;
103738 pTab = pIdx->pTable;
103739 sqlite3VdbeSetNumCols(v, 6);
103740 pParse->nMem = 6;
103741 sqlite3CodeVerifySchema(pParse, iDb);
103742 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", SQLITE_STATIC);
103743 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", SQLITE_STATIC);
103744 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", SQLITE_STATIC);
103745 sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "desc", SQLITE_STATIC);
103746 sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "coll", SQLITE_STATIC);
103747 sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "key", SQLITE_STATIC);
103748 for(i=0; i<mx; i++){
103749 i16 cnum = pIdx->aiColumn[i];
103750 sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
103751 sqlite3VdbeAddOp2(v, OP_Integer, cnum, 2);
103752 if( cnum<0 ){
103753 sqlite3VdbeAddOp2(v, OP_Null, 0, 3);
103754 }else{
103755 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pTab->aCol[cnum].zName, 0);
103756 }
103757 sqlite3VdbeAddOp2(v, OP_Integer, pIdx->aSortOrder[i], 4);
103758 sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, pIdx->azColl[i], 0);
103759 sqlite3VdbeAddOp2(v, OP_Integer, i<pIdx->nKeyCol, 6);
103760 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
103761 }
103762 }
103763 }
103764 break;
103765
@@ -103563,21 +103768,26 @@
103768 Table *pTab;
103769 int i;
103770 pTab = sqlite3FindTable(db, zRight, zDb);
103771 if( pTab ){
103772 v = sqlite3GetVdbe(pParse);
103773 sqlite3VdbeSetNumCols(v, 5);
103774 pParse->nMem = 5;
103775 sqlite3CodeVerifySchema(pParse, iDb);
103776 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
103777 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
103778 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", SQLITE_STATIC);
103779 sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "origin", SQLITE_STATIC);
103780 sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "partial", SQLITE_STATIC);
103781 for(pIdx=pTab->pIndex, i=0; pIdx; pIdx=pIdx->pNext, i++){
103782 const char *azOrigin[] = { "c", "u", "pk" };
103783 sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
103784 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0);
103785 sqlite3VdbeAddOp2(v, OP_Integer, IsUniqueIndex(pIdx), 3);
103786 sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, azOrigin[pIdx->idxType], 0);
103787 sqlite3VdbeAddOp2(v, OP_Integer, pIdx->pPartIdxWhere!=0, 5);
103788 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 5);
103789 }
103790 }
103791 }
103792 break;
103793
@@ -104143,13 +104353,13 @@
104353 **
104354 ** The user-version is not used internally by SQLite. It may be used by
104355 ** applications for any purpose.
104356 */
104357 case PragTyp_HEADER_VALUE: {
104358 int iCookie = pPragma->iArg; /* Which cookie to read or write */
104359 sqlite3VdbeUsesBtree(v, iDb);
104360 if( zRight && (pPragma->mPragFlag & PragFlag_ReadOnly)==0 ){
104361 /* Write the specified cookie value */
104362 static const VdbeOpList setCookie[] = {
104363 { OP_Transaction, 0, 1, 0}, /* 0 */
104364 { OP_Integer, 0, 1, 0}, /* 1 */
104365 { OP_SetCookie, 0, 0, 1}, /* 2 */
@@ -104265,11 +104475,11 @@
104475 ** if one is set. If no busy handler or a different busy handler is set
104476 ** then 0 is returned. Setting the busy_timeout to 0 or negative
104477 ** disables the timeout.
104478 */
104479 /*case PragTyp_BUSY_TIMEOUT*/ default: {
104480 assert( pPragma->ePragTyp==PragTyp_BUSY_TIMEOUT );
104481 if( zRight ){
104482 sqlite3_busy_timeout(db, sqlite3Atoi(zRight));
104483 }
104484 returnSingleInt(pParse, "timeout", db->busyTimeout);
104485 break;
@@ -108486,11 +108696,14 @@
108696 **
108697 ** Flattening is only attempted if all of the following are true:
108698 **
108699 ** (1) The subquery and the outer query do not both use aggregates.
108700 **
108701 ** (2) The subquery is not an aggregate or (2a) the outer query is not a join
108702 ** and (2b) the outer query does not use subqueries other than the one
108703 ** FROM-clause subquery that is a candidate for flattening. (2b is
108704 ** due to ticket [2f7170d73bf9abf80] from 2015-02-09.)
108705 **
108706 ** (3) The subquery is not the right operand of a left outer join
108707 ** (Originally ticket #306. Strengthened by ticket #3300)
108708 **
108709 ** (4) The subquery is not DISTINCT.
@@ -108623,12 +108836,21 @@
108836 assert( pSrc && iFrom>=0 && iFrom<pSrc->nSrc );
108837 pSubitem = &pSrc->a[iFrom];
108838 iParent = pSubitem->iCursor;
108839 pSub = pSubitem->pSelect;
108840 assert( pSub!=0 );
108841 if( subqueryIsAgg ){
108842 if( isAgg ) return 0; /* Restriction (1) */
108843 if( pSrc->nSrc>1 ) return 0; /* Restriction (2a) */
108844 if( (p->pWhere && ExprHasProperty(p->pWhere,EP_Subquery))
108845 || (sqlite3ExprListFlags(p->pEList) & EP_Subquery)!=0
108846 || (sqlite3ExprListFlags(p->pOrderBy) & EP_Subquery)!=0
108847 ){
108848 return 0; /* Restriction (2b) */
108849 }
108850 }
108851
108852 pSubSrc = pSub->pSrc;
108853 assert( pSubSrc );
108854 /* Prior to version 3.1.2, when LIMIT and OFFSET had to be simple constants,
108855 ** not arbitrary expressions, we allowed some combining of LIMIT and OFFSET
108856 ** because they could be computed at compile-time. But when LIMIT and OFFSET
@@ -109445,11 +109667,11 @@
109667 #ifndef SQLITE_OMIT_SUBQUERY
109668 Select *pSel = pFrom->pSelect;
109669 /* A sub-query in the FROM clause of a SELECT */
109670 assert( pSel!=0 );
109671 assert( pFrom->pTab==0 );
109672 if( sqlite3WalkSelect(pWalker, pSel) ) return WRC_Abort;
109673 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
109674 if( pTab==0 ) return WRC_Abort;
109675 pTab->nRef = 1;
109676 pTab->zName = sqlite3MPrintf(db, "sqlite_sq_%p", (void*)pTab);
109677 while( pSel->pPrior ){ pSel = pSel->pPrior; }
@@ -110044,10 +110266,17 @@
110266 if( pParse->nErr || db->mallocFailed ){
110267 goto select_end;
110268 }
110269 isAgg = (p->selFlags & SF_Aggregate)!=0;
110270 assert( pEList!=0 );
110271 #if SELECTTRACE_ENABLED
110272 if( sqlite3SelectTrace & 0x100 ){
110273 SELECTTRACE(0x100,pParse,p, ("after name resolution:\n"));
110274 sqlite3TreeViewSelect(0, p, 0);
110275 }
110276 #endif
110277
110278
110279 /* Begin generating code.
110280 */
110281 v = sqlite3GetVdbe(pParse);
110282 if( v==0 ) goto select_end;
@@ -110789,13 +111018,13 @@
111018 ** Generate a human-readable description of a the Select object.
111019 */
111020 SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){
111021 int n = 0;
111022 pView = sqlite3TreeViewPush(pView, moreToFollow);
111023 sqlite3TreeViewLine(pView, "SELECT%s%s (0x%p)",
111024 ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""),
111025 ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""), p
111026 );
111027 if( p->pSrc && p->pSrc->nSrc ) n++;
111028 if( p->pWhere ) n++;
111029 if( p->pGroupBy ) n++;
111030 if( p->pHaving ) n++;
@@ -113161,11 +113390,11 @@
113390 ** locked (as there was more than one active statement when the transaction
113391 ** to read the schema was concluded. Unlock it here so that this doesn't
113392 ** cause problems for the call to BtreeSetPageSize() below. */
113393 sqlite3BtreeCommit(pTemp);
113394
113395 nRes = sqlite3BtreeGetOptimalReserve(pMain);
113396
113397 /* A VACUUM cannot change the pagesize of an encrypted database. */
113398 #ifdef SQLITE_HAS_CODEC
113399 if( db->nextPagesize ){
113400 extern void sqlite3CodecGetKey(sqlite3*, int, void**, int*);
@@ -114058,11 +114287,13 @@
114287 int rc = SQLITE_OK;
114288 Table *pTab;
114289 char *zErr = 0;
114290
114291 #ifdef SQLITE_ENABLE_API_ARMOR
114292 if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){
114293 return SQLITE_MISUSE_BKPT;
114294 }
114295 #endif
114296 sqlite3_mutex_enter(db->mutex);
114297 if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){
114298 sqlite3Error(db, SQLITE_MISUSE);
114299 sqlite3_mutex_leave(db->mutex);
@@ -116547,16 +116778,20 @@
116778 pTable = pSrc->pTab;
116779 pWCEnd = &pWC->a[pWC->nTerm];
116780 pLoop = pLevel->pWLoop;
116781 idxCols = 0;
116782 for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
116783 Expr *pExpr = pTerm->pExpr;
116784 assert( !ExprHasProperty(pExpr, EP_FromJoin) /* prereq always non-zero */
116785 || pExpr->iRightJoinTable!=pSrc->iCursor /* for the right-hand */
116786 || pLoop->prereq!=0 ); /* table of a LEFT JOIN */
116787 if( pLoop->prereq==0
116788 && (pTerm->wtFlags & TERM_VIRTUAL)==0
116789 && !ExprHasProperty(pExpr, EP_FromJoin)
116790 && sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor) ){
116791 pPartial = sqlite3ExprAnd(pParse->db, pPartial,
116792 sqlite3ExprDup(pParse->db, pExpr, 0));
116793 }
116794 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
116795 int iCol = pTerm->u.leftColumn;
116796 Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
116797 testcase( iCol==BMS );
@@ -119630,12 +119865,13 @@
119865 */
119866 static int whereUsablePartialIndex(int iTab, WhereClause *pWC, Expr *pWhere){
119867 int i;
119868 WhereTerm *pTerm;
119869 for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
119870 Expr *pExpr = pTerm->pExpr;
119871 if( sqlite3ExprImpliesExpr(pExpr, pWhere, iTab)
119872 && (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->iRightJoinTable==iTab)
119873 ){
119874 return 1;
119875 }
119876 }
119877 return 0;
@@ -124576,11 +124812,11 @@
124812 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, yymsp[-3].minor.yy328 ? TK_NE : TK_EQ, yymsp[-4].minor.yy346.pExpr, pRHS, 0);
124813 }else{
124814 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy346.pExpr, 0, 0);
124815 if( yygotominor.yy346.pExpr ){
124816 yygotominor.yy346.pExpr->x.pList = yymsp[-1].minor.yy14;
124817 sqlite3ExprSetHeightAndFlags(pParse, yygotominor.yy346.pExpr);
124818 }else{
124819 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy14);
124820 }
124821 if( yymsp[-3].minor.yy328 ) yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy346.pExpr, 0, 0);
124822 }
@@ -124591,12 +124827,12 @@
124827 case 224: /* expr ::= LP select RP */
124828 {
124829 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
124830 if( yygotominor.yy346.pExpr ){
124831 yygotominor.yy346.pExpr->x.pSelect = yymsp[-1].minor.yy3;
124832 ExprSetProperty(yygotominor.yy346.pExpr, EP_xIsSelect|EP_Subquery);
124833 sqlite3ExprSetHeightAndFlags(pParse, yygotominor.yy346.pExpr);
124834 }else{
124835 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy3);
124836 }
124837 yygotominor.yy346.zStart = yymsp[-2].minor.yy0.z;
124838 yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
@@ -124605,12 +124841,12 @@
124841 case 225: /* expr ::= expr in_op LP select RP */
124842 {
124843 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy346.pExpr, 0, 0);
124844 if( yygotominor.yy346.pExpr ){
124845 yygotominor.yy346.pExpr->x.pSelect = yymsp[-1].minor.yy3;
124846 ExprSetProperty(yygotominor.yy346.pExpr, EP_xIsSelect|EP_Subquery);
124847 sqlite3ExprSetHeightAndFlags(pParse, yygotominor.yy346.pExpr);
124848 }else{
124849 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy3);
124850 }
124851 if( yymsp[-3].minor.yy328 ) yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy346.pExpr, 0, 0);
124852 yygotominor.yy346.zStart = yymsp[-4].minor.yy346.zStart;
@@ -124621,12 +124857,12 @@
124857 {
124858 SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);
124859 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy346.pExpr, 0, 0);
124860 if( yygotominor.yy346.pExpr ){
124861 yygotominor.yy346.pExpr->x.pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
124862 ExprSetProperty(yygotominor.yy346.pExpr, EP_xIsSelect|EP_Subquery);
124863 sqlite3ExprSetHeightAndFlags(pParse, yygotominor.yy346.pExpr);
124864 }else{
124865 sqlite3SrcListDelete(pParse->db, pSrc);
124866 }
124867 if( yymsp[-2].minor.yy328 ) yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy346.pExpr, 0, 0);
124868 yygotominor.yy346.zStart = yymsp[-3].minor.yy346.zStart;
@@ -124636,12 +124872,12 @@
124872 case 227: /* expr ::= EXISTS LP select RP */
124873 {
124874 Expr *p = yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
124875 if( p ){
124876 p->x.pSelect = yymsp[-1].minor.yy3;
124877 ExprSetProperty(p, EP_xIsSelect|EP_Subquery);
124878 sqlite3ExprSetHeightAndFlags(pParse, p);
124879 }else{
124880 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy3);
124881 }
124882 yygotominor.yy346.zStart = yymsp[-3].minor.yy0.z;
124883 yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
@@ -124650,11 +124886,11 @@
124886 case 228: /* expr ::= CASE case_operand case_exprlist case_else END */
124887 {
124888 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy132, 0, 0);
124889 if( yygotominor.yy346.pExpr ){
124890 yygotominor.yy346.pExpr->x.pList = yymsp[-1].minor.yy132 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy14,yymsp[-1].minor.yy132) : yymsp[-2].minor.yy14;
124891 sqlite3ExprSetHeightAndFlags(pParse, yygotominor.yy346.pExpr);
124892 }else{
124893 sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy14);
124894 sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy132);
124895 }
124896 yygotominor.yy346.zStart = yymsp[-4].minor.yy0.z;
@@ -125892,14 +126128,11 @@
126128 int lastTokenParsed = -1; /* type of the previous token */
126129 u8 enableLookaside; /* Saved value of db->lookaside.bEnabled */
126130 sqlite3 *db = pParse->db; /* The database connection */
126131 int mxSqlLen; /* Max length of an SQL string */
126132
126133 assert( zSql!=0 );
 
 
 
126134 mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
126135 if( db->nVdbeActive==0 ){
126136 db->u1.isInterrupted = 0;
126137 }
126138 pParse->rc = SQLITE_OK;
@@ -127823,11 +128056,11 @@
128056 sqlite3 *db,
128057 int (*xBusy)(void*,int),
128058 void *pArg
128059 ){
128060 #ifdef SQLITE_ENABLE_API_ARMOR
128061 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
128062 #endif
128063 sqlite3_mutex_enter(db->mutex);
128064 db->busyHandler.xFunc = xBusy;
128065 db->busyHandler.pArg = pArg;
128066 db->busyHandler.nBusy = 0;
@@ -129116,10 +129349,13 @@
129349 db->nMaxSorterMmap = 0x7FFFFFFF;
129350 db->flags |= SQLITE_ShortColNames | SQLITE_EnableTrigger | SQLITE_CacheSpill
129351 #if !defined(SQLITE_DEFAULT_AUTOMATIC_INDEX) || SQLITE_DEFAULT_AUTOMATIC_INDEX
129352 | SQLITE_AutoIndex
129353 #endif
129354 #if SQLITE_DEFAULT_CKPTFULLFSYNC
129355 | SQLITE_CkptFullFSync
129356 #endif
129357 #if SQLITE_DEFAULT_FILE_FORMAT<4
129358 | SQLITE_LegacyFileFmt
129359 #endif
129360 #ifdef SQLITE_ENABLE_LOAD_EXTENSION
129361 | SQLITE_LoadExtension
@@ -129551,17 +129787,23 @@
129787 int rc;
129788 char *zErrMsg = 0;
129789 Table *pTab = 0;
129790 Column *pCol = 0;
129791 int iCol = 0;
 
129792 char const *zDataType = 0;
129793 char const *zCollSeq = 0;
129794 int notnull = 0;
129795 int primarykey = 0;
129796 int autoinc = 0;
129797
129798
129799 #ifdef SQLITE_ENABLE_API_ARMOR
129800 if( !sqlite3SafetyCheckOk(db) || zTableName==0 ){
129801 return SQLITE_MISUSE_BKPT;
129802 }
129803 #endif
129804
129805 /* Ensure the database schema has been loaded */
129806 sqlite3_mutex_enter(db->mutex);
129807 sqlite3BtreeEnterAll(db);
129808 rc = sqlite3Init(db, &zErrMsg);
129809 if( SQLITE_OK!=rc ){
@@ -129704,11 +129946,11 @@
129946 rc = SQLITE_NOTFOUND;
129947 }
129948 sqlite3BtreeLeave(pBtree);
129949 }
129950 sqlite3_mutex_leave(db->mutex);
129951 return rc;
129952 }
129953
129954 /*
129955 ** Interface to the testing logic.
129956 */
@@ -130007,10 +130249,39 @@
130249 */
130250 case SQLITE_TESTCTRL_ISINIT: {
130251 if( sqlite3GlobalConfig.isInit==0 ) rc = SQLITE_ERROR;
130252 break;
130253 }
130254
130255 /* sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, db, dbName, onOff, tnum);
130256 **
130257 ** This test control is used to create imposter tables. "db" is a pointer
130258 ** to the database connection. dbName is the database name (ex: "main" or
130259 ** "temp") which will receive the imposter. "onOff" turns imposter mode on
130260 ** or off. "tnum" is the root page of the b-tree to which the imposter
130261 ** table should connect.
130262 **
130263 ** Enable imposter mode only when the schema has already been parsed. Then
130264 ** run a single CREATE TABLE statement to construct the imposter table in the
130265 ** parsed schema. Then turn imposter mode back off again.
130266 **
130267 ** If onOff==0 and tnum>0 then reset the schema for all databases, causing
130268 ** the schema to be reparsed the next time it is needed. This has the
130269 ** effect of erasing all imposter tables.
130270 */
130271 case SQLITE_TESTCTRL_IMPOSTER: {
130272 sqlite3 *db = va_arg(ap, sqlite3*);
130273 sqlite3_mutex_enter(db->mutex);
130274 db->init.iDb = sqlite3FindDbName(db, va_arg(ap,const char*));
130275 db->init.busy = db->init.imposterTable = va_arg(ap,int);
130276 db->init.newTnum = va_arg(ap,int);
130277 if( db->init.busy==0 && db->init.newTnum>0 ){
130278 sqlite3ResetAllSchemasOfConnection(db);
130279 }
130280 sqlite3_mutex_leave(db->mutex);
130281 break;
130282 }
130283 }
130284 va_end(ap);
130285 #endif /* SQLITE_OMIT_BUILTIN_TEST */
130286 return rc;
130287 }
@@ -134489,14 +134760,21 @@
134760 ** statement loops through all rows of the %_content table. For a
134761 ** full-text query or docid lookup, the statement retrieves a single
134762 ** row by docid.
134763 */
134764 if( eSearch==FTS3_FULLSCAN_SEARCH ){
134765 if( pDocidGe || pDocidLe ){
134766 zSql = sqlite3_mprintf(
134767 "SELECT %s WHERE rowid BETWEEN %lld AND %lld ORDER BY rowid %s",
134768 p->zReadExprlist, pCsr->iMinDocid, pCsr->iMaxDocid,
134769 (pCsr->bDesc ? "DESC" : "ASC")
134770 );
134771 }else{
134772 zSql = sqlite3_mprintf("SELECT %s ORDER BY rowid %s",
134773 p->zReadExprlist, (pCsr->bDesc ? "DESC" : "ASC")
134774 );
134775 }
134776 if( zSql ){
134777 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pCsr->pStmt, 0);
134778 sqlite3_free(zSql);
134779 }else{
134780 rc = SQLITE_NOMEM;
@@ -136981,11 +137259,10 @@
137259 iDocid = pExpr->iDocid;
137260 pIter = pPhrase->doclist.pList;
137261 if( iDocid!=pCsr->iPrevId || pExpr->bEof ){
137262 int rc = SQLITE_OK;
137263 int bDescDoclist = pTab->bDescIdx; /* For DOCID_CMP macro */
 
137264 int bOr = 0;
137265 u8 bEof = 0;
137266 u8 bTreeEof = 0;
137267 Fts3Expr *p; /* Used to iterate from pExpr to root */
137268 Fts3Expr *pNear; /* Most senior NEAR ancestor (or pExpr) */
@@ -147528,12 +147805,16 @@
147805
147806 /* Now that the shift has been done, check if the initial "..." are
147807 ** required. They are required if (a) this is not the first fragment,
147808 ** or (b) this fragment does not begin at position 0 of its column.
147809 */
147810 if( rc==SQLITE_OK ){
147811 if( iPos>0 || iFragment>0 ){
147812 rc = fts3StringAppend(pOut, zEllipsis, -1);
147813 }else if( iBegin ){
147814 rc = fts3StringAppend(pOut, zDoc, iBegin);
147815 }
147816 }
147817 if( rc!=SQLITE_OK || iCurrent<iPos ) continue;
147818 }
147819
147820 if( iCurrent>=(iPos+nSnippet) ){
147821
+29 -7
--- 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.8.8.3"
110
+#define SQLITE_VERSION "3.8.8"
111111
#define SQLITE_VERSION_NUMBER 3008008
112
-#define SQLITE_SOURCE_ID "2015-02-25 13:29:11 9d6c1880fb75660bbabd693175579529785f8a6b"
112
+#define SQLITE_SOURCE_ID "2015-02-25 14:25:31 6d132e7a224ee68b5cefe9222944aac5760ffc20"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -947,13 +947,13 @@
947947
** and only needs to be supported when SQLITE_TEST is defined.
948948
**
949949
** </ul>
950950
*/
951951
#define SQLITE_FCNTL_LOCKSTATE 1
952
-#define SQLITE_GET_LOCKPROXYFILE 2
953
-#define SQLITE_SET_LOCKPROXYFILE 3
954
-#define SQLITE_LAST_ERRNO 4
952
+#define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
953
+#define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
954
+#define SQLITE_FCNTL_LAST_ERRNO 4
955955
#define SQLITE_FCNTL_SIZE_HINT 5
956956
#define SQLITE_FCNTL_CHUNK_SIZE 6
957957
#define SQLITE_FCNTL_FILE_POINTER 7
958958
#define SQLITE_FCNTL_SYNC_OMITTED 8
959959
#define SQLITE_FCNTL_WIN32_AV_RETRY 9
@@ -968,10 +968,16 @@
968968
#define SQLITE_FCNTL_TRACE 19
969969
#define SQLITE_FCNTL_HAS_MOVED 20
970970
#define SQLITE_FCNTL_SYNC 21
971971
#define SQLITE_FCNTL_COMMIT_PHASETWO 22
972972
#define SQLITE_FCNTL_WIN32_SET_HANDLE 23
973
+
974
+/* deprecated names */
975
+#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
976
+#define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
977
+#define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
978
+
973979
974980
/*
975981
** CAPI3REF: Mutex Handle
976982
**
977983
** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -2229,10 +2235,14 @@
22292235
/*
22302236
** CAPI3REF: Formatted String Printing Functions
22312237
**
22322238
** These routines are work-alikes of the "printf()" family of functions
22332239
** from the standard C library.
2240
+** These routines understand most of the common K&R formatting options,
2241
+** plus some additional non-standard formats, detailed below.
2242
+** Note that some of the more obscure formatting options from recent
2243
+** C-library standards are omitted from this implementation.
22342244
**
22352245
** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
22362246
** results into memory obtained from [sqlite3_malloc()].
22372247
** The strings returned by these two routines should be
22382248
** released by [sqlite3_free()]. ^Both routines return a
@@ -2261,11 +2271,11 @@
22612271
** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
22622272
**
22632273
** These routines all implement some additional formatting
22642274
** options that are useful for constructing SQL statements.
22652275
** All of the usual printf() formatting options apply. In addition, there
2266
-** is are "%q", "%Q", and "%z" options.
2276
+** is are "%q", "%Q", "%w" and "%z" options.
22672277
**
22682278
** ^(The %q option works like %s in that it substitutes a nul-terminated
22692279
** string from the argument list. But %q also doubles every '\'' character.
22702280
** %q is designed for use inside a string literal.)^ By doubling each '\''
22712281
** character it escapes that character and allows it to be inserted into
@@ -2313,10 +2323,16 @@
23132323
** sqlite3_free(zSQL);
23142324
** </pre></blockquote>
23152325
**
23162326
** The code above will render a correct SQL statement in the zSQL
23172327
** variable even if the zText variable is a NULL pointer.
2328
+**
2329
+** ^(The "%w" formatting option is like "%q" except that it expects to
2330
+** be contained within double-quotes instead of single quotes, and it
2331
+** escapes the double-quote character instead of the single-quote
2332
+** character.)^ The "%w" formatting option is intended for safely inserting
2333
+** table and column names into a constructed SQL statement.
23182334
**
23192335
** ^(The "%z" formatting option works like "%s" but with the
23202336
** addition that after the string has been read and copied into
23212337
** the result, [sqlite3_free()] is called on the input string.)^
23222338
*/
@@ -5063,10 +5079,15 @@
50635079
** successfully. An [error code] is returned otherwise.)^
50645080
**
50655081
** ^Shared cache is disabled by default. But this might change in
50665082
** future releases of SQLite. Applications that care about shared
50675083
** cache setting should set it explicitly.
5084
+**
5085
+** Note: This method is disabled on MacOS X 10.7 and iOS version 5.0
5086
+** and will always return SQLITE_MISUSE. On those systems,
5087
+** shared cache mode should be enabled per-database connection via
5088
+** [sqlite3_open_v2()] with [SQLITE_OPEN_SHAREDCACHE].
50685089
**
50695090
** This interface is threadsafe on processors where writing a
50705091
** 32-bit integer is atomic.
50715092
**
50725093
** See Also: [SQLite Shared-Cache Mode]
@@ -6263,11 +6284,12 @@
62636284
#define SQLITE_TESTCTRL_NEVER_CORRUPT 20
62646285
#define SQLITE_TESTCTRL_VDBE_COVERAGE 21
62656286
#define SQLITE_TESTCTRL_BYTEORDER 22
62666287
#define SQLITE_TESTCTRL_ISINIT 23
62676288
#define SQLITE_TESTCTRL_SORTER_MMAP 24
6268
-#define SQLITE_TESTCTRL_LAST 24
6289
+#define SQLITE_TESTCTRL_IMPOSTER 25
6290
+#define SQLITE_TESTCTRL_LAST 25
62696291
62706292
/*
62716293
** CAPI3REF: SQLite Runtime Status
62726294
**
62736295
** ^This interface is used to retrieve runtime status information
62746296
--- 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.8.8.3"
111 #define SQLITE_VERSION_NUMBER 3008008
112 #define SQLITE_SOURCE_ID "2015-02-25 13:29:11 9d6c1880fb75660bbabd693175579529785f8a6b"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -947,13 +947,13 @@
947 ** and only needs to be supported when SQLITE_TEST is defined.
948 **
949 ** </ul>
950 */
951 #define SQLITE_FCNTL_LOCKSTATE 1
952 #define SQLITE_GET_LOCKPROXYFILE 2
953 #define SQLITE_SET_LOCKPROXYFILE 3
954 #define SQLITE_LAST_ERRNO 4
955 #define SQLITE_FCNTL_SIZE_HINT 5
956 #define SQLITE_FCNTL_CHUNK_SIZE 6
957 #define SQLITE_FCNTL_FILE_POINTER 7
958 #define SQLITE_FCNTL_SYNC_OMITTED 8
959 #define SQLITE_FCNTL_WIN32_AV_RETRY 9
@@ -968,10 +968,16 @@
968 #define SQLITE_FCNTL_TRACE 19
969 #define SQLITE_FCNTL_HAS_MOVED 20
970 #define SQLITE_FCNTL_SYNC 21
971 #define SQLITE_FCNTL_COMMIT_PHASETWO 22
972 #define SQLITE_FCNTL_WIN32_SET_HANDLE 23
 
 
 
 
 
 
973
974 /*
975 ** CAPI3REF: Mutex Handle
976 **
977 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -2229,10 +2235,14 @@
2229 /*
2230 ** CAPI3REF: Formatted String Printing Functions
2231 **
2232 ** These routines are work-alikes of the "printf()" family of functions
2233 ** from the standard C library.
 
 
 
 
2234 **
2235 ** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
2236 ** results into memory obtained from [sqlite3_malloc()].
2237 ** The strings returned by these two routines should be
2238 ** released by [sqlite3_free()]. ^Both routines return a
@@ -2261,11 +2271,11 @@
2261 ** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
2262 **
2263 ** These routines all implement some additional formatting
2264 ** options that are useful for constructing SQL statements.
2265 ** All of the usual printf() formatting options apply. In addition, there
2266 ** is are "%q", "%Q", and "%z" options.
2267 **
2268 ** ^(The %q option works like %s in that it substitutes a nul-terminated
2269 ** string from the argument list. But %q also doubles every '\'' character.
2270 ** %q is designed for use inside a string literal.)^ By doubling each '\''
2271 ** character it escapes that character and allows it to be inserted into
@@ -2313,10 +2323,16 @@
2313 ** sqlite3_free(zSQL);
2314 ** </pre></blockquote>
2315 **
2316 ** The code above will render a correct SQL statement in the zSQL
2317 ** variable even if the zText variable is a NULL pointer.
 
 
 
 
 
 
2318 **
2319 ** ^(The "%z" formatting option works like "%s" but with the
2320 ** addition that after the string has been read and copied into
2321 ** the result, [sqlite3_free()] is called on the input string.)^
2322 */
@@ -5063,10 +5079,15 @@
5063 ** successfully. An [error code] is returned otherwise.)^
5064 **
5065 ** ^Shared cache is disabled by default. But this might change in
5066 ** future releases of SQLite. Applications that care about shared
5067 ** cache setting should set it explicitly.
 
 
 
 
 
5068 **
5069 ** This interface is threadsafe on processors where writing a
5070 ** 32-bit integer is atomic.
5071 **
5072 ** See Also: [SQLite Shared-Cache Mode]
@@ -6263,11 +6284,12 @@
6263 #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
6264 #define SQLITE_TESTCTRL_VDBE_COVERAGE 21
6265 #define SQLITE_TESTCTRL_BYTEORDER 22
6266 #define SQLITE_TESTCTRL_ISINIT 23
6267 #define SQLITE_TESTCTRL_SORTER_MMAP 24
6268 #define SQLITE_TESTCTRL_LAST 24
 
6269
6270 /*
6271 ** CAPI3REF: SQLite Runtime Status
6272 **
6273 ** ^This interface is used to retrieve runtime status information
6274
--- 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.8.8"
111 #define SQLITE_VERSION_NUMBER 3008008
112 #define SQLITE_SOURCE_ID "2015-02-25 14:25:31 6d132e7a224ee68b5cefe9222944aac5760ffc20"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -947,13 +947,13 @@
947 ** and only needs to be supported when SQLITE_TEST is defined.
948 **
949 ** </ul>
950 */
951 #define SQLITE_FCNTL_LOCKSTATE 1
952 #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
953 #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
954 #define SQLITE_FCNTL_LAST_ERRNO 4
955 #define SQLITE_FCNTL_SIZE_HINT 5
956 #define SQLITE_FCNTL_CHUNK_SIZE 6
957 #define SQLITE_FCNTL_FILE_POINTER 7
958 #define SQLITE_FCNTL_SYNC_OMITTED 8
959 #define SQLITE_FCNTL_WIN32_AV_RETRY 9
@@ -968,10 +968,16 @@
968 #define SQLITE_FCNTL_TRACE 19
969 #define SQLITE_FCNTL_HAS_MOVED 20
970 #define SQLITE_FCNTL_SYNC 21
971 #define SQLITE_FCNTL_COMMIT_PHASETWO 22
972 #define SQLITE_FCNTL_WIN32_SET_HANDLE 23
973
974 /* deprecated names */
975 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
976 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
977 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
978
979
980 /*
981 ** CAPI3REF: Mutex Handle
982 **
983 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -2229,10 +2235,14 @@
2235 /*
2236 ** CAPI3REF: Formatted String Printing Functions
2237 **
2238 ** These routines are work-alikes of the "printf()" family of functions
2239 ** from the standard C library.
2240 ** These routines understand most of the common K&R formatting options,
2241 ** plus some additional non-standard formats, detailed below.
2242 ** Note that some of the more obscure formatting options from recent
2243 ** C-library standards are omitted from this implementation.
2244 **
2245 ** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
2246 ** results into memory obtained from [sqlite3_malloc()].
2247 ** The strings returned by these two routines should be
2248 ** released by [sqlite3_free()]. ^Both routines return a
@@ -2261,11 +2271,11 @@
2271 ** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
2272 **
2273 ** These routines all implement some additional formatting
2274 ** options that are useful for constructing SQL statements.
2275 ** All of the usual printf() formatting options apply. In addition, there
2276 ** is are "%q", "%Q", "%w" and "%z" options.
2277 **
2278 ** ^(The %q option works like %s in that it substitutes a nul-terminated
2279 ** string from the argument list. But %q also doubles every '\'' character.
2280 ** %q is designed for use inside a string literal.)^ By doubling each '\''
2281 ** character it escapes that character and allows it to be inserted into
@@ -2313,10 +2323,16 @@
2323 ** sqlite3_free(zSQL);
2324 ** </pre></blockquote>
2325 **
2326 ** The code above will render a correct SQL statement in the zSQL
2327 ** variable even if the zText variable is a NULL pointer.
2328 **
2329 ** ^(The "%w" formatting option is like "%q" except that it expects to
2330 ** be contained within double-quotes instead of single quotes, and it
2331 ** escapes the double-quote character instead of the single-quote
2332 ** character.)^ The "%w" formatting option is intended for safely inserting
2333 ** table and column names into a constructed SQL statement.
2334 **
2335 ** ^(The "%z" formatting option works like "%s" but with the
2336 ** addition that after the string has been read and copied into
2337 ** the result, [sqlite3_free()] is called on the input string.)^
2338 */
@@ -5063,10 +5079,15 @@
5079 ** successfully. An [error code] is returned otherwise.)^
5080 **
5081 ** ^Shared cache is disabled by default. But this might change in
5082 ** future releases of SQLite. Applications that care about shared
5083 ** cache setting should set it explicitly.
5084 **
5085 ** Note: This method is disabled on MacOS X 10.7 and iOS version 5.0
5086 ** and will always return SQLITE_MISUSE. On those systems,
5087 ** shared cache mode should be enabled per-database connection via
5088 ** [sqlite3_open_v2()] with [SQLITE_OPEN_SHAREDCACHE].
5089 **
5090 ** This interface is threadsafe on processors where writing a
5091 ** 32-bit integer is atomic.
5092 **
5093 ** See Also: [SQLite Shared-Cache Mode]
@@ -6263,11 +6284,12 @@
6284 #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
6285 #define SQLITE_TESTCTRL_VDBE_COVERAGE 21
6286 #define SQLITE_TESTCTRL_BYTEORDER 22
6287 #define SQLITE_TESTCTRL_ISINIT 23
6288 #define SQLITE_TESTCTRL_SORTER_MMAP 24
6289 #define SQLITE_TESTCTRL_IMPOSTER 25
6290 #define SQLITE_TESTCTRL_LAST 25
6291
6292 /*
6293 ** CAPI3REF: SQLite Runtime Status
6294 **
6295 ** ^This interface is used to retrieve runtime status information
6296
+1 -1
--- src/style.c
+++ src/style.c
@@ -504,11 +504,11 @@
504504
switch( aSubmenuCtrl[i].eType ){
505505
case FF_ENTRY: {
506506
cgi_printf(
507507
"<span class='submenuctrl'>"
508508
"&nbsp;%h<input type='text' name='%s' size='%d' maxlength='%d'"
509
- "value='%h'%s></span>\n",
509
+ " value='%h'%s></span>\n",
510510
aSubmenuCtrl[i].zLabel,
511511
zQPN,
512512
aSubmenuCtrl[i].iSize, aSubmenuCtrl[i].iSize,
513513
PD(zQPN,""),
514514
zDisabled
515515
--- src/style.c
+++ src/style.c
@@ -504,11 +504,11 @@
504 switch( aSubmenuCtrl[i].eType ){
505 case FF_ENTRY: {
506 cgi_printf(
507 "<span class='submenuctrl'>"
508 "&nbsp;%h<input type='text' name='%s' size='%d' maxlength='%d'"
509 "value='%h'%s></span>\n",
510 aSubmenuCtrl[i].zLabel,
511 zQPN,
512 aSubmenuCtrl[i].iSize, aSubmenuCtrl[i].iSize,
513 PD(zQPN,""),
514 zDisabled
515
--- src/style.c
+++ src/style.c
@@ -504,11 +504,11 @@
504 switch( aSubmenuCtrl[i].eType ){
505 case FF_ENTRY: {
506 cgi_printf(
507 "<span class='submenuctrl'>"
508 "&nbsp;%h<input type='text' name='%s' size='%d' maxlength='%d'"
509 " value='%h'%s></span>\n",
510 aSubmenuCtrl[i].zLabel,
511 zQPN,
512 aSubmenuCtrl[i].iSize, aSubmenuCtrl[i].iSize,
513 PD(zQPN,""),
514 zDisabled
515

Keyboard Shortcuts

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