| | @@ -1162,11 +1162,11 @@ |
| 1162 | 1162 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1163 | 1163 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1164 | 1164 | */ |
| 1165 | 1165 | #define SQLITE_VERSION "3.33.0" |
| 1166 | 1166 | #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" |
| 1168 | 1168 | |
| 1169 | 1169 | /* |
| 1170 | 1170 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1171 | 1171 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1172 | 1172 | ** |
| | @@ -14735,10 +14735,257 @@ |
| 14735 | 14735 | /* |
| 14736 | 14736 | ** Defer sourcing vdbe.h and btree.h until after the "u8" and |
| 14737 | 14737 | ** "BusyHandler" typedefs. vdbe.h also requires a few of the opaque |
| 14738 | 14738 | ** pointer types (i.e. FuncDef) defined above. |
| 14739 | 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 ******************/ |
| 14740 | 14987 | /************** Include btree.h in the middle of sqliteInt.h *****************/ |
| 14741 | 14988 | /************** Begin file btree.h *******************************************/ |
| 14742 | 14989 | /* |
| 14743 | 14990 | ** 2001 September 15 |
| 14744 | 14991 | ** |
| | @@ -14810,12 +15057,12 @@ |
| 14810 | 15057 | SQLITE_PRIVATE int sqlite3BtreeSetMmapLimit(Btree*,sqlite3_int64); |
| 14811 | 15058 | #endif |
| 14812 | 15059 | SQLITE_PRIVATE int sqlite3BtreeSetPagerFlags(Btree*,unsigned); |
| 14813 | 15060 | SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve, int eFix); |
| 14814 | 15061 | 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*); |
| 14817 | 15064 | SQLITE_PRIVATE int sqlite3BtreeSecureDelete(Btree*,int); |
| 14818 | 15065 | SQLITE_PRIVATE int sqlite3BtreeGetRequestedReserve(Btree*); |
| 14819 | 15066 | SQLITE_PRIVATE int sqlite3BtreeGetReserveNoMutex(Btree *p); |
| 14820 | 15067 | SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum(Btree *, int); |
| 14821 | 15068 | SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *); |
| | @@ -14823,11 +15070,11 @@ |
| 14823 | 15070 | SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree*, const char*); |
| 14824 | 15071 | SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree*, int); |
| 14825 | 15072 | SQLITE_PRIVATE int sqlite3BtreeCommit(Btree*); |
| 14826 | 15073 | SQLITE_PRIVATE int sqlite3BtreeRollback(Btree*,int,int); |
| 14827 | 15074 | SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree*,int); |
| 14828 | | -SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree*, int*, int flags); |
| 15075 | +SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree*, Pgno*, int flags); |
| 14829 | 15076 | SQLITE_PRIVATE int sqlite3BtreeIsInTrans(Btree*); |
| 14830 | 15077 | SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree*); |
| 14831 | 15078 | SQLITE_PRIVATE int sqlite3BtreeIsInBackup(Btree*); |
| 14832 | 15079 | SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *, int, void(*)(void *)); |
| 14833 | 15080 | SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *pBtree); |
| | @@ -14964,11 +15211,11 @@ |
| 14964 | 15211 | #define BTREE_WRCSR 0x00000004 /* read-write cursor */ |
| 14965 | 15212 | #define BTREE_FORDELETE 0x00000008 /* Cursor is for seek/delete only */ |
| 14966 | 15213 | |
| 14967 | 15214 | SQLITE_PRIVATE int sqlite3BtreeCursor( |
| 14968 | 15215 | Btree*, /* BTree containing table to open */ |
| 14969 | | - int iTable, /* Index of root page */ |
| 15216 | + Pgno iTable, /* Index of root page */ |
| 14970 | 15217 | int wrFlag, /* 1 for writing. 0 for read-only */ |
| 14971 | 15218 | struct KeyInfo*, /* First argument to compare function */ |
| 14972 | 15219 | BtCursor *pCursor /* Space to write cursor structure */ |
| 14973 | 15220 | ); |
| 14974 | 15221 | SQLITE_PRIVATE BtCursor *sqlite3BtreeFakeValidCursor(void); |
| | @@ -15055,11 +15302,11 @@ |
| 15055 | 15302 | SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*); |
| 15056 | 15303 | SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt); |
| 15057 | 15304 | SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*); |
| 15058 | 15305 | SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeMaxRecordSize(BtCursor*); |
| 15059 | 15306 | |
| 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*); |
| 15061 | 15308 | SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*); |
| 15062 | 15309 | SQLITE_PRIVATE i64 sqlite3BtreeRowCountEst(BtCursor*); |
| 15063 | 15310 | |
| 15064 | 15311 | #ifndef SQLITE_OMIT_INCRBLOB |
| 15065 | 15312 | SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor*, u32 offset, u32 amt, void*); |
| | @@ -15192,11 +15439,11 @@ |
| 15192 | 15439 | sqlite3_context *pCtx; /* Used when p4type is P4_FUNCCTX */ |
| 15193 | 15440 | CollSeq *pColl; /* Used when p4type is P4_COLLSEQ */ |
| 15194 | 15441 | Mem *pMem; /* Used when p4type is P4_MEM */ |
| 15195 | 15442 | VTable *pVtab; /* Used when p4type is P4_VTAB */ |
| 15196 | 15443 | 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 */ |
| 15198 | 15445 | SubProgram *pProgram; /* Used when p4type is P4_SUBPROGRAM */ |
| 15199 | 15446 | Table *pTab; /* Used when p4type is P4_TABLE */ |
| 15200 | 15447 | #ifdef SQLITE_ENABLE_CURSOR_HINTS |
| 15201 | 15448 | Expr *pExpr; /* Used when p4type is P4_EXPR */ |
| 15202 | 15449 | #endif |
| | @@ -15756,257 +16003,10 @@ |
| 15756 | 16003 | #endif |
| 15757 | 16004 | |
| 15758 | 16005 | #endif /* SQLITE_VDBE_H */ |
| 15759 | 16006 | |
| 15760 | 16007 | /************** 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 | 16008 | /************** Continuing where we left off in sqliteInt.h ******************/ |
| 16009 | 16009 | /************** Include pcache.h in the middle of sqliteInt.h ****************/ |
| 16010 | 16010 | /************** Begin file pcache.h ******************************************/ |
| 16011 | 16011 | /* |
| 16012 | 16012 | ** 2008 August 05 |
| | @@ -16843,11 +16843,11 @@ |
| 16843 | 16843 | int nChange; /* Value returned by sqlite3_changes() */ |
| 16844 | 16844 | int nTotalChange; /* Value returned by sqlite3_total_changes() */ |
| 16845 | 16845 | int aLimit[SQLITE_N_LIMIT]; /* Limits */ |
| 16846 | 16846 | int nMaxSorterMmap; /* Maximum size of regions mapped by sorter */ |
| 16847 | 16847 | struct sqlite3InitInfo { /* Information used during initialization */ |
| 16848 | | - int newTnum; /* Rootpage of table being initialized */ |
| 16848 | + Pgno newTnum; /* Rootpage of table being initialized */ |
| 16849 | 16849 | u8 iDb; /* Which db file is being initialized */ |
| 16850 | 16850 | u8 busy; /* TRUE if currently initializing */ |
| 16851 | 16851 | unsigned orphanTrigger : 1; /* Last statement is orphaned TEMP trigger */ |
| 16852 | 16852 | unsigned imposterTable : 1; /* Building an imposter table */ |
| 16853 | 16853 | unsigned reopenMemdb : 1; /* ATTACH is really a reopen using MemDB */ |
| | @@ -17482,11 +17482,11 @@ |
| 17482 | 17482 | Select *pSelect; /* NULL for tables. Points to definition if a view. */ |
| 17483 | 17483 | FKey *pFKey; /* Linked list of all foreign keys in this table */ |
| 17484 | 17484 | char *zColAff; /* String defining the affinity of each column */ |
| 17485 | 17485 | ExprList *pCheck; /* All CHECK constraints */ |
| 17486 | 17486 | /* ... 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 */ |
| 17488 | 17488 | u32 nTabRef; /* Number of pointers to this Table */ |
| 17489 | 17489 | u32 tabFlags; /* Mask of TF_* values */ |
| 17490 | 17490 | i16 iPKey; /* If not negative, use aCol[iPKey] as the rowid */ |
| 17491 | 17491 | i16 nCol; /* Number of columns in this table */ |
| 17492 | 17492 | i16 nNVCol; /* Number of columns that are not VIRTUAL */ |
| | @@ -17775,11 +17775,11 @@ |
| 17775 | 17775 | Schema *pSchema; /* Schema containing this index */ |
| 17776 | 17776 | u8 *aSortOrder; /* for each column: True==DESC, False==ASC */ |
| 17777 | 17777 | const char **azColl; /* Array of collation sequence names for index */ |
| 17778 | 17778 | Expr *pPartIdxWhere; /* WHERE clause for partial indices */ |
| 17779 | 17779 | ExprList *aColExpr; /* Column expressions */ |
| 17780 | | - int tnum; /* DB Page containing root of this index */ |
| 17780 | + Pgno tnum; /* DB Page containing root of this index */ |
| 17781 | 17781 | LogEst szIdxRow; /* Estimated average row size in bytes */ |
| 17782 | 17782 | u16 nKeyCol; /* Number of columns forming the key */ |
| 17783 | 17783 | u16 nColumn; /* Number of columns stored in the index */ |
| 17784 | 17784 | u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */ |
| 17785 | 17785 | unsigned idxType:2; /* 0:Normal 1:UNIQUE, 2:PRIMARY KEY, 3:IPK */ |
| | @@ -18990,10 +18990,11 @@ |
| 18990 | 18990 | char **pzErrMsg; /* Error message stored here */ |
| 18991 | 18991 | int iDb; /* 0 for main database. 1 for TEMP, 2.. for ATTACHed */ |
| 18992 | 18992 | int rc; /* Result code stored here */ |
| 18993 | 18993 | u32 mInitFlags; /* Flags controlling error messages */ |
| 18994 | 18994 | u32 nInitRow; /* Number of rows processed */ |
| 18995 | + Pgno mxPage; /* Maximum page number. 0 for no limit. */ |
| 18995 | 18996 | } InitData; |
| 18996 | 18997 | |
| 18997 | 18998 | /* |
| 18998 | 18999 | ** Allowed values for mInitFlags |
| 18999 | 19000 | */ |
| | @@ -19823,12 +19824,14 @@ |
| 19823 | 19824 | SQLITE_PRIVATE int sqlite3FixSelect(DbFixer*, Select*); |
| 19824 | 19825 | SQLITE_PRIVATE int sqlite3FixExpr(DbFixer*, Expr*); |
| 19825 | 19826 | SQLITE_PRIVATE int sqlite3FixExprList(DbFixer*, ExprList*); |
| 19826 | 19827 | SQLITE_PRIVATE int sqlite3FixTriggerStep(DbFixer*, TriggerStep*); |
| 19827 | 19828 | SQLITE_PRIVATE int sqlite3RealSameAsInt(double,sqlite3_int64); |
| 19829 | +SQLITE_PRIVATE void sqlite3Int64ToText(i64,char*); |
| 19828 | 19830 | SQLITE_PRIVATE int sqlite3AtoF(const char *z, double*, int, u8); |
| 19829 | 19831 | SQLITE_PRIVATE int sqlite3GetInt32(const char *, int*); |
| 19832 | +SQLITE_PRIVATE int sqlite3GetUInt32(const char*, u32*); |
| 19830 | 19833 | SQLITE_PRIVATE int sqlite3Atoi(const char*); |
| 19831 | 19834 | #ifndef SQLITE_OMIT_UTF16 |
| 19832 | 19835 | SQLITE_PRIVATE int sqlite3Utf16ByteLen(const void *pData, int nChar); |
| 19833 | 19836 | #endif |
| 19834 | 19837 | SQLITE_PRIVATE int sqlite3Utf8CharLen(const char *pData, int nByte); |
| | @@ -19952,11 +19955,11 @@ |
| 19952 | 19955 | #endif |
| 19953 | 19956 | #endif /* SQLITE_AMALGAMATION */ |
| 19954 | 19957 | #ifdef VDBE_PROFILE |
| 19955 | 19958 | SQLITE_PRIVATE sqlite3_uint64 sqlite3NProfileCnt; |
| 19956 | 19959 | #endif |
| 19957 | | -SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3*, int, int, int); |
| 19960 | +SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3*, int, Pgno, Pgno); |
| 19958 | 19961 | SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*); |
| 19959 | 19962 | SQLITE_PRIVATE void sqlite3AlterFunctions(void); |
| 19960 | 19963 | SQLITE_PRIVATE void sqlite3AlterRenameTable(Parse*, SrcList*, Token*); |
| 19961 | 19964 | SQLITE_PRIVATE void sqlite3AlterRenameColumn(Parse*, SrcList*, Token*, Token*); |
| 19962 | 19965 | SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *, int *); |
| | @@ -20066,11 +20069,11 @@ |
| 20066 | 20069 | #else |
| 20067 | 20070 | # define sqlite3CloseExtensions(X) |
| 20068 | 20071 | #endif |
| 20069 | 20072 | |
| 20070 | 20073 | #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 *); |
| 20072 | 20075 | #else |
| 20073 | 20076 | #define sqlite3TableLock(v,w,x,y,z) |
| 20074 | 20077 | #endif |
| 20075 | 20078 | |
| 20076 | 20079 | #ifdef SQLITE_TEST |
| | @@ -20788,11 +20791,11 @@ |
| 20788 | 20791 | Bool useRandomRowid:1; /* Generate new record numbers semi-randomly */ |
| 20789 | 20792 | Bool isOrdered:1; /* True if the table is not BTREE_UNORDERED */ |
| 20790 | 20793 | Bool seekHit:1; /* See the OP_SeekHit and OP_IfNoHope opcodes */ |
| 20791 | 20794 | Btree *pBtx; /* Separate file holding temporary table */ |
| 20792 | 20795 | i64 seqCount; /* Sequence counter */ |
| 20793 | | - int *aAltMap; /* Mapping from table to index column numbers */ |
| 20796 | + u32 *aAltMap; /* Mapping from table to index column numbers */ |
| 20794 | 20797 | |
| 20795 | 20798 | /* Cached OP_Column parse information is only valid if cacheStatus matches |
| 20796 | 20799 | ** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of |
| 20797 | 20800 | ** CACHE_STALE (0) and so setting cacheStatus=CACHE_STALE guarantees that |
| 20798 | 20801 | ** the cache is out of date. */ |
| | @@ -21184,11 +21187,11 @@ |
| 21184 | 21187 | */ |
| 21185 | 21188 | SQLITE_PRIVATE void sqlite3VdbeError(Vdbe*, const char *, ...); |
| 21186 | 21189 | SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*); |
| 21187 | 21190 | void sqliteVdbePopStack(Vdbe*,int); |
| 21188 | 21191 | SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeFinishMoveto(VdbeCursor*); |
| 21189 | | -SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor**, int*); |
| 21192 | +SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor**, u32*); |
| 21190 | 21193 | SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor*); |
| 21191 | 21194 | SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32); |
| 21192 | 21195 | SQLITE_PRIVATE u8 sqlite3VdbeOneByteSerialTypeLen(u8); |
| 21193 | 21196 | SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32); |
| 21194 | 21197 | SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*); |
| | @@ -22816,12 +22819,12 @@ |
| 22816 | 22819 | break; |
| 22817 | 22820 | } |
| 22818 | 22821 | case 'm': sqlite3_snprintf(3, &z[j],"%02d",x.M); j+=2; break; |
| 22819 | 22822 | case 'M': sqlite3_snprintf(3, &z[j],"%02d",x.m); j+=2; break; |
| 22820 | 22823 | 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]); |
| 22823 | 22826 | j += sqlite3Strlen30(&z[j]); |
| 22824 | 22827 | break; |
| 22825 | 22828 | } |
| 22826 | 22829 | case 'S': sqlite3_snprintf(3,&z[j],"%02d",(int)x.s); j+=2; break; |
| 22827 | 22830 | case 'w': { |
| | @@ -31770,10 +31773,34 @@ |
| 31770 | 31773 | #endif /* SQLITE_OMIT_FLOATING_POINT */ |
| 31771 | 31774 | } |
| 31772 | 31775 | #if defined(_MSC_VER) |
| 31773 | 31776 | #pragma warning(default : 4756) |
| 31774 | 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 | +} |
| 31775 | 31802 | |
| 31776 | 31803 | /* |
| 31777 | 31804 | ** Compare the 19-character string zNum against the text representation |
| 31778 | 31805 | ** value 2^63: 9223372036854775808. Return negative, zero, or positive |
| 31779 | 31806 | ** if zNum is less than, equal to, or greater than the string. |
| | @@ -32011,13 +32038,31 @@ |
| 32011 | 32038 | ** Return a 32-bit integer value extracted from a string. If the |
| 32012 | 32039 | ** string is not an integer, just return 0. |
| 32013 | 32040 | */ |
| 32014 | 32041 | SQLITE_PRIVATE int sqlite3Atoi(const char *z){ |
| 32015 | 32042 | int x = 0; |
| 32016 | | - if( z ) sqlite3GetInt32(z, &x); |
| 32043 | + sqlite3GetInt32(z, &x); |
| 32017 | 32044 | return x; |
| 32018 | 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 | +} |
| 32019 | 32064 | |
| 32020 | 32065 | /* |
| 32021 | 32066 | ** The variable-length integer encoding is as follows: |
| 32022 | 32067 | ** |
| 32023 | 32068 | ** KEY: |
| | @@ -39188,11 +39233,11 @@ |
| 39188 | 39233 | } |
| 39189 | 39234 | #endif |
| 39190 | 39235 | if( rc!=SQLITE_OK ){ |
| 39191 | 39236 | if( h>=0 ) robust_close(pNew, h, __LINE__); |
| 39192 | 39237 | }else{ |
| 39193 | | - pNew->pMethod = pLockingStyle; |
| 39238 | + pId->pMethods = pLockingStyle; |
| 39194 | 39239 | OpenCounter(+1); |
| 39195 | 39240 | verifyDbFile(pNew); |
| 39196 | 39241 | } |
| 39197 | 39242 | return rc; |
| 39198 | 39243 | } |
| | @@ -46899,11 +46944,11 @@ |
| 46899 | 46944 | { |
| 46900 | 46945 | sqlite3_free(zConverted); |
| 46901 | 46946 | } |
| 46902 | 46947 | |
| 46903 | 46948 | sqlite3_free(zTmpname); |
| 46904 | | - pFile->pMethod = pAppData ? pAppData->pMethod : &winIoMethod; |
| 46949 | + id->pMethods = pAppData ? pAppData->pMethod : &winIoMethod; |
| 46905 | 46950 | pFile->pVfs = pVfs; |
| 46906 | 46951 | pFile->h = h; |
| 46907 | 46952 | if( isReadonly ){ |
| 46908 | 46953 | pFile->ctrlFlags |= WINFILE_RDONLY; |
| 46909 | 46954 | } |
| | @@ -48125,11 +48170,11 @@ |
| 48125 | 48170 | } |
| 48126 | 48171 | memset(p, 0, sizeof(*p)); |
| 48127 | 48172 | p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE; |
| 48128 | 48173 | assert( pOutFlags!=0 ); /* True because flags==SQLITE_OPEN_MAIN_DB */ |
| 48129 | 48174 | *pOutFlags = flags | SQLITE_OPEN_MEMORY; |
| 48130 | | - p->base.pMethods = &memdb_io_methods; |
| 48175 | + pFile->pMethods = &memdb_io_methods; |
| 48131 | 48176 | p->szMax = sqlite3GlobalConfig.mxMemdbSize; |
| 48132 | 48177 | return SQLITE_OK; |
| 48133 | 48178 | } |
| 48134 | 48179 | |
| 48135 | 48180 | #if 0 /* Only used to delete rollback journals, super-journals, and WAL |
| | @@ -52442,15 +52487,10 @@ |
| 52442 | 52487 | # define USEFETCH(x) ((x)->bUseFetch) |
| 52443 | 52488 | #else |
| 52444 | 52489 | # define USEFETCH(x) 0 |
| 52445 | 52490 | #endif |
| 52446 | 52491 | |
| 52447 | | -/* |
| 52448 | | -** The maximum legal page number is (2^31 - 1). |
| 52449 | | -*/ |
| 52450 | | -#define PAGER_MAX_PGNO 2147483647 |
| 52451 | | - |
| 52452 | 52492 | /* |
| 52453 | 52493 | ** The argument to this macro is a file descriptor (type sqlite3_file*). |
| 52454 | 52494 | ** Return 0 if it is not open, or non-zero (but not 1) if it is. |
| 52455 | 52495 | ** |
| 52456 | 52496 | ** This is so that expressions can be written as: |
| | @@ -55419,11 +55459,11 @@ |
| 55419 | 55459 | ** Make no changes if mxPage is zero or negative. And never reduce the |
| 55420 | 55460 | ** maximum page count below the current size of the database. |
| 55421 | 55461 | ** |
| 55422 | 55462 | ** Regardless of mxPage, return the current maximum page count. |
| 55423 | 55463 | */ |
| 55424 | | -SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager *pPager, int mxPage){ |
| 55464 | +SQLITE_PRIVATE Pgno sqlite3PagerMaxPageCount(Pager *pPager, Pgno mxPage){ |
| 55425 | 55465 | if( mxPage>0 ){ |
| 55426 | 55466 | pPager->mxPgno = mxPage; |
| 55427 | 55467 | } |
| 55428 | 55468 | assert( pPager->eState!=PAGER_OPEN ); /* Called only by OP_MaxPgcnt */ |
| 55429 | 55469 | /* assert( pPager->mxPgno>=pPager->dbSize ); */ |
| | @@ -57146,22 +57186,22 @@ |
| 57146 | 57186 | |
| 57147 | 57187 | noContent = (flags & PAGER_GET_NOCONTENT)!=0; |
| 57148 | 57188 | if( pPg->pPager && !noContent ){ |
| 57149 | 57189 | /* In this case the pcache already contains an initialized copy of |
| 57150 | 57190 | ** the page. Return without further ado. */ |
| 57151 | | - assert( pgno<=PAGER_MAX_PGNO && pgno!=PAGER_MJ_PGNO(pPager) ); |
| 57191 | + assert( pgno!=PAGER_MJ_PGNO(pPager) ); |
| 57152 | 57192 | pPager->aStat[PAGER_STAT_HIT]++; |
| 57153 | 57193 | return SQLITE_OK; |
| 57154 | 57194 | |
| 57155 | 57195 | }else{ |
| 57156 | 57196 | /* The pager cache has created a new page. Its content needs to |
| 57157 | 57197 | ** be initialized. But first some error checks: |
| 57158 | 57198 | ** |
| 57159 | | - ** (1) The maximum page number is 2^31 |
| 57199 | + ** (*) obsolete. Was: maximum page number is 2^31 |
| 57160 | 57200 | ** (2) Never try to fetch the locking page |
| 57161 | 57201 | */ |
| 57162 | | - if( pgno>PAGER_MAX_PGNO || pgno==PAGER_MJ_PGNO(pPager) ){ |
| 57202 | + if( pgno==PAGER_MJ_PGNO(pPager) ){ |
| 57163 | 57203 | rc = SQLITE_CORRUPT_BKPT; |
| 57164 | 57204 | goto pager_acquire_err; |
| 57165 | 57205 | } |
| 57166 | 57206 | |
| 57167 | 57207 | pPg->pPager = pPager; |
| | @@ -59863,11 +59903,11 @@ |
| 59863 | 59903 | ** walIteratorFree() - Free an iterator. |
| 59864 | 59904 | ** |
| 59865 | 59905 | ** This functionality is used by the checkpoint code (see walCheckpoint()). |
| 59866 | 59906 | */ |
| 59867 | 59907 | struct WalIterator { |
| 59868 | | - int iPrior; /* Last result returned from the iterator */ |
| 59908 | + u32 iPrior; /* Last result returned from the iterator */ |
| 59869 | 59909 | int nSegment; /* Number of entries in aSegment[] */ |
| 59870 | 59910 | struct WalSegment { |
| 59871 | 59911 | int iNext; /* Next slot in aIndex[] not yet returned */ |
| 59872 | 59912 | ht_slot *aIndex; /* i0, i1, i2... such that aPgno[iN] ascend */ |
| 59873 | 59913 | u32 *aPgno; /* Array of page numbers. */ |
| | @@ -59945,11 +59985,13 @@ |
| 59945 | 59985 | rc = sqlite3OsShmMap(pWal->pDbFd, iPage, WALINDEX_PGSZ, |
| 59946 | 59986 | pWal->writeLock, (void volatile **)&pWal->apWiData[iPage] |
| 59947 | 59987 | ); |
| 59948 | 59988 | assert( pWal->apWiData[iPage]!=0 || rc!=SQLITE_OK || pWal->writeLock==0 ); |
| 59949 | 59989 | 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 ){ |
| 59951 | 59993 | pWal->readOnly |= WAL_SHM_RDONLY; |
| 59952 | 59994 | if( rc==SQLITE_READONLY ){ |
| 59953 | 59995 | rc = SQLITE_OK; |
| 59954 | 59996 | } |
| 59955 | 59997 | } |
| | @@ -60320,10 +60362,11 @@ |
| 60320 | 60362 | && (iHash>=1 || iFrame<=HASHTABLE_NPAGE_ONE) |
| 60321 | 60363 | && (iHash<=1 || iFrame>(HASHTABLE_NPAGE_ONE+HASHTABLE_NPAGE)) |
| 60322 | 60364 | && (iHash>=2 || iFrame<=HASHTABLE_NPAGE_ONE+HASHTABLE_NPAGE) |
| 60323 | 60365 | && (iHash<=2 || iFrame>(HASHTABLE_NPAGE_ONE+2*HASHTABLE_NPAGE)) |
| 60324 | 60366 | ); |
| 60367 | + assert( iHash>=0 ); |
| 60325 | 60368 | return iHash; |
| 60326 | 60369 | } |
| 60327 | 60370 | |
| 60328 | 60371 | /* |
| 60329 | 60372 | ** Return the page number associated with frame iFrame in this WAL. |
| | @@ -60516,16 +60559,10 @@ |
| 60516 | 60559 | assert( WAL_ALL_BUT_WRITE==WAL_WRITE_LOCK+1 ); |
| 60517 | 60560 | assert( WAL_CKPT_LOCK==WAL_ALL_BUT_WRITE ); |
| 60518 | 60561 | assert( pWal->writeLock ); |
| 60519 | 60562 | iLock = WAL_ALL_BUT_WRITE + pWal->ckptLock; |
| 60520 | 60563 | 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 | 60564 | if( rc ){ |
| 60528 | 60565 | return rc; |
| 60529 | 60566 | } |
| 60530 | 60567 | |
| 60531 | 60568 | WALTRACE(("WAL%p: recovery begin...\n", pWal)); |
| | @@ -60537,19 +60574,20 @@ |
| 60537 | 60574 | goto recovery_error; |
| 60538 | 60575 | } |
| 60539 | 60576 | |
| 60540 | 60577 | if( nSize>WAL_HDRSIZE ){ |
| 60541 | 60578 | u8 aBuf[WAL_HDRSIZE]; /* Buffer to load WAL header into */ |
| 60579 | + u32 *aPrivate = 0; /* Heap copy of *-shm hash being populated */ |
| 60542 | 60580 | u8 *aFrame = 0; /* Malloc'd buffer to load entire frame */ |
| 60543 | 60581 | int szFrame; /* Number of bytes in buffer aFrame[] */ |
| 60544 | 60582 | 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 | 60583 | int szPage; /* Page size according to the log */ |
| 60548 | 60584 | u32 magic; /* Magic value read from WAL header */ |
| 60549 | 60585 | u32 version; /* Magic value read from WAL header */ |
| 60550 | 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 */ |
| 60551 | 60589 | |
| 60552 | 60590 | /* Read in the WAL header. */ |
| 60553 | 60591 | rc = sqlite3OsRead(pWal->pWalFd, aBuf, WAL_HDRSIZE, 0); |
| 60554 | 60592 | if( rc!=SQLITE_OK ){ |
| 60555 | 60593 | goto recovery_error; |
| | @@ -60592,42 +60630,59 @@ |
| 60592 | 60630 | goto finished; |
| 60593 | 60631 | } |
| 60594 | 60632 | |
| 60595 | 60633 | /* Malloc a buffer to read frames into. */ |
| 60596 | 60634 | szFrame = szPage + WAL_FRAME_HDRSIZE; |
| 60597 | | - aFrame = (u8 *)sqlite3_malloc64(szFrame); |
| 60635 | + aFrame = (u8 *)sqlite3_malloc64(szFrame + WALINDEX_PGSZ); |
| 60598 | 60636 | if( !aFrame ){ |
| 60599 | 60637 | rc = SQLITE_NOMEM_BKPT; |
| 60600 | 60638 | goto recovery_error; |
| 60601 | 60639 | } |
| 60602 | 60640 | aData = &aFrame[WAL_FRAME_HDRSIZE]; |
| 60641 | + aPrivate = (u32*)&aData[szPage]; |
| 60603 | 60642 | |
| 60604 | 60643 | /* 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; |
| 60629 | 60684 | } |
| 60630 | 60685 | |
| 60631 | 60686 | sqlite3_free(aFrame); |
| 60632 | 60687 | } |
| 60633 | 60688 | |
| | @@ -60638,19 +60693,30 @@ |
| 60638 | 60693 | pWal->hdr.aFrameCksum[0] = aFrameCksum[0]; |
| 60639 | 60694 | pWal->hdr.aFrameCksum[1] = aFrameCksum[1]; |
| 60640 | 60695 | walIndexWriteHdr(pWal); |
| 60641 | 60696 | |
| 60642 | 60697 | /* 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. |
| 60645 | 60700 | */ |
| 60646 | 60701 | pInfo = walCkptInfo(pWal); |
| 60647 | 60702 | pInfo->nBackfill = 0; |
| 60648 | 60703 | pInfo->nBackfillAttempted = pWal->hdr.mxFrame; |
| 60649 | 60704 | 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 | + } |
| 60652 | 60718 | |
| 60653 | 60719 | /* If more than one frame was recovered from the log file, report an |
| 60654 | 60720 | ** event via sqlite3_log(). This is to help with identifying performance |
| 60655 | 60721 | ** problems caused by applications routinely shutting down without |
| 60656 | 60722 | ** checkpointing the log file. |
| | @@ -60664,11 +60730,10 @@ |
| 60664 | 60730 | } |
| 60665 | 60731 | |
| 60666 | 60732 | recovery_error: |
| 60667 | 60733 | WALTRACE(("WAL%p: recovery %s\n", pWal, rc ? "failed" : "ok")); |
| 60668 | 60734 | walUnlockExclusive(pWal, iLock, WAL_READ_LOCK(0)-iLock); |
| 60669 | | - walUnlockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1); |
| 60670 | 60735 | return rc; |
| 60671 | 60736 | } |
| 60672 | 60737 | |
| 60673 | 60738 | /* |
| 60674 | 60739 | ** Close an open wal-index. |
| | @@ -64048,11 +64113,12 @@ |
| 64048 | 64113 | Pgno nPage; /* Number of pages in the database */ |
| 64049 | 64114 | int mxErr; /* Stop accumulating errors when this reaches zero */ |
| 64050 | 64115 | int nErr; /* Number of messages written to zErrMsg so far */ |
| 64051 | 64116 | int bOomFault; /* A memory allocation error has occurred */ |
| 64052 | 64117 | 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 */ |
| 64054 | 64120 | StrAccum errMsg; /* Accumulate the error message text here */ |
| 64055 | 64121 | u32 *heap; /* Min-heap used for analyzing cell coverage */ |
| 64056 | 64122 | sqlite3 *db; /* Database connection running the check */ |
| 64057 | 64123 | }; |
| 64058 | 64124 | |
| | @@ -66513,16 +66579,15 @@ |
| 66513 | 66579 | /* |
| 66514 | 66580 | ** Return the size of the database file in pages. If there is any kind of |
| 66515 | 66581 | ** error, return ((unsigned int)-1). |
| 66516 | 66582 | */ |
| 66517 | 66583 | static Pgno btreePagecount(BtShared *pBt){ |
| 66518 | | - assert( (pBt->nPage & 0x80000000)==0 || CORRUPT_DB ); |
| 66519 | 66584 | return pBt->nPage; |
| 66520 | 66585 | } |
| 66521 | | -SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree *p){ |
| 66586 | +SQLITE_PRIVATE Pgno sqlite3BtreeLastPage(Btree *p){ |
| 66522 | 66587 | assert( sqlite3BtreeHoldsMutex(p) ); |
| 66523 | | - return btreePagecount(p->pBt) & 0x7fffffff; |
| 66588 | + return btreePagecount(p->pBt); |
| 66524 | 66589 | } |
| 66525 | 66590 | |
| 66526 | 66591 | /* |
| 66527 | 66592 | ** Get a page from the pager and initialize it. |
| 66528 | 66593 | ** |
| | @@ -67306,12 +67371,12 @@ |
| 67306 | 67371 | /* |
| 67307 | 67372 | ** Set the maximum page count for a database if mxPage is positive. |
| 67308 | 67373 | ** No changes are made if mxPage is 0 or negative. |
| 67309 | 67374 | ** Regardless of the value of mxPage, return the maximum page count. |
| 67310 | 67375 | */ |
| 67311 | | -SQLITE_PRIVATE int sqlite3BtreeMaxPageCount(Btree *p, int mxPage){ |
| 67312 | | - int n; |
| 67376 | +SQLITE_PRIVATE Pgno sqlite3BtreeMaxPageCount(Btree *p, Pgno mxPage){ |
| 67377 | + Pgno n; |
| 67313 | 67378 | sqlite3BtreeEnter(p); |
| 67314 | 67379 | n = sqlite3PagerMaxPageCount(p->pBt->pPager, mxPage); |
| 67315 | 67380 | sqlite3BtreeLeave(p); |
| 67316 | 67381 | return n; |
| 67317 | 67382 | } |
| | @@ -68746,11 +68811,11 @@ |
| 68746 | 68811 | ** It is assumed that the sqlite3BtreeCursorZero() has been called |
| 68747 | 68812 | ** on pCur to initialize the memory space prior to invoking this routine. |
| 68748 | 68813 | */ |
| 68749 | 68814 | static int btreeCursor( |
| 68750 | 68815 | Btree *p, /* The btree */ |
| 68751 | | - int iTable, /* Root page of table to open */ |
| 68816 | + Pgno iTable, /* Root page of table to open */ |
| 68752 | 68817 | int wrFlag, /* 1 to write. 0 read-only */ |
| 68753 | 68818 | struct KeyInfo *pKeyInfo, /* First arg to comparison function */ |
| 68754 | 68819 | BtCursor *pCur /* Space for new cursor */ |
| 68755 | 68820 | ){ |
| 68756 | 68821 | BtShared *pBt = p->pBt; /* Shared b-tree handle */ |
| | @@ -68789,21 +68854,21 @@ |
| 68789 | 68854 | } |
| 68790 | 68855 | } |
| 68791 | 68856 | |
| 68792 | 68857 | /* Now that no other errors can occur, finish filling in the BtCursor |
| 68793 | 68858 | ** variables and link the cursor into the BtShared list. */ |
| 68794 | | - pCur->pgnoRoot = (Pgno)iTable; |
| 68859 | + pCur->pgnoRoot = iTable; |
| 68795 | 68860 | pCur->iPage = -1; |
| 68796 | 68861 | pCur->pKeyInfo = pKeyInfo; |
| 68797 | 68862 | pCur->pBtree = p; |
| 68798 | 68863 | pCur->pBt = pBt; |
| 68799 | 68864 | pCur->curFlags = wrFlag ? BTCF_WriteFlag : 0; |
| 68800 | 68865 | pCur->curPagerFlags = wrFlag ? 0 : PAGER_GET_READONLY; |
| 68801 | 68866 | /* If there are two or more cursors on the same btree, then all such |
| 68802 | 68867 | ** cursors *must* have the BTCF_Multiple flag set. */ |
| 68803 | 68868 | for(pX=pBt->pCursor; pX; pX=pX->pNext){ |
| 68804 | | - if( pX->pgnoRoot==(Pgno)iTable ){ |
| 68869 | + if( pX->pgnoRoot==iTable ){ |
| 68805 | 68870 | pX->curFlags |= BTCF_Multiple; |
| 68806 | 68871 | pCur->curFlags |= BTCF_Multiple; |
| 68807 | 68872 | } |
| 68808 | 68873 | } |
| 68809 | 68874 | pCur->pNext = pBt->pCursor; |
| | @@ -68811,11 +68876,11 @@ |
| 68811 | 68876 | pCur->eState = CURSOR_INVALID; |
| 68812 | 68877 | return SQLITE_OK; |
| 68813 | 68878 | } |
| 68814 | 68879 | static int btreeCursorWithLock( |
| 68815 | 68880 | Btree *p, /* The btree */ |
| 68816 | | - int iTable, /* Root page of table to open */ |
| 68881 | + Pgno iTable, /* Root page of table to open */ |
| 68817 | 68882 | int wrFlag, /* 1 to write. 0 read-only */ |
| 68818 | 68883 | struct KeyInfo *pKeyInfo, /* First arg to comparison function */ |
| 68819 | 68884 | BtCursor *pCur /* Space for new cursor */ |
| 68820 | 68885 | ){ |
| 68821 | 68886 | int rc; |
| | @@ -68824,11 +68889,11 @@ |
| 68824 | 68889 | sqlite3BtreeLeave(p); |
| 68825 | 68890 | return rc; |
| 68826 | 68891 | } |
| 68827 | 68892 | SQLITE_PRIVATE int sqlite3BtreeCursor( |
| 68828 | 68893 | Btree *p, /* The btree */ |
| 68829 | | - int iTable, /* Root page of table to open */ |
| 68894 | + Pgno iTable, /* Root page of table to open */ |
| 68830 | 68895 | int wrFlag, /* 1 to write. 0 read-only */ |
| 68831 | 68896 | struct KeyInfo *pKeyInfo, /* First arg to xCompare() */ |
| 68832 | 68897 | BtCursor *pCur /* Write new cursor here */ |
| 68833 | 68898 | ){ |
| 68834 | 68899 | if( p->sharable ){ |
| | @@ -69249,10 +69314,11 @@ |
| 69249 | 69314 | } |
| 69250 | 69315 | |
| 69251 | 69316 | assert( rc==SQLITE_OK && amt>0 ); |
| 69252 | 69317 | while( nextPage ){ |
| 69253 | 69318 | /* If required, populate the overflow page-list cache. */ |
| 69319 | + if( nextPage > pBt->nPage ) return SQLITE_CORRUPT_BKPT; |
| 69254 | 69320 | assert( pCur->aOverflow[iIdx]==0 |
| 69255 | 69321 | || pCur->aOverflow[iIdx]==nextPage |
| 69256 | 69322 | || CORRUPT_DB ); |
| 69257 | 69323 | pCur->aOverflow[iIdx] = nextPage; |
| 69258 | 69324 | |
| | @@ -70321,11 +70387,11 @@ |
| 70321 | 70387 | ** shows that the page 'nearby' is somewhere on the free-list, then |
| 70322 | 70388 | ** the entire-list will be searched for that page. |
| 70323 | 70389 | */ |
| 70324 | 70390 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 70325 | 70391 | if( eMode==BTALLOC_EXACT ){ |
| 70326 | | - if( nearby<=mxPage ){ |
| 70392 | + if( ALWAYS(nearby<=mxPage) ){ |
| 70327 | 70393 | u8 eType; |
| 70328 | 70394 | assert( nearby>0 ); |
| 70329 | 70395 | assert( pBt->autoVacuum ); |
| 70330 | 70396 | rc = ptrmapGet(pBt, nearby, &eType, 0); |
| 70331 | 70397 | if( rc ) return rc; |
| | @@ -70617,11 +70683,11 @@ |
| 70617 | 70683 | |
| 70618 | 70684 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 70619 | 70685 | assert( CORRUPT_DB || iPage>1 ); |
| 70620 | 70686 | assert( !pMemPage || pMemPage->pgno==iPage ); |
| 70621 | 70687 | |
| 70622 | | - if( iPage<2 || iPage>pBt->nPage ){ |
| 70688 | + if( iPage<2 || NEVER(iPage>pBt->nPage) ){ |
| 70623 | 70689 | return SQLITE_CORRUPT_BKPT; |
| 70624 | 70690 | } |
| 70625 | 70691 | if( pMemPage ){ |
| 70626 | 70692 | pPage = pMemPage; |
| 70627 | 70693 | sqlite3PagerRef(pPage->pDbPage); |
| | @@ -70664,10 +70730,14 @@ |
| 70664 | 70730 | */ |
| 70665 | 70731 | if( nFree!=0 ){ |
| 70666 | 70732 | u32 nLeaf; /* Initial number of leaf cells on trunk page */ |
| 70667 | 70733 | |
| 70668 | 70734 | iTrunk = get4byte(&pPage1->aData[32]); |
| 70735 | + if( iTrunk>btreePagecount(pBt) ){ |
| 70736 | + rc = SQLITE_CORRUPT_BKPT; |
| 70737 | + goto freepage_out; |
| 70738 | + } |
| 70669 | 70739 | rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0); |
| 70670 | 70740 | if( rc!=SQLITE_OK ){ |
| 70671 | 70741 | goto freepage_out; |
| 70672 | 70742 | } |
| 70673 | 70743 | |
| | @@ -73468,11 +73538,11 @@ |
| 73468 | 73538 | ** flags might not work: |
| 73469 | 73539 | ** |
| 73470 | 73540 | ** BTREE_INTKEY|BTREE_LEAFDATA Used for SQL tables with rowid keys |
| 73471 | 73541 | ** BTREE_ZERODATA Used for SQL indices |
| 73472 | 73542 | */ |
| 73473 | | -static int btreeCreateTable(Btree *p, int *piTable, int createTabFlags){ |
| 73543 | +static int btreeCreateTable(Btree *p, Pgno *piTable, int createTabFlags){ |
| 73474 | 73544 | BtShared *pBt = p->pBt; |
| 73475 | 73545 | MemPage *pRoot; |
| 73476 | 73546 | Pgno pgnoRoot; |
| 73477 | 73547 | int rc; |
| 73478 | 73548 | int ptfFlags; /* Page-type flage for the root page of new table */ |
| | @@ -73501,21 +73571,23 @@ |
| 73501 | 73571 | /* Read the value of meta[3] from the database to determine where the |
| 73502 | 73572 | ** root page of the new table should go. meta[3] is the largest root-page |
| 73503 | 73573 | ** created so far, so the new root-page is (meta[3]+1). |
| 73504 | 73574 | */ |
| 73505 | 73575 | sqlite3BtreeGetMeta(p, BTREE_LARGEST_ROOT_PAGE, &pgnoRoot); |
| 73576 | + if( pgnoRoot>btreePagecount(pBt) ){ |
| 73577 | + return SQLITE_CORRUPT_BKPT; |
| 73578 | + } |
| 73506 | 73579 | pgnoRoot++; |
| 73507 | 73580 | |
| 73508 | 73581 | /* The new root-page may not be allocated on a pointer-map page, or the |
| 73509 | 73582 | ** PENDING_BYTE page. |
| 73510 | 73583 | */ |
| 73511 | 73584 | while( pgnoRoot==PTRMAP_PAGENO(pBt, pgnoRoot) || |
| 73512 | 73585 | pgnoRoot==PENDING_BYTE_PAGE(pBt) ){ |
| 73513 | 73586 | pgnoRoot++; |
| 73514 | 73587 | } |
| 73515 | | - assert( pgnoRoot>=3 || CORRUPT_DB ); |
| 73516 | | - testcase( pgnoRoot<3 ); |
| 73588 | + assert( pgnoRoot>=3 ); |
| 73517 | 73589 | |
| 73518 | 73590 | /* Allocate a page. The page that currently resides at pgnoRoot will |
| 73519 | 73591 | ** be moved to the allocated page (unless the allocated page happens |
| 73520 | 73592 | ** to reside at pgnoRoot). |
| 73521 | 73593 | */ |
| | @@ -73608,14 +73680,14 @@ |
| 73608 | 73680 | ptfFlags = PTF_ZERODATA | PTF_LEAF; |
| 73609 | 73681 | } |
| 73610 | 73682 | zeroPage(pRoot, ptfFlags); |
| 73611 | 73683 | sqlite3PagerUnref(pRoot->pDbPage); |
| 73612 | 73684 | assert( (pBt->openFlags & BTREE_SINGLE)==0 || pgnoRoot==2 ); |
| 73613 | | - *piTable = (int)pgnoRoot; |
| 73685 | + *piTable = pgnoRoot; |
| 73614 | 73686 | return SQLITE_OK; |
| 73615 | 73687 | } |
| 73616 | | -SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree *p, int *piTable, int flags){ |
| 73688 | +SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree *p, Pgno *piTable, int flags){ |
| 73617 | 73689 | int rc; |
| 73618 | 73690 | sqlite3BtreeEnter(p); |
| 73619 | 73691 | rc = btreeCreateTable(p, piTable, flags); |
| 73620 | 73692 | sqlite3BtreeLeave(p); |
| 73621 | 73693 | return rc; |
| | @@ -74095,11 +74167,11 @@ |
| 74095 | 74167 | ** Verify that the number of pages on the list is N. |
| 74096 | 74168 | */ |
| 74097 | 74169 | static void checkList( |
| 74098 | 74170 | IntegrityCk *pCheck, /* Integrity checking context */ |
| 74099 | 74171 | 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 */ |
| 74101 | 74173 | u32 N /* Expected number of pages in the list */ |
| 74102 | 74174 | ){ |
| 74103 | 74175 | int i; |
| 74104 | 74176 | u32 expected = N; |
| 74105 | 74177 | int nErrAtStart = pCheck->nErr; |
| | @@ -74227,11 +74299,11 @@ |
| 74227 | 74299 | ** 4. Recursively call checkTreePage on all children. |
| 74228 | 74300 | ** 5. Verify that the depth of all children is the same. |
| 74229 | 74301 | */ |
| 74230 | 74302 | static int checkTreePage( |
| 74231 | 74303 | 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 */ |
| 74233 | 74305 | i64 *piMinKey, /* Write minimum integer primary key here */ |
| 74234 | 74306 | i64 maxKey /* Error if integer primary key greater than this */ |
| 74235 | 74307 | ){ |
| 74236 | 74308 | MemPage *pPage = 0; /* The page being analyzed */ |
| 74237 | 74309 | int i; /* Loop counter */ |
| | @@ -74263,13 +74335,13 @@ |
| 74263 | 74335 | */ |
| 74264 | 74336 | pBt = pCheck->pBt; |
| 74265 | 74337 | usableSize = pBt->usableSize; |
| 74266 | 74338 | if( iPage==0 ) return 0; |
| 74267 | 74339 | if( checkRef(pCheck, iPage) ) return 0; |
| 74268 | | - pCheck->zPfx = "Page %d: "; |
| 74340 | + pCheck->zPfx = "Page %u: "; |
| 74269 | 74341 | pCheck->v1 = iPage; |
| 74270 | | - if( (rc = btreeGetPage(pBt, (Pgno)iPage, &pPage, 0))!=0 ){ |
| 74342 | + if( (rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0 ){ |
| 74271 | 74343 | checkAppendMsg(pCheck, |
| 74272 | 74344 | "unable to get the page. error code=%d", rc); |
| 74273 | 74345 | goto end_of_check; |
| 74274 | 74346 | } |
| 74275 | 74347 | |
| | @@ -74290,11 +74362,11 @@ |
| 74290 | 74362 | } |
| 74291 | 74363 | data = pPage->aData; |
| 74292 | 74364 | hdr = pPage->hdrOffset; |
| 74293 | 74365 | |
| 74294 | 74366 | /* Set up for cell analysis */ |
| 74295 | | - pCheck->zPfx = "On tree page %d cell %d: "; |
| 74367 | + pCheck->zPfx = "On tree page %u cell %d: "; |
| 74296 | 74368 | contentOffset = get2byteNotZero(&data[hdr+5]); |
| 74297 | 74369 | assert( contentOffset<=usableSize ); /* Enforced by btreeInitPage() */ |
| 74298 | 74370 | |
| 74299 | 74371 | /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the |
| 74300 | 74372 | ** number of cells on the page. */ |
| | @@ -74310,11 +74382,11 @@ |
| 74310 | 74382 | if( !pPage->leaf ){ |
| 74311 | 74383 | /* Analyze the right-child page of internal pages */ |
| 74312 | 74384 | pgno = get4byte(&data[hdr+8]); |
| 74313 | 74385 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 74314 | 74386 | if( pBt->autoVacuum ){ |
| 74315 | | - pCheck->zPfx = "On page %d at right child: "; |
| 74387 | + pCheck->zPfx = "On page %u at right child: "; |
| 74316 | 74388 | checkPtrmap(pCheck, pgno, PTRMAP_BTREE, iPage); |
| 74317 | 74389 | } |
| 74318 | 74390 | #endif |
| 74319 | 74391 | depth = checkTreePage(pCheck, pgno, &maxKey, maxKey); |
| 74320 | 74392 | keyCanBeEqual = 0; |
| | @@ -74451,11 +74523,11 @@ |
| 74451 | 74523 | nFrag = 0; |
| 74452 | 74524 | prev = contentOffset - 1; /* Implied first min-heap entry */ |
| 74453 | 74525 | while( btreeHeapPull(heap,&x) ){ |
| 74454 | 74526 | if( (prev&0xffff)>=(x>>16) ){ |
| 74455 | 74527 | 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); |
| 74457 | 74529 | break; |
| 74458 | 74530 | }else{ |
| 74459 | 74531 | nFrag += (x>>16) - (prev&0xffff) - 1; |
| 74460 | 74532 | prev = x; |
| 74461 | 74533 | } |
| | @@ -74466,11 +74538,11 @@ |
| 74466 | 74538 | ** EVIDENCE-OF: R-07161-27322 The one-byte integer at offset 7 gives the |
| 74467 | 74539 | ** number of fragmented free bytes within the cell content area. |
| 74468 | 74540 | */ |
| 74469 | 74541 | if( heap[0]==0 && nFrag!=data[hdr+7] ){ |
| 74470 | 74542 | checkAppendMsg(pCheck, |
| 74471 | | - "Fragmentation of %d bytes reported as %d on page %d", |
| 74543 | + "Fragmentation of %d bytes reported as %d on page %u", |
| 74472 | 74544 | nFrag, data[hdr+7], iPage); |
| 74473 | 74545 | } |
| 74474 | 74546 | } |
| 74475 | 74547 | |
| 74476 | 74548 | end_of_check: |
| | @@ -74494,25 +74566,44 @@ |
| 74494 | 74566 | ** |
| 74495 | 74567 | ** Write the number of error seen in *pnErr. Except for some memory |
| 74496 | 74568 | ** allocation errors, an error message held in memory obtained from |
| 74497 | 74569 | ** malloc is returned if *pnErr is non-zero. If *pnErr==0 then NULL is |
| 74498 | 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. |
| 74499 | 74580 | */ |
| 74500 | 74581 | SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck( |
| 74501 | 74582 | sqlite3 *db, /* Database connection that is running the check */ |
| 74502 | 74583 | 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 */ |
| 74504 | 74585 | int nRoot, /* Number of entries in aRoot[] */ |
| 74505 | 74586 | int mxErr, /* Stop reporting errors after this many */ |
| 74506 | 74587 | int *pnErr /* Write number of errors seen to this variable */ |
| 74507 | 74588 | ){ |
| 74508 | 74589 | Pgno i; |
| 74509 | 74590 | IntegrityCk sCheck; |
| 74510 | 74591 | BtShared *pBt = p->pBt; |
| 74511 | 74592 | u64 savedDbFlags = pBt->db->flags; |
| 74512 | 74593 | char zErr[100]; |
| 74594 | + int bPartial = 0; /* True if not checking all btrees */ |
| 74595 | + int bCkFreelist = 1; /* True to scan the freelist */ |
| 74513 | 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 | + } |
| 74514 | 74605 | |
| 74515 | 74606 | sqlite3BtreeEnter(p); |
| 74516 | 74607 | assert( p->inTrans>TRANS_NONE && pBt->inTransaction>TRANS_NONE ); |
| 74517 | 74608 | VVA_ONLY( nRef = sqlite3PagerRefcount(pBt->pPager) ); |
| 74518 | 74609 | assert( nRef>=0 ); |
| | @@ -74548,67 +74639,73 @@ |
| 74548 | 74639 | i = PENDING_BYTE_PAGE(pBt); |
| 74549 | 74640 | if( i<=sCheck.nPage ) setPageReferenced(&sCheck, i); |
| 74550 | 74641 | |
| 74551 | 74642 | /* Check the integrity of the freelist |
| 74552 | 74643 | */ |
| 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 | + } |
| 74557 | 74650 | |
| 74558 | 74651 | /* Check all the tables. |
| 74559 | 74652 | */ |
| 74560 | 74653 | #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 | + } |
| 74576 | 74671 | } |
| 74577 | 74672 | #endif |
| 74578 | 74673 | testcase( pBt->db->flags & SQLITE_CellSizeCk ); |
| 74579 | 74674 | pBt->db->flags &= ~(u64)SQLITE_CellSizeCk; |
| 74580 | 74675 | for(i=0; (int)i<nRoot && sCheck.mxErr; i++){ |
| 74581 | 74676 | i64 notUsed; |
| 74582 | 74677 | if( aRoot[i]==0 ) continue; |
| 74583 | 74678 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 74584 | | - if( pBt->autoVacuum && aRoot[i]>1 ){ |
| 74679 | + if( pBt->autoVacuum && aRoot[i]>1 && !bPartial ){ |
| 74585 | 74680 | checkPtrmap(&sCheck, aRoot[i], PTRMAP_ROOTPAGE, 0); |
| 74586 | 74681 | } |
| 74587 | 74682 | #endif |
| 74588 | 74683 | checkTreePage(&sCheck, aRoot[i], ¬Used, LARGEST_INT64); |
| 74589 | 74684 | } |
| 74590 | 74685 | pBt->db->flags = savedDbFlags; |
| 74591 | 74686 | |
| 74592 | 74687 | /* Make sure every page in the file is referenced |
| 74593 | 74688 | */ |
| 74594 | | - for(i=1; i<=sCheck.nPage && sCheck.mxErr; i++){ |
| 74689 | + if( !bPartial ){ |
| 74690 | + for(i=1; i<=sCheck.nPage && sCheck.mxErr; i++){ |
| 74595 | 74691 | #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 | + } |
| 74599 | 74695 | #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 | + } |
| 74610 | 74707 | } |
| 74611 | 74708 | #endif |
| 74612 | 74709 | } |
| 74613 | 74710 | |
| 74614 | 74711 | /* Clean up and report errors. |
| | @@ -75794,20 +75891,29 @@ |
| 75794 | 75891 | ** into a buffer. |
| 75795 | 75892 | */ |
| 75796 | 75893 | static void vdbeMemRenderNum(int sz, char *zBuf, Mem *p){ |
| 75797 | 75894 | StrAccum acc; |
| 75798 | 75895 | assert( p->flags & (MEM_Int|MEM_Real|MEM_IntReal) ); |
| 75799 | | - sqlite3StrAccumInit(&acc, 0, zBuf, sz, 0); |
| 75896 | + assert( sz>22 ); |
| 75800 | 75897 | 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 |
| 75804 | 75908 | }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) */ |
| 75806 | 75914 | } |
| 75807 | | - assert( acc.zText==zBuf && acc.mxAlloc<=0 ); |
| 75808 | | - zBuf[acc.nChar] = 0; /* Fast version of sqlite3StrAccumFinish(&acc) */ |
| 75809 | 75915 | } |
| 75810 | 75916 | |
| 75811 | 75917 | #ifdef SQLITE_DEBUG |
| 75812 | 75918 | /* |
| 75813 | 75919 | ** Validity checks on pMem. pMem holds a string. |
| | @@ -79301,16 +79407,16 @@ |
| 79301 | 79407 | sqlite3_str_appendf(&x, "vtab:%p", pVtab); |
| 79302 | 79408 | break; |
| 79303 | 79409 | } |
| 79304 | 79410 | #endif |
| 79305 | 79411 | 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 |
| 79309 | 79415 | ** count of the number of elements to follow */ |
| 79310 | 79416 | 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]); |
| 79312 | 79418 | } |
| 79313 | 79419 | sqlite3_str_append(&x, "]", 1); |
| 79314 | 79420 | break; |
| 79315 | 79421 | } |
| 79316 | 79422 | case P4_SUBPROGRAM: { |
| | @@ -81150,15 +81256,15 @@ |
| 81150 | 81256 | ** a NULL row. |
| 81151 | 81257 | ** |
| 81152 | 81258 | ** If the cursor is already pointing to the correct row and that row has |
| 81153 | 81259 | ** not been deleted out from under the cursor, then this routine is a no-op. |
| 81154 | 81260 | */ |
| 81155 | | -SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor **pp, int *piCol){ |
| 81261 | +SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor **pp, u32 *piCol){ |
| 81156 | 81262 | VdbeCursor *p = *pp; |
| 81157 | 81263 | assert( p->eCurType==CURTYPE_BTREE || p->eCurType==CURTYPE_PSEUDO ); |
| 81158 | 81264 | if( p->deferredMoveto ){ |
| 81159 | | - int iMap; |
| 81265 | + u32 iMap; |
| 81160 | 81266 | if( p->aAltMap && (iMap = p->aAltMap[1+*piCol])>0 && !p->nullRow ){ |
| 81161 | 81267 | *pp = p->pAltCursor; |
| 81162 | 81268 | *piCol = iMap - 1; |
| 81163 | 81269 | return SQLITE_OK; |
| 81164 | 81270 | } |
| | @@ -87427,14 +87533,14 @@ |
| 87427 | 87533 | int n; |
| 87428 | 87534 | int i; |
| 87429 | 87535 | int p1; |
| 87430 | 87536 | int p2; |
| 87431 | 87537 | const KeyInfo *pKeyInfo; |
| 87432 | | - int idx; |
| 87538 | + u32 idx; |
| 87433 | 87539 | CollSeq *pColl; /* Collating sequence to use on this term */ |
| 87434 | 87540 | int bRev; /* True for DESCENDING sort order */ |
| 87435 | | - int *aPermute; /* The permutation */ |
| 87541 | + u32 *aPermute; /* The permutation */ |
| 87436 | 87542 | |
| 87437 | 87543 | if( (pOp->p5 & OPFLAG_PERMUTE)==0 ){ |
| 87438 | 87544 | aPermute = 0; |
| 87439 | 87545 | }else{ |
| 87440 | 87546 | assert( pOp>aOp ); |
| | @@ -87459,11 +87565,11 @@ |
| 87459 | 87565 | assert( p1>0 && p1+n<=(p->nMem+1 - p->nCursor)+1 ); |
| 87460 | 87566 | assert( p2>0 && p2+n<=(p->nMem+1 - p->nCursor)+1 ); |
| 87461 | 87567 | } |
| 87462 | 87568 | #endif /* SQLITE_DEBUG */ |
| 87463 | 87569 | for(i=0; i<n; i++){ |
| 87464 | | - idx = aPermute ? aPermute[i] : i; |
| 87570 | + idx = aPermute ? aPermute[i] : (u32)i; |
| 87465 | 87571 | assert( memIsValid(&aMem[p1+idx]) ); |
| 87466 | 87572 | assert( memIsValid(&aMem[p2+idx]) ); |
| 87467 | 87573 | REGISTER_TRACE(p1+idx, &aMem[p1+idx]); |
| 87468 | 87574 | REGISTER_TRACE(p2+idx, &aMem[p2+idx]); |
| 87469 | 87575 | assert( i<pKeyInfo->nKeyField ); |
| | @@ -87770,11 +87876,11 @@ |
| 87770 | 87876 | ** the result is guaranteed to only be used as the argument of a length() |
| 87771 | 87877 | ** or typeof() function, respectively. The loading of large blobs can be |
| 87772 | 87878 | ** skipped for length() and all content loading can be skipped for typeof(). |
| 87773 | 87879 | */ |
| 87774 | 87880 | case OP_Column: { |
| 87775 | | - int p2; /* column number to retrieve */ |
| 87881 | + u32 p2; /* column number to retrieve */ |
| 87776 | 87882 | VdbeCursor *pC; /* The VDBE cursor */ |
| 87777 | 87883 | BtCursor *pCrsr; /* The BTree cursor */ |
| 87778 | 87884 | u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */ |
| 87779 | 87885 | int len; /* The length of the serialized data for the column */ |
| 87780 | 87886 | int i; /* Loop counter */ |
| | @@ -87788,11 +87894,11 @@ |
| 87788 | 87894 | Mem *pReg; /* PseudoTable input register */ |
| 87789 | 87895 | |
| 87790 | 87896 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 87791 | 87897 | pC = p->apCsr[pOp->p1]; |
| 87792 | 87898 | assert( pC!=0 ); |
| 87793 | | - p2 = pOp->p2; |
| 87899 | + p2 = (u32)pOp->p2; |
| 87794 | 87900 | |
| 87795 | 87901 | /* If the cursor cache is stale (meaning it is not currently point at |
| 87796 | 87902 | ** the correct row) then bring it up-to-date by doing the necessary |
| 87797 | 87903 | ** B-Tree seek. */ |
| 87798 | 87904 | rc = sqlite3VdbeCursorMoveto(&pC, &p2); |
| | @@ -87915,11 +88021,11 @@ |
| 87915 | 88021 | zHdr += sqlite3GetVarint32(zHdr, &t); |
| 87916 | 88022 | pC->aType[i] = t; |
| 87917 | 88023 | offset64 += sqlite3VdbeSerialTypeLen(t); |
| 87918 | 88024 | } |
| 87919 | 88025 | aOffset[++i] = (u32)(offset64 & 0xffffffff); |
| 87920 | | - }while( i<=p2 && zHdr<zEndHdr ); |
| 88026 | + }while( (u32)i<=p2 && zHdr<zEndHdr ); |
| 87921 | 88027 | |
| 87922 | 88028 | /* The record is corrupt if any of the following are true: |
| 87923 | 88029 | ** (1) the bytes of the header extend past the declared header size |
| 87924 | 88030 | ** (2) the entire header was used but not all data was used |
| 87925 | 88031 | ** (3) the end of the data extends beyond the end of the record. |
| | @@ -88939,11 +89045,11 @@ |
| 88939 | 89045 | ** See also: OP_OpenRead, OP_ReopenIdx |
| 88940 | 89046 | */ |
| 88941 | 89047 | case OP_ReopenIdx: { |
| 88942 | 89048 | int nField; |
| 88943 | 89049 | KeyInfo *pKeyInfo; |
| 88944 | | - int p2; |
| 89050 | + u32 p2; |
| 88945 | 89051 | int iDb; |
| 88946 | 89052 | int wrFlag; |
| 88947 | 89053 | Btree *pX; |
| 88948 | 89054 | VdbeCursor *pCur; |
| 88949 | 89055 | Db *pDb; |
| | @@ -88970,11 +89076,11 @@ |
| 88970 | 89076 | goto abort_due_to_error; |
| 88971 | 89077 | } |
| 88972 | 89078 | |
| 88973 | 89079 | nField = 0; |
| 88974 | 89080 | pKeyInfo = 0; |
| 88975 | | - p2 = pOp->p2; |
| 89081 | + p2 = (u32)pOp->p2; |
| 88976 | 89082 | iDb = pOp->p3; |
| 88977 | 89083 | assert( iDb>=0 && iDb<db->nDb ); |
| 88978 | 89084 | assert( DbMaskTest(p->btreeMask, iDb) ); |
| 88979 | 89085 | pDb = &db->aDb[iDb]; |
| 88980 | 89086 | pX = pDb->pBt; |
| | @@ -89142,11 +89248,11 @@ |
| 89142 | 89248 | ** opening it. If a transient table is required, just use the |
| 89143 | 89249 | ** automatically created table with root-page 1 (an BLOB_INTKEY table). |
| 89144 | 89250 | */ |
| 89145 | 89251 | if( (pCx->pKeyInfo = pKeyInfo = pOp->p4.pKeyInfo)!=0 ){ |
| 89146 | 89252 | assert( pOp->p4type==P4_KEYINFO ); |
| 89147 | | - rc = sqlite3BtreeCreateTable(pCx->pBtx, (int*)&pCx->pgnoRoot, |
| 89253 | + rc = sqlite3BtreeCreateTable(pCx->pBtx, &pCx->pgnoRoot, |
| 89148 | 89254 | BTREE_BLOBKEY | pOp->p5); |
| 89149 | 89255 | if( rc==SQLITE_OK ){ |
| 89150 | 89256 | assert( pCx->pgnoRoot==SCHEMA_ROOT+1 ); |
| 89151 | 89257 | assert( pKeyInfo->db==db ); |
| 89152 | 89258 | assert( pKeyInfo->enc==ENC(db) ); |
| | @@ -90406,14 +90512,10 @@ |
| 90406 | 90512 | ** generator) then the fix would be to insert a call to |
| 90407 | 90513 | ** sqlite3VdbeCursorMoveto(). |
| 90408 | 90514 | */ |
| 90409 | 90515 | assert( pC->deferredMoveto==0 ); |
| 90410 | 90516 | 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 | 90517 | |
| 90416 | 90518 | n = sqlite3BtreePayloadSize(pCrsr); |
| 90417 | 90519 | if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 90418 | 90520 | goto too_big; |
| 90419 | 90521 | } |
| | @@ -91179,11 +91281,11 @@ |
| 91179 | 91281 | sqlite3VdbeIncrWriteCounter(p, 0); |
| 91180 | 91282 | nChange = 0; |
| 91181 | 91283 | assert( p->readOnly==0 ); |
| 91182 | 91284 | assert( DbMaskTest(p->btreeMask, pOp->p2) ); |
| 91183 | 91285 | 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) |
| 91185 | 91287 | ); |
| 91186 | 91288 | if( pOp->p3 ){ |
| 91187 | 91289 | p->nChange += nChange; |
| 91188 | 91290 | if( pOp->p3>0 ){ |
| 91189 | 91291 | assert( memIsValid(&aMem[pOp->p3]) ); |
| | @@ -91228,11 +91330,11 @@ |
| 91228 | 91330 | ** P1>1. The P3 argument must be 1 (BTREE_INTKEY) for a rowid table |
| 91229 | 91331 | ** it must be 2 (BTREE_BLOBKEY) for an index or WITHOUT ROWID table. |
| 91230 | 91332 | ** The root page number of the new b-tree is stored in register P2. |
| 91231 | 91333 | */ |
| 91232 | 91334 | case OP_CreateBtree: { /* out2 */ |
| 91233 | | - int pgno; |
| 91335 | + Pgno pgno; |
| 91234 | 91336 | Db *pDb; |
| 91235 | 91337 | |
| 91236 | 91338 | sqlite3VdbeIncrWriteCounter(p, 0); |
| 91237 | 91339 | pOut = out2Prerelease(p, pOp); |
| 91238 | 91340 | pgno = 0; |
| | @@ -91303,10 +91405,11 @@ |
| 91303 | 91405 | zSchema = DFLT_SCHEMA_TABLE; |
| 91304 | 91406 | initData.db = db; |
| 91305 | 91407 | initData.iDb = iDb; |
| 91306 | 91408 | initData.pzErrMsg = &p->zErrMsg; |
| 91307 | 91409 | initData.mInitFlags = 0; |
| 91410 | + initData.mxPage = sqlite3BtreeLastPage(db->aDb[iDb].pBt); |
| 91308 | 91411 | zSql = sqlite3MPrintf(db, |
| 91309 | 91412 | "SELECT*FROM\"%w\".%s WHERE %s ORDER BY rowid", |
| 91310 | 91413 | db->aDb[iDb].zDbSName, zSchema, pOp->p4.z); |
| 91311 | 91414 | if( zSql==0 ){ |
| 91312 | 91415 | rc = SQLITE_NOMEM_BKPT; |
| | @@ -91416,11 +91519,11 @@ |
| 91416 | 91519 | ** |
| 91417 | 91520 | ** This opcode is used to implement the integrity_check pragma. |
| 91418 | 91521 | */ |
| 91419 | 91522 | case OP_IntegrityCk: { |
| 91420 | 91523 | 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 */ |
| 91422 | 91525 | int nErr; /* Number of errors reported */ |
| 91423 | 91526 | char *z; /* Text of the error report */ |
| 91424 | 91527 | Mem *pnErr; /* Register keeping track of errors remaining */ |
| 91425 | 91528 | |
| 91426 | 91529 | assert( p->bIsReader ); |
| | @@ -96701,11 +96804,11 @@ |
| 96701 | 96804 | }else{ |
| 96702 | 96805 | if( i<=2 && pCur->zType==0 ){ |
| 96703 | 96806 | Schema *pSchema; |
| 96704 | 96807 | HashElem *k; |
| 96705 | 96808 | int iDb = pOp->p3; |
| 96706 | | - int iRoot = pOp->p2; |
| 96809 | + Pgno iRoot = (Pgno)pOp->p2; |
| 96707 | 96810 | sqlite3 *db = pVTab->db; |
| 96708 | 96811 | pSchema = db->aDb[iDb].pSchema; |
| 96709 | 96812 | pCur->zSchema = db->aDb[iDb].zDbSName; |
| 96710 | 96813 | for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){ |
| 96711 | 96814 | Table *pTab = (Table*)sqliteHashData(k); |
| | @@ -97288,11 +97391,11 @@ |
| 97288 | 97391 | }else{ |
| 97289 | 97392 | p->nChunkSize = 8 + MEMJOURNAL_DFLT_FILECHUNKSIZE - sizeof(FileChunk); |
| 97290 | 97393 | assert( MEMJOURNAL_DFLT_FILECHUNKSIZE==fileChunkSize(p->nChunkSize) ); |
| 97291 | 97394 | } |
| 97292 | 97395 | |
| 97293 | | - p->pMethod = (const sqlite3_io_methods*)&MemJournalMethods; |
| 97396 | + pJfd->pMethods = (const sqlite3_io_methods*)&MemJournalMethods; |
| 97294 | 97397 | p->nSpill = nSpill; |
| 97295 | 97398 | p->flags = flags; |
| 97296 | 97399 | p->zJournal = zName; |
| 97297 | 97400 | p->pVfs = pVfs; |
| 97298 | 97401 | return SQLITE_OK; |
| | @@ -97314,11 +97417,11 @@ |
| 97314 | 97417 | ** file has not yet been created, create it now. |
| 97315 | 97418 | */ |
| 97316 | 97419 | SQLITE_PRIVATE int sqlite3JournalCreate(sqlite3_file *pJfd){ |
| 97317 | 97420 | int rc = SQLITE_OK; |
| 97318 | 97421 | MemJournal *p = (MemJournal*)pJfd; |
| 97319 | | - if( p->pMethod==&MemJournalMethods && ( |
| 97422 | + if( pJfd->pMethods==&MemJournalMethods && ( |
| 97320 | 97423 | #ifdef SQLITE_ENABLE_ATOMIC_WRITE |
| 97321 | 97424 | p->nSpill>0 |
| 97322 | 97425 | #else |
| 97323 | 97426 | /* While this appears to not be possible without ATOMIC_WRITE, the |
| 97324 | 97427 | ** paths are complex, so it seems prudent to leave the test in as |
| | @@ -107581,11 +107684,11 @@ |
| 107581 | 107684 | }; |
| 107582 | 107685 | int i; |
| 107583 | 107686 | sqlite3 *db = pParse->db; |
| 107584 | 107687 | Db *pDb; |
| 107585 | 107688 | Vdbe *v = sqlite3GetVdbe(pParse); |
| 107586 | | - int aRoot[ArraySize(aTable)]; |
| 107689 | + u32 aRoot[ArraySize(aTable)]; |
| 107587 | 107690 | u8 aCreateTbl[ArraySize(aTable)]; |
| 107588 | 107691 | #ifdef SQLITE_ENABLE_STAT4 |
| 107589 | 107692 | const int nToOpen = OptimizationEnabled(db,SQLITE_Stat4) ? 2 : 1; |
| 107590 | 107693 | #else |
| 107591 | 107694 | const int nToOpen = 1; |
| | @@ -107610,11 +107713,11 @@ |
| 107610 | 107713 | ** of the new table in register pParse->regRoot. This is important |
| 107611 | 107714 | ** because the OpenWrite opcode below will be needing it. */ |
| 107612 | 107715 | sqlite3NestedParse(pParse, |
| 107613 | 107716 | "CREATE TABLE %Q.%s(%s)", pDb->zDbSName, zTab, aTable[i].zCols |
| 107614 | 107717 | ); |
| 107615 | | - aRoot[i] = pParse->regRoot; |
| 107718 | + aRoot[i] = (u32)pParse->regRoot; |
| 107616 | 107719 | aCreateTbl[i] = OPFLAG_P2ISREG; |
| 107617 | 107720 | } |
| 107618 | 107721 | }else{ |
| 107619 | 107722 | /* The table already exists. If zWhere is not NULL, delete all entries |
| 107620 | 107723 | ** associated with the table zWhere. If zWhere is NULL, delete the |
| | @@ -107630,19 +107733,19 @@ |
| 107630 | 107733 | }else if( db->xPreUpdateCallback ){ |
| 107631 | 107734 | sqlite3NestedParse(pParse, "DELETE FROM %Q.%s", pDb->zDbSName, zTab); |
| 107632 | 107735 | #endif |
| 107633 | 107736 | }else{ |
| 107634 | 107737 | /* 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); |
| 107636 | 107739 | } |
| 107637 | 107740 | } |
| 107638 | 107741 | } |
| 107639 | 107742 | |
| 107640 | 107743 | /* Open the sqlite_stat[134] tables for writing. */ |
| 107641 | 107744 | for(i=0; i<nToOpen; i++){ |
| 107642 | 107745 | 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); |
| 107644 | 107747 | sqlite3VdbeChangeP5(v, aCreateTbl[i]); |
| 107645 | 107748 | VdbeComment((v, aTable[i].zName)); |
| 107646 | 107749 | } |
| 107647 | 107750 | } |
| 107648 | 107751 | |
| | @@ -110271,11 +110374,11 @@ |
| 110271 | 110374 | ** The TableLock structure is only used by the sqlite3TableLock() and |
| 110272 | 110375 | ** codeTableLocks() functions. |
| 110273 | 110376 | */ |
| 110274 | 110377 | struct TableLock { |
| 110275 | 110378 | 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 */ |
| 110277 | 110380 | u8 isWriteLock; /* True for write lock. False for a read lock */ |
| 110278 | 110381 | const char *zLockName; /* Name of the table */ |
| 110279 | 110382 | }; |
| 110280 | 110383 | |
| 110281 | 110384 | /* |
| | @@ -110289,11 +110392,11 @@ |
| 110289 | 110392 | ** codeTableLocks() which occurs during sqlite3FinishCoding(). |
| 110290 | 110393 | */ |
| 110291 | 110394 | SQLITE_PRIVATE void sqlite3TableLock( |
| 110292 | 110395 | Parse *pParse, /* Parsing context */ |
| 110293 | 110396 | 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 */ |
| 110295 | 110398 | u8 isWriteLock, /* True for a write lock */ |
| 110296 | 110399 | const char *zName /* Name of the table to be locked */ |
| 110297 | 110400 | ){ |
| 110298 | 110401 | Parse *pToplevel = sqlite3ParseToplevel(pParse); |
| 110299 | 110402 | int i; |
| | @@ -111128,23 +111231,24 @@ |
| 111128 | 111231 | const char *zName, /* Name of the object to check */ |
| 111129 | 111232 | const char *zType, /* Type of this object */ |
| 111130 | 111233 | const char *zTblName /* Parent table name for triggers and indexes */ |
| 111131 | 111234 | ){ |
| 111132 | 111235 | sqlite3 *db = pParse->db; |
| 111133 | | - if( sqlite3WritableSchema(db) || db->init.imposterTable ){ |
| 111236 | + if( sqlite3WritableSchema(db) |
| 111237 | + || db->init.imposterTable |
| 111238 | + || !sqlite3Config.bExtraSchemaChecks |
| 111239 | + ){ |
| 111134 | 111240 | /* Skip these error checks for writable_schema=ON */ |
| 111135 | 111241 | return SQLITE_OK; |
| 111136 | 111242 | } |
| 111137 | 111243 | if( db->init.busy ){ |
| 111138 | 111244 | if( sqlite3_stricmp(zType, db->init.azInit[0]) |
| 111139 | 111245 | || sqlite3_stricmp(zName, db->init.azInit[1]) |
| 111140 | 111246 | || sqlite3_stricmp(zTblName, db->init.azInit[2]) |
| 111141 | 111247 | ){ |
| 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; |
| 111146 | 111250 | } |
| 111147 | 111251 | }else{ |
| 111148 | 111252 | if( (pParse->nested==0 && 0==sqlite3StrNICmp(zName, "sqlite_", 7)) |
| 111149 | 111253 | || (sqlite3ReadOnlyShadowTables(db) && sqlite3ShadowTableName(db, zName)) |
| 111150 | 111254 | ){ |
| | @@ -112354,11 +112458,11 @@ |
| 112354 | 112458 | ** table entry. This is only required if currently generating VDBE |
| 112355 | 112459 | ** code for a CREATE TABLE (not when parsing one as part of reading |
| 112356 | 112460 | ** a database schema). */ |
| 112357 | 112461 | if( v && pPk->tnum>0 ){ |
| 112358 | 112462 | assert( db->init.busy==0 ); |
| 112359 | | - sqlite3VdbeChangeOpcode(v, pPk->tnum, OP_Goto); |
| 112463 | + sqlite3VdbeChangeOpcode(v, (int)pPk->tnum, OP_Goto); |
| 112360 | 112464 | } |
| 112361 | 112465 | |
| 112362 | 112466 | /* The root page of the PRIMARY KEY is the table root page */ |
| 112363 | 112467 | pPk->tnum = pTab->tnum; |
| 112364 | 112468 | |
| | @@ -113050,11 +113154,11 @@ |
| 113050 | 113154 | ** We must continue looping until all tables and indices with |
| 113051 | 113155 | ** rootpage==iFrom have been converted to have a rootpage of iTo |
| 113052 | 113156 | ** in order to be certain that we got the right one. |
| 113053 | 113157 | */ |
| 113054 | 113158 | #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){ |
| 113056 | 113160 | HashElem *pElem; |
| 113057 | 113161 | Hash *pHash; |
| 113058 | 113162 | Db *pDb; |
| 113059 | 113163 | |
| 113060 | 113164 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| | @@ -113083,11 +113187,11 @@ |
| 113083 | 113187 | ** erasing iTable (this can happen with an auto-vacuum database). |
| 113084 | 113188 | */ |
| 113085 | 113189 | static void destroyRootPage(Parse *pParse, int iTable, int iDb){ |
| 113086 | 113190 | Vdbe *v = sqlite3GetVdbe(pParse); |
| 113087 | 113191 | int r1 = sqlite3GetTempReg(pParse); |
| 113088 | | - if( iTable<2 ) sqlite3ErrorMsg(pParse, "corrupt schema"); |
| 113192 | + if( NEVER(iTable<2) ) return; |
| 113089 | 113193 | sqlite3VdbeAddOp3(v, OP_Destroy, iTable, r1, iDb); |
| 113090 | 113194 | sqlite3MayAbort(pParse); |
| 113091 | 113195 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 113092 | 113196 | /* OP_Destroy stores an in integer r1. If this integer |
| 113093 | 113197 | ** is non-zero, then it is the root page number of a table moved to |
| | @@ -113127,22 +113231,22 @@ |
| 113127 | 113231 | ** and root page 5 happened to be the largest root-page number in the |
| 113128 | 113232 | ** database, then root page 5 would be moved to page 4 by the |
| 113129 | 113233 | ** "OP_Destroy 4 0" opcode. The subsequent "OP_Destroy 5 0" would hit |
| 113130 | 113234 | ** a free-list page. |
| 113131 | 113235 | */ |
| 113132 | | - int iTab = pTab->tnum; |
| 113133 | | - int iDestroyed = 0; |
| 113236 | + Pgno iTab = pTab->tnum; |
| 113237 | + Pgno iDestroyed = 0; |
| 113134 | 113238 | |
| 113135 | 113239 | while( 1 ){ |
| 113136 | 113240 | Index *pIdx; |
| 113137 | | - int iLargest = 0; |
| 113241 | + Pgno iLargest = 0; |
| 113138 | 113242 | |
| 113139 | 113243 | if( iDestroyed==0 || iTab<iDestroyed ){ |
| 113140 | 113244 | iLargest = iTab; |
| 113141 | 113245 | } |
| 113142 | 113246 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 113143 | | - int iIdx = pIdx->tnum; |
| 113247 | + Pgno iIdx = pIdx->tnum; |
| 113144 | 113248 | assert( pIdx->pSchema==pTab->pSchema ); |
| 113145 | 113249 | if( (iDestroyed==0 || (iIdx<iDestroyed)) && iIdx>iLargest ){ |
| 113146 | 113250 | iLargest = iIdx; |
| 113147 | 113251 | } |
| 113148 | 113252 | } |
| | @@ -113561,11 +113665,11 @@ |
| 113561 | 113665 | int iTab = pParse->nTab++; /* Btree cursor used for pTab */ |
| 113562 | 113666 | int iIdx = pParse->nTab++; /* Btree cursor used for pIndex */ |
| 113563 | 113667 | int iSorter; /* Cursor opened by OpenSorter (if in use) */ |
| 113564 | 113668 | int addr1; /* Address of top of loop */ |
| 113565 | 113669 | int addr2; /* Address to jump to for next iteration */ |
| 113566 | | - int tnum; /* Root page of index */ |
| 113670 | + Pgno tnum; /* Root page of index */ |
| 113567 | 113671 | int iPartIdxLabel; /* Jump to this label to skip a row */ |
| 113568 | 113672 | Vdbe *v; /* Generate code into this virtual machine */ |
| 113569 | 113673 | KeyInfo *pKey; /* KeyInfo for index */ |
| 113570 | 113674 | int regRecord; /* Register holding assembled index record */ |
| 113571 | 113675 | sqlite3 *db = pParse->db; /* The database connection */ |
| | @@ -113582,11 +113686,11 @@ |
| 113582 | 113686 | sqlite3TableLock(pParse, iDb, pTab->tnum, 1, pTab->zName); |
| 113583 | 113687 | |
| 113584 | 113688 | v = sqlite3GetVdbe(pParse); |
| 113585 | 113689 | if( v==0 ) return; |
| 113586 | 113690 | if( memRootPage>=0 ){ |
| 113587 | | - tnum = memRootPage; |
| 113691 | + tnum = (Pgno)memRootPage; |
| 113588 | 113692 | }else{ |
| 113589 | 113693 | tnum = pIndex->tnum; |
| 113590 | 113694 | } |
| 113591 | 113695 | pKey = sqlite3KeyInfoOfIndex(pParse, pIndex); |
| 113592 | 113696 | assert( pKey!=0 || db->mallocFailed || pParse->nErr ); |
| | @@ -113607,11 +113711,11 @@ |
| 113607 | 113711 | sqlite3VdbeAddOp2(v, OP_SorterInsert, iSorter, regRecord); |
| 113608 | 113712 | sqlite3ResolvePartIdxLabel(pParse, iPartIdxLabel); |
| 113609 | 113713 | sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1); VdbeCoverage(v); |
| 113610 | 113714 | sqlite3VdbeJumpHere(v, addr1); |
| 113611 | 113715 | 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, |
| 113613 | 113717 | (char *)pKey, P4_KEYINFO); |
| 113614 | 113718 | sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR|((memRootPage>=0)?OPFLAG_P2ISREG:0)); |
| 113615 | 113719 | |
| 113616 | 113720 | addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0); VdbeCoverage(v); |
| 113617 | 113721 | if( IsUniqueIndex(pIndex) ){ |
| | @@ -114216,11 +114320,11 @@ |
| 114216 | 114320 | ** doing so, code a Noop instruction and store its address in |
| 114217 | 114321 | ** Index.tnum. This is required in case this index is actually a |
| 114218 | 114322 | ** PRIMARY KEY and the table is actually a WITHOUT ROWID table. In |
| 114219 | 114323 | ** that case the convertToWithoutRowidTable() routine will replace |
| 114220 | 114324 | ** 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); |
| 114222 | 114326 | sqlite3VdbeAddOp3(v, OP_CreateBtree, iDb, iMem, BTREE_BLOBKEY); |
| 114223 | 114327 | |
| 114224 | 114328 | /* Gather the complete text of the CREATE INDEX statement into |
| 114225 | 114329 | ** the zStmt variable |
| 114226 | 114330 | */ |
| | @@ -114258,11 +114362,11 @@ |
| 114258 | 114362 | sqlite3VdbeAddParseSchemaOp(v, iDb, |
| 114259 | 114363 | sqlite3MPrintf(db, "name='%q' AND type='index'", pIndex->zName)); |
| 114260 | 114364 | sqlite3VdbeAddOp2(v, OP_Expire, 0, 1); |
| 114261 | 114365 | } |
| 114262 | 114366 | |
| 114263 | | - sqlite3VdbeJumpHere(v, pIndex->tnum); |
| 114367 | + sqlite3VdbeJumpHere(v, (int)pIndex->tnum); |
| 114264 | 114368 | } |
| 114265 | 114369 | } |
| 114266 | 114370 | if( db->init.busy || pTblName==0 ){ |
| 114267 | 114371 | pIndex->pNext = pTab->pIndex; |
| 114268 | 114372 | pTab->pIndex = pIndex; |
| | @@ -120581,11 +120685,11 @@ |
| 120581 | 120685 | for(i=1; i<iEnd; i++){ |
| 120582 | 120686 | VdbeOp *pOp = sqlite3VdbeGetOp(v, i); |
| 120583 | 120687 | assert( pOp!=0 ); |
| 120584 | 120688 | if( pOp->opcode==OP_OpenRead && pOp->p3==iDb ){ |
| 120585 | 120689 | Index *pIndex; |
| 120586 | | - int tnum = pOp->p2; |
| 120690 | + Pgno tnum = pOp->p2; |
| 120587 | 120691 | if( tnum==pTab->tnum ){ |
| 120588 | 120692 | return 1; |
| 120589 | 120693 | } |
| 120590 | 120694 | for(pIndex=pTab->pIndex; pIndex; pIndex=pIndex->pNext){ |
| 120591 | 120695 | if( tnum==pIndex->tnum ){ |
| | @@ -126204,17 +126308,23 @@ |
| 126204 | 126308 | ** |
| 126205 | 126309 | ** Return the number of pages in the specified database. |
| 126206 | 126310 | */ |
| 126207 | 126311 | case PragTyp_PAGE_COUNT: { |
| 126208 | 126312 | int iReg; |
| 126313 | + i64 x = 0; |
| 126209 | 126314 | sqlite3CodeVerifySchema(pParse, iDb); |
| 126210 | 126315 | iReg = ++pParse->nMem; |
| 126211 | 126316 | if( sqlite3Tolower(zLeft[0])=='p' ){ |
| 126212 | 126317 | sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg); |
| 126213 | 126318 | }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); |
| 126216 | 126326 | } |
| 126217 | 126327 | sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1); |
| 126218 | 126328 | break; |
| 126219 | 126329 | } |
| 126220 | 126330 | |
| | @@ -127113,13 +127223,26 @@ |
| 127113 | 127223 | ** |
| 127114 | 127224 | ** The "quick_check" is reduced version of |
| 127115 | 127225 | ** integrity_check designed to detect most database corruption |
| 127116 | 127226 | ** without the overhead of cross-checking indexes. Quick_check |
| 127117 | 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; |
| 127118 | 127240 | */ |
| 127119 | 127241 | case PragTyp_INTEGRITY_CHECK: { |
| 127120 | 127242 | int i, j, addr, mxErr; |
| 127243 | + Table *pObjTab = 0; /* Check only this one table, if not NULL */ |
| 127121 | 127244 | |
| 127122 | 127245 | int isQuick = (sqlite3Tolower(zLeft[0])=='q'); |
| 127123 | 127246 | |
| 127124 | 127247 | /* If the PRAGMA command was of the form "PRAGMA <db>.integrity_check", |
| 127125 | 127248 | ** then iDb is set to the index of the database identified by <db>. |
| | @@ -127138,13 +127261,17 @@ |
| 127138 | 127261 | pParse->nMem = 6; |
| 127139 | 127262 | |
| 127140 | 127263 | /* Set the maximum error count */ |
| 127141 | 127264 | mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX; |
| 127142 | 127265 | 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); |
| 127146 | 127273 | } |
| 127147 | 127274 | } |
| 127148 | 127275 | sqlite3VdbeAddOp2(v, OP_Integer, mxErr-1, 1); /* reg[1] holds errors left */ |
| 127149 | 127276 | |
| 127150 | 127277 | /* Do an integrity check on each database file */ |
| | @@ -127169,19 +127296,25 @@ |
| 127169 | 127296 | pTbls = &db->aDb[i].pSchema->tblHash; |
| 127170 | 127297 | for(cnt=0, x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){ |
| 127171 | 127298 | Table *pTab = sqliteHashData(x); /* Current table */ |
| 127172 | 127299 | Index *pIdx; /* An index on pTab */ |
| 127173 | 127300 | int nIdx; /* Number of indexes on pTab */ |
| 127301 | + if( pObjTab && pObjTab!=pTab ) continue; |
| 127174 | 127302 | if( HasRowid(pTab) ) cnt++; |
| 127175 | 127303 | for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){ cnt++; } |
| 127176 | 127304 | if( nIdx>mxIdx ) mxIdx = nIdx; |
| 127177 | 127305 | } |
| 127306 | + if( cnt==0 ) continue; |
| 127307 | + if( pObjTab ) cnt++; |
| 127178 | 127308 | aRoot = sqlite3DbMallocRawNN(db, sizeof(int)*(cnt+1)); |
| 127179 | 127309 | 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)){ |
| 127181 | 127313 | Table *pTab = sqliteHashData(x); |
| 127182 | 127314 | Index *pIdx; |
| 127315 | + if( pObjTab && pObjTab!=pTab ) continue; |
| 127183 | 127316 | if( HasRowid(pTab) ) aRoot[++cnt] = pTab->tnum; |
| 127184 | 127317 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 127185 | 127318 | aRoot[++cnt] = pIdx->tnum; |
| 127186 | 127319 | } |
| 127187 | 127320 | } |
| | @@ -127211,10 +127344,11 @@ |
| 127211 | 127344 | int loopTop; |
| 127212 | 127345 | int iDataCur, iIdxCur; |
| 127213 | 127346 | int r1 = -1; |
| 127214 | 127347 | |
| 127215 | 127348 | if( pTab->tnum<1 ) continue; /* Skip VIEWs or VIRTUAL TABLEs */ |
| 127349 | + if( pObjTab && pObjTab!=pTab ) continue; |
| 127216 | 127350 | pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab); |
| 127217 | 127351 | sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0, |
| 127218 | 127352 | 1, 0, &iDataCur, &iIdxCur); |
| 127219 | 127353 | /* reg[7] counts the number of entries in the table. |
| 127220 | 127354 | ** reg[8+i] counts the number of entries in the i-th index |
| | @@ -128272,11 +128406,17 @@ |
| 128272 | 128406 | sqlite3_stmt *pStmt; |
| 128273 | 128407 | TESTONLY(int rcp); /* Return code from sqlite3_prepare() */ |
| 128274 | 128408 | |
| 128275 | 128409 | assert( db->init.busy ); |
| 128276 | 128410 | 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 | + } |
| 128278 | 128418 | db->init.orphanTrigger = 0; |
| 128279 | 128419 | db->init.azInit = argv; |
| 128280 | 128420 | pStmt = 0; |
| 128281 | 128421 | TESTONLY(rcp = ) sqlite3Prepare(db, argv[4], -1, 0, 0, &pStmt, 0); |
| 128282 | 128422 | rc = db->errCode; |
| | @@ -128305,16 +128445,21 @@ |
| 128305 | 128445 | ** been created when we processed the CREATE TABLE. All we have |
| 128306 | 128446 | ** to do here is record the root page number for that index. |
| 128307 | 128447 | */ |
| 128308 | 128448 | Index *pIndex; |
| 128309 | 128449 | 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 |
| 128312 | 128454 | || pIndex->tnum<2 |
| 128455 | + || pIndex->tnum>pData->mxPage |
| 128313 | 128456 | || sqlite3IndexHasDuplicateRootPage(pIndex) |
| 128314 | 128457 | ){ |
| 128315 | | - corruptSchema(pData, argv[1], pIndex?"invalid rootpage":"orphan index"); |
| 128458 | + if( sqlite3Config.bExtraSchemaChecks ){ |
| 128459 | + corruptSchema(pData, argv[1], "invalid rootpage"); |
| 128460 | + } |
| 128316 | 128461 | } |
| 128317 | 128462 | } |
| 128318 | 128463 | return 0; |
| 128319 | 128464 | } |
| 128320 | 128465 | |
| | @@ -128364,10 +128509,11 @@ |
| 128364 | 128509 | initData.iDb = iDb; |
| 128365 | 128510 | initData.rc = SQLITE_OK; |
| 128366 | 128511 | initData.pzErrMsg = pzErrMsg; |
| 128367 | 128512 | initData.mInitFlags = mFlags; |
| 128368 | 128513 | initData.nInitRow = 0; |
| 128514 | + initData.mxPage = 0; |
| 128369 | 128515 | sqlite3InitCallback(&initData, 5, (char **)azArg, 0); |
| 128370 | 128516 | db->mDbFlags &= mask; |
| 128371 | 128517 | if( initData.rc ){ |
| 128372 | 128518 | rc = initData.rc; |
| 128373 | 128519 | goto error_out; |
| | @@ -128486,10 +128632,11 @@ |
| 128486 | 128632 | } |
| 128487 | 128633 | |
| 128488 | 128634 | /* Read the schema information out of the schema tables |
| 128489 | 128635 | */ |
| 128490 | 128636 | assert( db->init.busy ); |
| 128637 | + initData.mxPage = sqlite3BtreeLastPage(pDb->pBt); |
| 128491 | 128638 | { |
| 128492 | 128639 | char *zSql; |
| 128493 | 128640 | zSql = sqlite3MPrintf(db, |
| 128494 | 128641 | "SELECT*FROM\"%w\".%s ORDER BY rowid", |
| 128495 | 128642 | db->aDb[iDb].zDbSName, zSchemaTabName); |
| | @@ -129368,12 +129515,14 @@ |
| 129368 | 129515 | ** Return the index of a column in a table. Return -1 if the column |
| 129369 | 129516 | ** is not contained in the table. |
| 129370 | 129517 | */ |
| 129371 | 129518 | static int columnIndex(Table *pTab, const char *zCol){ |
| 129372 | 129519 | 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; |
| 129375 | 129524 | } |
| 129376 | 129525 | return -1; |
| 129377 | 129526 | } |
| 129378 | 129527 | |
| 129379 | 129528 | /* |
| | @@ -130231,20 +130380,24 @@ |
| 130231 | 130380 | sqlite3ReleaseTempRange(pParse, r1, nPrefixReg+1); |
| 130232 | 130381 | break; |
| 130233 | 130382 | } |
| 130234 | 130383 | |
| 130235 | 130384 | case SRT_Upfrom: { |
| 130236 | | -#ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT |
| 130237 | 130385 | if( pSort ){ |
| 130238 | 130386 | pushOntoSorter( |
| 130239 | 130387 | pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg); |
| 130240 | | - }else |
| 130241 | | -#endif |
| 130242 | | - { |
| 130388 | + }else{ |
| 130243 | 130389 | int i2 = pDest->iSDParm2; |
| 130244 | 130390 | 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); |
| 130246 | 130399 | if( i2<0 ){ |
| 130247 | 130400 | sqlite3VdbeAddOp3(v, OP_Insert, iParm, r1, regResult); |
| 130248 | 130401 | }else{ |
| 130249 | 130402 | sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, r1, regResult, i2); |
| 130250 | 130403 | } |
| | @@ -130682,11 +130835,10 @@ |
| 130682 | 130835 | case SRT_Mem: { |
| 130683 | 130836 | /* The LIMIT clause will terminate the loop for us */ |
| 130684 | 130837 | break; |
| 130685 | 130838 | } |
| 130686 | 130839 | #endif |
| 130687 | | -#ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT |
| 130688 | 130840 | case SRT_Upfrom: { |
| 130689 | 130841 | int i2 = pDest->iSDParm2; |
| 130690 | 130842 | int r1 = sqlite3GetTempReg(pParse); |
| 130691 | 130843 | sqlite3VdbeAddOp3(v, OP_MakeRecord,regRow+(i2<0),nColumn-(i2<0),r1); |
| 130692 | 130844 | if( i2<0 ){ |
| | @@ -130694,11 +130846,10 @@ |
| 130694 | 130846 | }else{ |
| 130695 | 130847 | sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, r1, regRow, i2); |
| 130696 | 130848 | } |
| 130697 | 130849 | break; |
| 130698 | 130850 | } |
| 130699 | | -#endif |
| 130700 | 130851 | default: { |
| 130701 | 130852 | assert( eDest==SRT_Output || eDest==SRT_Coroutine ); |
| 130702 | 130853 | testcase( eDest==SRT_Output ); |
| 130703 | 130854 | testcase( eDest==SRT_Coroutine ); |
| 130704 | 130855 | if( eDest==SRT_Output ){ |
| | @@ -132281,11 +132432,11 @@ |
| 132281 | 132432 | KeyInfo *pKeyDup = 0; /* Comparison information for duplicate removal */ |
| 132282 | 132433 | KeyInfo *pKeyMerge; /* Comparison information for merging rows */ |
| 132283 | 132434 | sqlite3 *db; /* Database connection */ |
| 132284 | 132435 | ExprList *pOrderBy; /* The ORDER BY clause */ |
| 132285 | 132436 | 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 */ |
| 132287 | 132438 | |
| 132288 | 132439 | assert( p->pOrderBy!=0 ); |
| 132289 | 132440 | assert( pKeyDup==0 ); /* "Managed" code needs this. Ticket #3382. */ |
| 132290 | 132441 | db = pParse->db; |
| 132291 | 132442 | v = pParse->pVdbe; |
| | @@ -132330,11 +132481,11 @@ |
| 132330 | 132481 | ** row of results comes from selectA or selectB. Also add explicit |
| 132331 | 132482 | ** collations to the ORDER BY clause terms so that when the subqueries |
| 132332 | 132483 | ** to the right and the left are evaluated, they use the correct |
| 132333 | 132484 | ** collation. |
| 132334 | 132485 | */ |
| 132335 | | - aPermute = sqlite3DbMallocRawNN(db, sizeof(int)*(nOrderBy + 1)); |
| 132486 | + aPermute = sqlite3DbMallocRawNN(db, sizeof(u32)*(nOrderBy + 1)); |
| 132336 | 132487 | if( aPermute ){ |
| 132337 | 132488 | struct ExprList_item *pItem; |
| 132338 | 132489 | aPermute[0] = nOrderBy; |
| 132339 | 132490 | for(i=1, pItem=pOrderBy->a; i<=nOrderBy; i++, pItem++){ |
| 132340 | 132491 | assert( pItem->u.x.iOrderByCol>0 ); |
| | @@ -135823,11 +135974,11 @@ |
| 135823 | 135974 | const int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema); |
| 135824 | 135975 | const int iCsr = pParse->nTab++; /* Cursor to scan b-tree */ |
| 135825 | 135976 | Index *pIdx; /* Iterator variable */ |
| 135826 | 135977 | KeyInfo *pKeyInfo = 0; /* Keyinfo for scanned index */ |
| 135827 | 135978 | 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 */ |
| 135829 | 135980 | |
| 135830 | 135981 | sqlite3CodeVerifySchema(pParse, iDb); |
| 135831 | 135982 | sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName); |
| 135832 | 135983 | |
| 135833 | 135984 | /* Search for the index that has the lowest scan cost. |
| | @@ -135855,11 +136006,11 @@ |
| 135855 | 136006 | iRoot = pBest->tnum; |
| 135856 | 136007 | pKeyInfo = sqlite3KeyInfoOfIndex(pParse, pBest); |
| 135857 | 136008 | } |
| 135858 | 136009 | |
| 135859 | 136010 | /* 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); |
| 135861 | 136012 | if( pKeyInfo ){ |
| 135862 | 136013 | sqlite3VdbeChangeP4(v, -1, (char *)pKeyInfo, P4_KEYINFO); |
| 135863 | 136014 | } |
| 135864 | 136015 | sqlite3VdbeAddOp2(v, OP_Count, iCsr, pAggInfo->aFunc[0].iMem); |
| 135865 | 136016 | sqlite3VdbeAddOp1(v, OP_Close, iCsr); |
| | @@ -142375,11 +142526,11 @@ |
| 142375 | 142526 | if( (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE) |
| 142376 | 142527 | && DbMaskAllZero(sqlite3ParseToplevel(pParse)->writeMask) |
| 142377 | 142528 | ){ |
| 142378 | 142529 | int i; |
| 142379 | 142530 | 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)); |
| 142381 | 142532 | if( ai ){ |
| 142382 | 142533 | ai[0] = pTab->nCol; |
| 142383 | 142534 | for(i=0; i<pIdx->nColumn-1; i++){ |
| 142384 | 142535 | int x1, x2; |
| 142385 | 142536 | assert( pIdx->aiColumn[i]<pTab->nCol ); |
| | @@ -164889,10 +165040,16 @@ |
| 164889 | 165040 | /* sqlite3_test_control(SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS, int); |
| 164890 | 165041 | ** |
| 164891 | 165042 | ** Set or clear a flag that causes SQLite to verify that type, name, |
| 164892 | 165043 | ** and tbl_name fields of the sqlite_schema table. This is normally |
| 164893 | 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. |
| 164894 | 165051 | */ |
| 164895 | 165052 | case SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS: { |
| 164896 | 165053 | sqlite3GlobalConfig.bExtraSchemaChecks = va_arg(ap, int); |
| 164897 | 165054 | break; |
| 164898 | 165055 | } |
| | @@ -172498,11 +172655,12 @@ |
| 172498 | 172655 | ** do {...} while( pRoot->iDocid<iDocid && rc==SQLITE_OK ); |
| 172499 | 172656 | */ |
| 172500 | 172657 | fts3EvalRestart(pCsr, pRoot, &rc); |
| 172501 | 172658 | do { |
| 172502 | 172659 | fts3EvalNextRow(pCsr, pRoot, &rc); |
| 172503 | | - assert( pRoot->bEof==0 ); |
| 172660 | + assert_fts3_nc( pRoot->bEof==0 ); |
| 172661 | + if( pRoot->bEof ) rc = FTS_CORRUPT_VTAB; |
| 172504 | 172662 | }while( pRoot->iDocid!=iDocid && rc==SQLITE_OK ); |
| 172505 | 172663 | } |
| 172506 | 172664 | } |
| 172507 | 172665 | return rc; |
| 172508 | 172666 | } |
| | @@ -225482,11 +225640,11 @@ |
| 225482 | 225640 | int nArg, /* Number of args */ |
| 225483 | 225641 | sqlite3_value **apUnused /* Function arguments */ |
| 225484 | 225642 | ){ |
| 225485 | 225643 | assert( nArg==0 ); |
| 225486 | 225644 | 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); |
| 225488 | 225646 | } |
| 225489 | 225647 | |
| 225490 | 225648 | /* |
| 225491 | 225649 | ** Return true if zName is the extension on one of the shadow tables used |
| 225492 | 225650 | ** by this module. |
| | @@ -230265,12 +230423,12 @@ |
| 230265 | 230423 | } |
| 230266 | 230424 | #endif /* SQLITE_CORE */ |
| 230267 | 230425 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 230268 | 230426 | |
| 230269 | 230427 | /************** End of stmt.c ************************************************/ |
| 230270 | | -#if __LINE__!=230270 |
| 230428 | +#if __LINE__!=230428 |
| 230271 | 230429 | #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" |
| 230273 | 230431 | #endif |
| 230274 | 230432 | /* Return the source-id for this library */ |
| 230275 | 230433 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 230276 | 230434 | /************************** End of sqlite3.c ******************************/ |
| 230277 | 230435 | |