PageRenderTime 66ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/drivers/sqlite-wp7/sqlite/pager_c.cs

https://bitbucket.org/digitalizarte/coolstorage
C# | 7747 lines | 3789 code | 503 blank | 3455 comment | 1412 complexity | dc87b803f83c8f2d9d393c1a45ec3a23 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using i16 = System.Int16;
  5. using i64 = System.Int64;
  6. using u8 = System.Byte;
  7. using u16 = System.UInt16;
  8. using u32 = System.UInt32;
  9. using Pgno = System.UInt32;
  10. using sqlite3_int64 = System.Int64;
  11. namespace Community.CsharpSqlite
  12. {
  13. using System.Text;
  14. using DbPage = Sqlite3.PgHdr;
  15. public partial class Sqlite3
  16. {
  17. /*
  18. ** 2001 September 15
  19. **
  20. ** The author disclaims copyright to this source code. In place of
  21. ** a legal notice, here is a blessing:
  22. **
  23. ** May you do good and not evil.
  24. ** May you find forgiveness for yourself and forgive others.
  25. ** May you share freely, never taking more than you give.
  26. **
  27. *************************************************************************
  28. ** This is the implementation of the page cache subsystem or "pager".
  29. **
  30. ** The pager is used to access a database disk file. It implements
  31. ** atomic commit and rollback through the use of a journal file that
  32. ** is separate from the database file. The pager also implements file
  33. ** locking to prevent two processes from writing the same database
  34. ** file simultaneously, or one process from reading the database while
  35. ** another is writing.
  36. *************************************************************************
  37. ** Included in SQLite3 port to C#-SQLite; 2008 Noah B Hart
  38. ** C#-SQLite is an independent reimplementation of the SQLite software library
  39. **
  40. ** SQLITE_SOURCE_ID: 2011-01-28 17:03:50 ed759d5a9edb3bba5f48f243df47be29e3fe8cd7
  41. **
  42. *************************************************************************
  43. */
  44. #if !SQLITE_OMIT_DISKIO
  45. //#include "sqliteInt.h"
  46. //#include "wal.h"
  47. /******************* NOTES ON THE DESIGN OF THE PAGER ************************
  48. **
  49. ** This comment block describes invariants that hold when using a rollback
  50. ** journal. These invariants do not apply for journal_mode=WAL,
  51. ** journal_mode=MEMORY, or journal_mode=OFF.
  52. **
  53. ** Within this comment block, a page is deemed to have been synced
  54. ** automatically as soon as it is written when PRAGMA synchronous=OFF.
  55. ** Otherwise, the page is not synced until the xSync method of the VFS
  56. ** is called successfully on the file containing the page.
  57. **
  58. ** Definition: A page of the database file is said to be "overwriteable" if
  59. ** one or more of the following are true about the page:
  60. **
  61. ** (a) The original content of the page as it was at the beginning of
  62. ** the transaction has been written into the rollback journal and
  63. ** synced.
  64. **
  65. ** (b) The page was a freelist leaf page at the start of the transaction.
  66. **
  67. ** (c) The page number is greater than the largest page that existed in
  68. ** the database file at the start of the transaction.
  69. **
  70. ** (1) A page of the database file is never overwritten unless one of the
  71. ** following are true:
  72. **
  73. ** (a) The page and all other pages on the same sector are overwriteable.
  74. **
  75. ** (b) The atomic page write optimization is enabled, and the entire
  76. ** transaction other than the update of the transaction sequence
  77. ** number consists of a single page change.
  78. **
  79. ** (2) The content of a page written into the rollback journal exactly matches
  80. ** both the content in the database when the rollback journal was written
  81. ** and the content in the database at the beginning of the current
  82. ** transaction.
  83. **
  84. ** (3) Writes to the database file are an integer multiple of the page size
  85. ** in length and are aligned on a page boundary.
  86. **
  87. ** (4) Reads from the database file are either aligned on a page boundary and
  88. ** an integer multiple of the page size in length or are taken from the
  89. ** first 100 bytes of the database file.
  90. **
  91. ** (5) All writes to the database file are synced prior to the rollback journal
  92. ** being deleted, truncated, or zeroed.
  93. **
  94. ** (6) If a master journal file is used, then all writes to the database file
  95. ** are synced prior to the master journal being deleted.
  96. **
  97. ** Definition: Two databases (or the same database at two points it time)
  98. ** are said to be "logically equivalent" if they give the same answer to
  99. ** all queries. Note in particular the the content of freelist leaf
  100. ** pages can be changed arbitarily without effecting the logical equivalence
  101. ** of the database.
  102. **
  103. ** (7) At any time, if any subset, including the empty set and the total set,
  104. ** of the unsynced changes to a rollback journal are removed and the
  105. ** journal is rolled back, the resulting database file will be logical
  106. ** equivalent to the database file at the beginning of the transaction.
  107. **
  108. ** (8) When a transaction is rolled back, the xTruncate method of the VFS
  109. ** is called to restore the database file to the same size it was at
  110. ** the beginning of the transaction. (In some VFSes, the xTruncate
  111. ** method is a no-op, but that does not change the fact the SQLite will
  112. ** invoke it.)
  113. **
  114. ** (9) Whenever the database file is modified, at least one bit in the range
  115. ** of bytes from 24 through 39 inclusive will be changed prior to releasing
  116. ** the EXCLUSIVE lock, thus signaling other connections on the same
  117. ** database to flush their caches.
  118. **
  119. ** (10) The pattern of bits in bytes 24 through 39 shall not repeat in less
  120. ** than one billion transactions.
  121. **
  122. ** (11) A database file is well-formed at the beginning and at the conclusion
  123. ** of every transaction.
  124. **
  125. ** (12) An EXCLUSIVE lock is held on the database file when writing to
  126. ** the database file.
  127. **
  128. ** (13) A SHARED lock is held on the database file while reading any
  129. ** content out of the database file.
  130. **
  131. ******************************************************************************/
  132. /*
  133. ** Macros for troubleshooting. Normally turned off
  134. */
  135. #if TRACE
  136. static bool sqlite3PagerTrace = false; /* True to enable tracing */
  137. //#define sqlite3DebugPrintf printf
  138. //#define PAGERTRACE(X) if( sqlite3PagerTrace ){ sqlite3DebugPrintf X; }
  139. static void PAGERTRACE( string T, params object[] ap ) { if ( sqlite3PagerTrace )sqlite3DebugPrintf( T, ap ); }
  140. #else
  141. //#define PAGERTRACE(X)
  142. static void PAGERTRACE( string T, params object[] ap )
  143. {
  144. }
  145. #endif
  146. /*
  147. ** The following two macros are used within the PAGERTRACE() macros above
  148. ** to print out file-descriptors.
  149. **
  150. ** PAGERID() takes a pointer to a Pager struct as its argument. The
  151. ** associated file-descriptor is returned. FILEHANDLEID() takes an sqlite3_file
  152. ** struct as its argument.
  153. */
  154. //#define PAGERID(p) ((int)(p.fd))
  155. static int PAGERID( Pager p )
  156. {
  157. return p.GetHashCode();
  158. }
  159. //#define FILEHANDLEID(fd) ((int)fd)
  160. static int FILEHANDLEID( sqlite3_file fd )
  161. {
  162. return fd.GetHashCode();
  163. }
  164. /*
  165. ** The Pager.eState variable stores the current 'state' of a pager. A
  166. ** pager may be in any one of the seven states shown in the following
  167. ** state diagram.
  168. **
  169. ** OPEN <------+------+
  170. ** | | |
  171. ** V | |
  172. ** +---------> READER-------+ |
  173. ** | | |
  174. ** | V |
  175. ** |<-------WRITER_LOCKED------> ERROR
  176. ** | | ^
  177. ** | V |
  178. ** |<------WRITER_CACHEMOD-------->|
  179. ** | | |
  180. ** | V |
  181. ** |<-------WRITER_DBMOD---------->|
  182. ** | | |
  183. ** | V |
  184. ** +<------WRITER_FINISHED-------->+
  185. **
  186. **
  187. ** List of state transitions and the C [function] that performs each:
  188. **
  189. ** OPEN -> READER [sqlite3PagerSharedLock]
  190. ** READER -> OPEN [pager_unlock]
  191. **
  192. ** READER -> WRITER_LOCKED [sqlite3PagerBegin]
  193. ** WRITER_LOCKED -> WRITER_CACHEMOD [pager_open_journal]
  194. ** WRITER_CACHEMOD -> WRITER_DBMOD [syncJournal]
  195. ** WRITER_DBMOD -> WRITER_FINISHED [sqlite3PagerCommitPhaseOne]
  196. ** WRITER_*** -> READER [pager_end_transaction]
  197. **
  198. ** WRITER_*** -> ERROR [pager_error]
  199. ** ERROR -> OPEN [pager_unlock]
  200. **
  201. **
  202. ** OPEN:
  203. **
  204. ** The pager starts up in this state. Nothing is guaranteed in this
  205. ** state - the file may or may not be locked and the database size is
  206. ** unknown. The database may not be read or written.
  207. **
  208. ** * No read or write transaction is active.
  209. ** * Any lock, or no lock at all, may be held on the database file.
  210. ** * The dbSize, dbOrigSize and dbFileSize variables may not be trusted.
  211. **
  212. ** READER:
  213. **
  214. ** In this state all the requirements for reading the database in
  215. ** rollback (non-WAL) mode are met. Unless the pager is (or recently
  216. ** was) in exclusive-locking mode, a user-level read transaction is
  217. ** open. The database size is known in this state.
  218. **
  219. ** A connection running with locking_mode=normal enters this state when
  220. ** it opens a read-transaction on the database and returns to state
  221. ** OPEN after the read-transaction is completed. However a connection
  222. ** running in locking_mode=exclusive (including temp databases) remains in
  223. ** this state even after the read-transaction is closed. The only way
  224. ** a locking_mode=exclusive connection can transition from READER to OPEN
  225. ** is via the ERROR state (see below).
  226. **
  227. ** * A read transaction may be active (but a write-transaction cannot).
  228. ** * A SHARED or greater lock is held on the database file.
  229. ** * The dbSize variable may be trusted (even if a user-level read
  230. ** transaction is not active). The dbOrigSize and dbFileSize variables
  231. ** may not be trusted at this point.
  232. ** * If the database is a WAL database, then the WAL connection is open.
  233. ** * Even if a read-transaction is not open, it is guaranteed that
  234. ** there is no hot-journal in the file-system.
  235. **
  236. ** WRITER_LOCKED:
  237. **
  238. ** The pager moves to this state from READER when a write-transaction
  239. ** is first opened on the database. In WRITER_LOCKED state, all locks
  240. ** required to start a write-transaction are held, but no actual
  241. ** modifications to the cache or database have taken place.
  242. **
  243. ** In rollback mode, a RESERVED or (if the transaction was opened with
  244. ** BEGIN EXCLUSIVE) EXCLUSIVE lock is obtained on the database file when
  245. ** moving to this state, but the journal file is not written to or opened
  246. ** to in this state. If the transaction is committed or rolled back while
  247. ** in WRITER_LOCKED state, all that is required is to unlock the database
  248. ** file.
  249. **
  250. ** IN WAL mode, WalBeginWriteTransaction() is called to lock the log file.
  251. ** If the connection is running with locking_mode=exclusive, an attempt
  252. ** is made to obtain an EXCLUSIVE lock on the database file.
  253. **
  254. ** * A write transaction is active.
  255. ** * If the connection is open in rollback-mode, a RESERVED or greater
  256. ** lock is held on the database file.
  257. ** * If the connection is open in WAL-mode, a WAL write transaction
  258. ** is open (i.e. sqlite3WalBeginWriteTransaction() has been successfully
  259. ** called).
  260. ** * The dbSize, dbOrigSize and dbFileSize variables are all valid.
  261. ** * The contents of the pager cache have not been modified.
  262. ** * The journal file may or may not be open.
  263. ** * Nothing (not even the first header) has been written to the journal.
  264. **
  265. ** WRITER_CACHEMOD:
  266. **
  267. ** A pager moves from WRITER_LOCKED state to this state when a page is
  268. ** first modified by the upper layer. In rollback mode the journal file
  269. ** is opened (if it is not already open) and a header written to the
  270. ** start of it. The database file on disk has not been modified.
  271. **
  272. ** * A write transaction is active.
  273. ** * A RESERVED or greater lock is held on the database file.
  274. ** * The journal file is open and the first header has been written
  275. ** to it, but the header has not been synced to disk.
  276. ** * The contents of the page cache have been modified.
  277. **
  278. ** WRITER_DBMOD:
  279. **
  280. ** The pager transitions from WRITER_CACHEMOD into WRITER_DBMOD state
  281. ** when it modifies the contents of the database file. WAL connections
  282. ** never enter this state (since they do not modify the database file,
  283. ** just the log file).
  284. **
  285. ** * A write transaction is active.
  286. ** * An EXCLUSIVE or greater lock is held on the database file.
  287. ** * The journal file is open and the first header has been written
  288. ** and synced to disk.
  289. ** * The contents of the page cache have been modified (and possibly
  290. ** written to disk).
  291. **
  292. ** WRITER_FINISHED:
  293. **
  294. ** It is not possible for a WAL connection to enter this state.
  295. **
  296. ** A rollback-mode pager changes to WRITER_FINISHED state from WRITER_DBMOD
  297. ** state after the entire transaction has been successfully written into the
  298. ** database file. In this state the transaction may be committed simply
  299. ** by finalizing the journal file. Once in WRITER_FINISHED state, it is
  300. ** not possible to modify the database further. At this point, the upper
  301. ** layer must either commit or rollback the transaction.
  302. **
  303. ** * A write transaction is active.
  304. ** * An EXCLUSIVE or greater lock is held on the database file.
  305. ** * All writing and syncing of journal and database data has finished.
  306. ** If no error occured, all that remains is to finalize the journal to
  307. ** commit the transaction. If an error did occur, the caller will need
  308. ** to rollback the transaction.
  309. **
  310. ** ERROR:
  311. **
  312. ** The ERROR state is entered when an IO or disk-full error (including
  313. ** SQLITE_IOERR_NOMEM) occurs at a point in the code that makes it
  314. ** difficult to be sure that the in-memory pager state (cache contents,
  315. ** db size etc.) are consistent with the contents of the file-system.
  316. **
  317. ** Temporary pager files may enter the ERROR state, but in-memory pagers
  318. ** cannot.
  319. **
  320. ** For example, if an IO error occurs while performing a rollback,
  321. ** the contents of the page-cache may be left in an inconsistent state.
  322. ** At this point it would be dangerous to change back to READER state
  323. ** (as usually happens after a rollback). Any subsequent readers might
  324. ** report database corruption (due to the inconsistent cache), and if
  325. ** they upgrade to writers, they may inadvertently corrupt the database
  326. ** file. To avoid this hazard, the pager switches into the ERROR state
  327. ** instead of READER following such an error.
  328. **
  329. ** Once it has entered the ERROR state, any attempt to use the pager
  330. ** to read or write data returns an error. Eventually, once all
  331. ** outstanding transactions have been abandoned, the pager is able to
  332. ** transition back to OPEN state, discarding the contents of the
  333. ** page-cache and any other in-memory state at the same time. Everything
  334. ** is reloaded from disk (and, if necessary, hot-journal rollback peformed)
  335. ** when a read-transaction is next opened on the pager (transitioning
  336. ** the pager into READER state). At that point the system has recovered
  337. ** from the error.
  338. **
  339. ** Specifically, the pager jumps into the ERROR state if:
  340. **
  341. ** 1. An error occurs while attempting a rollback. This happens in
  342. ** function sqlite3PagerRollback().
  343. **
  344. ** 2. An error occurs while attempting to finalize a journal file
  345. ** following a commit in function sqlite3PagerCommitPhaseTwo().
  346. **
  347. ** 3. An error occurs while attempting to write to the journal or
  348. ** database file in function pagerStress() in order to free up
  349. ** memory.
  350. **
  351. ** In other cases, the error is returned to the b-tree layer. The b-tree
  352. ** layer then attempts a rollback operation. If the error condition
  353. ** persists, the pager enters the ERROR state via condition (1) above.
  354. **
  355. ** Condition (3) is necessary because it can be triggered by a read-only
  356. ** statement executed within a transaction. In this case, if the error
  357. ** code were simply returned to the user, the b-tree layer would not
  358. ** automatically attempt a rollback, as it assumes that an error in a
  359. ** read-only statement cannot leave the pager in an internally inconsistent
  360. ** state.
  361. **
  362. ** * The Pager.errCode variable is set to something other than SQLITE_OK.
  363. ** * There are one or more outstanding references to pages (after the
  364. ** last reference is dropped the pager should move back to OPEN state).
  365. ** * The pager is not an in-memory pager.
  366. **
  367. **
  368. ** Notes:
  369. **
  370. ** * A pager is never in WRITER_DBMOD or WRITER_FINISHED state if the
  371. ** connection is open in WAL mode. A WAL connection is always in one
  372. ** of the first four states.
  373. **
  374. ** * Normally, a connection open in exclusive mode is never in PAGER_OPEN
  375. ** state. There are two exceptions: immediately after exclusive-mode has
  376. ** been turned on (and before any read or write transactions are
  377. ** executed), and when the pager is leaving the "error state".
  378. **
  379. ** * See also: assert_pager_state().
  380. */
  381. //#define PAGER_OPEN 0
  382. //#define PAGER_READER 1
  383. //#define PAGER_WRITER_LOCKED 2
  384. //#define PAGER_WRITER_CACHEMOD 3
  385. //#define PAGER_WRITER_DBMOD 4
  386. //#define PAGER_WRITER_FINISHED 5
  387. //#define PAGER_ERROR 6
  388. const int PAGER_OPEN = 0;
  389. const int PAGER_READER = 1;
  390. const int PAGER_WRITER_LOCKED = 2;
  391. const int PAGER_WRITER_CACHEMOD = 3;
  392. const int PAGER_WRITER_DBMOD = 4;
  393. const int PAGER_WRITER_FINISHED = 5;
  394. const int PAGER_ERROR = 6;
  395. /*
  396. ** The Pager.eLock variable is almost always set to one of the
  397. ** following locking-states, according to the lock currently held on
  398. ** the database file: NO_LOCK, SHARED_LOCK, RESERVED_LOCK or EXCLUSIVE_LOCK.
  399. ** This variable is kept up to date as locks are taken and released by
  400. ** the pagerLockDb() and pagerUnlockDb() wrappers.
  401. **
  402. ** If the VFS xLock() or xUnlock() returns an error other than SQLITE_BUSY
  403. ** (i.e. one of the SQLITE_IOERR subtypes), it is not clear whether or not
  404. ** the operation was successful. In these circumstances pagerLockDb() and
  405. ** pagerUnlockDb() take a conservative approach - eLock is always updated
  406. ** when unlocking the file, and only updated when locking the file if the
  407. ** VFS call is successful. This way, the Pager.eLock variable may be set
  408. ** to a less exclusive (lower) value than the lock that is actually held
  409. ** at the system level, but it is never set to a more exclusive value.
  410. **
  411. ** This is usually safe. If an xUnlock fails or appears to fail, there may
  412. ** be a few redundant xLock() calls or a lock may be held for longer than
  413. ** required, but nothing really goes wrong.
  414. **
  415. ** The exception is when the database file is unlocked as the pager moves
  416. ** from ERROR to OPEN state. At this point there may be a hot-journal file
  417. ** in the file-system that needs to be rolled back (as part of a OPEN->SHARED
  418. ** transition, by the same pager or any other). If the call to xUnlock()
  419. ** fails at this point and the pager is left holding an EXCLUSIVE lock, this
  420. ** can confuse the call to xCheckReservedLock() call made later as part
  421. ** of hot-journal detection.
  422. **
  423. ** xCheckReservedLock() is defined as returning true "if there is a RESERVED
  424. ** lock held by this process or any others". So xCheckReservedLock may
  425. ** return true because the caller itself is holding an EXCLUSIVE lock (but
  426. ** doesn't know it because of a previous error in xUnlock). If this happens
  427. ** a hot-journal may be mistaken for a journal being created by an active
  428. ** transaction in another process, causing SQLite to read from the database
  429. ** without rolling it back.
  430. **
  431. ** To work around this, if a call to xUnlock() fails when unlocking the
  432. ** database in the ERROR state, Pager.eLock is set to UNKNOWN_LOCK. It
  433. ** is only changed back to a real locking state after a successful call
  434. ** to xLock(EXCLUSIVE). Also, the code to do the OPEN->SHARED state transition
  435. ** omits the check for a hot-journal if Pager.eLock is set to UNKNOWN_LOCK
  436. ** lock. Instead, it assumes a hot-journal exists and obtains an EXCLUSIVE
  437. ** lock on the database file before attempting to roll it back. See function
  438. ** PagerSharedLock() for more detail.
  439. **
  440. ** Pager.eLock may only be set to UNKNOWN_LOCK when the pager is in
  441. ** PAGER_OPEN state.
  442. */
  443. //#define UNKNOWN_LOCK (EXCLUSIVE_LOCK+1)
  444. const int UNKNOWN_LOCK = ( EXCLUSIVE_LOCK + 1 );
  445. /*
  446. ** A macro used for invoking the codec if there is one
  447. */
  448. // The E parameter is what executes when there is an error,
  449. // cannot implement here, since this is not really a macro
  450. // calling code must be modified to call E when truen
  451. #if SQLITE_HAS_CODEC
  452. //# define CODEC1(P,D,N,X,E) \
  453. //if( P.xCodec && P.xCodec(P.pCodec,D,N,X)==0 ){ E; }
  454. static bool CODEC1( Pager P, byte[] D, uint N /* page number */, int X /* E (moved to caller */)
  455. {
  456. return ( ( P.xCodec != null ) && ( P.xCodec( P.pCodec, D, N, X ) == null ) );
  457. }
  458. // The E parameter is what executes when there is an error,
  459. // cannot implement here, since this is not really a macro
  460. // calling code must be modified to call E when truen
  461. //# define CODEC2(P,D,N,X,E,O) \
  462. //if( P.xCodec==0 ){ O=(char*)D; }else \
  463. //if( (O=(char*)(P.xCodec(P.pCodec,D,N,X)))==0 ){ E; }
  464. static bool CODEC2( Pager P, byte[] D, uint N, int X, ref byte[] O )
  465. {
  466. if ( P.xCodec == null )
  467. {
  468. O = D; // do nothing
  469. return false;
  470. }
  471. else
  472. {
  473. return ( ( O = P.xCodec( P.pCodec, D, N, X ) ) == null );
  474. }
  475. }
  476. #else
  477. //# define CODEC1(P,D,N,X,E) /* NO-OP */
  478. static bool CODEC1 (Pager P, byte[] D, uint N /* page number */, int X /* E (moved to caller */) { return false; }
  479. //# define CODEC2(P,D,N,X,E,O) O=(char*)D
  480. static bool CODEC2( Pager P, byte[] D, uint N, int X, ref byte[] O ) { O = D; return false; }
  481. #endif
  482. /*
  483. ** The maximum allowed sector size. 64KiB. If the xSectorsize() method
  484. ** returns a value larger than this, then MAX_SECTOR_SIZE is used instead.
  485. ** This could conceivably cause corruption following a power failure on
  486. ** such a system. This is currently an undocumented limit.
  487. */
  488. //#define MAX_SECTOR_SIZE 0x10000
  489. const int MAX_SECTOR_SIZE = 0x10000;
  490. /*
  491. ** An instance of the following structure is allocated for each active
  492. ** savepoint and statement transaction in the system. All such structures
  493. ** are stored in the Pager.aSavepoint[] array, which is allocated and
  494. ** resized using sqlite3Realloc().
  495. **
  496. ** When a savepoint is created, the PagerSavepoint.iHdrOffset field is
  497. ** set to 0. If a journal-header is written into the main journal while
  498. ** the savepoint is active, then iHdrOffset is set to the byte offset
  499. ** immediately following the last journal record written into the main
  500. ** journal before the journal-header. This is required during savepoint
  501. ** rollback (see pagerPlaybackSavepoint()).
  502. */
  503. //typedef struct PagerSavepoint PagerSavepoint;
  504. public class PagerSavepoint
  505. {
  506. public i64 iOffset; /* Starting offset in main journal */
  507. public i64 iHdrOffset; /* See above */
  508. public Bitvec pInSavepoint; /* Set of pages in this savepoint */
  509. public Pgno nOrig; /* Original number of pages in file */
  510. public Pgno iSubRec; /* Index of first record in sub-journal */
  511. #if !SQLITE_OMIT_WAL
  512. public u32 aWalData[WAL_SAVEPOINT_NDATA]; /* WAL savepoint context */
  513. #else
  514. public object aWalData = null; /* Used for C# convenience */
  515. #endif
  516. public static implicit operator bool( PagerSavepoint b )
  517. {
  518. return ( b != null );
  519. }
  520. };
  521. /*
  522. ** A open page cache is an instance of struct Pager. A description of
  523. ** some of the more important member variables follows:
  524. **
  525. ** eState
  526. **
  527. ** The current 'state' of the pager object. See the comment and state
  528. ** diagram above for a description of the pager state.
  529. **
  530. ** eLock
  531. **
  532. ** For a real on-disk database, the current lock held on the database file -
  533. ** NO_LOCK, SHARED_LOCK, RESERVED_LOCK or EXCLUSIVE_LOCK.
  534. **
  535. ** For a temporary or in-memory database (neither of which require any
  536. ** locks), this variable is always set to EXCLUSIVE_LOCK. Since such
  537. ** databases always have Pager.exclusiveMode==1, this tricks the pager
  538. ** logic into thinking that it already has all the locks it will ever
  539. ** need (and no reason to release them).
  540. **
  541. ** In some (obscure) circumstances, this variable may also be set to
  542. ** UNKNOWN_LOCK. See the comment above the #define of UNKNOWN_LOCK for
  543. ** details.
  544. **
  545. ** changeCountDone
  546. **
  547. ** This boolean variable is used to make sure that the change-counter
  548. ** (the 4-byte header field at byte offset 24 of the database file) is
  549. ** not updated more often than necessary.
  550. **
  551. ** It is set to true when the change-counter field is updated, which
  552. ** can only happen if an exclusive lock is held on the database file.
  553. ** It is cleared (set to false) whenever an exclusive lock is
  554. ** relinquished on the database file. Each time a transaction is committed,
  555. ** The changeCountDone flag is inspected. If it is true, the work of
  556. ** updating the change-counter is omitted for the current transaction.
  557. **
  558. ** This mechanism means that when running in exclusive mode, a connection
  559. ** need only update the change-counter once, for the first transaction
  560. ** committed.
  561. **
  562. ** setMaster
  563. **
  564. ** When PagerCommitPhaseOne() is called to commit a transaction, it may
  565. ** (or may not) specify a master-journal name to be written into the
  566. ** journal file before it is synced to disk.
  567. **
  568. ** Whether or not a journal file contains a master-journal pointer affects
  569. ** the way in which the journal file is finalized after the transaction is
  570. ** committed or rolled back when running in "journal_mode=PERSIST" mode.
  571. ** If a journal file does not contain a master-journal pointer, it is
  572. ** finalized by overwriting the first journal header with zeroes. If
  573. ** it does contain a master-journal pointer the journal file is finalized
  574. ** by truncating it to zero bytes, just as if the connection were
  575. ** running in "journal_mode=truncate" mode.
  576. **
  577. ** Journal files that contain master journal pointers cannot be finalized
  578. ** simply by overwriting the first journal-header with zeroes, as the
  579. ** master journal pointer could interfere with hot-journal rollback of any
  580. ** subsequently interrupted transaction that reuses the journal file.
  581. **
  582. ** The flag is cleared as soon as the journal file is finalized (either
  583. ** by PagerCommitPhaseTwo or PagerRollback). If an IO error prevents the
  584. ** journal file from being successfully finalized, the setMaster flag
  585. ** is cleared anyway (and the pager will move to ERROR state).
  586. **
  587. ** doNotSpill, doNotSyncSpill
  588. **
  589. ** These two boolean variables control the behaviour of cache-spills
  590. ** (calls made by the pcache module to the pagerStress() routine to
  591. ** write cached data to the file-system in order to free up memory).
  592. **
  593. ** When doNotSpill is non-zero, writing to the database from pagerStress()
  594. ** is disabled altogether. This is done in a very obscure case that
  595. ** comes up during savepoint rollback that requires the pcache module
  596. ** to allocate a new page to prevent the journal file from being written
  597. ** while it is being traversed by code in pager_playback().
  598. **
  599. ** If doNotSyncSpill is non-zero, writing to the database from pagerStress()
  600. ** is permitted, but syncing the journal file is not. This flag is set
  601. ** by sqlite3PagerWrite() when the file-system sector-size is larger than
  602. ** the database page-size in order to prevent a journal sync from happening
  603. ** in between the journalling of two pages on the same sector.
  604. **
  605. ** subjInMemory
  606. **
  607. ** This is a boolean variable. If true, then any required sub-journal
  608. ** is opened as an in-memory journal file. If false, then in-memory
  609. ** sub-journals are only used for in-memory pager files.
  610. **
  611. ** This variable is updated by the upper layer each time a new
  612. ** write-transaction is opened.
  613. **
  614. ** dbSize, dbOrigSize, dbFileSize
  615. **
  616. ** Variable dbSize is set to the number of pages in the database file.
  617. ** It is valid in PAGER_READER and higher states (all states except for
  618. ** OPEN and ERROR).
  619. **
  620. ** dbSize is set based on the size of the database file, which may be
  621. ** larger than the size of the database (the value stored at offset
  622. ** 28 of the database header by the btree). If the size of the file
  623. ** is not an integer multiple of the page-size, the value stored in
  624. ** dbSize is rounded down (i.e. a 5KB file with 2K page-size has dbSize==2).
  625. ** Except, any file that is greater than 0 bytes in size is considered
  626. ** to have at least one page. (i.e. a 1KB file with 2K page-size leads
  627. ** to dbSize==1).
  628. **
  629. ** During a write-transaction, if pages with page-numbers greater than
  630. ** dbSize are modified in the cache, dbSize is updated accordingly.
  631. ** Similarly, if the database is truncated using PagerTruncateImage(),
  632. ** dbSize is updated.
  633. **
  634. ** Variables dbOrigSize and dbFileSize are valid in states
  635. ** PAGER_WRITER_LOCKED and higher. dbOrigSize is a copy of the dbSize
  636. ** variable at the start of the transaction. It is used during rollback,
  637. ** and to determine whether or not pages need to be journalled before
  638. ** being modified.
  639. **
  640. ** Throughout a write-transaction, dbFileSize contains the size of
  641. ** the file on disk in pages. It is set to a copy of dbSize when the
  642. ** write-transaction is first opened, and updated when VFS calls are made
  643. ** to write or truncate the database file on disk.
  644. **
  645. ** The only reason the dbFileSize variable is required is to suppress
  646. ** unnecessary calls to xTruncate() after committing a transaction. If,
  647. ** when a transaction is committed, the dbFileSize variable indicates
  648. ** that the database file is larger than the database image (Pager.dbSize),
  649. ** pager_truncate() is called. The pager_truncate() call uses xFilesize()
  650. ** to measure the database file on disk, and then truncates it if required.
  651. ** dbFileSize is not used when rolling back a transaction. In this case
  652. ** pager_truncate() is called unconditionally (which means there may be
  653. ** a call to xFilesize() that is not strictly required). In either case,
  654. ** pager_truncate() may cause the file to become smaller or larger.
  655. **
  656. ** dbHintSize
  657. **
  658. ** The dbHintSize variable is used to limit the number of calls made to
  659. ** the VFS xFileControl(FCNTL_SIZE_HINT) method.
  660. **
  661. ** dbHintSize is set to a copy of the dbSize variable when a
  662. ** write-transaction is opened (at the same time as dbFileSize and
  663. ** dbOrigSize). If the xFileControl(FCNTL_SIZE_HINT) method is called,
  664. ** dbHintSize is increased to the number of pages that correspond to the
  665. ** size-hint passed to the method call. See pager_write_pagelist() for
  666. ** details.
  667. **
  668. ** errCode
  669. **
  670. ** The Pager.errCode variable is only ever used in PAGER_ERROR state. It
  671. ** is set to zero in all other states. In PAGER_ERROR state, Pager.errCode
  672. ** is always set to SQLITE_FULL, SQLITE_IOERR or one of the SQLITE_IOERR_XXX
  673. ** sub-codes.
  674. */
  675. public class Pager
  676. {
  677. public sqlite3_vfs pVfs; /* OS functions to use for IO */
  678. public bool exclusiveMode; /* Boolean. True if locking_mode==EXCLUSIVE */
  679. public u8 journalMode; /* One of the PAGER_JOURNALMODE_* values */
  680. public u8 useJournal; /* Use a rollback journal on this file */
  681. public u8 noReadlock; /* Do not bother to obtain readlocks */
  682. public bool noSync; /* Do not sync the journal if true */
  683. public bool fullSync; /* Do extra syncs of the journal for robustness */
  684. public u8 ckptSyncFlags; /* SYNC_NORMAL or SYNC_FULL for checkpoint */
  685. public u8 syncFlags; /* SYNC_NORMAL or SYNC_FULL otherwise */
  686. public bool tempFile; /* zFilename is a temporary file */
  687. public bool readOnly; /* True for a read-only database */
  688. public bool alwaysRollback; /* Disable DontRollback() for all pages */
  689. public u8 memDb; /* True to inhibit all file I/O */
  690. /**************************************************************************
  691. ** The following block contains those class members that change during
  692. ** routine opertion. Class members not in this block are either fixed
  693. ** when the pager is first created or else only change when there is a
  694. ** significant mode change (such as changing the page_size, locking_mode,
  695. ** or the journal_mode). From another view, these class members describe
  696. ** the "state" of the pager, while other class members describe the
  697. ** "configuration" of the pager.
  698. */
  699. public u8 eState; /* Pager state (OPEN, READER, WRITER_LOCKED..) */
  700. public u8 eLock; /* Current lock held on database file */
  701. public bool changeCountDone; /* Set after incrementing the change-counter */
  702. public int setMaster; /* True if a m-j name has been written to jrnl */
  703. public u8 doNotSpill; /* Do not spill the cache when non-zero */
  704. public u8 doNotSyncSpill; /* Do not do a spill that requires jrnl sync */
  705. public u8 subjInMemory; /* True to use in-memory sub-journals */
  706. public Pgno dbSize; /* Number of pages in the database */
  707. public Pgno dbOrigSize; /* dbSize before the current transaction */
  708. public Pgno dbFileSize; /* Number of pages in the database file */
  709. public Pgno dbHintSize; /* Value passed to FCNTL_SIZE_HINT call */
  710. public int errCode; /* One of several kinds of errors */
  711. public int nRec; /* Pages journalled since last j-header written */
  712. public u32 cksumInit; /* Quasi-random value added to every checksum */
  713. public u32 nSubRec; /* Number of records written to sub-journal */
  714. public Bitvec pInJournal; /* One bit for each page in the database file */
  715. public sqlite3_file fd; /* File descriptor for database */
  716. public sqlite3_file jfd; /* File descriptor for main journal */
  717. public sqlite3_file sjfd; /* File descriptor for sub-journal */
  718. public i64 journalOff; /* Current write offset in the journal file */
  719. public i64 journalHdr; /* Byte offset to previous journal header */
  720. public sqlite3_backup pBackup; /* Pointer to list of ongoing backup processes */
  721. public PagerSavepoint[] aSavepoint;/* Array of active savepoints */
  722. public int nSavepoint; /* Number of elements in aSavepoint[] */
  723. public u8[] dbFileVers = new u8[16];/* Changes whenever database file changes */
  724. /*
  725. ** End of the routinely-changing class members
  726. ***************************************************************************/
  727. public u16 nExtra; /* Add this many bytes to each in-memory page */
  728. public i16 nReserve; /* Number of unused bytes at end of each page */
  729. public u32 vfsFlags; /* Flags for sqlite3_vfs.xOpen() */
  730. public u32 sectorSize; /* Assumed sector size during rollback */
  731. public int pageSize; /* Number of bytes in a page */
  732. public Pgno mxPgno; /* Maximum allowed size of the database */
  733. public i64 journalSizeLimit; /* Size limit for persistent journal files */
  734. public string zFilename; /* Name of the database file */
  735. public string zJournal; /* Name of the journal file */
  736. public dxBusyHandler xBusyHandler; /* Function to call when busy */
  737. public object pBusyHandlerArg; /* Context argument for xBusyHandler */
  738. #if SQLITE_TEST || DEBUG
  739. public int nHit, nMiss; /* Cache hits and missing */
  740. public int nRead, nWrite; /* Database pages read/written */
  741. #else
  742. public int nHit;
  743. #endif
  744. public dxReiniter xReiniter; //(DbPage*,int);/* Call this routine when reloading pages */
  745. #if SQLITE_HAS_CODEC
  746. //void *(*xCodec)(void*,void*,Pgno,int);
  747. public dxCodec xCodec; /* Routine for en/decoding data */
  748. //void (*xCodecSizeChng)(void*,int,int);
  749. public dxCodecSizeChng xCodecSizeChng; /* Notify of page size changes */
  750. //void (*xCodecFree)(void*);
  751. public dxCodecFree xCodecFree; /* Destructor for the codec */
  752. public codec_ctx pCodec; /* First argument to xCodec... methods */
  753. #endif
  754. public byte[] pTmpSpace; /* Pager.pageSize bytes of space for tmp use */
  755. public PCache pPCache; /* Pointer to page cache object */
  756. #if !SQLITE_OMIT_WAL
  757. public Wal pWal; /* Write-ahead log used by "journal_mode=wal" */
  758. public string zWal; /* File name for write-ahead log */
  759. #else
  760. public object pWal = null; /* Having this dummy here makes C# easier */
  761. #endif
  762. };
  763. /*
  764. ** The following global variables hold counters used for
  765. ** testing purposes only. These variables do not exist in
  766. ** a non-testing build. These variables are not thread-safe.
  767. */
  768. #if SQLITE_TEST
  769. //static int sqlite3_pager_readdb_count = 0; /* Number of full pages read from DB */
  770. //static int sqlite3_pager_writedb_count = 0; /* Number of full pages written to DB */
  771. //static int sqlite3_pager_writej_count = 0; /* Number of pages written to journal */
  772. static void PAGER_INCR( ref int v )
  773. {
  774. v++;
  775. }
  776. #else
  777. //# define PAGER_INCR(v)
  778. static void PAGER_INCR(ref int v) {}
  779. #endif
  780. /*
  781. ** Journal files begin with the following magic string. The data
  782. ** was obtained from /dev/random. It is used only as a sanity check.
  783. **
  784. ** Since version 2.8.0, the journal format contains additional sanity
  785. ** checking information. If the power fails while the journal is being
  786. ** written, semi-random garbage data might appear in the journal
  787. ** file after power is restored. If an attempt is then made
  788. ** to roll the journal back, the database could be corrupted. The additional
  789. ** sanity checking data is an attempt to discover the garbage in the
  790. ** journal and ignore it.
  791. **
  792. ** The sanity checking information for the new journal format consists
  793. ** of a 32-bit checksum on each page of data. The checksum covers both
  794. ** the page number and the pPager.pageSize bytes of data for the page.
  795. ** This cksum is initialized to a 32-bit random value that appears in the
  796. ** journal file right after the header. The random initializer is important,
  797. ** because garbage data that appears at the end of a journal is likely
  798. ** data that was once in other files that have now been deleted. If the
  799. ** garbage data came from an obsolete journal file, the checksums might
  800. ** be correct. But by initializing the checksum to random value which
  801. ** is different for every journal, we minimize that risk.
  802. */
  803. static byte[] aJournalMagic = new byte[] {
  804. 0xd9, 0xd5, 0x05, 0xf9, 0x20, 0xa1, 0x63, 0xd7,
  805. };
  806. /*
  807. ** The size of the of each page record in the journal is given by
  808. ** the following macro.
  809. */
  810. //#define JOURNAL_PG_SZ(pPager) ((pPager.pageSize) + 8)
  811. static int JOURNAL_PG_SZ( Pager pPager )
  812. {
  813. return ( pPager.pageSize + 8 );
  814. }
  815. /*
  816. ** The journal header size for this pager. This is usually the same
  817. ** size as a single disk sector. See also setSectorSize().
  818. */
  819. //#define JOURNAL_HDR_SZ(pPager) (pPager.sectorSize)
  820. static u32 JOURNAL_HDR_SZ( Pager pPager )
  821. {
  822. return ( pPager.sectorSize );
  823. }
  824. /*
  825. ** The macro MEMDB is true if we are dealing with an in-memory database.
  826. ** We do this as a macro so that if the SQLITE_OMIT_MEMORYDB macro is set,
  827. ** the value of MEMDB will be a constant and the compiler will optimize
  828. ** out code that would never execute.
  829. */
  830. #if SQLITE_OMIT_MEMORYDB
  831. //# define MEMDB 0
  832. const int MEMDB = 0;
  833. #else
  834. //# define MEMDB pPager.memDb
  835. #endif
  836. /*
  837. ** The maximum legal page number is (2^31 - 1).
  838. */
  839. //#define PAGER_MAX_PGNO 2147483647
  840. const int PAGER_MAX_PGNO = 2147483647;
  841. /*
  842. ** The argument to this macro is a file descriptor (type sqlite3_file*).
  843. ** Return 0 if it is not open, or non-zero (but not 1) if it is.
  844. **
  845. ** This is so that expressions can be written as:
  846. **
  847. ** if( isOpen(pPager->jfd) ){ ...
  848. **
  849. ** instead of
  850. **
  851. ** if( pPager->jfd->pMethods ){ ...
  852. */
  853. //#define isOpen(pFd) ((pFd)->pMethods)
  854. static bool isOpen( sqlite3_file pFd )
  855. {
  856. return pFd.pMethods != null;
  857. }
  858. /*
  859. ** Return true if this pager uses a write-ahead log instead of the usual
  860. ** rollback journal. Otherwise false.
  861. */
  862. #if !SQLITE_OMIT_WAL
  863. static int pagerUseWal(Pager *pPager){
  864. return (pPager->pWal!=0);
  865. }
  866. #else
  867. //# define pagerUseWal(x) 0
  868. static bool pagerUseWal( Pager x )
  869. {
  870. return false;
  871. }
  872. //# define pagerRollbackWal(x) 0
  873. static int pagerRollbackWal( Pager x )
  874. {
  875. return 0;
  876. }
  877. //# define pagerWalFrames(v,w,x,y,z) 0
  878. static int pagerWalFrames( Pager v, PgHdr w, Pgno x, int y, int z )
  879. {
  880. return 0;
  881. }
  882. //# define pagerOpenWalIfPresent(z) SQLITE_OK
  883. static int pagerOpenWalIfPresent( Pager z )
  884. {
  885. return SQLITE_OK;
  886. }
  887. //# define pagerBeginReadTransaction(z) SQLITE_OK
  888. static int pagerBeginReadTransaction( Pager z )
  889. {
  890. return SQLITE_OK;
  891. }
  892. #endif
  893. #if NDEBUG
  894. /*
  895. ** Usage:
  896. **
  897. ** Debug.Assert( assert_pager_state(pPager) );
  898. **
  899. ** This function runs many Debug.Asserts to try to find inconsistencies in
  900. ** the internal state of the Pager object.
  901. */
  902. static bool assert_pager_state( Pager p )
  903. {
  904. Pager pPager = p;
  905. /* State must be valid. */
  906. Debug.Assert( p.eState == PAGER_OPEN
  907. || p.eState == PAGER_READER
  908. || p.eState == PAGER_WRITER_LOCKED
  909. || p.eState == PAGER_WRITER_CACHEMOD
  910. || p.eState == PAGER_WRITER_DBMOD
  911. || p.eState == PAGER_WRITER_FINISHED
  912. || p.eState == PAGER_ERROR
  913. );
  914. /* Regardless of the current state, a temp-file connection always behaves
  915. ** as if it has an exclusive lock on the database file. It never updates
  916. ** the change-counter field, so the changeCountDone flag is always set.
  917. */
  918. Debug.Assert( p.tempFile == false || p.eLock == EXCLUSIVE_LOCK );
  919. Debug.Assert( p.tempFile == false || pPager.changeCountDone );
  920. /* If the useJournal flag is clear, the journal-mode must be "OFF".
  921. ** And if the journal-mode is "OFF", the journal file must not be open.
  922. */
  923. Debug.Assert( p.journalMode == PAGER_JOURNALMODE_OFF || p.useJournal != 0 );
  924. Debug.Assert( p.journalMode != PAGER_JOURNALMODE_OFF || !isOpen( p.jfd ) );
  925. /* Check that MEMDB implies noSync. And an in-memory journal. Since
  926. ** this means an in-memory pager performs no IO at all, it cannot encounter
  927. ** either SQLITE_IOERR or SQLITE_FULL during rollback or while finalizing
  928. ** a journal file. (although the in-memory journal implementation may
  929. ** return SQLITE_IOERR_NOMEM while the journal file is being written). It
  930. ** is therefore not possible for an in-memory pager to enter the ERROR
  931. ** state.
  932. */
  933. if (
  934. #if SQLITE_OMIT_MEMORYDB
  935. 0!=MEMDB
  936. #else
  937. 0 != pPager.memDb
  938. #endif
  939. )
  940. {
  941. Debug.Assert( p.noSync );
  942. Debug.Assert( p.journalMode == PAGER_JOURNALMODE_OFF
  943. || p.journalMode == PAGER_JOURNALMODE_MEMORY
  944. );
  945. Debug.Assert( p.eState != PAGER_ERROR && p.eState != PAGER_OPEN );
  946. Debug.Assert( pagerUseWal( p ) == false );
  947. }
  948. /* If changeCountDone is set, a RESERVED lock or greater must be held
  949. ** on the file.
  950. */
  951. Debug.Assert( pPager.changeCountDone == false || pPager.eLock >= RESERVED_LOCK );
  952. Debug.Assert( p.eLock != PENDING_LOCK );
  953. switch ( p.eState )
  954. {
  955. case PAGER_OPEN:
  956. Debug.Assert(
  957. #if SQLITE_OMIT_MEMORYDB
  958. 0==MEMDB
  959. #else
  960. 0 == pPager.memDb
  961. #endif
  962. );
  963. Debug.Assert( pPager.errCode == SQLITE_OK );
  964. Debug.Assert( sqlite3PcacheRefCount( pPager.pPCache ) == 0 || pPager.tempFile );
  965. break;
  966. case PAGER_READER:
  967. Debug.Assert( pPager.errCode == SQLITE_OK );
  968. Debug.Assert( p.eLock != UNKNOWN_LOCK );
  969. Debug.Assert( p.eLock >= SHARED_LOCK || p.noReadlock != 0 );
  970. break;
  971. case PAGER_WRITER_LOCKED:
  972. Debug.Assert( p.eLock != UNKNOWN_LOCK );
  973. Debug.Assert( pPager.errCode == SQLITE_OK );
  974. if ( !pagerUseWal( pPager ) )
  975. {
  976. Debug.Assert( p.eLock >= RESERVED_LOCK );
  977. }
  978. Debug.Assert( pPager.dbSize == pPager.dbOrigSize );
  979. Debug.Assert( pPager.dbOrigSize == pPager.dbFileSize );
  980. Debug.Assert( pPager.dbOrigSize == pPager.dbHintSize );
  981. Debug.Assert( pPager.setMaster == 0 );
  982. break;
  983. case PAGER_WRITER_CACHEMOD:
  984. Debug.Assert( p.eLock != UNKNOWN_LOCK );
  985. Debug.Assert( pPager.errCode == SQLITE_OK );
  986. if ( !pagerUseWal( pPager ) )
  987. {
  988. /* It is possible that if journal_mode=wal here that neither the
  989. ** journal file nor the WAL file are open. This happens during
  990. ** a rollback transaction that switches from journal_mode=off
  991. ** to journal_mode=wal.
  992. */
  993. Debug.Assert( p.eLock >= RESERVED_LOCK );
  994. Debug.Assert( isOpen( p.jfd )
  995. || p.journalMode == PAGER_JOURNALMODE_OFF
  996. || p.journalMode == PAGER_JOURNALMODE_WAL
  997. );
  998. }
  999. Debug.Assert( pPager.dbOrigSize == pPager.dbFileSize );
  1000. Debug.Assert( pPager.dbOrigSize == pPager.dbHintSize );
  1001. break;
  1002. case PAGER_WRITER_DBMOD:
  1003. Debug.Assert( p.eLock == EXCLUSIVE_LOCK );
  1004. Debug.Assert( pPager.errCode == SQLITE_OK );
  1005. Debug.Assert( !pagerUseWal( pPager ) );
  1006. Debug.Assert( p.eLock >= EXCLUSIVE_LOCK );
  1007. Debug.Assert( isOpen( p.jfd )
  1008. || p.journalMode == PAGER_JOURNALMODE_OFF
  1009. || p.journalMode == PAGER_JOURNALMODE_WAL
  1010. );
  1011. Debug.Assert( pPager.dbOrigSize <= pPager.dbHintSize );
  1012. break;
  1013. case PAGER_WRITER_FINISHED:
  1014. Debug.Assert( p.eLock == EXCLUSIVE_LOCK );
  1015. Debug.Assert( pPager.errCode == SQLITE_OK );
  1016. Debug.Assert( !pagerUseWal( pPager ) );
  1017. Debug.Assert( isOpen( p.jfd )
  1018. || p.journalMode == PAGER_JOURNALMODE_OFF
  1019. || p.journalMode == PAGER_JOURNALMODE_WAL
  1020. );
  1021. break;
  1022. case PAGER_ERROR:
  1023. /* There must be at least one outstanding reference to the pager if
  1024. ** in ERROR state. Otherwise the pager should have already dropped
  1025. ** back to OPEN state.
  1026. */
  1027. Debug.Assert( pPager.errCode != SQLITE_OK );
  1028. Debug.Assert( sqlite3PcacheRefCount( pPager.pPCache ) > 0 );
  1029. break;
  1030. }
  1031. return true;
  1032. }
  1033. #else
  1034. static bool assert_pager_state( Pager pPager )
  1035. {
  1036. return true;
  1037. }
  1038. #endif //* ifndef NDEBUG */
  1039. #if

Large files files are truncated, but you can click here to view the full file