Fossil SCM

Update the built-in SQLite to the latest 3.33.0 alpha, for testing.

drh 2020-07-30 22:09 trunk
Commit 38d1b32bdec37cde163b68fbefcf6f480f8722fa2bf0e029a1e3cb1387dbf225
3 files changed +19 -3 +619 -461 +1 -1
+19 -3
--- src/shell.c
+++ src/shell.c
@@ -639,10 +639,25 @@
639639
if( (0xc0&*(z++))!=0x80 ) n++;
640640
}
641641
return n;
642642
}
643643
644
+/*
645
+** Return true if zFile does not exist or if it is not an ordinary file.
646
+*/
647
+#ifdef _WIN32
648
+# define notNormalFile(X) 0
649
+#else
650
+static int notNormalFile(const char *zFile){
651
+ struct stat x;
652
+ int rc;
653
+ memset(&x, 0, sizeof(x));
654
+ rc = stat(zFile, &x);
655
+ return rc || !S_ISREG(x.st_mode);
656
+}
657
+#endif
658
+
644659
/*
645660
** This routine reads a line of text from FILE in, stores
646661
** the text in memory obtained from malloc() and returns a pointer
647662
** to the text. NULL is returned at end of file, or if malloc()
648663
** fails.
@@ -4045,11 +4060,11 @@
40454060
return pSubVfs->xOpen(pSubVfs, zName, pFile, flags, pOutFlags);
40464061
}
40474062
p = (ApndFile*)pFile;
40484063
memset(p, 0, sizeof(*p));
40494064
pSubFile = ORIGFILE(pFile);
4050
- p->base.pMethods = &apnd_io_methods;
4065
+ pFile->pMethods = &apnd_io_methods;
40514066
rc = pSubVfs->xOpen(pSubVfs, zName, pSubFile, flags, pOutFlags);
40524067
if( rc ) goto apnd_open_done;
40534068
rc = pSubFile->pMethods->xFileSize(pSubFile, &sz);
40544069
if( rc ){
40554070
pSubFile->pMethods->xClose(pSubFile);
@@ -18515,12 +18530,13 @@
1851518530
if( nArg!=2 ){
1851618531
raw_printf(stderr, "Usage: .read FILE\n");
1851718532
rc = 1;
1851818533
goto meta_command_exit;
1851918534
}
18520
- p->in = fopen(azArg[1], "rb");
18521
- if( p->in==0 ){
18535
+ if( notNormalFile(azArg[1])
18536
+ || (p->in = fopen(azArg[1], "rb"))==0
18537
+ ){
1852218538
utf8_printf(stderr,"Error: cannot open \"%s\"\n", azArg[1]);
1852318539
rc = 1;
1852418540
}else{
1852518541
rc = process_input(p);
1852618542
fclose(p->in);
1852718543
--- src/shell.c
+++ src/shell.c
@@ -639,10 +639,25 @@
639 if( (0xc0&*(z++))!=0x80 ) n++;
640 }
641 return n;
642 }
643
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
644 /*
645 ** This routine reads a line of text from FILE in, stores
646 ** the text in memory obtained from malloc() and returns a pointer
647 ** to the text. NULL is returned at end of file, or if malloc()
648 ** fails.
@@ -4045,11 +4060,11 @@
4045 return pSubVfs->xOpen(pSubVfs, zName, pFile, flags, pOutFlags);
4046 }
4047 p = (ApndFile*)pFile;
4048 memset(p, 0, sizeof(*p));
4049 pSubFile = ORIGFILE(pFile);
4050 p->base.pMethods = &apnd_io_methods;
4051 rc = pSubVfs->xOpen(pSubVfs, zName, pSubFile, flags, pOutFlags);
4052 if( rc ) goto apnd_open_done;
4053 rc = pSubFile->pMethods->xFileSize(pSubFile, &sz);
4054 if( rc ){
4055 pSubFile->pMethods->xClose(pSubFile);
@@ -18515,12 +18530,13 @@
18515 if( nArg!=2 ){
18516 raw_printf(stderr, "Usage: .read FILE\n");
18517 rc = 1;
18518 goto meta_command_exit;
18519 }
18520 p->in = fopen(azArg[1], "rb");
18521 if( p->in==0 ){
 
18522 utf8_printf(stderr,"Error: cannot open \"%s\"\n", azArg[1]);
18523 rc = 1;
18524 }else{
18525 rc = process_input(p);
18526 fclose(p->in);
18527
--- src/shell.c
+++ src/shell.c
@@ -639,10 +639,25 @@
639 if( (0xc0&*(z++))!=0x80 ) n++;
640 }
641 return n;
642 }
643
644 /*
645 ** Return true if zFile does not exist or if it is not an ordinary file.
646 */
647 #ifdef _WIN32
648 # define notNormalFile(X) 0
649 #else
650 static int notNormalFile(const char *zFile){
651 struct stat x;
652 int rc;
653 memset(&x, 0, sizeof(x));
654 rc = stat(zFile, &x);
655 return rc || !S_ISREG(x.st_mode);
656 }
657 #endif
658
659 /*
660 ** This routine reads a line of text from FILE in, stores
661 ** the text in memory obtained from malloc() and returns a pointer
662 ** to the text. NULL is returned at end of file, or if malloc()
663 ** fails.
@@ -4045,11 +4060,11 @@
4060 return pSubVfs->xOpen(pSubVfs, zName, pFile, flags, pOutFlags);
4061 }
4062 p = (ApndFile*)pFile;
4063 memset(p, 0, sizeof(*p));
4064 pSubFile = ORIGFILE(pFile);
4065 pFile->pMethods = &apnd_io_methods;
4066 rc = pSubVfs->xOpen(pSubVfs, zName, pSubFile, flags, pOutFlags);
4067 if( rc ) goto apnd_open_done;
4068 rc = pSubFile->pMethods->xFileSize(pSubFile, &sz);
4069 if( rc ){
4070 pSubFile->pMethods->xClose(pSubFile);
@@ -18515,12 +18530,13 @@
18530 if( nArg!=2 ){
18531 raw_printf(stderr, "Usage: .read FILE\n");
18532 rc = 1;
18533 goto meta_command_exit;
18534 }
18535 if( notNormalFile(azArg[1])
18536 || (p->in = fopen(azArg[1], "rb"))==0
18537 ){
18538 utf8_printf(stderr,"Error: cannot open \"%s\"\n", azArg[1]);
18539 rc = 1;
18540 }else{
18541 rc = process_input(p);
18542 fclose(p->in);
18543
+619 -461
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1162,11 +1162,11 @@
11621162
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11631163
** [sqlite_version()] and [sqlite_source_id()].
11641164
*/
11651165
#define SQLITE_VERSION "3.33.0"
11661166
#define SQLITE_VERSION_NUMBER 3033000
1167
-#define SQLITE_SOURCE_ID "2020-07-18 18:59:11 020dbfa2aef20e5872cc3e785d99f45903843401292114b5092b9c8aa829b9c3"
1167
+#define SQLITE_SOURCE_ID "2020-07-30 17:37:49 96e3dba2ed3ab0c5b2ecf65a3408633e0767c884d48c270e9ef10ab9fa3ec051"
11681168
11691169
/*
11701170
** CAPI3REF: Run-Time Library Version Numbers
11711171
** KEYWORDS: sqlite3_version sqlite3_sourceid
11721172
**
@@ -14735,10 +14735,257 @@
1473514735
/*
1473614736
** Defer sourcing vdbe.h and btree.h until after the "u8" and
1473714737
** "BusyHandler" typedefs. vdbe.h also requires a few of the opaque
1473814738
** pointer types (i.e. FuncDef) defined above.
1473914739
*/
14740
+/************** Include pager.h in the middle of sqliteInt.h *****************/
14741
+/************** Begin file pager.h *******************************************/
14742
+/*
14743
+** 2001 September 15
14744
+**
14745
+** The author disclaims copyright to this source code. In place of
14746
+** a legal notice, here is a blessing:
14747
+**
14748
+** May you do good and not evil.
14749
+** May you find forgiveness for yourself and forgive others.
14750
+** May you share freely, never taking more than you give.
14751
+**
14752
+*************************************************************************
14753
+** This header file defines the interface that the sqlite page cache
14754
+** subsystem. The page cache subsystem reads and writes a file a page
14755
+** at a time and provides a journal for rollback.
14756
+*/
14757
+
14758
+#ifndef SQLITE_PAGER_H
14759
+#define SQLITE_PAGER_H
14760
+
14761
+/*
14762
+** Default maximum size for persistent journal files. A negative
14763
+** value means no limit. This value may be overridden using the
14764
+** sqlite3PagerJournalSizeLimit() API. See also "PRAGMA journal_size_limit".
14765
+*/
14766
+#ifndef SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT
14767
+ #define SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT -1
14768
+#endif
14769
+
14770
+/*
14771
+** The type used to represent a page number. The first page in a file
14772
+** is called page 1. 0 is used to represent "not a page".
14773
+*/
14774
+typedef u32 Pgno;
14775
+
14776
+/*
14777
+** Each open file is managed by a separate instance of the "Pager" structure.
14778
+*/
14779
+typedef struct Pager Pager;
14780
+
14781
+/*
14782
+** Handle type for pages.
14783
+*/
14784
+typedef struct PgHdr DbPage;
14785
+
14786
+/*
14787
+** Page number PAGER_MJ_PGNO is never used in an SQLite database (it is
14788
+** reserved for working around a windows/posix incompatibility). It is
14789
+** used in the journal to signify that the remainder of the journal file
14790
+** is devoted to storing a super-journal name - there are no more pages to
14791
+** roll back. See comments for function writeSuperJournal() in pager.c
14792
+** for details.
14793
+*/
14794
+#define PAGER_MJ_PGNO(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1))
14795
+
14796
+/*
14797
+** Allowed values for the flags parameter to sqlite3PagerOpen().
14798
+**
14799
+** NOTE: These values must match the corresponding BTREE_ values in btree.h.
14800
+*/
14801
+#define PAGER_OMIT_JOURNAL 0x0001 /* Do not use a rollback journal */
14802
+#define PAGER_MEMORY 0x0002 /* In-memory database */
14803
+
14804
+/*
14805
+** Valid values for the second argument to sqlite3PagerLockingMode().
14806
+*/
14807
+#define PAGER_LOCKINGMODE_QUERY -1
14808
+#define PAGER_LOCKINGMODE_NORMAL 0
14809
+#define PAGER_LOCKINGMODE_EXCLUSIVE 1
14810
+
14811
+/*
14812
+** Numeric constants that encode the journalmode.
14813
+**
14814
+** The numeric values encoded here (other than PAGER_JOURNALMODE_QUERY)
14815
+** are exposed in the API via the "PRAGMA journal_mode" command and
14816
+** therefore cannot be changed without a compatibility break.
14817
+*/
14818
+#define PAGER_JOURNALMODE_QUERY (-1) /* Query the value of journalmode */
14819
+#define PAGER_JOURNALMODE_DELETE 0 /* Commit by deleting journal file */
14820
+#define PAGER_JOURNALMODE_PERSIST 1 /* Commit by zeroing journal header */
14821
+#define PAGER_JOURNALMODE_OFF 2 /* Journal omitted. */
14822
+#define PAGER_JOURNALMODE_TRUNCATE 3 /* Commit by truncating journal */
14823
+#define PAGER_JOURNALMODE_MEMORY 4 /* In-memory journal file */
14824
+#define PAGER_JOURNALMODE_WAL 5 /* Use write-ahead logging */
14825
+
14826
+/*
14827
+** Flags that make up the mask passed to sqlite3PagerGet().
14828
+*/
14829
+#define PAGER_GET_NOCONTENT 0x01 /* Do not load data from disk */
14830
+#define PAGER_GET_READONLY 0x02 /* Read-only page is acceptable */
14831
+
14832
+/*
14833
+** Flags for sqlite3PagerSetFlags()
14834
+**
14835
+** Value constraints (enforced via assert()):
14836
+** PAGER_FULLFSYNC == SQLITE_FullFSync
14837
+** PAGER_CKPT_FULLFSYNC == SQLITE_CkptFullFSync
14838
+** PAGER_CACHE_SPILL == SQLITE_CacheSpill
14839
+*/
14840
+#define PAGER_SYNCHRONOUS_OFF 0x01 /* PRAGMA synchronous=OFF */
14841
+#define PAGER_SYNCHRONOUS_NORMAL 0x02 /* PRAGMA synchronous=NORMAL */
14842
+#define PAGER_SYNCHRONOUS_FULL 0x03 /* PRAGMA synchronous=FULL */
14843
+#define PAGER_SYNCHRONOUS_EXTRA 0x04 /* PRAGMA synchronous=EXTRA */
14844
+#define PAGER_SYNCHRONOUS_MASK 0x07 /* Mask for four values above */
14845
+#define PAGER_FULLFSYNC 0x08 /* PRAGMA fullfsync=ON */
14846
+#define PAGER_CKPT_FULLFSYNC 0x10 /* PRAGMA checkpoint_fullfsync=ON */
14847
+#define PAGER_CACHESPILL 0x20 /* PRAGMA cache_spill=ON */
14848
+#define PAGER_FLAGS_MASK 0x38 /* All above except SYNCHRONOUS */
14849
+
14850
+/*
14851
+** The remainder of this file contains the declarations of the functions
14852
+** that make up the Pager sub-system API. See source code comments for
14853
+** a detailed description of each routine.
14854
+*/
14855
+
14856
+/* Open and close a Pager connection. */
14857
+SQLITE_PRIVATE int sqlite3PagerOpen(
14858
+ sqlite3_vfs*,
14859
+ Pager **ppPager,
14860
+ const char*,
14861
+ int,
14862
+ int,
14863
+ int,
14864
+ void(*)(DbPage*)
14865
+);
14866
+SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager, sqlite3*);
14867
+SQLITE_PRIVATE int sqlite3PagerReadFileheader(Pager*, int, unsigned char*);
14868
+
14869
+/* Functions used to configure a Pager object. */
14870
+SQLITE_PRIVATE void sqlite3PagerSetBusyHandler(Pager*, int(*)(void *), void *);
14871
+SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager*, u32*, int);
14872
+SQLITE_PRIVATE Pgno sqlite3PagerMaxPageCount(Pager*, Pgno);
14873
+SQLITE_PRIVATE void sqlite3PagerSetCachesize(Pager*, int);
14874
+SQLITE_PRIVATE int sqlite3PagerSetSpillsize(Pager*, int);
14875
+SQLITE_PRIVATE void sqlite3PagerSetMmapLimit(Pager *, sqlite3_int64);
14876
+SQLITE_PRIVATE void sqlite3PagerShrink(Pager*);
14877
+SQLITE_PRIVATE void sqlite3PagerSetFlags(Pager*,unsigned);
14878
+SQLITE_PRIVATE int sqlite3PagerLockingMode(Pager *, int);
14879
+SQLITE_PRIVATE int sqlite3PagerSetJournalMode(Pager *, int);
14880
+SQLITE_PRIVATE int sqlite3PagerGetJournalMode(Pager*);
14881
+SQLITE_PRIVATE int sqlite3PagerOkToChangeJournalMode(Pager*);
14882
+SQLITE_PRIVATE i64 sqlite3PagerJournalSizeLimit(Pager *, i64);
14883
+SQLITE_PRIVATE sqlite3_backup **sqlite3PagerBackupPtr(Pager*);
14884
+SQLITE_PRIVATE int sqlite3PagerFlush(Pager*);
14885
+
14886
+/* Functions used to obtain and release page references. */
14887
+SQLITE_PRIVATE int sqlite3PagerGet(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag);
14888
+SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno);
14889
+SQLITE_PRIVATE void sqlite3PagerRef(DbPage*);
14890
+SQLITE_PRIVATE void sqlite3PagerUnref(DbPage*);
14891
+SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage*);
14892
+SQLITE_PRIVATE void sqlite3PagerUnrefPageOne(DbPage*);
14893
+
14894
+/* Operations on page references. */
14895
+SQLITE_PRIVATE int sqlite3PagerWrite(DbPage*);
14896
+SQLITE_PRIVATE void sqlite3PagerDontWrite(DbPage*);
14897
+SQLITE_PRIVATE int sqlite3PagerMovepage(Pager*,DbPage*,Pgno,int);
14898
+SQLITE_PRIVATE int sqlite3PagerPageRefcount(DbPage*);
14899
+SQLITE_PRIVATE void *sqlite3PagerGetData(DbPage *);
14900
+SQLITE_PRIVATE void *sqlite3PagerGetExtra(DbPage *);
14901
+
14902
+/* Functions used to manage pager transactions and savepoints. */
14903
+SQLITE_PRIVATE void sqlite3PagerPagecount(Pager*, int*);
14904
+SQLITE_PRIVATE int sqlite3PagerBegin(Pager*, int exFlag, int);
14905
+SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zSuper, int);
14906
+SQLITE_PRIVATE int sqlite3PagerExclusiveLock(Pager*);
14907
+SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zSuper);
14908
+SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager*);
14909
+SQLITE_PRIVATE int sqlite3PagerRollback(Pager*);
14910
+SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int n);
14911
+SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint);
14912
+SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager);
14913
+
14914
+#ifndef SQLITE_OMIT_WAL
14915
+SQLITE_PRIVATE int sqlite3PagerCheckpoint(Pager *pPager, sqlite3*, int, int*, int*);
14916
+SQLITE_PRIVATE int sqlite3PagerWalSupported(Pager *pPager);
14917
+SQLITE_PRIVATE int sqlite3PagerWalCallback(Pager *pPager);
14918
+SQLITE_PRIVATE int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen);
14919
+SQLITE_PRIVATE int sqlite3PagerCloseWal(Pager *pPager, sqlite3*);
14920
+# ifdef SQLITE_ENABLE_SNAPSHOT
14921
+SQLITE_PRIVATE int sqlite3PagerSnapshotGet(Pager*, sqlite3_snapshot **ppSnapshot);
14922
+SQLITE_PRIVATE int sqlite3PagerSnapshotOpen(Pager*, sqlite3_snapshot *pSnapshot);
14923
+SQLITE_PRIVATE int sqlite3PagerSnapshotRecover(Pager *pPager);
14924
+SQLITE_PRIVATE int sqlite3PagerSnapshotCheck(Pager *pPager, sqlite3_snapshot *pSnapshot);
14925
+SQLITE_PRIVATE void sqlite3PagerSnapshotUnlock(Pager *pPager);
14926
+# endif
14927
+#endif
14928
+
14929
+#if !defined(SQLITE_OMIT_WAL) && defined(SQLITE_ENABLE_SETLK_TIMEOUT)
14930
+SQLITE_PRIVATE int sqlite3PagerWalWriteLock(Pager*, int);
14931
+SQLITE_PRIVATE void sqlite3PagerWalDb(Pager*, sqlite3*);
14932
+#else
14933
+# define sqlite3PagerWalWriteLock(y,z) SQLITE_OK
14934
+# define sqlite3PagerWalDb(x,y)
14935
+#endif
14936
+
14937
+#ifdef SQLITE_DIRECT_OVERFLOW_READ
14938
+SQLITE_PRIVATE int sqlite3PagerDirectReadOk(Pager *pPager, Pgno pgno);
14939
+#endif
14940
+
14941
+#ifdef SQLITE_ENABLE_ZIPVFS
14942
+SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager);
14943
+#endif
14944
+
14945
+/* Functions used to query pager state and configuration. */
14946
+SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*);
14947
+SQLITE_PRIVATE u32 sqlite3PagerDataVersion(Pager*);
14948
+#ifdef SQLITE_DEBUG
14949
+SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
14950
+#endif
14951
+SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*);
14952
+SQLITE_PRIVATE const char *sqlite3PagerFilename(const Pager*, int);
14953
+SQLITE_PRIVATE sqlite3_vfs *sqlite3PagerVfs(Pager*);
14954
+SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*);
14955
+SQLITE_PRIVATE sqlite3_file *sqlite3PagerJrnlFile(Pager*);
14956
+SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*);
14957
+SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*);
14958
+SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager*);
14959
+SQLITE_PRIVATE void sqlite3PagerCacheStat(Pager *, int, int, int *);
14960
+SQLITE_PRIVATE void sqlite3PagerClearCache(Pager*);
14961
+SQLITE_PRIVATE int sqlite3SectorSize(sqlite3_file *);
14962
+
14963
+/* Functions used to truncate the database file. */
14964
+SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno);
14965
+
14966
+SQLITE_PRIVATE void sqlite3PagerRekey(DbPage*, Pgno, u16);
14967
+
14968
+/* Functions to support testing and debugging. */
14969
+#if !defined(NDEBUG) || defined(SQLITE_TEST)
14970
+SQLITE_PRIVATE Pgno sqlite3PagerPagenumber(DbPage*);
14971
+SQLITE_PRIVATE int sqlite3PagerIswriteable(DbPage*);
14972
+#endif
14973
+#ifdef SQLITE_TEST
14974
+SQLITE_PRIVATE int *sqlite3PagerStats(Pager*);
14975
+SQLITE_PRIVATE void sqlite3PagerRefdump(Pager*);
14976
+ void disable_simulated_io_errors(void);
14977
+ void enable_simulated_io_errors(void);
14978
+#else
14979
+# define disable_simulated_io_errors()
14980
+# define enable_simulated_io_errors()
14981
+#endif
14982
+
14983
+#endif /* SQLITE_PAGER_H */
14984
+
14985
+/************** End of pager.h ***********************************************/
14986
+/************** Continuing where we left off in sqliteInt.h ******************/
1474014987
/************** Include btree.h in the middle of sqliteInt.h *****************/
1474114988
/************** Begin file btree.h *******************************************/
1474214989
/*
1474314990
** 2001 September 15
1474414991
**
@@ -14810,12 +15057,12 @@
1481015057
SQLITE_PRIVATE int sqlite3BtreeSetMmapLimit(Btree*,sqlite3_int64);
1481115058
#endif
1481215059
SQLITE_PRIVATE int sqlite3BtreeSetPagerFlags(Btree*,unsigned);
1481315060
SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve, int eFix);
1481415061
SQLITE_PRIVATE int sqlite3BtreeGetPageSize(Btree*);
14815
-SQLITE_PRIVATE int sqlite3BtreeMaxPageCount(Btree*,int);
14816
-SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree*);
15062
+SQLITE_PRIVATE Pgno sqlite3BtreeMaxPageCount(Btree*,Pgno);
15063
+SQLITE_PRIVATE Pgno sqlite3BtreeLastPage(Btree*);
1481715064
SQLITE_PRIVATE int sqlite3BtreeSecureDelete(Btree*,int);
1481815065
SQLITE_PRIVATE int sqlite3BtreeGetRequestedReserve(Btree*);
1481915066
SQLITE_PRIVATE int sqlite3BtreeGetReserveNoMutex(Btree *p);
1482015067
SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum(Btree *, int);
1482115068
SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *);
@@ -14823,11 +15070,11 @@
1482315070
SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree*, const char*);
1482415071
SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree*, int);
1482515072
SQLITE_PRIVATE int sqlite3BtreeCommit(Btree*);
1482615073
SQLITE_PRIVATE int sqlite3BtreeRollback(Btree*,int,int);
1482715074
SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree*,int);
14828
-SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree*, int*, int flags);
15075
+SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree*, Pgno*, int flags);
1482915076
SQLITE_PRIVATE int sqlite3BtreeIsInTrans(Btree*);
1483015077
SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree*);
1483115078
SQLITE_PRIVATE int sqlite3BtreeIsInBackup(Btree*);
1483215079
SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *, int, void(*)(void *));
1483315080
SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *pBtree);
@@ -14964,11 +15211,11 @@
1496415211
#define BTREE_WRCSR 0x00000004 /* read-write cursor */
1496515212
#define BTREE_FORDELETE 0x00000008 /* Cursor is for seek/delete only */
1496615213
1496715214
SQLITE_PRIVATE int sqlite3BtreeCursor(
1496815215
Btree*, /* BTree containing table to open */
14969
- int iTable, /* Index of root page */
15216
+ Pgno iTable, /* Index of root page */
1497015217
int wrFlag, /* 1 for writing. 0 for read-only */
1497115218
struct KeyInfo*, /* First argument to compare function */
1497215219
BtCursor *pCursor /* Space to write cursor structure */
1497315220
);
1497415221
SQLITE_PRIVATE BtCursor *sqlite3BtreeFakeValidCursor(void);
@@ -15055,11 +15302,11 @@
1505515302
SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*);
1505615303
SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt);
1505715304
SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*);
1505815305
SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeMaxRecordSize(BtCursor*);
1505915306
15060
-SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(sqlite3*,Btree*,int*aRoot,int nRoot,int,int*);
15307
+SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(sqlite3*,Btree*,Pgno*aRoot,int nRoot,int,int*);
1506115308
SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
1506215309
SQLITE_PRIVATE i64 sqlite3BtreeRowCountEst(BtCursor*);
1506315310
1506415311
#ifndef SQLITE_OMIT_INCRBLOB
1506515312
SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor*, u32 offset, u32 amt, void*);
@@ -15192,11 +15439,11 @@
1519215439
sqlite3_context *pCtx; /* Used when p4type is P4_FUNCCTX */
1519315440
CollSeq *pColl; /* Used when p4type is P4_COLLSEQ */
1519415441
Mem *pMem; /* Used when p4type is P4_MEM */
1519515442
VTable *pVtab; /* Used when p4type is P4_VTAB */
1519615443
KeyInfo *pKeyInfo; /* Used when p4type is P4_KEYINFO */
15197
- int *ai; /* Used when p4type is P4_INTARRAY */
15444
+ u32 *ai; /* Used when p4type is P4_INTARRAY */
1519815445
SubProgram *pProgram; /* Used when p4type is P4_SUBPROGRAM */
1519915446
Table *pTab; /* Used when p4type is P4_TABLE */
1520015447
#ifdef SQLITE_ENABLE_CURSOR_HINTS
1520115448
Expr *pExpr; /* Used when p4type is P4_EXPR */
1520215449
#endif
@@ -15756,257 +16003,10 @@
1575616003
#endif
1575716004
1575816005
#endif /* SQLITE_VDBE_H */
1575916006
1576016007
/************** End of vdbe.h ************************************************/
15761
-/************** Continuing where we left off in sqliteInt.h ******************/
15762
-/************** Include pager.h in the middle of sqliteInt.h *****************/
15763
-/************** Begin file pager.h *******************************************/
15764
-/*
15765
-** 2001 September 15
15766
-**
15767
-** The author disclaims copyright to this source code. In place of
15768
-** a legal notice, here is a blessing:
15769
-**
15770
-** May you do good and not evil.
15771
-** May you find forgiveness for yourself and forgive others.
15772
-** May you share freely, never taking more than you give.
15773
-**
15774
-*************************************************************************
15775
-** This header file defines the interface that the sqlite page cache
15776
-** subsystem. The page cache subsystem reads and writes a file a page
15777
-** at a time and provides a journal for rollback.
15778
-*/
15779
-
15780
-#ifndef SQLITE_PAGER_H
15781
-#define SQLITE_PAGER_H
15782
-
15783
-/*
15784
-** Default maximum size for persistent journal files. A negative
15785
-** value means no limit. This value may be overridden using the
15786
-** sqlite3PagerJournalSizeLimit() API. See also "PRAGMA journal_size_limit".
15787
-*/
15788
-#ifndef SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT
15789
- #define SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT -1
15790
-#endif
15791
-
15792
-/*
15793
-** The type used to represent a page number. The first page in a file
15794
-** is called page 1. 0 is used to represent "not a page".
15795
-*/
15796
-typedef u32 Pgno;
15797
-
15798
-/*
15799
-** Each open file is managed by a separate instance of the "Pager" structure.
15800
-*/
15801
-typedef struct Pager Pager;
15802
-
15803
-/*
15804
-** Handle type for pages.
15805
-*/
15806
-typedef struct PgHdr DbPage;
15807
-
15808
-/*
15809
-** Page number PAGER_MJ_PGNO is never used in an SQLite database (it is
15810
-** reserved for working around a windows/posix incompatibility). It is
15811
-** used in the journal to signify that the remainder of the journal file
15812
-** is devoted to storing a super-journal name - there are no more pages to
15813
-** roll back. See comments for function writeSuperJournal() in pager.c
15814
-** for details.
15815
-*/
15816
-#define PAGER_MJ_PGNO(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1))
15817
-
15818
-/*
15819
-** Allowed values for the flags parameter to sqlite3PagerOpen().
15820
-**
15821
-** NOTE: These values must match the corresponding BTREE_ values in btree.h.
15822
-*/
15823
-#define PAGER_OMIT_JOURNAL 0x0001 /* Do not use a rollback journal */
15824
-#define PAGER_MEMORY 0x0002 /* In-memory database */
15825
-
15826
-/*
15827
-** Valid values for the second argument to sqlite3PagerLockingMode().
15828
-*/
15829
-#define PAGER_LOCKINGMODE_QUERY -1
15830
-#define PAGER_LOCKINGMODE_NORMAL 0
15831
-#define PAGER_LOCKINGMODE_EXCLUSIVE 1
15832
-
15833
-/*
15834
-** Numeric constants that encode the journalmode.
15835
-**
15836
-** The numeric values encoded here (other than PAGER_JOURNALMODE_QUERY)
15837
-** are exposed in the API via the "PRAGMA journal_mode" command and
15838
-** therefore cannot be changed without a compatibility break.
15839
-*/
15840
-#define PAGER_JOURNALMODE_QUERY (-1) /* Query the value of journalmode */
15841
-#define PAGER_JOURNALMODE_DELETE 0 /* Commit by deleting journal file */
15842
-#define PAGER_JOURNALMODE_PERSIST 1 /* Commit by zeroing journal header */
15843
-#define PAGER_JOURNALMODE_OFF 2 /* Journal omitted. */
15844
-#define PAGER_JOURNALMODE_TRUNCATE 3 /* Commit by truncating journal */
15845
-#define PAGER_JOURNALMODE_MEMORY 4 /* In-memory journal file */
15846
-#define PAGER_JOURNALMODE_WAL 5 /* Use write-ahead logging */
15847
-
15848
-/*
15849
-** Flags that make up the mask passed to sqlite3PagerGet().
15850
-*/
15851
-#define PAGER_GET_NOCONTENT 0x01 /* Do not load data from disk */
15852
-#define PAGER_GET_READONLY 0x02 /* Read-only page is acceptable */
15853
-
15854
-/*
15855
-** Flags for sqlite3PagerSetFlags()
15856
-**
15857
-** Value constraints (enforced via assert()):
15858
-** PAGER_FULLFSYNC == SQLITE_FullFSync
15859
-** PAGER_CKPT_FULLFSYNC == SQLITE_CkptFullFSync
15860
-** PAGER_CACHE_SPILL == SQLITE_CacheSpill
15861
-*/
15862
-#define PAGER_SYNCHRONOUS_OFF 0x01 /* PRAGMA synchronous=OFF */
15863
-#define PAGER_SYNCHRONOUS_NORMAL 0x02 /* PRAGMA synchronous=NORMAL */
15864
-#define PAGER_SYNCHRONOUS_FULL 0x03 /* PRAGMA synchronous=FULL */
15865
-#define PAGER_SYNCHRONOUS_EXTRA 0x04 /* PRAGMA synchronous=EXTRA */
15866
-#define PAGER_SYNCHRONOUS_MASK 0x07 /* Mask for four values above */
15867
-#define PAGER_FULLFSYNC 0x08 /* PRAGMA fullfsync=ON */
15868
-#define PAGER_CKPT_FULLFSYNC 0x10 /* PRAGMA checkpoint_fullfsync=ON */
15869
-#define PAGER_CACHESPILL 0x20 /* PRAGMA cache_spill=ON */
15870
-#define PAGER_FLAGS_MASK 0x38 /* All above except SYNCHRONOUS */
15871
-
15872
-/*
15873
-** The remainder of this file contains the declarations of the functions
15874
-** that make up the Pager sub-system API. See source code comments for
15875
-** a detailed description of each routine.
15876
-*/
15877
-
15878
-/* Open and close a Pager connection. */
15879
-SQLITE_PRIVATE int sqlite3PagerOpen(
15880
- sqlite3_vfs*,
15881
- Pager **ppPager,
15882
- const char*,
15883
- int,
15884
- int,
15885
- int,
15886
- void(*)(DbPage*)
15887
-);
15888
-SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager, sqlite3*);
15889
-SQLITE_PRIVATE int sqlite3PagerReadFileheader(Pager*, int, unsigned char*);
15890
-
15891
-/* Functions used to configure a Pager object. */
15892
-SQLITE_PRIVATE void sqlite3PagerSetBusyHandler(Pager*, int(*)(void *), void *);
15893
-SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager*, u32*, int);
15894
-SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager*, int);
15895
-SQLITE_PRIVATE void sqlite3PagerSetCachesize(Pager*, int);
15896
-SQLITE_PRIVATE int sqlite3PagerSetSpillsize(Pager*, int);
15897
-SQLITE_PRIVATE void sqlite3PagerSetMmapLimit(Pager *, sqlite3_int64);
15898
-SQLITE_PRIVATE void sqlite3PagerShrink(Pager*);
15899
-SQLITE_PRIVATE void sqlite3PagerSetFlags(Pager*,unsigned);
15900
-SQLITE_PRIVATE int sqlite3PagerLockingMode(Pager *, int);
15901
-SQLITE_PRIVATE int sqlite3PagerSetJournalMode(Pager *, int);
15902
-SQLITE_PRIVATE int sqlite3PagerGetJournalMode(Pager*);
15903
-SQLITE_PRIVATE int sqlite3PagerOkToChangeJournalMode(Pager*);
15904
-SQLITE_PRIVATE i64 sqlite3PagerJournalSizeLimit(Pager *, i64);
15905
-SQLITE_PRIVATE sqlite3_backup **sqlite3PagerBackupPtr(Pager*);
15906
-SQLITE_PRIVATE int sqlite3PagerFlush(Pager*);
15907
-
15908
-/* Functions used to obtain and release page references. */
15909
-SQLITE_PRIVATE int sqlite3PagerGet(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag);
15910
-SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno);
15911
-SQLITE_PRIVATE void sqlite3PagerRef(DbPage*);
15912
-SQLITE_PRIVATE void sqlite3PagerUnref(DbPage*);
15913
-SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage*);
15914
-SQLITE_PRIVATE void sqlite3PagerUnrefPageOne(DbPage*);
15915
-
15916
-/* Operations on page references. */
15917
-SQLITE_PRIVATE int sqlite3PagerWrite(DbPage*);
15918
-SQLITE_PRIVATE void sqlite3PagerDontWrite(DbPage*);
15919
-SQLITE_PRIVATE int sqlite3PagerMovepage(Pager*,DbPage*,Pgno,int);
15920
-SQLITE_PRIVATE int sqlite3PagerPageRefcount(DbPage*);
15921
-SQLITE_PRIVATE void *sqlite3PagerGetData(DbPage *);
15922
-SQLITE_PRIVATE void *sqlite3PagerGetExtra(DbPage *);
15923
-
15924
-/* Functions used to manage pager transactions and savepoints. */
15925
-SQLITE_PRIVATE void sqlite3PagerPagecount(Pager*, int*);
15926
-SQLITE_PRIVATE int sqlite3PagerBegin(Pager*, int exFlag, int);
15927
-SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zSuper, int);
15928
-SQLITE_PRIVATE int sqlite3PagerExclusiveLock(Pager*);
15929
-SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zSuper);
15930
-SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager*);
15931
-SQLITE_PRIVATE int sqlite3PagerRollback(Pager*);
15932
-SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int n);
15933
-SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint);
15934
-SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager);
15935
-
15936
-#ifndef SQLITE_OMIT_WAL
15937
-SQLITE_PRIVATE int sqlite3PagerCheckpoint(Pager *pPager, sqlite3*, int, int*, int*);
15938
-SQLITE_PRIVATE int sqlite3PagerWalSupported(Pager *pPager);
15939
-SQLITE_PRIVATE int sqlite3PagerWalCallback(Pager *pPager);
15940
-SQLITE_PRIVATE int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen);
15941
-SQLITE_PRIVATE int sqlite3PagerCloseWal(Pager *pPager, sqlite3*);
15942
-# ifdef SQLITE_ENABLE_SNAPSHOT
15943
-SQLITE_PRIVATE int sqlite3PagerSnapshotGet(Pager*, sqlite3_snapshot **ppSnapshot);
15944
-SQLITE_PRIVATE int sqlite3PagerSnapshotOpen(Pager*, sqlite3_snapshot *pSnapshot);
15945
-SQLITE_PRIVATE int sqlite3PagerSnapshotRecover(Pager *pPager);
15946
-SQLITE_PRIVATE int sqlite3PagerSnapshotCheck(Pager *pPager, sqlite3_snapshot *pSnapshot);
15947
-SQLITE_PRIVATE void sqlite3PagerSnapshotUnlock(Pager *pPager);
15948
-# endif
15949
-#endif
15950
-
15951
-#if !defined(SQLITE_OMIT_WAL) && defined(SQLITE_ENABLE_SETLK_TIMEOUT)
15952
-SQLITE_PRIVATE int sqlite3PagerWalWriteLock(Pager*, int);
15953
-SQLITE_PRIVATE void sqlite3PagerWalDb(Pager*, sqlite3*);
15954
-#else
15955
-# define sqlite3PagerWalWriteLock(y,z) SQLITE_OK
15956
-# define sqlite3PagerWalDb(x,y)
15957
-#endif
15958
-
15959
-#ifdef SQLITE_DIRECT_OVERFLOW_READ
15960
-SQLITE_PRIVATE int sqlite3PagerDirectReadOk(Pager *pPager, Pgno pgno);
15961
-#endif
15962
-
15963
-#ifdef SQLITE_ENABLE_ZIPVFS
15964
-SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager);
15965
-#endif
15966
-
15967
-/* Functions used to query pager state and configuration. */
15968
-SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*);
15969
-SQLITE_PRIVATE u32 sqlite3PagerDataVersion(Pager*);
15970
-#ifdef SQLITE_DEBUG
15971
-SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
15972
-#endif
15973
-SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*);
15974
-SQLITE_PRIVATE const char *sqlite3PagerFilename(const Pager*, int);
15975
-SQLITE_PRIVATE sqlite3_vfs *sqlite3PagerVfs(Pager*);
15976
-SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*);
15977
-SQLITE_PRIVATE sqlite3_file *sqlite3PagerJrnlFile(Pager*);
15978
-SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*);
15979
-SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*);
15980
-SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager*);
15981
-SQLITE_PRIVATE void sqlite3PagerCacheStat(Pager *, int, int, int *);
15982
-SQLITE_PRIVATE void sqlite3PagerClearCache(Pager*);
15983
-SQLITE_PRIVATE int sqlite3SectorSize(sqlite3_file *);
15984
-
15985
-/* Functions used to truncate the database file. */
15986
-SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno);
15987
-
15988
-SQLITE_PRIVATE void sqlite3PagerRekey(DbPage*, Pgno, u16);
15989
-
15990
-/* Functions to support testing and debugging. */
15991
-#if !defined(NDEBUG) || defined(SQLITE_TEST)
15992
-SQLITE_PRIVATE Pgno sqlite3PagerPagenumber(DbPage*);
15993
-SQLITE_PRIVATE int sqlite3PagerIswriteable(DbPage*);
15994
-#endif
15995
-#ifdef SQLITE_TEST
15996
-SQLITE_PRIVATE int *sqlite3PagerStats(Pager*);
15997
-SQLITE_PRIVATE void sqlite3PagerRefdump(Pager*);
15998
- void disable_simulated_io_errors(void);
15999
- void enable_simulated_io_errors(void);
16000
-#else
16001
-# define disable_simulated_io_errors()
16002
-# define enable_simulated_io_errors()
16003
-#endif
16004
-
16005
-#endif /* SQLITE_PAGER_H */
16006
-
16007
-/************** End of pager.h ***********************************************/
1600816008
/************** Continuing where we left off in sqliteInt.h ******************/
1600916009
/************** Include pcache.h in the middle of sqliteInt.h ****************/
1601016010
/************** Begin file pcache.h ******************************************/
1601116011
/*
1601216012
** 2008 August 05
@@ -16843,11 +16843,11 @@
1684316843
int nChange; /* Value returned by sqlite3_changes() */
1684416844
int nTotalChange; /* Value returned by sqlite3_total_changes() */
1684516845
int aLimit[SQLITE_N_LIMIT]; /* Limits */
1684616846
int nMaxSorterMmap; /* Maximum size of regions mapped by sorter */
1684716847
struct sqlite3InitInfo { /* Information used during initialization */
16848
- int newTnum; /* Rootpage of table being initialized */
16848
+ Pgno newTnum; /* Rootpage of table being initialized */
1684916849
u8 iDb; /* Which db file is being initialized */
1685016850
u8 busy; /* TRUE if currently initializing */
1685116851
unsigned orphanTrigger : 1; /* Last statement is orphaned TEMP trigger */
1685216852
unsigned imposterTable : 1; /* Building an imposter table */
1685316853
unsigned reopenMemdb : 1; /* ATTACH is really a reopen using MemDB */
@@ -17482,11 +17482,11 @@
1748217482
Select *pSelect; /* NULL for tables. Points to definition if a view. */
1748317483
FKey *pFKey; /* Linked list of all foreign keys in this table */
1748417484
char *zColAff; /* String defining the affinity of each column */
1748517485
ExprList *pCheck; /* All CHECK constraints */
1748617486
/* ... also used as column name list in a VIEW */
17487
- int tnum; /* Root BTree page for this table */
17487
+ Pgno tnum; /* Root BTree page for this table */
1748817488
u32 nTabRef; /* Number of pointers to this Table */
1748917489
u32 tabFlags; /* Mask of TF_* values */
1749017490
i16 iPKey; /* If not negative, use aCol[iPKey] as the rowid */
1749117491
i16 nCol; /* Number of columns in this table */
1749217492
i16 nNVCol; /* Number of columns that are not VIRTUAL */
@@ -17775,11 +17775,11 @@
1777517775
Schema *pSchema; /* Schema containing this index */
1777617776
u8 *aSortOrder; /* for each column: True==DESC, False==ASC */
1777717777
const char **azColl; /* Array of collation sequence names for index */
1777817778
Expr *pPartIdxWhere; /* WHERE clause for partial indices */
1777917779
ExprList *aColExpr; /* Column expressions */
17780
- int tnum; /* DB Page containing root of this index */
17780
+ Pgno tnum; /* DB Page containing root of this index */
1778117781
LogEst szIdxRow; /* Estimated average row size in bytes */
1778217782
u16 nKeyCol; /* Number of columns forming the key */
1778317783
u16 nColumn; /* Number of columns stored in the index */
1778417784
u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
1778517785
unsigned idxType:2; /* 0:Normal 1:UNIQUE, 2:PRIMARY KEY, 3:IPK */
@@ -18990,10 +18990,11 @@
1899018990
char **pzErrMsg; /* Error message stored here */
1899118991
int iDb; /* 0 for main database. 1 for TEMP, 2.. for ATTACHed */
1899218992
int rc; /* Result code stored here */
1899318993
u32 mInitFlags; /* Flags controlling error messages */
1899418994
u32 nInitRow; /* Number of rows processed */
18995
+ Pgno mxPage; /* Maximum page number. 0 for no limit. */
1899518996
} InitData;
1899618997
1899718998
/*
1899818999
** Allowed values for mInitFlags
1899919000
*/
@@ -19823,12 +19824,14 @@
1982319824
SQLITE_PRIVATE int sqlite3FixSelect(DbFixer*, Select*);
1982419825
SQLITE_PRIVATE int sqlite3FixExpr(DbFixer*, Expr*);
1982519826
SQLITE_PRIVATE int sqlite3FixExprList(DbFixer*, ExprList*);
1982619827
SQLITE_PRIVATE int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
1982719828
SQLITE_PRIVATE int sqlite3RealSameAsInt(double,sqlite3_int64);
19829
+SQLITE_PRIVATE void sqlite3Int64ToText(i64,char*);
1982819830
SQLITE_PRIVATE int sqlite3AtoF(const char *z, double*, int, u8);
1982919831
SQLITE_PRIVATE int sqlite3GetInt32(const char *, int*);
19832
+SQLITE_PRIVATE int sqlite3GetUInt32(const char*, u32*);
1983019833
SQLITE_PRIVATE int sqlite3Atoi(const char*);
1983119834
#ifndef SQLITE_OMIT_UTF16
1983219835
SQLITE_PRIVATE int sqlite3Utf16ByteLen(const void *pData, int nChar);
1983319836
#endif
1983419837
SQLITE_PRIVATE int sqlite3Utf8CharLen(const char *pData, int nByte);
@@ -19952,11 +19955,11 @@
1995219955
#endif
1995319956
#endif /* SQLITE_AMALGAMATION */
1995419957
#ifdef VDBE_PROFILE
1995519958
SQLITE_PRIVATE sqlite3_uint64 sqlite3NProfileCnt;
1995619959
#endif
19957
-SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3*, int, int, int);
19960
+SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3*, int, Pgno, Pgno);
1995819961
SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*);
1995919962
SQLITE_PRIVATE void sqlite3AlterFunctions(void);
1996019963
SQLITE_PRIVATE void sqlite3AlterRenameTable(Parse*, SrcList*, Token*);
1996119964
SQLITE_PRIVATE void sqlite3AlterRenameColumn(Parse*, SrcList*, Token*, Token*);
1996219965
SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *, int *);
@@ -20066,11 +20069,11 @@
2006620069
#else
2006720070
# define sqlite3CloseExtensions(X)
2006820071
#endif
2006920072
2007020073
#ifndef SQLITE_OMIT_SHARED_CACHE
20071
-SQLITE_PRIVATE void sqlite3TableLock(Parse *, int, int, u8, const char *);
20074
+SQLITE_PRIVATE void sqlite3TableLock(Parse *, int, Pgno, u8, const char *);
2007220075
#else
2007320076
#define sqlite3TableLock(v,w,x,y,z)
2007420077
#endif
2007520078
2007620079
#ifdef SQLITE_TEST
@@ -20788,11 +20791,11 @@
2078820791
Bool useRandomRowid:1; /* Generate new record numbers semi-randomly */
2078920792
Bool isOrdered:1; /* True if the table is not BTREE_UNORDERED */
2079020793
Bool seekHit:1; /* See the OP_SeekHit and OP_IfNoHope opcodes */
2079120794
Btree *pBtx; /* Separate file holding temporary table */
2079220795
i64 seqCount; /* Sequence counter */
20793
- int *aAltMap; /* Mapping from table to index column numbers */
20796
+ u32 *aAltMap; /* Mapping from table to index column numbers */
2079420797
2079520798
/* Cached OP_Column parse information is only valid if cacheStatus matches
2079620799
** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
2079720800
** CACHE_STALE (0) and so setting cacheStatus=CACHE_STALE guarantees that
2079820801
** the cache is out of date. */
@@ -21184,11 +21187,11 @@
2118421187
*/
2118521188
SQLITE_PRIVATE void sqlite3VdbeError(Vdbe*, const char *, ...);
2118621189
SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*);
2118721190
void sqliteVdbePopStack(Vdbe*,int);
2118821191
SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeFinishMoveto(VdbeCursor*);
21189
-SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor**, int*);
21192
+SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor**, u32*);
2119021193
SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor*);
2119121194
SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
2119221195
SQLITE_PRIVATE u8 sqlite3VdbeOneByteSerialTypeLen(u8);
2119321196
SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32);
2119421197
SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
@@ -22816,12 +22819,12 @@
2281622819
break;
2281722820
}
2281822821
case 'm': sqlite3_snprintf(3, &z[j],"%02d",x.M); j+=2; break;
2281922822
case 'M': sqlite3_snprintf(3, &z[j],"%02d",x.m); j+=2; break;
2282022823
case 's': {
22821
- sqlite3_snprintf(30,&z[j],"%lld",
22822
- (i64)(x.iJD/1000 - 21086676*(i64)10000));
22824
+ i64 iS = (i64)(x.iJD/1000 - 21086676*(i64)10000);
22825
+ sqlite3Int64ToText(iS, &z[j]);
2282322826
j += sqlite3Strlen30(&z[j]);
2282422827
break;
2282522828
}
2282622829
case 'S': sqlite3_snprintf(3,&z[j],"%02d",(int)x.s); j+=2; break;
2282722830
case 'w': {
@@ -31770,10 +31773,34 @@
3177031773
#endif /* SQLITE_OMIT_FLOATING_POINT */
3177131774
}
3177231775
#if defined(_MSC_VER)
3177331776
#pragma warning(default : 4756)
3177431777
#endif
31778
+
31779
+/*
31780
+** Render an signed 64-bit integer as text. Store the result in zOut[].
31781
+**
31782
+** The caller must ensure that zOut[] is at least 21 bytes in size.
31783
+*/
31784
+SQLITE_PRIVATE void sqlite3Int64ToText(i64 v, char *zOut){
31785
+ int i;
31786
+ u64 x;
31787
+ char zTemp[22];
31788
+ if( v<0 ){
31789
+ x = (v==SMALLEST_INT64) ? ((u64)1)<<63 : (u64)-v;
31790
+ }else{
31791
+ x = v;
31792
+ }
31793
+ i = sizeof(zTemp)-2;
31794
+ zTemp[sizeof(zTemp)-1] = 0;
31795
+ do{
31796
+ zTemp[i--] = (x%10) + '0';
31797
+ x = x/10;
31798
+ }while( x );
31799
+ if( v<0 ) zTemp[i--] = '-';
31800
+ memcpy(zOut, &zTemp[i+1], sizeof(zTemp)-1-i);
31801
+}
3177531802
3177631803
/*
3177731804
** Compare the 19-character string zNum against the text representation
3177831805
** value 2^63: 9223372036854775808. Return negative, zero, or positive
3177931806
** if zNum is less than, equal to, or greater than the string.
@@ -32011,13 +32038,31 @@
3201132038
** Return a 32-bit integer value extracted from a string. If the
3201232039
** string is not an integer, just return 0.
3201332040
*/
3201432041
SQLITE_PRIVATE int sqlite3Atoi(const char *z){
3201532042
int x = 0;
32016
- if( z ) sqlite3GetInt32(z, &x);
32043
+ sqlite3GetInt32(z, &x);
3201732044
return x;
3201832045
}
32046
+
32047
+/*
32048
+** Try to convert z into an unsigned 32-bit integer. Return true on
32049
+** success and false if there is an error.
32050
+**
32051
+** Only decimal notation is accepted.
32052
+*/
32053
+SQLITE_PRIVATE int sqlite3GetUInt32(const char *z, u32 *pI){
32054
+ u64 v = 0;
32055
+ int i;
32056
+ for(i=0; sqlite3Isdigit(z[i]); i++){
32057
+ v = v*10 + z[i] - '0';
32058
+ if( v>4294967296LL ){ *pI = 0; return 0; }
32059
+ }
32060
+ if( i==0 || z[i]!=0 ){ *pI = 0; return 0; }
32061
+ *pI = (u32)v;
32062
+ return 1;
32063
+}
3201932064
3202032065
/*
3202132066
** The variable-length integer encoding is as follows:
3202232067
**
3202332068
** KEY:
@@ -39188,11 +39233,11 @@
3918839233
}
3918939234
#endif
3919039235
if( rc!=SQLITE_OK ){
3919139236
if( h>=0 ) robust_close(pNew, h, __LINE__);
3919239237
}else{
39193
- pNew->pMethod = pLockingStyle;
39238
+ pId->pMethods = pLockingStyle;
3919439239
OpenCounter(+1);
3919539240
verifyDbFile(pNew);
3919639241
}
3919739242
return rc;
3919839243
}
@@ -46899,11 +46944,11 @@
4689946944
{
4690046945
sqlite3_free(zConverted);
4690146946
}
4690246947
4690346948
sqlite3_free(zTmpname);
46904
- pFile->pMethod = pAppData ? pAppData->pMethod : &winIoMethod;
46949
+ id->pMethods = pAppData ? pAppData->pMethod : &winIoMethod;
4690546950
pFile->pVfs = pVfs;
4690646951
pFile->h = h;
4690746952
if( isReadonly ){
4690846953
pFile->ctrlFlags |= WINFILE_RDONLY;
4690946954
}
@@ -48125,11 +48170,11 @@
4812548170
}
4812648171
memset(p, 0, sizeof(*p));
4812748172
p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE;
4812848173
assert( pOutFlags!=0 ); /* True because flags==SQLITE_OPEN_MAIN_DB */
4812948174
*pOutFlags = flags | SQLITE_OPEN_MEMORY;
48130
- p->base.pMethods = &memdb_io_methods;
48175
+ pFile->pMethods = &memdb_io_methods;
4813148176
p->szMax = sqlite3GlobalConfig.mxMemdbSize;
4813248177
return SQLITE_OK;
4813348178
}
4813448179
4813548180
#if 0 /* Only used to delete rollback journals, super-journals, and WAL
@@ -52442,15 +52487,10 @@
5244252487
# define USEFETCH(x) ((x)->bUseFetch)
5244352488
#else
5244452489
# define USEFETCH(x) 0
5244552490
#endif
5244652491
52447
-/*
52448
-** The maximum legal page number is (2^31 - 1).
52449
-*/
52450
-#define PAGER_MAX_PGNO 2147483647
52451
-
5245252492
/*
5245352493
** The argument to this macro is a file descriptor (type sqlite3_file*).
5245452494
** Return 0 if it is not open, or non-zero (but not 1) if it is.
5245552495
**
5245652496
** This is so that expressions can be written as:
@@ -55419,11 +55459,11 @@
5541955459
** Make no changes if mxPage is zero or negative. And never reduce the
5542055460
** maximum page count below the current size of the database.
5542155461
**
5542255462
** Regardless of mxPage, return the current maximum page count.
5542355463
*/
55424
-SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager *pPager, int mxPage){
55464
+SQLITE_PRIVATE Pgno sqlite3PagerMaxPageCount(Pager *pPager, Pgno mxPage){
5542555465
if( mxPage>0 ){
5542655466
pPager->mxPgno = mxPage;
5542755467
}
5542855468
assert( pPager->eState!=PAGER_OPEN ); /* Called only by OP_MaxPgcnt */
5542955469
/* assert( pPager->mxPgno>=pPager->dbSize ); */
@@ -57146,22 +57186,22 @@
5714657186
5714757187
noContent = (flags & PAGER_GET_NOCONTENT)!=0;
5714857188
if( pPg->pPager && !noContent ){
5714957189
/* In this case the pcache already contains an initialized copy of
5715057190
** the page. Return without further ado. */
57151
- assert( pgno<=PAGER_MAX_PGNO && pgno!=PAGER_MJ_PGNO(pPager) );
57191
+ assert( pgno!=PAGER_MJ_PGNO(pPager) );
5715257192
pPager->aStat[PAGER_STAT_HIT]++;
5715357193
return SQLITE_OK;
5715457194
5715557195
}else{
5715657196
/* The pager cache has created a new page. Its content needs to
5715757197
** be initialized. But first some error checks:
5715857198
**
57159
- ** (1) The maximum page number is 2^31
57199
+ ** (*) obsolete. Was: maximum page number is 2^31
5716057200
** (2) Never try to fetch the locking page
5716157201
*/
57162
- if( pgno>PAGER_MAX_PGNO || pgno==PAGER_MJ_PGNO(pPager) ){
57202
+ if( pgno==PAGER_MJ_PGNO(pPager) ){
5716357203
rc = SQLITE_CORRUPT_BKPT;
5716457204
goto pager_acquire_err;
5716557205
}
5716657206
5716757207
pPg->pPager = pPager;
@@ -59863,11 +59903,11 @@
5986359903
** walIteratorFree() - Free an iterator.
5986459904
**
5986559905
** This functionality is used by the checkpoint code (see walCheckpoint()).
5986659906
*/
5986759907
struct WalIterator {
59868
- int iPrior; /* Last result returned from the iterator */
59908
+ u32 iPrior; /* Last result returned from the iterator */
5986959909
int nSegment; /* Number of entries in aSegment[] */
5987059910
struct WalSegment {
5987159911
int iNext; /* Next slot in aIndex[] not yet returned */
5987259912
ht_slot *aIndex; /* i0, i1, i2... such that aPgno[iN] ascend */
5987359913
u32 *aPgno; /* Array of page numbers. */
@@ -59945,11 +59985,13 @@
5994559985
rc = sqlite3OsShmMap(pWal->pDbFd, iPage, WALINDEX_PGSZ,
5994659986
pWal->writeLock, (void volatile **)&pWal->apWiData[iPage]
5994759987
);
5994859988
assert( pWal->apWiData[iPage]!=0 || rc!=SQLITE_OK || pWal->writeLock==0 );
5994959989
testcase( pWal->apWiData[iPage]==0 && rc==SQLITE_OK );
59950
- if( (rc&0xff)==SQLITE_READONLY ){
59990
+ if( rc==SQLITE_OK ){
59991
+ if( iPage>0 && sqlite3FaultSim(600) ) rc = SQLITE_NOMEM;
59992
+ }else if( (rc&0xff)==SQLITE_READONLY ){
5995159993
pWal->readOnly |= WAL_SHM_RDONLY;
5995259994
if( rc==SQLITE_READONLY ){
5995359995
rc = SQLITE_OK;
5995459996
}
5995559997
}
@@ -60320,10 +60362,11 @@
6032060362
&& (iHash>=1 || iFrame<=HASHTABLE_NPAGE_ONE)
6032160363
&& (iHash<=1 || iFrame>(HASHTABLE_NPAGE_ONE+HASHTABLE_NPAGE))
6032260364
&& (iHash>=2 || iFrame<=HASHTABLE_NPAGE_ONE+HASHTABLE_NPAGE)
6032360365
&& (iHash<=2 || iFrame>(HASHTABLE_NPAGE_ONE+2*HASHTABLE_NPAGE))
6032460366
);
60367
+ assert( iHash>=0 );
6032560368
return iHash;
6032660369
}
6032760370
6032860371
/*
6032960372
** Return the page number associated with frame iFrame in this WAL.
@@ -60516,16 +60559,10 @@
6051660559
assert( WAL_ALL_BUT_WRITE==WAL_WRITE_LOCK+1 );
6051760560
assert( WAL_CKPT_LOCK==WAL_ALL_BUT_WRITE );
6051860561
assert( pWal->writeLock );
6051960562
iLock = WAL_ALL_BUT_WRITE + pWal->ckptLock;
6052060563
rc = walLockExclusive(pWal, iLock, WAL_READ_LOCK(0)-iLock);
60521
- if( rc==SQLITE_OK ){
60522
- rc = walLockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1);
60523
- if( rc!=SQLITE_OK ){
60524
- walUnlockExclusive(pWal, iLock, WAL_READ_LOCK(0)-iLock);
60525
- }
60526
- }
6052760564
if( rc ){
6052860565
return rc;
6052960566
}
6053060567
6053160568
WALTRACE(("WAL%p: recovery begin...\n", pWal));
@@ -60537,19 +60574,20 @@
6053760574
goto recovery_error;
6053860575
}
6053960576
6054060577
if( nSize>WAL_HDRSIZE ){
6054160578
u8 aBuf[WAL_HDRSIZE]; /* Buffer to load WAL header into */
60579
+ u32 *aPrivate = 0; /* Heap copy of *-shm hash being populated */
6054260580
u8 *aFrame = 0; /* Malloc'd buffer to load entire frame */
6054360581
int szFrame; /* Number of bytes in buffer aFrame[] */
6054460582
u8 *aData; /* Pointer to data part of aFrame buffer */
60545
- int iFrame; /* Index of last frame read */
60546
- i64 iOffset; /* Next offset to read from log file */
6054760583
int szPage; /* Page size according to the log */
6054860584
u32 magic; /* Magic value read from WAL header */
6054960585
u32 version; /* Magic value read from WAL header */
6055060586
int isValid; /* True if this frame is valid */
60587
+ u32 iPg; /* Current 32KB wal-index page */
60588
+ u32 iLastFrame; /* Last frame in wal, based on nSize alone */
6055160589
6055260590
/* Read in the WAL header. */
6055360591
rc = sqlite3OsRead(pWal->pWalFd, aBuf, WAL_HDRSIZE, 0);
6055460592
if( rc!=SQLITE_OK ){
6055560593
goto recovery_error;
@@ -60592,42 +60630,59 @@
6059260630
goto finished;
6059360631
}
6059460632
6059560633
/* Malloc a buffer to read frames into. */
6059660634
szFrame = szPage + WAL_FRAME_HDRSIZE;
60597
- aFrame = (u8 *)sqlite3_malloc64(szFrame);
60635
+ aFrame = (u8 *)sqlite3_malloc64(szFrame + WALINDEX_PGSZ);
6059860636
if( !aFrame ){
6059960637
rc = SQLITE_NOMEM_BKPT;
6060060638
goto recovery_error;
6060160639
}
6060260640
aData = &aFrame[WAL_FRAME_HDRSIZE];
60641
+ aPrivate = (u32*)&aData[szPage];
6060360642
6060460643
/* Read all frames from the log file. */
60605
- iFrame = 0;
60606
- for(iOffset=WAL_HDRSIZE; (iOffset+szFrame)<=nSize; iOffset+=szFrame){
60607
- u32 pgno; /* Database page number for frame */
60608
- u32 nTruncate; /* dbsize field from frame header */
60609
-
60610
- /* Read and decode the next log frame. */
60611
- iFrame++;
60612
- rc = sqlite3OsRead(pWal->pWalFd, aFrame, szFrame, iOffset);
60613
- if( rc!=SQLITE_OK ) break;
60614
- isValid = walDecodeFrame(pWal, &pgno, &nTruncate, aData, aFrame);
60615
- if( !isValid ) break;
60616
- rc = walIndexAppend(pWal, iFrame, pgno);
60617
- if( rc!=SQLITE_OK ) break;
60618
-
60619
- /* If nTruncate is non-zero, this is a commit record. */
60620
- if( nTruncate ){
60621
- pWal->hdr.mxFrame = iFrame;
60622
- pWal->hdr.nPage = nTruncate;
60623
- pWal->hdr.szPage = (u16)((szPage&0xff00) | (szPage>>16));
60624
- testcase( szPage<=32768 );
60625
- testcase( szPage>=65536 );
60626
- aFrameCksum[0] = pWal->hdr.aFrameCksum[0];
60627
- aFrameCksum[1] = pWal->hdr.aFrameCksum[1];
60628
- }
60644
+ iLastFrame = (nSize - WAL_HDRSIZE) / szFrame;
60645
+ for(iPg=0; iPg<=(u32)walFramePage(iLastFrame); iPg++){
60646
+ u32 *aShare;
60647
+ u32 iFrame; /* Index of last frame read */
60648
+ u32 iLast = MIN(iLastFrame, HASHTABLE_NPAGE_ONE+iPg*HASHTABLE_NPAGE);
60649
+ u32 iFirst = 1 + (iPg==0?0:HASHTABLE_NPAGE_ONE+(iPg-1)*HASHTABLE_NPAGE);
60650
+ u32 nHdr, nHdr32;
60651
+ rc = walIndexPage(pWal, iPg, (volatile u32**)&aShare);
60652
+ if( rc ) break;
60653
+ pWal->apWiData[iPg] = aPrivate;
60654
+
60655
+ for(iFrame=iFirst; iFrame<=iLast; iFrame++){
60656
+ i64 iOffset = walFrameOffset(iFrame, szPage);
60657
+ u32 pgno; /* Database page number for frame */
60658
+ u32 nTruncate; /* dbsize field from frame header */
60659
+
60660
+ /* Read and decode the next log frame. */
60661
+ rc = sqlite3OsRead(pWal->pWalFd, aFrame, szFrame, iOffset);
60662
+ if( rc!=SQLITE_OK ) break;
60663
+ isValid = walDecodeFrame(pWal, &pgno, &nTruncate, aData, aFrame);
60664
+ if( !isValid ) break;
60665
+ rc = walIndexAppend(pWal, iFrame, pgno);
60666
+ if( NEVER(rc!=SQLITE_OK) ) break;
60667
+
60668
+ /* If nTruncate is non-zero, this is a commit record. */
60669
+ if( nTruncate ){
60670
+ pWal->hdr.mxFrame = iFrame;
60671
+ pWal->hdr.nPage = nTruncate;
60672
+ pWal->hdr.szPage = (u16)((szPage&0xff00) | (szPage>>16));
60673
+ testcase( szPage<=32768 );
60674
+ testcase( szPage>=65536 );
60675
+ aFrameCksum[0] = pWal->hdr.aFrameCksum[0];
60676
+ aFrameCksum[1] = pWal->hdr.aFrameCksum[1];
60677
+ }
60678
+ }
60679
+ pWal->apWiData[iPg] = aShare;
60680
+ nHdr = (iPg==0 ? WALINDEX_HDR_SIZE : 0);
60681
+ nHdr32 = nHdr / sizeof(u32);
60682
+ memcpy(&aShare[nHdr32], &aPrivate[nHdr32], WALINDEX_PGSZ-nHdr);
60683
+ if( iFrame<=iLast ) break;
6062960684
}
6063060685
6063160686
sqlite3_free(aFrame);
6063260687
}
6063360688
@@ -60638,19 +60693,30 @@
6063860693
pWal->hdr.aFrameCksum[0] = aFrameCksum[0];
6063960694
pWal->hdr.aFrameCksum[1] = aFrameCksum[1];
6064060695
walIndexWriteHdr(pWal);
6064160696
6064260697
/* Reset the checkpoint-header. This is safe because this thread is
60643
- ** currently holding locks that exclude all other readers, writers and
60644
- ** checkpointers.
60698
+ ** currently holding locks that exclude all other writers and
60699
+ ** checkpointers. Then set the values of read-mark slots 1 through N.
6064560700
*/
6064660701
pInfo = walCkptInfo(pWal);
6064760702
pInfo->nBackfill = 0;
6064860703
pInfo->nBackfillAttempted = pWal->hdr.mxFrame;
6064960704
pInfo->aReadMark[0] = 0;
60650
- for(i=1; i<WAL_NREADER; i++) pInfo->aReadMark[i] = READMARK_NOT_USED;
60651
- if( pWal->hdr.mxFrame ) pInfo->aReadMark[1] = pWal->hdr.mxFrame;
60705
+ for(i=1; i<WAL_NREADER; i++){
60706
+ rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1);
60707
+ if( rc==SQLITE_OK ){
60708
+ if( i==1 && pWal->hdr.mxFrame ){
60709
+ pInfo->aReadMark[i] = pWal->hdr.mxFrame;
60710
+ }else{
60711
+ pInfo->aReadMark[i] = READMARK_NOT_USED;
60712
+ }
60713
+ walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1);
60714
+ }else if( rc!=SQLITE_BUSY ){
60715
+ goto recovery_error;
60716
+ }
60717
+ }
6065260718
6065360719
/* If more than one frame was recovered from the log file, report an
6065460720
** event via sqlite3_log(). This is to help with identifying performance
6065560721
** problems caused by applications routinely shutting down without
6065660722
** checkpointing the log file.
@@ -60664,11 +60730,10 @@
6066460730
}
6066560731
6066660732
recovery_error:
6066760733
WALTRACE(("WAL%p: recovery %s\n", pWal, rc ? "failed" : "ok"));
6066860734
walUnlockExclusive(pWal, iLock, WAL_READ_LOCK(0)-iLock);
60669
- walUnlockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1);
6067060735
return rc;
6067160736
}
6067260737
6067360738
/*
6067460739
** Close an open wal-index.
@@ -64048,11 +64113,12 @@
6404864113
Pgno nPage; /* Number of pages in the database */
6404964114
int mxErr; /* Stop accumulating errors when this reaches zero */
6405064115
int nErr; /* Number of messages written to zErrMsg so far */
6405164116
int bOomFault; /* A memory allocation error has occurred */
6405264117
const char *zPfx; /* Error message prefix */
64053
- int v1, v2; /* Values for up to two %d fields in zPfx */
64118
+ Pgno v1; /* Value for first %u substitution in zPfx */
64119
+ int v2; /* Value for second %d substitution in zPfx */
6405464120
StrAccum errMsg; /* Accumulate the error message text here */
6405564121
u32 *heap; /* Min-heap used for analyzing cell coverage */
6405664122
sqlite3 *db; /* Database connection running the check */
6405764123
};
6405864124
@@ -66513,16 +66579,15 @@
6651366579
/*
6651466580
** Return the size of the database file in pages. If there is any kind of
6651566581
** error, return ((unsigned int)-1).
6651666582
*/
6651766583
static Pgno btreePagecount(BtShared *pBt){
66518
- assert( (pBt->nPage & 0x80000000)==0 || CORRUPT_DB );
6651966584
return pBt->nPage;
6652066585
}
66521
-SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree *p){
66586
+SQLITE_PRIVATE Pgno sqlite3BtreeLastPage(Btree *p){
6652266587
assert( sqlite3BtreeHoldsMutex(p) );
66523
- return btreePagecount(p->pBt) & 0x7fffffff;
66588
+ return btreePagecount(p->pBt);
6652466589
}
6652566590
6652666591
/*
6652766592
** Get a page from the pager and initialize it.
6652866593
**
@@ -67306,12 +67371,12 @@
6730667371
/*
6730767372
** Set the maximum page count for a database if mxPage is positive.
6730867373
** No changes are made if mxPage is 0 or negative.
6730967374
** Regardless of the value of mxPage, return the maximum page count.
6731067375
*/
67311
-SQLITE_PRIVATE int sqlite3BtreeMaxPageCount(Btree *p, int mxPage){
67312
- int n;
67376
+SQLITE_PRIVATE Pgno sqlite3BtreeMaxPageCount(Btree *p, Pgno mxPage){
67377
+ Pgno n;
6731367378
sqlite3BtreeEnter(p);
6731467379
n = sqlite3PagerMaxPageCount(p->pBt->pPager, mxPage);
6731567380
sqlite3BtreeLeave(p);
6731667381
return n;
6731767382
}
@@ -68746,11 +68811,11 @@
6874668811
** It is assumed that the sqlite3BtreeCursorZero() has been called
6874768812
** on pCur to initialize the memory space prior to invoking this routine.
6874868813
*/
6874968814
static int btreeCursor(
6875068815
Btree *p, /* The btree */
68751
- int iTable, /* Root page of table to open */
68816
+ Pgno iTable, /* Root page of table to open */
6875268817
int wrFlag, /* 1 to write. 0 read-only */
6875368818
struct KeyInfo *pKeyInfo, /* First arg to comparison function */
6875468819
BtCursor *pCur /* Space for new cursor */
6875568820
){
6875668821
BtShared *pBt = p->pBt; /* Shared b-tree handle */
@@ -68789,21 +68854,21 @@
6878968854
}
6879068855
}
6879168856
6879268857
/* Now that no other errors can occur, finish filling in the BtCursor
6879368858
** variables and link the cursor into the BtShared list. */
68794
- pCur->pgnoRoot = (Pgno)iTable;
68859
+ pCur->pgnoRoot = iTable;
6879568860
pCur->iPage = -1;
6879668861
pCur->pKeyInfo = pKeyInfo;
6879768862
pCur->pBtree = p;
6879868863
pCur->pBt = pBt;
6879968864
pCur->curFlags = wrFlag ? BTCF_WriteFlag : 0;
6880068865
pCur->curPagerFlags = wrFlag ? 0 : PAGER_GET_READONLY;
6880168866
/* If there are two or more cursors on the same btree, then all such
6880268867
** cursors *must* have the BTCF_Multiple flag set. */
6880368868
for(pX=pBt->pCursor; pX; pX=pX->pNext){
68804
- if( pX->pgnoRoot==(Pgno)iTable ){
68869
+ if( pX->pgnoRoot==iTable ){
6880568870
pX->curFlags |= BTCF_Multiple;
6880668871
pCur->curFlags |= BTCF_Multiple;
6880768872
}
6880868873
}
6880968874
pCur->pNext = pBt->pCursor;
@@ -68811,11 +68876,11 @@
6881168876
pCur->eState = CURSOR_INVALID;
6881268877
return SQLITE_OK;
6881368878
}
6881468879
static int btreeCursorWithLock(
6881568880
Btree *p, /* The btree */
68816
- int iTable, /* Root page of table to open */
68881
+ Pgno iTable, /* Root page of table to open */
6881768882
int wrFlag, /* 1 to write. 0 read-only */
6881868883
struct KeyInfo *pKeyInfo, /* First arg to comparison function */
6881968884
BtCursor *pCur /* Space for new cursor */
6882068885
){
6882168886
int rc;
@@ -68824,11 +68889,11 @@
6882468889
sqlite3BtreeLeave(p);
6882568890
return rc;
6882668891
}
6882768892
SQLITE_PRIVATE int sqlite3BtreeCursor(
6882868893
Btree *p, /* The btree */
68829
- int iTable, /* Root page of table to open */
68894
+ Pgno iTable, /* Root page of table to open */
6883068895
int wrFlag, /* 1 to write. 0 read-only */
6883168896
struct KeyInfo *pKeyInfo, /* First arg to xCompare() */
6883268897
BtCursor *pCur /* Write new cursor here */
6883368898
){
6883468899
if( p->sharable ){
@@ -69249,10 +69314,11 @@
6924969314
}
6925069315
6925169316
assert( rc==SQLITE_OK && amt>0 );
6925269317
while( nextPage ){
6925369318
/* If required, populate the overflow page-list cache. */
69319
+ if( nextPage > pBt->nPage ) return SQLITE_CORRUPT_BKPT;
6925469320
assert( pCur->aOverflow[iIdx]==0
6925569321
|| pCur->aOverflow[iIdx]==nextPage
6925669322
|| CORRUPT_DB );
6925769323
pCur->aOverflow[iIdx] = nextPage;
6925869324
@@ -70321,11 +70387,11 @@
7032170387
** shows that the page 'nearby' is somewhere on the free-list, then
7032270388
** the entire-list will be searched for that page.
7032370389
*/
7032470390
#ifndef SQLITE_OMIT_AUTOVACUUM
7032570391
if( eMode==BTALLOC_EXACT ){
70326
- if( nearby<=mxPage ){
70392
+ if( ALWAYS(nearby<=mxPage) ){
7032770393
u8 eType;
7032870394
assert( nearby>0 );
7032970395
assert( pBt->autoVacuum );
7033070396
rc = ptrmapGet(pBt, nearby, &eType, 0);
7033170397
if( rc ) return rc;
@@ -70617,11 +70683,11 @@
7061770683
7061870684
assert( sqlite3_mutex_held(pBt->mutex) );
7061970685
assert( CORRUPT_DB || iPage>1 );
7062070686
assert( !pMemPage || pMemPage->pgno==iPage );
7062170687
70622
- if( iPage<2 || iPage>pBt->nPage ){
70688
+ if( iPage<2 || NEVER(iPage>pBt->nPage) ){
7062370689
return SQLITE_CORRUPT_BKPT;
7062470690
}
7062570691
if( pMemPage ){
7062670692
pPage = pMemPage;
7062770693
sqlite3PagerRef(pPage->pDbPage);
@@ -70664,10 +70730,14 @@
7066470730
*/
7066570731
if( nFree!=0 ){
7066670732
u32 nLeaf; /* Initial number of leaf cells on trunk page */
7066770733
7066870734
iTrunk = get4byte(&pPage1->aData[32]);
70735
+ if( iTrunk>btreePagecount(pBt) ){
70736
+ rc = SQLITE_CORRUPT_BKPT;
70737
+ goto freepage_out;
70738
+ }
7066970739
rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0);
7067070740
if( rc!=SQLITE_OK ){
7067170741
goto freepage_out;
7067270742
}
7067370743
@@ -73468,11 +73538,11 @@
7346873538
** flags might not work:
7346973539
**
7347073540
** BTREE_INTKEY|BTREE_LEAFDATA Used for SQL tables with rowid keys
7347173541
** BTREE_ZERODATA Used for SQL indices
7347273542
*/
73473
-static int btreeCreateTable(Btree *p, int *piTable, int createTabFlags){
73543
+static int btreeCreateTable(Btree *p, Pgno *piTable, int createTabFlags){
7347473544
BtShared *pBt = p->pBt;
7347573545
MemPage *pRoot;
7347673546
Pgno pgnoRoot;
7347773547
int rc;
7347873548
int ptfFlags; /* Page-type flage for the root page of new table */
@@ -73501,21 +73571,23 @@
7350173571
/* Read the value of meta[3] from the database to determine where the
7350273572
** root page of the new table should go. meta[3] is the largest root-page
7350373573
** created so far, so the new root-page is (meta[3]+1).
7350473574
*/
7350573575
sqlite3BtreeGetMeta(p, BTREE_LARGEST_ROOT_PAGE, &pgnoRoot);
73576
+ if( pgnoRoot>btreePagecount(pBt) ){
73577
+ return SQLITE_CORRUPT_BKPT;
73578
+ }
7350673579
pgnoRoot++;
7350773580
7350873581
/* The new root-page may not be allocated on a pointer-map page, or the
7350973582
** PENDING_BYTE page.
7351073583
*/
7351173584
while( pgnoRoot==PTRMAP_PAGENO(pBt, pgnoRoot) ||
7351273585
pgnoRoot==PENDING_BYTE_PAGE(pBt) ){
7351373586
pgnoRoot++;
7351473587
}
73515
- assert( pgnoRoot>=3 || CORRUPT_DB );
73516
- testcase( pgnoRoot<3 );
73588
+ assert( pgnoRoot>=3 );
7351773589
7351873590
/* Allocate a page. The page that currently resides at pgnoRoot will
7351973591
** be moved to the allocated page (unless the allocated page happens
7352073592
** to reside at pgnoRoot).
7352173593
*/
@@ -73608,14 +73680,14 @@
7360873680
ptfFlags = PTF_ZERODATA | PTF_LEAF;
7360973681
}
7361073682
zeroPage(pRoot, ptfFlags);
7361173683
sqlite3PagerUnref(pRoot->pDbPage);
7361273684
assert( (pBt->openFlags & BTREE_SINGLE)==0 || pgnoRoot==2 );
73613
- *piTable = (int)pgnoRoot;
73685
+ *piTable = pgnoRoot;
7361473686
return SQLITE_OK;
7361573687
}
73616
-SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree *p, int *piTable, int flags){
73688
+SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree *p, Pgno *piTable, int flags){
7361773689
int rc;
7361873690
sqlite3BtreeEnter(p);
7361973691
rc = btreeCreateTable(p, piTable, flags);
7362073692
sqlite3BtreeLeave(p);
7362173693
return rc;
@@ -74095,11 +74167,11 @@
7409574167
** Verify that the number of pages on the list is N.
7409674168
*/
7409774169
static void checkList(
7409874170
IntegrityCk *pCheck, /* Integrity checking context */
7409974171
int isFreeList, /* True for a freelist. False for overflow page list */
74100
- int iPage, /* Page number for first page in the list */
74172
+ Pgno iPage, /* Page number for first page in the list */
7410174173
u32 N /* Expected number of pages in the list */
7410274174
){
7410374175
int i;
7410474176
u32 expected = N;
7410574177
int nErrAtStart = pCheck->nErr;
@@ -74227,11 +74299,11 @@
7422774299
** 4. Recursively call checkTreePage on all children.
7422874300
** 5. Verify that the depth of all children is the same.
7422974301
*/
7423074302
static int checkTreePage(
7423174303
IntegrityCk *pCheck, /* Context for the sanity check */
74232
- int iPage, /* Page number of the page to check */
74304
+ Pgno iPage, /* Page number of the page to check */
7423374305
i64 *piMinKey, /* Write minimum integer primary key here */
7423474306
i64 maxKey /* Error if integer primary key greater than this */
7423574307
){
7423674308
MemPage *pPage = 0; /* The page being analyzed */
7423774309
int i; /* Loop counter */
@@ -74263,13 +74335,13 @@
7426374335
*/
7426474336
pBt = pCheck->pBt;
7426574337
usableSize = pBt->usableSize;
7426674338
if( iPage==0 ) return 0;
7426774339
if( checkRef(pCheck, iPage) ) return 0;
74268
- pCheck->zPfx = "Page %d: ";
74340
+ pCheck->zPfx = "Page %u: ";
7426974341
pCheck->v1 = iPage;
74270
- if( (rc = btreeGetPage(pBt, (Pgno)iPage, &pPage, 0))!=0 ){
74342
+ if( (rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0 ){
7427174343
checkAppendMsg(pCheck,
7427274344
"unable to get the page. error code=%d", rc);
7427374345
goto end_of_check;
7427474346
}
7427574347
@@ -74290,11 +74362,11 @@
7429074362
}
7429174363
data = pPage->aData;
7429274364
hdr = pPage->hdrOffset;
7429374365
7429474366
/* Set up for cell analysis */
74295
- pCheck->zPfx = "On tree page %d cell %d: ";
74367
+ pCheck->zPfx = "On tree page %u cell %d: ";
7429674368
contentOffset = get2byteNotZero(&data[hdr+5]);
7429774369
assert( contentOffset<=usableSize ); /* Enforced by btreeInitPage() */
7429874370
7429974371
/* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
7430074372
** number of cells on the page. */
@@ -74310,11 +74382,11 @@
7431074382
if( !pPage->leaf ){
7431174383
/* Analyze the right-child page of internal pages */
7431274384
pgno = get4byte(&data[hdr+8]);
7431374385
#ifndef SQLITE_OMIT_AUTOVACUUM
7431474386
if( pBt->autoVacuum ){
74315
- pCheck->zPfx = "On page %d at right child: ";
74387
+ pCheck->zPfx = "On page %u at right child: ";
7431674388
checkPtrmap(pCheck, pgno, PTRMAP_BTREE, iPage);
7431774389
}
7431874390
#endif
7431974391
depth = checkTreePage(pCheck, pgno, &maxKey, maxKey);
7432074392
keyCanBeEqual = 0;
@@ -74451,11 +74523,11 @@
7445174523
nFrag = 0;
7445274524
prev = contentOffset - 1; /* Implied first min-heap entry */
7445374525
while( btreeHeapPull(heap,&x) ){
7445474526
if( (prev&0xffff)>=(x>>16) ){
7445574527
checkAppendMsg(pCheck,
74456
- "Multiple uses for byte %u of page %d", x>>16, iPage);
74528
+ "Multiple uses for byte %u of page %u", x>>16, iPage);
7445774529
break;
7445874530
}else{
7445974531
nFrag += (x>>16) - (prev&0xffff) - 1;
7446074532
prev = x;
7446174533
}
@@ -74466,11 +74538,11 @@
7446674538
** EVIDENCE-OF: R-07161-27322 The one-byte integer at offset 7 gives the
7446774539
** number of fragmented free bytes within the cell content area.
7446874540
*/
7446974541
if( heap[0]==0 && nFrag!=data[hdr+7] ){
7447074542
checkAppendMsg(pCheck,
74471
- "Fragmentation of %d bytes reported as %d on page %d",
74543
+ "Fragmentation of %d bytes reported as %d on page %u",
7447274544
nFrag, data[hdr+7], iPage);
7447374545
}
7447474546
}
7447574547
7447674548
end_of_check:
@@ -74494,25 +74566,44 @@
7449474566
**
7449574567
** Write the number of error seen in *pnErr. Except for some memory
7449674568
** allocation errors, an error message held in memory obtained from
7449774569
** malloc is returned if *pnErr is non-zero. If *pnErr==0 then NULL is
7449874570
** returned. If a memory allocation error occurs, NULL is returned.
74571
+**
74572
+** If the first entry in aRoot[] is 0, that indicates that the list of
74573
+** root pages is incomplete. This is a "partial integrity-check". This
74574
+** happens when performing an integrity check on a single table. The
74575
+** zero is skipped, of course. But in addition, the freelist checks
74576
+** and the checks to make sure every page is referenced are also skipped,
74577
+** since obviously it is not possible to know which pages are covered by
74578
+** the unverified btrees. Except, if aRoot[1] is 1, then the freelist
74579
+** checks are still performed.
7449974580
*/
7450074581
SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(
7450174582
sqlite3 *db, /* Database connection that is running the check */
7450274583
Btree *p, /* The btree to be checked */
74503
- int *aRoot, /* An array of root pages numbers for individual trees */
74584
+ Pgno *aRoot, /* An array of root pages numbers for individual trees */
7450474585
int nRoot, /* Number of entries in aRoot[] */
7450574586
int mxErr, /* Stop reporting errors after this many */
7450674587
int *pnErr /* Write number of errors seen to this variable */
7450774588
){
7450874589
Pgno i;
7450974590
IntegrityCk sCheck;
7451074591
BtShared *pBt = p->pBt;
7451174592
u64 savedDbFlags = pBt->db->flags;
7451274593
char zErr[100];
74594
+ int bPartial = 0; /* True if not checking all btrees */
74595
+ int bCkFreelist = 1; /* True to scan the freelist */
7451374596
VVA_ONLY( int nRef );
74597
+ assert( nRoot>0 );
74598
+
74599
+ /* aRoot[0]==0 means this is a partial check */
74600
+ if( aRoot[0]==0 ){
74601
+ assert( nRoot>1 );
74602
+ bPartial = 1;
74603
+ if( aRoot[1]!=1 ) bCkFreelist = 0;
74604
+ }
7451474605
7451574606
sqlite3BtreeEnter(p);
7451674607
assert( p->inTrans>TRANS_NONE && pBt->inTransaction>TRANS_NONE );
7451774608
VVA_ONLY( nRef = sqlite3PagerRefcount(pBt->pPager) );
7451874609
assert( nRef>=0 );
@@ -74548,67 +74639,73 @@
7454874639
i = PENDING_BYTE_PAGE(pBt);
7454974640
if( i<=sCheck.nPage ) setPageReferenced(&sCheck, i);
7455074641
7455174642
/* Check the integrity of the freelist
7455274643
*/
74553
- sCheck.zPfx = "Main freelist: ";
74554
- checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]),
74555
- get4byte(&pBt->pPage1->aData[36]));
74556
- sCheck.zPfx = 0;
74644
+ if( bCkFreelist ){
74645
+ sCheck.zPfx = "Main freelist: ";
74646
+ checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]),
74647
+ get4byte(&pBt->pPage1->aData[36]));
74648
+ sCheck.zPfx = 0;
74649
+ }
7455774650
7455874651
/* Check all the tables.
7455974652
*/
7456074653
#ifndef SQLITE_OMIT_AUTOVACUUM
74561
- if( pBt->autoVacuum ){
74562
- int mx = 0;
74563
- int mxInHdr;
74564
- for(i=0; (int)i<nRoot; i++) if( mx<aRoot[i] ) mx = aRoot[i];
74565
- mxInHdr = get4byte(&pBt->pPage1->aData[52]);
74566
- if( mx!=mxInHdr ){
74567
- checkAppendMsg(&sCheck,
74568
- "max rootpage (%d) disagrees with header (%d)",
74569
- mx, mxInHdr
74570
- );
74571
- }
74572
- }else if( get4byte(&pBt->pPage1->aData[64])!=0 ){
74573
- checkAppendMsg(&sCheck,
74574
- "incremental_vacuum enabled with a max rootpage of zero"
74575
- );
74654
+ if( !bPartial ){
74655
+ if( pBt->autoVacuum ){
74656
+ Pgno mx = 0;
74657
+ Pgno mxInHdr;
74658
+ for(i=0; (int)i<nRoot; i++) if( mx<aRoot[i] ) mx = aRoot[i];
74659
+ mxInHdr = get4byte(&pBt->pPage1->aData[52]);
74660
+ if( mx!=mxInHdr ){
74661
+ checkAppendMsg(&sCheck,
74662
+ "max rootpage (%d) disagrees with header (%d)",
74663
+ mx, mxInHdr
74664
+ );
74665
+ }
74666
+ }else if( get4byte(&pBt->pPage1->aData[64])!=0 ){
74667
+ checkAppendMsg(&sCheck,
74668
+ "incremental_vacuum enabled with a max rootpage of zero"
74669
+ );
74670
+ }
7457674671
}
7457774672
#endif
7457874673
testcase( pBt->db->flags & SQLITE_CellSizeCk );
7457974674
pBt->db->flags &= ~(u64)SQLITE_CellSizeCk;
7458074675
for(i=0; (int)i<nRoot && sCheck.mxErr; i++){
7458174676
i64 notUsed;
7458274677
if( aRoot[i]==0 ) continue;
7458374678
#ifndef SQLITE_OMIT_AUTOVACUUM
74584
- if( pBt->autoVacuum && aRoot[i]>1 ){
74679
+ if( pBt->autoVacuum && aRoot[i]>1 && !bPartial ){
7458574680
checkPtrmap(&sCheck, aRoot[i], PTRMAP_ROOTPAGE, 0);
7458674681
}
7458774682
#endif
7458874683
checkTreePage(&sCheck, aRoot[i], &notUsed, LARGEST_INT64);
7458974684
}
7459074685
pBt->db->flags = savedDbFlags;
7459174686
7459274687
/* Make sure every page in the file is referenced
7459374688
*/
74594
- for(i=1; i<=sCheck.nPage && sCheck.mxErr; i++){
74689
+ if( !bPartial ){
74690
+ for(i=1; i<=sCheck.nPage && sCheck.mxErr; i++){
7459574691
#ifdef SQLITE_OMIT_AUTOVACUUM
74596
- if( getPageReferenced(&sCheck, i)==0 ){
74597
- checkAppendMsg(&sCheck, "Page %d is never used", i);
74598
- }
74692
+ if( getPageReferenced(&sCheck, i)==0 ){
74693
+ checkAppendMsg(&sCheck, "Page %d is never used", i);
74694
+ }
7459974695
#else
74600
- /* If the database supports auto-vacuum, make sure no tables contain
74601
- ** references to pointer-map pages.
74602
- */
74603
- if( getPageReferenced(&sCheck, i)==0 &&
74604
- (PTRMAP_PAGENO(pBt, i)!=i || !pBt->autoVacuum) ){
74605
- checkAppendMsg(&sCheck, "Page %d is never used", i);
74606
- }
74607
- if( getPageReferenced(&sCheck, i)!=0 &&
74608
- (PTRMAP_PAGENO(pBt, i)==i && pBt->autoVacuum) ){
74609
- checkAppendMsg(&sCheck, "Pointer map page %d is referenced", i);
74696
+ /* If the database supports auto-vacuum, make sure no tables contain
74697
+ ** references to pointer-map pages.
74698
+ */
74699
+ if( getPageReferenced(&sCheck, i)==0 &&
74700
+ (PTRMAP_PAGENO(pBt, i)!=i || !pBt->autoVacuum) ){
74701
+ checkAppendMsg(&sCheck, "Page %d is never used", i);
74702
+ }
74703
+ if( getPageReferenced(&sCheck, i)!=0 &&
74704
+ (PTRMAP_PAGENO(pBt, i)==i && pBt->autoVacuum) ){
74705
+ checkAppendMsg(&sCheck, "Pointer map page %d is referenced", i);
74706
+ }
7461074707
}
7461174708
#endif
7461274709
}
7461374710
7461474711
/* Clean up and report errors.
@@ -75794,20 +75891,29 @@
7579475891
** into a buffer.
7579575892
*/
7579675893
static void vdbeMemRenderNum(int sz, char *zBuf, Mem *p){
7579775894
StrAccum acc;
7579875895
assert( p->flags & (MEM_Int|MEM_Real|MEM_IntReal) );
75799
- sqlite3StrAccumInit(&acc, 0, zBuf, sz, 0);
75896
+ assert( sz>22 );
7580075897
if( p->flags & MEM_Int ){
75801
- sqlite3_str_appendf(&acc, "%lld", p->u.i);
75802
- }else if( p->flags & MEM_IntReal ){
75803
- sqlite3_str_appendf(&acc, "%!.15g", (double)p->u.i);
75898
+#if GCC_VERSION>=7000000
75899
+ /* Work-around for GCC bug
75900
+ ** https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96270 */
75901
+ i64 x;
75902
+ assert( (p->flags&MEM_Int)*2==sizeof(x) );
75903
+ memcpy(&x, (char*)&p->u, (p->flags&MEM_Int)*2);
75904
+ sqlite3Int64ToText(x, zBuf);
75905
+#else
75906
+ sqlite3Int64ToText(p->u.i, zBuf);
75907
+#endif
7580475908
}else{
75805
- sqlite3_str_appendf(&acc, "%!.15g", p->u.r);
75909
+ sqlite3StrAccumInit(&acc, 0, zBuf, sz, 0);
75910
+ sqlite3_str_appendf(&acc, "%!.15g",
75911
+ (p->flags & MEM_IntReal)!=0 ? (double)p->u.i : p->u.r);
75912
+ assert( acc.zText==zBuf && acc.mxAlloc<=0 );
75913
+ zBuf[acc.nChar] = 0; /* Fast version of sqlite3StrAccumFinish(&acc) */
7580675914
}
75807
- assert( acc.zText==zBuf && acc.mxAlloc<=0 );
75808
- zBuf[acc.nChar] = 0; /* Fast version of sqlite3StrAccumFinish(&acc) */
7580975915
}
7581075916
7581175917
#ifdef SQLITE_DEBUG
7581275918
/*
7581375919
** Validity checks on pMem. pMem holds a string.
@@ -79301,16 +79407,16 @@
7930179407
sqlite3_str_appendf(&x, "vtab:%p", pVtab);
7930279408
break;
7930379409
}
7930479410
#endif
7930579411
case P4_INTARRAY: {
79306
- int i;
79307
- int *ai = pOp->p4.ai;
79308
- int n = ai[0]; /* The first element of an INTARRAY is always the
79412
+ u32 i;
79413
+ u32 *ai = pOp->p4.ai;
79414
+ u32 n = ai[0]; /* The first element of an INTARRAY is always the
7930979415
** count of the number of elements to follow */
7931079416
for(i=1; i<=n; i++){
79311
- sqlite3_str_appendf(&x, "%c%d", (i==1 ? '[' : ','), ai[i]);
79417
+ sqlite3_str_appendf(&x, "%c%u", (i==1 ? '[' : ','), ai[i]);
7931279418
}
7931379419
sqlite3_str_append(&x, "]", 1);
7931479420
break;
7931579421
}
7931679422
case P4_SUBPROGRAM: {
@@ -81150,15 +81256,15 @@
8115081256
** a NULL row.
8115181257
**
8115281258
** If the cursor is already pointing to the correct row and that row has
8115381259
** not been deleted out from under the cursor, then this routine is a no-op.
8115481260
*/
81155
-SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor **pp, int *piCol){
81261
+SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor **pp, u32 *piCol){
8115681262
VdbeCursor *p = *pp;
8115781263
assert( p->eCurType==CURTYPE_BTREE || p->eCurType==CURTYPE_PSEUDO );
8115881264
if( p->deferredMoveto ){
81159
- int iMap;
81265
+ u32 iMap;
8116081266
if( p->aAltMap && (iMap = p->aAltMap[1+*piCol])>0 && !p->nullRow ){
8116181267
*pp = p->pAltCursor;
8116281268
*piCol = iMap - 1;
8116381269
return SQLITE_OK;
8116481270
}
@@ -87427,14 +87533,14 @@
8742787533
int n;
8742887534
int i;
8742987535
int p1;
8743087536
int p2;
8743187537
const KeyInfo *pKeyInfo;
87432
- int idx;
87538
+ u32 idx;
8743387539
CollSeq *pColl; /* Collating sequence to use on this term */
8743487540
int bRev; /* True for DESCENDING sort order */
87435
- int *aPermute; /* The permutation */
87541
+ u32 *aPermute; /* The permutation */
8743687542
8743787543
if( (pOp->p5 & OPFLAG_PERMUTE)==0 ){
8743887544
aPermute = 0;
8743987545
}else{
8744087546
assert( pOp>aOp );
@@ -87459,11 +87565,11 @@
8745987565
assert( p1>0 && p1+n<=(p->nMem+1 - p->nCursor)+1 );
8746087566
assert( p2>0 && p2+n<=(p->nMem+1 - p->nCursor)+1 );
8746187567
}
8746287568
#endif /* SQLITE_DEBUG */
8746387569
for(i=0; i<n; i++){
87464
- idx = aPermute ? aPermute[i] : i;
87570
+ idx = aPermute ? aPermute[i] : (u32)i;
8746587571
assert( memIsValid(&aMem[p1+idx]) );
8746687572
assert( memIsValid(&aMem[p2+idx]) );
8746787573
REGISTER_TRACE(p1+idx, &aMem[p1+idx]);
8746887574
REGISTER_TRACE(p2+idx, &aMem[p2+idx]);
8746987575
assert( i<pKeyInfo->nKeyField );
@@ -87770,11 +87876,11 @@
8777087876
** the result is guaranteed to only be used as the argument of a length()
8777187877
** or typeof() function, respectively. The loading of large blobs can be
8777287878
** skipped for length() and all content loading can be skipped for typeof().
8777387879
*/
8777487880
case OP_Column: {
87775
- int p2; /* column number to retrieve */
87881
+ u32 p2; /* column number to retrieve */
8777687882
VdbeCursor *pC; /* The VDBE cursor */
8777787883
BtCursor *pCrsr; /* The BTree cursor */
8777887884
u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */
8777987885
int len; /* The length of the serialized data for the column */
8778087886
int i; /* Loop counter */
@@ -87788,11 +87894,11 @@
8778887894
Mem *pReg; /* PseudoTable input register */
8778987895
8779087896
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
8779187897
pC = p->apCsr[pOp->p1];
8779287898
assert( pC!=0 );
87793
- p2 = pOp->p2;
87899
+ p2 = (u32)pOp->p2;
8779487900
8779587901
/* If the cursor cache is stale (meaning it is not currently point at
8779687902
** the correct row) then bring it up-to-date by doing the necessary
8779787903
** B-Tree seek. */
8779887904
rc = sqlite3VdbeCursorMoveto(&pC, &p2);
@@ -87915,11 +88021,11 @@
8791588021
zHdr += sqlite3GetVarint32(zHdr, &t);
8791688022
pC->aType[i] = t;
8791788023
offset64 += sqlite3VdbeSerialTypeLen(t);
8791888024
}
8791988025
aOffset[++i] = (u32)(offset64 & 0xffffffff);
87920
- }while( i<=p2 && zHdr<zEndHdr );
88026
+ }while( (u32)i<=p2 && zHdr<zEndHdr );
8792188027
8792288028
/* The record is corrupt if any of the following are true:
8792388029
** (1) the bytes of the header extend past the declared header size
8792488030
** (2) the entire header was used but not all data was used
8792588031
** (3) the end of the data extends beyond the end of the record.
@@ -88939,11 +89045,11 @@
8893989045
** See also: OP_OpenRead, OP_ReopenIdx
8894089046
*/
8894189047
case OP_ReopenIdx: {
8894289048
int nField;
8894389049
KeyInfo *pKeyInfo;
88944
- int p2;
89050
+ u32 p2;
8894589051
int iDb;
8894689052
int wrFlag;
8894789053
Btree *pX;
8894889054
VdbeCursor *pCur;
8894989055
Db *pDb;
@@ -88970,11 +89076,11 @@
8897089076
goto abort_due_to_error;
8897189077
}
8897289078
8897389079
nField = 0;
8897489080
pKeyInfo = 0;
88975
- p2 = pOp->p2;
89081
+ p2 = (u32)pOp->p2;
8897689082
iDb = pOp->p3;
8897789083
assert( iDb>=0 && iDb<db->nDb );
8897889084
assert( DbMaskTest(p->btreeMask, iDb) );
8897989085
pDb = &db->aDb[iDb];
8898089086
pX = pDb->pBt;
@@ -89142,11 +89248,11 @@
8914289248
** opening it. If a transient table is required, just use the
8914389249
** automatically created table with root-page 1 (an BLOB_INTKEY table).
8914489250
*/
8914589251
if( (pCx->pKeyInfo = pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
8914689252
assert( pOp->p4type==P4_KEYINFO );
89147
- rc = sqlite3BtreeCreateTable(pCx->pBtx, (int*)&pCx->pgnoRoot,
89253
+ rc = sqlite3BtreeCreateTable(pCx->pBtx, &pCx->pgnoRoot,
8914889254
BTREE_BLOBKEY | pOp->p5);
8914989255
if( rc==SQLITE_OK ){
8915089256
assert( pCx->pgnoRoot==SCHEMA_ROOT+1 );
8915189257
assert( pKeyInfo->db==db );
8915289258
assert( pKeyInfo->enc==ENC(db) );
@@ -90406,14 +90512,10 @@
9040690512
** generator) then the fix would be to insert a call to
9040790513
** sqlite3VdbeCursorMoveto().
9040890514
*/
9040990515
assert( pC->deferredMoveto==0 );
9041090516
assert( sqlite3BtreeCursorIsValid(pCrsr) );
90411
-#if 0 /* Not required due to the previous to assert() statements */
90412
- rc = sqlite3VdbeCursorMoveto(pC);
90413
- if( rc!=SQLITE_OK ) goto abort_due_to_error;
90414
-#endif
9041590517
9041690518
n = sqlite3BtreePayloadSize(pCrsr);
9041790519
if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
9041890520
goto too_big;
9041990521
}
@@ -91179,11 +91281,11 @@
9117991281
sqlite3VdbeIncrWriteCounter(p, 0);
9118091282
nChange = 0;
9118191283
assert( p->readOnly==0 );
9118291284
assert( DbMaskTest(p->btreeMask, pOp->p2) );
9118391285
rc = sqlite3BtreeClearTable(
91184
- db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &nChange : 0)
91286
+ db->aDb[pOp->p2].pBt, (u32)pOp->p1, (pOp->p3 ? &nChange : 0)
9118591287
);
9118691288
if( pOp->p3 ){
9118791289
p->nChange += nChange;
9118891290
if( pOp->p3>0 ){
9118991291
assert( memIsValid(&aMem[pOp->p3]) );
@@ -91228,11 +91330,11 @@
9122891330
** P1>1. The P3 argument must be 1 (BTREE_INTKEY) for a rowid table
9122991331
** it must be 2 (BTREE_BLOBKEY) for an index or WITHOUT ROWID table.
9123091332
** The root page number of the new b-tree is stored in register P2.
9123191333
*/
9123291334
case OP_CreateBtree: { /* out2 */
91233
- int pgno;
91335
+ Pgno pgno;
9123491336
Db *pDb;
9123591337
9123691338
sqlite3VdbeIncrWriteCounter(p, 0);
9123791339
pOut = out2Prerelease(p, pOp);
9123891340
pgno = 0;
@@ -91303,10 +91405,11 @@
9130391405
zSchema = DFLT_SCHEMA_TABLE;
9130491406
initData.db = db;
9130591407
initData.iDb = iDb;
9130691408
initData.pzErrMsg = &p->zErrMsg;
9130791409
initData.mInitFlags = 0;
91410
+ initData.mxPage = sqlite3BtreeLastPage(db->aDb[iDb].pBt);
9130891411
zSql = sqlite3MPrintf(db,
9130991412
"SELECT*FROM\"%w\".%s WHERE %s ORDER BY rowid",
9131091413
db->aDb[iDb].zDbSName, zSchema, pOp->p4.z);
9131191414
if( zSql==0 ){
9131291415
rc = SQLITE_NOMEM_BKPT;
@@ -91416,11 +91519,11 @@
9141691519
**
9141791520
** This opcode is used to implement the integrity_check pragma.
9141891521
*/
9141991522
case OP_IntegrityCk: {
9142091523
int nRoot; /* Number of tables to check. (Number of root pages.) */
91421
- int *aRoot; /* Array of rootpage numbers for tables to be checked */
91524
+ Pgno *aRoot; /* Array of rootpage numbers for tables to be checked */
9142291525
int nErr; /* Number of errors reported */
9142391526
char *z; /* Text of the error report */
9142491527
Mem *pnErr; /* Register keeping track of errors remaining */
9142591528
9142691529
assert( p->bIsReader );
@@ -96701,11 +96804,11 @@
9670196804
}else{
9670296805
if( i<=2 && pCur->zType==0 ){
9670396806
Schema *pSchema;
9670496807
HashElem *k;
9670596808
int iDb = pOp->p3;
96706
- int iRoot = pOp->p2;
96809
+ Pgno iRoot = (Pgno)pOp->p2;
9670796810
sqlite3 *db = pVTab->db;
9670896811
pSchema = db->aDb[iDb].pSchema;
9670996812
pCur->zSchema = db->aDb[iDb].zDbSName;
9671096813
for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){
9671196814
Table *pTab = (Table*)sqliteHashData(k);
@@ -97288,11 +97391,11 @@
9728897391
}else{
9728997392
p->nChunkSize = 8 + MEMJOURNAL_DFLT_FILECHUNKSIZE - sizeof(FileChunk);
9729097393
assert( MEMJOURNAL_DFLT_FILECHUNKSIZE==fileChunkSize(p->nChunkSize) );
9729197394
}
9729297395
97293
- p->pMethod = (const sqlite3_io_methods*)&MemJournalMethods;
97396
+ pJfd->pMethods = (const sqlite3_io_methods*)&MemJournalMethods;
9729497397
p->nSpill = nSpill;
9729597398
p->flags = flags;
9729697399
p->zJournal = zName;
9729797400
p->pVfs = pVfs;
9729897401
return SQLITE_OK;
@@ -97314,11 +97417,11 @@
9731497417
** file has not yet been created, create it now.
9731597418
*/
9731697419
SQLITE_PRIVATE int sqlite3JournalCreate(sqlite3_file *pJfd){
9731797420
int rc = SQLITE_OK;
9731897421
MemJournal *p = (MemJournal*)pJfd;
97319
- if( p->pMethod==&MemJournalMethods && (
97422
+ if( pJfd->pMethods==&MemJournalMethods && (
9732097423
#ifdef SQLITE_ENABLE_ATOMIC_WRITE
9732197424
p->nSpill>0
9732297425
#else
9732397426
/* While this appears to not be possible without ATOMIC_WRITE, the
9732497427
** paths are complex, so it seems prudent to leave the test in as
@@ -107581,11 +107684,11 @@
107581107684
};
107582107685
int i;
107583107686
sqlite3 *db = pParse->db;
107584107687
Db *pDb;
107585107688
Vdbe *v = sqlite3GetVdbe(pParse);
107586
- int aRoot[ArraySize(aTable)];
107689
+ u32 aRoot[ArraySize(aTable)];
107587107690
u8 aCreateTbl[ArraySize(aTable)];
107588107691
#ifdef SQLITE_ENABLE_STAT4
107589107692
const int nToOpen = OptimizationEnabled(db,SQLITE_Stat4) ? 2 : 1;
107590107693
#else
107591107694
const int nToOpen = 1;
@@ -107610,11 +107713,11 @@
107610107713
** of the new table in register pParse->regRoot. This is important
107611107714
** because the OpenWrite opcode below will be needing it. */
107612107715
sqlite3NestedParse(pParse,
107613107716
"CREATE TABLE %Q.%s(%s)", pDb->zDbSName, zTab, aTable[i].zCols
107614107717
);
107615
- aRoot[i] = pParse->regRoot;
107718
+ aRoot[i] = (u32)pParse->regRoot;
107616107719
aCreateTbl[i] = OPFLAG_P2ISREG;
107617107720
}
107618107721
}else{
107619107722
/* The table already exists. If zWhere is not NULL, delete all entries
107620107723
** associated with the table zWhere. If zWhere is NULL, delete the
@@ -107630,19 +107733,19 @@
107630107733
}else if( db->xPreUpdateCallback ){
107631107734
sqlite3NestedParse(pParse, "DELETE FROM %Q.%s", pDb->zDbSName, zTab);
107632107735
#endif
107633107736
}else{
107634107737
/* The sqlite_stat[134] table already exists. Delete all rows. */
107635
- sqlite3VdbeAddOp2(v, OP_Clear, aRoot[i], iDb);
107738
+ sqlite3VdbeAddOp2(v, OP_Clear, (int)aRoot[i], iDb);
107636107739
}
107637107740
}
107638107741
}
107639107742
107640107743
/* Open the sqlite_stat[134] tables for writing. */
107641107744
for(i=0; i<nToOpen; i++){
107642107745
assert( i<ArraySize(aTable) );
107643
- sqlite3VdbeAddOp4Int(v, OP_OpenWrite, iStatCur+i, aRoot[i], iDb, 3);
107746
+ sqlite3VdbeAddOp4Int(v, OP_OpenWrite, iStatCur+i, (int)aRoot[i], iDb, 3);
107644107747
sqlite3VdbeChangeP5(v, aCreateTbl[i]);
107645107748
VdbeComment((v, aTable[i].zName));
107646107749
}
107647107750
}
107648107751
@@ -110271,11 +110374,11 @@
110271110374
** The TableLock structure is only used by the sqlite3TableLock() and
110272110375
** codeTableLocks() functions.
110273110376
*/
110274110377
struct TableLock {
110275110378
int iDb; /* The database containing the table to be locked */
110276
- int iTab; /* The root page of the table to be locked */
110379
+ Pgno iTab; /* The root page of the table to be locked */
110277110380
u8 isWriteLock; /* True for write lock. False for a read lock */
110278110381
const char *zLockName; /* Name of the table */
110279110382
};
110280110383
110281110384
/*
@@ -110289,11 +110392,11 @@
110289110392
** codeTableLocks() which occurs during sqlite3FinishCoding().
110290110393
*/
110291110394
SQLITE_PRIVATE void sqlite3TableLock(
110292110395
Parse *pParse, /* Parsing context */
110293110396
int iDb, /* Index of the database containing the table to lock */
110294
- int iTab, /* Root page number of the table to be locked */
110397
+ Pgno iTab, /* Root page number of the table to be locked */
110295110398
u8 isWriteLock, /* True for a write lock */
110296110399
const char *zName /* Name of the table to be locked */
110297110400
){
110298110401
Parse *pToplevel = sqlite3ParseToplevel(pParse);
110299110402
int i;
@@ -111128,23 +111231,24 @@
111128111231
const char *zName, /* Name of the object to check */
111129111232
const char *zType, /* Type of this object */
111130111233
const char *zTblName /* Parent table name for triggers and indexes */
111131111234
){
111132111235
sqlite3 *db = pParse->db;
111133
- if( sqlite3WritableSchema(db) || db->init.imposterTable ){
111236
+ if( sqlite3WritableSchema(db)
111237
+ || db->init.imposterTable
111238
+ || !sqlite3Config.bExtraSchemaChecks
111239
+ ){
111134111240
/* Skip these error checks for writable_schema=ON */
111135111241
return SQLITE_OK;
111136111242
}
111137111243
if( db->init.busy ){
111138111244
if( sqlite3_stricmp(zType, db->init.azInit[0])
111139111245
|| sqlite3_stricmp(zName, db->init.azInit[1])
111140111246
|| sqlite3_stricmp(zTblName, db->init.azInit[2])
111141111247
){
111142
- if( sqlite3Config.bExtraSchemaChecks ){
111143
- sqlite3ErrorMsg(pParse, ""); /* corruptSchema() will supply the error */
111144
- return SQLITE_ERROR;
111145
- }
111248
+ sqlite3ErrorMsg(pParse, ""); /* corruptSchema() will supply the error */
111249
+ return SQLITE_ERROR;
111146111250
}
111147111251
}else{
111148111252
if( (pParse->nested==0 && 0==sqlite3StrNICmp(zName, "sqlite_", 7))
111149111253
|| (sqlite3ReadOnlyShadowTables(db) && sqlite3ShadowTableName(db, zName))
111150111254
){
@@ -112354,11 +112458,11 @@
112354112458
** table entry. This is only required if currently generating VDBE
112355112459
** code for a CREATE TABLE (not when parsing one as part of reading
112356112460
** a database schema). */
112357112461
if( v && pPk->tnum>0 ){
112358112462
assert( db->init.busy==0 );
112359
- sqlite3VdbeChangeOpcode(v, pPk->tnum, OP_Goto);
112463
+ sqlite3VdbeChangeOpcode(v, (int)pPk->tnum, OP_Goto);
112360112464
}
112361112465
112362112466
/* The root page of the PRIMARY KEY is the table root page */
112363112467
pPk->tnum = pTab->tnum;
112364112468
@@ -113050,11 +113154,11 @@
113050113154
** We must continue looping until all tables and indices with
113051113155
** rootpage==iFrom have been converted to have a rootpage of iTo
113052113156
** in order to be certain that we got the right one.
113053113157
*/
113054113158
#ifndef SQLITE_OMIT_AUTOVACUUM
113055
-SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3 *db, int iDb, int iFrom, int iTo){
113159
+SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3 *db, int iDb, Pgno iFrom, Pgno iTo){
113056113160
HashElem *pElem;
113057113161
Hash *pHash;
113058113162
Db *pDb;
113059113163
113060113164
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
@@ -113083,11 +113187,11 @@
113083113187
** erasing iTable (this can happen with an auto-vacuum database).
113084113188
*/
113085113189
static void destroyRootPage(Parse *pParse, int iTable, int iDb){
113086113190
Vdbe *v = sqlite3GetVdbe(pParse);
113087113191
int r1 = sqlite3GetTempReg(pParse);
113088
- if( iTable<2 ) sqlite3ErrorMsg(pParse, "corrupt schema");
113192
+ if( NEVER(iTable<2) ) return;
113089113193
sqlite3VdbeAddOp3(v, OP_Destroy, iTable, r1, iDb);
113090113194
sqlite3MayAbort(pParse);
113091113195
#ifndef SQLITE_OMIT_AUTOVACUUM
113092113196
/* OP_Destroy stores an in integer r1. If this integer
113093113197
** is non-zero, then it is the root page number of a table moved to
@@ -113127,22 +113231,22 @@
113127113231
** and root page 5 happened to be the largest root-page number in the
113128113232
** database, then root page 5 would be moved to page 4 by the
113129113233
** "OP_Destroy 4 0" opcode. The subsequent "OP_Destroy 5 0" would hit
113130113234
** a free-list page.
113131113235
*/
113132
- int iTab = pTab->tnum;
113133
- int iDestroyed = 0;
113236
+ Pgno iTab = pTab->tnum;
113237
+ Pgno iDestroyed = 0;
113134113238
113135113239
while( 1 ){
113136113240
Index *pIdx;
113137
- int iLargest = 0;
113241
+ Pgno iLargest = 0;
113138113242
113139113243
if( iDestroyed==0 || iTab<iDestroyed ){
113140113244
iLargest = iTab;
113141113245
}
113142113246
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
113143
- int iIdx = pIdx->tnum;
113247
+ Pgno iIdx = pIdx->tnum;
113144113248
assert( pIdx->pSchema==pTab->pSchema );
113145113249
if( (iDestroyed==0 || (iIdx<iDestroyed)) && iIdx>iLargest ){
113146113250
iLargest = iIdx;
113147113251
}
113148113252
}
@@ -113561,11 +113665,11 @@
113561113665
int iTab = pParse->nTab++; /* Btree cursor used for pTab */
113562113666
int iIdx = pParse->nTab++; /* Btree cursor used for pIndex */
113563113667
int iSorter; /* Cursor opened by OpenSorter (if in use) */
113564113668
int addr1; /* Address of top of loop */
113565113669
int addr2; /* Address to jump to for next iteration */
113566
- int tnum; /* Root page of index */
113670
+ Pgno tnum; /* Root page of index */
113567113671
int iPartIdxLabel; /* Jump to this label to skip a row */
113568113672
Vdbe *v; /* Generate code into this virtual machine */
113569113673
KeyInfo *pKey; /* KeyInfo for index */
113570113674
int regRecord; /* Register holding assembled index record */
113571113675
sqlite3 *db = pParse->db; /* The database connection */
@@ -113582,11 +113686,11 @@
113582113686
sqlite3TableLock(pParse, iDb, pTab->tnum, 1, pTab->zName);
113583113687
113584113688
v = sqlite3GetVdbe(pParse);
113585113689
if( v==0 ) return;
113586113690
if( memRootPage>=0 ){
113587
- tnum = memRootPage;
113691
+ tnum = (Pgno)memRootPage;
113588113692
}else{
113589113693
tnum = pIndex->tnum;
113590113694
}
113591113695
pKey = sqlite3KeyInfoOfIndex(pParse, pIndex);
113592113696
assert( pKey!=0 || db->mallocFailed || pParse->nErr );
@@ -113607,11 +113711,11 @@
113607113711
sqlite3VdbeAddOp2(v, OP_SorterInsert, iSorter, regRecord);
113608113712
sqlite3ResolvePartIdxLabel(pParse, iPartIdxLabel);
113609113713
sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1); VdbeCoverage(v);
113610113714
sqlite3VdbeJumpHere(v, addr1);
113611113715
if( memRootPage<0 ) sqlite3VdbeAddOp2(v, OP_Clear, tnum, iDb);
113612
- sqlite3VdbeAddOp4(v, OP_OpenWrite, iIdx, tnum, iDb,
113716
+ sqlite3VdbeAddOp4(v, OP_OpenWrite, iIdx, (int)tnum, iDb,
113613113717
(char *)pKey, P4_KEYINFO);
113614113718
sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR|((memRootPage>=0)?OPFLAG_P2ISREG:0));
113615113719
113616113720
addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0); VdbeCoverage(v);
113617113721
if( IsUniqueIndex(pIndex) ){
@@ -114216,11 +114320,11 @@
114216114320
** doing so, code a Noop instruction and store its address in
114217114321
** Index.tnum. This is required in case this index is actually a
114218114322
** PRIMARY KEY and the table is actually a WITHOUT ROWID table. In
114219114323
** that case the convertToWithoutRowidTable() routine will replace
114220114324
** the Noop with a Goto to jump over the VDBE code generated below. */
114221
- pIndex->tnum = sqlite3VdbeAddOp0(v, OP_Noop);
114325
+ pIndex->tnum = (Pgno)sqlite3VdbeAddOp0(v, OP_Noop);
114222114326
sqlite3VdbeAddOp3(v, OP_CreateBtree, iDb, iMem, BTREE_BLOBKEY);
114223114327
114224114328
/* Gather the complete text of the CREATE INDEX statement into
114225114329
** the zStmt variable
114226114330
*/
@@ -114258,11 +114362,11 @@
114258114362
sqlite3VdbeAddParseSchemaOp(v, iDb,
114259114363
sqlite3MPrintf(db, "name='%q' AND type='index'", pIndex->zName));
114260114364
sqlite3VdbeAddOp2(v, OP_Expire, 0, 1);
114261114365
}
114262114366
114263
- sqlite3VdbeJumpHere(v, pIndex->tnum);
114367
+ sqlite3VdbeJumpHere(v, (int)pIndex->tnum);
114264114368
}
114265114369
}
114266114370
if( db->init.busy || pTblName==0 ){
114267114371
pIndex->pNext = pTab->pIndex;
114268114372
pTab->pIndex = pIndex;
@@ -120581,11 +120685,11 @@
120581120685
for(i=1; i<iEnd; i++){
120582120686
VdbeOp *pOp = sqlite3VdbeGetOp(v, i);
120583120687
assert( pOp!=0 );
120584120688
if( pOp->opcode==OP_OpenRead && pOp->p3==iDb ){
120585120689
Index *pIndex;
120586
- int tnum = pOp->p2;
120690
+ Pgno tnum = pOp->p2;
120587120691
if( tnum==pTab->tnum ){
120588120692
return 1;
120589120693
}
120590120694
for(pIndex=pTab->pIndex; pIndex; pIndex=pIndex->pNext){
120591120695
if( tnum==pIndex->tnum ){
@@ -126204,17 +126308,23 @@
126204126308
**
126205126309
** Return the number of pages in the specified database.
126206126310
*/
126207126311
case PragTyp_PAGE_COUNT: {
126208126312
int iReg;
126313
+ i64 x = 0;
126209126314
sqlite3CodeVerifySchema(pParse, iDb);
126210126315
iReg = ++pParse->nMem;
126211126316
if( sqlite3Tolower(zLeft[0])=='p' ){
126212126317
sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg);
126213126318
}else{
126214
- sqlite3VdbeAddOp3(v, OP_MaxPgcnt, iDb, iReg,
126215
- sqlite3AbsInt32(sqlite3Atoi(zRight)));
126319
+ if( zRight && sqlite3DecOrHexToI64(zRight,&x)==0 ){
126320
+ if( x<0 ) x = 0;
126321
+ else if( x>0xfffffffe ) x = 0xfffffffe;
126322
+ }else{
126323
+ x = 0;
126324
+ }
126325
+ sqlite3VdbeAddOp3(v, OP_MaxPgcnt, iDb, iReg, (int)x);
126216126326
}
126217126327
sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1);
126218126328
break;
126219126329
}
126220126330
@@ -127113,13 +127223,26 @@
127113127223
**
127114127224
** The "quick_check" is reduced version of
127115127225
** integrity_check designed to detect most database corruption
127116127226
** without the overhead of cross-checking indexes. Quick_check
127117127227
** is linear time wherease integrity_check is O(NlogN).
127228
+ **
127229
+ ** The maximum nubmer of errors is 100 by default. A different default
127230
+ ** can be specified using a numeric parameter N.
127231
+ **
127232
+ ** Or, the parameter N can be the name of a table. In that case, only
127233
+ ** the one table named is verified. The freelist is only verified if
127234
+ ** the named table is "sqlite_schema" (or one of its aliases).
127235
+ **
127236
+ ** All schemas are checked by default. To check just a single
127237
+ ** schema, use the form:
127238
+ **
127239
+ ** PRAGMA schema.integrity_check;
127118127240
*/
127119127241
case PragTyp_INTEGRITY_CHECK: {
127120127242
int i, j, addr, mxErr;
127243
+ Table *pObjTab = 0; /* Check only this one table, if not NULL */
127121127244
127122127245
int isQuick = (sqlite3Tolower(zLeft[0])=='q');
127123127246
127124127247
/* If the PRAGMA command was of the form "PRAGMA <db>.integrity_check",
127125127248
** then iDb is set to the index of the database identified by <db>.
@@ -127138,13 +127261,17 @@
127138127261
pParse->nMem = 6;
127139127262
127140127263
/* Set the maximum error count */
127141127264
mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
127142127265
if( zRight ){
127143
- sqlite3GetInt32(zRight, &mxErr);
127144
- if( mxErr<=0 ){
127145
- mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
127266
+ if( sqlite3GetInt32(zRight, &mxErr) ){
127267
+ if( mxErr<=0 ){
127268
+ mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
127269
+ }
127270
+ }else{
127271
+ pObjTab = sqlite3LocateTable(pParse, 0, zRight,
127272
+ iDb>=0 ? db->aDb[iDb].zDbSName : 0);
127146127273
}
127147127274
}
127148127275
sqlite3VdbeAddOp2(v, OP_Integer, mxErr-1, 1); /* reg[1] holds errors left */
127149127276
127150127277
/* Do an integrity check on each database file */
@@ -127169,19 +127296,25 @@
127169127296
pTbls = &db->aDb[i].pSchema->tblHash;
127170127297
for(cnt=0, x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
127171127298
Table *pTab = sqliteHashData(x); /* Current table */
127172127299
Index *pIdx; /* An index on pTab */
127173127300
int nIdx; /* Number of indexes on pTab */
127301
+ if( pObjTab && pObjTab!=pTab ) continue;
127174127302
if( HasRowid(pTab) ) cnt++;
127175127303
for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){ cnt++; }
127176127304
if( nIdx>mxIdx ) mxIdx = nIdx;
127177127305
}
127306
+ if( cnt==0 ) continue;
127307
+ if( pObjTab ) cnt++;
127178127308
aRoot = sqlite3DbMallocRawNN(db, sizeof(int)*(cnt+1));
127179127309
if( aRoot==0 ) break;
127180
- for(cnt=0, x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
127310
+ cnt = 0;
127311
+ if( pObjTab ) aRoot[++cnt] = 0;
127312
+ for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
127181127313
Table *pTab = sqliteHashData(x);
127182127314
Index *pIdx;
127315
+ if( pObjTab && pObjTab!=pTab ) continue;
127183127316
if( HasRowid(pTab) ) aRoot[++cnt] = pTab->tnum;
127184127317
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
127185127318
aRoot[++cnt] = pIdx->tnum;
127186127319
}
127187127320
}
@@ -127211,10 +127344,11 @@
127211127344
int loopTop;
127212127345
int iDataCur, iIdxCur;
127213127346
int r1 = -1;
127214127347
127215127348
if( pTab->tnum<1 ) continue; /* Skip VIEWs or VIRTUAL TABLEs */
127349
+ if( pObjTab && pObjTab!=pTab ) continue;
127216127350
pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
127217127351
sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0,
127218127352
1, 0, &iDataCur, &iIdxCur);
127219127353
/* reg[7] counts the number of entries in the table.
127220127354
** reg[8+i] counts the number of entries in the i-th index
@@ -128272,11 +128406,17 @@
128272128406
sqlite3_stmt *pStmt;
128273128407
TESTONLY(int rcp); /* Return code from sqlite3_prepare() */
128274128408
128275128409
assert( db->init.busy );
128276128410
db->init.iDb = iDb;
128277
- db->init.newTnum = sqlite3Atoi(argv[3]);
128411
+ if( sqlite3GetUInt32(argv[3], &db->init.newTnum)==0
128412
+ || (db->init.newTnum>pData->mxPage && pData->mxPage>0)
128413
+ ){
128414
+ if( sqlite3Config.bExtraSchemaChecks ){
128415
+ corruptSchema(pData, argv[1], "invalid rootpage");
128416
+ }
128417
+ }
128278128418
db->init.orphanTrigger = 0;
128279128419
db->init.azInit = argv;
128280128420
pStmt = 0;
128281128421
TESTONLY(rcp = ) sqlite3Prepare(db, argv[4], -1, 0, 0, &pStmt, 0);
128282128422
rc = db->errCode;
@@ -128305,16 +128445,21 @@
128305128445
** been created when we processed the CREATE TABLE. All we have
128306128446
** to do here is record the root page number for that index.
128307128447
*/
128308128448
Index *pIndex;
128309128449
pIndex = sqlite3FindIndex(db, argv[1], db->aDb[iDb].zDbSName);
128310
- if( pIndex==0
128311
- || sqlite3GetInt32(argv[3],&pIndex->tnum)==0
128450
+ if( pIndex==0 ){
128451
+ corruptSchema(pData, argv[1], "orphan index");
128452
+ }else
128453
+ if( sqlite3GetUInt32(argv[3],&pIndex->tnum)==0
128312128454
|| pIndex->tnum<2
128455
+ || pIndex->tnum>pData->mxPage
128313128456
|| sqlite3IndexHasDuplicateRootPage(pIndex)
128314128457
){
128315
- corruptSchema(pData, argv[1], pIndex?"invalid rootpage":"orphan index");
128458
+ if( sqlite3Config.bExtraSchemaChecks ){
128459
+ corruptSchema(pData, argv[1], "invalid rootpage");
128460
+ }
128316128461
}
128317128462
}
128318128463
return 0;
128319128464
}
128320128465
@@ -128364,10 +128509,11 @@
128364128509
initData.iDb = iDb;
128365128510
initData.rc = SQLITE_OK;
128366128511
initData.pzErrMsg = pzErrMsg;
128367128512
initData.mInitFlags = mFlags;
128368128513
initData.nInitRow = 0;
128514
+ initData.mxPage = 0;
128369128515
sqlite3InitCallback(&initData, 5, (char **)azArg, 0);
128370128516
db->mDbFlags &= mask;
128371128517
if( initData.rc ){
128372128518
rc = initData.rc;
128373128519
goto error_out;
@@ -128486,10 +128632,11 @@
128486128632
}
128487128633
128488128634
/* Read the schema information out of the schema tables
128489128635
*/
128490128636
assert( db->init.busy );
128637
+ initData.mxPage = sqlite3BtreeLastPage(pDb->pBt);
128491128638
{
128492128639
char *zSql;
128493128640
zSql = sqlite3MPrintf(db,
128494128641
"SELECT*FROM\"%w\".%s ORDER BY rowid",
128495128642
db->aDb[iDb].zDbSName, zSchemaTabName);
@@ -129368,12 +129515,14 @@
129368129515
** Return the index of a column in a table. Return -1 if the column
129369129516
** is not contained in the table.
129370129517
*/
129371129518
static int columnIndex(Table *pTab, const char *zCol){
129372129519
int i;
129373
- for(i=0; i<pTab->nCol; i++){
129374
- if( sqlite3StrICmp(pTab->aCol[i].zName, zCol)==0 ) return i;
129520
+ u8 h = sqlite3StrIHash(zCol);
129521
+ Column *pCol;
129522
+ for(pCol=pTab->aCol, i=0; i<pTab->nCol; pCol++, i++){
129523
+ if( pCol->hName==h && sqlite3StrICmp(pCol->zName, zCol)==0 ) return i;
129375129524
}
129376129525
return -1;
129377129526
}
129378129527
129379129528
/*
@@ -130231,20 +130380,24 @@
130231130380
sqlite3ReleaseTempRange(pParse, r1, nPrefixReg+1);
130232130381
break;
130233130382
}
130234130383
130235130384
case SRT_Upfrom: {
130236
-#ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
130237130385
if( pSort ){
130238130386
pushOntoSorter(
130239130387
pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg);
130240
- }else
130241
-#endif
130242
- {
130388
+ }else{
130243130389
int i2 = pDest->iSDParm2;
130244130390
int r1 = sqlite3GetTempReg(pParse);
130245
- sqlite3VdbeAddOp3(v, OP_MakeRecord,regResult+(i2<0),nResultCol-(i2<0),r1);
130391
+
130392
+ /* If the UPDATE FROM join is an aggregate that matches no rows, it
130393
+ ** might still be trying to return one row, because that is what
130394
+ ** aggregates do. Don't record that empty row in the output table. */
130395
+ sqlite3VdbeAddOp2(v, OP_IsNull, regResult, iBreak); VdbeCoverage(v);
130396
+
130397
+ sqlite3VdbeAddOp3(v, OP_MakeRecord,
130398
+ regResult+(i2<0), nResultCol-(i2<0), r1);
130246130399
if( i2<0 ){
130247130400
sqlite3VdbeAddOp3(v, OP_Insert, iParm, r1, regResult);
130248130401
}else{
130249130402
sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, r1, regResult, i2);
130250130403
}
@@ -130682,11 +130835,10 @@
130682130835
case SRT_Mem: {
130683130836
/* The LIMIT clause will terminate the loop for us */
130684130837
break;
130685130838
}
130686130839
#endif
130687
-#ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
130688130840
case SRT_Upfrom: {
130689130841
int i2 = pDest->iSDParm2;
130690130842
int r1 = sqlite3GetTempReg(pParse);
130691130843
sqlite3VdbeAddOp3(v, OP_MakeRecord,regRow+(i2<0),nColumn-(i2<0),r1);
130692130844
if( i2<0 ){
@@ -130694,11 +130846,10 @@
130694130846
}else{
130695130847
sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, r1, regRow, i2);
130696130848
}
130697130849
break;
130698130850
}
130699
-#endif
130700130851
default: {
130701130852
assert( eDest==SRT_Output || eDest==SRT_Coroutine );
130702130853
testcase( eDest==SRT_Output );
130703130854
testcase( eDest==SRT_Coroutine );
130704130855
if( eDest==SRT_Output ){
@@ -132281,11 +132432,11 @@
132281132432
KeyInfo *pKeyDup = 0; /* Comparison information for duplicate removal */
132282132433
KeyInfo *pKeyMerge; /* Comparison information for merging rows */
132283132434
sqlite3 *db; /* Database connection */
132284132435
ExprList *pOrderBy; /* The ORDER BY clause */
132285132436
int nOrderBy; /* Number of terms in the ORDER BY clause */
132286
- int *aPermute; /* Mapping from ORDER BY terms to result set columns */
132437
+ u32 *aPermute; /* Mapping from ORDER BY terms to result set columns */
132287132438
132288132439
assert( p->pOrderBy!=0 );
132289132440
assert( pKeyDup==0 ); /* "Managed" code needs this. Ticket #3382. */
132290132441
db = pParse->db;
132291132442
v = pParse->pVdbe;
@@ -132330,11 +132481,11 @@
132330132481
** row of results comes from selectA or selectB. Also add explicit
132331132482
** collations to the ORDER BY clause terms so that when the subqueries
132332132483
** to the right and the left are evaluated, they use the correct
132333132484
** collation.
132334132485
*/
132335
- aPermute = sqlite3DbMallocRawNN(db, sizeof(int)*(nOrderBy + 1));
132486
+ aPermute = sqlite3DbMallocRawNN(db, sizeof(u32)*(nOrderBy + 1));
132336132487
if( aPermute ){
132337132488
struct ExprList_item *pItem;
132338132489
aPermute[0] = nOrderBy;
132339132490
for(i=1, pItem=pOrderBy->a; i<=nOrderBy; i++, pItem++){
132340132491
assert( pItem->u.x.iOrderByCol>0 );
@@ -135823,11 +135974,11 @@
135823135974
const int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
135824135975
const int iCsr = pParse->nTab++; /* Cursor to scan b-tree */
135825135976
Index *pIdx; /* Iterator variable */
135826135977
KeyInfo *pKeyInfo = 0; /* Keyinfo for scanned index */
135827135978
Index *pBest = 0; /* Best index found so far */
135828
- int iRoot = pTab->tnum; /* Root page of scanned b-tree */
135979
+ Pgno iRoot = pTab->tnum; /* Root page of scanned b-tree */
135829135980
135830135981
sqlite3CodeVerifySchema(pParse, iDb);
135831135982
sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
135832135983
135833135984
/* Search for the index that has the lowest scan cost.
@@ -135855,11 +136006,11 @@
135855136006
iRoot = pBest->tnum;
135856136007
pKeyInfo = sqlite3KeyInfoOfIndex(pParse, pBest);
135857136008
}
135858136009
135859136010
/* Open a read-only cursor, execute the OP_Count, close the cursor. */
135860
- sqlite3VdbeAddOp4Int(v, OP_OpenRead, iCsr, iRoot, iDb, 1);
136011
+ sqlite3VdbeAddOp4Int(v, OP_OpenRead, iCsr, (int)iRoot, iDb, 1);
135861136012
if( pKeyInfo ){
135862136013
sqlite3VdbeChangeP4(v, -1, (char *)pKeyInfo, P4_KEYINFO);
135863136014
}
135864136015
sqlite3VdbeAddOp2(v, OP_Count, iCsr, pAggInfo->aFunc[0].iMem);
135865136016
sqlite3VdbeAddOp1(v, OP_Close, iCsr);
@@ -142375,11 +142526,11 @@
142375142526
if( (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)
142376142527
&& DbMaskAllZero(sqlite3ParseToplevel(pParse)->writeMask)
142377142528
){
142378142529
int i;
142379142530
Table *pTab = pIdx->pTable;
142380
- int *ai = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*(pTab->nCol+1));
142531
+ u32 *ai = (u32*)sqlite3DbMallocZero(pParse->db, sizeof(u32)*(pTab->nCol+1));
142381142532
if( ai ){
142382142533
ai[0] = pTab->nCol;
142383142534
for(i=0; i<pIdx->nColumn-1; i++){
142384142535
int x1, x2;
142385142536
assert( pIdx->aiColumn[i]<pTab->nCol );
@@ -164889,10 +165040,16 @@
164889165040
/* sqlite3_test_control(SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS, int);
164890165041
**
164891165042
** Set or clear a flag that causes SQLite to verify that type, name,
164892165043
** and tbl_name fields of the sqlite_schema table. This is normally
164893165044
** on, but it is sometimes useful to turn it off for testing.
165045
+ **
165046
+ ** 2020-07-22: Disabling EXTRA_SCHEMA_CHECKS also disables the
165047
+ ** verification of rootpage numbers when parsing the schema. This
165048
+ ** is useful to make it easier to reach strange internal error states
165049
+ ** during testing. The EXTRA_SCHEMA_CHECKS settting is always enabled
165050
+ ** in production.
164894165051
*/
164895165052
case SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS: {
164896165053
sqlite3GlobalConfig.bExtraSchemaChecks = va_arg(ap, int);
164897165054
break;
164898165055
}
@@ -172498,11 +172655,12 @@
172498172655
** do {...} while( pRoot->iDocid<iDocid && rc==SQLITE_OK );
172499172656
*/
172500172657
fts3EvalRestart(pCsr, pRoot, &rc);
172501172658
do {
172502172659
fts3EvalNextRow(pCsr, pRoot, &rc);
172503
- assert( pRoot->bEof==0 );
172660
+ assert_fts3_nc( pRoot->bEof==0 );
172661
+ if( pRoot->bEof ) rc = FTS_CORRUPT_VTAB;
172504172662
}while( pRoot->iDocid!=iDocid && rc==SQLITE_OK );
172505172663
}
172506172664
}
172507172665
return rc;
172508172666
}
@@ -225482,11 +225640,11 @@
225482225640
int nArg, /* Number of args */
225483225641
sqlite3_value **apUnused /* Function arguments */
225484225642
){
225485225643
assert( nArg==0 );
225486225644
UNUSED_PARAM2(nArg, apUnused);
225487
- sqlite3_result_text(pCtx, "fts5: 2020-07-18 18:59:11 020dbfa2aef20e5872cc3e785d99f45903843401292114b5092b9c8aa829b9c3", -1, SQLITE_TRANSIENT);
225645
+ sqlite3_result_text(pCtx, "fts5: 2020-07-30 17:37:49 96e3dba2ed3ab0c5b2ecf65a3408633e0767c884d48c270e9ef10ab9fa3ec051", -1, SQLITE_TRANSIENT);
225488225646
}
225489225647
225490225648
/*
225491225649
** Return true if zName is the extension on one of the shadow tables used
225492225650
** by this module.
@@ -230265,12 +230423,12 @@
230265230423
}
230266230424
#endif /* SQLITE_CORE */
230267230425
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
230268230426
230269230427
/************** End of stmt.c ************************************************/
230270
-#if __LINE__!=230270
230428
+#if __LINE__!=230428
230271230429
#undef SQLITE_SOURCE_ID
230272
-#define SQLITE_SOURCE_ID "2020-07-18 18:59:11 020dbfa2aef20e5872cc3e785d99f45903843401292114b5092b9c8aa829alt2"
230430
+#define SQLITE_SOURCE_ID "2020-07-30 17:37:49 96e3dba2ed3ab0c5b2ecf65a3408633e0767c884d48c270e9ef10ab9fa3ealt2"
230273230431
#endif
230274230432
/* Return the source-id for this library */
230275230433
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
230276230434
/************************** End of sqlite3.c ******************************/
230277230435
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1162,11 +1162,11 @@
1162 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1163 ** [sqlite_version()] and [sqlite_source_id()].
1164 */
1165 #define SQLITE_VERSION "3.33.0"
1166 #define SQLITE_VERSION_NUMBER 3033000
1167 #define SQLITE_SOURCE_ID "2020-07-18 18:59:11 020dbfa2aef20e5872cc3e785d99f45903843401292114b5092b9c8aa829b9c3"
1168
1169 /*
1170 ** CAPI3REF: Run-Time Library Version Numbers
1171 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1172 **
@@ -14735,10 +14735,257 @@
14735 /*
14736 ** Defer sourcing vdbe.h and btree.h until after the "u8" and
14737 ** "BusyHandler" typedefs. vdbe.h also requires a few of the opaque
14738 ** pointer types (i.e. FuncDef) defined above.
14739 */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14740 /************** Include btree.h in the middle of sqliteInt.h *****************/
14741 /************** Begin file btree.h *******************************************/
14742 /*
14743 ** 2001 September 15
14744 **
@@ -14810,12 +15057,12 @@
14810 SQLITE_PRIVATE int sqlite3BtreeSetMmapLimit(Btree*,sqlite3_int64);
14811 #endif
14812 SQLITE_PRIVATE int sqlite3BtreeSetPagerFlags(Btree*,unsigned);
14813 SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve, int eFix);
14814 SQLITE_PRIVATE int sqlite3BtreeGetPageSize(Btree*);
14815 SQLITE_PRIVATE int sqlite3BtreeMaxPageCount(Btree*,int);
14816 SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree*);
14817 SQLITE_PRIVATE int sqlite3BtreeSecureDelete(Btree*,int);
14818 SQLITE_PRIVATE int sqlite3BtreeGetRequestedReserve(Btree*);
14819 SQLITE_PRIVATE int sqlite3BtreeGetReserveNoMutex(Btree *p);
14820 SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum(Btree *, int);
14821 SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *);
@@ -14823,11 +15070,11 @@
14823 SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree*, const char*);
14824 SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree*, int);
14825 SQLITE_PRIVATE int sqlite3BtreeCommit(Btree*);
14826 SQLITE_PRIVATE int sqlite3BtreeRollback(Btree*,int,int);
14827 SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree*,int);
14828 SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree*, int*, int flags);
14829 SQLITE_PRIVATE int sqlite3BtreeIsInTrans(Btree*);
14830 SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree*);
14831 SQLITE_PRIVATE int sqlite3BtreeIsInBackup(Btree*);
14832 SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *, int, void(*)(void *));
14833 SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *pBtree);
@@ -14964,11 +15211,11 @@
14964 #define BTREE_WRCSR 0x00000004 /* read-write cursor */
14965 #define BTREE_FORDELETE 0x00000008 /* Cursor is for seek/delete only */
14966
14967 SQLITE_PRIVATE int sqlite3BtreeCursor(
14968 Btree*, /* BTree containing table to open */
14969 int iTable, /* Index of root page */
14970 int wrFlag, /* 1 for writing. 0 for read-only */
14971 struct KeyInfo*, /* First argument to compare function */
14972 BtCursor *pCursor /* Space to write cursor structure */
14973 );
14974 SQLITE_PRIVATE BtCursor *sqlite3BtreeFakeValidCursor(void);
@@ -15055,11 +15302,11 @@
15055 SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*);
15056 SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt);
15057 SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*);
15058 SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeMaxRecordSize(BtCursor*);
15059
15060 SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(sqlite3*,Btree*,int*aRoot,int nRoot,int,int*);
15061 SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
15062 SQLITE_PRIVATE i64 sqlite3BtreeRowCountEst(BtCursor*);
15063
15064 #ifndef SQLITE_OMIT_INCRBLOB
15065 SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor*, u32 offset, u32 amt, void*);
@@ -15192,11 +15439,11 @@
15192 sqlite3_context *pCtx; /* Used when p4type is P4_FUNCCTX */
15193 CollSeq *pColl; /* Used when p4type is P4_COLLSEQ */
15194 Mem *pMem; /* Used when p4type is P4_MEM */
15195 VTable *pVtab; /* Used when p4type is P4_VTAB */
15196 KeyInfo *pKeyInfo; /* Used when p4type is P4_KEYINFO */
15197 int *ai; /* Used when p4type is P4_INTARRAY */
15198 SubProgram *pProgram; /* Used when p4type is P4_SUBPROGRAM */
15199 Table *pTab; /* Used when p4type is P4_TABLE */
15200 #ifdef SQLITE_ENABLE_CURSOR_HINTS
15201 Expr *pExpr; /* Used when p4type is P4_EXPR */
15202 #endif
@@ -15756,257 +16003,10 @@
15756 #endif
15757
15758 #endif /* SQLITE_VDBE_H */
15759
15760 /************** End of vdbe.h ************************************************/
15761 /************** Continuing where we left off in sqliteInt.h ******************/
15762 /************** Include pager.h in the middle of sqliteInt.h *****************/
15763 /************** Begin file pager.h *******************************************/
15764 /*
15765 ** 2001 September 15
15766 **
15767 ** The author disclaims copyright to this source code. In place of
15768 ** a legal notice, here is a blessing:
15769 **
15770 ** May you do good and not evil.
15771 ** May you find forgiveness for yourself and forgive others.
15772 ** May you share freely, never taking more than you give.
15773 **
15774 *************************************************************************
15775 ** This header file defines the interface that the sqlite page cache
15776 ** subsystem. The page cache subsystem reads and writes a file a page
15777 ** at a time and provides a journal for rollback.
15778 */
15779
15780 #ifndef SQLITE_PAGER_H
15781 #define SQLITE_PAGER_H
15782
15783 /*
15784 ** Default maximum size for persistent journal files. A negative
15785 ** value means no limit. This value may be overridden using the
15786 ** sqlite3PagerJournalSizeLimit() API. See also "PRAGMA journal_size_limit".
15787 */
15788 #ifndef SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT
15789 #define SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT -1
15790 #endif
15791
15792 /*
15793 ** The type used to represent a page number. The first page in a file
15794 ** is called page 1. 0 is used to represent "not a page".
15795 */
15796 typedef u32 Pgno;
15797
15798 /*
15799 ** Each open file is managed by a separate instance of the "Pager" structure.
15800 */
15801 typedef struct Pager Pager;
15802
15803 /*
15804 ** Handle type for pages.
15805 */
15806 typedef struct PgHdr DbPage;
15807
15808 /*
15809 ** Page number PAGER_MJ_PGNO is never used in an SQLite database (it is
15810 ** reserved for working around a windows/posix incompatibility). It is
15811 ** used in the journal to signify that the remainder of the journal file
15812 ** is devoted to storing a super-journal name - there are no more pages to
15813 ** roll back. See comments for function writeSuperJournal() in pager.c
15814 ** for details.
15815 */
15816 #define PAGER_MJ_PGNO(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1))
15817
15818 /*
15819 ** Allowed values for the flags parameter to sqlite3PagerOpen().
15820 **
15821 ** NOTE: These values must match the corresponding BTREE_ values in btree.h.
15822 */
15823 #define PAGER_OMIT_JOURNAL 0x0001 /* Do not use a rollback journal */
15824 #define PAGER_MEMORY 0x0002 /* In-memory database */
15825
15826 /*
15827 ** Valid values for the second argument to sqlite3PagerLockingMode().
15828 */
15829 #define PAGER_LOCKINGMODE_QUERY -1
15830 #define PAGER_LOCKINGMODE_NORMAL 0
15831 #define PAGER_LOCKINGMODE_EXCLUSIVE 1
15832
15833 /*
15834 ** Numeric constants that encode the journalmode.
15835 **
15836 ** The numeric values encoded here (other than PAGER_JOURNALMODE_QUERY)
15837 ** are exposed in the API via the "PRAGMA journal_mode" command and
15838 ** therefore cannot be changed without a compatibility break.
15839 */
15840 #define PAGER_JOURNALMODE_QUERY (-1) /* Query the value of journalmode */
15841 #define PAGER_JOURNALMODE_DELETE 0 /* Commit by deleting journal file */
15842 #define PAGER_JOURNALMODE_PERSIST 1 /* Commit by zeroing journal header */
15843 #define PAGER_JOURNALMODE_OFF 2 /* Journal omitted. */
15844 #define PAGER_JOURNALMODE_TRUNCATE 3 /* Commit by truncating journal */
15845 #define PAGER_JOURNALMODE_MEMORY 4 /* In-memory journal file */
15846 #define PAGER_JOURNALMODE_WAL 5 /* Use write-ahead logging */
15847
15848 /*
15849 ** Flags that make up the mask passed to sqlite3PagerGet().
15850 */
15851 #define PAGER_GET_NOCONTENT 0x01 /* Do not load data from disk */
15852 #define PAGER_GET_READONLY 0x02 /* Read-only page is acceptable */
15853
15854 /*
15855 ** Flags for sqlite3PagerSetFlags()
15856 **
15857 ** Value constraints (enforced via assert()):
15858 ** PAGER_FULLFSYNC == SQLITE_FullFSync
15859 ** PAGER_CKPT_FULLFSYNC == SQLITE_CkptFullFSync
15860 ** PAGER_CACHE_SPILL == SQLITE_CacheSpill
15861 */
15862 #define PAGER_SYNCHRONOUS_OFF 0x01 /* PRAGMA synchronous=OFF */
15863 #define PAGER_SYNCHRONOUS_NORMAL 0x02 /* PRAGMA synchronous=NORMAL */
15864 #define PAGER_SYNCHRONOUS_FULL 0x03 /* PRAGMA synchronous=FULL */
15865 #define PAGER_SYNCHRONOUS_EXTRA 0x04 /* PRAGMA synchronous=EXTRA */
15866 #define PAGER_SYNCHRONOUS_MASK 0x07 /* Mask for four values above */
15867 #define PAGER_FULLFSYNC 0x08 /* PRAGMA fullfsync=ON */
15868 #define PAGER_CKPT_FULLFSYNC 0x10 /* PRAGMA checkpoint_fullfsync=ON */
15869 #define PAGER_CACHESPILL 0x20 /* PRAGMA cache_spill=ON */
15870 #define PAGER_FLAGS_MASK 0x38 /* All above except SYNCHRONOUS */
15871
15872 /*
15873 ** The remainder of this file contains the declarations of the functions
15874 ** that make up the Pager sub-system API. See source code comments for
15875 ** a detailed description of each routine.
15876 */
15877
15878 /* Open and close a Pager connection. */
15879 SQLITE_PRIVATE int sqlite3PagerOpen(
15880 sqlite3_vfs*,
15881 Pager **ppPager,
15882 const char*,
15883 int,
15884 int,
15885 int,
15886 void(*)(DbPage*)
15887 );
15888 SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager, sqlite3*);
15889 SQLITE_PRIVATE int sqlite3PagerReadFileheader(Pager*, int, unsigned char*);
15890
15891 /* Functions used to configure a Pager object. */
15892 SQLITE_PRIVATE void sqlite3PagerSetBusyHandler(Pager*, int(*)(void *), void *);
15893 SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager*, u32*, int);
15894 SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager*, int);
15895 SQLITE_PRIVATE void sqlite3PagerSetCachesize(Pager*, int);
15896 SQLITE_PRIVATE int sqlite3PagerSetSpillsize(Pager*, int);
15897 SQLITE_PRIVATE void sqlite3PagerSetMmapLimit(Pager *, sqlite3_int64);
15898 SQLITE_PRIVATE void sqlite3PagerShrink(Pager*);
15899 SQLITE_PRIVATE void sqlite3PagerSetFlags(Pager*,unsigned);
15900 SQLITE_PRIVATE int sqlite3PagerLockingMode(Pager *, int);
15901 SQLITE_PRIVATE int sqlite3PagerSetJournalMode(Pager *, int);
15902 SQLITE_PRIVATE int sqlite3PagerGetJournalMode(Pager*);
15903 SQLITE_PRIVATE int sqlite3PagerOkToChangeJournalMode(Pager*);
15904 SQLITE_PRIVATE i64 sqlite3PagerJournalSizeLimit(Pager *, i64);
15905 SQLITE_PRIVATE sqlite3_backup **sqlite3PagerBackupPtr(Pager*);
15906 SQLITE_PRIVATE int sqlite3PagerFlush(Pager*);
15907
15908 /* Functions used to obtain and release page references. */
15909 SQLITE_PRIVATE int sqlite3PagerGet(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag);
15910 SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno);
15911 SQLITE_PRIVATE void sqlite3PagerRef(DbPage*);
15912 SQLITE_PRIVATE void sqlite3PagerUnref(DbPage*);
15913 SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage*);
15914 SQLITE_PRIVATE void sqlite3PagerUnrefPageOne(DbPage*);
15915
15916 /* Operations on page references. */
15917 SQLITE_PRIVATE int sqlite3PagerWrite(DbPage*);
15918 SQLITE_PRIVATE void sqlite3PagerDontWrite(DbPage*);
15919 SQLITE_PRIVATE int sqlite3PagerMovepage(Pager*,DbPage*,Pgno,int);
15920 SQLITE_PRIVATE int sqlite3PagerPageRefcount(DbPage*);
15921 SQLITE_PRIVATE void *sqlite3PagerGetData(DbPage *);
15922 SQLITE_PRIVATE void *sqlite3PagerGetExtra(DbPage *);
15923
15924 /* Functions used to manage pager transactions and savepoints. */
15925 SQLITE_PRIVATE void sqlite3PagerPagecount(Pager*, int*);
15926 SQLITE_PRIVATE int sqlite3PagerBegin(Pager*, int exFlag, int);
15927 SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zSuper, int);
15928 SQLITE_PRIVATE int sqlite3PagerExclusiveLock(Pager*);
15929 SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zSuper);
15930 SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager*);
15931 SQLITE_PRIVATE int sqlite3PagerRollback(Pager*);
15932 SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int n);
15933 SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint);
15934 SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager);
15935
15936 #ifndef SQLITE_OMIT_WAL
15937 SQLITE_PRIVATE int sqlite3PagerCheckpoint(Pager *pPager, sqlite3*, int, int*, int*);
15938 SQLITE_PRIVATE int sqlite3PagerWalSupported(Pager *pPager);
15939 SQLITE_PRIVATE int sqlite3PagerWalCallback(Pager *pPager);
15940 SQLITE_PRIVATE int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen);
15941 SQLITE_PRIVATE int sqlite3PagerCloseWal(Pager *pPager, sqlite3*);
15942 # ifdef SQLITE_ENABLE_SNAPSHOT
15943 SQLITE_PRIVATE int sqlite3PagerSnapshotGet(Pager*, sqlite3_snapshot **ppSnapshot);
15944 SQLITE_PRIVATE int sqlite3PagerSnapshotOpen(Pager*, sqlite3_snapshot *pSnapshot);
15945 SQLITE_PRIVATE int sqlite3PagerSnapshotRecover(Pager *pPager);
15946 SQLITE_PRIVATE int sqlite3PagerSnapshotCheck(Pager *pPager, sqlite3_snapshot *pSnapshot);
15947 SQLITE_PRIVATE void sqlite3PagerSnapshotUnlock(Pager *pPager);
15948 # endif
15949 #endif
15950
15951 #if !defined(SQLITE_OMIT_WAL) && defined(SQLITE_ENABLE_SETLK_TIMEOUT)
15952 SQLITE_PRIVATE int sqlite3PagerWalWriteLock(Pager*, int);
15953 SQLITE_PRIVATE void sqlite3PagerWalDb(Pager*, sqlite3*);
15954 #else
15955 # define sqlite3PagerWalWriteLock(y,z) SQLITE_OK
15956 # define sqlite3PagerWalDb(x,y)
15957 #endif
15958
15959 #ifdef SQLITE_DIRECT_OVERFLOW_READ
15960 SQLITE_PRIVATE int sqlite3PagerDirectReadOk(Pager *pPager, Pgno pgno);
15961 #endif
15962
15963 #ifdef SQLITE_ENABLE_ZIPVFS
15964 SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager);
15965 #endif
15966
15967 /* Functions used to query pager state and configuration. */
15968 SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*);
15969 SQLITE_PRIVATE u32 sqlite3PagerDataVersion(Pager*);
15970 #ifdef SQLITE_DEBUG
15971 SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
15972 #endif
15973 SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*);
15974 SQLITE_PRIVATE const char *sqlite3PagerFilename(const Pager*, int);
15975 SQLITE_PRIVATE sqlite3_vfs *sqlite3PagerVfs(Pager*);
15976 SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*);
15977 SQLITE_PRIVATE sqlite3_file *sqlite3PagerJrnlFile(Pager*);
15978 SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*);
15979 SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*);
15980 SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager*);
15981 SQLITE_PRIVATE void sqlite3PagerCacheStat(Pager *, int, int, int *);
15982 SQLITE_PRIVATE void sqlite3PagerClearCache(Pager*);
15983 SQLITE_PRIVATE int sqlite3SectorSize(sqlite3_file *);
15984
15985 /* Functions used to truncate the database file. */
15986 SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno);
15987
15988 SQLITE_PRIVATE void sqlite3PagerRekey(DbPage*, Pgno, u16);
15989
15990 /* Functions to support testing and debugging. */
15991 #if !defined(NDEBUG) || defined(SQLITE_TEST)
15992 SQLITE_PRIVATE Pgno sqlite3PagerPagenumber(DbPage*);
15993 SQLITE_PRIVATE int sqlite3PagerIswriteable(DbPage*);
15994 #endif
15995 #ifdef SQLITE_TEST
15996 SQLITE_PRIVATE int *sqlite3PagerStats(Pager*);
15997 SQLITE_PRIVATE void sqlite3PagerRefdump(Pager*);
15998 void disable_simulated_io_errors(void);
15999 void enable_simulated_io_errors(void);
16000 #else
16001 # define disable_simulated_io_errors()
16002 # define enable_simulated_io_errors()
16003 #endif
16004
16005 #endif /* SQLITE_PAGER_H */
16006
16007 /************** End of pager.h ***********************************************/
16008 /************** Continuing where we left off in sqliteInt.h ******************/
16009 /************** Include pcache.h in the middle of sqliteInt.h ****************/
16010 /************** Begin file pcache.h ******************************************/
16011 /*
16012 ** 2008 August 05
@@ -16843,11 +16843,11 @@
16843 int nChange; /* Value returned by sqlite3_changes() */
16844 int nTotalChange; /* Value returned by sqlite3_total_changes() */
16845 int aLimit[SQLITE_N_LIMIT]; /* Limits */
16846 int nMaxSorterMmap; /* Maximum size of regions mapped by sorter */
16847 struct sqlite3InitInfo { /* Information used during initialization */
16848 int newTnum; /* Rootpage of table being initialized */
16849 u8 iDb; /* Which db file is being initialized */
16850 u8 busy; /* TRUE if currently initializing */
16851 unsigned orphanTrigger : 1; /* Last statement is orphaned TEMP trigger */
16852 unsigned imposterTable : 1; /* Building an imposter table */
16853 unsigned reopenMemdb : 1; /* ATTACH is really a reopen using MemDB */
@@ -17482,11 +17482,11 @@
17482 Select *pSelect; /* NULL for tables. Points to definition if a view. */
17483 FKey *pFKey; /* Linked list of all foreign keys in this table */
17484 char *zColAff; /* String defining the affinity of each column */
17485 ExprList *pCheck; /* All CHECK constraints */
17486 /* ... also used as column name list in a VIEW */
17487 int tnum; /* Root BTree page for this table */
17488 u32 nTabRef; /* Number of pointers to this Table */
17489 u32 tabFlags; /* Mask of TF_* values */
17490 i16 iPKey; /* If not negative, use aCol[iPKey] as the rowid */
17491 i16 nCol; /* Number of columns in this table */
17492 i16 nNVCol; /* Number of columns that are not VIRTUAL */
@@ -17775,11 +17775,11 @@
17775 Schema *pSchema; /* Schema containing this index */
17776 u8 *aSortOrder; /* for each column: True==DESC, False==ASC */
17777 const char **azColl; /* Array of collation sequence names for index */
17778 Expr *pPartIdxWhere; /* WHERE clause for partial indices */
17779 ExprList *aColExpr; /* Column expressions */
17780 int tnum; /* DB Page containing root of this index */
17781 LogEst szIdxRow; /* Estimated average row size in bytes */
17782 u16 nKeyCol; /* Number of columns forming the key */
17783 u16 nColumn; /* Number of columns stored in the index */
17784 u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
17785 unsigned idxType:2; /* 0:Normal 1:UNIQUE, 2:PRIMARY KEY, 3:IPK */
@@ -18990,10 +18990,11 @@
18990 char **pzErrMsg; /* Error message stored here */
18991 int iDb; /* 0 for main database. 1 for TEMP, 2.. for ATTACHed */
18992 int rc; /* Result code stored here */
18993 u32 mInitFlags; /* Flags controlling error messages */
18994 u32 nInitRow; /* Number of rows processed */
 
18995 } InitData;
18996
18997 /*
18998 ** Allowed values for mInitFlags
18999 */
@@ -19823,12 +19824,14 @@
19823 SQLITE_PRIVATE int sqlite3FixSelect(DbFixer*, Select*);
19824 SQLITE_PRIVATE int sqlite3FixExpr(DbFixer*, Expr*);
19825 SQLITE_PRIVATE int sqlite3FixExprList(DbFixer*, ExprList*);
19826 SQLITE_PRIVATE int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
19827 SQLITE_PRIVATE int sqlite3RealSameAsInt(double,sqlite3_int64);
 
19828 SQLITE_PRIVATE int sqlite3AtoF(const char *z, double*, int, u8);
19829 SQLITE_PRIVATE int sqlite3GetInt32(const char *, int*);
 
19830 SQLITE_PRIVATE int sqlite3Atoi(const char*);
19831 #ifndef SQLITE_OMIT_UTF16
19832 SQLITE_PRIVATE int sqlite3Utf16ByteLen(const void *pData, int nChar);
19833 #endif
19834 SQLITE_PRIVATE int sqlite3Utf8CharLen(const char *pData, int nByte);
@@ -19952,11 +19955,11 @@
19952 #endif
19953 #endif /* SQLITE_AMALGAMATION */
19954 #ifdef VDBE_PROFILE
19955 SQLITE_PRIVATE sqlite3_uint64 sqlite3NProfileCnt;
19956 #endif
19957 SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3*, int, int, int);
19958 SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*);
19959 SQLITE_PRIVATE void sqlite3AlterFunctions(void);
19960 SQLITE_PRIVATE void sqlite3AlterRenameTable(Parse*, SrcList*, Token*);
19961 SQLITE_PRIVATE void sqlite3AlterRenameColumn(Parse*, SrcList*, Token*, Token*);
19962 SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *, int *);
@@ -20066,11 +20069,11 @@
20066 #else
20067 # define sqlite3CloseExtensions(X)
20068 #endif
20069
20070 #ifndef SQLITE_OMIT_SHARED_CACHE
20071 SQLITE_PRIVATE void sqlite3TableLock(Parse *, int, int, u8, const char *);
20072 #else
20073 #define sqlite3TableLock(v,w,x,y,z)
20074 #endif
20075
20076 #ifdef SQLITE_TEST
@@ -20788,11 +20791,11 @@
20788 Bool useRandomRowid:1; /* Generate new record numbers semi-randomly */
20789 Bool isOrdered:1; /* True if the table is not BTREE_UNORDERED */
20790 Bool seekHit:1; /* See the OP_SeekHit and OP_IfNoHope opcodes */
20791 Btree *pBtx; /* Separate file holding temporary table */
20792 i64 seqCount; /* Sequence counter */
20793 int *aAltMap; /* Mapping from table to index column numbers */
20794
20795 /* Cached OP_Column parse information is only valid if cacheStatus matches
20796 ** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
20797 ** CACHE_STALE (0) and so setting cacheStatus=CACHE_STALE guarantees that
20798 ** the cache is out of date. */
@@ -21184,11 +21187,11 @@
21184 */
21185 SQLITE_PRIVATE void sqlite3VdbeError(Vdbe*, const char *, ...);
21186 SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*);
21187 void sqliteVdbePopStack(Vdbe*,int);
21188 SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeFinishMoveto(VdbeCursor*);
21189 SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor**, int*);
21190 SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor*);
21191 SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
21192 SQLITE_PRIVATE u8 sqlite3VdbeOneByteSerialTypeLen(u8);
21193 SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32);
21194 SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
@@ -22816,12 +22819,12 @@
22816 break;
22817 }
22818 case 'm': sqlite3_snprintf(3, &z[j],"%02d",x.M); j+=2; break;
22819 case 'M': sqlite3_snprintf(3, &z[j],"%02d",x.m); j+=2; break;
22820 case 's': {
22821 sqlite3_snprintf(30,&z[j],"%lld",
22822 (i64)(x.iJD/1000 - 21086676*(i64)10000));
22823 j += sqlite3Strlen30(&z[j]);
22824 break;
22825 }
22826 case 'S': sqlite3_snprintf(3,&z[j],"%02d",(int)x.s); j+=2; break;
22827 case 'w': {
@@ -31770,10 +31773,34 @@
31770 #endif /* SQLITE_OMIT_FLOATING_POINT */
31771 }
31772 #if defined(_MSC_VER)
31773 #pragma warning(default : 4756)
31774 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31775
31776 /*
31777 ** Compare the 19-character string zNum against the text representation
31778 ** value 2^63: 9223372036854775808. Return negative, zero, or positive
31779 ** if zNum is less than, equal to, or greater than the string.
@@ -32011,13 +32038,31 @@
32011 ** Return a 32-bit integer value extracted from a string. If the
32012 ** string is not an integer, just return 0.
32013 */
32014 SQLITE_PRIVATE int sqlite3Atoi(const char *z){
32015 int x = 0;
32016 if( z ) sqlite3GetInt32(z, &x);
32017 return x;
32018 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32019
32020 /*
32021 ** The variable-length integer encoding is as follows:
32022 **
32023 ** KEY:
@@ -39188,11 +39233,11 @@
39188 }
39189 #endif
39190 if( rc!=SQLITE_OK ){
39191 if( h>=0 ) robust_close(pNew, h, __LINE__);
39192 }else{
39193 pNew->pMethod = pLockingStyle;
39194 OpenCounter(+1);
39195 verifyDbFile(pNew);
39196 }
39197 return rc;
39198 }
@@ -46899,11 +46944,11 @@
46899 {
46900 sqlite3_free(zConverted);
46901 }
46902
46903 sqlite3_free(zTmpname);
46904 pFile->pMethod = pAppData ? pAppData->pMethod : &winIoMethod;
46905 pFile->pVfs = pVfs;
46906 pFile->h = h;
46907 if( isReadonly ){
46908 pFile->ctrlFlags |= WINFILE_RDONLY;
46909 }
@@ -48125,11 +48170,11 @@
48125 }
48126 memset(p, 0, sizeof(*p));
48127 p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE;
48128 assert( pOutFlags!=0 ); /* True because flags==SQLITE_OPEN_MAIN_DB */
48129 *pOutFlags = flags | SQLITE_OPEN_MEMORY;
48130 p->base.pMethods = &memdb_io_methods;
48131 p->szMax = sqlite3GlobalConfig.mxMemdbSize;
48132 return SQLITE_OK;
48133 }
48134
48135 #if 0 /* Only used to delete rollback journals, super-journals, and WAL
@@ -52442,15 +52487,10 @@
52442 # define USEFETCH(x) ((x)->bUseFetch)
52443 #else
52444 # define USEFETCH(x) 0
52445 #endif
52446
52447 /*
52448 ** The maximum legal page number is (2^31 - 1).
52449 */
52450 #define PAGER_MAX_PGNO 2147483647
52451
52452 /*
52453 ** The argument to this macro is a file descriptor (type sqlite3_file*).
52454 ** Return 0 if it is not open, or non-zero (but not 1) if it is.
52455 **
52456 ** This is so that expressions can be written as:
@@ -55419,11 +55459,11 @@
55419 ** Make no changes if mxPage is zero or negative. And never reduce the
55420 ** maximum page count below the current size of the database.
55421 **
55422 ** Regardless of mxPage, return the current maximum page count.
55423 */
55424 SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager *pPager, int mxPage){
55425 if( mxPage>0 ){
55426 pPager->mxPgno = mxPage;
55427 }
55428 assert( pPager->eState!=PAGER_OPEN ); /* Called only by OP_MaxPgcnt */
55429 /* assert( pPager->mxPgno>=pPager->dbSize ); */
@@ -57146,22 +57186,22 @@
57146
57147 noContent = (flags & PAGER_GET_NOCONTENT)!=0;
57148 if( pPg->pPager && !noContent ){
57149 /* In this case the pcache already contains an initialized copy of
57150 ** the page. Return without further ado. */
57151 assert( pgno<=PAGER_MAX_PGNO && pgno!=PAGER_MJ_PGNO(pPager) );
57152 pPager->aStat[PAGER_STAT_HIT]++;
57153 return SQLITE_OK;
57154
57155 }else{
57156 /* The pager cache has created a new page. Its content needs to
57157 ** be initialized. But first some error checks:
57158 **
57159 ** (1) The maximum page number is 2^31
57160 ** (2) Never try to fetch the locking page
57161 */
57162 if( pgno>PAGER_MAX_PGNO || pgno==PAGER_MJ_PGNO(pPager) ){
57163 rc = SQLITE_CORRUPT_BKPT;
57164 goto pager_acquire_err;
57165 }
57166
57167 pPg->pPager = pPager;
@@ -59863,11 +59903,11 @@
59863 ** walIteratorFree() - Free an iterator.
59864 **
59865 ** This functionality is used by the checkpoint code (see walCheckpoint()).
59866 */
59867 struct WalIterator {
59868 int iPrior; /* Last result returned from the iterator */
59869 int nSegment; /* Number of entries in aSegment[] */
59870 struct WalSegment {
59871 int iNext; /* Next slot in aIndex[] not yet returned */
59872 ht_slot *aIndex; /* i0, i1, i2... such that aPgno[iN] ascend */
59873 u32 *aPgno; /* Array of page numbers. */
@@ -59945,11 +59985,13 @@
59945 rc = sqlite3OsShmMap(pWal->pDbFd, iPage, WALINDEX_PGSZ,
59946 pWal->writeLock, (void volatile **)&pWal->apWiData[iPage]
59947 );
59948 assert( pWal->apWiData[iPage]!=0 || rc!=SQLITE_OK || pWal->writeLock==0 );
59949 testcase( pWal->apWiData[iPage]==0 && rc==SQLITE_OK );
59950 if( (rc&0xff)==SQLITE_READONLY ){
 
 
59951 pWal->readOnly |= WAL_SHM_RDONLY;
59952 if( rc==SQLITE_READONLY ){
59953 rc = SQLITE_OK;
59954 }
59955 }
@@ -60320,10 +60362,11 @@
60320 && (iHash>=1 || iFrame<=HASHTABLE_NPAGE_ONE)
60321 && (iHash<=1 || iFrame>(HASHTABLE_NPAGE_ONE+HASHTABLE_NPAGE))
60322 && (iHash>=2 || iFrame<=HASHTABLE_NPAGE_ONE+HASHTABLE_NPAGE)
60323 && (iHash<=2 || iFrame>(HASHTABLE_NPAGE_ONE+2*HASHTABLE_NPAGE))
60324 );
 
60325 return iHash;
60326 }
60327
60328 /*
60329 ** Return the page number associated with frame iFrame in this WAL.
@@ -60516,16 +60559,10 @@
60516 assert( WAL_ALL_BUT_WRITE==WAL_WRITE_LOCK+1 );
60517 assert( WAL_CKPT_LOCK==WAL_ALL_BUT_WRITE );
60518 assert( pWal->writeLock );
60519 iLock = WAL_ALL_BUT_WRITE + pWal->ckptLock;
60520 rc = walLockExclusive(pWal, iLock, WAL_READ_LOCK(0)-iLock);
60521 if( rc==SQLITE_OK ){
60522 rc = walLockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1);
60523 if( rc!=SQLITE_OK ){
60524 walUnlockExclusive(pWal, iLock, WAL_READ_LOCK(0)-iLock);
60525 }
60526 }
60527 if( rc ){
60528 return rc;
60529 }
60530
60531 WALTRACE(("WAL%p: recovery begin...\n", pWal));
@@ -60537,19 +60574,20 @@
60537 goto recovery_error;
60538 }
60539
60540 if( nSize>WAL_HDRSIZE ){
60541 u8 aBuf[WAL_HDRSIZE]; /* Buffer to load WAL header into */
 
60542 u8 *aFrame = 0; /* Malloc'd buffer to load entire frame */
60543 int szFrame; /* Number of bytes in buffer aFrame[] */
60544 u8 *aData; /* Pointer to data part of aFrame buffer */
60545 int iFrame; /* Index of last frame read */
60546 i64 iOffset; /* Next offset to read from log file */
60547 int szPage; /* Page size according to the log */
60548 u32 magic; /* Magic value read from WAL header */
60549 u32 version; /* Magic value read from WAL header */
60550 int isValid; /* True if this frame is valid */
 
 
60551
60552 /* Read in the WAL header. */
60553 rc = sqlite3OsRead(pWal->pWalFd, aBuf, WAL_HDRSIZE, 0);
60554 if( rc!=SQLITE_OK ){
60555 goto recovery_error;
@@ -60592,42 +60630,59 @@
60592 goto finished;
60593 }
60594
60595 /* Malloc a buffer to read frames into. */
60596 szFrame = szPage + WAL_FRAME_HDRSIZE;
60597 aFrame = (u8 *)sqlite3_malloc64(szFrame);
60598 if( !aFrame ){
60599 rc = SQLITE_NOMEM_BKPT;
60600 goto recovery_error;
60601 }
60602 aData = &aFrame[WAL_FRAME_HDRSIZE];
 
60603
60604 /* Read all frames from the log file. */
60605 iFrame = 0;
60606 for(iOffset=WAL_HDRSIZE; (iOffset+szFrame)<=nSize; iOffset+=szFrame){
60607 u32 pgno; /* Database page number for frame */
60608 u32 nTruncate; /* dbsize field from frame header */
60609
60610 /* Read and decode the next log frame. */
60611 iFrame++;
60612 rc = sqlite3OsRead(pWal->pWalFd, aFrame, szFrame, iOffset);
60613 if( rc!=SQLITE_OK ) break;
60614 isValid = walDecodeFrame(pWal, &pgno, &nTruncate, aData, aFrame);
60615 if( !isValid ) break;
60616 rc = walIndexAppend(pWal, iFrame, pgno);
60617 if( rc!=SQLITE_OK ) break;
60618
60619 /* If nTruncate is non-zero, this is a commit record. */
60620 if( nTruncate ){
60621 pWal->hdr.mxFrame = iFrame;
60622 pWal->hdr.nPage = nTruncate;
60623 pWal->hdr.szPage = (u16)((szPage&0xff00) | (szPage>>16));
60624 testcase( szPage<=32768 );
60625 testcase( szPage>=65536 );
60626 aFrameCksum[0] = pWal->hdr.aFrameCksum[0];
60627 aFrameCksum[1] = pWal->hdr.aFrameCksum[1];
60628 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60629 }
60630
60631 sqlite3_free(aFrame);
60632 }
60633
@@ -60638,19 +60693,30 @@
60638 pWal->hdr.aFrameCksum[0] = aFrameCksum[0];
60639 pWal->hdr.aFrameCksum[1] = aFrameCksum[1];
60640 walIndexWriteHdr(pWal);
60641
60642 /* Reset the checkpoint-header. This is safe because this thread is
60643 ** currently holding locks that exclude all other readers, writers and
60644 ** checkpointers.
60645 */
60646 pInfo = walCkptInfo(pWal);
60647 pInfo->nBackfill = 0;
60648 pInfo->nBackfillAttempted = pWal->hdr.mxFrame;
60649 pInfo->aReadMark[0] = 0;
60650 for(i=1; i<WAL_NREADER; i++) pInfo->aReadMark[i] = READMARK_NOT_USED;
60651 if( pWal->hdr.mxFrame ) pInfo->aReadMark[1] = pWal->hdr.mxFrame;
 
 
 
 
 
 
 
 
 
 
 
60652
60653 /* If more than one frame was recovered from the log file, report an
60654 ** event via sqlite3_log(). This is to help with identifying performance
60655 ** problems caused by applications routinely shutting down without
60656 ** checkpointing the log file.
@@ -60664,11 +60730,10 @@
60664 }
60665
60666 recovery_error:
60667 WALTRACE(("WAL%p: recovery %s\n", pWal, rc ? "failed" : "ok"));
60668 walUnlockExclusive(pWal, iLock, WAL_READ_LOCK(0)-iLock);
60669 walUnlockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1);
60670 return rc;
60671 }
60672
60673 /*
60674 ** Close an open wal-index.
@@ -64048,11 +64113,12 @@
64048 Pgno nPage; /* Number of pages in the database */
64049 int mxErr; /* Stop accumulating errors when this reaches zero */
64050 int nErr; /* Number of messages written to zErrMsg so far */
64051 int bOomFault; /* A memory allocation error has occurred */
64052 const char *zPfx; /* Error message prefix */
64053 int v1, v2; /* Values for up to two %d fields in zPfx */
 
64054 StrAccum errMsg; /* Accumulate the error message text here */
64055 u32 *heap; /* Min-heap used for analyzing cell coverage */
64056 sqlite3 *db; /* Database connection running the check */
64057 };
64058
@@ -66513,16 +66579,15 @@
66513 /*
66514 ** Return the size of the database file in pages. If there is any kind of
66515 ** error, return ((unsigned int)-1).
66516 */
66517 static Pgno btreePagecount(BtShared *pBt){
66518 assert( (pBt->nPage & 0x80000000)==0 || CORRUPT_DB );
66519 return pBt->nPage;
66520 }
66521 SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree *p){
66522 assert( sqlite3BtreeHoldsMutex(p) );
66523 return btreePagecount(p->pBt) & 0x7fffffff;
66524 }
66525
66526 /*
66527 ** Get a page from the pager and initialize it.
66528 **
@@ -67306,12 +67371,12 @@
67306 /*
67307 ** Set the maximum page count for a database if mxPage is positive.
67308 ** No changes are made if mxPage is 0 or negative.
67309 ** Regardless of the value of mxPage, return the maximum page count.
67310 */
67311 SQLITE_PRIVATE int sqlite3BtreeMaxPageCount(Btree *p, int mxPage){
67312 int n;
67313 sqlite3BtreeEnter(p);
67314 n = sqlite3PagerMaxPageCount(p->pBt->pPager, mxPage);
67315 sqlite3BtreeLeave(p);
67316 return n;
67317 }
@@ -68746,11 +68811,11 @@
68746 ** It is assumed that the sqlite3BtreeCursorZero() has been called
68747 ** on pCur to initialize the memory space prior to invoking this routine.
68748 */
68749 static int btreeCursor(
68750 Btree *p, /* The btree */
68751 int iTable, /* Root page of table to open */
68752 int wrFlag, /* 1 to write. 0 read-only */
68753 struct KeyInfo *pKeyInfo, /* First arg to comparison function */
68754 BtCursor *pCur /* Space for new cursor */
68755 ){
68756 BtShared *pBt = p->pBt; /* Shared b-tree handle */
@@ -68789,21 +68854,21 @@
68789 }
68790 }
68791
68792 /* Now that no other errors can occur, finish filling in the BtCursor
68793 ** variables and link the cursor into the BtShared list. */
68794 pCur->pgnoRoot = (Pgno)iTable;
68795 pCur->iPage = -1;
68796 pCur->pKeyInfo = pKeyInfo;
68797 pCur->pBtree = p;
68798 pCur->pBt = pBt;
68799 pCur->curFlags = wrFlag ? BTCF_WriteFlag : 0;
68800 pCur->curPagerFlags = wrFlag ? 0 : PAGER_GET_READONLY;
68801 /* If there are two or more cursors on the same btree, then all such
68802 ** cursors *must* have the BTCF_Multiple flag set. */
68803 for(pX=pBt->pCursor; pX; pX=pX->pNext){
68804 if( pX->pgnoRoot==(Pgno)iTable ){
68805 pX->curFlags |= BTCF_Multiple;
68806 pCur->curFlags |= BTCF_Multiple;
68807 }
68808 }
68809 pCur->pNext = pBt->pCursor;
@@ -68811,11 +68876,11 @@
68811 pCur->eState = CURSOR_INVALID;
68812 return SQLITE_OK;
68813 }
68814 static int btreeCursorWithLock(
68815 Btree *p, /* The btree */
68816 int iTable, /* Root page of table to open */
68817 int wrFlag, /* 1 to write. 0 read-only */
68818 struct KeyInfo *pKeyInfo, /* First arg to comparison function */
68819 BtCursor *pCur /* Space for new cursor */
68820 ){
68821 int rc;
@@ -68824,11 +68889,11 @@
68824 sqlite3BtreeLeave(p);
68825 return rc;
68826 }
68827 SQLITE_PRIVATE int sqlite3BtreeCursor(
68828 Btree *p, /* The btree */
68829 int iTable, /* Root page of table to open */
68830 int wrFlag, /* 1 to write. 0 read-only */
68831 struct KeyInfo *pKeyInfo, /* First arg to xCompare() */
68832 BtCursor *pCur /* Write new cursor here */
68833 ){
68834 if( p->sharable ){
@@ -69249,10 +69314,11 @@
69249 }
69250
69251 assert( rc==SQLITE_OK && amt>0 );
69252 while( nextPage ){
69253 /* If required, populate the overflow page-list cache. */
 
69254 assert( pCur->aOverflow[iIdx]==0
69255 || pCur->aOverflow[iIdx]==nextPage
69256 || CORRUPT_DB );
69257 pCur->aOverflow[iIdx] = nextPage;
69258
@@ -70321,11 +70387,11 @@
70321 ** shows that the page 'nearby' is somewhere on the free-list, then
70322 ** the entire-list will be searched for that page.
70323 */
70324 #ifndef SQLITE_OMIT_AUTOVACUUM
70325 if( eMode==BTALLOC_EXACT ){
70326 if( nearby<=mxPage ){
70327 u8 eType;
70328 assert( nearby>0 );
70329 assert( pBt->autoVacuum );
70330 rc = ptrmapGet(pBt, nearby, &eType, 0);
70331 if( rc ) return rc;
@@ -70617,11 +70683,11 @@
70617
70618 assert( sqlite3_mutex_held(pBt->mutex) );
70619 assert( CORRUPT_DB || iPage>1 );
70620 assert( !pMemPage || pMemPage->pgno==iPage );
70621
70622 if( iPage<2 || iPage>pBt->nPage ){
70623 return SQLITE_CORRUPT_BKPT;
70624 }
70625 if( pMemPage ){
70626 pPage = pMemPage;
70627 sqlite3PagerRef(pPage->pDbPage);
@@ -70664,10 +70730,14 @@
70664 */
70665 if( nFree!=0 ){
70666 u32 nLeaf; /* Initial number of leaf cells on trunk page */
70667
70668 iTrunk = get4byte(&pPage1->aData[32]);
 
 
 
 
70669 rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0);
70670 if( rc!=SQLITE_OK ){
70671 goto freepage_out;
70672 }
70673
@@ -73468,11 +73538,11 @@
73468 ** flags might not work:
73469 **
73470 ** BTREE_INTKEY|BTREE_LEAFDATA Used for SQL tables with rowid keys
73471 ** BTREE_ZERODATA Used for SQL indices
73472 */
73473 static int btreeCreateTable(Btree *p, int *piTable, int createTabFlags){
73474 BtShared *pBt = p->pBt;
73475 MemPage *pRoot;
73476 Pgno pgnoRoot;
73477 int rc;
73478 int ptfFlags; /* Page-type flage for the root page of new table */
@@ -73501,21 +73571,23 @@
73501 /* Read the value of meta[3] from the database to determine where the
73502 ** root page of the new table should go. meta[3] is the largest root-page
73503 ** created so far, so the new root-page is (meta[3]+1).
73504 */
73505 sqlite3BtreeGetMeta(p, BTREE_LARGEST_ROOT_PAGE, &pgnoRoot);
 
 
 
73506 pgnoRoot++;
73507
73508 /* The new root-page may not be allocated on a pointer-map page, or the
73509 ** PENDING_BYTE page.
73510 */
73511 while( pgnoRoot==PTRMAP_PAGENO(pBt, pgnoRoot) ||
73512 pgnoRoot==PENDING_BYTE_PAGE(pBt) ){
73513 pgnoRoot++;
73514 }
73515 assert( pgnoRoot>=3 || CORRUPT_DB );
73516 testcase( pgnoRoot<3 );
73517
73518 /* Allocate a page. The page that currently resides at pgnoRoot will
73519 ** be moved to the allocated page (unless the allocated page happens
73520 ** to reside at pgnoRoot).
73521 */
@@ -73608,14 +73680,14 @@
73608 ptfFlags = PTF_ZERODATA | PTF_LEAF;
73609 }
73610 zeroPage(pRoot, ptfFlags);
73611 sqlite3PagerUnref(pRoot->pDbPage);
73612 assert( (pBt->openFlags & BTREE_SINGLE)==0 || pgnoRoot==2 );
73613 *piTable = (int)pgnoRoot;
73614 return SQLITE_OK;
73615 }
73616 SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree *p, int *piTable, int flags){
73617 int rc;
73618 sqlite3BtreeEnter(p);
73619 rc = btreeCreateTable(p, piTable, flags);
73620 sqlite3BtreeLeave(p);
73621 return rc;
@@ -74095,11 +74167,11 @@
74095 ** Verify that the number of pages on the list is N.
74096 */
74097 static void checkList(
74098 IntegrityCk *pCheck, /* Integrity checking context */
74099 int isFreeList, /* True for a freelist. False for overflow page list */
74100 int iPage, /* Page number for first page in the list */
74101 u32 N /* Expected number of pages in the list */
74102 ){
74103 int i;
74104 u32 expected = N;
74105 int nErrAtStart = pCheck->nErr;
@@ -74227,11 +74299,11 @@
74227 ** 4. Recursively call checkTreePage on all children.
74228 ** 5. Verify that the depth of all children is the same.
74229 */
74230 static int checkTreePage(
74231 IntegrityCk *pCheck, /* Context for the sanity check */
74232 int iPage, /* Page number of the page to check */
74233 i64 *piMinKey, /* Write minimum integer primary key here */
74234 i64 maxKey /* Error if integer primary key greater than this */
74235 ){
74236 MemPage *pPage = 0; /* The page being analyzed */
74237 int i; /* Loop counter */
@@ -74263,13 +74335,13 @@
74263 */
74264 pBt = pCheck->pBt;
74265 usableSize = pBt->usableSize;
74266 if( iPage==0 ) return 0;
74267 if( checkRef(pCheck, iPage) ) return 0;
74268 pCheck->zPfx = "Page %d: ";
74269 pCheck->v1 = iPage;
74270 if( (rc = btreeGetPage(pBt, (Pgno)iPage, &pPage, 0))!=0 ){
74271 checkAppendMsg(pCheck,
74272 "unable to get the page. error code=%d", rc);
74273 goto end_of_check;
74274 }
74275
@@ -74290,11 +74362,11 @@
74290 }
74291 data = pPage->aData;
74292 hdr = pPage->hdrOffset;
74293
74294 /* Set up for cell analysis */
74295 pCheck->zPfx = "On tree page %d cell %d: ";
74296 contentOffset = get2byteNotZero(&data[hdr+5]);
74297 assert( contentOffset<=usableSize ); /* Enforced by btreeInitPage() */
74298
74299 /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
74300 ** number of cells on the page. */
@@ -74310,11 +74382,11 @@
74310 if( !pPage->leaf ){
74311 /* Analyze the right-child page of internal pages */
74312 pgno = get4byte(&data[hdr+8]);
74313 #ifndef SQLITE_OMIT_AUTOVACUUM
74314 if( pBt->autoVacuum ){
74315 pCheck->zPfx = "On page %d at right child: ";
74316 checkPtrmap(pCheck, pgno, PTRMAP_BTREE, iPage);
74317 }
74318 #endif
74319 depth = checkTreePage(pCheck, pgno, &maxKey, maxKey);
74320 keyCanBeEqual = 0;
@@ -74451,11 +74523,11 @@
74451 nFrag = 0;
74452 prev = contentOffset - 1; /* Implied first min-heap entry */
74453 while( btreeHeapPull(heap,&x) ){
74454 if( (prev&0xffff)>=(x>>16) ){
74455 checkAppendMsg(pCheck,
74456 "Multiple uses for byte %u of page %d", x>>16, iPage);
74457 break;
74458 }else{
74459 nFrag += (x>>16) - (prev&0xffff) - 1;
74460 prev = x;
74461 }
@@ -74466,11 +74538,11 @@
74466 ** EVIDENCE-OF: R-07161-27322 The one-byte integer at offset 7 gives the
74467 ** number of fragmented free bytes within the cell content area.
74468 */
74469 if( heap[0]==0 && nFrag!=data[hdr+7] ){
74470 checkAppendMsg(pCheck,
74471 "Fragmentation of %d bytes reported as %d on page %d",
74472 nFrag, data[hdr+7], iPage);
74473 }
74474 }
74475
74476 end_of_check:
@@ -74494,25 +74566,44 @@
74494 **
74495 ** Write the number of error seen in *pnErr. Except for some memory
74496 ** allocation errors, an error message held in memory obtained from
74497 ** malloc is returned if *pnErr is non-zero. If *pnErr==0 then NULL is
74498 ** returned. If a memory allocation error occurs, NULL is returned.
 
 
 
 
 
 
 
 
 
74499 */
74500 SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(
74501 sqlite3 *db, /* Database connection that is running the check */
74502 Btree *p, /* The btree to be checked */
74503 int *aRoot, /* An array of root pages numbers for individual trees */
74504 int nRoot, /* Number of entries in aRoot[] */
74505 int mxErr, /* Stop reporting errors after this many */
74506 int *pnErr /* Write number of errors seen to this variable */
74507 ){
74508 Pgno i;
74509 IntegrityCk sCheck;
74510 BtShared *pBt = p->pBt;
74511 u64 savedDbFlags = pBt->db->flags;
74512 char zErr[100];
 
 
74513 VVA_ONLY( int nRef );
 
 
 
 
 
 
 
 
74514
74515 sqlite3BtreeEnter(p);
74516 assert( p->inTrans>TRANS_NONE && pBt->inTransaction>TRANS_NONE );
74517 VVA_ONLY( nRef = sqlite3PagerRefcount(pBt->pPager) );
74518 assert( nRef>=0 );
@@ -74548,67 +74639,73 @@
74548 i = PENDING_BYTE_PAGE(pBt);
74549 if( i<=sCheck.nPage ) setPageReferenced(&sCheck, i);
74550
74551 /* Check the integrity of the freelist
74552 */
74553 sCheck.zPfx = "Main freelist: ";
74554 checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]),
74555 get4byte(&pBt->pPage1->aData[36]));
74556 sCheck.zPfx = 0;
 
 
74557
74558 /* Check all the tables.
74559 */
74560 #ifndef SQLITE_OMIT_AUTOVACUUM
74561 if( pBt->autoVacuum ){
74562 int mx = 0;
74563 int mxInHdr;
74564 for(i=0; (int)i<nRoot; i++) if( mx<aRoot[i] ) mx = aRoot[i];
74565 mxInHdr = get4byte(&pBt->pPage1->aData[52]);
74566 if( mx!=mxInHdr ){
74567 checkAppendMsg(&sCheck,
74568 "max rootpage (%d) disagrees with header (%d)",
74569 mx, mxInHdr
74570 );
74571 }
74572 }else if( get4byte(&pBt->pPage1->aData[64])!=0 ){
74573 checkAppendMsg(&sCheck,
74574 "incremental_vacuum enabled with a max rootpage of zero"
74575 );
 
 
74576 }
74577 #endif
74578 testcase( pBt->db->flags & SQLITE_CellSizeCk );
74579 pBt->db->flags &= ~(u64)SQLITE_CellSizeCk;
74580 for(i=0; (int)i<nRoot && sCheck.mxErr; i++){
74581 i64 notUsed;
74582 if( aRoot[i]==0 ) continue;
74583 #ifndef SQLITE_OMIT_AUTOVACUUM
74584 if( pBt->autoVacuum && aRoot[i]>1 ){
74585 checkPtrmap(&sCheck, aRoot[i], PTRMAP_ROOTPAGE, 0);
74586 }
74587 #endif
74588 checkTreePage(&sCheck, aRoot[i], &notUsed, LARGEST_INT64);
74589 }
74590 pBt->db->flags = savedDbFlags;
74591
74592 /* Make sure every page in the file is referenced
74593 */
74594 for(i=1; i<=sCheck.nPage && sCheck.mxErr; i++){
 
74595 #ifdef SQLITE_OMIT_AUTOVACUUM
74596 if( getPageReferenced(&sCheck, i)==0 ){
74597 checkAppendMsg(&sCheck, "Page %d is never used", i);
74598 }
74599 #else
74600 /* If the database supports auto-vacuum, make sure no tables contain
74601 ** references to pointer-map pages.
74602 */
74603 if( getPageReferenced(&sCheck, i)==0 &&
74604 (PTRMAP_PAGENO(pBt, i)!=i || !pBt->autoVacuum) ){
74605 checkAppendMsg(&sCheck, "Page %d is never used", i);
74606 }
74607 if( getPageReferenced(&sCheck, i)!=0 &&
74608 (PTRMAP_PAGENO(pBt, i)==i && pBt->autoVacuum) ){
74609 checkAppendMsg(&sCheck, "Pointer map page %d is referenced", i);
 
74610 }
74611 #endif
74612 }
74613
74614 /* Clean up and report errors.
@@ -75794,20 +75891,29 @@
75794 ** into a buffer.
75795 */
75796 static void vdbeMemRenderNum(int sz, char *zBuf, Mem *p){
75797 StrAccum acc;
75798 assert( p->flags & (MEM_Int|MEM_Real|MEM_IntReal) );
75799 sqlite3StrAccumInit(&acc, 0, zBuf, sz, 0);
75800 if( p->flags & MEM_Int ){
75801 sqlite3_str_appendf(&acc, "%lld", p->u.i);
75802 }else if( p->flags & MEM_IntReal ){
75803 sqlite3_str_appendf(&acc, "%!.15g", (double)p->u.i);
 
 
 
 
 
 
 
75804 }else{
75805 sqlite3_str_appendf(&acc, "%!.15g", p->u.r);
 
 
 
 
75806 }
75807 assert( acc.zText==zBuf && acc.mxAlloc<=0 );
75808 zBuf[acc.nChar] = 0; /* Fast version of sqlite3StrAccumFinish(&acc) */
75809 }
75810
75811 #ifdef SQLITE_DEBUG
75812 /*
75813 ** Validity checks on pMem. pMem holds a string.
@@ -79301,16 +79407,16 @@
79301 sqlite3_str_appendf(&x, "vtab:%p", pVtab);
79302 break;
79303 }
79304 #endif
79305 case P4_INTARRAY: {
79306 int i;
79307 int *ai = pOp->p4.ai;
79308 int n = ai[0]; /* The first element of an INTARRAY is always the
79309 ** count of the number of elements to follow */
79310 for(i=1; i<=n; i++){
79311 sqlite3_str_appendf(&x, "%c%d", (i==1 ? '[' : ','), ai[i]);
79312 }
79313 sqlite3_str_append(&x, "]", 1);
79314 break;
79315 }
79316 case P4_SUBPROGRAM: {
@@ -81150,15 +81256,15 @@
81150 ** a NULL row.
81151 **
81152 ** If the cursor is already pointing to the correct row and that row has
81153 ** not been deleted out from under the cursor, then this routine is a no-op.
81154 */
81155 SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor **pp, int *piCol){
81156 VdbeCursor *p = *pp;
81157 assert( p->eCurType==CURTYPE_BTREE || p->eCurType==CURTYPE_PSEUDO );
81158 if( p->deferredMoveto ){
81159 int iMap;
81160 if( p->aAltMap && (iMap = p->aAltMap[1+*piCol])>0 && !p->nullRow ){
81161 *pp = p->pAltCursor;
81162 *piCol = iMap - 1;
81163 return SQLITE_OK;
81164 }
@@ -87427,14 +87533,14 @@
87427 int n;
87428 int i;
87429 int p1;
87430 int p2;
87431 const KeyInfo *pKeyInfo;
87432 int idx;
87433 CollSeq *pColl; /* Collating sequence to use on this term */
87434 int bRev; /* True for DESCENDING sort order */
87435 int *aPermute; /* The permutation */
87436
87437 if( (pOp->p5 & OPFLAG_PERMUTE)==0 ){
87438 aPermute = 0;
87439 }else{
87440 assert( pOp>aOp );
@@ -87459,11 +87565,11 @@
87459 assert( p1>0 && p1+n<=(p->nMem+1 - p->nCursor)+1 );
87460 assert( p2>0 && p2+n<=(p->nMem+1 - p->nCursor)+1 );
87461 }
87462 #endif /* SQLITE_DEBUG */
87463 for(i=0; i<n; i++){
87464 idx = aPermute ? aPermute[i] : i;
87465 assert( memIsValid(&aMem[p1+idx]) );
87466 assert( memIsValid(&aMem[p2+idx]) );
87467 REGISTER_TRACE(p1+idx, &aMem[p1+idx]);
87468 REGISTER_TRACE(p2+idx, &aMem[p2+idx]);
87469 assert( i<pKeyInfo->nKeyField );
@@ -87770,11 +87876,11 @@
87770 ** the result is guaranteed to only be used as the argument of a length()
87771 ** or typeof() function, respectively. The loading of large blobs can be
87772 ** skipped for length() and all content loading can be skipped for typeof().
87773 */
87774 case OP_Column: {
87775 int p2; /* column number to retrieve */
87776 VdbeCursor *pC; /* The VDBE cursor */
87777 BtCursor *pCrsr; /* The BTree cursor */
87778 u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */
87779 int len; /* The length of the serialized data for the column */
87780 int i; /* Loop counter */
@@ -87788,11 +87894,11 @@
87788 Mem *pReg; /* PseudoTable input register */
87789
87790 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
87791 pC = p->apCsr[pOp->p1];
87792 assert( pC!=0 );
87793 p2 = pOp->p2;
87794
87795 /* If the cursor cache is stale (meaning it is not currently point at
87796 ** the correct row) then bring it up-to-date by doing the necessary
87797 ** B-Tree seek. */
87798 rc = sqlite3VdbeCursorMoveto(&pC, &p2);
@@ -87915,11 +88021,11 @@
87915 zHdr += sqlite3GetVarint32(zHdr, &t);
87916 pC->aType[i] = t;
87917 offset64 += sqlite3VdbeSerialTypeLen(t);
87918 }
87919 aOffset[++i] = (u32)(offset64 & 0xffffffff);
87920 }while( i<=p2 && zHdr<zEndHdr );
87921
87922 /* The record is corrupt if any of the following are true:
87923 ** (1) the bytes of the header extend past the declared header size
87924 ** (2) the entire header was used but not all data was used
87925 ** (3) the end of the data extends beyond the end of the record.
@@ -88939,11 +89045,11 @@
88939 ** See also: OP_OpenRead, OP_ReopenIdx
88940 */
88941 case OP_ReopenIdx: {
88942 int nField;
88943 KeyInfo *pKeyInfo;
88944 int p2;
88945 int iDb;
88946 int wrFlag;
88947 Btree *pX;
88948 VdbeCursor *pCur;
88949 Db *pDb;
@@ -88970,11 +89076,11 @@
88970 goto abort_due_to_error;
88971 }
88972
88973 nField = 0;
88974 pKeyInfo = 0;
88975 p2 = pOp->p2;
88976 iDb = pOp->p3;
88977 assert( iDb>=0 && iDb<db->nDb );
88978 assert( DbMaskTest(p->btreeMask, iDb) );
88979 pDb = &db->aDb[iDb];
88980 pX = pDb->pBt;
@@ -89142,11 +89248,11 @@
89142 ** opening it. If a transient table is required, just use the
89143 ** automatically created table with root-page 1 (an BLOB_INTKEY table).
89144 */
89145 if( (pCx->pKeyInfo = pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
89146 assert( pOp->p4type==P4_KEYINFO );
89147 rc = sqlite3BtreeCreateTable(pCx->pBtx, (int*)&pCx->pgnoRoot,
89148 BTREE_BLOBKEY | pOp->p5);
89149 if( rc==SQLITE_OK ){
89150 assert( pCx->pgnoRoot==SCHEMA_ROOT+1 );
89151 assert( pKeyInfo->db==db );
89152 assert( pKeyInfo->enc==ENC(db) );
@@ -90406,14 +90512,10 @@
90406 ** generator) then the fix would be to insert a call to
90407 ** sqlite3VdbeCursorMoveto().
90408 */
90409 assert( pC->deferredMoveto==0 );
90410 assert( sqlite3BtreeCursorIsValid(pCrsr) );
90411 #if 0 /* Not required due to the previous to assert() statements */
90412 rc = sqlite3VdbeCursorMoveto(pC);
90413 if( rc!=SQLITE_OK ) goto abort_due_to_error;
90414 #endif
90415
90416 n = sqlite3BtreePayloadSize(pCrsr);
90417 if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
90418 goto too_big;
90419 }
@@ -91179,11 +91281,11 @@
91179 sqlite3VdbeIncrWriteCounter(p, 0);
91180 nChange = 0;
91181 assert( p->readOnly==0 );
91182 assert( DbMaskTest(p->btreeMask, pOp->p2) );
91183 rc = sqlite3BtreeClearTable(
91184 db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &nChange : 0)
91185 );
91186 if( pOp->p3 ){
91187 p->nChange += nChange;
91188 if( pOp->p3>0 ){
91189 assert( memIsValid(&aMem[pOp->p3]) );
@@ -91228,11 +91330,11 @@
91228 ** P1>1. The P3 argument must be 1 (BTREE_INTKEY) for a rowid table
91229 ** it must be 2 (BTREE_BLOBKEY) for an index or WITHOUT ROWID table.
91230 ** The root page number of the new b-tree is stored in register P2.
91231 */
91232 case OP_CreateBtree: { /* out2 */
91233 int pgno;
91234 Db *pDb;
91235
91236 sqlite3VdbeIncrWriteCounter(p, 0);
91237 pOut = out2Prerelease(p, pOp);
91238 pgno = 0;
@@ -91303,10 +91405,11 @@
91303 zSchema = DFLT_SCHEMA_TABLE;
91304 initData.db = db;
91305 initData.iDb = iDb;
91306 initData.pzErrMsg = &p->zErrMsg;
91307 initData.mInitFlags = 0;
 
91308 zSql = sqlite3MPrintf(db,
91309 "SELECT*FROM\"%w\".%s WHERE %s ORDER BY rowid",
91310 db->aDb[iDb].zDbSName, zSchema, pOp->p4.z);
91311 if( zSql==0 ){
91312 rc = SQLITE_NOMEM_BKPT;
@@ -91416,11 +91519,11 @@
91416 **
91417 ** This opcode is used to implement the integrity_check pragma.
91418 */
91419 case OP_IntegrityCk: {
91420 int nRoot; /* Number of tables to check. (Number of root pages.) */
91421 int *aRoot; /* Array of rootpage numbers for tables to be checked */
91422 int nErr; /* Number of errors reported */
91423 char *z; /* Text of the error report */
91424 Mem *pnErr; /* Register keeping track of errors remaining */
91425
91426 assert( p->bIsReader );
@@ -96701,11 +96804,11 @@
96701 }else{
96702 if( i<=2 && pCur->zType==0 ){
96703 Schema *pSchema;
96704 HashElem *k;
96705 int iDb = pOp->p3;
96706 int iRoot = pOp->p2;
96707 sqlite3 *db = pVTab->db;
96708 pSchema = db->aDb[iDb].pSchema;
96709 pCur->zSchema = db->aDb[iDb].zDbSName;
96710 for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){
96711 Table *pTab = (Table*)sqliteHashData(k);
@@ -97288,11 +97391,11 @@
97288 }else{
97289 p->nChunkSize = 8 + MEMJOURNAL_DFLT_FILECHUNKSIZE - sizeof(FileChunk);
97290 assert( MEMJOURNAL_DFLT_FILECHUNKSIZE==fileChunkSize(p->nChunkSize) );
97291 }
97292
97293 p->pMethod = (const sqlite3_io_methods*)&MemJournalMethods;
97294 p->nSpill = nSpill;
97295 p->flags = flags;
97296 p->zJournal = zName;
97297 p->pVfs = pVfs;
97298 return SQLITE_OK;
@@ -97314,11 +97417,11 @@
97314 ** file has not yet been created, create it now.
97315 */
97316 SQLITE_PRIVATE int sqlite3JournalCreate(sqlite3_file *pJfd){
97317 int rc = SQLITE_OK;
97318 MemJournal *p = (MemJournal*)pJfd;
97319 if( p->pMethod==&MemJournalMethods && (
97320 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
97321 p->nSpill>0
97322 #else
97323 /* While this appears to not be possible without ATOMIC_WRITE, the
97324 ** paths are complex, so it seems prudent to leave the test in as
@@ -107581,11 +107684,11 @@
107581 };
107582 int i;
107583 sqlite3 *db = pParse->db;
107584 Db *pDb;
107585 Vdbe *v = sqlite3GetVdbe(pParse);
107586 int aRoot[ArraySize(aTable)];
107587 u8 aCreateTbl[ArraySize(aTable)];
107588 #ifdef SQLITE_ENABLE_STAT4
107589 const int nToOpen = OptimizationEnabled(db,SQLITE_Stat4) ? 2 : 1;
107590 #else
107591 const int nToOpen = 1;
@@ -107610,11 +107713,11 @@
107610 ** of the new table in register pParse->regRoot. This is important
107611 ** because the OpenWrite opcode below will be needing it. */
107612 sqlite3NestedParse(pParse,
107613 "CREATE TABLE %Q.%s(%s)", pDb->zDbSName, zTab, aTable[i].zCols
107614 );
107615 aRoot[i] = pParse->regRoot;
107616 aCreateTbl[i] = OPFLAG_P2ISREG;
107617 }
107618 }else{
107619 /* The table already exists. If zWhere is not NULL, delete all entries
107620 ** associated with the table zWhere. If zWhere is NULL, delete the
@@ -107630,19 +107733,19 @@
107630 }else if( db->xPreUpdateCallback ){
107631 sqlite3NestedParse(pParse, "DELETE FROM %Q.%s", pDb->zDbSName, zTab);
107632 #endif
107633 }else{
107634 /* The sqlite_stat[134] table already exists. Delete all rows. */
107635 sqlite3VdbeAddOp2(v, OP_Clear, aRoot[i], iDb);
107636 }
107637 }
107638 }
107639
107640 /* Open the sqlite_stat[134] tables for writing. */
107641 for(i=0; i<nToOpen; i++){
107642 assert( i<ArraySize(aTable) );
107643 sqlite3VdbeAddOp4Int(v, OP_OpenWrite, iStatCur+i, aRoot[i], iDb, 3);
107644 sqlite3VdbeChangeP5(v, aCreateTbl[i]);
107645 VdbeComment((v, aTable[i].zName));
107646 }
107647 }
107648
@@ -110271,11 +110374,11 @@
110271 ** The TableLock structure is only used by the sqlite3TableLock() and
110272 ** codeTableLocks() functions.
110273 */
110274 struct TableLock {
110275 int iDb; /* The database containing the table to be locked */
110276 int iTab; /* The root page of the table to be locked */
110277 u8 isWriteLock; /* True for write lock. False for a read lock */
110278 const char *zLockName; /* Name of the table */
110279 };
110280
110281 /*
@@ -110289,11 +110392,11 @@
110289 ** codeTableLocks() which occurs during sqlite3FinishCoding().
110290 */
110291 SQLITE_PRIVATE void sqlite3TableLock(
110292 Parse *pParse, /* Parsing context */
110293 int iDb, /* Index of the database containing the table to lock */
110294 int iTab, /* Root page number of the table to be locked */
110295 u8 isWriteLock, /* True for a write lock */
110296 const char *zName /* Name of the table to be locked */
110297 ){
110298 Parse *pToplevel = sqlite3ParseToplevel(pParse);
110299 int i;
@@ -111128,23 +111231,24 @@
111128 const char *zName, /* Name of the object to check */
111129 const char *zType, /* Type of this object */
111130 const char *zTblName /* Parent table name for triggers and indexes */
111131 ){
111132 sqlite3 *db = pParse->db;
111133 if( sqlite3WritableSchema(db) || db->init.imposterTable ){
 
 
 
111134 /* Skip these error checks for writable_schema=ON */
111135 return SQLITE_OK;
111136 }
111137 if( db->init.busy ){
111138 if( sqlite3_stricmp(zType, db->init.azInit[0])
111139 || sqlite3_stricmp(zName, db->init.azInit[1])
111140 || sqlite3_stricmp(zTblName, db->init.azInit[2])
111141 ){
111142 if( sqlite3Config.bExtraSchemaChecks ){
111143 sqlite3ErrorMsg(pParse, ""); /* corruptSchema() will supply the error */
111144 return SQLITE_ERROR;
111145 }
111146 }
111147 }else{
111148 if( (pParse->nested==0 && 0==sqlite3StrNICmp(zName, "sqlite_", 7))
111149 || (sqlite3ReadOnlyShadowTables(db) && sqlite3ShadowTableName(db, zName))
111150 ){
@@ -112354,11 +112458,11 @@
112354 ** table entry. This is only required if currently generating VDBE
112355 ** code for a CREATE TABLE (not when parsing one as part of reading
112356 ** a database schema). */
112357 if( v && pPk->tnum>0 ){
112358 assert( db->init.busy==0 );
112359 sqlite3VdbeChangeOpcode(v, pPk->tnum, OP_Goto);
112360 }
112361
112362 /* The root page of the PRIMARY KEY is the table root page */
112363 pPk->tnum = pTab->tnum;
112364
@@ -113050,11 +113154,11 @@
113050 ** We must continue looping until all tables and indices with
113051 ** rootpage==iFrom have been converted to have a rootpage of iTo
113052 ** in order to be certain that we got the right one.
113053 */
113054 #ifndef SQLITE_OMIT_AUTOVACUUM
113055 SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3 *db, int iDb, int iFrom, int iTo){
113056 HashElem *pElem;
113057 Hash *pHash;
113058 Db *pDb;
113059
113060 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
@@ -113083,11 +113187,11 @@
113083 ** erasing iTable (this can happen with an auto-vacuum database).
113084 */
113085 static void destroyRootPage(Parse *pParse, int iTable, int iDb){
113086 Vdbe *v = sqlite3GetVdbe(pParse);
113087 int r1 = sqlite3GetTempReg(pParse);
113088 if( iTable<2 ) sqlite3ErrorMsg(pParse, "corrupt schema");
113089 sqlite3VdbeAddOp3(v, OP_Destroy, iTable, r1, iDb);
113090 sqlite3MayAbort(pParse);
113091 #ifndef SQLITE_OMIT_AUTOVACUUM
113092 /* OP_Destroy stores an in integer r1. If this integer
113093 ** is non-zero, then it is the root page number of a table moved to
@@ -113127,22 +113231,22 @@
113127 ** and root page 5 happened to be the largest root-page number in the
113128 ** database, then root page 5 would be moved to page 4 by the
113129 ** "OP_Destroy 4 0" opcode. The subsequent "OP_Destroy 5 0" would hit
113130 ** a free-list page.
113131 */
113132 int iTab = pTab->tnum;
113133 int iDestroyed = 0;
113134
113135 while( 1 ){
113136 Index *pIdx;
113137 int iLargest = 0;
113138
113139 if( iDestroyed==0 || iTab<iDestroyed ){
113140 iLargest = iTab;
113141 }
113142 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
113143 int iIdx = pIdx->tnum;
113144 assert( pIdx->pSchema==pTab->pSchema );
113145 if( (iDestroyed==0 || (iIdx<iDestroyed)) && iIdx>iLargest ){
113146 iLargest = iIdx;
113147 }
113148 }
@@ -113561,11 +113665,11 @@
113561 int iTab = pParse->nTab++; /* Btree cursor used for pTab */
113562 int iIdx = pParse->nTab++; /* Btree cursor used for pIndex */
113563 int iSorter; /* Cursor opened by OpenSorter (if in use) */
113564 int addr1; /* Address of top of loop */
113565 int addr2; /* Address to jump to for next iteration */
113566 int tnum; /* Root page of index */
113567 int iPartIdxLabel; /* Jump to this label to skip a row */
113568 Vdbe *v; /* Generate code into this virtual machine */
113569 KeyInfo *pKey; /* KeyInfo for index */
113570 int regRecord; /* Register holding assembled index record */
113571 sqlite3 *db = pParse->db; /* The database connection */
@@ -113582,11 +113686,11 @@
113582 sqlite3TableLock(pParse, iDb, pTab->tnum, 1, pTab->zName);
113583
113584 v = sqlite3GetVdbe(pParse);
113585 if( v==0 ) return;
113586 if( memRootPage>=0 ){
113587 tnum = memRootPage;
113588 }else{
113589 tnum = pIndex->tnum;
113590 }
113591 pKey = sqlite3KeyInfoOfIndex(pParse, pIndex);
113592 assert( pKey!=0 || db->mallocFailed || pParse->nErr );
@@ -113607,11 +113711,11 @@
113607 sqlite3VdbeAddOp2(v, OP_SorterInsert, iSorter, regRecord);
113608 sqlite3ResolvePartIdxLabel(pParse, iPartIdxLabel);
113609 sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1); VdbeCoverage(v);
113610 sqlite3VdbeJumpHere(v, addr1);
113611 if( memRootPage<0 ) sqlite3VdbeAddOp2(v, OP_Clear, tnum, iDb);
113612 sqlite3VdbeAddOp4(v, OP_OpenWrite, iIdx, tnum, iDb,
113613 (char *)pKey, P4_KEYINFO);
113614 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR|((memRootPage>=0)?OPFLAG_P2ISREG:0));
113615
113616 addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0); VdbeCoverage(v);
113617 if( IsUniqueIndex(pIndex) ){
@@ -114216,11 +114320,11 @@
114216 ** doing so, code a Noop instruction and store its address in
114217 ** Index.tnum. This is required in case this index is actually a
114218 ** PRIMARY KEY and the table is actually a WITHOUT ROWID table. In
114219 ** that case the convertToWithoutRowidTable() routine will replace
114220 ** the Noop with a Goto to jump over the VDBE code generated below. */
114221 pIndex->tnum = sqlite3VdbeAddOp0(v, OP_Noop);
114222 sqlite3VdbeAddOp3(v, OP_CreateBtree, iDb, iMem, BTREE_BLOBKEY);
114223
114224 /* Gather the complete text of the CREATE INDEX statement into
114225 ** the zStmt variable
114226 */
@@ -114258,11 +114362,11 @@
114258 sqlite3VdbeAddParseSchemaOp(v, iDb,
114259 sqlite3MPrintf(db, "name='%q' AND type='index'", pIndex->zName));
114260 sqlite3VdbeAddOp2(v, OP_Expire, 0, 1);
114261 }
114262
114263 sqlite3VdbeJumpHere(v, pIndex->tnum);
114264 }
114265 }
114266 if( db->init.busy || pTblName==0 ){
114267 pIndex->pNext = pTab->pIndex;
114268 pTab->pIndex = pIndex;
@@ -120581,11 +120685,11 @@
120581 for(i=1; i<iEnd; i++){
120582 VdbeOp *pOp = sqlite3VdbeGetOp(v, i);
120583 assert( pOp!=0 );
120584 if( pOp->opcode==OP_OpenRead && pOp->p3==iDb ){
120585 Index *pIndex;
120586 int tnum = pOp->p2;
120587 if( tnum==pTab->tnum ){
120588 return 1;
120589 }
120590 for(pIndex=pTab->pIndex; pIndex; pIndex=pIndex->pNext){
120591 if( tnum==pIndex->tnum ){
@@ -126204,17 +126308,23 @@
126204 **
126205 ** Return the number of pages in the specified database.
126206 */
126207 case PragTyp_PAGE_COUNT: {
126208 int iReg;
 
126209 sqlite3CodeVerifySchema(pParse, iDb);
126210 iReg = ++pParse->nMem;
126211 if( sqlite3Tolower(zLeft[0])=='p' ){
126212 sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg);
126213 }else{
126214 sqlite3VdbeAddOp3(v, OP_MaxPgcnt, iDb, iReg,
126215 sqlite3AbsInt32(sqlite3Atoi(zRight)));
 
 
 
 
 
126216 }
126217 sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1);
126218 break;
126219 }
126220
@@ -127113,13 +127223,26 @@
127113 **
127114 ** The "quick_check" is reduced version of
127115 ** integrity_check designed to detect most database corruption
127116 ** without the overhead of cross-checking indexes. Quick_check
127117 ** is linear time wherease integrity_check is O(NlogN).
 
 
 
 
 
 
 
 
 
 
 
 
127118 */
127119 case PragTyp_INTEGRITY_CHECK: {
127120 int i, j, addr, mxErr;
 
127121
127122 int isQuick = (sqlite3Tolower(zLeft[0])=='q');
127123
127124 /* If the PRAGMA command was of the form "PRAGMA <db>.integrity_check",
127125 ** then iDb is set to the index of the database identified by <db>.
@@ -127138,13 +127261,17 @@
127138 pParse->nMem = 6;
127139
127140 /* Set the maximum error count */
127141 mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
127142 if( zRight ){
127143 sqlite3GetInt32(zRight, &mxErr);
127144 if( mxErr<=0 ){
127145 mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
 
 
 
 
127146 }
127147 }
127148 sqlite3VdbeAddOp2(v, OP_Integer, mxErr-1, 1); /* reg[1] holds errors left */
127149
127150 /* Do an integrity check on each database file */
@@ -127169,19 +127296,25 @@
127169 pTbls = &db->aDb[i].pSchema->tblHash;
127170 for(cnt=0, x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
127171 Table *pTab = sqliteHashData(x); /* Current table */
127172 Index *pIdx; /* An index on pTab */
127173 int nIdx; /* Number of indexes on pTab */
 
127174 if( HasRowid(pTab) ) cnt++;
127175 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){ cnt++; }
127176 if( nIdx>mxIdx ) mxIdx = nIdx;
127177 }
 
 
127178 aRoot = sqlite3DbMallocRawNN(db, sizeof(int)*(cnt+1));
127179 if( aRoot==0 ) break;
127180 for(cnt=0, x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
 
 
127181 Table *pTab = sqliteHashData(x);
127182 Index *pIdx;
 
127183 if( HasRowid(pTab) ) aRoot[++cnt] = pTab->tnum;
127184 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
127185 aRoot[++cnt] = pIdx->tnum;
127186 }
127187 }
@@ -127211,10 +127344,11 @@
127211 int loopTop;
127212 int iDataCur, iIdxCur;
127213 int r1 = -1;
127214
127215 if( pTab->tnum<1 ) continue; /* Skip VIEWs or VIRTUAL TABLEs */
 
127216 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
127217 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0,
127218 1, 0, &iDataCur, &iIdxCur);
127219 /* reg[7] counts the number of entries in the table.
127220 ** reg[8+i] counts the number of entries in the i-th index
@@ -128272,11 +128406,17 @@
128272 sqlite3_stmt *pStmt;
128273 TESTONLY(int rcp); /* Return code from sqlite3_prepare() */
128274
128275 assert( db->init.busy );
128276 db->init.iDb = iDb;
128277 db->init.newTnum = sqlite3Atoi(argv[3]);
 
 
 
 
 
 
128278 db->init.orphanTrigger = 0;
128279 db->init.azInit = argv;
128280 pStmt = 0;
128281 TESTONLY(rcp = ) sqlite3Prepare(db, argv[4], -1, 0, 0, &pStmt, 0);
128282 rc = db->errCode;
@@ -128305,16 +128445,21 @@
128305 ** been created when we processed the CREATE TABLE. All we have
128306 ** to do here is record the root page number for that index.
128307 */
128308 Index *pIndex;
128309 pIndex = sqlite3FindIndex(db, argv[1], db->aDb[iDb].zDbSName);
128310 if( pIndex==0
128311 || sqlite3GetInt32(argv[3],&pIndex->tnum)==0
 
 
128312 || pIndex->tnum<2
 
128313 || sqlite3IndexHasDuplicateRootPage(pIndex)
128314 ){
128315 corruptSchema(pData, argv[1], pIndex?"invalid rootpage":"orphan index");
 
 
128316 }
128317 }
128318 return 0;
128319 }
128320
@@ -128364,10 +128509,11 @@
128364 initData.iDb = iDb;
128365 initData.rc = SQLITE_OK;
128366 initData.pzErrMsg = pzErrMsg;
128367 initData.mInitFlags = mFlags;
128368 initData.nInitRow = 0;
 
128369 sqlite3InitCallback(&initData, 5, (char **)azArg, 0);
128370 db->mDbFlags &= mask;
128371 if( initData.rc ){
128372 rc = initData.rc;
128373 goto error_out;
@@ -128486,10 +128632,11 @@
128486 }
128487
128488 /* Read the schema information out of the schema tables
128489 */
128490 assert( db->init.busy );
 
128491 {
128492 char *zSql;
128493 zSql = sqlite3MPrintf(db,
128494 "SELECT*FROM\"%w\".%s ORDER BY rowid",
128495 db->aDb[iDb].zDbSName, zSchemaTabName);
@@ -129368,12 +129515,14 @@
129368 ** Return the index of a column in a table. Return -1 if the column
129369 ** is not contained in the table.
129370 */
129371 static int columnIndex(Table *pTab, const char *zCol){
129372 int i;
129373 for(i=0; i<pTab->nCol; i++){
129374 if( sqlite3StrICmp(pTab->aCol[i].zName, zCol)==0 ) return i;
 
 
129375 }
129376 return -1;
129377 }
129378
129379 /*
@@ -130231,20 +130380,24 @@
130231 sqlite3ReleaseTempRange(pParse, r1, nPrefixReg+1);
130232 break;
130233 }
130234
130235 case SRT_Upfrom: {
130236 #ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
130237 if( pSort ){
130238 pushOntoSorter(
130239 pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg);
130240 }else
130241 #endif
130242 {
130243 int i2 = pDest->iSDParm2;
130244 int r1 = sqlite3GetTempReg(pParse);
130245 sqlite3VdbeAddOp3(v, OP_MakeRecord,regResult+(i2<0),nResultCol-(i2<0),r1);
 
 
 
 
 
 
 
130246 if( i2<0 ){
130247 sqlite3VdbeAddOp3(v, OP_Insert, iParm, r1, regResult);
130248 }else{
130249 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, r1, regResult, i2);
130250 }
@@ -130682,11 +130835,10 @@
130682 case SRT_Mem: {
130683 /* The LIMIT clause will terminate the loop for us */
130684 break;
130685 }
130686 #endif
130687 #ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
130688 case SRT_Upfrom: {
130689 int i2 = pDest->iSDParm2;
130690 int r1 = sqlite3GetTempReg(pParse);
130691 sqlite3VdbeAddOp3(v, OP_MakeRecord,regRow+(i2<0),nColumn-(i2<0),r1);
130692 if( i2<0 ){
@@ -130694,11 +130846,10 @@
130694 }else{
130695 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, r1, regRow, i2);
130696 }
130697 break;
130698 }
130699 #endif
130700 default: {
130701 assert( eDest==SRT_Output || eDest==SRT_Coroutine );
130702 testcase( eDest==SRT_Output );
130703 testcase( eDest==SRT_Coroutine );
130704 if( eDest==SRT_Output ){
@@ -132281,11 +132432,11 @@
132281 KeyInfo *pKeyDup = 0; /* Comparison information for duplicate removal */
132282 KeyInfo *pKeyMerge; /* Comparison information for merging rows */
132283 sqlite3 *db; /* Database connection */
132284 ExprList *pOrderBy; /* The ORDER BY clause */
132285 int nOrderBy; /* Number of terms in the ORDER BY clause */
132286 int *aPermute; /* Mapping from ORDER BY terms to result set columns */
132287
132288 assert( p->pOrderBy!=0 );
132289 assert( pKeyDup==0 ); /* "Managed" code needs this. Ticket #3382. */
132290 db = pParse->db;
132291 v = pParse->pVdbe;
@@ -132330,11 +132481,11 @@
132330 ** row of results comes from selectA or selectB. Also add explicit
132331 ** collations to the ORDER BY clause terms so that when the subqueries
132332 ** to the right and the left are evaluated, they use the correct
132333 ** collation.
132334 */
132335 aPermute = sqlite3DbMallocRawNN(db, sizeof(int)*(nOrderBy + 1));
132336 if( aPermute ){
132337 struct ExprList_item *pItem;
132338 aPermute[0] = nOrderBy;
132339 for(i=1, pItem=pOrderBy->a; i<=nOrderBy; i++, pItem++){
132340 assert( pItem->u.x.iOrderByCol>0 );
@@ -135823,11 +135974,11 @@
135823 const int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
135824 const int iCsr = pParse->nTab++; /* Cursor to scan b-tree */
135825 Index *pIdx; /* Iterator variable */
135826 KeyInfo *pKeyInfo = 0; /* Keyinfo for scanned index */
135827 Index *pBest = 0; /* Best index found so far */
135828 int iRoot = pTab->tnum; /* Root page of scanned b-tree */
135829
135830 sqlite3CodeVerifySchema(pParse, iDb);
135831 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
135832
135833 /* Search for the index that has the lowest scan cost.
@@ -135855,11 +136006,11 @@
135855 iRoot = pBest->tnum;
135856 pKeyInfo = sqlite3KeyInfoOfIndex(pParse, pBest);
135857 }
135858
135859 /* Open a read-only cursor, execute the OP_Count, close the cursor. */
135860 sqlite3VdbeAddOp4Int(v, OP_OpenRead, iCsr, iRoot, iDb, 1);
135861 if( pKeyInfo ){
135862 sqlite3VdbeChangeP4(v, -1, (char *)pKeyInfo, P4_KEYINFO);
135863 }
135864 sqlite3VdbeAddOp2(v, OP_Count, iCsr, pAggInfo->aFunc[0].iMem);
135865 sqlite3VdbeAddOp1(v, OP_Close, iCsr);
@@ -142375,11 +142526,11 @@
142375 if( (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)
142376 && DbMaskAllZero(sqlite3ParseToplevel(pParse)->writeMask)
142377 ){
142378 int i;
142379 Table *pTab = pIdx->pTable;
142380 int *ai = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*(pTab->nCol+1));
142381 if( ai ){
142382 ai[0] = pTab->nCol;
142383 for(i=0; i<pIdx->nColumn-1; i++){
142384 int x1, x2;
142385 assert( pIdx->aiColumn[i]<pTab->nCol );
@@ -164889,10 +165040,16 @@
164889 /* sqlite3_test_control(SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS, int);
164890 **
164891 ** Set or clear a flag that causes SQLite to verify that type, name,
164892 ** and tbl_name fields of the sqlite_schema table. This is normally
164893 ** on, but it is sometimes useful to turn it off for testing.
 
 
 
 
 
 
164894 */
164895 case SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS: {
164896 sqlite3GlobalConfig.bExtraSchemaChecks = va_arg(ap, int);
164897 break;
164898 }
@@ -172498,11 +172655,12 @@
172498 ** do {...} while( pRoot->iDocid<iDocid && rc==SQLITE_OK );
172499 */
172500 fts3EvalRestart(pCsr, pRoot, &rc);
172501 do {
172502 fts3EvalNextRow(pCsr, pRoot, &rc);
172503 assert( pRoot->bEof==0 );
 
172504 }while( pRoot->iDocid!=iDocid && rc==SQLITE_OK );
172505 }
172506 }
172507 return rc;
172508 }
@@ -225482,11 +225640,11 @@
225482 int nArg, /* Number of args */
225483 sqlite3_value **apUnused /* Function arguments */
225484 ){
225485 assert( nArg==0 );
225486 UNUSED_PARAM2(nArg, apUnused);
225487 sqlite3_result_text(pCtx, "fts5: 2020-07-18 18:59:11 020dbfa2aef20e5872cc3e785d99f45903843401292114b5092b9c8aa829b9c3", -1, SQLITE_TRANSIENT);
225488 }
225489
225490 /*
225491 ** Return true if zName is the extension on one of the shadow tables used
225492 ** by this module.
@@ -230265,12 +230423,12 @@
230265 }
230266 #endif /* SQLITE_CORE */
230267 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
230268
230269 /************** End of stmt.c ************************************************/
230270 #if __LINE__!=230270
230271 #undef SQLITE_SOURCE_ID
230272 #define SQLITE_SOURCE_ID "2020-07-18 18:59:11 020dbfa2aef20e5872cc3e785d99f45903843401292114b5092b9c8aa829alt2"
230273 #endif
230274 /* Return the source-id for this library */
230275 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
230276 /************************** End of sqlite3.c ******************************/
230277
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1162,11 +1162,11 @@
1162 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1163 ** [sqlite_version()] and [sqlite_source_id()].
1164 */
1165 #define SQLITE_VERSION "3.33.0"
1166 #define SQLITE_VERSION_NUMBER 3033000
1167 #define SQLITE_SOURCE_ID "2020-07-30 17:37:49 96e3dba2ed3ab0c5b2ecf65a3408633e0767c884d48c270e9ef10ab9fa3ec051"
1168
1169 /*
1170 ** CAPI3REF: Run-Time Library Version Numbers
1171 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1172 **
@@ -14735,10 +14735,257 @@
14735 /*
14736 ** Defer sourcing vdbe.h and btree.h until after the "u8" and
14737 ** "BusyHandler" typedefs. vdbe.h also requires a few of the opaque
14738 ** pointer types (i.e. FuncDef) defined above.
14739 */
14740 /************** Include pager.h in the middle of sqliteInt.h *****************/
14741 /************** Begin file pager.h *******************************************/
14742 /*
14743 ** 2001 September 15
14744 **
14745 ** The author disclaims copyright to this source code. In place of
14746 ** a legal notice, here is a blessing:
14747 **
14748 ** May you do good and not evil.
14749 ** May you find forgiveness for yourself and forgive others.
14750 ** May you share freely, never taking more than you give.
14751 **
14752 *************************************************************************
14753 ** This header file defines the interface that the sqlite page cache
14754 ** subsystem. The page cache subsystem reads and writes a file a page
14755 ** at a time and provides a journal for rollback.
14756 */
14757
14758 #ifndef SQLITE_PAGER_H
14759 #define SQLITE_PAGER_H
14760
14761 /*
14762 ** Default maximum size for persistent journal files. A negative
14763 ** value means no limit. This value may be overridden using the
14764 ** sqlite3PagerJournalSizeLimit() API. See also "PRAGMA journal_size_limit".
14765 */
14766 #ifndef SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT
14767 #define SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT -1
14768 #endif
14769
14770 /*
14771 ** The type used to represent a page number. The first page in a file
14772 ** is called page 1. 0 is used to represent "not a page".
14773 */
14774 typedef u32 Pgno;
14775
14776 /*
14777 ** Each open file is managed by a separate instance of the "Pager" structure.
14778 */
14779 typedef struct Pager Pager;
14780
14781 /*
14782 ** Handle type for pages.
14783 */
14784 typedef struct PgHdr DbPage;
14785
14786 /*
14787 ** Page number PAGER_MJ_PGNO is never used in an SQLite database (it is
14788 ** reserved for working around a windows/posix incompatibility). It is
14789 ** used in the journal to signify that the remainder of the journal file
14790 ** is devoted to storing a super-journal name - there are no more pages to
14791 ** roll back. See comments for function writeSuperJournal() in pager.c
14792 ** for details.
14793 */
14794 #define PAGER_MJ_PGNO(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1))
14795
14796 /*
14797 ** Allowed values for the flags parameter to sqlite3PagerOpen().
14798 **
14799 ** NOTE: These values must match the corresponding BTREE_ values in btree.h.
14800 */
14801 #define PAGER_OMIT_JOURNAL 0x0001 /* Do not use a rollback journal */
14802 #define PAGER_MEMORY 0x0002 /* In-memory database */
14803
14804 /*
14805 ** Valid values for the second argument to sqlite3PagerLockingMode().
14806 */
14807 #define PAGER_LOCKINGMODE_QUERY -1
14808 #define PAGER_LOCKINGMODE_NORMAL 0
14809 #define PAGER_LOCKINGMODE_EXCLUSIVE 1
14810
14811 /*
14812 ** Numeric constants that encode the journalmode.
14813 **
14814 ** The numeric values encoded here (other than PAGER_JOURNALMODE_QUERY)
14815 ** are exposed in the API via the "PRAGMA journal_mode" command and
14816 ** therefore cannot be changed without a compatibility break.
14817 */
14818 #define PAGER_JOURNALMODE_QUERY (-1) /* Query the value of journalmode */
14819 #define PAGER_JOURNALMODE_DELETE 0 /* Commit by deleting journal file */
14820 #define PAGER_JOURNALMODE_PERSIST 1 /* Commit by zeroing journal header */
14821 #define PAGER_JOURNALMODE_OFF 2 /* Journal omitted. */
14822 #define PAGER_JOURNALMODE_TRUNCATE 3 /* Commit by truncating journal */
14823 #define PAGER_JOURNALMODE_MEMORY 4 /* In-memory journal file */
14824 #define PAGER_JOURNALMODE_WAL 5 /* Use write-ahead logging */
14825
14826 /*
14827 ** Flags that make up the mask passed to sqlite3PagerGet().
14828 */
14829 #define PAGER_GET_NOCONTENT 0x01 /* Do not load data from disk */
14830 #define PAGER_GET_READONLY 0x02 /* Read-only page is acceptable */
14831
14832 /*
14833 ** Flags for sqlite3PagerSetFlags()
14834 **
14835 ** Value constraints (enforced via assert()):
14836 ** PAGER_FULLFSYNC == SQLITE_FullFSync
14837 ** PAGER_CKPT_FULLFSYNC == SQLITE_CkptFullFSync
14838 ** PAGER_CACHE_SPILL == SQLITE_CacheSpill
14839 */
14840 #define PAGER_SYNCHRONOUS_OFF 0x01 /* PRAGMA synchronous=OFF */
14841 #define PAGER_SYNCHRONOUS_NORMAL 0x02 /* PRAGMA synchronous=NORMAL */
14842 #define PAGER_SYNCHRONOUS_FULL 0x03 /* PRAGMA synchronous=FULL */
14843 #define PAGER_SYNCHRONOUS_EXTRA 0x04 /* PRAGMA synchronous=EXTRA */
14844 #define PAGER_SYNCHRONOUS_MASK 0x07 /* Mask for four values above */
14845 #define PAGER_FULLFSYNC 0x08 /* PRAGMA fullfsync=ON */
14846 #define PAGER_CKPT_FULLFSYNC 0x10 /* PRAGMA checkpoint_fullfsync=ON */
14847 #define PAGER_CACHESPILL 0x20 /* PRAGMA cache_spill=ON */
14848 #define PAGER_FLAGS_MASK 0x38 /* All above except SYNCHRONOUS */
14849
14850 /*
14851 ** The remainder of this file contains the declarations of the functions
14852 ** that make up the Pager sub-system API. See source code comments for
14853 ** a detailed description of each routine.
14854 */
14855
14856 /* Open and close a Pager connection. */
14857 SQLITE_PRIVATE int sqlite3PagerOpen(
14858 sqlite3_vfs*,
14859 Pager **ppPager,
14860 const char*,
14861 int,
14862 int,
14863 int,
14864 void(*)(DbPage*)
14865 );
14866 SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager, sqlite3*);
14867 SQLITE_PRIVATE int sqlite3PagerReadFileheader(Pager*, int, unsigned char*);
14868
14869 /* Functions used to configure a Pager object. */
14870 SQLITE_PRIVATE void sqlite3PagerSetBusyHandler(Pager*, int(*)(void *), void *);
14871 SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager*, u32*, int);
14872 SQLITE_PRIVATE Pgno sqlite3PagerMaxPageCount(Pager*, Pgno);
14873 SQLITE_PRIVATE void sqlite3PagerSetCachesize(Pager*, int);
14874 SQLITE_PRIVATE int sqlite3PagerSetSpillsize(Pager*, int);
14875 SQLITE_PRIVATE void sqlite3PagerSetMmapLimit(Pager *, sqlite3_int64);
14876 SQLITE_PRIVATE void sqlite3PagerShrink(Pager*);
14877 SQLITE_PRIVATE void sqlite3PagerSetFlags(Pager*,unsigned);
14878 SQLITE_PRIVATE int sqlite3PagerLockingMode(Pager *, int);
14879 SQLITE_PRIVATE int sqlite3PagerSetJournalMode(Pager *, int);
14880 SQLITE_PRIVATE int sqlite3PagerGetJournalMode(Pager*);
14881 SQLITE_PRIVATE int sqlite3PagerOkToChangeJournalMode(Pager*);
14882 SQLITE_PRIVATE i64 sqlite3PagerJournalSizeLimit(Pager *, i64);
14883 SQLITE_PRIVATE sqlite3_backup **sqlite3PagerBackupPtr(Pager*);
14884 SQLITE_PRIVATE int sqlite3PagerFlush(Pager*);
14885
14886 /* Functions used to obtain and release page references. */
14887 SQLITE_PRIVATE int sqlite3PagerGet(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag);
14888 SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno);
14889 SQLITE_PRIVATE void sqlite3PagerRef(DbPage*);
14890 SQLITE_PRIVATE void sqlite3PagerUnref(DbPage*);
14891 SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage*);
14892 SQLITE_PRIVATE void sqlite3PagerUnrefPageOne(DbPage*);
14893
14894 /* Operations on page references. */
14895 SQLITE_PRIVATE int sqlite3PagerWrite(DbPage*);
14896 SQLITE_PRIVATE void sqlite3PagerDontWrite(DbPage*);
14897 SQLITE_PRIVATE int sqlite3PagerMovepage(Pager*,DbPage*,Pgno,int);
14898 SQLITE_PRIVATE int sqlite3PagerPageRefcount(DbPage*);
14899 SQLITE_PRIVATE void *sqlite3PagerGetData(DbPage *);
14900 SQLITE_PRIVATE void *sqlite3PagerGetExtra(DbPage *);
14901
14902 /* Functions used to manage pager transactions and savepoints. */
14903 SQLITE_PRIVATE void sqlite3PagerPagecount(Pager*, int*);
14904 SQLITE_PRIVATE int sqlite3PagerBegin(Pager*, int exFlag, int);
14905 SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zSuper, int);
14906 SQLITE_PRIVATE int sqlite3PagerExclusiveLock(Pager*);
14907 SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zSuper);
14908 SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager*);
14909 SQLITE_PRIVATE int sqlite3PagerRollback(Pager*);
14910 SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int n);
14911 SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint);
14912 SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager);
14913
14914 #ifndef SQLITE_OMIT_WAL
14915 SQLITE_PRIVATE int sqlite3PagerCheckpoint(Pager *pPager, sqlite3*, int, int*, int*);
14916 SQLITE_PRIVATE int sqlite3PagerWalSupported(Pager *pPager);
14917 SQLITE_PRIVATE int sqlite3PagerWalCallback(Pager *pPager);
14918 SQLITE_PRIVATE int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen);
14919 SQLITE_PRIVATE int sqlite3PagerCloseWal(Pager *pPager, sqlite3*);
14920 # ifdef SQLITE_ENABLE_SNAPSHOT
14921 SQLITE_PRIVATE int sqlite3PagerSnapshotGet(Pager*, sqlite3_snapshot **ppSnapshot);
14922 SQLITE_PRIVATE int sqlite3PagerSnapshotOpen(Pager*, sqlite3_snapshot *pSnapshot);
14923 SQLITE_PRIVATE int sqlite3PagerSnapshotRecover(Pager *pPager);
14924 SQLITE_PRIVATE int sqlite3PagerSnapshotCheck(Pager *pPager, sqlite3_snapshot *pSnapshot);
14925 SQLITE_PRIVATE void sqlite3PagerSnapshotUnlock(Pager *pPager);
14926 # endif
14927 #endif
14928
14929 #if !defined(SQLITE_OMIT_WAL) && defined(SQLITE_ENABLE_SETLK_TIMEOUT)
14930 SQLITE_PRIVATE int sqlite3PagerWalWriteLock(Pager*, int);
14931 SQLITE_PRIVATE void sqlite3PagerWalDb(Pager*, sqlite3*);
14932 #else
14933 # define sqlite3PagerWalWriteLock(y,z) SQLITE_OK
14934 # define sqlite3PagerWalDb(x,y)
14935 #endif
14936
14937 #ifdef SQLITE_DIRECT_OVERFLOW_READ
14938 SQLITE_PRIVATE int sqlite3PagerDirectReadOk(Pager *pPager, Pgno pgno);
14939 #endif
14940
14941 #ifdef SQLITE_ENABLE_ZIPVFS
14942 SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager);
14943 #endif
14944
14945 /* Functions used to query pager state and configuration. */
14946 SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*);
14947 SQLITE_PRIVATE u32 sqlite3PagerDataVersion(Pager*);
14948 #ifdef SQLITE_DEBUG
14949 SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
14950 #endif
14951 SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*);
14952 SQLITE_PRIVATE const char *sqlite3PagerFilename(const Pager*, int);
14953 SQLITE_PRIVATE sqlite3_vfs *sqlite3PagerVfs(Pager*);
14954 SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*);
14955 SQLITE_PRIVATE sqlite3_file *sqlite3PagerJrnlFile(Pager*);
14956 SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*);
14957 SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*);
14958 SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager*);
14959 SQLITE_PRIVATE void sqlite3PagerCacheStat(Pager *, int, int, int *);
14960 SQLITE_PRIVATE void sqlite3PagerClearCache(Pager*);
14961 SQLITE_PRIVATE int sqlite3SectorSize(sqlite3_file *);
14962
14963 /* Functions used to truncate the database file. */
14964 SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno);
14965
14966 SQLITE_PRIVATE void sqlite3PagerRekey(DbPage*, Pgno, u16);
14967
14968 /* Functions to support testing and debugging. */
14969 #if !defined(NDEBUG) || defined(SQLITE_TEST)
14970 SQLITE_PRIVATE Pgno sqlite3PagerPagenumber(DbPage*);
14971 SQLITE_PRIVATE int sqlite3PagerIswriteable(DbPage*);
14972 #endif
14973 #ifdef SQLITE_TEST
14974 SQLITE_PRIVATE int *sqlite3PagerStats(Pager*);
14975 SQLITE_PRIVATE void sqlite3PagerRefdump(Pager*);
14976 void disable_simulated_io_errors(void);
14977 void enable_simulated_io_errors(void);
14978 #else
14979 # define disable_simulated_io_errors()
14980 # define enable_simulated_io_errors()
14981 #endif
14982
14983 #endif /* SQLITE_PAGER_H */
14984
14985 /************** End of pager.h ***********************************************/
14986 /************** Continuing where we left off in sqliteInt.h ******************/
14987 /************** Include btree.h in the middle of sqliteInt.h *****************/
14988 /************** Begin file btree.h *******************************************/
14989 /*
14990 ** 2001 September 15
14991 **
@@ -14810,12 +15057,12 @@
15057 SQLITE_PRIVATE int sqlite3BtreeSetMmapLimit(Btree*,sqlite3_int64);
15058 #endif
15059 SQLITE_PRIVATE int sqlite3BtreeSetPagerFlags(Btree*,unsigned);
15060 SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve, int eFix);
15061 SQLITE_PRIVATE int sqlite3BtreeGetPageSize(Btree*);
15062 SQLITE_PRIVATE Pgno sqlite3BtreeMaxPageCount(Btree*,Pgno);
15063 SQLITE_PRIVATE Pgno sqlite3BtreeLastPage(Btree*);
15064 SQLITE_PRIVATE int sqlite3BtreeSecureDelete(Btree*,int);
15065 SQLITE_PRIVATE int sqlite3BtreeGetRequestedReserve(Btree*);
15066 SQLITE_PRIVATE int sqlite3BtreeGetReserveNoMutex(Btree *p);
15067 SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum(Btree *, int);
15068 SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *);
@@ -14823,11 +15070,11 @@
15070 SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree*, const char*);
15071 SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree*, int);
15072 SQLITE_PRIVATE int sqlite3BtreeCommit(Btree*);
15073 SQLITE_PRIVATE int sqlite3BtreeRollback(Btree*,int,int);
15074 SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree*,int);
15075 SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree*, Pgno*, int flags);
15076 SQLITE_PRIVATE int sqlite3BtreeIsInTrans(Btree*);
15077 SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree*);
15078 SQLITE_PRIVATE int sqlite3BtreeIsInBackup(Btree*);
15079 SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *, int, void(*)(void *));
15080 SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *pBtree);
@@ -14964,11 +15211,11 @@
15211 #define BTREE_WRCSR 0x00000004 /* read-write cursor */
15212 #define BTREE_FORDELETE 0x00000008 /* Cursor is for seek/delete only */
15213
15214 SQLITE_PRIVATE int sqlite3BtreeCursor(
15215 Btree*, /* BTree containing table to open */
15216 Pgno iTable, /* Index of root page */
15217 int wrFlag, /* 1 for writing. 0 for read-only */
15218 struct KeyInfo*, /* First argument to compare function */
15219 BtCursor *pCursor /* Space to write cursor structure */
15220 );
15221 SQLITE_PRIVATE BtCursor *sqlite3BtreeFakeValidCursor(void);
@@ -15055,11 +15302,11 @@
15302 SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*);
15303 SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt);
15304 SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*);
15305 SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeMaxRecordSize(BtCursor*);
15306
15307 SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(sqlite3*,Btree*,Pgno*aRoot,int nRoot,int,int*);
15308 SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
15309 SQLITE_PRIVATE i64 sqlite3BtreeRowCountEst(BtCursor*);
15310
15311 #ifndef SQLITE_OMIT_INCRBLOB
15312 SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor*, u32 offset, u32 amt, void*);
@@ -15192,11 +15439,11 @@
15439 sqlite3_context *pCtx; /* Used when p4type is P4_FUNCCTX */
15440 CollSeq *pColl; /* Used when p4type is P4_COLLSEQ */
15441 Mem *pMem; /* Used when p4type is P4_MEM */
15442 VTable *pVtab; /* Used when p4type is P4_VTAB */
15443 KeyInfo *pKeyInfo; /* Used when p4type is P4_KEYINFO */
15444 u32 *ai; /* Used when p4type is P4_INTARRAY */
15445 SubProgram *pProgram; /* Used when p4type is P4_SUBPROGRAM */
15446 Table *pTab; /* Used when p4type is P4_TABLE */
15447 #ifdef SQLITE_ENABLE_CURSOR_HINTS
15448 Expr *pExpr; /* Used when p4type is P4_EXPR */
15449 #endif
@@ -15756,257 +16003,10 @@
16003 #endif
16004
16005 #endif /* SQLITE_VDBE_H */
16006
16007 /************** End of vdbe.h ************************************************/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16008 /************** Continuing where we left off in sqliteInt.h ******************/
16009 /************** Include pcache.h in the middle of sqliteInt.h ****************/
16010 /************** Begin file pcache.h ******************************************/
16011 /*
16012 ** 2008 August 05
@@ -16843,11 +16843,11 @@
16843 int nChange; /* Value returned by sqlite3_changes() */
16844 int nTotalChange; /* Value returned by sqlite3_total_changes() */
16845 int aLimit[SQLITE_N_LIMIT]; /* Limits */
16846 int nMaxSorterMmap; /* Maximum size of regions mapped by sorter */
16847 struct sqlite3InitInfo { /* Information used during initialization */
16848 Pgno newTnum; /* Rootpage of table being initialized */
16849 u8 iDb; /* Which db file is being initialized */
16850 u8 busy; /* TRUE if currently initializing */
16851 unsigned orphanTrigger : 1; /* Last statement is orphaned TEMP trigger */
16852 unsigned imposterTable : 1; /* Building an imposter table */
16853 unsigned reopenMemdb : 1; /* ATTACH is really a reopen using MemDB */
@@ -17482,11 +17482,11 @@
17482 Select *pSelect; /* NULL for tables. Points to definition if a view. */
17483 FKey *pFKey; /* Linked list of all foreign keys in this table */
17484 char *zColAff; /* String defining the affinity of each column */
17485 ExprList *pCheck; /* All CHECK constraints */
17486 /* ... also used as column name list in a VIEW */
17487 Pgno tnum; /* Root BTree page for this table */
17488 u32 nTabRef; /* Number of pointers to this Table */
17489 u32 tabFlags; /* Mask of TF_* values */
17490 i16 iPKey; /* If not negative, use aCol[iPKey] as the rowid */
17491 i16 nCol; /* Number of columns in this table */
17492 i16 nNVCol; /* Number of columns that are not VIRTUAL */
@@ -17775,11 +17775,11 @@
17775 Schema *pSchema; /* Schema containing this index */
17776 u8 *aSortOrder; /* for each column: True==DESC, False==ASC */
17777 const char **azColl; /* Array of collation sequence names for index */
17778 Expr *pPartIdxWhere; /* WHERE clause for partial indices */
17779 ExprList *aColExpr; /* Column expressions */
17780 Pgno tnum; /* DB Page containing root of this index */
17781 LogEst szIdxRow; /* Estimated average row size in bytes */
17782 u16 nKeyCol; /* Number of columns forming the key */
17783 u16 nColumn; /* Number of columns stored in the index */
17784 u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
17785 unsigned idxType:2; /* 0:Normal 1:UNIQUE, 2:PRIMARY KEY, 3:IPK */
@@ -18990,10 +18990,11 @@
18990 char **pzErrMsg; /* Error message stored here */
18991 int iDb; /* 0 for main database. 1 for TEMP, 2.. for ATTACHed */
18992 int rc; /* Result code stored here */
18993 u32 mInitFlags; /* Flags controlling error messages */
18994 u32 nInitRow; /* Number of rows processed */
18995 Pgno mxPage; /* Maximum page number. 0 for no limit. */
18996 } InitData;
18997
18998 /*
18999 ** Allowed values for mInitFlags
19000 */
@@ -19823,12 +19824,14 @@
19824 SQLITE_PRIVATE int sqlite3FixSelect(DbFixer*, Select*);
19825 SQLITE_PRIVATE int sqlite3FixExpr(DbFixer*, Expr*);
19826 SQLITE_PRIVATE int sqlite3FixExprList(DbFixer*, ExprList*);
19827 SQLITE_PRIVATE int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
19828 SQLITE_PRIVATE int sqlite3RealSameAsInt(double,sqlite3_int64);
19829 SQLITE_PRIVATE void sqlite3Int64ToText(i64,char*);
19830 SQLITE_PRIVATE int sqlite3AtoF(const char *z, double*, int, u8);
19831 SQLITE_PRIVATE int sqlite3GetInt32(const char *, int*);
19832 SQLITE_PRIVATE int sqlite3GetUInt32(const char*, u32*);
19833 SQLITE_PRIVATE int sqlite3Atoi(const char*);
19834 #ifndef SQLITE_OMIT_UTF16
19835 SQLITE_PRIVATE int sqlite3Utf16ByteLen(const void *pData, int nChar);
19836 #endif
19837 SQLITE_PRIVATE int sqlite3Utf8CharLen(const char *pData, int nByte);
@@ -19952,11 +19955,11 @@
19955 #endif
19956 #endif /* SQLITE_AMALGAMATION */
19957 #ifdef VDBE_PROFILE
19958 SQLITE_PRIVATE sqlite3_uint64 sqlite3NProfileCnt;
19959 #endif
19960 SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3*, int, Pgno, Pgno);
19961 SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*);
19962 SQLITE_PRIVATE void sqlite3AlterFunctions(void);
19963 SQLITE_PRIVATE void sqlite3AlterRenameTable(Parse*, SrcList*, Token*);
19964 SQLITE_PRIVATE void sqlite3AlterRenameColumn(Parse*, SrcList*, Token*, Token*);
19965 SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *, int *);
@@ -20066,11 +20069,11 @@
20069 #else
20070 # define sqlite3CloseExtensions(X)
20071 #endif
20072
20073 #ifndef SQLITE_OMIT_SHARED_CACHE
20074 SQLITE_PRIVATE void sqlite3TableLock(Parse *, int, Pgno, u8, const char *);
20075 #else
20076 #define sqlite3TableLock(v,w,x,y,z)
20077 #endif
20078
20079 #ifdef SQLITE_TEST
@@ -20788,11 +20791,11 @@
20791 Bool useRandomRowid:1; /* Generate new record numbers semi-randomly */
20792 Bool isOrdered:1; /* True if the table is not BTREE_UNORDERED */
20793 Bool seekHit:1; /* See the OP_SeekHit and OP_IfNoHope opcodes */
20794 Btree *pBtx; /* Separate file holding temporary table */
20795 i64 seqCount; /* Sequence counter */
20796 u32 *aAltMap; /* Mapping from table to index column numbers */
20797
20798 /* Cached OP_Column parse information is only valid if cacheStatus matches
20799 ** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
20800 ** CACHE_STALE (0) and so setting cacheStatus=CACHE_STALE guarantees that
20801 ** the cache is out of date. */
@@ -21184,11 +21187,11 @@
21187 */
21188 SQLITE_PRIVATE void sqlite3VdbeError(Vdbe*, const char *, ...);
21189 SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*);
21190 void sqliteVdbePopStack(Vdbe*,int);
21191 SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeFinishMoveto(VdbeCursor*);
21192 SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor**, u32*);
21193 SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor*);
21194 SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
21195 SQLITE_PRIVATE u8 sqlite3VdbeOneByteSerialTypeLen(u8);
21196 SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32);
21197 SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
@@ -22816,12 +22819,12 @@
22819 break;
22820 }
22821 case 'm': sqlite3_snprintf(3, &z[j],"%02d",x.M); j+=2; break;
22822 case 'M': sqlite3_snprintf(3, &z[j],"%02d",x.m); j+=2; break;
22823 case 's': {
22824 i64 iS = (i64)(x.iJD/1000 - 21086676*(i64)10000);
22825 sqlite3Int64ToText(iS, &z[j]);
22826 j += sqlite3Strlen30(&z[j]);
22827 break;
22828 }
22829 case 'S': sqlite3_snprintf(3,&z[j],"%02d",(int)x.s); j+=2; break;
22830 case 'w': {
@@ -31770,10 +31773,34 @@
31773 #endif /* SQLITE_OMIT_FLOATING_POINT */
31774 }
31775 #if defined(_MSC_VER)
31776 #pragma warning(default : 4756)
31777 #endif
31778
31779 /*
31780 ** Render an signed 64-bit integer as text. Store the result in zOut[].
31781 **
31782 ** The caller must ensure that zOut[] is at least 21 bytes in size.
31783 */
31784 SQLITE_PRIVATE void sqlite3Int64ToText(i64 v, char *zOut){
31785 int i;
31786 u64 x;
31787 char zTemp[22];
31788 if( v<0 ){
31789 x = (v==SMALLEST_INT64) ? ((u64)1)<<63 : (u64)-v;
31790 }else{
31791 x = v;
31792 }
31793 i = sizeof(zTemp)-2;
31794 zTemp[sizeof(zTemp)-1] = 0;
31795 do{
31796 zTemp[i--] = (x%10) + '0';
31797 x = x/10;
31798 }while( x );
31799 if( v<0 ) zTemp[i--] = '-';
31800 memcpy(zOut, &zTemp[i+1], sizeof(zTemp)-1-i);
31801 }
31802
31803 /*
31804 ** Compare the 19-character string zNum against the text representation
31805 ** value 2^63: 9223372036854775808. Return negative, zero, or positive
31806 ** if zNum is less than, equal to, or greater than the string.
@@ -32011,13 +32038,31 @@
32038 ** Return a 32-bit integer value extracted from a string. If the
32039 ** string is not an integer, just return 0.
32040 */
32041 SQLITE_PRIVATE int sqlite3Atoi(const char *z){
32042 int x = 0;
32043 sqlite3GetInt32(z, &x);
32044 return x;
32045 }
32046
32047 /*
32048 ** Try to convert z into an unsigned 32-bit integer. Return true on
32049 ** success and false if there is an error.
32050 **
32051 ** Only decimal notation is accepted.
32052 */
32053 SQLITE_PRIVATE int sqlite3GetUInt32(const char *z, u32 *pI){
32054 u64 v = 0;
32055 int i;
32056 for(i=0; sqlite3Isdigit(z[i]); i++){
32057 v = v*10 + z[i] - '0';
32058 if( v>4294967296LL ){ *pI = 0; return 0; }
32059 }
32060 if( i==0 || z[i]!=0 ){ *pI = 0; return 0; }
32061 *pI = (u32)v;
32062 return 1;
32063 }
32064
32065 /*
32066 ** The variable-length integer encoding is as follows:
32067 **
32068 ** KEY:
@@ -39188,11 +39233,11 @@
39233 }
39234 #endif
39235 if( rc!=SQLITE_OK ){
39236 if( h>=0 ) robust_close(pNew, h, __LINE__);
39237 }else{
39238 pId->pMethods = pLockingStyle;
39239 OpenCounter(+1);
39240 verifyDbFile(pNew);
39241 }
39242 return rc;
39243 }
@@ -46899,11 +46944,11 @@
46944 {
46945 sqlite3_free(zConverted);
46946 }
46947
46948 sqlite3_free(zTmpname);
46949 id->pMethods = pAppData ? pAppData->pMethod : &winIoMethod;
46950 pFile->pVfs = pVfs;
46951 pFile->h = h;
46952 if( isReadonly ){
46953 pFile->ctrlFlags |= WINFILE_RDONLY;
46954 }
@@ -48125,11 +48170,11 @@
48170 }
48171 memset(p, 0, sizeof(*p));
48172 p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE;
48173 assert( pOutFlags!=0 ); /* True because flags==SQLITE_OPEN_MAIN_DB */
48174 *pOutFlags = flags | SQLITE_OPEN_MEMORY;
48175 pFile->pMethods = &memdb_io_methods;
48176 p->szMax = sqlite3GlobalConfig.mxMemdbSize;
48177 return SQLITE_OK;
48178 }
48179
48180 #if 0 /* Only used to delete rollback journals, super-journals, and WAL
@@ -52442,15 +52487,10 @@
52487 # define USEFETCH(x) ((x)->bUseFetch)
52488 #else
52489 # define USEFETCH(x) 0
52490 #endif
52491
 
 
 
 
 
52492 /*
52493 ** The argument to this macro is a file descriptor (type sqlite3_file*).
52494 ** Return 0 if it is not open, or non-zero (but not 1) if it is.
52495 **
52496 ** This is so that expressions can be written as:
@@ -55419,11 +55459,11 @@
55459 ** Make no changes if mxPage is zero or negative. And never reduce the
55460 ** maximum page count below the current size of the database.
55461 **
55462 ** Regardless of mxPage, return the current maximum page count.
55463 */
55464 SQLITE_PRIVATE Pgno sqlite3PagerMaxPageCount(Pager *pPager, Pgno mxPage){
55465 if( mxPage>0 ){
55466 pPager->mxPgno = mxPage;
55467 }
55468 assert( pPager->eState!=PAGER_OPEN ); /* Called only by OP_MaxPgcnt */
55469 /* assert( pPager->mxPgno>=pPager->dbSize ); */
@@ -57146,22 +57186,22 @@
57186
57187 noContent = (flags & PAGER_GET_NOCONTENT)!=0;
57188 if( pPg->pPager && !noContent ){
57189 /* In this case the pcache already contains an initialized copy of
57190 ** the page. Return without further ado. */
57191 assert( pgno!=PAGER_MJ_PGNO(pPager) );
57192 pPager->aStat[PAGER_STAT_HIT]++;
57193 return SQLITE_OK;
57194
57195 }else{
57196 /* The pager cache has created a new page. Its content needs to
57197 ** be initialized. But first some error checks:
57198 **
57199 ** (*) obsolete. Was: maximum page number is 2^31
57200 ** (2) Never try to fetch the locking page
57201 */
57202 if( pgno==PAGER_MJ_PGNO(pPager) ){
57203 rc = SQLITE_CORRUPT_BKPT;
57204 goto pager_acquire_err;
57205 }
57206
57207 pPg->pPager = pPager;
@@ -59863,11 +59903,11 @@
59903 ** walIteratorFree() - Free an iterator.
59904 **
59905 ** This functionality is used by the checkpoint code (see walCheckpoint()).
59906 */
59907 struct WalIterator {
59908 u32 iPrior; /* Last result returned from the iterator */
59909 int nSegment; /* Number of entries in aSegment[] */
59910 struct WalSegment {
59911 int iNext; /* Next slot in aIndex[] not yet returned */
59912 ht_slot *aIndex; /* i0, i1, i2... such that aPgno[iN] ascend */
59913 u32 *aPgno; /* Array of page numbers. */
@@ -59945,11 +59985,13 @@
59985 rc = sqlite3OsShmMap(pWal->pDbFd, iPage, WALINDEX_PGSZ,
59986 pWal->writeLock, (void volatile **)&pWal->apWiData[iPage]
59987 );
59988 assert( pWal->apWiData[iPage]!=0 || rc!=SQLITE_OK || pWal->writeLock==0 );
59989 testcase( pWal->apWiData[iPage]==0 && rc==SQLITE_OK );
59990 if( rc==SQLITE_OK ){
59991 if( iPage>0 && sqlite3FaultSim(600) ) rc = SQLITE_NOMEM;
59992 }else if( (rc&0xff)==SQLITE_READONLY ){
59993 pWal->readOnly |= WAL_SHM_RDONLY;
59994 if( rc==SQLITE_READONLY ){
59995 rc = SQLITE_OK;
59996 }
59997 }
@@ -60320,10 +60362,11 @@
60362 && (iHash>=1 || iFrame<=HASHTABLE_NPAGE_ONE)
60363 && (iHash<=1 || iFrame>(HASHTABLE_NPAGE_ONE+HASHTABLE_NPAGE))
60364 && (iHash>=2 || iFrame<=HASHTABLE_NPAGE_ONE+HASHTABLE_NPAGE)
60365 && (iHash<=2 || iFrame>(HASHTABLE_NPAGE_ONE+2*HASHTABLE_NPAGE))
60366 );
60367 assert( iHash>=0 );
60368 return iHash;
60369 }
60370
60371 /*
60372 ** Return the page number associated with frame iFrame in this WAL.
@@ -60516,16 +60559,10 @@
60559 assert( WAL_ALL_BUT_WRITE==WAL_WRITE_LOCK+1 );
60560 assert( WAL_CKPT_LOCK==WAL_ALL_BUT_WRITE );
60561 assert( pWal->writeLock );
60562 iLock = WAL_ALL_BUT_WRITE + pWal->ckptLock;
60563 rc = walLockExclusive(pWal, iLock, WAL_READ_LOCK(0)-iLock);
 
 
 
 
 
 
60564 if( rc ){
60565 return rc;
60566 }
60567
60568 WALTRACE(("WAL%p: recovery begin...\n", pWal));
@@ -60537,19 +60574,20 @@
60574 goto recovery_error;
60575 }
60576
60577 if( nSize>WAL_HDRSIZE ){
60578 u8 aBuf[WAL_HDRSIZE]; /* Buffer to load WAL header into */
60579 u32 *aPrivate = 0; /* Heap copy of *-shm hash being populated */
60580 u8 *aFrame = 0; /* Malloc'd buffer to load entire frame */
60581 int szFrame; /* Number of bytes in buffer aFrame[] */
60582 u8 *aData; /* Pointer to data part of aFrame buffer */
 
 
60583 int szPage; /* Page size according to the log */
60584 u32 magic; /* Magic value read from WAL header */
60585 u32 version; /* Magic value read from WAL header */
60586 int isValid; /* True if this frame is valid */
60587 u32 iPg; /* Current 32KB wal-index page */
60588 u32 iLastFrame; /* Last frame in wal, based on nSize alone */
60589
60590 /* Read in the WAL header. */
60591 rc = sqlite3OsRead(pWal->pWalFd, aBuf, WAL_HDRSIZE, 0);
60592 if( rc!=SQLITE_OK ){
60593 goto recovery_error;
@@ -60592,42 +60630,59 @@
60630 goto finished;
60631 }
60632
60633 /* Malloc a buffer to read frames into. */
60634 szFrame = szPage + WAL_FRAME_HDRSIZE;
60635 aFrame = (u8 *)sqlite3_malloc64(szFrame + WALINDEX_PGSZ);
60636 if( !aFrame ){
60637 rc = SQLITE_NOMEM_BKPT;
60638 goto recovery_error;
60639 }
60640 aData = &aFrame[WAL_FRAME_HDRSIZE];
60641 aPrivate = (u32*)&aData[szPage];
60642
60643 /* Read all frames from the log file. */
60644 iLastFrame = (nSize - WAL_HDRSIZE) / szFrame;
60645 for(iPg=0; iPg<=(u32)walFramePage(iLastFrame); iPg++){
60646 u32 *aShare;
60647 u32 iFrame; /* Index of last frame read */
60648 u32 iLast = MIN(iLastFrame, HASHTABLE_NPAGE_ONE+iPg*HASHTABLE_NPAGE);
60649 u32 iFirst = 1 + (iPg==0?0:HASHTABLE_NPAGE_ONE+(iPg-1)*HASHTABLE_NPAGE);
60650 u32 nHdr, nHdr32;
60651 rc = walIndexPage(pWal, iPg, (volatile u32**)&aShare);
60652 if( rc ) break;
60653 pWal->apWiData[iPg] = aPrivate;
60654
60655 for(iFrame=iFirst; iFrame<=iLast; iFrame++){
60656 i64 iOffset = walFrameOffset(iFrame, szPage);
60657 u32 pgno; /* Database page number for frame */
60658 u32 nTruncate; /* dbsize field from frame header */
60659
60660 /* Read and decode the next log frame. */
60661 rc = sqlite3OsRead(pWal->pWalFd, aFrame, szFrame, iOffset);
60662 if( rc!=SQLITE_OK ) break;
60663 isValid = walDecodeFrame(pWal, &pgno, &nTruncate, aData, aFrame);
60664 if( !isValid ) break;
60665 rc = walIndexAppend(pWal, iFrame, pgno);
60666 if( NEVER(rc!=SQLITE_OK) ) break;
60667
60668 /* If nTruncate is non-zero, this is a commit record. */
60669 if( nTruncate ){
60670 pWal->hdr.mxFrame = iFrame;
60671 pWal->hdr.nPage = nTruncate;
60672 pWal->hdr.szPage = (u16)((szPage&0xff00) | (szPage>>16));
60673 testcase( szPage<=32768 );
60674 testcase( szPage>=65536 );
60675 aFrameCksum[0] = pWal->hdr.aFrameCksum[0];
60676 aFrameCksum[1] = pWal->hdr.aFrameCksum[1];
60677 }
60678 }
60679 pWal->apWiData[iPg] = aShare;
60680 nHdr = (iPg==0 ? WALINDEX_HDR_SIZE : 0);
60681 nHdr32 = nHdr / sizeof(u32);
60682 memcpy(&aShare[nHdr32], &aPrivate[nHdr32], WALINDEX_PGSZ-nHdr);
60683 if( iFrame<=iLast ) break;
60684 }
60685
60686 sqlite3_free(aFrame);
60687 }
60688
@@ -60638,19 +60693,30 @@
60693 pWal->hdr.aFrameCksum[0] = aFrameCksum[0];
60694 pWal->hdr.aFrameCksum[1] = aFrameCksum[1];
60695 walIndexWriteHdr(pWal);
60696
60697 /* Reset the checkpoint-header. This is safe because this thread is
60698 ** currently holding locks that exclude all other writers and
60699 ** checkpointers. Then set the values of read-mark slots 1 through N.
60700 */
60701 pInfo = walCkptInfo(pWal);
60702 pInfo->nBackfill = 0;
60703 pInfo->nBackfillAttempted = pWal->hdr.mxFrame;
60704 pInfo->aReadMark[0] = 0;
60705 for(i=1; i<WAL_NREADER; i++){
60706 rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1);
60707 if( rc==SQLITE_OK ){
60708 if( i==1 && pWal->hdr.mxFrame ){
60709 pInfo->aReadMark[i] = pWal->hdr.mxFrame;
60710 }else{
60711 pInfo->aReadMark[i] = READMARK_NOT_USED;
60712 }
60713 walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1);
60714 }else if( rc!=SQLITE_BUSY ){
60715 goto recovery_error;
60716 }
60717 }
60718
60719 /* If more than one frame was recovered from the log file, report an
60720 ** event via sqlite3_log(). This is to help with identifying performance
60721 ** problems caused by applications routinely shutting down without
60722 ** checkpointing the log file.
@@ -60664,11 +60730,10 @@
60730 }
60731
60732 recovery_error:
60733 WALTRACE(("WAL%p: recovery %s\n", pWal, rc ? "failed" : "ok"));
60734 walUnlockExclusive(pWal, iLock, WAL_READ_LOCK(0)-iLock);
 
60735 return rc;
60736 }
60737
60738 /*
60739 ** Close an open wal-index.
@@ -64048,11 +64113,12 @@
64113 Pgno nPage; /* Number of pages in the database */
64114 int mxErr; /* Stop accumulating errors when this reaches zero */
64115 int nErr; /* Number of messages written to zErrMsg so far */
64116 int bOomFault; /* A memory allocation error has occurred */
64117 const char *zPfx; /* Error message prefix */
64118 Pgno v1; /* Value for first %u substitution in zPfx */
64119 int v2; /* Value for second %d substitution in zPfx */
64120 StrAccum errMsg; /* Accumulate the error message text here */
64121 u32 *heap; /* Min-heap used for analyzing cell coverage */
64122 sqlite3 *db; /* Database connection running the check */
64123 };
64124
@@ -66513,16 +66579,15 @@
66579 /*
66580 ** Return the size of the database file in pages. If there is any kind of
66581 ** error, return ((unsigned int)-1).
66582 */
66583 static Pgno btreePagecount(BtShared *pBt){
 
66584 return pBt->nPage;
66585 }
66586 SQLITE_PRIVATE Pgno sqlite3BtreeLastPage(Btree *p){
66587 assert( sqlite3BtreeHoldsMutex(p) );
66588 return btreePagecount(p->pBt);
66589 }
66590
66591 /*
66592 ** Get a page from the pager and initialize it.
66593 **
@@ -67306,12 +67371,12 @@
67371 /*
67372 ** Set the maximum page count for a database if mxPage is positive.
67373 ** No changes are made if mxPage is 0 or negative.
67374 ** Regardless of the value of mxPage, return the maximum page count.
67375 */
67376 SQLITE_PRIVATE Pgno sqlite3BtreeMaxPageCount(Btree *p, Pgno mxPage){
67377 Pgno n;
67378 sqlite3BtreeEnter(p);
67379 n = sqlite3PagerMaxPageCount(p->pBt->pPager, mxPage);
67380 sqlite3BtreeLeave(p);
67381 return n;
67382 }
@@ -68746,11 +68811,11 @@
68811 ** It is assumed that the sqlite3BtreeCursorZero() has been called
68812 ** on pCur to initialize the memory space prior to invoking this routine.
68813 */
68814 static int btreeCursor(
68815 Btree *p, /* The btree */
68816 Pgno iTable, /* Root page of table to open */
68817 int wrFlag, /* 1 to write. 0 read-only */
68818 struct KeyInfo *pKeyInfo, /* First arg to comparison function */
68819 BtCursor *pCur /* Space for new cursor */
68820 ){
68821 BtShared *pBt = p->pBt; /* Shared b-tree handle */
@@ -68789,21 +68854,21 @@
68854 }
68855 }
68856
68857 /* Now that no other errors can occur, finish filling in the BtCursor
68858 ** variables and link the cursor into the BtShared list. */
68859 pCur->pgnoRoot = iTable;
68860 pCur->iPage = -1;
68861 pCur->pKeyInfo = pKeyInfo;
68862 pCur->pBtree = p;
68863 pCur->pBt = pBt;
68864 pCur->curFlags = wrFlag ? BTCF_WriteFlag : 0;
68865 pCur->curPagerFlags = wrFlag ? 0 : PAGER_GET_READONLY;
68866 /* If there are two or more cursors on the same btree, then all such
68867 ** cursors *must* have the BTCF_Multiple flag set. */
68868 for(pX=pBt->pCursor; pX; pX=pX->pNext){
68869 if( pX->pgnoRoot==iTable ){
68870 pX->curFlags |= BTCF_Multiple;
68871 pCur->curFlags |= BTCF_Multiple;
68872 }
68873 }
68874 pCur->pNext = pBt->pCursor;
@@ -68811,11 +68876,11 @@
68876 pCur->eState = CURSOR_INVALID;
68877 return SQLITE_OK;
68878 }
68879 static int btreeCursorWithLock(
68880 Btree *p, /* The btree */
68881 Pgno iTable, /* Root page of table to open */
68882 int wrFlag, /* 1 to write. 0 read-only */
68883 struct KeyInfo *pKeyInfo, /* First arg to comparison function */
68884 BtCursor *pCur /* Space for new cursor */
68885 ){
68886 int rc;
@@ -68824,11 +68889,11 @@
68889 sqlite3BtreeLeave(p);
68890 return rc;
68891 }
68892 SQLITE_PRIVATE int sqlite3BtreeCursor(
68893 Btree *p, /* The btree */
68894 Pgno iTable, /* Root page of table to open */
68895 int wrFlag, /* 1 to write. 0 read-only */
68896 struct KeyInfo *pKeyInfo, /* First arg to xCompare() */
68897 BtCursor *pCur /* Write new cursor here */
68898 ){
68899 if( p->sharable ){
@@ -69249,10 +69314,11 @@
69314 }
69315
69316 assert( rc==SQLITE_OK && amt>0 );
69317 while( nextPage ){
69318 /* If required, populate the overflow page-list cache. */
69319 if( nextPage > pBt->nPage ) return SQLITE_CORRUPT_BKPT;
69320 assert( pCur->aOverflow[iIdx]==0
69321 || pCur->aOverflow[iIdx]==nextPage
69322 || CORRUPT_DB );
69323 pCur->aOverflow[iIdx] = nextPage;
69324
@@ -70321,11 +70387,11 @@
70387 ** shows that the page 'nearby' is somewhere on the free-list, then
70388 ** the entire-list will be searched for that page.
70389 */
70390 #ifndef SQLITE_OMIT_AUTOVACUUM
70391 if( eMode==BTALLOC_EXACT ){
70392 if( ALWAYS(nearby<=mxPage) ){
70393 u8 eType;
70394 assert( nearby>0 );
70395 assert( pBt->autoVacuum );
70396 rc = ptrmapGet(pBt, nearby, &eType, 0);
70397 if( rc ) return rc;
@@ -70617,11 +70683,11 @@
70683
70684 assert( sqlite3_mutex_held(pBt->mutex) );
70685 assert( CORRUPT_DB || iPage>1 );
70686 assert( !pMemPage || pMemPage->pgno==iPage );
70687
70688 if( iPage<2 || NEVER(iPage>pBt->nPage) ){
70689 return SQLITE_CORRUPT_BKPT;
70690 }
70691 if( pMemPage ){
70692 pPage = pMemPage;
70693 sqlite3PagerRef(pPage->pDbPage);
@@ -70664,10 +70730,14 @@
70730 */
70731 if( nFree!=0 ){
70732 u32 nLeaf; /* Initial number of leaf cells on trunk page */
70733
70734 iTrunk = get4byte(&pPage1->aData[32]);
70735 if( iTrunk>btreePagecount(pBt) ){
70736 rc = SQLITE_CORRUPT_BKPT;
70737 goto freepage_out;
70738 }
70739 rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0);
70740 if( rc!=SQLITE_OK ){
70741 goto freepage_out;
70742 }
70743
@@ -73468,11 +73538,11 @@
73538 ** flags might not work:
73539 **
73540 ** BTREE_INTKEY|BTREE_LEAFDATA Used for SQL tables with rowid keys
73541 ** BTREE_ZERODATA Used for SQL indices
73542 */
73543 static int btreeCreateTable(Btree *p, Pgno *piTable, int createTabFlags){
73544 BtShared *pBt = p->pBt;
73545 MemPage *pRoot;
73546 Pgno pgnoRoot;
73547 int rc;
73548 int ptfFlags; /* Page-type flage for the root page of new table */
@@ -73501,21 +73571,23 @@
73571 /* Read the value of meta[3] from the database to determine where the
73572 ** root page of the new table should go. meta[3] is the largest root-page
73573 ** created so far, so the new root-page is (meta[3]+1).
73574 */
73575 sqlite3BtreeGetMeta(p, BTREE_LARGEST_ROOT_PAGE, &pgnoRoot);
73576 if( pgnoRoot>btreePagecount(pBt) ){
73577 return SQLITE_CORRUPT_BKPT;
73578 }
73579 pgnoRoot++;
73580
73581 /* The new root-page may not be allocated on a pointer-map page, or the
73582 ** PENDING_BYTE page.
73583 */
73584 while( pgnoRoot==PTRMAP_PAGENO(pBt, pgnoRoot) ||
73585 pgnoRoot==PENDING_BYTE_PAGE(pBt) ){
73586 pgnoRoot++;
73587 }
73588 assert( pgnoRoot>=3 );
 
73589
73590 /* Allocate a page. The page that currently resides at pgnoRoot will
73591 ** be moved to the allocated page (unless the allocated page happens
73592 ** to reside at pgnoRoot).
73593 */
@@ -73608,14 +73680,14 @@
73680 ptfFlags = PTF_ZERODATA | PTF_LEAF;
73681 }
73682 zeroPage(pRoot, ptfFlags);
73683 sqlite3PagerUnref(pRoot->pDbPage);
73684 assert( (pBt->openFlags & BTREE_SINGLE)==0 || pgnoRoot==2 );
73685 *piTable = pgnoRoot;
73686 return SQLITE_OK;
73687 }
73688 SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree *p, Pgno *piTable, int flags){
73689 int rc;
73690 sqlite3BtreeEnter(p);
73691 rc = btreeCreateTable(p, piTable, flags);
73692 sqlite3BtreeLeave(p);
73693 return rc;
@@ -74095,11 +74167,11 @@
74167 ** Verify that the number of pages on the list is N.
74168 */
74169 static void checkList(
74170 IntegrityCk *pCheck, /* Integrity checking context */
74171 int isFreeList, /* True for a freelist. False for overflow page list */
74172 Pgno iPage, /* Page number for first page in the list */
74173 u32 N /* Expected number of pages in the list */
74174 ){
74175 int i;
74176 u32 expected = N;
74177 int nErrAtStart = pCheck->nErr;
@@ -74227,11 +74299,11 @@
74299 ** 4. Recursively call checkTreePage on all children.
74300 ** 5. Verify that the depth of all children is the same.
74301 */
74302 static int checkTreePage(
74303 IntegrityCk *pCheck, /* Context for the sanity check */
74304 Pgno iPage, /* Page number of the page to check */
74305 i64 *piMinKey, /* Write minimum integer primary key here */
74306 i64 maxKey /* Error if integer primary key greater than this */
74307 ){
74308 MemPage *pPage = 0; /* The page being analyzed */
74309 int i; /* Loop counter */
@@ -74263,13 +74335,13 @@
74335 */
74336 pBt = pCheck->pBt;
74337 usableSize = pBt->usableSize;
74338 if( iPage==0 ) return 0;
74339 if( checkRef(pCheck, iPage) ) return 0;
74340 pCheck->zPfx = "Page %u: ";
74341 pCheck->v1 = iPage;
74342 if( (rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0 ){
74343 checkAppendMsg(pCheck,
74344 "unable to get the page. error code=%d", rc);
74345 goto end_of_check;
74346 }
74347
@@ -74290,11 +74362,11 @@
74362 }
74363 data = pPage->aData;
74364 hdr = pPage->hdrOffset;
74365
74366 /* Set up for cell analysis */
74367 pCheck->zPfx = "On tree page %u cell %d: ";
74368 contentOffset = get2byteNotZero(&data[hdr+5]);
74369 assert( contentOffset<=usableSize ); /* Enforced by btreeInitPage() */
74370
74371 /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
74372 ** number of cells on the page. */
@@ -74310,11 +74382,11 @@
74382 if( !pPage->leaf ){
74383 /* Analyze the right-child page of internal pages */
74384 pgno = get4byte(&data[hdr+8]);
74385 #ifndef SQLITE_OMIT_AUTOVACUUM
74386 if( pBt->autoVacuum ){
74387 pCheck->zPfx = "On page %u at right child: ";
74388 checkPtrmap(pCheck, pgno, PTRMAP_BTREE, iPage);
74389 }
74390 #endif
74391 depth = checkTreePage(pCheck, pgno, &maxKey, maxKey);
74392 keyCanBeEqual = 0;
@@ -74451,11 +74523,11 @@
74523 nFrag = 0;
74524 prev = contentOffset - 1; /* Implied first min-heap entry */
74525 while( btreeHeapPull(heap,&x) ){
74526 if( (prev&0xffff)>=(x>>16) ){
74527 checkAppendMsg(pCheck,
74528 "Multiple uses for byte %u of page %u", x>>16, iPage);
74529 break;
74530 }else{
74531 nFrag += (x>>16) - (prev&0xffff) - 1;
74532 prev = x;
74533 }
@@ -74466,11 +74538,11 @@
74538 ** EVIDENCE-OF: R-07161-27322 The one-byte integer at offset 7 gives the
74539 ** number of fragmented free bytes within the cell content area.
74540 */
74541 if( heap[0]==0 && nFrag!=data[hdr+7] ){
74542 checkAppendMsg(pCheck,
74543 "Fragmentation of %d bytes reported as %d on page %u",
74544 nFrag, data[hdr+7], iPage);
74545 }
74546 }
74547
74548 end_of_check:
@@ -74494,25 +74566,44 @@
74566 **
74567 ** Write the number of error seen in *pnErr. Except for some memory
74568 ** allocation errors, an error message held in memory obtained from
74569 ** malloc is returned if *pnErr is non-zero. If *pnErr==0 then NULL is
74570 ** returned. If a memory allocation error occurs, NULL is returned.
74571 **
74572 ** If the first entry in aRoot[] is 0, that indicates that the list of
74573 ** root pages is incomplete. This is a "partial integrity-check". This
74574 ** happens when performing an integrity check on a single table. The
74575 ** zero is skipped, of course. But in addition, the freelist checks
74576 ** and the checks to make sure every page is referenced are also skipped,
74577 ** since obviously it is not possible to know which pages are covered by
74578 ** the unverified btrees. Except, if aRoot[1] is 1, then the freelist
74579 ** checks are still performed.
74580 */
74581 SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(
74582 sqlite3 *db, /* Database connection that is running the check */
74583 Btree *p, /* The btree to be checked */
74584 Pgno *aRoot, /* An array of root pages numbers for individual trees */
74585 int nRoot, /* Number of entries in aRoot[] */
74586 int mxErr, /* Stop reporting errors after this many */
74587 int *pnErr /* Write number of errors seen to this variable */
74588 ){
74589 Pgno i;
74590 IntegrityCk sCheck;
74591 BtShared *pBt = p->pBt;
74592 u64 savedDbFlags = pBt->db->flags;
74593 char zErr[100];
74594 int bPartial = 0; /* True if not checking all btrees */
74595 int bCkFreelist = 1; /* True to scan the freelist */
74596 VVA_ONLY( int nRef );
74597 assert( nRoot>0 );
74598
74599 /* aRoot[0]==0 means this is a partial check */
74600 if( aRoot[0]==0 ){
74601 assert( nRoot>1 );
74602 bPartial = 1;
74603 if( aRoot[1]!=1 ) bCkFreelist = 0;
74604 }
74605
74606 sqlite3BtreeEnter(p);
74607 assert( p->inTrans>TRANS_NONE && pBt->inTransaction>TRANS_NONE );
74608 VVA_ONLY( nRef = sqlite3PagerRefcount(pBt->pPager) );
74609 assert( nRef>=0 );
@@ -74548,67 +74639,73 @@
74639 i = PENDING_BYTE_PAGE(pBt);
74640 if( i<=sCheck.nPage ) setPageReferenced(&sCheck, i);
74641
74642 /* Check the integrity of the freelist
74643 */
74644 if( bCkFreelist ){
74645 sCheck.zPfx = "Main freelist: ";
74646 checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]),
74647 get4byte(&pBt->pPage1->aData[36]));
74648 sCheck.zPfx = 0;
74649 }
74650
74651 /* Check all the tables.
74652 */
74653 #ifndef SQLITE_OMIT_AUTOVACUUM
74654 if( !bPartial ){
74655 if( pBt->autoVacuum ){
74656 Pgno mx = 0;
74657 Pgno mxInHdr;
74658 for(i=0; (int)i<nRoot; i++) if( mx<aRoot[i] ) mx = aRoot[i];
74659 mxInHdr = get4byte(&pBt->pPage1->aData[52]);
74660 if( mx!=mxInHdr ){
74661 checkAppendMsg(&sCheck,
74662 "max rootpage (%d) disagrees with header (%d)",
74663 mx, mxInHdr
74664 );
74665 }
74666 }else if( get4byte(&pBt->pPage1->aData[64])!=0 ){
74667 checkAppendMsg(&sCheck,
74668 "incremental_vacuum enabled with a max rootpage of zero"
74669 );
74670 }
74671 }
74672 #endif
74673 testcase( pBt->db->flags & SQLITE_CellSizeCk );
74674 pBt->db->flags &= ~(u64)SQLITE_CellSizeCk;
74675 for(i=0; (int)i<nRoot && sCheck.mxErr; i++){
74676 i64 notUsed;
74677 if( aRoot[i]==0 ) continue;
74678 #ifndef SQLITE_OMIT_AUTOVACUUM
74679 if( pBt->autoVacuum && aRoot[i]>1 && !bPartial ){
74680 checkPtrmap(&sCheck, aRoot[i], PTRMAP_ROOTPAGE, 0);
74681 }
74682 #endif
74683 checkTreePage(&sCheck, aRoot[i], &notUsed, LARGEST_INT64);
74684 }
74685 pBt->db->flags = savedDbFlags;
74686
74687 /* Make sure every page in the file is referenced
74688 */
74689 if( !bPartial ){
74690 for(i=1; i<=sCheck.nPage && sCheck.mxErr; i++){
74691 #ifdef SQLITE_OMIT_AUTOVACUUM
74692 if( getPageReferenced(&sCheck, i)==0 ){
74693 checkAppendMsg(&sCheck, "Page %d is never used", i);
74694 }
74695 #else
74696 /* If the database supports auto-vacuum, make sure no tables contain
74697 ** references to pointer-map pages.
74698 */
74699 if( getPageReferenced(&sCheck, i)==0 &&
74700 (PTRMAP_PAGENO(pBt, i)!=i || !pBt->autoVacuum) ){
74701 checkAppendMsg(&sCheck, "Page %d is never used", i);
74702 }
74703 if( getPageReferenced(&sCheck, i)!=0 &&
74704 (PTRMAP_PAGENO(pBt, i)==i && pBt->autoVacuum) ){
74705 checkAppendMsg(&sCheck, "Pointer map page %d is referenced", i);
74706 }
74707 }
74708 #endif
74709 }
74710
74711 /* Clean up and report errors.
@@ -75794,20 +75891,29 @@
75891 ** into a buffer.
75892 */
75893 static void vdbeMemRenderNum(int sz, char *zBuf, Mem *p){
75894 StrAccum acc;
75895 assert( p->flags & (MEM_Int|MEM_Real|MEM_IntReal) );
75896 assert( sz>22 );
75897 if( p->flags & MEM_Int ){
75898 #if GCC_VERSION>=7000000
75899 /* Work-around for GCC bug
75900 ** https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96270 */
75901 i64 x;
75902 assert( (p->flags&MEM_Int)*2==sizeof(x) );
75903 memcpy(&x, (char*)&p->u, (p->flags&MEM_Int)*2);
75904 sqlite3Int64ToText(x, zBuf);
75905 #else
75906 sqlite3Int64ToText(p->u.i, zBuf);
75907 #endif
75908 }else{
75909 sqlite3StrAccumInit(&acc, 0, zBuf, sz, 0);
75910 sqlite3_str_appendf(&acc, "%!.15g",
75911 (p->flags & MEM_IntReal)!=0 ? (double)p->u.i : p->u.r);
75912 assert( acc.zText==zBuf && acc.mxAlloc<=0 );
75913 zBuf[acc.nChar] = 0; /* Fast version of sqlite3StrAccumFinish(&acc) */
75914 }
 
 
75915 }
75916
75917 #ifdef SQLITE_DEBUG
75918 /*
75919 ** Validity checks on pMem. pMem holds a string.
@@ -79301,16 +79407,16 @@
79407 sqlite3_str_appendf(&x, "vtab:%p", pVtab);
79408 break;
79409 }
79410 #endif
79411 case P4_INTARRAY: {
79412 u32 i;
79413 u32 *ai = pOp->p4.ai;
79414 u32 n = ai[0]; /* The first element of an INTARRAY is always the
79415 ** count of the number of elements to follow */
79416 for(i=1; i<=n; i++){
79417 sqlite3_str_appendf(&x, "%c%u", (i==1 ? '[' : ','), ai[i]);
79418 }
79419 sqlite3_str_append(&x, "]", 1);
79420 break;
79421 }
79422 case P4_SUBPROGRAM: {
@@ -81150,15 +81256,15 @@
81256 ** a NULL row.
81257 **
81258 ** If the cursor is already pointing to the correct row and that row has
81259 ** not been deleted out from under the cursor, then this routine is a no-op.
81260 */
81261 SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor **pp, u32 *piCol){
81262 VdbeCursor *p = *pp;
81263 assert( p->eCurType==CURTYPE_BTREE || p->eCurType==CURTYPE_PSEUDO );
81264 if( p->deferredMoveto ){
81265 u32 iMap;
81266 if( p->aAltMap && (iMap = p->aAltMap[1+*piCol])>0 && !p->nullRow ){
81267 *pp = p->pAltCursor;
81268 *piCol = iMap - 1;
81269 return SQLITE_OK;
81270 }
@@ -87427,14 +87533,14 @@
87533 int n;
87534 int i;
87535 int p1;
87536 int p2;
87537 const KeyInfo *pKeyInfo;
87538 u32 idx;
87539 CollSeq *pColl; /* Collating sequence to use on this term */
87540 int bRev; /* True for DESCENDING sort order */
87541 u32 *aPermute; /* The permutation */
87542
87543 if( (pOp->p5 & OPFLAG_PERMUTE)==0 ){
87544 aPermute = 0;
87545 }else{
87546 assert( pOp>aOp );
@@ -87459,11 +87565,11 @@
87565 assert( p1>0 && p1+n<=(p->nMem+1 - p->nCursor)+1 );
87566 assert( p2>0 && p2+n<=(p->nMem+1 - p->nCursor)+1 );
87567 }
87568 #endif /* SQLITE_DEBUG */
87569 for(i=0; i<n; i++){
87570 idx = aPermute ? aPermute[i] : (u32)i;
87571 assert( memIsValid(&aMem[p1+idx]) );
87572 assert( memIsValid(&aMem[p2+idx]) );
87573 REGISTER_TRACE(p1+idx, &aMem[p1+idx]);
87574 REGISTER_TRACE(p2+idx, &aMem[p2+idx]);
87575 assert( i<pKeyInfo->nKeyField );
@@ -87770,11 +87876,11 @@
87876 ** the result is guaranteed to only be used as the argument of a length()
87877 ** or typeof() function, respectively. The loading of large blobs can be
87878 ** skipped for length() and all content loading can be skipped for typeof().
87879 */
87880 case OP_Column: {
87881 u32 p2; /* column number to retrieve */
87882 VdbeCursor *pC; /* The VDBE cursor */
87883 BtCursor *pCrsr; /* The BTree cursor */
87884 u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */
87885 int len; /* The length of the serialized data for the column */
87886 int i; /* Loop counter */
@@ -87788,11 +87894,11 @@
87894 Mem *pReg; /* PseudoTable input register */
87895
87896 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
87897 pC = p->apCsr[pOp->p1];
87898 assert( pC!=0 );
87899 p2 = (u32)pOp->p2;
87900
87901 /* If the cursor cache is stale (meaning it is not currently point at
87902 ** the correct row) then bring it up-to-date by doing the necessary
87903 ** B-Tree seek. */
87904 rc = sqlite3VdbeCursorMoveto(&pC, &p2);
@@ -87915,11 +88021,11 @@
88021 zHdr += sqlite3GetVarint32(zHdr, &t);
88022 pC->aType[i] = t;
88023 offset64 += sqlite3VdbeSerialTypeLen(t);
88024 }
88025 aOffset[++i] = (u32)(offset64 & 0xffffffff);
88026 }while( (u32)i<=p2 && zHdr<zEndHdr );
88027
88028 /* The record is corrupt if any of the following are true:
88029 ** (1) the bytes of the header extend past the declared header size
88030 ** (2) the entire header was used but not all data was used
88031 ** (3) the end of the data extends beyond the end of the record.
@@ -88939,11 +89045,11 @@
89045 ** See also: OP_OpenRead, OP_ReopenIdx
89046 */
89047 case OP_ReopenIdx: {
89048 int nField;
89049 KeyInfo *pKeyInfo;
89050 u32 p2;
89051 int iDb;
89052 int wrFlag;
89053 Btree *pX;
89054 VdbeCursor *pCur;
89055 Db *pDb;
@@ -88970,11 +89076,11 @@
89076 goto abort_due_to_error;
89077 }
89078
89079 nField = 0;
89080 pKeyInfo = 0;
89081 p2 = (u32)pOp->p2;
89082 iDb = pOp->p3;
89083 assert( iDb>=0 && iDb<db->nDb );
89084 assert( DbMaskTest(p->btreeMask, iDb) );
89085 pDb = &db->aDb[iDb];
89086 pX = pDb->pBt;
@@ -89142,11 +89248,11 @@
89248 ** opening it. If a transient table is required, just use the
89249 ** automatically created table with root-page 1 (an BLOB_INTKEY table).
89250 */
89251 if( (pCx->pKeyInfo = pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
89252 assert( pOp->p4type==P4_KEYINFO );
89253 rc = sqlite3BtreeCreateTable(pCx->pBtx, &pCx->pgnoRoot,
89254 BTREE_BLOBKEY | pOp->p5);
89255 if( rc==SQLITE_OK ){
89256 assert( pCx->pgnoRoot==SCHEMA_ROOT+1 );
89257 assert( pKeyInfo->db==db );
89258 assert( pKeyInfo->enc==ENC(db) );
@@ -90406,14 +90512,10 @@
90512 ** generator) then the fix would be to insert a call to
90513 ** sqlite3VdbeCursorMoveto().
90514 */
90515 assert( pC->deferredMoveto==0 );
90516 assert( sqlite3BtreeCursorIsValid(pCrsr) );
 
 
 
 
90517
90518 n = sqlite3BtreePayloadSize(pCrsr);
90519 if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
90520 goto too_big;
90521 }
@@ -91179,11 +91281,11 @@
91281 sqlite3VdbeIncrWriteCounter(p, 0);
91282 nChange = 0;
91283 assert( p->readOnly==0 );
91284 assert( DbMaskTest(p->btreeMask, pOp->p2) );
91285 rc = sqlite3BtreeClearTable(
91286 db->aDb[pOp->p2].pBt, (u32)pOp->p1, (pOp->p3 ? &nChange : 0)
91287 );
91288 if( pOp->p3 ){
91289 p->nChange += nChange;
91290 if( pOp->p3>0 ){
91291 assert( memIsValid(&aMem[pOp->p3]) );
@@ -91228,11 +91330,11 @@
91330 ** P1>1. The P3 argument must be 1 (BTREE_INTKEY) for a rowid table
91331 ** it must be 2 (BTREE_BLOBKEY) for an index or WITHOUT ROWID table.
91332 ** The root page number of the new b-tree is stored in register P2.
91333 */
91334 case OP_CreateBtree: { /* out2 */
91335 Pgno pgno;
91336 Db *pDb;
91337
91338 sqlite3VdbeIncrWriteCounter(p, 0);
91339 pOut = out2Prerelease(p, pOp);
91340 pgno = 0;
@@ -91303,10 +91405,11 @@
91405 zSchema = DFLT_SCHEMA_TABLE;
91406 initData.db = db;
91407 initData.iDb = iDb;
91408 initData.pzErrMsg = &p->zErrMsg;
91409 initData.mInitFlags = 0;
91410 initData.mxPage = sqlite3BtreeLastPage(db->aDb[iDb].pBt);
91411 zSql = sqlite3MPrintf(db,
91412 "SELECT*FROM\"%w\".%s WHERE %s ORDER BY rowid",
91413 db->aDb[iDb].zDbSName, zSchema, pOp->p4.z);
91414 if( zSql==0 ){
91415 rc = SQLITE_NOMEM_BKPT;
@@ -91416,11 +91519,11 @@
91519 **
91520 ** This opcode is used to implement the integrity_check pragma.
91521 */
91522 case OP_IntegrityCk: {
91523 int nRoot; /* Number of tables to check. (Number of root pages.) */
91524 Pgno *aRoot; /* Array of rootpage numbers for tables to be checked */
91525 int nErr; /* Number of errors reported */
91526 char *z; /* Text of the error report */
91527 Mem *pnErr; /* Register keeping track of errors remaining */
91528
91529 assert( p->bIsReader );
@@ -96701,11 +96804,11 @@
96804 }else{
96805 if( i<=2 && pCur->zType==0 ){
96806 Schema *pSchema;
96807 HashElem *k;
96808 int iDb = pOp->p3;
96809 Pgno iRoot = (Pgno)pOp->p2;
96810 sqlite3 *db = pVTab->db;
96811 pSchema = db->aDb[iDb].pSchema;
96812 pCur->zSchema = db->aDb[iDb].zDbSName;
96813 for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){
96814 Table *pTab = (Table*)sqliteHashData(k);
@@ -97288,11 +97391,11 @@
97391 }else{
97392 p->nChunkSize = 8 + MEMJOURNAL_DFLT_FILECHUNKSIZE - sizeof(FileChunk);
97393 assert( MEMJOURNAL_DFLT_FILECHUNKSIZE==fileChunkSize(p->nChunkSize) );
97394 }
97395
97396 pJfd->pMethods = (const sqlite3_io_methods*)&MemJournalMethods;
97397 p->nSpill = nSpill;
97398 p->flags = flags;
97399 p->zJournal = zName;
97400 p->pVfs = pVfs;
97401 return SQLITE_OK;
@@ -97314,11 +97417,11 @@
97417 ** file has not yet been created, create it now.
97418 */
97419 SQLITE_PRIVATE int sqlite3JournalCreate(sqlite3_file *pJfd){
97420 int rc = SQLITE_OK;
97421 MemJournal *p = (MemJournal*)pJfd;
97422 if( pJfd->pMethods==&MemJournalMethods && (
97423 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
97424 p->nSpill>0
97425 #else
97426 /* While this appears to not be possible without ATOMIC_WRITE, the
97427 ** paths are complex, so it seems prudent to leave the test in as
@@ -107581,11 +107684,11 @@
107684 };
107685 int i;
107686 sqlite3 *db = pParse->db;
107687 Db *pDb;
107688 Vdbe *v = sqlite3GetVdbe(pParse);
107689 u32 aRoot[ArraySize(aTable)];
107690 u8 aCreateTbl[ArraySize(aTable)];
107691 #ifdef SQLITE_ENABLE_STAT4
107692 const int nToOpen = OptimizationEnabled(db,SQLITE_Stat4) ? 2 : 1;
107693 #else
107694 const int nToOpen = 1;
@@ -107610,11 +107713,11 @@
107713 ** of the new table in register pParse->regRoot. This is important
107714 ** because the OpenWrite opcode below will be needing it. */
107715 sqlite3NestedParse(pParse,
107716 "CREATE TABLE %Q.%s(%s)", pDb->zDbSName, zTab, aTable[i].zCols
107717 );
107718 aRoot[i] = (u32)pParse->regRoot;
107719 aCreateTbl[i] = OPFLAG_P2ISREG;
107720 }
107721 }else{
107722 /* The table already exists. If zWhere is not NULL, delete all entries
107723 ** associated with the table zWhere. If zWhere is NULL, delete the
@@ -107630,19 +107733,19 @@
107733 }else if( db->xPreUpdateCallback ){
107734 sqlite3NestedParse(pParse, "DELETE FROM %Q.%s", pDb->zDbSName, zTab);
107735 #endif
107736 }else{
107737 /* The sqlite_stat[134] table already exists. Delete all rows. */
107738 sqlite3VdbeAddOp2(v, OP_Clear, (int)aRoot[i], iDb);
107739 }
107740 }
107741 }
107742
107743 /* Open the sqlite_stat[134] tables for writing. */
107744 for(i=0; i<nToOpen; i++){
107745 assert( i<ArraySize(aTable) );
107746 sqlite3VdbeAddOp4Int(v, OP_OpenWrite, iStatCur+i, (int)aRoot[i], iDb, 3);
107747 sqlite3VdbeChangeP5(v, aCreateTbl[i]);
107748 VdbeComment((v, aTable[i].zName));
107749 }
107750 }
107751
@@ -110271,11 +110374,11 @@
110374 ** The TableLock structure is only used by the sqlite3TableLock() and
110375 ** codeTableLocks() functions.
110376 */
110377 struct TableLock {
110378 int iDb; /* The database containing the table to be locked */
110379 Pgno iTab; /* The root page of the table to be locked */
110380 u8 isWriteLock; /* True for write lock. False for a read lock */
110381 const char *zLockName; /* Name of the table */
110382 };
110383
110384 /*
@@ -110289,11 +110392,11 @@
110392 ** codeTableLocks() which occurs during sqlite3FinishCoding().
110393 */
110394 SQLITE_PRIVATE void sqlite3TableLock(
110395 Parse *pParse, /* Parsing context */
110396 int iDb, /* Index of the database containing the table to lock */
110397 Pgno iTab, /* Root page number of the table to be locked */
110398 u8 isWriteLock, /* True for a write lock */
110399 const char *zName /* Name of the table to be locked */
110400 ){
110401 Parse *pToplevel = sqlite3ParseToplevel(pParse);
110402 int i;
@@ -111128,23 +111231,24 @@
111231 const char *zName, /* Name of the object to check */
111232 const char *zType, /* Type of this object */
111233 const char *zTblName /* Parent table name for triggers and indexes */
111234 ){
111235 sqlite3 *db = pParse->db;
111236 if( sqlite3WritableSchema(db)
111237 || db->init.imposterTable
111238 || !sqlite3Config.bExtraSchemaChecks
111239 ){
111240 /* Skip these error checks for writable_schema=ON */
111241 return SQLITE_OK;
111242 }
111243 if( db->init.busy ){
111244 if( sqlite3_stricmp(zType, db->init.azInit[0])
111245 || sqlite3_stricmp(zName, db->init.azInit[1])
111246 || sqlite3_stricmp(zTblName, db->init.azInit[2])
111247 ){
111248 sqlite3ErrorMsg(pParse, ""); /* corruptSchema() will supply the error */
111249 return SQLITE_ERROR;
 
 
111250 }
111251 }else{
111252 if( (pParse->nested==0 && 0==sqlite3StrNICmp(zName, "sqlite_", 7))
111253 || (sqlite3ReadOnlyShadowTables(db) && sqlite3ShadowTableName(db, zName))
111254 ){
@@ -112354,11 +112458,11 @@
112458 ** table entry. This is only required if currently generating VDBE
112459 ** code for a CREATE TABLE (not when parsing one as part of reading
112460 ** a database schema). */
112461 if( v && pPk->tnum>0 ){
112462 assert( db->init.busy==0 );
112463 sqlite3VdbeChangeOpcode(v, (int)pPk->tnum, OP_Goto);
112464 }
112465
112466 /* The root page of the PRIMARY KEY is the table root page */
112467 pPk->tnum = pTab->tnum;
112468
@@ -113050,11 +113154,11 @@
113154 ** We must continue looping until all tables and indices with
113155 ** rootpage==iFrom have been converted to have a rootpage of iTo
113156 ** in order to be certain that we got the right one.
113157 */
113158 #ifndef SQLITE_OMIT_AUTOVACUUM
113159 SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3 *db, int iDb, Pgno iFrom, Pgno iTo){
113160 HashElem *pElem;
113161 Hash *pHash;
113162 Db *pDb;
113163
113164 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
@@ -113083,11 +113187,11 @@
113187 ** erasing iTable (this can happen with an auto-vacuum database).
113188 */
113189 static void destroyRootPage(Parse *pParse, int iTable, int iDb){
113190 Vdbe *v = sqlite3GetVdbe(pParse);
113191 int r1 = sqlite3GetTempReg(pParse);
113192 if( NEVER(iTable<2) ) return;
113193 sqlite3VdbeAddOp3(v, OP_Destroy, iTable, r1, iDb);
113194 sqlite3MayAbort(pParse);
113195 #ifndef SQLITE_OMIT_AUTOVACUUM
113196 /* OP_Destroy stores an in integer r1. If this integer
113197 ** is non-zero, then it is the root page number of a table moved to
@@ -113127,22 +113231,22 @@
113231 ** and root page 5 happened to be the largest root-page number in the
113232 ** database, then root page 5 would be moved to page 4 by the
113233 ** "OP_Destroy 4 0" opcode. The subsequent "OP_Destroy 5 0" would hit
113234 ** a free-list page.
113235 */
113236 Pgno iTab = pTab->tnum;
113237 Pgno iDestroyed = 0;
113238
113239 while( 1 ){
113240 Index *pIdx;
113241 Pgno iLargest = 0;
113242
113243 if( iDestroyed==0 || iTab<iDestroyed ){
113244 iLargest = iTab;
113245 }
113246 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
113247 Pgno iIdx = pIdx->tnum;
113248 assert( pIdx->pSchema==pTab->pSchema );
113249 if( (iDestroyed==0 || (iIdx<iDestroyed)) && iIdx>iLargest ){
113250 iLargest = iIdx;
113251 }
113252 }
@@ -113561,11 +113665,11 @@
113665 int iTab = pParse->nTab++; /* Btree cursor used for pTab */
113666 int iIdx = pParse->nTab++; /* Btree cursor used for pIndex */
113667 int iSorter; /* Cursor opened by OpenSorter (if in use) */
113668 int addr1; /* Address of top of loop */
113669 int addr2; /* Address to jump to for next iteration */
113670 Pgno tnum; /* Root page of index */
113671 int iPartIdxLabel; /* Jump to this label to skip a row */
113672 Vdbe *v; /* Generate code into this virtual machine */
113673 KeyInfo *pKey; /* KeyInfo for index */
113674 int regRecord; /* Register holding assembled index record */
113675 sqlite3 *db = pParse->db; /* The database connection */
@@ -113582,11 +113686,11 @@
113686 sqlite3TableLock(pParse, iDb, pTab->tnum, 1, pTab->zName);
113687
113688 v = sqlite3GetVdbe(pParse);
113689 if( v==0 ) return;
113690 if( memRootPage>=0 ){
113691 tnum = (Pgno)memRootPage;
113692 }else{
113693 tnum = pIndex->tnum;
113694 }
113695 pKey = sqlite3KeyInfoOfIndex(pParse, pIndex);
113696 assert( pKey!=0 || db->mallocFailed || pParse->nErr );
@@ -113607,11 +113711,11 @@
113711 sqlite3VdbeAddOp2(v, OP_SorterInsert, iSorter, regRecord);
113712 sqlite3ResolvePartIdxLabel(pParse, iPartIdxLabel);
113713 sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1); VdbeCoverage(v);
113714 sqlite3VdbeJumpHere(v, addr1);
113715 if( memRootPage<0 ) sqlite3VdbeAddOp2(v, OP_Clear, tnum, iDb);
113716 sqlite3VdbeAddOp4(v, OP_OpenWrite, iIdx, (int)tnum, iDb,
113717 (char *)pKey, P4_KEYINFO);
113718 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR|((memRootPage>=0)?OPFLAG_P2ISREG:0));
113719
113720 addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0); VdbeCoverage(v);
113721 if( IsUniqueIndex(pIndex) ){
@@ -114216,11 +114320,11 @@
114320 ** doing so, code a Noop instruction and store its address in
114321 ** Index.tnum. This is required in case this index is actually a
114322 ** PRIMARY KEY and the table is actually a WITHOUT ROWID table. In
114323 ** that case the convertToWithoutRowidTable() routine will replace
114324 ** the Noop with a Goto to jump over the VDBE code generated below. */
114325 pIndex->tnum = (Pgno)sqlite3VdbeAddOp0(v, OP_Noop);
114326 sqlite3VdbeAddOp3(v, OP_CreateBtree, iDb, iMem, BTREE_BLOBKEY);
114327
114328 /* Gather the complete text of the CREATE INDEX statement into
114329 ** the zStmt variable
114330 */
@@ -114258,11 +114362,11 @@
114362 sqlite3VdbeAddParseSchemaOp(v, iDb,
114363 sqlite3MPrintf(db, "name='%q' AND type='index'", pIndex->zName));
114364 sqlite3VdbeAddOp2(v, OP_Expire, 0, 1);
114365 }
114366
114367 sqlite3VdbeJumpHere(v, (int)pIndex->tnum);
114368 }
114369 }
114370 if( db->init.busy || pTblName==0 ){
114371 pIndex->pNext = pTab->pIndex;
114372 pTab->pIndex = pIndex;
@@ -120581,11 +120685,11 @@
120685 for(i=1; i<iEnd; i++){
120686 VdbeOp *pOp = sqlite3VdbeGetOp(v, i);
120687 assert( pOp!=0 );
120688 if( pOp->opcode==OP_OpenRead && pOp->p3==iDb ){
120689 Index *pIndex;
120690 Pgno tnum = pOp->p2;
120691 if( tnum==pTab->tnum ){
120692 return 1;
120693 }
120694 for(pIndex=pTab->pIndex; pIndex; pIndex=pIndex->pNext){
120695 if( tnum==pIndex->tnum ){
@@ -126204,17 +126308,23 @@
126308 **
126309 ** Return the number of pages in the specified database.
126310 */
126311 case PragTyp_PAGE_COUNT: {
126312 int iReg;
126313 i64 x = 0;
126314 sqlite3CodeVerifySchema(pParse, iDb);
126315 iReg = ++pParse->nMem;
126316 if( sqlite3Tolower(zLeft[0])=='p' ){
126317 sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg);
126318 }else{
126319 if( zRight && sqlite3DecOrHexToI64(zRight,&x)==0 ){
126320 if( x<0 ) x = 0;
126321 else if( x>0xfffffffe ) x = 0xfffffffe;
126322 }else{
126323 x = 0;
126324 }
126325 sqlite3VdbeAddOp3(v, OP_MaxPgcnt, iDb, iReg, (int)x);
126326 }
126327 sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1);
126328 break;
126329 }
126330
@@ -127113,13 +127223,26 @@
127223 **
127224 ** The "quick_check" is reduced version of
127225 ** integrity_check designed to detect most database corruption
127226 ** without the overhead of cross-checking indexes. Quick_check
127227 ** is linear time wherease integrity_check is O(NlogN).
127228 **
127229 ** The maximum nubmer of errors is 100 by default. A different default
127230 ** can be specified using a numeric parameter N.
127231 **
127232 ** Or, the parameter N can be the name of a table. In that case, only
127233 ** the one table named is verified. The freelist is only verified if
127234 ** the named table is "sqlite_schema" (or one of its aliases).
127235 **
127236 ** All schemas are checked by default. To check just a single
127237 ** schema, use the form:
127238 **
127239 ** PRAGMA schema.integrity_check;
127240 */
127241 case PragTyp_INTEGRITY_CHECK: {
127242 int i, j, addr, mxErr;
127243 Table *pObjTab = 0; /* Check only this one table, if not NULL */
127244
127245 int isQuick = (sqlite3Tolower(zLeft[0])=='q');
127246
127247 /* If the PRAGMA command was of the form "PRAGMA <db>.integrity_check",
127248 ** then iDb is set to the index of the database identified by <db>.
@@ -127138,13 +127261,17 @@
127261 pParse->nMem = 6;
127262
127263 /* Set the maximum error count */
127264 mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
127265 if( zRight ){
127266 if( sqlite3GetInt32(zRight, &mxErr) ){
127267 if( mxErr<=0 ){
127268 mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
127269 }
127270 }else{
127271 pObjTab = sqlite3LocateTable(pParse, 0, zRight,
127272 iDb>=0 ? db->aDb[iDb].zDbSName : 0);
127273 }
127274 }
127275 sqlite3VdbeAddOp2(v, OP_Integer, mxErr-1, 1); /* reg[1] holds errors left */
127276
127277 /* Do an integrity check on each database file */
@@ -127169,19 +127296,25 @@
127296 pTbls = &db->aDb[i].pSchema->tblHash;
127297 for(cnt=0, x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
127298 Table *pTab = sqliteHashData(x); /* Current table */
127299 Index *pIdx; /* An index on pTab */
127300 int nIdx; /* Number of indexes on pTab */
127301 if( pObjTab && pObjTab!=pTab ) continue;
127302 if( HasRowid(pTab) ) cnt++;
127303 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){ cnt++; }
127304 if( nIdx>mxIdx ) mxIdx = nIdx;
127305 }
127306 if( cnt==0 ) continue;
127307 if( pObjTab ) cnt++;
127308 aRoot = sqlite3DbMallocRawNN(db, sizeof(int)*(cnt+1));
127309 if( aRoot==0 ) break;
127310 cnt = 0;
127311 if( pObjTab ) aRoot[++cnt] = 0;
127312 for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
127313 Table *pTab = sqliteHashData(x);
127314 Index *pIdx;
127315 if( pObjTab && pObjTab!=pTab ) continue;
127316 if( HasRowid(pTab) ) aRoot[++cnt] = pTab->tnum;
127317 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
127318 aRoot[++cnt] = pIdx->tnum;
127319 }
127320 }
@@ -127211,10 +127344,11 @@
127344 int loopTop;
127345 int iDataCur, iIdxCur;
127346 int r1 = -1;
127347
127348 if( pTab->tnum<1 ) continue; /* Skip VIEWs or VIRTUAL TABLEs */
127349 if( pObjTab && pObjTab!=pTab ) continue;
127350 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
127351 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0,
127352 1, 0, &iDataCur, &iIdxCur);
127353 /* reg[7] counts the number of entries in the table.
127354 ** reg[8+i] counts the number of entries in the i-th index
@@ -128272,11 +128406,17 @@
128406 sqlite3_stmt *pStmt;
128407 TESTONLY(int rcp); /* Return code from sqlite3_prepare() */
128408
128409 assert( db->init.busy );
128410 db->init.iDb = iDb;
128411 if( sqlite3GetUInt32(argv[3], &db->init.newTnum)==0
128412 || (db->init.newTnum>pData->mxPage && pData->mxPage>0)
128413 ){
128414 if( sqlite3Config.bExtraSchemaChecks ){
128415 corruptSchema(pData, argv[1], "invalid rootpage");
128416 }
128417 }
128418 db->init.orphanTrigger = 0;
128419 db->init.azInit = argv;
128420 pStmt = 0;
128421 TESTONLY(rcp = ) sqlite3Prepare(db, argv[4], -1, 0, 0, &pStmt, 0);
128422 rc = db->errCode;
@@ -128305,16 +128445,21 @@
128445 ** been created when we processed the CREATE TABLE. All we have
128446 ** to do here is record the root page number for that index.
128447 */
128448 Index *pIndex;
128449 pIndex = sqlite3FindIndex(db, argv[1], db->aDb[iDb].zDbSName);
128450 if( pIndex==0 ){
128451 corruptSchema(pData, argv[1], "orphan index");
128452 }else
128453 if( sqlite3GetUInt32(argv[3],&pIndex->tnum)==0
128454 || pIndex->tnum<2
128455 || pIndex->tnum>pData->mxPage
128456 || sqlite3IndexHasDuplicateRootPage(pIndex)
128457 ){
128458 if( sqlite3Config.bExtraSchemaChecks ){
128459 corruptSchema(pData, argv[1], "invalid rootpage");
128460 }
128461 }
128462 }
128463 return 0;
128464 }
128465
@@ -128364,10 +128509,11 @@
128509 initData.iDb = iDb;
128510 initData.rc = SQLITE_OK;
128511 initData.pzErrMsg = pzErrMsg;
128512 initData.mInitFlags = mFlags;
128513 initData.nInitRow = 0;
128514 initData.mxPage = 0;
128515 sqlite3InitCallback(&initData, 5, (char **)azArg, 0);
128516 db->mDbFlags &= mask;
128517 if( initData.rc ){
128518 rc = initData.rc;
128519 goto error_out;
@@ -128486,10 +128632,11 @@
128632 }
128633
128634 /* Read the schema information out of the schema tables
128635 */
128636 assert( db->init.busy );
128637 initData.mxPage = sqlite3BtreeLastPage(pDb->pBt);
128638 {
128639 char *zSql;
128640 zSql = sqlite3MPrintf(db,
128641 "SELECT*FROM\"%w\".%s ORDER BY rowid",
128642 db->aDb[iDb].zDbSName, zSchemaTabName);
@@ -129368,12 +129515,14 @@
129515 ** Return the index of a column in a table. Return -1 if the column
129516 ** is not contained in the table.
129517 */
129518 static int columnIndex(Table *pTab, const char *zCol){
129519 int i;
129520 u8 h = sqlite3StrIHash(zCol);
129521 Column *pCol;
129522 for(pCol=pTab->aCol, i=0; i<pTab->nCol; pCol++, i++){
129523 if( pCol->hName==h && sqlite3StrICmp(pCol->zName, zCol)==0 ) return i;
129524 }
129525 return -1;
129526 }
129527
129528 /*
@@ -130231,20 +130380,24 @@
130380 sqlite3ReleaseTempRange(pParse, r1, nPrefixReg+1);
130381 break;
130382 }
130383
130384 case SRT_Upfrom: {
 
130385 if( pSort ){
130386 pushOntoSorter(
130387 pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg);
130388 }else{
 
 
130389 int i2 = pDest->iSDParm2;
130390 int r1 = sqlite3GetTempReg(pParse);
130391
130392 /* If the UPDATE FROM join is an aggregate that matches no rows, it
130393 ** might still be trying to return one row, because that is what
130394 ** aggregates do. Don't record that empty row in the output table. */
130395 sqlite3VdbeAddOp2(v, OP_IsNull, regResult, iBreak); VdbeCoverage(v);
130396
130397 sqlite3VdbeAddOp3(v, OP_MakeRecord,
130398 regResult+(i2<0), nResultCol-(i2<0), r1);
130399 if( i2<0 ){
130400 sqlite3VdbeAddOp3(v, OP_Insert, iParm, r1, regResult);
130401 }else{
130402 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, r1, regResult, i2);
130403 }
@@ -130682,11 +130835,10 @@
130835 case SRT_Mem: {
130836 /* The LIMIT clause will terminate the loop for us */
130837 break;
130838 }
130839 #endif
 
130840 case SRT_Upfrom: {
130841 int i2 = pDest->iSDParm2;
130842 int r1 = sqlite3GetTempReg(pParse);
130843 sqlite3VdbeAddOp3(v, OP_MakeRecord,regRow+(i2<0),nColumn-(i2<0),r1);
130844 if( i2<0 ){
@@ -130694,11 +130846,10 @@
130846 }else{
130847 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, r1, regRow, i2);
130848 }
130849 break;
130850 }
 
130851 default: {
130852 assert( eDest==SRT_Output || eDest==SRT_Coroutine );
130853 testcase( eDest==SRT_Output );
130854 testcase( eDest==SRT_Coroutine );
130855 if( eDest==SRT_Output ){
@@ -132281,11 +132432,11 @@
132432 KeyInfo *pKeyDup = 0; /* Comparison information for duplicate removal */
132433 KeyInfo *pKeyMerge; /* Comparison information for merging rows */
132434 sqlite3 *db; /* Database connection */
132435 ExprList *pOrderBy; /* The ORDER BY clause */
132436 int nOrderBy; /* Number of terms in the ORDER BY clause */
132437 u32 *aPermute; /* Mapping from ORDER BY terms to result set columns */
132438
132439 assert( p->pOrderBy!=0 );
132440 assert( pKeyDup==0 ); /* "Managed" code needs this. Ticket #3382. */
132441 db = pParse->db;
132442 v = pParse->pVdbe;
@@ -132330,11 +132481,11 @@
132481 ** row of results comes from selectA or selectB. Also add explicit
132482 ** collations to the ORDER BY clause terms so that when the subqueries
132483 ** to the right and the left are evaluated, they use the correct
132484 ** collation.
132485 */
132486 aPermute = sqlite3DbMallocRawNN(db, sizeof(u32)*(nOrderBy + 1));
132487 if( aPermute ){
132488 struct ExprList_item *pItem;
132489 aPermute[0] = nOrderBy;
132490 for(i=1, pItem=pOrderBy->a; i<=nOrderBy; i++, pItem++){
132491 assert( pItem->u.x.iOrderByCol>0 );
@@ -135823,11 +135974,11 @@
135974 const int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
135975 const int iCsr = pParse->nTab++; /* Cursor to scan b-tree */
135976 Index *pIdx; /* Iterator variable */
135977 KeyInfo *pKeyInfo = 0; /* Keyinfo for scanned index */
135978 Index *pBest = 0; /* Best index found so far */
135979 Pgno iRoot = pTab->tnum; /* Root page of scanned b-tree */
135980
135981 sqlite3CodeVerifySchema(pParse, iDb);
135982 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
135983
135984 /* Search for the index that has the lowest scan cost.
@@ -135855,11 +136006,11 @@
136006 iRoot = pBest->tnum;
136007 pKeyInfo = sqlite3KeyInfoOfIndex(pParse, pBest);
136008 }
136009
136010 /* Open a read-only cursor, execute the OP_Count, close the cursor. */
136011 sqlite3VdbeAddOp4Int(v, OP_OpenRead, iCsr, (int)iRoot, iDb, 1);
136012 if( pKeyInfo ){
136013 sqlite3VdbeChangeP4(v, -1, (char *)pKeyInfo, P4_KEYINFO);
136014 }
136015 sqlite3VdbeAddOp2(v, OP_Count, iCsr, pAggInfo->aFunc[0].iMem);
136016 sqlite3VdbeAddOp1(v, OP_Close, iCsr);
@@ -142375,11 +142526,11 @@
142526 if( (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)
142527 && DbMaskAllZero(sqlite3ParseToplevel(pParse)->writeMask)
142528 ){
142529 int i;
142530 Table *pTab = pIdx->pTable;
142531 u32 *ai = (u32*)sqlite3DbMallocZero(pParse->db, sizeof(u32)*(pTab->nCol+1));
142532 if( ai ){
142533 ai[0] = pTab->nCol;
142534 for(i=0; i<pIdx->nColumn-1; i++){
142535 int x1, x2;
142536 assert( pIdx->aiColumn[i]<pTab->nCol );
@@ -164889,10 +165040,16 @@
165040 /* sqlite3_test_control(SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS, int);
165041 **
165042 ** Set or clear a flag that causes SQLite to verify that type, name,
165043 ** and tbl_name fields of the sqlite_schema table. This is normally
165044 ** on, but it is sometimes useful to turn it off for testing.
165045 **
165046 ** 2020-07-22: Disabling EXTRA_SCHEMA_CHECKS also disables the
165047 ** verification of rootpage numbers when parsing the schema. This
165048 ** is useful to make it easier to reach strange internal error states
165049 ** during testing. The EXTRA_SCHEMA_CHECKS settting is always enabled
165050 ** in production.
165051 */
165052 case SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS: {
165053 sqlite3GlobalConfig.bExtraSchemaChecks = va_arg(ap, int);
165054 break;
165055 }
@@ -172498,11 +172655,12 @@
172655 ** do {...} while( pRoot->iDocid<iDocid && rc==SQLITE_OK );
172656 */
172657 fts3EvalRestart(pCsr, pRoot, &rc);
172658 do {
172659 fts3EvalNextRow(pCsr, pRoot, &rc);
172660 assert_fts3_nc( pRoot->bEof==0 );
172661 if( pRoot->bEof ) rc = FTS_CORRUPT_VTAB;
172662 }while( pRoot->iDocid!=iDocid && rc==SQLITE_OK );
172663 }
172664 }
172665 return rc;
172666 }
@@ -225482,11 +225640,11 @@
225640 int nArg, /* Number of args */
225641 sqlite3_value **apUnused /* Function arguments */
225642 ){
225643 assert( nArg==0 );
225644 UNUSED_PARAM2(nArg, apUnused);
225645 sqlite3_result_text(pCtx, "fts5: 2020-07-30 17:37:49 96e3dba2ed3ab0c5b2ecf65a3408633e0767c884d48c270e9ef10ab9fa3ec051", -1, SQLITE_TRANSIENT);
225646 }
225647
225648 /*
225649 ** Return true if zName is the extension on one of the shadow tables used
225650 ** by this module.
@@ -230265,12 +230423,12 @@
230423 }
230424 #endif /* SQLITE_CORE */
230425 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
230426
230427 /************** End of stmt.c ************************************************/
230428 #if __LINE__!=230428
230429 #undef SQLITE_SOURCE_ID
230430 #define SQLITE_SOURCE_ID "2020-07-30 17:37:49 96e3dba2ed3ab0c5b2ecf65a3408633e0767c884d48c270e9ef10ab9fa3ealt2"
230431 #endif
230432 /* Return the source-id for this library */
230433 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
230434 /************************** End of sqlite3.c ******************************/
230435
+1 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123123
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124124
** [sqlite_version()] and [sqlite_source_id()].
125125
*/
126126
#define SQLITE_VERSION "3.33.0"
127127
#define SQLITE_VERSION_NUMBER 3033000
128
-#define SQLITE_SOURCE_ID "2020-07-18 18:59:11 020dbfa2aef20e5872cc3e785d99f45903843401292114b5092b9c8aa829b9c3"
128
+#define SQLITE_SOURCE_ID "2020-07-30 17:37:49 96e3dba2ed3ab0c5b2ecf65a3408633e0767c884d48c270e9ef10ab9fa3ec051"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
134134
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.33.0"
127 #define SQLITE_VERSION_NUMBER 3033000
128 #define SQLITE_SOURCE_ID "2020-07-18 18:59:11 020dbfa2aef20e5872cc3e785d99f45903843401292114b5092b9c8aa829b9c3"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
134
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.33.0"
127 #define SQLITE_VERSION_NUMBER 3033000
128 #define SQLITE_SOURCE_ID "2020-07-30 17:37:49 96e3dba2ed3ab0c5b2ecf65a3408633e0767c884d48c270e9ef10ab9fa3ec051"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
134

Keyboard Shortcuts

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