Index: README.md
==================================================================
--- README.md
+++ README.md
@@ -304,34 +304,17 @@
describes its purpose and role within the larger system.
## Verifying Code Authenticity
-If you obtained an SQLite source tree from a secondary source, such as a
-GitHub mirror, and you want to verify that it has not been altered, there
-are a couple of ways to do that.
-
-If you have a release version of SQLite, and you are using the
-`sqlite3.c` amalgamation, then SHA3-256 hashes for the amalgamation are
-available in the [change log](https://www.sqlite.org/changes.html) on
-the official website. After building the `sqlite3.c` file, you can check
-that it is authentic by comparing the hash. This does not ensure that the
-test scripts are unaltered, but it does validate the deliverable part of
-the code and the verification process only involves computing and
-comparing a single hash.
-
-For versions other than an official release, or if you are building the
-`sqlite3.c` amalgamation using non-standard build options, the verification
-process is a little more involved. The `manifest` file at the root directory
-of the source tree
+The `manifest` file at the root directory of the source tree
contains either a SHA3-256 hash (for newer files) or a SHA1 hash (for
-older files) for every source file in the repository. You can write a script
-to extracts hashes from `manifest` and verifies the hashes against the
-corresponding files in the source tree. The SHA3-256 hash of the `manifest`
+older files) for every source file in the repository.
+The SHA3-256 hash of the `manifest`
file itself is the official name of the version of the source tree that you
-have. The `manifest.uuid` file should contain the SHA3-256 hash of the
-`manifest` file. If all of the above hash comparisons are correct, then
+have. The `manifest.uuid` file should contain the SHA3-256 hash of the
+`manifest` file. If all of the above hash comparisons are correct, then
you can be confident that your source tree is authentic and unadulterated.
The format of the `manifest` file should be mostly self-explanatory, but
if you want details, they are available
[here](https://fossil-scm.org/fossil/doc/trunk/www/fileformat.wiki#manifest).
Index: ext/fts3/fts3_write.c
==================================================================
--- ext/fts3/fts3_write.c
+++ ext/fts3/fts3_write.c
@@ -2617,18 +2617,18 @@
break;
}
nList -= (int)(p - pList);
pList = p;
- if( nList==0 ){
+ if( nList<=0 ){
break;
}
p = &pList[1];
p += fts3GetVarint32(p, &iCurrent);
}
- if( bZero && &pList[nList]!=pEnd ){
+ if( bZero && (pEnd - &pList[nList])>0){
memset(&pList[nList], 0, pEnd - &pList[nList]);
}
*ppList = pList;
*pnList = nList;
}
Index: ext/fts5/fts5_index.c
==================================================================
--- ext/fts5/fts5_index.c
+++ ext/fts5/fts5_index.c
@@ -990,11 +990,11 @@
pData = fts5DataRead(p, FTS5_STRUCTURE_ROWID);
if( p->rc==SQLITE_OK ){
/* TODO: Do we need this if the leaf-index is appended? Probably... */
memset(&pData->p[pData->nn], 0, FTS5_DATA_PADDING);
p->rc = fts5StructureDecode(pData->p, pData->nn, &iCookie, &pRet);
- if( p->rc==SQLITE_OK && pConfig->iCookie!=iCookie ){
+ if( p->rc==SQLITE_OK && (pConfig->pgsz==0 || pConfig->iCookie!=iCookie) ){
p->rc = sqlite3Fts5ConfigLoad(pConfig, iCookie);
}
fts5DataRelease(pData);
if( p->rc!=SQLITE_OK ){
fts5StructureRelease(pRet);
Index: ext/fts5/test/fts5corrupt3.test
==================================================================
--- ext/fts5/test/fts5corrupt3.test
+++ ext/fts5/test/fts5corrupt3.test
@@ -4666,11 +4666,10 @@
} {a b a b}
do_execsql_test 38.2 {
UPDATE t1_data SET block = X'000202' WHERE rowid=1;
}
-breakpoint
do_catchsql_test 38.3 {
SELECT * FROM t1('a b') ORDER BY rank;
} {1 {database disk image is malformed}}
db close
@@ -8951,13 +8950,217 @@
do_execsql_test 61.1 {
CREATE VIRTUAL TABLE t3 USING fts5vocab('t1'(),'col' );
}
-do_catchsql_test 62.2 {
+do_catchsql_test 61.2 {
SELECT * FROM t3 ORDER BY rowid;
} {1 {database disk image is malformed}}
+breakpoint
+#-------------------------------------------------------------------------
+do_test 62.0 {
+ sqlite3 db {}
+ db deserialize [decode_hexdb {
+.open --hexdb
+| size 28672 pagesize 4096 filename crash-44942694542e1e.db
+| page 1 offset 0
+| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
+| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 00 .....@ ........
+| 96: 00 00 00 00 0d 0f c7 00 07 0d 92 00 0f 8d 0f 36 ...............6
+| 112: 0e cb 0e 6b 0e 0e 0d b6 0d 92 00 00 00 00 00 00 ...k............
+| 3472: 00 00 22 08 06 17 11 11 01 31 74 61 62 6c 65 74 .........1tablet
+| 3488: 32 74 32 08 43 52 45 41 54 45 20 54 41 42 4c 45 2t2.CREATE TABLE
+| 3504: 20 74 32 28 78 29 56 07 06 17 1f 1f 01 7d 74 61 t2(x)V.......ta
+| 3520: 62 6c 65 74 31 5f 63 6f 6e 66 79 67 74 31 5f 63 blet1_confygt1_c
+| 3536: 6f 6e 66 69 67 07 43 52 45 41 54 45 20 54 41 42 onfig.CREATE TAB
+| 3552: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b LE 't1_config'(k
+| 3568: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29 PRIMARY KEY, v)
+| 3584: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 06 WITHOUT ROWID[.
+| 3600: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64 ..!!...tablet1_d
+| 3616: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65 ocsizet1_docsize
+| 3632: 06 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74 .CREATE TABLE 't
+| 3648: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e 1_docsize'(id IN
+| 3664: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 TEGER PRIMARY KE
+| 3680: 59 2c 20 73 7a 20 52 4c 4f 42 29 5e 05 07 17 21 Y, sz RLOB)^...!
+| 3696: 21 01 81 07 74 61 62 6c 65 74 31 5f 63 6f 6e 74 !...tablet1_cont
+| 3712: 65 6e 74 74 35 ff 63 6f 6e 74 65 6e 74 05 43 52 entt5.content.CR
+| 3728: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 EATE TABLE 't1_c
+| 3744: 6f 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 ontent'(id INTEG
+| 3760: 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 ER PRIMARY KEY,
+| 3776: 63 30 2c 20 63 31 2c 20 63 42 29 69 04 07 17 19 c0, c1, cB)i....
+| 3792: 19 01 81 2d 74 61 62 6c 65 74 31 5f 69 64 78 74 ...-tablet1_idxt
+| 3808: 31 5f 79 64 78 04 43 52 45 41 54 45 20 54 41 42 1_ydx.CREATE TAB
+| 3824: 4c 45 20 27 74 31 5f 69 64 78 27 28 73 65 67 69 LE 't1_idx'(segi
+| 3840: 64 2c 20 74 65 72 6d 2c 20 70 67 6e 6f 2c 20 50 d, term, pgno, P
+| 3856: 52 49 4d 41 52 59 20 4b 45 59 28 73 65 67 69 64 RIMARY KEY(segid
+| 3872: 2c 20 74 65 72 6d 29 29 20 57 49 54 48 4f 55 54 , term)) WITHOUT
+| 3888: 20 52 4f 57 49 44 55 03 07 17 1b 1b 01 81 01 74 ROWIDU........t
+| 3904: 61 62 6c 65 74 31 5f 64 61 74 61 74 31 5f 74 61 ablet1_datat1_ta
+| 3920: 74 61 03 43 52 45 41 54 45 20 54 41 42 4c 45 20 ta.CREATE TABLE
+| 3936: 27 74 31 5f 64 61 74 61 27 28 69 64 20 49 4e 54 't1_data'(id INT
+| 3952: 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 EGER PRIMARY KEY
+| 3968: 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 29 38 02 06 , block BLOB)8..
+| 3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52 ...._tablet1t1CR
+| 4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB
+| 4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 35 LE t1 USING fts5
+| 4032: 28 61 2c 62 2c 63 29 00 00 00 00 00 00 00 00 00 (a,b,c).........
+| page 3 offset 8192
+| 0: 0d 00 00 00 03 0c 94 00 0f e6 0f ef 0c 94 00 00 ................
+| 3216: 00 00 00 00 86 4a 84 80 80 80 80 01 04 00 8d 18 .....J..........
+| 3232: 00 00 03 2b 02 30 30 01 02 06 01 02 06 01 02 06 ...+.00.........
+| 3248: 2f 02 03 01 02 03 01 02 03 01 08 32 30 31 36 30 /..........20160
+| 3264: 36 30 39 01 02 07 01 02 07 01 02 07 01 01 34 01 609...........4.
+| 3280: 02 05 01 02 c7 01 02 05 01 01 35 01 02 04 01 02 ..........5.....
+| 3296: 04 01 02 04 02 07 30 30 30 30 30 30 30 1c 02 04 ......0000000...
+| 3312: 01 02 04 01 02 04 01 06 62 69 6e 61 72 79 03 06 ........binary..
+| 3328: 01 02 02 04 16 01 02 02 03 06 01 02 02 02 06 01 ................
+| 3344: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 ................
+| 3360: 02 03 06 01 02 02 03 06 01 02 02 02 06 01 02 02 ................
+| 3376: 03 06 01 02 02 03 06 01 02 02 01 08 63 6f 6d 70 ............comp
+| 3392: 69 6c 65 72 01 02 02 01 02 02 01 02 02 01 06 64 iler...........d
+| 3408: 62 73 74 61 74 07 02 03 00 02 03 01 02 03 02 04 bstat...........
+| 3424: 65 62 74 67 04 02 02 01 02 02 01 02 02 01 06 65 ebtg...........e
+| 3440: 6e 61 62 6c 65 07 02 02 01 02 02 01 02 02 01 02 nable...........
+| 3456: 02 01 02 02 01 02 02 01 02 02 01 02 01 f1 02 02 ................
+| 3472: 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 ................
+| 3488: 02 02 01 02 02 45 02 02 01 02 02 01 02 02 01 02 .....E..........
+| 3504: 02 01 02 02 02 08 78 74 65 6e 73 69 6f 6e 1f 02 ......xtension..
+| 3520: 04 01 02 09 c1 02 04 01 04 66 74 73 34 0a 02 03 .........fts4...
+| 3536: 01 02 03 01 02 03 04 00 35 0d 02 03 01 02 04 01 ........5.......
+| 3552: 02 03 01 0f d7 63 63 01 02 03 01 02 03 01 02 03 .....cc.........
+| 3568: 02 06 65 6f 70 6f 6b 79 10 02 03 01 02 03 01 02 ..eopoky........
+| 3584: 03 01 05 6a 73 6f 6e 31 13 02 03 14 02 03 01 02 ...json1........
+| 3600: 03 01 04 6c 6f 61 64 1f 02 03 01 02 03 01 02 03 ...load.........
+| 3616: 01 03 6d 61 78 1c 02 02 01 02 02 01 02 02 02 05 ..max...........
+| 3632: 65 6d 6f 72 79 1c 02 03 01 02 03 01 02 03 04 04 emory...........
+| 3648: 73 79 73 35 16 02 03 01 02 03 01 02 03 01 06 6e sys5...........n
+| 3664: 6f 63 61 73 65 02 06 01 02 12 03 06 01 02 02 03 ocase...........
+| 3680: 06 01 02 02 03 06 01 02 02 09 f6 01 02 02 03 06 ................
+| 3696: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 ................
+| 3712: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 11 02 ................
+| 3728: 02 01 04 6f 7d 69 74 1f 02 02 01 02 02 01 02 02 ...o.it.........
+| 3744: 01 05 72 74 72 65 65 19 02 03 01 02 03 01 02 03 ..rtree.........
+| 3760: 04 02 69 6d 01 06 01 02 02 03 06 01 02 02 03 06 ..im............
+| 3776: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 ................
+| 3792: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 11 02 ................
+| 3808: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 ................
+| 3824: 00 fa 74 68 72 65 61 64 73 61 66 65 22 02 02 01 ..threadsafe....
+| 3840: 02 02 01 02 02 01 04 76 74 61 62 07 03 04 01 40 .......vtab....@
+| 3856: 04 01 02 04 11 01 78 01 06 01 01 02 01 06 01 01 ......x.........
+| 3872: 02 01 06 01 00 02 01 06 01 01 02 01 03 91 01 02 ................
+| 3888: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 ................
+| 3904: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 ................
+| 3920: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 ................
+| 3936: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 ................
+| 3952: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 ................
+| 3968: 01 06 01 01 02 01 76 01 01 02 01 06 01 01 02 5c ......v.........
+| 3984: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 11 06 ................
+| 4000: 01 02 02 01 06 08 11 02 01 06 01 01 02 01 06 01 ................
+| 4016: 01 02 01 06 01 01 02 01 06 01 01 02 01 05 01 01 ................
+| 4032: 02 01 06 01 01 02 01 06 01 01 02 04 15 13 0c 0c ................
+| 4048: 12 44 13 11 0f 47 13 0f 0c 0e 11 10 ca 0e 10 0f .D...G..........
+| 4064: 44 0f 10 40 15 0f 07 01 03 00 14 24 5a 14 24 0f D..@.......$Z.$.
+| 4080: 0a 03 00 24 ff ff ff ff 01 01 02 00 01 01 01 01 ...$............
+| page 4 offset 12288
+| 0: 0a 00 00 00 01 0f fb 00 00 00 00 00 00 00 00 00 ................
+| 4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02 ................
+| page 5 offset 16384
+| 0: 0d 00 00 00 24 0c 09 00 00 00 00 00 00 00 00 00 ....$...........
+| 3072: 00 00 00 00 00 00 00 00 00 00 18 24 05 00 25 0f ...........$..%.
+| 3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49 .THREADSAFE=0XBI
+| 3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41 NARY.#..%..THREA
+| 3120: 44 53 41 46 45 3d 30 58 4e 4f 43 41 53 47 17 22 DSAFE=0XNOCASG..
+| 3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 45 3d ..%..THREADSAFE=
+| 3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d 0XRTRIM.!..3..OM
+| 3168: 49 54 20 4c 3f 41 44 20 45 58 54 45 4e 53 49 4f IT L?AD EXTENSIO
+| 3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f NXBINARY. ..3..O
+| 3200: 4d 49 64 20 4c 4f 41 44 20 45 58 54 45 d9 53 49 MId LOAD EXTE.SI
+| 3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17 ONXNOCASE....3..
+| 3232: 4f 4d 39 54 20 4c 4f 41 44 20 45 58 55 45 4e 53 OM9T LOAD EXUENS
+| 3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f 19 IONXRTRIM....3..
+| 3264: 4c 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 30 LAX MEMORY=50000
+| 3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f 000XBINARY....3.
+| 3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 .MAX MEMORY=5000
+| 3312: 30 30 30 30 58 af 4f 43 41 53 45 1e 1c 05 00 33 0000X.OCASE....3
+| 3328: 0f 17 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 ..MAX MEMORY=500
+| 3344: 30 30 ab 30 30 58 62 54 52 49 4d 18 1b 05 00 25 00.00XbTRIM....%
+| 3360: 0f 19 45 4e 41 42 4c 45 20 52 54 52 45 45 58 42 ..ENABLE RTREEXB
+| 3376: 49 4e 41 52 59 18 1b 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB
+| 3392: 4c 45 20 52 54 52 45 45 58 4e 4f 43 41 53 45 17 LE RTREEXNOCASE.
+| 3408: 19 05 00 25 0f 17 45 4e 41 42 4c 45 20 52 54 52 ...%..ENABLE RTR
+| 3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45 EEXRTRIM....)..E
+| 3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 63 35 58 42 49 NABLE MEMSYc5XBI
+| 3456: 4e 41 52 59 1a 17 04 00 29 0f 19 45 4e 41 42 4c NARY....)..ENABL
+| 3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 53 45 E MEMSYS5XNOCASE
+| 3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 3d 45 ....)..ENABLE =E
+| 3504: 4d 53 59 53 35 58 52 54 52 49 4d 18 15 05 00 25 MSYS5XRTRIM....%
+| 3520: 0f 19 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 58 42 ..ENABLE JSON1XB
+| 3536: 49 4e 41 52 59 18 14 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB
+| 3552: 4c 46 20 4a 53 4f 4e 31 58 4e 4f 43 41 53 45 17 LF JSON1XNOCASE.
+| 3568: 13 05 00 25 0f 17 45 4e 41 42 4c 45 20 4a 53 4f ...%..ENABLE JSO
+| 3584: 4e 31 58 52 54 52 49 4d 1a 12 05 00 29 0f 19 45 N1XRTRIM....)..E
+| 3600: 4e 41 42 4c 45 20 46 45 46 50 4f 4c 59 57 42 49 NABLE FEFPOLYWBI
+| 3616: 4e 41 52 59 18 11 05 00 29 0f 19 45 4e 41 42 4c NARY....)..ENABL
+| 3632: 45 20 47 45 4f 50 4f 4c 59 58 4e 5f 43 41 53 45 E GEOPOLYXN_CASE
+| 3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 42 ....)..ENABLE GB
+| 3664: 2f 50 4f 4c 59 58 51 54 52 49 4d 17 0f 05 00 23 /POLYXQTRIM....#
+| 3680: 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 58 42 49 ..ENABLE FTS5XBI
+| 3696: 4e 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 4c NARY....#..ENABL
+| 3712: 45 20 46 54 53 35 58 4e 4f 43 41 53 45 16 0d 05 E FTS5XNOCASE...
+| 3728: 00 23 0f 17 45 4e 41 42 4c 45 20 46 54 53 35 58 .#..ENABLE FTS5X
+| 3744: 52 54 52 49 4d 17 1c 05 00 23 0f 19 45 4e 41 42 RTRIM....#..ENAB
+| 3760: 4c 45 20 46 54 53 34 58 42 49 4e 41 52 59 16 0b LE FTS4XBINARY..
+| 3776: 05 00 22 0f e9 45 4e 41 42 4c 35 20 46 54 53 34 .....ENABL5 FTS4
+| 3792: 58 4e 4f 43 41 53 45 16 0a 05 00 23 00 47 45 4e XNOCASE....#.GEN
+| 3808: 41 42 4c 45 20 46 54 53 34 57 52 54 52 49 4d 1e ABLE FTS4WRTRIM.
+| 3824: 60 05 00 31 0f 19 45 4e 41 42 4c 55 20 43 42 53 `..1..ENABLU CBS
+| 3840: 54 41 54 20 56 54 42 42 58 42 49 4e 41 52 59 1e TAT VTBBXBINARY.
+| 3856: 08 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS
+| 3872: 54 40 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d T@T VTABXNOCASE.
+| 3888: 07 05 00 31 0f 17 45 4e 41 42 4c 55 20 44 42 53 ...1..ENABLU DBS
+| 3904: 54 41 54 20 56 54 41 42 58 52 54 52 49 4d 12 06 TAT VTABXRTRIM..
+| 3920: 05 00 17 0f 19 44 45 42 55 47 58 42 49 4e 41 52 .....DEBUGXBINAR
+| 3936: 59 21 05 05 00 17 0f 19 44 45 42 55 47 58 4e 4f Y!......DEBUGXNO
+| 3952: 43 41 53 45 10 04 05 00 17 0f 18 44 45 42 55 47 CASE.......DEBUG
+| 3968: 58 42 54 52 49 4d 27 11 05 00 43 0f 19 43 4f 4d XBTRIM'...C..COM
+| 3984: 50 49 48 f5 52 3d 67 63 63 2d 35 2e 34 2e 30 20 PIH.R=gcc-5.4.0
+| 4000: 32 30 31 36 30 36 30 39 58 42 49 4e 41 52 59 27 20160609XBINARY'
+| 4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67 ...C..COMPILER=g
+| 4032: 63 63 2d 35 2e 34 2e 30 22 32 30 31 36 30 36 30 cc-5.4.0.2016060
+| 4048: 39 c2 3e 4f 43 41 53 45 26 01 05 00 43 0f 17 43 9.>OCASE&...C..C
+| 4064: 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e OMPILER=gcc-5.4.
+| 4080: 30 30 32 30 31 26 30 36 30 39 58 52 54 52 49 4d 00201&0609XRTRIM
+| page 6 offset 20480
+| 0: 0d 00 00 00 24 0e e0 00 00 00 00 00 00 00 00 00 ....$...........
+| 3808: 06 24 03 00 12 02 01 01 06 23 03 00 12 02 01 01 .$.......#......
+| 3824: 06 22 03 00 12 02 01 01 06 21 03 00 12 03 01 01 .........!......
+| 3840: 06 20 03 00 12 03 01 01 06 1f 03 00 12 03 01 01 . ..............
+| 3856: 06 1e 03 00 12 03 01 01 06 1d 03 00 12 03 01 01 ................
+| 3872: 06 1c 03 00 12 03 01 01 06 1b 03 00 12 02 01 01 ................
+| 3888: 06 1a 03 00 12 02 01 01 06 19 03 00 12 02 01 01 ................
+| 3904: 06 18 03 00 12 02 01 00 f6 17 03 00 19 e2 f9 01 ................
+| 3920: 06 16 03 00 12 02 05 01 06 15 03 00 12 02 01 01 ................
+| 3936: 06 14 03 00 12 02 01 01 06 13 03 00 12 02 01 01 ................
+| 3952: 06 12 03 00 12 02 01 01 06 11 03 00 12 02 01 01 ................
+| 3968: 06 10 03 10 12 02 01 01 06 0f 03 00 12 02 01 01 ................
+| 3984: 06 0e 03 00 12 02 01 01 06 0d 03 00 12 02 00 f1 ................
+| 4000: 06 0c 03 00 12 02 01 01 06 0b 03 00 12 02 01 01 ................
+| 4016: 06 0a 03 00 12 02 01 01 05 09 03 00 12 03 01 01 ................
+| 4032: 06 08 03 00 12 03 01 01 06 07 03 00 12 03 01 01 ................
+| 4048: 06 06 03 00 12 01 01 01 06 05 02 ff 84 01 01 01 ................
+| 4064: 06 04 03 00 12 01 01 01 06 03 03 00 12 06 01 01 ................
+| 4080: 07 02 03 00 12 06 01 01 06 01 03 00 12 06 01 01 ................
+| page 7 offset 24576
+| 0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00 ................
+| 4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04 ........version.
+| end crash-44942694542e1e.db
+}]} {}
+
+do_catchsql_test 62.1 {
+ WITH c(x) AS (VALUES(false) UNION ALL SELECT x+1 FROM c WHERE x<72)
+ INSERT INTO t1(a) SELECT randomblob(2829) FROM c;
+} {0 {}}
sqlite3_fts5_may_be_corrupt 0
finish_test
ADDED ext/fts5/test/fts5corrupt4.test
Index: ext/fts5/test/fts5corrupt4.test
==================================================================
--- /dev/null
+++ ext/fts5/test/fts5corrupt4.test
@@ -0,0 +1,61 @@
+# 2019 May 16
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you do good and not evil.
+# May you find forgiveness for yourself and forgive others.
+# May you share freely, never taking more than you give.
+#
+#***********************************************************************
+#
+#
+
+source [file join [file dirname [info script]] fts5_common.tcl]
+set testprefix fts5corrupt4
+
+# If SQLITE_ENABLE_FTS5 is defined, omit this file.
+ifcapable !fts5 {
+ finish_test
+ return
+}
+sqlite3_fts5_may_be_corrupt 1
+
+do_execsql_test 1.0 {
+ CREATE VIRTUAL TABLE ttt USING fts5(a, b);
+ INSERT INTO ttt
+ VALUES('e ee eee e ee eee e ee eee', 'eee ee e e e ee eee ee ee');
+ INSERT INTO ttt SELECT a||a, b||b FROM ttt;
+ INSERT INTO ttt SELECT a||a, b||b FROM ttt;
+}
+
+proc mutate {blob i} {
+ set o [expr {$i % [string length $blob]}]
+ set a [string range $blob 0 $o-1]
+ set b [string range $blob $o+1 end]
+ set v [expr int(rand()*255) - 127]
+ return "$a[binary format c $v]$b"
+}
+db func mutate mutate
+
+for {set j 1000} {$j <= 5000} {incr j 1000} {
+ do_test 1.$j {
+ for {set i 0} {$i < 1000} {incr i} {
+ execsql {
+ BEGIN;
+ UPDATE ttt_data SET block = mutate(block, $i) WHERE id>10;
+ }
+ foreach sql {
+ {SELECT snippet(ttt, -1, '.', '..', '[', ']'), * FROM ttt('e*')}
+ {SELECT snippet(ttt, -1, '.', '..', '[', ']'), * FROM ttt('e* NOT ee*')}
+ } {
+ catch { execsql $sql }
+ }
+ execsql ROLLBACK
+ }
+ } {}
+}
+
+sqlite3_fts5_may_be_corrupt 0
+finish_test
+
Index: ext/session/sqlite3session.c
==================================================================
--- ext/session/sqlite3session.c
+++ ext/session/sqlite3session.c
@@ -1622,11 +1622,13 @@
}
}
}
sqlite3_free((char*)azCol);
if( bMismatch ){
- *pzErrMsg = sqlite3_mprintf("table schemas do not match");
+ if( pzErrMsg ){
+ *pzErrMsg = sqlite3_mprintf("table schemas do not match");
+ }
rc = SQLITE_SCHEMA;
}
if( bHasPk==0 ){
/* Ignore tables with no primary keys */
goto diff_out;
@@ -1828,11 +1830,11 @@
**
** If successful, return zero. Otherwise, if an OOM condition is encountered,
** set *pRc to SQLITE_NOMEM and return non-zero.
*/
static int sessionBufferGrow(SessionBuffer *p, size_t nByte, int *pRc){
- if( *pRc==SQLITE_OK && p->nAlloc-p->nBufnAlloc-p->nBuf)nAlloc ? p->nAlloc : 128;
do {
nNew = nNew*2;
}while( (nNew-p->nBuf)childPtrSize;
+ const int nOverrun = 18; /* Size of the overrun padding */
pPage->xParseCell(pPage, pCellBody, &pCur->info);
nCell = (int)pCur->info.nKey;
testcase( nCell<0 ); /* True if key size is 2^32 or more */
testcase( nCell==0 ); /* Invalid key size: 0x80 0x80 0x00 */
testcase( nCell==1 ); /* Invalid key size: 0x80 0x80 0x01 */
@@ -5532,17 +5533,18 @@
testcase( nCell==2 ); /* Minimum legal index key size */
if( nCell<2 || nCell/pCur->pBt->usableSize>pCur->pBt->nPage ){
rc = SQLITE_CORRUPT_PAGE(pPage);
goto moveto_finish;
}
- pCellKey = sqlite3Malloc( nCell+18 );
+ pCellKey = sqlite3Malloc( nCell+nOverrun );
if( pCellKey==0 ){
rc = SQLITE_NOMEM_BKPT;
goto moveto_finish;
}
pCur->ix = (u16)idx;
rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
+ memset(((u8*)pCellKey)+nCell,0,nOverrun); /* Fix uninit warnings */
pCur->curFlags &= ~BTCF_ValidOvfl;
if( rc ){
sqlite3_free(pCellKey);
goto moveto_finish;
}
Index: src/build.c
==================================================================
--- src/build.c
+++ src/build.c
@@ -3104,10 +3104,18 @@
sqlite3VdbeAddOp4Int(v, OP_SorterCompare, iSorter, j2, regRecord,
pIndex->nKeyCol); VdbeCoverage(v);
sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
sqlite3VdbeJumpHere(v, j2);
}else{
+ /* Most CREATE INDEX and REINDEX statements that are not UNIQUE can not
+ ** abort. The exception is if one of the indexed expressions contains a
+ ** user function that throws an exception when it is evaluated. But the
+ ** overhead of adding a statement journal to a CREATE INDEX statement is
+ ** very small (since most of the pages written do not contain content that
+ ** needs to be restored if the statement aborts), so we call
+ ** sqlite3MayAbort() for all CREATE INDEX statements. */
+ sqlite3MayAbort(pParse);
addr2 = sqlite3VdbeCurrentAddr(v);
}
sqlite3VdbeAddOp3(v, OP_SorterData, iSorter, regRecord, iIdx);
if( !pIndex->bAscKeyBug ){
/* This OP_SeekEnd opcode makes index insert for a REINDEX go much
Index: src/expr.c
==================================================================
--- src/expr.c
+++ src/expr.c
@@ -2806,10 +2806,11 @@
** this code only executes once. Because for a non-constant
** expression we need to rerun this code each time.
*/
if( addrOnce && !sqlite3ExprIsConstant(pE2) ){
sqlite3VdbeChangeToNoop(v, addrOnce);
+ ExprClearProperty(pExpr, EP_Subrtn);
addrOnce = 0;
}
/* Evaluate the expression and insert it into the temp table */
r3 = sqlite3ExprCodeTarget(pParse, pE2, r1);
@@ -4859,10 +4860,11 @@
if( pA->op!=TK_STRING
&& pA->op!=TK_TRUEFALSE
&& (combinedFlags & EP_Reduced)==0
){
if( pA->iColumn!=pB->iColumn ) return 2;
+ if( pA->op2!=pB->op2 ) return 2;
if( pA->iTable!=pB->iTable
&& (pA->iTable!=iTab || NEVER(pB->iTable>=0)) ) return 2;
}
}
return 0;
Index: src/parse.y
==================================================================
--- src/parse.y
+++ src/parse.y
@@ -299,28 +299,32 @@
%type scanpt {const char*}
scanpt(A) ::= . {
assert( yyLookahead!=YYNOCODE );
A = yyLookaheadToken.z;
}
+scantok(A) ::= . {
+ assert( yyLookahead!=YYNOCODE );
+ A = yyLookaheadToken;
+}
// "carglist" is a list of additional constraints that come after the
// column name and column type in a CREATE TABLE statement.
//
carglist ::= carglist ccons.
carglist ::= .
ccons ::= CONSTRAINT nm(X). {pParse->constraintName = X;}
-ccons ::= DEFAULT scanpt(A) term(X) scanpt(Z).
- {sqlite3AddDefaultValue(pParse,X,A,Z);}
+ccons ::= DEFAULT scantok(A) term(X).
+ {sqlite3AddDefaultValue(pParse,X,A.z,&A.z[A.n]);}
ccons ::= DEFAULT LP(A) expr(X) RP(Z).
{sqlite3AddDefaultValue(pParse,X,A.z+1,Z.z);}
-ccons ::= DEFAULT PLUS(A) term(X) scanpt(Z).
- {sqlite3AddDefaultValue(pParse,X,A.z,Z);}
-ccons ::= DEFAULT MINUS(A) term(X) scanpt(Z). {
+ccons ::= DEFAULT PLUS(A) scantok(Z) term(X).
+ {sqlite3AddDefaultValue(pParse,X,A.z,&Z.z[Z.n]);}
+ccons ::= DEFAULT MINUS(A) scantok(Z) term(X). {
Expr *p = sqlite3PExpr(pParse, TK_UMINUS, X, 0);
- sqlite3AddDefaultValue(pParse,p,A.z,Z);
+ sqlite3AddDefaultValue(pParse,p,A.z,&Z.z[Z.n]);
}
-ccons ::= DEFAULT scanpt id(X). {
+ccons ::= DEFAULT scantok id(X). {
Expr *p = tokenExpr(pParse, TK_STRING, X);
if( p ){
sqlite3ExprIdToTrueFalse(p);
testcase( p->op==TK_TRUEFALSE && sqlite3ExprTruthValue(p) );
}
Index: src/pragma.c
==================================================================
--- src/pragma.c
+++ src/pragma.c
@@ -648,10 +648,15 @@
if( !zMode ){
/* If the "=MODE" part does not match any known journal mode,
** then do a query */
eMode = PAGER_JOURNALMODE_QUERY;
}
+ if( eMode==PAGER_JOURNALMODE_OFF && (db->flags & SQLITE_Defensive)!=0 ){
+ /* Do not allow journal-mode "OFF" in defensive since the database
+ ** can become corrupted using ordinary SQL when the journal is off */
+ eMode = PAGER_JOURNALMODE_QUERY;
+ }
}
if( eMode==PAGER_JOURNALMODE_QUERY && pId2->n==0 ){
/* Convert "PRAGMA journal_mode" into "PRAGMA main.journal_mode" */
iDb = 0;
pId2->n = 1;
@@ -2130,32 +2135,34 @@
** textkey 4
** textrekey 5
*/
case PragTyp_KEY: {
if( zRight ){
- int n = pPragma->iArg<4 ? sqlite3Strlen30(zRight) : -1;
- if( (pPragma->iArg & 1)==0 ){
- sqlite3_key_v2(db, zDb, zRight, n);
- }else{
- sqlite3_rekey_v2(db, zDb, zRight, n);
- }
- }
- break;
- }
- case PragTyp_HEXKEY: {
- if( zRight ){
- u8 iByte;
- int i;
- char zKey[40];
- for(i=0, iByte=0; iiArg & 1)==0 ){
- sqlite3_key_v2(db, zDb, zKey, i/2);
- }else{
- sqlite3_rekey_v2(db, zDb, zKey, i/2);
+ char zBuf[40];
+ const char *zKey = zRight;
+ int n;
+ if( pPragma->iArg==2 || pPragma->iArg==3 ){
+ u8 iByte;
+ int i;
+ for(i=0, iByte=0; iiArg<4 ? sqlite3Strlen30(zRight) : -1;
+ }
+ if( (pPragma->iArg & 1)==0 ){
+ rc = sqlite3_key_v2(db, zDb, zKey, n);
+ }else{
+ rc = sqlite3_rekey_v2(db, zDb, zKey, n);
+ }
+ if( rc==SQLITE_OK && n!=0 ){
+ sqlite3VdbeSetNumCols(v, 1);
+ sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "ok", SQLITE_STATIC);
+ returnSingleText(v, "ok");
}
}
break;
}
#endif
Index: src/pragma.h
==================================================================
--- src/pragma.h
+++ src/pragma.h
@@ -44,14 +44,13 @@
#define PragTyp_TEMP_STORE_DIRECTORY 36
#define PragTyp_THREADS 37
#define PragTyp_WAL_AUTOCHECKPOINT 38
#define PragTyp_WAL_CHECKPOINT 39
#define PragTyp_ACTIVATE_EXTENSIONS 40
-#define PragTyp_HEXKEY 41
-#define PragTyp_KEY 42
-#define PragTyp_LOCK_STATUS 43
-#define PragTyp_STATS 44
+#define PragTyp_KEY 41
+#define PragTyp_LOCK_STATUS 42
+#define PragTyp_STATS 43
/* Property flags associated with various pragma. */
#define PragFlg_NeedSchema 0x01 /* Force schema load before running */
#define PragFlg_NoColumns 0x02 /* OP_ResultRow called with zero columns */
#define PragFlg_NoColumns1 0x04 /* zero columns if RHS argument is present */
@@ -327,16 +326,16 @@
/* iArg: */ 0 },
#endif
#endif
#if defined(SQLITE_HAS_CODEC)
{/* zName: */ "hexkey",
- /* ePragTyp: */ PragTyp_HEXKEY,
+ /* ePragTyp: */ PragTyp_KEY,
/* ePragFlg: */ 0,
/* ColNames: */ 0, 0,
/* iArg: */ 2 },
{/* zName: */ "hexrekey",
- /* ePragTyp: */ PragTyp_HEXKEY,
+ /* ePragTyp: */ PragTyp_KEY,
/* ePragFlg: */ 0,
/* ColNames: */ 0, 0,
/* iArg: */ 3 },
#endif
#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
Index: src/resolve.c
==================================================================
--- src/resolve.c
+++ src/resolve.c
@@ -474,11 +474,13 @@
** Because no reference was made to outer contexts, the pNC->nRef
** fields are not changed in any context.
*/
if( cnt==0 && zTab==0 ){
assert( pExpr->op==TK_ID );
- if( ExprHasProperty(pExpr,EP_DblQuoted) ){
+ if( ExprHasProperty(pExpr,EP_DblQuoted)
+ && 0==(pTopNC->ncFlags&NC_NoDblQStr)
+ ){
/* If a double-quoted identifier does not match any known column name,
** then treat it as a string.
**
** This hack was added in the early days of SQLite in a misguided attempt
** to be compatible with MySQL 3.x, which used double-quotes for strings.
@@ -1652,11 +1654,11 @@
*/
int sqlite3ResolveExprNames(
NameContext *pNC, /* Namespace to resolve expressions in. */
Expr *pExpr /* The expression to be analyzed. */
){
- u16 savedHasAgg;
+ int savedHasAgg;
Walker w;
if( pExpr==0 ) return SQLITE_OK;
savedHasAgg = pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
@@ -1767,9 +1769,12 @@
sSrc.a[0].iCursor = -1;
}
sNC.pParse = pParse;
sNC.pSrcList = &sSrc;
sNC.ncFlags = type;
+ if( !pParse->db->init.busy && !sqlite3WritableSchema(pParse->db) ){
+ sNC.ncFlags |= NC_NoDblQStr;
+ }
if( (rc = sqlite3ResolveExprNames(&sNC, pExpr))!=SQLITE_OK ) return rc;
if( pList ) rc = sqlite3ResolveExprListNames(&sNC, pList);
return rc;
}
Index: src/select.c
==================================================================
--- src/select.c
+++ src/select.c
@@ -4841,10 +4841,14 @@
}
assert( p->pSrc!=0 );
if( (selFlags & SF_Expanded)!=0 ){
return WRC_Prune;
}
+ if( pWalker->eCode ){
+ /* Renumber selId because it has been copied from a view */
+ p->selId = ++pParse->nSelect;
+ }
pTabList = p->pSrc;
pEList = p->pEList;
sqlite3WithPush(pParse, p->pWith, 0);
/* Make sure cursor numbers have been assigned to all entries in
@@ -4890,16 +4894,19 @@
return WRC_Abort;
}
#if !defined(SQLITE_OMIT_VIEW) || !defined (SQLITE_OMIT_VIRTUALTABLE)
if( IsVirtual(pTab) || pTab->pSelect ){
i16 nCol;
+ u8 eCodeOrig = pWalker->eCode;
if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort;
assert( pFrom->pSelect==0 );
pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0);
nCol = pTab->nCol;
pTab->nCol = -1;
+ pWalker->eCode = 1; /* Turn on Select.selId renumbering */
sqlite3WalkSelect(pWalker, pFrom->pSelect);
+ pWalker->eCode = eCodeOrig;
pTab->nCol = nCol;
}
#endif
}
@@ -5145,10 +5152,11 @@
w.xSelectCallback2 = 0;
sqlite3WalkSelect(&w, pSelect);
}
w.xSelectCallback = selectExpander;
w.xSelectCallback2 = selectPopWith;
+ w.eCode = 0;
sqlite3WalkSelect(&w, pSelect);
}
#ifndef SQLITE_OMIT_SUBQUERY
@@ -5471,14 +5479,16 @@
for(pItem = pTabList->a; pItempSelect==0 ) continue;
if( pItem->fg.viaCoroutine ) continue;
if( pItem->zName==0 ) continue;
- if( sqlite3_stricmp(pItem->zDatabase, pThis->zDatabase)!=0 ) continue;
+ assert( pItem->pTab!=0 );
+ assert( pThis->pTab!=0 );
+ if( pItem->pTab->pSchema!=pThis->pTab->pSchema ) continue;
if( sqlite3_stricmp(pItem->zName, pThis->zName)!=0 ) continue;
pS1 = pItem->pSelect;
- if( pThis->pSelect->selId!=pS1->selId ){
+ if( pItem->pTab->pSchema==0 && pThis->pSelect->selId!=pS1->selId ){
/* The query flattener left two different CTE tables with identical
** names in the same FROM clause. */
continue;
}
if( sqlite3ExprCompare(0, pThis->pSelect->pWhere, pS1->pWhere, -1)
@@ -5506,11 +5516,12 @@
** The transformation only works if all of the following are true:
**
** * The subquery is a UNION ALL of two or more terms
** * The subquery does not have a LIMIT clause
** * There is no WHERE or GROUP BY or HAVING clauses on the subqueries
-** * The outer query is a simple count(*)
+** * The outer query is a simple count(*) with no WHERE clause or other
+** extraneous syntax.
**
** Return TRUE if the optimization is undertaken.
*/
static int countOfViewOptimization(Parse *pParse, Select *p){
Select *pSub, *pPrior;
@@ -5517,10 +5528,12 @@
Expr *pExpr;
Expr *pCount;
sqlite3 *db;
if( (p->selFlags & SF_Aggregate)==0 ) return 0; /* This is an aggregate */
if( p->pEList->nExpr!=1 ) return 0; /* Single result column */
+ if( p->pWhere ) return 0;
+ if( p->pGroupBy ) return 0;
pExpr = p->pEList->a[0].pExpr;
if( pExpr->op!=TK_AGG_FUNCTION ) return 0; /* Result is an aggregate */
if( sqlite3_stricmp(pExpr->u.zToken,"count") ) return 0; /* Is count() */
if( pExpr->x.pList!=0 ) return 0; /* Must be count(*) */
if( p->pSrc->nSrc!=1 ) return 0; /* One table in FROM */
Index: src/sqlite.h.in
==================================================================
--- src/sqlite.h.in
+++ src/sqlite.h.in
@@ -2198,10 +2198,11 @@
** flag is enabled, language features that allow ordinary SQL to
** deliberately corrupt the database file are disabled. The disabled
** features include but are not limited to the following:
**
** - The [PRAGMA writable_schema=ON] statement.
+**
- The [PRAGMA journal_mode=OFF] statement.
**
- Writes to the [sqlite_dbpage] virtual table.
**
- Direct writes to [shadow tables].
**
**
**
Index: src/sqliteInt.h
==================================================================
--- src/sqliteInt.h
+++ src/sqliteInt.h
@@ -828,16 +828,17 @@
** using C-preprocessor macros. If that is unsuccessful, or if
** -DSQLITE_BYTEORDER=0 is set, then byte-order is determined
** at run-time.
*/
#ifndef SQLITE_BYTEORDER
-# if defined(i386) || defined(__i386__) || defined(_M_IX86) || \
- defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \
- defined(_M_AMD64) || defined(_M_ARM) || defined(__x86) || \
- defined(__arm__) || defined(_M_ARM64)
+# if defined(i386) || defined(__i386__) || defined(_M_IX86) || \
+ defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \
+ defined(_M_AMD64) || defined(_M_ARM) || defined(__x86) || \
+ defined(__ARMEL__) || defined(__AARCH64EL__) || defined(_M_ARM64)
# define SQLITE_BYTEORDER 1234
-# elif defined(sparc) || defined(__ppc__)
+# elif defined(sparc) || defined(__ppc__) || \
+ defined(__ARMEB__) || defined(__AARCH64EB__)
# define SQLITE_BYTEORDER 4321
# else
# define SQLITE_BYTEORDER 0
# endif
#endif
@@ -2499,11 +2500,11 @@
ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
** TK_VARIABLE: variable number (always >= 1).
** TK_SELECT_COLUMN: column of the result vector */
i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */
- u8 op2; /* TK_REGISTER: original value of Expr.op
+ u8 op2; /* TK_REGISTER/TK_TRUTH: original value of Expr.op
** TK_COLUMN: the value of p5 for OP_Column
** TK_AGG_FUNCTION: nesting depth */
AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
union {
Table *pTab; /* TK_COLUMN: Table containing column. Can be NULL
@@ -2784,11 +2785,11 @@
Upsert *pUpsert; /* ON CONFLICT clause information from an upsert */
} uNC;
NameContext *pNext; /* Next outer name context. NULL for outermost */
int nRef; /* Number of names resolved by this context */
int nErr; /* Number of errors encountered while resolving names */
- u16 ncFlags; /* Zero or more NC_* flags defined below */
+ int ncFlags; /* Zero or more NC_* flags defined below */
Select *pWinSelect; /* SELECT statement for any window functions */
};
/*
** Allowed values for the NameContext, ncFlags field.
@@ -2811,10 +2812,12 @@
#define NC_UUpsert 0x0200 /* True if uNC.pUpsert is used */
#define NC_MinMaxAgg 0x1000 /* min/max aggregates seen. See note above */
#define NC_Complex 0x2000 /* True if a function or subquery seen */
#define NC_AllowWin 0x4000 /* Window functions are allowed here */
#define NC_HasWin 0x8000 /* One or more window functions seen */
+#define NC_NoDblQStr 0x10000 /* Do not allow double-quoted string hack.
+ ** Mnemonic: "NO DouBLe-Quoted STRings" */
/*
** An instance of the following object describes a single ON CONFLICT
** clause in an upsert.
**
Index: src/vdbe.c
==================================================================
--- src/vdbe.c
+++ src/vdbe.c
@@ -1499,11 +1499,11 @@
}
nByte = pIn1->n + pIn2->n;
if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
goto too_big;
}
- if( sqlite3VdbeMemGrow(pOut, (int)nByte+2, pOut==pIn2) ){
+ if( sqlite3VdbeMemGrow(pOut, (int)nByte+3, pOut==pIn2) ){
goto no_mem;
}
MemSetTypeFlag(pOut, MEM_Str);
if( pOut!=pIn2 ){
memcpy(pOut->z, pIn2->z, pIn2->n);
@@ -1513,10 +1513,11 @@
memcpy(&pOut->z[pIn2->n], pIn1->z, pIn1->n);
assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
pIn1->flags = flags1;
pOut->z[nByte]=0;
pOut->z[nByte+1] = 0;
+ pOut->z[nByte+2] = 0;
pOut->flags |= MEM_Term;
pOut->n = (int)nByte;
pOut->enc = encoding;
UPDATE_MAX_BLOBSIZE(pOut);
break;
@@ -2881,10 +2882,14 @@
assert( pData0<=pLast );
if( zAffinity ){
pRec = pData0;
do{
applyAffinity(pRec, zAffinity[0], encoding);
+ if( zAffinity[0]==SQLITE_AFF_REAL && (pRec->flags & MEM_Int) ){
+ pRec->flags |= MEM_IntReal;
+ pRec->flags &= ~(MEM_Int);
+ }
REGISTER_TRACE((int)(pRec-aMem), pRec);
zAffinity++;
pRec++;
assert( zAffinity[0]==0 || pRec<=pLast );
}while( zAffinity[0] );
@@ -4781,11 +4786,11 @@
if( pOp->p4type==P4_TABLE && HasRowid(pOp->p4.pTab) && pOp->p5==0 ){
/* If p5 is zero, the seek operation that positioned the cursor prior to
** OP_Delete will have also set the pC->movetoTarget field to the rowid of
** the row that is being deleted */
i64 iKey = sqlite3BtreeIntegerKey(pC->uc.pCursor);
- assert( pC->movetoTarget==iKey );
+ assert( CORRUPT_DB || pC->movetoTarget==iKey );
}
#endif
/* If the update-hook or pre-update-hook will be invoked, set zDb to
** the name of the db to pass as to it. Also set local pTab to a copy
Index: src/vdbeaux.c
==================================================================
--- src/vdbeaux.c
+++ src/vdbeaux.c
@@ -629,10 +629,11 @@
*/
int sqlite3VdbeAssertMayAbort(Vdbe *v, int mayAbort){
int hasAbort = 0;
int hasFkCounter = 0;
int hasCreateTable = 0;
+ int hasCreateIndex = 0;
int hasInitCoroutine = 0;
Op *pOp;
VdbeOpIter sIter;
memset(&sIter, 0, sizeof(sIter));
sIter.v = v;
@@ -647,10 +648,18 @@
){
hasAbort = 1;
break;
}
if( opcode==OP_CreateBtree && pOp->p3==BTREE_INTKEY ) hasCreateTable = 1;
+ if( mayAbort ){
+ /* hasCreateIndex may also be set for some DELETE statements that use
+ ** OP_Clear. So this routine may end up returning true in the case
+ ** where a "DELETE FROM tbl" has a statement-journal but does not
+ ** require one. This is not so bad - it is an inefficiency, not a bug. */
+ if( opcode==OP_CreateBtree && pOp->p3==BTREE_BLOBKEY ) hasCreateIndex = 1;
+ if( opcode==OP_Clear ) hasCreateIndex = 1;
+ }
if( opcode==OP_InitCoroutine ) hasInitCoroutine = 1;
#ifndef SQLITE_OMIT_FOREIGN_KEY
if( opcode==OP_FkCounter && pOp->p1==0 && pOp->p2==1 ){
hasFkCounter = 1;
}
@@ -662,11 +671,12 @@
** If malloc failed, then the while() loop above may not have iterated
** through all opcodes and hasAbort may be set incorrectly. Return
** true for this case to prevent the assert() in the callers frame
** from failing. */
return ( v->db->mallocFailed || hasAbort==mayAbort || hasFkCounter
- || (hasCreateTable && hasInitCoroutine) );
+ || (hasCreateTable && hasInitCoroutine) || hasCreateIndex
+ );
}
#endif /* SQLITE_DEBUG - the sqlite3AssertMayAbort() function */
#ifdef SQLITE_DEBUG
/*
Index: src/vdbemem.c
==================================================================
--- src/vdbemem.c
+++ src/vdbemem.c
@@ -116,11 +116,14 @@
zBuf[acc.nChar] = 0; /* Fast version of sqlite3StrAccumFinish(&acc) */
}
#ifdef SQLITE_DEBUG
/*
-** Check that string value of pMem agrees with its integer or real value.
+** Validity checks on pMem. pMem holds a string.
+**
+** (1) Check that string value of pMem agrees with its integer or real value.
+** (2) Check that the string is correctly zero terminated
**
** A single int or real value always converts to the same strings. But
** many different strings can be converted into the same int or real.
** If a table contains a numeric value and an index is based on the
** corresponding string value, then it is important that the string be
@@ -134,15 +137,26 @@
** been derived from the numeric and not the other way around. It returns
** true if everything is ok and false if there is a problem.
**
** This routine is for use inside of assert() statements only.
*/
-int sqlite3VdbeMemConsistentDualRep(Mem *p){
+int sqlite3VdbeMemValidStrRep(Mem *p){
char zBuf[100];
char *z;
int i, j, incr;
if( (p->flags & MEM_Str)==0 ) return 1;
+ if( p->flags & MEM_Term ){
+ /* Insure that the string is properly zero-terminated. Pay particular
+ ** attention to the case where p->n is odd */
+ if( p->szMalloc>0 && p->z==p->zMalloc ){
+ assert( p->enc==SQLITE_UTF8 || p->szMalloc >= ((p->n+1)&~1)+2 );
+ assert( p->enc!=SQLITE_UTF8 || p->szMalloc >= p->n+1 );
+ }
+ assert( p->z[p->n]==0 );
+ assert( p->enc==SQLITE_UTF8 || p->z[(p->n+1)&~1]==0 );
+ assert( p->enc==SQLITE_UTF8 || p->z[((p->n+1)&~1)+1]==0 );
+ }
if( (p->flags & (MEM_Int|MEM_Real|MEM_IntReal))==0 ) return 1;
vdbeMemRenderNum(sizeof(zBuf), zBuf, p);
z = p->z;
i = j = 0;
incr = 1;
@@ -1219,11 +1233,11 @@
assert( 0==(1&SQLITE_PTR_TO_INT(pVal->z)) );
}
assert(pVal->enc==(enc & ~SQLITE_UTF16_ALIGNED) || pVal->db==0
|| pVal->db->mallocFailed );
if( pVal->enc==(enc & ~SQLITE_UTF16_ALIGNED) ){
- assert( sqlite3VdbeMemConsistentDualRep(pVal) );
+ assert( sqlite3VdbeMemValidStrRep(pVal) );
return pVal->z;
}else{
return 0;
}
}
@@ -1242,11 +1256,11 @@
if( !pVal ) return 0;
assert( pVal->db==0 || sqlite3_mutex_held(pVal->db->mutex) );
assert( (enc&3)==(enc&~SQLITE_UTF16_ALIGNED) );
assert( !sqlite3VdbeMemIsRowSet(pVal) );
if( (pVal->flags&(MEM_Str|MEM_Term))==(MEM_Str|MEM_Term) && pVal->enc==enc ){
- assert( sqlite3VdbeMemConsistentDualRep(pVal) );
+ assert( sqlite3VdbeMemValidStrRep(pVal) );
return pVal->z;
}
if( pVal->flags&MEM_Null ){
return 0;
}
Index: test/check.test
==================================================================
--- test/check.test
+++ test/check.test
@@ -115,15 +115,17 @@
}
} {4 11.0}
do_test check-2.1 {
execsql {
+ PRAGMA writable_schema = 1;
CREATE TABLE t2(
x INTEGER CONSTRAINT one CHECK( typeof(coalesce(x,0))=="integer" ),
y REAL CONSTRAINT two CHECK( typeof(coalesce(y,0.1))=='real' ),
z TEXT CONSTRAINT three CHECK( typeof(coalesce(z,''))=='text' )
);
+ PRAGMA writable_schema = 0;
}
} {}
do_test check-2.2 {
execsql {
INSERT INTO t2 VALUES(1,2.2,'three');
Index: test/corruptL.test
==================================================================
--- test/corruptL.test
+++ test/corruptL.test
@@ -1005,7 +1005,59 @@
do_catchsql_test 10.1 {
SELECT * FROM t1 WHERE a<='2019-05-09' ORDER BY a DESC;
} {1 {database disk image is malformed}}
+
+#-------------------------------------------------------------------------
+reset_db
+do_test 11.0 {
+ sqlite3 db {}
+ db deserialize [decode_hexdb {
+| size 595 pagesize 512 filename x.db
+| page 1 offset 0
+| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
+| 16: 02 00 00 01 00 40 20 20 00 01 00 0c 00 00 00 07 .....@ ........
+| 32: 00 00 00 05 07 a1 1f fa 00 00 00 08 00 00 00 04 ................
+| 48: 00 00 01 00 00 49 00 00 00 00 00 05 00 00 00 00 .....I..........
+| 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1c ................
+| 96: 00 2e 2c 50 0d 00 00 00 06 01 06 00 01 da 01 b0 ..,P............
+| 112: 01 56 01 86 01 2a 01 06 00 00 62 00 00 00 00 00 .V...*....b.....
+| 128: 00 ed e2 78 74 64 33 ff 43 52 45 41 54 45 20 49 ...xtd3.CREATE I
+| 144: 4e 44 45 58 20 74 33 78 20 4f 4e 20 74 33 28 38 NDEX t3x ON t3(8
+| 160: 29 2e 04 06 17 15 11 01 45 69 6e 64 65 68 74 32 ).......Eindeht2
+| 176: 63 64 74 31 e5 43 52 45 41 54 45 20 49 4e 44 45 cdt1.CREATE INDE
+| 192: 58 20 74 32 63 c4 20 4f 4e 20 74 32 28 63 2c 64 X t2c. ON t2(c,d
+| 208: 29 28 05 06 17 01 11 11 3d 74 61 6c 36 74 62 74 )(......=tal6tbt
+| 224: 65 32 04 43 52 45 41 54 45 20 54 41 42 4c 45 20 e2.CREATE TABLE
+| 240: 74 00 04 00 00 00 00 00 00 00 00 00 00 00 00 00 t...............
+| 256: 00 00 00 00 00 00 22 07 06 17 11 11 01 30 e8 03 .............0..
+| 272: 62 6c 65 74 34 74 35 02 43 52 45 41 54 45 20 54 blet4t5.CREATE T
+| 288: 41 42 4c 45 20 74 34 28 94 29 2a 06 06 17 13 11 ABLE t4(.)*.....
+| 304: 01 3f 69 33 74 6e 65 78 78 74 64 33 ff 43 52 45 .?i3tnexxtd3.CRE
+| 320: 41 54 45 20 49 4e 44 45 58 20 74 33 78 20 4f 4e ATE INDEX t3x ON
+| 336: 20 74 31 28 38 29 2e 04 06 17 15 11 01 45 69 6e t1(8).......Ein
+| 352: 64 65 68 74 32 63 64 74 31 e5 43 52 45 41 54 45 deht2cdt1.CREATE
+| 368: 20 49 4e 44 45 58 20 74 32 63 c4 20 4f 4e 20 74 INDEX t2c. ON t
+| 384: 32 28 63 2c 64 29 28 05 06 17 01 11 11 3d 74 61 2(c,d)(......=ta
+| 400: 6c 32 74 62 74 65 32 04 43 52 45 41 54 45 20 54 l2tbte2.CREATE T
+| 416: 41 42 4c 45 20 74 33 28 63 2c 78 2c 65 2c 66 29 ABLE t3(c,x,e,f)
+| 432: 28 02 06 17 11 11 01 3d 74 61 9e 93 65 74 32 74 (......=ta..et2t
+| 448: 32 03 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 2.CREATE TABLE t
+| 464: 32 28 63 2c 64 2c 65 2c 66 29 24 01 06 17 11 11 2(c,d,e,f)$.....
+| 480: 01 35 55 61 62 6c 88 74 31 74 31 02 43 52 45 41 .5Uabl.t1t1.CREA
+| 496: 54 45 20 54 41 42 4c 45 20 74 31 28 61 2c 62 29 TE TABLE t1(a,b)
+| page 2 offset 512
+| 0: 0d 00 00 00 0d 25 00 01 cf 00 01 fa 01 f3 01 de .....%..........
+| 16: 01 00 00 00 fd 00 00 0d 00 00 00 00 45 20 54 41 ............E TA
+| 32: 42 4c 45 20 74 34 28 94 29 2a 06 06 17 13 11 01 BLE t4(.)*......
+| 48: 3f 69 33 74 6e 65 78 78 74 64 33 ff 43 52 45 a0 ?i3tnexxtd3.CRE.
+| 64: a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 74 13 11 01 ............t...
+| 80: 49 45 74 00 00 00 00 00 00 00 00 00 00 00 00 00 IEt.............
+| end x.db
+}]} {}
+
+do_catchsql_test 11.1 {
+ DELETE FROM t3 WHERE x IN (SELECT x FROM t4);
+} {1 {database disk image is malformed}}
finish_test
Index: test/countofview.test
==================================================================
--- test/countofview.test
+++ test/countofview.test
@@ -37,7 +37,20 @@
do_execsql_test 1.3 {
select count(*) from (
select c from t2 union all select f from t3
)
} {3}
+
+# 2019-05-15
+do_execsql_test 2.0 {
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES(1),(99),('abc');
+ CREATE VIEW v1(x,y) AS SELECT x,1 FROM t1 UNION ALL SELECT x,2 FROM t1;
+ SELECT count(*) FROM v1 WHERE x<>1;
+} {4}
+do_execsql_test 2.1 {
+ SELECT count(*) FROM v1 GROUP BY y;
+} {3 3}
+
+
finish_test
ADDED test/expr2.test
Index: test/expr2.test
==================================================================
--- /dev/null
+++ test/expr2.test
@@ -0,0 +1,54 @@
+# 2019 May 20
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you do good and not evil.
+# May you find forgiveness for yourself and forgive others.
+# May you share freely, never taking more than you give.
+#
+#***********************************************************************
+# This file implements regression tests for SQLite library. The
+# focus of this file is testing expressions.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix expr2
+
+do_execsql_test 1.0 {
+ CREATE TABLE t0(c0);
+ INSERT INTO t0(c0) VALUES ('val');
+}
+
+do_execsql_test 1.1 {
+ SELECT * FROM t0 WHERE (
+ ( (0 IS NOT FALSE) OR NOT (0 IS FALSE OR (t0.c0 = 1)) ) IS 0
+ )
+} {val}
+
+do_execsql_test 1.2.1 {
+ SELECT
+ ( (0 IS NOT FALSE) OR NOT (0 IS FALSE OR (t0.c0 = 1)) ) IS 0
+ FROM t0
+} {1}
+
+do_execsql_test 1.2.2 {
+ SELECT
+ ( (0 IS NOT FALSE) OR NOT (0 IS 0 OR (t0.c0 = 1)) ) IS 0
+ FROM t0
+} {1}
+
+do_execsql_test 1.3 {
+ SELECT ( (0 IS NOT FALSE) OR NOT (0 IS FALSE OR (t0.c0 = 1)) ) FROM t0
+} {0}
+
+do_execsql_test 1.4.1 {
+ SELECT (0 IS NOT FALSE) FROM t0
+} {0}
+do_execsql_test 1.4.2 {
+ SELECT NOT (0 IS FALSE OR (t0.c0 = 1)) FROM t0
+} {0}
+
+
+finish_test
Index: test/fts3corrupt4.test
==================================================================
--- test/fts3corrupt4.test
+++ test/fts3corrupt4.test
@@ -1944,11 +1944,11 @@
| end crash-c666cfde112dee.db
}]} {}
do_catchsql_test 13.1 {
SELECT quote(matchinfo(t1,'pcxybs'))==0 FROM t1 WHERE b MATCH 'e*';
-} {0 {0 0}}
+} {0 {}}
#-------------------------------------------------------------------------
reset_db
do_test 14.0 {
sqlite3 db {}
@@ -2824,11 +2824,11 @@
| end crash-4ce32d0608aff1.db
}]} {}
do_catchsql_test 18.1 {
SELECT quote(matchinfo(t1,'pcxybs'))==0 FROM t1 WHERE b MATCH 'e*';
-} {0 0}
+} {0 {}}
#-------------------------------------------------------------------------
reset_db
do_test 19.0 {
sqlite3 db {}
@@ -4398,8 +4398,219 @@
do_catchsql_test 25.6 {
INSERT INTO t1(t1) SELECT x FROM t2;
INSERT INTO t1(t1) SELECT x FROM t2;
} {1 {database disk image is malformed}}
+
+#-------------------------------------------------------------------------
+reset_db
+do_test 26.0 {
+ sqlite3 db {}
+ db deserialize [decode_hexdb {
+.open --hexdb
+| size 28672 pagesize 4096 filename crash-26682721375870.db
+| page 1 offset 0
+| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
+| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 00 .....@ ........
+| 96: 00 00 00 00 0d 0e b1 00 06 0d a4 00 0f 8d 0f 21 ...............!
+| 112: 0e b9 0d c8 0e 7e 0d a4 00 00 00 00 00 00 00 00 .....~..........
+| 3488: 00 00 00 00 22 07 06 17 11 11 01 31 74 61 62 6c ...........1tabl
+| 3504: 65 74 32 74 32 07 43 52 45 41 54 45 20 54 41 42 et2t2.CREATE TAB
+| 3520: 4c 45 20 74 32 28 78 29 81 33 05 07 17 1f 1f 01 LE t2(x).3......
+| 3536: 82 35 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72 .5tablet1_segdir
+| 3552: 74 31 5f 73 65 67 64 69 72 05 43 52 45 41 54 45 t1_segdir.CREATE
+| 3568: 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69 TABLE 't1_segdi
+| 3584: 72 27 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 51 r'(level INTEGEQ
+| 3600: 2c 69 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61 ,idx INTEGER,sta
+| 3616: 72 74 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52 rt_block INTEGER
+| 3632: 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 ,leaves_end_bloc
+| 3648: 6b 20 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c k INTEGER,end_bl
+| 3664: 6f 63 6b 20 49 4e 54 45 47 45 62 2c 72 6f 6f 74 ock INTEGEb,root
+| 3680: 20 42 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45 BLOB,PRIMARY KE
+| 3696: 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 06 Y(level, idx))1.
+| 3712: 06 17 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74 ..E...indexsqlit
+| 3728: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73 e_autoindex_t1_s
+| 3744: 65 67 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72 egdir_1t1_segdir
+| 3760: 06 0f c7 00 08 00 00 00 00 66 04 07 17 23 23 01 .........f...##.
+| 3776: 81 13 74 61 62 6c 65 74 31 5f 73 65 66 6d 65 6e ..tablet1_sefmen
+| 3792: 74 73 74 31 5f 73 65 67 6d 65 6e 74 73 04 43 52 tst1_segments.CR
+| 3808: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 EATE TABLE 't1_s
+| 3824: 65 67 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64 egments'(blockid
+| 3840: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 INTEGER PRIMARY
+| 3856: 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 KEY, block BLOB
+| 3872: 29 6a 03 07 17 21 21 01 81 1f 74 61 62 6c 65 74 )j...!!...tablet
+| 3888: 31 5f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 1_contentt1_cont
+| 3904: 65 6e 74 03 43 52 45 41 54 45 20 54 41 42 4c 45 ent.CREATE TABLE
+| 3920: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f 't1_content'(do
+| 3936: 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d cid INTEGER PRIM
+| 3952: 41 52 59 20 4b 45 59 2c 20 27 63 30 61 27 2c 20 ARY KEY, 'c0a',
+| 3968: 27 63 31 62 27 2c 20 27 63 32 63 27 29 38 02 06 'c1b', 'c2c')8..
+| 3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52 ...._tablet1t1CR
+| 4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB
+| 4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33 LE t1 USING fts3
+| 4032: 28 61 2c 62 2c 63 29 00 00 00 00 00 00 00 00 00 (a,b,c).........
+| page 3 offset 8192
+| 0: 0d 00 00 00 25 0b 48 00 0f d8 0f af 0f 86 0f 74 ....%.H........t
+| 16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5 .a.N./..........
+| 32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 0d ef 00 00 ...t.[.@.$......
+| 2880: 00 00 00 00 00 00 00 00 81 3f 25 06 00 82 7f 00 .........?%.....
+| 2896: 00 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e .COMPILER=gcc-5.
+| 2912: 34 23 00 20 32 2f 31 36 30 36 30 39 20 44 45 42 4#. 2/160609 DEB
+| 2928: 55 47 20 45 4e 41 42 4c 45 20 44 42 53 54 41 54 UG ENABLE DBSTAT
+| 2944: 20 56 54 41 42 20 45 4e 41 42 4c 45 20 46 54 53 VTAB ENABLE FTS
+| 2960: 34 20 45 4e 41 42 4c 45 20 46 54 53 35 20 45 4e 4 ENABLE FTS5 EN
+| 2976: 41 42 4c 45 20 47 45 4f 50 4f 4c 59 20 45 4e 41 ABLE GEOPOLY ENA
+| 2992: 42 4c 45 20 4a 53 4f 4e 31 20 45 4e 41 42 4c 45 BLE JSON1 ENABLE
+| 3008: 20 4d 45 4d 53 59 53 35 20 45 4e 41 42 4c 45 20 MEMSYS5 ENABLE
+| 3024: 52 54 52 45 45 20 4d 41 58 20 4d 45 4d 4f 52 59 RTREE MAX MEMORY
+| 3040: 3d 35 30 30 30 30 30 30 30 20 4f 4d 49 54 20 4c =50000000 OMIT L
+| 3056: 4f 41 44 20 45 58 54 45 4e 53 59 4f 4e 20 54 48 OAD EXTENSYON TH
+| 3072: 52 45 41 44 53 41 46 45 3d 30 18 24 05 00 25 0f READSAFE=0.$..%.
+| 3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49 .THREADSAFE=0XBI
+| 3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41 NARY.#..%..THREA
+| 3120: 44 53 41 46 45 3d 30 58 4e 4f 43 41 53 45 17 22 DSAFE=0XNOCASE..
+| 3136: 05 00 25 0f 17 54 38 52 45 41 44 53 41 46 45 3d ..%..T8READSAFE=
+| 3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d 0XRTRIM.!..3..OM
+| 3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 fc 53 49 4f IT LOAD EXTE.SIO
+| 3184: 4e 68 42 49 4e 4a c2 59 1f 20 05 00 33 0f 19 4f NhBINJ.Y. ..3..O
+| 3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 MIT LOAD EXTENSI
+| 3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17 ONXNOCASE....3..
+| 3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 OMIT LOAD EXTENS
+| 3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f 19 IONXRTRIM....3..
+| 3264: 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 2f 30 30 MAX MEMORY=50/00
+| 3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f 000XBINARY....3.
+| 3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 .MAX MEMORY=5000
+| 3312: 30 30 30 30 48 4e 4f 43 41 53 45 1e 1c 05 00 33 0000HNOCASE....3
+| 3328: 0f 17 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 ..MAX MEMORY=500
+| 3344: 30 30 30 30 30 58 52 54 52 49 4d 18 1b 05 00 25 00000XRTRIM....%
+| 3360: 0f 19 45 4e 41 42 4c 45 20 52 54 52 45 45 58 42 ..ENABLE RTREEXB
+| 3376: 49 4e 41 52 59 18 1a 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB
+| 3392: 4c 45 20 52 54 52 45 45 58 4e 4f 53 41 53 45 17 LE RTREEXNOSASE.
+| 3408: 19 05 00 25 0f 17 45 4e 41 42 4c 45 20 52 54 52 ...%..ENABLE RTR
+| 3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45 EEXRTRIM....)..E
+| 3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 58 42 49 NABLE MEMSYS5XBI
+| 3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4e 41 42 4c NARY....)..ENABL
+| 3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 53 45 E MEMSYS5XNOCASE
+| 3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 4d 45 ....)..ENABLE ME
+| 3504: 4d 53 59 53 35 58 52 54 52 49 4d 18 15 05 00 25 MSYS5XRTRIM....%
+| 3520: 0f 19 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 58 42 ..ENABLE JSON1XB
+| 3536: 49 4e 41 52 59 18 14 05 00 25 0f 19 45 4e 42 42 INARY....%..ENBB
+| 3552: 4d 45 20 4a 53 4f 4e 31 58 4e 4f 43 41 53 45 17 ME JSON1XNOCASE.
+| 3568: 13 05 00 25 0f 17 45 4e 41 42 4c 45 20 4a 53 4f ...%..ENABLE JSO
+| 3584: 4e 31 58 52 54 52 49 4d 1a 12 05 00 29 0f 19 45 N1XRTRIM....)..E
+| 3600: 4e 41 42 4c 45 20 47 45 4f 50 4f 4c 59 58 42 49 NABLE GEOPOLYXBI
+| 3616: 4e 41 52 59 1a 11 05 00 29 0f 19 45 4e 41 1e 4c NARY....)..ENA.L
+| 3632: 45 20 47 45 4f 50 4f 4c 59 58 4e 4f 43 41 53 45 E GEOPOLYXNOCASE
+| 3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 45 ....)..ENABLE GE
+| 3664: 4f 50 4f 4c 59 58 62 54 52 49 4d 17 0f 05 00 23 OPOLYXbTRIM....#
+| 3680: 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 58 42 49 ..ENABLE FTS5XBI
+| 3696: 4e 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 4c NARY....#..ENABL
+| 3712: 45 20 46 54 fc 35 58 4e 4f 43 41 53 45 16 0d 05 E FT.5XNOCASE...
+| 3728: 00 23 0f 17 45 4e 41 42 4c 45 20 46 54 53 35 58 .#..ENABLE FTS5X
+| 3744: 52 54 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42 RTRIM....#..ENAB
+| 3760: 4c 45 20 46 54 53 34 58 42 49 4e 41 52 59 17 0b LE FTS4XBINARY..
+| 3776: 05 00 23 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 ..#..ENABLE FTS5
+| 3792: 58 4e 4f 43 40 53 45 16 0a 05 00 23 0f 17 45 4e XNOC@SE....#..EN
+| 3808: 41 42 4c 45 20 56 54 53 34 58 52 54 52 49 4d 1e ABLE VTS4XRTRIM.
+| 3824: 09 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS
+| 3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 b3 58 1e TAT VTABXBINA.X.
+| 3856: 08 05 00 31 0f 19 45 4e 40 42 4c 45 20 44 42 53 ...1..EN@BLE DBS
+| 3872: 54 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d TAT VTABXNOCASE.
+| 3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 45 42 53 ...1..ENABLE EBS
+| 3904: 54 41 54 20 56 54 41 42 58 52 54 52 49 4d 11 06 TAT VTABXRTRIM..
+| 3920: 05 00 17 0f 19 44 45 42 55 47 58 42 49 4e 41 52 .....DEBUGXBINAR
+| 3936: 59 11 05 05 00 17 0f 19 44 45 42 55 47 58 4e 4f Y.......DEBUGXNO
+| 3952: 43 41 53 45 10 04 05 00 17 0f 17 44 45 42 55 47 CASE.......DEBUG
+| 3968: 58 52 54 52 49 4d 27 03 05 00 43 0f 19 43 4f 4d XRTRIM'...C..COM
+| 3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20 PILER=gcc-5.4.0
+| 4000: 32 30 31 36 30 36 30 39 58 4b 19 4e 41 52 59 27 20160609XK.NARY'
+| 4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67 ...C..COMPILER=g
+| 4032: 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36 30 cc-5.4.0 2016060
+| page 5 offset 16384
+| 0: 0d 00 00 00 02 0b a0 00 0c ad 0b a0 00 00 00 00 ................
+| 2976: 82 0a 02 08 08 09 08 08 17 84 06 30 20 32 34 33 ...........0 243
+| 2992: 00 01 30 04 25 06 1b 00 00 08 32 30 31 36 30 36 ..0.%.....201606
+| 3008: 30 39 03 25 07 00 00 01 34 03 25 05 00 00 01 35 09.%....4.%....5
+| 3024: 03 25 04 00 01 07 30 30 30 30 30 30 30 03 25 1a .%....0000000.%.
+| 3040: 00 00 08 63 6f 6d 70 69 6c 65 72 03 25 02 00 00 ...compiler.%...
+| 3056: 06 64 62 73 74 51 74 03 25 0a 00 01 04 65 62 75 .dbstQt.%....ebu
+| 3072: 67 03 25 08 00 00 06 65 6e 61 62 6c 65 09 25 09 g.%....enable.%.
+| 3088: 05 04 04 04 04 04 00 01 08 78 74 65 6e 73 69 6f .........xtensio
+| 3104: 6e 03 25 1d 00 00 04 66 74 73 34 03 25 0d 00 03 n.%....fts4.%...
+| 3120: 01 35 03 25 0f 00 00 03 67 63 63 03 25 03 00 01 .5.%....gcc.%...
+| 3136: 06 65 6f 70 6f 6c 79 03 25 11 00 00 05 6a 73 6f .eopoly.%....jso
+| 3152: 6e 31 03 25 13 00 00 04 6c 6f 61 64 03 25 1c 00 n1.%....load.%..
+| 3168: 00 03 6d 61 78 03 25 18 00 01 05 65 6d 6f 72 79 ..max.%....emory
+| 3184: 03 25 19 00 03 04 73 79 73 35 03 25 15 00 00 04 .%....sys5.%....
+| 3200: 6f 6d 69 74 03 25 1b 00 00 05 72 74 72 65 65 03 omit.%....rtree.
+| 3216: 25 17 00 00 0a 74 68 72 65 61 64 73 61 66 65 03 %....threadsafe.
+| 3232: 25 1e 00 00 04 76 74 61 62 03 25 0b 00 86 50 01 %....vtab.%...P.
+| 3248: 08 08 08 08 08 17 8d 12 30 20 38 33 35 00 01 30 ........0 835..0
+| 3264: 12 01 06 00 01 06 00 01 06 00 1e f3 00 01 03 00 ................
+| 3280: 01 03 00 00 08 32 30 31 36 30 36 30 39 09 01 07 .....20160609...
+| 3296: 00 01 07 00 01 07 00 00 01 34 09 01 05 00 01 05 .........4......
+| 3312: 00 01 05 00 00 01 35 09 01 04 00 01 04 00 01 04 ......5.........
+| 3328: 00 01 07 30 30 30 30 2f 30 30 09 1c 04 00 01 04 ...0000/00......
+| 3344: 00 01 04 00 00 06 62 69 6e 61 72 79 3c 03 01 02 ......binary<...
+| 3360: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................
+| 3376: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................
+| 3392: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 ................
+| 3408: 01 02 02 00 03 01 02 02 00 00 08 63 6f 6d 70 69 ...........compi
+| 3424: 6c 65 72 09 01 02 00 01 02 00 01 02 00 00 06 64 ler............d
+| 3440: 62 73 74 61 74 09 07 03 00 01 03 00 01 03 00 01 bstat...........
+| 3456: 04 65 62 75 67 09 04 02 00 01 02 00 01 02 00 00 .ebug...........
+| 3472: 06 65 6e 61 62 6c 65 3f 07 02 00 01 02 00 01 02 .enable?........
+| 3488: 00 01 02 00 01 02 00 01 01 f0 01 02 00 57 02 00 .............W..
+| 3504: 01 02 00 01 02 00 01 02 00 01 02 00 01 02 10 01 ................
+| 3520: 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 ................
+| 3536: 00 00 02 00 01 02 00 01 08 78 74 65 6e 73 69 6f .........xtensio
+| 3552: 6e 09 1f 04 00 01 04 00 01 04 00 00 04 66 74 73 n............fts
+| 3568: 34 09 0a 03 00 01 03 00 01 03 00 03 01 35 09 0d 4............5..
+| 3584: 03 00 01 03 00 a9 03 00 00 03 67 63 63 09 01 03 ..........gcc...
+| 3600: 00 01 03 00 01 03 00 01 06 65 6f 70 6f 6c 79 09 .........eopoly.
+| 3616: 10 03 00 01 03 00 01 03 00 00 05 6a 73 6f 6e 31 ...........json1
+| 3632: 09 13 03 00 01 03 00 01 03 00 00 04 6c 6f 61 64 ............load
+| 3648: 09 1f 03 00 01 03 00 01 03 00 00 03 6d 61 78 09 ............max.
+| 3664: 1c 02 0b 31 02 00 01 02 00 01 05 65 6d 6f 72 79 ...1.......emory
+| 3680: 09 1c 03 00 01 03 00 01 03 00 03 04 73 79 73 35 ............sys5
+| 3696: 09 16 03 00 01 03 00 01 03 00 00 06 6e 6f 63 61 ............noca
+| 3712: 73 65 3c 02 01 02 02 00 03 01 02 02 00 03 01 02 se<.............
+| 3728: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................
+| 3744: 00 03 01 02 02 00 f3 01 02 02 00 03 01 02 02 00 ................
+| 3760: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 00 ................
+| 3776: 04 6f 6d 69 74 09 1f 02 00 01 02 00 01 02 00 00 .omit...........
+| 3792: 05 72 74 72 65 65 09 19 03 00 01 03 00 01 03 00 .rtree..........
+| 3808: 03 02 69 6d 3c 01 01 02 02 00 03 01 02 02 00 03 ..im<...........
+| 3824: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 ................
+| 3840: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 ................
+| 3856: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................
+| 3872: 00 00 0a 74 68 72 65 61 64 63 61 66 65 09 22 02 ...threadcafe...
+| 3888: 00 01 02 00 02 02 00 00 04 76 74 61 62 09 07 04 .........vtab...
+| 3904: 00 01 04 00 01 04 00 00 01 78 b4 01 01 01 01 02 .........x......
+| 3920: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................
+| 3936: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................
+| 3952: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................
+| 3968: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................
+| 3984: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................
+| 4000: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................
+| 4016: 01 01 01 02 00 01 01 01 02 00 01 00 01 02 00 01 ................
+| 4032: 01 01 02 00 01 01 00 e2 00 01 01 01 02 00 01 01 ................
+| 4048: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................
+| 4064: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................
+| 4080: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................
+| page 6 offset 20480
+| 0: 0a 00 00 00 02 0f f5 00 0f fb 0f f5 00 00 00 00 ................
+| 4080: 00 00 00 00 00 05 04 08 09 01 02 04 04 08 08 09 ................
+| page 7 offset 24576
+| 0: 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
+| 4016: 00 00 00 00 00 00 00 00 0d 05 02 23 61 00 00 00 ...........#a...
+| end crash-26682721375870.db
+}]} {}
+
+do_execsql_test 26.1 {
+ SELECT count(*) FROM (
+ SELECT t1, (t1) FROM t1 WHERE b MATCH 'x'
+ )
+} 34
finish_test
ADDED test/fts3corrupt5.test
Index: test/fts3corrupt5.test
==================================================================
--- /dev/null
+++ test/fts3corrupt5.test
@@ -0,0 +1,60 @@
+# 2019 May 22
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you do good and not evil.
+# May you find forgiveness for yourself and forgive others.
+# May you share freely, never taking more than you give.
+#
+#*************************************************************************
+#
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+source $testdir/fts3_common.tcl
+set testprefix fts3corrupt5
+
+# If SQLITE_ENABLE_FTS3 is defined, omit this file.
+ifcapable !fts3 {
+ finish_test
+ return
+}
+
+sqlite3_fts3_may_be_corrupt 1
+
+do_execsql_test 1.0 {
+ BEGIN;
+ CREATE VIRTUAL TABLE ft USING fts3(a, b, c);
+ INSERT INTO ft VALUES('one', 'one', 'one');
+ COMMIT;
+}
+
+do_execsql_test 1.1 {
+ SELECT * FROM ft WHERE ft MATCH 'b:one'
+} {one one one}
+
+do_execsql_test 1.2 {
+ SELECT quote(root) FROM ft_segdir;
+} {X'00036F6E6509010201010201020200'}
+
+breakpoint
+foreach {tn val q bCorrupt} {
+ 1 X'00036F6E650901' 'b:one' 1
+ 2 X'00036F6E6509010201010201FFFFFF' 'c:one' 1
+ 3 X'00036F6E6501' 'b:one' 1
+ 4 X'00036F6E650101' 'b:one' 1
+ 5 X'00036F6E650100' 'b:one' 0
+} {
+ do_execsql_test 1.3.$tn.1 "UPDATE ft_segdir SET root = $val"
+
+ set res {0 {}}
+ if {$bCorrupt} { set res {1 {database disk image is malformed}}}
+ do_catchsql_test 1.3.$tn.2 {
+ SELECT * FROM ft WHERE ft MATCH $q
+ } $res
+}
+
+finish_test
+
Index: test/fuzzdata7.db
==================================================================
--- test/fuzzdata7.db
+++ test/fuzzdata7.db
cannot compute difference between binary files
Index: test/fuzzdata8.db
==================================================================
--- test/fuzzdata8.db
+++ test/fuzzdata8.db
cannot compute difference between binary files
Index: test/index7.test
==================================================================
--- test/index7.test
+++ test/index7.test
@@ -324,8 +324,20 @@
} {SEARCH TABLE t4 USING INDEX i4 (c=?)}
do_catchsql_test index7-6.5 {
CREATE INDEX t5a ON t5(a) WHERE a=#1;
} {1 {near "#1": syntax error}}
+
+do_execsql_test index7-7.0 {
+ CREATE TABLE t6(x, y);
+ INSERT INTO t6 VALUES(1, 1);
+ INSERT INTO t6 VALUES(0, 0);
+ SELECT * FROM t6 WHERE y IS TRUE ORDER BY x;
+} {1 1}
+
+do_execsql_test index7-7.1 {
+ CREATE INDEX i6 ON t6(x) WHERE y IS NOT TRUE;
+ SELECT * FROM t6 WHERE y IS TRUE ORDER BY x;
+} {1 1}
finish_test
Index: test/indexexpr2.test
==================================================================
--- test/indexexpr2.test
+++ test/indexexpr2.test
@@ -275,8 +275,26 @@
SELECT a, b FROM x1 WHERE CAST(b AS TEXT) = 123;
} {1 123 2 123}
do_eqp_test 6.2.3 {
SELECT a, b FROM x1 WHERE CAST(b AS TEXT) = 123;
} {SEARCH TABLE x1 USING INDEX x1i2 (=?)}
+
+do_execsql_test 7.0 {
+ CREATE TABLE IF NOT EXISTS t0(c0);
+ INSERT INTO t0(c0) VALUES (-9223372036854775808);
+ BEGIN;
+}
+do_catchsql_test 7.1 {
+ CREATE INDEX i0 ON t0(ABS(c0));
+} {1 {integer overflow}}
+do_execsql_test 7.2 {
+ COMMIT;
+ SELECT sql FROM sqlite_master WHERE tbl_name = 't0';
+ CREATE INDEX i0 ON t0(c0);
+} {{CREATE TABLE t0(c0)}}
+do_execsql_test 7.3 {
+ REINDEX;
+} {}
+
finish_test
Index: test/intreal.test
==================================================================
--- test/intreal.test
+++ test/intreal.test
@@ -44,9 +44,43 @@
do_execsql_test 180 {
SELECT max(1.0,intreal(5),intreal(3),4.0),
max(1,intreal(5),intreal(3),4);
} {5.0 5.0}
+#-------------------------------------------------------------------------
+do_execsql_test 2.1 {
+ CREATE TABLE t2(a REAL);
+ INSERT INTO t2 VALUES( 836627109860825358 );
+ SELECT substr(a,1,4) FROM t2 WHERE a = CAST(836627109860825358 AS REAL);
+} {8.36}
+
+do_execsql_test 2.2 {
+ CREATE INDEX i2 ON t2(a);
+ SELECT substr(a,1,4) FROM t2 WHERE a = CAST(836627109860825358 AS REAL);
+} {8.36}
+
+do_execsql_test 2.3 {
+ CREATE TABLE t0 (c0);
+ CREATE TABLE t1 (c1 REAL);
+ INSERT INTO t1(c1) VALUES (8366271098608253588);
+ INSERT INTO t0(c0) VALUES ('a');
+}
+set D [db one {SELECT c1 FROM t1}]
+
+do_execsql_test 2.4 {
+ SELECT * FROM t1 WHERE (t1.c1 = CAST(8366271098608253588 AS REAL));
+} $D
+
+do_execsql_test 2.5 {
+ SELECT * FROM t0, t1 WHERE (t1.c1 = CAST(8366271098608253588 AS REAL));
+} [list a $D]
+do_execsql_test 2.6 {
+ SELECT * FROM t0, t1
+ WHERE (
+ t1.c1 >= CAST(8366271098608253588 AS REAL)
+ AND t1.c1 <= CAST(8366271098608253588 AS REAL)
+ );
+} [list a $D]
finish_test
Index: test/join5.test
==================================================================
--- test/join5.test
+++ test/join5.test
@@ -303,7 +303,28 @@
} {
QUERY PLAN
|--SCAN TABLE t3
`--SEARCH TABLE t4 USING INDEX t4xz (x=?)
}
+
+reset_db
+do_execsql_test 8.0 {
+ CREATE TABLE t0 (c0, c1, PRIMARY KEY (c0, c1));
+ CREATE TABLE t1 (c0);
+
+ INSERT INTO t1 VALUES (2);
+
+ INSERT INTO t0 VALUES(0, 10);
+ INSERT INTO t0 VALUES(1, 10);
+ INSERT INTO t0 VALUES(2, 10);
+ INSERT INTO t0 VALUES(3, 10);
+}
+
+do_execsql_test 8.1 {
+ SELECT * FROM t0, t1
+ WHERE (t0.c1 >= 1 OR t0.c1 < 1) AND t0.c0 IN (1, t1.c0) ORDER BY 1;
+} {
+ 1 10 2
+ 2 10 2
+}
finish_test
Index: test/jrnlmode.test
==================================================================
--- test/jrnlmode.test
+++ test/jrnlmode.test
@@ -63,11 +63,20 @@
PRAGMA journal_mode;
PRAGMA main.journal_mode;
PRAGMA temp.journal_mode;
}
} [list persist persist [temp_journal_mode persist]]
-do_test jrnlmode-1.4 {
+do_test jrnlmode-1.4a {
+ # When defensive is on, unable to set journal_mode to OFF
+ sqlite3_db_config db DEFENSIVE 1
+ execsql {
+ PRAGMA journal_mode = off;
+ }
+} {persist}
+do_test jrnlmode-1.4b {
+ # When defensive is on, unable to set journal_mode to OFF
+ sqlite3_db_config db DEFENSIVE 0
execsql {
PRAGMA journal_mode = off;
}
} {off}
do_test jrnlmode-1.5 {
Index: test/pragma4.test
==================================================================
--- test/pragma4.test
+++ test/pragma4.test
@@ -246,7 +246,17 @@
} {}
do_execsql_test 4.6.4 { pragma foreign_key_check('c1') } {c1 1 t1 0}
do_catchsql_test 4.6.5 {
pragma foreign_key_check('c2')
} {1 {no such table: c2}}
+
+do_execsql_test 5.0 {
+ CREATE TABLE t4(a DEFAULT 'abc' /* comment */, b DEFAULT -1 -- comment
+ , c DEFAULT +4.0 /* another comment */
+ );
+ PRAGMA table_info = t4;
+} {
+ 0 a {} 0 'abc' 0 1 b {} 0 -1 0 2 c {} 0 +4.0 0
+}
+
finish_test
Index: test/quote.test
==================================================================
--- test/quote.test
+++ test/quote.test
@@ -14,10 +14,11 @@
#
# $Id: quote.test,v 1.7 2007/04/25 11:32:30 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
+set testprefix quote
# Create a table with a strange name and with strange column names.
#
do_test quote-1.0 {
catchsql {CREATE TABLE '@abc' ( '#xyz' int, '!pqr' text );}
@@ -82,8 +83,60 @@
set r [catch {
execsql {DROP TABLE '@abc'}
} msg ]
lappend r $msg
} {0 {}}
-
+
+#-------------------------------------------------------------------------
+# Check that it is not possible to use double-quotes for a string
+# constant in a CHECK constraint or CREATE INDEX statement. However,
+# SQLite can load such a schema from disk.
+#
+reset_db
+do_execsql_test 2.0 {
+ CREATE TABLE t1(x, y, z);
+}
+foreach {tn sql errname} {
+ 1 { CREATE TABLE xyz(a, b, c CHECK (c!="null") ) } null
+ 2 { CREATE INDEX i2 ON t1(x, y, z||"abc") } abc
+ 3 { CREATE INDEX i3 ON t1("w") } w
+ 4 { CREATE INDEX i4 ON t1(x) WHERE z="w" } w
+} {
+ do_catchsql_test 2.1.$tn $sql [list 1 "no such column: $errname"]
+}
+
+do_execsql_test 2.2 {
+ PRAGMA writable_schema = 1;
+ CREATE TABLE xyz(a, b, c CHECK (c!="null") );
+ CREATE INDEX i2 ON t1(x, y, z||"abc");
+ CREATE INDEX i3 ON t1("w");
+ CREATE INDEX i4 ON t1(x) WHERE z="w";
+}
+
+db close
+sqlite3 db test.db
+
+do_execsql_test 2.3.1 {
+ INSERT INTO xyz VALUES(1, 2, 3);
+}
+do_catchsql_test 2.3.2 {
+ INSERT INTO xyz VALUES(1, 2, 'null');
+} {1 {CHECK constraint failed: xyz}}
+
+do_execsql_test 2.4 {
+ INSERT INTO t1 VALUES(1, 2, 3);
+ INSERT INTO t1 VALUES(4, 5, 'w');
+ SELECT * FROM t1 WHERE z='w';
+} {4 5 w}
+do_execsql_test 2.5 {
+ SELECT sql FROM sqlite_master;
+} {
+ {CREATE TABLE t1(x, y, z)}
+ {CREATE TABLE xyz(a, b, c CHECK (c!="null") )}
+ {CREATE INDEX i2 ON t1(x, y, z||"abc")}
+ {CREATE INDEX i3 ON t1("w")}
+ {CREATE INDEX i4 ON t1(x) WHERE z="w"}
+}
+
+
finish_test
Index: test/view.test
==================================================================
--- test/view.test
+++ test/view.test
@@ -709,10 +709,18 @@
INSERT INTO t16 VALUES(3, 3, 3);
CREATE VIEW v16 AS SELECT max(a) AS mx, min(b) AS mn FROM t16 GROUP BY c;
SELECT * FROM v16 AS one, v16 AS two WHERE one.mx=1;
} {
+ 1 1 1 1
+ 1 1 2 2
+ 1 1 3 3
+}
+do_execsql_test view-26.1 {
+ WITH v17(x,y) AS (SELECT max(a), min(b) FROM t16 GROUP BY c)
+ SELECT * FROM v17 AS one, v17 AS two WHERE one.x=1;
+} {
1 1 1 1
1 1 2 2
1 1 3 3
}
Index: test/with1.test
==================================================================
--- test/with1.test
+++ test/with1.test
@@ -1088,7 +1088,56 @@
)
SELECT 3 FROM c,c,c,c,c,c,c,c,c
)
SELECT 4 FROM c,c,c,c,c,c,c,c,c;
} {1 {too many FROM clause terms, max: 200}}
+
+# 2019-05-22
+# ticket https://www.sqlite.org/src/tktview/ce823231949d3abf42453c8f20
+#
+sqlite3 db :memory:
+do_execsql_test 23.1 {
+ CREATE TABLE t1(id INTEGER NULL PRIMARY KEY, name Text);
+ INSERT INTO t1 VALUES (1, 'john');
+ INSERT INTO t1 VALUES (2, 'james');
+ INSERT INTO t1 VALUES (3, 'jingle');
+ INSERT INTO t1 VALUES (4, 'himer');
+ INSERT INTO t1 VALUES (5, 'smith');
+ CREATE VIEW v2 AS
+ WITH t4(Name) AS (VALUES ('A'), ('B'))
+ SELECT Name Name FROM t4;
+ CREATE VIEW v3 AS
+ WITH t4(Att, Val, Act) AS (VALUES
+ ('C', 'D', 'E'),
+ ('F', 'G', 'H')
+ )
+ SELECT D.Id Id, P.Name Protocol, T.Att Att, T.Val Val, T.Act Act
+ FROM t1 D
+ CROSS JOIN v2 P
+ CROSS JOIN t4 T;
+ SELECT * FROM v3;
+} {1 A C D E 1 A F G H 1 B C D E 1 B F G H 2 A C D E 2 A F G H 2 B C D E 2 B F G H 3 A C D E 3 A F G H 3 B C D E 3 B F G H 4 A C D E 4 A F G H 4 B C D E 4 B F G H 5 A C D E 5 A F G H 5 B C D E 5 B F G H}
+
+#-------------------------------------------------------------------------
+reset_db
+do_execsql_test 24.1 {
+ CREATE TABLE t1(a, b, c);
+ CREATE VIEW v1 AS SELECT max(a), min(b) FROM t1 GROUP BY c;
+}
+do_test 24.1 {
+ set program [db eval {EXPLAIN SELECT 1 FROM v1,v1,v1}]
+ expr [lsearch $program OpenDup]>0
+} {1}
+do_execsql_test 24.2 {
+ ATTACH "" AS aux;
+ CREATE VIEW aux.v3 AS VALUES(1);
+ CREATE VIEW main.v3 AS VALUES(3);
+
+ CREATE VIEW aux.v2 AS SELECT * FROM v3;
+ CREATE VIEW main.v2 AS SELECT * FROM v3;
+
+ SELECT * FROM main.v2 AS a, aux.v2 AS b, aux.v2 AS c, main.v2 AS d;
+} {
+ 3 1 1 3
+}
finish_test
Index: tool/mkpragmatab.tcl
==================================================================
--- tool/mkpragmatab.tcl
+++ tool/mkpragmatab.tcl
@@ -379,16 +379,16 @@
TYPE: KEY
ARG: 1
IF: defined(SQLITE_HAS_CODEC)
NAME: hexkey
- TYPE: HEXKEY
+ TYPE: KEY
ARG: 2
IF: defined(SQLITE_HAS_CODEC)
NAME: hexrekey
- TYPE: HEXKEY
+ TYPE: KEY
ARG: 3
IF: defined(SQLITE_HAS_CODEC)
NAME: textkey
TYPE: KEY