/ Check-in [ff9f3e0951]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Merge recent enhancements from trunk.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | reuse-schema
Files: files | file ages | folders
SHA3-256: ff9f3e09510b4418cb166fa2557598a279e7baedc315a5d1c3ae63beb92c238d
User & Date: drh 2019-05-24 13:04:56
Wiki:reuse-schema
Context
2019-05-24
13:15
The ".shared-schema" command in the CLI requires the sqlite_dbpage table, so disable it if the build does not include that extension. check-in: 0913ff4dc3 user: drh tags: reuse-schema
13:04
Merge recent enhancements from trunk. check-in: ff9f3e0951 user: drh tags: reuse-schema
11:55
Fix an fts5 segfault that could occur after parsing a corrupt structure record. check-in: 600daa9c27 user: dan tags: trunk
2019-05-14
22:25
Merge all the latest trunk enhancements into the reuse-schema branch. check-in: 018f3199b9 user: drh tags: reuse-schema
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to README.md.

   302    302   
   303    303   There are many other source files.  Each has a succinct header comment that
   304    304   describes its purpose and role within the larger system.
   305    305   
   306    306   <a name="vauth"></a>
   307    307   ## Verifying Code Authenticity
   308    308   
   309         -If you obtained an SQLite source tree from a secondary source, such as a
   310         -GitHub mirror, and you want to verify that it has not been altered, there
   311         -are a couple of ways to do that.
   312         -
   313         -If you have a release version of SQLite, and you are using the
   314         -`sqlite3.c` amalgamation, then SHA3-256 hashes for the amalgamation are
   315         -available in the [change log](https://www.sqlite.org/changes.html) on
   316         -the official website.  After building the `sqlite3.c` file, you can check
   317         -that it is authentic by comparing the hash.  This does not ensure that the
   318         -test scripts are unaltered, but it does validate the deliverable part of
   319         -the code and the verification process only involves computing and
   320         -comparing a single hash.
   321         -
   322         -For versions other than an official release, or if you are building the
   323         -`sqlite3.c` amalgamation using non-standard build options, the verification
   324         -process is a little more involved.  The `manifest` file at the root directory
   325         -of the source tree
          309  +The `manifest` file at the root directory of the source tree
   326    310   contains either a SHA3-256 hash (for newer files) or a SHA1 hash (for 
   327         -older files) for every source file in the repository.  You can write a script
   328         -to extracts hashes from `manifest` and verifies the hashes against the 
   329         -corresponding files in the source tree.  The SHA3-256 hash of the `manifest`
          311  +older files) for every source file in the repository.
          312  +The SHA3-256 hash of the `manifest`
   330    313   file itself is the official name of the version of the source tree that you
   331         -have.  The `manifest.uuid` file should contain the SHA3-256 hash of the
   332         -`manifest` file.  If all of the above hash comparisons are correct, then
          314  +have. The `manifest.uuid` file should contain the SHA3-256 hash of the
          315  +`manifest` file. If all of the above hash comparisons are correct, then
   333    316   you can be confident that your source tree is authentic and unadulterated.
   334    317   
   335    318   The format of the `manifest` file should be mostly self-explanatory, but
   336    319   if you want details, they are available
   337    320   [here](https://fossil-scm.org/fossil/doc/trunk/www/fileformat.wiki#manifest).
   338    321   
   339    322   ## Contacts
   340    323   
   341    324   The main SQLite website is [http://www.sqlite.org/](http://www.sqlite.org/)
   342    325   with geographically distributed backups at
   343    326   [http://www2.sqlite.org/](http://www2.sqlite.org) and
   344    327   [http://www3.sqlite.org/](http://www3.sqlite.org).

Changes to ext/fts3/fts3_write.c.

  2615   2615       if( iCol==iCurrent ){
  2616   2616         nList = (int)(p - pList);
  2617   2617         break;
  2618   2618       }
  2619   2619   
  2620   2620       nList -= (int)(p - pList);
  2621   2621       pList = p;
  2622         -    if( nList==0 ){
         2622  +    if( nList<=0 ){
  2623   2623         break;
  2624   2624       }
  2625   2625       p = &pList[1];
  2626   2626       p += fts3GetVarint32(p, &iCurrent);
  2627   2627     }
  2628   2628   
  2629         -  if( bZero && &pList[nList]!=pEnd ){
         2629  +  if( bZero && (pEnd - &pList[nList])>0){
  2630   2630       memset(&pList[nList], 0, pEnd - &pList[nList]);
  2631   2631     }
  2632   2632     *ppList = pList;
  2633   2633     *pnList = nList;
  2634   2634   }
  2635   2635   
  2636   2636   /*

Changes to ext/fts5/fts5_index.c.

   988    988     Fts5Data *pData;
   989    989   
   990    990     pData = fts5DataRead(p, FTS5_STRUCTURE_ROWID);
   991    991     if( p->rc==SQLITE_OK ){
   992    992       /* TODO: Do we need this if the leaf-index is appended? Probably... */
   993    993       memset(&pData->p[pData->nn], 0, FTS5_DATA_PADDING);
   994    994       p->rc = fts5StructureDecode(pData->p, pData->nn, &iCookie, &pRet);
   995         -    if( p->rc==SQLITE_OK && pConfig->iCookie!=iCookie ){
          995  +    if( p->rc==SQLITE_OK && (pConfig->pgsz==0 || pConfig->iCookie!=iCookie) ){
   996    996         p->rc = sqlite3Fts5ConfigLoad(pConfig, iCookie);
   997    997       }
   998    998       fts5DataRelease(pData);
   999    999       if( p->rc!=SQLITE_OK ){
  1000   1000         fts5StructureRelease(pRet);
  1001   1001         pRet = 0;
  1002   1002       }

Changes to ext/fts5/test/fts5corrupt3.test.

  4664   4664   do_execsql_test 38.1 {
  4665   4665     SELECT * FROM t1('a b') ORDER BY rank;
  4666   4666   } {a b a b}
  4667   4667   
  4668   4668   do_execsql_test 38.2 {
  4669   4669     UPDATE t1_data SET block = X'000202' WHERE rowid=1;
  4670   4670   }
  4671         -breakpoint
  4672   4671   do_catchsql_test 38.3 {
  4673   4672     SELECT * FROM t1('a b') ORDER BY rank;
  4674   4673   } {1 {database disk image is malformed}}
  4675   4674   
  4676   4675   db close
  4677   4676   sqlite3 db test.db
  4678   4677   do_catchsql_test 38.4 {
................................................................................
  8949   8948   | end crash-e5fa281edabddf.db
  8950   8949   }]} {}
  8951   8950   
  8952   8951   do_execsql_test 61.1 {
  8953   8952     CREATE VIRTUAL TABLE t3 USING fts5vocab('t1'(),'col' );
  8954   8953   } 
  8955   8954   
  8956         -do_catchsql_test 62.2 {
         8955  +do_catchsql_test 61.2 {
  8957   8956     SELECT * FROM t3 ORDER BY rowid;
  8958   8957   } {1 {database disk image is malformed}}
  8959   8958   
         8959  +breakpoint
         8960  +#-------------------------------------------------------------------------
         8961  +do_test 62.0 {
         8962  +  sqlite3 db {}
         8963  +  db deserialize [decode_hexdb {
         8964  +.open --hexdb
         8965  +| size 28672 pagesize 4096 filename crash-44942694542e1e.db
         8966  +| page 1 offset 0
         8967  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         8968  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 00   .....@  ........
         8969  +|     96: 00 00 00 00 0d 0f c7 00 07 0d 92 00 0f 8d 0f 36   ...............6
         8970  +|    112: 0e cb 0e 6b 0e 0e 0d b6 0d 92 00 00 00 00 00 00   ...k............
         8971  +|   3472: 00 00 22 08 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
         8972  +|   3488: 32 74 32 08 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
         8973  +|   3504: 20 74 32 28 78 29 56 07 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
         8974  +|   3520: 62 6c 65 74 31 5f 63 6f 6e 66 79 67 74 31 5f 63   blet1_confygt1_c
         8975  +|   3536: 6f 6e 66 69 67 07 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
         8976  +|   3552: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
         8977  +|   3568: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
         8978  +|   3584: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 06    WITHOUT ROWID[.
         8979  +|   3600: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
         8980  +|   3616: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
         8981  +|   3632: 06 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
         8982  +|   3648: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
         8983  +|   3664: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
         8984  +|   3680: 59 2c 20 73 7a 20 52 4c 4f 42 29 5e 05 07 17 21   Y, sz RLOB)^...!
         8985  +|   3696: 21 01 81 07 74 61 62 6c 65 74 31 5f 63 6f 6e 74   !...tablet1_cont
         8986  +|   3712: 65 6e 74 74 35 ff 63 6f 6e 74 65 6e 74 05 43 52   entt5.content.CR
         8987  +|   3728: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63   EATE TABLE 't1_c
         8988  +|   3744: 6f 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47   ontent'(id INTEG
         8989  +|   3760: 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20   ER PRIMARY KEY, 
         8990  +|   3776: 63 30 2c 20 63 31 2c 20 63 42 29 69 04 07 17 19   c0, c1, cB)i....
         8991  +|   3792: 19 01 81 2d 74 61 62 6c 65 74 31 5f 69 64 78 74   ...-tablet1_idxt
         8992  +|   3808: 31 5f 79 64 78 04 43 52 45 41 54 45 20 54 41 42   1_ydx.CREATE TAB
         8993  +|   3824: 4c 45 20 27 74 31 5f 69 64 78 27 28 73 65 67 69   LE 't1_idx'(segi
         8994  +|   3840: 64 2c 20 74 65 72 6d 2c 20 70 67 6e 6f 2c 20 50   d, term, pgno, P
         8995  +|   3856: 52 49 4d 41 52 59 20 4b 45 59 28 73 65 67 69 64   RIMARY KEY(segid
         8996  +|   3872: 2c 20 74 65 72 6d 29 29 20 57 49 54 48 4f 55 54   , term)) WITHOUT
         8997  +|   3888: 20 52 4f 57 49 44 55 03 07 17 1b 1b 01 81 01 74    ROWIDU........t
         8998  +|   3904: 61 62 6c 65 74 31 5f 64 61 74 61 74 31 5f 74 61   ablet1_datat1_ta
         8999  +|   3920: 74 61 03 43 52 45 41 54 45 20 54 41 42 4c 45 20   ta.CREATE TABLE 
         9000  +|   3936: 27 74 31 5f 64 61 74 61 27 28 69 64 20 49 4e 54   't1_data'(id INT
         9001  +|   3952: 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59   EGER PRIMARY KEY
         9002  +|   3968: 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 29 38 02 06   , block BLOB)8..
         9003  +|   3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52   ...._tablet1t1CR
         9004  +|   4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42   EATE VIRTUAL TAB
         9005  +|   4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 35   LE t1 USING fts5
         9006  +|   4032: 28 61 2c 62 2c 63 29 00 00 00 00 00 00 00 00 00   (a,b,c).........
         9007  +| page 3 offset 8192
         9008  +|      0: 0d 00 00 00 03 0c 94 00 0f e6 0f ef 0c 94 00 00   ................
         9009  +|   3216: 00 00 00 00 86 4a 84 80 80 80 80 01 04 00 8d 18   .....J..........
         9010  +|   3232: 00 00 03 2b 02 30 30 01 02 06 01 02 06 01 02 06   ...+.00.........
         9011  +|   3248: 2f 02 03 01 02 03 01 02 03 01 08 32 30 31 36 30   /..........20160
         9012  +|   3264: 36 30 39 01 02 07 01 02 07 01 02 07 01 01 34 01   609...........4.
         9013  +|   3280: 02 05 01 02 c7 01 02 05 01 01 35 01 02 04 01 02   ..........5.....
         9014  +|   3296: 04 01 02 04 02 07 30 30 30 30 30 30 30 1c 02 04   ......0000000...
         9015  +|   3312: 01 02 04 01 02 04 01 06 62 69 6e 61 72 79 03 06   ........binary..
         9016  +|   3328: 01 02 02 04 16 01 02 02 03 06 01 02 02 02 06 01   ................
         9017  +|   3344: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02   ................
         9018  +|   3360: 02 03 06 01 02 02 03 06 01 02 02 02 06 01 02 02   ................
         9019  +|   3376: 03 06 01 02 02 03 06 01 02 02 01 08 63 6f 6d 70   ............comp
         9020  +|   3392: 69 6c 65 72 01 02 02 01 02 02 01 02 02 01 06 64   iler...........d
         9021  +|   3408: 62 73 74 61 74 07 02 03 00 02 03 01 02 03 02 04   bstat...........
         9022  +|   3424: 65 62 74 67 04 02 02 01 02 02 01 02 02 01 06 65   ebtg...........e
         9023  +|   3440: 6e 61 62 6c 65 07 02 02 01 02 02 01 02 02 01 02   nable...........
         9024  +|   3456: 02 01 02 02 01 02 02 01 02 02 01 02 01 f1 02 02   ................
         9025  +|   3472: 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01   ................
         9026  +|   3488: 02 02 01 02 02 45 02 02 01 02 02 01 02 02 01 02   .....E..........
         9027  +|   3504: 02 01 02 02 02 08 78 74 65 6e 73 69 6f 6e 1f 02   ......xtension..
         9028  +|   3520: 04 01 02 09 c1 02 04 01 04 66 74 73 34 0a 02 03   .........fts4...
         9029  +|   3536: 01 02 03 01 02 03 04 00 35 0d 02 03 01 02 04 01   ........5.......
         9030  +|   3552: 02 03 01 0f d7 63 63 01 02 03 01 02 03 01 02 03   .....cc.........
         9031  +|   3568: 02 06 65 6f 70 6f 6b 79 10 02 03 01 02 03 01 02   ..eopoky........
         9032  +|   3584: 03 01 05 6a 73 6f 6e 31 13 02 03 14 02 03 01 02   ...json1........
         9033  +|   3600: 03 01 04 6c 6f 61 64 1f 02 03 01 02 03 01 02 03   ...load.........
         9034  +|   3616: 01 03 6d 61 78 1c 02 02 01 02 02 01 02 02 02 05   ..max...........
         9035  +|   3632: 65 6d 6f 72 79 1c 02 03 01 02 03 01 02 03 04 04   emory...........
         9036  +|   3648: 73 79 73 35 16 02 03 01 02 03 01 02 03 01 06 6e   sys5...........n
         9037  +|   3664: 6f 63 61 73 65 02 06 01 02 12 03 06 01 02 02 03   ocase...........
         9038  +|   3680: 06 01 02 02 03 06 01 02 02 09 f6 01 02 02 03 06   ................
         9039  +|   3696: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01   ................
         9040  +|   3712: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 11 02   ................
         9041  +|   3728: 02 01 04 6f 7d 69 74 1f 02 02 01 02 02 01 02 02   ...o.it.........
         9042  +|   3744: 01 05 72 74 72 65 65 19 02 03 01 02 03 01 02 03   ..rtree.........
         9043  +|   3760: 04 02 69 6d 01 06 01 02 02 03 06 01 02 02 03 06   ..im............
         9044  +|   3776: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01   ................
         9045  +|   3792: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 11 02   ................
         9046  +|   3808: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02   ................
         9047  +|   3824: 00 fa 74 68 72 65 61 64 73 61 66 65 22 02 02 01   ..threadsafe....
         9048  +|   3840: 02 02 01 02 02 01 04 76 74 61 62 07 03 04 01 40   .......vtab....@
         9049  +|   3856: 04 01 02 04 11 01 78 01 06 01 01 02 01 06 01 01   ......x.........
         9050  +|   3872: 02 01 06 01 00 02 01 06 01 01 02 01 03 91 01 02   ................
         9051  +|   3888: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01   ................
         9052  +|   3904: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06   ................
         9053  +|   3920: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01   ................
         9054  +|   3936: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01   ................
         9055  +|   3952: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02   ................
         9056  +|   3968: 01 06 01 01 02 01 76 01 01 02 01 06 01 01 02 5c   ......v.........
         9057  +|   3984: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 11 06   ................
         9058  +|   4000: 01 02 02 01 06 08 11 02 01 06 01 01 02 01 06 01   ................
         9059  +|   4016: 01 02 01 06 01 01 02 01 06 01 01 02 01 05 01 01   ................
         9060  +|   4032: 02 01 06 01 01 02 01 06 01 01 02 04 15 13 0c 0c   ................
         9061  +|   4048: 12 44 13 11 0f 47 13 0f 0c 0e 11 10 ca 0e 10 0f   .D...G..........
         9062  +|   4064: 44 0f 10 40 15 0f 07 01 03 00 14 24 5a 14 24 0f   D..@.......$Z.$.
         9063  +|   4080: 0a 03 00 24 ff ff ff ff 01 01 02 00 01 01 01 01   ...$............
         9064  +| page 4 offset 12288
         9065  +|      0: 0a 00 00 00 01 0f fb 00 00 00 00 00 00 00 00 00   ................
         9066  +|   4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02   ................
         9067  +| page 5 offset 16384
         9068  +|      0: 0d 00 00 00 24 0c 09 00 00 00 00 00 00 00 00 00   ....$...........
         9069  +|   3072: 00 00 00 00 00 00 00 00 00 00 18 24 05 00 25 0f   ...........$..%.
         9070  +|   3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49   .THREADSAFE=0XBI
         9071  +|   3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41   NARY.#..%..THREA
         9072  +|   3120: 44 53 41 46 45 3d 30 58 4e 4f 43 41 53 47 17 22   DSAFE=0XNOCASG..
         9073  +|   3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 45 3d   ..%..THREADSAFE=
         9074  +|   3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d   0XRTRIM.!..3..OM
         9075  +|   3168: 49 54 20 4c 3f 41 44 20 45 58 54 45 4e 53 49 4f   IT L?AD EXTENSIO
         9076  +|   3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f   NXBINARY. ..3..O
         9077  +|   3200: 4d 49 64 20 4c 4f 41 44 20 45 58 54 45 d9 53 49   MId LOAD EXTE.SI
         9078  +|   3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17   ONXNOCASE....3..
         9079  +|   3232: 4f 4d 39 54 20 4c 4f 41 44 20 45 58 55 45 4e 53   OM9T LOAD EXUENS
         9080  +|   3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f 19   IONXRTRIM....3..
         9081  +|   3264: 4c 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 30   LAX MEMORY=50000
         9082  +|   3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f   000XBINARY....3.
         9083  +|   3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30   .MAX MEMORY=5000
         9084  +|   3312: 30 30 30 30 58 af 4f 43 41 53 45 1e 1c 05 00 33   0000X.OCASE....3
         9085  +|   3328: 0f 17 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30   ..MAX MEMORY=500
         9086  +|   3344: 30 30 ab 30 30 58 62 54 52 49 4d 18 1b 05 00 25   00.00XbTRIM....%
         9087  +|   3360: 0f 19 45 4e 41 42 4c 45 20 52 54 52 45 45 58 42   ..ENABLE RTREEXB
         9088  +|   3376: 49 4e 41 52 59 18 1b 05 00 25 0f 19 45 4e 41 42   INARY....%..ENAB
         9089  +|   3392: 4c 45 20 52 54 52 45 45 58 4e 4f 43 41 53 45 17   LE RTREEXNOCASE.
         9090  +|   3408: 19 05 00 25 0f 17 45 4e 41 42 4c 45 20 52 54 52   ...%..ENABLE RTR
         9091  +|   3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45   EEXRTRIM....)..E
         9092  +|   3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 63 35 58 42 49   NABLE MEMSYc5XBI
         9093  +|   3456: 4e 41 52 59 1a 17 04 00 29 0f 19 45 4e 41 42 4c   NARY....)..ENABL
         9094  +|   3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 53 45   E MEMSYS5XNOCASE
         9095  +|   3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 3d 45   ....)..ENABLE =E
         9096  +|   3504: 4d 53 59 53 35 58 52 54 52 49 4d 18 15 05 00 25   MSYS5XRTRIM....%
         9097  +|   3520: 0f 19 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 58 42   ..ENABLE JSON1XB
         9098  +|   3536: 49 4e 41 52 59 18 14 05 00 25 0f 19 45 4e 41 42   INARY....%..ENAB
         9099  +|   3552: 4c 46 20 4a 53 4f 4e 31 58 4e 4f 43 41 53 45 17   LF JSON1XNOCASE.
         9100  +|   3568: 13 05 00 25 0f 17 45 4e 41 42 4c 45 20 4a 53 4f   ...%..ENABLE JSO
         9101  +|   3584: 4e 31 58 52 54 52 49 4d 1a 12 05 00 29 0f 19 45   N1XRTRIM....)..E
         9102  +|   3600: 4e 41 42 4c 45 20 46 45 46 50 4f 4c 59 57 42 49   NABLE FEFPOLYWBI
         9103  +|   3616: 4e 41 52 59 18 11 05 00 29 0f 19 45 4e 41 42 4c   NARY....)..ENABL
         9104  +|   3632: 45 20 47 45 4f 50 4f 4c 59 58 4e 5f 43 41 53 45   E GEOPOLYXN_CASE
         9105  +|   3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 42   ....)..ENABLE GB
         9106  +|   3664: 2f 50 4f 4c 59 58 51 54 52 49 4d 17 0f 05 00 23   /POLYXQTRIM....#
         9107  +|   3680: 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 58 42 49   ..ENABLE FTS5XBI
         9108  +|   3696: 4e 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 4c   NARY....#..ENABL
         9109  +|   3712: 45 20 46 54 53 35 58 4e 4f 43 41 53 45 16 0d 05   E FTS5XNOCASE...
         9110  +|   3728: 00 23 0f 17 45 4e 41 42 4c 45 20 46 54 53 35 58   .#..ENABLE FTS5X
         9111  +|   3744: 52 54 52 49 4d 17 1c 05 00 23 0f 19 45 4e 41 42   RTRIM....#..ENAB
         9112  +|   3760: 4c 45 20 46 54 53 34 58 42 49 4e 41 52 59 16 0b   LE FTS4XBINARY..
         9113  +|   3776: 05 00 22 0f e9 45 4e 41 42 4c 35 20 46 54 53 34   .....ENABL5 FTS4
         9114  +|   3792: 58 4e 4f 43 41 53 45 16 0a 05 00 23 00 47 45 4e   XNOCASE....#.GEN
         9115  +|   3808: 41 42 4c 45 20 46 54 53 34 57 52 54 52 49 4d 1e   ABLE FTS4WRTRIM.
         9116  +|   3824: 60 05 00 31 0f 19 45 4e 41 42 4c 55 20 43 42 53   `..1..ENABLU CBS
         9117  +|   3840: 54 41 54 20 56 54 42 42 58 42 49 4e 41 52 59 1e   TAT VTBBXBINARY.
         9118  +|   3856: 08 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         9119  +|   3872: 54 40 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d   T@T VTABXNOCASE.
         9120  +|   3888: 07 05 00 31 0f 17 45 4e 41 42 4c 55 20 44 42 53   ...1..ENABLU DBS
         9121  +|   3904: 54 41 54 20 56 54 41 42 58 52 54 52 49 4d 12 06   TAT VTABXRTRIM..
         9122  +|   3920: 05 00 17 0f 19 44 45 42 55 47 58 42 49 4e 41 52   .....DEBUGXBINAR
         9123  +|   3936: 59 21 05 05 00 17 0f 19 44 45 42 55 47 58 4e 4f   Y!......DEBUGXNO
         9124  +|   3952: 43 41 53 45 10 04 05 00 17 0f 18 44 45 42 55 47   CASE.......DEBUG
         9125  +|   3968: 58 42 54 52 49 4d 27 11 05 00 43 0f 19 43 4f 4d   XBTRIM'...C..COM
         9126  +|   3984: 50 49 48 f5 52 3d 67 63 63 2d 35 2e 34 2e 30 20   PIH.R=gcc-5.4.0 
         9127  +|   4000: 32 30 31 36 30 36 30 39 58 42 49 4e 41 52 59 27   20160609XBINARY'
         9128  +|   4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67   ...C..COMPILER=g
         9129  +|   4032: 63 63 2d 35 2e 34 2e 30 22 32 30 31 36 30 36 30   cc-5.4.0.2016060
         9130  +|   4048: 39 c2 3e 4f 43 41 53 45 26 01 05 00 43 0f 17 43   9.>OCASE&...C..C
         9131  +|   4064: 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e   OMPILER=gcc-5.4.
         9132  +|   4080: 30 30 32 30 31 26 30 36 30 39 58 52 54 52 49 4d   00201&0609XRTRIM
         9133  +| page 6 offset 20480
         9134  +|      0: 0d 00 00 00 24 0e e0 00 00 00 00 00 00 00 00 00   ....$...........
         9135  +|   3808: 06 24 03 00 12 02 01 01 06 23 03 00 12 02 01 01   .$.......#......
         9136  +|   3824: 06 22 03 00 12 02 01 01 06 21 03 00 12 03 01 01   .........!......
         9137  +|   3840: 06 20 03 00 12 03 01 01 06 1f 03 00 12 03 01 01   . ..............
         9138  +|   3856: 06 1e 03 00 12 03 01 01 06 1d 03 00 12 03 01 01   ................
         9139  +|   3872: 06 1c 03 00 12 03 01 01 06 1b 03 00 12 02 01 01   ................
         9140  +|   3888: 06 1a 03 00 12 02 01 01 06 19 03 00 12 02 01 01   ................
         9141  +|   3904: 06 18 03 00 12 02 01 00 f6 17 03 00 19 e2 f9 01   ................
         9142  +|   3920: 06 16 03 00 12 02 05 01 06 15 03 00 12 02 01 01   ................
         9143  +|   3936: 06 14 03 00 12 02 01 01 06 13 03 00 12 02 01 01   ................
         9144  +|   3952: 06 12 03 00 12 02 01 01 06 11 03 00 12 02 01 01   ................
         9145  +|   3968: 06 10 03 10 12 02 01 01 06 0f 03 00 12 02 01 01   ................
         9146  +|   3984: 06 0e 03 00 12 02 01 01 06 0d 03 00 12 02 00 f1   ................
         9147  +|   4000: 06 0c 03 00 12 02 01 01 06 0b 03 00 12 02 01 01   ................
         9148  +|   4016: 06 0a 03 00 12 02 01 01 05 09 03 00 12 03 01 01   ................
         9149  +|   4032: 06 08 03 00 12 03 01 01 06 07 03 00 12 03 01 01   ................
         9150  +|   4048: 06 06 03 00 12 01 01 01 06 05 02 ff 84 01 01 01   ................
         9151  +|   4064: 06 04 03 00 12 01 01 01 06 03 03 00 12 06 01 01   ................
         9152  +|   4080: 07 02 03 00 12 06 01 01 06 01 03 00 12 06 01 01   ................
         9153  +| page 7 offset 24576
         9154  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         9155  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         9156  +| end crash-44942694542e1e.db
         9157  +}]} {}
         9158  +
         9159  +do_catchsql_test 62.1 {
         9160  +  WITH c(x) AS (VALUES(false) UNION ALL SELECT x+1 FROM c WHERE x<72)
         9161  +    INSERT INTO t1(a) SELECT randomblob(2829) FROM c;
         9162  +} {0 {}}
  8960   9163   
  8961   9164   sqlite3_fts5_may_be_corrupt 0
  8962   9165   finish_test
  8963   9166   

Added ext/fts5/test/fts5corrupt4.test.

            1  +# 2019 May 16
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +#
           12  +#
           13  +
           14  +source [file join [file dirname [info script]] fts5_common.tcl]
           15  +set testprefix fts5corrupt4
           16  +
           17  +# If SQLITE_ENABLE_FTS5 is defined, omit this file.
           18  +ifcapable !fts5 {
           19  +  finish_test
           20  +  return
           21  +}
           22  +sqlite3_fts5_may_be_corrupt 1
           23  +
           24  +do_execsql_test 1.0 {
           25  +  CREATE VIRTUAL TABLE ttt USING fts5(a, b); 
           26  +  INSERT INTO ttt 
           27  +     VALUES('e ee eee e ee eee e ee eee', 'eee ee e e e ee eee ee ee');
           28  +  INSERT INTO ttt SELECT a||a, b||b FROM ttt;   
           29  +  INSERT INTO ttt SELECT a||a, b||b FROM ttt;   
           30  +}
           31  +
           32  +proc mutate {blob i} {
           33  +  set o [expr {$i % [string length $blob]}]
           34  +  set a [string range $blob 0 $o-1]
           35  +  set b [string range $blob $o+1 end]
           36  +  set v [expr int(rand()*255) - 127]
           37  +  return "$a[binary format c $v]$b"
           38  +}
           39  +db func mutate mutate
           40  +
           41  +for {set j 1000} {$j <= 5000} {incr j 1000} {
           42  +  do_test 1.$j {
           43  +    for {set i 0} {$i < 1000} {incr i} {
           44  +      execsql {
           45  +        BEGIN;
           46  +          UPDATE ttt_data SET block = mutate(block, $i) WHERE id>10;
           47  +      }
           48  +      foreach sql {
           49  +        {SELECT snippet(ttt, -1, '.', '..', '[', ']'), * FROM ttt('e*')}
           50  +        {SELECT snippet(ttt, -1, '.', '..', '[', ']'), * FROM ttt('e* NOT ee*')}
           51  +      } {
           52  +        catch { execsql $sql }
           53  +      }
           54  +      execsql ROLLBACK
           55  +    }
           56  +  } {}
           57  +}
           58  +
           59  +sqlite3_fts5_may_be_corrupt 0
           60  +finish_test
           61  +

Changes to ext/session/sqlite3session.c.

  1620   1620               if( sqlite3_stricmp(azCol[i], pTo->azCol[i]) ) bMismatch = 1;
  1621   1621               if( abPK[i] ) bHasPk = 1;
  1622   1622             }
  1623   1623           }
  1624   1624         }
  1625   1625         sqlite3_free((char*)azCol);
  1626   1626         if( bMismatch ){
  1627         -        *pzErrMsg = sqlite3_mprintf("table schemas do not match");
         1627  +        if( pzErrMsg ){
         1628  +          *pzErrMsg = sqlite3_mprintf("table schemas do not match");
         1629  +        }
  1628   1630           rc = SQLITE_SCHEMA;
  1629   1631         }
  1630   1632         if( bHasPk==0 ){
  1631   1633           /* Ignore tables with no primary keys */
  1632   1634           goto diff_out;
  1633   1635         }
  1634   1636       }
................................................................................
  1826   1828   ** Ensure that there is room in the buffer to append nByte bytes of data.
  1827   1829   ** If not, use sqlite3_realloc() to grow the buffer so that there is.
  1828   1830   **
  1829   1831   ** If successful, return zero. Otherwise, if an OOM condition is encountered,
  1830   1832   ** set *pRc to SQLITE_NOMEM and return non-zero.
  1831   1833   */
  1832   1834   static int sessionBufferGrow(SessionBuffer *p, size_t nByte, int *pRc){
  1833         -  if( *pRc==SQLITE_OK && p->nAlloc-p->nBuf<nByte ){
         1835  +  if( *pRc==SQLITE_OK && (size_t)(p->nAlloc-p->nBuf)<nByte ){
  1834   1836       u8 *aNew;
  1835   1837       i64 nNew = p->nAlloc ? p->nAlloc : 128;
  1836   1838       do {
  1837   1839         nNew = nNew*2;
  1838   1840       }while( (nNew-p->nBuf)<nByte );
  1839   1841   
  1840   1842       aNew = (u8 *)sqlite3_realloc64(p->aBuf, nNew);

Changes to src/btree.c.

  5520   5520             **
  5521   5521             ** If the record is corrupt, the xRecordCompare routine may read
  5522   5522             ** up to two varints past the end of the buffer. An extra 18 
  5523   5523             ** bytes of padding is allocated at the end of the buffer in
  5524   5524             ** case this happens.  */
  5525   5525             void *pCellKey;
  5526   5526             u8 * const pCellBody = pCell - pPage->childPtrSize;
         5527  +          const int nOverrun = 18;  /* Size of the overrun padding */
  5527   5528             pPage->xParseCell(pPage, pCellBody, &pCur->info);
  5528   5529             nCell = (int)pCur->info.nKey;
  5529   5530             testcase( nCell<0 );   /* True if key size is 2^32 or more */
  5530   5531             testcase( nCell==0 );  /* Invalid key size:  0x80 0x80 0x00 */
  5531   5532             testcase( nCell==1 );  /* Invalid key size:  0x80 0x80 0x01 */
  5532   5533             testcase( nCell==2 );  /* Minimum legal index key size */
  5533   5534             if( nCell<2 || nCell/pCur->pBt->usableSize>pCur->pBt->nPage ){
  5534   5535               rc = SQLITE_CORRUPT_PAGE(pPage);
  5535   5536               goto moveto_finish;
  5536   5537             }
  5537         -          pCellKey = sqlite3Malloc( nCell+18 );
         5538  +          pCellKey = sqlite3Malloc( nCell+nOverrun );
  5538   5539             if( pCellKey==0 ){
  5539   5540               rc = SQLITE_NOMEM_BKPT;
  5540   5541               goto moveto_finish;
  5541   5542             }
  5542   5543             pCur->ix = (u16)idx;
  5543   5544             rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
         5545  +          memset(((u8*)pCellKey)+nCell,0,nOverrun); /* Fix uninit warnings */
  5544   5546             pCur->curFlags &= ~BTCF_ValidOvfl;
  5545   5547             if( rc ){
  5546   5548               sqlite3_free(pCellKey);
  5547   5549               goto moveto_finish;
  5548   5550             }
  5549   5551             c = sqlite3VdbeRecordCompare(nCell, pCellKey, pIdxKey);
  5550   5552             sqlite3_free(pCellKey);

Changes to src/build.c.

  3102   3102       addr2 = sqlite3VdbeCurrentAddr(v);
  3103   3103       sqlite3VdbeVerifyAbortable(v, OE_Abort);
  3104   3104       sqlite3VdbeAddOp4Int(v, OP_SorterCompare, iSorter, j2, regRecord,
  3105   3105                            pIndex->nKeyCol); VdbeCoverage(v);
  3106   3106       sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
  3107   3107       sqlite3VdbeJumpHere(v, j2);
  3108   3108     }else{
         3109  +    /* Most CREATE INDEX and REINDEX statements that are not UNIQUE can not
         3110  +    ** abort. The exception is if one of the indexed expressions contains a
         3111  +    ** user function that throws an exception when it is evaluated. But the
         3112  +    ** overhead of adding a statement journal to a CREATE INDEX statement is
         3113  +    ** very small (since most of the pages written do not contain content that
         3114  +    ** needs to be restored if the statement aborts), so we call 
         3115  +    ** sqlite3MayAbort() for all CREATE INDEX statements.  */
         3116  +    sqlite3MayAbort(pParse);
  3109   3117       addr2 = sqlite3VdbeCurrentAddr(v);
  3110   3118     }
  3111   3119     sqlite3VdbeAddOp3(v, OP_SorterData, iSorter, regRecord, iIdx);
  3112   3120     if( !pIndex->bAscKeyBug ){
  3113   3121       /* This OP_SeekEnd opcode makes index insert for a REINDEX go much
  3114   3122       ** faster by avoiding unnecessary seeks.  But the optimization does
  3115   3123       ** not work for UNIQUE constraint indexes on WITHOUT ROWID tables

Changes to src/expr.c.

  2804   2804         /* If the expression is not constant then we will need to
  2805   2805         ** disable the test that was generated above that makes sure
  2806   2806         ** this code only executes once.  Because for a non-constant
  2807   2807         ** expression we need to rerun this code each time.
  2808   2808         */
  2809   2809         if( addrOnce && !sqlite3ExprIsConstant(pE2) ){
  2810   2810           sqlite3VdbeChangeToNoop(v, addrOnce);
         2811  +        ExprClearProperty(pExpr, EP_Subrtn);
  2811   2812           addrOnce = 0;
  2812   2813         }
  2813   2814   
  2814   2815         /* Evaluate the expression and insert it into the temp table */
  2815   2816         r3 = sqlite3ExprCodeTarget(pParse, pE2, r1);
  2816   2817         sqlite3VdbeAddOp4(v, OP_MakeRecord, r3, 1, r2, &affinity, 1);
  2817   2818         sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iTab, r2, r3, 1);
................................................................................
  4857   4858       if( sqlite3ExprCompare(pParse, pA->pRight, pB->pRight, iTab) ) return 2;
  4858   4859       if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList, iTab) ) return 2;
  4859   4860       if( pA->op!=TK_STRING
  4860   4861        && pA->op!=TK_TRUEFALSE
  4861   4862        && (combinedFlags & EP_Reduced)==0
  4862   4863       ){
  4863   4864         if( pA->iColumn!=pB->iColumn ) return 2;
         4865  +      if( pA->op2!=pB->op2 ) return 2;
  4864   4866         if( pA->iTable!=pB->iTable 
  4865   4867          && (pA->iTable!=iTab || NEVER(pB->iTable>=0)) ) return 2;
  4866   4868       }
  4867   4869     }
  4868   4870     return 0;
  4869   4871   }
  4870   4872   

Changes to src/parse.y.

   297    297   // post-processing, if needed.
   298    298   //
   299    299   %type scanpt {const char*}
   300    300   scanpt(A) ::= . {
   301    301     assert( yyLookahead!=YYNOCODE );
   302    302     A = yyLookaheadToken.z;
   303    303   }
          304  +scantok(A) ::= . {
          305  +  assert( yyLookahead!=YYNOCODE );
          306  +  A = yyLookaheadToken;
          307  +}
   304    308   
   305    309   // "carglist" is a list of additional constraints that come after the
   306    310   // column name and column type in a CREATE TABLE statement.
   307    311   //
   308    312   carglist ::= carglist ccons.
   309    313   carglist ::= .
   310    314   ccons ::= CONSTRAINT nm(X).           {pParse->constraintName = X;}
   311         -ccons ::= DEFAULT scanpt(A) term(X) scanpt(Z).
   312         -                            {sqlite3AddDefaultValue(pParse,X,A,Z);}
          315  +ccons ::= DEFAULT scantok(A) term(X).
          316  +                            {sqlite3AddDefaultValue(pParse,X,A.z,&A.z[A.n]);}
   313    317   ccons ::= DEFAULT LP(A) expr(X) RP(Z).
   314    318                               {sqlite3AddDefaultValue(pParse,X,A.z+1,Z.z);}
   315         -ccons ::= DEFAULT PLUS(A) term(X) scanpt(Z).
   316         -                            {sqlite3AddDefaultValue(pParse,X,A.z,Z);}
   317         -ccons ::= DEFAULT MINUS(A) term(X) scanpt(Z).      {
          319  +ccons ::= DEFAULT PLUS(A) scantok(Z) term(X).
          320  +                            {sqlite3AddDefaultValue(pParse,X,A.z,&Z.z[Z.n]);}
          321  +ccons ::= DEFAULT MINUS(A) scantok(Z) term(X). {
   318    322     Expr *p = sqlite3PExpr(pParse, TK_UMINUS, X, 0);
   319         -  sqlite3AddDefaultValue(pParse,p,A.z,Z);
          323  +  sqlite3AddDefaultValue(pParse,p,A.z,&Z.z[Z.n]);
   320    324   }
   321         -ccons ::= DEFAULT scanpt id(X).       {
          325  +ccons ::= DEFAULT scantok id(X).       {
   322    326     Expr *p = tokenExpr(pParse, TK_STRING, X);
   323    327     if( p ){
   324    328       sqlite3ExprIdToTrueFalse(p);
   325    329       testcase( p->op==TK_TRUEFALSE && sqlite3ExprTruthValue(p) );
   326    330     }
   327    331       sqlite3AddDefaultValue(pParse,p,X.z,X.z+X.n);
   328    332   }

Changes to src/pragma.c.

   646    646           if( sqlite3StrNICmp(zRight, zMode, n)==0 ) break;
   647    647         }
   648    648         if( !zMode ){
   649    649           /* If the "=MODE" part does not match any known journal mode,
   650    650           ** then do a query */
   651    651           eMode = PAGER_JOURNALMODE_QUERY;
   652    652         }
          653  +      if( eMode==PAGER_JOURNALMODE_OFF && (db->flags & SQLITE_Defensive)!=0 ){
          654  +        /* Do not allow journal-mode "OFF" in defensive since the database
          655  +        ** can become corrupted using ordinary SQL when the journal is off */
          656  +        eMode = PAGER_JOURNALMODE_QUERY;
          657  +      }
   653    658       }
   654    659       if( eMode==PAGER_JOURNALMODE_QUERY && pId2->n==0 ){
   655    660         /* Convert "PRAGMA journal_mode" into "PRAGMA main.journal_mode" */
   656    661         iDb = 0;
   657    662         pId2->n = 1;
   658    663       }
   659    664       for(ii=db->nDb-1; ii>=0; ii--){
................................................................................
  2128   2133     **  hexkey        2
  2129   2134     **  hexrekey      3
  2130   2135     **  textkey       4
  2131   2136     **  textrekey     5
  2132   2137     */
  2133   2138     case PragTyp_KEY: {
  2134   2139       if( zRight ){
  2135         -      int n = pPragma->iArg<4 ? sqlite3Strlen30(zRight) : -1;
  2136         -      if( (pPragma->iArg & 1)==0 ){
  2137         -        sqlite3_key_v2(db, zDb, zRight, n);
         2140  +      char zBuf[40];
         2141  +      const char *zKey = zRight;
         2142  +      int n;
         2143  +      if( pPragma->iArg==2 || pPragma->iArg==3 ){
         2144  +        u8 iByte;
         2145  +        int i;
         2146  +        for(i=0, iByte=0; i<sizeof(zBuf)*2 && sqlite3Isxdigit(zRight[i]); i++){
         2147  +          iByte = (iByte<<4) + sqlite3HexToInt(zRight[i]);
         2148  +          if( (i&1)!=0 ) zBuf[i/2] = iByte;
         2149  +        }
         2150  +        zKey = zBuf;
         2151  +        n = i/2;
  2138   2152         }else{
  2139         -        sqlite3_rekey_v2(db, zDb, zRight, n);
  2140         -      }
  2141         -    }
  2142         -    break;
  2143         -  }
  2144         -  case PragTyp_HEXKEY: {
  2145         -    if( zRight ){
  2146         -      u8 iByte;
  2147         -      int i;
  2148         -      char zKey[40];
  2149         -      for(i=0, iByte=0; i<sizeof(zKey)*2 && sqlite3Isxdigit(zRight[i]); i++){
  2150         -        iByte = (iByte<<4) + sqlite3HexToInt(zRight[i]);
  2151         -        if( (i&1)!=0 ) zKey[i/2] = iByte;
         2153  +        n = pPragma->iArg<4 ? sqlite3Strlen30(zRight) : -1;
  2152   2154         }
  2153   2155         if( (pPragma->iArg & 1)==0 ){
  2154         -        sqlite3_key_v2(db, zDb, zKey, i/2);
         2156  +        rc = sqlite3_key_v2(db, zDb, zKey, n);
  2155   2157         }else{
  2156         -        sqlite3_rekey_v2(db, zDb, zKey, i/2);
         2158  +        rc = sqlite3_rekey_v2(db, zDb, zKey, n);
         2159  +      }
         2160  +      if( rc==SQLITE_OK && n!=0 ){
         2161  +        sqlite3VdbeSetNumCols(v, 1);
         2162  +        sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "ok", SQLITE_STATIC);
         2163  +        returnSingleText(v, "ok");
  2157   2164         }
  2158   2165       }
  2159   2166       break;
  2160   2167     }
  2161   2168   #endif
  2162   2169   #if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD)
  2163   2170     case PragTyp_ACTIVATE_EXTENSIONS: if( zRight ){

Changes to src/pragma.h.

    42     42   #define PragTyp_TABLE_INFO                    34
    43     43   #define PragTyp_TEMP_STORE                    35
    44     44   #define PragTyp_TEMP_STORE_DIRECTORY          36
    45     45   #define PragTyp_THREADS                       37
    46     46   #define PragTyp_WAL_AUTOCHECKPOINT            38
    47     47   #define PragTyp_WAL_CHECKPOINT                39
    48     48   #define PragTyp_ACTIVATE_EXTENSIONS           40
    49         -#define PragTyp_HEXKEY                        41
    50         -#define PragTyp_KEY                           42
    51         -#define PragTyp_LOCK_STATUS                   43
    52         -#define PragTyp_STATS                         44
           49  +#define PragTyp_KEY                           41
           50  +#define PragTyp_LOCK_STATUS                   42
           51  +#define PragTyp_STATS                         43
    53     52   
    54     53   /* Property flags associated with various pragma. */
    55     54   #define PragFlg_NeedSchema 0x01 /* Force schema load before running */
    56     55   #define PragFlg_NoColumns  0x02 /* OP_ResultRow called with zero columns */
    57     56   #define PragFlg_NoColumns1 0x04 /* zero columns if RHS argument is present */
    58     57   #define PragFlg_OneSchema  0x08 /* Only a single schema required */
    59     58   #define PragFlg_Result0    0x10 /* Acts as query when no argument */
................................................................................
   325    324     /* ePragFlg:  */ PragFlg_Result0,
   326    325     /* ColNames:  */ 41, 2,
   327    326     /* iArg:      */ 0 },
   328    327   #endif
   329    328   #endif
   330    329   #if defined(SQLITE_HAS_CODEC)
   331    330    {/* zName:     */ "hexkey",
   332         -  /* ePragTyp:  */ PragTyp_HEXKEY,
          331  +  /* ePragTyp:  */ PragTyp_KEY,
   333    332     /* ePragFlg:  */ 0,
   334    333     /* ColNames:  */ 0, 0,
   335    334     /* iArg:      */ 2 },
   336    335    {/* zName:     */ "hexrekey",
   337         -  /* ePragTyp:  */ PragTyp_HEXKEY,
          336  +  /* ePragTyp:  */ PragTyp_KEY,
   338    337     /* ePragFlg:  */ 0,
   339    338     /* ColNames:  */ 0, 0,
   340    339     /* iArg:      */ 3 },
   341    340   #endif
   342    341   #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   343    342   #if !defined(SQLITE_OMIT_CHECK)
   344    343    {/* zName:     */ "ignore_check_constraints",

Changes to src/resolve.c.

   472    472     ** pExpr.
   473    473     **
   474    474     ** Because no reference was made to outer contexts, the pNC->nRef
   475    475     ** fields are not changed in any context.
   476    476     */
   477    477     if( cnt==0 && zTab==0 ){
   478    478       assert( pExpr->op==TK_ID );
   479         -    if( ExprHasProperty(pExpr,EP_DblQuoted) ){
          479  +    if( ExprHasProperty(pExpr,EP_DblQuoted) 
          480  +     && 0==(pTopNC->ncFlags&NC_NoDblQStr) 
          481  +    ){
   480    482         /* If a double-quoted identifier does not match any known column name,
   481    483         ** then treat it as a string.
   482    484         **
   483    485         ** This hack was added in the early days of SQLite in a misguided attempt
   484    486         ** to be compatible with MySQL 3.x, which used double-quotes for strings.
   485    487         ** I now sorely regret putting in this hack. The effect of this hack is
   486    488         ** that misspelled identifier names are silently converted into strings
................................................................................
  1650   1652   ** An error message is left in pParse if anything is amiss.  The number
  1651   1653   ** if errors is returned.
  1652   1654   */
  1653   1655   int sqlite3ResolveExprNames( 
  1654   1656     NameContext *pNC,       /* Namespace to resolve expressions in. */
  1655   1657     Expr *pExpr             /* The expression to be analyzed. */
  1656   1658   ){
  1657         -  u16 savedHasAgg;
         1659  +  int savedHasAgg;
  1658   1660     Walker w;
  1659   1661   
  1660   1662     if( pExpr==0 ) return SQLITE_OK;
  1661   1663     savedHasAgg = pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
  1662   1664     pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
  1663   1665     w.pParse = pNC->pParse;
  1664   1666     w.xExprCallback = resolveExprStep;
................................................................................
  1765   1767       sSrc.a[0].zName = pTab->zName;
  1766   1768       sSrc.a[0].pTab = pTab;
  1767   1769       sSrc.a[0].iCursor = -1;
  1768   1770     }
  1769   1771     sNC.pParse = pParse;
  1770   1772     sNC.pSrcList = &sSrc;
  1771   1773     sNC.ncFlags = type;
         1774  +  if( !pParse->db->init.busy && !sqlite3WritableSchema(pParse->db) ){
         1775  +    sNC.ncFlags |= NC_NoDblQStr;
         1776  +  }
  1772   1777     if( (rc = sqlite3ResolveExprNames(&sNC, pExpr))!=SQLITE_OK ) return rc;
  1773   1778     if( pList ) rc = sqlite3ResolveExprListNames(&sNC, pList);
  1774   1779     return rc;
  1775   1780   }

Changes to src/select.c.

  4839   4839     if( db->mallocFailed  ){
  4840   4840       return WRC_Abort;
  4841   4841     }
  4842   4842     assert( p->pSrc!=0 );
  4843   4843     if( (selFlags & SF_Expanded)!=0 ){
  4844   4844       return WRC_Prune;
  4845   4845     }
         4846  +  if( pWalker->eCode ){
         4847  +    /* Renumber selId because it has been copied from a view */
         4848  +    p->selId = ++pParse->nSelect;
         4849  +  }
  4846   4850     pTabList = p->pSrc;
  4847   4851     pEList = p->pEList;
  4848   4852     sqlite3WithPush(pParse, p->pWith, 0);
  4849   4853   
  4850   4854     /* Make sure cursor numbers have been assigned to all entries in
  4851   4855     ** the FROM clause of the SELECT statement.
  4852   4856     */
................................................................................
  4888   4892         pTab->nTabRef++;
  4889   4893         if( !IsVirtual(pTab) && cannotBeFunction(pParse, pFrom) ){
  4890   4894           return WRC_Abort;
  4891   4895         }
  4892   4896   #if !defined(SQLITE_OMIT_VIEW) || !defined (SQLITE_OMIT_VIRTUALTABLE)
  4893   4897         if( IsVirtual(pTab) || pTab->pSelect ){
  4894   4898           i16 nCol;
         4899  +        u8 eCodeOrig = pWalker->eCode;
  4895   4900           if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort;
  4896   4901           assert( pFrom->pSelect==0 );
  4897   4902           pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0);
  4898   4903           nCol = pTab->nCol;
  4899   4904           pTab->nCol = -1;
         4905  +        pWalker->eCode = 1;  /* Turn on Select.selId renumbering */
  4900   4906           sqlite3WalkSelect(pWalker, pFrom->pSelect);
         4907  +        pWalker->eCode = eCodeOrig;
  4901   4908           pTab->nCol = nCol;
  4902   4909         }
  4903   4910   #endif
  4904   4911       }
  4905   4912   
  4906   4913       /* Locate the index named by the INDEXED BY clause, if any. */
  4907   4914       if( sqlite3IndexedByLookup(pParse, pFrom) ){
................................................................................
  5143   5150     if( OK_IF_ALWAYS_TRUE(pParse->hasCompound) ){
  5144   5151       w.xSelectCallback = convertCompoundSelectToSubquery;
  5145   5152       w.xSelectCallback2 = 0;
  5146   5153       sqlite3WalkSelect(&w, pSelect);
  5147   5154     }
  5148   5155     w.xSelectCallback = selectExpander;
  5149   5156     w.xSelectCallback2 = selectPopWith;
         5157  +  w.eCode = 0;
  5150   5158     sqlite3WalkSelect(&w, pSelect);
  5151   5159   }
  5152   5160   
  5153   5161   
  5154   5162   #ifndef SQLITE_OMIT_SUBQUERY
  5155   5163   /*
  5156   5164   ** This is a Walker.xSelectCallback callback for the sqlite3SelectTypeInfo()
................................................................................
  5469   5477   ){
  5470   5478     struct SrcList_item *pItem;
  5471   5479     for(pItem = pTabList->a; pItem<pThis; pItem++){
  5472   5480       Select *pS1;
  5473   5481       if( pItem->pSelect==0 ) continue;
  5474   5482       if( pItem->fg.viaCoroutine ) continue;
  5475   5483       if( pItem->zName==0 ) continue;
  5476         -    if( sqlite3_stricmp(pItem->zDatabase, pThis->zDatabase)!=0 ) continue;
         5484  +    assert( pItem->pTab!=0 );
         5485  +    assert( pThis->pTab!=0 );
         5486  +    if( pItem->pTab->pSchema!=pThis->pTab->pSchema ) continue;
  5477   5487       if( sqlite3_stricmp(pItem->zName, pThis->zName)!=0 ) continue;
  5478   5488       pS1 = pItem->pSelect;
  5479         -    if( pThis->pSelect->selId!=pS1->selId ){
         5489  +    if( pItem->pTab->pSchema==0 && pThis->pSelect->selId!=pS1->selId ){
  5480   5490         /* The query flattener left two different CTE tables with identical
  5481   5491         ** names in the same FROM clause. */
  5482   5492         continue;
  5483   5493       }
  5484   5494       if( sqlite3ExprCompare(0, pThis->pSelect->pWhere, pS1->pWhere, -1)
  5485   5495        || sqlite3ExprCompare(0, pThis->pSelect->pHaving, pS1->pHaving, -1) 
  5486   5496       ){
................................................................................
  5504   5514   **    SELECT (SELECT count(*) FROM t1)+(SELECT count(*) FROM t2)
  5505   5515   **
  5506   5516   ** The transformation only works if all of the following are true:
  5507   5517   **
  5508   5518   **   *  The subquery is a UNION ALL of two or more terms
  5509   5519   **   *  The subquery does not have a LIMIT clause
  5510   5520   **   *  There is no WHERE or GROUP BY or HAVING clauses on the subqueries
  5511         -**   *  The outer query is a simple count(*)
         5521  +**   *  The outer query is a simple count(*) with no WHERE clause or other
         5522  +**      extraneous syntax.
  5512   5523   **
  5513   5524   ** Return TRUE if the optimization is undertaken.
  5514   5525   */
  5515   5526   static int countOfViewOptimization(Parse *pParse, Select *p){
  5516   5527     Select *pSub, *pPrior;
  5517   5528     Expr *pExpr;
  5518   5529     Expr *pCount;
  5519   5530     sqlite3 *db;
  5520   5531     if( (p->selFlags & SF_Aggregate)==0 ) return 0;   /* This is an aggregate */
  5521   5532     if( p->pEList->nExpr!=1 ) return 0;               /* Single result column */
         5533  +  if( p->pWhere ) return 0;
         5534  +  if( p->pGroupBy ) return 0;
  5522   5535     pExpr = p->pEList->a[0].pExpr;
  5523   5536     if( pExpr->op!=TK_AGG_FUNCTION ) return 0;        /* Result is an aggregate */
  5524   5537     if( sqlite3_stricmp(pExpr->u.zToken,"count") ) return 0;  /* Is count() */
  5525   5538     if( pExpr->x.pList!=0 ) return 0;                 /* Must be count(*) */
  5526   5539     if( p->pSrc->nSrc!=1 ) return 0;                  /* One table in FROM  */
  5527   5540     pSub = p->pSrc->a[0].pSelect;
  5528   5541     if( pSub==0 ) return 0;                           /* The FROM is a subquery */

Changes to src/sqlite.h.in.

  2196   2196   ** <dd>The SQLITE_DBCONFIG_DEFENSIVE option activates or deactivates the
  2197   2197   ** "defensive" flag for a database connection.  When the defensive
  2198   2198   ** flag is enabled, language features that allow ordinary SQL to 
  2199   2199   ** deliberately corrupt the database file are disabled.  The disabled
  2200   2200   ** features include but are not limited to the following:
  2201   2201   ** <ul>
  2202   2202   ** <li> The [PRAGMA writable_schema=ON] statement.
         2203  +** <li> The [PRAGMA journal_mode=OFF] statement.
  2203   2204   ** <li> Writes to the [sqlite_dbpage] virtual table.
  2204   2205   ** <li> Direct writes to [shadow tables].
  2205   2206   ** </ul>
  2206   2207   ** </dd>
  2207   2208   **
  2208   2209   ** [[SQLITE_DBCONFIG_WRITABLE_SCHEMA]] <dt>SQLITE_DBCONFIG_WRITABLE_SCHEMA</dt>
  2209   2210   ** <dd>The SQLITE_DBCONFIG_WRITABLE_SCHEMA option activates or deactivates the

Changes to src/sqliteInt.h.

   826    826   **
   827    827   ** For best performance, an attempt is made to guess at the byte-order
   828    828   ** using C-preprocessor macros.  If that is unsuccessful, or if
   829    829   ** -DSQLITE_BYTEORDER=0 is set, then byte-order is determined
   830    830   ** at run-time.
   831    831   */
   832    832   #ifndef SQLITE_BYTEORDER
   833         -# if defined(i386)     || defined(__i386__)   || defined(_M_IX86) ||    \
   834         -     defined(__x86_64) || defined(__x86_64__) || defined(_M_X64)  ||    \
   835         -     defined(_M_AMD64) || defined(_M_ARM)     || defined(__x86)   ||    \
   836         -     defined(__arm__)  || defined(_M_ARM64)
          833  +# if defined(i386)      || defined(__i386__)      || defined(_M_IX86) ||    \
          834  +     defined(__x86_64)  || defined(__x86_64__)    || defined(_M_X64)  ||    \
          835  +     defined(_M_AMD64)  || defined(_M_ARM)        || defined(__x86)   ||    \
          836  +     defined(__ARMEL__) || defined(__AARCH64EL__) || defined(_M_ARM64)
   837    837   #   define SQLITE_BYTEORDER    1234
   838         -# elif defined(sparc)    || defined(__ppc__)
          838  +# elif defined(sparc)     || defined(__ppc__) || \
          839  +       defined(__ARMEB__) || defined(__AARCH64EB__)
   839    840   #   define SQLITE_BYTEORDER    4321
   840    841   # else
   841    842   #   define SQLITE_BYTEORDER 0
   842    843   # endif
   843    844   #endif
   844    845   #if SQLITE_BYTEORDER==4321
   845    846   # define SQLITE_BIGENDIAN    1
................................................................................
  2497   2498                            ** EP_Unlikely:  134217728 times likelihood
  2498   2499                            ** TK_SELECT: 1st register of result vector */
  2499   2500     ynVar iColumn;         /* TK_COLUMN: column index.  -1 for rowid.
  2500   2501                            ** TK_VARIABLE: variable number (always >= 1).
  2501   2502                            ** TK_SELECT_COLUMN: column of the result vector */
  2502   2503     i16 iAgg;              /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
  2503   2504     i16 iRightJoinTable;   /* If EP_FromJoin, the right table of the join */
  2504         -  u8 op2;                /* TK_REGISTER: original value of Expr.op
         2505  +  u8 op2;                /* TK_REGISTER/TK_TRUTH: original value of Expr.op
  2505   2506                            ** TK_COLUMN: the value of p5 for OP_Column
  2506   2507                            ** TK_AGG_FUNCTION: nesting depth */
  2507   2508     AggInfo *pAggInfo;     /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
  2508   2509     union {
  2509   2510       Table *pTab;           /* TK_COLUMN: Table containing column. Can be NULL
  2510   2511                              ** for a column of an index on an expression */
  2511   2512       Window *pWin;          /* TK_FUNCTION: Window definition for the func */
................................................................................
  2782   2783       ExprList *pEList;    /* Optional list of result-set columns */
  2783   2784       AggInfo *pAggInfo;   /* Information about aggregates at this level */
  2784   2785       Upsert *pUpsert;     /* ON CONFLICT clause information from an upsert */
  2785   2786     } uNC;
  2786   2787     NameContext *pNext;  /* Next outer name context.  NULL for outermost */
  2787   2788     int nRef;            /* Number of names resolved by this context */
  2788   2789     int nErr;            /* Number of errors encountered while resolving names */
  2789         -  u16 ncFlags;         /* Zero or more NC_* flags defined below */
         2790  +  int ncFlags;         /* Zero or more NC_* flags defined below */
  2790   2791     Select *pWinSelect;  /* SELECT statement for any window functions */
  2791   2792   };
  2792   2793   
  2793   2794   /*
  2794   2795   ** Allowed values for the NameContext, ncFlags field.
  2795   2796   **
  2796   2797   ** Value constraints (all checked via assert()):
................................................................................
  2809   2810   #define NC_UEList    0x0080  /* True if uNC.pEList is used */
  2810   2811   #define NC_UAggInfo  0x0100  /* True if uNC.pAggInfo is used */
  2811   2812   #define NC_UUpsert   0x0200  /* True if uNC.pUpsert is used */
  2812   2813   #define NC_MinMaxAgg 0x1000  /* min/max aggregates seen.  See note above */
  2813   2814   #define NC_Complex   0x2000  /* True if a function or subquery seen */
  2814   2815   #define NC_AllowWin  0x4000  /* Window functions are allowed here */
  2815   2816   #define NC_HasWin    0x8000  /* One or more window functions seen */
         2817  +#define NC_NoDblQStr 0x10000 /* Do not allow double-quoted string hack.
         2818  +                             ** Mnemonic: "NO DouBLe-Quoted STRings" */
  2816   2819   
  2817   2820   /*
  2818   2821   ** An instance of the following object describes a single ON CONFLICT
  2819   2822   ** clause in an upsert.
  2820   2823   **
  2821   2824   ** The pUpsertTarget field is only set if the ON CONFLICT clause includes
  2822   2825   ** conflict-target clause.  (In "ON CONFLICT(a,b)" the "(a,b)" is the

Changes to src/vdbe.c.

  1497   1497       if( sqlite3VdbeMemExpandBlob(pIn2) ) goto no_mem;
  1498   1498       flags2 = pIn2->flags & ~MEM_Str;
  1499   1499     }
  1500   1500     nByte = pIn1->n + pIn2->n;
  1501   1501     if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
  1502   1502       goto too_big;
  1503   1503     }
  1504         -  if( sqlite3VdbeMemGrow(pOut, (int)nByte+2, pOut==pIn2) ){
         1504  +  if( sqlite3VdbeMemGrow(pOut, (int)nByte+3, pOut==pIn2) ){
  1505   1505       goto no_mem;
  1506   1506     }
  1507   1507     MemSetTypeFlag(pOut, MEM_Str);
  1508   1508     if( pOut!=pIn2 ){
  1509   1509       memcpy(pOut->z, pIn2->z, pIn2->n);
  1510   1510       assert( (pIn2->flags & MEM_Dyn) == (flags2 & MEM_Dyn) );
  1511   1511       pIn2->flags = flags2;
  1512   1512     }
  1513   1513     memcpy(&pOut->z[pIn2->n], pIn1->z, pIn1->n);
  1514   1514     assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
  1515   1515     pIn1->flags = flags1;
  1516   1516     pOut->z[nByte]=0;
  1517   1517     pOut->z[nByte+1] = 0;
         1518  +  pOut->z[nByte+2] = 0;
  1518   1519     pOut->flags |= MEM_Term;
  1519   1520     pOut->n = (int)nByte;
  1520   1521     pOut->enc = encoding;
  1521   1522     UPDATE_MAX_BLOBSIZE(pOut);
  1522   1523     break;
  1523   1524   }
  1524   1525   
................................................................................
  2879   2880     /* Apply the requested affinity to all inputs
  2880   2881     */
  2881   2882     assert( pData0<=pLast );
  2882   2883     if( zAffinity ){
  2883   2884       pRec = pData0;
  2884   2885       do{
  2885   2886         applyAffinity(pRec, zAffinity[0], encoding);
         2887  +      if( zAffinity[0]==SQLITE_AFF_REAL && (pRec->flags & MEM_Int) ){
         2888  +        pRec->flags |= MEM_IntReal;
         2889  +        pRec->flags &= ~(MEM_Int);
         2890  +      }
  2886   2891         REGISTER_TRACE((int)(pRec-aMem), pRec);
  2887   2892         zAffinity++;
  2888   2893         pRec++;
  2889   2894         assert( zAffinity[0]==0 || pRec<=pLast );
  2890   2895       }while( zAffinity[0] );
  2891   2896     }
  2892   2897   
................................................................................
  4779   4784   
  4780   4785   #ifdef SQLITE_DEBUG
  4781   4786     if( pOp->p4type==P4_TABLE && HasRowid(pOp->p4.pTab) && pOp->p5==0 ){
  4782   4787       /* If p5 is zero, the seek operation that positioned the cursor prior to
  4783   4788       ** OP_Delete will have also set the pC->movetoTarget field to the rowid of
  4784   4789       ** the row that is being deleted */
  4785   4790       i64 iKey = sqlite3BtreeIntegerKey(pC->uc.pCursor);
  4786         -    assert( pC->movetoTarget==iKey );
         4791  +    assert( CORRUPT_DB || pC->movetoTarget==iKey );
  4787   4792     }
  4788   4793   #endif
  4789   4794   
  4790   4795     /* If the update-hook or pre-update-hook will be invoked, set zDb to
  4791   4796     ** the name of the db to pass as to it. Also set local pTab to a copy
  4792   4797     ** of p4.pTab. Finally, if p5 is true, indicating that this cursor was
  4793   4798     ** last moved with OP_Next or OP_Prev, not Seek or NotFound, set 

Changes to src/vdbeaux.c.

   627    627   **
   628    628   **   assert( sqlite3VdbeAssertMayAbort(pParse->pVdbe, pParse->mayAbort) );
   629    629   */
   630    630   int sqlite3VdbeAssertMayAbort(Vdbe *v, int mayAbort){
   631    631     int hasAbort = 0;
   632    632     int hasFkCounter = 0;
   633    633     int hasCreateTable = 0;
          634  +  int hasCreateIndex = 0;
   634    635     int hasInitCoroutine = 0;
   635    636     Op *pOp;
   636    637     VdbeOpIter sIter;
   637    638     memset(&sIter, 0, sizeof(sIter));
   638    639     sIter.v = v;
   639    640   
   640    641     while( (pOp = opIterNext(&sIter))!=0 ){
................................................................................
   645    646        || ((opcode==OP_Halt || opcode==OP_HaltIfNull) 
   646    647         && ((pOp->p1)!=SQLITE_OK && pOp->p2==OE_Abort))
   647    648       ){
   648    649         hasAbort = 1;
   649    650         break;
   650    651       }
   651    652       if( opcode==OP_CreateBtree && pOp->p3==BTREE_INTKEY ) hasCreateTable = 1;
          653  +    if( mayAbort ){
          654  +      /* hasCreateIndex may also be set for some DELETE statements that use
          655  +      ** OP_Clear. So this routine may end up returning true in the case 
          656  +      ** where a "DELETE FROM tbl" has a statement-journal but does not
          657  +      ** require one. This is not so bad - it is an inefficiency, not a bug. */
          658  +      if( opcode==OP_CreateBtree && pOp->p3==BTREE_BLOBKEY ) hasCreateIndex = 1;
          659  +      if( opcode==OP_Clear ) hasCreateIndex = 1;
          660  +    }
   652    661       if( opcode==OP_InitCoroutine ) hasInitCoroutine = 1;
   653    662   #ifndef SQLITE_OMIT_FOREIGN_KEY
   654    663       if( opcode==OP_FkCounter && pOp->p1==0 && pOp->p2==1 ){
   655    664         hasFkCounter = 1;
   656    665       }
   657    666   #endif
   658    667     }
................................................................................
   660    669   
   661    670     /* Return true if hasAbort==mayAbort. Or if a malloc failure occurred.
   662    671     ** If malloc failed, then the while() loop above may not have iterated
   663    672     ** through all opcodes and hasAbort may be set incorrectly. Return
   664    673     ** true for this case to prevent the assert() in the callers frame
   665    674     ** from failing.  */
   666    675     return ( v->db->mallocFailed || hasAbort==mayAbort || hasFkCounter
   667         -              || (hasCreateTable && hasInitCoroutine) );
          676  +        || (hasCreateTable && hasInitCoroutine) || hasCreateIndex
          677  +  );
   668    678   }
   669    679   #endif /* SQLITE_DEBUG - the sqlite3AssertMayAbort() function */
   670    680   
   671    681   #ifdef SQLITE_DEBUG
   672    682   /*
   673    683   ** Increment the nWrite counter in the VDBE if the cursor is not an
   674    684   ** ephemeral cursor, or if the cursor argument is NULL.

Changes to src/vdbemem.c.

   114    114     }
   115    115     assert( acc.zText==zBuf && acc.mxAlloc<=0 );
   116    116     zBuf[acc.nChar] = 0; /* Fast version of sqlite3StrAccumFinish(&acc) */
   117    117   }
   118    118   
   119    119   #ifdef SQLITE_DEBUG
   120    120   /*
   121         -** Check that string value of pMem agrees with its integer or real value.
          121  +** Validity checks on pMem.  pMem holds a string.
          122  +**
          123  +** (1) Check that string value of pMem agrees with its integer or real value.
          124  +** (2) Check that the string is correctly zero terminated
   122    125   **
   123    126   ** A single int or real value always converts to the same strings.  But
   124    127   ** many different strings can be converted into the same int or real.
   125    128   ** If a table contains a numeric value and an index is based on the
   126    129   ** corresponding string value, then it is important that the string be
   127    130   ** derived from the numeric value, not the other way around, to ensure
   128    131   ** that the index and table are consistent.  See ticket
................................................................................
   132    135   ** This routine looks at pMem to verify that if it has both a numeric
   133    136   ** representation and a string representation then the string rep has
   134    137   ** been derived from the numeric and not the other way around.  It returns
   135    138   ** true if everything is ok and false if there is a problem.
   136    139   **
   137    140   ** This routine is for use inside of assert() statements only.
   138    141   */
   139         -int sqlite3VdbeMemConsistentDualRep(Mem *p){
          142  +int sqlite3VdbeMemValidStrRep(Mem *p){
   140    143     char zBuf[100];
   141    144     char *z;
   142    145     int i, j, incr;
   143    146     if( (p->flags & MEM_Str)==0 ) return 1;
          147  +  if( p->flags & MEM_Term ){
          148  +    /* Insure that the string is properly zero-terminated.  Pay particular
          149  +    ** attention to the case where p->n is odd */
          150  +    if( p->szMalloc>0 && p->z==p->zMalloc ){
          151  +      assert( p->enc==SQLITE_UTF8 || p->szMalloc >= ((p->n+1)&~1)+2 );
          152  +      assert( p->enc!=SQLITE_UTF8 || p->szMalloc >= p->n+1 );
          153  +    }
          154  +    assert( p->z[p->n]==0 );
          155  +    assert( p->enc==SQLITE_UTF8 || p->z[(p->n+1)&~1]==0 );
          156  +    assert( p->enc==SQLITE_UTF8 || p->z[((p->n+1)&~1)+1]==0 );
          157  +  }
   144    158     if( (p->flags & (MEM_Int|MEM_Real|MEM_IntReal))==0 ) return 1;
   145    159     vdbeMemRenderNum(sizeof(zBuf), zBuf, p);
   146    160     z = p->z;
   147    161     i = j = 0;
   148    162     incr = 1;
   149    163     if( p->enc!=SQLITE_UTF8 ){
   150    164       incr = 2;
................................................................................
  1217   1231     }else{
  1218   1232       sqlite3VdbeMemStringify(pVal, enc, 0);
  1219   1233       assert( 0==(1&SQLITE_PTR_TO_INT(pVal->z)) );
  1220   1234     }
  1221   1235     assert(pVal->enc==(enc & ~SQLITE_UTF16_ALIGNED) || pVal->db==0
  1222   1236                 || pVal->db->mallocFailed );
  1223   1237     if( pVal->enc==(enc & ~SQLITE_UTF16_ALIGNED) ){
  1224         -    assert( sqlite3VdbeMemConsistentDualRep(pVal) );
         1238  +    assert( sqlite3VdbeMemValidStrRep(pVal) );
  1225   1239       return pVal->z;
  1226   1240     }else{
  1227   1241       return 0;
  1228   1242     }
  1229   1243   }
  1230   1244   
  1231   1245   /* This function is only available internally, it is not part of the
................................................................................
  1240   1254   */
  1241   1255   const void *sqlite3ValueText(sqlite3_value* pVal, u8 enc){
  1242   1256     if( !pVal ) return 0;
  1243   1257     assert( pVal->db==0 || sqlite3_mutex_held(pVal->db->mutex) );
  1244   1258     assert( (enc&3)==(enc&~SQLITE_UTF16_ALIGNED) );
  1245   1259     assert( !sqlite3VdbeMemIsRowSet(pVal) );
  1246   1260     if( (pVal->flags&(MEM_Str|MEM_Term))==(MEM_Str|MEM_Term) && pVal->enc==enc ){
  1247         -    assert( sqlite3VdbeMemConsistentDualRep(pVal) );
         1261  +    assert( sqlite3VdbeMemValidStrRep(pVal) );
  1248   1262       return pVal->z;
  1249   1263     }
  1250   1264     if( pVal->flags&MEM_Null ){
  1251   1265       return 0;
  1252   1266     }
  1253   1267     return valueToText(pVal, enc);
  1254   1268   }

Changes to test/check.test.

   113    113     execsql {
   114    114       SELECT * FROM t1;
   115    115     }
   116    116   } {4 11.0}
   117    117   
   118    118   do_test check-2.1 {
   119    119     execsql {
          120  +    PRAGMA writable_schema = 1;
   120    121       CREATE TABLE t2(
   121    122         x INTEGER CONSTRAINT one CHECK( typeof(coalesce(x,0))=="integer" ),
   122    123         y REAL CONSTRAINT two CHECK( typeof(coalesce(y,0.1))=='real' ),
   123    124         z TEXT CONSTRAINT three CHECK( typeof(coalesce(z,''))=='text' )
   124    125       );
          126  +    PRAGMA writable_schema = 0;
   125    127     }
   126    128   } {}
   127    129   do_test check-2.2 {
   128    130     execsql {
   129    131       INSERT INTO t2 VALUES(1,2.2,'three');
   130    132       SELECT * FROM t2;
   131    133     }

Changes to test/corruptL.test.

  1003   1003   | end crash-41390d95d613b6.db
  1004   1004   }]} {}
  1005   1005   
  1006   1006   do_catchsql_test 10.1 {
  1007   1007     SELECT * FROM t1 WHERE a<='2019-05-09' ORDER BY a DESC;
  1008   1008   } {1 {database disk image is malformed}}
  1009   1009   
         1010  +
         1011  +#-------------------------------------------------------------------------
         1012  +reset_db
         1013  +do_test 11.0 {
         1014  +  sqlite3 db {}
         1015  +  db deserialize [decode_hexdb {
         1016  +| size 595 pagesize 512 filename x.db
         1017  +| page 1 offset 0
         1018  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         1019  +|     16: 02 00 00 01 00 40 20 20 00 01 00 0c 00 00 00 07   .....@  ........
         1020  +|     32: 00 00 00 05 07 a1 1f fa 00 00 00 08 00 00 00 04   ................
         1021  +|     48: 00 00 01 00 00 49 00 00 00 00 00 05 00 00 00 00   .....I..........
         1022  +|     80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1c   ................
         1023  +|     96: 00 2e 2c 50 0d 00 00 00 06 01 06 00 01 da 01 b0   ..,P............
         1024  +|    112: 01 56 01 86 01 2a 01 06 00 00 62 00 00 00 00 00   .V...*....b.....
         1025  +|    128: 00 ed e2 78 74 64 33 ff 43 52 45 41 54 45 20 49   ...xtd3.CREATE I
         1026  +|    144: 4e 44 45 58 20 74 33 78 20 4f 4e 20 74 33 28 38   NDEX t3x ON t3(8
         1027  +|    160: 29 2e 04 06 17 15 11 01 45 69 6e 64 65 68 74 32   ).......Eindeht2
         1028  +|    176: 63 64 74 31 e5 43 52 45 41 54 45 20 49 4e 44 45   cdt1.CREATE INDE
         1029  +|    192: 58 20 74 32 63 c4 20 4f 4e 20 74 32 28 63 2c 64   X t2c. ON t2(c,d
         1030  +|    208: 29 28 05 06 17 01 11 11 3d 74 61 6c 36 74 62 74   )(......=tal6tbt
         1031  +|    224: 65 32 04 43 52 45 41 54 45 20 54 41 42 4c 45 20   e2.CREATE TABLE 
         1032  +|    240: 74 00 04 00 00 00 00 00 00 00 00 00 00 00 00 00   t...............
         1033  +|    256: 00 00 00 00 00 00 22 07 06 17 11 11 01 30 e8 03   .............0..
         1034  +|    272: 62 6c 65 74 34 74 35 02 43 52 45 41 54 45 20 54   blet4t5.CREATE T
         1035  +|    288: 41 42 4c 45 20 74 34 28 94 29 2a 06 06 17 13 11   ABLE t4(.)*.....
         1036  +|    304: 01 3f 69 33 74 6e 65 78 78 74 64 33 ff 43 52 45   .?i3tnexxtd3.CRE
         1037  +|    320: 41 54 45 20 49 4e 44 45 58 20 74 33 78 20 4f 4e   ATE INDEX t3x ON
         1038  +|    336: 20 74 31 28 38 29 2e 04 06 17 15 11 01 45 69 6e    t1(8).......Ein
         1039  +|    352: 64 65 68 74 32 63 64 74 31 e5 43 52 45 41 54 45   deht2cdt1.CREATE
         1040  +|    368: 20 49 4e 44 45 58 20 74 32 63 c4 20 4f 4e 20 74    INDEX t2c. ON t
         1041  +|    384: 32 28 63 2c 64 29 28 05 06 17 01 11 11 3d 74 61   2(c,d)(......=ta
         1042  +|    400: 6c 32 74 62 74 65 32 04 43 52 45 41 54 45 20 54   l2tbte2.CREATE T
         1043  +|    416: 41 42 4c 45 20 74 33 28 63 2c 78 2c 65 2c 66 29   ABLE t3(c,x,e,f)
         1044  +|    432: 28 02 06 17 11 11 01 3d 74 61 9e 93 65 74 32 74   (......=ta..et2t
         1045  +|    448: 32 03 43 52 45 41 54 45 20 54 41 42 4c 45 20 74   2.CREATE TABLE t
         1046  +|    464: 32 28 63 2c 64 2c 65 2c 66 29 24 01 06 17 11 11   2(c,d,e,f)$.....
         1047  +|    480: 01 35 55 61 62 6c 88 74 31 74 31 02 43 52 45 41   .5Uabl.t1t1.CREA
         1048  +|    496: 54 45 20 54 41 42 4c 45 20 74 31 28 61 2c 62 29   TE TABLE t1(a,b)
         1049  +| page 2 offset 512
         1050  +|      0: 0d 00 00 00 0d 25 00 01 cf 00 01 fa 01 f3 01 de   .....%..........
         1051  +|     16: 01 00 00 00 fd 00 00 0d 00 00 00 00 45 20 54 41   ............E TA
         1052  +|     32: 42 4c 45 20 74 34 28 94 29 2a 06 06 17 13 11 01   BLE t4(.)*......
         1053  +|     48: 3f 69 33 74 6e 65 78 78 74 64 33 ff 43 52 45 a0   ?i3tnexxtd3.CRE.
         1054  +|     64: a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 74 13 11 01   ............t...
         1055  +|     80: 49 45 74 00 00 00 00 00 00 00 00 00 00 00 00 00   IEt.............
         1056  +| end x.db
         1057  +}]} {}
         1058  +
         1059  +do_catchsql_test 11.1 {
         1060  +  DELETE FROM t3 WHERE x IN (SELECT x FROM t4);
         1061  +} {1 {database disk image is malformed}}
  1010   1062   
  1011   1063   finish_test

Changes to test/countofview.test.

    35     35   } {1}
    36     36   
    37     37   do_execsql_test 1.3 {
    38     38     select count(*) from (
    39     39       select c from t2 union all select f from t3
    40     40     )
    41     41   } {3}
           42  +
           43  +# 2019-05-15
           44  +do_execsql_test 2.0 {
           45  +  CREATE TABLE t1(x);
           46  +  INSERT INTO t1 VALUES(1),(99),('abc');
           47  +  CREATE VIEW v1(x,y) AS SELECT x,1 FROM t1 UNION ALL SELECT x,2 FROM t1;
           48  +  SELECT count(*) FROM v1 WHERE x<>1;
           49  +} {4}
           50  +do_execsql_test 2.1 {
           51  +  SELECT count(*) FROM v1 GROUP BY y;
           52  +} {3 3}
           53  +
           54  +
    42     55   
    43     56   finish_test

Added test/expr2.test.

            1  +# 2019 May 20
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +# This file implements regression tests for SQLite library.  The
           12  +# focus of this file is testing expressions.
           13  +#
           14  +
           15  +set testdir [file dirname $argv0]
           16  +source $testdir/tester.tcl
           17  +set testprefix expr2
           18  +
           19  +do_execsql_test 1.0 {
           20  +  CREATE TABLE t0(c0);
           21  +  INSERT INTO t0(c0) VALUES ('val');
           22  +}
           23  +
           24  +do_execsql_test 1.1 {
           25  +  SELECT * FROM t0 WHERE (
           26  +      ( (0 IS NOT FALSE) OR NOT (0 IS FALSE OR (t0.c0 = 1)) ) IS 0
           27  +  )
           28  +} {val}
           29  +
           30  +do_execsql_test 1.2.1 {
           31  +  SELECT 
           32  +      ( (0 IS NOT FALSE) OR NOT (0 IS FALSE OR (t0.c0 = 1)) ) IS 0
           33  +  FROM t0 
           34  +} {1}
           35  +
           36  +do_execsql_test 1.2.2 {
           37  +  SELECT 
           38  +      ( (0 IS NOT FALSE) OR NOT (0 IS 0 OR (t0.c0 = 1)) ) IS 0
           39  +  FROM t0 
           40  +} {1}
           41  +
           42  +do_execsql_test 1.3 {
           43  +  SELECT ( (0 IS NOT FALSE) OR NOT (0 IS FALSE OR (t0.c0 = 1)) ) FROM t0 
           44  +} {0}
           45  +
           46  +do_execsql_test 1.4.1 {
           47  +  SELECT (0 IS NOT FALSE) FROM t0 
           48  +} {0}
           49  +do_execsql_test 1.4.2 {
           50  +  SELECT NOT (0 IS FALSE OR (t0.c0 = 1)) FROM t0 
           51  +} {0}
           52  +
           53  +
           54  +finish_test

Changes to test/fts3corrupt4.test.

  1942   1942   |   4064: 69 74 79 2d 63 68 65 63 6b 09 02 02 1b 72 65 62   ity-check....reb
  1943   1943   |   4080: 75 69 6c 64 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   uild....optimize
  1944   1944   | end crash-c666cfde112dee.db
  1945   1945   }]} {}
  1946   1946   
  1947   1947   do_catchsql_test 13.1 {
  1948   1948     SELECT quote(matchinfo(t1,'pcxybs'))==0 FROM t1 WHERE b MATCH 'e*';
  1949         -} {0 {0 0}}
         1949  +} {0 {}}
  1950   1950   
  1951   1951   #-------------------------------------------------------------------------
  1952   1952   reset_db
  1953   1953   do_test 14.0 {
  1954   1954     sqlite3 db {}
  1955   1955     db deserialize [decode_hexdb {
  1956   1956   | size 28672 pagesize 4096 filename crash-f7b636a855e1d2.db
................................................................................
  2822   2822   |     16: 2d 63 68 65 63 6b 09 02 02 1b 72 65 62 75 69 6c   -check....rebuil
  2823   2823   |     32: 64 0a 01 02 1d 6f 70 74 69 6d 69 7a 65 00 00 00   d....optimize...
  2824   2824   | end crash-4ce32d0608aff1.db
  2825   2825   }]} {}
  2826   2826   
  2827   2827   do_catchsql_test 18.1 {
  2828   2828     SELECT quote(matchinfo(t1,'pcxybs'))==0 FROM t1 WHERE b MATCH 'e*';
  2829         -} {0 0}
         2829  +} {0 {}}
  2830   2830   
  2831   2831   #-------------------------------------------------------------------------
  2832   2832   reset_db
  2833   2833   do_test 19.0 {
  2834   2834     sqlite3 db {}
  2835   2835     db deserialize [decode_hexdb {
  2836   2836   | size 28672 pagesize 4096 filename crash-526ea445f41c02.db
................................................................................
  4396   4396       INSERT INTO t1( a ) SELECT randomblob(3000) FROM t2 ;
  4397   4397   } {0 {}}
  4398   4398   
  4399   4399   do_catchsql_test 25.6 {
  4400   4400     INSERT INTO t1(t1) SELECT x FROM t2;
  4401   4401     INSERT INTO t1(t1) SELECT x FROM t2;
  4402   4402   } {1 {database disk image is malformed}}
         4403  +
         4404  +#-------------------------------------------------------------------------
         4405  +reset_db
         4406  +do_test 26.0 {
         4407  +  sqlite3 db {}
         4408  +  db deserialize [decode_hexdb {
         4409  +.open --hexdb
         4410  +| size 28672 pagesize 4096 filename crash-26682721375870.db
         4411  +| page 1 offset 0
         4412  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         4413  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 00   .....@  ........
         4414  +|     96: 00 00 00 00 0d 0e b1 00 06 0d a4 00 0f 8d 0f 21   ...............!
         4415  +|    112: 0e b9 0d c8 0e 7e 0d a4 00 00 00 00 00 00 00 00   .....~..........
         4416  +|   3488: 00 00 00 00 22 07 06 17 11 11 01 31 74 61 62 6c   ...........1tabl
         4417  +|   3504: 65 74 32 74 32 07 43 52 45 41 54 45 20 54 41 42   et2t2.CREATE TAB
         4418  +|   3520: 4c 45 20 74 32 28 78 29 81 33 05 07 17 1f 1f 01   LE t2(x).3......
         4419  +|   3536: 82 35 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72   .5tablet1_segdir
         4420  +|   3552: 74 31 5f 73 65 67 64 69 72 05 43 52 45 41 54 45   t1_segdir.CREATE
         4421  +|   3568: 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69    TABLE 't1_segdi
         4422  +|   3584: 72 27 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 51   r'(level INTEGEQ
         4423  +|   3600: 2c 69 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61   ,idx INTEGER,sta
         4424  +|   3616: 72 74 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52   rt_block INTEGER
         4425  +|   3632: 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63   ,leaves_end_bloc
         4426  +|   3648: 6b 20 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c   k INTEGER,end_bl
         4427  +|   3664: 6f 63 6b 20 49 4e 54 45 47 45 62 2c 72 6f 6f 74   ock INTEGEb,root
         4428  +|   3680: 20 42 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45    BLOB,PRIMARY KE
         4429  +|   3696: 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 06   Y(level, idx))1.
         4430  +|   3712: 06 17 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74   ..E...indexsqlit
         4431  +|   3728: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73   e_autoindex_t1_s
         4432  +|   3744: 65 67 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72   egdir_1t1_segdir
         4433  +|   3760: 06 0f c7 00 08 00 00 00 00 66 04 07 17 23 23 01   .........f...##.
         4434  +|   3776: 81 13 74 61 62 6c 65 74 31 5f 73 65 66 6d 65 6e   ..tablet1_sefmen
         4435  +|   3792: 74 73 74 31 5f 73 65 67 6d 65 6e 74 73 04 43 52   tst1_segments.CR
         4436  +|   3808: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73   EATE TABLE 't1_s
         4437  +|   3824: 65 67 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64   egments'(blockid
         4438  +|   3840: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59    INTEGER PRIMARY
         4439  +|   3856: 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42    KEY, block BLOB
         4440  +|   3872: 29 6a 03 07 17 21 21 01 81 1f 74 61 62 6c 65 74   )j...!!...tablet
         4441  +|   3888: 31 5f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74   1_contentt1_cont
         4442  +|   3904: 65 6e 74 03 43 52 45 41 54 45 20 54 41 42 4c 45   ent.CREATE TABLE
         4443  +|   3920: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f    't1_content'(do
         4444  +|   3936: 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   cid INTEGER PRIM
         4445  +|   3952: 41 52 59 20 4b 45 59 2c 20 27 63 30 61 27 2c 20   ARY KEY, 'c0a', 
         4446  +|   3968: 27 63 31 62 27 2c 20 27 63 32 63 27 29 38 02 06   'c1b', 'c2c')8..
         4447  +|   3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52   ...._tablet1t1CR
         4448  +|   4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42   EATE VIRTUAL TAB
         4449  +|   4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33   LE t1 USING fts3
         4450  +|   4032: 28 61 2c 62 2c 63 29 00 00 00 00 00 00 00 00 00   (a,b,c).........
         4451  +| page 3 offset 8192
         4452  +|      0: 0d 00 00 00 25 0b 48 00 0f d8 0f af 0f 86 0f 74   ....%.H........t
         4453  +|     16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5   .a.N./..........
         4454  +|     32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 0d ef 00 00   ...t.[.@.$......
         4455  +|   2880: 00 00 00 00 00 00 00 00 81 3f 25 06 00 82 7f 00   .........?%.....
         4456  +|   2896: 00 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e   .COMPILER=gcc-5.
         4457  +|   2912: 34 23 00 20 32 2f 31 36 30 36 30 39 20 44 45 42   4#. 2/160609 DEB
         4458  +|   2928: 55 47 20 45 4e 41 42 4c 45 20 44 42 53 54 41 54   UG ENABLE DBSTAT
         4459  +|   2944: 20 56 54 41 42 20 45 4e 41 42 4c 45 20 46 54 53    VTAB ENABLE FTS
         4460  +|   2960: 34 20 45 4e 41 42 4c 45 20 46 54 53 35 20 45 4e   4 ENABLE FTS5 EN
         4461  +|   2976: 41 42 4c 45 20 47 45 4f 50 4f 4c 59 20 45 4e 41   ABLE GEOPOLY ENA
         4462  +|   2992: 42 4c 45 20 4a 53 4f 4e 31 20 45 4e 41 42 4c 45   BLE JSON1 ENABLE
         4463  +|   3008: 20 4d 45 4d 53 59 53 35 20 45 4e 41 42 4c 45 20    MEMSYS5 ENABLE 
         4464  +|   3024: 52 54 52 45 45 20 4d 41 58 20 4d 45 4d 4f 52 59   RTREE MAX MEMORY
         4465  +|   3040: 3d 35 30 30 30 30 30 30 30 20 4f 4d 49 54 20 4c   =50000000 OMIT L
         4466  +|   3056: 4f 41 44 20 45 58 54 45 4e 53 59 4f 4e 20 54 48   OAD EXTENSYON TH
         4467  +|   3072: 52 45 41 44 53 41 46 45 3d 30 18 24 05 00 25 0f   READSAFE=0.$..%.
         4468  +|   3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49   .THREADSAFE=0XBI
         4469  +|   3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41   NARY.#..%..THREA
         4470  +|   3120: 44 53 41 46 45 3d 30 58 4e 4f 43 41 53 45 17 22   DSAFE=0XNOCASE..
         4471  +|   3136: 05 00 25 0f 17 54 38 52 45 41 44 53 41 46 45 3d   ..%..T8READSAFE=
         4472  +|   3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d   0XRTRIM.!..3..OM
         4473  +|   3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 fc 53 49 4f   IT LOAD EXTE.SIO
         4474  +|   3184: 4e 68 42 49 4e 4a c2 59 1f 20 05 00 33 0f 19 4f   NhBINJ.Y. ..3..O
         4475  +|   3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49   MIT LOAD EXTENSI
         4476  +|   3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17   ONXNOCASE....3..
         4477  +|   3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53   OMIT LOAD EXTENS
         4478  +|   3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f 19   IONXRTRIM....3..
         4479  +|   3264: 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 2f 30 30   MAX MEMORY=50/00
         4480  +|   3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f   000XBINARY....3.
         4481  +|   3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30   .MAX MEMORY=5000
         4482  +|   3312: 30 30 30 30 48 4e 4f 43 41 53 45 1e 1c 05 00 33   0000HNOCASE....3
         4483  +|   3328: 0f 17 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30   ..MAX MEMORY=500
         4484  +|   3344: 30 30 30 30 30 58 52 54 52 49 4d 18 1b 05 00 25   00000XRTRIM....%
         4485  +|   3360: 0f 19 45 4e 41 42 4c 45 20 52 54 52 45 45 58 42   ..ENABLE RTREEXB
         4486  +|   3376: 49 4e 41 52 59 18 1a 05 00 25 0f 19 45 4e 41 42   INARY....%..ENAB
         4487  +|   3392: 4c 45 20 52 54 52 45 45 58 4e 4f 53 41 53 45 17   LE RTREEXNOSASE.
         4488  +|   3408: 19 05 00 25 0f 17 45 4e 41 42 4c 45 20 52 54 52   ...%..ENABLE RTR
         4489  +|   3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45   EEXRTRIM....)..E
         4490  +|   3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 58 42 49   NABLE MEMSYS5XBI
         4491  +|   3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4e 41 42 4c   NARY....)..ENABL
         4492  +|   3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 53 45   E MEMSYS5XNOCASE
         4493  +|   3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 4d 45   ....)..ENABLE ME
         4494  +|   3504: 4d 53 59 53 35 58 52 54 52 49 4d 18 15 05 00 25   MSYS5XRTRIM....%
         4495  +|   3520: 0f 19 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 58 42   ..ENABLE JSON1XB
         4496  +|   3536: 49 4e 41 52 59 18 14 05 00 25 0f 19 45 4e 42 42   INARY....%..ENBB
         4497  +|   3552: 4d 45 20 4a 53 4f 4e 31 58 4e 4f 43 41 53 45 17   ME JSON1XNOCASE.
         4498  +|   3568: 13 05 00 25 0f 17 45 4e 41 42 4c 45 20 4a 53 4f   ...%..ENABLE JSO
         4499  +|   3584: 4e 31 58 52 54 52 49 4d 1a 12 05 00 29 0f 19 45   N1XRTRIM....)..E
         4500  +|   3600: 4e 41 42 4c 45 20 47 45 4f 50 4f 4c 59 58 42 49   NABLE GEOPOLYXBI
         4501  +|   3616: 4e 41 52 59 1a 11 05 00 29 0f 19 45 4e 41 1e 4c   NARY....)..ENA.L
         4502  +|   3632: 45 20 47 45 4f 50 4f 4c 59 58 4e 4f 43 41 53 45   E GEOPOLYXNOCASE
         4503  +|   3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 45   ....)..ENABLE GE
         4504  +|   3664: 4f 50 4f 4c 59 58 62 54 52 49 4d 17 0f 05 00 23   OPOLYXbTRIM....#
         4505  +|   3680: 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 58 42 49   ..ENABLE FTS5XBI
         4506  +|   3696: 4e 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 4c   NARY....#..ENABL
         4507  +|   3712: 45 20 46 54 fc 35 58 4e 4f 43 41 53 45 16 0d 05   E FT.5XNOCASE...
         4508  +|   3728: 00 23 0f 17 45 4e 41 42 4c 45 20 46 54 53 35 58   .#..ENABLE FTS5X
         4509  +|   3744: 52 54 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42   RTRIM....#..ENAB
         4510  +|   3760: 4c 45 20 46 54 53 34 58 42 49 4e 41 52 59 17 0b   LE FTS4XBINARY..
         4511  +|   3776: 05 00 23 0f 19 45 4e 41 42 4c 45 20 46 54 53 35   ..#..ENABLE FTS5
         4512  +|   3792: 58 4e 4f 43 40 53 45 16 0a 05 00 23 0f 17 45 4e   XNOC@SE....#..EN
         4513  +|   3808: 41 42 4c 45 20 56 54 53 34 58 52 54 52 49 4d 1e   ABLE VTS4XRTRIM.
         4514  +|   3824: 09 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         4515  +|   3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 b3 58 1e   TAT VTABXBINA.X.
         4516  +|   3856: 08 05 00 31 0f 19 45 4e 40 42 4c 45 20 44 42 53   ...1..EN@BLE DBS
         4517  +|   3872: 54 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d   TAT VTABXNOCASE.
         4518  +|   3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 45 42 53   ...1..ENABLE EBS
         4519  +|   3904: 54 41 54 20 56 54 41 42 58 52 54 52 49 4d 11 06   TAT VTABXRTRIM..
         4520  +|   3920: 05 00 17 0f 19 44 45 42 55 47 58 42 49 4e 41 52   .....DEBUGXBINAR
         4521  +|   3936: 59 11 05 05 00 17 0f 19 44 45 42 55 47 58 4e 4f   Y.......DEBUGXNO
         4522  +|   3952: 43 41 53 45 10 04 05 00 17 0f 17 44 45 42 55 47   CASE.......DEBUG
         4523  +|   3968: 58 52 54 52 49 4d 27 03 05 00 43 0f 19 43 4f 4d   XRTRIM'...C..COM
         4524  +|   3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20   PILER=gcc-5.4.0 
         4525  +|   4000: 32 30 31 36 30 36 30 39 58 4b 19 4e 41 52 59 27   20160609XK.NARY'
         4526  +|   4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67   ...C..COMPILER=g
         4527  +|   4032: 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36 30   cc-5.4.0 2016060
         4528  +| page 5 offset 16384
         4529  +|      0: 0d 00 00 00 02 0b a0 00 0c ad 0b a0 00 00 00 00   ................
         4530  +|   2976: 82 0a 02 08 08 09 08 08 17 84 06 30 20 32 34 33   ...........0 243
         4531  +|   2992: 00 01 30 04 25 06 1b 00 00 08 32 30 31 36 30 36   ..0.%.....201606
         4532  +|   3008: 30 39 03 25 07 00 00 01 34 03 25 05 00 00 01 35   09.%....4.%....5
         4533  +|   3024: 03 25 04 00 01 07 30 30 30 30 30 30 30 03 25 1a   .%....0000000.%.
         4534  +|   3040: 00 00 08 63 6f 6d 70 69 6c 65 72 03 25 02 00 00   ...compiler.%...
         4535  +|   3056: 06 64 62 73 74 51 74 03 25 0a 00 01 04 65 62 75   .dbstQt.%....ebu
         4536  +|   3072: 67 03 25 08 00 00 06 65 6e 61 62 6c 65 09 25 09   g.%....enable.%.
         4537  +|   3088: 05 04 04 04 04 04 00 01 08 78 74 65 6e 73 69 6f   .........xtensio
         4538  +|   3104: 6e 03 25 1d 00 00 04 66 74 73 34 03 25 0d 00 03   n.%....fts4.%...
         4539  +|   3120: 01 35 03 25 0f 00 00 03 67 63 63 03 25 03 00 01   .5.%....gcc.%...
         4540  +|   3136: 06 65 6f 70 6f 6c 79 03 25 11 00 00 05 6a 73 6f   .eopoly.%....jso
         4541  +|   3152: 6e 31 03 25 13 00 00 04 6c 6f 61 64 03 25 1c 00   n1.%....load.%..
         4542  +|   3168: 00 03 6d 61 78 03 25 18 00 01 05 65 6d 6f 72 79   ..max.%....emory
         4543  +|   3184: 03 25 19 00 03 04 73 79 73 35 03 25 15 00 00 04   .%....sys5.%....
         4544  +|   3200: 6f 6d 69 74 03 25 1b 00 00 05 72 74 72 65 65 03   omit.%....rtree.
         4545  +|   3216: 25 17 00 00 0a 74 68 72 65 61 64 73 61 66 65 03   %....threadsafe.
         4546  +|   3232: 25 1e 00 00 04 76 74 61 62 03 25 0b 00 86 50 01   %....vtab.%...P.
         4547  +|   3248: 08 08 08 08 08 17 8d 12 30 20 38 33 35 00 01 30   ........0 835..0
         4548  +|   3264: 12 01 06 00 01 06 00 01 06 00 1e f3 00 01 03 00   ................
         4549  +|   3280: 01 03 00 00 08 32 30 31 36 30 36 30 39 09 01 07   .....20160609...
         4550  +|   3296: 00 01 07 00 01 07 00 00 01 34 09 01 05 00 01 05   .........4......
         4551  +|   3312: 00 01 05 00 00 01 35 09 01 04 00 01 04 00 01 04   ......5.........
         4552  +|   3328: 00 01 07 30 30 30 30 2f 30 30 09 1c 04 00 01 04   ...0000/00......
         4553  +|   3344: 00 01 04 00 00 06 62 69 6e 61 72 79 3c 03 01 02   ......binary<...
         4554  +|   3360: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02   ................
         4555  +|   3376: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00   ................
         4556  +|   3392: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03   ................
         4557  +|   3408: 01 02 02 00 03 01 02 02 00 00 08 63 6f 6d 70 69   ...........compi
         4558  +|   3424: 6c 65 72 09 01 02 00 01 02 00 01 02 00 00 06 64   ler............d
         4559  +|   3440: 62 73 74 61 74 09 07 03 00 01 03 00 01 03 00 01   bstat...........
         4560  +|   3456: 04 65 62 75 67 09 04 02 00 01 02 00 01 02 00 00   .ebug...........
         4561  +|   3472: 06 65 6e 61 62 6c 65 3f 07 02 00 01 02 00 01 02   .enable?........
         4562  +|   3488: 00 01 02 00 01 02 00 01 01 f0 01 02 00 57 02 00   .............W..
         4563  +|   3504: 01 02 00 01 02 00 01 02 00 01 02 00 01 02 10 01   ................
         4564  +|   3520: 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02   ................
         4565  +|   3536: 00 00 02 00 01 02 00 01 08 78 74 65 6e 73 69 6f   .........xtensio
         4566  +|   3552: 6e 09 1f 04 00 01 04 00 01 04 00 00 04 66 74 73   n............fts
         4567  +|   3568: 34 09 0a 03 00 01 03 00 01 03 00 03 01 35 09 0d   4............5..
         4568  +|   3584: 03 00 01 03 00 a9 03 00 00 03 67 63 63 09 01 03   ..........gcc...
         4569  +|   3600: 00 01 03 00 01 03 00 01 06 65 6f 70 6f 6c 79 09   .........eopoly.
         4570  +|   3616: 10 03 00 01 03 00 01 03 00 00 05 6a 73 6f 6e 31   ...........json1
         4571  +|   3632: 09 13 03 00 01 03 00 01 03 00 00 04 6c 6f 61 64   ............load
         4572  +|   3648: 09 1f 03 00 01 03 00 01 03 00 00 03 6d 61 78 09   ............max.
         4573  +|   3664: 1c 02 0b 31 02 00 01 02 00 01 05 65 6d 6f 72 79   ...1.......emory
         4574  +|   3680: 09 1c 03 00 01 03 00 01 03 00 03 04 73 79 73 35   ............sys5
         4575  +|   3696: 09 16 03 00 01 03 00 01 03 00 00 06 6e 6f 63 61   ............noca
         4576  +|   3712: 73 65 3c 02 01 02 02 00 03 01 02 02 00 03 01 02   se<.............
         4577  +|   3728: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02   ................
         4578  +|   3744: 00 03 01 02 02 00 f3 01 02 02 00 03 01 02 02 00   ................
         4579  +|   3760: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 00   ................
         4580  +|   3776: 04 6f 6d 69 74 09 1f 02 00 01 02 00 01 02 00 00   .omit...........
         4581  +|   3792: 05 72 74 72 65 65 09 19 03 00 01 03 00 01 03 00   .rtree..........
         4582  +|   3808: 03 02 69 6d 3c 01 01 02 02 00 03 01 02 02 00 03   ..im<...........
         4583  +|   3824: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01   ................
         4584  +|   3840: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02   ................
         4585  +|   3856: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02   ................
         4586  +|   3872: 00 00 0a 74 68 72 65 61 64 63 61 66 65 09 22 02   ...threadcafe...
         4587  +|   3888: 00 01 02 00 02 02 00 00 04 76 74 61 62 09 07 04   .........vtab...
         4588  +|   3904: 00 01 04 00 01 04 00 00 01 78 b4 01 01 01 01 02   .........x......
         4589  +|   3920: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00   ................
         4590  +|   3936: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01   ................
         4591  +|   3952: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01   ................
         4592  +|   3968: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01   ................
         4593  +|   3984: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02   ................
         4594  +|   4000: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00   ................
         4595  +|   4016: 01 01 01 02 00 01 01 01 02 00 01 00 01 02 00 01   ................
         4596  +|   4032: 01 01 02 00 01 01 00 e2 00 01 01 01 02 00 01 01   ................
         4597  +|   4048: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01   ................
         4598  +|   4064: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02   ................
         4599  +|   4080: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00   ................
         4600  +| page 6 offset 20480
         4601  +|      0: 0a 00 00 00 02 0f f5 00 0f fb 0f f5 00 00 00 00   ................
         4602  +|   4080: 00 00 00 00 00 05 04 08 09 01 02 04 04 08 08 09   ................
         4603  +| page 7 offset 24576
         4604  +|      0: 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
         4605  +|   4016: 00 00 00 00 00 00 00 00 0d 05 02 23 61 00 00 00   ...........#a...
         4606  +| end crash-26682721375870.db
         4607  +}]} {}
         4608  +
         4609  +do_execsql_test 26.1 {
         4610  +  SELECT count(*) FROM (
         4611  +    SELECT t1, (t1) FROM t1 WHERE b MATCH 'x'
         4612  +  )
         4613  +} 34
  4403   4614    
  4404   4615   finish_test
  4405   4616   

Added test/fts3corrupt5.test.

            1  +# 2019 May 22
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#*************************************************************************
           11  +#
           12  +#
           13  +
           14  +set testdir [file dirname $argv0]
           15  +source $testdir/tester.tcl
           16  +source $testdir/fts3_common.tcl
           17  +set testprefix fts3corrupt5
           18  +
           19  +# If SQLITE_ENABLE_FTS3 is defined, omit this file.
           20  +ifcapable !fts3 {
           21  +  finish_test
           22  +  return
           23  +}
           24  +
           25  +sqlite3_fts3_may_be_corrupt 1
           26  +
           27  +do_execsql_test 1.0 {
           28  +  BEGIN;
           29  +    CREATE VIRTUAL TABLE ft USING fts3(a, b, c);
           30  +    INSERT INTO ft VALUES('one', 'one', 'one');
           31  +  COMMIT;
           32  +}
           33  +
           34  +do_execsql_test 1.1 {
           35  +  SELECT * FROM ft WHERE ft MATCH 'b:one'
           36  +} {one one one}
           37  +
           38  +do_execsql_test 1.2 {
           39  +  SELECT quote(root) FROM ft_segdir;
           40  +} {X'00036F6E6509010201010201020200'}
           41  +
           42  +breakpoint
           43  +foreach {tn val q bCorrupt} {
           44  +  1 X'00036F6E650901'                   'b:one'  1
           45  +  2 X'00036F6E6509010201010201FFFFFF'   'c:one'  1
           46  +  3 X'00036F6E6501'                     'b:one'  1
           47  +  4 X'00036F6E650101'                   'b:one'  1
           48  +  5 X'00036F6E650100'                   'b:one'  0
           49  +} {
           50  +  do_execsql_test 1.3.$tn.1 "UPDATE ft_segdir SET root = $val"
           51  +
           52  +  set res {0 {}}
           53  +  if {$bCorrupt} { set res {1 {database disk image is malformed}}}
           54  +  do_catchsql_test 1.3.$tn.2 {
           55  +    SELECT * FROM ft WHERE ft MATCH $q
           56  +  } $res
           57  +}
           58  +
           59  +finish_test
           60  +

Changes to test/fuzzdata7.db.

cannot compute difference between binary files

Changes to test/fuzzdata8.db.

cannot compute difference between binary files

Changes to test/index7.test.

   322    322   do_eqp_test index7-6.4 {
   323    323     SELECT * FROM v4 WHERE d='xyz' AND c='def'
   324    324   } {SEARCH TABLE t4 USING INDEX i4 (c=?)}
   325    325   
   326    326   do_catchsql_test index7-6.5 {
   327    327     CREATE INDEX t5a ON t5(a) WHERE a=#1;
   328    328   } {1 {near "#1": syntax error}}
          329  +
          330  +do_execsql_test index7-7.0 {
          331  +  CREATE TABLE t6(x, y);
          332  +  INSERT INTO t6 VALUES(1, 1);
          333  +  INSERT INTO t6 VALUES(0, 0);
          334  +  SELECT * FROM t6 WHERE y IS TRUE ORDER BY x;
          335  +} {1 1}
          336  +
          337  +do_execsql_test index7-7.1 {
          338  +  CREATE INDEX i6 ON t6(x) WHERE y IS NOT TRUE;
          339  +  SELECT * FROM t6 WHERE y IS TRUE ORDER BY x;
          340  +} {1 1}
   329    341   
   330    342   
   331    343   finish_test

Changes to test/indexexpr2.test.

   273    273   do_execsql_test 6.2.2 {
   274    274     CREATE INDEX x1i2 ON x1( CAST(b AS TEXT) );
   275    275     SELECT a, b FROM x1 WHERE CAST(b AS TEXT) = 123;
   276    276   } {1 123   2 123}
   277    277   do_eqp_test 6.2.3 {
   278    278     SELECT a, b FROM x1 WHERE CAST(b AS TEXT) = 123;
   279    279   } {SEARCH TABLE x1 USING INDEX x1i2 (<expr>=?)}
          280  +
          281  +do_execsql_test 7.0 {
          282  +  CREATE TABLE IF NOT EXISTS t0(c0);
          283  +  INSERT INTO t0(c0) VALUES (-9223372036854775808);
          284  +  BEGIN;
          285  +}
          286  +do_catchsql_test 7.1 {
          287  +  CREATE INDEX i0 ON t0(ABS(c0));
          288  +} {1 {integer overflow}}
          289  +do_execsql_test 7.2 {
          290  +  COMMIT;
          291  +  SELECT sql FROM sqlite_master WHERE tbl_name = 't0';
          292  +  CREATE INDEX i0 ON t0(c0);
          293  +} {{CREATE TABLE t0(c0)}}
          294  +do_execsql_test 7.3 {
          295  +  REINDEX;
          296  +} {}
          297  +
   280    298   
   281    299   
   282    300   finish_test

Changes to test/intreal.test.

    42     42            max(1,intreal(2),intreal(3),4);
    43     43   } {4.0 4}
    44     44   do_execsql_test 180 {
    45     45     SELECT max(1.0,intreal(5),intreal(3),4.0),
    46     46            max(1,intreal(5),intreal(3),4);
    47     47   } {5.0 5.0}
    48     48   
           49  +#-------------------------------------------------------------------------
           50  +do_execsql_test 2.1 {
           51  +  CREATE TABLE t2(a REAL);
           52  +  INSERT INTO t2 VALUES( 836627109860825358 );
           53  +  SELECT substr(a,1,4) FROM t2 WHERE a = CAST(836627109860825358 AS REAL);
           54  +} {8.36}
           55  +
           56  +do_execsql_test 2.2 {
           57  +  CREATE INDEX i2 ON t2(a);
           58  +  SELECT substr(a,1,4) FROM t2 WHERE a = CAST(836627109860825358 AS REAL);
           59  +} {8.36}
           60  +
           61  +do_execsql_test 2.3 {
           62  +  CREATE TABLE t0 (c0);
           63  +  CREATE TABLE t1 (c1 REAL);
           64  +  INSERT INTO t1(c1) VALUES (8366271098608253588);
           65  +  INSERT INTO t0(c0) VALUES ('a');
           66  +}
           67  +set D [db one {SELECT c1 FROM t1}]
           68  +
           69  +do_execsql_test 2.4 {
           70  +  SELECT * FROM t1 WHERE (t1.c1 = CAST(8366271098608253588 AS REAL));
           71  +} $D
           72  +
           73  +do_execsql_test 2.5 {
           74  +  SELECT * FROM t0, t1 WHERE (t1.c1 = CAST(8366271098608253588 AS REAL));
           75  +} [list a $D]
    49     76   
           77  +do_execsql_test 2.6 {
           78  +  SELECT * FROM t0, t1 
           79  +  WHERE (
           80  +        t1.c1 >= CAST(8366271098608253588 AS REAL) 
           81  +    AND t1.c1 <= CAST(8366271098608253588 AS REAL)
           82  +  );
           83  +} [list a $D]
    50     84   
    51     85   
    52     86   finish_test

Changes to test/join5.test.

   301    301   do_eqp_test 7.4 {
   302    302     SELECT * FROM t3 LEFT JOIN t4 ON (t4.x = t3.x) WHERE (t4.y = ? OR t4.z = ?);
   303    303   } {
   304    304     QUERY PLAN
   305    305     |--SCAN TABLE t3
   306    306     `--SEARCH TABLE t4 USING INDEX t4xz (x=?)
   307    307   } 
          308  +
          309  +reset_db
          310  +do_execsql_test 8.0 {
          311  +  CREATE TABLE t0 (c0, c1, PRIMARY KEY (c0, c1));
          312  +  CREATE TABLE t1 (c0);
          313  +
          314  +  INSERT INTO t1 VALUES (2);
          315  +
          316  +  INSERT INTO t0 VALUES(0, 10);
          317  +  INSERT INTO t0 VALUES(1, 10);
          318  +  INSERT INTO t0 VALUES(2, 10);
          319  +  INSERT INTO t0 VALUES(3, 10);
          320  +}
          321  +
          322  +do_execsql_test 8.1 {
          323  +  SELECT * FROM t0, t1 
          324  +  WHERE (t0.c1 >= 1 OR t0.c1 < 1) AND t0.c0 IN (1, t1.c0) ORDER BY 1;
          325  +} {
          326  +  1 10 2
          327  +  2 10 2
          328  +}
   308    329   
   309    330   finish_test

Changes to test/jrnlmode.test.

    61     61   do_test jrnlmode-1.2 {
    62     62     execsql {
    63     63       PRAGMA journal_mode;
    64     64       PRAGMA main.journal_mode;
    65     65       PRAGMA temp.journal_mode;
    66     66     } 
    67     67   } [list persist persist [temp_journal_mode persist]]
    68         -do_test jrnlmode-1.4 {
           68  +do_test jrnlmode-1.4a {
           69  +  # When defensive is on, unable to set journal_mode to OFF
           70  +  sqlite3_db_config db DEFENSIVE 1
           71  +  execsql {
           72  +    PRAGMA journal_mode = off;
           73  +  } 
           74  +} {persist}
           75  +do_test jrnlmode-1.4b {
           76  +  # When defensive is on, unable to set journal_mode to OFF
           77  +  sqlite3_db_config db DEFENSIVE 0
    69     78     execsql {
    70     79       PRAGMA journal_mode = off;
    71     80     } 
    72     81   } {off}
    73     82   do_test jrnlmode-1.5 {
    74     83     execsql {
    75     84       PRAGMA journal_mode;

Changes to test/pragma4.test.

   244    244   do_test 4.6.3 { 
   245    245     execsql { DROP TABLE c2 } db2
   246    246   } {}
   247    247   do_execsql_test 4.6.4 { pragma foreign_key_check('c1') } {c1 1 t1 0}
   248    248   do_catchsql_test 4.6.5 { 
   249    249     pragma foreign_key_check('c2') 
   250    250   } {1 {no such table: c2}}
          251  +
          252  +do_execsql_test 5.0 {
          253  +  CREATE TABLE t4(a DEFAULT 'abc' /* comment */, b DEFAULT -1 -- comment
          254  +     , c DEFAULT +4.0 /* another comment */
          255  +  );
          256  +  PRAGMA table_info = t4;
          257  +} {
          258  +  0 a {} 0 'abc' 0 1 b {} 0 -1 0 2 c {} 0 +4.0 0
          259  +}
          260  +
   251    261   
   252    262   finish_test

Changes to test/quote.test.

    12     12   # focus of this file is the ability to specify table and column names
    13     13   # as quoted strings.
    14     14   #
    15     15   # $Id: quote.test,v 1.7 2007/04/25 11:32:30 drh Exp $
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
           19  +set testprefix quote
    19     20   
    20     21   # Create a table with a strange name and with strange column names.
    21     22   #
    22     23   do_test quote-1.0 {
    23     24     catchsql {CREATE TABLE '@abc' ( '#xyz' int, '!pqr' text );}
    24     25   } {0 {}}
    25     26   
................................................................................
    80     81   #
    81     82   do_test quote-1.6 {
    82     83     set r [catch {
    83     84       execsql {DROP TABLE '@abc'}
    84     85     } msg ]
    85     86     lappend r $msg
    86     87   } {0 {}}
    87         - 
           88  +
           89  +#-------------------------------------------------------------------------
           90  +# Check that it is not possible to use double-quotes for a string
           91  +# constant in a CHECK constraint or CREATE INDEX statement. However, 
           92  +# SQLite can load such a schema from disk.
           93  +#
           94  +reset_db 
           95  +do_execsql_test 2.0 {
           96  +  CREATE TABLE t1(x, y, z);
           97  +}
           98  +foreach {tn sql errname} {
           99  +  1 { CREATE TABLE xyz(a, b, c CHECK (c!="null") ) } null
          100  +  2 { CREATE INDEX i2 ON t1(x, y, z||"abc") }        abc
          101  +  3 { CREATE INDEX i3 ON t1("w") }                   w
          102  +  4 { CREATE INDEX i4 ON t1(x) WHERE z="w" }         w
          103  +} {
          104  +  do_catchsql_test 2.1.$tn $sql [list 1 "no such column: $errname"]
          105  +}
          106  +
          107  +do_execsql_test 2.2 {
          108  +  PRAGMA writable_schema = 1;
          109  +  CREATE TABLE xyz(a, b, c CHECK (c!="null") );
          110  +  CREATE INDEX i2 ON t1(x, y, z||"abc");
          111  +  CREATE INDEX i3 ON t1("w");
          112  +  CREATE INDEX i4 ON t1(x) WHERE z="w";
          113  +}
          114  +
          115  +db close
          116  +sqlite3 db test.db
          117  +
          118  +do_execsql_test 2.3.1 {
          119  +  INSERT INTO xyz VALUES(1, 2, 3);
          120  +}
          121  +do_catchsql_test 2.3.2 {
          122  +  INSERT INTO xyz VALUES(1, 2, 'null');
          123  +} {1 {CHECK constraint failed: xyz}}
          124  +
          125  +do_execsql_test 2.4 {
          126  +  INSERT INTO t1 VALUES(1, 2, 3);
          127  +  INSERT INTO t1 VALUES(4, 5, 'w');
          128  +  SELECT * FROM t1 WHERE z='w';
          129  +} {4 5 w}
          130  +do_execsql_test 2.5 {
          131  +  SELECT sql FROM sqlite_master;
          132  +} {
          133  +  {CREATE TABLE t1(x, y, z)}
          134  +  {CREATE TABLE xyz(a, b, c CHECK (c!="null") )}
          135  +  {CREATE INDEX i2 ON t1(x, y, z||"abc")}
          136  +  {CREATE INDEX i3 ON t1("w")}
          137  +  {CREATE INDEX i4 ON t1(x) WHERE z="w"}
          138  +}
          139  +
          140  +
    88    141   
    89    142   finish_test

Changes to test/view.test.

   707    707     INSERT INTO t16 VALUES(1, 1, 1);
   708    708     INSERT INTO t16 VALUES(2, 2, 2);
   709    709     INSERT INTO t16 VALUES(3, 3, 3);
   710    710     CREATE VIEW v16 AS SELECT max(a) AS mx, min(b) AS mn FROM t16 GROUP BY c;
   711    711   
   712    712     SELECT * FROM v16 AS one, v16 AS two WHERE one.mx=1;
   713    713   } {
          714  +  1 1 1 1 
          715  +  1 1 2 2 
          716  +  1 1 3 3
          717  +}
          718  +do_execsql_test view-26.1 {
          719  +  WITH v17(x,y) AS (SELECT max(a), min(b) FROM t16 GROUP BY c)
          720  +  SELECT * FROM v17 AS one, v17 AS two WHERE one.x=1;
          721  +} {
   714    722     1 1 1 1 
   715    723     1 1 2 2 
   716    724     1 1 3 3
   717    725   }
   718    726   
   719    727   finish_test

Changes to test/with1.test.

  1086   1086           )
  1087   1087           SELECT  2 FROM c,c,c,c,c,c,c,c,c
  1088   1088        )
  1089   1089        SELECT 3 FROM c,c,c,c,c,c,c,c,c
  1090   1090     )
  1091   1091     SELECT 4 FROM c,c,c,c,c,c,c,c,c;
  1092   1092   } {1 {too many FROM clause terms, max: 200}}
         1093  +
         1094  +# 2019-05-22
         1095  +# ticket https://www.sqlite.org/src/tktview/ce823231949d3abf42453c8f20
         1096  +#
         1097  +sqlite3 db :memory:
         1098  +do_execsql_test 23.1 {
         1099  +  CREATE TABLE t1(id INTEGER NULL PRIMARY KEY, name Text);
         1100  +  INSERT INTO t1 VALUES (1, 'john');
         1101  +  INSERT INTO t1 VALUES (2, 'james');
         1102  +  INSERT INTO t1 VALUES (3, 'jingle');
         1103  +  INSERT INTO t1 VALUES (4, 'himer');
         1104  +  INSERT INTO t1 VALUES (5, 'smith');
         1105  +  CREATE VIEW v2 AS
         1106  +    WITH t4(Name) AS (VALUES ('A'), ('B'))
         1107  +    SELECT Name Name FROM t4;
         1108  +  CREATE VIEW v3 AS
         1109  +    WITH t4(Att, Val, Act) AS (VALUES
         1110  +      ('C', 'D', 'E'),
         1111  +      ('F', 'G', 'H')
         1112  +    )
         1113  +    SELECT D.Id Id, P.Name Protocol, T.Att Att, T.Val Val, T.Act Act
         1114  +    FROM t1 D
         1115  +    CROSS JOIN v2 P
         1116  +    CROSS JOIN t4 T;
         1117  +  SELECT * FROM v3;
         1118  +} {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}
         1119  +
         1120  +#-------------------------------------------------------------------------
         1121  +reset_db
         1122  +do_execsql_test 24.1 {
         1123  +  CREATE TABLE t1(a, b, c);
         1124  +  CREATE VIEW v1 AS SELECT max(a), min(b) FROM t1 GROUP BY c;
         1125  +}
         1126  +do_test 24.1 {
         1127  +  set program [db eval {EXPLAIN SELECT 1 FROM v1,v1,v1}]
         1128  +  expr [lsearch $program OpenDup]>0
         1129  +} {1}
         1130  +do_execsql_test 24.2 {
         1131  +  ATTACH "" AS aux;
         1132  +  CREATE VIEW aux.v3 AS VALUES(1);
         1133  +  CREATE VIEW main.v3 AS VALUES(3);
         1134  +
         1135  +  CREATE VIEW aux.v2 AS SELECT * FROM v3;
         1136  +  CREATE VIEW main.v2 AS SELECT * FROM v3;
         1137  +
         1138  +  SELECT * FROM main.v2 AS a, aux.v2 AS b, aux.v2 AS c, main.v2 AS d;
         1139  +} {
         1140  +  3 1 1 3
         1141  +}
  1093   1142   
  1094   1143   finish_test

Changes to tool/mkpragmatab.tcl.

   377    377   
   378    378     NAME: rekey
   379    379     TYPE: KEY
   380    380     ARG:  1
   381    381     IF:   defined(SQLITE_HAS_CODEC)
   382    382   
   383    383     NAME: hexkey
   384         -  TYPE: HEXKEY
          384  +  TYPE: KEY
   385    385     ARG:  2
   386    386     IF:   defined(SQLITE_HAS_CODEC)
   387    387   
   388    388     NAME: hexrekey
   389         -  TYPE: HEXKEY
          389  +  TYPE: KEY
   390    390     ARG:  3
   391    391     IF:   defined(SQLITE_HAS_CODEC)
   392    392   
   393    393     NAME: textkey
   394    394     TYPE: KEY
   395    395     ARG:  4
   396    396     IF:   defined(SQLITE_HAS_CODEC)