Fossil SCM

Import the latest SQLite 3.8.0 beta code from upstream.

drh 2013-07-17 12:06 trunk
Commit df46aa659c132784f2fa08c60b36565d5fa5c6e9
3 files changed +1 -3 +295 -111 +24 -4
+1 -3
--- src/shell.c
+++ src/shell.c
@@ -1719,11 +1719,10 @@
17191719
|| (c=='\n' && pc==cQuote)
17201720
|| (c=='\n' && pc=='\r' && p->n>2 && p->z[p->n-2]==cQuote)
17211721
|| (c==EOF && pc==cQuote)
17221722
){
17231723
do{ p->n--; }while( p->z[p->n]!=cQuote );
1724
- p->z[p->n] = 0;
17251724
p->cTerm = c;
17261725
break;
17271726
}
17281727
if( pc==cQuote && c!='\r' ){
17291728
fprintf(stderr, "%s:%d: unescaped %c character\n",
@@ -1730,11 +1729,10 @@
17301729
p->zFile, p->nLine, cQuote);
17311730
}
17321731
if( c==EOF ){
17331732
fprintf(stderr, "%s:%d: unterminated %c-quoted field\n",
17341733
p->zFile, startLine, cQuote);
1735
- p->z[p->n] = 0;
17361734
p->cTerm = EOF;
17371735
break;
17381736
}
17391737
csv_append_char(p, c);
17401738
pc = c;
@@ -1746,13 +1744,13 @@
17461744
}
17471745
if( c=='\n' ){
17481746
p->nLine++;
17491747
if( p->n>1 && p->z[p->n-1]=='\r' ) p->n--;
17501748
}
1751
- p->z[p->n] = 0;
17521749
p->cTerm = c;
17531750
}
1751
+ if( p->z ) p->z[p->n] = 0;
17541752
return p->z;
17551753
}
17561754
17571755
/*
17581756
** If an input line begins with "." then invoke this routine to
17591757
--- src/shell.c
+++ src/shell.c
@@ -1719,11 +1719,10 @@
1719 || (c=='\n' && pc==cQuote)
1720 || (c=='\n' && pc=='\r' && p->n>2 && p->z[p->n-2]==cQuote)
1721 || (c==EOF && pc==cQuote)
1722 ){
1723 do{ p->n--; }while( p->z[p->n]!=cQuote );
1724 p->z[p->n] = 0;
1725 p->cTerm = c;
1726 break;
1727 }
1728 if( pc==cQuote && c!='\r' ){
1729 fprintf(stderr, "%s:%d: unescaped %c character\n",
@@ -1730,11 +1729,10 @@
1730 p->zFile, p->nLine, cQuote);
1731 }
1732 if( c==EOF ){
1733 fprintf(stderr, "%s:%d: unterminated %c-quoted field\n",
1734 p->zFile, startLine, cQuote);
1735 p->z[p->n] = 0;
1736 p->cTerm = EOF;
1737 break;
1738 }
1739 csv_append_char(p, c);
1740 pc = c;
@@ -1746,13 +1744,13 @@
1746 }
1747 if( c=='\n' ){
1748 p->nLine++;
1749 if( p->n>1 && p->z[p->n-1]=='\r' ) p->n--;
1750 }
1751 p->z[p->n] = 0;
1752 p->cTerm = c;
1753 }
 
1754 return p->z;
1755 }
1756
1757 /*
1758 ** If an input line begins with "." then invoke this routine to
1759
--- src/shell.c
+++ src/shell.c
@@ -1719,11 +1719,10 @@
1719 || (c=='\n' && pc==cQuote)
1720 || (c=='\n' && pc=='\r' && p->n>2 && p->z[p->n-2]==cQuote)
1721 || (c==EOF && pc==cQuote)
1722 ){
1723 do{ p->n--; }while( p->z[p->n]!=cQuote );
 
1724 p->cTerm = c;
1725 break;
1726 }
1727 if( pc==cQuote && c!='\r' ){
1728 fprintf(stderr, "%s:%d: unescaped %c character\n",
@@ -1730,11 +1729,10 @@
1729 p->zFile, p->nLine, cQuote);
1730 }
1731 if( c==EOF ){
1732 fprintf(stderr, "%s:%d: unterminated %c-quoted field\n",
1733 p->zFile, startLine, cQuote);
 
1734 p->cTerm = EOF;
1735 break;
1736 }
1737 csv_append_char(p, c);
1738 pc = c;
@@ -1746,13 +1744,13 @@
1744 }
1745 if( c=='\n' ){
1746 p->nLine++;
1747 if( p->n>1 && p->z[p->n-1]=='\r' ) p->n--;
1748 }
 
1749 p->cTerm = c;
1750 }
1751 if( p->z ) p->z[p->n] = 0;
1752 return p->z;
1753 }
1754
1755 /*
1756 ** If an input line begins with "." then invoke this routine to
1757
+295 -111
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -670,11 +670,11 @@
670670
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
671671
** [sqlite_version()] and [sqlite_source_id()].
672672
*/
673673
#define SQLITE_VERSION "3.8.0"
674674
#define SQLITE_VERSION_NUMBER 3008000
675
-#define SQLITE_SOURCE_ID "2013-07-09 03:04:32 52a49cbc1621094b2fe2b021209b768d29e0426b"
675
+#define SQLITE_SOURCE_ID "2013-07-17 11:54:47 64bf8148b84e0ebb45c12b629f49bc9b316aceba"
676676
677677
/*
678678
** CAPI3REF: Run-Time Library Version Numbers
679679
** KEYWORDS: sqlite3_version, sqlite3_sourceid
680680
**
@@ -3120,11 +3120,11 @@
31203120
** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
31213121
** database connection D. An example use for this
31223122
** interface is to keep a GUI updated during a large query.
31233123
**
31243124
** ^The parameter P is passed through as the only parameter to the
3125
-** callback function X. ^The parameter N is the number of
3125
+** callback function X. ^The parameter N is the approximate number of
31263126
** [virtual machine instructions] that are evaluated between successive
31273127
** invocations of the callback X.
31283128
**
31293129
** ^Only a single progress handler may be defined at one time per
31303130
** [database connection]; setting a new progress handler cancels the
@@ -5689,14 +5689,27 @@
56895689
**
56905690
** ^Calling sqlite3_auto_extension(X) with an entry point X that is already
56915691
** on the list of automatic extensions is a harmless no-op. ^No entry point
56925692
** will be called more than once for each database connection that is opened.
56935693
**
5694
-** See also: [sqlite3_reset_auto_extension()].
5694
+** See also: [sqlite3_reset_auto_extension()]
5695
+** and [sqlite3_cancel_auto_extension()]
56955696
*/
56965697
SQLITE_API int sqlite3_auto_extension(void (*xEntryPoint)(void));
56975698
5699
+/*
5700
+** CAPI3REF: Cancel Automatic Extension Loading
5701
+**
5702
+** ^The [sqlite3_cancel_auto_extension(X)] interface unregisters the
5703
+** initialization routine X that was registered using a prior call to
5704
+** [sqlite3_auto_extension(X)]. ^The [sqlite3_cancel_auto_extension(X)]
5705
+** routine returns 1 if initialization routine X was successfully
5706
+** unregistered and it returns 0 if X was not on the list of initialization
5707
+** routines.
5708
+*/
5709
+SQLITE_API int sqlite3_cancel_auto_extension(void (*xEntryPoint)(void));
5710
+
56985711
/*
56995712
** CAPI3REF: Reset Automatic Extension Loading
57005713
**
57015714
** ^This interface disables all automatic extensions previously
57025715
** registered using [sqlite3_auto_extension()].
@@ -6805,10 +6818,16 @@
68056818
** transaction rollback or database recovery operations are not included.
68066819
** If an IO or other error occurs while writing a page to disk, the effect
68076820
** on subsequent SQLITE_DBSTATUS_CACHE_WRITE requests is undefined.)^ ^The
68086821
** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0.
68096822
** </dd>
6823
+**
6824
+** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt>
6825
+** <dd>This parameter returns the zero for the current value if and only if
6826
+** there all foreign key constraints (deferred or immediate) have been
6827
+** resolved. The highwater mark is always 0.
6828
+** </dd>
68106829
** </dl>
68116830
*/
68126831
#define SQLITE_DBSTATUS_LOOKASIDE_USED 0
68136832
#define SQLITE_DBSTATUS_CACHE_USED 1
68146833
#define SQLITE_DBSTATUS_SCHEMA_USED 2
@@ -6817,11 +6836,12 @@
68176836
#define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5
68186837
#define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6
68196838
#define SQLITE_DBSTATUS_CACHE_HIT 7
68206839
#define SQLITE_DBSTATUS_CACHE_MISS 8
68216840
#define SQLITE_DBSTATUS_CACHE_WRITE 9
6822
-#define SQLITE_DBSTATUS_MAX 9 /* Largest defined DBSTATUS */
6841
+#define SQLITE_DBSTATUS_DEFERRED_FKS 10
6842
+#define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */
68236843
68246844
68256845
/*
68266846
** CAPI3REF: Prepared Statement Status
68276847
**
@@ -10117,11 +10137,11 @@
1011710137
void *pAuthArg; /* 1st argument to the access auth function */
1011810138
#endif
1011910139
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
1012010140
int (*xProgress)(void *); /* The progress callback */
1012110141
void *pProgressArg; /* Argument to the progress callback */
10122
- int nProgressOps; /* Number of opcodes for progress callback */
10142
+ unsigned nProgressOps; /* Number of opcodes for progress callback */
1012310143
#endif
1012410144
#ifndef SQLITE_OMIT_VIRTUALTABLE
1012510145
int nVTrans; /* Allocated size of aVTrans */
1012610146
Hash aModule; /* populated by sqlite3_create_module() */
1012710147
VtabCtx *pVtabCtx; /* Context for active vtab connect/create */
@@ -10135,10 +10155,11 @@
1013510155
Savepoint *pSavepoint; /* List of active savepoints */
1013610156
int busyTimeout; /* Busy handler timeout, in msec */
1013710157
int nSavepoint; /* Number of non-transaction savepoints */
1013810158
int nStatement; /* Number of nested statement-transactions */
1013910159
i64 nDeferredCons; /* Net deferred constraints this transaction. */
10160
+ i64 nDeferredImmCons; /* Net deferred immediate constraints */
1014010161
int *pnBytesFreed; /* If not NULL, increment this in DbFree() */
1014110162
1014210163
#ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
1014310164
/* The following variables are all protected by the STATIC_MASTER
1014410165
** mutex, not by sqlite3.mutex. They are used by code in notify.c.
@@ -10190,10 +10211,13 @@
1019010211
#define SQLITE_ForeignKeys 0x00040000 /* Enforce foreign key constraints */
1019110212
#define SQLITE_AutoIndex 0x00080000 /* Enable automatic indexes */
1019210213
#define SQLITE_PreferBuiltin 0x00100000 /* Preference to built-in funcs */
1019310214
#define SQLITE_LoadExtension 0x00200000 /* Enable load_extension */
1019410215
#define SQLITE_EnableTrigger 0x00400000 /* True to enable triggers */
10216
+#define SQLITE_DeferFKs 0x00800000 /* Defer all FK constraints */
10217
+#define SQLITE_QueryOnly 0x01000000 /* Disable database changes */
10218
+
1019510219
1019610220
/*
1019710221
** Bits of the sqlite3.dbOptFlags field that are used by the
1019810222
** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
1019910223
** selectively disable various optimizations.
@@ -10336,10 +10360,11 @@
1033610360
** OP_Savepoint instruction.
1033710361
*/
1033810362
struct Savepoint {
1033910363
char *zName; /* Savepoint name (nul-terminated) */
1034010364
i64 nDeferredCons; /* Number of deferred fk violations */
10365
+ i64 nDeferredImmCons; /* Number of deferred imm fk. */
1034110366
Savepoint *pNext; /* Parent savepoint (if any) */
1034210367
};
1034310368
1034410369
/*
1034510370
** The following are used as the second parameter to sqlite3Savepoint(),
@@ -13530,10 +13555,11 @@
1353013555
#ifndef SQLITE_OMIT_TRACE
1353113556
i64 startTime; /* Time when query started - used for profiling */
1353213557
#endif
1353313558
i64 nFkConstraint; /* Number of imm. FK constraints this VM */
1353413559
i64 nStmtDefCons; /* Number of def. constraints when stmt started */
13560
+ i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */
1353513561
char *zSql; /* Text of the SQL statement that generated this */
1353613562
void *pFree; /* Free this when deleting the vdbe */
1353713563
#ifdef SQLITE_DEBUG
1353813564
FILE *trace; /* Write an execution trace here, if not NULL */
1353913565
#endif
@@ -13889,10 +13915,20 @@
1388913915
}
1389013916
*pHighwater = 0;
1389113917
*pCurrent = nRet;
1389213918
break;
1389313919
}
13920
+
13921
+ /* Set *pCurrent to non-zero if there are unresolved deferred foreign
13922
+ ** key constraints. Set *pCurrent to zero if all foreign key constraints
13923
+ ** have been satisfied. The *pHighwater is always set to zero.
13924
+ */
13925
+ case SQLITE_DBSTATUS_DEFERRED_FKS: {
13926
+ *pHighwater = 0;
13927
+ *pCurrent = db->nDeferredImmCons>0 || db->nDeferredCons>0;
13928
+ break;
13929
+ }
1389413930
1389513931
default: {
1389613932
rc = SQLITE_ERROR;
1389713933
}
1389813934
}
@@ -61946,10 +61982,11 @@
6194661982
/* If the statement transaction is being rolled back, also restore the
6194761983
** database handles deferred constraint counter to the value it had when
6194861984
** the statement transaction was opened. */
6194961985
if( eOp==SAVEPOINT_ROLLBACK ){
6195061986
db->nDeferredCons = p->nStmtDefCons;
61987
+ db->nDeferredImmCons = p->nStmtDefImmCons;
6195161988
}
6195261989
}
6195361990
return rc;
6195461991
}
6195561992
@@ -61964,11 +62001,13 @@
6196462001
** and write an error message to it. Then return SQLITE_ERROR.
6196562002
*/
6196662003
#ifndef SQLITE_OMIT_FOREIGN_KEY
6196762004
SQLITE_PRIVATE int sqlite3VdbeCheckFk(Vdbe *p, int deferred){
6196862005
sqlite3 *db = p->db;
61969
- if( (deferred && db->nDeferredCons>0) || (!deferred && p->nFkConstraint>0) ){
62006
+ if( (deferred && (db->nDeferredCons+db->nDeferredImmCons)>0)
62007
+ || (!deferred && p->nFkConstraint>0)
62008
+ ){
6197062009
p->rc = SQLITE_CONSTRAINT_FOREIGNKEY;
6197162010
p->errorAction = OE_Abort;
6197262011
sqlite3SetString(&p->zErrMsg, db, "foreign key constraint failed");
6197362012
return SQLITE_ERROR;
6197462013
}
@@ -62097,10 +62136,12 @@
6209762136
}else if( rc!=SQLITE_OK ){
6209862137
p->rc = rc;
6209962138
sqlite3RollbackAll(db, SQLITE_OK);
6210062139
}else{
6210162140
db->nDeferredCons = 0;
62141
+ db->nDeferredImmCons = 0;
62142
+ db->flags &= ~SQLITE_DeferFKs;
6210262143
sqlite3CommitInternalChanges(db);
6210362144
}
6210462145
}else{
6210562146
sqlite3RollbackAll(db, SQLITE_OK);
6210662147
}
@@ -63536,11 +63577,13 @@
6353663577
*/
6353763578
if( db->nVdbeActive==0 ){
6353863579
db->u1.isInterrupted = 0;
6353963580
}
6354063581
63541
- assert( db->nVdbeWrite>0 || db->autoCommit==0 || db->nDeferredCons==0 );
63582
+ assert( db->nVdbeWrite>0 || db->autoCommit==0
63583
+ || (db->nDeferredCons==0 && db->nDeferredImmCons==0)
63584
+ );
6354263585
6354363586
#ifndef SQLITE_OMIT_TRACE
6354463587
if( db->xProfile && !db->init.busy ){
6354563588
sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime);
6354663589
}
@@ -65384,16 +65427,15 @@
6538465427
Op *pOp; /* Current operation */
6538565428
int rc = SQLITE_OK; /* Value to return */
6538665429
sqlite3 *db = p->db; /* The database */
6538765430
u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
6538865431
u8 encoding = ENC(db); /* The database encoding */
65389
-#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
65390
- int checkProgress; /* True if progress callbacks are enabled */
65391
- int nProgressOps = 0; /* Opcodes executed since progress callback. */
65392
-#endif
6539365432
int iCompare = 0; /* Result of last OP_Compare operation */
6539465433
unsigned nVmStep = 0; /* Number of virtual machine steps */
65434
+#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
65435
+ unsigned nProgressOps = 0; /* nVmStep at last progress callback. */
65436
+#endif
6539565437
Mem *aMem = p->aMem; /* Copy of p->aMem */
6539665438
Mem *pIn1 = 0; /* 1st input operand */
6539765439
Mem *pIn2 = 0; /* 2nd input operand */
6539865440
Mem *pIn3 = 0; /* 3rd input operand */
6539965441
Mem *pOut = 0; /* Output operand */
@@ -65847,13 +65889,10 @@
6584765889
assert( p->explain==0 );
6584865890
p->pResultSet = 0;
6584965891
db->busyHandler.nBusy = 0;
6585065892
CHECK_FOR_INTERRUPT;
6585165893
sqlite3VdbeIOTraceSql(p);
65852
-#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
65853
- checkProgress = db->xProgress!=0;
65854
-#endif
6585565894
#ifdef SQLITE_DEBUG
6585665895
sqlite3BeginBenignMalloc();
6585765896
if( p->pc==0 && (p->db->flags & SQLITE_VdbeListing)!=0 ){
6585865897
int i;
6585965898
printf("VDBE Program Listing:\n");
@@ -65895,31 +65934,10 @@
6589565934
sqlite3_interrupt_count--;
6589665935
if( sqlite3_interrupt_count==0 ){
6589765936
sqlite3_interrupt(db);
6589865937
}
6589965938
}
65900
-#endif
65901
-
65902
-#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
65903
- /* Call the progress callback if it is configured and the required number
65904
- ** of VDBE ops have been executed (either since this invocation of
65905
- ** sqlite3VdbeExec() or since last time the progress callback was called).
65906
- ** If the progress callback returns non-zero, exit the virtual machine with
65907
- ** a return code SQLITE_ABORT.
65908
- */
65909
- if( checkProgress ){
65910
- if( db->nProgressOps==nProgressOps ){
65911
- int prc;
65912
- prc = db->xProgress(db->pProgressArg);
65913
- if( prc!=0 ){
65914
- rc = SQLITE_INTERRUPT;
65915
- goto vdbe_error_halt;
65916
- }
65917
- nProgressOps = 0;
65918
- }
65919
- nProgressOps++;
65920
- }
6592165939
#endif
6592265940
6592365941
/* On any opcode with the "out2-prerelease" tag, free any
6592465942
** external allocations out of mem[p2] and set mem[p2] to be
6592565943
** an undefined integer. Opcodes will either fill in the integer
@@ -66010,12 +66028,42 @@
6601066028
** The next instruction executed will be
6601166029
** the one at index P2 from the beginning of
6601266030
** the program.
6601366031
*/
6601466032
case OP_Goto: { /* jump */
66015
- CHECK_FOR_INTERRUPT;
6601666033
pc = pOp->p2 - 1;
66034
+
66035
+ /* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev,
66036
+ ** OP_VNext, OP_RowSetNext, or OP_SorterNext) all jump here upon
66037
+ ** completion. Check to see if sqlite3_interrupt() has been called
66038
+ ** or if the progress callback needs to be invoked.
66039
+ **
66040
+ ** This code uses unstructured "goto" statements and does not look clean.
66041
+ ** But that is not due to sloppy coding habits. The code is written this
66042
+ ** way for performance, to avoid having to run the interrupt and progress
66043
+ ** checks on every opcode. This helps sqlite3_step() to run about 1.5%
66044
+ ** faster according to "valgrind --tool=cachegrind" */
66045
+check_for_interrupt:
66046
+ CHECK_FOR_INTERRUPT;
66047
+#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
66048
+ /* Call the progress callback if it is configured and the required number
66049
+ ** of VDBE ops have been executed (either since this invocation of
66050
+ ** sqlite3VdbeExec() or since last time the progress callback was called).
66051
+ ** If the progress callback returns non-zero, exit the virtual machine with
66052
+ ** a return code SQLITE_ABORT.
66053
+ */
66054
+ if( db->xProgress!=0 && (nVmStep - nProgressOps)>=db->nProgressOps ){
66055
+ int prc;
66056
+ prc = db->xProgress(db->pProgressArg);
66057
+ if( prc!=0 ){
66058
+ rc = SQLITE_INTERRUPT;
66059
+ goto vdbe_error_halt;
66060
+ }
66061
+ nProgressOps = nVmStep;
66062
+ }
66063
+#endif
66064
+
6601766065
break;
6601866066
}
6601966067
6602066068
/* Opcode: Gosub P1 P2 * * *
6602166069
**
@@ -66132,11 +66180,11 @@
6613266180
assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
6613366181
if( rc==SQLITE_BUSY ){
6613466182
p->rc = rc = SQLITE_BUSY;
6613566183
}else{
6613666184
assert( rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT );
66137
- assert( rc==SQLITE_OK || db->nDeferredCons>0 );
66185
+ assert( rc==SQLITE_OK || db->nDeferredCons>0 || db->nDeferredImmCons>0 );
6613866186
rc = p->rc ? SQLITE_ERROR : SQLITE_DONE;
6613966187
}
6614066188
goto vdbe_return;
6614166189
}
6614266190
@@ -68028,10 +68076,11 @@
6802868076
6802968077
/* Link the new savepoint into the database handle's list. */
6803068078
u.as.pNew->pNext = db->pSavepoint;
6803168079
db->pSavepoint = u.as.pNew;
6803268080
u.as.pNew->nDeferredCons = db->nDeferredCons;
68081
+ u.as.pNew->nDeferredImmCons = db->nDeferredImmCons;
6803368082
}
6803468083
}
6803568084
}else{
6803668085
u.as.iSavepoint = 0;
6803768086
@@ -68115,10 +68164,11 @@
6811568164
if( !isTransaction ){
6811668165
db->nSavepoint--;
6811768166
}
6811868167
}else{
6811968168
db->nDeferredCons = u.as.pSavepoint->nDeferredCons;
68169
+ db->nDeferredImmCons = u.as.pSavepoint->nDeferredImmCons;
6812068170
}
6812168171
6812268172
if( !isTransaction ){
6812368173
rc = sqlite3VtabSavepoint(db, u.as.p1, u.as.iSavepoint);
6812468174
if( rc!=SQLITE_OK ) goto abort_due_to_error;
@@ -68244,10 +68294,14 @@
6824468294
6824568295
assert( p->bIsReader );
6824668296
assert( p->readOnly==0 || pOp->p2==0 );
6824768297
assert( pOp->p1>=0 && pOp->p1<db->nDb );
6824868298
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
68299
+ if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){
68300
+ rc = SQLITE_READONLY;
68301
+ goto abort_due_to_error;
68302
+ }
6824968303
u.au.pBt = db->aDb[pOp->p1].pBt;
6825068304
6825168305
if( u.au.pBt ){
6825268306
rc = sqlite3BtreeBeginTrans(u.au.pBt, pOp->p2);
6825368307
if( rc==SQLITE_BUSY ){
@@ -68276,10 +68330,11 @@
6827668330
6827768331
/* Store the current value of the database handles deferred constraint
6827868332
** counter. If the statement transaction needs to be rolled back,
6827968333
** the value of this counter needs to be restored too. */
6828068334
p->nStmtDefCons = db->nDeferredCons;
68335
+ p->nStmtDefImmCons = db->nDeferredImmCons;
6828168336
}
6828268337
}
6828368338
break;
6828468339
}
6828568340
@@ -69851,11 +69906,10 @@
6985169906
#if 0 /* local variables moved into u.br */
6985269907
VdbeCursor *pC;
6985369908
int res;
6985469909
#endif /* local variables moved into u.br */
6985569910
69856
- CHECK_FOR_INTERRUPT;
6985769911
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
6985869912
assert( pOp->p5<=ArraySize(p->aCounter) );
6985969913
u.br.pC = p->apCsr[pOp->p1];
6986069914
if( u.br.pC==0 ){
6986169915
break; /* See ticket #2273 */
@@ -69880,11 +69934,11 @@
6988069934
#ifdef SQLITE_TEST
6988169935
sqlite3_search_count++;
6988269936
#endif
6988369937
}
6988469938
u.br.pC->rowidIsValid = 0;
69885
- break;
69939
+ goto check_for_interrupt;
6988669940
}
6988769941
6988869942
/* Opcode: IdxInsert P1 P2 P3 * P5
6988969943
**
6989069944
** Register P2 holds an SQL index key made using the
@@ -70426,11 +70480,11 @@
7042670480
*/
7042770481
case OP_RowSetRead: { /* jump, in1, out3 */
7042870482
#if 0 /* local variables moved into u.cb */
7042970483
i64 val;
7043070484
#endif /* local variables moved into u.cb */
70431
- CHECK_FOR_INTERRUPT;
70485
+
7043270486
pIn1 = &aMem[pOp->p1];
7043370487
if( (pIn1->flags & MEM_RowSet)==0
7043470488
|| sqlite3RowSetNext(pIn1->u.pRowSet, &u.cb.val)==0
7043570489
){
7043670490
/* The boolean index is empty */
@@ -70438,11 +70492,11 @@
7043870492
pc = pOp->p2 - 1;
7043970493
}else{
7044070494
/* A value was pulled from the index */
7044170495
sqlite3VdbeMemSetInt64(&aMem[pOp->p3], u.cb.val);
7044270496
}
70443
- break;
70497
+ goto check_for_interrupt;
7044470498
}
7044570499
7044670500
/* Opcode: RowSetTest P1 P2 P3 P4
7044770501
**
7044870502
** Register P3 is assumed to hold a 64-bit integer value. If register P1
@@ -70658,11 +70712,13 @@
7065870712
** If P1 is non-zero, the database constraint counter is incremented
7065970713
** (deferred foreign key constraints). Otherwise, if P1 is zero, the
7066070714
** statement counter is incremented (immediate foreign key constraints).
7066170715
*/
7066270716
case OP_FkCounter: {
70663
- if( pOp->p1 ){
70717
+ if( db->flags & SQLITE_DeferFKs ){
70718
+ db->nDeferredImmCons += pOp->p2;
70719
+ }else if( pOp->p1 ){
7066470720
db->nDeferredCons += pOp->p2;
7066570721
}else{
7066670722
p->nFkConstraint += pOp->p2;
7066770723
}
7066870724
break;
@@ -70679,13 +70735,13 @@
7067970735
** zero, the jump is taken if the statement constraint-counter is zero
7068070736
** (immediate foreign key constraint violations).
7068170737
*/
7068270738
case OP_FkIfZero: { /* jump */
7068370739
if( pOp->p1 ){
70684
- if( db->nDeferredCons==0 ) pc = pOp->p2-1;
70740
+ if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
7068570741
}else{
70686
- if( p->nFkConstraint==0 ) pc = pOp->p2-1;
70742
+ if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
7068770743
}
7068870744
break;
7068970745
}
7069070746
#endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */
7069170747
@@ -71367,11 +71423,11 @@
7136771423
7136871424
if( !u.cp.res ){
7136971425
/* If there is data, jump to P2 */
7137071426
pc = pOp->p2 - 1;
7137171427
}
71372
- break;
71428
+ goto check_for_interrupt;
7137371429
}
7137471430
#endif /* SQLITE_OMIT_VIRTUALTABLE */
7137571431
7137671432
#ifndef SQLITE_OMIT_VIRTUALTABLE
7137771433
/* Opcode: VRename P1 * * P4 *
@@ -89262,11 +89318,14 @@
8926289318
sqlite3ReleaseTempReg(pParse, regRec);
8926389319
sqlite3ReleaseTempRange(pParse, regTemp, nCol);
8926489320
}
8926589321
}
8926689322
89267
- if( !pFKey->isDeferred && !pParse->pToplevel && !pParse->isMultiWrite ){
89323
+ if( !pFKey->isDeferred && !(pParse->db->flags & SQLITE_DeferFKs)
89324
+ && !pParse->pToplevel
89325
+ && !pParse->isMultiWrite
89326
+ ){
8926889327
/* Special case: If this is an INSERT statement that will insert exactly
8926989328
** one row into the table, raise a constraint immediately instead of
8927089329
** incrementing a counter. This is necessary as the VM code is being
8927189330
** generated for will not open a statement transaction. */
8927289331
assert( nIncr==1 );
@@ -89653,11 +89712,13 @@
8965389712
for(pFKey = sqlite3FkReferences(pTab); pFKey; pFKey=pFKey->pNextTo){
8965489713
Index *pIdx = 0; /* Foreign key index for pFKey */
8965589714
SrcList *pSrc;
8965689715
int *aiCol = 0;
8965789716
89658
- if( !pFKey->isDeferred && !pParse->pToplevel && !pParse->isMultiWrite ){
89717
+ if( !pFKey->isDeferred && !(db->flags & SQLITE_DeferFKs)
89718
+ && !pParse->pToplevel && !pParse->isMultiWrite
89719
+ ){
8965989720
assert( regOld==0 && regNew!=0 );
8966089721
/* Inserting a single row into a parent table cannot cause an immediate
8966189722
** foreign key violation. So do nothing in this case. */
8966289723
continue;
8966389724
}
@@ -92615,15 +92676,18 @@
9261592676
#ifndef SQLITE_CORE
9261692677
/* This case when the file really is being compiled as a loadable
9261792678
** extension */
9261892679
# define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api=0;
9261992680
# define SQLITE_EXTENSION_INIT2(v) sqlite3_api=v;
92681
+# define SQLITE_EXTENSION_INIT3 \
92682
+ extern const sqlite3_api_routines *sqlite3_api;
9262092683
#else
9262192684
/* This case when the file is being statically linked into the
9262292685
** application */
9262392686
# define SQLITE_EXTENSION_INIT1 /*no-op*/
9262492687
# define SQLITE_EXTENSION_INIT2(v) (void)v; /* unused parameter */
92688
+# define SQLITE_EXTENSION_INIT3 /*no-op*/
9262592689
#endif
9262692690
9262792691
#endif /* _SQLITE3EXT_H_ */
9262892692
9262992693
/************** End of sqlite3ext.h ******************************************/
@@ -93275,10 +93339,39 @@
9327593339
sqlite3_mutex_leave(mutex);
9327693340
assert( (rc&0xff)==rc );
9327793341
return rc;
9327893342
}
9327993343
}
93344
+
93345
+/*
93346
+** Cancel a prior call to sqlite3_auto_extension. Remove xInit from the
93347
+** set of routines that is invoked for each new database connection, if it
93348
+** is currently on the list. If xInit is not on the list, then this
93349
+** routine is a no-op.
93350
+**
93351
+** Return 1 if xInit was found on the list and removed. Return 0 if xInit
93352
+** was not on the list.
93353
+*/
93354
+SQLITE_API int sqlite3_cancel_auto_extension(void (*xInit)(void)){
93355
+#if SQLITE_THREADSAFE
93356
+ sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
93357
+#endif
93358
+ int i;
93359
+ int n = 0;
93360
+ wsdAutoextInit;
93361
+ sqlite3_mutex_enter(mutex);
93362
+ for(i=wsdAutoext.nExt-1; i>=0; i--){
93363
+ if( wsdAutoext.aExt[i]==xInit ){
93364
+ wsdAutoext.nExt--;
93365
+ wsdAutoext.aExt[i] = wsdAutoext.aExt[wsdAutoext.nExt];
93366
+ n++;
93367
+ break;
93368
+ }
93369
+ }
93370
+ sqlite3_mutex_leave(mutex);
93371
+ return n;
93372
+}
9328093373
9328193374
/*
9328293375
** Reset the automatic extension loading mechanism.
9328393376
*/
9328493377
SQLITE_API void sqlite3_reset_auto_extension(void){
@@ -93516,10 +93609,11 @@
9351693609
{ "empty_result_callbacks", SQLITE_NullCallback },
9351793610
{ "legacy_file_format", SQLITE_LegacyFileFmt },
9351893611
{ "fullfsync", SQLITE_FullFSync },
9351993612
{ "checkpoint_fullfsync", SQLITE_CkptFullFSync },
9352093613
{ "reverse_unordered_selects", SQLITE_ReverseOrder },
93614
+ { "query_only", SQLITE_QueryOnly },
9352193615
#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
9352293616
{ "automatic_index", SQLITE_AutoIndex },
9352393617
#endif
9352493618
#ifdef SQLITE_DEBUG
9352593619
{ "sql_trace", SQLITE_SqlTrace },
@@ -93536,16 +93630,17 @@
9353693630
{ "writable_schema", SQLITE_WriteSchema|SQLITE_RecoveryMode },
9353793631
9353893632
/* TODO: Maybe it shouldn't be possible to change the ReadUncommitted
9353993633
** flag if there are any active statements. */
9354093634
{ "read_uncommitted", SQLITE_ReadUncommitted },
93541
- { "recursive_triggers", SQLITE_RecTriggers },
93635
+ { "recursive_triggers", SQLITE_RecTriggers },
9354293636
9354393637
/* This flag may only be set if both foreign-key and trigger support
9354493638
** are present in the build. */
9354593639
#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
93546
- { "foreign_keys", SQLITE_ForeignKeys },
93640
+ { "foreign_keys", SQLITE_ForeignKeys },
93641
+ { "defer_foreign_keys", SQLITE_DeferFKs },
9354793642
#endif
9354893643
};
9354993644
int i;
9355093645
const struct sPragmaType *p;
9355193646
for(i=0, p=aPragma; i<ArraySize(aPragma); i++, p++){
@@ -93567,10 +93662,11 @@
9356793662
9356893663
if( sqlite3GetBoolean(zRight, 0) ){
9356993664
db->flags |= mask;
9357093665
}else{
9357193666
db->flags &= ~mask;
93667
+ if( mask==SQLITE_DeferFKs ) db->nDeferredImmCons = 0;
9357293668
}
9357393669
9357493670
/* Many of the flag-pragmas modify the code generated by the SQL
9357593671
** compiler (eg. count_changes). So add an opcode to expire all
9357693672
** compiled SQL statements after modifying a pragma value.
@@ -95979,10 +96075,16 @@
9597996075
9598096076
assert( ppStmt );
9598196077
*ppStmt = 0;
9598296078
if( !sqlite3SafetyCheckOk(db) ){
9598396079
return SQLITE_MISUSE_BKPT;
96080
+ }
96081
+ if( nBytes>=0 ){
96082
+ int sz;
96083
+ const char *z = (const char*)zSql;
96084
+ for(sz=0; sz<nBytes && (z[sz]!=0 || z[sz+1]!=0); sz += 2){}
96085
+ nBytes = sz;
9598496086
}
9598596087
sqlite3_mutex_enter(db->mutex);
9598696088
zSql8 = sqlite3Utf16to8(db, zSql, nBytes, SQLITE_UTF16NATIVE);
9598796089
if( zSql8 ){
9598896090
rc = sqlite3LockAndPrepare(db, zSql8, -1, saveSqlFlag, 0, ppStmt, &zTail8);
@@ -104070,12 +104172,12 @@
104070104172
int (*x)(sqlite3_vtab *);
104071104173
sqlite3_vtab *pVtab = aVTrans[i]->pVtab;
104072104174
if( pVtab && (x = pVtab->pModule->xSync)!=0 ){
104073104175
rc = x(pVtab);
104074104176
sqlite3DbFree(db, *pzErrmsg);
104075
- *pzErrmsg = sqlite3DbStrDup(db, pVtab->zErrMsg);
104076
- sqlite3_free(pVtab->zErrMsg);
104177
+ *pzErrmsg = pVtab->zErrMsg;
104178
+ pVtab->zErrMsg = 0;
104077104179
}
104078104180
}
104079104181
db->aVTrans = aVTrans;
104080104182
return rc;
104081104183
}
@@ -104391,10 +104493,12 @@
104391104493
typedef struct WhereLoop WhereLoop;
104392104494
typedef struct WherePath WherePath;
104393104495
typedef struct WhereTerm WhereTerm;
104394104496
typedef struct WhereLoopBuilder WhereLoopBuilder;
104395104497
typedef struct WhereScan WhereScan;
104498
+typedef struct WhereOrCost WhereOrCost;
104499
+typedef struct WhereOrSet WhereOrSet;
104396104500
104397104501
/*
104398104502
** Cost X is tracked as 10*log2(X) stored in a 16-bit integer. The
104399104503
** maximum cost for ordinary tables is 64*(2**63) which becomes 6900.
104400104504
** (Virtual tables can return a larger cost, but let's assume they do not.)
@@ -104497,10 +104601,31 @@
104497104601
u16 nLSlot; /* Number of slots allocated for aLTerm[] */
104498104602
WhereTerm **aLTerm; /* WhereTerms used */
104499104603
WhereLoop *pNextLoop; /* Next WhereLoop object in the WhereClause */
104500104604
WhereTerm *aLTermSpace[4]; /* Initial aLTerm[] space */
104501104605
};
104606
+
104607
+/* This object holds the prerequisites and the cost of running a
104608
+** subquery on one operand of an OR operator in the WHERE clause.
104609
+** See WhereOrSet for additional information
104610
+*/
104611
+struct WhereOrCost {
104612
+ Bitmask prereq; /* Prerequisites */
104613
+ WhereCost rRun; /* Cost of running this subquery */
104614
+ WhereCost nOut; /* Number of outputs for this subquery */
104615
+};
104616
+
104617
+/* The WhereOrSet object holds a set of possible WhereOrCosts that
104618
+** correspond to the subquery(s) of OR-clause processing. At most
104619
+** favorable N_OR_COST elements are retained.
104620
+*/
104621
+#define N_OR_COST 3
104622
+struct WhereOrSet {
104623
+ u16 n; /* Number of valid a[] entries */
104624
+ WhereOrCost a[N_OR_COST]; /* Set of best costs */
104625
+};
104626
+
104502104627
104503104628
/* Forward declaration of methods */
104504104629
static int whereLoopResize(sqlite3*, WhereLoop*, int);
104505104630
104506104631
/*
@@ -104712,11 +104837,11 @@
104712104837
struct WhereLoopBuilder {
104713104838
WhereInfo *pWInfo; /* Information about this WHERE */
104714104839
WhereClause *pWC; /* WHERE clause terms */
104715104840
ExprList *pOrderBy; /* ORDER BY clause */
104716104841
WhereLoop *pNew; /* Template WhereLoop */
104717
- WhereLoop *pBest; /* If non-NULL, store single best loop here */
104842
+ WhereOrSet *pOrSet; /* Record best loops here, if not NULL */
104718104843
};
104719104844
104720104845
/*
104721104846
** The WHERE clause processing routine has two halves. The
104722104847
** first part does the start of the WHERE loop and the second
@@ -104854,10 +104979,58 @@
104854104979
** UPDATE or DELETE might change subsequent WHERE clause results.
104855104980
*/
104856104981
SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo *pWInfo){
104857104982
return pWInfo->okOnePass;
104858104983
}
104984
+
104985
+/*
104986
+** Move the content of pSrc into pDest
104987
+*/
104988
+static void whereOrMove(WhereOrSet *pDest, WhereOrSet *pSrc){
104989
+ pDest->n = pSrc->n;
104990
+ memcpy(pDest->a, pSrc->a, pDest->n*sizeof(pDest->a[0]));
104991
+}
104992
+
104993
+/*
104994
+** Try to insert a new prerequisite/cost entry into the WhereOrSet pSet.
104995
+**
104996
+** The new entry might overwrite an existing entry, or it might be
104997
+** appended, or it might be discarded. Do whatever is the right thing
104998
+** so that pSet keeps the N_OR_COST best entries seen so far.
104999
+*/
105000
+static int whereOrInsert(
105001
+ WhereOrSet *pSet, /* The WhereOrSet to be updated */
105002
+ Bitmask prereq, /* Prerequisites of the new entry */
105003
+ WhereCost rRun, /* Run-cost of the new entry */
105004
+ WhereCost nOut /* Number of outputs for the new entry */
105005
+){
105006
+ u16 i;
105007
+ WhereOrCost *p;
105008
+ for(i=pSet->n, p=pSet->a; i>0; i--, p++){
105009
+ if( rRun<=p->rRun && (prereq & p->prereq)==prereq ){
105010
+ goto whereOrInsert_done;
105011
+ }
105012
+ if( p->rRun<=rRun && (p->prereq & prereq)==p->prereq ){
105013
+ return 0;
105014
+ }
105015
+ }
105016
+ if( pSet->n<N_OR_COST ){
105017
+ p = &pSet->a[pSet->n++];
105018
+ p->nOut = nOut;
105019
+ }else{
105020
+ p = pSet->a;
105021
+ for(i=1; i<pSet->n; i++){
105022
+ if( p->rRun>pSet->a[i].rRun ) p = pSet->a + i;
105023
+ }
105024
+ if( p->rRun<=rRun ) return 0;
105025
+ }
105026
+whereOrInsert_done:
105027
+ p->prereq = prereq;
105028
+ p->rRun = rRun;
105029
+ if( p->nOut>nOut ) p->nOut = nOut;
105030
+ return 1;
105031
+}
104859105032
104860105033
/*
104861105034
** Initialize a preallocated WhereClause structure.
104862105035
*/
104863105036
static void whereClauseInit(
@@ -108089,12 +108262,13 @@
108089108262
*/
108090108263
if( pWC->nTerm>1 ){
108091108264
int iTerm;
108092108265
for(iTerm=0; iTerm<pWC->nTerm; iTerm++){
108093108266
Expr *pExpr = pWC->a[iTerm].pExpr;
108267
+ if( &pWC->a[iTerm] == pTerm ) continue;
108094108268
if( ExprHasProperty(pExpr, EP_FromJoin) ) continue;
108095
- if( pWC->a[iTerm].wtFlags & (TERM_VIRTUAL|TERM_ORINFO) ) continue;
108269
+ if( pWC->a[iTerm].wtFlags & (TERM_ORINFO) ) continue;
108096108270
if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue;
108097108271
pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
108098108272
pAndExpr = sqlite3ExprAnd(pParse->db, pAndExpr, pExpr);
108099108273
}
108100108274
if( pAndExpr ){
@@ -108418,16 +108592,16 @@
108418108592
** is better and has fewer dependencies. Or the template will be ignored
108419108593
** and no insert will occur if an existing WhereLoop is faster and has
108420108594
** fewer dependencies than the template. Otherwise a new WhereLoop is
108421108595
** added based on the template.
108422108596
**
108423
-** If pBuilder->pBest is not NULL then we only care about the very
108424
-** best template and that template should be stored in pBuilder->pBest.
108425
-** If pBuilder->pBest is NULL then a list of the best templates are stored
108426
-** in pBuilder->pWInfo->pLoops.
108597
+** If pBuilder->pOrSet is not NULL then we only care about only the
108598
+** prerequisites and rRun and nOut costs of the N best loops. That
108599
+** information is gathered in the pBuilder->pOrSet object. This special
108600
+** processing mode is used only for OR clause processing.
108427108601
**
108428
-** When accumulating multiple loops (when pBuilder->pBest is NULL) we
108602
+** When accumulating multiple loops (when pBuilder->pOrSet is NULL) we
108429108603
** still might overwrite similar loops with the new template if the
108430108604
** template is better. Loops may be overwritten if the following
108431108605
** conditions are met:
108432108606
**
108433108607
** (1) They have the same iTab.
@@ -108440,34 +108614,26 @@
108440108614
static int whereLoopInsert(WhereLoopBuilder *pBuilder, WhereLoop *pTemplate){
108441108615
WhereLoop **ppPrev, *p, *pNext = 0;
108442108616
WhereInfo *pWInfo = pBuilder->pWInfo;
108443108617
sqlite3 *db = pWInfo->pParse->db;
108444108618
108445
- /* If pBuilder->pBest is defined, then only keep track of the single
108446
- ** best WhereLoop. pBuilder->pBest->maskSelf==0 indicates that no
108447
- ** prior WhereLoops have been evaluated and that the current pTemplate
108448
- ** is therefore the first and hence the best and should be retained.
108619
+ /* If pBuilder->pOrSet is defined, then only keep track of the costs
108620
+ ** and prereqs.
108449108621
*/
108450
- if( (p = pBuilder->pBest)!=0 ){
108451
- if( p->maskSelf!=0 ){
108452
- WhereCost rCost = whereCostAdd(p->rRun,p->rSetup);
108453
- WhereCost rTemplate = whereCostAdd(pTemplate->rRun,pTemplate->rSetup);
108454
- if( rCost < rTemplate ){
108455
- testcase( rCost==rTemplate-1 );
108456
- goto whereLoopInsert_noop;
108457
- }
108458
- if( rCost==rTemplate && (p->prereq & pTemplate->prereq)==p->prereq ){
108459
- goto whereLoopInsert_noop;
108460
- }
108461
- }
108622
+ if( pBuilder->pOrSet!=0 ){
108623
+#if WHERETRACE_ENABLED
108624
+ u16 n = pBuilder->pOrSet->n;
108625
+ int x =
108626
+#endif
108627
+ whereOrInsert(pBuilder->pOrSet, pTemplate->prereq, pTemplate->rRun,
108628
+ pTemplate->nOut);
108462108629
#if WHERETRACE_ENABLED
108463108630
if( sqlite3WhereTrace & 0x8 ){
108464
- sqlite3DebugPrintf(p->maskSelf==0 ? "ins-init: " : "ins-best: ");
108631
+ sqlite3DebugPrintf(x?" or-%d: ":" or-X: ", n);
108465108632
whereLoopPrint(pTemplate, pWInfo->pTabList);
108466108633
}
108467108634
#endif
108468
- whereLoopXfer(db, p, pTemplate);
108469108635
return SQLITE_OK;
108470108636
}
108471108637
108472108638
/* Search for an existing WhereLoop to overwrite, or which takes
108473108639
** priority over pTemplate.
@@ -108557,11 +108723,11 @@
108557108723
108558108724
/* Jump here if the insert is a no-op */
108559108725
whereLoopInsert_noop:
108560108726
#if WHERETRACE_ENABLED
108561108727
if( sqlite3WhereTrace & 0x8 ){
108562
- sqlite3DebugPrintf(pBuilder->pBest ? "ins-skip: " : "ins-noop: ");
108728
+ sqlite3DebugPrintf("ins-noop: ");
108563108729
whereLoopPrint(pTemplate, pWInfo->pTabList);
108564108730
}
108565108731
#endif
108566108732
return SQLITE_OK;
108567108733
}
@@ -108839,11 +109005,11 @@
108839109005
}
108840109006
rSize = whereCost(pSrc->pTab->nRowEst);
108841109007
rLogSize = estLog(rSize);
108842109008
108843109009
/* Automatic indexes */
108844
- if( !pBuilder->pBest
109010
+ if( !pBuilder->pOrSet
108845109011
&& (pWInfo->pParse->db->flags & SQLITE_AutoIndex)!=0
108846109012
&& pSrc->pIndex==0
108847109013
&& !pSrc->viaCoroutine
108848109014
&& !pSrc->notIndexed
108849109015
&& !pSrc->isCorrelated
@@ -109125,11 +109291,11 @@
109125109291
WhereTerm *pTerm, *pWCEnd;
109126109292
int rc = SQLITE_OK;
109127109293
int iCur;
109128109294
WhereClause tempWC;
109129109295
WhereLoopBuilder sSubBuild;
109130
- WhereLoop sBest;
109296
+ WhereOrSet sSum, sCur, sPrev;
109131109297
struct SrcList_item *pItem;
109132109298
109133109299
pWC = pBuilder->pWC;
109134109300
if( pWInfo->wctrlFlags & WHERE_AND_ONLY ) return SQLITE_OK;
109135109301
pWCEnd = pWC->a + pWC->nTerm;
@@ -109140,20 +109306,18 @@
109140109306
&& (pTerm->u.pOrInfo->indexable & pNew->maskSelf)!=0
109141109307
){
109142109308
WhereClause * const pOrWC = &pTerm->u.pOrInfo->wc;
109143109309
WhereTerm * const pOrWCEnd = &pOrWC->a[pOrWC->nTerm];
109144109310
WhereTerm *pOrTerm;
109145
- WhereCost rTotal = 0;
109146
- WhereCost nRow = 0;
109147
- Bitmask prereq = mExtra;
109311
+ int once = 1;
109312
+ int i, j;
109148109313
109149
- whereLoopInit(&sBest);
109150109314
pItem = pWInfo->pTabList->a + pNew->iTab;
109151109315
iCur = pItem->iCursor;
109152109316
sSubBuild = *pBuilder;
109153109317
sSubBuild.pOrderBy = 0;
109154
- sSubBuild.pBest = &sBest;
109318
+ sSubBuild.pOrSet = &sCur;
109155109319
109156109320
for(pOrTerm=pOrWC->a; pOrTerm<pOrWCEnd; pOrTerm++){
109157109321
if( (pOrTerm->eOperator & WO_AND)!=0 ){
109158109322
sSubBuild.pWC = &pOrTerm->u.pAndInfo->wc;
109159109323
}else if( pOrTerm->leftCursor==iCur ){
@@ -109164,43 +109328,52 @@
109164109328
tempWC.a = pOrTerm;
109165109329
sSubBuild.pWC = &tempWC;
109166109330
}else{
109167109331
continue;
109168109332
}
109169
- sBest.maskSelf = 0;
109170
- sBest.rSetup = 0;
109171
- sBest.rRun = 0;
109333
+ sCur.n = 0;
109172109334
#ifndef SQLITE_OMIT_VIRTUALTABLE
109173109335
if( IsVirtual(pItem->pTab) ){
109174109336
rc = whereLoopAddVirtual(&sSubBuild);
109337
+ for(i=0; i<sCur.n; i++) sCur.a[i].prereq |= mExtra;
109175109338
}else
109176109339
#endif
109177109340
{
109178109341
rc = whereLoopAddBtree(&sSubBuild, mExtra);
109179109342
}
109180
- /* sBest.maskSelf is always zero if an error occurs */
109181
- assert( rc==SQLITE_OK || sBest.maskSelf==0 );
109182
- if( sBest.maskSelf==0 ) break;
109183
- assert( sBest.rSetup==0 );
109184
- rTotal = whereCostAdd(rTotal, sBest.rRun);
109185
- nRow = whereCostAdd(nRow, sBest.nOut);
109186
- prereq |= sBest.prereq;
109187
- }
109188
- assert( pNew->nLSlot>=1 );
109189
- if( sBest.maskSelf ){
109190
- pNew->nLTerm = 1;
109191
- pNew->aLTerm[0] = pTerm;
109192
- pNew->wsFlags = WHERE_MULTI_OR;
109193
- pNew->rSetup = 0;
109343
+ assert( rc==SQLITE_OK || sCur.n==0 );
109344
+ if( sCur.n==0 ){
109345
+ sSum.n = 0;
109346
+ break;
109347
+ }else if( once ){
109348
+ whereOrMove(&sSum, &sCur);
109349
+ once = 0;
109350
+ }else{
109351
+ whereOrMove(&sPrev, &sSum);
109352
+ sSum.n = 0;
109353
+ for(i=0; i<sPrev.n; i++){
109354
+ for(j=0; j<sCur.n; j++){
109355
+ whereOrInsert(&sSum, sPrev.a[i].prereq | sCur.a[j].prereq,
109356
+ whereCostAdd(sPrev.a[i].rRun, sCur.a[j].rRun),
109357
+ whereCostAdd(sPrev.a[i].nOut, sCur.a[j].nOut));
109358
+ }
109359
+ }
109360
+ }
109361
+ }
109362
+ pNew->nLTerm = 1;
109363
+ pNew->aLTerm[0] = pTerm;
109364
+ pNew->wsFlags = WHERE_MULTI_OR;
109365
+ pNew->rSetup = 0;
109366
+ pNew->iSortIdx = 0;
109367
+ memset(&pNew->u, 0, sizeof(pNew->u));
109368
+ for(i=0; rc==SQLITE_OK && i<sSum.n; i++){
109194109369
/* TUNING: Multiple by 3.5 for the secondary table lookup */
109195
- pNew->rRun = rTotal + 18; assert( 18==whereCost(7)-whereCost(2) );
109196
- pNew->nOut = nRow;
109197
- pNew->prereq = prereq;
109198
- memset(&pNew->u, 0, sizeof(pNew->u));
109370
+ pNew->rRun = sSum.a[i].rRun + 18;
109371
+ pNew->nOut = sSum.a[i].nOut;
109372
+ pNew->prereq = sSum.a[i].prereq;
109199109373
rc = whereLoopInsert(pBuilder, pNew);
109200109374
}
109201
- whereLoopClear(pWInfo->pParse->db, &sBest);
109202109375
}
109203109376
}
109204109377
return rc;
109205109378
}
109206109379
@@ -116127,10 +116300,12 @@
116127116300
}
116128116301
sqlite3BtreeLeaveAll(db);
116129116302
116130116303
/* Any deferred constraint violations have now been resolved. */
116131116304
db->nDeferredCons = 0;
116305
+ db->nDeferredImmCons = 0;
116306
+ db->flags &= ~SQLITE_DeferFKs;
116132116307
116133116308
/* If one has been configured, invoke the rollback-hook callback */
116134116309
if( db->xRollbackCallback && (inTrans || !db->autoCommit) ){
116135116310
db->xRollbackCallback(db->pRollbackArg);
116136116311
}
@@ -116388,11 +116563,11 @@
116388116563
void *pArg
116389116564
){
116390116565
sqlite3_mutex_enter(db->mutex);
116391116566
if( nOps>0 ){
116392116567
db->xProgress = xProgress;
116393
- db->nProgressOps = nOps;
116568
+ db->nProgressOps = (unsigned)nOps;
116394116569
db->pProgressArg = pArg;
116395116570
}else{
116396116571
db->xProgress = 0;
116397116572
db->nProgressOps = 0;
116398116573
db->pProgressArg = 0;
@@ -119087,11 +119262,11 @@
119087119262
119088119263
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
119089119264
119090119265
/* If not building as part of the core, include sqlite3ext.h. */
119091119266
#ifndef SQLITE_CORE
119092
-SQLITE_API extern const sqlite3_api_routines *sqlite3_api;
119267
+SQLITE_EXTENSION_INIT3
119093119268
#endif
119094119269
119095119270
/************** Include fts3_tokenizer.h in the middle of fts3Int.h **********/
119096119271
/************** Begin file fts3_tokenizer.h **********************************/
119097119272
/*
@@ -124995,11 +125170,14 @@
124995125170
124996125171
#if !SQLITE_CORE
124997125172
/*
124998125173
** Initialize API pointer table, if required.
124999125174
*/
125000
-SQLITE_API int sqlite3_extension_init(
125175
+#ifdef _WIN32
125176
+__declspec(dllexport)
125177
+#endif
125178
+SQLITE_API int sqlite3_fts3_init(
125001125179
sqlite3 *db,
125002125180
char **pzErrMsg,
125003125181
const sqlite3_api_routines *pApi
125004125182
){
125005125183
SQLITE_EXTENSION_INIT2(pApi)
@@ -140042,11 +140220,14 @@
140042140220
(void *)pGeomCtx, geomCallback, 0, 0, doSqlite3Free
140043140221
);
140044140222
}
140045140223
140046140224
#if !SQLITE_CORE
140047
-SQLITE_API int sqlite3_extension_init(
140225
+#ifdef _WIN32
140226
+__declspec(dllexport)
140227
+#endif
140228
+SQLITE_API int sqlite3_rtree_init(
140048140229
sqlite3 *db,
140049140230
char **pzErrMsg,
140050140231
const sqlite3_api_routines *pApi
140051140232
){
140052140233
SQLITE_EXTENSION_INIT2(pApi)
@@ -140544,11 +140725,14 @@
140544140725
140545140726
return rc;
140546140727
}
140547140728
140548140729
#if !SQLITE_CORE
140549
-SQLITE_API int sqlite3_extension_init(
140730
+#ifdef _WIN32
140731
+__declspec(dllexport)
140732
+#endif
140733
+SQLITE_API int sqlite3_icu_init(
140550140734
sqlite3 *db,
140551140735
char **pzErrMsg,
140552140736
const sqlite3_api_routines *pApi
140553140737
){
140554140738
SQLITE_EXTENSION_INIT2(pApi)
140555140739
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -670,11 +670,11 @@
670 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
671 ** [sqlite_version()] and [sqlite_source_id()].
672 */
673 #define SQLITE_VERSION "3.8.0"
674 #define SQLITE_VERSION_NUMBER 3008000
675 #define SQLITE_SOURCE_ID "2013-07-09 03:04:32 52a49cbc1621094b2fe2b021209b768d29e0426b"
676
677 /*
678 ** CAPI3REF: Run-Time Library Version Numbers
679 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
680 **
@@ -3120,11 +3120,11 @@
3120 ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
3121 ** database connection D. An example use for this
3122 ** interface is to keep a GUI updated during a large query.
3123 **
3124 ** ^The parameter P is passed through as the only parameter to the
3125 ** callback function X. ^The parameter N is the number of
3126 ** [virtual machine instructions] that are evaluated between successive
3127 ** invocations of the callback X.
3128 **
3129 ** ^Only a single progress handler may be defined at one time per
3130 ** [database connection]; setting a new progress handler cancels the
@@ -5689,14 +5689,27 @@
5689 **
5690 ** ^Calling sqlite3_auto_extension(X) with an entry point X that is already
5691 ** on the list of automatic extensions is a harmless no-op. ^No entry point
5692 ** will be called more than once for each database connection that is opened.
5693 **
5694 ** See also: [sqlite3_reset_auto_extension()].
 
5695 */
5696 SQLITE_API int sqlite3_auto_extension(void (*xEntryPoint)(void));
5697
 
 
 
 
 
 
 
 
 
 
 
 
5698 /*
5699 ** CAPI3REF: Reset Automatic Extension Loading
5700 **
5701 ** ^This interface disables all automatic extensions previously
5702 ** registered using [sqlite3_auto_extension()].
@@ -6805,10 +6818,16 @@
6805 ** transaction rollback or database recovery operations are not included.
6806 ** If an IO or other error occurs while writing a page to disk, the effect
6807 ** on subsequent SQLITE_DBSTATUS_CACHE_WRITE requests is undefined.)^ ^The
6808 ** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0.
6809 ** </dd>
 
 
 
 
 
 
6810 ** </dl>
6811 */
6812 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
6813 #define SQLITE_DBSTATUS_CACHE_USED 1
6814 #define SQLITE_DBSTATUS_SCHEMA_USED 2
@@ -6817,11 +6836,12 @@
6817 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5
6818 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6
6819 #define SQLITE_DBSTATUS_CACHE_HIT 7
6820 #define SQLITE_DBSTATUS_CACHE_MISS 8
6821 #define SQLITE_DBSTATUS_CACHE_WRITE 9
6822 #define SQLITE_DBSTATUS_MAX 9 /* Largest defined DBSTATUS */
 
6823
6824
6825 /*
6826 ** CAPI3REF: Prepared Statement Status
6827 **
@@ -10117,11 +10137,11 @@
10117 void *pAuthArg; /* 1st argument to the access auth function */
10118 #endif
10119 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
10120 int (*xProgress)(void *); /* The progress callback */
10121 void *pProgressArg; /* Argument to the progress callback */
10122 int nProgressOps; /* Number of opcodes for progress callback */
10123 #endif
10124 #ifndef SQLITE_OMIT_VIRTUALTABLE
10125 int nVTrans; /* Allocated size of aVTrans */
10126 Hash aModule; /* populated by sqlite3_create_module() */
10127 VtabCtx *pVtabCtx; /* Context for active vtab connect/create */
@@ -10135,10 +10155,11 @@
10135 Savepoint *pSavepoint; /* List of active savepoints */
10136 int busyTimeout; /* Busy handler timeout, in msec */
10137 int nSavepoint; /* Number of non-transaction savepoints */
10138 int nStatement; /* Number of nested statement-transactions */
10139 i64 nDeferredCons; /* Net deferred constraints this transaction. */
 
10140 int *pnBytesFreed; /* If not NULL, increment this in DbFree() */
10141
10142 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
10143 /* The following variables are all protected by the STATIC_MASTER
10144 ** mutex, not by sqlite3.mutex. They are used by code in notify.c.
@@ -10190,10 +10211,13 @@
10190 #define SQLITE_ForeignKeys 0x00040000 /* Enforce foreign key constraints */
10191 #define SQLITE_AutoIndex 0x00080000 /* Enable automatic indexes */
10192 #define SQLITE_PreferBuiltin 0x00100000 /* Preference to built-in funcs */
10193 #define SQLITE_LoadExtension 0x00200000 /* Enable load_extension */
10194 #define SQLITE_EnableTrigger 0x00400000 /* True to enable triggers */
 
 
 
10195
10196 /*
10197 ** Bits of the sqlite3.dbOptFlags field that are used by the
10198 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
10199 ** selectively disable various optimizations.
@@ -10336,10 +10360,11 @@
10336 ** OP_Savepoint instruction.
10337 */
10338 struct Savepoint {
10339 char *zName; /* Savepoint name (nul-terminated) */
10340 i64 nDeferredCons; /* Number of deferred fk violations */
 
10341 Savepoint *pNext; /* Parent savepoint (if any) */
10342 };
10343
10344 /*
10345 ** The following are used as the second parameter to sqlite3Savepoint(),
@@ -13530,10 +13555,11 @@
13530 #ifndef SQLITE_OMIT_TRACE
13531 i64 startTime; /* Time when query started - used for profiling */
13532 #endif
13533 i64 nFkConstraint; /* Number of imm. FK constraints this VM */
13534 i64 nStmtDefCons; /* Number of def. constraints when stmt started */
 
13535 char *zSql; /* Text of the SQL statement that generated this */
13536 void *pFree; /* Free this when deleting the vdbe */
13537 #ifdef SQLITE_DEBUG
13538 FILE *trace; /* Write an execution trace here, if not NULL */
13539 #endif
@@ -13889,10 +13915,20 @@
13889 }
13890 *pHighwater = 0;
13891 *pCurrent = nRet;
13892 break;
13893 }
 
 
 
 
 
 
 
 
 
 
13894
13895 default: {
13896 rc = SQLITE_ERROR;
13897 }
13898 }
@@ -61946,10 +61982,11 @@
61946 /* If the statement transaction is being rolled back, also restore the
61947 ** database handles deferred constraint counter to the value it had when
61948 ** the statement transaction was opened. */
61949 if( eOp==SAVEPOINT_ROLLBACK ){
61950 db->nDeferredCons = p->nStmtDefCons;
 
61951 }
61952 }
61953 return rc;
61954 }
61955
@@ -61964,11 +62001,13 @@
61964 ** and write an error message to it. Then return SQLITE_ERROR.
61965 */
61966 #ifndef SQLITE_OMIT_FOREIGN_KEY
61967 SQLITE_PRIVATE int sqlite3VdbeCheckFk(Vdbe *p, int deferred){
61968 sqlite3 *db = p->db;
61969 if( (deferred && db->nDeferredCons>0) || (!deferred && p->nFkConstraint>0) ){
 
 
61970 p->rc = SQLITE_CONSTRAINT_FOREIGNKEY;
61971 p->errorAction = OE_Abort;
61972 sqlite3SetString(&p->zErrMsg, db, "foreign key constraint failed");
61973 return SQLITE_ERROR;
61974 }
@@ -62097,10 +62136,12 @@
62097 }else if( rc!=SQLITE_OK ){
62098 p->rc = rc;
62099 sqlite3RollbackAll(db, SQLITE_OK);
62100 }else{
62101 db->nDeferredCons = 0;
 
 
62102 sqlite3CommitInternalChanges(db);
62103 }
62104 }else{
62105 sqlite3RollbackAll(db, SQLITE_OK);
62106 }
@@ -63536,11 +63577,13 @@
63536 */
63537 if( db->nVdbeActive==0 ){
63538 db->u1.isInterrupted = 0;
63539 }
63540
63541 assert( db->nVdbeWrite>0 || db->autoCommit==0 || db->nDeferredCons==0 );
 
 
63542
63543 #ifndef SQLITE_OMIT_TRACE
63544 if( db->xProfile && !db->init.busy ){
63545 sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime);
63546 }
@@ -65384,16 +65427,15 @@
65384 Op *pOp; /* Current operation */
65385 int rc = SQLITE_OK; /* Value to return */
65386 sqlite3 *db = p->db; /* The database */
65387 u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
65388 u8 encoding = ENC(db); /* The database encoding */
65389 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
65390 int checkProgress; /* True if progress callbacks are enabled */
65391 int nProgressOps = 0; /* Opcodes executed since progress callback. */
65392 #endif
65393 int iCompare = 0; /* Result of last OP_Compare operation */
65394 unsigned nVmStep = 0; /* Number of virtual machine steps */
 
 
 
65395 Mem *aMem = p->aMem; /* Copy of p->aMem */
65396 Mem *pIn1 = 0; /* 1st input operand */
65397 Mem *pIn2 = 0; /* 2nd input operand */
65398 Mem *pIn3 = 0; /* 3rd input operand */
65399 Mem *pOut = 0; /* Output operand */
@@ -65847,13 +65889,10 @@
65847 assert( p->explain==0 );
65848 p->pResultSet = 0;
65849 db->busyHandler.nBusy = 0;
65850 CHECK_FOR_INTERRUPT;
65851 sqlite3VdbeIOTraceSql(p);
65852 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
65853 checkProgress = db->xProgress!=0;
65854 #endif
65855 #ifdef SQLITE_DEBUG
65856 sqlite3BeginBenignMalloc();
65857 if( p->pc==0 && (p->db->flags & SQLITE_VdbeListing)!=0 ){
65858 int i;
65859 printf("VDBE Program Listing:\n");
@@ -65895,31 +65934,10 @@
65895 sqlite3_interrupt_count--;
65896 if( sqlite3_interrupt_count==0 ){
65897 sqlite3_interrupt(db);
65898 }
65899 }
65900 #endif
65901
65902 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
65903 /* Call the progress callback if it is configured and the required number
65904 ** of VDBE ops have been executed (either since this invocation of
65905 ** sqlite3VdbeExec() or since last time the progress callback was called).
65906 ** If the progress callback returns non-zero, exit the virtual machine with
65907 ** a return code SQLITE_ABORT.
65908 */
65909 if( checkProgress ){
65910 if( db->nProgressOps==nProgressOps ){
65911 int prc;
65912 prc = db->xProgress(db->pProgressArg);
65913 if( prc!=0 ){
65914 rc = SQLITE_INTERRUPT;
65915 goto vdbe_error_halt;
65916 }
65917 nProgressOps = 0;
65918 }
65919 nProgressOps++;
65920 }
65921 #endif
65922
65923 /* On any opcode with the "out2-prerelease" tag, free any
65924 ** external allocations out of mem[p2] and set mem[p2] to be
65925 ** an undefined integer. Opcodes will either fill in the integer
@@ -66010,12 +66028,42 @@
66010 ** The next instruction executed will be
66011 ** the one at index P2 from the beginning of
66012 ** the program.
66013 */
66014 case OP_Goto: { /* jump */
66015 CHECK_FOR_INTERRUPT;
66016 pc = pOp->p2 - 1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66017 break;
66018 }
66019
66020 /* Opcode: Gosub P1 P2 * * *
66021 **
@@ -66132,11 +66180,11 @@
66132 assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
66133 if( rc==SQLITE_BUSY ){
66134 p->rc = rc = SQLITE_BUSY;
66135 }else{
66136 assert( rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT );
66137 assert( rc==SQLITE_OK || db->nDeferredCons>0 );
66138 rc = p->rc ? SQLITE_ERROR : SQLITE_DONE;
66139 }
66140 goto vdbe_return;
66141 }
66142
@@ -68028,10 +68076,11 @@
68028
68029 /* Link the new savepoint into the database handle's list. */
68030 u.as.pNew->pNext = db->pSavepoint;
68031 db->pSavepoint = u.as.pNew;
68032 u.as.pNew->nDeferredCons = db->nDeferredCons;
 
68033 }
68034 }
68035 }else{
68036 u.as.iSavepoint = 0;
68037
@@ -68115,10 +68164,11 @@
68115 if( !isTransaction ){
68116 db->nSavepoint--;
68117 }
68118 }else{
68119 db->nDeferredCons = u.as.pSavepoint->nDeferredCons;
 
68120 }
68121
68122 if( !isTransaction ){
68123 rc = sqlite3VtabSavepoint(db, u.as.p1, u.as.iSavepoint);
68124 if( rc!=SQLITE_OK ) goto abort_due_to_error;
@@ -68244,10 +68294,14 @@
68244
68245 assert( p->bIsReader );
68246 assert( p->readOnly==0 || pOp->p2==0 );
68247 assert( pOp->p1>=0 && pOp->p1<db->nDb );
68248 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
 
 
 
 
68249 u.au.pBt = db->aDb[pOp->p1].pBt;
68250
68251 if( u.au.pBt ){
68252 rc = sqlite3BtreeBeginTrans(u.au.pBt, pOp->p2);
68253 if( rc==SQLITE_BUSY ){
@@ -68276,10 +68330,11 @@
68276
68277 /* Store the current value of the database handles deferred constraint
68278 ** counter. If the statement transaction needs to be rolled back,
68279 ** the value of this counter needs to be restored too. */
68280 p->nStmtDefCons = db->nDeferredCons;
 
68281 }
68282 }
68283 break;
68284 }
68285
@@ -69851,11 +69906,10 @@
69851 #if 0 /* local variables moved into u.br */
69852 VdbeCursor *pC;
69853 int res;
69854 #endif /* local variables moved into u.br */
69855
69856 CHECK_FOR_INTERRUPT;
69857 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
69858 assert( pOp->p5<=ArraySize(p->aCounter) );
69859 u.br.pC = p->apCsr[pOp->p1];
69860 if( u.br.pC==0 ){
69861 break; /* See ticket #2273 */
@@ -69880,11 +69934,11 @@
69880 #ifdef SQLITE_TEST
69881 sqlite3_search_count++;
69882 #endif
69883 }
69884 u.br.pC->rowidIsValid = 0;
69885 break;
69886 }
69887
69888 /* Opcode: IdxInsert P1 P2 P3 * P5
69889 **
69890 ** Register P2 holds an SQL index key made using the
@@ -70426,11 +70480,11 @@
70426 */
70427 case OP_RowSetRead: { /* jump, in1, out3 */
70428 #if 0 /* local variables moved into u.cb */
70429 i64 val;
70430 #endif /* local variables moved into u.cb */
70431 CHECK_FOR_INTERRUPT;
70432 pIn1 = &aMem[pOp->p1];
70433 if( (pIn1->flags & MEM_RowSet)==0
70434 || sqlite3RowSetNext(pIn1->u.pRowSet, &u.cb.val)==0
70435 ){
70436 /* The boolean index is empty */
@@ -70438,11 +70492,11 @@
70438 pc = pOp->p2 - 1;
70439 }else{
70440 /* A value was pulled from the index */
70441 sqlite3VdbeMemSetInt64(&aMem[pOp->p3], u.cb.val);
70442 }
70443 break;
70444 }
70445
70446 /* Opcode: RowSetTest P1 P2 P3 P4
70447 **
70448 ** Register P3 is assumed to hold a 64-bit integer value. If register P1
@@ -70658,11 +70712,13 @@
70658 ** If P1 is non-zero, the database constraint counter is incremented
70659 ** (deferred foreign key constraints). Otherwise, if P1 is zero, the
70660 ** statement counter is incremented (immediate foreign key constraints).
70661 */
70662 case OP_FkCounter: {
70663 if( pOp->p1 ){
 
 
70664 db->nDeferredCons += pOp->p2;
70665 }else{
70666 p->nFkConstraint += pOp->p2;
70667 }
70668 break;
@@ -70679,13 +70735,13 @@
70679 ** zero, the jump is taken if the statement constraint-counter is zero
70680 ** (immediate foreign key constraint violations).
70681 */
70682 case OP_FkIfZero: { /* jump */
70683 if( pOp->p1 ){
70684 if( db->nDeferredCons==0 ) pc = pOp->p2-1;
70685 }else{
70686 if( p->nFkConstraint==0 ) pc = pOp->p2-1;
70687 }
70688 break;
70689 }
70690 #endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */
70691
@@ -71367,11 +71423,11 @@
71367
71368 if( !u.cp.res ){
71369 /* If there is data, jump to P2 */
71370 pc = pOp->p2 - 1;
71371 }
71372 break;
71373 }
71374 #endif /* SQLITE_OMIT_VIRTUALTABLE */
71375
71376 #ifndef SQLITE_OMIT_VIRTUALTABLE
71377 /* Opcode: VRename P1 * * P4 *
@@ -89262,11 +89318,14 @@
89262 sqlite3ReleaseTempReg(pParse, regRec);
89263 sqlite3ReleaseTempRange(pParse, regTemp, nCol);
89264 }
89265 }
89266
89267 if( !pFKey->isDeferred && !pParse->pToplevel && !pParse->isMultiWrite ){
 
 
 
89268 /* Special case: If this is an INSERT statement that will insert exactly
89269 ** one row into the table, raise a constraint immediately instead of
89270 ** incrementing a counter. This is necessary as the VM code is being
89271 ** generated for will not open a statement transaction. */
89272 assert( nIncr==1 );
@@ -89653,11 +89712,13 @@
89653 for(pFKey = sqlite3FkReferences(pTab); pFKey; pFKey=pFKey->pNextTo){
89654 Index *pIdx = 0; /* Foreign key index for pFKey */
89655 SrcList *pSrc;
89656 int *aiCol = 0;
89657
89658 if( !pFKey->isDeferred && !pParse->pToplevel && !pParse->isMultiWrite ){
 
 
89659 assert( regOld==0 && regNew!=0 );
89660 /* Inserting a single row into a parent table cannot cause an immediate
89661 ** foreign key violation. So do nothing in this case. */
89662 continue;
89663 }
@@ -92615,15 +92676,18 @@
92615 #ifndef SQLITE_CORE
92616 /* This case when the file really is being compiled as a loadable
92617 ** extension */
92618 # define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api=0;
92619 # define SQLITE_EXTENSION_INIT2(v) sqlite3_api=v;
 
 
92620 #else
92621 /* This case when the file is being statically linked into the
92622 ** application */
92623 # define SQLITE_EXTENSION_INIT1 /*no-op*/
92624 # define SQLITE_EXTENSION_INIT2(v) (void)v; /* unused parameter */
 
92625 #endif
92626
92627 #endif /* _SQLITE3EXT_H_ */
92628
92629 /************** End of sqlite3ext.h ******************************************/
@@ -93275,10 +93339,39 @@
93275 sqlite3_mutex_leave(mutex);
93276 assert( (rc&0xff)==rc );
93277 return rc;
93278 }
93279 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93280
93281 /*
93282 ** Reset the automatic extension loading mechanism.
93283 */
93284 SQLITE_API void sqlite3_reset_auto_extension(void){
@@ -93516,10 +93609,11 @@
93516 { "empty_result_callbacks", SQLITE_NullCallback },
93517 { "legacy_file_format", SQLITE_LegacyFileFmt },
93518 { "fullfsync", SQLITE_FullFSync },
93519 { "checkpoint_fullfsync", SQLITE_CkptFullFSync },
93520 { "reverse_unordered_selects", SQLITE_ReverseOrder },
 
93521 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
93522 { "automatic_index", SQLITE_AutoIndex },
93523 #endif
93524 #ifdef SQLITE_DEBUG
93525 { "sql_trace", SQLITE_SqlTrace },
@@ -93536,16 +93630,17 @@
93536 { "writable_schema", SQLITE_WriteSchema|SQLITE_RecoveryMode },
93537
93538 /* TODO: Maybe it shouldn't be possible to change the ReadUncommitted
93539 ** flag if there are any active statements. */
93540 { "read_uncommitted", SQLITE_ReadUncommitted },
93541 { "recursive_triggers", SQLITE_RecTriggers },
93542
93543 /* This flag may only be set if both foreign-key and trigger support
93544 ** are present in the build. */
93545 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
93546 { "foreign_keys", SQLITE_ForeignKeys },
 
93547 #endif
93548 };
93549 int i;
93550 const struct sPragmaType *p;
93551 for(i=0, p=aPragma; i<ArraySize(aPragma); i++, p++){
@@ -93567,10 +93662,11 @@
93567
93568 if( sqlite3GetBoolean(zRight, 0) ){
93569 db->flags |= mask;
93570 }else{
93571 db->flags &= ~mask;
 
93572 }
93573
93574 /* Many of the flag-pragmas modify the code generated by the SQL
93575 ** compiler (eg. count_changes). So add an opcode to expire all
93576 ** compiled SQL statements after modifying a pragma value.
@@ -95979,10 +96075,16 @@
95979
95980 assert( ppStmt );
95981 *ppStmt = 0;
95982 if( !sqlite3SafetyCheckOk(db) ){
95983 return SQLITE_MISUSE_BKPT;
 
 
 
 
 
 
95984 }
95985 sqlite3_mutex_enter(db->mutex);
95986 zSql8 = sqlite3Utf16to8(db, zSql, nBytes, SQLITE_UTF16NATIVE);
95987 if( zSql8 ){
95988 rc = sqlite3LockAndPrepare(db, zSql8, -1, saveSqlFlag, 0, ppStmt, &zTail8);
@@ -104070,12 +104172,12 @@
104070 int (*x)(sqlite3_vtab *);
104071 sqlite3_vtab *pVtab = aVTrans[i]->pVtab;
104072 if( pVtab && (x = pVtab->pModule->xSync)!=0 ){
104073 rc = x(pVtab);
104074 sqlite3DbFree(db, *pzErrmsg);
104075 *pzErrmsg = sqlite3DbStrDup(db, pVtab->zErrMsg);
104076 sqlite3_free(pVtab->zErrMsg);
104077 }
104078 }
104079 db->aVTrans = aVTrans;
104080 return rc;
104081 }
@@ -104391,10 +104493,12 @@
104391 typedef struct WhereLoop WhereLoop;
104392 typedef struct WherePath WherePath;
104393 typedef struct WhereTerm WhereTerm;
104394 typedef struct WhereLoopBuilder WhereLoopBuilder;
104395 typedef struct WhereScan WhereScan;
 
 
104396
104397 /*
104398 ** Cost X is tracked as 10*log2(X) stored in a 16-bit integer. The
104399 ** maximum cost for ordinary tables is 64*(2**63) which becomes 6900.
104400 ** (Virtual tables can return a larger cost, but let's assume they do not.)
@@ -104497,10 +104601,31 @@
104497 u16 nLSlot; /* Number of slots allocated for aLTerm[] */
104498 WhereTerm **aLTerm; /* WhereTerms used */
104499 WhereLoop *pNextLoop; /* Next WhereLoop object in the WhereClause */
104500 WhereTerm *aLTermSpace[4]; /* Initial aLTerm[] space */
104501 };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104502
104503 /* Forward declaration of methods */
104504 static int whereLoopResize(sqlite3*, WhereLoop*, int);
104505
104506 /*
@@ -104712,11 +104837,11 @@
104712 struct WhereLoopBuilder {
104713 WhereInfo *pWInfo; /* Information about this WHERE */
104714 WhereClause *pWC; /* WHERE clause terms */
104715 ExprList *pOrderBy; /* ORDER BY clause */
104716 WhereLoop *pNew; /* Template WhereLoop */
104717 WhereLoop *pBest; /* If non-NULL, store single best loop here */
104718 };
104719
104720 /*
104721 ** The WHERE clause processing routine has two halves. The
104722 ** first part does the start of the WHERE loop and the second
@@ -104854,10 +104979,58 @@
104854 ** UPDATE or DELETE might change subsequent WHERE clause results.
104855 */
104856 SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo *pWInfo){
104857 return pWInfo->okOnePass;
104858 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104859
104860 /*
104861 ** Initialize a preallocated WhereClause structure.
104862 */
104863 static void whereClauseInit(
@@ -108089,12 +108262,13 @@
108089 */
108090 if( pWC->nTerm>1 ){
108091 int iTerm;
108092 for(iTerm=0; iTerm<pWC->nTerm; iTerm++){
108093 Expr *pExpr = pWC->a[iTerm].pExpr;
 
108094 if( ExprHasProperty(pExpr, EP_FromJoin) ) continue;
108095 if( pWC->a[iTerm].wtFlags & (TERM_VIRTUAL|TERM_ORINFO) ) continue;
108096 if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue;
108097 pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
108098 pAndExpr = sqlite3ExprAnd(pParse->db, pAndExpr, pExpr);
108099 }
108100 if( pAndExpr ){
@@ -108418,16 +108592,16 @@
108418 ** is better and has fewer dependencies. Or the template will be ignored
108419 ** and no insert will occur if an existing WhereLoop is faster and has
108420 ** fewer dependencies than the template. Otherwise a new WhereLoop is
108421 ** added based on the template.
108422 **
108423 ** If pBuilder->pBest is not NULL then we only care about the very
108424 ** best template and that template should be stored in pBuilder->pBest.
108425 ** If pBuilder->pBest is NULL then a list of the best templates are stored
108426 ** in pBuilder->pWInfo->pLoops.
108427 **
108428 ** When accumulating multiple loops (when pBuilder->pBest is NULL) we
108429 ** still might overwrite similar loops with the new template if the
108430 ** template is better. Loops may be overwritten if the following
108431 ** conditions are met:
108432 **
108433 ** (1) They have the same iTab.
@@ -108440,34 +108614,26 @@
108440 static int whereLoopInsert(WhereLoopBuilder *pBuilder, WhereLoop *pTemplate){
108441 WhereLoop **ppPrev, *p, *pNext = 0;
108442 WhereInfo *pWInfo = pBuilder->pWInfo;
108443 sqlite3 *db = pWInfo->pParse->db;
108444
108445 /* If pBuilder->pBest is defined, then only keep track of the single
108446 ** best WhereLoop. pBuilder->pBest->maskSelf==0 indicates that no
108447 ** prior WhereLoops have been evaluated and that the current pTemplate
108448 ** is therefore the first and hence the best and should be retained.
108449 */
108450 if( (p = pBuilder->pBest)!=0 ){
108451 if( p->maskSelf!=0 ){
108452 WhereCost rCost = whereCostAdd(p->rRun,p->rSetup);
108453 WhereCost rTemplate = whereCostAdd(pTemplate->rRun,pTemplate->rSetup);
108454 if( rCost < rTemplate ){
108455 testcase( rCost==rTemplate-1 );
108456 goto whereLoopInsert_noop;
108457 }
108458 if( rCost==rTemplate && (p->prereq & pTemplate->prereq)==p->prereq ){
108459 goto whereLoopInsert_noop;
108460 }
108461 }
108462 #if WHERETRACE_ENABLED
108463 if( sqlite3WhereTrace & 0x8 ){
108464 sqlite3DebugPrintf(p->maskSelf==0 ? "ins-init: " : "ins-best: ");
108465 whereLoopPrint(pTemplate, pWInfo->pTabList);
108466 }
108467 #endif
108468 whereLoopXfer(db, p, pTemplate);
108469 return SQLITE_OK;
108470 }
108471
108472 /* Search for an existing WhereLoop to overwrite, or which takes
108473 ** priority over pTemplate.
@@ -108557,11 +108723,11 @@
108557
108558 /* Jump here if the insert is a no-op */
108559 whereLoopInsert_noop:
108560 #if WHERETRACE_ENABLED
108561 if( sqlite3WhereTrace & 0x8 ){
108562 sqlite3DebugPrintf(pBuilder->pBest ? "ins-skip: " : "ins-noop: ");
108563 whereLoopPrint(pTemplate, pWInfo->pTabList);
108564 }
108565 #endif
108566 return SQLITE_OK;
108567 }
@@ -108839,11 +109005,11 @@
108839 }
108840 rSize = whereCost(pSrc->pTab->nRowEst);
108841 rLogSize = estLog(rSize);
108842
108843 /* Automatic indexes */
108844 if( !pBuilder->pBest
108845 && (pWInfo->pParse->db->flags & SQLITE_AutoIndex)!=0
108846 && pSrc->pIndex==0
108847 && !pSrc->viaCoroutine
108848 && !pSrc->notIndexed
108849 && !pSrc->isCorrelated
@@ -109125,11 +109291,11 @@
109125 WhereTerm *pTerm, *pWCEnd;
109126 int rc = SQLITE_OK;
109127 int iCur;
109128 WhereClause tempWC;
109129 WhereLoopBuilder sSubBuild;
109130 WhereLoop sBest;
109131 struct SrcList_item *pItem;
109132
109133 pWC = pBuilder->pWC;
109134 if( pWInfo->wctrlFlags & WHERE_AND_ONLY ) return SQLITE_OK;
109135 pWCEnd = pWC->a + pWC->nTerm;
@@ -109140,20 +109306,18 @@
109140 && (pTerm->u.pOrInfo->indexable & pNew->maskSelf)!=0
109141 ){
109142 WhereClause * const pOrWC = &pTerm->u.pOrInfo->wc;
109143 WhereTerm * const pOrWCEnd = &pOrWC->a[pOrWC->nTerm];
109144 WhereTerm *pOrTerm;
109145 WhereCost rTotal = 0;
109146 WhereCost nRow = 0;
109147 Bitmask prereq = mExtra;
109148
109149 whereLoopInit(&sBest);
109150 pItem = pWInfo->pTabList->a + pNew->iTab;
109151 iCur = pItem->iCursor;
109152 sSubBuild = *pBuilder;
109153 sSubBuild.pOrderBy = 0;
109154 sSubBuild.pBest = &sBest;
109155
109156 for(pOrTerm=pOrWC->a; pOrTerm<pOrWCEnd; pOrTerm++){
109157 if( (pOrTerm->eOperator & WO_AND)!=0 ){
109158 sSubBuild.pWC = &pOrTerm->u.pAndInfo->wc;
109159 }else if( pOrTerm->leftCursor==iCur ){
@@ -109164,43 +109328,52 @@
109164 tempWC.a = pOrTerm;
109165 sSubBuild.pWC = &tempWC;
109166 }else{
109167 continue;
109168 }
109169 sBest.maskSelf = 0;
109170 sBest.rSetup = 0;
109171 sBest.rRun = 0;
109172 #ifndef SQLITE_OMIT_VIRTUALTABLE
109173 if( IsVirtual(pItem->pTab) ){
109174 rc = whereLoopAddVirtual(&sSubBuild);
 
109175 }else
109176 #endif
109177 {
109178 rc = whereLoopAddBtree(&sSubBuild, mExtra);
109179 }
109180 /* sBest.maskSelf is always zero if an error occurs */
109181 assert( rc==SQLITE_OK || sBest.maskSelf==0 );
109182 if( sBest.maskSelf==0 ) break;
109183 assert( sBest.rSetup==0 );
109184 rTotal = whereCostAdd(rTotal, sBest.rRun);
109185 nRow = whereCostAdd(nRow, sBest.nOut);
109186 prereq |= sBest.prereq;
109187 }
109188 assert( pNew->nLSlot>=1 );
109189 if( sBest.maskSelf ){
109190 pNew->nLTerm = 1;
109191 pNew->aLTerm[0] = pTerm;
109192 pNew->wsFlags = WHERE_MULTI_OR;
109193 pNew->rSetup = 0;
 
 
 
 
 
 
 
 
 
 
 
 
109194 /* TUNING: Multiple by 3.5 for the secondary table lookup */
109195 pNew->rRun = rTotal + 18; assert( 18==whereCost(7)-whereCost(2) );
109196 pNew->nOut = nRow;
109197 pNew->prereq = prereq;
109198 memset(&pNew->u, 0, sizeof(pNew->u));
109199 rc = whereLoopInsert(pBuilder, pNew);
109200 }
109201 whereLoopClear(pWInfo->pParse->db, &sBest);
109202 }
109203 }
109204 return rc;
109205 }
109206
@@ -116127,10 +116300,12 @@
116127 }
116128 sqlite3BtreeLeaveAll(db);
116129
116130 /* Any deferred constraint violations have now been resolved. */
116131 db->nDeferredCons = 0;
 
 
116132
116133 /* If one has been configured, invoke the rollback-hook callback */
116134 if( db->xRollbackCallback && (inTrans || !db->autoCommit) ){
116135 db->xRollbackCallback(db->pRollbackArg);
116136 }
@@ -116388,11 +116563,11 @@
116388 void *pArg
116389 ){
116390 sqlite3_mutex_enter(db->mutex);
116391 if( nOps>0 ){
116392 db->xProgress = xProgress;
116393 db->nProgressOps = nOps;
116394 db->pProgressArg = pArg;
116395 }else{
116396 db->xProgress = 0;
116397 db->nProgressOps = 0;
116398 db->pProgressArg = 0;
@@ -119087,11 +119262,11 @@
119087
119088 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
119089
119090 /* If not building as part of the core, include sqlite3ext.h. */
119091 #ifndef SQLITE_CORE
119092 SQLITE_API extern const sqlite3_api_routines *sqlite3_api;
119093 #endif
119094
119095 /************** Include fts3_tokenizer.h in the middle of fts3Int.h **********/
119096 /************** Begin file fts3_tokenizer.h **********************************/
119097 /*
@@ -124995,11 +125170,14 @@
124995
124996 #if !SQLITE_CORE
124997 /*
124998 ** Initialize API pointer table, if required.
124999 */
125000 SQLITE_API int sqlite3_extension_init(
 
 
 
125001 sqlite3 *db,
125002 char **pzErrMsg,
125003 const sqlite3_api_routines *pApi
125004 ){
125005 SQLITE_EXTENSION_INIT2(pApi)
@@ -140042,11 +140220,14 @@
140042 (void *)pGeomCtx, geomCallback, 0, 0, doSqlite3Free
140043 );
140044 }
140045
140046 #if !SQLITE_CORE
140047 SQLITE_API int sqlite3_extension_init(
 
 
 
140048 sqlite3 *db,
140049 char **pzErrMsg,
140050 const sqlite3_api_routines *pApi
140051 ){
140052 SQLITE_EXTENSION_INIT2(pApi)
@@ -140544,11 +140725,14 @@
140544
140545 return rc;
140546 }
140547
140548 #if !SQLITE_CORE
140549 SQLITE_API int sqlite3_extension_init(
 
 
 
140550 sqlite3 *db,
140551 char **pzErrMsg,
140552 const sqlite3_api_routines *pApi
140553 ){
140554 SQLITE_EXTENSION_INIT2(pApi)
140555
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -670,11 +670,11 @@
670 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
671 ** [sqlite_version()] and [sqlite_source_id()].
672 */
673 #define SQLITE_VERSION "3.8.0"
674 #define SQLITE_VERSION_NUMBER 3008000
675 #define SQLITE_SOURCE_ID "2013-07-17 11:54:47 64bf8148b84e0ebb45c12b629f49bc9b316aceba"
676
677 /*
678 ** CAPI3REF: Run-Time Library Version Numbers
679 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
680 **
@@ -3120,11 +3120,11 @@
3120 ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
3121 ** database connection D. An example use for this
3122 ** interface is to keep a GUI updated during a large query.
3123 **
3124 ** ^The parameter P is passed through as the only parameter to the
3125 ** callback function X. ^The parameter N is the approximate number of
3126 ** [virtual machine instructions] that are evaluated between successive
3127 ** invocations of the callback X.
3128 **
3129 ** ^Only a single progress handler may be defined at one time per
3130 ** [database connection]; setting a new progress handler cancels the
@@ -5689,14 +5689,27 @@
5689 **
5690 ** ^Calling sqlite3_auto_extension(X) with an entry point X that is already
5691 ** on the list of automatic extensions is a harmless no-op. ^No entry point
5692 ** will be called more than once for each database connection that is opened.
5693 **
5694 ** See also: [sqlite3_reset_auto_extension()]
5695 ** and [sqlite3_cancel_auto_extension()]
5696 */
5697 SQLITE_API int sqlite3_auto_extension(void (*xEntryPoint)(void));
5698
5699 /*
5700 ** CAPI3REF: Cancel Automatic Extension Loading
5701 **
5702 ** ^The [sqlite3_cancel_auto_extension(X)] interface unregisters the
5703 ** initialization routine X that was registered using a prior call to
5704 ** [sqlite3_auto_extension(X)]. ^The [sqlite3_cancel_auto_extension(X)]
5705 ** routine returns 1 if initialization routine X was successfully
5706 ** unregistered and it returns 0 if X was not on the list of initialization
5707 ** routines.
5708 */
5709 SQLITE_API int sqlite3_cancel_auto_extension(void (*xEntryPoint)(void));
5710
5711 /*
5712 ** CAPI3REF: Reset Automatic Extension Loading
5713 **
5714 ** ^This interface disables all automatic extensions previously
5715 ** registered using [sqlite3_auto_extension()].
@@ -6805,10 +6818,16 @@
6818 ** transaction rollback or database recovery operations are not included.
6819 ** If an IO or other error occurs while writing a page to disk, the effect
6820 ** on subsequent SQLITE_DBSTATUS_CACHE_WRITE requests is undefined.)^ ^The
6821 ** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0.
6822 ** </dd>
6823 **
6824 ** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt>
6825 ** <dd>This parameter returns the zero for the current value if and only if
6826 ** there all foreign key constraints (deferred or immediate) have been
6827 ** resolved. The highwater mark is always 0.
6828 ** </dd>
6829 ** </dl>
6830 */
6831 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
6832 #define SQLITE_DBSTATUS_CACHE_USED 1
6833 #define SQLITE_DBSTATUS_SCHEMA_USED 2
@@ -6817,11 +6836,12 @@
6836 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5
6837 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6
6838 #define SQLITE_DBSTATUS_CACHE_HIT 7
6839 #define SQLITE_DBSTATUS_CACHE_MISS 8
6840 #define SQLITE_DBSTATUS_CACHE_WRITE 9
6841 #define SQLITE_DBSTATUS_DEFERRED_FKS 10
6842 #define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */
6843
6844
6845 /*
6846 ** CAPI3REF: Prepared Statement Status
6847 **
@@ -10117,11 +10137,11 @@
10137 void *pAuthArg; /* 1st argument to the access auth function */
10138 #endif
10139 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
10140 int (*xProgress)(void *); /* The progress callback */
10141 void *pProgressArg; /* Argument to the progress callback */
10142 unsigned nProgressOps; /* Number of opcodes for progress callback */
10143 #endif
10144 #ifndef SQLITE_OMIT_VIRTUALTABLE
10145 int nVTrans; /* Allocated size of aVTrans */
10146 Hash aModule; /* populated by sqlite3_create_module() */
10147 VtabCtx *pVtabCtx; /* Context for active vtab connect/create */
@@ -10135,10 +10155,11 @@
10155 Savepoint *pSavepoint; /* List of active savepoints */
10156 int busyTimeout; /* Busy handler timeout, in msec */
10157 int nSavepoint; /* Number of non-transaction savepoints */
10158 int nStatement; /* Number of nested statement-transactions */
10159 i64 nDeferredCons; /* Net deferred constraints this transaction. */
10160 i64 nDeferredImmCons; /* Net deferred immediate constraints */
10161 int *pnBytesFreed; /* If not NULL, increment this in DbFree() */
10162
10163 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
10164 /* The following variables are all protected by the STATIC_MASTER
10165 ** mutex, not by sqlite3.mutex. They are used by code in notify.c.
@@ -10190,10 +10211,13 @@
10211 #define SQLITE_ForeignKeys 0x00040000 /* Enforce foreign key constraints */
10212 #define SQLITE_AutoIndex 0x00080000 /* Enable automatic indexes */
10213 #define SQLITE_PreferBuiltin 0x00100000 /* Preference to built-in funcs */
10214 #define SQLITE_LoadExtension 0x00200000 /* Enable load_extension */
10215 #define SQLITE_EnableTrigger 0x00400000 /* True to enable triggers */
10216 #define SQLITE_DeferFKs 0x00800000 /* Defer all FK constraints */
10217 #define SQLITE_QueryOnly 0x01000000 /* Disable database changes */
10218
10219
10220 /*
10221 ** Bits of the sqlite3.dbOptFlags field that are used by the
10222 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
10223 ** selectively disable various optimizations.
@@ -10336,10 +10360,11 @@
10360 ** OP_Savepoint instruction.
10361 */
10362 struct Savepoint {
10363 char *zName; /* Savepoint name (nul-terminated) */
10364 i64 nDeferredCons; /* Number of deferred fk violations */
10365 i64 nDeferredImmCons; /* Number of deferred imm fk. */
10366 Savepoint *pNext; /* Parent savepoint (if any) */
10367 };
10368
10369 /*
10370 ** The following are used as the second parameter to sqlite3Savepoint(),
@@ -13530,10 +13555,11 @@
13555 #ifndef SQLITE_OMIT_TRACE
13556 i64 startTime; /* Time when query started - used for profiling */
13557 #endif
13558 i64 nFkConstraint; /* Number of imm. FK constraints this VM */
13559 i64 nStmtDefCons; /* Number of def. constraints when stmt started */
13560 i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */
13561 char *zSql; /* Text of the SQL statement that generated this */
13562 void *pFree; /* Free this when deleting the vdbe */
13563 #ifdef SQLITE_DEBUG
13564 FILE *trace; /* Write an execution trace here, if not NULL */
13565 #endif
@@ -13889,10 +13915,20 @@
13915 }
13916 *pHighwater = 0;
13917 *pCurrent = nRet;
13918 break;
13919 }
13920
13921 /* Set *pCurrent to non-zero if there are unresolved deferred foreign
13922 ** key constraints. Set *pCurrent to zero if all foreign key constraints
13923 ** have been satisfied. The *pHighwater is always set to zero.
13924 */
13925 case SQLITE_DBSTATUS_DEFERRED_FKS: {
13926 *pHighwater = 0;
13927 *pCurrent = db->nDeferredImmCons>0 || db->nDeferredCons>0;
13928 break;
13929 }
13930
13931 default: {
13932 rc = SQLITE_ERROR;
13933 }
13934 }
@@ -61946,10 +61982,11 @@
61982 /* If the statement transaction is being rolled back, also restore the
61983 ** database handles deferred constraint counter to the value it had when
61984 ** the statement transaction was opened. */
61985 if( eOp==SAVEPOINT_ROLLBACK ){
61986 db->nDeferredCons = p->nStmtDefCons;
61987 db->nDeferredImmCons = p->nStmtDefImmCons;
61988 }
61989 }
61990 return rc;
61991 }
61992
@@ -61964,11 +62001,13 @@
62001 ** and write an error message to it. Then return SQLITE_ERROR.
62002 */
62003 #ifndef SQLITE_OMIT_FOREIGN_KEY
62004 SQLITE_PRIVATE int sqlite3VdbeCheckFk(Vdbe *p, int deferred){
62005 sqlite3 *db = p->db;
62006 if( (deferred && (db->nDeferredCons+db->nDeferredImmCons)>0)
62007 || (!deferred && p->nFkConstraint>0)
62008 ){
62009 p->rc = SQLITE_CONSTRAINT_FOREIGNKEY;
62010 p->errorAction = OE_Abort;
62011 sqlite3SetString(&p->zErrMsg, db, "foreign key constraint failed");
62012 return SQLITE_ERROR;
62013 }
@@ -62097,10 +62136,12 @@
62136 }else if( rc!=SQLITE_OK ){
62137 p->rc = rc;
62138 sqlite3RollbackAll(db, SQLITE_OK);
62139 }else{
62140 db->nDeferredCons = 0;
62141 db->nDeferredImmCons = 0;
62142 db->flags &= ~SQLITE_DeferFKs;
62143 sqlite3CommitInternalChanges(db);
62144 }
62145 }else{
62146 sqlite3RollbackAll(db, SQLITE_OK);
62147 }
@@ -63536,11 +63577,13 @@
63577 */
63578 if( db->nVdbeActive==0 ){
63579 db->u1.isInterrupted = 0;
63580 }
63581
63582 assert( db->nVdbeWrite>0 || db->autoCommit==0
63583 || (db->nDeferredCons==0 && db->nDeferredImmCons==0)
63584 );
63585
63586 #ifndef SQLITE_OMIT_TRACE
63587 if( db->xProfile && !db->init.busy ){
63588 sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime);
63589 }
@@ -65384,16 +65427,15 @@
65427 Op *pOp; /* Current operation */
65428 int rc = SQLITE_OK; /* Value to return */
65429 sqlite3 *db = p->db; /* The database */
65430 u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
65431 u8 encoding = ENC(db); /* The database encoding */
 
 
 
 
65432 int iCompare = 0; /* Result of last OP_Compare operation */
65433 unsigned nVmStep = 0; /* Number of virtual machine steps */
65434 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
65435 unsigned nProgressOps = 0; /* nVmStep at last progress callback. */
65436 #endif
65437 Mem *aMem = p->aMem; /* Copy of p->aMem */
65438 Mem *pIn1 = 0; /* 1st input operand */
65439 Mem *pIn2 = 0; /* 2nd input operand */
65440 Mem *pIn3 = 0; /* 3rd input operand */
65441 Mem *pOut = 0; /* Output operand */
@@ -65847,13 +65889,10 @@
65889 assert( p->explain==0 );
65890 p->pResultSet = 0;
65891 db->busyHandler.nBusy = 0;
65892 CHECK_FOR_INTERRUPT;
65893 sqlite3VdbeIOTraceSql(p);
 
 
 
65894 #ifdef SQLITE_DEBUG
65895 sqlite3BeginBenignMalloc();
65896 if( p->pc==0 && (p->db->flags & SQLITE_VdbeListing)!=0 ){
65897 int i;
65898 printf("VDBE Program Listing:\n");
@@ -65895,31 +65934,10 @@
65934 sqlite3_interrupt_count--;
65935 if( sqlite3_interrupt_count==0 ){
65936 sqlite3_interrupt(db);
65937 }
65938 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65939 #endif
65940
65941 /* On any opcode with the "out2-prerelease" tag, free any
65942 ** external allocations out of mem[p2] and set mem[p2] to be
65943 ** an undefined integer. Opcodes will either fill in the integer
@@ -66010,12 +66028,42 @@
66028 ** The next instruction executed will be
66029 ** the one at index P2 from the beginning of
66030 ** the program.
66031 */
66032 case OP_Goto: { /* jump */
 
66033 pc = pOp->p2 - 1;
66034
66035 /* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev,
66036 ** OP_VNext, OP_RowSetNext, or OP_SorterNext) all jump here upon
66037 ** completion. Check to see if sqlite3_interrupt() has been called
66038 ** or if the progress callback needs to be invoked.
66039 **
66040 ** This code uses unstructured "goto" statements and does not look clean.
66041 ** But that is not due to sloppy coding habits. The code is written this
66042 ** way for performance, to avoid having to run the interrupt and progress
66043 ** checks on every opcode. This helps sqlite3_step() to run about 1.5%
66044 ** faster according to "valgrind --tool=cachegrind" */
66045 check_for_interrupt:
66046 CHECK_FOR_INTERRUPT;
66047 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
66048 /* Call the progress callback if it is configured and the required number
66049 ** of VDBE ops have been executed (either since this invocation of
66050 ** sqlite3VdbeExec() or since last time the progress callback was called).
66051 ** If the progress callback returns non-zero, exit the virtual machine with
66052 ** a return code SQLITE_ABORT.
66053 */
66054 if( db->xProgress!=0 && (nVmStep - nProgressOps)>=db->nProgressOps ){
66055 int prc;
66056 prc = db->xProgress(db->pProgressArg);
66057 if( prc!=0 ){
66058 rc = SQLITE_INTERRUPT;
66059 goto vdbe_error_halt;
66060 }
66061 nProgressOps = nVmStep;
66062 }
66063 #endif
66064
66065 break;
66066 }
66067
66068 /* Opcode: Gosub P1 P2 * * *
66069 **
@@ -66132,11 +66180,11 @@
66180 assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
66181 if( rc==SQLITE_BUSY ){
66182 p->rc = rc = SQLITE_BUSY;
66183 }else{
66184 assert( rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT );
66185 assert( rc==SQLITE_OK || db->nDeferredCons>0 || db->nDeferredImmCons>0 );
66186 rc = p->rc ? SQLITE_ERROR : SQLITE_DONE;
66187 }
66188 goto vdbe_return;
66189 }
66190
@@ -68028,10 +68076,11 @@
68076
68077 /* Link the new savepoint into the database handle's list. */
68078 u.as.pNew->pNext = db->pSavepoint;
68079 db->pSavepoint = u.as.pNew;
68080 u.as.pNew->nDeferredCons = db->nDeferredCons;
68081 u.as.pNew->nDeferredImmCons = db->nDeferredImmCons;
68082 }
68083 }
68084 }else{
68085 u.as.iSavepoint = 0;
68086
@@ -68115,10 +68164,11 @@
68164 if( !isTransaction ){
68165 db->nSavepoint--;
68166 }
68167 }else{
68168 db->nDeferredCons = u.as.pSavepoint->nDeferredCons;
68169 db->nDeferredImmCons = u.as.pSavepoint->nDeferredImmCons;
68170 }
68171
68172 if( !isTransaction ){
68173 rc = sqlite3VtabSavepoint(db, u.as.p1, u.as.iSavepoint);
68174 if( rc!=SQLITE_OK ) goto abort_due_to_error;
@@ -68244,10 +68294,14 @@
68294
68295 assert( p->bIsReader );
68296 assert( p->readOnly==0 || pOp->p2==0 );
68297 assert( pOp->p1>=0 && pOp->p1<db->nDb );
68298 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
68299 if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){
68300 rc = SQLITE_READONLY;
68301 goto abort_due_to_error;
68302 }
68303 u.au.pBt = db->aDb[pOp->p1].pBt;
68304
68305 if( u.au.pBt ){
68306 rc = sqlite3BtreeBeginTrans(u.au.pBt, pOp->p2);
68307 if( rc==SQLITE_BUSY ){
@@ -68276,10 +68330,11 @@
68330
68331 /* Store the current value of the database handles deferred constraint
68332 ** counter. If the statement transaction needs to be rolled back,
68333 ** the value of this counter needs to be restored too. */
68334 p->nStmtDefCons = db->nDeferredCons;
68335 p->nStmtDefImmCons = db->nDeferredImmCons;
68336 }
68337 }
68338 break;
68339 }
68340
@@ -69851,11 +69906,10 @@
69906 #if 0 /* local variables moved into u.br */
69907 VdbeCursor *pC;
69908 int res;
69909 #endif /* local variables moved into u.br */
69910
 
69911 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
69912 assert( pOp->p5<=ArraySize(p->aCounter) );
69913 u.br.pC = p->apCsr[pOp->p1];
69914 if( u.br.pC==0 ){
69915 break; /* See ticket #2273 */
@@ -69880,11 +69934,11 @@
69934 #ifdef SQLITE_TEST
69935 sqlite3_search_count++;
69936 #endif
69937 }
69938 u.br.pC->rowidIsValid = 0;
69939 goto check_for_interrupt;
69940 }
69941
69942 /* Opcode: IdxInsert P1 P2 P3 * P5
69943 **
69944 ** Register P2 holds an SQL index key made using the
@@ -70426,11 +70480,11 @@
70480 */
70481 case OP_RowSetRead: { /* jump, in1, out3 */
70482 #if 0 /* local variables moved into u.cb */
70483 i64 val;
70484 #endif /* local variables moved into u.cb */
70485
70486 pIn1 = &aMem[pOp->p1];
70487 if( (pIn1->flags & MEM_RowSet)==0
70488 || sqlite3RowSetNext(pIn1->u.pRowSet, &u.cb.val)==0
70489 ){
70490 /* The boolean index is empty */
@@ -70438,11 +70492,11 @@
70492 pc = pOp->p2 - 1;
70493 }else{
70494 /* A value was pulled from the index */
70495 sqlite3VdbeMemSetInt64(&aMem[pOp->p3], u.cb.val);
70496 }
70497 goto check_for_interrupt;
70498 }
70499
70500 /* Opcode: RowSetTest P1 P2 P3 P4
70501 **
70502 ** Register P3 is assumed to hold a 64-bit integer value. If register P1
@@ -70658,11 +70712,13 @@
70712 ** If P1 is non-zero, the database constraint counter is incremented
70713 ** (deferred foreign key constraints). Otherwise, if P1 is zero, the
70714 ** statement counter is incremented (immediate foreign key constraints).
70715 */
70716 case OP_FkCounter: {
70717 if( db->flags & SQLITE_DeferFKs ){
70718 db->nDeferredImmCons += pOp->p2;
70719 }else if( pOp->p1 ){
70720 db->nDeferredCons += pOp->p2;
70721 }else{
70722 p->nFkConstraint += pOp->p2;
70723 }
70724 break;
@@ -70679,13 +70735,13 @@
70735 ** zero, the jump is taken if the statement constraint-counter is zero
70736 ** (immediate foreign key constraint violations).
70737 */
70738 case OP_FkIfZero: { /* jump */
70739 if( pOp->p1 ){
70740 if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
70741 }else{
70742 if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
70743 }
70744 break;
70745 }
70746 #endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */
70747
@@ -71367,11 +71423,11 @@
71423
71424 if( !u.cp.res ){
71425 /* If there is data, jump to P2 */
71426 pc = pOp->p2 - 1;
71427 }
71428 goto check_for_interrupt;
71429 }
71430 #endif /* SQLITE_OMIT_VIRTUALTABLE */
71431
71432 #ifndef SQLITE_OMIT_VIRTUALTABLE
71433 /* Opcode: VRename P1 * * P4 *
@@ -89262,11 +89318,14 @@
89318 sqlite3ReleaseTempReg(pParse, regRec);
89319 sqlite3ReleaseTempRange(pParse, regTemp, nCol);
89320 }
89321 }
89322
89323 if( !pFKey->isDeferred && !(pParse->db->flags & SQLITE_DeferFKs)
89324 && !pParse->pToplevel
89325 && !pParse->isMultiWrite
89326 ){
89327 /* Special case: If this is an INSERT statement that will insert exactly
89328 ** one row into the table, raise a constraint immediately instead of
89329 ** incrementing a counter. This is necessary as the VM code is being
89330 ** generated for will not open a statement transaction. */
89331 assert( nIncr==1 );
@@ -89653,11 +89712,13 @@
89712 for(pFKey = sqlite3FkReferences(pTab); pFKey; pFKey=pFKey->pNextTo){
89713 Index *pIdx = 0; /* Foreign key index for pFKey */
89714 SrcList *pSrc;
89715 int *aiCol = 0;
89716
89717 if( !pFKey->isDeferred && !(db->flags & SQLITE_DeferFKs)
89718 && !pParse->pToplevel && !pParse->isMultiWrite
89719 ){
89720 assert( regOld==0 && regNew!=0 );
89721 /* Inserting a single row into a parent table cannot cause an immediate
89722 ** foreign key violation. So do nothing in this case. */
89723 continue;
89724 }
@@ -92615,15 +92676,18 @@
92676 #ifndef SQLITE_CORE
92677 /* This case when the file really is being compiled as a loadable
92678 ** extension */
92679 # define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api=0;
92680 # define SQLITE_EXTENSION_INIT2(v) sqlite3_api=v;
92681 # define SQLITE_EXTENSION_INIT3 \
92682 extern const sqlite3_api_routines *sqlite3_api;
92683 #else
92684 /* This case when the file is being statically linked into the
92685 ** application */
92686 # define SQLITE_EXTENSION_INIT1 /*no-op*/
92687 # define SQLITE_EXTENSION_INIT2(v) (void)v; /* unused parameter */
92688 # define SQLITE_EXTENSION_INIT3 /*no-op*/
92689 #endif
92690
92691 #endif /* _SQLITE3EXT_H_ */
92692
92693 /************** End of sqlite3ext.h ******************************************/
@@ -93275,10 +93339,39 @@
93339 sqlite3_mutex_leave(mutex);
93340 assert( (rc&0xff)==rc );
93341 return rc;
93342 }
93343 }
93344
93345 /*
93346 ** Cancel a prior call to sqlite3_auto_extension. Remove xInit from the
93347 ** set of routines that is invoked for each new database connection, if it
93348 ** is currently on the list. If xInit is not on the list, then this
93349 ** routine is a no-op.
93350 **
93351 ** Return 1 if xInit was found on the list and removed. Return 0 if xInit
93352 ** was not on the list.
93353 */
93354 SQLITE_API int sqlite3_cancel_auto_extension(void (*xInit)(void)){
93355 #if SQLITE_THREADSAFE
93356 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
93357 #endif
93358 int i;
93359 int n = 0;
93360 wsdAutoextInit;
93361 sqlite3_mutex_enter(mutex);
93362 for(i=wsdAutoext.nExt-1; i>=0; i--){
93363 if( wsdAutoext.aExt[i]==xInit ){
93364 wsdAutoext.nExt--;
93365 wsdAutoext.aExt[i] = wsdAutoext.aExt[wsdAutoext.nExt];
93366 n++;
93367 break;
93368 }
93369 }
93370 sqlite3_mutex_leave(mutex);
93371 return n;
93372 }
93373
93374 /*
93375 ** Reset the automatic extension loading mechanism.
93376 */
93377 SQLITE_API void sqlite3_reset_auto_extension(void){
@@ -93516,10 +93609,11 @@
93609 { "empty_result_callbacks", SQLITE_NullCallback },
93610 { "legacy_file_format", SQLITE_LegacyFileFmt },
93611 { "fullfsync", SQLITE_FullFSync },
93612 { "checkpoint_fullfsync", SQLITE_CkptFullFSync },
93613 { "reverse_unordered_selects", SQLITE_ReverseOrder },
93614 { "query_only", SQLITE_QueryOnly },
93615 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
93616 { "automatic_index", SQLITE_AutoIndex },
93617 #endif
93618 #ifdef SQLITE_DEBUG
93619 { "sql_trace", SQLITE_SqlTrace },
@@ -93536,16 +93630,17 @@
93630 { "writable_schema", SQLITE_WriteSchema|SQLITE_RecoveryMode },
93631
93632 /* TODO: Maybe it shouldn't be possible to change the ReadUncommitted
93633 ** flag if there are any active statements. */
93634 { "read_uncommitted", SQLITE_ReadUncommitted },
93635 { "recursive_triggers", SQLITE_RecTriggers },
93636
93637 /* This flag may only be set if both foreign-key and trigger support
93638 ** are present in the build. */
93639 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
93640 { "foreign_keys", SQLITE_ForeignKeys },
93641 { "defer_foreign_keys", SQLITE_DeferFKs },
93642 #endif
93643 };
93644 int i;
93645 const struct sPragmaType *p;
93646 for(i=0, p=aPragma; i<ArraySize(aPragma); i++, p++){
@@ -93567,10 +93662,11 @@
93662
93663 if( sqlite3GetBoolean(zRight, 0) ){
93664 db->flags |= mask;
93665 }else{
93666 db->flags &= ~mask;
93667 if( mask==SQLITE_DeferFKs ) db->nDeferredImmCons = 0;
93668 }
93669
93670 /* Many of the flag-pragmas modify the code generated by the SQL
93671 ** compiler (eg. count_changes). So add an opcode to expire all
93672 ** compiled SQL statements after modifying a pragma value.
@@ -95979,10 +96075,16 @@
96075
96076 assert( ppStmt );
96077 *ppStmt = 0;
96078 if( !sqlite3SafetyCheckOk(db) ){
96079 return SQLITE_MISUSE_BKPT;
96080 }
96081 if( nBytes>=0 ){
96082 int sz;
96083 const char *z = (const char*)zSql;
96084 for(sz=0; sz<nBytes && (z[sz]!=0 || z[sz+1]!=0); sz += 2){}
96085 nBytes = sz;
96086 }
96087 sqlite3_mutex_enter(db->mutex);
96088 zSql8 = sqlite3Utf16to8(db, zSql, nBytes, SQLITE_UTF16NATIVE);
96089 if( zSql8 ){
96090 rc = sqlite3LockAndPrepare(db, zSql8, -1, saveSqlFlag, 0, ppStmt, &zTail8);
@@ -104070,12 +104172,12 @@
104172 int (*x)(sqlite3_vtab *);
104173 sqlite3_vtab *pVtab = aVTrans[i]->pVtab;
104174 if( pVtab && (x = pVtab->pModule->xSync)!=0 ){
104175 rc = x(pVtab);
104176 sqlite3DbFree(db, *pzErrmsg);
104177 *pzErrmsg = pVtab->zErrMsg;
104178 pVtab->zErrMsg = 0;
104179 }
104180 }
104181 db->aVTrans = aVTrans;
104182 return rc;
104183 }
@@ -104391,10 +104493,12 @@
104493 typedef struct WhereLoop WhereLoop;
104494 typedef struct WherePath WherePath;
104495 typedef struct WhereTerm WhereTerm;
104496 typedef struct WhereLoopBuilder WhereLoopBuilder;
104497 typedef struct WhereScan WhereScan;
104498 typedef struct WhereOrCost WhereOrCost;
104499 typedef struct WhereOrSet WhereOrSet;
104500
104501 /*
104502 ** Cost X is tracked as 10*log2(X) stored in a 16-bit integer. The
104503 ** maximum cost for ordinary tables is 64*(2**63) which becomes 6900.
104504 ** (Virtual tables can return a larger cost, but let's assume they do not.)
@@ -104497,10 +104601,31 @@
104601 u16 nLSlot; /* Number of slots allocated for aLTerm[] */
104602 WhereTerm **aLTerm; /* WhereTerms used */
104603 WhereLoop *pNextLoop; /* Next WhereLoop object in the WhereClause */
104604 WhereTerm *aLTermSpace[4]; /* Initial aLTerm[] space */
104605 };
104606
104607 /* This object holds the prerequisites and the cost of running a
104608 ** subquery on one operand of an OR operator in the WHERE clause.
104609 ** See WhereOrSet for additional information
104610 */
104611 struct WhereOrCost {
104612 Bitmask prereq; /* Prerequisites */
104613 WhereCost rRun; /* Cost of running this subquery */
104614 WhereCost nOut; /* Number of outputs for this subquery */
104615 };
104616
104617 /* The WhereOrSet object holds a set of possible WhereOrCosts that
104618 ** correspond to the subquery(s) of OR-clause processing. At most
104619 ** favorable N_OR_COST elements are retained.
104620 */
104621 #define N_OR_COST 3
104622 struct WhereOrSet {
104623 u16 n; /* Number of valid a[] entries */
104624 WhereOrCost a[N_OR_COST]; /* Set of best costs */
104625 };
104626
104627
104628 /* Forward declaration of methods */
104629 static int whereLoopResize(sqlite3*, WhereLoop*, int);
104630
104631 /*
@@ -104712,11 +104837,11 @@
104837 struct WhereLoopBuilder {
104838 WhereInfo *pWInfo; /* Information about this WHERE */
104839 WhereClause *pWC; /* WHERE clause terms */
104840 ExprList *pOrderBy; /* ORDER BY clause */
104841 WhereLoop *pNew; /* Template WhereLoop */
104842 WhereOrSet *pOrSet; /* Record best loops here, if not NULL */
104843 };
104844
104845 /*
104846 ** The WHERE clause processing routine has two halves. The
104847 ** first part does the start of the WHERE loop and the second
@@ -104854,10 +104979,58 @@
104979 ** UPDATE or DELETE might change subsequent WHERE clause results.
104980 */
104981 SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo *pWInfo){
104982 return pWInfo->okOnePass;
104983 }
104984
104985 /*
104986 ** Move the content of pSrc into pDest
104987 */
104988 static void whereOrMove(WhereOrSet *pDest, WhereOrSet *pSrc){
104989 pDest->n = pSrc->n;
104990 memcpy(pDest->a, pSrc->a, pDest->n*sizeof(pDest->a[0]));
104991 }
104992
104993 /*
104994 ** Try to insert a new prerequisite/cost entry into the WhereOrSet pSet.
104995 **
104996 ** The new entry might overwrite an existing entry, or it might be
104997 ** appended, or it might be discarded. Do whatever is the right thing
104998 ** so that pSet keeps the N_OR_COST best entries seen so far.
104999 */
105000 static int whereOrInsert(
105001 WhereOrSet *pSet, /* The WhereOrSet to be updated */
105002 Bitmask prereq, /* Prerequisites of the new entry */
105003 WhereCost rRun, /* Run-cost of the new entry */
105004 WhereCost nOut /* Number of outputs for the new entry */
105005 ){
105006 u16 i;
105007 WhereOrCost *p;
105008 for(i=pSet->n, p=pSet->a; i>0; i--, p++){
105009 if( rRun<=p->rRun && (prereq & p->prereq)==prereq ){
105010 goto whereOrInsert_done;
105011 }
105012 if( p->rRun<=rRun && (p->prereq & prereq)==p->prereq ){
105013 return 0;
105014 }
105015 }
105016 if( pSet->n<N_OR_COST ){
105017 p = &pSet->a[pSet->n++];
105018 p->nOut = nOut;
105019 }else{
105020 p = pSet->a;
105021 for(i=1; i<pSet->n; i++){
105022 if( p->rRun>pSet->a[i].rRun ) p = pSet->a + i;
105023 }
105024 if( p->rRun<=rRun ) return 0;
105025 }
105026 whereOrInsert_done:
105027 p->prereq = prereq;
105028 p->rRun = rRun;
105029 if( p->nOut>nOut ) p->nOut = nOut;
105030 return 1;
105031 }
105032
105033 /*
105034 ** Initialize a preallocated WhereClause structure.
105035 */
105036 static void whereClauseInit(
@@ -108089,12 +108262,13 @@
108262 */
108263 if( pWC->nTerm>1 ){
108264 int iTerm;
108265 for(iTerm=0; iTerm<pWC->nTerm; iTerm++){
108266 Expr *pExpr = pWC->a[iTerm].pExpr;
108267 if( &pWC->a[iTerm] == pTerm ) continue;
108268 if( ExprHasProperty(pExpr, EP_FromJoin) ) continue;
108269 if( pWC->a[iTerm].wtFlags & (TERM_ORINFO) ) continue;
108270 if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue;
108271 pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
108272 pAndExpr = sqlite3ExprAnd(pParse->db, pAndExpr, pExpr);
108273 }
108274 if( pAndExpr ){
@@ -108418,16 +108592,16 @@
108592 ** is better and has fewer dependencies. Or the template will be ignored
108593 ** and no insert will occur if an existing WhereLoop is faster and has
108594 ** fewer dependencies than the template. Otherwise a new WhereLoop is
108595 ** added based on the template.
108596 **
108597 ** If pBuilder->pOrSet is not NULL then we only care about only the
108598 ** prerequisites and rRun and nOut costs of the N best loops. That
108599 ** information is gathered in the pBuilder->pOrSet object. This special
108600 ** processing mode is used only for OR clause processing.
108601 **
108602 ** When accumulating multiple loops (when pBuilder->pOrSet is NULL) we
108603 ** still might overwrite similar loops with the new template if the
108604 ** template is better. Loops may be overwritten if the following
108605 ** conditions are met:
108606 **
108607 ** (1) They have the same iTab.
@@ -108440,34 +108614,26 @@
108614 static int whereLoopInsert(WhereLoopBuilder *pBuilder, WhereLoop *pTemplate){
108615 WhereLoop **ppPrev, *p, *pNext = 0;
108616 WhereInfo *pWInfo = pBuilder->pWInfo;
108617 sqlite3 *db = pWInfo->pParse->db;
108618
108619 /* If pBuilder->pOrSet is defined, then only keep track of the costs
108620 ** and prereqs.
 
 
108621 */
108622 if( pBuilder->pOrSet!=0 ){
108623 #if WHERETRACE_ENABLED
108624 u16 n = pBuilder->pOrSet->n;
108625 int x =
108626 #endif
108627 whereOrInsert(pBuilder->pOrSet, pTemplate->prereq, pTemplate->rRun,
108628 pTemplate->nOut);
 
 
 
 
 
108629 #if WHERETRACE_ENABLED
108630 if( sqlite3WhereTrace & 0x8 ){
108631 sqlite3DebugPrintf(x?" or-%d: ":" or-X: ", n);
108632 whereLoopPrint(pTemplate, pWInfo->pTabList);
108633 }
108634 #endif
 
108635 return SQLITE_OK;
108636 }
108637
108638 /* Search for an existing WhereLoop to overwrite, or which takes
108639 ** priority over pTemplate.
@@ -108557,11 +108723,11 @@
108723
108724 /* Jump here if the insert is a no-op */
108725 whereLoopInsert_noop:
108726 #if WHERETRACE_ENABLED
108727 if( sqlite3WhereTrace & 0x8 ){
108728 sqlite3DebugPrintf("ins-noop: ");
108729 whereLoopPrint(pTemplate, pWInfo->pTabList);
108730 }
108731 #endif
108732 return SQLITE_OK;
108733 }
@@ -108839,11 +109005,11 @@
109005 }
109006 rSize = whereCost(pSrc->pTab->nRowEst);
109007 rLogSize = estLog(rSize);
109008
109009 /* Automatic indexes */
109010 if( !pBuilder->pOrSet
109011 && (pWInfo->pParse->db->flags & SQLITE_AutoIndex)!=0
109012 && pSrc->pIndex==0
109013 && !pSrc->viaCoroutine
109014 && !pSrc->notIndexed
109015 && !pSrc->isCorrelated
@@ -109125,11 +109291,11 @@
109291 WhereTerm *pTerm, *pWCEnd;
109292 int rc = SQLITE_OK;
109293 int iCur;
109294 WhereClause tempWC;
109295 WhereLoopBuilder sSubBuild;
109296 WhereOrSet sSum, sCur, sPrev;
109297 struct SrcList_item *pItem;
109298
109299 pWC = pBuilder->pWC;
109300 if( pWInfo->wctrlFlags & WHERE_AND_ONLY ) return SQLITE_OK;
109301 pWCEnd = pWC->a + pWC->nTerm;
@@ -109140,20 +109306,18 @@
109306 && (pTerm->u.pOrInfo->indexable & pNew->maskSelf)!=0
109307 ){
109308 WhereClause * const pOrWC = &pTerm->u.pOrInfo->wc;
109309 WhereTerm * const pOrWCEnd = &pOrWC->a[pOrWC->nTerm];
109310 WhereTerm *pOrTerm;
109311 int once = 1;
109312 int i, j;
 
109313
 
109314 pItem = pWInfo->pTabList->a + pNew->iTab;
109315 iCur = pItem->iCursor;
109316 sSubBuild = *pBuilder;
109317 sSubBuild.pOrderBy = 0;
109318 sSubBuild.pOrSet = &sCur;
109319
109320 for(pOrTerm=pOrWC->a; pOrTerm<pOrWCEnd; pOrTerm++){
109321 if( (pOrTerm->eOperator & WO_AND)!=0 ){
109322 sSubBuild.pWC = &pOrTerm->u.pAndInfo->wc;
109323 }else if( pOrTerm->leftCursor==iCur ){
@@ -109164,43 +109328,52 @@
109328 tempWC.a = pOrTerm;
109329 sSubBuild.pWC = &tempWC;
109330 }else{
109331 continue;
109332 }
109333 sCur.n = 0;
 
 
109334 #ifndef SQLITE_OMIT_VIRTUALTABLE
109335 if( IsVirtual(pItem->pTab) ){
109336 rc = whereLoopAddVirtual(&sSubBuild);
109337 for(i=0; i<sCur.n; i++) sCur.a[i].prereq |= mExtra;
109338 }else
109339 #endif
109340 {
109341 rc = whereLoopAddBtree(&sSubBuild, mExtra);
109342 }
109343 assert( rc==SQLITE_OK || sCur.n==0 );
109344 if( sCur.n==0 ){
109345 sSum.n = 0;
109346 break;
109347 }else if( once ){
109348 whereOrMove(&sSum, &sCur);
109349 once = 0;
109350 }else{
109351 whereOrMove(&sPrev, &sSum);
109352 sSum.n = 0;
109353 for(i=0; i<sPrev.n; i++){
109354 for(j=0; j<sCur.n; j++){
109355 whereOrInsert(&sSum, sPrev.a[i].prereq | sCur.a[j].prereq,
109356 whereCostAdd(sPrev.a[i].rRun, sCur.a[j].rRun),
109357 whereCostAdd(sPrev.a[i].nOut, sCur.a[j].nOut));
109358 }
109359 }
109360 }
109361 }
109362 pNew->nLTerm = 1;
109363 pNew->aLTerm[0] = pTerm;
109364 pNew->wsFlags = WHERE_MULTI_OR;
109365 pNew->rSetup = 0;
109366 pNew->iSortIdx = 0;
109367 memset(&pNew->u, 0, sizeof(pNew->u));
109368 for(i=0; rc==SQLITE_OK && i<sSum.n; i++){
109369 /* TUNING: Multiple by 3.5 for the secondary table lookup */
109370 pNew->rRun = sSum.a[i].rRun + 18;
109371 pNew->nOut = sSum.a[i].nOut;
109372 pNew->prereq = sSum.a[i].prereq;
 
109373 rc = whereLoopInsert(pBuilder, pNew);
109374 }
 
109375 }
109376 }
109377 return rc;
109378 }
109379
@@ -116127,10 +116300,12 @@
116300 }
116301 sqlite3BtreeLeaveAll(db);
116302
116303 /* Any deferred constraint violations have now been resolved. */
116304 db->nDeferredCons = 0;
116305 db->nDeferredImmCons = 0;
116306 db->flags &= ~SQLITE_DeferFKs;
116307
116308 /* If one has been configured, invoke the rollback-hook callback */
116309 if( db->xRollbackCallback && (inTrans || !db->autoCommit) ){
116310 db->xRollbackCallback(db->pRollbackArg);
116311 }
@@ -116388,11 +116563,11 @@
116563 void *pArg
116564 ){
116565 sqlite3_mutex_enter(db->mutex);
116566 if( nOps>0 ){
116567 db->xProgress = xProgress;
116568 db->nProgressOps = (unsigned)nOps;
116569 db->pProgressArg = pArg;
116570 }else{
116571 db->xProgress = 0;
116572 db->nProgressOps = 0;
116573 db->pProgressArg = 0;
@@ -119087,11 +119262,11 @@
119262
119263 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
119264
119265 /* If not building as part of the core, include sqlite3ext.h. */
119266 #ifndef SQLITE_CORE
119267 SQLITE_EXTENSION_INIT3
119268 #endif
119269
119270 /************** Include fts3_tokenizer.h in the middle of fts3Int.h **********/
119271 /************** Begin file fts3_tokenizer.h **********************************/
119272 /*
@@ -124995,11 +125170,14 @@
125170
125171 #if !SQLITE_CORE
125172 /*
125173 ** Initialize API pointer table, if required.
125174 */
125175 #ifdef _WIN32
125176 __declspec(dllexport)
125177 #endif
125178 SQLITE_API int sqlite3_fts3_init(
125179 sqlite3 *db,
125180 char **pzErrMsg,
125181 const sqlite3_api_routines *pApi
125182 ){
125183 SQLITE_EXTENSION_INIT2(pApi)
@@ -140042,11 +140220,14 @@
140220 (void *)pGeomCtx, geomCallback, 0, 0, doSqlite3Free
140221 );
140222 }
140223
140224 #if !SQLITE_CORE
140225 #ifdef _WIN32
140226 __declspec(dllexport)
140227 #endif
140228 SQLITE_API int sqlite3_rtree_init(
140229 sqlite3 *db,
140230 char **pzErrMsg,
140231 const sqlite3_api_routines *pApi
140232 ){
140233 SQLITE_EXTENSION_INIT2(pApi)
@@ -140544,11 +140725,14 @@
140725
140726 return rc;
140727 }
140728
140729 #if !SQLITE_CORE
140730 #ifdef _WIN32
140731 __declspec(dllexport)
140732 #endif
140733 SQLITE_API int sqlite3_icu_init(
140734 sqlite3 *db,
140735 char **pzErrMsg,
140736 const sqlite3_api_routines *pApi
140737 ){
140738 SQLITE_EXTENSION_INIT2(pApi)
140739
+24 -4
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110110
#define SQLITE_VERSION "3.8.0"
111111
#define SQLITE_VERSION_NUMBER 3008000
112
-#define SQLITE_SOURCE_ID "2013-07-09 03:04:32 52a49cbc1621094b2fe2b021209b768d29e0426b"
112
+#define SQLITE_SOURCE_ID "2013-07-17 11:54:47 64bf8148b84e0ebb45c12b629f49bc9b316aceba"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -2557,11 +2557,11 @@
25572557
** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
25582558
** database connection D. An example use for this
25592559
** interface is to keep a GUI updated during a large query.
25602560
**
25612561
** ^The parameter P is passed through as the only parameter to the
2562
-** callback function X. ^The parameter N is the number of
2562
+** callback function X. ^The parameter N is the approximate number of
25632563
** [virtual machine instructions] that are evaluated between successive
25642564
** invocations of the callback X.
25652565
**
25662566
** ^Only a single progress handler may be defined at one time per
25672567
** [database connection]; setting a new progress handler cancels the
@@ -5126,14 +5126,27 @@
51265126
**
51275127
** ^Calling sqlite3_auto_extension(X) with an entry point X that is already
51285128
** on the list of automatic extensions is a harmless no-op. ^No entry point
51295129
** will be called more than once for each database connection that is opened.
51305130
**
5131
-** See also: [sqlite3_reset_auto_extension()].
5131
+** See also: [sqlite3_reset_auto_extension()]
5132
+** and [sqlite3_cancel_auto_extension()]
51325133
*/
51335134
SQLITE_API int sqlite3_auto_extension(void (*xEntryPoint)(void));
51345135
5136
+/*
5137
+** CAPI3REF: Cancel Automatic Extension Loading
5138
+**
5139
+** ^The [sqlite3_cancel_auto_extension(X)] interface unregisters the
5140
+** initialization routine X that was registered using a prior call to
5141
+** [sqlite3_auto_extension(X)]. ^The [sqlite3_cancel_auto_extension(X)]
5142
+** routine returns 1 if initialization routine X was successfully
5143
+** unregistered and it returns 0 if X was not on the list of initialization
5144
+** routines.
5145
+*/
5146
+SQLITE_API int sqlite3_cancel_auto_extension(void (*xEntryPoint)(void));
5147
+
51355148
/*
51365149
** CAPI3REF: Reset Automatic Extension Loading
51375150
**
51385151
** ^This interface disables all automatic extensions previously
51395152
** registered using [sqlite3_auto_extension()].
@@ -6242,10 +6255,16 @@
62426255
** transaction rollback or database recovery operations are not included.
62436256
** If an IO or other error occurs while writing a page to disk, the effect
62446257
** on subsequent SQLITE_DBSTATUS_CACHE_WRITE requests is undefined.)^ ^The
62456258
** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0.
62466259
** </dd>
6260
+**
6261
+** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt>
6262
+** <dd>This parameter returns the zero for the current value if and only if
6263
+** there all foreign key constraints (deferred or immediate) have been
6264
+** resolved. The highwater mark is always 0.
6265
+** </dd>
62476266
** </dl>
62486267
*/
62496268
#define SQLITE_DBSTATUS_LOOKASIDE_USED 0
62506269
#define SQLITE_DBSTATUS_CACHE_USED 1
62516270
#define SQLITE_DBSTATUS_SCHEMA_USED 2
@@ -6254,11 +6273,12 @@
62546273
#define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5
62556274
#define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6
62566275
#define SQLITE_DBSTATUS_CACHE_HIT 7
62576276
#define SQLITE_DBSTATUS_CACHE_MISS 8
62586277
#define SQLITE_DBSTATUS_CACHE_WRITE 9
6259
-#define SQLITE_DBSTATUS_MAX 9 /* Largest defined DBSTATUS */
6278
+#define SQLITE_DBSTATUS_DEFERRED_FKS 10
6279
+#define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */
62606280
62616281
62626282
/*
62636283
** CAPI3REF: Prepared Statement Status
62646284
**
62656285
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.0"
111 #define SQLITE_VERSION_NUMBER 3008000
112 #define SQLITE_SOURCE_ID "2013-07-09 03:04:32 52a49cbc1621094b2fe2b021209b768d29e0426b"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -2557,11 +2557,11 @@
2557 ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
2558 ** database connection D. An example use for this
2559 ** interface is to keep a GUI updated during a large query.
2560 **
2561 ** ^The parameter P is passed through as the only parameter to the
2562 ** callback function X. ^The parameter N is the number of
2563 ** [virtual machine instructions] that are evaluated between successive
2564 ** invocations of the callback X.
2565 **
2566 ** ^Only a single progress handler may be defined at one time per
2567 ** [database connection]; setting a new progress handler cancels the
@@ -5126,14 +5126,27 @@
5126 **
5127 ** ^Calling sqlite3_auto_extension(X) with an entry point X that is already
5128 ** on the list of automatic extensions is a harmless no-op. ^No entry point
5129 ** will be called more than once for each database connection that is opened.
5130 **
5131 ** See also: [sqlite3_reset_auto_extension()].
 
5132 */
5133 SQLITE_API int sqlite3_auto_extension(void (*xEntryPoint)(void));
5134
 
 
 
 
 
 
 
 
 
 
 
 
5135 /*
5136 ** CAPI3REF: Reset Automatic Extension Loading
5137 **
5138 ** ^This interface disables all automatic extensions previously
5139 ** registered using [sqlite3_auto_extension()].
@@ -6242,10 +6255,16 @@
6242 ** transaction rollback or database recovery operations are not included.
6243 ** If an IO or other error occurs while writing a page to disk, the effect
6244 ** on subsequent SQLITE_DBSTATUS_CACHE_WRITE requests is undefined.)^ ^The
6245 ** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0.
6246 ** </dd>
 
 
 
 
 
 
6247 ** </dl>
6248 */
6249 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
6250 #define SQLITE_DBSTATUS_CACHE_USED 1
6251 #define SQLITE_DBSTATUS_SCHEMA_USED 2
@@ -6254,11 +6273,12 @@
6254 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5
6255 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6
6256 #define SQLITE_DBSTATUS_CACHE_HIT 7
6257 #define SQLITE_DBSTATUS_CACHE_MISS 8
6258 #define SQLITE_DBSTATUS_CACHE_WRITE 9
6259 #define SQLITE_DBSTATUS_MAX 9 /* Largest defined DBSTATUS */
 
6260
6261
6262 /*
6263 ** CAPI3REF: Prepared Statement Status
6264 **
6265
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.0"
111 #define SQLITE_VERSION_NUMBER 3008000
112 #define SQLITE_SOURCE_ID "2013-07-17 11:54:47 64bf8148b84e0ebb45c12b629f49bc9b316aceba"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -2557,11 +2557,11 @@
2557 ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
2558 ** database connection D. An example use for this
2559 ** interface is to keep a GUI updated during a large query.
2560 **
2561 ** ^The parameter P is passed through as the only parameter to the
2562 ** callback function X. ^The parameter N is the approximate number of
2563 ** [virtual machine instructions] that are evaluated between successive
2564 ** invocations of the callback X.
2565 **
2566 ** ^Only a single progress handler may be defined at one time per
2567 ** [database connection]; setting a new progress handler cancels the
@@ -5126,14 +5126,27 @@
5126 **
5127 ** ^Calling sqlite3_auto_extension(X) with an entry point X that is already
5128 ** on the list of automatic extensions is a harmless no-op. ^No entry point
5129 ** will be called more than once for each database connection that is opened.
5130 **
5131 ** See also: [sqlite3_reset_auto_extension()]
5132 ** and [sqlite3_cancel_auto_extension()]
5133 */
5134 SQLITE_API int sqlite3_auto_extension(void (*xEntryPoint)(void));
5135
5136 /*
5137 ** CAPI3REF: Cancel Automatic Extension Loading
5138 **
5139 ** ^The [sqlite3_cancel_auto_extension(X)] interface unregisters the
5140 ** initialization routine X that was registered using a prior call to
5141 ** [sqlite3_auto_extension(X)]. ^The [sqlite3_cancel_auto_extension(X)]
5142 ** routine returns 1 if initialization routine X was successfully
5143 ** unregistered and it returns 0 if X was not on the list of initialization
5144 ** routines.
5145 */
5146 SQLITE_API int sqlite3_cancel_auto_extension(void (*xEntryPoint)(void));
5147
5148 /*
5149 ** CAPI3REF: Reset Automatic Extension Loading
5150 **
5151 ** ^This interface disables all automatic extensions previously
5152 ** registered using [sqlite3_auto_extension()].
@@ -6242,10 +6255,16 @@
6255 ** transaction rollback or database recovery operations are not included.
6256 ** If an IO or other error occurs while writing a page to disk, the effect
6257 ** on subsequent SQLITE_DBSTATUS_CACHE_WRITE requests is undefined.)^ ^The
6258 ** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0.
6259 ** </dd>
6260 **
6261 ** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt>
6262 ** <dd>This parameter returns the zero for the current value if and only if
6263 ** there all foreign key constraints (deferred or immediate) have been
6264 ** resolved. The highwater mark is always 0.
6265 ** </dd>
6266 ** </dl>
6267 */
6268 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
6269 #define SQLITE_DBSTATUS_CACHE_USED 1
6270 #define SQLITE_DBSTATUS_SCHEMA_USED 2
@@ -6254,11 +6273,12 @@
6273 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5
6274 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6
6275 #define SQLITE_DBSTATUS_CACHE_HIT 7
6276 #define SQLITE_DBSTATUS_CACHE_MISS 8
6277 #define SQLITE_DBSTATUS_CACHE_WRITE 9
6278 #define SQLITE_DBSTATUS_DEFERRED_FKS 10
6279 #define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */
6280
6281
6282 /*
6283 ** CAPI3REF: Prepared Statement Status
6284 **
6285

Keyboard Shortcuts

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