0000: 2f 2a 0a 2a 2a 20 32 30 30 31 20 53 65 70 74 65 /*.** 2001 Septe
0010: 6d 62 65 72 20 31 35 0a 2a 2a 0a 2a 2a 20 54 68 mber 15.**.** Th
0020: 65 20 61 75 74 68 6f 72 20 64 69 73 63 6c 61 69 e author disclai
0030: 6d 73 20 63 6f 70 79 72 69 67 68 74 20 74 6f 20 ms copyright to
0040: 74 68 69 73 20 73 6f 75 72 63 65 20 63 6f 64 65 this source code
0050: 2e 20 20 49 6e 20 70 6c 61 63 65 20 6f 66 0a 2a . In place of.*
0060: 2a 20 61 20 6c 65 67 61 6c 20 6e 6f 74 69 63 65 * a legal notice
0070: 2c 20 68 65 72 65 20 69 73 20 61 20 62 6c 65 73 , here is a bles
0080: 73 69 6e 67 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 4d sing:.**.** M
0090: 61 79 20 79 6f 75 20 64 6f 20 67 6f 6f 64 20 61 ay you do good a
00a0: 6e 64 20 6e 6f 74 20 65 76 69 6c 2e 0a 2a 2a 20 nd not evil..**
00b0: 20 20 20 4d 61 79 20 79 6f 75 20 66 69 6e 64 20 May you find
00c0: 66 6f 72 67 69 76 65 6e 65 73 73 20 66 6f 72 20 forgiveness for
00d0: 79 6f 75 72 73 65 6c 66 20 61 6e 64 20 66 6f 72 yourself and for
00e0: 67 69 76 65 20 6f 74 68 65 72 73 2e 0a 2a 2a 20 give others..**
00f0: 20 20 20 4d 61 79 20 79 6f 75 20 73 68 61 72 65 May you share
0100: 20 66 72 65 65 6c 79 2c 20 6e 65 76 65 72 20 74 freely, never t
0110: 61 6b 69 6e 67 20 6d 6f 72 65 20 74 68 61 6e 20 aking more than
0120: 79 6f 75 20 67 69 76 65 2e 0a 2a 2a 0a 2a 2a 2a you give..**.***
0130: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0140: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0150: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0160: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0170: 2a 2a 2a 2a 2a 2a 0a 2a 2a 20 54 68 69 73 20 68 ******.** This h
0180: 65 61 64 65 72 20 66 69 6c 65 20 64 65 66 69 6e eader file defin
0190: 65 73 20 74 68 65 20 69 6e 74 65 72 66 61 63 65 es the interface
01a0: 20 74 68 61 74 20 74 68 65 20 73 71 6c 69 74 65 that the sqlite
01b0: 20 70 61 67 65 20 63 61 63 68 65 0a 2a 2a 20 73 page cache.** s
01c0: 75 62 73 79 73 74 65 6d 2e 20 20 54 68 65 20 70 ubsystem. The p
01d0: 61 67 65 20 63 61 63 68 65 20 73 75 62 73 79 73 age cache subsys
01e0: 74 65 6d 20 72 65 61 64 73 20 61 6e 64 20 77 72 tem reads and wr
01f0: 69 74 65 73 20 61 20 66 69 6c 65 20 61 20 70 61 ites a file a pa
0200: 67 65 0a 2a 2a 20 61 74 20 61 20 74 69 6d 65 20 ge.** at a time
0210: 61 6e 64 20 70 72 6f 76 69 64 65 73 20 61 20 6a and provides a j
0220: 6f 75 72 6e 61 6c 20 66 6f 72 20 72 6f 6c 6c 62 ournal for rollb
0230: 61 63 6b 2e 0a 2a 2f 0a 0a 23 69 66 6e 64 65 66 ack..*/..#ifndef
0240: 20 53 51 4c 49 54 45 5f 50 41 47 45 52 5f 48 0a SQLITE_PAGER_H.
0250: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 50 #define SQLITE_P
0260: 41 47 45 52 5f 48 0a 0a 2f 2a 0a 2a 2a 20 44 65 AGER_H../*.** De
0270: 66 61 75 6c 74 20 6d 61 78 69 6d 75 6d 20 73 69 fault maximum si
0280: 7a 65 20 66 6f 72 20 70 65 72 73 69 73 74 65 6e ze for persisten
0290: 74 20 6a 6f 75 72 6e 61 6c 20 66 69 6c 65 73 2e t journal files.
02a0: 20 41 20 6e 65 67 61 74 69 76 65 20 0a 2a 2a 20 A negative .**
02b0: 76 61 6c 75 65 20 6d 65 61 6e 73 20 6e 6f 20 6c value means no l
02c0: 69 6d 69 74 2e 20 54 68 69 73 20 76 61 6c 75 65 imit. This value
02d0: 20 6d 61 79 20 62 65 20 6f 76 65 72 72 69 64 64 may be overridd
02e0: 65 6e 20 75 73 69 6e 67 20 74 68 65 20 0a 2a 2a en using the .**
02f0: 20 73 71 6c 69 74 65 33 50 61 67 65 72 4a 6f 75 sqlite3PagerJou
0300: 72 6e 61 6c 53 69 7a 65 4c 69 6d 69 74 28 29 20 rnalSizeLimit()
0310: 41 50 49 2e 20 53 65 65 20 61 6c 73 6f 20 22 50 API. See also "P
0320: 52 41 47 4d 41 20 6a 6f 75 72 6e 61 6c 5f 73 69 RAGMA journal_si
0330: 7a 65 5f 6c 69 6d 69 74 22 2e 0a 2a 2f 0a 23 69 ze_limit"..*/.#i
0340: 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 44 45 46 fndef SQLITE_DEF
0350: 41 55 4c 54 5f 4a 4f 55 52 4e 41 4c 5f 53 49 5a AULT_JOURNAL_SIZ
0360: 45 5f 4c 49 4d 49 54 0a 20 20 23 64 65 66 69 6e E_LIMIT. #defin
0370: 65 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 e SQLITE_DEFAULT
0380: 5f 4a 4f 55 52 4e 41 4c 5f 53 49 5a 45 5f 4c 49 _JOURNAL_SIZE_LI
0390: 4d 49 54 20 2d 31 0a 23 65 6e 64 69 66 0a 0a 2f MIT -1.#endif../
03a0: 2a 0a 2a 2a 20 54 68 65 20 74 79 70 65 20 75 73 *.** The type us
03b0: 65 64 20 74 6f 20 72 65 70 72 65 73 65 6e 74 20 ed to represent
03c0: 61 20 70 61 67 65 20 6e 75 6d 62 65 72 2e 20 20 a page number.
03d0: 54 68 65 20 66 69 72 73 74 20 70 61 67 65 20 69 The first page i
03e0: 6e 20 61 20 66 69 6c 65 0a 2a 2a 20 69 73 20 63 n a file.** is c
03f0: 61 6c 6c 65 64 20 70 61 67 65 20 31 2e 20 20 30 alled page 1. 0
0400: 20 69 73 20 75 73 65 64 20 74 6f 20 72 65 70 72 is used to repr
0410: 65 73 65 6e 74 20 22 6e 6f 74 20 61 20 70 61 67 esent "not a pag
0420: 65 22 2e 0a 2a 2f 0a 74 79 70 65 64 65 66 20 75 e"..*/.typedef u
0430: 33 32 20 50 67 6e 6f 3b 0a 0a 2f 2a 0a 2a 2a 20 32 Pgno;../*.**
0440: 45 61 63 68 20 6f 70 65 6e 20 66 69 6c 65 20 69 Each open file i
0450: 73 20 6d 61 6e 61 67 65 64 20 62 79 20 61 20 73 s managed by a s
0460: 65 70 61 72 61 74 65 20 69 6e 73 74 61 6e 63 65 eparate instance
0470: 20 6f 66 20 74 68 65 20 22 50 61 67 65 72 22 20 of the "Pager"
0480: 73 74 72 75 63 74 75 72 65 2e 0a 2a 2f 0a 74 79 structure..*/.ty
0490: 70 65 64 65 66 20 73 74 72 75 63 74 20 50 61 67 pedef struct Pag
04a0: 65 72 20 50 61 67 65 72 3b 0a 0a 2f 2a 0a 2a 2a er Pager;../*.**
04b0: 20 48 61 6e 64 6c 65 20 74 79 70 65 20 66 6f 72 Handle type for
04c0: 20 70 61 67 65 73 2e 0a 2a 2f 0a 74 79 70 65 64 pages..*/.typed
04d0: 65 66 20 73 74 72 75 63 74 20 50 67 48 64 72 20 ef struct PgHdr
04e0: 44 62 50 61 67 65 3b 0a 0a 2f 2a 0a 2a 2a 20 50 DbPage;../*.** P
04f0: 61 67 65 20 6e 75 6d 62 65 72 20 50 41 47 45 52 age number PAGER
0500: 5f 4d 4a 5f 50 47 4e 4f 20 69 73 20 6e 65 76 65 _MJ_PGNO is neve
0510: 72 20 75 73 65 64 20 69 6e 20 61 6e 20 53 51 4c r used in an SQL
0520: 69 74 65 20 64 61 74 61 62 61 73 65 20 28 69 74 ite database (it
0530: 20 69 73 0a 2a 2a 20 72 65 73 65 72 76 65 64 20 is.** reserved
0540: 66 6f 72 20 77 6f 72 6b 69 6e 67 20 61 72 6f 75 for working arou
0550: 6e 64 20 61 20 77 69 6e 64 6f 77 73 2f 70 6f 73 nd a windows/pos
0560: 69 78 20 69 6e 63 6f 6d 70 61 74 69 62 69 6c 69 ix incompatibili
0570: 74 79 29 2e 20 49 74 20 69 73 0a 2a 2a 20 75 73 ty). It is.** us
0580: 65 64 20 69 6e 20 74 68 65 20 6a 6f 75 72 6e 61 ed in the journa
0590: 6c 20 74 6f 20 73 69 67 6e 69 66 79 20 74 68 61 l to signify tha
05a0: 74 20 74 68 65 20 72 65 6d 61 69 6e 64 65 72 20 t the remainder
05b0: 6f 66 20 74 68 65 20 6a 6f 75 72 6e 61 6c 20 66 of the journal f
05c0: 69 6c 65 20 0a 2a 2a 20 69 73 20 64 65 76 6f 74 ile .** is devot
05d0: 65 64 20 74 6f 20 73 74 6f 72 69 6e 67 20 61 20 ed to storing a
05e0: 6d 61 73 74 65 72 20 6a 6f 75 72 6e 61 6c 20 6e master journal n
05f0: 61 6d 65 20 2d 20 74 68 65 72 65 20 61 72 65 20 ame - there are
0600: 6e 6f 20 6d 6f 72 65 20 70 61 67 65 73 20 74 6f no more pages to
0610: 0a 2a 2a 20 72 6f 6c 6c 20 62 61 63 6b 2e 20 53 .** roll back. S
0620: 65 65 20 63 6f 6d 6d 65 6e 74 73 20 66 6f 72 20 ee comments for
0630: 66 75 6e 63 74 69 6f 6e 20 77 72 69 74 65 4d 61 function writeMa
0640: 73 74 65 72 4a 6f 75 72 6e 61 6c 28 29 20 69 6e sterJournal() in
0650: 20 70 61 67 65 72 2e 63 20 0a 2a 2a 20 66 6f 72 pager.c .** for
0660: 20 64 65 74 61 69 6c 73 2e 0a 2a 2f 0a 23 64 65 details..*/.#de
0670: 66 69 6e 65 20 50 41 47 45 52 5f 4d 4a 5f 50 47 fine PAGER_MJ_PG
0680: 4e 4f 28 78 29 20 28 28 50 67 6e 6f 29 28 28 50 NO(x) ((Pgno)((P
0690: 45 4e 44 49 4e 47 5f 42 59 54 45 2f 28 28 78 29 ENDING_BYTE/((x)
06a0: 2d 3e 70 61 67 65 53 69 7a 65 29 29 2b 31 29 29 ->pageSize))+1))
06b0: 0a 0a 2f 2a 0a 2a 2a 20 41 6c 6c 6f 77 65 64 20 ../*.** Allowed
06c0: 76 61 6c 75 65 73 20 66 6f 72 20 74 68 65 20 66 values for the f
06d0: 6c 61 67 73 20 70 61 72 61 6d 65 74 65 72 20 74 lags parameter t
06e0: 6f 20 73 71 6c 69 74 65 33 50 61 67 65 72 4f 70 o sqlite3PagerOp
06f0: 65 6e 28 29 2e 0a 2a 2a 0a 2a 2a 20 4e 4f 54 45 en()..**.** NOTE
0700: 3a 20 54 68 65 73 65 20 76 61 6c 75 65 73 20 6d : These values m
0710: 75 73 74 20 6d 61 74 63 68 20 74 68 65 20 63 6f ust match the co
0720: 72 72 65 73 70 6f 6e 64 69 6e 67 20 42 54 52 45 rresponding BTRE
0730: 45 5f 20 76 61 6c 75 65 73 20 69 6e 20 62 74 72 E_ values in btr
0740: 65 65 2e 68 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 ee.h..*/.#define
0750: 20 50 41 47 45 52 5f 4f 4d 49 54 5f 4a 4f 55 52 PAGER_OMIT_JOUR
0760: 4e 41 4c 20 20 30 78 30 30 30 31 20 20 20 20 2f NAL 0x0001 /
0770: 2a 20 44 6f 20 6e 6f 74 20 75 73 65 20 61 20 72 * Do not use a r
0780: 6f 6c 6c 62 61 63 6b 20 6a 6f 75 72 6e 61 6c 20 ollback journal
0790: 2a 2f 0a 23 64 65 66 69 6e 65 20 50 41 47 45 52 */.#define PAGER
07a0: 5f 4d 45 4d 4f 52 59 20 20 20 20 20 20 20 20 30 _MEMORY 0
07b0: 78 30 30 30 32 20 20 20 20 2f 2a 20 49 6e 2d 6d x0002 /* In-m
07c0: 65 6d 6f 72 79 20 64 61 74 61 62 61 73 65 20 2a emory database *
07d0: 2f 0a 0a 2f 2a 0a 2a 2a 20 56 61 6c 69 64 20 76 /../*.** Valid v
07e0: 61 6c 75 65 73 20 66 6f 72 20 74 68 65 20 73 65 alues for the se
07f0: 63 6f 6e 64 20 61 72 67 75 6d 65 6e 74 20 74 6f cond argument to
0800: 20 73 71 6c 69 74 65 33 50 61 67 65 72 4c 6f 63 sqlite3PagerLoc
0810: 6b 69 6e 67 4d 6f 64 65 28 29 2e 0a 2a 2f 0a 23 kingMode()..*/.#
0820: 64 65 66 69 6e 65 20 50 41 47 45 52 5f 4c 4f 43 define PAGER_LOC
0830: 4b 49 4e 47 4d 4f 44 45 5f 51 55 45 52 59 20 20 KINGMODE_QUERY
0840: 20 20 20 20 2d 31 0a 23 64 65 66 69 6e 65 20 50 -1.#define P
0850: 41 47 45 52 5f 4c 4f 43 4b 49 4e 47 4d 4f 44 45 AGER_LOCKINGMODE
0860: 5f 4e 4f 52 4d 41 4c 20 20 20 20 20 20 30 0a 23 _NORMAL 0.#
0870: 64 65 66 69 6e 65 20 50 41 47 45 52 5f 4c 4f 43 define PAGER_LOC
0880: 4b 49 4e 47 4d 4f 44 45 5f 45 58 43 4c 55 53 49 KINGMODE_EXCLUSI
0890: 56 45 20 20 20 31 0a 0a 2f 2a 0a 2a 2a 20 4e 75 VE 1../*.** Nu
08a0: 6d 65 72 69 63 20 63 6f 6e 73 74 61 6e 74 73 20 meric constants
08b0: 74 68 61 74 20 65 6e 63 6f 64 65 20 74 68 65 20 that encode the
08c0: 6a 6f 75 72 6e 61 6c 6d 6f 64 65 2e 0a 2a 2a 0a journalmode..**.
08d0: 2a 2a 20 54 68 65 20 6e 75 6d 65 72 69 63 20 76 ** The numeric v
08e0: 61 6c 75 65 73 20 65 6e 63 6f 64 65 64 20 68 65 alues encoded he
08f0: 72 65 20 28 6f 74 68 65 72 20 74 68 61 6e 20 50 re (other than P
0900: 41 47 45 52 5f 4a 4f 55 52 4e 41 4c 4d 4f 44 45 AGER_JOURNALMODE
0910: 5f 51 55 45 52 59 29 0a 2a 2a 20 61 72 65 20 65 _QUERY).** are e
0920: 78 70 6f 73 65 64 20 69 6e 20 74 68 65 20 41 50 xposed in the AP
0930: 49 20 76 69 61 20 74 68 65 20 22 50 52 41 47 4d I via the "PRAGM
0940: 41 20 6a 6f 75 72 6e 61 6c 5f 6d 6f 64 65 22 20 A journal_mode"
0950: 63 6f 6d 6d 61 6e 64 20 61 6e 64 0a 2a 2a 20 74 command and.** t
0960: 68 65 72 65 66 6f 72 65 20 63 61 6e 6e 6f 74 20 herefore cannot
0970: 62 65 20 63 68 61 6e 67 65 64 20 77 69 74 68 6f be changed witho
0980: 75 74 20 61 20 63 6f 6d 70 61 74 69 62 69 6c 69 ut a compatibili
0990: 74 79 20 62 72 65 61 6b 2e 0a 2a 2f 0a 23 64 65 ty break..*/.#de
09a0: 66 69 6e 65 20 50 41 47 45 52 5f 4a 4f 55 52 4e fine PAGER_JOURN
09b0: 41 4c 4d 4f 44 45 5f 51 55 45 52 59 20 20 20 20 ALMODE_QUERY
09c0: 20 28 2d 31 29 20 20 2f 2a 20 51 75 65 72 79 20 (-1) /* Query
09d0: 74 68 65 20 76 61 6c 75 65 20 6f 66 20 6a 6f 75 the value of jou
09e0: 72 6e 61 6c 6d 6f 64 65 20 2a 2f 0a 23 64 65 66 rnalmode */.#def
09f0: 69 6e 65 20 50 41 47 45 52 5f 4a 4f 55 52 4e 41 ine PAGER_JOURNA
0a00: 4c 4d 4f 44 45 5f 44 45 4c 45 54 45 20 20 20 20 LMODE_DELETE
0a10: 20 20 30 20 20 20 2f 2a 20 43 6f 6d 6d 69 74 20 0 /* Commit
0a20: 62 79 20 64 65 6c 65 74 69 6e 67 20 6a 6f 75 72 by deleting jour
0a30: 6e 61 6c 20 66 69 6c 65 20 2a 2f 0a 23 64 65 66 nal file */.#def
0a40: 69 6e 65 20 50 41 47 45 52 5f 4a 4f 55 52 4e 41 ine PAGER_JOURNA
0a50: 4c 4d 4f 44 45 5f 50 45 52 53 49 53 54 20 20 20 LMODE_PERSIST
0a60: 20 20 31 20 20 20 2f 2a 20 43 6f 6d 6d 69 74 20 1 /* Commit
0a70: 62 79 20 7a 65 72 6f 69 6e 67 20 6a 6f 75 72 6e by zeroing journ
0a80: 61 6c 20 68 65 61 64 65 72 20 2a 2f 0a 23 64 65 al header */.#de
0a90: 66 69 6e 65 20 50 41 47 45 52 5f 4a 4f 55 52 4e fine PAGER_JOURN
0aa0: 41 4c 4d 4f 44 45 5f 4f 46 46 20 20 20 20 20 20 ALMODE_OFF
0ab0: 20 20 20 32 20 20 20 2f 2a 20 4a 6f 75 72 6e 61 2 /* Journa
0ac0: 6c 20 6f 6d 69 74 74 65 64 2e 20 20 2a 2f 0a 23 l omitted. */.#
0ad0: 64 65 66 69 6e 65 20 50 41 47 45 52 5f 4a 4f 55 define PAGER_JOU
0ae0: 52 4e 41 4c 4d 4f 44 45 5f 54 52 55 4e 43 41 54 RNALMODE_TRUNCAT
0af0: 45 20 20 20 20 33 20 20 20 2f 2a 20 43 6f 6d 6d E 3 /* Comm
0b00: 69 74 20 62 79 20 74 72 75 6e 63 61 74 69 6e 67 it by truncating
0b10: 20 6a 6f 75 72 6e 61 6c 20 2a 2f 0a 23 64 65 66 journal */.#def
0b20: 69 6e 65 20 50 41 47 45 52 5f 4a 4f 55 52 4e 41 ine PAGER_JOURNA
0b30: 4c 4d 4f 44 45 5f 4d 45 4d 4f 52 59 20 20 20 20 LMODE_MEMORY
0b40: 20 20 34 20 20 20 2f 2a 20 49 6e 2d 6d 65 6d 6f 4 /* In-memo
0b50: 72 79 20 6a 6f 75 72 6e 61 6c 20 66 69 6c 65 20 ry journal file
0b60: 2a 2f 0a 23 64 65 66 69 6e 65 20 50 41 47 45 52 */.#define PAGER
0b70: 5f 4a 4f 55 52 4e 41 4c 4d 4f 44 45 5f 57 41 4c _JOURNALMODE_WAL
0b80: 20 20 20 20 20 20 20 20 20 35 20 20 20 2f 2a 20 5 /*
0b90: 55 73 65 20 77 72 69 74 65 2d 61 68 65 61 64 20 Use write-ahead
0ba0: 6c 6f 67 67 69 6e 67 20 2a 2f 0a 0a 2f 2a 0a 2a logging */../*.*
0bb0: 2a 20 46 6c 61 67 73 20 74 68 61 74 20 6d 61 6b * Flags that mak
0bc0: 65 20 75 70 20 74 68 65 20 6d 61 73 6b 20 70 61 e up the mask pa
0bd0: 73 73 65 64 20 74 6f 20 73 71 6c 69 74 65 33 50 ssed to sqlite3P
0be0: 61 67 65 72 47 65 74 28 29 2e 0a 2a 2f 0a 23 64 agerGet()..*/.#d
0bf0: 65 66 69 6e 65 20 50 41 47 45 52 5f 47 45 54 5f efine PAGER_GET_
0c00: 4e 4f 43 4f 4e 54 45 4e 54 20 20 20 20 20 30 78 NOCONTENT 0x
0c10: 30 31 20 20 2f 2a 20 44 6f 20 6e 6f 74 20 6c 6f 01 /* Do not lo
0c20: 61 64 20 64 61 74 61 20 66 72 6f 6d 20 64 69 73 ad data from dis
0c30: 6b 20 2a 2f 0a 23 64 65 66 69 6e 65 20 50 41 47 k */.#define PAG
0c40: 45 52 5f 47 45 54 5f 52 45 41 44 4f 4e 4c 59 20 ER_GET_READONLY
0c50: 20 20 20 20 20 30 78 30 32 20 20 2f 2a 20 52 65 0x02 /* Re
0c60: 61 64 2d 6f 6e 6c 79 20 70 61 67 65 20 69 73 20 ad-only page is
0c70: 61 63 63 65 70 74 61 62 6c 65 20 2a 2f 0a 0a 2f acceptable */../
0c80: 2a 0a 2a 2a 20 46 6c 61 67 73 20 66 6f 72 20 73 *.** Flags for s
0c90: 71 6c 69 74 65 33 50 61 67 65 72 53 65 74 46 6c qlite3PagerSetFl
0ca0: 61 67 73 28 29 0a 2a 2a 0a 2a 2a 20 56 61 6c 75 ags().**.** Valu
0cb0: 65 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 28 65 e constraints (e
0cc0: 6e 66 6f 72 63 65 64 20 76 69 61 20 61 73 73 65 nforced via asse
0cd0: 72 74 28 29 29 3a 0a 2a 2a 20 20 20 20 50 41 47 rt()):.** PAG
0ce0: 45 52 5f 46 55 4c 4c 46 53 59 4e 43 20 20 20 20 ER_FULLFSYNC
0cf0: 20 20 3d 3d 20 53 51 4c 49 54 45 5f 46 75 6c 6c == SQLITE_Full
0d00: 46 53 79 6e 63 0a 2a 2a 20 20 20 20 50 41 47 45 FSync.** PAGE
0d10: 52 5f 43 4b 50 54 5f 46 55 4c 4c 46 53 59 4e 43 R_CKPT_FULLFSYNC
0d20: 20 3d 3d 20 53 51 4c 49 54 45 5f 43 6b 70 74 46 == SQLITE_CkptF
0d30: 75 6c 6c 46 53 79 6e 63 0a 2a 2a 20 20 20 20 50 ullFSync.** P
0d40: 41 47 45 52 5f 43 41 43 48 45 5f 53 50 49 4c 4c AGER_CACHE_SPILL
0d50: 20 20 20 20 3d 3d 20 53 51 4c 49 54 45 5f 43 61 == SQLITE_Ca
0d60: 63 68 65 53 70 69 6c 6c 0a 2a 2f 0a 23 64 65 66 cheSpill.*/.#def
0d70: 69 6e 65 20 50 41 47 45 52 5f 53 59 4e 43 48 52 ine PAGER_SYNCHR
0d80: 4f 4e 4f 55 53 5f 4f 46 46 20 20 20 20 20 20 20 ONOUS_OFF
0d90: 30 78 30 31 20 20 2f 2a 20 50 52 41 47 4d 41 20 0x01 /* PRAGMA
0da0: 73 79 6e 63 68 72 6f 6e 6f 75 73 3d 4f 46 46 20 synchronous=OFF
0db0: 2a 2f 0a 23 64 65 66 69 6e 65 20 50 41 47 45 52 */.#define PAGER
0dc0: 5f 53 59 4e 43 48 52 4f 4e 4f 55 53 5f 4e 4f 52 _SYNCHRONOUS_NOR
0dd0: 4d 41 4c 20 20 20 20 30 78 30 32 20 20 2f 2a 20 MAL 0x02 /*
0de0: 50 52 41 47 4d 41 20 73 79 6e 63 68 72 6f 6e 6f PRAGMA synchrono
0df0: 75 73 3d 4e 4f 52 4d 41 4c 20 2a 2f 0a 23 64 65 us=NORMAL */.#de
0e00: 66 69 6e 65 20 50 41 47 45 52 5f 53 59 4e 43 48 fine PAGER_SYNCH
0e10: 52 4f 4e 4f 55 53 5f 46 55 4c 4c 20 20 20 20 20 RONOUS_FULL
0e20: 20 30 78 30 33 20 20 2f 2a 20 50 52 41 47 4d 41 0x03 /* PRAGMA
0e30: 20 73 79 6e 63 68 72 6f 6e 6f 75 73 3d 46 55 4c synchronous=FUL
0e40: 4c 20 2a 2f 0a 23 64 65 66 69 6e 65 20 50 41 47 L */.#define PAG
0e50: 45 52 5f 53 59 4e 43 48 52 4f 4e 4f 55 53 5f 45 ER_SYNCHRONOUS_E
0e60: 58 54 52 41 20 20 20 20 20 30 78 30 34 20 20 2f XTRA 0x04 /
0e70: 2a 20 50 52 41 47 4d 41 20 73 79 6e 63 68 72 6f * PRAGMA synchro
0e80: 6e 6f 75 73 3d 45 58 54 52 41 20 2a 2f 0a 23 64 nous=EXTRA */.#d
0e90: 65 66 69 6e 65 20 50 41 47 45 52 5f 53 59 4e 43 efine PAGER_SYNC
0ea0: 48 52 4f 4e 4f 55 53 5f 4d 41 53 4b 20 20 20 20 HRONOUS_MASK
0eb0: 20 20 30 78 30 37 20 20 2f 2a 20 4d 61 73 6b 20 0x07 /* Mask
0ec0: 66 6f 72 20 66 6f 75 72 20 76 61 6c 75 65 73 20 for four values
0ed0: 61 62 6f 76 65 20 2a 2f 0a 23 64 65 66 69 6e 65 above */.#define
0ee0: 20 50 41 47 45 52 5f 46 55 4c 4c 46 53 59 4e 43 PAGER_FULLFSYNC
0ef0: 20 20 20 20 20 20 20 20 20 20 20 20 20 30 78 30 0x0
0f00: 38 20 20 2f 2a 20 50 52 41 47 4d 41 20 66 75 6c 8 /* PRAGMA ful
0f10: 6c 66 73 79 6e 63 3d 4f 4e 20 2a 2f 0a 23 64 65 lfsync=ON */.#de
0f20: 66 69 6e 65 20 50 41 47 45 52 5f 43 4b 50 54 5f fine PAGER_CKPT_
0f30: 46 55 4c 4c 46 53 59 4e 43 20 20 20 20 20 20 20 FULLFSYNC
0f40: 20 30 78 31 30 20 20 2f 2a 20 50 52 41 47 4d 41 0x10 /* PRAGMA
0f50: 20 63 68 65 63 6b 70 6f 69 6e 74 5f 66 75 6c 6c checkpoint_full
0f60: 66 73 79 6e 63 3d 4f 4e 20 2a 2f 0a 23 64 65 66 fsync=ON */.#def
0f70: 69 6e 65 20 50 41 47 45 52 5f 43 41 43 48 45 53 ine PAGER_CACHES
0f80: 50 49 4c 4c 20 20 20 20 20 20 20 20 20 20 20 20 PILL
0f90: 30 78 32 30 20 20 2f 2a 20 50 52 41 47 4d 41 20 0x20 /* PRAGMA
0fa0: 63 61 63 68 65 5f 73 70 69 6c 6c 3d 4f 4e 20 2a cache_spill=ON *
0fb0: 2f 0a 23 64 65 66 69 6e 65 20 50 41 47 45 52 5f /.#define PAGER_
0fc0: 46 4c 41 47 53 5f 4d 41 53 4b 20 20 20 20 20 20 FLAGS_MASK
0fd0: 20 20 20 20 20 20 30 78 33 38 20 20 2f 2a 20 41 0x38 /* A
0fe0: 6c 6c 20 61 62 6f 76 65 20 65 78 63 65 70 74 20 ll above except
0ff0: 53 59 4e 43 48 52 4f 4e 4f 55 53 20 2a 2f 0a 0a SYNCHRONOUS */..
1000: 2f 2a 0a 2a 2a 20 54 68 65 20 72 65 6d 61 69 6e /*.** The remain
1010: 64 65 72 20 6f 66 20 74 68 69 73 20 66 69 6c 65 der of this file
1020: 20 63 6f 6e 74 61 69 6e 73 20 74 68 65 20 64 65 contains the de
1030: 63 6c 61 72 61 74 69 6f 6e 73 20 6f 66 20 74 68 clarations of th
1040: 65 20 66 75 6e 63 74 69 6f 6e 73 0a 2a 2a 20 74 e functions.** t
1050: 68 61 74 20 6d 61 6b 65 20 75 70 20 74 68 65 20 hat make up the
1060: 50 61 67 65 72 20 73 75 62 2d 73 79 73 74 65 6d Pager sub-system
1070: 20 41 50 49 2e 20 53 65 65 20 73 6f 75 72 63 65 API. See source
1080: 20 63 6f 64 65 20 63 6f 6d 6d 65 6e 74 73 20 66 code comments f
1090: 6f 72 20 0a 2a 2a 20 61 20 64 65 74 61 69 6c 65 or .** a detaile
10a0: 64 20 64 65 73 63 72 69 70 74 69 6f 6e 20 6f 66 d description of
10b0: 20 65 61 63 68 20 72 6f 75 74 69 6e 65 2e 0a 2a each routine..*
10c0: 2f 0a 0a 2f 2a 20 4f 70 65 6e 20 61 6e 64 20 63 /../* Open and c
10d0: 6c 6f 73 65 20 61 20 50 61 67 65 72 20 63 6f 6e lose a Pager con
10e0: 6e 65 63 74 69 6f 6e 2e 20 2a 2f 20 0a 69 6e 74 nection. */ .int
10f0: 20 73 71 6c 69 74 65 33 50 61 67 65 72 4f 70 65 sqlite3PagerOpe
1100: 6e 28 0a 20 20 73 71 6c 69 74 65 33 5f 76 66 73 n(. sqlite3_vfs
1110: 2a 2c 0a 20 20 50 61 67 65 72 20 2a 2a 70 70 50 *,. Pager **ppP
1120: 61 67 65 72 2c 0a 20 20 63 6f 6e 73 74 20 63 68 ager,. const ch
1130: 61 72 2a 2c 0a 20 20 69 6e 74 2c 0a 20 20 69 6e ar*,. int,. in
1140: 74 2c 0a 20 20 69 6e 74 2c 0a 20 20 76 6f 69 64 t,. int,. void
1150: 28 2a 29 28 44 62 50 61 67 65 2a 29 0a 29 3b 0a (*)(DbPage*).);.
1160: 69 6e 74 20 73 71 6c 69 74 65 33 50 61 67 65 72 int sqlite3Pager
1170: 43 6c 6f 73 65 28 50 61 67 65 72 20 2a 70 50 61 Close(Pager *pPa
1180: 67 65 72 2c 20 73 71 6c 69 74 65 33 2a 29 3b 0a ger, sqlite3*);.
1190: 69 6e 74 20 73 71 6c 69 74 65 33 50 61 67 65 72 int sqlite3Pager
11a0: 52 65 61 64 46 69 6c 65 68 65 61 64 65 72 28 50 ReadFileheader(P
11b0: 61 67 65 72 2a 2c 20 69 6e 74 2c 20 75 6e 73 69 ager*, int, unsi
11c0: 67 6e 65 64 20 63 68 61 72 2a 29 3b 0a 0a 2f 2a gned char*);../*
11d0: 20 46 75 6e 63 74 69 6f 6e 73 20 75 73 65 64 20 Functions used
11e0: 74 6f 20 63 6f 6e 66 69 67 75 72 65 20 61 20 50 to configure a P
11f0: 61 67 65 72 20 6f 62 6a 65 63 74 2e 20 2a 2f 0a ager object. */.
1200: 76 6f 69 64 20 73 71 6c 69 74 65 33 50 61 67 65 void sqlite3Page
1210: 72 53 65 74 42 75 73 79 48 61 6e 64 6c 65 72 28 rSetBusyHandler(
1220: 50 61 67 65 72 2a 2c 20 69 6e 74 28 2a 29 28 76 Pager*, int(*)(v
1230: 6f 69 64 20 2a 29 2c 20 76 6f 69 64 20 2a 29 3b oid *), void *);
1240: 0a 69 6e 74 20 73 71 6c 69 74 65 33 50 61 67 65 .int sqlite3Page
1250: 72 53 65 74 50 61 67 65 73 69 7a 65 28 50 61 67 rSetPagesize(Pag
1260: 65 72 2a 2c 20 75 33 32 2a 2c 20 69 6e 74 29 3b er*, u32*, int);
1270: 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 48 .#ifdef SQLITE_H
1280: 41 53 5f 43 4f 44 45 43 0a 76 6f 69 64 20 73 71 AS_CODEC.void sq
1290: 6c 69 74 65 33 50 61 67 65 72 41 6c 69 67 6e 52 lite3PagerAlignR
12a0: 65 73 65 72 76 65 28 50 61 67 65 72 2a 2c 50 61 eserve(Pager*,Pa
12b0: 67 65 72 2a 29 3b 0a 23 65 6e 64 69 66 0a 69 6e ger*);.#endif.in
12c0: 74 20 73 71 6c 69 74 65 33 50 61 67 65 72 4d 61 t sqlite3PagerMa
12d0: 78 50 61 67 65 43 6f 75 6e 74 28 50 61 67 65 72 xPageCount(Pager
12e0: 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 *, int);.void sq
12f0: 6c 69 74 65 33 50 61 67 65 72 53 65 74 43 61 63 lite3PagerSetCac
1300: 68 65 73 69 7a 65 28 50 61 67 65 72 2a 2c 20 69 hesize(Pager*, i
1310: 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 nt);.int sqlite3
1320: 50 61 67 65 72 53 65 74 53 70 69 6c 6c 73 69 7a PagerSetSpillsiz
1330: 65 28 50 61 67 65 72 2a 2c 20 69 6e 74 29 3b 0a e(Pager*, int);.
1340: 76 6f 69 64 20 73 71 6c 69 74 65 33 50 61 67 65 void sqlite3Page
1350: 72 53 65 74 4d 6d 61 70 4c 69 6d 69 74 28 50 61 rSetMmapLimit(Pa
1360: 67 65 72 20 2a 2c 20 73 71 6c 69 74 65 33 5f 69 ger *, sqlite3_i
1370: 6e 74 36 34 29 3b 0a 76 6f 69 64 20 73 71 6c 69 nt64);.void sqli
1380: 74 65 33 50 61 67 65 72 53 68 72 69 6e 6b 28 50 te3PagerShrink(P
1390: 61 67 65 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c ager*);.void sql
13a0: 69 74 65 33 50 61 67 65 72 53 65 74 46 6c 61 67 ite3PagerSetFlag
13b0: 73 28 50 61 67 65 72 2a 2c 75 6e 73 69 67 6e 65 s(Pager*,unsigne
13c0: 64 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 50 d);.int sqlite3P
13d0: 61 67 65 72 4c 6f 63 6b 69 6e 67 4d 6f 64 65 28 agerLockingMode(
13e0: 50 61 67 65 72 20 2a 2c 20 69 6e 74 29 3b 0a 69 Pager *, int);.i
13f0: 6e 74 20 73 71 6c 69 74 65 33 50 61 67 65 72 53 nt sqlite3PagerS
1400: 65 74 4a 6f 75 72 6e 61 6c 4d 6f 64 65 28 50 61 etJournalMode(Pa
1410: 67 65 72 20 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 ger *, int);.int
1420: 20 73 71 6c 69 74 65 33 50 61 67 65 72 47 65 74 sqlite3PagerGet
1430: 4a 6f 75 72 6e 61 6c 4d 6f 64 65 28 50 61 67 65 JournalMode(Page
1440: 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 r*);.int sqlite3
1450: 50 61 67 65 72 4f 6b 54 6f 43 68 61 6e 67 65 4a PagerOkToChangeJ
1460: 6f 75 72 6e 61 6c 4d 6f 64 65 28 50 61 67 65 72 ournalMode(Pager
1470: 2a 29 3b 0a 69 36 34 20 73 71 6c 69 74 65 33 50 *);.i64 sqlite3P
1480: 61 67 65 72 4a 6f 75 72 6e 61 6c 53 69 7a 65 4c agerJournalSizeL
1490: 69 6d 69 74 28 50 61 67 65 72 20 2a 2c 20 69 36 imit(Pager *, i6
14a0: 34 29 3b 0a 73 71 6c 69 74 65 33 5f 62 61 63 6b 4);.sqlite3_back
14b0: 75 70 20 2a 2a 73 71 6c 69 74 65 33 50 61 67 65 up **sqlite3Page
14c0: 72 42 61 63 6b 75 70 50 74 72 28 50 61 67 65 72 rBackupPtr(Pager
14d0: 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 50 *);.int sqlite3P
14e0: 61 67 65 72 46 6c 75 73 68 28 50 61 67 65 72 2a agerFlush(Pager*
14f0: 29 3b 0a 0a 2f 2a 20 46 75 6e 63 74 69 6f 6e 73 );../* Functions
1500: 20 75 73 65 64 20 74 6f 20 6f 62 74 61 69 6e 20 used to obtain
1510: 61 6e 64 20 72 65 6c 65 61 73 65 20 70 61 67 65 and release page
1520: 20 72 65 66 65 72 65 6e 63 65 73 2e 20 2a 2f 20 references. */
1530: 0a 69 6e 74 20 73 71 6c 69 74 65 33 50 61 67 65 .int sqlite3Page
1540: 72 47 65 74 28 50 61 67 65 72 20 2a 70 50 61 67 rGet(Pager *pPag
1550: 65 72 2c 20 50 67 6e 6f 20 70 67 6e 6f 2c 20 44 er, Pgno pgno, D
1560: 62 50 61 67 65 20 2a 2a 70 70 50 61 67 65 2c 20 bPage **ppPage,
1570: 69 6e 74 20 63 6c 72 46 6c 61 67 29 3b 0a 44 62 int clrFlag);.Db
1580: 50 61 67 65 20 2a 73 71 6c 69 74 65 33 50 61 67 Page *sqlite3Pag
1590: 65 72 4c 6f 6f 6b 75 70 28 50 61 67 65 72 20 2a erLookup(Pager *
15a0: 70 50 61 67 65 72 2c 20 50 67 6e 6f 20 70 67 6e pPager, Pgno pgn
15b0: 6f 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 o);.void sqlite3
15c0: 50 61 67 65 72 52 65 66 28 44 62 50 61 67 65 2a PagerRef(DbPage*
15d0: 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 50 );.void sqlite3P
15e0: 61 67 65 72 55 6e 72 65 66 28 44 62 50 61 67 65 agerUnref(DbPage
15f0: 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
1600: 50 61 67 65 72 55 6e 72 65 66 4e 6f 74 4e 75 6c PagerUnrefNotNul
1610: 6c 28 44 62 50 61 67 65 2a 29 3b 0a 76 6f 69 64 l(DbPage*);.void
1620: 20 73 71 6c 69 74 65 33 50 61 67 65 72 55 6e 72 sqlite3PagerUnr
1630: 65 66 50 61 67 65 4f 6e 65 28 44 62 50 61 67 65 efPageOne(DbPage
1640: 2a 29 3b 0a 0a 2f 2a 20 4f 70 65 72 61 74 69 6f *);../* Operatio
1650: 6e 73 20 6f 6e 20 70 61 67 65 20 72 65 66 65 72 ns on page refer
1660: 65 6e 63 65 73 2e 20 2a 2f 0a 69 6e 74 20 73 71 ences. */.int sq
1670: 6c 69 74 65 33 50 61 67 65 72 57 72 69 74 65 28 lite3PagerWrite(
1680: 44 62 50 61 67 65 2a 29 3b 0a 76 6f 69 64 20 73 DbPage*);.void s
1690: 71 6c 69 74 65 33 50 61 67 65 72 44 6f 6e 74 57 qlite3PagerDontW
16a0: 72 69 74 65 28 44 62 50 61 67 65 2a 29 3b 0a 69 rite(DbPage*);.i
16b0: 6e 74 20 73 71 6c 69 74 65 33 50 61 67 65 72 4d nt sqlite3PagerM
16c0: 6f 76 65 70 61 67 65 28 50 61 67 65 72 2a 2c 44 ovepage(Pager*,D
16d0: 62 50 61 67 65 2a 2c 50 67 6e 6f 2c 69 6e 74 29 bPage*,Pgno,int)
16e0: 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 50 61 67 ;.int sqlite3Pag
16f0: 65 72 50 61 67 65 52 65 66 63 6f 75 6e 74 28 44 erPageRefcount(D
1700: 62 50 61 67 65 2a 29 3b 0a 76 6f 69 64 20 2a 73 bPage*);.void *s
1710: 71 6c 69 74 65 33 50 61 67 65 72 47 65 74 44 61 qlite3PagerGetDa
1720: 74 61 28 44 62 50 61 67 65 20 2a 29 3b 20 0a 76 ta(DbPage *); .v
1730: 6f 69 64 20 2a 73 71 6c 69 74 65 33 50 61 67 65 oid *sqlite3Page
1740: 72 47 65 74 45 78 74 72 61 28 44 62 50 61 67 65 rGetExtra(DbPage
1750: 20 2a 29 3b 20 0a 0a 2f 2a 20 46 75 6e 63 74 69 *); ../* Functi
1760: 6f 6e 73 20 75 73 65 64 20 74 6f 20 6d 61 6e 61 ons used to mana
1770: 67 65 20 70 61 67 65 72 20 74 72 61 6e 73 61 63 ge pager transac
1780: 74 69 6f 6e 73 20 61 6e 64 20 73 61 76 65 70 6f tions and savepo
1790: 69 6e 74 73 2e 20 2a 2f 0a 76 6f 69 64 20 73 71 ints. */.void sq
17a0: 6c 69 74 65 33 50 61 67 65 72 50 61 67 65 63 6f lite3PagerPageco
17b0: 75 6e 74 28 50 61 67 65 72 2a 2c 20 69 6e 74 2a unt(Pager*, int*
17c0: 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 50 61 );.int sqlite3Pa
17d0: 67 65 72 42 65 67 69 6e 28 50 61 67 65 72 2a 2c gerBegin(Pager*,
17e0: 20 69 6e 74 20 65 78 46 6c 61 67 2c 20 69 6e 74 int exFlag, int
17f0: 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 50 61 );.int sqlite3Pa
1800: 67 65 72 43 6f 6d 6d 69 74 50 68 61 73 65 4f 6e gerCommitPhaseOn
1810: 65 28 50 61 67 65 72 2a 2c 63 6f 6e 73 74 20 63 e(Pager*,const c
1820: 68 61 72 20 2a 7a 4d 61 73 74 65 72 2c 20 69 6e har *zMaster, in
1830: 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 50 t);.int sqlite3P
1840: 61 67 65 72 45 78 63 6c 75 73 69 76 65 4c 6f 63 agerExclusiveLoc
1850: 6b 28 50 61 67 65 72 2a 29 3b 0a 69 6e 74 20 73 k(Pager*);.int s
1860: 71 6c 69 74 65 33 50 61 67 65 72 53 79 6e 63 28 qlite3PagerSync(
1870: 50 61 67 65 72 20 2a 70 50 61 67 65 72 2c 20 63 Pager *pPager, c
1880: 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4d 61 73 74 onst char *zMast
1890: 65 72 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 er);.int sqlite3
18a0: 50 61 67 65 72 43 6f 6d 6d 69 74 50 68 61 73 65 PagerCommitPhase
18b0: 54 77 6f 28 50 61 67 65 72 2a 29 3b 0a 69 6e 74 Two(Pager*);.int
18c0: 20 73 71 6c 69 74 65 33 50 61 67 65 72 52 6f 6c sqlite3PagerRol
18d0: 6c 62 61 63 6b 28 50 61 67 65 72 2a 29 3b 0a 69 lback(Pager*);.i
18e0: 6e 74 20 73 71 6c 69 74 65 33 50 61 67 65 72 4f nt sqlite3PagerO
18f0: 70 65 6e 53 61 76 65 70 6f 69 6e 74 28 50 61 67 penSavepoint(Pag
1900: 65 72 20 2a 70 50 61 67 65 72 2c 20 69 6e 74 20 er *pPager, int
1910: 6e 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 50 n);.int sqlite3P
1920: 61 67 65 72 53 61 76 65 70 6f 69 6e 74 28 50 61 agerSavepoint(Pa
1930: 67 65 72 20 2a 70 50 61 67 65 72 2c 20 69 6e 74 ger *pPager, int
1940: 20 6f 70 2c 20 69 6e 74 20 69 53 61 76 65 70 6f op, int iSavepo
1950: 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 int);.int sqlite
1960: 33 50 61 67 65 72 53 68 61 72 65 64 4c 6f 63 6b 3PagerSharedLock
1970: 28 50 61 67 65 72 20 2a 70 50 61 67 65 72 29 3b (Pager *pPager);
1980: 0a 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 ..#ifndef SQLITE
1990: 5f 4f 4d 49 54 5f 57 41 4c 0a 20 20 69 6e 74 20 _OMIT_WAL. int
19a0: 73 71 6c 69 74 65 33 50 61 67 65 72 43 68 65 63 sqlite3PagerChec
19b0: 6b 70 6f 69 6e 74 28 50 61 67 65 72 20 2a 70 50 kpoint(Pager *pP
19c0: 61 67 65 72 2c 20 73 71 6c 69 74 65 33 2a 2c 20 ager, sqlite3*,
19d0: 69 6e 74 2c 20 69 6e 74 2a 2c 20 69 6e 74 2a 29 int, int*, int*)
19e0: 3b 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 50 ;. int sqlite3P
19f0: 61 67 65 72 57 61 6c 53 75 70 70 6f 72 74 65 64 agerWalSupported
1a00: 28 50 61 67 65 72 20 2a 70 50 61 67 65 72 29 3b (Pager *pPager);
1a10: 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 50 61 . int sqlite3Pa
1a20: 67 65 72 57 61 6c 43 61 6c 6c 62 61 63 6b 28 50 gerWalCallback(P
1a30: 61 67 65 72 20 2a 70 50 61 67 65 72 29 3b 0a 20 ager *pPager);.
1a40: 20 69 6e 74 20 73 71 6c 69 74 65 33 50 61 67 65 int sqlite3Page
1a50: 72 4f 70 65 6e 57 61 6c 28 50 61 67 65 72 20 2a rOpenWal(Pager *
1a60: 70 50 61 67 65 72 2c 20 69 6e 74 20 2a 70 69 73 pPager, int *pis
1a70: 4f 70 65 6e 29 3b 0a 20 20 69 6e 74 20 73 71 6c Open);. int sql
1a80: 69 74 65 33 50 61 67 65 72 43 6c 6f 73 65 57 61 ite3PagerCloseWa
1a90: 6c 28 50 61 67 65 72 20 2a 70 50 61 67 65 72 2c l(Pager *pPager,
1aa0: 20 73 71 6c 69 74 65 33 2a 29 3b 0a 23 20 69 66 sqlite3*);.# if
1ab0: 64 65 66 20 53 51 4c 49 54 45 5f 44 49 52 45 43 def SQLITE_DIREC
1ac0: 54 5f 4f 56 45 52 46 4c 4f 57 5f 52 45 41 44 0a T_OVERFLOW_READ.
1ad0: 20 20 69 6e 74 20 73 71 6c 69 74 65 33 50 61 67 int sqlite3Pag
1ae0: 65 72 55 73 65 57 61 6c 28 50 61 67 65 72 20 2a erUseWal(Pager *
1af0: 70 50 61 67 65 72 2c 20 50 67 6e 6f 29 3b 0a 23 pPager, Pgno);.#
1b00: 20 65 6e 64 69 66 0a 23 20 69 66 64 65 66 20 53 endif.# ifdef S
1b10: 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 4e 41 QLITE_ENABLE_SNA
1b20: 50 53 48 4f 54 0a 20 20 69 6e 74 20 73 71 6c 69 PSHOT. int sqli
1b30: 74 65 33 50 61 67 65 72 53 6e 61 70 73 68 6f 74 te3PagerSnapshot
1b40: 47 65 74 28 50 61 67 65 72 20 2a 70 50 61 67 65 Get(Pager *pPage
1b50: 72 2c 20 73 71 6c 69 74 65 33 5f 73 6e 61 70 73 r, sqlite3_snaps
1b60: 68 6f 74 20 2a 2a 70 70 53 6e 61 70 73 68 6f 74 hot **ppSnapshot
1b70: 29 3b 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 );. int sqlite3
1b80: 50 61 67 65 72 53 6e 61 70 73 68 6f 74 4f 70 65 PagerSnapshotOpe
1b90: 6e 28 50 61 67 65 72 20 2a 70 50 61 67 65 72 2c n(Pager *pPager,
1ba0: 20 73 71 6c 69 74 65 33 5f 73 6e 61 70 73 68 6f sqlite3_snapsho
1bb0: 74 20 2a 70 53 6e 61 70 73 68 6f 74 29 3b 0a 20 t *pSnapshot);.
1bc0: 20 69 6e 74 20 73 71 6c 69 74 65 33 50 61 67 65 int sqlite3Page
1bd0: 72 53 6e 61 70 73 68 6f 74 52 65 63 6f 76 65 72 rSnapshotRecover
1be0: 28 50 61 67 65 72 20 2a 70 50 61 67 65 72 29 3b (Pager *pPager);
1bf0: 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 50 61 . int sqlite3Pa
1c00: 67 65 72 53 6e 61 70 73 68 6f 74 43 68 65 63 6b gerSnapshotCheck
1c10: 28 50 61 67 65 72 20 2a 70 50 61 67 65 72 2c 20 (Pager *pPager,
1c20: 73 71 6c 69 74 65 33 5f 73 6e 61 70 73 68 6f 74 sqlite3_snapshot
1c30: 20 2a 70 53 6e 61 70 73 68 6f 74 29 3b 0a 20 20 *pSnapshot);.
1c40: 76 6f 69 64 20 73 71 6c 69 74 65 33 50 61 67 65 void sqlite3Page
1c50: 72 53 6e 61 70 73 68 6f 74 55 6e 6c 6f 63 6b 28 rSnapshotUnlock(
1c60: 50 61 67 65 72 20 2a 70 50 61 67 65 72 29 3b 0a Pager *pPager);.
1c70: 23 20 65 6e 64 69 66 0a 23 65 6c 73 65 0a 23 20 # endif.#else.#
1c80: 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 50 61 define sqlite3Pa
1c90: 67 65 72 55 73 65 57 61 6c 28 78 2c 79 29 20 30 gerUseWal(x,y) 0
1ca0: 0a 23 65 6e 64 69 66 0a 0a 23 69 66 64 65 66 20 .#endif..#ifdef
1cb0: 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 5a 49 SQLITE_ENABLE_ZI
1cc0: 50 56 46 53 0a 20 20 69 6e 74 20 73 71 6c 69 74 PVFS. int sqlit
1cd0: 65 33 50 61 67 65 72 57 61 6c 46 72 61 6d 65 73 e3PagerWalFrames
1ce0: 69 7a 65 28 50 61 67 65 72 20 2a 70 50 61 67 65 ize(Pager *pPage
1cf0: 72 29 3b 0a 23 65 6e 64 69 66 0a 0a 2f 2a 20 46 r);.#endif../* F
1d00: 75 6e 63 74 69 6f 6e 73 20 75 73 65 64 20 74 6f unctions used to
1d10: 20 71 75 65 72 79 20 70 61 67 65 72 20 73 74 61 query pager sta
1d20: 74 65 20 61 6e 64 20 63 6f 6e 66 69 67 75 72 61 te and configura
1d30: 74 69 6f 6e 2e 20 2a 2f 0a 75 38 20 73 71 6c 69 tion. */.u8 sqli
1d40: 74 65 33 50 61 67 65 72 49 73 72 65 61 64 6f 6e te3PagerIsreadon
1d50: 6c 79 28 50 61 67 65 72 2a 29 3b 0a 75 33 32 20 ly(Pager*);.u32
1d60: 73 71 6c 69 74 65 33 50 61 67 65 72 44 61 74 61 sqlite3PagerData
1d70: 56 65 72 73 69 6f 6e 28 50 61 67 65 72 2a 29 3b Version(Pager*);
1d80: 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 44 .#ifdef SQLITE_D
1d90: 45 42 55 47 0a 20 20 69 6e 74 20 73 71 6c 69 74 EBUG. int sqlit
1da0: 65 33 50 61 67 65 72 52 65 66 63 6f 75 6e 74 28 e3PagerRefcount(
1db0: 50 61 67 65 72 2a 29 3b 0a 23 65 6e 64 69 66 0a Pager*);.#endif.
1dc0: 69 6e 74 20 73 71 6c 69 74 65 33 50 61 67 65 72 int sqlite3Pager
1dd0: 4d 65 6d 55 73 65 64 28 50 61 67 65 72 2a 29 3b MemUsed(Pager*);
1de0: 0a 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 71 6c .const char *sql
1df0: 69 74 65 33 50 61 67 65 72 46 69 6c 65 6e 61 6d ite3PagerFilenam
1e00: 65 28 50 61 67 65 72 2a 2c 20 69 6e 74 29 3b 0a e(Pager*, int);.
1e10: 73 71 6c 69 74 65 33 5f 76 66 73 20 2a 73 71 6c sqlite3_vfs *sql
1e20: 69 74 65 33 50 61 67 65 72 56 66 73 28 50 61 67 ite3PagerVfs(Pag
1e30: 65 72 2a 29 3b 0a 73 71 6c 69 74 65 33 5f 66 69 er*);.sqlite3_fi
1e40: 6c 65 20 2a 73 71 6c 69 74 65 33 50 61 67 65 72 le *sqlite3Pager
1e50: 46 69 6c 65 28 50 61 67 65 72 2a 29 3b 0a 73 71 File(Pager*);.sq
1e60: 6c 69 74 65 33 5f 66 69 6c 65 20 2a 73 71 6c 69 lite3_file *sqli
1e70: 74 65 33 50 61 67 65 72 4a 72 6e 6c 46 69 6c 65 te3PagerJrnlFile
1e80: 28 50 61 67 65 72 2a 29 3b 0a 63 6f 6e 73 74 20 (Pager*);.const
1e90: 63 68 61 72 20 2a 73 71 6c 69 74 65 33 50 61 67 char *sqlite3Pag
1ea0: 65 72 4a 6f 75 72 6e 61 6c 6e 61 6d 65 28 50 61 erJournalname(Pa
1eb0: 67 65 72 2a 29 3b 0a 76 6f 69 64 20 2a 73 71 6c ger*);.void *sql
1ec0: 69 74 65 33 50 61 67 65 72 54 65 6d 70 53 70 61 ite3PagerTempSpa
1ed0: 63 65 28 50 61 67 65 72 2a 29 3b 0a 69 6e 74 20 ce(Pager*);.int
1ee0: 73 71 6c 69 74 65 33 50 61 67 65 72 49 73 4d 65 sqlite3PagerIsMe
1ef0: 6d 64 62 28 50 61 67 65 72 2a 29 3b 0a 76 6f 69 mdb(Pager*);.voi
1f00: 64 20 73 71 6c 69 74 65 33 50 61 67 65 72 43 61 d sqlite3PagerCa
1f10: 63 68 65 53 74 61 74 28 50 61 67 65 72 20 2a 2c cheStat(Pager *,
1f20: 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 20 2a int, int, int *
1f30: 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 50 );.void sqlite3P
1f40: 61 67 65 72 43 6c 65 61 72 43 61 63 68 65 28 50 agerClearCache(P
1f50: 61 67 65 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 ager*);.int sqli
1f60: 74 65 33 53 65 63 74 6f 72 53 69 7a 65 28 73 71 te3SectorSize(sq
1f70: 6c 69 74 65 33 5f 66 69 6c 65 20 2a 29 3b 0a 23 lite3_file *);.#
1f80: 69 66 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 ifdef SQLITE_ENA
1f90: 42 4c 45 5f 53 45 54 4c 4b 5f 54 49 4d 45 4f 55 BLE_SETLK_TIMEOU
1fa0: 54 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 50 61 T.void sqlite3Pa
1fb0: 67 65 72 52 65 73 65 74 4c 6f 63 6b 54 69 6d 65 gerResetLockTime
1fc0: 6f 75 74 28 50 61 67 65 72 20 2a 70 50 61 67 65 out(Pager *pPage
1fd0: 72 29 3b 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 r);.#else.# defi
1fe0: 6e 65 20 73 71 6c 69 74 65 33 50 61 67 65 72 52 ne sqlite3PagerR
1ff0: 65 73 65 74 4c 6f 63 6b 54 69 6d 65 6f 75 74 28 esetLockTimeout(
2000: 58 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a 20 46 75 X).#endif../* Fu
2010: 6e 63 74 69 6f 6e 73 20 75 73 65 64 20 74 6f 20 nctions used to
2020: 74 72 75 6e 63 61 74 65 20 74 68 65 20 64 61 74 truncate the dat
2030: 61 62 61 73 65 20 66 69 6c 65 2e 20 2a 2f 0a 76 abase file. */.v
2040: 6f 69 64 20 73 71 6c 69 74 65 33 50 61 67 65 72 oid sqlite3Pager
2050: 54 72 75 6e 63 61 74 65 49 6d 61 67 65 28 50 61 TruncateImage(Pa
2060: 67 65 72 2a 2c 50 67 6e 6f 29 3b 0a 0a 76 6f 69 ger*,Pgno);..voi
2070: 64 20 73 71 6c 69 74 65 33 50 61 67 65 72 52 65 d sqlite3PagerRe
2080: 6b 65 79 28 44 62 50 61 67 65 2a 2c 20 50 67 6e key(DbPage*, Pgn
2090: 6f 2c 20 75 31 36 29 3b 0a 0a 23 69 66 20 64 65 o, u16);..#if de
20a0: 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 48 41 53 fined(SQLITE_HAS
20b0: 5f 43 4f 44 45 43 29 20 26 26 20 21 64 65 66 69 _CODEC) && !defi
20c0: 6e 65 64 28 53 51 4c 49 54 45 5f 4f 4d 49 54 5f ned(SQLITE_OMIT_
20d0: 57 41 4c 29 0a 76 6f 69 64 20 2a 73 71 6c 69 74 WAL).void *sqlit
20e0: 65 33 50 61 67 65 72 43 6f 64 65 63 28 44 62 50 e3PagerCodec(DbP
20f0: 61 67 65 20 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a age *);.#endif..
2100: 2f 2a 20 46 75 6e 63 74 69 6f 6e 73 20 74 6f 20 /* Functions to
2110: 73 75 70 70 6f 72 74 20 74 65 73 74 69 6e 67 20 support testing
2120: 61 6e 64 20 64 65 62 75 67 67 69 6e 67 2e 20 2a and debugging. *
2130: 2f 0a 23 69 66 20 21 64 65 66 69 6e 65 64 28 4e /.#if !defined(N
2140: 44 45 42 55 47 29 20 7c 7c 20 64 65 66 69 6e 65 DEBUG) || define
2150: 64 28 53 51 4c 49 54 45 5f 54 45 53 54 29 0a 20 d(SQLITE_TEST).
2160: 20 50 67 6e 6f 20 73 71 6c 69 74 65 33 50 61 67 Pgno sqlite3Pag
2170: 65 72 50 61 67 65 6e 75 6d 62 65 72 28 44 62 50 erPagenumber(DbP
2180: 61 67 65 2a 29 3b 0a 20 20 69 6e 74 20 73 71 6c age*);. int sql
2190: 69 74 65 33 50 61 67 65 72 49 73 77 72 69 74 65 ite3PagerIswrite
21a0: 61 62 6c 65 28 44 62 50 61 67 65 2a 29 3b 0a 23 able(DbPage*);.#
21b0: 65 6e 64 69 66 0a 23 69 66 64 65 66 20 53 51 4c endif.#ifdef SQL
21c0: 49 54 45 5f 54 45 53 54 0a 20 20 69 6e 74 20 2a ITE_TEST. int *
21d0: 73 71 6c 69 74 65 33 50 61 67 65 72 53 74 61 74 sqlite3PagerStat
21e0: 73 28 50 61 67 65 72 2a 29 3b 0a 20 20 76 6f 69 s(Pager*);. voi
21f0: 64 20 73 71 6c 69 74 65 33 50 61 67 65 72 52 65 d sqlite3PagerRe
2200: 66 64 75 6d 70 28 50 61 67 65 72 2a 29 3b 0a 20 fdump(Pager*);.
2210: 20 76 6f 69 64 20 64 69 73 61 62 6c 65 5f 73 69 void disable_si
2220: 6d 75 6c 61 74 65 64 5f 69 6f 5f 65 72 72 6f 72 mulated_io_error
2230: 73 28 76 6f 69 64 29 3b 0a 20 20 76 6f 69 64 20 s(void);. void
2240: 65 6e 61 62 6c 65 5f 73 69 6d 75 6c 61 74 65 64 enable_simulated
2250: 5f 69 6f 5f 65 72 72 6f 72 73 28 76 6f 69 64 29 _io_errors(void)
2260: 3b 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 ;.#else.# define
2270: 20 64 69 73 61 62 6c 65 5f 73 69 6d 75 6c 61 74 disable_simulat
2280: 65 64 5f 69 6f 5f 65 72 72 6f 72 73 28 29 0a 23 ed_io_errors().#
2290: 20 64 65 66 69 6e 65 20 65 6e 61 62 6c 65 5f 73 define enable_s
22a0: 69 6d 75 6c 61 74 65 64 5f 69 6f 5f 65 72 72 6f imulated_io_erro
22b0: 72 73 28 29 0a 23 65 6e 64 69 66 0a 0a 23 65 6e rs().#endif..#en
22c0: 64 69 66 20 2f 2a 20 53 51 4c 49 54 45 5f 50 41 dif /* SQLITE_PA
22d0: 47 45 52 5f 48 20 2a 2f 0a GER_H */.