From 63847496f14c813a5d80efd5b7de0f1294ffe1e3 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 16:07:11 +0200 Subject: Adding upstream version 3.45.1. Signed-off-by: Daniel Baumann --- test/8_3_names.test | 197 + test/affinity2.test | 136 + test/affinity3.test | 123 + test/aggerror.test | 78 + test/aggfault.test | 43 + test/aggnested.test | 487 + test/aggorderby.test | 162 + test/alias.test | 140 + test/all.test | 51 + test/alter.test | 986 + test/alter2.test | 470 + test/alter3.test | 443 + test/alter4.test | 427 + test/alterauth.test | 72 + test/alterauth2.test | 119 + test/altercol.test | 949 + test/altercorrupt.test | 181 + test/alterdropcol.test | 339 + test/alterdropcol2.test | 222 + test/alterfault.test | 41 + test/alterlegacy.test | 469 + test/altermalloc.test | 71 + test/altermalloc2.test | 127 + test/altermalloc3.test | 90 + test/alterqf.test | 120 + test/altertab.test | 1002 + test/altertab2.test | 363 + test/altertab3.test | 739 + test/altertrig.test | 162 + test/amatch1.test | 117 + test/analyze.test | 399 + test/analyze3.test | 766 + test/analyze4.test | 117 + test/analyze5.test | 247 + test/analyze6.test | 126 + test/analyze7.test | 114 + test/analyze8.test | 115 + test/analyze9.test | 1235 ++ test/analyzeC.test | 181 + test/analyzeD.test | 107 + test/analyzeE.test | 294 + test/analyzeF.test | 150 + test/analyzeG.test | 84 + test/analyzer1.test | 55 + test/async.test | 90 + test/async2.test | 126 + test/async3.test | 76 + test/async4.test | 168 + test/async5.test | 68 + test/atof1.test | 86 + test/atomic.test | 41 + test/atomic2.test | 95 + test/atrc.c | 150 + test/attach.test | 928 + test/attach2.test | 451 + test/attach3.test | 353 + test/attach4.test | 137 + test/attachmalloc.test | 78 + test/auth.test | 2678 +++ test/auth2.test | 160 + test/auth3.test | 134 + test/autoanalyze1.test | 123 + test/autoinc.test | 883 + test/autoindex1.test | 565 + test/autoindex2.test | 232 + test/autoindex3.test | 94 + test/autoindex4.test | 223 + test/autoindex5.test | 234 + test/autovacuum.test | 715 + test/autovacuum2.test | 87 + test/autovacuum_ioerr2.test | 132 + test/avfs.test | 395 + test/avtrans.test | 927 + test/backcompat.test | 524 + test/backup.test | 1004 + test/backup2.test | 187 + test/backup4.test | 108 + test/backup5.test | 65 + test/backup_ioerr.test | 286 + test/backup_malloc.test | 119 + test/badutf.test | 143 + test/badutf2.test | 127 + test/basexx1.test | 155 + test/bc_common.tcl | 75 + test/bestindex1.test | 344 + test/bestindex2.test | 145 + test/bestindex3.test | 185 + test/bestindex4.test | 182 + test/bestindex5.test | 252 + test/bestindex6.test | 113 + test/bestindex7.test | 82 + test/bestindex8.test | 463 + test/bestindex9.test | 104 + test/bestindexA.test | 135 + test/bestindexB.test | 87 + test/between.test | 143 + test/bigfile.test | 203 + test/bigfile2.test | 62 + test/bigmmap.test | 108 + test/bigrow.test | 223 + test/bigsort.test | 57 + test/bind.test | 758 + test/bind2.test | 63 + test/bindxfer.test | 76 + test/bitvec.test | 195 + test/blob.test | 147 + test/bloom1.test | 188 + test/boundary1.tcl | 289 + test/boundary1.test | 7645 ++++++++ test/boundary2.tcl | 445 + test/boundary2.test | 15198 +++++++++++++++ test/boundary3.tcl | 289 + test/boundary3.test | 12456 ++++++++++++ test/boundary4.tcl | 340 + test/boundary4.test | 343 + test/btree01.test | 156 + test/btree02.test | 62 + test/btreefault.test | 106 + test/busy.test | 139 + test/busy2.test | 171 + test/cache.test | 140 + test/cacheflush.test | 323 + test/cachespill.test | 77 + test/capi2.test | 803 + test/capi3.test | 1276 ++ test/capi3b.test | 145 + test/capi3c.test | 1401 ++ test/capi3d.test | 289 + test/capi3e.test | 126 + test/carray01.test | 159 + test/cast.test | 560 + test/cffault.test | 158 + test/changes.test | 88 + test/changes2.test | 94 + test/check.test | 615 + test/checkfault.test | 41 + test/chunksize.test | 41 + test/close.test | 89 + test/closure01.test | 295 + test/coalesce.test | 84 + test/collate1.test | 452 + test/collate2.test | 742 + test/collate3.test | 531 + test/collate4.test | 704 + test/collate5.test | 328 + test/collate6.test | 153 + test/collate7.test | 72 + test/collate8.test | 157 + test/collate9.test | 178 + test/collateA.test | 217 + test/collateB.test | 77 + test/colmeta.test | 110 + test/colname.test | 447 + test/columncount.test | 62 + test/conflict.test | 891 + test/conflict2.test | 858 + test/conflict3.test | 437 + test/contrib01.test | 90 + test/corrupt.test | 349 + test/corrupt2.test | 611 + test/corrupt3.test | 121 + test/corrupt4.test | 149 + test/corrupt5.test | 50 + test/corrupt6.test | 259 + test/corrupt7.test | 112 + test/corrupt8.test | 108 + test/corrupt9.test | 140 + test/corruptA.test | 83 + test/corruptB.test | 193 + test/corruptC.test | 428 + test/corruptD.test | 145 + test/corruptE.test | 152 + test/corruptF.test | 153 + test/corruptG.test | 75 + test/corruptH.test | 176 + test/corruptI.test | 258 + test/corruptJ.test | 80 + test/corruptK.test | 234 + test/corruptL.test | 1508 ++ test/corruptM.test | 186 + test/corruptN.test | 279 + test/cost.test | 289 + test/count.test | 251 + test/countofview.test | 107 + test/coveridxscan.test | 119 + test/crash.test | 411 + test/crash2.test | 133 + test/crash3.test | 190 + test/crash4.test | 102 + test/crash5.test | 127 + test/crash6.test | 118 + test/crash7.test | 116 + test/crash8.test | 419 + test/crashM.test | 80 + test/crashtest1.c | 96 + test/createtab.test | 154 + test/cse.test | 200 + test/csv01.test | 279 + test/ctime.test | 259 + test/cursorhint.test | 214 + test/cursorhint2.test | 204 + test/dataversion1.test | 87 + test/date.test | 576 + test/date2.test | 176 + test/date3.test | 149 + test/date4.test | 38 + test/dbdata.test | 115 + test/dbfuzz.c | 754 + test/dbfuzz001.test | 397 + test/dbfuzz2-seed1.db | Bin 0 -> 3584 bytes test/dbfuzz2.c | 402 + test/dbpage.test | 111 + test/dbpagefault.test | 86 + test/dbstatus.test | 457 + test/dbstatus2.test | 115 + test/decimal.test | 193 + test/default.test | 140 + test/delete.test | 443 + test/delete2.test | 119 + test/delete3.test | 57 + test/delete4.test | 272 + test/delete_db.test | 222 + test/descidx1.test | 365 + test/descidx2.test | 186 + test/descidx3.test | 155 + test/diskfull.test | 115 + test/distinct.test | 408 + test/distinct2.test | 316 + test/distinctagg.test | 217 + test/e_blobbytes.test | 79 + test/e_blobclose.test | 175 + test/e_blobopen.test | 553 + test/e_blobwrite.test | 208 + test/e_changes.test | 443 + test/e_createtable.test | 1970 ++ test/e_delete.test | 477 + test/e_droptrigger.test | 218 + test/e_dropview.test | 192 + test/e_expr.test | 1989 ++ test/e_fkey.test | 3047 +++ test/e_fts3.test | 707 + test/e_insert.test | 431 + test/e_reindex.test | 299 + test/e_resolve.test | 135 + test/e_select.test | 2174 +++ test/e_select2.test | 580 + test/e_totalchanges.test | 214 + test/e_update.test | 605 + test/e_uri.test | 465 + test/e_vacuum.test | 347 + test/e_wal.test | 231 + test/e_walauto.test | 214 + test/e_walckpt.test | 753 + test/e_walhook.test | 200 + test/emptytable.test | 50 + test/enc.test | 252 + test/enc2.test | 567 + test/enc3.test | 107 + test/enc4.test | 137 + test/eqp.test | 850 + test/errmsg.test | 118 + test/eval.test | 87 + test/exclusive.test | 540 + test/exclusive2.test | 324 + test/exec.test | 37 + test/exists.test | 199 + test/expr.test | 1084 ++ test/expr2.test | 54 + test/exprfault.test | 45 + test/extension01.test | 83 + test/external_reader.test | 74 + test/extraquick.test | 16 + test/fallocate.test | 157 + test/filectrl.test | 72 + test/filefmt.test | 254 + test/filter1.test | 237 + test/filter2.tcl | 132 + test/filter2.test | 156 + test/filterfault.test | 44 + test/fkey1.test | 286 + test/fkey2.test | 2047 ++ test/fkey3.test | 186 + test/fkey4.test | 57 + test/fkey5.test | 492 + test/fkey6.test | 229 + test/fkey7.test | 121 + test/fkey8.test | 253 + test/fkey_malloc.test | 134 + test/fordelete.test | 209 + test/format4.test | 66 + test/fp-speed-1.c | 164 + test/fpconv1.test | 44 + test/fts-9fd058691.test | 59 + test/fts3.test | 19 + test/fts3_common.tcl | 420 + test/fts3aa.test | 265 + test/fts3ab.test | 147 + test/fts3ac.test | 1219 ++ test/fts3ad.test | 106 + test/fts3ae.test | 85 + test/fts3af.test | 90 + test/fts3ag.test | 93 + test/fts3ah.test | 71 + test/fts3ai.test | 92 + test/fts3aj.test | 87 + test/fts3ak.test | 105 + test/fts3al.test | 73 + test/fts3am.test | 65 + test/fts3an.test | 218 + test/fts3ao.test | 250 + test/fts3atoken.test | 287 + test/fts3auto.test | 717 + test/fts3aux1.test | 531 + test/fts3aux2.test | 168 + test/fts3b.test | 230 + test/fts3c.test | 255 + test/fts3comp1.test | 115 + test/fts3conf.test | 256 + test/fts3corrupt.test | 234 + test/fts3corrupt2.test | 111 + test/fts3corrupt3.test | 66 + test/fts3corrupt4.test | 7666 ++++++++ test/fts3corrupt5.test | 59 + test/fts3corrupt6.test | 79 + test/fts3cov.test | 434 + test/fts3d.test | 372 + test/fts3defer.test | 531 + test/fts3defer2.test | 193 + test/fts3defer3.test | 84 + test/fts3drop.test | 61 + test/fts3dropmod.test | 44 + test/fts3e.test | 125 + test/fts3expr.test | 521 + test/fts3expr2.test | 166 + test/fts3expr3.test | 238 + test/fts3expr4.test | 91 + test/fts3expr5.test | 66 + test/fts3f.test | 57 + test/fts3fault.test | 263 + test/fts3fault2.test | 250 + test/fts3fault3.test | 54 + test/fts3first.test | 163 + test/fts3fuzz001.test | 141 + test/fts3integrity.test | 42 + test/fts3join.test | 107 + test/fts3malloc.test | 307 + test/fts3matchinfo.test | 556 + test/fts3matchinfo2.test | 35 + test/fts3misc.test | 326 + test/fts3near.test | 597 + test/fts3offsets.test | 135 + test/fts3prefix.test | 295 + test/fts3prefix2.test | 61 + test/fts3query.test | 293 + test/fts3rank.test | 69 + test/fts3rnd.test | 460 + test/fts3shared.test | 176 + test/fts3snippet.test | 592 + test/fts3snippet2.test | 59 + test/fts3sort.test | 184 + test/fts3tok1.test | 124 + test/fts3tok_err.test | 47 + test/fts3varint.test | 121 + test/fts4aa.test | 256 + test/fts4check.test | 223 + test/fts4content.test | 674 + test/fts4docid.test | 116 + test/fts4growth.test | 441 + test/fts4growth2.test | 92 + test/fts4incr.test | 77 + test/fts4intck1.test | 75 + test/fts4langid.test | 508 + test/fts4lastrowid.test | 72 + test/fts4merge.test | 347 + test/fts4merge2.test | 38 + test/fts4merge3.test | 105 + test/fts4merge4.test | 102 + test/fts4merge5.test | 58 + test/fts4min.test | 53 + test/fts4noti.test | 230 + test/fts4onepass.test | 160 + test/fts4opt.test | 214 + test/fts4record.test | 120 + test/fts4rename.test | 43 + test/fts4umlaut.test | 64 + test/fts4unicode.test | 588 + test/fts4upfrom.test | 139 + test/full.test | 20 + test/func.test | 1556 ++ test/func2.test | 511 + test/func3.test | 211 + test/func4.test | 758 + test/func5.test | 64 + test/func6.test | 183 + test/func7.test | 251 + test/func8.test | 64 + test/func9.test | 40 + test/fuzz-oss1.test | 2007 ++ test/fuzz.test | 379 + test/fuzz2.test | 139 + test/fuzz3.test | 175 + test/fuzz4.test | 82 + test/fuzz_common.tcl | 392 + test/fuzz_malloc.test | 100 + test/fuzzcheck.c | 2557 +++ test/fuzzdata1.db | Bin 0 -> 4421632 bytes test/fuzzdata2.db | Bin 0 -> 17021952 bytes test/fuzzdata3.db | Bin 0 -> 11848704 bytes test/fuzzdata4.db | Bin 0 -> 2021376 bytes test/fuzzdata5.db | Bin 0 -> 7197696 bytes test/fuzzdata6.db | Bin 0 -> 1785856 bytes test/fuzzdata7.db | Bin 0 -> 16819200 bytes test/fuzzdata8.db | Bin 0 -> 4239360 bytes test/fuzzer1.test | 1820 ++ test/fuzzer2.test | 72 + test/fuzzerfault.test | 111 + test/fuzzinvariants.c | 510 + test/gcfault.test | 56 + test/gencol1.test | 669 + test/genesis.tcl | 1560 ++ test/having.test | 191 + test/hexlit.test | 125 + test/hidden.test | 153 + test/hook.test | 1025 + test/hook2.test | 218 + test/icu.test | 167 + test/ieee754.test | 60 + test/imposter1.test | 141 + test/in.test | 863 + test/in2.test | 67 + test/in3.test | 289 + test/in4.test | 520 + test/in5.test | 269 + test/in6.test | 119 + test/incrblob.test | 693 + test/incrblob2.test | 453 + test/incrblob3.test | 314 + test/incrblob4.test | 109 + test/incrblob_err.test | 140 + test/incrblobfault.test | 74 + test/incrcorrupt.test | 126 + test/incrvacuum.test | 892 + test/incrvacuum2.test | 213 + test/incrvacuum3.test | 153 + test/incrvacuum_ioerr.test | 182 + test/index.test | 769 + test/index2.test | 73 + test/index3.test | 96 + test/index4.test | 126 + test/index5.test | 80 + test/index6.test | 531 + test/index7.test | 355 + test/index8.test | 60 + test/index9.test | 96 + test/indexA.test | 350 + test/indexedby.test | 385 + test/indexexpr1.test | 633 + test/indexexpr2.test | 428 + test/indexfault.test | 352 + test/init.test | 82 + test/insert.test | 603 + test/insert2.test | 298 + test/insert3.test | 205 + test/insert4.test | 628 + test/insert5.test | 117 + test/insertfault.test | 36 + test/instr.test | 281 + test/instrfault.test | 92 + test/intarray.test | 116 + test/interrupt.test | 199 + test/interrupt2.test | 159 + test/intpkey.test | 645 + test/intreal.test | 116 + test/io.test | 645 + test/ioerr.test | 466 + test/ioerr2.test | 176 + test/ioerr3.test | 42 + test/ioerr4.test | 100 + test/ioerr5.test | 216 + test/ioerr6.test | 91 + test/istrue.test | 206 + test/join.test | 1292 ++ test/join2.test | 431 + test/join3.test | 62 + test/join4.test | 98 + test/join5.test | 454 + test/join6.test | 176 + test/join7.test | 355 + test/join8.test | 815 + test/join9.test | 565 + test/joinA.test | 277 + test/joinB.test | 7252 +++++++ test/joinC.test | 4594 +++++ test/joinD.test | 35136 +++++++++++++++++++++++++++++++++ test/joinE.test | 443 + test/joinF.test | 613 + test/joinH.test | 312 + test/journal1.test | 72 + test/journal2.test | 233 + test/journal3.test | 69 + test/jrnlmode.test | 585 + test/jrnlmode2.test | 128 + test/jrnlmode3.test | 149 + test/json/README.md | 66 + test/json/json-generator.tcl | 401 + test/json/json-q1.txt | 24 + test/json/json-speed-check.sh | 87 + test/json/jsonb-q1.txt | 24 + test/json101.test | 1167 ++ test/json102.test | 767 + test/json103.test | 93 + test/json104.test | 195 + test/json105.test | 113 + test/json106.test | 73 + test/json107.test | 86 + test/json501.test | 309 + test/json502.test | 67 + test/jsonb01.test | 53 + test/keyword1.test | 121 + test/kvtest.c | 1137 ++ test/lastinsert.test | 377 + test/laststmtchanges.test | 331 + test/lemon-test01.y | 75 + test/like.test | 1163 ++ test/like2.test | 1017 + test/like3.test | 278 + test/limit.test | 668 + test/limit2.test | 217 + test/loadext.test | 299 + test/loadext2.test | 168 + test/lock.test | 453 + test/lock2.test | 111 + test/lock3.test | 79 + test/lock4.test | 126 + test/lock5.test | 196 + test/lock6.test | 167 + test/lock7.test | 60 + test/lock_common.tcl | 206 + test/lookaside.test | 136 + test/main.test | 538 + test/make-where7.tcl | 120 + test/malloc.test | 954 + test/malloc3.test | 703 + test/malloc4.test | 194 + test/malloc5.test | 421 + test/malloc6.test | 55 + test/malloc7.test | 48 + test/malloc8.test | 95 + test/malloc9.test | 51 + test/mallocA.test | 127 + test/mallocAll.test | 66 + test/mallocB.test | 51 + test/mallocC.test | 122 + test/mallocD.test | 65 + test/mallocE.test | 48 + test/mallocF.test | 76 + test/mallocG.test | 73 + test/mallocH.test | 73 + test/mallocI.test | 75 + test/mallocJ.test | 73 + test/mallocK.test | 175 + test/mallocL.test | 42 + test/mallocM.test | 48 + test/malloc_common.tcl | 698 + test/malloctraceviewer.tcl | 253 + test/manydb.test | 102 + test/mem5.test | 66 + test/memdb.test | 431 + test/memdb1.test | 270 + test/memdb2.test | 76 + test/memjournal.test | 48 + test/memjournal2.test | 61 + test/memleak.test | 97 + test/memsubsys1.test | 189 + test/memsubsys2.test | 181 + test/merge1.test | 145 + test/minmax.test | 661 + test/minmax2.test | 426 + test/minmax3.test | 288 + test/minmax4.test | 236 + test/misc1.test | 775 + test/misc2.test | 444 + test/misc3.test | 355 + test/misc4.test | 233 + test/misc5.test | 1895 ++ test/misc6.test | 48 + test/misc7.test | 573 + test/misc8.test | 141 + test/misuse.test | 210 + test/mjournal.test | 162 + test/mmap1.test | 323 + test/mmap2.test | 87 + test/mmap3.test | 101 + test/mmap4.test | 104 + test/mmapcorrupt.test | 51 + test/mmapfault.test | 76 + test/mmapwarm.test | 81 + test/multiplex.test | 615 + test/multiplex2.test | 70 + test/multiplex3.test | 168 + test/multiplex4.test | 132 + test/mutex1.test | 224 + test/mutex2.test | 105 + test/nan.test | 375 + test/nockpt.test | 147 + test/nolock.test | 220 + test/normalize.test | 394 + test/notify1.test | 500 + test/notify2.test | 267 + test/notify3.test | 152 + test/notnull.test | 608 + test/notnull2.test | 114 + test/notnullfault.test | 55 + test/null.test | 307 + test/nulls1.test | 343 + test/numcast.test | 46 + test/numindex1.test | 79 + test/offset1.test | 202 + test/openv2.test | 55 + test/optfuzz-db01.c | 947 + test/optfuzz-db01.txt | 142 + test/optfuzz.c | 308 + test/orderby1.test | 569 + test/orderby2.test | 117 + test/orderby3.test | 123 + test/orderby4.test | 56 + test/orderby5.test | 187 + test/orderby6.test | 183 + test/orderby7.test | 106 + test/orderby8.test | 41 + test/orderby9.test | 62 + test/orderbyA.test | 147 + test/oserror.test | 142 + test/ossfuzz.c | 201 + test/ossshell.c | 100 + test/ovfl.test | 47 + test/pager1.test | 2956 +++ test/pager2.test | 171 + test/pager3.test | 37 + test/pager4.test | 99 + test/pagerfault.test | 1553 ++ test/pagerfault2.test | 98 + test/pagerfault3.test | 63 + test/pageropt.test | 209 + test/pagesize.test | 237 + test/parser1.test | 103 + test/pcache.test | 182 + test/pcache2.test | 84 + test/pendingrace.test | 123 + test/percentile.test | 209 + test/permutations.test | 1259 ++ test/pg_common.tcl | 175 + test/pragma.test | 2076 ++ test/pragma2.test | 275 + test/pragma3.test | 287 + test/pragma4.test | 268 + test/pragma5.test | 70 + test/pragmafault.test | 39 + test/prefixes.test | 88 + test/printf.test | 3836 ++++ test/printf2.test | 213 + test/progress.test | 178 + test/ptrchng.test | 223 + test/pushdown.test | 230 + test/queryonly.test | 72 + test/quick.test | 15 + test/quickcheck.test | 33 + test/quota-glob.test | 87 + test/quota.test | 532 + test/quota2.test | 302 + test/quote.test | 186 + test/randexpr1.tcl | 342 + test/randexpr1.test | 7837 ++++++++ test/rbu.test | 17 + test/rdonly.test | 95 + test/recover.test | 179 + test/regexp1.test | 335 + test/regexp2.test | 144 + test/reindex.test | 205 + test/resetdb.test | 300 + test/resolver01.test | 216 + test/returning1.test | 442 + test/returningfault.test | 36 + test/rollback.test | 152 + test/rollback2.test | 156 + test/rollbackfault.test | 82 + test/round1.test | 42 + test/rowallock.test | 67 + test/rowhash.test | 59 + test/rowid.test | 820 + test/rowvalue.test | 785 + test/rowvalue2.test | 279 + test/rowvalue3.test | 221 + test/rowvalue4.test | 305 + test/rowvalue5.test | 117 + test/rowvalue6.test | 36 + test/rowvalue7.test | 68 + test/rowvalue8.test | 59 + test/rowvalue9.test | 352 + test/rowvalueA.test | 76 + test/rowvaluefault.test | 89 + test/rowvaluevtab.test | 95 + test/rtree.test | 18 + test/run-wordcount.sh | 78 + test/savepoint.test | 1058 + test/savepoint2.test | 154 + test/savepoint4.test | 169 + test/savepoint5.test | 46 + test/savepoint6.test | 281 + test/savepoint7.test | 132 + test/savepointfault.test | 137 + test/scanstatus.test | 417 + test/scanstatus2.test | 334 + test/schema.test | 403 + test/schema2.test | 340 + test/schema3.test | 103 + test/schema4.test | 175 + test/schema5.test | 69 + test/schema6.test | 164 + test/schemafault.test | 31 + test/securedel.test | 100 + test/securedel2.test | 94 + test/seekscan1.test | 68 + test/select1.test | 1213 ++ test/select2.test | 185 + test/select3.test | 436 + test/select4.test | 1043 + test/select5.test | 262 + test/select6.test | 631 + test/select7.test | 218 + test/select8.test | 61 + test/select9.test | 472 + test/selectA.test | 1510 ++ test/selectB.test | 426 + test/selectC.test | 275 + test/selectD.test | 174 + test/selectE.test | 100 + test/selectF.test | 49 + test/selectG.test | 59 + test/selectH.test | 145 + test/session.test | 22 + test/sessionfuzz-data1.db | Bin 0 -> 258048 bytes test/sessionfuzz.c | 1015 + test/shared.test | 1184 ++ test/shared2.test | 139 + test/shared3.test | 142 + test/shared4.test | 236 + test/shared6.test | 255 + test/shared7.test | 58 + test/shared8.test | 113 + test/shared9.test | 230 + test/sharedA.test | 198 + test/sharedB.test | 65 + test/shared_err.test | 528 + test/sharedlock.test | 82 + test/shell1.test | 1292 ++ test/shell2.test | 275 + test/shell3.test | 138 + test/shell4.test | 156 + test/shell5.test | 573 + test/shell6.test | 129 + test/shell7.test | 52 + test/shell8.test | 196 + test/shell9.test | 148 + test/shmlock.test | 180 + test/shortread1.test | 52 + test/show_speedtest1_rtree.tcl | 57 + test/shrink.test | 55 + test/sidedelete.test | 92 + test/skipscan1.test | 432 + test/skipscan2.test | 205 + test/skipscan3.test | 73 + test/skipscan5.test | 182 + test/skipscan6.test | 191 + test/snapshot.test | 497 + test/snapshot2.test | 240 + test/snapshot3.test | 99 + test/snapshot4.test | 74 + test/snapshot_fault.test | 252 + test/snapshot_up.test | 185 + test/soak.test | 90 + test/softheap1.test | 74 + test/sort.test | 630 + test/sort2.test | 88 + test/sort3.test | 113 + test/sort4.test | 210 + test/sort5.test | 122 + test/sorterref.test | 56 + test/sortfault.test | 171 + test/speed1.test | 300 + test/speed1p.explain | 366 + test/speed1p.test | 349 + test/speed2.test | 339 + test/speed3.test | 172 + test/speed4.test | 231 + test/speed4p.explain | 283 + test/speed4p.test | 291 + test/speedtest1.c | 2678 +++ test/spellfix.test | 405 + test/spellfix2.test | 118 + test/spellfix3.test | 52 + test/spellfix4.test | 353 + test/sqldiff1.test | 88 + test/sqllimits1.test | 978 + test/sqllog.test | 113 + test/startup.c | 628 + test/stat.test | 328 + test/statfault.test | 54 + test/stmt.test | 104 + test/stmtvtab1.test | 82 + test/strict1.test | 165 + test/strict2.test | 158 + test/subjournal.test | 69 + test/subquery.test | 655 + test/subquery2.test | 218 + test/subselect.test | 210 + test/substr.test | 158 + test/subtype1.test | 77 + test/superlock.test | 268 + test/swarmvtab.test | 246 + test/swarmvtab2.test | 75 + test/swarmvtab3.test | 235 + test/swarmvtabfault.test | 65 + test/symlink.test | 238 + test/symlink2.test | 116 + test/sync.test | 105 + test/sync2.test | 161 + test/syscall.test | 278 + test/sysfault.test | 278 + test/tabfunc01.test | 332 + test/table.test | 840 + test/tableapi.test | 252 + test/tableopts.test | 76 + test/tclsqlite.test | 892 + test/tempdb.test | 98 + test/tempdb2.test | 99 + test/tempfault.test | 134 + test/temptable.test | 441 + test/temptable2.test | 360 + test/temptable3.test | 41 + test/temptrigger.test | 279 + test/tester.tcl | 2646 +++ test/testrunner.tcl | 1092 ++ test/testrunner_data.tcl | 640 + test/thread001.test | 147 + test/thread002.test | 105 + test/thread003.test | 189 + test/thread004.test | 79 + test/thread005.test | 238 + test/thread1.test | 173 + test/thread2.test | 120 + test/thread3.test | 77 + test/thread_common.tcl | 110 + test/threadtest1.c | 289 + test/threadtest2.c | 133 + test/threadtest3.c | 1584 ++ test/threadtest4.c | 484 + test/threadtest5.c | 339 + test/time-wordcount.sh | 34 + test/timediff1.test | 222 + test/tkt-02a8e81d44.test | 36 + test/tkt-18458b1a.test | 52 + test/tkt-26ff0c2d1e.test | 35 + test/tkt-2a5629202f.test | 76 + test/tkt-2d1a5c67d.test | 128 + test/tkt-2ea2425d34.test | 31 + test/tkt-31338dca7e.test | 178 + test/tkt-313723c356.test | 57 + test/tkt-385a5b56b9.test | 50 + test/tkt-38cb5df375.test | 326 + test/tkt-3998683a16.test | 46 + test/tkt-3a77c9714e.test | 86 + test/tkt-3fe897352e.test | 60 + test/tkt-4a03edc4c8.test | 46 + test/tkt-4c86b126f2.test | 49 + test/tkt-4dd95f6943.test | 151 + test/tkt-4ef7e3cfca.test | 68 + test/tkt-54844eea3f.test | 67 + test/tkt-5d863f876e.test | 55 + test/tkt-5e10420e8d.test | 50 + test/tkt-5ee23731f.test | 42 + test/tkt-6bfb98dfc0.test | 61 + test/tkt-752e1646fc.test | 30 + test/tkt-78e04e52ea.test | 66 + test/tkt-7a31705a7e6.test | 27 + test/tkt-7bbfb7d442.test | 154 + test/tkt-80ba201079.test | 195 + test/tkt-80e031a00f.test | 205 + test/tkt-8454a207b9.test | 73 + test/tkt-868145d012.test | 64 + test/tkt-8c63ff0ec.test | 48 + test/tkt-91e2e8ba6f.test | 52 + test/tkt-94c04eaadb.test | 72 + test/tkt-99378177930f87bd.test | 196 + test/tkt-9a8b09f8e6.test | 323 + test/tkt-9d68c883.test | 55 + test/tkt-9f2eb3abac.test | 78 + test/tkt-a7b7803e.test | 84 + test/tkt-a7debbe0.test | 102 + test/tkt-a8a0d2996a.test | 95 + test/tkt-b1d3a2e531.test | 109 + test/tkt-b351d95f9.test | 47 + test/tkt-b72787b1.test | 82 + test/tkt-b75a9ca6b0.test | 77 + test/tkt-ba7cbfaedc.test | 63 + test/tkt-bd484a090c.test | 38 + test/tkt-bdc6bbbb38.test | 90 + test/tkt-c48d99d690.test | 25 + test/tkt-c694113d5.test | 36 + test/tkt-cbd054fa6b.test | 107 + test/tkt-d11f09d36e.test | 61 + test/tkt-d635236375.test | 38 + test/tkt-d82e3f3721.test | 85 + test/tkt-f3e5abed55.test | 116 + test/tkt-f67b41381a.test | 58 + test/tkt-f777251dc7a.test | 105 + test/tkt-f7b4edec.test | 75 + test/tkt-f973c7ac31.test | 86 + test/tkt-fa7bf5ec.test | 39 + test/tkt-fc62af4523.test | 84 + test/tkt-fc7bd6358f.test | 78 + test/tkt1435.test | 111 + test/tkt1443.test | 180 + test/tkt1444.test | 56 + test/tkt1449.test | 262 + test/tkt1473.test | 728 + test/tkt1501.test | 36 + test/tkt1512.test | 54 + test/tkt1514.test | 27 + test/tkt1536.test | 38 + test/tkt1537.test | 122 + test/tkt1567.test | 82 + test/tkt1644.test | 111 + test/tkt1667.test | 83 + test/tkt1873.test | 72 + test/tkt2141.test | 61 + test/tkt2192.test | 140 + test/tkt2213.test | 29 + test/tkt2251.test | 108 + test/tkt2285.test | 56 + test/tkt2332.test | 67 + test/tkt2339.test | 100 + test/tkt2391.test | 49 + test/tkt2409.test | 229 + test/tkt2450.test | 48 + test/tkt2565.test | 92 + test/tkt2640.test | 124 + test/tkt2643.test | 39 + test/tkt2686.test | 81 + test/tkt2767.test | 90 + test/tkt2817.test | 72 + test/tkt2820.test | 94 + test/tkt2822.test | 346 + test/tkt2832.test | 67 + test/tkt2854.test | 139 + test/tkt2920.test | 78 + test/tkt2927.test | 674 + test/tkt2942.test | 62 + test/tkt3080.test | 77 + test/tkt3093.test | 86 + test/tkt3121.test | 50 + test/tkt3201.test | 105 + test/tkt3292.test | 61 + test/tkt3298.test | 80 + test/tkt3334.test | 86 + test/tkt3346.test | 67 + test/tkt3357.test | 64 + test/tkt3419.test | 73 + test/tkt3424.test | 53 + test/tkt3442.test | 62 + test/tkt3457.test | 105 + test/tkt3461.test | 67 + test/tkt3493.test | 153 + test/tkt3508.test | 38 + test/tkt3522.test | 43 + test/tkt3527.test | 123 + test/tkt3541.test | 35 + test/tkt3554.test | 67 + test/tkt3581.test | 54 + test/tkt35xx.test | 102 + test/tkt3630.test | 47 + test/tkt3718.test | 230 + test/tkt3731.test | 56 + test/tkt3757.test | 60 + test/tkt3761.test | 40 + test/tkt3762.test | 54 + test/tkt3773.test | 43 + test/tkt3791.test | 28 + test/tkt3793.test | 112 + test/tkt3810.test | 103 + test/tkt3824.test | 99 + test/tkt3832.test | 41 + test/tkt3838.test | 58 + test/tkt3841.test | 49 + test/tkt3871.test | 53 + test/tkt3879.test | 52 + test/tkt3911.test | 58 + test/tkt3918.test | 59 + test/tkt3922.test | 89 + test/tkt3929.test | 52 + test/tkt3935.test | 57 + test/tkt3992.test | 81 + test/tkt3997.test | 73 + test/tkt4018.test | 90 + test/tokenize.test | 65 + test/tpch01.test | 200 + test/trace.test | 269 + test/trace2.test | 155 + test/trace3.test | 346 + test/trans.test | 994 + test/trans2.test | 232 + test/trans3.test | 76 + test/transitive1.test | 429 + test/trigger1.test | 841 + test/trigger2.test | 792 + test/trigger3.test | 200 + test/trigger4.test | 200 + test/trigger5.test | 43 + test/trigger6.test | 82 + test/trigger7.test | 119 + test/trigger8.test | 53 + test/trigger9.test | 253 + test/triggerA.test | 230 + test/triggerB.test | 153 + test/triggerC.test | 1074 ++ test/triggerD.test | 219 + test/triggerE.test | 114 + test/triggerF.test | 71 + test/triggerG.test | 94 + test/triggerupfrom.test | 173 + test/trustschema1.test | 262 + test/tt3_checkpoint.c | 148 + test/tt3_index.c | 74 + test/tt3_lookaside1.c | 99 + test/tt3_shared.c | 55 + test/tt3_stress.c | 364 + test/tt3_vacuum.c | 90 + test/types.test | 325 + test/types2.test | 340 + test/types3.test | 99 + test/unhex.test | 102 + test/unionall.test | 453 + test/unionall2.test | 58 + test/unionallfault.test | 36 + test/unionvtab.test | 457 + test/unionvtabfault.test | 83 + test/unique.test | 261 + test/unique2.test | 86 + test/unixexcl.test | 129 + test/unordered.test | 69 + test/update.test | 790 + test/update2.test | 235 + test/upfrom1.tcl | 115 + test/upfrom1.test | 210 + test/upfrom2.test | 405 + test/upfrom3.test | 261 + test/upfrom4.test | 156 + test/upfromfault.test | 139 + test/upsert1.test | 271 + test/upsert2.test | 170 + test/upsert3.test | 58 + test/upsert4.test | 407 + test/upsert5.test | 411 + test/upsertfault.test | 38 + test/uri.test | 345 + test/uri2.test | 63 + test/userauth01.test | 257 + test/utf16align.test | 96 + test/vacuum-into.test | 187 + test/vacuum.test | 404 + test/vacuum2.test | 251 + test/vacuum3.test | 350 + test/vacuum4.test | 69 + test/vacuum5.test | 155 + test/vacuum6.test | 113 + test/vacuummem.test | 74 + test/varint.test | 34 + test/veryquick.test | 18 + test/view.test | 804 + test/view2.test | 49 + test/view3.test | 60 + test/vt02.c | 1024 + test/vtab1.test | 1593 ++ test/vtab2.test | 163 + test/vtab3.test | 140 + test/vtab4.test | 193 + test/vtab5.test | 154 + test/vtab6.test | 583 + test/vtab7.test | 207 + test/vtab8.test | 78 + test/vtab9.test | 70 + test/vtabA.test | 164 + test/vtabB.test | 79 + test/vtabC.test | 116 + test/vtabD.test | 69 + test/vtabE.test | 52 + test/vtabF.test | 45 + test/vtabH.test | 261 + test/vtabI.test | 126 + test/vtabJ.test | 154 + test/vtabK.test | 83 + test/vtab_alter.test | 103 + test/vtab_err.test | 87 + test/vtab_shared.test | 278 + test/vtabdistinct.test | 41 + test/vtabdrop.test | 127 + test/vtabrhs1.test | 76 + test/wal.test | 1550 ++ test/wal2.test | 1353 ++ test/wal3.test | 652 + test/wal4.test | 64 + test/wal5.test | 478 + test/wal6.test | 269 + test/wal64k.test | 63 + test/wal7.test | 118 + test/wal8.test | 91 + test/wal9.test | 94 + test/wal_common.tcl | 93 + test/walbak.test | 359 + test/walbig.test | 78 + test/walblock.test | 114 + test/walcksum.test | 338 + test/walcrash.test | 296 + test/walcrash2.test | 98 + test/walcrash3.test | 128 + test/walcrash4.test | 85 + test/walfault.test | 590 + test/walfault2.test | 91 + test/walhook.test | 109 + test/walmode.test | 393 + test/walnoshm.test | 184 + test/waloverwrite.test | 162 + test/walpersist.test | 142 + test/walprotocol.test | 201 + test/walprotocol2.test | 97 + test/walro.test | 300 + test/walro2.test | 411 + test/walrofault.test | 60 + test/walseh1.test | 148 + test/walsetlk.test | 199 + test/walshared.test | 62 + test/walslow.test | 231 + test/walthread.test | 529 + test/walvfs.test | 437 + test/where.test | 1707 ++ test/where2.test | 781 + test/where3.test | 518 + test/where4.test | 307 + test/where5.test | 288 + test/where6.test | 154 + test/where7.test | 23403 ++++++++++++++++++++++ test/where8.test | 773 + test/where9.test | 1004 + test/whereA.test | 189 + test/whereB.test | 543 + test/whereC.test | 70 + test/whereD.test | 433 + test/whereE.test | 68 + test/whereF.test | 312 + test/whereG.test | 402 + test/whereH.test | 139 + test/whereI.test | 99 + test/whereJ.test | 674 + test/whereK.test | 72 + test/whereL.test | 212 + test/whereM.test | 112 + test/wherefault.test | 83 + test/wherelfault.test | 82 + test/wherelimit.test | 342 + test/wherelimit2.test | 333 + test/widetab1.test | 156 + test/win32heap.test | 73 + test/win32lock.test | 184 + test/win32longpath.test | 139 + test/win32nolock.test | 126 + test/window1.test | 2379 +++ test/window2.tcl | 494 + test/window2.test | 976 + test/window3.tcl | 363 + test/window3.test | 40613 +++++++++++++++++++++++++++++++++++++++ test/window4.tcl | 424 + test/window4.test | 1390 ++ test/window5.test | 96 + test/window6.test | 371 + test/window7.tcl | 91 + test/window7.test | 186 + test/window8.tcl | 495 + test/window8.test | 6543 +++++++ test/window9.test | 285 + test/windowA.test | 309 + test/windowB.test | 486 + test/windowC.test | 85 + test/windowD.test | 94 + test/windowE.test | 58 + test/windowerr.tcl | 72 + test/windowerr.test | 116 + test/windowfault.test | 334 + test/windowpushd.test | 236 + test/with1.test | 1240 ++ test/with2.test | 628 + test/with3.test | 248 + test/with4.test | 52 + test/with5.test | 194 + test/with6.test | 377 + test/withM.test | 74 + test/without_rowid1.test | 490 + test/without_rowid2.test | 125 + test/without_rowid3.test | 2111 ++ test/without_rowid4.test | 764 + test/without_rowid5.test | 289 + test/without_rowid6.test | 134 + test/without_rowid7.test | 60 + test/wordcount.c | 659 + test/writecrash.test | 68 + test/zeroblob.test | 343 + test/zeroblobfault.test | 28 + test/zerodamage.test | 122 + test/zipfile.test | 887 + test/zipfile2.test | 243 + test/zipfilefault.test | 166 + 1220 files changed, 497651 insertions(+) create mode 100644 test/8_3_names.test create mode 100644 test/affinity2.test create mode 100644 test/affinity3.test create mode 100644 test/aggerror.test create mode 100644 test/aggfault.test create mode 100644 test/aggnested.test create mode 100644 test/aggorderby.test create mode 100644 test/alias.test create mode 100644 test/all.test create mode 100644 test/alter.test create mode 100644 test/alter2.test create mode 100644 test/alter3.test create mode 100644 test/alter4.test create mode 100644 test/alterauth.test create mode 100644 test/alterauth2.test create mode 100644 test/altercol.test create mode 100644 test/altercorrupt.test create mode 100644 test/alterdropcol.test create mode 100644 test/alterdropcol2.test create mode 100644 test/alterfault.test create mode 100644 test/alterlegacy.test create mode 100644 test/altermalloc.test create mode 100644 test/altermalloc2.test create mode 100644 test/altermalloc3.test create mode 100644 test/alterqf.test create mode 100644 test/altertab.test create mode 100644 test/altertab2.test create mode 100644 test/altertab3.test create mode 100644 test/altertrig.test create mode 100644 test/amatch1.test create mode 100644 test/analyze.test create mode 100644 test/analyze3.test create mode 100644 test/analyze4.test create mode 100644 test/analyze5.test create mode 100644 test/analyze6.test create mode 100644 test/analyze7.test create mode 100644 test/analyze8.test create mode 100644 test/analyze9.test create mode 100644 test/analyzeC.test create mode 100644 test/analyzeD.test create mode 100644 test/analyzeE.test create mode 100644 test/analyzeF.test create mode 100644 test/analyzeG.test create mode 100644 test/analyzer1.test create mode 100644 test/async.test create mode 100644 test/async2.test create mode 100644 test/async3.test create mode 100644 test/async4.test create mode 100644 test/async5.test create mode 100644 test/atof1.test create mode 100644 test/atomic.test create mode 100644 test/atomic2.test create mode 100644 test/atrc.c create mode 100644 test/attach.test create mode 100644 test/attach2.test create mode 100644 test/attach3.test create mode 100644 test/attach4.test create mode 100644 test/attachmalloc.test create mode 100644 test/auth.test create mode 100644 test/auth2.test create mode 100644 test/auth3.test create mode 100644 test/autoanalyze1.test create mode 100644 test/autoinc.test create mode 100644 test/autoindex1.test create mode 100644 test/autoindex2.test create mode 100644 test/autoindex3.test create mode 100644 test/autoindex4.test create mode 100644 test/autoindex5.test create mode 100644 test/autovacuum.test create mode 100644 test/autovacuum2.test create mode 100644 test/autovacuum_ioerr2.test create mode 100644 test/avfs.test create mode 100644 test/avtrans.test create mode 100644 test/backcompat.test create mode 100644 test/backup.test create mode 100644 test/backup2.test create mode 100644 test/backup4.test create mode 100644 test/backup5.test create mode 100644 test/backup_ioerr.test create mode 100644 test/backup_malloc.test create mode 100644 test/badutf.test create mode 100644 test/badutf2.test create mode 100644 test/basexx1.test create mode 100644 test/bc_common.tcl create mode 100644 test/bestindex1.test create mode 100644 test/bestindex2.test create mode 100644 test/bestindex3.test create mode 100644 test/bestindex4.test create mode 100644 test/bestindex5.test create mode 100644 test/bestindex6.test create mode 100644 test/bestindex7.test create mode 100644 test/bestindex8.test create mode 100644 test/bestindex9.test create mode 100644 test/bestindexA.test create mode 100644 test/bestindexB.test create mode 100644 test/between.test create mode 100644 test/bigfile.test create mode 100644 test/bigfile2.test create mode 100644 test/bigmmap.test create mode 100644 test/bigrow.test create mode 100644 test/bigsort.test create mode 100644 test/bind.test create mode 100644 test/bind2.test create mode 100644 test/bindxfer.test create mode 100644 test/bitvec.test create mode 100644 test/blob.test create mode 100644 test/bloom1.test create mode 100644 test/boundary1.tcl create mode 100644 test/boundary1.test create mode 100644 test/boundary2.tcl create mode 100644 test/boundary2.test create mode 100644 test/boundary3.tcl create mode 100644 test/boundary3.test create mode 100644 test/boundary4.tcl create mode 100644 test/boundary4.test create mode 100644 test/btree01.test create mode 100644 test/btree02.test create mode 100644 test/btreefault.test create mode 100644 test/busy.test create mode 100644 test/busy2.test create mode 100644 test/cache.test create mode 100644 test/cacheflush.test create mode 100644 test/cachespill.test create mode 100644 test/capi2.test create mode 100644 test/capi3.test create mode 100644 test/capi3b.test create mode 100644 test/capi3c.test create mode 100644 test/capi3d.test create mode 100644 test/capi3e.test create mode 100644 test/carray01.test create mode 100644 test/cast.test create mode 100644 test/cffault.test create mode 100644 test/changes.test create mode 100644 test/changes2.test create mode 100644 test/check.test create mode 100644 test/checkfault.test create mode 100644 test/chunksize.test create mode 100644 test/close.test create mode 100644 test/closure01.test create mode 100644 test/coalesce.test create mode 100644 test/collate1.test create mode 100644 test/collate2.test create mode 100644 test/collate3.test create mode 100644 test/collate4.test create mode 100644 test/collate5.test create mode 100644 test/collate6.test create mode 100644 test/collate7.test create mode 100644 test/collate8.test create mode 100644 test/collate9.test create mode 100644 test/collateA.test create mode 100644 test/collateB.test create mode 100644 test/colmeta.test create mode 100644 test/colname.test create mode 100644 test/columncount.test create mode 100644 test/conflict.test create mode 100644 test/conflict2.test create mode 100644 test/conflict3.test create mode 100644 test/contrib01.test create mode 100644 test/corrupt.test create mode 100644 test/corrupt2.test create mode 100644 test/corrupt3.test create mode 100644 test/corrupt4.test create mode 100644 test/corrupt5.test create mode 100644 test/corrupt6.test create mode 100644 test/corrupt7.test create mode 100644 test/corrupt8.test create mode 100644 test/corrupt9.test create mode 100644 test/corruptA.test create mode 100644 test/corruptB.test create mode 100644 test/corruptC.test create mode 100644 test/corruptD.test create mode 100644 test/corruptE.test create mode 100644 test/corruptF.test create mode 100644 test/corruptG.test create mode 100644 test/corruptH.test create mode 100644 test/corruptI.test create mode 100644 test/corruptJ.test create mode 100644 test/corruptK.test create mode 100644 test/corruptL.test create mode 100644 test/corruptM.test create mode 100644 test/corruptN.test create mode 100644 test/cost.test create mode 100644 test/count.test create mode 100644 test/countofview.test create mode 100644 test/coveridxscan.test create mode 100644 test/crash.test create mode 100644 test/crash2.test create mode 100644 test/crash3.test create mode 100644 test/crash4.test create mode 100644 test/crash5.test create mode 100644 test/crash6.test create mode 100644 test/crash7.test create mode 100644 test/crash8.test create mode 100644 test/crashM.test create mode 100644 test/crashtest1.c create mode 100644 test/createtab.test create mode 100644 test/cse.test create mode 100644 test/csv01.test create mode 100644 test/ctime.test create mode 100644 test/cursorhint.test create mode 100644 test/cursorhint2.test create mode 100644 test/dataversion1.test create mode 100644 test/date.test create mode 100644 test/date2.test create mode 100644 test/date3.test create mode 100644 test/date4.test create mode 100644 test/dbdata.test create mode 100644 test/dbfuzz.c create mode 100644 test/dbfuzz001.test create mode 100644 test/dbfuzz2-seed1.db create mode 100644 test/dbfuzz2.c create mode 100644 test/dbpage.test create mode 100644 test/dbpagefault.test create mode 100644 test/dbstatus.test create mode 100644 test/dbstatus2.test create mode 100644 test/decimal.test create mode 100644 test/default.test create mode 100644 test/delete.test create mode 100644 test/delete2.test create mode 100644 test/delete3.test create mode 100644 test/delete4.test create mode 100644 test/delete_db.test create mode 100644 test/descidx1.test create mode 100644 test/descidx2.test create mode 100644 test/descidx3.test create mode 100644 test/diskfull.test create mode 100644 test/distinct.test create mode 100644 test/distinct2.test create mode 100644 test/distinctagg.test create mode 100644 test/e_blobbytes.test create mode 100644 test/e_blobclose.test create mode 100644 test/e_blobopen.test create mode 100644 test/e_blobwrite.test create mode 100644 test/e_changes.test create mode 100644 test/e_createtable.test create mode 100644 test/e_delete.test create mode 100644 test/e_droptrigger.test create mode 100644 test/e_dropview.test create mode 100644 test/e_expr.test create mode 100644 test/e_fkey.test create mode 100644 test/e_fts3.test create mode 100644 test/e_insert.test create mode 100644 test/e_reindex.test create mode 100644 test/e_resolve.test create mode 100644 test/e_select.test create mode 100644 test/e_select2.test create mode 100644 test/e_totalchanges.test create mode 100644 test/e_update.test create mode 100644 test/e_uri.test create mode 100644 test/e_vacuum.test create mode 100644 test/e_wal.test create mode 100644 test/e_walauto.test create mode 100644 test/e_walckpt.test create mode 100644 test/e_walhook.test create mode 100644 test/emptytable.test create mode 100644 test/enc.test create mode 100644 test/enc2.test create mode 100644 test/enc3.test create mode 100644 test/enc4.test create mode 100644 test/eqp.test create mode 100644 test/errmsg.test create mode 100644 test/eval.test create mode 100644 test/exclusive.test create mode 100644 test/exclusive2.test create mode 100644 test/exec.test create mode 100644 test/exists.test create mode 100644 test/expr.test create mode 100644 test/expr2.test create mode 100644 test/exprfault.test create mode 100644 test/extension01.test create mode 100644 test/external_reader.test create mode 100644 test/extraquick.test create mode 100644 test/fallocate.test create mode 100644 test/filectrl.test create mode 100644 test/filefmt.test create mode 100644 test/filter1.test create mode 100644 test/filter2.tcl create mode 100644 test/filter2.test create mode 100644 test/filterfault.test create mode 100644 test/fkey1.test create mode 100644 test/fkey2.test create mode 100644 test/fkey3.test create mode 100644 test/fkey4.test create mode 100644 test/fkey5.test create mode 100644 test/fkey6.test create mode 100644 test/fkey7.test create mode 100644 test/fkey8.test create mode 100644 test/fkey_malloc.test create mode 100644 test/fordelete.test create mode 100644 test/format4.test create mode 100644 test/fp-speed-1.c create mode 100644 test/fpconv1.test create mode 100644 test/fts-9fd058691.test create mode 100644 test/fts3.test create mode 100644 test/fts3_common.tcl create mode 100644 test/fts3aa.test create mode 100644 test/fts3ab.test create mode 100644 test/fts3ac.test create mode 100644 test/fts3ad.test create mode 100644 test/fts3ae.test create mode 100644 test/fts3af.test create mode 100644 test/fts3ag.test create mode 100644 test/fts3ah.test create mode 100644 test/fts3ai.test create mode 100644 test/fts3aj.test create mode 100644 test/fts3ak.test create mode 100644 test/fts3al.test create mode 100644 test/fts3am.test create mode 100644 test/fts3an.test create mode 100644 test/fts3ao.test create mode 100644 test/fts3atoken.test create mode 100644 test/fts3auto.test create mode 100644 test/fts3aux1.test create mode 100644 test/fts3aux2.test create mode 100644 test/fts3b.test create mode 100644 test/fts3c.test create mode 100644 test/fts3comp1.test create mode 100644 test/fts3conf.test create mode 100644 test/fts3corrupt.test create mode 100644 test/fts3corrupt2.test create mode 100644 test/fts3corrupt3.test create mode 100644 test/fts3corrupt4.test create mode 100644 test/fts3corrupt5.test create mode 100644 test/fts3corrupt6.test create mode 100644 test/fts3cov.test create mode 100644 test/fts3d.test create mode 100644 test/fts3defer.test create mode 100644 test/fts3defer2.test create mode 100644 test/fts3defer3.test create mode 100644 test/fts3drop.test create mode 100644 test/fts3dropmod.test create mode 100644 test/fts3e.test create mode 100644 test/fts3expr.test create mode 100644 test/fts3expr2.test create mode 100644 test/fts3expr3.test create mode 100644 test/fts3expr4.test create mode 100644 test/fts3expr5.test create mode 100644 test/fts3f.test create mode 100644 test/fts3fault.test create mode 100644 test/fts3fault2.test create mode 100644 test/fts3fault3.test create mode 100644 test/fts3first.test create mode 100644 test/fts3fuzz001.test create mode 100644 test/fts3integrity.test create mode 100644 test/fts3join.test create mode 100644 test/fts3malloc.test create mode 100644 test/fts3matchinfo.test create mode 100644 test/fts3matchinfo2.test create mode 100644 test/fts3misc.test create mode 100644 test/fts3near.test create mode 100644 test/fts3offsets.test create mode 100644 test/fts3prefix.test create mode 100644 test/fts3prefix2.test create mode 100644 test/fts3query.test create mode 100644 test/fts3rank.test create mode 100644 test/fts3rnd.test create mode 100644 test/fts3shared.test create mode 100644 test/fts3snippet.test create mode 100644 test/fts3snippet2.test create mode 100644 test/fts3sort.test create mode 100644 test/fts3tok1.test create mode 100644 test/fts3tok_err.test create mode 100644 test/fts3varint.test create mode 100644 test/fts4aa.test create mode 100644 test/fts4check.test create mode 100644 test/fts4content.test create mode 100644 test/fts4docid.test create mode 100644 test/fts4growth.test create mode 100644 test/fts4growth2.test create mode 100644 test/fts4incr.test create mode 100644 test/fts4intck1.test create mode 100644 test/fts4langid.test create mode 100644 test/fts4lastrowid.test create mode 100644 test/fts4merge.test create mode 100644 test/fts4merge2.test create mode 100644 test/fts4merge3.test create mode 100644 test/fts4merge4.test create mode 100644 test/fts4merge5.test create mode 100644 test/fts4min.test create mode 100644 test/fts4noti.test create mode 100644 test/fts4onepass.test create mode 100644 test/fts4opt.test create mode 100644 test/fts4record.test create mode 100644 test/fts4rename.test create mode 100644 test/fts4umlaut.test create mode 100644 test/fts4unicode.test create mode 100644 test/fts4upfrom.test create mode 100644 test/full.test create mode 100644 test/func.test create mode 100644 test/func2.test create mode 100644 test/func3.test create mode 100644 test/func4.test create mode 100644 test/func5.test create mode 100644 test/func6.test create mode 100644 test/func7.test create mode 100644 test/func8.test create mode 100644 test/func9.test create mode 100644 test/fuzz-oss1.test create mode 100644 test/fuzz.test create mode 100644 test/fuzz2.test create mode 100644 test/fuzz3.test create mode 100644 test/fuzz4.test create mode 100644 test/fuzz_common.tcl create mode 100644 test/fuzz_malloc.test create mode 100644 test/fuzzcheck.c create mode 100644 test/fuzzdata1.db create mode 100644 test/fuzzdata2.db create mode 100644 test/fuzzdata3.db create mode 100644 test/fuzzdata4.db create mode 100644 test/fuzzdata5.db create mode 100644 test/fuzzdata6.db create mode 100644 test/fuzzdata7.db create mode 100644 test/fuzzdata8.db create mode 100644 test/fuzzer1.test create mode 100644 test/fuzzer2.test create mode 100644 test/fuzzerfault.test create mode 100644 test/fuzzinvariants.c create mode 100644 test/gcfault.test create mode 100644 test/gencol1.test create mode 100644 test/genesis.tcl create mode 100644 test/having.test create mode 100644 test/hexlit.test create mode 100644 test/hidden.test create mode 100644 test/hook.test create mode 100644 test/hook2.test create mode 100644 test/icu.test create mode 100644 test/ieee754.test create mode 100644 test/imposter1.test create mode 100644 test/in.test create mode 100644 test/in2.test create mode 100644 test/in3.test create mode 100644 test/in4.test create mode 100644 test/in5.test create mode 100644 test/in6.test create mode 100644 test/incrblob.test create mode 100644 test/incrblob2.test create mode 100644 test/incrblob3.test create mode 100644 test/incrblob4.test create mode 100644 test/incrblob_err.test create mode 100644 test/incrblobfault.test create mode 100644 test/incrcorrupt.test create mode 100644 test/incrvacuum.test create mode 100644 test/incrvacuum2.test create mode 100644 test/incrvacuum3.test create mode 100644 test/incrvacuum_ioerr.test create mode 100644 test/index.test create mode 100644 test/index2.test create mode 100644 test/index3.test create mode 100644 test/index4.test create mode 100644 test/index5.test create mode 100644 test/index6.test create mode 100644 test/index7.test create mode 100644 test/index8.test create mode 100644 test/index9.test create mode 100644 test/indexA.test create mode 100644 test/indexedby.test create mode 100644 test/indexexpr1.test create mode 100644 test/indexexpr2.test create mode 100644 test/indexfault.test create mode 100644 test/init.test create mode 100644 test/insert.test create mode 100644 test/insert2.test create mode 100644 test/insert3.test create mode 100644 test/insert4.test create mode 100644 test/insert5.test create mode 100644 test/insertfault.test create mode 100644 test/instr.test create mode 100644 test/instrfault.test create mode 100644 test/intarray.test create mode 100644 test/interrupt.test create mode 100644 test/interrupt2.test create mode 100644 test/intpkey.test create mode 100644 test/intreal.test create mode 100644 test/io.test create mode 100644 test/ioerr.test create mode 100644 test/ioerr2.test create mode 100644 test/ioerr3.test create mode 100644 test/ioerr4.test create mode 100644 test/ioerr5.test create mode 100644 test/ioerr6.test create mode 100644 test/istrue.test create mode 100644 test/join.test create mode 100644 test/join2.test create mode 100644 test/join3.test create mode 100644 test/join4.test create mode 100644 test/join5.test create mode 100644 test/join6.test create mode 100644 test/join7.test create mode 100644 test/join8.test create mode 100644 test/join9.test create mode 100644 test/joinA.test create mode 100644 test/joinB.test create mode 100644 test/joinC.test create mode 100644 test/joinD.test create mode 100644 test/joinE.test create mode 100644 test/joinF.test create mode 100644 test/joinH.test create mode 100644 test/journal1.test create mode 100644 test/journal2.test create mode 100644 test/journal3.test create mode 100644 test/jrnlmode.test create mode 100644 test/jrnlmode2.test create mode 100644 test/jrnlmode3.test create mode 100644 test/json/README.md create mode 100644 test/json/json-generator.tcl create mode 100644 test/json/json-q1.txt create mode 100755 test/json/json-speed-check.sh create mode 100644 test/json/jsonb-q1.txt create mode 100644 test/json101.test create mode 100644 test/json102.test create mode 100644 test/json103.test create mode 100644 test/json104.test create mode 100644 test/json105.test create mode 100644 test/json106.test create mode 100644 test/json107.test create mode 100644 test/json501.test create mode 100644 test/json502.test create mode 100644 test/jsonb01.test create mode 100644 test/keyword1.test create mode 100644 test/kvtest.c create mode 100644 test/lastinsert.test create mode 100644 test/laststmtchanges.test create mode 100644 test/lemon-test01.y create mode 100644 test/like.test create mode 100644 test/like2.test create mode 100644 test/like3.test create mode 100644 test/limit.test create mode 100644 test/limit2.test create mode 100644 test/loadext.test create mode 100644 test/loadext2.test create mode 100644 test/lock.test create mode 100644 test/lock2.test create mode 100644 test/lock3.test create mode 100644 test/lock4.test create mode 100644 test/lock5.test create mode 100644 test/lock6.test create mode 100644 test/lock7.test create mode 100644 test/lock_common.tcl create mode 100644 test/lookaside.test create mode 100644 test/main.test create mode 100644 test/make-where7.tcl create mode 100644 test/malloc.test create mode 100644 test/malloc3.test create mode 100644 test/malloc4.test create mode 100644 test/malloc5.test create mode 100644 test/malloc6.test create mode 100644 test/malloc7.test create mode 100644 test/malloc8.test create mode 100644 test/malloc9.test create mode 100644 test/mallocA.test create mode 100644 test/mallocAll.test create mode 100644 test/mallocB.test create mode 100644 test/mallocC.test create mode 100644 test/mallocD.test create mode 100644 test/mallocE.test create mode 100644 test/mallocF.test create mode 100644 test/mallocG.test create mode 100644 test/mallocH.test create mode 100644 test/mallocI.test create mode 100644 test/mallocJ.test create mode 100644 test/mallocK.test create mode 100644 test/mallocL.test create mode 100644 test/mallocM.test create mode 100644 test/malloc_common.tcl create mode 100644 test/malloctraceviewer.tcl create mode 100644 test/manydb.test create mode 100644 test/mem5.test create mode 100644 test/memdb.test create mode 100644 test/memdb1.test create mode 100644 test/memdb2.test create mode 100644 test/memjournal.test create mode 100644 test/memjournal2.test create mode 100644 test/memleak.test create mode 100644 test/memsubsys1.test create mode 100644 test/memsubsys2.test create mode 100644 test/merge1.test create mode 100644 test/minmax.test create mode 100644 test/minmax2.test create mode 100644 test/minmax3.test create mode 100644 test/minmax4.test create mode 100644 test/misc1.test create mode 100644 test/misc2.test create mode 100644 test/misc3.test create mode 100644 test/misc4.test create mode 100644 test/misc5.test create mode 100644 test/misc6.test create mode 100644 test/misc7.test create mode 100644 test/misc8.test create mode 100644 test/misuse.test create mode 100644 test/mjournal.test create mode 100644 test/mmap1.test create mode 100644 test/mmap2.test create mode 100644 test/mmap3.test create mode 100644 test/mmap4.test create mode 100644 test/mmapcorrupt.test create mode 100644 test/mmapfault.test create mode 100644 test/mmapwarm.test create mode 100644 test/multiplex.test create mode 100644 test/multiplex2.test create mode 100644 test/multiplex3.test create mode 100644 test/multiplex4.test create mode 100644 test/mutex1.test create mode 100644 test/mutex2.test create mode 100644 test/nan.test create mode 100644 test/nockpt.test create mode 100644 test/nolock.test create mode 100644 test/normalize.test create mode 100644 test/notify1.test create mode 100644 test/notify2.test create mode 100644 test/notify3.test create mode 100644 test/notnull.test create mode 100644 test/notnull2.test create mode 100644 test/notnullfault.test create mode 100644 test/null.test create mode 100644 test/nulls1.test create mode 100644 test/numcast.test create mode 100644 test/numindex1.test create mode 100644 test/offset1.test create mode 100644 test/openv2.test create mode 100644 test/optfuzz-db01.c create mode 100644 test/optfuzz-db01.txt create mode 100644 test/optfuzz.c create mode 100644 test/orderby1.test create mode 100644 test/orderby2.test create mode 100644 test/orderby3.test create mode 100644 test/orderby4.test create mode 100644 test/orderby5.test create mode 100644 test/orderby6.test create mode 100644 test/orderby7.test create mode 100644 test/orderby8.test create mode 100644 test/orderby9.test create mode 100644 test/orderbyA.test create mode 100644 test/oserror.test create mode 100644 test/ossfuzz.c create mode 100644 test/ossshell.c create mode 100644 test/ovfl.test create mode 100644 test/pager1.test create mode 100644 test/pager2.test create mode 100644 test/pager3.test create mode 100644 test/pager4.test create mode 100644 test/pagerfault.test create mode 100644 test/pagerfault2.test create mode 100644 test/pagerfault3.test create mode 100644 test/pageropt.test create mode 100644 test/pagesize.test create mode 100644 test/parser1.test create mode 100644 test/pcache.test create mode 100644 test/pcache2.test create mode 100644 test/pendingrace.test create mode 100644 test/percentile.test create mode 100644 test/permutations.test create mode 100644 test/pg_common.tcl create mode 100644 test/pragma.test create mode 100644 test/pragma2.test create mode 100644 test/pragma3.test create mode 100644 test/pragma4.test create mode 100644 test/pragma5.test create mode 100644 test/pragmafault.test create mode 100644 test/prefixes.test create mode 100644 test/printf.test create mode 100644 test/printf2.test create mode 100644 test/progress.test create mode 100644 test/ptrchng.test create mode 100644 test/pushdown.test create mode 100644 test/queryonly.test create mode 100644 test/quick.test create mode 100644 test/quickcheck.test create mode 100644 test/quota-glob.test create mode 100644 test/quota.test create mode 100644 test/quota2.test create mode 100644 test/quote.test create mode 100644 test/randexpr1.tcl create mode 100644 test/randexpr1.test create mode 100644 test/rbu.test create mode 100644 test/rdonly.test create mode 100644 test/recover.test create mode 100644 test/regexp1.test create mode 100644 test/regexp2.test create mode 100644 test/reindex.test create mode 100644 test/resetdb.test create mode 100644 test/resolver01.test create mode 100644 test/returning1.test create mode 100644 test/returningfault.test create mode 100644 test/rollback.test create mode 100644 test/rollback2.test create mode 100644 test/rollbackfault.test create mode 100644 test/round1.test create mode 100644 test/rowallock.test create mode 100644 test/rowhash.test create mode 100644 test/rowid.test create mode 100644 test/rowvalue.test create mode 100644 test/rowvalue2.test create mode 100644 test/rowvalue3.test create mode 100644 test/rowvalue4.test create mode 100644 test/rowvalue5.test create mode 100644 test/rowvalue6.test create mode 100644 test/rowvalue7.test create mode 100644 test/rowvalue8.test create mode 100644 test/rowvalue9.test create mode 100644 test/rowvalueA.test create mode 100644 test/rowvaluefault.test create mode 100644 test/rowvaluevtab.test create mode 100644 test/rtree.test create mode 100644 test/run-wordcount.sh create mode 100644 test/savepoint.test create mode 100644 test/savepoint2.test create mode 100644 test/savepoint4.test create mode 100644 test/savepoint5.test create mode 100644 test/savepoint6.test create mode 100644 test/savepoint7.test create mode 100644 test/savepointfault.test create mode 100644 test/scanstatus.test create mode 100644 test/scanstatus2.test create mode 100644 test/schema.test create mode 100644 test/schema2.test create mode 100644 test/schema3.test create mode 100644 test/schema4.test create mode 100644 test/schema5.test create mode 100644 test/schema6.test create mode 100644 test/schemafault.test create mode 100644 test/securedel.test create mode 100644 test/securedel2.test create mode 100644 test/seekscan1.test create mode 100644 test/select1.test create mode 100644 test/select2.test create mode 100644 test/select3.test create mode 100644 test/select4.test create mode 100644 test/select5.test create mode 100644 test/select6.test create mode 100644 test/select7.test create mode 100644 test/select8.test create mode 100644 test/select9.test create mode 100644 test/selectA.test create mode 100644 test/selectB.test create mode 100644 test/selectC.test create mode 100644 test/selectD.test create mode 100644 test/selectE.test create mode 100644 test/selectF.test create mode 100644 test/selectG.test create mode 100644 test/selectH.test create mode 100644 test/session.test create mode 100644 test/sessionfuzz-data1.db create mode 100644 test/sessionfuzz.c create mode 100644 test/shared.test create mode 100644 test/shared2.test create mode 100644 test/shared3.test create mode 100644 test/shared4.test create mode 100644 test/shared6.test create mode 100644 test/shared7.test create mode 100644 test/shared8.test create mode 100644 test/shared9.test create mode 100644 test/sharedA.test create mode 100644 test/sharedB.test create mode 100644 test/shared_err.test create mode 100644 test/sharedlock.test create mode 100644 test/shell1.test create mode 100644 test/shell2.test create mode 100644 test/shell3.test create mode 100644 test/shell4.test create mode 100644 test/shell5.test create mode 100644 test/shell6.test create mode 100644 test/shell7.test create mode 100644 test/shell8.test create mode 100644 test/shell9.test create mode 100644 test/shmlock.test create mode 100644 test/shortread1.test create mode 100644 test/show_speedtest1_rtree.tcl create mode 100644 test/shrink.test create mode 100644 test/sidedelete.test create mode 100644 test/skipscan1.test create mode 100644 test/skipscan2.test create mode 100644 test/skipscan3.test create mode 100644 test/skipscan5.test create mode 100644 test/skipscan6.test create mode 100644 test/snapshot.test create mode 100644 test/snapshot2.test create mode 100644 test/snapshot3.test create mode 100644 test/snapshot4.test create mode 100644 test/snapshot_fault.test create mode 100644 test/snapshot_up.test create mode 100644 test/soak.test create mode 100644 test/softheap1.test create mode 100644 test/sort.test create mode 100644 test/sort2.test create mode 100644 test/sort3.test create mode 100644 test/sort4.test create mode 100644 test/sort5.test create mode 100644 test/sorterref.test create mode 100644 test/sortfault.test create mode 100644 test/speed1.test create mode 100644 test/speed1p.explain create mode 100644 test/speed1p.test create mode 100644 test/speed2.test create mode 100644 test/speed3.test create mode 100644 test/speed4.test create mode 100644 test/speed4p.explain create mode 100644 test/speed4p.test create mode 100644 test/speedtest1.c create mode 100644 test/spellfix.test create mode 100644 test/spellfix2.test create mode 100644 test/spellfix3.test create mode 100644 test/spellfix4.test create mode 100644 test/sqldiff1.test create mode 100644 test/sqllimits1.test create mode 100644 test/sqllog.test create mode 100644 test/startup.c create mode 100644 test/stat.test create mode 100644 test/statfault.test create mode 100644 test/stmt.test create mode 100644 test/stmtvtab1.test create mode 100644 test/strict1.test create mode 100644 test/strict2.test create mode 100644 test/subjournal.test create mode 100644 test/subquery.test create mode 100644 test/subquery2.test create mode 100644 test/subselect.test create mode 100644 test/substr.test create mode 100644 test/subtype1.test create mode 100644 test/superlock.test create mode 100644 test/swarmvtab.test create mode 100644 test/swarmvtab2.test create mode 100644 test/swarmvtab3.test create mode 100644 test/swarmvtabfault.test create mode 100644 test/symlink.test create mode 100644 test/symlink2.test create mode 100644 test/sync.test create mode 100644 test/sync2.test create mode 100644 test/syscall.test create mode 100644 test/sysfault.test create mode 100644 test/tabfunc01.test create mode 100644 test/table.test create mode 100644 test/tableapi.test create mode 100644 test/tableopts.test create mode 100644 test/tclsqlite.test create mode 100644 test/tempdb.test create mode 100644 test/tempdb2.test create mode 100644 test/tempfault.test create mode 100644 test/temptable.test create mode 100644 test/temptable2.test create mode 100644 test/temptable3.test create mode 100644 test/temptrigger.test create mode 100644 test/tester.tcl create mode 100644 test/testrunner.tcl create mode 100644 test/testrunner_data.tcl create mode 100644 test/thread001.test create mode 100644 test/thread002.test create mode 100644 test/thread003.test create mode 100644 test/thread004.test create mode 100644 test/thread005.test create mode 100644 test/thread1.test create mode 100644 test/thread2.test create mode 100644 test/thread3.test create mode 100644 test/thread_common.tcl create mode 100644 test/threadtest1.c create mode 100644 test/threadtest2.c create mode 100644 test/threadtest3.c create mode 100644 test/threadtest4.c create mode 100644 test/threadtest5.c create mode 100644 test/time-wordcount.sh create mode 100644 test/timediff1.test create mode 100644 test/tkt-02a8e81d44.test create mode 100644 test/tkt-18458b1a.test create mode 100644 test/tkt-26ff0c2d1e.test create mode 100644 test/tkt-2a5629202f.test create mode 100644 test/tkt-2d1a5c67d.test create mode 100644 test/tkt-2ea2425d34.test create mode 100644 test/tkt-31338dca7e.test create mode 100644 test/tkt-313723c356.test create mode 100644 test/tkt-385a5b56b9.test create mode 100644 test/tkt-38cb5df375.test create mode 100644 test/tkt-3998683a16.test create mode 100644 test/tkt-3a77c9714e.test create mode 100644 test/tkt-3fe897352e.test create mode 100644 test/tkt-4a03edc4c8.test create mode 100644 test/tkt-4c86b126f2.test create mode 100644 test/tkt-4dd95f6943.test create mode 100644 test/tkt-4ef7e3cfca.test create mode 100644 test/tkt-54844eea3f.test create mode 100644 test/tkt-5d863f876e.test create mode 100644 test/tkt-5e10420e8d.test create mode 100644 test/tkt-5ee23731f.test create mode 100644 test/tkt-6bfb98dfc0.test create mode 100644 test/tkt-752e1646fc.test create mode 100644 test/tkt-78e04e52ea.test create mode 100644 test/tkt-7a31705a7e6.test create mode 100644 test/tkt-7bbfb7d442.test create mode 100644 test/tkt-80ba201079.test create mode 100644 test/tkt-80e031a00f.test create mode 100644 test/tkt-8454a207b9.test create mode 100644 test/tkt-868145d012.test create mode 100644 test/tkt-8c63ff0ec.test create mode 100644 test/tkt-91e2e8ba6f.test create mode 100644 test/tkt-94c04eaadb.test create mode 100644 test/tkt-99378177930f87bd.test create mode 100644 test/tkt-9a8b09f8e6.test create mode 100644 test/tkt-9d68c883.test create mode 100644 test/tkt-9f2eb3abac.test create mode 100644 test/tkt-a7b7803e.test create mode 100644 test/tkt-a7debbe0.test create mode 100644 test/tkt-a8a0d2996a.test create mode 100644 test/tkt-b1d3a2e531.test create mode 100644 test/tkt-b351d95f9.test create mode 100644 test/tkt-b72787b1.test create mode 100644 test/tkt-b75a9ca6b0.test create mode 100644 test/tkt-ba7cbfaedc.test create mode 100644 test/tkt-bd484a090c.test create mode 100644 test/tkt-bdc6bbbb38.test create mode 100644 test/tkt-c48d99d690.test create mode 100644 test/tkt-c694113d5.test create mode 100644 test/tkt-cbd054fa6b.test create mode 100644 test/tkt-d11f09d36e.test create mode 100644 test/tkt-d635236375.test create mode 100644 test/tkt-d82e3f3721.test create mode 100644 test/tkt-f3e5abed55.test create mode 100644 test/tkt-f67b41381a.test create mode 100644 test/tkt-f777251dc7a.test create mode 100644 test/tkt-f7b4edec.test create mode 100644 test/tkt-f973c7ac31.test create mode 100644 test/tkt-fa7bf5ec.test create mode 100644 test/tkt-fc62af4523.test create mode 100644 test/tkt-fc7bd6358f.test create mode 100644 test/tkt1435.test create mode 100644 test/tkt1443.test create mode 100644 test/tkt1444.test create mode 100644 test/tkt1449.test create mode 100644 test/tkt1473.test create mode 100644 test/tkt1501.test create mode 100644 test/tkt1512.test create mode 100644 test/tkt1514.test create mode 100644 test/tkt1536.test create mode 100644 test/tkt1537.test create mode 100644 test/tkt1567.test create mode 100644 test/tkt1644.test create mode 100644 test/tkt1667.test create mode 100644 test/tkt1873.test create mode 100644 test/tkt2141.test create mode 100644 test/tkt2192.test create mode 100644 test/tkt2213.test create mode 100644 test/tkt2251.test create mode 100644 test/tkt2285.test create mode 100644 test/tkt2332.test create mode 100644 test/tkt2339.test create mode 100644 test/tkt2391.test create mode 100644 test/tkt2409.test create mode 100644 test/tkt2450.test create mode 100644 test/tkt2565.test create mode 100644 test/tkt2640.test create mode 100644 test/tkt2643.test create mode 100644 test/tkt2686.test create mode 100644 test/tkt2767.test create mode 100644 test/tkt2817.test create mode 100644 test/tkt2820.test create mode 100644 test/tkt2822.test create mode 100644 test/tkt2832.test create mode 100644 test/tkt2854.test create mode 100644 test/tkt2920.test create mode 100644 test/tkt2927.test create mode 100644 test/tkt2942.test create mode 100644 test/tkt3080.test create mode 100644 test/tkt3093.test create mode 100644 test/tkt3121.test create mode 100644 test/tkt3201.test create mode 100644 test/tkt3292.test create mode 100644 test/tkt3298.test create mode 100644 test/tkt3334.test create mode 100644 test/tkt3346.test create mode 100644 test/tkt3357.test create mode 100644 test/tkt3419.test create mode 100644 test/tkt3424.test create mode 100644 test/tkt3442.test create mode 100644 test/tkt3457.test create mode 100644 test/tkt3461.test create mode 100644 test/tkt3493.test create mode 100644 test/tkt3508.test create mode 100644 test/tkt3522.test create mode 100644 test/tkt3527.test create mode 100644 test/tkt3541.test create mode 100644 test/tkt3554.test create mode 100644 test/tkt3581.test create mode 100644 test/tkt35xx.test create mode 100644 test/tkt3630.test create mode 100644 test/tkt3718.test create mode 100644 test/tkt3731.test create mode 100644 test/tkt3757.test create mode 100644 test/tkt3761.test create mode 100644 test/tkt3762.test create mode 100644 test/tkt3773.test create mode 100644 test/tkt3791.test create mode 100644 test/tkt3793.test create mode 100644 test/tkt3810.test create mode 100644 test/tkt3824.test create mode 100644 test/tkt3832.test create mode 100644 test/tkt3838.test create mode 100644 test/tkt3841.test create mode 100644 test/tkt3871.test create mode 100644 test/tkt3879.test create mode 100644 test/tkt3911.test create mode 100644 test/tkt3918.test create mode 100644 test/tkt3922.test create mode 100644 test/tkt3929.test create mode 100644 test/tkt3935.test create mode 100644 test/tkt3992.test create mode 100644 test/tkt3997.test create mode 100644 test/tkt4018.test create mode 100644 test/tokenize.test create mode 100644 test/tpch01.test create mode 100644 test/trace.test create mode 100644 test/trace2.test create mode 100644 test/trace3.test create mode 100644 test/trans.test create mode 100644 test/trans2.test create mode 100644 test/trans3.test create mode 100644 test/transitive1.test create mode 100644 test/trigger1.test create mode 100644 test/trigger2.test create mode 100644 test/trigger3.test create mode 100644 test/trigger4.test create mode 100644 test/trigger5.test create mode 100644 test/trigger6.test create mode 100644 test/trigger7.test create mode 100644 test/trigger8.test create mode 100644 test/trigger9.test create mode 100644 test/triggerA.test create mode 100644 test/triggerB.test create mode 100644 test/triggerC.test create mode 100644 test/triggerD.test create mode 100644 test/triggerE.test create mode 100644 test/triggerF.test create mode 100644 test/triggerG.test create mode 100644 test/triggerupfrom.test create mode 100644 test/trustschema1.test create mode 100644 test/tt3_checkpoint.c create mode 100644 test/tt3_index.c create mode 100644 test/tt3_lookaside1.c create mode 100644 test/tt3_shared.c create mode 100644 test/tt3_stress.c create mode 100644 test/tt3_vacuum.c create mode 100644 test/types.test create mode 100644 test/types2.test create mode 100644 test/types3.test create mode 100644 test/unhex.test create mode 100644 test/unionall.test create mode 100644 test/unionall2.test create mode 100644 test/unionallfault.test create mode 100644 test/unionvtab.test create mode 100644 test/unionvtabfault.test create mode 100644 test/unique.test create mode 100644 test/unique2.test create mode 100644 test/unixexcl.test create mode 100644 test/unordered.test create mode 100644 test/update.test create mode 100644 test/update2.test create mode 100644 test/upfrom1.tcl create mode 100644 test/upfrom1.test create mode 100644 test/upfrom2.test create mode 100644 test/upfrom3.test create mode 100644 test/upfrom4.test create mode 100644 test/upfromfault.test create mode 100644 test/upsert1.test create mode 100644 test/upsert2.test create mode 100644 test/upsert3.test create mode 100644 test/upsert4.test create mode 100644 test/upsert5.test create mode 100644 test/upsertfault.test create mode 100644 test/uri.test create mode 100644 test/uri2.test create mode 100644 test/userauth01.test create mode 100644 test/utf16align.test create mode 100644 test/vacuum-into.test create mode 100644 test/vacuum.test create mode 100644 test/vacuum2.test create mode 100644 test/vacuum3.test create mode 100644 test/vacuum4.test create mode 100644 test/vacuum5.test create mode 100644 test/vacuum6.test create mode 100644 test/vacuummem.test create mode 100644 test/varint.test create mode 100644 test/veryquick.test create mode 100644 test/view.test create mode 100644 test/view2.test create mode 100644 test/view3.test create mode 100644 test/vt02.c create mode 100644 test/vtab1.test create mode 100644 test/vtab2.test create mode 100644 test/vtab3.test create mode 100644 test/vtab4.test create mode 100644 test/vtab5.test create mode 100644 test/vtab6.test create mode 100644 test/vtab7.test create mode 100644 test/vtab8.test create mode 100644 test/vtab9.test create mode 100644 test/vtabA.test create mode 100644 test/vtabB.test create mode 100644 test/vtabC.test create mode 100644 test/vtabD.test create mode 100644 test/vtabE.test create mode 100644 test/vtabF.test create mode 100644 test/vtabH.test create mode 100644 test/vtabI.test create mode 100644 test/vtabJ.test create mode 100644 test/vtabK.test create mode 100644 test/vtab_alter.test create mode 100644 test/vtab_err.test create mode 100644 test/vtab_shared.test create mode 100644 test/vtabdistinct.test create mode 100644 test/vtabdrop.test create mode 100644 test/vtabrhs1.test create mode 100644 test/wal.test create mode 100644 test/wal2.test create mode 100644 test/wal3.test create mode 100644 test/wal4.test create mode 100644 test/wal5.test create mode 100644 test/wal6.test create mode 100644 test/wal64k.test create mode 100644 test/wal7.test create mode 100644 test/wal8.test create mode 100644 test/wal9.test create mode 100644 test/wal_common.tcl create mode 100644 test/walbak.test create mode 100644 test/walbig.test create mode 100644 test/walblock.test create mode 100644 test/walcksum.test create mode 100644 test/walcrash.test create mode 100644 test/walcrash2.test create mode 100644 test/walcrash3.test create mode 100644 test/walcrash4.test create mode 100644 test/walfault.test create mode 100644 test/walfault2.test create mode 100644 test/walhook.test create mode 100644 test/walmode.test create mode 100644 test/walnoshm.test create mode 100644 test/waloverwrite.test create mode 100644 test/walpersist.test create mode 100644 test/walprotocol.test create mode 100644 test/walprotocol2.test create mode 100644 test/walro.test create mode 100644 test/walro2.test create mode 100644 test/walrofault.test create mode 100644 test/walseh1.test create mode 100644 test/walsetlk.test create mode 100644 test/walshared.test create mode 100644 test/walslow.test create mode 100644 test/walthread.test create mode 100644 test/walvfs.test create mode 100644 test/where.test create mode 100644 test/where2.test create mode 100644 test/where3.test create mode 100644 test/where4.test create mode 100644 test/where5.test create mode 100644 test/where6.test create mode 100644 test/where7.test create mode 100644 test/where8.test create mode 100644 test/where9.test create mode 100644 test/whereA.test create mode 100644 test/whereB.test create mode 100644 test/whereC.test create mode 100644 test/whereD.test create mode 100644 test/whereE.test create mode 100644 test/whereF.test create mode 100644 test/whereG.test create mode 100644 test/whereH.test create mode 100644 test/whereI.test create mode 100644 test/whereJ.test create mode 100644 test/whereK.test create mode 100644 test/whereL.test create mode 100644 test/whereM.test create mode 100644 test/wherefault.test create mode 100644 test/wherelfault.test create mode 100644 test/wherelimit.test create mode 100644 test/wherelimit2.test create mode 100644 test/widetab1.test create mode 100644 test/win32heap.test create mode 100644 test/win32lock.test create mode 100644 test/win32longpath.test create mode 100644 test/win32nolock.test create mode 100644 test/window1.test create mode 100644 test/window2.tcl create mode 100644 test/window2.test create mode 100644 test/window3.tcl create mode 100644 test/window3.test create mode 100644 test/window4.tcl create mode 100644 test/window4.test create mode 100644 test/window5.test create mode 100644 test/window6.test create mode 100644 test/window7.tcl create mode 100644 test/window7.test create mode 100644 test/window8.tcl create mode 100644 test/window8.test create mode 100644 test/window9.test create mode 100644 test/windowA.test create mode 100644 test/windowB.test create mode 100644 test/windowC.test create mode 100644 test/windowD.test create mode 100644 test/windowE.test create mode 100644 test/windowerr.tcl create mode 100644 test/windowerr.test create mode 100644 test/windowfault.test create mode 100644 test/windowpushd.test create mode 100644 test/with1.test create mode 100644 test/with2.test create mode 100644 test/with3.test create mode 100644 test/with4.test create mode 100644 test/with5.test create mode 100644 test/with6.test create mode 100644 test/withM.test create mode 100644 test/without_rowid1.test create mode 100644 test/without_rowid2.test create mode 100644 test/without_rowid3.test create mode 100644 test/without_rowid4.test create mode 100644 test/without_rowid5.test create mode 100644 test/without_rowid6.test create mode 100644 test/without_rowid7.test create mode 100644 test/wordcount.c create mode 100644 test/writecrash.test create mode 100644 test/zeroblob.test create mode 100644 test/zeroblobfault.test create mode 100644 test/zerodamage.test create mode 100644 test/zipfile.test create mode 100644 test/zipfile2.test create mode 100644 test/zipfilefault.test (limited to 'test') diff --git a/test/8_3_names.test b/test/8_3_names.test new file mode 100644 index 0000000..1d63f5d --- /dev/null +++ b/test/8_3_names.test @@ -0,0 +1,197 @@ +# 2011 May 17 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Test cases for the SQLITE_ENABLE_8_3_NAMES feature that forces all +# filename extensions to be limited to 3 characters. Some embedded +# systems need this to work around microsoft FAT patents, but this +# feature should be disabled on most deployments. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +ifcapable !8_3_names { + finish_test + return +} + +db close +sqlite3_shutdown +sqlite3_config_uri 1 + +do_test 8_3_names-1.0 { + forcedelete test.db test.nal test.db-journal + sqlite3 db test.db + db eval { + PRAGMA cache_size=10; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(randomblob(20000)); + BEGIN; + DELETE FROM t1; + INSERT INTO t1 VALUES(randomblob(15000)); + } + file exists test.db-journal +} 1 +do_test 8_3_names-1.1 { + file exists test.nal +} 0 +do_test 8_3_names-1.2 { + db eval { + ROLLBACK; + SELECT length(x) FROM t1 + } +} 20000 + +db close +do_test 8_3_names-2.0 { + forcedelete test.db test.nal test.db-journal + sqlite3 db file:./test.db?8_3_names=1 + db eval { + PRAGMA cache_size=10; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(randomblob(20000)); + BEGIN; + DELETE FROM t1; + INSERT INTO t1 VALUES(randomblob(15000)); + } + file exists test.db-journal +} 0 +do_test 8_3_names-2.1 { + file exists test.nal +} 1 +forcedelete test2.db test2.nal test2.db-journal +copy_file test.db test2.db +copy_file test.nal test2.nal +do_test 8_3_names-2.2 { + db eval { + COMMIT; + SELECT length(x) FROM t1 + } +} 15000 +do_test 8_3_names-2.3 { + sqlite3 db2 file:./test2.db?8_3_names=1 + db2 eval { + PRAGMA integrity_check; + SELECT length(x) FROM t1; + } +} {ok 20000} + +db close +do_test 8_3_names-3.0 { + forcedelete test.db test.nal test.db-journal + sqlite3 db file:./test.db?8_3_names=0 + db eval { + PRAGMA cache_size=10; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(randomblob(20000)); + BEGIN; + DELETE FROM t1; + INSERT INTO t1 VALUES(randomblob(15000)); + } + file exists test.db-journal +} 1 +do_test 8_3_names-3.1 { + file exists test.nal +} 0 +forcedelete test2.db test2.nal test2.db-journal +copy_file test.db test2.db +copy_file test.db-journal test2.db-journal +do_test 8_3_names-3.2 { + db eval { + COMMIT; + SELECT length(x) FROM t1 + } +} 15000 +do_test 8_3_names-3.3 { + sqlite3 db2 file:./test2.db?8_3_names=0 + db2 eval { + PRAGMA integrity_check; + SELECT length(x) FROM t1; + } +} {ok 20000} + +########################################################################## +# Master journals. +# +db close +forcedelete test.db test2.db +do_test 8_3_names-4.0 { + sqlite3 db file:./test.db?8_3_names=1 + db eval { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(1); + ATTACH 'file:./test2.db?8_3_names=1' AS db2; + CREATE TABLE db2.t2(y); + INSERT INTO t2 VALUES(2); + BEGIN; + INSERT INTO t1 VALUES(3); + INSERT INTO t2 VALUES(4); + COMMIT; + SELECT * FROM t1, t2 ORDER BY x, y + } +} {1 2 1 4 3 2 3 4} + + +########################################################################## +# WAL mode. +# +ifcapable !wal { + finish_test + return +} +db close +forcedelete test.db +do_test 8_3_names-5.0 { + sqlite3 db file:./test.db?8_3_names=1 + load_static_extension db wholenumber + db eval { + PRAGMA journal_mode=WAL; + CREATE TABLE t1(x); + CREATE VIRTUAL TABLE nums USING wholenumber; + INSERT INTO t1 SELECT value FROM nums WHERE value BETWEEN 1 AND 1000; + BEGIN; + UPDATE t1 SET x=x*2; + } + sqlite3 db2 file:./test.db?8_3_names=1 + load_static_extension db2 wholenumber + db2 eval { + BEGIN; + SELECT sum(x) FROM t1; + } +} {500500} + +do_test 8_3_names-5.1 { + file exists test.db-wal +} 0 +do_test 8_3_names-5.2 { + file exists test.wal +} 1 +do_test 8_3_names-5.3 { + file exists test.db-shm +} 0 +do_test 8_3_names-5.4 { + file exists test.shm +} 1 + + +do_test 8_3_names-5.5 { + db eval { + COMMIT; + SELECT sum(x) FROM t1; + } +} {1001000} +do_test 8_3_names-5.6 { + db2 eval { + SELECT sum(x) FROM t1; + } +} {500500} + + +finish_test diff --git a/test/affinity2.test b/test/affinity2.test new file mode 100644 index 0000000..6ad257a --- /dev/null +++ b/test/affinity2.test @@ -0,0 +1,136 @@ +# 2015-06-02 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is type affinity in comparison operations. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix affinity2 + +do_execsql_test affinity2-100 { + CREATE TABLE t1( + xi INTEGER, + xr REAL, + xb BLOB, + xn NUMERIC, + xt TEXT + ); + INSERT INTO t1(rowid,xi,xr,xb,xn,xt) VALUES(1,1,1,1,1,1); + INSERT INTO t1(rowid,xi,xr,xb,xn,xt) VALUES(2,'2','2','2','2','2'); + INSERT INTO t1(rowid,xi,xr,xb,xn,xt) VALUES(3,'03','03','03','03','03'); + +} {} +do_execsql_test affinity2-110 { + SELECT xi, typeof(xi) FROM t1 ORDER BY rowid; +} {1 integer 2 integer 3 integer} +do_execsql_test affinity2-120 { + SELECT xr, typeof(xr) FROM t1 ORDER BY rowid; +} {1.0 real 2.0 real 3.0 real} +do_execsql_test affinity2-130 { + SELECT xb, typeof(xb) FROM t1 ORDER BY rowid; +} {1 integer 2 text 03 text} +do_execsql_test affinity2-140 { + SELECT xn, typeof(xn) FROM t1 ORDER BY rowid; +} {1 integer 2 integer 3 integer} +do_execsql_test affinity2-150 { + SELECT xt, typeof(xt) FROM t1 ORDER BY rowid; +} {1 text 2 text 03 text} + +do_execsql_test affinity2-200 { + SELECT rowid, xi==xt, xi==xb, xi==+xt FROM t1 ORDER BY rowid; +} {1 1 1 1 2 1 1 1 3 1 1 1} +do_execsql_test affinity2-210 { + SELECT rowid, xr==xt, xr==xb, xr==+xt FROM t1 ORDER BY rowid; +} {1 1 1 1 2 1 1 1 3 1 1 1} +do_execsql_test affinity2-220 { + SELECT rowid, xn==xt, xn==xb, xn==+xt FROM t1 ORDER BY rowid; +} {1 1 1 1 2 1 1 1 3 1 1 1} + +do_execsql_test affinity2-300 { + SELECT rowid, xt==+xi, xt==xi, xt==xb FROM t1 ORDER BY rowid; +} {1 1 1 0 2 1 1 1 3 0 1 1} + +#------------------------------------------------------------------------- +do_execsql_test 400 { + CREATE TABLE ttt(c0, c1); + CREATE INDEX ii ON ttt(CAST(c0 AS NUMERIC)); + INSERT INTO ttt VALUES('abc', '-1'); +} +do_execsql_test 410 { + SELECT * FROM ttt WHERE CAST(c0 AS NUMERIC) > c1 GROUP BY rowid; +} {abc -1} +do_execsql_test 420 { + SELECT * FROM ttt INDEXED BY ii WHERE CAST(c0 AS NUMERIC) > c1 GROUP BY rowid; +} {abc -1} + +do_execsql_test 430 { + CREATE TABLE t3(a, b, c INTEGER); + CREATE INDEX t3ac ON t3(a, c-1); + INSERT INTO t3 VALUES(1, 1, 1); + INSERT INTO t3 VALUES(2, 1, 0); + INSERT INTO t3 VALUES(3, 1, 1); + INSERT INTO t3 VALUES(4, 1, 0); + INSERT INTO t3 VALUES(5, 1, 1); +} +do_execsql_test 440 { + SELECT * FROM t3 WHERE c='0' ORDER BY a; +} {2 1 0 4 1 0} + +# 2019-08-22 ticket https://sqlite.org/src/info/d99f1ffe836c591ac57f +# False positive in sqlite3ExprNeedsNoAffinityChange() +# +do_execsql_test 500 { + DROP TABLE IF EXISTS t0; + CREATE TABLE t0(c0 TEXT UNIQUE, c1); + INSERT INTO t0(c0) VALUES (-1); + SELECT quote(- x'ce'), quote(t0.c0), quote(- x'ce' >= t0.c0) FROM t0; +} {0 '-1' 1} +do_execsql_test 501 { + SELECT * FROM t0 WHERE - x'ce' >= t0.c0; +} {-1 {}} +do_execsql_test 502 { + SELECT quote(+-+x'ce'), quote(t0.c0), quote(+-+x'ce' >= t0.c0) FROM t0; +} {0 '-1' 1} +do_execsql_test 503 { + SELECT * FROM t0 WHERE +-+x'ce' >= t0.c0; +} {-1 {}} +do_execsql_test 504 { + SELECT quote(- 'ce'), quote(t0.c0), quote(- 'ce' >= t0.c0) FROM t0; +} {0 '-1' 1} +do_execsql_test 505 { + SELECT * FROM t0 WHERE - 'ce' >= t0.c0; +} {-1 {}} +do_execsql_test 506 { + SELECT quote(+-+'ce'), quote(t0.c0), quote(+-+'ce' >= t0.c0) FROM t0; +} {0 '-1' 1} +do_execsql_test 507 { + SELECT * FROM t0 WHERE +-+'ce' >= t0.c0; +} {-1 {}} + +# 2019-08-30 ticket https://www.sqlite.org/src/info/40812aea1fde9594 +# +# Due to some differences in floating point computations, these tests do not +# work under valgrind. +# +if {![info exists ::G(valgrind)]} { + do_execsql_test 600 { + DROP TABLE IF EXISTS t0; + CREATE TABLE t0(c0 REAL UNIQUE); + INSERT INTO t0(c0) VALUES (3175546974276630385); + SELECT 3175546974276630385 < c0 FROM t0; + } {1} + do_execsql_test 601 { + SELECT 1 FROM t0 WHERE 3175546974276630385 < c0; + } {1} +} + +finish_test diff --git a/test/affinity3.test b/test/affinity3.test new file mode 100644 index 0000000..3695ea8 --- /dev/null +++ b/test/affinity3.test @@ -0,0 +1,123 @@ +# 2017-01-16 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Test cases for bugs: +# +# https://www.sqlite.org/src/info/91e2e8ba6ff2e2 +# https://www.sqlite.org/src/info/7ffd1ca1d2ad4ecf +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Ticket https://www.sqlite.org/src/info/91e2e8ba6ff2e2 (2011-09-19) +# Automatic index causes undesired type conversions +# +do_execsql_test affinity3-100 { + CREATE TABLE customer (id INT PRIMARY KEY); + CREATE TABLE apr (id INT PRIMARY KEY, apr REAL); + + CREATE VIEW v1 AS + SELECT c.id, i.apr + FROM customer c + LEFT JOIN apr i ON i.id=c.id; + + CREATE VIEW v1rj AS + SELECT c.id, i.apr + FROM apr i + RIGHT JOIN customer c ON i.id=c.id; + + CREATE VIEW v2 AS + SELECT c.id, v1.apr + FROM customer c + LEFT JOIN v1 ON v1.id=c.id; + + CREATE VIEW v2rj AS + SELECT c.id, v1.apr + FROM v1 RIGHT JOIN customer c ON v1.id=c.id; + + CREATE VIEW v2rjrj AS + SELECT c.id, v1rj.apr + FROM v1rj RIGHT JOIN customer c ON v1rj.id=c.id; + + INSERT INTO customer (id) VALUES (1); + INSERT INTO apr (id, apr) VALUES (1, 12); + INSERT INTO customer (id) VALUES (2); + INSERT INTO apr (id, apr) VALUES (2, 12.01); +} +do_execsql_test affinity3-110 { + PRAGMA automatic_index=ON; + SELECT id, (apr / 100), typeof(apr) apr_type FROM v1; +} {1 0.12 real 2 0.1201 real} +do_execsql_test affinity3-111 { + PRAGMA automatic_index=ON; + SELECT id, (apr / 100), typeof(apr) apr_type FROM v1rj; +} {1 0.12 real 2 0.1201 real} +do_execsql_test affinity3-120 { + SELECT id, (apr / 100), typeof(apr) apr_type FROM v2; +} {1 0.12 real 2 0.1201 real} +do_execsql_test affinity3-121 { + SELECT id, (apr / 100), typeof(apr) apr_type FROM v2rj; +} {1 0.12 real 2 0.1201 real} +do_execsql_test affinity3-122 { + SELECT id, (apr / 100), typeof(apr) apr_type FROM v2rjrj; +} {1 0.12 real 2 0.1201 real} +do_execsql_test affinity3-130 { + PRAGMA automatic_index=OFF; + SELECT id, (apr / 100), typeof(apr) apr_type FROM v1; +} {1 0.12 real 2 0.1201 real} +do_execsql_test affinity3-131 { + SELECT id, (apr / 100), typeof(apr) apr_type FROM v1rj; +} {1 0.12 real 2 0.1201 real} +do_execsql_test affinity3-140 { + SELECT id, (apr / 100), typeof(apr) apr_type FROM v2; +} {1 0.12 real 2 0.1201 real} +do_execsql_test affinity3-141 { + SELECT id, (apr / 100), typeof(apr) apr_type FROM v2rj; +} {1 0.12 real 2 0.1201 real} +do_execsql_test affinity3-142 { + SELECT id, (apr / 100), typeof(apr) apr_type FROM v2rjrj; +} {1 0.12 real 2 0.1201 real} + +# Ticket https://www.sqlite.org/src/info/7ffd1ca1d2ad4ecf (2017-01-16) +# Incorrect affinity when using automatic indexes +# +do_execsql_test affinity3-200 { + CREATE TABLE map_integer (id INT, name); + INSERT INTO map_integer VALUES(1,'a'); + CREATE TABLE map_text (id TEXT, name); + INSERT INTO map_text VALUES('4','e'); + CREATE TABLE data (id TEXT, name); + INSERT INTO data VALUES(1,'abc'); + INSERT INTO data VALUES('4','xyz'); + CREATE VIEW idmap as + SELECT * FROM map_integer + UNION SELECT * FROM map_text; + CREATE TABLE mzed AS SELECT * FROM idmap; +} + +do_execsql_test affinity3-210 { + PRAGMA automatic_index=ON; + SELECT * FROM data JOIN idmap USING(id); +} {4 xyz e} +do_execsql_test affinity3-220 { + SELECT * FROM data JOIN mzed USING(id); +} {4 xyz e} + +do_execsql_test affinity3-250 { + PRAGMA automatic_index=OFF; + SELECT * FROM data JOIN idmap USING(id); +} {4 xyz e} +do_execsql_test affinity3-260 { + SELECT * FROM data JOIN mzed USING(id); +} {4 xyz e} + +finish_test diff --git a/test/aggerror.test b/test/aggerror.test new file mode 100644 index 0000000..f95d8b2 --- /dev/null +++ b/test/aggerror.test @@ -0,0 +1,78 @@ +# 2006 January 20 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests for calling sqlite3_result_error() +# from within an aggregate function implementation. +# +# $Id: aggerror.test,v 1.3 2006/05/03 23:34:06 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + + +# Add the x_count aggregate function to the database handle. +# x_count will error out if its input is 40 or 41 or if its +# final results is 42. Make sure that such errors are handled +# appropriately. +# +do_test aggerror-1.1 { + set DB [sqlite3_connection_pointer db] + sqlite3_create_aggregate $DB + execsql { + CREATE TABLE t1(a); + INSERT INTO t1 VALUES(1); + INSERT INTO t1 VALUES(2); + INSERT INTO t1 SELECT a+2 FROM t1; + INSERT INTO t1 SELECT a+4 FROM t1; + INSERT INTO t1 SELECT a+8 FROM t1; + INSERT INTO t1 SELECT a+16 FROM t1; + INSERT INTO t1 SELECT a+32 FROM t1 ORDER BY a LIMIT 7; + SELECT x_count(*) FROM t1; + } +} {39} +do_test aggerror-1.2 { + execsql { + INSERT INTO t1 VALUES(40); + SELECT x_count(*) FROM t1; + } +} {40} +do_test aggerror-1.3 { + catchsql { + SELECT x_count(a) FROM t1; + } +} {1 {value of 40 handed to x_count}} +ifcapable utf16 { + do_test aggerror-1.4 { + execsql { + UPDATE t1 SET a=41 WHERE a=40 + } + catchsql { + SELECT x_count(a) FROM t1; + } + } {1 abc} +} +do_test aggerror-1.5 { + execsql { + SELECT x_count(*) FROM t1 + } +} 40 +do_test aggerror-1.6 { + execsql { + INSERT INTO t1 VALUES(40); + INSERT INTO t1 VALUES(42); + } + catchsql { + SELECT x_count(*) FROM t1; + } +} {1 {x_count totals to 42}} + +finish_test diff --git a/test/aggfault.test b/test/aggfault.test new file mode 100644 index 0000000..7c16b03 --- /dev/null +++ b/test/aggfault.test @@ -0,0 +1,43 @@ +# 2023 March 30 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix aggfault + + +do_execsql_test 1 { + CREATE TABLE t1(x); + CREATE INDEX t1x ON t1(x, x=0); +} +faultsim_save_and_close + +do_faultsim_test 2 -faults oom* -prep { + faultsim_restore_and_reopen + execsql { SELECT * FROM sqlite_schema } +} -body { + execsql { + SELECT * FROM t1 AS a1 WHERE ( + SELECT count(x AND 0=a1.x) FROM t1 GROUP BY abs(1) + ) AND x=( + SELECT * FROM t1 AS a1 + WHERE (SELECT count(x IS 1 AND a1.x=0) + FROM t1 + GROUP BY abs(1)) AND x=0 + ); + } +} -test { + faultsim_test_result {0 {}} +} + + +finish_test diff --git a/test/aggnested.test b/test/aggnested.test new file mode 100644 index 0000000..f353907 --- /dev/null +++ b/test/aggnested.test @@ -0,0 +1,487 @@ +# 2012-08-23 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests for processing aggregate queries with +# subqueries in which the subqueries hold the aggregate functions +# or in which the subqueries are themselves aggregate queries +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix aggnested + +do_test aggnested-1.1 { + db eval { + CREATE TABLE t1(a1 INTEGER); + INSERT INTO t1 VALUES(1), (2), (3); + CREATE TABLE t2(b1 INTEGER); + INSERT INTO t2 VALUES(4), (5); + SELECT (SELECT string_agg(a1,'x') FROM t2) FROM t1; + } +} {1x2x3} +do_test aggnested-1.2 { + db eval { + SELECT + (SELECT string_agg(a1,'x') || '-' || string_agg(b1,'y') FROM t2) + FROM t1; + } +} {1x2x3-4y5} +do_test aggnested-1.3 { + db eval { + SELECT (SELECT string_agg(b1,a1) FROM t2) FROM t1; + } +} {415 425 435} +do_test aggnested-1.4 { + db eval { + SELECT (SELECT group_concat(a1,b1) FROM t2) FROM t1; + } +} {151 252 353} + + +# This test case is a copy of the one in +# http://www.mail-archive.com/sqlite-users@sqlite.org/msg70787.html +# +do_test aggnested-2.0 { + sqlite3 db2 :memory: + db2 eval { + CREATE TABLE t1 (A1 INTEGER NOT NULL,A2 INTEGER NOT NULL,A3 INTEGER NOT + NULL,A4 INTEGER NOT NULL,PRIMARY KEY(A1)); + REPLACE INTO t1 VALUES(1,11,111,1111); + REPLACE INTO t1 VALUES(2,22,222,2222); + REPLACE INTO t1 VALUES(3,33,333,3333); + CREATE TABLE t2 (B1 INTEGER NOT NULL,B2 INTEGER NOT NULL,B3 INTEGER NOT + NULL,B4 INTEGER NOT NULL,PRIMARY KEY(B1)); + REPLACE INTO t2 VALUES(1,88,888,8888); + REPLACE INTO t2 VALUES(2,99,999,9999); + SELECT (SELECT GROUP_CONCAT(CASE WHEN a1=1 THEN'A' ELSE 'B' END) FROM t2), + t1.* + FROM t1; + } +} {A,B,B 1 11 111 1111} +db2 close + +##################### Test cases for ticket [bfbf38e5e9956ac69f] ############ +# +# This first test case is the original problem report: +do_test aggnested-3.0 { + db eval { + CREATE TABLE AAA ( + aaa_id INTEGER PRIMARY KEY AUTOINCREMENT + ); + CREATE TABLE RRR ( + rrr_id INTEGER PRIMARY KEY AUTOINCREMENT, + rrr_date INTEGER NOT NULL, + rrr_aaa INTEGER + ); + CREATE TABLE TTT ( + ttt_id INTEGER PRIMARY KEY AUTOINCREMENT, + target_aaa INTEGER NOT NULL, + source_aaa INTEGER NOT NULL + ); + insert into AAA (aaa_id) values (2); + insert into TTT (ttt_id, target_aaa, source_aaa) + values (4469, 2, 2); + insert into TTT (ttt_id, target_aaa, source_aaa) + values (4476, 2, 1); + insert into RRR (rrr_id, rrr_date, rrr_aaa) + values (0, 0, NULL); + insert into RRR (rrr_id, rrr_date, rrr_aaa) + values (2, 4312, 2); + SELECT i.aaa_id, + (SELECT sum(CASE WHEN (t.source_aaa == i.aaa_id) THEN 1 ELSE 0 END) + FROM TTT t + ) AS segfault + FROM + (SELECT curr.rrr_aaa as aaa_id + FROM RRR curr + -- you also can comment out the next line + -- it causes segfault to happen after one row is outputted + INNER JOIN AAA a ON (curr.rrr_aaa = aaa_id) + LEFT JOIN RRR r ON (r.rrr_id <> 0 AND r.rrr_date < curr.rrr_date) + GROUP BY curr.rrr_id + HAVING r.rrr_date IS NULL + ) i; + } +} {2 1} + +# Further variants of the test case, as found in the ticket +# +do_test aggnested-3.1 { + db eval { + DROP TABLE IF EXISTS t1; + DROP TABLE IF EXISTS t2; + CREATE TABLE t1 ( + id1 INTEGER PRIMARY KEY AUTOINCREMENT, + value1 INTEGER + ); + INSERT INTO t1 VALUES(4469,2),(4476,1); + CREATE TABLE t2 ( + id2 INTEGER PRIMARY KEY AUTOINCREMENT, + value2 INTEGER + ); + INSERT INTO t2 VALUES(0,1),(2,2); + SELECT + (SELECT sum(value2==xyz) FROM t2) + FROM + (SELECT curr.value1 as xyz + FROM t1 AS curr LEFT JOIN t1 AS other + GROUP BY curr.id1); + } +} {1 1} +do_test aggnested-3.1-rj { + db eval { + SELECT + (SELECT sum(value2==xyz) FROM t2) + FROM + (SELECT curr.value1 as xyz + FROM t1 AS other RIGHT JOIN t1 AS curr + GROUP BY curr.id1); + } +} {1 1} + +do_test aggnested-3.2 { + db eval { + DROP TABLE IF EXISTS t1; + DROP TABLE IF EXISTS t2; + CREATE TABLE t1 ( + id1 INTEGER, + value1 INTEGER, + x1 INTEGER + ); + INSERT INTO t1 VALUES(4469,2,98),(4469,1,99),(4469,3,97); + CREATE TABLE t2 ( + value2 INTEGER + ); + INSERT INTO t2 VALUES(1); + SELECT + (SELECT sum(value2==xyz) FROM t2) + FROM + (SELECT value1 as xyz, max(x1) AS pqr + FROM t1 + GROUP BY id1); + SELECT + (SELECT sum(value2<>xyz) FROM t2) + FROM + (SELECT value1 as xyz, max(x1) AS pqr + FROM t1 + GROUP BY id1); + } +} {1 0} +do_test aggnested-3.3 { + db eval { + DROP TABLE IF EXISTS t1; + DROP TABLE IF EXISTS t2; + CREATE TABLE t1(id1, value1); + INSERT INTO t1 VALUES(4469,2),(4469,1); + CREATE TABLE t2 (value2); + INSERT INTO t2 VALUES(1); + SELECT (SELECT sum(value2=value1) FROM t2), max(value1) + FROM t1 + GROUP BY id1; + } +} {0 2} + +# A batch of queries all doing approximately the same operation involving +# two nested aggregate queries. +# +do_test aggnested-3.11 { + db eval { + DROP TABLE IF EXISTS t1; + DROP TABLE IF EXISTS t2; + CREATE TABLE t1(id1, value1); + INSERT INTO t1 VALUES(4469,12),(4469,11),(4470,34); + CREATE INDEX t1id1 ON t1(id1); + CREATE TABLE t2 (value2); + INSERT INTO t2 VALUES(12),(34),(34); + INSERT INTO t2 SELECT value2 FROM t2; + + SELECT max(value1), (SELECT count(*) FROM t2 WHERE value2=max(value1)) + FROM t1 + GROUP BY id1; + } +} {12 2 34 4} +do_test aggnested-3.12 { + db eval { + SELECT max(value1), (SELECT count(*) FROM t2 WHERE value2=value1) + FROM t1 + GROUP BY id1; + } +} {12 2 34 4} +do_test aggnested-3.13 { + db eval { + SELECT value1, (SELECT sum(value2=value1) FROM t2) + FROM t1; + } +} {12 2 11 0 34 4} +do_test aggnested-3.14 { + db eval { + SELECT value1, (SELECT sum(value2=value1) FROM t2) + FROM t1 + WHERE value1 IN (SELECT max(value1) FROM t1 GROUP BY id1); + } +} {12 2 34 4} +do_test aggnested-3.15 { + # FIXME: If case 3.16 works, then this case really ought to work too... + catchsql { + SELECT max(value1), (SELECT sum(value2=max(value1)) FROM t2) + FROM t1 + GROUP BY id1; + } +} {1 {misuse of aggregate function max()}} +do_test aggnested-3.16 { + db eval { + SELECT max(value1), (SELECT sum(value2=value1) FROM t2) + FROM t1 + GROUP BY id1; + } +} {12 2 34 4} + +# 2019-08-31 +# Problem found by dbsqlfuzz +# +do_execsql_test aggnested-4.1 { + DROP TABLE IF EXISTS aa; + DROP TABLE IF EXISTS bb; + CREATE TABLE aa(x INT); INSERT INTO aa(x) VALUES(123); + CREATE TABLE bb(y INT); INSERT INTO bb(y) VALUES(456); + SELECT (SELECT sum(x+(SELECT y)) FROM bb) FROM aa; +} {579} +do_execsql_test aggnested-4.2 { + SELECT (SELECT sum(x+y) FROM bb) FROM aa; +} {579} +do_execsql_test aggnested-4.3 { + DROP TABLE IF EXISTS tx; + DROP TABLE IF EXISTS ty; + CREATE TABLE tx(x INT); + INSERT INTO tx VALUES(1),(2),(3),(4),(5); + CREATE TABLE ty(y INT); + INSERT INTO ty VALUES(91),(92),(93); + SELECT min((SELECT count(y) FROM ty)) FROM tx; +} {3} +do_execsql_test aggnested-4.4 { + SELECT max((SELECT a FROM (SELECT count(*) AS a FROM ty) AS s)) FROM tx; +} {3} + +#-------------------------------------------------------------------------- +# +reset_db +do_execsql_test 5.0 { + CREATE TABLE x1(a, b); + INSERT INTO x1 VALUES(1, 2); + CREATE TABLE x2(x); + INSERT INTO x2 VALUES(NULL), (NULL), (NULL); +} + +# At one point, aggregate "total()" in the query below was being processed +# as part of the outer SELECT, not as part of the sub-select with no FROM +# clause. +do_execsql_test 5.1 { + SELECT ( SELECT total( (SELECT b FROM x1) ) ) FROM x2; +} {2.0 2.0 2.0} + +do_execsql_test 5.2 { + SELECT ( SELECT total( (SELECT 2 FROM x1) ) ) FROM x2; +} {2.0 2.0 2.0} + +do_execsql_test 5.3 { + CREATE TABLE t1(a); + CREATE TABLE t2(b); +} + +do_execsql_test 5.4 { + SELECT( + SELECT max(b) LIMIT ( + SELECT total( (SELECT a FROM t1) ) + ) + ) + FROM t2; +} {{}} + +do_execsql_test 5.5 { + CREATE TABLE a(b); + WITH c AS(SELECT a) + SELECT(SELECT(SELECT string_agg(b, b) + LIMIT(SELECT 0.100000 * + AVG(DISTINCT(SELECT 0 FROM a ORDER BY b, b, b)))) + FROM a GROUP BY b, + b, b) FROM a EXCEPT SELECT b FROM a ORDER BY b, + b, b; +} + +#------------------------------------------------------------------------- +# dbsqlfuzz a779227f721a834df95f4f42d0c31550a1f8b8a2 +# +reset_db +do_execsql_test 6.0 { + CREATE TABLE t1(a); + CREATE TABLE t2(b); + + INSERT INTO t1 VALUES('x'); + INSERT INTO t2 VALUES(1); +} + +do_execsql_test 6.1.1 { + SELECT ( + SELECT t2.b FROM (SELECT t2.b AS c FROM t1) GROUP BY 1 HAVING t2.b + ) + FROM t2 GROUP BY 'constant_string'; +} {1} +do_execsql_test 6.1.2 { + SELECT ( + SELECT c FROM (SELECT t2.b AS c FROM t1) GROUP BY c HAVING t2.b + ) + FROM t2 GROUP BY 'constant_string'; +} {1} + +do_execsql_test 6.2.0 { + UPDATE t2 SET b=0 +} +do_execsql_test 6.2.1 { + SELECT ( + SELECT t2.b FROM (SELECT t2.b AS c FROM t1) GROUP BY 1 HAVING t2.b + ) + FROM t2 GROUP BY 'constant_string'; +} {{}} +do_execsql_test 6.2.2 { + SELECT ( + SELECT c FROM (SELECT t2.b AS c FROM t1) GROUP BY c HAVING t2.b + ) + FROM t2 GROUP BY 'constant_string'; +} {{}} + +#------------------------------------------------------------------------- +reset_db + +do_execsql_test 7.0 { + CREATE TABLE invoice ( + id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + amount DOUBLE PRECISION DEFAULT NULL, + name VARCHAR(100) DEFAULT NULL + ); + + INSERT INTO invoice (amount, name) VALUES + (4.0, 'Michael'), (15.0, 'Bara'), (4.0, 'Michael'), (6.0, 'John'); +} + +do_execsql_test 7.1 { + SELECT sum(amount), name + from invoice + group by name + having (select v > 6 from (select sum(amount) v) t) +} { + 15.0 Bara + 8.0 Michael +} + +do_execsql_test 7.2 { + SELECT (select 1 from (select sum(amount))) FROM invoice +} {1} + +do_execsql_test 8.0 { + CREATE TABLE t1(x INT); + INSERT INTO t1 VALUES(100); + INSERT INTO t1 VALUES(20); + INSERT INTO t1 VALUES(3); + SELECT (SELECT y FROM (SELECT sum(x) AS y) AS t2 ) FROM t1; +} {123} + +do_execsql_test 8.1 { + SELECT ( + SELECT y FROM ( + SELECT z AS y FROM (SELECT sum(x) AS z) AS t2 + ) + ) FROM t1; +} {123} + +do_execsql_test 8.2 { + SELECT ( + SELECT a FROM ( + SELECT y AS a FROM ( + SELECT z AS y FROM (SELECT sum(x) AS z) AS t2 + ) + ) + ) FROM t1; +} {123} + +#------------------------------------------------------------------------- +# dbsqlfuzz 04408efc51ae46897c4c122b407412045ed221b4 +# +reset_db + +do_execsql_test 9.1 { + WITH out(i, j, k) AS ( + VALUES(1234, 5678, 9012) + ) + SELECT ( + SELECT ( + SELECT min(abc) = ( SELECT ( SELECT 1234 fROM (SELECT abc) ) ) + FROM ( + SELECT sum( out.i ) + ( SELECT sum( out.i ) ) AS abc FROM (SELECT out.j) + ) + ) + ) FROM out; +} {0} + +do_execsql_test 9.2 { + CREATE TABLE t1(a); + CREATE TABLE t2(b); + INSERT INTO t1 VALUES(1), (2), (3); + INSERT INTO t2 VALUES(4), (5), (6); + + SELECT ( + SELECT min(y) + (SELECT x) FROM ( + SELECT sum(a) AS x, b AS y FROM t2 + ) + ) + FROM t1; +} {10} + +do_execsql_test 9.3 { + SELECT ( + SELECT min(y) + (SELECT (SELECT x)) FROM ( + SELECT sum(a) AS x, b AS y FROM t2 + ) + ) + FROM t1; +} {10} + +do_execsql_test 9.4 { + SELECT ( + SELECT (SELECT x) FROM ( + SELECT sum(a) AS x, b AS y FROM t2 + ) GROUP BY y + ) + FROM t1; +} {6} + +do_execsql_test 9.5 { + SELECT ( + SELECT (SELECT (SELECT x)) FROM ( + SELECT sum(a) AS x, b AS y FROM t2 + ) GROUP BY y + ) + FROM t1; +} {6} + +# 2023-12-16 +# New test case for check-in [4470f657d2069972] from 2023-11-02 +# https://bugs.chromium.org/p/chromium/issues/detail?id=1511689 +# +do_execsql_test 10.1 { + DROP TABLE IF EXISTS t0; + DROP TABLE IF EXISTS t1; + CREATE TABLE t0(c1, c2); INSERT INTO t0 VALUES(1,2); + CREATE TABLE t1(c3, c4); INSERT INTO t1 VALUES(3,4); + SELECT * FROM t0 WHERE EXISTS (SELECT 1 FROM t1 GROUP BY c3 HAVING ( SELECT count(*) FROM (SELECT 1 UNION ALL SELECT sum(DISTINCT c1) ) ) ) BETWEEN 1 AND 1; +} {1 2} + +finish_test diff --git a/test/aggorderby.test b/test/aggorderby.test new file mode 100644 index 0000000..eed1f83 --- /dev/null +++ b/test/aggorderby.test @@ -0,0 +1,162 @@ +# 2023-10-18 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements tests for ORDER BY on aggregate functions. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +do_execsql_test aggorderby-1.1 { + CREATE TABLE t1(a TEXT,b INT,c INT,d INT); + WITH RECURSIVE c(x) AS (VALUES(0) UNION ALL SELECT x+1 FROM c WHERE x<9) + INSERT INTO t1(a,b,c,d) SELECT printf('%d',(x*7)%10),1,x,10-x FROM c; + INSERT INTO t1(a,b,c,d) SELECT a, 2, c, 10-d FROM t1; + CREATE INDEX t1b ON t1(b); +} +do_catchsql_test aggorderby-1.2 { + SELECT b, group_concat(a ORDER BY max(d)) FROM t1 GROUP BY b; +} {1 {misuse of aggregate function max()}} +do_catchsql_test aggorderby-1.3 { + SELECT abs(a ORDER BY max(d)) FROM t1; +} {1 {ORDER BY may not be used with non-aggregate abs()}} + +do_execsql_test aggorderby-2.0 { + SELECT group_concat(a ORDER BY a) FROM t1 WHERE b=1; +} {0,1,2,3,4,5,6,7,8,9} +do_execsql_test aggorderby-2.1 { + SELECT group_concat(a ORDER BY c) FROM t1 WHERE b=1; +} {0,7,4,1,8,5,2,9,6,3} +do_execsql_test aggorderby-2.2 { + SELECT group_concat(a ORDER BY b, d) FROM t1; +} {3,6,9,2,5,8,1,4,7,0,0,7,4,1,8,5,2,9,6,3} +do_execsql_test aggorderby-2.3 { + SELECT string_agg(a, ',' ORDER BY b DESC, d) FROM t1; +} {0,7,4,1,8,5,2,9,6,3,3,6,9,2,5,8,1,4,7,0} +do_execsql_test aggorderby-2.4 { + SELECT b, group_concat(a ORDER BY d) FROM t1 GROUP BY b ORDER BY b; +} {1 3,6,9,2,5,8,1,4,7,0 2 0,7,4,1,8,5,2,9,6,3} + +do_execsql_test aggorderby-3.0 { + SELECT group_concat(DISTINCT a ORDER BY a) FROM t1; +} {0,1,2,3,4,5,6,7,8,9} +do_execsql_test aggorderby-3.1 { + SELECT group_concat(DISTINCT a ORDER BY c) FROM t1; +} {0,7,4,1,8,5,2,9,6,3} + +do_execsql_test aggorderby-4.0 { + SELECT count(ORDER BY a) FROM t1; +} 20 +do_execsql_test aggorderby-4.1 { + SELECT c, max(a ORDER BY a) FROM t1; +} {7 9} + + +do_execsql_test aggorderby-5.0 { + DROP TABLE IF EXISTS t1; + DROP TABLE IF EXISTS t3; + CREATE TABLE t1(a TEXT); INSERT INTO t1 VALUES('aaa'),('bbb'); + CREATE TABLE t3(d TEXT); INSERT INTO t3 VALUES('/'),('-'); + SELECT (SELECT string_agg(a,d) FROM t3) FROM t1; +} {aaa-aaa bbb-bbb} +do_execsql_test aggorderby-5.1 { + SELECT (SELECT group_concat(a,d ORDER BY d) FROM t3) FROM t1; +} {aaa/aaa bbb/bbb} +do_execsql_test aggorderby-5.2 { + SELECT (SELECT string_agg(a,d ORDER BY d DESC) FROM t3) FROM t1; +} {aaa-aaa bbb-bbb} +do_execsql_test aggorderby-5.3 { + SELECT (SELECT string_agg(a,'#' ORDER BY d) FROM t3) FROM t1; +} {aaa#aaa bbb#bbb} + +# COLLATE works on the ORDER BY. +# +do_execsql_test aggorderby-6.0 { + WITH c(x) AS (VALUES('abc'),('DEF'),('xyz'),('ABC'),('XYZ')) + SELECT string_agg(x,',' ORDER BY x COLLATE nocase), + string_agg(x,',' ORDER BY x) FROM c; +} {abc,ABC,DEF,xyz,XYZ ABC,DEF,XYZ,abc,xyz} +do_execsql_test aggorderby-6.1 { + WITH c(x,y) AS (VALUES(1,'a'),(2,'B'),(3,'c'),(4,'D')) + SELECT group_concat(x ORDER BY y COLLATE nocase), + group_concat(x ORDER BY y COLLATE binary) FROM c; +} {1,2,3,4 2,4,1,3} + +# NULLS FIRST and NULLS LAST work on the ORDER BY +# +do_execsql_test aggorderby-7.0 { + WITH c(x) AS (VALUES(1),(NULL),(2.5),(NULL),('three')) + SELECT json_group_array(x ORDER BY x NULLS FIRST), + json_group_array(x ORDER BY x NULLS LAST) FROM c; +} {[null,null,1,2.5,"three"] [1,2.5,"three",null,null]} +do_execsql_test aggorderby-7.1 { + WITH c(x,y) AS (VALUES(1,9),(2,null),(3,5),(4,null),(5,1)) + SELECT json_group_array(x ORDER BY y NULLS FIRST, x), + json_group_array(x ORDER BY y NULLS LAST, x) FROM c; +} {[2,4,5,3,1] [5,3,1,2,4]} + +# The DISTINCT only applies to the function arguments, not to the +# ORDER BY arguments. +# +do_execsql_test aggorderby-8.0 { + WITH c(x,y,z) AS (VALUES('a',4,5),('b',3,6),('c',2,7),('c',1,8)) + SELECT group_concat(DISTINCT x ORDER BY y, z) FROM c; +} {c,b,a} +do_execsql_test aggorderby-8.1 { + WITH c(x,y,z) AS (VALUES('a',4,5),('b',3,6),('b',2,7),('c',1,8)) + SELECT group_concat(DISTINCT x ORDER BY y, z) FROM c; +} {c,b,a} +do_execsql_test aggorderby-8.2 { + WITH c(x,y) AS (VALUES(1,1),(2,2),(3,3),(3,4),(3,5),(3,6)) + SELECT sum(DISTINCT x ORDER BY y) FROM c; +} 6 + +# Subtype information is transfered through the sorter for aggregates +# that make use of subtype info. +# +do_execsql_test aggorderby-9.0 { + WITH c(x,y) AS (VALUES + ('{a:3}', 3), + ('[1,1]', 1), + ('[4,4]', 4), + ('{x:2}', 2)) + SELECT json_group_array(json(x) ORDER BY y) FROM c; +} {{[[1,1],{"x":2},{"a":3},[4,4]]}} +do_execsql_test aggorderby-9.1 { + WITH c(x,y) AS (VALUES + ('[4,4]', 4), + ('{a:3}', 3), + ('[4,4]', 4), + ('[1,1]', 1), + ('[4,4]', 4), + ('{x:2}', 2)) + SELECT json_group_array(DISTINCT json(x) ORDER BY y) FROM c; +} {{[[1,1],{"x":2},{"a":3},[4,4]]}} +do_execsql_test aggorderby-9.2 { + WITH c(x,y) AS (VALUES + ('{a:3}', 3), + ('[1,1]', 1), + ('[4,4]', 4), + ('{x:2}', 2)) + SELECT json_group_array(json(x) ORDER BY json(x)) FROM c; +} {{[[1,1],[4,4],{"a":3},{"x":2}]}} +do_execsql_test aggorderby-9.3 { + WITH c(x,y) AS (VALUES + ('[4,4]', 4), + ('{a:3}', 3), + ('[4,4]', 4), + ('[1,1]', 1), + ('[4,4]', 4), + ('{x:2}', 2)) + SELECT json_group_array(DISTINCT json(x) ORDER BY json(x)) FROM c; +} {{[[1,1],[4,4],{"a":3},{"x":2}]}} + + +finish_test diff --git a/test/alias.test b/test/alias.test new file mode 100644 index 0000000..2907989 --- /dev/null +++ b/test/alias.test @@ -0,0 +1,140 @@ +# 2008 August 28 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file implements regression tests for SQLite library. The +# focus of this script is correct code generation of aliased result-set +# values. See ticket #3343. +# +# $Id: alias.test,v 1.3 2009/04/23 13:22:44 drh Exp $ +# +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Aliases are currently evaluated twice. We might try to change this +# in the future. But not now. +return + +# A procedure to return a sequence of increasing integers. +# +namespace eval ::seq { + variable counter 0 + proc value {args} { + variable counter + incr counter + return $counter + } + proc reset {} { + variable counter + set counter 0 + } +} + + +do_test alias-1.1 { + db function sequence ::seq::value + db eval { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(9); + INSERT INTO t1 VALUES(8); + INSERT INTO t1 VALUES(7); + SELECT x, sequence() FROM t1; + } +} {9 1 8 2 7 3} +do_test alias-1.2 { + ::seq::reset + db eval { + SELECT x, sequence() AS y FROM t1 WHERE y>0 + } +} {9 1 8 2 7 3} +do_test alias-1.3 { + ::seq::reset + db eval { + SELECT x, sequence() AS y FROM t1 WHERE y>0 AND y<99 + } +} {9 1 8 2 7 3} +do_test alias-1.4 { + ::seq::reset + db eval { + SELECT x, sequence() AS y FROM t1 WHERE y>0 AND y<99 AND y!=55 + } +} {9 1 8 2 7 3} +do_test alias-1.5 { + ::seq::reset + db eval { + SELECT x, sequence() AS y FROM t1 + WHERE y>0 AND y<99 AND y!=55 AND y NOT IN (56,57,58) + AND y NOT LIKE 'abc%' AND y%10==2 + } +} {8 2} +do_test alias-1.6 { + ::seq::reset + db eval { + SELECT x, sequence() AS y FROM t1 WHERE y BETWEEN 0 AND 99 + } +} {9 1 8 2 7 3} +#do_test alias-1.7 { +# ::seq::reset +# db eval { +# SELECT x, sequence() AS y FROM t1 WHERE y IN (55,66,3) +# } +#} {7 3} +do_test alias-1.8 { + ::seq::reset + db eval { + SELECT x, 1-sequence() AS y FROM t1 ORDER BY y + } +} {7 -2 8 -1 9 0} +do_test alias-1.9 { + ::seq::reset + db eval { + SELECT x, sequence() AS y FROM t1 ORDER BY -y + } +} {7 3 8 2 9 1} +do_test alias-1.10 { + ::seq::reset + db eval { + SELECT x, sequence() AS y FROM t1 ORDER BY x%2, y + } +} {8 2 9 1 7 3} + +unset -nocomplain random_int_list +set random_int_list [db eval { + SELECT random()&2147483647 AS r FROM t1, t1, t1, t1 ORDER BY r +}] +do_test alias-1.11 { + lsort -integer $::random_int_list +} $random_int_list + + +do_test alias-2.1 { + db eval { + SELECT 4 UNION SELECT 1 ORDER BY 1 + } +} {1 4} +do_test alias-2.2 { + db eval { + SELECT 4 UNION SELECT 1 UNION SELECT 9 ORDER BY 1 + } +} {1 4 9} + +if 0 { + # Aliases in the GROUP BY clause cause the expression to be evaluated + # twice in the current implementation. This might change in the future. + # + do_test alias-3.1 { + ::seq::reset + db eval { + SELECT sequence(*) AS y, count(*) AS z FROM t1 GROUP BY y ORDER BY z, y + } + } {1 1 2 1 3 1} +} + +finish_test diff --git a/test/all.test b/test/all.test new file mode 100644 index 0000000..46e8115 --- /dev/null +++ b/test/all.test @@ -0,0 +1,51 @@ +# 2001 September 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file runs all tests. +# + +set testdir [file dirname $argv0] +source $testdir/permutations.test + +run_test_suite full + +ifcapable rbu { run_test_suite rbu } +run_test_suite no_optimization +run_test_suite memsubsys1 +run_test_suite memsubsys2 +run_test_suite singlethread +run_test_suite multithread +run_test_suite onefile +run_test_suite utf16 +run_test_suite exclusive +run_test_suite persistent_journal +run_test_suite persistent_journal_error +run_test_suite no_journal +run_test_suite no_journal_error +run_test_suite autovacuum_ioerr +run_test_suite no_mutex_try +run_test_suite fullmutex +run_test_suite journaltest +run_test_suite inmemory_journal +run_test_suite pcache0 +run_test_suite pcache10 +run_test_suite pcache50 +run_test_suite pcache90 +run_test_suite pcache100 +run_test_suite prepare +run_test_suite mmap + +if {$::tcl_platform(platform)=="unix"} { + ifcapable !default_autovacuum { + run_test_suite autovacuum_crash + } +} + +finish_test diff --git a/test/alter.test b/test/alter.test new file mode 100644 index 0000000..9201f40 --- /dev/null +++ b/test/alter.test @@ -0,0 +1,986 @@ +# 2004 November 10 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the ALTER TABLE statement. +# +# $Id: alter.test,v 1.32 2009/03/24 15:08:10 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. +ifcapable !altertable { + finish_test + return +} + +#---------------------------------------------------------------------- +# Test organization: +# +# alter-1.1.* - alter-1.7.*: Basic tests of ALTER TABLE, including tables +# with implicit and explicit indices. These tests came from an earlier +# fork of SQLite that also supported ALTER TABLE. +# alter-1.8.*: Tests for ALTER TABLE when the table resides in an +# attached database. +# alter-1.9.*: Tests for ALTER TABLE when their is whitespace between the +# table name and left parenthesis token. i.e: +# "CREATE TABLE abc (a, b, c);" +# alter-2.*: Test error conditions and messages. +# alter-3.*: Test ALTER TABLE on tables that have TRIGGERs attached to them. +# alter-4.*: Test ALTER TABLE on tables that have AUTOINCREMENT fields. +# ... +# alter-12.*: Test ALTER TABLE on views. +# + +# Create some tables to rename. Be sure to include some TEMP tables +# and some tables with odd names. +# +do_test alter-1.1 { + ifcapable tempdb { + set ::temp TEMP + } else { + set ::temp {} + } + execsql [subst -nocommands { + CREATE TABLE t1(a,b); + INSERT INTO t1 VALUES(1,2); + CREATE TABLE [t1'x1](c UNIQUE, b PRIMARY KEY); + INSERT INTO [t1'x1] VALUES(3,4); + CREATE INDEX t1i1 ON T1(B); + CREATE INDEX t1i2 ON t1(a,b); + CREATE INDEX i3 ON [t1'x1](b,c); + CREATE $::temp TABLE "temp table"(e,f,g UNIQUE); + CREATE INDEX i2 ON [temp table](f); + INSERT INTO [temp table] VALUES(5,6,7); + }] + execsql { + SELECT 't1', * FROM t1; + SELECT 't1''x1', * FROM "t1'x1"; + SELECT * FROM [temp table]; + } +} {t1 1 2 t1'x1 3 4 5 6 7} +do_test alter-1.2 { + execsql [subst { + CREATE $::temp TABLE objlist(type, name, tbl_name); + INSERT INTO objlist SELECT type, name, tbl_name + FROM sqlite_master WHERE NAME!='objlist'; + }] + ifcapable tempdb { + execsql { + INSERT INTO objlist SELECT type, name, tbl_name + FROM temp.sqlite_master WHERE NAME!='objlist'; + } + } + + execsql { + SELECT type, name, tbl_name FROM objlist ORDER BY tbl_name, type desc, name; + } +} [list \ + table t1 t1 \ + index t1i1 t1 \ + index t1i2 t1 \ + table t1'x1 t1'x1 \ + index i3 t1'x1 \ + index {sqlite_autoindex_t1'x1_1} t1'x1 \ + index {sqlite_autoindex_t1'x1_2} t1'x1 \ + table {temp table} {temp table} \ + index i2 {temp table} \ + index {sqlite_autoindex_temp table_1} {temp table} \ + ] + +# Make some changes +# +integrity_check alter-1.3.0 +do_test alter-1.3 { + execsql { + ALTER TABLE [T1] RENAME to [-t1-]; + ALTER TABLE "t1'x1" RENAME TO T2; + ALTER TABLE [temp table] RENAME to TempTab; + } +} {} +integrity_check alter-1.3.1 +do_test alter-1.4 { + execsql { + SELECT 't1', * FROM [-t1-]; + SELECT 't2', * FROM t2; + SELECT * FROM temptab; + } +} {t1 1 2 t2 3 4 5 6 7} +do_test alter-1.5 { + execsql { + DELETE FROM objlist; + INSERT INTO objlist SELECT type, name, tbl_name + FROM sqlite_master WHERE NAME!='objlist'; + } + catchsql { + INSERT INTO objlist SELECT type, name, tbl_name + FROM sqlite_temp_master WHERE NAME!='objlist'; + } + execsql { + SELECT type, name, tbl_name FROM objlist ORDER BY tbl_name, type desc, name; + } +} [list \ + table -t1- -t1- \ + index t1i1 -t1- \ + index t1i2 -t1- \ + table T2 T2 \ + index i3 T2 \ + index {sqlite_autoindex_T2_1} T2 \ + index {sqlite_autoindex_T2_2} T2 \ + table {TempTab} {TempTab} \ + index i2 {TempTab} \ + index {sqlite_autoindex_TempTab_1} {TempTab} \ + ] + +# Make sure the changes persist after restarting the database. +# (The TEMP table will not persist, of course.) +# +ifcapable tempdb { + do_test alter-1.6 { + db close + sqlite3 db test.db + set DB [sqlite3_connection_pointer db] + execsql { + CREATE TEMP TABLE objlist(type, name, tbl_name); + INSERT INTO objlist SELECT type, name, tbl_name FROM sqlite_master; + INSERT INTO objlist + SELECT type, name, tbl_name FROM temp.sqlite_master + WHERE NAME!='objlist'; + SELECT type, name, tbl_name FROM objlist + ORDER BY tbl_name, type desc, name; + } + } [list \ + table -t1- -t1- \ + index t1i1 -t1- \ + index t1i2 -t1- \ + table T2 T2 \ + index i3 T2 \ + index {sqlite_autoindex_T2_1} T2 \ + index {sqlite_autoindex_T2_2} T2 \ + ] +} else { + execsql { + DROP TABLE TempTab; + } +} + +# Create bogus application-defined functions for functions used +# internally by ALTER TABLE, to ensure that ALTER TABLE falls back +# to the built-in functions. +# +proc failing_app_func {args} {error "bad function"} +do_test alter-1.7-prep { + db func substr failing_app_func + db func like failing_app_func + db func sqlite_rename_table failing_app_func + db func sqlite_rename_trigger failing_app_func + db func sqlite_rename_parent failing_app_func + catchsql {SELECT substr(name,1,3) FROM sqlite_master} +} {1 {bad function}} + +# Make sure the ALTER TABLE statements work with the +# non-callback API +# +do_test alter-1.7 { + stepsql $DB { + ALTER TABLE [-t1-] RENAME to [*t1*]; + ALTER TABLE T2 RENAME TO []; + } + execsql { + DELETE FROM objlist; + INSERT INTO objlist SELECT type, name, tbl_name + FROM sqlite_master WHERE NAME!='objlist'; + } + catchsql { + INSERT INTO objlist SELECT type, name, tbl_name + FROM sqlite_temp_master WHERE NAME!='objlist'; + } + execsql { + SELECT type, name, tbl_name FROM objlist ORDER BY tbl_name, type desc, name; + } +} [list \ + table *t1* *t1* \ + index t1i1 *t1* \ + index t1i2 *t1* \ + table \ + index i3 \ + index {sqlite_autoindex__1} \ + index {sqlite_autoindex__2} \ + ] + +# Check that ALTER TABLE works on attached databases. +# +ifcapable attach { + do_test alter-1.8.1 { + forcedelete test2.db + forcedelete test2.db-journal + execsql { + ATTACH 'test2.db' AS aux; + } + } {} + do_test alter-1.8.2 { + execsql { + CREATE TABLE t4(a PRIMARY KEY, b, c); + CREATE TABLE aux.t4(a PRIMARY KEY, b, c); + CREATE INDEX i4 ON t4(b); + CREATE INDEX aux.i4 ON t4(b); + } + } {} + do_test alter-1.8.3 { + execsql { + INSERT INTO t4 VALUES('main', 'main', 'main'); + INSERT INTO aux.t4 VALUES('aux', 'aux', 'aux'); + SELECT * FROM t4 WHERE a = 'main'; + } + } {main main main} + do_test alter-1.8.4 { + execsql { + ALTER TABLE t4 RENAME TO t5; + SELECT * FROM t4 WHERE a = 'aux'; + } + } {aux aux aux} + do_test alter-1.8.5 { + execsql { + SELECT * FROM t5; + } + } {main main main} + do_test alter-1.8.6 { + execsql { + SELECT * FROM t5 WHERE b = 'main'; + } + } {main main main} + do_test alter-1.8.7 { + execsql { + ALTER TABLE aux.t4 RENAME TO t5; + SELECT * FROM aux.t5 WHERE b = 'aux'; + } + } {aux aux aux} +} + +do_test alter-1.9.1 { + execsql { + CREATE TABLE tbl1 (a, b, c); + INSERT INTO tbl1 VALUES(1, 2, 3); + } +} {} +do_test alter-1.9.2 { + execsql { + SELECT * FROM tbl1; + } +} {1 2 3} +do_test alter-1.9.3 { + execsql { + ALTER TABLE tbl1 RENAME TO tbl2; + SELECT * FROM tbl2; + } +} {1 2 3} +do_test alter-1.9.4 { + execsql { + DROP TABLE tbl2; + } +} {} + +# Test error messages +# +do_test alter-2.1 { + catchsql { + ALTER TABLE none RENAME TO hi; + } +} {1 {no such table: none}} +do_test alter-2.2 { + execsql { + CREATE TABLE t3(p,q,r); + } + catchsql { + ALTER TABLE [] RENAME TO t3; + } +} {1 {there is already another table or index with this name: t3}} +do_test alter-2.3 { + catchsql { + ALTER TABLE [] RENAME TO i3; + } +} {1 {there is already another table or index with this name: i3}} +do_test alter-2.4 { + catchsql { + ALTER TABLE SqLiTe_master RENAME TO master; + } +} {1 {table sqlite_master may not be altered}} +do_test alter-2.5 { + catchsql { + ALTER TABLE t3 RENAME TO sqlite_t3; + } +} {1 {object name reserved for internal use: sqlite_t3}} +do_test alter-2.6 { + catchsql { + ALTER TABLE t3 ADD COLUMN (ALTER TABLE t3 ADD COLUMN); + } +} {1 {near "(": syntax error}} + +# If this compilation does not include triggers, omit the alter-3.* tests. +ifcapable trigger { + +#----------------------------------------------------------------------- +# Tests alter-3.* test ALTER TABLE on tables that have triggers. +# +# alter-3.1.*: ALTER TABLE with triggers. +# alter-3.2.*: Test that the ON keyword cannot be used as a database, +# table or column name unquoted. This is done because part of the +# ALTER TABLE code (specifically the implementation of SQL function +# "sqlite_alter_trigger") will break in this case. +# alter-3.3.*: ALTER TABLE with TEMP triggers (todo). +# + +# An SQL user-function for triggers to fire, so that we know they +# are working. +proc trigfunc {args} { + set ::TRIGGER $args +} +db func trigfunc trigfunc + +do_test alter-3.1.0 { + execsql { + CREATE TABLE t6(a, b, c); + -- Different case for the table name in the trigger. + CREATE TRIGGER trig1 AFTER INSERT ON T6 BEGIN + SELECT trigfunc('trig1', new.a, new.b, new.c); + END; + } +} {} +do_test alter-3.1.1 { + execsql { + INSERT INTO t6 VALUES(1, 2, 3); + } + set ::TRIGGER +} {trig1 1 2 3} +do_test alter-3.1.2 { + execsql { + ALTER TABLE t6 RENAME TO t7; + INSERT INTO t7 VALUES(4, 5, 6); + } + set ::TRIGGER +} {trig1 4 5 6} +do_test alter-3.1.3 { + execsql { + DROP TRIGGER trig1; + } +} {} +do_test alter-3.1.4 { + execsql { + CREATE TRIGGER trig2 AFTER INSERT ON main.t7 BEGIN + SELECT trigfunc('trig2', new.a, new.b, new.c); + END; + INSERT INTO t7 VALUES(1, 2, 3); + } + set ::TRIGGER +} {trig2 1 2 3} +do_test alter-3.1.5 { + execsql { + ALTER TABLE t7 RENAME TO t8; + INSERT INTO t8 VALUES(4, 5, 6); + } + set ::TRIGGER +} {trig2 4 5 6} +do_test alter-3.1.6 { + execsql { + DROP TRIGGER trig2; + } +} {} +do_test alter-3.1.7 { + execsql { + CREATE TRIGGER trig3 AFTER INSERT ON main.'t8'BEGIN + SELECT trigfunc('trig3', new.a, new.b, new.c); + END; + INSERT INTO t8 VALUES(1, 2, 3); + } + set ::TRIGGER +} {trig3 1 2 3} +do_test alter-3.1.8 { + execsql { + ALTER TABLE t8 RENAME TO t9; + INSERT INTO t9 VALUES(4, 5, 6); + } + set ::TRIGGER +} {trig3 4 5 6} + +# Make sure "ON" cannot be used as a database, table or column name without +# quoting. Otherwise the sqlite_alter_trigger() function might not work. +forcedelete test3.db +forcedelete test3.db-journal +ifcapable attach { + do_test alter-3.2.1 { + catchsql { + ATTACH 'test3.db' AS ON; + } + } {1 {near "ON": syntax error}} + do_test alter-3.2.2 { + catchsql { + ATTACH 'test3.db' AS 'ON'; + } + } {0 {}} + do_test alter-3.2.3 { + catchsql { + CREATE TABLE ON.t1(a, b, c); + } + } {1 {near "ON": syntax error}} + do_test alter-3.2.4 { + catchsql { + CREATE TABLE 'ON'.t1(a, b, c); + } + } {0 {}} + do_test alter-3.2.4 { + catchsql { + CREATE TABLE 'ON'.ON(a, b, c); + } + } {1 {near "ON": syntax error}} + do_test alter-3.2.5 { + catchsql { + CREATE TABLE 'ON'.'ON'(a, b, c); + } + } {0 {}} +} +do_test alter-3.2.6 { + catchsql { + CREATE TABLE t10(a, ON, c); + } +} {1 {near "ON": syntax error}} +do_test alter-3.2.7 { + catchsql { + CREATE TABLE t10(a, 'ON', c); + } +} {0 {}} +do_test alter-3.2.8 { + catchsql { + CREATE TRIGGER trig4 AFTER INSERT ON ON BEGIN SELECT 1; END; + } +} {1 {near "ON": syntax error}} +ifcapable attach { + do_test alter-3.2.9 { + catchsql { + CREATE TRIGGER 'on'.trig4 AFTER INSERT ON 'ON' BEGIN SELECT 1; END; + } + } {0 {}} +} +do_test alter-3.2.10 { + execsql { + DROP TABLE t10; + } +} {} + +do_test alter-3.3.1 { + execsql [subst { + CREATE TABLE tbl1(a, b, c); + CREATE $::temp TRIGGER trig1 AFTER INSERT ON tbl1 BEGIN + SELECT trigfunc('trig1', new.a, new.b, new.c); + END; + }] +} {} +do_test alter-3.3.2 { + execsql { + INSERT INTO tbl1 VALUES('a', 'b', 'c'); + } + set ::TRIGGER +} {trig1 a b c} +do_test alter-3.3.3 { + execsql { + ALTER TABLE tbl1 RENAME TO tbl2; + INSERT INTO tbl2 VALUES('d', 'e', 'f'); + } + set ::TRIGGER +} {trig1 d e f} +do_test alter-3.3.4 { + execsql [subst { + CREATE $::temp TRIGGER trig2 AFTER UPDATE ON tbl2 BEGIN + SELECT trigfunc('trig2', new.a, new.b, new.c); + END; + }] +} {} +do_test alter-3.3.5 { + execsql { + ALTER TABLE tbl2 RENAME TO tbl3; + INSERT INTO tbl3 VALUES('g', 'h', 'i'); + } + set ::TRIGGER +} {trig1 g h i} +do_test alter-3.3.6 { + execsql { + UPDATE tbl3 SET a = 'G' where a = 'g'; + } + set ::TRIGGER +} {trig2 G h i} +do_test alter-3.3.7 { + execsql { + DROP TABLE tbl3; + } +} {} +ifcapable tempdb { + do_test alter-3.3.8 { + execsql { + SELECT * FROM temp.sqlite_master WHERE type = 'trigger'; + } + } {} +} + +} ;# ifcapable trigger + +# If the build does not include AUTOINCREMENT fields, omit alter-4.*. +ifcapable autoinc { + +do_test alter-4.1 { + execsql { + CREATE TABLE tbl1(a INTEGER PRIMARY KEY AUTOINCREMENT); + INSERT INTO tbl1 VALUES(10); + } +} {} +do_test alter-4.2 { + execsql { + INSERT INTO tbl1 VALUES(NULL); + SELECT a FROM tbl1; + } +} {10 11} +do_test alter-4.3 { + execsql { + ALTER TABLE tbl1 RENAME TO tbl2; + DELETE FROM tbl2; + INSERT INTO tbl2 VALUES(NULL); + SELECT a FROM tbl2; + } +} {12} +do_test alter-4.4 { + execsql { + DROP TABLE tbl2; + } +} {} + +} ;# ifcapable autoinc + +# Test that it is Ok to execute an ALTER TABLE immediately after +# opening a database. +do_test alter-5.1 { + execsql { + CREATE TABLE tbl1(a, b, c); + INSERT INTO tbl1 VALUES('x', 'y', 'z'); + } +} {} +do_test alter-5.2 { + sqlite3 db2 test.db + execsql { + ALTER TABLE tbl1 RENAME TO tbl2; + SELECT * FROM tbl2; + } db2 +} {x y z} +do_test alter-5.3 { + db2 close +} {} + +foreach tblname [execsql { + SELECT name FROM sqlite_master + WHERE type='table' AND name NOT GLOB 'sqlite*' +}] { + execsql "DROP TABLE \"$tblname\"" +} + +set ::tbl_name "abc\uABCDdef" +do_test alter-6.1 { + string length $::tbl_name +} {7} +do_test alter-6.2 { + execsql " + CREATE TABLE ${tbl_name}(a, b, c); + " + set ::oid [execsql {SELECT max(oid) FROM sqlite_master}] + execsql " + SELECT sql FROM sqlite_master WHERE oid = $::oid; + " +} "{CREATE TABLE ${::tbl_name}(a, b, c)}" +execsql " + SELECT * FROM ${::tbl_name} +" +set ::tbl_name2 "abcXdef" +do_test alter-6.3 { + execsql " + ALTER TABLE $::tbl_name RENAME TO $::tbl_name2 + " + execsql " + SELECT sql FROM sqlite_master WHERE oid = $::oid + " +} "{CREATE TABLE \"${::tbl_name2}\"(a, b, c)}" +do_test alter-6.4 { + execsql " + ALTER TABLE $::tbl_name2 RENAME TO $::tbl_name + " + execsql " + SELECT sql FROM sqlite_master WHERE oid = $::oid + " +} "{CREATE TABLE \"${::tbl_name}\"(a, b, c)}" +set ::col_name ghi\1234\jkl +do_test alter-6.5 { + execsql " + ALTER TABLE $::tbl_name ADD COLUMN $::col_name VARCHAR + " + execsql " + SELECT sql FROM sqlite_master WHERE oid = $::oid + " +} "{CREATE TABLE \"${::tbl_name}\"(a, b, c, $::col_name VARCHAR)}" +set ::col_name2 B\3421\A +do_test alter-6.6 { + db close + sqlite3 db test.db + execsql " + ALTER TABLE $::tbl_name ADD COLUMN $::col_name2 + " + execsql " + SELECT sql FROM sqlite_master WHERE oid = $::oid + " +} "{CREATE TABLE \"${::tbl_name}\"(a, b, c, $::col_name VARCHAR, $::col_name2)}" +do_test alter-6.7 { + execsql " + INSERT INTO ${::tbl_name} VALUES(1, 2, 3, 4, 5); + SELECT $::col_name, $::col_name2 FROM $::tbl_name; + " +} {4 5} + +# Ticket #1665: Make sure ALTER TABLE ADD COLUMN works on a table +# that includes a COLLATE clause. +# +do_realnum_test alter-7.1 { + execsql { + CREATE TABLE t1(a TEXT COLLATE BINARY); + ALTER TABLE t1 ADD COLUMN b INTEGER COLLATE NOCASE; + INSERT INTO t1 VALUES(1,'-2'); + INSERT INTO t1 VALUES(5.4e-08,'5.4e-08'); + SELECT typeof(a), a, typeof(b), b FROM t1; + } +} {text 1 integer -2 text 5.4e-08 real 5.4e-08} + +# Make sure that when a column is added by ALTER TABLE ADD COLUMN and has +# a default value that the default value is used by aggregate functions. +# +do_test alter-8.1 { + execsql { + CREATE TABLE t2(a INTEGER); + INSERT INTO t2 VALUES(1); + INSERT INTO t2 VALUES(1); + INSERT INTO t2 VALUES(2); + ALTER TABLE t2 ADD COLUMN b INTEGER DEFAULT 9; + SELECT sum(b) FROM t2; + } +} {27} +do_test alter-8.2 { + execsql { + SELECT a, sum(b) FROM t2 GROUP BY a; + } +} {1 18 2 9} + +#-------------------------------------------------------------------------- +# alter-9.X - Special test: Make sure the sqlite_rename_column() and +# rename_table() functions do not crash when handed bad input. +# +sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db +do_test alter-9.1 { + execsql {SELECT SQLITE_RENAME_COLUMN(0,0,0,0,0,0,0,0,0)} +} {{}} +foreach {tn sql} { + 1 { SELECT SQLITE_RENAME_TABLE(0,0,0,0,0,0,0) } + 2 { SELECT SQLITE_RENAME_TABLE(10,20,30,40,50,60,70) } + 3 { SELECT SQLITE_RENAME_TABLE('foo','foo','foo','foo','foo','foo','foo') } +} { + do_test alter-9.2.$tn { + catch { execsql $sql } + } 1 +} +sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db + +# If the INTERNAL_FUNCTIONS test-control is disabled (which is the default), +# then the sqlite_rename_table() SQL function is not accessible to ordinary SQL. +# +do_catchsql_test alter-9.3 { + SELECT sqlite_rename_table(0,0,0,0,0,0,0); +} {1 {no such function: sqlite_rename_table}} + +#------------------------------------------------------------------------ +# alter-10.X - Make sure ALTER TABLE works with multi-byte UTF-8 characters +# in the names. +# +do_test alter-10.1 { + execsql "CREATE TABLE xyz(x UNIQUE)" + execsql "ALTER TABLE xyz RENAME TO xyz\u1234abc" + execsql {SELECT name FROM sqlite_master WHERE name GLOB 'xyz*'} +} [list xyz\u1234abc] +do_test alter-10.2 { + execsql {SELECT name FROM sqlite_master WHERE name GLOB 'sqlite_autoindex*'} +} [list sqlite_autoindex_xyz\u1234abc_1] +do_test alter-10.3 { + execsql "ALTER TABLE xyz\u1234abc RENAME TO xyzabc" + execsql {SELECT name FROM sqlite_master WHERE name GLOB 'xyz*'} +} [list xyzabc] +do_test alter-10.4 { + execsql {SELECT name FROM sqlite_master WHERE name GLOB 'sqlite_autoindex*'} +} [list sqlite_autoindex_xyzabc_1] + +do_test alter-11.1 { + sqlite3_exec db {CREATE TABLE t11(%c6%c6)} + execsql { + ALTER TABLE t11 ADD COLUMN abc; + } + catchsql { + ALTER TABLE t11 ADD COLUMN abc; + } +} {1 {duplicate column name: abc}} +set isutf16 [regexp 16 [db one {PRAGMA encoding}]] +if {!$isutf16} { + do_test alter-11.2 { + execsql {INSERT INTO t11 VALUES(1,2)} + sqlite3_exec db {SELECT %c6%c6 AS xyz, abc FROM t11} + } {0 {xyz abc 1 2}} +} +do_test alter-11.3 { + sqlite3_exec db {CREATE TABLE t11b("%81%82%83" text)} + execsql { + ALTER TABLE t11b ADD COLUMN abc; + } + catchsql { + ALTER TABLE t11b ADD COLUMN abc; + } +} {1 {duplicate column name: abc}} +if {!$isutf16} { + do_test alter-11.4 { + execsql {INSERT INTO t11b VALUES(3,4)} + sqlite3_exec db {SELECT %81%82%83 AS xyz, abc FROM t11b} + } {0 {xyz abc 3 4}} + do_test alter-11.5 { + sqlite3_exec db {SELECT [%81%82%83] AS xyz, abc FROM t11b} + } {0 {xyz abc 3 4}} + do_test alter-11.6 { + sqlite3_exec db {SELECT "%81%82%83" AS xyz, abc FROM t11b} + } {0 {xyz abc 3 4}} +} +do_test alter-11.7 { + sqlite3_exec db {CREATE TABLE t11c(%81%82%83 text)} + execsql { + ALTER TABLE t11c ADD COLUMN abc; + } + catchsql { + ALTER TABLE t11c ADD COLUMN abc; + } +} {1 {duplicate column name: abc}} +if {!$isutf16} { + do_test alter-11.8 { + execsql {INSERT INTO t11c VALUES(5,6)} + sqlite3_exec db {SELECT %81%82%83 AS xyz, abc FROM t11c} + } {0 {xyz abc 5 6}} + do_test alter-11.9 { + sqlite3_exec db {SELECT [%81%82%83] AS xyz, abc FROM t11c} + } {0 {xyz abc 5 6}} + do_test alter-11.10 { + sqlite3_exec db {SELECT "%81%82%83" AS xyz, abc FROM t11c} + } {0 {xyz abc 5 6}} +} + +do_test alter-12.1 { + execsql { + CREATE TABLE t12(a, b, c); + CREATE VIEW v1 AS SELECT * FROM t12; + } +} {} +do_test alter-12.2 { + catchsql { + ALTER TABLE v1 RENAME TO v2; + } +} {1 {view v1 may not be altered}} +do_test alter-12.3 { + execsql { SELECT * FROM v1; } +} {} +do_test alter-12.4 { + db close + sqlite3 db test.db + execsql { SELECT * FROM v1; } +} {} +do_test alter-12.5 { + catchsql { + ALTER TABLE v1 ADD COLUMN new_column; + } +} {1 {Cannot add a column to a view}} + +# Ticket #3102: +# Verify that comments do not interfere with the table rename +# algorithm. +# +do_test alter-13.1 { + execsql { + CREATE TABLE /* hi */ t3102a(x); + CREATE TABLE t3102b -- comment + (y); + CREATE INDEX t3102c ON t3102a(x); + SELECT name FROM sqlite_master WHERE name GLOB 't3102*' ORDER BY 1; + } +} {t3102a t3102b t3102c} +do_test alter-13.2 { + execsql { + ALTER TABLE t3102a RENAME TO t3102a_rename; + SELECT name FROM sqlite_master WHERE name GLOB 't3102*' ORDER BY 1; + } +} {t3102a_rename t3102b t3102c} +do_test alter-13.3 { + execsql { + ALTER TABLE t3102b RENAME TO t3102b_rename; + SELECT name FROM sqlite_master WHERE name GLOB 't3102*' ORDER BY 1; + } +} {t3102a_rename t3102b_rename t3102c} + +# Ticket #3651 +do_test alter-14.1 { + catchsql { + CREATE TABLE t3651(a UNIQUE); + INSERT INTO t3651 VALUES(5); + ALTER TABLE t3651 ADD COLUMN b UNIQUE; + } +} {1 {Cannot add a UNIQUE column}} +do_test alter-14.2 { + catchsql { + ALTER TABLE t3651 ADD COLUMN b PRIMARY KEY; + } +} {1 {Cannot add a PRIMARY KEY column}} + + +#------------------------------------------------------------------------- +# Test that it is not possible to use ALTER TABLE on any system table. +# +set system_table_list {1 sqlite_master} +catchsql ANALYZE +ifcapable analyze { lappend system_table_list 2 sqlite_stat1 } +ifcapable stat4 { lappend system_table_list 4 sqlite_stat4 } + +foreach {tn tbl} $system_table_list { + do_test alter-15.$tn.1 { + catchsql "ALTER TABLE $tbl RENAME TO xyz" + } [list 1 "table $tbl may not be altered"] + + do_test alter-15.$tn.2 { + catchsql "ALTER TABLE $tbl ADD COLUMN xyz" + } [list 1 "table $tbl may not be altered"] +} + +#------------------------------------------------------------------------ +# Verify that ALTER TABLE works on tables with the WITHOUT rowid option. +# +do_execsql_test alter-16.1 { + CREATE TABLE t16a(a TEXT, b REAL, c INT, PRIMARY KEY(a,b)) WITHOUT rowid; + INSERT INTO t16a VALUES('abc',1.25,99); + ALTER TABLE t16a ADD COLUMN d TEXT DEFAULT 'xyzzy'; + INSERT INTO t16a VALUES('cba',5.5,98,'fizzle'); + SELECT * FROM t16a ORDER BY a; +} {abc 1.25 99 xyzzy cba 5.5 98 fizzle} +do_execsql_test alter-16.2 { + ALTER TABLE t16a RENAME TO t16a_rn; + SELECT * FROM t16a_rn ORDER BY a; +} {abc 1.25 99 xyzzy cba 5.5 98 fizzle} + +# 2018-09-16 ticket b41031ea2b5372378cb3d2d43cf9fe2a4a5c2510 +# +ifcapable rtree { + db close + sqlite3 db :memory: + do_execsql_test alter-17.100 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + CREATE VIRTUAL TABLE t2 USING rtree(id,x0,x1); + INSERT INTO t1 VALUES(1,'apple'),(2,'fig'),(3,'pear'); + INSERT INTO t2 VALUES(1,1.0,2.0),(2,2.0,3.0),(3,1.5,3.5); + CREATE TRIGGER r1 AFTER UPDATE ON t1 BEGIN + DELETE FROM t2 WHERE id = OLD.a; + END; + ALTER TABLE t1 RENAME TO t3; + UPDATE t3 SET b='peach' WHERE a=2; + SELECT * FROM t2 ORDER BY 1; + } {1 1.0 2.0 3 1.5 3.5} +} + +# 2021-03-08 dbsqlfuzz 3f0a7245b69cd08617d7d7781ebaedb0fe765a93 +reset_db +do_catchsql_test alter-18.1 { + CREATE TABLE t1(a,b,c); + CREATE TABLE log(a INTEGER PRIMARY KEY,b,c); + CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN + INSERT INTO logx(a,b,c) VALUES(new.a,new.b,new.c) + ON CONFLICT(a) DO UPDATE SET c=excluded.c, b=new.b; + END; + ALTER TABLE log RENAME COLUMN a TO x; +} {1 {error in trigger tr1: no such table: main.logx}} + +# 2021-10-13 dbsqlfuzz e89174cbfad2d904f06b5e24df0a22510b6a1c1e +reset_db +do_execsql_test alter-19.1 { + CREATE TABLE t1(x); + CREATE TABLE t2(c); + CREATE TRIGGER r1 AFTER INSERT ON t2 BEGIN + UPDATE t2 SET (c)=( + EXISTS(SELECT 1 WHERE (WITH cte1(a) AS (SELECT 1 FROM t1 WHERE (SELECT 1 WHERE (WITH cte2(b) AS (VALUES(1))SELECT b FROM cte2)))SELECT a FROM cte1)) + ); + END; + ALTER TABLE t2 RENAME TO t3; +} {} +do_execsql_test alter-19.2 { + SELECT name FROM sqlite_schema WHERE sql LIKE '%t2%'; +} {} +do_execsql_test alter-19.3 { + SELECT name FROM sqlite_schema WHERE sql LIKE '%t3%' ORDER BY name; +} {r1 t3} + +# 2023-10-14 +# On an ALTER TABLE ADD COLUMN with a DEFAULT clause on a STRICT table +# make sure that the DEFAULT has a compatible type. +# +reset_db +do_execsql_test alter-20.1 { + CREATE TABLE t1(a INT) STRICT; + INSERT INTO t1(a) VALUES(45); +} {} +do_catchsql_test alter-20.2 { + ALTER TABLE t1 ADD COLUMN b TEXT DEFAULT x'313233'; +} {1 {type mismatch on DEFAULT}} +do_execsql_test alter-20.2 { + DELETE FROM t1; + ALTER TABLE t1 ADD COLUMN b TEXT DEFAULT x'313233'; +} {} +do_catchsql_test alter-20.3 { + INSERT INTO t1(a) VALUES(45); +} {1 {cannot store BLOB value in TEXT column t1.b}} + +# 2023-11-17 dbsqlfuzz e0900262dadd5c78c2226ad6a435c7f0255be2cd +# Assertion fault associated with ALTER TABLE and an +# aggregate ORDER BY within an unknown aggregate function. +# +reset_db +do_execsql_test alter-21.1 { + CREATE TABLE t1(a,b,c,d); + CREATE TABLE t2(a,b,c,d,x); + CREATE TRIGGER r1 AFTER INSERT ON t2 BEGIN + SELECT unknown_function(a ORDER BY (SELECT group_concat(DISTINCT a ORDER BY a) FROM t1)) FROM t1; + END; + ALTER TABLE t2 RENAME TO e; +} {} +do_execsql_test alter-21.2 { + SELECT name, type FROM sqlite_schema ORDER BY name; +} {e table r1 trigger t1 table} +do_execsql_test alter-21.3 { + DROP TRIGGER r1; + CREATE TRIGGER r2 AFTER INSERT ON e BEGIN + SELECT unknown_function(a ORDER BY (SELECT group_concat(a ORDER BY a) FROM (SELECT b FROM t1))) FROM t1; + END; + ALTER TABLE e RENAME TO t99; +} +do_execsql_test alter-21.4 { + SELECT name, type FROM sqlite_schema ORDER BY name; +} {r2 trigger t1 table t99 table} + + + +finish_test diff --git a/test/alter2.test b/test/alter2.test new file mode 100644 index 0000000..aae0061 --- /dev/null +++ b/test/alter2.test @@ -0,0 +1,470 @@ +# 2005 February 18 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing that SQLite can handle a subtle +# file format change that may be used in the future to implement +# "ALTER TABLE ... ADD COLUMN". +# +# $Id: alter2.test,v 1.14 2009/04/07 14:14:22 danielk1977 Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# We have to have pragmas in order to do this test +ifcapable {!pragma} return + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts. See proc [set_file_format]. +# +do_not_use_codec + +# The file format change affects the way row-records stored in tables (but +# not indices) are interpreted. Before version 3.1.3, a row-record for a +# table with N columns was guaranteed to contain exactly N fields. As +# of version 3.1.3, the record may contain up to N fields. In this case +# the M fields that are present are the values for the left-most M +# columns. The (N-M) rightmost columns contain NULL. +# +# If any records in the database contain less fields than their table +# has columns, then the file-format meta value should be set to (at least) 2. +# + +# This procedure sets the value of the file-format in file 'test.db' +# to $newval. Also, the schema cookie is incremented. +# +proc set_file_format {newval} { + hexio_write test.db 44 [hexio_render_int32 $newval] + set schemacookie [hexio_get_int [hexio_read test.db 40 4]] + incr schemacookie + hexio_write test.db 40 [hexio_render_int32 $schemacookie] + return {} +} + +# This procedure returns the value of the file-format in file 'test.db'. +# +proc get_file_format {{fname test.db}} { + return [hexio_get_int [hexio_read $fname 44 4]] +} + +# This procedure sets the SQL statement stored for table $tbl in the +# sqlite_master table of file 'test.db' to $sql. Also set the file format +# to the supplied value. This is 2 if the added column has a default that is +# NULL, or 3 otherwise. +# +proc alter_table {tbl sql {file_format 2}} { + sqlite3 dbat test.db + set s [string map {' ''} $sql] + set t [string map {' ''} $tbl] + sqlite3_db_config dbat DEFENSIVE 0 + dbat eval [subst { + PRAGMA writable_schema = 1; + UPDATE sqlite_master SET sql = '$s' WHERE name = '$t' AND type = 'table'; + PRAGMA writable_schema = 0; + }] + dbat close + set_file_format 2 +} + +# Create bogus application-defined functions for functions used +# internally by ALTER TABLE, to ensure that ALTER TABLE falls back +# to the built-in functions. +# +proc failing_app_func {args} {error "bad function"} +do_test alter2-1.0 { + db func substr failing_app_func + db func like failing_app_func + db func sqlite_rename_table failing_app_func + db func sqlite_rename_trigger failing_app_func + db func sqlite_rename_parent failing_app_func + catchsql {SELECT substr('abcdefg',1,3)} +} {1 {bad function}} + + +#----------------------------------------------------------------------- +# Some basic tests to make sure short rows are handled. +# +sqlite3_db_config db DEFENSIVE 0 +do_test alter2-1.1 { + execsql { + CREATE TABLE abc(a, b); + INSERT INTO abc VALUES(1, 2); + INSERT INTO abc VALUES(3, 4); + INSERT INTO abc VALUES(5, 6); + } +} {} +do_test alter2-1.2 { + # ALTER TABLE abc ADD COLUMN c; + alter_table abc {CREATE TABLE abc(a, b, c);} +} {} +do_test alter2-1.3 { + execsql { + SELECT * FROM abc; + } +} {1 2 {} 3 4 {} 5 6 {}} +do_test alter2-1.4 { + execsql { + UPDATE abc SET c = 10 WHERE a = 1; + SELECT * FROM abc; + } +} {1 2 10 3 4 {} 5 6 {}} +do_test alter2-1.5 { + execsql { + CREATE INDEX abc_i ON abc(c); + } +} {} +do_test alter2-1.6 { + execsql { + SELECT c FROM abc ORDER BY c; + } +} {{} {} 10} +do_test alter2-1.7 { + execsql { + SELECT * FROM abc WHERE c = 10; + } +} {1 2 10} +do_test alter2-1.8 { + execsql { + SELECT sum(a), c FROM abc GROUP BY c; + } +} {8 {} 1 10} +do_test alter2-1.9 { + # ALTER TABLE abc ADD COLUMN d; + alter_table abc {CREATE TABLE abc(a, b, c, d);} + if {[permutation] == "prepare"} { db cache flush } + execsql { SELECT * FROM abc; } + execsql { + UPDATE abc SET d = 11 WHERE c IS NULL AND a<4; + SELECT * FROM abc; + } +} {1 2 10 {} 3 4 {} 11 5 6 {} {}} +do_test alter2-1.10 { + execsql { + SELECT typeof(d) FROM abc; + } +} {null integer null} +do_test alter2-1.99 { + execsql { + DROP TABLE abc; + } +} {} + +#----------------------------------------------------------------------- +# Test that views work when the underlying table structure is changed. +# +ifcapable view { + do_test alter2-2.1 { + execsql { + CREATE TABLE abc2(a, b, c); + INSERT INTO abc2 VALUES(1, 2, 10); + INSERT INTO abc2 VALUES(3, 4, NULL); + INSERT INTO abc2 VALUES(5, 6, NULL); + CREATE VIEW abc2_v AS SELECT * FROM abc2; + SELECT * FROM abc2_v; + } + } {1 2 10 3 4 {} 5 6 {}} + do_test alter2-2.2 { + # ALTER TABLE abc ADD COLUMN d; + alter_table abc2 {CREATE TABLE abc2(a, b, c, d);} + execsql { + SELECT * FROM abc2_v; + } + } {1 2 10 {} 3 4 {} {} 5 6 {} {}} + do_test alter2-2.3 { + execsql { + DROP TABLE abc2; + DROP VIEW abc2_v; + } + } {} +} + +#----------------------------------------------------------------------- +# Test that triggers work when a short row is copied to the old.* +# trigger pseudo-table. +# +ifcapable trigger { + do_test alter2-3.1 { + execsql { + CREATE TABLE abc3(a, b); + CREATE TABLE blog(o, n); + CREATE TRIGGER abc3_t AFTER UPDATE OF b ON abc3 BEGIN + INSERT INTO blog VALUES(old.b, new.b); + END; + } + } {} + do_test alter2-3.2 { + execsql { + INSERT INTO abc3 VALUES(1, 4); + UPDATE abc3 SET b = 2 WHERE b = 4; + SELECT * FROM blog; + } + } {4 2} + do_test alter2-3.3 { + execsql { + INSERT INTO abc3 VALUES(3, 4); + INSERT INTO abc3 VALUES(5, 6); + } + alter_table abc3 {CREATE TABLE abc3(a, b, c);} + execsql { + SELECT * FROM abc3; + } + } {1 2 {} 3 4 {} 5 6 {}} + do_test alter2-3.4 { + execsql { + UPDATE abc3 SET b = b*2 WHERE a<4; + SELECT * FROM abc3; + } + } {1 4 {} 3 8 {} 5 6 {}} + do_test alter2-3.5 { + execsql { + SELECT * FROM blog; + } + } {4 2 2 4 4 8} + + do_test alter2-3.6 { + execsql { + CREATE TABLE clog(o, n); + CREATE TRIGGER abc3_t2 AFTER UPDATE OF c ON abc3 BEGIN + INSERT INTO clog VALUES(old.c, new.c); + END; + UPDATE abc3 SET c = a*2; + SELECT * FROM clog; + } + } {{} 2 {} 6 {} 10} +} else { + execsql { CREATE TABLE abc3(a, b); } +} + +#--------------------------------------------------------------------- +# Check that an error occurs if the database is upgraded to a file +# format that SQLite does not support (in this case 5). Note: The +# file format is checked each time the schema is read, so changing the +# file format requires incrementing the schema cookie. +# +do_test alter2-4.1 { + db close + set_file_format 5 + catch { sqlite3 db test.db } + set {} {} +} {} +do_test alter2-4.2 { + # We have to run two queries here because the Tcl interface uses + # sqlite3_prepare_v2(). In this case, the first query encounters an + # SQLITE_SCHEMA error. Then, when trying to recompile the statement, the + # "unsupported file format" error is encountered. So the error code + # returned is SQLITE_SCHEMA, not SQLITE_ERROR as required by the following + # test case. + # + # When the query is attempted a second time, the same error message is + # returned but the error code is SQLITE_ERROR, because the unsupported + # file format was detected during a call to sqlite3_prepare(), not + # sqlite3_step(). + # + catchsql { SELECT * FROM sqlite_master; } + catchsql { SELECT * FROM sqlite_master; } +} {1 {unsupported file format}} +do_test alter2-4.3 { + sqlite3_errcode db +} {SQLITE_ERROR} +do_test alter2-4.4 { + set ::DB [sqlite3_connection_pointer db] + catchsql { + SELECT * FROM sqlite_master; + } +} {1 {unsupported file format}} +do_test alter2-4.5 { + sqlite3_errcode db +} {SQLITE_ERROR} + +#--------------------------------------------------------------------- +# Check that executing VACUUM on a file with file-format version 2 +# resets the file format to 1. +# +set default_file_format [expr $SQLITE_DEFAULT_FILE_FORMAT==4 ? 4 : 1] +ifcapable vacuum { + do_test alter2-5.1 { + set_file_format 2 + db close + sqlite3 db test.db + execsql {SELECT 1 FROM sqlite_master LIMIT 1;} + get_file_format + } {2} + do_test alter2-5.2 { + execsql { VACUUM } + } {} + do_test alter2-5.3 { + get_file_format + } $default_file_format +} + +#--------------------------------------------------------------------- +# Test that when a database with file-format 2 is opened, new +# databases are still created with file-format 1. +# +do_test alter2-6.1 { + db close + set_file_format 2 + sqlite3 db test.db + get_file_format +} {2} +ifcapable attach { + do_test alter2-6.2 { + forcedelete test2.db-journal + forcedelete test2.db + execsql { + ATTACH 'test2.db' AS aux; + CREATE TABLE aux.t1(a, b); + } + get_file_format test2.db + } $default_file_format +} +do_test alter2-6.3 { + execsql { + CREATE TABLE t1(a, b); + } + get_file_format +} {2} + +#--------------------------------------------------------------------- +# Test that types and values for columns added with default values +# other than NULL work with SELECT statements. +# +do_test alter2-7.1 { + execsql { + DROP TABLE t1; + CREATE TABLE t1(a); + INSERT INTO t1 VALUES(1); + INSERT INTO t1 VALUES(2); + INSERT INTO t1 VALUES(3); + INSERT INTO t1 VALUES(4); + SELECT * FROM t1; + } +} {1 2 3 4} +do_test alter2-7.2 { + set sql {CREATE TABLE t1(a, b DEFAULT '123', c INTEGER DEFAULT '123')} + alter_table t1 $sql 3 + execsql { + SELECT * FROM t1 LIMIT 1; + } +} {1 123 123} +do_test alter2-7.3 { + execsql { + SELECT a, typeof(a), b, typeof(b), c, typeof(c) FROM t1 LIMIT 1; + } +} {1 integer 123 text 123 integer} +do_test alter2-7.4 { + execsql { + SELECT a, typeof(a), b, typeof(b), c, typeof(c) FROM t1 LIMIT 1; + } +} {1 integer 123 text 123 integer} +do_test alter2-7.5 { + set sql {CREATE TABLE t1(a, b DEFAULT -123.0, c VARCHAR(10) default 5)} + alter_table t1 $sql 3 + execsql { + SELECT a, typeof(a), b, typeof(b), c, typeof(c) FROM t1 LIMIT 1; + } +} {1 integer -123 integer 5 text} + +#----------------------------------------------------------------------- +# Test that UPDATE trigger tables work with default values, and that when +# a row is updated the default values are correctly transfered to the +# new row. +# +ifcapable trigger { +db function set_val {set ::val} + do_test alter2-8.1 { + execsql { + CREATE TRIGGER trig1 BEFORE UPDATE ON t1 BEGIN + SELECT set_val( + old.b||' '||typeof(old.b)||' '||old.c||' '||typeof(old.c)||' '|| + new.b||' '||typeof(new.b)||' '||new.c||' '||typeof(new.c) + ); + END; + } + list + } {} +} +do_test alter2-8.2 { + execsql { + UPDATE t1 SET c = 10 WHERE a = 1; + SELECT a, typeof(a), b, typeof(b), c, typeof(c) FROM t1 LIMIT 1; + } +} {1 integer -123 integer 10 text} +ifcapable trigger { + do_test alter2-8.3 { + set ::val + } {-123 integer 5 text -123 integer 10 text} +} + +#----------------------------------------------------------------------- +# Test that DELETE trigger tables work with default values, and that when +# a row is updated the default values are correctly transfered to the +# new row. +# +ifcapable trigger { + do_test alter2-9.1 { + execsql { + CREATE TRIGGER trig2 BEFORE DELETE ON t1 BEGIN + SELECT set_val( + old.b||' '||typeof(old.b)||' '||old.c||' '||typeof(old.c) + ); + END; + } + list + } {} + do_test alter2-9.2 { + execsql { + DELETE FROM t1 WHERE a = 2; + } + set ::val + } {-123 integer 5 text} +} + +#----------------------------------------------------------------------- +# Test creating an index on a column added with a default value. +# +ifcapable bloblit { + do_test alter2-10.1 { + execsql { + CREATE TABLE t2(a); + INSERT INTO t2 VALUES('a'); + INSERT INTO t2 VALUES('b'); + INSERT INTO t2 VALUES('c'); + INSERT INTO t2 VALUES('d'); + } + alter_table t2 {CREATE TABLE t2(a, b DEFAULT X'ABCD', c DEFAULT NULL);} 3 + catchsql { + SELECT * FROM sqlite_master; + } + execsql { + SELECT quote(a), quote(b), quote(c) FROM t2 LIMIT 1; + } + } {'a' X'ABCD' NULL} + do_test alter2-10.2 { + execsql { + CREATE INDEX i1 ON t2(b); + SELECT a FROM t2 WHERE b = X'ABCD'; + } + } {a b c d} + do_test alter2-10.3 { + execsql { + DELETE FROM t2 WHERE a = 'c'; + SELECT a FROM t2 WHERE b = X'ABCD'; + } + } {a b d} + do_test alter2-10.4 { + execsql { + SELECT count(b) FROM t2 WHERE b = X'ABCD'; + } + } {3} +} + +finish_test diff --git a/test/alter3.test b/test/alter3.test new file mode 100644 index 0000000..c6f26b0 --- /dev/null +++ b/test/alter3.test @@ -0,0 +1,443 @@ +# 2005 February 19 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing that SQLite can handle a subtle +# file format change that may be used in the future to implement +# "ALTER TABLE ... ADD COLUMN". +# + +set testdir [file dirname $argv0] + +source $testdir/tester.tcl + +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. +ifcapable !altertable { + finish_test + return +} + +# Determine if there is a codec available on this test. +# +if {[catch {sqlite3 -has-codec} r] || $r} { + set has_codec 1 +} else { + set has_codec 0 +} + + +# Test Organisation: +# ------------------ +# +# alter3-1.*: Test that ALTER TABLE correctly modifies the CREATE TABLE sql. +# alter3-2.*: Test error messages. +# alter3-3.*: Test adding columns with default value NULL. +# alter3-4.*: Test adding columns with default values other than NULL. +# alter3-5.*: Test adding columns to tables in ATTACHed databases. +# alter3-6.*: Test that temp triggers are not accidentally dropped. +# alter3-7.*: Test that VACUUM resets the file-format. +# + +# This procedure returns the value of the file-format in file 'test.db'. +# +proc get_file_format {{fname test.db}} { + return [hexio_get_int [hexio_read $fname 44 4]] +} + +do_test alter3-1.1 { + sqlite3_db_config db LEGACY_FILE_FORMAT 1 + execsql { + CREATE TABLE abc(a, b, c); + SELECT sql FROM sqlite_master; + } +} {{CREATE TABLE abc(a, b, c)}} +do_test alter3-1.2 { + execsql {ALTER TABLE abc ADD d INTEGER;} + execsql { + SELECT sql FROM sqlite_master; + } +} {{CREATE TABLE abc(a, b, c, d INTEGER)}} +do_test alter3-1.3 { + execsql {ALTER TABLE abc ADD e} + execsql { + SELECT sql FROM sqlite_master; + } +} {{CREATE TABLE abc(a, b, c, d INTEGER, e)}} +do_test alter3-1.4 { + execsql { + CREATE TABLE main.t1(a, b); + ALTER TABLE t1 ADD c; + SELECT sql FROM sqlite_master WHERE tbl_name = 't1'; + } +} {{CREATE TABLE t1(a, b, c)}} +do_test alter3-1.5 { + execsql { + ALTER TABLE t1 ADD d CHECK (a>d); + SELECT sql FROM sqlite_master WHERE tbl_name = 't1'; + } +} {{CREATE TABLE t1(a, b, c, d CHECK (a>d))}} +ifcapable foreignkey { + do_test alter3-1.6 { + execsql { + CREATE TABLE t2(a, b, UNIQUE(a, b)); + ALTER TABLE t2 ADD c REFERENCES t1(c) ; + SELECT sql FROM sqlite_master WHERE tbl_name = 't2' AND type = 'table'; + } + } {{CREATE TABLE t2(a, b, c REFERENCES t1(c), UNIQUE(a, b))}} +} +do_test alter3-1.7 { + execsql { + CREATE TABLE t3(a, b, UNIQUE(a, b)); + ALTER TABLE t3 ADD COLUMN c VARCHAR(10, 20); + SELECT sql FROM sqlite_master WHERE tbl_name = 't3' AND type = 'table'; + } +} {{CREATE TABLE t3(a, b, c VARCHAR(10, 20), UNIQUE(a, b))}} +do_test alter3-1.99 { + catchsql { + # May not exist if foriegn-keys are omitted at compile time. + DROP TABLE t2; + } + execsql { + DROP TABLE abc; + DROP TABLE t1; + DROP TABLE t3; + } +} {} + +do_test alter3-2.1 { + execsql { + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1,2); + } + catchsql { + ALTER TABLE t1 ADD c PRIMARY KEY; + } +} {1 {Cannot add a PRIMARY KEY column}} +do_test alter3-2.2 { + catchsql { + ALTER TABLE t1 ADD c UNIQUE + } +} {1 {Cannot add a UNIQUE column}} +do_test alter3-2.3 { + catchsql { + ALTER TABLE t1 ADD b VARCHAR(10) + } +} {1 {duplicate column name: b}} +do_test alter3-2.3 { + catchsql { + ALTER TABLE t1 ADD c NOT NULL; + } +} {1 {Cannot add a NOT NULL column with default value NULL}} +do_test alter3-2.4 { + catchsql { + ALTER TABLE t1 ADD c NOT NULL DEFAULT 10; + } +} {0 {}} +ifcapable view { + do_test alter3-2.5 { + execsql { + CREATE VIEW v1 AS SELECT * FROM t1; + } + catchsql { + alter table v1 add column d; + } + } {1 {Cannot add a column to a view}} +} +do_test alter3-2.6 { + catchsql { + alter table t1 add column d DEFAULT CURRENT_TIME; + } +} {1 {Cannot add a column with non-constant default}} +do_test alter3-2.99 { + execsql { + DROP TABLE t1; + } +} {} + +do_test alter3-3.1 { + execsql { + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 100); + INSERT INTO t1 VALUES(2, 300); + SELECT * FROM t1; + } +} {1 100 2 300} +do_test alter3-3.1 { + execsql { + PRAGMA schema_version = 10; + } +} {} +do_test alter3-3.2 { + execsql { + ALTER TABLE t1 ADD c; + SELECT * FROM t1; + } +} {1 100 {} 2 300 {}} +if {!$has_codec} { + do_test alter3-3.3 { + get_file_format + } {3} +} +ifcapable schema_version { + do_test alter3-3.4 { + execsql { + PRAGMA schema_version; + } + } {11} +} + +do_test alter3-4.1 { + db close + forcedelete test.db + set ::DB [sqlite3 db test.db] + sqlite3_db_config db LEGACY_FILE_FORMAT 1 + execsql { + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 100); + INSERT INTO t1 VALUES(2, 300); + SELECT * FROM t1; + } +} {1 100 2 300} +do_test alter3-4.1 { + execsql { + PRAGMA schema_version = 20; + } +} {} +do_test alter3-4.2 { + execsql { + ALTER TABLE t1 ADD c DEFAULT 'hello world'; + SELECT * FROM t1; + } +} {1 100 {hello world} 2 300 {hello world}} +if {!$has_codec} { + do_test alter3-4.3 { + get_file_format + } {3} +} +ifcapable schema_version { + do_test alter3-4.4 { + execsql { + PRAGMA schema_version; + } + } {21} +} +do_test alter3-4.99 { + execsql { + DROP TABLE t1; + } +} {} + +ifcapable attach { + do_test alter3-5.1 { + forcedelete test2.db + forcedelete test2.db-journal + execsql { + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 'one'); + INSERT INTO t1 VALUES(2, 'two'); + ATTACH 'test2.db' AS aux; + CREATE TABLE aux.t1 AS SELECT * FROM t1; + PRAGMA aux.schema_version = 30; + SELECT sql FROM aux.sqlite_master; + } + } {{CREATE TABLE t1(a,b)}} + do_test alter3-5.2 { + execsql { + ALTER TABLE aux.t1 ADD COLUMN c VARCHAR(128); + SELECT sql FROM aux.sqlite_master; + } + } {{CREATE TABLE t1(a,b, c VARCHAR(128))}} + do_test alter3-5.3 { + execsql { + SELECT * FROM aux.t1; + } + } {1 one {} 2 two {}} + ifcapable schema_version { + do_test alter3-5.4 { + execsql { + PRAGMA aux.schema_version; + } + } {31} + } + if {!$has_codec} { + do_test alter3-5.5 { + list [get_file_format test2.db] [get_file_format] + } {3 3} + } + do_test alter3-5.6 { + execsql { + ALTER TABLE aux.t1 ADD COLUMN d DEFAULT 1000; + SELECT sql FROM aux.sqlite_master; + } + } {{CREATE TABLE t1(a,b, c VARCHAR(128), d DEFAULT 1000)}} + do_test alter3-5.7 { + execsql { + SELECT * FROM aux.t1; + } + } {1 one {} 1000 2 two {} 1000} + ifcapable schema_version { + do_test alter3-5.8 { + execsql { + PRAGMA aux.schema_version; + } + } {32} + } + do_test alter3-5.9 { + execsql { + SELECT * FROM t1; + } + } {1 one 2 two} + do_test alter3-5.99 { + execsql { + DROP TABLE aux.t1; + DROP TABLE t1; + } + } {} +} + +#---------------------------------------------------------------- +# Test that the table schema is correctly reloaded when a column +# is added to a table. +# +ifcapable trigger&&tempdb { + do_test alter3-6.1 { + execsql { + CREATE TABLE t1(a, b); + CREATE TABLE log(trig, a, b); + + CREATE TRIGGER t1_a AFTER INSERT ON t1 BEGIN + INSERT INTO log VALUES('a', new.a, new.b); + END; + CREATE TEMP TRIGGER t1_b AFTER INSERT ON t1 BEGIN + INSERT INTO log VALUES('b', new.a, new.b); + END; + + INSERT INTO t1 VALUES(1, 2); + SELECT * FROM log; + } + } {b 1 2 a 1 2} + do_test alter3-6.2 { + execsql { + ALTER TABLE t1 ADD COLUMN c DEFAULT 'c'; + INSERT INTO t1(a, b) VALUES(3, 4); + SELECT * FROM log; + } + } {b 1 2 a 1 2 b 3 4 a 3 4} +} + +if {!$has_codec} { + ifcapable vacuum { + do_test alter3-7.1 { + execsql { + VACUUM; + } + get_file_format + } {1} + do_test alter3-7.2 { + execsql { + CREATE TABLE abc(a, b, c); + ALTER TABLE abc ADD d DEFAULT NULL; + } + get_file_format + } {3} + do_test alter3-7.3 { + execsql { + ALTER TABLE abc ADD e DEFAULT 10; + } + get_file_format + } {3} + do_test alter3-7.4 { + execsql { + ALTER TABLE abc ADD f DEFAULT NULL; + } + get_file_format + } {3} + do_test alter3-7.5 { + execsql { + VACUUM; + } + get_file_format + } {1} + } +} + +# Ticket #1183 - Make sure adding columns to large tables does not cause +# memory corruption (as was the case before this bug was fixed). +do_test alter3-8.1 { + execsql { + CREATE TABLE t4(c1); + } +} {} +set ::sql "" +do_test alter3-8.2 { + set cols c1 + for {set i 2} {$i < 100} {incr i} { + execsql " + ALTER TABLE t4 ADD c$i + " + lappend cols c$i + } + set ::sql "CREATE TABLE t4([join $cols {, }])" + list +} {} +do_test alter3-8.2 { + execsql { + SELECT sql FROM sqlite_master WHERE name = 't4'; + } +} [list $::sql] + +# 2021-07-20: Add support for detecting CHECK and NOT NULL constraint +# violations in ALTER TABLE ADD COLUMN +# +reset_db +do_execsql_test alter3-9.1 { + CREATE TABLE t1(a,b); + INSERT INTO t1 VALUES(1, 2), ('null!',NULL), (3,4); +} {} +do_catchsql_test alter3-9.2 { + ALTER TABLE t1 ADD COLUMN c CHECK(a!=1); +} {1 {CHECK constraint failed}} +do_catchsql_test alter3-9.3 { + ALTER TABLE t1 ADD COLUMN c CHECK(a!=3); +} {1 {CHECK constraint failed}} +do_catchsql_test alter3-9.4 { + ALTER TABLE t1 ADD COLUMN c CHECK(a!=2); +} {0 {}} +do_catchsql_test alter3-9.5 { + ALTER TABLE t1 ADD COLUMN d AS (b+1) NOT NULL; +} {1 {NOT NULL constraint failed}} +do_catchsql_test alter3-9.6 { + ALTER TABLE t1 ADD COLUMN d AS (b+1) NOT NULL CHECK(a!=1); +} {1 {CHECK constraint failed}} +do_catchsql_test alter3-9.7 { + ALTER TABLE t1 ADD COLUMN d AS (b+1) NOT NULL CHECK(a!=3); +} {1 {NOT NULL constraint failed}} + +do_execsql_test alter3-9.10 { + CREATE TEMP TABLE t0(m,n); + INSERT INTO t0 VALUES(1, 2), ('null!',NULL), (3,4); + ATTACH ':memory:' AS aux1; + CREATE TABLE aux1.t2(x,y); + INSERT INTO t2 VALUES(1, 2), ('null!',NULL), (3,4); +} {} +do_catchsql_test alter3-9.11 { + ALTER TABLE t0 ADD COLUMN xtra1 AS (n+1) NOT NULL CHECK(m!=1); +} {1 {CHECK constraint failed}} +do_catchsql_test alter3-9.12 { + ALTER TABLE t0 ADD COLUMN xtra1 AS (n+1) NOT NULL CHECK(m!=3); +} {1 {NOT NULL constraint failed}} +do_catchsql_test alter3-9.13 { + ALTER TABLE t2 ADD COLUMN xtra1 AS (y+1) NOT NULL CHECK(x!=1); +} {1 {CHECK constraint failed}} +do_catchsql_test alter3-9.14 { + ALTER TABLE t2 ADD COLUMN xtra1 AS (y+1) NOT NULL CHECK(x!=3); +} {1 {NOT NULL constraint failed}} + +finish_test diff --git a/test/alter4.test b/test/alter4.test new file mode 100644 index 0000000..c63ba6b --- /dev/null +++ b/test/alter4.test @@ -0,0 +1,427 @@ +# 2009 February 2 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing that SQLite can handle a subtle +# file format change that may be used in the future to implement +# "ALTER TABLE ... ADD COLUMN". +# +# $Id: alter4.test,v 1.1 2009/02/02 18:03:22 drh Exp $ +# + +set testdir [file dirname $argv0] + +source $testdir/tester.tcl + +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. +ifcapable !altertable { + finish_test + return +} + + +# Test Organisation: +# ------------------ +# +# alter4-1.*: Test that ALTER TABLE correctly modifies the CREATE TABLE sql. +# alter4-2.*: Test error messages. +# alter4-3.*: Test adding columns with default value NULL. +# alter4-4.*: Test adding columns with default values other than NULL. +# alter4-5.*: Test adding columns to tables in ATTACHed databases. +# alter4-6.*: Test that temp triggers are not accidentally dropped. +# alter4-7.*: Test that VACUUM resets the file-format. +# + +do_test alter4-1.1 { + execsql { + CREATE TEMP TABLE abc(a, b, c); + SELECT sql FROM sqlite_temp_master; + } +} {{CREATE TABLE abc(a, b, c)}} +do_test alter4-1.1b { + execsql { + SELECT sql FROM temp.sqlite_master; + } +} {{CREATE TABLE abc(a, b, c)}} +do_test alter4-1.2 { + execsql {ALTER TABLE abc ADD d INTEGER;} + execsql { + SELECT sql FROM sqlite_temp_master; + } +} {{CREATE TABLE abc(a, b, c, d INTEGER)}} +do_test alter4-1.2b { + execsql { + SELECT sql FROM temp.sqlite_master; + } +} {{CREATE TABLE abc(a, b, c, d INTEGER)}} +do_test alter4-1.3 { + execsql {ALTER TABLE abc ADD e} + execsql { + SELECT sql FROM sqlite_temp_master; + } +} {{CREATE TABLE abc(a, b, c, d INTEGER, e)}} +do_test alter4-1.3b { + execsql { + SELECT sql FROM temp.sqlite_master; + } +} {{CREATE TABLE abc(a, b, c, d INTEGER, e)}} +do_test alter4-1.4 { + execsql { + CREATE TABLE temp.t1(a, b); + ALTER TABLE t1 ADD c; + SELECT sql FROM sqlite_temp_master WHERE tbl_name = 't1'; + } +} {{CREATE TABLE t1(a, b, c)}} +do_test alter4-1.4b { + execsql { + SELECT sql FROM temp.sqlite_master WHERE tbl_name = 't1'; + } +} {{CREATE TABLE t1(a, b, c)}} +do_test alter4-1.5 { + execsql { + ALTER TABLE t1 ADD d CHECK (a>d); + SELECT sql FROM sqlite_temp_master WHERE tbl_name = 't1'; + } +} {{CREATE TABLE t1(a, b, c, d CHECK (a>d))}} +ifcapable foreignkey { + do_test alter4-1.6 { + execsql { + CREATE TEMP TABLE t2(a, b, UNIQUE(a, b)); + ALTER TABLE t2 ADD c REFERENCES t1(c) ; + SELECT sql FROM sqlite_temp_master + WHERE tbl_name = 't2' AND type = 'table'; + } + } {{CREATE TABLE t2(a, b, c REFERENCES t1(c), UNIQUE(a, b))}} +} +do_test alter4-1.7 { + execsql { + CREATE TEMPORARY TABLE t3(a, b, UNIQUE(a, b)); + ALTER TABLE t3 ADD COLUMN c VARCHAR(10, 20); + SELECT sql FROM sqlite_temp_master + WHERE tbl_name = 't3' AND type = 'table'; + } +} {{CREATE TABLE t3(a, b, c VARCHAR(10, 20), UNIQUE(a, b))}} +do_test alter4-1.99 { + catchsql { + # May not exist if foriegn-keys are omitted at compile time. + DROP TABLE t2; + } + execsql { + DROP TABLE abc; + DROP TABLE t1; + DROP TABLE t3; + } +} {} + +do_test alter4-2.1 { + execsql { + CREATE TABLE temp.t1(a, b); + INSERT INTO t1 VALUES(1,2); + } + catchsql { + ALTER TABLE t1 ADD c PRIMARY KEY; + } +} {1 {Cannot add a PRIMARY KEY column}} +do_test alter4-2.2 { + catchsql { + ALTER TABLE t1 ADD c UNIQUE + } +} {1 {Cannot add a UNIQUE column}} +do_test alter4-2.3 { + catchsql { + ALTER TABLE t1 ADD b VARCHAR(10) + } +} {1 {duplicate column name: b}} +do_test alter4-2.3 { + catchsql { + ALTER TABLE t1 ADD c NOT NULL; + } +} {1 {Cannot add a NOT NULL column with default value NULL}} +do_test alter4-2.4 { + catchsql { + ALTER TABLE t1 ADD c NOT NULL DEFAULT 10; + } +} {0 {}} +ifcapable view { + do_test alter4-2.5 { + execsql { + CREATE TEMPORARY VIEW v1 AS SELECT * FROM t1; + } + catchsql { + alter table v1 add column d; + } + } {1 {Cannot add a column to a view}} +} +do_test alter4-2.6 { + catchsql { + alter table t1 add column d DEFAULT CURRENT_TIME; + } +} {1 {Cannot add a column with non-constant default}} +do_test alter4-2.7 { + catchsql { + alter table t1 add column d default (-5+1); + } +} {1 {Cannot add a column with non-constant default}} +do_test alter4-2.99 { + execsql { + DROP TABLE t1; + } +} {} + +do_test alter4-3.1 { + execsql { + CREATE TEMP TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 100); + INSERT INTO t1 VALUES(2, 300); + SELECT * FROM t1; + } +} {1 100 2 300} +do_test alter4-3.1 { + execsql { + PRAGMA schema_version = 10; + } +} {} +do_test alter4-3.2 { + execsql { + ALTER TABLE t1 ADD c; + SELECT * FROM t1; + } +} {1 100 {} 2 300 {}} +ifcapable schema_version { + do_test alter4-3.4 { + execsql { + PRAGMA schema_version; + } + } {10} +} + +do_test alter4-4.1 { + db close + forcedelete test.db + set ::DB [sqlite3 db test.db] + execsql { + CREATE TEMP TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 100); + INSERT INTO t1 VALUES(2, 300); + SELECT * FROM t1; + } +} {1 100 2 300} +do_test alter4-4.1 { + execsql { + PRAGMA schema_version = 20; + } +} {} +do_test alter4-4.2 { + execsql { + ALTER TABLE t1 ADD c DEFAULT 'hello world'; + SELECT * FROM t1; + } +} {1 100 {hello world} 2 300 {hello world}} +ifcapable schema_version { + do_test alter4-4.4 { + execsql { + PRAGMA schema_version; + } + } {20} +} +do_test alter4-4.99 { + execsql { + DROP TABLE t1; + } +} {} + +ifcapable attach { + do_test alter4-5.1 { + forcedelete test2.db + forcedelete test2.db-journal + execsql { + CREATE TEMP TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 'one'); + INSERT INTO t1 VALUES(2, 'two'); + ATTACH 'test2.db' AS aux; + CREATE TABLE aux.t1 AS SELECT * FROM t1; + PRAGMA aux.schema_version = 30; + SELECT sql FROM aux.sqlite_master; + } + } {{CREATE TABLE t1(a,b)}} + do_test alter4-5.2 { + execsql { + ALTER TABLE aux.t1 ADD COLUMN c VARCHAR(128); + SELECT sql FROM aux.sqlite_master; + } + } {{CREATE TABLE t1(a,b, c VARCHAR(128))}} + do_test alter4-5.3 { + execsql { + SELECT * FROM aux.t1; + } + } {1 one {} 2 two {}} + ifcapable schema_version { + do_test alter4-5.4 { + execsql { + PRAGMA aux.schema_version; + } + } {31} + } + do_test alter4-5.6 { + execsql { + ALTER TABLE aux.t1 ADD COLUMN d DEFAULT 1000; + SELECT sql FROM aux.sqlite_master; + } + } {{CREATE TABLE t1(a,b, c VARCHAR(128), d DEFAULT 1000)}} + do_test alter4-5.7 { + execsql { + SELECT * FROM aux.t1; + } + } {1 one {} 1000 2 two {} 1000} + ifcapable schema_version { + do_test alter4-5.8 { + execsql { + PRAGMA aux.schema_version; + } + } {32} + } + do_test alter4-5.9 { + execsql { + SELECT * FROM t1; + } + } {1 one 2 two} + do_test alter4-5.99 { + execsql { + DROP TABLE aux.t1; + DROP TABLE t1; + } + } {} +} + +#---------------------------------------------------------------- +# Test that the table schema is correctly reloaded when a column +# is added to a table. +# +ifcapable trigger&&tempdb { + do_test alter4-6.1 { + execsql { + CREATE TEMP TABLE t1(a, b); + CREATE TEMP TABLE log(trig, a, b); + + CREATE TRIGGER t1_a AFTER INSERT ON t1 BEGIN + INSERT INTO log VALUES('a', new.a, new.b); + END; + CREATE TEMP TRIGGER t1_b AFTER INSERT ON t1 BEGIN + INSERT INTO log VALUES('b', new.a, new.b); + END; + + INSERT INTO t1 VALUES(1, 2); + SELECT * FROM log ORDER BY trig, a, b; + } + } {a 1 2 b 1 2} + do_test alter4-6.2 { + execsql { + ALTER TABLE t1 ADD COLUMN c DEFAULT 'c'; + INSERT INTO t1(a, b) VALUES(3, 4); + SELECT * FROM log ORDER BY trig, a, b; + } + } {a 1 2 a 3 4 b 1 2 b 3 4} +} + +# Ticket #1183 - Make sure adding columns to large tables does not cause +# memory corruption (as was the case before this bug was fixed). +do_test alter4-8.1 { + execsql { + CREATE TEMP TABLE t4(c1); + } +} {} +set ::sql "" +do_test alter4-8.2 { + set cols c1 + for {set i 2} {$i < 100} {incr i} { + execsql " + ALTER TABLE t4 ADD c$i + " + lappend cols c$i + } + set ::sql "CREATE TABLE t4([join $cols {, }])" + list +} {} +do_test alter4-8.2 { + execsql { + SELECT sql FROM sqlite_temp_master WHERE name = 't4'; + } +} [list $::sql] + + +# Test that a default value equal to -1 multipied by the smallest possible +# 64-bit integer is correctly converted to a real. +do_execsql_test alter4-9.1 { + CREATE TABLE t5( + a INTEGER DEFAULT -9223372036854775808, + b INTEGER DEFAULT (-(-9223372036854775808)) + ); + INSERT INTO t5 DEFAULT VALUES; +} + +do_execsql_test alter4-9.2 { SELECT typeof(a), a, typeof(b), b FROM t5; } { + integer -9223372036854775808 + real 9.22337203685478e+18 +} + +do_execsql_test alter4-9.3 { + ALTER TABLE t5 ADD COLUMN c INTEGER DEFAULT (-(-9223372036854775808)); + SELECT typeof(c), c FROM t5; +} {real 9.22337203685478e+18} + +# Confirm that doing an ALTER TABLE on a legacy format database +# does not corrupt DESC indexes. +# +# Ticket https://www.sqlite.org/src/tktview/f68bf68513a1c +# +do_test alter4-10.1 { + db close + sqlite3 db :memory: + sqlite3_db_config db LEGACY_FILE_FORMAT 1 + db eval { + CREATE TABLE t1(a,b,c); + CREATE INDEX t1a ON t1(a DESC); + INSERT INTO t1 VALUES(1,2,3); + INSERT INTO t1 VALUES(2,3,4); + ALTER TABLE t1 ADD COLUMN d; + PRAGMA integrity_check; + } +} {ok} + +reset_db +do_execsql_test alter4-11.0 { + CREATE TABLE t1(c INTEGER PRIMARY KEY, d); + INSERT INTO t1(c,d) VALUES(1,2); + PRAGMA foreign_keys = on; + ALTER TABLE t1 ADD COLUMN e; +} + +do_execsql_test alter4-11.1 { + ALTER TABLE t1 ADD COLUMN f REFERENCES t1; +} + +do_catchsql_test alter4-11.2 { + ALTER TABLE t1 ADD COLUMN g REFERENCES t1 DEFAULT 4; +} {1 {Cannot add a REFERENCES column with non-NULL default value}} + +do_catchsql_test alter4-11.3 { + ALTER TABLE t2 ADD COLUMN g; +} {1 {no such table: t2}} + +ifcapable fts5 { + do_execsql_test alter4-11.4 { + CREATE VIRTUAL TABLE fff USING fts5(f); + } + do_catchsql_test alter4-11.2 { + ALTER TABLE fff ADD COLUMN g; + } {1 {virtual tables may not be altered}} +} + +finish_test diff --git a/test/alterauth.test b/test/alterauth.test new file mode 100644 index 0000000..12645b3 --- /dev/null +++ b/test/alterauth.test @@ -0,0 +1,72 @@ +# 2018 September 2 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# + +set testdir [file dirname $argv0] + +source $testdir/tester.tcl + +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. +ifcapable !altertable { + finish_test + return +} +set testprefix alterauth + +set ::auth [list] +proc xAuth {type args} { + if {$type == "SQLITE_ALTER_TABLE"} { + lappend ::auth [concat $type [lrange $args 0 3]] + } + return SQLITE_OK +} +db auth xAuth + +do_execsql_test 1.0 { CREATE TABLE t1(a, b, c); } + +do_test 1.1 { + set ::auth [list] + execsql { ALTER TABLE t1 RENAME TO t2 } + set ::auth +} {{SQLITE_ALTER_TABLE main t1 {} {}}} + +do_test 1.2 { + set ::auth [list] + execsql { ALTER TABLE t2 RENAME c TO ccc } + set ::auth +} {{SQLITE_ALTER_TABLE main t2 {} {}}} + +do_test 1.3 { + set ::auth [list] + execsql { ALTER TABLE t2 ADD COLUMN d } + set ::auth +} {{SQLITE_ALTER_TABLE main t2 {} {}}} + +proc xAuth {type args} { + if {$type == "SQLITE_ALTER_TABLE"} { + return SQLITE_DENY + } + return SQLITE_OK +} + +do_test 2.1 { + catchsql { ALTER TABLE t2 RENAME TO t3 } +} {1 {not authorized}} + +do_test 2.2 { + catchsql { ALTER TABLE t2 RENAME d TO ddd } +} {1 {not authorized}} + +do_test 2.3 { + catchsql { ALTER TABLE t2 ADD COLUMN e } +} {1 {not authorized}} + +finish_test diff --git a/test/alterauth2.test b/test/alterauth2.test new file mode 100644 index 0000000..6f9242d --- /dev/null +++ b/test/alterauth2.test @@ -0,0 +1,119 @@ +# 2018 October 6 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# + +set testdir [file dirname $argv0] + +source $testdir/tester.tcl + +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. +ifcapable !altertable { + finish_test + return +} +set testprefix alterauth2 + +set ::auth [list] +proc xAuth {type args} { + lappend ::auth [concat $type [lrange $args 0 3]] + if {$type=="SQLITE_READ" && [lindex $args 0] == "t2"} breakpoint + return SQLITE_OK +} +db auth xAuth + +proc do_auth_test {tn sql authcode} { + set script " + set ::auth \[list\] + execsql {$sql} + lsort -unique \[set ::auth\] + " + + set normal [list {*}$authcode] + uplevel [list do_test $tn $script $normal] +} + +do_execsql_test 1.0 { + CREATE TABLE t1(a, b, c); + CREATE VIEW v1 AS SELECT * FROM t1; + CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN + DELETE FROM t1 WHERE a0} + {{CREATE TABLE t1(a, d, c)} {CREATE INDEX t1i ON t1(d+d+d+d, c) WHERE d>0}} + + 13 {CREATE TABLE t1(a, b, c, FOREIGN KEY (b) REFERENCES t2)} + {CREATE TABLE t1(a, d, c, FOREIGN KEY (d) REFERENCES t2)} + + 14 {CREATE TABLE t1(a INTEGER, b TEXT, c BLOB, PRIMARY KEY(b))} + {CREATE TABLE t1(a INTEGER, d TEXT, c BLOB, PRIMARY KEY(d))} + + 15 {CREATE TABLE t1(a INTEGER, b INTEGER, c BLOB, PRIMARY KEY(b))} + {CREATE TABLE t1(a INTEGER, d INTEGER, c BLOB, PRIMARY KEY(d))} + + 16 {CREATE TABLE t1(a INTEGER, b INTEGER PRIMARY KEY, c BLOB)} + {CREATE TABLE t1(a INTEGER, d INTEGER PRIMARY KEY, c BLOB)} + + 17 {CREATE TABLE t1(a INTEGER, b INTEGER PRIMARY KEY, c BLOB, FOREIGN KEY (b) REFERENCES t2)} + {CREATE TABLE t1(a INTEGER, d INTEGER PRIMARY KEY, c BLOB, FOREIGN KEY (d) REFERENCES t2)} + +} { + reset_db + do_execsql_test 1.$tn.0 $before + + do_execsql_test 1.$tn.1 { + INSERT INTO t1 VALUES(1, 2, 3); + } + + do_execsql_test 1.$tn.2 { + ALTER TABLE t1 RENAME COLUMN b TO d; + } + + do_execsql_test 1.$tn.3 { + SELECT * FROM t1; + } {1 2 3} + + if {[string first INDEX $before]>0} { + set res $after + } else { + set res [list $after] + } + do_execsql_test 1.$tn.4 { + SELECT sql FROM sqlite_master WHERE tbl_name='t1' AND sql!='' + } $res +} + +#------------------------------------------------------------------------- +# +do_execsql_test 2.0 { + CREATE TABLE t3(a, b, c, d, e, f, g, h, i, j, k, l, m, FOREIGN KEY (b, c, d, e, f, g, h, i, j, k, l, m) REFERENCES t4); +} + +sqlite3 db2 test.db +do_execsql_test -db db2 2.1 { SELECT b FROM t3 } + +do_execsql_test 2.2 { + ALTER TABLE t3 RENAME b TO biglongname; + SELECT sql FROM sqlite_master WHERE name='t3'; +} {{CREATE TABLE t3(a, biglongname, c, d, e, f, g, h, i, j, k, l, m, FOREIGN KEY (biglongname, c, d, e, f, g, h, i, j, k, l, m) REFERENCES t4)}} + +do_execsql_test -db db2 2.3 { SELECT biglongname FROM t3 } + +#------------------------------------------------------------------------- +# +do_execsql_test 3.0 { + CREATE TABLE t4(x, y, z); + CREATE TRIGGER ttt AFTER INSERT ON t4 WHEN new.y<0 BEGIN + SELECT x, y, z FROM t4; + DELETE FROM t4 WHERE y=32; + UPDATE t4 SET x=y+1, y=0 WHERE y=32; + INSERT INTO t4(x, y, z) SELECT 4, 5, 6 WHERE 0; + END; + INSERT INTO t4 VALUES(3, 2, 1); +} + +do_execsql_test 3.1 { + ALTER TABLE t4 RENAME y TO abc; + SELECT sql FROM sqlite_master WHERE name='t4'; +} {{CREATE TABLE t4(x, abc, z)}} + +do_execsql_test 3.2 { + SELECT * FROM t4; +} {3 2 1} + +do_execsql_test 3.3 { INSERT INTO t4 VALUES(6, 5, 4); } {} + +do_execsql_test 3.4 { SELECT sql FROM sqlite_master WHERE type='trigger' } { +{CREATE TRIGGER ttt AFTER INSERT ON t4 WHEN new.abc<0 BEGIN + SELECT x, abc, z FROM t4; + DELETE FROM t4 WHERE abc=32; + UPDATE t4 SET x=abc+1, abc=0 WHERE abc=32; + INSERT INTO t4(x, abc, z) SELECT 4, 5, 6 WHERE 0; + END} +} + +#------------------------------------------------------------------------- +# +do_execsql_test 4.0 { + CREATE TABLE c1(a, b, FOREIGN KEY (a, b) REFERENCES p1(c, d)); + CREATE TABLE p1(c, d, PRIMARY KEY(c, d)); + PRAGMA foreign_keys = 1; + INSERT INTO p1 VALUES(1, 2); + INSERT INTO p1 VALUES(3, 4); +} + +do_execsql_test 4.1 { + ALTER TABLE p1 RENAME d TO "silly name"; + SELECT sql FROM sqlite_master WHERE name IN ('c1', 'p1'); +} { + {CREATE TABLE c1(a, b, FOREIGN KEY (a, b) REFERENCES p1(c, "silly name"))} + {CREATE TABLE p1(c, "silly name", PRIMARY KEY(c, "silly name"))} +} + +do_execsql_test 4.2 { INSERT INTO c1 VALUES(1, 2); } + +do_execsql_test 4.3 { + CREATE TABLE c2(a, b, FOREIGN KEY (a, b) REFERENCES p1); +} + +do_execsql_test 4.4 { + ALTER TABLE p1 RENAME "silly name" TO reasonable; + SELECT sql FROM sqlite_master WHERE name IN ('c1', 'c2', 'p1'); +} { + {CREATE TABLE c1(a, b, FOREIGN KEY (a, b) REFERENCES p1(c, "reasonable"))} + {CREATE TABLE p1(c, "reasonable", PRIMARY KEY(c, "reasonable"))} + {CREATE TABLE c2(a, b, FOREIGN KEY (a, b) REFERENCES p1)} +} + +#------------------------------------------------------------------------- + +do_execsql_test 5.0 { + CREATE TABLE t5(a, b, c); + CREATE INDEX t5a ON t5(a); + INSERT INTO t5 VALUES(1, 2, 3), (4, 5, 6); + ANALYZE; +} + +do_execsql_test 5.1 { + ALTER TABLE t5 RENAME b TO big; + SELECT big FROM t5; +} {2 5} + +do_catchsql_test 6.1 { + ALTER TABLE sqlite_stat1 RENAME tbl TO thetable; +} {1 {table sqlite_stat1 may not be altered}} + +#------------------------------------------------------------------------- +# +do_execsql_test 6.0 { + CREATE TABLE blob( + rid INTEGER PRIMARY KEY, + rcvid INTEGER, + size INTEGER, + uuid TEXT UNIQUE NOT NULL, + content BLOB, + CHECK( length(uuid)>=40 AND rid>0 ) + ); +} + +do_execsql_test 6.1 { + ALTER TABLE "blob" RENAME COLUMN "rid" TO "a1"; +} + +do_catchsql_test 6.2 { + ALTER TABLE "blob" RENAME COLUMN "a1" TO [where]; +} {0 {}} + +do_execsql_test 6.3 { + SELECT "where" FROM blob; +} {} + +#------------------------------------------------------------------------- +# Triggers. +# +db close +db2 close +reset_db +do_execsql_test 7.0 { + CREATE TABLE c(x); + INSERT INTO c VALUES(0); + CREATE TABLE t6("col a", "col b", "col c"); + CREATE TRIGGER zzz AFTER UPDATE OF "col a", "col c" ON t6 BEGIN + UPDATE c SET x=x+1; + END; +} + +do_execsql_test 7.1.1 { + INSERT INTO t6 VALUES(0, 0, 0); + UPDATE t6 SET "col c" = 1; + SELECT * FROM c; +} {1} + +do_execsql_test 7.1.2 { + ALTER TABLE t6 RENAME "col c" TO "col 3"; +} + +do_execsql_test 7.1.3 { + UPDATE t6 SET "col 3" = 0; + SELECT * FROM c; +} {2} + +#------------------------------------------------------------------------- +# Views. +# +reset_db +do_execsql_test 8.0 { + CREATE TABLE a1(x INTEGER, y TEXT, z BLOB, PRIMARY KEY(x)); + CREATE TABLE a2(a, b, c); + CREATE VIEW v1 AS SELECT x, y, z FROM a1; +} + +do_execsql_test 8.1 { + ALTER TABLE a1 RENAME y TO yyy; + SELECT sql FROM sqlite_master WHERE type='view'; +} {{CREATE VIEW v1 AS SELECT x, yyy, z FROM a1}} + +do_execsql_test 8.2.1 { + DROP VIEW v1; + CREATE VIEW v2 AS SELECT x, x+x, a, a+a FROM a1, a2; +} {} +do_execsql_test 8.2.2 { + ALTER TABLE a1 RENAME x TO xxx; +} +do_execsql_test 8.2.3 { + SELECT sql FROM sqlite_master WHERE type='view'; +} {{CREATE VIEW v2 AS SELECT xxx, xxx+xxx, a, a+a FROM a1, a2}} + +do_execsql_test 8.3.1 { + DROP TABLE a2; + DROP VIEW v2; + CREATE TABLE a2(a INTEGER PRIMARY KEY, b, c); + CREATE VIEW v2 AS SELECT xxx, xxx+xxx, a, a+a FROM a1, a2; +} {} +do_execsql_test 8.3.2 { + ALTER TABLE a1 RENAME xxx TO x; +} +do_execsql_test 8.3.3 { + SELECT sql FROM sqlite_master WHERE type='view'; +} {{CREATE VIEW v2 AS SELECT x, x+x, a, a+a FROM a1, a2}} + +do_execsql_test 8.4.0 { + CREATE TABLE b1(a, b, c); + CREATE TABLE b2(x, y, z); +} + +do_execsql_test 8.4.1 { + CREATE VIEW vvv AS SELECT c+c || coalesce(c, c) FROM b1, b2 WHERE x=c GROUP BY c HAVING c>0; + ALTER TABLE b1 RENAME c TO "a;b"; + SELECT sql FROM sqlite_master WHERE name='vvv'; +} {{CREATE VIEW vvv AS SELECT "a;b"+"a;b" || coalesce("a;b", "a;b") FROM b1, b2 WHERE x="a;b" GROUP BY "a;b" HAVING "a;b">0}} + +do_execsql_test 8.4.2 { + CREATE VIEW www AS SELECT b FROM b1 UNION ALL SELECT y FROM b2; + ALTER TABLE b1 RENAME b TO bbb; + SELECT sql FROM sqlite_master WHERE name='www'; +} {{CREATE VIEW www AS SELECT bbb FROM b1 UNION ALL SELECT y FROM b2}} + +db collate nocase {string compare} + +do_execsql_test 8.4.3 { + CREATE VIEW xxx AS SELECT a FROM b1 UNION SELECT x FROM b2 ORDER BY 1 COLLATE nocase; +} + +do_execsql_test 8.4.4 { + ALTER TABLE b2 RENAME x TO hello; + SELECT sql FROM sqlite_master WHERE name='xxx'; +} {{CREATE VIEW xxx AS SELECT a FROM b1 UNION SELECT hello FROM b2 ORDER BY 1 COLLATE nocase}} + +do_catchsql_test 8.4.5 { + CREATE VIEW zzz AS SELECT george, ringo FROM b1; + ALTER TABLE b1 RENAME a TO aaa; +} {1 {error in view zzz: no such column: george}} + +do_execsql_test 8.5 { + DROP VIEW zzz; + CREATE TABLE t5(a TEXT, b INT); + INSERT INTO t5(a,b) VALUES('aaa',7),('bbb',3),('ccc',4); + CREATE VIEW vt5(x) AS SELECT group_concat(a ORDER BY b) FROM t5; + SELECT x FROM vt5; +} {bbb,ccc,aaa} +do_execsql_test 8.5.1 { + ALTER TABLE t5 RENAME COLUMN b TO bbb; + SELECT sql FROM sqlite_schema WHERE name='vt5'; +} {{CREATE VIEW vt5(x) AS SELECT group_concat(a ORDER BY bbb) FROM t5}} +do_execsql_test 8.5.2 { + SELECT x FROM vt5; +} {bbb,ccc,aaa} + +#------------------------------------------------------------------------- +# More triggers. +# +proc do_rename_column_test {tn old new lSchema} { + for {set i 0} {$i < 2} {incr i} { + drop_all_tables_and_views db + + set lSorted [list] + foreach sql $lSchema { + execsql $sql + lappend lSorted [string trim $sql] + } + set lSorted [lsort $lSorted] + + do_execsql_test $tn.$i.1 { + SELECT sql FROM sqlite_master WHERE sql!='' ORDER BY 1 + } $lSorted + + if {$i==1} { + db close + sqlite3 db test.db + } + + do_execsql_test $tn.$i.2 "ALTER TABLE t1 RENAME $old TO $new" + + do_execsql_test $tn.$i.3 { + SELECT sql FROM sqlite_master ORDER BY 1 + } [string map [list $old $new] $lSorted] + } +} + +foreach {tn old new lSchema} { + 1 _x_ _xxx_ { + { CREATE TABLE t1(a, b, _x_) } + { CREATE TRIGGER AFTER INSERT ON t1 BEGIN + SELECT _x_ FROM t1; + END } + } + + 2 _x_ _xxx_ { + { CREATE TABLE t1(a, b, _x_) } + { CREATE TABLE t2(c, d, e) } + { CREATE TRIGGER ttt AFTER INSERT ON t2 BEGIN + SELECT _x_ FROM t1; + END } + } + + 3 _x_ _xxx_ { + { CREATE TABLE t1(a, b, _x_ INTEGER, PRIMARY KEY(_x_), CHECK(_x_>0)) } + { CREATE TABLE t2(c, d, e) } + { CREATE TRIGGER ttt AFTER UPDATE ON t1 BEGIN + INSERT INTO t2 VALUES(new.a, new.b, new._x_); + END } + } + + 4 _x_ _xxx_ { + { CREATE TABLE t1(a, b, _x_ INTEGER, PRIMARY KEY(_x_), CHECK(_x_>0)) } + { CREATE TRIGGER ttt AFTER UPDATE ON t1 BEGIN + INSERT INTO t1 VALUES(new.a, new.b, new._x_) + ON CONFLICT (_x_) WHERE _x_>10 DO UPDATE SET _x_ = _x_+1; + END } + } + + 4 _x_ _xxx_ { + { CREATE TABLE t1(a, b, _x_ INTEGER, PRIMARY KEY(_x_), CHECK(_x_>0)) } + { CREATE TRIGGER ttt AFTER UPDATE ON t1 BEGIN + INSERT INTO t1 VALUES(new.a, new.b, new._x_) + ON CONFLICT (_x_) WHERE _x_>10 DO NOTHING; + END } + } +} { + do_rename_column_test 9.$tn $old $new $lSchema +} + +#------------------------------------------------------------------------- +# Test that views can be edited even if there are missing collation +# sequences or user defined functions. +# +reset_db + +ifcapable vtab { + foreach {tn old new lSchema} { + 1 _x_ _xxx_ { + { CREATE TABLE t1(a, b, _x_) } + { CREATE VIEW s1 AS SELECT a, b, _x_ FROM t1 WHERE _x_='abc' COLLATE xyz } + } + + 2 _x_ _xxx_ { + { CREATE TABLE t1(a, b, _x_) } + { CREATE VIEW v1 AS SELECT a, b, _x_ FROM t1 WHERE scalar(_x_) } + } + + 3 _x_ _xxx_ { + { CREATE TABLE t1(a, b, _x_) } + { CREATE VIEW v1 AS SELECT a, b, _x_ FROM t1 WHERE _x_ = unicode(1, 2, 3) } + } + + 4 _x_ _xxx_ { + { CREATE TABLE t1(a, b, _x_) } + { CREATE VIRTUAL TABLE e1 USING echo(t1) } + } + } { + register_echo_module db + do_rename_column_test 10.$tn $old $new $lSchema + } + + #-------------------------------------------------------------------------- + # Test that if a view or trigger refers to a virtual table for which the + # module is not available, RENAME COLUMN cannot proceed. + # + reset_db + register_echo_module db + do_execsql_test 11.0 { + CREATE TABLE x1(a, b, c); + CREATE VIRTUAL TABLE e1 USING echo(x1); + } + db close + sqlite3 db test.db + + do_execsql_test 11.1 { + ALTER TABLE x1 RENAME b TO bbb; + SELECT sql FROM sqlite_master; + } { {CREATE TABLE x1(a, bbb, c)} {CREATE VIRTUAL TABLE e1 USING echo(x1)} } + + do_execsql_test 11.2 { + CREATE VIEW v1 AS SELECT e1.*, x1.c FROM e1, x1; + } + + do_catchsql_test 11.3 { + ALTER TABLE x1 RENAME c TO ccc; + } {1 {error in view v1: no such module: echo}} +} + +#------------------------------------------------------------------------- +# Test some error conditions: +# +# 1. Renaming a column of a system table, +# 2. Renaming a column of a VIEW, +# 3. Renaming a column of a virtual table. +# 4. Renaming a column that does not exist. +# 5. Renaming a column of a table that does not exist. +# +reset_db +do_execsql_test 12.1.1 { + CREATE TABLE t1(a, b); + CREATE INDEX t1a ON t1(a); + INSERT INTO t1 VALUES(1, 1), (2, 2), (3, 4); + ANALYZE; +} +do_catchsql_test 12.1.2 { + ALTER TABLE sqlite_stat1 RENAME idx TO theindex; +} {1 {table sqlite_stat1 may not be altered}} +do_execsql_test 12.1.3 { + SELECT sql FROM sqlite_master WHERE tbl_name = 'sqlite_stat1' +} {{CREATE TABLE sqlite_stat1(tbl,idx,stat)}} + +do_execsql_test 12.2.1 { + CREATE VIEW v1 AS SELECT * FROM t1; + CREATE VIEW v2(c, d) AS SELECT * FROM t1; +} +do_catchsql_test 12.2.2 { + ALTER TABLE v1 RENAME a TO z; +} {1 {cannot rename columns of view "v1"}} +do_catchsql_test 12.2.3 { + ALTER TABLE v2 RENAME c TO y; +} {1 {cannot rename columns of view "v2"}} + +ifcapable fts5 { + do_execsql_test 12.3.1 { + CREATE VIRTUAL TABLE ft USING fts5(a, b, c); + } + do_catchsql_test 12.3.2 { + ALTER TABLE ft RENAME a TO z; + } {1 {cannot rename columns of virtual table "ft"}} +} + +do_execsql_test 12.4.1 { + CREATE TABLE t2(x, y, z); +} +do_catchsql_test 12.4.2 { + ALTER TABLE t2 RENAME COLUMN a TO b; +} {1 {no such column: "a"}} + +do_catchsql_test 12.5.1 { + ALTER TABLE t3 RENAME COLUMN a TO b; +} {1 {no such table: t3}} + +#------------------------------------------------------------------------- +# Test the effect of some parse/resolve errors. +# +reset_db +do_execsql_test 13.1.1 { + CREATE TABLE x1(i INTEGER, t TEXT UNIQUE); + CREATE TRIGGER tr1 AFTER INSERT ON x1 BEGIN + SELECT * FROM nosuchtable; + END; +} + +do_catchsql_test 13.1.2 { + ALTER TABLE x1 RENAME COLUMN t TO ttt; +} {1 {error in trigger tr1: no such table: main.nosuchtable}} + +do_execsql_test 13.1.3 { + DROP TRIGGER tr1; + CREATE INDEX x1i ON x1(i); + SELECT sql FROM sqlite_master WHERE name='x1i'; +} {{CREATE INDEX x1i ON x1(i)}} + +sqlite3_db_config db DEFENSIVE 0 +do_execsql_test 13.1.4 { + PRAGMA writable_schema = ON; + UPDATE sqlite_master SET sql = 'CREATE INDEX x1i ON x1(j)' WHERE name='x1i'; + PRAGMA writable_schema = OFF; +} {} + +do_catchsql_test 13.1.5 { + ALTER TABLE x1 RENAME COLUMN t TO ttt; +} {1 {error in index x1i: no such column: j}} + +do_execsql_test 13.1.6 { + PRAGMA writable_schema = ON; + UPDATE sqlite_master SET sql = '' WHERE name='x1i'; + PRAGMA writable_schema = OFF; +} {} + +do_catchsql_test 13.1.7 { + ALTER TABLE x1 RENAME COLUMN t TO ttt; +} {1 {error in index x1i: }} + +do_execsql_test 13.1.8 { + PRAGMA writable_schema = ON; + DELETE FROM sqlite_master WHERE name = 'x1i'; + PRAGMA writable_schema = OFF; +} + +do_execsql_test 13.2.0 { + CREATE TABLE data(x UNIQUE, y, z); +} +foreach {tn trigger error} { + 1 { + CREATE TRIGGER tr1 AFTER INSERT ON x1 BEGIN + UPDATE data SET x=x+1 WHERE zzz=new.i; + END; + } {no such column: zzz} + + 2 { + CREATE TRIGGER tr1 AFTER INSERT ON x1 BEGIN + INSERT INTO data(x, y) VALUES(new.i, new.t, 1) + ON CONFLICT (x) DO UPDATE SET z=zz+1; + END; + } {no such column: zz} + + 3 { + CREATE TRIGGER tr1 AFTER INSERT ON x1 BEGIN + INSERT INTO x1(i, t) VALUES(new.i+1, new.t||'1') + ON CONFLICT (tttttt) DO UPDATE SET t=i+1; + END; + } {no such column: tttttt} + + 4 { + CREATE TRIGGER tr1 AFTER INSERT ON x1 BEGIN + INSERT INTO nosuchtable VALUES(new.i, new.t); + END; + } {no such table: main.nosuchtable} +} { + do_execsql_test 13.2.$tn.1 " + DROP TRIGGER IF EXISTS tr1; + $trigger + " + + do_catchsql_test 13.2.$tn.2 { + ALTER TABLE x1 RENAME COLUMN t TO ttt; + } "1 {error in trigger tr1: $error}" +} + +#------------------------------------------------------------------------- +# Passing invalid parameters directly to sqlite_rename_column(). +# +sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db +do_execsql_test 14.1 { + CREATE TABLE ddd(sql, type, object, db, tbl, icol, znew, bquote); + INSERT INTO ddd VALUES( + 'CREATE TABLE x1(i INTEGER, t TEXT)', + 'table', 'x1', 'main', 'x1', -1, 'zzz', 0 + ), ( + 'CREATE TABLE x1(i INTEGER, t TEXT)', + 'table', 'x1', 'main', 'x1', 2, 'zzz', 0 + ), ( + 'CREATE TABLE x1(i INTEGER, t TEXT)', + 'table', 'x1', 'main', 'notable', 0, 'zzz', 0 + ), ( + 'CREATE TABLE x1(i INTEGER, t TEXT)', + 'table', 'x1', 'main', 'ddd', -1, 'zzz', 0 + ); +} {} + +do_execsql_test 14.2 { + SELECT + sqlite_rename_column(sql, type, object, db, tbl, icol, znew, bquote, 0) + FROM ddd; +} {{} {} {} {}} +sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db + +# If the INTERNAL_FUNCTIONS test-control is disabled (which is the default) +# then the sqlite_rename_table() SQL function is not accessible to +# ordinary SQL. +# +do_catchsql_test 14.3 { + SELECT sqlite_rename_column(0,0,0,0,0,0,0,0,0); +} {1 {no such function: sqlite_rename_column}} + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 15.0 { + CREATE TABLE xxx(a, b, c); + SELECT a AS d FROM xxx WHERE d=0; +} + +do_execsql_test 15.1 { + CREATE VIEW vvv AS SELECT a AS d FROM xxx WHERE d=0; + ALTER TABLE xxx RENAME a TO xyz; +} + +do_execsql_test 15.2 { + SELECT sql FROM sqlite_master WHERE type='view'; +} {{CREATE VIEW vvv AS SELECT xyz AS d FROM xxx WHERE d=0}} + +#------------------------------------------------------------------------- +# +do_execsql_test 16.1.0 { + CREATE TABLE t1(a,b,c); + CREATE TABLE t2(d,e,f); + INSERT INTO t1 VALUES(1,2,3); + INSERT INTO t2 VALUES(4,5,6); + CREATE VIEW v4 AS SELECT a, d FROM t1, t2; + SELECT * FROM v4; +} {1 4} + +do_catchsql_test 16.1.1 { + ALTER TABLE t2 RENAME d TO a; +} {1 {error in view v4 after rename: ambiguous column name: a}} + +do_execsql_test 16.1.2 { + SELECT * FROM v4; +} {1 4} + +do_execsql_test 16.1.3 { + CREATE UNIQUE INDEX t2d ON t2(d); + CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN + INSERT INTO t2 VALUES(new.a, new.b, new.c) + ON CONFLICT(d) DO UPDATE SET f = excluded.f; + END; +} + +do_execsql_test 16.1.4 { + INSERT INTO t1 VALUES(4, 8, 456); + SELECT * FROM t2; +} {4 5 456} + +do_execsql_test 16.1.5 { + ALTER TABLE t2 RENAME COLUMN f TO "big f"; + INSERT INTO t1 VALUES(4, 0, 20456); + SELECT * FROM t2; +} {4 5 20456} + +do_execsql_test 16.1.6 { + ALTER TABLE t1 RENAME COLUMN c TO "big c"; + INSERT INTO t1 VALUES(4, 0, 0); + SELECT * FROM t2; +} {4 5 0} + +do_execsql_test 16.2.1 { + CREATE VIEW temp.v5 AS SELECT "big c" FROM t1; + SELECT * FROM v5; +} {3 456 20456 0} + +do_execsql_test 16.2.2 { + ALTER TABLE t1 RENAME COLUMN "big c" TO reallybigc; +} {} + +do_execsql_test 16.2.3 { + SELECT * FROM v5; +} {3 456 20456 0} + +#------------------------------------------------------------------------- +# +do_execsql_test 17.0 { + CREATE TABLE u7(x, y, z); + CREATE TRIGGER u7t AFTER INSERT ON u7 BEGIN + INSERT INTO u8 VALUES(new.x, new.y, new.z); + END; +} {} +do_catchsql_test 17.1 { + ALTER TABLE u7 RENAME x TO xxx; +} {1 {error in trigger u7t: no such table: main.u8}} + +do_execsql_test 17.2 { + CREATE TEMP TABLE uu7(x, y, z); + CREATE TRIGGER uu7t AFTER INSERT ON uu7 BEGIN + INSERT INTO u8 VALUES(new.x, new.y, new.z); + END; +} {} +do_catchsql_test 17.3 { + ALTER TABLE uu7 RENAME x TO xxx; +} {1 {error in trigger uu7t: no such table: u8}} + +reset_db +forcedelete test.db2 +do_execsql_test 18.0 { + ATTACH 'test.db2' AS aux; + CREATE TABLE t1(a); + CREATE TABLE aux.log(v); + CREATE TEMP TRIGGER tr1 AFTER INSERT ON t1 BEGIN + INSERT INTO log VALUES(new.a); + END; + INSERT INTO t1 VALUES(111); + SELECT v FROM log; +} {111} + +do_execsql_test 18.1 { + ALTER TABLE t1 RENAME a TO b; +} + +reset_db +do_execsql_test 19.0 { + CREATE TABLE t1(a, b); + CREATE TABLE t2(c, d); + CREATE VIEW v2(e) AS SELECT coalesce(t2.c,t1.a) FROM t1, t2 WHERE t1.b=t2.d; +} + +do_execsql_test 19.1 { + ALTER TABLE t1 RENAME a TO f; + SELECT sql FROM sqlite_master WHERE name = 'v2'; +} { + {CREATE VIEW v2(e) AS SELECT coalesce(t2.c,t1.f) FROM t1, t2 WHERE t1.b=t2.d} +} + +# 2019-01-08: https://www.sqlite.org/src/tktview/bc8d94f0fbd633fd9a051e3 +# +# ALTER TABLE RENAME COLUMN does not work for tables that have redundant +# UNIQUE constraints. +# +sqlite3 db :memory: +do_execsql_test 20.100 { + CREATE TABLE t1(aaa,b,c,UNIQUE(aaA),PRIMARY KEY(aAa),UNIQUE(aAA)); + ALTER TABLE t1 RENAME aaa TO bbb; + SELECT sql FROM sqlite_master WHERE name='t1'; +} {{CREATE TABLE t1(bbb,b,c,UNIQUE(bbb),PRIMARY KEY(bbb),UNIQUE(bbb))}} +do_execsql_test 20.105 { + DROP TABLE t1; + CREATE TABLE t1(aaa,b,c,UNIQUE(aaA),PRIMARY KEY(aAa),UNIQUE(aAA))WITHOUT ROWID; + ALTER TABLE t1 RENAME aaa TO bbb; + SELECT sql FROM sqlite_master WHERE name='t1'; +} {{CREATE TABLE t1(bbb,b,c,UNIQUE(bbb),PRIMARY KEY(bbb),UNIQUE(bbb))WITHOUT ROWID}} +do_execsql_test 20.110 { + DROP TABLE t1; + CREATE TABLE t1(aa UNIQUE,bb UNIQUE,cc UNIQUE,UNIQUE(aA),PRIMARY KEY(bB),UNIQUE(cC)); + ALTER TABLE t1 RENAME aa TO xx; + ALTER TABLE t1 RENAME bb TO yy; + ALTER TABLE t1 RENAME cc TO zz; + SELECT sql FROM sqlite_master WHERE name='t1'; +} {{CREATE TABLE t1(xx UNIQUE,yy UNIQUE,zz UNIQUE,UNIQUE(xx),PRIMARY KEY(yy),UNIQUE(zz))}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 21.0 { + CREATE TABLE t1(a, b, c NOT NULL); + CREATE TRIGGER tr1 AFTER INSERT ON t1 WHEN new.c IS NOT NULL BEGIN + SELECT c NOT NULL FROM t1; + END; +} + +do_execsql_test 21.1 { + ALTER TABLE t1 RENAME c TO d; +} + +do_execsql_test 21.2 { + SELECT sql FROM sqlite_schema WHERE name IS 'tr1' +} {{CREATE TRIGGER tr1 AFTER INSERT ON t1 WHEN new.d IS NOT NULL BEGIN + SELECT d NOT NULL FROM t1; + END} +} + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 22.0 { + CREATE TABLE t1(a, b); + CREATE TABLE t2(c, othername, extra AS (c + 1)); + ALTER TABLE t1 RENAME a to othername; + SELECT sql FROM sqlite_schema; +} { + {CREATE TABLE t1(othername, b)} + {CREATE TABLE t2(c, othername, extra AS (c + 1))} +} + +#------------------------------------------------------------------------- +# +reset_db +sqlite3_db_config db SQLITE_DBCONFIG_DQS_DDL 1 +sqlite3_db_config db SQLITE_DBCONFIG_DQS_DML 1 +do_execsql_test 22.0 { + CREATE TABLE t1(a, b); + CREATE INDEX x1 on t1("c"=b); + INSERT INTO t1 VALUES('a', 'a'); + INSERT INTO t1 VALUES('b', 'b'); + INSERT INTO t1 VALUES('c', 'c'); + ALTER TABLE t1 RENAME COLUMN a TO "c"; + PRAGMA integrity_check; +} {ok} + +reset_db +do_execsql_test 23.0 { + CREATE TABLE t1('a'"b",c); + CREATE INDEX i1 ON t1('a'); + INSERT INTO t1 VALUES(1,2), (3,4); + ALTER TABLE t1 RENAME COLUMN a TO x; + PRAGMA integrity_check; + SELECT sql FROM sqlite_schema WHERE name='t1'; + +} {ok {CREATE TABLE t1("x" "b",c)}} + +# 2022-02-04 +# Do not complain about syntax errors in the schema if +# in PRAGMA writable_schema=ON mode. +# +reset_db +do_execsql_test 23.0 { + CREATE TABLE t1(a INT, b REAL, c TEXT, d BLOB, e ANY); + CREATE INDEX t1abx ON t1(a, b, a+b) WHERE c IS NOT NULL; + CREATE VIEW t2 AS SELECT a+10, b*5.0, xyz FROM t1; -- unknown column "xyz" + CREATE TABLE schema_copy(name TEXT, sql TEXT); + INSERT INTO schema_copy(name,sql) SELECT name, sql FROM sqlite_schema WHERE sql IS NOT NULL; +} {} +do_catchsql_test 23.1 { + ALTER TABLE t1 RENAME COLUMN e TO eeee; +} {1 {error in view t2: no such column: xyz}} +do_execsql_test 23.2 { + SELECT name, sql FROM sqlite_master + EXCEPT SELECT name, sql FROM schema_copy; +} {} +do_execsql_test 23.3 { + BEGIN; + PRAGMA writable_schema=ON; + ALTER TABLE t1 RENAME COLUMN e TO eeee; + PRAGMA writable_schema=OFF; + SELECT name FROM sqlite_master + WHERE (name, sql) NOT IN (SELECT name, sql FROM schema_copy); + ROLLBACK; +} {t1} +do_execsql_test 23.10 { + DROP VIEW t2; + CREATE TRIGGER r3 AFTER INSERT ON t1 BEGIN + INSERT INTO t3(x,y) VALUES(new.a, new.b); + INSERT INTO t4(p) VALUES(new.c); -- no such table "t4" + END; + DELETE FROM schema_copy; + INSERT INTO schema_copy(name,sql) SELECT name, sql FROM sqlite_schema WHERE sql IS NOT NULL; +} {} +do_catchsql_test 23.11 { + ALTER TABLE t1 RENAME COLUMN e TO eeee; +} {1 {error in trigger r3: no such table: main.t3}} +do_execsql_test 23.12 { + SELECT name, sql FROM sqlite_master + EXCEPT SELECT name, sql FROM schema_copy; +} {} +do_execsql_test 23.13 { + BEGIN; + PRAGMA writable_schema=ON; + ALTER TABLE t1 RENAME COLUMN e TO eeee; + PRAGMA writable_schema=OFF; + SELECT name FROM sqlite_master + WHERE (name, sql) NOT IN (SELECT name, sql FROM schema_copy); + ROLLBACK; +} {t1} +do_execsql_test 23.20 { + CREATE TABLE t4(id INTEGER PRIMARY KEY, c1 INT, c2 INT); + CREATE VIEW t4v1 AS SELECT id, c1, c99 FROM t4; + DELETE FROM schema_copy; + INSERT INTO schema_copy SELECT name, sql FROM sqlite_schema; + BEGIN; + PRAGMA writable_schema=ON; + ALTER TABLE t4 RENAME to t4new; + SELECT name FROM sqlite_schema WHERE (name,sql) NOT IN (SELECT * FROM schema_copy); + ROLLBACK; +} {t4new} + +finish_test diff --git a/test/altercorrupt.test b/test/altercorrupt.test new file mode 100644 index 0000000..f24cb30 --- /dev/null +++ b/test/altercorrupt.test @@ -0,0 +1,181 @@ +# 2019-01-11 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix altercorrupt + +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. +ifcapable !altertable { + finish_test + return +} + +database_may_be_corrupt + +#-------------------------------------------------------------------------- +reset_db +do_test 1.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +.open --hexdb +| size 24576 pagesize 4096 filename crash-685346d89b5e5f.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 06 .....@ ........ +| 32: 00 00 63 00 00 05 f0 00 00 00 00 04 10 00 00 04 ..c............. +| 48: 00 00 00 00 00 00 0f f0 00 00 00 01 00 00 00 00 ................ +| 64: 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 96: 00 00 00 00 0d 0f f8 00 05 0e cf 00 0f 79 0f d3 .............y.. +| 112: 0f 2e 0e f3 0e cf 00 00 00 00 00 00 00 00 00 00 ................ +| 3776: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 22 ................ +| 3792: 05 06 17 11 11 01 31 74 61 62 6c 65 74 34 74 34 ......1tablet4t4 +| 3808: 06 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 34 .CREATE TABLE t4 +| 3824: 28 7a 29 39 04 06 17 11 11 01 5f 74 61 62 6c 65 (z)9......_table +| 3840: 74 33 74 33 05 43 52 45 41 54 45 20 54 41 42 4c t3t3.CREATE TABL +| 3856: 45 20 74 33 28 78 20 49 4e 54 45 47 45 52 20 50 E t3(x INTEGER P +| 3872: 52 49 4d 41 52 59 20 4b 45 59 2c 20 79 29 49 03 RIMARY KEY, y)I. +| 3888: 06 17 11 11 01 7f 74 61 62 6c 65 74 32 74 32 04 ......tablet2t2. +| 3904: 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 32 28 CREATE TABLE t2( +| 3920: 61 2c 62 2c 63 20 50 52 49 4d 41 52 59 20 4b 45 a,b,c PRIMARY KE +| 3936: 59 2c 20 64 2c 20 65 2c 20 66 29 20 57 49 54 48 Y, d, e, f) WITH +| 3952: 4f 55 54 20 52 4f 57 49 44 58 03 07 17 11 11 01 OUT ROWIDX...... +| 3968: 81 1b 74 61 62 6c 65 74 31 74 31 02 43 52 45 41 ..tablet1t1.CREA +| 3984: 54 45 20 54 41 42 4c 45 20 74 31 28 61 2c 62 2c TE TABLE t1(a,b, +| 4000: 63 20 41 53 20 28 2d 62 29 20 56 49 52 54 55 41 c AS (-b) VIRTUA +| 4016: 4c 2c 64 20 43 48 45 43 4b 28 64 3e 35 29 2c 65 L,d CHECK(d>5),e +| 4032: 20 55 4e 49 51 55 45 2c 20 66 20 41 53 20 28 2b UNIQUE, f AS (+ +| 4048: 62 29 29 23 02 06 17 37 11 01 00 69 6e 64 65 78 b))#...7...index +| 4064: 73 71 6c 69 74 65 5f 61 75 74 6f 69 6e 64 65 78 sqlite_autoindex +| 4080: 5f 74 31 5f 31 74 31 03 00 00 00 08 00 00 00 00 _t1_1t1......... +| page 2 offset 4096 +| 0: 0d 00 00 00 0a 0f 93 00 0f f6 0f eb 0f e0 0f d5 ................ +| 16: 0f ca 0f 8f 0f b4 0f a9 0f 9e 0f 93 00 00 00 00 ................ +| 3984: 00 00 00 09 0a 05 01 01 01 01 0a 64 6e 14 09 09 ...........dn... +| 4000: 05 01 01 01 01 09 5a 6d 12 09 08 05 01 01 01 01 ......Zm........ +| 4016: 08 50 6c 10 09 07 05 01 01 01 01 07 46 6b 0e 09 .Pl.........Fk.. +| 4032: 06 05 01 01 01 01 06 3c 6a 0c 09 05 05 01 01 01 .......5),e +| 4032: 20 55 4e 49 51 55 45 2c 20 66 20 41 53 20 28 2b UNIQUE, f AS (+ +| 4048: 62 29 29 23 02 06 17 37 11 01 00 69 6e 64 65 78 b))#...7...index +| 4064: 73 71 6c 69 74 65 5f 61 75 74 6f 69 6e 64 65 78 sqlite_autoindex +| 4080: 5f 74 31 5f 31 84 31 03 01 00 00 08 00 00 00 00 _t1_1.1......... +| page 2 offset 4096 +| 0: 0d 00 00 00 0a 0f 93 00 0f f6 0f eb 0f e0 0f d5 ................ +| 16: 0f ca 0f 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 3984: 00 00 00 09 0a 05 01 01 01 01 0a 64 6e 14 09 09 ...........dn... +| 4000: 05 01 01 01 01 09 5a 6d 12 09 08 05 01 00 f1 01 ......Zm........ +| 4016: 08 50 6c 10 09 07 05 01 01 01 01 07 46 6b 0e 09 .Pl.........Fk.. +| 4032: 06 05 01 00 f1 01 06 3c 6a 0c 09 05 05 01 01 01 .......10)); + CREATE TABLE t13(a, b, c CHECK(c>10)); +} +do_catchsql_test 3.1 { + ALTER TABLE t12 DROP COLUMN c; +} {1 {error in table t12 after drop column: no such column: c}} + +do_catchsql_test 3.2 { + ALTER TABLE t13 DROP COLUMN c; +} {0 {}} + +#------------------------------------------------------------------------- +# Test that generated columns can be dropped. And that other columns from +# tables that contain generated columns can be dropped. +# +foreach {tn wo vs} { + 1 "" "" + 2 "" VIRTUAL + 3 "" STORED + 4 "WITHOUT ROWID" STORED + 5 "WITHOUT ROWID" VIRTUAL +} { + reset_db + + do_execsql_test 4.$tn.0 " + CREATE TABLE 'my table'(a, b PRIMARY KEY, c AS (a+b) $vs, d) $wo + " + do_execsql_test 4.$tn.1 { + INSERT INTO "my table"(a, b, d) VALUES(1, 2, 'hello'); + INSERT INTO "my table"(a, b, d) VALUES(3, 4, 'world'); + + SELECT * FROM "my table" + } { + 1 2 3 hello + 3 4 7 world + } + + do_execsql_test 4.$tn.2 { + ALTER TABLE "my table" DROP COLUMN c; + } + do_execsql_test 4.$tn.3 { + SELECT * FROM "my table" + } { + 1 2 hello + 3 4 world + } + + do_execsql_test 4.$tn.4 " + CREATE TABLE x1(a, b, c PRIMARY KEY, d AS (b+c) $vs, e) $wo + " + do_execsql_test 4.$tn.5 { + INSERT INTO x1(a, b, c, e) VALUES(1, 2, 3, 4); + INSERT INTO x1(a, b, c, e) VALUES(5, 6, 7, 8); + INSERT INTO x1(a, b, c, e) VALUES(9, 10, 11, 12); + SELECT * FROM x1; + } { + 1 2 3 5 4 + 5 6 7 13 8 + 9 10 11 21 12 + } + + do_execsql_test 4.$tn.6 { + ALTER TABLE x1 DROP COLUMN a + } + do_execsql_test 4.$tn.7 { + SELECT * FROM x1 + } { + 2 3 5 4 + 6 7 13 8 + 10 11 21 12 + } + do_execsql_test 4.$tn.8 { + ALTER TABLE x1 DROP COLUMN e + } + do_execsql_test 4.$tn.9 { + SELECT * FROM x1 + } { + 2 3 5 + 6 7 13 + 10 11 21 + } +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 5.0 { + CREATE TABLE p1(a PRIMARY KEY, b UNIQUE); + CREATE TABLE c1(x, y, z REFERENCES p1(c)); + CREATE TABLE c2(x, y, z, w REFERENCES p1(b)); +} +do_execsql_test 5.1 { + ALTER TABLE c1 DROP COLUMN z; + ALTER TABLE c2 DROP COLUMN z; + SELECT sql FROM sqlite_schema WHERE name IN ('c1', 'c2'); +} { + {CREATE TABLE c1(x, y)} + {CREATE TABLE c2(x, y, w REFERENCES p1(b))} +} + +do_execsql_test 5.2.1 { + CREATE VIEW v1 AS SELECT d, e FROM p1 +} +do_catchsql_test 5.2.2 { + ALTER TABLE c1 DROP COLUMN x +} {1 {error in view v1: no such column: d}} +do_execsql_test 5.3.1 { + DROP VIEW v1; + CREATE VIEW v1 AS SELECT x, y FROM c1; +} +do_catchsql_test 5.3.2 { + ALTER TABLE c1 DROP COLUMN x +} {1 {error in view v1 after drop column: no such column: x}} + +do_execsql_test 5.4.1 { + CREATE TRIGGER tr AFTER INSERT ON c1 BEGIN + INSERT INTO p1 VALUES(new.y, new.xyz); + END; +} +do_catchsql_test 5.4.2 { + ALTER TABLE c1 DROP COLUMN y +} {1 {error in trigger tr: no such column: new.xyz}} +do_execsql_test 5.5.1 { + DROP TRIGGER tr; + CREATE TRIGGER tr AFTER INSERT ON c1 BEGIN + INSERT INTO p1 VALUES(new.y, new.z); + END; +} +do_catchsql_test 5.5.2 { + ALTER TABLE c1 DROP COLUMN y +} {1 {error in trigger tr: no such column: new.z}} + +# 2021-03-06 dbsqlfuzz crash-419aa525df93db6e463772c686ac6da27b46da9e +reset_db +do_catchsql_test 6.0 { + CREATE TABLE t1(a,b,c); + CREATE TABLE t2(x,y,z); + PRAGMA writable_schema=ON; + UPDATE sqlite_schema SET sql='CREATE INDEX t1b ON t1(b)' WHERE name='t2'; + PRAGMA writable_schema=OFF; + ALTER TABLE t2 DROP COLUMN z; +} {1 {database disk image is malformed}} +reset_db +do_catchsql_test 6.1 { + CREATE TABLE t1(a,b,c); + CREATE TABLE t2(x,y,z); + PRAGMA writable_schema=ON; + UPDATE sqlite_schema SET sql='CREATE VIEW t2(x,y,z) AS SELECT b,a,c FROM t1' + WHERE name='t2'; + PRAGMA writable_schema=OFF; + ALTER TABLE t2 DROP COLUMN z; +} {1 {database disk image is malformed}} + +# 2021-04-06 dbsqlfuzz crash-331c5c29bb76257b198f1318eef3288f9624c8ce +reset_db +do_execsql_test 7.0 { + CREATE TABLE t1(a, b, c, PRIMARY KEY(a COLLATE nocase, a)) WITHOUT ROWID; + INSERT INTO t1 VALUES(1, 2, 3); + INSERT INTO t1 VALUES(4, 5, 6); +} +do_execsql_test 7.1 { + ALTER TABLE t1 DROP COLUMN c; +} +do_execsql_test 7.2 { + SELECT sql FROM sqlite_schema; +} {{CREATE TABLE t1(a, b, PRIMARY KEY(a COLLATE nocase, a)) WITHOUT ROWID}} +do_execsql_test 7.3 { + SELECT * FROM t1; +} {1 2 4 5} + +reset_db +do_execsql_test 8.0 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + PRAGMA writable_schema = 1; + UPDATE sqlite_schema + SET sql = 'CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b)' +} +db close +sqlite3 db test.db +do_execsql_test 8.1 { + ALTER TABLE t1 DROP COLUMN b; +} +do_execsql_test 8.2 { + SELECT sql FROM sqlite_schema; +} {{CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT)}} + +#------------------------------------------------------------------------- + +foreach {tn wo} { + 1 {} + 2 {WITHOUT ROWID} +} { + reset_db + do_execsql_test 9.$tn.0 " + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c) $wo; + " + do_execsql_test 9.$tn.1 { + WITH s(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<50000 + ) + INSERT INTO t1(a, b, c) SELECT i, 123, 456 FROM s; + } + do_execsql_test 9.$tn.2 { + ALTER TABLE t1 DROP COLUMN b; + } + + do_execsql_test 9.$tn.3 { + SELECT count(*), c FROM t1 GROUP BY c; + } {50000 456} +} + + + +finish_test diff --git a/test/alterdropcol2.test b/test/alterdropcol2.test new file mode 100644 index 0000000..d60e7db --- /dev/null +++ b/test/alterdropcol2.test @@ -0,0 +1,222 @@ +# 2021 February 19 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix alterdropcol2 + +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. +ifcapable !altertable { + finish_test + return +} + +# EVIDENCE-OF: R-58318-35349 The DROP COLUMN syntax is used to remove an +# existing column from a table. +do_execsql_test 1.0 { + CREATE TABLE t1(c, b, a, PRIMARY KEY(b, a)) WITHOUT ROWID; + INSERT INTO t1 VALUES(1, 2, 3), (4, 5, 6); +} +do_execsql_test 1.1 { + ALTER TABLE t1 DROP c; +} + +# EVIDENCE-OF: The DROP COLUMN command removes the named column from the table, +# and also rewrites the entire table to purge the data associated with that +# column. +do_execsql_test 1.2.1 { + SELECT * FROM t1; +} {2 3 5 6} + +do_execsql_test 1.2.2 { + SELECT sql FROM sqlite_schema; +} { + {CREATE TABLE t1(b, a, PRIMARY KEY(b, a)) WITHOUT ROWID} +} + +proc do_atdc_error_test {tn schema atdc error} { + reset_db + execsql $schema + uplevel [list do_catchsql_test $tn $atdc [list 1 [string trim $error]]] +} + +#------------------------------------------------------------------------- +# Test cases 2.* attempt to verify the following: +# +# EVIDENCE-OF: R-24098-10282 The DROP COLUMN command only works if the column +# is not referenced by any other parts of the schema and is not a PRIMARY KEY +# and does not have a UNIQUE constraint. +# + +# EVIDENCE-OF: R-52436-31752 The column is a PRIMARY KEY or part of one. +# +do_atdc_error_test 2.1.1 { + CREATE TABLE x1(a PRIMARY KEY, b, c); +} { + ALTER TABLE x1 DROP COLUMN a +} { + cannot drop PRIMARY KEY column: "a" +} +do_atdc_error_test 2.1.2 { + CREATE TABLE x1(a,b,c,d,e, PRIMARY KEY(b,c,d)); +} { + ALTER TABLE x1 DROP COLUMN c +} { + cannot drop PRIMARY KEY column: "c" +} + +# EVIDENCE-OF: R-43412-16016 The column has a UNIQUE constraint. +# +do_atdc_error_test 2.2.1 { + CREATE TABLE x1(a PRIMARY KEY, b, c UNIQUE); +} { + ALTER TABLE x1 DROP COLUMN c +} { + cannot drop UNIQUE column: "c" +} +do_atdc_error_test 2.2.2 { + CREATE TABLE x1(a PRIMARY KEY, b, c, UNIQUE(b, c)); +} { + ALTER TABLE x1 DROP COLUMN c +} { + error in table x1 after drop column: no such column: c +} + +# EVIDENCE-OF: R-46731-08965 The column is indexed. +# +do_atdc_error_test 2.3.1 { + CREATE TABLE 'one two'('x y', 'z 1', 'a b'); + CREATE INDEX idx ON 'one two'('z 1'); +} { + ALTER TABLE 'one two' DROP COLUMN 'z 1' +} { + error in index idx after drop column: no such column: z 1 +} +do_atdc_error_test 2.3.2 { + CREATE TABLE x1(a, b, c); + CREATE INDEX idx ON x1(a); +} { + ALTER TABLE x1 DROP COLUMN a; +} { + error in index idx after drop column: no such column: a +} + +# EVIDENCE-OF: R-46731-08965 The column is indexed. +# +do_atdc_error_test 2.4.1 { + CREATE TABLE x1234(a, b, c PRIMARY KEY) WITHOUT ROWID; + CREATE INDEX i1 ON x1234(b) WHERE ((a+5) % 10)==0; +} { + ALTER TABLE x1234 DROP a +} { + error in index i1 after drop column: no such column: a +} + +# EVIDENCE-OF: R-47838-03249 The column is named in a table or column +# CHECK constraint not associated with the column being dropped. +# +do_atdc_error_test 2.5.1 { + CREATE TABLE x1234(a, b, c PRIMARY KEY, CHECK(((a+5)%10)!=0)) WITHOUT ROWID; +} { + ALTER TABLE x1234 DROP a +} { + error in table x1234 after drop column: no such column: a +} + +# EVIDENCE-OF: R-55640-01652 The column is used in a foreign key constraint. +# +do_atdc_error_test 2.6.1 { + CREATE TABLE p1(x, y UNIQUE); + CREATE TABLE c1(u, v, FOREIGN KEY (v) REFERENCES p1(y)) +} { + ALTER TABLE c1 DROP v +} { + error in table c1 after drop column: unknown column "v" in foreign key definition +} + +# EVIDENCE-OF: R-20795-39479 The column is used in the expression of a +# generated column. +do_atdc_error_test 2.7.1 { + CREATE TABLE c1(u, v, w AS (u+v)); +} { + ALTER TABLE c1 DROP v +} { + error in table c1 after drop column: no such column: v +} +do_atdc_error_test 2.7.2 { + CREATE TABLE c1(u, v, w AS (u+v) STORED); +} { + ALTER TABLE c1 DROP u +} { + error in table c1 after drop column: no such column: u +} + +# EVIDENCE-OF: R-01515-49025 The column appears in a trigger or view. +# +do_atdc_error_test 2.8.1 { + CREATE TABLE log(l); + CREATE TABLE c1(u, v, w); + CREATE TRIGGER tr1 AFTER INSERT ON c1 BEGIN + INSERT INTO log VALUES(new.w); + END; +} { + ALTER TABLE c1 DROP w +} { + error in trigger tr1 after drop column: no such column: new.w +} +do_atdc_error_test 2.8.2 { + CREATE TABLE c1(u, v, w); + CREATE VIEW v1 AS SELECT u, v, w FROM c1; +} { + ALTER TABLE c1 DROP w +} { + error in view v1 after drop column: no such column: w +} +do_atdc_error_test 2.8.3 { + CREATE TABLE c1(u, v, w); + CREATE VIEW v1 AS SELECT * FROM c1 WHERE w IS NOT NULL; +} { + ALTER TABLE c1 DROP w +} { + error in view v1 after drop column: no such column: w +} + +#------------------------------------------------------------------------- +# Verify that a column that is part of a CHECK constraint may be dropped +# if the CHECK constraint was specified as part of the column definition. +# + +# STALE-EVIDENCE: R-60924-11170 However, the column being deleted can be used in a +# column CHECK constraint because the column CHECK constraint is dropped +# together with the column itself. +do_execsql_test 3.0 { + CREATE TABLE yyy(q, w, e CHECK (e > 0), r); + INSERT INTO yyy VALUES(1,1,1,1), (2,2,2,2); + + CREATE TABLE zzz(q, w, e, r, CHECK (e > 0)); + INSERT INTO zzz VALUES(1,1,1,1), (2,2,2,2); +} +do_catchsql_test 3.1.1 { + INSERT INTO yyy VALUES(0,0,0,0); +} {1 {CHECK constraint failed: e > 0}} +do_catchsql_test 3.1.2 { + INSERT INTO yyy VALUES(0,0,0,0); +} {1 {CHECK constraint failed: e > 0}} + +do_execsql_test 3.2.1 { + ALTER TABLE yyy DROP e; +} +do_catchsql_test 3.2.2 { + ALTER TABLE zzz DROP e; +} {1 {error in table zzz after drop column: no such column: e}} + +finish_test diff --git a/test/alterfault.test b/test/alterfault.test new file mode 100644 index 0000000..b6b4297 --- /dev/null +++ b/test/alterfault.test @@ -0,0 +1,41 @@ +# 2021 November 16 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix alterfault + +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. +ifcapable !altertable { + finish_test + return +} + +do_execsql_test 1.0 { + CREATE TABLE t1(a); +} +faultsim_save_and_close + +do_faultsim_test 1.1 -faults oom* -prep { + faultsim_restore_and_reopen +} -body { + execsql { + ALTER TABLE t1 ADD COLUMN b CHECK (a!=1) + } +} -test { + faultsim_test_result {0 {}} +} + + + +finish_test diff --git a/test/alterlegacy.test b/test/alterlegacy.test new file mode 100644 index 0000000..dfa1716 --- /dev/null +++ b/test/alterlegacy.test @@ -0,0 +1,469 @@ +# 2018 September 20 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix alterlegacy + +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. +ifcapable !altertable { + finish_test + return +} + +do_execsql_test 1.0 { + PRAGMA legacy_alter_table = 1; + CREATE TABLE t1(a, b, CHECK(t1.a != t1.b)); + CREATE TABLE t2(a, b); + CREATE INDEX t2expr ON t2(a) WHERE t2.b>0; +} + +do_execsql_test 1.1 { + SELECT sql FROM sqlite_master +} { + {CREATE TABLE t1(a, b, CHECK(t1.a != t1.b))} + {CREATE TABLE t2(a, b)} + {CREATE INDEX t2expr ON t2(a) WHERE t2.b>0} +} + +# Legacy behavior is to corrupt the schema in this case, as the table name in +# the CHECK constraint is incorrect after "t1" is renamed. This version is +# slightly different - it rejects the change and rolls back the transaction. +do_catchsql_test 1.2 { + ALTER TABLE t1 RENAME TO t1new; +} {1 {error in table t1new after rename: no such column: t1.a}} + +do_execsql_test 1.3 { + CREATE TABLE t3(c, d); + ALTER TABLE t3 RENAME TO t3new; + DROP TABLE t3new; +} + +do_execsql_test 1.4 { + SELECT sql FROM sqlite_master +} { + {CREATE TABLE t1(a, b, CHECK(t1.a != t1.b))} + {CREATE TABLE t2(a, b)} + {CREATE INDEX t2expr ON t2(a) WHERE t2.b>0} +} + + +do_catchsql_test 1.3 { + ALTER TABLE t2 RENAME TO t2new; +} {1 {error in index t2expr after rename: no such column: t2.b}} +do_execsql_test 1.4 { + SELECT sql FROM sqlite_master +} { + {CREATE TABLE t1(a, b, CHECK(t1.a != t1.b))} + {CREATE TABLE t2(a, b)} + {CREATE INDEX t2expr ON t2(a) WHERE t2.b>0} +} + + +#------------------------------------------------------------------------- +reset_db +ifcapable vtab { + register_echo_module db + + do_execsql_test 2.0 { + PRAGMA legacy_alter_table = 1; + CREATE TABLE abc(a, b, c); + INSERT INTO abc VALUES(1, 2, 3); + CREATE VIRTUAL TABLE eee USING echo('abc'); + SELECT * FROM eee; + } {1 2 3} + + do_execsql_test 2.1 { + ALTER TABLE eee RENAME TO fff; + SELECT * FROM fff; + } {1 2 3} + + db close + sqlite3 db test.db + + do_catchsql_test 2.2 { + ALTER TABLE fff RENAME TO ggg; + } {1 {no such module: echo}} +} + +#------------------------------------------------------------------------- +reset_db + +do_execsql_test 3.0 { + PRAGMA legacy_alter_table = 1; + CREATE TABLE txx(a, b, c); + INSERT INTO txx VALUES(1, 2, 3); + CREATE VIEW vvv AS SELECT main.txx.a, txx.b, c FROM txx; + CREATE VIEW uuu AS SELECT main.one.a, one.b, c FROM txx AS one; + CREATE VIEW temp.ttt AS SELECT main.txx.a, txx.b, one.b, main.one.a FROM txx AS one, txx; +} + +do_execsql_test 3.1.1 { + SELECT * FROM vvv; +} {1 2 3} +do_execsql_test 3.1.2a { + ALTER TABLE txx RENAME TO "t xx"; +} +do_catchsql_test 3.1.2b { + SELECT * FROM vvv; +} {1 {no such table: main.txx}} +do_execsql_test 3.1.3 { + SELECT sql FROM sqlite_master WHERE name='vvv'; +} {{CREATE VIEW vvv AS SELECT main.txx.a, txx.b, c FROM txx}} + + +do_catchsql_test 3.2.1 { + SELECT * FROM uuu; +} {1 {no such table: main.txx}} +do_execsql_test 3.2.2 { + SELECT sql FROM sqlite_master WHERE name='uuu';; +} {{CREATE VIEW uuu AS SELECT main.one.a, one.b, c FROM txx AS one}} + +do_catchsql_test 3.3.1 { + SELECT * FROM ttt; +} {1 {no such table: txx}} +do_execsql_test 3.3.2 { + SELECT sql FROM sqlite_temp_master WHERE name='ttt'; +} {{CREATE VIEW ttt AS SELECT main.txx.a, txx.b, one.b, main.one.a FROM txx AS one, txx}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 4.0 { + PRAGMA legacy_alter_table = 1; + CREATE table t1(x, y); + CREATE table t2(a, b); + + CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN + SELECT t1.x, * FROM t1, t2; + INSERT INTO t2 VALUES(new.x, new.y); + END; +} + +do_execsql_test 4.1 { + INSERT INTO t1 VALUES(1, 1); + ALTER TABLE t1 RENAME TO t11; +} +do_catchsql_test 4.1a { + INSERT INTO t11 VALUES(2, 2); +} {1 {no such table: main.t1}} +do_execsql_test 4.1b { + ALTER TABLE t11 RENAME TO t1; + ALTER TABLE t2 RENAME TO t22; +} +do_catchsql_test 4.1c { + INSERT INTO t1 VALUES(3, 3); +} {1 {no such table: main.t2}} + +proc squish {a} { + string trim [regsub -all {[[:space:]][[:space:]]*} $a { }] +} +db func squish squish +do_test 4.2 { + execsql { SELECT squish(sql) FROM sqlite_master WHERE name = 'tr1' } +} [list [squish { + CREATE TRIGGER tr1 AFTER INSERT ON "t1" BEGIN + SELECT t1.x, * FROM t1, t2; + INSERT INTO t2 VALUES(new.x, new.y); + END +}]] + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 5.0 { + PRAGMA legacy_alter_table = 1; + CREATE TABLE t9(a, b, c); + CREATE TABLE t10(a, b, c); + CREATE TEMP TABLE t9(a, b, c); + + CREATE TRIGGER temp.t9t AFTER INSERT ON temp.t9 BEGIN + INSERT INTO t10 VALUES(new.a, new.b, new.c); + END; + + INSERT INTO temp.t9 VALUES(1, 2, 3); + SELECT * FROM t10; +} {1 2 3} + +do_execsql_test 5.1 { + ALTER TABLE temp.t9 RENAME TO 't1234567890' +} + +do_execsql_test 5.2 { + CREATE TABLE t1(a, b); + CREATE TABLE t2(a, b); + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t2 VALUES(3, 4); + CREATE VIEW v AS SELECT one.a, one.b, t2.a, t2.b FROM t1 AS one, t2; + SELECT * FROM v; +} {1 2 3 4} + +do_execsql_test 5.3 { + ALTER TABLE t2 RENAME TO one; +} {} + +do_catchsql_test 5.4 { + SELECT * FROM v +} {1 {no such table: main.t2}} + +do_execsql_test 5.5 { + ALTER TABLE one RENAME TO t2; + DROP VIEW v; + CREATE VIEW temp.vv AS SELECT one.a, one.b, t2.a, t2.b FROM t1 AS one, t2; + SELECT * FROM vv; +} {1 2 3 4} + +do_execsql_test 5.6 { + ALTER TABLE t2 RENAME TO one; +} {} +do_catchsql_test 5.7 { + SELECT * FROM vv +} {1 {no such table: t2}} + +#------------------------------------------------------------------------- + +ifcapable vtab { + register_tcl_module db + proc tcl_command {method args} { + switch -- $method { + xConnect { + return "CREATE TABLE t1(a, b, c)" + } + } + return {} + } + + do_execsql_test 6.0 { + CREATE VIRTUAL TABLE x1 USING tcl(tcl_command); + } + + do_execsql_test 6.1 { + ALTER TABLE x1 RENAME TO x2; + SELECT sql FROM sqlite_master WHERE name = 'x2' + } {{CREATE VIRTUAL TABLE "x2" USING tcl(tcl_command)}} + + do_execsql_test 7.1 { + CREATE TABLE ddd(db, sql, zOld, zNew, bTemp); + INSERT INTO ddd VALUES( + 'main', 'CREATE TABLE x1(i INTEGER, t TEXT)', 'ddd', NULL, 0 + ), ( + 'main', 'CREATE TABLE x1(i INTEGER, t TEXT)', NULL, 'eee', 0 + ), ( + 'main', NULL, 'ddd', 'eee', 0 + ); + } {} +} + +#------------------------------------------------------------------------- +# +reset_db +forcedelete test.db2 +do_execsql_test 8.1 { + PRAGMA legacy_alter_table = 1; + ATTACH 'test.db2' AS aux; + PRAGMA foreign_keys = on; + CREATE TABLE aux.p1(a INTEGER PRIMARY KEY, b); + CREATE TABLE aux.c1(x INTEGER PRIMARY KEY, y REFERENCES p1(a)); + INSERT INTO aux.p1 VALUES(1, 1); + INSERT INTO aux.p1 VALUES(2, 2); + INSERT INTO aux.c1 VALUES(NULL, 2); + CREATE TABLE aux.c2(x INTEGER PRIMARY KEY, y REFERENCES c1(a)); +} + +do_execsql_test 8.2 { + ALTER TABLE aux.p1 RENAME TO ppp; +} + +do_execsql_test 8.2 { + INSERT INTO aux.c1 VALUES(NULL, 1); + SELECT sql FROM aux.sqlite_master WHERE name = 'c1'; +} {{CREATE TABLE c1(x INTEGER PRIMARY KEY, y REFERENCES "ppp"(a))}} + +reset_db +do_execsql_test 9.0 { + PRAGMA legacy_alter_table = 1; + CREATE TABLE t1(a, b, c); + CREATE VIEW v1 AS SELECT * FROM t2; +} +do_execsql_test 9.1 { + ALTER TABLE t1 RENAME TO t3; +} {} +do_execsql_test 9.1b { + ALTER TABLE t3 RENAME TO t1; +} {} +do_execsql_test 9.2 { + DROP VIEW v1; + CREATE TRIGGER tr AFTER INSERT ON t1 BEGIN + INSERT INTO t2 VALUES(new.a); + END; +} +do_execsql_test 9.3 { + ALTER TABLE t1 RENAME TO t3; +} {} + +forcedelete test.db2 +do_execsql_test 9.4 { + ALTER TABLE t3 RENAME TO t1; + DROP TRIGGER tr; + + ATTACH 'test.db2' AS aux; + CREATE TRIGGER tr AFTER INSERT ON t1 WHEN new.a IS NULL BEGIN SELECT 1, 2, 3; END; + + CREATE TABLE aux.t1(x); + CREATE TEMP TRIGGER tr AFTER INSERT ON aux.t1 BEGIN SELECT 1, 2, 3; END; +} +do_execsql_test 9.5 { + ALTER TABLE main.t1 RENAME TO t3; +} +do_execsql_test 9.6 { + SELECT sql FROM sqlite_temp_master; + SELECT sql FROM sqlite_master WHERE type='trigger'; +} { + {CREATE TRIGGER tr AFTER INSERT ON aux.t1 BEGIN SELECT 1, 2, 3; END} + {CREATE TRIGGER tr AFTER INSERT ON "t3" WHEN new.a IS NULL BEGIN SELECT 1, 2, 3; END} +} + +#------------------------------------------------------------------------- +reset_db +ifcapable fts5 { + do_execsql_test 10.0 { + PRAGMA legacy_alter_table = 1; + CREATE VIRTUAL TABLE fff USING fts5(x, y, z); + } + + do_execsql_test 10.1 { + BEGIN; + INSERT INTO fff VALUES('a', 'b', 'c'); + ALTER TABLE fff RENAME TO ggg; + COMMIT; + } + + do_execsql_test 10.2 { + SELECT * FROM ggg; + } {a b c} +} + +#------------------------------------------------------------------------- +reset_db +forcedelete test.db2 +db func trigger trigger +set ::trigger [list] +proc trigger {args} { + lappend ::trigger $args +} +do_execsql_test 11.0 { + PRAGMA legacy_alter_table = 1; + ATTACH 'test.db2' AS aux; + CREATE TABLE aux.t1(a, b, c); + CREATE TABLE main.t1(a, b, c); + CREATE TEMP TRIGGER tr AFTER INSERT ON aux.t1 BEGIN + SELECT trigger(new.a, new.b, new.c); + END; +} + +do_execsql_test 11.1 { + INSERT INTO main.t1 VALUES(1, 2, 3); + INSERT INTO aux.t1 VALUES(4, 5, 6); +} +do_test 11.2 { set ::trigger } {{4 5 6}} + +do_execsql_test 11.3 { + SELECT name, tbl_name FROM sqlite_temp_master; +} {tr t1} + +do_execsql_test 11.4 { + ALTER TABLE main.t1 RENAME TO t2; + SELECT name, tbl_name FROM sqlite_temp_master; +} {tr t1} + +do_execsql_test 11.5 { + ALTER TABLE aux.t1 RENAME TO t2; + SELECT name, tbl_name FROM sqlite_temp_master; +} {tr t2} + +do_execsql_test 11.6 { + INSERT INTO aux.t2 VALUES(7, 8, 9); +} +do_test 11.7 { set ::trigger } {{4 5 6} {7 8 9}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 12.0 { + PRAGMA legacy_alter_table = 1; + CREATE TABLE t1(a); + CREATE TABLE t2(w); + CREATE TRIGGER temp.r1 AFTER INSERT ON main.t2 BEGIN + INSERT INTO t1(a) VALUES(new.w); + END; + CREATE TEMP TABLE t2(x); +} + +do_execsql_test 12.1 { + ALTER TABLE main.t2 RENAME TO t3; +} + +do_execsql_test 12.2 { + INSERT INTO t3 VALUES('WWW'); + SELECT * FROM t1; +} {WWW} + + +#------------------------------------------------------------------------- +reset_db + +ifcapable rtree { + do_execsql_test 14.0 { + PRAGMA legacy_alter_table = 1; + CREATE VIRTUAL TABLE rt USING rtree(id, minx, maxx, miny, maxy); + + CREATE TABLE "mytable" ( "fid" INTEGER PRIMARY KEY, "geom" BLOB); + + CREATE TRIGGER tr1 AFTER UPDATE OF "geom" ON "mytable" + WHEN OLD."fid" = NEW."fid" AND NEW."geom" IS NULL BEGIN + DELETE FROM rt WHERE id = OLD."fid"; + END; + + INSERT INTO mytable VALUES(1, X'abcd'); + } + + do_execsql_test 14.1 { + UPDATE mytable SET geom = X'1234' + } + + do_execsql_test 14.2 { + ALTER TABLE mytable RENAME TO mytable_renamed; + } + + do_execsql_test 14.3 { + CREATE TRIGGER tr2 AFTER INSERT ON mytable_renamed BEGIN + DELETE FROM rt WHERE id=(SELECT min(id) FROM rt); + END; + } + + do_execsql_test 14.4 { + ALTER TABLE mytable_renamed RENAME TO mytable2; + } +} + +reset_db +do_execsql_test 14.5 { + PRAGMA legacy_alter_table = 1; + CREATE TABLE t1(a, b, c); + CREATE VIEW v1 AS SELECT * FROM t1; + CREATE TRIGGER xyz AFTER INSERT ON t1 BEGIN + SELECT a, b FROM v1; + END; +} +do_execsql_test 14.6 { + ALTER TABLE t1 RENAME TO tt1; +} + + +finish_test diff --git a/test/altermalloc.test b/test/altermalloc.test new file mode 100644 index 0000000..22ea158 --- /dev/null +++ b/test/altermalloc.test @@ -0,0 +1,71 @@ +# 2005 September 19 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the ALTER TABLE statement and +# specifically out-of-memory conditions within that command. +# +# $Id: altermalloc.test,v 1.10 2008/10/30 17:21:13 danielk1977 Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. +ifcapable !altertable { + finish_test + return +} + +source $testdir/malloc_common.tcl + +do_malloc_test altermalloc-1 -tclprep { + db close +} -tclbody { + if {[catch {sqlite3 db test.db}]} { + error "out of memory" + } + sqlite3_db_config_lookaside db 0 0 0 + sqlite3_extended_result_codes db 1 +} -sqlbody { + CREATE TABLE t1(a int); + ALTER TABLE t1 ADD COLUMN b INTEGER DEFAULT NULL; + ALTER TABLE t1 ADD COLUMN c TEXT DEFAULT 'default-text'; + ALTER TABLE t1 RENAME TO t2; + ALTER TABLE t2 ADD COLUMN d BLOB DEFAULT X'ABCD'; +} + +# Test malloc() failure on an ALTER TABLE on a virtual table. +# +ifcapable vtab { + do_malloc_test altermalloc-vtab -tclprep { + sqlite3 db2 test.db + sqlite3_db_config_lookaside db2 0 0 0 + sqlite3_extended_result_codes db2 1 + register_echo_module [sqlite3_connection_pointer db2] + db2 eval { + CREATE TABLE t1(a, b VARCHAR, c INTEGER); + CREATE VIRTUAL TABLE t1echo USING echo(t1); + } + db2 close + + register_echo_module [sqlite3_connection_pointer db] + } -tclbody { + set rc [catch {db eval { ALTER TABLE t1echo RENAME TO t1_echo }} msg] + if {$msg eq "vtable constructor failed: t1echo"} { + set msg "out of memory" + } + if {$rc} { + error $msg + } + } +} + +finish_test diff --git a/test/altermalloc2.test b/test/altermalloc2.test new file mode 100644 index 0000000..a90be88 --- /dev/null +++ b/test/altermalloc2.test @@ -0,0 +1,127 @@ +# 2018 August 20 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/malloc_common.tcl +set testprefix altermalloc2 + +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. +ifcapable !altertable { + finish_test + return +} + +do_execsql_test 1.0 { + CREATE TABLE t1(abcd, efgh); +} +faultsim_save_and_close + +set ::TMPDBERROR [list 1 \ + {unable to open a temporary database file for storing temporary tables} +] + + +do_faultsim_test 1 -prep { + faultsim_restore_and_reopen +} -body { + execsql { + ALTER TABLE t1 RENAME abcd TO dcba + } +} -test { + faultsim_test_result {0 {}} $::TMPDBERROR +} + +catch {db close} +forcedelete test.db +sqlite3 db test.db +do_execsql_test 2.0 { + PRAGMA encoding = 'utf-16'; + CREATE TABLE t1(abcd, efgh); +} +faultsim_save_and_close + +do_faultsim_test 2 -prep { + faultsim_restore_and_reopen +} -body { + execsql { + ALTER TABLE t1 RENAME abcd TO dcba + } +} -test { + faultsim_test_result {0 {}} $::TMPDBERROR +} + + +reset_db +do_execsql_test 3.0 { + CREATE TABLE t1(abcd, efgh); + CREATE VIEW v1 AS SELECT * FROM t1 WHERE abcd>efgh; +} +faultsim_save_and_close + +do_faultsim_test 3 -prep { + faultsim_restore_and_reopen +} -body { + execsql { + ALTER TABLE t1 RENAME abcd TO dcba + } +} -test { + faultsim_test_result {0 {}} $::TMPDBERROR +} + +reset_db +do_execsql_test 4.0 { + CREATE TABLE rr(a, b); + CREATE VIEW vv AS SELECT * FROM rr; + + CREATE TRIGGER vv1 INSTEAD OF INSERT ON vv BEGIN + SELECT 1, 2, 3; + END; + CREATE TRIGGER tr1 AFTER INSERT ON rr BEGIN + INSERT INTO vv VALUES(new.a, new.b); + END; +} {} + +faultsim_save_and_close +do_faultsim_test 4 -faults oom-* -prep { + faultsim_restore_and_reopen + execsql { SELECT * FROM sqlite_master } +} -body { + execsql { + ALTER TABLE rr RENAME a TO c; + } +} -test { + faultsim_test_result {0 {}} $::TMPDBERROR +} + +reset_db +do_execsql_test 5.0 { + CREATE TABLE rr(a, b); + CREATE VIEW vv AS SELECT * FROM ( + WITH abc(d, e) AS (SELECT * FROM rr) + SELECT * FROM abc + ); +} {} + +faultsim_save_and_close +do_faultsim_test 5 -faults oom-* -prep { + faultsim_restore_and_reopen + execsql { SELECT * FROM sqlite_master } +} -body { + execsql { + ALTER TABLE rr RENAME TO c; + } +} -test { + faultsim_test_result {0 {}} $::TMPDBERROR +} + +finish_test diff --git a/test/altermalloc3.test b/test/altermalloc3.test new file mode 100644 index 0000000..47efebe --- /dev/null +++ b/test/altermalloc3.test @@ -0,0 +1,90 @@ +# 2021 February 18 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/malloc_common.tcl +set testprefix altermalloc3 + +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. +ifcapable !altertable { + finish_test + return +} + + +set ::TMPDBERROR [list 1 \ + {unable to open a temporary database file for storing temporary tables} +] + +sqlite3_db_config db SQLITE_DBCONFIG_DQS_DDL 1 +do_execsql_test 1.0 { + CREATE TABLE x1( + one, two, three, PRIMARY KEY(one), + CHECK (three!="xyz"), CHECK (two!="one") + ) WITHOUT ROWID; + CREATE INDEX x1i ON x1(one+"two"+"four") WHERE "five"; + CREATE TEMP TRIGGER AFTER INSERT ON x1 BEGIN + UPDATE x1 SET two=new.three || "new" WHERE one=new.one||""; + END; + CREATE TABLE t1(a, b, c, d, PRIMARY KEY(d, b)) WITHOUT ROWID; + INSERT INTO t1 VALUES(1, 2, 3, 4); +} +faultsim_save_and_close + +do_faultsim_test 1 -prep { + faultsim_restore_and_reopen +} -body { + execsql { ALTER TABLE t1 DROP COLUMN c } +} -test { + faultsim_test_result {0 {}} $::TMPDBERROR +} + + +#------------------------------------------------------------------------- +# dbsqlfuzz e3dd84cda3848016a6a6024c7249d09bc2ef2615 +# +reset_db +do_execsql_test 2.0 { + CREATE TABLE t2(k,v); + CREATE TRIGGER r2 AFTER INSERT ON t2 BEGIN + UPDATE t2 SET (k,v)= ( + (WITH cte1(a) AS ( SELECT 1 FROM ( SELECT * FROM t2 ) ) + SELECT a FROM cte1 + ), 1); + END; + + CREATE TRIGGER r1 AFTER INSERT ON t2 BEGIN + UPDATE t2 SET k=1 FROM t2 AS one, t2 AS two NATURAL JOIN t2 AS three + WHERE one.k=two.v; + END; +} + +faultsim_save_and_close +faultsim_restore_and_reopen + +do_execsql_test 2.1 { + ALTER TABLE t2 RENAME TO t2x; +} + +do_faultsim_test 2.2 -prep { + faultsim_restore_and_reopen + db eval { SELECT * FROM sqlite_master } +} -body { + execsql { + ALTER TABLE t2 RENAME TO t2x; + } +} -test { + faultsim_test_result {0 {}} $::TMPDBERROR +} + +finish_test diff --git a/test/alterqf.test b/test/alterqf.test new file mode 100644 index 0000000..b248c7c --- /dev/null +++ b/test/alterqf.test @@ -0,0 +1,120 @@ +# 2021 March 16 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. This +# script focuses on testing internal function sqlite_rename_quotefix(). +# + + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix alterqf + +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. +ifcapable !altertable { + finish_test + return +} + + +sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db +sqlite3_db_config db SQLITE_DBCONFIG_DQS_DDL 1 +sqlite3_db_config db SQLITE_DBCONFIG_DQS_DML 1 + +do_execsql_test 1.0 { + CREATE TABLE t1(a, b, c); +} + +foreach {tn before after} { + 1 {CREATE VIEW v1 AS SELECT "a", "b", "notacolumn!", "c" FROM t1} + {CREATE VIEW v1 AS SELECT "a", "b", 'notacolumn!', "c" FROM t1} + + 2 {CREATE VIEW v1 AS SELECT "a", "b", "not'a'column!", "c" FROM t1} + {CREATE VIEW v1 AS SELECT "a", "b", 'not''a''column!', "c" FROM t1} + + 3 {CREATE VIEW v1 AS SELECT "a", "b", "not""a""column!", "c" FROM t1} + {CREATE VIEW v1 AS SELECT "a", "b", 'not"a"column!', "c" FROM t1} + + 4 {CREATE VIEW v1 AS SELECT "val", count("b") FROM t1 GROUP BY "abc"} + {CREATE VIEW v1 AS SELECT 'val', count("b") FROM t1 GROUP BY 'abc'} + + 5 {CREATE TABLE xyz(a CHECK (a!="str"), b AS (a||"str"))} + {CREATE TABLE xyz(a CHECK (a!='str'), b AS (a||'str'))} + + 6 {CREATE INDEX i1 ON t1(a || "str", "b", "val")} + {CREATE INDEX i1 ON t1(a || 'str', "b", 'val')} + + 7 {CREATE TRIGGER tr AFTER INSERT ON t1 BEGIN SELECT "abcd"; END} + {CREATE TRIGGER tr AFTER INSERT ON t1 BEGIN SELECT 'abcd'; END} + + 8 {CREATE VIEW v1 AS SELECT "string"'alias' FROM t1} + {CREATE VIEW v1 AS SELECT 'string' 'alias' FROM t1} + + 9 {CREATE INDEX i1 ON t1(a) WHERE "b"="bb"} + {CREATE INDEX i1 ON t1(a) WHERE "b"='bb'} + + 10 {CREATE TABLE t2(abc, xyz CHECK (xyz != "123"))} + {CREATE TABLE t2(abc, xyz CHECK (xyz != '123'))} + + 11 {CREATE TRIGGER ott AFTER UPDATE ON t1 BEGIN + SELECT max("str", new."a") FROM t1 + WHERE string_agg("b", ",") OVER (ORDER BY c||"str"); + UPDATE t1 SET c= b + "str"; + DELETE FROM t1 WHERE EXISTS ( + SELECT 1 FROM t1 AS o WHERE o."a" = "o.a" AND t1.b IN("t1.b") + ); + END; + } {CREATE TRIGGER ott AFTER UPDATE ON t1 BEGIN + SELECT max('str', new."a") FROM t1 + WHERE string_agg("b", ',') OVER (ORDER BY c||'str'); + UPDATE t1 SET c= b + 'str'; + DELETE FROM t1 WHERE EXISTS ( + SELECT 1 FROM t1 AS o WHERE o."a" = 'o.a' AND t1.b IN('t1.b') + ); + END; + } + +} { + do_execsql_test 1.$tn { + SELECT sqlite_rename_quotefix('main', $before) + } [list $after] +} + +#------------------------------------------------------------------------- +reset_db +sqlite3_db_config db SQLITE_DBCONFIG_DQS_DDL 1 +sqlite3_db_config db SQLITE_DBCONFIG_DQS_DML 1 +do_execsql_test 2.0 { + CREATE TABLE x1( + one, two, three, PRIMARY KEY(one), + CHECK (three!="xyz"), CHECK (two!="one") + ) WITHOUT ROWID; + CREATE INDEX x1i ON x1(one+"two"+"four") WHERE "five"; + CREATE TEMP TRIGGER AFTER INSERT ON x1 BEGIN + UPDATE x1 SET two=new.three || "new" WHERE one=new.one||""; + END; +} + +do_execsql_test 2.1 { + ALTER TABLE x1 RENAME two TO 'four'; + SELECT sql FROM sqlite_schema; + SELECT sql FROM sqlite_temp_schema; +} {{CREATE TABLE x1( + one, "four", three, PRIMARY KEY(one), + CHECK (three!='xyz'), CHECK ("four"!="one") + ) WITHOUT ROWID} + {CREATE INDEX x1i ON x1(one+"four"+'four') WHERE 'five'} + {CREATE TRIGGER AFTER INSERT ON x1 BEGIN + UPDATE x1 SET "four"=new.three || 'new' WHERE one=new.one||''; + END} +} + + +finish_test diff --git a/test/altertab.test b/test/altertab.test new file mode 100644 index 0000000..9cc43e1 --- /dev/null +++ b/test/altertab.test @@ -0,0 +1,1002 @@ +# 2018 August 24 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix altertab + +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. +ifcapable !altertable { + finish_test + return +} + +do_execsql_test 1.0 { + CREATE TABLE t1(a, b, CHECK(t1.a != t1.b)); + + CREATE TABLE t2(a, b); + CREATE INDEX t2expr ON t2(a) WHERE t2.b>0; +} + +do_execsql_test 1.1 { + SELECT sql FROM sqlite_master +} { + {CREATE TABLE t1(a, b, CHECK(t1.a != t1.b))} + {CREATE TABLE t2(a, b)} + {CREATE INDEX t2expr ON t2(a) WHERE t2.b>0} +} + +do_execsql_test 1.2 { + ALTER TABLE t1 RENAME TO t1new; +} + +do_execsql_test 1.3 { + CREATE TABLE t3(c, d); + ALTER TABLE t3 RENAME TO t3new; + DROP TABLE t3new; +} + +do_execsql_test 1.4 { + SELECT sql FROM sqlite_master +} { + {CREATE TABLE "t1new"(a, b, CHECK("t1new".a != "t1new".b))} + {CREATE TABLE t2(a, b)} + {CREATE INDEX t2expr ON t2(a) WHERE t2.b>0} +} + + +do_execsql_test 1.3 { + ALTER TABLE t2 RENAME TO t2new; +} +do_execsql_test 1.4 { + SELECT sql FROM sqlite_master +} { + {CREATE TABLE "t1new"(a, b, CHECK("t1new".a != "t1new".b))} + {CREATE TABLE "t2new"(a, b)} + {CREATE INDEX t2expr ON "t2new"(a) WHERE "t2new".b>0} +} + + +#------------------------------------------------------------------------- +reset_db +ifcapable vtab { + register_echo_module db + + do_execsql_test 2.0 { + CREATE TABLE abc(a, b, c); + INSERT INTO abc VALUES(1, 2, 3); + CREATE VIRTUAL TABLE eee USING echo('abc'); + SELECT * FROM eee; + } {1 2 3} + + do_execsql_test 2.1 { + ALTER TABLE eee RENAME TO fff; + SELECT * FROM fff; + } {1 2 3} + + db close + sqlite3 db test.db + + do_catchsql_test 2.2 { + ALTER TABLE fff RENAME TO ggg; + } {1 {no such module: echo}} +} + +#------------------------------------------------------------------------- +reset_db + +do_execsql_test 3.0 { + CREATE TABLE txx(a, b, c); + INSERT INTO txx VALUES(1, 2, 3); + CREATE VIEW vvv AS SELECT main.txx.a, txx.b, c FROM txx; + CREATE VIEW uuu AS SELECT main.one.a, one.b, c FROM txx AS one; + CREATE VIEW temp.ttt AS SELECT main.txx.a, txx.b, one.b, main.one.a FROM txx AS one, txx; +} + +do_execsql_test 3.1.1 { + SELECT * FROM vvv; +} {1 2 3} +do_execsql_test 3.1.2 { + ALTER TABLE txx RENAME TO "t xx"; + SELECT * FROM vvv; +} {1 2 3} +do_execsql_test 3.1.3 { + SELECT sql FROM sqlite_master WHERE name='vvv'; +} {{CREATE VIEW vvv AS SELECT main."t xx".a, "t xx".b, c FROM "t xx"}} + + +do_execsql_test 3.2.1 { + SELECT * FROM uuu; +} {1 2 3} +do_execsql_test 3.2.2 { + SELECT sql FROM sqlite_master WHERE name='uuu';; +} {{CREATE VIEW uuu AS SELECT main.one.a, one.b, c FROM "t xx" AS one}} + +do_execsql_test 3.3.1 { + SELECT * FROM ttt; +} {1 2 2 1} +do_execsql_test 3.3.2 { + SELECT sql FROM sqlite_temp_master WHERE name='ttt'; +} {{CREATE VIEW ttt AS SELECT main."t xx".a, "t xx".b, one.b, main.one.a FROM "t xx" AS one, "t xx"}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 4.0 { + CREATE table t1(x, y); + CREATE table t2(a, b); + + CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN + SELECT t1.x, * FROM t1, t2; + INSERT INTO t2 VALUES(new.x, new.y); + END; +} + +do_execsql_test 4.1 { + INSERT INTO t1 VALUES(1, 1); + ALTER TABLE t1 RENAME TO t11; + INSERT INTO t11 VALUES(2, 2); + ALTER TABLE t2 RENAME TO t22; + INSERT INTO t11 VALUES(3, 3); +} + +proc squish {a} { + string trim [regsub -all {[[:space:]][[:space:]]*} $a { }] +} +db func squish squish +do_test 4.2 { + execsql { SELECT squish(sql) FROM sqlite_master WHERE name = 'tr1' } +} [list [squish { + CREATE TRIGGER tr1 AFTER INSERT ON "t11" BEGIN + SELECT "t11".x, * FROM "t11", "t22"; + INSERT INTO "t22" VALUES(new.x, new.y); + END +}]] + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 5.0 { + CREATE TABLE t9(a, b, c); + CREATE TABLE t10(a, b, c); + CREATE TEMP TABLE t9(a, b, c); + + CREATE TRIGGER temp.t9t AFTER INSERT ON temp.t9 BEGIN + INSERT INTO t10 VALUES(new.a, new.b, new.c); + END; + + INSERT INTO temp.t9 VALUES(1, 2, 3); + SELECT * FROM t10; +} {1 2 3} + +do_execsql_test 5.1 { + ALTER TABLE temp.t9 RENAME TO 't1234567890' +} + +do_execsql_test 5.2 { + CREATE TABLE t1(a, b); + CREATE TABLE t2(a, b); + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t2 VALUES(3, 4); + CREATE VIEW v AS SELECT one.a, one.b, t2.a, t2.b FROM t1 AS one, t2; + SELECT * FROM v; +} {1 2 3 4} + +do_catchsql_test 5.3 { + ALTER TABLE t2 RENAME TO one; +} {1 {error in view v after rename: ambiguous column name: one.a}} + +do_execsql_test 5.4 { + SELECT * FROM v +} {1 2 3 4} + +do_execsql_test 5.5 { + DROP VIEW v; + CREATE VIEW temp.vv AS SELECT one.a, one.b, t2.a, t2.b FROM t1 AS one, t2; + SELECT * FROM vv; +} {1 2 3 4} + +do_catchsql_test 5.6 { + ALTER TABLE t2 RENAME TO one; +} {1 {error in view vv after rename: ambiguous column name: one.a}} + +#------------------------------------------------------------------------- + +ifcapable vtab { + register_tcl_module db + proc tcl_command {method args} { + switch -- $method { + xConnect { + return "CREATE TABLE t1(a, b, c)" + } + } + return {} + } + + do_execsql_test 6.0 { + CREATE VIRTUAL TABLE x1 USING tcl(tcl_command); + } + + do_execsql_test 6.1 { + ALTER TABLE x1 RENAME TO x2; + SELECT sql FROM sqlite_master WHERE name = 'x2' + } {{CREATE VIRTUAL TABLE "x2" USING tcl(tcl_command)}} + + do_execsql_test 7.1 { + CREATE TABLE ddd(db, sql, zOld, zNew, bTemp); + INSERT INTO ddd VALUES( + 'main', 'CREATE TABLE x1(i INTEGER, t TEXT)', 'ddd', NULL, 0 + ), ( + 'main', 'CREATE TABLE x1(i INTEGER, t TEXT)', NULL, 'eee', 0 + ), ( + 'main', NULL, 'ddd', 'eee', 0 + ); + } {} + + sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db + do_execsql_test 7.2 { + SELECT + sqlite_rename_table(db, 0, 0, sql, zOld, zNew, bTemp) + FROM ddd; + } {{} {} {}} + sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db +} + +#------------------------------------------------------------------------- +# +reset_db +forcedelete test.db2 +do_execsql_test 8.1 { + ATTACH 'test.db2' AS aux; + PRAGMA foreign_keys = on; + CREATE TABLE aux.p1(a INTEGER PRIMARY KEY, b); + CREATE TABLE aux.c1(x INTEGER PRIMARY KEY, y REFERENCES p1(a)); + INSERT INTO aux.p1 VALUES(1, 1); + INSERT INTO aux.p1 VALUES(2, 2); + INSERT INTO aux.c1 VALUES(NULL, 2); + CREATE TABLE aux.c2(x INTEGER PRIMARY KEY, y REFERENCES c1(a)); +} + +do_execsql_test 8.2 { + ALTER TABLE aux.p1 RENAME TO ppp; +} + +do_execsql_test 8.2 { + INSERT INTO aux.c1 VALUES(NULL, 1); + SELECT sql FROM aux.sqlite_master WHERE name = 'c1'; +} {{CREATE TABLE c1(x INTEGER PRIMARY KEY, y REFERENCES "ppp"(a))}} + +reset_db +do_execsql_test 9.0 { + CREATE TABLE t1(a, b, c); + CREATE VIEW v1 AS SELECT * FROM t2; +} +do_catchsql_test 9.1 { + ALTER TABLE t1 RENAME TO t3; +} {1 {error in view v1: no such table: main.t2}} +do_execsql_test 9.2 { + DROP VIEW v1; + CREATE TRIGGER tr AFTER INSERT ON t1 BEGIN + INSERT INTO t2 VALUES(new.a); + END; +} +do_catchsql_test 9.3 { + ALTER TABLE t1 RENAME TO t3; +} {1 {error in trigger tr: no such table: main.t2}} + +forcedelete test.db2 +do_execsql_test 9.4 { + DROP TRIGGER tr; + + ATTACH 'test.db2' AS aux; + CREATE TRIGGER tr AFTER INSERT ON t1 WHEN new.a IS NULL BEGIN SELECT 1, 2, 3; END; + + CREATE TABLE aux.t1(x); + CREATE TEMP TRIGGER tr AFTER INSERT ON aux.t1 BEGIN SELECT 1, 2, 3; END; +} +do_execsql_test 9.5 { + ALTER TABLE main.t1 RENAME TO t3; +} +do_execsql_test 9.6 { + SELECT sql FROM sqlite_temp_master; + SELECT sql FROM sqlite_master WHERE type='trigger'; +} { + {CREATE TRIGGER tr AFTER INSERT ON aux.t1 BEGIN SELECT 1, 2, 3; END} + {CREATE TRIGGER tr AFTER INSERT ON "t3" WHEN new.a IS NULL BEGIN SELECT 1, 2, 3; END} +} + +#------------------------------------------------------------------------- +reset_db +ifcapable fts5 { + do_execsql_test 10.0 { + CREATE VIRTUAL TABLE fff USING fts5(x, y, z); + } + + do_execsql_test 10.1 { + BEGIN; + INSERT INTO fff VALUES('a', 'b', 'c'); + ALTER TABLE fff RENAME TO ggg; + COMMIT; + } + + do_execsql_test 10.2 { + SELECT * FROM ggg; + } {a b c} +} + +#------------------------------------------------------------------------- +reset_db +forcedelete test.db2 +db func trigger trigger +set ::trigger [list] +proc trigger {args} { + lappend ::trigger $args +} +do_execsql_test 11.0 { + ATTACH 'test.db2' AS aux; + CREATE TABLE aux.t1(a, b, c); + CREATE TABLE main.t1(a, b, c); + CREATE TEMP TRIGGER tr AFTER INSERT ON aux.t1 BEGIN + SELECT trigger(new.a, new.b, new.c); + END; +} + +do_execsql_test 11.1 { + INSERT INTO main.t1 VALUES(1, 2, 3); + INSERT INTO aux.t1 VALUES(4, 5, 6); +} +do_test 11.2 { set ::trigger } {{4 5 6}} + +do_execsql_test 11.3 { + SELECT name, tbl_name FROM sqlite_temp_master; +} {tr t1} + +do_execsql_test 11.4 { + ALTER TABLE main.t1 RENAME TO t2; + SELECT name, tbl_name FROM sqlite_temp_master; +} {tr t1} + +do_execsql_test 11.5 { + ALTER TABLE aux.t1 RENAME TO t2; + SELECT name, tbl_name FROM sqlite_temp_master; +} {tr t2} + +do_execsql_test 11.6 { + INSERT INTO aux.t2 VALUES(7, 8, 9); +} +do_test 11.7 { set ::trigger } {{4 5 6} {7 8 9}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 12.0 { + CREATE TABLE t1(a); + CREATE TABLE t2(w); + CREATE TRIGGER temp.r1 AFTER INSERT ON main.t2 BEGIN + INSERT INTO t1(a) VALUES(new.w); + END; + CREATE TEMP TABLE t2(x); +} + +do_execsql_test 12.1 { + ALTER TABLE main.t2 RENAME TO t3; +} + +do_execsql_test 12.2 { + INSERT INTO t3 VALUES('WWW'); + SELECT * FROM t1; +} {WWW} + + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 13.0 { + CREATE TABLE t1(x, y); + CREATE TABLE t2(a, b); + CREATE TABLE log(c); + CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN + INSERT INTO log SELECT y FROM t1, t2; + END; +} + +do_execsql_test 13.1 { + INSERT INTO t1 VALUES(1, 2); +} + +do_catchsql_test 13.2 { + ALTER TABLE t2 RENAME b TO y; +} {1 {error in trigger tr1 after rename: ambiguous column name: y}} + +#------------------------------------------------------------------------- +reset_db + +ifcapable rtree { + do_execsql_test 14.0 { + CREATE VIRTUAL TABLE rt USING rtree(id, minx, maxx, miny, maxy); + + CREATE TABLE "mytable" ( "fid" INTEGER PRIMARY KEY, "geom" BLOB); + + CREATE TRIGGER tr1 AFTER UPDATE OF "geom" ON "mytable" + WHEN OLD."fid" = NEW."fid" AND NEW."geom" IS NULL BEGIN + DELETE FROM rt WHERE id = OLD."fid"; + END; + + INSERT INTO mytable VALUES(1, X'abcd'); + } + + do_execsql_test 14.1 { + UPDATE mytable SET geom = X'1234' + } + + do_execsql_test 14.2 { + ALTER TABLE mytable RENAME TO mytable_renamed; + } + + do_execsql_test 14.3 { + CREATE TRIGGER tr2 AFTER INSERT ON mytable_renamed BEGIN + DELETE FROM rt WHERE id=(SELECT min(id) FROM rt); + END; + } + + do_execsql_test 14.4 { + ALTER TABLE mytable_renamed RENAME TO mytable2; + } +} + +reset_db +do_execsql_test 14.5 { + CREATE TABLE t1(a, b, c); + CREATE VIEW v1 AS SELECT * FROM t1; + CREATE TRIGGER xyz AFTER INSERT ON t1 BEGIN + SELECT a, b FROM v1; + END; +} +do_execsql_test 14.6 { + ALTER TABLE t1 RENAME TO tt1; +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 15.0 { + CREATE TABLE t1(a integer NOT NULL PRIMARY KEY); + CREATE VIEW v1 AS SELECT a FROM t1; + CREATE TRIGGER tr1 INSTEAD OF INSERT ON v1 BEGIN + UPDATE t1 SET a = NEW.a; + END; + CREATE TRIGGER tr2 INSTEAD OF INSERT ON v1 BEGIN + SELECT new.a; + END; + CREATE TABLE t2 (b); +} + +do_execsql_test 15.1 { + INSERT INTO v1 VALUES(1); + ALTER TABLE t2 RENAME TO t3; +} + +do_execsql_test 15.2 { + CREATE TABLE x(f1 integer NOT NULL); + CREATE VIEW y AS SELECT f1 AS f1 FROM x; + CREATE TRIGGER t INSTEAD OF UPDATE OF f1 ON y BEGIN + UPDATE x SET f1 = NEW.f1; + END; + CREATE TABLE z (f1 integer NOT NULL PRIMARY KEY); + ALTER TABLE z RENAME TO z2; +} + +do_execsql_test 15.3 { + INSERT INTO x VALUES(1), (2), (3); + ALTER TABLE x RENAME f1 TO f2; + SELECT * FROM x; +} {1 2 3} + +do_execsql_test 15.4 { + UPDATE y SET f1 = 'x' WHERE f1 = 1; + SELECT * FROM x; +} {x x x} + +do_execsql_test 15.5 { + SELECT sql FROM sqlite_master WHERE name = 'y'; +} {{CREATE VIEW y AS SELECT f2 AS f1 FROM x}} + +#------------------------------------------------------------------------- +# Test that it is not possible to rename a shadow table in DEFENSIVE mode. +# +ifcapable fts3 { + proc vtab_command {method args} { + switch -- $method { + xConnect { + if {[info exists ::vtab_connect_sql]} { + execsql $::vtab_connect_sql + } + return "CREATE TABLE t1(a, b, c)" + } + + xBestIndex { + set clist [lindex $args 0] + if {[llength $clist]!=1} { error "unexpected constraint list" } + catch { array unset C } + array set C [lindex $clist 0] + if {$C(usable)} { + return "omit 0 cost 0 rows 1 idxnum 555 idxstr eq!" + } else { + return "cost 1000000 rows 0 idxnum 0 idxstr scan..." + } + } + } + + return {} + } + + register_tcl_module db + + sqlite3_db_config db DEFENSIVE 1 + + do_execsql_test 16.0 { + CREATE VIRTUAL TABLE y1 USING fts3; + VACUUM; + } + + do_catchsql_test 16.10 { + INSERT INTO y1_segments VALUES(1, X'1234567890'); + } {1 {table y1_segments may not be modified}} + + do_catchsql_test 16.20 { + DROP TABLE y1_segments; + } {1 {table y1_segments may not be dropped}} + + do_catchsql_test 16.20 { + ALTER TABLE y1_segments RENAME TO abc; + } {1 {table y1_segments may not be altered}} + sqlite3_db_config db DEFENSIVE 0 + do_catchsql_test 16.22 { + ALTER TABLE y1_segments RENAME TO abc; + } {0 {}} + sqlite3_db_config db DEFENSIVE 1 + do_catchsql_test 16.23 { + CREATE TABLE y1_segments AS SELECT * FROM abc; + } {1 {object name reserved for internal use: y1_segments}} + do_catchsql_test 16.24 { + CREATE VIEW y1_segments AS SELECT * FROM abc; + } {1 {object name reserved for internal use: y1_segments}} + sqlite3_db_config db DEFENSIVE 0 + do_catchsql_test 16.25 { + ALTER TABLE abc RENAME TO y1_segments; + } {0 {}} + sqlite3_db_config db DEFENSIVE 1 + + do_execsql_test 16.30 { + ALTER TABLE y1 RENAME TO z1; + } + + do_execsql_test 16.40 { + SELECT * FROM z1_segments; + } +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 17.0 { + CREATE TABLE sqlite1234 (id integer); + ALTER TABLE sqlite1234 RENAME TO User; + SELECT name, sql FROM sqlite_master WHERE sql IS NOT NULL; +} { + User {CREATE TABLE "User" (id integer)} +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 18.1.0 { + CREATE TABLE t0 (c0 INTEGER, PRIMARY KEY(c0)) WITHOUT ROWID; +} +do_execsql_test 18.1.1 { + ALTER TABLE t0 RENAME COLUMN c0 TO c1; +} +do_execsql_test 18.1.2 { + SELECT sql FROM sqlite_master; +} {{CREATE TABLE t0 (c1 INTEGER, PRIMARY KEY(c1)) WITHOUT ROWID}} + +reset_db +do_execsql_test 18.2.0 { + CREATE TABLE t0 (c0 INTEGER, PRIMARY KEY(c0)); +} +do_execsql_test 18.2.1 { + ALTER TABLE t0 RENAME COLUMN c0 TO c1; +} +do_execsql_test 18.2.2 { + SELECT sql FROM sqlite_master; +} {{CREATE TABLE t0 (c1 INTEGER, PRIMARY KEY(c1))}} + +# 2020-02-23 ticket f50af3e8a565776b +reset_db +do_execsql_test 19.100 { + CREATE TABLE t1(x); + CREATE VIEW t2 AS SELECT 1 FROM t1, (t1 AS a0, t1); + ALTER TABLE t1 RENAME TO t3; + SELECT sql FROM sqlite_master; +} {{CREATE TABLE "t3"(x)} {CREATE VIEW t2 AS SELECT 1 FROM "t3", ("t3" AS a0, "t3")}} +do_execsql_test 19.110 { + INSERT INTO t3(x) VALUES(123); + SELECT * FROM t2; +} {1} +do_execsql_test 19.120 { + INSERT INTO t3(x) VALUES('xyz'); + SELECT * FROM t2; +} {1 1 1 1 1 1 1 1} + +# Ticket 4722bdab08cb14 +reset_db +do_execsql_test 20.0 { + CREATE TABLE a(a); + CREATE VIEW b AS SELECT(SELECT *FROM c JOIN a USING(d, a, a, a) JOIN a) IN(); +} +do_execsql_test 20.1 { + ALTER TABLE a RENAME a TO e; +} {} + +reset_db +do_execsql_test 21.0 { + CREATE TABLE a(b); + CREATE VIEW c AS + SELECT NULL INTERSECT + SELECT NULL ORDER BY + likelihood(NULL, (d, (SELECT c))); +} {} +do_catchsql_test 21.1 { + SELECT likelihood(NULL, (d, (SELECT c))); +} {1 {second argument to likelihood() must be a constant between 0.0 and 1.0}} +do_catchsql_test 21.2 { + SELECT * FROM c; +} {1 {1st ORDER BY term does not match any column in the result set}} + +do_catchsql_test 21.3 { + ALTER TABLE a RENAME TO e; +} {1 {error in view c: 1st ORDER BY term does not match any column in the result set}} + +# After forum thread https://sqlite.org/forum/forumpost/ddbe1c7efa +# Ensure that PRAGMA schema_version=N causes a full schema reload. +# +reset_db +do_execsql_test 22.0 { + CREATE TABLE t1(a INT, b TEXT NOT NULL); + INSERT INTO t1 VALUES(1,2),('a','b'); + BEGIN; + PRAGMA writable_schema=ON; + UPDATE sqlite_schema SET sql='CREATE TABLE t1(a INT, b TEXT)' WHERE name LIKE 't1'; + PRAGMA schema_version=1234; + COMMIT; + PRAGMA integrity_check; +} {ok} +do_execsql_test 22.1 { + ALTER TABLE t1 ADD COLUMN c INT DEFAULT 78; + SELECT * FROM t1; +} {1 2 78 a b 78} + +#------------------------------------------------------------------------- +reset_db +db collate compare64 compare64 + +do_execsql_test 23.1 { + CREATE TABLE gigo(a text); + CREATE TABLE idx(x text COLLATE compare64); + CREATE VIEW v1 AS SELECT * FROM idx WHERE x='abc'; +} +db close +sqlite3 db test.db + +do_execsql_test 23.2 { + alter table gigo rename to ggiiggoo; + alter table idx rename to idx2; +} + +do_execsql_test 23.3 { + SELECT sql FROM sqlite_master; +} { + {CREATE TABLE "ggiiggoo"(a text)} + {CREATE TABLE "idx2"(x text COLLATE compare64)} + {CREATE VIEW v1 AS SELECT * FROM "idx2" WHERE x='abc'} +} + +do_execsql_test 23.4 { + ALTER TABLE idx2 RENAME x TO y; + SELECT sql FROM sqlite_master; +} { + {CREATE TABLE "ggiiggoo"(a text)} + {CREATE TABLE "idx2"(y text COLLATE compare64)} + {CREATE VIEW v1 AS SELECT * FROM "idx2" WHERE y='abc'} +} + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 24.1.0 { + CREATE TABLE t1(a, b); + CREATE TRIGGER AFTER INSERT ON t1 BEGIN + INSERT INTO nosuchtable VALUES(new.a) ON CONFLICT(a) DO NOTHING; + END; +} +do_catchsql_test 24.1.1 { + ALTER TABLE t1 RENAME TO t2; +} {1 {error in trigger AFTER: no such table: main.nosuchtable}} + +reset_db +do_execsql_test 24.2.0 { + CREATE TABLE t1(a, b); + CREATE TRIGGER AFTER INSERT ON t1 BEGIN + INSERT INTO v1 VALUES(new.a) ON CONFLICT(a) DO NOTHING; + END; + CREATE VIEW v1 AS SELECT * FROM nosuchtable; +} +do_catchsql_test 24.2.1 { + ALTER TABLE t1 RENAME TO t2; +} {1 {error in trigger AFTER: no such table: main.nosuchtable}} + +#-------------------------------------------------------------------------- +# +reset_db +do_execsql_test 25.1 { + CREATE TABLE xx(x); + CREATE VIEW v3(b) AS WITH b AS (SELECT b FROM (SELECT * FROM t2)) VALUES(1); +} + +ifcapable json1&&vtab { + do_catchsql_test 25.2 { + ALTER TABLE json_each RENAME TO t4; + } {1 {table json_each may not be altered}} +} + +# 2021-05-01 dbsqlfuzz bc17a306a09329bba0ecc61547077f6178bcf321 +# Remove a NEVER() inserted on 2019-12-09 that is reachable after all. +# +reset_db +do_execsql_test 26.1 { + CREATE TABLE t1(k,v); + CREATE TABLE t2_a(k,v); + CREATE VIEW t2 AS SELECT * FROM t2_a; + CREATE TRIGGER r2 AFTER INSERT ON t1 BEGIN + UPDATE t1 + SET (k,v)=((WITH cte1(a) AS (SELECT 1 FROM t2) SELECT t2.k FROM t2, cte1),1); + END; + ALTER TABLE t1 RENAME TO t1x; + INSERT INTO t2_a VALUES(2,3); + INSERT INTO t1x VALUES(98,99); + SELECT * FROM t1x; +} {2 1} + +#------------------------------------------------------------------------- +reset_db + +do_execsql_test 27.1 { + + create table t_sa ( + c_muyat INTEGER NOT NULL, + c_d4u TEXT + ); + + create table t2 ( abc ); + + CREATE TRIGGER trig AFTER DELETE ON t_sa + BEGIN + DELETE FROM t_sa WHERE ( + SELECT 123 FROM t2 + WINDOW oamat7fzf AS ( PARTITION BY t_sa.c_d4u ) + ); + END; +} + +do_execsql_test 27.2 { + alter table t_sa rename column c_muyat to c_dg; +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 29.1 { + CREATE TABLE t1(a, b, c); + INSERT INTO t1 VALUES('a', 'b', 'c'); + + CREATE VIEW v0 AS + WITH p AS ( SELECT 1 FROM t1 ), + g AS ( SELECT 1 FROM p, t1 ) + SELECT 1 FROM g; +} + +do_execsql_test 29.2 { + SELECT * FROM v0 +} 1 + +do_execsql_test 29.2 { + ALTER TABLE t1 RENAME TO t2 +} + +do_execsql_test 29.3 { + SELECT sql FROM sqlite_schema WHERE name='v0' +} {{CREATE VIEW v0 AS + WITH p AS ( SELECT 1 FROM "t2" ), + g AS ( SELECT 1 FROM p, "t2" ) + SELECT 1 FROM g}} + +do_execsql_test 29.4 { + CREATE VIEW v2 AS + WITH p AS ( SELECT 1 FROM t2 ), + g AS ( SELECT 1 FROM ( + WITH i AS (SELECT 1 FROM p, t2) + SELECT * FROM i + ) + ) + SELECT 1 FROM g; +} + +do_execsql_test 29.4 { + SELECT * FROM v2; +} 1 + +do_execsql_test 29.5 { + ALTER TABLE t2 RENAME TO t3; +} + +do_execsql_test 29.5 { + SELECT sql FROM sqlite_schema WHERE name='v2' +} {{CREATE VIEW v2 AS + WITH p AS ( SELECT 1 FROM "t3" ), + g AS ( SELECT 1 FROM ( + WITH i AS (SELECT 1 FROM p, "t3") + SELECT * FROM i + ) + ) + SELECT 1 FROM g}} + + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 28.1 { + CREATE TABLE t1(a); + CREATE TABLE t2(b,c); + CREATE TABLE t4(b,c); + INSERT INTO t2 VALUES(1,2),(1,3),(2,5); + INSERT INTO t4 VALUES(1,2),(1,3),(2,5); + + CREATE VIEW v3 AS + WITH RECURSIVE t3(x,y,z) AS ( + SELECT b,c,NULL FROM t4 + UNION + SELECT x,y,NULL FROM t3, t2 + ) + SELECT * FROM t3 AS xyz; +} + +do_execsql_test 28.2 { + SELECT * FROM v3 +} { + 1 2 {} 1 3 {} 2 5 {} +} + +do_execsql_test 28.3 { + ALTER TABLE t1 RENAME a TO a2; -- fails in v3 +} + +do_execsql_test 28.4 { + ALTER TABLE t2 RENAME TO t5; +} + +do_execsql_test 28.5 { + SELECT sql FROM sqlite_schema WHERE name='v3' +} {{CREATE VIEW v3 AS + WITH RECURSIVE t3(x,y,z) AS ( + SELECT b,c,NULL FROM t4 + UNION + SELECT x,y,NULL FROM t3, "t5" + ) + SELECT * FROM t3 AS xyz}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 30.0 { + CREATE TABLE t1(a,b,c,d,e,f); + CREATE TABLE t2(a,b,c); + CREATE INDEX t1abc ON t1(a,b,c+d+e); + CREATE VIEW v1(x,y) AS + SELECT t1.b,t2.b FROM t1,t2 WHERE t1.a=t2.a + GROUP BY 1 HAVING t2.c NOT NULL LIMIT 10; + CREATE TRIGGER r1 AFTER INSERT ON t1 WHEN 'no' NOT NULL BEGIN + INSERT INTO t2(a,a,b,c) VALUES(new.b,new.a,new.c-7); + WITH c1(x) AS ( + VALUES(0) + UNION ALL + SELECT current_time+x FROM c1 WHERE x + UNION ALL + SELECT 1+x FROM c1 WHERE x<1 + ), c2(x) AS (VALUES(0),(1)) + SELECT * FROM c1 AS x1, c2 AS x2, ( + SELECT x+1 FROM c1 WHERE x IS NOT TRUE + UNION ALL + SELECT 1+x FROM c1 WHERE 1='d' ORDER BY name; + SELECT new.c; + END; +} + +do_execsql_test 2.1 { + ALTER TABLE t1 RENAME TO t1x; + SELECT sql FROM sqlite_master WHERE name = 'r1'; +} {{CREATE TRIGGER r1 AFTER INSERT ON "t1x" WHEN new.a NOT NULL BEGIN + SELECT a,b, a name FROM "t1x" + INTERSECT + SELECT a,b,c FROM "t1x" WHERE b>='d' ORDER BY name; + SELECT new.c; + END}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 3.0 { + CREATE TABLE t1(a, b, c, d); + CREATE VIEW v1 AS SELECT * FROM t1 WHERE a=1 OR (b IN ()); +} + +do_execsql_test 3.1 { + ALTER TABLE t1 RENAME b TO bbb; +} + +do_execsql_test 3.2 { + SELECT sql FROM sqlite_master WHERE name = 'v1' +} {{CREATE VIEW v1 AS SELECT * FROM t1 WHERE a=1 OR (b IN ())}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 4.0 { + CREATE TABLE t1(a, b); + CREATE TABLE t3(e, f); + CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN + INSERT INTO t2 VALUES(new.a, new.b); + END; +} + +do_catchsql_test 4.1.2 { + BEGIN; + ALTER TABLE t3 RENAME TO t4; +} {1 {error in trigger tr1: no such table: main.t2}} +do_execsql_test 4.1.2 { + COMMIT; +} +do_execsql_test 4.1.3 { + SELECT type, name, tbl_name, sql + FROM sqlite_master WHERE type='table' AND name!='t1'; +} {table t3 t3 {CREATE TABLE t3(e, f)}} + + +do_catchsql_test 4.2.1 { + BEGIN; + ALTER TABLE t3 RENAME e TO eee; +} {1 {error in trigger tr1: no such table: main.t2}} +do_execsql_test 4.2.2 { + COMMIT; +} +do_execsql_test 4.2.3 { + SELECT type, name, tbl_name, sql + FROM sqlite_master WHERE type='table' AND name!='t1'; +} {table t3 t3 {CREATE TABLE t3(e, f)}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 5.0 { + CREATE TABLE t1 ( + c1 integer, c2, PRIMARY KEY(c1 collate rtrim), + UNIQUE(c2) + ) +} +do_execsql_test 5.1 { + ALTER TABLE t1 RENAME c1 TO c3; +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 6.0 { + CREATE TEMPORARY TABLE Table0 ( + Col0 INTEGER, + PRIMARY KEY(Col0 COLLATE RTRIM), + FOREIGN KEY (Col0) REFERENCES Table0 + ); +} + +do_execsql_test 6.1 { + ALTER TABLE Table0 RENAME Col0 TO Col0; +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 7.1.0 { + CREATE TABLE t1(a,b,c); + CREATE TRIGGER AFTER INSERT ON t1 BEGIN + SELECT a, rank() OVER w1 FROM t1 + WINDOW w1 AS (PARTITION BY b, percent_rank() OVER w1); + END; +} + +do_execsql_test 7.1.2 { + ALTER TABLE t1 RENAME TO t1x; + SELECT sql FROM sqlite_master; +} { + {CREATE TABLE "t1x"(a,b,c)} + {CREATE TRIGGER AFTER INSERT ON "t1x" BEGIN + SELECT a, rank() OVER w1 FROM "t1x" + WINDOW w1 AS (PARTITION BY b, percent_rank() OVER w1); + END} +} + +do_execsql_test 7.2.1 { + DROP TRIGGER after; + CREATE TRIGGER AFTER INSERT ON t1x BEGIN + SELECT a, rank() OVER w1 FROM t1x + WINDOW w1 AS (PARTITION BY b, percent_rank() OVER w1 ORDER BY d); + END; +} + +do_catchsql_test 7.2.2 { + ALTER TABLE t1x RENAME TO t1; +} {1 {error in trigger AFTER: no such column: d}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 8.0 { + CREATE TABLE t0(c0); + CREATE INDEX i0 ON t0('1' IN ()); +} +do_execsql_test 8.1 { + ALTER TABLE t0 RENAME TO t1; + SELECT sql FROM sqlite_master; +} { + {CREATE TABLE "t1"(c0)} + {CREATE INDEX i0 ON "t1"('1' IN ())} +} +do_execsql_test 8.2.1 { + CREATE TABLE t2 (c0); + CREATE INDEX i2 ON t2((LIKELIHOOD(c0, 100) IN ())); + ALTER TABLE t2 RENAME COLUMN c0 TO c1; +} +do_execsql_test 8.2.2 { + SELECT sql FROM sqlite_master WHERE tbl_name = 't2'; +} { + {CREATE TABLE t2 (c1)} + {CREATE INDEX i2 ON t2((LIKELIHOOD(c0, 100) IN ()))} +} +do_test 8.2.3 { + sqlite3 db2 test.db + db2 eval { INSERT INTO t2 VALUES (1), (2), (3) } + db close +} {} +db2 close + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 9.1 { + CREATE TABLE t1(a,b,c); + CREATE TRIGGER AFTER INSERT ON t1 WHEN new.a NOT NULL BEGIN + SELECT true WHERE (SELECT a, b FROM (t1)) IN (); + END; +} +do_execsql_test 9.2 { + ALTER TABLE t1 RENAME TO t1x; +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 10.1 { + CREATE TABLE t1(a, b, c); + CREATE TABLE t2(a, b, c); + CREATE VIEW v1 AS SELECT * FROM t1 WHERE ( + SELECT t1.a FROM t1, t2 + ) IN () OR t1.a=5; +} + +do_execsql_test 10.2 { + ALTER TABLE t2 RENAME TO t3; + SELECT sql FROM sqlite_master WHERE name='v1'; +} { + {CREATE VIEW v1 AS SELECT * FROM t1 WHERE ( + SELECT t1.a FROM t1, t2 + ) IN () OR t1.a=5} +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 11.1 { + CREATE TABLE t1( + a,b,c,d,e,f,g,h,j,jj,jjb,k,aa,bb,cc,dd,ee DEFAULT 3.14, + ff DEFAULT('hiccup'),Wg NOD NULL DEFAULT(false) + ); + + CREATE TRIGGER b AFTER INSERT ON t1 WHEN new.a BEGIN + SELECT a, sum() w3 FROM t1 + WINDOW b AS (ORDER BY NOT EXISTS(SELECT 1 FROM abc)); + END; +} + +do_catchsql_test 11.2 { + ALTER TABLE t1 RENAME TO t1x; +} {1 {error in trigger b: no such table: main.abc}} + +do_execsql_test 11.3 { + DROP TRIGGER b; + CREATE TRIGGER b AFTER INSERT ON t1 WHEN new.a BEGIN + SELECT a, sum() w3 FROM t1 + WINDOW b AS (ORDER BY NOT EXISTS(SELECT 1 FROM t1)); + END; +} {} + +do_execsql_test 11.4 { + ALTER TABLE t1 RENAME TO t1x; + SELECT sql FROM sqlite_master WHERE name = 'b'; +} { +{CREATE TRIGGER b AFTER INSERT ON "t1x" WHEN new.a BEGIN + SELECT a, sum() w3 FROM "t1x" + WINDOW b AS (ORDER BY NOT EXISTS(SELECT 1 FROM "t1x")); + END} +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 12.1 { +CREATE TABLE t1(a,b,c,d,e,f,g,h,j,jj,Zjj,k,aQ,bb,cc,dd,ee DEFAULT 3.14, +ff DEFAULT('hiccup'),gg NOD NULL DEFAULT(false)); +CREATE TRIGGER AFTER INSERT ON t1 WHEN new.a NOT NULL BEGIN + +SELECT b () OVER , dense_rank() OVER d, d () OVER w1 +FROM t1 +WINDOW +w1 AS +( w1 ORDER BY d +ROWS BETWEEN 2 NOT IN(SELECT a, sum(d) w2,max(d)OVER FROM t1 +WINDOW +w1 AS +(PARTITION BY d +ROWS BETWEEN '' PRECEDING AND false FOLLOWING), +d AS +(PARTITION BY b ORDER BY d +ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) +) PRECEDING AND 1 FOLLOWING), +w2 AS +(PARTITION BY b ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW), +w3 AS +(PARTITION BY b ORDER BY d +ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) +; +SELECT a, sum(d) w2,max(d)OVER FROM t1 +WINDOW +w1 AS +(PARTITION BY d +ROWS BETWEEN '' PRECEDING AND false FOLLOWING), +d AS +(PARTITION BY b ORDER BY d +ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) +; + +END; +} + +do_execsql_test 12.2 { + ALTER TABLE t1 RENAME TO t1x; +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 13.1 { + CREATE TABLE t1(a); + CREATE TRIGGER r1 INSERT ON t1 BEGIN + SELECT a(*) OVER (ORDER BY (SELECT 1)) FROM t1; + END; +} + +do_execsql_test 13.2 { + ALTER TABLE t1 RENAME TO t1x; +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 14.1 { + CREATE TABLE t1(a); + CREATE TABLE t2(b); + CREATE TRIGGER AFTER INSERT ON t1 BEGIN + SELECT sum() FILTER (WHERE (SELECT sum() FILTER (WHERE 0)) AND a); + END; +} + +do_catchsql_test 14.2 { + ALTER TABLE t1 RENAME TO t1x; +} {1 {error in trigger AFTER: no such column: a}} + +#------------------------------------------------------------------------- +reset_db + +do_execsql_test 16.1 { + CREATE TABLE t1(x); + CREATE TRIGGER AFTER INSERT ON t1 BEGIN + SELECT (WITH t2 AS (WITH t3 AS (SELECT true) + SELECT * FROM t3 ORDER BY true COLLATE nocase) + SELECT 11); + + WITH t4 AS (SELECT * FROM t1) SELECT 33; + END; +} +do_execsql_test 16.2 { + ALTER TABLE t1 RENAME TO t1x; +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 17.1 { + CREATE TABLE t1(a,b,c); + CREATE TRIGGER AFTER INSERT ON t1 WHEN new.a NOT NULL BEGIN + SELECT a () FILTER (WHERE a>0) FROM t1; + END; +} + +do_execsql_test 17.2 { + ALTER TABLE t1 RENAME TO t1x; + ALTER TABLE t1x RENAME a TO aaa; + SELECT sql FROM sqlite_master WHERE type='trigger'; +} { +{CREATE TRIGGER AFTER INSERT ON "t1x" WHEN new.aaa NOT NULL BEGIN + SELECT a () FILTER (WHERE aaa>0) FROM "t1x"; + END} +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 18.1 { + CREATE TABLE t1(a,b); + CREATE TRIGGER r1 AFTER INSERT ON t1 BEGIN + SELECT a, b FROM t1 + INTERSECT SELECT b,a FROM t1 + ORDER BY b IN ( + SELECT a UNION SELECT b + FROM t1 + ORDER BY b COLLATE nocase + ) + ; + END; +} + +do_catchsql_test 18.2 { + SELECT a, b FROM t1 + INTERSECT + SELECT b,a FROM t1 + ORDER BY b IN ( + SELECT a UNION SELECT b + FROM t1 + ORDER BY b COLLATE nocase + ); +} {1 {1st ORDER BY term does not match any column in the result set}} + +do_catchsql_test 18.3 { + ALTER TABLE t1 RENAME TO t1x; +} {1 {error in trigger r1: 1st ORDER BY term does not match any column in the result set}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 19.0 { + CREATE TABLE a(a,h CONSTRAINT a UNIQUE ON CONFLICT FAIL,CONSTRAINT a); +} + +foreach {tn v res} { + 1 { + CREATE VIEW q AS SELECT 123 + + WINDOW x AS ( + RANGE BETWEEN UNBOUNDED PRECEDING AND INDEXED() OVER( + PARTITION BY ( WITH x AS(VALUES(col1)) VALUES(453) ) + ) + FOLLOWING + ) + } {1 {error in view q: no such column: col1}} + + 2 { + CREATE VIEW q AS SELECT + CAST(CAST(CAST(CAST(CAST(CAST(CAST(CAST(CAST(CAST(CAST(RIGHT + AS)AS)AS)AS)AS)AS)AS)AS)AS)AS)AS)WINDOW x AS(RANGE BETWEEN UNBOUNDED + PRECEDING AND INDEXED(*)OVER(PARTITION BY + CROSS,CROSS,NATURAL,sqlite_master(*)OVER a,(WITH a AS(VALUES(LEFT)UNION + VALUES(LEFT)UNION VALUES(LEFT)UNION VALUES(LEFT)UNION VALUES(LEFT)UNION + VALUES(LEFT)UNION VALUES(LEFT))VALUES(LEFT))IN + STORED,LEFT,LEFT,LEFT,LEFT,LEFT,LEFT)*LEFT FOLLOWING)ORDER BY + LEFT,LEFT,LEFT,LEFT,LEFT,LEFT,LEFT,LEFT,LEFT,LEFT,LEFT LIMIT + LEFT,INDEXED(*)OVER(PARTITION BY + CROSS,CROSS,CROSS,LEFT,INDEXED(*)OVER(PARTITION BY + CROSS,CROSS,CROSS),INDEXED(*)OVER(PARTITION BY + LEFT,LEFT,LEFT,LEFT,LEFT,LEFT,LEFT,LEFT,LEFT,LEFT,LEFT), + LEFT,LEFT,INNER,CROSS,CROSS,CROSS,INNER,NATURAL ORDER BY + OUTER,NATURAL,NATURAL,NATURAL,NATURAL,NATURAL,NATURAL,NATURAL,INNER, + INNER,INNER NULLS LAST GROUPS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED + FOLLOWING); + } {1 {error in view q: no such column: LEFT}} + + 3 { + CREATE VIEW q AS SELECT 99 WINDOW x AS (RANGE BETWEEN UNBOUNDED PRECEDING + AND count(*)OVER(PARTITION BY (WITH a AS(VALUES(2),(x3))VALUES(0))) + FOLLOWING)ORDER BY x2,sum(1)OVER(PARTITION BY avg(5)OVER(PARTITION BY x1)); + } {1 {error in view q: no such column: x3}} +} { + do_execsql_test 19.$tn.1 " + DROP VIEW IF EXISTS q; + $v + " {} + + do_catchsql_test 19.$tn.2 { + ALTER TABLE a RENAME TO g; + } $res +} + +# Verify that the "if( pParse->nErr ) return WRC_Abort" at the top of the +# renameUnmapSelectCb() routine in alter.c (2019-12-04) is really required. +# +sqlite3 db :memory: +do_catchsql_test 20.10 { + CREATE TABLE s(a, b, c); + CREATE INDEX k ON s( (WITH s AS( SELECT * ) VALUES(2) ) IN () ); + ALTER TABLE s RENAME a TO a2; +} {1 {error in index k: no tables specified}} + +#------------------------------------------------------------------------ +# +reset_db +do_execsql_test 21.1 { + CREATE TABLE s(col); + CREATE VIEW v AS SELECT ( + WITH x(a) AS(SELECT * FROM s) VALUES(RIGHT) + ) IN() ; + CREATE TABLE a(a); + ALTER TABLE a RENAME a TO b; +} + +#------------------------------------------------------------------------ +# +reset_db +do_execsql_test 22.1 { + CREATE TABLE t1(a); + CREATE VIEW v2(b) AS SELECT * FROM v2; +} + +do_catchsql_test 22.2 { + ALTER TABLE t1 RENAME TO t4; +} {1 {error in view v2: view v2 is circularly defined}} + +do_execsql_test 22.3 { + DROP VIEW v2; + CREATE VIEW v2(b) AS WITH t3 AS (SELECT b FROM v2) SELECT * FROM t3; +} + +do_catchsql_test 22.4 { + ALTER TABLE t1 RENAME TO t4; +} {1 {error in view v2: view v2 is circularly defined}} + +do_execsql_test 22.5 { + DROP VIEW v2; + CREATE VIEW v2(b) AS WITH t3 AS (SELECT b FROM v2) VALUES(1); +} + +do_catchsql_test 22.6 { + ALTER TABLE t1 RENAME TO t4; +} {0 {}} + +#------------------------------------------------------------------------ +# +reset_db +do_execsql_test 23.1 { + CREATE TABLE t1(x); + CREATE TRIGGER r1 AFTER INSERT ON t1 BEGIN + UPDATE t1 SET (c,d)=((SELECT 1 FROM t1 JOIN t2 ON b=x),1); + END; +} + +do_catchsql_test 23.2 { + ALTER TABLE t1 RENAME TO t1x; +} {1 {error in trigger r1: no such table: main.t2}} + +#------------------------------------------------------------------------ +# +reset_db +do_execsql_test 23.1 { + CREATE TABLE v0 (a); + CREATE VIEW v2 (v3) AS + WITH x1 AS (SELECT * FROM v2) + SELECT v3 AS x, v3 AS y FROM v2; +} + +do_catchsql_test 23.2 { + SELECT * FROM v2 +} {1 {view v2 is circularly defined}} + +db close +sqlite3 db test.db + +do_catchsql_test 23.3 { + ALTER TABLE v0 RENAME TO t3 ; +} {1 {error in view v2: view v2 is circularly defined}} + +#------------------------------------------------------------------------ +# +reset_db +do_execsql_test 24.1 { + CREATE TABLE v0 (v1); + CREATE TABLE v2 (v3 INTEGER UNIQUE ON CONFLICT ABORT); + CREATE TRIGGER x AFTER INSERT ON v2 WHEN ( + ( SELECT v1 AS PROMO_REVENUE FROM v2 JOIN v0 USING ( VALUE ) ) AND 0 ) + BEGIN + DELETE FROM v2; + END; +} +do_catchsql_test 24.2 { + ALTER TABLE v0 RENAME TO x ; +} {1 {error in trigger x: cannot join using column VALUE - column not present in both tables}} + +do_execsql_test 24.3 { + DROP TRIGGER x; + CREATE TRIGGER x AFTER INSERT ON v2 WHEN ( + 0 AND (SELECT rowid FROM v0) + ) BEGIN + DELETE FROM v2; + END; +} + +do_execsql_test 24.4 { + ALTER TABLE v0 RENAME TO xyz; + SELECT sql FROM sqlite_master WHERE type='trigger' +} {{CREATE TRIGGER x AFTER INSERT ON v2 WHEN ( + 0 AND (SELECT rowid FROM "xyz") + ) BEGIN + DELETE FROM v2; + END}} + +#------------------------------------------------------------------------ +# +reset_db +do_execsql_test 25.1 { + CREATE TABLE t1(a, b, c); + CREATE TABLE t2(a, b, c); + CREATE TRIGGER ttt AFTER INSERT ON t1 BEGIN + UPDATE t1 SET a=t2.a FROM t2 WHERE t1.a=t2.a; + END; +} +#do_execsql_test 25.2 { +# ALTER TABLE t2 RENAME COLUMN a TO aaa; +#} + +#------------------------------------------------------------------------ +# +reset_db +do_execsql_test 26.1 { + CREATE TABLE t1(x); + + CREATE TABLE t3(y); + CREATE TABLE t4(z); + + CREATE TRIGGER tr1 INSERT ON t3 BEGIN + UPDATE t3 SET y=z FROM (SELECT z FROM t4); + END; + + CREATE TRIGGER tr2 INSERT ON t3 BEGIN + UPDATE t3 SET y=abc FROM (SELECT x AS abc FROM t1); + END; +} + +do_execsql_test 26.2 { + ALTER TABLE t1 RENAME TO t2; +} + +do_execsql_test 26.3 { + ALTER TABLE t2 RENAME x TO xx; +} + +do_execsql_test 26.4 { + SELECT sql FROM sqlite_schema WHERE name='tr2' +} { +{CREATE TRIGGER tr2 INSERT ON t3 BEGIN + UPDATE t3 SET y=abc FROM (SELECT xx AS abc FROM "t2"); + END} +} + +# 2020-11-02 OSSFuzz +# +reset_db +do_execsql_test 26.5 { + CREATE TABLE t1(xx); + CREATE TRIGGER xx INSERT ON t1 BEGIN + UPDATE t1 SET xx=xx FROM(SELECT xx); + END; +} {} +do_catchsql_test 26.6 { + ALTER TABLE t1 RENAME TO t2; +} {1 {error in trigger xx: no such column: xx}} + + +#------------------------------------------------------------------------- +reset_db + +do_execsql_test 27.1 { + CREATE TABLE t1(a, b AS ((WITH w1 (xyz) AS ( SELECT t1.b FROM t1 ) SELECT 123) IN ()), c); +} + +do_execsql_test 27.2 { + ALTER TABLE t1 DROP COLUMN c; + SELECT sql FROM sqlite_schema WHERE name = 't1'; +} { + {CREATE TABLE t1(a, b AS ((WITH w1 (xyz) AS ( SELECT t1.b FROM t1 ) SELECT 123) IN ()))} +} + +do_execsql_test 27.3 { + CREATE TABLE t0(c0 , c1 AS (CASE TRUE NOT IN () WHEN NULL THEN CASE + 0xa ISNULL WHEN NOT + 0x9 THEN t0.c1 ELSE CURRENT_TIME LIKE CAST (t0.c1 REGEXP '-([1-9]\d*.\d*|0\.\d*[1-9]\d*)'ESCAPE (c1) COLLATE BINARY BETWEEN c1 AND c1 NOT IN (WITH t4 (c0) AS (WITH t3 (c0) AS NOT MATERIALIZED (WITH RECURSIVE t2 (c0) AS (WITH RECURSIVE t1 AS (VALUES (x'717171ff71717171' ) ) SELECT DISTINCT t0.c0 FROM t0 NOT INDEXED WHERE t0.c0 =t0.c0 GROUP BY 0x9 ) SELECT DISTINCT t0.c0 FROM t0 NOT INDEXED WHERE t0.c0 =t0.c1 ) SELECT DISTINCT t0.c0 FROM t0 NOT INDEXED WHERE t0.c0 =t0.c0 GROUP BY typeof(0x9 ) ) SELECT DISTINCT t0.c0 FROM t0 NOT INDEXED WHERE t0.c0 =t0.c0 GROUP BY typeof(typeof(0x9 ) ) ) IN t0 BETWEEN typeof(typeof(typeof(hex(*) FILTER (WHERE + x'5ccd1e68' ) ) ) ) AND 1 >0xa AS BLOB (+4.4E4 , -0xe ) ) END <> c1 IN () END ) VIRTUAL , c35 PRIMARY KEY , c60 , c64 NUMERIC (-6.8 , -0xE ) ) WITHOUT ROWID ; +} {} + +do_execsql_test 27.4 { + ALTER TABLE t0 DROP COLUMN c60; +} {} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 28.1 { + CREATE TABLE t1(a,b,c,d); + CREATE TRIGGER AFTER INSERT ON t1 BEGIN + UPDATE t1 SET (c,d)=(a,b); + END; + ALTER TABLE t1 RENAME TO t2; +} + +do_execsql_test 28.2 { + SELECT sql FROM sqlite_schema WHERE type='trigger' +} {{CREATE TRIGGER AFTER INSERT ON "t2" BEGIN + UPDATE "t2" SET (c,d)=(a,b); + END}} + + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 29.1 { + CREATE TABLE t1(x, y); + CREATE TRIGGER Trigger1 DELETE ON t1 + BEGIN + SELECT t1.*, t1.x FROM t1 ORDER BY t1.x; + END; +} + + +do_execsql_test 29.2 { + ALTER TABLE t1 RENAME x TO z; +} + +do_execsql_test 29.3 { + ALTER TABLE t1 RENAME TO t2; +} + +do_execsql_test 29.4 { + CREATE TRIGGER tr2 AFTER DELETE ON t2 BEGIN + SELECT z, y FROM ( + SELECT t2.* FROM t2 + ); + END; +} + +do_execsql_test 29.5 { + DELETE FROM t2 +} + +do_execsql_test 29.6 { + ALTER TABLE t2 RENAME TO t3; +} + +do_execsql_test 29.7 { + SELECT sql FROM sqlite_schema WHERE type='trigger' +} { + {CREATE TRIGGER Trigger1 DELETE ON "t3" + BEGIN + SELECT "t3".*, "t3".z FROM "t3" ORDER BY "t3".z; + END} + {CREATE TRIGGER tr2 AFTER DELETE ON "t3" BEGIN + SELECT z, y FROM ( + SELECT "t3".* FROM "t3" + ); + END} +} + +finish_test diff --git a/test/altertrig.test b/test/altertrig.test new file mode 100644 index 0000000..556dc3f --- /dev/null +++ b/test/altertrig.test @@ -0,0 +1,162 @@ +# 2022 May 27 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix altertrig + +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. +ifcapable !altertable { + finish_test + return +} + +proc collapse_whitespace {in} { + regsub -all {[ \t\n]+} [string trim $in] { } +} + +proc do_whitespace_sql_test {tn sql res} { + set got [execsql $sql] + set wgot [list] + set wres [list] + foreach g $got { lappend wgot [collapse_whitespace $g] } + foreach r $res { lappend wres [collapse_whitespace $r] } + + uplevel [list do_test $tn [list set {} $wgot] $wres] +} + +do_execsql_test 1.0 { + CREATE TABLE t1(x); + CREATE TABLE t2(y); + CREATE TABLE t3(z); + CREATE TABLE t4(a); + + CREATE TRIGGER r1 INSERT ON t1 BEGIN + UPDATE t1 SET d='xyz' FROM t2, t3; + END; +} + +do_whitespace_sql_test 1.1 { + ALTER TABLE t3 RENAME TO t5; + SELECT sql FROM sqlite_schema WHERE type='trigger'; +} {{ + CREATE TRIGGER r1 INSERT ON t1 BEGIN + UPDATE t1 SET d='xyz' FROM t2, "t5"; + END +}} + +do_execsql_test 1.2 { + DROP TRIGGER r1; + CREATE TRIGGER r1 INSERT ON t1 BEGIN + UPDATE t1 SET d='xyz' FROM t2, (SELECT * FROM t5); + END; +} + +do_whitespace_sql_test 1.3 { + ALTER TABLE t5 RENAME TO t3; + SELECT sql FROM sqlite_schema WHERE type='trigger'; +} {{ + CREATE TRIGGER r1 INSERT ON t1 BEGIN + UPDATE t1 SET d='xyz' FROM t2, (SELECT * FROM "t3"); + END +}} + +foreach {tn alter update final} { + 1 { + ALTER TABLE t3 RENAME TO t10 + } { + UPDATE t1 SET d='xyz' FROM t2, (SELECT * FROM t3) + } { + UPDATE t1 SET d='xyz' FROM t2, (SELECT * FROM "t10") + } + + 2 { + ALTER TABLE t3 RENAME TO t10 + } { + UPDATE t1 SET a='xyz' FROM t3, (SELECT * FROM (SELECT e FROM t3)) + } { + UPDATE t1 SET a='xyz' FROM "t10", (SELECT * FROM (SELECT e FROM "t10")) + } + + 3 { + ALTER TABLE t3 RENAME e TO abc + } { + UPDATE t1 SET a='xyz' FROM t3, (SELECT * FROM (SELECT e FROM t3)) + } { + UPDATE t1 SET a='xyz' FROM t3, (SELECT * FROM (SELECT abc FROM t3)) + } + + 4 { + ALTER TABLE t2 RENAME c TO abc + } { + UPDATE t1 SET a='xyz' FROM t3, (SELECT 1 FROM t2 WHERE c) + } { + UPDATE t1 SET a='xyz' FROM t3, (SELECT 1 FROM t2 WHERE abc) + } + + 5 { + ALTER TABLE t2 RENAME c TO abc + } { + UPDATE t1 SET a=t2.c FROM t2 + } { + UPDATE t1 SET a=t2.abc FROM t2 + } + + 6 { + ALTER TABLE t2 RENAME c TO abc + } { + UPDATE t1 SET a=t2.c FROM t2, t3 + } { + UPDATE t1 SET a=t2.abc FROM t2, t3 + } + + 7 { + ALTER TABLE t4 RENAME e TO abc + } { + UPDATE t1 SET a=1 FROM t3 NATURAL JOIN t4 WHERE t4.e=a + } { + UPDATE t1 SET a=1 FROM t3 NATURAL JOIN t4 WHERE t4.abc=a + } + + 8 { + ALTER TABLE t4 RENAME TO abc + } { + UPDATE t1 SET a=1 FROM t3 NATURAL JOIN t4 WHERE t4.e=a + } { + UPDATE t1 SET a=1 FROM t3 NATURAL JOIN "abc" WHERE "abc".e=a + } + +} { + reset_db + do_execsql_test 2.$tn.1 { + CREATE TABLE t1(a,b); + CREATE TABLE t2(c,d); + CREATE TABLE t3(e,f); + CREATE TABLE t4(e,f); + } + do_execsql_test 2.$tn.2 " + CREATE TRIGGER r1 INSERT ON t1 BEGIN + $update; + END + " + do_execsql_test 2.$tn.3 $alter + + do_whitespace_sql_test 2.$tn.4 { + SELECT sqL FROM sqlite_schema WHERE type='trigger' + } "{ + CREATE TRIGGER r1 INSERT ON t1 BEGIN + $final; + END + }" +} + +finish_test diff --git a/test/amatch1.test b/test/amatch1.test new file mode 100644 index 0000000..cc0f77a --- /dev/null +++ b/test/amatch1.test @@ -0,0 +1,117 @@ +# 2013-09-30 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for "approximate_match" virtual +# table that is in the "amatch.c" extension. +# +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS4 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# Create the fts_kjv_genesis procedure which fills and FTS3/4 table with +# the complete text of the Book of Genesis. +# +source $testdir/genesis.tcl + + + +do_test amatch1-1.0 { + db eval { + CREATE VIRTUAL TABLE t1 USING fts4(words); --, tokenize porter); + } + fts_kjv_genesis + db eval { + INSERT INTO t1(t1) VALUES('optimize'); + CREATE VIRTUAL TABLE temp.t1aux USING fts4aux(main, t1); + SELECT term FROM t1aux WHERE col=0 ORDER BY 1 LIMIT 5 + } +} {a abated abel abelmizraim abidah} +do_test amatch1-1.1 { + db eval { + SELECT term FROM t1aux WHERE term>'b' AND col=0 ORDER BY 1 LIMIT 5 + } +} {baalhanan babel back backward bad} +do_test amatch1-1.2 { + db eval { + SELECT term FROM t1aux WHERE term>'b' AND col=0 LIMIT 5 + } +} {baalhanan babel back backward bad} + +# Load the amatch extension +load_static_extension db amatch + +do_execsql_test amatch1-2.0 { + CREATE TABLE costs(iLang, cFrom, cTo, Cost); + INSERT INTO costs VALUES(0, '', '?', 100); + INSERT INTO costs VALUES(0, '?', '', 100); + INSERT INTO costs VALUES(0, '?', '?', 150); + CREATE TABLE vocab(w TEXT UNIQUE); + INSERT OR IGNORE INTO vocab SELECT term FROM t1aux; + CREATE VIRTUAL TABLE t2 USING approximate_match( + vocabulary_table=t1aux, + vocabulary_word=term, + edit_distances=costs + ); + CREATE VIRTUAL TABLE t3 USING approximate_match( + vocabulary_table=vocab, + vocabulary_word=w, + edit_distances=costs + ); + CREATE VIRTUAL TABLE t4 USING approximate_match( + vocabulary_table=vtemp, + vocabulary_word=w, + edit_distances=costs + ); +} {} +puts "Query against fts4aux: [time { + do_execsql_test amatch1-2.1 { + SELECT word, distance FROM t2 + WHERE word MATCH 'josxph' AND distance<300; + } {joseph 150}} 1]" +puts "Query against ordinary table: [time { + do_execsql_test amatch1-2.2 { + SELECT word, distance FROM t3 + WHERE word MATCH 'josxph' AND distance<300; + } {joseph 150}} 1]" +puts "Temp table initialized from fts4aux: [time { + do_execsql_test amatch1-2.3a { + CREATE TEMP TABLE vtemp(w TEXT UNIQUE); + INSERT OR IGNORE INTO vtemp SELECT term FROM t1aux; + } {}} 1]" +puts "Query against temp table: [time { + do_execsql_test amatch1-2.3b { + SELECT word, distance FROM t4 + WHERE word MATCH 'josxph' AND distance<300; + } {joseph 150}} 1]" +do_execsql_test amatch1-2.11 { + SELECT word, distance FROM t2 + WHERE word MATCH 'joxxph' AND distance<=300; +} {joseph 300} +do_execsql_test amatch1-2.12 { + SELECT word, distance FROM t3 + WHERE word MATCH 'joxxph' AND distance<=300; +} {joseph 300} +do_execsql_test amatch1-2.21 { + SELECT word, distance FROM t2 + WHERE word MATCH 'joxxph' AND distance<300; +} {} +do_execsql_test amatch1-2.22 { + SELECT word, distance FROM t3 + WHERE word MATCH 'joxxph' AND distance<300; +} {} + +finish_test diff --git a/test/analyze.test b/test/analyze.test new file mode 100644 index 0000000..f97c78a --- /dev/null +++ b/test/analyze.test @@ -0,0 +1,399 @@ +# 2005 July 22 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# This file implements tests for the ANALYZE command. +# +# $Id: analyze.test,v 1.9 2008/08/11 18:44:58 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# There is nothing to test if ANALYZE is disable for this build. +# +ifcapable {!analyze} { + finish_test + return +} + +# Basic sanity checks. +# +do_test analyze-1.1 { + catchsql { + ANALYZE no_such_table + } +} {1 {no such table: no_such_table}} +do_test analyze-1.2 { + execsql { + SELECT count(*) FROM sqlite_master WHERE name='sqlite_stat1' + } +} {0} +do_test analyze-1.3 { + catchsql { + ANALYZE no_such_db.no_such_table + } +} {1 {unknown database no_such_db}} +do_test analyze-1.4 { + execsql { + SELECT count(*) FROM sqlite_master WHERE name='sqlite_stat1' + } +} {0} +do_test analyze-1.5.1 { + catchsql { + ANALYZE + } +} {0 {}} +do_test analyze-1.5.2 { + catchsql { + PRAGMA empty_result_callbacks=1; + ANALYZE + } +} {0 {}} +do_test analyze-1.6 { + execsql { + SELECT count(*) FROM sqlite_master WHERE name='sqlite_stat1' + } +} {1} +do_test analyze-1.6.2 { + catchsql { + CREATE INDEX stat1idx ON sqlite_stat1(idx); + } +} {1 {table sqlite_stat1 may not be indexed}} +do_test analyze-1.6.3 { + catchsql { + CREATE INDEX main.stat1idx ON SQLite_stat1(idx); + } +} {1 {table sqlite_stat1 may not be indexed}} +do_test analyze-1.7 { + execsql { + SELECT * FROM sqlite_stat1 WHERE idx NOT NULL + } +} {} +do_test analyze-1.8 { + catchsql { + ANALYZE main + } +} {0 {}} +do_test analyze-1.9 { + execsql { + SELECT * FROM sqlite_stat1 WHERE idx NOT NULL + } +} {} +do_test analyze-1.10 { + catchsql { + CREATE TABLE t1(a,b); + ANALYZE main.t1; + } +} {0 {}} +do_test analyze-1.11 { + execsql { + SELECT * FROM sqlite_stat1 + } +} {} +do_test analyze-1.12 { + catchsql { + ANALYZE t1; + } +} {0 {}} +do_test analyze-1.13 { + execsql { + SELECT * FROM sqlite_stat1 + } +} {} + +# Create some indices that can be analyzed. But do not yet add +# data. Without data in the tables, no analysis is done. +# +do_test analyze-2.1 { + execsql { + CREATE INDEX t1i1 ON t1(a); + ANALYZE main.t1; + SELECT * FROM sqlite_stat1 ORDER BY idx; + } +} {} +do_test analyze-2.2 { + execsql { + CREATE INDEX t1i2 ON t1(b); + ANALYZE t1; + SELECT * FROM sqlite_stat1 ORDER BY idx; + } +} {} +do_test analyze-2.3 { + execsql { + CREATE INDEX t1i3 ON t1(a,b); + ANALYZE main; + SELECT * FROM sqlite_stat1 ORDER BY idx; + } +} {} + +# Start adding data to the table. Verify that the analysis +# is done correctly. +# +do_test analyze-3.1 { + execsql { + INSERT INTO t1 VALUES(1,2); + INSERT INTO t1 VALUES(1,3); + ANALYZE main.t1; + SELECT idx, stat FROM sqlite_stat1 ORDER BY idx; + } +} {t1i1 {2 2} t1i2 {2 1} t1i3 {2 2 1}} +do_test analyze-3.2 { + execsql { + INSERT INTO t1 VALUES(1,4); + INSERT INTO t1 VALUES(1,5); + ANALYZE t1; + SELECT idx, stat FROM sqlite_stat1 ORDER BY idx; + } +} {t1i1 {4 4} t1i2 {4 1} t1i3 {4 4 1}} +do_test analyze-3.3 { + execsql { + INSERT INTO t1 VALUES(2,5); + ANALYZE main; + SELECT idx, stat FROM sqlite_stat1 ORDER BY idx; + } +} {t1i1 {5 3} t1i2 {5 2} t1i3 {5 3 1}} +do_test analyze-3.4 { + execsql { + CREATE TABLE t2 AS SELECT * FROM t1; + CREATE INDEX t2i1 ON t2(a); + CREATE INDEX t2i2 ON t2(b); + CREATE INDEX t2i3 ON t2(a,b); + ANALYZE; + SELECT idx, stat FROM sqlite_stat1 ORDER BY idx; + } +} {t1i1 {5 3} t1i2 {5 2} t1i3 {5 3 1} t2i1 {5 3} t2i2 {5 2} t2i3 {5 3 1}} +do_test analyze-3.5 { + execsql { + DROP INDEX t2i3; + ANALYZE t1; + SELECT idx, stat FROM sqlite_stat1 ORDER BY idx; + } +} {t1i1 {5 3} t1i2 {5 2} t1i3 {5 3 1} t2i1 {5 3} t2i2 {5 2}} +do_test analyze-3.6 { + execsql { + ANALYZE t2; + SELECT idx, stat FROM sqlite_stat1 ORDER BY idx; + } +} {t1i1 {5 3} t1i2 {5 2} t1i3 {5 3 1} t2i1 {5 3} t2i2 {5 2}} +do_test analyze-3.7 { + execsql { + DROP INDEX t2i2; + ANALYZE t2; + SELECT idx, stat FROM sqlite_stat1 ORDER BY idx; + } +} {t1i1 {5 3} t1i2 {5 2} t1i3 {5 3 1} t2i1 {5 3}} +do_test analyze-3.8 { + execsql { + CREATE TABLE t3 AS SELECT a, b, rowid AS c, 'hi' AS d FROM t1; + CREATE INDEX t3i1 ON t3(a); + CREATE INDEX t3i2 ON t3(a,b,c,d); + CREATE INDEX t3i3 ON t3(d,b,c,a); + DROP TABLE t1; + DROP TABLE t2; + SELECT idx, stat FROM sqlite_stat1 ORDER BY idx; + } +} {} +do_test analyze-3.9 { + execsql { + ANALYZE; + SELECT idx, stat FROM sqlite_stat1 ORDER BY idx; + } +} {t3i1 {5 3} t3i2 {5 3 1 1 1} t3i3 {5 5 2 1 1}} + +do_test analyze-3.10 { + execsql { + CREATE TABLE [silly " name](a, b, c); + CREATE INDEX 'foolish '' name' ON [silly " name](a, b); + CREATE INDEX 'another foolish '' name' ON [silly " name](c); + INSERT INTO [silly " name] VALUES(1, 2, 3); + INSERT INTO [silly " name] VALUES(4, 5, 6); + ANALYZE; + SELECT idx, stat FROM sqlite_stat1 ORDER BY idx; + } +} {{another foolish ' name} {2 1} {foolish ' name} {2 1 1} t3i1 {5 3} t3i2 {5 3 1 1 1} t3i3 {5 5 2 1 1}} +do_test analyze-3.11 { + execsql { + DROP INDEX "foolish ' name"; + SELECT idx, stat FROM sqlite_stat1 ORDER BY idx; + } +} {{another foolish ' name} {2 1} t3i1 {5 3} t3i2 {5 3 1 1 1} t3i3 {5 5 2 1 1}} +do_test analyze-3.11 { + execsql { + DROP TABLE "silly "" name"; + SELECT idx, stat FROM sqlite_stat1 ORDER BY idx; + } +} {t3i1 {5 3} t3i2 {5 3 1 1 1} t3i3 {5 5 2 1 1}} + +# Try corrupting the sqlite_stat1 table and make sure the +# database is still able to function. +# +do_test analyze-4.0 { + sqlite3 db2 test.db + db2 eval { + CREATE TABLE t4(x,y,z); + CREATE INDEX t4i1 ON t4(x); + CREATE INDEX t4i2 ON t4(y); + INSERT INTO t4 SELECT a,b,c FROM t3; + } + db2 close + db close + sqlite3 db test.db + execsql { + ANALYZE; + SELECT idx, stat FROM sqlite_stat1 ORDER BY idx; + } +} {t3i1 {5 3} t3i2 {5 3 1 1 1} t3i3 {5 5 2 1 1} t4i1 {5 3} t4i2 {5 2}} +do_test analyze-4.1 { + execsql { + PRAGMA writable_schema=on; + INSERT INTO sqlite_stat1 VALUES(null,null,null); + PRAGMA writable_schema=off; + } + db close + sqlite3 db test.db + execsql { + SELECT * FROM t4 WHERE x=1234; + } +} {} +do_test analyze-4.2 { + execsql { + PRAGMA writable_schema=on; + DELETE FROM sqlite_stat1; + INSERT INTO sqlite_stat1 VALUES('t4','t4i1','nonsense'); + INSERT INTO sqlite_stat1 VALUES('t4','t4i2','120897349817238741092873198273409187234918720394817209384710928374109827172901827349871928741910'); + PRAGMA writable_schema=off; + } + db close + sqlite3 db test.db + execsql { + SELECT * FROM t4 WHERE x=1234; + } +} {} +do_test analyze-4.3 { + execsql { + INSERT INTO sqlite_stat1 VALUES('t4','xyzzy','0 1 2 3'); + } + db close + sqlite3 db test.db + execsql { + SELECT * FROM t4 WHERE x=1234; + } +} {} + +# Verify that DROP TABLE and DROP INDEX remove entries from the +# sqlite_stat1 and sqlite_stat4 tables. +# +do_test analyze-5.0 { + execsql { + DELETE FROM t3; + DELETE FROM t4; + INSERT INTO t3 VALUES(1,2,3,4); + INSERT INTO t3 VALUES(5,6,7,8); + INSERT INTO t3 SELECT a+8, b+8, c+8, d+8 FROM t3; + INSERT INTO t3 SELECT a+16, b+16, c+16, d+16 FROM t3; + INSERT INTO t3 SELECT a+32, b+32, c+32, d+32 FROM t3; + INSERT INTO t3 SELECT a+64, b+64, c+64, d+64 FROM t3; + INSERT INTO t4 SELECT a, b, c FROM t3; + ANALYZE; + SELECT DISTINCT idx FROM sqlite_stat1 ORDER BY 1; + SELECT DISTINCT tbl FROM sqlite_stat1 ORDER BY 1; + } +} {t3i1 t3i2 t3i3 t4i1 t4i2 t3 t4} +ifcapable stat4 { + do_test analyze-5.1 { + execsql { + SELECT DISTINCT idx FROM sqlite_stat4 ORDER BY 1; + SELECT DISTINCT tbl FROM sqlite_stat4 ORDER BY 1; + } + } {t3i1 t3i2 t3i3 t4i1 t4i2 t3 t4} +} +do_test analyze-5.2 { + execsql { + DROP INDEX t3i2; + SELECT DISTINCT idx FROM sqlite_stat1 ORDER BY 1; + SELECT DISTINCT tbl FROM sqlite_stat1 ORDER BY 1; + } +} {t3i1 t3i3 t4i1 t4i2 t3 t4} +ifcapable stat4 { + do_test analyze-5.3 { + execsql { + SELECT DISTINCT idx FROM sqlite_stat4 ORDER BY 1; + SELECT DISTINCT tbl FROM sqlite_stat4 ORDER BY 1; + } + } {t3i1 t3i3 t4i1 t4i2 t3 t4} +} +do_test analyze-5.4 { + execsql { + DROP TABLE t3; + SELECT DISTINCT idx FROM sqlite_stat1 ORDER BY 1; + SELECT DISTINCT tbl FROM sqlite_stat1 ORDER BY 1; + } +} {t4i1 t4i2 t4} +ifcapable stat4 { + do_test analyze-5.5 { + execsql { + SELECT DISTINCT idx FROM sqlite_stat4 ORDER BY 1; + SELECT DISTINCT tbl FROM sqlite_stat4 ORDER BY 1; + } + } {t4i1 t4i2 t4} +} + +# This test corrupts the database file so it must be the last test +# in the series. +# +do_test analyze-5.99 { + sqlite3_db_config db DEFENSIVE 0 + execsql { + PRAGMA writable_schema=on; + UPDATE sqlite_master SET sql='nonsense' WHERE name='sqlite_stat1'; + } + db close + catch { sqlite3 db test.db } + catchsql { + ANALYZE + } +} {1 {malformed database schema (sqlite_stat1)}} + +# Verify that tables whose names begin with "sqlite" but not +# "sqlite_" are analyzed. +# +db close +sqlite3 db :memory: +do_execsql_test analyze-6.1 { + CREATE TABLE sqliteDemo(a); + INSERT INTO sqliteDemo(a) VALUES(1),(2),(3),(4),(5); + CREATE TABLE SQLiteDemo2(a INTEGER PRIMARY KEY AUTOINCREMENT); + INSERT INTO SQLiteDemo2 SELECT * FROM sqliteDemo; + CREATE TABLE t1(b); + INSERT INTO t1(b) SELECT a FROM sqliteDemo; + ANALYZE; + SELECT tbl FROM sqlite_stat1 WHERE idx IS NULL ORDER BY tbl; +} {SQLiteDemo2 sqliteDemo t1} + +# The following caused a small buffer overread in STAT4 processing prior +# to check-in [b99135288b157044]. +# +ifcapable stat4 { + reset_db + database_may_be_corrupt + do_execsql_test analyze-7.1 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b INTEGER); + INSERT INTO t1 VALUES(1, 7223372036854775); + INSERT INTO t1 VALUES(2, 7223372036854776); + INSERT INTO t1 VALUES(3, 7223372036854777); + CREATE INDEX i1 ON t1(b); + ANALYZE; + UPDATE sqlite_stat4 SET sample = substr(sample, 0, 4); + ANALYZE sqlite_schema; + SELECT * FROM t1 WHERE b>7223372036854775 + } {2 7223372036854776 3 7223372036854777} +} + +finish_test diff --git a/test/analyze3.test b/test/analyze3.test new file mode 100644 index 0000000..c5d7a7c --- /dev/null +++ b/test/analyze3.test @@ -0,0 +1,766 @@ +# 2009 August 06 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file implements regression tests for SQLite library. This file +# implements tests for range and LIKE constraints that use bound variables +# instead of literal constant arguments. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix analyze3 + +ifcapable !stat4 { + finish_test + return +} + +# This test cannot be run with the sqlite3_prepare() permutation, as it +# tests that stat4 data can be used to influence the plans of queries +# based on bound variable values. And this is not possible when using +# sqlite3_prepare() - as queries cannot be internally re-prepared after +# binding values are available. +if {[permutation]=="prepare"} { + finish_test + return +} + +#---------------------------------------------------------------------- +# Test Organization: +# +# analyze3-1.*: Test that the values of bound parameters are considered +# in the same way as constants when planning queries that +# use range constraints. +# +# analyze3-2.*: Test that the values of bound parameters are considered +# in the same way as constants when planning queries that +# use LIKE expressions in the WHERE clause. +# +# analyze3-3.*: Test that binding to a variable does not invalidate the +# query plan when there is no way in which replanning the +# query may produce a superior outcome. +# +# analyze3-4.*: Test that SQL or authorization callback errors occuring +# within sqlite3Reprepare() are handled correctly. +# +# analyze3-5.*: Check that the query plans of applicable statements are +# invalidated if the values of SQL parameter are modified +# using the clear_bindings() or transfer_bindings() APIs. +# +# analyze3-6.*: Test that the problem fixed by commit [127a5b776d] is fixed. +# +# analyze3-7.*: Test that some memory leaks discovered by fuzz testing +# have been fixed. +# + +proc getvar {varname} { uplevel #0 set $varname } +db function var getvar + +proc eqp {sql {db db}} { + uplevel execsql [list "EXPLAIN QUERY PLAN $sql"] $db +} + +proc sf_execsql {sql {db db}} { + set ::sqlite_search_count 0 + set r [uplevel [list execsql $sql $db]] + + concat $::sqlite_search_count [$db status step] $r +} + +#------------------------------------------------------------------------- +# +# analyze3-1.1.1: +# Create a table with two columns. Populate the first column (affinity +# INTEGER) with integer values from 100 to 1100. Create an index on this +# column. ANALYZE the table. +# +# analyze3-1.1.2 - 3.1.3 +# Show that there are two possible plans for querying the table with +# a range constraint on the indexed column - "full table scan" or "use +# the index". When the range is specified using literal values, SQLite +# is able to pick the best plan based on the samples in sqlite_stat3. +# +# analyze3-1.1.4 - 3.1.9 +# Show that using SQL variables produces the same results as using +# literal values to constrain the range scan. +# +# These tests also check that the compiler code considers column +# affinities when estimating the number of rows scanned by the "use +# index strategy". +# +do_test analyze3-1.1.1 { + execsql { + BEGIN; + CREATE TABLE t1(x INTEGER, y); + CREATE INDEX i1 ON t1(x); + } + for {set i 0} {$i < 1000} {incr i} { + execsql { INSERT INTO t1 VALUES($i+100, $i) } + } + execsql { + COMMIT; + ANALYZE; + } + + execsql { SELECT count(*)>0 FROM sqlite_stat4; } +} {1} + +do_execsql_test analyze3-1.1.x { + SELECT count(*) FROM t1 WHERE x>200 AND x<300; + SELECT count(*) FROM t1 WHERE x>0 AND x<1100; +} {99 1000} + +# The first of the following two SELECT statements visits 99 rows. So +# it is better to use the index. But the second visits every row in +# the table (1000 in total) so it is better to do a full-table scan. +# +do_eqp_test analyze3-1.1.2 { + SELECT sum(y) FROM t1 WHERE x>200 AND x<300 +} {SEARCH t1 USING INDEX i1 (x>? AND x0 AND x<1100 +} {SCAN t1} + +# 2017-06-26: Verify that the SQLITE_DBCONFIG_ENABLE_QPSG setting disables +# the use of bound parameters by STAT4 +# +db cache flush +unset -nocomplain l +unset -nocomplain u +do_eqp_test analyze3-1.1.3.100 { + SELECT sum(y) FROM t1 WHERE x>$l AND x<$u +} {SEARCH t1 USING INDEX i1 (x>? AND x$l AND x<$u +} {SEARCH t1 USING INDEX i1 (x>? AND x$l AND x<$u +} {SCAN t1} +db cache flush +sqlite3_db_config db ENABLE_QPSG 1 +do_eqp_test analyze3-1.1.3.103 { + SELECT sum(y) FROM t1 WHERE x>$l AND x<$u +} {SEARCH t1 USING INDEX i1 (x>? AND x$l AND x<$u +} {SCAN t1} + +do_test analyze3-1.1.4 { + sf_execsql { SELECT sum(y) FROM t1 WHERE x>200 AND x<300 } +} {199 0 14850} +do_test analyze3-1.1.5 { + set l [string range "200" 0 end] + set u [string range "300" 0 end] + sf_execsql { SELECT sum(y) FROM t1 WHERE x>$l AND x<$u } +} {199 0 14850} +do_test analyze3-1.1.6 { + set l [expr int(200)] + set u [expr int(300)] + sf_execsql { SELECT sum(y) FROM t1 WHERE x>$l AND x<$u } +} {199 0 14850} +do_test analyze3-1.1.7 { + sf_execsql { SELECT sum(y) FROM t1 WHERE x>0 AND x<1100 } +} {999 999 499500} +do_test analyze3-1.1.8 { + set l [string range "0" 0 end] + set u [string range "1100" 0 end] + sf_execsql { SELECT sum(y) FROM t1 WHERE x>$l AND x<$u } +} {999 999 499500} +do_test analyze3-1.1.9 { + set l [expr int(0)] + set u [expr int(1100)] + sf_execsql { SELECT sum(y) FROM t1 WHERE x>$l AND x<$u } +} {999 999 499500} + + +# The following tests are similar to the block above. The difference is +# that the indexed column has TEXT affinity in this case. In the tests +# above the affinity is INTEGER. +# +do_test analyze3-1.2.1 { + execsql { + BEGIN; + CREATE TABLE t2(x TEXT, y); + INSERT INTO t2 SELECT * FROM t1; + CREATE INDEX i2 ON t2(x); + COMMIT; + ANALYZE; + } +} {} +do_execsql_test analyze3-2.1.x { + SELECT count(*) FROM t2 WHERE x>1 AND x<2; + SELECT count(*) FROM t2 WHERE x>0 AND x<99; +} {200 990} +do_eqp_test analyze3-1.2.2 { + SELECT sum(y) FROM t2 WHERE x>1 AND x<2 +} {SEARCH t2 USING INDEX i2 (x>? AND x0 AND x<99 +} {SCAN t2} + +do_test analyze3-1.2.4 { + sf_execsql { SELECT sum(y) FROM t2 WHERE x>12 AND x<20 } +} {161 0 4760} +do_test analyze3-1.2.5 { + set l [string range "12" 0 end] + set u [string range "20" 0 end] + sf_execsql {SELECT typeof($l), typeof($u), sum(y) FROM t2 WHERE x>$l AND x<$u} +} {161 0 text text 4760} +do_test analyze3-1.2.6 { + set l [expr int(12)] + set u [expr int(20)] + sf_execsql {SELECT typeof($l), typeof($u), sum(y) FROM t2 WHERE x>$l AND x<$u} +} {161 0 integer integer 4760} +do_test analyze3-1.2.7 { + sf_execsql { SELECT sum(y) FROM t2 WHERE x>0 AND x<99 } +} {999 999 490555} +do_test analyze3-1.2.8 { + set l [string range "0" 0 end] + set u [string range "99" 0 end] + sf_execsql {SELECT typeof($l), typeof($u), sum(y) FROM t2 WHERE x>$l AND x<$u} +} {999 999 text text 490555} +do_test analyze3-1.2.9 { + set l [expr int(0)] + set u [expr int(99)] + sf_execsql {SELECT typeof($l), typeof($u), sum(y) FROM t2 WHERE x>$l AND x<$u} +} {999 999 integer integer 490555} + +# Same tests a third time. This time, column x has INTEGER affinity and +# is not the leftmost column of the table. This triggered a bug causing +# SQLite to use sub-optimal query plans in 3.6.18 and earlier. +# +do_test analyze3-1.3.1 { + execsql { + BEGIN; + CREATE TABLE t3(y TEXT, x INTEGER); + INSERT INTO t3 SELECT y, x FROM t1; + CREATE INDEX i3 ON t3(x); + COMMIT; + ANALYZE; + } +} {} +do_execsql_test analyze3-1.3.x { + SELECT count(*) FROM t3 WHERE x>200 AND x<300; + SELECT count(*) FROM t3 WHERE x>0 AND x<1100 +} {99 1000} +do_eqp_test analyze3-1.3.2 { + SELECT sum(y) FROM t3 WHERE x>200 AND x<300 +} {SEARCH t3 USING INDEX i3 (x>? AND x0 AND x<1100 +} {SCAN t3} + +do_test analyze3-1.3.4 { + sf_execsql { SELECT sum(y) FROM t3 WHERE x>200 AND x<300 } +} {199 0 14850} +do_test analyze3-1.3.5 { + set l [string range "200" 0 end] + set u [string range "300" 0 end] + sf_execsql { SELECT sum(y) FROM t3 WHERE x>$l AND x<$u } +} {199 0 14850} +do_test analyze3-1.3.6 { + set l [expr int(200)] + set u [expr int(300)] + sf_execsql { SELECT sum(y) FROM t3 WHERE x>$l AND x<$u } +} {199 0 14850} +do_test analyze3-1.3.7 { + sf_execsql { SELECT sum(y) FROM t3 WHERE x>0 AND x<1100 } +} {999 999 499500} +do_test analyze3-1.3.8 { + set l [string range "0" 0 end] + set u [string range "1100" 0 end] + sf_execsql { SELECT sum(y) FROM t3 WHERE x>$l AND x<$u } +} {999 999 499500} +do_test analyze3-1.3.9 { + set l [expr int(0)] + set u [expr int(1100)] + sf_execsql { SELECT sum(y) FROM t3 WHERE x>$l AND x<$u } +} {999 999 499500} + +#------------------------------------------------------------------------- +# Test that the values of bound SQL variables may be used for the LIKE +# optimization. +# +drop_all_tables +do_test analyze3-2.1 { + execsql { + PRAGMA case_sensitive_like=off; + BEGIN; + CREATE TABLE t1(a, b TEXT COLLATE nocase); + CREATE INDEX i1 ON t1(b); + } + for {set i 0} {$i < 1000} {incr i} { + set t "" + append t [lindex {a b c d e f g h i j} [expr $i/100]] + append t [lindex {a b c d e f g h i j} [expr ($i/10)%10]] + append t [lindex {a b c d e f g h i j} [expr ($i%10)]] + execsql { INSERT INTO t1 VALUES($i, $t) } + } + execsql COMMIT +} {} +do_eqp_test analyze3-2.2 { + SELECT count(a) FROM t1 WHERE b LIKE 'a%' +} {SEARCH t1 USING INDEX i1 (b>? AND b?" -1 dummy] + sqlite3_expired $S +} {0} +do_test analyze3-3.2.2 { + sqlite3_bind_text $S 1 "abc" 3 + sqlite3_expired $S +} {1} +do_test analyze3-3.2.4 { + sqlite3_finalize $S +} {SQLITE_OK} + +do_test analyze3-3.2.5 { + set S [sqlite3_prepare_v2 db "SELECT * FROM t1 WHERE b=?" -1 dummy] + sqlite3_expired $S +} {0} +do_test analyze3-3.2.6 { + sqlite3_bind_text $S 1 "abc" 3 + sqlite3_expired $S +} {1} +do_test analyze3-3.2.7 { + sqlite3_finalize $S +} {SQLITE_OK} + +do_test analyze3-3.4.1 { + set S [sqlite3_prepare_v2 db "SELECT * FROM t1 WHERE a=? AND b>?" -1 dummy] + sqlite3_expired $S +} {0} +do_test analyze3-3.4.2 { + sqlite3_bind_text $S 1 "abc" 3 + sqlite3_expired $S +} {0} +do_test analyze3-3.4.3 { + sqlite3_bind_text $S 2 "def" 3 + sqlite3_expired $S +} {1} +do_test analyze3-3.4.4 { + sqlite3_bind_text $S 2 "ghi" 3 + sqlite3_expired $S +} {1} +do_test analyze3-3.4.5 { + sqlite3_expired $S +} {1} +do_test analyze3-3.4.6 { + sqlite3_finalize $S +} {SQLITE_OK} + +do_test analyze3-3.5.1 { + set S [sqlite3_prepare_v2 db { + SELECT * FROM t1 WHERE a IN ( + ?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, + ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18, ?19, ?20, + ?21, ?22, ?23, ?24, ?25, ?26, ?27, ?28, ?29, ?30, ?31 + ) AND b>?32; + } -1 dummy] + sqlite3_expired $S +} {0} +do_test analyze3-3.5.2 { + sqlite3_bind_text $S 31 "abc" 3 + sqlite3_expired $S +} {0} +do_test analyze3-3.5.3 { + sqlite3_bind_text $S 32 "def" 3 + sqlite3_expired $S +} {1} +do_test analyze3-3.5.5 { + sqlite3_finalize $S +} {SQLITE_OK} + +do_test analyze3-3.6.1 { + set S [sqlite3_prepare_v2 db { + SELECT * FROM t1 WHERE a IN ( + ?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, + ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18, ?19, ?20, + ?21, ?22, ?23, ?24, ?25, ?26, ?27, ?28, ?29, ?30, ?31, ?32 + ) AND b>?33; + } -1 dummy] + sqlite3_expired $S +} {0} +do_test analyze3-3.6.2 { + sqlite3_bind_text $S 32 "abc" 3 + sqlite3_expired $S +} {1} +do_test analyze3-3.6.3 { + sqlite3_bind_text $S 33 "def" 3 + sqlite3_expired $S +} {1} +do_test analyze3-3.6.5 { + sqlite3_finalize $S +} {SQLITE_OK} + +do_test analyze3-3.7.1 { + set S [sqlite3_prepare_v2 db { + SELECT * FROM t1 WHERE a IN ( + ?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?33, + ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18, ?19, ?20, + ?21, ?22, ?23, ?24, ?25, ?26, ?27, ?28, ?29, ?30, ?31, ?32 + ) AND b>?10; + } -1 dummy] + sqlite3_expired $S +} {0} +do_test analyze3-3.7.2 { + sqlite3_bind_text $S 32 "abc" 3 + sqlite3_expired $S +} {0} +do_test analyze3-3.7.3 { + sqlite3_bind_text $S 33 "def" 3 + sqlite3_expired $S +} {0} +do_test analyze3-3.7.4 { + sqlite3_bind_text $S 10 "def" 3 + sqlite3_expired $S +} {1} +do_test analyze3-3.7.6 { + sqlite3_finalize $S +} {SQLITE_OK} + +do_test analyze3-3.8.1 { + execsql { + CREATE TABLE t4(x, y TEXT COLLATE NOCASE); + CREATE INDEX i4 ON t4(y); + } +} {} +do_test analyze3-3.8.2 { + set S [sqlite3_prepare_v2 db { + SELECT * FROM t4 WHERE x != ? AND y LIKE ? + } -1 dummy] + sqlite3_expired $S +} {0} +do_test analyze3-3.8.3 { + sqlite3_bind_text $S 1 "abc" 3 + sqlite3_expired $S +} {0} +do_test analyze3-3.8.4 { + sqlite3_bind_text $S 2 "def" 3 + sqlite3_expired $S +} {1} +do_test analyze3-3.8.7 { + sqlite3_bind_text $S 2 "ghi%" 4 + sqlite3_expired $S +} {1} +do_test analyze3-3.8.8 { + sqlite3_expired $S +} {1} +do_test analyze3-3.8.9 { + sqlite3_bind_text $S 2 "ghi%def" 7 + sqlite3_expired $S +} {1} +do_test analyze3-3.8.10 { + sqlite3_expired $S +} {1} +do_test analyze3-3.8.11 { + sqlite3_bind_text $S 2 "%ab" 3 + sqlite3_expired $S +} {1} +do_test analyze3-3.8.12 { + sqlite3_expired $S +} {1} +do_test analyze3-3.8.12 { + sqlite3_bind_text $S 2 "%de" 3 + sqlite3_expired $S +} {1} +do_test analyze3-3.8.13 { + sqlite3_expired $S +} {1} +do_test analyze3-3.8.14 { + sqlite3_finalize $S +} {SQLITE_OK} + +#------------------------------------------------------------------------- +# These tests check that errors encountered while repreparing an SQL +# statement within sqlite3Reprepare() are handled correctly. +# + +# Check a schema error. +# +do_test analyze3-4.1.1 { + set S [sqlite3_prepare_v2 db "SELECT * FROM t1 WHERE a=? AND b>?" -1 dummy] + sqlite3_step $S +} {SQLITE_DONE} +do_test analyze3-4.1.2 { + sqlite3_reset $S + sqlite3_bind_text $S 2 "abc" 3 + execsql { DROP TABLE t1 } + sqlite3_step $S +} {SQLITE_ERROR} +do_test analyze3-4.1.3 { + sqlite3_finalize $S +} {SQLITE_ERROR} + +# Check an authorization error. +# +do_test analyze3-4.2.1 { + execsql { + BEGIN; + CREATE TABLE t1(a, b, c); + CREATE INDEX i1 ON t1(b); + } + for {set i 0} {$i < 100} {incr i} { + execsql { INSERT INTO t1 VALUES($i, $i, $i) } + } + execsql COMMIT + execsql ANALYZE + set S [sqlite3_prepare_v2 db "SELECT * FROM t1 WHERE a=? AND b>?" -1 dummy] + sqlite3_step $S +} {SQLITE_DONE} +db auth auth +proc auth {args} { + if {[lindex $args 0] == "SQLITE_READ"} {return SQLITE_DENY} + return SQLITE_OK +} +do_test analyze3-4.2.2 { + sqlite3_reset $S + sqlite3_bind_text $S 2 "abc" 3 + sqlite3_step $S +} {SQLITE_AUTH} +do_test analyze3-4.2.4 { + sqlite3_finalize $S +} {SQLITE_AUTH} + +# Check the effect of an authorization error that occurs in a re-prepare +# performed by sqlite3_step() is the same as one that occurs within +# sqlite3Reprepare(). +# +do_test analyze3-4.3.1 { + db auth {} + set S [sqlite3_prepare_v2 db "SELECT * FROM t1 WHERE a=? AND b>?" -1 dummy] + execsql { CREATE TABLE t2(d, e, f) } + db auth auth + sqlite3_step $S +} {SQLITE_AUTH} +do_test analyze3-4.3.2 { + sqlite3_finalize $S +} {SQLITE_AUTH} +db auth {} + +#------------------------------------------------------------------------- +# Test that modifying bound variables using the clear_bindings() or +# transfer_bindings() APIs works. +# +# analyze3-5.1.*: sqlite3_clear_bindings() +# analyze3-5.2.*: sqlite3_transfer_bindings() +# +do_test analyze3-5.1.1 { + drop_all_tables + execsql { + CREATE TABLE t1(x TEXT COLLATE NOCASE); + CREATE INDEX i1 ON t1(x); + INSERT INTO t1 VALUES('aaa'); + INSERT INTO t1 VALUES('abb'); + INSERT INTO t1 VALUES('acc'); + INSERT INTO t1 VALUES('baa'); + INSERT INTO t1 VALUES('bbb'); + INSERT INTO t1 VALUES('bcc'); + } + + set S [sqlite3_prepare_v2 db "SELECT * FROM t1 WHERE x LIKE ?" -1 dummy] + sqlite3_bind_text $S 1 "a%" 2 + set R [list] + while { "SQLITE_ROW" == [sqlite3_step $S] } { + lappend R [sqlite3_column_text $S 0] + } + concat [sqlite3_reset $S] $R +} {SQLITE_OK aaa abb acc} +do_test analyze3-5.1.2 { + sqlite3_clear_bindings $S + set R [list] + while { "SQLITE_ROW" == [sqlite3_step $S] } { + lappend R [sqlite3_column_text $S 0] + } + concat [sqlite3_reset $S] $R +} {SQLITE_OK} +do_test analyze3-5.1.3 { + sqlite3_finalize $S +} {SQLITE_OK} + +do_test analyze3-5.1.1 { + set S1 [sqlite3_prepare_v2 db "SELECT * FROM t1 WHERE x LIKE ?" -1 dummy] + sqlite3_bind_text $S1 1 "b%" 2 + set R [list] + while { "SQLITE_ROW" == [sqlite3_step $S1] } { + lappend R [sqlite3_column_text $S1 0] + } + concat [sqlite3_reset $S1] $R +} {SQLITE_OK baa bbb bcc} + +do_test analyze3-5.1.2 { + set S2 [sqlite3_prepare_v2 db "SELECT * FROM t1 WHERE x = ?" -1 dummy] + sqlite3_bind_text $S2 1 "a%" 2 + sqlite3_transfer_bindings $S2 $S1 + set R [list] + while { "SQLITE_ROW" == [sqlite3_step $S1] } { + lappend R [sqlite3_column_text $S1 0] + } + concat [sqlite3_reset $S1] $R +} {SQLITE_OK aaa abb acc} +do_test analyze3-5.1.3 { + sqlite3_finalize $S2 + sqlite3_finalize $S1 +} {SQLITE_OK} + +#------------------------------------------------------------------------- + +do_test analyze3-6.1 { + execsql { DROP TABLE IF EXISTS t1 } + execsql BEGIN + execsql { CREATE TABLE t1(a, b, c) } + for {set i 0} {$i < 1000} {incr i} { + execsql "INSERT INTO t1 VALUES([expr $i/100], 'x', [expr $i/10])" + } + execsql { + CREATE INDEX i1 ON t1(a, b); + CREATE INDEX i2 ON t1(c); + } + execsql COMMIT + execsql ANALYZE +} {} + +do_eqp_test analyze3-6-3 { + SELECT * FROM t1 WHERE a = 5 AND c = 13; +} {SEARCH t1 USING INDEX i2 (c=?)} + +do_eqp_test analyze3-6-2 { + SELECT * FROM t1 WHERE a = 5 AND b > 'w' AND c = 13; +} {SEARCH t1 USING INDEX i2 (c=?)} + +#----------------------------------------------------------------------------- +# 2015-04-20. +# Memory leak in sqlite3Stat4ProbeFree(). (Discovered while fuzzing.) +# +do_execsql_test analyze-7.1 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c); + INSERT INTO t1 VALUES(1,1,'0000'); + CREATE INDEX t0b ON t1(b); + ANALYZE; + SELECT c FROM t1 WHERE b=3 AND a BETWEEN 30 AND hex(1); +} {} + +# At one point duplicate stat1 entries were causing a memory leak. +# +reset_db +do_execsql_test 7.2 { + CREATE TABLE t1(a,b,c); + CREATE INDEX t1a ON t1(a); + ANALYZE; + SELECT * FROM sqlite_stat1; + INSERT INTO sqlite_stat1(tbl,idx,stat) VALUES('t1','t1a','12000'); + INSERT INTO sqlite_stat1(tbl,idx,stat) VALUES('t1','t1a','12000'); + ANALYZE sqlite_master; +} + +# 2023-04-22 https://sqlite.org/forum/info/6c118daad0f1f5ef +# Case differences in the sqlite_stat4.idx field should not matter. +# +reset_db +do_execsql_test 8.0 { + CREATE TABLE t1(a PRIMARY KEY, v) WITHOUT ROWID; + ANALYZE sqlite_schema; + INSERT INTO sqlite_stat1 VALUES('t1','t1','1 1'); + INSERT INTO sqlite_stat4 VALUES('t1','t1','1','0','0',X'021b76657273696f6e'); + INSERT INTO sqlite_stat4 VALUES('T1','T1','1','0','0',X'021b76657273696f6e'); + ANALYZE sqlite_schema; +} {} + +# 2023-05-03 https://sqlite.org/forum/forumpost/537d8ab118 +# Same index appears by two different names in the sqlite_stat4 table. +# +reset_db +do_execsql_test 8.1 { + CREATE TABLE t1(a INT PRIMARY KEY, b INT) WITHOUT ROWID; + ANALYZE sqlite_schema; + INSERT INTO sqlite_stat4 VALUES + ('t1','t1','1','2','2',X'03000103'), + ('t1','sqlite_autoindex_t1_1','1','2','2',X'03000103'); + ANALYZE sqlite_schema; + PRAGMA integrity_check; +} {ok} + +finish_test diff --git a/test/analyze4.test b/test/analyze4.test new file mode 100644 index 0000000..d4f1921 --- /dev/null +++ b/test/analyze4.test @@ -0,0 +1,117 @@ +# 2011 January 04 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file implements regression tests for SQLite library. This file +# implements tests for ANALYZE to verify that multiple rows containing +# a NULL value count as distinct rows for the purposes of analyze +# statistics. +# +# Also include test cases for collating sequences on indices. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. +ifcapable !altertable { + finish_test + return +} + +do_test analyze4-1.0 { + db eval { + CREATE TABLE t1(a,b); + CREATE INDEX t1a ON t1(a); + CREATE INDEX t1b ON t1(b); + INSERT INTO t1 VALUES(1,NULL); + INSERT INTO t1 SELECT a+1, b FROM t1; + INSERT INTO t1 SELECT a+2, b FROM t1; + INSERT INTO t1 SELECT a+4, b FROM t1; + INSERT INTO t1 SELECT a+8, b FROM t1; + INSERT INTO t1 SELECT a+16, b FROM t1; + INSERT INTO t1 SELECT a+32, b FROM t1; + INSERT INTO t1 SELECT a+64, b FROM t1; + ANALYZE; + } + + # Should choose the t1a index since it is more specific than t1b. + db eval {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE a=5 AND b IS NULL} +} {/*SEARCH t1 USING INDEX t1a (a=?)*/} + +# Verify that the t1b index shows that it does not narrow down the +# search any at all. +# +do_test analyze4-1.1 { + db eval { + SELECT idx, stat FROM sqlite_stat1 WHERE tbl='t1' ORDER BY idx; + } +} {t1a {128 1} t1b {128 128}} + +# Change half of the b values from NULL to a constant. Verify +# that the number of rows selected in stat1 is half the total +# number of rows. +# +do_test analyze4-1.2 { + db eval { + UPDATE t1 SET b='x' WHERE a%2; + ANALYZE; + SELECT idx, stat FROM sqlite_stat1 WHERE tbl='t1' ORDER BY idx; + } +} {t1a {128 1} t1b {128 64}} + +# Change the t1.b values all back to NULL. Add columns t1.c and t1.d. +# Create a multi-column indices using t1.b and verify that ANALYZE +# processes them correctly. +# +do_test analyze4-1.3 { + db eval { + UPDATE t1 SET b=NULL; + ALTER TABLE t1 ADD COLUMN c; + ALTER TABLE t1 ADD COLUMN d; + UPDATE t1 SET c=a/4, d=a/2; + CREATE INDEX t1bcd ON t1(b,c,d); + CREATE INDEX t1cdb ON t1(c,d,b); + CREATE INDEX t1cbd ON t1(c,b,d); + ANALYZE; + SELECT idx, stat FROM sqlite_stat1 WHERE tbl='t1' ORDER BY idx; + } +} {t1a {128 1} t1b {128 128} t1bcd {128 128 4 2} t1cbd {128 4 4 2} t1cdb {128 4 2 2}} + +# Verify that collating sequences are taken into account when computing +# ANALYZE statistics. +# +do_test analyze4-2.0 { + db eval { + CREATE TABLE t2( + x INTEGER PRIMARY KEY, + a TEXT COLLATE nocase, + b TEXT COLLATE rtrim, + c TEXT COLLATE binary + ); + CREATE INDEX t2a ON t2(a); + CREATE INDEX t2b ON t2(b); + CREATE INDEX t2c ON t2(c); + CREATE INDEX t2c2 ON t2(c COLLATE nocase); + CREATE INDEX t2c3 ON t2(c COLLATE rtrim); + INSERT INTO t2 VALUES(1, 'abc', 'abc', 'abc'); + INSERT INTO t2 VALUES(2, 'abC', 'abC', 'abC'); + INSERT INTO t2 VALUES(3, 'abc ', 'abc ', 'abc '); + INSERT INTO t2 VALUES(4, 'abC ', 'abC ', 'abC '); + INSERT INTO t2 VALUES(5, 'aBc', 'aBc', 'aBc'); + INSERT INTO t2 VALUES(6, 'aBC', 'aBC', 'aBC'); + INSERT INTO t2 VALUES(7, 'aBc ', 'aBc ', 'aBc '); + INSERT INTO t2 VALUES(8, 'aBC ', 'aBC ', 'aBC '); + ANALYZE; + SELECT idx, stat FROM sqlite_stat1 WHERE tbl='t2' ORDER BY idx; + } +} {t2a {8 4} t2b {8 2} t2c {8 1} t2c2 {8 4} t2c3 {8 2}} + +finish_test diff --git a/test/analyze5.test b/test/analyze5.test new file mode 100644 index 0000000..e58457a --- /dev/null +++ b/test/analyze5.test @@ -0,0 +1,247 @@ +# 2011 January 19 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file implements tests for SQLite library. The focus of the tests +# in this file is the use of the sqlite_stat4 histogram data on tables +# with many repeated values and only a few distinct values. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !stat4 { + finish_test + return +} + +set testprefix analyze5 + +proc eqp {sql {db db}} { + uplevel execsql [list "EXPLAIN QUERY PLAN $sql"] $db +} + +proc alpha {blob} { + set ret "" + foreach c [split $blob {}] { + if {[string is alpha $c]} {append ret $c} + } + return $ret +} +db func alpha alpha + +db func lindex lindex + +unset -nocomplain i t u v w x y z +do_test analyze5-1.0 { + db eval {CREATE TABLE t1(t,u,v TEXT COLLATE nocase,w,x,y,z)} + for {set i 0} {$i < 1000} {incr i} { + set y [expr {$i>=25 && $i<=50}] + set z [expr {($i>=400) + ($i>=700) + ($i>=875)}] + set x $z + set w $z + set t [expr {$z+0.5}] + switch $z { + 0 {set u "alpha"; unset x} + 1 {set u "bravo"} + 2 {set u "charlie"} + 3 {set u "delta"; unset w} + } + if {$i%2} {set v $u} {set v [string toupper $u]} + db eval {INSERT INTO t1 VALUES($t,$u,$v,$w,$x,$y,$z)} + } + db eval { + CREATE INDEX t1t ON t1(t); -- 0.5, 1.5, 2.5, and 3.5 + CREATE INDEX t1u ON t1(u); -- text + CREATE INDEX t1v ON t1(v); -- mixed case text + CREATE INDEX t1w ON t1(w); -- integers 0, 1, 2 and a few NULLs + CREATE INDEX t1x ON t1(x); -- integers 1, 2, 3 and many NULLs + CREATE INDEX t1y ON t1(y); -- integers 0 and very few 1s + CREATE INDEX t1z ON t1(z); -- integers 0, 1, 2, and 3 + ANALYZE; + } + db eval { + SELECT DISTINCT lindex(test_decode(sample),0) + FROM sqlite_stat4 WHERE idx='t1u' ORDER BY nlt; + } +} {alpha bravo charlie delta} + +do_test analyze5-1.1 { + db eval { + SELECT DISTINCT lower(lindex(test_decode(sample), 0)) + FROM sqlite_stat4 WHERE idx='t1v' ORDER BY 1 + } +} {alpha bravo charlie delta} +do_test analyze5-1.2 { + db eval {SELECT idx, count(*) FROM sqlite_stat4 GROUP BY 1 ORDER BY 1} +} {t1t 8 t1u 8 t1v 8 t1w 8 t1x 8 t1y 9 t1z 8} + +# Verify that range queries generate the correct row count estimates +# +foreach {testid where index rows} { + 1 {z>=0 AND z<=0} t1z 400 + 2 {z>=1 AND z<=1} t1z 300 + 3 {z>=2 AND z<=2} t1z 175 + 4 {z>=3 AND z<=3} t1z 125 + 5 {z>=4 AND z<=4} t1z 1 + 6 {z>=-1 AND z<=-1} t1z 1 + 7 {z>1 AND z<3} t1z 175 + 8 {z>0 AND z<100} t1z 600 + 9 {z>=1 AND z<100} t1z 600 + 10 {z>1 AND z<100} t1z 300 + 11 {z>=2 AND z<100} t1z 300 + 12 {z>2 AND z<100} t1z 125 + 13 {z>=3 AND z<100} t1z 125 + 14 {z>3 AND z<100} t1z 1 + 15 {z>=4 AND z<100} t1z 1 + 16 {z>=-100 AND z<=-1} t1z 1 + 17 {z>=-100 AND z<=0} t1z 400 + 18 {z>=-100 AND z<0} t1z 1 + 19 {z>=-100 AND z<=1} t1z 700 + 20 {z>=-100 AND z<2} t1z 700 + 21 {z>=-100 AND z<=2} t1z 875 + 22 {z>=-100 AND z<3} t1z 875 + + 31 {z>=0.0 AND z<=0.0} t1z 400 + 32 {z>=1.0 AND z<=1.0} t1z 300 + 33 {z>=2.0 AND z<=2.0} t1z 175 + 34 {z>=3.0 AND z<=3.0} t1z 125 + 35 {z>=4.0 AND z<=4.0} t1z 1 + 36 {z>=-1.0 AND z<=-1.0} t1z 1 + 37 {z>1.5 AND z<3.0} t1z 174 + 38 {z>0.5 AND z<100} t1z 599 + 39 {z>=1.0 AND z<100} t1z 600 + 40 {z>1.5 AND z<100} t1z 299 + 41 {z>=2.0 AND z<100} t1z 300 + 42 {z>2.1 AND z<100} t1z 124 + 43 {z>=3.0 AND z<100} t1z 125 + 44 {z>3.2 AND z<100} t1z 1 + 45 {z>=4.0 AND z<100} t1z 1 + 46 {z>=-100 AND z<=-1.0} t1z 1 + 47 {z>=-100 AND z<=0.0} t1z 400 + 48 {z>=-100 AND z<0.0} t1z 1 + 49 {z>=-100 AND z<=1.0} t1z 700 + 50 {z>=-100 AND z<2.0} t1z 700 + 51 {z>=-100 AND z<=2.0} t1z 875 + 52 {z>=-100 AND z<3.0} t1z 875 + + 101 {z=-1} t1z 1 + 102 {z=0} t1z 400 + 103 {z=1} t1z 300 + 104 {z=2} t1z 175 + 105 {z=3} t1z 125 + 106 {z=4} t1z 1 + 107 {z=-10.0} t1z 1 + 108 {z=0.0} t1z 400 + 109 {z=1.0} t1z 300 + 110 {z=2.0} t1z 175 + 111 {z=3.0} t1z 125 + 112 {z=4.0} t1z 1 + 113 {z=1.5} t1z 1 + 114 {z=2.5} t1z 1 + + 201 {z IN (-1)} t1z 1 + 202 {z IN (0)} t1z 400 + 203 {z IN (1)} t1z 300 + 204 {z IN (2)} t1z 175 + 205 {z IN (3)} t1z 125 + 206 {z IN (4)} t1z 1 + 207 {z IN (0.5)} t1z 1 + 208 {z IN (0,1)} t1z 700 + 209 {z IN (0,1,2)} t1z 875 + 210 {z IN (0,1,2,3)} {} 100 + 211 {z IN (0,1,2,3,4,5)} {} 100 + 212 {z IN (1,2)} t1z 475 + 213 {z IN (2,3)} t1z 300 + 214 {z=3 OR z=2} t1z 300 + 215 {z IN (-1,3)} t1z 126 + 216 {z=-1 OR z=3} t1z 126 + + 300 {y=0} t1y 974 + 301 {y=1} t1y 26 + 302 {y=0.1} t1y 1 + + 400 {x IS NULL} t1x 400 + +} { + # Verify that the expected index is used with the expected row count + # No longer valid due to an EXPLAIN QUERY PLAN output format change + # do_test analyze5-1.${testid}a { + # set x [lindex [eqp "SELECT * FROM t1 WHERE $where"] 3] + # set idx {} + # regexp {INDEX (t1.) } $x all idx + # regexp {~([0-9]+) rows} $x all nrow + # list $idx $nrow + # } [list $index $rows] + + # Verify that the same result is achieved regardless of whether or not + # the index is used + do_test analyze5-1.${testid}b { + set w2 [string map {y +y z +z} $where] + set a1 [db eval "SELECT rowid FROM t1 NOT INDEXED WHERE $w2\ + ORDER BY +rowid"] + set a2 [db eval "SELECT rowid FROM t1 WHERE $where ORDER BY +rowid"] + if {$a1==$a2} { + set res ok + } else { + set res "a1=\[$a1\] a2=\[$a2\]" + } + set res + } {ok} +} + +# Increase the number of NULLs in column x +# +db eval { + UPDATE t1 SET x=NULL; + UPDATE t1 SET x=rowid + WHERE rowid IN (SELECT rowid FROM t1 ORDER BY random() LIMIT 5); + ANALYZE; +} + +# Verify that range queries generate the correct row count estimates +# +foreach {testid where index rows} { + 500 {x IS NULL AND u='charlie'} t1u 17 + 501 {x=1 AND u='charlie'} t1x 1 + 502 {x IS NULL} t1x 995 + 503 {x=1} t1x 1 + 504 {x IS NOT NULL} t1x 2 + 505 {+x IS NOT NULL} {} 500 + 506 {upper(x) IS NOT NULL} {} 500 + +} { + # Verify that the expected index is used with the expected row count + # No longer valid due to an EXPLAIN QUERY PLAN format change + # do_test analyze5-1.${testid}a { + # set x [lindex [eqp "SELECT * FROM t1 WHERE $where"] 3] + # set idx {} + # regexp {INDEX (t1.) } $x all idx + # regexp {~([0-9]+) rows} $x all nrow + # list $idx $nrow + # } [list $index $rows] + + # Verify that the same result is achieved regardless of whether or not + # the index is used + do_test analyze5-1.${testid}b { + set w2 [string map {y +y z +z} $where] + set a1 [db eval "SELECT rowid FROM t1 NOT INDEXED WHERE $w2\ + ORDER BY +rowid"] + set a2 [db eval "SELECT rowid FROM t1 WHERE $where ORDER BY +rowid"] + if {$a1==$a2} { + set res ok + } else { + set res "a1=\[$a1\] a2=\[$a2\]" + } + set res + } {ok} +} + +finish_test diff --git a/test/analyze6.test b/test/analyze6.test new file mode 100644 index 0000000..807fec1 --- /dev/null +++ b/test/analyze6.test @@ -0,0 +1,126 @@ +# 2011 March 3 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file implements tests for SQLite library. The focus of the tests +# in this file a corner-case query planner optimization involving the +# join order of two tables of different sizes. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !stat4 { + finish_test + return +} + +set testprefix analyze6 + +proc eqp {sql {db db}} { + uplevel execsql [list "EXPLAIN QUERY PLAN $sql"] $db +} + +do_test analyze6-1.0 { + db eval { + CREATE TABLE cat(x INT, yz TEXT); + CREATE UNIQUE INDEX catx ON cat(x); + /* Give cat 16 unique integers */ + INSERT INTO cat(x) VALUES(1); + INSERT INTO cat(x) VALUES(2); + INSERT INTO cat(x) SELECT x+2 FROM cat; + INSERT INTO cat(x) SELECT x+4 FROM cat; + INSERT INTO cat(x) SELECT x+8 FROM cat; + + CREATE TABLE ev(y INT); + CREATE INDEX evy ON ev(y); + /* ev will hold 32 copies of 16 integers found in cat */ + INSERT INTO ev SELECT x FROM cat; + INSERT INTO ev SELECT x FROM cat; + INSERT INTO ev SELECT y FROM ev; + INSERT INTO ev SELECT y FROM ev; + INSERT INTO ev SELECT y FROM ev; + INSERT INTO ev SELECT y FROM ev; + ANALYZE; + SELECT count(*) FROM cat; + SELECT count(*) FROM ev; + } +} {16 512} + +# The lowest cost plan is to scan CAT and for each integer there, do a single +# lookup of the first corresponding entry in EV then read off the equal values +# in EV. (Prior to the 2011-03-04 enhancement to where.c, this query would +# have used EV for the outer loop instead of CAT - which was about 3x slower.) +# +do_test analyze6-1.1 { + eqp {SELECT count(*) FROM ev, cat WHERE x=y} +} {/*SCAN cat USING COVERING INDEX catx*SEARCH ev USING COVERING INDEX evy (y=?)*/} + +# The same plan is chosen regardless of the order of the tables in the +# FROM clause. +# +do_eqp_test analyze6-1.2 { + SELECT count(*) FROM cat, ev WHERE x=y +} { + QUERY PLAN + |--SCAN cat USING COVERING INDEX catx + `--SEARCH ev USING COVERING INDEX evy (y=?) +} + + +# Ticket [83ea97620bd3101645138b7b0e71c12c5498fe3d] 2011-03-30 +# If ANALYZE is run on an empty table, make sure indices are used +# on the table. +# +do_test analyze6-2.1 { + execsql { + CREATE TABLE t201(x INTEGER PRIMARY KEY, y UNIQUE, z); + CREATE INDEX t201z ON t201(z); + ANALYZE; + } + eqp {SELECT * FROM t201 WHERE z=5} +} {/*SEARCH t201 USING INDEX t201z (z=?)*/} +do_test analyze6-2.2 { + eqp {SELECT * FROM t201 WHERE y=5} +} {/*SEARCH t201 USING INDEX sqlite_autoindex_t201_1 (y=?)*/} +do_test analyze6-2.3 { + eqp {SELECT * FROM t201 WHERE x=5} +} {/*SEARCH t201 USING INTEGER PRIMARY KEY (rowid=?)*/} +do_test analyze6-2.4 { + execsql { + INSERT INTO t201 VALUES(1,2,3),(2,3,4),(3,4,5); + ANALYZE t201; + } + eqp {SELECT * FROM t201 WHERE z=5} +} {/*SEARCH t201 USING INDEX t201z (z=?)*/} +do_test analyze6-2.5 { + eqp {SELECT * FROM t201 WHERE y=5} +} {/*SEARCH t201 USING INDEX sqlite_autoindex_t201_1 (y=?)*/} +do_test analyze6-2.6 { + eqp {SELECT * FROM t201 WHERE x=5} +} {/*SEARCH t201 USING INTEGER PRIMARY KEY (rowid=?)*/} +do_test analyze6-2.7 { + execsql { + INSERT INTO t201 VALUES(4,5,7); + INSERT INTO t201 SELECT x+100, y+100, z+100 FROM t201; + INSERT INTO t201 SELECT x+200, y+200, z+200 FROM t201; + INSERT INTO t201 SELECT x+400, y+400, z+400 FROM t201; + ANALYZE t201; + } + eqp {SELECT * FROM t201 WHERE z=5} +} {/*SEARCH t201 USING INDEX t201z (z=?)*/} +do_test analyze6-2.8 { + eqp {SELECT * FROM t201 WHERE y=5} +} {/*SEARCH t201 USING INDEX sqlite_autoindex_t201_1 (y=?)*/} +do_test analyze6-2.9 { + eqp {SELECT * FROM t201 WHERE x=5} +} {/*SEARCH t201 USING INTEGER PRIMARY KEY (rowid=?)*/} + +finish_test diff --git a/test/analyze7.test b/test/analyze7.test new file mode 100644 index 0000000..53a80f6 --- /dev/null +++ b/test/analyze7.test @@ -0,0 +1,114 @@ +# 2011 April 1 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# This file implements tests for the ANALYZE command when an idnex +# name is given as the argument. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# There is nothing to test if ANALYZE is disable for this build. +# +ifcapable {!analyze||!vtab} { + finish_test + return +} + +# Generate some test data +# +do_test analyze7-1.0 { + load_static_extension db wholenumber + execsql { + CREATE TABLE t1(a,b,c,d); + CREATE INDEX t1a ON t1(a); + CREATE INDEX t1b ON t1(b); + CREATE INDEX t1cd ON t1(c,d); + CREATE VIRTUAL TABLE nums USING wholenumber; + INSERT INTO t1 SELECT value, value, value/100, value FROM nums + WHERE value BETWEEN 1 AND 256; + EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE a=123; + } +} {/*SEARCH t1 USING INDEX t1a (a=?)*/} +do_test analyze7-1.1 { + execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE b=123;} +} {/*SEARCH t1 USING INDEX t1b (b=?)*/} +do_test analyze7-1.2 { + execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE c=2;} +} {/*SEARCH t1 USING INDEX t1cd (c=?)*/} + +# Run an analyze on one of the three indices. Verify that this +# effects the row-count estimate on the one query that uses that +# one index. +# +do_test analyze7-2.0 { + execsql {ANALYZE t1a;} + db cache flush + execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE a=123;} +} {/*SEARCH t1 USING INDEX t1a (a=?)*/} +do_test analyze7-2.1 { + execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE b=123;} +} {/*SEARCH t1 USING INDEX t1b (b=?)*/} +do_test analyze7-2.2 { + execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE c=2;} +} {/*SEARCH t1 USING INDEX t1cd (c=?)*/} + +# Verify that since the query planner now things that t1a is more +# selective than t1b, it prefers to use t1a. +# +do_test analyze7-2.3 { + execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE a=123 AND b=123} +} {/*SEARCH t1 USING INDEX t1a (a=?)*/} + +# Run an analysis on another of the three indices. Verify that this +# new analysis works and does not disrupt the previous analysis. +# +do_test analyze7-3.0 { + execsql {ANALYZE t1cd;} + db cache flush; + execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE a=123;} +} {/*SEARCH t1 USING INDEX t1a (a=?)*/} +do_test analyze7-3.1 { + execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE b=123;} +} {/*SEARCH t1 USING INDEX t1b (b=?)*/} +do_test analyze7-3.2.1 { + execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE c=?;} +} {/*SEARCH t1 USING INDEX t1cd (c=?)*/} +ifcapable stat4 { + # If ENABLE_STAT4 is defined, SQLite comes up with a different estimated + # row count for (c=2) than it does for (c=?). + do_test analyze7-3.2.2 { + execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE c=2;} + } {/*SEARCH t1 USING INDEX t1cd (c=?)*/} +} else { + # If ENABLE_STAT4 is not defined, the expected row count for (c=2) is the + # same as that for (c=?). + do_test analyze7-3.2.3 { + execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE c=2;} + } {/*SEARCH t1 USING INDEX t1cd (c=?)*/} +} +do_test analyze7-3.3 { + execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE a=123 AND b=123} +} {/*SEARCH t1 USING INDEX t1a (a=?)*/} + +ifcapable {!stat4} { + do_test analyze7-3.4 { + execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE c=123 AND b=123} + } {/*SEARCH t1 USING INDEX t1b (b=?)*/} + do_test analyze7-3.5 { + execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE a=123 AND c=123} + } {/*SEARCH t1 USING INDEX t1a (a=?)*/} +} +do_test analyze7-3.6 { + execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE c=123 AND d=123 AND b=123} +} {/*SEARCH t1 USING INDEX t1cd (c=? AND d=?)*/} + +finish_test diff --git a/test/analyze8.test b/test/analyze8.test new file mode 100644 index 0000000..69605fd --- /dev/null +++ b/test/analyze8.test @@ -0,0 +1,115 @@ +# 2011 August 13 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file implements tests for SQLite library. The focus of the tests +# in this file is testing the capabilities of sqlite_stat4. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !stat4 { + finish_test + return +} + +set testprefix analyze8 + +proc eqp {sql {db db}} { + uplevel execsql [list "EXPLAIN QUERY PLAN $sql"] $db +} + +# Scenario: +# +# Two indices. One has mostly singleton entries, but for a few +# values there are hundreds of entries. The other has 10-20 +# entries per value. +# +# Verify that the query planner chooses the first index for the singleton +# entries and the second index for the others. +# +do_test 1.0 { + db eval { + CREATE TABLE t1(a,b,c,d); + CREATE INDEX t1a ON t1(a); + CREATE INDEX t1b ON t1(b); + CREATE INDEX t1c ON t1(c); + } + for {set i 0} {$i<1000} {incr i} { + if {$i%2==0} {set a $i} {set a [expr {($i%8)*100}]} + set b [expr {$i/10}] + set c [expr {$i/8}] + set c [expr {$c*$c*$c}] + db eval {INSERT INTO t1 VALUES($a,$b,$c,$i)} + } + db eval {ANALYZE} +} {} + +# The a==100 comparison is expensive because there are many rows +# with a==100. And so for those cases, choose the t1b index. +# +# Buf ro a==99 and a==101, there are far fewer rows so choose +# the t1a index. +# +do_test 1.1 { + eqp {SELECT * FROM t1 WHERE a=100 AND b=55} +} {/*SEARCH t1 USING INDEX t1b (b=?)*/} +do_test 1.2 { + eqp {SELECT * FROM t1 WHERE a=99 AND b=55} +} {/*SEARCH t1 USING INDEX t1a (a=?)*/} +do_test 1.3 { + eqp {SELECT * FROM t1 WHERE a=101 AND b=55} +} {/*SEARCH t1 USING INDEX t1a (a=?)*/} +do_test 1.4 { + eqp {SELECT * FROM t1 WHERE a=100 AND b=56} +} {/*SEARCH t1 USING INDEX t1b (b=?)*/} +do_test 1.5 { + eqp {SELECT * FROM t1 WHERE a=99 AND b=56} +} {/*SEARCH t1 USING INDEX t1a (a=?)*/} +do_test 1.6 { + eqp {SELECT * FROM t1 WHERE a=101 AND b=56} +} {/*SEARCH t1 USING INDEX t1a (a=?)*/} +do_test 2.1 { + eqp {SELECT * FROM t1 WHERE a=100 AND b BETWEEN 50 AND 54} +} {/*SEARCH t1 USING INDEX t1b (b>? AND b? AND b? AND c? AND c90} { set a $i } else { set a NULL } + set b [expr $i % 5] + execsql "INSERT INTO t3 VALUES($a, $b)" + } + execsql ANALYZE +} {} +do_eqp_test 10.1.3 { + SELECT * FROM t3 WHERE a IS NULL AND b = 2 +} {/t3 USING INDEX t3b/} +do_eqp_test 10.1.4 { + SELECT * FROM t3 WHERE a IS NOT NULL AND b = 2 +} {/t3 USING INDEX t3a/} + +do_execsql_test 10.2.1 { + DROP TABLE IF EXISTS t3; + CREATE TABLE t3(x, a, b); + CREATE INDEX t3a ON t3(x, a); + CREATE INDEX t3b ON t3(x, b); +} +do_test 10.2.2 { + for {set i 1} {$i < 100} {incr i} { + if {$i>90} { set a $i } else { set a NULL } + set b [expr $i % 5] + execsql "INSERT INTO t3 VALUES('xyz', $a, $b)" + } + execsql ANALYZE +} {} +do_eqp_test 10.2.3 { + SELECT * FROM t3 WHERE x = 'xyz' AND a IS NULL AND b = 2 +} {/t3 USING INDEX t3b/} +do_eqp_test 10.2.4 { + SELECT * FROM t3 WHERE x = 'xyz' AND a IS NOT NULL AND b = 2 +} {/t3 USING INDEX t3a/} + +#------------------------------------------------------------------------- +# Check that stat4 data is used correctly with non-default collation +# sequences. +# +foreach {tn schema} { + 1 { + CREATE TABLE t4(a COLLATE nocase, b); + CREATE INDEX t4a ON t4(a); + CREATE INDEX t4b ON t4(b); + } + 2 { + CREATE TABLE t4(a, b); + CREATE INDEX t4a ON t4(a COLLATE nocase); + CREATE INDEX t4b ON t4(b); + } +} { + drop_all_tables + do_test 11.$tn.1 { execsql $schema } {} + + do_test 11.$tn.2 { + for {set i 0} {$i < 100} {incr i} { + if { ($i % 10)==0 } { set a ABC } else { set a DEF } + set b [expr $i % 5] + execsql { INSERT INTO t4 VALUES($a, $b) } + } + execsql ANALYZE + } {} + + do_eqp_test 11.$tn.3 { + SELECT * FROM t4 WHERE a = 'def' AND b = 3; + } {/t4 USING INDEX t4b/} + + if {$tn==1} { + set sql "SELECT * FROM t4 WHERE a = 'abc' AND b = 3;" + do_eqp_test 11.$tn.4 $sql {/t4 USING INDEX t4a/} + } else { + + set sql "SELECT * FROM t4 WHERE a = 'abc' COLLATE nocase AND b = 3;" + do_eqp_test 11.$tn.5 $sql {/t4 USING INDEX t4a/} + + set sql "SELECT * FROM t4 WHERE a COLLATE nocase = 'abc' AND b = 3;" + do_eqp_test 11.$tn.6 $sql {/t4 USING INDEX t4a/} + } +} + +foreach {tn schema} { + 1 { + CREATE TABLE t4(x, a COLLATE nocase, b); + CREATE INDEX t4a ON t4(x, a); + CREATE INDEX t4b ON t4(x, b); + } + 2 { + CREATE TABLE t4(x, a, b); + CREATE INDEX t4a ON t4(x, a COLLATE nocase); + CREATE INDEX t4b ON t4(x, b); + } +} { + drop_all_tables + do_test 12.$tn.1 { execsql $schema } {} + + do_test 12.$tn.2 { + for {set i 0} {$i < 100} {incr i} { + if { ($i % 10)==0 } { set a ABC } else { set a DEF } + set b [expr $i % 5] + execsql { INSERT INTO t4 VALUES(X'abcdef', $a, $b) } + } + execsql ANALYZE + } {} + + do_eqp_test 12.$tn.3 { + SELECT * FROM t4 WHERE x=X'abcdef' AND a = 'def' AND b = 3; + } {/t4 USING INDEX t4b/} + + if {$tn==1} { + set sql "SELECT * FROM t4 WHERE x=X'abcdef' AND a = 'abc' AND b = 3;" + do_eqp_test 12.$tn.4 $sql {/t4 USING INDEX t4a/} + } else { + set sql { + SELECT * FROM t4 WHERE x=X'abcdef' AND a = 'abc' COLLATE nocase AND b = 3 + } + do_eqp_test 12.$tn.5 $sql {/t4 USING INDEX t4a/} + set sql { + SELECT * FROM t4 WHERE x=X'abcdef' AND a COLLATE nocase = 'abc' AND b = 3 + } + do_eqp_test 12.$tn.6 $sql {/t4 USING INDEX t4a/} + } +} + +#------------------------------------------------------------------------- +# Check that affinities are taken into account when using stat4 data to +# estimate the number of rows scanned by a rowid constraint. +# +drop_all_tables +do_test 13.1 { + execsql { + CREATE TABLE t1(a, b, c, d); + CREATE INDEX i1 ON t1(a); + CREATE INDEX i2 ON t1(b, c); + } + for {set i 0} {$i<100} {incr i} { + if {$i %2} {set a abc} else {set a def} + execsql { INSERT INTO t1(rowid, a, b, c) VALUES($i, $a, $i, $i) } + } + execsql ANALYZE +} {} +do_eqp_test 13.2.1 { + SELECT * FROM t1 WHERE a='abc' AND rowid<15 AND b<12 +} {/SEARCH t1 USING INDEX i1/} +do_eqp_test 13.2.2 { + SELECT * FROM t1 WHERE a='abc' AND rowid<'15' AND b<12 +} {/SEARCH t1 USING INDEX i1/} +do_eqp_test 13.3.1 { + SELECT * FROM t1 WHERE a='abc' AND rowid<100 AND b<12 +} {/SEARCH t1 USING INDEX i2/} +do_eqp_test 13.3.2 { + SELECT * FROM t1 WHERE a='abc' AND rowid<'100' AND b<12 +} {/SEARCH t1 USING INDEX i2/} + +#------------------------------------------------------------------------- +# Check also that affinities are taken into account when using stat4 data +# to estimate the number of rows scanned by any other constraint on a +# column other than the leftmost. +# +drop_all_tables +do_test 14.1 { + execsql { CREATE TABLE t1(a, b INTEGER, c) } + for {set i 0} {$i<100} {incr i} { + set c [expr $i % 3] + execsql { INSERT INTO t1 VALUES('ott', $i, $c) } + } + execsql { + CREATE INDEX i1 ON t1(a, b); + CREATE INDEX i2 ON t1(c); + ANALYZE; + } +} {} +do_eqp_test 13.2.1 { + SELECT * FROM t1 WHERE a='ott' AND b<10 AND c=1 +} {/SEARCH t1 USING INDEX i1/} +do_eqp_test 13.2.2 { + SELECT * FROM t1 WHERE a='ott' AND b<'10' AND c=1 +} {/SEARCH t1 USING INDEX i1/} + +#------------------------------------------------------------------------- +# By default, 16 non-periodic samples are collected for the stat4 table. +# The following tests attempt to verify that the most common keys are +# being collected. +# +proc check_stat4 {tn} { + db eval ANALYZE + db eval {SELECT a, b, c, d FROM t1} { + incr k($a) + incr k([list $a $b]) + incr k([list $a $b $c]) + if { [info exists k([list $a $b $c $d])]==0 } { incr nRow } + incr k([list $a $b $c $d]) + } + + set L [list] + foreach key [array names k] { + lappend L [list $k($key) $key] + } + + set nSample $nRow + if {$nSample>16} {set nSample 16} + + set nThreshold [lindex [lsort -decr -integer -index 0 $L] [expr $nSample-1] 0] + foreach key [array names k] { + if {$k($key)>$nThreshold} { + set expect($key) 1 + } + if {$k($key)==$nThreshold} { + set possible($key) 1 + } + } + + + set nPossible [expr $nSample - [llength [array names expect]]] + + #puts "EXPECT: [array names expect]" + #puts "POSSIBLE($nPossible/[array size possible]): [array names possible]" + #puts "HAVE: [db eval {SELECT test_decode(sample) FROM sqlite_stat4 WHERE idx='i1'}]" + + db eval {SELECT test_decode(sample) AS s FROM sqlite_stat4 WHERE idx='i1'} { + set seen 0 + for {set i 0} {$i<4} {incr i} { + unset -nocomplain expect([lrange $s 0 $i]) + if {[info exists possible([lrange $s 0 $i])]} { + set seen 1 + unset -nocomplain possible([lrange $s 0 $i]) + } + } + if {$seen} {incr nPossible -1} + } + if {$nPossible<0} {set nPossible 0} + + set res [list [llength [array names expect]] $nPossible] + uplevel [list do_test $tn [list set {} $res] {0 0}] +} + +drop_all_tables +do_test 14.1.1 { + execsql { + CREATE TABLE t1(a,b,c,d); + CREATE INDEX i1 ON t1(a,b,c,d); + } + for {set i 0} {$i < 160} {incr i} { + execsql { INSERT INTO t1 VALUES($i,$i,$i,$i) } + if {($i % 10)==0} { execsql { INSERT INTO t1 VALUES($i,$i,$i,$i) } } + } +} {} +check_stat4 14.1.2 + +do_test 14.2.1 { + execsql { DELETE FROM t1 } + for {set i 0} {$i < 1600} {incr i} { + execsql { INSERT INTO t1 VALUES($i/10,$i/17,$i/27,$i/37) } + } +} {} +check_stat4 14.2.2 + +do_test 14.3.1 { + for {set i 0} {$i < 10} {incr i} { + execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) } + execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) } + execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) } + execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) } + execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) } + execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) } + execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) } + execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) } + execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) } + execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) } + } +} {} +check_stat4 14.3.2 + +do_test 14.4.1 { + execsql {DELETE FROM t1} + for {set i 1} {$i < 160} {incr i} { + set b [expr $i % 10] + if {$b==0 || $b==2} {set b 1} + execsql { INSERT INTO t1 VALUES($i/10,$b,$i,$i) } + } +} {} +check_stat4 14.4.2 +db func lrange lrange +db func lindex lindex +do_execsql_test 14.4.3 { + SELECT lrange(test_decode(sample), 0, 1) AS s FROM sqlite_stat4 + WHERE lindex(s, 1)=='1' ORDER BY rowid +} { + {0 1} {1 1} {2 1} {3 1} + {4 1} {5 1} {6 1} {7 1} + {8 1} {9 1} {10 1} {11 1} + {12 1} {13 1} {14 1} {15 1} +} + +#------------------------------------------------------------------------- +# Test that nothing untoward happens if the stat4 table contains entries +# for indexes that do not exist. Or NULL values in the idx column. +# Or NULL values in any of the other columns. +# +drop_all_tables +do_execsql_test 15.1 { + CREATE TABLE x1(a, b, UNIQUE(a, b)); + INSERT INTO x1 VALUES(1, 2); + INSERT INTO x1 VALUES(3, 4); + INSERT INTO x1 VALUES(5, 6); + ANALYZE; + INSERT INTO sqlite_stat4 VALUES(NULL, NULL, NULL, NULL, NULL, NULL); +} +db close +sqlite3 db test.db +do_execsql_test 15.2 { SELECT * FROM x1 } {1 2 3 4 5 6} + +do_execsql_test 15.3 { + INSERT INTO sqlite_stat4 VALUES(42, 42, 42, 42, 42, 42); +} +db close +sqlite3 db test.db +do_execsql_test 15.4 { SELECT * FROM x1 } {1 2 3 4 5 6} + +do_execsql_test 15.5 { + UPDATE sqlite_stat1 SET stat = NULL; +} +db close +sqlite3 db test.db +do_execsql_test 15.6 { SELECT * FROM x1 } {1 2 3 4 5 6} + +do_execsql_test 15.7 { + ANALYZE; + UPDATE sqlite_stat1 SET tbl = 'no such tbl'; +} +db close +sqlite3 db test.db +do_execsql_test 15.8 { SELECT * FROM x1 } {1 2 3 4 5 6} + +do_execsql_test 15.9 { + ANALYZE; + UPDATE sqlite_stat4 SET neq = NULL, nlt=NULL, ndlt=NULL; +} +db close +sqlite3 db test.db +do_execsql_test 15.10 { SELECT * FROM x1 } {1 2 3 4 5 6} + +# This is just for coverage.... +do_execsql_test 15.11 { + ANALYZE; + UPDATE sqlite_stat1 SET stat = stat || ' unordered'; +} +db close +sqlite3 db test.db +do_execsql_test 15.12 { SELECT * FROM x1 } {1 2 3 4 5 6} + +#------------------------------------------------------------------------- +# Test that allocations used for sqlite_stat4 samples are included in +# the quantity returned by SQLITE_DBSTATUS_SCHEMA_USED. +# +set one [string repeat x 1000] +set two [string repeat x 2000] +do_test 16.1 { + reset_db + execsql { + CREATE TABLE t1(a, UNIQUE(a)); + INSERT INTO t1 VALUES($one); + ANALYZE; + } + set nByte [lindex [sqlite3_db_status db SCHEMA_USED 0] 1] + + reset_db + execsql { + CREATE TABLE t1(a, UNIQUE(a)); + INSERT INTO t1 VALUES($two); + ANALYZE; + } + set nByte2 [lindex [sqlite3_db_status db SCHEMA_USED 0] 1] + puts -nonewline " (nByte=$nByte nByte2=$nByte2)" + + expr {$nByte2 > $nByte+900 && $nByte2 < $nByte+1100} +} {1} + +#------------------------------------------------------------------------- +# Test that stat4 data may be used with partial indexes. +# +do_test 17.1 { + reset_db + execsql { + CREATE TABLE t1(a, b, c, d); + CREATE INDEX i1 ON t1(a, b) WHERE d IS NOT NULL; + INSERT INTO t1 VALUES(-1, -1, -1, NULL); + INSERT INTO t1 SELECT 2*a,2*b,2*c,d FROM t1; + INSERT INTO t1 SELECT 2*a,2*b,2*c,d FROM t1; + INSERT INTO t1 SELECT 2*a,2*b,2*c,d FROM t1; + INSERT INTO t1 SELECT 2*a,2*b,2*c,d FROM t1; + INSERT INTO t1 SELECT 2*a,2*b,2*c,d FROM t1; + INSERT INTO t1 SELECT 2*a,2*b,2*c,d FROM t1; + } + + for {set i 0} {$i < 32} {incr i} { + if {$i<8} {set b 0} else { set b $i } + execsql { INSERT INTO t1 VALUES($i%2, $b, $i/2, 'abc') } + } + execsql {ANALYZE main.t1} +} {} + +do_catchsql_test 17.1.2 { + ANALYZE temp.t1; +} {1 {no such table: temp.t1}} + +do_eqp_test 17.2 { + SELECT * FROM t1 WHERE d IS NOT NULL AND a=0 AND b=10 AND c=10; +} {/USING INDEX i1/} +do_eqp_test 17.3 { + SELECT * FROM t1 WHERE d IS NOT NULL AND a=0 AND b=0 AND c=10; +} {/USING INDEX i1/} + +do_execsql_test 17.4 { + CREATE INDEX i2 ON t1(c, d); + ANALYZE main.i2; +} +do_eqp_test 17.5 { + SELECT * FROM t1 WHERE d IS NOT NULL AND a=0 AND b=10 AND c=10; +} {/USING INDEX i1/} +do_eqp_test 17.6 { + SELECT * FROM t1 WHERE d IS NOT NULL AND a=0 AND b=0 AND c=10; +} {/USING INDEX i2/} + +#------------------------------------------------------------------------- +# +do_test 18.1 { + reset_db + execsql { + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a, b); + } + for {set i 0} {$i < 9} {incr i} { + execsql { + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + } + } + execsql ANALYZE + execsql { SELECT count(*) FROM sqlite_stat4 } +} {9} + +#------------------------------------------------------------------------- +# For coverage. +# +ifcapable view { + do_test 19.1 { + reset_db + execsql { + CREATE TABLE t1(x, y); + CREATE INDEX i1 ON t1(x, y); + CREATE VIEW v1 AS SELECT * FROM t1; + ANALYZE; + } + } {} +} +ifcapable auth { + proc authproc {op args} { + if {$op == "SQLITE_ANALYZE"} { return "SQLITE_DENY" } + return "SQLITE_OK" + } + do_test 19.2 { + reset_db + db auth authproc + execsql { + CREATE TABLE t1(x, y); + CREATE VIEW v1 AS SELECT * FROM t1; + } + catchsql ANALYZE + } {1 {not authorized}} +} + +#------------------------------------------------------------------------- +# +reset_db +proc r {args} { expr rand() } +db func r r +db func lrange lrange +do_test 20.1 { + execsql { + CREATE TABLE t1(a,b,c,d); + CREATE INDEX i1 ON t1(a,b,c,d); + } + for {set i 0} {$i < 16} {incr i} { + execsql { + INSERT INTO t1 VALUES($i, r(), r(), r()); + INSERT INTO t1 VALUES($i, $i, r(), r()); + INSERT INTO t1 VALUES($i, $i, $i, r()); + INSERT INTO t1 VALUES($i, $i, $i, $i); + INSERT INTO t1 VALUES($i, $i, $i, $i); + INSERT INTO t1 VALUES($i, $i, $i, r()); + INSERT INTO t1 VALUES($i, $i, r(), r()); + INSERT INTO t1 VALUES($i, r(), r(), r()); + } + } +} {} +do_execsql_test 20.2 { ANALYZE } +for {set i 0} {$i<16} {incr i} { + set val "$i $i $i $i" + do_execsql_test 20.3.$i { + SELECT count(*) FROM sqlite_stat4 + WHERE lrange(test_decode(sample), 0, 3)=$val + } {1} +} + +#------------------------------------------------------------------------- +# +reset_db + +do_execsql_test 21.0 { + CREATE TABLE t2(a, b); + CREATE INDEX i2 ON t2(a); +} + +do_test 21.1 { + for {set i 1} {$i < 100} {incr i} { + execsql { + INSERT INTO t2 VALUES(CASE WHEN $i < 80 THEN 'one' ELSE 'two' END, $i) + } + } + execsql ANALYZE +} {} + +# Condition (a='one') matches 80% of the table. (rowid<10) reduces this to +# 10%, but (rowid<50) only reduces it to 50%. So in the first case below +# the index is used. In the second, it is not. +# +do_eqp_test 21.2 { + SELECT * FROM t2 WHERE a='one' AND rowid < 10 +} {/*USING INDEX i2 (a=? AND rowid45 AND x<96) THEN 'B' ELSE 'A' END, /* Column "a" */ + x, /* Column "b" */ + CASE WHEN (x<51) THEN 'one' ELSE 'two' END, /* Column "c" */ + x /* Column "d" */ + FROM r; + + CREATE INDEX i3 ON t3(c); + CREATE INDEX i4 ON t3(d); + ANALYZE; +} + +# Expression (c='one' AND a='B') matches 5 table rows. But (c='one' AND a=A') +# matches 45. Expression (d? AND b=? term. Better than + # (a<20) but not as good as (a<10). + do_eqp_test 25.4.1 { + SELECT * FROM t6 WHERE a < 10 AND (b BETWEEN ? AND 60) + } {SEARCH t6 USING INDEX aa (a? AND b 25) matches 76 rows +# (70 * 2/3 + 30). Before, due to the problem, the planner was estimating +# that this matched 100 rows. +# +reset_db +do_execsql_test 26.2.1 { + BEGIN; + CREATE TABLE t1(x, y, z); + CREATE INDEX i1 ON t1(x, y); + CREATE INDEX i2 ON t1(z); + + WITH + cnt(y) AS (SELECT 0 UNION ALL SELECT y+1 FROM cnt WHERE y<99), + letters(x) AS ( + SELECT 'A' UNION SELECT 'B' UNION SELECT 'C' UNION SELECT 'D' + ) + INSERT INTO t1(x, y) SELECT x, y FROM letters, cnt; + + WITH + letters(x) AS ( + SELECT 'A' UNION SELECT 'B' UNION SELECT 'C' UNION SELECT 'D' + ) + INSERT INTO t1(x, y) SELECT x, 70 FROM letters; + + WITH + cnt(i) AS (SELECT 0 UNION ALL SELECT i+1 FROM cnt WHERE i<9999) + INSERT INTO t1(x, y) SELECT i, i FROM cnt; + + UPDATE t1 SET z = (rowid / 95); + ANALYZE; + COMMIT; +} + +do_eqp_test 26.2.2 { + SELECT * FROM t1 WHERE x='B' AND y>25 AND z=?; +} {SEARCH t1 USING INDEX i1 (x=? AND y>?)} + + +finish_test diff --git a/test/analyzeC.test b/test/analyzeC.test new file mode 100644 index 0000000..2f43d57 --- /dev/null +++ b/test/analyzeC.test @@ -0,0 +1,181 @@ +# 2014-07-22 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file contains automated tests used to verify that the text terms +# at the end of sqlite_stat1.stat are processed correctly. +# +# (1) "unordered" means that the index cannot be used for ORDER BY +# or for range queries +# +# (2) "sz=NNN" sets the relative size of the index entries +# +# (3) All other fields are silently ignored +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix analyzeC + +# Baseline case. Range queries work OK. Indexes can be used for +# ORDER BY. +# +do_execsql_test 1.0 { + CREATE TABLE t1(a,b,c); + INSERT INTO t1(a,b,c) + VALUES(1,2,3),(7,8,9),(4,5,6),(10,11,12),(4,8,12),(1,11,111); + CREATE INDEX t1a ON t1(a); + CREATE INDEX t1b ON t1(b); + ANALYZE; + DELETE FROM sqlite_stat1; + INSERT INTO sqlite_stat1(tbl,idx,stat) + VALUES('t1','t1a','12345 2'),('t1','t1b','12345 4'); + ANALYZE sqlite_master; + SELECT *, '#' FROM t1 WHERE a BETWEEN 3 AND 8 ORDER BY c; +} {4 5 6 # 7 8 9 # 4 8 12 #} +do_execsql_test 1.1 { + EXPLAIN QUERY PLAN + SELECT *, '#' FROM t1 WHERE a BETWEEN 3 AND 8 ORDER BY c; +} {/.* USING INDEX t1a .a>. AND a<...*/} +do_execsql_test 1.2 { + SELECT c FROM t1 ORDER BY a; +} {3 111 6 12 9 12} +do_execsql_test 1.3 { + EXPLAIN QUERY PLAN + SELECT c FROM t1 ORDER BY a; +} {/.*SCAN t1 USING INDEX t1a.*/} +do_execsql_test 1.3x { + EXPLAIN QUERY PLAN + SELECT c FROM t1 ORDER BY a; +} {~/.*B-TREE FOR ORDER BY.*/} + +# Now mark the t1a index as "unordered". Range queries and ORDER BY no +# longer use the index, but equality queries do. +# +do_execsql_test 2.0 { + UPDATE sqlite_stat1 SET stat='12345 2 unordered' WHERE idx='t1a'; + ANALYZE sqlite_master; + SELECT *, '#' FROM t1 WHERE a BETWEEN 3 AND 8 ORDER BY c; +} {4 5 6 # 7 8 9 # 4 8 12 #} +do_execsql_test 2.1 { + EXPLAIN QUERY PLAN + SELECT *, '#' FROM t1 WHERE a BETWEEN 3 AND 8 ORDER BY c; +} {~/.*USING INDEX.*/} +do_execsql_test 2.2 { + SELECT c FROM t1 ORDER BY a; +} {3 111 6 12 9 12} +do_execsql_test 2.3 { + EXPLAIN QUERY PLAN + SELECT c FROM t1 ORDER BY a; +} {~/.*USING INDEX.*/} +do_execsql_test 2.3x { + EXPLAIN QUERY PLAN + SELECT c FROM t1 ORDER BY a; +} {/.*B-TREE FOR ORDER BY.*/} + +# Ignore extraneous text parameters in the sqlite_stat1.stat field. +# +do_execsql_test 3.0 { + UPDATE sqlite_stat1 SET stat='12345 2 whatever=5 unordered xyzzy=11' + WHERE idx='t1a'; + ANALYZE sqlite_master; + SELECT *, '#' FROM t1 WHERE a BETWEEN 3 AND 8 ORDER BY c; +} {4 5 6 # 7 8 9 # 4 8 12 #} +do_execsql_test 3.1 { + EXPLAIN QUERY PLAN + SELECT *, '#' FROM t1 WHERE a BETWEEN 3 AND 8 ORDER BY c; +} {~/.*USING INDEX.*/} +do_execsql_test 3.2 { + SELECT c FROM t1 ORDER BY a; +} {3 111 6 12 9 12} +do_execsql_test 3.3 { + EXPLAIN QUERY PLAN + SELECT c FROM t1 ORDER BY a; +} {~/.*USING INDEX.*/} +do_execsql_test 3.3x { + EXPLAIN QUERY PLAN + SELECT c FROM t1 ORDER BY a; +} {/.*B-TREE FOR ORDER BY.*/} + +# The sz=NNN parameter determines which index to scan +# +do_execsql_test 4.0 { + DROP INDEX t1a; + CREATE INDEX t1ab ON t1(a,b); + CREATE INDEX t1ca ON t1(c,a); + DELETE FROM sqlite_stat1; + INSERT INTO sqlite_stat1(tbl,idx,stat) + VALUES('t1','t1ab','12345 3 2 sz=10'),('t1','t1ca','12345 3 2 sz=20'); + ANALYZE sqlite_master; + SELECT count(a) FROM t1; +} {6} +do_execsql_test 4.1 { + EXPLAIN QUERY PLAN + SELECT count(a) FROM t1; +} {/.*INDEX t1ab.*/} +do_execsql_test 4.2 { + DELETE FROM sqlite_stat1; + INSERT INTO sqlite_stat1(tbl,idx,stat) + VALUES('t1','t1ab','12345 3 2 sz=20'),('t1','t1ca','12345 3 2 sz=10'); + ANALYZE sqlite_master; + SELECT count(a) FROM t1; +} {6} +do_execsql_test 4.3 { + EXPLAIN QUERY PLAN + SELECT count(a) FROM t1; +} {/.*INDEX t1ca.*/} + +# 2019-08-15. +# Ticket https://www.sqlite.org/src/tktview/e4598ecbdd18bd82945f602901 +# The sz=N parameter in the sqlite_stat1 table needs to have a value of +# 2 or more to avoid a division by zero in the query planner. +# +do_execsql_test 4.4 { + DROP TABLE IF EXISTS t44; + CREATE TABLE t44(a PRIMARY KEY); + INSERT INTO sqlite_stat1 VALUES('t44',null,'sz=0'); + ANALYZE sqlite_master; + SELECT 0 FROM t44 WHERE a IN(1,2,3); +} {} + + + +# The sz=NNN parameter works even if there is other extraneous text +# in the sqlite_stat1.stat column. +# +do_execsql_test 5.0 { + DELETE FROM sqlite_stat1; + INSERT INTO sqlite_stat1(tbl,idx,stat) + VALUES('t1','t1ab','12345 3 2 x=5 sz=10 y=10'), + ('t1','t1ca','12345 3 2 whatever sz=20 junk'); + ANALYZE sqlite_master; + SELECT count(a) FROM t1; +} {6} +do_execsql_test 5.1 { + EXPLAIN QUERY PLAN + SELECT count(a) FROM t1; +} {/.*INDEX t1ab.*/} +do_execsql_test 5.2 { + DELETE FROM sqlite_stat1; + INSERT INTO sqlite_stat1(tbl,idx,stat) + VALUES('t1','t1ca','12345 3 2 x=5 sz=10 y=10'), + ('t1','t1ab','12345 3 2 whatever sz=20 junk'); + ANALYZE sqlite_master; + SELECT count(a) FROM t1; +} {6} +do_execsql_test 5.3 { + EXPLAIN QUERY PLAN + SELECT count(a) FROM t1; +} {/.*INDEX t1ca.*/} + + + + +finish_test diff --git a/test/analyzeD.test b/test/analyzeD.test new file mode 100644 index 0000000..7a51785 --- /dev/null +++ b/test/analyzeD.test @@ -0,0 +1,107 @@ +# 2014-10-04 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# This file implements tests for the ANALYZE command. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix analyzeD + +ifcapable {!stat4} { + finish_test + return +} + + +# Set up a table with the following properties: +# +# * Contains 1000 rows. +# * Column a contains even integers between 0 and 18, inclusive (so that +# a=? for any such integer matches 100 rows). +# * Column b contains integers between 0 and 9, inclusive. +# * Column c contains integers between 0 and 199, inclusive (so that +# for any such integer, c=? matches 5 rows). +# * Then add 7 rows with a new value for "a" - 3001. The stat4 table will +# not contain any samples with a=3001. +# +do_execsql_test 1.0 { + CREATE TABLE t1(a, b, c); +} +do_test 1.1 { + for {set i 1} {$i < 1000} {incr i} { + set c [expr $i % 200] + execsql { INSERT INTO t1(a, b, c) VALUES( 2*($i/100), $i%10, $c ) } + } + + execsql { + INSERT INTO t1 VALUES(3001, 3001, 3001); + INSERT INTO t1 VALUES(3001, 3001, 3002); + INSERT INTO t1 VALUES(3001, 3001, 3003); + INSERT INTO t1 VALUES(3001, 3001, 3004); + INSERT INTO t1 VALUES(3001, 3001, 3005); + INSERT INTO t1 VALUES(3001, 3001, 3006); + INSERT INTO t1 VALUES(3001, 3001, 3007); + + CREATE INDEX t1_ab ON t1(a, b); + CREATE INDEX t1_c ON t1(c); + + ANALYZE; + } +} {} + +# With full ANALYZE data, SQLite sees that c=150 (5 rows) is better than +# a=3001 (7 rows). +# +do_eqp_test 1.2 { + SELECT * FROM t1 WHERE a=3001 AND c=150; +} {SEARCH t1 USING INDEX t1_c (c=?)} + +do_test 1.3 { + execsql { DELETE FROM sqlite_stat1 } + db close + sqlite3 db test.db +} {} + +# Without stat1, because 3001 is larger than all samples in the stat4 +# table, SQLite thinks that a=3001 matches just 1 row. So it (incorrectly) +# chooses it over the c=150 index (5 rows). Even with stat1 data, things +# worked this way before commit [e6f7f97dbc]. +# +do_eqp_test 1.4 { + SELECT * FROM t1 WHERE a=3001 AND c=150; +} {SEARCH t1 USING INDEX t1_ab (a=?)} + +do_test 1.5 { + execsql { + UPDATE t1 SET a=13 WHERE a = 3001; + ANALYZE; + } +} {} + +do_eqp_test 1.6 { + SELECT * FROM t1 WHERE a=13 AND c=150; +} {SEARCH t1 USING INDEX t1_c (c=?)} + +do_test 1.7 { + execsql { DELETE FROM sqlite_stat1 } + db close + sqlite3 db test.db +} {} + +# Same test as 1.4, except this time the 7 rows that match the a=? condition +# do not feature larger values than all rows in the stat4 table. So SQLite +# gets this right, even without stat1 data. +do_eqp_test 1.8 { + SELECT * FROM t1 WHERE a=13 AND c=150; +} {SEARCH t1 USING INDEX t1_c (c=?)} + +finish_test diff --git a/test/analyzeE.test b/test/analyzeE.test new file mode 100644 index 0000000..2547daa --- /dev/null +++ b/test/analyzeE.test @@ -0,0 +1,294 @@ +# 2014-10-08 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements tests for using STAT4 information +# on a descending index in a range query. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix analyzeE + +ifcapable {!stat4} { + finish_test + return +} + +# Verify that range queries on an ASCENDING index will use the +# index only if the range covers only a small fraction of the +# entries. +# +do_execsql_test analyzeE-1.0 { + CREATE TABLE t1(a,b); + WITH RECURSIVE + cnt(x) AS (VALUES(1000) UNION ALL SELECT x+1 FROM cnt WHERE x<2000) + INSERT INTO t1(a,b) SELECT x, x FROM cnt; + CREATE INDEX t1a ON t1(a); + ANALYZE; +} {} +do_execsql_test analyzeE-1.1 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a BETWEEN 500 AND 2500; +} {/SCAN t1/} +do_execsql_test analyzeE-1.2 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a BETWEEN 2900 AND 3000; +} {/SEARCH t1 USING INDEX t1a/} +do_execsql_test analyzeE-1.3 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a BETWEEN 1700 AND 1750; +} {/SEARCH t1 USING INDEX t1a/} +do_execsql_test analyzeE-1.4 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a BETWEEN 1 AND 500 +} {/SEARCH t1 USING INDEX t1a/} +do_execsql_test analyzeE-1.5 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a BETWEEN 3000 AND 3000000 +} {/SEARCH t1 USING INDEX t1a/} +do_execsql_test analyzeE-1.6 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a<500 +} {/SEARCH t1 USING INDEX t1a/} +do_execsql_test analyzeE-1.7 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a>2500 +} {/SEARCH t1 USING INDEX t1a/} +do_execsql_test analyzeE-1.8 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a>1900 +} {/SEARCH t1 USING INDEX t1a/} +do_execsql_test analyzeE-1.9 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a>1100 +} {/SCAN t1/} +do_execsql_test analyzeE-1.10 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a<1100 +} {/SEARCH t1 USING INDEX t1a/} +do_execsql_test analyzeE-1.11 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a<1900 +} {/SCAN t1/} + +# Verify that everything works the same on a DESCENDING index. +# +do_execsql_test analyzeE-2.0 { + DROP INDEX t1a; + CREATE INDEX t1a ON t1(a DESC); + ANALYZE; +} {} +do_execsql_test analyzeE-2.1 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a BETWEEN 500 AND 2500; +} {/SCAN t1/} +do_execsql_test analyzeE-2.2 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a BETWEEN 2900 AND 3000; +} {/SEARCH t1 USING INDEX t1a/} +do_execsql_test analyzeE-2.3 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a BETWEEN 1700 AND 1750; +} {/SEARCH t1 USING INDEX t1a/} +do_execsql_test analyzeE-2.4 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a BETWEEN 1 AND 500 +} {/SEARCH t1 USING INDEX t1a/} +do_execsql_test analyzeE-2.5 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a BETWEEN 3000 AND 3000000 +} {/SEARCH t1 USING INDEX t1a/} +do_execsql_test analyzeE-2.6 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a<500 +} {/SEARCH t1 USING INDEX t1a/} +do_execsql_test analyzeE-2.7 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a>2500 +} {/SEARCH t1 USING INDEX t1a/} +do_execsql_test analyzeE-2.8 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a>1900 +} {/SEARCH t1 USING INDEX t1a/} +do_execsql_test analyzeE-2.9 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a>1100 +} {/SCAN t1/} +do_execsql_test analyzeE-2.10 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a<1100 +} {/SEARCH t1 USING INDEX t1a/} +do_execsql_test analyzeE-2.11 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a<1900 +} {/SCAN t1/} + +# Now do a range query on the second term of an ASCENDING index +# where the first term is constrained by equality. +# +do_execsql_test analyzeE-3.0 { + DROP TABLE t1; + CREATE TABLE t1(a,b,c); + WITH RECURSIVE + cnt(x) AS (VALUES(1000) UNION ALL SELECT x+1 FROM cnt WHERE x<2000) + INSERT INTO t1(a,b,c) SELECT x, x, 123 FROM cnt; + CREATE INDEX t1ca ON t1(c,a); + ANALYZE; +} {} +do_execsql_test analyzeE-3.1 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a BETWEEN 500 AND 2500 AND c=123; +} {/SCAN t1/} +do_execsql_test analyzeE-3.2 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a BETWEEN 2900 AND 3000 AND c=123; +} {/SEARCH t1 USING INDEX t1ca/} +do_execsql_test analyzeE-3.3 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a BETWEEN 1700 AND 1750 AND c=123; +} {/SEARCH t1 USING INDEX t1ca/} +do_execsql_test analyzeE-3.4 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a BETWEEN 1 AND 500 AND c=123 +} {/SEARCH t1 USING INDEX t1ca/} +do_execsql_test analyzeE-3.5 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a BETWEEN 3000 AND 3000000 AND c=123 +} {/SEARCH t1 USING INDEX t1ca/} +do_execsql_test analyzeE-3.6 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a<500 AND c=123 +} {/SEARCH t1 USING INDEX t1ca/} +do_execsql_test analyzeE-3.7 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a>2500 AND c=123 +} {/SEARCH t1 USING INDEX t1ca/} +do_execsql_test analyzeE-3.8 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a>1900 AND c=123 +} {/SEARCH t1 USING INDEX t1ca/} +do_execsql_test analyzeE-3.9 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a>1100 AND c=123 +} {/SCAN t1/} +do_execsql_test analyzeE-3.10 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a<1100 AND c=123 +} {/SEARCH t1 USING INDEX t1ca/} +do_execsql_test analyzeE-3.11 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a<1900 AND c=123 +} {/SCAN t1/} + +# Repeat the 3.x tests using a DESCENDING index +# +do_execsql_test analyzeE-4.0 { + DROP INDEX t1ca; + CREATE INDEX t1ca ON t1(c ASC,a DESC); + ANALYZE; +} {} +do_execsql_test analyzeE-4.1 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a BETWEEN 500 AND 2500 AND c=123; +} {/SCAN t1/} +do_execsql_test analyzeE-4.2 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a BETWEEN 2900 AND 3000 AND c=123; +} {/SEARCH t1 USING INDEX t1ca/} +do_execsql_test analyzeE-4.3 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a BETWEEN 1700 AND 1750 AND c=123; +} {/SEARCH t1 USING INDEX t1ca/} +do_execsql_test analyzeE-4.4 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a BETWEEN 1 AND 500 AND c=123 +} {/SEARCH t1 USING INDEX t1ca/} +do_execsql_test analyzeE-4.5 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a BETWEEN 3000 AND 3000000 AND c=123 +} {/SEARCH t1 USING INDEX t1ca/} +do_execsql_test analyzeE-4.6 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a<500 AND c=123 +} {/SEARCH t1 USING INDEX t1ca/} +do_execsql_test analyzeE-4.7 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a>2500 AND c=123 +} {/SEARCH t1 USING INDEX t1ca/} +do_execsql_test analyzeE-4.8 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a>1900 AND c=123 +} {/SEARCH t1 USING INDEX t1ca/} +do_execsql_test analyzeE-4.9 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a>1100 AND c=123 +} {/SCAN t1/} +do_execsql_test analyzeE-4.10 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a<1100 AND c=123 +} {/SEARCH t1 USING INDEX t1ca/} +do_execsql_test analyzeE-4.11 { + EXPLAIN QUERY PLAN + SELECT * FROM t1 WHERE a<1900 AND c=123 +} {/SCAN t1/} + +# 2023-03-23 https://sqlite.org/forum/forumpost/dc4854437b +# +reset_db +do_execsql_test analyzeE-5.0 { + PRAGMA encoding = 'UTF-16'; + CREATE TABLE t0 (c1 TEXT); + INSERT INTO t0 VALUES (''); + CREATE INDEX i0 ON t0(c1); + ANALYZE; + SELECT * FROM t0 WHERE t0.c1 BETWEEN '' AND (ABS('')); +} {{}} + +# 2023-03-24 https://sqlite.org/forum/forumpost/bc39e531e5 +# +reset_db +do_execsql_test analyzeE-6.0 { + CREATE TABLE t1(x); + CREATE INDEX i1 ON t1(x,x,x,x,x||2); + CREATE INDEX i2 ON t1(1<2); + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<1000) + INSERT INTO t1(x) SELECT x FROM c; + ANALYZE; +} {} +do_execsql_test analyzeE-6.1 { + SELECT count(*)>1 FROM sqlite_stat4 WHERE idx='i2' AND neq='1000 1'; +} 1 +do_execsql_test analyzeE-6.2 { + SELECT count(*) FROM sqlite_stat4 WHERE idx='i2' AND neq<>'1000 1'; +} 0 +do_execsql_test analyzeE-6.3 { + SELECT count(*)>1 FROM sqlite_stat4 WHERE idx='i1' AND neq='1 1 1 1 1 1'; +} 1 +do_execsql_test analyzeE-6.4 { + SELECT count(*) FROM sqlite_stat4 WHERE idx='i1' AND neq<>'1 1 1 1 1 1'; +} 0 + +# 2023-03-25 https://sqlite.org/forum/forumpost/5275207102 +# Correctly expand zeroblobs while processing STAT4 information +# during query planning. +# +reset_db +do_execsql_test analyzeE-7.0 { + CREATE TABLE t1(a TEXT COLLATE binary); + CREATE INDEX t1x ON t1(a); + INSERT INTO t1(a) VALUES(0),('apple'),(NULL),(''),('banana'); + ANALYZE; + SELECT format('(%s)',a) FROM t1 WHERE t1.a > CAST(zeroblob(5) AS TEXT); +} {(0) (apple) (banana)} +do_execsql_test analyzeE-7.1 { + SELECT format('(%s)',a) FROM t1 WHERE t1.a <= CAST(zeroblob(5) AS TEXT); +} {()} + +finish_test diff --git a/test/analyzeF.test b/test/analyzeF.test new file mode 100644 index 0000000..0010799 --- /dev/null +++ b/test/analyzeF.test @@ -0,0 +1,150 @@ +# 2015-03-12 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# Test that deterministic scalar functions passed constant arguments +# are used with stat4 data. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix analyzeF + +ifcapable {!stat4} { + finish_test + return +} + +proc isqrt {i} { expr { int(sqrt($i)) } } +db func isqrt isqrt + +do_execsql_test 1.0 { + CREATE TABLE t1(x INTEGER, y INTEGER); + WITH data(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM data + ) + INSERT INTO t1 SELECT isqrt(i), isqrt(i) FROM data LIMIT 400; + CREATE INDEX t1x ON t1(x); + CREATE INDEX t1y ON t1(y); + ANALYZE; +} + +proc str {a} { return $a } +db func str str + +# Note: tests 7 to 12 might be unstable - as they assume SQLite will +# prefer the expression to the right of the AND clause. Which of +# course could change. +# +# Note 2: tests 9 and 10 depend on the tcl interface creating functions +# without the SQLITE_DETERMINISTIC flag set. +# +foreach {tn where idx} { + 1 "x = 4 AND y = 19" {t1x (x=?)} + 2 "x = 19 AND y = 4" {t1y (y=?)} + 3 "x = '4' AND y = '19'" {t1x (x=?)} + 4 "x = '19' AND y = '4'" {t1y (y=?)} + 5 "x = substr('5195', 2, 2) AND y = substr('145', 2, 1)" {t1y (y=?)} + 6 "x = substr('145', 2, 1) AND y = substr('5195', 2, 2)" {t1x (x=?)} + + 7 "x = substr('5195', 2, 2+0) AND y = substr('145', 2, 1+0)" {t1y (y=?)} + 8 "x = substr('145', 2, 1+0) AND y = substr('5195', 2, 2+0)" {t1y (y=?)} + + 9 "x = str('19') AND y = str('4')" {t1y (y=?)} + 10 "x = str('4') AND y = str('19')" {t1y (y=?)} + + 11 "x = nullif('19', 0) AND y = nullif('4', 0)" {t1y (y=?)} + 12 "x = nullif('4', 0) AND y = nullif('19', 0)" {t1y (y=?)} +} { + set res "SEARCH t1 USING INDEX $idx" + do_eqp_test 1.$tn "SELECT * FROM t1 WHERE $where" $res +} + +# Test that functions that do not exist - "func()" - do not cause an error. +# +do_catchsql_test 2.1 { + SELECT * FROM t1 WHERE x = substr('145', 2, 1) AND y = func(1, 2, 3) +} {1 {no such function: func}} +do_catchsql_test 2.2 { + UPDATE t1 SET y=y+1 WHERE x = substr('145', 2, 1) AND y = func(1, 2, 3) +} {1 {no such function: func}} + + +# Check that functions that accept zero arguments do not cause problems. +# +proc ret {x} { return $x } + +db func det4 -deterministic [list ret 4] +db func nondet4 [list ret 4] +db func det19 -deterministic [list ret 19] +db func nondet19 [list ret 19] + +foreach {tn where idx} { + 1 "x = det4() AND y = det19()" {t1x (x=?)} + 2 "x = det19() AND y = det4()" {t1y (y=?)} + + 3 "x = nondet4() AND y = nondet19()" {t1y (y=?)} + 4 "x = nondet19() AND y = nondet4()" {t1y (y=?)} +} { + set res "SEARCH t1 USING INDEX $idx" + do_eqp_test 3.$tn "SELECT * FROM t1 WHERE $where" $res +} + + +execsql { DELETE FROM t1 } + +proc throw_error {err} { error $err } +db func error -deterministic throw_error +do_catchsql_test 4.1 { + SELECT * FROM t1 WHERE x = error('error one') AND y = 4; +} {1 {error one}} + +do_catchsql_test 4.2 { + SELECT * FROM t1 WHERE x = zeroblob(2200000000) AND y = 4; +} {1 {string or blob too big}} + +sqlite3_limit db SQLITE_LIMIT_LENGTH 1000000 +proc dstr {} { return [string repeat x 1100000] } +db func dstr -deterministic dstr +do_catchsql_test 4.3 { + SELECT * FROM t1 WHERE x = dstr() AND y = 11; +} {1 {string or blob too big}} + +do_catchsql_test 4.4 { + SELECT * FROM t1 WHERE x = test_zeroblob(1100000) AND y = 4; +} {1 {string or blob too big}} + +# 2016-12-08: Constraints of the form "x=? AND x IS NOT NULL" were being +# mishandled. The sqlite3Stat4ProbeSetValue() routine was assuming that +# valueNew() was returning a Mem object that was preset to NULL, which is +# not the case. The consequence was the the "x IS NOT NULL" constraint +# was used to drive the index (via the "x>NULL" pseudo-constraint) rather +# than the "x=?" constraint. +# +do_execsql_test 5.1 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c INT); + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<10000) + INSERT INTO t1(a, c) SELECT x, x FROM c; + UPDATE t1 SET b=printf('x%02x',a/500) WHERE a>4000; + UPDATE t1 SET b='xyz' where a>=9998; + CREATE INDEX t1b ON t1(b); + ANALYZE; + SELECT count(*), b FROM t1 GROUP BY 2 ORDER BY 2; +} {4000 {} 499 x08 500 x09 500 x0a 500 x0b 500 x0c 500 x0d 500 x0e 500 x0f 500 x10 500 x11 500 x12 498 x13 3 xyz} +do_execsql_test 5.2 { + explain query plan + SELECT * FROM t1 WHERE b='xyz' AND b IS NOT NULL ORDER BY +a; + /* v---- Should be "=", not ">" */ +} {/USING INDEX t1b .b=/} +do_execsql_test 5.3 { + SELECT * FROM t1 WHERE b='xyz' AND b IS NOT NULL ORDER BY +a; +} {9998 xyz 9998 9999 xyz 9999 10000 xyz 10000} + +finish_test diff --git a/test/analyzeG.test b/test/analyzeG.test new file mode 100644 index 0000000..ca65bc3 --- /dev/null +++ b/test/analyzeG.test @@ -0,0 +1,84 @@ +# 2020-02-23 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# Tests for functionality related to ANALYZE. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !stat4 { + finish_test + return +} +set testprefix analyzeG + +#------------------------------------------------------------------------- +# Test cases 1.* seek to verify that even if an index is not used, its +# stat4 data may be used by the planner to estimate the number of +# rows that match an unindexed constraint on the same column. +# +do_execsql_test 1.0 { + PRAGMA automatic_index = 0; + CREATE TABLE t1(a, x); + CREATE TABLE t2(b, y); + WITH s(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<100 + ) + INSERT INTO t1 SELECT (i%50), NULL FROM s; + WITH s(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<100 + ) + INSERT INTO t2 SELECT (CASE WHEN i<95 THEN 44 ELSE i END), NULL FROM s; +} + +# Join tables t1 and t2. Both contain 100 rows. (a=44) matches 2 rows +# in "t1", (b=44) matches 95 rows in table "t2". But the planner doesn't +# know this, so it has no preference as to which order the tables are +# scanned in. In practice this means that tables are scanned in the order +# they are specified in in the FROM clause. +do_eqp_test 1.1.1 { + SELECT * FROM t1, t2 WHERE a=44 AND b=44; +} { + +} +do_eqp_test 1.1.2 { + SELECT * FROM t2, t1 WHERE a=44 AND b=44 +} { + QUERY PLAN + |--SCAN t2 + `--SCAN t1 +} + +do_execsql_test 1.2 { + CREATE INDEX t2b ON t2(b); + ANALYZE; +} + +# Now, with the ANALYZE data, the planner knows that (b=44) matches a +# large number of rows. So it elects to scan table "t1" first, regardless +# of the order in which the tables are specified in the FROM clause. +do_eqp_test 1.3.1 { + SELECT * FROM t1, t2 WHERE a=44 AND b=44; +} { + QUERY PLAN + |--SCAN t1 + `--SCAN t2 +} +do_eqp_test 1.3.2 { + SELECT * FROM t2, t1 WHERE a=44 AND b=44 +} { + QUERY PLAN + |--SCAN t1 + `--SCAN t2 +} + + +finish_test diff --git a/test/analyzer1.test b/test/analyzer1.test new file mode 100644 index 0000000..51b5f8b --- /dev/null +++ b/test/analyzer1.test @@ -0,0 +1,55 @@ +# 2015-05-11 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Quick tests for the sqlite3_analyzer tool +# +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !vtab { + finish_test + return +} + +if {$tcl_platform(platform)=="windows"} { + set PROG "sqlite3_analyzer.exe" +} else { + set PROG "./sqlite3_analyzer" +} +if {![file exe $PROG]} { + set PROG [file normalize [file join $::cmdlinearg(TESTFIXTURE_HOME) $PROG]] + if {![file exe $PROG]} { + puts "analyzer1 cannot run because $PROG is not available" + finish_test + return + } +} +db close +forcedelete test.db test.db-journal test.db-wal +sqlite3 db test.db + +do_test analyzer1-1.0 { + db eval { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + CREATE TABLE t2(a INT PRIMARY KEY, b) WITHOUT ROWID; + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<250) + INSERT INTO t1(a,b) SELECT x, randomblob(200) FROM c; + INSERT INTO t2(a,b) SELECT a, b FROM t1; + } + set line "exec $PROG test.db" + unset -nocomplain ::MSG + catch {eval $line} ::MSG +} {0} +do_test analyzer1-1.1 { + regexp {^/\*\* Disk-Space Utilization.*COMMIT;\W*$} $::MSG +} {1} + +finish_test diff --git a/test/async.test b/test/async.test new file mode 100644 index 0000000..e1bc086 --- /dev/null +++ b/test/async.test @@ -0,0 +1,90 @@ +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file runs all tests. +# +# $Id: async.test,v 1.21 2009/06/05 17:09:12 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +if {[info commands sqlite3async_initialize] eq ""} { + # The async logic is not built into this system + finish_test + return +} + +rename finish_test async_really_finish_test +proc finish_test {} { + catch {db close} + catch {db2 close} + catch {db3 close} +} +if {[info exists G(isquick)]} { set ASYNC_SAVE_ISQUICK $G(isquick) } +set G(isquick) 1 + +set ASYNC_INCLUDE { + insert.test + insert2.test + insert3.test + lock.test + lock2.test + lock3.test + select1.test + select2.test + select3.test + select4.test + trans.test +} + +# Enable asynchronous IO. +sqlite3async_initialize "" 1 + +# This proc flushes the contents of the async-IO queue through to the +# underlying VFS. A couple of the test scripts identified in $ASYNC_INCLUDE +# above contain lines like "catch flush_async_queue" in places where +# this is required for the tests to work in async mode. +# +proc flush_async_queue {} { + sqlite3async_control halt idle + sqlite3async_start + sqlite3async_wait + sqlite3async_control halt never +} + +rename do_test async_really_do_test +proc do_test {name args} { + uplevel async_really_do_test async_io-$name $args + flush_async_queue +} + +foreach testfile [lsort -dictionary [glob $testdir/*.test]] { + set tail [file tail $testfile] + if {[lsearch -exact $ASYNC_INCLUDE $tail]<0} continue + source $testfile + + # Make sure everything is flushed through. This is because [source]ing + # the next test file will delete the database file on disk (using + # [delete_file]). If the asynchronous backend still has the file + # open, it will become confused. + # + flush_async_queue +} + +# Flush the write-queue and disable asynchronous IO. This should ensure +# all allocated memory is cleaned up. +set sqlite3async_trace 1 +flush_async_queue +sqlite3async_shutdown +set sqlite3async_trace 0 + +rename do_test {} +rename async_really_do_test do_test +rename finish_test {} +rename async_really_finish_test finish_test + +if {[info exists ASYNC_SAVE_ISQUICK]} { set G(isquick) $ASYNC_SAVE_ISQUICK } +finish_test diff --git a/test/async2.test b/test/async2.test new file mode 100644 index 0000000..7994a72 --- /dev/null +++ b/test/async2.test @@ -0,0 +1,126 @@ +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# $Id: async2.test,v 1.12 2009/04/25 08:39:15 danielk1977 Exp $ + + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +if { + [info commands sqlite3async_initialize]=="" || + [info command sqlite3_memdebug_fail]=="" +} { + # The async logic is not built into this system + puts "Skipping async2 tests: not compiled with required features" + finish_test + return +} + +# Enable asynchronous IO. + +set setup_script { + CREATE TABLE counter(c); + INSERT INTO counter(c) VALUES (1); +} + +set sql_script { + BEGIN; + UPDATE counter SET c = 2; + CREATE TABLE t1(a PRIMARY KEY, b, c); + CREATE TABLE t2(a PRIMARY KEY, b, c); + COMMIT; + + BEGIN; + UPDATE counter SET c = 3; + INSERT INTO t1 VALUES('abcdefghij', 'four', 'score'); + INSERT INTO t2 VALUES('klmnopqrst', 'and', 'seven'); + COMMIT; + + UPDATE counter SET c = 'FIN'; +} + +db close + +foreach err [list ioerr malloc-transient malloc-persistent] { + set ::go 10 + for {set n 1} {$::go} {incr n} { + set ::sqlite_io_error_pending 0 + sqlite3_memdebug_fail -1 + forcedelete test.db test.db-journal + sqlite3 db test.db + execsql $::setup_script + db close + + sqlite3async_initialize "" 1 + sqlite3 db test.db + sqlite3_db_config_lookaside db 0 0 0 + + switch -- $err { + ioerr { set ::sqlite_io_error_pending $n } + malloc-persistent { sqlite3_memdebug_fail $n -repeat 1 } + malloc-transient { sqlite3_memdebug_fail $n -repeat 0 } + } + + catchsql $::sql_script + db close + + sqlite3async_control halt idle + sqlite3async_start + sqlite3async_wait + sqlite3async_control halt never + sqlite3async_shutdown + + set ::sqlite_io_error_pending 0 + sqlite3_memdebug_fail -1 + + sqlite3 db test.db + set c [db one {SELECT c FROM counter LIMIT 1}] + switch -- $c { + 1 { + do_test async-$err-1.1.$n { + execsql { + SELECT name FROM sqlite_master; + } + } {counter} + } + 2 { + do_test async-$err-1.2.$n.1 { + execsql { + SELECT * FROM t1; + } + } {} + do_test async-$err-1.2.$n.2 { + execsql { + SELECT * FROM t2; + } + } {} + } + 3 { + do_test async-$err-1.3.$n.1 { + execsql { + SELECT * FROM t1; + } + } {abcdefghij four score} + do_test async-$err-1.3.$n.2 { + execsql { + SELECT * FROM t2; + } + } {klmnopqrst and seven} + } + FIN { + incr ::go -1 + } + } + + db close + } +} + +catch {db close} + +finish_test diff --git a/test/async3.test b/test/async3.test new file mode 100644 index 0000000..9336b66 --- /dev/null +++ b/test/async3.test @@ -0,0 +1,76 @@ +# 2007 September 5 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# The focus of this file is testing the code in test_async.c. +# Specifically, it tests that the xFullPathname() method of +# of the asynchronous vfs works correctly. +# +# $Id: async3.test,v 1.5 2009/04/25 08:39:15 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +if { [info commands sqlite3async_initialize]=="" } { + # The async logic is not built into this system + puts "Skipping async3 tests: not compiled with required features" + finish_test + return +} + +db close +sqlite3async_initialize "" 1 +#set sqlite3async_trace 1 +sqlite3async_start + +set paths { + chocolate/banana/vanilla/file.db + chocolate//banana/vanilla/file.db + chocolate/./banana//vanilla/file.db + chocolate/banana/./vanilla/file.db + chocolate/banana/../banana/vanilla/file.db + chocolate/banana/./vanilla/extra_bit/../file.db +} + +do_test async3-1.0 { + file mkdir [file join chocolate banana vanilla] + forcedelete chocolate/banana/vanilla/file.db + forcedelete chocolate/banana/vanilla/file.db-journal +} {} + +do_test async3-1.1 { + sqlite3 db chocolate/banana/vanilla/file.db + execsql { + CREATE TABLE abc(a, b, c); + BEGIN; + INSERT INTO abc VALUES(1, 2, 3); + } +} {} + +set N 2 +foreach p $paths { + sqlite3 db2 $p + do_test async3-1.$N.1 { + execsql {SELECT * FROM abc} db2 + } {} + do_test async3-1.$N.2 { + catchsql {INSERT INTO abc VALUES(4, 5, 6)} db2 + } {1 {database is locked}} + db2 close + incr N +} + +db close + +sqlite3async_control halt idle +sqlite3async_wait +sqlite3async_control halt never +sqlite3async_shutdown +finish_test diff --git a/test/async4.test b/test/async4.test new file mode 100644 index 0000000..92a8201 --- /dev/null +++ b/test/async4.test @@ -0,0 +1,168 @@ +# 2009 April 25 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# $Id: async4.test,v 1.4 2009/06/05 17:09:12 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +# These tests only work for Tcl version 8.5 and later on Windows (for now) +# +if {$tcl_platform(platform)=="windows"} { + scan $::tcl_version %f vx + if {$vx<8.5} { + finish_test + return + } +} + +if {[info commands sqlite3async_initialize] eq ""} { + # The async logic is not built into this system + finish_test + return +} +db close + +# Test layout: +# +# async4.1.*: Test the lockfiles parameter. +# async4.2.*: Test the delay parameter. + +do_test async4.1.1 { + sqlite3async_initialize {} 0 + sqlite3async_control lockfiles +} {1} +do_test async4.1.2 { + sqlite3async_control lockfiles false +} {0} +do_test async4.1.3 { + sqlite3async_control lockfiles +} {0} +do_test async4.1.4 { + sqlite3async_control lockfiles true +} {1} + +do_test async4.1.5 { + sqlite3 db test.db -vfs sqlite3async + execsql { CREATE TABLE t1(a, b, c) } +} {} +do_test async4.1.6 { + list [file exists test.db] [file size test.db] +} {1 0} +do_test async4.1.7 { + sqlite3 db2 test.db + catchsql { CREATE TABLE t2(a, b, c) } db2 +} {1 {database is locked}} +do_test async4.1.8 { + sqlite3async_control halt idle + sqlite3async_start + sqlite3async_wait +} {} +do_test async4.1.9 { + catchsql { CREATE TABLE t2(a, b, c) } db2 +} {0 {}} +do_test async4.1.10 { + list [catch {sqlite3async_control lockfiles false} msg] $msg +} {1 SQLITE_MISUSE} +do_test async4.1.11 { + db close + list [catch {sqlite3async_control lockfiles false} msg] $msg +} {1 SQLITE_MISUSE} +do_test async4.1.12 { + sqlite3async_start + sqlite3async_wait + sqlite3async_control lockfiles false +} {0} +do_test async4.1.13 { + sqlite3 db test.db -vfs sqlite3async + execsql { CREATE TABLE t3(a, b, c) } db +} {} +do_test async4.1.14 { + execsql { + CREATE INDEX i1 ON t2(a); + CREATE INDEX i2 ON t1(a); + } db2 +} {} +do_test async4.1.15 { + sqlite3async_start + sqlite3async_wait + hexio_write test.db 28 00000000 + execsql { pragma integrity_check } db2 +} {{*** in database main *** +Page 5 is never used}} +do_test async4.1.16 { + db close + db2 close + sqlite3async_start + sqlite3async_wait +} {} +do_test async4.1.17 { + sqlite3async_control lockfiles true +} {1} + +do_test async4.2.1 { + sqlite3async_control delay +} {0} +do_test async4.2.2 { + sqlite3async_control delay 23 +} {23} +do_test async4.2.3 { + sqlite3async_control delay +} {23} +do_test async4.2.4 { + sqlite3async_control delay 0 +} {0} +do_test async4.2.5 { + sqlite3 db test.db -vfs sqlite3async + + execsql { CREATE TABLE t4(a, b) } + set T1 [lindex [time { + sqlite3async_start + sqlite3async_wait + }] 0] + + sqlite3async_control delay 100 + execsql { CREATE TABLE t5(a, b) } + set T2 [lindex [time { + sqlite3async_start + sqlite3async_wait + }] 0] + + expr {($T1+1000000) < $T2} +} {1} + +do_test async4.2.6 { + sqlite3async_control delay 0 + execsql { CREATE TABLE t6(a, b) } + set T1 [lindex [time { + sqlite3async_start + sqlite3async_wait + }] 0] + + expr {($T1+1000000) < $T2} +} {1} + +do_test async4.2.7 { + list [catch { sqlite3async_control delay -1 } msg] $msg +} {1 SQLITE_MISUSE} + +do_test async4.2.8 { + db close + sqlite3async_start + sqlite3async_wait +} {} + +finish_test diff --git a/test/async5.test b/test/async5.test new file mode 100644 index 0000000..abac11f --- /dev/null +++ b/test/async5.test @@ -0,0 +1,68 @@ +# 2009 July 19 +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file tests that asynchronous IO is compatible with multi-file +# transactions. +# +# $Id: async5.test,v 1.1 2009/07/18 11:52:04 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +if {[info commands sqlite3async_initialize] eq ""} { + # The async logic is not built into this system + finish_test + return +} + +db close +forcedelete test2.db +sqlite3async_initialize "" 1 +sqlite3async_control halt never +sqlite3 db test.db + +do_test async5-1.1 { + execsql { + ATTACH 'test2.db' AS next; + CREATE TABLE main.t1(a, b); + CREATE TABLE next.t2(a, b); + BEGIN; + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t2 VALUES(3, 4); + COMMIT; + } +} {} +do_test async5-1.2 { + execsql { SELECT * FROM t1 } +} {1 2} +do_test async5-1.3 { + execsql { SELECT * FROM t2 } +} {3 4} +do_test async5-1.4 { + execsql { + BEGIN; + INSERT INTO t1 VALUES('a', 'b'); + INSERT INTO t2 VALUES('c', 'd'); + COMMIT; + } +} {} +do_test async5-1.5 { + execsql { SELECT * FROM t1 } +} {1 2 a b} +do_test async5-1.6 { + execsql { SELECT * FROM t2 } +} {3 4 c d} + +db close + +sqlite3async_control halt idle +sqlite3async_start +sqlite3async_wait +sqlite3async_control halt never +sqlite3async_shutdown +set sqlite3async_trace 0 +finish_test diff --git a/test/atof1.test b/test/atof1.test new file mode 100644 index 0000000..95f443c --- /dev/null +++ b/test/atof1.test @@ -0,0 +1,86 @@ +# 2012 June 18 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Tests of the sqlite3AtoF() function. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +set mxpow [expr {[use_long_double]?100:35}] +expr srand(1) +for {set i 1} {$i<20000} {incr i} { + set pow [expr {int((rand()-0.5)*$mxpow)}] + set x [expr {pow((rand()-0.5)*2*rand(),$pow)}] + set xf [format %.32e $x] + + # Verify that text->real conversions get exactly same ieee754 floating- + # point value in SQLite as they do in TCL. + # + do_test atof1-1.$i.1 { + set y [db eval "SELECT $xf=\$x"] + if {!$y} { + puts -nonewline \173[db eval "SELECT real2hex($xf), real2hex(\$x)"]\175 + db eval "SELECT $xf+0.0 AS a, \$x AS b" { + puts [format "\n%.60e\n%.60e\n%.60e" $x $a $b] + } + } + set y + } {1} + + # Verify that round-trip real->text->real conversions using the quote() + # function preserve the bits of the numeric value exactly. + # + do_test atof1-1.$i.2 { + set y [db eval {SELECT $x=CAST(quote($x) AS real)}] + if {!$y} { + db eval {SELECT real2hex($x) a, real2hex(CAST(quote($x) AS real)) b} {} + puts "" + if {$x<0} { + puts "[format {!SCALE: %17s 1 23456789 123456789 123456789} {}]" + } else { + puts "[format {!SCALE: %16s 1 23456789 123456789 123456789} {}]" + } + puts "!IN: $a $xf" + puts [format {!QUOTE: %16s %s} {} [db eval {SELECT quote($x)}]] + db eval {SELECT CAST(quote($x) AS real) c} {} + puts "!OUT: $b [format %.32e $c]" + } + set y + } {1} +} + +# 2020-01-08 ticket 9eda2697f5cc1aba +# When running sqlite3AtoF() on a blob with an odd number of bytes using +# UTF16, ignore the last byte so that the string has an integer number of +# UTF16 code points. +# +reset_db +do_execsql_test atof1-2.10 { + PRAGMA encoding = 'UTF16be'; + CREATE TABLE t1(a, b); + INSERT INTO t1(rowid,a) VALUES (1,x'00'),(2,3); + SELECT substr(a,',') is true FROM t1 ORDER BY rowid; +} {0 1} +do_execsql_test atof1-2.20 { + SELECT substr(a,',') is true FROM t1 ORDER BY rowid DESC; +} {1 0} +do_execsql_test atof1-2.30 { + CREATE INDEX i1 ON t1(a); + SELECT count(*) FROM t1 WHERE substr(a,','); +} {1} +# 2020-08-27 OSSFuzz find related to the above. +do_execsql_test atof1-2.40 { + SELECT randomblob(0) - 1; +} {-1} + + +finish_test diff --git a/test/atomic.test b/test/atomic.test new file mode 100644 index 0000000..6ce6deb --- /dev/null +++ b/test/atomic.test @@ -0,0 +1,41 @@ +# 2015-11-07 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing the WITH clause. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix atomic + +db close +if {[atomic_batch_write test.db]==0} { + puts "No f2fs atomic-batch-write support. Skipping tests..." + finish_test + return +} + +reset_db + +do_execsql_test 1.0 { + CREATE TABLE t1(x, y); + BEGIN; + INSERT INTO t1 VALUES(1, 2); +} + +do_test 1.1 { file exists test.db-journal } {0} + +do_execsql_test 1.2 { + COMMIT; +} + + +finish_test diff --git a/test/atomic2.test b/test/atomic2.test new file mode 100644 index 0000000..5b78658 --- /dev/null +++ b/test/atomic2.test @@ -0,0 +1,95 @@ +# 2018-07-15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing that if an IO error is encountered +# as part of an atomic F2FS commit, an attempt is made to commit the +# transaction using a legacy journal commit. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/malloc_common.tcl +set ::testprefix atomic2 + +db close +if {[atomic_batch_write test.db]==0} { + puts "No f2fs atomic-batch-write support. Skipping tests..." + finish_test + return +} + +reset_db + +do_execsql_test 1.0 { + CREATE TABLE t1(x, y); + CREATE INDEX i1x ON t1(x); + CREATE INDEX i2x ON t1(y); + + WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<100 ) + INSERT INTO t1 SELECT randomblob(400), randomblob(400) FROM s; +} + +set setup [list \ + -injectstart at_injectstart \ + -injectstop at_injectstop \ +] + +set ::at_fail 0 +set ::at_nfail 0 + +proc at_injectstart {iFail} { + set ::at_fail $iFail + set ::at_nfail 0 +} +proc at_injectstop {} { + set ::at_fail 0 + return $::at_nfail +} + +proc at_vfs_callback {method file z args} { + if {$::at_fail>0} { + incr ::at_fail -1 + if {$::at_fail==0} { + incr ::at_nfail + return SQLITE_IOERR + } elseif {$method=="xFileControl" && $z=="COMMIT_ATOMIC_WRITE"} { + set ::at_fail 0 + } + } + return SQLITE_OK +} + +testvfs tvfs -default 1 +tvfs script at_vfs_callback +tvfs filter {xFileControl xWrite} + +faultsim_save_and_close + +do_one_faultsim_test 2.0 {*}$setup -prep { + faultsim_restore_and_reopen +} -body { + execsql { + WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<100 ) + INSERT INTO t1 SELECT randomblob(400), randomblob(400) FROM s; + } +} -test { + faultsim_test_result {0 {}} + + set res [execsql {SELECT count(*) FROM t1; PRAGMA integrity_check}] + if {$res!="200 ok"} { + error "expected {200 ok}, got $res" + } +} + +db close +tvfs delete + +finish_test diff --git a/test/atrc.c b/test/atrc.c new file mode 100644 index 0000000..673f12c --- /dev/null +++ b/test/atrc.c @@ -0,0 +1,150 @@ +/* +** This program generates a script that stresses the ALTER TABLE statement. +** Compile like this: +** +** gcc -g -c sqlite3.c +** gcc -g -o atrc atrc.c sqlite3.o -ldl -lpthread +** +** Run the program this way: +** +** ./atrc DATABASE | ./sqlite3 DATABASE +** +** This program "atrc" generates a script that can be fed into an ordinary +** command-line shell. The script performs many ALTER TABLE statements, +** runs ".schema --indent" and "PRAGMA integrity_check;", does more +** ALTER TABLE statements to restore the original schema, and then +** runs "PRAGMA integrity_check" again. Every table and column has its +** name changed. The entire script is contained within BEGIN...ROLLBACK +** so that no changes are ever actually made to the database. +*/ +#include "sqlite3.h" +#include + +/* +** Generate the text of ALTER TABLE statements that will rename +** every column in table zTable to a generic name composed from +** zColPrefix and a sequential number. The generated text is +** appended pConvert. If pUndo is not NULL, then SQL text that +** will undo the change is appended to pUndo. +** +** The table to be converted must be in the "main" schema. +*/ +int rename_all_columns_of_table( + sqlite3 *db, /* Database connection */ + const char *zTab, /* Table whose columns should all be renamed */ + const char *zColPrefix, /* Prefix for new column names */ + sqlite3_str *pConvert, /* Append ALTER TABLE statements here */ + sqlite3_str *pUndo /* SQL to undo the change, if not NULL */ +){ + sqlite3_stmt *pStmt; + int rc; + int cnt = 0; + + rc = sqlite3_prepare_v2(db, + "SELECT name FROM pragma_table_info(?1);", + -1, &pStmt, 0); + if( rc ) return rc; + sqlite3_bind_text(pStmt, 1, zTab, -1, SQLITE_STATIC); + while( sqlite3_step(pStmt)==SQLITE_ROW ){ + const char *zCol = (const char*)sqlite3_column_text(pStmt, 0); + cnt++; + sqlite3_str_appendf(pConvert, + "ALTER TABLE \"%w\" RENAME COLUMN \"%w\" TO \"%w%d\";\n", + zTab, zCol, zColPrefix, cnt + ); + if( pUndo ){ + sqlite3_str_appendf(pUndo, + "ALTER TABLE \"%w\" RENAME COLUMN \"%w%d\" TO \"%w\";\n", + zTab, zColPrefix, cnt, zCol + ); + } + } + sqlite3_finalize(pStmt); + return SQLITE_OK; +} + +/* Rename all tables and their columns in the main database +*/ +int rename_all_tables( + sqlite3 *db, /* Database connection */ + sqlite3_str *pConvert, /* Append SQL to do the rename here */ + sqlite3_str *pUndo /* Append SQL to undo the rename here */ +){ + sqlite3_stmt *pStmt; + int rc; + int cnt = 0; + + rc = sqlite3_prepare_v2(db, + "SELECT name FROM sqlite_schema WHERE type='table'" + " AND name NOT LIKE 'sqlite_%';", + -1, &pStmt, 0); + if( rc ) return rc; + while( sqlite3_step(pStmt)==SQLITE_ROW ){ + const char *zTab = (const char*)sqlite3_column_text(pStmt, 0); + char *zNewTab; + char zPrefix[2]; + + zPrefix[0] = (cnt%26) + 'a'; + zPrefix[1] = 0; + zNewTab = sqlite3_mprintf("tx%d", ++cnt); + if( pUndo ){ + sqlite3_str_appendf(pUndo, + "ALTER TABLE \"%s\" RENAME TO \"%w\";\n", + zNewTab, zTab + ); + } + rename_all_columns_of_table(db, zTab, zPrefix, pConvert, pUndo); + sqlite3_str_appendf(pConvert, + "ALTER TABLE \"%w\" RENAME TO \"%s\";\n", + zTab, zNewTab + ); + sqlite3_free(zNewTab); + } + sqlite3_finalize(pStmt); + return SQLITE_OK; +} + +/* +** Generate a script that does this: +** +** (1) Start a transaction +** (2) Rename all tables and columns to use generic names. +** (3) Print the schema after this rename +** (4) Run pragma integrity_check +** (5) Do more ALTER TABLE statements to change the names back +** (6) Run pragma integrity_check again +** (7) Rollback the transaction +*/ +int main(int argc, char **argv){ + sqlite3 *db; + int rc; + sqlite3_str *pConvert; + sqlite3_str *pUndo; + char *zDbName; + char *zSql1, *zSql2; + if( argc!=2 ){ + fprintf(stderr, "Usage: %s DATABASE\n", argv[0]); + } + zDbName = argv[1]; + rc = sqlite3_open(zDbName, &db); + if( rc ){ + fprintf(stderr, "sqlite3_open() returns %d\n", rc); + return 1; + } + pConvert = sqlite3_str_new(db); + pUndo = sqlite3_str_new(db); + rename_all_tables(db, pConvert, pUndo); + zSql1 = sqlite3_str_finish(pConvert); + zSql2 = sqlite3_str_finish(pUndo); + sqlite3_close(db); + printf("BEGIN;\n"); + printf("%s", zSql1); + sqlite3_free(zSql1); + printf(".schema --indent\n"); + printf("PRAGMA integrity_check;\n"); + printf("%s", zSql2); + sqlite3_free(zSql2); + printf("PRAGMA integrity_check;\n"); + printf("ROLLBACK;\n"); + return 0; +} diff --git a/test/attach.test b/test/attach.test new file mode 100644 index 0000000..557201d --- /dev/null +++ b/test/attach.test @@ -0,0 +1,928 @@ +# 2003 April 4 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script is testing the ATTACH and DETACH commands +# and related functionality. +# +# $Id: attach.test,v 1.52 2009/05/29 14:39:08 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !attach { + finish_test + return +} + +for {set i 2} {$i<=15} {incr i} { + forcedelete test$i.db + forcedelete test$i.db-journal +} + +do_test attach-1.1 { + execsql { + CREATE TABLE t1(a,b); + INSERT INTO t1 VALUES(1,2); + INSERT INTO t1 VALUES(3,4); + SELECT * FROM t1; + } +} {1 2 3 4} +do_test attach-1.2 { + sqlite3 db2 test2.db + execsql { + CREATE TABLE t2(x,y); + INSERT INTO t2 VALUES(1,'x'); + INSERT INTO t2 VALUES(2,'y'); + SELECT * FROM t2; + } db2 +} {1 x 2 y} +do_test attach-1.3 { + execsql { + ATTACH DATABASE 'test2.db' AS two; + SELECT * FROM two.t2; + } +} {1 x 2 y} + +# Tests for the sqlite3_db_filename interface +# +do_test attach-1.3.1 { + file tail [sqlite3_db_filename db main] +} {test.db} +do_test attach-1.3.2 { + file tail [sqlite3_db_filename db MAIN] +} {test.db} +do_test attach-1.3.3 { + file tail [sqlite3_db_filename db temp] +} {} +do_test attach-1.3.4 { + file tail [sqlite3_db_filename db two] +} {test2.db} +do_test attach-1.3.5 { + file tail [sqlite3_db_filename db three] +} {} + +do_test attach-1.4 { + execsql { + SELECT * FROM t2; + } +} {1 x 2 y} +do_test attach-1.5 { + execsql { + DETACH DATABASE two; + SELECT * FROM t1; + } +} {1 2 3 4} +do_test attach-1.6 { + catchsql { + SELECT * FROM t2; + } +} {1 {no such table: t2}} +do_test attach-1.7 { + catchsql { + SELECT * FROM two.t2; + } +} {1 {no such table: two.t2}} +do_test attach-1.8 { + catchsql { + ATTACH DATABASE 'test3.db' AS three; + } +} {0 {}} +do_test attach-1.9 { + catchsql { + SELECT * FROM three.sqlite_master; + } +} {0 {}} +do_test attach-1.10 { + catchsql { + DETACH DATABASE [three]; + } +} {0 {}} +do_test attach-1.11 { + execsql { + ATTACH 'test.db' AS db2; + ATTACH 'test.db' AS db3; + ATTACH 'test.db' AS db4; + ATTACH 'test.db' AS db5; + ATTACH 'test.db' AS db6; + ATTACH 'test.db' AS db7; + ATTACH 'test.db' AS db8; + ATTACH 'test.db' AS db9; + } +} {} +proc db_list {db} { + set list {} + foreach {idx name file} [execsql {PRAGMA database_list} $db] { + lappend list $idx $name + } + return $list +} +ifcapable schema_pragmas { +do_test attach-1.11b { + db_list db +} {0 main 2 db2 3 db3 4 db4 5 db5 6 db6 7 db7 8 db8 9 db9} +} ;# ifcapable schema_pragmas +do_test attach-1.12 { + catchsql { + ATTACH 'test.db' as db2; + } +} {1 {database db2 is already in use}} +do_test attach-1.12.2 { + db errorcode +} {1} +do_test attach-1.13 { + catchsql { + ATTACH 'test.db' as db5; + } +} {1 {database db5 is already in use}} +do_test attach-1.14 { + catchsql { + ATTACH 'test.db' as db9; + } +} {1 {database db9 is already in use}} +do_catchsql_test attach-1.15 { + ATTACH 'test.db' as main; +} {1 {database main is already in use}} +ifcapable tempdb { + do_test attach-1.16 { + catchsql { + ATTACH 'test.db' as temp; + } + } {1 {database temp is already in use}} +} +do_catchsql_test attach-1.17 { + ATTACH 'test.db' as MAIN; +} {1 {database MAIN is already in use}} +do_test attach-1.18 { + catchsql { + ATTACH 'test.db' as db10; + ATTACH 'test.db' as db11; + } +} {0 {}} +if {$SQLITE_MAX_ATTACHED==10} { + do_test attach-1.19 { + catchsql { + ATTACH 'test.db' as db12; + } + } {1 {too many attached databases - max 10}} + do_test attach-1.19.1 { + db errorcode + } {1} +} +do_test attach-1.20.1 { + execsql { + DETACH db5; + } +} {} +ifcapable schema_pragmas { +do_test attach-1.20.2 { + db_list db +} {0 main 2 db2 3 db3 4 db4 5 db6 6 db7 7 db8 8 db9 9 db10 10 db11} +} ;# ifcapable schema_pragmas +integrity_check attach-1.20.3 +ifcapable tempdb { + execsql {select * from temp.sqlite_master} +} +do_test attach-1.21 { + catchsql { + ATTACH 'test.db' as db12; + } +} {0 {}} +if {$SQLITE_MAX_ATTACHED==10} { + do_test attach-1.22 { + catchsql { + ATTACH 'test.db' as db13; + } + } {1 {too many attached databases - max 10}} + do_test attach-1.22.1 { + db errorcode + } {1} +} +do_test attach-1.23 { + catchsql { + DETACH "db14"; + } +} {1 {no such database: db14}} +do_test attach-1.24 { + catchsql { + DETACH db12; + } +} {0 {}} +do_test attach-1.25 { + catchsql { + DETACH db12; + } +} {1 {no such database: db12}} +do_test attach-1.26 { + catchsql { + DETACH main; + } +} {1 {cannot detach database main}} + + +ifcapable tempdb { + do_test attach-1.27 { + catchsql { + DETACH Temp; + } + } {1 {cannot detach database Temp}} +} else { + do_test attach-1.27 { + catchsql { + DETACH Temp; + } + } {1 {no such database: Temp}} +} + +do_test attach-1.28 { + catchsql { + DETACH db11; + DETACH db10; + DETACH db9; + DETACH db8; + DETACH db7; + DETACH db6; + DETACH db4; + DETACH db3; + DETACH db2; + } +} {0 {}} +ifcapable schema_pragmas { + ifcapable tempdb { + do_test attach-1.29 { + db_list db + } {0 main 1 temp} + } else { + do_test attach-1.29 { + db_list db + } {0 main} + } +} ;# ifcapable schema_pragmas + +ifcapable {trigger} { # Only do the following tests if triggers are enabled +do_test attach-2.1 { + execsql { + CREATE TABLE tx(x1,x2,y1,y2); + CREATE TRIGGER r1 AFTER UPDATE ON t2 FOR EACH ROW BEGIN + INSERT INTO tx(x1,x2,y1,y2) VALUES(OLD.x,NEW.x,OLD.y,NEW.y); + END; + SELECT * FROM tx; + } db2; +} {} +do_test attach-2.2 { + execsql { + UPDATE t2 SET x=x+10; + SELECT * FROM tx; + } db2; +} {1 11 x x 2 12 y y} +do_test attach-2.3 { + execsql { + CREATE TABLE tx(x1,x2,y1,y2); + SELECT * FROM tx; + } +} {} +do_test attach-2.4 { + execsql { + ATTACH 'test2.db' AS db2; + } +} {} +do_test attach-2.5 { + execsql { + UPDATE db2.t2 SET x=x+10; + SELECT * FROM db2.tx; + } +} {1 11 x x 2 12 y y 11 21 x x 12 22 y y} +do_test attach-2.6 { + execsql { + SELECT * FROM main.tx; + } +} {} +do_test attach-2.7 { + execsql { + SELECT type, name, tbl_name FROM db2.sqlite_master; + } +} {table t2 t2 table tx tx trigger r1 t2} + +ifcapable schema_pragmas&&tempdb { + do_test attach-2.8 { + db_list db + } {0 main 1 temp 2 db2} +} ;# ifcapable schema_pragmas&&tempdb +ifcapable schema_pragmas&&!tempdb { + do_test attach-2.8 { + db_list db + } {0 main 2 db2} +} ;# ifcapable schema_pragmas&&!tempdb + +do_test attach-2.9 { + execsql { + CREATE INDEX i2 ON t2(x); + SELECT * FROM t2 WHERE x>5; + } db2 +} {21 x 22 y} +do_test attach-2.10 { + execsql { + SELECT type, name, tbl_name FROM sqlite_master; + } db2 +} {table t2 t2 table tx tx trigger r1 t2 index i2 t2} +#do_test attach-2.11 { +# catchsql { +# SELECT * FROM t2 WHERE x>5; +# } +#} {1 {database schema has changed}} +ifcapable schema_pragmas { + ifcapable tempdb { + do_test attach-2.12 { + db_list db + } {0 main 1 temp 2 db2} + } else { + do_test attach-2.12 { + db_list db + } {0 main 2 db2} + } +} ;# ifcapable schema_pragmas +do_test attach-2.13 { + catchsql { + SELECT * FROM t2 WHERE x>5; + } +} {0 {21 x 22 y}} +do_test attach-2.14 { + execsql { + SELECT type, name, tbl_name FROM sqlite_master; + } +} {table t1 t1 table tx tx} +do_test attach-2.15 { + execsql { + SELECT type, name, tbl_name FROM db2.sqlite_master; + } +} {table t2 t2 table tx tx trigger r1 t2 index i2 t2} +do_test attach-2.16 { + db close + sqlite3 db test.db + execsql { + ATTACH 'test2.db' AS db2; + SELECT type, name, tbl_name FROM db2.sqlite_master; + } +} {table t2 t2 table tx tx trigger r1 t2 index i2 t2} +} ;# End of ifcapable {trigger} + +do_test attach-3.1 { + db close + db2 close + sqlite3 db test.db + sqlite3 db2 test2.db + execsql { + SELECT * FROM t1 + } +} {1 2 3 4} + +# If we are testing a version of the code that lacks trigger support, +# adjust the database contents so that they are the same if triggers +# had been enabled. +ifcapable {!trigger} { + db2 eval { + DELETE FROM t2; + INSERT INTO t2 VALUES(21, 'x'); + INSERT INTO t2 VALUES(22, 'y'); + CREATE TABLE tx(x1,x2,y1,y2); + INSERT INTO tx VALUES(1, 11, 'x', 'x'); + INSERT INTO tx VALUES(2, 12, 'y', 'y'); + INSERT INTO tx VALUES(11, 21, 'x', 'x'); + INSERT INTO tx VALUES(12, 22, 'y', 'y'); + CREATE INDEX i2 ON t2(x); + } +} + +do_test attach-3.2 { + catchsql { + SELECT * FROM t2 + } +} {1 {no such table: t2}} +do_test attach-3.3 { + catchsql { + ATTACH DATABASE 'test2.db' AS db2; + SELECT * FROM t2 + } +} {0 {21 x 22 y}} + +# Even though 'db' has started a transaction, it should not yet have +# a lock on test2.db so 'db2' should be readable. +do_test attach-3.4 { + execsql BEGIN + catchsql { + SELECT * FROM t2; + } db2; +} {0 {21 x 22 y}} + +# Reading from test2.db from db within a transaction should not +# prevent test2.db from being read by db2. +do_test attach-3.5 { + execsql {SELECT * FROM t2} + catchsql { + SELECT * FROM t2; + } db2; +} {0 {21 x 22 y}} + +# Making a change to test2.db through db causes test2.db to get +# a reserved lock. It should still be accessible through db2. +do_test attach-3.6 { + execsql { + UPDATE t2 SET x=x+1 WHERE x=50; + } + catchsql { + SELECT * FROM t2; + } db2; +} {0 {21 x 22 y}} + +do_test attach-3.7 { + execsql ROLLBACK + execsql {SELECT * FROM t2} db2 +} {21 x 22 y} + +# Start transactions on both db and db2. Once again, just because +# we make a change to test2.db using db2, only a RESERVED lock is +# obtained, so test2.db should still be readable using db. +# +do_test attach-3.8 { + execsql BEGIN + execsql BEGIN db2 + execsql {UPDATE t2 SET x=0 WHERE 0} db2 + catchsql {SELECT * FROM t2} +} {0 {21 x 22 y}} + +# It is also still accessible from db2. +do_test attach-3.9 { + catchsql {SELECT * FROM t2} db2 +} {0 {21 x 22 y}} + +do_test attach-3.10 { + execsql {SELECT * FROM t1} +} {1 2 3 4} + +do_test attach-3.11 { + catchsql {UPDATE t1 SET a=a+1} +} {0 {}} +do_test attach-3.12 { + execsql {SELECT * FROM t1} +} {2 2 4 4} + +# db2 has a RESERVED lock on test2.db, so db cannot write to any tables +# in test2.db. +do_test attach-3.13 { + catchsql {UPDATE t2 SET x=x+1 WHERE x=50} +} {1 {database is locked}} + +# Change for version 3. Transaction is no longer rolled back +# for a locked database. +execsql {ROLLBACK} + +# db is able to reread its schema because db2 still only holds a +# reserved lock. +do_test attach-3.14 { + catchsql {SELECT * FROM t1} +} {0 {1 2 3 4}} +do_test attach-3.15 { + execsql COMMIT db2 + execsql {SELECT * FROM t1} +} {1 2 3 4} + +# Ticket #323 +do_test attach-4.1 { + execsql {DETACH db2} + db2 close + sqlite3 db2 test2.db + execsql { + CREATE TABLE t3(x,y); + CREATE UNIQUE INDEX t3i1 ON t3(x); + INSERT INTO t3 VALUES(1,2); + SELECT * FROM t3; + } db2; +} {1 2} +do_test attach-4.2 { + execsql { + CREATE TABLE t3(a,b); + CREATE UNIQUE INDEX t3i1b ON t3(a); + INSERT INTO t3 VALUES(9,10); + SELECT * FROM t3; + } +} {9 10} +do_test attach-4.3 { + execsql { + ATTACH DATABASE 'test2.db' AS db2; + SELECT * FROM db2.t3; + } +} {1 2} +do_test attach-4.4 { + execsql { + SELECT * FROM main.t3; + } +} {9 10} +do_test attach-4.5 { + execsql { + INSERT INTO db2.t3 VALUES(9,10); + SELECT * FROM db2.t3; + } +} {1 2 9 10} +execsql { + DETACH db2; +} +ifcapable {trigger} { + do_test attach-4.6 { + execsql { + CREATE TABLE t4(x); + CREATE TRIGGER t3r3 AFTER INSERT ON t3 BEGIN + INSERT INTO t4 VALUES('db2.' || NEW.x); + END; + INSERT INTO t3 VALUES(6,7); + SELECT * FROM t4; + } db2 + } {db2.6} + do_test attach-4.7 { + execsql { + CREATE TABLE t4(y); + CREATE TRIGGER t3r3 AFTER INSERT ON t3 BEGIN + INSERT INTO t4 VALUES('main.' || NEW.a); + END; + INSERT INTO main.t3 VALUES(11,12); + SELECT * FROM main.t4; + } + } {main.11} +} +ifcapable {!trigger} { + # When we do not have trigger support, set up the table like they + # would have been had triggers been there. The tests that follow need + # this setup. + execsql { + CREATE TABLE t4(x); + INSERT INTO t3 VALUES(6,7); + INSERT INTO t4 VALUES('db2.6'); + INSERT INTO t4 VALUES('db2.13'); + } db2 + execsql { + CREATE TABLE t4(y); + INSERT INTO main.t3 VALUES(11,12); + INSERT INTO t4 VALUES('main.11'); + } +} + + +# This one is tricky. On the UNION ALL select, we have to make sure +# the schema for both main and db2 is valid before starting to execute +# the first query of the UNION ALL. If we wait to test the validity of +# the schema for main until after the first query has run, that test will +# fail and the query will abort but we will have already output some +# results. When the query is retried, the results will be repeated. +# +ifcapable compound { +do_test attach-4.8 { + execsql { + ATTACH DATABASE 'test2.db' AS db2; + INSERT INTO db2.t3 VALUES(13,14); + SELECT * FROM db2.t4 UNION ALL SELECT * FROM main.t4; + } +} {db2.6 db2.13 main.11} + +do_test attach-4.9 { + ifcapable {!trigger} {execsql {INSERT INTO main.t4 VALUES('main.15')}} + execsql { + INSERT INTO main.t3 VALUES(15,16); + SELECT * FROM db2.t4 UNION ALL SELECT * FROM main.t4; + } +} {db2.6 db2.13 main.11 main.15} +} ;# ifcapable compound + +ifcapable !compound { + ifcapable {!trigger} {execsql {INSERT INTO main.t4 VALUES('main.15')}} + execsql { + ATTACH DATABASE 'test2.db' AS db2; + INSERT INTO db2.t3 VALUES(13,14); + INSERT INTO main.t3 VALUES(15,16); + } +} ;# ifcapable !compound + +ifcapable view { +do_test attach-4.10 { + execsql { + DETACH DATABASE db2; + } + execsql { + CREATE VIEW v3 AS SELECT x*100+y FROM t3; + SELECT * FROM v3; + } db2 +} {102 910 607 1314} +do_test attach-4.11 { + execsql { + CREATE VIEW v3 AS SELECT a*100+b FROM t3; + SELECT * FROM v3; + } +} {910 1112 1516} +do_test attach-4.12 { + execsql { + ATTACH DATABASE 'test2.db' AS db2; + SELECT * FROM db2.v3; + } +} {102 910 607 1314} +do_test attach-4.13 { + execsql { + SELECT * FROM main.v3; + } +} {910 1112 1516} +} ;# ifcapable view + +# Tests for the sqliteFix...() routines in attach.c +# +ifcapable {trigger} { +do_test attach-5.1 { + db close + sqlite3 db test.db + db2 close + forcedelete test2.db + sqlite3 db2 test2.db + catchsql { + ATTACH DATABASE 'test.db' AS orig; + CREATE TRIGGER r1 AFTER INSERT ON orig.t1 BEGIN + SELECT 'no-op'; + END; + } db2 +} {1 {trigger r1 cannot reference objects in database orig}} +do_test attach-5.2 { + catchsql { + CREATE TABLE t5(x,y); + CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN + SELECT 'no-op'; + END; + } db2 +} {0 {}} +do_test attach-5.3 { + catchsql { + DROP TRIGGER r5; + CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN + SELECT 'no-op' FROM orig.t1; + END; + } db2 +} {1 {trigger r5 cannot reference objects in database orig}} +ifcapable tempdb { + do_test attach-5.4 { + catchsql { + CREATE TEMP TABLE t6(p,q,r); + CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN + SELECT 'no-op' FROM temp.t6; + END; + } db2 + } {1 {trigger r5 cannot reference objects in database temp}} +} +ifcapable subquery { + do_test attach-5.5 { + catchsql { + CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN + SELECT 'no-op' || (SELECT * FROM temp.t6); + END; + } db2 + } {1 {trigger r5 cannot reference objects in database temp}} + do_test attach-5.6 { + catchsql { + CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN + SELECT 'no-op' FROM t1 WHERE x<(SELECT min(x) FROM temp.t6); + END; + } db2 + } {1 {trigger r5 cannot reference objects in database temp}} + do_test attach-5.7 { + catchsql { + CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN + SELECT 'no-op' FROM t1 GROUP BY 1 HAVING x<(SELECT min(x) FROM temp.t6); + END; + } db2 + } {1 {trigger r5 cannot reference objects in database temp}} + do_test attach-5.7 { + catchsql { + CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN + SELECT max(1,x,(SELECT min(x) FROM temp.t6)) FROM t1; + END; + } db2 + } {1 {trigger r5 cannot reference objects in database temp}} + do_test attach-5.8 { + catchsql { + CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN + INSERT INTO t1 VALUES((SELECT min(x) FROM temp.t6),5); + END; + } db2 + } {1 {trigger r5 cannot reference objects in database temp}} + do_test attach-5.9 { + catchsql { + CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN + DELETE FROM t1 WHERE x<(SELECT min(x) FROM temp.t6); + END; + } db2 + } {1 {trigger r5 cannot reference objects in database temp}} +} ;# endif subquery +ifcapable json1&&vtab { + do_test attach-5.10 { + db close + catch {db2 close} + forcedelete test.db + sqlite3 db test.db + db eval { + CREATE TABLE t1(x); + CREATE TABLE t2(a,b); + CREATE TRIGGER x1 AFTER INSERT ON t1 BEGIN + INSERT INTO t2(a,b) SELECT key, value FROM json_each(NEW.x); + END; + INSERT INTO t1(x) VALUES('{"a":1}'); + SELECT * FROM t2; + } + } {a 1} + do_test attach-5.11 { + sqlite3 db2 :memory: + db2 eval { + CREATE TABLE t3(y); + ATTACH 'test.db' AS aux; + INSERT INTO aux.t1(x) VALUES('{"b":2}'); + SELECT * FROM aux.t2; + } + } {a 1 b 2} +} ;# endif json1 +} ;# endif trigger + +# Check to make sure we get a sensible error if unable to open +# the file that we are trying to attach. +# +do_test attach-6.1 { + catchsql { + ATTACH DATABASE 'no-such-file' AS nosuch; + } +} {0 {}} +if {$tcl_platform(platform)=="unix"} { + do_test attach-6.2 { + sqlite3 dbx cannot-read + dbx eval {CREATE TABLE t1(a,b,c)} + dbx close + file attributes cannot-read -permission 0000 + if {[file writable cannot-read]} { + puts "\n**** Tests do not work when run as root ****" + forcedelete cannot-read + exit 1 + } + catchsql { + ATTACH DATABASE 'cannot-read' AS noread; + } + } {1 {unable to open database: cannot-read}} + do_test attach-6.2.2 { + db errorcode + } {14} + forcedelete cannot-read +} + +# Check the error message if we try to access a database that has +# not been attached. +do_test attach-6.3 { + catchsql { + CREATE TABLE no_such_db.t1(a, b, c); + } +} {1 {unknown database no_such_db}} +for {set i 2} {$i<=15} {incr i} { + catch {db$i close} +} +db close +forcedelete test2.db +forcedelete no-such-file + +ifcapable subquery { + do_test attach-7.1 { + forcedelete test.db test.db-journal + sqlite3 db test.db + catchsql { + DETACH RAISE ( IGNORE ) IN ( SELECT "AAAAAA" . * ORDER BY + REGISTER LIMIT "AAAAAA" . "AAAAAA" OFFSET RAISE ( IGNORE ) NOT NULL ) + } + } {1 {no such table: AAAAAA}} +} + +# Create a malformed file (a file that is not a valid database) +# and try to attach it +# +do_test attach-8.1 { + set fd [open test2.db w] + puts $fd "This file is not a valid SQLite database" + close $fd + catchsql { + ATTACH 'test2.db' AS t2; + } +} {1 {file is not a database}} +do_test attach-8.2 { + db errorcode +} {26} +forcedelete test2.db +do_test attach-8.3 { + sqlite3 db2 test2.db + db2 eval {CREATE TABLE t1(x); BEGIN EXCLUSIVE} + catchsql { + ATTACH 'test2.db' AS t2; + } +} {1 {database is locked}} +do_test attach-8.4 { + db errorcode +} {5} +db2 close +forcedelete test2.db + +# Test that it is possible to attach the same database more than +# once when not in shared-cache mode. That this is not possible in +# shared-cache mode is tested in shared7.test. +do_test attach-9.1 { + forcedelete test4.db + execsql { + ATTACH 'test4.db' AS aux1; + CREATE TABLE aux1.t1(a, b); + INSERT INTO aux1.t1 VALUES(1, 2); + ATTACH 'test4.db' AS aux2; + SELECT * FROM aux2.t1; + } +} {1 2} +do_test attach-9.2 { + catchsql { + BEGIN; + INSERT INTO aux1.t1 VALUES(3, 4); + INSERT INTO aux2.t1 VALUES(5, 6); + } +} {1 {database is locked}} +do_test attach-9.3 { + execsql { + COMMIT; + SELECT * FROM aux2.t1; + } +} {1 2 3 4} + +# Ticket [abe728bbc311d81334dae9762f0db87c07a98f79]. +# Multi-database commit on an attached TEMP database. +# +do_test attach-10.1 { + execsql { + ATTACH '' AS noname; + ATTACH ':memory:' AS inmem; + BEGIN; + CREATE TABLE noname.noname(x); + CREATE TABLE inmem.inmem(y); + CREATE TABLE main.main(z); + COMMIT; + SELECT name FROM noname.sqlite_master; + SELECT name FROM inmem.sqlite_master; + } +} {noname inmem} +do_test attach-10.2 { + lrange [execsql { + PRAGMA database_list; + }] 9 end +} {4 noname {} 5 inmem {}} + +# Attach with a very long URI filename. +# +db close +sqlite3 db test.db -uri 1 +do_execsql_test attach-11.1 { + ATTACH printf('file:%09000x/x.db?mode=memory&cache=shared',1) AS aux1; + CREATE TABLE aux1.t1(x,y); + INSERT INTO aux1.t1(x,y) VALUES(1,2),(3,4); + SELECT * FROM aux1.t1; +} {1 2 3 4} + +# Ticket https://sqlite.org/src/tktview/a4e06e75a9ab61a1 2017-07-15 +# False positive when running integrity_check on a connection with +# attached databases. +# +db close +sqlite3 db :memory: +do_execsql_test attach-12.1 { + CREATE TABLE Table1 (col TEXT NOT NULL PRIMARY KEY); + ATTACH ':memory:' AS db2; + CREATE TABLE db2.Table2(col1 INTEGER, col2 INTEGER, col3 INTEGER, col4); + CREATE UNIQUE INDEX db2.idx_col1_unique ON Table2 (col1); + CREATE UNIQUE INDEX db2.idx_col23_unique ON Table2 (col2, col3); + CREATE INDEX db2.idx_col2 ON Table2 (col2); + INSERT INTO Table2 VALUES(1,2,3,4); + PRAGMA integrity_check; +} {ok} + +# 2021-03-10 Forum post https://sqlite.org/forum/forumpost/a006d86f72 +# +reset_db +do_test attach-13.1 { + sqlite3 db :memory: + db eval {CREATE TABLE base(x);} + for {set i 0} {$i<$SQLITE_MAX_ATTACHED} {incr i} { + db eval "ATTACH ':memory:' AS a$i" + } + set m "a[expr {$SQLITE_MAX_ATTACHED-1}]" + db eval "CREATE TABLE $m.t1(a INTEGER PRIMARY KEY, b);" + db eval "CREATE TABLE $m.t2(a INTEGER PRIMARY KEY, b);" + db eval {SELECT a FROM t1 WHERE b IN (SELECT a FROM t2);} +} {} + +finish_test diff --git a/test/attach2.test b/test/attach2.test new file mode 100644 index 0000000..91e14ee --- /dev/null +++ b/test/attach2.test @@ -0,0 +1,451 @@ +# 2003 July 1 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script is testing the ATTACH and DETACH commands +# and related functionality. +# +# $Id: attach2.test,v 1.38 2007/12/13 21:54:11 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix attach2 + +ifcapable !attach { + finish_test + return +} + +# Ticket #354 +# +# Databases test.db and test2.db contain identical schemas. Make +# sure we can attach test2.db from test.db. +# +do_test attach2-1.1 { + db eval { + CREATE TABLE t1(a,b); + CREATE INDEX x1 ON t1(a); + } + forcedelete test2.db + forcedelete test2.db-journal + sqlite3 db2 test2.db + db2 eval { + CREATE TABLE t1(a,b); + CREATE INDEX x1 ON t1(a); + } + catchsql { + ATTACH 'test2.db' AS t2; + } +} {0 {}} + +# Ticket #514 +# +proc db_list {db} { + set list {} + foreach {idx name file} [execsql {PRAGMA database_list} $db] { + lappend list $idx $name + } + return $list +} +db eval {DETACH t2} +do_test attach2-2.1 { + # lock test2.db then try to attach it. This is no longer an error because + # db2 just RESERVES the database. It does not obtain a write-lock until + # we COMMIT. + db2 eval {BEGIN} + db2 eval {UPDATE t1 SET a = 0 WHERE 0} + catchsql { + ATTACH 'test2.db' AS t2; + } +} {0 {}} +ifcapable schema_pragmas { +do_test attach2-2.2 { + # make sure test2.db did get attached. + db_list db +} {0 main 2 t2} +} ;# ifcapable schema_pragmas +db2 eval {COMMIT} + +do_test attach2-2.5 { + # Make sure we can read test2.db from db + catchsql { + SELECT name FROM t2.sqlite_master; + } +} {0 {t1 x1}} +do_test attach2-2.6 { + # lock test2.db and try to read from it. This should still work because + # the lock is only a RESERVED lock which does not prevent reading. + # + db2 eval BEGIN + db2 eval {UPDATE t1 SET a = 0 WHERE 0} + catchsql { + SELECT name FROM t2.sqlite_master; + } +} {0 {t1 x1}} +do_test attach2-2.7 { + # but we can still read from test1.db even though test2.db is locked. + catchsql { + SELECT name FROM main.sqlite_master; + } +} {0 {t1 x1}} +do_test attach2-2.8 { + # start a transaction on test.db even though test2.db is locked. + catchsql { + BEGIN; + INSERT INTO t1 VALUES(8,9); + } +} {0 {}} +do_test attach2-2.9 { + execsql { + SELECT * FROM t1 + } +} {8 9} +do_test attach2-2.10 { + # now try to write to test2.db. the write should fail + catchsql { + INSERT INTO t2.t1 VALUES(1,2); + } +} {1 {database is locked}} +do_test attach2-2.11 { + # when the write failed in the previous test, the transaction should + # have rolled back. + # + # Update for version 3: A transaction is no longer rolled back if a + # database is found to be busy. + execsql {rollback} + db2 eval ROLLBACK + execsql { + SELECT * FROM t1 + } +} {} +do_test attach2-2.12 { + catchsql { + COMMIT + } +} {1 {cannot commit - no transaction is active}} + +# Ticket #574: Make sure it works using the non-callback API +# +do_test attach2-3.1 { + set DB [sqlite3_connection_pointer db] + set rc [catch {sqlite3_prepare $DB "ATTACH 'test2.db' AS t2" -1 TAIL} VM] + if {$rc} {lappend rc $VM} + sqlite3_step $VM + sqlite3_finalize $VM + set rc +} {0} +do_test attach2-3.2 { + set rc [catch {sqlite3_prepare $DB "DETACH t2" -1 TAIL} VM] + if {$rc} {lappend rc $VM} + sqlite3_step $VM + sqlite3_finalize $VM + set rc +} {0} + +db close +for {set i 2} {$i<=15} {incr i} { + catch {db$i close} +} + +# A procedure to verify the status of locks on a database. +# +proc lock_status {testnum db expected_result} { + # If the database was compiled with OMIT_TEMPDB set, then + # the lock_status list will not contain an entry for the temp + # db. But the test code doesn't know this, so its easiest + # to filter it out of the $expected_result list here. + ifcapable !tempdb { + set expected_result [concat \ + [lrange $expected_result 0 1] \ + [lrange $expected_result 4 end] \ + ] + } + do_test attach2-$testnum [subst { + $db cache flush ;# The lock_status pragma should not be cached + execsql {PRAGMA lock_status} $db + }] $expected_result +} +set sqlite_os_trace 0 + +# Tests attach2-4.* test that read-locks work correctly with attached +# databases. +do_test attach2-4.1 { + sqlite3 db test.db + sqlite3 db2 test.db + execsql {ATTACH 'test2.db' as file2} + execsql {ATTACH 'test2.db' as file2} db2 +} {} + +lock_status 4.1.1 db {main unlocked temp closed file2 unlocked} +lock_status 4.1.2 db2 {main unlocked temp closed file2 unlocked} + +do_test attach2-4.2 { + # Handle 'db' read-locks test.db + execsql {BEGIN} + execsql {SELECT * FROM t1} + # Lock status: + # db - shared(main) + # db2 - +} {} + +lock_status 4.2.1 db {main shared temp closed file2 unlocked} +lock_status 4.2.2 db2 {main unlocked temp closed file2 unlocked} + +do_test attach2-4.3 { + # The read lock held by db does not prevent db2 from reading test.db + execsql {SELECT * FROM t1} db2 +} {} + +lock_status 4.3.1 db {main shared temp closed file2 unlocked} +lock_status 4.3.2 db2 {main unlocked temp closed file2 unlocked} + +do_test attach2-4.4 { + # db is holding a read lock on test.db, so we should not be able + # to commit a write to test.db from db2 + catchsql { + INSERT INTO t1 VALUES(1, 2) + } db2 +} {1 {database is locked}} + +lock_status 4.4.1 db {main shared temp closed file2 unlocked} +lock_status 4.4.2 db2 {main unlocked temp closed file2 unlocked} + +# We have to make sure that the cache_size and the soft_heap_limit +# are large enough to hold the entire change in memory. If either +# is set too small, then changes will spill to the database, forcing +# a reserved lock to promote to exclusive. That will mess up our +# test results. + +set soft_limit [sqlite3_soft_heap_limit 0] + + +do_test attach2-4.5 { + # Handle 'db2' reserves file2. + execsql {BEGIN} db2 + execsql {INSERT INTO file2.t1 VALUES(1, 2)} db2 + # Lock status: + # db - shared(main) + # db2 - reserved(file2) +} {} + +lock_status 4.5.1 db {main shared temp closed file2 unlocked} +lock_status 4.5.2 db2 {main unlocked temp closed file2 reserved} + +do_test attach2-4.6.1 { + # Reads are allowed against a reserved database. + catchsql { + SELECT * FROM file2.t1; + } + # Lock status: + # db - shared(main), shared(file2) + # db2 - reserved(file2) +} {0 {}} + +lock_status 4.6.1.1 db {main shared temp closed file2 shared} +lock_status 4.6.1.2 db2 {main unlocked temp closed file2 reserved} + +do_test attach2-4.6.2 { + # Writes against a reserved database are not allowed. + catchsql { + UPDATE file2.t1 SET a=0; + } +} {1 {database is locked}} + +lock_status 4.6.2.1 db {main shared temp closed file2 shared} +lock_status 4.6.2.2 db2 {main unlocked temp closed file2 reserved} + +do_test attach2-4.7 { + # Ensure handle 'db' retains the lock on the main file after + # failing to obtain a write-lock on file2. + catchsql { + INSERT INTO t1 VALUES(1, 2) + } db2 +} {0 {}} + +lock_status 4.7.1 db {main shared temp closed file2 shared} +lock_status 4.7.2 db2 {main reserved temp closed file2 reserved} + +do_test attach2-4.8 { + # We should still be able to read test.db from db2 + execsql {SELECT * FROM t1} db2 +} {1 2} + +lock_status 4.8.1 db {main shared temp closed file2 shared} +lock_status 4.8.2 db2 {main reserved temp closed file2 reserved} + +do_test attach2-4.9 { + # Try to upgrade the handle 'db' lock. + catchsql { + INSERT INTO t1 VALUES(1, 2) + } +} {1 {database is locked}} + +lock_status 4.9.1 db {main shared temp closed file2 shared} +lock_status 4.9.2 db2 {main reserved temp closed file2 reserved} + +do_test attach2-4.10 { + # We cannot commit db2 while db is holding a read-lock + catchsql {COMMIT} db2 +} {1 {database is locked}} + +lock_status 4.10.1 db {main shared temp closed file2 shared} +lock_status 4.10.2 db2 {main pending temp closed file2 reserved} + +set sqlite_os_trace 0 +do_test attach2-4.11 { + # db is able to commit. + catchsql {COMMIT} +} {0 {}} + +lock_status 4.11.1 db {main unlocked temp closed file2 unlocked} +lock_status 4.11.2 db2 {main pending temp closed file2 reserved} + +do_test attach2-4.12 { + # Now we can commit db2 + catchsql {COMMIT} db2 +} {0 {}} + +lock_status 4.12.1 db {main unlocked temp closed file2 unlocked} +lock_status 4.12.2 db2 {main unlocked temp closed file2 unlocked} + +do_test attach2-4.13 { + execsql {SELECT * FROM file2.t1} +} {1 2} +do_test attach2-4.14 { + execsql {INSERT INTO t1 VALUES(1, 2)} +} {} +do_test attach2-4.15 { + execsql {SELECT * FROM t1} db2 +} {1 2 1 2} + +db close +db2 close +forcedelete test2.db +sqlite3_soft_heap_limit $soft_limit + +# These tests - attach2-5.* - check that the master journal file is deleted +# correctly when a multi-file transaction is committed or rolled back. +# +# Update: It's not actually created if a rollback occurs, so that test +# doesn't really prove too much. +foreach f [glob test.db*] {forcedelete $f} +do_test attach2-5.1 { + sqlite3 db test.db + execsql { + ATTACH 'test.db2' AS aux; + } +} {} +do_test attach2-5.2 { + execsql { + BEGIN; + CREATE TABLE tbl(a, b, c); + CREATE TABLE aux.tbl(a, b, c); + COMMIT; + } +} {} +do_test attach2-5.3 { + lsort [glob test.db*] +} {test.db test.db2} +do_test attach2-5.4 { + execsql { + BEGIN; + DROP TABLE aux.tbl; + DROP TABLE tbl; + ROLLBACK; + } +} {} +do_test attach2-5.5 { + lsort [glob test.db*] +} {test.db test.db2} + +# Check that a database cannot be ATTACHed or DETACHed during a transaction. +do_test attach2-6.1 { + execsql { + BEGIN; + } +} {} +do_test attach2-6.2 { + catchsql { + ATTACH 'test3.db' as aux2; + DETACH aux2; + } +} {0 {}} + +# As of version 3.21.0: it is ok to DETACH from within a transaction +# +do_test attach2-6.3 { + catchsql { + DETACH aux; + } +} {0 {}} + +db close + +ifcapable utf16 { + forcedelete test.db2 ;# utf-16 + forcedelete test.db3 ;# utf-16 + forcedelete test.db4 ;# utf-8 + + sqlite3 db2 test.db2 + do_execsql_test -db db2 1.1 { + PRAGMA encoding = 'utf16'; + CREATE TABLE t2(x); + INSERT INTO t2 VALUES('text2'); + } + db2 close + + sqlite3 db3 test.db3 + do_execsql_test -db db3 1.2 { + PRAGMA encoding = 'utf16'; + CREATE TABLE t3(x); + INSERT INTO t3 VALUES('text3'); + } + db3 close + + sqlite3 db4 test.db4 + do_execsql_test -db db4 1.3 { + PRAGMA encoding = 'utf8'; + CREATE TABLE t4(x); + INSERT INTO t4 VALUES('text4'); + } + db4 close + + reset_db + do_execsql_test 2.1 { + PRAGMA encoding = 'utf16'; + ATTACH 'test.db2' AS aux; + SELECT * FROM t2; + } {text2} + + reset_db + do_execsql_test 2.2 { + ATTACH 'test.db4' AS aux; + SELECT * FROM t4; + } {text4} + + db close + sqlite3 db test.db2 + do_execsql_test 2.3 { + ATTACH 'test.db3' AS aux; + SELECT * FROM t3; + SELECT * FROM t2; + } {text3 text2} + + db close + sqlite3 db test.db2 + do_catchsql_test 2.4 { + ATTACH 'test.db4' AS aux; + } {1 {attached databases must use the same text encoding as main database}} + + db close +} + +finish_test diff --git a/test/attach3.test b/test/attach3.test new file mode 100644 index 0000000..1c8601c --- /dev/null +++ b/test/attach3.test @@ -0,0 +1,353 @@ +# 2003 July 1 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script is testing the ATTACH and DETACH commands +# and schema changes to attached databases. +# +# $Id: attach3.test,v 1.18 2007/10/09 08:29:32 danielk1977 Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !attach { + finish_test + return +} + +# The tests in this file were written before SQLite supported recursive +# trigger invocation, and some tests depend on that to pass. So disable +# recursive triggers for this file. +catchsql { pragma recursive_triggers = off } + +# Create tables t1 and t2 in the main database +execsql { + CREATE TABLE t1(a, b); + CREATE TABLE t2(c, d); +} + +# Create tables t1 and t2 in database file test2.db +forcedelete test2.db +forcedelete test2.db-journal +sqlite3 db2 test2.db +execsql { + CREATE TABLE t1(a, b); + CREATE TABLE t2(c, d); +} db2 +db2 close + +# Create a table in the auxilary database. +do_test attach3-1.1 { + execsql { + ATTACH 'test2.db' AS aux; + } +} {} +do_test attach3-1.2 { + execsql { + CREATE TABLE aux.t3(e, f); + } +} {} +do_test attach3-1.3 { + execsql { + SELECT * FROM sqlite_master WHERE name = 't3'; + } +} {} +do_test attach3-1.4 { + execsql { + SELECT * FROM aux.sqlite_master WHERE name = 't3'; + } +} "table t3 t3 [expr $AUTOVACUUM?5:4] {CREATE TABLE t3(e, f)}" +do_test attach3-1.5 { + execsql { + INSERT INTO t3 VALUES(1, 2); + SELECT * FROM t3; + } +} {1 2} + +# Create an index on the auxilary database table. +do_test attach3-2.1 { + execsql { + CREATE INDEX aux.i1 on t3(e); + } +} {} +do_test attach3-2.2 { + execsql { + SELECT * FROM sqlite_master WHERE name = 'i1'; + } +} {} +do_test attach3-2.3 { + execsql { + SELECT * FROM aux.sqlite_master WHERE name = 'i1'; + } +} "index i1 t3 [expr $AUTOVACUUM?6:5] {CREATE INDEX i1 on t3(e)}" + +# Drop the index on the aux database table. +do_test attach3-3.1 { + execsql { + DROP INDEX aux.i1; + SELECT * FROM aux.sqlite_master WHERE name = 'i1'; + } +} {} +do_test attach3-3.2 { + execsql { + CREATE INDEX aux.i1 on t3(e); + SELECT * FROM aux.sqlite_master WHERE name = 'i1'; + } +} "index i1 t3 [expr $AUTOVACUUM?6:5] {CREATE INDEX i1 on t3(e)}" +do_test attach3-3.3 { + execsql { + DROP INDEX i1; + SELECT * FROM aux.sqlite_master WHERE name = 'i1'; + } +} {} + +# Drop tables t1 and t2 in the auxilary database. +do_test attach3-4.1 { + execsql { + DROP TABLE aux.t1; + SELECT name FROM aux.sqlite_master; + } +} {t2 t3} +do_test attach3-4.2 { + # This will drop main.t2 + execsql { + DROP TABLE t2; + SELECT name FROM aux.sqlite_master; + } +} {t2 t3} +do_test attach3-4.3 { + execsql { + DROP TABLE t2; + SELECT name FROM aux.sqlite_master; + } +} {t3} + +# Create a view in the auxilary database. +ifcapable view { +do_test attach3-5.1 { + execsql { + CREATE VIEW aux.v1 AS SELECT * FROM t3; + } +} {} +do_test attach3-5.2 { + execsql { + SELECT * FROM aux.sqlite_master WHERE name = 'v1'; + } +} {view v1 v1 0 {CREATE VIEW v1 AS SELECT * FROM t3}} +do_test attach3-5.3 { + execsql { + INSERT INTO aux.t3 VALUES('hello', 'world'); + SELECT * FROM v1; + } +} {1 2 hello world} + +# Drop the view +do_test attach3-6.1 { + execsql { + DROP VIEW aux.v1; + } +} {} +do_test attach3-6.2 { + execsql { + SELECT * FROM aux.sqlite_master WHERE name = 'v1'; + } +} {} +} ;# ifcapable view + +ifcapable {trigger} { +# Create a trigger in the auxilary database. +do_test attach3-7.1 { + execsql { + CREATE TRIGGER aux.tr1 AFTER INSERT ON t3 BEGIN + INSERT INTO t3 VALUES(new.e*2, new.f*2); + END; + } +} {} +do_test attach3-7.2 { + execsql { + DELETE FROM t3; + INSERT INTO t3 VALUES(10, 20); + SELECT * FROM t3; + } +} {10 20 20 40} +do_test attach3-5.3 { + execsql { + SELECT * FROM aux.sqlite_master WHERE name = 'tr1'; + } +} {trigger tr1 t3 0 {CREATE TRIGGER tr1 AFTER INSERT ON t3 BEGIN + INSERT INTO t3 VALUES(new.e*2, new.f*2); + END}} + +# Drop the trigger +do_test attach3-8.1 { + execsql { + DROP TRIGGER aux.tr1; + } +} {} +do_test attach3-8.2 { + execsql { + SELECT * FROM aux.sqlite_master WHERE name = 'tr1'; + } +} {} + +ifcapable tempdb { + # Try to trick SQLite into dropping the wrong temp trigger. + do_test attach3-9.0 { + execsql { + CREATE TABLE main.t4(a, b, c); + CREATE TABLE aux.t4(a, b, c); + CREATE TEMP TRIGGER tst_trigger BEFORE INSERT ON aux.t4 BEGIN + SELECT 'hello world'; + END; + SELECT count(*) FROM temp.sqlite_master; + } + } {1} + do_test attach3-9.1 { + execsql { + DROP TABLE main.t4; + SELECT count(*) FROM sqlite_temp_master; + } + } {1} + do_test attach3-9.2 { + execsql { + DROP TABLE aux.t4; + SELECT count(*) FROM temp.sqlite_master; + } + } {0} +} +} ;# endif trigger + +# Make sure the aux.sqlite_master table is read-only +do_test attach3-10.0 { + catchsql { + INSERT INTO aux.sqlite_master VALUES(1, 2, 3, 4, 5); + } +} {1 {table sqlite_master may not be modified}} + +# Failure to attach leaves us in a workable state. +# Ticket #811 +# +do_test attach3-11.0 { + catchsql { + ATTACH DATABASE '/nodir/nofile.x' AS notadb; + } +} {1 {unable to open database: /nodir/nofile.x}} +do_test attach3-11.1 { + catchsql { + ATTACH DATABASE ':memory:' AS notadb; + } +} {0 {}} +do_test attach3-11.2 { + catchsql { + DETACH DATABASE notadb; + } +} {0 {}} + +# Return a list of attached databases +# +proc db_list {} { + set x [execsql { + PRAGMA database_list; + }] + set y {} + foreach {n id file} $x {lappend y $id} + return $y +} + +ifcapable schema_pragmas&&tempdb { + +ifcapable !trigger { + execsql {create temp table dummy(dummy)} +} + +# Ticket #1825 +# +do_test attach3-12.1 { + db_list +} {main temp aux} +do_test attach3-12.2 { + execsql { + ATTACH DATABASE ? AS ? + } + db_list +} {main temp aux {}} +do_test attach3-12.3 { + execsql { + DETACH aux + } + db_list +} {main temp {}} +do_test attach3-12.4 { + execsql { + DETACH ? + } + db_list +} {main temp} +do_test attach3-12.5 { + execsql { + ATTACH DATABASE '' AS '' + } + db_list +} {main temp {}} +do_test attach3-12.6 { + execsql { + DETACH '' + } + db_list +} {main temp} +do_test attach3-12.7 { + execsql { + ATTACH DATABASE '' AS ? + } + db_list +} {main temp {}} +do_test attach3-12.8 { + execsql { + DETACH '' + } + db_list +} {main temp} +do_test attach3-12.9 { + execsql { + ATTACH DATABASE '' AS NULL + } + db_list +} {main temp {}} +do_test attach3-12.10 { + execsql { + DETACH ? + } + db_list +} {main temp} +do_test attach3-12.11 { + catchsql { + DETACH NULL + } +} {1 {no such database: }} +do_test attach3-12.12 { + catchsql { + ATTACH null AS null; + ATTACH '' AS ''; + } +} {1 {database is already in use}} +do_test attach3-12.13 { + db_list +} {main temp {}} +do_test attach3-12.14 { + execsql { + DETACH ''; + } + db_list +} {main temp} + +} ;# ifcapable pragma + +finish_test diff --git a/test/attach4.test b/test/attach4.test new file mode 100644 index 0000000..9d54e7d --- /dev/null +++ b/test/attach4.test @@ -0,0 +1,137 @@ +# 200 July 1 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script is attaching many database files to a single +# connection. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +set testprefix attach4 + +ifcapable !attach { + finish_test + return +} + +puts "Testing with SQLITE_MAX_ATTACHED=$SQLITE_MAX_ATTACHED" + +set files {main test.db} +for {set ii 0} {$ii < $SQLITE_MAX_ATTACHED} {incr ii} { + lappend files aux$ii "test.db$ii" +} + +do_test 1.1 { + sqlite3_limit db SQLITE_LIMIT_ATTACHED -1 +} $SQLITE_MAX_ATTACHED + +do_test 1.2.1 { + db close + foreach {name f} $files { forcedelete $f } + sqlite3 db test.db + + foreach {name f} $files { + if {$name == "main"} continue + execsql "ATTACH '$f' AS $name" + } + + db eval {PRAGMA database_list} { + lappend L $name [file tail $file] + } + set L +} $files + +do_catchsql_test 1.2.2 { + ATTACH 'x.db' AS next; +} [list 1 "too many attached databases - max $SQLITE_MAX_ATTACHED"] + +do_test 1.3 { + execsql BEGIN; + foreach {name f} $files { + execsql "CREATE TABLE $name.tbl(x)" + execsql "INSERT INTO $name.tbl VALUES('$f')" + } + execsql COMMIT; +} {} + +do_test 1.4 { + set L [list] + foreach {name f} $files { + lappend L $name [execsql "SELECT x FROM $name.tbl"] + } + set L +} $files + +set L [list] +set S "" +foreach {name f} $files { + if {[permutation] == "journaltest"} { + set mode delete + } else { + set mode wal + } + ifcapable !wal { set mode delete } + lappend L $mode + append S " + PRAGMA $name.journal_mode = WAL; + UPDATE $name.tbl SET x = '$name'; + " +} +do_execsql_test 1.5 $S $L + +do_test 1.6 { + set L [list] + foreach {name f} $files { + lappend L [execsql "SELECT x FROM $name.tbl"] $f + } + set L +} $files + +do_test 1.7 { + execsql BEGIN; + foreach {name f} $files { + execsql "UPDATE $name.tbl SET x = '$f'" + } + execsql COMMIT; +} {} + +do_test 1.8 { + set L [list] + foreach {name f} $files { + lappend L $name [execsql "SELECT x FROM $name.tbl"] + } + set L +} $files + +db close +foreach {name f} $files { forcedelete $f } + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 2.0 { + ATTACH DATABASE '' AS aux; + CREATE TABLE IF NOT EXISTS aux.t1(a, b); + CREATE TEMPORARY TRIGGER tr1 DELETE ON t1 BEGIN + DELETE FROM t1; + END; + CREATE TABLE temp.t1(a, b); +} + +do_execsql_test 2.1 { + DETACH DATABASE aux; +} + +do_execsql_test 2.2 { + DROP TRIGGER tr1; +} + +finish_test diff --git a/test/attachmalloc.test b/test/attachmalloc.test new file mode 100644 index 0000000..3c6a075 --- /dev/null +++ b/test/attachmalloc.test @@ -0,0 +1,78 @@ +# 2005 September 19 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the ATTACH statement and +# specifically out-of-memory conditions within that command. +# +# $Id: attachmalloc.test,v 1.10 2008/10/22 10:45:38 danielk1977 Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !attach { + finish_test + return +} + +source $testdir/malloc_common.tcl + +do_malloc_test attachmalloc-1 -tclprep { + catch { db close } + for {set i 2} {$i<=4} {incr i} { + catch { db$i close } + forcedelete test$i.db + forcedelete test$i.db-journal + } +} -tclbody { + if {[catch {sqlite3 db test.db}]} { + error "out of memory" + } + sqlite3_db_config_lookaside db 0 0 0 + sqlite3_extended_result_codes db 1 +} -sqlbody { + ATTACH 'test2.db' AS two; + CREATE TABLE two.t1(x); + ATTACH 'test3.db' AS three; + CREATE TABLE three.t1(x); + ATTACH 'test4.db' AS four; + CREATE TABLE four.t1(x); +} + +do_malloc_test attachmalloc-2 -tclprep { + forcedelete test2.db + forcedelete test2.db-journal + sqlite3 db2 test2.db + db2 eval { + CREATE TABLE t1(a, b, c); + CREATE INDEX i1 ON t1(a, b); + } + db2 close +} -sqlbody { + CREATE TABLE t1(d, e, f); + ATTACH 'test2.db' AS db1; +} + +ifcapable shared_cache { + set enable_shared_cache [sqlite3_enable_shared_cache 1] + sqlite3 dbaux test3.db + dbaux eval {SELECT * FROM sqlite_master} + do_malloc_test attachmalloc-3 -sqlbody { + SELECT * FROM sqlite_master; + ATTACH 'test3.db' AS three; + } -cleanup { + db eval { DETACH three } + } + dbaux close + sqlite3_enable_shared_cache $enable_shared_cache +} + +finish_test diff --git a/test/auth.test b/test/auth.test new file mode 100644 index 0000000..1d56f70 --- /dev/null +++ b/test/auth.test @@ -0,0 +1,2678 @@ +# 2003 April 4 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script is testing the sqlite3_set_authorizer() API +# and related functionality. +# +# $Id: auth.test,v 1.46 2009/07/02 18:40:35 danielk1977 Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# disable this test if the SQLITE_OMIT_AUTHORIZATION macro is +# defined during compilation. +if {[catch {db auth {}} msg]} { + finish_test + return +} + +rename proc proc_real +proc_real proc {name arguments script} { + proc_real $name $arguments $script + if {$name=="auth"} { + db authorizer ::auth + } +} + +do_test auth-1.1.1 { + db close + set ::DB [sqlite3 db test.db] + proc authx {code arg1 arg2 arg3 arg4 args} {return SQLITE_DENY} + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + db authorizer ::authx + # EVIDENCE-OF: R-03993-24285 Only a single authorizer can be in place on + # a database connection at a time. Each call to sqlite3_set_authorizer + # overrides the previous call. + # + # The authx authorizer above is overridden by the auth authorizer below + # authx is never invoked. + db authorizer ::auth + catchsql {CREATE TABLE t1(a,b,c)} +} {1 {not authorized}} +do_test auth-1.1.2 { + db errorcode +} {23} +do_test auth-1.1.3 { + db authorizer +} {::auth} +do_test auth-1.1.4 { + # Ticket #896. + catchsql { + SELECT x; + } +} {1 {no such column: x}} +do_test auth-1.2 { + execsql {SELECT name FROM sqlite_master} +} {} +# EVIDENCE-OF: R-04452-49349 When the callback returns SQLITE_DENY, the +# sqlite3_prepare_v2() or equivalent call that triggered the authorizer +# will fail with an error message explaining that access is denied. +do_test auth-1.3.1 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {CREATE TABLE t1(a,b,c)} +} {1 {not authorized}} +do_test auth-1.3.2 { + db errorcode +} {23} +do_test auth-1.3.3 { + set ::authargs +} {t1 {} main {}} +do_test auth-1.4 { + execsql {SELECT name FROM sqlite_master} +} {} + +ifcapable tempdb { + do_test auth-1.5 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {CREATE TEMP TABLE t1(a,b,c)} + } {1 {not authorized}} + do_test auth-1.6 { + execsql {SELECT name FROM temp.sqlite_master} + } {} + do_test auth-1.7.1 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TEMP_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {CREATE TEMP TABLE t1(a,b,c)} + } {1 {not authorized}} + do_test auth-1.7.2 { + set ::authargs + } {t1 {} temp {}} + do_test auth-1.8 { + execsql {SELECT name FROM sqlite_temp_master} + } {} +} + +do_test auth-1.9 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {CREATE TABLE t1(a,b,c)} +} {0 {}} +do_test auth-1.10 { + execsql {SELECT name FROM sqlite_master} +} {} +do_test auth-1.11 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {CREATE TABLE t1(a,b,c)} +} {0 {}} +do_test auth-1.12 { + execsql {SELECT name FROM sqlite_master} +} {} + +ifcapable tempdb { + do_test auth-1.13 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {CREATE TEMP TABLE t1(a,b,c)} + } {0 {}} + do_test auth-1.14 { + execsql {SELECT name FROM temp.sqlite_master} + } {} + do_test auth-1.15 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TEMP_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {CREATE TEMP TABLE t1(a,b,c)} + } {0 {}} + do_test auth-1.16 { + execsql {SELECT name FROM sqlite_temp_master} + } {} + + do_test auth-1.17 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {CREATE TEMP TABLE t1(a,b,c)} + } {0 {}} + do_test auth-1.18 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} +} + +do_test auth-1.19.1 { + set ::authargs {} + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TEMP_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {CREATE TABLE t2(a,b,c)} +} {0 {}} +do_test auth-1.19.2 { + set ::authargs +} {} +do_test auth-1.20 { + execsql {SELECT name FROM sqlite_master} +} {t2} + +do_test auth-1.21.1 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP TABLE t2} +} {1 {not authorized}} +do_test auth-1.21.2 { + set ::authargs +} {t2 {} main {}} +do_test auth-1.22 { + execsql {SELECT name FROM sqlite_master} +} {t2} +do_test auth-1.23.1 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP TABLE t2} +} {0 {}} +do_test auth-1.23.2 { + set ::authargs +} {t2 {} main {}} +do_test auth-1.24 { + execsql {SELECT name FROM sqlite_master} +} {t2} + +ifcapable tempdb { + do_test auth-1.25 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TEMP_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP TABLE t1} + } {1 {not authorized}} + do_test auth-1.26 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} + do_test auth-1.27 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TEMP_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP TABLE t1} + } {0 {}} + do_test auth-1.28 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} +} + +do_test auth-1.29 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="t2"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {INSERT INTO t2 VALUES(1,2,3)} +} {1 {not authorized}} +do_test auth-1.30 { + execsql {SELECT * FROM t2} +} {} +do_test auth-1.31 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="t2"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {INSERT INTO t2 VALUES(1,2,3)} +} {0 {}} +do_test auth-1.32 { + execsql {SELECT * FROM t2} +} {} +do_test auth-1.33 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="t1"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {INSERT INTO t2 VALUES(1,2,3)} +} {0 {}} +do_test auth-1.34 { + execsql {SELECT * FROM t2} +} {1 2 3} + +do_test auth-1.35.1 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {SELECT * FROM t2} +} {1 {access to t2.b is prohibited}} +ifcapable attach { + do_test auth-1.35.2 { + execsql {ATTACH DATABASE 'test.db' AS two} + catchsql {SELECT * FROM two.t2} + } {1 {access to two.t2.b is prohibited}} + execsql {DETACH DATABASE two} +} +# EVIDENCE-OF: R-38392-49970 If the action code is SQLITE_READ and the +# callback returns SQLITE_IGNORE then the prepared statement statement +# is constructed to substitute a NULL value in place of the table column +# that would have been read if SQLITE_OK had been returned. +do_test auth-1.36 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {SELECT * FROM t2} +} {0 {1 {} 3}} +do_test auth-1.37 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {SELECT * FROM t2 WHERE b=2} +} {0 {}} +do_test auth-1.38 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="a"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {SELECT * FROM t2 WHERE b=2} +} {0 {{} 2 3}} +do_test auth-1.39 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {SELECT * FROM t2 WHERE b IS NULL} +} {0 {1 {} 3}} +do_test auth-1.40 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {SELECT a,c FROM t2 WHERE b IS NULL} +} {1 {access to t2.b is prohibited}} + +do_test auth-1.41 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_UPDATE" && $arg1=="t2" && $arg2=="b"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {UPDATE t2 SET a=11} +} {0 {}} +do_test auth-1.42 { + execsql {SELECT * FROM t2} +} {11 2 3} +do_test auth-1.43 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_UPDATE" && $arg1=="t2" && $arg2=="b"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {UPDATE t2 SET b=22, c=33} +} {1 {not authorized}} +do_test auth-1.44 { + execsql {SELECT * FROM t2} +} {11 2 3} +do_test auth-1.45 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_UPDATE" && $arg1=="t2" && $arg2=="b"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {UPDATE t2 SET b=22, c=33} +} {0 {}} +do_test auth-1.46 { + execsql {SELECT * FROM t2} +} {11 2 33} + +do_test auth-1.47 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="t2"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DELETE FROM t2 WHERE a=11} +} {1 {not authorized}} +do_test auth-1.48 { + execsql {SELECT * FROM t2} +} {11 2 33} +do_test auth-1.49 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="t2"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DELETE FROM t2 WHERE a=11} +} {0 {}} +do_test auth-1.50 { + execsql {SELECT * FROM t2} +} {} +do_test auth-1.50.2 { + execsql {INSERT INTO t2 VALUES(11, 2, 33)} +} {} + +do_test auth-1.51 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_SELECT"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {SELECT * FROM t2} +} {1 {not authorized}} +do_test auth-1.52 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_SELECT"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {SELECT * FROM t2} +} {0 {}} +do_test auth-1.53 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_SELECT"} { + return SQLITE_OK + } + return SQLITE_OK + } + catchsql {SELECT * FROM t2} +} {0 {11 2 33}} + +# Update for version 3: There used to be a handful of test here that +# tested the authorisation callback with the COPY command. The following +# test makes the same database modifications as they used to. +do_test auth-1.54 { + execsql {INSERT INTO t2 VALUES(7, 8, 9);} +} {} +do_test auth-1.55 { + execsql {SELECT * FROM t2} +} {11 2 33 7 8 9} + +do_test auth-1.63 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP TABLE t2} +} {1 {not authorized}} +do_test auth-1.64 { + execsql {SELECT name FROM sqlite_master} +} {t2} +do_test auth-1.65 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="t2"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP TABLE t2} +} {1 {not authorized}} +do_test auth-1.66 { + execsql {SELECT name FROM sqlite_master} +} {t2} + +ifcapable tempdb { + do_test auth-1.67 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP TABLE t1} + } {1 {not authorized}} + do_test auth-1.68 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} + do_test auth-1.69 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="t1"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP TABLE t1} + } {1 {not authorized}} + do_test auth-1.70 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} +} + +do_test auth-1.71 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP TABLE t2} +} {0 {}} +do_test auth-1.72 { + execsql {SELECT name FROM sqlite_master} +} {t2} +do_test auth-1.73 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="t2"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP TABLE t2} +} {0 {}} +do_test auth-1.74 { + execsql {SELECT name FROM sqlite_master} +} {t2} + +ifcapable tempdb { + do_test auth-1.75 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP TABLE t1} + } {0 {}} + do_test auth-1.76 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} + do_test auth-1.77 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="t1"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP TABLE t1} + } {0 {}} + do_test auth-1.78 { + execsql {SELECT name FROM temp.sqlite_master} + } {t1} +} + +# Test cases auth-1.79 to auth-1.124 test creating and dropping views. +# Omit these if the library was compiled with views omitted. +ifcapable view { +do_test auth-1.79 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_VIEW"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2} +} {1 {not authorized}} +do_test auth-1.80 { + set ::authargs +} {v1 {} main {}} +do_test auth-1.81 { + execsql {SELECT name FROM sqlite_master} +} {t2} +do_test auth-1.82 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_VIEW"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2} +} {0 {}} +do_test auth-1.83 { + set ::authargs +} {v1 {} main {}} +do_test auth-1.84 { + execsql {SELECT name FROM sqlite_master} +} {t2} + +ifcapable tempdb { + do_test auth-1.85 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TEMP_VIEW"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2} + } {1 {not authorized}} + do_test auth-1.86 { + set ::authargs + } {v1 {} temp {}} + do_test auth-1.87 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} + do_test auth-1.88 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TEMP_VIEW"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2} + } {0 {}} + do_test auth-1.89 { + set ::authargs + } {v1 {} temp {}} + do_test auth-1.90 { + execsql {SELECT name FROM temp.sqlite_master} + } {t1} +} + +do_test auth-1.91 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2} +} {1 {not authorized}} +do_test auth-1.92 { + execsql {SELECT name FROM sqlite_master} +} {t2} +do_test auth-1.93 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2} +} {0 {}} +do_test auth-1.94 { + execsql {SELECT name FROM sqlite_master} +} {t2} + +ifcapable tempdb { + do_test auth-1.95 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2} + } {1 {not authorized}} + do_test auth-1.96 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} + do_test auth-1.97 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2} + } {0 {}} + do_test auth-1.98 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} +} + +do_test auth-1.99 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql { + CREATE VIEW v2 AS SELECT a+1,b+1 FROM t2; + DROP VIEW v2 + } +} {1 {not authorized}} +do_test auth-1.100 { + execsql {SELECT name FROM sqlite_master} +} {t2 v2} +do_test auth-1.101 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_VIEW"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP VIEW v2} +} {1 {not authorized}} +do_test auth-1.102 { + set ::authargs +} {v2 {} main {}} +do_test auth-1.103 { + execsql {SELECT name FROM sqlite_master} +} {t2 v2} +do_test auth-1.104 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP VIEW v2} +} {0 {}} +do_test auth-1.105 { + execsql {SELECT name FROM sqlite_master} +} {t2 v2} +do_test auth-1.106 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_VIEW"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP VIEW v2} +} {0 {}} +do_test auth-1.107 { + set ::authargs +} {v2 {} main {}} +do_test auth-1.108 { + execsql {SELECT name FROM sqlite_master} +} {t2 v2} +do_test auth-1.109 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_VIEW"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql {DROP VIEW v2} +} {0 {}} +do_test auth-1.110 { + set ::authargs +} {v2 {} main {}} +do_test auth-1.111 { + execsql {SELECT name FROM sqlite_master} +} {t2} + + +ifcapable tempdb { + do_test auth-1.112 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql { + CREATE TEMP VIEW v1 AS SELECT a+1,b+1 FROM t1; + DROP VIEW v1 + } + } {1 {not authorized}} + do_test auth-1.113 { + execsql {SELECT name FROM temp.sqlite_master} + } {t1 v1} + do_test auth-1.114 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TEMP_VIEW"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP VIEW v1} + } {1 {not authorized}} + do_test auth-1.115 { + set ::authargs + } {v1 {} temp {}} + do_test auth-1.116 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1 v1} + do_test auth-1.117 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP VIEW v1} + } {0 {}} + do_test auth-1.118 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1 v1} + do_test auth-1.119 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TEMP_VIEW"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP VIEW v1} + } {0 {}} + do_test auth-1.120 { + set ::authargs + } {v1 {} temp {}} + do_test auth-1.121 { + execsql {SELECT name FROM temp.sqlite_master} + } {t1 v1} + do_test auth-1.122 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TEMP_VIEW"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql {DROP VIEW v1} + } {0 {}} + do_test auth-1.123 { + set ::authargs + } {v1 {} temp {}} + do_test auth-1.124 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} +} +} ;# ifcapable view + +# Test cases auth-1.125 to auth-1.176 test creating and dropping triggers. +# Omit these if the library was compiled with triggers omitted. +# +ifcapable trigger&&tempdb { +do_test auth-1.125 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TRIGGER"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql { + CREATE TRIGGER r2 DELETE on t2 BEGIN + SELECT NULL; + END; + } +} {1 {not authorized}} +do_test auth-1.126 { + set ::authargs +} {r2 t2 main {}} +do_test auth-1.127 { + execsql {SELECT name FROM sqlite_master} +} {t2} +do_test auth-1.128 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql { + CREATE TRIGGER r2 DELETE on t2 BEGIN + SELECT NULL; + END; + } +} {1 {not authorized}} +do_test auth-1.129 { + execsql {SELECT name FROM sqlite_master} +} {t2} +do_test auth-1.130 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TRIGGER"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql { + CREATE TRIGGER r2 DELETE on t2 BEGIN + SELECT NULL; + END; + } +} {0 {}} +do_test auth-1.131 { + set ::authargs +} {r2 t2 main {}} +do_test auth-1.132 { + execsql {SELECT name FROM sqlite_master} +} {t2} +do_test auth-1.133 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql { + CREATE TRIGGER r2 DELETE on t2 BEGIN + SELECT NULL; + END; + } +} {0 {}} +do_test auth-1.134 { + execsql {SELECT name FROM sqlite_master} +} {t2} +do_test auth-1.135 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TRIGGER"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql { + CREATE TABLE tx(id); + CREATE TRIGGER r2 AFTER INSERT ON t2 BEGIN + INSERT INTO tx VALUES(NEW.rowid); + END; + } +} {0 {}} +do_test auth-1.136.1 { + set ::authargs +} {r2 t2 main {}} +do_test auth-1.136.2 { + execsql { + SELECT name FROM sqlite_master WHERE type='trigger' + } +} {r2} +do_test auth-1.136.3 { + proc auth {code arg1 arg2 arg3 arg4 args} { + lappend ::authargs $code $arg1 $arg2 $arg3 $arg4 + return SQLITE_OK + } + set ::authargs {} + execsql { + INSERT INTO t2 VALUES(1,2,3); + } + set ::authargs +} {SQLITE_INSERT t2 {} main {} SQLITE_INSERT tx {} main r2 SQLITE_READ t2 ROWID main r2} +do_test auth-1.136.4 { + execsql { + SELECT * FROM tx; + } +} {3} +do_test auth-1.137 { + execsql {SELECT name FROM sqlite_master} +} {t2 tx r2} +do_test auth-1.138 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TEMP_TRIGGER"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql { + CREATE TRIGGER r1 DELETE on t1 BEGIN + SELECT NULL; + END; + } +} {1 {not authorized}} +do_test auth-1.139 { + set ::authargs +} {r1 t1 temp {}} +do_test auth-1.140 { + execsql {SELECT name FROM temp.sqlite_master} +} {t1} +do_test auth-1.141 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql { + CREATE TRIGGER r1 DELETE on t1 BEGIN + SELECT NULL; + END; + } +} {1 {not authorized}} +do_test auth-1.142 { + execsql {SELECT name FROM sqlite_temp_master} +} {t1} +do_test auth-1.143 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TEMP_TRIGGER"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql { + CREATE TRIGGER r1 DELETE on t1 BEGIN + SELECT NULL; + END; + } +} {0 {}} +do_test auth-1.144 { + set ::authargs +} {r1 t1 temp {}} +do_test auth-1.145 { + execsql {SELECT name FROM temp.sqlite_master} +} {t1} +do_test auth-1.146 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql { + CREATE TRIGGER r1 DELETE on t1 BEGIN + SELECT NULL; + END; + } +} {0 {}} +do_test auth-1.147 { + execsql {SELECT name FROM sqlite_temp_master} +} {t1} +do_test auth-1.148 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TEMP_TRIGGER"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql { + CREATE TRIGGER r1 DELETE on t1 BEGIN + SELECT NULL; + END; + } +} {0 {}} +do_test auth-1.149 { + set ::authargs +} {r1 t1 temp {}} +do_test auth-1.150 { + execsql {SELECT name FROM temp.sqlite_master} +} {t1 r1} + +do_test auth-1.151 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP TRIGGER r2} +} {1 {not authorized}} +do_test auth-1.152 { + execsql {SELECT name FROM sqlite_master} +} {t2 tx r2} +do_test auth-1.153 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TRIGGER"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP TRIGGER r2} +} {1 {not authorized}} +do_test auth-1.154 { + set ::authargs +} {r2 t2 main {}} +do_test auth-1.155 { + execsql {SELECT name FROM sqlite_master} +} {t2 tx r2} +do_test auth-1.156 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP TRIGGER r2} +} {0 {}} +do_test auth-1.157 { + execsql {SELECT name FROM sqlite_master} +} {t2 tx r2} +do_test auth-1.158 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TRIGGER"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP TRIGGER r2} +} {0 {}} +do_test auth-1.159 { + set ::authargs +} {r2 t2 main {}} +do_test auth-1.160 { + execsql {SELECT name FROM sqlite_master} +} {t2 tx r2} +do_test auth-1.161 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TRIGGER"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql {DROP TRIGGER r2} +} {0 {}} +do_test auth-1.162 { + set ::authargs +} {r2 t2 main {}} +do_test auth-1.163 { + execsql { + DROP TABLE tx; + DELETE FROM t2 WHERE a=1 AND b=2 AND c=3; + SELECT name FROM sqlite_master; + } +} {t2} + +do_test auth-1.164 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP TRIGGER r1} +} {1 {not authorized}} +do_test auth-1.165 { + execsql {SELECT name FROM temp.sqlite_master} +} {t1 r1} +do_test auth-1.166 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TEMP_TRIGGER"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP TRIGGER r1} +} {1 {not authorized}} +do_test auth-1.167 { + set ::authargs +} {r1 t1 temp {}} +do_test auth-1.168 { + execsql {SELECT name FROM sqlite_temp_master} +} {t1 r1} +do_test auth-1.169 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP TRIGGER r1} +} {0 {}} +do_test auth-1.170 { + execsql {SELECT name FROM temp.sqlite_master} +} {t1 r1} +do_test auth-1.171 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TEMP_TRIGGER"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP TRIGGER r1} +} {0 {}} +do_test auth-1.172 { + set ::authargs +} {r1 t1 temp {}} +do_test auth-1.173 { + execsql {SELECT name FROM sqlite_temp_master} +} {t1 r1} +do_test auth-1.174 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TEMP_TRIGGER"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql {DROP TRIGGER r1} +} {0 {}} +do_test auth-1.175 { + set ::authargs +} {r1 t1 temp {}} +do_test auth-1.176 { + execsql {SELECT name FROM temp.sqlite_master} +} {t1} +} ;# ifcapable trigger + +do_test auth-1.177 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_INDEX"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {CREATE INDEX i2 ON t2(a)} +} {1 {not authorized}} +do_test auth-1.178 { + set ::authargs +} {i2 t2 main {}} +do_test auth-1.179 { + execsql {SELECT name FROM sqlite_master} +} {t2} +do_test auth-1.180 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {CREATE INDEX i2 ON t2(a)} +} {1 {not authorized}} +do_test auth-1.181 { + execsql {SELECT name FROM sqlite_master} +} {t2} +do_test auth-1.182 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_INDEX"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {CREATE INDEX i2 ON t2(b)} +} {0 {}} +do_test auth-1.183 { + set ::authargs +} {i2 t2 main {}} +do_test auth-1.184 { + execsql {SELECT name FROM sqlite_master} +} {t2} +do_test auth-1.185 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {CREATE INDEX i2 ON t2(b)} +} {0 {}} +do_test auth-1.186 { + execsql {SELECT name FROM sqlite_master} +} {t2} +do_test auth-1.187 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_INDEX"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql {CREATE INDEX i2 ON t2(a)} +} {0 {}} +do_test auth-1.188 { + set ::authargs +} {i2 t2 main {}} +do_test auth-1.189 { + execsql {SELECT name FROM sqlite_master} +} {t2 i2} + +ifcapable tempdb { + do_test auth-1.190 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TEMP_INDEX"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {CREATE INDEX i1 ON t1(a)} + } {1 {not authorized}} + do_test auth-1.191 { + set ::authargs + } {i1 t1 temp {}} + do_test auth-1.192 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} + do_test auth-1.193 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {CREATE INDEX i1 ON t1(b)} + } {1 {not authorized}} + do_test auth-1.194 { + execsql {SELECT name FROM temp.sqlite_master} + } {t1} + do_test auth-1.195 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TEMP_INDEX"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {CREATE INDEX i1 ON t1(b)} + } {0 {}} + do_test auth-1.196 { + set ::authargs + } {i1 t1 temp {}} + do_test auth-1.197 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} + do_test auth-1.198 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {CREATE INDEX i1 ON t1(c)} + } {0 {}} + do_test auth-1.199 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} + do_test auth-1.200 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TEMP_INDEX"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql {CREATE INDEX i1 ON t1(a)} + } {0 {}} + do_test auth-1.201 { + set ::authargs + } {i1 t1 temp {}} + do_test auth-1.202 { + execsql {SELECT name FROM temp.sqlite_master} + } {t1 i1} +} + +do_test auth-1.203 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP INDEX i2} +} {1 {not authorized}} +do_test auth-1.204 { + execsql {SELECT name FROM sqlite_master} +} {t2 i2} +do_test auth-1.205 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_INDEX"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP INDEX i2} +} {1 {not authorized}} +do_test auth-1.205a { + set ::authargs +} {i2 t2 main {}} +db eval { + ATTACH ':memory:' as di205; + CREATE TABLE di205.t1(x); + CREATE INDEX di205.t1x ON t1(x); +} +do_catchsql_test auth-1.205b { + DROP INDEX di205.t1x; +} {1 {not authorized}} +db eval { + DETACH di205; +} +do_test auth-1.206 { + set ::authargs +} {t1x t1 di205 {}} +do_test auth-1.207 { + execsql {SELECT name FROM sqlite_master} +} {t2 i2} +do_test auth-1.208 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP INDEX i2} +} {0 {}} +do_test auth-1.209 { + execsql {SELECT name FROM sqlite_master} +} {t2 i2} +do_test auth-1.210 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_INDEX"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP INDEX i2} +} {0 {}} +do_test auth-1.211 { + set ::authargs +} {i2 t2 main {}} +do_test auth-1.212 { + execsql {SELECT name FROM sqlite_master} +} {t2 i2} +do_test auth-1.213 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_INDEX"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql {DROP INDEX i2} +} {0 {}} +do_test auth-1.214 { + set ::authargs +} {i2 t2 main {}} +do_test auth-1.215 { + execsql {SELECT name FROM sqlite_master} +} {t2} + +ifcapable tempdb { + do_test auth-1.216 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP INDEX i1} + } {1 {not authorized}} + do_test auth-1.217 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1 i1} + do_test auth-1.218 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TEMP_INDEX"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP INDEX i1} + } {1 {not authorized}} + do_test auth-1.219 { + set ::authargs + } {i1 t1 temp {}} + do_test auth-1.220 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1 i1} + do_test auth-1.221 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP INDEX i1} + } {0 {}} + do_test auth-1.222 { + execsql {SELECT name FROM temp.sqlite_master} + } {t1 i1} + do_test auth-1.223 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TEMP_INDEX"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP INDEX i1} + } {0 {}} + do_test auth-1.224 { + set ::authargs + } {i1 t1 temp {}} + do_test auth-1.225 { + execsql {SELECT name FROM temp.sqlite_master} + } {t1 i1} + do_test auth-1.226 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TEMP_INDEX"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql {DROP INDEX i1} + } {0 {}} + do_test auth-1.227 { + set ::authargs + } {i1 t1 temp {}} + do_test auth-1.228 { + execsql {SELECT name FROM temp.sqlite_master} + } {t1} +} + +do_test auth-1.229 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_PRAGMA"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {PRAGMA full_column_names=on} +} {1 {not authorized}} +do_test auth-1.230 { + set ::authargs +} {full_column_names on {} {}} +do_test auth-1.231 { + execsql2 {SELECT a FROM t2} +} {a 11 a 7} +do_test auth-1.232 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_PRAGMA"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {PRAGMA full_column_names=on} +} {0 {}} +do_test auth-1.233 { + set ::authargs +} {full_column_names on {} {}} +do_test auth-1.234 { + execsql2 {SELECT a FROM t2} +} {a 11 a 7} +do_test auth-1.235 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_PRAGMA"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql {PRAGMA full_column_names=on} +} {0 {}} +do_test auth-1.236 { + execsql2 {SELECT a FROM t2} +} {t2.a 11 t2.a 7} +do_test auth-1.237 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_PRAGMA"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql {PRAGMA full_column_names=OFF} +} {0 {}} +do_test auth-1.238 { + set ::authargs +} {full_column_names OFF {} {}} +do_test auth-1.239 { + execsql2 {SELECT a FROM t2} +} {a 11 a 7} + +do_test auth-1.240 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_TRANSACTION"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {BEGIN} +} {1 {not authorized}} +do_test auth-1.241 { + set ::authargs +} {BEGIN {} {} {}} +do_test auth-1.242 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_TRANSACTION" && $arg1!="BEGIN"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {BEGIN; INSERT INTO t2 VALUES(44,55,66); COMMIT} +} {1 {not authorized}} +do_test auth-1.243 { + set ::authargs +} {COMMIT {} {} {}} +do_test auth-1.244 { + execsql {SELECT * FROM t2} +} {11 2 33 7 8 9 44 55 66} +do_test auth-1.245 { + catchsql {ROLLBACK} +} {1 {not authorized}} +do_test auth-1.246 { + set ::authargs +} {ROLLBACK {} {} {}} +do_test auth-1.247 { + catchsql {END TRANSACTION} +} {1 {not authorized}} +do_test auth-1.248 { + set ::authargs +} {COMMIT {} {} {}} +do_test auth-1.249 { + # EVIDENCE-OF: R-52112-44167 Disable the authorizer by installing a NULL + # callback. + db authorizer {} + catchsql {ROLLBACK} +} {0 {}} +do_test auth-1.250 { + execsql {SELECT * FROM t2} +} {11 2 33 7 8 9} + +# ticket #340 - authorization for ATTACH and DETACH. +# +ifcapable attach { + do_test auth-1.251 { + db authorizer ::auth + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_ATTACH"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + } + return SQLITE_OK + } + catchsql { + ATTACH DATABASE ':memory:' AS test1 + } + } {0 {}} + do_test auth-1.252a { + set ::authargs + } {:memory: {} {} {}} + do_test auth-1.252b { + db eval {DETACH test1} + set ::attachfilename :memory: + db eval {ATTACH $::attachfilename AS test1} + set ::authargs + } {{} {} {} {}} + do_test auth-1.252c { + db eval {DETACH test1} + db eval {ATTACH ':mem' || 'ory:' AS test1} + set ::authargs + } {{} {} {} {}} + do_test auth-1.253 { + catchsql {DETACH DATABASE test1} + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_ATTACH"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql { + ATTACH DATABASE ':memory:' AS test1; + } + } {1 {not authorized}} + do_test auth-1.254 { + lindex [execsql {PRAGMA database_list}] 7 + } {} + do_test auth-1.255 { + catchsql {DETACH DATABASE test1} + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_ATTACH"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql { + ATTACH DATABASE ':memory:' AS test1; + } + } {0 {}} + do_test auth-1.256 { + lindex [execsql {PRAGMA database_list}] 7 + } {} + do_test auth-1.257 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DETACH"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + execsql {ATTACH DATABASE ':memory:' AS test1} + catchsql { + DETACH DATABASE test1; + } + } {0 {}} + do_test auth-1.258 { + lindex [execsql {PRAGMA database_list}] 7 + } {} + do_test auth-1.259 { + execsql {ATTACH DATABASE ':memory:' AS test1} + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DETACH"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql { + DETACH DATABASE test1; + } + } {0 {}} + ifcapable tempdb { + ifcapable schema_pragmas { + do_test auth-1.260 { + lindex [execsql {PRAGMA database_list}] 7 + } {test1} + } ;# ifcapable schema_pragmas + do_test auth-1.261 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DETACH"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql { + DETACH DATABASE test1; + } + } {1 {not authorized}} + ifcapable schema_pragmas { + do_test auth-1.262 { + lindex [execsql {PRAGMA database_list}] 7 + } {test1} + } ;# ifcapable schema_pragmas + db authorizer {} + execsql {DETACH DATABASE test1} + db authorizer ::auth + + # Authorization for ALTER TABLE. These tests are omitted if the library + # was built without ALTER TABLE support. + ifcapable altertable { + + do_test auth-1.263 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_ALTER_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql { + ALTER TABLE t1 RENAME TO t1x + } + } {0 {}} + do_test auth-1.264 { + execsql {SELECT name FROM sqlite_temp_master WHERE type='table'} + } {t1x} + do_test auth-1.265 { + set authargs + } {temp t1 {} {}} + do_test auth-1.266 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_ALTER_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql { + ALTER TABLE t1x RENAME TO t1 + } + } {0 {}} + do_test auth-1.267 { + execsql {SELECT name FROM temp.sqlite_master WHERE type='table'} + } {t1x} + do_test auth-1.268 { + set authargs + } {temp t1x {} {}} + do_test auth-1.269 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_ALTER_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql { + ALTER TABLE t1x RENAME TO t1 + } + } {1 {not authorized}} + do_test auth-1.270 { + execsql {SELECT name FROM sqlite_temp_master WHERE type='table'} + } {t1x} + + do_test auth-1.271 { + set authargs + } {temp t1x {} {}} + } ;# ifcapable altertable + + } else { + db authorizer {} + db eval { + DETACH DATABASE test1; + } + } +} + +ifcapable altertable { +db authorizer {} +catchsql {ALTER TABLE t1x RENAME TO t1} +db authorizer ::auth +do_test auth-1.272 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_ALTER_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql { + ALTER TABLE t2 RENAME TO t2x + } +} {0 {}} +do_test auth-1.273 { + execsql {SELECT name FROM sqlite_master WHERE type='table'} +} {t2x} +do_test auth-1.274 { + set authargs +} {main t2 {} {}} +do_test auth-1.275 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_ALTER_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql { + ALTER TABLE t2x RENAME TO t2 + } +} {0 {}} +do_test auth-1.276 { + execsql {SELECT name FROM sqlite_master WHERE type='table'} +} {t2x} +do_test auth-1.277 { + set authargs +} {main t2x {} {}} +do_test auth-1.278 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_ALTER_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql { + ALTER TABLE t2x RENAME TO t2 + } +} {1 {not authorized}} +do_test auth-1.279 { + execsql {SELECT name FROM sqlite_master WHERE type='table'} +} {t2x} +do_test auth-1.280 { + set authargs +} {main t2x {} {}} +db authorizer {} +catchsql {ALTER TABLE t2x RENAME TO t2} + +} ;# ifcapable altertable + +# Test the authorization callbacks for the REINDEX command. +ifcapable reindex { + +proc auth {code args} { + if {$code=="SQLITE_REINDEX"} { + set ::authargs [concat $::authargs [lrange $args 0 3]] + } + return SQLITE_OK +} +db authorizer auth +do_test auth-1.281 { + execsql { + CREATE TABLE t3(a PRIMARY KEY, b, c); + CREATE INDEX t3_idx1 ON t3(c COLLATE BINARY); + CREATE INDEX t3_idx2 ON t3(b COLLATE NOCASE); + } +} {} +do_test auth-1.282 { + set ::authargs {} + execsql { + REINDEX t3_idx1; + } + set ::authargs +} {t3_idx1 {} main {}} +do_test auth-1.283 { + set ::authargs {} + execsql { + REINDEX BINARY; + } + set ::authargs +} {t3_idx1 {} main {} sqlite_autoindex_t3_1 {} main {}} +do_test auth-1.284 { + set ::authargs {} + execsql { + REINDEX NOCASE; + } + set ::authargs +} {t3_idx2 {} main {}} +do_test auth-1.285 { + set ::authargs {} + execsql { + REINDEX t3; + } + set ::authargs +} {t3_idx2 {} main {} t3_idx1 {} main {} sqlite_autoindex_t3_1 {} main {}} +do_test auth-1.286 { + execsql { + DROP TABLE t3; + } +} {} +ifcapable tempdb { + do_test auth-1.287 { + execsql { + CREATE TEMP TABLE t3(a PRIMARY KEY, b, c); + CREATE INDEX t3_idx1 ON t3(c COLLATE BINARY); + CREATE INDEX t3_idx2 ON t3(b COLLATE NOCASE); + } + } {} + do_test auth-1.288 { + set ::authargs {} + execsql { + REINDEX temp.t3_idx1; + } + set ::authargs + } {t3_idx1 {} temp {}} + do_test auth-1.289 { + set ::authargs {} + execsql { + REINDEX BINARY; + } + set ::authargs + } {t3_idx1 {} temp {} sqlite_autoindex_t3_1 {} temp {}} + do_test auth-1.290 { + set ::authargs {} + execsql { + REINDEX NOCASE; + } + set ::authargs + } {t3_idx2 {} temp {}} + do_test auth-1.291 { + set ::authargs {} + execsql { + REINDEX temp.t3; + } + set ::authargs + } {t3_idx2 {} temp {} t3_idx1 {} temp {} sqlite_autoindex_t3_1 {} temp {}} + proc auth {code args} { + if {$code=="SQLITE_REINDEX"} { + set ::authargs [concat $::authargs [lrange $args 0 3]] + return SQLITE_DENY + } + return SQLITE_OK + } + do_test auth-1.292 { + set ::authargs {} + catchsql { + REINDEX temp.t3; + } + } {1 {not authorized}} + do_test auth-1.293 { + execsql { + DROP TABLE t3; + } + } {} +} + +} ;# ifcapable reindex + +ifcapable analyze { + proc auth {code args} { + if {$code=="SQLITE_ANALYZE"} { + set ::authargs [concat $::authargs [lrange $args 0 3]] + } + return SQLITE_OK + } + do_test auth-1.294 { + set ::authargs {} + execsql { + CREATE TABLE t4(a,b,c); + CREATE INDEX t4i1 ON t4(a); + CREATE INDEX t4i2 ON t4(b,a,c); + INSERT INTO t4 VALUES(1,2,3); + ANALYZE; + } + set ::authargs + } {t4 {} main {} t2 {} main {}} + do_test auth-1.295 { + execsql { + SELECT count(*) FROM sqlite_stat1; + } + } 3 + proc auth {code args} { + if {$code=="SQLITE_ANALYZE"} { + set ::authargs [concat $::authargs $args] + return SQLITE_DENY + } + return SQLITE_OK + } + do_test auth-1.296 { + set ::authargs {} + catchsql { + ANALYZE; + } + } {1 {not authorized}} + do_test auth-1.297 { + execsql { + SELECT count(*) FROM sqlite_stat1; + } + } 3 +} ;# ifcapable analyze + + +# Authorization for ALTER TABLE ADD COLUMN. +# These tests are omitted if the library +# was built without ALTER TABLE support. +ifcapable {altertable} { + do_test auth-1.300 { + execsql {CREATE TABLE t5(x)} + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_ALTER_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql { + ALTER TABLE t5 ADD COLUMN new_col_1; + } + } {0 {}} + do_test auth-1.301 { + set x [execsql {SELECT sql FROM sqlite_master WHERE name='t5'}] + regexp new_col_1 $x + } {1} + do_test auth-1.302 { + set authargs + } {main t5 {} {}} + db eval BEGIN + set authargs {} + do_execsql_test auth-1.302-drop-1 { + ALTER TABLE t5 DROP COLUMN new_col_1; + } {} + db eval ROLLBACK + do_test auth-1.302-drop-2 { + set authargs + } {main t5 new_col_1 {}} + do_test auth-1.303 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_ALTER_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql { + ALTER TABLE t5 ADD COLUMN new_col_2; + } + } {0 {}} + do_test auth-1.304 { + set x [execsql {SELECT sql FROM sqlite_master WHERE name='t5'}] + regexp new_col_2 $x + } {0} + do_test auth-1.305 { + set authargs + } {main t5 {} {}} + db eval BEGIN + set authargs {} + do_execsql_test auth-1.305-drop-1 { + ALTER TABLE t5 DROP COLUMN new_col_1; + SELECT 1 FROM sqlite_schema WHERE name='t5' AND sql LIKE '%new_col_1%'; + } {1} + db eval ROLLBACK + do_test auth-1.305-drop-2 { + set authargs + } {main t5 new_col_1 {}} + do_test auth-1.306 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_ALTER_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql { + ALTER TABLE t5 ADD COLUMN new_col_3 + } + } {1 {not authorized}} + do_test auth-1.307 { + set x [execsql {SELECT sql FROM temp.sqlite_master WHERE type='t5'}] + regexp new_col_3 $x + } {0} + do_test auth-1.308 { + set authargs + } {main t5 {} {}} + db eval BEGIN + set authargs {} + do_catchsql_test auth-1.308-drop-1 { + ALTER TABLE t5 DROP COLUMN new_col_1; + } {1 {not authorized}} + do_execsql_test auth-1.308-drop-2 { + SELECT 1 FROM sqlite_schema WHERE name='t5' AND sql LIKE '%new_col_1%'; + } {1} + do_test auth-1.308-drop-3 { + set authargs + } {main t5 new_col_1 {}} + db eval ROLLBACK + + execsql {DROP TABLE t5} +} ;# ifcapable altertable + +ifcapable {cte} { + do_test auth-1.310 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_RECURSIVE"} { + return SQLITE_DENY + } + return SQLITE_OK + } + db eval { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(a,b); + INSERT INTO t1 VALUES(1,2),(3,4),(5,6); + } + } {} + do_catchsql_test auth-1.311 { + WITH + auth1311(x,y) AS (SELECT a+b, b-a FROM t1) + SELECT * FROM auth1311 ORDER BY x; + } {0 {3 1 7 1 11 1}} + do_catchsql_test auth-1.312 { + WITH RECURSIVE + auth1312(x,y) AS (SELECT a+b, b-a FROM t1) + SELECT x, y FROM auth1312 ORDER BY x; + } {0 {3 1 7 1 11 1}} + do_catchsql_test auth-1.313 { + WITH RECURSIVE + auth1313(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM auth1313 WHERE x<5) + SELECT * FROM t1; + } {0 {1 2 3 4 5 6}} + do_catchsql_test auth-1.314 { + WITH RECURSIVE + auth1314(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM auth1314 WHERE x<5) + SELECT * FROM t1 LEFT JOIN auth1314; + } {1 {not authorized}} +} ;# ifcapable cte + +# +# db eval {SELECT sql FROM temp.sqlite_master} {puts "TEMP: $sql;"} +# db eval {SELECT sql FROM main.sqlite_master} {puts "MAIN: $sql;"} +# +# MAIN: CREATE TABLE "t2"(a,b,c); +# MAIN: CREATE TABLE t4(a,b,c); +# MAIN: CREATE INDEX t4i1 ON t4(a); +# MAIN: CREATE INDEX t4i2 ON t4(b,a,c); +# MAIN: CREATE TABLE sqlite_stat1(tbl,idx,stat); +# MAIN: CREATE TABLE t1(a,b); +# +ifcapable altertable&&vtab { + do_test auth-1.350 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_ALTER_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql { + ALTER TABLE t1 RENAME COLUMN b TO bcdefg; + } + } {0 {}} + do_execsql_test auth-1.351 { + SELECT name FROM pragma_table_info('t1') ORDER BY cid; + } {a bcdefg} + do_test auth-1.352 { + set authargs + } {main t1 {} {}} + do_test auth-1.353 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_ALTER_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql { + ALTER TABLE t1 RENAME COLUMN bcdefg TO b; + } + } {0 {}} + do_execsql_test auth-1.354 { + SELECT name FROM pragma_table_info('t1') ORDER BY cid; + } {a bcdefg} + do_test auth-1.355 { + set authargs + } {main t1 {} {}} + do_test auth-1.356 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_ALTER_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql { + ALTER TABLE t1 RENAME COLUMN bcdefg TO b; + } + } {1 {not authorized}} + do_execsql_test auth-1.357 { + SELECT name FROM pragma_table_info('t1') ORDER BY cid; + } {a bcdefg} + do_test auth-1.358 { + set authargs + } {main t1 {} {}} +} + +# 2022-12-28 +# The sqlite3_declare_vtab() call that occurs during pragma_table_list +# should not cause an authentication failure. +# +ifcapable vtab { + do_test auth-1.359 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_UPDATE"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {SELECT * FROM pragma_table_list WHERE name='xyzzy';} + } {0 {}} +} + +do_test auth-2.1 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="x"} { + return SQLITE_DENY + } + return SQLITE_OK + } + db authorizer ::auth + execsql {CREATE TABLE t3(x INTEGER PRIMARY KEY, y, z)} + catchsql {SELECT * FROM t3} +} {1 {access to t3.x is prohibited}} +do_test auth-2.1 { + catchsql {SELECT y,z FROM t3} +} {0 {}} +do_test auth-2.2 { + catchsql {SELECT ROWID,y,z FROM t3} +} {1 {access to t3.x is prohibited}} +do_test auth-2.3 { + catchsql {SELECT OID,y,z FROM t3} +} {1 {access to t3.x is prohibited}} +do_test auth-2.4 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="x"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + execsql {INSERT INTO t3 VALUES(44,55,66)} + catchsql {SELECT * FROM t3} +} {0 {{} 55 66}} +do_test auth-2.5 { + catchsql {SELECT rowid,y,z FROM t3} +} {0 {{} 55 66}} +do_test auth-2.6 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="ROWID"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {SELECT * FROM t3} +} {0 {44 55 66}} +do_test auth-2.7 { + catchsql {SELECT ROWID,y,z FROM t3} +} {0 {44 55 66}} +do_test auth-2.8 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="ROWID"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {SELECT ROWID,b,c FROM t2} +} {0 {{} 2 33 {} 8 9}} +do_test auth-2.9.1 { + # We have to flush the cache here in case the Tcl interface tries to + # reuse a statement compiled with sqlite3_prepare_v2(). In this case, + # the first error encountered is an SQLITE_SCHEMA error. Then, when + # trying to recompile the statement, the authorization error is encountered. + # If we do not flush the cache, the correct error message is returned, but + # the error code is SQLITE_SCHEMA, not SQLITE_ERROR as required by the test + # case after this one. + # + db cache flush + + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="ROWID"} { + return bogus + } + return SQLITE_OK + } + catchsql {SELECT ROWID,b,c FROM t2} +} {1 {authorizer malfunction}} +do_test auth-2.9.2 { + db errorcode +} {1} +do_test auth-2.10 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_SELECT"} { + return bogus + } + return SQLITE_OK + } + catchsql {SELECT ROWID,b,c FROM t2} +} {1 {authorizer malfunction}} +do_test auth-2.11.1 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_READ" && $arg2=="a"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {SELECT * FROM t2, t3} +} {0 {{} 2 33 44 55 66 {} 8 9 44 55 66}} +do_test auth-2.11.2 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_READ" && $arg2=="x"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {SELECT * FROM t2, t3} +} {0 {11 2 33 {} 55 66 7 8 9 {} 55 66}} + +# Make sure the OLD and NEW pseudo-tables of a trigger get authorized. +# +ifcapable trigger { + do_test auth-3.1 { + proc auth {code arg1 arg2 arg3 arg4 args} { + return SQLITE_OK + } + execsql { + CREATE TABLE tx(a1,a2,b1,b2,c1,c2); + CREATE TRIGGER r1 AFTER UPDATE ON t2 FOR EACH ROW BEGIN + INSERT INTO tx VALUES(OLD.a,NEW.a,OLD.b,NEW.b,OLD.c,NEW.c); + END; + UPDATE t2 SET a=a+1; + SELECT * FROM tx; + } + } {11 12 2 2 33 33 7 8 8 8 9 9} + do_test auth-3.2 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="c"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + execsql { + DELETE FROM tx; + UPDATE t2 SET a=a+100; + SELECT * FROM tx; + } + } {12 112 2 2 {} {} 8 108 8 8 {} {}} +} ;# ifcapable trigger + +# Make sure the names of views and triggers are passed on on arg4. +# +ifcapable trigger { +do_test auth-4.1 { + proc auth {code arg1 arg2 arg3 arg4 args} { + lappend ::authargs $code $arg1 $arg2 $arg3 $arg4 + return SQLITE_OK + } + set authargs {} + execsql { + UPDATE t2 SET a=a+1; + } + set authargs +} [list \ + SQLITE_READ t2 a main {} \ + SQLITE_UPDATE t2 a main {} \ + SQLITE_INSERT tx {} main r1 \ + SQLITE_READ t2 a main r1 \ + SQLITE_READ t2 a main r1 \ + SQLITE_READ t2 b main r1 \ + SQLITE_READ t2 b main r1 \ + SQLITE_READ t2 c main r1 \ + SQLITE_READ t2 c main r1] +} + +ifcapable {view && trigger} { +do_test auth-4.2 { + execsql { + CREATE VIEW v1 AS SELECT a+b AS x FROM t2; + CREATE TABLE v1chng(x1,x2); + CREATE TRIGGER r2 INSTEAD OF UPDATE ON v1 BEGIN + INSERT INTO v1chng VALUES(OLD.x,NEW.x); + END; + SELECT * FROM v1; + } +} {115 117} +do_test auth-4.3 { + set authargs {} + execsql { + UPDATE v1 SET x=1 WHERE x=117 + } + set authargs +} [list \ + SQLITE_UPDATE v1 x main {} \ + SQLITE_SELECT {} {} {} v1 \ + SQLITE_READ t2 a main v1 \ + SQLITE_READ t2 b main v1 \ + SQLITE_READ v1 x main v1 \ + SQLITE_READ v1 x main v1 \ + SQLITE_SELECT {} {} {} v1 \ + SQLITE_READ v1 x main v1 \ + SQLITE_INSERT v1chng {} main r2 \ + SQLITE_READ v1 x main r2 \ + SQLITE_READ v1 x main r2 \ +] + +do_test auth-4.4 { + execsql { + CREATE TRIGGER r3 INSTEAD OF DELETE ON v1 BEGIN + INSERT INTO v1chng VALUES(OLD.x,NULL); + END; + SELECT * FROM v1; + } +} {115 117} +do_test auth-4.5 { + set authargs {} + execsql { + DELETE FROM v1 WHERE x=117 + } + set authargs +} [list \ + SQLITE_DELETE v1 {} main {} \ + SQLITE_SELECT {} {} {} v1 \ + SQLITE_READ t2 a main v1 \ + SQLITE_READ t2 b main v1 \ + SQLITE_READ v1 x main v1 \ + SQLITE_READ v1 x main v1 \ + SQLITE_SELECT {} {} {} v1 \ + SQLITE_READ v1 x main v1 \ + SQLITE_INSERT v1chng {} main r3 \ + SQLITE_READ v1 x main r3 \ +] + +} ;# ifcapable view && trigger + +# Ticket #1338: Make sure authentication works in the presence of an AS +# clause. +# +do_test auth-5.1 { + proc auth {code arg1 arg2 arg3 arg4 args} { + return SQLITE_OK + } + execsql { + SELECT count(a) AS cnt FROM t4 ORDER BY cnt + } +} {1} + +# Ticket #1607 +# +ifcapable compound&&subquery { + ifcapable trigger { + execsql { + DROP TABLE tx; + } + ifcapable view { + execsql { + DROP TABLE v1chng; + } + } + } + ifcapable stat4 { + set stat4 "sqlite_stat4 " + } else { + set stat4 "" + } + do_test auth-5.2 { + execsql { + SELECT name FROM ( + SELECT * FROM sqlite_master UNION ALL SELECT * FROM temp.sqlite_master) + WHERE type='table' + ORDER BY name + } + } "sqlite_stat1 ${stat4}t1 t2 t3 t4" +} + +# Ticket #3944 +# +ifcapable trigger { + do_test auth-5.3.1 { + execsql { + CREATE TABLE t5 ( x ); + CREATE TRIGGER t5_tr1 AFTER INSERT ON t5 BEGIN + UPDATE t5 SET x = 1 WHERE NEW.x = 0; + END; + } + } {} + set ::authargs [list] + proc auth {args} { + eval lappend ::authargs [lrange $args 0 4] + return SQLITE_OK + } + do_test auth-5.3.2 { + execsql { INSERT INTO t5 (x) values(0) } + set ::authargs + } [list SQLITE_INSERT t5 {} main {} \ + SQLITE_UPDATE t5 x main t5_tr1 \ + SQLITE_READ t5 x main t5_tr1 \ + ] + do_test auth-5.3.2 { + execsql { SELECT * FROM t5 } + } {1} +} + +# Ticket [0eb70d77cb05bb22720]: Invalid pointer passsed to the authorizer +# callback when updating a ROWID. +# +do_test auth-6.1 { + execsql { + CREATE TABLE t6(a,b,c,d,e,f,g,h); + INSERT INTO t6 VALUES(1,2,3,4,5,6,7,8); + } +} {} +set ::authargs [list] +proc auth {args} { + eval lappend ::authargs [lrange $args 0 4] + return SQLITE_OK +} +do_test auth-6.2 { + execsql {UPDATE t6 SET rowID=rowID+100} + set ::authargs +} [list SQLITE_READ t6 ROWID main {} \ + SQLITE_UPDATE t6 ROWID main {} \ +] +do_test auth-6.3 { + execsql {SELECT rowid, * FROM t6} +} {101 1 2 3 4 5 6 7 8} + +#------------------------------------------------------------------------- +# Test that view names are included as zArg4. +# +do_execsql_test auth-7.1 { + CREATE TABLE t7(a, b, c); + CREATE VIEW v7 AS SELECT * FROM t7; +} {} +set ::authargs [list] +proc auth {args} { + eval lappend ::authargs [lrange $args 0 4] + return SQLITE_OK +} + +do_test auth-7.2 { + execsql {SELECT a, c FROM v7} + set ::authargs +} [list \ + SQLITE_SELECT {} {} {} {} \ + SQLITE_READ t7 a main v7 \ + SQLITE_READ t7 b main v7 \ + SQLITE_READ t7 c main v7 \ + SQLITE_READ v7 a main {} \ + SQLITE_READ v7 c main {} \ + SQLITE_SELECT {} {} {} v7 \ +] + +set ::authargs [list] +do_test auth-7.3 { + execsql {SELECT a, c FROM t7} + set ::authargs +} [list \ + SQLITE_SELECT {} {} {} {} \ + SQLITE_READ t7 a main {} \ + SQLITE_READ t7 c main {} \ +] + +set ::authargs [list] +do_test auth-7.4 { + execsql {SELECT a, c FROM t7 AS v7} + set ::authargs +} [list \ + SQLITE_SELECT {} {} {} {} \ + SQLITE_READ t7 a main {} \ + SQLITE_READ t7 c main {} \ +] + +# If a table is referenced but no columns are read from the table, +# that causes a single SQLITE_READ authorization with a NULL column +# name. +# +# EVIDENCE-OF: R-31520-16302 When a table is referenced by a SELECT but +# no column values are extracted from that table (for example in a query +# like "SELECT count(*) FROM tab") then the SQLITE_READ authorizer +# callback is invoked once for that table with a column name that is an +# empty string. +# +set ::authargs [list] +do_test auth-8.1 { + execsql {SELECT count(*) FROM t7} + set ::authargs +} [list \ + SQLITE_SELECT {} {} {} {} \ + SQLITE_FUNCTION {} count {} {} \ + SQLITE_READ t7 {} {} {} \ + ] +set ::authargs [list] + +do_test auth-8.2 { + execsql {SELECT t6.a FROM t6, t7} + set ::authargs +} [list \ + SQLITE_SELECT {} {} {} {} \ + SQLITE_READ t6 a main {} \ + SQLITE_READ t7 {} {} {} \ + ] + +# Test also that if SQLITE_DENY is returned from an SQLITE_READ authorizer +# invocation with no column name specified, compilation fails. +# +set ::authargs [list] +proc auth {op args} { + foreach {a b c d} $args break + lappend ::authargs $op $a $b $c $d + if {$op == "SQLITE_READ"} { return "SQLITE_DENY" } + return "SQLITE_OK" +} +set ::authargs [list] +do_catchsql_test auth-8.3 { + SELECT count(*) FROM t7 +} {1 {not authorized}} +do_test auth-8.4 { + set ::authargs +} [list \ + SQLITE_SELECT {} {} {} {} \ + SQLITE_FUNCTION {} count {} {} \ + SQLITE_READ t7 {} {} {} \ +] + + +rename proc {} +rename proc_real proc +finish_test diff --git a/test/auth2.test b/test/auth2.test new file mode 100644 index 0000000..08d46ca --- /dev/null +++ b/test/auth2.test @@ -0,0 +1,160 @@ +# 2006 Aug 24 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script is testing the sqlite3_set_authorizer() API +# and related functionality. +# +# $Id: auth2.test,v 1.3 2008/07/02 13:13:53 danielk1977 Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# disable this test if the SQLITE_OMIT_AUTHORIZATION macro is +# defined during compilation. +if {[catch {db auth {}} msg]} { + finish_test + return +} + +do_test auth2-1.1 { + execsql { + CREATE TABLE t1(a,b,c); + INSERT INTO t1 VALUES(1,2,3); + } + set ::flist {} + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_FUNCTION"} { + lappend ::flist $arg2 + if {$arg2=="max"} { + return SQLITE_DENY + } elseif {$arg2=="min"} { + return SQLITE_IGNORE + } else { + return SQLITE_OK + } + } + return SQLITE_OK + } + db authorizer ::auth + catchsql {SELECT max(a,b,c) FROM t1} +} {1 {not authorized to use function: max}} +do_test auth2-1.2 { + set ::flist +} max +do_test auth2-1.3 { + set ::flist {} + catchsql {SELECT min(a,b,c) FROM t1} +} {0 {{}}} +do_test auth2-1.4 { + set ::flist +} min +do_test auth2-1.5 { + set ::flist {} + catchsql {SELECT coalesce(min(a,b,c),999) FROM t1} +} {0 999} +do_test auth2-1.6 { + set ::flist +} {coalesce min} +do_test auth2-1.7 { + set ::flist {} + catchsql {SELECT coalesce(a,b,c) FROM t1} +} {0 1} +do_test auth2-1.8 { + set ::flist +} coalesce + +# Make sure the authorizer is not called when parsing the schema +# and when computing the result set of a view. +# +db close +sqlite3 db test.db +sqlite3 db2 test.db +proc auth {args} { + global authargs + append authargs [lrange $args 0 4]\n + return SQLITE_OK +} +db auth auth +do_test auth2-2.1 { + set ::authargs {} + db eval { + CREATE TABLE t2(x,y,z); + } + set ::authargs +} {SQLITE_INSERT sqlite_master {} main {} +SQLITE_CREATE_TABLE t2 {} main {} +SQLITE_UPDATE sqlite_master type main {} +SQLITE_UPDATE sqlite_master name main {} +SQLITE_UPDATE sqlite_master tbl_name main {} +SQLITE_UPDATE sqlite_master rootpage main {} +SQLITE_UPDATE sqlite_master sql main {} +SQLITE_READ sqlite_master ROWID main {} +} +do_test auth2-2.2 { + set ::authargs {} + db eval { + CREATE VIEW v2 AS SELECT x+y AS a, y+z AS b from t2; + } + set ::authargs +} {SQLITE_INSERT sqlite_master {} main {} +SQLITE_CREATE_VIEW v2 {} main {} +SQLITE_UPDATE sqlite_master type main {} +SQLITE_UPDATE sqlite_master name main {} +SQLITE_UPDATE sqlite_master tbl_name main {} +SQLITE_UPDATE sqlite_master rootpage main {} +SQLITE_UPDATE sqlite_master sql main {} +SQLITE_READ sqlite_master ROWID main {} +} +do_test auth2-2.3 { + set ::authargs {} + db eval { + SELECT a, b FROM v2; + } + set ::authargs +} {SQLITE_SELECT {} {} {} {} +SQLITE_READ t2 x main v2 +SQLITE_READ t2 y main v2 +SQLITE_READ t2 y main v2 +SQLITE_READ t2 z main v2 +SQLITE_READ v2 a main {} +SQLITE_READ v2 b main {} +SQLITE_SELECT {} {} {} v2 +} +do_test auth2-2.4 { + db2 eval { + CREATE TABLE t3(p,q,r); + } + set ::authargs {} + db eval { + SELECT b, a FROM v2; + } + set ::authargs +} {SQLITE_SELECT {} {} {} {} +SQLITE_READ t2 x main v2 +SQLITE_READ t2 y main v2 +SQLITE_READ t2 y main v2 +SQLITE_READ t2 z main v2 +SQLITE_READ v2 b main {} +SQLITE_READ v2 a main {} +SQLITE_SELECT {} {} {} v2 +SQLITE_SELECT {} {} {} {} +SQLITE_READ t2 x main v2 +SQLITE_READ t2 y main v2 +SQLITE_READ t2 y main v2 +SQLITE_READ t2 z main v2 +SQLITE_READ v2 b main {} +SQLITE_READ v2 a main {} +SQLITE_SELECT {} {} {} v2 +} +db2 close + +finish_test diff --git a/test/auth3.test b/test/auth3.test new file mode 100644 index 0000000..abc9734 --- /dev/null +++ b/test/auth3.test @@ -0,0 +1,134 @@ +# 2008 October 27 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Test that the truncate optimization is disabled if the SQLITE_DELETE +# authorization callback returns SQLITE_IGNORE. +# +# Test that authorizer is disabled during schema parsing. + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# disable this test if the SQLITE_OMIT_AUTHORIZATION macro is +# defined during compilation. +if {[catch {db auth {}} msg]} { + finish_test + return +} + +# Disable the statement cache for these tests. +# +db cache size 0 + +db authorizer ::auth +proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE"} { + return $::authcode + } + return SQLITE_OK +} + +#-------------------------------------------------------------------------- +# The following tests - auth3-1.* - test that return values of SQLITE_DENY, +# SQLITE_IGNORE, SQLITE_OK and are correctly handled when returned +# by an SQLITE_DELETE authorization callback triggered by a +# "DELETE FROM " statement. +# +do_test auth3-1.1 { + execsql { + CREATE TABLE t1(a,b,c); + INSERT INTO t1 VALUES(1, 2, 3); + INSERT INTO t1 VALUES(4, 5, 6); + } +} {} +do_test auth3.1.2 { + set ::authcode SQLITE_DENY + catchsql { DELETE FROM t1 } +} {1 {not authorized}} +# EVIDENCE-OF: R-64962-58611 If the authorizer callback returns any +# value other than SQLITE_IGNORE, SQLITE_OK, or SQLITE_DENY then the +# sqlite3_prepare_v2() or equivalent call that triggered the authorizer +# will fail with an error message. +do_test auth3.1.3 { + set ::authcode SQLITE_INVALID + catchsql { DELETE FROM t1 } +} {1 {authorizer malfunction}} +do_test auth3.1.4 { + execsql { SELECT * FROM t1 } +} {1 2 3 4 5 6} +do_test auth3-1.5 { + set ::authcode SQLITE_IGNORE + execsql { + DELETE FROM t1; + SELECT * FROM t1; + } +} {} +do_test auth3-1.6 { + set ::authcode SQLITE_OK + execsql { + INSERT INTO t1 VALUES(1, 2, 3); + INSERT INTO t1 VALUES(4, 5, 6); + DELETE FROM t1; + SELECT * FROM t1; + } +} {} + +#-------------------------------------------------------------------------- +# These tests - auth3-2.* - test that returning SQLITE_IGNORE really does +# disable the truncate optimization. +# +do_test auth3-2.1 { + set ::authcode SQLITE_OK + execsql { + INSERT INTO t1 VALUES(1, 2, 3); + INSERT INTO t1 VALUES(4, 5, 6); + } + set sqlite_search_count 0 + execsql { + DELETE FROM t1; + } + set sqlite_search_count +} {0} + +do_test auth3-2.2 { + set ::authcode SQLITE_IGNORE + execsql { + INSERT INTO t1 VALUES(1, 2, 3); + INSERT INTO t1 VALUES(4, 5, 6); + } + set sqlite_search_count 0 + execsql { + DELETE FROM t1; + } + set sqlite_search_count +} {1} + +# 2016-07-28. A problem report from a private client complaining about +# an authorizer failure during an ALTER TABLE. The solution (I think) is +# to disable the authorizer during schema parsing. +# +ifcapable altertable { + proc auth {code args} { + if {$code=="SQLITE_READ" && [regexp {DoNotRead} $args]} { + return SQLITE_DENY + } + return SQLITE_OK + } + do_execsql_test auth3-3.0 { + CREATE TEMPORARY TABLE TempTable ( + key TEXT NOT NULL ON CONFLICT FAIL UNIQUE ON CONFLICT REPLACE, + value TEXT NOT NULL ON CONFLICT FAIL); + ALTER TABLE TempTable RENAME TO DoNotRead; + SELECT name FROM temp.sqlite_master; + } {DoNotRead sqlite_autoindex_DoNotRead_1} +} + +finish_test diff --git a/test/autoanalyze1.test b/test/autoanalyze1.test new file mode 100644 index 0000000..71e5d6c --- /dev/null +++ b/test/autoanalyze1.test @@ -0,0 +1,123 @@ +# 2017-02-17 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file implements tests for the logic used to estimate when +# running ANALYZE would be beneficial. +# +# Note that this test uses some hard-coded bitmask values from sqliteInt.h. +# If any of the following constants changes: +# +# define TF_HasStat1 0x0010 +# define TF_StatsUsed 0x0100 +# +# then some of the magic numbers in test results below might need to be +# adjusted. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# There is nothing to test if ANALYZE is disable for this build. +# These tests also use "PRAGMA stats" which are only enabled for +# debugging builds. +# +ifcapable {!debug || !analyze || !vtab} { + finish_test + return +} + +do_execsql_test autoanalyze1-100 { + -- Build up a test table with some indexes + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, d); + CREATE UNIQUE INDEX t1bc ON t1(b,c); + CREATE INDEX t1d ON t1(d); + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100) + INSERT INTO t1(a,b,c,d) SELECT x, x, x, x FROM c; + -- Verify that the hasStat1 flag is clear on on indexes + SELECT idx, flgs FROM pragma_stats + WHERE idx IS NOT NULL + ORDER BY idx; + -- Verify that the TF_HasStat1 flag is clear on the table + SELECT tbl, (flgs & 0x10)!=0 FROM pragma_stats WHERE tbl='t1' AND idx IS NULL; +} {t1bc 0 t1d 0 t1 0} + +# No use of stat1 recorded so far +do_execsql_test autoanalyze1-110 { + SELECT (flgs & 0x0100)!=0 FROM pragma_stats WHERE tbl='t1' AND idx IS NULL; +} {0} + +# Access using a unique index does not set the TF_StatsUsed flag. +# +do_execsql_test autoanalyze1-200 { + SELECT * FROM t1 WHERE a=55; +} {55 55 55 55} +do_execsql_test autoanalyze1-201 { + SELECT (flgs & 0x0100)!=0 FROM pragma_stats WHERE tbl='t1' AND idx IS NULL; +} {0} + +do_execsql_test autoanalyze1-210 { + SELECT * FROM t1 WHERE a IN (55,199,299); +} {55 55 55 55} +do_execsql_test autoanalyze1-211 { + SELECT (flgs & 0x0100)!=0 FROM pragma_stats WHERE tbl='t1' AND idx IS NULL; +} {0} + +do_execsql_test autoanalyze1-220 { + SELECT * FROM t1 WHERE (b,c)=(45,45); +} {45 45 45 45} +do_execsql_test autoanalyze1-221 { + SELECT (flgs & 0x0100)!=0 FROM pragma_stats WHERE tbl='t1' AND idx IS NULL; +} {0} + +# Any use of the non-unique t1d index triggers the use of stats. +# +sqlite3 db test.db +do_execsql_test autoanalyze1-300 { + SELECT * FROM t1 WHERE d=45; +} {45 45 45 45} +do_execsql_test autoanalyze1-301 { + SELECT (flgs & 0x0100)!=0 FROM pragma_stats WHERE tbl='t1' AND idx IS NULL; +} {1} + +sqlite3 db test.db +do_execsql_test autoanalyze1-310 { + SELECT * FROM t1 WHERE d=45 AND a=45; +} {45 45 45 45} +do_execsql_test autoanalyze1-311 { + SELECT (flgs & 0x0100)!=0 FROM pragma_stats WHERE tbl='t1' AND idx IS NULL; +} {0} ;# The ROWID lookup short-circuits the d=45 constraint + +sqlite3 db test.db +do_execsql_test autoanalyze1-320 { + SELECT * FROM t1 WHERE d=45 AND a IN (45,46); +} {45 45 45 45} +do_execsql_test autoanalyze1-321 { + SELECT (flgs & 0x0100)!=0 FROM pragma_stats WHERE tbl='t1' AND idx IS NULL; +} {1} + +# Any use of prefix of a unique index triggers the use of stats +# +sqlite3 db test.db +do_execsql_test autoanalyze1-400 { + SELECT * FROM t1 WHERE b=45; +} {45 45 45 45} +do_execsql_test autoanalyze1-401 { + SELECT (flgs & 0x0100)!=0 FROM pragma_stats WHERE tbl='t1' AND idx IS NULL; +} {1} + +# The TF_StatsUsed flag is reset when the database is reopened +# +sqlite3 db test.db +do_execsql_test autoanalyze1-500 { + SELECT (flgs & 0x0100)!=0 FROM pragma_stats WHERE tbl='t1' AND idx IS NULL; +} {0} + +finish_test diff --git a/test/autoinc.test b/test/autoinc.test new file mode 100644 index 0000000..2c7ee2a --- /dev/null +++ b/test/autoinc.test @@ -0,0 +1,883 @@ +# 2004 November 12 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the AUTOINCREMENT features. +# +# $Id: autoinc.test,v 1.14 2009/06/23 20:28:54 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix autoinc + +# If the library is not compiled with autoincrement support then +# skip all tests in this file. +# +ifcapable {!autoinc} { + finish_test + return +} + +if {[permutation]=="inmemory_journal"} { + finish_test + return +} + +sqlite3_db_config_lookaside db 0 0 0 + +# The database is initially empty. +# +do_test autoinc-1.1 { + execsql { + SELECT name FROM sqlite_master WHERE type='table'; + } +} {} + +# Add a table with the AUTOINCREMENT feature. Verify that the +# SQLITE_SEQUENCE table gets created. +# +do_test autoinc-1.2 { + execsql { + CREATE TABLE t1(x INTEGER PRIMARY KEY AUTOINCREMENT, y); + SELECT name FROM sqlite_master WHERE type='table'; + } +} {t1 sqlite_sequence} + +# The SQLITE_SEQUENCE table is initially empty +# +do_test autoinc-1.3 { + execsql { + SELECT * FROM sqlite_sequence; + } +} {} +do_test autoinc-1.3.1 { + catchsql { + CREATE INDEX seqidx ON sqlite_sequence(name) + } +} {1 {table sqlite_sequence may not be indexed}} + +# Close and reopen the database. Verify that everything is still there. +# +do_test autoinc-1.4 { + db close + sqlite3 db test.db + execsql { + SELECT * FROM sqlite_sequence; + } +} {} + +# We are not allowed to drop the sqlite_sequence table. +# +do_test autoinc-1.5 { + catchsql {DROP TABLE sqlite_sequence} +} {1 {table sqlite_sequence may not be dropped}} +do_test autoinc-1.6 { + execsql {SELECT name FROM sqlite_master WHERE type='table'} +} {t1 sqlite_sequence} + +# Insert an entries into the t1 table and make sure the largest key +# is always recorded in the sqlite_sequence table. +# +do_test autoinc-2.1 { + execsql { + SELECT * FROM sqlite_sequence + } +} {} +do_test autoinc-2.2 { + execsql { + INSERT INTO t1 VALUES(12,34); + SELECT * FROM sqlite_sequence; + } +} {t1 12} +do_test autoinc-2.3 { + execsql { + INSERT INTO t1 VALUES(1,23); + SELECT * FROM sqlite_sequence; + } +} {t1 12} +do_test autoinc-2.4 { + execsql { + INSERT INTO t1 VALUES(123,456); + SELECT * FROM sqlite_sequence; + } +} {t1 123} +do_test autoinc-2.5 { + execsql { + INSERT INTO t1 VALUES(NULL,567); + SELECT * FROM sqlite_sequence; + } +} {t1 124} +do_test autoinc-2.6 { + execsql { + DELETE FROM t1 WHERE y=567; + SELECT * FROM sqlite_sequence; + } +} {t1 124} +do_test autoinc-2.7 { + execsql { + INSERT INTO t1 VALUES(NULL,567); + SELECT * FROM sqlite_sequence; + } +} {t1 125} +do_test autoinc-2.8 { + execsql { + DELETE FROM t1; + SELECT * FROM sqlite_sequence; + } +} {t1 125} +do_test autoinc-2.9 { + execsql { + INSERT INTO t1 VALUES(12,34); + SELECT * FROM sqlite_sequence; + } +} {t1 125} +do_test autoinc-2.10 { + execsql { + INSERT INTO t1 VALUES(125,456); + SELECT * FROM sqlite_sequence; + } +} {t1 125} +do_test autoinc-2.11 { + execsql { + INSERT INTO t1 VALUES(-1234567,-1); + SELECT * FROM sqlite_sequence; + } +} {t1 125} +do_test autoinc-2.12 { + execsql { + INSERT INTO t1 VALUES(234,5678); + SELECT * FROM sqlite_sequence; + } +} {t1 234} +do_test autoinc-2.13 { + execsql { + DELETE FROM t1; + INSERT INTO t1 VALUES(NULL,1); + SELECT * FROM sqlite_sequence; + } +} {t1 235} +do_test autoinc-2.14 { + execsql { + SELECT * FROM t1; + } +} {235 1} + +# Manually change the autoincrement values in sqlite_sequence. +# +do_test autoinc-2.20 { + execsql { + UPDATE sqlite_sequence SET seq=1234 WHERE name='t1'; + INSERT INTO t1 VALUES(NULL,2); + SELECT * FROM t1; + } +} {235 1 1235 2} +do_test autoinc-2.21 { + execsql { + SELECT * FROM sqlite_sequence; + } +} {t1 1235} +do_test autoinc-2.22 { + execsql { + UPDATE sqlite_sequence SET seq=NULL WHERE name='t1'; + INSERT INTO t1 VALUES(NULL,3); + SELECT * FROM t1; + } +} {235 1 1235 2 1236 3} +do_test autoinc-2.23 { + execsql { + SELECT * FROM sqlite_sequence; + } +} {t1 1236} +do_test autoinc-2.24 { + execsql { + UPDATE sqlite_sequence SET seq='a-string' WHERE name='t1'; + INSERT INTO t1 VALUES(NULL,4); + SELECT * FROM t1; + } +} {235 1 1235 2 1236 3 1237 4} +do_test autoinc-2.25 { + execsql { + SELECT * FROM sqlite_sequence; + } +} {t1 1237} +do_test autoinc-2.26 { + execsql { + DELETE FROM sqlite_sequence WHERE name='t1'; + INSERT INTO t1 VALUES(NULL,5); + SELECT * FROM t1; + } +} {235 1 1235 2 1236 3 1237 4 1238 5} +do_test autoinc-2.27 { + execsql { + SELECT * FROM sqlite_sequence; + } +} {t1 1238} +do_test autoinc-2.28 { + execsql { + UPDATE sqlite_sequence SET seq='-12345678901234567890' + WHERE name='t1'; + INSERT INTO t1 VALUES(NULL,6); + SELECT * FROM t1; + } +} {235 1 1235 2 1236 3 1237 4 1238 5 1239 6} +do_test autoinc-2.29 { + execsql { + SELECT * FROM sqlite_sequence; + } +} {t1 1239} + +# Test multi-row inserts +# +do_test autoinc-2.50 { + execsql { + DELETE FROM t1 WHERE y>=3; + INSERT INTO t1 SELECT NULL, y+2 FROM t1; + SELECT * FROM t1; + } +} {235 1 1235 2 1240 3 1241 4} +do_test autoinc-2.51 { + execsql { + SELECT * FROM sqlite_sequence + } +} {t1 1241} + +ifcapable tempdb { + do_test autoinc-2.52 { + execsql { + CREATE TEMP TABLE t2 AS SELECT y FROM t1; + } + execsql { + INSERT INTO t1 SELECT NULL, y+4 FROM t2; + SELECT * FROM t1; + } + } {235 1 1235 2 1240 3 1241 4 1242 5 1243 6 1244 7 1245 8} + do_test autoinc-2.53 { + execsql { + SELECT * FROM sqlite_sequence + } + } {t1 1245} + do_test autoinc-2.54 { + execsql { + DELETE FROM t1; + INSERT INTO t1 SELECT NULL, y FROM t2; + SELECT * FROM t1; + } + } {1246 1 1247 2 1248 3 1249 4} + do_test autoinc-2.55 { + execsql { + SELECT * FROM sqlite_sequence + } + } {t1 1249} +} + +# Create multiple AUTOINCREMENT tables. Make sure all sequences are +# tracked separately and do not interfere with one another. +# +do_test autoinc-2.70 { + catchsql { + DROP TABLE t2; + } + execsql { + CREATE TABLE t2(d, e INTEGER PRIMARY KEY AUTOINCREMENT, f); + INSERT INTO t2(d) VALUES(1); + SELECT * FROM sqlite_sequence; + } +} [ifcapable tempdb {list t1 1249 t2 1} else {list t1 1241 t2 1}] +do_test autoinc-2.71 { + execsql { + INSERT INTO t2(d) VALUES(2); + SELECT * FROM sqlite_sequence; + } +} [ifcapable tempdb {list t1 1249 t2 2} else {list t1 1241 t2 2}] +do_test autoinc-2.72 { + execsql { + INSERT INTO t1(x) VALUES(10000); + SELECT * FROM sqlite_sequence; + } +} {t1 10000 t2 2} +do_test autoinc-2.73 { + execsql { + CREATE TABLE t3(g INTEGER PRIMARY KEY AUTOINCREMENT, h); + INSERT INTO t3(h) VALUES(1); + SELECT * FROM sqlite_sequence; + } +} {t1 10000 t2 2 t3 1} +do_test autoinc-2.74 { + execsql { + INSERT INTO t2(d,e) VALUES(3,100); + SELECT * FROM sqlite_sequence; + } +} {t1 10000 t2 100 t3 1} + + +# When a table with an AUTOINCREMENT is deleted, the corresponding entry +# in the SQLITE_SEQUENCE table should also be deleted. But the SQLITE_SEQUENCE +# table itself should remain behind. +# +do_test autoinc-3.1 { + execsql {SELECT name FROM sqlite_sequence} +} {t1 t2 t3} +do_test autoinc-3.2 { + execsql { + DROP TABLE t1; + SELECT name FROM sqlite_sequence; + } +} {t2 t3} +do_test autoinc-3.3 { + execsql { + DROP TABLE t3; + SELECT name FROM sqlite_sequence; + } +} {t2} +do_test autoinc-3.4 { + execsql { + DROP TABLE t2; + SELECT name FROM sqlite_sequence; + } +} {} + +# AUTOINCREMENT on TEMP tables. +# +ifcapable tempdb { + do_test autoinc-4.1 { + execsql { + SELECT 1, name FROM sqlite_master WHERE type='table'; + SELECT 2, name FROM temp.sqlite_master WHERE type='table'; + } + } {1 sqlite_sequence} + do_test autoinc-4.2 { + execsql { + CREATE TABLE t1(x INTEGER PRIMARY KEY AUTOINCREMENT, y); + CREATE TEMP TABLE t3(a INTEGER PRIMARY KEY AUTOINCREMENT, b); + SELECT 1, name FROM sqlite_master WHERE type='table'; + SELECT 2, name FROM sqlite_temp_master WHERE type='table'; + } + } {1 sqlite_sequence 1 t1 2 t3 2 sqlite_sequence} + do_test autoinc-4.3 { + execsql { + SELECT 1, * FROM main.sqlite_sequence; + SELECT 2, * FROM temp.sqlite_sequence; + } + } {} + do_test autoinc-4.4 { + execsql { + INSERT INTO t1 VALUES(10,1); + INSERT INTO t3 VALUES(20,2); + INSERT INTO t1 VALUES(NULL,3); + INSERT INTO t3 VALUES(NULL,4); + } + } {} + + ifcapable compound { + do_test autoinc-4.4.1 { + execsql { + SELECT * FROM t1 UNION ALL SELECT * FROM t3; + } + } {10 1 11 3 20 2 21 4} + } ;# ifcapable compound + + do_test autoinc-4.5 { + execsql { + SELECT 1, * FROM main.sqlite_sequence; + SELECT 2, * FROM temp.sqlite_sequence; + } + } {1 t1 11 2 t3 21} + do_test autoinc-4.6 { + execsql { + INSERT INTO t1 SELECT * FROM t3; + SELECT 1, * FROM main.sqlite_sequence; + SELECT 2, * FROM temp.sqlite_sequence; + } + } {1 t1 21 2 t3 21} + do_test autoinc-4.7 { + execsql { + INSERT INTO t3 SELECT x+100, y FROM t1; + SELECT 1, * FROM main.sqlite_sequence; + SELECT 2, * FROM temp.sqlite_sequence; + } + } {1 t1 21 2 t3 121} + do_test autoinc-4.8 { + execsql { + DROP TABLE t3; + SELECT 1, * FROM main.sqlite_sequence; + SELECT 2, * FROM temp.sqlite_sequence; + } + } {1 t1 21} + do_test autoinc-4.9 { + execsql { + CREATE TEMP TABLE t2(p INTEGER PRIMARY KEY AUTOINCREMENT, q); + INSERT INTO t2 SELECT * FROM t1; + DROP TABLE t1; + SELECT 1, * FROM main.sqlite_sequence; + SELECT 2, * FROM temp.sqlite_sequence; + } + } {2 t2 21} + do_test autoinc-4.10 { + execsql { + DROP TABLE t2; + SELECT 1, * FROM main.sqlite_sequence; + SELECT 2, * FROM temp.sqlite_sequence; + } + } {} +} + +# Make sure AUTOINCREMENT works on ATTACH-ed tables. +# +ifcapable tempdb&&attach { + do_test autoinc-5.1 { + forcedelete test2.db + forcedelete test2.db-journal + sqlite3 db2 test2.db + execsql { + CREATE TABLE t4(m INTEGER PRIMARY KEY AUTOINCREMENT, n); + CREATE TABLE t5(o, p INTEGER PRIMARY KEY AUTOINCREMENT); + } db2; + execsql { + ATTACH 'test2.db' as aux; + SELECT 1, * FROM main.sqlite_sequence; + SELECT 2, * FROM temp.sqlite_sequence; + SELECT 3, * FROM aux.sqlite_sequence; + } + } {} + do_test autoinc-5.2 { + execsql { + INSERT INTO t4 VALUES(NULL,1); + SELECT 1, * FROM main.sqlite_sequence; + SELECT 2, * FROM temp.sqlite_sequence; + SELECT 3, * FROM aux.sqlite_sequence; + } + } {3 t4 1} + do_test autoinc-5.3 { + execsql { + INSERT INTO t5 VALUES(100,200); + SELECT * FROM sqlite_sequence + } db2 + } {t4 1 t5 200} + do_test autoinc-5.4 { + execsql { + SELECT 1, * FROM main.sqlite_sequence; + SELECT 2, * FROM temp.sqlite_sequence; + SELECT 3, * FROM aux.sqlite_sequence; + } + } {3 t4 1 3 t5 200} +} + +# Requirement REQ00310: Make sure an insert fails if the sequence is +# already at its maximum value. +# +ifcapable {rowid32} { + do_test autoinc-6.1 { + execsql { + CREATE TABLE t6(v INTEGER PRIMARY KEY AUTOINCREMENT, w); + INSERT INTO t6 VALUES(2147483647,1); + SELECT seq FROM main.sqlite_sequence WHERE name='t6'; + } + } 2147483647 +} +ifcapable {!rowid32} { + do_test autoinc-6.1 { + execsql { + CREATE TABLE t6(v INTEGER PRIMARY KEY AUTOINCREMENT, w); + INSERT INTO t6 VALUES(9223372036854775807,1); + SELECT seq FROM main.sqlite_sequence WHERE name='t6'; + } + } 9223372036854775807 +} +do_test autoinc-6.2 { + catchsql { + INSERT INTO t6 VALUES(NULL,1); + } +} {1 {database or disk is full}} + +# Allow the AUTOINCREMENT keyword inside the parentheses +# on a separate PRIMARY KEY designation. +# +do_test autoinc-7.1 { + execsql { + CREATE TABLE t7(x INTEGER, y REAL, PRIMARY KEY(x AUTOINCREMENT)); + INSERT INTO t7(y) VALUES(123); + INSERT INTO t7(y) VALUES(234); + DELETE FROM t7; + INSERT INTO t7(y) VALUES(345); + SELECT * FROM t7; + } +} {3 345.0} + +# Test that if the AUTOINCREMENT is applied to a non integer primary key +# the error message is sensible. +do_test autoinc-7.2 { + catchsql { + CREATE TABLE t8(x TEXT PRIMARY KEY AUTOINCREMENT); + } +} {1 {AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY}} + + +# Ticket #1283. Make sure that preparing but never running a statement +# that creates the sqlite_sequence table does not mess up the database. +# +do_test autoinc-8.1 { + catch {db2 close} + catch {db close} + forcedelete test.db + sqlite3 db test.db + set DB [sqlite3_connection_pointer db] + set STMT [sqlite3_prepare $DB { + CREATE TABLE t1( + x INTEGER PRIMARY KEY AUTOINCREMENT + ) + } -1 TAIL] + sqlite3_finalize $STMT + set STMT [sqlite3_prepare $DB { + CREATE TABLE t1( + x INTEGER PRIMARY KEY AUTOINCREMENT + ) + } -1 TAIL] + sqlite3_step $STMT + sqlite3_finalize $STMT + execsql { + INSERT INTO t1 VALUES(NULL); + SELECT * FROM t1; + } +} {1} + +# Ticket #3148 +# Make sure the sqlite_sequence table is not damaged when doing +# an empty insert - an INSERT INTO ... SELECT ... where the SELECT +# clause returns an empty set. +# +do_test autoinc-9.1 { + db eval { + CREATE TABLE t2(x INTEGER PRIMARY KEY AUTOINCREMENT, y); + INSERT INTO t2 VALUES(NULL, 1); + CREATE TABLE t3(a INTEGER PRIMARY KEY AUTOINCREMENT, b); + INSERT INTO t3 SELECT * FROM t2 WHERE y>1; + + SELECT * FROM sqlite_sequence WHERE name='t3'; + } +} {t3 0} + +ifcapable trigger { + catchsql { pragma recursive_triggers = off } + + # Ticket #3928. Make sure that triggers to not make extra slots in + # the SQLITE_SEQUENCE table. + # + do_test autoinc-3928.1 { + db eval { + CREATE TABLE t3928(a INTEGER PRIMARY KEY AUTOINCREMENT, b); + CREATE TRIGGER t3928r1 BEFORE INSERT ON t3928 BEGIN + INSERT INTO t3928(b) VALUES('before1'); + INSERT INTO t3928(b) VALUES('before2'); + END; + CREATE TRIGGER t3928r2 AFTER INSERT ON t3928 BEGIN + INSERT INTO t3928(b) VALUES('after1'); + INSERT INTO t3928(b) VALUES('after2'); + END; + INSERT INTO t3928(b) VALUES('test'); + SELECT * FROM t3928 ORDER BY a; + } + } {1 before1 2 after1 3 after2 4 before2 5 after1 6 after2 7 test 8 before1 9 before2 10 after1 11 before1 12 before2 13 after2} + do_test autoinc-3928.2 { + db eval { + SELECT * FROM sqlite_sequence WHERE name='t3928' + } + } {t3928 13} + + do_test autoinc-3928.3 { + db eval { + DROP TRIGGER t3928r1; + DROP TRIGGER t3928r2; + CREATE TRIGGER t3928r3 BEFORE UPDATE ON t3928 + WHEN typeof(new.b)=='integer' BEGIN + INSERT INTO t3928(b) VALUES('before-int-' || new.b); + END; + CREATE TRIGGER t3928r4 AFTER UPDATE ON t3928 + WHEN typeof(new.b)=='integer' BEGIN + INSERT INTO t3928(b) VALUES('after-int-' || new.b); + END; + DELETE FROM t3928 WHERE a!=1; + UPDATE t3928 SET b=456 WHERE a=1; + SELECT * FROM t3928 ORDER BY a; + } + } {1 456 14 before-int-456 15 after-int-456} + do_test autoinc-3928.4 { + db eval { + SELECT * FROM sqlite_sequence WHERE name='t3928' + } + } {t3928 15} + + do_test autoinc-3928.5 { + db eval { + CREATE TABLE t3928b(x); + INSERT INTO t3928b VALUES(100); + INSERT INTO t3928b VALUES(200); + INSERT INTO t3928b VALUES(300); + DELETE FROM t3928; + CREATE TABLE t3928c(y INTEGER PRIMARY KEY AUTOINCREMENT, z); + CREATE TRIGGER t3928br1 BEFORE DELETE ON t3928b BEGIN + INSERT INTO t3928(b) VALUES('before-del-'||old.x); + INSERT INTO t3928c(z) VALUES('before-del-'||old.x); + END; + CREATE TRIGGER t3928br2 AFTER DELETE ON t3928b BEGIN + INSERT INTO t3928(b) VALUES('after-del-'||old.x); + INSERT INTO t3928c(z) VALUES('after-del-'||old.x); + END; + DELETE FROM t3928b; + SELECT * FROM t3928 ORDER BY a; + } + } {16 before-del-100 17 after-del-100 18 before-del-200 19 after-del-200 20 before-del-300 21 after-del-300} + do_test autoinc-3928.6 { + db eval { + SELECT * FROM t3928c ORDER BY y; + } + } {1 before-del-100 2 after-del-100 3 before-del-200 4 after-del-200 5 before-del-300 6 after-del-300} + do_test autoinc-3928.7 { + db eval { + SELECT * FROM sqlite_sequence WHERE name LIKE 't3928%' ORDER BY name; + } + } {t3928 21 t3928c 6} + + # Ticket [a696379c1f0886615541a48b35bd8181a80e88f8] + do_test autoinc-a69637.1 { + db eval { + CREATE TABLE ta69637_1(x INTEGER PRIMARY KEY AUTOINCREMENT, y); + CREATE TABLE ta69637_2(z); + CREATE TRIGGER ra69637_1 AFTER INSERT ON ta69637_2 BEGIN + INSERT INTO ta69637_1(y) VALUES(new.z+1); + END; + INSERT INTO ta69637_2 VALUES(123); + SELECT * FROM ta69637_1; + } + } {1 124} + do_test autoinc-a69637.2 { + db eval { + CREATE VIEW va69637_2 AS SELECT * FROM ta69637_2; + CREATE TRIGGER ra69637_2 INSTEAD OF INSERT ON va69637_2 BEGIN + INSERT INTO ta69637_1(y) VALUES(new.z+10000); + END; + INSERT INTO va69637_2 VALUES(123); + SELECT * FROM ta69637_1; + } + } {1 124 2 10123} +} + +# 2016-10-03 ticket https://www.sqlite.org/src/tktview/7b3328086a5c1 +# Make sure autoincrement plays nicely with the xfer optimization +# +do_execsql_test autoinc-10.1 { + DELETE FROM sqlite_sequence; + CREATE TABLE t10a(a INTEGER PRIMARY KEY AUTOINCREMENT, b UNIQUE); + INSERT INTO t10a VALUES(888,9999); + CREATE TABLE t10b(x INTEGER PRIMARY KEY AUTOINCREMENT, y UNIQUE); + INSERT INTO t10b SELECT * FROM t10a; + SELECT * FROM sqlite_sequence; +} {t10a 888 t10b 888} + +# 2018-04-21 autoincrement does not cause problems for upsert +# +do_execsql_test autoinc-11.1 { + CREATE TABLE t11(a INTEGER PRIMARY KEY AUTOINCREMENT,b UNIQUE); + INSERT INTO t11(a,b) VALUES(2,3),(5,6),(4,3),(1,2) + ON CONFLICT(b) DO UPDATE SET a=a+1000; + SELECT seq FROM sqlite_sequence WHERE name='t11'; +} {5} + +# 2018-05-23 ticket d8dc2b3a58cd5dc2918a1d4acbba4676a23ada4c +# Does not crash if the sqlite_sequence table schema is missing +# or corrupt. +# +do_test autoinc-12.1 { + db close + forcedelete test.db + sqlite3 db test.db + sqlite3_db_config db DEFENSIVE 0 + db eval { + CREATE TABLE fake_sequence(name TEXT PRIMARY KEY,seq) WITHOUT ROWID; + PRAGMA writable_schema=on; + UPDATE sqlite_master SET + sql=replace(sql,'fake_','sqlite_'), + name='sqlite_sequence', + tbl_name='sqlite_sequence' + WHERE name='fake_sequence'; + } + db close + sqlite3 db test.db + set res [catch {db eval { + CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT); + INSERT INTO t1(b) VALUES('one'); + }} msg] + lappend res $msg +} {1 {database disk image is malformed}} +do_test autoinc-12.2 { + db close + forcedelete test.db + sqlite3 db test.db + sqlite3_db_config db DEFENSIVE 0 + db eval { + CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT); + INSERT INTO t1(b) VALUES('one'); + PRAGMA writable_schema=on; + UPDATE sqlite_master SET + sql=replace(sql,'sqlite_','x_'), + name='x_sequence', + tbl_name='x_sequence' + WHERE name='sqlite_sequence'; + } + db close + sqlite3 db test.db + set res [catch {db eval { + INSERT INTO t1(b) VALUES('two'); + }} msg] + lappend res $msg +} {1 {database disk image is malformed}} +ifcapable vtab { + set err "database disk image is malformed" +} else { + set err {malformed database schema (sqlite_sequence) - near "VIRTUAL": syntax error} +} +do_test autoinc-12.3 { + db close + forcedelete test.db + sqlite3 db test.db + sqlite3_db_config db DEFENSIVE 0 + db eval { + CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT); + INSERT INTO t1(b) VALUES('one'); + PRAGMA writable_schema=on; + UPDATE sqlite_master SET + sql='CREATE VIRTUAL TABLE sqlite_sequence USING sqlite_dbpage' + WHERE name='sqlite_sequence'; + } + db close + sqlite3 db test.db + set res [catch {db eval { + INSERT INTO t1(b) VALUES('two'); + }} msg] + lappend res $msg +} [list 1 $err] +do_test autoinc-12.4 { + db close + forcedelete test.db + sqlite3 db test.db + db eval { + CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT); + INSERT INTO t1(b) VALUES('one'); + CREATE TABLE fake(name TEXT PRIMARY KEY,seq) WITHOUT ROWID; + } + set root1 [db one {SELECT rootpage FROM sqlite_master + WHERE name='sqlite_sequence'}] + set root2 [db one {SELECT rootpage FROM sqlite_master + WHERE name='fake'}] + sqlite3_db_config db DEFENSIVE 0 + db eval { + PRAGMA writable_schema=on; + UPDATE sqlite_master SET rootpage=$root2 + WHERE name='sqlite_sequence'; + UPDATE sqlite_master SET rootpage=$root1 + WHERE name='fake'; + } + db close + sqlite3 db test.db + set res [catch {db eval { + INSERT INTO t1(b) VALUES('two'); + }} msg] + lappend res $msg +} {1 {database disk image is malformed}} +breakpoint +do_test autoinc-12.5 { + db close + forcedelete test.db + sqlite3 db test.db + sqlite3_db_config db DEFENSIVE 0 + db eval { + CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT); + INSERT INTO t1(b) VALUES('one'); + PRAGMA writable_schema=on; + UPDATE sqlite_master SET + sql='CREATE TABLE sqlite_sequence(x)' + WHERE name='sqlite_sequence'; + } + db close + sqlite3 db test.db + set res [catch {db eval { + INSERT INTO t1(b) VALUES('two'); + }} msg] + lappend res $msg +} {1 {database disk image is malformed}} +do_test autoinc-12.6 { + db close + forcedelete test.db + sqlite3 db test.db + sqlite3_db_config db DEFENSIVE 0 + db eval { + CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT); + INSERT INTO t1(b) VALUES('one'); + PRAGMA writable_schema=on; + UPDATE sqlite_master SET + sql='CREATE TABLE sqlite_sequence(x,y INTEGER PRIMARY KEY)' + WHERE name='sqlite_sequence'; + } + db close + sqlite3 db test.db + set res [catch {db eval { + INSERT INTO t1(b) VALUES('two'),('three'),('four'); + INSERT INTO t1(b) VALUES('five'); + PRAGMA integrity_check; + }} msg] + lappend res $msg +} {0 ok} +do_test autoinc-12.7 { + db close + forcedelete test.db + sqlite3 db test.db + sqlite3_db_config db DEFENSIVE 0 + db eval { + CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT); + INSERT INTO t1(b) VALUES('one'); + PRAGMA writable_schema=on; + UPDATE sqlite_master SET + sql='CREATE TABLE sqlite_sequence(y INTEGER PRIMARY KEY,x)' + WHERE name='sqlite_sequence'; + } + db close + sqlite3 db test.db + set res [catch {db eval { + INSERT INTO t1(b) VALUES('two'),('three'),('four'); + INSERT INTO t1(b) VALUES('five'); + PRAGMA integrity_check; + }} msg] + lappend res $msg +} {0 ok} + +#-------------------------------------------------------------------------- +reset_db +do_execsql_test 13.0 { + CREATE TABLE t1(i INTEGER PRIMARY KEY AUTOINCREMENT, j); + CREATE TABLE t2(i INTEGER PRIMARY KEY AUTOINCREMENT, j); + CREATE TABLE t3(i INTEGER PRIMARY KEY AUTOINCREMENT, j); + + INSERT INTO t1 VALUES(NULL, 1); + INSERT INTO t2 VALUES(NULL, 2); + INSERT INTO t3 VALUES(NULL, 3); + + SELECT name FROM sqlite_sequence; +} {t1 t2 t3} + +do_execsql_test 13.1 { + UPDATE sqlite_sequence SET name=NULL WHERE name='t2'; + INSERT INTO t3 VALUES(NULL, 4); + DELETE FROM t3; + INSERT INTO t3 VALUES(NULL, 5); + SELECT * FROM t3; +} {3 5} + + +finish_test diff --git a/test/autoindex1.test b/test/autoindex1.test new file mode 100644 index 0000000..08bd9f7 --- /dev/null +++ b/test/autoindex1.test @@ -0,0 +1,565 @@ +# 2010 April 07 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing automatic index creation logic. +# +# EVIDENCE-OF: R-34271-33106 PRAGMA automatic_index; PRAGMA +# automatic_index = boolean; Query, set, or clear the automatic indexing +# capability. + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If the library is not compiled with automatic index support then +# skip all tests in this file. +# +ifcapable {!autoindex} { + finish_test + return +} + +# Setup for logging +db close +sqlite3_shutdown +test_sqlite3_log [list lappend ::log] +set ::log [list] +sqlite3 db test.db + + +# With automatic index turned off, we do a full scan of the T2 table +do_test autoindex1-100 { + db eval { + CREATE TABLE t1(a,b); + INSERT INTO t1 VALUES(1,11); + INSERT INTO t1 VALUES(2,22); + INSERT INTO t1 SELECT a+2, b+22 FROM t1; + INSERT INTO t1 SELECT a+4, b+44 FROM t1; + CREATE TABLE t2(c,d); + INSERT INTO t2 SELECT a, 900+b FROM t1; + } + db eval { + PRAGMA automatic_index=OFF; + SELECT b, d FROM t1 JOIN t2 ON a=c ORDER BY b; + } +} {11 911 22 922 33 933 44 944 55 955 66 966 77 977 88 988} +do_test autoindex1-101 { + db status step +} {63} +do_test autoindex1-102 { + db status autoindex +} {0} + +# With autoindex turned on, we build an index once and then use that index +# to find T2 values. +do_test autoindex1-110 { + db eval { + PRAGMA automatic_index=ON; + SELECT b, d FROM t1 JOIN t2 ON a=c ORDER BY b; + } +} {11 911 22 922 33 933 44 944 55 955 66 966 77 977 88 988} +do_test autoindex1-111 { + db status step +} {7} +do_test autoindex1-112 { + db status autoindex +} {7} +do_test autoindex1-113 { + set ::log +} {SQLITE_WARNING_AUTOINDEX {automatic index on t2(c)}} + +db close +sqlite3_shutdown +test_sqlite3_log +sqlite3_initialize +sqlite3 db test.db + +# The same test as above, but this time the T2 query is a subquery rather +# than a join. +do_test autoindex1-200 { + db eval { + PRAGMA automatic_index=OFF; + SELECT b, (SELECT d FROM t2 WHERE c=a) FROM t1; + } +} {11 911 22 922 33 933 44 944 55 955 66 966 77 977 88 988} +do_test autoindex1-201 { + db status step +} {35} +do_test autoindex1-202 { + db status autoindex +} {0} +do_test autoindex1-210 { + db eval { + PRAGMA automatic_index=ON; + ANALYZE; + UPDATE sqlite_stat1 SET stat='10000' WHERE tbl='t1'; + -- Table t2 actually contains 8 rows. + UPDATE sqlite_stat1 SET stat='16' WHERE tbl='t2'; + ANALYZE sqlite_master; + SELECT b, (SELECT d FROM t2 WHERE c=a) FROM t1; + } +} {11 911 22 922 33 933 44 944 55 955 66 966 77 977 88 988} +do_test autoindex1-211 { + db status step +} {7} +do_test autoindex1-212 { + db status autoindex +} {7} + + +# Modify the second table of the join while the join is in progress +# +do_execsql_test autoindex1-299 { + UPDATE sqlite_stat1 SET stat='10000' WHERE tbl='t2'; + ANALYZE sqlite_master; + EXPLAIN QUERY PLAN + SELECT b, d FROM t1 CROSS JOIN t2 ON (c=a); +} {/AUTOMATIC COVERING INDEX/} +do_test autoindex1-300 { + set r {} + db eval {SELECT b, d FROM t1 CROSS JOIN t2 ON (c=a)} { + lappend r $b $d + db eval {UPDATE t2 SET d=d+1} + } + set r +} {11 911 22 922 33 933 44 944 55 955 66 966 77 977 88 988} +do_test autoindex1-310 { + db eval {SELECT d FROM t2 ORDER BY d} +} {919 930 941 952 963 974 985 996} + +# The next test does a 10-way join on unindexed tables. Without +# automatic indices, the join will take a long time to complete. +# With automatic indices, it should only take about a second. +# +do_test autoindex1-400 { + db eval { + CREATE TABLE t4(a, b); + INSERT INTO t4 VALUES(1,2); + INSERT INTO t4 VALUES(2,3); + } + for {set n 2} {$n<4096} {set n [expr {$n+$n}]} { + db eval {INSERT INTO t4 SELECT a+$n, b+$n FROM t4} + } + db eval { + SELECT count(*) FROM t4; + } +} {4096} +do_test autoindex1-401 { + db eval { + SELECT count(*) + FROM t4 AS x1 + JOIN t4 AS x2 ON x2.a=x1.b + JOIN t4 AS x3 ON x3.a=x2.b + JOIN t4 AS x4 ON x4.a=x3.b + JOIN t4 AS x5 ON x5.a=x4.b + JOIN t4 AS x6 ON x6.a=x5.b + JOIN t4 AS x7 ON x7.a=x6.b + JOIN t4 AS x8 ON x8.a=x7.b + JOIN t4 AS x9 ON x9.a=x8.b + JOIN t4 AS x10 ON x10.a=x9.b; + } +} {4087} + +# Ticket [8011086c85c6c404014c947fcf3eb9f42b184a0d] from 2010-07-08 +# Make sure automatic indices are not created for the RHS of an IN expression +# that is not a correlated subquery. +# +do_execsql_test autoindex1-500 { + CREATE TABLE t501(a INTEGER PRIMARY KEY, b); + CREATE TABLE t502(x INTEGER PRIMARY KEY, y); + INSERT INTO sqlite_stat1(tbl,idx,stat) VALUES('t501',null,'1000000'); + INSERT INTO sqlite_stat1(tbl,idx,stat) VALUES('t502',null,'1000'); + ANALYZE sqlite_master; +} +do_eqp_test autoindex1-500.1 { + SELECT b FROM t501 + WHERE t501.a IN (SELECT x FROM t502 WHERE y=?); +} { + QUERY PLAN + |--SEARCH t501 USING INTEGER PRIMARY KEY (rowid=?) + `--LIST SUBQUERY xxxxxx + `--SCAN t502 +} +do_eqp_test autoindex1-501 { + SELECT b FROM t501 + WHERE t501.a IN (SELECT x FROM t502 WHERE y=t501.b); +} { + QUERY PLAN + |--SCAN t501 + `--CORRELATED LIST SUBQUERY xxxxxx + |--BLOOM FILTER ON t502 (y=?) + `--SEARCH t502 USING AUTOMATIC COVERING INDEX (y=?) +} +do_eqp_test autoindex1-502 { + SELECT b FROM t501 + WHERE t501.a=123 + AND t501.a IN (SELECT x FROM t502 WHERE y=t501.b); +} { + QUERY PLAN + |--SEARCH t501 USING INTEGER PRIMARY KEY (rowid=?) + `--CORRELATED LIST SUBQUERY xxxxxx + `--SCAN t502 +} + +# The following code checks a performance regression reported on the +# mailing list on 2010-10-19. The problem is that the nRowEst field +# of ephermeral tables was not being initialized correctly and so no +# automatic index was being created for the emphemeral table when it was +# used as part of a join. +# +do_execsql_test autoindex1-600 { + CREATE TABLE flock_owner( + owner_rec_id INTEGER CONSTRAINT flock_owner_key PRIMARY KEY, + flock_no VARCHAR(6) NOT NULL REFERENCES flock (flock_no), + owner_person_id INTEGER NOT NULL REFERENCES person (person_id), + owner_change_date TEXT, last_changed TEXT NOT NULL, + CONSTRAINT fo_owner_date UNIQUE (flock_no, owner_change_date) + ); + CREATE TABLE sheep ( + Sheep_No char(7) NOT NULL, + Date_of_Birth char(8), + Sort_DoB text, + Flock_Book_Vol char(2), + Breeder_No char(6), + Breeder_Person integer, + Originating_Flock char(6), + Registering_Flock char(6), + Tag_Prefix char(9), + Tag_No char(15), + Sort_Tag_No integer, + Breeders_Temp_Tag char(15), + Sex char(1), + Sheep_Name char(32), + Sire_No char(7), + Dam_No char(7), + Register_Code char(1), + Colour char(48), + Colour_Code char(2), + Pattern_Code char(8), + Horns char(1), + Litter_Size char(1), + Coeff_of_Inbreeding real, + Date_of_Registration text, + Date_Last_Changed text, + UNIQUE(Sheep_No)); + CREATE INDEX fo_flock_no_index + ON flock_owner (flock_no); + CREATE INDEX fo_owner_change_date_index + ON flock_owner (owner_change_date); + CREATE INDEX fo_owner_person_id_index + ON flock_owner (owner_person_id); + CREATE INDEX sheep_org_flock_index + ON sheep (originating_flock); + CREATE INDEX sheep_reg_flock_index + ON sheep (registering_flock); +} +do_eqp_test autoindex1-600a { + SELECT x.sheep_no, x.registering_flock, x.date_of_registration + FROM sheep x LEFT JOIN + (SELECT s.sheep_no, prev.flock_no, prev.owner_person_id, + s.date_of_registration, prev.owner_change_date + FROM sheep s JOIN flock_owner prev ON s.registering_flock = + prev.flock_no + AND (prev.owner_change_date <= s.date_of_registration || ' 00:00:00') + WHERE NOT EXISTS + (SELECT 'x' FROM flock_owner later + WHERE prev.flock_no = later.flock_no + AND later.owner_change_date > prev.owner_change_date + AND later.owner_change_date <= s.date_of_registration||' 00:00:00') + ) y ON x.sheep_no = y.sheep_no + WHERE y.sheep_no IS NULL + ORDER BY x.registering_flock; +} { + QUERY PLAN + |--MATERIALIZE y + | |--SCAN s + | |--SEARCH prev USING INDEX sqlite_autoindex_flock_owner_1 (flock_no=? AND owner_change_date? AND owner_change_date 1393520400 + AND param3<>9001 + AND t3.flg7 = 1 + AND t1.did = t2.did + AND t2.uid = t3.uid + ORDER BY t1.ptime desc LIMIT 500; +} {~/AUTO/} +# +# ^^^--- Before being fixed, the above was using an automatic covering +# on t3 and reordering the tables so that t3 was in the outer loop and +# implementing the ORDER BY clause using a B-Tree. +# +# This test is sanitized data received from a user. The original unsanitized +# data and STAT4 data is found in the th3private test repository. See one of +# the th3private check-ins on 2016-02-25. The test is much more accurate when +# STAT4 data is used. + +finish_test diff --git a/test/autoindex3.test b/test/autoindex3.test new file mode 100644 index 0000000..3da7a70 --- /dev/null +++ b/test/autoindex3.test @@ -0,0 +1,94 @@ +# 2014-06-17 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# +# This file implements regression tests for SQLite library. The +# focus of this script is testing automatic index creation logic, +# and specifically that an automatic index will not be created that +# shadows a declared index. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix autoindex3 + +# The t1b and t2d indexes are not very selective. It used to be that +# the autoindex mechanism would create automatic indexes on t1(b) or +# t2(d), make assumptions that they were reasonably selective, and use +# them instead of t1b or t2d. But that would be cheating, because the +# automatic index cannot be any more selective than the real index. +# +# This test verifies that the cheat is no longer allowed. +# +do_execsql_test autoindex3-100 { + CREATE TABLE t1(a,b,x); + CREATE TABLE t2(c,d,y); + CREATE INDEX t1b ON t1(b); + CREATE INDEX t2d ON t2(d); + ANALYZE sqlite_master; + INSERT INTO sqlite_stat1 VALUES('t1','t1b','10000 500'); + INSERT INTO sqlite_stat1 VALUES('t2','t2d','10000 500'); + ANALYZE sqlite_master; + EXPLAIN QUERY PLAN SELECT * FROM t1, t2 WHERE d=b; +} {~/AUTO/} + +# Automatic indexes can still be used if existing indexes do not +# participate in == constraints. +# +do_execsql_test autoindex3-110 { + EXPLAIN QUERY PLAN SELECT * FROM t1, t2 WHERE d>b AND x=y; +} {/AUTO/} +do_execsql_test autoindex3-120 { + EXPLAIN QUERY PLAN SELECT * FROM t1, t2 WHERE d?) +# 0|1|0|SEARCH u USING COVERING INDEX uab (ANY(a) AND b=?) +# +# on the basis that the real index "uab" must be better than the automatic +# index. This is not right - a skip-scan is not necessarily better than an +# automatic index scan. +# +do_eqp_test 220 { + select count(*) from u, v where u.b = v.b and v.e > 34; +} { + QUERY PLAN + |--SEARCH v USING INDEX ve (e>?) + |--BLOOM FILTER ON u (b=?) + `--SEARCH u USING AUTOMATIC COVERING INDEX (b=?) +} + + +finish_test diff --git a/test/autoindex4.test b/test/autoindex4.test new file mode 100644 index 0000000..6af99f5 --- /dev/null +++ b/test/autoindex4.test @@ -0,0 +1,223 @@ +# 2014-10-24 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# +# This file implements regression tests for SQLite library. The +# focus of this script is testing automatic index creation logic, +# and specifically creation of automatic partial indexes. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +do_execsql_test autoindex4-1.0 { + CREATE TABLE t1(a,b); + INSERT INTO t1 VALUES(123,'abc'),(234,'def'),(234,'ghi'),(345,'jkl'); + CREATE TABLE t2(x,y); + INSERT INTO t2 VALUES(987,'zyx'),(654,'wvu'),(987,'rqp'); + + SELECT *, '|' FROM t1, t2 WHERE a=234 AND x=987 ORDER BY +b; +} {234 def 987 rqp | 234 def 987 zyx | 234 ghi 987 rqp | 234 ghi 987 zyx |} +do_execsql_test autoindex4-1.1 { + SELECT *, '|' FROM t1, t2 WHERE a=234 AND x=555; +} {} + +do_execsql_test autoindex4-1.2 { + SELECT *, '|' FROM t1 LEFT JOIN t2 ON a=234 AND x=555; +} {123 abc {} {} | 234 def {} {} | 234 ghi {} {} | 345 jkl {} {} |} +do_execsql_test autoindex4-1.2-rj { + SELECT t1.*, t2.*, '|' FROM t2 RIGHT JOIN t1 ON a=234 AND x=555; +} {123 abc {} {} | 234 def {} {} | 234 ghi {} {} | 345 jkl {} {} |} +do_execsql_test autoindex4-1.3 { + SELECT *, '|' FROM t1 LEFT JOIN t2 ON x=555 WHERE a=234; +} {234 def {} {} | 234 ghi {} {} |} +do_execsql_test autoindex4-1.3-rj { + SELECT t1.*, t2.*, '|' FROM t2 RIGHT JOIN t1 ON x=555 WHERE a=234; +} {234 def {} {} | 234 ghi {} {} |} +do_execsql_test autoindex4-1.4 { + SELECT *, '|' FROM t1 LEFT JOIN t2 WHERE a=234 AND x=555; +} {} +do_execsql_test autoindex4-1.4-rj { + SELECT t1.*, t2.*, '|' FROM t2 RIGHT JOIN t1 WHERE a=234 AND x=555; +} {} + + +do_execsql_test autoindex4-2.0 { + CREATE TABLE t3(e,f); + INSERT INTO t3 VALUES(123,654),(555,444),(234,987); + + SELECT (SELECT count(*) FROM t1, t2 WHERE a=e AND x=f), e, f, '|' + FROM t3 + ORDER BY rowid; +} {1 123 654 | 0 555 444 | 4 234 987 |} + +# Ticket [2326c258d02ead33d] +# Two joins, one with and the other without an ORDER BY clause. +# The one without ORDER BY correctly returns two rows of result. +# The one with ORDER BY returns no rows. +# +do_execsql_test autoindex4-3.0 { + CREATE TABLE A(Name text); + CREATE TABLE Items(ItemName text , Name text); + INSERT INTO Items VALUES('Item1','Parent'); + INSERT INTO Items VALUES('Item2','Parent'); + CREATE TABLE B(Name text); + + SELECT Items.ItemName + FROM Items + LEFT JOIN A ON (A.Name = Items.ItemName and Items.ItemName = 'dummy') + LEFT JOIN B ON (B.Name = Items.ItemName) + WHERE Items.Name = 'Parent' + ORDER BY Items.ItemName; +} {Item1 Item2} +do_execsql_test autoindex4-3.1 { + SELECT Items.ItemName + FROM A + RIGHT JOIN Items ON (A.Name = Items.ItemName and Items.ItemName = 'dummy') + LEFT JOIN B ON (B.Name = Items.ItemName) + WHERE Items.Name = 'Parent' + ORDER BY Items.ItemName; +} {Item1 Item2} +do_execsql_test autoindex4-3.10 { + CREATE INDEX Items_x1 ON Items(ItemName,Name) WHERE ItemName = 'dummy'; + + SELECT Items.ItemName + FROM Items + LEFT JOIN A ON (A.Name = Items.ItemName and Items.ItemName = 'dummy') + LEFT JOIN B ON (B.Name = Items.ItemName) + WHERE Items.Name = 'Parent' + ORDER BY Items.ItemName; +} {Item1 Item2} +do_execsql_test autoindex4-3.11 { + SELECT Items.ItemName + FROM A + RIGHT JOIN Items ON (A.Name = Items.ItemName and Items.ItemName = 'dummy') + LEFT JOIN B ON (B.Name = Items.ItemName) + WHERE Items.Name = 'Parent' + ORDER BY Items.ItemName; +} {Item1 Item2} + +# 2021-11-30 - Enhancement to help the automatic index mechanism to +# create a partial index more often. +# +unset -nocomplain id data1 data2 jointype onclause whereclause answer +foreach {id data1 data2 jointype onclause whereclause answer} { + 1 + VALUES(1,2),(3,4) + VALUES(1,2),(3,4) + {LEFT JOIN} + a=x + {y=4 OR y IS NULL} + {3 4 3 4} + + 2 + VALUES(1,2),(3,4) + VALUES(1,2),(3,4) + {LEFT JOIN} + {a=x AND y=4} + {coalesce(y,4)==4} + {1 2 {} {} 3 4 3 4} + + 3 + VALUES(1,2),(3,4) + VALUES(1,2),(3,4) + {JOIN} + {a=x} + {y=4 OR y IS NULL} + {3 4 3 4} + + 4 + VALUES(1,2),(3,4) + VALUES(1,2),(3,4) + {JOIN} + {a=x AND y=4} + {coalesce(y,4)==4} + {3 4 3 4} + + 5.1 + VALUES(1,2),(3,4),(NULL,4) + VALUES(1,2),(3,4) + {LEFT JOIN} + a=x + {y=4 OR y IS NULL} + {3 4 3 4 {} 4 {} {}} + + 5.2 + VALUES(1,2),(3,4),(NULL,4) + VALUES(1,2),(3,4) + {LEFT JOIN} + a=x + {y NOT IN ()} + {1 2 1 2 3 4 3 4 {} 4 {} {}} + + 5.3 + VALUES(1,2),(3,4),(NULL,4) + VALUES(1,2),(3,4) + {LEFT JOIN} + a=x + {y NOT IN (SELECT 1 WHERE false)} + {1 2 1 2 3 4 3 4 {} 4 {} {}} + + 6 + VALUES(1,2),(3,4) + VALUES(1,2),(3,4),(NULL,4) + {LEFT JOIN} + {a=x AND y=4} + {coalesce(y,4)==4} + {1 2 {} {} 3 4 3 4} + + 7 + VALUES(1,2),(3,4),(NULL,4) + VALUES(1,2),(3,4),(NULL,4) + {JOIN} + {a=x} + {y=4 OR y IS NULL} + {3 4 3 4} + + 8 + VALUES(1,2),(3,4) + VALUES(1,2),(3,4) + {JOIN} + {a=x AND y=4} + {coalesce(y,4)==4} + {3 4 3 4} +} { + do_test autoindex4-4.$id.0 { + db eval { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(a INT, b INT); + DROP TABLE IF EXISTS t2; + CREATE TABLE t2(x INT, y INT); + } + db eval "INSERT INTO t1(a,b) $data1;" + db eval "INSERT INTO t2(x,y) $data2;" + } {} + set sql "SELECT * FROM t1 $jointype t2 ON $onclause WHERE $whereclause" + # puts "sql = $sql" + do_test autoindex4-4.$id.1 { + db eval {PRAGMA automatic_index=ON;} + db eval $sql + } $answer + do_test autoindex4-4.$id.2 { + db eval {PRAGMA automatic_index=OFF;} + db eval $sql + } $answer + do_test autoindex4-4.$id.3 { + db eval {PRAGMA automatic_index=ON;} + optimization_control db all 0 + db eval $sql + } $answer + optimization_control db all 1 +} + + + + +finish_test diff --git a/test/autoindex5.test b/test/autoindex5.test new file mode 100644 index 0000000..aa8dec2 --- /dev/null +++ b/test/autoindex5.test @@ -0,0 +1,234 @@ +# 2014-10-24 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# +# This file implements regression tests for SQLite library. The +# focus of this script is testing automatic index creation logic, +# and specifically ensuring that automatic indexes can be used with +# co-routine subqueries. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix autoindex5 + +# Schema is from the Debian security database +# +do_execsql_test autoindex5-1.0 { + CREATE TABLE source_package_status + (bug_name TEXT NOT NULL, + package INTEGER NOT NULL, + vulnerable INTEGER NOT NULL, + urgency TEXT NOT NULL, + PRIMARY KEY (bug_name, package)); + CREATE INDEX source_package_status_package + ON source_package_status(package); + + CREATE TABLE source_packages + (name TEXT NOT NULL, + release TEXT NOT NULL, + subrelease TEXT NOT NULL, + archive TEXT NOT NULL, + version TEXT NOT NULL, + version_id INTEGER NOT NULL DEFAULT 0, + PRIMARY KEY (name, release, subrelease, archive)); + + CREATE TABLE bugs + (name TEXT NOT NULL PRIMARY KEY, + cve_status TEXT NOT NULL + CHECK (cve_status IN + ('', 'CANDIDATE', 'ASSIGNED', 'RESERVED', 'REJECTED')), + not_for_us INTEGER NOT NULL CHECK (not_for_us IN (0, 1)), + description TEXT NOT NULL, + release_date TEXT NOT NULL, + source_file TEXT NOT NULL, + source_line INTEGER NOT NULL); + + CREATE TABLE package_notes + (id INTEGER NOT NULL PRIMARY KEY, + bug_name TEXT NOT NULL, + package TEXT NOT NULL, + fixed_version TEXT + CHECK (fixed_version IS NULL OR fixed_version <> ''), + fixed_version_id INTEGER NOT NULL DEFAULT 0, + release TEXT NOT NULL, + package_kind TEXT NOT NULL DEFAULT 'unknown', + urgency TEXT NOT NULL, + bug_origin TEXT NOT NULL DEFAULT ''); + CREATE INDEX package_notes_package + ON package_notes(package); + CREATE UNIQUE INDEX package_notes_bug + ON package_notes(bug_name, package, release); + + CREATE TABLE debian_bugs + (bug INTEGER NOT NULL, + note INTEGER NOT NULL, + PRIMARY KEY (bug, note)); + + + CREATE VIEW debian_cve AS + SELECT DISTINCT debian_bugs.bug, st.bug_name + FROM package_notes, debian_bugs, source_package_status AS st + WHERE package_notes.bug_name = st.bug_name + AND debian_bugs.note = package_notes.id + ORDER BY debian_bugs.bug; +} {} + +# The following query should use an automatic index for the view +# in FROM clause of the subquery of the second result column. +# +do_eqp_test autoindex5-1.1 { + SELECT + st.bug_name, + (SELECT ALL debian_cve.bug FROM debian_cve + WHERE debian_cve.bug_name = st.bug_name + ORDER BY debian_cve.bug), + sp.release + FROM + source_package_status AS st, + source_packages AS sp, + bugs + WHERE + sp.rowid = st.package + AND st.bug_name = bugs.name + AND ( st.bug_name LIKE 'CVE-%' OR st.bug_name LIKE 'TEMP-%' ) + AND ( sp.release = 'sid' OR sp.release = 'stretch' OR sp.release = 'jessie' + OR sp.release = 'wheezy' OR sp.release = 'squeeze' ) + ORDER BY sp.name, st.bug_name, sp.release, sp.subrelease; +} {SEARCH debian_cve USING AUTOMATIC COVERING INDEX (bug_name=?)} + +#------------------------------------------------------------------------- +# Test that ticket [8a2adec1] has been fixed. +# +do_execsql_test 2.1 { + CREATE TABLE one(o); + INSERT INTO one DEFAULT VALUES; + + CREATE TABLE t1(x, z); + INSERT INTO t1 VALUES('aaa', 4.0); + INSERT INTO t1 VALUES('aaa', 4.0); + CREATE VIEW vvv AS + SELECT * FROM t1 + UNION ALL + SELECT 0, 0 WHERE 0; + + SELECT ( + SELECT sum(z) FROM vvv WHERE x='aaa' + ) FROM one; +} {8.0} + +# At one point the following was returning "no such column: rowid". This +# was incorrect - "rowid" matches against the rowid of table t1 in this +# query. +do_catchsql_test 2.2 { + DROP TABLE t1; + CREATE TABLE t1(aaa); + INSERT INTO t1(aaa) VALUES(9); + SELECT ( + SELECT aaa FROM t1 GROUP BY ( + SELECT bbb FROM ( + SELECT ccc AS bbb FROM ( + SELECT 1 ccc + ) WHERE rowid IS NOT 1 + ) WHERE bbb = 1 + ) + ); +} {0 9} + +# Ticket https://www.sqlite.org/src/info/787fa716be3a7f65 +# Segfault due to multiple uses of the same subquery where the +# subquery is implemented via coroutine. +# +ifcapable windowfunc { +sqlite3 db :memory: +do_execsql_test 3.0 { + -- This is the original test case reported on the mailing list + CREATE TABLE artists ( + id integer NOT NULL PRIMARY KEY AUTOINCREMENT, + name varchar(255) + ); + CREATE TABLE albums ( + id integer NOT NULL PRIMARY KEY AUTOINCREMENT, + name varchar(255), + artist_id integer REFERENCES artists + ); + INSERT INTO artists (name) VALUES ('Ar'); + INSERT INTO albums (name, artist_id) VALUES ('Al', 1); + SELECT artists.* + FROM artists + INNER JOIN artists AS 'b' ON (b.id = artists.id) + WHERE (artists.id IN ( + SELECT albums.artist_id + FROM albums + WHERE ((name = 'Al') + AND (albums.artist_id IS NOT NULL) + AND (albums.id IN ( + SELECT id + FROM ( + SELECT albums.id, + row_number() OVER ( + PARTITION BY albums.artist_id + ORDER BY name + ) AS 'x' + FROM albums + WHERE (name = 'Al') + ) AS 't1' + WHERE (x = 1) + )) + AND (albums.id IN (1, 2))) + )); +} {1 Ar} +} ;# windowfunc + +# The remaining test cases were discovered (by Dan) during trouble-shooting +sqlite3 db :memory: +do_execsql_test 3.1 { + CREATE TABLE t1 (a); INSERT INTO t1 (a) VALUES (104); + CREATE TABLE t2 (b); INSERT INTO t2 (b) VALUES (104); + CREATE TABLE t3 (c); INSERT INTO t3 (c) VALUES (104); + CREATE TABLE t4 (d); INSERT INTO t4 (d) VALUES (104); + SELECT * + FROM t1 CROSS JOIN t2 ON (t1.a = t2.b) WHERE t2.b IN ( + SELECT t3.c + FROM t3 + WHERE t3.c IN ( + SELECT d FROM (SELECT DISTINCT d FROM t4) AS x WHERE x.d=104 + ) + ); +} {104 104} +sqlite3 db :memory: +do_execsql_test 3.2 { + CREATE TABLE t5(a, b, c, d); + CREATE INDEX t5a ON t5(a); + CREATE INDEX t5b ON t5(b); + CREATE TABLE t6(e); + INSERT INTO t6 VALUES(1); + INSERT INTO t5 VALUES(1,1,1,1), (2,2,2,2); + SELECT * FROM t5 WHERE (a=1 OR b=2) AND c IN ( + SELECT e FROM (SELECT DISTINCT e FROM t6) WHERE e=1 + ); +} {1 1 1 1} +sqlite3 db :memory: +do_execsql_test 3.3 { + CREATE TABLE t1(a1, a2, a3); + CREATE INDEX t1a2 ON t1(a2, a1); + CREATE INDEX t1a3 ON t1(a3, a1); + CREATE TABLE t2(d); + INSERT INTO t1 VALUES(3, 1, 1), (3, 2, 2); + INSERT INTO t2 VALUES(3); + SELECT *, 'x' FROM t1 WHERE (a2=1 OR a3=2) AND a1 = ( + SELECT d FROM (SELECT DISTINCT d FROM t2) WHERE d=3 + ); +} {3 1 1 x 3 2 2 x} + + + + +finish_test diff --git a/test/autovacuum.test b/test/autovacuum.test new file mode 100644 index 0000000..245ea8b --- /dev/null +++ b/test/autovacuum.test @@ -0,0 +1,715 @@ +# 2001 September 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing the autovacuum feature. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If this build of the library does not support auto-vacuum, omit this +# whole file. +ifcapable {!autovacuum || !pragma} { + finish_test + return +} + +# Return a string $len characters long. The returned string is $char repeated +# over and over. For example, [make_str abc 8] returns "abcabcab". +proc make_str {char len} { + set str [string repeat $char. $len] + return [string range $str 0 [expr $len-1]] +} + +# Return the number of pages in the file test.db by looking at the file system. +proc file_pages {} { + return [expr [file size test.db] / 1024] +} + +#------------------------------------------------------------------------- +# Test cases autovacuum-1.* work as follows: +# +# 1. A table with a single indexed field is created. +# 2. Approximately 20 rows are inserted into the table. Each row is long +# enough such that it uses at least 2 overflow pages for both the table +# and index entry. +# 3. The rows are deleted in a psuedo-random order. Sometimes only one row +# is deleted per transaction, sometimes more than one. +# 4. After each transaction the table data is checked to ensure it is correct +# and a "PRAGMA integrity_check" is executed. +# 5. Once all the rows are deleted the file is checked to make sure it +# consists of exactly 4 pages. +# +# Steps 2-5 are repeated for a few different psuedo-random delete patterns +# (defined by the $delete_orders list). +set delete_orders [list] +lappend delete_orders {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20} +lappend delete_orders {20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +lappend delete_orders {8 18 2 4 14 11 13 3 10 7 9 5 12 17 19 15 20 6 16 1} +lappend delete_orders {10 3 11 17 19 20 7 4 13 6 1 14 16 12 9 18 8 15 5 2} +lappend delete_orders {{1 2 3 4 5 6 7 8 9 10} {11 12 13 14 15 16 17 18 19 20}} +lappend delete_orders {{19 8 17 15} {16 11 9 14} {18 5 3 1} {13 20 7 2} {6 12}} + +# The length of each table entry. +# set ENTRY_LEN 3500 +set ENTRY_LEN 3500 + +do_test autovacuum-1.1 { + execsql { + PRAGMA auto_vacuum = 1; + CREATE TABLE av1(a); + CREATE INDEX av1_idx ON av1(a); + } +} {} + +set tn 0 +foreach delete_order $delete_orders { + incr tn + + # Set up the table. + set ::tbl_data [list] + foreach i [lsort -integer [eval concat $delete_order]] { + execsql "INSERT INTO av1 (oid, a) VALUES($i, '[make_str $i $ENTRY_LEN]')" + lappend ::tbl_data [make_str $i $ENTRY_LEN] + } + + # Make sure the integrity check passes with the initial data. + ifcapable {integrityck} { + do_test autovacuum-1.$tn.1 { + execsql { + pragma integrity_check + } + } {ok} + } + + foreach delete $delete_order { + # Delete one set of rows from the table. + do_test autovacuum-1.$tn.($delete).1 { + execsql " + DELETE FROM av1 WHERE oid = [join $delete " OR oid = "] + " + } {} + + # Do the integrity check. + ifcapable {integrityck} { + do_test autovacuum-1.$tn.($delete).2 { + execsql { + pragma integrity_check + } + } {ok} + } + # Ensure the data remaining in the table is what was expected. + foreach d $delete { + set idx [lsearch $::tbl_data [make_str $d $ENTRY_LEN]] + set ::tbl_data [lreplace $::tbl_data $idx $idx] + } + do_test autovacuum-1.$tn.($delete).3 { + execsql { + select a from av1 order by rowid + } + } $::tbl_data + } + + # All rows have been deleted. Ensure the file has shrunk to 4 pages. + do_test autovacuum-1.$tn.3 { + file_pages + } {4} +} + +#--------------------------------------------------------------------------- +# Tests cases autovacuum-2.* test that root pages are allocated +# and deallocated correctly at the start of the file. Operation is roughly as +# follows: +# +# autovacuum-2.1.*: Drop the tables that currently exist in the database. +# autovacuum-2.2.*: Create some tables. Ensure that data pages can be +# moved correctly to make space for new root-pages. +# autovacuum-2.3.*: Drop one of the tables just created (not the last one), +# and check that one of the other tables is moved to +# the free root-page location. +# autovacuum-2.4.*: Check that a table can be created correctly when the +# root-page it requires is on the free-list. +# autovacuum-2.5.*: Check that a table with indices can be dropped. This +# is slightly tricky because dropping one of the +# indices/table btrees could move the root-page of another. +# The code-generation layer of SQLite overcomes this problem +# by dropping the btrees in descending order of root-pages. +# This test ensures that this actually happens. +# +do_test autovacuum-2.1.1 { + execsql { + DROP TABLE av1; + } +} {} +do_test autovacuum-2.1.2 { + file_pages +} {1} + +# Create a table and put some data in it. +do_test autovacuum-2.2.1 { + execsql { + CREATE TABLE av1(x); + SELECT rootpage FROM sqlite_master ORDER BY rootpage; + } +} {3} +do_test autovacuum-2.2.2 { + execsql " + INSERT INTO av1 VALUES('[make_str abc 3000]'); + INSERT INTO av1 VALUES('[make_str def 3000]'); + INSERT INTO av1 VALUES('[make_str ghi 3000]'); + INSERT INTO av1 VALUES('[make_str jkl 3000]'); + " + set ::av1_data [db eval {select * from av1}] + file_pages +} {15} + +# Create another table. Check it is located immediately after the first. +# This test case moves the second page in an over-flow chain. +do_test autovacuum-2.2.3 { + execsql { + CREATE TABLE av2(x); + SELECT rootpage FROM sqlite_master ORDER BY rootpage; + } +} {3 4} +do_test autovacuum-2.2.4 { + file_pages +} {16} + +# Create another table. Check it is located immediately after the second. +# This test case moves the first page in an over-flow chain. +do_test autovacuum-2.2.5 { + execsql { + CREATE TABLE av3(x); + SELECT rootpage FROM sqlite_master ORDER BY rootpage; + } +} {3 4 5} +do_test autovacuum-2.2.6 { + file_pages +} {17} + +# Create another table. Check it is located immediately after the second. +# This test case moves a btree leaf page. +do_test autovacuum-2.2.7 { + execsql { + CREATE TABLE av4(x); + SELECT rootpage FROM sqlite_master ORDER BY rootpage; + } +} {3 4 5 6} +do_test autovacuum-2.2.8 { + file_pages +} {18} +do_test autovacuum-2.2.9 { + execsql { + select * from av1 + } +} $av1_data + +do_test autovacuum-2.3.1 { + execsql { + INSERT INTO av2 SELECT 'av1' || x FROM av1; + INSERT INTO av3 SELECT 'av2' || x FROM av1; + INSERT INTO av4 SELECT 'av3' || x FROM av1; + } + set ::av2_data [execsql {select x from av2}] + set ::av3_data [execsql {select x from av3}] + set ::av4_data [execsql {select x from av4}] + file_pages +} {54} +do_test autovacuum-2.3.2 { + execsql { + DROP TABLE av2; + SELECT rootpage FROM sqlite_master ORDER BY rootpage; + } +} {3 4 5} +do_test autovacuum-2.3.3 { + file_pages +} {41} +do_test autovacuum-2.3.4 { + execsql { + SELECT x FROM av3; + } +} $::av3_data +do_test autovacuum-2.3.5 { + execsql { + SELECT x FROM av4; + } +} $::av4_data + +# Drop all the tables in the file. This puts all pages except the first 2 +# (the sqlite_master root-page and the first pointer map page) on the +# free-list. +do_test autovacuum-2.4.1 { + execsql { + DROP TABLE av1; + DROP TABLE av3; + BEGIN; + DROP TABLE av4; + } + file_pages +} {15} +do_test autovacuum-2.4.2 { + for {set i 3} {$i<=10} {incr i} { + execsql "CREATE TABLE av$i (x)" + } + file_pages +} {15} +do_test autovacuum-2.4.3 { + execsql { + SELECT rootpage FROM sqlite_master ORDER by rootpage + } +} {3 4 5 6 7 8 9 10} + +# Right now there are 5 free pages in the database. Consume and then free +# all 520 pages. Then create 520 tables. This ensures that at least some of the +# desired root-pages reside on the second free-list trunk page, and that the +# trunk itself is required at some point. +do_test autovacuum-2.4.4 { + execsql " + INSERT INTO av3 VALUES ('[make_str abcde [expr 1020*520 + 500]]'); + DELETE FROM av3; + " +} {} +set root_page_list [list] +set pending_byte_page [expr ($::sqlite_pending_byte / 1024) + 1] + +# unusable_pages +# These are either the pending_byte page or the pointer map pages +# +unset -nocomplain unusable_page +if {[sqlite3 -has-codec]} { + array set unusable_page {205 1 408 1} +} else { + array set unusable_page {207 1 412 1} +} +set unusable_page($pending_byte_page) 1 + +for {set i 3} {$i<=532} {incr i} { + if {![info exists unusable_page($i)]} { + lappend root_page_list $i + } +} +if {$i >= $pending_byte_page} { + lappend root_page_list $i +} +do_test autovacuum-2.4.5 { + for {set i 11} {$i<=530} {incr i} { + execsql "CREATE TABLE av$i (x)" + } + execsql { + SELECT rootpage FROM sqlite_master ORDER by rootpage + } +} $root_page_list + +# Just for fun, delete all those tables and see if the database is 1 page. +do_test autovacuum-2.4.6 { + execsql COMMIT; + file_pages +} [expr 561 + (($i >= $pending_byte_page)?1:0)] +integrity_check autovacuum-2.4.6 +do_test autovacuum-2.4.7 { + execsql BEGIN + for {set i 3} {$i<=530} {incr i} { + execsql "DROP TABLE av$i" + } + execsql COMMIT + file_pages +} 1 + +# Create some tables with indices to drop. +do_test autovacuum-2.5.1 { + execsql { + CREATE TABLE av1(a PRIMARY KEY, b, c); + INSERT INTO av1 VALUES('av1 a', 'av1 b', 'av1 c'); + + CREATE TABLE av2(a PRIMARY KEY, b, c); + CREATE INDEX av2_i1 ON av2(b); + CREATE INDEX av2_i2 ON av2(c); + INSERT INTO av2 VALUES('av2 a', 'av2 b', 'av2 c'); + + CREATE TABLE av3(a PRIMARY KEY, b, c); + CREATE INDEX av3_i1 ON av3(b); + INSERT INTO av3 VALUES('av3 a', 'av3 b', 'av3 c'); + + CREATE TABLE av4(a, b, c); + CREATE INDEX av4_i1 ON av4(a); + CREATE INDEX av4_i2 ON av4(b); + CREATE INDEX av4_i3 ON av4(c); + CREATE INDEX av4_i4 ON av4(a, b, c); + INSERT INTO av4 VALUES('av4 a', 'av4 b', 'av4 c'); + } +} {} + +do_test autovacuum-2.5.2 { + execsql { + SELECT name, rootpage FROM sqlite_master; + } +} [list av1 3 sqlite_autoindex_av1_1 4 \ + av2 5 sqlite_autoindex_av2_1 6 av2_i1 7 av2_i2 8 \ + av3 9 sqlite_autoindex_av3_1 10 av3_i1 11 \ + av4 12 av4_i1 13 av4_i2 14 av4_i3 15 av4_i4 16 \ +] + +# The following 4 tests are SELECT queries that use the indices created. +# If the root-pages in the internal schema are not updated correctly when +# a table or indice is moved, these queries will fail. They are repeated +# after each table is dropped (i.e. as test cases 2.5.*.[1..4]). +do_test autovacuum-2.5.2.1 { + execsql { + SELECT * FROM av1 WHERE a = 'av1 a'; + } +} {{av1 a} {av1 b} {av1 c}} +do_test autovacuum-2.5.2.2 { + execsql { + SELECT * FROM av2 WHERE a = 'av2 a' AND b = 'av2 b' AND c = 'av2 c' + } +} {{av2 a} {av2 b} {av2 c}} +do_test autovacuum-2.5.2.3 { + execsql { + SELECT * FROM av3 WHERE a = 'av3 a' AND b = 'av3 b'; + } +} {{av3 a} {av3 b} {av3 c}} +do_test autovacuum-2.5.2.4 { + execsql { + SELECT * FROM av4 WHERE a = 'av4 a' AND b = 'av4 b' AND c = 'av4 c'; + } +} {{av4 a} {av4 b} {av4 c}} + +# Drop table av3. Indices av4_i2, av4_i3 and av4_i4 are moved to fill the two +# root pages vacated. The operation proceeds as: +# Step 1: Delete av3_i1 (root-page 11). Move root-page of av4_i4 to page 11. +# Step 2: Delete av3 (root-page 10). Move root-page of av4_i3 to page 10. +# Step 3: Delete sqlite_autoindex_av1_3 (root-page 9). Move av4_i2 to page 9. +do_test autovacuum-2.5.3 { + execsql { + DROP TABLE av3; + SELECT name, rootpage FROM sqlite_master; + } +} [list av1 3 sqlite_autoindex_av1_1 4 \ + av2 5 sqlite_autoindex_av2_1 6 av2_i1 7 av2_i2 8 \ + av4 12 av4_i1 13 av4_i2 9 av4_i3 10 av4_i4 11 \ +] +do_test autovacuum-2.5.3.1 { + execsql { + SELECT * FROM av1 WHERE a = 'av1 a'; + } +} {{av1 a} {av1 b} {av1 c}} +do_test autovacuum-2.5.3.2 { + execsql { + SELECT * FROM av2 WHERE a = 'av2 a' AND b = 'av2 b' AND c = 'av2 c' + } +} {{av2 a} {av2 b} {av2 c}} +do_test autovacuum-2.5.3.3 { + execsql { + SELECT * FROM av4 WHERE a = 'av4 a' AND b = 'av4 b' AND c = 'av4 c'; + } +} {{av4 a} {av4 b} {av4 c}} + +# Drop table av1: +# Step 1: Delete av1 (root page 4). Root-page of av4_i1 fills the gap. +# Step 2: Delete sqlite_autoindex_av1_1 (root page 3). Move av4 to the gap. +do_test autovacuum-2.5.4 { + execsql { + DROP TABLE av1; + SELECT name, rootpage FROM sqlite_master; + } +} [list av2 5 sqlite_autoindex_av2_1 6 av2_i1 7 av2_i2 8 \ + av4 3 av4_i1 4 av4_i2 9 av4_i3 10 av4_i4 11 \ +] +do_test autovacuum-2.5.4.2 { + execsql { + SELECT * FROM av2 WHERE a = 'av2 a' AND b = 'av2 b' AND c = 'av2 c' + } +} {{av2 a} {av2 b} {av2 c}} +do_test autovacuum-2.5.4.4 { + execsql { + SELECT * FROM av4 WHERE a = 'av4 a' AND b = 'av4 b' AND c = 'av4 c'; + } +} {{av4 a} {av4 b} {av4 c}} + +# Drop table av4: +# Step 1: Delete av4_i4. +# Step 2: Delete av4_i3. +# Step 3: Delete av4_i2. +# Step 4: Delete av4_i1. av2_i2 replaces it. +# Step 5: Delete av4. av2_i1 replaces it. +do_test autovacuum-2.5.5 { + execsql { + DROP TABLE av4; + SELECT name, rootpage FROM sqlite_master; + } +} [list av2 5 sqlite_autoindex_av2_1 6 av2_i1 3 av2_i2 4] +do_test autovacuum-2.5.5.2 { + execsql { + SELECT * FROM av2 WHERE a = 'av2 a' AND b = 'av2 b' AND c = 'av2 c' + } +} {{av2 a} {av2 b} {av2 c}} + +#-------------------------------------------------------------------------- +# Test cases autovacuum-3.* test the operation of the "PRAGMA auto_vacuum" +# command. +# +do_test autovacuum-3.1 { + execsql { + PRAGMA auto_vacuum; + } +} {1} +do_test autovacuum-3.2 { + db close + sqlite3 db test.db + execsql { + PRAGMA auto_vacuum; + } +} {1} +do_test autovacuum-3.3 { + execsql { + PRAGMA auto_vacuum = 0; + PRAGMA auto_vacuum; + } +} {1} + +do_test autovacuum-3.4 { + db close + forcedelete test.db + sqlite3 db test.db + execsql { + PRAGMA auto_vacuum; + } +} $AUTOVACUUM +do_test autovacuum-3.5 { + execsql { + CREATE TABLE av1(x); + PRAGMA auto_vacuum; + } +} $AUTOVACUUM +do_test autovacuum-3.6 { + execsql { + PRAGMA auto_vacuum = 1; + PRAGMA auto_vacuum; + } +} [expr $AUTOVACUUM ? 1 : 0] +do_test autovacuum-3.7 { + execsql { + DROP TABLE av1; + } + file_pages +} [expr $AUTOVACUUM?1:2] + + +#----------------------------------------------------------------------- +# Test that if a statement transaction around a CREATE INDEX statement is +# rolled back no corruption occurs. +# +do_test autovacuum-4.0 { + # The last round of tests may have left the db in non-autovacuum mode. + # Reset everything just in case. + # + db close + forcedelete test.db test.db-journal + sqlite3 db test.db + execsql { + PRAGMA auto_vacuum = 1; + PRAGMA auto_vacuum; + } +} {1} +do_test autovacuum-4.1 { + execsql { + CREATE TABLE av1(a, b); + BEGIN; + } + for {set i 0} {$i<100} {incr i} { + execsql "INSERT INTO av1 VALUES($i, '[string repeat X 200]');" + } + execsql "INSERT INTO av1 VALUES(99, '[string repeat X 200]');" + execsql { + SELECT sum(a) FROM av1; + } +} {5049} +do_test autovacuum-4.2 { + catchsql { + CREATE UNIQUE INDEX av1_i ON av1(a); + } +} {1 {UNIQUE constraint failed: av1.a}} +do_test autovacuum-4.3 { + execsql { + SELECT sum(a) FROM av1; + } +} {5049} +do_test autovacuum-4.4 { + execsql { + COMMIT; + } +} {} + +ifcapable integrityck { + +# Ticket #1727 +do_test autovacuum-5.1 { + db close + sqlite3 db :memory: + db eval { + PRAGMA auto_vacuum=1; + CREATE TABLE t1(a); + CREATE TABLE t2(a); + DROP TABLE t1; + PRAGMA integrity_check; + } +} ok + +} + +# Ticket #1728. +# +# In autovacuum mode, when tables or indices are deleted, the rootpage +# values in the symbol table have to be updated. There was a bug in this +# logic so that if an index/table was moved twice, the second move might +# not occur. This would leave the internal symbol table in an inconsistent +# state causing subsequent statements to fail. +# +# The problem is difficult to reproduce. The sequence of statements in +# the following test are carefully designed make it occur and thus to +# verify that this very obscure bug has been resolved. +# +ifcapable integrityck&&memorydb { + +do_test autovacuum-6.1 { + db close + sqlite3 db :memory: + db eval { + PRAGMA auto_vacuum=1; + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a); + CREATE TABLE t2(a); + CREATE INDEX i2 ON t2(a); + CREATE TABLE t3(a); + CREATE INDEX i3 ON t2(a); + CREATE INDEX x ON t1(b); + DROP TABLE t3; + PRAGMA integrity_check; + DROP TABLE t2; + PRAGMA integrity_check; + DROP TABLE t1; + PRAGMA integrity_check; + } +} {ok ok ok} + +} + +#--------------------------------------------------------------------- +# Test cases autovacuum-7.X test the case where a page must be moved +# and the destination location collides with at least one other +# entry in the page hash-table (internal to the pager.c module. +# +do_test autovacuum-7.1 { + db close + forcedelete test.db + forcedelete test.db-journal + sqlite3 db test.db + + execsql { + PRAGMA auto_vacuum=1; + CREATE TABLE t1(a, b, PRIMARY KEY(a, b)); + INSERT INTO t1 VALUES(randstr(400,400),randstr(400,400)); + INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 2 + INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 4 + INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 8 + INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 16 + INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 32 + } + + expr {[file size test.db] / 1024} +} {73} + +do_test autovacuum-7.2 { + execsql { + CREATE TABLE t2(a, b, PRIMARY KEY(a, b)); + INSERT INTO t2 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 2 + CREATE TABLE t3(a, b, PRIMARY KEY(a, b)); + INSERT INTO t3 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 2 + CREATE TABLE t4(a, b, PRIMARY KEY(a, b)); + INSERT INTO t4 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 2 + CREATE TABLE t5(a, b, PRIMARY KEY(a, b)); + INSERT INTO t5 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 2 + } + expr {[file size test.db] / 1024} +} {354} + +do_test autovacuum-7.3 { + db close + sqlite3 db test.db + execsql { + BEGIN; + DELETE FROM t4; + COMMIT; + SELECT count(*) FROM t1; + } + expr {[file size test.db] / 1024} +} {286} + +#------------------------------------------------------------------------ +# Additional tests. +# +# Try to determine the autovacuum setting for a database that is locked. +# +do_test autovacuum-8.1 { + db close + sqlite3 db test.db + sqlite3 db2 test.db + db eval {PRAGMA auto_vacuum} +} {1} +if {[permutation] == ""} { + do_test autovacuum-8.2 { + db eval {BEGIN EXCLUSIVE} + catchsql {PRAGMA auto_vacuum} db2 + } {1 {database is locked}} + catch {db2 close} + catch {db eval {COMMIT}} +} + +do_test autovacuum-9.1 { + execsql { + DROP TABLE t1; + DROP TABLE t2; + DROP TABLE t3; + DROP TABLE t4; + DROP TABLE t5; + PRAGMA page_count; + } +} {1} +do_test autovacuum-9.2 { + file size test.db +} 1024 +do_test autovacuum-9.3 { + execsql { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + INSERT INTO t1 VALUES(NULL, randstr(50,50)); + } + for {set ii 0} {$ii < 10} {incr ii} { + db eval { INSERT INTO t1 SELECT NULL, randstr(50,50) FROM t1 } + } + file size test.db +} $::sqlite_pending_byte +do_test autovacuum-9.4 { + execsql { INSERT INTO t1 SELECT NULL, randstr(50,50) FROM t1 } +} {} +do_test autovacuum-9.5 { + execsql { DELETE FROM t1 WHERE rowid > (SELECT max(a)/2 FROM t1) } + file size test.db +} $::sqlite_pending_byte + +do_execsql_test autovacuum-10.1 { + DROP TABLE t1; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + INSERT INTO t1 VALUES(25, randomblob(104)); + REPLACE INTO t1 VALUES(25, randomblob(1117)); + PRAGMA integrity_check; +} {ok} + +finish_test diff --git a/test/autovacuum2.test b/test/autovacuum2.test new file mode 100644 index 0000000..a3c4098 --- /dev/null +++ b/test/autovacuum2.test @@ -0,0 +1,87 @@ +# 2021-10-15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing the sqlite3_autovacuum_pages() interface +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If this build of the library does not support auto-vacuum, omit this +# whole file. +ifcapable {!autovacuum || !pragma} { + finish_test + return +} + +# Demonstrate basic sqlite3_autovacuum_pages functionality +# +do_execsql_test autovacuum2-1.0 { + PRAGMA page_size=1024; + PRAGMA auto_vacuum=FULL; + CREATE TABLE t1(x); + VACUUM; + INSERT INTO t1(x) VALUES(zeroblob(10000)); + PRAGMA page_count; +} {12} +proc autovac_page_callback {schema filesize freesize pagesize} { + global autovac_callback_data + lappend autovac_callback_data $schema $filesize $freesize $pagesize + return [expr {$freesize/2}] +} +sqlite3_autovacuum_pages db autovac_page_callback +set autovac_callback_data {} +do_execsql_test autovacuum2-1.1 { + BEGIN; + DELETE FROM t1; + PRAGMA freelist_count; + PRAGMA page_count; +} {9 12} +do_execsql_test autovacuum2-1.2 { + COMMIT; +} {} +do_test autovacuum2-1.3 { + set autovac_callback_data +} {main 12 9 1024} +do_execsql_test autovacuum2-1.4 { + PRAGMA freelist_count; + PRAGMA page_count; +} {5 8} +do_execsql_test autovacuum2-1.5 { + PRAGMA integrity_check; +} {ok} + +# Disable the autovacuum-pages callback. Then do any transaction. +# The database should shrink to minimal size +# +sqlite3_autovacuum_pages db +do_execsql_test autovacuum2-1.10 { + CREATE TABLE t2(x); + PRAGMA freelist_count; +} {0} + +# Rig the autovacuum-pages callback to always return zero. No +# autovacuum will happen. +# +proc autovac_page_callback_off {schema filesize freesize pagesize} { + return 0 +} +sqlite3_autovacuum_pages db autovac_page_callback_off +do_execsql_test autovacuum2-1.20 { + BEGIN; + INSERT INTO t1(x) VALUES(zeroblob(10000)); + DELETE FROM t1; + PRAGMA freelist_count; + COMMIT; + PRAGMA freelist_count; +} {9 9} + +finish_test diff --git a/test/autovacuum_ioerr2.test b/test/autovacuum_ioerr2.test new file mode 100644 index 0000000..891d00e --- /dev/null +++ b/test/autovacuum_ioerr2.test @@ -0,0 +1,132 @@ +# 2001 October 12 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing for correct handling of I/O errors +# such as writes failing because the disk is full. +# +# The tests in this file use special facilities that are only +# available in the SQLite test fixture. +# +# $Id: autovacuum_ioerr2.test,v 1.7 2008/07/12 14:52:20 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If this build of the library does not support auto-vacuum, omit this +# whole file. +ifcapable {!autovacuum} { + finish_test + return +} + +do_ioerr_test autovacuum-ioerr2-1 -sqlprep { + PRAGMA auto_vacuum = 1; + CREATE TABLE abc(a); + INSERT INTO abc VALUES(randstr(1500,1500)); +} -sqlbody { + CREATE TABLE abc2(a); + BEGIN; + DELETE FROM abc; + INSERT INTO abc VALUES(randstr(1500,1500)); + CREATE TABLE abc3(a); + COMMIT; +} + +do_ioerr_test autovacuum-ioerr2-2 -tclprep { + execsql { + PRAGMA auto_vacuum = 1; + PRAGMA cache_size = 10; + BEGIN; + CREATE TABLE abc(a); + INSERT INTO abc VALUES(randstr(1100,1100)); -- Page 4 is overflow + INSERT INTO abc VALUES(randstr(1100,1100)); -- Page 5 is overflow + } + for {set i 0} {$i<150} {incr i} { + execsql { + INSERT INTO abc VALUES(randstr(100,100)); + } + } + execsql COMMIT +} -sqlbody { + BEGIN; + DELETE FROM abc WHERE length(a)>100; + UPDATE abc SET a = randstr(90,90); + CREATE TABLE abc3(a); + COMMIT; +} + +do_ioerr_test autovacuum-ioerr2-3 -sqlprep { + PRAGMA auto_vacuum = 1; + CREATE TABLE abc(a); + CREATE TABLE abc2(b); +} -sqlbody { + BEGIN; + INSERT INTO abc2 VALUES(10); + DROP TABLE abc; + COMMIT; + DROP TABLE abc2; +} + +forcedelete backup.db +ifcapable subquery { + do_ioerr_test autovacuum-ioerr2-4 -tclprep { + if {![file exists backup.db]} { + sqlite3 dbb backup.db + execsql { + PRAGMA auto_vacuum = 1; + BEGIN; + CREATE TABLE abc(a); + INSERT INTO abc VALUES(randstr(1100,1100)); -- Page 4 is overflow + INSERT INTO abc VALUES(randstr(1100,1100)); -- Page 5 is overflow + } dbb + for {set i 0} {$i<2500} {incr i} { + execsql { + INSERT INTO abc VALUES(randstr(100,100)); + } dbb + } + execsql { + COMMIT; + PRAGMA cache_size = 10; + } dbb + dbb close + } + db close + forcedelete test.db + forcedelete test.db-journal + forcecopy backup.db test.db + set ::DB [sqlite3 db test.db] + execsql { + PRAGMA cache_size = 10; + } + } -sqlbody { + BEGIN; + DELETE FROM abc WHERE oid < 3; + UPDATE abc SET a = randstr(100,100) WHERE oid > 2300; + UPDATE abc SET a = randstr(1100,1100) WHERE oid = + (select max(oid) from abc); + COMMIT; + } +} + +do_ioerr_test autovacuum-ioerr2-1 -sqlprep { + PRAGMA auto_vacuum = 1; + CREATE TABLE abc(a); + INSERT INTO abc VALUES(randstr(1500,1500)); +} -sqlbody { + CREATE TABLE abc2(a); + BEGIN; + DELETE FROM abc; + INSERT INTO abc VALUES(randstr(1500,1500)); + CREATE TABLE abc3(a); + COMMIT; +} + +finish_test diff --git a/test/avfs.test b/test/avfs.test new file mode 100644 index 0000000..2ebd608 --- /dev/null +++ b/test/avfs.test @@ -0,0 +1,395 @@ +# 2021-03-06 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file implements tests for the appendvfs extension. +# +# Tests performed: +# avfs-1.0. Test that an appendvfs DB can be added to an empty (ZLF) file. +# avfs-1.1. Test that the DB can be read with correct content upon reopen. +# avfs-1.2. Test that an appendvfs DB can be added to a simple text file. +# avfs-1.3. Test that the DB can be read with correct content upon reopen. +# avfs-1.4. Test that appended DB is aligned to default page boundary. +# avfs-2.1. Test that the simple text file retains its initial text. +# avfs-3.1. Test that the appendvfs can grow and shrink, remaining intact. +# avfs-3.2. Test that appendvfs is intact after grow/shrink/close/reopen. +# avfs-3.3. Test that appendvfs can grow by many pages and be written. +# avfs-3.4. Test that grown appendvfs can be reopened and appear intact. +# avfs-3.5. Test that much grown appendvfs can shrink and reopen intact. +# avfs-4.1. Test shell's ability to append to a non-appendvfs file. +# avfs-4.2. Test shell's ability to append to empty or nonexistent file. +# avfs-4.3. Test shell's ability to reopen and alter an appendvfs file. +# avfs-5.1. Test appendvfs refusal to open too-tiny DB appended onto ZLF. +# avfs-5.2. Test appendvfs refusal to open too-tiny DB appended on other. +# ... +# (more to come) + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix avfs + +# Do not attempt this test if SQLITE_OMIT_VIRTUALTABLE is defined. +# +ifcapable !vtab { + finish_test + return +} + +set CLI [test_find_cli] +db close +# forcedelete test.db + +load_static_extension db appendvfs + +set ::fa avfs.adb +set ::fza avfs.sdb +forcedelete $::fa $::fza +set ::result {} + +proc shellDoesAr {} { + set shdo "sh_app1.sql" + forcedelete $shdo + set fd [open $shdo w] + puts $fd ".help\n.q" + close $fd + set res [catchcmd "-batch -cmd \".read $shdo\""] + return [regexp {^.archive} [lindex $res 1]] +} + +set ::vf "&vfs=apndvfs" + +# Return file offset of appendvfs portion of a file, or {} if none such. +proc fosAvfs {fname} { + if {[file size $fname] < 25} { + return {} + } + if {[catch {set fd [open $fname rb]}]} { + return {} + } + seek $fd -25 end + set am [read $fd 17] + set ao [read $fd 8] + close $fd + if {$am ne "Start-Of-SQLite3-"} { + return {} + } + binary scan $ao "W" rvo + return $rvo +} + +do_test 1.0 { + set results {} + set out [open $::fza wb] + close $out + sqlite3 adb "file:$::fza?mode=rwc$::vf" -uri 1 + adb eval { + PRAGMA page_size=1024; + PRAGMA cache_size=10; + CREATE TABLE t1(a TEXT); + INSERT INTO t1 VALUES ('dog'),('cat'); + SELECT group_concat(a) as pets FROM (SELECT a FROM t1 ORDER BY a); + } { lappend results $pets } + adb close + lappend results [fosAvfs $fza] + set ::result [join $results " | "] +} {cat,dog | 0} + +do_test 1.1 { + set results {} + sqlite3 adb "file:$::fza?mode=rw$::vf" -uri 1 + adb eval { + SELECT group_concat(a) as pets FROM (SELECT a FROM t1 ORDER BY a DESC); + } { lappend results $pets } + adb close + set ::result [join $results " | "] +} {dog,cat} + +do_test 1.2 { + set results {} + set out [open $::fa wb] + set ::tlo { "Just some text," "and more text," "ending at 3 lines." } + puts $out [join $::tlo "\n"] + close $out + set adbSz [file size $::fa] + sqlite3 adb "file:$::fa?mode=rwc$::vf" -uri 1 + adb eval { + PRAGMA auto_vacuum = 0; + PRAGMA page_size=512; + PRAGMA cache_size=0; + CREATE TABLE t1(a TEXT); + INSERT INTO t1 VALUES ('dog'),('cat'),('pig'); + SELECT group_concat(a) as pets FROM (SELECT a FROM t1 ORDER BY a); + } { lappend results $pets } + adb close + set adaSz [file size $::fa] + lappend results "Bytes before/after $adbSz/$adaSz" + set ::result [join $results " | "] +} {cat,dog,pig | Bytes before/after 50/5145} + +do_test 1.3 { + set results {} + sqlite3 adb "file:$::fa?mode=rw$::vf" -uri 1 + adb eval { + SELECT group_concat(a) as pets FROM (SELECT a FROM t1 ORDER BY a DESC); + } { lappend results $pets } + adb close + set ::result [join $results " | "] +} {pig,dog,cat} + +do_test 1.4 { + set ::result [fosAvfs $fa] +} {4096} + +do_test 2.1 { + set in [open $::fa r] + set tli {} + for {set i [llength $::tlo]} {$i > 0} {incr i -1} { + lappend tli [gets $in] + } + close $in + if { [join $tli ":"] ne [join $::tlo ":"] } { + set ::result "Appendee changed." + } else { + set ::result "Appendee intact." + } +} {Appendee intact.} + +# Set of repeatable random integers for a couple tests. +set ::nrint 50000 +proc rint {v} { + return [::tcl::mathfunc::int [expr $v * 100000]] +} +array set ::randints [list 0 [rint [::tcl::mathfunc::srand 0]]] +for {set i 1} {$i < $::nrint} {incr i} { + set ::randints($i) [rint [::tcl::mathfunc::rand]] +} + +do_test 3.1 { + set results {} + sqlite3 adb "file:$::fa?mode=rw$::vf" -uri 1 + adb eval { + DROP TABLE t1; + PRAGMA cache_size=10; + CREATE TABLE ri (i INTEGER); + BEGIN; + } + for {set i 0} {$i < $::nrint} {incr i} { + set r $::randints($i) + set s $::randints([incr i]) + set t $::randints([incr i]) + set u $::randints([incr i]) + set v $::randints([incr i]) + adb eval { + INSERT INTO ri VALUES ($r),($s),($t),($u),($v) + } + } + adb eval { + COMMIT; + SELECT integrity_check as ic FROM pragma_integrity_check(); + } { lappend results $ic } + set adbSz [file size $::fa] + set qr {} + adb eval { + SELECT count(*) as ic FROM ri; + DELETE FROM ri WHERE (i % 50) <> 25; + SELECT integrity_check as ic FROM pragma_integrity_check(); + VACUUM; + SELECT integrity_check as ic FROM pragma_integrity_check(); + SELECT count(*) as ic FROM ri; + } { lappend qr $ic } + adb close + set adaSz [file size $::fa] + set adba [expr ($adbSz + 0.1)/$adaSz] + # lappend results $adba + set results [concat $results [lrange $qr 0 2]] + lappend results [expr {$adba > 10.0}] + set ::result [join $results " | "] +} "ok | $::nrint | ok | ok | 1" + +do_test 3.2 { + set results {} + sqlite3 adb "file:$::fa?mode=rw$::vf" -uri 1 + adb eval { + SELECT integrity_check as ic FROM pragma_integrity_check(); + } { lappend results $ic } + adb close + set ::result [join $results " | "] +} {ok} + +# avfs-3.3. Test that appendvfs can grow by many pages and be written. +do_test 3.3 { + set results {} + sqlite3 adb "file:$::fa?mode=rw$::vf" -uri 1 + set npages 300 + adb eval { BEGIN } + while {$npages > 0} { + adb eval { INSERT INTO ri VALUES (randomblob(1500)) } + incr npages -1 + } + adb eval { COMMIT } + adb eval { + SELECT integrity_check as ic FROM pragma_integrity_check(); + } { lappend results $ic } + adb close + set adaSzr [expr [file size $::fa] / 300.0 / 1500 ] + set okSzr [expr $adaSzr > 1.0 && $adaSzr < 1.3 ] + lappend results $okSzr + set ::result [join $results " | "] +} {ok | 1} + +# avfs-3.4. Test that grown appendvfs can be reopened and appear intact. +do_test 3.4 { + set results {} + sqlite3 adb "file:$::fa?mode=rw$::vf" -uri 1 + adb eval { + SELECT integrity_check as ic FROM pragma_integrity_check(); + } { lappend results $ic } + adb close + set ::result $ic +} {ok} + +# avfs-3.5. Test that much grown appendvfs can shrink and reopen intact. +do_test 3.5 { + set results {} + set adbsz [file size $::fa] + sqlite3 adb "file:$::fa?mode=rw$::vf" -uri 1 + adb eval { + DELETE FROM ri WHERE rowid % 8 <> 0; + SELECT integrity_check as ic FROM pragma_integrity_check(); + VACUUM; + SELECT integrity_check as ic FROM pragma_integrity_check(); + } { lappend results $ic } + adb close + set adasz [file size $::fa] + lappend results [expr {$adbsz/$adasz > 5}] + sqlite3 adb "file:$::fa?mode=rw$::vf" -uri 1 + adb eval { + SELECT integrity_check as ic FROM pragma_integrity_check(); + } { lappend results $ic } + adb close + set ::result [join $results " | "] +} {ok | ok | 1 | ok} + +set ::cliDoesAr [shellDoesAr] + +do_test 4.1 { + set shdo "sh_app1.sql" + set shod "sh_app1.adb" + forcedelete $shdo $shod + set ofd [open $shdo w] + if {$::cliDoesAr} { + puts $ofd ".ar -c" + } else { + puts $ofd "pragma page_size=512;" + puts $ofd "create table sqlar (a);" + } + puts $ofd ".tables" + puts $ofd ".q" + close $ofd + set ofd [open $shod wb] + puts $ofd "Some text." + close $ofd + set res [catchcmd "-append -batch -init $shdo $shod" ""] + lappend res [fosAvfs $shod] + forcedelete $shdo $shod + set ::result [join $res " | "] +} {0 | sqlar | 4096} + +do_test 4.2 { + set shdo "sh_app1.sql" + set shod "sh_app1.adb" + forcedelete $shdo $shod + set ofd [open $shdo w] + if {$::cliDoesAr} { + puts $ofd ".ar -c" + } else { + puts $ofd "pragma page_size=512;" + puts $ofd "create table sqlar (a);" + } + puts $ofd ".tables" + puts $ofd ".q" + close $ofd + set ofd [open $shod wb] + close $ofd + set res [catchcmd "-append -batch -init $shdo $shod" ""] + lappend res [fosAvfs $shod] + forcedelete $shdo ; # Leave $shod for next test. + set ::result [join $res " | "] +} {0 | sqlar | 0} + +do_test 4.3 { + set shdo "sh_app1.sql" + set shod "sh_app1.adb" ; # Same as test 4.2, reusing ADB. + forcedelete $shdo + set ofd [open $shdo w] + if {$::cliDoesAr} { + puts $ofd ".ar -u $shdo" + puts $ofd "select count(*) from sqlar where name = '$shdo';" + } else { + puts $ofd "insert into sqlar values (1);" + puts $ofd "select count(*) from sqlar;" + } + puts $ofd ".q" + close $ofd + set res [catchcmd "-append -batch -init $shdo $shod" ""] + sqlite3 adb "file:$shod?mode=rw$::vf" -uri 1 + adb eval { + SELECT count(*) as n FROM sqlar + } { lappend res $n } + adb close + forcedelete $shdo $shod; + set ::result [join $res " | "] +} {0 | 1 | 1} + +do_test 5.1 { + set fake "faketiny.sdb" + forcedelete $fake + set ofd [open $fake wb] + puts -nonewline $ofd "SQLite format 3" + puts -nonewline $ofd [binary format "c" 0] + puts -nonewline $ofd "Start-Of-SQLite3-" + puts -nonewline $ofd [binary format "W" 0] + close $ofd + if {[catch {sqlite3 adb "file:$fake?mode=rw$::vf" -uri 1}]} { + set res "Open failed." + } else { + adb close + set res "Opened when should not." + } + forcedelete $fake + set ::result $res +} {Open failed.} + +do_test 5.2 { + set fake "faketiny.sdb" + forcedelete $fake + set ofd [open $fake wb] + set fakeAppendee "Dog ate my homework.\n" + puts -nonewline $ofd $fakeAppendee + puts -nonewline $ofd "SQLite format 3" + puts -nonewline $ofd [binary format "c" 0] + puts -nonewline $ofd "Start-Of-SQLite3-" + puts -nonewline $ofd [binary format "W" [string length $fakeAppendee]] + close $ofd + if {[catch {sqlite3 adb "file:$fake?mode=rw$::vf" -uri 1}]} { + set res "Open failed." + } else { + adb close + set res "Opened when should not." + } + forcedelete $fake + set ::result $res +} {Open failed.} + +forcedelete $::fa $::fza + +unset -nocomplain ::fa ::fza ::tlo ::result ::randints ::nrint ::cliDoesAr + +finish_test diff --git a/test/avtrans.test b/test/avtrans.test new file mode 100644 index 0000000..6fc4a3e --- /dev/null +++ b/test/avtrans.test @@ -0,0 +1,927 @@ +# 2001 September 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. This +# file is a copy of "trans.test" modified to run under autovacuum mode. +# the point is to stress the autovacuum logic and try to get it to fail. +# +# $Id: avtrans.test,v 1.6 2007/09/12 17:01:45 danielk1977 Exp $ + + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + + +# Create several tables to work with. +# +do_test avtrans-1.0 { + execsql { PRAGMA auto_vacuum=full } + wal_set_journal_mode + execsql { + CREATE TABLE one(a int PRIMARY KEY, b text); + INSERT INTO one VALUES(1,'one'); + INSERT INTO one VALUES(2,'two'); + INSERT INTO one VALUES(3,'three'); + SELECT b FROM one ORDER BY a; + } +} {one two three} +do_test avtrans-1.0.1 { execsql { PRAGMA auto_vacuum } } 1 +do_test avtrans-1.1 { + execsql { + CREATE TABLE two(a int PRIMARY KEY, b text); + INSERT INTO two VALUES(1,'I'); + INSERT INTO two VALUES(5,'V'); + INSERT INTO two VALUES(10,'X'); + SELECT b FROM two ORDER BY a; + } +} {I V X} +do_test avtrans-1.9 { + sqlite3 altdb test.db + execsql {SELECT b FROM one ORDER BY a} altdb +} {one two three} +do_test avtrans-1.10 { + execsql {SELECT b FROM two ORDER BY a} altdb +} {I V X} +integrity_check avtrans-1.11 +wal_check_journal_mode avtrans-1.12 + +# Basic transactions +# +do_test avtrans-2.1 { + set v [catch {execsql {BEGIN}} msg] + lappend v $msg +} {0 {}} +do_test avtrans-2.2 { + set v [catch {execsql {END}} msg] + lappend v $msg +} {0 {}} +do_test avtrans-2.3 { + set v [catch {execsql {BEGIN TRANSACTION}} msg] + lappend v $msg +} {0 {}} +do_test avtrans-2.4 { + set v [catch {execsql {COMMIT TRANSACTION}} msg] + lappend v $msg +} {0 {}} +do_test avtrans-2.5 { + set v [catch {execsql {BEGIN TRANSACTION 'foo'}} msg] + lappend v $msg +} {0 {}} +do_test avtrans-2.6 { + set v [catch {execsql {ROLLBACK TRANSACTION 'foo'}} msg] + lappend v $msg +} {0 {}} +do_test avtrans-2.10 { + execsql { + BEGIN; + SELECT a FROM one ORDER BY a; + SELECT a FROM two ORDER BY a; + END; + } +} {1 2 3 1 5 10} +integrity_check avtrans-2.11 +wal_check_journal_mode avtrans-2.12 + +# Check the locking behavior +# +sqlite3_soft_heap_limit 0 +do_test avtrans-3.1 { + execsql { + BEGIN; + UPDATE one SET a = 0 WHERE 0; + SELECT a FROM one ORDER BY a; + } +} {1 2 3} +do_test avtrans-3.2 { + catchsql { + SELECT a FROM two ORDER BY a; + } altdb +} {0 {1 5 10}} +do_test avtrans-3.3 { + catchsql { + SELECT a FROM one ORDER BY a; + } altdb +} {0 {1 2 3}} +do_test avtrans-3.4 { + catchsql { + INSERT INTO one VALUES(4,'four'); + } +} {0 {}} +do_test avtrans-3.5 { + catchsql { + SELECT a FROM two ORDER BY a; + } altdb +} {0 {1 5 10}} +do_test avtrans-3.6 { + catchsql { + SELECT a FROM one ORDER BY a; + } altdb +} {0 {1 2 3}} +do_test avtrans-3.7 { + catchsql { + INSERT INTO two VALUES(4,'IV'); + } +} {0 {}} +do_test avtrans-3.8 { + catchsql { + SELECT a FROM two ORDER BY a; + } altdb +} {0 {1 5 10}} +do_test avtrans-3.9 { + catchsql { + SELECT a FROM one ORDER BY a; + } altdb +} {0 {1 2 3}} +do_test avtrans-3.10 { + execsql {END TRANSACTION} +} {} +do_test avtrans-3.11 { + set v [catch {execsql { + SELECT a FROM two ORDER BY a; + } altdb} msg] + lappend v $msg +} {0 {1 4 5 10}} +do_test avtrans-3.12 { + set v [catch {execsql { + SELECT a FROM one ORDER BY a; + } altdb} msg] + lappend v $msg +} {0 {1 2 3 4}} +do_test avtrans-3.13 { + set v [catch {execsql { + SELECT a FROM two ORDER BY a; + } db} msg] + lappend v $msg +} {0 {1 4 5 10}} +do_test avtrans-3.14 { + set v [catch {execsql { + SELECT a FROM one ORDER BY a; + } db} msg] + lappend v $msg +} {0 {1 2 3 4}} +sqlite3_soft_heap_limit $cmdlinearg(soft-heap-limit) +integrity_check avtrans-3.15 + +do_test avtrans-4.1 { + set v [catch {execsql { + COMMIT; + } db} msg] + lappend v $msg +} {1 {cannot commit - no transaction is active}} +do_test avtrans-4.2 { + set v [catch {execsql { + ROLLBACK; + } db} msg] + lappend v $msg +} {1 {cannot rollback - no transaction is active}} +do_test avtrans-4.3 { + catchsql { + BEGIN TRANSACTION; + UPDATE two SET a = 0 WHERE 0; + SELECT a FROM two ORDER BY a; + } db +} {0 {1 4 5 10}} +do_test avtrans-4.4 { + catchsql { + SELECT a FROM two ORDER BY a; + } altdb +} {0 {1 4 5 10}} +do_test avtrans-4.5 { + catchsql { + SELECT a FROM one ORDER BY a; + } altdb +} {0 {1 2 3 4}} +do_test avtrans-4.6 { + catchsql { + BEGIN TRANSACTION; + SELECT a FROM one ORDER BY a; + } db +} {1 {cannot start a transaction within a transaction}} +do_test avtrans-4.7 { + catchsql { + SELECT a FROM two ORDER BY a; + } altdb +} {0 {1 4 5 10}} +do_test avtrans-4.8 { + catchsql { + SELECT a FROM one ORDER BY a; + } altdb +} {0 {1 2 3 4}} +do_test avtrans-4.9 { + set v [catch {execsql { + END TRANSACTION; + SELECT a FROM two ORDER BY a; + } db} msg] + lappend v $msg +} {0 {1 4 5 10}} +do_test avtrans-4.10 { + set v [catch {execsql { + SELECT a FROM two ORDER BY a; + } altdb} msg] + lappend v $msg +} {0 {1 4 5 10}} +do_test avtrans-4.11 { + set v [catch {execsql { + SELECT a FROM one ORDER BY a; + } altdb} msg] + lappend v $msg +} {0 {1 2 3 4}} +integrity_check avtrans-4.12 +do_test avtrans-4.98 { + altdb close + execsql { + DROP TABLE one; + DROP TABLE two; + } +} {} +integrity_check avtrans-4.99 + +# Check out the commit/rollback behavior of the database +# +do_test avtrans-5.1 { + execsql {SELECT name FROM sqlite_master WHERE type='table' ORDER BY name} +} {} +do_test avtrans-5.2 { + execsql {BEGIN TRANSACTION} + execsql {SELECT name FROM sqlite_master WHERE type='table' ORDER BY name} +} {} +do_test avtrans-5.3 { + execsql {CREATE TABLE one(a text, b int)} + execsql {SELECT name FROM sqlite_master WHERE type='table' ORDER BY name} +} {one} +do_test avtrans-5.4 { + execsql {SELECT a,b FROM one ORDER BY b} +} {} +do_test avtrans-5.5 { + execsql {INSERT INTO one(a,b) VALUES('hello', 1)} + execsql {SELECT a,b FROM one ORDER BY b} +} {hello 1} +do_test avtrans-5.6 { + execsql {ROLLBACK} + execsql {SELECT name FROM sqlite_master WHERE type='table' ORDER BY name} +} {} +do_test avtrans-5.7 { + set v [catch { + execsql {SELECT a,b FROM one ORDER BY b} + } msg] + lappend v $msg +} {1 {no such table: one}} + +# Test commits and rollbacks of table CREATE TABLEs, CREATE INDEXs +# DROP TABLEs and DROP INDEXs +# +do_test avtrans-5.8 { + execsql { + SELECT name fROM sqlite_master + WHERE type='table' OR type='index' + ORDER BY name + } +} {} +do_test avtrans-5.9 { + execsql { + BEGIN TRANSACTION; + CREATE TABLE t1(a int, b int, c int); + SELECT name fROM sqlite_master + WHERE type='table' OR type='index' + ORDER BY name; + } +} {t1} +do_test avtrans-5.10 { + execsql { + CREATE INDEX i1 ON t1(a); + SELECT name fROM sqlite_master + WHERE type='table' OR type='index' + ORDER BY name; + } +} {i1 t1} +do_test avtrans-5.11 { + execsql { + COMMIT; + SELECT name fROM sqlite_master + WHERE type='table' OR type='index' + ORDER BY name; + } +} {i1 t1} +do_test avtrans-5.12 { + execsql { + BEGIN TRANSACTION; + CREATE TABLE t2(a int, b int, c int); + CREATE INDEX i2a ON t2(a); + CREATE INDEX i2b ON t2(b); + DROP TABLE t1; + SELECT name fROM sqlite_master + WHERE type='table' OR type='index' + ORDER BY name; + } +} {i2a i2b t2} +do_test avtrans-5.13 { + execsql { + ROLLBACK; + SELECT name fROM sqlite_master + WHERE type='table' OR type='index' + ORDER BY name; + } +} {i1 t1} +do_test avtrans-5.14 { + execsql { + BEGIN TRANSACTION; + DROP INDEX i1; + SELECT name fROM sqlite_master + WHERE type='table' OR type='index' + ORDER BY name; + } +} {t1} +do_test avtrans-5.15 { + execsql { + ROLLBACK; + SELECT name fROM sqlite_master + WHERE type='table' OR type='index' + ORDER BY name; + } +} {i1 t1} +do_test avtrans-5.16 { + execsql { + BEGIN TRANSACTION; + DROP INDEX i1; + CREATE TABLE t2(x int, y int, z int); + CREATE INDEX i2x ON t2(x); + CREATE INDEX i2y ON t2(y); + INSERT INTO t2 VALUES(1,2,3); + SELECT name fROM sqlite_master + WHERE type='table' OR type='index' + ORDER BY name; + } +} {i2x i2y t1 t2} +do_test avtrans-5.17 { + execsql { + COMMIT; + SELECT name fROM sqlite_master + WHERE type='table' OR type='index' + ORDER BY name; + } +} {i2x i2y t1 t2} +do_test avtrans-5.18 { + execsql { + SELECT * FROM t2; + } +} {1 2 3} +do_test avtrans-5.19 { + execsql { + SELECT x FROM t2 WHERE y=2; + } +} {1} +do_test avtrans-5.20 { + execsql { + BEGIN TRANSACTION; + DROP TABLE t1; + DROP TABLE t2; + SELECT name fROM sqlite_master + WHERE type='table' OR type='index' + ORDER BY name; + } +} {} +do_test avtrans-5.21 { + set r [catch {execsql { + SELECT * FROM t2 + }} msg] + lappend r $msg +} {1 {no such table: t2}} +do_test avtrans-5.22 { + execsql { + ROLLBACK; + SELECT name fROM sqlite_master + WHERE type='table' OR type='index' + ORDER BY name; + } +} {i2x i2y t1 t2} +do_test avtrans-5.23 { + execsql { + SELECT * FROM t2; + } +} {1 2 3} +integrity_check avtrans-5.23 + + +# Try to DROP and CREATE tables and indices with the same name +# within a transaction. Make sure ROLLBACK works. +# +do_test avtrans-6.1 { + execsql2 { + INSERT INTO t1 VALUES(1,2,3); + BEGIN TRANSACTION; + DROP TABLE t1; + CREATE TABLE t1(p,q,r); + ROLLBACK; + SELECT * FROM t1; + } +} {a 1 b 2 c 3} +do_test avtrans-6.2 { + execsql2 { + INSERT INTO t1 VALUES(1,2,3); + BEGIN TRANSACTION; + DROP TABLE t1; + CREATE TABLE t1(p,q,r); + COMMIT; + SELECT * FROM t1; + } +} {} +do_test avtrans-6.3 { + execsql2 { + INSERT INTO t1 VALUES(1,2,3); + SELECT * FROM t1; + } +} {p 1 q 2 r 3} +do_test avtrans-6.4 { + execsql2 { + BEGIN TRANSACTION; + DROP TABLE t1; + CREATE TABLE t1(a,b,c); + INSERT INTO t1 VALUES(4,5,6); + SELECT * FROM t1; + DROP TABLE t1; + } +} {a 4 b 5 c 6} +do_test avtrans-6.5 { + execsql2 { + ROLLBACK; + SELECT * FROM t1; + } +} {p 1 q 2 r 3} +do_test avtrans-6.6 { + execsql2 { + BEGIN TRANSACTION; + DROP TABLE t1; + CREATE TABLE t1(a,b,c); + INSERT INTO t1 VALUES(4,5,6); + SELECT * FROM t1; + DROP TABLE t1; + } +} {a 4 b 5 c 6} +do_test avtrans-6.7 { + catchsql { + COMMIT; + SELECT * FROM t1; + } +} {1 {no such table: t1}} + +# Repeat on a table with an automatically generated index. +# +do_test avtrans-6.10 { + execsql2 { + CREATE TABLE t1(a unique,b,c); + INSERT INTO t1 VALUES(1,2,3); + BEGIN TRANSACTION; + DROP TABLE t1; + CREATE TABLE t1(p unique,q,r); + ROLLBACK; + SELECT * FROM t1; + } +} {a 1 b 2 c 3} +do_test avtrans-6.11 { + execsql2 { + BEGIN TRANSACTION; + DROP TABLE t1; + CREATE TABLE t1(p unique,q,r); + COMMIT; + SELECT * FROM t1; + } +} {} +do_test avtrans-6.12 { + execsql2 { + INSERT INTO t1 VALUES(1,2,3); + SELECT * FROM t1; + } +} {p 1 q 2 r 3} +do_test avtrans-6.13 { + execsql2 { + BEGIN TRANSACTION; + DROP TABLE t1; + CREATE TABLE t1(a unique,b,c); + INSERT INTO t1 VALUES(4,5,6); + SELECT * FROM t1; + DROP TABLE t1; + } +} {a 4 b 5 c 6} +do_test avtrans-6.14 { + execsql2 { + ROLLBACK; + SELECT * FROM t1; + } +} {p 1 q 2 r 3} +do_test avtrans-6.15 { + execsql2 { + BEGIN TRANSACTION; + DROP TABLE t1; + CREATE TABLE t1(a unique,b,c); + INSERT INTO t1 VALUES(4,5,6); + SELECT * FROM t1; + DROP TABLE t1; + } +} {a 4 b 5 c 6} +do_test avtrans-6.16 { + catchsql { + COMMIT; + SELECT * FROM t1; + } +} {1 {no such table: t1}} + +do_test avtrans-6.20 { + execsql { + CREATE TABLE t1(a integer primary key,b,c); + INSERT INTO t1 VALUES(1,-2,-3); + INSERT INTO t1 VALUES(4,-5,-6); + SELECT * FROM t1; + } +} {1 -2 -3 4 -5 -6} +do_test avtrans-6.21 { + execsql { + CREATE INDEX i1 ON t1(b); + SELECT * FROM t1 WHERE b<1; + } +} {4 -5 -6 1 -2 -3} +do_test avtrans-6.22 { + execsql { + BEGIN TRANSACTION; + DROP INDEX i1; + SELECT * FROM t1 WHERE b<1; + ROLLBACK; + } +} {1 -2 -3 4 -5 -6} +do_test avtrans-6.23 { + execsql { + SELECT * FROM t1 WHERE b<1; + } +} {4 -5 -6 1 -2 -3} +do_test avtrans-6.24 { + execsql { + BEGIN TRANSACTION; + DROP TABLE t1; + ROLLBACK; + SELECT * FROM t1 WHERE b<1; + } +} {4 -5 -6 1 -2 -3} + +do_test avtrans-6.25 { + execsql { + BEGIN TRANSACTION; + DROP INDEX i1; + CREATE INDEX i1 ON t1(c); + SELECT * FROM t1 WHERE b<1; + } +} {1 -2 -3 4 -5 -6} +do_test avtrans-6.26 { + execsql { + SELECT * FROM t1 WHERE c<1; + } +} {4 -5 -6 1 -2 -3} +do_test avtrans-6.27 { + execsql { + ROLLBACK; + SELECT * FROM t1 WHERE b<1; + } +} {4 -5 -6 1 -2 -3} +do_test avtrans-6.28 { + execsql { + SELECT * FROM t1 WHERE c<1; + } +} {1 -2 -3 4 -5 -6} + +# The following repeats steps 6.20 through 6.28, but puts a "unique" +# constraint the first field of the table in order to generate an +# automatic index. +# +do_test avtrans-6.30 { + execsql { + BEGIN TRANSACTION; + DROP TABLE t1; + CREATE TABLE t1(a int unique,b,c); + COMMIT; + INSERT INTO t1 VALUES(1,-2,-3); + INSERT INTO t1 VALUES(4,-5,-6); + SELECT * FROM t1 ORDER BY a; + } +} {1 -2 -3 4 -5 -6} +do_test avtrans-6.31 { + execsql { + CREATE INDEX i1 ON t1(b); + SELECT * FROM t1 WHERE b<1; + } +} {4 -5 -6 1 -2 -3} +do_test avtrans-6.32 { + execsql { + BEGIN TRANSACTION; + DROP INDEX i1; + SELECT * FROM t1 WHERE b<1; + ROLLBACK; + } +} {1 -2 -3 4 -5 -6} +do_test avtrans-6.33 { + execsql { + SELECT * FROM t1 WHERE b<1; + } +} {4 -5 -6 1 -2 -3} +do_test avtrans-6.34 { + execsql { + BEGIN TRANSACTION; + DROP TABLE t1; + ROLLBACK; + SELECT * FROM t1 WHERE b<1; + } +} {4 -5 -6 1 -2 -3} + +do_test avtrans-6.35 { + execsql { + BEGIN TRANSACTION; + DROP INDEX i1; + CREATE INDEX i1 ON t1(c); + SELECT * FROM t1 WHERE b<1; + } +} {1 -2 -3 4 -5 -6} +do_test avtrans-6.36 { + execsql { + SELECT * FROM t1 WHERE c<1; + } +} {4 -5 -6 1 -2 -3} +do_test avtrans-6.37 { + execsql { + DROP INDEX i1; + SELECT * FROM t1 WHERE c<1; + } +} {1 -2 -3 4 -5 -6} +do_test avtrans-6.38 { + execsql { + ROLLBACK; + SELECT * FROM t1 WHERE b<1; + } +} {4 -5 -6 1 -2 -3} +do_test avtrans-6.39 { + execsql { + SELECT * FROM t1 WHERE c<1; + } +} {1 -2 -3 4 -5 -6} +integrity_check avtrans-6.40 + +ifcapable !floatingpoint { + finish_test + return +} + +# Test to make sure rollback restores the database back to its original +# state. +# +do_test avtrans-7.1 { + execsql {BEGIN} + for {set i 0} {$i<1000} {incr i} { + set r1 [expr {rand()}] + set r2 [expr {rand()}] + set r3 [expr {rand()}] + execsql "INSERT INTO t2 VALUES($r1,$r2,$r3)" + } + execsql {COMMIT} + set ::checksum [execsql {SELECT md5sum(x,y,z) FROM t2}] + set ::checksum2 [ + execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master} + ] + execsql {SELECT count(*) FROM t2} +} {1001} +do_test avtrans-7.2 { + execsql {SELECT md5sum(x,y,z) FROM t2} +} $checksum +do_test avtrans-7.2.1 { + execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master} +} $checksum2 +do_test avtrans-7.3 { + execsql { + BEGIN; + DELETE FROM t2; + ROLLBACK; + SELECT md5sum(x,y,z) FROM t2; + } +} $checksum +do_test avtrans-7.4 { + execsql { + BEGIN; + INSERT INTO t2 SELECT * FROM t2; + ROLLBACK; + SELECT md5sum(x,y,z) FROM t2; + } +} $checksum +do_test avtrans-7.5 { + execsql { + BEGIN; + DELETE FROM t2; + ROLLBACK; + SELECT md5sum(x,y,z) FROM t2; + } +} $checksum +do_test avtrans-7.6 { + execsql { + BEGIN; + INSERT INTO t2 SELECT * FROM t2; + ROLLBACK; + SELECT md5sum(x,y,z) FROM t2; + } +} $checksum +do_test avtrans-7.7 { + execsql { + BEGIN; + CREATE TABLE t3 AS SELECT * FROM t2; + INSERT INTO t2 SELECT * FROM t3; + ROLLBACK; + SELECT md5sum(x,y,z) FROM t2; + } +} $checksum +do_test avtrans-7.8 { + execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master} +} $checksum2 +ifcapable tempdb { + do_test avtrans-7.9 { + execsql { + BEGIN; + CREATE TEMP TABLE t3 AS SELECT * FROM t2; + INSERT INTO t2 SELECT * FROM t3; + ROLLBACK; + SELECT md5sum(x,y,z) FROM t2; + } + } $checksum +} +do_test avtrans-7.10 { + execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master} +} $checksum2 +ifcapable tempdb { + do_test avtrans-7.11 { + execsql { + BEGIN; + CREATE TEMP TABLE t3 AS SELECT * FROM t2; + INSERT INTO t2 SELECT * FROM t3; + DROP INDEX i2x; + DROP INDEX i2y; + CREATE INDEX i3a ON t3(x); + ROLLBACK; + SELECT md5sum(x,y,z) FROM t2; + } + } $checksum +} +do_test avtrans-7.12 { + execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master} +} $checksum2 +ifcapable tempdb { + do_test avtrans-7.13 { + execsql { + BEGIN; + DROP TABLE t2; + ROLLBACK; + SELECT md5sum(x,y,z) FROM t2; + } + } $checksum +} +do_test avtrans-7.14 { + execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master} +} $checksum2 +integrity_check avtrans-7.15 + +# Arrange for another process to begin modifying the database but abort +# and die in the middle of the modification. Then have this process read +# the database. This process should detect the journal file and roll it +# back. Verify that this happens correctly. +# +set fd [open test.tcl w] +puts $fd { + sqlite3 db test.db + db eval { + PRAGMA default_cache_size=20; + BEGIN; + CREATE TABLE t3 AS SELECT * FROM t2; + DELETE FROM t2; + } + sqlite_abort +} +close $fd +do_test avtrans-8.1 { + catch {exec [info nameofexec] test.tcl} + execsql {SELECT md5sum(x,y,z) FROM t2} +} $checksum +do_test avtrans-8.2 { + execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master} +} $checksum2 +integrity_check avtrans-8.3 + +# In the following sequence of tests, compute the MD5 sum of the content +# of a table, make lots of modifications to that table, then do a rollback. +# Verify that after the rollback, the MD5 checksum is unchanged. +# +do_test avtrans-9.1 { + execsql { + PRAGMA default_cache_size=10; + } + db close + sqlite3 db test.db + execsql { + BEGIN; + CREATE TABLE t3(x TEXT); + INSERT INTO t3 VALUES(randstr(10,400)); + INSERT INTO t3 VALUES(randstr(10,400)); + INSERT INTO t3 SELECT randstr(10,400) FROM t3; + INSERT INTO t3 SELECT randstr(10,400) FROM t3; + INSERT INTO t3 SELECT randstr(10,400) FROM t3; + INSERT INTO t3 SELECT randstr(10,400) FROM t3; + INSERT INTO t3 SELECT randstr(10,400) FROM t3; + INSERT INTO t3 SELECT randstr(10,400) FROM t3; + INSERT INTO t3 SELECT randstr(10,400) FROM t3; + INSERT INTO t3 SELECT randstr(10,400) FROM t3; + INSERT INTO t3 SELECT randstr(10,400) FROM t3; + COMMIT; + SELECT count(*) FROM t3; + } +} {1024} + +# The following procedure computes a "signature" for table "t3". If +# T3 changes in any way, the signature should change. +# +# This is used to test ROLLBACK. We gather a signature for t3, then +# make lots of changes to t3, then rollback and take another signature. +# The two signatures should be the same. +# +proc signature {} { + return [db eval {SELECT count(*), md5sum(x) FROM t3}] +} + +# Repeat the following group of tests 20 times for quick testing and +# 40 times for full testing. Each iteration of the test makes table +# t3 a little larger, and thus takes a little longer, so doing 40 tests +# is more than 2.0 times slower than doing 20 tests. Considerably more. +# +if {[info exists G(isquick)]} { + set limit 20 +} else { + set limit 40 +} + +# Do rollbacks. Make sure the signature does not change. +# +for {set i 2} {$i<=$limit} {incr i} { + set ::sig [signature] + set cnt [lindex $::sig 0] + if {$i%2==0} { + execsql {PRAGMA fullfsync=ON} + } else { + execsql {PRAGMA fullfsync=OFF} + } + set sqlite_sync_count 0 + set sqlite_fullsync_count 0 + do_test avtrans-9.$i.1-$cnt { + execsql { + BEGIN; + DELETE FROM t3 WHERE random()%10!=0; + INSERT INTO t3 SELECT randstr(10,10)||x FROM t3; + INSERT INTO t3 SELECT randstr(10,10)||x FROM t3; + ROLLBACK; + } + signature + } $sig + do_test avtrans-9.$i.2-$cnt { + execsql { + BEGIN; + DELETE FROM t3 WHERE random()%10!=0; + INSERT INTO t3 SELECT randstr(10,10)||x FROM t3; + DELETE FROM t3 WHERE random()%10!=0; + INSERT INTO t3 SELECT randstr(10,10)||x FROM t3; + ROLLBACK; + } + signature + } $sig + if {$i<$limit} { + do_test avtrans-9.$i.3-$cnt { + execsql { + INSERT INTO t3 SELECT randstr(10,400) FROM t3 WHERE random()%10==0; + } + } {} + if {$tcl_platform(platform)=="unix"} { + do_test avtrans-9.$i.4-$cnt { + expr {$sqlite_sync_count>0} + } 1 + ifcapable pager_pragmas { + do_test avtrans-9.$i.5-$cnt { + expr {$sqlite_fullsync_count>0} + } [expr {$i%2==0}] + } else { + do_test avtrans-9.$i.5-$cnt { + expr {$sqlite_fullsync_count==0} + } {1} + } + } + wal_check_journal_mode avtrans-9.$i-6.$cnt + } + set ::pager_old_format 0 +} +integrity_check avtrans-10.1 +wal_check_journal_mode avtrans-10.2 + +finish_test diff --git a/test/backcompat.test b/test/backcompat.test new file mode 100644 index 0000000..87ffc4b --- /dev/null +++ b/test/backcompat.test @@ -0,0 +1,524 @@ +# 2010 August 19 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing that the current version of SQLite +# is capable of reading and writing databases created by previous +# versions, and vice-versa. +# +# To use this test, old versions of the testfixture process should be +# copied into the working directory alongside the new version. The old +# versions should be named "testfixtureXXX" (or testfixtureXXX.exe on +# windows), where XXX can be any string. +# +# This test file uses the tcl code for controlling a second testfixture +# process located in lock_common.tcl. See the commments in lock_common.tcl +# for documentation of the available commands. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/lock_common.tcl +source $testdir/malloc_common.tcl +source $testdir/bc_common.tcl +db close + +if {"" == [bc_find_binaries backcompat.test]} { + finish_test + return +} + +proc do_backcompat_test {rv bin1 bin2 script} { + + forcedelete test.db + + if {$bin1 != ""} { set ::bc_chan1 [launch_testfixture $bin1] } + set ::bc_chan2 [launch_testfixture $bin2] + + if { $rv } { + proc code2 {tcl} { uplevel #0 $tcl } + if {$bin1 != ""} { proc code2 {tcl} { testfixture $::bc_chan1 $tcl } } + proc code1 {tcl} { testfixture $::bc_chan2 $tcl } + } else { + proc code1 {tcl} { uplevel #0 $tcl } + if {$bin1 != ""} { proc code1 {tcl} { testfixture $::bc_chan1 $tcl } } + proc code2 {tcl} { testfixture $::bc_chan2 $tcl } + } + + proc sql1 sql { code1 [list db eval $sql] } + proc sql2 sql { code2 [list db eval $sql] } + + code1 { sqlite3 db test.db } + code2 { sqlite3 db test.db } + + foreach c {code1 code2} { + $c { + set v [split [db version] .] + if {[llength $v]==3} {lappend v 0} + set ::sqlite_libversion [format \ + "%d%.2d%.2d%.2d" [lindex $v 0] [lindex $v 1] [lindex $v 2] [lindex $v 3] + ] + } + } + + uplevel $script + + catch { code1 { db close } } + catch { code2 { db close } } + catch { close $::bc_chan2 } + catch { close $::bc_chan1 } + + +} + +array set ::incompatible [list] +proc do_allbackcompat_test {script} { + + foreach bin $::BC(binaries) { + set nErr [set_test_counter errors] + foreach dir {0 1} { + + set bintag $bin + regsub {.*testfixture\.} $bintag {} bintag + set bintag [string map {\.exe {}} $bintag] + if {$bintag == ""} {set bintag self} + set ::bcname ".$bintag.$dir." + + rename do_test _do_test + proc do_test {nm sql res} { + set nm [regsub {\.} $nm $::bcname] + uplevel [list _do_test $nm $sql $res] + } + + do_backcompat_test $dir {} $bin $script + + rename do_test {} + rename _do_test do_test + } + if { $nErr < [set_test_counter errors] } { + set ::incompatible([get_version $bin]) 1 + } + } +} + +proc read_file {zFile} { + set zData {} + if {[file exists $zFile]} { + set fd [open $zFile] + fconfigure $fd -translation binary -encoding binary + + if {[file size $zFile]<=$::sqlite_pending_byte || $zFile != "test.db"} { + set zData [read $fd] + } else { + set zData [read $fd $::sqlite_pending_byte] + append zData [string repeat x 512] + seek $fd [expr $::sqlite_pending_byte+512] start + append zData [read $fd] + } + + close $fd + } + return $zData +} +proc write_file {zFile zData} { + set fd [open $zFile w] + fconfigure $fd -translation binary -encoding binary + puts -nonewline $fd $zData + close $fd +} +proc read_file_system {} { + set ret [list] + foreach f {test.db test.db-journal test.db-wal} { lappend ret [read_file $f] } + set ret +} +proc write_file_system {data} { + foreach f {test.db test.db-journal test.db-wal} d $data { + if {[string length $d] == 0} { + forcedelete $f + } else { + write_file $f $d + } + } +} + +#------------------------------------------------------------------------- +# Actual tests begin here. +# +# This first block of tests checks to see that the same database and +# journal files can be used by old and new versions. WAL and wal-index +# files are tested separately below. +# +do_allbackcompat_test { + + # Test that database files are backwards compatible. + # + do_test backcompat-1.1.1 { sql1 { + CREATE TABLE t1(a PRIMARY KEY, b UNIQUE); + INSERT INTO t1 VALUES('abc', 'def'); + } } {} + do_test backcompat-1.1.2 { sql2 { SELECT * FROM t1; } } {abc def} + do_test backcompat-1.1.3 { sql2 { INSERT INTO t1 VALUES('ghi', 'jkl'); } } {} + do_test backcompat-1.1.4 { sql1 { SELECT * FROM t1; } } {abc def ghi jkl} + do_test backcompat-1.1.5 { sql1 { PRAGMA integrity_check } } {ok} + do_test backcompat-1.1.6 { sql2 { PRAGMA integrity_check } } {ok} + + # Test that one version can roll back a hot-journal file left in the + # file-system by the other version. + # + # Each test case is named "backcompat-1.X...", where X is either 0 or + # 1. If it is 0, then the current version creates a journal file that + # the old versions try to read. Otherwise, if X is 1, then the old version + # creates the journal file and we try to read it with the current version. + # + do_test backcompat-1.2.1 { sql1 { + PRAGMA cache_size = 10; + BEGIN; + INSERT INTO t1 VALUES(randomblob(400), randomblob(400)); + INSERT INTO t1 SELECT randomblob(400), randomblob(400) FROM t1; + INSERT INTO t1 SELECT randomblob(400), randomblob(400) FROM t1; + INSERT INTO t1 SELECT randomblob(400), randomblob(400) FROM t1; + INSERT INTO t1 SELECT randomblob(400), randomblob(400) FROM t1; + COMMIT; + } } {} + set cksum1 [sql1 {SELECT md5sum(a), md5sum(b) FROM t1}] + set cksum2 [sql2 {SELECT md5sum(a), md5sum(b) FROM t1}] + do_test backcompat-1.2.2 [list string compare $cksum1 $cksum2] 0 + + do_test backcompat-1.2.3 { sql1 { + BEGIN; + UPDATE t1 SET a = randomblob(500); + } } {} + set data [read_file_system] + + do_test backcompat-1.2.4 { sql1 { COMMIT } } {} + + set same [expr {[sql2 {SELECT md5sum(a), md5sum(b) FROM t1}] == $cksum2}] + do_test backcompat-1.2.5 [list set {} $same] 0 + + code1 { db close } + code2 { db close } + write_file_system $data + code1 { sqlite3 db test.db } + code2 { sqlite3 db test.db } + + set same [expr {[sql2 {SELECT md5sum(a), md5sum(b) FROM t1}] == $cksum2}] + do_test backcompat-1.2.6 [list set {} $same] 1 + + do_test backcompat-1.2.7 { sql1 { PRAGMA integrity_check } } {ok} + do_test backcompat-1.2.8 { sql2 { PRAGMA integrity_check } } {ok} + + do_test backcompat-2.1 { + sql1 { + CREATE TABLE t2(a UNIQUE, b PRIMARY KEY, c UNIQUE); + INSERT INTO t2 VALUES(1,9,5); + INSERT INTO t2 VALUES(5,5,1); + INSERT INTO t2 VALUES(9,1,9); + SELECT * FROM t2 ORDER BY a; + } + } {1 9 5 5 5 1 9 1 9} + do_test backcompat-2.2 { + sql2 { + SELECT * FROM sqlite_master WHERE rootpage=-1; + SELECT * FROM t2 ORDER BY a; + } + } {1 9 5 5 5 1 9 1 9} + do_test backcompat-2.3 { + sql1 { + SELECT * FROM t2 ORDER BY b; + } + } {9 1 9 5 5 1 1 9 5} + do_test backcompat-2.4 { + sql2 { + SELECT * FROM t2 ORDER BY b; + } + } {9 1 9 5 5 1 1 9 5} + do_test backcompat-2.5 { + sql1 { + SELECT * FROM t2 ORDER BY c; + } + } {5 5 1 1 9 5 9 1 9} + do_test backcompat-2.6 { + sql2 { + SELECT * FROM t2 ORDER BY c; + } + } {5 5 1 1 9 5 9 1 9} +} +foreach k [lsort [array names ::incompatible]] { + puts "ERROR: Detected journal incompatibility with version $k" +} +unset ::incompatible + + +#------------------------------------------------------------------------- +# Test that WAL and wal-index files may be shared between different +# SQLite versions. +# +do_allbackcompat_test { + if {[code1 {sqlite3 -version}] >= "3.7.0" + && [code1 {set ::sqlite_options(wal)}] + && [code2 {sqlite3 -version}] >= "3.7.0" + && [code2 {set ::sqlite_options(wal)}] + } { + + do_test backcompat-2.1.1 { sql1 { + PRAGMA journal_mode = WAL; + CREATE TABLE t1(a PRIMARY KEY, b UNIQUE); + INSERT INTO t1 VALUES('I', 1); + INSERT INTO t1 VALUES('II', 2); + INSERT INTO t1 VALUES('III', 3); + SELECT * FROM t1; + } } {wal I 1 II 2 III 3} + do_test backcompat-2.1.2 { sql2 { + SELECT * FROM t1; + } } {I 1 II 2 III 3} + + set data [read_file_system] + code1 {db close} + code2 {db close} + write_file_system $data + code1 {sqlite3 db test.db} + code2 {sqlite3 db test.db} + + # The WAL file now in the file-system was created by the [code1] + # process. Check that the [code2] process can recover the log. + # + do_test backcompat-2.1.3 { sql2 { + SELECT * FROM t1; + } } {I 1 II 2 III 3} + do_test backcompat-2.1.4 { sql1 { + SELECT * FROM t1; + } } {I 1 II 2 III 3} + } +} + +#------------------------------------------------------------------------- +# Test that FTS3 tables may be read/written by different versions of +# SQLite. +# +ifcapable fts3 { + set contents { + CREATE VIRTUAL TABLE t1 USING fts3(a, b); + } + foreach {num doc} { + one "jk zm jk eczkjblu urvysbnykk sk gnl jk ttvgf hmjf" + two "jk bnhc jjrxpjkb mjpavjuhw fibokdry igju jk zm zm xh" + three "wxe ogttbykvt uhzq xr iaf zf urvysbnykk aayxpmve oacaxgjoo mjpavjuhw" + four "gazrt jk ephknonq myjp uenvbm wuvajhwqz jk zm xnxhf nvfasfh" + five "zm aayxpmve csjqxhgj xnxhf xr jk aayxpmve xnxhf zm zm" + six "sokcyf zm ogyavjvv jk zm fibokdry zm jk igju igju" + seven "vgsld bvgimjik xuprtlyle jk akmikrqyt jk aayxpmve hkfoudzftq ddjj" + eight "zm uhzq ovkyevlgv zk uenvbm csjqxhgj jk vgsld pgybs jk" + nine "zm agmckuiu zexh fibokdry jk uhzq bu tugflixoex xnxhf sk" + } { + append contents "INSERT INTO t1 VALUES('$num', '$doc');" + } + do_allbackcompat_test { + if {[code1 {set ::sqlite_options(fts3)}] + && [code2 {set ::sqlite_options(fts3)}] + } { + + do_test backcompat-3.1 { sql1 $contents } {} + + foreach {n q} { + 1 "SELECT * FROM t1 ORDER BY a, b" + 2 "SELECT rowid FROM t1 WHERE a MATCH 'five'" + 3 "SELECT * FROM t1 WHERE a MATCH 'five'" + 4 "SELECT offsets(t1) FROM t1 WHERE t1 MATCH 'jk'" + 5 "SELECT offsets(t1) FROM t1 WHERE t1 MATCH 'tug* OR eight'" + } { + do_test backcompat-3.2 [list sql1 $q] [sql2 $q] + } + + do_test backcompat-3.3 { sql1 { + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + } } {} + + foreach {n q} { + 1 "SELECT * FROM t1 ORDER BY a, b" + 2 "SELECT rowid FROM t1 WHERE a MATCH 'five'" + 3 "SELECT * FROM t1 WHERE a MATCH 'five'" + 4 "SELECT offsets(t1) FROM t1 WHERE t1 MATCH 'jk'" + 5 "SELECT offsets(t1) FROM t1 WHERE t1 MATCH 'tug* OR eight'" + } { + do_test backcompat-3.4 [list sql1 $q] [sql2 $q] + } + + set alphabet "a b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3 4" + for {set i 0} {$i < 900} {incr i} { + set term "[lindex $alphabet [expr $i/30]][lindex $alphabet [expr $i%30]] " + sql1 "INSERT INTO t1 VALUES($i, '[string repeat $term 14]')" + } + + foreach {n q} { + 1 "SELECT * FROM t1 ORDER BY a, b" + 2 "SELECT rowid FROM t1 WHERE a MATCH 'five'" + 3 "SELECT * FROM t1 WHERE a MATCH 'five'" + 4 "SELECT offsets(t1) FROM t1 WHERE t1 MATCH 'jk'" + 5 "SELECT offsets(t1) FROM t1 WHERE t1 MATCH 'tug* OR eight'" + + 6 "SELECT offsets(t1) FROM t1 WHERE t1 MATCH 'aa'" + 7 "SELECT offsets(t1) FROM t1 WHERE t1 MATCH '44'" + 8 "SELECT offsets(t1) FROM t1 WHERE t1 MATCH 'a*'" + } { + do_test backcompat-3.5 [list sql1 $q] [sql2 $q] + } + + do_test backcompat-3.6 { + sql1 "SELECT optimize(t1) FROM t1 LIMIT 1" + } {{Index optimized}} + + foreach {n q} { + 1 "SELECT * FROM t1 ORDER BY a, b" + 2 "SELECT rowid FROM t1 WHERE a MATCH 'five'" + 3 "SELECT * FROM t1 WHERE a MATCH 'five'" + 4 "SELECT offsets(t1) FROM t1 WHERE t1 MATCH 'jk'" + 5 "SELECT offsets(t1) FROM t1 WHERE t1 MATCH 'tug* OR eight'" + + 6 "SELECT offsets(t1) FROM t1 WHERE t1 MATCH 'aa'" + 7 "SELECT offsets(t1) FROM t1 WHERE t1 MATCH '44'" + 8 "SELECT offsets(t1) FROM t1 WHERE t1 MATCH 'a*'" + } { + do_test backcompat-3.7 [list sql1 $q] [sql2 $q] + } + + # Now test that an incremental merge can be started by one version + # and finished by another. And that the integrity-check still + # passes. + do_test backcompat-3.8 { + sql1 { + DROP TABLE IF EXISTS t1; + DROP TABLE IF EXISTS t2; + CREATE TABLE t1(docid, words); + CREATE VIRTUAL TABLE t2 USING fts3(words); + } + code1 [list source $testdir/genesis.tcl] + code1 { fts_kjv_genesis } + sql1 { + INSERT INTO t2 SELECT words FROM t1; + INSERT INTO t2 SELECT words FROM t1; + INSERT INTO t2 SELECT words FROM t1; + INSERT INTO t2 SELECT words FROM t1; + INSERT INTO t2 SELECT words FROM t1; + INSERT INTO t2 SELECT words FROM t1; + SELECT level, group_concat(idx, ' ') FROM t2_segdir GROUP BY level; + } + } {0 {0 1 2 3 4 5}} + + if {[code1 { set ::sqlite_libversion }] >=3071200 + && [code2 { set ::sqlite_libversion }] >=3071200 + } { + if {[code1 { set ::sqlite_libversion }]<3120000} { + set res {0 {0 1} 1 0} + } else { + set res {1 0} + } + + do_test backcompat-3.9 { + sql1 { INSERT INTO t2(t2) VALUES('merge=100,4'); } + sql2 { INSERT INTO t2(t2) VALUES('merge=100,4'); } + sql1 { INSERT INTO t2(t2) VALUES('merge=100,4'); } + sql2 { INSERT INTO t2(t2) VALUES('merge=2500,4'); } + sql2 { + SELECT level, group_concat(idx, ' ') FROM t2_segdir GROUP BY level; + } + } $res + + do_test backcompat-3.10 { + sql1 { INSERT INTO t2(t2) VALUES('integrity-check') } + sql2 { INSERT INTO t2(t2) VALUES('integrity-check') } + } {} + } + } + } +} + +#------------------------------------------------------------------------- +# Test that Rtree tables may be read/written by different versions of +# SQLite. +# +ifcapable rtree { + set contents { + CREATE VIRTUAL TABLE t1 USING rtree(id, x1, x2, y1, y2); + } + foreach {id x1 x2 y1 y2} { + 1 -47.64 43.87 33.86 34.42 2 -21.51 17.32 2.05 31.04 + 3 -43.67 -38.33 -19.79 3.43 4 32.41 35.16 9.12 19.82 + 5 33.28 34.87 14.78 28.26 6 49.31 116.59 -9.87 75.09 + 7 -14.93 34.51 -17.64 64.09 8 -43.05 23.43 -1.19 69.44 + 9 44.79 133.56 28.09 80.30 10 -2.66 81.47 -41.38 -10.46 + 11 -42.89 -3.54 15.76 71.63 12 -3.50 84.96 -11.64 64.95 + 13 -45.69 26.25 11.14 55.06 14 -44.09 11.23 17.52 44.45 + 15 36.23 133.49 -19.38 53.67 16 -17.89 81.54 14.64 50.61 + 17 -41.97 -24.04 -39.43 28.95 18 -5.85 7.76 -6.38 47.02 + 19 18.82 27.10 42.82 100.09 20 39.17 113.45 26.14 73.47 + 21 22.31 103.17 49.92 106.05 22 -43.06 40.38 -1.75 76.08 + 23 2.43 57.27 -14.19 -3.83 24 -47.57 -4.35 8.93 100.06 + 25 -37.47 49.14 -29.11 8.81 26 -7.86 75.72 49.34 107.42 + 27 1.53 45.49 20.36 49.74 28 -48.48 32.54 28.81 54.45 + 29 2.67 39.77 -4.05 13.67 30 4.11 62.88 -47.44 -5.72 + 31 -21.47 51.75 37.25 116.09 32 45.59 111.37 -6.43 43.64 + 33 35.23 48.29 23.54 113.33 34 16.61 68.35 -14.69 65.97 + 35 13.98 16.60 48.66 102.87 36 19.74 23.84 31.15 77.27 + 37 -27.61 24.43 7.96 94.91 38 -34.77 12.05 -22.60 -6.29 + 39 -25.83 8.71 -13.48 -12.53 40 -17.11 -1.01 18.06 67.89 + 41 14.13 71.72 -3.78 39.25 42 23.75 76.00 -16.30 8.23 + 43 -39.15 28.63 38.12 125.88 44 48.62 86.09 36.49 102.95 + 45 -31.39 -21.98 2.52 89.78 46 5.65 56.04 15.94 89.10 + 47 18.28 95.81 46.46 143.08 48 30.93 102.82 -20.08 37.36 + 49 -20.78 -3.48 -5.58 35.46 50 49.85 90.58 -24.48 46.29 + } { + if {$x1 >= $x2 || $y1 >= $y2} { error "$x1 $x2 $y1 $y2" } + append contents "INSERT INTO t1 VALUES($id, $x1, $x2, $y1, $y2);" + } + set queries { + 1 "SELECT id FROM t1 WHERE x1>10 AND x2<44" + 2 "SELECT id FROM t1 WHERE y1<100" + 3 "SELECT id FROM t1 WHERE y1<100 AND x1>0" + 4 "SELECT id FROM t1 WHERE y1>10 AND x1>0 AND x2<50 AND y2<550" + } + do_allbackcompat_test { + if {[code1 {set ::sqlite_options(fts3)}] + && [code2 {set ::sqlite_options(fts3)}] + } { + + do_test backcompat-4.1 { sql1 $contents } {} + + foreach {n q} $::queries { + do_test backcompat-4.2.$n [list sql1 $q] [sql2 $q] + } + + do_test backcompat-4.3 { sql1 { + INSERT INTO t1 SELECT id+100, x1+10.0, x2+10.0, y1-10.0, y2-10.0 FROM t1; + } } {} + + foreach {n q} $::queries { + do_test backcompat-4.4.$n [list sql1 $q] [sql2 $q] + } + + do_test backcompat-4.5 { sql2 { + INSERT INTO t1 SELECT id+200, x1+20.0, x2+20.0, y1-20.0, y2-20.0 FROM t1; + } } {} + + foreach {n q} $::queries { + do_test backcompat-4.6.$n [list sql1 $q] [sql2 $q] + } + + } + } +} + +finish_test diff --git a/test/backup.test b/test/backup.test new file mode 100644 index 0000000..ad1a383 --- /dev/null +++ b/test/backup.test @@ -0,0 +1,1004 @@ +# 2009 January 30 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing the sqlite3_backup_XXX API. +# +# $Id: backup.test,v 1.11 2009/06/05 17:09:12 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +do_not_use_codec + +#--------------------------------------------------------------------- +# Test organization: +# +# backup-1.*: Warm-body tests. +# +# backup-2.*: Test backup under various conditions. To and from in-memory +# databases. To and from empty/populated databases. etc. +# +# backup-3.*: Verify that the locking-page (pending byte page) is handled. +# +# backup-4.*: Test various error conditions. +# +# backup-5.*: Test the source database being modified during a backup. +# +# backup-6.*: Test the backup_remaining() and backup_pagecount() APIs. +# +# backup-7.*: Test SQLITE_BUSY and SQLITE_LOCKED errors. +# +# backup-8.*: Test multiple simultaneous backup operations. +# +# backup-9.*: Test that passing a negative argument to backup_step() is +# interpreted as "copy the whole file". +# +# backup-10.*: Test writing the source database mid backup. +# + +proc data_checksum {db file} { $db one "SELECT md5sum(a, b) FROM ${file}.t1" } +proc test_contents {name db1 file1 db2 file2} { + $db2 eval {select * from sqlite_master} + $db1 eval {select * from sqlite_master} + set checksum [data_checksum $db2 $file2] + uplevel [list do_test $name [list data_checksum $db1 $file1] $checksum] +} + +do_test backup-1.1 { + execsql { + BEGIN; + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a, b); + INSERT INTO t1 VALUES(1, randstr(1000,1000)); + INSERT INTO t1 VALUES(2, randstr(1000,1000)); + INSERT INTO t1 VALUES(3, randstr(1000,1000)); + INSERT INTO t1 VALUES(4, randstr(1000,1000)); + INSERT INTO t1 VALUES(5, randstr(1000,1000)); + COMMIT; + } +} {} + +# Sanity check to verify that the [test_contents] proc works. +# +test_contents backup-1.2 db main db main + +# Check that it is possible to create and finish backup operations. +# +do_test backup-1.3.1 { + delete_file test2.db + sqlite3 db2 test2.db + sqlite3_backup B db2 main db main +} {B} +do_test backup-1.3.2 { + B finish +} {SQLITE_OK} +do_test backup-1.3.3 { + info commands B +} {} + +# Simplest backup operation. Backup test.db to test2.db. test2.db is +# initially empty. test.db uses the default page size. +# +do_test backup-1.4.1 { + sqlite3_backup B db2 main db main +} {B} +do_test backup-1.4.2 { + B step 200 +} {SQLITE_DONE} +do_test backup-1.4.3 { + B finish +} {SQLITE_OK} +do_test backup-1.4.4 { + info commands B +} {} +test_contents backup-1.4.5 db2 main db main +db close +db2 close +# +# End of backup-1.* tests. +#--------------------------------------------------------------------- + + +#--------------------------------------------------------------------- +# The following tests, backup-2.*, are based on the following procedure: +# +# 1) Populate the source database. +# 2) Populate the destination database. +# 3) Run the backup to completion. (backup-2.*.1) +# 4) Integrity check the destination db. (backup-2.*.2) +# 5) Check that the contents of the destination db is the same as that +# of the source db. (backup-2.*.3) +# +# The test is run with all possible combinations of the following +# input parameters, except that if the destination is an in-memory +# database, the only page size tested is 1024 bytes (the same as the +# source page-size). +# +# * Source database is an in-memory database, OR +# * Source database is a file-backed database. +# +# * Target database is an in-memory database, OR +# * Target database is a file-backed database. +# +# * Destination database is a main file, OR +# * Destination database is an attached file, OR +# * Destination database is a temp database. +# +# * Target database is empty (zero bytes), OR +# * Target database is larger than the source, OR +# * Target database is smaller than the source. +# +# * Target database page-size is the same as the source, OR +# * Target database page-size is larger than the source, OR +# * Target database page-size is smaller than the source. +# +# * Each call to step copies a single page, OR +# * A single call to step copies the entire source database. +# +set iTest 1 +foreach zSrcFile {test.db :memory:} { +foreach zDestFile {test2.db :memory:} { +foreach zOpenScript [list { + sqlite3 db $zSrcFile + sqlite3 db2 $zSrcFile + db2 eval "ATTACH '$zDestFile' AS bak" + set db_dest db2 + set file_dest bak +} { + sqlite3 db $zSrcFile + sqlite3 db2 $zDestFile + set db_dest db2 + set file_dest main +} { + sqlite3 db $zSrcFile + sqlite3 db2 $zDestFile + set db_dest db2 + set file_dest temp +}] { +foreach rows_dest {0 3 10} { +foreach pgsz_dest {512 1024 2048 4096} { +foreach nPagePerStep {1 200} { + + # Open the databases. + catch { delete_file test.db } + catch { delete_file test2.db } + eval $zOpenScript + + # Set to true if copying to an in-memory destination. Copying to an + # in-memory destination is only possible if the initial destination + # page size is the same as the source page size (in this case 1024 bytes). + # + set isMemDest [expr { $zDestFile eq ":memory:" || $file_dest eq "temp" }] + + if 0 { + puts -nonewline "Test $iTest: src=$zSrcFile dest=$zDestFile" + puts -nonewline " (as $db_dest.$file_dest)" + puts -nonewline " rows_dest=$rows_dest pgsz_dest=$pgsz_dest" + puts "" + } + + if { $isMemDest==0 || $pgsz_dest==1024 || $rows_dest==0 } { + + # Set up the content of the source database. + execsql { + PRAGMA page_size = 1024; + BEGIN; + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a, b); + INSERT INTO t1 VALUES(1, randstr(1000,1000)); + INSERT INTO t1 VALUES(2, randstr(1000,1000)); + INSERT INTO t1 VALUES(3, randstr(1000,1000)); + INSERT INTO t1 VALUES(4, randstr(1000,1000)); + INSERT INTO t1 VALUES(5, randstr(1000,1000)); + COMMIT; + } + + + + # Set up the content of the target database. + execsql "PRAGMA ${file_dest}.page_size = ${pgsz_dest}" $db_dest + if {$rows_dest != 0} { + execsql " + BEGIN; + CREATE TABLE ${file_dest}.t1(a, b); + CREATE INDEX ${file_dest}.i1 ON t1(a, b); + " $db_dest + for {set ii 0} {$ii < $rows_dest} {incr ii} { + execsql " + INSERT INTO ${file_dest}.t1 VALUES(1, randstr(1000,1000)) + " $db_dest + } + execsql COMMIT $db_dest + } + + # Backup the source database. + do_test backup-2.$iTest.1 { + sqlite3_backup B $db_dest $file_dest db main + while {[B step $nPagePerStep]=="SQLITE_OK"} {} + B finish + } {SQLITE_OK} + + # Run integrity check on the backup. + do_test backup-2.$iTest.2 { + execsql "PRAGMA ${file_dest}.integrity_check" $db_dest + } {ok} + + test_contents backup-2.$iTest.3 db main $db_dest $file_dest + + } + + db close + catch {db2 close} + incr iTest + +} } } } } } +# +# End of backup-2.* tests. +#--------------------------------------------------------------------- + +#--------------------------------------------------------------------- +# These tests, backup-3.*, ensure that nothing goes wrong if either +# the source or destination database are large enough to include the +# the locking-page (the page that contains the range of bytes that +# the locks are applied to). These tests assume that the pending +# byte is at offset 0x00010000 (64KB offset), as set by tester.tcl, +# not at the 1GB offset as it usually is. +# +# The test procedure is as follows (same procedure as used for +# the backup-2.* tests): +# +# 1) Populate the source database. +# 2) Populate the destination database. +# 3) Run the backup to completion. (backup-3.*.1) +# 4) Integrity check the destination db. (backup-3.*.2) +# 5) Check that the contents of the destination db is the same as that +# of the source db. (backup-3.*.3) +# +# The test procedure is run with the following parameters varied: +# +# * Source database includes pending-byte page. +# * Source database does not include pending-byte page. +# +# * Target database includes pending-byte page. +# * Target database does not include pending-byte page. +# +# * Target database page-size is the same as the source, OR +# * Target database page-size is larger than the source, OR +# * Target database page-size is smaller than the source. +# +set iTest 1 +foreach nSrcPg {10 64 65 66 100} { +foreach nDestRow {10 100} { +foreach nDestPgsz {512 1024 2048 4096} { + + catch { delete_file test.db } + catch { delete_file test2.db } + sqlite3 db test.db + sqlite3 db2 test2.db + + # Set up the content of the two databases. + # + execsql { PRAGMA page_size = 1024 } + execsql "PRAGMA page_size = $nDestPgsz" db2 + foreach db {db db2} { + execsql { + BEGIN; + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a, b); + COMMIT; + } $db + } + while {[file size test.db]/1024 < $nSrcPg} { + execsql { INSERT INTO t1 VALUES($ii, randstr(200,200)) } + } + + for {set ii 0} {$ii < $nDestRow} {incr ii} { + execsql { INSERT INTO t1 VALUES($ii, randstr(1000,1000)) } db2 + } + + # Backup the source database. + do_test backup-3.$iTest.1 { + sqlite3_backup B db main db2 main + while {[B step 10]=="SQLITE_OK"} {} + B finish + } {SQLITE_OK} + + # Run integrity check on the backup. + do_test backup-3.$iTest.2 { + execsql "PRAGMA integrity_check" db2 + } {ok} + + test_contents backup-3.$iTest.3 db main db2 main + + db close + db2 close + incr iTest +} +} +} + +#-------------------------------------------------------------------- +do_test backup-3.$iTest.1 { + catch { forcedelete test.db } + catch { forcedelete test2.db } + sqlite3 db test.db + set iTab 1 + + db eval { PRAGMA page_size = 512 } + while {[file size test.db] <= $::sqlite_pending_byte} { + db eval "CREATE TABLE t${iTab}(a, b, c)" + incr iTab + } + + sqlite3 db2 test2.db + db2 eval { PRAGMA page_size = 4096 } + while {[file size test2.db] < $::sqlite_pending_byte} { + db2 eval "CREATE TABLE t${iTab}(a, b, c)" + incr iTab + } + + sqlite3_backup B db2 main db main + B step -1 +} {SQLITE_DONE} + +do_test backup-3.$iTest.2 { + B finish +} {SQLITE_OK} + +# +# End of backup-3.* tests. +#--------------------------------------------------------------------- + + +#--------------------------------------------------------------------- +# The following tests, backup-4.*, test various error conditions: +# +# backup-4.1.*: Test invalid database names. +# +# backup-4.2.*: Test that the source database cannot be detached while +# a backup is in progress. +# +# backup-4.3.*: Test that the source database handle cannot be closed +# while a backup is in progress. +# +# backup-4.4.*: Test an attempt to specify the same handle for the +# source and destination databases. +# +# backup-4.5.*: Test that an in-memory destination with a different +# page-size to the source database is an error. +# +sqlite3 db test.db +sqlite3 db2 test2.db + +do_test backup-4.1.1 { + catch { sqlite3_backup B db aux db2 main } +} {1} +do_test backup-4.1.2 { + sqlite3_errmsg db +} {unknown database aux} +do_test backup-4.1.3 { + catch { sqlite3_backup B db main db2 aux } +} {1} +do_test backup-4.1.4 { + sqlite3_errmsg db +} {unknown database aux} + +do_test backup-4.2.1 { + catch { forcedelete test3.db } + catch { forcedelete test4.db } + execsql { + ATTACH 'test3.db' AS aux1; + CREATE TABLE aux1.t1(a, b); + } + execsql { + ATTACH 'test4.db' AS aux2; + CREATE TABLE aux2.t2(a, b); + } db2 + sqlite3_backup B db aux1 db2 aux2 +} {B} +do_test backup-4.2.2 { + catchsql { DETACH aux2 } db2 +} {1 {database aux2 is locked}} +do_test backup-4.2.3 { + B step 50 +} {SQLITE_DONE} +do_test backup-4.2.4 { + B finish +} {SQLITE_OK} + +do_test backup-4.3.1 { + sqlite3_backup B db aux1 db2 aux2 +} {B} +do_test backup-4.3.2 { + db2 cache flush + sqlite3_close db2 +} {SQLITE_BUSY} +do_test backup-4.3.3 { + sqlite3_errmsg db2 +} {unable to close due to unfinalized statements or unfinished backups} +do_test backup-4.3.4 { + B step 50 +} {SQLITE_DONE} +do_test backup-4.3.5 { + B finish +} {SQLITE_OK} + +do_test backup-4.4.1 { + set rc [catch {sqlite3_backup B db main db aux1}] + list $rc [sqlite3_errcode db] [sqlite3_errmsg db] +} {1 SQLITE_ERROR {source and destination must be distinct}} +db close +db2 close + +do_test backup-4.5.1 { + catch { forcedelete test.db } + sqlite3 db test.db + sqlite3 db2 :memory: + execsql { + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 2); + } + execsql { + PRAGMA page_size = 4096; + CREATE TABLE t2(a, b); + INSERT INTO t2 VALUES(3, 4); + } db2 + sqlite3_backup B db2 main db main +} {B} +do_test backup-4.5.2 { + B step 5000 +} {SQLITE_READONLY} +do_test backup-4.5.3 { + B finish +} {SQLITE_READONLY} + +db close +db2 close +# +# End of backup-4.* tests. +#--------------------------------------------------------------------- + +#--------------------------------------------------------------------- +# The following tests, backup-5.*, test that the backup works properly +# when the source database is modified during the backup. Test cases +# are organized as follows: +# +# backup-5.x.1.*: Nothing special. Modify the database mid-backup. +# +# backup-5.x.2.*: Modify the database mid-backup so that one or more +# pages are written out due to cache stress. Then +# rollback the transaction. +# +# backup-5.x.3.*: Database is vacuumed. +# +# backup-5.x.4.*: Database is vacuumed and the page-size modified. +# +# backup-5.x.5.*: Database is shrunk via incr-vacuum. +# +# Each test is run three times, in the following configurations: +# +# 1) Backing up file-to-file. The writer writes via an external pager. +# 2) Backing up file-to-file. The writer writes via the same pager as +# is used by the backup operation. +# 3) Backing up memory-to-file. +# +set iTest 0 +forcedelete bak.db-wal +foreach {writer file} {db test.db db3 test.db db :memory:} { + incr iTest + catch { delete_file bak.db } + sqlite3 db2 bak.db + catch { delete_file $file } + sqlite3 db $file + sqlite3 db3 $file + + do_test backup-5.$iTest.1.1 { + execsql { + BEGIN; + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a, b); + INSERT INTO t1 VALUES(1, randstr(1000,1000)); + INSERT INTO t1 VALUES(2, randstr(1000,1000)); + INSERT INTO t1 VALUES(3, randstr(1000,1000)); + INSERT INTO t1 VALUES(4, randstr(1000,1000)); + INSERT INTO t1 VALUES(5, randstr(1000,1000)); + COMMIT; + } + expr {[execsql {PRAGMA page_count}] > 10} + } {1} + do_test backup-5.$iTest.1.2 { + sqlite3_backup B db2 main db main + B step 5 + } {SQLITE_OK} + do_test backup-5.$iTest.1.3 { + execsql { UPDATE t1 SET a = a + 1 } $writer + B step 50 + } {SQLITE_DONE} + do_test backup-5.$iTest.1.4 { + B finish + } {SQLITE_OK} + integrity_check backup-5.$iTest.1.5 db2 + test_contents backup-5.$iTest.1.6 db main db2 main + + do_test backup-5.$iTest.2.1 { + execsql { + PRAGMA cache_size = 10; + BEGIN; + INSERT INTO t1 SELECT '', randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT '', randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT '', randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT '', randstr(1000,1000) FROM t1; + COMMIT; + } + } {} + do_test backup-5.$iTest.2.2 { + sqlite3_backup B db2 main db main + B step 50 + } {SQLITE_OK} + do_test backup-5.$iTest.2.3 { + execsql { + BEGIN; + UPDATE t1 SET a = a + 1; + ROLLBACK; + } $writer + B step 5000 + } {SQLITE_DONE} + do_test backup-5.$iTest.2.4 { + B finish + } {SQLITE_OK} + integrity_check backup-5.$iTest.2.5 db2 + test_contents backup-5.$iTest.2.6 db main db2 main + + do_test backup-5.$iTest.3.1 { + execsql { UPDATE t1 SET b = randstr(1000,1000) } + } {} + do_test backup-5.$iTest.3.2 { + sqlite3_backup B db2 main db main + B step 50 + } {SQLITE_OK} + do_test backup-5.$iTest.3.3 { + execsql { VACUUM } $writer + B step 5000 + } {SQLITE_DONE} + do_test backup-5.$iTest.3.4 { + B finish + } {SQLITE_OK} + integrity_check backup-5.$iTest.3.5 db2 + test_contents backup-5.$iTest.3.6 db main db2 main + + do_test backup-5.$iTest.4.1 { + execsql { UPDATE t1 SET b = randstr(1000,1000) } + } {} + do_test backup-5.$iTest.4.2 { + sqlite3_backup B db2 main db main + B step 50 + } {SQLITE_OK} + do_test backup-5.$iTest.4.3 { + execsql { + PRAGMA page_size = 2048; + VACUUM; + } $writer + B step 5000 + } {SQLITE_DONE} + do_test backup-5.$iTest.4.4 { + B finish + } {SQLITE_OK} + integrity_check backup-5.$iTest.4.5 db2 + test_contents backup-5.$iTest.4.6 db main db2 main + + catch {db close} + catch {db2 close} + catch {db3 close} + catch { delete_file bak.db } + sqlite3 db2 bak.db + catch { delete_file $file } + sqlite3 db $file + sqlite3 db3 $file + do_test backup-5.$iTest.5.1 { + execsql { + PRAGMA auto_vacuum = incremental; + BEGIN; + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a, b); + INSERT INTO t1 VALUES(1, randstr(1000,1000)); + INSERT INTO t1 VALUES(2, randstr(1000,1000)); + INSERT INTO t1 VALUES(3, randstr(1000,1000)); + INSERT INTO t1 VALUES(4, randstr(1000,1000)); + INSERT INTO t1 VALUES(5, randstr(1000,1000)); + COMMIT; + } + } {} + do_test backup-5.$iTest.5.2 { + sqlite3_backup B db2 main db main + B step 8 + } {SQLITE_OK} + do_test backup-5.$iTest.5.3 { + execsql { + DELETE FROM t1; + PRAGMA incremental_vacuum; + } $writer + B step 50 + } {SQLITE_DONE} + do_test backup-5.$iTest.5.4 { + B finish + } {SQLITE_OK} + integrity_check backup-5.$iTest.5.5 db2 + test_contents backup-5.$iTest.5.6 db main db2 main + catch {db close} + catch {db2 close} + catch {db3 close} +} +# +# End of backup-5.* tests. +#--------------------------------------------------------------------- + +#--------------------------------------------------------------------- +# Test the sqlite3_backup_remaining() and backup_pagecount() APIs. +# +do_test backup-6.1 { + catch { forcedelete test.db } + catch { forcedelete test2.db } + sqlite3 db test.db + sqlite3 db2 test2.db + execsql { + BEGIN; + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a, b); + INSERT INTO t1 VALUES(1, randstr(1000,1000)); + INSERT INTO t1 VALUES(2, randstr(1000,1000)); + INSERT INTO t1 VALUES(3, randstr(1000,1000)); + INSERT INTO t1 VALUES(4, randstr(1000,1000)); + INSERT INTO t1 VALUES(5, randstr(1000,1000)); + COMMIT; + } +} {} +do_test backup-6.2 { + set nTotal [expr {[file size test.db]/1024}] + sqlite3_backup B db2 main db main + B step 1 +} {SQLITE_OK} +do_test backup-6.3 { + B pagecount +} $nTotal +do_test backup-6.4 { + B remaining +} [expr $nTotal-1] +do_test backup-6.5 { + B step 5 + list [B remaining] [B pagecount] +} [list [expr $nTotal-6] $nTotal] +do_test backup-6.6 { + execsql { CREATE TABLE t2(a PRIMARY KEY, b) } + B step 1 + list [B remaining] [B pagecount] +} [list [expr $nTotal-5] [expr $nTotal+2]] + +do_test backup-6.X { + B finish +} {SQLITE_OK} + +catch {db close} +catch {db2 close} + +#--------------------------------------------------------------------- +# Test cases backup-7.* test that SQLITE_BUSY and SQLITE_LOCKED errors +# are returned correctly: +# +# backup-7.1.*: Source database is externally locked (return SQLITE_BUSY). +# +# backup-7.2.*: Attempt to step the backup process while a +# write-transaction is underway on the source pager (return +# SQLITE_LOCKED). +# +# backup-7.3.*: Destination database is externally locked (return SQLITE_BUSY). +# +do_test backup-7.0 { + catch { forcedelete test.db } + catch { forcedelete test2.db } + sqlite3 db2 test2.db + sqlite3 db test.db + execsql { + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a, b); + INSERT INTO t1 VALUES(1, randstr(1000,1000)); + INSERT INTO t1 SELECT a+ 1, randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT a+ 2, randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT a+ 4, randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT a+ 8, randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT a+16, randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT a+32, randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT a+64, randstr(1000,1000) FROM t1; + } +} {} + +do_test backup-7.1.1 { + sqlite3_backup B db2 main db main + B step 5 +} {SQLITE_OK} +do_test backup-7.1.2 { + sqlite3 db3 test.db + execsql { BEGIN EXCLUSIVE } db3 + B step 5 +} {SQLITE_BUSY} +do_test backup-7.1.3 { + execsql { ROLLBACK } db3 + B step 5 +} {SQLITE_OK} +do_test backup-7.2.1 { + execsql { + BEGIN; + INSERT INTO t1 VALUES(1, 4); + } +} {} +do_test backup-7.2.2 { + B step 5000 +} {SQLITE_BUSY} +do_test backup-7.2.3 { + execsql { ROLLBACK } + B step 5000 +} {SQLITE_DONE} +do_test backup-7.2.4 { + B finish +} {SQLITE_OK} +test_contents backup-7.2.5 db main db2 main +integrity_check backup-7.3.6 db2 + +do_test backup-7.3.1 { + db2 close + db3 close + forcedelete test2.db + sqlite3 db2 test2.db + sqlite3 db3 test2.db + + sqlite3_backup B db2 main db main + execsql { BEGIN ; CREATE TABLE t2(a, b); } db3 + + B step 5 +} {SQLITE_BUSY} +do_test backup-7.3.2 { + execsql { COMMIT } db3 + B step 5000 +} {SQLITE_DONE} +do_test backup-7.3.3 { + B finish +} {SQLITE_OK} +test_contents backup-7.3.4 db main db2 main +integrity_check backup-7.3.5 db2 +catch { db2 close } +catch { db3 close } + +#----------------------------------------------------------------------- +# The following tests, backup-8.*, test attaching multiple backup +# processes to the same source database. Also, reading from the source +# database while a read transaction is active. +# +# These tests reuse the database "test.db" left over from backup-7.*. +# +do_test backup-8.1 { + catch { forcedelete test2.db } + catch { forcedelete test3.db } + sqlite3 db2 test2.db + sqlite3 db3 test3.db + + sqlite3_backup B2 db2 main db main + sqlite3_backup B3 db3 main db main + list [B2 finish] [B3 finish] +} {SQLITE_OK SQLITE_OK} +do_test backup-8.2 { + sqlite3_backup B3 db3 main db main + sqlite3_backup B2 db2 main db main + list [B2 finish] [B3 finish] +} {SQLITE_OK SQLITE_OK} +do_test backup-8.3 { + sqlite3_backup B2 db2 main db main + sqlite3_backup B3 db3 main db main + B2 step 5 +} {SQLITE_OK} +do_test backup-8.4 { + execsql { + BEGIN; + SELECT * FROM sqlite_master; + } + B3 step 5 +} {SQLITE_OK} +do_test backup-8.5 { + list [B3 step 5000] [B3 finish] +} {SQLITE_DONE SQLITE_OK} +do_test backup-8.6 { + list [B2 step 5000] [B2 finish] +} {SQLITE_DONE SQLITE_OK} +test_contents backup-8.7 db main db2 main +test_contents backup-8.8 db main db3 main +do_test backup-8.9 { + execsql { PRAGMA lock_status } +} {main shared temp closed} +do_test backup-8.10 { + execsql COMMIT +} {} +catch { db2 close } +catch { db3 close } + +#----------------------------------------------------------------------- +# The following tests, backup-9.*, test that: +# +# * Passing 0 as an argument to sqlite3_backup_step() means no pages +# are backed up (backup-9.1.*), and +# * Passing a negative value as an argument to sqlite3_backup_step() means +# all pages are backed up (backup-9.2.*). +# +# These tests reuse the database "test.db" left over from backup-7.*. +# +do_test backup-9.1.1 { + sqlite3 db2 test2.db + sqlite3_backup B db2 main db main + B step 1 +} {SQLITE_OK} +do_test backup-9.1.2 { + set nRemaining [B remaining] + expr {$nRemaining>100} +} {1} +do_test backup-9.1.3 { + B step 0 +} {SQLITE_OK} +do_test backup-9.1.4 { + B remaining +} $nRemaining + +do_test backup-9.2.1 { + B step -1 +} {SQLITE_DONE} +do_test backup-9.2.2 { + B remaining +} {0} +do_test backup-9.2.3 { + B finish +} {SQLITE_OK} +catch {db2 close} + +ifcapable memorymanage { + db close + forcedelete test.db + forcedelete bak.db + + sqlite3 db test.db + sqlite3 db2 test.db + sqlite3 db3 bak.db + + do_test backup-10.1.1 { + execsql { + BEGIN; + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, randstr(1000,1000)); + INSERT INTO t1 VALUES(2, randstr(1000,1000)); + INSERT INTO t1 VALUES(3, randstr(1000,1000)); + INSERT INTO t1 VALUES(4, randstr(1000,1000)); + INSERT INTO t1 VALUES(5, randstr(1000,1000)); + CREATE INDEX i1 ON t1(a, b); + COMMIT; + } + } {} + do_test backup-10.1.2 { + sqlite3_backup B db3 main db2 main + B step 5 + } {SQLITE_OK} + do_test backup-10.1.3 { + execsql { + UPDATE t1 SET b = randstr(500,500); + } + } {} + sqlite3_release_memory [expr 1024*1024] + do_test backup-10.1.3 { + B step 50 + } {SQLITE_DONE} + do_test backup-10.1.4 { + B finish + } {SQLITE_OK} + do_test backup-10.1.5 { + execsql { PRAGMA integrity_check } db3 + } {ok} + + db2 close + db3 close +} + + +#----------------------------------------------------------------------- +# Test that if the database is written to via the same database handle being +# used as the source by a backup operation: +# +# 10.1.*: If the db is in-memory, the backup is restarted. +# 10.2.*: If the db is a file, the backup is not restarted. +# +db close +forcedelete test.db test.db-journal +foreach {tn file rc} { + 1 test.db SQLITE_DONE + 2 :memory: SQLITE_OK +} { + do_test backup-10.$tn.1 { + sqlite3 db $file + execsql { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b BLOB); + BEGIN; + INSERT INTO t1 VALUES(NULL, randomblob(200)); + INSERT INTO t1 SELECT NULL, randomblob(200) FROM t1; + INSERT INTO t1 SELECT NULL, randomblob(200) FROM t1; + INSERT INTO t1 SELECT NULL, randomblob(200) FROM t1; + INSERT INTO t1 SELECT NULL, randomblob(200) FROM t1; + INSERT INTO t1 SELECT NULL, randomblob(200) FROM t1; + INSERT INTO t1 SELECT NULL, randomblob(200) FROM t1; + INSERT INTO t1 SELECT NULL, randomblob(200) FROM t1; + INSERT INTO t1 SELECT NULL, randomblob(200) FROM t1; + COMMIT; + SELECT count(*) FROM t1; + } + } {256} + + do_test backup-10.$tn.2 { + set pgs [execsql {pragma page_count}] + expr {$pgs > 50 && $pgs < 75} + } {1} + + do_test backup-10.$tn.3 { + forcedelete bak.db bak.db-journal + sqlite3 db2 bak.db + sqlite3_backup B db2 main db main + B step 50 + } {SQLITE_OK} + + do_test backup-10.$tn.4 { + execsql { UPDATE t1 SET b = randomblob(200) WHERE a IN (1, 250) } + } {} + + do_test backup-10.$tn.5 { + B step 50 + } $rc + + do_test backup-10.$tn.6 { + B finish + } {SQLITE_OK} + + db2 close +} + +# 2021-01-31 https://sqlite.org/forum/forumpost/8b39fbf3e7 +# +do_test backup-11.1 { + sqlite3 db1 :memory: + sqlite3 db2 :memory: + sqlite3_backup B db1 main db2 temp + B finish +} {SQLITE_OK} +db1 close +db2 close + +#------------------------------------------------------------------------- +do_test backup-12.1 { + sqlite3 db1 :memory: + sqlite3 db2 :memory: + db1 eval { + PRAGMA page_size = 8192; + CREATE TABLE t1(x); + } + db2 eval { + PRAGMA page_size = 1024; + CREATE TABLE t2(x); + } + + sqlite3_backup B db1 main db2 temp + B step 100 + B finish +} {SQLITE_READONLY} + + + + +finish_test diff --git a/test/backup2.test b/test/backup2.test new file mode 100644 index 0000000..1822e2d --- /dev/null +++ b/test/backup2.test @@ -0,0 +1,187 @@ +# 2009 February 4 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing the "backup" and "restore" methods +# of the TCL interface - methods which are based on the +# sqlite3_backup_XXX API. +# +# $Id: backup2.test,v 1.4 2009/04/07 14:14:23 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +do_not_use_codec + +ifcapable !trigger||!view { finish_test ; return } + +# Fill a database with test data. +# +do_test backup2-1 { + db eval { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(randstr(8000,8000)); + INSERT INTO t1 VALUES(randstr(8000,8000)); + INSERT INTO t1 VALUES(randstr(8000,8000)); + INSERT INTO t1 VALUES(randstr(8000,8000)); + INSERT INTO t1 VALUES(randstr(8000,8000)); + CREATE VIEW v1 AS SELECT substr(x,10,10) FROM t1; + CREATE TABLE t2(a,b); + INSERT INTO t2 VALUES(1,2); + INSERT INTO t2 VALUES(2,4); + INSERT INTO t2 SELECT a+2, (a+2)*2 FROM t2; + INSERT INTO t2 SELECT a+4, (a+4)*2 FROM t2; + INSERT INTO t2 SELECT a+8, (a+8)*2 FROM t2; + INSERT INTO t2 SELECT a+16, (a+16)*2 FROM t2; + INSERT INTO t2 SELECT a+32, (a+32)*2 FROM t2; + INSERT INTO t2 SELECT a+64, (a+64)*2 FROM t2; + INSERT INTO t2 SELECT a+128, (a+128)*2 FROM t2; + CREATE INDEX t2i1 ON t2(a,b); + CREATE TRIGGER r1 AFTER INSERT ON t2 BEGIN + SELECT 'hello'; + END; + ANALYZE; + PRAGMA integrity_check; + } +} {ok} + +# Remember a check-sum on the database file. +# +unset -nocomplain cksum +set cksum [dbcksum db main] + +# Make a backup of the test data. Verify that the backup copy +# is identical to the original. +# +do_test backup2-2 { + forcedelete bu1.db + db backup bu1.db + sqlite3 db2 bu1.db + dbcksum db2 main +} $cksum + +# Delete the original. Restore from backup. Verify the content is +# unchanged. +# +do_test backup2-3.1 { + db close + forcedelete test.db test.db-journal + sqlite3 db test.db + db2 eval {BEGIN EXCLUSIVE} + set rc [catch {db restore bu1.db} res] + lappend rc $res + db2 eval {ROLLBACK} + set rc +} {1 {restore failed: source database busy}} +do_test backup2-3.2 { + db close + forcedelete test.db test.db-journal + sqlite3 db test.db + db restore bu1.db + dbcksum db main +} $cksum + +# Use alternative databases - other than "main". +# +do_test backup2-4 { + db restore temp bu1.db + dbcksum db temp +} $cksum +do_test backup2-5 { + db2 close + forcedelete bu1.db bu2.db + db backup temp bu2.db + sqlite3 db2 bu2.db + dbcksum db2 main +} $cksum + +# Try to backup to a readonly file. +# +do_test backup2-6 { + db2 close + catch {file attributes bu2.db -permissions r--------} + catch {file attributes bu2.db -readonly 1} + set rc [catch {db backup temp bu2.db} res] + lappend rc $res +} {1 {backup failed: attempt to write a readonly database}} + +# Try to backup to something that is not a database file. +# +do_test backup2-7 { + catch {file attributes bu2.db -readonly 0} + catch {file attributes bu2.db -permissions rw-------} + set out [open bu2.db w] + puts $out "This is not a valid database file" + close $out + set rc [catch {db backup temp bu2.db} res] + lappend rc $res +} {1 {backup failed: file is not a database}} + +# Try to backup database that does not exist +# +do_test backup2-8 { + forcedelete bu1.db + set rc [catch {db backup aux1 bu1.db} res] + lappend rc $res +} {1 {backup failed: unknown database aux1}} + +# Invalid syntax on the backup method +# +do_test backup2-9 { + set rc [catch {db backup} res] + lappend rc $res +} {1 {wrong # args: should be "db backup ?DATABASE? FILENAME"}} + +# Try to restore from an unreadable file. +# +if {$tcl_platform(platform)=="windows"} { + set msg {cannot open source database: unable to open database file} +} elseif {[string match *BSD $tcl_platform(os)]} { + set msg {} +} else { + set msg {cannot open source database: disk I/O error} +} +do_test backup2-10 { + forcedelete bu3.db + file mkdir bu3.db + set rc [catch {db restore temp bu3.db} res] + if {[string match *BSD $tcl_platform(os)]} { set res "" } + list $rc $res +} [list 1 $msg] + +# Try to restore from something that is not a database file. +# +do_test backup2-11 { + set rc [catch {db restore temp bu2.db} res] + lappend rc $res +} {1 {restore failed: file is not a database}} + +# Try to restore a database that does not exist +# +do_test backup2-12 { + set rc [catch {db restore aux1 bu2.db} res] + lappend rc $res +} {1 {restore failed: unknown database aux1}} +do_test backup2-13 { + forcedelete bu4.db + set rc [catch {db restore bu4.db} res] + lappend rc $res +} {1 {cannot open source database: unable to open database file}} + +# Invalid syntax on the restore method +# +do_test backup2-14 { + set rc [catch {db restore} res] + lappend rc $res +} {1 {wrong # args: should be "db restore ?DATABASE? FILENAME"}} + +forcedelete bu1.db bu2.db bu3.db bu4.db + +finish_test diff --git a/test/backup4.test b/test/backup4.test new file mode 100644 index 0000000..2756995 --- /dev/null +++ b/test/backup4.test @@ -0,0 +1,108 @@ +# 2012 October 13 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# The tests in this file verify that if an empty database (zero bytes in +# size) is used as the source of a backup operation, the final destination +# database is one page in size. +# +# The destination must consist of at least one page as truncating a +# database file to zero bytes is equivalent to resetting the database +# schema cookie and change counter. Doing that could cause other clients +# to become confused and continue using out-of-date cache data. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix backup4 + +# The codec logic does not work for zero-length database files. A database +# file must contain at least one page in order to be recognized as an +# encrypted database. +do_not_use_codec + +#------------------------------------------------------------------------- +# At one point this test was failing because [db] was using an out of +# date schema in test case 1.2. +# +do_execsql_test 1.0 { + CREATE TABLE t1(x, y, UNIQUE(x, y)); + INSERT INTO t1 VALUES('one', 'two'); + SELECT * FROM t1 WHERE x='one'; + PRAGMA integrity_check; +} {one two ok} + +do_test 1.1 { + sqlite3 db1 :memory: + db1 backup test.db + sqlite3 db1 test.db + db1 eval { + CREATE TABLE t1(x, y); + INSERT INTO t1 VALUES('one', 'two'); + } + db1 close +} {} + +do_execsql_test 1.2 { + SELECT * FROM t1 WHERE x='one'; + PRAGMA integrity_check; +} {one two ok} + +db close +forcedelete test.db +forcedelete test.db2 +sqlite3 db test.db + +#------------------------------------------------------------------------- +# Test that if the source is zero bytes, the destination database +# consists of a single page only. +# +do_execsql_test 2.1 { + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a, b); +} +do_test 2.2 { file size test.db } [expr $AUTOVACUUM ? 4096 : 3072] + +do_test 2.3 { + sqlite3 db1 test.db2 + db1 backup test.db + db1 close + file size test.db +} {1024} + +do_test 2.4 { file size test.db2 } 0 + +db close +forcedelete test.db +forcedelete test.db2 +sqlite3 db test.db + +#------------------------------------------------------------------------- +# Test that if the destination has a page-size larger than the implicit +# page-size of the source, the final destination database still consists +# of a single page. +# +do_execsql_test 3.1 { + PRAGMA page_size = 4096; + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a, b); +} +do_test 3.2 { file size test.db } [expr $AUTOVACUUM ? 16384 : 12288] + +do_test 3.3 { + sqlite3 db1 test.db2 + db1 backup test.db + db1 close + file size test.db +} {1024} + +do_test 3.4 { file size test.db2 } 0 + +finish_test diff --git a/test/backup5.test b/test/backup5.test new file mode 100644 index 0000000..c789adf --- /dev/null +++ b/test/backup5.test @@ -0,0 +1,65 @@ +# 2014 November 13 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix backup5 + +forcedelete test2.db + +do_execsql_test 1.0 { + CREATE TABLE t1(a, b); + CREATE TABLE t2(a, b); + INSERT INTO t2 VALUES(1, 1); + INSERT INTO t2 VALUES(2, 2); + INSERT INTO t2 VALUES(3, 3); +} + +do_test 1.1 { + forcecopy test.db test.db2 + db eval { + DROP TABLE t2; + INSERT INTO t1 VALUES(zeroblob(1000), zeroblob(1000)); + INSERT INTO t1 VALUES(randomblob(1000), randomblob(1000)); + } +} {} + +do_test 1.2 { + sqlite3 db2 test.db2 + set stmt [sqlite3_prepare_v2 db2 "SELECT * FROM t2" -1 dummy] + sqlite3_step $stmt +} {SQLITE_ROW} + +do_test 1.3 { + list [catch { sqlite3_backup B db2 main db main } msg] $msg +} {1 {sqlite3_backup_init() failed}} + +do_test 1.4 { + sqlite3_errmsg db2 +} {destination database is in use} + +do_test 1.5 { + sqlite3_reset $stmt + sqlite3_backup B db2 main db main + B step 200 + B finish +} {SQLITE_OK} + +do_test 1.6 { + list [sqlite3_step $stmt] [sqlite3_finalize $stmt] +} {SQLITE_ERROR SQLITE_ERROR} + +do_test 1.7 { + sqlite3_errmsg db2 +} {no such table: t2} + +finish_test diff --git a/test/backup_ioerr.test b/test/backup_ioerr.test new file mode 100644 index 0000000..ca3fd32 --- /dev/null +++ b/test/backup_ioerr.test @@ -0,0 +1,286 @@ +# 2009 January 30 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing the handling of IO errors by the +# sqlite3_backup_XXX APIs. +# +# $Id: backup_ioerr.test,v 1.3 2009/04/10 18:41:01 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +proc data_checksum {db file} { + $db one "SELECT md5sum(a, b) FROM ${file}.t1" +} +proc test_contents {name db1 file1 db2 file2} { + $db2 eval {select * from sqlite_master} + $db1 eval {select * from sqlite_master} + set checksum [data_checksum $db2 $file2] + uplevel [list do_test $name [list data_checksum $db1 $file1] $checksum] +} + +#-------------------------------------------------------------------- +# This proc creates a database of approximately 290 pages. Depending +# on whether or not auto-vacuum is configured. Test cases backup_ioerr-1.* +# verify nothing more than this assumption. +# +proc populate_database {db {xtra_large 0}} { + execsql { + BEGIN; + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, randstr(1000,1000)); + INSERT INTO t1 SELECT a+ 1, randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT a+ 2, randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT a+ 4, randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT a+ 8, randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT a+16, randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT a+32, randstr(1000,1000) FROM t1; + CREATE INDEX i1 ON t1(b); + COMMIT; + } $db + if {$xtra_large} { + execsql { INSERT INTO t1 SELECT a+64, randstr(1000,1000) FROM t1 } $db + } +} +do_test backup_ioerr-1.1 { + populate_database db + set nPage [expr {[file size test.db] / 1024}] + expr {$nPage>130 && $nPage<160} +} {1} +do_test backup_ioerr-1.2 { + expr {[file size test.db] > $sqlite_pending_byte} +} {1} +do_test backup_ioerr-1.3 { + db close + forcedelete test.db +} {} + +# Turn off IO error simulation. +# +proc clear_ioerr_simulation {} { + set ::sqlite_io_error_hit 0 + set ::sqlite_io_error_hardhit 0 + set ::sqlite_io_error_pending 0 + set ::sqlite_io_error_persist 0 +} + +#-------------------------------------------------------------------- +# The following procedure runs with SQLite's IO error simulation +# enabled. +# +# 1) Start with a reasonably sized database. One that includes the +# pending-byte (locking) page. +# +# 2) Open a backup process. Set the cache-size for the destination +# database to 10 pages only. +# +# 3) Step the backup process N times to partially backup the database +# file. If an IO error is reported, then the backup process is +# concluded with a call to backup_finish(). +# +# If an IO error occurs, verify that: +# +# * the call to backup_step() returns an SQLITE_IOERR_XXX error code. +# +# * after the failed call to backup_step() but before the call to +# backup_finish() the destination database handle error code and +# error message remain unchanged. +# +# * the call to backup_finish() returns an SQLITE_IOERR_XXX error code. +# +# * following the call to backup_finish(), the destination database +# handle has been populated with an error code and error message. +# +# 4) Write to the database via the source database connection. Check +# that: +# +# * If an IO error occurs while writing the source database, the +# write operation should report an IO error. The backup should +# proceed as normal. +# +# * If an IO error occurs while updating the backup, the write +# operation should proceed normally. The error should be reported +# from the next call to backup_step() (in step 5 of this test +# procedure). +# +# 5) Step the backup process to finish the backup. If an IO error is +# reported, then the backup process is concluded with a call to +# backup_finish(). +# +# Test that if an IO error occurs, or if one occurred while updating +# the backup database during step 4, then the conditions listed +# under step 3 are all true. +# +# 6) Finish the backup process. +# +# * If the backup succeeds (backup_finish() returns SQLITE_OK), then +# the contents of the backup database should match that of the +# source database. +# +# * If the backup fails (backup_finish() returns other than SQLITE_OK), +# then the contents of the backup database should be as they were +# before the operation was started. +# +# The following factors are varied: +# +# * Destination database is initially larger than the source database, OR +# * Destination database is initially smaller than the source database. +# +# * IO errors are transient, OR +# * IO errors are persistent. +# +# * Destination page-size is smaller than the source. +# * Destination page-size is the same as the source. +# * Destination page-size is larger than the source. +# + +set iTest 1 +foreach bPersist {0 1} { +foreach iDestPagesize {512 1024 4096} { +foreach zSetupBak [list "" {populate_database ddb 1}] { + + incr iTest + set bStop 0 +for {set iError 1} {$bStop == 0} {incr iError} { + # Disable IO error simulation. + clear_ioerr_simulation + + catch { ddb close } + catch { sdb close } + catch { forcedelete test.db } + catch { forcedelete bak.db } + + # Open the source and destination databases. + sqlite3 sdb test.db + sqlite3 ddb bak.db + + # Step 1: Populate the source and destination databases. + populate_database sdb + ddb eval "PRAGMA page_size = $iDestPagesize" + ddb eval "PRAGMA cache_size = 10" + eval $zSetupBak + + # Step 2: Open the backup process. + sqlite3_backup B ddb main sdb main + + # Enable IO error simulation. + set ::sqlite_io_error_pending $iError + set ::sqlite_io_error_persist $bPersist + + # Step 3: Partially backup the database. If an IO error occurs, check + # a few things then skip to the next iteration of the loop. + # + set rc [B step 100] + if {$::sqlite_io_error_hardhit} { + + do_test backup_ioerr-$iTest.$iError.1 { + string match SQLITE_IOERR* $rc + } {1} + do_test backup_ioerr-$iTest.$iError.2 { + list [sqlite3_errcode ddb] [sqlite3_errmsg ddb] + } {SQLITE_OK {not an error}} + + set rc [B finish] + do_test backup_ioerr-$iTest.$iError.3 { + string match SQLITE_IOERR* $rc + } {1} + + do_test backup_ioerr-$iTest.$iError.4 { + sqlite3_errmsg ddb + } {disk I/O error} + + clear_ioerr_simulation + sqlite3 ddb bak.db + integrity_check backup_ioerr-$iTest.$iError.5 ddb + + continue + } + + # No IO error was encountered during step 3. Check that backup_step() + # returned SQLITE_OK before proceding. + do_test backup_ioerr-$iTest.$iError.6 { + expr {$rc eq "SQLITE_OK"} + } {1} + + # Step 4: Write to the source database. + set rc [catchsql { UPDATE t1 SET b = randstr(1000,1000) WHERE a < 50 } sdb] + + if {[lindex $rc 0] && $::sqlite_io_error_persist==0} { + # The IO error occurred while updating the source database. In this + # case the backup should be able to continue. + set rc [B step 5000] + if { $rc != "SQLITE_IOERR_UNLOCK" } { + do_test backup_ioerr-$iTest.$iError.7 { + list [B step 5000] [B finish] + } {SQLITE_DONE SQLITE_OK} + + clear_ioerr_simulation + test_contents backup_ioerr-$iTest.$iError.8 ddb main sdb main + integrity_check backup_ioerr-$iTest.$iError.9 ddb + } else { + do_test backup_ioerr-$iTest.$iError.10 { + B finish + } {SQLITE_IOERR_UNLOCK} + } + + clear_ioerr_simulation + sqlite3 ddb bak.db + integrity_check backup_ioerr-$iTest.$iError.11 ddb + + continue + } + + # Step 5: Finish the backup operation. If an IO error occurs, check that + # it is reported correctly and skip to the next iteration of the loop. + # + set rc [B step 5000] + if {$rc != "SQLITE_DONE"} { + do_test backup_ioerr-$iTest.$iError.12 { + string match SQLITE_IOERR* $rc + } {1} + do_test backup_ioerr-$iTest.$iError.13 { + list [sqlite3_errcode ddb] [sqlite3_errmsg ddb] + } {SQLITE_OK {not an error}} + + set rc [B finish] + do_test backup_ioerr-$iTest.$iError.14 { + string match SQLITE_IOERR* $rc + } {1} + do_test backup_ioerr-$iTest.$iError.15 { + sqlite3_errmsg ddb + } {disk I/O error} + + clear_ioerr_simulation + sqlite3 ddb bak.db + integrity_check backup_ioerr-$iTest.$iError.16 ddb + + continue + } + + # The backup was successfully completed. + # + do_test backup_ioerr-$iTest.$iError.17 { + list [set rc] [B finish] + } {SQLITE_DONE SQLITE_OK} + + clear_ioerr_simulation + sqlite3 sdb test.db + sqlite3 ddb bak.db + + test_contents backup_ioerr-$iTest.$iError.18 ddb main sdb main + integrity_check backup_ioerr-$iTest.$iError.19 ddb + + set bStop [expr $::sqlite_io_error_pending<=0] +}}}} + +catch { sdb close } +catch { ddb close } +finish_test diff --git a/test/backup_malloc.test b/test/backup_malloc.test new file mode 100644 index 0000000..5444a70 --- /dev/null +++ b/test/backup_malloc.test @@ -0,0 +1,119 @@ +# 2009 January 30 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing the handling of OOM errors by the +# sqlite3_backup_XXX APIs. +# +# $Id: backup_malloc.test,v 1.2 2009/02/04 22:46:47 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +source $testdir/malloc_common.tcl + +do_malloc_test backup_malloc-1 -tclprep { + execsql { + PRAGMA cache_size = 10; + BEGIN; + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, randstr(1000,1000)); + INSERT INTO t1 SELECT a+ 1, randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT a+ 2, randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT a+ 4, randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT a+ 8, randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT a+16, randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT a+32, randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT a+64, randstr(1000,1000) FROM t1; + CREATE INDEX i1 ON t1(b); + COMMIT; + } + sqlite3 db2 test2.db + execsql { PRAGMA cache_size = 10 } db2 +} -tclbody { + + # Create a backup object. + # + set rc [catch {sqlite3_backup B db2 main db main}] + if {$rc && [sqlite3_errcode db2] == "SQLITE_NOMEM"} { + error "out of memory" + } + + # Run the backup process some. + # + set rc [B step 50] + if {$rc == "SQLITE_NOMEM" || $rc == "SQLITE_IOERR_NOMEM"} { + error "out of memory" + } + + # Update the database. + # + execsql { UPDATE t1 SET a = a + 1 } + + # Finish doing the backup. + # + set rc [B step 5000] + if {$rc == "SQLITE_NOMEM" || $rc == "SQLITE_IOERR_NOMEM"} { + error "out of memory" + } + + # Finalize the backup. + B finish +} -cleanup { + catch { B finish } + catch { db2 close } +} + +do_malloc_test backup_malloc-2 -tclprep { + sqlite3 db2 test2.db +} -tclbody { + set rc [catch {sqlite3_backup B db2 temp db main}] + set errcode [sqlite3_errcode db2] + if {$rc && ($errcode == "SQLITE_NOMEM" || $errcode == "SQLITE_IOERR_NOMEM")} { + error "out of memory" + } +} -cleanup { + catch { B finish } + db2 close +} + +reset_db +do_execsql_test 3.0 { + PRAGMA page_size = 16384; + BEGIN; + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 2); + COMMIT; +} + +do_faultsim_test 3 -faults oom* -prep { + catch { db close } + catch { db2 close } + + forcedelete test2.db + sqlite3 db2 test2.db + sqlite3 db test.db + sqlite3_backup B db2 main db main +} -body { + + set rc [B step 50] + if {$rc == "SQLITE_NOMEM" || $rc == "SQLITE_IOERR_NOMEM"} { + error "out of memory" + } + +} -test { + faultsim_test_result {0 {}} + faultsim_integrity_check + + # Finalize the backup. + catch { B finish } +} + +finish_test diff --git a/test/badutf.test b/test/badutf.test new file mode 100644 index 0000000..d09c933 --- /dev/null +++ b/test/badutf.test @@ -0,0 +1,143 @@ +# 2007 May 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file checks to make sure SQLite is able to gracefully +# handle malformed UTF-8. +# +# $Id: badutf.test,v 1.2 2007/09/12 17:01:45 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +do_test badutf-1.1 { + db eval {PRAGMA encoding=UTF8} + sqlite3_exec db {SELECT hex('%80') AS x} +} {0 {x 80}} +do_test badutf-1.2 { + sqlite3_exec db {SELECT hex('%81') AS x} +} {0 {x 81}} +do_test badutf-1.3 { + sqlite3_exec db {SELECT hex('%bf') AS x} +} {0 {x BF}} +do_test badutf-1.4 { + sqlite3_exec db {SELECT hex('%c0') AS x} +} {0 {x C0}} +do_test badutf-1.5 { + sqlite3_exec db {SELECT hex('%e0') AS x} +} {0 {x E0}} +do_test badutf-1.6 { + sqlite3_exec db {SELECT hex('%f0') AS x} +} {0 {x F0}} +do_test badutf-1.7 { + sqlite3_exec db {SELECT hex('%ff') AS x} +} {0 {x FF}} + +sqlite3 db2 {} +ifcapable utf16 { + do_test badutf-1.10 { + db2 eval {PRAGMA encoding=UTF16be} + sqlite3_exec db2 {SELECT hex('%80') AS x} + } {0 {x 0080}} + do_test badutf-1.11 { + sqlite3_exec db2 {SELECT hex('%81') AS x} + } {0 {x 0081}} + do_test badutf-1.12 { + sqlite3_exec db2 {SELECT hex('%bf') AS x} + } {0 {x 00BF}} + do_test badutf-1.13 { + sqlite3_exec db2 {SELECT hex('%c0') AS x} + } {0 {x FFFD}} + do_test badutf-1.14 { + sqlite3_exec db2 {SELECT hex('%c1') AS x} + } {0 {x FFFD}} + do_test badutf-1.15 { + sqlite3_exec db2 {SELECT hex('%c0%bf') AS x} + } {0 {x FFFD}} + do_test badutf-1.16 { + sqlite3_exec db2 {SELECT hex('%c1%bf') AS x} + } {0 {x FFFD}} + do_test badutf-1.17 { + sqlite3_exec db2 {SELECT hex('%c3%bf') AS x} + } {0 {x 00FF}} + do_test badutf-1.18 { + sqlite3_exec db2 {SELECT hex('%e0') AS x} + } {0 {x FFFD}} + do_test badutf-1.19 { + sqlite3_exec db2 {SELECT hex('%f0') AS x} + } {0 {x FFFD}} + do_test badutf-1.20 { + sqlite3_exec db2 {SELECT hex('%ff') AS x} + } {0 {x FFFD}} +} + + +ifcapable bloblit { + do_test badutf-2.1 { + sqlite3_exec db {SELECT '%80'=CAST(x'80' AS text) AS x} + } {0 {x 1}} + do_test badutf-2.2 { + sqlite3_exec db {SELECT CAST('%80' AS blob)=x'80' AS x} + } {0 {x 1}} +} + +do_test badutf-3.1 { + sqlite3_exec db {SELECT length('%80') AS x} +} {0 {x 1}} +do_test badutf-3.2 { + sqlite3_exec db {SELECT length('%61%62%63') AS x} +} {0 {x 3}} +do_test badutf-3.3 { + sqlite3_exec db {SELECT length('%7f%80%81') AS x} +} {0 {x 3}} +do_test badutf-3.4 { + sqlite3_exec db {SELECT length('%61%c0') AS x} +} {0 {x 2}} +do_test badutf-3.5 { + sqlite3_exec db {SELECT length('%61%c0%80%80%80%80%80%80%80%80%80%80') AS x} +} {0 {x 2}} +do_test badutf-3.6 { + sqlite3_exec db {SELECT length('%c0%80%80%80%80%80%80%80%80%80%80') AS x} +} {0 {x 1}} +do_test badutf-3.7 { + sqlite3_exec db {SELECT length('%80%80%80%80%80%80%80%80%80%80') AS x} +} {0 {x 10}} +do_test badutf-3.8 { + sqlite3_exec db {SELECT length('%80%80%80%80%80%f0%80%80%80%80') AS x} +} {0 {x 6}} +do_test badutf-3.9 { + sqlite3_exec db {SELECT length('%80%80%80%80%80%f0%80%80%80%ff') AS x} +} {0 {x 7}} + +do_test badutf-4.1 { + sqlite3_exec db {SELECT hex(trim('%80%80%80%f0%80%80%80%ff','%80%ff')) AS x} +} {0 {x F0}} +do_test badutf-4.2 { + sqlite3_exec db {SELECT hex(ltrim('%80%80%80%f0%80%80%80%ff','%80%ff')) AS x} +} {0 {x F0808080FF}} +do_test badutf-4.3 { + sqlite3_exec db {SELECT hex(rtrim('%80%80%80%f0%80%80%80%ff','%80%ff')) AS x} +} {0 {x 808080F0}} +do_test badutf-4.4 { + sqlite3_exec db {SELECT hex(trim('%80%80%80%f0%80%80%80%ff','%ff%80')) AS x} +} {0 {x 808080F0808080FF}} +do_test badutf-4.5 { + sqlite3_exec db {SELECT hex(trim('%ff%80%80%f0%80%80%80%ff','%ff%80')) AS x} +} {0 {x 80F0808080FF}} +do_test badutf-4.6 { + sqlite3_exec db {SELECT hex(trim('%ff%80%f0%80%80%80%ff','%ff%80')) AS x} +} {0 {x F0808080FF}} +do_test badutf-4.7 { + sqlite3_exec db {SELECT hex(trim('%ff%80%f0%80%80%80%ff','%ff%80%80')) AS x} +} {0 {x FF80F0808080FF}} + +db2 close +finish_test diff --git a/test/badutf2.test b/test/badutf2.test new file mode 100644 index 0000000..64a730d --- /dev/null +++ b/test/badutf2.test @@ -0,0 +1,127 @@ +# 2011 March 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file checks to make sure SQLite is able to gracEFully +# handle malformed UTF-8. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +proc utf8_to_ustr2 {s} { + set r "" + foreach i [split $s ""] { + scan $i %c c + append r [format \\u%04.4X $c] + } + set r +} + +proc utf8_to_hstr {in} { + regsub -all -- {(..)} $in {%[format "%s" \1]} out + subst $out +} + +proc utf8_to_xstr {in} { + regsub -all -- {(..)} $in {\\\\x[format "%s" \1]} out + subst $out +} + +proc utf8_to_ustr {in} { + regsub -all -- {(..)} $in {\\\\u[format "%04.4X" 0x\1]} out + subst $out +} + +do_test badutf2-1.0 { + db close + forcedelete test.db + sqlite3 db test.db + db eval "PRAGMA encoding = 'UTF-8'" +} {} + +do_test badutf2-4.0 { + set S [sqlite3_prepare_v2 db "SELECT ?" -1 dummy] + sqlite3_expired $S +} {0} + +foreach { i len uval xstr ustr u2u } { +1 1 00 \x00 {} {} +2 1 01 \x01 "\\u0001" 01 +3 1 3F \x3F "\\u003F" 3F +4 1 7F \x7F "\\u007F" 7F +5 1 80 \x80 "\\u0080" C280 +6 1 C3BF \xFF "\\u00FF" C3BF +7 3 EFBFBD \xEF\xBF\xBD "\\uFFFD" {} +} { + + set hstr [ utf8_to_hstr $uval ] + + ifcapable bloblit { + if {$hstr != "%00"} { + do_test badutf2-2.1.$i { + set sql "SELECT '$hstr'=CAST(x'$uval' AS text) AS x;" + set res [ sqlite3_exec db $sql ] + lindex [ lindex $res 1] 1 + } {1} + do_test badutf2-2.2.$i { + set sql "SELECT CAST('$hstr' AS blob)=x'$uval' AS x;" + set res [ sqlite3_exec db $sql ] + lindex [ lindex $res 1] 1 + } {1} + } + do_test badutf2-2.3.$i { + set sql "SELECT hex(CAST(x'$uval' AS text)) AS x;" + set res [ sqlite3_exec db $sql ] + lindex [ lindex $res 1] 1 + } $uval + do_test badutf2-2.4.$i { + set sql "SELECT hex(CAST(x'$uval' AS text)) AS x;" + set res [ sqlite3_exec db $sql ] + lindex [ lindex $res 1] 1 + } $uval + } + + if {$hstr != "%00"} { + do_test badutf2-3.1.$i { + set sql "SELECT hex('$hstr') AS x;" + set res [ sqlite3_exec db $sql ] + lindex [ lindex $res 1] 1 + } $uval + } + + # Tcl 8.7 and later do automatic bad-utf8 correction for + # characters 0x80 thru 0x9f so test case 5 does not work here. + if {$i==5 && $tcl_version>=8.7} { + # no-op + } else { + do_test badutf2-4.1.$i { + sqlite3_reset $S + sqlite3_bind_text $S 1 $xstr $len + sqlite3_step $S + utf8_to_ustr2 [ sqlite3_column_text $S 0 ] + } $ustr + } + + ifcapable debug { + do_test badutf2-5.1.$i { + utf8_to_utf8 $uval + } $u2u + } + +} + +do_test badutf2-4.2 { + sqlite3_finalize $S +} {SQLITE_OK} + + +finish_test diff --git a/test/basexx1.test b/test/basexx1.test new file mode 100644 index 0000000..947a567 --- /dev/null +++ b/test/basexx1.test @@ -0,0 +1,155 @@ +# 2022 November 22 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix basexx + +if {[catch {load_static_extension db basexx} error]} { + puts "Skipping basexx tests, hit load error: $error" + finish_test; return +} + +# Empty blobs encode to empty strings. +do_execsql_test 100 { + SELECT base64(x'')||base85(x''); +} {{}} + +# Empty strings decode to empty blobs. +do_execsql_test 101 { + SELECT hex(x'01'||base64('')||base85('')||x'02'); +} {0102} + +# Basic base64 encoding +do_execsql_test 102 { + SELECT base64(x'000102030405'); + SELECT base64(x'0001020304'); + SELECT base64(x'00010203'); +} {{AAECAwQF +} {AAECAwQ= +} {AAECAw== +}} + +# Basic base64 decoding with pad chars +do_execsql_test 103 { + SELECT hex(base64('AAECAwQF')); + SELECT hex(base64('AAECAwQ=')); + SELECT hex(base64('AAECAw==')); +} {000102030405 0001020304 00010203} + +# Basic base64 decoding without pad chars and with whitespace +do_execsql_test 104 { + SELECT hex(base64(' AAECAwQF ')); + SELECT hex(base64(' AAECAwQ')); + SELECT hex(base64('AAECAw ')); +} {000102030405 0001020304 00010203} + +# Basic base85 encoding +do_execsql_test 105 { + SELECT base85(x'000102030405'); + SELECT base85(x'0001020304'); + SELECT base85(x'00010203'); +} {{##/2,#2/ +} {##/2,#* +} {##/2, +}} + +# Basic base85 decoding with and without whitespace +do_execsql_test 106 { + SELECT hex(base85('##/2,#2/')); + SELECT hex(base85('##/2,#*')); + SELECT hex(base85('##/2,')); + SELECT hex(base85(' ##/2,#2/ ')); + SELECT hex(base85(' ##/2,#*')); + SELECT hex(base85('##/2, ')); +} {000102030405 0001020304 00010203 000102030405 0001020304 00010203} + +# Round-trip some random blobs. +do_execsql_test 107 { + CREATE TEMP TABLE rb( len int, b blob ) STRICT; + INSERT INTO rb(len) VALUES (1),(2),(3),(4),(5),(150),(151),(152),(153),(1054); + UPDATE rb SET b = randomblob(len); + SELECT len, base64(base64(b))=b, base85(base85(b))=b + FROM rb ORDER BY len; +} {1 1 1 2 1 1 3 1 1 4 1 1 5 1 1 150 1 1 151 1 1 152 1 1 153 1 1 1054 1 1} + +# Same round-trip but with space or junk prepended and/or appended or not. +do_execsql_test 108 { + CREATE TEMP TABLE junk(j text, rank int); + INSERT INTO junk VALUES ('',0),(' ',1),('~',2); + SELECT len, base64(j.j||base64(b)||j.j)=b, base85(j.j||base85(b)||j.j)=b + FROM rb r, junk j WHERE j.rank=(r.len+r.len/25)%3 ORDER BY len; +} {1 1 1 2 1 1 3 1 1 4 1 1 5 1 1 150 1 1 151 1 1 152 1 1 153 1 1 1054 1 1} + +# Exercise the fail-on-too-large result feature. + +set inLimit [sqlite3_limit db SQLITE_LIMIT_LENGTH -1] +sqlite3_limit db SQLITE_LIMIT_LENGTH 1300 + +do_catchsql_test 109 { + SELECT len, base64(b) FROM rb WHERE len>200; +} {1 {blob expanded to base64 too big}} + +do_catchsql_test 110 { + SELECT len, base85(b) FROM rb WHERE len>200; +} {1 {blob expanded to base85 too big}} + +do_catchsql_test 111 { + SELECT length(base85(b))=1335 FROM rb WHERE len=1054; +} {1 {blob expanded to base85 too big}} + +sqlite3_limit db SQLITE_LIMIT_LENGTH $inLimit + +# Exercise is_base85(t) + +do_execsql_test 112 { + SELECT is_base85(' '||base85(x'123456')||char(10)), + is_base85('#$%&*+,-./0123456789:;<=>?@' + ||'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + ||'[\]^_`' + ||'abcdefghijklmnopqrstuvwxyz'), + is_base85('!'), is_base85('"'), is_base85(''''), is_base85('('), + is_base85(')'), is_base85(char(123)), is_base85('|'), is_base85(char(125)), + is_base85('~'), is_base85(char(127)); +} {1 1 0 0 0 0 0 0 0 0 0 0} + +do_execsql_test 113 { + SELECT is_base85(NULL) IS NULL; +} {1} + +do_catchsql_test 114 { + SELECT is_base85(1); +} {1 {is_base85 accepts only text or NULL}} + +do_catchsql_test 115 { + SELECT is_base85(1.1); +} {1 {is_base85 accepts only text or NULL}} + +do_catchsql_test 116 { + SELECT is_base85(x'00'); +} {1 {is_base85 accepts only text or NULL}} + +# Round-trip many bigger random blobs. + +do_execsql_test 117 { + CREATE TABLE bs(b blob, num); + INSERT INTO bs SELECT randomblob(4000 + n%3), n + FROM ( + WITH RECURSIVE seq(n) AS ( + VALUES(1) UNION ALL SELECT n+1 + FROM seq WHERE n<100 + ) SELECT n FROM seq); + SELECT num FROM bs WHERE base64(base64(b))!=b; + SELECT num FROM bs WHERE base85(base85(b))!=b; +} {} + +finish_test diff --git a/test/bc_common.tcl b/test/bc_common.tcl new file mode 100644 index 0000000..c47f996 --- /dev/null +++ b/test/bc_common.tcl @@ -0,0 +1,75 @@ + + + +proc bc_find_binaries {zCaption} { + # Search for binaries to test against. Any executable files that match + # our naming convention are assumed to be testfixture binaries to test + # against. + # + set binaries [list] + set self [info nameofexec] + set pattern "$self?*" + if {$::tcl_platform(platform)=="windows"} { + set pattern [string map {\.exe {}} $pattern] + } + foreach file [glob -nocomplain $pattern] { + if {$file==$self} continue + if {[file executable $file] && [file isfile $file]} {lappend binaries $file} + } + + if {[llength $binaries]==0} { + puts "WARNING: No historical binaries to test against." + puts "WARNING: Omitting backwards-compatibility tests" + } + + foreach bin $binaries { + puts -nonewline "Testing against $bin - " + flush stdout + puts "version [get_version $bin]" + } + + set ::BC(binaries) $binaries + return $binaries +} + +proc get_version {binary} { + set chan [launch_testfixture $binary] + set v [testfixture $chan { sqlite3 -version }] + close $chan + set v +} + +proc do_bc_test {bin script} { + + forcedelete test.db + set ::bc_chan [launch_testfixture $bin] + + proc code1 {tcl} { uplevel #0 $tcl } + proc code2 {tcl} { testfixture $::bc_chan $tcl } + proc sql1 sql { code1 [list db eval $sql] } + proc sql2 sql { code2 [list db eval $sql] } + + code1 { sqlite3 db test.db } + code2 { sqlite3 db test.db } + + set bintag $bin + regsub {.*testfixture\.} $bintag {} bintag + set bintag [string map {\.exe {}} $bintag] + if {$bintag == ""} {set bintag self} + set saved_prefix $::testprefix + append ::testprefix ".$bintag" + + uplevel $script + + set ::testprefix $saved_prefix + + catch { code1 { db close } } + catch { code2 { db close } } + catch { close $::bc_chan } +} + +proc do_all_bc_test {script} { + foreach bin $::BC(binaries) { + uplevel [list do_bc_test $bin $script] + } +} diff --git a/test/bestindex1.test b/test/bestindex1.test new file mode 100644 index 0000000..e505a8b --- /dev/null +++ b/test/bestindex1.test @@ -0,0 +1,344 @@ +# 2016-03-01 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix bestindex1 + +ifcapable !vtab { + finish_test + return +} + +register_tcl_module db + +proc vtab_command {method args} { + switch -- $method { + xConnect { + return "CREATE TABLE t1(a, b, c)" + } + + xBestIndex { + set hdl [lindex $args 0] + set clist [$hdl constraints] + set orderby [$hdl orderby] + + if {[llength $clist]!=1} { error "unexpected constraint list" } + catch { array unset C } + array set C [lindex $clist 0] + if {$C(usable)} { + return "omit 0 cost 0 rows 1 idxnum 555 idxstr eq!" + } else { + return "cost 1000000 rows 0 idxnum 0 idxstr scan..." + } + } + + } + + return {} +} + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE x1 USING tcl(vtab_command); +} {} + +do_eqp_test 1.1 { + SELECT * FROM x1 WHERE a = 'abc' +} {SCAN x1 VIRTUAL TABLE INDEX 555:eq!} + +do_eqp_test 1.2 { + SELECT * FROM x1 WHERE a IN ('abc', 'def'); +} {SCAN x1 VIRTUAL TABLE INDEX 555:eq!} + +#------------------------------------------------------------------------- +# +reset_db +register_tcl_module db + +# Parameter $mode may be one of: +# +# "omit" - Implement filtering. Set the omit flag. +# "use" - Implement filtering. Use the constraint, but do not set omit. +# "use2" - Do not implement filtering. Use the constraint anyway. +# +# +proc t1_vtab {mode method args} { + switch -- $method { + xConnect { + return "CREATE TABLE t1(a, b)" + } + + xBestIndex { + set hdl [lindex $args 0] + set clist [$hdl constraints] + set orderby [$hdl orderby] + + set SQL_FILTER {SELECT * FROM t1x WHERE a='%1%'} + set SQL_SCAN {SELECT * FROM t1x} + + set idx 0 + for {set idx 0} {$idx < [llength $clist]} {incr idx} { + array unset C + array set C [lindex $clist $idx] + if {$C(column)==0 && $C(op)=="eq" && $C(usable)} { + switch -- $mode { + "omit" { + return [list omit $idx rows 10 cost 10 idxstr $SQL_FILTER] + } + "use" { + return [list use $idx rows 10 cost 10 idxstr $SQL_FILTER] + } + "use2" { + return [list use $idx rows 10 cost 10 idxstr $SQL_SCAN] + } + default { + error "Bad mode - $mode" + } + } + } + } + + return [list idxstr {SELECT * FROM t1x}] + } + + xFilter { + set map [list %1% [lindex $args 2 0]] + set sql [string map $map [lindex $args 1]] + return [list sql $sql] + } + } + + return {} +} + +do_execsql_test 2.1 { + CREATE TABLE t1x(i INTEGER PRIMARY KEY, a, b); + INSERT INTO t1x VALUES(1, 'one', 1); + INSERT INTO t1x VALUES(2, 'two', 2); + INSERT INTO t1x VALUES(3, 'three', 3); + INSERT INTO t1x VALUES(4, 'four', 4); +} + +foreach {tn mode} { + 1 use 2 omit 3 use2 +} { + do_execsql_test 2.2.$mode.1 " + DROP TABLE IF EXISTS t1; + CREATE VIRTUAL TABLE t1 USING tcl(t1_vtab $mode); + " + + do_execsql_test 2.2.$mode.2 {SELECT * FROM t1} {one 1 two 2 three 3 four 4} + do_execsql_test 2.2.$mode.3 {SELECT rowid FROM t1} {1 2 3 4} + do_execsql_test 2.2.$mode.4 {SELECT rowid FROM t1 WHERE a='two'} {2} + + do_execsql_test 2.2.$mode.5 { + SELECT rowid FROM t1 WHERE a IN ('one', 'four') ORDER BY +rowid + } {1 4} + + set plan(use) { + QUERY PLAN + |--SCAN t1 VIRTUAL TABLE INDEX 0:SELECT * FROM t1x WHERE a='%1%' + `--USE TEMP B-TREE FOR ORDER BY + } + set plan(omit) { + QUERY PLAN + |--SCAN t1 VIRTUAL TABLE INDEX 0:SELECT * FROM t1x WHERE a='%1%' + `--USE TEMP B-TREE FOR ORDER BY + } + set plan(use2) { + QUERY PLAN + |--SCAN t1 VIRTUAL TABLE INDEX 0:SELECT * FROM t1x + `--USE TEMP B-TREE FOR ORDER BY + } + + do_eqp_test 2.2.$mode.6 { + SELECT rowid FROM t1 WHERE a IN ('one', 'four') ORDER BY +rowid + } [string map {"\n " "\n"} $plan($mode)] +} + +# 2016-04-09. +# Demonstrate a register overwrite problem when using two virtual +# tables where the outer loop uses the IN operator. +# +set G(collist) [list PrimaryKey flagA columnA] +set G(cols) [join $G(collist) ,] +set G(nulls) "NULL" + +proc vtab_command {method args} { + global G + + switch -- $method { + xConnect { + return "CREATE TABLE t1($G(cols))" + } + + xBestIndex { + set hdl [lindex $args 0] + set clist [$hdl constraints] + set orderby [$hdl orderby] + + #puts $clist + set W [list] + set U [list] + + set i 0 + for {set idx 0} {$idx < [llength $clist]} {incr idx} { + array set c [lindex $clist $idx] + if {$c(op)=="eq" && $c(usable)} { + lappend W "[lindex $G(collist) $c(column)] = %$i%" + lappend U use $idx + incr i + } + } + + if {$W==""} { + set sql "SELECT rowid, * FROM t1" + } else { + set sql "SELECT rowid, * FROM t1 WHERE [join $W { AND }]" + } + + return [concat [list idxstr $sql] $U] + } + + xFilter { + foreach {idxnum idxstr vals} $args {} + + set map [list] + for {set i 0} {$i < [llength $vals]} {incr i} { + lappend map "%$i%" + set v [lindex $vals $i] + if {[string is integer $v]} { + lappend map $v + } else { + lappend map "'$v'" + } + } + set sql [string map $map $idxstr] + + #puts "SQL: $sql" + return [list sql $sql] + } + } + + return {} +} + +db close +forcedelete test.db +sqlite3 db test.db +register_tcl_module db + +do_execsql_test 3.1 " + CREATE TABLE t1($G(cols)); + INSERT INTO t1 VALUES(1, 0, 'ValueA'); + INSERT INTO t1 VALUES(2, 0, 'ValueA'); + INSERT INTO t1 VALUES(3, 0, 'ValueB'); + INSERT INTO t1 VALUES(4, 0, 'ValueB'); +" + +do_execsql_test 3.2 { + CREATE VIRTUAL TABLE VirtualTableA USING tcl(vtab_command); + CREATE VIRTUAL TABLE VirtualTableB USING tcl(vtab_command); +} + +do_execsql_test 3.3 { SELECT primarykey FROM VirtualTableA } {1 2 3 4} + +do_execsql_test 3.4 { + SELECT * FROM + VirtualTableA a CROSS JOIN VirtualTableB b ON b.PrimaryKey=a.PrimaryKey + WHERE a.ColumnA IN ('ValueA', 'ValueB') AND a.FlagA=0 +} { + 1 0 ValueA 1 0 ValueA + 2 0 ValueA 2 0 ValueA + 3 0 ValueB 3 0 ValueB + 4 0 ValueB 4 0 ValueB +} + +do_execsql_test 3.5 { + SELECT * FROM + VirtualTableA a CROSS JOIN VirtualTableB b ON b.PrimaryKey=a.PrimaryKey + WHERE a.FlagA=0 AND a.ColumnA IN ('ValueA', 'ValueB') +} { + 1 0 ValueA 1 0 ValueA + 2 0 ValueA 2 0 ValueA + 3 0 ValueB 3 0 ValueB + 4 0 ValueB 4 0 ValueB +} + +#------------------------------------------------------------------------- +# If there is an IN(..) condition in the WHERE clause of a query on a +# virtual table, the xBestIndex method is first invoked with the IN(...) +# represented by a "usable" SQLITE_INDEX_CONSTRAINT_EQ constraint. If +# the virtual table elects to use the IN(...) constraint, then the +# xBestIndex method is invoked again, this time with the IN(...) marked +# as "not usable". Depending on the relative costs of the two plans as +# defined by the virtual table implementation, and the cardinality of the +# IN(...) operator, SQLite chooses the most efficient plan. +# +# At one point the second invocation of xBestIndex() was only being made +# for join queries. The following tests check that this problem has been +# fixed. +# +proc vtab_command {method args} { + switch -- $method { + xConnect { + return "CREATE TABLE t1(a, b, c, d)" + } + + xBestIndex { + set hdl [lindex $args 0] + set clist [$hdl constraints] + set orderby [$hdl orderby] + + lappend ::bestindex_calls $clist + set ret "cost 1000000 idxnum 555" + for {set i 0} {$i < [llength $clist]} {incr i} { + array set C [lindex $clist $i] + if {$C(usable)} { + lappend ret use $i + } + } + return $ret + } + } + return {} +} + +do_execsql_test 4.0 { + CREATE VIRTUAL TABLE x1 USING tcl(vtab_command); +} {} + +do_test 4.1 { + set ::bestindex_calls [list] + execsql { + SELECT * FROM x1 WHERE a=? AND b BETWEEN ? AND ? AND c IN (1, 2, 3, 4); + } + set ::bestindex_calls +} [list \ + [list {op eq column 0 usable 1} \ + {op eq column 2 usable 1} \ + {op ge column 1 usable 1} \ + {op le column 1 usable 1} \ + ] \ + [list {op eq column 0 usable 1} \ + {op eq column 2 usable 0} \ + {op ge column 1 usable 1} \ + {op le column 1 usable 1} + ] +] + +do_catchsql_test 5.0 { + SELECT * FROM tcl('abc'); +} {1 {wrong number of arguments}} + +finish_test diff --git a/test/bestindex2.test b/test/bestindex2.test new file mode 100644 index 0000000..c47a721 --- /dev/null +++ b/test/bestindex2.test @@ -0,0 +1,145 @@ +# 2016 March 3 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix bestindex2 + +ifcapable !vtab { + finish_test + return +} + +#------------------------------------------------------------------------- +# Virtual table callback for table named $tbl, with the columns specified +# by list argument $cols. e.g. if the function is invoked as: +# +# vtab_cmd t1 {a b c} ... +# +# The table created is: +# +# "CREATE TABLE t1 (a, b, c)" +# +# The tables xBestIndex method behaves as if all possible combinations of +# "=" constraints (but no others) may be optimized. The cost of a full table +# scan is: +# +# "WHERE 1" "cost 1000000 rows 1000000" +# +# If one or more "=" constraints are in use, the cost and estimated number +# of rows returned are both is (11 - nCons)*1000, where nCons is the number +# of constraints used. e.g. +# +# "WHERE a=? AND b=?" -> "cost 900 rows 900" +# "WHERE c=? AND b "cost 1000 rows 1000" +# +proc vtab_cmd {tbl cols method args} { + switch -- $method { + xConnect { + return "CREATE TABLE $tbl ([join $cols ,])" + } + xBestIndex { + set hdl [lindex $args 0] + set clist [$hdl constraints] + set orderby [$hdl orderby] + set mask [$hdl mask] + + set cons [list] + set used [list] + + for {set i 0} {$i < [llength $clist]} {incr i} { + array unset C + array set C [lindex $clist $i] + if {$C(op)=="eq" && $C(usable) && [lsearch $cons $C(column)]<0} { + lappend used use $i + lappend cons $C(column) + } + } + + set nCons [llength $cons] + if {$nCons==0} { + return "cost 1000000 rows 1000000" + } else { + set cost [expr (11-$nCons) * 1000] + set ret [concat $used "cost $cost rows $cost"] + + set txt [list] + foreach c $cons { lappend txt "[lindex $cols $c]=?" } + lappend ret idxstr "indexed([join $txt { AND }])" + + return $ret + } + } + } + return "" +} + +register_tcl_module db + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t1 USING tcl("vtab_cmd t1 {a b}"); + CREATE VIRTUAL TABLE t2 USING tcl("vtab_cmd t2 {c d}"); + CREATE VIRTUAL TABLE t3 USING tcl("vtab_cmd t3 {e f}"); +} + +do_eqp_test 1.1 { + SELECT * FROM t1 WHERE a='abc' +} {SCAN t1 VIRTUAL TABLE INDEX 0:indexed(a=?)} + +do_eqp_test 1.2 { + SELECT * FROM t1 WHERE a='abc' AND b='def' +} {SCAN t1 VIRTUAL TABLE INDEX 0:indexed(a=? AND b=?)} + +do_eqp_test 1.3 { + SELECT * FROM t1 WHERE a='abc' AND a='def' +} {SCAN t1 VIRTUAL TABLE INDEX 0:indexed(a=?)} + +do_eqp_test 1.4 { + SELECT * FROM t1,t2 WHERE c=a +} { + QUERY PLAN + |--SCAN t1 VIRTUAL TABLE INDEX 0: + `--SCAN t2 VIRTUAL TABLE INDEX 0:indexed(c=?) +} + +do_eqp_test 1.5 { + SELECT * FROM t1, t2 CROSS JOIN t3 WHERE t2.c = +t1.b AND t3.e=t2.d +} { + QUERY PLAN + |--SCAN t1 VIRTUAL TABLE INDEX 0: + |--SCAN t2 VIRTUAL TABLE INDEX 0:indexed(c=?) + `--SCAN t3 VIRTUAL TABLE INDEX 0:indexed(e=?) +} + +do_eqp_test 1.6 { + SELECT * FROM t1, t2, t3 WHERE t2.c = +t1.b AND t3.e = t2.d +} { + QUERY PLAN + |--SCAN t1 VIRTUAL TABLE INDEX 0: + |--SCAN t2 VIRTUAL TABLE INDEX 0:indexed(c=?) + `--SCAN t3 VIRTUAL TABLE INDEX 0:indexed(e=?) +} + +do_execsql_test 1.7.1 { + CREATE TABLE x1(a, b); +} +do_eqp_test 1.7.2 { + SELECT * FROM x1 CROSS JOIN t1, t2, t3 + WHERE t1.a = t2.c AND t1.b = t3.e +} { + QUERY PLAN + |--SCAN x1 + |--SCAN t1 VIRTUAL TABLE INDEX 0: + |--SCAN t2 VIRTUAL TABLE INDEX 0:indexed(c=?) + `--SCAN t3 VIRTUAL TABLE INDEX 0:indexed(e=?) +} + +finish_test diff --git a/test/bestindex3.test b/test/bestindex3.test new file mode 100644 index 0000000..6aa3321 --- /dev/null +++ b/test/bestindex3.test @@ -0,0 +1,185 @@ +# 2016 May 29 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix bestindex3 + +ifcapable !vtab { + finish_test + return +} + +#------------------------------------------------------------------------- +# Virtual table callback for a virtual table named $tbl. +# +# The table created is: +# +# "CREATE TABLE t1 (a, b, c)" +# +# This virtual table supports both LIKE and = operators on all columns. +# +proc vtab_cmd {bOmit method args} { + switch -- $method { + xConnect { + return "CREATE TABLE t1(a, b, c)" + } + + xBestIndex { + set hdl [lindex $args 0] + set clist [$hdl constraints] + set orderby [$hdl orderby] + set mask [$hdl mask] + + set ret [list] + set use use + if {$bOmit} {set use omit} + + for {set i 0} {$i < [llength $clist]} {incr i} { + array unset C + array set C [lindex $clist $i] + if {$C(usable) && ($C(op)=="like" || $C(op)=="eq")} { + lappend ret $use $i + lappend ret idxstr + lappend ret "[lindex {a b c} $C(column)] [string toupper $C(op)] ?" + break + } + } + + if {$ret==""} { + lappend ret cost 1000000 rows 1000000 + } else { + lappend ret cost 100 rows 10 + } + return $ret + } + + xFilter { + foreach {idxnum idxstr param} $args {} + set where "" + if {$bOmit && $idxstr != ""} { + set where " WHERE [string map [list ? '$param' EQ =] $idxstr]" + } + return [list sql "SELECT rowid, * FROM ttt$where"] + } + } + return "" +} + +register_tcl_module db + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t1 USING tcl("vtab_cmd 0"); +} + +do_eqp_test 1.1 { + SELECT * FROM t1 WHERE a LIKE 'abc'; +} {SCAN t1 VIRTUAL TABLE INDEX 0:a LIKE ?} + +do_eqp_test 1.2 { + SELECT * FROM t1 WHERE a = 'abc'; +} {SCAN t1 VIRTUAL TABLE INDEX 0:a EQ ?} + +do_eqp_test 1.3 { + SELECT * FROM t1 WHERE a = 'abc' OR b = 'def'; +} { + QUERY PLAN + `--MULTI-INDEX OR + |--INDEX 1 + | `--SCAN t1 VIRTUAL TABLE INDEX 0:a EQ ? + `--INDEX 2 + `--SCAN t1 VIRTUAL TABLE INDEX 0:b EQ ? +} + +do_eqp_test 1.4 { + SELECT * FROM t1 WHERE a LIKE 'abc%' OR b = 'def'; +} { + QUERY PLAN + `--MULTI-INDEX OR + |--INDEX 1 + | `--SCAN t1 VIRTUAL TABLE INDEX 0:a LIKE ? + `--INDEX 2 + `--SCAN t1 VIRTUAL TABLE INDEX 0:b EQ ? +} + +do_execsql_test 1.5 { + CREATE TABLE ttt(a, b, c); + + INSERT INTO ttt VALUES(1, 'two', 'three'); + INSERT INTO ttt VALUES(2, 'one', 'two'); + INSERT INTO ttt VALUES(3, 'three', 'one'); + INSERT INTO ttt VALUES(4, 'y', 'one'); + INSERT INTO ttt VALUES(5, 'x', 'two'); + INSERT INTO ttt VALUES(6, 'y', 'three'); +} + +foreach omit {0 1} { + do_execsql_test 1.6.$omit.0 " + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING tcl('vtab_cmd $omit'); + " + do_execsql_test 1.6.$omit.1 { + SELECT rowid FROM t1 WHERE c LIKE 'o%' + } {3 4} + + do_execsql_test 1.6.$omit.2 { + SELECT rowid FROM t1 WHERE c LIKE 'o%' OR b='y' + } {3 4 6} + + do_execsql_test 1.6.$omit.3 { + SELECT rowid FROM t1 WHERE c = 'three' OR c LIKE 'o%' + } {1 6 3 4} +} + +#------------------------------------------------------------------------- +# Test the same pattern works with ordinary tables. +# +# This test does not work if the ICU extension is enabled. ICU overrides +# LIKE - and this optimization only works with the built-in LIKE function. +# +ifcapable !icu { + do_execsql_test 2.1 { + CREATE TABLE t2(x TEXT COLLATE nocase, y TEXT); + CREATE INDEX t2x ON t2(x COLLATE nocase); + CREATE INDEX t2y ON t2(y); + } + + do_eqp_test 2.2 { + SELECT * FROM t2 WHERE x LIKE 'abc%' OR y = 'def' + } [string map {"\n " \n} { + QUERY PLAN + `--MULTI-INDEX OR + |--INDEX 1 + | `--SEARCH t2 USING INDEX t2x (x>? AND x=0} + } $idxinsert + do_test 1.$tn.4 { + set ::lOrderByConsumed + } $bConsumed +} + +#------------------------------------------------------------------------- +reset_db +register_tcl_module db + +proc vtab_command {src method args} { + switch -- $method { + xConnect { + return "CREATE TABLE xxx(a, b)" + } + + xBestIndex { + set hdl [lindex $args 0] + set ret [list] + + set iCons 0 + foreach cons [$hdl constraints] { + array set C $cons + if {($C(op)=="limit" || $C(op)=="offset") && $C(usable)} { + lappend ret use $iCons + } + incr iCons + } + + return $ret + } + + xFilter { + lappend ::lFilterArgs [lindex $args 2] + return [list sql "SELECT rowid, a, b FROM $src"] + } + + } + + return {} +} + +do_execsql_test 2.0 { + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a, b); + CREATE VIRTUAL TABLE vt1 USING tcl(vtab_command t1); +} + +do_test 2.1 { + set ::lFilterArgs [list] + execsql { SELECT * FROM vt1 LIMIT 10 } + set ::lFilterArgs +} {10} + +do_test 2.2 { + set ::lFilterArgs [list] + execsql { SELECT * FROM vt1 LIMIT 5 OFFSET 50 } + set ::lFilterArgs +} {{5 50}} + +do_test 2.3 { + set ::lFilterArgs [list] + execsql { SELECT * FROM vt1 ORDER BY a, b LIMIT 1 OFFSET 1 } + set ::lFilterArgs +} {{1 1}} + +do_test 2.4 { + set ::lFilterArgs [list] + execsql { SELECT * FROM vt1 ORDER BY a, +b LIMIT 1 OFFSET 1 } + set ::lFilterArgs +} {{}} + +#------------------------------------------------------------------------- +reset_db +register_tcl_module db + +proc vtab_command {src method args} { + switch -- $method { + xConnect { + return "CREATE TABLE xxx(a, b)" + } + + xBestIndex { + set hdl [lindex $args 0] + set lCons [$hdl constraints] + + set ret [list] + for {set i 0} {$i < [llength $lCons]} {incr i} { + array set C [lindex $lCons $i] + if {$C(usable)} { + lappend ret use $i + $hdl in $i 1 + } + } + return $ret + } + + xFilter { + set lArg [lindex $args 2] + lappend ::lFilterArg {*}$lArg + return [list sql "SELECT rowid, a, b FROM $src"] + } + + } + + return {} +} + +do_execsql_test 3.0 { + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a, b); + CREATE VIRTUAL TABLE vt1 USING tcl(vtab_command t1); +} + +foreach {tn sql lfa} { + 1 "SELECT * FROM vt1 WHERE b IN (10, 20, 30)" {{10 20 30}} + 2 "SELECT * FROM vt1 WHERE b IN ('abc', 'def')" {{abc def}} + 3 "SELECT * FROM vt1 WHERE a IS NULL AND b IN ('abc', 'def')" {{} {abc def}} + 4 "SELECT * FROM vt1 WHERE a IN (1,2,3) AND b IN ('abc', 'def')" + {{1 2 3} {abc def}} + + 5 "SELECT * FROM vt1 + WHERE a IN (SELECT 1 UNION SELECT 2) AND b IN ('abc', 'def')" + {{1 2} {abc def}} + + 6 "SELECT * FROM vt1 + WHERE b IN ('abc', 'def') AND a IN (SELECT 1 UNION SELECT 2)" + {{abc def} {1 2}} +} { + do_test 3.$tn { + set ::lFilterArg [list] + execsql $sql + set ::lFilterArg + } $lfa +} + +#explain_i { SELECT * FROM vt1 WHERE b IN (10, 20, 30) } + +#------------------------------------------------------------------------- +reset_db +register_tcl_module db + +proc vtab_command {src method args} { + switch -- $method { + xConnect { + return "CREATE TABLE xxx(a, b, c)" + } + + xBestIndex { + set hdl [lindex $args 0] + set lCons [$hdl constraints] + + set ret [list] + for {set i 0} {$i < [llength $lCons]} {incr i} { + lappend ::lBestIndexRhs [$hdl rhs_value $i -] + } + return $ret + } + + xFilter { + return [list sql "SELECT rowid, a, b, c FROM $src"] + } + + } + + return {} +} + +do_execsql_test 4.0 { + CREATE TABLE t1(a, b, c); + CREATE VIRTUAL TABLE vt1 USING tcl(vtab_command t1); +} + +foreach {tn sql lbir} { + 1 "SELECT * FROM vt1 WHERE b = 10" {10} + 2 "SELECT * FROM vt1 WHERE a = 'abc' AND b < 30" {abc 30} + 3 "SELECT * FROM vt1 WHERE a = 'abc' AND b < 30+2" {abc -} + 4 "SELECT * FROM vt1 WHERE a IN (1,2,3) AND b < 30+2" {- -} + 5 "SELECT * FROM vt1 WHERE a IS 111 AND b < 30+2" {111 -} +} { + do_test 4.$tn { + set ::lBestIndexRhs [list] + execsql $sql + set ::lBestIndexRhs + } $lbir +} + +#------------------------------------------------------------------------- +reset_db +db cache size 0 +register_tcl_module db + +set ::vtab_handle_in 1 +proc vtab_command {src method args} { + switch -- $method { + xConnect { + return "CREATE TABLE xxx(a, b, c)" + } + + xBestIndex { + set lCols [list a b c] + + set hdl [lindex $args 0] + set lCons [$hdl constraints] + set lOrder [$hdl order] + + set L "" + set O "" + set W [list] + set a 0 + for {set i 0} {$i < [llength $lCons]} {incr i} { + array set C [lindex $lCons $i] + if {$C(usable)} { + if { $C(op)=="eq" } { + set bIn 0 + if {$::vtab_handle_in} { set bIn [$hdl in $i 1] } + if {$bIn} { + lappend W "[lindex $lCols $C(column)] IN (%I$a%)" + } else { + lappend W "[lindex $lCols $C(column)] = %$a%" + } + lappend ret omit $i + } + if { $C(op)=="limit" } { set L " LIMIT %$a%" ; lappend ret use $i } + if { $C(op)=="offset" } { set O " OFFSET %$a%" ; lappend ret use $i } + incr a + } + } + + set order "" + set selectlist "rowid, a, b, c" + if {[llength $lOrder]} { + array set sl [list] + set lO [list] + foreach s $lOrder { + array set C $s + set ad "" + if {$C(desc)} { set ad " DESC" } + lappend lO "[lindex $lCols $C(column)]$ad" + set sl($C(column)) 1 + } + if {[$hdl distinct]==2} { + set selectlist "DISTINCT 0" + foreach i {0 1 2} { + if {[info exists sl($i)]} { + append selectlist ", [lindex $lCols $i]" + } else { + append selectlist ", 0" + } + } + } else { + set order " ORDER BY [join $lO ,]" + } + } + + set where "" + if {[llength $W]} { set where " WHERE [join $W { AND }]" } + set sql "SELECT $selectlist FROM $src$where$order$L$O" + + lappend ret idxStr $sql + return $ret + } + + xFilter { + foreach {idxnum idxstr lArg} $args {} + set ii 0 + set sql $idxstr + foreach a $lArg { + set sql [string map [list %$ii% $a] $sql] + set sql [string map [list %I$ii% [join $a ,]] $sql] + incr ii + } + lappend ::lFilterSql $sql + + if {[regexp {OFFSET (.*)$} $sql -> off]} { + set real_sql " + WITH c(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM c WHERE i<$off ) + SELECT 0,0,0,0 FROM c + UNION ALL SELECT * FROM ( + $sql + ) + " + } else { + set real_sql $sql + } + + return [list sql $real_sql] + } + + } + + return {} +} + +do_execsql_test 5.0 { + CREATE TABLE t1(a, b, c); + CREATE VIRTUAL TABLE vt1 USING tcl(vtab_command t1); + INSERT INTO t1 VALUES(1, 2, 3); + INSERT INTO t1 VALUES(2, 3, 4); + INSERT INTO t1 VALUES(3, 4, 5); + INSERT INTO t1 VALUES(1, 5, 6); + INSERT INTO t1 VALUES(2, 6, 7); + INSERT INTO t1 VALUES(3, 7, 8); + INSERT INTO t1 VALUES(1, 8, 9); + INSERT INTO t1 VALUES(2, 9, 0); +} + +proc do_vtab_test {tn sql vtsql {res {}}} { + set ::lFilterSql [list] + uplevel [list do_execsql_test $tn.1 $sql $res] + uplevel [list do_test $tn.2 {set ::lFilterSql} [list {*}$vtsql]] +} + +do_vtab_test 5.1.1 { + SELECT DISTINCT a FROM vt1 +} { + {SELECT DISTINCT 0, a, 0, 0 FROM t1} +} {1 2 3} + +do_vtab_test 5.1.2 { + SELECT DISTINCT a FROM vt1 ORDER BY a +} { + {SELECT rowid, a, b, c FROM t1 ORDER BY a} +} {1 2 3} + +do_vtab_test 5.1.3 { + SELECT DISTINCT a FROM vt1 WHERE c IN (4,5,6,7,8) +} { + {SELECT DISTINCT 0, a, 0, 0 FROM t1 WHERE c IN (4,5,6,7,8)} +} {2 3 1} + +set ::vtab_handle_in 0 +do_vtab_test 5.1.4 { + SELECT DISTINCT a FROM vt1 WHERE c IN (4,5,6,7,8) +} { + {SELECT DISTINCT 0, a, 0, 0 FROM t1 WHERE c = 4} + {SELECT DISTINCT 0, a, 0, 0 FROM t1 WHERE c = 5} + {SELECT DISTINCT 0, a, 0, 0 FROM t1 WHERE c = 6} + {SELECT DISTINCT 0, a, 0, 0 FROM t1 WHERE c = 7} + {SELECT DISTINCT 0, a, 0, 0 FROM t1 WHERE c = 8} +} {2 3 1} + +set ::vtab_handle_in 1 +do_vtab_test 5.1.5a { + SELECT a, b, c FROM vt1 WHERE c IN (4,5,6,7,8) LIMIT 2 OFFSET 2 +} { + {SELECT rowid, a, b, c FROM t1 WHERE c IN (4,5,6,7,8) LIMIT 2 OFFSET 2} +} {1 5 6 2 6 7} + +set ::vtab_handle_in 0 +do_vtab_test 5.1.5b { + SELECT a, b, c FROM vt1 WHERE c IN (4,5,6,7,8) LIMIT 2 OFFSET 2 +} { + {SELECT rowid, a, b, c FROM t1 WHERE c = 4} + {SELECT rowid, a, b, c FROM t1 WHERE c = 5} + {SELECT rowid, a, b, c FROM t1 WHERE c = 6} + {SELECT rowid, a, b, c FROM t1 WHERE c = 7} +} {1 5 6 2 6 7} +set ::vtab_handle_in 1 + +finish_test diff --git a/test/bestindex9.test b/test/bestindex9.test new file mode 100644 index 0000000..d591b30 --- /dev/null +++ b/test/bestindex9.test @@ -0,0 +1,104 @@ +# 2020-01-29 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix bestindex9 + +ifcapable !vtab { + finish_test + return +} + + +proc vtab_command {method args} { + switch -- $method { + xConnect { + return $::create_table + } + + xBestIndex { + set hdl [lindex $args 0] + set ::vtab_orderby [$hdl orderby] + set ::vtab_distinct [$hdl distinct] + + return [list orderby 1] + } + + xFilter { + return "" + } + } + + return {} +} + +proc do_bestindex9_test {tn create select orderby distinct} { + forcedelete test.db2 + sqlite3 dbtest test.db2 + register_tcl_module dbtest + + set ::create_table $create + dbtest eval { CREATE VIRTUAL TABLE t1 USING tcl(vtab_command); } + dbtest eval $select + + do_test $tn.orderby [list set {} $::vtab_orderby] $orderby + do_test $tn.distinct [list set {} $::vtab_distinct] $distinct + + dbtest close +} + +#------------------------------------------------------------------------- +# +do_bestindex9_test 1.0 { + CREATE TABLE x(k1, k2, v1, PRIMARY KEY(k1, k2)) +} { + SELECT DISTINCT k1, k2 FROM t1 +} {{column 0 desc 0} {column 1 desc 0}} 2 + +do_bestindex9_test 1.1 { + CREATE TABLE x(k1, k2, v1, PRIMARY KEY(k1, k2)) WITHOUT ROWID +} { + SELECT DISTINCT k1, k2 FROM t1 +} {} 0 + +do_bestindex9_test 1.2 { + CREATE TABLE x(k1 NOT NULL, k2 NOT NULL, v1, PRIMARY KEY(k1, k2)) +} { + SELECT DISTINCT k1, k2 FROM t1 +} {} 0 + +#------------------------------------------------------------------------- +# +do_bestindex9_test 2 { + CREATE TABLE x(c1, c2, c3); +} { + SELECT DISTINCT c1 FROM t1 ORDER BY c1 +} {{column 0 desc 0}} 3 + +#------------------------------------------------------------------------- +# +do_bestindex9_test 3 { + CREATE TABLE x(c1, c2, c3); +} { + SELECT DISTINCT c1 FROM t1 GROUP BY c1 +} {{column 0 desc 0}} 1 + +do_bestindex9_test 4 { + CREATE TABLE x(c1, c2, c3); +} { + CREATE TABLE t2(balls); + SELECT DISTINCT c1 FROM t1, t2 +} {{column 0 desc 0}} 2 + + +finish_test diff --git a/test/bestindexA.test b/test/bestindexA.test new file mode 100644 index 0000000..1976986 --- /dev/null +++ b/test/bestindexA.test @@ -0,0 +1,135 @@ +# 2020-01-29 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix bestindexA + +ifcapable !vtab { + finish_test + return +} + + +proc vtab_command {method args} { + switch -- $method { + xConnect { + return "CREATE TABLE x(a, b, c)" + } + + xBestIndex { + set hdl [lindex $args 0] + set clist [$hdl constraints] + foreach c $clist { + array set C $c + lappend ::vtab_constraints [list $C(op) $C(column)] + } + return [list] + } + + xFilter { + return "" + } + + xFindFunction { + foreach {nArg name} $args {} + if {$nArg==2 && $name=="even"} { + return 152 + } + return 0 + } + + } + + return {} +} + +register_tcl_module db +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t1 USING tcl(vtab_command); +} + +proc do_xbestindex_test {tn sql res} { + set script [subst { + execsql "$sql" + set ::vtab_constraints + }] + + uplevel [list do_test $tn $script [list {*}$res]] + set ::vtab_constraints [list] +} + +do_xbestindex_test 1.1 { + SELECT * FROM t1 WHERE a=? +} { + {eq 0} +} + +do_xbestindex_test 1.2 { + SELECT * FROM t1 WHERE a=? LIMIT 10 +} { + {eq 0} + {limit 0} +} + +do_xbestindex_test 1.3 { + SELECT * FROM t1 WHERE a=? AND (b+1)=? LIMIT 10 +} { + {eq 0} +} + +proc error_function {args} { error "not a function!" } +db function even error_function + +do_xbestindex_test 1.4 { + SELECT * FROM t1 WHERE even(a, ?) +} { + {152 0} +} + +do_xbestindex_test 1.5 { + SELECT * FROM t1 WHERE b=10 AND even(a, ?) +} { + {eq 1} + {152 0} +} + +do_xbestindex_test 1.6 { + SELECT * FROM t1 WHERE b=10 LIMIT 10 +} { + {eq 1} + {limit 0} +} + +do_xbestindex_test 1.7 { + SELECT * FROM t1 WHERE even(b,?) LIMIT 10 +} { + {152 1} + {limit 0} +} + +do_xbestindex_test 1.8 { + SELECT * FROM t1 WHERE b!=? LIMIT 10 +} { + {ne 1} + {limit 0} +} + +do_xbestindex_test 1.9 { + SELECT * FROM t1 WHERE ?=a LIMIT 10 +} { + {eq 0} + {limit 0} +} + + +finish_test diff --git a/test/bestindexB.test b/test/bestindexB.test new file mode 100644 index 0000000..b50e74f --- /dev/null +++ b/test/bestindexB.test @@ -0,0 +1,87 @@ +# 2023-10-26 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix bestindexB + +ifcapable !vtab { + finish_test + return +} + +register_tcl_module db + +proc vtab_command {method args} { + switch -- $method { + xConnect { + return "CREATE TABLE t1(a, b, c)" + } + + xBestIndex { + set hdl [lindex $args 0] + set clist [$hdl constraints] + set orderby [$hdl orderby] + + if {[info exists ::xbestindex_sql]} { + explain_i $::xbestindex_sql + set ::xbestindex_res [ execsql $::xbestindex_sql ] + } + + return "cost 1000000 rows 1000000 idxnum 0 idxstr hello" + } + + xFilter { + return "sql {SELECT 0, 1, 2, 3}" + } + } + + return {} +} + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE x1 USING tcl(vtab_command); + CREATE TABLE y1(a, b); + CREATE TABLE y2(a, b); +} {} + +do_execsql_test 1.1 { + SELECT * FROM x1 +} {1 2 3} + +do_execsql_test 1.2 { + INSERT INTO y1 VALUES(1, 2) RETURNING rowid; +} {1} + +do_execsql_test 1.3 { + CREATE TRIGGER y1tr BEFORE INSERT ON y1 BEGIN + SELECT * FROM x1; + END; + INSERT INTO y1 VALUES(3, 4) RETURNING rowid; +} {2} + + +# This time, rig the xBestIndex() method of the vtab to invoke an SQL +# statement that uses RETURNING. +set ::xbestindex_sql { + INSERT INTO y2 VALUES(NULL, NULL) RETURNING rowid; +} +do_execsql_test 1.4 { + INSERT INTO y1 VALUES(5, 6) RETURNING rowid; +} {3} + +do_test 1.5 { + set ::xbestindex_res +} {1} + +finish_test diff --git a/test/between.test b/test/between.test new file mode 100644 index 0000000..16c3913 --- /dev/null +++ b/test/between.test @@ -0,0 +1,143 @@ +# 2005 July 28 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing the use of indices in WHERE clauses +# when the WHERE clause contains the BETWEEN operator. +# +# $Id: between.test,v 1.2 2006/01/17 09:35:02 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Build some test data +# +do_test between-1.0 { + execsql { + BEGIN; + CREATE TABLE t1(w int, x int, y int, z int); + } + for {set i 1} {$i<=100} {incr i} { + set w $i + set x [expr {int(log($i)/log(2))}] + set y [expr {$i*$i + 2*$i + 1}] + set z [expr {$x+$y}] + ifcapable tclvar { + # Random unplanned test of the $varname variable syntax. + execsql {INSERT INTO t1 VALUES($::w,$::x,$::y,$::z)} + } else { + # If the $varname syntax is not available, use the regular variable + # declaration syntax. + execsql {INSERT INTO t1 VALUES(:w,:x,:y,:z)} + } + } + execsql { + CREATE UNIQUE INDEX i1w ON t1(w); + CREATE INDEX i1xy ON t1(x,y); + CREATE INDEX i1zyx ON t1(z,y,x); + COMMIT; + } +} {} + +# This procedure executes the SQL. Then it appends to the result the +# "sort" or "nosort" keyword depending on whether or not any sorting +# is done. Then it appends the names of the table and index used. +# +proc queryplan {sql} { + set ::sqlite_sort_count 0 + set data [execsql $sql] + if {$::sqlite_sort_count} {set x sort} {set x nosort} + lappend data $x + set eqp [execsql "EXPLAIN QUERY PLAN $sql"] + # puts eqp=$eqp + foreach {a b c x} $eqp { + if {[regexp {(SCAN|SEARCH) (\w+ AS )?(\w+) USING.* INDEX (\w+)\y} \ + $x all ss as tab idx]} { + lappend data $tab $idx + } elseif {[regexp {(SCAN|SEARCH) (\w+ AS )?(\w+)\y} $x all ss as tab]} { + lappend data $tab * + } + } + return $data +} + +do_test between-1.1.1 { + queryplan { + SELECT * FROM t1 WHERE w BETWEEN 5 AND 6 ORDER BY +w + } +} {5 2 36 38 6 2 49 51 sort t1 i1w} +do_test between-1.1.2 { + queryplan { + SELECT * FROM t1 WHERE +w BETWEEN 5 AND 6 ORDER BY +w + } +} {5 2 36 38 6 2 49 51 sort t1 *} +do_test between-1.2.1 { + queryplan { + SELECT * FROM t1 WHERE w BETWEEN 5 AND 65-y ORDER BY +w + } +} {5 2 36 38 6 2 49 51 sort t1 i1w} +do_test between-1.2.2 { + queryplan { + SELECT * FROM t1 WHERE +w BETWEEN 5 AND 65-y ORDER BY +w + } +} {5 2 36 38 6 2 49 51 sort t1 *} +do_test between-1.3.1 { + queryplan { + SELECT * FROM t1 WHERE w BETWEEN 41-y AND 6 ORDER BY +w + } +} {5 2 36 38 6 2 49 51 sort t1 i1w} +do_test between-1.3.2 { + queryplan { + SELECT * FROM t1 WHERE +w BETWEEN 41-y AND 6 ORDER BY +w + } +} {5 2 36 38 6 2 49 51 sort t1 *} +do_test between-1.4 { + queryplan { + SELECT * FROM t1 WHERE w BETWEEN 41-y AND 65-y ORDER BY +w + } +} {5 2 36 38 6 2 49 51 sort t1 *} +do_test between-1.5.1 { + queryplan { + SELECT * FROM t1 WHERE 26 BETWEEN y AND z ORDER BY +w + } +} {4 2 25 27 sort t1 i1zyx} +do_test between-1.5.2 { + queryplan { + SELECT * FROM t1 WHERE 26 BETWEEN +y AND z ORDER BY +w + } +} {4 2 25 27 sort t1 i1zyx} +do_test between-1.5.3 { + queryplan { + SELECT * FROM t1 WHERE 26 BETWEEN y AND +z ORDER BY +w + } +} {4 2 25 27 sort t1 *} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test between-2.0 { + CREATE TABLE t1(x TEXT, y TEXT COLLATE nocase); + INSERT INTO t1 VALUES('0', 'abc'); +} + +foreach {tn expr res} { + 1 "x BETWEEN 1 AND '5'" 0 + 2 "x COLLATE binary BETWEEN 1 AND '5'" 0 + 3 "x COLLATE nocase BETWEEN 1 AND '5'" 0 + + 4 "y BETWEEN 'A' AND 'B'" 1 + 5 "y COLLATE nocase BETWEEN 'A' AND 'B'" 1 + 6 "y COLLATE binary BETWEEN 'A' AND 'B'" 0 + 7 "(y COLLATE binary) BETWEEN 'A' AND 'B'" 0 +} { + set sql "SELECT $expr FROM t1" + do_execsql_test between-2.1.$tn $sql $res +} + +finish_test diff --git a/test/bigfile.test b/test/bigfile.test new file mode 100644 index 0000000..31c6323 --- /dev/null +++ b/test/bigfile.test @@ -0,0 +1,203 @@ +# 2002 November 30 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script testing the ability of SQLite to handle database +# files larger than 4GB. +# +# $Id: bigfile.test,v 1.12 2009/03/05 04:27:08 shane Exp $ +# + +if {[file exists skip-big-file]} return +if {$tcl_platform(os)=="Darwin"} return + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Do not use a codec for this file, as the database is manipulated using +# external methods (the [fake_big_file] and [hexio_write] commands). +# +do_not_use_codec + +# If SQLITE_DISABLE_LFS is defined, omit this file. +ifcapable !lfs { + finish_test + return +} + +# These tests only work for Tcl version 8.4 and later. Prior to 8.4, +# Tcl was unable to handle large files. +# +scan $::tcl_version %f vx +if {$vx<8.4} return + +# Mac OS X does not handle large files efficiently. So skip this test +# on that platform. +if {$tcl_platform(os)=="Darwin"} return + +# This is the md5 checksum of all the data in table t1 as created +# by the first test. We will use this number to make sure that data +# never changes. +# +set MAGIC_SUM {593f1efcfdbe698c28b4b1b693f7e4cf} + +do_test bigfile-1.1 { + execsql { + BEGIN; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES('abcdefghijklmnopqrstuvwxyz'); + INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; + INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; + INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; + INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; + INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; + INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; + INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; + COMMIT; + } + execsql { + SELECT md5sum(x) FROM t1; + } +} $::MAGIC_SUM + +# Try to create a large file - a file that is larger than 2^32 bytes. +# If this fails, it means that the system being tested does not support +# large files. So skip all of the remaining tests in this file. +# +db close +if {[catch {fake_big_file 4096 [get_pwd]/test.db} msg]} { + puts "**** Unable to create a file larger than 4096 MB. *****" + finish_test + return +} +hexio_write test.db 28 00000000 + +do_test bigfile-1.2 { + sqlite3 db test.db + execsql { + SELECT md5sum(x) FROM t1; + } +} $::MAGIC_SUM + +# The previous test may fail on some systems because they are unable +# to handle large files. If that is so, then skip all of the following +# tests. We will know the above test failed because the "db" command +# does not exist. +# +if {[llength [info command db]]<=0} { + puts "**** Large file support appears to be broken. *****" + finish_test + return +} + +do_test bigfile-1.3 { + execsql { + CREATE TABLE t2 AS SELECT * FROM t1; + SELECT md5sum(x) FROM t2; + } +} $::MAGIC_SUM +do_test bigfile-1.4 { + db close + sqlite3 db test.db + execsql { + SELECT md5sum(x) FROM t1; + } +} $::MAGIC_SUM + +db close +if {[catch {fake_big_file 8192 [get_pwd]/test.db}]} { + puts "**** Unable to create a file larger than 8192 MB. *****" + finish_test + return +} +hexio_write test.db 28 00000000 + +do_test bigfile-1.5 { + sqlite3 db test.db + execsql { + SELECT md5sum(x) FROM t1; + } +} $::MAGIC_SUM +do_test bigfile-1.6 { + sqlite3 db test.db + execsql { + SELECT md5sum(x) FROM t2; + } +} $::MAGIC_SUM +do_test bigfile-1.7 { + execsql { + CREATE TABLE t3 AS SELECT * FROM t1; + SELECT md5sum(x) FROM t3; + } +} $::MAGIC_SUM +do_test bigfile-1.8 { + db close + sqlite3 db test.db + execsql { + SELECT md5sum(x) FROM t1; + } +} $::MAGIC_SUM +do_test bigfile-1.9 { + execsql { + SELECT md5sum(x) FROM t2; + } +} $::MAGIC_SUM + +db close +if {[catch {fake_big_file 16384 [get_pwd]/test.db}]} { + puts "**** Unable to create a file larger than 16384 MB. *****" + finish_test + return +} +hexio_write test.db 28 00000000 + +do_test bigfile-1.10 { + sqlite3 db test.db + execsql { + SELECT md5sum(x) FROM t1; + } +} $::MAGIC_SUM +do_test bigfile-1.11 { + sqlite3 db test.db + execsql { + SELECT md5sum(x) FROM t2; + } +} $::MAGIC_SUM +do_test bigfile-1.12 { + sqlite3 db test.db + execsql { + SELECT md5sum(x) FROM t3; + } +} $::MAGIC_SUM +do_test bigfile-1.13 { + execsql { + CREATE TABLE t4 AS SELECT * FROM t1; + SELECT md5sum(x) FROM t4; + } +} $::MAGIC_SUM +do_test bigfile-1.14 { + db close + sqlite3 db test.db + execsql { + SELECT md5sum(x) FROM t1; + } +} $::MAGIC_SUM +do_test bigfile-1.15 { + execsql { + SELECT md5sum(x) FROM t2; + } +} $::MAGIC_SUM +do_test bigfile-1.16 { + execsql { + SELECT md5sum(x) FROM t3; + } +} $::MAGIC_SUM + +finish_test diff --git a/test/bigfile2.test b/test/bigfile2.test new file mode 100644 index 0000000..de3b14b --- /dev/null +++ b/test/bigfile2.test @@ -0,0 +1,62 @@ +# 2011 December 20 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script testing the ability of SQLite to handle database +# files larger than 4GB. +# + +if {[file exists skip-big-file]} return +if {$tcl_platform(os)=="Darwin"} return + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix bigfile2 + +# Create a small database. +# +do_execsql_test 1.1 { + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 2); +} + +# Pad the file out to 4GB in size. Then clear the file-size field in the +# db header. This will cause SQLite to assume that the first 4GB of pages +# are actually in use and new pages will be appended to the file. +# +db close +if {[catch {fake_big_file 4096 [get_pwd]/test.db} msg]} { + puts "**** Unable to create a file larger than 4096 MB. *****" + finish_test + return +} +hexio_write test.db 28 00000000 + +do_test 1.2 { + file size test.db +} [expr 14 + 4096 * (1<<20)] + +# Now insert a large row. The overflow pages will be located past the 4GB +# boundary. Then, after opening and closing the database, test that the row +# can be read back in. +# +set str [string repeat k 30000] +do_test 1.3 { + sqlite3 db test.db + execsql { INSERT INTO t1 VALUES(3, $str) } + db close + sqlite3 db test.db + db one { SELECT b FROM t1 WHERE a = 3 } +} $str + +db close +delete_file test.db + +finish_test diff --git a/test/bigmmap.test b/test/bigmmap.test new file mode 100644 index 0000000..ba9f842 --- /dev/null +++ b/test/bigmmap.test @@ -0,0 +1,108 @@ +# 2017 August 07 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script testing the ability of SQLite to use mmap +# to access files larger than 4GiB. +# + +if {[file exists skip-big-file]} return +if {$tcl_platform(os)=="Darwin"} return + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix bigmmap + +ifcapable !mmap||!vtab { + finish_test + return +} + +set mmap_limit 0 +db eval { + SELECT compile_options AS x FROM pragma_compile_options + WHERE x LIKE 'max_mmap_size=%' +} { + regexp {MAX_MMAP_SIZE=([0-9]*)} $x -> mmap_limit +} +if {$mmap_limit < [expr 8 * 1<<30]} { + puts "Skipping bigmmap.test - requires SQLITE_MAX_MMAP_SIZE >= 8G" + finish_test + return +} + + +#------------------------------------------------------------------------- +# Create the database file roughly 8GiB in size. Most pages are unused, +# except that there is a table and index clustered around each 1GiB +# boundary. +# +do_execsql_test 1.0 { + PRAGMA page_size = 4096; + CREATE TABLE t0(a INTEGER PRIMARY KEY, b, c, UNIQUE(b, c)); + WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s LIMIT 100 ) + INSERT INTO t0 SELECT i, 't0', randomblob(800) FROM s; +} + +for {set i 1} {$i < 8} {incr i} { + if {[catch {fake_big_file [expr $i*1024] [get_pwd]/test.db}]} { + puts "Cannot create ${i}MB sparse file" + finish_test + return + } + hexio_write test.db 28 [format %.8x [expr ($i*1024*1024*1024/4096) - 5]] + + do_execsql_test 1.$i " + CREATE TABLE t$i (a INTEGER PRIMARY KEY, b, c, UNIQUE(b, c)); + WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s LIMIT 100 ) + INSERT INTO t$i SELECT i, 't$i', randomblob(800) FROM s; + " +} + +#------------------------------------------------------------------------- +# Check that data can be retrieved from the db with a variety of +# configured mmap size limits. +# +for {set i 0} {$i < 9} {incr i} { + + # Configure a memory mapping $i GB in size. + # + set val [expr $i*1024*1024*1024] + execsql "PRAGMA main.mmap_size = $val" + do_execsql_test 2.$i.0 { + PRAGMA main.mmap_size + } $val + + for {set t 0} {$t < 8} {incr t} { + do_execsql_test 2.$i.$t.1 " + SELECT count(*) FROM t$t; + SELECT count(b || c) FROM t$t GROUP BY b; + " {100 100} + + do_execsql_test 2.$i.$t.2 " + SELECT * FROM t$t AS o WHERE + NOT EXISTS( SELECT * FROM t$t AS i WHERE a=o.a AND +b=o.b AND +c=o.c ) + ORDER BY b, c; + " {} + + do_eqp_test 2.$i.$t.3 " + SELECT * FROM t$t AS o WHERE + NOT EXISTS( SELECT * FROM t$t AS i WHERE a=o.a AND +b=o.b AND +c=o.c ) + ORDER BY b, c; + " [string map {"\n " "\n"} " + QUERY PLAN + |--SCAN o USING COVERING INDEX sqlite_autoindex_t${t}_1 + `--CORRELATED SCALAR SUBQUERY xxxxxx + `--SEARCH i USING INTEGER PRIMARY KEY (rowid=?) + "] + } +} + +finish_test diff --git a/test/bigrow.test b/test/bigrow.test new file mode 100644 index 0000000..fa59c36 --- /dev/null +++ b/test/bigrow.test @@ -0,0 +1,223 @@ +# 2001 September 23 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is stressing the library by putting large amounts +# of data in a single row of a table. +# +# $Id: bigrow.test,v 1.5 2004/08/07 23:54:48 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Make a big string that we can use for test data +# +do_test bigrow-1.0 { + set ::bigstr {} + for {set i 1} {$i<=9999} {incr i} { + set sep [string index "abcdefghijklmnopqrstuvwxyz" [expr {$i%26}]] + append ::bigstr "$sep [format %04d $i] " + } + string length $::bigstr +} {69993} + +# Make a table into which we can insert some but records. +# +do_test bigrow-1.1 { + execsql { + CREATE TABLE t1(a text, b text, c text); + SELECT name FROM sqlite_master + WHERE type='table' OR type='index' + ORDER BY name + } +} {t1} + +do_test bigrow-1.2 { + set ::big1 [string range $::bigstr 0 65519] + set sql "INSERT INTO t1 VALUES('abc'," + append sql "'$::big1', 'xyz');" + execsql $sql + execsql {SELECT a, c FROM t1} +} {abc xyz} +do_test bigrow-1.3 { + execsql {SELECT b FROM t1} +} [list $::big1] +do_test bigrow-1.4 { + set ::big2 [string range $::bigstr 0 65520] + set sql "INSERT INTO t1 VALUES('abc2'," + append sql "'$::big2', 'xyz2');" + set r [catch {execsql $sql} msg] + lappend r $msg +} {0 {}} +do_test bigrow-1.4.1 { + execsql {SELECT b FROM t1 ORDER BY c} +} [list $::big1 $::big2] +do_test bigrow-1.4.2 { + execsql {SELECT c FROM t1 ORDER BY c} +} {xyz xyz2} +do_test bigrow-1.4.3 { + execsql {DELETE FROM t1 WHERE a='abc2'} + execsql {SELECT c FROM t1} +} {xyz} + +do_test bigrow-1.5 { + execsql { + UPDATE t1 SET a=b, b=a; + SELECT b,c FROM t1 + } +} {abc xyz} +do_test bigrow-1.6 { + execsql { + SELECT * FROM t1 + } +} [list $::big1 abc xyz] +do_test bigrow-1.7 { + execsql { + INSERT INTO t1 VALUES('1','2','3'); + INSERT INTO t1 VALUES('A','B','C'); + SELECT b FROM t1 WHERE a=='1'; + } +} {2} +do_test bigrow-1.8 { + execsql "SELECT b FROM t1 WHERE a=='$::big1'" +} {abc} +do_test bigrow-1.9 { + execsql "SELECT b FROM t1 WHERE a!='$::big1' ORDER BY a" +} {2 B} + +# Try doing some indexing on big columns +# +do_test bigrow-2.1 { + execsql { + CREATE INDEX i1 ON t1(a) + } + execsql "SELECT b FROM t1 WHERE a=='$::big1'" +} {abc} +do_test bigrow-2.2 { + execsql { + UPDATE t1 SET a=b, b=a + } + execsql "SELECT b FROM t1 WHERE a=='abc'" +} [list $::big1] +do_test bigrow-2.3 { + execsql { + UPDATE t1 SET a=b, b=a + } + execsql "SELECT b FROM t1 WHERE a=='$::big1'" +} {abc} +catch {unset ::bigstr} +catch {unset ::big1} +catch {unset ::big2} + +# Mosts of the tests above were created back when rows were limited in +# size to 64K. Now rows can be much bigger. Test that logic. Also +# make sure things work correctly at the transition boundries between +# row sizes of 256 to 257 bytes and from 65536 to 65537 bytes. +# +# We begin by testing the 256..257 transition. +# +do_test bigrow-3.1 { + execsql { + DELETE FROM t1; + INSERT INTO t1(a,b,c) VALUES('one','abcdefghijklmnopqrstuvwxyz0123','hi'); + } + execsql {SELECT a,length(b),c FROM t1} +} {one 30 hi} +do_test bigrow-3.2 { + execsql { + UPDATE t1 SET b=b||b; + UPDATE t1 SET b=b||b; + UPDATE t1 SET b=b||b; + } + execsql {SELECT a,length(b),c FROM t1} +} {one 240 hi} +for {set i 1} {$i<10} {incr i} { + do_test bigrow-3.3.$i { + execsql "UPDATE t1 SET b=b||'$i'" + execsql {SELECT a,length(b),c FROM t1} + } "one [expr {240+$i}] hi" +} + +# Now test the 65536..65537 row-size transition. +# +do_test bigrow-4.1 { + execsql { + DELETE FROM t1; + INSERT INTO t1(a,b,c) VALUES('one','abcdefghijklmnopqrstuvwxyz0123','hi'); + } + execsql {SELECT a,length(b),c FROM t1} +} {one 30 hi} +do_test bigrow-4.2 { + execsql { + UPDATE t1 SET b=b||b; + UPDATE t1 SET b=b||b; + UPDATE t1 SET b=b||b; + UPDATE t1 SET b=b||b; + UPDATE t1 SET b=b||b; + UPDATE t1 SET b=b||b; + UPDATE t1 SET b=b||b; + UPDATE t1 SET b=b||b; + UPDATE t1 SET b=b||b; + UPDATE t1 SET b=b||b; + UPDATE t1 SET b=b||b; + UPDATE t1 SET b=b||b; + } + execsql {SELECT a,length(b),c FROM t1} +} {one 122880 hi} +do_test bigrow-4.3 { + execsql { + UPDATE t1 SET b=substr(b,1,65515) + } + execsql {SELECT a,length(b),c FROM t1} +} {one 65515 hi} +for {set i 1} {$i<10} {incr i} { + do_test bigrow-4.4.$i { + execsql "UPDATE t1 SET b=b||'$i'" + execsql {SELECT a,length(b),c FROM t1} + } "one [expr {65515+$i}] hi" +} + +# Check to make sure the library recovers safely if a row contains +# too much data. +# +do_test bigrow-5.1 { + execsql { + DELETE FROM t1; + INSERT INTO t1(a,b,c) VALUES('one','abcdefghijklmnopqrstuvwxyz0123','hi'); + } + execsql {SELECT a,length(b),c FROM t1} +} {one 30 hi} +set i 1 +for {set sz 60} {$sz<1048560} {incr sz $sz} { + do_test bigrow-5.2.$i { + execsql { + UPDATE t1 SET b=b||b; + SELECT a,length(b),c FROM t1; + } + } "one $sz hi" + incr i +} +do_test bigrow-5.3 { + catchsql {UPDATE t1 SET b=b||b} +} {0 {}} +do_test bigrow-5.4 { + execsql {SELECT length(b) FROM t1} +} 1966080 +do_test bigrow-5.5 { + catchsql {UPDATE t1 SET b=b||b} +} {0 {}} +do_test bigrow-5.6 { + execsql {SELECT length(b) FROM t1} +} 3932160 +do_test bigrow-5.99 { + execsql {DROP TABLE t1} +} {} + +finish_test diff --git a/test/bigsort.test b/test/bigsort.test new file mode 100644 index 0000000..61c3344 --- /dev/null +++ b/test/bigsort.test @@ -0,0 +1,57 @@ +# 2014 November 26 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix bigsort + +#-------------------------------------------------------------------- +# At one point there was an overflow problem if the product of the +# cache-size and page-size was larger than 2^31. Causing an infinite +# loop if the product was also an integer multiple of 2^32, or +# inefficiency otherwise. +# +# This test causes thrashing on machines with smaller amounts of +# memory. Make sure the host has at least 8GB available before running +# this test. +# +# Update: https://sqlite.org/src/info/7c96a56 adds assert() statements +# that make this test too slow to run with SQLITE_DEBUG builds. +# +if {[catch {exec free | grep Mem:} out] || [lindex $out 1]<8000000} { + finish_test + return +} +ifcapable debug { + finish_test + return +} + +do_execsql_test 1.0 { + PRAGMA page_size = 1024; + CREATE TABLE t1(a, b); + BEGIN; + WITH data(x,y) AS ( + SELECT 1, zeroblob(10000) + UNION ALL + SELECT x+1, y FROM data WHERE x < 300000 + ) + INSERT INTO t1 SELECT * FROM data; + COMMIT; +} +do_execsql_test 1.1 { + PRAGMA cache_size = 4194304; + CREATE INDEX i1 ON t1(a, b); +} + + +finish_test diff --git a/test/bind.test b/test/bind.test new file mode 100644 index 0000000..8cafaab --- /dev/null +++ b/test/bind.test @@ -0,0 +1,758 @@ +# 2003 September 6 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script testing the sqlite_bind API. +# +# $Id: bind.test,v 1.48 2009/07/22 07:27:57 danielk1977 Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +proc sqlite_step {stmt N VALS COLS} { + upvar VALS vals + upvar COLS cols + set vals [list] + set cols [list] + + set rc [sqlite3_step $stmt] + for {set i 0} {$i < [sqlite3_column_count $stmt]} {incr i} { + lappend cols [sqlite3_column_name $stmt $i] + } + for {set i 0} {$i < [sqlite3_data_count $stmt]} {incr i} { + lappend vals [sqlite3_column_text $stmt $i] + } + + return $rc +} + +do_test bind-1.1 { + set DB [sqlite3_connection_pointer db] + execsql {CREATE TABLE t1(a,b,c);} + set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES(:1,?,:abc)} -1 TAIL] + set TAIL +} {} +do_test bind-1.1.1 { + sqlite3_bind_parameter_count $VM +} 3 +do_test bind-1.1.2 { + sqlite3_bind_parameter_name $VM 1 +} {:1} +do_test bind-1.1.3 { + sqlite3_bind_parameter_name $VM 2 +} {} +do_test bind-1.1.4 { + sqlite3_bind_parameter_name $VM 3 +} {:abc} +do_test bind-1.2 { + sqlite_step $VM N VALUES COLNAMES +} {SQLITE_DONE} +do_test bind-1.3 { + execsql {SELECT rowid, * FROM t1} +} {1 {} {} {}} +do_test bind-1.4 { + sqlite3_reset $VM + sqlite_bind $VM 1 {test value 1} normal + sqlite_step $VM N VALUES COLNAMES +} SQLITE_DONE +do_test bind-1.5 { + execsql {SELECT rowid, * FROM t1} +} {1 {} {} {} 2 {test value 1} {} {}} +do_test bind-1.6 { + sqlite3_reset $VM + sqlite_bind $VM 3 {'test value 2'} normal + sqlite_step $VM N VALUES COLNAMES +} SQLITE_DONE +do_test bind-1.7 { + execsql {SELECT rowid, * FROM t1} +} {1 {} {} {} 2 {test value 1} {} {} 3 {test value 1} {} {'test value 2'}} +do_test bind-1.8 { + sqlite3_reset $VM + set sqlite_static_bind_value 123 + sqlite_bind $VM 1 {} static + sqlite_bind $VM 2 {abcdefg} normal + sqlite_bind $VM 3 {} null + execsql {DELETE FROM t1} + sqlite_step $VM N VALUES COLNAMES + execsql {SELECT rowid, * FROM t1} +} {1 123 abcdefg {}} +do_test bind-1.9 { + sqlite3_reset $VM + sqlite_bind $VM 1 {456} normal + sqlite_step $VM N VALUES COLNAMES + execsql {SELECT rowid, * FROM t1} +} {1 123 abcdefg {} 2 456 abcdefg {}} + +do_test bind-1.10 { + set rc [catch { + sqlite3_prepare db {INSERT INTO t1 VALUES($abc:123,?,:abc)} -1 TAIL + } msg] + lappend rc $msg +} {1 {(1) near ":123": syntax error}} +do_test bind-1.11 { + set rc [catch { + sqlite3_prepare db {INSERT INTO t1 VALUES(@abc:xyz,?,:abc)} -1 TAIL + } msg] + lappend rc $msg +} {1 {(1) near ":xyz": syntax error}} + +do_test bind-1.99 { + sqlite3_finalize $VM +} SQLITE_OK + +# Prepare the statement in different ways depending on whether or not +# the $var processing is compiled into the library. +# +ifcapable {tclvar} { + do_test bind-2.1 { + execsql { + DELETE FROM t1; + } + set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES($one,$::two,$x(-z-))}\ + -1 TX] + set TX + } {} + set v1 {$one} + set v2 {$::two} + set v3 {$x(-z-)} +} +ifcapable {!tclvar} { + do_test bind-2.1 { + execsql { + DELETE FROM t1; + } + set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES(:one,:two,:_)} -1 TX] + set TX + } {} + set v1 {:one} + set v2 {:two} + set v3 {:_} +} + +do_test bind-2.1.1 { + sqlite3_bind_parameter_count $VM +} 3 +do_test bind-2.1.2 { + sqlite3_bind_parameter_name $VM 1 +} $v1 +do_test bind-2.1.3 { + sqlite3_bind_parameter_name $VM 2 +} $v2 +do_test bind-2.1.4 { + sqlite3_bind_parameter_name $VM 3 +} $v3 +do_test bind-2.1.5 { + sqlite3_bind_parameter_index $VM $v1 +} 1 +do_test bind-2.1.6 { + sqlite3_bind_parameter_index $VM $v2 +} 2 +do_test bind-2.1.7 { + sqlite3_bind_parameter_index $VM $v3 +} 3 +do_test bind-2.1.8 { + sqlite3_bind_parameter_index $VM {:hi} +} 0 + +# 32 bit Integers +do_test bind-2.2 { + sqlite3_bind_int $VM 1 123 + sqlite3_bind_int $VM 2 456 + sqlite3_bind_int $VM 3 789 + sqlite_step $VM N VALUES COLNAMES + sqlite3_reset $VM + execsql {SELECT rowid, * FROM t1} +} {1 123 456 789} +do_test bind-2.3 { + sqlite3_bind_int $VM 2 -2000000000 + sqlite3_bind_int $VM 3 2000000000 + sqlite_step $VM N VALUES COLNAMES + sqlite3_reset $VM + execsql {SELECT rowid, * FROM t1} +} {1 123 456 789 2 123 -2000000000 2000000000} +do_test bind-2.4 { + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1} +} {integer integer integer integer integer integer} +do_test bind-2.5 { + execsql { + DELETE FROM t1; + } +} {} + +# 64 bit Integers +do_test bind-3.1 { + sqlite3_bind_int64 $VM 1 32 + sqlite3_bind_int64 $VM 2 -2000000000000 + sqlite3_bind_int64 $VM 3 2000000000000 + sqlite_step $VM N VALUES COLNAMES + sqlite3_reset $VM + execsql {SELECT rowid, * FROM t1} +} {1 32 -2000000000000 2000000000000} +do_test bind-3.2 { + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1} +} {integer integer integer} +do_test bind-3.3 { + execsql { + DELETE FROM t1; + } +} {} + +# Doubles +do_test bind-4.1 { + sqlite3_bind_double $VM 1 1234.1234 + sqlite3_bind_double $VM 2 0.00001 + sqlite3_bind_double $VM 3 123456789 + sqlite_step $VM N VALUES COLNAMES + sqlite3_reset $VM + set x [execsql {SELECT rowid, * FROM t1}] + regsub {1e-005} $x {1e-05} y + set y +} {1 1234.1234 1e-05 123456789.0} +do_test bind-4.2 { + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1} +} {real real real} +do_test bind-4.3 { + execsql { + DELETE FROM t1; + } +} {} +do_test bind-4.4 { + sqlite3_bind_double $VM 1 NaN + sqlite3_bind_double $VM 2 1e300 + sqlite3_bind_double $VM 3 -1e-300 + sqlite_step $VM N VALUES COLNAMES + sqlite3_reset $VM + set x [execsql {SELECT rowid, * FROM t1}] + regsub {1e-005} $x {1e-05} y + set y +} {1 {} 1e+300 -1e-300} +do_test bind-4.5 { + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1} +} {null real real} +do_test bind-4.6 { + execsql { + DELETE FROM t1; + } +} {} + +# NULL +do_test bind-5.1 { + sqlite3_bind_null $VM 1 + sqlite3_bind_null $VM 2 + sqlite3_bind_null $VM 3 + sqlite_step $VM N VALUES COLNAMES + sqlite3_reset $VM + execsql {SELECT rowid, * FROM t1} +} {1 {} {} {}} +do_test bind-5.2 { + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1} +} {null null null} +do_test bind-5.3 { + execsql { + DELETE FROM t1; + } +} {} + +# UTF-8 text +do_test bind-6.1 { + sqlite3_bind_text $VM 1 hellothere 5 + sqlite3_bind_text $VM 2 ".." 1 + sqlite3_bind_text $VM 3 world\000 -1 + sqlite_step $VM N VALUES COLNAMES + sqlite3_reset $VM + execsql {SELECT rowid, * FROM t1} +} {1 hello . world} +do_test bind-6.2 { + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1} +} {text text text} +do_test bind-6.3 { + execsql { + DELETE FROM t1; + } +} {} + +# Make sure zeros in a string work. +# +do_test bind-6.4 { + db eval {DELETE FROM t1} + sqlite3_bind_text $VM 1 hello\000there\000 12 + sqlite3_bind_text $VM 2 hello\000there\000 11 + sqlite3_bind_text $VM 3 hello\000there\000 -1 + sqlite_step $VM N VALUES COLNAMES + sqlite3_reset $VM + execsql {SELECT * FROM t1} +} {hello hello hello} +set enc [db eval {PRAGMA encoding}] +if {$enc=="UTF-8" || $enc==""} { + do_test bind-6.5 { + execsql {SELECT hex(a), hex(b), hex(c) FROM t1} + } {68656C6C6F00746865726500 68656C6C6F007468657265 68656C6C6F} +} elseif {$enc=="UTF-16le"} { + do_test bind-6.5 { + execsql {SELECT hex(a), hex(b), hex(c) FROM t1} + } {680065006C006C006F000000740068006500720065000000 680065006C006C006F00000074006800650072006500 680065006C006C006F00} +} elseif {$enc=="UTF-16be"} { + do_test bind-6.5 { + execsql {SELECT hex(a), hex(b), hex(c) FROM t1} + } {00680065006C006C006F0000007400680065007200650000 00680065006C006C006F000000740068006500720065 00680065006C006C006F} +} else { + do_test bind-6.5 { + set "Unknown database encoding: $::enc" + } {} +} +do_test bind-6.6 { + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1} +} {text text text} +do_test bind-6.7 { + execsql { + DELETE FROM t1; + } +} {} + +# UTF-16 text +ifcapable {utf16} { + do_test bind-7.1 { + sqlite3_bind_text16 $VM 1 [encoding convertto unicode hellothere] 10 + sqlite3_bind_text16 $VM 2 [encoding convertto unicode ""] 0 + sqlite3_bind_text16 $VM 3 [encoding convertto unicode world] 10 + sqlite_step $VM N VALUES COLNAMES + sqlite3_reset $VM + execsql {SELECT rowid, * FROM t1} + } {1 hello {} world} + do_test bind-7.2 { + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1} + } {text text text} + do_test bind-7.3 { + db eval {DELETE FROM t1} + sqlite3_bind_text16 $VM 1 [encoding convertto unicode hi\000yall\000] 16 + sqlite3_bind_text16 $VM 2 [encoding convertto unicode hi\000yall\000] 14 + sqlite3_bind_text16 $VM 3 [encoding convertto unicode hi\000yall\000] -1 + sqlite_step $VM N VALUES COLNAMES + sqlite3_reset $VM + execsql {SELECT * FROM t1} + } {hi hi hi} + if {$enc=="UTF-8"} { + do_test bind-7.4 { + execsql {SELECT hex(a), hex(b), hex(c) FROM t1} + } {68690079616C6C00 68690079616C6C 6869} + } elseif {$enc=="UTF-16le"} { + do_test bind-7.4 { + execsql {SELECT hex(a), hex(b), hex(c) FROM t1} + } {680069000000790061006C006C000000 680069000000790061006C006C00 68006900} + } elseif {$enc=="UTF-16be"} { + do_test bind-7.4 { + execsql {SELECT hex(a), hex(b), hex(c) FROM t1} + } {00680069000000790061006C006C0000 00680069000000790061006C006C 00680069} + } + do_test bind-7.5 { + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1} + } {text text text} +} +do_test bind-7.99 { + execsql {DELETE FROM t1;} +} {} + +# Test that the 'out of range' error works. +do_test bind-8.1 { + catch { sqlite3_bind_null $VM 0 } +} {1} +do_test bind-8.2 { + sqlite3_errmsg $DB +} {column index out of range} +ifcapable {utf16} { + do_test bind-8.3 { + encoding convertfrom unicode [sqlite3_errmsg16 $DB] + } {column index out of range} +} +do_test bind-8.4 { + sqlite3_bind_null $VM 1 + sqlite3_errmsg $DB +} {not an error} +do_test bind-8.5 { + catch { sqlite3_bind_null $VM 4 } +} {1} +do_test bind-8.6 { + sqlite3_errmsg $DB +} {column index out of range} +ifcapable {utf16} { + do_test bind-8.7 { + encoding convertfrom unicode [sqlite3_errmsg16 $DB] + } {column index out of range} +} + +do_test bind-8.8 { + catch { sqlite3_bind_blob $VM 0 "abc" 3 } +} {1} +do_test bind-8.9 { + catch { sqlite3_bind_blob $VM 4 "abc" 3 } +} {1} +do_test bind-8.10 { + catch { sqlite3_bind_text $VM 0 "abc" 3 } +} {1} +ifcapable {utf16} { + do_test bind-8.11 { + catch { sqlite3_bind_text16 $VM 4 "abc" 2 } + } {1} +} +do_test bind-8.12 { + catch { sqlite3_bind_int $VM 0 5 } +} {1} +do_test bind-8.13 { + catch { sqlite3_bind_int $VM 4 5 } +} {1} +do_test bind-8.14 { + catch { sqlite3_bind_double $VM 0 5.0 } +} {1} +do_test bind-8.15 { + catch { sqlite3_bind_double $VM 4 6.0 } +} {1} + +do_test bind-8.99 { + sqlite3_finalize $VM +} SQLITE_OK + +set iMaxVar $SQLITE_MAX_VARIABLE_NUMBER +set zError "(1) variable number must be between ?1 and ?$iMaxVar" +do_test bind-9.1 { + execsql { + CREATE TABLE t2(a,b,c,d,e,f); + } + set rc [catch { + sqlite3_prepare $DB { + INSERT INTO t2(a) VALUES(?0) + } -1 TAIL + } msg] + lappend rc $msg +} [list 1 $zError] +do_test bind-9.2 { + set rc [catch { + sqlite3_prepare $DB "INSERT INTO t2(a) VALUES(?[expr $iMaxVar+1])" -1 TAIL + } msg] + lappend rc $msg +} [list 1 $zError] +do_test bind-9.3.1 { + set VM [ + sqlite3_prepare $DB " + INSERT INTO t2(a,b) VALUES(?1,?$iMaxVar) + " -1 TAIL + ] + sqlite3_bind_parameter_count $VM +} $iMaxVar +catch {sqlite3_finalize $VM} +do_test bind-9.3.2 { + set VM [ + sqlite3_prepare $DB " + INSERT INTO t2(a,b) VALUES(?2,?[expr $iMaxVar - 1]) + " -1 TAIL + ] + sqlite3_bind_parameter_count $VM +} [expr {$iMaxVar - 1}] +catch {sqlite3_finalize $VM} +do_test bind-9.4 { + set VM [ + sqlite3_prepare $DB " + INSERT INTO t2(a,b,c,d) VALUES(?1,?[expr $iMaxVar - 2],?,?) + " -1 TAIL + ] + sqlite3_bind_parameter_count $VM +} $iMaxVar +do_test bind-9.5 { + sqlite3_bind_int $VM 1 1 + sqlite3_bind_int $VM [expr $iMaxVar - 2] 999 + sqlite3_bind_int $VM [expr $iMaxVar - 1] 1000 + sqlite3_bind_int $VM $iMaxVar 1001 + sqlite3_step $VM +} SQLITE_DONE +do_test bind-9.6 { + sqlite3_finalize $VM +} SQLITE_OK +do_test bind-9.7 { + execsql {SELECT * FROM t2} +} {1 999 1000 1001 {} {}} + +ifcapable {tclvar} { + do_test bind-10.1 { + set VM [ + sqlite3_prepare $DB { + INSERT INTO t2(a,b,c,d,e,f) VALUES(:abc,$abc,:abc,$ab,$abc,:abc) + } -1 TAIL + ] + sqlite3_bind_parameter_count $VM + } 3 + set v1 {$abc} + set v2 {$ab} +} +ifcapable {!tclvar} { + do_test bind-10.1 { + set VM [ + sqlite3_prepare $DB { + INSERT INTO t2(a,b,c,d,e,f) VALUES(:abc,:xyz,:abc,:xy,:xyz,:abc) + } -1 TAIL + ] + sqlite3_bind_parameter_count $VM + } 3 + set v1 {:xyz} + set v2 {:xy} +} +do_test bind-10.2 { + sqlite3_bind_parameter_index $VM :abc +} 1 +do_test bind-10.3 { + sqlite3_bind_parameter_index $VM $v1 +} 2 +do_test bind-10.4 { + sqlite3_bind_parameter_index $VM $v2 +} 3 +do_test bind-10.5 { + sqlite3_bind_parameter_name $VM 1 +} :abc +do_test bind-10.6 { + sqlite3_bind_parameter_name $VM 2 +} $v1 +do_test bind-10.7 { + sqlite3_bind_parameter_name $VM 3 +} $v2 +do_test bind-10.7.1 { + sqlite3_bind_parameter_name 0 1 ;# Ignore if VM is NULL +} {} +do_test bind-10.7.2 { + sqlite3_bind_parameter_name $VM 0 ;# Ignore if index too small +} {} +do_test bind-10.7.3 { + sqlite3_bind_parameter_name $VM 4 ;# Ignore if index is too big +} {} +do_test bind-10.8 { + sqlite3_bind_int $VM 1 1 + sqlite3_bind_int $VM 2 2 + sqlite3_bind_int $VM 3 3 + sqlite3_step $VM +} SQLITE_DONE +do_test bind-10.8.1 { + # Binding attempts after program start should fail + set rc [catch { + sqlite3_bind_int $VM 1 1 + } msg] + lappend rc $msg +} {1 {}} +do_test bind-10.9 { + sqlite3_finalize $VM +} SQLITE_OK +do_test bind-10.10 { + execsql {SELECT * FROM t2} +} {1 999 1000 1001 {} {} 1 2 1 3 2 1} + +# Ticket #918 +# +do_test bind-10.11 { + # catch {sqlite3_finalize $VM} + set VM [ + sqlite3_prepare $DB { + INSERT INTO t2(a,b,c,d,e,f) VALUES(:abc,?,?4,:pqr,:abc,?4) + } -1 TAIL + ] + sqlite3_bind_parameter_count $VM +} 5 +do_test bind-10.11.1 { + sqlite3_bind_parameter_index 0 :xyz ;# ignore NULL VM arguments +} 0 +do_test bind-10.12 { + sqlite3_bind_parameter_index $VM :xyz +} 0 +do_test bind-10.13 { + sqlite3_bind_parameter_index $VM {} +} 0 +do_test bind-10.14 { + sqlite3_bind_parameter_index $VM :pqr +} 5 +do_test bind-10.15 { + sqlite3_bind_parameter_index $VM ?4 +} 4 +do_test bind-10.16 { + sqlite3_bind_parameter_name $VM 1 +} :abc +do_test bind-10.17 { + sqlite3_bind_parameter_name $VM 2 +} {} +do_test bind-10.18 { + sqlite3_bind_parameter_name $VM 3 +} {} +do_test bind-10.19 { + sqlite3_bind_parameter_name $VM 4 +} {?4} +do_test bind-10.20 { + sqlite3_bind_parameter_name $VM 5 +} :pqr +catch {sqlite3_finalize $VM} + +# Make sure we catch an unterminated "(" in a Tcl-style variable name +# +ifcapable tclvar { + do_test bind-11.1 { + catchsql {SELECT * FROM sqlite_master WHERE name=$abc(123 and sql NOT NULL;} + } {1 {unrecognized token: "$abc(123"}} +} + +if {[execsql {pragma encoding}]=="UTF-8"} { + # Test the ability to bind text that contains embedded '\000' characters. + # Make sure we can recover the entire input string. + # + do_test bind-12.1 { + execsql { + CREATE TABLE t3(x BLOB); + } + set VM [sqlite3_prepare $DB {INSERT INTO t3 VALUES(?)} -1 TAIL] + sqlite_bind $VM 1 not-used blob10 + sqlite3_step $VM + sqlite3_finalize $VM + execsql { + SELECT typeof(x), length(x), quote(x), + length(cast(x AS BLOB)), quote(cast(x AS BLOB)) FROM t3 + } + } {text 3 'abc' 10 X'6162630078797A007071'} + do_test bind-12.2 { + sqlite3_create_function $DB + execsql { + SELECT quote(cast(x_coalesce(x) AS blob)) FROM t3 + } + } {X'6162630078797A007071'} +} + +# Test the operation of sqlite3_clear_bindings +# +do_test bind-13.1 { + set VM [sqlite3_prepare $DB {SELECT ?,?,?} -1 TAIL] + sqlite3_step $VM + list [sqlite3_column_type $VM 0] [sqlite3_column_type $VM 1] \ + [sqlite3_column_type $VM 2] +} {NULL NULL NULL} +do_test bind-13.2 { + sqlite3_reset $VM + sqlite3_bind_int $VM 1 1 + sqlite3_bind_int $VM 2 2 + sqlite3_bind_int $VM 3 3 + sqlite3_step $VM + list [sqlite3_column_type $VM 0] [sqlite3_column_type $VM 1] \ + [sqlite3_column_type $VM 2] +} {INTEGER INTEGER INTEGER} +do_test bind-13.3 { + sqlite3_reset $VM + sqlite3_step $VM + list [sqlite3_column_type $VM 0] [sqlite3_column_type $VM 1] \ + [sqlite3_column_type $VM 2] +} {INTEGER INTEGER INTEGER} +do_test bind-13.4 { + sqlite3_reset $VM + sqlite3_clear_bindings $VM + sqlite3_step $VM + list [sqlite3_column_type $VM 0] [sqlite3_column_type $VM 1] \ + [sqlite3_column_type $VM 2] +} {NULL NULL NULL} +sqlite3_finalize $VM + +#-------------------------------------------------------------------- +# These tests attempt to reproduce bug #3463. +# +proc param_names {db zSql} { + set ret [list] + set VM [sqlite3_prepare db $zSql -1 TAIL] + for {set ii 1} {$ii <= [sqlite3_bind_parameter_count $VM]} {incr ii} { + lappend ret [sqlite3_bind_parameter_name $VM $ii] + } + sqlite3_finalize $VM + set ret +} + +do_test bind-14.1 { + param_names db { SELECT @a, @b } +} {@a @b} +do_test bind-14.2 { + param_names db { SELECT NULL FROM (SELECT NULL) WHERE @a = @b } +} {@a @b} +do_test bind-14.3 { + param_names db { SELECT @a FROM (SELECT NULL) WHERE 1 = @b } +} {@a @b} +do_test bind-14.4 { + param_names db { SELECT @a, @b FROM (SELECT NULL) } +} {@a @b} + +#-------------------------------------------------------------------------- +# Tests of the OP_Variable opcode where P3>1 +# +do_test bind-15.1 { + db eval {CREATE TABLE t4(a,b,c,d,e,f,g,h);} + set VM [sqlite3_prepare db { + INSERT INTO t4(a,b,c,d,f,g,h,e) VALUES(?,?,?,?,?,?,?,?) + } -1 TAIL] + sqlite3_bind_int $VM 1 1 + sqlite3_bind_int $VM 2 2 + sqlite3_bind_int $VM 3 3 + sqlite3_bind_int $VM 4 4 + sqlite3_bind_int $VM 5 5 + sqlite3_bind_int $VM 6 6 + sqlite3_bind_int $VM 7 7 + sqlite3_bind_int $VM 8 8 + sqlite3_step $VM + sqlite3_finalize $VM + db eval {SELECT * FROM t4} +} {1 2 3 4 8 5 6 7} +do_test bind-15.2 { + db eval {DELETE FROM t4} + set VM [sqlite3_prepare db { + INSERT INTO t4(a,b,c,d,e,f,g,h) VALUES(?,?,?,?,?,?,?,?) + } -1 TAIL] + sqlite3_bind_int $VM 1 1 + sqlite3_bind_int $VM 2 2 + sqlite3_bind_int $VM 3 3 + sqlite3_bind_int $VM 4 4 + sqlite3_bind_int $VM 5 5 + sqlite3_bind_int $VM 6 6 + sqlite3_bind_int $VM 7 7 + sqlite3_bind_int $VM 8 8 + sqlite3_step $VM + sqlite3_finalize $VM + db eval {SELECT * FROM t4} +} {1 2 3 4 5 6 7 8} +do_test bind-15.3 { + db eval {DELETE FROM t4} + set VM [sqlite3_prepare db { + INSERT INTO t4(h,g,f,e,d,c,b,a) VALUES(?,?,?,?,?,?,?,?) + } -1 TAIL] + sqlite3_bind_int $VM 1 1 + sqlite3_bind_int $VM 2 2 + sqlite3_bind_int $VM 3 3 + sqlite3_bind_int $VM 4 4 + sqlite3_bind_int $VM 5 5 + sqlite3_bind_int $VM 6 6 + sqlite3_bind_int $VM 7 7 + sqlite3_bind_int $VM 8 8 + sqlite3_step $VM + sqlite3_finalize $VM + db eval {SELECT * FROM t4} +} {8 7 6 5 4 3 2 1} +do_test bind-15.4 { + db eval {DELETE FROM t4} + set VM [sqlite3_prepare db { + INSERT INTO t4(a,b,c,d,e,f,g,h) VALUES(?,?,?,?4,?,?6,?,?) + } -1 TAIL] + sqlite3_bind_int $VM 1 1 + sqlite3_bind_int $VM 2 2 + sqlite3_bind_int $VM 3 3 + sqlite3_bind_int $VM 4 4 + sqlite3_bind_int $VM 5 5 + sqlite3_bind_int $VM 6 6 + sqlite3_bind_int $VM 7 7 + sqlite3_bind_int $VM 8 8 + sqlite3_step $VM + sqlite3_finalize $VM + db eval {SELECT * FROM t4} +} {1 2 3 4 5 6 7 8} + +finish_test diff --git a/test/bind2.test b/test/bind2.test new file mode 100644 index 0000000..1ebf35c --- /dev/null +++ b/test/bind2.test @@ -0,0 +1,63 @@ +# 2022 Feb 10 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix bind2 + + +# Test that using bind_value() on a REAL sqlite3_value that was stored +# as an INTEGER works properly. +# +# 1.1: An IntReal value read from a table, +# 1.2: IntReal values obtained via the sqlite3_preupdate_old|new() +# interfaces. +# +do_execsql_test 1.0 { + CREATE TABLE t1(a REAL); + INSERT INTO t1 VALUES(42.0); + SELECT * FROM t1; +} {42.0} + +do_test 1.1 { + set stmt [sqlite3_prepare db "SELECT ?" -1 tail] + sqlite3_bind_value_from_select $stmt 1 "SELECT a FROM t1" + sqlite3_step $stmt + sqlite3_column_text $stmt 0 +} {42.0} +sqlite3_finalize $stmt + +ifcapable !preupdate { + finish_test + return +} + +proc preup {args} { + set stmt [sqlite3_prepare db "SELECT ?" -1 tail] + sqlite3_bind_value_from_preupdate $stmt 1 old 0 + sqlite3_step $stmt + lappend ::reslist [sqlite3_column_text $stmt 0] + sqlite3_reset $stmt + sqlite3_bind_value_from_preupdate $stmt 1 new 0 + sqlite3_step $stmt + lappend ::reslist [sqlite3_column_text $stmt 0] + sqlite3_finalize $stmt +} +db preupdate hook preup + +do_test 1.2 { + set ::reslist [list] + execsql { UPDATE t1 SET a=43; } + set ::reslist +} {42.0 43.0} + +finish_test diff --git a/test/bindxfer.test b/test/bindxfer.test new file mode 100644 index 0000000..393aab9 --- /dev/null +++ b/test/bindxfer.test @@ -0,0 +1,76 @@ +# 2005 April 21 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script testing the sqlite_transfer_bindings() API. +# +# $Id: bindxfer.test,v 1.9 2009/04/17 11:56:28 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +proc sqlite_step {stmt VALS COLS} { + upvar #0 $VALS vals + upvar #0 $COLS cols + set vals [list] + set cols [list] + + set rc [sqlite3_step $stmt] + for {set i 0} {$i < [sqlite3_column_count $stmt]} {incr i} { + lappend cols [sqlite3_column_name $stmt $i] + } + for {set i 0} {$i < [sqlite3_data_count $stmt]} {incr i} { + lappend vals [sqlite3_column_text $stmt $i] + } + + return $rc +} + +do_test bindxfer-1.1 { + set DB [sqlite3_connection_pointer db] + execsql {CREATE TABLE t1(a,b,c);} + set VM1 [sqlite3_prepare $DB {SELECT ?, ?, ?} -1 TAIL] + set TAIL +} {} +do_test bindxfer-1.2 { + sqlite3_bind_parameter_count $VM1 +} 3 +do_test bindxfer-1.3 { + set VM2 [sqlite3_prepare $DB {SELECT ?, ?, ?} -1 TAIL] + set TAIL +} {} +do_test bindxfer-1.4 { + sqlite3_bind_parameter_count $VM2 +} 3 +ifcapable deprecated { + do_test bindxfer-1.5 { + sqlite_bind $VM1 1 one normal + set sqlite_static_bind_value two + sqlite_bind $VM1 2 {} static + sqlite_bind $VM1 3 {} null + sqlite3_transfer_bindings $VM1 $VM2 + sqlite_step $VM1 VALUES COLNAMES + } SQLITE_ROW + do_test bindxfer-1.6 { + set VALUES + } {{} {} {}} + do_test bindxfer-1.7 { + sqlite_step $VM2 VALUES COLNAMES + } SQLITE_ROW + do_test bindxfer-1.8 { + set VALUES + } {one two {}} +} +catch {sqlite3_finalize $VM1} +catch {sqlite3_finalize $VM2} + + +finish_test diff --git a/test/bitvec.test b/test/bitvec.test new file mode 100644 index 0000000..d27f927 --- /dev/null +++ b/test/bitvec.test @@ -0,0 +1,195 @@ +# 2008 February 18 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Unit testing of the Bitvec object. +# +# $Id: bitvec.test,v 1.4 2009/04/01 23:49:04 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# The built-in test logic must be operational in order for +# this test to work. +ifcapable !builtin_test { + finish_test + return +} + +# Test that sqlite3BitvecBuiltinTest correctly reports errors +# that are deliberately introduced. +# +do_test bitvec-1.0.1 { + sqlite3BitvecBuiltinTest 400 {5 1 1 1 0} +} 1 +do_test bitvec-1.0.2 { + sqlite3BitvecBuiltinTest 400 {5 1 234 1 0} +} 234 + +# Run test cases that set every bit in vectors of various sizes. +# for larger cases, this should cycle the bit vector representation +# from hashing into subbitmaps. The subbitmaps should start as +# hashes then change to either subbitmaps or linear maps, depending +# on their size. +# +do_test bitvec-1.1 { + sqlite3BitvecBuiltinTest 400 {1 400 1 1 0} +} 0 +do_test bitvec-1.2 { + sqlite3BitvecBuiltinTest 4000 {1 4000 1 1 0} +} 0 +do_test bitvec-1.3 { + sqlite3BitvecBuiltinTest 40000 {1 40000 1 1 0} +} 0 +do_test bitvec-1.4 { + sqlite3BitvecBuiltinTest 400000 {1 400000 1 1 0} +} 0 + +# By specifying a larger increments, we spread the load around. +# +do_test bitvec-1.5 { + sqlite3BitvecBuiltinTest 400 {1 400 1 7 0} +} 0 +do_test bitvec-1.6 { + sqlite3BitvecBuiltinTest 4000 {1 4000 1 7 0} +} 0 +do_test bitvec-1.7 { + sqlite3BitvecBuiltinTest 40000 {1 40000 1 7 0} +} 0 +do_test bitvec-1.8 { + sqlite3BitvecBuiltinTest 400000 {1 400000 1 7 0} +} 0 + +# First fill up the bitmap with ones, then go through and +# clear all the bits. This will stress the clearing mechanism. +# +do_test bitvec-1.9 { + sqlite3BitvecBuiltinTest 400 {1 400 1 1 2 400 1 1 0} +} 0 +do_test bitvec-1.10 { + sqlite3BitvecBuiltinTest 4000 {1 4000 1 1 2 4000 1 1 0} +} 0 +do_test bitvec-1.11 { + sqlite3BitvecBuiltinTest 40000 {1 40000 1 1 2 40000 1 1 0} +} 0 +do_test bitvec-1.12 { + sqlite3BitvecBuiltinTest 400000 {1 400000 1 1 2 400000 1 1 0} +} 0 + +do_test bitvec-1.13 { + sqlite3BitvecBuiltinTest 400 {1 400 1 1 2 400 1 7 0} +} 0 +do_test bitvec-1.15 { + sqlite3BitvecBuiltinTest 4000 {1 4000 1 1 2 4000 1 7 0} +} 0 +do_test bitvec-1.16 { + sqlite3BitvecBuiltinTest 40000 {1 40000 1 1 2 40000 1 77 0} +} 0 +do_test bitvec-1.17 { + sqlite3BitvecBuiltinTest 400000 {1 400000 1 1 2 400000 1 777 0} +} 0 + +do_test bitvec-1.18 { + sqlite3BitvecBuiltinTest 400000 {1 5000 100000 1 2 400000 1 37 0} +} 0 + +# Attempt to induce hash collisions. +# +unset -nocomplain start +unset -nocomplain incr +foreach start {1 2 3 4 5 6 7 8} { + foreach incr {124 125} { + do_test bitvec-1.20.$start.$incr { + set prog [list 1 60 $::start $::incr 2 5000 1 1 0] + sqlite3BitvecBuiltinTest 5000 $prog + } 0 + } +} + +do_test bitvec-1.30.big_and_slow { + sqlite3BitvecBuiltinTest 17000000 {1 17000000 1 1 2 17000000 1 1 0} +} 0 + + +# Test setting and clearing a random subset of bits. +# +do_test bitvec-2.1 { + sqlite3BitvecBuiltinTest 4000 {3 2000 4 2000 0} +} 0 +do_test bitvec-2.2 { + sqlite3BitvecBuiltinTest 4000 {3 1000 4 1000 3 1000 4 1000 3 1000 4 1000 + 3 1000 4 1000 3 1000 4 1000 3 1000 4 1000 0} +} 0 +do_test bitvec-2.3 { + sqlite3BitvecBuiltinTest 400000 {3 10 0} +} 0 +do_test bitvec-2.4 { + sqlite3BitvecBuiltinTest 4000 {3 10 2 4000 1 1 0} +} 0 +do_test bitvec-2.5 { + sqlite3BitvecBuiltinTest 5000 {3 20 2 5000 1 1 0} +} 0 +do_test bitvec-2.6 { + sqlite3BitvecBuiltinTest 50000 {3 60 2 50000 1 1 0} +} 0 +do_test bitvec-2.7 { + sqlite3BitvecBuiltinTest 5000 { + 1 25 121 125 + 1 50 121 125 + 2 25 121 125 + 0 + } +} 0 + +# This procedure runs sqlite3BitvecBuiltinTest with argments "n" and +# "program". But it also causes a malloc error to occur after the +# "failcnt"-th malloc. The result should be "0" if no malloc failure +# occurs or "-1" if there is a malloc failure. +# +proc bitvec_malloc_test {label failcnt n program} { + do_test $label [subst { + sqlite3_memdebug_fail $failcnt + set x \[sqlite3BitvecBuiltinTest $n [list $program]\] + set nFail \[sqlite3_memdebug_fail -1\] + if {\$nFail==0} { + set ::go 0 + set x -1 + } + set x + }] -1 +} + +# Make sure malloc failures are handled sanily. +# +unset -nocomplain n +unset -nocomplain go +set go 1 +save_prng_state +for {set n 0} {$go} {incr n} { + restore_prng_state + bitvec_malloc_test bitvec-3.1.$n $n 5000 { + 3 60 2 5000 1 1 3 60 2 5000 1 1 3 60 2 5000 1 1 0 + } +} +set go 1 +for {set n 0} {$go} {incr n} { + restore_prng_state + bitvec_malloc_test bitvec-3.2.$n $n 5000 { + 3 600 2 5000 1 1 3 600 2 5000 1 1 3 600 2 5000 1 1 0 + } +} +set go 1 +for {set n 1} {$go} {incr n} { + bitvec_malloc_test bitvec-3.3.$n $n 50000 {1 50000 1 1 0} +} + +finish_test +return diff --git a/test/blob.test b/test/blob.test new file mode 100644 index 0000000..b1aae38 --- /dev/null +++ b/test/blob.test @@ -0,0 +1,147 @@ +# 2001 September 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# $Id: blob.test,v 1.8 2009/04/28 18:00:27 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable {!bloblit} { + finish_test + return +} + +proc bin_to_hex {blob} { + set bytes {} + binary scan $blob \c* bytes + set bytes2 [list] + foreach b $bytes {lappend bytes2 [format %02X [expr $b & 0xFF]]} + join $bytes2 {} +} + +# Simplest possible case. Specify a blob literal +do_test blob-1.0 { + set blob [execsql {SELECT X'01020304';}] + bin_to_hex [lindex $blob 0] +} {01020304} +do_test blob-1.1 { + set blob [execsql {SELECT x'ABCDEF';}] + bin_to_hex [lindex $blob 0] +} {ABCDEF} +do_test blob-1.2 { + set blob [execsql {SELECT x'';}] + bin_to_hex [lindex $blob 0] +} {} +do_test blob-1.3 { + set blob [execsql {SELECT x'abcdEF12';}] + bin_to_hex [lindex $blob 0] +} {ABCDEF12} +do_test blob-1.3.2 { + set blob [execsql {SELECT x'0123456789abcdefABCDEF';}] + bin_to_hex [lindex $blob 0] +} {0123456789ABCDEFABCDEF} + +# Try some syntax errors in blob literals. +do_test blob-1.4 { + catchsql {SELECT X'01020k304', 100} +} {1 {unrecognized token: "X'01020k304'"}} +do_test blob-1.5 { + catchsql {SELECT X'01020, 100} +} {1 {unrecognized token: "X'01020, 100"}} +do_test blob-1.6 { + catchsql {SELECT X'01020 100'} +} {1 {unrecognized token: "X'01020 100'"}} +do_test blob-1.7 { + catchsql {SELECT X'01001'} +} {1 {unrecognized token: "X'01001'"}} +do_test blob-1.8 { + catchsql {SELECT x'012/45'} +} {1 {unrecognized token: "x'012/45'"}} +do_test blob-1.9 { + catchsql {SELECT x'012:45'} +} {1 {unrecognized token: "x'012:45'"}} +do_test blob-1.10 { + catchsql {SELECT x'012@45'} +} {1 {unrecognized token: "x'012@45'"}} +do_test blob-1.11 { + catchsql {SELECT x'012G45'} +} {1 {unrecognized token: "x'012G45'"}} +do_test blob-1.12 { + catchsql {SELECT x'012`45'} +} {1 {unrecognized token: "x'012`45'"}} +do_test blob-1.13 { + catchsql {SELECT x'012g45'} +} {1 {unrecognized token: "x'012g45'"}} + + +# Insert a blob into a table and retrieve it. +do_test blob-2.0 { + execsql { + CREATE TABLE t1(a BLOB, b BLOB); + INSERT INTO t1 VALUES(X'123456', x'7890ab'); + INSERT INTO t1 VALUES(X'CDEF12', x'345678'); + } + set blobs [execsql {SELECT * FROM t1}] + set blobs2 [list] + foreach b $blobs {lappend blobs2 [bin_to_hex $b]} + set blobs2 +} {123456 7890AB CDEF12 345678} + +# An index on a blob column +do_test blob-2.1 { + execsql { + CREATE INDEX i1 ON t1(a); + } + set blobs [execsql {SELECT * FROM t1}] + set blobs2 [list] + foreach b $blobs {lappend blobs2 [bin_to_hex $b]} + set blobs2 +} {123456 7890AB CDEF12 345678} +do_test blob-2.2 { + set blobs [execsql {SELECT * FROM t1 where a = X'123456'}] + set blobs2 [list] + foreach b $blobs {lappend blobs2 [bin_to_hex $b]} + set blobs2 +} {123456 7890AB} +do_test blob-2.3 { + set blobs [execsql {SELECT * FROM t1 where a = X'CDEF12'}] + set blobs2 [list] + foreach b $blobs {lappend blobs2 [bin_to_hex $b]} + set blobs2 +} {CDEF12 345678} +do_test blob-2.4 { + set blobs [execsql {SELECT * FROM t1 where a = X'CD12'}] + set blobs2 [list] + foreach b $blobs {lappend blobs2 [bin_to_hex $b]} + set blobs2 +} {} + +# Try to bind a blob value to a prepared statement. +do_test blob-3.0 { + sqlite3 db2 test.db + set DB [sqlite3_connection_pointer db2] + set STMT [sqlite3_prepare $DB "DELETE FROM t1 WHERE a = ?" -1 DUMMY] + sqlite3_bind_blob $STMT 1 "\x12\x34\x56" 3 + sqlite3_step $STMT +} {SQLITE_DONE} +do_test blob-3.1 { + sqlite3_finalize $STMT + db2 close +} {} +do_test blob-3.2 { + set blobs [execsql {SELECT * FROM t1}] + set blobs2 [list] + foreach b $blobs {lappend blobs2 [bin_to_hex $b]} + set blobs2 +} {CDEF12 345678} + +finish_test diff --git a/test/bloom1.test b/test/bloom1.test new file mode 100644 index 0000000..151f364 --- /dev/null +++ b/test/bloom1.test @@ -0,0 +1,188 @@ +# 2022 October 06 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Tests for queries that use bloom filters + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/lock_common.tcl +source $testdir/malloc_common.tcl + +set testprefix bloom1 + +# Tests 1.* verify that the bloom filter code correctly handles the +# case where the RHS of an ( = ?) expression must be coerced +# to an integer before the comparison made. +# +do_execsql_test 1.0 { + CREATE TABLE t1(a, b); + CREATE TABLE t2(c INTEGER PRIMARY KEY, d); +} + +do_execsql_test 1.1 { + INSERT INTO t1 VALUES('hello', 'world'); + INSERT INTO t2 VALUES(14, 'fourteen'); +} + +do_execsql_test 1.2 { + ANALYZE sqlite_schema; + INSERT INTO sqlite_stat1 VALUES('t2','idx1','6 6'); + ANALYZE sqlite_schema; +} + +do_execsql_test 1.3 { + SELECT 'affinity!' FROM t1 CROSS JOIN t2 WHERE t2.c = '14'; +} {affinity!} + + +reset_db +do_execsql_test 1.4 { + CREATE TABLE t1(a, b TEXT); + CREATE TABLE t2(c INTEGER PRIMARY KEY, d); + CREATE TABLE t3(e INTEGER PRIMARY KEY, f); + + ANALYZE sqlite_schema; + INSERT INTO sqlite_stat1 VALUES('t1','idx1','600 6'); + INSERT INTO sqlite_stat1 VALUES('t2','idx1','6 6'); + INSERT INTO sqlite_stat1 VALUES('t3','idx2','6 6'); + ANALYZE sqlite_schema; + + INSERT INTO t1 VALUES(1, '123'); + INSERT INTO t2 VALUES(123, 'one'); + INSERT INTO t3 VALUES(123, 'two'); +} + +do_execsql_test 1.5 { + SELECT 'result' FROM t1, t2, t3 + WHERE t2.c=t1.b AND t2.d!='silly' + AND t3.e=t1.b AND t3.f!='silly' +} {result} + +# 2023-02-05 +# https://sqlite.org/forum/forumpost/56de336385 +# +# Do not employ a Bloom filter if the table being filtered or any table +# wo the left of the table being filtered lacks STAT1 data, since we +# cannot make a good Bloom filter usefulness determination without STAT1 +# data. +# +reset_db +do_execsql_test 2.0 { + CREATE TABLE objs(c INTEGER, s INTEGER, p INTEGER, o INTEGER); + CREATE UNIQUE INDEX objs_cspo ON objs(o,p,c,s); + ANALYZE; + DELETE FROM sqlite_stat1; + INSERT INTO sqlite_stat1 VALUES('objs','objs_cspo','520138 21 20 19 1'); + ANALYZE sqlite_schema; +} +do_eqp_test 2.1 { + WITH RECURSIVE transit(x) AS ( + SELECT s FROM objs WHERE p=9 AND o=32805 + UNION + SELECT objs.s FROM objs, transit WHERE objs.p=9 AND objs.o=transit.x + ) + SELECT x FROM transit; +} { + QUERY PLAN + |--CO-ROUTINE transit + | |--SETUP + | | `--SEARCH objs USING COVERING INDEX objs_cspo (o=? AND p=?) + | `--RECURSIVE STEP + | |--SCAN transit + | `--SEARCH objs USING COVERING INDEX objs_cspo (o=? AND p=?) + `--SCAN transit +} + +# 2023-02-28 +# https://sqlite.org/forum/forumpost/0846211821 +# +# Bloom filter gives an incorrect result if the collating sequence is +# anything other than binary. +# +reset_db +do_execsql_test 3.1 { + CREATE TABLE t0(x TEXT COLLATE rtrim); + INSERT INTO t0(x) VALUES ('a'), ('b'), ('c'); + CREATE VIEW v0(y) AS SELECT DISTINCT x FROM t0; + SELECT count(*) FROM t0, v0 WHERE x='b '; +} 3 +do_eqp_test 3.2 { + SELECT count(*) FROM t0, v0 WHERE x='b '; +} { + QUERY PLAN + |--CO-ROUTINE v0 + | |--SCAN t0 + | `--USE TEMP B-TREE FOR DISTINCT + |--SCAN v0 + `--SEARCH t0 USING AUTOMATIC PARTIAL COVERING INDEX (x=?) +} +# ^^^^^--- The key feature in the previous result is that no Bloom filter +# is used. In the following, a Bloom filter is used because the data type +# is INT instead of TEXT. +do_execsql_test 3.3 { + CREATE TABLE t1(x INT COLLATE rtrim); + INSERT INTO t1(x) VALUES ('a'), ('b'), ('c'); + CREATE VIEW v1(y) AS SELECT DISTINCT x FROM t1; + SELECT count(*) FROM t1, v1 WHERE x='b '; +} 3 +do_eqp_test 3.4 { + SELECT count(*) FROM t1, v1 WHERE x='b '; +} { + QUERY PLAN + |--CO-ROUTINE v1 + | |--SCAN t1 + | `--USE TEMP B-TREE FOR DISTINCT + |--SCAN v1 + |--BLOOM FILTER ON t1 (x=?) + `--SEARCH t1 USING AUTOMATIC PARTIAL COVERING INDEX (x=?) +} + +# 2023-03-14 +# https://sqlite.org/forum/forumpost/d47a0e8e3a +# https://sqlite.org/forum/forumpost/2e427099d5 +# +# Both reports are for the same problem - using a Bloom filter on an +# expression index can cause issues. +# +reset_db +do_execsql_test 4.1 { + CREATE TABLE t1(x TEXT, y INT, z TEXT); + INSERT INTO t1(rowid,x,y,z) VALUES(12,'aa','bb','aa'); + CREATE INDEX i1x ON t1(1 IS true,z); + CREATE TABLE t0(x TEXT); + INSERT INTO t0(rowid,x) VALUES(4,'aa'); + ANALYZE sqlite_schema; + INSERT INTO sqlite_stat1 VALUES('t0',NULL,'20'); + INSERT INTO sqlite_stat1 VALUES('t1','i1x','18 18 2'); + ANALYZE sqlite_schema; +} +do_execsql_test 4.2 { + SELECT * FROM t0 NATURAL JOIN t1 WHERE z=t1.x; +} {aa bb aa} +do_execsql_test 4.3 { + DROP TABLE t0; + CREATE TABLE t0(a TEXT); + INSERT INTO t0 VALUES ('xyz'); + CREATE INDEX t0x ON t0(a IS FALSE) WHERE false; + DROP TABLE t1; + CREATE TABLE t1(b INT); + INSERT INTO t1 VALUES('aaa'),('bbb'),('ccc'),('ddd'),(NULL); + CREATE TABLE t2(c REAL); + INSERT INTO t2 VALUES(7); + ANALYZE; + CREATE INDEX t2x ON t2(true IN ()); +} +do_execsql_test 4.4 { + SELECT * FROM t0 LEFT JOIN t1 LEFT JOIN t2 ON (b NOTNULL)==(c IN ()) WHERE c; +} {xyz {} 7.0} + + +finish_test diff --git a/test/boundary1.tcl b/test/boundary1.tcl new file mode 100644 index 0000000..3896b50 --- /dev/null +++ b/test/boundary1.tcl @@ -0,0 +1,289 @@ +puts {# 2008 December 11 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file is automatically generated from a separate TCL script. +# This file seeks to exercise integer boundary values. +# +# $Id: boundary1.tcl,v 1.3 2009/01/02 15:45:48 shane Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Many of the boundary tests depend on a working 64-bit implementation. +if {![working_64bit_int]} { finish_test; return } +} + +expr srand(0) + +# Generate interesting boundary numbers +# +foreach x { + 0 + 1 + 0x7f + 0x7fff + 0x7fffff + 0x7fffffff + 0x7fffffffff + 0x7fffffffffff + 0x7fffffffffffff + 0x7fffffffffffffff +} { + set x [expr {wide($x)}] + set boundarynum($x) 1 + set boundarynum([expr {$x+1}]) 1 + set boundarynum([expr {-($x+1)}]) 1 + set boundarynum([expr {-($x+2)}]) 1 + set boundarynum([expr {$x+$x+1}]) 1 + set boundarynum([expr {$x+$x+2}]) 1 +} +set x [expr {wide(127)}] +for {set i 1} {$i<=9} {incr i} { + set boundarynum($x) 1 + set boundarynum([expr {$x+1}]) 1 + set x [expr {wide($x*128 + 127)}] +} + +# Scramble the $inlist into a random order. +# +proc scramble {inlist} { + set y {} + foreach x $inlist { + lappend y [list [expr {rand()}] $x] + } + set y [lsort $y] + set outlist {} + foreach x $y { + lappend outlist [lindex $x 1] + } + return $outlist +} + +# A simple selection sort. Not trying to be efficient. +# +proc sort {inlist} { + set outlist {} + set mn [lindex $inlist 0] + foreach x $inlist { + if {$x<$mn} {set mn $x} + } + set outlist $mn + set mx $mn + while {1} { + set valid 0 + foreach x $inlist { + if {$x>$mx && (!$valid || $mn>$x)} { + set mn $x + set valid 1 + } + } + if {!$valid} break + lappend outlist $mn + set mx $mn + } + return $outlist +} + +# Reverse the order of a list +# +proc reverse {inlist} { + set i [llength $inlist] + set outlist {} + for {incr i -1} {$i>=0} {incr i -1} { + lappend outlist [lindex $inlist $i] + } + return $outlist +} + +set nums1 [scramble [array names boundarynum]] +set nums2 [scramble [array names boundarynum]] + +set tname boundary1 +puts "do_test $tname-1.1 \173" +puts " db eval \173" +puts " CREATE TABLE t1(a,x);" +set a 0 +foreach r $nums1 { + incr a + set t1ra($r) $a + set t1ar($a) $r + set x [format %08x%08x [expr {wide($r)>>32}] $r] + set t1rx($r) $x + set t1xr($x) $r + puts " INSERT INTO t1(oid,a,x) VALUES($r,$a,'$x');" +} +puts " CREATE INDEX t1i1 ON t1(a);" +puts " CREATE INDEX t1i2 ON t1(x);" +puts " \175" +puts "\175 {}" + +puts "do_test $tname-1.2 \173" +puts " db eval \173" +puts " SELECT count(*) FROM t1" +puts " \175" +puts "\175 {64}" + +set nums3 $nums2 +lappend nums3 9.22337303685477580800e+18 +lappend nums3 -9.22337303685477580800e+18 + +set i 0 +foreach r $nums3 { + incr i + + if {abs($r)<9.22337203685477580800e+18} { + set x $t1rx($r) + set a $t1ra($r) + set r5 $r.5 + set r0 $r.0 + puts "do_test $tname-2.$i.1 \173" + puts " db eval \173" + puts " SELECT * FROM t1 WHERE rowid=$r" + puts " \175" + puts "\175 {$a $x}" + puts "do_test $tname-2.$i.2 \173" + puts " db eval \173" + puts " SELECT rowid, a FROM t1 WHERE x='$x'" + puts " \175" + puts "\175 {$r $a}" + puts "do_test $tname-2.$i.3 \173" + puts " db eval \173" + puts " SELECT rowid, x FROM t1 WHERE a=$a" + puts " \175" + puts "\175 {$r $x}" + } + + foreach op {> >= < <=} subno {gt ge lt le} { + + ################################################################ 2.x.y.1 + set rset {} + set aset {} + foreach rx $nums2 { + if "\$rx $op \$r" { + lappend rset $rx + lappend aset $t1ra($rx) + } + } + puts "do_test $tname-2.$i.$subno.1 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE rowid $op $r ORDER BY a" + puts " \175" + puts "\175 {[sort $aset]}" + + ################################################################ 2.x.y.2 + puts "do_test $tname-2.$i.$subno.2 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE rowid $op $r ORDER BY a DESC" + puts " \175" + puts "\175 {[reverse [sort $aset]]}" + + ################################################################ 2.x.y.3 + set aset {} + foreach rx [sort $rset] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.3 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE rowid $op $r ORDER BY rowid" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.4 + set aset {} + foreach rx [reverse [sort $rset]] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.4 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE rowid $op $r ORDER BY rowid DESC" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.5 + set aset {} + set xset {} + foreach rx $rset { + lappend xset $t1rx($rx) + } + foreach x [sort $xset] { + set rx $t1xr($x) + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.5 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE rowid $op $r ORDER BY x" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.10 + if {abs($r)>9223372036854775808 || [string length $r5]>15} continue + set rset {} + set aset {} + foreach rx $nums2 { + if "\$rx $op \$r0" { + lappend rset $rx + } + } + foreach rx [sort $rset] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.10 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE rowid $op $r0 ORDER BY rowid" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.11 + set aset {} + foreach rx [reverse [sort $rset]] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.11 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE rowid $op $r0 ORDER BY rowid DESC" + puts " \175" + puts "\175 {$aset}" + + + ################################################################ 2.x.y.12 + set rset {} + set aset {} + foreach rx $nums2 { + if "\$rx $op \$r5" { + lappend rset $rx + } + } + foreach rx [sort $rset] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.12 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE rowid $op $r5 ORDER BY rowid" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.13 + set aset {} + foreach rx [reverse [sort $rset]] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.13 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE rowid $op $r5 ORDER BY rowid DESC" + puts " \175" + puts "\175 {$aset}" + } + +} + + +puts {finish_test} diff --git a/test/boundary1.test b/test/boundary1.test new file mode 100644 index 0000000..0e2458c --- /dev/null +++ b/test/boundary1.test @@ -0,0 +1,7645 @@ +# 2008 December 11 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file is automatically generated from a separate TCL script. +# This file seeks to exercise integer boundary values. +# +# $Id: boundary1.test,v 1.2 2009/01/02 15:45:48 shane Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Many of the boundary tests depend on a working 64-bit implementation. +if {![working_64bit_int]} { finish_test; return } + +do_test boundary1-1.1 { + db eval { + CREATE TABLE t1(a,x); + INSERT INTO t1(oid,a,x) VALUES(-8388609,1,'ffffffffff7fffff'); + INSERT INTO t1(oid,a,x) VALUES(-36028797018963969,2,'ff7fffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(9223372036854775807,3,'7fffffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(127,4,'000000000000007f'); + INSERT INTO t1(oid,a,x) VALUES(3,5,'0000000000000003'); + INSERT INTO t1(oid,a,x) VALUES(16777216,6,'0000000001000000'); + INSERT INTO t1(oid,a,x) VALUES(4398046511103,7,'000003ffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(16383,8,'0000000000003fff'); + INSERT INTO t1(oid,a,x) VALUES(16777215,9,'0000000000ffffff'); + INSERT INTO t1(oid,a,x) VALUES(281474976710655,10,'0000ffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(-2147483648,11,'ffffffff80000000'); + INSERT INTO t1(oid,a,x) VALUES(268435455,12,'000000000fffffff'); + INSERT INTO t1(oid,a,x) VALUES(562949953421311,13,'0001ffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(4294967295,14,'00000000ffffffff'); + INSERT INTO t1(oid,a,x) VALUES(2097151,15,'00000000001fffff'); + INSERT INTO t1(oid,a,x) VALUES(16384,16,'0000000000004000'); + INSERT INTO t1(oid,a,x) VALUES(72057594037927935,17,'00ffffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(8388607,18,'00000000007fffff'); + INSERT INTO t1(oid,a,x) VALUES(1099511627776,19,'0000010000000000'); + INSERT INTO t1(oid,a,x) VALUES(2147483647,20,'000000007fffffff'); + INSERT INTO t1(oid,a,x) VALUES(-140737488355329,21,'ffff7fffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(34359738368,22,'0000000800000000'); + INSERT INTO t1(oid,a,x) VALUES(32767,23,'0000000000007fff'); + INSERT INTO t1(oid,a,x) VALUES(8388608,24,'0000000000800000'); + INSERT INTO t1(oid,a,x) VALUES(140737488355327,25,'00007fffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(281474976710656,26,'0001000000000000'); + INSERT INTO t1(oid,a,x) VALUES(36028797018963967,27,'007fffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(72057594037927936,28,'0100000000000000'); + INSERT INTO t1(oid,a,x) VALUES(-32769,29,'ffffffffffff7fff'); + INSERT INTO t1(oid,a,x) VALUES(255,30,'00000000000000ff'); + INSERT INTO t1(oid,a,x) VALUES(4,31,'0000000000000004'); + INSERT INTO t1(oid,a,x) VALUES(-32768,32,'ffffffffffff8000'); + INSERT INTO t1(oid,a,x) VALUES(-2,33,'fffffffffffffffe'); + INSERT INTO t1(oid,a,x) VALUES(140737488355328,34,'0000800000000000'); + INSERT INTO t1(oid,a,x) VALUES(549755813888,35,'0000008000000000'); + INSERT INTO t1(oid,a,x) VALUES(4294967296,36,'0000000100000000'); + INSERT INTO t1(oid,a,x) VALUES(-8388608,37,'ffffffffff800000'); + INSERT INTO t1(oid,a,x) VALUES(-1,38,'ffffffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(34359738367,39,'00000007ffffffff'); + INSERT INTO t1(oid,a,x) VALUES(268435456,40,'0000000010000000'); + INSERT INTO t1(oid,a,x) VALUES(2,41,'0000000000000002'); + INSERT INTO t1(oid,a,x) VALUES(2097152,42,'0000000000200000'); + INSERT INTO t1(oid,a,x) VALUES(562949953421312,43,'0002000000000000'); + INSERT INTO t1(oid,a,x) VALUES(-140737488355328,44,'ffff800000000000'); + INSERT INTO t1(oid,a,x) VALUES(36028797018963968,45,'0080000000000000'); + INSERT INTO t1(oid,a,x) VALUES(549755813887,46,'0000007fffffffff'); + INSERT INTO t1(oid,a,x) VALUES(-2147483649,47,'ffffffff7fffffff'); + INSERT INTO t1(oid,a,x) VALUES(65535,48,'000000000000ffff'); + INSERT INTO t1(oid,a,x) VALUES(128,49,'0000000000000080'); + INSERT INTO t1(oid,a,x) VALUES(32768,50,'0000000000008000'); + INSERT INTO t1(oid,a,x) VALUES(2147483648,51,'0000000080000000'); + INSERT INTO t1(oid,a,x) VALUES(-3,52,'fffffffffffffffd'); + INSERT INTO t1(oid,a,x) VALUES(-128,53,'ffffffffffffff80'); + INSERT INTO t1(oid,a,x) VALUES(-129,54,'ffffffffffffff7f'); + INSERT INTO t1(oid,a,x) VALUES(-9223372036854775808,55,'8000000000000000'); + INSERT INTO t1(oid,a,x) VALUES(4398046511104,56,'0000040000000000'); + INSERT INTO t1(oid,a,x) VALUES(1099511627775,57,'000000ffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(-549755813889,58,'ffffff7fffffffff'); + INSERT INTO t1(oid,a,x) VALUES(0,59,'0000000000000000'); + INSERT INTO t1(oid,a,x) VALUES(1,60,'0000000000000001'); + INSERT INTO t1(oid,a,x) VALUES(256,61,'0000000000000100'); + INSERT INTO t1(oid,a,x) VALUES(65536,62,'0000000000010000'); + INSERT INTO t1(oid,a,x) VALUES(-549755813888,63,'ffffff8000000000'); + INSERT INTO t1(oid,a,x) VALUES(-36028797018963968,64,'ff80000000000000'); + CREATE INDEX t1i1 ON t1(a); + CREATE INDEX t1i2 ON t1(x); + } +} {} +do_test boundary1-1.2 { + db eval { + SELECT count(*) FROM t1 + } +} {64} +do_test boundary1-2.1.1 { + db eval { + SELECT * FROM t1 WHERE rowid=72057594037927935 + } +} {17 00ffffffffffffff} +do_test boundary1-2.1.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='00ffffffffffffff' + } +} {72057594037927935 17} +do_test boundary1-2.1.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=17 + } +} {72057594037927935 00ffffffffffffff} +do_test boundary1-2.1.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 72057594037927935 ORDER BY a + } +} {3 28} +do_test boundary1-2.1.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 72057594037927935 ORDER BY a DESC + } +} {28 3} +do_test boundary1-2.1.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 72057594037927935 ORDER BY rowid + } +} {28 3} +do_test boundary1-2.1.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 72057594037927935 ORDER BY rowid DESC + } +} {3 28} +do_test boundary1-2.1.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 72057594037927935 ORDER BY x + } +} {28 3} +do_test boundary1-2.1.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 72057594037927935 ORDER BY a + } +} {3 17 28} +do_test boundary1-2.1.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 72057594037927935 ORDER BY a DESC + } +} {28 17 3} +do_test boundary1-2.1.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 72057594037927935 ORDER BY rowid + } +} {17 28 3} +do_test boundary1-2.1.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 72057594037927935 ORDER BY rowid DESC + } +} {3 28 17} +do_test boundary1-2.1.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 72057594037927935 ORDER BY x + } +} {17 28 3} +do_test boundary1-2.1.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 72057594037927935 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.1.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 72057594037927935 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.1.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 72057594037927935 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45} +do_test boundary1-2.1.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 72057594037927935 ORDER BY rowid DESC + } +} {45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.1.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 72057594037927935 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.1.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 72057594037927935 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.1.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 72057594037927935 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.1.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 72057594037927935 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17} +do_test boundary1-2.1.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 72057594037927935 ORDER BY rowid DESC + } +} {17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.1.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 72057594037927935 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.2.1 { + db eval { + SELECT * FROM t1 WHERE rowid=16384 + } +} {16 0000000000004000} +do_test boundary1-2.2.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000000004000' + } +} {16384 16} +do_test boundary1-2.2.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=16 + } +} {16384 0000000000004000} +do_test boundary1-2.2.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 16384 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary1-2.2.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 16384 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary1-2.2.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 16384 ORDER BY rowid + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.2.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 16384 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23} +do_test boundary1-2.2.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 16384 ORDER BY x + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.2.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16384 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary1-2.2.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16384 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 7 6 3} +do_test boundary1-2.2.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16384 ORDER BY rowid + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.2.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16384 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16} +do_test boundary1-2.2.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16384 ORDER BY x + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.2.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 16384 ORDER BY a + } +} {1 2 4 5 8 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary1-2.2.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 16384 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 8 5 4 2 1} +do_test boundary1-2.2.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 16384 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8} +do_test boundary1-2.2.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 16384 ORDER BY rowid DESC + } +} {8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.2.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 16384 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.2.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16384 ORDER BY a + } +} {1 2 4 5 8 11 16 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary1-2.2.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16384 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 16 11 8 5 4 2 1} +do_test boundary1-2.2.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16384 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16} +do_test boundary1-2.2.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16384 ORDER BY rowid DESC + } +} {16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.2.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16384 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.3.1 { + db eval { + SELECT * FROM t1 WHERE rowid=4294967296 + } +} {36 0000000100000000} +do_test boundary1-2.3.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000100000000' + } +} {4294967296 36} +do_test boundary1-2.3.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=36 + } +} {4294967296 0000000100000000} +do_test boundary1-2.3.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 4294967296 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 39 43 45 46 56 57} +do_test boundary1-2.3.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 4294967296 ORDER BY a DESC + } +} {57 56 46 45 43 39 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary1-2.3.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 4294967296 ORDER BY rowid + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.3.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 4294967296 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39} +do_test boundary1-2.3.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 4294967296 ORDER BY x + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.3.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4294967296 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary1-2.3.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4294967296 ORDER BY a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary1-2.3.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4294967296 ORDER BY rowid + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.3.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4294967296 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36} +do_test boundary1-2.3.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4294967296 ORDER BY x + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.3.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 4294967296 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.3.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 4294967296 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.3.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 4294967296 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14} +do_test boundary1-2.3.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 4294967296 ORDER BY rowid DESC + } +} {14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.3.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 4294967296 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.3.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4294967296 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.3.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4294967296 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.3.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4294967296 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36} +do_test boundary1-2.3.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4294967296 ORDER BY rowid DESC + } +} {36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.3.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4294967296 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.4.1 { + db eval { + SELECT * FROM t1 WHERE rowid=16777216 + } +} {6 0000000001000000} +do_test boundary1-2.4.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000001000000' + } +} {16777216 6} +do_test boundary1-2.4.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=6 + } +} {16777216 0000000001000000} +do_test boundary1-2.4.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 16777216 ORDER BY a + } +} {3 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary1-2.4.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 16777216 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 3} +do_test boundary1-2.4.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 16777216 ORDER BY rowid + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.4.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 16777216 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12} +do_test boundary1-2.4.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 16777216 ORDER BY x + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.4.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16777216 ORDER BY a + } +} {3 6 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary1-2.4.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16777216 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 6 3} +do_test boundary1-2.4.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16777216 ORDER BY rowid + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.4.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16777216 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6} +do_test boundary1-2.4.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16777216 ORDER BY x + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.4.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 16777216 ORDER BY a + } +} {1 2 4 5 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.4.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 16777216 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 5 4 2 1} +do_test boundary1-2.4.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 16777216 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9} +do_test boundary1-2.4.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 16777216 ORDER BY rowid DESC + } +} {9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.4.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 16777216 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.4.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16777216 ORDER BY a + } +} {1 2 4 5 6 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.4.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16777216 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 6 5 4 2 1} +do_test boundary1-2.4.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16777216 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6} +do_test boundary1-2.4.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16777216 ORDER BY rowid DESC + } +} {6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.4.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16777216 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.5.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-32769 + } +} {29 ffffffffffff7fff} +do_test boundary1-2.5.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='ffffffffffff7fff' + } +} {-32769 29} +do_test boundary1-2.5.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=29 + } +} {-32769 ffffffffffff7fff} +do_test boundary1-2.5.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -32769 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary1-2.5.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -32769 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.5.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -32769 ORDER BY rowid + } +} {32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.5.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -32769 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32} +do_test boundary1-2.5.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -32769 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 32 54 53 52 33 38} +do_test boundary1-2.5.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -32769 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary1-2.5.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -32769 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.5.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -32769 ORDER BY rowid + } +} {29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.5.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -32769 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29} +do_test boundary1-2.5.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -32769 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 29 32 54 53 52 33 38} +do_test boundary1-2.5.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -32769 ORDER BY a + } +} {1 2 11 21 37 44 47 55 58 63 64} +do_test boundary1-2.5.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -32769 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 21 11 2 1} +do_test boundary1-2.5.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -32769 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary1-2.5.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -32769 ORDER BY rowid DESC + } +} {37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.5.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -32769 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary1-2.5.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -32769 ORDER BY a + } +} {1 2 11 21 29 37 44 47 55 58 63 64} +do_test boundary1-2.5.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -32769 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 29 21 11 2 1} +do_test boundary1-2.5.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -32769 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary1-2.5.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -32769 ORDER BY rowid DESC + } +} {29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.5.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -32769 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary1-2.6.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-140737488355329 + } +} {21 ffff7fffffffffff} +do_test boundary1-2.6.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='ffff7fffffffffff' + } +} {-140737488355329 21} +do_test boundary1-2.6.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=21 + } +} {-140737488355329 ffff7fffffffffff} +do_test boundary1-2.6.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -140737488355329 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary1-2.6.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -140737488355329 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.6.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -140737488355329 ORDER BY rowid + } +} {44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.6.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -140737488355329 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44} +do_test boundary1-2.6.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -140737488355329 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.6.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -140737488355329 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary1-2.6.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -140737488355329 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.6.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -140737488355329 ORDER BY rowid + } +} {21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.6.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -140737488355329 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21} +do_test boundary1-2.6.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -140737488355329 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.6.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -140737488355329 ORDER BY a + } +} {2 55 64} +do_test boundary1-2.6.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -140737488355329 ORDER BY a DESC + } +} {64 55 2} +do_test boundary1-2.6.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -140737488355329 ORDER BY rowid + } +} {55 2 64} +do_test boundary1-2.6.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -140737488355329 ORDER BY rowid DESC + } +} {64 2 55} +do_test boundary1-2.6.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -140737488355329 ORDER BY x + } +} {55 2 64} +do_test boundary1-2.6.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -140737488355329 ORDER BY a + } +} {2 21 55 64} +do_test boundary1-2.6.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -140737488355329 ORDER BY a DESC + } +} {64 55 21 2} +do_test boundary1-2.6.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -140737488355329 ORDER BY rowid + } +} {55 2 64 21} +do_test boundary1-2.6.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -140737488355329 ORDER BY rowid DESC + } +} {21 64 2 55} +do_test boundary1-2.6.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -140737488355329 ORDER BY x + } +} {55 2 64 21} +do_test boundary1-2.7.1 { + db eval { + SELECT * FROM t1 WHERE rowid=2 + } +} {41 0000000000000002} +do_test boundary1-2.7.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000000000002' + } +} {2 41} +do_test boundary1-2.7.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=41 + } +} {2 0000000000000002} +do_test boundary1-2.7.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 2 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary1-2.7.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 2 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.7.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 2 ORDER BY rowid + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.7.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 2 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5} +do_test boundary1-2.7.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 2 ORDER BY x + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.7.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary1-2.7.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.7.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2 ORDER BY rowid + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.7.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41} +do_test boundary1-2.7.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2 ORDER BY x + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.7.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 2 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary1-2.7.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 2 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary1-2.7.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 2 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60} +do_test boundary1-2.7.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 2 ORDER BY rowid DESC + } +} {60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.7.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 2 ORDER BY x + } +} {59 60 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.7.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary1-2.7.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 2 1} +do_test boundary1-2.7.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41} +do_test boundary1-2.7.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2 ORDER BY rowid DESC + } +} {41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.7.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2 ORDER BY x + } +} {59 60 41 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.8.1 { + db eval { + SELECT * FROM t1 WHERE rowid=4 + } +} {31 0000000000000004} +do_test boundary1-2.8.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000000000004' + } +} {4 31} +do_test boundary1-2.8.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=31 + } +} {4 0000000000000004} +do_test boundary1-2.8.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 4 ORDER BY a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary1-2.8.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 4 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary1-2.8.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 4 ORDER BY rowid + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.8.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 4 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4} +do_test boundary1-2.8.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 4 ORDER BY x + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.8.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4 ORDER BY a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary1-2.8.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary1-2.8.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4 ORDER BY rowid + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.8.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31} +do_test boundary1-2.8.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4 ORDER BY x + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.8.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 4 ORDER BY a + } +} {1 2 5 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary1-2.8.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 4 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 5 2 1} +do_test boundary1-2.8.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 4 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5} +do_test boundary1-2.8.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 4 ORDER BY rowid DESC + } +} {5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.8.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 4 ORDER BY x + } +} {59 60 41 5 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.8.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4 ORDER BY a + } +} {1 2 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary1-2.8.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 2 1} +do_test boundary1-2.8.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31} +do_test boundary1-2.8.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4 ORDER BY rowid DESC + } +} {31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.8.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4 ORDER BY x + } +} {59 60 41 5 31 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.9.1 { + db eval { + SELECT * FROM t1 WHERE rowid=562949953421311 + } +} {13 0001ffffffffffff} +do_test boundary1-2.9.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0001ffffffffffff' + } +} {562949953421311 13} +do_test boundary1-2.9.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=13 + } +} {562949953421311 0001ffffffffffff} +do_test boundary1-2.9.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 562949953421311 ORDER BY a + } +} {3 17 27 28 43 45} +do_test boundary1-2.9.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 562949953421311 ORDER BY a DESC + } +} {45 43 28 27 17 3} +do_test boundary1-2.9.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 562949953421311 ORDER BY rowid + } +} {43 27 45 17 28 3} +do_test boundary1-2.9.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 562949953421311 ORDER BY rowid DESC + } +} {3 28 17 45 27 43} +do_test boundary1-2.9.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 562949953421311 ORDER BY x + } +} {43 27 45 17 28 3} +do_test boundary1-2.9.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 562949953421311 ORDER BY a + } +} {3 13 17 27 28 43 45} +do_test boundary1-2.9.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 562949953421311 ORDER BY a DESC + } +} {45 43 28 27 17 13 3} +do_test boundary1-2.9.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 562949953421311 ORDER BY rowid + } +} {13 43 27 45 17 28 3} +do_test boundary1-2.9.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 562949953421311 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13} +do_test boundary1-2.9.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 562949953421311 ORDER BY x + } +} {13 43 27 45 17 28 3} +do_test boundary1-2.9.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 562949953421311 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.9.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 562949953421311 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.9.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 562949953421311 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26} +do_test boundary1-2.9.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 562949953421311 ORDER BY rowid DESC + } +} {26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.9.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 562949953421311 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.9.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 562949953421311 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.9.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 562949953421311 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.9.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 562949953421311 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13} +do_test boundary1-2.9.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 562949953421311 ORDER BY rowid DESC + } +} {13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.9.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 562949953421311 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.10.1 { + db eval { + SELECT * FROM t1 WHERE rowid=256 + } +} {61 0000000000000100} +do_test boundary1-2.10.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000000000100' + } +} {256 61} +do_test boundary1-2.10.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=61 + } +} {256 0000000000000100} +do_test boundary1-2.10.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 256 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary1-2.10.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 256 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary1-2.10.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 256 ORDER BY rowid + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.10.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 256 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8} +do_test boundary1-2.10.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 256 ORDER BY x + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.10.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 256 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary1-2.10.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 256 ORDER BY a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary1-2.10.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 256 ORDER BY rowid + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.10.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 256 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61} +do_test boundary1-2.10.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 256 ORDER BY x + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.10.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 256 ORDER BY a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary1-2.10.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 256 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary1-2.10.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 256 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30} +do_test boundary1-2.10.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 256 ORDER BY rowid DESC + } +} {30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.10.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 256 ORDER BY x + } +} {59 60 41 5 31 4 49 30 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.10.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 256 ORDER BY a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary1-2.10.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 256 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary1-2.10.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 256 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61} +do_test boundary1-2.10.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 256 ORDER BY rowid DESC + } +} {61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.10.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 256 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.11.1 { + db eval { + SELECT * FROM t1 WHERE rowid=34359738368 + } +} {22 0000000800000000} +do_test boundary1-2.11.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000800000000' + } +} {34359738368 22} +do_test boundary1-2.11.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=22 + } +} {34359738368 0000000800000000} +do_test boundary1-2.11.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 34359738368 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary1-2.11.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 34359738368 ORDER BY a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary1-2.11.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 34359738368 ORDER BY rowid + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.11.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 34359738368 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46} +do_test boundary1-2.11.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 34359738368 ORDER BY x + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.11.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 34359738368 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary1-2.11.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 34359738368 ORDER BY a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary1-2.11.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 34359738368 ORDER BY rowid + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.11.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 34359738368 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22} +do_test boundary1-2.11.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 34359738368 ORDER BY x + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.11.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 34359738368 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.11.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 34359738368 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.11.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 34359738368 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39} +do_test boundary1-2.11.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 34359738368 ORDER BY rowid DESC + } +} {39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.11.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 34359738368 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.11.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 34359738368 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.11.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 34359738368 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.11.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 34359738368 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22} +do_test boundary1-2.11.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 34359738368 ORDER BY rowid DESC + } +} {22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.11.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 34359738368 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.12.1 { + db eval { + SELECT * FROM t1 WHERE rowid=65536 + } +} {62 0000000000010000} +do_test boundary1-2.12.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000000010000' + } +} {65536 62} +do_test boundary1-2.12.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=62 + } +} {65536 0000000000010000} +do_test boundary1-2.12.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 65536 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary1-2.12.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 65536 ORDER BY a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary1-2.12.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 65536 ORDER BY rowid + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.12.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 65536 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15} +do_test boundary1-2.12.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 65536 ORDER BY x + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.12.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 65536 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57 62} +do_test boundary1-2.12.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 65536 ORDER BY a DESC + } +} {62 57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary1-2.12.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 65536 ORDER BY rowid + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.12.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 65536 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62} +do_test boundary1-2.12.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 65536 ORDER BY x + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.12.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 65536 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary1-2.12.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 65536 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary1-2.12.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 65536 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48} +do_test boundary1-2.12.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 65536 ORDER BY rowid DESC + } +} {48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.12.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 65536 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.12.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 65536 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.12.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 65536 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary1-2.12.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 65536 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62} +do_test boundary1-2.12.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 65536 ORDER BY rowid DESC + } +} {62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.12.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 65536 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.13.1 { + db eval { + SELECT * FROM t1 WHERE rowid=268435456 + } +} {40 0000000010000000} +do_test boundary1-2.13.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000010000000' + } +} {268435456 40} +do_test boundary1-2.13.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=40 + } +} {268435456 0000000010000000} +do_test boundary1-2.13.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 268435456 ORDER BY a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary1-2.13.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 268435456 ORDER BY a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary1-2.13.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 268435456 ORDER BY rowid + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.13.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 268435456 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20} +do_test boundary1-2.13.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 268435456 ORDER BY x + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.13.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 268435456 ORDER BY a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary1-2.13.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 268435456 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary1-2.13.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 268435456 ORDER BY rowid + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.13.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 268435456 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40} +do_test boundary1-2.13.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 268435456 ORDER BY x + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.13.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 268435456 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.13.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 268435456 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.13.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 268435456 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12} +do_test boundary1-2.13.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 268435456 ORDER BY rowid DESC + } +} {12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.13.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 268435456 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.13.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 268435456 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.13.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 268435456 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.13.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 268435456 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40} +do_test boundary1-2.13.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 268435456 ORDER BY rowid DESC + } +} {40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.13.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 268435456 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.14.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-140737488355328 + } +} {44 ffff800000000000} +do_test boundary1-2.14.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='ffff800000000000' + } +} {-140737488355328 44} +do_test boundary1-2.14.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=44 + } +} {-140737488355328 ffff800000000000} +do_test boundary1-2.14.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -140737488355328 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary1-2.14.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -140737488355328 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.14.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -140737488355328 ORDER BY rowid + } +} {58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.14.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -140737488355328 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58} +do_test boundary1-2.14.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -140737488355328 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.14.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -140737488355328 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary1-2.14.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -140737488355328 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.14.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -140737488355328 ORDER BY rowid + } +} {44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.14.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -140737488355328 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44} +do_test boundary1-2.14.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -140737488355328 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.14.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -140737488355328 ORDER BY a + } +} {2 21 55 64} +do_test boundary1-2.14.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -140737488355328 ORDER BY a DESC + } +} {64 55 21 2} +do_test boundary1-2.14.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -140737488355328 ORDER BY rowid + } +} {55 2 64 21} +do_test boundary1-2.14.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -140737488355328 ORDER BY rowid DESC + } +} {21 64 2 55} +do_test boundary1-2.14.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -140737488355328 ORDER BY x + } +} {55 2 64 21} +do_test boundary1-2.14.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -140737488355328 ORDER BY a + } +} {2 21 44 55 64} +do_test boundary1-2.14.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -140737488355328 ORDER BY a DESC + } +} {64 55 44 21 2} +do_test boundary1-2.14.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -140737488355328 ORDER BY rowid + } +} {55 2 64 21 44} +do_test boundary1-2.14.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -140737488355328 ORDER BY rowid DESC + } +} {44 21 64 2 55} +do_test boundary1-2.14.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -140737488355328 ORDER BY x + } +} {55 2 64 21 44} +do_test boundary1-2.15.1 { + db eval { + SELECT * FROM t1 WHERE rowid=1099511627776 + } +} {19 0000010000000000} +do_test boundary1-2.15.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000010000000000' + } +} {1099511627776 19} +do_test boundary1-2.15.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=19 + } +} {1099511627776 0000010000000000} +do_test boundary1-2.15.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 1099511627776 ORDER BY a + } +} {3 7 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary1-2.15.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 1099511627776 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 7 3} +do_test boundary1-2.15.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 1099511627776 ORDER BY rowid + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.15.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 1099511627776 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7} +do_test boundary1-2.15.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 1099511627776 ORDER BY x + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.15.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 1099511627776 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56} +do_test boundary1-2.15.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 1099511627776 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary1-2.15.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 1099511627776 ORDER BY rowid + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.15.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 1099511627776 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19} +do_test boundary1-2.15.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 1099511627776 ORDER BY x + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.15.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 1099511627776 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary1-2.15.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 1099511627776 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.15.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 1099511627776 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57} +do_test boundary1-2.15.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 1099511627776 ORDER BY rowid DESC + } +} {57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.15.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 1099511627776 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.15.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 1099511627776 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary1-2.15.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 1099511627776 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.15.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 1099511627776 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19} +do_test boundary1-2.15.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 1099511627776 ORDER BY rowid DESC + } +} {19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.15.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 1099511627776 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.16.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 9223372036854775807 ORDER BY a + } +} {} +do_test boundary1-2.16.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 9223372036854775807 ORDER BY a DESC + } +} {} +do_test boundary1-2.16.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 9223372036854775807 ORDER BY rowid + } +} {} +do_test boundary1-2.16.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 9223372036854775807 ORDER BY rowid DESC + } +} {} +do_test boundary1-2.16.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 9223372036854775807 ORDER BY x + } +} {} +do_test boundary1-2.16.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 9223372036854775807 ORDER BY a + } +} {3} +do_test boundary1-2.16.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 9223372036854775807 ORDER BY a DESC + } +} {3} +do_test boundary1-2.16.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 9223372036854775807 ORDER BY rowid + } +} {3} +do_test boundary1-2.16.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 9223372036854775807 ORDER BY rowid DESC + } +} {3} +do_test boundary1-2.16.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 9223372036854775807 ORDER BY x + } +} {3} +do_test boundary1-2.16.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 9223372036854775807 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.16.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 9223372036854775807 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.16.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 9223372036854775807 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28} +do_test boundary1-2.16.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 9223372036854775807 ORDER BY rowid DESC + } +} {28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.16.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 9223372036854775807 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.16.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 9223372036854775807 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.16.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 9223372036854775807 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary1-2.16.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 9223372036854775807 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.16.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 9223372036854775807 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.16.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 9223372036854775807 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.17.1 { + db eval { + SELECT * FROM t1 WHERE rowid=32768 + } +} {50 0000000000008000} +do_test boundary1-2.17.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000000008000' + } +} {32768 50} +do_test boundary1-2.17.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=50 + } +} {32768 0000000000008000} +do_test boundary1-2.17.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 32768 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 51 56 57 62} +do_test boundary1-2.17.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 32768 ORDER BY a DESC + } +} {62 57 56 51 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary1-2.17.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 32768 ORDER BY rowid + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.17.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 32768 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48} +do_test boundary1-2.17.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 32768 ORDER BY x + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.17.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 32768 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary1-2.17.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 32768 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary1-2.17.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 32768 ORDER BY rowid + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.17.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 32768 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50} +do_test boundary1-2.17.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 32768 ORDER BY x + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.17.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 32768 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary1-2.17.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 32768 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary1-2.17.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 32768 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23} +do_test boundary1-2.17.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 32768 ORDER BY rowid DESC + } +} {23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.17.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 32768 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.17.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 32768 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary1-2.17.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 32768 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary1-2.17.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 32768 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50} +do_test boundary1-2.17.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 32768 ORDER BY rowid DESC + } +} {50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.17.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 32768 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.18.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-36028797018963968 + } +} {64 ff80000000000000} +do_test boundary1-2.18.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='ff80000000000000' + } +} {-36028797018963968 64} +do_test boundary1-2.18.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=64 + } +} {-36028797018963968 ff80000000000000} +do_test boundary1-2.18.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -36028797018963968 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary1-2.18.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -36028797018963968 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.18.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -36028797018963968 ORDER BY rowid + } +} {21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.18.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -36028797018963968 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21} +do_test boundary1-2.18.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -36028797018963968 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.18.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -36028797018963968 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.18.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -36028797018963968 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.18.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -36028797018963968 ORDER BY rowid + } +} {64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.18.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -36028797018963968 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64} +do_test boundary1-2.18.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -36028797018963968 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.18.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -36028797018963968 ORDER BY a + } +} {2 55} +do_test boundary1-2.18.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -36028797018963968 ORDER BY a DESC + } +} {55 2} +do_test boundary1-2.18.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -36028797018963968 ORDER BY rowid + } +} {55 2} +do_test boundary1-2.18.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -36028797018963968 ORDER BY rowid DESC + } +} {2 55} +do_test boundary1-2.18.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -36028797018963968 ORDER BY x + } +} {55 2} +do_test boundary1-2.18.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -36028797018963968 ORDER BY a + } +} {2 55 64} +do_test boundary1-2.18.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -36028797018963968 ORDER BY a DESC + } +} {64 55 2} +do_test boundary1-2.18.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -36028797018963968 ORDER BY rowid + } +} {55 2 64} +do_test boundary1-2.18.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -36028797018963968 ORDER BY rowid DESC + } +} {64 2 55} +do_test boundary1-2.18.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -36028797018963968 ORDER BY x + } +} {55 2 64} +do_test boundary1-2.19.1 { + db eval { + SELECT * FROM t1 WHERE rowid=65535 + } +} {48 000000000000ffff} +do_test boundary1-2.19.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='000000000000ffff' + } +} {65535 48} +do_test boundary1-2.19.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=48 + } +} {65535 000000000000ffff} +do_test boundary1-2.19.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 65535 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57 62} +do_test boundary1-2.19.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 65535 ORDER BY a DESC + } +} {62 57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary1-2.19.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 65535 ORDER BY rowid + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.19.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 65535 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62} +do_test boundary1-2.19.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 65535 ORDER BY x + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.19.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 65535 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 51 56 57 62} +do_test boundary1-2.19.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 65535 ORDER BY a DESC + } +} {62 57 56 51 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary1-2.19.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 65535 ORDER BY rowid + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.19.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 65535 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48} +do_test boundary1-2.19.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 65535 ORDER BY x + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.19.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 65535 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary1-2.19.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 65535 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary1-2.19.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 65535 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50} +do_test boundary1-2.19.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 65535 ORDER BY rowid DESC + } +} {50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.19.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 65535 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.19.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 65535 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary1-2.19.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 65535 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary1-2.19.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 65535 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48} +do_test boundary1-2.19.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 65535 ORDER BY rowid DESC + } +} {48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.19.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 65535 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.20.1 { + db eval { + SELECT * FROM t1 WHERE rowid=4294967295 + } +} {14 00000000ffffffff} +do_test boundary1-2.20.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='00000000ffffffff' + } +} {4294967295 14} +do_test boundary1-2.20.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=14 + } +} {4294967295 00000000ffffffff} +do_test boundary1-2.20.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 4294967295 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary1-2.20.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 4294967295 ORDER BY a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary1-2.20.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 4294967295 ORDER BY rowid + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.20.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 4294967295 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36} +do_test boundary1-2.20.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 4294967295 ORDER BY x + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.20.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4294967295 ORDER BY a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary1-2.20.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4294967295 ORDER BY a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary1-2.20.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4294967295 ORDER BY rowid + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.20.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4294967295 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14} +do_test boundary1-2.20.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4294967295 ORDER BY x + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.20.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 4294967295 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.20.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 4294967295 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.20.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 4294967295 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51} +do_test boundary1-2.20.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 4294967295 ORDER BY rowid DESC + } +} {51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.20.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 4294967295 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.20.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4294967295 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.20.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4294967295 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.20.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4294967295 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14} +do_test boundary1-2.20.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4294967295 ORDER BY rowid DESC + } +} {14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.20.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4294967295 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.21.1 { + db eval { + SELECT * FROM t1 WHERE rowid=1099511627775 + } +} {57 000000ffffffffff} +do_test boundary1-2.21.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='000000ffffffffff' + } +} {1099511627775 57} +do_test boundary1-2.21.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=57 + } +} {1099511627775 000000ffffffffff} +do_test boundary1-2.21.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 1099511627775 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56} +do_test boundary1-2.21.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 1099511627775 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary1-2.21.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 1099511627775 ORDER BY rowid + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.21.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 1099511627775 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19} +do_test boundary1-2.21.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 1099511627775 ORDER BY x + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.21.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 1099511627775 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56 57} +do_test boundary1-2.21.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 1099511627775 ORDER BY a DESC + } +} {57 56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary1-2.21.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 1099511627775 ORDER BY rowid + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.21.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 1099511627775 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57} +do_test boundary1-2.21.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 1099511627775 ORDER BY x + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.21.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 1099511627775 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.21.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 1099511627775 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.21.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 1099511627775 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35} +do_test boundary1-2.21.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 1099511627775 ORDER BY rowid DESC + } +} {35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.21.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 1099511627775 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.21.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 1099511627775 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary1-2.21.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 1099511627775 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.21.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 1099511627775 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57} +do_test boundary1-2.21.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 1099511627775 ORDER BY rowid DESC + } +} {57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.21.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 1099511627775 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.22.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-8388608 + } +} {37 ffffffffff800000} +do_test boundary1-2.22.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='ffffffffff800000' + } +} {-8388608 37} +do_test boundary1-2.22.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=37 + } +} {-8388608 ffffffffff800000} +do_test boundary1-2.22.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -8388608 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary1-2.22.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -8388608 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.22.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -8388608 ORDER BY rowid + } +} {29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.22.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -8388608 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29} +do_test boundary1-2.22.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -8388608 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 29 32 54 53 52 33 38} +do_test boundary1-2.22.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -8388608 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary1-2.22.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -8388608 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.22.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -8388608 ORDER BY rowid + } +} {37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.22.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -8388608 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37} +do_test boundary1-2.22.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -8388608 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 37 29 32 54 53 52 33 38} +do_test boundary1-2.22.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -8388608 ORDER BY a + } +} {1 2 11 21 44 47 55 58 63 64} +do_test boundary1-2.22.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -8388608 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 11 2 1} +do_test boundary1-2.22.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -8388608 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary1-2.22.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -8388608 ORDER BY rowid DESC + } +} {1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.22.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -8388608 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary1-2.22.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -8388608 ORDER BY a + } +} {1 2 11 21 37 44 47 55 58 63 64} +do_test boundary1-2.22.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -8388608 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 21 11 2 1} +do_test boundary1-2.22.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -8388608 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary1-2.22.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -8388608 ORDER BY rowid DESC + } +} {37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.22.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -8388608 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary1-2.23.1 { + db eval { + SELECT * FROM t1 WHERE rowid=549755813888 + } +} {35 0000008000000000} +do_test boundary1-2.23.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000008000000000' + } +} {549755813888 35} +do_test boundary1-2.23.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=35 + } +} {549755813888 0000008000000000} +do_test boundary1-2.23.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 549755813888 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56 57} +do_test boundary1-2.23.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 549755813888 ORDER BY a DESC + } +} {57 56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary1-2.23.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 549755813888 ORDER BY rowid + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.23.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 549755813888 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57} +do_test boundary1-2.23.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 549755813888 ORDER BY x + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.23.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 549755813888 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 56 57} +do_test boundary1-2.23.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 549755813888 ORDER BY a DESC + } +} {57 56 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary1-2.23.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 549755813888 ORDER BY rowid + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.23.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 549755813888 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35} +do_test boundary1-2.23.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 549755813888 ORDER BY x + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.23.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 549755813888 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.23.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 549755813888 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.23.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 549755813888 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46} +do_test boundary1-2.23.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 549755813888 ORDER BY rowid DESC + } +} {46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.23.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 549755813888 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.23.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 549755813888 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.23.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 549755813888 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.23.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 549755813888 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35} +do_test boundary1-2.23.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 549755813888 ORDER BY rowid DESC + } +} {35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.23.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 549755813888 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.24.1 { + db eval { + SELECT * FROM t1 WHERE rowid=8388607 + } +} {18 00000000007fffff} +do_test boundary1-2.24.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='00000000007fffff' + } +} {8388607 18} +do_test boundary1-2.24.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=18 + } +} {8388607 00000000007fffff} +do_test boundary1-2.24.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 8388607 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary1-2.24.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 8388607 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary1-2.24.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 8388607 ORDER BY rowid + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.24.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 8388607 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24} +do_test boundary1-2.24.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 8388607 ORDER BY x + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.24.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 8388607 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary1-2.24.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 8388607 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary1-2.24.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 8388607 ORDER BY rowid + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.24.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 8388607 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18} +do_test boundary1-2.24.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 8388607 ORDER BY x + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.24.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 8388607 ORDER BY a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.24.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 8388607 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary1-2.24.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 8388607 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42} +do_test boundary1-2.24.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 8388607 ORDER BY rowid DESC + } +} {42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.24.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 8388607 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.24.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 8388607 ORDER BY a + } +} {1 2 4 5 8 11 15 16 18 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.24.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 8388607 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary1-2.24.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 8388607 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18} +do_test boundary1-2.24.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 8388607 ORDER BY rowid DESC + } +} {18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.24.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 8388607 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.25.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-3 + } +} {52 fffffffffffffffd} +do_test boundary1-2.25.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='fffffffffffffffd' + } +} {-3 52} +do_test boundary1-2.25.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=52 + } +} {-3 fffffffffffffffd} +do_test boundary1-2.25.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -3 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary1-2.25.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -3 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.25.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -3 ORDER BY rowid + } +} {33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.25.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -3 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33} +do_test boundary1-2.25.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -3 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 33 38} +do_test boundary1-2.25.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -3 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 56 57 59 60 61 62} +do_test boundary1-2.25.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -3 ORDER BY a DESC + } +} {62 61 60 59 57 56 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.25.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -3 ORDER BY rowid + } +} {52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.25.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -3 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52} +do_test boundary1-2.25.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -3 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 52 33 38} +do_test boundary1-2.25.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -3 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 53 54 55 58 63 64} +do_test boundary1-2.25.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -3 ORDER BY a DESC + } +} {64 63 58 55 54 53 47 44 37 32 29 21 11 2 1} +do_test boundary1-2.25.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -3 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary1-2.25.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -3 ORDER BY rowid DESC + } +} {53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.25.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -3 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary1-2.25.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -3 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 52 53 54 55 58 63 64} +do_test boundary1-2.25.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -3 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 37 32 29 21 11 2 1} +do_test boundary1-2.25.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -3 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary1-2.25.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -3 ORDER BY rowid DESC + } +} {52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.25.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -3 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary1-2.26.1 { + db eval { + SELECT * FROM t1 WHERE rowid=0 + } +} {59 0000000000000000} +do_test boundary1-2.26.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000000000000' + } +} {0 59} +do_test boundary1-2.26.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=59 + } +} {0 0000000000000000} +do_test boundary1-2.26.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 0 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 60 61 62} +do_test boundary1-2.26.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 0 ORDER BY a DESC + } +} {62 61 60 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.26.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 0 ORDER BY rowid + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.26.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 0 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60} +do_test boundary1-2.26.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 0 ORDER BY x + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.26.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 0 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary1-2.26.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 0 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.26.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 0 ORDER BY rowid + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.26.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 0 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59} +do_test boundary1-2.26.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 0 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.26.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 0 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 63 64} +do_test boundary1-2.26.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 0 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary1-2.26.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 0 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.26.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 0 ORDER BY rowid DESC + } +} {38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.26.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 0 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.26.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 0 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 63 64} +do_test boundary1-2.26.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 0 ORDER BY a DESC + } +} {64 63 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary1-2.26.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 0 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59} +do_test boundary1-2.26.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 0 ORDER BY rowid DESC + } +} {59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.26.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 0 ORDER BY x + } +} {59 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.27.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-1 + } +} {38 ffffffffffffffff} +do_test boundary1-2.27.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='ffffffffffffffff' + } +} {-1 38} +do_test boundary1-2.27.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=38 + } +} {-1 ffffffffffffffff} +do_test boundary1-2.27.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -1 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary1-2.27.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -1 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.27.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -1 ORDER BY rowid + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.27.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -1 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59} +do_test boundary1-2.27.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -1 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.27.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -1 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary1-2.27.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -1 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.27.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -1 ORDER BY rowid + } +} {38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.27.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -1 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38} +do_test boundary1-2.27.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -1 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 38} +do_test boundary1-2.27.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -1 ORDER BY a + } +} {1 2 11 21 29 32 33 37 44 47 52 53 54 55 58 63 64} +do_test boundary1-2.27.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -1 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 37 33 32 29 21 11 2 1} +do_test boundary1-2.27.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -1 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary1-2.27.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -1 ORDER BY rowid DESC + } +} {33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.27.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -1 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary1-2.27.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -1 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 63 64} +do_test boundary1-2.27.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -1 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary1-2.27.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -1 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.27.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -1 ORDER BY rowid DESC + } +} {38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.27.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -1 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.28.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-2 + } +} {33 fffffffffffffffe} +do_test boundary1-2.28.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='fffffffffffffffe' + } +} {-2 33} +do_test boundary1-2.28.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=33 + } +} {-2 fffffffffffffffe} +do_test boundary1-2.28.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -2 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary1-2.28.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -2 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.28.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -2 ORDER BY rowid + } +} {38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.28.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -2 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38} +do_test boundary1-2.28.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -2 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 38} +do_test boundary1-2.28.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -2 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary1-2.28.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -2 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.28.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -2 ORDER BY rowid + } +} {33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.28.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -2 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33} +do_test boundary1-2.28.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -2 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 33 38} +do_test boundary1-2.28.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -2 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 52 53 54 55 58 63 64} +do_test boundary1-2.28.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -2 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 37 32 29 21 11 2 1} +do_test boundary1-2.28.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -2 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary1-2.28.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -2 ORDER BY rowid DESC + } +} {52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.28.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -2 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary1-2.28.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -2 ORDER BY a + } +} {1 2 11 21 29 32 33 37 44 47 52 53 54 55 58 63 64} +do_test boundary1-2.28.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -2 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 37 33 32 29 21 11 2 1} +do_test boundary1-2.28.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -2 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary1-2.28.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -2 ORDER BY rowid DESC + } +} {33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.28.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -2 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary1-2.29.1 { + db eval { + SELECT * FROM t1 WHERE rowid=2097152 + } +} {42 0000000000200000} +do_test boundary1-2.29.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000000200000' + } +} {2097152 42} +do_test boundary1-2.29.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=42 + } +} {2097152 0000000000200000} +do_test boundary1-2.29.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 2097152 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary1-2.29.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 2097152 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary1-2.29.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 2097152 ORDER BY rowid + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.29.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 2097152 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18} +do_test boundary1-2.29.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 2097152 ORDER BY x + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.29.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2097152 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary1-2.29.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2097152 ORDER BY a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary1-2.29.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2097152 ORDER BY rowid + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.29.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2097152 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42} +do_test boundary1-2.29.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2097152 ORDER BY x + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.29.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 2097152 ORDER BY a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.29.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 2097152 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary1-2.29.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 2097152 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15} +do_test boundary1-2.29.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 2097152 ORDER BY rowid DESC + } +} {15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.29.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 2097152 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.29.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2097152 ORDER BY a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.29.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2097152 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary1-2.29.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2097152 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42} +do_test boundary1-2.29.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2097152 ORDER BY rowid DESC + } +} {42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.29.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2097152 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.30.1 { + db eval { + SELECT * FROM t1 WHERE rowid=128 + } +} {49 0000000000000080} +do_test boundary1-2.30.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000000000080' + } +} {128 49} +do_test boundary1-2.30.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=49 + } +} {128 0000000000000080} +do_test boundary1-2.30.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 128 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary1-2.30.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 128 ORDER BY a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary1-2.30.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 128 ORDER BY rowid + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.30.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 128 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30} +do_test boundary1-2.30.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 128 ORDER BY x + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.30.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 128 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary1-2.30.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 128 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary1-2.30.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 128 ORDER BY rowid + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.30.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 128 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49} +do_test boundary1-2.30.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 128 ORDER BY x + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.30.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 128 ORDER BY a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary1-2.30.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 128 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary1-2.30.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 128 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4} +do_test boundary1-2.30.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 128 ORDER BY rowid DESC + } +} {4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.30.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 128 ORDER BY x + } +} {59 60 41 5 31 4 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.30.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 128 ORDER BY a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary1-2.30.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 128 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary1-2.30.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 128 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49} +do_test boundary1-2.30.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 128 ORDER BY rowid DESC + } +} {49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.30.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 128 ORDER BY x + } +} {59 60 41 5 31 4 49 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.31.1 { + db eval { + SELECT * FROM t1 WHERE rowid=255 + } +} {30 00000000000000ff} +do_test boundary1-2.31.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='00000000000000ff' + } +} {255 30} +do_test boundary1-2.31.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=30 + } +} {255 00000000000000ff} +do_test boundary1-2.31.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 255 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary1-2.31.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 255 ORDER BY a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary1-2.31.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 255 ORDER BY rowid + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.31.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 255 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61} +do_test boundary1-2.31.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 255 ORDER BY x + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.31.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 255 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary1-2.31.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 255 ORDER BY a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary1-2.31.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 255 ORDER BY rowid + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.31.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 255 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30} +do_test boundary1-2.31.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 255 ORDER BY x + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.31.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 255 ORDER BY a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary1-2.31.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 255 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary1-2.31.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 255 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49} +do_test boundary1-2.31.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 255 ORDER BY rowid DESC + } +} {49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.31.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 255 ORDER BY x + } +} {59 60 41 5 31 4 49 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.31.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 255 ORDER BY a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary1-2.31.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 255 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary1-2.31.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 255 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30} +do_test boundary1-2.31.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 255 ORDER BY rowid DESC + } +} {30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.31.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 255 ORDER BY x + } +} {59 60 41 5 31 4 49 30 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.32.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-2147483648 + } +} {11 ffffffff80000000} +do_test boundary1-2.32.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='ffffffff80000000' + } +} {-2147483648 11} +do_test boundary1-2.32.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=11 + } +} {-2147483648 ffffffff80000000} +do_test boundary1-2.32.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -2147483648 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary1-2.32.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -2147483648 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.32.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -2147483648 ORDER BY rowid + } +} {1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.32.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -2147483648 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1} +do_test boundary1-2.32.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -2147483648 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.32.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -2147483648 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary1-2.32.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -2147483648 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.32.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -2147483648 ORDER BY rowid + } +} {11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.32.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -2147483648 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11} +do_test boundary1-2.32.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -2147483648 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.32.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -2147483648 ORDER BY a + } +} {2 21 44 47 55 58 63 64} +do_test boundary1-2.32.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -2147483648 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 2} +do_test boundary1-2.32.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -2147483648 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47} +do_test boundary1-2.32.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -2147483648 ORDER BY rowid DESC + } +} {47 63 58 44 21 64 2 55} +do_test boundary1-2.32.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -2147483648 ORDER BY x + } +} {55 2 64 21 44 58 63 47} +do_test boundary1-2.32.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -2147483648 ORDER BY a + } +} {2 11 21 44 47 55 58 63 64} +do_test boundary1-2.32.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -2147483648 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 11 2} +do_test boundary1-2.32.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -2147483648 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary1-2.32.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -2147483648 ORDER BY rowid DESC + } +} {11 47 63 58 44 21 64 2 55} +do_test boundary1-2.32.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -2147483648 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary1-2.33.1 { + db eval { + SELECT * FROM t1 WHERE rowid=34359738367 + } +} {39 00000007ffffffff} +do_test boundary1-2.33.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='00000007ffffffff' + } +} {34359738367 39} +do_test boundary1-2.33.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=39 + } +} {34359738367 00000007ffffffff} +do_test boundary1-2.33.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 34359738367 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary1-2.33.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 34359738367 ORDER BY a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary1-2.33.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 34359738367 ORDER BY rowid + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.33.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 34359738367 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22} +do_test boundary1-2.33.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 34359738367 ORDER BY x + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.33.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 34359738367 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 39 43 45 46 56 57} +do_test boundary1-2.33.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 34359738367 ORDER BY a DESC + } +} {57 56 46 45 43 39 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary1-2.33.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 34359738367 ORDER BY rowid + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.33.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 34359738367 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39} +do_test boundary1-2.33.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 34359738367 ORDER BY x + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.33.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 34359738367 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.33.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 34359738367 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.33.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 34359738367 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36} +do_test boundary1-2.33.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 34359738367 ORDER BY rowid DESC + } +} {36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.33.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 34359738367 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.33.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 34359738367 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.33.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 34359738367 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.33.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 34359738367 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39} +do_test boundary1-2.33.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 34359738367 ORDER BY rowid DESC + } +} {39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.33.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 34359738367 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.34.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-549755813889 + } +} {58 ffffff7fffffffff} +do_test boundary1-2.34.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='ffffff7fffffffff' + } +} {-549755813889 58} +do_test boundary1-2.34.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=58 + } +} {-549755813889 ffffff7fffffffff} +do_test boundary1-2.34.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -549755813889 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62 63} +do_test boundary1-2.34.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -549755813889 ORDER BY a DESC + } +} {63 62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.34.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -549755813889 ORDER BY rowid + } +} {63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.34.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -549755813889 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63} +do_test boundary1-2.34.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -549755813889 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.34.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -549755813889 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary1-2.34.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -549755813889 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.34.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -549755813889 ORDER BY rowid + } +} {58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.34.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -549755813889 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58} +do_test boundary1-2.34.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -549755813889 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.34.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -549755813889 ORDER BY a + } +} {2 21 44 55 64} +do_test boundary1-2.34.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -549755813889 ORDER BY a DESC + } +} {64 55 44 21 2} +do_test boundary1-2.34.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -549755813889 ORDER BY rowid + } +} {55 2 64 21 44} +do_test boundary1-2.34.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -549755813889 ORDER BY rowid DESC + } +} {44 21 64 2 55} +do_test boundary1-2.34.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -549755813889 ORDER BY x + } +} {55 2 64 21 44} +do_test boundary1-2.34.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -549755813889 ORDER BY a + } +} {2 21 44 55 58 64} +do_test boundary1-2.34.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -549755813889 ORDER BY a DESC + } +} {64 58 55 44 21 2} +do_test boundary1-2.34.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -549755813889 ORDER BY rowid + } +} {55 2 64 21 44 58} +do_test boundary1-2.34.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -549755813889 ORDER BY rowid DESC + } +} {58 44 21 64 2 55} +do_test boundary1-2.34.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -549755813889 ORDER BY x + } +} {55 2 64 21 44 58} +do_test boundary1-2.35.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-32768 + } +} {32 ffffffffffff8000} +do_test boundary1-2.35.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='ffffffffffff8000' + } +} {-32768 32} +do_test boundary1-2.35.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=32 + } +} {-32768 ffffffffffff8000} +do_test boundary1-2.35.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -32768 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary1-2.35.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -32768 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.35.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -32768 ORDER BY rowid + } +} {54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.35.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -32768 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54} +do_test boundary1-2.35.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -32768 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 54 53 52 33 38} +do_test boundary1-2.35.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -32768 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary1-2.35.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -32768 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.35.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -32768 ORDER BY rowid + } +} {32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.35.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -32768 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32} +do_test boundary1-2.35.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -32768 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 32 54 53 52 33 38} +do_test boundary1-2.35.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -32768 ORDER BY a + } +} {1 2 11 21 29 37 44 47 55 58 63 64} +do_test boundary1-2.35.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -32768 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 29 21 11 2 1} +do_test boundary1-2.35.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -32768 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary1-2.35.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -32768 ORDER BY rowid DESC + } +} {29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.35.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -32768 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary1-2.35.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -32768 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 55 58 63 64} +do_test boundary1-2.35.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -32768 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 32 29 21 11 2 1} +do_test boundary1-2.35.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -32768 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary1-2.35.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -32768 ORDER BY rowid DESC + } +} {32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.35.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -32768 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary1-2.36.1 { + db eval { + SELECT * FROM t1 WHERE rowid=2147483647 + } +} {20 000000007fffffff} +do_test boundary1-2.36.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='000000007fffffff' + } +} {2147483647 20} +do_test boundary1-2.36.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=20 + } +} {2147483647 000000007fffffff} +do_test boundary1-2.36.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 2147483647 ORDER BY a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary1-2.36.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 2147483647 ORDER BY a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary1-2.36.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 2147483647 ORDER BY rowid + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.36.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 2147483647 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51} +do_test boundary1-2.36.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 2147483647 ORDER BY x + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.36.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2147483647 ORDER BY a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary1-2.36.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2147483647 ORDER BY a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary1-2.36.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2147483647 ORDER BY rowid + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.36.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2147483647 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20} +do_test boundary1-2.36.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2147483647 ORDER BY x + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.36.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 2147483647 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.36.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 2147483647 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.36.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 2147483647 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40} +do_test boundary1-2.36.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 2147483647 ORDER BY rowid DESC + } +} {40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.36.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 2147483647 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.36.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2147483647 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.36.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2147483647 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.36.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2147483647 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20} +do_test boundary1-2.36.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2147483647 ORDER BY rowid DESC + } +} {20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.36.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2147483647 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.37.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-129 + } +} {54 ffffffffffffff7f} +do_test boundary1-2.37.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='ffffffffffffff7f' + } +} {-129 54} +do_test boundary1-2.37.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=54 + } +} {-129 ffffffffffffff7f} +do_test boundary1-2.37.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -129 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 56 57 59 60 61 62} +do_test boundary1-2.37.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -129 ORDER BY a DESC + } +} {62 61 60 59 57 56 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.37.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -129 ORDER BY rowid + } +} {53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.37.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -129 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53} +do_test boundary1-2.37.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -129 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 53 52 33 38} +do_test boundary1-2.37.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -129 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary1-2.37.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -129 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.37.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -129 ORDER BY rowid + } +} {54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.37.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -129 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54} +do_test boundary1-2.37.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -129 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 54 53 52 33 38} +do_test boundary1-2.37.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -129 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 55 58 63 64} +do_test boundary1-2.37.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -129 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 32 29 21 11 2 1} +do_test boundary1-2.37.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -129 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary1-2.37.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -129 ORDER BY rowid DESC + } +} {32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.37.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -129 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary1-2.37.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -129 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 54 55 58 63 64} +do_test boundary1-2.37.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -129 ORDER BY a DESC + } +} {64 63 58 55 54 47 44 37 32 29 21 11 2 1} +do_test boundary1-2.37.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -129 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary1-2.37.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -129 ORDER BY rowid DESC + } +} {54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.37.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -129 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary1-2.38.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-128 + } +} {53 ffffffffffffff80} +do_test boundary1-2.38.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='ffffffffffffff80' + } +} {-128 53} +do_test boundary1-2.38.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=53 + } +} {-128 ffffffffffffff80} +do_test boundary1-2.38.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -128 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 56 57 59 60 61 62} +do_test boundary1-2.38.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -128 ORDER BY a DESC + } +} {62 61 60 59 57 56 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.38.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -128 ORDER BY rowid + } +} {52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.38.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -128 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52} +do_test boundary1-2.38.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -128 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 52 33 38} +do_test boundary1-2.38.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -128 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 56 57 59 60 61 62} +do_test boundary1-2.38.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -128 ORDER BY a DESC + } +} {62 61 60 59 57 56 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.38.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -128 ORDER BY rowid + } +} {53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.38.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -128 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53} +do_test boundary1-2.38.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -128 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 53 52 33 38} +do_test boundary1-2.38.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -128 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 54 55 58 63 64} +do_test boundary1-2.38.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -128 ORDER BY a DESC + } +} {64 63 58 55 54 47 44 37 32 29 21 11 2 1} +do_test boundary1-2.38.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -128 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary1-2.38.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -128 ORDER BY rowid DESC + } +} {54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.38.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -128 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary1-2.38.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -128 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 53 54 55 58 63 64} +do_test boundary1-2.38.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -128 ORDER BY a DESC + } +} {64 63 58 55 54 53 47 44 37 32 29 21 11 2 1} +do_test boundary1-2.38.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -128 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary1-2.38.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -128 ORDER BY rowid DESC + } +} {53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.38.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -128 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary1-2.39.1 { + db eval { + SELECT * FROM t1 WHERE rowid=72057594037927936 + } +} {28 0100000000000000} +do_test boundary1-2.39.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0100000000000000' + } +} {72057594037927936 28} +do_test boundary1-2.39.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=28 + } +} {72057594037927936 0100000000000000} +do_test boundary1-2.39.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 72057594037927936 ORDER BY a + } +} {3} +do_test boundary1-2.39.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 72057594037927936 ORDER BY a DESC + } +} {3} +do_test boundary1-2.39.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 72057594037927936 ORDER BY rowid + } +} {3} +do_test boundary1-2.39.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 72057594037927936 ORDER BY rowid DESC + } +} {3} +do_test boundary1-2.39.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 72057594037927936 ORDER BY x + } +} {3} +do_test boundary1-2.39.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 72057594037927936 ORDER BY a + } +} {3 28} +do_test boundary1-2.39.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 72057594037927936 ORDER BY a DESC + } +} {28 3} +do_test boundary1-2.39.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 72057594037927936 ORDER BY rowid + } +} {28 3} +do_test boundary1-2.39.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 72057594037927936 ORDER BY rowid DESC + } +} {3 28} +do_test boundary1-2.39.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 72057594037927936 ORDER BY x + } +} {28 3} +do_test boundary1-2.39.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 72057594037927936 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.39.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 72057594037927936 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.39.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 72057594037927936 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17} +do_test boundary1-2.39.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 72057594037927936 ORDER BY rowid DESC + } +} {17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.39.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 72057594037927936 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.39.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 72057594037927936 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.39.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 72057594037927936 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.39.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 72057594037927936 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28} +do_test boundary1-2.39.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 72057594037927936 ORDER BY rowid DESC + } +} {28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.39.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 72057594037927936 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.40.1 { + db eval { + SELECT * FROM t1 WHERE rowid=2147483648 + } +} {51 0000000080000000} +do_test boundary1-2.40.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000080000000' + } +} {2147483648 51} +do_test boundary1-2.40.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=51 + } +} {2147483648 0000000080000000} +do_test boundary1-2.40.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 2147483648 ORDER BY a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary1-2.40.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 2147483648 ORDER BY a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary1-2.40.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 2147483648 ORDER BY rowid + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.40.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 2147483648 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14} +do_test boundary1-2.40.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 2147483648 ORDER BY x + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.40.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2147483648 ORDER BY a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary1-2.40.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2147483648 ORDER BY a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary1-2.40.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2147483648 ORDER BY rowid + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.40.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2147483648 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51} +do_test boundary1-2.40.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2147483648 ORDER BY x + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.40.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 2147483648 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.40.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 2147483648 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.40.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 2147483648 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20} +do_test boundary1-2.40.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 2147483648 ORDER BY rowid DESC + } +} {20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.40.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 2147483648 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.40.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2147483648 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.40.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2147483648 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.40.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2147483648 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51} +do_test boundary1-2.40.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2147483648 ORDER BY rowid DESC + } +} {51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.40.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2147483648 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.41.1 { + db eval { + SELECT * FROM t1 WHERE rowid=549755813887 + } +} {46 0000007fffffffff} +do_test boundary1-2.41.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000007fffffffff' + } +} {549755813887 46} +do_test boundary1-2.41.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=46 + } +} {549755813887 0000007fffffffff} +do_test boundary1-2.41.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 549755813887 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 56 57} +do_test boundary1-2.41.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 549755813887 ORDER BY a DESC + } +} {57 56 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary1-2.41.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 549755813887 ORDER BY rowid + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.41.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 549755813887 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35} +do_test boundary1-2.41.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 549755813887 ORDER BY x + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.41.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 549755813887 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary1-2.41.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 549755813887 ORDER BY a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary1-2.41.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 549755813887 ORDER BY rowid + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.41.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 549755813887 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46} +do_test boundary1-2.41.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 549755813887 ORDER BY x + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.41.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 549755813887 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.41.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 549755813887 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.41.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 549755813887 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22} +do_test boundary1-2.41.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 549755813887 ORDER BY rowid DESC + } +} {22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.41.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 549755813887 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.41.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 549755813887 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.41.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 549755813887 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.41.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 549755813887 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46} +do_test boundary1-2.41.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 549755813887 ORDER BY rowid DESC + } +} {46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.41.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 549755813887 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.42.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-549755813888 + } +} {63 ffffff8000000000} +do_test boundary1-2.42.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='ffffff8000000000' + } +} {-549755813888 63} +do_test boundary1-2.42.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=63 + } +} {-549755813888 ffffff8000000000} +do_test boundary1-2.42.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -549755813888 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary1-2.42.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -549755813888 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.42.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -549755813888 ORDER BY rowid + } +} {47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.42.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -549755813888 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47} +do_test boundary1-2.42.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -549755813888 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.42.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -549755813888 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62 63} +do_test boundary1-2.42.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -549755813888 ORDER BY a DESC + } +} {63 62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.42.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -549755813888 ORDER BY rowid + } +} {63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.42.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -549755813888 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63} +do_test boundary1-2.42.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -549755813888 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.42.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -549755813888 ORDER BY a + } +} {2 21 44 55 58 64} +do_test boundary1-2.42.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -549755813888 ORDER BY a DESC + } +} {64 58 55 44 21 2} +do_test boundary1-2.42.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -549755813888 ORDER BY rowid + } +} {55 2 64 21 44 58} +do_test boundary1-2.42.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -549755813888 ORDER BY rowid DESC + } +} {58 44 21 64 2 55} +do_test boundary1-2.42.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -549755813888 ORDER BY x + } +} {55 2 64 21 44 58} +do_test boundary1-2.42.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -549755813888 ORDER BY a + } +} {2 21 44 55 58 63 64} +do_test boundary1-2.42.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -549755813888 ORDER BY a DESC + } +} {64 63 58 55 44 21 2} +do_test boundary1-2.42.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -549755813888 ORDER BY rowid + } +} {55 2 64 21 44 58 63} +do_test boundary1-2.42.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -549755813888 ORDER BY rowid DESC + } +} {63 58 44 21 64 2 55} +do_test boundary1-2.42.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -549755813888 ORDER BY x + } +} {55 2 64 21 44 58 63} +do_test boundary1-2.43.1 { + db eval { + SELECT * FROM t1 WHERE rowid=281474976710655 + } +} {10 0000ffffffffffff} +do_test boundary1-2.43.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000ffffffffffff' + } +} {281474976710655 10} +do_test boundary1-2.43.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=10 + } +} {281474976710655 0000ffffffffffff} +do_test boundary1-2.43.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 281474976710655 ORDER BY a + } +} {3 13 17 26 27 28 43 45} +do_test boundary1-2.43.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 281474976710655 ORDER BY a DESC + } +} {45 43 28 27 26 17 13 3} +do_test boundary1-2.43.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 281474976710655 ORDER BY rowid + } +} {26 13 43 27 45 17 28 3} +do_test boundary1-2.43.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 281474976710655 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26} +do_test boundary1-2.43.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 281474976710655 ORDER BY x + } +} {26 13 43 27 45 17 28 3} +do_test boundary1-2.43.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 281474976710655 ORDER BY a + } +} {3 10 13 17 26 27 28 43 45} +do_test boundary1-2.43.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 281474976710655 ORDER BY a DESC + } +} {45 43 28 27 26 17 13 10 3} +do_test boundary1-2.43.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 281474976710655 ORDER BY rowid + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary1-2.43.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 281474976710655 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10} +do_test boundary1-2.43.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 281474976710655 ORDER BY x + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary1-2.43.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 281474976710655 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.43.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 281474976710655 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary1-2.43.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 281474976710655 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34} +do_test boundary1-2.43.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 281474976710655 ORDER BY rowid DESC + } +} {34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.43.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 281474976710655 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.43.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 281474976710655 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.43.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 281474976710655 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.43.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 281474976710655 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10} +do_test boundary1-2.43.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 281474976710655 ORDER BY rowid DESC + } +} {10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.43.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 281474976710655 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.44.1 { + db eval { + SELECT * FROM t1 WHERE rowid=4398046511103 + } +} {7 000003ffffffffff} +do_test boundary1-2.44.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='000003ffffffffff' + } +} {4398046511103 7} +do_test boundary1-2.44.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=7 + } +} {4398046511103 000003ffffffffff} +do_test boundary1-2.44.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 4398046511103 ORDER BY a + } +} {3 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary1-2.44.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 4398046511103 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 3} +do_test boundary1-2.44.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 4398046511103 ORDER BY rowid + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.44.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 4398046511103 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56} +do_test boundary1-2.44.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 4398046511103 ORDER BY x + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.44.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4398046511103 ORDER BY a + } +} {3 7 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary1-2.44.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4398046511103 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 7 3} +do_test boundary1-2.44.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4398046511103 ORDER BY rowid + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.44.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4398046511103 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7} +do_test boundary1-2.44.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4398046511103 ORDER BY x + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.44.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 4398046511103 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary1-2.44.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 4398046511103 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.44.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 4398046511103 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19} +do_test boundary1-2.44.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 4398046511103 ORDER BY rowid DESC + } +} {19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.44.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 4398046511103 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.44.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4398046511103 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary1-2.44.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4398046511103 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary1-2.44.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4398046511103 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7} +do_test boundary1-2.44.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4398046511103 ORDER BY rowid DESC + } +} {7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.44.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4398046511103 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.45.1 { + db eval { + SELECT * FROM t1 WHERE rowid=268435455 + } +} {12 000000000fffffff} +do_test boundary1-2.45.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='000000000fffffff' + } +} {268435455 12} +do_test boundary1-2.45.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=12 + } +} {268435455 000000000fffffff} +do_test boundary1-2.45.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 268435455 ORDER BY a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary1-2.45.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 268435455 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary1-2.45.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 268435455 ORDER BY rowid + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.45.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 268435455 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40} +do_test boundary1-2.45.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 268435455 ORDER BY x + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.45.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 268435455 ORDER BY a + } +} {3 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary1-2.45.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 268435455 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 3} +do_test boundary1-2.45.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 268435455 ORDER BY rowid + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.45.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 268435455 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12} +do_test boundary1-2.45.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 268435455 ORDER BY x + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.45.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 268435455 ORDER BY a + } +} {1 2 4 5 6 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.45.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 268435455 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 6 5 4 2 1} +do_test boundary1-2.45.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 268435455 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6} +do_test boundary1-2.45.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 268435455 ORDER BY rowid DESC + } +} {6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.45.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 268435455 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.45.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 268435455 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.45.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 268435455 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.45.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 268435455 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12} +do_test boundary1-2.45.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 268435455 ORDER BY rowid DESC + } +} {12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.45.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 268435455 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.46.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-9223372036854775808 + } +} {55 8000000000000000} +do_test boundary1-2.46.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='8000000000000000' + } +} {-9223372036854775808 55} +do_test boundary1-2.46.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=55 + } +} {-9223372036854775808 8000000000000000} +do_test boundary1-2.46.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -9223372036854775808 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.46.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -9223372036854775808 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary1-2.46.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -9223372036854775808 ORDER BY rowid + } +} {2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.46.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -9223372036854775808 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2} +do_test boundary1-2.46.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -9223372036854775808 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.46.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -9223372036854775808 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.46.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -9223372036854775808 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary1-2.46.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -9223372036854775808 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.46.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -9223372036854775808 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.46.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -9223372036854775808 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.46.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -9223372036854775808 ORDER BY a + } +} {} +do_test boundary1-2.46.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -9223372036854775808 ORDER BY a DESC + } +} {} +do_test boundary1-2.46.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -9223372036854775808 ORDER BY rowid + } +} {} +do_test boundary1-2.46.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -9223372036854775808 ORDER BY rowid DESC + } +} {} +do_test boundary1-2.46.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -9223372036854775808 ORDER BY x + } +} {} +do_test boundary1-2.46.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -9223372036854775808 ORDER BY a + } +} {55} +do_test boundary1-2.46.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -9223372036854775808 ORDER BY a DESC + } +} {55} +do_test boundary1-2.46.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -9223372036854775808 ORDER BY rowid + } +} {55} +do_test boundary1-2.46.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -9223372036854775808 ORDER BY rowid DESC + } +} {55} +do_test boundary1-2.46.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -9223372036854775808 ORDER BY x + } +} {55} +do_test boundary1-2.47.1 { + db eval { + SELECT * FROM t1 WHERE rowid=562949953421312 + } +} {43 0002000000000000} +do_test boundary1-2.47.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0002000000000000' + } +} {562949953421312 43} +do_test boundary1-2.47.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=43 + } +} {562949953421312 0002000000000000} +do_test boundary1-2.47.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 562949953421312 ORDER BY a + } +} {3 17 27 28 45} +do_test boundary1-2.47.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 562949953421312 ORDER BY a DESC + } +} {45 28 27 17 3} +do_test boundary1-2.47.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 562949953421312 ORDER BY rowid + } +} {27 45 17 28 3} +do_test boundary1-2.47.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 562949953421312 ORDER BY rowid DESC + } +} {3 28 17 45 27} +do_test boundary1-2.47.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 562949953421312 ORDER BY x + } +} {27 45 17 28 3} +do_test boundary1-2.47.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 562949953421312 ORDER BY a + } +} {3 17 27 28 43 45} +do_test boundary1-2.47.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 562949953421312 ORDER BY a DESC + } +} {45 43 28 27 17 3} +do_test boundary1-2.47.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 562949953421312 ORDER BY rowid + } +} {43 27 45 17 28 3} +do_test boundary1-2.47.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 562949953421312 ORDER BY rowid DESC + } +} {3 28 17 45 27 43} +do_test boundary1-2.47.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 562949953421312 ORDER BY x + } +} {43 27 45 17 28 3} +do_test boundary1-2.47.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 562949953421312 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.47.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 562949953421312 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.47.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 562949953421312 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13} +do_test boundary1-2.47.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 562949953421312 ORDER BY rowid DESC + } +} {13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.47.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 562949953421312 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.47.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 562949953421312 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.47.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 562949953421312 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.47.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 562949953421312 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43} +do_test boundary1-2.47.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 562949953421312 ORDER BY rowid DESC + } +} {43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.47.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 562949953421312 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.48.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-8388609 + } +} {1 ffffffffff7fffff} +do_test boundary1-2.48.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='ffffffffff7fffff' + } +} {-8388609 1} +do_test boundary1-2.48.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=1 + } +} {-8388609 ffffffffff7fffff} +do_test boundary1-2.48.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -8388609 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary1-2.48.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -8388609 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.48.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -8388609 ORDER BY rowid + } +} {37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.48.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -8388609 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37} +do_test boundary1-2.48.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -8388609 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 37 29 32 54 53 52 33 38} +do_test boundary1-2.48.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -8388609 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary1-2.48.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -8388609 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.48.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -8388609 ORDER BY rowid + } +} {1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.48.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -8388609 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1} +do_test boundary1-2.48.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -8388609 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.48.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -8388609 ORDER BY a + } +} {2 11 21 44 47 55 58 63 64} +do_test boundary1-2.48.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -8388609 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 11 2} +do_test boundary1-2.48.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -8388609 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary1-2.48.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -8388609 ORDER BY rowid DESC + } +} {11 47 63 58 44 21 64 2 55} +do_test boundary1-2.48.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -8388609 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary1-2.48.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -8388609 ORDER BY a + } +} {1 2 11 21 44 47 55 58 63 64} +do_test boundary1-2.48.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -8388609 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 11 2 1} +do_test boundary1-2.48.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -8388609 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary1-2.48.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -8388609 ORDER BY rowid DESC + } +} {1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.48.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -8388609 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary1-2.49.1 { + db eval { + SELECT * FROM t1 WHERE rowid=16777215 + } +} {9 0000000000ffffff} +do_test boundary1-2.49.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000000ffffff' + } +} {16777215 9} +do_test boundary1-2.49.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=9 + } +} {16777215 0000000000ffffff} +do_test boundary1-2.49.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 16777215 ORDER BY a + } +} {3 6 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary1-2.49.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 16777215 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 6 3} +do_test boundary1-2.49.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 16777215 ORDER BY rowid + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.49.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 16777215 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6} +do_test boundary1-2.49.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 16777215 ORDER BY x + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.49.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16777215 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary1-2.49.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16777215 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary1-2.49.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16777215 ORDER BY rowid + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.49.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16777215 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9} +do_test boundary1-2.49.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16777215 ORDER BY x + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.49.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 16777215 ORDER BY a + } +} {1 2 4 5 8 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.49.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 16777215 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary1-2.49.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 16777215 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24} +do_test boundary1-2.49.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 16777215 ORDER BY rowid DESC + } +} {24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.49.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 16777215 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.49.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16777215 ORDER BY a + } +} {1 2 4 5 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.49.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16777215 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 5 4 2 1} +do_test boundary1-2.49.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16777215 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9} +do_test boundary1-2.49.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16777215 ORDER BY rowid DESC + } +} {9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.49.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16777215 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.50.1 { + db eval { + SELECT * FROM t1 WHERE rowid=8388608 + } +} {24 0000000000800000} +do_test boundary1-2.50.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000000800000' + } +} {8388608 24} +do_test boundary1-2.50.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=24 + } +} {8388608 0000000000800000} +do_test boundary1-2.50.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 8388608 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary1-2.50.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 8388608 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary1-2.50.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 8388608 ORDER BY rowid + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.50.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 8388608 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9} +do_test boundary1-2.50.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 8388608 ORDER BY x + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.50.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 8388608 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary1-2.50.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 8388608 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary1-2.50.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 8388608 ORDER BY rowid + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.50.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 8388608 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24} +do_test boundary1-2.50.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 8388608 ORDER BY x + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.50.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 8388608 ORDER BY a + } +} {1 2 4 5 8 11 15 16 18 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.50.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 8388608 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary1-2.50.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 8388608 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18} +do_test boundary1-2.50.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 8388608 ORDER BY rowid DESC + } +} {18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.50.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 8388608 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.50.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 8388608 ORDER BY a + } +} {1 2 4 5 8 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.50.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 8388608 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary1-2.50.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 8388608 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24} +do_test boundary1-2.50.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 8388608 ORDER BY rowid DESC + } +} {24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.50.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 8388608 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.51.1 { + db eval { + SELECT * FROM t1 WHERE rowid=16383 + } +} {8 0000000000003fff} +do_test boundary1-2.51.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000000003fff' + } +} {16383 8} +do_test boundary1-2.51.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=8 + } +} {16383 0000000000003fff} +do_test boundary1-2.51.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 16383 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary1-2.51.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 16383 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 7 6 3} +do_test boundary1-2.51.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 16383 ORDER BY rowid + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.51.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 16383 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16} +do_test boundary1-2.51.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 16383 ORDER BY x + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.51.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16383 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary1-2.51.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16383 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary1-2.51.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16383 ORDER BY rowid + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.51.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16383 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8} +do_test boundary1-2.51.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16383 ORDER BY x + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.51.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 16383 ORDER BY a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary1-2.51.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 16383 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary1-2.51.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 16383 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61} +do_test boundary1-2.51.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 16383 ORDER BY rowid DESC + } +} {61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.51.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 16383 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.51.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16383 ORDER BY a + } +} {1 2 4 5 8 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary1-2.51.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16383 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 8 5 4 2 1} +do_test boundary1-2.51.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16383 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8} +do_test boundary1-2.51.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16383 ORDER BY rowid DESC + } +} {8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.51.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16383 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.52.1 { + db eval { + SELECT * FROM t1 WHERE rowid=140737488355328 + } +} {34 0000800000000000} +do_test boundary1-2.52.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000800000000000' + } +} {140737488355328 34} +do_test boundary1-2.52.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=34 + } +} {140737488355328 0000800000000000} +do_test boundary1-2.52.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 140737488355328 ORDER BY a + } +} {3 10 13 17 26 27 28 43 45} +do_test boundary1-2.52.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 140737488355328 ORDER BY a DESC + } +} {45 43 28 27 26 17 13 10 3} +do_test boundary1-2.52.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 140737488355328 ORDER BY rowid + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary1-2.52.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 140737488355328 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10} +do_test boundary1-2.52.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 140737488355328 ORDER BY x + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary1-2.52.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 140737488355328 ORDER BY a + } +} {3 10 13 17 26 27 28 34 43 45} +do_test boundary1-2.52.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 140737488355328 ORDER BY a DESC + } +} {45 43 34 28 27 26 17 13 10 3} +do_test boundary1-2.52.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 140737488355328 ORDER BY rowid + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.52.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 140737488355328 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34} +do_test boundary1-2.52.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 140737488355328 ORDER BY x + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.52.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 140737488355328 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.52.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 140737488355328 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary1-2.52.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 140737488355328 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25} +do_test boundary1-2.52.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 140737488355328 ORDER BY rowid DESC + } +} {25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.52.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 140737488355328 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.52.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 140737488355328 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.52.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 140737488355328 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary1-2.52.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 140737488355328 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34} +do_test boundary1-2.52.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 140737488355328 ORDER BY rowid DESC + } +} {34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.52.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 140737488355328 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.53.1 { + db eval { + SELECT * FROM t1 WHERE rowid=2097151 + } +} {15 00000000001fffff} +do_test boundary1-2.53.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='00000000001fffff' + } +} {2097151 15} +do_test boundary1-2.53.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=15 + } +} {2097151 00000000001fffff} +do_test boundary1-2.53.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 2097151 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary1-2.53.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 2097151 ORDER BY a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary1-2.53.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 2097151 ORDER BY rowid + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.53.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 2097151 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42} +do_test boundary1-2.53.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 2097151 ORDER BY x + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.53.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2097151 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary1-2.53.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2097151 ORDER BY a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary1-2.53.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2097151 ORDER BY rowid + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.53.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2097151 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15} +do_test boundary1-2.53.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2097151 ORDER BY x + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.53.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 2097151 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.53.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 2097151 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary1-2.53.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 2097151 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62} +do_test boundary1-2.53.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 2097151 ORDER BY rowid DESC + } +} {62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.53.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 2097151 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.53.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2097151 ORDER BY a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.53.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2097151 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary1-2.53.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2097151 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15} +do_test boundary1-2.53.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2097151 ORDER BY rowid DESC + } +} {15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.53.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2097151 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.54.1 { + db eval { + SELECT * FROM t1 WHERE rowid=140737488355327 + } +} {25 00007fffffffffff} +do_test boundary1-2.54.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='00007fffffffffff' + } +} {140737488355327 25} +do_test boundary1-2.54.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=25 + } +} {140737488355327 00007fffffffffff} +do_test boundary1-2.54.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 140737488355327 ORDER BY a + } +} {3 10 13 17 26 27 28 34 43 45} +do_test boundary1-2.54.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 140737488355327 ORDER BY a DESC + } +} {45 43 34 28 27 26 17 13 10 3} +do_test boundary1-2.54.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 140737488355327 ORDER BY rowid + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.54.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 140737488355327 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34} +do_test boundary1-2.54.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 140737488355327 ORDER BY x + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.54.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 140737488355327 ORDER BY a + } +} {3 10 13 17 25 26 27 28 34 43 45} +do_test boundary1-2.54.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 140737488355327 ORDER BY a DESC + } +} {45 43 34 28 27 26 25 17 13 10 3} +do_test boundary1-2.54.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 140737488355327 ORDER BY rowid + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.54.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 140737488355327 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25} +do_test boundary1-2.54.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 140737488355327 ORDER BY x + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.54.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 140737488355327 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.54.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 140737488355327 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary1-2.54.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 140737488355327 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56} +do_test boundary1-2.54.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 140737488355327 ORDER BY rowid DESC + } +} {56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.54.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 140737488355327 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.54.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 140737488355327 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.54.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 140737488355327 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary1-2.54.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 140737488355327 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25} +do_test boundary1-2.54.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 140737488355327 ORDER BY rowid DESC + } +} {25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.54.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 140737488355327 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.55.1 { + db eval { + SELECT * FROM t1 WHERE rowid=281474976710656 + } +} {26 0001000000000000} +do_test boundary1-2.55.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0001000000000000' + } +} {281474976710656 26} +do_test boundary1-2.55.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=26 + } +} {281474976710656 0001000000000000} +do_test boundary1-2.55.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 281474976710656 ORDER BY a + } +} {3 13 17 27 28 43 45} +do_test boundary1-2.55.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 281474976710656 ORDER BY a DESC + } +} {45 43 28 27 17 13 3} +do_test boundary1-2.55.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 281474976710656 ORDER BY rowid + } +} {13 43 27 45 17 28 3} +do_test boundary1-2.55.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 281474976710656 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13} +do_test boundary1-2.55.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 281474976710656 ORDER BY x + } +} {13 43 27 45 17 28 3} +do_test boundary1-2.55.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 281474976710656 ORDER BY a + } +} {3 13 17 26 27 28 43 45} +do_test boundary1-2.55.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 281474976710656 ORDER BY a DESC + } +} {45 43 28 27 26 17 13 3} +do_test boundary1-2.55.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 281474976710656 ORDER BY rowid + } +} {26 13 43 27 45 17 28 3} +do_test boundary1-2.55.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 281474976710656 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26} +do_test boundary1-2.55.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 281474976710656 ORDER BY x + } +} {26 13 43 27 45 17 28 3} +do_test boundary1-2.55.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 281474976710656 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.55.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 281474976710656 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.55.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 281474976710656 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10} +do_test boundary1-2.55.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 281474976710656 ORDER BY rowid DESC + } +} {10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.55.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 281474976710656 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.55.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 281474976710656 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.55.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 281474976710656 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.55.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 281474976710656 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26} +do_test boundary1-2.55.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 281474976710656 ORDER BY rowid DESC + } +} {26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.55.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 281474976710656 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.56.1 { + db eval { + SELECT * FROM t1 WHERE rowid=32767 + } +} {23 0000000000007fff} +do_test boundary1-2.56.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000000007fff' + } +} {32767 23} +do_test boundary1-2.56.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=23 + } +} {32767 0000000000007fff} +do_test boundary1-2.56.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 32767 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary1-2.56.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 32767 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary1-2.56.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 32767 ORDER BY rowid + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.56.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 32767 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50} +do_test boundary1-2.56.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 32767 ORDER BY x + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.56.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 32767 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary1-2.56.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 32767 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary1-2.56.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 32767 ORDER BY rowid + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.56.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 32767 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23} +do_test boundary1-2.56.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 32767 ORDER BY x + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.56.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 32767 ORDER BY a + } +} {1 2 4 5 8 11 16 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary1-2.56.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 32767 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 16 11 8 5 4 2 1} +do_test boundary1-2.56.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 32767 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16} +do_test boundary1-2.56.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 32767 ORDER BY rowid DESC + } +} {16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.56.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 32767 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.56.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 32767 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary1-2.56.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 32767 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary1-2.56.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 32767 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23} +do_test boundary1-2.56.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 32767 ORDER BY rowid DESC + } +} {23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.56.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 32767 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.57.1 { + db eval { + SELECT * FROM t1 WHERE rowid=127 + } +} {4 000000000000007f} +do_test boundary1-2.57.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='000000000000007f' + } +} {127 4} +do_test boundary1-2.57.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=4 + } +} {127 000000000000007f} +do_test boundary1-2.57.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 127 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary1-2.57.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 127 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary1-2.57.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 127 ORDER BY rowid + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.57.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 127 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49} +do_test boundary1-2.57.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 127 ORDER BY x + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.57.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 127 ORDER BY a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary1-2.57.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 127 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary1-2.57.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 127 ORDER BY rowid + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.57.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 127 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4} +do_test boundary1-2.57.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 127 ORDER BY x + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.57.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 127 ORDER BY a + } +} {1 2 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary1-2.57.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 127 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 2 1} +do_test boundary1-2.57.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 127 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31} +do_test boundary1-2.57.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 127 ORDER BY rowid DESC + } +} {31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.57.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 127 ORDER BY x + } +} {59 60 41 5 31 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.57.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 127 ORDER BY a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary1-2.57.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 127 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary1-2.57.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 127 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4} +do_test boundary1-2.57.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 127 ORDER BY rowid DESC + } +} {4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.57.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 127 ORDER BY x + } +} {59 60 41 5 31 4 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.58.1 { + db eval { + SELECT * FROM t1 WHERE rowid=36028797018963967 + } +} {27 007fffffffffffff} +do_test boundary1-2.58.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='007fffffffffffff' + } +} {36028797018963967 27} +do_test boundary1-2.58.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=27 + } +} {36028797018963967 007fffffffffffff} +do_test boundary1-2.58.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 36028797018963967 ORDER BY a + } +} {3 17 28 45} +do_test boundary1-2.58.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 36028797018963967 ORDER BY a DESC + } +} {45 28 17 3} +do_test boundary1-2.58.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 36028797018963967 ORDER BY rowid + } +} {45 17 28 3} +do_test boundary1-2.58.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 36028797018963967 ORDER BY rowid DESC + } +} {3 28 17 45} +do_test boundary1-2.58.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 36028797018963967 ORDER BY x + } +} {45 17 28 3} +do_test boundary1-2.58.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 36028797018963967 ORDER BY a + } +} {3 17 27 28 45} +do_test boundary1-2.58.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 36028797018963967 ORDER BY a DESC + } +} {45 28 27 17 3} +do_test boundary1-2.58.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 36028797018963967 ORDER BY rowid + } +} {27 45 17 28 3} +do_test boundary1-2.58.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 36028797018963967 ORDER BY rowid DESC + } +} {3 28 17 45 27} +do_test boundary1-2.58.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 36028797018963967 ORDER BY x + } +} {27 45 17 28 3} +do_test boundary1-2.58.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 36028797018963967 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.58.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 36028797018963967 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.58.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 36028797018963967 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43} +do_test boundary1-2.58.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 36028797018963967 ORDER BY rowid DESC + } +} {43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.58.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 36028797018963967 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.58.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 36028797018963967 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.58.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 36028797018963967 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.58.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 36028797018963967 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27} +do_test boundary1-2.58.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 36028797018963967 ORDER BY rowid DESC + } +} {27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.58.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 36028797018963967 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.59.1 { + db eval { + SELECT * FROM t1 WHERE rowid=4398046511104 + } +} {56 0000040000000000} +do_test boundary1-2.59.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000040000000000' + } +} {4398046511104 56} +do_test boundary1-2.59.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=56 + } +} {4398046511104 0000040000000000} +do_test boundary1-2.59.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 4398046511104 ORDER BY a + } +} {3 10 13 17 25 26 27 28 34 43 45} +do_test boundary1-2.59.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 4398046511104 ORDER BY a DESC + } +} {45 43 34 28 27 26 25 17 13 10 3} +do_test boundary1-2.59.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 4398046511104 ORDER BY rowid + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.59.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 4398046511104 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25} +do_test boundary1-2.59.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 4398046511104 ORDER BY x + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.59.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4398046511104 ORDER BY a + } +} {3 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary1-2.59.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4398046511104 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 3} +do_test boundary1-2.59.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4398046511104 ORDER BY rowid + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.59.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4398046511104 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56} +do_test boundary1-2.59.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4398046511104 ORDER BY x + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.59.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 4398046511104 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary1-2.59.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 4398046511104 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary1-2.59.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 4398046511104 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7} +do_test boundary1-2.59.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 4398046511104 ORDER BY rowid DESC + } +} {7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.59.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 4398046511104 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.59.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4398046511104 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.59.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4398046511104 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary1-2.59.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4398046511104 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56} +do_test boundary1-2.59.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4398046511104 ORDER BY rowid DESC + } +} {56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.59.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4398046511104 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.60.1 { + db eval { + SELECT * FROM t1 WHERE rowid=1 + } +} {60 0000000000000001} +do_test boundary1-2.60.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000000000001' + } +} {1 60} +do_test boundary1-2.60.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=60 + } +} {1 0000000000000001} +do_test boundary1-2.60.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 1 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary1-2.60.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 1 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.60.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 1 ORDER BY rowid + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.60.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 1 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41} +do_test boundary1-2.60.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 1 ORDER BY x + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.60.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 1 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 60 61 62} +do_test boundary1-2.60.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 1 ORDER BY a DESC + } +} {62 61 60 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.60.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 1 ORDER BY rowid + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.60.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 1 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60} +do_test boundary1-2.60.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 1 ORDER BY x + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.60.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 1 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 63 64} +do_test boundary1-2.60.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 1 ORDER BY a DESC + } +} {64 63 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary1-2.60.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 1 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59} +do_test boundary1-2.60.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 1 ORDER BY rowid DESC + } +} {59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.60.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 1 ORDER BY x + } +} {59 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.60.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 1 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary1-2.60.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 1 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary1-2.60.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 1 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60} +do_test boundary1-2.60.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 1 ORDER BY rowid DESC + } +} {60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.60.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 1 ORDER BY x + } +} {59 60 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.61.1 { + db eval { + SELECT * FROM t1 WHERE rowid=36028797018963968 + } +} {45 0080000000000000} +do_test boundary1-2.61.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0080000000000000' + } +} {36028797018963968 45} +do_test boundary1-2.61.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=45 + } +} {36028797018963968 0080000000000000} +do_test boundary1-2.61.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 36028797018963968 ORDER BY a + } +} {3 17 28} +do_test boundary1-2.61.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 36028797018963968 ORDER BY a DESC + } +} {28 17 3} +do_test boundary1-2.61.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 36028797018963968 ORDER BY rowid + } +} {17 28 3} +do_test boundary1-2.61.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 36028797018963968 ORDER BY rowid DESC + } +} {3 28 17} +do_test boundary1-2.61.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 36028797018963968 ORDER BY x + } +} {17 28 3} +do_test boundary1-2.61.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 36028797018963968 ORDER BY a + } +} {3 17 28 45} +do_test boundary1-2.61.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 36028797018963968 ORDER BY a DESC + } +} {45 28 17 3} +do_test boundary1-2.61.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 36028797018963968 ORDER BY rowid + } +} {45 17 28 3} +do_test boundary1-2.61.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 36028797018963968 ORDER BY rowid DESC + } +} {3 28 17 45} +do_test boundary1-2.61.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 36028797018963968 ORDER BY x + } +} {45 17 28 3} +do_test boundary1-2.61.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 36028797018963968 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.61.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 36028797018963968 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.61.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 36028797018963968 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27} +do_test boundary1-2.61.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 36028797018963968 ORDER BY rowid DESC + } +} {27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.61.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 36028797018963968 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.61.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 36028797018963968 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.61.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 36028797018963968 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.61.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 36028797018963968 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45} +do_test boundary1-2.61.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 36028797018963968 ORDER BY rowid DESC + } +} {45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.61.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 36028797018963968 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.62.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-2147483649 + } +} {47 ffffffff7fffffff} +do_test boundary1-2.62.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='ffffffff7fffffff' + } +} {-2147483649 47} +do_test boundary1-2.62.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=47 + } +} {-2147483649 ffffffff7fffffff} +do_test boundary1-2.62.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -2147483649 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary1-2.62.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -2147483649 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.62.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -2147483649 ORDER BY rowid + } +} {11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.62.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -2147483649 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11} +do_test boundary1-2.62.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -2147483649 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.62.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -2147483649 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary1-2.62.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -2147483649 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.62.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -2147483649 ORDER BY rowid + } +} {47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.62.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -2147483649 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47} +do_test boundary1-2.62.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -2147483649 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.62.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -2147483649 ORDER BY a + } +} {2 21 44 55 58 63 64} +do_test boundary1-2.62.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -2147483649 ORDER BY a DESC + } +} {64 63 58 55 44 21 2} +do_test boundary1-2.62.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -2147483649 ORDER BY rowid + } +} {55 2 64 21 44 58 63} +do_test boundary1-2.62.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -2147483649 ORDER BY rowid DESC + } +} {63 58 44 21 64 2 55} +do_test boundary1-2.62.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -2147483649 ORDER BY x + } +} {55 2 64 21 44 58 63} +do_test boundary1-2.62.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -2147483649 ORDER BY a + } +} {2 21 44 47 55 58 63 64} +do_test boundary1-2.62.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -2147483649 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 2} +do_test boundary1-2.62.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -2147483649 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47} +do_test boundary1-2.62.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -2147483649 ORDER BY rowid DESC + } +} {47 63 58 44 21 64 2 55} +do_test boundary1-2.62.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -2147483649 ORDER BY x + } +} {55 2 64 21 44 58 63 47} +do_test boundary1-2.63.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-36028797018963969 + } +} {2 ff7fffffffffffff} +do_test boundary1-2.63.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='ff7fffffffffffff' + } +} {-36028797018963969 2} +do_test boundary1-2.63.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=2 + } +} {-36028797018963969 ff7fffffffffffff} +do_test boundary1-2.63.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -36028797018963969 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.63.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -36028797018963969 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.63.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -36028797018963969 ORDER BY rowid + } +} {64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.63.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -36028797018963969 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64} +do_test boundary1-2.63.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -36028797018963969 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.63.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -36028797018963969 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.63.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -36028797018963969 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary1-2.63.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -36028797018963969 ORDER BY rowid + } +} {2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.63.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -36028797018963969 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2} +do_test boundary1-2.63.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -36028797018963969 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.63.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -36028797018963969 ORDER BY a + } +} {55} +do_test boundary1-2.63.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -36028797018963969 ORDER BY a DESC + } +} {55} +do_test boundary1-2.63.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -36028797018963969 ORDER BY rowid + } +} {55} +do_test boundary1-2.63.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -36028797018963969 ORDER BY rowid DESC + } +} {55} +do_test boundary1-2.63.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -36028797018963969 ORDER BY x + } +} {55} +do_test boundary1-2.63.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -36028797018963969 ORDER BY a + } +} {2 55} +do_test boundary1-2.63.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -36028797018963969 ORDER BY a DESC + } +} {55 2} +do_test boundary1-2.63.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -36028797018963969 ORDER BY rowid + } +} {55 2} +do_test boundary1-2.63.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -36028797018963969 ORDER BY rowid DESC + } +} {2 55} +do_test boundary1-2.63.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -36028797018963969 ORDER BY x + } +} {55 2} +do_test boundary1-2.64.1 { + db eval { + SELECT * FROM t1 WHERE rowid=3 + } +} {5 0000000000000003} +do_test boundary1-2.64.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000000000003' + } +} {3 5} +do_test boundary1-2.64.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=5 + } +} {3 0000000000000003} +do_test boundary1-2.64.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 3 ORDER BY a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary1-2.64.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 3 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary1-2.64.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 3 ORDER BY rowid + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.64.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 3 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31} +do_test boundary1-2.64.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 3 ORDER BY x + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.64.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 3 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary1-2.64.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 3 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.64.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 3 ORDER BY rowid + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.64.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 3 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5} +do_test boundary1-2.64.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 3 ORDER BY x + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.64.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 3 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary1-2.64.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 3 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 2 1} +do_test boundary1-2.64.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 3 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41} +do_test boundary1-2.64.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 3 ORDER BY rowid DESC + } +} {41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.64.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 3 ORDER BY x + } +} {59 60 41 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.64.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 3 ORDER BY a + } +} {1 2 5 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary1-2.64.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 3 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 5 2 1} +do_test boundary1-2.64.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 3 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5} +do_test boundary1-2.64.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 3 ORDER BY rowid DESC + } +} {5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.64.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 3 ORDER BY x + } +} {59 60 41 5 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.65.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 9.22337303685477580800e+18 ORDER BY a + } +} {} +do_test boundary1-2.65.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 9.22337303685477580800e+18 ORDER BY a DESC + } +} {} +do_test boundary1-2.65.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 9.22337303685477580800e+18 ORDER BY rowid + } +} {} +do_test boundary1-2.65.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 9.22337303685477580800e+18 ORDER BY rowid DESC + } +} {} +do_test boundary1-2.65.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 9.22337303685477580800e+18 ORDER BY x + } +} {} +do_test boundary1-2.65.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 9.22337303685477580800e+18 ORDER BY a + } +} {} +do_test boundary1-2.65.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 9.22337303685477580800e+18 ORDER BY a DESC + } +} {} +do_test boundary1-2.65.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 9.22337303685477580800e+18 ORDER BY rowid + } +} {} +do_test boundary1-2.65.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 9.22337303685477580800e+18 ORDER BY rowid DESC + } +} {} +do_test boundary1-2.65.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 9.22337303685477580800e+18 ORDER BY x + } +} {} +do_test boundary1-2.65.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 9.22337303685477580800e+18 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.65.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 9.22337303685477580800e+18 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary1-2.65.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 9.22337303685477580800e+18 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.65.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 9.22337303685477580800e+18 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.65.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 9.22337303685477580800e+18 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.65.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 9.22337303685477580800e+18 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.65.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 9.22337303685477580800e+18 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary1-2.65.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 9.22337303685477580800e+18 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.65.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 9.22337303685477580800e+18 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.65.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 9.22337303685477580800e+18 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.66.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -9.22337303685477580800e+18 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.66.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -9.22337303685477580800e+18 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary1-2.66.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -9.22337303685477580800e+18 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.66.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -9.22337303685477580800e+18 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.66.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -9.22337303685477580800e+18 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.66.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -9.22337303685477580800e+18 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.66.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -9.22337303685477580800e+18 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary1-2.66.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -9.22337303685477580800e+18 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.66.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -9.22337303685477580800e+18 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.66.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -9.22337303685477580800e+18 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.66.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -9.22337303685477580800e+18 ORDER BY a + } +} {} +do_test boundary1-2.66.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -9.22337303685477580800e+18 ORDER BY a DESC + } +} {} +do_test boundary1-2.66.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -9.22337303685477580800e+18 ORDER BY rowid + } +} {} +do_test boundary1-2.66.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -9.22337303685477580800e+18 ORDER BY rowid DESC + } +} {} +do_test boundary1-2.66.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -9.22337303685477580800e+18 ORDER BY x + } +} {} +do_test boundary1-2.66.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -9.22337303685477580800e+18 ORDER BY a + } +} {} +do_test boundary1-2.66.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -9.22337303685477580800e+18 ORDER BY a DESC + } +} {} +do_test boundary1-2.66.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -9.22337303685477580800e+18 ORDER BY rowid + } +} {} +do_test boundary1-2.66.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -9.22337303685477580800e+18 ORDER BY rowid DESC + } +} {} +do_test boundary1-2.66.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -9.22337303685477580800e+18 ORDER BY x + } +} {} +finish_test diff --git a/test/boundary2.tcl b/test/boundary2.tcl new file mode 100644 index 0000000..b141166 --- /dev/null +++ b/test/boundary2.tcl @@ -0,0 +1,445 @@ +puts {# 2008 December 11 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file is automatically generated from a separate TCL script. +# This file seeks to exercise integer boundary values. +# +# $Id: boundary2.tcl,v 1.3 2009/01/02 15:45:48 shane Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Many of the boundary tests depend on a working 64-bit implementation. +if {![working_64bit_int]} { finish_test; return } +} + +expr srand(0) + +# Generate interesting boundary numbers +# +foreach x { + 0 + 1 + 0x7f + 0x7fff + 0x7fffff + 0x7fffffff + 0x7fffffffff + 0x7fffffffffff + 0x7fffffffffffff + 0x7fffffffffffffff +} { + set x [expr {wide($x)}] + set boundarynum($x) 1 + set boundarynum([expr {$x+1}]) 1 + set boundarynum([expr {-($x+1)}]) 1 + set boundarynum([expr {-($x+2)}]) 1 + set boundarynum([expr {$x+$x+1}]) 1 + set boundarynum([expr {$x+$x+2}]) 1 +} +set x [expr {wide(127)}] +for {set i 1} {$i<=9} {incr i} { + set boundarynum($x) 1 + set boundarynum([expr {$x+1}]) 1 + set x [expr {wide($x*128 + 127)}] +} + +# Scramble the $inlist into a random order. +# +proc scramble {inlist} { + set y {} + foreach x $inlist { + lappend y [list [expr {rand()}] $x] + } + set y [lsort $y] + set outlist {} + foreach x $y { + lappend outlist [lindex $x 1] + } + return $outlist +} + +# A simple selection sort. Not trying to be efficient. +# +proc sort {inlist} { + set outlist {} + set mn [lindex $inlist 0] + foreach x $inlist { + if {$x<$mn} {set mn $x} + } + set outlist $mn + set mx $mn + while {1} { + set valid 0 + foreach x $inlist { + if {$x>$mx && (!$valid || $mn>$x)} { + set mn $x + set valid 1 + } + } + if {!$valid} break + lappend outlist $mn + set mx $mn + } + return $outlist +} + +# Reverse the order of a list +# +proc reverse {inlist} { + set i [llength $inlist] + set outlist {} + for {incr i -1} {$i>=0} {incr i -1} { + lappend outlist [lindex $inlist $i] + } + return $outlist +} + +set nums1 [scramble [array names boundarynum]] +set nums2 [scramble [array names boundarynum]] + +set tname boundary2 +puts "do_test $tname-1.1 \173" +puts " db eval \173" +puts " CREATE TABLE t1(r INTEGER, a INTEGER, x TEXT);" +set a 0 +foreach r $nums1 { + incr a + set t1ra($r) $a + set t1ar($a) $r + set x [format %08x%08x [expr {wide($r)>>32}] $r] + set t1rx($r) $x + set t1xr($x) $r + puts " INSERT INTO t1 VALUES($r,$a,'$x');" +} +puts " CREATE INDEX t1i1 ON t1(r);" +puts " CREATE INDEX t1i2 ON t1(a);" +puts " CREATE INDEX t1i3 ON t1(x);" +puts " \175" +puts "\175 {}" + +puts "do_test $tname-1.2 \173" +puts " db eval \173" +puts " SELECT count(*) FROM t1" +puts " \175" +puts "\175 {64}" + +set nums3 $nums2 +lappend nums3 9.22337303685477580800e+18 +lappend nums3 -9.22337303685477580800e+18 + +set i 0 +foreach r $nums3 { + incr i + + if {abs($r)<9.22337203685477580800e+18} { + set x $t1rx($r) + set a $t1ra($r) + set r5 $r.5 + set r0 $r.0 + puts "do_test $tname-2.$i.1 \173" + puts " db eval \173" + puts " SELECT * FROM t1 WHERE r=$r" + puts " \175" + puts "\175 {$r $a $x}" + puts "do_test $tname-2.$i.2 \173" + puts " db eval \173" + puts " SELECT r, a FROM t1 WHERE x='$x'" + puts " \175" + puts "\175 {$r $a}" + puts "do_test $tname-2.$i.3 \173" + puts " db eval \173" + puts " SELECT r, x FROM t1 WHERE a=$a" + puts " \175" + puts "\175 {$r $x}" + } + + foreach op {> >= < <=} subno {gt ge lt le} { + + ################################################################ 2.x.y.1 + set rset {} + set aset {} + foreach rx $nums2 { + if "\$rx $op \$r" { + lappend rset $rx + lappend aset $t1ra($rx) + } + } + puts "do_test $tname-2.$i.$subno.1 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r ORDER BY a" + puts " \175" + puts "\175 {[sort $aset]}" + + ################################################################ 2.x.y.2 + puts "do_test $tname-2.$i.$subno.2 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r ORDER BY a DESC" + puts " \175" + puts "\175 {[reverse [sort $aset]]}" + + ################################################################ 2.x.y.3 + set aset {} + foreach rx [sort $rset] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.3 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r ORDER BY r" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.4 + set aset {} + foreach rx [reverse [sort $rset]] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.4 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r ORDER BY r DESC" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.5 + set aset {} + set xset {} + foreach rx $rset { + lappend xset $t1rx($rx) + } + foreach x [sort $xset] { + set rx $t1xr($x) + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.5 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r ORDER BY x" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.10 + if {abs($r)>9223372036854775808 || [string length $r5]>15} continue + set rset {} + set aset {} + foreach rx $nums2 { + if "\$rx $op \$r0" { + lappend rset $rx + } + } + foreach rx [sort $rset] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.10 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r0 ORDER BY r" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.11 + set aset {} + foreach rx [reverse [sort $rset]] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.11 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r0 ORDER BY r DESC" + puts " \175" + puts "\175 {$aset}" + + + ################################################################ 2.x.y.12 + set rset {} + set aset {} + foreach rx $nums2 { + if "\$rx $op \$r5" { + lappend rset $rx + } + } + foreach rx [sort $rset] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.12 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r5 ORDER BY r" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.13 + set aset {} + foreach rx [reverse [sort $rset]] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.13 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r5 ORDER BY r DESC" + puts " \175" + puts "\175 {$aset}" + } +} + +puts "do_test $tname-3.1 \173" +puts " db eval \173" +puts " DROP INDEX t1i1;" +puts " DROP INDEX t1i2;" +puts " DROP INDEX t1i3;" +puts " \175" +puts "\175 {}" + +set i 0 +foreach r $nums3 { + incr i + + if {abs($r)<9.22337203685477580800e+18} { + set x $t1rx($r) + set a $t1ra($r) + set r5 $r.5 + set r0 $r.0 + puts "do_test $tname-4.$i.1 \173" + puts " db eval \173" + puts " SELECT * FROM t1 WHERE r=$r" + puts " \175" + puts "\175 {$r $a $x}" + puts "do_test $tname-4.$i.2 \173" + puts " db eval \173" + puts " SELECT r, a FROM t1 WHERE x='$x'" + puts " \175" + puts "\175 {$r $a}" + puts "do_test $tname-4.$i.3 \173" + puts " db eval \173" + puts " SELECT r, x FROM t1 WHERE a=$a" + puts " \175" + puts "\175 {$r $x}" + } + + foreach op {> >= < <=} subno {gt ge lt le} { + + ################################################################ 2.x.y.1 + set rset {} + set aset {} + foreach rx $nums2 { + if "\$rx $op \$r" { + lappend rset $rx + lappend aset $t1ra($rx) + } + } + puts "do_test $tname-4.$i.$subno.1 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r ORDER BY a" + puts " \175" + puts "\175 {[sort $aset]}" + + ################################################################ 2.x.y.2 + puts "do_test $tname-4.$i.$subno.2 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r ORDER BY a DESC" + puts " \175" + puts "\175 {[reverse [sort $aset]]}" + + ################################################################ 2.x.y.3 + set aset {} + foreach rx [sort $rset] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-4.$i.$subno.3 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r ORDER BY r" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.4 + set aset {} + foreach rx [reverse [sort $rset]] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-4.$i.$subno.4 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r ORDER BY r DESC" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.5 + set aset {} + set xset {} + foreach rx $rset { + lappend xset $t1rx($rx) + } + foreach x [sort $xset] { + set rx $t1xr($x) + lappend aset $t1ra($rx) + } + puts "do_test $tname-4.$i.$subno.5 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r ORDER BY x" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.10 + if {abs($r)>9223372036854775808 || [string length $r5]>15} continue + set rset {} + set aset {} + foreach rx $nums2 { + if "\$rx $op \$r0" { + lappend rset $rx + } + } + foreach rx [sort $rset] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-4.$i.$subno.10 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r0 ORDER BY r" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.11 + set aset {} + foreach rx [reverse [sort $rset]] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-4.$i.$subno.11 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r0 ORDER BY r DESC" + puts " \175" + puts "\175 {$aset}" + + + ################################################################ 2.x.y.12 + set rset {} + set aset {} + foreach rx $nums2 { + if "\$rx $op \$r5" { + lappend rset $rx + } + } + foreach rx [sort $rset] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-4.$i.$subno.12 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r5 ORDER BY r" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.13 + set aset {} + foreach rx [reverse [sort $rset]] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-4.$i.$subno.13 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r5 ORDER BY r DESC" + puts " \175" + puts "\175 {$aset}" + } +} + + +puts {finish_test} diff --git a/test/boundary2.test b/test/boundary2.test new file mode 100644 index 0000000..15a824d --- /dev/null +++ b/test/boundary2.test @@ -0,0 +1,15198 @@ +# 2008 December 11 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file is automatically generated from a separate TCL script. +# This file seeks to exercise integer boundary values. +# +# $Id: boundary2.test,v 1.2 2009/01/02 15:45:48 shane Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Many of the boundary tests depend on a working 64-bit implementation. +if {![working_64bit_int]} { finish_test; return } + +do_test boundary2-1.1 { + db eval { + CREATE TABLE t1(r INTEGER, a INTEGER, x TEXT); + INSERT INTO t1 VALUES(-8388609,1,'ffffffffff7fffff'); + INSERT INTO t1 VALUES(-36028797018963969,2,'ff7fffffffffffff'); + INSERT INTO t1 VALUES(9223372036854775807,3,'7fffffffffffffff'); + INSERT INTO t1 VALUES(127,4,'000000000000007f'); + INSERT INTO t1 VALUES(3,5,'0000000000000003'); + INSERT INTO t1 VALUES(16777216,6,'0000000001000000'); + INSERT INTO t1 VALUES(4398046511103,7,'000003ffffffffff'); + INSERT INTO t1 VALUES(16383,8,'0000000000003fff'); + INSERT INTO t1 VALUES(16777215,9,'0000000000ffffff'); + INSERT INTO t1 VALUES(281474976710655,10,'0000ffffffffffff'); + INSERT INTO t1 VALUES(-2147483648,11,'ffffffff80000000'); + INSERT INTO t1 VALUES(268435455,12,'000000000fffffff'); + INSERT INTO t1 VALUES(562949953421311,13,'0001ffffffffffff'); + INSERT INTO t1 VALUES(4294967295,14,'00000000ffffffff'); + INSERT INTO t1 VALUES(2097151,15,'00000000001fffff'); + INSERT INTO t1 VALUES(16384,16,'0000000000004000'); + INSERT INTO t1 VALUES(72057594037927935,17,'00ffffffffffffff'); + INSERT INTO t1 VALUES(8388607,18,'00000000007fffff'); + INSERT INTO t1 VALUES(1099511627776,19,'0000010000000000'); + INSERT INTO t1 VALUES(2147483647,20,'000000007fffffff'); + INSERT INTO t1 VALUES(-140737488355329,21,'ffff7fffffffffff'); + INSERT INTO t1 VALUES(34359738368,22,'0000000800000000'); + INSERT INTO t1 VALUES(32767,23,'0000000000007fff'); + INSERT INTO t1 VALUES(8388608,24,'0000000000800000'); + INSERT INTO t1 VALUES(140737488355327,25,'00007fffffffffff'); + INSERT INTO t1 VALUES(281474976710656,26,'0001000000000000'); + INSERT INTO t1 VALUES(36028797018963967,27,'007fffffffffffff'); + INSERT INTO t1 VALUES(72057594037927936,28,'0100000000000000'); + INSERT INTO t1 VALUES(-32769,29,'ffffffffffff7fff'); + INSERT INTO t1 VALUES(255,30,'00000000000000ff'); + INSERT INTO t1 VALUES(4,31,'0000000000000004'); + INSERT INTO t1 VALUES(-32768,32,'ffffffffffff8000'); + INSERT INTO t1 VALUES(-2,33,'fffffffffffffffe'); + INSERT INTO t1 VALUES(140737488355328,34,'0000800000000000'); + INSERT INTO t1 VALUES(549755813888,35,'0000008000000000'); + INSERT INTO t1 VALUES(4294967296,36,'0000000100000000'); + INSERT INTO t1 VALUES(-8388608,37,'ffffffffff800000'); + INSERT INTO t1 VALUES(-1,38,'ffffffffffffffff'); + INSERT INTO t1 VALUES(34359738367,39,'00000007ffffffff'); + INSERT INTO t1 VALUES(268435456,40,'0000000010000000'); + INSERT INTO t1 VALUES(2,41,'0000000000000002'); + INSERT INTO t1 VALUES(2097152,42,'0000000000200000'); + INSERT INTO t1 VALUES(562949953421312,43,'0002000000000000'); + INSERT INTO t1 VALUES(-140737488355328,44,'ffff800000000000'); + INSERT INTO t1 VALUES(36028797018963968,45,'0080000000000000'); + INSERT INTO t1 VALUES(549755813887,46,'0000007fffffffff'); + INSERT INTO t1 VALUES(-2147483649,47,'ffffffff7fffffff'); + INSERT INTO t1 VALUES(65535,48,'000000000000ffff'); + INSERT INTO t1 VALUES(128,49,'0000000000000080'); + INSERT INTO t1 VALUES(32768,50,'0000000000008000'); + INSERT INTO t1 VALUES(2147483648,51,'0000000080000000'); + INSERT INTO t1 VALUES(-3,52,'fffffffffffffffd'); + INSERT INTO t1 VALUES(-128,53,'ffffffffffffff80'); + INSERT INTO t1 VALUES(-129,54,'ffffffffffffff7f'); + INSERT INTO t1 VALUES(-9223372036854775808,55,'8000000000000000'); + INSERT INTO t1 VALUES(4398046511104,56,'0000040000000000'); + INSERT INTO t1 VALUES(1099511627775,57,'000000ffffffffff'); + INSERT INTO t1 VALUES(-549755813889,58,'ffffff7fffffffff'); + INSERT INTO t1 VALUES(0,59,'0000000000000000'); + INSERT INTO t1 VALUES(1,60,'0000000000000001'); + INSERT INTO t1 VALUES(256,61,'0000000000000100'); + INSERT INTO t1 VALUES(65536,62,'0000000000010000'); + INSERT INTO t1 VALUES(-549755813888,63,'ffffff8000000000'); + INSERT INTO t1 VALUES(-36028797018963968,64,'ff80000000000000'); + CREATE INDEX t1i1 ON t1(r); + CREATE INDEX t1i2 ON t1(a); + CREATE INDEX t1i3 ON t1(x); + } +} {} +do_test boundary2-1.2 { + db eval { + SELECT count(*) FROM t1 + } +} {64} +do_test boundary2-2.1.1 { + db eval { + SELECT * FROM t1 WHERE r=72057594037927935 + } +} {72057594037927935 17 00ffffffffffffff} +do_test boundary2-2.1.2 { + db eval { + SELECT r, a FROM t1 WHERE x='00ffffffffffffff' + } +} {72057594037927935 17} +do_test boundary2-2.1.3 { + db eval { + SELECT r, x FROM t1 WHERE a=17 + } +} {72057594037927935 00ffffffffffffff} +do_test boundary2-2.1.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927935 ORDER BY a + } +} {3 28} +do_test boundary2-2.1.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927935 ORDER BY a DESC + } +} {28 3} +do_test boundary2-2.1.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927935 ORDER BY r + } +} {28 3} +do_test boundary2-2.1.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927935 ORDER BY r DESC + } +} {3 28} +do_test boundary2-2.1.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927935 ORDER BY x + } +} {28 3} +do_test boundary2-2.1.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927935 ORDER BY a + } +} {3 17 28} +do_test boundary2-2.1.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927935 ORDER BY a DESC + } +} {28 17 3} +do_test boundary2-2.1.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927935 ORDER BY r + } +} {17 28 3} +do_test boundary2-2.1.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927935 ORDER BY r DESC + } +} {3 28 17} +do_test boundary2-2.1.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927935 ORDER BY x + } +} {17 28 3} +do_test boundary2-2.1.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927935 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.1.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927935 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.1.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927935 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45} +do_test boundary2-2.1.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927935 ORDER BY r DESC + } +} {45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.1.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927935 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.1.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927935 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.1.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927935 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.1.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927935 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17} +do_test boundary2-2.1.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927935 ORDER BY r DESC + } +} {17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.1.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927935 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.2.1 { + db eval { + SELECT * FROM t1 WHERE r=16384 + } +} {16384 16 0000000000004000} +do_test boundary2-2.2.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000004000' + } +} {16384 16} +do_test boundary2-2.2.3 { + db eval { + SELECT r, x FROM t1 WHERE a=16 + } +} {16384 0000000000004000} +do_test boundary2-2.2.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 16384 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-2.2.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 16384 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-2.2.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 16384 ORDER BY r + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.2.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 16384 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23} +do_test boundary2-2.2.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 16384 ORDER BY x + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.2.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 16384 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-2.2.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 16384 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 7 6 3} +do_test boundary2-2.2.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 16384 ORDER BY r + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.2.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 16384 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16} +do_test boundary2-2.2.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 16384 ORDER BY x + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.2.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 16384 ORDER BY a + } +} {1 2 4 5 8 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-2.2.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 16384 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 8 5 4 2 1} +do_test boundary2-2.2.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 16384 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8} +do_test boundary2-2.2.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 16384 ORDER BY r DESC + } +} {8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.2.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 16384 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.2.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 16384 ORDER BY a + } +} {1 2 4 5 8 11 16 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-2.2.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 16384 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 16 11 8 5 4 2 1} +do_test boundary2-2.2.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 16384 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16} +do_test boundary2-2.2.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 16384 ORDER BY r DESC + } +} {16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.2.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 16384 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.3.1 { + db eval { + SELECT * FROM t1 WHERE r=4294967296 + } +} {4294967296 36 0000000100000000} +do_test boundary2-2.3.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000100000000' + } +} {4294967296 36} +do_test boundary2-2.3.3 { + db eval { + SELECT r, x FROM t1 WHERE a=36 + } +} {4294967296 0000000100000000} +do_test boundary2-2.3.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 4294967296 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 39 43 45 46 56 57} +do_test boundary2-2.3.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 4294967296 ORDER BY a DESC + } +} {57 56 46 45 43 39 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary2-2.3.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 4294967296 ORDER BY r + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.3.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 4294967296 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39} +do_test boundary2-2.3.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 4294967296 ORDER BY x + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.3.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967296 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary2-2.3.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967296 ORDER BY a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary2-2.3.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967296 ORDER BY r + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.3.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967296 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36} +do_test boundary2-2.3.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967296 ORDER BY x + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.3.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 4294967296 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.3.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 4294967296 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.3.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 4294967296 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14} +do_test boundary2-2.3.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 4294967296 ORDER BY r DESC + } +} {14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.3.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 4294967296 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.3.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967296 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.3.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967296 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.3.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967296 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36} +do_test boundary2-2.3.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967296 ORDER BY r DESC + } +} {36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.3.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967296 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.4.1 { + db eval { + SELECT * FROM t1 WHERE r=16777216 + } +} {16777216 6 0000000001000000} +do_test boundary2-2.4.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000001000000' + } +} {16777216 6} +do_test boundary2-2.4.3 { + db eval { + SELECT r, x FROM t1 WHERE a=6 + } +} {16777216 0000000001000000} +do_test boundary2-2.4.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 16777216 ORDER BY a + } +} {3 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-2.4.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 16777216 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 3} +do_test boundary2-2.4.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 16777216 ORDER BY r + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.4.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 16777216 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12} +do_test boundary2-2.4.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 16777216 ORDER BY x + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.4.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 16777216 ORDER BY a + } +} {3 6 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-2.4.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 16777216 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 6 3} +do_test boundary2-2.4.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 16777216 ORDER BY r + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.4.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 16777216 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6} +do_test boundary2-2.4.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 16777216 ORDER BY x + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.4.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 16777216 ORDER BY a + } +} {1 2 4 5 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.4.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 16777216 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 5 4 2 1} +do_test boundary2-2.4.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 16777216 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9} +do_test boundary2-2.4.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 16777216 ORDER BY r DESC + } +} {9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.4.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 16777216 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.4.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 16777216 ORDER BY a + } +} {1 2 4 5 6 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.4.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 16777216 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 6 5 4 2 1} +do_test boundary2-2.4.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 16777216 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6} +do_test boundary2-2.4.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 16777216 ORDER BY r DESC + } +} {6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.4.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 16777216 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.5.1 { + db eval { + SELECT * FROM t1 WHERE r=-32769 + } +} {-32769 29 ffffffffffff7fff} +do_test boundary2-2.5.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffffffff7fff' + } +} {-32769 29} +do_test boundary2-2.5.3 { + db eval { + SELECT r, x FROM t1 WHERE a=29 + } +} {-32769 ffffffffffff7fff} +do_test boundary2-2.5.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -32769 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-2.5.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -32769 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.5.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -32769 ORDER BY r + } +} {32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.5.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -32769 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32} +do_test boundary2-2.5.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -32769 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 32 54 53 52 33 38} +do_test boundary2-2.5.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -32769 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-2.5.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -32769 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.5.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -32769 ORDER BY r + } +} {29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.5.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -32769 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29} +do_test boundary2-2.5.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -32769 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 29 32 54 53 52 33 38} +do_test boundary2-2.5.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -32769 ORDER BY a + } +} {1 2 11 21 37 44 47 55 58 63 64} +do_test boundary2-2.5.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -32769 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 21 11 2 1} +do_test boundary2-2.5.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -32769 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary2-2.5.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -32769 ORDER BY r DESC + } +} {37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.5.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -32769 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary2-2.5.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -32769 ORDER BY a + } +} {1 2 11 21 29 37 44 47 55 58 63 64} +do_test boundary2-2.5.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -32769 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 29 21 11 2 1} +do_test boundary2-2.5.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -32769 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary2-2.5.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -32769 ORDER BY r DESC + } +} {29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.5.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -32769 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary2-2.6.1 { + db eval { + SELECT * FROM t1 WHERE r=-140737488355329 + } +} {-140737488355329 21 ffff7fffffffffff} +do_test boundary2-2.6.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffff7fffffffffff' + } +} {-140737488355329 21} +do_test boundary2-2.6.3 { + db eval { + SELECT r, x FROM t1 WHERE a=21 + } +} {-140737488355329 ffff7fffffffffff} +do_test boundary2-2.6.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355329 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary2-2.6.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355329 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.6.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355329 ORDER BY r + } +} {44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.6.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355329 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44} +do_test boundary2-2.6.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355329 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.6.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355329 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary2-2.6.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355329 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.6.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355329 ORDER BY r + } +} {21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.6.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355329 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21} +do_test boundary2-2.6.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355329 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.6.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355329 ORDER BY a + } +} {2 55 64} +do_test boundary2-2.6.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355329 ORDER BY a DESC + } +} {64 55 2} +do_test boundary2-2.6.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355329 ORDER BY r + } +} {55 2 64} +do_test boundary2-2.6.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355329 ORDER BY r DESC + } +} {64 2 55} +do_test boundary2-2.6.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355329 ORDER BY x + } +} {55 2 64} +do_test boundary2-2.6.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355329 ORDER BY a + } +} {2 21 55 64} +do_test boundary2-2.6.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355329 ORDER BY a DESC + } +} {64 55 21 2} +do_test boundary2-2.6.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355329 ORDER BY r + } +} {55 2 64 21} +do_test boundary2-2.6.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355329 ORDER BY r DESC + } +} {21 64 2 55} +do_test boundary2-2.6.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355329 ORDER BY x + } +} {55 2 64 21} +do_test boundary2-2.7.1 { + db eval { + SELECT * FROM t1 WHERE r=2 + } +} {2 41 0000000000000002} +do_test boundary2-2.7.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000000002' + } +} {2 41} +do_test boundary2-2.7.3 { + db eval { + SELECT r, x FROM t1 WHERE a=41 + } +} {2 0000000000000002} +do_test boundary2-2.7.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 2 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-2.7.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 2 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.7.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 2 ORDER BY r + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.7.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 2 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5} +do_test boundary2-2.7.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 2 ORDER BY x + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.7.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 2 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-2.7.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 2 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.7.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 2 ORDER BY r + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.7.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 2 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41} +do_test boundary2-2.7.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 2 ORDER BY x + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.7.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 2 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-2.7.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 2 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary2-2.7.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 2 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60} +do_test boundary2-2.7.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 2 ORDER BY r DESC + } +} {60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.7.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 2 ORDER BY x + } +} {59 60 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.7.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 2 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-2.7.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 2 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 2 1} +do_test boundary2-2.7.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 2 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41} +do_test boundary2-2.7.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 2 ORDER BY r DESC + } +} {41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.7.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 2 ORDER BY x + } +} {59 60 41 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.8.1 { + db eval { + SELECT * FROM t1 WHERE r=4 + } +} {4 31 0000000000000004} +do_test boundary2-2.8.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000000004' + } +} {4 31} +do_test boundary2-2.8.3 { + db eval { + SELECT r, x FROM t1 WHERE a=31 + } +} {4 0000000000000004} +do_test boundary2-2.8.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 4 ORDER BY a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-2.8.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 4 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary2-2.8.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 4 ORDER BY r + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.8.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 4 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4} +do_test boundary2-2.8.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 4 ORDER BY x + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.8.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 4 ORDER BY a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-2.8.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 4 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary2-2.8.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 4 ORDER BY r + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.8.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 4 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31} +do_test boundary2-2.8.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 4 ORDER BY x + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.8.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 4 ORDER BY a + } +} {1 2 5 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-2.8.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 4 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 5 2 1} +do_test boundary2-2.8.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 4 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5} +do_test boundary2-2.8.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 4 ORDER BY r DESC + } +} {5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.8.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 4 ORDER BY x + } +} {59 60 41 5 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.8.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 4 ORDER BY a + } +} {1 2 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-2.8.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 4 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 2 1} +do_test boundary2-2.8.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 4 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31} +do_test boundary2-2.8.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 4 ORDER BY r DESC + } +} {31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.8.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 4 ORDER BY x + } +} {59 60 41 5 31 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.9.1 { + db eval { + SELECT * FROM t1 WHERE r=562949953421311 + } +} {562949953421311 13 0001ffffffffffff} +do_test boundary2-2.9.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0001ffffffffffff' + } +} {562949953421311 13} +do_test boundary2-2.9.3 { + db eval { + SELECT r, x FROM t1 WHERE a=13 + } +} {562949953421311 0001ffffffffffff} +do_test boundary2-2.9.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421311 ORDER BY a + } +} {3 17 27 28 43 45} +do_test boundary2-2.9.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421311 ORDER BY a DESC + } +} {45 43 28 27 17 3} +do_test boundary2-2.9.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421311 ORDER BY r + } +} {43 27 45 17 28 3} +do_test boundary2-2.9.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421311 ORDER BY r DESC + } +} {3 28 17 45 27 43} +do_test boundary2-2.9.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421311 ORDER BY x + } +} {43 27 45 17 28 3} +do_test boundary2-2.9.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421311 ORDER BY a + } +} {3 13 17 27 28 43 45} +do_test boundary2-2.9.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421311 ORDER BY a DESC + } +} {45 43 28 27 17 13 3} +do_test boundary2-2.9.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421311 ORDER BY r + } +} {13 43 27 45 17 28 3} +do_test boundary2-2.9.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421311 ORDER BY r DESC + } +} {3 28 17 45 27 43 13} +do_test boundary2-2.9.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421311 ORDER BY x + } +} {13 43 27 45 17 28 3} +do_test boundary2-2.9.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421311 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.9.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421311 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.9.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421311 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26} +do_test boundary2-2.9.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421311 ORDER BY r DESC + } +} {26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.9.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421311 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.9.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421311 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.9.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421311 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.9.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421311 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13} +do_test boundary2-2.9.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421311 ORDER BY r DESC + } +} {13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.9.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421311 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.10.1 { + db eval { + SELECT * FROM t1 WHERE r=256 + } +} {256 61 0000000000000100} +do_test boundary2-2.10.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000000100' + } +} {256 61} +do_test boundary2-2.10.3 { + db eval { + SELECT r, x FROM t1 WHERE a=61 + } +} {256 0000000000000100} +do_test boundary2-2.10.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 256 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-2.10.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 256 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-2.10.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 256 ORDER BY r + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.10.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 256 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8} +do_test boundary2-2.10.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 256 ORDER BY x + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.10.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 256 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary2-2.10.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 256 ORDER BY a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-2.10.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 256 ORDER BY r + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.10.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 256 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61} +do_test boundary2-2.10.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 256 ORDER BY x + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.10.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 256 ORDER BY a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary2-2.10.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 256 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary2-2.10.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 256 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30} +do_test boundary2-2.10.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 256 ORDER BY r DESC + } +} {30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.10.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 256 ORDER BY x + } +} {59 60 41 5 31 4 49 30 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.10.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 256 ORDER BY a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-2.10.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 256 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary2-2.10.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 256 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61} +do_test boundary2-2.10.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 256 ORDER BY r DESC + } +} {61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.10.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 256 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.11.1 { + db eval { + SELECT * FROM t1 WHERE r=34359738368 + } +} {34359738368 22 0000000800000000} +do_test boundary2-2.11.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000800000000' + } +} {34359738368 22} +do_test boundary2-2.11.3 { + db eval { + SELECT r, x FROM t1 WHERE a=22 + } +} {34359738368 0000000800000000} +do_test boundary2-2.11.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 34359738368 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary2-2.11.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 34359738368 ORDER BY a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-2.11.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 34359738368 ORDER BY r + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.11.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 34359738368 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46} +do_test boundary2-2.11.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 34359738368 ORDER BY x + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.11.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738368 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary2-2.11.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738368 ORDER BY a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary2-2.11.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738368 ORDER BY r + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.11.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738368 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22} +do_test boundary2-2.11.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738368 ORDER BY x + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.11.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 34359738368 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.11.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 34359738368 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.11.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 34359738368 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39} +do_test boundary2-2.11.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 34359738368 ORDER BY r DESC + } +} {39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.11.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 34359738368 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.11.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738368 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.11.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738368 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.11.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738368 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22} +do_test boundary2-2.11.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738368 ORDER BY r DESC + } +} {22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.11.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738368 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.12.1 { + db eval { + SELECT * FROM t1 WHERE r=65536 + } +} {65536 62 0000000000010000} +do_test boundary2-2.12.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000010000' + } +} {65536 62} +do_test boundary2-2.12.3 { + db eval { + SELECT r, x FROM t1 WHERE a=62 + } +} {65536 0000000000010000} +do_test boundary2-2.12.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 65536 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary2-2.12.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 65536 ORDER BY a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-2.12.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 65536 ORDER BY r + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.12.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 65536 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15} +do_test boundary2-2.12.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 65536 ORDER BY x + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.12.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 65536 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57 62} +do_test boundary2-2.12.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 65536 ORDER BY a DESC + } +} {62 57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-2.12.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 65536 ORDER BY r + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.12.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 65536 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62} +do_test boundary2-2.12.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 65536 ORDER BY x + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.12.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 65536 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-2.12.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 65536 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-2.12.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 65536 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48} +do_test boundary2-2.12.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 65536 ORDER BY r DESC + } +} {48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.12.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 65536 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.12.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 65536 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.12.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 65536 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-2.12.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 65536 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62} +do_test boundary2-2.12.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 65536 ORDER BY r DESC + } +} {62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.12.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 65536 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.13.1 { + db eval { + SELECT * FROM t1 WHERE r=268435456 + } +} {268435456 40 0000000010000000} +do_test boundary2-2.13.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000010000000' + } +} {268435456 40} +do_test boundary2-2.13.3 { + db eval { + SELECT r, x FROM t1 WHERE a=40 + } +} {268435456 0000000010000000} +do_test boundary2-2.13.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 268435456 ORDER BY a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary2-2.13.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 268435456 ORDER BY a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary2-2.13.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 268435456 ORDER BY r + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.13.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 268435456 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20} +do_test boundary2-2.13.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 268435456 ORDER BY x + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.13.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 268435456 ORDER BY a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-2.13.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 268435456 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary2-2.13.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 268435456 ORDER BY r + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.13.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 268435456 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40} +do_test boundary2-2.13.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 268435456 ORDER BY x + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.13.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 268435456 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.13.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 268435456 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.13.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 268435456 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12} +do_test boundary2-2.13.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 268435456 ORDER BY r DESC + } +} {12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.13.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 268435456 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.13.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 268435456 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.13.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 268435456 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.13.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 268435456 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40} +do_test boundary2-2.13.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 268435456 ORDER BY r DESC + } +} {40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.13.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 268435456 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.14.1 { + db eval { + SELECT * FROM t1 WHERE r=-140737488355328 + } +} {-140737488355328 44 ffff800000000000} +do_test boundary2-2.14.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffff800000000000' + } +} {-140737488355328 44} +do_test boundary2-2.14.3 { + db eval { + SELECT r, x FROM t1 WHERE a=44 + } +} {-140737488355328 ffff800000000000} +do_test boundary2-2.14.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355328 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary2-2.14.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355328 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.14.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355328 ORDER BY r + } +} {58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.14.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355328 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58} +do_test boundary2-2.14.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355328 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.14.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355328 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary2-2.14.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355328 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.14.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355328 ORDER BY r + } +} {44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.14.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355328 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44} +do_test boundary2-2.14.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355328 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.14.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355328 ORDER BY a + } +} {2 21 55 64} +do_test boundary2-2.14.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355328 ORDER BY a DESC + } +} {64 55 21 2} +do_test boundary2-2.14.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355328 ORDER BY r + } +} {55 2 64 21} +do_test boundary2-2.14.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355328 ORDER BY r DESC + } +} {21 64 2 55} +do_test boundary2-2.14.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355328 ORDER BY x + } +} {55 2 64 21} +do_test boundary2-2.14.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355328 ORDER BY a + } +} {2 21 44 55 64} +do_test boundary2-2.14.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355328 ORDER BY a DESC + } +} {64 55 44 21 2} +do_test boundary2-2.14.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355328 ORDER BY r + } +} {55 2 64 21 44} +do_test boundary2-2.14.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355328 ORDER BY r DESC + } +} {44 21 64 2 55} +do_test boundary2-2.14.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355328 ORDER BY x + } +} {55 2 64 21 44} +do_test boundary2-2.15.1 { + db eval { + SELECT * FROM t1 WHERE r=1099511627776 + } +} {1099511627776 19 0000010000000000} +do_test boundary2-2.15.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000010000000000' + } +} {1099511627776 19} +do_test boundary2-2.15.3 { + db eval { + SELECT r, x FROM t1 WHERE a=19 + } +} {1099511627776 0000010000000000} +do_test boundary2-2.15.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627776 ORDER BY a + } +} {3 7 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary2-2.15.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627776 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 7 3} +do_test boundary2-2.15.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627776 ORDER BY r + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.15.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627776 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7} +do_test boundary2-2.15.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627776 ORDER BY x + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.15.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627776 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56} +do_test boundary2-2.15.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627776 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-2.15.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627776 ORDER BY r + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.15.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627776 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19} +do_test boundary2-2.15.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627776 ORDER BY x + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.15.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627776 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary2-2.15.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627776 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.15.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627776 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57} +do_test boundary2-2.15.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627776 ORDER BY r DESC + } +} {57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.15.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627776 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.15.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627776 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary2-2.15.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627776 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.15.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627776 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19} +do_test boundary2-2.15.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627776 ORDER BY r DESC + } +} {19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.15.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627776 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.16.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 9223372036854775807 ORDER BY a + } +} {} +do_test boundary2-2.16.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 9223372036854775807 ORDER BY a DESC + } +} {} +do_test boundary2-2.16.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 9223372036854775807 ORDER BY r + } +} {} +do_test boundary2-2.16.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 9223372036854775807 ORDER BY r DESC + } +} {} +do_test boundary2-2.16.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 9223372036854775807 ORDER BY x + } +} {} +do_test boundary2-2.16.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 9223372036854775807 ORDER BY a + } +} {3} +do_test boundary2-2.16.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 9223372036854775807 ORDER BY a DESC + } +} {3} +do_test boundary2-2.16.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 9223372036854775807 ORDER BY r + } +} {3} +do_test boundary2-2.16.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 9223372036854775807 ORDER BY r DESC + } +} {3} +do_test boundary2-2.16.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 9223372036854775807 ORDER BY x + } +} {3} +do_test boundary2-2.16.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 9223372036854775807 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.16.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 9223372036854775807 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.16.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 9223372036854775807 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28} +do_test boundary2-2.16.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 9223372036854775807 ORDER BY r DESC + } +} {28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.16.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 9223372036854775807 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.16.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 9223372036854775807 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.16.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 9223372036854775807 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-2.16.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 9223372036854775807 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.16.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 9223372036854775807 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.16.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 9223372036854775807 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.17.1 { + db eval { + SELECT * FROM t1 WHERE r=32768 + } +} {32768 50 0000000000008000} +do_test boundary2-2.17.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000008000' + } +} {32768 50} +do_test boundary2-2.17.3 { + db eval { + SELECT r, x FROM t1 WHERE a=50 + } +} {32768 0000000000008000} +do_test boundary2-2.17.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 32768 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 51 56 57 62} +do_test boundary2-2.17.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 32768 ORDER BY a DESC + } +} {62 57 56 51 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-2.17.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 32768 ORDER BY r + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.17.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 32768 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48} +do_test boundary2-2.17.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 32768 ORDER BY x + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.17.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 32768 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-2.17.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 32768 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-2.17.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 32768 ORDER BY r + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.17.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 32768 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50} +do_test boundary2-2.17.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 32768 ORDER BY x + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.17.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 32768 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-2.17.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 32768 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-2.17.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 32768 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23} +do_test boundary2-2.17.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 32768 ORDER BY r DESC + } +} {23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.17.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 32768 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.17.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 32768 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-2.17.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 32768 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-2.17.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 32768 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50} +do_test boundary2-2.17.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 32768 ORDER BY r DESC + } +} {50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.17.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 32768 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.18.1 { + db eval { + SELECT * FROM t1 WHERE r=-36028797018963968 + } +} {-36028797018963968 64 ff80000000000000} +do_test boundary2-2.18.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ff80000000000000' + } +} {-36028797018963968 64} +do_test boundary2-2.18.3 { + db eval { + SELECT r, x FROM t1 WHERE a=64 + } +} {-36028797018963968 ff80000000000000} +do_test boundary2-2.18.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963968 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary2-2.18.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963968 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.18.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963968 ORDER BY r + } +} {21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.18.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963968 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21} +do_test boundary2-2.18.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963968 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.18.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963968 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.18.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963968 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.18.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963968 ORDER BY r + } +} {64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.18.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963968 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64} +do_test boundary2-2.18.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963968 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.18.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963968 ORDER BY a + } +} {2 55} +do_test boundary2-2.18.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963968 ORDER BY a DESC + } +} {55 2} +do_test boundary2-2.18.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963968 ORDER BY r + } +} {55 2} +do_test boundary2-2.18.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963968 ORDER BY r DESC + } +} {2 55} +do_test boundary2-2.18.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963968 ORDER BY x + } +} {55 2} +do_test boundary2-2.18.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963968 ORDER BY a + } +} {2 55 64} +do_test boundary2-2.18.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963968 ORDER BY a DESC + } +} {64 55 2} +do_test boundary2-2.18.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963968 ORDER BY r + } +} {55 2 64} +do_test boundary2-2.18.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963968 ORDER BY r DESC + } +} {64 2 55} +do_test boundary2-2.18.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963968 ORDER BY x + } +} {55 2 64} +do_test boundary2-2.19.1 { + db eval { + SELECT * FROM t1 WHERE r=65535 + } +} {65535 48 000000000000ffff} +do_test boundary2-2.19.2 { + db eval { + SELECT r, a FROM t1 WHERE x='000000000000ffff' + } +} {65535 48} +do_test boundary2-2.19.3 { + db eval { + SELECT r, x FROM t1 WHERE a=48 + } +} {65535 000000000000ffff} +do_test boundary2-2.19.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 65535 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57 62} +do_test boundary2-2.19.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 65535 ORDER BY a DESC + } +} {62 57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-2.19.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 65535 ORDER BY r + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.19.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 65535 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62} +do_test boundary2-2.19.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 65535 ORDER BY x + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.19.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 65535 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 51 56 57 62} +do_test boundary2-2.19.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 65535 ORDER BY a DESC + } +} {62 57 56 51 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-2.19.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 65535 ORDER BY r + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.19.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 65535 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48} +do_test boundary2-2.19.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 65535 ORDER BY x + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.19.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 65535 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-2.19.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 65535 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-2.19.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 65535 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50} +do_test boundary2-2.19.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 65535 ORDER BY r DESC + } +} {50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.19.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 65535 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.19.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 65535 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-2.19.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 65535 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-2.19.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 65535 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48} +do_test boundary2-2.19.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 65535 ORDER BY r DESC + } +} {48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.19.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 65535 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.20.1 { + db eval { + SELECT * FROM t1 WHERE r=4294967295 + } +} {4294967295 14 00000000ffffffff} +do_test boundary2-2.20.2 { + db eval { + SELECT r, a FROM t1 WHERE x='00000000ffffffff' + } +} {4294967295 14} +do_test boundary2-2.20.3 { + db eval { + SELECT r, x FROM t1 WHERE a=14 + } +} {4294967295 00000000ffffffff} +do_test boundary2-2.20.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 4294967295 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary2-2.20.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 4294967295 ORDER BY a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary2-2.20.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 4294967295 ORDER BY r + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.20.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 4294967295 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36} +do_test boundary2-2.20.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 4294967295 ORDER BY x + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.20.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967295 ORDER BY a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary2-2.20.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967295 ORDER BY a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary2-2.20.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967295 ORDER BY r + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.20.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967295 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14} +do_test boundary2-2.20.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967295 ORDER BY x + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.20.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 4294967295 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.20.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 4294967295 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.20.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 4294967295 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51} +do_test boundary2-2.20.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 4294967295 ORDER BY r DESC + } +} {51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.20.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 4294967295 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.20.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967295 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.20.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967295 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.20.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967295 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14} +do_test boundary2-2.20.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967295 ORDER BY r DESC + } +} {14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.20.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967295 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.21.1 { + db eval { + SELECT * FROM t1 WHERE r=1099511627775 + } +} {1099511627775 57 000000ffffffffff} +do_test boundary2-2.21.2 { + db eval { + SELECT r, a FROM t1 WHERE x='000000ffffffffff' + } +} {1099511627775 57} +do_test boundary2-2.21.3 { + db eval { + SELECT r, x FROM t1 WHERE a=57 + } +} {1099511627775 000000ffffffffff} +do_test boundary2-2.21.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627775 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56} +do_test boundary2-2.21.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627775 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-2.21.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627775 ORDER BY r + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.21.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627775 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19} +do_test boundary2-2.21.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627775 ORDER BY x + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.21.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627775 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56 57} +do_test boundary2-2.21.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627775 ORDER BY a DESC + } +} {57 56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-2.21.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627775 ORDER BY r + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.21.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627775 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57} +do_test boundary2-2.21.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627775 ORDER BY x + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.21.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627775 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.21.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627775 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.21.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627775 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35} +do_test boundary2-2.21.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627775 ORDER BY r DESC + } +} {35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.21.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627775 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.21.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627775 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary2-2.21.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627775 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.21.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627775 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57} +do_test boundary2-2.21.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627775 ORDER BY r DESC + } +} {57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.21.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627775 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.22.1 { + db eval { + SELECT * FROM t1 WHERE r=-8388608 + } +} {-8388608 37 ffffffffff800000} +do_test boundary2-2.22.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffffff800000' + } +} {-8388608 37} +do_test boundary2-2.22.3 { + db eval { + SELECT r, x FROM t1 WHERE a=37 + } +} {-8388608 ffffffffff800000} +do_test boundary2-2.22.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -8388608 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-2.22.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -8388608 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.22.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -8388608 ORDER BY r + } +} {29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.22.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -8388608 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29} +do_test boundary2-2.22.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -8388608 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 29 32 54 53 52 33 38} +do_test boundary2-2.22.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -8388608 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-2.22.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -8388608 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.22.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -8388608 ORDER BY r + } +} {37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.22.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -8388608 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37} +do_test boundary2-2.22.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -8388608 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 37 29 32 54 53 52 33 38} +do_test boundary2-2.22.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -8388608 ORDER BY a + } +} {1 2 11 21 44 47 55 58 63 64} +do_test boundary2-2.22.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -8388608 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 11 2 1} +do_test boundary2-2.22.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -8388608 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary2-2.22.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -8388608 ORDER BY r DESC + } +} {1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.22.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -8388608 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary2-2.22.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -8388608 ORDER BY a + } +} {1 2 11 21 37 44 47 55 58 63 64} +do_test boundary2-2.22.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -8388608 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 21 11 2 1} +do_test boundary2-2.22.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -8388608 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary2-2.22.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -8388608 ORDER BY r DESC + } +} {37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.22.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -8388608 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary2-2.23.1 { + db eval { + SELECT * FROM t1 WHERE r=549755813888 + } +} {549755813888 35 0000008000000000} +do_test boundary2-2.23.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000008000000000' + } +} {549755813888 35} +do_test boundary2-2.23.3 { + db eval { + SELECT r, x FROM t1 WHERE a=35 + } +} {549755813888 0000008000000000} +do_test boundary2-2.23.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 549755813888 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56 57} +do_test boundary2-2.23.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 549755813888 ORDER BY a DESC + } +} {57 56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-2.23.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 549755813888 ORDER BY r + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.23.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 549755813888 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57} +do_test boundary2-2.23.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 549755813888 ORDER BY x + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.23.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813888 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 56 57} +do_test boundary2-2.23.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813888 ORDER BY a DESC + } +} {57 56 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-2.23.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813888 ORDER BY r + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.23.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813888 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35} +do_test boundary2-2.23.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813888 ORDER BY x + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.23.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 549755813888 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.23.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 549755813888 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.23.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 549755813888 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46} +do_test boundary2-2.23.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 549755813888 ORDER BY r DESC + } +} {46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.23.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 549755813888 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.23.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813888 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.23.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813888 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.23.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813888 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35} +do_test boundary2-2.23.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813888 ORDER BY r DESC + } +} {35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.23.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813888 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.24.1 { + db eval { + SELECT * FROM t1 WHERE r=8388607 + } +} {8388607 18 00000000007fffff} +do_test boundary2-2.24.2 { + db eval { + SELECT r, a FROM t1 WHERE x='00000000007fffff' + } +} {8388607 18} +do_test boundary2-2.24.3 { + db eval { + SELECT r, x FROM t1 WHERE a=18 + } +} {8388607 00000000007fffff} +do_test boundary2-2.24.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 8388607 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-2.24.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 8388607 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary2-2.24.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 8388607 ORDER BY r + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.24.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 8388607 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24} +do_test boundary2-2.24.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 8388607 ORDER BY x + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.24.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 8388607 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-2.24.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 8388607 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary2-2.24.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 8388607 ORDER BY r + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.24.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 8388607 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18} +do_test boundary2-2.24.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 8388607 ORDER BY x + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.24.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 8388607 ORDER BY a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.24.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 8388607 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary2-2.24.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 8388607 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42} +do_test boundary2-2.24.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 8388607 ORDER BY r DESC + } +} {42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.24.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 8388607 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.24.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 8388607 ORDER BY a + } +} {1 2 4 5 8 11 15 16 18 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.24.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 8388607 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary2-2.24.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 8388607 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18} +do_test boundary2-2.24.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 8388607 ORDER BY r DESC + } +} {18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.24.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 8388607 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.25.1 { + db eval { + SELECT * FROM t1 WHERE r=-3 + } +} {-3 52 fffffffffffffffd} +do_test boundary2-2.25.2 { + db eval { + SELECT r, a FROM t1 WHERE x='fffffffffffffffd' + } +} {-3 52} +do_test boundary2-2.25.3 { + db eval { + SELECT r, x FROM t1 WHERE a=52 + } +} {-3 fffffffffffffffd} +do_test boundary2-2.25.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -3 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary2-2.25.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -3 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.25.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -3 ORDER BY r + } +} {33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.25.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -3 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33} +do_test boundary2-2.25.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -3 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 33 38} +do_test boundary2-2.25.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -3 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 56 57 59 60 61 62} +do_test boundary2-2.25.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -3 ORDER BY a DESC + } +} {62 61 60 59 57 56 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.25.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -3 ORDER BY r + } +} {52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.25.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -3 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52} +do_test boundary2-2.25.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -3 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 52 33 38} +do_test boundary2-2.25.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -3 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 53 54 55 58 63 64} +do_test boundary2-2.25.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -3 ORDER BY a DESC + } +} {64 63 58 55 54 53 47 44 37 32 29 21 11 2 1} +do_test boundary2-2.25.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -3 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary2-2.25.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -3 ORDER BY r DESC + } +} {53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.25.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -3 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary2-2.25.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -3 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 52 53 54 55 58 63 64} +do_test boundary2-2.25.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -3 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 37 32 29 21 11 2 1} +do_test boundary2-2.25.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -3 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary2-2.25.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -3 ORDER BY r DESC + } +} {52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.25.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -3 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary2-2.26.1 { + db eval { + SELECT * FROM t1 WHERE r=0 + } +} {0 59 0000000000000000} +do_test boundary2-2.26.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000000000' + } +} {0 59} +do_test boundary2-2.26.3 { + db eval { + SELECT r, x FROM t1 WHERE a=59 + } +} {0 0000000000000000} +do_test boundary2-2.26.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 0 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 60 61 62} +do_test boundary2-2.26.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 0 ORDER BY a DESC + } +} {62 61 60 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.26.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 0 ORDER BY r + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.26.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 0 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60} +do_test boundary2-2.26.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 0 ORDER BY x + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.26.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 0 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary2-2.26.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 0 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.26.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 0 ORDER BY r + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.26.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 0 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59} +do_test boundary2-2.26.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 0 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.26.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 0 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 63 64} +do_test boundary2-2.26.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 0 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary2-2.26.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 0 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.26.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 0 ORDER BY r DESC + } +} {38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.26.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 0 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.26.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 0 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 63 64} +do_test boundary2-2.26.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 0 ORDER BY a DESC + } +} {64 63 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary2-2.26.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 0 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59} +do_test boundary2-2.26.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 0 ORDER BY r DESC + } +} {59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.26.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 0 ORDER BY x + } +} {59 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.27.1 { + db eval { + SELECT * FROM t1 WHERE r=-1 + } +} {-1 38 ffffffffffffffff} +do_test boundary2-2.27.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffffffffffff' + } +} {-1 38} +do_test boundary2-2.27.3 { + db eval { + SELECT r, x FROM t1 WHERE a=38 + } +} {-1 ffffffffffffffff} +do_test boundary2-2.27.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -1 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary2-2.27.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -1 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.27.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -1 ORDER BY r + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.27.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -1 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59} +do_test boundary2-2.27.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -1 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.27.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -1 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary2-2.27.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -1 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.27.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -1 ORDER BY r + } +} {38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.27.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -1 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38} +do_test boundary2-2.27.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -1 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 38} +do_test boundary2-2.27.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -1 ORDER BY a + } +} {1 2 11 21 29 32 33 37 44 47 52 53 54 55 58 63 64} +do_test boundary2-2.27.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -1 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 37 33 32 29 21 11 2 1} +do_test boundary2-2.27.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -1 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary2-2.27.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -1 ORDER BY r DESC + } +} {33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.27.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -1 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary2-2.27.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -1 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 63 64} +do_test boundary2-2.27.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -1 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary2-2.27.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -1 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.27.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -1 ORDER BY r DESC + } +} {38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.27.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -1 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.28.1 { + db eval { + SELECT * FROM t1 WHERE r=-2 + } +} {-2 33 fffffffffffffffe} +do_test boundary2-2.28.2 { + db eval { + SELECT r, a FROM t1 WHERE x='fffffffffffffffe' + } +} {-2 33} +do_test boundary2-2.28.3 { + db eval { + SELECT r, x FROM t1 WHERE a=33 + } +} {-2 fffffffffffffffe} +do_test boundary2-2.28.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -2 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary2-2.28.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -2 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.28.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -2 ORDER BY r + } +} {38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.28.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -2 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38} +do_test boundary2-2.28.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -2 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 38} +do_test boundary2-2.28.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -2 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary2-2.28.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -2 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.28.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -2 ORDER BY r + } +} {33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.28.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -2 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33} +do_test boundary2-2.28.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -2 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 33 38} +do_test boundary2-2.28.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -2 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 52 53 54 55 58 63 64} +do_test boundary2-2.28.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -2 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 37 32 29 21 11 2 1} +do_test boundary2-2.28.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -2 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary2-2.28.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -2 ORDER BY r DESC + } +} {52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.28.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -2 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary2-2.28.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -2 ORDER BY a + } +} {1 2 11 21 29 32 33 37 44 47 52 53 54 55 58 63 64} +do_test boundary2-2.28.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -2 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 37 33 32 29 21 11 2 1} +do_test boundary2-2.28.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -2 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary2-2.28.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -2 ORDER BY r DESC + } +} {33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.28.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -2 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary2-2.29.1 { + db eval { + SELECT * FROM t1 WHERE r=2097152 + } +} {2097152 42 0000000000200000} +do_test boundary2-2.29.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000200000' + } +} {2097152 42} +do_test boundary2-2.29.3 { + db eval { + SELECT r, x FROM t1 WHERE a=42 + } +} {2097152 0000000000200000} +do_test boundary2-2.29.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 2097152 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-2.29.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 2097152 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary2-2.29.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 2097152 ORDER BY r + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.29.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 2097152 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18} +do_test boundary2-2.29.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 2097152 ORDER BY x + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.29.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 2097152 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary2-2.29.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 2097152 ORDER BY a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary2-2.29.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 2097152 ORDER BY r + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.29.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 2097152 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42} +do_test boundary2-2.29.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 2097152 ORDER BY x + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.29.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 2097152 ORDER BY a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.29.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 2097152 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary2-2.29.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 2097152 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15} +do_test boundary2-2.29.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 2097152 ORDER BY r DESC + } +} {15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.29.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 2097152 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.29.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 2097152 ORDER BY a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.29.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 2097152 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary2-2.29.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 2097152 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42} +do_test boundary2-2.29.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 2097152 ORDER BY r DESC + } +} {42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.29.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 2097152 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.30.1 { + db eval { + SELECT * FROM t1 WHERE r=128 + } +} {128 49 0000000000000080} +do_test boundary2-2.30.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000000080' + } +} {128 49} +do_test boundary2-2.30.3 { + db eval { + SELECT r, x FROM t1 WHERE a=49 + } +} {128 0000000000000080} +do_test boundary2-2.30.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 128 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary2-2.30.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 128 ORDER BY a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-2.30.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 128 ORDER BY r + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.30.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 128 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30} +do_test boundary2-2.30.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 128 ORDER BY x + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.30.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 128 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-2.30.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 128 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-2.30.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 128 ORDER BY r + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.30.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 128 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49} +do_test boundary2-2.30.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 128 ORDER BY x + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.30.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 128 ORDER BY a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-2.30.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 128 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary2-2.30.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 128 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4} +do_test boundary2-2.30.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 128 ORDER BY r DESC + } +} {4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.30.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 128 ORDER BY x + } +} {59 60 41 5 31 4 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.30.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 128 ORDER BY a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary2-2.30.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 128 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary2-2.30.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 128 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49} +do_test boundary2-2.30.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 128 ORDER BY r DESC + } +} {49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.30.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 128 ORDER BY x + } +} {59 60 41 5 31 4 49 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.31.1 { + db eval { + SELECT * FROM t1 WHERE r=255 + } +} {255 30 00000000000000ff} +do_test boundary2-2.31.2 { + db eval { + SELECT r, a FROM t1 WHERE x='00000000000000ff' + } +} {255 30} +do_test boundary2-2.31.3 { + db eval { + SELECT r, x FROM t1 WHERE a=30 + } +} {255 00000000000000ff} +do_test boundary2-2.31.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 255 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary2-2.31.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 255 ORDER BY a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-2.31.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 255 ORDER BY r + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.31.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 255 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61} +do_test boundary2-2.31.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 255 ORDER BY x + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.31.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 255 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary2-2.31.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 255 ORDER BY a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-2.31.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 255 ORDER BY r + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.31.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 255 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30} +do_test boundary2-2.31.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 255 ORDER BY x + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.31.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 255 ORDER BY a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary2-2.31.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 255 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary2-2.31.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 255 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49} +do_test boundary2-2.31.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 255 ORDER BY r DESC + } +} {49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.31.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 255 ORDER BY x + } +} {59 60 41 5 31 4 49 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.31.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 255 ORDER BY a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary2-2.31.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 255 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary2-2.31.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 255 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30} +do_test boundary2-2.31.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 255 ORDER BY r DESC + } +} {30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.31.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 255 ORDER BY x + } +} {59 60 41 5 31 4 49 30 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.32.1 { + db eval { + SELECT * FROM t1 WHERE r=-2147483648 + } +} {-2147483648 11 ffffffff80000000} +do_test boundary2-2.32.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffff80000000' + } +} {-2147483648 11} +do_test boundary2-2.32.3 { + db eval { + SELECT r, x FROM t1 WHERE a=11 + } +} {-2147483648 ffffffff80000000} +do_test boundary2-2.32.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -2147483648 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-2.32.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -2147483648 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.32.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -2147483648 ORDER BY r + } +} {1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.32.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -2147483648 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1} +do_test boundary2-2.32.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -2147483648 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.32.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483648 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-2.32.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483648 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.32.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483648 ORDER BY r + } +} {11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.32.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483648 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11} +do_test boundary2-2.32.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483648 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.32.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -2147483648 ORDER BY a + } +} {2 21 44 47 55 58 63 64} +do_test boundary2-2.32.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -2147483648 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 2} +do_test boundary2-2.32.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -2147483648 ORDER BY r + } +} {55 2 64 21 44 58 63 47} +do_test boundary2-2.32.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -2147483648 ORDER BY r DESC + } +} {47 63 58 44 21 64 2 55} +do_test boundary2-2.32.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -2147483648 ORDER BY x + } +} {55 2 64 21 44 58 63 47} +do_test boundary2-2.32.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483648 ORDER BY a + } +} {2 11 21 44 47 55 58 63 64} +do_test boundary2-2.32.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483648 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 11 2} +do_test boundary2-2.32.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483648 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary2-2.32.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483648 ORDER BY r DESC + } +} {11 47 63 58 44 21 64 2 55} +do_test boundary2-2.32.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483648 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary2-2.33.1 { + db eval { + SELECT * FROM t1 WHERE r=34359738367 + } +} {34359738367 39 00000007ffffffff} +do_test boundary2-2.33.2 { + db eval { + SELECT r, a FROM t1 WHERE x='00000007ffffffff' + } +} {34359738367 39} +do_test boundary2-2.33.3 { + db eval { + SELECT r, x FROM t1 WHERE a=39 + } +} {34359738367 00000007ffffffff} +do_test boundary2-2.33.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 34359738367 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary2-2.33.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 34359738367 ORDER BY a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary2-2.33.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 34359738367 ORDER BY r + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.33.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 34359738367 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22} +do_test boundary2-2.33.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 34359738367 ORDER BY x + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.33.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738367 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 39 43 45 46 56 57} +do_test boundary2-2.33.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738367 ORDER BY a DESC + } +} {57 56 46 45 43 39 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary2-2.33.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738367 ORDER BY r + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.33.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738367 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39} +do_test boundary2-2.33.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738367 ORDER BY x + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.33.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 34359738367 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.33.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 34359738367 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.33.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 34359738367 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36} +do_test boundary2-2.33.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 34359738367 ORDER BY r DESC + } +} {36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.33.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 34359738367 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.33.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738367 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.33.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738367 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.33.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738367 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39} +do_test boundary2-2.33.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738367 ORDER BY r DESC + } +} {39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.33.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738367 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.34.1 { + db eval { + SELECT * FROM t1 WHERE r=-549755813889 + } +} {-549755813889 58 ffffff7fffffffff} +do_test boundary2-2.34.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffff7fffffffff' + } +} {-549755813889 58} +do_test boundary2-2.34.3 { + db eval { + SELECT r, x FROM t1 WHERE a=58 + } +} {-549755813889 ffffff7fffffffff} +do_test boundary2-2.34.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -549755813889 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62 63} +do_test boundary2-2.34.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -549755813889 ORDER BY a DESC + } +} {63 62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.34.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -549755813889 ORDER BY r + } +} {63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.34.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -549755813889 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63} +do_test boundary2-2.34.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -549755813889 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.34.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813889 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary2-2.34.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813889 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.34.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813889 ORDER BY r + } +} {58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.34.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813889 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58} +do_test boundary2-2.34.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813889 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.34.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -549755813889 ORDER BY a + } +} {2 21 44 55 64} +do_test boundary2-2.34.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -549755813889 ORDER BY a DESC + } +} {64 55 44 21 2} +do_test boundary2-2.34.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -549755813889 ORDER BY r + } +} {55 2 64 21 44} +do_test boundary2-2.34.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -549755813889 ORDER BY r DESC + } +} {44 21 64 2 55} +do_test boundary2-2.34.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -549755813889 ORDER BY x + } +} {55 2 64 21 44} +do_test boundary2-2.34.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813889 ORDER BY a + } +} {2 21 44 55 58 64} +do_test boundary2-2.34.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813889 ORDER BY a DESC + } +} {64 58 55 44 21 2} +do_test boundary2-2.34.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813889 ORDER BY r + } +} {55 2 64 21 44 58} +do_test boundary2-2.34.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813889 ORDER BY r DESC + } +} {58 44 21 64 2 55} +do_test boundary2-2.34.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813889 ORDER BY x + } +} {55 2 64 21 44 58} +do_test boundary2-2.35.1 { + db eval { + SELECT * FROM t1 WHERE r=-32768 + } +} {-32768 32 ffffffffffff8000} +do_test boundary2-2.35.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffffffff8000' + } +} {-32768 32} +do_test boundary2-2.35.3 { + db eval { + SELECT r, x FROM t1 WHERE a=32 + } +} {-32768 ffffffffffff8000} +do_test boundary2-2.35.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -32768 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-2.35.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -32768 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.35.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -32768 ORDER BY r + } +} {54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.35.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -32768 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54} +do_test boundary2-2.35.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -32768 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 54 53 52 33 38} +do_test boundary2-2.35.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -32768 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-2.35.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -32768 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.35.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -32768 ORDER BY r + } +} {32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.35.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -32768 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32} +do_test boundary2-2.35.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -32768 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 32 54 53 52 33 38} +do_test boundary2-2.35.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -32768 ORDER BY a + } +} {1 2 11 21 29 37 44 47 55 58 63 64} +do_test boundary2-2.35.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -32768 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 29 21 11 2 1} +do_test boundary2-2.35.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -32768 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary2-2.35.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -32768 ORDER BY r DESC + } +} {29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.35.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -32768 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary2-2.35.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -32768 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 55 58 63 64} +do_test boundary2-2.35.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -32768 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 32 29 21 11 2 1} +do_test boundary2-2.35.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -32768 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary2-2.35.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -32768 ORDER BY r DESC + } +} {32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.35.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -32768 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary2-2.36.1 { + db eval { + SELECT * FROM t1 WHERE r=2147483647 + } +} {2147483647 20 000000007fffffff} +do_test boundary2-2.36.2 { + db eval { + SELECT r, a FROM t1 WHERE x='000000007fffffff' + } +} {2147483647 20} +do_test boundary2-2.36.3 { + db eval { + SELECT r, x FROM t1 WHERE a=20 + } +} {2147483647 000000007fffffff} +do_test boundary2-2.36.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 2147483647 ORDER BY a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary2-2.36.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 2147483647 ORDER BY a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary2-2.36.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 2147483647 ORDER BY r + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.36.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 2147483647 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51} +do_test boundary2-2.36.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 2147483647 ORDER BY x + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.36.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483647 ORDER BY a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary2-2.36.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483647 ORDER BY a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary2-2.36.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483647 ORDER BY r + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.36.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483647 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20} +do_test boundary2-2.36.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483647 ORDER BY x + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.36.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 2147483647 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.36.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 2147483647 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.36.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 2147483647 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40} +do_test boundary2-2.36.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 2147483647 ORDER BY r DESC + } +} {40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.36.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 2147483647 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.36.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483647 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.36.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483647 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.36.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483647 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20} +do_test boundary2-2.36.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483647 ORDER BY r DESC + } +} {20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.36.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483647 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.37.1 { + db eval { + SELECT * FROM t1 WHERE r=-129 + } +} {-129 54 ffffffffffffff7f} +do_test boundary2-2.37.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffffffffff7f' + } +} {-129 54} +do_test boundary2-2.37.3 { + db eval { + SELECT r, x FROM t1 WHERE a=54 + } +} {-129 ffffffffffffff7f} +do_test boundary2-2.37.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -129 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 56 57 59 60 61 62} +do_test boundary2-2.37.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -129 ORDER BY a DESC + } +} {62 61 60 59 57 56 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.37.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -129 ORDER BY r + } +} {53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.37.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -129 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53} +do_test boundary2-2.37.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -129 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 53 52 33 38} +do_test boundary2-2.37.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -129 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-2.37.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -129 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.37.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -129 ORDER BY r + } +} {54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.37.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -129 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54} +do_test boundary2-2.37.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -129 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 54 53 52 33 38} +do_test boundary2-2.37.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -129 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 55 58 63 64} +do_test boundary2-2.37.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -129 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 32 29 21 11 2 1} +do_test boundary2-2.37.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -129 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary2-2.37.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -129 ORDER BY r DESC + } +} {32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.37.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -129 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary2-2.37.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -129 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 54 55 58 63 64} +do_test boundary2-2.37.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -129 ORDER BY a DESC + } +} {64 63 58 55 54 47 44 37 32 29 21 11 2 1} +do_test boundary2-2.37.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -129 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary2-2.37.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -129 ORDER BY r DESC + } +} {54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.37.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -129 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary2-2.38.1 { + db eval { + SELECT * FROM t1 WHERE r=-128 + } +} {-128 53 ffffffffffffff80} +do_test boundary2-2.38.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffffffffff80' + } +} {-128 53} +do_test boundary2-2.38.3 { + db eval { + SELECT r, x FROM t1 WHERE a=53 + } +} {-128 ffffffffffffff80} +do_test boundary2-2.38.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -128 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 56 57 59 60 61 62} +do_test boundary2-2.38.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -128 ORDER BY a DESC + } +} {62 61 60 59 57 56 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.38.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -128 ORDER BY r + } +} {52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.38.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -128 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52} +do_test boundary2-2.38.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -128 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 52 33 38} +do_test boundary2-2.38.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -128 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 56 57 59 60 61 62} +do_test boundary2-2.38.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -128 ORDER BY a DESC + } +} {62 61 60 59 57 56 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.38.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -128 ORDER BY r + } +} {53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.38.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -128 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53} +do_test boundary2-2.38.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -128 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 53 52 33 38} +do_test boundary2-2.38.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -128 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 54 55 58 63 64} +do_test boundary2-2.38.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -128 ORDER BY a DESC + } +} {64 63 58 55 54 47 44 37 32 29 21 11 2 1} +do_test boundary2-2.38.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -128 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary2-2.38.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -128 ORDER BY r DESC + } +} {54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.38.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -128 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary2-2.38.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -128 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 53 54 55 58 63 64} +do_test boundary2-2.38.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -128 ORDER BY a DESC + } +} {64 63 58 55 54 53 47 44 37 32 29 21 11 2 1} +do_test boundary2-2.38.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -128 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary2-2.38.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -128 ORDER BY r DESC + } +} {53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.38.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -128 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary2-2.39.1 { + db eval { + SELECT * FROM t1 WHERE r=72057594037927936 + } +} {72057594037927936 28 0100000000000000} +do_test boundary2-2.39.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0100000000000000' + } +} {72057594037927936 28} +do_test boundary2-2.39.3 { + db eval { + SELECT r, x FROM t1 WHERE a=28 + } +} {72057594037927936 0100000000000000} +do_test boundary2-2.39.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927936 ORDER BY a + } +} {3} +do_test boundary2-2.39.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927936 ORDER BY a DESC + } +} {3} +do_test boundary2-2.39.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927936 ORDER BY r + } +} {3} +do_test boundary2-2.39.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927936 ORDER BY r DESC + } +} {3} +do_test boundary2-2.39.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927936 ORDER BY x + } +} {3} +do_test boundary2-2.39.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927936 ORDER BY a + } +} {3 28} +do_test boundary2-2.39.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927936 ORDER BY a DESC + } +} {28 3} +do_test boundary2-2.39.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927936 ORDER BY r + } +} {28 3} +do_test boundary2-2.39.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927936 ORDER BY r DESC + } +} {3 28} +do_test boundary2-2.39.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927936 ORDER BY x + } +} {28 3} +do_test boundary2-2.39.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927936 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.39.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927936 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.39.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927936 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17} +do_test boundary2-2.39.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927936 ORDER BY r DESC + } +} {17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.39.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927936 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.39.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927936 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.39.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927936 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.39.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927936 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28} +do_test boundary2-2.39.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927936 ORDER BY r DESC + } +} {28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.39.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927936 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.40.1 { + db eval { + SELECT * FROM t1 WHERE r=2147483648 + } +} {2147483648 51 0000000080000000} +do_test boundary2-2.40.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000080000000' + } +} {2147483648 51} +do_test boundary2-2.40.3 { + db eval { + SELECT r, x FROM t1 WHERE a=51 + } +} {2147483648 0000000080000000} +do_test boundary2-2.40.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 2147483648 ORDER BY a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary2-2.40.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 2147483648 ORDER BY a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary2-2.40.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 2147483648 ORDER BY r + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.40.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 2147483648 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14} +do_test boundary2-2.40.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 2147483648 ORDER BY x + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.40.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483648 ORDER BY a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary2-2.40.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483648 ORDER BY a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary2-2.40.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483648 ORDER BY r + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.40.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483648 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51} +do_test boundary2-2.40.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483648 ORDER BY x + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.40.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 2147483648 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.40.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 2147483648 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.40.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 2147483648 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20} +do_test boundary2-2.40.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 2147483648 ORDER BY r DESC + } +} {20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.40.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 2147483648 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.40.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483648 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.40.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483648 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.40.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483648 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51} +do_test boundary2-2.40.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483648 ORDER BY r DESC + } +} {51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.40.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483648 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.41.1 { + db eval { + SELECT * FROM t1 WHERE r=549755813887 + } +} {549755813887 46 0000007fffffffff} +do_test boundary2-2.41.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000007fffffffff' + } +} {549755813887 46} +do_test boundary2-2.41.3 { + db eval { + SELECT r, x FROM t1 WHERE a=46 + } +} {549755813887 0000007fffffffff} +do_test boundary2-2.41.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 549755813887 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 56 57} +do_test boundary2-2.41.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 549755813887 ORDER BY a DESC + } +} {57 56 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-2.41.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 549755813887 ORDER BY r + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.41.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 549755813887 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35} +do_test boundary2-2.41.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 549755813887 ORDER BY x + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.41.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813887 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary2-2.41.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813887 ORDER BY a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-2.41.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813887 ORDER BY r + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.41.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813887 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46} +do_test boundary2-2.41.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813887 ORDER BY x + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.41.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 549755813887 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.41.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 549755813887 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.41.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 549755813887 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22} +do_test boundary2-2.41.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 549755813887 ORDER BY r DESC + } +} {22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.41.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 549755813887 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.41.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813887 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.41.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813887 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.41.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813887 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46} +do_test boundary2-2.41.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813887 ORDER BY r DESC + } +} {46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.41.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813887 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.42.1 { + db eval { + SELECT * FROM t1 WHERE r=-549755813888 + } +} {-549755813888 63 ffffff8000000000} +do_test boundary2-2.42.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffff8000000000' + } +} {-549755813888 63} +do_test boundary2-2.42.3 { + db eval { + SELECT r, x FROM t1 WHERE a=63 + } +} {-549755813888 ffffff8000000000} +do_test boundary2-2.42.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -549755813888 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-2.42.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -549755813888 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.42.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -549755813888 ORDER BY r + } +} {47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.42.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -549755813888 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47} +do_test boundary2-2.42.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -549755813888 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.42.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813888 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62 63} +do_test boundary2-2.42.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813888 ORDER BY a DESC + } +} {63 62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.42.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813888 ORDER BY r + } +} {63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.42.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813888 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63} +do_test boundary2-2.42.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813888 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.42.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -549755813888 ORDER BY a + } +} {2 21 44 55 58 64} +do_test boundary2-2.42.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -549755813888 ORDER BY a DESC + } +} {64 58 55 44 21 2} +do_test boundary2-2.42.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -549755813888 ORDER BY r + } +} {55 2 64 21 44 58} +do_test boundary2-2.42.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -549755813888 ORDER BY r DESC + } +} {58 44 21 64 2 55} +do_test boundary2-2.42.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -549755813888 ORDER BY x + } +} {55 2 64 21 44 58} +do_test boundary2-2.42.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813888 ORDER BY a + } +} {2 21 44 55 58 63 64} +do_test boundary2-2.42.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813888 ORDER BY a DESC + } +} {64 63 58 55 44 21 2} +do_test boundary2-2.42.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813888 ORDER BY r + } +} {55 2 64 21 44 58 63} +do_test boundary2-2.42.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813888 ORDER BY r DESC + } +} {63 58 44 21 64 2 55} +do_test boundary2-2.42.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813888 ORDER BY x + } +} {55 2 64 21 44 58 63} +do_test boundary2-2.43.1 { + db eval { + SELECT * FROM t1 WHERE r=281474976710655 + } +} {281474976710655 10 0000ffffffffffff} +do_test boundary2-2.43.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000ffffffffffff' + } +} {281474976710655 10} +do_test boundary2-2.43.3 { + db eval { + SELECT r, x FROM t1 WHERE a=10 + } +} {281474976710655 0000ffffffffffff} +do_test boundary2-2.43.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710655 ORDER BY a + } +} {3 13 17 26 27 28 43 45} +do_test boundary2-2.43.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710655 ORDER BY a DESC + } +} {45 43 28 27 26 17 13 3} +do_test boundary2-2.43.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710655 ORDER BY r + } +} {26 13 43 27 45 17 28 3} +do_test boundary2-2.43.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710655 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26} +do_test boundary2-2.43.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710655 ORDER BY x + } +} {26 13 43 27 45 17 28 3} +do_test boundary2-2.43.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710655 ORDER BY a + } +} {3 10 13 17 26 27 28 43 45} +do_test boundary2-2.43.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710655 ORDER BY a DESC + } +} {45 43 28 27 26 17 13 10 3} +do_test boundary2-2.43.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710655 ORDER BY r + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary2-2.43.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710655 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10} +do_test boundary2-2.43.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710655 ORDER BY x + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary2-2.43.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710655 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.43.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710655 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-2.43.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710655 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34} +do_test boundary2-2.43.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710655 ORDER BY r DESC + } +} {34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.43.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710655 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.43.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710655 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.43.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710655 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.43.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710655 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10} +do_test boundary2-2.43.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710655 ORDER BY r DESC + } +} {10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.43.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710655 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.44.1 { + db eval { + SELECT * FROM t1 WHERE r=4398046511103 + } +} {4398046511103 7 000003ffffffffff} +do_test boundary2-2.44.2 { + db eval { + SELECT r, a FROM t1 WHERE x='000003ffffffffff' + } +} {4398046511103 7} +do_test boundary2-2.44.3 { + db eval { + SELECT r, x FROM t1 WHERE a=7 + } +} {4398046511103 000003ffffffffff} +do_test boundary2-2.44.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511103 ORDER BY a + } +} {3 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary2-2.44.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511103 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 3} +do_test boundary2-2.44.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511103 ORDER BY r + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.44.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511103 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56} +do_test boundary2-2.44.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511103 ORDER BY x + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.44.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511103 ORDER BY a + } +} {3 7 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary2-2.44.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511103 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 7 3} +do_test boundary2-2.44.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511103 ORDER BY r + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.44.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511103 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7} +do_test boundary2-2.44.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511103 ORDER BY x + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.44.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511103 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary2-2.44.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511103 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.44.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511103 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19} +do_test boundary2-2.44.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511103 ORDER BY r DESC + } +} {19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.44.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511103 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.44.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511103 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary2-2.44.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511103 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-2.44.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511103 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7} +do_test boundary2-2.44.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511103 ORDER BY r DESC + } +} {7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.44.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511103 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.45.1 { + db eval { + SELECT * FROM t1 WHERE r=268435455 + } +} {268435455 12 000000000fffffff} +do_test boundary2-2.45.2 { + db eval { + SELECT r, a FROM t1 WHERE x='000000000fffffff' + } +} {268435455 12} +do_test boundary2-2.45.3 { + db eval { + SELECT r, x FROM t1 WHERE a=12 + } +} {268435455 000000000fffffff} +do_test boundary2-2.45.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 268435455 ORDER BY a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-2.45.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 268435455 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary2-2.45.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 268435455 ORDER BY r + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.45.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 268435455 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40} +do_test boundary2-2.45.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 268435455 ORDER BY x + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.45.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 268435455 ORDER BY a + } +} {3 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-2.45.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 268435455 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 3} +do_test boundary2-2.45.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 268435455 ORDER BY r + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.45.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 268435455 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12} +do_test boundary2-2.45.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 268435455 ORDER BY x + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.45.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 268435455 ORDER BY a + } +} {1 2 4 5 6 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.45.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 268435455 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 6 5 4 2 1} +do_test boundary2-2.45.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 268435455 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6} +do_test boundary2-2.45.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 268435455 ORDER BY r DESC + } +} {6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.45.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 268435455 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.45.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 268435455 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.45.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 268435455 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.45.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 268435455 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12} +do_test boundary2-2.45.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 268435455 ORDER BY r DESC + } +} {12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.45.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 268435455 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.46.1 { + db eval { + SELECT * FROM t1 WHERE r=-9223372036854775808 + } +} {-9223372036854775808 55 8000000000000000} +do_test boundary2-2.46.2 { + db eval { + SELECT r, a FROM t1 WHERE x='8000000000000000' + } +} {-9223372036854775808 55} +do_test boundary2-2.46.3 { + db eval { + SELECT r, x FROM t1 WHERE a=55 + } +} {-9223372036854775808 8000000000000000} +do_test boundary2-2.46.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -9223372036854775808 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.46.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -9223372036854775808 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-2.46.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -9223372036854775808 ORDER BY r + } +} {2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.46.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -9223372036854775808 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2} +do_test boundary2-2.46.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -9223372036854775808 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.46.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -9223372036854775808 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.46.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -9223372036854775808 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-2.46.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -9223372036854775808 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.46.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -9223372036854775808 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.46.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -9223372036854775808 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.46.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -9223372036854775808 ORDER BY a + } +} {} +do_test boundary2-2.46.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -9223372036854775808 ORDER BY a DESC + } +} {} +do_test boundary2-2.46.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -9223372036854775808 ORDER BY r + } +} {} +do_test boundary2-2.46.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -9223372036854775808 ORDER BY r DESC + } +} {} +do_test boundary2-2.46.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -9223372036854775808 ORDER BY x + } +} {} +do_test boundary2-2.46.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -9223372036854775808 ORDER BY a + } +} {55} +do_test boundary2-2.46.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -9223372036854775808 ORDER BY a DESC + } +} {55} +do_test boundary2-2.46.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -9223372036854775808 ORDER BY r + } +} {55} +do_test boundary2-2.46.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -9223372036854775808 ORDER BY r DESC + } +} {55} +do_test boundary2-2.46.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -9223372036854775808 ORDER BY x + } +} {55} +do_test boundary2-2.47.1 { + db eval { + SELECT * FROM t1 WHERE r=562949953421312 + } +} {562949953421312 43 0002000000000000} +do_test boundary2-2.47.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0002000000000000' + } +} {562949953421312 43} +do_test boundary2-2.47.3 { + db eval { + SELECT r, x FROM t1 WHERE a=43 + } +} {562949953421312 0002000000000000} +do_test boundary2-2.47.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421312 ORDER BY a + } +} {3 17 27 28 45} +do_test boundary2-2.47.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421312 ORDER BY a DESC + } +} {45 28 27 17 3} +do_test boundary2-2.47.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421312 ORDER BY r + } +} {27 45 17 28 3} +do_test boundary2-2.47.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421312 ORDER BY r DESC + } +} {3 28 17 45 27} +do_test boundary2-2.47.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421312 ORDER BY x + } +} {27 45 17 28 3} +do_test boundary2-2.47.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421312 ORDER BY a + } +} {3 17 27 28 43 45} +do_test boundary2-2.47.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421312 ORDER BY a DESC + } +} {45 43 28 27 17 3} +do_test boundary2-2.47.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421312 ORDER BY r + } +} {43 27 45 17 28 3} +do_test boundary2-2.47.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421312 ORDER BY r DESC + } +} {3 28 17 45 27 43} +do_test boundary2-2.47.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421312 ORDER BY x + } +} {43 27 45 17 28 3} +do_test boundary2-2.47.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421312 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.47.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421312 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.47.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421312 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13} +do_test boundary2-2.47.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421312 ORDER BY r DESC + } +} {13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.47.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421312 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.47.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421312 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.47.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421312 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.47.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421312 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43} +do_test boundary2-2.47.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421312 ORDER BY r DESC + } +} {43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.47.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421312 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.48.1 { + db eval { + SELECT * FROM t1 WHERE r=-8388609 + } +} {-8388609 1 ffffffffff7fffff} +do_test boundary2-2.48.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffffff7fffff' + } +} {-8388609 1} +do_test boundary2-2.48.3 { + db eval { + SELECT r, x FROM t1 WHERE a=1 + } +} {-8388609 ffffffffff7fffff} +do_test boundary2-2.48.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -8388609 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-2.48.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -8388609 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.48.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -8388609 ORDER BY r + } +} {37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.48.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -8388609 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37} +do_test boundary2-2.48.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -8388609 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 37 29 32 54 53 52 33 38} +do_test boundary2-2.48.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -8388609 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-2.48.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -8388609 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.48.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -8388609 ORDER BY r + } +} {1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.48.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -8388609 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1} +do_test boundary2-2.48.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -8388609 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.48.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -8388609 ORDER BY a + } +} {2 11 21 44 47 55 58 63 64} +do_test boundary2-2.48.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -8388609 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 11 2} +do_test boundary2-2.48.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -8388609 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary2-2.48.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -8388609 ORDER BY r DESC + } +} {11 47 63 58 44 21 64 2 55} +do_test boundary2-2.48.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -8388609 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary2-2.48.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -8388609 ORDER BY a + } +} {1 2 11 21 44 47 55 58 63 64} +do_test boundary2-2.48.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -8388609 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 11 2 1} +do_test boundary2-2.48.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -8388609 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary2-2.48.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -8388609 ORDER BY r DESC + } +} {1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.48.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -8388609 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary2-2.49.1 { + db eval { + SELECT * FROM t1 WHERE r=16777215 + } +} {16777215 9 0000000000ffffff} +do_test boundary2-2.49.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000ffffff' + } +} {16777215 9} +do_test boundary2-2.49.3 { + db eval { + SELECT r, x FROM t1 WHERE a=9 + } +} {16777215 0000000000ffffff} +do_test boundary2-2.49.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 16777215 ORDER BY a + } +} {3 6 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-2.49.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 16777215 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 6 3} +do_test boundary2-2.49.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 16777215 ORDER BY r + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.49.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 16777215 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6} +do_test boundary2-2.49.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 16777215 ORDER BY x + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.49.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 16777215 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-2.49.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 16777215 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary2-2.49.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 16777215 ORDER BY r + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.49.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 16777215 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9} +do_test boundary2-2.49.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 16777215 ORDER BY x + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.49.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 16777215 ORDER BY a + } +} {1 2 4 5 8 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.49.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 16777215 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary2-2.49.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 16777215 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24} +do_test boundary2-2.49.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 16777215 ORDER BY r DESC + } +} {24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.49.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 16777215 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.49.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 16777215 ORDER BY a + } +} {1 2 4 5 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.49.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 16777215 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 5 4 2 1} +do_test boundary2-2.49.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 16777215 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9} +do_test boundary2-2.49.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 16777215 ORDER BY r DESC + } +} {9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.49.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 16777215 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.50.1 { + db eval { + SELECT * FROM t1 WHERE r=8388608 + } +} {8388608 24 0000000000800000} +do_test boundary2-2.50.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000800000' + } +} {8388608 24} +do_test boundary2-2.50.3 { + db eval { + SELECT r, x FROM t1 WHERE a=24 + } +} {8388608 0000000000800000} +do_test boundary2-2.50.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 8388608 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-2.50.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 8388608 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary2-2.50.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 8388608 ORDER BY r + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.50.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 8388608 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9} +do_test boundary2-2.50.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 8388608 ORDER BY x + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.50.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 8388608 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-2.50.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 8388608 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary2-2.50.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 8388608 ORDER BY r + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.50.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 8388608 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24} +do_test boundary2-2.50.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 8388608 ORDER BY x + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.50.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 8388608 ORDER BY a + } +} {1 2 4 5 8 11 15 16 18 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.50.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 8388608 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary2-2.50.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 8388608 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18} +do_test boundary2-2.50.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 8388608 ORDER BY r DESC + } +} {18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.50.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 8388608 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.50.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 8388608 ORDER BY a + } +} {1 2 4 5 8 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.50.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 8388608 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary2-2.50.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 8388608 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24} +do_test boundary2-2.50.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 8388608 ORDER BY r DESC + } +} {24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.50.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 8388608 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.51.1 { + db eval { + SELECT * FROM t1 WHERE r=16383 + } +} {16383 8 0000000000003fff} +do_test boundary2-2.51.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000003fff' + } +} {16383 8} +do_test boundary2-2.51.3 { + db eval { + SELECT r, x FROM t1 WHERE a=8 + } +} {16383 0000000000003fff} +do_test boundary2-2.51.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 16383 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-2.51.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 16383 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 7 6 3} +do_test boundary2-2.51.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 16383 ORDER BY r + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.51.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 16383 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16} +do_test boundary2-2.51.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 16383 ORDER BY x + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.51.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 16383 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-2.51.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 16383 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-2.51.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 16383 ORDER BY r + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.51.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 16383 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8} +do_test boundary2-2.51.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 16383 ORDER BY x + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.51.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 16383 ORDER BY a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-2.51.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 16383 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary2-2.51.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 16383 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61} +do_test boundary2-2.51.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 16383 ORDER BY r DESC + } +} {61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.51.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 16383 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.51.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 16383 ORDER BY a + } +} {1 2 4 5 8 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-2.51.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 16383 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 8 5 4 2 1} +do_test boundary2-2.51.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 16383 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8} +do_test boundary2-2.51.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 16383 ORDER BY r DESC + } +} {8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.51.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 16383 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.52.1 { + db eval { + SELECT * FROM t1 WHERE r=140737488355328 + } +} {140737488355328 34 0000800000000000} +do_test boundary2-2.52.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000800000000000' + } +} {140737488355328 34} +do_test boundary2-2.52.3 { + db eval { + SELECT r, x FROM t1 WHERE a=34 + } +} {140737488355328 0000800000000000} +do_test boundary2-2.52.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355328 ORDER BY a + } +} {3 10 13 17 26 27 28 43 45} +do_test boundary2-2.52.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355328 ORDER BY a DESC + } +} {45 43 28 27 26 17 13 10 3} +do_test boundary2-2.52.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355328 ORDER BY r + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary2-2.52.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355328 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10} +do_test boundary2-2.52.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355328 ORDER BY x + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary2-2.52.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355328 ORDER BY a + } +} {3 10 13 17 26 27 28 34 43 45} +do_test boundary2-2.52.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355328 ORDER BY a DESC + } +} {45 43 34 28 27 26 17 13 10 3} +do_test boundary2-2.52.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355328 ORDER BY r + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.52.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355328 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34} +do_test boundary2-2.52.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355328 ORDER BY x + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.52.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355328 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.52.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355328 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-2.52.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355328 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25} +do_test boundary2-2.52.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355328 ORDER BY r DESC + } +} {25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.52.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355328 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.52.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355328 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.52.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355328 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-2.52.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355328 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34} +do_test boundary2-2.52.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355328 ORDER BY r DESC + } +} {34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.52.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355328 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.53.1 { + db eval { + SELECT * FROM t1 WHERE r=2097151 + } +} {2097151 15 00000000001fffff} +do_test boundary2-2.53.2 { + db eval { + SELECT r, a FROM t1 WHERE x='00000000001fffff' + } +} {2097151 15} +do_test boundary2-2.53.3 { + db eval { + SELECT r, x FROM t1 WHERE a=15 + } +} {2097151 00000000001fffff} +do_test boundary2-2.53.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 2097151 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary2-2.53.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 2097151 ORDER BY a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary2-2.53.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 2097151 ORDER BY r + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.53.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 2097151 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42} +do_test boundary2-2.53.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 2097151 ORDER BY x + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.53.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 2097151 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary2-2.53.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 2097151 ORDER BY a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-2.53.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 2097151 ORDER BY r + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.53.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 2097151 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15} +do_test boundary2-2.53.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 2097151 ORDER BY x + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.53.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 2097151 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.53.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 2097151 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-2.53.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 2097151 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62} +do_test boundary2-2.53.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 2097151 ORDER BY r DESC + } +} {62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.53.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 2097151 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.53.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 2097151 ORDER BY a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.53.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 2097151 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary2-2.53.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 2097151 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15} +do_test boundary2-2.53.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 2097151 ORDER BY r DESC + } +} {15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.53.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 2097151 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.54.1 { + db eval { + SELECT * FROM t1 WHERE r=140737488355327 + } +} {140737488355327 25 00007fffffffffff} +do_test boundary2-2.54.2 { + db eval { + SELECT r, a FROM t1 WHERE x='00007fffffffffff' + } +} {140737488355327 25} +do_test boundary2-2.54.3 { + db eval { + SELECT r, x FROM t1 WHERE a=25 + } +} {140737488355327 00007fffffffffff} +do_test boundary2-2.54.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355327 ORDER BY a + } +} {3 10 13 17 26 27 28 34 43 45} +do_test boundary2-2.54.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355327 ORDER BY a DESC + } +} {45 43 34 28 27 26 17 13 10 3} +do_test boundary2-2.54.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355327 ORDER BY r + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.54.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355327 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34} +do_test boundary2-2.54.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355327 ORDER BY x + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.54.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355327 ORDER BY a + } +} {3 10 13 17 25 26 27 28 34 43 45} +do_test boundary2-2.54.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355327 ORDER BY a DESC + } +} {45 43 34 28 27 26 25 17 13 10 3} +do_test boundary2-2.54.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355327 ORDER BY r + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.54.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355327 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25} +do_test boundary2-2.54.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355327 ORDER BY x + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.54.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355327 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.54.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355327 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-2.54.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355327 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56} +do_test boundary2-2.54.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355327 ORDER BY r DESC + } +} {56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.54.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355327 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.54.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355327 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.54.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355327 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-2.54.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355327 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25} +do_test boundary2-2.54.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355327 ORDER BY r DESC + } +} {25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.54.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355327 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.55.1 { + db eval { + SELECT * FROM t1 WHERE r=281474976710656 + } +} {281474976710656 26 0001000000000000} +do_test boundary2-2.55.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0001000000000000' + } +} {281474976710656 26} +do_test boundary2-2.55.3 { + db eval { + SELECT r, x FROM t1 WHERE a=26 + } +} {281474976710656 0001000000000000} +do_test boundary2-2.55.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710656 ORDER BY a + } +} {3 13 17 27 28 43 45} +do_test boundary2-2.55.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710656 ORDER BY a DESC + } +} {45 43 28 27 17 13 3} +do_test boundary2-2.55.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710656 ORDER BY r + } +} {13 43 27 45 17 28 3} +do_test boundary2-2.55.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710656 ORDER BY r DESC + } +} {3 28 17 45 27 43 13} +do_test boundary2-2.55.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710656 ORDER BY x + } +} {13 43 27 45 17 28 3} +do_test boundary2-2.55.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710656 ORDER BY a + } +} {3 13 17 26 27 28 43 45} +do_test boundary2-2.55.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710656 ORDER BY a DESC + } +} {45 43 28 27 26 17 13 3} +do_test boundary2-2.55.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710656 ORDER BY r + } +} {26 13 43 27 45 17 28 3} +do_test boundary2-2.55.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710656 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26} +do_test boundary2-2.55.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710656 ORDER BY x + } +} {26 13 43 27 45 17 28 3} +do_test boundary2-2.55.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710656 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.55.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710656 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.55.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710656 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10} +do_test boundary2-2.55.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710656 ORDER BY r DESC + } +} {10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.55.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710656 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.55.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710656 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.55.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710656 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.55.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710656 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26} +do_test boundary2-2.55.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710656 ORDER BY r DESC + } +} {26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.55.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710656 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.56.1 { + db eval { + SELECT * FROM t1 WHERE r=32767 + } +} {32767 23 0000000000007fff} +do_test boundary2-2.56.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000007fff' + } +} {32767 23} +do_test boundary2-2.56.3 { + db eval { + SELECT r, x FROM t1 WHERE a=23 + } +} {32767 0000000000007fff} +do_test boundary2-2.56.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 32767 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-2.56.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 32767 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-2.56.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 32767 ORDER BY r + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.56.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 32767 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50} +do_test boundary2-2.56.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 32767 ORDER BY x + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.56.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 32767 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-2.56.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 32767 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-2.56.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 32767 ORDER BY r + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.56.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 32767 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23} +do_test boundary2-2.56.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 32767 ORDER BY x + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.56.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 32767 ORDER BY a + } +} {1 2 4 5 8 11 16 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-2.56.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 32767 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 16 11 8 5 4 2 1} +do_test boundary2-2.56.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 32767 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16} +do_test boundary2-2.56.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 32767 ORDER BY r DESC + } +} {16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.56.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 32767 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.56.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 32767 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-2.56.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 32767 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-2.56.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 32767 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23} +do_test boundary2-2.56.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 32767 ORDER BY r DESC + } +} {23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.56.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 32767 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.57.1 { + db eval { + SELECT * FROM t1 WHERE r=127 + } +} {127 4 000000000000007f} +do_test boundary2-2.57.2 { + db eval { + SELECT r, a FROM t1 WHERE x='000000000000007f' + } +} {127 4} +do_test boundary2-2.57.3 { + db eval { + SELECT r, x FROM t1 WHERE a=4 + } +} {127 000000000000007f} +do_test boundary2-2.57.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 127 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-2.57.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 127 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-2.57.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 127 ORDER BY r + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.57.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 127 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49} +do_test boundary2-2.57.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 127 ORDER BY x + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.57.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 127 ORDER BY a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-2.57.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 127 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary2-2.57.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 127 ORDER BY r + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.57.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 127 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4} +do_test boundary2-2.57.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 127 ORDER BY x + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.57.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 127 ORDER BY a + } +} {1 2 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-2.57.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 127 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 2 1} +do_test boundary2-2.57.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 127 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31} +do_test boundary2-2.57.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 127 ORDER BY r DESC + } +} {31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.57.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 127 ORDER BY x + } +} {59 60 41 5 31 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.57.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 127 ORDER BY a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-2.57.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 127 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary2-2.57.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 127 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4} +do_test boundary2-2.57.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 127 ORDER BY r DESC + } +} {4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.57.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 127 ORDER BY x + } +} {59 60 41 5 31 4 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.58.1 { + db eval { + SELECT * FROM t1 WHERE r=36028797018963967 + } +} {36028797018963967 27 007fffffffffffff} +do_test boundary2-2.58.2 { + db eval { + SELECT r, a FROM t1 WHERE x='007fffffffffffff' + } +} {36028797018963967 27} +do_test boundary2-2.58.3 { + db eval { + SELECT r, x FROM t1 WHERE a=27 + } +} {36028797018963967 007fffffffffffff} +do_test boundary2-2.58.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963967 ORDER BY a + } +} {3 17 28 45} +do_test boundary2-2.58.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963967 ORDER BY a DESC + } +} {45 28 17 3} +do_test boundary2-2.58.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963967 ORDER BY r + } +} {45 17 28 3} +do_test boundary2-2.58.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963967 ORDER BY r DESC + } +} {3 28 17 45} +do_test boundary2-2.58.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963967 ORDER BY x + } +} {45 17 28 3} +do_test boundary2-2.58.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963967 ORDER BY a + } +} {3 17 27 28 45} +do_test boundary2-2.58.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963967 ORDER BY a DESC + } +} {45 28 27 17 3} +do_test boundary2-2.58.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963967 ORDER BY r + } +} {27 45 17 28 3} +do_test boundary2-2.58.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963967 ORDER BY r DESC + } +} {3 28 17 45 27} +do_test boundary2-2.58.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963967 ORDER BY x + } +} {27 45 17 28 3} +do_test boundary2-2.58.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963967 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.58.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963967 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.58.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963967 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43} +do_test boundary2-2.58.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963967 ORDER BY r DESC + } +} {43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.58.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963967 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.58.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963967 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.58.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963967 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.58.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963967 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27} +do_test boundary2-2.58.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963967 ORDER BY r DESC + } +} {27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.58.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963967 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.59.1 { + db eval { + SELECT * FROM t1 WHERE r=4398046511104 + } +} {4398046511104 56 0000040000000000} +do_test boundary2-2.59.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000040000000000' + } +} {4398046511104 56} +do_test boundary2-2.59.3 { + db eval { + SELECT r, x FROM t1 WHERE a=56 + } +} {4398046511104 0000040000000000} +do_test boundary2-2.59.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511104 ORDER BY a + } +} {3 10 13 17 25 26 27 28 34 43 45} +do_test boundary2-2.59.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511104 ORDER BY a DESC + } +} {45 43 34 28 27 26 25 17 13 10 3} +do_test boundary2-2.59.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511104 ORDER BY r + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.59.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511104 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25} +do_test boundary2-2.59.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511104 ORDER BY x + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.59.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511104 ORDER BY a + } +} {3 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary2-2.59.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511104 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 3} +do_test boundary2-2.59.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511104 ORDER BY r + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.59.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511104 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56} +do_test boundary2-2.59.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511104 ORDER BY x + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.59.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511104 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary2-2.59.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511104 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-2.59.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511104 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7} +do_test boundary2-2.59.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511104 ORDER BY r DESC + } +} {7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.59.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511104 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.59.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511104 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.59.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511104 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-2.59.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511104 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56} +do_test boundary2-2.59.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511104 ORDER BY r DESC + } +} {56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.59.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511104 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.60.1 { + db eval { + SELECT * FROM t1 WHERE r=1 + } +} {1 60 0000000000000001} +do_test boundary2-2.60.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000000001' + } +} {1 60} +do_test boundary2-2.60.3 { + db eval { + SELECT r, x FROM t1 WHERE a=60 + } +} {1 0000000000000001} +do_test boundary2-2.60.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 1 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-2.60.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 1 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.60.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 1 ORDER BY r + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.60.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 1 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41} +do_test boundary2-2.60.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 1 ORDER BY x + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.60.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 1 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 60 61 62} +do_test boundary2-2.60.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 1 ORDER BY a DESC + } +} {62 61 60 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.60.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 1 ORDER BY r + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.60.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 1 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60} +do_test boundary2-2.60.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 1 ORDER BY x + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.60.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 1 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 63 64} +do_test boundary2-2.60.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 1 ORDER BY a DESC + } +} {64 63 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary2-2.60.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 1 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59} +do_test boundary2-2.60.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 1 ORDER BY r DESC + } +} {59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.60.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 1 ORDER BY x + } +} {59 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.60.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 1 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-2.60.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 1 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary2-2.60.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 1 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60} +do_test boundary2-2.60.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 1 ORDER BY r DESC + } +} {60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.60.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 1 ORDER BY x + } +} {59 60 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.61.1 { + db eval { + SELECT * FROM t1 WHERE r=36028797018963968 + } +} {36028797018963968 45 0080000000000000} +do_test boundary2-2.61.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0080000000000000' + } +} {36028797018963968 45} +do_test boundary2-2.61.3 { + db eval { + SELECT r, x FROM t1 WHERE a=45 + } +} {36028797018963968 0080000000000000} +do_test boundary2-2.61.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963968 ORDER BY a + } +} {3 17 28} +do_test boundary2-2.61.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963968 ORDER BY a DESC + } +} {28 17 3} +do_test boundary2-2.61.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963968 ORDER BY r + } +} {17 28 3} +do_test boundary2-2.61.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963968 ORDER BY r DESC + } +} {3 28 17} +do_test boundary2-2.61.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963968 ORDER BY x + } +} {17 28 3} +do_test boundary2-2.61.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963968 ORDER BY a + } +} {3 17 28 45} +do_test boundary2-2.61.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963968 ORDER BY a DESC + } +} {45 28 17 3} +do_test boundary2-2.61.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963968 ORDER BY r + } +} {45 17 28 3} +do_test boundary2-2.61.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963968 ORDER BY r DESC + } +} {3 28 17 45} +do_test boundary2-2.61.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963968 ORDER BY x + } +} {45 17 28 3} +do_test boundary2-2.61.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963968 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.61.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963968 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.61.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963968 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27} +do_test boundary2-2.61.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963968 ORDER BY r DESC + } +} {27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.61.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963968 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.61.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963968 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.61.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963968 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.61.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963968 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45} +do_test boundary2-2.61.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963968 ORDER BY r DESC + } +} {45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.61.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963968 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.62.1 { + db eval { + SELECT * FROM t1 WHERE r=-2147483649 + } +} {-2147483649 47 ffffffff7fffffff} +do_test boundary2-2.62.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffff7fffffff' + } +} {-2147483649 47} +do_test boundary2-2.62.3 { + db eval { + SELECT r, x FROM t1 WHERE a=47 + } +} {-2147483649 ffffffff7fffffff} +do_test boundary2-2.62.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -2147483649 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-2.62.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -2147483649 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.62.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -2147483649 ORDER BY r + } +} {11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.62.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -2147483649 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11} +do_test boundary2-2.62.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -2147483649 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.62.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483649 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-2.62.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483649 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.62.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483649 ORDER BY r + } +} {47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.62.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483649 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47} +do_test boundary2-2.62.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483649 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.62.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -2147483649 ORDER BY a + } +} {2 21 44 55 58 63 64} +do_test boundary2-2.62.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -2147483649 ORDER BY a DESC + } +} {64 63 58 55 44 21 2} +do_test boundary2-2.62.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -2147483649 ORDER BY r + } +} {55 2 64 21 44 58 63} +do_test boundary2-2.62.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -2147483649 ORDER BY r DESC + } +} {63 58 44 21 64 2 55} +do_test boundary2-2.62.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -2147483649 ORDER BY x + } +} {55 2 64 21 44 58 63} +do_test boundary2-2.62.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483649 ORDER BY a + } +} {2 21 44 47 55 58 63 64} +do_test boundary2-2.62.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483649 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 2} +do_test boundary2-2.62.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483649 ORDER BY r + } +} {55 2 64 21 44 58 63 47} +do_test boundary2-2.62.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483649 ORDER BY r DESC + } +} {47 63 58 44 21 64 2 55} +do_test boundary2-2.62.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483649 ORDER BY x + } +} {55 2 64 21 44 58 63 47} +do_test boundary2-2.63.1 { + db eval { + SELECT * FROM t1 WHERE r=-36028797018963969 + } +} {-36028797018963969 2 ff7fffffffffffff} +do_test boundary2-2.63.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ff7fffffffffffff' + } +} {-36028797018963969 2} +do_test boundary2-2.63.3 { + db eval { + SELECT r, x FROM t1 WHERE a=2 + } +} {-36028797018963969 ff7fffffffffffff} +do_test boundary2-2.63.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963969 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.63.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963969 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.63.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963969 ORDER BY r + } +} {64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.63.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963969 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64} +do_test boundary2-2.63.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963969 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.63.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963969 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.63.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963969 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-2.63.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963969 ORDER BY r + } +} {2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.63.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963969 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2} +do_test boundary2-2.63.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963969 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.63.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963969 ORDER BY a + } +} {55} +do_test boundary2-2.63.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963969 ORDER BY a DESC + } +} {55} +do_test boundary2-2.63.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963969 ORDER BY r + } +} {55} +do_test boundary2-2.63.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963969 ORDER BY r DESC + } +} {55} +do_test boundary2-2.63.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963969 ORDER BY x + } +} {55} +do_test boundary2-2.63.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963969 ORDER BY a + } +} {2 55} +do_test boundary2-2.63.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963969 ORDER BY a DESC + } +} {55 2} +do_test boundary2-2.63.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963969 ORDER BY r + } +} {55 2} +do_test boundary2-2.63.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963969 ORDER BY r DESC + } +} {2 55} +do_test boundary2-2.63.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963969 ORDER BY x + } +} {55 2} +do_test boundary2-2.64.1 { + db eval { + SELECT * FROM t1 WHERE r=3 + } +} {3 5 0000000000000003} +do_test boundary2-2.64.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000000003' + } +} {3 5} +do_test boundary2-2.64.3 { + db eval { + SELECT r, x FROM t1 WHERE a=5 + } +} {3 0000000000000003} +do_test boundary2-2.64.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 3 ORDER BY a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-2.64.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 3 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary2-2.64.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 3 ORDER BY r + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.64.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 3 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31} +do_test boundary2-2.64.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 3 ORDER BY x + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.64.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 3 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-2.64.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 3 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.64.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 3 ORDER BY r + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.64.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 3 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5} +do_test boundary2-2.64.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 3 ORDER BY x + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.64.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 3 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-2.64.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 3 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 2 1} +do_test boundary2-2.64.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 3 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41} +do_test boundary2-2.64.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 3 ORDER BY r DESC + } +} {41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.64.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 3 ORDER BY x + } +} {59 60 41 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.64.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 3 ORDER BY a + } +} {1 2 5 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-2.64.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 3 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 5 2 1} +do_test boundary2-2.64.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 3 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5} +do_test boundary2-2.64.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 3 ORDER BY r DESC + } +} {5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.64.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 3 ORDER BY x + } +} {59 60 41 5 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.65.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 9.22337303685477580800e+18 ORDER BY a + } +} {} +do_test boundary2-2.65.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 9.22337303685477580800e+18 ORDER BY a DESC + } +} {} +do_test boundary2-2.65.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 9.22337303685477580800e+18 ORDER BY r + } +} {} +do_test boundary2-2.65.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 9.22337303685477580800e+18 ORDER BY r DESC + } +} {} +do_test boundary2-2.65.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 9.22337303685477580800e+18 ORDER BY x + } +} {} +do_test boundary2-2.65.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 9.22337303685477580800e+18 ORDER BY a + } +} {} +do_test boundary2-2.65.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 9.22337303685477580800e+18 ORDER BY a DESC + } +} {} +do_test boundary2-2.65.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 9.22337303685477580800e+18 ORDER BY r + } +} {} +do_test boundary2-2.65.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 9.22337303685477580800e+18 ORDER BY r DESC + } +} {} +do_test boundary2-2.65.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 9.22337303685477580800e+18 ORDER BY x + } +} {} +do_test boundary2-2.65.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 9.22337303685477580800e+18 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.65.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 9.22337303685477580800e+18 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-2.65.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 9.22337303685477580800e+18 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.65.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 9.22337303685477580800e+18 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.65.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 9.22337303685477580800e+18 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.65.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 9.22337303685477580800e+18 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.65.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 9.22337303685477580800e+18 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-2.65.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 9.22337303685477580800e+18 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.65.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 9.22337303685477580800e+18 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.65.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 9.22337303685477580800e+18 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.66.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -9.22337303685477580800e+18 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.66.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -9.22337303685477580800e+18 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-2.66.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -9.22337303685477580800e+18 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.66.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -9.22337303685477580800e+18 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.66.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -9.22337303685477580800e+18 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.66.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -9.22337303685477580800e+18 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.66.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -9.22337303685477580800e+18 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-2.66.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -9.22337303685477580800e+18 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.66.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -9.22337303685477580800e+18 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.66.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -9.22337303685477580800e+18 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.66.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -9.22337303685477580800e+18 ORDER BY a + } +} {} +do_test boundary2-2.66.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -9.22337303685477580800e+18 ORDER BY a DESC + } +} {} +do_test boundary2-2.66.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -9.22337303685477580800e+18 ORDER BY r + } +} {} +do_test boundary2-2.66.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -9.22337303685477580800e+18 ORDER BY r DESC + } +} {} +do_test boundary2-2.66.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -9.22337303685477580800e+18 ORDER BY x + } +} {} +do_test boundary2-2.66.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -9.22337303685477580800e+18 ORDER BY a + } +} {} +do_test boundary2-2.66.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -9.22337303685477580800e+18 ORDER BY a DESC + } +} {} +do_test boundary2-2.66.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -9.22337303685477580800e+18 ORDER BY r + } +} {} +do_test boundary2-2.66.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -9.22337303685477580800e+18 ORDER BY r DESC + } +} {} +do_test boundary2-2.66.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -9.22337303685477580800e+18 ORDER BY x + } +} {} +do_test boundary2-3.1 { + db eval { + DROP INDEX t1i1; + DROP INDEX t1i2; + DROP INDEX t1i3; + } +} {} +do_test boundary2-4.1.1 { + db eval { + SELECT * FROM t1 WHERE r=72057594037927935 + } +} {72057594037927935 17 00ffffffffffffff} +do_test boundary2-4.1.2 { + db eval { + SELECT r, a FROM t1 WHERE x='00ffffffffffffff' + } +} {72057594037927935 17} +do_test boundary2-4.1.3 { + db eval { + SELECT r, x FROM t1 WHERE a=17 + } +} {72057594037927935 00ffffffffffffff} +do_test boundary2-4.1.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927935 ORDER BY a + } +} {3 28} +do_test boundary2-4.1.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927935 ORDER BY a DESC + } +} {28 3} +do_test boundary2-4.1.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927935 ORDER BY r + } +} {28 3} +do_test boundary2-4.1.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927935 ORDER BY r DESC + } +} {3 28} +do_test boundary2-4.1.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927935 ORDER BY x + } +} {28 3} +do_test boundary2-4.1.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927935 ORDER BY a + } +} {3 17 28} +do_test boundary2-4.1.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927935 ORDER BY a DESC + } +} {28 17 3} +do_test boundary2-4.1.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927935 ORDER BY r + } +} {17 28 3} +do_test boundary2-4.1.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927935 ORDER BY r DESC + } +} {3 28 17} +do_test boundary2-4.1.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927935 ORDER BY x + } +} {17 28 3} +do_test boundary2-4.1.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927935 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.1.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927935 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.1.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927935 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45} +do_test boundary2-4.1.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927935 ORDER BY r DESC + } +} {45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.1.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927935 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.1.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927935 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.1.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927935 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.1.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927935 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17} +do_test boundary2-4.1.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927935 ORDER BY r DESC + } +} {17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.1.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927935 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.2.1 { + db eval { + SELECT * FROM t1 WHERE r=16384 + } +} {16384 16 0000000000004000} +do_test boundary2-4.2.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000004000' + } +} {16384 16} +do_test boundary2-4.2.3 { + db eval { + SELECT r, x FROM t1 WHERE a=16 + } +} {16384 0000000000004000} +do_test boundary2-4.2.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 16384 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-4.2.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 16384 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-4.2.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 16384 ORDER BY r + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.2.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 16384 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23} +do_test boundary2-4.2.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 16384 ORDER BY x + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.2.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 16384 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-4.2.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 16384 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 7 6 3} +do_test boundary2-4.2.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 16384 ORDER BY r + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.2.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 16384 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16} +do_test boundary2-4.2.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 16384 ORDER BY x + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.2.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 16384 ORDER BY a + } +} {1 2 4 5 8 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-4.2.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 16384 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 8 5 4 2 1} +do_test boundary2-4.2.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 16384 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8} +do_test boundary2-4.2.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 16384 ORDER BY r DESC + } +} {8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.2.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 16384 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.2.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 16384 ORDER BY a + } +} {1 2 4 5 8 11 16 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-4.2.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 16384 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 16 11 8 5 4 2 1} +do_test boundary2-4.2.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 16384 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16} +do_test boundary2-4.2.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 16384 ORDER BY r DESC + } +} {16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.2.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 16384 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.3.1 { + db eval { + SELECT * FROM t1 WHERE r=4294967296 + } +} {4294967296 36 0000000100000000} +do_test boundary2-4.3.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000100000000' + } +} {4294967296 36} +do_test boundary2-4.3.3 { + db eval { + SELECT r, x FROM t1 WHERE a=36 + } +} {4294967296 0000000100000000} +do_test boundary2-4.3.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 4294967296 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 39 43 45 46 56 57} +do_test boundary2-4.3.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 4294967296 ORDER BY a DESC + } +} {57 56 46 45 43 39 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary2-4.3.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 4294967296 ORDER BY r + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.3.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 4294967296 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39} +do_test boundary2-4.3.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 4294967296 ORDER BY x + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.3.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967296 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary2-4.3.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967296 ORDER BY a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary2-4.3.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967296 ORDER BY r + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.3.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967296 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36} +do_test boundary2-4.3.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967296 ORDER BY x + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.3.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 4294967296 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.3.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 4294967296 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.3.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 4294967296 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14} +do_test boundary2-4.3.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 4294967296 ORDER BY r DESC + } +} {14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.3.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 4294967296 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.3.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967296 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.3.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967296 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.3.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967296 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36} +do_test boundary2-4.3.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967296 ORDER BY r DESC + } +} {36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.3.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967296 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.4.1 { + db eval { + SELECT * FROM t1 WHERE r=16777216 + } +} {16777216 6 0000000001000000} +do_test boundary2-4.4.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000001000000' + } +} {16777216 6} +do_test boundary2-4.4.3 { + db eval { + SELECT r, x FROM t1 WHERE a=6 + } +} {16777216 0000000001000000} +do_test boundary2-4.4.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 16777216 ORDER BY a + } +} {3 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-4.4.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 16777216 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 3} +do_test boundary2-4.4.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 16777216 ORDER BY r + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.4.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 16777216 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12} +do_test boundary2-4.4.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 16777216 ORDER BY x + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.4.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 16777216 ORDER BY a + } +} {3 6 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-4.4.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 16777216 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 6 3} +do_test boundary2-4.4.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 16777216 ORDER BY r + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.4.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 16777216 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6} +do_test boundary2-4.4.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 16777216 ORDER BY x + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.4.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 16777216 ORDER BY a + } +} {1 2 4 5 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.4.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 16777216 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 5 4 2 1} +do_test boundary2-4.4.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 16777216 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9} +do_test boundary2-4.4.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 16777216 ORDER BY r DESC + } +} {9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.4.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 16777216 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.4.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 16777216 ORDER BY a + } +} {1 2 4 5 6 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.4.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 16777216 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 6 5 4 2 1} +do_test boundary2-4.4.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 16777216 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6} +do_test boundary2-4.4.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 16777216 ORDER BY r DESC + } +} {6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.4.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 16777216 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.5.1 { + db eval { + SELECT * FROM t1 WHERE r=-32769 + } +} {-32769 29 ffffffffffff7fff} +do_test boundary2-4.5.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffffffff7fff' + } +} {-32769 29} +do_test boundary2-4.5.3 { + db eval { + SELECT r, x FROM t1 WHERE a=29 + } +} {-32769 ffffffffffff7fff} +do_test boundary2-4.5.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -32769 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-4.5.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -32769 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.5.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -32769 ORDER BY r + } +} {32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.5.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -32769 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32} +do_test boundary2-4.5.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -32769 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 32 54 53 52 33 38} +do_test boundary2-4.5.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -32769 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-4.5.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -32769 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.5.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -32769 ORDER BY r + } +} {29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.5.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -32769 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29} +do_test boundary2-4.5.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -32769 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 29 32 54 53 52 33 38} +do_test boundary2-4.5.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -32769 ORDER BY a + } +} {1 2 11 21 37 44 47 55 58 63 64} +do_test boundary2-4.5.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -32769 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 21 11 2 1} +do_test boundary2-4.5.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -32769 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary2-4.5.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -32769 ORDER BY r DESC + } +} {37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.5.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -32769 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary2-4.5.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -32769 ORDER BY a + } +} {1 2 11 21 29 37 44 47 55 58 63 64} +do_test boundary2-4.5.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -32769 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 29 21 11 2 1} +do_test boundary2-4.5.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -32769 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary2-4.5.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -32769 ORDER BY r DESC + } +} {29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.5.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -32769 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary2-4.6.1 { + db eval { + SELECT * FROM t1 WHERE r=-140737488355329 + } +} {-140737488355329 21 ffff7fffffffffff} +do_test boundary2-4.6.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffff7fffffffffff' + } +} {-140737488355329 21} +do_test boundary2-4.6.3 { + db eval { + SELECT r, x FROM t1 WHERE a=21 + } +} {-140737488355329 ffff7fffffffffff} +do_test boundary2-4.6.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355329 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary2-4.6.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355329 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.6.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355329 ORDER BY r + } +} {44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.6.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355329 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44} +do_test boundary2-4.6.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355329 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.6.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355329 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary2-4.6.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355329 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.6.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355329 ORDER BY r + } +} {21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.6.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355329 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21} +do_test boundary2-4.6.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355329 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.6.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355329 ORDER BY a + } +} {2 55 64} +do_test boundary2-4.6.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355329 ORDER BY a DESC + } +} {64 55 2} +do_test boundary2-4.6.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355329 ORDER BY r + } +} {55 2 64} +do_test boundary2-4.6.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355329 ORDER BY r DESC + } +} {64 2 55} +do_test boundary2-4.6.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355329 ORDER BY x + } +} {55 2 64} +do_test boundary2-4.6.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355329 ORDER BY a + } +} {2 21 55 64} +do_test boundary2-4.6.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355329 ORDER BY a DESC + } +} {64 55 21 2} +do_test boundary2-4.6.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355329 ORDER BY r + } +} {55 2 64 21} +do_test boundary2-4.6.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355329 ORDER BY r DESC + } +} {21 64 2 55} +do_test boundary2-4.6.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355329 ORDER BY x + } +} {55 2 64 21} +do_test boundary2-4.7.1 { + db eval { + SELECT * FROM t1 WHERE r=2 + } +} {2 41 0000000000000002} +do_test boundary2-4.7.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000000002' + } +} {2 41} +do_test boundary2-4.7.3 { + db eval { + SELECT r, x FROM t1 WHERE a=41 + } +} {2 0000000000000002} +do_test boundary2-4.7.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 2 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-4.7.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 2 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.7.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 2 ORDER BY r + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.7.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 2 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5} +do_test boundary2-4.7.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 2 ORDER BY x + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.7.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 2 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-4.7.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 2 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.7.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 2 ORDER BY r + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.7.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 2 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41} +do_test boundary2-4.7.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 2 ORDER BY x + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.7.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 2 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-4.7.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 2 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary2-4.7.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 2 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60} +do_test boundary2-4.7.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 2 ORDER BY r DESC + } +} {60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.7.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 2 ORDER BY x + } +} {59 60 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.7.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 2 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-4.7.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 2 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 2 1} +do_test boundary2-4.7.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 2 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41} +do_test boundary2-4.7.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 2 ORDER BY r DESC + } +} {41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.7.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 2 ORDER BY x + } +} {59 60 41 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.8.1 { + db eval { + SELECT * FROM t1 WHERE r=4 + } +} {4 31 0000000000000004} +do_test boundary2-4.8.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000000004' + } +} {4 31} +do_test boundary2-4.8.3 { + db eval { + SELECT r, x FROM t1 WHERE a=31 + } +} {4 0000000000000004} +do_test boundary2-4.8.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 4 ORDER BY a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-4.8.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 4 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary2-4.8.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 4 ORDER BY r + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.8.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 4 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4} +do_test boundary2-4.8.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 4 ORDER BY x + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.8.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 4 ORDER BY a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-4.8.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 4 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary2-4.8.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 4 ORDER BY r + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.8.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 4 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31} +do_test boundary2-4.8.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 4 ORDER BY x + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.8.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 4 ORDER BY a + } +} {1 2 5 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-4.8.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 4 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 5 2 1} +do_test boundary2-4.8.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 4 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5} +do_test boundary2-4.8.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 4 ORDER BY r DESC + } +} {5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.8.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 4 ORDER BY x + } +} {59 60 41 5 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.8.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 4 ORDER BY a + } +} {1 2 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-4.8.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 4 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 2 1} +do_test boundary2-4.8.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 4 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31} +do_test boundary2-4.8.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 4 ORDER BY r DESC + } +} {31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.8.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 4 ORDER BY x + } +} {59 60 41 5 31 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.9.1 { + db eval { + SELECT * FROM t1 WHERE r=562949953421311 + } +} {562949953421311 13 0001ffffffffffff} +do_test boundary2-4.9.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0001ffffffffffff' + } +} {562949953421311 13} +do_test boundary2-4.9.3 { + db eval { + SELECT r, x FROM t1 WHERE a=13 + } +} {562949953421311 0001ffffffffffff} +do_test boundary2-4.9.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421311 ORDER BY a + } +} {3 17 27 28 43 45} +do_test boundary2-4.9.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421311 ORDER BY a DESC + } +} {45 43 28 27 17 3} +do_test boundary2-4.9.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421311 ORDER BY r + } +} {43 27 45 17 28 3} +do_test boundary2-4.9.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421311 ORDER BY r DESC + } +} {3 28 17 45 27 43} +do_test boundary2-4.9.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421311 ORDER BY x + } +} {43 27 45 17 28 3} +do_test boundary2-4.9.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421311 ORDER BY a + } +} {3 13 17 27 28 43 45} +do_test boundary2-4.9.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421311 ORDER BY a DESC + } +} {45 43 28 27 17 13 3} +do_test boundary2-4.9.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421311 ORDER BY r + } +} {13 43 27 45 17 28 3} +do_test boundary2-4.9.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421311 ORDER BY r DESC + } +} {3 28 17 45 27 43 13} +do_test boundary2-4.9.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421311 ORDER BY x + } +} {13 43 27 45 17 28 3} +do_test boundary2-4.9.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421311 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.9.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421311 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.9.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421311 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26} +do_test boundary2-4.9.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421311 ORDER BY r DESC + } +} {26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.9.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421311 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.9.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421311 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.9.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421311 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.9.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421311 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13} +do_test boundary2-4.9.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421311 ORDER BY r DESC + } +} {13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.9.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421311 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.10.1 { + db eval { + SELECT * FROM t1 WHERE r=256 + } +} {256 61 0000000000000100} +do_test boundary2-4.10.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000000100' + } +} {256 61} +do_test boundary2-4.10.3 { + db eval { + SELECT r, x FROM t1 WHERE a=61 + } +} {256 0000000000000100} +do_test boundary2-4.10.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 256 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-4.10.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 256 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-4.10.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 256 ORDER BY r + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.10.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 256 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8} +do_test boundary2-4.10.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 256 ORDER BY x + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.10.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 256 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary2-4.10.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 256 ORDER BY a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-4.10.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 256 ORDER BY r + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.10.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 256 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61} +do_test boundary2-4.10.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 256 ORDER BY x + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.10.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 256 ORDER BY a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary2-4.10.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 256 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary2-4.10.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 256 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30} +do_test boundary2-4.10.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 256 ORDER BY r DESC + } +} {30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.10.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 256 ORDER BY x + } +} {59 60 41 5 31 4 49 30 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.10.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 256 ORDER BY a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-4.10.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 256 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary2-4.10.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 256 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61} +do_test boundary2-4.10.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 256 ORDER BY r DESC + } +} {61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.10.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 256 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.11.1 { + db eval { + SELECT * FROM t1 WHERE r=34359738368 + } +} {34359738368 22 0000000800000000} +do_test boundary2-4.11.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000800000000' + } +} {34359738368 22} +do_test boundary2-4.11.3 { + db eval { + SELECT r, x FROM t1 WHERE a=22 + } +} {34359738368 0000000800000000} +do_test boundary2-4.11.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 34359738368 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary2-4.11.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 34359738368 ORDER BY a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-4.11.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 34359738368 ORDER BY r + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.11.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 34359738368 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46} +do_test boundary2-4.11.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 34359738368 ORDER BY x + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.11.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738368 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary2-4.11.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738368 ORDER BY a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary2-4.11.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738368 ORDER BY r + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.11.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738368 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22} +do_test boundary2-4.11.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738368 ORDER BY x + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.11.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 34359738368 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.11.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 34359738368 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.11.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 34359738368 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39} +do_test boundary2-4.11.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 34359738368 ORDER BY r DESC + } +} {39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.11.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 34359738368 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.11.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738368 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.11.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738368 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.11.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738368 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22} +do_test boundary2-4.11.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738368 ORDER BY r DESC + } +} {22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.11.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738368 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.12.1 { + db eval { + SELECT * FROM t1 WHERE r=65536 + } +} {65536 62 0000000000010000} +do_test boundary2-4.12.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000010000' + } +} {65536 62} +do_test boundary2-4.12.3 { + db eval { + SELECT r, x FROM t1 WHERE a=62 + } +} {65536 0000000000010000} +do_test boundary2-4.12.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 65536 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary2-4.12.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 65536 ORDER BY a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-4.12.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 65536 ORDER BY r + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.12.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 65536 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15} +do_test boundary2-4.12.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 65536 ORDER BY x + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.12.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 65536 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57 62} +do_test boundary2-4.12.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 65536 ORDER BY a DESC + } +} {62 57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-4.12.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 65536 ORDER BY r + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.12.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 65536 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62} +do_test boundary2-4.12.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 65536 ORDER BY x + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.12.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 65536 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-4.12.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 65536 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-4.12.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 65536 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48} +do_test boundary2-4.12.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 65536 ORDER BY r DESC + } +} {48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.12.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 65536 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.12.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 65536 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.12.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 65536 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-4.12.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 65536 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62} +do_test boundary2-4.12.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 65536 ORDER BY r DESC + } +} {62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.12.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 65536 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.13.1 { + db eval { + SELECT * FROM t1 WHERE r=268435456 + } +} {268435456 40 0000000010000000} +do_test boundary2-4.13.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000010000000' + } +} {268435456 40} +do_test boundary2-4.13.3 { + db eval { + SELECT r, x FROM t1 WHERE a=40 + } +} {268435456 0000000010000000} +do_test boundary2-4.13.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 268435456 ORDER BY a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary2-4.13.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 268435456 ORDER BY a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary2-4.13.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 268435456 ORDER BY r + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.13.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 268435456 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20} +do_test boundary2-4.13.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 268435456 ORDER BY x + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.13.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 268435456 ORDER BY a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-4.13.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 268435456 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary2-4.13.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 268435456 ORDER BY r + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.13.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 268435456 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40} +do_test boundary2-4.13.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 268435456 ORDER BY x + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.13.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 268435456 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.13.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 268435456 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.13.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 268435456 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12} +do_test boundary2-4.13.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 268435456 ORDER BY r DESC + } +} {12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.13.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 268435456 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.13.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 268435456 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.13.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 268435456 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.13.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 268435456 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40} +do_test boundary2-4.13.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 268435456 ORDER BY r DESC + } +} {40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.13.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 268435456 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.14.1 { + db eval { + SELECT * FROM t1 WHERE r=-140737488355328 + } +} {-140737488355328 44 ffff800000000000} +do_test boundary2-4.14.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffff800000000000' + } +} {-140737488355328 44} +do_test boundary2-4.14.3 { + db eval { + SELECT r, x FROM t1 WHERE a=44 + } +} {-140737488355328 ffff800000000000} +do_test boundary2-4.14.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355328 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary2-4.14.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355328 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.14.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355328 ORDER BY r + } +} {58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.14.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355328 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58} +do_test boundary2-4.14.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355328 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.14.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355328 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary2-4.14.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355328 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.14.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355328 ORDER BY r + } +} {44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.14.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355328 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44} +do_test boundary2-4.14.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355328 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.14.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355328 ORDER BY a + } +} {2 21 55 64} +do_test boundary2-4.14.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355328 ORDER BY a DESC + } +} {64 55 21 2} +do_test boundary2-4.14.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355328 ORDER BY r + } +} {55 2 64 21} +do_test boundary2-4.14.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355328 ORDER BY r DESC + } +} {21 64 2 55} +do_test boundary2-4.14.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355328 ORDER BY x + } +} {55 2 64 21} +do_test boundary2-4.14.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355328 ORDER BY a + } +} {2 21 44 55 64} +do_test boundary2-4.14.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355328 ORDER BY a DESC + } +} {64 55 44 21 2} +do_test boundary2-4.14.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355328 ORDER BY r + } +} {55 2 64 21 44} +do_test boundary2-4.14.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355328 ORDER BY r DESC + } +} {44 21 64 2 55} +do_test boundary2-4.14.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355328 ORDER BY x + } +} {55 2 64 21 44} +do_test boundary2-4.15.1 { + db eval { + SELECT * FROM t1 WHERE r=1099511627776 + } +} {1099511627776 19 0000010000000000} +do_test boundary2-4.15.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000010000000000' + } +} {1099511627776 19} +do_test boundary2-4.15.3 { + db eval { + SELECT r, x FROM t1 WHERE a=19 + } +} {1099511627776 0000010000000000} +do_test boundary2-4.15.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627776 ORDER BY a + } +} {3 7 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary2-4.15.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627776 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 7 3} +do_test boundary2-4.15.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627776 ORDER BY r + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.15.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627776 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7} +do_test boundary2-4.15.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627776 ORDER BY x + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.15.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627776 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56} +do_test boundary2-4.15.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627776 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-4.15.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627776 ORDER BY r + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.15.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627776 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19} +do_test boundary2-4.15.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627776 ORDER BY x + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.15.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627776 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary2-4.15.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627776 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.15.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627776 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57} +do_test boundary2-4.15.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627776 ORDER BY r DESC + } +} {57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.15.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627776 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.15.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627776 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary2-4.15.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627776 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.15.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627776 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19} +do_test boundary2-4.15.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627776 ORDER BY r DESC + } +} {19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.15.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627776 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.16.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 9223372036854775807 ORDER BY a + } +} {} +do_test boundary2-4.16.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 9223372036854775807 ORDER BY a DESC + } +} {} +do_test boundary2-4.16.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 9223372036854775807 ORDER BY r + } +} {} +do_test boundary2-4.16.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 9223372036854775807 ORDER BY r DESC + } +} {} +do_test boundary2-4.16.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 9223372036854775807 ORDER BY x + } +} {} +do_test boundary2-4.16.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 9223372036854775807 ORDER BY a + } +} {3} +do_test boundary2-4.16.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 9223372036854775807 ORDER BY a DESC + } +} {3} +do_test boundary2-4.16.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 9223372036854775807 ORDER BY r + } +} {3} +do_test boundary2-4.16.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 9223372036854775807 ORDER BY r DESC + } +} {3} +do_test boundary2-4.16.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 9223372036854775807 ORDER BY x + } +} {3} +do_test boundary2-4.16.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 9223372036854775807 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.16.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 9223372036854775807 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.16.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 9223372036854775807 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28} +do_test boundary2-4.16.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 9223372036854775807 ORDER BY r DESC + } +} {28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.16.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 9223372036854775807 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.16.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 9223372036854775807 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.16.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 9223372036854775807 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-4.16.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 9223372036854775807 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.16.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 9223372036854775807 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.16.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 9223372036854775807 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.17.1 { + db eval { + SELECT * FROM t1 WHERE r=32768 + } +} {32768 50 0000000000008000} +do_test boundary2-4.17.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000008000' + } +} {32768 50} +do_test boundary2-4.17.3 { + db eval { + SELECT r, x FROM t1 WHERE a=50 + } +} {32768 0000000000008000} +do_test boundary2-4.17.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 32768 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 51 56 57 62} +do_test boundary2-4.17.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 32768 ORDER BY a DESC + } +} {62 57 56 51 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-4.17.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 32768 ORDER BY r + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.17.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 32768 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48} +do_test boundary2-4.17.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 32768 ORDER BY x + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.17.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 32768 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-4.17.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 32768 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-4.17.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 32768 ORDER BY r + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.17.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 32768 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50} +do_test boundary2-4.17.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 32768 ORDER BY x + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.17.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 32768 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-4.17.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 32768 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-4.17.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 32768 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23} +do_test boundary2-4.17.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 32768 ORDER BY r DESC + } +} {23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.17.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 32768 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.17.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 32768 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-4.17.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 32768 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-4.17.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 32768 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50} +do_test boundary2-4.17.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 32768 ORDER BY r DESC + } +} {50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.17.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 32768 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.18.1 { + db eval { + SELECT * FROM t1 WHERE r=-36028797018963968 + } +} {-36028797018963968 64 ff80000000000000} +do_test boundary2-4.18.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ff80000000000000' + } +} {-36028797018963968 64} +do_test boundary2-4.18.3 { + db eval { + SELECT r, x FROM t1 WHERE a=64 + } +} {-36028797018963968 ff80000000000000} +do_test boundary2-4.18.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963968 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary2-4.18.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963968 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.18.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963968 ORDER BY r + } +} {21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.18.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963968 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21} +do_test boundary2-4.18.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963968 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.18.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963968 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.18.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963968 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.18.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963968 ORDER BY r + } +} {64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.18.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963968 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64} +do_test boundary2-4.18.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963968 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.18.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963968 ORDER BY a + } +} {2 55} +do_test boundary2-4.18.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963968 ORDER BY a DESC + } +} {55 2} +do_test boundary2-4.18.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963968 ORDER BY r + } +} {55 2} +do_test boundary2-4.18.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963968 ORDER BY r DESC + } +} {2 55} +do_test boundary2-4.18.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963968 ORDER BY x + } +} {55 2} +do_test boundary2-4.18.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963968 ORDER BY a + } +} {2 55 64} +do_test boundary2-4.18.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963968 ORDER BY a DESC + } +} {64 55 2} +do_test boundary2-4.18.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963968 ORDER BY r + } +} {55 2 64} +do_test boundary2-4.18.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963968 ORDER BY r DESC + } +} {64 2 55} +do_test boundary2-4.18.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963968 ORDER BY x + } +} {55 2 64} +do_test boundary2-4.19.1 { + db eval { + SELECT * FROM t1 WHERE r=65535 + } +} {65535 48 000000000000ffff} +do_test boundary2-4.19.2 { + db eval { + SELECT r, a FROM t1 WHERE x='000000000000ffff' + } +} {65535 48} +do_test boundary2-4.19.3 { + db eval { + SELECT r, x FROM t1 WHERE a=48 + } +} {65535 000000000000ffff} +do_test boundary2-4.19.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 65535 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57 62} +do_test boundary2-4.19.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 65535 ORDER BY a DESC + } +} {62 57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-4.19.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 65535 ORDER BY r + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.19.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 65535 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62} +do_test boundary2-4.19.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 65535 ORDER BY x + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.19.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 65535 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 51 56 57 62} +do_test boundary2-4.19.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 65535 ORDER BY a DESC + } +} {62 57 56 51 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-4.19.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 65535 ORDER BY r + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.19.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 65535 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48} +do_test boundary2-4.19.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 65535 ORDER BY x + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.19.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 65535 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-4.19.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 65535 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-4.19.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 65535 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50} +do_test boundary2-4.19.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 65535 ORDER BY r DESC + } +} {50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.19.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 65535 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.19.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 65535 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-4.19.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 65535 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-4.19.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 65535 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48} +do_test boundary2-4.19.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 65535 ORDER BY r DESC + } +} {48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.19.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 65535 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.20.1 { + db eval { + SELECT * FROM t1 WHERE r=4294967295 + } +} {4294967295 14 00000000ffffffff} +do_test boundary2-4.20.2 { + db eval { + SELECT r, a FROM t1 WHERE x='00000000ffffffff' + } +} {4294967295 14} +do_test boundary2-4.20.3 { + db eval { + SELECT r, x FROM t1 WHERE a=14 + } +} {4294967295 00000000ffffffff} +do_test boundary2-4.20.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 4294967295 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary2-4.20.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 4294967295 ORDER BY a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary2-4.20.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 4294967295 ORDER BY r + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.20.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 4294967295 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36} +do_test boundary2-4.20.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 4294967295 ORDER BY x + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.20.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967295 ORDER BY a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary2-4.20.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967295 ORDER BY a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary2-4.20.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967295 ORDER BY r + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.20.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967295 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14} +do_test boundary2-4.20.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967295 ORDER BY x + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.20.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 4294967295 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.20.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 4294967295 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.20.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 4294967295 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51} +do_test boundary2-4.20.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 4294967295 ORDER BY r DESC + } +} {51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.20.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 4294967295 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.20.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967295 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.20.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967295 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.20.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967295 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14} +do_test boundary2-4.20.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967295 ORDER BY r DESC + } +} {14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.20.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967295 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.21.1 { + db eval { + SELECT * FROM t1 WHERE r=1099511627775 + } +} {1099511627775 57 000000ffffffffff} +do_test boundary2-4.21.2 { + db eval { + SELECT r, a FROM t1 WHERE x='000000ffffffffff' + } +} {1099511627775 57} +do_test boundary2-4.21.3 { + db eval { + SELECT r, x FROM t1 WHERE a=57 + } +} {1099511627775 000000ffffffffff} +do_test boundary2-4.21.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627775 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56} +do_test boundary2-4.21.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627775 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-4.21.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627775 ORDER BY r + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.21.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627775 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19} +do_test boundary2-4.21.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627775 ORDER BY x + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.21.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627775 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56 57} +do_test boundary2-4.21.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627775 ORDER BY a DESC + } +} {57 56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-4.21.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627775 ORDER BY r + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.21.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627775 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57} +do_test boundary2-4.21.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627775 ORDER BY x + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.21.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627775 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.21.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627775 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.21.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627775 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35} +do_test boundary2-4.21.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627775 ORDER BY r DESC + } +} {35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.21.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627775 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.21.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627775 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary2-4.21.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627775 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.21.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627775 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57} +do_test boundary2-4.21.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627775 ORDER BY r DESC + } +} {57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.21.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627775 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.22.1 { + db eval { + SELECT * FROM t1 WHERE r=-8388608 + } +} {-8388608 37 ffffffffff800000} +do_test boundary2-4.22.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffffff800000' + } +} {-8388608 37} +do_test boundary2-4.22.3 { + db eval { + SELECT r, x FROM t1 WHERE a=37 + } +} {-8388608 ffffffffff800000} +do_test boundary2-4.22.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -8388608 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-4.22.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -8388608 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.22.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -8388608 ORDER BY r + } +} {29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.22.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -8388608 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29} +do_test boundary2-4.22.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -8388608 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 29 32 54 53 52 33 38} +do_test boundary2-4.22.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -8388608 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-4.22.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -8388608 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.22.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -8388608 ORDER BY r + } +} {37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.22.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -8388608 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37} +do_test boundary2-4.22.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -8388608 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 37 29 32 54 53 52 33 38} +do_test boundary2-4.22.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -8388608 ORDER BY a + } +} {1 2 11 21 44 47 55 58 63 64} +do_test boundary2-4.22.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -8388608 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 11 2 1} +do_test boundary2-4.22.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -8388608 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary2-4.22.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -8388608 ORDER BY r DESC + } +} {1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.22.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -8388608 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary2-4.22.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -8388608 ORDER BY a + } +} {1 2 11 21 37 44 47 55 58 63 64} +do_test boundary2-4.22.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -8388608 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 21 11 2 1} +do_test boundary2-4.22.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -8388608 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary2-4.22.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -8388608 ORDER BY r DESC + } +} {37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.22.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -8388608 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary2-4.23.1 { + db eval { + SELECT * FROM t1 WHERE r=549755813888 + } +} {549755813888 35 0000008000000000} +do_test boundary2-4.23.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000008000000000' + } +} {549755813888 35} +do_test boundary2-4.23.3 { + db eval { + SELECT r, x FROM t1 WHERE a=35 + } +} {549755813888 0000008000000000} +do_test boundary2-4.23.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 549755813888 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56 57} +do_test boundary2-4.23.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 549755813888 ORDER BY a DESC + } +} {57 56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-4.23.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 549755813888 ORDER BY r + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.23.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 549755813888 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57} +do_test boundary2-4.23.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 549755813888 ORDER BY x + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.23.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813888 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 56 57} +do_test boundary2-4.23.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813888 ORDER BY a DESC + } +} {57 56 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-4.23.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813888 ORDER BY r + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.23.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813888 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35} +do_test boundary2-4.23.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813888 ORDER BY x + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.23.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 549755813888 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.23.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 549755813888 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.23.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 549755813888 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46} +do_test boundary2-4.23.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 549755813888 ORDER BY r DESC + } +} {46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.23.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 549755813888 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.23.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813888 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.23.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813888 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.23.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813888 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35} +do_test boundary2-4.23.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813888 ORDER BY r DESC + } +} {35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.23.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813888 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.24.1 { + db eval { + SELECT * FROM t1 WHERE r=8388607 + } +} {8388607 18 00000000007fffff} +do_test boundary2-4.24.2 { + db eval { + SELECT r, a FROM t1 WHERE x='00000000007fffff' + } +} {8388607 18} +do_test boundary2-4.24.3 { + db eval { + SELECT r, x FROM t1 WHERE a=18 + } +} {8388607 00000000007fffff} +do_test boundary2-4.24.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 8388607 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-4.24.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 8388607 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary2-4.24.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 8388607 ORDER BY r + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.24.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 8388607 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24} +do_test boundary2-4.24.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 8388607 ORDER BY x + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.24.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 8388607 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-4.24.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 8388607 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary2-4.24.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 8388607 ORDER BY r + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.24.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 8388607 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18} +do_test boundary2-4.24.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 8388607 ORDER BY x + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.24.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 8388607 ORDER BY a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.24.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 8388607 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary2-4.24.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 8388607 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42} +do_test boundary2-4.24.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 8388607 ORDER BY r DESC + } +} {42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.24.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 8388607 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.24.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 8388607 ORDER BY a + } +} {1 2 4 5 8 11 15 16 18 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.24.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 8388607 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary2-4.24.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 8388607 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18} +do_test boundary2-4.24.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 8388607 ORDER BY r DESC + } +} {18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.24.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 8388607 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.25.1 { + db eval { + SELECT * FROM t1 WHERE r=-3 + } +} {-3 52 fffffffffffffffd} +do_test boundary2-4.25.2 { + db eval { + SELECT r, a FROM t1 WHERE x='fffffffffffffffd' + } +} {-3 52} +do_test boundary2-4.25.3 { + db eval { + SELECT r, x FROM t1 WHERE a=52 + } +} {-3 fffffffffffffffd} +do_test boundary2-4.25.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -3 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary2-4.25.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -3 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.25.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -3 ORDER BY r + } +} {33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.25.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -3 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33} +do_test boundary2-4.25.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -3 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 33 38} +do_test boundary2-4.25.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -3 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 56 57 59 60 61 62} +do_test boundary2-4.25.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -3 ORDER BY a DESC + } +} {62 61 60 59 57 56 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.25.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -3 ORDER BY r + } +} {52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.25.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -3 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52} +do_test boundary2-4.25.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -3 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 52 33 38} +do_test boundary2-4.25.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -3 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 53 54 55 58 63 64} +do_test boundary2-4.25.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -3 ORDER BY a DESC + } +} {64 63 58 55 54 53 47 44 37 32 29 21 11 2 1} +do_test boundary2-4.25.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -3 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary2-4.25.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -3 ORDER BY r DESC + } +} {53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.25.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -3 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary2-4.25.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -3 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 52 53 54 55 58 63 64} +do_test boundary2-4.25.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -3 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 37 32 29 21 11 2 1} +do_test boundary2-4.25.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -3 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary2-4.25.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -3 ORDER BY r DESC + } +} {52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.25.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -3 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary2-4.26.1 { + db eval { + SELECT * FROM t1 WHERE r=0 + } +} {0 59 0000000000000000} +do_test boundary2-4.26.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000000000' + } +} {0 59} +do_test boundary2-4.26.3 { + db eval { + SELECT r, x FROM t1 WHERE a=59 + } +} {0 0000000000000000} +do_test boundary2-4.26.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 0 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 60 61 62} +do_test boundary2-4.26.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 0 ORDER BY a DESC + } +} {62 61 60 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.26.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 0 ORDER BY r + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.26.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 0 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60} +do_test boundary2-4.26.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 0 ORDER BY x + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.26.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 0 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary2-4.26.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 0 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.26.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 0 ORDER BY r + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.26.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 0 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59} +do_test boundary2-4.26.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 0 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.26.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 0 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 63 64} +do_test boundary2-4.26.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 0 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary2-4.26.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 0 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.26.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 0 ORDER BY r DESC + } +} {38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.26.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 0 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.26.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 0 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 63 64} +do_test boundary2-4.26.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 0 ORDER BY a DESC + } +} {64 63 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary2-4.26.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 0 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59} +do_test boundary2-4.26.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 0 ORDER BY r DESC + } +} {59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.26.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 0 ORDER BY x + } +} {59 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.27.1 { + db eval { + SELECT * FROM t1 WHERE r=-1 + } +} {-1 38 ffffffffffffffff} +do_test boundary2-4.27.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffffffffffff' + } +} {-1 38} +do_test boundary2-4.27.3 { + db eval { + SELECT r, x FROM t1 WHERE a=38 + } +} {-1 ffffffffffffffff} +do_test boundary2-4.27.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -1 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary2-4.27.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -1 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.27.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -1 ORDER BY r + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.27.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -1 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59} +do_test boundary2-4.27.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -1 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.27.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -1 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary2-4.27.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -1 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.27.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -1 ORDER BY r + } +} {38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.27.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -1 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38} +do_test boundary2-4.27.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -1 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 38} +do_test boundary2-4.27.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -1 ORDER BY a + } +} {1 2 11 21 29 32 33 37 44 47 52 53 54 55 58 63 64} +do_test boundary2-4.27.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -1 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 37 33 32 29 21 11 2 1} +do_test boundary2-4.27.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -1 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary2-4.27.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -1 ORDER BY r DESC + } +} {33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.27.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -1 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary2-4.27.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -1 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 63 64} +do_test boundary2-4.27.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -1 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary2-4.27.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -1 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.27.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -1 ORDER BY r DESC + } +} {38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.27.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -1 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.28.1 { + db eval { + SELECT * FROM t1 WHERE r=-2 + } +} {-2 33 fffffffffffffffe} +do_test boundary2-4.28.2 { + db eval { + SELECT r, a FROM t1 WHERE x='fffffffffffffffe' + } +} {-2 33} +do_test boundary2-4.28.3 { + db eval { + SELECT r, x FROM t1 WHERE a=33 + } +} {-2 fffffffffffffffe} +do_test boundary2-4.28.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -2 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary2-4.28.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -2 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.28.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -2 ORDER BY r + } +} {38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.28.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -2 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38} +do_test boundary2-4.28.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -2 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 38} +do_test boundary2-4.28.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -2 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary2-4.28.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -2 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.28.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -2 ORDER BY r + } +} {33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.28.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -2 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33} +do_test boundary2-4.28.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -2 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 33 38} +do_test boundary2-4.28.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -2 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 52 53 54 55 58 63 64} +do_test boundary2-4.28.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -2 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 37 32 29 21 11 2 1} +do_test boundary2-4.28.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -2 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary2-4.28.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -2 ORDER BY r DESC + } +} {52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.28.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -2 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary2-4.28.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -2 ORDER BY a + } +} {1 2 11 21 29 32 33 37 44 47 52 53 54 55 58 63 64} +do_test boundary2-4.28.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -2 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 37 33 32 29 21 11 2 1} +do_test boundary2-4.28.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -2 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary2-4.28.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -2 ORDER BY r DESC + } +} {33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.28.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -2 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary2-4.29.1 { + db eval { + SELECT * FROM t1 WHERE r=2097152 + } +} {2097152 42 0000000000200000} +do_test boundary2-4.29.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000200000' + } +} {2097152 42} +do_test boundary2-4.29.3 { + db eval { + SELECT r, x FROM t1 WHERE a=42 + } +} {2097152 0000000000200000} +do_test boundary2-4.29.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 2097152 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-4.29.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 2097152 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary2-4.29.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 2097152 ORDER BY r + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.29.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 2097152 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18} +do_test boundary2-4.29.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 2097152 ORDER BY x + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.29.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 2097152 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary2-4.29.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 2097152 ORDER BY a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary2-4.29.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 2097152 ORDER BY r + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.29.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 2097152 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42} +do_test boundary2-4.29.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 2097152 ORDER BY x + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.29.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 2097152 ORDER BY a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.29.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 2097152 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary2-4.29.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 2097152 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15} +do_test boundary2-4.29.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 2097152 ORDER BY r DESC + } +} {15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.29.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 2097152 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.29.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 2097152 ORDER BY a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.29.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 2097152 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary2-4.29.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 2097152 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42} +do_test boundary2-4.29.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 2097152 ORDER BY r DESC + } +} {42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.29.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 2097152 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.30.1 { + db eval { + SELECT * FROM t1 WHERE r=128 + } +} {128 49 0000000000000080} +do_test boundary2-4.30.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000000080' + } +} {128 49} +do_test boundary2-4.30.3 { + db eval { + SELECT r, x FROM t1 WHERE a=49 + } +} {128 0000000000000080} +do_test boundary2-4.30.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 128 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary2-4.30.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 128 ORDER BY a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-4.30.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 128 ORDER BY r + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.30.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 128 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30} +do_test boundary2-4.30.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 128 ORDER BY x + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.30.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 128 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-4.30.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 128 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-4.30.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 128 ORDER BY r + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.30.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 128 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49} +do_test boundary2-4.30.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 128 ORDER BY x + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.30.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 128 ORDER BY a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-4.30.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 128 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary2-4.30.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 128 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4} +do_test boundary2-4.30.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 128 ORDER BY r DESC + } +} {4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.30.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 128 ORDER BY x + } +} {59 60 41 5 31 4 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.30.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 128 ORDER BY a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary2-4.30.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 128 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary2-4.30.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 128 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49} +do_test boundary2-4.30.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 128 ORDER BY r DESC + } +} {49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.30.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 128 ORDER BY x + } +} {59 60 41 5 31 4 49 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.31.1 { + db eval { + SELECT * FROM t1 WHERE r=255 + } +} {255 30 00000000000000ff} +do_test boundary2-4.31.2 { + db eval { + SELECT r, a FROM t1 WHERE x='00000000000000ff' + } +} {255 30} +do_test boundary2-4.31.3 { + db eval { + SELECT r, x FROM t1 WHERE a=30 + } +} {255 00000000000000ff} +do_test boundary2-4.31.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 255 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary2-4.31.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 255 ORDER BY a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-4.31.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 255 ORDER BY r + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.31.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 255 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61} +do_test boundary2-4.31.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 255 ORDER BY x + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.31.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 255 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary2-4.31.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 255 ORDER BY a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-4.31.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 255 ORDER BY r + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.31.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 255 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30} +do_test boundary2-4.31.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 255 ORDER BY x + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.31.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 255 ORDER BY a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary2-4.31.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 255 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary2-4.31.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 255 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49} +do_test boundary2-4.31.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 255 ORDER BY r DESC + } +} {49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.31.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 255 ORDER BY x + } +} {59 60 41 5 31 4 49 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.31.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 255 ORDER BY a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary2-4.31.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 255 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary2-4.31.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 255 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30} +do_test boundary2-4.31.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 255 ORDER BY r DESC + } +} {30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.31.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 255 ORDER BY x + } +} {59 60 41 5 31 4 49 30 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.32.1 { + db eval { + SELECT * FROM t1 WHERE r=-2147483648 + } +} {-2147483648 11 ffffffff80000000} +do_test boundary2-4.32.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffff80000000' + } +} {-2147483648 11} +do_test boundary2-4.32.3 { + db eval { + SELECT r, x FROM t1 WHERE a=11 + } +} {-2147483648 ffffffff80000000} +do_test boundary2-4.32.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -2147483648 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-4.32.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -2147483648 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.32.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -2147483648 ORDER BY r + } +} {1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.32.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -2147483648 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1} +do_test boundary2-4.32.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -2147483648 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.32.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483648 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-4.32.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483648 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.32.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483648 ORDER BY r + } +} {11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.32.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483648 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11} +do_test boundary2-4.32.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483648 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.32.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -2147483648 ORDER BY a + } +} {2 21 44 47 55 58 63 64} +do_test boundary2-4.32.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -2147483648 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 2} +do_test boundary2-4.32.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -2147483648 ORDER BY r + } +} {55 2 64 21 44 58 63 47} +do_test boundary2-4.32.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -2147483648 ORDER BY r DESC + } +} {47 63 58 44 21 64 2 55} +do_test boundary2-4.32.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -2147483648 ORDER BY x + } +} {55 2 64 21 44 58 63 47} +do_test boundary2-4.32.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483648 ORDER BY a + } +} {2 11 21 44 47 55 58 63 64} +do_test boundary2-4.32.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483648 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 11 2} +do_test boundary2-4.32.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483648 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary2-4.32.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483648 ORDER BY r DESC + } +} {11 47 63 58 44 21 64 2 55} +do_test boundary2-4.32.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483648 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary2-4.33.1 { + db eval { + SELECT * FROM t1 WHERE r=34359738367 + } +} {34359738367 39 00000007ffffffff} +do_test boundary2-4.33.2 { + db eval { + SELECT r, a FROM t1 WHERE x='00000007ffffffff' + } +} {34359738367 39} +do_test boundary2-4.33.3 { + db eval { + SELECT r, x FROM t1 WHERE a=39 + } +} {34359738367 00000007ffffffff} +do_test boundary2-4.33.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 34359738367 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary2-4.33.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 34359738367 ORDER BY a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary2-4.33.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 34359738367 ORDER BY r + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.33.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 34359738367 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22} +do_test boundary2-4.33.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 34359738367 ORDER BY x + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.33.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738367 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 39 43 45 46 56 57} +do_test boundary2-4.33.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738367 ORDER BY a DESC + } +} {57 56 46 45 43 39 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary2-4.33.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738367 ORDER BY r + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.33.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738367 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39} +do_test boundary2-4.33.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738367 ORDER BY x + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.33.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 34359738367 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.33.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 34359738367 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.33.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 34359738367 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36} +do_test boundary2-4.33.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 34359738367 ORDER BY r DESC + } +} {36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.33.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 34359738367 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.33.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738367 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.33.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738367 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.33.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738367 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39} +do_test boundary2-4.33.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738367 ORDER BY r DESC + } +} {39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.33.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738367 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.34.1 { + db eval { + SELECT * FROM t1 WHERE r=-549755813889 + } +} {-549755813889 58 ffffff7fffffffff} +do_test boundary2-4.34.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffff7fffffffff' + } +} {-549755813889 58} +do_test boundary2-4.34.3 { + db eval { + SELECT r, x FROM t1 WHERE a=58 + } +} {-549755813889 ffffff7fffffffff} +do_test boundary2-4.34.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -549755813889 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62 63} +do_test boundary2-4.34.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -549755813889 ORDER BY a DESC + } +} {63 62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.34.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -549755813889 ORDER BY r + } +} {63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.34.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -549755813889 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63} +do_test boundary2-4.34.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -549755813889 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.34.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813889 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary2-4.34.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813889 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.34.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813889 ORDER BY r + } +} {58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.34.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813889 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58} +do_test boundary2-4.34.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813889 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.34.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -549755813889 ORDER BY a + } +} {2 21 44 55 64} +do_test boundary2-4.34.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -549755813889 ORDER BY a DESC + } +} {64 55 44 21 2} +do_test boundary2-4.34.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -549755813889 ORDER BY r + } +} {55 2 64 21 44} +do_test boundary2-4.34.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -549755813889 ORDER BY r DESC + } +} {44 21 64 2 55} +do_test boundary2-4.34.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -549755813889 ORDER BY x + } +} {55 2 64 21 44} +do_test boundary2-4.34.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813889 ORDER BY a + } +} {2 21 44 55 58 64} +do_test boundary2-4.34.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813889 ORDER BY a DESC + } +} {64 58 55 44 21 2} +do_test boundary2-4.34.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813889 ORDER BY r + } +} {55 2 64 21 44 58} +do_test boundary2-4.34.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813889 ORDER BY r DESC + } +} {58 44 21 64 2 55} +do_test boundary2-4.34.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813889 ORDER BY x + } +} {55 2 64 21 44 58} +do_test boundary2-4.35.1 { + db eval { + SELECT * FROM t1 WHERE r=-32768 + } +} {-32768 32 ffffffffffff8000} +do_test boundary2-4.35.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffffffff8000' + } +} {-32768 32} +do_test boundary2-4.35.3 { + db eval { + SELECT r, x FROM t1 WHERE a=32 + } +} {-32768 ffffffffffff8000} +do_test boundary2-4.35.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -32768 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-4.35.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -32768 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.35.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -32768 ORDER BY r + } +} {54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.35.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -32768 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54} +do_test boundary2-4.35.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -32768 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 54 53 52 33 38} +do_test boundary2-4.35.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -32768 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-4.35.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -32768 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.35.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -32768 ORDER BY r + } +} {32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.35.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -32768 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32} +do_test boundary2-4.35.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -32768 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 32 54 53 52 33 38} +do_test boundary2-4.35.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -32768 ORDER BY a + } +} {1 2 11 21 29 37 44 47 55 58 63 64} +do_test boundary2-4.35.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -32768 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 29 21 11 2 1} +do_test boundary2-4.35.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -32768 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary2-4.35.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -32768 ORDER BY r DESC + } +} {29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.35.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -32768 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary2-4.35.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -32768 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 55 58 63 64} +do_test boundary2-4.35.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -32768 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 32 29 21 11 2 1} +do_test boundary2-4.35.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -32768 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary2-4.35.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -32768 ORDER BY r DESC + } +} {32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.35.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -32768 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary2-4.36.1 { + db eval { + SELECT * FROM t1 WHERE r=2147483647 + } +} {2147483647 20 000000007fffffff} +do_test boundary2-4.36.2 { + db eval { + SELECT r, a FROM t1 WHERE x='000000007fffffff' + } +} {2147483647 20} +do_test boundary2-4.36.3 { + db eval { + SELECT r, x FROM t1 WHERE a=20 + } +} {2147483647 000000007fffffff} +do_test boundary2-4.36.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 2147483647 ORDER BY a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary2-4.36.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 2147483647 ORDER BY a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary2-4.36.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 2147483647 ORDER BY r + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.36.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 2147483647 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51} +do_test boundary2-4.36.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 2147483647 ORDER BY x + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.36.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483647 ORDER BY a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary2-4.36.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483647 ORDER BY a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary2-4.36.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483647 ORDER BY r + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.36.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483647 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20} +do_test boundary2-4.36.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483647 ORDER BY x + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.36.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 2147483647 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.36.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 2147483647 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.36.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 2147483647 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40} +do_test boundary2-4.36.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 2147483647 ORDER BY r DESC + } +} {40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.36.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 2147483647 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.36.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483647 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.36.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483647 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.36.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483647 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20} +do_test boundary2-4.36.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483647 ORDER BY r DESC + } +} {20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.36.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483647 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.37.1 { + db eval { + SELECT * FROM t1 WHERE r=-129 + } +} {-129 54 ffffffffffffff7f} +do_test boundary2-4.37.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffffffffff7f' + } +} {-129 54} +do_test boundary2-4.37.3 { + db eval { + SELECT r, x FROM t1 WHERE a=54 + } +} {-129 ffffffffffffff7f} +do_test boundary2-4.37.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -129 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 56 57 59 60 61 62} +do_test boundary2-4.37.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -129 ORDER BY a DESC + } +} {62 61 60 59 57 56 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.37.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -129 ORDER BY r + } +} {53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.37.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -129 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53} +do_test boundary2-4.37.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -129 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 53 52 33 38} +do_test boundary2-4.37.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -129 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-4.37.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -129 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.37.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -129 ORDER BY r + } +} {54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.37.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -129 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54} +do_test boundary2-4.37.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -129 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 54 53 52 33 38} +do_test boundary2-4.37.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -129 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 55 58 63 64} +do_test boundary2-4.37.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -129 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 32 29 21 11 2 1} +do_test boundary2-4.37.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -129 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary2-4.37.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -129 ORDER BY r DESC + } +} {32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.37.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -129 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary2-4.37.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -129 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 54 55 58 63 64} +do_test boundary2-4.37.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -129 ORDER BY a DESC + } +} {64 63 58 55 54 47 44 37 32 29 21 11 2 1} +do_test boundary2-4.37.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -129 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary2-4.37.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -129 ORDER BY r DESC + } +} {54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.37.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -129 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary2-4.38.1 { + db eval { + SELECT * FROM t1 WHERE r=-128 + } +} {-128 53 ffffffffffffff80} +do_test boundary2-4.38.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffffffffff80' + } +} {-128 53} +do_test boundary2-4.38.3 { + db eval { + SELECT r, x FROM t1 WHERE a=53 + } +} {-128 ffffffffffffff80} +do_test boundary2-4.38.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -128 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 56 57 59 60 61 62} +do_test boundary2-4.38.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -128 ORDER BY a DESC + } +} {62 61 60 59 57 56 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.38.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -128 ORDER BY r + } +} {52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.38.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -128 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52} +do_test boundary2-4.38.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -128 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 52 33 38} +do_test boundary2-4.38.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -128 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 56 57 59 60 61 62} +do_test boundary2-4.38.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -128 ORDER BY a DESC + } +} {62 61 60 59 57 56 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.38.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -128 ORDER BY r + } +} {53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.38.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -128 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53} +do_test boundary2-4.38.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -128 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 53 52 33 38} +do_test boundary2-4.38.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -128 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 54 55 58 63 64} +do_test boundary2-4.38.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -128 ORDER BY a DESC + } +} {64 63 58 55 54 47 44 37 32 29 21 11 2 1} +do_test boundary2-4.38.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -128 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary2-4.38.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -128 ORDER BY r DESC + } +} {54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.38.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -128 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary2-4.38.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -128 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 53 54 55 58 63 64} +do_test boundary2-4.38.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -128 ORDER BY a DESC + } +} {64 63 58 55 54 53 47 44 37 32 29 21 11 2 1} +do_test boundary2-4.38.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -128 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary2-4.38.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -128 ORDER BY r DESC + } +} {53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.38.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -128 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary2-4.39.1 { + db eval { + SELECT * FROM t1 WHERE r=72057594037927936 + } +} {72057594037927936 28 0100000000000000} +do_test boundary2-4.39.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0100000000000000' + } +} {72057594037927936 28} +do_test boundary2-4.39.3 { + db eval { + SELECT r, x FROM t1 WHERE a=28 + } +} {72057594037927936 0100000000000000} +do_test boundary2-4.39.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927936 ORDER BY a + } +} {3} +do_test boundary2-4.39.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927936 ORDER BY a DESC + } +} {3} +do_test boundary2-4.39.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927936 ORDER BY r + } +} {3} +do_test boundary2-4.39.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927936 ORDER BY r DESC + } +} {3} +do_test boundary2-4.39.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927936 ORDER BY x + } +} {3} +do_test boundary2-4.39.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927936 ORDER BY a + } +} {3 28} +do_test boundary2-4.39.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927936 ORDER BY a DESC + } +} {28 3} +do_test boundary2-4.39.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927936 ORDER BY r + } +} {28 3} +do_test boundary2-4.39.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927936 ORDER BY r DESC + } +} {3 28} +do_test boundary2-4.39.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927936 ORDER BY x + } +} {28 3} +do_test boundary2-4.39.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927936 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.39.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927936 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.39.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927936 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17} +do_test boundary2-4.39.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927936 ORDER BY r DESC + } +} {17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.39.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927936 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.39.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927936 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.39.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927936 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.39.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927936 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28} +do_test boundary2-4.39.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927936 ORDER BY r DESC + } +} {28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.39.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927936 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.40.1 { + db eval { + SELECT * FROM t1 WHERE r=2147483648 + } +} {2147483648 51 0000000080000000} +do_test boundary2-4.40.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000080000000' + } +} {2147483648 51} +do_test boundary2-4.40.3 { + db eval { + SELECT r, x FROM t1 WHERE a=51 + } +} {2147483648 0000000080000000} +do_test boundary2-4.40.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 2147483648 ORDER BY a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary2-4.40.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 2147483648 ORDER BY a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary2-4.40.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 2147483648 ORDER BY r + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.40.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 2147483648 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14} +do_test boundary2-4.40.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 2147483648 ORDER BY x + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.40.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483648 ORDER BY a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary2-4.40.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483648 ORDER BY a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary2-4.40.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483648 ORDER BY r + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.40.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483648 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51} +do_test boundary2-4.40.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483648 ORDER BY x + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.40.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 2147483648 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.40.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 2147483648 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.40.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 2147483648 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20} +do_test boundary2-4.40.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 2147483648 ORDER BY r DESC + } +} {20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.40.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 2147483648 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.40.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483648 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.40.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483648 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.40.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483648 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51} +do_test boundary2-4.40.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483648 ORDER BY r DESC + } +} {51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.40.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483648 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.41.1 { + db eval { + SELECT * FROM t1 WHERE r=549755813887 + } +} {549755813887 46 0000007fffffffff} +do_test boundary2-4.41.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000007fffffffff' + } +} {549755813887 46} +do_test boundary2-4.41.3 { + db eval { + SELECT r, x FROM t1 WHERE a=46 + } +} {549755813887 0000007fffffffff} +do_test boundary2-4.41.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 549755813887 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 56 57} +do_test boundary2-4.41.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 549755813887 ORDER BY a DESC + } +} {57 56 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-4.41.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 549755813887 ORDER BY r + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.41.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 549755813887 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35} +do_test boundary2-4.41.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 549755813887 ORDER BY x + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.41.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813887 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary2-4.41.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813887 ORDER BY a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-4.41.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813887 ORDER BY r + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.41.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813887 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46} +do_test boundary2-4.41.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813887 ORDER BY x + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.41.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 549755813887 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.41.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 549755813887 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.41.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 549755813887 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22} +do_test boundary2-4.41.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 549755813887 ORDER BY r DESC + } +} {22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.41.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 549755813887 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.41.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813887 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.41.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813887 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.41.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813887 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46} +do_test boundary2-4.41.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813887 ORDER BY r DESC + } +} {46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.41.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813887 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.42.1 { + db eval { + SELECT * FROM t1 WHERE r=-549755813888 + } +} {-549755813888 63 ffffff8000000000} +do_test boundary2-4.42.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffff8000000000' + } +} {-549755813888 63} +do_test boundary2-4.42.3 { + db eval { + SELECT r, x FROM t1 WHERE a=63 + } +} {-549755813888 ffffff8000000000} +do_test boundary2-4.42.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -549755813888 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-4.42.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -549755813888 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.42.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -549755813888 ORDER BY r + } +} {47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.42.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -549755813888 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47} +do_test boundary2-4.42.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -549755813888 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.42.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813888 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62 63} +do_test boundary2-4.42.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813888 ORDER BY a DESC + } +} {63 62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.42.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813888 ORDER BY r + } +} {63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.42.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813888 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63} +do_test boundary2-4.42.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813888 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.42.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -549755813888 ORDER BY a + } +} {2 21 44 55 58 64} +do_test boundary2-4.42.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -549755813888 ORDER BY a DESC + } +} {64 58 55 44 21 2} +do_test boundary2-4.42.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -549755813888 ORDER BY r + } +} {55 2 64 21 44 58} +do_test boundary2-4.42.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -549755813888 ORDER BY r DESC + } +} {58 44 21 64 2 55} +do_test boundary2-4.42.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -549755813888 ORDER BY x + } +} {55 2 64 21 44 58} +do_test boundary2-4.42.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813888 ORDER BY a + } +} {2 21 44 55 58 63 64} +do_test boundary2-4.42.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813888 ORDER BY a DESC + } +} {64 63 58 55 44 21 2} +do_test boundary2-4.42.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813888 ORDER BY r + } +} {55 2 64 21 44 58 63} +do_test boundary2-4.42.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813888 ORDER BY r DESC + } +} {63 58 44 21 64 2 55} +do_test boundary2-4.42.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813888 ORDER BY x + } +} {55 2 64 21 44 58 63} +do_test boundary2-4.43.1 { + db eval { + SELECT * FROM t1 WHERE r=281474976710655 + } +} {281474976710655 10 0000ffffffffffff} +do_test boundary2-4.43.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000ffffffffffff' + } +} {281474976710655 10} +do_test boundary2-4.43.3 { + db eval { + SELECT r, x FROM t1 WHERE a=10 + } +} {281474976710655 0000ffffffffffff} +do_test boundary2-4.43.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710655 ORDER BY a + } +} {3 13 17 26 27 28 43 45} +do_test boundary2-4.43.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710655 ORDER BY a DESC + } +} {45 43 28 27 26 17 13 3} +do_test boundary2-4.43.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710655 ORDER BY r + } +} {26 13 43 27 45 17 28 3} +do_test boundary2-4.43.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710655 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26} +do_test boundary2-4.43.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710655 ORDER BY x + } +} {26 13 43 27 45 17 28 3} +do_test boundary2-4.43.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710655 ORDER BY a + } +} {3 10 13 17 26 27 28 43 45} +do_test boundary2-4.43.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710655 ORDER BY a DESC + } +} {45 43 28 27 26 17 13 10 3} +do_test boundary2-4.43.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710655 ORDER BY r + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary2-4.43.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710655 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10} +do_test boundary2-4.43.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710655 ORDER BY x + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary2-4.43.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710655 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.43.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710655 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-4.43.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710655 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34} +do_test boundary2-4.43.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710655 ORDER BY r DESC + } +} {34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.43.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710655 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.43.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710655 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.43.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710655 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.43.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710655 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10} +do_test boundary2-4.43.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710655 ORDER BY r DESC + } +} {10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.43.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710655 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.44.1 { + db eval { + SELECT * FROM t1 WHERE r=4398046511103 + } +} {4398046511103 7 000003ffffffffff} +do_test boundary2-4.44.2 { + db eval { + SELECT r, a FROM t1 WHERE x='000003ffffffffff' + } +} {4398046511103 7} +do_test boundary2-4.44.3 { + db eval { + SELECT r, x FROM t1 WHERE a=7 + } +} {4398046511103 000003ffffffffff} +do_test boundary2-4.44.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511103 ORDER BY a + } +} {3 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary2-4.44.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511103 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 3} +do_test boundary2-4.44.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511103 ORDER BY r + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.44.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511103 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56} +do_test boundary2-4.44.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511103 ORDER BY x + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.44.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511103 ORDER BY a + } +} {3 7 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary2-4.44.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511103 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 7 3} +do_test boundary2-4.44.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511103 ORDER BY r + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.44.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511103 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7} +do_test boundary2-4.44.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511103 ORDER BY x + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.44.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511103 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary2-4.44.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511103 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.44.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511103 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19} +do_test boundary2-4.44.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511103 ORDER BY r DESC + } +} {19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.44.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511103 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.44.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511103 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary2-4.44.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511103 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-4.44.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511103 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7} +do_test boundary2-4.44.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511103 ORDER BY r DESC + } +} {7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.44.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511103 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.45.1 { + db eval { + SELECT * FROM t1 WHERE r=268435455 + } +} {268435455 12 000000000fffffff} +do_test boundary2-4.45.2 { + db eval { + SELECT r, a FROM t1 WHERE x='000000000fffffff' + } +} {268435455 12} +do_test boundary2-4.45.3 { + db eval { + SELECT r, x FROM t1 WHERE a=12 + } +} {268435455 000000000fffffff} +do_test boundary2-4.45.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 268435455 ORDER BY a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-4.45.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 268435455 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary2-4.45.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 268435455 ORDER BY r + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.45.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 268435455 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40} +do_test boundary2-4.45.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 268435455 ORDER BY x + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.45.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 268435455 ORDER BY a + } +} {3 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-4.45.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 268435455 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 3} +do_test boundary2-4.45.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 268435455 ORDER BY r + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.45.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 268435455 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12} +do_test boundary2-4.45.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 268435455 ORDER BY x + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.45.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 268435455 ORDER BY a + } +} {1 2 4 5 6 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.45.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 268435455 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 6 5 4 2 1} +do_test boundary2-4.45.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 268435455 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6} +do_test boundary2-4.45.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 268435455 ORDER BY r DESC + } +} {6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.45.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 268435455 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.45.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 268435455 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.45.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 268435455 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.45.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 268435455 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12} +do_test boundary2-4.45.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 268435455 ORDER BY r DESC + } +} {12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.45.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 268435455 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.46.1 { + db eval { + SELECT * FROM t1 WHERE r=-9223372036854775808 + } +} {-9223372036854775808 55 8000000000000000} +do_test boundary2-4.46.2 { + db eval { + SELECT r, a FROM t1 WHERE x='8000000000000000' + } +} {-9223372036854775808 55} +do_test boundary2-4.46.3 { + db eval { + SELECT r, x FROM t1 WHERE a=55 + } +} {-9223372036854775808 8000000000000000} +do_test boundary2-4.46.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -9223372036854775808 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.46.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -9223372036854775808 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-4.46.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -9223372036854775808 ORDER BY r + } +} {2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.46.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -9223372036854775808 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2} +do_test boundary2-4.46.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -9223372036854775808 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.46.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -9223372036854775808 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.46.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -9223372036854775808 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-4.46.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -9223372036854775808 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.46.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -9223372036854775808 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.46.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -9223372036854775808 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.46.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -9223372036854775808 ORDER BY a + } +} {} +do_test boundary2-4.46.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -9223372036854775808 ORDER BY a DESC + } +} {} +do_test boundary2-4.46.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -9223372036854775808 ORDER BY r + } +} {} +do_test boundary2-4.46.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -9223372036854775808 ORDER BY r DESC + } +} {} +do_test boundary2-4.46.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -9223372036854775808 ORDER BY x + } +} {} +do_test boundary2-4.46.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -9223372036854775808 ORDER BY a + } +} {55} +do_test boundary2-4.46.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -9223372036854775808 ORDER BY a DESC + } +} {55} +do_test boundary2-4.46.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -9223372036854775808 ORDER BY r + } +} {55} +do_test boundary2-4.46.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -9223372036854775808 ORDER BY r DESC + } +} {55} +do_test boundary2-4.46.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -9223372036854775808 ORDER BY x + } +} {55} +do_test boundary2-4.47.1 { + db eval { + SELECT * FROM t1 WHERE r=562949953421312 + } +} {562949953421312 43 0002000000000000} +do_test boundary2-4.47.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0002000000000000' + } +} {562949953421312 43} +do_test boundary2-4.47.3 { + db eval { + SELECT r, x FROM t1 WHERE a=43 + } +} {562949953421312 0002000000000000} +do_test boundary2-4.47.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421312 ORDER BY a + } +} {3 17 27 28 45} +do_test boundary2-4.47.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421312 ORDER BY a DESC + } +} {45 28 27 17 3} +do_test boundary2-4.47.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421312 ORDER BY r + } +} {27 45 17 28 3} +do_test boundary2-4.47.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421312 ORDER BY r DESC + } +} {3 28 17 45 27} +do_test boundary2-4.47.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421312 ORDER BY x + } +} {27 45 17 28 3} +do_test boundary2-4.47.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421312 ORDER BY a + } +} {3 17 27 28 43 45} +do_test boundary2-4.47.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421312 ORDER BY a DESC + } +} {45 43 28 27 17 3} +do_test boundary2-4.47.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421312 ORDER BY r + } +} {43 27 45 17 28 3} +do_test boundary2-4.47.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421312 ORDER BY r DESC + } +} {3 28 17 45 27 43} +do_test boundary2-4.47.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421312 ORDER BY x + } +} {43 27 45 17 28 3} +do_test boundary2-4.47.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421312 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.47.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421312 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.47.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421312 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13} +do_test boundary2-4.47.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421312 ORDER BY r DESC + } +} {13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.47.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421312 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.47.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421312 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.47.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421312 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.47.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421312 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43} +do_test boundary2-4.47.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421312 ORDER BY r DESC + } +} {43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.47.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421312 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.48.1 { + db eval { + SELECT * FROM t1 WHERE r=-8388609 + } +} {-8388609 1 ffffffffff7fffff} +do_test boundary2-4.48.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffffff7fffff' + } +} {-8388609 1} +do_test boundary2-4.48.3 { + db eval { + SELECT r, x FROM t1 WHERE a=1 + } +} {-8388609 ffffffffff7fffff} +do_test boundary2-4.48.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -8388609 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-4.48.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -8388609 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.48.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -8388609 ORDER BY r + } +} {37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.48.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -8388609 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37} +do_test boundary2-4.48.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -8388609 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 37 29 32 54 53 52 33 38} +do_test boundary2-4.48.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -8388609 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-4.48.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -8388609 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.48.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -8388609 ORDER BY r + } +} {1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.48.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -8388609 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1} +do_test boundary2-4.48.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -8388609 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.48.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -8388609 ORDER BY a + } +} {2 11 21 44 47 55 58 63 64} +do_test boundary2-4.48.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -8388609 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 11 2} +do_test boundary2-4.48.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -8388609 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary2-4.48.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -8388609 ORDER BY r DESC + } +} {11 47 63 58 44 21 64 2 55} +do_test boundary2-4.48.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -8388609 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary2-4.48.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -8388609 ORDER BY a + } +} {1 2 11 21 44 47 55 58 63 64} +do_test boundary2-4.48.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -8388609 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 11 2 1} +do_test boundary2-4.48.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -8388609 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary2-4.48.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -8388609 ORDER BY r DESC + } +} {1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.48.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -8388609 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary2-4.49.1 { + db eval { + SELECT * FROM t1 WHERE r=16777215 + } +} {16777215 9 0000000000ffffff} +do_test boundary2-4.49.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000ffffff' + } +} {16777215 9} +do_test boundary2-4.49.3 { + db eval { + SELECT r, x FROM t1 WHERE a=9 + } +} {16777215 0000000000ffffff} +do_test boundary2-4.49.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 16777215 ORDER BY a + } +} {3 6 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-4.49.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 16777215 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 6 3} +do_test boundary2-4.49.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 16777215 ORDER BY r + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.49.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 16777215 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6} +do_test boundary2-4.49.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 16777215 ORDER BY x + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.49.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 16777215 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-4.49.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 16777215 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary2-4.49.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 16777215 ORDER BY r + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.49.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 16777215 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9} +do_test boundary2-4.49.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 16777215 ORDER BY x + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.49.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 16777215 ORDER BY a + } +} {1 2 4 5 8 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.49.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 16777215 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary2-4.49.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 16777215 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24} +do_test boundary2-4.49.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 16777215 ORDER BY r DESC + } +} {24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.49.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 16777215 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.49.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 16777215 ORDER BY a + } +} {1 2 4 5 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.49.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 16777215 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 5 4 2 1} +do_test boundary2-4.49.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 16777215 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9} +do_test boundary2-4.49.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 16777215 ORDER BY r DESC + } +} {9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.49.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 16777215 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.50.1 { + db eval { + SELECT * FROM t1 WHERE r=8388608 + } +} {8388608 24 0000000000800000} +do_test boundary2-4.50.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000800000' + } +} {8388608 24} +do_test boundary2-4.50.3 { + db eval { + SELECT r, x FROM t1 WHERE a=24 + } +} {8388608 0000000000800000} +do_test boundary2-4.50.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 8388608 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-4.50.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 8388608 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary2-4.50.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 8388608 ORDER BY r + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.50.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 8388608 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9} +do_test boundary2-4.50.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 8388608 ORDER BY x + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.50.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 8388608 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-4.50.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 8388608 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary2-4.50.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 8388608 ORDER BY r + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.50.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 8388608 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24} +do_test boundary2-4.50.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 8388608 ORDER BY x + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.50.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 8388608 ORDER BY a + } +} {1 2 4 5 8 11 15 16 18 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.50.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 8388608 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary2-4.50.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 8388608 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18} +do_test boundary2-4.50.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 8388608 ORDER BY r DESC + } +} {18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.50.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 8388608 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.50.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 8388608 ORDER BY a + } +} {1 2 4 5 8 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.50.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 8388608 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary2-4.50.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 8388608 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24} +do_test boundary2-4.50.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 8388608 ORDER BY r DESC + } +} {24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.50.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 8388608 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.51.1 { + db eval { + SELECT * FROM t1 WHERE r=16383 + } +} {16383 8 0000000000003fff} +do_test boundary2-4.51.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000003fff' + } +} {16383 8} +do_test boundary2-4.51.3 { + db eval { + SELECT r, x FROM t1 WHERE a=8 + } +} {16383 0000000000003fff} +do_test boundary2-4.51.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 16383 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-4.51.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 16383 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 7 6 3} +do_test boundary2-4.51.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 16383 ORDER BY r + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.51.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 16383 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16} +do_test boundary2-4.51.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 16383 ORDER BY x + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.51.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 16383 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-4.51.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 16383 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-4.51.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 16383 ORDER BY r + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.51.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 16383 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8} +do_test boundary2-4.51.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 16383 ORDER BY x + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.51.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 16383 ORDER BY a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-4.51.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 16383 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary2-4.51.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 16383 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61} +do_test boundary2-4.51.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 16383 ORDER BY r DESC + } +} {61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.51.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 16383 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.51.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 16383 ORDER BY a + } +} {1 2 4 5 8 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-4.51.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 16383 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 8 5 4 2 1} +do_test boundary2-4.51.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 16383 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8} +do_test boundary2-4.51.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 16383 ORDER BY r DESC + } +} {8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.51.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 16383 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.52.1 { + db eval { + SELECT * FROM t1 WHERE r=140737488355328 + } +} {140737488355328 34 0000800000000000} +do_test boundary2-4.52.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000800000000000' + } +} {140737488355328 34} +do_test boundary2-4.52.3 { + db eval { + SELECT r, x FROM t1 WHERE a=34 + } +} {140737488355328 0000800000000000} +do_test boundary2-4.52.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355328 ORDER BY a + } +} {3 10 13 17 26 27 28 43 45} +do_test boundary2-4.52.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355328 ORDER BY a DESC + } +} {45 43 28 27 26 17 13 10 3} +do_test boundary2-4.52.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355328 ORDER BY r + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary2-4.52.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355328 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10} +do_test boundary2-4.52.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355328 ORDER BY x + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary2-4.52.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355328 ORDER BY a + } +} {3 10 13 17 26 27 28 34 43 45} +do_test boundary2-4.52.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355328 ORDER BY a DESC + } +} {45 43 34 28 27 26 17 13 10 3} +do_test boundary2-4.52.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355328 ORDER BY r + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.52.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355328 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34} +do_test boundary2-4.52.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355328 ORDER BY x + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.52.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355328 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.52.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355328 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-4.52.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355328 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25} +do_test boundary2-4.52.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355328 ORDER BY r DESC + } +} {25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.52.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355328 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.52.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355328 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.52.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355328 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-4.52.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355328 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34} +do_test boundary2-4.52.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355328 ORDER BY r DESC + } +} {34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.52.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355328 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.53.1 { + db eval { + SELECT * FROM t1 WHERE r=2097151 + } +} {2097151 15 00000000001fffff} +do_test boundary2-4.53.2 { + db eval { + SELECT r, a FROM t1 WHERE x='00000000001fffff' + } +} {2097151 15} +do_test boundary2-4.53.3 { + db eval { + SELECT r, x FROM t1 WHERE a=15 + } +} {2097151 00000000001fffff} +do_test boundary2-4.53.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 2097151 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary2-4.53.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 2097151 ORDER BY a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary2-4.53.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 2097151 ORDER BY r + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.53.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 2097151 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42} +do_test boundary2-4.53.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 2097151 ORDER BY x + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.53.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 2097151 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary2-4.53.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 2097151 ORDER BY a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-4.53.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 2097151 ORDER BY r + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.53.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 2097151 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15} +do_test boundary2-4.53.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 2097151 ORDER BY x + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.53.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 2097151 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.53.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 2097151 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-4.53.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 2097151 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62} +do_test boundary2-4.53.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 2097151 ORDER BY r DESC + } +} {62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.53.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 2097151 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.53.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 2097151 ORDER BY a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.53.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 2097151 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary2-4.53.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 2097151 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15} +do_test boundary2-4.53.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 2097151 ORDER BY r DESC + } +} {15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.53.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 2097151 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.54.1 { + db eval { + SELECT * FROM t1 WHERE r=140737488355327 + } +} {140737488355327 25 00007fffffffffff} +do_test boundary2-4.54.2 { + db eval { + SELECT r, a FROM t1 WHERE x='00007fffffffffff' + } +} {140737488355327 25} +do_test boundary2-4.54.3 { + db eval { + SELECT r, x FROM t1 WHERE a=25 + } +} {140737488355327 00007fffffffffff} +do_test boundary2-4.54.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355327 ORDER BY a + } +} {3 10 13 17 26 27 28 34 43 45} +do_test boundary2-4.54.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355327 ORDER BY a DESC + } +} {45 43 34 28 27 26 17 13 10 3} +do_test boundary2-4.54.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355327 ORDER BY r + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.54.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355327 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34} +do_test boundary2-4.54.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355327 ORDER BY x + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.54.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355327 ORDER BY a + } +} {3 10 13 17 25 26 27 28 34 43 45} +do_test boundary2-4.54.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355327 ORDER BY a DESC + } +} {45 43 34 28 27 26 25 17 13 10 3} +do_test boundary2-4.54.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355327 ORDER BY r + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.54.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355327 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25} +do_test boundary2-4.54.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355327 ORDER BY x + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.54.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355327 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.54.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355327 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-4.54.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355327 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56} +do_test boundary2-4.54.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355327 ORDER BY r DESC + } +} {56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.54.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355327 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.54.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355327 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.54.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355327 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-4.54.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355327 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25} +do_test boundary2-4.54.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355327 ORDER BY r DESC + } +} {25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.54.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355327 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.55.1 { + db eval { + SELECT * FROM t1 WHERE r=281474976710656 + } +} {281474976710656 26 0001000000000000} +do_test boundary2-4.55.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0001000000000000' + } +} {281474976710656 26} +do_test boundary2-4.55.3 { + db eval { + SELECT r, x FROM t1 WHERE a=26 + } +} {281474976710656 0001000000000000} +do_test boundary2-4.55.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710656 ORDER BY a + } +} {3 13 17 27 28 43 45} +do_test boundary2-4.55.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710656 ORDER BY a DESC + } +} {45 43 28 27 17 13 3} +do_test boundary2-4.55.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710656 ORDER BY r + } +} {13 43 27 45 17 28 3} +do_test boundary2-4.55.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710656 ORDER BY r DESC + } +} {3 28 17 45 27 43 13} +do_test boundary2-4.55.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710656 ORDER BY x + } +} {13 43 27 45 17 28 3} +do_test boundary2-4.55.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710656 ORDER BY a + } +} {3 13 17 26 27 28 43 45} +do_test boundary2-4.55.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710656 ORDER BY a DESC + } +} {45 43 28 27 26 17 13 3} +do_test boundary2-4.55.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710656 ORDER BY r + } +} {26 13 43 27 45 17 28 3} +do_test boundary2-4.55.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710656 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26} +do_test boundary2-4.55.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710656 ORDER BY x + } +} {26 13 43 27 45 17 28 3} +do_test boundary2-4.55.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710656 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.55.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710656 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.55.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710656 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10} +do_test boundary2-4.55.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710656 ORDER BY r DESC + } +} {10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.55.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710656 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.55.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710656 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.55.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710656 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.55.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710656 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26} +do_test boundary2-4.55.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710656 ORDER BY r DESC + } +} {26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.55.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710656 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.56.1 { + db eval { + SELECT * FROM t1 WHERE r=32767 + } +} {32767 23 0000000000007fff} +do_test boundary2-4.56.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000007fff' + } +} {32767 23} +do_test boundary2-4.56.3 { + db eval { + SELECT r, x FROM t1 WHERE a=23 + } +} {32767 0000000000007fff} +do_test boundary2-4.56.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 32767 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-4.56.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 32767 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-4.56.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 32767 ORDER BY r + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.56.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 32767 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50} +do_test boundary2-4.56.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 32767 ORDER BY x + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.56.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 32767 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-4.56.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 32767 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-4.56.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 32767 ORDER BY r + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.56.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 32767 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23} +do_test boundary2-4.56.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 32767 ORDER BY x + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.56.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 32767 ORDER BY a + } +} {1 2 4 5 8 11 16 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-4.56.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 32767 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 16 11 8 5 4 2 1} +do_test boundary2-4.56.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 32767 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16} +do_test boundary2-4.56.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 32767 ORDER BY r DESC + } +} {16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.56.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 32767 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.56.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 32767 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-4.56.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 32767 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-4.56.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 32767 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23} +do_test boundary2-4.56.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 32767 ORDER BY r DESC + } +} {23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.56.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 32767 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.57.1 { + db eval { + SELECT * FROM t1 WHERE r=127 + } +} {127 4 000000000000007f} +do_test boundary2-4.57.2 { + db eval { + SELECT r, a FROM t1 WHERE x='000000000000007f' + } +} {127 4} +do_test boundary2-4.57.3 { + db eval { + SELECT r, x FROM t1 WHERE a=4 + } +} {127 000000000000007f} +do_test boundary2-4.57.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 127 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-4.57.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 127 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-4.57.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 127 ORDER BY r + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.57.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 127 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49} +do_test boundary2-4.57.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 127 ORDER BY x + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.57.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 127 ORDER BY a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-4.57.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 127 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary2-4.57.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 127 ORDER BY r + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.57.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 127 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4} +do_test boundary2-4.57.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 127 ORDER BY x + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.57.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 127 ORDER BY a + } +} {1 2 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-4.57.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 127 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 2 1} +do_test boundary2-4.57.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 127 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31} +do_test boundary2-4.57.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 127 ORDER BY r DESC + } +} {31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.57.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 127 ORDER BY x + } +} {59 60 41 5 31 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.57.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 127 ORDER BY a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-4.57.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 127 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary2-4.57.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 127 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4} +do_test boundary2-4.57.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 127 ORDER BY r DESC + } +} {4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.57.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 127 ORDER BY x + } +} {59 60 41 5 31 4 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.58.1 { + db eval { + SELECT * FROM t1 WHERE r=36028797018963967 + } +} {36028797018963967 27 007fffffffffffff} +do_test boundary2-4.58.2 { + db eval { + SELECT r, a FROM t1 WHERE x='007fffffffffffff' + } +} {36028797018963967 27} +do_test boundary2-4.58.3 { + db eval { + SELECT r, x FROM t1 WHERE a=27 + } +} {36028797018963967 007fffffffffffff} +do_test boundary2-4.58.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963967 ORDER BY a + } +} {3 17 28 45} +do_test boundary2-4.58.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963967 ORDER BY a DESC + } +} {45 28 17 3} +do_test boundary2-4.58.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963967 ORDER BY r + } +} {45 17 28 3} +do_test boundary2-4.58.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963967 ORDER BY r DESC + } +} {3 28 17 45} +do_test boundary2-4.58.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963967 ORDER BY x + } +} {45 17 28 3} +do_test boundary2-4.58.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963967 ORDER BY a + } +} {3 17 27 28 45} +do_test boundary2-4.58.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963967 ORDER BY a DESC + } +} {45 28 27 17 3} +do_test boundary2-4.58.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963967 ORDER BY r + } +} {27 45 17 28 3} +do_test boundary2-4.58.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963967 ORDER BY r DESC + } +} {3 28 17 45 27} +do_test boundary2-4.58.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963967 ORDER BY x + } +} {27 45 17 28 3} +do_test boundary2-4.58.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963967 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.58.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963967 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.58.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963967 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43} +do_test boundary2-4.58.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963967 ORDER BY r DESC + } +} {43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.58.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963967 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.58.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963967 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.58.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963967 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.58.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963967 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27} +do_test boundary2-4.58.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963967 ORDER BY r DESC + } +} {27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.58.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963967 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.59.1 { + db eval { + SELECT * FROM t1 WHERE r=4398046511104 + } +} {4398046511104 56 0000040000000000} +do_test boundary2-4.59.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000040000000000' + } +} {4398046511104 56} +do_test boundary2-4.59.3 { + db eval { + SELECT r, x FROM t1 WHERE a=56 + } +} {4398046511104 0000040000000000} +do_test boundary2-4.59.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511104 ORDER BY a + } +} {3 10 13 17 25 26 27 28 34 43 45} +do_test boundary2-4.59.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511104 ORDER BY a DESC + } +} {45 43 34 28 27 26 25 17 13 10 3} +do_test boundary2-4.59.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511104 ORDER BY r + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.59.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511104 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25} +do_test boundary2-4.59.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511104 ORDER BY x + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.59.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511104 ORDER BY a + } +} {3 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary2-4.59.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511104 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 3} +do_test boundary2-4.59.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511104 ORDER BY r + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.59.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511104 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56} +do_test boundary2-4.59.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511104 ORDER BY x + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.59.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511104 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary2-4.59.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511104 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-4.59.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511104 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7} +do_test boundary2-4.59.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511104 ORDER BY r DESC + } +} {7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.59.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511104 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.59.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511104 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.59.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511104 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-4.59.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511104 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56} +do_test boundary2-4.59.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511104 ORDER BY r DESC + } +} {56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.59.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511104 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.60.1 { + db eval { + SELECT * FROM t1 WHERE r=1 + } +} {1 60 0000000000000001} +do_test boundary2-4.60.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000000001' + } +} {1 60} +do_test boundary2-4.60.3 { + db eval { + SELECT r, x FROM t1 WHERE a=60 + } +} {1 0000000000000001} +do_test boundary2-4.60.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 1 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-4.60.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 1 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.60.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 1 ORDER BY r + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.60.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 1 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41} +do_test boundary2-4.60.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 1 ORDER BY x + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.60.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 1 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 60 61 62} +do_test boundary2-4.60.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 1 ORDER BY a DESC + } +} {62 61 60 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.60.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 1 ORDER BY r + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.60.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 1 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60} +do_test boundary2-4.60.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 1 ORDER BY x + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.60.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 1 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 63 64} +do_test boundary2-4.60.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 1 ORDER BY a DESC + } +} {64 63 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary2-4.60.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 1 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59} +do_test boundary2-4.60.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 1 ORDER BY r DESC + } +} {59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.60.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 1 ORDER BY x + } +} {59 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.60.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 1 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-4.60.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 1 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary2-4.60.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 1 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60} +do_test boundary2-4.60.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 1 ORDER BY r DESC + } +} {60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.60.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 1 ORDER BY x + } +} {59 60 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.61.1 { + db eval { + SELECT * FROM t1 WHERE r=36028797018963968 + } +} {36028797018963968 45 0080000000000000} +do_test boundary2-4.61.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0080000000000000' + } +} {36028797018963968 45} +do_test boundary2-4.61.3 { + db eval { + SELECT r, x FROM t1 WHERE a=45 + } +} {36028797018963968 0080000000000000} +do_test boundary2-4.61.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963968 ORDER BY a + } +} {3 17 28} +do_test boundary2-4.61.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963968 ORDER BY a DESC + } +} {28 17 3} +do_test boundary2-4.61.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963968 ORDER BY r + } +} {17 28 3} +do_test boundary2-4.61.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963968 ORDER BY r DESC + } +} {3 28 17} +do_test boundary2-4.61.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963968 ORDER BY x + } +} {17 28 3} +do_test boundary2-4.61.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963968 ORDER BY a + } +} {3 17 28 45} +do_test boundary2-4.61.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963968 ORDER BY a DESC + } +} {45 28 17 3} +do_test boundary2-4.61.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963968 ORDER BY r + } +} {45 17 28 3} +do_test boundary2-4.61.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963968 ORDER BY r DESC + } +} {3 28 17 45} +do_test boundary2-4.61.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963968 ORDER BY x + } +} {45 17 28 3} +do_test boundary2-4.61.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963968 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.61.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963968 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.61.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963968 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27} +do_test boundary2-4.61.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963968 ORDER BY r DESC + } +} {27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.61.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963968 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.61.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963968 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.61.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963968 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.61.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963968 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45} +do_test boundary2-4.61.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963968 ORDER BY r DESC + } +} {45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.61.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963968 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.62.1 { + db eval { + SELECT * FROM t1 WHERE r=-2147483649 + } +} {-2147483649 47 ffffffff7fffffff} +do_test boundary2-4.62.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffff7fffffff' + } +} {-2147483649 47} +do_test boundary2-4.62.3 { + db eval { + SELECT r, x FROM t1 WHERE a=47 + } +} {-2147483649 ffffffff7fffffff} +do_test boundary2-4.62.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -2147483649 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-4.62.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -2147483649 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.62.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -2147483649 ORDER BY r + } +} {11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.62.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -2147483649 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11} +do_test boundary2-4.62.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -2147483649 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.62.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483649 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-4.62.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483649 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.62.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483649 ORDER BY r + } +} {47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.62.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483649 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47} +do_test boundary2-4.62.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483649 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.62.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -2147483649 ORDER BY a + } +} {2 21 44 55 58 63 64} +do_test boundary2-4.62.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -2147483649 ORDER BY a DESC + } +} {64 63 58 55 44 21 2} +do_test boundary2-4.62.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -2147483649 ORDER BY r + } +} {55 2 64 21 44 58 63} +do_test boundary2-4.62.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -2147483649 ORDER BY r DESC + } +} {63 58 44 21 64 2 55} +do_test boundary2-4.62.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -2147483649 ORDER BY x + } +} {55 2 64 21 44 58 63} +do_test boundary2-4.62.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483649 ORDER BY a + } +} {2 21 44 47 55 58 63 64} +do_test boundary2-4.62.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483649 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 2} +do_test boundary2-4.62.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483649 ORDER BY r + } +} {55 2 64 21 44 58 63 47} +do_test boundary2-4.62.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483649 ORDER BY r DESC + } +} {47 63 58 44 21 64 2 55} +do_test boundary2-4.62.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483649 ORDER BY x + } +} {55 2 64 21 44 58 63 47} +do_test boundary2-4.63.1 { + db eval { + SELECT * FROM t1 WHERE r=-36028797018963969 + } +} {-36028797018963969 2 ff7fffffffffffff} +do_test boundary2-4.63.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ff7fffffffffffff' + } +} {-36028797018963969 2} +do_test boundary2-4.63.3 { + db eval { + SELECT r, x FROM t1 WHERE a=2 + } +} {-36028797018963969 ff7fffffffffffff} +do_test boundary2-4.63.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963969 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.63.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963969 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.63.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963969 ORDER BY r + } +} {64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.63.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963969 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64} +do_test boundary2-4.63.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963969 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.63.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963969 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.63.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963969 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-4.63.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963969 ORDER BY r + } +} {2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.63.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963969 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2} +do_test boundary2-4.63.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963969 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.63.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963969 ORDER BY a + } +} {55} +do_test boundary2-4.63.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963969 ORDER BY a DESC + } +} {55} +do_test boundary2-4.63.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963969 ORDER BY r + } +} {55} +do_test boundary2-4.63.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963969 ORDER BY r DESC + } +} {55} +do_test boundary2-4.63.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963969 ORDER BY x + } +} {55} +do_test boundary2-4.63.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963969 ORDER BY a + } +} {2 55} +do_test boundary2-4.63.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963969 ORDER BY a DESC + } +} {55 2} +do_test boundary2-4.63.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963969 ORDER BY r + } +} {55 2} +do_test boundary2-4.63.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963969 ORDER BY r DESC + } +} {2 55} +do_test boundary2-4.63.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963969 ORDER BY x + } +} {55 2} +do_test boundary2-4.64.1 { + db eval { + SELECT * FROM t1 WHERE r=3 + } +} {3 5 0000000000000003} +do_test boundary2-4.64.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000000003' + } +} {3 5} +do_test boundary2-4.64.3 { + db eval { + SELECT r, x FROM t1 WHERE a=5 + } +} {3 0000000000000003} +do_test boundary2-4.64.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 3 ORDER BY a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-4.64.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 3 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary2-4.64.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 3 ORDER BY r + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.64.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 3 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31} +do_test boundary2-4.64.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 3 ORDER BY x + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.64.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 3 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-4.64.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 3 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.64.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 3 ORDER BY r + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.64.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 3 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5} +do_test boundary2-4.64.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 3 ORDER BY x + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.64.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 3 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-4.64.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 3 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 2 1} +do_test boundary2-4.64.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 3 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41} +do_test boundary2-4.64.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 3 ORDER BY r DESC + } +} {41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.64.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 3 ORDER BY x + } +} {59 60 41 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.64.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 3 ORDER BY a + } +} {1 2 5 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-4.64.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 3 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 5 2 1} +do_test boundary2-4.64.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 3 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5} +do_test boundary2-4.64.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 3 ORDER BY r DESC + } +} {5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.64.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 3 ORDER BY x + } +} {59 60 41 5 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.65.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 9.22337303685477580800e+18 ORDER BY a + } +} {} +do_test boundary2-4.65.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 9.22337303685477580800e+18 ORDER BY a DESC + } +} {} +do_test boundary2-4.65.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 9.22337303685477580800e+18 ORDER BY r + } +} {} +do_test boundary2-4.65.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 9.22337303685477580800e+18 ORDER BY r DESC + } +} {} +do_test boundary2-4.65.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 9.22337303685477580800e+18 ORDER BY x + } +} {} +do_test boundary2-4.65.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 9.22337303685477580800e+18 ORDER BY a + } +} {} +do_test boundary2-4.65.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 9.22337303685477580800e+18 ORDER BY a DESC + } +} {} +do_test boundary2-4.65.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 9.22337303685477580800e+18 ORDER BY r + } +} {} +do_test boundary2-4.65.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 9.22337303685477580800e+18 ORDER BY r DESC + } +} {} +do_test boundary2-4.65.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 9.22337303685477580800e+18 ORDER BY x + } +} {} +do_test boundary2-4.65.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 9.22337303685477580800e+18 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.65.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 9.22337303685477580800e+18 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-4.65.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 9.22337303685477580800e+18 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.65.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 9.22337303685477580800e+18 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.65.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 9.22337303685477580800e+18 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.65.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 9.22337303685477580800e+18 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.65.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 9.22337303685477580800e+18 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-4.65.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 9.22337303685477580800e+18 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.65.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 9.22337303685477580800e+18 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.65.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 9.22337303685477580800e+18 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.66.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -9.22337303685477580800e+18 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.66.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -9.22337303685477580800e+18 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-4.66.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -9.22337303685477580800e+18 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.66.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -9.22337303685477580800e+18 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.66.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -9.22337303685477580800e+18 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.66.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -9.22337303685477580800e+18 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.66.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -9.22337303685477580800e+18 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-4.66.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -9.22337303685477580800e+18 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.66.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -9.22337303685477580800e+18 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.66.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -9.22337303685477580800e+18 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.66.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -9.22337303685477580800e+18 ORDER BY a + } +} {} +do_test boundary2-4.66.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -9.22337303685477580800e+18 ORDER BY a DESC + } +} {} +do_test boundary2-4.66.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -9.22337303685477580800e+18 ORDER BY r + } +} {} +do_test boundary2-4.66.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -9.22337303685477580800e+18 ORDER BY r DESC + } +} {} +do_test boundary2-4.66.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -9.22337303685477580800e+18 ORDER BY x + } +} {} +do_test boundary2-4.66.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -9.22337303685477580800e+18 ORDER BY a + } +} {} +do_test boundary2-4.66.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -9.22337303685477580800e+18 ORDER BY a DESC + } +} {} +do_test boundary2-4.66.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -9.22337303685477580800e+18 ORDER BY r + } +} {} +do_test boundary2-4.66.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -9.22337303685477580800e+18 ORDER BY r DESC + } +} {} +do_test boundary2-4.66.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -9.22337303685477580800e+18 ORDER BY x + } +} {} +finish_test diff --git a/test/boundary3.tcl b/test/boundary3.tcl new file mode 100644 index 0000000..5fc26d6 --- /dev/null +++ b/test/boundary3.tcl @@ -0,0 +1,289 @@ +puts {# 2008 December 11 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file is automatically generated from a separate TCL script. +# This file seeks to exercise integer boundary values. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Many of the boundary tests depend on a working 64-bit implementation. +if {![working_64bit_int]} { finish_test; return } +} + +expr srand(0) + +# Generate interesting boundary numbers +# +foreach x { + 0 + 1 + 0x7f + 0x7fff + 0x7fffff + 0x7fffffff + 0x7fffffffff + 0x7fffffffffff + 0x7fffffffffffff + 0x7fffffffffffffff +} { + set x [expr {wide($x)}] + set boundarynum($x) 1 + set boundarynum([expr {wide($x+1)}]) 1 + set boundarynum([expr {wide(-($x+1))}]) 1 + set boundarynum([expr {wide(-($x+2))}]) 1 + set boundarynum([expr {wide($x+$x+1)}]) 1 + set boundarynum([expr {wide($x+$x+2)}]) 1 +} +set x [expr {wide(127)}] +for {set i 1} {$i<=9} {incr i} { + set boundarynum($x) 1 + set boundarynum([expr {wide($x+1)}]) 1 + set x [expr {wide($x*128 + 127)}] +} + +# Scramble the $inlist into a random order. +# +proc scramble {inlist} { + set y {} + foreach x $inlist { + lappend y [list [expr {rand()}] $x] + } + set y [lsort $y] + set outlist {} + foreach x $y { + lappend outlist [lindex $x 1] + } + return $outlist +} + +# A simple selection sort. Not trying to be efficient. +# +proc sort {inlist} { + set outlist {} + set mn [lindex $inlist 0] + foreach x $inlist { + if {$x<$mn} {set mn $x} + } + set outlist $mn + set mx $mn + while {1} { + set valid 0 + foreach x $inlist { + if {$x>$mx && (!$valid || $mn>$x)} { + set mn $x + set valid 1 + } + } + if {!$valid} break + lappend outlist $mn + set mx $mn + } + return $outlist +} + +# Reverse the order of a list +# +proc reverse {inlist} { + set i [llength $inlist] + set outlist {} + for {incr i -1} {$i>=0} {incr i -1} { + lappend outlist [lindex $inlist $i] + } + return $outlist +} + +set nums1 [scramble [array names boundarynum]] +set nums2 [scramble [array names boundarynum]] + +set tname boundary3 +puts "do_test $tname-1.1 \173" +puts " db eval \173" +puts " CREATE TABLE t1(a,x);" +set a 0 +foreach r $nums1 { + incr a + set t1ra($r) $a + set t1ar($a) $r + set x [format %016x [expr {wide($r)}]] + set t1rx($r) $x + set t1xr($x) $r + puts " INSERT INTO t1(oid,a,x) VALUES($r,$a,'$x');" +} +puts " CREATE INDEX t1i1 ON t1(a);" +puts " CREATE INDEX t1i2 ON t1(x);" +puts " \175" +puts "\175 {}" + +puts "do_test $tname-1.2 \173" +puts " db eval \173" +puts " SELECT count(*) FROM t1" +puts " \175" +puts "\175 {64}" + +puts "do_test $tname-1.3 \173" +puts " db eval \173" +puts " CREATE TABLE t2(r,a);" +puts " INSERT INTO t2 SELECT rowid, a FROM t1;" +puts " CREATE INDEX t2i1 ON t2(r);" +puts " CREATE INDEX t2i2 ON t2(a);" +puts " INSERT INTO t2 VALUES(9.22337303685477580800e+18,65);" +set t1ra(9.22337303685477580800e+18) 65 +set t1ar(65) 9.22337303685477580800e+18) +puts " INSERT INTO t2 VALUES(-9.22337303685477580800e+18,66);" +set t1ra(-9.22337303685477580800e+18) 66 +set t1ar(66) -9.22337303685477580800e+18) +puts " SELECT count(*) FROM t2;" +puts " \175" +puts "\175 {66}" + +set nums3 $nums2 +lappend nums3 9.22337303685477580800e+18 +lappend nums3 -9.22337303685477580800e+18 + +set i 0 +foreach r $nums3 { + incr i + + set r5 $r.5 + set r0 $r.0 + if {abs($r)<0x7FFFFFFFFFFFFFFF || $r==-9223372036854775808} { + set x $t1rx($r) + set a $t1ra($r) + puts "do_test $tname-2.$i.1 \173" + puts " db eval \173" + puts " SELECT t1.* FROM t1, t2 WHERE t1.rowid=$r AND t2.a=t1.a" + puts " \175" + puts "\175 {$a $x}" + puts "do_test $tname-2.$i.2 \173" + puts " db eval \173" + puts " SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='$x'" + puts " \175" + puts "\175 {$r $a}" + puts "do_test $tname-2.$i.3 \173" + puts " db eval \173" + puts " SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=$a" + puts " \175" + puts "\175 {$r $x}" + } + + foreach op {> >= < <=} subno {gt ge lt le} { + + ################################################################ 2.x.y.1 + set rset {} + set aset {} + foreach rx $nums2 { + if "\$rx $op \$r" { + lappend rset $rx + lappend aset $t1ra($rx) + } + } + puts "do_test $tname-2.$i.$subno.1 \173" + puts " db eval \173" + puts " SELECT t2.a FROM t1 JOIN t2 USING(a)" + puts " WHERE t1.rowid $op $r ORDER BY t2.a" + puts " \175" + puts "\175 {[sort $aset]}" + + ################################################################ 2.x.y.2 + puts "do_test $tname-2.$i.$subno.2 \173" + puts " db eval \173" + puts " SELECT t2.a FROM t2 NATURAL JOIN t1" + puts " WHERE t1.rowid $op $r ORDER BY t1.a DESC" + puts " \175" + puts "\175 {[reverse [sort $aset]]}" + + + ################################################################ 2.x.y.3 + set ax $t1ra($r) + set aset {} + foreach rx [sort $rset] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.3 \173" + puts " db eval \173" + puts " SELECT t1.a FROM t1 JOIN t2 ON t1.rowid $op t2.r" + puts " WHERE t2.a=$ax" + puts " ORDER BY t1.rowid" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.4 + set aset {} + foreach rx [reverse [sort $rset]] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.4 \173" + puts " db eval \173" + puts " SELECT t1.a FROM t1 JOIN t2 ON t1.rowid $op t2.r" + puts " WHERE t2.a=$ax" + puts " ORDER BY t1.rowid DESC" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.5 + set aset {} + set xset {} + foreach rx $rset { + lappend xset $t1rx($rx) + } + foreach x [sort $xset] { + set rx $t1xr($x) + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.5 \173" + puts " db eval \173" + puts " SELECT t1.a FROM t1 JOIN t2 ON t1.rowid $op t2.r" + puts " WHERE t2.a=$ax" + puts " ORDER BY x" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.10 + if {[string length $r5]>15} continue + set rset {} + set aset {} + foreach rx $nums2 { + if "\$rx $op \$r0" { + lappend rset $rx + } + } + foreach rx [sort $rset] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.10 \173" + puts " db eval \173" + puts " SELECT t1.a FROM t1 JOIN t2 ON t1.rowid $op CAST(t2.r AS real)" + puts " WHERE t2.a=$ax" + puts " ORDER BY t1.rowid" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.11 + set aset {} + foreach rx [reverse [sort $rset]] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.11 \173" + puts " db eval \173" + puts " SELECT t1.a FROM t1 JOIN t2 ON t1.rowid $op CAST(t2.r AS real)" + puts " WHERE t2.a=$ax" + puts " ORDER BY t1.rowid DESC" + puts " \175" + puts "\175 {$aset}" + } + +} + + +puts {finish_test} diff --git a/test/boundary3.test b/test/boundary3.test new file mode 100644 index 0000000..dbe9abf --- /dev/null +++ b/test/boundary3.test @@ -0,0 +1,12456 @@ +# 2008 December 11 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file is automatically generated from a separate TCL script. +# This file seeks to exercise integer boundary values. +# +# $Id: boundary3.test,v 1.2 2009/01/02 15:45:48 shane Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Many of the boundary tests depend on a working 64-bit implementation. +if {![working_64bit_int]} { finish_test; return } + +do_test boundary3-1.1 { + db eval { + CREATE TABLE t1(a,x); + INSERT INTO t1(oid,a,x) VALUES(-8388609,1,'ffffffffff7fffff'); + INSERT INTO t1(oid,a,x) VALUES(-36028797018963969,2,'ff7fffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(9223372036854775807,3,'7fffffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(127,4,'000000000000007f'); + INSERT INTO t1(oid,a,x) VALUES(3,5,'0000000000000003'); + INSERT INTO t1(oid,a,x) VALUES(16777216,6,'0000000001000000'); + INSERT INTO t1(oid,a,x) VALUES(4398046511103,7,'000003ffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(16383,8,'0000000000003fff'); + INSERT INTO t1(oid,a,x) VALUES(16777215,9,'0000000000ffffff'); + INSERT INTO t1(oid,a,x) VALUES(281474976710655,10,'0000ffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(-2147483648,11,'ffffffff80000000'); + INSERT INTO t1(oid,a,x) VALUES(268435455,12,'000000000fffffff'); + INSERT INTO t1(oid,a,x) VALUES(562949953421311,13,'0001ffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(4294967295,14,'00000000ffffffff'); + INSERT INTO t1(oid,a,x) VALUES(2097151,15,'00000000001fffff'); + INSERT INTO t1(oid,a,x) VALUES(16384,16,'0000000000004000'); + INSERT INTO t1(oid,a,x) VALUES(72057594037927935,17,'00ffffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(8388607,18,'00000000007fffff'); + INSERT INTO t1(oid,a,x) VALUES(1099511627776,19,'0000010000000000'); + INSERT INTO t1(oid,a,x) VALUES(2147483647,20,'000000007fffffff'); + INSERT INTO t1(oid,a,x) VALUES(-140737488355329,21,'ffff7fffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(34359738368,22,'0000000800000000'); + INSERT INTO t1(oid,a,x) VALUES(32767,23,'0000000000007fff'); + INSERT INTO t1(oid,a,x) VALUES(8388608,24,'0000000000800000'); + INSERT INTO t1(oid,a,x) VALUES(140737488355327,25,'00007fffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(281474976710656,26,'0001000000000000'); + INSERT INTO t1(oid,a,x) VALUES(36028797018963967,27,'007fffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(72057594037927936,28,'0100000000000000'); + INSERT INTO t1(oid,a,x) VALUES(-32769,29,'ffffffffffff7fff'); + INSERT INTO t1(oid,a,x) VALUES(255,30,'00000000000000ff'); + INSERT INTO t1(oid,a,x) VALUES(4,31,'0000000000000004'); + INSERT INTO t1(oid,a,x) VALUES(-32768,32,'ffffffffffff8000'); + INSERT INTO t1(oid,a,x) VALUES(-2,33,'fffffffffffffffe'); + INSERT INTO t1(oid,a,x) VALUES(140737488355328,34,'0000800000000000'); + INSERT INTO t1(oid,a,x) VALUES(549755813888,35,'0000008000000000'); + INSERT INTO t1(oid,a,x) VALUES(4294967296,36,'0000000100000000'); + INSERT INTO t1(oid,a,x) VALUES(-8388608,37,'ffffffffff800000'); + INSERT INTO t1(oid,a,x) VALUES(-1,38,'ffffffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(34359738367,39,'00000007ffffffff'); + INSERT INTO t1(oid,a,x) VALUES(268435456,40,'0000000010000000'); + INSERT INTO t1(oid,a,x) VALUES(2,41,'0000000000000002'); + INSERT INTO t1(oid,a,x) VALUES(2097152,42,'0000000000200000'); + INSERT INTO t1(oid,a,x) VALUES(562949953421312,43,'0002000000000000'); + INSERT INTO t1(oid,a,x) VALUES(-140737488355328,44,'ffff800000000000'); + INSERT INTO t1(oid,a,x) VALUES(36028797018963968,45,'0080000000000000'); + INSERT INTO t1(oid,a,x) VALUES(549755813887,46,'0000007fffffffff'); + INSERT INTO t1(oid,a,x) VALUES(-2147483649,47,'ffffffff7fffffff'); + INSERT INTO t1(oid,a,x) VALUES(65535,48,'000000000000ffff'); + INSERT INTO t1(oid,a,x) VALUES(128,49,'0000000000000080'); + INSERT INTO t1(oid,a,x) VALUES(32768,50,'0000000000008000'); + INSERT INTO t1(oid,a,x) VALUES(2147483648,51,'0000000080000000'); + INSERT INTO t1(oid,a,x) VALUES(-3,52,'fffffffffffffffd'); + INSERT INTO t1(oid,a,x) VALUES(-128,53,'ffffffffffffff80'); + INSERT INTO t1(oid,a,x) VALUES(-129,54,'ffffffffffffff7f'); + INSERT INTO t1(oid,a,x) VALUES(-9223372036854775808,55,'8000000000000000'); + INSERT INTO t1(oid,a,x) VALUES(4398046511104,56,'0000040000000000'); + INSERT INTO t1(oid,a,x) VALUES(1099511627775,57,'000000ffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(-549755813889,58,'ffffff7fffffffff'); + INSERT INTO t1(oid,a,x) VALUES(0,59,'0000000000000000'); + INSERT INTO t1(oid,a,x) VALUES(1,60,'0000000000000001'); + INSERT INTO t1(oid,a,x) VALUES(256,61,'0000000000000100'); + INSERT INTO t1(oid,a,x) VALUES(65536,62,'0000000000010000'); + INSERT INTO t1(oid,a,x) VALUES(-549755813888,63,'ffffff8000000000'); + INSERT INTO t1(oid,a,x) VALUES(-36028797018963968,64,'ff80000000000000'); + CREATE INDEX t1i1 ON t1(a); + CREATE INDEX t1i2 ON t1(x); + } +} {} +do_test boundary3-1.2 { + db eval { + SELECT count(*) FROM t1 + } +} {64} +do_test boundary3-1.3 { + db eval { + CREATE TABLE t2(r,a); + INSERT INTO t2 SELECT rowid, a FROM t1; + CREATE INDEX t2i1 ON t2(r); + CREATE INDEX t2i2 ON t2(a); + INSERT INTO t2 VALUES(9.22337303685477580800e+18,65); + INSERT INTO t2 VALUES(-9.22337303685477580800e+18,66); + SELECT count(*) FROM t2; + } +} {66} +do_test boundary3-2.1.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=72057594037927935 AND t2.a=t1.a + } +} {17 00ffffffffffffff} +do_test boundary3-2.1.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='00ffffffffffffff' + } +} {72057594037927935 17} +do_test boundary3-2.1.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=17 + } +} {72057594037927935 00ffffffffffffff} +do_test boundary3-2.1.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 72057594037927935 ORDER BY t2.a + } +} {3 28} +do_test boundary3-2.1.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 72057594037927935 ORDER BY t1.a DESC + } +} {28 3} +do_test boundary3-2.1.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=17 + ORDER BY t1.rowid + } +} {28 3} +do_test boundary3-2.1.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=17 + ORDER BY t1.rowid DESC + } +} {3 28} +do_test boundary3-2.1.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=17 + ORDER BY x + } +} {28 3} +do_test boundary3-2.1.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 72057594037927935 ORDER BY t2.a + } +} {3 17 28} +do_test boundary3-2.1.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 72057594037927935 ORDER BY t1.a DESC + } +} {28 17 3} +do_test boundary3-2.1.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=17 + ORDER BY t1.rowid + } +} {17 28 3} +do_test boundary3-2.1.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=17 + ORDER BY t1.rowid DESC + } +} {3 28 17} +do_test boundary3-2.1.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=17 + ORDER BY x + } +} {17 28 3} +do_test boundary3-2.1.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 72057594037927935 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.1.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 72057594037927935 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.1.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=17 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45} +do_test boundary3-2.1.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=17 + ORDER BY t1.rowid DESC + } +} {45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.1.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=17 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.1.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 72057594037927935 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.1.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 72057594037927935 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.1.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=17 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17} +do_test boundary3-2.1.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=17 + ORDER BY t1.rowid DESC + } +} {17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.1.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=17 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.2.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=16384 AND t2.a=t1.a + } +} {16 0000000000004000} +do_test boundary3-2.2.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000000004000' + } +} {16384 16} +do_test boundary3-2.2.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=16 + } +} {16384 0000000000004000} +do_test boundary3-2.2.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 16384 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary3-2.2.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 16384 ORDER BY t1.a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary3-2.2.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=16 + ORDER BY t1.rowid + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.2.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=16 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23} +do_test boundary3-2.2.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=16 + ORDER BY x + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.2.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=16 + ORDER BY t1.rowid + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.2.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=16 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23} +do_test boundary3-2.2.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 16384 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary3-2.2.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 16384 ORDER BY t1.a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 7 6 3} +do_test boundary3-2.2.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=16 + ORDER BY t1.rowid + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.2.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=16 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16} +do_test boundary3-2.2.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=16 + ORDER BY x + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.2.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=16 + ORDER BY t1.rowid + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.2.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=16 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16} +do_test boundary3-2.2.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 16384 ORDER BY t2.a + } +} {1 2 4 5 8 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary3-2.2.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 16384 ORDER BY t1.a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 8 5 4 2 1} +do_test boundary3-2.2.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=16 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8} +do_test boundary3-2.2.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=16 + ORDER BY t1.rowid DESC + } +} {8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.2.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=16 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.2.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=16 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8} +do_test boundary3-2.2.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=16 + ORDER BY t1.rowid DESC + } +} {8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.2.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 16384 ORDER BY t2.a + } +} {1 2 4 5 8 11 16 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary3-2.2.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 16384 ORDER BY t1.a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 16 11 8 5 4 2 1} +do_test boundary3-2.2.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=16 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16} +do_test boundary3-2.2.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=16 + ORDER BY t1.rowid DESC + } +} {16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.2.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=16 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.2.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=16 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16} +do_test boundary3-2.2.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=16 + ORDER BY t1.rowid DESC + } +} {16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.3.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=4294967296 AND t2.a=t1.a + } +} {36 0000000100000000} +do_test boundary3-2.3.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000100000000' + } +} {4294967296 36} +do_test boundary3-2.3.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=36 + } +} {4294967296 0000000100000000} +do_test boundary3-2.3.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 4294967296 ORDER BY t2.a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 39 43 45 46 56 57} +do_test boundary3-2.3.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 4294967296 ORDER BY t1.a DESC + } +} {57 56 46 45 43 39 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary3-2.3.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=36 + ORDER BY t1.rowid + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.3.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=36 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39} +do_test boundary3-2.3.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=36 + ORDER BY x + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.3.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=36 + ORDER BY t1.rowid + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.3.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=36 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39} +do_test boundary3-2.3.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 4294967296 ORDER BY t2.a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary3-2.3.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 4294967296 ORDER BY t1.a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary3-2.3.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=36 + ORDER BY t1.rowid + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.3.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=36 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36} +do_test boundary3-2.3.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=36 + ORDER BY x + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.3.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=36 + ORDER BY t1.rowid + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.3.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=36 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36} +do_test boundary3-2.3.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 4294967296 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.3.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 4294967296 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.3.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=36 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14} +do_test boundary3-2.3.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=36 + ORDER BY t1.rowid DESC + } +} {14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.3.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=36 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.3.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=36 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14} +do_test boundary3-2.3.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=36 + ORDER BY t1.rowid DESC + } +} {14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.3.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 4294967296 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.3.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 4294967296 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.3.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=36 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36} +do_test boundary3-2.3.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=36 + ORDER BY t1.rowid DESC + } +} {36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.3.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=36 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.3.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=36 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36} +do_test boundary3-2.3.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=36 + ORDER BY t1.rowid DESC + } +} {36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.4.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=16777216 AND t2.a=t1.a + } +} {6 0000000001000000} +do_test boundary3-2.4.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000001000000' + } +} {16777216 6} +do_test boundary3-2.4.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=6 + } +} {16777216 0000000001000000} +do_test boundary3-2.4.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 16777216 ORDER BY t2.a + } +} {3 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary3-2.4.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 16777216 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 3} +do_test boundary3-2.4.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=6 + ORDER BY t1.rowid + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.4.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=6 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12} +do_test boundary3-2.4.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=6 + ORDER BY x + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.4.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=6 + ORDER BY t1.rowid + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.4.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=6 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12} +do_test boundary3-2.4.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 16777216 ORDER BY t2.a + } +} {3 6 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary3-2.4.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 16777216 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 6 3} +do_test boundary3-2.4.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=6 + ORDER BY t1.rowid + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.4.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=6 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6} +do_test boundary3-2.4.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=6 + ORDER BY x + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.4.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=6 + ORDER BY t1.rowid + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.4.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=6 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6} +do_test boundary3-2.4.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 16777216 ORDER BY t2.a + } +} {1 2 4 5 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.4.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 16777216 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 5 4 2 1} +do_test boundary3-2.4.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=6 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9} +do_test boundary3-2.4.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=6 + ORDER BY t1.rowid DESC + } +} {9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.4.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=6 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.4.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=6 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9} +do_test boundary3-2.4.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=6 + ORDER BY t1.rowid DESC + } +} {9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.4.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 16777216 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.4.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 16777216 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 6 5 4 2 1} +do_test boundary3-2.4.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=6 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6} +do_test boundary3-2.4.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=6 + ORDER BY t1.rowid DESC + } +} {6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.4.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=6 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.4.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=6 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6} +do_test boundary3-2.4.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=6 + ORDER BY t1.rowid DESC + } +} {6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.5.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-32769 AND t2.a=t1.a + } +} {29 ffffffffffff7fff} +do_test boundary3-2.5.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='ffffffffffff7fff' + } +} {-32769 29} +do_test boundary3-2.5.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=29 + } +} {-32769 ffffffffffff7fff} +do_test boundary3-2.5.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -32769 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary3-2.5.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -32769 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.5.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=29 + ORDER BY t1.rowid + } +} {32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.5.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=29 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32} +do_test boundary3-2.5.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=29 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 32 54 53 52 33 38} +do_test boundary3-2.5.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=29 + ORDER BY t1.rowid + } +} {32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.5.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=29 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32} +do_test boundary3-2.5.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -32769 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary3-2.5.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -32769 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.5.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=29 + ORDER BY t1.rowid + } +} {29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.5.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=29 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29} +do_test boundary3-2.5.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=29 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 29 32 54 53 52 33 38} +do_test boundary3-2.5.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=29 + ORDER BY t1.rowid + } +} {29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.5.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=29 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29} +do_test boundary3-2.5.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -32769 ORDER BY t2.a + } +} {1 2 11 21 37 44 47 55 58 63 64} +do_test boundary3-2.5.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -32769 ORDER BY t1.a DESC + } +} {64 63 58 55 47 44 37 21 11 2 1} +do_test boundary3-2.5.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=29 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary3-2.5.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=29 + ORDER BY t1.rowid DESC + } +} {37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.5.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=29 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary3-2.5.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=29 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary3-2.5.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=29 + ORDER BY t1.rowid DESC + } +} {37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.5.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -32769 ORDER BY t2.a + } +} {1 2 11 21 29 37 44 47 55 58 63 64} +do_test boundary3-2.5.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -32769 ORDER BY t1.a DESC + } +} {64 63 58 55 47 44 37 29 21 11 2 1} +do_test boundary3-2.5.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=29 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary3-2.5.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=29 + ORDER BY t1.rowid DESC + } +} {29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.5.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=29 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary3-2.5.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=29 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary3-2.5.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=29 + ORDER BY t1.rowid DESC + } +} {29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.6.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-140737488355329 AND t2.a=t1.a + } +} {21 ffff7fffffffffff} +do_test boundary3-2.6.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='ffff7fffffffffff' + } +} {-140737488355329 21} +do_test boundary3-2.6.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=21 + } +} {-140737488355329 ffff7fffffffffff} +do_test boundary3-2.6.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -140737488355329 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary3-2.6.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -140737488355329 ORDER BY t1.a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.6.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=21 + ORDER BY t1.rowid + } +} {44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.6.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=21 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44} +do_test boundary3-2.6.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=21 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.6.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -140737488355329 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary3-2.6.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -140737488355329 ORDER BY t1.a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.6.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=21 + ORDER BY t1.rowid + } +} {21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.6.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=21 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21} +do_test boundary3-2.6.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=21 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.6.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -140737488355329 ORDER BY t2.a + } +} {2 55 64} +do_test boundary3-2.6.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -140737488355329 ORDER BY t1.a DESC + } +} {64 55 2} +do_test boundary3-2.6.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=21 + ORDER BY t1.rowid + } +} {55 2 64} +do_test boundary3-2.6.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=21 + ORDER BY t1.rowid DESC + } +} {64 2 55} +do_test boundary3-2.6.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=21 + ORDER BY x + } +} {55 2 64} +do_test boundary3-2.6.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -140737488355329 ORDER BY t2.a + } +} {2 21 55 64} +do_test boundary3-2.6.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -140737488355329 ORDER BY t1.a DESC + } +} {64 55 21 2} +do_test boundary3-2.6.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=21 + ORDER BY t1.rowid + } +} {55 2 64 21} +do_test boundary3-2.6.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=21 + ORDER BY t1.rowid DESC + } +} {21 64 2 55} +do_test boundary3-2.6.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=21 + ORDER BY x + } +} {55 2 64 21} +do_test boundary3-2.7.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=2 AND t2.a=t1.a + } +} {41 0000000000000002} +do_test boundary3-2.7.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000000000002' + } +} {2 41} +do_test boundary3-2.7.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=41 + } +} {2 0000000000000002} +do_test boundary3-2.7.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 2 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary3-2.7.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 2 ORDER BY t1.a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.7.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=41 + ORDER BY t1.rowid + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.7.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=41 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5} +do_test boundary3-2.7.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=41 + ORDER BY x + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.7.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=41 + ORDER BY t1.rowid + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.7.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=41 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5} +do_test boundary3-2.7.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 2 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary3-2.7.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 2 ORDER BY t1.a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.7.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=41 + ORDER BY t1.rowid + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.7.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=41 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41} +do_test boundary3-2.7.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=41 + ORDER BY x + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.7.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=41 + ORDER BY t1.rowid + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.7.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=41 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41} +do_test boundary3-2.7.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 2 ORDER BY t2.a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary3-2.7.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 2 ORDER BY t1.a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary3-2.7.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=41 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60} +do_test boundary3-2.7.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=41 + ORDER BY t1.rowid DESC + } +} {60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.7.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=41 + ORDER BY x + } +} {59 60 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.7.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=41 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60} +do_test boundary3-2.7.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=41 + ORDER BY t1.rowid DESC + } +} {60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.7.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 2 ORDER BY t2.a + } +} {1 2 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary3-2.7.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 2 ORDER BY t1.a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 2 1} +do_test boundary3-2.7.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=41 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41} +do_test boundary3-2.7.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=41 + ORDER BY t1.rowid DESC + } +} {41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.7.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=41 + ORDER BY x + } +} {59 60 41 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.7.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=41 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41} +do_test boundary3-2.7.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=41 + ORDER BY t1.rowid DESC + } +} {41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.8.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=4 AND t2.a=t1.a + } +} {31 0000000000000004} +do_test boundary3-2.8.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000000000004' + } +} {4 31} +do_test boundary3-2.8.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=31 + } +} {4 0000000000000004} +do_test boundary3-2.8.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 4 ORDER BY t2.a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary3-2.8.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 4 ORDER BY t1.a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary3-2.8.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=31 + ORDER BY t1.rowid + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.8.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=31 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4} +do_test boundary3-2.8.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=31 + ORDER BY x + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.8.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=31 + ORDER BY t1.rowid + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.8.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=31 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4} +do_test boundary3-2.8.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 4 ORDER BY t2.a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary3-2.8.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 4 ORDER BY t1.a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary3-2.8.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=31 + ORDER BY t1.rowid + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.8.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=31 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31} +do_test boundary3-2.8.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=31 + ORDER BY x + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.8.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=31 + ORDER BY t1.rowid + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.8.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=31 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31} +do_test boundary3-2.8.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 4 ORDER BY t2.a + } +} {1 2 5 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary3-2.8.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 4 ORDER BY t1.a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 5 2 1} +do_test boundary3-2.8.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=31 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5} +do_test boundary3-2.8.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=31 + ORDER BY t1.rowid DESC + } +} {5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.8.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=31 + ORDER BY x + } +} {59 60 41 5 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.8.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=31 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5} +do_test boundary3-2.8.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=31 + ORDER BY t1.rowid DESC + } +} {5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.8.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 4 ORDER BY t2.a + } +} {1 2 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary3-2.8.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 4 ORDER BY t1.a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 2 1} +do_test boundary3-2.8.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=31 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31} +do_test boundary3-2.8.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=31 + ORDER BY t1.rowid DESC + } +} {31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.8.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=31 + ORDER BY x + } +} {59 60 41 5 31 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.8.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=31 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31} +do_test boundary3-2.8.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=31 + ORDER BY t1.rowid DESC + } +} {31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.9.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=562949953421311 AND t2.a=t1.a + } +} {13 0001ffffffffffff} +do_test boundary3-2.9.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0001ffffffffffff' + } +} {562949953421311 13} +do_test boundary3-2.9.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=13 + } +} {562949953421311 0001ffffffffffff} +do_test boundary3-2.9.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 562949953421311 ORDER BY t2.a + } +} {3 17 27 28 43 45} +do_test boundary3-2.9.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 562949953421311 ORDER BY t1.a DESC + } +} {45 43 28 27 17 3} +do_test boundary3-2.9.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=13 + ORDER BY t1.rowid + } +} {43 27 45 17 28 3} +do_test boundary3-2.9.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=13 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43} +do_test boundary3-2.9.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=13 + ORDER BY x + } +} {43 27 45 17 28 3} +do_test boundary3-2.9.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 562949953421311 ORDER BY t2.a + } +} {3 13 17 27 28 43 45} +do_test boundary3-2.9.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 562949953421311 ORDER BY t1.a DESC + } +} {45 43 28 27 17 13 3} +do_test boundary3-2.9.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=13 + ORDER BY t1.rowid + } +} {13 43 27 45 17 28 3} +do_test boundary3-2.9.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=13 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13} +do_test boundary3-2.9.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=13 + ORDER BY x + } +} {13 43 27 45 17 28 3} +do_test boundary3-2.9.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 562949953421311 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.9.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 562949953421311 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.9.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=13 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26} +do_test boundary3-2.9.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=13 + ORDER BY t1.rowid DESC + } +} {26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.9.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=13 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.9.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 562949953421311 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.9.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 562949953421311 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.9.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=13 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13} +do_test boundary3-2.9.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=13 + ORDER BY t1.rowid DESC + } +} {13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.9.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=13 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.10.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=256 AND t2.a=t1.a + } +} {61 0000000000000100} +do_test boundary3-2.10.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000000000100' + } +} {256 61} +do_test boundary3-2.10.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=61 + } +} {256 0000000000000100} +do_test boundary3-2.10.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 256 ORDER BY t2.a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary3-2.10.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 256 ORDER BY t1.a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary3-2.10.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=61 + ORDER BY t1.rowid + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.10.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=61 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8} +do_test boundary3-2.10.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=61 + ORDER BY x + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.10.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=61 + ORDER BY t1.rowid + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.10.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=61 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8} +do_test boundary3-2.10.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 256 ORDER BY t2.a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary3-2.10.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 256 ORDER BY t1.a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary3-2.10.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=61 + ORDER BY t1.rowid + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.10.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=61 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61} +do_test boundary3-2.10.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=61 + ORDER BY x + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.10.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=61 + ORDER BY t1.rowid + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.10.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=61 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61} +do_test boundary3-2.10.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 256 ORDER BY t2.a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary3-2.10.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 256 ORDER BY t1.a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary3-2.10.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=61 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30} +do_test boundary3-2.10.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=61 + ORDER BY t1.rowid DESC + } +} {30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.10.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=61 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.10.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=61 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30} +do_test boundary3-2.10.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=61 + ORDER BY t1.rowid DESC + } +} {30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.10.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 256 ORDER BY t2.a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary3-2.10.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 256 ORDER BY t1.a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary3-2.10.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=61 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61} +do_test boundary3-2.10.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=61 + ORDER BY t1.rowid DESC + } +} {61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.10.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=61 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.10.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=61 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61} +do_test boundary3-2.10.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=61 + ORDER BY t1.rowid DESC + } +} {61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.11.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=34359738368 AND t2.a=t1.a + } +} {22 0000000800000000} +do_test boundary3-2.11.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000800000000' + } +} {34359738368 22} +do_test boundary3-2.11.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=22 + } +} {34359738368 0000000800000000} +do_test boundary3-2.11.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 34359738368 ORDER BY t2.a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary3-2.11.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 34359738368 ORDER BY t1.a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary3-2.11.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=22 + ORDER BY t1.rowid + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.11.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=22 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46} +do_test boundary3-2.11.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=22 + ORDER BY x + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.11.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=22 + ORDER BY t1.rowid + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.11.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=22 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46} +do_test boundary3-2.11.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 34359738368 ORDER BY t2.a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary3-2.11.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 34359738368 ORDER BY t1.a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary3-2.11.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=22 + ORDER BY t1.rowid + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.11.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=22 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22} +do_test boundary3-2.11.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=22 + ORDER BY x + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.11.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=22 + ORDER BY t1.rowid + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.11.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=22 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22} +do_test boundary3-2.11.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 34359738368 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.11.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 34359738368 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.11.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=22 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39} +do_test boundary3-2.11.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=22 + ORDER BY t1.rowid DESC + } +} {39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.11.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=22 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.11.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=22 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39} +do_test boundary3-2.11.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=22 + ORDER BY t1.rowid DESC + } +} {39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.11.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 34359738368 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.11.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 34359738368 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.11.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=22 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22} +do_test boundary3-2.11.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=22 + ORDER BY t1.rowid DESC + } +} {22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.11.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=22 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.11.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=22 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22} +do_test boundary3-2.11.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=22 + ORDER BY t1.rowid DESC + } +} {22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.12.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=65536 AND t2.a=t1.a + } +} {62 0000000000010000} +do_test boundary3-2.12.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000000010000' + } +} {65536 62} +do_test boundary3-2.12.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=62 + } +} {65536 0000000000010000} +do_test boundary3-2.12.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 65536 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary3-2.12.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 65536 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary3-2.12.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=62 + ORDER BY t1.rowid + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.12.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=62 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15} +do_test boundary3-2.12.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=62 + ORDER BY x + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.12.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=62 + ORDER BY t1.rowid + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.12.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=62 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15} +do_test boundary3-2.12.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 65536 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57 62} +do_test boundary3-2.12.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 65536 ORDER BY t1.a DESC + } +} {62 57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary3-2.12.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=62 + ORDER BY t1.rowid + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.12.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=62 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62} +do_test boundary3-2.12.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=62 + ORDER BY x + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.12.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=62 + ORDER BY t1.rowid + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.12.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=62 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62} +do_test boundary3-2.12.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 65536 ORDER BY t2.a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary3-2.12.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 65536 ORDER BY t1.a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary3-2.12.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=62 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48} +do_test boundary3-2.12.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=62 + ORDER BY t1.rowid DESC + } +} {48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.12.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=62 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.12.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=62 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48} +do_test boundary3-2.12.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=62 + ORDER BY t1.rowid DESC + } +} {48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.12.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 65536 ORDER BY t2.a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.12.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 65536 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary3-2.12.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=62 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62} +do_test boundary3-2.12.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=62 + ORDER BY t1.rowid DESC + } +} {62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.12.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=62 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.12.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=62 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62} +do_test boundary3-2.12.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=62 + ORDER BY t1.rowid DESC + } +} {62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.13.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=268435456 AND t2.a=t1.a + } +} {40 0000000010000000} +do_test boundary3-2.13.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000010000000' + } +} {268435456 40} +do_test boundary3-2.13.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=40 + } +} {268435456 0000000010000000} +do_test boundary3-2.13.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 268435456 ORDER BY t2.a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary3-2.13.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 268435456 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary3-2.13.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=40 + ORDER BY t1.rowid + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.13.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=40 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20} +do_test boundary3-2.13.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=40 + ORDER BY x + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.13.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=40 + ORDER BY t1.rowid + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.13.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=40 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20} +do_test boundary3-2.13.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 268435456 ORDER BY t2.a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary3-2.13.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 268435456 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary3-2.13.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=40 + ORDER BY t1.rowid + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.13.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=40 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40} +do_test boundary3-2.13.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=40 + ORDER BY x + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.13.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=40 + ORDER BY t1.rowid + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.13.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=40 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40} +do_test boundary3-2.13.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 268435456 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.13.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 268435456 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.13.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=40 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12} +do_test boundary3-2.13.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=40 + ORDER BY t1.rowid DESC + } +} {12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.13.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=40 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.13.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=40 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12} +do_test boundary3-2.13.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=40 + ORDER BY t1.rowid DESC + } +} {12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.13.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 268435456 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.13.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 268435456 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.13.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=40 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40} +do_test boundary3-2.13.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=40 + ORDER BY t1.rowid DESC + } +} {40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.13.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=40 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.13.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=40 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40} +do_test boundary3-2.13.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=40 + ORDER BY t1.rowid DESC + } +} {40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.14.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-140737488355328 AND t2.a=t1.a + } +} {44 ffff800000000000} +do_test boundary3-2.14.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='ffff800000000000' + } +} {-140737488355328 44} +do_test boundary3-2.14.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=44 + } +} {-140737488355328 ffff800000000000} +do_test boundary3-2.14.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -140737488355328 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary3-2.14.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -140737488355328 ORDER BY t1.a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.14.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=44 + ORDER BY t1.rowid + } +} {58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.14.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=44 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58} +do_test boundary3-2.14.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=44 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.14.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -140737488355328 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary3-2.14.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -140737488355328 ORDER BY t1.a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.14.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=44 + ORDER BY t1.rowid + } +} {44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.14.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=44 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44} +do_test boundary3-2.14.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=44 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.14.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -140737488355328 ORDER BY t2.a + } +} {2 21 55 64} +do_test boundary3-2.14.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -140737488355328 ORDER BY t1.a DESC + } +} {64 55 21 2} +do_test boundary3-2.14.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=44 + ORDER BY t1.rowid + } +} {55 2 64 21} +do_test boundary3-2.14.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=44 + ORDER BY t1.rowid DESC + } +} {21 64 2 55} +do_test boundary3-2.14.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=44 + ORDER BY x + } +} {55 2 64 21} +do_test boundary3-2.14.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -140737488355328 ORDER BY t2.a + } +} {2 21 44 55 64} +do_test boundary3-2.14.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -140737488355328 ORDER BY t1.a DESC + } +} {64 55 44 21 2} +do_test boundary3-2.14.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=44 + ORDER BY t1.rowid + } +} {55 2 64 21 44} +do_test boundary3-2.14.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=44 + ORDER BY t1.rowid DESC + } +} {44 21 64 2 55} +do_test boundary3-2.14.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=44 + ORDER BY x + } +} {55 2 64 21 44} +do_test boundary3-2.15.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=1099511627776 AND t2.a=t1.a + } +} {19 0000010000000000} +do_test boundary3-2.15.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000010000000000' + } +} {1099511627776 19} +do_test boundary3-2.15.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=19 + } +} {1099511627776 0000010000000000} +do_test boundary3-2.15.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 1099511627776 ORDER BY t2.a + } +} {3 7 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary3-2.15.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 1099511627776 ORDER BY t1.a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 7 3} +do_test boundary3-2.15.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=19 + ORDER BY t1.rowid + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.15.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=19 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7} +do_test boundary3-2.15.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=19 + ORDER BY x + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.15.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=19 + ORDER BY t1.rowid + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.15.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=19 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7} +do_test boundary3-2.15.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 1099511627776 ORDER BY t2.a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56} +do_test boundary3-2.15.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 1099511627776 ORDER BY t1.a DESC + } +} {56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary3-2.15.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=19 + ORDER BY t1.rowid + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.15.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=19 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19} +do_test boundary3-2.15.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=19 + ORDER BY x + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.15.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=19 + ORDER BY t1.rowid + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.15.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=19 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19} +do_test boundary3-2.15.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 1099511627776 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary3-2.15.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 1099511627776 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.15.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=19 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57} +do_test boundary3-2.15.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=19 + ORDER BY t1.rowid DESC + } +} {57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.15.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=19 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.15.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=19 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57} +do_test boundary3-2.15.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=19 + ORDER BY t1.rowid DESC + } +} {57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.15.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 1099511627776 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary3-2.15.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 1099511627776 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.15.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=19 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19} +do_test boundary3-2.15.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=19 + ORDER BY t1.rowid DESC + } +} {19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.15.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=19 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.15.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=19 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19} +do_test boundary3-2.15.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=19 + ORDER BY t1.rowid DESC + } +} {19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.16.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 9223372036854775807 ORDER BY t2.a + } +} {} +do_test boundary3-2.16.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 9223372036854775807 ORDER BY t1.a DESC + } +} {} +do_test boundary3-2.16.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=3 + ORDER BY t1.rowid + } +} {} +do_test boundary3-2.16.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=3 + ORDER BY t1.rowid DESC + } +} {} +do_test boundary3-2.16.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=3 + ORDER BY x + } +} {} +do_test boundary3-2.16.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 9223372036854775807 ORDER BY t2.a + } +} {3} +do_test boundary3-2.16.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 9223372036854775807 ORDER BY t1.a DESC + } +} {3} +do_test boundary3-2.16.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=3 + ORDER BY t1.rowid + } +} {3} +do_test boundary3-2.16.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=3 + ORDER BY t1.rowid DESC + } +} {3} +do_test boundary3-2.16.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=3 + ORDER BY x + } +} {3} +do_test boundary3-2.16.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 9223372036854775807 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.16.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 9223372036854775807 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.16.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=3 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28} +do_test boundary3-2.16.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=3 + ORDER BY t1.rowid DESC + } +} {28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.16.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=3 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.16.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 9223372036854775807 ORDER BY t2.a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.16.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 9223372036854775807 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary3-2.16.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=3 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.16.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=3 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.16.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=3 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.17.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=32768 AND t2.a=t1.a + } +} {50 0000000000008000} +do_test boundary3-2.17.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000000008000' + } +} {32768 50} +do_test boundary3-2.17.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=50 + } +} {32768 0000000000008000} +do_test boundary3-2.17.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 32768 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 51 56 57 62} +do_test boundary3-2.17.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 32768 ORDER BY t1.a DESC + } +} {62 57 56 51 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary3-2.17.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=50 + ORDER BY t1.rowid + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.17.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=50 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48} +do_test boundary3-2.17.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=50 + ORDER BY x + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.17.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=50 + ORDER BY t1.rowid + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.17.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=50 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48} +do_test boundary3-2.17.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 32768 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary3-2.17.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 32768 ORDER BY t1.a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary3-2.17.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=50 + ORDER BY t1.rowid + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.17.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=50 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50} +do_test boundary3-2.17.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=50 + ORDER BY x + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.17.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=50 + ORDER BY t1.rowid + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.17.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=50 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50} +do_test boundary3-2.17.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 32768 ORDER BY t2.a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary3-2.17.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 32768 ORDER BY t1.a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary3-2.17.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=50 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23} +do_test boundary3-2.17.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=50 + ORDER BY t1.rowid DESC + } +} {23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.17.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=50 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.17.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=50 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23} +do_test boundary3-2.17.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=50 + ORDER BY t1.rowid DESC + } +} {23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.17.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 32768 ORDER BY t2.a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary3-2.17.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 32768 ORDER BY t1.a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary3-2.17.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=50 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50} +do_test boundary3-2.17.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=50 + ORDER BY t1.rowid DESC + } +} {50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.17.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=50 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.17.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=50 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50} +do_test boundary3-2.17.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=50 + ORDER BY t1.rowid DESC + } +} {50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.18.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-36028797018963968 AND t2.a=t1.a + } +} {64 ff80000000000000} +do_test boundary3-2.18.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='ff80000000000000' + } +} {-36028797018963968 64} +do_test boundary3-2.18.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=64 + } +} {-36028797018963968 ff80000000000000} +do_test boundary3-2.18.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -36028797018963968 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary3-2.18.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -36028797018963968 ORDER BY t1.a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.18.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=64 + ORDER BY t1.rowid + } +} {21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.18.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=64 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21} +do_test boundary3-2.18.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=64 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.18.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -36028797018963968 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.18.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -36028797018963968 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.18.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=64 + ORDER BY t1.rowid + } +} {64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.18.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=64 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64} +do_test boundary3-2.18.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=64 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.18.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -36028797018963968 ORDER BY t2.a + } +} {2 55} +do_test boundary3-2.18.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -36028797018963968 ORDER BY t1.a DESC + } +} {55 2} +do_test boundary3-2.18.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=64 + ORDER BY t1.rowid + } +} {55 2} +do_test boundary3-2.18.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=64 + ORDER BY t1.rowid DESC + } +} {2 55} +do_test boundary3-2.18.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=64 + ORDER BY x + } +} {55 2} +do_test boundary3-2.18.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -36028797018963968 ORDER BY t2.a + } +} {2 55 64} +do_test boundary3-2.18.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -36028797018963968 ORDER BY t1.a DESC + } +} {64 55 2} +do_test boundary3-2.18.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=64 + ORDER BY t1.rowid + } +} {55 2 64} +do_test boundary3-2.18.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=64 + ORDER BY t1.rowid DESC + } +} {64 2 55} +do_test boundary3-2.18.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=64 + ORDER BY x + } +} {55 2 64} +do_test boundary3-2.19.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=65535 AND t2.a=t1.a + } +} {48 000000000000ffff} +do_test boundary3-2.19.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='000000000000ffff' + } +} {65535 48} +do_test boundary3-2.19.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=48 + } +} {65535 000000000000ffff} +do_test boundary3-2.19.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 65535 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57 62} +do_test boundary3-2.19.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 65535 ORDER BY t1.a DESC + } +} {62 57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary3-2.19.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=48 + ORDER BY t1.rowid + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.19.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=48 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62} +do_test boundary3-2.19.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=48 + ORDER BY x + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.19.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=48 + ORDER BY t1.rowid + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.19.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=48 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62} +do_test boundary3-2.19.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 65535 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 51 56 57 62} +do_test boundary3-2.19.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 65535 ORDER BY t1.a DESC + } +} {62 57 56 51 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary3-2.19.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=48 + ORDER BY t1.rowid + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.19.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=48 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48} +do_test boundary3-2.19.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=48 + ORDER BY x + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.19.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=48 + ORDER BY t1.rowid + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.19.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=48 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48} +do_test boundary3-2.19.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 65535 ORDER BY t2.a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary3-2.19.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 65535 ORDER BY t1.a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary3-2.19.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=48 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50} +do_test boundary3-2.19.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=48 + ORDER BY t1.rowid DESC + } +} {50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.19.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=48 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.19.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=48 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50} +do_test boundary3-2.19.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=48 + ORDER BY t1.rowid DESC + } +} {50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.19.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 65535 ORDER BY t2.a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary3-2.19.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 65535 ORDER BY t1.a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary3-2.19.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=48 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48} +do_test boundary3-2.19.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=48 + ORDER BY t1.rowid DESC + } +} {48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.19.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=48 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.19.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=48 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48} +do_test boundary3-2.19.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=48 + ORDER BY t1.rowid DESC + } +} {48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.20.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=4294967295 AND t2.a=t1.a + } +} {14 00000000ffffffff} +do_test boundary3-2.20.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='00000000ffffffff' + } +} {4294967295 14} +do_test boundary3-2.20.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=14 + } +} {4294967295 00000000ffffffff} +do_test boundary3-2.20.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 4294967295 ORDER BY t2.a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary3-2.20.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 4294967295 ORDER BY t1.a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary3-2.20.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=14 + ORDER BY t1.rowid + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.20.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=14 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36} +do_test boundary3-2.20.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=14 + ORDER BY x + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.20.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=14 + ORDER BY t1.rowid + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.20.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=14 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36} +do_test boundary3-2.20.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 4294967295 ORDER BY t2.a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary3-2.20.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 4294967295 ORDER BY t1.a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary3-2.20.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=14 + ORDER BY t1.rowid + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.20.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=14 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14} +do_test boundary3-2.20.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=14 + ORDER BY x + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.20.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=14 + ORDER BY t1.rowid + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.20.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=14 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14} +do_test boundary3-2.20.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 4294967295 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.20.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 4294967295 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.20.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=14 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51} +do_test boundary3-2.20.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=14 + ORDER BY t1.rowid DESC + } +} {51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.20.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=14 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.20.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=14 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51} +do_test boundary3-2.20.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=14 + ORDER BY t1.rowid DESC + } +} {51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.20.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 4294967295 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.20.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 4294967295 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.20.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=14 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14} +do_test boundary3-2.20.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=14 + ORDER BY t1.rowid DESC + } +} {14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.20.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=14 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.20.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=14 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14} +do_test boundary3-2.20.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=14 + ORDER BY t1.rowid DESC + } +} {14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.21.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=1099511627775 AND t2.a=t1.a + } +} {57 000000ffffffffff} +do_test boundary3-2.21.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='000000ffffffffff' + } +} {1099511627775 57} +do_test boundary3-2.21.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=57 + } +} {1099511627775 000000ffffffffff} +do_test boundary3-2.21.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 1099511627775 ORDER BY t2.a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56} +do_test boundary3-2.21.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 1099511627775 ORDER BY t1.a DESC + } +} {56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary3-2.21.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=57 + ORDER BY t1.rowid + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.21.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=57 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19} +do_test boundary3-2.21.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=57 + ORDER BY x + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.21.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=57 + ORDER BY t1.rowid + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.21.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=57 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19} +do_test boundary3-2.21.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 1099511627775 ORDER BY t2.a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56 57} +do_test boundary3-2.21.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 1099511627775 ORDER BY t1.a DESC + } +} {57 56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary3-2.21.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=57 + ORDER BY t1.rowid + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.21.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=57 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57} +do_test boundary3-2.21.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=57 + ORDER BY x + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.21.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=57 + ORDER BY t1.rowid + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.21.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=57 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57} +do_test boundary3-2.21.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 1099511627775 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.21.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 1099511627775 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.21.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=57 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35} +do_test boundary3-2.21.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=57 + ORDER BY t1.rowid DESC + } +} {35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.21.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=57 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.21.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=57 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35} +do_test boundary3-2.21.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=57 + ORDER BY t1.rowid DESC + } +} {35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.21.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 1099511627775 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary3-2.21.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 1099511627775 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.21.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=57 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57} +do_test boundary3-2.21.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=57 + ORDER BY t1.rowid DESC + } +} {57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.21.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=57 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.21.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=57 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57} +do_test boundary3-2.21.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=57 + ORDER BY t1.rowid DESC + } +} {57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.22.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-8388608 AND t2.a=t1.a + } +} {37 ffffffffff800000} +do_test boundary3-2.22.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='ffffffffff800000' + } +} {-8388608 37} +do_test boundary3-2.22.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=37 + } +} {-8388608 ffffffffff800000} +do_test boundary3-2.22.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -8388608 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary3-2.22.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -8388608 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.22.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=37 + ORDER BY t1.rowid + } +} {29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.22.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=37 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29} +do_test boundary3-2.22.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=37 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 29 32 54 53 52 33 38} +do_test boundary3-2.22.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=37 + ORDER BY t1.rowid + } +} {29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.22.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=37 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29} +do_test boundary3-2.22.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -8388608 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary3-2.22.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -8388608 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.22.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=37 + ORDER BY t1.rowid + } +} {37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.22.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=37 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37} +do_test boundary3-2.22.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=37 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 37 29 32 54 53 52 33 38} +do_test boundary3-2.22.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=37 + ORDER BY t1.rowid + } +} {37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.22.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=37 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37} +do_test boundary3-2.22.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -8388608 ORDER BY t2.a + } +} {1 2 11 21 44 47 55 58 63 64} +do_test boundary3-2.22.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -8388608 ORDER BY t1.a DESC + } +} {64 63 58 55 47 44 21 11 2 1} +do_test boundary3-2.22.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=37 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary3-2.22.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=37 + ORDER BY t1.rowid DESC + } +} {1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.22.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=37 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary3-2.22.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=37 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary3-2.22.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=37 + ORDER BY t1.rowid DESC + } +} {1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.22.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -8388608 ORDER BY t2.a + } +} {1 2 11 21 37 44 47 55 58 63 64} +do_test boundary3-2.22.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -8388608 ORDER BY t1.a DESC + } +} {64 63 58 55 47 44 37 21 11 2 1} +do_test boundary3-2.22.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=37 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary3-2.22.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=37 + ORDER BY t1.rowid DESC + } +} {37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.22.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=37 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary3-2.22.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=37 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary3-2.22.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=37 + ORDER BY t1.rowid DESC + } +} {37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.23.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=549755813888 AND t2.a=t1.a + } +} {35 0000008000000000} +do_test boundary3-2.23.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000008000000000' + } +} {549755813888 35} +do_test boundary3-2.23.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=35 + } +} {549755813888 0000008000000000} +do_test boundary3-2.23.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 549755813888 ORDER BY t2.a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56 57} +do_test boundary3-2.23.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 549755813888 ORDER BY t1.a DESC + } +} {57 56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary3-2.23.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=35 + ORDER BY t1.rowid + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.23.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=35 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57} +do_test boundary3-2.23.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=35 + ORDER BY x + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.23.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=35 + ORDER BY t1.rowid + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.23.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=35 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57} +do_test boundary3-2.23.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 549755813888 ORDER BY t2.a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 56 57} +do_test boundary3-2.23.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 549755813888 ORDER BY t1.a DESC + } +} {57 56 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary3-2.23.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=35 + ORDER BY t1.rowid + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.23.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=35 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35} +do_test boundary3-2.23.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=35 + ORDER BY x + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.23.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=35 + ORDER BY t1.rowid + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.23.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=35 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35} +do_test boundary3-2.23.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 549755813888 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.23.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 549755813888 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.23.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=35 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46} +do_test boundary3-2.23.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=35 + ORDER BY t1.rowid DESC + } +} {46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.23.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=35 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.23.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=35 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46} +do_test boundary3-2.23.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=35 + ORDER BY t1.rowid DESC + } +} {46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.23.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 549755813888 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.23.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 549755813888 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.23.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=35 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35} +do_test boundary3-2.23.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=35 + ORDER BY t1.rowid DESC + } +} {35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.23.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=35 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.23.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=35 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35} +do_test boundary3-2.23.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=35 + ORDER BY t1.rowid DESC + } +} {35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.24.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=8388607 AND t2.a=t1.a + } +} {18 00000000007fffff} +do_test boundary3-2.24.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='00000000007fffff' + } +} {8388607 18} +do_test boundary3-2.24.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=18 + } +} {8388607 00000000007fffff} +do_test boundary3-2.24.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 8388607 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary3-2.24.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 8388607 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary3-2.24.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=18 + ORDER BY t1.rowid + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.24.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=18 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24} +do_test boundary3-2.24.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=18 + ORDER BY x + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.24.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=18 + ORDER BY t1.rowid + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.24.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=18 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24} +do_test boundary3-2.24.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 8388607 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary3-2.24.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 8388607 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary3-2.24.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=18 + ORDER BY t1.rowid + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.24.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=18 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18} +do_test boundary3-2.24.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=18 + ORDER BY x + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.24.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=18 + ORDER BY t1.rowid + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.24.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=18 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18} +do_test boundary3-2.24.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 8388607 ORDER BY t2.a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.24.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 8388607 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary3-2.24.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=18 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42} +do_test boundary3-2.24.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=18 + ORDER BY t1.rowid DESC + } +} {42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.24.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=18 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.24.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=18 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42} +do_test boundary3-2.24.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=18 + ORDER BY t1.rowid DESC + } +} {42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.24.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 8388607 ORDER BY t2.a + } +} {1 2 4 5 8 11 15 16 18 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.24.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 8388607 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary3-2.24.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=18 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18} +do_test boundary3-2.24.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=18 + ORDER BY t1.rowid DESC + } +} {18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.24.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=18 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.24.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=18 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18} +do_test boundary3-2.24.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=18 + ORDER BY t1.rowid DESC + } +} {18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.25.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-3 AND t2.a=t1.a + } +} {52 fffffffffffffffd} +do_test boundary3-2.25.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='fffffffffffffffd' + } +} {-3 52} +do_test boundary3-2.25.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=52 + } +} {-3 fffffffffffffffd} +do_test boundary3-2.25.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -3 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary3-2.25.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -3 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.25.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=52 + ORDER BY t1.rowid + } +} {33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.25.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=52 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33} +do_test boundary3-2.25.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=52 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 33 38} +do_test boundary3-2.25.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=52 + ORDER BY t1.rowid + } +} {33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.25.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=52 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33} +do_test boundary3-2.25.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -3 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 56 57 59 60 61 62} +do_test boundary3-2.25.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -3 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.25.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=52 + ORDER BY t1.rowid + } +} {52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.25.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=52 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52} +do_test boundary3-2.25.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=52 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 52 33 38} +do_test boundary3-2.25.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=52 + ORDER BY t1.rowid + } +} {52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.25.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=52 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52} +do_test boundary3-2.25.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -3 ORDER BY t2.a + } +} {1 2 11 21 29 32 37 44 47 53 54 55 58 63 64} +do_test boundary3-2.25.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -3 ORDER BY t1.a DESC + } +} {64 63 58 55 54 53 47 44 37 32 29 21 11 2 1} +do_test boundary3-2.25.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=52 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary3-2.25.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=52 + ORDER BY t1.rowid DESC + } +} {53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.25.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=52 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary3-2.25.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=52 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary3-2.25.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=52 + ORDER BY t1.rowid DESC + } +} {53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.25.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -3 ORDER BY t2.a + } +} {1 2 11 21 29 32 37 44 47 52 53 54 55 58 63 64} +do_test boundary3-2.25.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -3 ORDER BY t1.a DESC + } +} {64 63 58 55 54 53 52 47 44 37 32 29 21 11 2 1} +do_test boundary3-2.25.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=52 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary3-2.25.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=52 + ORDER BY t1.rowid DESC + } +} {52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.25.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=52 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary3-2.25.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=52 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary3-2.25.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=52 + ORDER BY t1.rowid DESC + } +} {52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.26.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=0 AND t2.a=t1.a + } +} {59 0000000000000000} +do_test boundary3-2.26.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000000000000' + } +} {0 59} +do_test boundary3-2.26.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=59 + } +} {0 0000000000000000} +do_test boundary3-2.26.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 0 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 60 61 62} +do_test boundary3-2.26.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 0 ORDER BY t1.a DESC + } +} {62 61 60 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.26.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=59 + ORDER BY t1.rowid + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.26.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=59 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60} +do_test boundary3-2.26.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=59 + ORDER BY x + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.26.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=59 + ORDER BY t1.rowid + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.26.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=59 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60} +do_test boundary3-2.26.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 0 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary3-2.26.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 0 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.26.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=59 + ORDER BY t1.rowid + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.26.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=59 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59} +do_test boundary3-2.26.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=59 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.26.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=59 + ORDER BY t1.rowid + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.26.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=59 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59} +do_test boundary3-2.26.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 0 ORDER BY t2.a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 63 64} +do_test boundary3-2.26.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 0 ORDER BY t1.a DESC + } +} {64 63 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary3-2.26.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=59 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.26.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=59 + ORDER BY t1.rowid DESC + } +} {38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.26.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=59 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.26.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=59 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.26.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=59 + ORDER BY t1.rowid DESC + } +} {38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.26.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 0 ORDER BY t2.a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 63 64} +do_test boundary3-2.26.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 0 ORDER BY t1.a DESC + } +} {64 63 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary3-2.26.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=59 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59} +do_test boundary3-2.26.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=59 + ORDER BY t1.rowid DESC + } +} {59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.26.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=59 + ORDER BY x + } +} {59 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.26.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=59 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59} +do_test boundary3-2.26.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=59 + ORDER BY t1.rowid DESC + } +} {59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.27.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-1 AND t2.a=t1.a + } +} {38 ffffffffffffffff} +do_test boundary3-2.27.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='ffffffffffffffff' + } +} {-1 38} +do_test boundary3-2.27.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=38 + } +} {-1 ffffffffffffffff} +do_test boundary3-2.27.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -1 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary3-2.27.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -1 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.27.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=38 + ORDER BY t1.rowid + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.27.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=38 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59} +do_test boundary3-2.27.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=38 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.27.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=38 + ORDER BY t1.rowid + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.27.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=38 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59} +do_test boundary3-2.27.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -1 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary3-2.27.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -1 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.27.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=38 + ORDER BY t1.rowid + } +} {38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.27.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=38 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38} +do_test boundary3-2.27.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=38 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 38} +do_test boundary3-2.27.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=38 + ORDER BY t1.rowid + } +} {38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.27.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=38 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38} +do_test boundary3-2.27.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -1 ORDER BY t2.a + } +} {1 2 11 21 29 32 33 37 44 47 52 53 54 55 58 63 64} +do_test boundary3-2.27.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -1 ORDER BY t1.a DESC + } +} {64 63 58 55 54 53 52 47 44 37 33 32 29 21 11 2 1} +do_test boundary3-2.27.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=38 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary3-2.27.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=38 + ORDER BY t1.rowid DESC + } +} {33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.27.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=38 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary3-2.27.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=38 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary3-2.27.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=38 + ORDER BY t1.rowid DESC + } +} {33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.27.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -1 ORDER BY t2.a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 63 64} +do_test boundary3-2.27.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -1 ORDER BY t1.a DESC + } +} {64 63 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary3-2.27.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=38 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.27.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=38 + ORDER BY t1.rowid DESC + } +} {38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.27.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=38 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.27.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=38 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.27.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=38 + ORDER BY t1.rowid DESC + } +} {38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.28.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-2 AND t2.a=t1.a + } +} {33 fffffffffffffffe} +do_test boundary3-2.28.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='fffffffffffffffe' + } +} {-2 33} +do_test boundary3-2.28.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=33 + } +} {-2 fffffffffffffffe} +do_test boundary3-2.28.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -2 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary3-2.28.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -2 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.28.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=33 + ORDER BY t1.rowid + } +} {38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.28.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=33 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38} +do_test boundary3-2.28.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=33 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 38} +do_test boundary3-2.28.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=33 + ORDER BY t1.rowid + } +} {38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.28.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=33 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38} +do_test boundary3-2.28.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -2 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary3-2.28.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -2 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.28.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=33 + ORDER BY t1.rowid + } +} {33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.28.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=33 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33} +do_test boundary3-2.28.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=33 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 33 38} +do_test boundary3-2.28.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=33 + ORDER BY t1.rowid + } +} {33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.28.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=33 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33} +do_test boundary3-2.28.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -2 ORDER BY t2.a + } +} {1 2 11 21 29 32 37 44 47 52 53 54 55 58 63 64} +do_test boundary3-2.28.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -2 ORDER BY t1.a DESC + } +} {64 63 58 55 54 53 52 47 44 37 32 29 21 11 2 1} +do_test boundary3-2.28.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=33 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary3-2.28.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=33 + ORDER BY t1.rowid DESC + } +} {52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.28.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=33 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary3-2.28.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=33 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary3-2.28.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=33 + ORDER BY t1.rowid DESC + } +} {52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.28.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -2 ORDER BY t2.a + } +} {1 2 11 21 29 32 33 37 44 47 52 53 54 55 58 63 64} +do_test boundary3-2.28.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -2 ORDER BY t1.a DESC + } +} {64 63 58 55 54 53 52 47 44 37 33 32 29 21 11 2 1} +do_test boundary3-2.28.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=33 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary3-2.28.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=33 + ORDER BY t1.rowid DESC + } +} {33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.28.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=33 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary3-2.28.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=33 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary3-2.28.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=33 + ORDER BY t1.rowid DESC + } +} {33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.29.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=2097152 AND t2.a=t1.a + } +} {42 0000000000200000} +do_test boundary3-2.29.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000000200000' + } +} {2097152 42} +do_test boundary3-2.29.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=42 + } +} {2097152 0000000000200000} +do_test boundary3-2.29.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 2097152 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary3-2.29.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 2097152 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary3-2.29.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=42 + ORDER BY t1.rowid + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.29.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=42 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18} +do_test boundary3-2.29.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=42 + ORDER BY x + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.29.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=42 + ORDER BY t1.rowid + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.29.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=42 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18} +do_test boundary3-2.29.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 2097152 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary3-2.29.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 2097152 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary3-2.29.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=42 + ORDER BY t1.rowid + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.29.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=42 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42} +do_test boundary3-2.29.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=42 + ORDER BY x + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.29.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=42 + ORDER BY t1.rowid + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.29.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=42 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42} +do_test boundary3-2.29.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 2097152 ORDER BY t2.a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.29.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 2097152 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary3-2.29.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=42 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15} +do_test boundary3-2.29.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=42 + ORDER BY t1.rowid DESC + } +} {15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.29.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=42 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.29.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=42 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15} +do_test boundary3-2.29.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=42 + ORDER BY t1.rowid DESC + } +} {15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.29.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 2097152 ORDER BY t2.a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.29.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 2097152 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary3-2.29.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=42 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42} +do_test boundary3-2.29.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=42 + ORDER BY t1.rowid DESC + } +} {42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.29.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=42 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.29.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=42 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42} +do_test boundary3-2.29.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=42 + ORDER BY t1.rowid DESC + } +} {42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.30.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=128 AND t2.a=t1.a + } +} {49 0000000000000080} +do_test boundary3-2.30.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000000000080' + } +} {128 49} +do_test boundary3-2.30.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=49 + } +} {128 0000000000000080} +do_test boundary3-2.30.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 128 ORDER BY t2.a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary3-2.30.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 128 ORDER BY t1.a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary3-2.30.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=49 + ORDER BY t1.rowid + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.30.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=49 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30} +do_test boundary3-2.30.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=49 + ORDER BY x + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.30.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=49 + ORDER BY t1.rowid + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.30.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=49 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30} +do_test boundary3-2.30.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 128 ORDER BY t2.a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary3-2.30.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 128 ORDER BY t1.a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary3-2.30.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=49 + ORDER BY t1.rowid + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.30.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=49 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49} +do_test boundary3-2.30.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=49 + ORDER BY x + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.30.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=49 + ORDER BY t1.rowid + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.30.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=49 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49} +do_test boundary3-2.30.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 128 ORDER BY t2.a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary3-2.30.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 128 ORDER BY t1.a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary3-2.30.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=49 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4} +do_test boundary3-2.30.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=49 + ORDER BY t1.rowid DESC + } +} {4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.30.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=49 + ORDER BY x + } +} {59 60 41 5 31 4 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.30.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=49 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4} +do_test boundary3-2.30.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=49 + ORDER BY t1.rowid DESC + } +} {4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.30.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 128 ORDER BY t2.a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary3-2.30.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 128 ORDER BY t1.a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary3-2.30.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=49 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49} +do_test boundary3-2.30.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=49 + ORDER BY t1.rowid DESC + } +} {49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.30.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=49 + ORDER BY x + } +} {59 60 41 5 31 4 49 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.30.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=49 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49} +do_test boundary3-2.30.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=49 + ORDER BY t1.rowid DESC + } +} {49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.31.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=255 AND t2.a=t1.a + } +} {30 00000000000000ff} +do_test boundary3-2.31.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='00000000000000ff' + } +} {255 30} +do_test boundary3-2.31.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=30 + } +} {255 00000000000000ff} +do_test boundary3-2.31.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 255 ORDER BY t2.a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary3-2.31.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 255 ORDER BY t1.a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary3-2.31.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=30 + ORDER BY t1.rowid + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.31.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=30 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61} +do_test boundary3-2.31.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=30 + ORDER BY x + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.31.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=30 + ORDER BY t1.rowid + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.31.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=30 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61} +do_test boundary3-2.31.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 255 ORDER BY t2.a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary3-2.31.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 255 ORDER BY t1.a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary3-2.31.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=30 + ORDER BY t1.rowid + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.31.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=30 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30} +do_test boundary3-2.31.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=30 + ORDER BY x + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.31.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=30 + ORDER BY t1.rowid + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.31.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=30 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30} +do_test boundary3-2.31.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 255 ORDER BY t2.a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary3-2.31.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 255 ORDER BY t1.a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary3-2.31.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=30 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49} +do_test boundary3-2.31.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=30 + ORDER BY t1.rowid DESC + } +} {49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.31.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=30 + ORDER BY x + } +} {59 60 41 5 31 4 49 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.31.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=30 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49} +do_test boundary3-2.31.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=30 + ORDER BY t1.rowid DESC + } +} {49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.31.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 255 ORDER BY t2.a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary3-2.31.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 255 ORDER BY t1.a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary3-2.31.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=30 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30} +do_test boundary3-2.31.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=30 + ORDER BY t1.rowid DESC + } +} {30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.31.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=30 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.31.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=30 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30} +do_test boundary3-2.31.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=30 + ORDER BY t1.rowid DESC + } +} {30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.32.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-2147483648 AND t2.a=t1.a + } +} {11 ffffffff80000000} +do_test boundary3-2.32.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='ffffffff80000000' + } +} {-2147483648 11} +do_test boundary3-2.32.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=11 + } +} {-2147483648 ffffffff80000000} +do_test boundary3-2.32.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -2147483648 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary3-2.32.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -2147483648 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.32.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=11 + ORDER BY t1.rowid + } +} {1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.32.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=11 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1} +do_test boundary3-2.32.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=11 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.32.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=11 + ORDER BY t1.rowid + } +} {1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.32.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=11 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1} +do_test boundary3-2.32.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -2147483648 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary3-2.32.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -2147483648 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.32.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=11 + ORDER BY t1.rowid + } +} {11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.32.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=11 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11} +do_test boundary3-2.32.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=11 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.32.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=11 + ORDER BY t1.rowid + } +} {11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.32.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=11 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11} +do_test boundary3-2.32.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -2147483648 ORDER BY t2.a + } +} {2 21 44 47 55 58 63 64} +do_test boundary3-2.32.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -2147483648 ORDER BY t1.a DESC + } +} {64 63 58 55 47 44 21 2} +do_test boundary3-2.32.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=11 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47} +do_test boundary3-2.32.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=11 + ORDER BY t1.rowid DESC + } +} {47 63 58 44 21 64 2 55} +do_test boundary3-2.32.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=11 + ORDER BY x + } +} {55 2 64 21 44 58 63 47} +do_test boundary3-2.32.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=11 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47} +do_test boundary3-2.32.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=11 + ORDER BY t1.rowid DESC + } +} {47 63 58 44 21 64 2 55} +do_test boundary3-2.32.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -2147483648 ORDER BY t2.a + } +} {2 11 21 44 47 55 58 63 64} +do_test boundary3-2.32.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -2147483648 ORDER BY t1.a DESC + } +} {64 63 58 55 47 44 21 11 2} +do_test boundary3-2.32.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=11 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary3-2.32.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=11 + ORDER BY t1.rowid DESC + } +} {11 47 63 58 44 21 64 2 55} +do_test boundary3-2.32.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=11 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary3-2.32.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=11 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary3-2.32.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=11 + ORDER BY t1.rowid DESC + } +} {11 47 63 58 44 21 64 2 55} +do_test boundary3-2.33.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=34359738367 AND t2.a=t1.a + } +} {39 00000007ffffffff} +do_test boundary3-2.33.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='00000007ffffffff' + } +} {34359738367 39} +do_test boundary3-2.33.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=39 + } +} {34359738367 00000007ffffffff} +do_test boundary3-2.33.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 34359738367 ORDER BY t2.a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary3-2.33.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 34359738367 ORDER BY t1.a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary3-2.33.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=39 + ORDER BY t1.rowid + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.33.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=39 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22} +do_test boundary3-2.33.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=39 + ORDER BY x + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.33.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=39 + ORDER BY t1.rowid + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.33.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=39 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22} +do_test boundary3-2.33.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 34359738367 ORDER BY t2.a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 39 43 45 46 56 57} +do_test boundary3-2.33.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 34359738367 ORDER BY t1.a DESC + } +} {57 56 46 45 43 39 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary3-2.33.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=39 + ORDER BY t1.rowid + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.33.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=39 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39} +do_test boundary3-2.33.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=39 + ORDER BY x + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.33.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=39 + ORDER BY t1.rowid + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.33.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=39 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39} +do_test boundary3-2.33.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 34359738367 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.33.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 34359738367 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.33.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=39 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36} +do_test boundary3-2.33.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=39 + ORDER BY t1.rowid DESC + } +} {36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.33.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=39 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.33.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=39 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36} +do_test boundary3-2.33.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=39 + ORDER BY t1.rowid DESC + } +} {36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.33.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 34359738367 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.33.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 34359738367 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.33.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=39 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39} +do_test boundary3-2.33.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=39 + ORDER BY t1.rowid DESC + } +} {39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.33.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=39 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.33.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=39 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39} +do_test boundary3-2.33.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=39 + ORDER BY t1.rowid DESC + } +} {39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.34.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-549755813889 AND t2.a=t1.a + } +} {58 ffffff7fffffffff} +do_test boundary3-2.34.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='ffffff7fffffffff' + } +} {-549755813889 58} +do_test boundary3-2.34.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=58 + } +} {-549755813889 ffffff7fffffffff} +do_test boundary3-2.34.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -549755813889 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62 63} +do_test boundary3-2.34.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -549755813889 ORDER BY t1.a DESC + } +} {63 62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.34.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=58 + ORDER BY t1.rowid + } +} {63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.34.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=58 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63} +do_test boundary3-2.34.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=58 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.34.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=58 + ORDER BY t1.rowid + } +} {63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.34.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=58 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63} +do_test boundary3-2.34.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -549755813889 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary3-2.34.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -549755813889 ORDER BY t1.a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.34.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=58 + ORDER BY t1.rowid + } +} {58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.34.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=58 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58} +do_test boundary3-2.34.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=58 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.34.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=58 + ORDER BY t1.rowid + } +} {58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.34.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=58 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58} +do_test boundary3-2.34.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -549755813889 ORDER BY t2.a + } +} {2 21 44 55 64} +do_test boundary3-2.34.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -549755813889 ORDER BY t1.a DESC + } +} {64 55 44 21 2} +do_test boundary3-2.34.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=58 + ORDER BY t1.rowid + } +} {55 2 64 21 44} +do_test boundary3-2.34.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=58 + ORDER BY t1.rowid DESC + } +} {44 21 64 2 55} +do_test boundary3-2.34.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=58 + ORDER BY x + } +} {55 2 64 21 44} +do_test boundary3-2.34.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=58 + ORDER BY t1.rowid + } +} {55 2 64 21 44} +do_test boundary3-2.34.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=58 + ORDER BY t1.rowid DESC + } +} {44 21 64 2 55} +do_test boundary3-2.34.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -549755813889 ORDER BY t2.a + } +} {2 21 44 55 58 64} +do_test boundary3-2.34.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -549755813889 ORDER BY t1.a DESC + } +} {64 58 55 44 21 2} +do_test boundary3-2.34.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=58 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58} +do_test boundary3-2.34.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=58 + ORDER BY t1.rowid DESC + } +} {58 44 21 64 2 55} +do_test boundary3-2.34.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=58 + ORDER BY x + } +} {55 2 64 21 44 58} +do_test boundary3-2.34.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=58 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58} +do_test boundary3-2.34.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=58 + ORDER BY t1.rowid DESC + } +} {58 44 21 64 2 55} +do_test boundary3-2.35.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-32768 AND t2.a=t1.a + } +} {32 ffffffffffff8000} +do_test boundary3-2.35.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='ffffffffffff8000' + } +} {-32768 32} +do_test boundary3-2.35.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=32 + } +} {-32768 ffffffffffff8000} +do_test boundary3-2.35.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -32768 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary3-2.35.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -32768 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.35.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=32 + ORDER BY t1.rowid + } +} {54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.35.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=32 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54} +do_test boundary3-2.35.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=32 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 54 53 52 33 38} +do_test boundary3-2.35.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=32 + ORDER BY t1.rowid + } +} {54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.35.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=32 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54} +do_test boundary3-2.35.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -32768 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary3-2.35.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -32768 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.35.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=32 + ORDER BY t1.rowid + } +} {32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.35.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=32 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32} +do_test boundary3-2.35.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=32 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 32 54 53 52 33 38} +do_test boundary3-2.35.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=32 + ORDER BY t1.rowid + } +} {32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.35.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=32 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32} +do_test boundary3-2.35.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -32768 ORDER BY t2.a + } +} {1 2 11 21 29 37 44 47 55 58 63 64} +do_test boundary3-2.35.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -32768 ORDER BY t1.a DESC + } +} {64 63 58 55 47 44 37 29 21 11 2 1} +do_test boundary3-2.35.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=32 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary3-2.35.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=32 + ORDER BY t1.rowid DESC + } +} {29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.35.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=32 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary3-2.35.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=32 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary3-2.35.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=32 + ORDER BY t1.rowid DESC + } +} {29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.35.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -32768 ORDER BY t2.a + } +} {1 2 11 21 29 32 37 44 47 55 58 63 64} +do_test boundary3-2.35.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -32768 ORDER BY t1.a DESC + } +} {64 63 58 55 47 44 37 32 29 21 11 2 1} +do_test boundary3-2.35.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=32 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary3-2.35.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=32 + ORDER BY t1.rowid DESC + } +} {32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.35.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=32 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary3-2.35.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=32 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary3-2.35.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=32 + ORDER BY t1.rowid DESC + } +} {32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.36.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=2147483647 AND t2.a=t1.a + } +} {20 000000007fffffff} +do_test boundary3-2.36.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='000000007fffffff' + } +} {2147483647 20} +do_test boundary3-2.36.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=20 + } +} {2147483647 000000007fffffff} +do_test boundary3-2.36.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 2147483647 ORDER BY t2.a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary3-2.36.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 2147483647 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary3-2.36.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=20 + ORDER BY t1.rowid + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.36.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=20 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51} +do_test boundary3-2.36.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=20 + ORDER BY x + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.36.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=20 + ORDER BY t1.rowid + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.36.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=20 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51} +do_test boundary3-2.36.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 2147483647 ORDER BY t2.a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary3-2.36.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 2147483647 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary3-2.36.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=20 + ORDER BY t1.rowid + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.36.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=20 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20} +do_test boundary3-2.36.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=20 + ORDER BY x + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.36.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=20 + ORDER BY t1.rowid + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.36.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=20 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20} +do_test boundary3-2.36.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 2147483647 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.36.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 2147483647 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.36.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=20 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40} +do_test boundary3-2.36.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=20 + ORDER BY t1.rowid DESC + } +} {40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.36.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=20 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.36.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=20 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40} +do_test boundary3-2.36.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=20 + ORDER BY t1.rowid DESC + } +} {40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.36.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 2147483647 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.36.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 2147483647 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.36.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=20 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20} +do_test boundary3-2.36.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=20 + ORDER BY t1.rowid DESC + } +} {20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.36.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=20 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.36.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=20 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20} +do_test boundary3-2.36.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=20 + ORDER BY t1.rowid DESC + } +} {20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.37.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-129 AND t2.a=t1.a + } +} {54 ffffffffffffff7f} +do_test boundary3-2.37.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='ffffffffffffff7f' + } +} {-129 54} +do_test boundary3-2.37.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=54 + } +} {-129 ffffffffffffff7f} +do_test boundary3-2.37.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -129 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 56 57 59 60 61 62} +do_test boundary3-2.37.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -129 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.37.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=54 + ORDER BY t1.rowid + } +} {53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.37.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=54 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53} +do_test boundary3-2.37.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=54 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 53 52 33 38} +do_test boundary3-2.37.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=54 + ORDER BY t1.rowid + } +} {53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.37.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=54 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53} +do_test boundary3-2.37.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -129 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary3-2.37.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -129 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.37.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=54 + ORDER BY t1.rowid + } +} {54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.37.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=54 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54} +do_test boundary3-2.37.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=54 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 54 53 52 33 38} +do_test boundary3-2.37.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=54 + ORDER BY t1.rowid + } +} {54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.37.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=54 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54} +do_test boundary3-2.37.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -129 ORDER BY t2.a + } +} {1 2 11 21 29 32 37 44 47 55 58 63 64} +do_test boundary3-2.37.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -129 ORDER BY t1.a DESC + } +} {64 63 58 55 47 44 37 32 29 21 11 2 1} +do_test boundary3-2.37.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=54 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary3-2.37.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=54 + ORDER BY t1.rowid DESC + } +} {32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.37.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=54 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary3-2.37.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=54 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary3-2.37.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=54 + ORDER BY t1.rowid DESC + } +} {32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.37.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -129 ORDER BY t2.a + } +} {1 2 11 21 29 32 37 44 47 54 55 58 63 64} +do_test boundary3-2.37.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -129 ORDER BY t1.a DESC + } +} {64 63 58 55 54 47 44 37 32 29 21 11 2 1} +do_test boundary3-2.37.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=54 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary3-2.37.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=54 + ORDER BY t1.rowid DESC + } +} {54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.37.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=54 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary3-2.37.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=54 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary3-2.37.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=54 + ORDER BY t1.rowid DESC + } +} {54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.38.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-128 AND t2.a=t1.a + } +} {53 ffffffffffffff80} +do_test boundary3-2.38.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='ffffffffffffff80' + } +} {-128 53} +do_test boundary3-2.38.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=53 + } +} {-128 ffffffffffffff80} +do_test boundary3-2.38.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -128 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 56 57 59 60 61 62} +do_test boundary3-2.38.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -128 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.38.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=53 + ORDER BY t1.rowid + } +} {52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.38.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=53 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52} +do_test boundary3-2.38.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=53 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 52 33 38} +do_test boundary3-2.38.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=53 + ORDER BY t1.rowid + } +} {52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.38.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=53 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52} +do_test boundary3-2.38.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -128 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 56 57 59 60 61 62} +do_test boundary3-2.38.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -128 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.38.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=53 + ORDER BY t1.rowid + } +} {53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.38.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=53 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53} +do_test boundary3-2.38.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=53 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 53 52 33 38} +do_test boundary3-2.38.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=53 + ORDER BY t1.rowid + } +} {53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.38.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=53 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53} +do_test boundary3-2.38.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -128 ORDER BY t2.a + } +} {1 2 11 21 29 32 37 44 47 54 55 58 63 64} +do_test boundary3-2.38.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -128 ORDER BY t1.a DESC + } +} {64 63 58 55 54 47 44 37 32 29 21 11 2 1} +do_test boundary3-2.38.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=53 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary3-2.38.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=53 + ORDER BY t1.rowid DESC + } +} {54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.38.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=53 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary3-2.38.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=53 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary3-2.38.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=53 + ORDER BY t1.rowid DESC + } +} {54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.38.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -128 ORDER BY t2.a + } +} {1 2 11 21 29 32 37 44 47 53 54 55 58 63 64} +do_test boundary3-2.38.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -128 ORDER BY t1.a DESC + } +} {64 63 58 55 54 53 47 44 37 32 29 21 11 2 1} +do_test boundary3-2.38.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=53 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary3-2.38.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=53 + ORDER BY t1.rowid DESC + } +} {53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.38.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=53 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary3-2.38.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=53 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary3-2.38.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=53 + ORDER BY t1.rowid DESC + } +} {53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.39.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=72057594037927936 AND t2.a=t1.a + } +} {28 0100000000000000} +do_test boundary3-2.39.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0100000000000000' + } +} {72057594037927936 28} +do_test boundary3-2.39.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=28 + } +} {72057594037927936 0100000000000000} +do_test boundary3-2.39.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 72057594037927936 ORDER BY t2.a + } +} {3} +do_test boundary3-2.39.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 72057594037927936 ORDER BY t1.a DESC + } +} {3} +do_test boundary3-2.39.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=28 + ORDER BY t1.rowid + } +} {3} +do_test boundary3-2.39.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=28 + ORDER BY t1.rowid DESC + } +} {3} +do_test boundary3-2.39.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=28 + ORDER BY x + } +} {3} +do_test boundary3-2.39.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 72057594037927936 ORDER BY t2.a + } +} {3 28} +do_test boundary3-2.39.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 72057594037927936 ORDER BY t1.a DESC + } +} {28 3} +do_test boundary3-2.39.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=28 + ORDER BY t1.rowid + } +} {28 3} +do_test boundary3-2.39.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=28 + ORDER BY t1.rowid DESC + } +} {3 28} +do_test boundary3-2.39.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=28 + ORDER BY x + } +} {28 3} +do_test boundary3-2.39.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 72057594037927936 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.39.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 72057594037927936 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.39.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=28 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17} +do_test boundary3-2.39.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=28 + ORDER BY t1.rowid DESC + } +} {17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.39.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=28 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.39.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 72057594037927936 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.39.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 72057594037927936 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.39.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=28 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28} +do_test boundary3-2.39.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=28 + ORDER BY t1.rowid DESC + } +} {28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.39.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=28 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.40.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=2147483648 AND t2.a=t1.a + } +} {51 0000000080000000} +do_test boundary3-2.40.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000080000000' + } +} {2147483648 51} +do_test boundary3-2.40.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=51 + } +} {2147483648 0000000080000000} +do_test boundary3-2.40.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 2147483648 ORDER BY t2.a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary3-2.40.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 2147483648 ORDER BY t1.a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary3-2.40.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=51 + ORDER BY t1.rowid + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.40.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=51 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14} +do_test boundary3-2.40.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=51 + ORDER BY x + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.40.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=51 + ORDER BY t1.rowid + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.40.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=51 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14} +do_test boundary3-2.40.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 2147483648 ORDER BY t2.a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary3-2.40.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 2147483648 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary3-2.40.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=51 + ORDER BY t1.rowid + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.40.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=51 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51} +do_test boundary3-2.40.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=51 + ORDER BY x + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.40.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=51 + ORDER BY t1.rowid + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.40.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=51 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51} +do_test boundary3-2.40.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 2147483648 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.40.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 2147483648 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.40.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=51 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20} +do_test boundary3-2.40.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=51 + ORDER BY t1.rowid DESC + } +} {20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.40.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=51 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.40.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=51 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20} +do_test boundary3-2.40.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=51 + ORDER BY t1.rowid DESC + } +} {20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.40.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 2147483648 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.40.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 2147483648 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.40.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=51 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51} +do_test boundary3-2.40.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=51 + ORDER BY t1.rowid DESC + } +} {51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.40.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=51 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.40.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=51 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51} +do_test boundary3-2.40.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=51 + ORDER BY t1.rowid DESC + } +} {51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.41.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=549755813887 AND t2.a=t1.a + } +} {46 0000007fffffffff} +do_test boundary3-2.41.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000007fffffffff' + } +} {549755813887 46} +do_test boundary3-2.41.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=46 + } +} {549755813887 0000007fffffffff} +do_test boundary3-2.41.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 549755813887 ORDER BY t2.a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 56 57} +do_test boundary3-2.41.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 549755813887 ORDER BY t1.a DESC + } +} {57 56 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary3-2.41.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=46 + ORDER BY t1.rowid + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.41.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=46 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35} +do_test boundary3-2.41.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=46 + ORDER BY x + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.41.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=46 + ORDER BY t1.rowid + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.41.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=46 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35} +do_test boundary3-2.41.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 549755813887 ORDER BY t2.a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary3-2.41.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 549755813887 ORDER BY t1.a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary3-2.41.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=46 + ORDER BY t1.rowid + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.41.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=46 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46} +do_test boundary3-2.41.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=46 + ORDER BY x + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.41.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=46 + ORDER BY t1.rowid + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.41.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=46 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46} +do_test boundary3-2.41.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 549755813887 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.41.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 549755813887 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.41.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=46 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22} +do_test boundary3-2.41.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=46 + ORDER BY t1.rowid DESC + } +} {22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.41.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=46 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.41.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=46 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22} +do_test boundary3-2.41.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=46 + ORDER BY t1.rowid DESC + } +} {22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.41.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 549755813887 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.41.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 549755813887 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.41.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=46 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46} +do_test boundary3-2.41.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=46 + ORDER BY t1.rowid DESC + } +} {46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.41.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=46 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.41.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=46 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46} +do_test boundary3-2.41.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=46 + ORDER BY t1.rowid DESC + } +} {46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.42.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-549755813888 AND t2.a=t1.a + } +} {63 ffffff8000000000} +do_test boundary3-2.42.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='ffffff8000000000' + } +} {-549755813888 63} +do_test boundary3-2.42.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=63 + } +} {-549755813888 ffffff8000000000} +do_test boundary3-2.42.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -549755813888 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary3-2.42.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -549755813888 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.42.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=63 + ORDER BY t1.rowid + } +} {47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.42.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=63 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47} +do_test boundary3-2.42.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=63 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.42.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=63 + ORDER BY t1.rowid + } +} {47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.42.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=63 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47} +do_test boundary3-2.42.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -549755813888 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62 63} +do_test boundary3-2.42.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -549755813888 ORDER BY t1.a DESC + } +} {63 62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.42.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=63 + ORDER BY t1.rowid + } +} {63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.42.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=63 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63} +do_test boundary3-2.42.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=63 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.42.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=63 + ORDER BY t1.rowid + } +} {63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.42.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=63 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63} +do_test boundary3-2.42.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -549755813888 ORDER BY t2.a + } +} {2 21 44 55 58 64} +do_test boundary3-2.42.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -549755813888 ORDER BY t1.a DESC + } +} {64 58 55 44 21 2} +do_test boundary3-2.42.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=63 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58} +do_test boundary3-2.42.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=63 + ORDER BY t1.rowid DESC + } +} {58 44 21 64 2 55} +do_test boundary3-2.42.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=63 + ORDER BY x + } +} {55 2 64 21 44 58} +do_test boundary3-2.42.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=63 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58} +do_test boundary3-2.42.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=63 + ORDER BY t1.rowid DESC + } +} {58 44 21 64 2 55} +do_test boundary3-2.42.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -549755813888 ORDER BY t2.a + } +} {2 21 44 55 58 63 64} +do_test boundary3-2.42.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -549755813888 ORDER BY t1.a DESC + } +} {64 63 58 55 44 21 2} +do_test boundary3-2.42.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=63 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63} +do_test boundary3-2.42.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=63 + ORDER BY t1.rowid DESC + } +} {63 58 44 21 64 2 55} +do_test boundary3-2.42.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=63 + ORDER BY x + } +} {55 2 64 21 44 58 63} +do_test boundary3-2.42.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=63 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63} +do_test boundary3-2.42.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=63 + ORDER BY t1.rowid DESC + } +} {63 58 44 21 64 2 55} +do_test boundary3-2.43.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=281474976710655 AND t2.a=t1.a + } +} {10 0000ffffffffffff} +do_test boundary3-2.43.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000ffffffffffff' + } +} {281474976710655 10} +do_test boundary3-2.43.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=10 + } +} {281474976710655 0000ffffffffffff} +do_test boundary3-2.43.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 281474976710655 ORDER BY t2.a + } +} {3 13 17 26 27 28 43 45} +do_test boundary3-2.43.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 281474976710655 ORDER BY t1.a DESC + } +} {45 43 28 27 26 17 13 3} +do_test boundary3-2.43.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=10 + ORDER BY t1.rowid + } +} {26 13 43 27 45 17 28 3} +do_test boundary3-2.43.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=10 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26} +do_test boundary3-2.43.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=10 + ORDER BY x + } +} {26 13 43 27 45 17 28 3} +do_test boundary3-2.43.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 281474976710655 ORDER BY t2.a + } +} {3 10 13 17 26 27 28 43 45} +do_test boundary3-2.43.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 281474976710655 ORDER BY t1.a DESC + } +} {45 43 28 27 26 17 13 10 3} +do_test boundary3-2.43.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=10 + ORDER BY t1.rowid + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary3-2.43.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=10 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10} +do_test boundary3-2.43.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=10 + ORDER BY x + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary3-2.43.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 281474976710655 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.43.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 281474976710655 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary3-2.43.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=10 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34} +do_test boundary3-2.43.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=10 + ORDER BY t1.rowid DESC + } +} {34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.43.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=10 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.43.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 281474976710655 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.43.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 281474976710655 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.43.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=10 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10} +do_test boundary3-2.43.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=10 + ORDER BY t1.rowid DESC + } +} {10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.43.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=10 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.44.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=4398046511103 AND t2.a=t1.a + } +} {7 000003ffffffffff} +do_test boundary3-2.44.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='000003ffffffffff' + } +} {4398046511103 7} +do_test boundary3-2.44.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=7 + } +} {4398046511103 000003ffffffffff} +do_test boundary3-2.44.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 4398046511103 ORDER BY t2.a + } +} {3 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary3-2.44.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 4398046511103 ORDER BY t1.a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 3} +do_test boundary3-2.44.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=7 + ORDER BY t1.rowid + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.44.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=7 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56} +do_test boundary3-2.44.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=7 + ORDER BY x + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.44.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=7 + ORDER BY t1.rowid + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.44.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=7 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56} +do_test boundary3-2.44.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 4398046511103 ORDER BY t2.a + } +} {3 7 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary3-2.44.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 4398046511103 ORDER BY t1.a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 7 3} +do_test boundary3-2.44.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=7 + ORDER BY t1.rowid + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.44.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=7 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7} +do_test boundary3-2.44.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=7 + ORDER BY x + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.44.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=7 + ORDER BY t1.rowid + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.44.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=7 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7} +do_test boundary3-2.44.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 4398046511103 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary3-2.44.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 4398046511103 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.44.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=7 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19} +do_test boundary3-2.44.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=7 + ORDER BY t1.rowid DESC + } +} {19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.44.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=7 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.44.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=7 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19} +do_test boundary3-2.44.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=7 + ORDER BY t1.rowid DESC + } +} {19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.44.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 4398046511103 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary3-2.44.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 4398046511103 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary3-2.44.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=7 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7} +do_test boundary3-2.44.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=7 + ORDER BY t1.rowid DESC + } +} {7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.44.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=7 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.44.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=7 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7} +do_test boundary3-2.44.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=7 + ORDER BY t1.rowid DESC + } +} {7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.45.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=268435455 AND t2.a=t1.a + } +} {12 000000000fffffff} +do_test boundary3-2.45.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='000000000fffffff' + } +} {268435455 12} +do_test boundary3-2.45.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=12 + } +} {268435455 000000000fffffff} +do_test boundary3-2.45.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 268435455 ORDER BY t2.a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary3-2.45.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 268435455 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary3-2.45.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=12 + ORDER BY t1.rowid + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.45.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=12 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40} +do_test boundary3-2.45.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=12 + ORDER BY x + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.45.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=12 + ORDER BY t1.rowid + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.45.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=12 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40} +do_test boundary3-2.45.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 268435455 ORDER BY t2.a + } +} {3 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary3-2.45.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 268435455 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 3} +do_test boundary3-2.45.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=12 + ORDER BY t1.rowid + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.45.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=12 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12} +do_test boundary3-2.45.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=12 + ORDER BY x + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.45.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=12 + ORDER BY t1.rowid + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.45.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=12 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12} +do_test boundary3-2.45.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 268435455 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.45.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 268435455 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 6 5 4 2 1} +do_test boundary3-2.45.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=12 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6} +do_test boundary3-2.45.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=12 + ORDER BY t1.rowid DESC + } +} {6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.45.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=12 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.45.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=12 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6} +do_test boundary3-2.45.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=12 + ORDER BY t1.rowid DESC + } +} {6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.45.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 268435455 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.45.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 268435455 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.45.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=12 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12} +do_test boundary3-2.45.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=12 + ORDER BY t1.rowid DESC + } +} {12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.45.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=12 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.45.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=12 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12} +do_test boundary3-2.45.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=12 + ORDER BY t1.rowid DESC + } +} {12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.46.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-9223372036854775808 AND t2.a=t1.a + } +} {55 8000000000000000} +do_test boundary3-2.46.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='8000000000000000' + } +} {-9223372036854775808 55} +do_test boundary3-2.46.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=55 + } +} {-9223372036854775808 8000000000000000} +do_test boundary3-2.46.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -9223372036854775808 ORDER BY t2.a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.46.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -9223372036854775808 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary3-2.46.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=55 + ORDER BY t1.rowid + } +} {2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.46.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=55 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2} +do_test boundary3-2.46.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=55 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.46.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -9223372036854775808 ORDER BY t2.a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.46.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -9223372036854775808 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary3-2.46.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=55 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.46.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=55 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.46.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=55 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.46.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -9223372036854775808 ORDER BY t2.a + } +} {} +do_test boundary3-2.46.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -9223372036854775808 ORDER BY t1.a DESC + } +} {} +do_test boundary3-2.46.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=55 + ORDER BY t1.rowid + } +} {} +do_test boundary3-2.46.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=55 + ORDER BY t1.rowid DESC + } +} {} +do_test boundary3-2.46.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=55 + ORDER BY x + } +} {} +do_test boundary3-2.46.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -9223372036854775808 ORDER BY t2.a + } +} {55} +do_test boundary3-2.46.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -9223372036854775808 ORDER BY t1.a DESC + } +} {55} +do_test boundary3-2.46.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=55 + ORDER BY t1.rowid + } +} {55} +do_test boundary3-2.46.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=55 + ORDER BY t1.rowid DESC + } +} {55} +do_test boundary3-2.46.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=55 + ORDER BY x + } +} {55} +do_test boundary3-2.47.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=562949953421312 AND t2.a=t1.a + } +} {43 0002000000000000} +do_test boundary3-2.47.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0002000000000000' + } +} {562949953421312 43} +do_test boundary3-2.47.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=43 + } +} {562949953421312 0002000000000000} +do_test boundary3-2.47.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 562949953421312 ORDER BY t2.a + } +} {3 17 27 28 45} +do_test boundary3-2.47.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 562949953421312 ORDER BY t1.a DESC + } +} {45 28 27 17 3} +do_test boundary3-2.47.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=43 + ORDER BY t1.rowid + } +} {27 45 17 28 3} +do_test boundary3-2.47.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=43 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27} +do_test boundary3-2.47.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=43 + ORDER BY x + } +} {27 45 17 28 3} +do_test boundary3-2.47.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 562949953421312 ORDER BY t2.a + } +} {3 17 27 28 43 45} +do_test boundary3-2.47.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 562949953421312 ORDER BY t1.a DESC + } +} {45 43 28 27 17 3} +do_test boundary3-2.47.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=43 + ORDER BY t1.rowid + } +} {43 27 45 17 28 3} +do_test boundary3-2.47.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=43 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43} +do_test boundary3-2.47.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=43 + ORDER BY x + } +} {43 27 45 17 28 3} +do_test boundary3-2.47.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 562949953421312 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.47.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 562949953421312 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.47.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=43 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13} +do_test boundary3-2.47.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=43 + ORDER BY t1.rowid DESC + } +} {13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.47.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=43 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.47.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 562949953421312 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.47.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 562949953421312 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.47.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=43 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43} +do_test boundary3-2.47.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=43 + ORDER BY t1.rowid DESC + } +} {43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.47.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=43 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.48.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-8388609 AND t2.a=t1.a + } +} {1 ffffffffff7fffff} +do_test boundary3-2.48.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='ffffffffff7fffff' + } +} {-8388609 1} +do_test boundary3-2.48.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=1 + } +} {-8388609 ffffffffff7fffff} +do_test boundary3-2.48.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -8388609 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary3-2.48.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -8388609 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.48.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=1 + ORDER BY t1.rowid + } +} {37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.48.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=1 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37} +do_test boundary3-2.48.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=1 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 37 29 32 54 53 52 33 38} +do_test boundary3-2.48.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=1 + ORDER BY t1.rowid + } +} {37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.48.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=1 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37} +do_test boundary3-2.48.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -8388609 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary3-2.48.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -8388609 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.48.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=1 + ORDER BY t1.rowid + } +} {1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.48.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=1 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1} +do_test boundary3-2.48.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=1 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.48.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=1 + ORDER BY t1.rowid + } +} {1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.48.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=1 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1} +do_test boundary3-2.48.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -8388609 ORDER BY t2.a + } +} {2 11 21 44 47 55 58 63 64} +do_test boundary3-2.48.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -8388609 ORDER BY t1.a DESC + } +} {64 63 58 55 47 44 21 11 2} +do_test boundary3-2.48.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=1 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary3-2.48.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=1 + ORDER BY t1.rowid DESC + } +} {11 47 63 58 44 21 64 2 55} +do_test boundary3-2.48.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=1 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary3-2.48.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=1 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary3-2.48.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=1 + ORDER BY t1.rowid DESC + } +} {11 47 63 58 44 21 64 2 55} +do_test boundary3-2.48.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -8388609 ORDER BY t2.a + } +} {1 2 11 21 44 47 55 58 63 64} +do_test boundary3-2.48.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -8388609 ORDER BY t1.a DESC + } +} {64 63 58 55 47 44 21 11 2 1} +do_test boundary3-2.48.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=1 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary3-2.48.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=1 + ORDER BY t1.rowid DESC + } +} {1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.48.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=1 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary3-2.48.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=1 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary3-2.48.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=1 + ORDER BY t1.rowid DESC + } +} {1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.49.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=16777215 AND t2.a=t1.a + } +} {9 0000000000ffffff} +do_test boundary3-2.49.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000000ffffff' + } +} {16777215 9} +do_test boundary3-2.49.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=9 + } +} {16777215 0000000000ffffff} +do_test boundary3-2.49.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 16777215 ORDER BY t2.a + } +} {3 6 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary3-2.49.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 16777215 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 6 3} +do_test boundary3-2.49.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=9 + ORDER BY t1.rowid + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.49.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=9 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6} +do_test boundary3-2.49.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=9 + ORDER BY x + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.49.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=9 + ORDER BY t1.rowid + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.49.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=9 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6} +do_test boundary3-2.49.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 16777215 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary3-2.49.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 16777215 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary3-2.49.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=9 + ORDER BY t1.rowid + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.49.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=9 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9} +do_test boundary3-2.49.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=9 + ORDER BY x + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.49.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=9 + ORDER BY t1.rowid + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.49.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=9 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9} +do_test boundary3-2.49.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 16777215 ORDER BY t2.a + } +} {1 2 4 5 8 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.49.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 16777215 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary3-2.49.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=9 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24} +do_test boundary3-2.49.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=9 + ORDER BY t1.rowid DESC + } +} {24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.49.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=9 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.49.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=9 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24} +do_test boundary3-2.49.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=9 + ORDER BY t1.rowid DESC + } +} {24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.49.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 16777215 ORDER BY t2.a + } +} {1 2 4 5 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.49.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 16777215 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 5 4 2 1} +do_test boundary3-2.49.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=9 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9} +do_test boundary3-2.49.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=9 + ORDER BY t1.rowid DESC + } +} {9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.49.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=9 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.49.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=9 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9} +do_test boundary3-2.49.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=9 + ORDER BY t1.rowid DESC + } +} {9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.50.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=8388608 AND t2.a=t1.a + } +} {24 0000000000800000} +do_test boundary3-2.50.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000000800000' + } +} {8388608 24} +do_test boundary3-2.50.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=24 + } +} {8388608 0000000000800000} +do_test boundary3-2.50.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 8388608 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary3-2.50.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 8388608 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary3-2.50.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=24 + ORDER BY t1.rowid + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.50.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=24 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9} +do_test boundary3-2.50.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=24 + ORDER BY x + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.50.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=24 + ORDER BY t1.rowid + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.50.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=24 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9} +do_test boundary3-2.50.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 8388608 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary3-2.50.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 8388608 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary3-2.50.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=24 + ORDER BY t1.rowid + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.50.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=24 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24} +do_test boundary3-2.50.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=24 + ORDER BY x + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.50.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=24 + ORDER BY t1.rowid + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.50.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=24 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24} +do_test boundary3-2.50.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 8388608 ORDER BY t2.a + } +} {1 2 4 5 8 11 15 16 18 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.50.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 8388608 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary3-2.50.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=24 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18} +do_test boundary3-2.50.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=24 + ORDER BY t1.rowid DESC + } +} {18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.50.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=24 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.50.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=24 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18} +do_test boundary3-2.50.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=24 + ORDER BY t1.rowid DESC + } +} {18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.50.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 8388608 ORDER BY t2.a + } +} {1 2 4 5 8 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.50.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 8388608 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary3-2.50.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=24 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24} +do_test boundary3-2.50.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=24 + ORDER BY t1.rowid DESC + } +} {24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.50.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=24 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.50.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=24 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24} +do_test boundary3-2.50.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=24 + ORDER BY t1.rowid DESC + } +} {24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.51.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=16383 AND t2.a=t1.a + } +} {8 0000000000003fff} +do_test boundary3-2.51.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000000003fff' + } +} {16383 8} +do_test boundary3-2.51.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=8 + } +} {16383 0000000000003fff} +do_test boundary3-2.51.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 16383 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary3-2.51.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 16383 ORDER BY t1.a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 7 6 3} +do_test boundary3-2.51.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=8 + ORDER BY t1.rowid + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.51.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=8 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16} +do_test boundary3-2.51.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=8 + ORDER BY x + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.51.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=8 + ORDER BY t1.rowid + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.51.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=8 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16} +do_test boundary3-2.51.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 16383 ORDER BY t2.a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary3-2.51.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 16383 ORDER BY t1.a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary3-2.51.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=8 + ORDER BY t1.rowid + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.51.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=8 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8} +do_test boundary3-2.51.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=8 + ORDER BY x + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.51.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=8 + ORDER BY t1.rowid + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.51.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=8 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8} +do_test boundary3-2.51.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 16383 ORDER BY t2.a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary3-2.51.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 16383 ORDER BY t1.a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary3-2.51.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=8 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61} +do_test boundary3-2.51.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=8 + ORDER BY t1.rowid DESC + } +} {61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.51.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=8 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.51.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=8 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61} +do_test boundary3-2.51.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=8 + ORDER BY t1.rowid DESC + } +} {61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.51.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 16383 ORDER BY t2.a + } +} {1 2 4 5 8 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary3-2.51.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 16383 ORDER BY t1.a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 8 5 4 2 1} +do_test boundary3-2.51.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=8 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8} +do_test boundary3-2.51.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=8 + ORDER BY t1.rowid DESC + } +} {8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.51.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=8 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.51.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=8 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8} +do_test boundary3-2.51.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=8 + ORDER BY t1.rowid DESC + } +} {8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.52.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=140737488355328 AND t2.a=t1.a + } +} {34 0000800000000000} +do_test boundary3-2.52.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000800000000000' + } +} {140737488355328 34} +do_test boundary3-2.52.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=34 + } +} {140737488355328 0000800000000000} +do_test boundary3-2.52.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 140737488355328 ORDER BY t2.a + } +} {3 10 13 17 26 27 28 43 45} +do_test boundary3-2.52.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 140737488355328 ORDER BY t1.a DESC + } +} {45 43 28 27 26 17 13 10 3} +do_test boundary3-2.52.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=34 + ORDER BY t1.rowid + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary3-2.52.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=34 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10} +do_test boundary3-2.52.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=34 + ORDER BY x + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary3-2.52.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 140737488355328 ORDER BY t2.a + } +} {3 10 13 17 26 27 28 34 43 45} +do_test boundary3-2.52.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 140737488355328 ORDER BY t1.a DESC + } +} {45 43 34 28 27 26 17 13 10 3} +do_test boundary3-2.52.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=34 + ORDER BY t1.rowid + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.52.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=34 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34} +do_test boundary3-2.52.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=34 + ORDER BY x + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.52.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 140737488355328 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.52.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 140737488355328 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary3-2.52.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=34 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25} +do_test boundary3-2.52.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=34 + ORDER BY t1.rowid DESC + } +} {25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.52.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=34 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.52.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 140737488355328 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.52.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 140737488355328 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary3-2.52.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=34 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34} +do_test boundary3-2.52.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=34 + ORDER BY t1.rowid DESC + } +} {34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.52.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=34 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.53.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=2097151 AND t2.a=t1.a + } +} {15 00000000001fffff} +do_test boundary3-2.53.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='00000000001fffff' + } +} {2097151 15} +do_test boundary3-2.53.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=15 + } +} {2097151 00000000001fffff} +do_test boundary3-2.53.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 2097151 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary3-2.53.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 2097151 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary3-2.53.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=15 + ORDER BY t1.rowid + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.53.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=15 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42} +do_test boundary3-2.53.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=15 + ORDER BY x + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.53.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=15 + ORDER BY t1.rowid + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.53.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=15 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42} +do_test boundary3-2.53.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 2097151 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary3-2.53.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 2097151 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary3-2.53.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=15 + ORDER BY t1.rowid + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.53.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=15 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15} +do_test boundary3-2.53.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=15 + ORDER BY x + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.53.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=15 + ORDER BY t1.rowid + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.53.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=15 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15} +do_test boundary3-2.53.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 2097151 ORDER BY t2.a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.53.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 2097151 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary3-2.53.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=15 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62} +do_test boundary3-2.53.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=15 + ORDER BY t1.rowid DESC + } +} {62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.53.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=15 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.53.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=15 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62} +do_test boundary3-2.53.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=15 + ORDER BY t1.rowid DESC + } +} {62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.53.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 2097151 ORDER BY t2.a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.53.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 2097151 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary3-2.53.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=15 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15} +do_test boundary3-2.53.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=15 + ORDER BY t1.rowid DESC + } +} {15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.53.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=15 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.53.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=15 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15} +do_test boundary3-2.53.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=15 + ORDER BY t1.rowid DESC + } +} {15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.54.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=140737488355327 AND t2.a=t1.a + } +} {25 00007fffffffffff} +do_test boundary3-2.54.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='00007fffffffffff' + } +} {140737488355327 25} +do_test boundary3-2.54.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=25 + } +} {140737488355327 00007fffffffffff} +do_test boundary3-2.54.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 140737488355327 ORDER BY t2.a + } +} {3 10 13 17 26 27 28 34 43 45} +do_test boundary3-2.54.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 140737488355327 ORDER BY t1.a DESC + } +} {45 43 34 28 27 26 17 13 10 3} +do_test boundary3-2.54.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=25 + ORDER BY t1.rowid + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.54.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=25 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34} +do_test boundary3-2.54.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=25 + ORDER BY x + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.54.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 140737488355327 ORDER BY t2.a + } +} {3 10 13 17 25 26 27 28 34 43 45} +do_test boundary3-2.54.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 140737488355327 ORDER BY t1.a DESC + } +} {45 43 34 28 27 26 25 17 13 10 3} +do_test boundary3-2.54.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=25 + ORDER BY t1.rowid + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.54.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=25 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25} +do_test boundary3-2.54.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=25 + ORDER BY x + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.54.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 140737488355327 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.54.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 140737488355327 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary3-2.54.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=25 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56} +do_test boundary3-2.54.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=25 + ORDER BY t1.rowid DESC + } +} {56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.54.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=25 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.54.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 140737488355327 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.54.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 140737488355327 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary3-2.54.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=25 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25} +do_test boundary3-2.54.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=25 + ORDER BY t1.rowid DESC + } +} {25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.54.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=25 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.55.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=281474976710656 AND t2.a=t1.a + } +} {26 0001000000000000} +do_test boundary3-2.55.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0001000000000000' + } +} {281474976710656 26} +do_test boundary3-2.55.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=26 + } +} {281474976710656 0001000000000000} +do_test boundary3-2.55.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 281474976710656 ORDER BY t2.a + } +} {3 13 17 27 28 43 45} +do_test boundary3-2.55.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 281474976710656 ORDER BY t1.a DESC + } +} {45 43 28 27 17 13 3} +do_test boundary3-2.55.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=26 + ORDER BY t1.rowid + } +} {13 43 27 45 17 28 3} +do_test boundary3-2.55.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=26 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13} +do_test boundary3-2.55.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=26 + ORDER BY x + } +} {13 43 27 45 17 28 3} +do_test boundary3-2.55.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 281474976710656 ORDER BY t2.a + } +} {3 13 17 26 27 28 43 45} +do_test boundary3-2.55.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 281474976710656 ORDER BY t1.a DESC + } +} {45 43 28 27 26 17 13 3} +do_test boundary3-2.55.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=26 + ORDER BY t1.rowid + } +} {26 13 43 27 45 17 28 3} +do_test boundary3-2.55.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=26 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26} +do_test boundary3-2.55.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=26 + ORDER BY x + } +} {26 13 43 27 45 17 28 3} +do_test boundary3-2.55.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 281474976710656 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.55.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 281474976710656 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.55.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=26 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10} +do_test boundary3-2.55.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=26 + ORDER BY t1.rowid DESC + } +} {10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.55.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=26 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.55.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 281474976710656 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.55.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 281474976710656 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.55.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=26 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26} +do_test boundary3-2.55.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=26 + ORDER BY t1.rowid DESC + } +} {26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.55.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=26 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.56.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=32767 AND t2.a=t1.a + } +} {23 0000000000007fff} +do_test boundary3-2.56.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000000007fff' + } +} {32767 23} +do_test boundary3-2.56.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=23 + } +} {32767 0000000000007fff} +do_test boundary3-2.56.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 32767 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary3-2.56.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 32767 ORDER BY t1.a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary3-2.56.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=23 + ORDER BY t1.rowid + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.56.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=23 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50} +do_test boundary3-2.56.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=23 + ORDER BY x + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.56.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=23 + ORDER BY t1.rowid + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.56.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=23 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50} +do_test boundary3-2.56.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 32767 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary3-2.56.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 32767 ORDER BY t1.a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary3-2.56.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=23 + ORDER BY t1.rowid + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.56.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=23 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23} +do_test boundary3-2.56.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=23 + ORDER BY x + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.56.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=23 + ORDER BY t1.rowid + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.56.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=23 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23} +do_test boundary3-2.56.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 32767 ORDER BY t2.a + } +} {1 2 4 5 8 11 16 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary3-2.56.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 32767 ORDER BY t1.a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 16 11 8 5 4 2 1} +do_test boundary3-2.56.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=23 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16} +do_test boundary3-2.56.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=23 + ORDER BY t1.rowid DESC + } +} {16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.56.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=23 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.56.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=23 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16} +do_test boundary3-2.56.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=23 + ORDER BY t1.rowid DESC + } +} {16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.56.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 32767 ORDER BY t2.a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary3-2.56.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 32767 ORDER BY t1.a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary3-2.56.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=23 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23} +do_test boundary3-2.56.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=23 + ORDER BY t1.rowid DESC + } +} {23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.56.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=23 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.56.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=23 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23} +do_test boundary3-2.56.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=23 + ORDER BY t1.rowid DESC + } +} {23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.57.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=127 AND t2.a=t1.a + } +} {4 000000000000007f} +do_test boundary3-2.57.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='000000000000007f' + } +} {127 4} +do_test boundary3-2.57.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=4 + } +} {127 000000000000007f} +do_test boundary3-2.57.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 127 ORDER BY t2.a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary3-2.57.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 127 ORDER BY t1.a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary3-2.57.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=4 + ORDER BY t1.rowid + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.57.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=4 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49} +do_test boundary3-2.57.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=4 + ORDER BY x + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.57.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=4 + ORDER BY t1.rowid + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.57.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=4 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49} +do_test boundary3-2.57.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 127 ORDER BY t2.a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary3-2.57.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 127 ORDER BY t1.a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary3-2.57.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=4 + ORDER BY t1.rowid + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.57.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=4 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4} +do_test boundary3-2.57.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=4 + ORDER BY x + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.57.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=4 + ORDER BY t1.rowid + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.57.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=4 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4} +do_test boundary3-2.57.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 127 ORDER BY t2.a + } +} {1 2 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary3-2.57.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 127 ORDER BY t1.a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 2 1} +do_test boundary3-2.57.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=4 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31} +do_test boundary3-2.57.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=4 + ORDER BY t1.rowid DESC + } +} {31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.57.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=4 + ORDER BY x + } +} {59 60 41 5 31 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.57.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=4 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31} +do_test boundary3-2.57.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=4 + ORDER BY t1.rowid DESC + } +} {31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.57.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 127 ORDER BY t2.a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary3-2.57.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 127 ORDER BY t1.a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary3-2.57.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=4 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4} +do_test boundary3-2.57.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=4 + ORDER BY t1.rowid DESC + } +} {4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.57.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=4 + ORDER BY x + } +} {59 60 41 5 31 4 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.57.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=4 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4} +do_test boundary3-2.57.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=4 + ORDER BY t1.rowid DESC + } +} {4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.58.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=36028797018963967 AND t2.a=t1.a + } +} {27 007fffffffffffff} +do_test boundary3-2.58.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='007fffffffffffff' + } +} {36028797018963967 27} +do_test boundary3-2.58.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=27 + } +} {36028797018963967 007fffffffffffff} +do_test boundary3-2.58.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 36028797018963967 ORDER BY t2.a + } +} {3 17 28 45} +do_test boundary3-2.58.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 36028797018963967 ORDER BY t1.a DESC + } +} {45 28 17 3} +do_test boundary3-2.58.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=27 + ORDER BY t1.rowid + } +} {45 17 28 3} +do_test boundary3-2.58.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=27 + ORDER BY t1.rowid DESC + } +} {3 28 17 45} +do_test boundary3-2.58.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=27 + ORDER BY x + } +} {45 17 28 3} +do_test boundary3-2.58.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 36028797018963967 ORDER BY t2.a + } +} {3 17 27 28 45} +do_test boundary3-2.58.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 36028797018963967 ORDER BY t1.a DESC + } +} {45 28 27 17 3} +do_test boundary3-2.58.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=27 + ORDER BY t1.rowid + } +} {27 45 17 28 3} +do_test boundary3-2.58.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=27 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27} +do_test boundary3-2.58.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=27 + ORDER BY x + } +} {27 45 17 28 3} +do_test boundary3-2.58.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 36028797018963967 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.58.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 36028797018963967 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.58.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=27 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43} +do_test boundary3-2.58.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=27 + ORDER BY t1.rowid DESC + } +} {43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.58.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=27 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.58.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 36028797018963967 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.58.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 36028797018963967 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.58.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=27 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27} +do_test boundary3-2.58.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=27 + ORDER BY t1.rowid DESC + } +} {27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.58.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=27 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.59.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=4398046511104 AND t2.a=t1.a + } +} {56 0000040000000000} +do_test boundary3-2.59.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000040000000000' + } +} {4398046511104 56} +do_test boundary3-2.59.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=56 + } +} {4398046511104 0000040000000000} +do_test boundary3-2.59.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 4398046511104 ORDER BY t2.a + } +} {3 10 13 17 25 26 27 28 34 43 45} +do_test boundary3-2.59.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 4398046511104 ORDER BY t1.a DESC + } +} {45 43 34 28 27 26 25 17 13 10 3} +do_test boundary3-2.59.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=56 + ORDER BY t1.rowid + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.59.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=56 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25} +do_test boundary3-2.59.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=56 + ORDER BY x + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.59.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=56 + ORDER BY t1.rowid + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.59.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=56 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25} +do_test boundary3-2.59.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 4398046511104 ORDER BY t2.a + } +} {3 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary3-2.59.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 4398046511104 ORDER BY t1.a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 3} +do_test boundary3-2.59.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=56 + ORDER BY t1.rowid + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.59.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=56 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56} +do_test boundary3-2.59.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=56 + ORDER BY x + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.59.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=56 + ORDER BY t1.rowid + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.59.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=56 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56} +do_test boundary3-2.59.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 4398046511104 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary3-2.59.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 4398046511104 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary3-2.59.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=56 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7} +do_test boundary3-2.59.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=56 + ORDER BY t1.rowid DESC + } +} {7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.59.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=56 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.59.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=56 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7} +do_test boundary3-2.59.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=56 + ORDER BY t1.rowid DESC + } +} {7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.59.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 4398046511104 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.59.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 4398046511104 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary3-2.59.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=56 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56} +do_test boundary3-2.59.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=56 + ORDER BY t1.rowid DESC + } +} {56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.59.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=56 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.59.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=56 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56} +do_test boundary3-2.59.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=56 + ORDER BY t1.rowid DESC + } +} {56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.60.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=1 AND t2.a=t1.a + } +} {60 0000000000000001} +do_test boundary3-2.60.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000000000001' + } +} {1 60} +do_test boundary3-2.60.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=60 + } +} {1 0000000000000001} +do_test boundary3-2.60.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 1 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary3-2.60.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 1 ORDER BY t1.a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.60.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=60 + ORDER BY t1.rowid + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.60.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=60 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41} +do_test boundary3-2.60.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=60 + ORDER BY x + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.60.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=60 + ORDER BY t1.rowid + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.60.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=60 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41} +do_test boundary3-2.60.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 1 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 60 61 62} +do_test boundary3-2.60.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 1 ORDER BY t1.a DESC + } +} {62 61 60 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.60.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=60 + ORDER BY t1.rowid + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.60.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=60 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60} +do_test boundary3-2.60.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=60 + ORDER BY x + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.60.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=60 + ORDER BY t1.rowid + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.60.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=60 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60} +do_test boundary3-2.60.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 1 ORDER BY t2.a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 63 64} +do_test boundary3-2.60.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 1 ORDER BY t1.a DESC + } +} {64 63 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary3-2.60.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=60 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59} +do_test boundary3-2.60.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=60 + ORDER BY t1.rowid DESC + } +} {59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.60.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=60 + ORDER BY x + } +} {59 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.60.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=60 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59} +do_test boundary3-2.60.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=60 + ORDER BY t1.rowid DESC + } +} {59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.60.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 1 ORDER BY t2.a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary3-2.60.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 1 ORDER BY t1.a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary3-2.60.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=60 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60} +do_test boundary3-2.60.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=60 + ORDER BY t1.rowid DESC + } +} {60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.60.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=60 + ORDER BY x + } +} {59 60 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.60.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=60 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60} +do_test boundary3-2.60.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=60 + ORDER BY t1.rowid DESC + } +} {60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.61.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=36028797018963968 AND t2.a=t1.a + } +} {45 0080000000000000} +do_test boundary3-2.61.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0080000000000000' + } +} {36028797018963968 45} +do_test boundary3-2.61.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=45 + } +} {36028797018963968 0080000000000000} +do_test boundary3-2.61.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 36028797018963968 ORDER BY t2.a + } +} {3 17 28} +do_test boundary3-2.61.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 36028797018963968 ORDER BY t1.a DESC + } +} {28 17 3} +do_test boundary3-2.61.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=45 + ORDER BY t1.rowid + } +} {17 28 3} +do_test boundary3-2.61.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=45 + ORDER BY t1.rowid DESC + } +} {3 28 17} +do_test boundary3-2.61.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=45 + ORDER BY x + } +} {17 28 3} +do_test boundary3-2.61.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 36028797018963968 ORDER BY t2.a + } +} {3 17 28 45} +do_test boundary3-2.61.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 36028797018963968 ORDER BY t1.a DESC + } +} {45 28 17 3} +do_test boundary3-2.61.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=45 + ORDER BY t1.rowid + } +} {45 17 28 3} +do_test boundary3-2.61.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=45 + ORDER BY t1.rowid DESC + } +} {3 28 17 45} +do_test boundary3-2.61.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=45 + ORDER BY x + } +} {45 17 28 3} +do_test boundary3-2.61.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 36028797018963968 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.61.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 36028797018963968 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.61.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=45 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27} +do_test boundary3-2.61.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=45 + ORDER BY t1.rowid DESC + } +} {27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.61.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=45 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.61.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 36028797018963968 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.61.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 36028797018963968 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.61.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=45 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45} +do_test boundary3-2.61.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=45 + ORDER BY t1.rowid DESC + } +} {45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.61.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=45 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.62.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-2147483649 AND t2.a=t1.a + } +} {47 ffffffff7fffffff} +do_test boundary3-2.62.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='ffffffff7fffffff' + } +} {-2147483649 47} +do_test boundary3-2.62.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=47 + } +} {-2147483649 ffffffff7fffffff} +do_test boundary3-2.62.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -2147483649 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary3-2.62.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -2147483649 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.62.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=47 + ORDER BY t1.rowid + } +} {11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.62.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=47 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11} +do_test boundary3-2.62.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=47 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.62.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=47 + ORDER BY t1.rowid + } +} {11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.62.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=47 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11} +do_test boundary3-2.62.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -2147483649 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary3-2.62.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -2147483649 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.62.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=47 + ORDER BY t1.rowid + } +} {47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.62.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=47 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47} +do_test boundary3-2.62.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=47 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.62.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=47 + ORDER BY t1.rowid + } +} {47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.62.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=47 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47} +do_test boundary3-2.62.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -2147483649 ORDER BY t2.a + } +} {2 21 44 55 58 63 64} +do_test boundary3-2.62.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -2147483649 ORDER BY t1.a DESC + } +} {64 63 58 55 44 21 2} +do_test boundary3-2.62.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=47 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63} +do_test boundary3-2.62.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=47 + ORDER BY t1.rowid DESC + } +} {63 58 44 21 64 2 55} +do_test boundary3-2.62.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=47 + ORDER BY x + } +} {55 2 64 21 44 58 63} +do_test boundary3-2.62.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=47 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63} +do_test boundary3-2.62.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=47 + ORDER BY t1.rowid DESC + } +} {63 58 44 21 64 2 55} +do_test boundary3-2.62.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -2147483649 ORDER BY t2.a + } +} {2 21 44 47 55 58 63 64} +do_test boundary3-2.62.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -2147483649 ORDER BY t1.a DESC + } +} {64 63 58 55 47 44 21 2} +do_test boundary3-2.62.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=47 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47} +do_test boundary3-2.62.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=47 + ORDER BY t1.rowid DESC + } +} {47 63 58 44 21 64 2 55} +do_test boundary3-2.62.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=47 + ORDER BY x + } +} {55 2 64 21 44 58 63 47} +do_test boundary3-2.62.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=47 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47} +do_test boundary3-2.62.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=47 + ORDER BY t1.rowid DESC + } +} {47 63 58 44 21 64 2 55} +do_test boundary3-2.63.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-36028797018963969 AND t2.a=t1.a + } +} {2 ff7fffffffffffff} +do_test boundary3-2.63.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='ff7fffffffffffff' + } +} {-36028797018963969 2} +do_test boundary3-2.63.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=2 + } +} {-36028797018963969 ff7fffffffffffff} +do_test boundary3-2.63.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -36028797018963969 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.63.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -36028797018963969 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.63.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=2 + ORDER BY t1.rowid + } +} {64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.63.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=2 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64} +do_test boundary3-2.63.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=2 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.63.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -36028797018963969 ORDER BY t2.a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.63.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -36028797018963969 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary3-2.63.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=2 + ORDER BY t1.rowid + } +} {2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.63.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=2 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2} +do_test boundary3-2.63.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=2 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.63.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -36028797018963969 ORDER BY t2.a + } +} {55} +do_test boundary3-2.63.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -36028797018963969 ORDER BY t1.a DESC + } +} {55} +do_test boundary3-2.63.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=2 + ORDER BY t1.rowid + } +} {55} +do_test boundary3-2.63.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=2 + ORDER BY t1.rowid DESC + } +} {55} +do_test boundary3-2.63.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=2 + ORDER BY x + } +} {55} +do_test boundary3-2.63.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -36028797018963969 ORDER BY t2.a + } +} {2 55} +do_test boundary3-2.63.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -36028797018963969 ORDER BY t1.a DESC + } +} {55 2} +do_test boundary3-2.63.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=2 + ORDER BY t1.rowid + } +} {55 2} +do_test boundary3-2.63.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=2 + ORDER BY t1.rowid DESC + } +} {2 55} +do_test boundary3-2.63.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=2 + ORDER BY x + } +} {55 2} +do_test boundary3-2.64.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=3 AND t2.a=t1.a + } +} {5 0000000000000003} +do_test boundary3-2.64.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000000000003' + } +} {3 5} +do_test boundary3-2.64.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=5 + } +} {3 0000000000000003} +do_test boundary3-2.64.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 3 ORDER BY t2.a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary3-2.64.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 3 ORDER BY t1.a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary3-2.64.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=5 + ORDER BY t1.rowid + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.64.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=5 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31} +do_test boundary3-2.64.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=5 + ORDER BY x + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.64.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=5 + ORDER BY t1.rowid + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.64.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=5 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31} +do_test boundary3-2.64.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 3 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary3-2.64.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 3 ORDER BY t1.a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.64.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=5 + ORDER BY t1.rowid + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.64.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=5 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5} +do_test boundary3-2.64.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=5 + ORDER BY x + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.64.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=5 + ORDER BY t1.rowid + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.64.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=5 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5} +do_test boundary3-2.64.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 3 ORDER BY t2.a + } +} {1 2 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary3-2.64.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 3 ORDER BY t1.a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 2 1} +do_test boundary3-2.64.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=5 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41} +do_test boundary3-2.64.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=5 + ORDER BY t1.rowid DESC + } +} {41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.64.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=5 + ORDER BY x + } +} {59 60 41 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.64.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=5 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41} +do_test boundary3-2.64.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=5 + ORDER BY t1.rowid DESC + } +} {41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.64.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 3 ORDER BY t2.a + } +} {1 2 5 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary3-2.64.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 3 ORDER BY t1.a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 5 2 1} +do_test boundary3-2.64.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=5 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5} +do_test boundary3-2.64.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=5 + ORDER BY t1.rowid DESC + } +} {5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.64.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=5 + ORDER BY x + } +} {59 60 41 5 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.64.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=5 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5} +do_test boundary3-2.64.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=5 + ORDER BY t1.rowid DESC + } +} {5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.65.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 9.22337303685477580800e+18 ORDER BY t2.a + } +} {} +do_test boundary3-2.65.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 9.22337303685477580800e+18 ORDER BY t1.a DESC + } +} {} +do_test boundary3-2.65.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=65 + ORDER BY t1.rowid + } +} {} +do_test boundary3-2.65.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=65 + ORDER BY t1.rowid DESC + } +} {} +do_test boundary3-2.65.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=65 + ORDER BY x + } +} {} +do_test boundary3-2.65.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 9.22337303685477580800e+18 ORDER BY t2.a + } +} {} +do_test boundary3-2.65.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 9.22337303685477580800e+18 ORDER BY t1.a DESC + } +} {} +do_test boundary3-2.65.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=65 + ORDER BY t1.rowid + } +} {} +do_test boundary3-2.65.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=65 + ORDER BY t1.rowid DESC + } +} {} +do_test boundary3-2.65.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=65 + ORDER BY x + } +} {} +do_test boundary3-2.65.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 9.22337303685477580800e+18 ORDER BY t2.a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.65.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 9.22337303685477580800e+18 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary3-2.65.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=65 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.65.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=65 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.65.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=65 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.65.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 9.22337303685477580800e+18 ORDER BY t2.a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.65.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 9.22337303685477580800e+18 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary3-2.65.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=65 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.65.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=65 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.65.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=65 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.66.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -9.22337303685477580800e+18 ORDER BY t2.a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.66.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -9.22337303685477580800e+18 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary3-2.66.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=66 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.66.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=66 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.66.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=66 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.66.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -9.22337303685477580800e+18 ORDER BY t2.a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.66.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -9.22337303685477580800e+18 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary3-2.66.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=66 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.66.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=66 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.66.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=66 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.66.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -9.22337303685477580800e+18 ORDER BY t2.a + } +} {} +do_test boundary3-2.66.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -9.22337303685477580800e+18 ORDER BY t1.a DESC + } +} {} +do_test boundary3-2.66.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=66 + ORDER BY t1.rowid + } +} {} +do_test boundary3-2.66.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=66 + ORDER BY t1.rowid DESC + } +} {} +do_test boundary3-2.66.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=66 + ORDER BY x + } +} {} +do_test boundary3-2.66.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -9.22337303685477580800e+18 ORDER BY t2.a + } +} {} +do_test boundary3-2.66.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -9.22337303685477580800e+18 ORDER BY t1.a DESC + } +} {} +do_test boundary3-2.66.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=66 + ORDER BY t1.rowid + } +} {} +do_test boundary3-2.66.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=66 + ORDER BY t1.rowid DESC + } +} {} +do_test boundary3-2.66.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=66 + ORDER BY x + } +} {} +finish_test diff --git a/test/boundary4.tcl b/test/boundary4.tcl new file mode 100644 index 0000000..20f5c96 --- /dev/null +++ b/test/boundary4.tcl @@ -0,0 +1,340 @@ +puts {# 2008 December 11 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file is automatically generated from a separate TCL script. +# This file seeks to exercise integer boundary values. +# +# $Id: boundary4.tcl,v 1.3 2009/01/02 15:45:48 shane Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Many of the boundary tests depend on a working 64-bit implementation. +if {![working_64bit_int]} { finish_test; return } +ifcapable !altertable { finish_test; return } +} + +expr srand(0) + +# Generate interesting boundary numbers +# +foreach x { + 0x7f + 0x7fff + 0x7fffff + 0x7fffffff + 0x7fffffffff + 0x7fffffffffff + 0x7fffffffffffff + 0x7fffffffffffffff +} { + set x [expr {wide($x)}] + set boundarynum($x) 1 + set boundarynum([expr {$x+1}]) 1 + set boundarynum([expr {-($x+1)}]) 1 + set boundarynum([expr {-($x+2)}]) 1 + set boundarynum([expr {$x+$x+1}]) 1 + set boundarynum([expr {$x+$x+2}]) 1 +} +set x [expr {wide(127)}] +for {set i 127} {$i<=9} {incr i} { + set boundarynum($x) 1 + set boundarynum([expr {$x+1}]) 1 + set x [expr {wide($x*128 + 127)}] +} + +# Scramble the $inlist into a random order. +# +proc scramble {inlist} { + set y {} + foreach x $inlist { + lappend y [list [expr {rand()}] $x] + } + set y [lsort $y] + set outlist {} + foreach x $y { + lappend outlist [lindex $x 1] + } + return $outlist +} + +# A simple selection sort. Not trying to be efficient. +# +proc sort {inlist} { + set outlist {} + set mn [lindex $inlist 0] + foreach x $inlist { + if {$x<$mn} {set mn $x} + } + set outlist $mn + set mx $mn + while {1} { + set valid 0 + foreach x $inlist { + if {$x>$mx && (!$valid || $mn>$x)} { + set mn $x + set valid 1 + } + } + if {!$valid} break + lappend outlist $mn + set mx $mn + } + return $outlist +} + +# Reverse the order of a list +# +proc reverse {inlist} { + set i [llength $inlist] + set outlist {} + for {incr i -1} {$i>=0} {incr i -1} { + lappend outlist [lindex $inlist $i] + } + return $outlist +} + +set nums1 [scramble [array names boundarynum]] +set nums2 [scramble [array names boundarynum]] + +set tname boundary4 +puts "do_test $tname-1.1 \173" +puts " db eval \173" +puts " CREATE TABLE t1(a,x);" +set a 0 +set all_rowid {} +set all_a {} +set all_x {} +foreach r $nums1 { + incr a + set t1ra($r) $a + set t1ar($a) $r + set x [format %08x%08x [expr {wide($r)>>32}] $r] + set t1rx($r) $x + set t1xr($x) $r + puts " INSERT INTO t1(oid,a,x) VALUES($r,$a,'$x');" + lappend all_rowid $r + lappend all_a $a + lappend all_x $x +} +puts " CREATE INDEX t1i1 ON t1(a);" +puts " CREATE INDEX t1i2 ON t1(x);" +puts " \175" +puts "\175 {}" + +puts "do_test $tname-1.2 \173" +puts " db eval \173" +puts " SELECT count(*) FROM t1" +puts " \175" +puts "\175 {[llength $nums1]}" + +proc maketest {tnum sql answer} { + puts "do_test $::tname-$tnum \173" + puts " db eval \173" + puts " $sql" + puts " \175" + puts "\175 {$answer}" +} + +set ans {} +foreach r [sort $all_rowid] { + lappend ans $r $t1ra($r) $t1rx($r) +} +maketest 1.3 {SELECT rowid, a, x FROM t1 ORDER BY +rowid} $ans +maketest 1.4 {SELECT rowid, a, x FROM t1 ORDER BY rowid} $ans + +set ans {} +foreach r [reverse [sort $all_rowid]] { + lappend ans $r $t1ra($r) $t1rx($r) +} +maketest 1.5 {SELECT rowid, a, x FROM t1 ORDER BY +rowid DESC} $ans +maketest 1.6 {SELECT rowid, a, x FROM t1 ORDER BY rowid DESC} $ans + +set ans {} +foreach a [sort $all_a] { + set r $t1ar($a) + lappend ans $r $a $t1rx($r) +} +maketest 1.7 {SELECT rowid, a, x FROM t1 ORDER BY +a} $ans +maketest 1.8 {SELECT rowid, a, x FROM t1 ORDER BY a} $ans + +set ans {} +foreach a [reverse [sort $all_a]] { + set r $t1ar($a) + lappend ans $r $a $t1rx($r) +} +maketest 1.9 {SELECT rowid, a, x FROM t1 ORDER BY +a DESC} $ans +maketest 1.10 {SELECT rowid, a, x FROM t1 ORDER BY a DESC} $ans + +set ans {} +foreach x [sort $all_x] { + set r $t1xr($x) + lappend ans $r $t1ra($r) $x +} +maketest 1.11 {SELECT rowid, a, x FROM t1 ORDER BY +x} $ans +maketest 1.12 {SELECT rowid, a, x FROM t1 ORDER BY x} $ans + +set ans {} +foreach x [reverse [sort $all_x]] { + set r $t1xr($x) + lappend ans $r $t1ra($r) $x +} +maketest 1.13 {SELECT rowid, a, x FROM t1 ORDER BY +x DESC} $ans +maketest 1.14 {SELECT rowid, a, x FROM t1 ORDER BY x DESC} $ans + +maketest 2.1 {UPDATE t1 SET rowid=a, a=rowid} {} + +set ans {} +foreach r [sort $all_rowid] { + lappend ans $r $t1ra($r) $t1rx($r) +} +maketest 2.3 {SELECT a, rowid, x FROM t1 ORDER BY +a} $ans +maketest 2.4 {SELECT a, rowid, x FROM t1 ORDER BY a} $ans + +set ans {} +foreach r [reverse [sort $all_rowid]] { + lappend ans $r $t1ra($r) $t1rx($r) +} +maketest 2.5 {SELECT a, rowid, x FROM t1 ORDER BY +a DESC} $ans +maketest 2.6 {SELECT a, rowid, x FROM t1 ORDER BY a DESC} $ans + +set ans {} +foreach a [sort $all_a] { + set r $t1ar($a) + lappend ans $r $a $t1rx($r) +} +maketest 2.7 {SELECT a, rowid, x FROM t1 ORDER BY +rowid} $ans +maketest 2.8 {SELECT a, rowid, x FROM t1 ORDER BY rowid} $ans + +set ans {} +foreach a [reverse [sort $all_a]] { + set r $t1ar($a) + lappend ans $r $a $t1rx($r) +} +maketest 2.9 {SELECT a, rowid, x FROM t1 ORDER BY +rowid DESC} $ans +maketest 2.10 {SELECT a, rowid, x FROM t1 ORDER BY rowid DESC} $ans + +set ans {} +foreach x [sort $all_x] { + set r $t1xr($x) + lappend ans $r $t1ra($r) $x +} +maketest 2.11 {SELECT a, rowid, x FROM t1 ORDER BY +x} $ans +maketest 2.12 {SELECT a, rowid, x FROM t1 ORDER BY x} $ans + +set ans {} +foreach x [reverse [sort $all_x]] { + set r $t1xr($x) + lappend ans $r $t1ra($r) $x +} +maketest 2.13 {SELECT a, rowid, x FROM t1 ORDER BY +x DESC} $ans +maketest 2.14 {SELECT a, rowid, x FROM t1 ORDER BY x DESC} $ans + +maketest 3.1 {UPDATE t1 SET rowid=a, a=rowid} {} +maketest 3.2 {ALTER TABLE t1 ADD COLUMN z; UPDATE t1 SET z=zeroblob(600)} {} + +set ans {} +foreach r [sort $all_rowid] { + lappend ans $r $t1ra($r) $t1rx($r) +} +maketest 3.3 {SELECT rowid, a, x FROM t1 ORDER BY +rowid} $ans +maketest 3.4 {SELECT rowid, a, x FROM t1 ORDER BY rowid} $ans + +set ans {} +foreach r [reverse [sort $all_rowid]] { + lappend ans $r $t1ra($r) $t1rx($r) +} +maketest 3.5 {SELECT rowid, a, x FROM t1 ORDER BY +rowid DESC} $ans +maketest 3.6 {SELECT rowid, a, x FROM t1 ORDER BY rowid DESC} $ans + +set ans {} +foreach a [sort $all_a] { + set r $t1ar($a) + lappend ans $r $a $t1rx($r) +} +maketest 3.7 {SELECT rowid, a, x FROM t1 ORDER BY +a} $ans +maketest 3.8 {SELECT rowid, a, x FROM t1 ORDER BY a} $ans + +set ans {} +foreach a [reverse [sort $all_a]] { + set r $t1ar($a) + lappend ans $r $a $t1rx($r) +} +maketest 3.9 {SELECT rowid, a, x FROM t1 ORDER BY +a DESC} $ans +maketest 3.10 {SELECT rowid, a, x FROM t1 ORDER BY a DESC} $ans + +set ans {} +foreach x [sort $all_x] { + set r $t1xr($x) + lappend ans $r $t1ra($r) $x +} +maketest 3.11 {SELECT rowid, a, x FROM t1 ORDER BY +x} $ans +maketest 3.12 {SELECT rowid, a, x FROM t1 ORDER BY x} $ans + +set ans {} +foreach x [reverse [sort $all_x]] { + set r $t1xr($x) + lappend ans $r $t1ra($r) $x +} +maketest 3.13 {SELECT rowid, a, x FROM t1 ORDER BY +x DESC} $ans +maketest 3.14 {SELECT rowid, a, x FROM t1 ORDER BY x DESC} $ans + + +maketest 4.1 {UPDATE t1 SET rowid=a, a=rowid, x=z, z=x} {} + +set ans {} +foreach r [sort $all_rowid] { + lappend ans $r $t1ra($r) $t1rx($r) +} +maketest 4.3 {SELECT a, rowid, z FROM t1 ORDER BY +a} $ans +maketest 4.4 {SELECT a, rowid, z FROM t1 ORDER BY a} $ans + +set ans {} +foreach r [reverse [sort $all_rowid]] { + lappend ans $r $t1ra($r) $t1rx($r) +} +maketest 4.5 {SELECT a, rowid, z FROM t1 ORDER BY +a DESC} $ans +maketest 4.6 {SELECT a, rowid, z FROM t1 ORDER BY a DESC} $ans + +set ans {} +foreach a [sort $all_a] { + set r $t1ar($a) + lappend ans $r $a $t1rx($r) +} +maketest 4.7 {SELECT a, rowid, z FROM t1 ORDER BY +rowid} $ans +maketest 4.8 {SELECT a, rowid, z FROM t1 ORDER BY rowid} $ans + +set ans {} +foreach a [reverse [sort $all_a]] { + set r $t1ar($a) + lappend ans $r $a $t1rx($r) +} +maketest 4.9 {SELECT a, rowid, z FROM t1 ORDER BY +rowid DESC} $ans +maketest 4.10 {SELECT a, rowid, z FROM t1 ORDER BY rowid DESC} $ans + +set ans {} +foreach x [sort $all_x] { + set r $t1xr($x) + lappend ans $r $t1ra($r) $x +} +maketest 4.11 {SELECT a, rowid, z FROM t1 ORDER BY +z} $ans +maketest 4.12 {SELECT a, rowid, z FROM t1 ORDER BY z} $ans + +set ans {} +foreach x [reverse [sort $all_x]] { + set r $t1xr($x) + lappend ans $r $t1ra($r) $x +} +maketest 4.13 {SELECT a, rowid, z FROM t1 ORDER BY +z DESC} $ans +maketest 4.14 {SELECT a, rowid, z FROM t1 ORDER BY z DESC} $ans + +puts {finish_test} diff --git a/test/boundary4.test b/test/boundary4.test new file mode 100644 index 0000000..b77ac3a --- /dev/null +++ b/test/boundary4.test @@ -0,0 +1,343 @@ +# 2008 December 11 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file is automatically generated from a separate TCL script. +# This file seeks to exercise integer boundary values. +# +# $Id: boundary4.test,v 1.2 2009/01/02 15:45:48 shane Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Many of the boundary tests depend on a working 64-bit implementation. +if {![working_64bit_int]} { finish_test; return } +ifcapable !altertable { finish_test; return } + +do_test boundary4-1.1 { + db eval { + CREATE TABLE t1(a,x); + INSERT INTO t1(oid,a,x) VALUES(549755813887,1,'0000007fffffffff'); + INSERT INTO t1(oid,a,x) VALUES(-8388608,2,'ffffffffff800000'); + INSERT INTO t1(oid,a,x) VALUES(0,3,'0000000000000000'); + INSERT INTO t1(oid,a,x) VALUES(-129,4,'ffffffffffffff7f'); + INSERT INTO t1(oid,a,x) VALUES(8388608,5,'0000000000800000'); + INSERT INTO t1(oid,a,x) VALUES(65535,6,'000000000000ffff'); + INSERT INTO t1(oid,a,x) VALUES(8388607,7,'00000000007fffff'); + INSERT INTO t1(oid,a,x) VALUES(1099511627776,8,'0000010000000000'); + INSERT INTO t1(oid,a,x) VALUES(16777215,9,'0000000000ffffff'); + INSERT INTO t1(oid,a,x) VALUES(32767,10,'0000000000007fff'); + INSERT INTO t1(oid,a,x) VALUES(4294967296,11,'0000000100000000'); + INSERT INTO t1(oid,a,x) VALUES(-549755813888,12,'ffffff8000000000'); + INSERT INTO t1(oid,a,x) VALUES(-140737488355328,13,'ffff800000000000'); + INSERT INTO t1(oid,a,x) VALUES(256,14,'0000000000000100'); + INSERT INTO t1(oid,a,x) VALUES(16777216,15,'0000000001000000'); + INSERT INTO t1(oid,a,x) VALUES(72057594037927936,16,'0100000000000000'); + INSERT INTO t1(oid,a,x) VALUES(-1,17,'ffffffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(9223372036854775807,18,'7fffffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(281474976710655,19,'0000ffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(1099511627775,20,'000000ffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(-8388609,21,'ffffffffff7fffff'); + INSERT INTO t1(oid,a,x) VALUES(32768,22,'0000000000008000'); + INSERT INTO t1(oid,a,x) VALUES(36028797018963968,23,'0080000000000000'); + INSERT INTO t1(oid,a,x) VALUES(-32769,24,'ffffffffffff7fff'); + INSERT INTO t1(oid,a,x) VALUES(127,25,'000000000000007f'); + INSERT INTO t1(oid,a,x) VALUES(-9223372036854775808,26,'8000000000000000'); + INSERT INTO t1(oid,a,x) VALUES(72057594037927935,27,'00ffffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(-549755813889,28,'ffffff7fffffffff'); + INSERT INTO t1(oid,a,x) VALUES(255,29,'00000000000000ff'); + INSERT INTO t1(oid,a,x) VALUES(-36028797018963969,30,'ff7fffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(-2147483648,31,'ffffffff80000000'); + INSERT INTO t1(oid,a,x) VALUES(281474976710656,32,'0001000000000000'); + INSERT INTO t1(oid,a,x) VALUES(65536,33,'0000000000010000'); + INSERT INTO t1(oid,a,x) VALUES(140737488355328,34,'0000800000000000'); + INSERT INTO t1(oid,a,x) VALUES(549755813888,35,'0000008000000000'); + INSERT INTO t1(oid,a,x) VALUES(2147483648,36,'0000000080000000'); + INSERT INTO t1(oid,a,x) VALUES(4294967295,37,'00000000ffffffff'); + INSERT INTO t1(oid,a,x) VALUES(140737488355327,38,'00007fffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(-2147483649,39,'ffffffff7fffffff'); + INSERT INTO t1(oid,a,x) VALUES(36028797018963967,40,'007fffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(128,41,'0000000000000080'); + INSERT INTO t1(oid,a,x) VALUES(-32768,42,'ffffffffffff8000'); + INSERT INTO t1(oid,a,x) VALUES(-36028797018963968,43,'ff80000000000000'); + INSERT INTO t1(oid,a,x) VALUES(-140737488355329,44,'ffff7fffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(-128,45,'ffffffffffffff80'); + INSERT INTO t1(oid,a,x) VALUES(2147483647,46,'000000007fffffff'); + CREATE INDEX t1i1 ON t1(a); + CREATE INDEX t1i2 ON t1(x); + } +} {} +do_test boundary4-1.2 { + db eval { + SELECT count(*) FROM t1 + } +} {46} +do_test boundary4-1.3 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY +rowid + } +} {-9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff 0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff} +do_test boundary4-1.4 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY rowid + } +} {-9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff 0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff} +do_test boundary4-1.5 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY +rowid DESC + } +} {9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000 -1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000} +do_test boundary4-1.6 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY rowid DESC + } +} {9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000 -1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000} +do_test boundary4-1.7 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY +a + } +} {549755813887 1 0000007fffffffff -8388608 2 ffffffffff800000 0 3 0000000000000000 -129 4 ffffffffffffff7f 8388608 5 0000000000800000 65535 6 000000000000ffff 8388607 7 00000000007fffff 1099511627776 8 0000010000000000 16777215 9 0000000000ffffff 32767 10 0000000000007fff 4294967296 11 0000000100000000 -549755813888 12 ffffff8000000000 -140737488355328 13 ffff800000000000 256 14 0000000000000100 16777216 15 0000000001000000 72057594037927936 16 0100000000000000 -1 17 ffffffffffffffff 9223372036854775807 18 7fffffffffffffff 281474976710655 19 0000ffffffffffff 1099511627775 20 000000ffffffffff -8388609 21 ffffffffff7fffff 32768 22 0000000000008000 36028797018963968 23 0080000000000000 -32769 24 ffffffffffff7fff 127 25 000000000000007f -9223372036854775808 26 8000000000000000 72057594037927935 27 00ffffffffffffff -549755813889 28 ffffff7fffffffff 255 29 00000000000000ff -36028797018963969 30 ff7fffffffffffff -2147483648 31 ffffffff80000000 281474976710656 32 0001000000000000 65536 33 0000000000010000 140737488355328 34 0000800000000000 549755813888 35 0000008000000000 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 140737488355327 38 00007fffffffffff -2147483649 39 ffffffff7fffffff 36028797018963967 40 007fffffffffffff 128 41 0000000000000080 -32768 42 ffffffffffff8000 -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -128 45 ffffffffffffff80 2147483647 46 000000007fffffff} +do_test boundary4-1.8 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY a + } +} {549755813887 1 0000007fffffffff -8388608 2 ffffffffff800000 0 3 0000000000000000 -129 4 ffffffffffffff7f 8388608 5 0000000000800000 65535 6 000000000000ffff 8388607 7 00000000007fffff 1099511627776 8 0000010000000000 16777215 9 0000000000ffffff 32767 10 0000000000007fff 4294967296 11 0000000100000000 -549755813888 12 ffffff8000000000 -140737488355328 13 ffff800000000000 256 14 0000000000000100 16777216 15 0000000001000000 72057594037927936 16 0100000000000000 -1 17 ffffffffffffffff 9223372036854775807 18 7fffffffffffffff 281474976710655 19 0000ffffffffffff 1099511627775 20 000000ffffffffff -8388609 21 ffffffffff7fffff 32768 22 0000000000008000 36028797018963968 23 0080000000000000 -32769 24 ffffffffffff7fff 127 25 000000000000007f -9223372036854775808 26 8000000000000000 72057594037927935 27 00ffffffffffffff -549755813889 28 ffffff7fffffffff 255 29 00000000000000ff -36028797018963969 30 ff7fffffffffffff -2147483648 31 ffffffff80000000 281474976710656 32 0001000000000000 65536 33 0000000000010000 140737488355328 34 0000800000000000 549755813888 35 0000008000000000 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 140737488355327 38 00007fffffffffff -2147483649 39 ffffffff7fffffff 36028797018963967 40 007fffffffffffff 128 41 0000000000000080 -32768 42 ffffffffffff8000 -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -128 45 ffffffffffffff80 2147483647 46 000000007fffffff} +do_test boundary4-1.9 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY +a DESC + } +} {2147483647 46 000000007fffffff -128 45 ffffffffffffff80 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -32768 42 ffffffffffff8000 128 41 0000000000000080 36028797018963967 40 007fffffffffffff -2147483649 39 ffffffff7fffffff 140737488355327 38 00007fffffffffff 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 549755813888 35 0000008000000000 140737488355328 34 0000800000000000 65536 33 0000000000010000 281474976710656 32 0001000000000000 -2147483648 31 ffffffff80000000 -36028797018963969 30 ff7fffffffffffff 255 29 00000000000000ff -549755813889 28 ffffff7fffffffff 72057594037927935 27 00ffffffffffffff -9223372036854775808 26 8000000000000000 127 25 000000000000007f -32769 24 ffffffffffff7fff 36028797018963968 23 0080000000000000 32768 22 0000000000008000 -8388609 21 ffffffffff7fffff 1099511627775 20 000000ffffffffff 281474976710655 19 0000ffffffffffff 9223372036854775807 18 7fffffffffffffff -1 17 ffffffffffffffff 72057594037927936 16 0100000000000000 16777216 15 0000000001000000 256 14 0000000000000100 -140737488355328 13 ffff800000000000 -549755813888 12 ffffff8000000000 4294967296 11 0000000100000000 32767 10 0000000000007fff 16777215 9 0000000000ffffff 1099511627776 8 0000010000000000 8388607 7 00000000007fffff 65535 6 000000000000ffff 8388608 5 0000000000800000 -129 4 ffffffffffffff7f 0 3 0000000000000000 -8388608 2 ffffffffff800000 549755813887 1 0000007fffffffff} +do_test boundary4-1.10 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY a DESC + } +} {2147483647 46 000000007fffffff -128 45 ffffffffffffff80 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -32768 42 ffffffffffff8000 128 41 0000000000000080 36028797018963967 40 007fffffffffffff -2147483649 39 ffffffff7fffffff 140737488355327 38 00007fffffffffff 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 549755813888 35 0000008000000000 140737488355328 34 0000800000000000 65536 33 0000000000010000 281474976710656 32 0001000000000000 -2147483648 31 ffffffff80000000 -36028797018963969 30 ff7fffffffffffff 255 29 00000000000000ff -549755813889 28 ffffff7fffffffff 72057594037927935 27 00ffffffffffffff -9223372036854775808 26 8000000000000000 127 25 000000000000007f -32769 24 ffffffffffff7fff 36028797018963968 23 0080000000000000 32768 22 0000000000008000 -8388609 21 ffffffffff7fffff 1099511627775 20 000000ffffffffff 281474976710655 19 0000ffffffffffff 9223372036854775807 18 7fffffffffffffff -1 17 ffffffffffffffff 72057594037927936 16 0100000000000000 16777216 15 0000000001000000 256 14 0000000000000100 -140737488355328 13 ffff800000000000 -549755813888 12 ffffff8000000000 4294967296 11 0000000100000000 32767 10 0000000000007fff 16777215 9 0000000000ffffff 1099511627776 8 0000010000000000 8388607 7 00000000007fffff 65535 6 000000000000ffff 8388608 5 0000000000800000 -129 4 ffffffffffffff7f 0 3 0000000000000000 -8388608 2 ffffffffff800000 549755813887 1 0000007fffffffff} +do_test boundary4-1.11 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY +x + } +} {0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff -9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff} +do_test boundary4-1.12 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY x + } +} {0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff -9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff} +do_test boundary4-1.13 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY +x DESC + } +} {-1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000 9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000} +do_test boundary4-1.14 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY x DESC + } +} {-1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000 9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000} +do_test boundary4-2.1 { + db eval { + UPDATE t1 SET rowid=a, a=rowid + } +} {} +do_test boundary4-2.3 { + db eval { + SELECT a, rowid, x FROM t1 ORDER BY +a + } +} {-9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff 0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff} +do_test boundary4-2.4 { + db eval { + SELECT a, rowid, x FROM t1 ORDER BY a + } +} {-9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff 0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff} +do_test boundary4-2.5 { + db eval { + SELECT a, rowid, x FROM t1 ORDER BY +a DESC + } +} {9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000 -1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000} +do_test boundary4-2.6 { + db eval { + SELECT a, rowid, x FROM t1 ORDER BY a DESC + } +} {9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000 -1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000} +do_test boundary4-2.7 { + db eval { + SELECT a, rowid, x FROM t1 ORDER BY +rowid + } +} {549755813887 1 0000007fffffffff -8388608 2 ffffffffff800000 0 3 0000000000000000 -129 4 ffffffffffffff7f 8388608 5 0000000000800000 65535 6 000000000000ffff 8388607 7 00000000007fffff 1099511627776 8 0000010000000000 16777215 9 0000000000ffffff 32767 10 0000000000007fff 4294967296 11 0000000100000000 -549755813888 12 ffffff8000000000 -140737488355328 13 ffff800000000000 256 14 0000000000000100 16777216 15 0000000001000000 72057594037927936 16 0100000000000000 -1 17 ffffffffffffffff 9223372036854775807 18 7fffffffffffffff 281474976710655 19 0000ffffffffffff 1099511627775 20 000000ffffffffff -8388609 21 ffffffffff7fffff 32768 22 0000000000008000 36028797018963968 23 0080000000000000 -32769 24 ffffffffffff7fff 127 25 000000000000007f -9223372036854775808 26 8000000000000000 72057594037927935 27 00ffffffffffffff -549755813889 28 ffffff7fffffffff 255 29 00000000000000ff -36028797018963969 30 ff7fffffffffffff -2147483648 31 ffffffff80000000 281474976710656 32 0001000000000000 65536 33 0000000000010000 140737488355328 34 0000800000000000 549755813888 35 0000008000000000 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 140737488355327 38 00007fffffffffff -2147483649 39 ffffffff7fffffff 36028797018963967 40 007fffffffffffff 128 41 0000000000000080 -32768 42 ffffffffffff8000 -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -128 45 ffffffffffffff80 2147483647 46 000000007fffffff} +do_test boundary4-2.8 { + db eval { + SELECT a, rowid, x FROM t1 ORDER BY rowid + } +} {549755813887 1 0000007fffffffff -8388608 2 ffffffffff800000 0 3 0000000000000000 -129 4 ffffffffffffff7f 8388608 5 0000000000800000 65535 6 000000000000ffff 8388607 7 00000000007fffff 1099511627776 8 0000010000000000 16777215 9 0000000000ffffff 32767 10 0000000000007fff 4294967296 11 0000000100000000 -549755813888 12 ffffff8000000000 -140737488355328 13 ffff800000000000 256 14 0000000000000100 16777216 15 0000000001000000 72057594037927936 16 0100000000000000 -1 17 ffffffffffffffff 9223372036854775807 18 7fffffffffffffff 281474976710655 19 0000ffffffffffff 1099511627775 20 000000ffffffffff -8388609 21 ffffffffff7fffff 32768 22 0000000000008000 36028797018963968 23 0080000000000000 -32769 24 ffffffffffff7fff 127 25 000000000000007f -9223372036854775808 26 8000000000000000 72057594037927935 27 00ffffffffffffff -549755813889 28 ffffff7fffffffff 255 29 00000000000000ff -36028797018963969 30 ff7fffffffffffff -2147483648 31 ffffffff80000000 281474976710656 32 0001000000000000 65536 33 0000000000010000 140737488355328 34 0000800000000000 549755813888 35 0000008000000000 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 140737488355327 38 00007fffffffffff -2147483649 39 ffffffff7fffffff 36028797018963967 40 007fffffffffffff 128 41 0000000000000080 -32768 42 ffffffffffff8000 -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -128 45 ffffffffffffff80 2147483647 46 000000007fffffff} +do_test boundary4-2.9 { + db eval { + SELECT a, rowid, x FROM t1 ORDER BY +rowid DESC + } +} {2147483647 46 000000007fffffff -128 45 ffffffffffffff80 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -32768 42 ffffffffffff8000 128 41 0000000000000080 36028797018963967 40 007fffffffffffff -2147483649 39 ffffffff7fffffff 140737488355327 38 00007fffffffffff 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 549755813888 35 0000008000000000 140737488355328 34 0000800000000000 65536 33 0000000000010000 281474976710656 32 0001000000000000 -2147483648 31 ffffffff80000000 -36028797018963969 30 ff7fffffffffffff 255 29 00000000000000ff -549755813889 28 ffffff7fffffffff 72057594037927935 27 00ffffffffffffff -9223372036854775808 26 8000000000000000 127 25 000000000000007f -32769 24 ffffffffffff7fff 36028797018963968 23 0080000000000000 32768 22 0000000000008000 -8388609 21 ffffffffff7fffff 1099511627775 20 000000ffffffffff 281474976710655 19 0000ffffffffffff 9223372036854775807 18 7fffffffffffffff -1 17 ffffffffffffffff 72057594037927936 16 0100000000000000 16777216 15 0000000001000000 256 14 0000000000000100 -140737488355328 13 ffff800000000000 -549755813888 12 ffffff8000000000 4294967296 11 0000000100000000 32767 10 0000000000007fff 16777215 9 0000000000ffffff 1099511627776 8 0000010000000000 8388607 7 00000000007fffff 65535 6 000000000000ffff 8388608 5 0000000000800000 -129 4 ffffffffffffff7f 0 3 0000000000000000 -8388608 2 ffffffffff800000 549755813887 1 0000007fffffffff} +do_test boundary4-2.10 { + db eval { + SELECT a, rowid, x FROM t1 ORDER BY rowid DESC + } +} {2147483647 46 000000007fffffff -128 45 ffffffffffffff80 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -32768 42 ffffffffffff8000 128 41 0000000000000080 36028797018963967 40 007fffffffffffff -2147483649 39 ffffffff7fffffff 140737488355327 38 00007fffffffffff 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 549755813888 35 0000008000000000 140737488355328 34 0000800000000000 65536 33 0000000000010000 281474976710656 32 0001000000000000 -2147483648 31 ffffffff80000000 -36028797018963969 30 ff7fffffffffffff 255 29 00000000000000ff -549755813889 28 ffffff7fffffffff 72057594037927935 27 00ffffffffffffff -9223372036854775808 26 8000000000000000 127 25 000000000000007f -32769 24 ffffffffffff7fff 36028797018963968 23 0080000000000000 32768 22 0000000000008000 -8388609 21 ffffffffff7fffff 1099511627775 20 000000ffffffffff 281474976710655 19 0000ffffffffffff 9223372036854775807 18 7fffffffffffffff -1 17 ffffffffffffffff 72057594037927936 16 0100000000000000 16777216 15 0000000001000000 256 14 0000000000000100 -140737488355328 13 ffff800000000000 -549755813888 12 ffffff8000000000 4294967296 11 0000000100000000 32767 10 0000000000007fff 16777215 9 0000000000ffffff 1099511627776 8 0000010000000000 8388607 7 00000000007fffff 65535 6 000000000000ffff 8388608 5 0000000000800000 -129 4 ffffffffffffff7f 0 3 0000000000000000 -8388608 2 ffffffffff800000 549755813887 1 0000007fffffffff} +do_test boundary4-2.11 { + db eval { + SELECT a, rowid, x FROM t1 ORDER BY +x + } +} {0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff -9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff} +do_test boundary4-2.12 { + db eval { + SELECT a, rowid, x FROM t1 ORDER BY x + } +} {0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff -9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff} +do_test boundary4-2.13 { + db eval { + SELECT a, rowid, x FROM t1 ORDER BY +x DESC + } +} {-1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000 9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000} +do_test boundary4-2.14 { + db eval { + SELECT a, rowid, x FROM t1 ORDER BY x DESC + } +} {-1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000 9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000} +do_test boundary4-3.1 { + db eval { + UPDATE t1 SET rowid=a, a=rowid + } +} {} +do_test boundary4-3.2 { + db eval { + ALTER TABLE t1 ADD COLUMN z; UPDATE t1 SET z=zeroblob(600) + } +} {} +do_test boundary4-3.3 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY +rowid + } +} {-9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff 0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff} +do_test boundary4-3.4 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY rowid + } +} {-9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff 0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff} +do_test boundary4-3.5 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY +rowid DESC + } +} {9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000 -1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000} +do_test boundary4-3.6 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY rowid DESC + } +} {9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000 -1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000} +do_test boundary4-3.7 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY +a + } +} {549755813887 1 0000007fffffffff -8388608 2 ffffffffff800000 0 3 0000000000000000 -129 4 ffffffffffffff7f 8388608 5 0000000000800000 65535 6 000000000000ffff 8388607 7 00000000007fffff 1099511627776 8 0000010000000000 16777215 9 0000000000ffffff 32767 10 0000000000007fff 4294967296 11 0000000100000000 -549755813888 12 ffffff8000000000 -140737488355328 13 ffff800000000000 256 14 0000000000000100 16777216 15 0000000001000000 72057594037927936 16 0100000000000000 -1 17 ffffffffffffffff 9223372036854775807 18 7fffffffffffffff 281474976710655 19 0000ffffffffffff 1099511627775 20 000000ffffffffff -8388609 21 ffffffffff7fffff 32768 22 0000000000008000 36028797018963968 23 0080000000000000 -32769 24 ffffffffffff7fff 127 25 000000000000007f -9223372036854775808 26 8000000000000000 72057594037927935 27 00ffffffffffffff -549755813889 28 ffffff7fffffffff 255 29 00000000000000ff -36028797018963969 30 ff7fffffffffffff -2147483648 31 ffffffff80000000 281474976710656 32 0001000000000000 65536 33 0000000000010000 140737488355328 34 0000800000000000 549755813888 35 0000008000000000 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 140737488355327 38 00007fffffffffff -2147483649 39 ffffffff7fffffff 36028797018963967 40 007fffffffffffff 128 41 0000000000000080 -32768 42 ffffffffffff8000 -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -128 45 ffffffffffffff80 2147483647 46 000000007fffffff} +do_test boundary4-3.8 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY a + } +} {549755813887 1 0000007fffffffff -8388608 2 ffffffffff800000 0 3 0000000000000000 -129 4 ffffffffffffff7f 8388608 5 0000000000800000 65535 6 000000000000ffff 8388607 7 00000000007fffff 1099511627776 8 0000010000000000 16777215 9 0000000000ffffff 32767 10 0000000000007fff 4294967296 11 0000000100000000 -549755813888 12 ffffff8000000000 -140737488355328 13 ffff800000000000 256 14 0000000000000100 16777216 15 0000000001000000 72057594037927936 16 0100000000000000 -1 17 ffffffffffffffff 9223372036854775807 18 7fffffffffffffff 281474976710655 19 0000ffffffffffff 1099511627775 20 000000ffffffffff -8388609 21 ffffffffff7fffff 32768 22 0000000000008000 36028797018963968 23 0080000000000000 -32769 24 ffffffffffff7fff 127 25 000000000000007f -9223372036854775808 26 8000000000000000 72057594037927935 27 00ffffffffffffff -549755813889 28 ffffff7fffffffff 255 29 00000000000000ff -36028797018963969 30 ff7fffffffffffff -2147483648 31 ffffffff80000000 281474976710656 32 0001000000000000 65536 33 0000000000010000 140737488355328 34 0000800000000000 549755813888 35 0000008000000000 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 140737488355327 38 00007fffffffffff -2147483649 39 ffffffff7fffffff 36028797018963967 40 007fffffffffffff 128 41 0000000000000080 -32768 42 ffffffffffff8000 -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -128 45 ffffffffffffff80 2147483647 46 000000007fffffff} +do_test boundary4-3.9 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY +a DESC + } +} {2147483647 46 000000007fffffff -128 45 ffffffffffffff80 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -32768 42 ffffffffffff8000 128 41 0000000000000080 36028797018963967 40 007fffffffffffff -2147483649 39 ffffffff7fffffff 140737488355327 38 00007fffffffffff 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 549755813888 35 0000008000000000 140737488355328 34 0000800000000000 65536 33 0000000000010000 281474976710656 32 0001000000000000 -2147483648 31 ffffffff80000000 -36028797018963969 30 ff7fffffffffffff 255 29 00000000000000ff -549755813889 28 ffffff7fffffffff 72057594037927935 27 00ffffffffffffff -9223372036854775808 26 8000000000000000 127 25 000000000000007f -32769 24 ffffffffffff7fff 36028797018963968 23 0080000000000000 32768 22 0000000000008000 -8388609 21 ffffffffff7fffff 1099511627775 20 000000ffffffffff 281474976710655 19 0000ffffffffffff 9223372036854775807 18 7fffffffffffffff -1 17 ffffffffffffffff 72057594037927936 16 0100000000000000 16777216 15 0000000001000000 256 14 0000000000000100 -140737488355328 13 ffff800000000000 -549755813888 12 ffffff8000000000 4294967296 11 0000000100000000 32767 10 0000000000007fff 16777215 9 0000000000ffffff 1099511627776 8 0000010000000000 8388607 7 00000000007fffff 65535 6 000000000000ffff 8388608 5 0000000000800000 -129 4 ffffffffffffff7f 0 3 0000000000000000 -8388608 2 ffffffffff800000 549755813887 1 0000007fffffffff} +do_test boundary4-3.10 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY a DESC + } +} {2147483647 46 000000007fffffff -128 45 ffffffffffffff80 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -32768 42 ffffffffffff8000 128 41 0000000000000080 36028797018963967 40 007fffffffffffff -2147483649 39 ffffffff7fffffff 140737488355327 38 00007fffffffffff 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 549755813888 35 0000008000000000 140737488355328 34 0000800000000000 65536 33 0000000000010000 281474976710656 32 0001000000000000 -2147483648 31 ffffffff80000000 -36028797018963969 30 ff7fffffffffffff 255 29 00000000000000ff -549755813889 28 ffffff7fffffffff 72057594037927935 27 00ffffffffffffff -9223372036854775808 26 8000000000000000 127 25 000000000000007f -32769 24 ffffffffffff7fff 36028797018963968 23 0080000000000000 32768 22 0000000000008000 -8388609 21 ffffffffff7fffff 1099511627775 20 000000ffffffffff 281474976710655 19 0000ffffffffffff 9223372036854775807 18 7fffffffffffffff -1 17 ffffffffffffffff 72057594037927936 16 0100000000000000 16777216 15 0000000001000000 256 14 0000000000000100 -140737488355328 13 ffff800000000000 -549755813888 12 ffffff8000000000 4294967296 11 0000000100000000 32767 10 0000000000007fff 16777215 9 0000000000ffffff 1099511627776 8 0000010000000000 8388607 7 00000000007fffff 65535 6 000000000000ffff 8388608 5 0000000000800000 -129 4 ffffffffffffff7f 0 3 0000000000000000 -8388608 2 ffffffffff800000 549755813887 1 0000007fffffffff} +do_test boundary4-3.11 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY +x + } +} {0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff -9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff} +do_test boundary4-3.12 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY x + } +} {0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff -9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff} +do_test boundary4-3.13 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY +x DESC + } +} {-1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000 9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000} +do_test boundary4-3.14 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY x DESC + } +} {-1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000 9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000} +do_test boundary4-4.1 { + db eval { + UPDATE t1 SET rowid=a, a=rowid, x=z, z=x + } +} {} +do_test boundary4-4.3 { + db eval { + SELECT a, rowid, z FROM t1 ORDER BY +a + } +} {-9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff 0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff} +do_test boundary4-4.4 { + db eval { + SELECT a, rowid, z FROM t1 ORDER BY a + } +} {-9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff 0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff} +do_test boundary4-4.5 { + db eval { + SELECT a, rowid, z FROM t1 ORDER BY +a DESC + } +} {9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000 -1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000} +do_test boundary4-4.6 { + db eval { + SELECT a, rowid, z FROM t1 ORDER BY a DESC + } +} {9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000 -1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000} +do_test boundary4-4.7 { + db eval { + SELECT a, rowid, z FROM t1 ORDER BY +rowid + } +} {549755813887 1 0000007fffffffff -8388608 2 ffffffffff800000 0 3 0000000000000000 -129 4 ffffffffffffff7f 8388608 5 0000000000800000 65535 6 000000000000ffff 8388607 7 00000000007fffff 1099511627776 8 0000010000000000 16777215 9 0000000000ffffff 32767 10 0000000000007fff 4294967296 11 0000000100000000 -549755813888 12 ffffff8000000000 -140737488355328 13 ffff800000000000 256 14 0000000000000100 16777216 15 0000000001000000 72057594037927936 16 0100000000000000 -1 17 ffffffffffffffff 9223372036854775807 18 7fffffffffffffff 281474976710655 19 0000ffffffffffff 1099511627775 20 000000ffffffffff -8388609 21 ffffffffff7fffff 32768 22 0000000000008000 36028797018963968 23 0080000000000000 -32769 24 ffffffffffff7fff 127 25 000000000000007f -9223372036854775808 26 8000000000000000 72057594037927935 27 00ffffffffffffff -549755813889 28 ffffff7fffffffff 255 29 00000000000000ff -36028797018963969 30 ff7fffffffffffff -2147483648 31 ffffffff80000000 281474976710656 32 0001000000000000 65536 33 0000000000010000 140737488355328 34 0000800000000000 549755813888 35 0000008000000000 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 140737488355327 38 00007fffffffffff -2147483649 39 ffffffff7fffffff 36028797018963967 40 007fffffffffffff 128 41 0000000000000080 -32768 42 ffffffffffff8000 -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -128 45 ffffffffffffff80 2147483647 46 000000007fffffff} +do_test boundary4-4.8 { + db eval { + SELECT a, rowid, z FROM t1 ORDER BY rowid + } +} {549755813887 1 0000007fffffffff -8388608 2 ffffffffff800000 0 3 0000000000000000 -129 4 ffffffffffffff7f 8388608 5 0000000000800000 65535 6 000000000000ffff 8388607 7 00000000007fffff 1099511627776 8 0000010000000000 16777215 9 0000000000ffffff 32767 10 0000000000007fff 4294967296 11 0000000100000000 -549755813888 12 ffffff8000000000 -140737488355328 13 ffff800000000000 256 14 0000000000000100 16777216 15 0000000001000000 72057594037927936 16 0100000000000000 -1 17 ffffffffffffffff 9223372036854775807 18 7fffffffffffffff 281474976710655 19 0000ffffffffffff 1099511627775 20 000000ffffffffff -8388609 21 ffffffffff7fffff 32768 22 0000000000008000 36028797018963968 23 0080000000000000 -32769 24 ffffffffffff7fff 127 25 000000000000007f -9223372036854775808 26 8000000000000000 72057594037927935 27 00ffffffffffffff -549755813889 28 ffffff7fffffffff 255 29 00000000000000ff -36028797018963969 30 ff7fffffffffffff -2147483648 31 ffffffff80000000 281474976710656 32 0001000000000000 65536 33 0000000000010000 140737488355328 34 0000800000000000 549755813888 35 0000008000000000 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 140737488355327 38 00007fffffffffff -2147483649 39 ffffffff7fffffff 36028797018963967 40 007fffffffffffff 128 41 0000000000000080 -32768 42 ffffffffffff8000 -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -128 45 ffffffffffffff80 2147483647 46 000000007fffffff} +do_test boundary4-4.9 { + db eval { + SELECT a, rowid, z FROM t1 ORDER BY +rowid DESC + } +} {2147483647 46 000000007fffffff -128 45 ffffffffffffff80 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -32768 42 ffffffffffff8000 128 41 0000000000000080 36028797018963967 40 007fffffffffffff -2147483649 39 ffffffff7fffffff 140737488355327 38 00007fffffffffff 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 549755813888 35 0000008000000000 140737488355328 34 0000800000000000 65536 33 0000000000010000 281474976710656 32 0001000000000000 -2147483648 31 ffffffff80000000 -36028797018963969 30 ff7fffffffffffff 255 29 00000000000000ff -549755813889 28 ffffff7fffffffff 72057594037927935 27 00ffffffffffffff -9223372036854775808 26 8000000000000000 127 25 000000000000007f -32769 24 ffffffffffff7fff 36028797018963968 23 0080000000000000 32768 22 0000000000008000 -8388609 21 ffffffffff7fffff 1099511627775 20 000000ffffffffff 281474976710655 19 0000ffffffffffff 9223372036854775807 18 7fffffffffffffff -1 17 ffffffffffffffff 72057594037927936 16 0100000000000000 16777216 15 0000000001000000 256 14 0000000000000100 -140737488355328 13 ffff800000000000 -549755813888 12 ffffff8000000000 4294967296 11 0000000100000000 32767 10 0000000000007fff 16777215 9 0000000000ffffff 1099511627776 8 0000010000000000 8388607 7 00000000007fffff 65535 6 000000000000ffff 8388608 5 0000000000800000 -129 4 ffffffffffffff7f 0 3 0000000000000000 -8388608 2 ffffffffff800000 549755813887 1 0000007fffffffff} +do_test boundary4-4.10 { + db eval { + SELECT a, rowid, z FROM t1 ORDER BY rowid DESC + } +} {2147483647 46 000000007fffffff -128 45 ffffffffffffff80 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -32768 42 ffffffffffff8000 128 41 0000000000000080 36028797018963967 40 007fffffffffffff -2147483649 39 ffffffff7fffffff 140737488355327 38 00007fffffffffff 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 549755813888 35 0000008000000000 140737488355328 34 0000800000000000 65536 33 0000000000010000 281474976710656 32 0001000000000000 -2147483648 31 ffffffff80000000 -36028797018963969 30 ff7fffffffffffff 255 29 00000000000000ff -549755813889 28 ffffff7fffffffff 72057594037927935 27 00ffffffffffffff -9223372036854775808 26 8000000000000000 127 25 000000000000007f -32769 24 ffffffffffff7fff 36028797018963968 23 0080000000000000 32768 22 0000000000008000 -8388609 21 ffffffffff7fffff 1099511627775 20 000000ffffffffff 281474976710655 19 0000ffffffffffff 9223372036854775807 18 7fffffffffffffff -1 17 ffffffffffffffff 72057594037927936 16 0100000000000000 16777216 15 0000000001000000 256 14 0000000000000100 -140737488355328 13 ffff800000000000 -549755813888 12 ffffff8000000000 4294967296 11 0000000100000000 32767 10 0000000000007fff 16777215 9 0000000000ffffff 1099511627776 8 0000010000000000 8388607 7 00000000007fffff 65535 6 000000000000ffff 8388608 5 0000000000800000 -129 4 ffffffffffffff7f 0 3 0000000000000000 -8388608 2 ffffffffff800000 549755813887 1 0000007fffffffff} +do_test boundary4-4.11 { + db eval { + SELECT a, rowid, z FROM t1 ORDER BY +z + } +} {0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff -9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff} +do_test boundary4-4.12 { + db eval { + SELECT a, rowid, z FROM t1 ORDER BY z + } +} {0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff -9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff} +do_test boundary4-4.13 { + db eval { + SELECT a, rowid, z FROM t1 ORDER BY +z DESC + } +} {-1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000 9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000} +do_test boundary4-4.14 { + db eval { + SELECT a, rowid, z FROM t1 ORDER BY z DESC + } +} {-1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000 9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000} +finish_test diff --git a/test/btree01.test b/test/btree01.test new file mode 100644 index 0000000..6e4717a --- /dev/null +++ b/test/btree01.test @@ -0,0 +1,156 @@ +# 2014-11-27 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file contains test cases for b-tree logic. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix btree01 + +# The refactoring on the b-tree balance() routine in check-in +# http://www.sqlite.org/src/info/face33bea1ba3a (2014-10-27) +# caused the integrity_check on the following SQL to fail. +# +do_execsql_test btree01-1.1 { + PRAGMA page_size=65536; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b BLOB); + WITH RECURSIVE + c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<30) + INSERT INTO t1(a,b) SELECT i, zeroblob(6500) FROM c; + UPDATE t1 SET b=zeroblob(3000); + UPDATE t1 SET b=zeroblob(64000) WHERE a=2; + PRAGMA integrity_check; +} {ok} + +# The previous test is sufficient to prevent a regression. But we +# add a number of additional tests to stress the balancer in similar +# ways, looking for related problems. +# +for {set i 1} {$i<=30} {incr i} { + do_test btree01-1.2.$i { + db eval { + DELETE FROM t1; + WITH RECURSIVE + c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<30) + INSERT INTO t1(a,b) SELECT i, zeroblob(6500) FROM c; + UPDATE t1 SET b=zeroblob(3000); + UPDATE t1 SET b=zeroblob(64000) WHERE a=$::i; + PRAGMA integrity_check; + } + } {ok} +} +for {set i 1} {$i<=30} {incr i} { + do_test btree01-1.3.$i { + db eval { + DELETE FROM t1; + WITH RECURSIVE + c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<30) + INSERT INTO t1(a,b) SELECT i, zeroblob(6500) FROM c; + UPDATE t1 SET b=zeroblob(2000); + UPDATE t1 SET b=zeroblob(64000) WHERE a=$::i; + PRAGMA integrity_check; + } + } {ok} +} +for {set i 1} {$i<=30} {incr i} { + do_test btree01-1.4.$i { + db eval { + DELETE FROM t1; + WITH RECURSIVE + c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<30) + INSERT INTO t1(a,b) SELECT i, zeroblob(6500) FROM c; + UPDATE t1 SET b=zeroblob(6499) WHERE (a%3)==0; + UPDATE t1 SET b=zeroblob(6499) WHERE (a%3)==1; + UPDATE t1 SET b=zeroblob(6499) WHERE (a%3)==2; + UPDATE t1 SET b=zeroblob(64000) WHERE a=$::i; + PRAGMA integrity_check; + } + } {ok} +} +for {set i 1} {$i<=30} {incr i} { + do_test btree01-1.5.$i { + db eval { + DELETE FROM t1; + WITH RECURSIVE + c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<30) + INSERT INTO t1(a,b) SELECT i, zeroblob(6542) FROM c; + UPDATE t1 SET b=zeroblob(2331); + UPDATE t1 SET b=zeroblob(65496) WHERE a=$::i; + PRAGMA integrity_check; + } + } {ok} +} +for {set i 1} {$i<=30} {incr i} { + do_test btree01-1.6.$i { + db eval { + DELETE FROM t1; + WITH RECURSIVE + c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<30) + INSERT INTO t1(a,b) SELECT i, zeroblob(6542) FROM c; + UPDATE t1 SET b=zeroblob(2332); + UPDATE t1 SET b=zeroblob(65496) WHERE a=$::i; + PRAGMA integrity_check; + } + } {ok} +} +for {set i 1} {$i<=30} {incr i} { + do_test btree01-1.7.$i { + db eval { + DELETE FROM t1; + WITH RECURSIVE + c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<30) + INSERT INTO t1(a,b) SELECT i, zeroblob(6500) FROM c; + UPDATE t1 SET b=zeroblob(1); + UPDATE t1 SET b=zeroblob(65000) WHERE a=$::i; + PRAGMA integrity_check; + } + } {ok} +} +for {set i 1} {$i<=31} {incr i} { + do_test btree01-1.8.$i { + db eval { + DELETE FROM t1; + WITH RECURSIVE + c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<31) + INSERT INTO t1(a,b) SELECT i, zeroblob(6500) FROM c; + UPDATE t1 SET b=zeroblob(4000); + UPDATE t1 SET b=zeroblob(65000) WHERE a=$::i; + PRAGMA integrity_check; + } + } {ok} +} + +# 2022-03-06 OSSFuzz issue 45329 +# An assertion fault due to the failure to clear a flag in an optimization +# committed last night. +# +# When the stay-on-last page optimization of sqlite3BtreeIndexMoveto() is +# invoked, it needs to clear the BTCF_ValidOvfl flag. +# +db close +sqlite3 db :memory: +do_execsql_test btree01-2.1 { + PRAGMA page_size=1024; + CREATE TABLE t1(a INT PRIMARY KEY, b BLOB, c INT) WITHOUT ROWID; + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100) + INSERT INTO t1(a,b,c) SELECT x*2, zeroblob(100), x FROM c; + UPDATE t1 SET b=zeroblob(1000) WHERE a=198; + CREATE TABLE t2(x INTEGER PRIMARY KEY, y INT); + INSERT INTO t2(y) VALUES(198),(187),(100); + SELECT y, c FROM t2 LEFT JOIN t1 ON y=a ORDER BY x; +} {198 99 187 {} 100 50} +do_execsql_test btree01-2.2 { + SELECT y, c FROM t1 RIGHT JOIN t2 ON y=a ORDER BY x; +} {198 99 187 {} 100 50} + + +finish_test diff --git a/test/btree02.test b/test/btree02.test new file mode 100644 index 0000000..c1fede5 --- /dev/null +++ b/test/btree02.test @@ -0,0 +1,62 @@ +# 2015-03-25 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# The focus of this script is making multiple calls to saveCursorPosition() +# and restoreCursorPosition() when cursors have eState==CURSOR_SKIPNEXT +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +load_static_extension db eval +do_execsql_test btree02-100 { + CREATE TABLE t1(a TEXT, ax INTEGER, b INT, PRIMARY KEY(a,ax)) WITHOUT ROWID; + WITH RECURSIVE c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<10) + INSERT INTO t1(a,ax,b) SELECT printf('%02x',i+160), random(), i FROM c; + CREATE INDEX t1a ON t1(a); + CREATE TABLE t2(x,y); + CREATE TABLE t3(cnt); + WITH RECURSIVE c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<4) + INSERT INTO t3(cnt) SELECT i FROM c; + SELECT count(*) FROM t1; +} {10} + +proc showt1 {} { + puts -nonewline "t1: " + puts [db eval {SELECT printf('(%s,%s)',quote(a),quote(b)) FROM t1}] +} + +do_test btree02-110 { + db eval BEGIN + set i 0 + # showt1 + db eval {SELECT a, ax, b, cnt FROM t1 CROSS JOIN t3 WHERE b IS NOT NULL} { + if {$a==""} continue + db eval {INSERT INTO t2(x,y) VALUES($b,$cnt)} + # puts "a,b,cnt = ($a,$b,$cnt)" + incr i + if {$i%2==1} { + set bx [expr {$b+1000}] + # puts "INSERT ($a),$bx" + db eval {INSERT INTO t1(a,ax,b) VALUES(printf('(%s)',$a),random(),$bx)} + # showt1 + } else { + # puts "DELETE a=$a" + db eval {DELETE FROM t1 WHERE a=$a} + # showt1 + } + db eval {COMMIT; BEGIN} + } + db one {COMMIT; SELECT count(*) FROM t1;} +} {10} + +finish_test diff --git a/test/btreefault.test b/test/btreefault.test new file mode 100644 index 0000000..d0ba059 --- /dev/null +++ b/test/btreefault.test @@ -0,0 +1,106 @@ +# 2013 April 02 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file contains fault injection tests designed to test the btree.c +# module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/malloc_common.tcl +set testprefix btreefault + +# This test will not work with an in-memory journal, as the database will +# become corrupt if an error is injected into a transaction after it starts +# writing data out to the db file. +if {[permutation]=="inmemory_journal"} { + finish_test + return +} + +do_test 1-pre1 { + execsql { + PRAGMA auto_vacuum = incremental; + PRAGMA journal_mode = DELETE; + CREATE TABLE t1(a PRIMARY KEY, b); + INSERT INTO t1 VALUES(randomblob(1000), randomblob(100)); + INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1; + INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1; + INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1; + INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1; + DELETE FROM t1 WHERE rowid%2; + } + faultsim_save_and_close +} {} + +do_faultsim_test 1 -prep { + faultsim_restore_and_reopen + set ::STMT [sqlite3_prepare db "SELECT * FROM t1 ORDER BY a" -1 DUMMY] + sqlite3_step $::STMT + sqlite3_step $::STMT +} -body { + execsql { PRAGMA incremental_vacuum = 10 } +} -test { + sqlite3_finalize $::STMT + faultsim_test_result {0 {}} + faultsim_integrity_check +} + +#------------------------------------------------------------------------- +# dbsqlfuzz crash-6ef3cd3b18ccc5de86120950a0498641acd90a33.txt +# +reset_db + +do_execsql_test 2.0 { + CREATE TABLE t1(i INTEGER PRIMARY KEY, a, b); + CREATE INDEX i1 ON t1(b); + CREATE TABLE t2(x, y); +} + +do_execsql_test 2.1 { + INSERT INTO t1 VALUES(25, 25, 25); + INSERT INTO t2 VALUES(25, 'a'), (25, 'b'), (25, 'c'); +} + +faultsim_save +do_test 2.2 { + set res [list] + db eval { + SELECT x, y FROM t1 CROSS JOIN t2 WHERE t2.x=t1.i AND +t1.i=25 ORDER BY b + } { + lappend res $x $y + if {$y=="b"} { + db eval { DELETE FROM t1 WHERE i=25 } + } + } + set res +} {25 a 25 b} + +do_faultsim_test 2 -faults oom-t* -prep { + faultsim_restore_and_reopen + db eval {SELECT * FROM sqlite_master} +} -body { + set ::myres [list] + db eval { + SELECT x, y FROM t1 CROSS JOIN t2 WHERE t2.x=t1.i AND +t1.i=25 ORDER BY b + } { + lappend ::myres $x $y + if {$y=="b"} { + db eval { DELETE FROM t1 WHERE i=25 } + } + } + set ::myres +} -test { + faultsim_test_result {0 {25 a 25 b}} +} + + +finish_test diff --git a/test/busy.test b/test/busy.test new file mode 100644 index 0000000..be0515b --- /dev/null +++ b/test/busy.test @@ -0,0 +1,139 @@ +# 2005 july 8 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file test the busy handler +# + + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix busy + +do_test busy-1.1 { + sqlite3 db2 test.db + execsql { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(1); + SELECT * FROM t1 + } +} 1 +proc busy x { + lappend ::busyargs $x + if {$x>2} {return 1} + return 0 +} +set busyargs {} +do_test busy-1.2 { + db busy busy + db2 eval {BEGIN EXCLUSIVE} + catchsql {BEGIN IMMEDIATE} +} {1 {database is locked}} +do_test busy-1.3 { + set busyargs +} {0 1 2 3} +do_test busy-1.4 { + set busyargs {} + catchsql {BEGIN IMMEDIATE} + set busyargs +} {0 1 2 3} + +do_test busy-2.1 { + db2 eval {COMMIT} + db eval {BEGIN; INSERT INTO t1 VALUES(5)} + db2 eval {BEGIN; SELECT * FROM t1} + set busyargs {} + catchsql COMMIT +} {1 {database is locked}} +do_test busy-2.2 { + set busyargs +} {0 1 2 3} + +db2 close + +#------------------------------------------------------------------------- +# Test that the busy-handler is invoked correctly for "PRAGMA optimize" +# and ANALYZE commnds. +ifcapable pragma&&analyze&&!stat4 { + +reset_db + +do_execsql_test 3.1 { + CREATE TABLE t1(x); + CREATE TABLE t2(y); + CREATE TABLE t3(z); + + CREATE INDEX i1 ON t1(x); + CREATE INDEX i2 ON t2(y); + + INSERT INTO t1 VALUES(1); + INSERT INTO t2 VALUES(1); + ANALYZE; + + SELECT * FROM t1 WHERE x=1; + SELECT * FROM t2 WHERE y=1; +} {1 1} + +do_test 3.2 { + sqlite3 db2 test.db + execsql { BEGIN EXCLUSIVE } db2 + catchsql { PRAGMA optimize } +} {1 {database is locked}} + +proc busy_handler {n} { + if {$n>1000} { execsql { COMMIT } db2 } + return 0 +} +db busy busy_handler + +do_test 3.3 { + catchsql { PRAGMA optimize } +} {0 {}} + +do_test 3.4 { + execsql { + BEGIN; + SELECT count(*) FROM sqlite_master; + } db2 +} {6} + +proc busy_handler {n} { return 1 } +do_test 3.5 { + catchsql { PRAGMA optimize } +} {0 {}} + +do_test 3.6 { + execsql { COMMIT } db2 + execsql { + WITH s(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<1000 + ) + INSERT INTO t1 SELECT i FROM s; + } + execsql { + BEGIN; + SELECT count(*) FROM sqlite_master; + } db2 +} {6} + +do_test 3.7 { + catchsql { PRAGMA optimize } +} {1 {database is locked}} + +proc busy_handler {n} { + if {$n>1000} { execsql { COMMIT } db2 } + return 0 +} +do_test 3.8 { + catchsql { PRAGMA optimize } +} {0 {}} + +} + +finish_test diff --git a/test/busy2.test b/test/busy2.test new file mode 100644 index 0000000..ec420c8 --- /dev/null +++ b/test/busy2.test @@ -0,0 +1,171 @@ +# 2020 June 30 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file test the busy handler +# +# TESTRUNNER: slow + + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/lock_common.tcl +set testprefix busy2 + +do_multiclient_test tn { + do_test 1.$tn.0 { + sql2 { + CREATE TABLE t1(a, b); + PRAGMA journal_mode = wal; + INSERT INTO t1 VALUES('A', 'B'); + } + } {wal} + + do_test 1.$tn.1 { + code1 { db timeout 1000 } + sql1 { SELECT * FROM t1 } + } {A B} + + do_test 1.$tn.2 { + sql2 { + BEGIN; + INSERT INTO t1 VALUES('C', 'D'); + } + } {} + + do_test 1.$tn.3 { + set us [lindex [time { catch { sql1 { BEGIN EXCLUSIVE } } }] 0] + expr {$us>950000 && $us<1500000} + } {1} + + do_test 1.$tn.4 { + sql2 { + COMMIT + } + } {} +} + +#------------------------------------------------------------------------- + +do_multiclient_test tn { + # Make the db a WAL mode db. And add a table and a row to it. Then open + # a second connection within process 1. Process 1 now has connections + # [db] and [db1.2], process 2 has connection [db2] only. + # + # Configure all connections to use a 1000 ms timeout. + # + do_test 2.$tn.0 { + code1 { + sqlite3 db1.2 test.db + } + sql1 { + PRAGMA auto_vacuum = off; + PRAGMA journal_mode = wal; + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 2); + } + code2 { + db2 timeout 1000 + } + code1 { + db1.2 timeout 1000 + db timeout 1000 + db1.2 eval {SELECT * FROM t1} + } + } {1 2} + + # Take a read lock with [db] in process 1. + # + do_test 2.$tn.1 { + sql1 { + BEGIN; + SELECT * FROM t1; + } + } {1 2} + + # Insert a row using [db2] in process 2. Then try a passive checkpoint. + # It fails to checkpoint the final frame (due to the readlock taken by + # [db]), and returns in less than 250ms. + do_test 2.$tn.2 { + sql2 { INSERT INTO t1 VALUES(3, 4) } + set us [lindex [time { + set res [code2 { db2 eval { PRAGMA wal_checkpoint } }] + }] 0] + list [expr $us < 250000] $res + } {1 {0 4 3}} + + # Now try a FULL checkpoint with [db2]. It returns SQLITE_BUSY. And takes + # over 950ms to do so. + do_test 2.$tn.3 { + set us [lindex [time { + set res [code2 { db2 eval { PRAGMA wal_checkpoint = FULL } }] + }] 0] + list [expr $us > 950000] $res + } {1 {1 4 3}} + + # Passive checkpoint with [db1.2] (process 1). No SQLITE_BUSY, returns + # in under 250ms. + do_test 2.$tn.4 { + set us [lindex [time { + set res [code1 { db1.2 eval { PRAGMA wal_checkpoint } }] + }] 0] + list [expr $us < 250000] $res + } {1 {0 4 3}} + + # Full checkpoint with [db1.2] (process 1). SQLITE_BUSY returned in + # a bit over 950ms. + do_test 2.$tn.5 { + set us [lindex [time { + set res [code1 { db1.2 eval { PRAGMA wal_checkpoint = FULL } }] + }] 0] + list [expr $us > 950000] $res + } {1 {1 4 3}} + + code1 { + db1.2 close + } +} + +#------------------------------------------------------------------------- +# Check that even if the busy-handler fails (returns zero) within a +# call to sqlite3_prepare() (or _v2(), or _v3()), it is still invoked +# the next time an SQLITE_BUSY is encountered. +# +do_multiclient_test tn { + code1 { + set ::busy_called 0 + proc busy {args} { + if {$::busy_called} { return 1 } + set ::busy_called 1 + return 0 + } + db busy busy + } + + do_test 3.$tn.1 { + sql2 { + CREATE TABLE t1(x); + BEGIN EXCLUSIVE; + INSERT INTO t1 VALUES('x'); + } + } {} + + do_test 3.$tn.2 { + set ::busy_called 0 + list [catch { sql1 { SELECT * FROM t1 } } msg] $::busy_called + } {1 1} + + do_test 3.$tn.3 { + set ::busy_called 0 + list [catch { sql1 { SELECT * FROM t1 } } msg] $::busy_called + } {1 1} + +} + +finish_test diff --git a/test/cache.test b/test/cache.test new file mode 100644 index 0000000..ffc25c4 --- /dev/null +++ b/test/cache.test @@ -0,0 +1,140 @@ +# 2007 March 24 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# $Id: cache.test,v 1.4 2007/08/22 02:56:44 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !pager_pragmas||!compound { + finish_test + return +} +sqlite3_soft_heap_limit 0 + +proc pager_cache_size {db} { + set bt [btree_from_db $db] + db_enter $db + array set stats [btree_pager_stats $bt] + db_leave $db + return $stats(page) +} + +if {[permutation] == ""} { + do_test cache-1.1 { pager_cache_size db } {0} +} + +do_test cache-1.2 { + execsql { + PRAGMA auto_vacuum=OFF; + CREATE TABLE abc(a, b, c); + INSERT INTO abc VALUES(1, 2, 3); + } + pager_cache_size db +} {2} + +# At one point, repeatedly locking and unlocking the cache was causing +# a resource leak of one page per repetition. The page wasn't actually +# leaked, but would not be reused until the pager-cache was full (i.e. +# 2000 pages by default). +# +# This tests that once the pager-cache is initialized, it can be locked +# and unlocked repeatedly without internally allocating any new pages. +# +set cache_size [pager_cache_size db] +for {set ii 0} {$ii < 10} {incr ii} { + do_test cache-1.3.$ii { + execsql {SELECT * FROM abc} + pager_cache_size db + } $::cache_size +} + +#------------------------------------------------------------------------- +# This block of tests checks that it is possible to set the cache_size of a +# database to a small (< 10) value. More specifically: +# +# cache-2.1.*: Test that "PRAGMA cache_size" appears to work with small +# values. +# cache-2.2.*: Test that "PRAGMA main.cache_size" appears to work with +# small values. +# cache-2.3.*: Test cache_size=1 correctly spills/flushes the cache. +# cache-2.4.*: Test cache_size=0 correctly spills/flushes the cache. +# +# +db_delete_and_reopen +do_execsql_test cache-2.0 { + PRAGMA auto_vacuum=OFF; + PRAGMA journal_mode=DELETE; + CREATE TABLE t1(a, b); + CREATE TABLE t2(c, d); + INSERT INTO t1 VALUES('x', 'y'); + INSERT INTO t2 VALUES('i', 'j'); +} {delete} + +for {set i 0} {$i < 20} {incr i} { + do_execsql_test cache-2.1.$i.1 "PRAGMA cache_size = $i" + do_execsql_test cache-2.1.$i.2 "PRAGMA cache_size" $i + do_execsql_test cache-2.1.$i.3 "SELECT * FROM t1" {x y} + do_execsql_test cache-2.1.$i.4 "PRAGMA cache_size" $i +} +for {set i 0} {$i < 20} {incr i} { + do_execsql_test cache-2.2.$i.1 "PRAGMA main.cache_size = $i" + do_execsql_test cache-2.2.$i.2 "PRAGMA main.cache_size" $i + do_execsql_test cache-2.2.$i.3 "SELECT * FROM t1" {x y} + do_execsql_test cache-2.2.$i.4 "PRAGMA main.cache_size" $i +} + +# Tests for cache_size = 1. +# +do_execsql_test cache-2.3.1 { + PRAGMA cache_size = 1; + BEGIN; + INSERT INTO t1 VALUES(1, 2); + PRAGMA lock_status; +} {main reserved temp closed} +do_test cache-2.3.2 { pager_cache_size db } 2 +do_execsql_test cache-2.3.3 { + INSERT INTO t2 VALUES(1, 2); + PRAGMA lock_status; +} {main exclusive temp closed} +do_test cache-2.3.4 { pager_cache_size db } 2 +do_execsql_test cache-2.3.5 COMMIT +do_test cache-2.3.6 { pager_cache_size db } 1 + +do_execsql_test cache-2.3.7 { + SELECT * FROM t1 UNION SELECT * FROM t2; +} {1 2 i j x y} +do_test cache-2.3.8 { pager_cache_size db } 1 + +# Tests for cache_size = 0. +# +do_execsql_test cache-2.4.1 { + PRAGMA cache_size = 0; + BEGIN; + INSERT INTO t1 VALUES(1, 2); + PRAGMA lock_status; +} {main reserved temp closed} +do_test cache-2.4.2 { pager_cache_size db } 2 +do_execsql_test cache-2.4.3 { + INSERT INTO t2 VALUES(1, 2); + PRAGMA lock_status; +} {main exclusive temp closed} +do_test cache-2.4.4 { pager_cache_size db } 2 +do_execsql_test cache-2.4.5 COMMIT + +do_test cache-2.4.6 { pager_cache_size db } 0 +do_execsql_test cache-2.4.7 { + SELECT * FROM t1 UNION SELECT * FROM t2; +} {1 2 i j x y} +do_test cache-2.4.8 { pager_cache_size db } 0 + +sqlite3_soft_heap_limit $cmdlinearg(soft-heap-limit) +finish_test diff --git a/test/cacheflush.test b/test/cacheflush.test new file mode 100644 index 0000000..5046189 --- /dev/null +++ b/test/cacheflush.test @@ -0,0 +1,323 @@ +# 2011 November 16 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file contains test cases for sqlite3_db_cacheflush API. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix cacheflush +test_set_config_pagecache 0 0 + +# Run the supplied SQL on a copy of the database currently stored on +# disk in file $dbfile. +proc diskquery {dbfile sql} { + forcecopy $dbfile dq.db + sqlite3 dq dq.db + set res [execsql $sql dq] + dq close + set res +} + +# Simplest possible test. +# +do_execsql_test 1.1.0 { + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 2); + BEGIN; + INSERT INTO t1 VALUES(3, 4); +} +do_test 1.1.1 { + diskquery test.db { SELECT * FROM t1 } +} {1 2} +do_test 1.1.2 { + sqlite3_db_cacheflush db + diskquery test.db { SELECT * FROM t1 } +} {1 2 3 4} + +# Test that multiple pages may be flushed to disk. +# +do_execsql_test 1.2.0 { + COMMIT; + CREATE TABLE t2(a, b); + BEGIN; + INSERT INTO t1 VALUES(5, 6); + INSERT INTO t2 VALUES('a', 'b'); +} +do_test 1.2.1 { + diskquery test.db { + SELECT * FROM t1; + SELECT * FROM t2; + } +} {1 2 3 4} +do_test 1.2.2 { + sqlite3_db_cacheflush db + diskquery test.db { + SELECT * FROM t1; + SELECT * FROM t2; + } +} {1 2 3 4 5 6 a b} + +# Test that pages with nRef!=0 are not flushed to disk. +# +do_execsql_test 1.3.0 { + COMMIT; + CREATE TABLE t3(a, b); + BEGIN; + INSERT INTO t1 VALUES(7, 8); + INSERT INTO t2 VALUES('c', 'd'); + INSERT INTO t3 VALUES('i', 'ii'); +} +do_test 1.3.1 { + diskquery test.db { + SELECT * FROM t1; + SELECT * FROM t2; + SELECT * FROM t3; + } +} {1 2 3 4 5 6 a b} +do_test 1.3.2 { + db eval { SELECT a FROM t1 } { + if {$a==3} { + sqlite3_db_cacheflush db + } + } + diskquery test.db { + SELECT * FROM t1; + SELECT * FROM t2; + SELECT * FROM t3; + } +} {1 2 3 4 5 6 a b c d i ii} +do_test 1.3.2 { + sqlite3_db_cacheflush db + diskquery test.db { + SELECT * FROM t1; + SELECT * FROM t2; + SELECT * FROM t3; + } +} {1 2 3 4 5 6 7 8 a b c d i ii} + +# Check that SQLITE_BUSY is returned if pages cannot be flushed due to +# conflicting read locks. +# +do_execsql_test 1.4.0 { + COMMIT; + BEGIN; + INSERT INTO t1 VALUES(9, 10); +} +do_test 1.4.1 { + sqlite3 db2 test.db + db2 eval { + BEGIN; + SELECT * FROM t1; + } + diskquery test.db { + SELECT * FROM t1; + } +} {1 2 3 4 5 6 7 8} +do_test 1.4.2 { + list [catch { sqlite3_db_cacheflush db } msg] $msg +} {1 {database is locked}} +do_test 1.4.3 { + diskquery test.db { + SELECT * FROM t1; + } +} {1 2 3 4 5 6 7 8} +do_test 1.4.4 { + db2 close + sqlite3_db_cacheflush db + diskquery test.db { + SELECT * FROM t1; + } +} {1 2 3 4 5 6 7 8 9 10} +do_execsql_test 1.4.5 { COMMIT } + +#------------------------------------------------------------------------- +# Test that ATTACHed database caches are also flushed. +# +forcedelete test.db2 +do_execsql_test 2.1.0 { + ATTACH 'test.db2' AS aux; + CREATE TABLE aux.t4(x, y); + INSERT INTO t4 VALUES('A', 'B'); + BEGIN; + INSERT INTO t1 VALUES(11, 12); + INSERT INTO t4 VALUES('C', 'D'); +} +do_test 2.1.1 { + diskquery test.db { SELECT * FROM t1; } +} {1 2 3 4 5 6 7 8 9 10} +do_test 2.1.2 { + diskquery test.db2 { SELECT * FROM t4; } +} {A B} +do_test 2.1.3 { + sqlite3_db_cacheflush db + diskquery test.db { SELECT * FROM t1; } +} {1 2 3 4 5 6 7 8 9 10 11 12} +do_test 2.1.4 { + sqlite3_db_cacheflush db + diskquery test.db2 { SELECT * FROM t4; } +} {A B C D} +do_execsql_test 2.1.5 { COMMIT } + +# And that hitting an SQLITE_BUSY when flushing "main" does not stop +# SQLite from going on to flush "aux". +# +do_execsql_test 2.2.0 { + BEGIN; + INSERT INTO t1 VALUES(13, 14); + INSERT INTO t4 VALUES('E', 'F'); +} +do_test 2.2.1 { + diskquery test.db { SELECT * FROM t1; } +} {1 2 3 4 5 6 7 8 9 10 11 12} +do_test 2.2.2 { + diskquery test.db2 { SELECT * FROM t4; } +} {A B C D} +do_test 2.2.3 { + sqlite3 db2 test.db + execsql { + BEGIN; + SELECT * FROM t1; + } db2 + list [catch { sqlite3_db_cacheflush db } msg] $msg +} {1 {database is locked}} +do_test 2.2.4 { + diskquery test.db { SELECT * FROM t1; } +} {1 2 3 4 5 6 7 8 9 10 11 12} +do_test 2.2.5 { + diskquery test.db2 { SELECT * FROM t4; } +} {A B C D E F} +do_test 2.2.6 { + db2 close + sqlite3_db_cacheflush db + diskquery test.db { SELECT * FROM t1; } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14} +do_execsql_test 2.2.7 { COMMIT } + +#------------------------------------------------------------------------- +# Test that nothing terrible happens if sqlite3_db_cacheflush() is +# called on an in-memory database. +# +do_test 3.0 { + db close + sqlite3 db :memory: + db eval { + CREATE TABLE t1(x PRIMARY KEY); + CREATE TABLE t2(y PRIMARY KEY); + BEGIN; + INSERT INTO t1 VALUES(randomblob(100)); + INSERT INTO t2 VALUES(randomblob(100)); + INSERT INTO t1 VALUES(randomblob(100)); + INSERT INTO t2 VALUES(randomblob(100)); + } + sqlite3_db_cacheflush db +} {} + +do_execsql_test 3.1 { PRAGMA integrity_check } ok +do_execsql_test 3.2 { COMMIT } +do_execsql_test 3.3 { PRAGMA integrity_check } ok +do_execsql_test 3.4 { + SELECT count(*) FROM t1; + SELECT count(*) FROM t2; +} {2 2} + +#------------------------------------------------------------------------- +# Test that calling sqlite3_db_cacheflush() does not interfere with +# savepoint transactions. +# +do_test 4.0 { + reset_db + execsql { + CREATE TABLE ta(a, aa); + CREATE TABLE tb(b, bb); + INSERT INTO ta VALUES('a', randomblob(500)); + INSERT INTO tb VALUES('b', randomblob(500)); + BEGIN; + UPDATE ta SET a = 'A'; + SAVEPOINT one; + UPDATE tb SET b = 'B'; + } + + sqlite3_db_cacheflush db + diskquery test.db { + SELECT a FROM ta; + SELECT b FROM tb; + } +} {A B} + +do_test 4.1 { + execsql { + ROLLBACK TO one; + } + sqlite3_db_cacheflush db + diskquery test.db { + SELECT a FROM ta; + SELECT b FROM tb; + } +} {A b} + +do_test 4.2 { + execsql { + INSERT INTO tb VALUES('c', randomblob(10)); + INSERT INTO tb VALUES('d', randomblob(10)); + INSERT INTO tb VALUES('e', randomblob(10)); + } + sqlite3_db_cacheflush db + diskquery test.db { + SELECT a FROM ta; + SELECT b FROM tb; + } +} {A b c d e} + +do_test 4.3 { + execsql { + SAVEPOINT two; + UPDATE tb SET b = upper(b); + } + sqlite3_db_cacheflush db + diskquery test.db { + SELECT a FROM ta; + SELECT b FROM tb; + } +} {A B C D E} + +do_test 4.4 { + execsql { + ROLLBACK TO two; + } + sqlite3_db_cacheflush db + diskquery test.db { + SELECT a FROM ta; + SELECT b FROM tb; + } +} {A b c d e} + +do_test 4.4 { + execsql { + ROLLBACK TO one; + } + sqlite3_db_cacheflush db + diskquery test.db { + SELECT a FROM ta; + SELECT b FROM tb; + } +} {A b} + +do_test 4.5 { + execsql { + ROLLBACK; + SELECT a FROM ta; + SELECT b FROM tb; + } +} {a b} + +test_restore_config_pagecache +finish_test diff --git a/test/cachespill.test b/test/cachespill.test new file mode 100644 index 0000000..0692513 --- /dev/null +++ b/test/cachespill.test @@ -0,0 +1,77 @@ +# 2017 April 26 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix cachespill + +ifcapable !pager_pragmas { + finish_test + return +} + +#------------------------------------------------------------------------- +# Test that "PRAGMA cache_spill = 0" completely disables cache spilling. +# +do_execsql_test 1.1 { + PRAGMA auto_vacuum = 0; + PRAGMA page_size = 1024; + PRAGMA cache_size = 100; + CREATE TABLE t1(a); +} + +do_test 1.2 { + file size test.db +} {2048} + +do_test 1.3 { + execsql { + BEGIN; + WITH s(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<200 + ) INSERT INTO t1 SELECT randomblob(900) FROM s; + } + expr {[file size test.db] > 50000} +} {1} + +do_test 1.4 { + execsql ROLLBACK + file size test.db +} {2048} + +do_test 1.5 { + execsql { + PRAGMA cache_spill = 0; + BEGIN; + WITH s(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<200 + ) INSERT INTO t1 SELECT randomblob(900) FROM s; + } + file size test.db +} {2048} + +do_test 1.5 { + execsql { + ROLLBACK; + PRAGMA cache_spill = 1; + BEGIN; + WITH s(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<200 + ) INSERT INTO t1 SELECT randomblob(900) FROM s; + } + expr {[file size test.db] > 50000} +} {1} + +do_execsql_test 1.6 { ROLLBACK } + + +finish_test diff --git a/test/capi2.test b/test/capi2.test new file mode 100644 index 0000000..de47ab3 --- /dev/null +++ b/test/capi2.test @@ -0,0 +1,803 @@ +# 2003 January 29 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script testing the callback-free C/C++ API. +# +# $Id: capi2.test,v 1.37 2008/12/30 17:55:00 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Return the text values from the current row pointed at by STMT as a list. +proc get_row_values {STMT} { + set VALUES [list] + for {set i 0} {$i < [sqlite3_data_count $STMT]} {incr i} { + lappend VALUES [sqlite3_column_text $STMT $i] + } + return $VALUES +} + +# Return the column names followed by declaration types for the result set +# of the SQL statement STMT. +# +# i.e. for: +# CREATE TABLE abc(a text, b integer); +# SELECT * FROM abc; +# +# The result is {a b text integer} +proc get_column_names {STMT} { + set VALUES [list] + for {set i 0} {$i < [sqlite3_column_count $STMT]} {incr i} { + lappend VALUES [sqlite3_column_name $STMT $i] + } + for {set i 0} {$i < [sqlite3_column_count $STMT]} {incr i} { + lappend VALUES [sqlite3_column_decltype $STMT $i] + } + return $VALUES +} + +# Check basic functionality +# +do_test capi2-1.1 { + set DB [sqlite3_connection_pointer db] + execsql {CREATE TABLE t1(a,b,c)} + set VM [sqlite3_prepare $DB {SELECT name, rowid FROM sqlite_master} -1 TAIL] + set TAIL +} {} +do_test capi2-1.2 { + sqlite3_step $VM +} {SQLITE_ROW} +do_test capi2-1.3 { + sqlite3_data_count $VM +} {2} +do_test capi2-1.4 { + get_row_values $VM +} {t1 1} +do_test capi2-1.5 { + get_column_names $VM +} {name rowid TEXT INTEGER} +do_test capi2-1.6 { + sqlite3_step $VM +} {SQLITE_DONE} +do_test capi2-1.7 { + list [sqlite3_column_count $VM] [get_row_values $VM] [get_column_names $VM] +} {2 {} {name rowid TEXT INTEGER}} + +# This used to be SQLITE_MISUSE. But now we automatically reset prepared +# statements. +ifcapable autoreset { + do_test capi2-1.8 { + sqlite3_step $VM + } {SQLITE_ROW} +} else { + do_test capi2-1.8 { + sqlite3_step $VM + } {SQLITE_MISUSE} +} + +# Update: In v2, once SQLITE_MISUSE is returned the statement handle cannot +# be interrogated for more information. However in v3, since the column +# count, names and types are determined at compile time, these are still +# accessible after an SQLITE_MISUSE error. +do_test capi2-1.9 { + sqlite3_reset $VM + list [sqlite3_column_count $VM] [get_row_values $VM] [get_column_names $VM] +} {2 {} {name rowid TEXT INTEGER}} +do_test capi2-1.10 { + sqlite3_data_count $VM +} {0} + +do_test capi2-1.11 { + sqlite3_finalize $VM +} {SQLITE_OK} + +# Check to make sure that the "tail" of a multi-statement SQL script +# is returned by sqlite3_prepare. +# +do_test capi2-2.1 { + set SQL { + SELECT name, rowid FROM sqlite_master; + SELECT name, rowid FROM sqlite_master WHERE 0; + -- A comment at the end + } + set VM [sqlite3_prepare $DB $SQL -1 SQL] + set SQL +} { + SELECT name, rowid FROM sqlite_master WHERE 0; + -- A comment at the end + } +do_test capi2-2.2 { + set r [sqlite3_step $VM] + lappend r [sqlite3_column_count $VM] \ + [get_row_values $VM] \ + [get_column_names $VM] +} {SQLITE_ROW 2 {t1 1} {name rowid TEXT INTEGER}} +do_test capi2-2.3 { + set r [sqlite3_step $VM] + lappend r [sqlite3_column_count $VM] \ + [get_row_values $VM] \ + [get_column_names $VM] +} {SQLITE_DONE 2 {} {name rowid TEXT INTEGER}} +do_test capi2-2.4 { + sqlite3_finalize $VM +} {SQLITE_OK} +do_test capi2-2.5 { + set VM [sqlite3_prepare $DB $SQL -1 SQL] + set SQL +} { + -- A comment at the end + } +do_test capi2-2.6 { + set r [sqlite3_step $VM] + lappend r [sqlite3_column_count $VM] \ + [get_row_values $VM] \ + [get_column_names $VM] +} {SQLITE_DONE 2 {} {name rowid TEXT INTEGER}} +do_test capi2-2.7 { + sqlite3_finalize $VM +} {SQLITE_OK} +do_test capi2-2.8 { + set VM [sqlite3_prepare $DB $SQL -1 SQL] + list $SQL $VM +} {{} {}} + +# Check the error handling. +# +do_test capi2-3.1 { + set rc [catch { + sqlite3_prepare $DB {select bogus from sqlite_master} -1 TAIL + } msg] + lappend rc $msg $TAIL +} {1 {(1) no such column: bogus} {}} +do_test capi2-3.2 { + set rc [catch { + sqlite3_prepare $DB {select bogus from } -1 TAIL + } msg] + lappend rc $msg $TAIL +} {1 {(1) incomplete input} {}} +do_test capi2-3.3 { + set rc [catch { + sqlite3_prepare $DB {;;;;select bogus from sqlite_master} -1 TAIL + } msg] + lappend rc $msg $TAIL +} {1 {(1) no such column: bogus} {}} +do_test capi2-3.4 { + set rc [catch { + sqlite3_prepare $DB {select bogus from sqlite_master;x;} -1 TAIL + } msg] + lappend rc $msg $TAIL +} {1 {(1) no such column: bogus} {x;}} +do_test capi2-3.5 { + set rc [catch { + sqlite3_prepare $DB {select bogus from sqlite_master;;;x;} -1 TAIL + } msg] + lappend rc $msg $TAIL +} {1 {(1) no such column: bogus} {;;x;}} +do_test capi2-3.6 { + set rc [catch { + sqlite3_prepare $DB {select 5/0;} -1 TAIL + } VM] + lappend rc $TAIL +} {0 {}} +do_test capi2-3.7 { + list [sqlite3_step $VM] \ + [sqlite3_column_count $VM] \ + [get_row_values $VM] \ + [get_column_names $VM] +} {SQLITE_ROW 1 {{}} {5/0 {}}} +do_test capi2-3.8 { + sqlite3_finalize $VM +} {SQLITE_OK} +do_test capi2-3.9 { + execsql {CREATE UNIQUE INDEX i1 ON t1(a)} + set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES(1,2,3)} -1 TAIL] + set TAIL +} {} +do_test capi2-3.9b {db changes} {0} +do_test capi2-3.10 { + list [sqlite3_step $VM] \ + [sqlite3_column_count $VM] \ + [get_row_values $VM] \ + [get_column_names $VM] +} {SQLITE_DONE 0 {} {}} + +# Update for v3 - the change has not actually happened until the query is +# finalized. Is this going to cause trouble for anyone? Lee Nelson maybe? +# (Later:) The change now happens just before SQLITE_DONE is returned. +do_test capi2-3.10b {db changes} {1} +do_test capi2-3.11 { + sqlite3_finalize $VM +} {SQLITE_OK} +do_test capi2-3.11b {db changes} {1} +#do_test capi2-3.12-misuse { +# sqlite3_finalize $VM +#} {SQLITE_MISUSE} +do_test capi2-3.13 { + set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES(1,3,4)} -1 TAIL] + list [sqlite3_step $VM] \ + [sqlite3_column_count $VM] \ + [get_row_values $VM] \ + [get_column_names $VM] +} {SQLITE_ERROR 0 {} {}} + +# Update for v3: Preparing a statement does not affect the change counter. +# (Test result changes from 0 to 1). (Later:) change counter updates occur +# when sqlite3_step returns, not at finalize time. +do_test capi2-3.13b {db changes} {0} + +do_test capi2-3.14 { + list [sqlite3_finalize $VM] [sqlite3_errmsg $DB] \ + [sqlite3_extended_errcode $DB] +} {SQLITE_CONSTRAINT {UNIQUE constraint failed: t1.a} SQLITE_CONSTRAINT_UNIQUE} +do_test capi2-3.15 { + set VM [sqlite3_prepare $DB {CREATE TABLE t2(a NOT NULL, b)} -1 TAIL] + set TAIL +} {} +do_test capi2-3.16 { + list [sqlite3_step $VM] \ + [sqlite3_column_count $VM] \ + [get_row_values $VM] \ + [get_column_names $VM] +} {SQLITE_DONE 0 {} {}} +do_test capi2-3.17 { + list [sqlite3_finalize $VM] [sqlite3_errmsg $DB] +} {SQLITE_OK {not an error}} +do_test capi2-3.18 { + set VM [sqlite3_prepare $DB {INSERT INTO t2 VALUES(NULL,2)} -1 TAIL] + list [sqlite3_step $VM] \ + [sqlite3_column_count $VM] \ + [get_row_values $VM] \ + [get_column_names $VM] +} {SQLITE_ERROR 0 {} {}} +do_test capi2-3.19 { + list [sqlite3_finalize $VM] [sqlite3_errmsg $DB] \ + [sqlite3_extended_errcode $DB] +} {SQLITE_CONSTRAINT {NOT NULL constraint failed: t2.a} SQLITE_CONSTRAINT_NOTNULL} + +do_test capi2-3.20 { + execsql { + CREATE TABLE a1(message_id, name , UNIQUE(message_id, name) ); + INSERT INTO a1 VALUES(1, 1); + } +} {} +do_test capi2-3.21 { + set VM [sqlite3_prepare $DB {INSERT INTO a1 VALUES(1, 1)} -1 TAIL] + sqlite3_step $VM +} {SQLITE_ERROR} +do_test capi2-3.22 { + sqlite3_errcode $DB +} {SQLITE_ERROR} +do_test capi2-3.23 { + sqlite3_finalize $VM +} {SQLITE_CONSTRAINT} +do_test capi2-3.24 { + list [sqlite3_errcode $DB] [sqlite3_extended_errcode $DB] +} {SQLITE_CONSTRAINT SQLITE_CONSTRAINT_UNIQUE} + +# Two or more virtual machines exists at the same time. +# +do_test capi2-4.1 { + set VM1 [sqlite3_prepare $DB {INSERT INTO t2 VALUES(1,2)} -1 TAIL] + set TAIL +} {} +do_test capi2-4.2 { + set VM2 [sqlite3_prepare $DB {INSERT INTO t2 VALUES(2,3)} -1 TAIL] + set TAIL +} {} +do_test capi2-4.3 { + set VM3 [sqlite3_prepare $DB {INSERT INTO t2 VALUES(3,4)} -1 TAIL] + set TAIL +} {} +do_test capi2-4.4 { + list [sqlite3_step $VM2] \ + [sqlite3_column_count $VM2] \ + [get_row_values $VM2] \ + [get_column_names $VM2] +} {SQLITE_DONE 0 {} {}} +do_test capi2-4.5 { + execsql {SELECT * FROM t2 ORDER BY a} +} {2 3} +do_test capi2-4.6 { + sqlite3_finalize $VM2 +} {SQLITE_OK} +do_test capi2-4.7 { + list [sqlite3_step $VM3] \ + [sqlite3_column_count $VM3] \ + [get_row_values $VM3] \ + [get_column_names $VM3] +} {SQLITE_DONE 0 {} {}} +do_test capi2-4.8 { + execsql {SELECT * FROM t2 ORDER BY a} +} {2 3 3 4} +do_test capi2-4.9 { + sqlite3_finalize $VM3 +} {SQLITE_OK} +do_test capi2-4.10 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_DONE 0 {} {}} +do_test capi2-4.11 { + execsql {SELECT * FROM t2 ORDER BY a} +} {1 2 2 3 3 4} +do_test capi2-4.12 { + sqlite3_finalize $VM1 +} {SQLITE_OK} + +# Interleaved SELECTs +# +do_test capi2-5.1 { + set VM1 [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL] + set VM2 [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL] + set VM3 [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL] + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 2 {2 3} {a b {} {}}} +do_test capi2-5.2 { + list [sqlite3_step $VM2] \ + [sqlite3_column_count $VM2] \ + [get_row_values $VM2] \ + [get_column_names $VM2] +} {SQLITE_ROW 2 {2 3} {a b {} {}}} +do_test capi2-5.3 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 2 {3 4} {a b {} {}}} +do_test capi2-5.4 { + list [sqlite3_step $VM3] \ + [sqlite3_column_count $VM3] \ + [get_row_values $VM3] \ + [get_column_names $VM3] +} {SQLITE_ROW 2 {2 3} {a b {} {}}} +do_test capi2-5.5 { + list [sqlite3_step $VM3] \ + [sqlite3_column_count $VM3] \ + [get_row_values $VM3] \ + [get_column_names $VM3] +} {SQLITE_ROW 2 {3 4} {a b {} {}}} +do_test capi2-5.6 { + list [sqlite3_step $VM3] \ + [sqlite3_column_count $VM3] \ + [get_row_values $VM3] \ + [get_column_names $VM3] +} {SQLITE_ROW 2 {1 2} {a b {} {}}} +do_test capi2-5.7 { + list [sqlite3_step $VM3] \ + [sqlite3_column_count $VM3] \ + [get_row_values $VM3] \ + [get_column_names $VM3] +} {SQLITE_DONE 2 {} {a b {} {}}} +do_test capi2-5.8 { + sqlite3_finalize $VM3 +} {SQLITE_OK} +do_test capi2-5.9 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 2 {1 2} {a b {} {}}} +do_test capi2-5.10 { + sqlite3_finalize $VM1 +} {SQLITE_OK} +do_test capi2-5.11 { + list [sqlite3_step $VM2] \ + [sqlite3_column_count $VM2] \ + [get_row_values $VM2] \ + [get_column_names $VM2] +} {SQLITE_ROW 2 {3 4} {a b {} {}}} +do_test capi2-5.12 { + list [sqlite3_step $VM2] \ + [sqlite3_column_count $VM2] \ + [get_row_values $VM2] \ + [get_column_names $VM2] +} {SQLITE_ROW 2 {1 2} {a b {} {}}} +do_test capi2-5.11 { + sqlite3_finalize $VM2 +} {SQLITE_OK} + +# Check for proper SQLITE_BUSY returns. +# +do_test capi2-6.1 { + execsql { + BEGIN; + CREATE TABLE t3(x counter); + INSERT INTO t3 VALUES(1); + INSERT INTO t3 VALUES(2); + INSERT INTO t3 SELECT x+2 FROM t3; + INSERT INTO t3 SELECT x+4 FROM t3; + INSERT INTO t3 SELECT x+8 FROM t3; + COMMIT; + } + set VM1 [sqlite3_prepare $DB {SELECT * FROM t3} -1 TAIL] + sqlite3 db2 test.db + execsql {BEGIN} db2 +} {} +# Update for v3: BEGIN doesn't write-lock the database. It is quite +# difficult to get v3 to write-lock the database, which causes a few +# problems for test scripts. +# +# do_test capi2-6.2 { +# list [sqlite3_step $VM1] \ +# [sqlite3_column_count $VM1] \ +# [get_row_values $VM1] \ +# [get_column_names $VM1] +# } {SQLITE_BUSY 0 {} {}} +do_test capi2-6.3 { + execsql {COMMIT} db2 +} {} +do_test capi2-6.4 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 1 1 {x counter}} +do_test capi2-6.5 { + catchsql {INSERT INTO t3 VALUES(10);} db2 +} {1 {database is locked}} +do_test capi2-6.6 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 1 2 {x counter}} +do_test capi2-6.7 { + execsql {SELECT * FROM t2} db2 +} {2 3 3 4 1 2} +do_test capi2-6.8 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 1 3 {x counter}} +do_test capi2-6.9 { + execsql {SELECT * FROM t2} +} {2 3 3 4 1 2} +do_test capi2-6.10 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 1 4 {x counter}} +do_test capi2-6.11 { + execsql {BEGIN} +} {} +do_test capi2-6.12 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 1 5 {x counter}} + +# A read no longer blocks a write in the same connection. +#do_test capi2-6.13 { +# catchsql {UPDATE t3 SET x=x+1} +#} {1 {database table is locked}} + +do_test capi2-6.14 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 1 6 {x counter}} +do_test capi2-6.15 { + execsql {SELECT * FROM t1} +} {1 2 3} +do_test capi2-6.16 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 1 7 {x counter}} +do_test capi2-6.17 { + catchsql {UPDATE t1 SET b=b+1} +} {0 {}} +do_test capi2-6.18 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 1 8 {x counter}} +do_test capi2-6.19 { + execsql {SELECT * FROM t1} +} {1 3 3} +do_test capi2-6.20 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 1 9 {x counter}} +#do_test capi2-6.21 { +# execsql {ROLLBACK; SELECT * FROM t1} +#} {1 2 3} +do_test capi2-6.22 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 1 10 {x counter}} +#do_test capi2-6.23 { +# execsql {BEGIN TRANSACTION;} +#} {} +do_test capi2-6.24 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 1 11 {x counter}} +do_test capi2-6.25 { + execsql { + INSERT INTO t1 VALUES(2,3,4); + SELECT * FROM t1; + } +} {1 3 3 2 3 4} +do_test capi2-6.26 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 1 12 {x counter}} +do_test capi2-6.27 { + catchsql { + INSERT INTO t1 VALUES(2,4,5); + SELECT * FROM t1; + } +} {1 {UNIQUE constraint failed: t1.a}} +do_test capi2-6.28 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 1 13 {x counter}} +do_test capi2-6.99 { + sqlite3_finalize $VM1 +} {SQLITE_OK} +catchsql {ROLLBACK} + +do_test capi2-7.1 { + stepsql $DB { + SELECT * FROM t1 + } +} {0 1 2 3} +do_test capi2-7.2 { + stepsql $DB { + PRAGMA count_changes=on + } +} {0} +do_test capi2-7.3 { + stepsql $DB { + UPDATE t1 SET a=a+10; + } +} {0 1} +do_test capi2-7.4 { + stepsql $DB { + INSERT INTO t1 SELECT a+1,b+1,c+1 FROM t1; + } +} {0 1} +do_test capi2-7.4b {sqlite3_changes $DB} {1} +do_test capi2-7.5 { + stepsql $DB { + UPDATE t1 SET a=a+10; + } +} {0 2} +do_test capi2-7.5b {sqlite3_changes $DB} {2} +do_test capi2-7.6 { + stepsql $DB { + SELECT * FROM t1; + } +} {0 21 2 3 22 3 4} +do_test capi2-7.7 { + stepsql $DB { + INSERT INTO t1 SELECT a+2,b+2,c+2 FROM t1; + } +} {0 2} +do_test capi2-7.8 { + sqlite3_changes $DB +} {2} +do_test capi2-7.9 { + stepsql $DB { + SELECT * FROM t1; + } +} {0 21 2 3 22 3 4 23 4 5 24 5 6} +do_test capi2-7.10 { + stepsql $DB { + UPDATE t1 SET a=a-20; + SELECT * FROM t1; + } +} {0 4 1 2 3 2 3 4 3 4 5 4 5 6} + +# Update for version 3: A SELECT statement no longer resets the change +# counter (Test result changes from 0 to 4). +do_test capi2-7.11 { + sqlite3_changes $DB +} {4} +do_test capi2-7.11a { + execsql {SELECT count(*) FROM t1} +} {4} + +ifcapable {explain} { + do_test capi2-7.12 { + set x [stepsql $DB {EXPLAIN SELECT * FROM t1}] + lindex $x 0 + } {0} +} + +# Ticket #261 - make sure we can finalize before the end of a query. +# +do_test capi2-8.1 { + set VM1 [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL] + sqlite3_finalize $VM1 +} {SQLITE_OK} + +# Tickets #384 and #385 - make sure the TAIL argument to sqlite3_prepare +# and all of the return pointers in sqlite_step can be null. +# +do_test capi2-9.1 { + set VM1 [sqlite3_prepare $DB {SELECT * FROM t2} -1 DUMMY] + sqlite3_step $VM1 + sqlite3_finalize $VM1 +} {SQLITE_OK} + +# Test that passing a NULL pointer to sqlite3_finalize() or sqlite3_reset +# does not cause an error. +do_test capi2-10.1 { + sqlite3_finalize 0 +} {SQLITE_OK} +do_test capi2-10.2 { + sqlite3_reset 0 +} {SQLITE_OK} + +#--------------------------------------------------------------------------- +# The following tests - capi2-11.* - test the "column origin" APIs. +# +# sqlite3_column_origin_name() +# sqlite3_column_database_name() +# sqlite3_column_table_name() +# + +ifcapable columnmetadata { + +# This proc uses the database handle $::DB to compile the SQL statement passed +# as a parameter. The return value of this procedure is a list with one +# element for each column returned by the compiled statement. Each element of +# this list is itself a list of length three, consisting of the origin +# database, table and column for the corresponding returned column. +proc check_origins {sql} { + set ret [list] + set ::STMT [sqlite3_prepare $::DB $sql -1 dummy] + for {set i 0} {$i < [sqlite3_column_count $::STMT]} {incr i} { + lappend ret [list \ + [sqlite3_column_database_name $::STMT $i] \ + [sqlite3_column_table_name $::STMT $i] \ + [sqlite3_column_origin_name $::STMT $i] \ + ] + } + sqlite3_finalize $::STMT + return $ret +} +do_test capi2-11.1 { + execsql { + CREATE TABLE tab1(col1, col2); + } +} {} +do_test capi2-11.2 { + check_origins {SELECT col2, col1 FROM tab1} +} [list {main tab1 col2} {main tab1 col1}] +do_test capi2-11.3 { + check_origins {SELECT col2 AS hello, col1 AS world FROM tab1} +} [list {main tab1 col2} {main tab1 col1}] + +ifcapable subquery { + do_test capi2-11.4 { + check_origins {SELECT b, a FROM (SELECT col1 AS a, col2 AS b FROM tab1)} + } [list {main tab1 col2} {main tab1 col1}] + do_test capi2-11.5 { + check_origins {SELECT (SELECT col2 FROM tab1), (SELECT col1 FROM tab1)} + } [list {main tab1 col2} {main tab1 col1}] + do_test capi2-11.6 { + check_origins {SELECT (SELECT col2), (SELECT col1) FROM tab1} + } [list {main tab1 col2} {main tab1 col1}] + do_test capi2-11.7 { + check_origins {SELECT * FROM tab1} + } [list {main tab1 col1} {main tab1 col2}] + do_test capi2-11.8 { + check_origins {SELECT * FROM (SELECT * FROM tab1)} + } [list {main tab1 col1} {main tab1 col2}] +} + +ifcapable view&&subquery { + do_test capi2-12.1 { + execsql { + CREATE VIEW view1 AS SELECT * FROM tab1; + } + } {} + do_test capi2-12.2 { + check_origins {SELECT col2, col1 FROM view1} + } [list {main tab1 col2} {main tab1 col1}] + do_test capi2-12.3 { + check_origins {SELECT col2 AS hello, col1 AS world FROM view1} + } [list {main tab1 col2} {main tab1 col1}] + do_test capi2-12.4 { + check_origins {SELECT b, a FROM (SELECT col1 AS a, col2 AS b FROM view1)} + } [list {main tab1 col2} {main tab1 col1}] + do_test capi2-12.5 { + check_origins {SELECT (SELECT col2 FROM view1), (SELECT col1 FROM view1)} + } [list {main tab1 col2} {main tab1 col1}] + do_test capi2-12.6 { + check_origins {SELECT (SELECT col2), (SELECT col1) FROM view1} + } [list {main tab1 col2} {main tab1 col1}] + do_test capi2-12.7 { + check_origins {SELECT * FROM view1} + } [list {main tab1 col1} {main tab1 col2}] + do_test capi2-12.8 { + check_origins {select * from (select * from view1)} + } [list {main tab1 col1} {main tab1 col2}] + do_test capi2-12.9 { + check_origins {select * from (select * from (select * from view1))} + } [list {main tab1 col1} {main tab1 col2}] + do_test capi2-12.10 { + db close + sqlite3 db test.db + set ::DB [sqlite3_connection_pointer db] + check_origins {select * from (select * from (select * from view1))} + } [list {main tab1 col1} {main tab1 col2}] + + # This view will thwart the flattening optimization. + do_test capi2-13.1 { + execsql { + CREATE VIEW view2 AS SELECT * FROM tab1 limit 10 offset 10; + } + } {} + do_test capi2-13.2 { + check_origins {SELECT col2, col1 FROM view2} + } [list {main tab1 col2} {main tab1 col1}] + do_test capi2-13.3 { + check_origins {SELECT col2 AS hello, col1 AS world FROM view2} + } [list {main tab1 col2} {main tab1 col1}] + do_test capi2-13.4 { + check_origins {SELECT b, a FROM (SELECT col1 AS a, col2 AS b FROM view2)} + } [list {main tab1 col2} {main tab1 col1}] + do_test capi2-13.5 { + check_origins {SELECT (SELECT col2 FROM view2), (SELECT col1 FROM view2)} + } [list {main tab1 col2} {main tab1 col1}] + do_test capi2-13.6 { + check_origins {SELECT (SELECT col2), (SELECT col1) FROM view2} + } [list {main tab1 col2} {main tab1 col1}] + do_test capi2-13.7 { + check_origins {SELECT * FROM view2} + } [list {main tab1 col1} {main tab1 col2}] + do_test capi2-13.8 { + check_origins {select * from (select * from view2)} + } [list {main tab1 col1} {main tab1 col2}] + do_test capi2-13.9 { + check_origins {select * from (select * from (select * from view2))} + } [list {main tab1 col1} {main tab1 col2}] + do_test capi2-13.10 { + db close + sqlite3 db test.db + set ::DB [sqlite3_connection_pointer db] + check_origins {select * from (select * from (select * from view2))} + } [list {main tab1 col1} {main tab1 col2}] + do_test capi2-13.11 { + check_origins {select * from (select * from tab1 limit 10 offset 10)} + } [list {main tab1 col1} {main tab1 col2}] +} + + +} ;# ifcapable columnmetadata + +db2 close +finish_test diff --git a/test/capi3.test b/test/capi3.test new file mode 100644 index 0000000..40d87ac --- /dev/null +++ b/test/capi3.test @@ -0,0 +1,1276 @@ +# 2003 January 29 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script testing the callback-free C/C++ API. +# +# $Id: capi3.test,v 1.70 2009/01/09 02:49:32 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix capi3 + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +# Return the UTF-16 representation of the supplied UTF-8 string $str. +# If $nt is true, append two 0x00 bytes as a nul terminator. +proc utf16 {str {nt 1}} { + set r [encoding convertto unicode $str] + if {$nt} { + append r "\x00\x00" + } + return $r +} + +# Return the UTF-8 representation of the supplied UTF-16 string $str. +proc utf8 {str} { + # If $str ends in two 0x00 0x00 bytes, knock these off before + # converting to UTF-8 using TCL. + binary scan $str \c* vals + if {[lindex $vals end]==0 && [lindex $vals end-1]==0} { + set str [binary format \c* [lrange $vals 0 end-2]] + } + + set r [encoding convertfrom unicode $str] + return $r +} + +# These tests complement those in capi2.test. They are organized +# as follows: +# +# capi3-1.*: Test sqlite3_prepare +# capi3-2.*: Test sqlite3_prepare16 +# capi3-3.*: Test sqlite3_open +# capi3-4.*: Test sqlite3_open16 +# capi3-5.*: Test the various sqlite3_result_* APIs +# capi3-6.*: Test that sqlite3_close fails if there are outstanding VMs. +# + +set DB [sqlite3_connection_pointer db] + +do_test capi3-1.0 { + sqlite3_get_autocommit $DB +} 1 +do_test capi3-1.1 { + set STMT [sqlite3_prepare $DB {SELECT name FROM sqlite_master} -1 TAIL] + sqlite3_finalize $STMT + set TAIL +} {} +do_test capi3-1.2.1 { + sqlite3_errcode $DB +} {SQLITE_OK} +do_test capi3-1.2.2 { + sqlite3_extended_errcode $DB +} {SQLITE_OK} +do_test capi3-1.3 { + sqlite3_errmsg $DB +} {not an error} +do_test capi3-1.4 { + set sql {SELECT name FROM sqlite_master;SELECT 10} + set STMT [sqlite3_prepare $DB $sql -1 TAIL] + sqlite3_finalize $STMT + set TAIL +} {SELECT 10} +do_test capi3-1.5 { + set sql {SELECT name FROM sqlite_master;SELECT 10} + set STMT [sqlite3_prepare $DB $sql [string length $sql] TAIL] + sqlite3_finalize $STMT + set TAIL +} {SELECT 10} +do_test capi3-1.6 { + set sql {SELECT name FROM sqlite_master;SELECT 10} + set STMT [sqlite3_prepare $DB $sql [expr [string length $sql]+1] TAIL] + sqlite3_finalize $STMT + set TAIL +} {SELECT 10} + +do_test capi3-1.7 { + set sql {SELECT namex FROM sqlite_master} + catch { + set STMT [sqlite3_prepare $DB $sql -1 TAIL] + } +} {1} +do_test capi3-1.8.1 { + sqlite3_errcode $DB +} {SQLITE_ERROR} +do_test capi3-1.8.2 { + sqlite3_extended_errcode $DB +} {SQLITE_ERROR} +do_test capi3-1.9 { + sqlite3_errmsg $DB +} {no such column: namex} + +ifcapable {utf16} { + do_test capi3-2.1 { + set sql16 [utf16 {SELECT name FROM sqlite_master}] + set STMT [sqlite3_prepare16 $DB $sql16 -1 ::TAIL] + sqlite3_finalize $STMT + utf8 $::TAIL + } {} + do_test capi3-2.2 { + set sql [utf16 {SELECT name FROM sqlite_master;SELECT 10}] + set STMT [sqlite3_prepare16 $DB $sql -1 TAIL] + sqlite3_finalize $STMT + utf8 $TAIL + } {SELECT 10} + do_test capi3-2.3 { + set sql [utf16 {SELECT namex FROM sqlite_master}] + catch { + set STMT [sqlite3_prepare16 $DB $sql -1] + } + } {1} + do_test capi3-2.4.1 { + sqlite3_errcode $DB + } {SQLITE_ERROR} + do_test capi3-2.4.2 { + sqlite3_extended_errcode $DB + } {SQLITE_ERROR} + do_test capi3-2.5 { + sqlite3_errmsg $DB + } {no such column: namex} + + ifcapable schema_pragmas { + do_test capi3-2.6 { + execsql {CREATE TABLE tablename(x)} + set sql16 [utf16 {PRAGMA table_info("TableName"); --excess text}] + set STMT [sqlite3_prepare16 $DB $sql16 -1] + sqlite3_step $STMT + } SQLITE_ROW + do_test capi3-2.7 { + sqlite3_step $STMT + } SQLITE_DONE + do_test capi3-2.8 { + sqlite3_finalize $STMT + } SQLITE_OK + } + +} ;# endif utf16 + +# rename sqlite3_open sqlite3_open_old +# proc sqlite3_open {fname options} {sqlite3_open_new $fname $options} + +do_test capi3-3.1 { + set db2 [sqlite3_open test.db {}] + sqlite3_errcode $db2 +} {SQLITE_OK} +# FIX ME: Should test the db handle works. +do_test capi3-3.2 { + sqlite3_close $db2 +} {SQLITE_OK} +do_test capi3-3.3 { + catch { + set db2 [sqlite3_open /bogus/path/test.db {}] + } + set ::capi3_errno [sqlite3_system_errno $db2] + list [sqlite3_extended_errcode $db2] [expr {$::capi3_errno!=0}] +} {SQLITE_CANTOPEN 1} +do_test capi3-3.4 { + sqlite3_errmsg $db2 +} {unable to open database file} +do_test capi3-3.5 { + list [sqlite3_system_errno $db2] [sqlite3_close $db2] +} [list $::capi3_errno SQLITE_OK] +if {[clang_sanitize_address]==0} { + do_test capi3-3.6.1-misuse { + sqlite3_close $db2 + } {SQLITE_MISUSE} + do_test capi3-3.6.2-misuse { + sqlite3_errmsg $db2 + } {bad parameter or other API misuse} + ifcapable {utf16} { + do_test capi3-3.6.3-misuse { + utf8 [sqlite3_errmsg16 $db2] + } {bad parameter or other API misuse} + } +} + +do_test capi3-3.7 { + set db2 [sqlite3_open] + sqlite3_errcode $db2 +} {SQLITE_OK} +do_test capi3-3.8 { + sqlite3_close $db2 +} {SQLITE_OK} + +# rename sqlite3_open "" +# rename sqlite3_open_old sqlite3_open + +ifcapable {utf16} { +do_test capi3-4.1 { + set db2 [sqlite3_open16 [utf16 test.db] {}] + sqlite3_errcode $db2 +} {SQLITE_OK} +# FIX ME: Should test the db handle works. +do_test capi3-4.2 { + sqlite3_close $db2 +} {SQLITE_OK} +do_test capi3-4.3 { + catch { + set db2 [sqlite3_open16 [utf16 /bogus/path/test.db] {}] + } + sqlite3_errcode $db2 +} {SQLITE_CANTOPEN} +do_test capi3-4.4 { + utf8 [sqlite3_errmsg16 $db2] +} {unable to open database file} +do_test capi3-4.5 { + sqlite3_close $db2 +} {SQLITE_OK} +} ;# utf16 + +# This proc is used to test the following API calls: +# +# sqlite3_column_count +# sqlite3_column_name +# sqlite3_column_name16 +# sqlite3_column_decltype +# sqlite3_column_decltype16 +# +# $STMT is a compiled SQL statement. $test is a prefix +# to use for test names within this proc. $names is a list +# of the column names that should be returned by $STMT. +# $decltypes is a list of column declaration types for $STMT. +# +# Example: +# +# set STMT [sqlite3_prepare "SELECT 1, 2, 2;" -1 DUMMY] +# check_header test1.1 {1 2 3} {"" "" ""} +# +proc check_header {STMT test names decltypes} { + + # Use the return value of sqlite3_column_count() to build + # a list of column indexes. i.e. If sqlite3_column_count + # is 3, build the list {0 1 2}. + set ::idxlist [list] + set ::numcols [sqlite3_column_count $STMT] + for {set i 0} {$i < $::numcols} {incr i} {lappend ::idxlist $i} + + # Column names in UTF-8 + do_test $test.1 { + set cnamelist [list] + foreach i $idxlist {lappend cnamelist [sqlite3_column_name $STMT $i]} + set cnamelist + } $names + + # Column names in UTF-16 + ifcapable {utf16} { + do_test $test.2 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [utf8 [sqlite3_column_name16 $STMT $i]] + } + set cnamelist + } $names + } + + # Column names in UTF-8 + do_test $test.3 { + set cnamelist [list] + foreach i $idxlist {lappend cnamelist [sqlite3_column_name $STMT $i]} + set cnamelist + } $names + + # Column names in UTF-16 + ifcapable {utf16} { + do_test $test.4 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [utf8 [sqlite3_column_name16 $STMT $i]] + } + set cnamelist + } $names + } + + # Column names in UTF-8 + do_test $test.5 { + set cnamelist [list] + foreach i $idxlist {lappend cnamelist [sqlite3_column_decltype $STMT $i]} + set cnamelist + } $decltypes + + # Column declaration types in UTF-16 + ifcapable {utf16} { + do_test $test.6 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [utf8 [sqlite3_column_decltype16 $STMT $i]] + } + set cnamelist + } $decltypes + } + + + # Test some out of range conditions: + ifcapable {utf16} { + do_test $test.7 { + list \ + [sqlite3_column_name $STMT -1] \ + [sqlite3_column_name16 $STMT -1] \ + [sqlite3_column_decltype $STMT -1] \ + [sqlite3_column_decltype16 $STMT -1] \ + [sqlite3_column_name $STMT $numcols] \ + [sqlite3_column_name16 $STMT $numcols] \ + [sqlite3_column_decltype $STMT $numcols] \ + [sqlite3_column_decltype16 $STMT $numcols] + } {{} {} {} {} {} {} {} {}} + } +} + +# This proc is used to test the following API calls: +# +# sqlite3_column_origin_name +# sqlite3_column_origin_name16 +# sqlite3_column_table_name +# sqlite3_column_table_name16 +# sqlite3_column_database_name +# sqlite3_column_database_name16 +# +# $STMT is a compiled SQL statement. $test is a prefix +# to use for test names within this proc. $names is a list +# of the column names that should be returned by $STMT. +# $decltypes is a list of column declaration types for $STMT. +# +# Example: +# +# set STMT [sqlite3_prepare "SELECT 1, 2, 2;" -1 DUMMY] +# check_header test1.1 {1 2 3} {"" "" ""} +# +proc check_origin_header {STMT test dbs tables cols} { + # If sqlite3_column_origin_name() and friends are not compiled into + # this build, this proc is a no-op. + ifcapable columnmetadata { + # Use the return value of sqlite3_column_count() to build + # a list of column indexes. i.e. If sqlite3_column_count + # is 3, build the list {0 1 2}. + set ::idxlist [list] + set ::numcols [sqlite3_column_count $STMT] + for {set i 0} {$i < $::numcols} {incr i} {lappend ::idxlist $i} + + # Database names in UTF-8 + do_test $test.8 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [sqlite3_column_database_name $STMT $i] + } + set cnamelist + } $dbs + + # Database names in UTF-16 + ifcapable {utf16} { + do_test $test.9 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [utf8 [sqlite3_column_database_name16 $STMT $i]] + } + set cnamelist + } $dbs + } + + # Table names in UTF-8 + do_test $test.10 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [sqlite3_column_table_name $STMT $i] + } + set cnamelist + } $tables + + # Table names in UTF-16 + ifcapable {utf16} { + do_test $test.11 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [utf8 [sqlite3_column_table_name16 $STMT $i]] + } + set cnamelist + } $tables + } + + # Origin names in UTF-8 + do_test $test.12 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [sqlite3_column_origin_name $STMT $i] + } + set cnamelist + } $cols + + # Origin declaration types in UTF-16 + ifcapable {utf16} { + do_test $test.13 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [utf8 [sqlite3_column_origin_name16 $STMT $i]] + } + set cnamelist + } $cols + } + } +} + +# This proc is used to test the following APIs: +# +# sqlite3_data_count +# sqlite3_column_type +# sqlite3_column_int +# sqlite3_column_text +# sqlite3_column_text16 +# sqlite3_column_double +# +# $STMT is a compiled SQL statement for which the previous call +# to sqlite3_step returned SQLITE_ROW. $test is a prefix to use +# for test names within this proc. $types is a list of the +# manifest types for the current row. $ints, $doubles and $strings +# are lists of the integer, real and string representations of +# the values in the current row. +# +# Example: +# +# set STMT [sqlite3_prepare "SELECT 'hello', 1.1, NULL" -1 DUMMY] +# sqlite3_step $STMT +# check_data test1.2 {TEXT REAL NULL} {0 1 0} {0 1.1 0} {hello 1.1 {}} +# +proc check_data {STMT test types ints doubles strings} { + + # Use the return value of sqlite3_column_count() to build + # a list of column indexes. i.e. If sqlite3_column_count + # is 3, build the list {0 1 2}. + set ::idxlist [list] + set numcols [sqlite3_data_count $STMT] + for {set i 0} {$i < $numcols} {incr i} {lappend ::idxlist $i} + +# types +do_test $test.1 { + set types [list] + foreach i $idxlist { + set x [sqlite3_column_type $STMT $i] + # EVIDENCE-OF: R-12793-43283 Every value in SQLite has one of five + # fundamental datatypes: 64-bit signed integer 64-bit IEEE floating + # point number string BLOB NULL + if {[lsearch {INTEGER FLOAT TEXT BLOB NULL} $x]<0} { + set types ERROR + break + } else { + lappend types $x + } + } + set types +} $types + + +# Integers +do_test $test.2 { + set ints [list] + foreach i $idxlist {lappend ints [sqlite3_column_int64 $STMT $i]} + set ints +} $ints + +# bytes +set lens [list] +foreach i $::idxlist { + lappend lens [string length [lindex $strings $i]] +} +do_test $test.3 { + set bytes [list] + set lens [list] + foreach i $idxlist { + lappend bytes [sqlite3_column_bytes $STMT $i] + } + set bytes +} $lens + +# bytes16 +ifcapable {utf16} { + set lens [list] + foreach i $::idxlist { + lappend lens [expr 2 * [string length [lindex $strings $i]]] + } + do_test $test.4 { + set bytes [list] + set lens [list] + foreach i $idxlist { + lappend bytes [sqlite3_column_bytes16 $STMT $i] + } + set bytes + } $lens +} + +# Blob +do_test $test.5 { + set utf8 [list] + foreach i $idxlist {lappend utf8 [sqlite3_column_blob $STMT $i]} + set utf8 +} $strings + +# UTF-8 +do_test $test.6 { + set utf8 [list] + foreach i $idxlist {lappend utf8 [sqlite3_column_text $STMT $i]} + set utf8 +} $strings + +# Floats +do_test $test.7 { + set utf8 [list] + foreach i $idxlist {lappend utf8 [sqlite3_column_double $STMT $i]} + set utf8 +} $doubles + +# UTF-16 +ifcapable {utf16} { + do_test $test.8 { + set utf8 [list] + foreach i $idxlist {lappend utf8 [utf8 [sqlite3_column_text16 $STMT $i]]} + set utf8 + } $strings +} + +# Integers +do_test $test.9 { + set ints [list] + foreach i $idxlist {lappend ints [sqlite3_column_int $STMT $i]} + set ints +} $ints + +# Floats +do_test $test.10 { + set utf8 [list] + foreach i $idxlist {lappend utf8 [sqlite3_column_double $STMT $i]} + set utf8 +} $doubles + +# UTF-8 +do_test $test.11 { + set utf8 [list] + foreach i $idxlist {lappend utf8 [sqlite3_column_text $STMT $i]} + set utf8 +} $strings + +# Types +do_test $test.12 { + set types [list] + foreach i $idxlist {lappend types [sqlite3_column_type $STMT $i]} + set types +} $types + +# Test that an out of range request returns the equivalent of NULL +do_test $test.13 { + sqlite3_column_int $STMT -1 +} {0} +do_test $test.13 { + sqlite3_column_text $STMT -1 +} {} + +} + +ifcapable !floatingpoint { + finish_test + return +} + +do_test capi3-5.0 { + execsql { + CREATE TABLE t1(a VARINT, b BLOB, c VARCHAR(16)); + INSERT INTO t1 VALUES(1, 2, 3); + INSERT INTO t1 VALUES('one', 'two', NULL); + INSERT INTO t1 VALUES(1.2, 1.3, 1.4); + } + set sql "SELECT * FROM t1" + set STMT [sqlite3_prepare $DB $sql -1 TAIL] + sqlite3_column_count $STMT +} 3 + +check_header $STMT capi3-5.1 {a b c} {VARINT BLOB VARCHAR(16)} +check_origin_header $STMT capi3-5.1 {main main main} {t1 t1 t1} {a b c} +do_test capi3-5.2 { + sqlite3_step $STMT +} SQLITE_ROW + +check_header $STMT capi3-5.3 {a b c} {VARINT BLOB VARCHAR(16)} +check_origin_header $STMT capi3-5.3 {main main main} {t1 t1 t1} {a b c} +check_data $STMT capi3-5.4 {INTEGER INTEGER TEXT} {1 2 3} {1.0 2.0 3.0} {1 2 3} + +do_test capi3-5.5 { + sqlite3_step $STMT +} SQLITE_ROW + +check_header $STMT capi3-5.6 {a b c} {VARINT BLOB VARCHAR(16)} +check_origin_header $STMT capi3-5.6 {main main main} {t1 t1 t1} {a b c} +check_data $STMT capi3-5.7 {TEXT TEXT NULL} {0 0 0} {0.0 0.0 0.0} {one two {}} + +do_test capi3-5.8 { + sqlite3_step $STMT +} SQLITE_ROW + +check_header $STMT capi3-5.9 {a b c} {VARINT BLOB VARCHAR(16)} +check_origin_header $STMT capi3-5.9 {main main main} {t1 t1 t1} {a b c} +check_data $STMT capi3-5.10 {FLOAT FLOAT TEXT} {1 1 1} {1.2 1.3 1.4} {1.2 1.3 1.4} + +do_test capi3-5.11 { + sqlite3_step $STMT +} SQLITE_DONE + +do_test capi3-5.12 { + sqlite3_finalize $STMT +} SQLITE_OK + +do_test capi3-5.20 { + set sql "SELECT a, sum(b), max(c) FROM t1 GROUP BY a" + set STMT [sqlite3_prepare $DB $sql -1 TAIL] + sqlite3_column_count $STMT +} 3 + +check_header $STMT capi3-5.21 {a sum(b) max(c)} {VARINT {} {}} +check_origin_header $STMT capi3-5.22 {main {} {}} {t1 {} {}} {a {} {}} +do_test capi3-5.23 { + sqlite3_finalize $STMT +} SQLITE_OK + +do_test capi3-5.30 { + set sql "SELECT a AS x, sum(b) AS y, max(c) AS z FROM t1 AS m GROUP BY x" + set STMT [sqlite3_prepare $DB $sql -1 TAIL] + sqlite3_column_count $STMT +} 3 + +check_header $STMT capi3-5.31 {x y z} {VARINT {} {}} +check_origin_header $STMT capi3-5.32 {main {} {}} {t1 {} {}} {a {} {}} +do_test capi3-5.33 { + sqlite3_finalize $STMT +} SQLITE_OK + +# 2018-01-09: If a column is the last token if a string, the column name +# was not being set correctly, due to changes in check-in +# https://sqlite.org/src/info/0fdf97efe5df7455 +# +# This problem was detected by the community during beta-testing. +# +do_test capi3-5.34 { + set STMT [sqlite3_prepare $DB {SELECT :a, :b} -1 TAIL] + sqlite3_column_count $STMT +} 2 +check_header $STMT capi-5.35 {:a :b} {{} {}} +sqlite3_finalize $STMT + +set ::ENC [execsql {pragma encoding}] +db close + +do_test capi3-6.0 { + sqlite3 db test.db + set DB [sqlite3_connection_pointer db] + if {[sqlite3 -has-codec]==0} { sqlite3_key $DB xyzzy } + set sql {SELECT a FROM t1 order by rowid} + set STMT [sqlite3_prepare $DB $sql -1 TAIL] + expr 0 +} {0} +do_test capi3-6.1 { + db cache flush + sqlite3_close $DB +} {SQLITE_BUSY} + +# 6.2 and 6.3 used to return SQLITE_ERROR and SQLITE_SCHEMA, respectively. +# But since attempting to close a connection no longer resets the internal +# schema and expires all statements, this is no longer the case. +do_test capi3-6.2 { + sqlite3_step $STMT +} {SQLITE_ROW} +#check_data $STMT capi3-6.3 {INTEGER} {1} {1.0} {1} +do_test capi3-6.3 { + sqlite3_finalize $STMT +} {SQLITE_OK} + +if {[clang_sanitize_address]==0} { + do_test capi3-6.4-misuse { + db cache flush + sqlite3_close $DB + } {SQLITE_OK} +} +db close + +# This procedure sets the value of the file-format in file 'test.db' +# to $newval. Also, the schema cookie is incremented. +# +proc set_file_format {newval} { + hexio_write test.db 44 [hexio_render_int32 $newval] + set schemacookie [hexio_get_int [hexio_read test.db 40 4]] + incr schemacookie + hexio_write test.db 40 [hexio_render_int32 $schemacookie] + return {} +} + +# This procedure returns the value of the file-format in file 'test.db'. +# +proc get_file_format {{fname test.db}} { + return [hexio_get_int [hexio_read $fname 44 4]] +} + +if {![sqlite3 -has-codec]} { + # Test what happens when the library encounters a newer file format. + do_test capi3-7.1 { + set_file_format 5 + } {} + do_test capi3-7.2 { + catch { sqlite3 db test.db } + catchsql { + SELECT * FROM sqlite_master; + } + } {1 {unsupported file format}} + db close +} + +if {![sqlite3 -has-codec]} { + # Now test that the library correctly handles bogus entries in the + # sqlite_master table (schema corruption). + do_test capi3-8.1 { + forcedelete test.db test.db-journal + sqlite3 db test.db + execsql { + CREATE TABLE t1(a); + } + db close + } {} + do_test capi3-8.2 { + sqlite3 db test.db + sqlite3_db_config db DEFENSIVE 0 + execsql { + PRAGMA writable_schema=ON; + INSERT INTO sqlite_master VALUES(NULL,NULL,NULL,NULL,NULL); + } + db close + } {} + do_test capi3-8.3 { + catch { sqlite3 db test.db } + catchsql { + SELECT * FROM sqlite_master; + } + } {1 {malformed database schema (?)}} + do_test capi3-8.4 { + # Build a 5-field row record. The first field is a string 'table', and + # subsequent fields are all NULL. + db close + forcedelete test.db test.db-journal + sqlite3 db test.db + sqlite3_db_config db DEFENSIVE 0 + execsql { + CREATE TABLE t1(a); + PRAGMA writable_schema=ON; + INSERT INTO sqlite_master VALUES('table',NULL,NULL,NULL,NULL); + } + db close + } {}; + do_test capi3-8.5 { + catch { sqlite3 db test.db } + catchsql { + SELECT * FROM sqlite_master; + } + } {1 {malformed database schema (?)}} + db close +} +forcedelete test.db +forcedelete test.db-journal + + +# Test the english language string equivalents for sqlite error codes +set code2english [list \ +SQLITE_OK {not an error} \ +SQLITE_ERROR {SQL logic error} \ +SQLITE_PERM {access permission denied} \ +SQLITE_ABORT {query aborted} \ +SQLITE_BUSY {database is locked} \ +SQLITE_LOCKED {database table is locked} \ +SQLITE_NOMEM {out of memory} \ +SQLITE_READONLY {attempt to write a readonly database} \ +SQLITE_INTERRUPT {interrupted} \ +SQLITE_IOERR {disk I/O error} \ +SQLITE_CORRUPT {database disk image is malformed} \ +SQLITE_FULL {database or disk is full} \ +SQLITE_CANTOPEN {unable to open database file} \ +SQLITE_SCHEMA {database schema has changed} \ +SQLITE_CONSTRAINT {constraint failed} \ +SQLITE_MISMATCH {datatype mismatch} \ +SQLITE_MISUSE {bad parameter or other API misuse} \ +SQLITE_AUTH {authorization denied} \ +SQLITE_RANGE {column index out of range} \ +SQLITE_NOTADB {file is not a database} \ +unknownerror {unknown error} \ +] + +set test_number 1 +foreach {code english} $code2english { + do_test capi3-9.$test_number "sqlite3_test_errstr $code" $english + incr test_number +} + +# Test the error message when a "real" out of memory occurs. +if { [permutation] != "nofaultsim" } { + do_test capi3-10-1 { + sqlite3 db test.db + set DB [sqlite3_connection_pointer db] + sqlite3_memdebug_fail 1 + catchsql { + select * from sqlite_master; + } + } {1 {out of memory}} + do_test capi3-10-2 { + sqlite3_errmsg $::DB + } {out of memory} + ifcapable {utf16} { + do_test capi3-10-3 { + utf8 [sqlite3_errmsg16 $::DB] + } {out of memory} + } + db close + sqlite3_memdebug_fail -1 + do_test capi3-10-4 { + sqlite3 db test.db + set DB [sqlite3_connection_pointer db] + sqlite3_memdebug_fail 1 + catchsql { + select * from sqlite_master where rowid>5; + } + } {1 {out of memory}} + do_test capi3-10-5 { + sqlite3_errmsg $::DB + } {out of memory} + ifcapable {utf16} { + do_test capi3-10-6 { + utf8 [sqlite3_errmsg16 $::DB] + } {out of memory} + } + db close + sqlite3_memdebug_fail -1 +} + +# The following tests - capi3-11.* - test that a COMMIT or ROLLBACK +# statement issued while there are still outstanding VMs that are part of +# the transaction fails. +sqlite3 db test.db +set DB [sqlite3_connection_pointer db] +sqlite_register_test_function $DB func +do_test capi3-11.1 { + execsql { + BEGIN; + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 'int'); + INSERT INTO t1 VALUES(2, 'notatype'); + } +} {} +do_test capi3-11.1.1 { + sqlite3_get_autocommit $DB +} 0 +do_test capi3-11.2 { + set STMT [sqlite3_prepare $DB "SELECT func(b, a) FROM t1" -1 TAIL] + sqlite3_step $STMT +} {SQLITE_ROW} + +# As of 3.6.5 a COMMIT is OK during while a query is still running - +# as long as it is a read-only query and not an incremental BLOB write. +# +do_test capi3-11.3.1 { + catchsql { + COMMIT; + } +} {0 {}} +do_test capi3-11.3.2 { + sqlite3_extended_errcode $DB +} {SQLITE_OK} +do_test capi3-11.3.3 { + sqlite3_get_autocommit $DB +} 1 +do_test capi3-11.3.4 { + db eval {PRAGMA lock_status} +} {main shared temp closed} + +do_test capi3-11.4 { + sqlite3_step $STMT +} {SQLITE_ERROR} +do_test capi3-11.5 { + sqlite3_finalize $STMT +} {SQLITE_ERROR} +do_test capi3-11.6 { + catchsql { + SELECT * FROM t1; + } +} {0 {1 int 2 notatype}} +do_test capi3-11.7 { + sqlite3_get_autocommit $DB +} 1 +do_test capi3-11.8 { + execsql { + CREATE TABLE t2(a); + INSERT INTO t2 VALUES(1); + INSERT INTO t2 VALUES(2); + BEGIN; + INSERT INTO t2 VALUES(3); + } +} {} +do_test capi3-11.8.1 { + sqlite3_get_autocommit $DB +} 0 +do_test capi3-11.9 { + set STMT [sqlite3_prepare $DB "SELECT a FROM t2" -1 TAIL] + sqlite3_step $STMT +} {SQLITE_ROW} +do_test capi3-11.9.1 { + sqlite3_get_autocommit $DB +} 0 +do_test capi3-11.9.2 { + catchsql { + ROLLBACK; + } +} {0 {}} +do_test capi3-11.9.3 { + sqlite3_get_autocommit $DB +} 1 +do_test capi3-11.10 { + sqlite3_step $STMT +} {SQLITE_ROW} +do_test capi3-11.11 { + sqlite3_step $STMT +} {SQLITE_DONE} +ifcapable !autoreset { + do_test capi3-11.12armor { + sqlite3_step $STMT + sqlite3_step $STMT + } {SQLITE_MISUSE} +} else { + do_test capi3-11.12 { + sqlite3_step $STMT + sqlite3_step $STMT + } {SQLITE_ROW} +} +do_test capi3-11.13 { + sqlite3_finalize $STMT +} {SQLITE_OK} +do_test capi3-11.14 { + execsql { + SELECT a FROM t2; + } +} {1 2} +do_test capi3-11.14.1 { + sqlite3_get_autocommit $DB +} 1 +do_test capi3-11.15 { + catchsql { + ROLLBACK; + } +} {1 {cannot rollback - no transaction is active}} +do_test capi3-11.15.1 { + sqlite3_get_autocommit $DB +} 1 +do_test capi3-11.16 { + execsql { + SELECT a FROM t2; + } +} {1 2} + +# Sanity check on the definition of 'outstanding VM'. This means any VM +# that has had sqlite3_step() called more recently than sqlite3_finalize() or +# sqlite3_reset(). So a VM that has just been prepared or reset does not +# count as an active VM. +do_test capi3-11.17 { + execsql { + BEGIN; + } +} {} +do_test capi3-11.18 { + set STMT [sqlite3_prepare $DB "SELECT a FROM t1" -1 TAIL] + catchsql { + COMMIT; + } +} {0 {}} +do_test capi3-11.19 { + sqlite3_step $STMT +} {SQLITE_ROW} +do_test capi3-11.20 { + catchsql { + BEGIN; + COMMIT; + } +} {0 {}} +do_test capi3-11.20 { + sqlite3_reset $STMT + catchsql { + COMMIT; + } +} {1 {cannot commit - no transaction is active}} +do_test capi3-11.21 { + sqlite3_finalize $STMT +} {SQLITE_OK} + +# The following tests - capi3-12.* - check that its Ok to start a +# transaction while other VMs are active, and that its Ok to execute +# atomic updates in the same situation +# +do_test capi3-12.1 { + set STMT [sqlite3_prepare $DB "SELECT a FROM t2" -1 TAIL] + sqlite3_step $STMT +} {SQLITE_ROW} +do_test capi3-12.2 { + catchsql { + INSERT INTO t1 VALUES(3, NULL); + } +} {0 {}} +do_test capi3-12.3 { + catchsql { + INSERT INTO t2 VALUES(4); + } +} {0 {}} +do_test capi3-12.4 { + catchsql { + BEGIN; + INSERT INTO t1 VALUES(4, NULL); + } +} {0 {}} +do_test capi3-12.5 { + sqlite3_step $STMT +} {SQLITE_ROW} +do_test capi3-12.5.1 { + sqlite3_step $STMT +} {SQLITE_ROW} +do_test capi3-12.6 { + sqlite3_step $STMT +} {SQLITE_DONE} +do_test capi3-12.7 { + sqlite3_finalize $STMT +} {SQLITE_OK} +do_test capi3-12.8 { + execsql { + COMMIT; + SELECT a FROM t1; + } +} {1 2 3 4} + +# Test cases capi3-13.* test the sqlite3_clear_bindings() and +# sqlite3_sleep APIs. +# +if {[llength [info commands sqlite3_clear_bindings]]>0} { + do_test capi3-13.1 { + execsql { + DELETE FROM t1; + } + set STMT [sqlite3_prepare $DB "INSERT INTO t1 VALUES(?, ?)" -1 TAIL] + sqlite3_step $STMT + } {SQLITE_DONE} + do_test capi3-13.2 { + sqlite3_reset $STMT + sqlite3_bind_text $STMT 1 hello 5 + sqlite3_bind_text $STMT 2 world 5 + sqlite3_step $STMT + } {SQLITE_DONE} + do_test capi3-13.3 { + sqlite3_reset $STMT + sqlite3_clear_bindings $STMT + sqlite3_step $STMT + } {SQLITE_DONE} + do_test capi3-13-4 { + sqlite3_finalize $STMT + execsql { + SELECT * FROM t1; + } + } {{} {} hello world {} {}} +} +if {[llength [info commands sqlite3_sleep]]>0} { + do_test capi3-13-5 { + set ms [sqlite3_sleep 80] + expr {$ms==80 || $ms==1000} + } {1} +} + +# Ticket #1219: Make sure binding APIs can handle a NULL pointer. +# +if {[clang_sanitize_address]==0} { + do_test capi3-14.1-misuse { + set rc [catch {sqlite3_bind_text 0 1 hello 5} msg] + lappend rc $msg + } {1 SQLITE_MISUSE} +} + +# Ticket #1650: Honor the nBytes parameter to sqlite3_prepare. +# +do_test capi3-15.1 { + set sql {SELECT * FROM t2} + set nbytes [string length $sql] + append sql { WHERE a==1} + set STMT [sqlite3_prepare $DB $sql $nbytes TAIL] + sqlite3_step $STMT + sqlite3_column_int $STMT 0 +} {1} +do_test capi3-15.2 { + sqlite3_step $STMT + sqlite3_column_int $STMT 0 +} {2} +do_test capi3-15.3 { + sqlite3_finalize $STMT +} {SQLITE_OK} +do_test capi3-15.4 { + # 123456789 1234567 + set sql {SELECT 1234567890} + set STMT [sqlite3_prepare $DB $sql 8 TAIL] + sqlite3_step $STMT + set v1 [sqlite3_column_int $STMT 0] + sqlite3_finalize $STMT + set v1 +} {1} +do_test capi3-15.5 { + # 123456789 1234567 + set sql {SELECT 1234567890} + set STMT [sqlite3_prepare $DB $sql 9 TAIL] + sqlite3_step $STMT + set v1 [sqlite3_column_int $STMT 0] + sqlite3_finalize $STMT + set v1 +} {12} +do_test capi3-15.6 { + # 123456789 1234567 + set sql {SELECT 1234567890} + set STMT [sqlite3_prepare $DB $sql 12 TAIL] + sqlite3_step $STMT + set v1 [sqlite3_column_int $STMT 0] + sqlite3_finalize $STMT + set v1 +} {12345} +do_test capi3-15.7 { + # 123456789 1234567 + set sql {SELECT 12.34567890} + set STMT [sqlite3_prepare $DB $sql 12 TAIL] + sqlite3_step $STMT + set v1 [sqlite3_column_double $STMT 0] + sqlite3_finalize $STMT + set v1 +} {12.34} +do_test capi3-15.8 { + # 123456789 1234567 + set sql {SELECT 12.34567890} + set STMT [sqlite3_prepare $DB $sql 14 TAIL] + sqlite3_step $STMT + set v1 [sqlite3_column_double $STMT 0] + sqlite3_finalize $STMT + set v1 +} {12.3456} + +# Make sure code is always generated even if an IF EXISTS or +# IF NOT EXISTS clause is present that the table does not or +# does exists. That way we will always have a prepared statement +# to expire when the schema changes. +# +do_test capi3-16.1 { + set sql {DROP TABLE IF EXISTS t3} + set STMT [sqlite3_prepare $DB $sql -1 TAIL] + sqlite3_finalize $STMT + expr {$STMT!=""} +} {1} +do_test capi3-16.2 { + set sql {CREATE TABLE IF NOT EXISTS t1(x,y)} + set STMT [sqlite3_prepare $DB $sql -1 TAIL] + sqlite3_finalize $STMT + expr {$STMT!=""} +} {1} + +# But still we do not generate code if there is no SQL +# +do_test capi3-16.3 { + set STMT [sqlite3_prepare $DB {} -1 TAIL] + sqlite3_finalize $STMT + expr {$STMT==""} +} {1} +do_test capi3-16.4 { + set STMT [sqlite3_prepare $DB {;} -1 TAIL] + sqlite3_finalize $STMT + expr {$STMT==""} +} {1} + +# Ticket #2426: Misuse of sqlite3_column_* by calling it after +# a sqlite3_reset should be harmless. +# +do_test capi3-17.1 { + set STMT [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL] + sqlite3_step $STMT + sqlite3_column_int $STMT 0 +} {1} +do_test capi3-17.2 { + sqlite3_reset $STMT + sqlite3_column_int $STMT 0 +} {0} +do_test capi3-17.3 { + sqlite3_finalize $STMT +} {SQLITE_OK} + +# Verify that sqlite3_step() fails with an SQLITE_SCHEMA error +# when the statement is prepared with sqlite3_prepare() (not +# sqlite3_prepare_v2()) and the schema has changed. +# +do_test capi3-18.1 { + set STMT [sqlite3_prepare db {SELECT * FROM t2} -1 TAIL] + sqlite3 db2 test.db + db2 eval {CREATE TABLE t3(x)} + db2 close + sqlite3_step $STMT +} {SQLITE_ERROR} +do_test capi3-18.2 { + sqlite3_reset $STMT + sqlite3_errcode db +} {SQLITE_SCHEMA} +do_test capi3-18.3 { + sqlite3_errmsg db +} {database schema has changed} +# The error persist on retry when sqlite3_prepare() has been used. +do_test capi3-18.4 { + sqlite3_step $STMT +} {SQLITE_ERROR} +do_test capi3-18.5 { + sqlite3_reset $STMT + sqlite3_errcode db +} {SQLITE_SCHEMA} +do_test capi3-18.6 { + sqlite3_errmsg db +} {database schema has changed} +sqlite3_finalize $STMT + +# Ticket #3134. Prepare a statement with an nBytes parameter of 0. +# Make sure this works correctly and does not reference memory out of +# range. +# +do_test capi3-19.1 { + sqlite3_prepare_tkt3134 db +} {} + +# Test that calling sqlite3_column_blob() on a TEXT value does not change +# the return type of subsequent calls to sqlite3_column_type(). +# +do_execsql_test 20.1 { + CREATE TABLE t4(x); + INSERT INTO t4 VALUES('abcdefghij'); +} +do_test 20.2 { + set stmt [sqlite3_prepare db "SELECT * FROM t4" -1 dummy] + sqlite3_step $stmt +} {SQLITE_ROW} +do_test 20.3 { sqlite3_column_type $stmt 0 } {TEXT} +do_test 20.4 { sqlite3_column_blob $stmt 0 } {abcdefghij} +do_test 20.5 { sqlite3_column_type $stmt 0 } {TEXT} +do_test 20.6 { sqlite3_finalize $stmt } SQLITE_OK + + +# Tests of the interface when no VFS is registered. +# +if {![info exists tester_do_binarylog]} { + db close + vfs_unregister_all + do_test capi3-20.1 { + sqlite3_sleep 100 + } {0} + vfs_reregister_all +} + +finish_test diff --git a/test/capi3b.test b/test/capi3b.test new file mode 100644 index 0000000..72bbbaf --- /dev/null +++ b/test/capi3b.test @@ -0,0 +1,145 @@ +# 2004 September 2 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script testing the callback-free C/C++ API and in +# particular the behavior of sqlite3_step() when trying to commit +# with lock contention. +# +# $Id: capi3b.test,v 1.4 2007/08/10 19:46:14 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + + +# These tests depend on the pager holding changes in cache +# until it is time to commit. But that won't happen if the +# soft-heap-limit is set too low. So disable the soft heap limit +# for the duration of this test. +# +sqlite3_soft_heap_limit 0 + + +set DB [sqlite3_connection_pointer db] +sqlite3 db2 test.db +set DB2 [sqlite3_connection_pointer db2] + +# Create some data in the database +# +do_test capi3b-1.1 { + execsql { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(1); + INSERT INTO t1 VALUES(2); + SELECT * FROM t1 + } +} {1 2} + +# Make sure the second database connection can see the data +# +do_test capi3b-1.2 { + execsql { + SELECT * FROM t1 + } db2 +} {1 2} + +# First database connection acquires a shared lock +# +do_test capi3b-1.3 { + execsql { + BEGIN; + SELECT * FROM t1; + } +} {1 2} + +# Second database connection tries to write. The sqlite3_step() +# function returns SQLITE_BUSY because it cannot commit. +# +do_test capi3b-1.4 { + set VM [sqlite3_prepare $DB2 {INSERT INTO t1 VALUES(3)} -1 TAIL] + sqlite3_step $VM +} SQLITE_BUSY + +# The sqlite3_step call can be repeated multiple times. +# +do_test capi3b-1.5.1 { + sqlite3_step $VM +} SQLITE_BUSY +do_test capi3b-1.5.2 { + sqlite3_step $VM +} SQLITE_BUSY + +# The first connection closes its transaction. This allows the second +# connections sqlite3_step to succeed. +# +do_test capi3b-1.6 { + execsql COMMIT + sqlite3_step $VM +} SQLITE_DONE +do_test capi3b-1.7 { + sqlite3_finalize $VM +} SQLITE_OK +do_test capi3b-1.8 { + execsql {SELECT * FROM t1} db2 +} {1 2 3} +do_test capi3b-1.9 { + execsql {SELECT * FROM t1} +} {1 2 3} + +# Start doing a SELECT with one connection. This gets a SHARED lock. +# Then do an INSERT with the other connection. The INSERT should +# not be able to complete until the SELECT finishes. +# +do_test capi3b-2.1 { + set VM1 [sqlite3_prepare $DB {SELECT * FROM t1} -1 TAIL] + sqlite3_step $VM1 +} SQLITE_ROW +do_test capi3b-2.2 { + sqlite3_column_text $VM1 0 +} 1 +do_test capi3b-2.3 { + set VM2 [sqlite3_prepare $DB2 {INSERT INTO t1 VALUES(4)} -1 TAIL] + sqlite3_step $VM2 +} SQLITE_BUSY +do_test capi3b-2.4 { + sqlite3_step $VM1 +} SQLITE_ROW +do_test capi3b-2.5 { + sqlite3_column_text $VM1 0 +} 2 +do_test capi3b-2.6 { + sqlite3_step $VM2 +} SQLITE_BUSY +do_test capi3b-2.7 { + sqlite3_step $VM1 +} SQLITE_ROW +do_test capi3b-2.8 { + sqlite3_column_text $VM1 0 +} 3 +do_test capi3b-2.9 { + sqlite3_step $VM2 +} SQLITE_BUSY +do_test capi3b-2.10 { + sqlite3_step $VM1 +} SQLITE_DONE +do_test capi3b-2.11 { + sqlite3_step $VM2 +} SQLITE_DONE +do_test capi3b-2.12 { + sqlite3_finalize $VM1 + sqlite3_finalize $VM2 + execsql {SELECT * FROM t1} +} {1 2 3 4} + +catch {db2 close} + +sqlite3_soft_heap_limit $cmdlinearg(soft-heap-limit) +finish_test diff --git a/test/capi3c.test b/test/capi3c.test new file mode 100644 index 0000000..247dbf3 --- /dev/null +++ b/test/capi3c.test @@ -0,0 +1,1401 @@ +# 2006 November 08 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This is a copy of the capi3.test file that has been adapted to +# test the new sqlite3_prepare_v2 interface. +# +# $Id: capi3c.test,v 1.23 2009/07/22 07:27:57 danielk1977 Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix capi3c + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +# Return the UTF-16 representation of the supplied UTF-8 string $str. +# If $nt is true, append two 0x00 bytes as a nul terminator. +proc utf16 {str {nt 1}} { + set r [encoding convertto unicode $str] + if {$nt} { + append r "\x00\x00" + } + return $r +} + +# Return the UTF-8 representation of the supplied UTF-16 string $str. +proc utf8 {str} { + # If $str ends in two 0x00 0x00 bytes, knock these off before + # converting to UTF-8 using TCL. + binary scan $str \c* vals + if {[lindex $vals end]==0 && [lindex $vals end-1]==0} { + set str [binary format \c* [lrange $vals 0 end-2]] + } + + set r [encoding convertfrom unicode $str] + return $r +} + +# These tests complement those in capi2.test. They are organized +# as follows: +# +# capi3c-1.*: Test sqlite3_prepare_v2 +# capi3c-2.*: Test sqlite3_prepare16_v2 +# capi3c-3.*: Test sqlite3_open +# capi3c-4.*: Test sqlite3_open16 +# capi3c-5.*: Test the various sqlite3_result_* APIs +# capi3c-6.*: Test that sqlite3_close fails if there are outstanding VMs. +# + +set DB [sqlite3_connection_pointer db] + +do_test capi3c-1.0 { + sqlite3_get_autocommit $DB +} 1 +do_test capi3c-1.1 { + set STMT [sqlite3_prepare_v2 $DB {SELECT name FROM sqlite_master} -1 TAIL] + sqlite3_finalize $STMT + set TAIL +} {} +do_test capi3c-1.2.1 { + sqlite3_errcode $DB +} {SQLITE_OK} +do_test capi3c-1.2.2 { + sqlite3_extended_errcode $DB +} {SQLITE_OK} +do_test capi3c-1.3 { + sqlite3_errmsg $DB +} {not an error} +do_test capi3c-1.4 { + set sql {SELECT name FROM sqlite_master;SELECT 10} + set STMT [sqlite3_prepare_v2 $DB $sql -1 TAIL] + sqlite3_finalize $STMT + set TAIL +} {SELECT 10} +do_test capi3c-1.5 { + set sql {SELECT namex FROM sqlite_master} + catch { + set STMT [sqlite3_prepare_v2 $DB $sql -1 TAIL] + } +} {1} +do_test capi3c-1.6.1 { + sqlite3_errcode $DB +} {SQLITE_ERROR} +do_test capi3c-1.6.2 { + sqlite3_extended_errcode $DB +} {SQLITE_ERROR} +do_test capi3c-1.7 { + sqlite3_errmsg $DB +} {no such column: namex} + + +ifcapable {utf16} { + do_test capi3c-2.1 { + set sql16 [utf16 {SELECT name FROM sqlite_master}] + set STMT [sqlite3_prepare16_v2 $DB $sql16 -1 ::TAIL] + sqlite3_finalize $STMT + utf8 $::TAIL + } {} + do_test capi3c-2.2 { + set sql [utf16 {SELECT name FROM sqlite_master;SELECT 10}] + set STMT [sqlite3_prepare16_v2 $DB $sql -1 TAIL] + sqlite3_finalize $STMT + utf8 $TAIL + } {SELECT 10} + do_test capi3c-2.3 { + set sql [utf16 {SELECT namex FROM sqlite_master}] + catch { + set STMT [sqlite3_prepare16_v2 $DB $sql -1 TAIL] + } + } {1} + do_test capi3c-2.4.1 { + sqlite3_errcode $DB + } {SQLITE_ERROR} + do_test capi3c-2.4.2 { + sqlite3_extended_errcode $DB + } {SQLITE_ERROR} + do_test capi3c-2.5 { + sqlite3_errmsg $DB + } {no such column: namex} + + ifcapable schema_pragmas { + do_test capi3c-2.6 { + execsql {CREATE TABLE tablename(x)} + set sql16 [utf16 {PRAGMA table_info("TableName")}] + set STMT [sqlite3_prepare16_v2 $DB $sql16 -1 TAIL] + sqlite3_step $STMT + } SQLITE_ROW + do_test capi3c-2.7 { + sqlite3_step $STMT + } SQLITE_DONE + do_test capi3c-2.8 { + sqlite3_finalize $STMT + } SQLITE_OK + } + +} ;# endif utf16 + +# rename sqlite3_open sqlite3_open_old +# proc sqlite3_open {fname options} {sqlite3_open_new $fname $options} + +do_test capi3c-3.1 { + set db2 [sqlite3_open test.db {}] + sqlite3_errcode $db2 +} {SQLITE_OK} +# FIX ME: Should test the db handle works. +do_test capi3c-3.2 { + sqlite3_close $db2 +} {SQLITE_OK} +do_test capi3c-3.3 { + catch { + set db2 [sqlite3_open /bogus/path/test.db {}] + } + sqlite3_errcode $db2 +} {SQLITE_CANTOPEN} +do_test capi3c-3.4 { + sqlite3_errmsg $db2 +} {unable to open database file} +do_test capi3c-3.5 { + sqlite3_close $db2 +} {SQLITE_OK} +if {[clang_sanitize_address]==0} { + do_test capi3c-3.6.1-misuse { + sqlite3_close $db2 + } {SQLITE_MISUSE} + do_test capi3c-3.6.2-misuse { + sqlite3_errmsg $db2 + } {bad parameter or other API misuse} + ifcapable {utf16} { + do_test capi3c-3.6.3-misuse { + utf8 [sqlite3_errmsg16 $db2] + } {bad parameter or other API misuse} + } +} + +# rename sqlite3_open "" +# rename sqlite3_open_old sqlite3_open + +ifcapable {utf16} { +do_test capi3c-4.1 { + set db2 [sqlite3_open16 [utf16 test.db] {}] + sqlite3_errcode $db2 +} {SQLITE_OK} +# FIX ME: Should test the db handle works. +do_test capi3c-4.2 { + sqlite3_close $db2 +} {SQLITE_OK} +do_test capi3c-4.3 { + catch { + set db2 [sqlite3_open16 [utf16 /bogus/path/test.db] {}] + } + sqlite3_errcode $db2 +} {SQLITE_CANTOPEN} +do_test capi3c-4.4 { + utf8 [sqlite3_errmsg16 $db2] +} {unable to open database file} +do_test capi3c-4.5 { + sqlite3_close $db2 +} {SQLITE_OK} +} ;# utf16 + +# This proc is used to test the following API calls: +# +# sqlite3_column_count +# sqlite3_column_name +# sqlite3_column_name16 +# sqlite3_column_decltype +# sqlite3_column_decltype16 +# +# $STMT is a compiled SQL statement. $test is a prefix +# to use for test names within this proc. $names is a list +# of the column names that should be returned by $STMT. +# $decltypes is a list of column declaration types for $STMT. +# +# Example: +# +# set STMT [sqlite3_prepare_v2 "SELECT 1, 2, 2;" -1 DUMMY] +# check_header test1.1 {1 2 3} {"" "" ""} +# +proc check_header {STMT test names decltypes} { + + # Use the return value of sqlite3_column_count() to build + # a list of column indexes. i.e. If sqlite3_column_count + # is 3, build the list {0 1 2}. + set ::idxlist [list] + set ::numcols [sqlite3_column_count $STMT] + for {set i 0} {$i < $::numcols} {incr i} {lappend ::idxlist $i} + + # Column names in UTF-8 + do_test $test.1 { + set cnamelist [list] + foreach i $idxlist {lappend cnamelist [sqlite3_column_name $STMT $i]} + set cnamelist + } $names + + # Column names in UTF-16 + ifcapable {utf16} { + do_test $test.2 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [utf8 [sqlite3_column_name16 $STMT $i]] + } + set cnamelist + } $names + } + + # Column names in UTF-8 + do_test $test.3 { + set cnamelist [list] + foreach i $idxlist {lappend cnamelist [sqlite3_column_name $STMT $i]} + set cnamelist + } $names + + # Column names in UTF-16 + ifcapable {utf16} { + do_test $test.4 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [utf8 [sqlite3_column_name16 $STMT $i]] + } + set cnamelist + } $names + } + + # Column names in UTF-8 + do_test $test.5 { + set cnamelist [list] + foreach i $idxlist {lappend cnamelist [sqlite3_column_decltype $STMT $i]} + set cnamelist + } $decltypes + + # Column declaration types in UTF-16 + ifcapable {utf16} { + do_test $test.6 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [utf8 [sqlite3_column_decltype16 $STMT $i]] + } + set cnamelist + } $decltypes + } + + + # Test some out of range conditions: + ifcapable {utf16} { + do_test $test.7 { + list \ + [sqlite3_column_name $STMT -1] \ + [sqlite3_column_name16 $STMT -1] \ + [sqlite3_column_decltype $STMT -1] \ + [sqlite3_column_decltype16 $STMT -1] \ + [sqlite3_column_name $STMT $numcols] \ + [sqlite3_column_name16 $STMT $numcols] \ + [sqlite3_column_decltype $STMT $numcols] \ + [sqlite3_column_decltype16 $STMT $numcols] + } {{} {} {} {} {} {} {} {}} + } +} + +# This proc is used to test the following API calls: +# +# sqlite3_column_origin_name +# sqlite3_column_origin_name16 +# sqlite3_column_table_name +# sqlite3_column_table_name16 +# sqlite3_column_database_name +# sqlite3_column_database_name16 +# +# $STMT is a compiled SQL statement. $test is a prefix +# to use for test names within this proc. $names is a list +# of the column names that should be returned by $STMT. +# $decltypes is a list of column declaration types for $STMT. +# +# Example: +# +# set STMT [sqlite3_prepare_v2 "SELECT 1, 2, 2;" -1 DUMMY] +# check_header test1.1 {1 2 3} {"" "" ""} +# +proc check_origin_header {STMT test dbs tables cols} { + # If sqlite3_column_origin_name() and friends are not compiled into + # this build, this proc is a no-op. +ifcapable columnmetadata { + + # Use the return value of sqlite3_column_count() to build + # a list of column indexes. i.e. If sqlite3_column_count + # is 3, build the list {0 1 2}. + set ::idxlist [list] + set ::numcols [sqlite3_column_count $STMT] + for {set i 0} {$i < $::numcols} {incr i} {lappend ::idxlist $i} + + # Database names in UTF-8 + do_test $test.8 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [sqlite3_column_database_name $STMT $i] + } + set cnamelist + } $dbs + + # Database names in UTF-16 + ifcapable {utf16} { + do_test $test.9 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [utf8 [sqlite3_column_database_name16 $STMT $i]] + } + set cnamelist + } $dbs + } + + # Table names in UTF-8 + do_test $test.10 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [sqlite3_column_table_name $STMT $i] + } + set cnamelist + } $tables + + # Table names in UTF-16 + ifcapable {utf16} { + do_test $test.11 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [utf8 [sqlite3_column_table_name16 $STMT $i]] + } + set cnamelist + } $tables + } + + # Origin names in UTF-8 + do_test $test.12 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [sqlite3_column_origin_name $STMT $i] + } + set cnamelist + } $cols + + # Origin declaration types in UTF-16 + ifcapable {utf16} { + do_test $test.13 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [utf8 [sqlite3_column_origin_name16 $STMT $i]] + } + set cnamelist + } $cols + } + } +} + +# This proc is used to test the following APIs: +# +# sqlite3_data_count +# sqlite3_column_type +# sqlite3_column_int +# sqlite3_column_text +# sqlite3_column_text16 +# sqlite3_column_double +# +# $STMT is a compiled SQL statement for which the previous call +# to sqlite3_step returned SQLITE_ROW. $test is a prefix to use +# for test names within this proc. $types is a list of the +# manifest types for the current row. $ints, $doubles and $strings +# are lists of the integer, real and string representations of +# the values in the current row. +# +# Example: +# +# set STMT [sqlite3_prepare_v2 "SELECT 'hello', 1.1, NULL" -1 DUMMY] +# sqlite3_step $STMT +# check_data test1.2 {TEXT REAL NULL} {0 1 0} {0 1.1 0} {hello 1.1 {}} +# +proc check_data {STMT test types ints doubles strings} { + + # Use the return value of sqlite3_column_count() to build + # a list of column indexes. i.e. If sqlite3_column_count + # is 3, build the list {0 1 2}. + set ::idxlist [list] + set numcols [sqlite3_data_count $STMT] + for {set i 0} {$i < $numcols} {incr i} {lappend ::idxlist $i} + +# types +do_test $test.1 { + set types [list] + foreach i $idxlist {lappend types [sqlite3_column_type $STMT $i]} + set types +} $types + +# Integers +do_test $test.2 { + set ints [list] + foreach i $idxlist {lappend ints [sqlite3_column_int64 $STMT $i]} + set ints +} $ints + +# bytes +set lens [list] +foreach i $::idxlist { + lappend lens [string length [lindex $strings $i]] +} +do_test $test.3 { + set bytes [list] + set lens [list] + foreach i $idxlist { + lappend bytes [sqlite3_column_bytes $STMT $i] + } + set bytes +} $lens + +# bytes16 +ifcapable {utf16} { + set lens [list] + foreach i $::idxlist { + lappend lens [expr 2 * [string length [lindex $strings $i]]] + } + do_test $test.4 { + set bytes [list] + set lens [list] + foreach i $idxlist { + lappend bytes [sqlite3_column_bytes16 $STMT $i] + } + set bytes + } $lens +} + +# Blob +do_test $test.5 { + set utf8 [list] + foreach i $idxlist {lappend utf8 [sqlite3_column_blob $STMT $i]} + set utf8 +} $strings + +# UTF-8 +do_test $test.6 { + set utf8 [list] + foreach i $idxlist {lappend utf8 [sqlite3_column_text $STMT $i]} + set utf8 +} $strings + +# Floats +do_test $test.7 { + set utf8 [list] + foreach i $idxlist {lappend utf8 [sqlite3_column_double $STMT $i]} + set utf8 +} $doubles + +# UTF-16 +ifcapable {utf16} { + do_test $test.8 { + set utf8 [list] + foreach i $idxlist {lappend utf8 [utf8 [sqlite3_column_text16 $STMT $i]]} + set utf8 + } $strings +} + +# Integers +do_test $test.9 { + set ints [list] + foreach i $idxlist {lappend ints [sqlite3_column_int $STMT $i]} + set ints +} $ints + +# Floats +do_test $test.10 { + set utf8 [list] + foreach i $idxlist {lappend utf8 [sqlite3_column_double $STMT $i]} + set utf8 +} $doubles + +# UTF-8 +do_test $test.11 { + set utf8 [list] + foreach i $idxlist {lappend utf8 [sqlite3_column_text $STMT $i]} + set utf8 +} $strings + +# Types +do_test $test.12 { + set types [list] + foreach i $idxlist {lappend types [sqlite3_column_type $STMT $i]} + set types +} $types + +# Test that an out of range request returns the equivalent of NULL +do_test $test.13 { + sqlite3_column_int $STMT -1 +} {0} +do_test $test.13 { + sqlite3_column_text $STMT -1 +} {} + +} + +ifcapable !floatingpoint { + finish_test + return +} + +do_test capi3c-5.0 { + execsql { + CREATE TABLE t1(a VARINT, b BLOB, c VARCHAR(16)); + INSERT INTO t1 VALUES(1, 2, 3); + INSERT INTO t1 VALUES('one', 'two', NULL); + INSERT INTO t1 VALUES(1.2, 1.3, 1.4); + } + set sql "SELECT * FROM t1" + set STMT [sqlite3_prepare_v2 $DB $sql -1 TAIL] + sqlite3_column_count $STMT +} 3 + +check_header $STMT capi3c-5.1 {a b c} {VARINT BLOB VARCHAR(16)} +check_origin_header $STMT capi3c-5.1 {main main main} {t1 t1 t1} {a b c} +do_test capi3c-5.2 { + sqlite3_step $STMT +} SQLITE_ROW + +check_header $STMT capi3c-5.3 {a b c} {VARINT BLOB VARCHAR(16)} +check_origin_header $STMT capi3c-5.3 {main main main} {t1 t1 t1} {a b c} +check_data $STMT capi3c-5.4 {INTEGER INTEGER TEXT} {1 2 3} {1.0 2.0 3.0} {1 2 3} + +do_test capi3c-5.5 { + sqlite3_step $STMT +} SQLITE_ROW + +check_header $STMT capi3c-5.6 {a b c} {VARINT BLOB VARCHAR(16)} +check_origin_header $STMT capi3c-5.6 {main main main} {t1 t1 t1} {a b c} +check_data $STMT capi3c-5.7 {TEXT TEXT NULL} {0 0 0} {0.0 0.0 0.0} {one two {}} + +do_test capi3c-5.8 { + sqlite3_step $STMT +} SQLITE_ROW + +check_header $STMT capi3c-5.9 {a b c} {VARINT BLOB VARCHAR(16)} +check_origin_header $STMT capi3c-5.9 {main main main} {t1 t1 t1} {a b c} +check_data $STMT capi3c-5.10 {FLOAT FLOAT TEXT} {1 1 1} {1.2 1.3 1.4} {1.2 1.3 1.4} + +do_test capi3c-5.11 { + sqlite3_step $STMT +} SQLITE_DONE + +do_test capi3c-5.12 { + sqlite3_finalize $STMT +} SQLITE_OK + +do_test capi3c-5.20 { + set sql "SELECT a, sum(b), max(c) FROM t1 GROUP BY a" + set STMT [sqlite3_prepare_v2 $DB $sql -1 TAIL] + sqlite3_column_count $STMT +} 3 + +check_header $STMT capi3c-5.21 {a sum(b) max(c)} {VARINT {} {}} +check_origin_header $STMT capi3c-5.22 {main {} {}} {t1 {} {}} {a {} {}} +do_test capi3c-5.23 { + sqlite3_finalize $STMT +} SQLITE_OK + + +set ::ENC [execsql {pragma encoding}] +db close + +do_test capi3c-6.0 { + sqlite3 db test.db + set DB [sqlite3_connection_pointer db] + if {[sqlite3 -has-codec]==0} { sqlite3_key $DB xyzzy } + set sql {SELECT a FROM t1 order by rowid} + set STMT [sqlite3_prepare_v2 $DB $sql -1 TAIL] + expr 0 +} {0} +do_test capi3c-6.1 { + db cache flush + sqlite3_close $DB +} {SQLITE_BUSY} +do_test capi3c-6.2 { + sqlite3_step $STMT +} {SQLITE_ROW} +check_data $STMT capi3c-6.3 {INTEGER} {1} {1.0} {1} +do_test capi3c-6.3 { + sqlite3_finalize $STMT +} {SQLITE_OK} +if {[clang_sanitize_address]==0} { + do_test capi3c-6.4 { + db cache flush + sqlite3_close $DB + } {SQLITE_OK} + do_test capi3c-6.99-misuse { + db close + } {} +} else { + db close +} + +# This procedure sets the value of the file-format in file 'test.db' +# to $newval. Also, the schema cookie is incremented. +# +proc set_file_format {newval} { + hexio_write test.db 44 [hexio_render_int32 $newval] + set schemacookie [hexio_get_int [hexio_read test.db 40 4]] + incr schemacookie + hexio_write test.db 40 [hexio_render_int32 $schemacookie] + return {} +} + +# This procedure returns the value of the file-format in file 'test.db'. +# +proc get_file_format {{fname test.db}} { + return [hexio_get_int [hexio_read $fname 44 4]] +} + +if {![sqlite3 -has-codec]} { + # Test what happens when the library encounters a newer file format. + do_test capi3c-7.1 { + set_file_format 5 + } {} + do_test capi3c-7.2 { + catch { sqlite3 db test.db } + catchsql { + SELECT * FROM sqlite_master; + } + } {1 {unsupported file format}} + db close +} + +if {![sqlite3 -has-codec]} { + # Now test that the library correctly handles bogus entries in the + # sqlite_master table (schema corruption). + do_test capi3c-8.1 { + forcedelete test.db test.db-journal + sqlite3 db test.db + execsql { + CREATE TABLE t1(a); + } + db close + } {} + do_test capi3c-8.2 { + sqlite3 db test.db + sqlite3_db_config db DEFENSIVE 0 + execsql { + PRAGMA writable_schema=ON; + INSERT INTO sqlite_master VALUES(NULL,NULL,NULL,NULL,NULL); + } + db close + } {} + do_test capi3c-8.3 { + catch { sqlite3 db test.db } + catchsql { + SELECT * FROM sqlite_master; + } + } {1 {malformed database schema (?)}} + do_test capi3c-8.4 { + # Build a 5-field row record. The first field is a string 'table', and + # subsequent fields are all NULL. + db close + forcedelete test.db test.db-journal + sqlite3 db test.db + sqlite3_db_config db DEFENSIVE 0 + execsql { + CREATE TABLE t1(a); + PRAGMA writable_schema=ON; + INSERT INTO sqlite_master VALUES('table',NULL,NULL,NULL,NULL); + } + db close + } {}; + do_test capi3c-8.5 { + catch { sqlite3 db test.db } + catchsql { + SELECT * FROM sqlite_master; + } + } {1 {malformed database schema (?)}} + db close +} +forcedelete test.db +forcedelete test.db-journal + + +# Test the english language string equivalents for sqlite error codes +set code2english [list \ +SQLITE_OK {not an error} \ +SQLITE_ERROR {SQL logic error} \ +SQLITE_PERM {access permission denied} \ +SQLITE_ABORT {query aborted} \ +SQLITE_BUSY {database is locked} \ +SQLITE_LOCKED {database table is locked} \ +SQLITE_NOMEM {out of memory} \ +SQLITE_READONLY {attempt to write a readonly database} \ +SQLITE_INTERRUPT {interrupted} \ +SQLITE_IOERR {disk I/O error} \ +SQLITE_CORRUPT {database disk image is malformed} \ +SQLITE_FULL {database or disk is full} \ +SQLITE_CANTOPEN {unable to open database file} \ +SQLITE_EMPTY {unknown error} \ +SQLITE_SCHEMA {database schema has changed} \ +SQLITE_CONSTRAINT {constraint failed} \ +SQLITE_MISMATCH {datatype mismatch} \ +SQLITE_MISUSE {bad parameter or other API misuse} \ +SQLITE_AUTH {authorization denied} \ +SQLITE_RANGE {column index out of range} \ +SQLITE_NOTADB {file is not a database} \ +unknownerror {unknown error} \ +] + +set test_number 1 +foreach {code english} $code2english { + do_test capi3c-9.$test_number "sqlite3_test_errstr $code" $english + incr test_number +} + +# Test the error message when a "real" out of memory occurs. +if { [permutation] != "nofaultsim" } { + do_test capi3c-10-1 { + sqlite3 db test.db + set DB [sqlite3_connection_pointer db] + sqlite3_memdebug_fail 0 + catchsql { + select * from sqlite_master; + } + } {1 {out of memory}} + do_test capi3c-10-2 { + sqlite3_errmsg $::DB + } {out of memory} + ifcapable {utf16} { + do_test capi3c-10-3 { + utf8 [sqlite3_errmsg16 $::DB] + } {out of memory} + } + db close + sqlite3_memdebug_fail -1 +} + +# The following tests - capi3c-11.* - test that a COMMIT or ROLLBACK +# statement issued while there are still outstanding VMs that are part of +# the transaction fails. +sqlite3 db test.db +set DB [sqlite3_connection_pointer db] +sqlite_register_test_function $DB func +do_test capi3c-11.1 { + execsql { + BEGIN; + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 'int'); + INSERT INTO t1 VALUES(2, 'notatype'); + } +} {} +do_test capi3c-11.1.1 { + sqlite3_get_autocommit $DB +} 0 +do_test capi3c-11.2 { + set STMT [sqlite3_prepare_v2 $DB "SELECT func(b, a) FROM t1" -1 TAIL] + sqlite3_step $STMT +} {SQLITE_ROW} + +# As of 3.6.5 a COMMIT is OK during while a query is still running - +# as long as it is a read-only query and not an incremental BLOB write. +# +do_test capi3-11.3.1 { + catchsql { + COMMIT; + } +} {0 {}} +do_test capi3-11.3.2 { + sqlite3_extended_errcode $DB +} {SQLITE_OK} +do_test capi3-11.3.3 { + sqlite3_get_autocommit $DB +} 1 +do_test capi3-11.3.4 { + db eval {PRAGMA lock_status} +} {main shared temp closed} + +do_test capi3c-11.4 { + sqlite3_step $STMT +} {SQLITE_ERROR} +do_test capi3c-11.5 { + sqlite3_finalize $STMT +} {SQLITE_ERROR} +do_test capi3c-11.6 { + catchsql { + SELECT * FROM t1; + } +} {0 {1 int 2 notatype}} +do_test capi3c-11.7 { + sqlite3_get_autocommit $DB +} 1 +do_test capi3c-11.8 { + execsql { + CREATE TABLE t2(a); + INSERT INTO t2 VALUES(1); + INSERT INTO t2 VALUES(2); + BEGIN; + INSERT INTO t2 VALUES(3); + } +} {} +do_test capi3c-11.8.1 { + sqlite3_get_autocommit $DB +} 0 +do_test capi3c-11.9 { + set STMT [sqlite3_prepare_v2 $DB "SELECT a FROM t2" -1 TAIL] + sqlite3_step $STMT +} {SQLITE_ROW} +do_test capi3c-11.9.1 { + sqlite3_get_autocommit $DB +} 0 +do_test capi3c-11.9.2 { + catchsql { + ROLLBACK; + } +} {0 {}} +do_test capi3c-11.9.3 { + sqlite3_get_autocommit $DB +} 1 +do_test capi3c-11.10 { + sqlite3_step $STMT +} {SQLITE_ROW} +do_test capi3c-11.11 { + sqlite3_step $STMT +} {SQLITE_DONE} +ifcapable !autoreset { + do_test capi3c-11.12armor { + sqlite3_step $STMT + sqlite3_step $STMT + } {SQLITE_MISUSE} +} else { + do_test capi3c-11.12 { + sqlite3_step $STMT + sqlite3_step $STMT + } {SQLITE_ROW} +} +do_test capi3c-11.13 { + sqlite3_finalize $STMT +} {SQLITE_OK} +do_test capi3c-11.14 { + execsql { + SELECT a FROM t2; + } +} {1 2} +do_test capi3c-11.14.1 { + sqlite3_get_autocommit $DB +} 1 +do_test capi3c-11.15 { + catchsql { + ROLLBACK; + } +} {1 {cannot rollback - no transaction is active}} +do_test capi3c-11.15.1 { + sqlite3_get_autocommit $DB +} 1 +do_test capi3c-11.16 { + execsql { + SELECT a FROM t2; + } +} {1 2} + +# Sanity check on the definition of 'outstanding VM'. This means any VM +# that has had sqlite3_step() called more recently than sqlite3_finalize() or +# sqlite3_reset(). So a VM that has just been prepared or reset does not +# count as an active VM. +do_test capi3c-11.17 { + execsql { + BEGIN; + } +} {} +do_test capi3c-11.18 { + set STMT [sqlite3_prepare_v2 $DB "SELECT a FROM t1" -1 TAIL] + catchsql { + COMMIT; + } +} {0 {}} +do_test capi3c-11.19 { + sqlite3_step $STMT +} {SQLITE_ROW} +do_test capi3c-11.20 { + catchsql { + BEGIN; + COMMIT; + } +} {0 {}} +do_test capi3c-11.20 { + sqlite3_reset $STMT + catchsql { + COMMIT; + } +} {1 {cannot commit - no transaction is active}} +do_test capi3c-11.21 { + sqlite3_finalize $STMT +} {SQLITE_OK} + +# The following tests - capi3c-12.* - check that its Ok to start a +# transaction while other VMs are active, and that its Ok to execute +# atomic updates in the same situation +# +do_test capi3c-12.1 { + set STMT [sqlite3_prepare_v2 $DB "SELECT a FROM t2" -1 TAIL] + sqlite3_step $STMT +} {SQLITE_ROW} +do_test capi3c-12.2 { + catchsql { + INSERT INTO t1 VALUES(3, NULL); + } +} {0 {}} +do_test capi3c-12.3 { + catchsql { + INSERT INTO t2 VALUES(4); + } +} {0 {}} +do_test capi3c-12.4 { + catchsql { + BEGIN; + INSERT INTO t1 VALUES(4, NULL); + } +} {0 {}} +do_test capi3c-12.5 { + sqlite3_step $STMT +} {SQLITE_ROW} +do_test capi3c-12.5.1 { + sqlite3_step $STMT +} {SQLITE_ROW} +do_test capi3c-12.6 { + sqlite3_step $STMT +} {SQLITE_DONE} +do_test capi3c-12.7 { + sqlite3_finalize $STMT +} {SQLITE_OK} +do_test capi3c-12.8 { + execsql { + COMMIT; + SELECT a FROM t1; + } +} {1 2 3 4} + +# Test cases capi3c-13.* test the sqlite3_clear_bindings() and +# sqlite3_sleep APIs. +# +if {[llength [info commands sqlite3_clear_bindings]]>0} { + do_test capi3c-13.1 { + execsql { + DELETE FROM t1; + } + set STMT [sqlite3_prepare_v2 $DB "INSERT INTO t1 VALUES(?, ?)" -1 TAIL] + sqlite3_step $STMT + } {SQLITE_DONE} + do_test capi3c-13.2 { + sqlite3_reset $STMT + sqlite3_bind_text $STMT 1 hello 5 + sqlite3_bind_text $STMT 2 world 5 + sqlite3_step $STMT + } {SQLITE_DONE} + do_test capi3c-13.3 { + sqlite3_reset $STMT + sqlite3_clear_bindings $STMT + sqlite3_step $STMT + } {SQLITE_DONE} + do_test capi3c-13-4 { + sqlite3_finalize $STMT + execsql { + SELECT * FROM t1; + } + } {{} {} hello world {} {}} +} +if {[llength [info commands sqlite3_sleep]]>0} { + do_test capi3c-13-5 { + set ms [sqlite3_sleep 80] + expr {$ms==80 || $ms==1000} + } {1} +} + +# Ticket #1219: Make sure binding APIs can handle a NULL pointer. +# +do_test capi3c-14.1 { + set rc [catch {sqlite3_bind_text 0 1 hello 5} msg] + lappend rc $msg +} {1 SQLITE_MISUSE} + +# Ticket #1650: Honor the nBytes parameter to sqlite3_prepare. +# +do_test capi3c-15.1 { + set sql {SELECT * FROM t2} + set nbytes [string length $sql] + append sql { WHERE a==1} + set STMT [sqlite3_prepare_v2 $DB $sql $nbytes TAIL] + sqlite3_step $STMT + sqlite3_column_int $STMT 0 +} {1} +do_test capi3c-15.2 { + sqlite3_step $STMT + sqlite3_column_int $STMT 0 +} {2} +do_test capi3c-15.3 { + sqlite3_finalize $STMT +} {SQLITE_OK} + +# Make sure code is always generated even if an IF EXISTS or +# IF NOT EXISTS clause is present that the table does not or +# does exists. That way we will always have a prepared statement +# to expire when the schema changes. +# +do_test capi3c-16.1 { + set sql {DROP TABLE IF EXISTS t3} + set STMT [sqlite3_prepare_v2 $DB $sql -1 TAIL] + sqlite3_finalize $STMT + expr {$STMT!=""} +} {1} +do_test capi3c-16.2 { + set sql {CREATE TABLE IF NOT EXISTS t1(x,y)} + set STMT [sqlite3_prepare_v2 $DB $sql -1 TAIL] + sqlite3_finalize $STMT + expr {$STMT!=""} +} {1} + +# But still we do not generate code if there is no SQL +# +do_test capi3c-16.3 { + set STMT [sqlite3_prepare_v2 $DB {} -1 TAIL] + sqlite3_finalize $STMT + expr {$STMT==""} +} {1} +do_test capi3c-16.4 { + set STMT [sqlite3_prepare_v2 $DB {;} -1 TAIL] + sqlite3_finalize $STMT + expr {$STMT==""} +} {1} + +# Ticket #2154. +# +do_test capi3c-17.1 { + set STMT [sqlite3_prepare_v2 $DB {SELECT max(a) FROM t2} -1 TAIL] + sqlite3_step $STMT +} SQLITE_ROW +do_test capi3c-17.2 { + sqlite3_column_int $STMT 0 +} 4 +do_test capi3c-17.3 { + sqlite3_step $STMT +} SQLITE_DONE +do_test capi3c-17.4 { + sqlite3_reset $STMT + db eval {CREATE INDEX i2 ON t2(a)} + sqlite3_step $STMT +} SQLITE_ROW +do_test capi3c-17.5 { + sqlite3_column_int $STMT 0 +} 4 +do_test capi3c-17.6 { + sqlite3_step $STMT +} SQLITE_DONE +do_test capi3c-17.7 { + sqlite3_reset $STMT + db eval {DROP INDEX i2} + sqlite3_step $STMT +} SQLITE_ROW +do_test capi3c-17.8 { + sqlite3_column_int $STMT 0 +} 4 +do_test capi3c-17.9 { + sqlite3_step $STMT +} SQLITE_DONE +do_test capi3c-17.10 { + sqlite3_finalize $STMT + set STMT [sqlite3_prepare_v2 $DB {SELECT b FROM t1 WHERE a=?} -1 TAIL] + sqlite3_bind_int $STMT 1 2 + db eval { + DELETE FROM t1; + INSERT INTO t1 VALUES(1,'one'); + INSERT INTO t1 VALUES(2,'two'); + INSERT INTO t1 VALUES(3,'three'); + INSERT INTO t1 VALUES(4,'four'); + } + sqlite3_step $STMT +} SQLITE_ROW +do_test capi3c-17.11 { + sqlite3_column_text $STMT 0 +} two +do_test capi3c-17.12 { + sqlite3_step $STMT +} SQLITE_DONE +do_test capi3c-17.13 { + sqlite3_reset $STMT + db eval {CREATE INDEX i1 ON t1(a)} + sqlite3_step $STMT +} SQLITE_ROW +do_test capi3c-17.14 { + sqlite3_column_text $STMT 0 +} two +do_test capi3c-17.15 { + sqlite3_step $STMT +} SQLITE_DONE +do_test capi3c-17.16 { + sqlite3_reset $STMT + db eval {DROP INDEX i1} + sqlite3_step $STMT +} SQLITE_ROW +do_test capi3c-17.17 { + sqlite3_column_text $STMT 0 +} two +do_test capi3c-17.18 { + sqlite3_step $STMT +} SQLITE_DONE +do_test capi3c-17.99 { + sqlite3_finalize $STMT +} SQLITE_OK + +# On the mailing list it has been reported that finalizing after +# an SQLITE_BUSY return leads to a segfault. Here we test that case. +# +do_test capi3c-18.1 { + sqlite3 db2 test.db + set STMT [sqlite3_prepare_v2 $DB {SELECT max(a) FROM t1} -1 TAIL] + sqlite3_step $STMT +} SQLITE_ROW +do_test capi3c-18.2 { + sqlite3_column_int $STMT 0 +} 4 +do_test capi3c-18.3 { + sqlite3_reset $STMT + db2 eval {BEGIN EXCLUSIVE} + sqlite3_step $STMT +} SQLITE_BUSY +do_test capi3c-18.4 { + sqlite3_finalize $STMT +} SQLITE_BUSY +do_test capi3c-18.5 { + db2 eval {COMMIT} + db2 close +} {} + +# Ticket #2158. The sqlite3_step() will still return SQLITE_SCHEMA +# if the database schema changes in a way that makes the statement +# no longer valid. +# +do_test capi3c-19.1 { + db eval { + CREATE TABLE t3(x,y); + INSERT INTO t3 VALUES(1,2); + } + set STMT [sqlite3_prepare_v2 $DB {SELECT * FROM t3} -1 TAIL] + sqlite3_step $STMT +} SQLITE_ROW +do_test capi3c-19.2 { + sqlite3_column_int $STMT 0 +} 1 +do_test capi3c-19.3 { + sqlite3_step $STMT +} SQLITE_DONE +do_test capi3c-19.4 { + sqlite3_reset $STMT + db eval {DROP TABLE t3} + sqlite3_step $STMT +} SQLITE_ERROR +do_test capi3c-19.4.1 { + sqlite3_errmsg $DB +} {no such table: t3} +ifcapable deprecated { + do_test capi3c-19.4.2 { + sqlite3_expired $STMT + } 1 +} +do_test capi3c-19.4.3 { + sqlite3_errmsg $DB +} {no such table: t3} +ifcapable deprecated { + do_test capi3c-19.4.4 { + sqlite3_expired 0 + } 1 +} +do_test capi3c-19.5 { + sqlite3_reset $STMT + db eval { + CREATE TABLE t3(x,y); + INSERT INTO t3 VALUES(1,2); + } + sqlite3_step $STMT +} SQLITE_ROW +ifcapable deprecated { + do_test capi3c-19.5.2 { + sqlite3_expired $STMT + } 0 +} +do_test capi3c-19.6 { + sqlite3_column_int $STMT 1 +} 2 +do_test capi3c-19.99 { + sqlite3_finalize $STMT +} SQLITE_OK + +# Make sure a change in a separate database connection does not +# cause an SQLITE_SCHEMA return. +# +do_test capi3c-20.1 { + set STMT [sqlite3_prepare_v2 $DB {SELECT * FROM t3} -1 TAIL] + sqlite3 db2 test.db + db2 eval {CREATE TABLE t4(x)} + sqlite3_step $STMT +} SQLITE_ROW +do_test capi3c-20.2 { + sqlite3_column_int $STMT 1 +} 2 +do_test capi3c-20.3 { + sqlite3_step $STMT +} SQLITE_DONE +do_test capi3c-20.4 { + db2 close + sqlite3_finalize $STMT +} SQLITE_OK + +# Test that sqlite3_step() sets the database error code correctly. +# See ticket #2497. +# +ifcapable progress { + do_test capi3c-21.1 { + set STMT [sqlite3_prepare_v2 $DB {SELECT * FROM t3} -1 TAIL] + db progress 5 "expr 1" + sqlite3_step $STMT + } {SQLITE_INTERRUPT} + do_test capi3c-21.2 { + sqlite3_extended_errcode $DB + } {SQLITE_INTERRUPT} + do_test capi3c-21.3 { + sqlite3_finalize $STMT + } {SQLITE_INTERRUPT} + do_test capi3c-21.4 { + db progress + set STMT [sqlite3_prepare $DB {SELECT * FROM t3} -1 TAIL] + db progress 5 "expr 1" + sqlite3_step $STMT + } {SQLITE_ERROR} + do_test capi3c-21.5 { + sqlite3_errcode $DB + } {SQLITE_ERROR} + do_test capi3c-21.6 { + sqlite3_finalize $STMT + } {SQLITE_INTERRUPT} + do_test capi3c-21.7 { + sqlite3_errcode $DB + } {SQLITE_INTERRUPT} + do_test capi3c-21.8 { + sqlite3_extended_errcode $DB + } {SQLITE_INTERRUPT} +} + +# Make sure sqlite3_result_error_code() returns the correct error code. +# See ticket #2940 +# +do_test capi3c-22.1 { + db progress 0 {} + set STMT [sqlite3_prepare_v2 db {SELECT test_error('the message',3)} -1 TAIL] + sqlite3_step $STMT +} {SQLITE_PERM} +sqlite3_finalize $STMT +do_test capi3c-22.2 { + set STMT [sqlite3_prepare_v2 db {SELECT test_error('the message',4)} -1 TAIL] + sqlite3_step $STMT +} {SQLITE_ABORT} +sqlite3_finalize $STMT +do_test capi3c-22.3 { + set STMT [sqlite3_prepare_v2 db {SELECT test_error('the message',16)} -1 TAIL] + sqlite3_step $STMT +} {SQLITE_EMPTY} +sqlite3_finalize $STMT + +# For a multi-column result set where the same table column is repeated +# in multiple columns of the output, verify that doing a UTF-8 to UTF-16 +# conversion (or vice versa) on one column does not change the value of +# the second. +# +ifcapable utf16 { + do_test capi3c-23.1 { + set STMT [sqlite3_prepare_v2 db {SELECT b,b,b,b FROM t1} -1 TAIL] + sqlite3_step $STMT + } {SQLITE_ROW} + do_test capi3c-23.2 { + sqlite3_column_text16 $STMT 0 + sqlite3_column_text $STMT 1 + } {one} + do_test capi3c-23.3 { + sqlite3_column_text16 $STMT 2 + sqlite3_column_text $STMT 3 + } {one} + sqlite3_finalize $STMT + do_test capi3c-23.4 { + set STMT [sqlite3_prepare_v2 db {SELECT b||'x',b,b,b FROM t1} -1 TAIL] + sqlite3_step $STMT + } {SQLITE_ROW} + do_test capi3c-23.5 { + sqlite3_column_text16 $STMT 0 + sqlite3_column_text $STMT 1 + } {one} + do_test capi3c-23.6 { + sqlite3_column_text16 $STMT 2 + sqlite3_column_text $STMT 3 + } {one} + sqlite3_finalize $STMT +} + +# Test decltype on some SELECT statements that contain sub-selects. +# +proc decltype {zSql} { + set ret [list] + set STMT [sqlite3_prepare_v2 db $zSql -1 TAIL] + for {set i 0} {$i < [sqlite3_column_count $STMT]} {incr i} { + lappend ret [sqlite3_column_decltype $STMT $i] + } + sqlite3_finalize $STMT + return $ret +} +do_test capi3c-24.1 { + execsql { CREATE TABLE t5(a INTEGER, b STRING, c DATETIME) } + decltype {SELECT * FROM t5} +} {INTEGER STRING DATETIME} +do_test capi3c-24.2 { + decltype {SELECT (SELECT c) FROM t5} +} {DATETIME} +do_test capi3c-24.3 { + decltype {SELECT (SELECT * FROM (SELECT c)) FROM t5} +} {DATETIME} +do_test capi3c-24.4 { + decltype {SELECT * FROM (SELECT * FROM t5 ORDER BY c LIMIT 1) ORDER BY b} +} {INTEGER STRING DATETIME} +do_test capi3c-24.5 { + decltype { + SELECT (SELECT x FROM (SELECT c AS x)) + FROM (SELECT * FROM t5 ORDER BY c LIMIT 1) ORDER BY b + } +} {DATETIME} +do_test capi3c-24.3 { + decltype {SELECT (SELECT x FROM (SELECT t5.a AS x)) FROM t5} +} {INTEGER} + + +# Further tests of sqlite3_column_decltype(): +# +do_execsql_test 25.0 { + CREATE TABLE t11(a VARCHAR(10), b INTEGER); + CREATE TABLE t12(a VARCHAR(15), b FLOAT); +} + +foreach {tn sql} { + 1 "SELECT * FROM t11 UNION ALL SELECT * FROM t12" + 2 "SELECT * FROM t11 UNION SELECT * FROM t12" + 3 "SELECT * FROM t11 EXCEPT SELECT * FROM t12" + 4 "SELECT * FROM t11 INTERSECT SELECT * FROM t12" + + 5 "SELECT * FROM t11 UNION ALL SELECT * FROM t12 ORDER BY 1" + 6 "SELECT * FROM t11 UNION SELECT * FROM t12 ORDER BY 1" + 7 "SELECT * FROM t11 EXCEPT SELECT * FROM t12 ORDER BY 1" + 8 "SELECT * FROM t11 INTERSECT SELECT * FROM t12 ORDER BY 1" +} { + do_test 25.$tn { decltype $sql } {VARCHAR(10) INTEGER} +} + +finish_test diff --git a/test/capi3d.test b/test/capi3d.test new file mode 100644 index 0000000..7cad287 --- /dev/null +++ b/test/capi3d.test @@ -0,0 +1,289 @@ +# 2008 June 18 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file is devoted to testing the sqlite3_next_stmt and +# sqlite3_stmt_readonly and sqlite3_stmt_busy interfaces. +# +# $Id: capi3d.test,v 1.2 2008/07/14 15:11:20 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Create N prepared statements against database connection db +# and return a list of all the generated prepared statements. +# +proc make_prepared_statements {N} { + set plist {} + for {set i 0} {$i<$N} {incr i} { + set sql "SELECT $i FROM sqlite_master WHERE name LIKE '%$i%'" + if {rand()<0.33} { + set s [sqlite3_prepare_v2 db $sql -1 notused] + } else { + ifcapable utf16 { + if {rand()<0.5} { + set sql [encoding convertto unicode $sql]\x00\x00 + set s [sqlite3_prepare16 db $sql -1 notused] + } else { + set s [sqlite3_prepare db $sql -1 notused] + } + } + ifcapable !utf16 { + set s [sqlite3_prepare db $sql -1 notused] + } + } + lappend plist $s + } + return $plist +} + + +# Scramble the $inlist into a random order. +# +proc scramble {inlist} { + set y {} + foreach x $inlist { + lappend y [list [expr {rand()}] $x] + } + set y [lsort $y] + set outlist {} + foreach x $y { + lappend outlist [lindex $x 1] + } + return $outlist +} + +# Database initially has no prepared statements. +# +do_test capi3d-1.1 { + db cache flush + sqlite3_next_stmt db 0 +} {} + +# Run the following tests for between 1 and 100 prepared statements. +# +for {set i 1} {$i<=100} {incr i} { + set stmtlist [make_prepared_statements $i] + do_test capi3d-1.2.$i.1 { + set p [sqlite3_next_stmt db 0] + set x {} + while {$p!=""} { + lappend x $p + set p [sqlite3_next_stmt db $p] + } + lsort $x + } [lsort $stmtlist] + do_test capi3-1.2.$i.2 { + foreach p [scramble $::stmtlist] { + sqlite3_finalize $p + } + sqlite3_next_stmt db 0 + } {} +} + +# Tests for the is-read-only interface. +# +proc test_is_readonly {testname sql truth} { + do_test $testname [format { + set DB [sqlite3_connection_pointer db] + set STMT [sqlite3_prepare $DB {%s} -1 TAIL] + set rc [sqlite3_stmt_readonly $STMT] + sqlite3_finalize $STMT + set rc + } $sql] $truth + + # EVIDENCE-OF: R-61212-30018 If prepared statement X is an EXPLAIN or + # EXPLAIN QUERY PLAN statement, then sqlite3_stmt_readonly(X) returns + # the same value as if the EXPLAIN or EXPLAIN QUERY PLAN prefix were + # omitted. + # + do_test $testname.explain [format { + set DB [sqlite3_connection_pointer db] + set STMT [sqlite3_prepare $DB {EXPLAIN %s} -1 TAIL] + set rc [sqlite3_stmt_readonly $STMT] + sqlite3_finalize $STMT + set rc + } $sql] $truth + do_test $testname.eqp [format { + set DB [sqlite3_connection_pointer db] + set STMT [sqlite3_prepare $DB {EXPLAIN QUERY PLAN %s} -1 TAIL] + set rc [sqlite3_stmt_readonly $STMT] + sqlite3_finalize $STMT + set rc + } $sql] $truth +} + +# EVIDENCE-OF: R-23332-64992 The sqlite3_stmt_readonly(X) interface +# returns true (non-zero) if and only if the prepared statement X makes +# no direct changes to the content of the database file. +# +test_is_readonly capi3d-2.1 {SELECT * FROM sqlite_master} 1 +test_is_readonly capi3d-2.2 {CREATE TABLE t1(x)} 0 +db eval {CREATE TABLE t1(x)} +test_is_readonly capi3d-2.3 {INSERT INTO t1 VALUES(5)} 0 +test_is_readonly capi3d-2.4 {UPDATE t1 SET x=x+1 WHERE x<0} 0 +test_is_readonly capi3d-2.5 {SELECT * FROM t1} 1 +ifcapable wal { + test_is_readonly capi3d-2.6 {PRAGMA journal_mode=WAL} 0 + test_is_readonly capi3d-2.7 {PRAGMA wal_checkpoint} 0 +} +test_is_readonly capi3d-2.8 {PRAGMA application_id=1234} 0 +test_is_readonly capi3d-2.9 {VACUUM} 0 +test_is_readonly capi3d-2.10 {PRAGMA integrity_check} 1 +do_test capi3-2.49 { + sqlite3_stmt_readonly 0 +} 1 + + +# EVIDENCE-OF: R-04929-09147 This routine returns false if there is any +# possibility that the statement might change the database file. +# +# EVIDENCE-OF: R-13288-53765 A false return does not guarantee that the +# statement will change the database file. +# +# EVIDENCE-OF: R-22182-18548 For example, an UPDATE statement might have +# a WHERE clause that makes it a no-op, but the sqlite3_stmt_readonly() +# result would still be false. +# +# EVIDENCE-OF: R-50998-48593 Similarly, a CREATE TABLE IF NOT EXISTS +# statement is a read-only no-op if the table already exists, but +# sqlite3_stmt_readonly() still returns false for such a statement. +# +db eval { + CREATE TABLE t2(a,b,c); + INSERT INTO t2 VALUES(1,2,3); +} +test_is_readonly capi3d-2.11 {UPDATE t2 SET a=a+1 WHERE false} 0 +test_is_readonly capi3d-2.12 {CREATE TABLE IF NOT EXISTS t2(x,y)} 0 + + +# EVIDENCE-OF: R-37014-01401 The ATTACH and DETACH statements also cause +# sqlite3_stmt_readonly() to return true since, while those statements +# change the configuration of a database connection, they do not make +# changes to the content of the database files on disk. +# +test_is_readonly capi3d-2.13 {ATTACH ':memory:' AS mem1} 1 +db eval {ATTACH ':memory:' AS mem1} +test_is_readonly capi3d-2.14 {DETACH mem1} 1 +db eval {DETACH mem1} + +# EVIDENCE-OF: R-07474-04783 Transaction control statements such as +# BEGIN, COMMIT, ROLLBACK, SAVEPOINT, and RELEASE cause +# sqlite3_stmt_readonly() to return true, since the statements +# themselves do not actually modify the database but rather they control +# the timing of when other statements modify the database. +# +test_is_readonly capi3d-2.15 {BEGIN} 1 +test_is_readonly capi3d-2.16 {COMMIT} 1 +test_is_readonly capi3d-2.17 {SAVEPOINT one} 1 +test_is_readonly capi3d-2.18 {RELEASE one} 1 + +# EVIDENCE-OF: R-36961-63052 The sqlite3_stmt_readonly() interface +# returns true for BEGIN since BEGIN merely sets internal flags, but the +# BEGIN IMMEDIATE and BEGIN EXCLUSIVE commands do touch the database and +# so sqlite3_stmt_readonly() returns false for those commands. +# +test_is_readonly capi3d-2.19 {BEGIN IMMEDIATE} 0 +test_is_readonly capi3d-2.20 {BEGIN EXCLUSIVE} 0 + +# EVIDENCE-OF: R-21769-42523 For example, if an application defines a +# function "eval()" that calls sqlite3_exec(), then the following SQL +# statement would change the database file through side-effects: SELECT +# eval('DELETE FROM t1') FROM t2; But because the SELECT statement does +# not change the database file directly, sqlite3_stmt_readonly() would +# still return true. +# +proc evalsql {sql} {db eval $sql} +db func eval evalsql +test_is_readonly capi3d-2.21 {SELECT eval('DELETE FROM t1') FROM t2} 1 + +# Tests for the is-explain interface. +# +proc test_is_explain {testname sql truth} { + do_test $testname [format { + set DB [sqlite3_connection_pointer db] + set STMT [sqlite3_prepare $DB {%s} -1 TAIL] + set rc [sqlite3_stmt_isexplain $STMT] + sqlite3_finalize $STMT + set rc + } $sql] $truth +} + +test_is_explain capi3d-2.51 {SELECT * FROM sqlite_master} 0 +test_is_explain capi3d-2.52 { explain SELECT * FROM sqlite_master} 1 +test_is_explain capi3d-2.53 { Explain Query Plan select * FROM sqlite_master} 2 +do_test capi3-2.99 { + sqlite3_stmt_isexplain 0 +} 0 + +# Tests for sqlite3_stmt_busy +# +do_test capi3d-3.1 { + db eval {INSERT INTO t1 VALUES(6); INSERT INTO t1 VALUES(7);} + set STMT [sqlite3_prepare db {SELECT * FROM t1} -1 TAIL] + sqlite3_stmt_busy $STMT +} {0} +do_test capi3d-3.2 { + sqlite3_step $STMT + sqlite3_stmt_busy $STMT +} {1} +do_test capi3d-3.3 { + sqlite3_step $STMT + sqlite3_stmt_busy $STMT +} {1} +do_test capi3d-3.4 { + sqlite3_reset $STMT + sqlite3_stmt_busy $STMT +} {0} + +do_test capi3d-3.99 { + sqlite3_finalize $STMT + sqlite3_stmt_busy 0 +} {0} + +#-------------------------------------------------------------------------- +# Test the sqlite3_stmt_busy() function with ROLLBACK statements. +# +reset_db + +do_execsql_test capi3d-4.1 { + CREATE TABLE t4(x,y); + BEGIN; +} + +do_test capi3d-4.2.1 { + set ::s1 [sqlite3_prepare_v2 db "ROLLBACK" -1 notused] + sqlite3_step $::s1 +} {SQLITE_DONE} + +do_test capi3d-4.2.2 { + sqlite3_stmt_busy $::s1 +} {0} + +do_catchsql_test capi3d-4.2.3 { + VACUUM +} {0 {}} + +do_test capi3d-4.2.4 { + sqlite3_reset $::s1 +} {SQLITE_OK} + +do_catchsql_test capi3d-4.2.5 { + VACUUM +} {0 {}} + +do_test capi3d-4.2.6 { + sqlite3_finalize $::s1 +} {SQLITE_OK} + + +finish_test diff --git a/test/capi3e.test b/test/capi3e.test new file mode 100644 index 0000000..3e478e7 --- /dev/null +++ b/test/capi3e.test @@ -0,0 +1,126 @@ +# 2010 Novemeber 18 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script testing the callback-free C/C++ API. +# +# $Id: capi3e.test,v 1.70 2009/01/09 02:49:32 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Make sure the system encoding is utf-8. Otherwise, if the system encoding +# is other than utf-8, [file isfile $x] may not refer to the same file +# as [sqlite3 db $x]. +# +# This is no longer needed here because it should be done within the test +# fixture executable itself, via Tcl_SetSystemEncoding. +# +# encoding system utf-8 + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +# Return the UTF-16 representation of the supplied UTF-8 string $str. +# If $nt is true, append two 0x00 bytes as a nul terminator. +proc utf16 {str {nt 1}} { + set r [encoding convertto unicode $str] + if {$nt} { + append r "\x00\x00" + } + return $r +} + +# Return the UTF-8 representation of the supplied UTF-16 string $str. +proc utf8 {str} { + # If $str ends in two 0x00 0x00 bytes, knock these off before + # converting to UTF-8 using TCL. + binary scan $str \c* vals + if {[lindex $vals end]==0 && [lindex $vals end-1]==0} { + set str [binary format \c* [lrange $vals 0 end-2]] + } + + set r [encoding convertfrom unicode $str] + return $r +} + +# These tests complement those in capi2.test. They are organized +# as follows: +# +# capi3e-1.*: Test sqlite3_open with various UTF8 filenames +# capi3e-2.*: Test sqlite3_open16 with various UTF8 filenames +# capi3e-3.*: Test ATTACH with various UTF8 filenames + +db close + +# here's the list of file names we're testing +set names {t 1 t. 1. t.d 1.d t-1 1-1 t.db ä.db ë.db ö.db ü.db ÿ.db} + +set i 0 +foreach name $names { + incr i + do_test capi3e-1.1.$i { + set db2 [sqlite3_open $name {}] + sqlite3_errcode $db2 + } {SQLITE_OK} + do_test capi3e-1.2.$i { + sqlite3_close $db2 + } {SQLITE_OK} + do_test capi3e-1.3.$i { + file isfile $name + } {1} +} + +ifcapable {utf16} { + set i 0 + foreach name $names { + incr i + do_test capi3e-2.1.$i { + set db2 [sqlite3_open16 [utf16 $name] {}] + sqlite3_errcode $db2 + } {SQLITE_OK} + do_test capi3e-2.2.$i { + sqlite3_close $db2 + } {SQLITE_OK} + do_test capi3e-2.3.$i { + file isfile $name + } {1} + } +} + +ifcapable attach { + do_test capi3e-3.1 { + sqlite3 db2 base.db + } {} + set i 0 + foreach name $names { + incr i + do_test capi3e-3.2.$i { + db2 eval "ATTACH DATABASE '$name' AS db$i;" + } {} + do_test capi3e-3.3.$i { + db2 eval "DETACH DATABASE db$i;" + } {} + } + do_test capi3e-3.4 { + db2 close + } {} +} + +# clean up +forcedelete base.db +foreach name $names { + forcedelete $name +} + +finish_test diff --git a/test/carray01.test b/test/carray01.test new file mode 100644 index 0000000..1af9cb6 --- /dev/null +++ b/test/carray01.test @@ -0,0 +1,159 @@ +# 2020-11-17 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file implements tests for CARRAY extension +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix carray01 + +ifcapable !vtab { + finish_test + return +} +load_static_extension db carray + +# Parameter $stmt must be a prepared statement created using +# the sqlite3_prepare_v2 command and with parameters fully bound. +# This routine simply runs the statement, gathers the result, and +# returns a list containing the result. +# +# If the optional second argument is true, then the stmt is finalized +# after it is run. +# +proc run_stmt {stmt} { + set r {} + while {[sqlite3_step $stmt]=="SQLITE_ROW"} { + for {set i 0} {$i<[sqlite3_data_count $stmt]} {incr i} { + lappend r [sqlite3_column_text $stmt $i] + } + } + sqlite3_reset $stmt + return $r +} + +do_test 100 { + set STMT [sqlite3_prepare_v2 db {SELECT 5 IN carray(?3)} -1] + sqlite3_carray_bind $STMT 3 1 2 3 4 5 6 7 + run_stmt $STMT +} {1} +do_test 101 { + sqlite3_carray_bind -static $STMT 3 1 2 3 4 5 6 7 + run_stmt $STMT +} {1} +do_test 102 { + set STMT2 [sqlite3_prepare_v2 db { + SELECT DISTINCT typeof(value) FROM carray(?3)} -1] + sqlite3_carray_bind $STMT2 3 1 2 3 4 5 6 7 + run_stmt $STMT2 +} {integer} +do_test 110 { + sqlite3_carray_bind $STMT 3 1 2 3 4 6 7 + run_stmt $STMT +} {0} +do_test 120 { + sqlite3_carray_bind -int64 $STMT 3 1 2 3 4 5 6 7 + run_stmt $STMT +} {1} +do_test 120b { + sqlite3_carray_bind -int64 $STMT2 3 1 2 3 4 5 6 7 + run_stmt $STMT2 +} {integer} +do_test 121 { + sqlite3_carray_bind -int64 -transient $STMT 3 1 2 3 4 5 6 7 + run_stmt $STMT +} {1} +do_test 122 { + sqlite3_carray_bind -int64 -static $STMT 3 1 2 3 4 5 6 7 + run_stmt $STMT +} {1} +do_test 123 { + sqlite3_carray_bind -int32 -transient $STMT 3 1 2 3 4 5 6 7 + run_stmt $STMT +} {1} +do_test 124 { + sqlite3_carray_bind -int32 -static $STMT 3 1 2 3 4 5 6 7 + run_stmt $STMT +} {1} +do_test 125 { + sqlite3_carray_bind -int32 $STMT 3 1 2 3 4 5 6 7 + run_stmt $STMT +} {1} +do_test 130 { + sqlite3_carray_bind -int64 $STMT 3 1 2 3 4 6 7 + run_stmt $STMT +} {0} +do_test 131 { + sqlite3_carray_bind -int64 -transient $STMT 3 1 2 3 4 6 7 + run_stmt $STMT +} {0} +do_test 131 { + sqlite3_carray_bind -int64 -static $STMT 3 1 2 3 4 6 7 + run_stmt $STMT +} {0} +do_test 140 { + sqlite3_carray_bind -double $STMT 3 1 2 3 4 5 6 7 + run_stmt $STMT +} {1} +do_test 141 { + sqlite3_carray_bind -double -transient $STMT 3 1 2 3 4 5 6 7 + run_stmt $STMT +} {1} +do_test 142 { + sqlite3_carray_bind -double -static $STMT 3 1 2 3 4 5 6 7 + run_stmt $STMT +} {1} +do_test 143 { + sqlite3_carray_bind -double $STMT2 3 1 2 3 4 5 6 7 + run_stmt $STMT2 +} {real} +do_test 150 { + sqlite3_carray_bind -double $STMT 3 1 2 3 4 6 7 + run_stmt $STMT +} {0} +do_test 160 { + sqlite3_carray_bind -double $STMT 3 1 2 3 4 5 6 7 + run_stmt $STMT +} {1} +do_test 170 { + sqlite3_carray_bind -text -static $STMT 3 1 2 3 4 6 7 + run_stmt $STMT +} {0} +do_test 171 { + sqlite3_carray_bind -text -static $STMT2 3 1 2 3 4 6 7 + run_stmt $STMT2 +} {text} +do_test 180 { + sqlite3_carray_bind -text -transient $STMT 3 1 2 3 4 5 6 7 + run_stmt $STMT +} {0} +do_test 190 { + sqlite3_carray_bind -blob -static $STMT 3 1 2 3 4 5 6 7 + run_stmt $STMT +} {0} +do_test 191 { + sqlite3_carray_bind -blob -static $STMT2 3 1 2 3 4 5 6 7 + run_stmt $STMT2 +} {blob} +do_test 200 { + sqlite3_carray_bind -blob -transient $STMT 3 1 2 3 4 5 6 7 + run_stmt $STMT +} {0} +do_test 300 { + sqlite3_carray_bind $STMT 3 + run_stmt $STMT +} {0} + +sqlite3_finalize $STMT +sqlite3_finalize $STMT2 + +finish_test diff --git a/test/cast.test b/test/cast.test new file mode 100644 index 0000000..ebfea5a --- /dev/null +++ b/test/cast.test @@ -0,0 +1,560 @@ +# 2005 June 25 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing the CAST operator. +# +# $Id: cast.test,v 1.10 2008/11/06 15:33:04 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Only run these tests if the build includes the CAST operator +ifcapable !cast { + finish_test + return +} + +# Tests for the CAST( AS blob), CAST( AS text) and CAST( AS numeric) built-ins +# +ifcapable bloblit { + do_test cast-1.1 { + execsql {SELECT x'616263'} + } abc + do_test cast-1.2 { + execsql {SELECT typeof(x'616263')} + } blob + do_test cast-1.3 { + execsql {SELECT CAST(x'616263' AS text)} + } abc + do_test cast-1.4 { + execsql {SELECT typeof(CAST(x'616263' AS text))} + } text + do_test cast-1.5 { + execsql {SELECT CAST(x'616263' AS numeric)} + } 0 + do_test cast-1.6 { + execsql {SELECT typeof(CAST(x'616263' AS numeric))} + } integer + do_test cast-1.7 { + execsql {SELECT CAST(x'616263' AS blob)} + } abc + do_test cast-1.8 { + execsql {SELECT typeof(CAST(x'616263' AS blob))} + } blob + do_test cast-1.9 { + execsql {SELECT CAST(x'616263' AS integer)} + } 0 + do_test cast-1.10 { + execsql {SELECT typeof(CAST(x'616263' AS integer))} + } integer +} +do_test cast-1.11 { + execsql {SELECT null} +} {{}} +do_test cast-1.12 { + execsql {SELECT typeof(NULL)} +} null +do_test cast-1.13 { + execsql {SELECT CAST(NULL AS text)} +} {{}} +do_test cast-1.14 { + execsql {SELECT typeof(CAST(NULL AS text))} +} null +do_test cast-1.15 { + execsql {SELECT CAST(NULL AS numeric)} +} {{}} +do_test cast-1.16 { + execsql {SELECT typeof(CAST(NULL AS numeric))} +} null +do_test cast-1.17 { + execsql {SELECT CAST(NULL AS blob)} +} {{}} +do_test cast-1.18 { + execsql {SELECT typeof(CAST(NULL AS blob))} +} null +do_test cast-1.19 { + execsql {SELECT CAST(NULL AS integer)} +} {{}} +do_test cast-1.20 { + execsql {SELECT typeof(CAST(NULL AS integer))} +} null +do_test cast-1.21 { + execsql {SELECT 123} +} {123} +do_test cast-1.22 { + execsql {SELECT typeof(123)} +} integer +do_test cast-1.23 { + execsql {SELECT CAST(123 AS text)} +} {123} +do_test cast-1.24 { + execsql {SELECT typeof(CAST(123 AS text))} +} text +do_test cast-1.25 { + execsql {SELECT CAST(123 AS numeric)} +} 123 +do_test cast-1.26 { + execsql {SELECT typeof(CAST(123 AS numeric))} +} integer +do_test cast-1.27 { + execsql {SELECT CAST(123 AS blob)} +} {123} +do_test cast-1.28 { + execsql {SELECT typeof(CAST(123 AS blob))} +} blob +do_test cast-1.29 { + execsql {SELECT CAST(123 AS integer)} +} {123} +do_test cast-1.30 { + execsql {SELECT typeof(CAST(123 AS integer))} +} integer +do_test cast-1.31 { + execsql {SELECT 123.456} +} {123.456} +do_test cast-1.32 { + execsql {SELECT typeof(123.456)} +} real +do_test cast-1.33 { + execsql {SELECT CAST(123.456 AS text)} +} {123.456} +do_test cast-1.34 { + execsql {SELECT typeof(CAST(123.456 AS text))} +} text +do_test cast-1.35 { + execsql {SELECT CAST(123.456 AS numeric)} +} 123.456 +do_test cast-1.36 { + execsql {SELECT typeof(CAST(123.456 AS numeric))} +} real +do_test cast-1.37 { + execsql {SELECT CAST(123.456 AS blob)} +} {123.456} +do_test cast-1.38 { + execsql {SELECT typeof(CAST(123.456 AS blob))} +} blob +do_test cast-1.39 { + execsql {SELECT CAST(123.456 AS integer)} +} {123} +do_test cast-1.38 { + execsql {SELECT typeof(CAST(123.456 AS integer))} +} integer +do_test cast-1.41 { + execsql {SELECT '123abc'} +} {123abc} +do_test cast-1.42 { + execsql {SELECT typeof('123abc')} +} text +do_test cast-1.43 { + execsql {SELECT CAST('123abc' AS text)} +} {123abc} +do_test cast-1.44 { + execsql {SELECT typeof(CAST('123abc' AS text))} +} text +do_test cast-1.45 { + execsql {SELECT CAST('123abc' AS numeric)} +} 123 +do_test cast-1.46 { + execsql {SELECT typeof(CAST('123abc' AS numeric))} +} integer +do_test cast-1.47 { + execsql {SELECT CAST('123abc' AS blob)} +} {123abc} +do_test cast-1.48 { + execsql {SELECT typeof(CAST('123abc' AS blob))} +} blob +do_test cast-1.49 { + execsql {SELECT CAST('123abc' AS integer)} +} 123 +do_test cast-1.50 { + execsql {SELECT typeof(CAST('123abc' AS integer))} +} integer +do_test cast-1.51 { + execsql {SELECT CAST('123.5abc' AS numeric)} +} 123.5 +do_test cast-1.53 { + execsql {SELECT CAST('123.5abc' AS integer)} +} 123 + +do_test cast-1.60 { + execsql {SELECT CAST(null AS REAL)} +} {{}} +do_test cast-1.61 { + execsql {SELECT typeof(CAST(null AS REAL))} +} {null} +do_test cast-1.62 { + execsql {SELECT CAST(1 AS REAL)} +} {1.0} +do_test cast-1.63 { + execsql {SELECT typeof(CAST(1 AS REAL))} +} {real} +do_test cast-1.64 { + execsql {SELECT CAST('1' AS REAL)} +} {1.0} +do_test cast-1.65 { + execsql {SELECT typeof(CAST('1' AS REAL))} +} {real} +do_test cast-1.66 { + execsql {SELECT CAST('abc' AS REAL)} +} {0.0} +do_test cast-1.67 { + execsql {SELECT typeof(CAST('abc' AS REAL))} +} {real} +do_test cast-1.68 { + execsql {SELECT CAST(x'31' AS REAL)} +} {1.0} +do_test cast-1.69 { + execsql {SELECT typeof(CAST(x'31' AS REAL))} +} {real} + + +# Ticket #1662. Ignore leading spaces in numbers when casting. +# +do_test cast-2.1 { + execsql {SELECT CAST(' 123' AS integer)} +} 123 +do_test cast-2.2 { + execsql {SELECT CAST(' -123.456' AS real)} +} -123.456 + +# ticket #2364. Use full percision integers if possible when casting +# to numeric. Do not fallback to real (and the corresponding 48-bit +# mantissa) unless absolutely necessary. +# +do_test cast-3.1 { + execsql {SELECT CAST(9223372036854774800 AS integer)} +} 9223372036854774800 +do_test cast-3.2 { + execsql {SELECT CAST(9223372036854774800 AS numeric)} +} 9223372036854774800 +do_realnum_test cast-3.3 { + execsql {SELECT CAST(9223372036854774800 AS real)} +} 9.22337203685477e+18 +do_test cast-3.4 { + execsql {SELECT CAST(CAST(9223372036854774800 AS real) AS integer)} +} 9223372036854774784 +do_test cast-3.5 { + execsql {SELECT CAST(-9223372036854774800 AS integer)} +} -9223372036854774800 +do_test cast-3.6 { + execsql {SELECT CAST(-9223372036854774800 AS numeric)} +} -9223372036854774800 +do_realnum_test cast-3.7 { + execsql {SELECT CAST(-9223372036854774800 AS real)} +} -9.22337203685477e+18 +do_test cast-3.8 { + execsql {SELECT CAST(CAST(-9223372036854774800 AS real) AS integer)} +} -9223372036854774784 +do_test cast-3.11 { + execsql {SELECT CAST('9223372036854774800' AS integer)} +} 9223372036854774800 +do_test cast-3.12 { + execsql {SELECT CAST('9223372036854774800' AS numeric)} +} 9223372036854774800 +do_realnum_test cast-3.13 { + execsql {SELECT CAST('9223372036854774800' AS real)} +} 9.22337203685477e+18 +ifcapable long_double { + do_test cast-3.14 { + execsql {SELECT CAST(CAST('9223372036854774800' AS real) AS integer)} + } 9223372036854774784 +} +do_test cast-3.15 { + execsql {SELECT CAST('-9223372036854774800' AS integer)} +} -9223372036854774800 +do_test cast-3.16 { + execsql {SELECT CAST('-9223372036854774800' AS numeric)} +} -9223372036854774800 +do_realnum_test cast-3.17 { + execsql {SELECT CAST('-9223372036854774800' AS real)} +} -9.22337203685477e+18 +ifcapable long_double { + do_test cast-3.18 { + execsql {SELECT CAST(CAST('-9223372036854774800' AS real) AS integer)} + } -9223372036854774784 +} +if {[db eval {PRAGMA encoding}]=="UTF-8"} { + do_test cast-3.21 { + execsql {SELECT CAST(x'39323233333732303336383534373734383030' AS integer)} + } 9223372036854774800 + do_test cast-3.22 { + execsql {SELECT CAST(x'39323233333732303336383534373734383030' AS numeric)} + } 9223372036854774800 + do_realnum_test cast-3.23 { + execsql {SELECT CAST(x'39323233333732303336383534373734383030' AS real)} + } 9.22337203685477e+18 + ifcapable long_double { + do_test cast-3.24 { + execsql { + SELECT CAST(CAST(x'39323233333732303336383534373734383030' AS real) + AS integer) + } + } 9223372036854774784 + } +} +do_test cast-3.31 { + execsql {SELECT CAST(NULL AS numeric)} +} {{}} + +# Test to see if it is possible to trick SQLite into reading past +# the end of a blob when converting it to a number. +do_test cast-3.32.1 { + set blob "1234567890" + set DB [sqlite3_connection_pointer db] + set ::STMT [sqlite3_prepare $DB {SELECT CAST(? AS real)} -1 TAIL] + sqlite3_bind_blob -static $::STMT 1 $blob 5 + sqlite3_step $::STMT +} {SQLITE_ROW} +do_test cast-3.32.2 { + sqlite3_column_int $::STMT 0 +} {12345} +do_test cast-3.32.3 { + sqlite3_finalize $::STMT +} {SQLITE_OK} + + +do_test cast-4.1 { + db eval { + CREATE TABLE t1(a); + INSERT INTO t1 VALUES('abc'); + SELECT a, CAST(a AS integer) FROM t1; + } +} {abc 0} +do_test cast-4.2 { + db eval { + SELECT CAST(a AS integer), a FROM t1; + } +} {0 abc} +do_test cast-4.3 { + db eval { + SELECT a, CAST(a AS integer), a FROM t1; + } +} {abc 0 abc} +do_test cast-4.4 { + db eval { + SELECT CAST(a AS integer), a, CAST(a AS real), a FROM t1; + } +} {0 abc 0.0 abc} + +# Added 2018-01-26 +# +# EVIDENCE-OF: R-48741-32454 If the prefix integer is greater than +# +9223372036854775807 then the result of the cast is exactly +# +9223372036854775807. +do_execsql_test cast-5.1 { + SELECT CAST('9223372036854775808' AS integer); + SELECT CAST(' +000009223372036854775808' AS integer); + SELECT CAST('12345678901234567890123' AS INTEGER); +} {9223372036854775807 9223372036854775807 9223372036854775807} + +# EVIDENCE-OF: R-06028-16857 Similarly, if the prefix integer is less +# than -9223372036854775808 then the result of the cast is exactly +# -9223372036854775808. +do_execsql_test cast-5.2 { + SELECT CAST('-9223372036854775808' AS integer); + SELECT CAST('-9223372036854775809' AS integer); + SELECT CAST('-12345678901234567890123' AS INTEGER); +} {-9223372036854775808 -9223372036854775808 -9223372036854775808} + +# EVIDENCE-OF: R-33990-33527 When casting to INTEGER, if the text looks +# like a floating point value with an exponent, the exponent will be +# ignored because it is no part of the integer prefix. +# EVIDENCE-OF: R-24225-46995 For example, "(CAST '123e+5' AS INTEGER)" +# results in 123, not in 12300000. +do_execsql_test cast-5.3 { + SELECT CAST('123e+5' AS INTEGER); + SELECT CAST('123e+5' AS NUMERIC); + SELECT CAST('123e+5' AS REAL); +} {123 12300000 12300000.0} + + +# The following does not have anything to do with the CAST operator, +# but it does deal with affinity transformations. +# +do_execsql_test cast-6.1 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(a NUMERIC); + INSERT INTO t1 VALUES + ('9000000000000000001'), + ('9000000000000000001 '), + (' 9000000000000000001'), + (' 9000000000000000001 '); + SELECT * FROM t1; +} {9000000000000000001 9000000000000000001 9000000000000000001 9000000000000000001} + +# 2019-06-07 +# https://www.sqlite.org/src/info/4c2d7639f076aa7c +do_execsql_test cast-7.1 { + SELECT CAST('-' AS NUMERIC); +} {0} +do_execsql_test cast-7.2 { + SELECT CAST('-0' AS NUMERIC); +} {0} +do_execsql_test cast-7.3 { + SELECT CAST('+' AS NUMERIC); +} {0} +do_execsql_test cast-7.4 { + SELECT CAST('/' AS NUMERIC); +} {0} + +# 2019-06-07 +# https://www.sqlite.org/src/info/e8bedb2a184001bb +do_execsql_test cast-7.10 { + SELECT '' - 2851427734582196970; +} {-2851427734582196970} +do_execsql_test cast-7.11 { + SELECT 0 - 2851427734582196970; +} {-2851427734582196970} +do_execsql_test cast-7.12 { + SELECT '' - 1; +} {-1} + +# 2019-06-10 +# https://www.sqlite.org/src/info/dd6bffbfb6e61db9 +# +# EVIDENCE-OF: R-55084-10555 Casting a TEXT or BLOB value into NUMERIC +# yields either an INTEGER or a REAL result. +# +do_execsql_test cast-7.20 { + DROP TABLE IF EXISTS t0; + CREATE TABLE t0 (c0 TEXT); + INSERT INTO t0(c0) VALUES ('1.0'); + SELECT CAST(c0 AS NUMERIC) FROM t0; +} {1} + +# 2019-06-10 +# https://sqlite.org/src/info/27de823723a41df45af3 +# +do_execsql_test cast-7.30 { + SELECT -'.'; +} 0 +do_execsql_test cast-7.31 { + SELECT '.'+0; +} 0 +do_execsql_test cast-7.32 { + SELECT CAST('.' AS numeric); +} 0 +do_execsql_test cast-7.33 { + SELECT -CAST('.' AS numeric); +} 0 + +# 2019-06-12 +# https://www.sqlite.org/src/info/674385aeba91c774 +# +do_execsql_test cast-7.40 { + SELECT CAST('-0.0' AS numeric); +} 0 +do_execsql_test cast-7.41 { + SELECT CAST('0.0' AS numeric); +} 0 +do_execsql_test cast-7.42 { + SELECT CAST('+0.0' AS numeric); +} 0 +do_execsql_test cast-7.43 { + SELECT CAST('-1.0' AS numeric); +} -1 + +ifcapable utf16 { + reset_db + execsql { PRAGMA encoding='utf16' } + + do_execsql_test cast-8.1 { + SELECT quote(X'310032003300')==quote(substr(X'310032003300', 1)) + } 1 + do_execsql_test cast-8.2 { + SELECT CAST(X'310032003300' AS TEXT) + ==CAST(substr(X'310032003300', 1) AS TEXT) + } 1 +} + +reset_db +do_execsql_test cast-9.0 { + CREATE TABLE t0(c0); + INSERT INTO t0(c0) VALUES (0); + CREATE VIEW v1(c0, c1) AS + SELECT CAST(0.0 AS NUMERIC), COUNT(*) OVER () FROM t0; + SELECT v1.c0 FROM v1, t0 WHERE v1.c0=0; +} {0.0} + +# Set the 2022-12-10 "reopen" of ticket [https://sqlite.org/src/tktview/57c47526c3] +# +do_execsql_test cast-9.1 { + CREATE TABLE dual(dummy TEXT); + INSERT INTO dual VALUES('X'); + SELECT CAST(4 AS NUMERIC); +} {4} +do_execsql_test cast-9.2 { + SELECT CAST(4.0 AS NUMERIC); +} {4.0} +do_execsql_test cast-9.3 { + SELECT CAST(4.5 AS NUMERIC); +} {4.5} +do_execsql_test cast-9.4 { + SELECT x, typeof(x) FROM (SELECT CAST(4 AS NUMERIC) AS x) JOIN dual; +} {4 integer} +do_execsql_test cast-9.5 { + SELECT x, typeof(x) FROM dual CROSS JOIN (SELECT CAST(4 AS NUMERIC) AS x); +} {4 integer} +do_execsql_test cast-9.10 { + SELECT x, typeof(x) FROM (SELECT CAST(4.0 AS NUMERIC) AS x) JOIN dual; +} {4.0 real} +do_execsql_test cast-9.11 { + SELECT x, typeof(x) FROM dual CROSS JOIN (SELECT CAST(4.0 AS NUMERIC) AS x); +} {4.0 real} +do_execsql_test cast-9.12 { + SELECT x, typeof(x) FROM (SELECT CAST(4.5 AS NUMERIC) AS x) JOIN dual; +} {4.5 real} +do_execsql_test cast-9.13 { + SELECT x, typeof(x) FROM dual CROSS JOIN (SELECT CAST(4.5 AS NUMERIC) AS x); +} {4.5 real} + +# 2022-12-15 dbsqlfuzz c9ee6f9a0a8b8fefb02cf69de2a8b67ca39525c8 +# +# Added a new SQLITE_AFF_FLEXNUM that does not try to convert int to real or +# real to int. +# +do_execsql_test cast-10.1 { + VALUES(CAST(44 AS REAL)),(55); +} {44.0 55} +do_execsql_test cast-10.2 { + SELECT CAST(44 AS REAL) AS 'm' UNION ALL SELECT 55; +} {44.0 55} +do_execsql_test cast-10.3 { + SELECT * FROM (VALUES(CAST(44 AS REAL)),(55)); +} {44.0 55} +do_execsql_test cast-10.4 { + SELECT * FROM (SELECT CAST(44 AS REAL) AS 'm' UNION ALL SELECT 55); +} {44.0 55} +do_execsql_test cast-10.5 { + SELECT * FROM dual CROSS JOIN (VALUES(CAST(44 AS REAL)),(55)); +} {X 44.0 X 55} +do_execsql_test cast-10.6 { + SELECT * FROM dual CROSS JOIN (SELECT CAST(44 AS REAL) AS 'm' + UNION ALL SELECT 55); +} {X 44.0 X 55} +ifcapable vtab { + do_execsql_test cast-10.7 { + DROP VIEW v1; + CREATE VIEW v1 AS SELECT CAST(44 AS REAL) AS 'm' UNION ALL SELECT 55; + SELECT name, type FROM pragma_table_info('v1'); + } {m NUM} + do_execsql_test cast-10.8 { + CREATE VIEW v2 AS VALUES(CAST(44 AS REAL)),(55); + SELECT type FROM pragma_table_info('v2'); + } {NUM} + do_execsql_test cast-10.9 { + SELECT * FROM v1; + } {44.0 55} + do_execsql_test cast-10.10 { + SELECT * FROM v2; + } {44.0 55} +} + +finish_test diff --git a/test/cffault.test b/test/cffault.test new file mode 100644 index 0000000..0d029ec --- /dev/null +++ b/test/cffault.test @@ -0,0 +1,158 @@ +# 2011 November 16 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file contains fault-injection test cases for the +# sqlite3_db_cacheflush API. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix cffault +source $testdir/malloc_common.tcl + +# Run the supplied SQL on a copy of the database currently stored on +# disk in file $dbfile. +proc diskquery {dbfile sql} { + forcecopy $dbfile dq.db + sqlite3 dq dq.db + set res [execsql $sql dq] + dq close + set res +} + +do_execsql_test 1.0 { + CREATE TABLE t1(a PRIMARY KEY, b); + CREATE INDEX i1 ON t1(b); + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t1 VALUES(3, 4); + INSERT INTO t1 VALUES(5, 6); + INSERT INTO t1 VALUES(7, 8); +} +faultsim_save_and_close + +do_faultsim_test 1.1 -prep { + faultsim_restore_and_reopen + db eval { + BEGIN; + UPDATE t1 SET b=b+1; + } +} -body { + sqlite3_db_cacheflush db +} -test { + if {[sqlite3_get_autocommit db]} { error "Transaction rolled back!" } + faultsim_test_result {0 {}} {1 {disk I/O error}} + catch { db eval COMMIT } + faultsim_integrity_check +} + +do_faultsim_test 1.2 -prep { + faultsim_restore_and_reopen + db eval { + BEGIN; + UPDATE t1 SET b=b+1; + } +} -body { + set result [list] + db eval { SELECT * FROM t1 } { + if {$a==5} { catch { sqlite3_db_cacheflush db } } + lappend result $a $b + } + set result +} -test { + faultsim_test_result {0 {1 3 3 5 5 7 7 9}} {1 {disk I/O error}} + catch { db eval COMMIT } + faultsim_integrity_check +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 2.0 { + CREATE TABLE t1(a PRIMARY KEY, b, c); + CREATE INDEX i1 ON t1(b); + CREATE INDEX i2 ON t1(c, b); + INSERT INTO t1 VALUES(1, 2, randomblob(600)); + INSERT INTO t1 VALUES(3, 4, randomblob(600)); + INSERT INTO t1 VALUES(5, 6, randomblob(600)); + INSERT INTO t1 VALUES(7, 8, randomblob(600)); + INSERT INTO t1 VALUES(9, 10, randomblob(600)); +} +faultsim_save_and_close + +do_faultsim_test 2.1 -prep { + faultsim_restore_and_reopen + db eval { + BEGIN; + UPDATE t1 SET b=b+1; + } +} -body { + set result [list] + db eval { SELECT * FROM t1 } { + if {$a==5} { catch { sqlite3_db_cacheflush db } } + lappend result $a $b + } + set result +} -test { + faultsim_test_result {0 {1 3 3 5 5 7 7 9 9 11}} {1 {disk I/O error}} + catch { db eval { INSERT INTO t1 VALUES(11, 12, randomblob(600)) } } + catch { db eval COMMIT } + faultsim_integrity_check +} + +do_faultsim_test 2.2 -prep { + faultsim_restore_and_reopen + db eval { + BEGIN; + UPDATE t1 SET b=b+1; + } +} -body { + sqlite3_db_cacheflush db +} -test { + if {[sqlite3_get_autocommit db]} { error "Transaction rolled back!" } + faultsim_test_result {0 {}} {1 {disk I/O error}} + catch { db eval { SELECT * FROM t1 } } + catch { db eval COMMIT } + faultsim_integrity_check +} + +do_faultsim_test 2.3 -prep { + faultsim_restore_and_reopen + db eval { + BEGIN; + UPDATE t1 SET b=b-1; + } +} -body { + sqlite3_db_cacheflush db +} -test { + if {[sqlite3_get_autocommit db]} { error "Transaction rolled back!" } + faultsim_test_result {0 {}} {1 {disk I/O error}} + catch { db eval { INSERT INTO t1 VALUES(11, 12, randomblob(600)) } } + catch { db eval COMMIT } + faultsim_integrity_check +} + +do_faultsim_test 2.4 -prep { + faultsim_restore_and_reopen + db eval { + BEGIN; + UPDATE t1 SET b=b-1; + } +} -body { + catch { sqlite3_db_cacheflush db } + catch { sqlite3_db_release_memory db } + catch { sqlite3_db_cacheflush db } + execsql { SELECT a, b FROM t1 } +} -test { + faultsim_test_result {0 {1 1 3 3 5 5 7 7 9 9}} {1 {disk I/O error}} + catchsql ROLLBACK + faultsim_integrity_check +} + +finish_test diff --git a/test/changes.test b/test/changes.test new file mode 100644 index 0000000..b3a2ae1 --- /dev/null +++ b/test/changes.test @@ -0,0 +1,88 @@ +# 2021 June 22 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Tests for the sqlite3_changes() and sqlite3_total_changes() APIs. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix changes + +# To test that the change-counters do not suffer from 32-bit signed integer +# rollover, add the following line to the array of test cases below. The +# test will take will over an hour to run. +# +# 7 (1<<31)+10 "" +# + +foreach {tn nRow wor} { + 1 50 "" + 2 50 "WITHOUT ROWID" + + 3 5000 "" + 4 5000 "WITHOUT ROWID" + + 5 50000 "" + 6 50000 "WITHOUT ROWID" +} { + reset_db + set nBig [expr $nRow] + + do_execsql_test 1.$tn.0 " + PRAGMA journal_mode = off; + CREATE TABLE t1(x INTEGER PRIMARY KEY) $wor; + " {off} + + do_execsql_test 1.$tn.1 { + WITH s(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i < $nBig + ) + INSERT INTO t1 SELECT i FROM s; + } + + do_test 1.$tn.2 { + db changes + } [expr $nBig] + + do_test 1.$tn.3 { + db total_changes + } [expr $nBig] + + do_execsql_test 1.$tn.4 { + INSERT INTO t1 VALUES(-1) + } + + do_test 1.$tn.5 { + db changes + } [expr 1] + + do_test 1.$tn.6 { + db total_changes + } [expr {$nBig+1}] + + do_execsql_test 1.$tn.7a { + SELECT count(*) FROM t1 + } [expr {$nBig+1}] + + do_execsql_test 1.$tn.7 { + DELETE FROM t1 + } + + do_test 1.$tn.8 { + db changes + } [expr {$nBig+1}] + + do_test 1.$tn.9 { + db total_changes + } [expr {2*($nBig+1)}] +} + +finish_test diff --git a/test/changes2.test b/test/changes2.test new file mode 100644 index 0000000..5b2684a --- /dev/null +++ b/test/changes2.test @@ -0,0 +1,94 @@ +# 2022 June 6 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix changes2 + +do_execsql_test 1.0 { + CREATE TABLE some_table ( + id INTEGER NOT NULL, value VARCHAR(40) NOT NULL, PRIMARY KEY (id) + ); + INSERT INTO some_table (id, value) VALUES (1, 'v1'); +} {} + +set ::stmt [sqlite3_prepare_v2 db { + UPDATE some_table SET value='v2' WHERE id=1 RETURNING id +} -1 dummy] + +do_test 1.1 { + list [sqlite3_step $::stmt] [db changes] +} {SQLITE_ROW 1} + +do_test 1.2 { + list [sqlite3_step $::stmt] [db changes] +} {SQLITE_DONE 1} + +sqlite3_reset $::stmt + +do_execsql_test 1.2 { + DROP TABLE some_table; + CREATE TABLE some_table ( + id INTEGER NOT NULL, value VARCHAR(40) NOT NULL, PRIMARY KEY (id) + ); + INSERT INTO some_table (id, value) VALUES (1, 'v1'); +} {} + +do_test 1.3 { + list [sqlite3_step $::stmt] [db changes] +} {SQLITE_ROW 1} + +do_test 1.4 { + list [sqlite3_step $::stmt] [db changes] +} {SQLITE_DONE 1} + +sqlite3_finalize $::stmt + +#------------------------------------------------------------------------- +reset_db + +do_execsql_test 2.0 { + CREATE TABLE t1(a, b); + CREATE TABLE log(t); +} {} + +set ::stmt [sqlite3_prepare_v2 db { + INSERT INTO log VALUES(changes() || ' changes') +} -1 dummy] + +do_execsql_test 2.1 { + INSERT INTO t1 VALUES (1, 'v1'), (2, 'v2'); +} {} + +do_test 2.2 { + list [sqlite3_step $::stmt] [sqlite3_reset $::stmt] +} {SQLITE_DONE SQLITE_OK} + +do_execsql_test 2.3 { + CREATE TABLE t3(x); +} + +do_execsql_test 2.2 { + INSERT INTO t1 VALUES (3, 'v1'), (4, 'v2'); +} {} + +do_test 2.3 { + list [sqlite3_step $::stmt] [sqlite3_reset $::stmt] +} {SQLITE_DONE SQLITE_OK} + +sqlite3_finalize $::stmt + +do_execsql_test 2.4 { + SELECT * FROM log; +} {{2 changes} {2 changes}} + +finish_test diff --git a/test/check.test b/test/check.test new file mode 100644 index 0000000..10d1cf4 --- /dev/null +++ b/test/check.test @@ -0,0 +1,615 @@ +# 2005 November 2 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing CHECK constraints +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix check + +# Only run these tests if the build includes support for CHECK constraints +ifcapable !check { + finish_test + return +} +sqlite3_db_config db SQLITE_DBCONFIG_DQS_DDL 1 +sqlite3_db_config db SQLITE_DBCONFIG_DQS_DML 1 + +do_test check-1.1 { + execsql { + CREATE TABLE t1( + x INTEGER CHECK( x<5 ), + y REAL CHECK( y>x ) + ); + } +} {} +do_test check-1.2 { + execsql { + INSERT INTO t1 VALUES(3,4); + SELECT * FROM t1; + } +} {3 4.0} +do_test check-1.3 { + catchsql { + INSERT INTO t1 VALUES(6,7); + } +} {1 {CHECK constraint failed: x<5}} +do_test check-1.4 { + execsql { + SELECT * FROM t1; + } +} {3 4.0} +do_test check-1.5 { + catchsql { + INSERT INTO t1 VALUES(4,3); + } +} {1 {CHECK constraint failed: y>x}} +do_test check-1.6 { + execsql { + SELECT * FROM t1; + } +} {3 4.0} +do_test check-1.7 { + catchsql { + INSERT INTO t1 VALUES(NULL,6); + } +} {0 {}} +do_test check-1.8 { + execsql { + SELECT * FROM t1; + } +} {3 4.0 {} 6.0} +do_test check-1.9 { + catchsql { + INSERT INTO t1 VALUES(2,NULL); + } +} {0 {}} +do_test check-1.10 { + execsql { + SELECT * FROM t1; + } +} {3 4.0 {} 6.0 2 {}} +do_test check-1.11 { + execsql { + DELETE FROM t1 WHERE x IS NULL OR x!=3; + UPDATE t1 SET x=2 WHERE x==3; + SELECT * FROM t1; + } +} {2 4.0} +do_test check-1.12 { + catchsql { + UPDATE t1 SET x=7 WHERE x==2 + } +} {1 {CHECK constraint failed: x<5}} +do_test check-1.13 { + execsql { + SELECT * FROM t1; + } +} {2 4.0} +do_test check-1.14 { + catchsql { + UPDATE t1 SET x=5 WHERE x==2 + } +} {1 {CHECK constraint failed: x<5}} +do_test check-1.15 { + execsql { + SELECT * FROM t1; + } +} {2 4.0} +do_test check-1.16 { + catchsql { + UPDATE t1 SET x=4, y=11 WHERE x==2 + } +} {0 {}} +do_test check-1.17 { + execsql { + SELECT * FROM t1; + } +} {4 11.0} + +do_test check-2.1 { + execsql { + PRAGMA writable_schema = 1; + CREATE TABLE t2( + x INTEGER CONSTRAINT one CHECK( typeof(coalesce(x,0))=="integer" ), + y REAL CONSTRAINT two CHECK( typeof(coalesce(y,0.1))=='real' ), + z TEXT CONSTRAINT three CHECK( typeof(coalesce(z,''))=='text' ) + ); + CREATE TABLE t2n( + x INTEGER CONSTRAINT one CHECK( typeof(coalesce(x,0))=="integer" ), + y NUMERIC CONSTRAINT two CHECK( typeof(coalesce(y,0.1))=='real' ), + z TEXT CONSTRAINT three CHECK( typeof(coalesce(z,''))=='text' ) + ); + PRAGMA writable_schema = 0; + } +} {} +do_test check-2.2 { + execsql { + INSERT INTO t2 VALUES(1,2.2,'three'); + SELECT * FROM t2; + } +} {1 2.2 three} +db close +sqlite3 db test.db +sqlite3_db_config db SQLITE_DBCONFIG_DQS_DDL 1 +sqlite3_db_config db SQLITE_DBCONFIG_DQS_DML 1 +do_test check-2.3 { + execsql { + INSERT INTO t2 VALUES(NULL, NULL, NULL); + SELECT * FROM t2; + } +} {1 2.2 three {} {} {}} +do_test check-2.4 { + catchsql { + INSERT INTO t2 VALUES(1.1, NULL, NULL); + } +} {1 {CHECK constraint failed: one}} +do_test check-2.5 { + # The 5 gets automatically promoted to 5.0 because the column type is REAL + catchsql { + INSERT INTO t2 VALUES(NULL, 5, NULL); + } +} {0 {}} +do_test check-2.5b { + # This time the column type is NUMERIC, so not automatic promption to REAL + # occurs and the constraint fails. + catchsql { + INSERT INTO t2n VALUES(NULL, 5, NULL); + } +} {1 {CHECK constraint failed: two}} +do_test check-2.6 { + catchsql { + INSERT INTO t2 VALUES(NULL, NULL, 3.14159); + } +} {0 {}} + +# Undocumented behavior: The CONSTRAINT name clause can follow a constraint. +# Such a clause is ignored. But the parser must accept it for backwards +# compatibility. +# +do_test check-2.10 { + execsql { + CREATE TABLE t2b( + x INTEGER CHECK( typeof(coalesce(x,0))=='integer' ) CONSTRAINT one, + y TEXT PRIMARY KEY constraint two, + z INTEGER, + UNIQUE(x,z) constraint three + ); + } +} {} +do_test check-2.11 { + catchsql { + INSERT INTO t2b VALUES('xyzzy','hi',5); + } +} {1 {CHECK constraint failed: typeof(coalesce(x,0))=='integer'}} +do_test check-2.12 { + execsql { + CREATE TABLE t2c( + x INTEGER CONSTRAINT x_one CONSTRAINT x_two + CHECK( typeof(coalesce(x,0))=='integer' ) + CONSTRAINT x_two CONSTRAINT x_three, + y INTEGER, z INTEGER, + CONSTRAINT u_one UNIQUE(x,y,z) CONSTRAINT u_two + ); + } +} {} +do_test check-2.13 { + catchsql { + INSERT INTO t2c VALUES('xyzzy',7,8); + } +} {1 {CHECK constraint failed: x_two}} +do_test check-2.cleanup { + execsql { + DROP TABLE IF EXISTS t2b; + DROP TABLE IF EXISTS t2c; + DROP TABLE IF EXISTS t2n; + } +} {} + +ifcapable subquery { + do_test check-3.1 { + catchsql { + CREATE TABLE t3( + x, y, z, + CHECK( x<(SELECT min(x) FROM t1) ) + ); + } + } {1 {subqueries prohibited in CHECK constraints}} +} + +do_test check-3.2 { + execsql { + SELECT name FROM sqlite_master ORDER BY name + } +} {t1 t2} +do_test check-3.3 { + catchsql { + CREATE TABLE t3( + x, y, z, + CHECK( q0 )); + CREATE TABLE t811(b, CHECK( xyzzy.t811.b BETWEEN 5 AND 10 )); +} {} + +# Make sure check constraints involving the ROWID are not ignored +# +do_execsql_test 9.1 { + CREATE TABLE t1( + a INTEGER PRIMARY KEY, + b INTEGER NOT NULL CONSTRAINT 'b-check' CHECK( b>a ), + c INTEGER NOT NULL CONSTRAINT 'c-check' CHECK( c>rowid*2 ), + d INTEGER NOT NULL CONSTRAINT 'd-check' CHECK( d BETWEEN b AND c ) + ); + INSERT INTO t1(a,b,c,d) VALUES(1,2,4,3),(2,4,6,5),(3,10,30,20); +} {} +do_catchsql_test 9.2 { + UPDATE t1 SET b=0 WHERE a=1; +} {1 {CHECK constraint failed: b-check}} +do_catchsql_test 9.3 { + UPDATE t1 SET c=a*2 WHERE a=1; +} {1 {CHECK constraint failed: c-check}} + +# Integrity check on a VIEW with columns. +# +db close +db2 close +forcedelete test.db +sqlite3 db test.db +do_execsql_test 10.1 { + CREATE TABLE t1(x); + CREATE VIEW v1(y) AS SELECT x FROM t1; + PRAGMA integrity_check; +} {ok} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 11.0 { + CREATE TABLE t1 (Col0 CHECK(1 COLLATE BINARY BETWEEN 1 AND 1) ) ; +} +do_execsql_test 11.1 { + INSERT INTO t1 VALUES (NULL); +} +do_execsql_test 11.2 { + INSERT INTO t1 VALUES (NULL); +} + +do_execsql_test 11.3 { + CREATE TABLE t2(b, a CHECK( + CASE 'abc' COLLATE nocase WHEN a THEN 1 ELSE 0 END) + ); +} +do_execsql_test 11.4 { + INSERT INTO t2(a) VALUES('abc'); +} +do_execsql_test 11.5 { + INSERT INTO t2(b, a) VALUES(1, 'abc'||''); +} +do_execsql_test 11.6 { + INSERT INTO t2(b, a) VALUES(2, 'abc'); +} + +# 2019-12-24 ticket b383b90278186263 +# +reset_db +do_execsql_test 12.10 { + CREATE TABLE t1(a TEXT, CHECK(a=+a)); + INSERT INTO t1(a) VALUES(NULL),('xyz'),(5),(x'303132'),(4.75); + SELECT quote(a) FROM t1 ORDER BY rowid; +} {NULL 'xyz' '5' X'303132' '4.75'} +do_execsql_test 12.20 { + DROP TABLE t1; + CREATE TABLE t1(a TEXT, CHECK(a<>+a)); + INSERT INTO t1(a) VALUES(NULL); +} {} +do_catchsql_test 12.21 { + INSERT INTO t1(a) VALUES('xyz'); +} {1 {CHECK constraint failed: a<>+a}} +do_catchsql_test 12.22 { + INSERT INTO t1(a) VALUES(123); +} {1 {CHECK constraint failed: a<>+a}} +do_execsql_test 12.30 { + DROP TABLE t1; + CREATE TABLE t1(a TEXT, CHECK(NOT(a=+a))); + INSERT INTO t1(a) VALUES(NULL); +} {} +do_catchsql_test 12.31 { + INSERT INTO t1(a) VALUES('xyz'); +} {1 {CHECK constraint failed: NOT(a=+a)}} +do_catchsql_test 12.32 { + INSERT INTO t1(a) VALUES(123); +} {1 {CHECK constraint failed: NOT(a=+a)}} +do_execsql_test 12.40 { + DROP TABLE t1; + CREATE TABLE t1(a TEXT, CHECK(NOT(a<>+a))); + INSERT INTO t1(a) VALUES(NULL),('xyz'),(5),(x'303132'),(4.75); + SELECT quote(a) FROM t1 ORDER BY rowid; +} {NULL 'xyz' '5' X'303132' '4.75'} +do_execsql_test 12.50 { + DROP TABLE t1; + CREATE TABLE t1(a TEXT, CHECK(a BETWEEN 0 AND +a)); + INSERT INTO t1(a) VALUES(NULL),('xyz'),(5),(x'303132'),(4.75); + SELECT quote(a) FROM t1 ORDER BY rowid; +} {NULL 'xyz' '5' X'303132' '4.75'} +do_execsql_test 12.60 { + DROP TABLE t1; + CREATE TABLE t1(a TEXT, CHECK(a NOT BETWEEN 0 AND +a)); + INSERT INTO t1(a) VALUES(NULL); + SELECT quote(a) FROM t1 ORDER BY rowid; +} {NULL} +do_catchsql_test 12.61 { + INSERT INTO t1(a) VALUES(456); +} {1 {CHECK constraint failed: a NOT BETWEEN 0 AND +a}} +do_execsql_test 12.70 { + DROP TABLE t1; + CREATE TABLE t1(a TEXT, CHECK(a BETWEEN +a AND 999999)); + INSERT INTO t1(a) VALUES(NULL),(5); + SELECT quote(a) FROM t1 ORDER BY rowid; +} {NULL '5'} +do_execsql_test 12.80 { + DROP TABLE t1; + CREATE TABLE t1(a TEXT, CHECK(a NOT BETWEEN +a AND 999999)); + INSERT INTO t1(a) VALUES(NULL); + SELECT quote(a) FROM t1 ORDER BY rowid; +} {NULL} +do_catchsql_test 12.81 { + INSERT INTO t1(a) VALUES(456); +} {1 {CHECK constraint failed: a NOT BETWEEN +a AND 999999}} + +finish_test diff --git a/test/checkfault.test b/test/checkfault.test new file mode 100644 index 0000000..3b18a64 --- /dev/null +++ b/test/checkfault.test @@ -0,0 +1,41 @@ +# 2019 July 17 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file contains fault-injection test cases for the +# sqlite3_db_cacheflush API. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix cffault +source $testdir/malloc_common.tcl + +do_execsql_test 1.0 { + CREATE TABLE t1 (Col0 CHECK(1 COLLATE BINARY BETWEEN 1 AND 1) ) ; + CREATE TABLE t2(b, a CHECK( + CASE 'abc' COLLATE nocase WHEN a THEN 1 ELSE 0 END) + ); +} + +do_faultsim_test 1.1 -faults oom* -body { + execsql { INSERT INTO t1 VALUES ('ABCDEFG') } +} -test { + faultsim_test_result {0 {}} +} + +do_faultsim_test 1.2 -faults oom* -body { + execsql { INSERT INTO t2(a) VALUES('abc') } +} -test { + faultsim_test_result {0 {}} +} + + +finish_test diff --git a/test/chunksize.test b/test/chunksize.test new file mode 100644 index 0000000..47d118d --- /dev/null +++ b/test/chunksize.test @@ -0,0 +1,41 @@ +# 2019 June 5 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix chunksize + +if {$::tcl_platform(platform)!="unix"} { + finish_test + return +} + +foreach {tn jrnlmode} { + 1 delete + 2 wal +} { + reset_db + file_control_chunksize_test db main 32768 + do_execsql_test $tn.0 " PRAGMA journal_mode = $jrnlmode " $jrnlmode + do_execsql_test $tn.1 { + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 2); + } + + execsql { PRAGMA wal_checkpoint } + + do_test $tn.2 { + file size test.db + } 32768 +} + +finish_test diff --git a/test/close.test b/test/close.test new file mode 100644 index 0000000..107c7a7 --- /dev/null +++ b/test/close.test @@ -0,0 +1,89 @@ +# 2013 May 14 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Test some specific circumstances to do with shared cache mode. +# + + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix close + +# This module bypasses the "-key" logic in tester.tcl, so it cannot run +# with the codec enabled. +do_not_use_codec + +do_execsql_test 1.0 { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES('one'); + INSERT INTO t1 VALUES('two'); + INSERT INTO t1 VALUES('three'); +} +db close + +do_test 1.1 { + set DB [sqlite3_open test.db] + sqlite3_close_v2 $DB +} {SQLITE_OK} + +do_test 1.2.1 { + set DB [sqlite3_open test.db] + set STMT [sqlite3_prepare $DB "SELECT * FROM t1" -1 dummy] + sqlite3_close_v2 $DB +} {SQLITE_OK} +do_test 1.2.2 { + sqlite3_finalize $STMT +} {SQLITE_OK} + +do_test 1.3.1 { + set DB [sqlite3_open test.db] + set STMT [sqlite3_prepare $DB "SELECT * FROM t1" -1 dummy] + sqlite3_step $STMT + sqlite3_close_v2 $DB +} {SQLITE_OK} + +do_test 1.3.2 { + sqlite3_column_text $STMT 0 +} {one} + +do_test 1.3.3 { + sqlite3_finalize $STMT +} {SQLITE_OK} + +do_test 1.4.1 { + set DB [sqlite3_open test.db] + set STMT [sqlite3_prepare $DB "SELECT * FROM t1" -1 dummy] + sqlite3_step $STMT + sqlite3_close_v2 $DB +} {SQLITE_OK} + +do_test 1.4.2 { + list [sqlite3_step $STMT] [sqlite3_column_text $STMT 0] +} {SQLITE_ROW two} + +do_test 1.4.3 { + list [catch { + sqlite3_prepare $DB "SELECT * FROM sqlite_master" -1 dummy + } msg] $msg +} {1 {(21) bad parameter or other API misuse}} + +do_test 1.4.4 { + sqlite3_finalize $STMT +} {SQLITE_OK} + +do_test 1.5 { + set DB [sqlite3_open test.db] + sqlite3_blob_open $DB main t1 x 2 0 BLOB + sqlite3_close_v2 $DB + sqlite3_blob_close $BLOB +} {} + +finish_test diff --git a/test/closure01.test b/test/closure01.test new file mode 100644 index 0000000..ee3f2dd --- /dev/null +++ b/test/closure01.test @@ -0,0 +1,295 @@ +# 2013-04-25 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Test cases for transitive_closure virtual table. + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix closure01 + +ifcapable !vtab||!cte { finish_test ; return } + +load_static_extension db closure + +do_execsql_test 1.0 { + BEGIN; + CREATE TABLE t1(x INTEGER PRIMARY KEY, y INTEGER); + WITH RECURSIVE + cnt(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM cnt LIMIT 131072) + INSERT INTO t1(x, y) SELECT i, nullif(i,1)/2 FROM cnt; + CREATE INDEX t1y ON t1(y); + COMMIT; + CREATE VIRTUAL TABLE cx + USING transitive_closure(tablename=t1, idcolumn=x, parentcolumn=y); +} {} + +# The entire table +do_timed_execsql_test 1.1 { + SELECT count(*), depth FROM cx WHERE root=1 GROUP BY depth ORDER BY 1; +} {/1 0 1 17 2 1 4 2 8 3 16 4 .* 65536 16/} +do_timed_execsql_test 1.1-cte { + WITH RECURSIVE + below(id,depth) AS ( + VALUES(1,0) + UNION ALL + SELECT t1.x, below.depth+1 + FROM t1 JOIN below on t1.y=below.id + ) + SELECT count(*), depth FROM below GROUP BY depth ORDER BY 1; +} {/1 0 1 17 2 1 4 2 8 3 16 4 .* 65536 16/} + +# descendents of 32768 +do_timed_execsql_test 1.2 { + SELECT * FROM cx WHERE root=32768 ORDER BY id; +} {32768 0 65536 1 65537 1 131072 2} +do_timed_execsql_test 1.2-cte { + WITH RECURSIVE + below(id,depth) AS ( + VALUES(32768,0) + UNION ALL + SELECT t1.x, below.depth+1 + FROM t1 JOIN below on t1.y=below.id + WHERE below.depth<2 + ) + SELECT id, depth FROM below ORDER BY id; +} {32768 0 65536 1 65537 1 131072 2} + +# descendents of 16384 +do_timed_execsql_test 1.3 { + SELECT * FROM cx WHERE root=16384 AND depth<=2 ORDER BY id; +} {16384 0 32768 1 32769 1 65536 2 65537 2 65538 2 65539 2} +do_timed_execsql_test 1.3-cte { + WITH RECURSIVE + below(id,depth) AS ( + VALUES(16384,0) + UNION ALL + SELECT t1.x, below.depth+1 + FROM t1 JOIN below on t1.y=below.id + WHERE below.depth<2 + ) + SELECT id, depth FROM below ORDER BY id; +} {16384 0 32768 1 32769 1 65536 2 65537 2 65538 2 65539 2} + +# children of 16384 +do_execsql_test 1.4 { + SELECT id, depth, root, tablename, idcolumn, parentcolumn FROM cx + WHERE root=16384 + AND depth=1 + ORDER BY id; +} {32768 1 {} t1 x y 32769 1 {} t1 x y} + +# great-grandparent of 16384 +do_timed_execsql_test 1.5 { + SELECT id, depth, root, tablename, idcolumn, parentcolumn FROM cx + WHERE root=16384 + AND depth=3 + AND idcolumn='Y' + AND parentcolumn='X'; +} {2048 3 {} t1 Y X} +do_timed_execsql_test 1.5-cte { + WITH RECURSIVE + above(id,depth) AS ( + VALUES(16384,0) + UNION ALL + SELECT t1.y, above.depth+1 + FROM t1 JOIN above ON t1.x=above.id + WHERE above.depth<3 + ) + SELECT id FROM above WHERE depth=3; +} {2048} + +# depth<5 +do_timed_execsql_test 1.6 { + SELECT count(*), depth FROM cx WHERE root=1 AND depth<5 + GROUP BY depth ORDER BY 1; +} {1 0 2 1 4 2 8 3 16 4} +do_timed_execsql_test 1.6-cte { + WITH RECURSIVE + below(id,depth) AS ( + VALUES(1,0) + UNION ALL + SELECT t1.x, below.depth+1 + FROM t1 JOIN below ON t1.y=below.id + WHERE below.depth<4 + ) + SELECT count(*), depth FROM below GROUP BY depth ORDER BY 1; +} {1 0 2 1 4 2 8 3 16 4} + +# depth<=5 +do_execsql_test 1.7 { + SELECT count(*), depth FROM cx WHERE root=1 AND depth<=5 + GROUP BY depth ORDER BY 1; +} {1 0 2 1 4 2 8 3 16 4 32 5} + +# depth==5 +do_execsql_test 1.8 { + SELECT count(*), depth FROM cx WHERE root=1 AND depth=5 + GROUP BY depth ORDER BY 1; +} {32 5} + +# depth BETWEEN 3 AND 5 +do_execsql_test 1.9 { + SELECT count(*), depth FROM cx WHERE root=1 AND depth BETWEEN 3 AND 5 + GROUP BY depth ORDER BY 1; +} {8 3 16 4 32 5} + +# depth==5 with min() and max() +do_timed_execsql_test 1.10 { + SELECT count(*), min(id), max(id) FROM cx WHERE root=1 AND depth=5; +} {32 32 63} +do_timed_execsql_test 1.10-cte { + WITH RECURSIVE + below(id,depth) AS ( + VALUES(1,0) + UNION ALL + SELECT t1.x, below.depth+1 + FROM t1 JOIN below ON t1.y=below.id + WHERE below.depth<5 + ) + SELECT count(*), min(id), max(id) FROM below WHERE depth=5; +} {32 32 63} + +# Create a much smaller table t2 with only 32 elements +db eval { + CREATE TABLE t2(x INTEGER PRIMARY KEY, y INTEGER); + INSERT INTO t2 SELECT x, y FROM t1 WHERE x<32; + CREATE INDEX t2y ON t2(y); + CREATE VIRTUAL TABLE c2 + USING transitive_closure(tablename=t2, idcolumn=x, parentcolumn=y); +} + +# t2 full-table +do_execsql_test 2.1 { + SELECT count(*), min(id), max(id) FROM c2 WHERE root=1; +} {31 1 31} +# t2 root=10 +do_execsql_test 2.2 { + SELECT id FROM c2 WHERE root=10; +} {10 20 21} +# t2 root=11 +do_execsql_test 2.3 { + SELECT id FROM c2 WHERE root=12; +} {12 24 25} +# t2 root IN [10,12] +do_execsql_test 2.4 { + SELECT id FROM c2 WHERE root IN (10,12) ORDER BY id; +} {10 12 20 21 24 25} +# t2 root IN [10,12] (sorted) +do_execsql_test 2.5 { + SELECT id FROM c2 WHERE root IN (10,12) ORDER BY +id; +} {10 12 20 21 24 25} + +# t2 c2up from 20 +do_execsql_test 3.0 { + CREATE VIRTUAL TABLE c2up USING transitive_closure( + tablename = t2, + idcolumn = y, + parentcolumn = x + ); + SELECT id FROM c2up WHERE root=20; +} {1 2 5 10 20} + +# cx as c2up +do_execsql_test 3.1 { + SELECT id FROM cx + WHERE root=20 + AND tablename='t2' + AND idcolumn='y' + AND parentcolumn='x'; +} {1 2 5 10 20} + +# t2 first cousins of 20 +do_execsql_test 3.2 { + SELECT DISTINCT id FROM c2 + WHERE root IN (SELECT id FROM c2up + WHERE root=20 AND depth<=2) + ORDER BY id; +} {5 10 11 20 21 22 23} + +# t2 first cousins of 20 +do_execsql_test 3.3 { + SELECT id FROM c2 + WHERE root=(SELECT id FROM c2up + WHERE root=20 AND depth=2) + AND depth=2 + EXCEPT + SELECT id FROM c2 + WHERE root=(SELECT id FROM c2up + WHERE root=20 AND depth=1) + AND depth<=1 + ORDER BY id; +} {22 23} + +# missing tablename. +do_test 4.1 { + catchsql { + SELECT id FROM cx + WHERE root=20 + AND tablename='t3' + AND idcolumn='y' + AND parentcolumn='x'; + } +} {1 {no such table: t3}} + +# missing idcolumn +do_test 4.2 { + catchsql { + SELECT id FROM cx + WHERE root=20 + AND tablename='t2' + AND idcolumn='xyz' + AND parentcolumn='x'; + } +} {1 {no such column: t2.xyz}} + +# missing parentcolumn +do_test 4.3 { + catchsql { + SELECT id FROM cx + WHERE root=20 + AND tablename='t2' + AND idcolumn='x' + AND parentcolumn='pqr'; + } +} {1 {no such column: t2.pqr}} + +# generic closure +do_execsql_test 5.1 { + CREATE VIRTUAL TABLE temp.closure USING transitive_closure; + SELECT id FROM closure + WHERE root=1 + AND depth=3 + AND tablename='t1' + AND idcolumn='x' + AND parentcolumn='y' + ORDER BY id; +} {8 9 10 11 12 13 14 15} + +#------------------------------------------------------------------------- +# At one point the following join query was causing a malfunction in +# xBestIndex. +# +do_execsql_test 6.0 { + CREATE TABLE t4 ( + id INTEGER PRIMARY KEY, + name TEXT NOT NULL, + parent_id INTEGER + ); + CREATE VIRTUAL TABLE vt4 USING transitive_closure ( + idcolumn=id, parentcolumn=parent_id, tablename=t4 + ); +} + +do_execsql_test 6.1 { + SELECT * FROM t4, vt4 WHERE t4.id = vt4.root AND vt4.id=4 AND vt4.depth=2; +} + +finish_test diff --git a/test/coalesce.test b/test/coalesce.test new file mode 100644 index 0000000..af4ea8d --- /dev/null +++ b/test/coalesce.test @@ -0,0 +1,84 @@ +# 2009 November 10 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# Additional test cases for the COALESCE() and IFNULL() functions. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + + +do_test coalesce-1.0 { + db eval { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, d); + INSERT INTO t1 VALUES(1, null, null, null); + INSERT INTO t1 VALUES(2, 2, 99, 99); + INSERT INTO t1 VALUES(3, null, 3, 99); + INSERT INTO t1 VALUES(4, null, null, 4); + INSERT INTO t1 VALUES(5, null, null, null); + INSERT INTO t1 VALUES(6, 22, 99, 99); + INSERT INTO t1 VALUES(7, null, 33, 99); + INSERT INTO t1 VALUES(8, null, null, 44); + + SELECT coalesce(b,c,d) FROM t1 ORDER BY a; + } +} {{} 2 3 4 {} 22 33 44} +do_test coalesce-1.1 { + db eval { + SELECT coalesce(d+c+b,d+c,d) FROM t1 ORDER BY a; + } +} {{} 200 102 4 {} 220 132 44} +do_test coalesce-1.2 { + db eval { + SELECT ifnull(d+c+b,ifnull(d+c,d)) FROM t1 ORDER BY a; + } +} {{} 200 102 4 {} 220 132 44} +do_test coalesce-1.3 { + db eval { + SELECT ifnull(ifnull(d+c+b,d+c),d) FROM t1 ORDER BY a; + } +} {{} 200 102 4 {} 220 132 44} +do_test coalesce-1.4 { + db eval { + SELECT ifnull(ifnull(b,c),d) FROM t1 ORDER BY a; + } +} {{} 2 3 4 {} 22 33 44} +do_test coalesce-1.5 { + db eval { + SELECT ifnull(b,ifnull(c,d)) FROM t1 ORDER BY a; + } +} {{} 2 3 4 {} 22 33 44} +do_test coalesce-1.6 { + db eval { + SELECT coalesce(b,NOT b,-b,abs(b),lower(b),length(b),min(b,5),b*123,c) + FROM t1 ORDER BY a; + } +} {{} 2 3 {} {} 22 33 {}} +do_test coalesce-1.7 { + db eval { + SELECT ifnull(nullif(a,4),99) + FROM t1 ORDER BY a; + } +} {1 2 3 99 5 6 7 8} +do_test coalesce-1.8 { + db eval { +pragma vdbe_listing=on; + SELECT coalesce( + CASE WHEN b=2 THEN 123 END, + CASE WHEN b=3 THEN 234 END, + CASE WHEN c=3 THEN 345 WHEN c=33 THEN 456 END, + d + ) + FROM t1 ORDER BY a; + } +} {{} 123 345 4 {} 99 456 44} + + +finish_test diff --git a/test/collate1.test b/test/collate1.test new file mode 100644 index 0000000..b65b850 --- /dev/null +++ b/test/collate1.test @@ -0,0 +1,452 @@ +# +# 2001 September 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script is testing collation sequences. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix collate1 + +# +# Tests are roughly organised as follows: +# +# collate1-1.* - Single-field ORDER BY with an explicit COLLATE clause. +# collate1-2.* - Multi-field ORDER BY with an explicit COLLATE clause. +# collate1-3.* - ORDER BY using a default collation type. Also that an +# explict collate type overrides a default collate type. +# collate1-4.* - ORDER BY using a data type. +# + +# +# Collation type 'HEX'. If an argument can be interpreted as a hexadecimal +# number, then it is converted to one before the comparison is performed. +# Numbers are less than other strings. If neither argument is a number, +# [string compare] is used. +# +db collate HEX hex_collate +proc hex_collate {lhs rhs} { + set lhs_ishex [regexp {^(0x|)[1234567890abcdefABCDEF]+$} $lhs] + set rhs_ishex [regexp {^(0x|)[1234567890abcdefABCDEF]+$} $rhs] + if {$lhs_ishex && $rhs_ishex} { + set lhsx [scan $lhs %x] + set rhsx [scan $rhs %x] + if {$lhs < $rhs} {return -1} + if {$lhs == $rhs} {return 0} + if {$lhs > $rhs} {return 1} + } + if {$lhs_ishex} { + return -1; + } + if {$rhs_ishex} { + return 1; + } + return [string compare $lhs $rhs] +} +db function hex {format 0x%X} + +# Mimic the SQLite 2 collation type NUMERIC. +db collate numeric numeric_collate +proc numeric_collate {lhs rhs} { + if {$lhs == $rhs} {return 0} + return [expr ($lhs>$rhs)?1:-1] +} + +do_test collate1-1.0 { + execsql { + CREATE TABLE collate1t1(c1, c2); + INSERT INTO collate1t1 VALUES(45, hex(45)); + INSERT INTO collate1t1 VALUES(NULL, NULL); + INSERT INTO collate1t1 VALUES(281, hex(281)); + } +} {} +do_test collate1-1.1 { + execsql { + SELECT c2 FROM collate1t1 ORDER BY 1; + } +} {{} 0x119 0x2D} +do_test collate1-1.2 { + execsql { + SELECT c2 FROM collate1t1 ORDER BY 1 COLLATE hex; + } +} {{} 0x2D 0x119} +do_test collate1-1.3 { + execsql { + SELECT c2 FROM collate1t1 ORDER BY 1 COLLATE hex DESC; + } +} {0x119 0x2D {}} +do_test collate1-1.4 { + execsql { + SELECT c2 FROM collate1t1 ORDER BY 1 COLLATE hex ASC; + } +} {{} 0x2D 0x119} +do_test collate1-1.5 { + execsql { + SELECT c2 COLLATE hex FROM collate1t1 ORDER BY 1 + } +} {{} 0x2D 0x119} +do_test collate1-1.6 { + execsql { + SELECT c2 COLLATE hex FROM collate1t1 ORDER BY 1 ASC + } +} {{} 0x2D 0x119} +do_test collate1-1.7 { + execsql { + SELECT c2 COLLATE hex FROM collate1t1 ORDER BY 1 DESC + } +} {0x119 0x2D {}} +do_test collate1-1.99 { + execsql { + DROP TABLE collate1t1; + } +} {} + +do_test collate1-2.0 { + execsql { + CREATE TABLE collate1t1(c1, c2); + INSERT INTO collate1t1 VALUES('5', '0x11'); + INSERT INTO collate1t1 VALUES('5', '0xA'); + INSERT INTO collate1t1 VALUES(NULL, NULL); + INSERT INTO collate1t1 VALUES('7', '0xA'); + INSERT INTO collate1t1 VALUES('11', '0x11'); + INSERT INTO collate1t1 VALUES('11', '0x101'); + } +} {} +do_test collate1-2.2 { + execsql { + SELECT c1, c2 FROM collate1t1 ORDER BY 1 COLLATE numeric, 2 COLLATE hex; + } +} {{} {} 5 0xA 5 0x11 7 0xA 11 0x11 11 0x101} +do_test collate1-2.3 { + execsql { + SELECT c1, c2 FROM collate1t1 ORDER BY 1 COLLATE binary, 2 COLLATE hex; + } +} {{} {} 11 0x11 11 0x101 5 0xA 5 0x11 7 0xA} +do_test collate1-2.4 { + execsql { + SELECT c1, c2 FROM collate1t1 ORDER BY 1 COLLATE binary DESC, 2 COLLATE hex; + } +} {7 0xA 5 0xA 5 0x11 11 0x11 11 0x101 {} {}} +do_test collate1-2.5 { + execsql { + SELECT c1, c2 FROM collate1t1 + ORDER BY 1 COLLATE binary DESC, 2 COLLATE hex DESC; + } +} {7 0xA 5 0x11 5 0xA 11 0x101 11 0x11 {} {}} +do_test collate1-2.6 { + execsql { + SELECT c1, c2 FROM collate1t1 + ORDER BY 1 COLLATE binary ASC, 2 COLLATE hex ASC; + } +} {{} {} 11 0x11 11 0x101 5 0xA 5 0x11 7 0xA} +do_test collate1-2.12.1 { + execsql { + SELECT c1 COLLATE numeric, c2 FROM collate1t1 + ORDER BY 1, 2 COLLATE hex; + } +} {{} {} 5 0xA 5 0x11 7 0xA 11 0x11 11 0x101} +do_test collate1-2.12.2 { + execsql { + SELECT c1 COLLATE hex, c2 FROM collate1t1 + ORDER BY 1 COLLATE numeric, 2 COLLATE hex; + } +} {{} {} 5 0xA 5 0x11 7 0xA 11 0x11 11 0x101} +do_test collate1-2.12.3 { + execsql { + SELECT c1, c2 COLLATE hex FROM collate1t1 + ORDER BY 1 COLLATE numeric, 2; + } +} {{} {} 5 0xA 5 0x11 7 0xA 11 0x11 11 0x101} +do_test collate1-2.12.4 { + execsql { + SELECT c1 COLLATE numeric, c2 COLLATE hex + FROM collate1t1 + ORDER BY 1, 2; + } +} {{} {} 5 0xA 5 0x11 7 0xA 11 0x11 11 0x101} +do_test collate1-2.13 { + execsql { + SELECT c1 COLLATE binary, c2 COLLATE hex + FROM collate1t1 + ORDER BY 1, 2; + } +} {{} {} 11 0x11 11 0x101 5 0xA 5 0x11 7 0xA} +do_test collate1-2.14 { + execsql { + SELECT c1, c2 + FROM collate1t1 ORDER BY 1 COLLATE binary DESC, 2 COLLATE hex; + } +} {7 0xA 5 0xA 5 0x11 11 0x11 11 0x101 {} {}} +do_test collate1-2.15 { + execsql { + SELECT c1 COLLATE binary, c2 COLLATE hex + FROM collate1t1 + ORDER BY 1 DESC, 2 DESC; + } +} {7 0xA 5 0x11 5 0xA 11 0x101 11 0x11 {} {}} +do_test collate1-2.16 { + execsql { + SELECT c1 COLLATE hex, c2 COLLATE binary + FROM collate1t1 + ORDER BY 1 COLLATE binary ASC, 2 COLLATE hex ASC; + } +} {{} {} 11 0x11 11 0x101 5 0xA 5 0x11 7 0xA} +do_test collate1-2.99 { + execsql { + DROP TABLE collate1t1; + } +} {} + +# +# These tests ensure that the default collation type for a column is used +# by an ORDER BY clause correctly. The focus is all the different ways +# the column can be referenced. i.e. a, collate2t1.a, main.collate2t1.a etc. +# +do_test collate1-3.0 { + execsql { + CREATE TABLE collate1t1(a COLLATE hex, b); + INSERT INTO collate1t1 VALUES( '0x5', 5 ); + INSERT INTO collate1t1 VALUES( '1', 1 ); + INSERT INTO collate1t1 VALUES( '0x45', 69 ); + INSERT INTO collate1t1 VALUES( NULL, NULL ); + SELECT * FROM collate1t1 ORDER BY a; + } +} {{} {} 1 1 0x5 5 0x45 69} + +do_test collate1-3.1 { + execsql { + SELECT * FROM collate1t1 ORDER BY 1; + } +} {{} {} 1 1 0x5 5 0x45 69} +do_test collate1-3.2 { + execsql { + SELECT * FROM collate1t1 ORDER BY collate1t1.a; + } +} {{} {} 1 1 0x5 5 0x45 69} +do_test collate1-3.3 { + execsql { + SELECT * FROM collate1t1 ORDER BY main.collate1t1.a; + } +} {{} {} 1 1 0x5 5 0x45 69} +do_test collate1-3.4 { + execsql { + SELECT a as c1, b as c2 FROM collate1t1 ORDER BY c1; + } +} {{} {} 1 1 0x5 5 0x45 69} +do_test collate1-3.5 { + execsql { + SELECT a as c1, b as c2 FROM collate1t1 ORDER BY c1 COLLATE binary; + } +} {{} {} 0x45 69 0x5 5 1 1} +do_test collate1-3.5.1 { + execsql { + SELECT a COLLATE binary as c1, b as c2 + FROM collate1t1 ORDER BY c1; + } +} {{} {} 0x45 69 0x5 5 1 1} +do_test collate1-3.6 { + execsql { + DROP TABLE collate1t1; + } +} {} + +# Update for SQLite version 3. The collate1-4.* test cases were written +# before manifest types were introduced. The following test cases still +# work, due to the 'affinity' mechanism, but they don't prove anything +# about collation sequences. +# +do_test collate1-4.0 { + execsql { + CREATE TABLE collate1t1(c1 numeric, c2 text); + INSERT INTO collate1t1 VALUES(1, 1); + INSERT INTO collate1t1 VALUES(12, 12); + INSERT INTO collate1t1 VALUES(NULL, NULL); + INSERT INTO collate1t1 VALUES(101, 101); + } +} {} +do_test collate1-4.1 { + execsql { + SELECT c1 FROM collate1t1 ORDER BY 1; + } +} {{} 1 12 101} +do_test collate1-4.2 { + execsql { + SELECT c2 FROM collate1t1 ORDER BY 1; + } +} {{} 1 101 12} +do_test collate1-4.3 { + execsql { + SELECT c2+0 FROM collate1t1 ORDER BY 1; + } +} {{} 1 12 101} +do_test collate1-4.4 { + execsql { + SELECT c1||'' FROM collate1t1 ORDER BY 1; + } +} {{} 1 101 12} +do_test collate1-4.4.1 { + execsql { + SELECT (c1||'') COLLATE numeric FROM collate1t1 ORDER BY 1; + } +} {{} 1 12 101} +do_test collate1-4.5 { + execsql { + DROP TABLE collate1t1; + } +} {} + +# A problem reported on the mailing list: A CREATE TABLE statement +# is allowed to have two or more COLLATE clauses on the same column. +# That probably ought to be an error, but we allow it for backwards +# compatibility. Just make sure it works and doesn't leak memory. +# +do_test collate1-5.1 { + execsql { + CREATE TABLE c5( + id INTEGER PRIMARY KEY, + a TEXT COLLATE binary COLLATE nocase COLLATE rtrim, + b TEXT COLLATE nocase COLLATE binary, + c TEXT COLLATE rtrim COLLATE binary COLLATE rtrim COLLATE nocase + ); + INSERT INTO c5 VALUES(1, 'abc','abc','abc'); + INSERT INTO c5 VALUES(2, 'abc ','ABC','ABC'); + SELECT id FROM c5 WHERE a='abc' ORDER BY id; + } +} {1 2} +do_test collate1-5.2 { + execsql { + SELECT id FROM c5 WHERE b='abc' ORDER BY id; + } +} {1} +do_test collate1-5.3 { + execsql { + SELECT id FROM c5 WHERE c='abc' ORDER BY id; + } +} {1 2} + + + +#------------------------------------------------------------------------- +# Fix problems with handling collation sequences named '"""'. +# +sqlite3_db_config db SQLITE_DBCONFIG_DQS_DML 1 +do_execsql_test 6.1 { + SELECT """"""""; +} {\"\"\"} + +do_catchsql_test 6.2 { + CREATE TABLE x1(a); + SELECT a FROM x1 ORDER BY a COLLATE """"""""; +} {1 {no such collation sequence: """}} + +do_catchsql_test 6.3 { + SELECT a FROM x1 ORDER BY 1 COLLATE """"""""; +} {1 {no such collation sequence: """}} + +do_catchsql_test 6.4 { + SELECT 0 UNION SELECT 0 ORDER BY 1 COLLATE """"""""; +} {1 {no such collation sequence: """}} + +db collate {"""} [list string compare -nocase] + +do_execsql_test 6.5 { + PRAGMA foreign_keys = ON; + CREATE TABLE p1(a PRIMARY KEY COLLATE '"""'); + CREATE TABLE c1(x, y REFERENCES p1); +} {} + +do_execsql_test 6.6 { + INSERT INTO p1 VALUES('abc'); + INSERT INTO c1 VALUES(1, 'ABC'); +} + +ifcapable foreignkey { + do_catchsql_test 6.7 { + DELETE FROM p1 WHERE rowid = 1 + } {1 {FOREIGN KEY constraint failed}} +} + +do_execsql_test 6.8 { + INSERT INTO p1 VALUES('abb'); + INSERT INTO p1 VALUES('wxz'); + INSERT INTO p1 VALUES('wxy'); + + INSERT INTO c1 VALUES(2, 'abb'); + INSERT INTO c1 VALUES(3, 'wxz'); + INSERT INTO c1 VALUES(4, 'WXY'); + SELECT x, y FROM c1 ORDER BY y COLLATE """"""""; +} {2 abb 1 ABC 4 WXY 3 wxz} + +# 2015-04-15: Nested COLLATE operators +# +do_execsql_test 7.0 { + SELECT 'abc' UNION ALL SELECT 'DEF' + ORDER BY 1 COLLATE nocase COLLATE nocase COLLATE nocase COLLATE nocase; +} {abc DEF} +do_execsql_test 7.1 { + SELECT 'abc' UNION ALL SELECT 'DEF' + ORDER BY 1 COLLATE nocase COLLATE nocase COLLATE nocase COLLATE binary; +} {DEF abc} +do_execsql_test 7.2 { + SELECT 'abc' UNION ALL SELECT 'DEF' + ORDER BY 1 COLLATE binary COLLATE binary COLLATE binary COLLATE nocase; +} {abc DEF} + +# 2019-06-14 +# https://sqlite.org/src/info/f1580ba1b574e9e9 +# +do_execsql_test 8.0 { + SELECT ' ' > char(20) COLLATE rtrim; +} 0 +do_execsql_test 8.1 { + SELECT '' < char(20) COLLATE rtrim; +} 1 +do_execsql_test 8.2 { + DROP TABLE IF EXISTS t0; + CREATE TABLE t0(c0 COLLATE RTRIM, c1 BLOB UNIQUE, + PRIMARY KEY (c0, c1)) WITHOUT ROWID; + INSERT INTO t0 VALUES (123, 3), (' ', 1), (' ', 2), ('', 4); + SELECT * FROM t0 WHERE c1 = 1; +} {{ } 1} + +# 2019-10-09 +# ALWAYS() macro fails following OOM +# Problem detected by dbsqlfuzz. +# +do_execsql_test 9.0 { + CREATE TABLE t1(a, b); + CREATE TABLE t2(c, d); +} + +do_faultsim_test 9.1 -faults oom* -body { + execsql { + SELECT * FROM ( + SELECT b COLLATE nocase IN (SELECT c FROM t2) FROM t1 + ); + } +} -test { + faultsim_test_result {0 {}} +} + +# 2020-01-03 dbsqlfuzz find +# +reset_db +do_catchsql_test 10.0 { + CREATE TABLE t1(a INTEGER PRIMARY KEY,b); + INSERT INTO t1 VALUES(0,NULL); + CREATE TABLE t2(x UNIQUE); + CREATE VIEW v1a(z,y) AS SELECT x COLLATE x FROM t2; + SELECT a,b,z,y,'' FROM t1 JOIN v1a ON b IS NOT FALSE; +} {1 {no such collation sequence: x}} + + +finish_test diff --git a/test/collate2.test b/test/collate2.test new file mode 100644 index 0000000..281aa35 --- /dev/null +++ b/test/collate2.test @@ -0,0 +1,742 @@ +# +# 2001 September 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script is page cache subsystem. +# +# $Id: collate2.test,v 1.6 2008/08/20 16:35:10 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +set ::testprefix collate2 + +# +# Tests are organised as follows: +# +# collate2-1.* WHERE expressions (sqliteExprIfTrue). +# collate2-2.* WHERE NOT expressions (sqliteExprIfFalse). +# collate2-3.* SELECT expressions (sqliteExprCode). +# collate2-4.* Precedence of collation/data types in binary comparisons +# collate2-5.* JOIN syntax. +# + +# Create a collation type BACKWARDS for use in testing. This collation type +# is similar to the built-in TEXT collation type except the order of +# characters in each string is reversed before the comparison is performed. +db collate BACKWARDS backwards_collate +proc backwards_collate {a b} { + set ra {}; + set rb {} + foreach c [split $a {}] { set ra $c$ra } + foreach c [split $b {}] { set rb $c$rb } + return [string compare $ra $rb] +} + +# The following values are used in these tests: +# NULL aa ab ba bb aA aB bA bB Aa Ab Ba Bb AA AB BA BB +# +# The collation orders for each of the tested collation types are: +# +# BINARY: NULL AA AB Aa Ab BA BB Ba Bb aA aB aa ab bA bB ba bb +# NOCASE: NULL aa aA Aa AA ab aB Ab AB ba bA Ba BA bb bB Bb BB +# BACKWARDS: NULL AA BA aA bA AB BB aB bB Aa Ba aa ba Ab Bb ab bb +# +# These tests verify that the default collation type for a column is used +# for comparison operators (<, >, <=, >=, =) involving that column and +# an expression that is not a column with a default collation type. +# +# The collation sequences BINARY and NOCASE are built-in, the BACKWARDS +# collation sequence is implemented by the TCL proc backwards_collate +# above. +# +do_test collate2-1.0 { + execsql { + CREATE TABLE collate2t1( + a COLLATE BINARY, + b COLLATE NOCASE, + c COLLATE BACKWARDS + ); + INSERT INTO collate2t1 VALUES( NULL, NULL, NULL ); + + INSERT INTO collate2t1 VALUES( 'aa', 'aa', 'aa' ); + INSERT INTO collate2t1 VALUES( 'ab', 'ab', 'ab' ); + INSERT INTO collate2t1 VALUES( 'ba', 'ba', 'ba' ); + INSERT INTO collate2t1 VALUES( 'bb', 'bb', 'bb' ); + + INSERT INTO collate2t1 VALUES( 'aA', 'aA', 'aA' ); + INSERT INTO collate2t1 VALUES( 'aB', 'aB', 'aB' ); + INSERT INTO collate2t1 VALUES( 'bA', 'bA', 'bA' ); + INSERT INTO collate2t1 VALUES( 'bB', 'bB', 'bB' ); + + INSERT INTO collate2t1 VALUES( 'Aa', 'Aa', 'Aa' ); + INSERT INTO collate2t1 VALUES( 'Ab', 'Ab', 'Ab' ); + INSERT INTO collate2t1 VALUES( 'Ba', 'Ba', 'Ba' ); + INSERT INTO collate2t1 VALUES( 'Bb', 'Bb', 'Bb' ); + + INSERT INTO collate2t1 VALUES( 'AA', 'AA', 'AA' ); + INSERT INTO collate2t1 VALUES( 'AB', 'AB', 'AB' ); + INSERT INTO collate2t1 VALUES( 'BA', 'BA', 'BA' ); + INSERT INTO collate2t1 VALUES( 'BB', 'BB', 'BB' ); + } + if {[info exists collate_test_use_index]} { + execsql { + CREATE INDEX collate2t1_i1 ON collate2t1(a); + CREATE INDEX collate2t1_i2 ON collate2t1(b); + CREATE INDEX collate2t1_i3 ON collate2t1(c); + } + } +} {} +do_test collate2-1.1 { + execsql { + SELECT a FROM collate2t1 WHERE a > 'aa' ORDER BY 1; + } +} {ab bA bB ba bb} +do_test collate2-1.1.1 { + execsql { + SELECT a FROM collate2t1 WHERE a COLLATE binary > 'aa' ORDER BY 1; + } +} {ab bA bB ba bb} +do_test collate2-1.1.2 { + execsql { + SELECT a FROM collate2t1 WHERE b COLLATE binary > 'aa' ORDER BY 1; + } +} {ab bA bB ba bb} +do_test collate2-1.1.3 { + execsql { + SELECT a FROM collate2t1 WHERE c COLLATE binary > 'aa' ORDER BY 1; + } +} {ab bA bB ba bb} +do_test collate2-1.2 { + execsql { + SELECT b FROM collate2t1 WHERE b > 'aa' ORDER BY 1, oid; + } +} {ab aB Ab AB ba bA Ba BA bb bB Bb BB} +do_test collate2-1.2.1 { + execsql { + SELECT b FROM collate2t1 WHERE a COLLATE nocase > 'aa' + ORDER BY 1, oid; + } +} {ab aB Ab AB ba bA Ba BA bb bB Bb BB} +do_test collate2-1.2.2 { + execsql { + SELECT b FROM collate2t1 WHERE b COLLATE nocase > 'aa' + ORDER BY 1, oid; + } +} {ab aB Ab AB ba bA Ba BA bb bB Bb BB} +do_test collate2-1.2.3 { + execsql { + SELECT b FROM collate2t1 WHERE c COLLATE nocase > 'aa' + ORDER BY 1, oid; + } +} {ab aB Ab AB ba bA Ba BA bb bB Bb BB} +do_test collate2-1.2.4 { + execsql { + SELECT b FROM collate2t1 WHERE b > 'aa' ORDER BY +b; + } +} {ab aB Ab AB ba bA Ba BA bb bB Bb BB} +do_test collate2-1.2.5 { + execsql { + SELECT b FROM collate2t1 WHERE a COLLATE nocase > 'aa' ORDER BY +b; + } +} {ab aB Ab AB ba bA Ba BA bb bB Bb BB} +do_test collate2-1.2.6 { + execsql { + SELECT b FROM collate2t1 WHERE b COLLATE nocase > 'aa' ORDER BY +b; + } +} {ab aB Ab AB ba bA Ba BA bb bB Bb BB} +do_test collate2-1.2.7 { + execsql { + SELECT b FROM collate2t1 WHERE c COLLATE nocase > 'aa' ORDER BY +b; + } +} {ab aB Ab AB ba bA Ba BA bb bB Bb BB} +do_test collate2-1.3 { + execsql { + SELECT c FROM collate2t1 WHERE c > 'aa' ORDER BY 1; + } +} {ba Ab Bb ab bb} +do_test collate2-1.3.1 { + execsql { + SELECT c FROM collate2t1 WHERE a COLLATE backwards > 'aa' + ORDER BY 1; + } +} {ba Ab Bb ab bb} +do_test collate2-1.3.2 { + execsql { + SELECT c FROM collate2t1 WHERE b COLLATE backwards > 'aa' + ORDER BY 1; + } +} {ba Ab Bb ab bb} +do_test collate2-1.3.3 { + execsql { + SELECT c FROM collate2t1 WHERE c COLLATE backwards > 'aa' + ORDER BY 1; + } +} {ba Ab Bb ab bb} +do_test collate2-1.4 { + execsql { + SELECT a FROM collate2t1 WHERE a < 'aa' ORDER BY 1; + } +} {AA AB Aa Ab BA BB Ba Bb aA aB} +do_test collate2-1.5 { + execsql { + SELECT b FROM collate2t1 WHERE b < 'aa' ORDER BY 1, oid; + } +} {} +do_test collate2-1.5.1 { + execsql { + SELECT b FROM collate2t1 WHERE b < 'aa' ORDER BY +b; + } +} {} +do_test collate2-1.6 { + execsql { + SELECT c FROM collate2t1 WHERE c < 'aa' ORDER BY 1; + } +} {AA BA aA bA AB BB aB bB Aa Ba} +do_test collate2-1.7 { + execsql { + SELECT a FROM collate2t1 WHERE a = 'aa'; + } +} {aa} +do_test collate2-1.8 { + execsql { + SELECT b FROM collate2t1 WHERE b = 'aa' ORDER BY oid; + } +} {aa aA Aa AA} +do_test collate2-1.9 { + execsql { + SELECT c FROM collate2t1 WHERE c = 'aa'; + } +} {aa} +do_test collate2-1.10 { + execsql { + SELECT a FROM collate2t1 WHERE a >= 'aa' ORDER BY 1; + } +} {aa ab bA bB ba bb} +do_test collate2-1.11 { + execsql { + SELECT b FROM collate2t1 WHERE b >= 'aa' ORDER BY 1, oid; + } +} {aa aA Aa AA ab aB Ab AB ba bA Ba BA bb bB Bb BB} +do_test collate2-1.12 { + execsql { + SELECT c FROM collate2t1 WHERE c >= 'aa' ORDER BY 1; + } +} {aa ba Ab Bb ab bb} +do_test collate2-1.13 { + execsql { + SELECT a FROM collate2t1 WHERE a <= 'aa' ORDER BY 1; + } +} {AA AB Aa Ab BA BB Ba Bb aA aB aa} +do_test collate2-1.14 { + execsql { + SELECT b FROM collate2t1 WHERE b <= 'aa' ORDER BY 1, oid; + } +} {aa aA Aa AA} +do_test collate2-1.15 { + execsql { + SELECT c FROM collate2t1 WHERE c <= 'aa' ORDER BY 1; + } +} {AA BA aA bA AB BB aB bB Aa Ba aa} +do_test collate2-1.16 { + execsql { + SELECT a FROM collate2t1 WHERE a BETWEEN 'Aa' AND 'Bb' ORDER BY 1; + } +} {Aa Ab BA BB Ba Bb} +do_test collate2-1.17 { + execsql { + SELECT b FROM collate2t1 WHERE b BETWEEN 'Aa' AND 'Bb' ORDER BY 1, oid; + } +} {aa aA Aa AA ab aB Ab AB ba bA Ba BA bb bB Bb BB} +do_test collate2-1.17.1 { + execsql { + SELECT b FROM collate2t1 WHERE b BETWEEN 'Aa' AND 'Bb' ORDER BY +b; + } +} {aa aA Aa AA ab aB Ab AB ba bA Ba BA bb bB Bb BB} +do_test collate2-1.18 { + execsql { + SELECT c FROM collate2t1 WHERE c BETWEEN 'Aa' AND 'Bb' ORDER BY 1; + } +} {Aa Ba aa ba Ab Bb} +do_test collate2-1.19 { + execsql { + SELECT a FROM collate2t1 WHERE + CASE a WHEN 'aa' THEN 1 ELSE 0 END + ORDER BY 1, oid; + } +} {aa} +do_test collate2-1.20 { + execsql { + SELECT b FROM collate2t1 WHERE + CASE b WHEN 'aa' THEN 1 ELSE 0 END + ORDER BY 1, oid; + } +} {aa aA Aa AA} +do_test collate2-1.21 { + execsql { + SELECT c FROM collate2t1 WHERE + CASE c WHEN 'aa' THEN 1 ELSE 0 END + ORDER BY 1, oid; + } +} {aa} + +ifcapable subquery { + do_test collate2-1.22 { + execsql { + SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb') ORDER BY 1, oid; + } + } {aa bb} + do_test collate2-1.23 { + execsql { + SELECT b FROM collate2t1 WHERE b IN ('aa', 'bb') ORDER BY 1, oid; + } + } {aa aA Aa AA bb bB Bb BB} + do_test collate2-1.24 { + execsql { + SELECT c FROM collate2t1 WHERE c IN ('aa', 'bb') ORDER BY 1, oid; + } + } {aa bb} + do_test collate2-1.25 { + execsql { + SELECT a FROM collate2t1 + WHERE a IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb')); + } + } {aa bb} + do_test collate2-1.26 { + execsql { + SELECT b FROM collate2t1 + WHERE b IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb')); + } + } {aa bb aA bB Aa Bb AA BB} + do_test collate2-1.27 { + execsql { + SELECT c FROM collate2t1 + WHERE c IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb')); + } + } {aa bb} +} ;# ifcapable subquery + +do_test collate2-2.1 { + execsql { + SELECT a FROM collate2t1 WHERE NOT a > 'aa' ORDER BY 1; + } +} {AA AB Aa Ab BA BB Ba Bb aA aB aa} +do_test collate2-2.2 { + execsql { + SELECT b FROM collate2t1 WHERE NOT b > 'aa' ORDER BY 1, oid; + } +} {aa aA Aa AA} +do_test collate2-2.3 { + execsql { + SELECT c FROM collate2t1 WHERE NOT c > 'aa' ORDER BY 1; + } +} {AA BA aA bA AB BB aB bB Aa Ba aa} +do_test collate2-2.4 { + execsql { + SELECT a FROM collate2t1 WHERE NOT a < 'aa' ORDER BY 1; + } +} {aa ab bA bB ba bb} +do_test collate2-2.5 { + execsql { + SELECT b FROM collate2t1 WHERE NOT b < 'aa' ORDER BY 1, oid; + } +} {aa aA Aa AA ab aB Ab AB ba bA Ba BA bb bB Bb BB} +do_test collate2-2.6 { + execsql { + SELECT c FROM collate2t1 WHERE NOT c < 'aa' ORDER BY 1; + } +} {aa ba Ab Bb ab bb} +do_test collate2-2.7 { + execsql { + SELECT a FROM collate2t1 WHERE NOT a = 'aa'; + } +} {ab ba bb aA aB bA bB Aa Ab Ba Bb AA AB BA BB} +do_test collate2-2.8 { + execsql { + SELECT b FROM collate2t1 WHERE NOT b = 'aa'; + } +} {ab ba bb aB bA bB Ab Ba Bb AB BA BB} +do_test collate2-2.9 { + execsql { + SELECT c FROM collate2t1 WHERE NOT c = 'aa'; + } +} {ab ba bb aA aB bA bB Aa Ab Ba Bb AA AB BA BB} +do_test collate2-2.10 { + execsql { + SELECT a FROM collate2t1 WHERE NOT a >= 'aa' ORDER BY 1; + } +} {AA AB Aa Ab BA BB Ba Bb aA aB} +do_test collate2-2.11 { + execsql { + SELECT b FROM collate2t1 WHERE NOT b >= 'aa' ORDER BY 1, oid; + } +} {} +do_test collate2-2.12 { + execsql { + SELECT c FROM collate2t1 WHERE NOT c >= 'aa' ORDER BY 1; + } +} {AA BA aA bA AB BB aB bB Aa Ba} +do_test collate2-2.13 { + execsql { + SELECT a FROM collate2t1 WHERE NOT a <= 'aa' ORDER BY 1; + } +} {ab bA bB ba bb} +do_test collate2-2.14 { + execsql { + SELECT b FROM collate2t1 WHERE NOT b <= 'aa' ORDER BY 1, oid; + } +} {ab aB Ab AB ba bA Ba BA bb bB Bb BB} +do_test collate2-2.15 { + execsql { + SELECT c FROM collate2t1 WHERE NOT c <= 'aa' ORDER BY 1; + } +} {ba Ab Bb ab bb} +do_test collate2-2.16 { + execsql { + SELECT a FROM collate2t1 WHERE a NOT BETWEEN 'Aa' AND 'Bb' ORDER BY 1; + } +} {AA AB aA aB aa ab bA bB ba bb} +do_test collate2-2.17 { + execsql { + SELECT b FROM collate2t1 WHERE b NOT BETWEEN 'Aa' AND 'Bb' ORDER BY 1, oid; + } +} {} +do_test collate2-2.18 { + execsql { + SELECT c FROM collate2t1 WHERE c NOT BETWEEN 'Aa' AND 'Bb' ORDER BY 1; + } +} {AA BA aA bA AB BB aB bB ab bb} +do_test collate2-2.19 { + execsql { + SELECT a FROM collate2t1 WHERE NOT CASE a WHEN 'aa' THEN 1 ELSE 0 END; + } +} {{} ab ba bb aA aB bA bB Aa Ab Ba Bb AA AB BA BB} +do_test collate2-2.20 { + execsql { + SELECT b FROM collate2t1 WHERE NOT CASE b WHEN 'aa' THEN 1 ELSE 0 END; + } +} {{} ab ba bb aB bA bB Ab Ba Bb AB BA BB} +do_test collate2-2.21 { + execsql { + SELECT c FROM collate2t1 WHERE NOT CASE c WHEN 'aa' THEN 1 ELSE 0 END; + } +} {{} ab ba bb aA aB bA bB Aa Ab Ba Bb AA AB BA BB} + +ifcapable subquery { + do_test collate2-2.22 { + execsql { + SELECT a FROM collate2t1 WHERE NOT a IN ('aa', 'bb'); + } + } {ab ba aA aB bA bB Aa Ab Ba Bb AA AB BA BB} + do_test collate2-2.23 { + execsql { + SELECT b FROM collate2t1 WHERE NOT b IN ('aa', 'bb'); + } + } {ab ba aB bA Ab Ba AB BA} + do_test collate2-2.24 { + execsql { + SELECT c FROM collate2t1 WHERE NOT c IN ('aa', 'bb'); + } + } {ab ba aA aB bA bB Aa Ab Ba Bb AA AB BA BB} + do_test collate2-2.25 { + execsql { + SELECT a FROM collate2t1 + WHERE NOT a IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb')); + } + } {ab ba aA aB bA bB Aa Ab Ba Bb AA AB BA BB} + do_test collate2-2.26 { + execsql { + SELECT b FROM collate2t1 + WHERE NOT b IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb')); + } + } {ab ba aB bA Ab Ba AB BA} + do_test collate2-2.27 { + execsql { + SELECT c FROM collate2t1 + WHERE NOT c IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb')); + } + } {ab ba aA aB bA bB Aa Ab Ba Bb AA AB BA BB} +} + +do_test collate2-3.1 { + execsql { + SELECT a > 'aa' FROM collate2t1; + } +} {{} 0 1 1 1 0 0 1 1 0 0 0 0 0 0 0 0} +do_test collate2-3.2 { + execsql { + SELECT b > 'aa' FROM collate2t1; + } +} {{} 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1} +do_test collate2-3.3 { + execsql { + SELECT c > 'aa' FROM collate2t1; + } +} {{} 0 1 1 1 0 0 0 0 0 1 0 1 0 0 0 0} +do_test collate2-3.4 { + execsql { + SELECT a < 'aa' FROM collate2t1; + } +} {{} 0 0 0 0 1 1 0 0 1 1 1 1 1 1 1 1} +do_test collate2-3.5 { + execsql { + SELECT b < 'aa' FROM collate2t1; + } +} {{} 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0} +do_test collate2-3.6 { + execsql { + SELECT c < 'aa' FROM collate2t1; + } +} {{} 0 0 0 0 1 1 1 1 1 0 1 0 1 1 1 1} +do_test collate2-3.7 { + execsql { + SELECT a = 'aa' FROM collate2t1; + } +} {{} 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0} +do_test collate2-3.8 { + execsql { + SELECT b = 'aa' FROM collate2t1; + } +} {{} 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0} +do_test collate2-3.9 { + execsql { + SELECT c = 'aa' FROM collate2t1; + } +} {{} 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0} +do_test collate2-3.10 { + execsql { + SELECT a <= 'aa' FROM collate2t1; + } +} {{} 1 0 0 0 1 1 0 0 1 1 1 1 1 1 1 1} +do_test collate2-3.11 { + execsql { + SELECT b <= 'aa' FROM collate2t1; + } +} {{} 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0} +do_test collate2-3.12 { + execsql { + SELECT c <= 'aa' FROM collate2t1; + } +} {{} 1 0 0 0 1 1 1 1 1 0 1 0 1 1 1 1} +do_test collate2-3.13 { + execsql { + SELECT a >= 'aa' FROM collate2t1; + } +} {{} 1 1 1 1 0 0 1 1 0 0 0 0 0 0 0 0} +do_test collate2-3.14 { + execsql { + SELECT b >= 'aa' FROM collate2t1; + } +} {{} 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1} +do_test collate2-3.15 { + execsql { + SELECT c >= 'aa' FROM collate2t1; + } +} {{} 1 1 1 1 0 0 0 0 0 1 0 1 0 0 0 0} +do_test collate2-3.16 { + execsql { + SELECT a BETWEEN 'Aa' AND 'Bb' FROM collate2t1; + } +} {{} 0 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1} +do_test collate2-3.17 { + execsql { + SELECT b BETWEEN 'Aa' AND 'Bb' FROM collate2t1; + } +} {{} 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1} +do_test collate2-3.18 { + execsql { + SELECT c BETWEEN 'Aa' AND 'Bb' FROM collate2t1; + } +} {{} 1 0 1 0 0 0 0 0 1 1 1 1 0 0 0 0} +do_test collate2-3.19 { + execsql { + SELECT CASE a WHEN 'aa' THEN 1 ELSE 0 END FROM collate2t1; + } +} {0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0} +do_test collate2-3.20 { + execsql { + SELECT CASE b WHEN 'aa' THEN 1 ELSE 0 END FROM collate2t1; + } +} {0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0} +do_test collate2-3.21 { + execsql { + SELECT CASE c WHEN 'aa' THEN 1 ELSE 0 END FROM collate2t1; + } +} {0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0} + +ifcapable subquery { + do_test collate2-3.22 { + execsql { + SELECT a IN ('aa', 'bb') FROM collate2t1; + } + } {{} 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0} + do_test collate2-3.23 { + execsql { + SELECT b IN ('aa', 'bb') FROM collate2t1; + } + } {{} 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1} + do_test collate2-3.24 { + execsql { + SELECT c IN ('aa', 'bb') FROM collate2t1; + } + } {{} 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0} + do_test collate2-3.25 { + execsql { + SELECT a IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb')) + FROM collate2t1; + } + } {{} 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0} + do_test collate2-3.26 { + execsql { + SELECT b IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb')) + FROM collate2t1; + } + } {{} 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1} + do_test collate2-3.27 { + execsql { + SELECT c IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb')) + FROM collate2t1; + } + } {{} 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0} +} + +do_test collate2-4.0 { + execsql { + CREATE TABLE collate2t2(b COLLATE binary); + CREATE TABLE collate2t3(b text); + INSERT INTO collate2t2 VALUES('aa'); + INSERT INTO collate2t3 VALUES('aa'); + } +} {} + +# Test that when both sides of a binary comparison operator have +# default collation types, the collate type for the leftmost term +# is used. +do_test collate2-4.1 { + execsql { + SELECT collate2t1.a FROM collate2t1, collate2t2 + WHERE collate2t1.b = collate2t2.b; + } +} {aa aA Aa AA} +do_test collate2-4.2 { + execsql { + SELECT collate2t1.a FROM collate2t1, collate2t2 + WHERE collate2t2.b = collate2t1.b; + } +} {aa} + +# Test that when one side has a default collation type and the other +# does not, the collation type is used. +do_test collate2-4.3 { + execsql { + SELECT collate2t1.a FROM collate2t1, collate2t3 + WHERE collate2t1.b = collate2t3.b||'' + ORDER BY +collate2t1.a DESC; + } +} {aa aA Aa AA} +do_test collate2-4.4 { + execsql { + SELECT collate2t1.a FROM collate2t1, collate2t3 + WHERE collate2t3.b||'' = collate2t1.b + ORDER BY +collate2t1.a DESC; + } +} {aa aA Aa AA} + +do_test collate2-4.5 { + execsql { + DROP TABLE collate2t3; + } +} {} + +# +# Test that the default collation types are used when the JOIN syntax +# is used in place of a WHERE clause. +# +# SQLite transforms the JOIN syntax into a WHERE clause internally, so +# the focus of these tests is to ensure that the table on the left-hand-side +# of the join determines the collation type used. +# +do_test collate2-5.0 { + execsql { + SELECT collate2t1.b FROM collate2t1 JOIN collate2t2 USING (b); + } +} {aa aA Aa AA} +do_test collate2-5.1 { + execsql { + SELECT collate2t1.b FROM collate2t2 JOIN collate2t1 USING (b); + } +} {aa} +do_test collate2-5.2 { + execsql { + SELECT collate2t1.b FROM collate2t1 NATURAL JOIN collate2t2; + } +} {aa aA Aa AA} +do_test collate2-5.3 { + execsql { + SELECT collate2t1.b FROM collate2t2 NATURAL JOIN collate2t1; + } +} {aa} +do_test collate2-5.4.1 { + execsql { + SELECT collate2t2.b FROM collate2t1 LEFT JOIN collate2t2 USING (b) order by collate2t1.oid; + } +} {{} aa {} {} {} aa {} {} {} aa {} {} {} aa {} {} {}} +do_test collate2-5.4.2 { + execsql { + SELECT collate2t2.b FROM collate2t2 RIGHT JOIN collate2t1 ON collate2t1.b=collate2t2.b + ORDER BY collate2t1.oid; + } +} {{} aa {} {} {} aa {} {} {} aa {} {} {} aa {} {} {}} +do_test collate2-5.4.3 { + execsql { + SELECT collate2t2.b FROM collate2t1 LEFT JOIN collate2t2 ON collate2t2.b=collate2t1.b + ORDER BY collate2t1.oid; + } +} {{} aa {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}} +do_test collate2-5.5.1 { + execsql { + SELECT collate2t1.b, collate2t2.b FROM collate2t2 LEFT OUTER JOIN collate2t1 USING (b); + } +} {aa aa} +do_test collate2-5.5.2 { + execsql { + SELECT collate2t1.b, collate2t2.b + FROM collate2t1 RIGHT JOIN collate2t2 ON collate2t2.b=collate2t1.b + } +} {aa aa} + +do_execsql_test 6.1 { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES('b'); + INSERT INTO t1 VALUES('B'); +} +do_execsql_test 6.2 { + SELECT * FROM t1 WHERE x COLLATE nocase BETWEEN 'a' AND 'c'; +} {b B} +do_execsql_test 6.3 { + SELECT * FROM t1 WHERE x BETWEEN 'a' COLLATE nocase AND 'c' COLLATE nocase; +} {b B} +do_execsql_test 6.4 { + SELECT * FROM t1 + WHERE x COLLATE nocase BETWEEN 'a' COLLATE nocase AND 'c' COLLATE nocase; +} {b B} +do_execsql_test 6.5 { + SELECT * FROM t1 WHERE +x COLLATE nocase BETWEEN 'a' AND 'c'; +} {b B} +do_execsql_test 6.6 { + SELECT * FROM t1 WHERE +x BETWEEN 'a' COLLATE nocase AND 'c' COLLATE nocase; +} {b B} +do_execsql_test 6.7 { + SELECT * FROM t1 + WHERE +x COLLATE nocase BETWEEN 'a' COLLATE nocase AND 'c' COLLATE nocase; +} {b B} + +finish_test diff --git a/test/collate3.test b/test/collate3.test new file mode 100644 index 0000000..99640d0 --- /dev/null +++ b/test/collate3.test @@ -0,0 +1,531 @@ +# 2001 September 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script is page cache subsystem. +# +# $Id: collate3.test,v 1.13 2008/08/20 16:35:10 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# +# Tests are organised as follows: +# +# collate3.1.* - Errors related to unknown collation sequences. +# collate3.2.* - Errors related to undefined collation sequences. +# collate3.3.* - Writing to a table that has an index with an undefined c.s. +# collate3.4.* - Misc errors. +# collate3.5.* - Collation factory. +# + +# +# These tests ensure that when a user executes a statement with an +# unknown collation sequence an error is returned. +# +do_test collate3-1.0 { + execsql { + CREATE TABLE collate3t1(c1 UNIQUE); + } +} {} +do_test collate3-1.1 { + catchsql { + SELECT * FROM collate3t1 ORDER BY 1 collate garbage; + } +} {1 {no such collation sequence: garbage}} +do_test collate3-1.1.2 { + catchsql { + SELECT DISTINCT c1 COLLATE garbage FROM collate3t1; + } +} {1 {no such collation sequence: garbage}} +do_test collate3-1.2 { + catchsql { + CREATE TABLE collate3t2(c1 collate garbage); + } +} {1 {no such collation sequence: garbage}} +do_test collate3-1.3 { + catchsql { + CREATE INDEX collate3i1 ON collate3t1(c1 COLLATE garbage); + } +} {1 {no such collation sequence: garbage}} + +execsql { + DROP TABLE collate3t1; +} + +proc caseless {a b} { string compare -nocase $a $b } +do_test collate3-1.4 { + db collate caseless caseless + execsql { + CREATE TABLE t1(a COLLATE caseless); + INSERT INTO t1 VALUES('Abc2'); + INSERT INTO t1 VALUES('abc1'); + INSERT INTO t1 VALUES('aBc3'); + } + execsql { SELECT * FROM t1 ORDER BY a } +} {abc1 Abc2 aBc3} + +do_test collate3-1.5 { + db close + sqlite3 db test.db + catchsql { SELECT * FROM t1 ORDER BY a } +} {1 {no such collation sequence: caseless}} + +do_test collate3-1.6.1 { + db collate caseless caseless + execsql { CREATE INDEX i1 ON t1(a) } + execsql { SELECT * FROM t1 ORDER BY a } +} {abc1 Abc2 aBc3} + +do_test collate3-1.6.2 { + db close + sqlite3 db test.db + catchsql { SELECT * FROM t1 ORDER BY a } +} {1 {no such collation sequence: caseless}} + +do_test collate3-1.6.3 { + db close + sqlite3 db test.db + catchsql { PRAGMA integrity_check } +} {1 {no such collation sequence: caseless}} + +do_test collate3-1.6.4 { + db close + sqlite3 db test.db + catchsql { REINDEX } +} {1 {no such collation sequence: caseless}} + +do_test collate3-1.7.1 { + db collate caseless caseless + execsql { + DROP TABLE t1; + CREATE TABLE t1(a); + CREATE INDEX i1 ON t1(a COLLATE caseless); + INSERT INTO t1 VALUES('Abc2'); + INSERT INTO t1 VALUES('abc1'); + INSERT INTO t1 VALUES('aBc3'); + SELECT * FROM t1 ORDER BY a COLLATE caseless; + } +} {abc1 Abc2 aBc3} + +do_test collate3-1.7.2 { + db close + sqlite3 db test.db + catchsql { SELECT * FROM t1 ORDER BY a COLLATE caseless} +} {1 {no such collation sequence: caseless}} + +do_test collate3-1.7.4 { + db close + sqlite3 db test.db + catchsql { REINDEX } +} {1 {no such collation sequence: caseless}} + +do_test collate3-1.7.3 { + db close + sqlite3 db test.db + catchsql { PRAGMA integrity_check } +} {1 {no such collation sequence: caseless}} + +do_test collate3-1.7.4 { + db close + sqlite3 db test.db + catchsql { REINDEX } +} {1 {no such collation sequence: caseless}} + +do_test collate3-1.7.5 { + db close + sqlite3 db test.db + db collate caseless caseless + catchsql { PRAGMA integrity_check } +} {0 ok} + +proc needed {nm} { db collate caseless caseless } +do_test collate3-1.7.6 { + db close + sqlite3 db test.db + db collation_needed needed + catchsql { PRAGMA integrity_check } +} {0 ok} + +do_test collate3-1.8 { + execsql { DROP TABLE t1 } +} {} + +# +# Create a table with a default collation sequence, then close +# and re-open the database without re-registering the collation +# sequence. Then make sure the library stops us from using +# the collation sequence in: +# * an explicitly collated ORDER BY +# * an ORDER BY that uses the default collation sequence +# * an expression (=) +# * a CREATE TABLE statement +# * a CREATE INDEX statement that uses a default collation sequence +# * a GROUP BY that uses the default collation sequence +# * a SELECT DISTINCT that uses the default collation sequence +# * Compound SELECTs that uses the default collation sequence +# * An ORDER BY on a compound SELECT with an explicit ORDER BY. +# +do_test collate3-2.0 { + db collate string_compare {string compare} + execsql { + CREATE TABLE collate3t1(c1 COLLATE string_compare, c2); + } + db close + sqlite3 db test.db + expr 0 +} 0 +do_test collate3-2.1 { + catchsql { + SELECT * FROM collate3t1 ORDER BY 1 COLLATE string_compare; + } +} {1 {no such collation sequence: string_compare}} +do_test collate3-2.2 { + catchsql { + SELECT * FROM collate3t1 ORDER BY c1; + } +} {1 {no such collation sequence: string_compare}} +do_test collate3-2.3 { + catchsql { + SELECT * FROM collate3t1 WHERE c1 = 'xxx'; + } +} {1 {no such collation sequence: string_compare}} +do_test collate3-2.4 { + catchsql { + CREATE TABLE collate3t2(c1 COLLATE string_compare); + } +} {1 {no such collation sequence: string_compare}} +do_test collate3-2.5 { + catchsql { + CREATE INDEX collate3t1_i1 ON collate3t1(c1); + } +} {1 {no such collation sequence: string_compare}} +do_test collate3-2.6 { + catchsql { + SELECT * FROM collate3t1; + } +} {0 {}} +do_test collate3-2.7.1 { + catchsql { + SELECT count(*) FROM collate3t1 GROUP BY c1; + } +} {1 {no such collation sequence: string_compare}} +# do_test collate3-2.7.2 { +# catchsql { +# SELECT * FROM collate3t1 GROUP BY c1; +# } +# } {1 {GROUP BY may only be used on aggregate queries}} +do_test collate3-2.7.2 { + catchsql { + SELECT * FROM collate3t1 GROUP BY c1; + } +} {1 {no such collation sequence: string_compare}} +do_test collate3-2.8 { + catchsql { + SELECT DISTINCT c1 FROM collate3t1; + } +} {1 {no such collation sequence: string_compare}} + +ifcapable compound { + do_test collate3-2.9 { + catchsql { + SELECT c1 FROM collate3t1 UNION SELECT c1 FROM collate3t1; + } + } {1 {no such collation sequence: string_compare}} + do_test collate3-2.10 { + catchsql { + SELECT c1 FROM collate3t1 EXCEPT SELECT c1 FROM collate3t1; + } + } {1 {no such collation sequence: string_compare}} + do_test collate3-2.11 { + catchsql { + SELECT c1 FROM collate3t1 INTERSECT SELECT c1 FROM collate3t1; + } + } {1 {no such collation sequence: string_compare}} + do_test collate3-2.12 { + catchsql { + SELECT c1 FROM collate3t1 UNION ALL SELECT c1 FROM collate3t1; + } + } {0 {}} + do_test collate3-2.13 { + catchsql { + SELECT 10 UNION ALL SELECT 20 ORDER BY 1 COLLATE string_compare; + } + } {1 {no such collation sequence: string_compare}} + do_test collate3-2.14 { + catchsql { + SELECT 10 INTERSECT SELECT 20 ORDER BY 1 COLLATE string_compare; + } + } {1 {no such collation sequence: string_compare}} + do_test collate3-2.15 { + catchsql { + SELECT 10 EXCEPT SELECT 20 ORDER BY 1 COLLATE string_compare; + } + } {1 {no such collation sequence: string_compare}} + do_test collate3-2.16 { + catchsql { + SELECT 10 UNION SELECT 20 ORDER BY 1 COLLATE string_compare; + } + } {1 {no such collation sequence: string_compare}} + do_test collate3-2.17 { + catchsql { + SELECT c1 FROM collate3t1 UNION ALL SELECT c1 FROM collate3t1 ORDER BY 1; + } + } {1 {no such collation sequence: string_compare}} +} ;# ifcapable compound + +# +# Create an index that uses a collation sequence then close and +# re-open the database without re-registering the collation +# sequence. Then check that for the table with the index +# * An INSERT fails, +# * An UPDATE on the column with the index fails, +# * An UPDATE on a different column succeeds. +# * A DELETE with a WHERE clause fails +# * A DELETE without a WHERE clause succeeds +# +# Also, ensure that the restrictions tested by collate3-2.* still +# apply after the index has been created. +# +do_test collate3-3.0 { + db collate string_compare {string compare} + execsql { + CREATE INDEX collate3t1_i1 ON collate3t1(c1); + INSERT INTO collate3t1 VALUES('xxx', 'yyy'); + } + db close + sqlite3 db test.db + expr 0 +} 0 +db eval {select * from collate3t1} +do_test collate3-3.1 { + catchsql { + INSERT INTO collate3t1 VALUES('xxx', 0); + } +} {1 {no such collation sequence: string_compare}} +do_test collate3-3.2 { + catchsql { + UPDATE collate3t1 SET c1 = 'xxx'; + } +} {1 {no such collation sequence: string_compare}} +do_test collate3-3.3 { + catchsql { + UPDATE collate3t1 SET c2 = 'xxx'; + } +} {0 {}} +do_test collate3-3.4 { + catchsql { + DELETE FROM collate3t1 WHERE 1; + } +} {1 {no such collation sequence: string_compare}} +do_test collate3-3.5 { + catchsql { + SELECT * FROM collate3t1; + } +} {0 {xxx xxx}} +do_test collate3-3.6 { + catchsql { + DELETE FROM collate3t1; + } +} {0 {}} +ifcapable {integrityck} { + do_test collate3-3.8 { + catchsql { + PRAGMA integrity_check + } + } {1 {no such collation sequence: string_compare}} +} +do_test collate3-3.9 { + catchsql { + SELECT * FROM collate3t1; + } +} {0 {}} +do_test collate3-3.10 { + catchsql { + SELECT * FROM collate3t1 ORDER BY 1 COLLATE string_compare; + } +} {1 {no such collation sequence: string_compare}} +do_test collate3-3.11 { + catchsql { + SELECT * FROM collate3t1 ORDER BY c1; + } +} {1 {no such collation sequence: string_compare}} +do_test collate3-3.12 { + catchsql { + SELECT * FROM collate3t1 WHERE c1 = 'xxx'; + } +} {1 {no such collation sequence: string_compare}} +do_test collate3-3.13 { + catchsql { + CREATE TABLE collate3t2(c1 COLLATE string_compare); + } +} {1 {no such collation sequence: string_compare}} +do_test collate3-3.14 { + catchsql { + CREATE INDEX collate3t1_i2 ON collate3t1(c1); + } +} {1 {no such collation sequence: string_compare}} +do_test collate3-3.15 { + execsql { + DROP TABLE collate3t1; + } +} {} + +# Check we can create an index that uses an explicit collation +# sequence and then close and re-open the database. +do_test collate3-4.6 { + db collate user_defined "string compare" + execsql { + CREATE TABLE collate3t1(a, b); + INSERT INTO collate3t1 VALUES('hello', NULL); + CREATE INDEX collate3i1 ON collate3t1(a COLLATE user_defined); + } +} {} +do_test collate3-4.7 { + db close + sqlite3 db test.db + catchsql { + SELECT * FROM collate3t1 ORDER BY a COLLATE user_defined; + } +} {1 {no such collation sequence: user_defined}} +do_test collate3-4.8.1 { + db collate user_defined "string compare" + catchsql { + SELECT * FROM collate3t1 ORDER BY a COLLATE user_defined; + } +} {0 {hello {}}} +do_test collate3-4.8.2 { + db close + lindex [catch { + sqlite3 db test.db + }] 0 +} {0} +do_test collate3-4.8.3 { + execsql { + DROP TABLE collate3t1; + } +} {} + +# Compare strings as numbers. +proc numeric_compare {lhs rhs} { + if {$rhs > $lhs} { + set res -1 + } else { + set res [expr ($lhs > $rhs)?1:0] + } + return $res +} + +# Check we can create a view that uses an explicit collation +# sequence and then close and re-open the database. +ifcapable view { +do_test collate3-4.9 { + db collate user_defined numeric_compare + execsql { + CREATE TABLE collate3t1(a, b); + INSERT INTO collate3t1 VALUES('2', NULL); + INSERT INTO collate3t1 VALUES('101', NULL); + INSERT INTO collate3t1 VALUES('12', NULL); + CREATE VIEW collate3v1 AS SELECT * FROM collate3t1 + ORDER BY 1 COLLATE user_defined; + SELECT * FROM collate3v1; + } +} {2 {} 12 {} 101 {}} +do_test collate3-4.10 { + db close + sqlite3 db test.db + catchsql { + SELECT * FROM collate3v1; + } +} {1 {no such collation sequence: user_defined}} +do_test collate3-4.11 { + db collate user_defined numeric_compare + catchsql { + SELECT * FROM collate3v1; + } +} {0 {2 {} 12 {} 101 {}}} +do_test collate3-4.12 { + execsql { + DROP TABLE collate3t1; + } +} {} +} ;# ifcapable view + +# +# Test the collation factory. In the code, the "no such collation sequence" +# message is only generated in two places. So these tests just test that +# the collation factory can be called once from each of those points. +# +do_test collate3-5.0 { + catchsql { + CREATE TABLE collate3t1(a); + INSERT INTO collate3t1 VALUES(10); + SELECT a FROM collate3t1 ORDER BY 1 COLLATE unk; + } +} {1 {no such collation sequence: unk}} +do_test collate3-5.1 { + set ::cfact_cnt 0 + proc cfact {nm} { + db collate $nm {string compare} + incr ::cfact_cnt + } + db collation_needed cfact +} {} +do_test collate3-5.2 { + catchsql { + SELECT a FROM collate3t1 ORDER BY 1 COLLATE unk; + } +} {0 10} +do_test collate3-5.3 { + set ::cfact_cnt +} {1} +do_test collate3-5.4 { + catchsql { + SELECT a FROM collate3t1 ORDER BY 1 COLLATE unk; + } +} {0 10} +do_test collate3-5.5 { + set ::cfact_cnt +} {1} +do_test collate3-5.6 { + catchsql { + SELECT a FROM collate3t1 ORDER BY 1 COLLATE unk; + } +} {0 10} +do_test collate3-5.7 { + execsql { + DROP TABLE collate3t1; + CREATE TABLE collate3t1(a COLLATE unk); + } + db close + sqlite3 db test.db + catchsql { + SELECT a FROM collate3t1 ORDER BY 1; + } +} {1 {no such collation sequence: unk}} +do_test collate3-5.8 { + set ::cfact_cnt 0 + proc cfact {nm} { + db collate $nm {string compare} + incr ::cfact_cnt + } + db collation_needed cfact + catchsql { + SELECT a FROM collate3t1 ORDER BY 1; + } +} {0 {}} + +do_test collate3-5.9 { + execsql { + DROP TABLE collate3t1; + } +} {} + +finish_test diff --git a/test/collate4.test b/test/collate4.test new file mode 100644 index 0000000..b8c1c57 --- /dev/null +++ b/test/collate4.test @@ -0,0 +1,704 @@ +# +# 2001 September 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script is page cache subsystem. +# +# $Id: collate4.test,v 1.9 2008/01/05 17:39:30 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +db collate TEXT text_collate +proc text_collate {a b} { + return [string compare $a $b] +} + +# Do an SQL statement. Append the search count to the end of the result. +# +proc count sql { + set ::sqlite_search_count 0 + return [concat [execsql $sql] $::sqlite_search_count] +} + +# This procedure executes the SQL. Then it checks the generated program +# for the SQL and appends a "nosort" to the result if the program contains the +# SortCallback opcode. If the program does not contain the SortCallback +# opcode it appends "sort" +# +proc cksort {sql} { + set ::sqlite_sort_count 0 + set data [execsql $sql] + if {$::sqlite_sort_count} {set x sort} {set x nosort} + lappend data $x + return $data +} + +# +# Test cases are organized roughly as follows: +# +# collate4-1.* ORDER BY. +# collate4-2.* WHERE clauses. +# collate4-3.* constraints (primary key, unique). +# collate4-4.* simple min() or max() queries. +# collate4-5.* REINDEX command +# collate4-6.* INTEGER PRIMARY KEY indices. +# + +# +# These tests - collate4-1.* - check that indices are correctly +# selected or not selected to implement ORDER BY clauses when +# user defined collation sequences are involved. +# +# Because these tests also exercise all the different ways indices +# can be created, they also serve to verify that indices are correctly +# initialized with user-defined collation sequences when they are +# created. +# +# Tests named collate4-1.1.* use indices with a single column. Tests +# collate4-1.2.* use indices with two columns. +# +do_test collate4-1.1.0 { + execsql { + CREATE TABLE collate4t1(a COLLATE NOCASE, b COLLATE TEXT); + INSERT INTO collate4t1 VALUES( 'a', 'a' ); + INSERT INTO collate4t1 VALUES( 'b', 'b' ); + INSERT INTO collate4t1 VALUES( NULL, NULL ); + INSERT INTO collate4t1 VALUES( 'B', 'B' ); + INSERT INTO collate4t1 VALUES( 'A', 'A' ); + CREATE INDEX collate4i1 ON collate4t1(a); + CREATE INDEX collate4i2 ON collate4t1(b); + } +} {} +do_test collate4-1.1.1 { + cksort {SELECT a FROM collate4t1 ORDER BY a} +} {{} a A b B nosort} +do_test collate4-1.1.2 { + cksort {SELECT a FROM collate4t1 ORDER BY a COLLATE NOCASE} +} {{} a A b B nosort} +do_test collate4-1.1.3 { + cksort {SELECT a FROM collate4t1 ORDER BY a COLLATE TEXT} +} {{} A B a b sort} +do_test collate4-1.1.4 { + cksort {SELECT b FROM collate4t1 ORDER BY b} +} {{} A B a b nosort} +do_test collate4-1.1.5 { + cksort {SELECT b FROM collate4t1 ORDER BY b COLLATE TEXT} +} {{} A B a b nosort} +do_test collate4-1.1.6 { + cksort {SELECT b FROM collate4t1 ORDER BY b COLLATE NOCASE, rowid} +} {{} a A b B sort} + +do_test collate4-1.1.7 { + execsql { + CREATE TABLE collate4t2( + a PRIMARY KEY COLLATE NOCASE, + b UNIQUE COLLATE TEXT + ); + INSERT INTO collate4t2 VALUES( 'a', 'a' ); + INSERT INTO collate4t2 VALUES( NULL, NULL ); + INSERT INTO collate4t2 VALUES( 'B', 'B' ); + } +} {} +do_test collate4-1.1.8 { + cksort {SELECT a FROM collate4t2 ORDER BY a} +} {{} a B nosort} +do_test collate4-1.1.9 { + cksort {SELECT a FROM collate4t2 ORDER BY a COLLATE NOCASE} +} {{} a B nosort} +do_test collate4-1.1.10 { + cksort {SELECT a FROM collate4t2 ORDER BY a COLLATE TEXT} +} {{} B a sort} +do_test collate4-1.1.11 { + cksort {SELECT b FROM collate4t2 ORDER BY b} +} {{} B a nosort} +do_test collate4-1.1.12 { + cksort {SELECT b FROM collate4t2 ORDER BY b COLLATE TEXT} +} {{} B a nosort} +do_test collate4-1.1.13 { + cksort {SELECT b FROM collate4t2 ORDER BY b COLLATE NOCASE} +} {{} a B sort} + +do_test collate4-1.1.14 { + execsql { + CREATE TABLE collate4t3( + b COLLATE TEXT, + a COLLATE NOCASE, + UNIQUE(a), PRIMARY KEY(b) + ); + INSERT INTO collate4t3 VALUES( 'a', 'a' ); + INSERT INTO collate4t3 VALUES( NULL, NULL ); + INSERT INTO collate4t3 VALUES( 'B', 'B' ); + } +} {} +do_test collate4-1.1.15 { + cksort {SELECT a FROM collate4t3 ORDER BY a} +} {{} a B nosort} +do_test collate4-1.1.16 { + cksort {SELECT a FROM collate4t3 ORDER BY a COLLATE NOCASE} +} {{} a B nosort} +do_test collate4-1.1.17 { + cksort {SELECT a FROM collate4t3 ORDER BY a COLLATE TEXT} +} {{} B a sort} +do_test collate4-1.1.18 { + cksort {SELECT b FROM collate4t3 ORDER BY b} +} {{} B a nosort} +do_test collate4-1.1.19 { + cksort {SELECT b FROM collate4t3 ORDER BY b COLLATE TEXT} +} {{} B a nosort} +do_test collate4-1.1.20 { + cksort {SELECT b FROM collate4t3 ORDER BY b COLLATE NOCASE} +} {{} a B sort} + +do_test collate4-1.1.21 { + execsql { + CREATE TABLE collate4t4(a COLLATE NOCASE, b COLLATE TEXT); + INSERT INTO collate4t4 VALUES( 'a', 'a' ); + INSERT INTO collate4t4 VALUES( 'b', 'b' ); + INSERT INTO collate4t4 VALUES( NULL, NULL ); + INSERT INTO collate4t4 VALUES( 'B', 'B' ); + INSERT INTO collate4t4 VALUES( 'A', 'A' ); + CREATE INDEX collate4i3 ON collate4t4(a COLLATE TEXT); + CREATE INDEX collate4i4 ON collate4t4(b COLLATE NOCASE); + } +} {} +do_test collate4-1.1.22 { + cksort {SELECT a FROM collate4t4 ORDER BY a, rowid} +} {{} a A b B sort} +do_test collate4-1.1.23 { + cksort {SELECT a FROM collate4t4 ORDER BY a COLLATE NOCASE, rowid} +} {{} a A b B sort} +do_test collate4-1.1.24 { + cksort {SELECT a FROM collate4t4 ORDER BY a COLLATE TEXT, rowid} +} {{} A B a b nosort} +do_test collate4-1.1.25 { + cksort {SELECT b FROM collate4t4 ORDER BY b} +} {{} A B a b sort} +do_test collate4-1.1.26 { + cksort {SELECT b FROM collate4t4 ORDER BY b COLLATE TEXT} +} {{} A B a b sort} +do_test collate4-1.1.27 { + cksort {SELECT b FROM collate4t4 ORDER BY b COLLATE NOCASE} +} {{} a A b B nosort} + +do_test collate4-1.1.30 { + execsql { + DROP TABLE collate4t1; + DROP TABLE collate4t2; + DROP TABLE collate4t3; + DROP TABLE collate4t4; + } +} {} + +do_test collate4-1.2.0 { + execsql { + CREATE TABLE collate4t1(a COLLATE NOCASE, b COLLATE TEXT); + INSERT INTO collate4t1 VALUES( 'a', 'a' ); + INSERT INTO collate4t1 VALUES( 'b', 'b' ); + INSERT INTO collate4t1 VALUES( NULL, NULL ); + INSERT INTO collate4t1 VALUES( 'B', 'B' ); + INSERT INTO collate4t1 VALUES( 'A', 'A' ); + CREATE INDEX collate4i1 ON collate4t1(a, b); + } +} {} +do_test collate4-1.2.1 { + cksort {SELECT a FROM collate4t1 ORDER BY a} +} {{} A a B b nosort} +do_test collate4-1.2.2 { + cksort {SELECT a FROM collate4t1 ORDER BY a COLLATE nocase} +} {{} A a B b nosort} +do_test collate4-1.2.3 { + cksort {SELECT a FROM collate4t1 ORDER BY a COLLATE text} +} {{} A B a b sort} +do_test collate4-1.2.4 { + cksort {SELECT a FROM collate4t1 ORDER BY a, b} +} {{} A a B b nosort} +do_test collate4-1.2.5 { + cksort {SELECT a FROM collate4t1 ORDER BY a, b COLLATE nocase, rowid} +} {{} a A b B sort} +do_test collate4-1.2.6 { + cksort {SELECT a FROM collate4t1 ORDER BY a, b COLLATE text} +} {{} A a B b nosort} + +do_test collate4-1.2.7 { + execsql { + CREATE TABLE collate4t2( + a COLLATE NOCASE, + b COLLATE TEXT, + PRIMARY KEY(a, b) + ); + INSERT INTO collate4t2 VALUES( 'a', 'a' ); + INSERT INTO collate4t2 VALUES( NULL, NULL ); + INSERT INTO collate4t2 VALUES( 'B', 'B' ); + } +} {} +do_test collate4-1.2.8 { + cksort {SELECT a FROM collate4t2 ORDER BY a} +} {{} a B nosort} +do_test collate4-1.2.9 { + cksort {SELECT a FROM collate4t2 ORDER BY a COLLATE nocase} +} {{} a B nosort} +do_test collate4-1.2.10 { + cksort {SELECT a FROM collate4t2 ORDER BY a COLLATE text} +} {{} B a sort} +do_test collate4-1.2.11 { + cksort {SELECT a FROM collate4t2 ORDER BY a, b} +} {{} a B nosort} +do_test collate4-1.2.12 { + cksort {SELECT a FROM collate4t2 ORDER BY a, b COLLATE nocase} +} {{} a B sort} +do_test collate4-1.2.13 { + cksort {SELECT a FROM collate4t2 ORDER BY a, b COLLATE text} +} {{} a B nosort} + +do_test collate4-1.2.14 { + execsql { + CREATE TABLE collate4t3(a COLLATE NOCASE, b COLLATE TEXT); + INSERT INTO collate4t3 VALUES( 'a', 'a' ); + INSERT INTO collate4t3 VALUES( 'b', 'b' ); + INSERT INTO collate4t3 VALUES( NULL, NULL ); + INSERT INTO collate4t3 VALUES( 'B', 'B' ); + INSERT INTO collate4t3 VALUES( 'A', 'A' ); + CREATE INDEX collate4i2 ON collate4t3(a COLLATE TEXT, b COLLATE NOCASE); + } +} {} +do_test collate4-1.2.15 { + cksort {SELECT a FROM collate4t3 ORDER BY a, rowid} +} {{} a A b B sort} +do_test collate4-1.2.16 { + cksort {SELECT a FROM collate4t3 ORDER BY a COLLATE nocase, rowid} +} {{} a A b B sort} +do_test collate4-1.2.17 { + cksort {SELECT a FROM collate4t3 ORDER BY a COLLATE text} +} {{} A B a b nosort} +do_test collate4-1.2.18 { + cksort {SELECT a FROM collate4t3 ORDER BY a COLLATE text, b} +} {{} A B a b sort} +do_test collate4-1.2.19 { + cksort {SELECT a FROM collate4t3 ORDER BY a COLLATE text, b COLLATE nocase} +} {{} A B a b nosort} +do_test collate4-1.2.20 { + cksort {SELECT a FROM collate4t3 ORDER BY a COLLATE text, b COLLATE text} +} {{} A B a b sort} +do_test collate4-1.2.21 { + cksort {SELECT a FROM collate4t3 ORDER BY a COLLATE text DESC} +} {b a B A {} nosort} +do_test collate4-1.2.22 { + cksort {SELECT a FROM collate4t3 ORDER BY a COLLATE text DESC, b} +} {b a B A {} sort} +do_test collate4-1.2.23 { + cksort {SELECT a FROM collate4t3 + ORDER BY a COLLATE text DESC, b COLLATE nocase} +} {b a B A {} sort} +do_test collate4-1.2.24 { + cksort {SELECT a FROM collate4t3 + ORDER BY a COLLATE text DESC, b COLLATE nocase DESC} +} {b a B A {} nosort} + +do_test collate4-1.2.25 { + execsql { + DROP TABLE collate4t1; + DROP TABLE collate4t2; + DROP TABLE collate4t3; + } +} {} + +# +# These tests - collate4-2.* - check that indices are correctly +# selected or not selected to implement WHERE clauses when user +# defined collation sequences are involved. +# +# Indices may optimise WHERE clauses using <, >, <=, >=, = or IN +# operators. +# +do_test collate4-2.1.0 { + execsql { + PRAGMA automatic_index=OFF; + CREATE TABLE collate4t1(a COLLATE NOCASE); + CREATE TABLE collate4t2(b COLLATE TEXT); + + INSERT INTO collate4t1 VALUES('a'); + INSERT INTO collate4t1 VALUES('A'); + INSERT INTO collate4t1 VALUES('b'); + INSERT INTO collate4t1 VALUES('B'); + INSERT INTO collate4t1 VALUES('c'); + INSERT INTO collate4t1 VALUES('C'); + INSERT INTO collate4t1 VALUES('d'); + INSERT INTO collate4t1 VALUES('D'); + INSERT INTO collate4t1 VALUES('e'); + INSERT INTO collate4t1 VALUES('D'); + + INSERT INTO collate4t2 VALUES('A'); + INSERT INTO collate4t2 VALUES('Z'); + } +} {} +do_test collate4-2.1.1 { + count { + SELECT * FROM collate4t2, collate4t1 WHERE a = b; + } +} {A a A A 19} +do_test collate4-2.1.2 { + execsql { + CREATE INDEX collate4i1 ON collate4t1(a); + } + count { + SELECT * FROM collate4t2, collate4t1 WHERE a = b; + } +} {A a A A 4} +do_test collate4-2.1.3 { + count { + SELECT * FROM collate4t2, collate4t1 WHERE b = a; + } +} {A A 19} +do_test collate4-2.1.4 { + execsql { + DROP INDEX collate4i1; + CREATE INDEX collate4i1 ON collate4t1(a COLLATE TEXT); + } + count { + SELECT * FROM collate4t2, collate4t1 WHERE a = b + ORDER BY collate4t2.rowid, collate4t1.rowid + } +} {A a A A 19} +do_test collate4-2.1.5 { + count { + SELECT * FROM collate4t2, collate4t1 WHERE b = a; + } +} {A A 3} +ifcapable subquery { + do_test collate4-2.1.6 { + count { + SELECT a FROM collate4t1 WHERE a IN (SELECT * FROM collate4t2) + ORDER BY rowid + } + } {a A 10} + do_test collate4-2.1.7 { + execsql { + DROP INDEX collate4i1; + CREATE INDEX collate4i1 ON collate4t1(a); + } + count { + SELECT a FROM collate4t1 WHERE a IN (SELECT * FROM collate4t2) + ORDER BY rowid + } + } {a A 5} + do_test collate4-2.1.8 { + count { + SELECT a FROM collate4t1 WHERE a IN ('z', 'a'); + } + } {a A 4} + do_test collate4-2.1.9 { + execsql { + DROP INDEX collate4i1; + CREATE INDEX collate4i1 ON collate4t1(a COLLATE TEXT); + } + count { + SELECT a FROM collate4t1 WHERE a IN ('z', 'a') ORDER BY rowid; + } + } {a A 9} +} +do_test collate4-2.1.10 { + execsql { + DROP TABLE collate4t1; + DROP TABLE collate4t2; + } +} {} + +do_test collate4-2.2.0 { + execsql { + CREATE TABLE collate4t1(a COLLATE nocase, b COLLATE text, c); + CREATE TABLE collate4t2(a COLLATE nocase, b COLLATE text, c COLLATE TEXT); + + INSERT INTO collate4t1 VALUES('0', '0', '0'); + INSERT INTO collate4t1 VALUES('0', '0', '1'); + INSERT INTO collate4t1 VALUES('0', '1', '0'); + INSERT INTO collate4t1 VALUES('0', '1', '1'); + INSERT INTO collate4t1 VALUES('1', '0', '0'); + INSERT INTO collate4t1 VALUES('1', '0', '1'); + INSERT INTO collate4t1 VALUES('1', '1', '0'); + INSERT INTO collate4t1 VALUES('1', '1', '1'); + insert into collate4t2 SELECT * FROM collate4t1; + } +} {} +do_test collate4-2.2.1 { + count { + SELECT * FROM collate4t2 NOT INDEXED NATURAL JOIN collate4t1 NOT INDEXED; + } +} {0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 63} +do_test collate4-2.2.1b { + execsql { + CREATE INDEX collate4i1 ON collate4t1(a, b, c); + } + count { + SELECT * FROM collate4t2 NATURAL JOIN collate4t1; + } +} {0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 29} +do_test collate4-2.2.2 { + execsql { + DROP INDEX collate4i1; + CREATE INDEX collate4i1 ON collate4t1(a, b, c COLLATE text); + } + count { + SELECT * FROM collate4t2 NATURAL JOIN collate4t1; + } +} {0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 22} + +do_test collate4-2.2.10 { + execsql { + DROP TABLE collate4t1; + DROP TABLE collate4t2; + } +} {} + +# +# These tests - collate4-3.* verify that indices that implement +# UNIQUE and PRIMARY KEY constraints operate correctly with user +# defined collation sequences. +# +do_test collate4-3.0 { + execsql { + CREATE TABLE collate4t1(a PRIMARY KEY COLLATE NOCASE); + } +} {} +do_test collate4-3.1 { + catchsql { + INSERT INTO collate4t1 VALUES('abc'); + INSERT INTO collate4t1 VALUES('ABC'); + } +} {1 {UNIQUE constraint failed: collate4t1.a}} +do_test collate4-3.2 { + execsql { + SELECT * FROM collate4t1; + } +} {abc} +do_test collate4-3.3 { + catchsql { + INSERT INTO collate4t1 SELECT upper(a) FROM collate4t1; + } +} {1 {UNIQUE constraint failed: collate4t1.a}} +do_test collate4-3.4 { + catchsql { + INSERT INTO collate4t1 VALUES(1); + UPDATE collate4t1 SET a = 'abc'; + } +} {1 {UNIQUE constraint failed: collate4t1.a}} +do_test collate4-3.5 { + execsql { + DROP TABLE collate4t1; + CREATE TABLE collate4t1(a COLLATE NOCASE UNIQUE); + } +} {} +do_test collate4-3.6 { + catchsql { + INSERT INTO collate4t1 VALUES('abc'); + INSERT INTO collate4t1 VALUES('ABC'); + } +} {1 {UNIQUE constraint failed: collate4t1.a}} +do_test collate4-3.7 { + execsql { + SELECT * FROM collate4t1; + } +} {abc} +do_test collate4-3.8 { + catchsql { + INSERT INTO collate4t1 SELECT upper(a) FROM collate4t1; + } +} {1 {UNIQUE constraint failed: collate4t1.a}} +do_test collate4-3.9 { + catchsql { + INSERT INTO collate4t1 VALUES(1); + UPDATE collate4t1 SET a = 'abc'; + } +} {1 {UNIQUE constraint failed: collate4t1.a}} +do_test collate4-3.10 { + execsql { + DROP TABLE collate4t1; + CREATE TABLE collate4t1(a); + CREATE UNIQUE INDEX collate4i1 ON collate4t1(a COLLATE NOCASE); + } +} {} +do_test collate4-3.11 { + catchsql { + INSERT INTO collate4t1 VALUES('abc'); + INSERT INTO collate4t1 VALUES('ABC'); + } +} {1 {UNIQUE constraint failed: collate4t1.a}} +do_test collate4-3.12 { + execsql { + SELECT * FROM collate4t1; + } +} {abc} +do_test collate4-3.13 { + catchsql { + INSERT INTO collate4t1 SELECT upper(a) FROM collate4t1; + } +} {1 {UNIQUE constraint failed: collate4t1.a}} +do_test collate4-3.14 { + catchsql { + INSERT INTO collate4t1 VALUES(1); + UPDATE collate4t1 SET a = 'abc'; + } +} {1 {UNIQUE constraint failed: collate4t1.a}} + +do_test collate4-3.15 { + execsql { + DROP TABLE collate4t1; + } +} {} + +# Mimic the SQLite 2 collation type NUMERIC. +db collate numeric numeric_collate +proc numeric_collate {lhs rhs} { + if {$lhs == $rhs} {return 0} + return [expr ($lhs>$rhs)?1:-1] +} + +# +# These tests - collate4-4.* check that min() and max() only ever +# use indices constructed with built-in collation type numeric. +# +# CHANGED: min() and max() now use the collation type. If there +# is an indice that can be used, it is used. +# +do_test collate4-4.0 { + execsql { + CREATE TABLE collate4t1(a COLLATE TEXT); + INSERT INTO collate4t1 VALUES('2'); + INSERT INTO collate4t1 VALUES('10'); + INSERT INTO collate4t1 VALUES('20'); + INSERT INTO collate4t1 VALUES('104'); + } +} {} +do_test collate4-4.1 { + count { + SELECT max(a) FROM collate4t1 + } +} {20 3} +do_test collate4-4.2 { + count { + SELECT min(a) FROM collate4t1 + } +} {10 3} +do_test collate4-4.3 { + # Test that the index with collation type TEXT is used. + execsql { + CREATE INDEX collate4i1 ON collate4t1(a); + } + count { + SELECT min(a) FROM collate4t1; + } +} {10 1} +do_test collate4-4.4 { + count { + SELECT max(a) FROM collate4t1; + } +} {20 0} +do_test collate4-4.5 { + # Test that the index with collation type NUMERIC is not used. + execsql { + DROP INDEX collate4i1; + CREATE INDEX collate4i1 ON collate4t1(a COLLATE NUMERIC); + } + count { + SELECT min(a) FROM collate4t1; + } +} {10 3} +do_test collate4-4.6 { + count { + SELECT max(a) FROM collate4t1; + } +} {20 3} +do_test collate4-4.7 { + execsql { + DROP TABLE collate4t1; + } +} {} + +# Also test the scalar min() and max() functions. +# +do_test collate4-4.8 { + execsql { + CREATE TABLE collate4t1(a COLLATE TEXT, b COLLATE NUMERIC); + INSERT INTO collate4t1 VALUES('11', '101'); + INSERT INTO collate4t1 VALUES('101', '11') + } +} {} +do_test collate4-4.9 { + execsql { + SELECT max(a, b) FROM collate4t1; + } +} {11 11} +do_test collate4-4.10 { + execsql { + SELECT max(b, a) FROM collate4t1; + } +} {101 101} +do_test collate4-4.11 { + execsql { + SELECT max(a, '101') FROM collate4t1; + } +} {11 101} +do_test collate4-4.12 { + execsql { + SELECT max('101', a) FROM collate4t1; + } +} {11 101} +do_test collate4-4.13 { + execsql { + SELECT max(b, '101') FROM collate4t1; + } +} {101 101} +do_test collate4-4.14 { + execsql { + SELECT max('101', b) FROM collate4t1; + } +} {101 101} + +do_test collate4-4.15 { + execsql { + DROP TABLE collate4t1; + } +} {} + +# +# These tests - collate4.6.* - ensure that implict INTEGER PRIMARY KEY +# indices do not confuse collation sequences. +# +# These indices are never used for sorting in SQLite. And you can't +# create another index on an INTEGER PRIMARY KEY column, so we don't have +# to test that. +# (Revised 2004-Nov-22): The ROWID can be used for sorting now. +# +do_test collate4-6.0 { + execsql { + CREATE TABLE collate4t1(a INTEGER PRIMARY KEY); + INSERT INTO collate4t1 VALUES(101); + INSERT INTO collate4t1 VALUES(10); + INSERT INTO collate4t1 VALUES(15); + } +} {} +do_test collate4-6.1 { + cksort { + SELECT * FROM collate4t1 ORDER BY 1; + } +} {10 15 101 nosort} +do_test collate4-6.2 { + cksort { + SELECT * FROM collate4t1 ORDER BY oid; + } +} {10 15 101 nosort} +do_test collate4-6.3 { + cksort { + SELECT * FROM collate4t1 ORDER BY oid||'' COLLATE TEXT; + } +} {10 101 15 sort} + +finish_test diff --git a/test/collate5.test b/test/collate5.test new file mode 100644 index 0000000..71d4efe --- /dev/null +++ b/test/collate5.test @@ -0,0 +1,328 @@ +# +# 2001 September 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this file is testing DISTINCT, UNION, INTERSECT and EXCEPT +# SELECT statements that use user-defined collation sequences. Also +# GROUP BY clauses that use user-defined collation sequences. +# +# $Id: collate5.test,v 1.7 2008/09/16 11:58:20 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +set testprefix collate5 + + +# +# Tests are organised as follows: +# collate5-1.* - DISTINCT +# collate5-2.* - Compound SELECT +# collate5-3.* - ORDER BY on compound SELECT +# collate5-4.* - GROUP BY +# collate5-5.* - Collation sequence cases + +# Create the collation sequence 'TEXT', purely for asthetic reasons. The +# test cases in this script could just as easily use BINARY. +db collate TEXT [list string compare] + +# Mimic the SQLite 2 collation type NUMERIC. +db collate numeric numeric_collate +proc numeric_collate {lhs rhs} { + if {$lhs == $rhs} {return 0} + return [expr ($lhs>$rhs)?1:-1] +} + +# +# These tests - collate5-1.* - focus on the DISTINCT keyword. +# +do_test collate5-1.0 { + execsql { + CREATE TABLE collate5t1(a COLLATE nocase, b COLLATE text); + + INSERT INTO collate5t1 VALUES('a', 'apple'); + INSERT INTO collate5t1 VALUES('A', 'Apple'); + INSERT INTO collate5t1 VALUES('b', 'banana'); + INSERT INTO collate5t1 VALUES('B', 'banana'); + INSERT INTO collate5t1 VALUES('n', NULL); + INSERT INTO collate5t1 VALUES('N', NULL); + } +} {} +do_test collate5-1.1 { + execsql { + SELECT DISTINCT a FROM collate5t1; + } +} {a b n} +do_test collate5-1.2 { + execsql { + SELECT DISTINCT b FROM collate5t1; + } +} {apple Apple banana {}} +do_test collate5-1.3 { + execsql { + SELECT DISTINCT a, b FROM collate5t1; + } +} {a apple A Apple b banana n {}} + +# Ticket #3376 +# +do_test collate5-1.11 { + execsql { + CREATE TABLE tkt3376(a COLLATE nocase PRIMARY KEY); + INSERT INTO tkt3376 VALUES('abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'); + INSERT INTO tkt3376 VALUES('ABXYZ012234567890123456789ABXYZ012234567890123456789ABXYZ012234567890123456789ABXYZ012234567890123456789ABXYZ012234567890123456789ABXYZ012234567890123456789ABXYZ012234567890123456789'); + SELECT DISTINCT a FROM tkt3376; + } +} {abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz ABXYZ012234567890123456789ABXYZ012234567890123456789ABXYZ012234567890123456789ABXYZ012234567890123456789ABXYZ012234567890123456789ABXYZ012234567890123456789ABXYZ012234567890123456789} +do_test collate5-1.12 { + sqlite3 db2 :memory: + db2 eval { + PRAGMA encoding=UTF16le; + CREATE TABLE tkt3376(a COLLATE nocase PRIMARY KEY); + INSERT INTO tkt3376 VALUES('abc'); + INSERT INTO tkt3376 VALUES('ABX'); + SELECT DISTINCT a FROM tkt3376; + } +} {abc ABX} +catch {db2 close} + +# The remainder of this file tests compound SELECT statements. +# Omit it if the library is compiled such that they are omitted. +# +ifcapable !compound { + finish_test + return +} + +# +# Tests named collate5-2.* focus on UNION, EXCEPT and INTERSECT +# queries that use user-defined collation sequences. +# +# collate5-2.1.* - UNION +# collate5-2.2.* - INTERSECT +# collate5-2.3.* - EXCEPT +# +do_test collate5-2.0 { + execsql { + CREATE TABLE collate5t2(a COLLATE text, b COLLATE nocase); + + INSERT INTO collate5t2 VALUES('a', 'apple'); + INSERT INTO collate5t2 VALUES('A', 'apple'); + INSERT INTO collate5t2 VALUES('b', 'banana'); + INSERT INTO collate5t2 VALUES('B', 'Banana'); + } +} {} + +do_test collate5-2.1.1 { + execsql { + SELECT a FROM collate5t1 UNION select a FROM collate5t2; + } +} {A B N} +do_test collate5-2.1.2 { + execsql { + SELECT a FROM collate5t2 UNION select a FROM collate5t1; + } +} {A B N a b n} +do_test collate5-2.1.3 { + execsql { + SELECT a, b FROM collate5t1 UNION select a, b FROM collate5t2; + } +} {A Apple A apple B Banana b banana N {}} +do_test collate5-2.1.4 { + execsql { + SELECT a, b FROM collate5t2 UNION select a, b FROM collate5t1; + } +} {A Apple B banana N {} a apple b banana n {}} + +do_test collate5-2.2.1 { + execsql { + SELECT a FROM collate5t1 EXCEPT select a FROM collate5t2; + } +} {N} +do_test collate5-2.2.2 { + execsql { + SELECT a FROM collate5t2 EXCEPT select a FROM collate5t1 WHERE a != 'a'; + } +} {A a} +do_test collate5-2.2.3 { + execsql { + SELECT a, b FROM collate5t1 EXCEPT select a, b FROM collate5t2; + } +} {A Apple N {}} +do_test collate5-2.2.4 { + execsql { + SELECT a, b FROM collate5t2 EXCEPT select a, b FROM collate5t1 + where a != 'a'; + } +} {A apple a apple} + +do_test collate5-2.3.1 { + execsql { + SELECT a FROM collate5t1 INTERSECT select a FROM collate5t2; + } +} {A B} +do_test collate5-2.3.2 { + execsql { + SELECT a FROM collate5t2 INTERSECT select a FROM collate5t1 WHERE a != 'a'; + } +} {B b} +do_test collate5-2.3.3 { + execsql { + SELECT a, b FROM collate5t1 INTERSECT select a, b FROM collate5t2; + } +} {a apple B banana} +do_test collate5-2.3.4 { + execsql { + SELECT a, b FROM collate5t2 INTERSECT select a, b FROM collate5t1; + } +} {A apple B Banana a apple b banana} + +# +# This test ensures performs a UNION operation with a bunch of different +# length records. The goal is to test that the logic that compares records +# for the compound SELECT operators works with record lengths that lie +# either side of the troublesome 256 and 65536 byte marks. +# +set ::lens [list \ + 0 1 2 3 4 5 6 7 8 9 \ + 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 \ + 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 \ + 65520 65521 65522 65523 65524 65525 65526 65527 65528 65529 65530 \ + 65531 65532 65533 65534 65535 65536 65537 65538 65539 65540 65541 \ + 65542 65543 65544 65545 65546 65547 65548 65549 65550 65551 ] +do_test collate5-2.4.0 { + execsql { + BEGIN; + CREATE TABLE collate5t3(a, b); + } + foreach ii $::lens { + execsql "INSERT INTO collate5t3 VALUES($ii, '[string repeat a $ii]');" + } + expr [llength [execsql { + COMMIT; + SELECT * FROM collate5t3 UNION SELECT * FROM collate5t3; + }]] / 2 +} [llength $::lens] +do_test collate5-2.4.1 { + execsql {DROP TABLE collate5t3;} +} {} +unset ::lens + +# +# These tests - collate5-3.* - focus on compound SELECT queries that +# feature ORDER BY clauses. +# +do_test collate5-3.0 { + execsql { + SELECT a FROM collate5t1 UNION ALL SELECT a FROM collate5t2 ORDER BY 1; + } +} {/[aA] [aA] [aA] [aA] [bB] [bB] [bB] [bB] [nN] [nN]/} +do_test collate5-3.1 { + execsql { + SELECT a FROM collate5t2 UNION ALL SELECT a FROM collate5t1 ORDER BY 1; + } +} {A A B B N a a b b n} +do_test collate5-3.2 { + execsql { + SELECT a FROM collate5t1 UNION ALL SELECT a FROM collate5t2 + ORDER BY 1 COLLATE TEXT; + } +} {A A B B N a a b b n} + +do_test collate5-3.3 { + execsql { + CREATE TABLE collate5t_cn(a COLLATE NUMERIC); + CREATE TABLE collate5t_ct(a COLLATE TEXT); + INSERT INTO collate5t_cn VALUES('1'); + INSERT INTO collate5t_cn VALUES('11'); + INSERT INTO collate5t_cn VALUES('101'); + INSERT INTO collate5t_ct SELECT * FROM collate5t_cn; + } +} {} +do_test collate5-3.4 { + execsql { + SELECT a FROM collate5t_cn INTERSECT SELECT a FROM collate5t_ct ORDER BY 1; + } +} {1 11 101} +do_test collate5-3.5 { + execsql { + SELECT a FROM collate5t_ct INTERSECT SELECT a FROM collate5t_cn ORDER BY 1; + } +} {1 101 11} + +do_test collate5-3.20 { + execsql { + DROP TABLE collate5t_cn; + DROP TABLE collate5t_ct; + DROP TABLE collate5t1; + DROP TABLE collate5t2; + } +} {} + +do_test collate5-4.0 { + execsql { + CREATE TABLE collate5t1(a COLLATE NOCASE, b COLLATE NUMERIC); + INSERT INTO collate5t1 VALUES('a', '1'); + INSERT INTO collate5t1 VALUES('A', '1.0'); + INSERT INTO collate5t1 VALUES('b', '2'); + INSERT INTO collate5t1 VALUES('B', '3'); + } +} {} +do_test collate5-4.1 { + string tolower [execsql { + SELECT a, count(*) FROM collate5t1 GROUP BY a; + }] +} {a 2 b 2} +do_test collate5-4.2 { + execsql { + SELECT a, b, count(*) FROM collate5t1 GROUP BY a, b ORDER BY a, b; + } +} {/[aA] 1(.0)? 2 [bB] 2 1 [bB] 3 1/} +do_test collate5-4.3 { + execsql { + DROP TABLE collate5t1; + } +} {} + +#------------------------------------------------------------------------- +reset_db + +do_execsql_test 5.0 { + CREATE TABLE t1(a, b COLLATE nocase); + CREATE TABLE t2(c, d); + INSERT INTO t2 VALUES(1, 'bbb'); +} +do_execsql_test 5.1 { + SELECT * FROM ( + SELECT a, b FROM t1 UNION ALL SELECT c, d FROM t2 + ) WHERE b='BbB'; +} {1 bbb} + +reset_db +do_execsql_test 5.2 { + CREATE TABLE t1(a,b,c COLLATE NOCASE); + INSERT INTO t1 VALUES(NULL,'C','c'); + CREATE VIEW v2 AS + SELECT a,b,c FROM t1 INTERSECT SELECT a,b,b FROM t1 + WHERE 'eT"3qRkL+oJMJjQ9z0'>=b + ORDER BY a,b,c; +} + +do_execsql_test 5.3 { + SELECT * FROM v2; +} { {} C c } + +do_execsql_test 5.4 { + SELECT * FROM v2 WHERE c='c'; +} { {} C c } + + +finish_test diff --git a/test/collate6.test b/test/collate6.test new file mode 100644 index 0000000..d238639 --- /dev/null +++ b/test/collate6.test @@ -0,0 +1,153 @@ +# +# 2001 September 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script is collation sequences in concert with triggers. +# +# $Id: collate6.test,v 1.4 2007/07/30 14:40:48 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# There are no tests in this file that will work without +# trigger support. +# +ifcapable {!trigger} { + finish_test + return +} + +# Create a case-insensitive collation type NOCASE for use in testing. +# Normally, capital letters are less than their lower-case counterparts. +db collate NOCASE nocase_collate +proc nocase_collate {a b} { + return [string compare -nocase $a $b] +} + +# +# Tests are organized as follows: +# collate6-1.* - triggers. +# + +do_test collate6-1.0 { + execsql { + CREATE TABLE collate6log(a, b); + CREATE TABLE collate6tab(a COLLATE NOCASE, b COLLATE BINARY); + } +} {} + +# Test that the default collation sequence applies to new.* references +# in WHEN clauses. +do_test collate6-1.1 { + execsql { + CREATE TRIGGER collate6trig BEFORE INSERT ON collate6tab + WHEN new.a = 'a' BEGIN + INSERT INTO collate6log VALUES(new.a, new.b); + END; + } +} {} +do_test collate6-1.2 { + execsql { + INSERT INTO collate6tab VALUES('a', 'b'); + SELECT * FROM collate6log; + } +} {a b} +do_test collate6-1.3 { + execsql { + INSERT INTO collate6tab VALUES('A', 'B'); + SELECT * FROM collate6log; + } +} {a b A B} +do_test collate6-1.4 { + execsql { + DROP TRIGGER collate6trig; + DELETE FROM collate6log; + } +} {} + +# Test that the default collation sequence applies to new.* references +# in the body of triggers. +do_test collate6-1.5 { + execsql { + CREATE TRIGGER collate6trig BEFORE INSERT ON collate6tab BEGIN + INSERT INTO collate6log VALUES(new.a='a', new.b='b'); + END; + } +} {} +do_test collate6-1.6 { + execsql { + INSERT INTO collate6tab VALUES('a', 'b'); + SELECT * FROM collate6log; + } +} {1 1} +do_test collate6-1.7 { + execsql { + INSERT INTO collate6tab VALUES('A', 'B'); + SELECT * FROM collate6log; + } +} {1 1 1 0} +do_test collate6-1.8 { + execsql { + DROP TRIGGER collate6trig; + DELETE FROM collate6log; + } +} {} + +do_test collate6-1.9 { + execsql { + DROP TABLE collate6tab; + } +} {} + +# Test that an explicit collation sequence overrides an implicit +# one attached to a 'new' reference. +# +do_test collate6-2.1 { + execsql { + CREATE TABLE abc(a COLLATE binary, b, c); + CREATE TABLE def(a, b, c); + CREATE TRIGGER abc_t1 AFTER INSERT ON abc BEGIN + INSERT INTO def SELECT * FROM abc WHERE a < new.a COLLATE nocase; + END + } +} {} +do_test collate6-2.2 { + execsql { + INSERT INTO abc VALUES('One', 'Two', 'Three'); + INSERT INTO abc VALUES('one', 'two', 'three'); + SELECT * FROM def; + } +} {} +do_test collate6-2.3 { + execsql { + UPDATE abc SET a = 'four' WHERE a = 'one'; + CREATE TRIGGER abc_t2 AFTER UPDATE ON abc BEGIN + INSERT INTO def SELECT * FROM abc WHERE a < new.a COLLATE nocase; + END; + SELECT * FROM def; + } +} {} + +# At one point the 6-3.2 (but not 6-3.1) was causing an assert() to fail. +# +do_test collate6-3.1 { + execsql { + SELECT 1 FROM sqlite_master WHERE name COLLATE nocase = 'hello'; + } +} {} +do_test collate6-3.2 { + execsql { + SELECT 1 FROM sqlite_master WHERE 'hello' = name COLLATE nocase; + } +} {} + + +finish_test diff --git a/test/collate7.test b/test/collate7.test new file mode 100644 index 0000000..da97491 --- /dev/null +++ b/test/collate7.test @@ -0,0 +1,72 @@ +# +# 2007 May 7 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script is the experimental sqlite3_create_collation_v2() +# API. +# +# $Id: collate7.test,v 1.2 2008/07/12 14:52:20 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +set ::caseless_del 0 +proc caseless_cmp {zLeft zRight} { + string compare -nocase $zLeft $zRight +} + +do_test collate7-1.1 { + set cmd [list incr ::caseless_del] + sqlite3_create_collation_v2 db CASELESS caseless_cmp $cmd + set ::caseless_del +} {0} +do_test collate7-1.2 { + sqlite_delete_collation db CASELESS + set ::caseless_del +} {1} +do_test collate7-1.3 { + catchsql { + CREATE TABLE abc(a COLLATE CASELESS, b, c); + } +} {1 {no such collation sequence: CASELESS}} +do_test collate7-1.4 { + sqlite3_create_collation_v2 db CASELESS caseless_cmp {incr ::caseless_del} + db close + set ::caseless_del +} {2} + +do_test collate7-2.1 { + forcedelete test.db test.db-journal + sqlite3 db test.db + sqlite3_create_collation_v2 db CASELESS caseless_cmp {incr ::caseless_del} + execsql { + PRAGMA encoding='utf-16'; + CREATE TABLE abc16(a COLLATE CASELESS, b, c); + } db + set ::caseless_del +} {2} +do_test collate7-2.2 { + execsql { + SELECT * FROM abc16 WHERE a < 'abc'; + } + set ::caseless_del +} {2} +do_test collate7-2.3 { + sqlite_delete_collation db CASELESS + set ::caseless_del +} {3} +do_test collate7-2.4 { + catchsql { + SELECT * FROM abc16 WHERE a < 'abc'; + } +} {1 {no such collation sequence: CASELESS}} + +finish_test diff --git a/test/collate8.test b/test/collate8.test new file mode 100644 index 0000000..b06c87d --- /dev/null +++ b/test/collate8.test @@ -0,0 +1,157 @@ +# +# 2007 June 20 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script is making sure collations pass through the +# unary + operator. +# +# 2015-02-09: Added tests to make sure COLLATE passes through function +# calls. Ticket [ca0d20b6cdddec5e81b8d66f89c46a5583b5f6f6]. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +do_test collate8-1.1 { + execsql { + CREATE TABLE t1(a TEXT COLLATE nocase); + INSERT INTO t1 VALUES('aaa'); + INSERT INTO t1 VALUES('BBB'); + INSERT INTO t1 VALUES('ccc'); + INSERT INTO t1 VALUES('DDD'); + SELECT a FROM t1 ORDER BY a; + } +} {aaa BBB ccc DDD} +do_test collate8-1.2 { + execsql { + SELECT rowid FROM t1 WHERE a<'ccc' ORDER BY 1 + } +} {1 2} +do_test collate8-1.3 { + execsql { + SELECT rowid FROM t1 WHERE a<'ccc' COLLATE binary ORDER BY 1 + } +} {1 2 4} +do_test collate8-1.4 { + execsql { + SELECT rowid FROM t1 WHERE +a<'ccc' ORDER BY 1 + } +} {1 2} +do_test collate8-1.5 { + execsql { + SELECT a FROM t1 ORDER BY +a + } +} {aaa BBB ccc DDD} +do_test collate8-1.11 { + execsql { + SELECT a AS x FROM t1 ORDER BY "x"; + } +} {aaa BBB ccc DDD} +do_test collate8-1.12 { + execsql { + SELECT a AS x FROM t1 WHERE x<'ccc' ORDER BY 1 + } +} {aaa BBB} +do_test collate8-1.13 { + execsql { + SELECT a AS x FROM t1 WHERE x<'ccc' COLLATE binary ORDER BY [x] + } +} {aaa BBB DDD} +do_test collate8-1.14 { + execsql { + SELECT a AS x FROM t1 WHERE +x<'ccc' ORDER BY 1 + } +} {aaa BBB} +do_test collate8-1.15 { + execsql { + SELECT a AS x FROM t1 ORDER BY +x + } +} {aaa BBB ccc DDD} + + +# When a result-set column is aliased into a WHERE clause, make sure the +# collating sequence logic works correctly. +# +do_test collate8-2.1 { + execsql { + CREATE TABLE t2(a); + INSERT INTO t2 VALUES('abc'); + INSERT INTO t2 VALUES('ABC'); + SELECT a AS x FROM t2 WHERE x='abc'; + } +} {abc} +do_test collate8-2.2 { + execsql { + SELECT a AS x FROM t2 WHERE x='abc' COLLATE nocase; + } +} {abc ABC} +do_test collate8-2.3 { + execsql { + SELECT a AS x FROM t2 WHERE (x COLLATE nocase)='abc'; + } +} {abc ABC} +do_test collate8-2.4 { + execsql { + SELECT a COLLATE nocase AS x FROM t2 WHERE x='abc'; + } +} {abc ABC} +do_test collate8-2.5 { + execsql { + SELECT a COLLATE nocase AS x FROM t2 WHERE (x COLLATE binary)='abc'; + } +} {abc} +do_test collate8-2.6 { + execsql { + SELECT a COLLATE nocase AS x FROM t2 WHERE x='abc' COLLATE binary; + } +} {abc ABC} +do_test collate8-2.7 { + execsql { + SELECT * FROM t2 WHERE (a COLLATE nocase)='abc' COLLATE binary; + } +} {abc ABC} +do_test collate8-2.8 { + execsql { + SELECT a COLLATE nocase AS x FROM t2 WHERE 'abc'=x COLLATE binary; + } +} {abc} + +# Make sure the COLLATE operator perculates up through function calls +# and other Expr structures that use the Expr.x.pList field. +# +do_execsql_test collate8-3.1 { + SELECT 'abc'==('ABC'||'') COLLATE nocase; + SELECT 'abc'==('ABC'||'' COLLATE nocase); + SELECT 'abc'==('ABC'||('' COLLATE nocase)); + SELECT 'abc'==('ABC'||upper('' COLLATE nocase)); +} {1 1 1 1} +do_execsql_test collate8-3.2 { + SELECT 'abc'==('ABC'||max('' COLLATE nocase,'' COLLATE binary)); +} {1} + +# The COLLATE binary is on the left and so takes precedence +do_execsql_test collate8-3.3 { + SELECT 'abc'==('ABC'||max('' COLLATE binary,'' COLLATE nocase)); +} {0} + +do_execsql_test collate8-3.4 { + SELECT 'abc'==('ABC'||CASE WHEN 1-1=2 THEN '' COLLATE nocase + ELSE '' COLLATE binary END); + SELECT 'abc'==('ABC'||CASE WHEN 1+1=2 THEN '' COLLATE nocase + ELSE '' COLLATE binary END); +} {1 1} +do_execsql_test collate8-3.5 { + SELECT 'abc'==('ABC'||CASE WHEN 1=2 THEN '' COLLATE binary + ELSE '' COLLATE nocase END); +} {0} + + +finish_test diff --git a/test/collate9.test b/test/collate9.test new file mode 100644 index 0000000..5a07773 --- /dev/null +++ b/test/collate9.test @@ -0,0 +1,178 @@ +# +# 2007 November 12 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script is making sure that the names of collation +# sequences may be quoted using double quotes in SQL statements. +# +# $Id: collate9.test,v 1.2 2008/07/10 00:32:42 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +proc reverse_sort {lhs rhs} { + return [string compare $rhs $lhs] +} +db collate "reverse sort" reverse_sort + +# This procedure executes the SQL. Then it checks to see if the OP_Sort +# opcode was executed. If an OP_Sort did occur, then "sort" is appended +# to the result. If no OP_Sort happened, then "nosort" is appended. +# +# This procedure is used to check to make sure sorting is or is not +# occurring as expected. +# +proc cksort {sql} { + set ::sqlite_sort_count 0 + set data [execsql $sql] + if {$::sqlite_sort_count} {set x sort} {set x nosort} + lappend data $x + return $data +} + +# Test plan: +# +# collate9-1.* - Test collation sequences attached to table columns +# collate9-2.* - Test collation sequences attached to expressions +# collate9-3.* - Test collation sequences attached to an index +# collate9-4.* - Test collation sequences as an argument to REINDEX +# + +do_test collate9-1.1 { + execsql { + CREATE TABLE xy(x COLLATE "reverse sort", y COLLATE binary); + INSERT INTO xy VALUES('one', 'one'); + INSERT INTO xy VALUES('two', 'two'); + INSERT INTO xy VALUES('three', 'three'); + } +} {} +do_test collate9-1.2 { + execsql { + SELECT x FROM xy ORDER BY x + } +} {two three one} +do_test collate9-1.3 { + execsql { + SELECT y FROM xy ORDER BY y + } +} {one three two} +do_test collate9-1.4 { + cksort { + SELECT x FROM xy ORDER BY x + } +} {two three one sort} +do_test collate9-1.5 { + execsql { + CREATE INDEX xy_i ON xy(x) + } +} {} +do_test collate9-1.6 { + cksort { + SELECT x FROM xy ORDER BY x + } +} {two three one nosort} + +do_test collate9-2.1 { + execsql { + SELECT x, x < 'seven' FROM xy ORDER BY x + } +} {two 1 three 1 one 0} +do_test collate9-2.2 { + execsql { + SELECT y, y < 'seven' FROM xy ORDER BY x + } +} {two 0 three 0 one 1} +do_test collate9-2.3 { + execsql { + SELECT y, y COLLATE "reverse sort" < 'seven' FROM xy ORDER BY x + } +} {two 1 three 1 one 0} +do_test collate9-2.4 { + execsql { + SELECT y FROM xy ORDER BY y + } +} {one three two} +do_test collate9-2.5 { + execsql { + SELECT y FROM xy ORDER BY y COLLATE "reverse sort" + } +} {two three one} +do_test collate9-2.6 { + execsql { + SELECT y COLLATE "reverse sort" AS aaa FROM xy ORDER BY aaa + } +} {two three one} + +do_test collate9-3.1 { + execsql { + CREATE INDEX xy_i2 ON xy(y COLLATE "reverse sort"); + } +} {} +do_test collate9-3.2 { + cksort { + SELECT y FROM xy ORDER BY y + } +} {one three two sort} +do_test collate9-3.3 { + cksort { + SELECT y FROM xy ORDER BY y COLLATE "reverse sort" + } +} {two three one nosort} +do_test collate9-3.4 { + cksort { + SELECT y AS aaa FROM xy ORDER BY aaa + } +} {one three two sort} +do_test collate9-3.5 { + cksort { + SELECT y COLLATE "reverse sort" AS aaa FROM xy ORDER BY aaa + } +} {two three one nosort} + +ifcapable reindex { + do_test collate9-4.1 { + execsql { + REINDEX "reverse sort" + } + } {} + + # Modify the "reverse sort" collation so that it now sorts in the same + # order as binary. + proc reverse_sort {lhs rhs} { + return [string compare $lhs $rhs] + } + + # The integrity check should now fail because the indexes created using + # "reverse sort" are no longer in sync with the collation sequence + # implementation. + do_test collate9-4.2 { + expr {"ok" eq [execsql { PRAGMA integrity_check }]} + } {0} + + do_test collate9-4.3 { + execsql { + REINDEX "reverse sort" + } + } {} + + # Integrity check should now pass. + do_test collate9-4.4 { + expr {"ok" eq [execsql { PRAGMA integrity_check }]} + } {1} + + do_test collate9-4.5 { + cksort { + SELECT x FROM xy ORDER BY x COLLATE "reverse sort" + } + } {one three two nosort} +} + +finish_test diff --git a/test/collateA.test b/test/collateA.test new file mode 100644 index 0000000..3f7ebd9 --- /dev/null +++ b/test/collateA.test @@ -0,0 +1,217 @@ +# +# 2008 January 20 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script is the built-in RTRIM collating +# API. +# +# $Id: collateA.test,v 1.3 2008/04/15 04:02:41 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +do_test collateA-1.1 { + execsql { + CREATE TABLE t1( + a INTEGER PRIMARY KEY, + b TEXT COLLATE BINARY, + c TEXT COLLATE RTRIM + ); + INSERT INTO t1 VALUES(1, 'abcde','abcde'); + INSERT INTO t1 VALUES(2, 'xyzzy ','xyzzy '); + INSERT INTO t1 VALUES(3, 'xyzzy ','xyzzy '); + INSERT INTO t1 VALUES(4, 'xyzzy ','xyzzy '); + INSERT INTO t1 VALUES(5, ' ', ' '); + INSERT INTO t1 VALUES(6, '', ''); + SELECT count(*) FROM t1; + } +} {6} +do_test collateA-1.2 { + execsql {SELECT a FROM t1 WHERE b='abcde '} +} {} +do_test collateA-1.3 { + execsql {SELECT a FROM t1 WHERE c='abcde '} +} {1} +do_test collateA-1.4 { + execsql {SELECT a FROM t1 WHERE b='xyzzy'} +} {} +do_test collateA-1.5 { + execsql {SELECT a FROM t1 WHERE c='xyzzy'} +} {2 3 4} +do_test collateA-1.6 { + execsql {SELECT a FROM t1 WHERE c='xyzzy '} +} {2 3 4} +do_test collateA-1.7 { + execsql {SELECT a FROM t1 WHERE c='xyzzy '} +} {2 3 4} +do_test collateA-1.8 { + execsql {SELECT a FROM t1 WHERE c='xyzzy '} +} {2 3 4} +do_test collateA-1.9 { + execsql {SELECT a FROM t1 WHERE c='xyzzy '} +} {2 3 4} +do_test collateA-1.10 { + execsql {SELECT a FROM t1 WHERE c='xyzzy '} +} {2 3 4} +do_test collateA-1.11 { + execsql {SELECT 'abc123'='abc123 ' COLLATE RTRIM;} +} {1} +do_test collateA-1.12 { + execsql {SELECT 'abc123 '='abc123' COLLATE RTRIM;} +} {1} +do_test collateA-1.13 { + execsql {SELECT ' '='' COLLATE RTRIM, ' '='' COLLATE BINARY, ' '=''} +} {1 0 0} +do_test collateA-1.14 { + execsql {SELECT ''=' ' COLLATE RTRIM, ''=' ' COLLATE BINARY, ''=' '} +} {1 0 0} +do_test collateA-1.15 { + execsql {SELECT ' '=' ' COLLATE RTRIM, ' '=' '} +} {1 0} +do_test collateA-1.16 { + execsql {SELECT ''<>' ' COLLATE RTRIM, ''<>' ' COLLATE BINARY, ''<>' '} +} {0 1 1} +do_test collateA-1.17 { + execsql {SELECT a FROM t1 WHERE c='xyzz'} +} {} +do_test collateA-1.18 { + execsql {SELECT a FROM t1 WHERE c='xyzzyy '} +} {} +do_test collateA-1.19 { + execsql {SELECT a FROM t1 WHERE c='xyzz '} +} {} +do_test collateA-1.20 { + execsql {SELECT a FROM t1 WHERE c='abcd '} +} {} +do_test collateA-1.21 { + execsql {SELECT a FROM t1 WHERE c='abcd'} +} {} +do_test collateA-1.22 { + execsql {SELECT a FROM t1 WHERE c='abc'} +} {} +do_test collateA-1.23 { + execsql {SELECT a FROM t1 WHERE c='abcdef '} +} {} +do_test collateA-1.24 { + execsql {SELECT a FROM t1 WHERE c=''} +} {5 6} +do_test collateA-1.25 { + execsql {SELECT a FROM t1 WHERE c=' '} +} {5 6} +do_test collateA-1.26 { + execsql {SELECT a FROM t1 WHERE c=' '} +} {5 6} + + +do_test collateA-2.1 { + execsql { + CREATE INDEX i1b ON t1(b); + CREATE INDEX i1c ON t1(c); + PRAGMA integrity_check; + } +} {ok} +do_test collateA-2.2 { + execsql {SELECT a FROM t1 WHERE b='abcde '} +} {} +do_test collateA-2.3 { + execsql {SELECT a FROM t1 WHERE c='abcde '} +} {1} +do_test collateA-2.4 { + execsql {SELECT a FROM t1 WHERE b='xyzzy'} +} {} +do_test collateA-2.5 { + execsql {SELECT a FROM t1 WHERE c='xyzzy'} +} {2 3 4} +do_test collateA-2.6 { + execsql {SELECT a FROM t1 WHERE c='xyzzy '} +} {2 3 4} +do_test collateA-2.7 { + execsql {SELECT a FROM t1 WHERE c='xyzzy '} +} {2 3 4} +do_test collateA-2.8 { + execsql {SELECT a FROM t1 WHERE c='xyzzy '} +} {2 3 4} +do_test collateA-2.9 { + execsql {SELECT a FROM t1 WHERE c='xyzzy '} +} {2 3 4} +do_test collateA-2.10 { + execsql {SELECT a FROM t1 WHERE c='xyzzy '} +} {2 3 4} +do_test collateA-2.17 { + execsql {SELECT a FROM t1 WHERE c='xyzz'} +} {} +do_test collateA-2.18 { + execsql {SELECT a FROM t1 WHERE c='xyzzyy '} +} {} +do_test collateA-2.19 { + execsql {SELECT a FROM t1 WHERE c='xyzz '} +} {} +do_test collateA-2.20 { + execsql {SELECT a FROM t1 WHERE c='abcd '} +} {} +do_test collateA-2.21 { + execsql {SELECT a FROM t1 WHERE c='abcd'} +} {} +do_test collateA-2.22 { + execsql {SELECT a FROM t1 WHERE c='abc'} +} {} +do_test collateA-2.23 { + execsql {SELECT a FROM t1 WHERE c='abcdef '} +} {} +do_test collateA-2.24 { + execsql {SELECT a FROM t1 WHERE c=''} +} {5 6} +do_test collateA-2.25 { + execsql {SELECT a FROM t1 WHERE c=' '} +} {5 6} +do_test collateA-2.26 { + execsql {SELECT a FROM t1 WHERE c=' '} +} {5 6} + + +do_test collateA-3.1 { + db close + sqlite3 db test.db + execsql { + REINDEX; + PRAGMA integrity_check; + } +} {ok} +do_test collateA-3.2 { + execsql {SELECT a FROM t1 WHERE b='abcde '} +} {} +do_test collateA-3.3 { + execsql {SELECT a FROM t1 WHERE c='abcde '} +} {1} +do_test collateA-3.4 { + execsql {SELECT a FROM t1 WHERE b='xyzzy'} +} {} +do_test collateA-3.5 { + execsql {SELECT a FROM t1 WHERE c='xyzzy'} +} {2 3 4} +do_test collateA-3.6 { + execsql {SELECT a FROM t1 WHERE c='xyzzy '} +} {2 3 4} +do_test collateA-3.7 { + execsql {SELECT a FROM t1 WHERE c='xyzzy '} +} {2 3 4} +do_test collateA-3.8 { + execsql {SELECT a FROM t1 WHERE c='xyzzy '} +} {2 3 4} +do_test collateA-3.9 { + execsql {SELECT a FROM t1 WHERE c='xyzzy '} +} {2 3 4} +do_test collateA-3.10 { + execsql {SELECT a FROM t1 WHERE c='xyzzy '} +} {2 3 4} + + +finish_test diff --git a/test/collateB.test b/test/collateB.test new file mode 100644 index 0000000..3c8d50d --- /dev/null +++ b/test/collateB.test @@ -0,0 +1,77 @@ +# 2016-07-01 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# Test cases for a crash bug. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix collateB + +do_execsql_test collateB-1.1 { + CREATE TABLE t1(a INTEGER PRIMARY KEY); + CREATE TABLE t2(b INTEGER PRIMARY KEY, x1 INT COLLATE NOCASE); + CREATE TABLE t3(x2 INT); + SELECT * FROM t3, t2, t1 WHERE x2=b AND x1=a AND a=1; +} {} +do_execsql_test collateB-1.2 { + INSERT INTO t1(a) VALUES(1),(2),(3); + INSERT INTO t2(b,x1) VALUES(11,1),(22,2),(33,3); + INSERT INTO t3(x2) VALUES(11),(22),(33); + SELECT *,'|' FROM t3, t2, t1 WHERE x2=b AND x1=a AND a=1; +} {11 11 1 1 |} +do_execsql_test collateB-1.3 { + SELECT *,'|' FROM t3, t1, t2 WHERE x2=b AND x1=a AND a=1; +} {11 1 11 1 |} +do_execsql_test collateB-1.4 { + SELECT *,'|' FROM t2, t3, t1 WHERE x2=b AND x1=a AND a=1; +} {11 1 11 1 |} +do_execsql_test collateB-1.5 { + SELECT *,'|' FROM t2, t1, t3 WHERE x2=b AND x1=a AND a=1; +} {11 1 1 11 |} +do_execsql_test collateB-1.6 { + SELECT *,'|' FROM t1, t2, t3 WHERE x2=b AND x1=a AND a=1; +} {1 11 1 11 |} +do_execsql_test collateB-1.7 { + SELECT *,'|' FROM t1, t2, t3 WHERE x2=b AND x1=a AND a=1; +} {1 11 1 11 |} +do_execsql_test collateB-1.12 { + SELECT *,'|' FROM t3, t2, t1 WHERE b=x2 AND a=x1 AND 1=a; +} {11 11 1 1 |} +do_execsql_test collateB-1.13 { + SELECT *,'|' FROM t3, t1, t2 WHERE b=x2 AND a=x1 AND 1=a; +} {11 1 11 1 |} +do_execsql_test collateB-1.14 { + SELECT *,'|' FROM t2, t3, t1 WHERE b=x2 AND a=x1 AND 1=a; +} {11 1 11 1 |} +do_execsql_test collateB-1.15 { + SELECT *,'|' FROM t2, t1, t3 WHERE b=x2 AND a=x1 AND 1=a; +} {11 1 1 11 |} +do_execsql_test collateB-1.16 { + SELECT *,'|' FROM t1, t2, t3 WHERE b=x2 AND a=x1 AND 1=a; +} {1 11 1 11 |} +do_execsql_test collateB-1.17 { + SELECT *,'|' FROM t1, t2, t3 WHERE b=x2 AND a=x1 AND 1=a; +} {1 11 1 11 |} + +#------------------------------------------------------------------------- +# Test an assert() failure that was occuring if an index were created +# on a column explicitly declared "COLLATE binary". +reset_db +do_execsql_test 2.1 { + CREATE TABLE t4(a COLLATE binary); + CREATE INDEX i4 ON t4(a); + INSERT INTO t4 VALUES('one'), ('two'), ('three'); + VACUUM; +} + +integrity_check 2.2 + +finish_test diff --git a/test/colmeta.test b/test/colmeta.test new file mode 100644 index 0000000..21b0e0f --- /dev/null +++ b/test/colmeta.test @@ -0,0 +1,110 @@ +# +# 2006 February 9 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script is the sqlite3_table_column_metadata() API. +# +# $Id: colmeta.test,v 1.4 2008/01/23 12:52:41 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Set up a schema in the main and temp test databases. +do_test colmeta-0 { + execsql { + CREATE TABLE abc(a, b, c); + CREATE TABLE abc2(a PRIMARY KEY COLLATE NOCASE, b VARCHAR(32), c); + CREATE TABLE abc3(a NOT NULL, b INTEGER PRIMARY KEY, c); + CREATE TABLE abc5(w,x,y,z,PRIMARY KEY(x,z)) WITHOUT ROWID; + CREATE TABLE abc6(rowid TEXT COLLATE rtrim, oid REAL, _rowid_ BLOB); + } + ifcapable autoinc { + execsql { + CREATE TABLE abc4(a, b INTEGER PRIMARY KEY AUTOINCREMENT, c); + } + } + ifcapable view { + execsql { + CREATE VIEW v1 AS SELECT * FROM abc2; + } + } +} {} + + +# Return values are of the form: +# +# { } +# +set tests { + 1 {main abc a} {0 {{} BINARY 0 0 0}} + 2 {{} abc a} {0 {{} BINARY 0 0 0}} + 3 {{} abc2 b} {0 {VARCHAR(32) BINARY 0 0 0}} + 4 {main abc2 b} {0 {VARCHAR(32) BINARY 0 0 0}} + 5 {{} abc2 a} {0 {{} NOCASE 0 1 0}} + 6 {{} abc3 a} {0 {{} BINARY 1 0 0}} + 7 {{} abc3 b} {0 {INTEGER BINARY 0 1 0}} + 13 {main abc rowid} {0 {INTEGER BINARY 0 1 0}} + 14 {main abc3 rowid} {0 {INTEGER BINARY 0 1 0}} + 16 {main abc d} {1 {no such table column: abc.d}} + 20 {main abc5 w} {0 {{} BINARY 0 0 0}} + 21 {main abc5 x} {0 {{} BINARY 1 1 0}} + 22 {main abc5 y} {0 {{} BINARY 0 0 0}} + 23 {main abc5 z} {0 {{} BINARY 1 1 0}} + 24 {main abc5 rowid} {1 {no such table column: abc5.rowid}} + 30 {main abc6 rowid} {0 {TEXT rtrim 0 0 0}} + 31 {main abc6 oid} {0 {REAL BINARY 0 0 0}} + 32 {main abc6 _rowid_} {0 {BLOB BINARY 0 0 0}} +} +ifcapable autoinc { + set tests [concat $tests { + 100 {{} abc4 b} {0 {INTEGER BINARY 0 1 1}} + 101 {main abc4 rowid} {0 {INTEGER BINARY 0 1 1}} + }] +} +ifcapable view { + set tests [concat $tests { + 200 {{} v1 a} {1 {no such table column: v1.a}} + 201 {main v1 b} {1 {no such table column: v1.b}} + 202 {main v1 badname} {1 {no such table column: v1.badname}} + 203 {main v1 rowid} {1 {no such table column: v1.rowid}} + }] +} + +foreach {tn params results} $tests { + set ::DB [sqlite3_connection_pointer db] + + set tstbody [concat sqlite3_table_column_metadata $::DB $params] + do_test colmeta-$tn.1 { + list [catch $tstbody msg] [set msg] + } $results + + db close + sqlite3 db test.db + + set ::DB [sqlite3_connection_pointer db] + set tstbody [concat sqlite3_table_column_metadata $::DB $params] + do_test colmeta-$tn.2 { + list [catch $tstbody msg] [set msg] + } $results +} + +# Calling sqlite3_table_column_metadata with a NULL column name merely +# checks for the existance of the table. +# +do_test colmeta-300 { + catch {sqlite3_table_column_metadata $::DB main xyzzy} res +} {1} +do_test colmeta-301 { + catch {sqlite3_table_column_metadata $::DB main abc} res +} {0} + + +finish_test diff --git a/test/colname.test b/test/colname.test new file mode 100644 index 0000000..5fa0b60 --- /dev/null +++ b/test/colname.test @@ -0,0 +1,447 @@ +# 2008 July 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# The focus of this file is testing how SQLite generates the names +# of columns in a result set. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Rules (applied in order): +# +# (1) If there is an AS clause, use it. +# +# (2) A non-trival expression (not a table column name) then the name is +# a copy of the expression text. +# +# (3) If short_column_names=ON, then just the abbreviated column name without +# the table name. +# +# (4) When short_column_names=OFF and full_column_names=OFF then +# use case (2) for simple queries and case (5) for joins. +# +# (5) When short_column_names=OFF and full_column_names=ON then +# use the form: TABLE.COLUMN +# + + +# Verify the default settings for short_column_name and full_column_name +# +do_test colname-1.1 { + db eval {PRAGMA short_column_names} +} {1} +do_test colname-1.2 { + db eval {PRAGMA full_column_names} +} {0} + +# Tests for then short=ON and full=any +# +do_test colname-2.1 { + db eval { + CREATE TABLE tabc(a,b,c); + INSERT INTO tabc VALUES(1,2,3); + CREATE TABLE txyz(x,y,z); + INSERT INTO txyz VALUES(4,5,6); + CREATE TABLE tboth(a,b,c,x,y,z); + INSERT INTO tboth VALUES(11,12,13,14,15,16); + CREATE VIEW v1 AS SELECT tabC.a, txyZ.x, * + FROM tabc, txyz ORDER BY 1 LIMIT 1; + CREATE VIEW v2 AS SELECT tabC.a, txyZ.x, tboTh.a, tbotH.x, * + FROM tabc, txyz, tboth ORDER BY 1 LIMIT 1; + } + execsql2 { + SELECT * FROM tabc; + } +} {a 1 b 2 c 3} +do_test colname-2.2 { + execsql2 { + SELECT Tabc.a, tAbc.b, taBc.c, * FROM tabc + } +} {a 1 b 2 c 3 a 1 b 2 c 3} +do_test colname-2.3 { + execsql2 { + SELECT +tabc.a, -tabc.b, tabc.c, * FROM tabc + } +} {+tabc.a 1 -tabc.b -2 c 3 a 1 b 2 c 3} +do_test colname-2.4 { + execsql2 { + SELECT +tabc.a AS AAA, -tabc.b AS BBB, tabc.c CCC, * FROM tabc + } +} {AAA 1 BBB -2 CCC 3 a 1 b 2 c 3} +do_test colname-2.5 { + execsql2 { + SELECT tabc.a, txyz.x, * FROM tabc, txyz; + } +} {a 1 x 4 a 1 b 2 c 3 x 4 y 5 z 6} +do_test colname-2.6 { + execsql2 { + SELECT tabc.a, txyz.x, tabc.*, txyz.* FROM tabc, txyz; + } +} {a 1 x 4 a 1 b 2 c 3 x 4 y 5 z 6} +do_test colname-2.7 { + execsql2 { + SELECT tabc.a, txyz.x, tboth.a, tboth.x, * FROM tabc, txyz, tboth; + } +} {a 11 x 14 a 11 x 14 a 11 b 12 c 13 x 14 y 15 z 16 a 11 b 12 c 13 x 14 y 15 z 16} +do_test colname-2.8 { + execsql2 { + SELECT * FROM v1 ORDER BY 2; + } +} {a 1 x 4 a:1 1 b 2 c 3 x:1 4 y 5 z 6} +do_test colname-2.9 { + execsql2 { + SELECT * FROM v2 ORDER BY 2; + } +} {a 1 x 4 a:1 11 x:1 14 a:2 1 b 2 c 3 x:2 4 y 5 z 6 a:3 11 b:1 12 c:1 13 x:3 14 y:1 15 z:1 16} + + +# Tests for short=OFF and full=OFF +# +do_test colname-3.1 { + db eval { + PRAGMA short_column_names=OFF; + PRAGMA full_column_names=OFF; + CREATE VIEW v3 AS SELECT tabC.a, txyZ.x, * + FROM tabc, txyz ORDER BY 1 LIMIT 1; + CREATE VIEW v4 AS SELECT tabC.a, txyZ.x, tboTh.a, tbotH.x, * + FROM tabc, txyz, tboth ORDER BY 1 LIMIT 1; + } + execsql2 { + SELECT * FROM tabc; + } +} {a 1 b 2 c 3} +do_test colname-3.2 { + execsql2 { + SELECT Tabc.a, tAbc.b, taBc.c FROM tabc + } +} {Tabc.a 1 tAbc.b 2 taBc.c 3} +do_test colname-3.3 { + execsql2 { + SELECT +tabc.a, -tabc.b, tabc.c FROM tabc + } +} {+tabc.a 1 -tabc.b -2 tabc.c 3} +do_test colname-3.4 { + execsql2 { + SELECT +tabc.a AS AAA, -tabc.b AS BBB, tabc.c CCC FROM tabc + } +} {AAA 1 BBB -2 CCC 3} +do_test colname-3.5 { + execsql2 { + SELECT Tabc.a, Txyz.x, * FROM tabc, txyz; + } +} {Tabc.a 1 Txyz.x 4 a 1 b 2 c 3 x 4 y 5 z 6} +do_test colname-3.6 { + execsql2 { + SELECT tabc.*, txyz.* FROM tabc, txyz; + } +} {a 1 b 2 c 3 x 4 y 5 z 6} +do_test colname-3.7 { + execsql2 { + SELECT * FROM tabc, txyz, tboth; + } +} {a 11 b 12 c 13 x 14 y 15 z 16 a 11 b 12 c 13 x 14 y 15 z 16} +do_test colname-3.8 { + execsql2 { + SELECT v1.a, * FROM v1 ORDER BY 2; + } +} {v1.a 1 a 1 x 4 a:1 1 b 2 c 3 x:1 4 y 5 z 6} +do_test colname-3.9 { + execsql2 { + SELECT * FROM v2 ORDER BY 2; + } +} {a 1 x 4 a:1 11 x:1 14 a:2 1 b 2 c 3 x:2 4 y 5 z 6 a:3 11 b:1 12 c:1 13 x:3 14 y:1 15 z:1 16} +do_test colname-3.10 { + execsql2 { + SELECT * FROM v3 ORDER BY 2; + } +} {a 1 x 4 a:1 1 b 2 c 3 x:1 4 y 5 z 6} +do_test colname-3.11 { + execsql2 { + SELECT * FROM v4 ORDER BY 2; + } +} {a 1 x 4 a:1 11 x:1 14 a:2 1 b 2 c 3 x:2 4 y 5 z 6 a:3 11 b:1 12 c:1 13 x:3 14 y:1 15 z:1 16} + +# Test for short=OFF and full=ON +# +do_test colname-4.1 { + db eval { + PRAGMA short_column_names=OFF; + PRAGMA full_column_names=ON; + CREATE VIEW v5 AS SELECT tabC.a, txyZ.x, * + FROM tabc, txyz ORDER BY 1 LIMIT 1; + CREATE VIEW v6 AS SELECT tabC.a, txyZ.x, tboTh.a, tbotH.x, * + FROM tabc, txyz, tboth ORDER BY 1 LIMIT 1; + } + execsql2 { + SELECT * FROM tabc; + } +} {tabc.a 1 tabc.b 2 tabc.c 3} +do_test colname-4.2 { + execsql2 { + SELECT Tabc.a, tAbc.b, taBc.c FROM tabc + } +} {tabc.a 1 tabc.b 2 tabc.c 3} +do_test colname-4.3 { + execsql2 { + SELECT +tabc.a, -tabc.b, tabc.c FROM tabc + } +} {+tabc.a 1 -tabc.b -2 tabc.c 3} +do_test colname-4.4 { + execsql2 { + SELECT +tabc.a AS AAA, -tabc.b AS BBB, tabc.c CCC FROM tabc + } +} {AAA 1 BBB -2 CCC 3} +do_test colname-4.5 { + execsql2 { + SELECT Tabc.a, Txyz.x, * FROM tabc, txyz; + } +} {tabc.a 1 txyz.x 4 tabc.a 1 tabc.b 2 tabc.c 3 txyz.x 4 txyz.y 5 txyz.z 6} +do_test colname-4.6 { + execsql2 { + SELECT tabc.*, txyz.* FROM tabc, txyz; + } +} {tabc.a 1 tabc.b 2 tabc.c 3 txyz.x 4 txyz.y 5 txyz.z 6} +do_test colname-4.7 { + execsql2 { + SELECT * FROM tabc, txyz, tboth; + } +} {tabc.a 1 tabc.b 2 tabc.c 3 txyz.x 4 txyz.y 5 txyz.z 6 tboth.a 11 tboth.b 12 tboth.c 13 tboth.x 14 tboth.y 15 tboth.z 16} +do_test colname-4.8 { + execsql2 { + SELECT * FROM v1 ORDER BY 2; + } +} {v1.a 1 v1.x 4 v1.a:1 1 v1.b 2 v1.c 3 v1.x:1 4 v1.y 5 v1.z 6} +do_test colname-4.9 { + execsql2 { + SELECT * FROM v2 ORDER BY 2; + } +} {v2.a 1 v2.x 4 v2.a:1 11 v2.x:1 14 v2.a:2 1 v2.b 2 v2.c 3 v2.x:2 4 v2.y 5 v2.z 6 v2.a:3 11 v2.b:1 12 v2.c:1 13 v2.x:3 14 v2.y:1 15 v2.z:1 16} +do_test colname-4.10 { + execsql2 { + SELECT * FROM v3 ORDER BY 2; + } +} {v3.a 1 v3.x 4 v3.a:1 1 v3.b 2 v3.c 3 v3.x:1 4 v3.y 5 v3.z 6} +do_test colname-4.11 { + execsql2 { + SELECT * FROM v4 ORDER BY 2; + } +} {v4.a 1 v4.x 4 v4.a:1 11 v4.x:1 14 v4.a:2 1 v4.b 2 v4.c 3 v4.x:2 4 v4.y 5 v4.z 6 v4.a:3 11 v4.b:1 12 v4.c:1 13 v4.x:3 14 v4.y:1 15 v4.z:1 16} +do_test colname-4.12 { + execsql2 { + SELECT * FROM v5 ORDER BY 2; + } +} {v5.a 1 v5.x 4 v5.a:1 1 v5.b 2 v5.c 3 v5.x:1 4 v5.y 5 v5.z 6} +do_test colname-4.13 { + execsql2 { + SELECT * FROM v6 ORDER BY 2; + } +} {v6.a 1 v6.x 4 v6.a:1 11 v6.x:1 14 v6.a:2 1 v6.b 2 v6.c 3 v6.x:2 4 v6.y 5 v6.z 6 v6.a:3 11 v6.b:1 12 v6.c:1 13 v6.x:3 14 v6.y:1 15 v6.z:1 16} + +# ticket #3229 +do_test colname-5.1 { + lreplace [db eval { + SELECT x.* FROM sqlite_master X LIMIT 1; + }] 3 3 x +} {table tabc tabc x {CREATE TABLE tabc(a,b,c)}} + +# ticket #3370, #3371, #3372 +# +do_test colname-6.1 { + db close + sqlite3 db test.db + db eval { + CREATE TABLE t6(a, ['a'], ["a"], "[a]", [`a`]); + INSERT INTO t6 VALUES(1,2,3,4,5); + } + execsql2 {SELECT * FROM t6} +} {a 1 'a' 2 {"a"} 3 {[a]} 4 `a` 5} +do_test colname-6.2 { + execsql2 {SELECT ['a'], [`a`], "[a]", [a], ["a"] FROM t6} +} {'a' 2 `a` 5 {[a]} 4 a 1 {"a"} 3} +do_test colname-6.3 { + execsql2 {SELECT "'a'", "`a`", "[a]", "a", """a""" FROM t6} +} {'a' 2 `a` 5 {[a]} 4 a 1 {"a"} 3} +do_test colname-6.4 { + execsql2 {SELECT `'a'`, ```a```, `[a]`, `a`, `"a"` FROM t6} +} {'a' 2 `a` 5 {[a]} 4 a 1 {"a"} 3} +do_test colname-6.11 { + execsql2 {SELECT a, max(a) AS m FROM t6} +} {a 1 m 1} +do_test colname-6.12 { + execsql2 {SELECT `a`, max(a) AS m FROM t6} +} {a 1 m 1} +do_test colname-6.13 { + execsql2 {SELECT "a", max(a) AS m FROM t6} +} {a 1 m 1} +do_test colname-6.14 { + execsql2 {SELECT [a], max(a) AS m FROM t6} +} {a 1 m 1} +do_test colname-6.15 { + execsql2 {SELECT t6.a, max(a) AS m FROM t6} +} {a 1 m 1} +do_test colname-6.16 { + execsql2 {SELECT ['a'], max(['a']) AS m FROM t6} +} {'a' 2 m 2} +do_test colname-6.17 { + execsql2 {SELECT ["a"], max(["a"]) AS m FROM t6} +} {{"a"} 3 m 3} +do_test colname-6.18 { + execsql2 {SELECT "[a]", max("[a]") AS m FROM t6} +} {{[a]} 4 m 4} +do_test colname-6.19 { + execsql2 {SELECT "`a`", max([`a`]) AS m FROM t6} +} {`a` 5 m 5} + + +# Ticket #3429 +# We cannot find anything wrong, but it never hurts to add another +# test case. +# +do_test colname-7.1 { + db eval { + CREATE TABLE t7(x INTEGER PRIMARY KEY, y); + INSERT INTO t7 VALUES(1,2); + } + execsql2 {SELECT rowid, * FROM t7} +} {x 1 x 1 y 2} + +# Tickets #3893 and #3984. (Same problem; independently reported) +# +do_test colname-8.1 { + db eval { + CREATE TABLE "t3893"("x"); + INSERT INTO t3893 VALUES(123); + SELECT "y"."x" FROM (SELECT "x" FROM "t3893") AS "y"; + } +} {123} + +# 2017-07-29: Interaction between column naming and query flattening. +# For years now, the query flattener has inserted AS clauses on the +# outer query that were the original SQL text of the column. This caused +# column-name shifts when the query flattener was enhanced, breaking +# legacy applications. See https://sqlite.org/src/info/41c27bc0ff1d3135 +# for details. +# +# To fix this, the column naming logic was moved ahead of the query +# flattener so that column names are assigned before the query flattener +# runs. +# +db close +sqlite3 db :memory: +do_test colname-9.100 { + db eval { + CREATE TABLE t1(a,b); + INSERT INTO t1 VALUES(1,2); + CREATE VIEW v1(x,y) AS SELECT a,b FROM t1; + } + execsql2 {SELECT v1.x, (Y) FROM v1} + # Prior to the fix, this would return: "v1.x 1 (Y) 2" +} {x 1 y 2} +do_test colname-9.110 { + execsql2 {SELECT * FROM v1} +} {x 1 y 2} +do_test colname-9.120 { + db eval { + CREATE VIEW v2(x,y) AS SELECT a,b FROM t1 LIMIT 10; + } + execsql2 {SELECT * FROM v2 WHERE 1} +} {x 1 y 2} +do_test colname-9.130 { + execsql2 {SELECT v2.x, [v2].[y] FROM v2 WHERE 1} +} {x 1 y 2} +do_test colname-9.140 { + execsql2 {SELECT +x, +y FROM v2 WHERE 1} +} {+x 1 +y 2} + +do_test colname-9.200 { + db eval { + CREATE TABLE t2(c,d); + INSERT INTO t2 VALUES(3,4); + CREATE VIEW v3 AS SELECT c AS a, d AS b FROM t2; + } + execsql2 {SELECT t1.a, v3.a AS n FROM t1 LEFT JOIN v3} +} {a 1 n 3} +do_test colname-9.211 { + execsql2 {SELECT t1.a AS n, v3.a FROM t1 JOIN v3} +} {n 1 a 3} +do_test colname-9.210 { + execsql2 {SELECT t1.a, v3.a AS n FROM t1 JOIN v3} +} {a 1 n 3} + +# 2017-12-23: Ticket https://www.sqlite.org/src/info/3b4450072511e621 +# Inconsistent column names in CREATE TABLE AS +# +# Verify that the names of columns in the created table of a CREATE TABLE AS +# are the same as the names of result columns in the SELECT statement. +# +do_execsql_test colname-9.300 { + DROP TABLE IF EXISTS t1; + DROP TABLE IF EXISTS t2; + CREATE TABLE t1(aaa INT); + INSERT INTO t1(aaa) VALUES(123); +} +do_test colname-9.310 { + execsql2 {SELECT BBb FROM (SELECT aaa AS Bbb FROM t1)} +} {Bbb 123} +ifcapable vtab { + do_execsql_test colname-9.320 { + CREATE TABLE t2 AS SELECT BBb FROM (SELECT aaa AS Bbb FROM t1); + SELECT name FROM pragma_table_info('t2'); + } {Bbb} +} +do_execsql_test colname-9.330 { -- added 2019-08-10 to invalidate + DROP TABLE IF EXISTS t1; -- a couple assert()s that were + CREATE TABLE t1(a); -- added by ticket 3b44500725 + INSERT INTO t1 VALUES(17),(2),(99),(-3),(7); + SELECT (SELECT avg(a) UNION SELECT min(a) OVER()) FROM t1; +} {17} + +# Issue detected by OSSFuzz on 2017-12-24 (Christmas Eve) +# caused by check-in https://sqlite.org/src/info/6b2ff26c25 +# +# Prior to being fixed, the following CREATE TABLE was dereferencing +# a NULL pointer and segfaulting. +# +do_catchsql_test colname-9.400 { + CREATE TABLE t4 AS SELECT #0; +} {1 {near "#0": syntax error}} + +# Issue detected by OSSFuzz on 2017-12-25 (Christmas Day) +# also caused by check-in https://sqlite.org/src/info/6b2ff26c25 +# +# Prior to being fixed, the following CREATE TABLE caused an +# assertion fault. +# +do_catchsql_test colname-9.410 { + CREATE TABLE t5 AS SELECT RAISE(abort,a); +} {1 {RAISE() may only be used within a trigger-program}} + +# Make sure the quotation marks get removed from the column names +# when constructing a new table from an aggregate SELECT. +# Email from Juergen Palm on 2017-07-11. +# +do_execsql_test colname-10.100 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1("with space" TEXT); + DROP TABLE IF EXISTS t2; + CREATE TABLE t2 AS SELECT "with space" FROM t1; + PRAGMA table_info(t2); +} {0 {with space} TEXT 0 {} 0} +do_execsql_test colname-10.110 { + DROP TABLE IF EXISTS t3; + CREATE TABLE t3 AS SELECT "with space" FROM t1 GROUP BY 1; + PRAGMA table_info(t3); +} {0 {with space} TEXT 0 {} 0} + + +finish_test diff --git a/test/columncount.test b/test/columncount.test new file mode 100644 index 0000000..d9956b4 --- /dev/null +++ b/test/columncount.test @@ -0,0 +1,62 @@ +# 2021 February 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing the sqlite3_column_count() API. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix columncount + +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. +ifcapable !altertable { + finish_test + return +} + +proc do_ccsql_test {tn sql res} { + + uplevel [list do_test $tn [subst -nocommands { + set stmt [sqlite3_prepare_v2 db {$sql} -1 dummy] + set res [sqlite3_column_count [set stmt]] + while {[sqlite3_step [set stmt]]=="SQLITE_ROW"} { + for {set i 0} {[set i] < [sqlite3_data_count [set stmt]]} {incr i} { + lappend res [sqlite3_column_text [set stmt] [set i]] + } + } + + set rc [sqlite3_finalize [set stmt]] + if {[set rc]!="SQLITE_OK"} { + error [sqlite3_errmsg db] + } + + set res + }] [list {*}$res]] + +} + +do_execsql_test 1.0 { + CREATE TABLE t1(x, y, z); + INSERT INTO t1 VALUES('a', 'b', 'c'); +} + +do_ccsql_test 1.1 { SELECT * FROM t1 } {3 a b c} +do_ccsql_test 1.2 { CREATE TABLE t2(a, b) } {0} + +do_ccsql_test 1.3 { ALTER TABLE t2 RENAME TO t3 } {0} +do_ccsql_test 1.4 { ALTER TABLE t3 RENAME b TO ccc } {0} +do_ccsql_test 1.5 { ALTER TABLE t3 ADD COLUMN d } {0} + +do_ccsql_test 1.6 { DROP TABLE t3 } {0} + + + +finish_test diff --git a/test/conflict.test b/test/conflict.test new file mode 100644 index 0000000..ba3ad9b --- /dev/null +++ b/test/conflict.test @@ -0,0 +1,891 @@ +# 2002 January 29 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests for the conflict resolution extension +# to SQLite. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !conflict { + finish_test + return +} + +# Create tables for the first group of tests. +# +do_test conflict-1.0 { + execsql { + CREATE TABLE t1(a, b, c, UNIQUE(a,b)); + CREATE TABLE t2(x); + SELECT c FROM t1 ORDER BY c; + } +} {} + +# Six columns of configuration data as follows: +# +# i The reference number of the test +# cmd An INSERT or REPLACE command to execute against table t1 +# t0 True if there is an error from $cmd +# t1 Content of "c" column of t1 assuming no error in $cmd +# t2 Content of "x" column of t2 +# t3 Number of temporary files created by this test +# +foreach {i cmd t0 t1 t2 t3} { + 1 INSERT 1 {} 1 0 + 2 {INSERT OR IGNORE} 0 3 1 0 + 3 {INSERT OR REPLACE} 0 4 1 0 + 4 REPLACE 0 4 1 0 + 5 {INSERT OR FAIL} 1 {} 1 0 + 6 {INSERT OR ABORT} 1 {} 1 0 + 7 {INSERT OR ROLLBACK} 1 {} {} 0 +} { + do_test conflict-1.$i { + set ::sqlite_opentemp_count 0 + set r0 [catch {execsql [subst { + DELETE FROM t1; + DELETE FROM t2; + INSERT INTO t1 VALUES(1,2,3); + BEGIN; + INSERT INTO t2 VALUES(1); + $cmd INTO t1 VALUES(1,2,4); + }]} r1] + catch {execsql {COMMIT}} + if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]} + set r2 [execsql {SELECT x FROM t2}] + set r3 $::sqlite_opentemp_count + list $r0 $r1 $r2 $r3 + } [list $t0 $t1 $t2 $t3] +} + +# Create tables for the first group of tests. +# +do_test conflict-2.0 { + execsql { + DROP TABLE t1; + DROP TABLE t2; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, UNIQUE(a,b)); + CREATE TABLE t2(x); + SELECT c FROM t1 ORDER BY c; + } +} {} + +# Six columns of configuration data as follows: +# +# i The reference number of the test +# cmd An INSERT or REPLACE command to execute against table t1 +# t0 True if there is an error from $cmd +# t1 Content of "c" column of t1 assuming no error in $cmd +# t2 Content of "x" column of t2 +# +foreach {i cmd t0 t1 t2} { + 1 INSERT 1 {} 1 + 2 {INSERT OR IGNORE} 0 3 1 + 3 {INSERT OR REPLACE} 0 4 1 + 4 REPLACE 0 4 1 + 5 {INSERT OR FAIL} 1 {} 1 + 6 {INSERT OR ABORT} 1 {} 1 + 7 {INSERT OR ROLLBACK} 1 {} {} +} { + do_test conflict-2.$i { + set r0 [catch {execsql [subst { + DELETE FROM t1; + DELETE FROM t2; + INSERT INTO t1 VALUES(1,2,3); + BEGIN; + INSERT INTO t2 VALUES(1); + $cmd INTO t1 VALUES(1,2,4); + }]} r1] + catch {execsql {COMMIT}} + if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]} + set r2 [execsql {SELECT x FROM t2}] + list $r0 $r1 $r2 + } [list $t0 $t1 $t2] +} + +# Create tables for the first group of tests. +# +do_test conflict-3.0 { + execsql { + DROP TABLE t1; + DROP TABLE t2; + CREATE TABLE t1(a, b, c INTEGER, PRIMARY KEY(c), UNIQUE(a,b)); + CREATE TABLE t2(x); + SELECT c FROM t1 ORDER BY c; + } +} {} + +# Six columns of configuration data as follows: +# +# i The reference number of the test +# cmd An INSERT or REPLACE command to execute against table t1 +# t0 True if there is an error from $cmd +# t1 Content of "c" column of t1 assuming no error in $cmd +# t2 Content of "x" column of t2 +# +foreach {i cmd t0 t1 t2} { + 1 INSERT 1 {} 1 + 2 {INSERT OR IGNORE} 0 3 1 + 3 {INSERT OR REPLACE} 0 4 1 + 4 REPLACE 0 4 1 + 5 {INSERT OR FAIL} 1 {} 1 + 6 {INSERT OR ABORT} 1 {} 1 + 7 {INSERT OR ROLLBACK} 1 {} {} +} { + do_test conflict-3.$i { + set r0 [catch {execsql [subst { + DELETE FROM t1; + DELETE FROM t2; + INSERT INTO t1 VALUES(1,2,3); + BEGIN; + INSERT INTO t2 VALUES(1); + $cmd INTO t1 VALUES(1,2,4); + }]} r1] + catch {execsql {COMMIT}} + if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]} + set r2 [execsql {SELECT x FROM t2}] + list $r0 $r1 $r2 + } [list $t0 $t1 $t2] +} + +do_test conflict-4.0 { + execsql { + DROP TABLE t2; + CREATE TABLE t2(x); + SELECT x FROM t2; + } +} {} + +# Six columns of configuration data as follows: +# +# i The reference number of the test +# conf1 The conflict resolution algorithm on the UNIQUE constraint +# cmd An INSERT or REPLACE command to execute against table t1 +# t0 True if there is an error from $cmd +# t1 Content of "c" column of t1 assuming no error in $cmd +# t2 Content of "x" column of t2 +# +foreach {i conf1 cmd t0 t1 t2} { + 1 {} INSERT 1 {} 1 + 2 REPLACE INSERT 0 4 1 + 3 IGNORE INSERT 0 3 1 + 4 FAIL INSERT 1 {} 1 + 5 ABORT INSERT 1 {} 1 + 6 ROLLBACK INSERT 1 {} {} + 7 REPLACE {INSERT OR IGNORE} 0 3 1 + 8 IGNORE {INSERT OR REPLACE} 0 4 1 + 9 FAIL {INSERT OR IGNORE} 0 3 1 + 10 ABORT {INSERT OR REPLACE} 0 4 1 + 11 ROLLBACK {INSERT OR IGNORE } 0 3 1 +} { + do_test conflict-4.$i { + if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"} + set r0 [catch {execsql [subst { + DROP TABLE t1; + CREATE TABLE t1(a,b,c,UNIQUE(a,b) $conf1); + DELETE FROM t2; + INSERT INTO t1 VALUES(1,2,3); + BEGIN; + INSERT INTO t2 VALUES(1); + $cmd INTO t1 VALUES(1,2,4); + }]} r1] + catch {execsql {COMMIT}} + if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]} + set r2 [execsql {SELECT x FROM t2}] + list $r0 $r1 $r2 + } [list $t0 $t1 $t2] +} + +do_test conflict-5.0 { + execsql { + DROP TABLE t2; + CREATE TABLE t2(x); + SELECT x FROM t2; + } +} {} + +# Six columns of configuration data as follows: +# +# i The reference number of the test +# conf1 The conflict resolution algorithm on the NOT NULL constraint +# cmd An INSERT or REPLACE command to execute against table t1 +# t0 True if there is an error from $cmd +# t1 Content of "c" column of t1 assuming no error in $cmd +# t2 Content of "x" column of t2 +# +foreach {i conf1 cmd t0 t1 t2} { + 1 {} INSERT 1 {} 1 + 2 REPLACE INSERT 0 5 1 + 3 IGNORE INSERT 0 {} 1 + 4 FAIL INSERT 1 {} 1 + 5 ABORT INSERT 1 {} 1 + 6 ROLLBACK INSERT 1 {} {} + 7 REPLACE {INSERT OR IGNORE} 0 {} 1 + 8 IGNORE {INSERT OR REPLACE} 0 5 1 + 9 FAIL {INSERT OR IGNORE} 0 {} 1 + 10 ABORT {INSERT OR REPLACE} 0 5 1 + 11 ROLLBACK {INSERT OR IGNORE} 0 {} 1 + 12 {} {INSERT OR IGNORE} 0 {} 1 + 13 {} {INSERT OR REPLACE} 0 5 1 + 14 {} {INSERT OR FAIL} 1 {} 1 + 15 {} {INSERT OR ABORT} 1 {} 1 + 16 {} {INSERT OR ROLLBACK} 1 {} {} +} { + if {$t0} {set t1 {NOT NULL constraint failed: t1.c}} + do_test conflict-5.$i { + if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"} + set r0 [catch {execsql [subst { + DROP TABLE t1; + CREATE TABLE t1(a,b,c NOT NULL $conf1 DEFAULT 5); + DELETE FROM t2; + BEGIN; + INSERT INTO t2 VALUES(1); + $cmd INTO t1 VALUES(1,2,NULL); + }]} r1] + catch {execsql {COMMIT}} + if {!$r0} {set r1 [execsql {SELECT c FROM t1}]} + set r2 [execsql {SELECT x FROM t2}] + list $r0 $r1 $r2 + } [list $t0 $t1 $t2] +} + +do_test conflict-6.0 { + execsql { + DROP TABLE t2; + CREATE TABLE t2(a,b,c); + INSERT INTO t2 VALUES(1,2,1); + INSERT INTO t2 VALUES(2,3,2); + INSERT INTO t2 VALUES(3,4,1); + INSERT INTO t2 VALUES(4,5,4); + SELECT c FROM t2 ORDER BY b; + CREATE TABLE t3(x); + INSERT INTO t3 VALUES(1); + } +} {1 2 1 4} + +# Six columns of configuration data as follows: +# +# i The reference number of the test +# conf1 The conflict resolution algorithm on the UNIQUE constraint +# cmd An UPDATE command to execute against table t1 +# t0 True if there is an error from $cmd +# t1 Content of "b" column of t1 assuming no error in $cmd +# t2 Content of "x" column of t3 +# t3 Number of temporary files for tables +# t4 Number of temporary files for statement journals +# +# Update (2007-08-21): Since temporary table files are now opened lazily, +# and none of the following tests use large quantities of data, t3 is always 0. +# +# Update (2016-03-04): Subjournals now also open lazily, so t4 is also always 0. +# +foreach {i conf1 cmd t0 t1 t2 t3 t4} { + 1 {} UPDATE 1 {6 7 8 9} 1 0 0 + 2 REPLACE UPDATE 0 {7 6 9} 1 0 0 + 3 IGNORE UPDATE 0 {6 7 3 9} 1 0 0 + 4 FAIL UPDATE 1 {6 7 3 4} 1 0 0 + 5 ABORT UPDATE 1 {1 2 3 4} 1 0 0 + 6 ROLLBACK UPDATE 1 {1 2 3 4} 0 0 0 + 7 REPLACE {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0 0 + 8 IGNORE {UPDATE OR REPLACE} 0 {7 6 9} 1 0 0 + 9 FAIL {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0 0 + 10 ABORT {UPDATE OR REPLACE} 0 {7 6 9} 1 0 0 + 11 ROLLBACK {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0 0 + 12 {} {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0 0 + 13 {} {UPDATE OR REPLACE} 0 {7 6 9} 1 0 0 + 14 {} {UPDATE OR FAIL} 1 {6 7 3 4} 1 0 0 + 15 {} {UPDATE OR ABORT} 1 {1 2 3 4} 1 0 0 + 16 {} {UPDATE OR ROLLBACK} 1 {1 2 3 4} 0 0 0 +} { + if {$t0} {set t1 {UNIQUE constraint failed: t1.a}} + if {[info exists TEMP_STORE] && $TEMP_STORE==3} { + set t3 0 + } else { + set t3 [expr {$t3+$t4}] + } + do_test conflict-6.$i { + db close + sqlite3 db test.db + if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"} + execsql {pragma temp_store=file} + set ::sqlite_opentemp_count 0 + set r0 [catch {execsql [subst { + DROP TABLE t1; + CREATE TABLE t1(a,b,c, UNIQUE(a) $conf1); + INSERT INTO t1 SELECT * FROM t2; + UPDATE t3 SET x=0; + BEGIN; + $cmd t3 SET x=1; + $cmd t1 SET b=b*2; + $cmd t1 SET a=c+5; + }]} r1] + catch {execsql {COMMIT}} + if {!$r0} {set r1 [execsql {SELECT a FROM t1 ORDER BY b}]} + set r2 [execsql {SELECT x FROM t3}] + list $r0 $r1 $r2 $::sqlite_opentemp_count + } [list $t0 $t1 $t2 $t3] +} + +# Test to make sure a lot of IGNOREs don't cause a stack overflow +# +do_test conflict-7.1 { + execsql { + DROP TABLE t1; + DROP TABLE t2; + DROP TABLE t3; + CREATE TABLE t1(a unique, b); + } + for {set i 1} {$i<=50} {incr i} { + execsql "INSERT into t1 values($i,[expr {$i+1}]);" + } + execsql { + SELECT count(*), min(a), max(b) FROM t1; + } +} {50 1 51} +do_test conflict-7.2 { + execsql { + PRAGMA count_changes=on; + UPDATE OR IGNORE t1 SET a=1000; + } +} {1} +do_test conflict-7.2.1 { + db changes +} {1} +do_test conflict-7.3 { + execsql { + SELECT b FROM t1 WHERE a=1000; + } +} {2} +do_test conflict-7.4 { + execsql { + SELECT count(*) FROM t1; + } +} {50} +do_test conflict-7.5 { + execsql { + PRAGMA count_changes=on; + UPDATE OR REPLACE t1 SET a=1001; + } +} {50} +do_test conflict-7.5.1 { + db changes +} {50} +do_test conflict-7.6 { + execsql { + SELECT b FROM t1 WHERE a=1001; + } +} {51} +do_test conflict-7.7 { + execsql { + SELECT count(*) FROM t1; + } +} {1} + +# Update for version 3: A SELECT statement no longer resets the change +# counter (Test result changes from 0 to 50). +do_test conflict-7.7.1 { + db changes +} {50} + +# Make sure the row count is right for rows that are ignored on +# an insert. +# +do_test conflict-8.1 { + execsql { + DELETE FROM t1; + INSERT INTO t1 VALUES(1,2); + } + execsql { + INSERT OR IGNORE INTO t1 VALUES(2,3); + } +} {1} +do_test conflict-8.1.1 { + db changes +} {1} +do_test conflict-8.2 { + execsql { + INSERT OR IGNORE INTO t1 VALUES(2,4); + } +} {0} +do_test conflict-8.2.1 { + db changes +} {0} +do_test conflict-8.3 { + execsql { + INSERT OR REPLACE INTO t1 VALUES(2,4); + } +} {1} +do_test conflict-8.3.1 { + db changes +} {1} +do_test conflict-8.4 { + execsql { + INSERT OR IGNORE INTO t1 SELECT * FROM t1; + } +} {0} +do_test conflict-8.4.1 { + db changes +} {0} +do_test conflict-8.5 { + execsql { + INSERT OR IGNORE INTO t1 SELECT a+2,b+2 FROM t1; + } +} {2} +do_test conflict-8.5.1 { + db changes +} {2} +do_test conflict-8.6 { + execsql { + INSERT OR IGNORE INTO t1 SELECT a+3,b+3 FROM t1; + } +} {3} +do_test conflict-8.6.1 { + db changes +} {3} + +integrity_check conflict-8.99 + +do_test conflict-9.1 { + execsql { + PRAGMA count_changes=0; + CREATE TABLE t2( + a INTEGER UNIQUE ON CONFLICT IGNORE, + b INTEGER UNIQUE ON CONFLICT FAIL, + c INTEGER UNIQUE ON CONFLICT REPLACE, + d INTEGER UNIQUE ON CONFLICT ABORT, + e INTEGER UNIQUE ON CONFLICT ROLLBACK + ); + CREATE TABLE t3(x); + INSERT INTO t3 VALUES(1); + SELECT * FROM t3; + } +} {1} +do_test conflict-9.2 { + catchsql { + INSERT INTO t2 VALUES(1,1,1,1,1); + INSERT INTO t2 VALUES(2,2,2,2,2); + SELECT * FROM t2; + } +} {0 {1 1 1 1 1 2 2 2 2 2}} +do_test conflict-9.3 { + catchsql { + INSERT INTO t2 VALUES(1,3,3,3,3); + SELECT * FROM t2; + } +} {0 {1 1 1 1 1 2 2 2 2 2}} +do_test conflict-9.4 { + catchsql { + UPDATE t2 SET a=a+1 WHERE a=1; + SELECT * FROM t2; + } +} {0 {1 1 1 1 1 2 2 2 2 2}} +do_test conflict-9.5 { + catchsql { + INSERT INTO t2 VALUES(3,1,3,3,3); + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.b}} +do_test conflict-9.6 { + catchsql { + UPDATE t2 SET b=b+1 WHERE b=1; + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.b}} +do_test conflict-9.7 { + catchsql { + BEGIN; + UPDATE t3 SET x=x+1; + INSERT INTO t2 VALUES(3,1,3,3,3); + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.b}} +do_test conflict-9.8 { + execsql {COMMIT} + execsql {SELECT * FROM t3} +} {2} +do_test conflict-9.9 { + catchsql { + BEGIN; + UPDATE t3 SET x=x+1; + UPDATE t2 SET b=b+1 WHERE b=1; + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.b}} +do_test conflict-9.10 { + execsql {COMMIT} + execsql {SELECT * FROM t3} +} {3} +do_test conflict-9.11 { + catchsql { + INSERT INTO t2 VALUES(3,3,3,1,3); + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.d}} +do_test conflict-9.12 { + catchsql { + UPDATE t2 SET d=d+1 WHERE d=1; + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.d}} +do_test conflict-9.13 { + catchsql { + BEGIN; + UPDATE t3 SET x=x+1; + INSERT INTO t2 VALUES(3,3,3,1,3); + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.d}} +do_test conflict-9.14 { + execsql {COMMIT} + execsql {SELECT * FROM t3} +} {4} +do_test conflict-9.15 { + catchsql { + BEGIN; + UPDATE t3 SET x=x+1; + UPDATE t2 SET d=d+1 WHERE d=1; + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.d}} +do_test conflict-9.16 { + execsql {COMMIT} + execsql {SELECT * FROM t3} +} {5} +do_test conflict-9.17 { + catchsql { + INSERT INTO t2 VALUES(3,3,3,3,1); + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.e}} +do_test conflict-9.18 { + catchsql { + UPDATE t2 SET e=e+1 WHERE e=1; + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.e}} +do_test conflict-9.19 { + catchsql { + BEGIN; + UPDATE t3 SET x=x+1; + INSERT INTO t2 VALUES(3,3,3,3,1); + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.e}} +verify_ex_errcode conflict-9.21b SQLITE_CONSTRAINT_UNIQUE +do_test conflict-9.20 { + catch {execsql {COMMIT}} + execsql {SELECT * FROM t3} +} {5} +do_test conflict-9.21 { + catchsql { + BEGIN; + UPDATE t3 SET x=x+1; + UPDATE t2 SET e=e+1 WHERE e=1; + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.e}} +verify_ex_errcode conflict-9.21b SQLITE_CONSTRAINT_UNIQUE +do_test conflict-9.22 { + catch {execsql {COMMIT}} + execsql {SELECT * FROM t3} +} {5} +do_test conflict-9.23 { + catchsql { + INSERT INTO t2 VALUES(3,3,1,3,3); + SELECT * FROM t2; + } +} {0 {2 2 2 2 2 3 3 1 3 3}} +do_test conflict-9.24 { + catchsql { + UPDATE t2 SET c=c-1 WHERE c=2; + SELECT * FROM t2; + } +} {0 {2 2 1 2 2}} +do_test conflict-9.25 { + catchsql { + BEGIN; + UPDATE t3 SET x=x+1; + INSERT INTO t2 VALUES(3,3,1,3,3); + SELECT * FROM t2; + } +} {0 {3 3 1 3 3}} +do_test conflict-9.26 { + catch {execsql {COMMIT}} + execsql {SELECT * FROM t3} +} {6} + +do_test conflict-10.1 { + catchsql { + DELETE FROM t1; + BEGIN; + INSERT OR ROLLBACK INTO t1 VALUES(1,2); + INSERT OR ROLLBACK INTO t1 VALUES(1,3); + COMMIT; + } + execsql {SELECT * FROM t1} +} {} +do_test conflict-10.2 { + catchsql { + CREATE TABLE t4(x); + CREATE UNIQUE INDEX t4x ON t4(x); + BEGIN; + INSERT OR ROLLBACK INTO t4 VALUES(1); + INSERT OR ROLLBACK INTO t4 VALUES(1); + COMMIT; + } + execsql {SELECT * FROM t4} +} {} + +# Ticket #1171. Make sure statement rollbacks do not +# damage the database. +# +do_test conflict-11.1 { + execsql { + -- Create a database object (pages 2, 3 of the file) + BEGIN; + CREATE TABLE abc(a UNIQUE, b, c); + INSERT INTO abc VALUES(1, 2, 3); + INSERT INTO abc VALUES(4, 5, 6); + INSERT INTO abc VALUES(7, 8, 9); + COMMIT; + } + + + # Set a small cache size so that changes will spill into + # the database file. + execsql { + PRAGMA cache_size = 10; + } + + # Make lots of changes. Because of the small cache, some + # (most?) of these changes will spill into the disk file. + # In other words, some of the changes will not be held in + # cache. + # + execsql { + BEGIN; + -- Make sure the pager is in EXCLUSIVE state. + CREATE TABLE def(d, e, f); + INSERT INTO def VALUES + ('xxxxxxxxxxxxxxx', 'yyyyyyyyyyyyyyyy', 'zzzzzzzzzzzzzzzz'); + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + DELETE FROM abc WHERE a = 4; + } + + # Execute a statement that does a statement rollback due to + # a constraint failure. + # + catchsql { + INSERT INTO abc SELECT 10, 20, 30 FROM def; + } + + # Rollback the database. Verify that the state of the ABC table + # is unchanged from the beginning of the transaction. In other words, + # make sure the DELETE on table ABC that occurred within the transaction + # had no effect. + # + execsql { + ROLLBACK; + SELECT * FROM abc; + } +} {1 2 3 4 5 6 7 8 9} +integrity_check conflict-11.2 + +# Repeat test conflict-11.1 but this time commit. +# +do_test conflict-11.3 { + execsql { + BEGIN; + -- Make sure the pager is in EXCLUSIVE state. + UPDATE abc SET a=a+1; + CREATE TABLE def(d, e, f); + INSERT INTO def VALUES + ('xxxxxxxxxxxxxxx', 'yyyyyyyyyyyyyyyy', 'zzzzzzzzzzzzzzzz'); + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + DELETE FROM abc WHERE a = 4; + } + catchsql { + INSERT INTO abc SELECT 10, 20, 30 FROM def; + } + execsql { + ROLLBACK; + SELECT * FROM abc; + } +} {1 2 3 4 5 6 7 8 9} +# Repeat test conflict-11.1 but this time commit. +# +do_test conflict-11.5 { + execsql { + BEGIN; + -- Make sure the pager is in EXCLUSIVE state. + CREATE TABLE def(d, e, f); + INSERT INTO def VALUES + ('xxxxxxxxxxxxxxx', 'yyyyyyyyyyyyyyyy', 'zzzzzzzzzzzzzzzz'); + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + DELETE FROM abc WHERE a = 4; + } + catchsql { + INSERT INTO abc SELECT 10, 20, 30 FROM def; + } + execsql { + COMMIT; + SELECT * FROM abc; + } +} {1 2 3 7 8 9} +integrity_check conflict-11.6 + +# Make sure UPDATE OR REPLACE works on tables that have only +# an INTEGER PRIMARY KEY. +# +do_test conflict-12.1 { + execsql { + CREATE TABLE t5(a INTEGER PRIMARY KEY, b text); + INSERT INTO t5 VALUES(1,'one'); + INSERT INTO t5 VALUES(2,'two'); + SELECT * FROM t5 + } +} {1 one 2 two} +do_test conflict-12.2 { + execsql { + UPDATE OR IGNORE t5 SET a=a+1 WHERE a=1; + SELECT * FROM t5; + } +} {1 one 2 two} +do_test conflict-12.3 { + catchsql { + UPDATE t5 SET a=a+1 WHERE a=1; + } +} {1 {UNIQUE constraint failed: t5.a}} +verify_ex_errcode conflict-12.3b SQLITE_CONSTRAINT_PRIMARYKEY +do_test conflict-12.4 { + execsql { + UPDATE OR REPLACE t5 SET a=a+1 WHERE a=1; + SELECT * FROM t5; + } +} {2 one} +do_test conflict-12.5 { + catchsql { + CREATE TABLE t5b(x); + INSERT INTO t5b(rowid, x) VALUES(1,10),(2,11); + UPDATE t5b SET rowid=rowid+1 WHERE x=10; + } +} {1 {UNIQUE constraint failed: t5b.rowid}} +verify_ex_errcode conflict-12.5b SQLITE_CONSTRAINT_ROWID + + +# Ticket [c38baa3d969eab7946dc50ba9d9b4f0057a19437] +# REPLACE works like ABORT on a CHECK constraint. +# +do_test conflict-13.1 { + execsql { + CREATE TABLE t13(a CHECK(a!=2)); + BEGIN; + REPLACE INTO t13 VALUES(1); + } + catchsql { + REPLACE INTO t13 VALUES(2); + } +} {1 {CHECK constraint failed: a!=2}} +verify_ex_errcode conflict-13.1b SQLITE_CONSTRAINT_CHECK +do_test conflict-13.2 { + execsql { + REPLACE INTO t13 VALUES(3); + COMMIT; + SELECT * FROM t13; + } +} {1 3} + + +# Ticket https://www.sqlite.org/src/tktview/e6f1f2e34dceeb1ed61531c7e9 +# Verify that it is not possible to sneak a NULL value into a NOT NULL +# column using REPLACE. +# +do_catchsql_test conflict-14.1 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(x NOT NULL DEFAULT NULL); + REPLACE INTO t1 DEFAULT VALUES; +} {1 {NOT NULL constraint failed: t1.x}} + +# 2019-12-15 gramfuzz1 find +# Three UNIQUE constraints, where the third would is a duplicate except +# that it adds ON CONFLICT REPLACE. Verify that the indexes end up +# sorted in the correct order (REPLACE last) so that constraint processing +# works correctly. +# +reset_db +do_execsql_test conflict-15.10 { + CREATE TABLE t1( + x PRIMARY KEY, + UNIQUE(x,x), + UNIQUE(x,x) ON CONFLICT REPLACE + ); + INSERT INTO t1(x) VALUES(1); + SELECT * FROM t1; +} {1} +do_catchsql_test conflict-15.20 { + INSERT INTO t1(x) VALUES(1); +} {1 {UNIQUE constraint failed: t1.x}} +do_execsql_test conflict-15.30 { + SELECT * FROM t1; +} {1} + +# 2023-01-16 https://sqlite.org/forum/forumpost/aa580a5af38a58e3 +# The parser accepts an ON CONFLICT clause on table CHECK constraints +# but not on column CHECK constraints. But the CHECK constraint is +# ignored. It has been like this since version 3.0.0. +# +# There might be applications and/or databases in the wild that have +# table CHECK constraints with ON CONFLICT clauses. In as much as this +# is a harmless quirk, we continue to support it in order to avoid +# breaking those legacy applications and databases. +# +reset_db +do_catchsql_test conflict-16.1 { + -- ON CONFLICT clauses are not allowed on column CHECK constraints + CREATE TABLE t1(a INT CHECK( a!=5 ) ON CONFLICT ignore); +} {1 {near "ON": syntax error}} +do_execsql_test conflict-16.2 { + -- ON CONFLICT is allowed on table CHECK constraints + CREATE TABLE t1(a INT, CHECK( a!=5 ) ON CONFLICT ignore); +} {} +do_catchsql_test conflict-16.3 { + -- The ON CONFLICT clause is in-op + INSERT INTO t1(a) VALUES(4),(5),(6); +} {1 {CHECK constraint failed: a!=5}} +do_execsql_test conflict-16.4 { + SELECT a FROM t1 ORDER BY a; +} {} +do_execsql_test conflict-16.5 { + INSERT OR IGNORE INTO t1(a) VALUES(4),(5),(6); + SELECT a FROM t1 ORDER BY a; +} {4 6} + +finish_test diff --git a/test/conflict2.test b/test/conflict2.test new file mode 100644 index 0000000..96289d3 --- /dev/null +++ b/test/conflict2.test @@ -0,0 +1,858 @@ +# 2013-11-04 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests for the conflict resolution extension +# in WITHOUT ROWID tables +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !conflict { + finish_test + return +} + +# Create tables for the first group of tests. +# +do_test conflict2-1.0 { + execsql { + CREATE TABLE t1(a, b, c, PRIMARY KEY(a,b)) WITHOUT rowid; + CREATE TABLE t2(x); + SELECT c FROM t1 ORDER BY c; + } +} {} + +# Six columns of configuration data as follows: +# +# i The reference number of the test +# cmd An INSERT or REPLACE command to execute against table t1 +# t0 True if there is an error from $cmd +# t1 Content of "c" column of t1 assuming no error in $cmd +# t2 Content of "x" column of t2 +# t3 Number of temporary files created by this test +# +foreach {i cmd t0 t1 t2 t3} { + 1 INSERT 1 {} 1 0 + 2 {INSERT OR IGNORE} 0 3 1 0 + 3 {INSERT OR REPLACE} 0 4 1 0 + 4 REPLACE 0 4 1 0 + 5 {INSERT OR FAIL} 1 {} 1 0 + 6 {INSERT OR ABORT} 1 {} 1 0 + 7 {INSERT OR ROLLBACK} 1 {} {} 0 +} { + do_test conflict2-1.$i { + set ::sqlite_opentemp_count 0 + set r0 [catch {execsql [subst { + DELETE FROM t1; + DELETE FROM t2; + INSERT INTO t1 VALUES(1,2,3); + BEGIN; + INSERT INTO t2 VALUES(1); + $cmd INTO t1 VALUES(1,2,4); + }]} r1] + catch {execsql {COMMIT}} + if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]} + set r2 [execsql {SELECT x FROM t2}] + set r3 $::sqlite_opentemp_count + list $r0 $r1 $r2 $r3 + } [list $t0 $t1 $t2 $t3] +} + +# Create tables for the first group of tests. +# +do_test conflict2-2.0 { + execsql { + DROP TABLE t1; + DROP TABLE t2; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, UNIQUE(a,b)) WITHOUT rowid; + CREATE TABLE t2(x); + SELECT c FROM t1 ORDER BY c; + } +} {} + +# Six columns of configuration data as follows: +# +# i The reference number of the test +# cmd An INSERT or REPLACE command to execute against table t1 +# t0 True if there is an error from $cmd +# t1 Content of "c" column of t1 assuming no error in $cmd +# t2 Content of "x" column of t2 +# +foreach {i cmd t0 t1 t2} { + 1 INSERT 1 {} 1 + 2 {INSERT OR IGNORE} 0 3 1 + 3 {INSERT OR REPLACE} 0 4 1 + 4 REPLACE 0 4 1 + 5 {INSERT OR FAIL} 1 {} 1 + 6 {INSERT OR ABORT} 1 {} 1 + 7 {INSERT OR ROLLBACK} 1 {} {} +} { + do_test conflict2-2.$i { + set r0 [catch {execsql [subst { + DELETE FROM t1; + DELETE FROM t2; + INSERT INTO t1 VALUES(1,2,3); + BEGIN; + INSERT INTO t2 VALUES(1); + $cmd INTO t1 VALUES(1,2,4); + }]} r1] + catch {execsql {COMMIT}} + if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]} + set r2 [execsql {SELECT x FROM t2}] + list $r0 $r1 $r2 + } [list $t0 $t1 $t2] +} + +# Create tables for the first group of tests. +# +do_test conflict2-3.0 { + execsql { + DROP TABLE t1; + DROP TABLE t2; + CREATE TABLE t1(a, b, c INTEGER, PRIMARY KEY(c), UNIQUE(a,b)) WITHOUT rowid; + CREATE TABLE t2(x); + SELECT c FROM t1 ORDER BY c; + } +} {} + +# Six columns of configuration data as follows: +# +# i The reference number of the test +# cmd An INSERT or REPLACE command to execute against table t1 +# t0 True if there is an error from $cmd +# t1 Content of "c" column of t1 assuming no error in $cmd +# t2 Content of "x" column of t2 +# +foreach {i cmd t0 t1 t2} { + 1 INSERT 1 {} 1 + 2 {INSERT OR IGNORE} 0 3 1 + 3 {INSERT OR REPLACE} 0 4 1 + 4 REPLACE 0 4 1 + 5 {INSERT OR FAIL} 1 {} 1 + 6 {INSERT OR ABORT} 1 {} 1 + 7 {INSERT OR ROLLBACK} 1 {} {} +} { + do_test conflict2-3.$i { + set r0 [catch {execsql [subst { + DELETE FROM t1; + DELETE FROM t2; + INSERT INTO t1 VALUES(1,2,3); + BEGIN; + INSERT INTO t2 VALUES(1); + $cmd INTO t1 VALUES(1,2,4); + }]} r1] + catch {execsql {COMMIT}} + if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]} + set r2 [execsql {SELECT x FROM t2}] + list $r0 $r1 $r2 + } [list $t0 $t1 $t2] +} + +do_test conflict2-4.0 { + execsql { + DROP TABLE t2; + CREATE TABLE t2(x); + SELECT x FROM t2; + } +} {} + +# Six columns of configuration data as follows: +# +# i The reference number of the test +# conf1 The conflict resolution algorithm on the UNIQUE constraint +# cmd An INSERT or REPLACE command to execute against table t1 +# t0 True if there is an error from $cmd +# t1 Content of "c" column of t1 assuming no error in $cmd +# t2 Content of "x" column of t2 +# +foreach {i conf1 cmd t0 t1 t2} { + 1 {} INSERT 1 {} 1 + 2 REPLACE INSERT 0 4 1 + 3 IGNORE INSERT 0 3 1 + 4 FAIL INSERT 1 {} 1 + 5 ABORT INSERT 1 {} 1 + 6 ROLLBACK INSERT 1 {} {} + 7 REPLACE {INSERT OR IGNORE} 0 3 1 + 8 IGNORE {INSERT OR REPLACE} 0 4 1 + 9 FAIL {INSERT OR IGNORE} 0 3 1 + 10 ABORT {INSERT OR REPLACE} 0 4 1 + 11 ROLLBACK {INSERT OR IGNORE } 0 3 1 +} { + do_test conflict2-4.$i { + if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"} + set r0 [catch {execsql [subst { + DROP TABLE t1; + CREATE TABLE t1(a,b,c,PRIMARY KEY(a,b) $conf1) WITHOUT rowid; + DELETE FROM t2; + INSERT INTO t1 VALUES(1,2,3); + BEGIN; + INSERT INTO t2 VALUES(1); + $cmd INTO t1 VALUES(1,2,4); + }]} r1] + catch {execsql {COMMIT}} + if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]} + set r2 [execsql {SELECT x FROM t2}] + list $r0 $r1 $r2 + } [list $t0 $t1 $t2] +} + +do_test conflict2-5.0 { + execsql { + DROP TABLE t2; + CREATE TABLE t2(x); + SELECT x FROM t2; + } +} {} + +# Six columns of configuration data as follows: +# +# i The reference number of the test +# conf1 The conflict resolution algorithm on the NOT NULL constraint +# cmd An INSERT or REPLACE command to execute against table t1 +# t0 True if there is an error from $cmd +# t1 Content of "c" column of t1 assuming no error in $cmd +# t2 Content of "x" column of t2 +# +foreach {i conf1 cmd t0 t1 t2} { + 1 {} INSERT 1 {} 1 + 2 REPLACE INSERT 0 5 1 + 3 IGNORE INSERT 0 {} 1 + 4 FAIL INSERT 1 {} 1 + 5 ABORT INSERT 1 {} 1 + 6 ROLLBACK INSERT 1 {} {} + 7 REPLACE {INSERT OR IGNORE} 0 {} 1 + 8 IGNORE {INSERT OR REPLACE} 0 5 1 + 9 FAIL {INSERT OR IGNORE} 0 {} 1 + 10 ABORT {INSERT OR REPLACE} 0 5 1 + 11 ROLLBACK {INSERT OR IGNORE} 0 {} 1 + 12 {} {INSERT OR IGNORE} 0 {} 1 + 13 {} {INSERT OR REPLACE} 0 5 1 + 14 {} {INSERT OR FAIL} 1 {} 1 + 15 {} {INSERT OR ABORT} 1 {} 1 + 16 {} {INSERT OR ROLLBACK} 1 {} {} +} { + if {$t0} {set t1 {NOT NULL constraint failed: t1.c}} + do_test conflict2-5.$i { + if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"} + set r0 [catch {execsql [subst { + DROP TABLE t1; + CREATE TABLE t1(a,b,c NOT NULL $conf1 DEFAULT 5); + DELETE FROM t2; + BEGIN; + INSERT INTO t2 VALUES(1); + $cmd INTO t1 VALUES(1,2,NULL); + }]} r1] + catch {execsql {COMMIT}} + if {!$r0} {set r1 [execsql {SELECT c FROM t1}]} + set r2 [execsql {SELECT x FROM t2}] + list $r0 $r1 $r2 + } [list $t0 $t1 $t2] +} + +do_test conflict2-6.0 { + execsql { + DROP TABLE t2; + CREATE TABLE t2(a,b,c); + INSERT INTO t2 VALUES(1,2,1); + INSERT INTO t2 VALUES(2,3,2); + INSERT INTO t2 VALUES(3,4,1); + INSERT INTO t2 VALUES(4,5,4); + SELECT c FROM t2 ORDER BY b; + CREATE TABLE t3(x); + INSERT INTO t3 VALUES(1); + } +} {1 2 1 4} + +# Six columns of configuration data as follows: +# +# i The reference number of the test +# conf1 The conflict resolution algorithm on the UNIQUE constraint +# cmd An UPDATE command to execute against table t1 +# t0 True if there is an error from $cmd +# t1 Content of "b" column of t1 assuming no error in $cmd +# t2 Content of "x" column of t3 +# t3 Number of temporary files for tables +# t4 Number of temporary files for statement journals +# +# Update: Since temporary table files are now opened lazily, and none +# of the following tests use large quantities of data, t3 is always 0. +# +# Update (2016-03-04): Subjournals now only open when their size +# exceeds 64KB. +# +foreach {i conf1 cmd t0 t1 t2 t3 t4} { + 1 {} UPDATE 1 {6 7 8 9} 1 0 0 + 2 REPLACE UPDATE 0 {7 6 9} 1 0 0 + 3 IGNORE UPDATE 0 {6 7 3 9} 1 0 0 + 4 FAIL UPDATE 1 {6 7 3 4} 1 0 0 + 5 ABORT UPDATE 1 {1 2 3 4} 1 0 0 + 6 ROLLBACK UPDATE 1 {1 2 3 4} 0 0 0 + 7 REPLACE {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0 0 + 8 IGNORE {UPDATE OR REPLACE} 0 {7 6 9} 1 0 0 + 9 FAIL {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0 0 + 10 ABORT {UPDATE OR REPLACE} 0 {7 6 9} 1 0 0 + 11 ROLLBACK {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0 0 + 12 {} {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0 0 + 13 {} {UPDATE OR REPLACE} 0 {7 6 9} 1 0 0 + 14 {} {UPDATE OR FAIL} 1 {6 7 3 4} 1 0 0 + 15 {} {UPDATE OR ABORT} 1 {1 2 3 4} 1 0 0 + 16 {} {UPDATE OR ROLLBACK} 1 {1 2 3 4} 0 0 0 +} { + + # When using in-memory journals, no temporary files are required for + # statement journals. + if {[permutation] == "inmemory_journal"} { set t4 0 } + + if {$t0} {set t1 {UNIQUE constraint failed: t1.a}} + if {[info exists TEMP_STORE] && $TEMP_STORE==3} { + set t3 0 + } else { + set t3 [expr {$t3+$t4}] + } + do_test conflict2-6.$i { + db close + sqlite3 db test.db + if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"} + execsql {pragma temp_store=file} + set ::sqlite_opentemp_count 0 + set r0 [catch {execsql [subst { + DROP TABLE t1; + CREATE TABLE t1(a,b,c, PRIMARY KEY(a) $conf1) WITHOUT rowid; + INSERT INTO t1 SELECT * FROM t2; + UPDATE t3 SET x=0; + BEGIN; + $cmd t3 SET x=1; + $cmd t1 SET b=b*2; + $cmd t1 SET a=c+5; + }]} r1] + catch {execsql {COMMIT}} + if {!$r0} {set r1 [execsql {SELECT a FROM t1 ORDER BY b}]} + set r2 [execsql {SELECT x FROM t3}] + list $r0 $r1 $r2 $::sqlite_opentemp_count + } [list $t0 $t1 $t2 $t3] +} + +# Test to make sure a lot of IGNOREs don't cause a stack overflow +# +do_test conflict2-7.1 { + execsql { + DROP TABLE t1; + DROP TABLE t2; + DROP TABLE t3; + CREATE TABLE t1(a PRIMARY KEY, b) without rowid; + } + for {set i 1} {$i<=50} {incr i} { + execsql "INSERT into t1 values($i,[expr {$i+1}]);" + } + execsql { + SELECT count(*), min(a), max(b) FROM t1; + } +} {50 1 51} +do_test conflict2-7.2 { + execsql { + PRAGMA count_changes=on; + UPDATE OR IGNORE t1 SET a=1000; + } +} {1} +do_test conflict2-7.2.1 { + db changes +} {1} +do_test conflict2-7.3 { + execsql { + SELECT b FROM t1 WHERE a=1000; + } +} {2} +do_test conflict2-7.4 { + execsql { + SELECT count(*) FROM t1; + } +} {50} +do_test conflict2-7.5 { + execsql { + PRAGMA count_changes=on; + UPDATE OR REPLACE t1 SET a=1001; + } +} {50} +do_test conflict2-7.5.1 { + db changes +} {50} +do_test conflict2-7.7 { + execsql { + SELECT count(*) FROM t1; + } +} {1} + +# Update for version 3: A SELECT statement no longer resets the change +# counter (Test result changes from 0 to 50). +do_test conflict2-7.7.1 { + db changes +} {50} + +# Make sure the row count is right for rows that are ignored on +# an insert. +# +do_test conflict2-8.1 { + execsql { + DELETE FROM t1; + INSERT INTO t1 VALUES(1,2); + } + execsql { + INSERT OR IGNORE INTO t1 VALUES(2,3); + } +} {1} +do_test conflict2-8.1.1 { + db changes +} {1} +do_test conflict2-8.2 { + execsql { + INSERT OR IGNORE INTO t1 VALUES(2,4); + } +} {0} +do_test conflict2-8.2.1 { + db changes +} {0} +do_test conflict2-8.3 { + execsql { + INSERT OR REPLACE INTO t1 VALUES(2,4); + } +} {1} +do_test conflict2-8.3.1 { + db changes +} {1} +do_test conflict2-8.4 { + execsql { + INSERT OR IGNORE INTO t1 SELECT * FROM t1; + } +} {0} +do_test conflict2-8.4.1 { + db changes +} {0} +do_test conflict2-8.5 { + execsql { + INSERT OR IGNORE INTO t1 SELECT a+2,b+2 FROM t1; + } +} {2} +do_test conflict2-8.5.1 { + db changes +} {2} +do_test conflict2-8.6 { + execsql { + INSERT OR IGNORE INTO t1 SELECT a+3,b+3 FROM t1; + } +} {3} +do_test conflict2-8.6.1 { + db changes +} {3} + +integrity_check conflict2-8.99 + +do_test conflict2-9.1 { + execsql { + PRAGMA count_changes=0; + CREATE TABLE t2( + a INTEGER PRIMARY KEY ON CONFLICT IGNORE, + b INTEGER UNIQUE ON CONFLICT FAIL, + c INTEGER UNIQUE ON CONFLICT REPLACE, + d INTEGER UNIQUE ON CONFLICT ABORT, + e INTEGER UNIQUE ON CONFLICT ROLLBACK + ) WITHOUT rowid; + CREATE TABLE t3(x); + INSERT INTO t3 VALUES(1); + SELECT * FROM t3; + } +} {1} +do_test conflict2-9.2 { + catchsql { + INSERT INTO t2 VALUES(1,1,1,1,1); + INSERT INTO t2 VALUES(2,2,2,2,2); + SELECT * FROM t2; + } +} {0 {1 1 1 1 1 2 2 2 2 2}} +do_test conflict2-9.3 { + catchsql { + INSERT INTO t2 VALUES(1,3,3,3,3); + SELECT * FROM t2; + } +} {0 {1 1 1 1 1 2 2 2 2 2}} +do_test conflict2-9.4 { + catchsql { + UPDATE t2 SET a=a+1 WHERE a=1; + SELECT * FROM t2; + } +} {0 {1 1 1 1 1 2 2 2 2 2}} +do_test conflict2-9.5 { + catchsql { + INSERT INTO t2 VALUES(3,1,3,3,3); + } +} {1 {UNIQUE constraint failed: t2.b}} +do_test conflict2-9.5b { + db eval {SELECT * FROM t2;} +} {1 1 1 1 1 2 2 2 2 2} +do_test conflict2-9.6 { + catchsql { + UPDATE t2 SET b=b+1 WHERE b=1; + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.b}} +do_test conflict2-9.6b { + db eval {SELECT * FROM t2;} +} {1 1 1 1 1 2 2 2 2 2} +do_test conflict2-9.7 { + catchsql { + BEGIN; + UPDATE t3 SET x=x+1; + INSERT INTO t2 VALUES(3,1,3,3,3); + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.b}} +do_test conflict2-9.8 { + execsql {COMMIT} + execsql {SELECT * FROM t3} +} {2} +do_test conflict2-9.9 { + catchsql { + BEGIN; + UPDATE t3 SET x=x+1; + UPDATE t2 SET b=b+1 WHERE b=1; + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.b}} +do_test conflict2-9.10 { + execsql {COMMIT} + execsql {SELECT * FROM t3} +} {3} +do_test conflict2-9.11 { + catchsql { + INSERT INTO t2 VALUES(3,3,3,1,3); + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.d}} +do_test conflict2-9.12 { + catchsql { + UPDATE t2 SET d=d+1 WHERE d=1; + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.d}} +do_test conflict2-9.13 { + catchsql { + BEGIN; + UPDATE t3 SET x=x+1; + INSERT INTO t2 VALUES(3,3,3,1,3); + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.d}} +do_test conflict2-9.14 { + execsql {COMMIT} + execsql {SELECT * FROM t3} +} {4} +do_test conflict2-9.15 { + catchsql { + BEGIN; + UPDATE t3 SET x=x+1; + UPDATE t2 SET d=d+1 WHERE d=1; + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.d}} +do_test conflict2-9.16 { + execsql {COMMIT} + execsql {SELECT * FROM t3} +} {5} +do_test conflict2-9.17 { + catchsql { + INSERT INTO t2 VALUES(3,3,3,3,1); + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.e}} +do_test conflict2-9.18 { + catchsql { + UPDATE t2 SET e=e+1 WHERE e=1; + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.e}} +do_test conflict2-9.19 { + catchsql { + BEGIN; + UPDATE t3 SET x=x+1; + INSERT INTO t2 VALUES(3,3,3,3,1); + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.e}} +verify_ex_errcode conflict2-9.21b SQLITE_CONSTRAINT_UNIQUE +do_test conflict2-9.20 { + catch {execsql {COMMIT}} + execsql {SELECT * FROM t3} +} {5} +do_test conflict2-9.21 { + catchsql { + BEGIN; + UPDATE t3 SET x=x+1; + UPDATE t2 SET e=e+1 WHERE e=1; + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.e}} +verify_ex_errcode conflict2-9.21b SQLITE_CONSTRAINT_UNIQUE +do_test conflict2-9.22 { + catch {execsql {COMMIT}} + execsql {SELECT * FROM t3} +} {5} +do_test conflict2-9.23 { + catchsql { + INSERT INTO t2 VALUES(3,3,1,3,3); + SELECT * FROM t2; + } +} {0 {2 2 2 2 2 3 3 1 3 3}} +do_test conflict2-9.24 { + catchsql { + UPDATE t2 SET c=c-1 WHERE c=2; + SELECT * FROM t2; + } +} {0 {2 2 1 2 2}} +do_test conflict2-9.25 { + catchsql { + BEGIN; + UPDATE t3 SET x=x+1; + INSERT INTO t2 VALUES(3,3,1,3,3); + SELECT * FROM t2; + } +} {0 {3 3 1 3 3}} +do_test conflict2-9.26 { + catch {execsql {COMMIT}} + execsql {SELECT * FROM t3} +} {6} + +do_test conflict2-10.1 { + catchsql { + DELETE FROM t1; + BEGIN; + INSERT OR ROLLBACK INTO t1 VALUES(1,2); + INSERT OR ROLLBACK INTO t1 VALUES(1,3); + COMMIT; + } + execsql {SELECT * FROM t1} +} {} +do_test conflict2-10.2 { + catchsql { + CREATE TABLE t4(x); + CREATE UNIQUE INDEX t4x ON t4(x); + BEGIN; + INSERT OR ROLLBACK INTO t4 VALUES(1); + INSERT OR ROLLBACK INTO t4 VALUES(1); + COMMIT; + } + execsql {SELECT * FROM t4} +} {} + +# Ticket #1171. Make sure statement rollbacks do not +# damage the database. +# +do_test conflict2-11.1 { + execsql { + -- Create a database object (pages 2, 3 of the file) + BEGIN; + CREATE TABLE abc(a PRIMARY KEY, b, c) WITHOUT rowid; + INSERT INTO abc VALUES(1, 2, 3); + INSERT INTO abc VALUES(4, 5, 6); + INSERT INTO abc VALUES(7, 8, 9); + COMMIT; + } + + + # Set a small cache size so that changes will spill into + # the database file. + execsql { + PRAGMA cache_size = 10; + } + + # Make lots of changes. Because of the small cache, some + # (most?) of these changes will spill into the disk file. + # In other words, some of the changes will not be held in + # cache. + # + execsql { + BEGIN; + -- Make sure the pager is in EXCLUSIVE state. + CREATE TABLE def(d, e, f); + INSERT INTO def VALUES + ('xxxxxxxxxxxxxxx', 'yyyyyyyyyyyyyyyy', 'zzzzzzzzzzzzzzzz'); + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + DELETE FROM abc WHERE a = 4; + } + + # Execute a statement that does a statement rollback due to + # a constraint failure. + # + catchsql { + INSERT INTO abc SELECT 10, 20, 30 FROM def; + } + + # Rollback the database. Verify that the state of the ABC table + # is unchanged from the beginning of the transaction. In other words, + # make sure the DELETE on table ABC that occurred within the transaction + # had no effect. + # + execsql { + ROLLBACK; + SELECT * FROM abc; + } +} {1 2 3 4 5 6 7 8 9} +integrity_check conflict2-11.2 + +# Repeat test conflict2-11.1 but this time commit. +# +do_test conflict2-11.3 { + execsql { + BEGIN; + -- Make sure the pager is in EXCLUSIVE state. + UPDATE abc SET a=a+1; + CREATE TABLE def(d, e, f); + INSERT INTO def VALUES + ('xxxxxxxxxxxxxxx', 'yyyyyyyyyyyyyyyy', 'zzzzzzzzzzzzzzzz'); + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + DELETE FROM abc WHERE a = 4; + } + catchsql { + INSERT INTO abc SELECT 10, 20, 30 FROM def; + } + execsql { + ROLLBACK; + SELECT * FROM abc; + } +} {1 2 3 4 5 6 7 8 9} +# Repeat test conflict2-11.1 but this time commit. +# +do_test conflict2-11.5 { + execsql { + BEGIN; + -- Make sure the pager is in EXCLUSIVE state. + CREATE TABLE def(d, e, f); + INSERT INTO def VALUES + ('xxxxxxxxxxxxxxx', 'yyyyyyyyyyyyyyyy', 'zzzzzzzzzzzzzzzz'); + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + DELETE FROM abc WHERE a = 4; + } + catchsql { + INSERT INTO abc SELECT 10, 20, 30 FROM def; + } + execsql { + COMMIT; + SELECT * FROM abc; + } +} {1 2 3 7 8 9} +integrity_check conflict2-11.6 + +# Make sure UPDATE OR REPLACE works on tables that have only +# an INTEGER PRIMARY KEY. +# +do_test conflict2-12.1 { + execsql { + CREATE TABLE t5(a INTEGER PRIMARY KEY, b text) WITHOUT rowid; + INSERT INTO t5 VALUES(1,'one'); + INSERT INTO t5 VALUES(2,'two'); + SELECT * FROM t5 + } +} {1 one 2 two} +do_test conflict2-12.2 { + execsql { + UPDATE OR IGNORE t5 SET a=a+1 WHERE a=1; + SELECT * FROM t5; + } +} {1 one 2 two} +do_test conflict2-12.3 { + catchsql { + UPDATE t5 SET a=a+1 WHERE a=1; + } +} {1 {UNIQUE constraint failed: t5.a}} +verify_ex_errcode conflict2-12.3b SQLITE_CONSTRAINT_PRIMARYKEY +do_test conflict2-12.4 { + execsql { + UPDATE OR REPLACE t5 SET a=a+1 WHERE a=1; + SELECT * FROM t5; + } +} {2 one} + + +# Ticket [c38baa3d969eab7946dc50ba9d9b4f0057a19437] +# REPLACE works like ABORT on a CHECK constraint. +# +do_test conflict2-13.1 { + execsql { + CREATE TABLE t13(a PRIMARY KEY CHECK(a!=2)) WITHOUT rowid; + BEGIN; + REPLACE INTO t13 VALUES(1); + } + catchsql { + REPLACE INTO t13 VALUES(2); + } +} {1 {CHECK constraint failed: a!=2}} +verify_ex_errcode conflict2-13.1b SQLITE_CONSTRAINT_CHECK +do_test conflict2-13.2 { + execsql { + REPLACE INTO t13 VALUES(3); + COMMIT; + SELECT * FROM t13; + } +} {1 3} + +# Test for an unreleased bug in the REPLACE conflict resolution +# discovered on 2013-11-09. +# +do_execsql_test conflict2-14.1 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1( + x TEXT PRIMARY KEY NOT NULL, + y TEXT NOT NULL, + z INTEGER + ); + INSERT INTO t1 VALUES('alpha','beta',1); + CREATE UNIQUE INDEX t1xy ON t1(x,y); + REPLACE INTO t1(x,y,z) VALUES('alpha','gamma',1); + PRAGMA integrity_check; + SELECT x,y FROM t1 INDEXED BY t1xy; + SELECT x,y,z FROM t1 NOT INDEXED; +} {ok alpha gamma alpha gamma 1} +do_execsql_test conflict2-14.2 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1( + x TEXT PRIMARY KEY NOT NULL, + y TEXT NOT NULL, + z INTEGER + ) WITHOUT ROWID; + INSERT INTO t1 VALUES('alpha','beta',1); + CREATE UNIQUE INDEX t1xy ON t1(x,y); + REPLACE INTO t1(x,y,z) VALUES('alpha','gamma',1); + PRAGMA integrity_check; + SELECT x,y FROM t1 INDEXED BY t1xy; + SELECT x,y,z FROM t1 NOT INDEXED; +} {ok alpha gamma alpha gamma 1} + + + +finish_test diff --git a/test/conflict3.test b/test/conflict3.test new file mode 100644 index 0000000..8eb4c1b --- /dev/null +++ b/test/conflict3.test @@ -0,0 +1,437 @@ +# 2013-11-05 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests for the conflict resolution extension +# to SQLite. +# +# This file focuses on making sure that combinations of REPLACE, +# IGNORE, and FAIL conflict resolution play well together. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix conflict3 + +ifcapable !conflict { + finish_test + return +} + +do_execsql_test 1.1 { + CREATE TABLE t1( + a INTEGER PRIMARY KEY ON CONFLICT REPLACE, + b UNIQUE ON CONFLICT IGNORE, + c UNIQUE ON CONFLICT FAIL + ); + INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert a row that conflicts on column B. The insert should be ignored. +# +do_execsql_test 1.2 { + INSERT INTO t1(a,b,c) VALUES(3,2,5); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert two rows where the second conflicts on C. The first row show go +# and and then there should be a constraint error. +# +do_test 1.3 { + catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} +} {1 {UNIQUE constraint failed: t1.c}} +do_execsql_test 1.4 { + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4 4 5 6} + +# Replete the tests above, but this time on a table non-INTEGER primary key. +# +do_execsql_test 2.1 { + DROP TABLE t1; + CREATE TABLE t1( + a INT PRIMARY KEY ON CONFLICT REPLACE, + b UNIQUE ON CONFLICT IGNORE, + c UNIQUE ON CONFLICT FAIL + ); + INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert a row that conflicts on column B. The insert should be ignored. +# +do_execsql_test 2.2 { + INSERT INTO t1(a,b,c) VALUES(3,2,5); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert two rows where the second conflicts on C. The first row show go +# and and then there should be a constraint error. +# +do_test 2.3 { + catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} +} {1 {UNIQUE constraint failed: t1.c}} +do_execsql_test 2.4 { + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4 4 5 6} + +# Replete again on a WITHOUT ROWID table. +# +do_execsql_test 3.1 { + DROP TABLE t1; + CREATE TABLE t1( + a INT PRIMARY KEY ON CONFLICT REPLACE, + b UNIQUE ON CONFLICT IGNORE, + c UNIQUE ON CONFLICT FAIL + ) WITHOUT ROWID; + INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert a row that conflicts on column B. The insert should be ignored. +# +do_execsql_test 3.2 { + INSERT INTO t1(a,b,c) VALUES(3,2,5); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert two rows where the second conflicts on C. The first row show go +# and and then there should be a constraint error. +# +do_test 3.3 { + catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} +} {1 {UNIQUE constraint failed: t1.c}} +do_execsql_test 3.4 { + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4 4 5 6} + +# Arrange the table rows in a different order and repeat. +# +do_execsql_test 4.1 { + DROP TABLE t1; + CREATE TABLE t1( + b UNIQUE ON CONFLICT IGNORE, + c UNIQUE ON CONFLICT FAIL, + a INT PRIMARY KEY ON CONFLICT REPLACE + ) WITHOUT ROWID; + INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert a row that conflicts on column B. The insert should be ignored. +# +do_execsql_test 4.2 { + INSERT INTO t1(a,b,c) VALUES(3,2,5); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert two rows where the second conflicts on C. The first row show go +# and and then there should be a constraint error. +# +do_test 4.3 { + catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} +} {1 {UNIQUE constraint failed: t1.c}} +do_execsql_test 4.4 { + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4 4 5 6} + +# Arrange the table rows in a different order and repeat. +# +do_execsql_test 5.1 { + DROP TABLE t1; + CREATE TABLE t1( + b UNIQUE ON CONFLICT IGNORE, + a INT PRIMARY KEY ON CONFLICT REPLACE, + c UNIQUE ON CONFLICT FAIL + ); + INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert a row that conflicts on column B. The insert should be ignored. +# +do_execsql_test 5.2 { + INSERT INTO t1(a,b,c) VALUES(3,2,5); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert two rows where the second conflicts on C. The first row show go +# and and then there should be a constraint error. +# +do_test 5.3 { + catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} +} {1 {UNIQUE constraint failed: t1.c}} +do_execsql_test 5.4 { + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4 4 5 6} + +# Arrange the table rows in a different order and repeat. +# +do_execsql_test 6.1 { + DROP TABLE t1; + CREATE TABLE t1( + c UNIQUE ON CONFLICT FAIL, + a INT PRIMARY KEY ON CONFLICT REPLACE, + b UNIQUE ON CONFLICT IGNORE + ); + INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert a row that conflicts on column B. The insert should be ignored. +# +do_execsql_test 6.2 { + INSERT INTO t1(a,b,c) VALUES(3,2,5); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert two rows where the second conflicts on C. The first row show go +# and and then there should be a constraint error. +# +do_test 6.3 { + catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} +} {1 {UNIQUE constraint failed: t1.c}} +do_execsql_test 6.4 { + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4 4 5 6} + +# Change which column is the PRIMARY KEY +# +do_execsql_test 7.1 { + DROP TABLE t1; + CREATE TABLE t1( + a UNIQUE ON CONFLICT REPLACE, + b INTEGER PRIMARY KEY ON CONFLICT IGNORE, + c UNIQUE ON CONFLICT FAIL + ); + INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert a row that conflicts on column B. The insert should be ignored. +# +do_execsql_test 7.2 { + INSERT INTO t1(a,b,c) VALUES(3,2,5); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert two rows where the second conflicts on C. The first row show go +# and and then there should be a constraint error. +# +do_test 7.3 { + catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} +} {1 {UNIQUE constraint failed: t1.c}} +do_execsql_test 7.4 { + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4 4 5 6} + +# Change which column is the PRIMARY KEY +# +do_execsql_test 8.1 { + DROP TABLE t1; + CREATE TABLE t1( + a UNIQUE ON CONFLICT REPLACE, + b INT PRIMARY KEY ON CONFLICT IGNORE, + c UNIQUE ON CONFLICT FAIL + ); + INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert a row that conflicts on column B. The insert should be ignored. +# +do_execsql_test 8.2 { + INSERT INTO t1(a,b,c) VALUES(3,2,5); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert two rows where the second conflicts on C. The first row show go +# and and then there should be a constraint error. +# +do_test 8.3 { + catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} +} {1 {UNIQUE constraint failed: t1.c}} +do_execsql_test 8.4 { + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4 4 5 6} + +# Change which column is the PRIMARY KEY +# +do_execsql_test 9.1 { + DROP TABLE t1; + CREATE TABLE t1( + a UNIQUE ON CONFLICT REPLACE, + b INT PRIMARY KEY ON CONFLICT IGNORE, + c UNIQUE ON CONFLICT FAIL + ) WITHOUT ROWID; + INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert a row that conflicts on column B. The insert should be ignored. +# +do_execsql_test 9.2 { + INSERT INTO t1(a,b,c) VALUES(3,2,5); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert two rows where the second conflicts on C. The first row show go +# and and then there should be a constraint error. +# +do_test 9.3 { + catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} +} {1 {UNIQUE constraint failed: t1.c}} +do_execsql_test 9.4 { + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4 4 5 6} + +# Change which column is the PRIMARY KEY +# +do_execsql_test 10.1 { + DROP TABLE t1; + CREATE TABLE t1( + a UNIQUE ON CONFLICT REPLACE, + b UNIQUE ON CONFLICT IGNORE, + c INTEGER PRIMARY KEY ON CONFLICT FAIL + ); + INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert a row that conflicts on column B. The insert should be ignored. +# +do_execsql_test 10.2 { + INSERT INTO t1(a,b,c) VALUES(3,2,5); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert two rows where the second conflicts on C. The first row show go +# and and then there should be a constraint error. +# +do_test 10.3 { + catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} +} {1 {UNIQUE constraint failed: t1.c}} +do_execsql_test 10.4 { + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4 4 5 6} + +# Change which column is the PRIMARY KEY +# +do_execsql_test 11.1 { + DROP TABLE t1; + CREATE TABLE t1( + a UNIQUE ON CONFLICT REPLACE, + b UNIQUE ON CONFLICT IGNORE, + c PRIMARY KEY ON CONFLICT FAIL + ) WITHOUT ROWID; + INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert a row that conflicts on column B. The insert should be ignored. +# +do_execsql_test 11.2 { + INSERT INTO t1(a,b,c) VALUES(3,2,5); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert two rows where the second conflicts on C. The first row show go +# and and then there should be a constraint error. +# +do_test 11.3 { + catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} +} {1 {UNIQUE constraint failed: t1.c}} +do_execsql_test 11.4 { + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4 4 5 6} + +# Check that ticket [f68dc596c4] has been fixed. +# +do_execsql_test 12.1 { + CREATE TABLE t2(a INTEGER PRIMARY KEY, b TEXT); + INSERT INTO t2 VALUES(111, '111'); +} +do_execsql_test 12.2 { + REPLACE INTO t2 VALUES(NULL, '112'), (111, '111B'); +} +do_execsql_test 12.3 { + SELECT * FROM t2; +} {111 111B 112 112} + +#------------------------------------------------------------------------- +ifcapable trigger { + reset_db + do_execsql_test 13.1.0 { + PRAGMA recursive_triggers = true; + CREATE TABLE t0 (c0 UNIQUE, c1 UNIQUE); + CREATE TRIGGER tr0 AFTER DELETE ON t0 BEGIN + DELETE FROM t0; + END; + + INSERT INTO t0 VALUES(1, NULL); + INSERT INTO t0 VALUES(0, NULL); + } + + do_catchsql_test 13.1.1 { + UPDATE OR REPLACE t0 SET c1 = 1; + } {1 {constraint failed}} + + integrity_check 13.1.2 + + do_execsql_test 13.1.3 { + SELECT * FROM t0 + } {1 {} 0 {}} + + do_execsql_test 13.2.0 { + CREATE TABLE t2 (a PRIMARY KEY, b UNIQUE, c UNIQUE) WITHOUT ROWID; + CREATE TRIGGER tr3 AFTER DELETE ON t2 BEGIN + DELETE FROM t2; + END; + + INSERT INTO t2 VALUES(1, 1, 1); + INSERT INTO t2 VALUES(2, 2, 2); + } + + do_catchsql_test 13.2.1 { + UPDATE OR REPLACE t2 SET c = 0; + } {1 {constraint failed}} + + integrity_check 13.2.2 + + do_execsql_test 13.2.3 { + SELECT * FROM t2 + } {1 1 1 2 2 2} + + do_execsql_test 13.3.0 { + CREATE TABLE t1(a, b); + CREATE TABLE log(x); + CREATE INDEX i1 ON t1(a); + INSERT INTO t1 VALUES(1, 2); + + CREATE TRIGGER tb BEFORE UPDATE ON t1 BEGIN + DELETE FROM t1; + END; + CREATE TRIGGER ta AFTER UPDATE ON t1 BEGIN + INSERT INTO log VALUES('fired!'); + END; + + UPDATE t1 SET b=3; + } + + do_execsql_test 13.3.1 { + SELECT * FROM t1; + } {} + do_execsql_test 13.3.2 { + SELECT * FROM log; + } {} +} + +finish_test diff --git a/test/contrib01.test b/test/contrib01.test new file mode 100644 index 0000000..43ea47c --- /dev/null +++ b/test/contrib01.test @@ -0,0 +1,90 @@ +# 2013-06-05 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file contains test cases that were contributed on the sqlite-users +# mailing list on 2013-06-05 by Mi Chen at mi.chen@echostar.com. +# +# At the time it was contributed, this test failed on trunk, but +# worked on the NGQP. + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Build some test data +# +do_test contrib01-1.0 { + db eval { + CREATE TABLE T1 (B INTEGER NOT NULL, + C INTEGER NOT NULL, + D INTEGER NOT NULL, + E INTEGER NOT NULL, + F INTEGER NOT NULL, + G INTEGER NOT NULL, + H INTEGER NOT NULL, + PRIMARY KEY (B, C, D)); + + CREATE TABLE T2 (A INTEGER NOT NULL, + B INTEGER NOT NULL, + C INTEGER NOT NULL, + PRIMARY KEY (A, B, C)); + + INSERT INTO T2(A, B, C) VALUES(702118,16183,15527); + INSERT INTO T2(A, B, C) VALUES(702118,16183,15560); + INSERT INTO T2(A, B, C) VALUES(702118,16183,15561); + INSERT INTO T2(A, B, C) VALUES(702118,16183,15563); + INSERT INTO T2(A, B, C) VALUES(702118,16183,15564); + INSERT INTO T2(A, B, C) VALUES(702118,16183,15566); + INSERT INTO T2(A, B, C) VALUES(702118,16183,15567); + INSERT INTO T2(A, B, C) VALUES(702118,16183,15569); + INSERT INTO T2(A, B, C) VALUES(702118,16183,15612); + INSERT INTO T2(A, B, C) VALUES(702118,16183,15613); + INSERT INTO T2(A, B, C) VALUES(702118,16183,15638); + INSERT INTO T2(A, B, C) VALUES(702118,16183,15681); + INSERT INTO T2(A, B, C) VALUES(702118,16183,15682); + + INSERT INTO T1(B, C, D, E, F, G, H) VALUES(16183,15527,6,0,5,5,0); + INSERT INTO T1(B, C, D, E, F, G, H) VALUES(16183,15560,6,0,5,2,0); + INSERT INTO T1(B, C, D, E, F, G, H) VALUES(16183,15561,6,0,5,2,0); + INSERT INTO T1(B, C, D, E, F, G, H) VALUES(16183,15563,6,0,5,2,0); + INSERT INTO T1(B, C, D, E, F, G, H) VALUES(16183,15564,6,0,5,2,0); + INSERT INTO T1(B, C, D, E, F, G, H) VALUES(16183,15566,6,0,5,2,0); + INSERT INTO T1(B, C, D, E, F, G, H) VALUES(16183,15567,6,0,5,2,0); + INSERT INTO T1(B, C, D, E, F, G, H) VALUES(16183,15569,6,0,5,2,0); + INSERT INTO T1(B, C, D, E, F, G, H) VALUES(16183,15612,6,0,5,5,0); + INSERT INTO T1(B, C, D, E, F, G, H) VALUES(16183,15613,6,0,5,2,0); + INSERT INTO T1(B, C, D, E, F, G, H) VALUES(16183,15638,6,0,5,2,0); + INSERT INTO T1(B, C, D, E, F, G, H) VALUES(16183,15681,6,0,5,5,0); + INSERT INTO T1(B, C, D, E, F, G, H) VALUES(16183,15682,6,0,5,2,0); + } +} {} +do_test contrib01-1.1 { + db eval { + SELECT T2.A, T2.B, T1.D, T1.E, T1.F, T1.G, T1.H, MAX(T1.C), '^' + FROM T1, T2 + WHERE T1.B = T2.B + AND T1.C = T2.C + GROUP BY T2.A, T2.B, T1.D, T1.E, T1.F, T1.G, T1.H + ORDER BY +max(t1.c); + } +} {702118 16183 6 0 5 5 0 15681 ^ 702118 16183 6 0 5 2 0 15682 ^} +do_test contrib01-1.2 { + db eval { + SELECT T2.A, T2.B, T1.D, T1.E, T1.F, T1.G, T1.H, MAX(T1.C), '^' + FROM T1, T2 + WHERE T1.B = T2.B + AND T1.C = T2.C + GROUP BY T2.A, T2.B, T1.F, T1.D, T1.E, T1.G, T1.H + ORDER BY +max(t1.c); + } +} {702118 16183 6 0 5 5 0 15681 ^ 702118 16183 6 0 5 2 0 15682 ^} + +finish_test diff --git a/test/corrupt.test b/test/corrupt.test new file mode 100644 index 0000000..62ead4d --- /dev/null +++ b/test/corrupt.test @@ -0,0 +1,349 @@ +# 2004 August 30 {} +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests to make sure SQLite does not crash or +# segfault if it sees a corrupt database file. +# +# $Id: corrupt.test,v 1.12 2009/07/13 09:41:45 danielk1977 Exp $ + +catch {forcedelete test.db test.db-journal test.bu} + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +# These tests deal with corrupt database files +# +database_may_be_corrupt + +# Construct a large database for testing. +# +do_test corrupt-1.1 { + execsql { + BEGIN; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(randstr(100,100)); + INSERT INTO t1 VALUES(randstr(90,90)); + INSERT INTO t1 VALUES(randstr(80,80)); + INSERT INTO t1 SELECT x || randstr(5,5) FROM t1; + INSERT INTO t1 SELECT x || randstr(6,6) FROM t1; + INSERT INTO t1 SELECT x || randstr(7,7) FROM t1; + INSERT INTO t1 SELECT x || randstr(8,8) FROM t1; + INSERT INTO t1 VALUES(randstr(3000,3000)); + INSERT INTO t1 SELECT x || randstr(9,9) FROM t1; + INSERT INTO t1 SELECT x || randstr(10,10) FROM t1; + INSERT INTO t1 SELECT x || randstr(11,11) FROM t1; + INSERT INTO t1 SELECT x || randstr(12,12) FROM t1; + CREATE INDEX t1i1 ON t1(x); + CREATE TABLE t2 AS SELECT * FROM t1; + DELETE FROM t2 WHERE rowid%5!=0; + COMMIT; + } +} {} +integrity_check corrupt-1.2 + +# Setup for the tests. Make a backup copy of the good database in test.bu. +# Create a string of garbage data that is 256 bytes long. +# +forcecopy test.db test.bu +set fsize [file size test.db] +set junk "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" +while {[string length $junk]<256} {append junk $junk} +set junk [string range $junk 0 255] + +# Go through the database and write garbage data into each 256 segment +# of the file. Then do various operations on the file to make sure that +# the database engine can recover gracefully from the corruption. +# +for {set i [expr {1*256}]} {$i<$fsize-256} {incr i 256} { + set tn [expr {$i/256}] + db close + forcecopy test.bu test.db + set fd [open test.db r+] + fconfigure $fd -translation binary + seek $fd $i + puts -nonewline $fd $junk + close $fd + do_test corrupt-2.$tn.1 { + sqlite3 db test.db + catchsql {SELECT count(*) FROM sqlite_master} + set x {} + } {} + do_test corrupt-2.$tn.2 { + catchsql {SELECT count(*) FROM t1} + set x {} + } {} + do_test corrupt-2.$tn.3 { + catchsql {SELECT count(*) FROM t1 WHERE x>'abcdef'} + set x {} + } {} + do_test corrupt-2.$tn.4 { + catchsql {SELECT count(*) FROM t2} + set x {} + } {} + do_test corrupt-2.$tn.5 { + catchsql {CREATE TABLE t3 AS SELECT * FROM t1} + set x {} + } {} + do_test corrupt-2.$tn.6 { + catchsql {DROP TABLE t1} + set x {} + } {} + do_test corrupt-2.$tn.7 { + catchsql {PRAGMA integrity_check} + set x {} + } {} + + # Check that no page references were leaked. + do_test corrupt-2.$tn.8 { + set bt [btree_from_db db] + db_enter db + array set stats [btree_pager_stats $bt] + db_leave db + set stats(ref) + } {0} +} + +#------------------------------------------------------------------------ +# For these tests, swap the rootpage entries of t1 (a table) and t1i1 (an +# index on t1) in sqlite_master. Then perform a few different queries +# and make sure this is detected as corruption. +# +do_test corrupt-3.1 { + db close + forcecopy test.bu test.db + sqlite3 db test.db + list +} {} +do_test corrupt-3.2 { + set t1_r [execsql {SELECT rootpage FROM sqlite_master WHERE name = 't1i1'}] + set t1i1_r [execsql {SELECT rootpage FROM sqlite_master WHERE name = 't1'}] + set cookie [expr [execsql {PRAGMA schema_version}] + 1] + sqlite3_db_config db DEFENSIVE 0 + execsql " + PRAGMA writable_schema = 1; + UPDATE sqlite_master SET rootpage = $t1_r WHERE name = 't1'; + UPDATE sqlite_master SET rootpage = $t1i1_r WHERE name = 't1i1'; + PRAGMA writable_schema = 0; + PRAGMA schema_version = $cookie; + " +} {} + +# This one tests the case caught by code in checkin [2313]. +do_test corrupt-3.3 { + db close + sqlite3 db test.db + catchsql { + INSERT INTO t1 VALUES('abc'); + } +} {1 {database disk image is malformed}} +do_test corrupt-3.4 { + db close + sqlite3 db test.db + catchsql { + SELECT * FROM t1; + } +} {1 {database disk image is malformed}} +do_test corrupt-3.5 { + db close + sqlite3 db test.db + catchsql { + SELECT * FROM t1 WHERE oid = 10; + } +} {1 {database disk image is malformed}} +do_test corrupt-3.6 { + db close + sqlite3 db test.db + catchsql { + SELECT * FROM t1 WHERE x = 'abcde'; + } +} {1 {database disk image is malformed}} + +do_test corrupt-4.1 { + db close + forcedelete test.db test.db-journal + sqlite3 db test.db + execsql { + PRAGMA page_size = 1024; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT); + } + for {set i 0} {$i < 10} {incr i} { + set text [string repeat $i 220] + execsql { INSERT INTO t1 VALUES($i, $text) } + } + execsql { CREATE INDEX i1 ON t1(b) } +} {} +do_test corrupt-4.2 { + set iRoot [db one {SELECT rootpage FROM sqlite_master WHERE name = 'i1'}] + set iOffset [hexio_get_int [hexio_read test.db [expr 12+($iRoot-1)*1024] 2]] + set data [hexio_render_int32 [expr $iRoot - 1]] + hexio_write test.db [expr ($iRoot-1)*1024 + $iOffset] $data + db close + sqlite3 db test.db + + # The following DELETE statement attempts to delete a cell stored on the + # root page of index i1. After this cell is deleted it must be replaced + # by a cell retrieved from the child page (a leaf) of the deleted cell. + # This will fail, as the block modified the database image so that the + # child page of the deleted cell is from a table (intkey) b-tree, not an + # index b-tree as expected. At one point this was causing an assert() + # to fail. + catchsql { DELETE FROM t1 WHERE rowid = 3 } +} {1 {database disk image is malformed}} + +do_test corrupt-5.1 { + db close + forcedelete test.db test.db-journal + sqlite3 db test.db + + execsql { PRAGMA page_size = 1024 } + set ct "CREATE TABLE t1(c0 " + set i 0 + while {[string length $ct] < 950} { append ct ", c[incr i]" } + append ct ")" + execsql $ct +} {} + +do_test corrupt-5.2 { + db close + hexio_write test.db 108 00000000 + sqlite3 db test.db + catchsql { SELECT * FROM sqlite_master } +} {1 {database disk image is malformed}} + +# At one point, the specific corruption caused by this test case was +# causing a buffer overwrite. Although a crash was never demonstrated, +# running this testcase under valgrind revealed the problem. +do_test corrupt-6.1 { + db close + forcedelete test.db test.db-journal + sqlite3 db test.db + execsql { + PRAGMA page_size = 1024; CREATE TABLE t1(x); + } + + # The root page of t1 is 1024 bytes in size. The header is 8 bytes, and + # each of the cells inserted by the following INSERT statements consume + # 16 bytes (including the 2 byte cell-offset array entry). So the page + # can contain up to 63 cells. + for {set i 0} {$i < 63} {incr i} { + execsql { INSERT INTO t1 VALUES( randomblob(10) ) } + } + + # Free the cell stored right at the end of the page (at offset pgsz-14). + execsql { DELETE FROM t1 WHERE rowid=1 } + set rootpage [db one {SELECT rootpage FROM sqlite_master WHERE name = 't1'}] + db close + + set offset [expr ($rootpage * 1024)-14+2] + hexio_write test.db $offset 00FF + sqlite3 db test.db + + catchsql { INSERT INTO t1 VALUES( randomblob(10) ) } +} {1 {database disk image is malformed}} + +ifcapable oversize_cell_check { + db close + forcedelete test.db test.db-journal + sqlite3 db test.db + execsql { + PRAGMA page_size = 1024; CREATE TABLE t1(x); + } + + do_test corrupt-7.1 { + for {set i 0} {$i < 39} {incr i} { + execsql { + INSERT INTO t1 VALUES(X'000100020003000400050006000700080009000A'); + } + } + } {} + db close + + # Corrupt the root page of table t1 so that the first offset in the + # cell-offset array points to the data for the SQL blob associated with + # record (rowid=10). The root page still passes the checks in btreeInitPage(), + # because the start of said blob looks like the start of a legitimate + # page cell. + # + # Test case cc-2 overwrites the blob so that it no longer looks like a + # real cell. But, by the time it is overwritten, btreeInitPage() has already + # initialized the root page, so no corruption is detected. + # + # Test case cc-3 inserts an extra record into t1, forcing balance-deeper + # to run. After copying the contents of the root page to the new child, + # btreeInitPage() is called on the child. This time, it detects corruption + # (because the start of the blob associated with the (rowid=10) record + # no longer looks like a real cell). At one point the code assumed that + # detecting corruption was not possible at that point, and an assert() failed. + # + set fd [open test.db r+] + fconfigure $fd -translation binary -encoding binary + seek $fd [expr 1024+8] + puts -nonewline $fd "\x03\x14" + close $fd + + sqlite3 db test.db + do_test corrupt-7.2 { + execsql { + UPDATE t1 SET x = X'870400020003000400050006000700080009000A' + WHERE rowid = 10; + } + } {} + do_test corrupt-7.3 { + catchsql { + INSERT INTO t1 VALUES(X'000100020003000400050006000700080009000A'); + } + } {1 {database disk image is malformed}} +} + +db close +forcedelete test.db test.db-journal +do_test corrupt-8.1 { + sqlite3 db test.db + execsql { + PRAGMA page_size = 1024; + PRAGMA secure_delete = on; + PRAGMA auto_vacuum = 0; + CREATE TABLE t1(x INTEGER PRIMARY KEY, y); + INSERT INTO t1 VALUES(5, randomblob(1900)); + } + + hexio_write test.db 2044 [hexio_render_int32 2] + hexio_write test.db 24 [hexio_render_int32 45] + + catchsql { INSERT OR REPLACE INTO t1 VALUES(5, randomblob(1900)) } +} {1 {database disk image is malformed}} + +db close +forcedelete test.db test.db-journal +do_test corrupt-8.2 { + sqlite3 db test.db + execsql { + PRAGMA page_size = 1024; + PRAGMA secure_delete = on; + PRAGMA auto_vacuum = 0; + CREATE TABLE t1(x INTEGER PRIMARY KEY, y); + INSERT INTO t1 VALUES(5, randomblob(900)); + INSERT INTO t1 VALUES(6, randomblob(900)); + } + + hexio_write test.db 2047 FF + hexio_write test.db 24 [hexio_render_int32 45] + + catchsql { INSERT INTO t1 VALUES(4, randomblob(1900)) } +} {1 {database disk image is malformed}} + +finish_test diff --git a/test/corrupt2.test b/test/corrupt2.test new file mode 100644 index 0000000..2e36cbd --- /dev/null +++ b/test/corrupt2.test @@ -0,0 +1,611 @@ +# 2004 August 30 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests to make sure SQLite does not crash or +# segfault if it sees a corrupt database file. +# +# $Id: corrupt2.test,v 1.20 2009/04/06 17:50:03 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix corrupt2 + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +# These tests deal with corrupt database files +# +database_may_be_corrupt + +set presql "" +catch { set presql "$::G(perm:presql);" } +unset -nocomplain ::G(perm:presql) + +# The following tests - corrupt2-1.* - create some databases corrupted in +# specific ways and ensure that SQLite detects them as corrupt. +# +do_test corrupt2-1.1 { + execsql { + PRAGMA auto_vacuum=0; + PRAGMA page_size=1024; + CREATE TABLE abc(a, b, c); + } +} {} + +do_test corrupt2-1.2 { + + # Corrupt the 16 byte magic string at the start of the file + forcedelete corrupt.db + forcedelete corrupt.db-journal + forcecopy test.db corrupt.db + set f [open corrupt.db RDWR] + seek $f 8 start + puts $f blah + close $f + + sqlite3 db2 corrupt.db + catchsql " + $::presql + SELECT * FROM sqlite_master; + " db2 +} {1 {file is not a database}} + +do_test corrupt2-1.3 { + db2 close + + # Corrupt the page-size (bytes 16 and 17 of page 1). + forcedelete corrupt.db + forcedelete corrupt.db-journal + forcecopy test.db corrupt.db + set f [open corrupt.db RDWR] + fconfigure $f -encoding binary + seek $f 16 start + puts -nonewline $f "\x00\xFF" + close $f + + sqlite3 db2 corrupt.db + catchsql " + $::presql + SELECT * FROM sqlite_master; + " db2 +} {1 {file is not a database}} + +do_test corrupt2-1.4 { + db2 close + + # Corrupt the free-block list on page 1. + forcedelete corrupt.db + forcedelete corrupt.db-journal + forcecopy test.db corrupt.db + set f [open corrupt.db RDWR] + fconfigure $f -encoding binary + seek $f 101 start + puts -nonewline $f "\xFF\xFF" + close $f + + sqlite3 db2 corrupt.db + # Note: This test is no longer meaningful due to the deferred computation + # of MemPage.nFree + catchsql {PRAGMA quick_check} db2 +} {0 {{*** in database main *** +Tree 1 page 1: free space corruption}}} + +do_test corrupt2-1.5 { + db2 close + + # Corrupt the free-block list on page 1. + forcedelete corrupt.db + forcedelete corrupt.db-journal + forcecopy test.db corrupt.db + set f [open corrupt.db RDWR] + fconfigure $f -encoding binary + seek $f 101 start + puts -nonewline $f "\x00\xC8" + seek $f 200 start + puts -nonewline $f "\x00\x00" + puts -nonewline $f "\x10\x00" + close $f + + sqlite3 db2 corrupt.db + catchsql {PRAGMA quick_check} db2 +} {0 {{*** in database main *** +Tree 1 page 1: free space corruption}}} +db2 close + +# Corrupt a database by having 2 indices of the same name: +do_test corrupt2-2.1 { + + forcedelete corrupt.db + forcedelete corrupt.db-journal + forcecopy test.db corrupt.db + + sqlite3 db2 corrupt.db + sqlite3_db_config db2 DEFENSIVE 0 + execsql " + $::presql + CREATE INDEX a1 ON abc(a); + CREATE INDEX a2 ON abc(b); + PRAGMA writable_schema = 1; + UPDATE sqlite_master + SET name = 'a3', sql = 'CREATE INDEX a3' || substr(sql, 16, 10000) + WHERE type = 'index'; + PRAGMA writable_schema = 0; + " db2 + + db2 close + sqlite3 db2 corrupt.db + catchsql " + $::presql + SELECT * FROM sqlite_master; + " db2 +} {1 {malformed database schema (a3) - index a3 already exists}} + +db2 close + +do_test corrupt2-3.1 { + forcedelete corrupt.db + forcedelete corrupt.db-journal + sqlite3 db2 corrupt.db + + execsql " + $::presql + PRAGMA auto_vacuum = 1; + PRAGMA page_size = 1024; + CREATE TABLE t1(a, b, c); + CREATE TABLE t2(a, b, c); + INSERT INTO t2 VALUES(randomblob(100), randomblob(100), randomblob(100)); + INSERT INTO t2 SELECT * FROM t2; + INSERT INTO t2 SELECT * FROM t2; + INSERT INTO t2 SELECT * FROM t2; + INSERT INTO t2 SELECT * FROM t2; + " db2 + + db2 close + + # On the root page of table t2 (page 4), set one of the child page-numbers + # to 0. This corruption will be detected when SQLite attempts to update + # the pointer-map after moving the content of page 4 to page 3 as part + # of the DROP TABLE operation below. + # + set fd [open corrupt.db r+] + fconfigure $fd -encoding binary -translation binary + seek $fd [expr 1024*3 + 12] + set zCelloffset [read $fd 2] + binary scan $zCelloffset S iCelloffset + seek $fd [expr 1024*3 + $iCelloffset] + puts -nonewline $fd "\00\00\00\00" + close $fd + + sqlite3 db2 corrupt.db + catchsql " + $::presql + DROP TABLE t1; + " db2 +} {1 {database disk image is malformed}} + +do_test corrupt2-4.1 { + catchsql { + SELECT * FROM t2; + } db2 +} {1 {database disk image is malformed}} + +db2 close + +unset -nocomplain result +do_test corrupt2-5.1 { + forcedelete corrupt.db + forcedelete corrupt.db-journal + sqlite3 db2 corrupt.db + + execsql " + $::presql + PRAGMA auto_vacuum = 0; + PRAGMA page_size = 1024; + CREATE TABLE t1(a, b, c); + CREATE TABLE t2(a, b, c); + INSERT INTO t2 VALUES(randomblob(100), randomblob(100), randomblob(100)); + INSERT INTO t2 SELECT * FROM t2; + INSERT INTO t2 SELECT * FROM t2; + INSERT INTO t2 SELECT * FROM t2; + INSERT INTO t2 SELECT * FROM t2; + INSERT INTO t1 SELECT * FROM t2; + " db2 + + db2 close + + # This block links a page from table t2 into the t1 table structure. + # + set fd [open corrupt.db r+] + fconfigure $fd -encoding binary -translation binary + seek $fd [expr 1024 + 12] + set zCelloffset [read $fd 2] + binary scan $zCelloffset S iCelloffset + seek $fd [expr 1024 + $iCelloffset] + set zChildPage [read $fd 4] + seek $fd [expr 2*1024 + 12] + set zCelloffset [read $fd 2] + binary scan $zCelloffset S iCelloffset + seek $fd [expr 2*1024 + $iCelloffset] + puts -nonewline $fd $zChildPage + close $fd + + sqlite3 db2 corrupt.db + db2 eval $::presql + db2 eval {SELECT rowid FROM t1} { + set result [db2 eval {pragma integrity_check}] + break + } + set result +} {{*** in database main *** +Tree 2 page 2 cell 0: 2nd reference to page 10 +Page 4: never used}} + +db2 close + +proc corruption_test {args} { + set A(-corrupt) {} + set A(-sqlprep) {} + set A(-tclprep) {} + array set A $args + + catch {db close} + forcedelete corrupt.db + forcedelete corrupt.db-journal + + sqlite3 db corrupt.db + sqlite3_db_config db DEFENSIVE 0 + db eval $::presql + eval $A(-tclprep) + db eval $A(-sqlprep) + db close + + eval $A(-corrupt) + + sqlite3 db corrupt.db + eval $A(-test) +} + +ifcapable autovacuum { + # The tests within this block - corrupt2-6.* - aim to test corruption + # detection within an incremental-vacuum. When an incremental-vacuum + # step is executed, the last non-free page of the database file is + # moved into a free space in the body of the file. After doing so, + # the page reference in the parent page must be updated to refer + # to the new location. These tests test the outcome of corrupting + # that page reference before performing the incremental vacuum. + # + + # The last page in the database page is the second page + # in an overflow chain. + # + corruption_test -sqlprep { + PRAGMA auto_vacuum = incremental; + PRAGMA page_size = 1024; + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, randomblob(2500)); + INSERT INTO t1 VALUES(2, randomblob(2500)); + DELETE FROM t1 WHERE a = 1; + } -corrupt { + hexio_write corrupt.db [expr 1024*5] 00000008 + } -test { + do_test corrupt2-6.1 { + catchsql " $::presql pragma incremental_vacuum = 1 " + } {1 {database disk image is malformed}} + } + + # The last page in the database page is a non-root b-tree page. + # + corruption_test -sqlprep { + PRAGMA auto_vacuum = incremental; + PRAGMA page_size = 1024; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + INSERT INTO t1 VALUES(1, randomblob(2500)); + INSERT INTO t1 VALUES(2, randomblob(50)); + INSERT INTO t1 SELECT NULL, randomblob(50) FROM t1; + INSERT INTO t1 SELECT NULL, randomblob(50) FROM t1; + INSERT INTO t1 SELECT NULL, randomblob(50) FROM t1; + INSERT INTO t1 SELECT NULL, randomblob(50) FROM t1; + DELETE FROM t1 WHERE a = 1; + } -corrupt { + hexio_write corrupt.db [expr 1024*2 + 8] 00000009 + } -test { + do_test corrupt2-6.2 { + catchsql " $::presql pragma incremental_vacuum = 1 " + } {1 {database disk image is malformed}} + } + + # Set up a pointer-map entry so that the last page of the database + # file appears to be a b-tree root page. This should be detected + # as corruption. + # + corruption_test -sqlprep { + PRAGMA auto_vacuum = incremental; + PRAGMA page_size = 1024; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + INSERT INTO t1 VALUES(1, randomblob(2500)); + INSERT INTO t1 VALUES(2, randomblob(2500)); + INSERT INTO t1 VALUES(3, randomblob(2500)); + DELETE FROM t1 WHERE a = 1; + } -corrupt { + set nPage [expr [file size corrupt.db] / 1024] + hexio_write corrupt.db [expr 1024 + ($nPage-3)*5] 010000000 + } -test { + do_test corrupt2-6.3 { + catchsql " $::presql pragma incremental_vacuum = 1 " + } {1 {database disk image is malformed}} + } + + if {![nonzero_reserved_bytes]} { + corruption_test -sqlprep { + PRAGMA auto_vacuum = 1; + PRAGMA page_size = 1024; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + INSERT INTO t1 VALUES(1, randomblob(2500)); + DELETE FROM t1 WHERE a = 1; + } -corrupt { + set nAppend [expr 1024*207 - [file size corrupt.db]] + set fd [open corrupt.db r+] + seek $fd 0 end + puts -nonewline $fd [string repeat x $nAppend] + close $fd + hexio_write corrupt.db 28 00000000 + } -test { + do_test corrupt2-6.4 { + catchsql " + $::presql + BEGIN EXCLUSIVE; + COMMIT; + " + } {1 {database disk image is malformed}} + } + } +} + + +set sqlprep { + PRAGMA auto_vacuum = 0; + PRAGMA page_size = 1024; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + CREATE INDEX i1 ON t1(b); + INSERT INTO t1 VALUES(1, randomblob(50)); + INSERT INTO t1 SELECT NULL, randomblob(50) FROM t1; + INSERT INTO t1 SELECT NULL, randomblob(50) FROM t1; + INSERT INTO t1 SELECT NULL, randomblob(50) FROM t1; + INSERT INTO t1 SELECT NULL, randomblob(50) FROM t1; + INSERT INTO t1 SELECT NULL, randomblob(50) FROM t1; + INSERT INTO t1 SELECT NULL, randomblob(50) FROM t1; +} + +corruption_test -sqlprep $sqlprep -corrupt { + # Set the page-flags of one of the leaf pages of the index B-Tree to + # 0x0D (interpreted by SQLite as "leaf page of a table B-Tree"). + # + set fd [open corrupt.db r+] + fconfigure $fd -translation binary -encoding binary + seek $fd [expr 1024*2 + 8] + set zRightChild [read $fd 4] + binary scan $zRightChild I iRightChild + seek $fd [expr 1024*($iRightChild-1)] + puts -nonewline $fd "\x0D" + close $fd +} -test { + do_test corrupt2-7.1 { + catchsql " $::presql SELECT b FROM t1 ORDER BY b ASC " + } {1 {database disk image is malformed}} +} + +corruption_test -sqlprep $sqlprep -corrupt { + # Mess up the page-header of one of the leaf pages of the index B-Tree. + # The corruption is detected as part of an OP_Prev opcode. + # + set fd [open corrupt.db r+] + fconfigure $fd -translation binary -encoding binary + seek $fd [expr 1024*2 + 12] + set zCellOffset [read $fd 2] + binary scan $zCellOffset S iCellOffset + seek $fd [expr 1024*2 + $iCellOffset] + set zChild [read $fd 4] + binary scan $zChild I iChild + seek $fd [expr 1024*($iChild-1)+3] + puts -nonewline $fd "\xFFFF" + close $fd +} -test { + do_test corrupt2-7.1 { + catchsql " $::presql SELECT b FROM t1 ORDER BY b DESC " + } {1 {database disk image is malformed}} +} + +corruption_test -sqlprep $sqlprep -corrupt { + # Set the page-flags of one of the leaf pages of the table B-Tree to + # 0x0A (interpreted by SQLite as "leaf page of an index B-Tree"). + # + set fd [open corrupt.db r+] + fconfigure $fd -translation binary -encoding binary + seek $fd [expr 1024*1 + 8] + set zRightChild [read $fd 4] + binary scan $zRightChild I iRightChild + seek $fd [expr 1024*($iRightChild-1)] + puts -nonewline $fd "\x0A" + close $fd +} -test { + do_test corrupt2-8.1 { + catchsql " $::presql SELECT * FROM t1 WHERE rowid=1000 " + } {1 {database disk image is malformed}} +} + +corruption_test -sqlprep { + CREATE TABLE t1(a, b, c); CREATE TABLE t8(a, b, c); CREATE TABLE tE(a, b, c); + CREATE TABLE t2(a, b, c); CREATE TABLE t9(a, b, c); CREATE TABLE tF(a, b, c); + CREATE TABLE t3(a, b, c); CREATE TABLE tA(a, b, c); CREATE TABLE tG(a, b, c); + CREATE TABLE t4(a, b, c); CREATE TABLE tB(a, b, c); CREATE TABLE tH(a, b, c); + CREATE TABLE t5(a, b, c); CREATE TABLE tC(a, b, c); CREATE TABLE tI(a, b, c); + CREATE TABLE t6(a, b, c); CREATE TABLE tD(a, b, c); CREATE TABLE tJ(a, b, c); + CREATE TABLE x1(a, b, c); CREATE TABLE x8(a, b, c); CREATE TABLE xE(a, b, c); + CREATE TABLE x2(a, b, c); CREATE TABLE x9(a, b, c); CREATE TABLE xF(a, b, c); + CREATE TABLE x3(a, b, c); CREATE TABLE xA(a, b, c); CREATE TABLE xG(a, b, c); + CREATE TABLE x4(a, b, c); CREATE TABLE xB(a, b, c); CREATE TABLE xH(a, b, c); + CREATE TABLE x5(a, b, c); CREATE TABLE xC(a, b, c); CREATE TABLE xI(a, b, c); + CREATE TABLE x6(a, b, c); CREATE TABLE xD(a, b, c); CREATE TABLE xJ(a, b, c); +} -corrupt { + set fd [open corrupt.db r+] + fconfigure $fd -translation binary -encoding binary + seek $fd 108 + set zRightChild [read $fd 4] + binary scan $zRightChild I iRightChild + seek $fd [expr 1024*($iRightChild-1)+3] + puts -nonewline $fd "\x00\x00" + close $fd +} -test { + do_test corrupt2-9.1 { + catchsql " $::presql SELECT sql FROM sqlite_master " + } {1 {database disk image is malformed}} +} + +corruption_test -sqlprep { + CREATE TABLE t1(a, b, c); + CREATE TABLE t2(a, b, c); + PRAGMA writable_schema = 1; + UPDATE sqlite_master SET rootpage = NULL WHERE name = 't2'; +} -test { + do_test corrupt2-10.1 { + catchsql " $::presql SELECT * FROM t2 " + } {1 {malformed database schema (t2)}} + do_test corrupt2-10.2 { + sqlite3_errcode db + } {SQLITE_CORRUPT} +} + +corruption_test -sqlprep { + PRAGMA auto_vacuum = incremental; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + CREATE TABLE t2(a INTEGER PRIMARY KEY, b); + INSERT INTO t1 VALUES(1, randstr(100,100)); + INSERT INTO t1 SELECT NULL, randstr(100,100) FROM t1; + INSERT INTO t1 SELECT NULL, randstr(100,100) FROM t1; + INSERT INTO t1 SELECT NULL, randstr(100,100) FROM t1; + INSERT INTO t1 SELECT NULL, randstr(100,100) FROM t1; + INSERT INTO t1 SELECT NULL, randstr(100,100) FROM t1; + INSERT INTO t2 SELECT * FROM t1; + DELETE FROM t1; +} -corrupt { + set offset [expr [file size corrupt.db] - 1024] + hexio_write corrupt.db $offset FF + hexio_write corrupt.db 24 12345678 +} -test { + do_test corrupt2-11.1 { + catchsql " $::presql PRAGMA incremental_vacuum " + } {1 {database disk image is malformed}} +} +corruption_test -sqlprep { + PRAGMA auto_vacuum = incremental; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + CREATE TABLE t2(a INTEGER PRIMARY KEY, b); + INSERT INTO t1 VALUES(1, randstr(100,100)); + INSERT INTO t1 SELECT NULL, randstr(100,100) FROM t1; + INSERT INTO t1 SELECT NULL, randstr(100,100) FROM t1; + INSERT INTO t1 SELECT NULL, randstr(100,100) FROM t1; + INSERT INTO t1 SELECT NULL, randstr(100,100) FROM t1; + INSERT INTO t1 SELECT NULL, randstr(100,100) FROM t1; + INSERT INTO t2 SELECT * FROM t1; + DELETE FROM t1; +} -corrupt { + set pgno [expr [file size corrupt.db] / 1024] + hexio_write corrupt.db [expr 1024+5*($pgno-3)] 03 + hexio_write corrupt.db 24 12345678 +} -test { + do_test corrupt2-12.1 { + catchsql " $::presql PRAGMA incremental_vacuum " + } {1 {database disk image is malformed}} +} + +ifcapable autovacuum { + # It is not possible for the last page in a database file to be the + # pending-byte page (AKA the locking page). This test verifies that if + # an attempt is made to commit a transaction to such an auto-vacuum + # database SQLITE_CORRUPT is returned. + # + corruption_test -tclprep { + db eval { + PRAGMA auto_vacuum = full; + PRAGMA page_size = 1024; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + INSERT INTO t1 VALUES(NULL, randstr(50,50)); + } + for {set ii 0} {$ii < 10} {incr ii} { + db eval " $::presql INSERT INTO t1 SELECT NULL, randstr(50,50) FROM t1 " + } + } -corrupt { + do_test corrupt2-13.1 { + file size corrupt.db + } $::sqlite_pending_byte + hexio_write corrupt.db [expr $::sqlite_pending_byte+1023] 00 + hexio_write corrupt.db 28 00000000 + } -test { + do_test corrupt2-13.2 { + file size corrupt.db + } [expr $::sqlite_pending_byte + 1024] + do_test corrupt2-13.3 { + catchsql { DELETE FROM t1 WHERE rowid < 30; } + } {1 {database disk image is malformed}} + } +} + +#------------------------------------------------------------------------- +# Test that PRAGMA integrity_check detects cases where the freelist-count +# header field is smaller than the actual number of pages on the freelist. +# + +reset_db +do_execsql_test 14.0 { + PRAGMA auto_vacuum = 0; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(randomblob(3500)); + DELETE FROM t1; +} + +do_execsql_test 14.1 { + PRAGMA integrity_check; + PRAGMA freelist_count; +} {ok 3} + +# There are now 3 free pages. Modify the header-field so that it +# (incorrectly) says that just 2 are free. +do_test 14.2 { + db close + hexio_write test.db 36 [hexio_render_int32 2] + sqlite3 db test.db + execsql { PRAGMA freelist_count } +} {2} + +do_execsql_test 14.3 { + PRAGMA integrity_check; +} {{*** in database main *** +Freelist: size is 3 but should be 2}} + +# Use 2 of the free pages on the free-list. +# +do_execsql_test 14.4 { + INSERT INTO t1 VALUES(randomblob(2500)); + PRAGMA freelist_count; +} {0} + +do_execsql_test 14.5 { + PRAGMA integrity_check; +} {{*** in database main *** +Freelist: size is 1 but should be 0}} + + +finish_test + +finish_test diff --git a/test/corrupt3.test b/test/corrupt3.test new file mode 100644 index 0000000..691302f --- /dev/null +++ b/test/corrupt3.test @@ -0,0 +1,121 @@ +# 2007 April 6 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests to make sure SQLite does not crash or +# segfault if it sees a corrupt database file. +# +# $Id: corrupt3.test,v 1.2 2007/04/06 21:42:22 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# This module uses hard-coded offsets which do not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} + +# These tests deal with corrupt database files +# +database_may_be_corrupt + +# We must have the page_size pragma for these tests to work. +# +ifcapable !pager_pragmas||direct_read { + finish_test + return +} + +# Create a database with an overflow page. +# +do_test corrupt3-1.1 { + set bigstring [string repeat 0123456789 200] + execsql { + PRAGMA auto_vacuum=OFF; + PRAGMA page_size=1024; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES($bigstring); + } + file size test.db +} [expr {1024*3}] + +# Verify that the file format is as we expect. The page size +# should be 1024 bytes. The only record should have a single +# overflow page. The overflow page is page 3. The pointer to +# the overflow page is on the last 4 bytes of page 2. +# +do_test corrupt3-1.2 { + hexio_get_int [hexio_read test.db 16 2] +} 1024 ;# The page size is 1024 +do_test corrupt3-1.3 { + hexio_get_int [hexio_read test.db 20 1] +} 0 ;# Unused bytes per page is 0 +do_test corrupt3-1.4 { + hexio_get_int [hexio_read test.db 2044 4] +} 3 ;# Overflow page is 3 +do_test corrupt3-1.5 { + hexio_get_int [hexio_read test.db 2048 4] +} 0 ;# First chained overflow is 0 + +integrity_check corrupt3-1.6 + +# Make the overflow chain loop back on itself. See if the +# corruption is detected. +# +do_test corrupt3-1.7 { + db close + hexio_write test.db 2048 [hexio_render_int32 3] + sqlite3 db test.db + catchsql { + SELECT x FROM t1 + } +} [list 0 $bigstring] +do_test corrupt3-1.8 { + catchsql { + PRAGMA integrity_check + } +} {0 {{*** in database main *** +Tree 2 page 2 cell 0: 2nd reference to page 3}}} + +# Change the pointer for the first page of the overflow +# change to be a non-existant page. +# +do_test corrupt3-1.9 { + db close + hexio_write test.db 2044 [hexio_render_int32 4] + sqlite3 db test.db + catchsql { + SELECT substr(x,1,10) FROM t1 + } +} [list 1 {database disk image is malformed}] +do_test corrupt3-1.10 { + catchsql { + PRAGMA integrity_check + } +} {0 {{*** in database main *** +Tree 2 page 2 cell 0: invalid page number 4 +Page 3: never used}}} +do_test corrupt3-1.11 { + db close + hexio_write test.db 2044 [hexio_render_int32 0] + sqlite3 db test.db + catchsql { + SELECT substr(x,1,10) FROM t1 + } +} [list 1 {database disk image is malformed}] +do_test corrupt3-1.12 { + catchsql { + PRAGMA integrity_check + } +} {0 {{*** in database main *** +Tree 2 page 2 cell 0: overflow list length is 0 but should be 1 +Page 3: never used}}} + +finish_test diff --git a/test/corrupt4.test b/test/corrupt4.test new file mode 100644 index 0000000..5b0965a --- /dev/null +++ b/test/corrupt4.test @@ -0,0 +1,149 @@ +# 2007 Sept 7 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests to make sure SQLite does not crash or +# segfault if it sees a corrupt database file. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix corrupt4 + +# This module uses hard-coded offsets which do not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} + +# These tests deal with corrupt database files +# +database_may_be_corrupt + +# We must have the page_size pragma for these tests to work. +# +ifcapable !pager_pragmas { + finish_test + return +} + +# Create a database with a freelist containing at least two pages. +# +do_test corrupt4-1.1 { + set bigstring [string repeat 0123456789 200] + execsql { + PRAGMA auto_vacuum=OFF; + PRAGMA page_size=1024; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES($bigstring); + CREATE TABLE t2(y); + INSERT INTO t2 VALUES(1); + DROP TABLE t1; + } + file size test.db +} [expr {1024*4}] + +# Verify that there are two pages on the freelist. +# +do_test corrupt4-1.2 { + execsql {PRAGMA freelist_count} +} {2} + +# Get the page number for the trunk of the freelist. +# +set trunkpgno [hexio_get_int [hexio_read test.db 32 4]] +set baseaddr [expr {($trunkpgno-1)*1024}] + +# Verify that the trunk of the freelist has exactly one +# leaf. +# +do_test corrupt4-1.3 { + hexio_get_int [hexio_read test.db [expr {$::baseaddr+4}] 4] +} {1} + +# Insert a negative number as the number of leaves on the trunk. +# Then try to add a new element to the freelist. +# +do_test corrupt4-1.4 { + hexio_write test.db [expr {$::baseaddr+4}] [hexio_render_int32 -100000000] + db close + sqlite3 db test.db + catchsql { + DROP TABLE t2 + } +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- + +reset_db +do_execsql_test 2.0 { + PRAGMA page_size = 512; + CREATE TABLE t1(a, b, c); +} + +# Create a database with a schema so large that the root of the +# sqlite_schema table is the grandparent of its leaves. +# +set nView 1000 +do_test 2.1 { + execsql BEGIN + for {set ii 0} {$ii<$nView} {incr ii} { + execsql " CREATE VIEW v$ii AS SELECT a, b, c FROM t1 " + } + execsql COMMIT +} {} +db close + +proc get2byte {fd offset} { + seek $fd $offset + set bin [read $fd 2] + binary scan $bin S val + set val +} +proc get4byte {fd offset} { + seek $fd $offset + set bin [read $fd 4] + binary scan $bin I val + set val +} +proc put4byte {fd offset val} { + seek $fd $offset + set bin [binary format I $val] + puts -nonewline $fd $bin +} + +# Page 1 is now the grandparent of its leaves. Corrupt the database by setting +# the second rightmost child page number of page 1 to 1. +# +set fd [open test.db r+] +fconfigure $fd -encoding binary -translation binary +set nChild [get2byte $fd 103] +set offChild [get2byte $fd [expr 100+12+($nChild-2)*2]] +set pgnoChild [get4byte $fd $offChild] +put4byte $fd $offChild 1 +close $fd + +if {![info exists ::G(perm:presql)]} { + sqlite3 db test.db + + do_catchsql_test 2.2 { + PRAGMA writable_schema = 1; + SELECT * FROM sqlite_schema; + } {1 {database disk image is malformed}} + + do_test 2.3 { + list [catch { + for {set ii $nView} {$ii<$nView*2} {incr ii} { + execsql "INSERT INTO sqlite_master VALUES(1, 2, 3, 4, 5)" + } + } msg] $msg + } {1 {database disk image is malformed}} +} + +finish_test diff --git a/test/corrupt5.test b/test/corrupt5.test new file mode 100644 index 0000000..7509766 --- /dev/null +++ b/test/corrupt5.test @@ -0,0 +1,50 @@ +# 2008 Jan 22 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests to make sure SQLite does not crash or +# segfault if it sees a corrupt database file. Checks for +# malformed schema. +# +# $Id: corrupt5.test,v 1.3 2009/06/04 02:47:04 shane Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# These tests deal with corrupt database files +# +database_may_be_corrupt + +# We must have the page_size pragma for these tests to work. +# +ifcapable !pager_pragmas { + finish_test + return +} + +# Create a database with a freelist containing at least two pages. +# +do_test corrupt5-1.1 { + sqlite3_db_config db DEFENSIVE 0 + execsql { + CREATE TABLE t1(a,b,c); + CREATE INDEX i1 ON t1(a,b); + PRAGMA writable_schema=ON; + UPDATE sqlite_master SET name=NULL, sql=NULL WHERE name='i1'; + } + db close + sqlite3 db test.db + catchsql { + SELECT * FROM t1 + } +} {1 {malformed database schema (?)}} + +finish_test diff --git a/test/corrupt6.test b/test/corrupt6.test new file mode 100644 index 0000000..dd773c9 --- /dev/null +++ b/test/corrupt6.test @@ -0,0 +1,259 @@ +# 2008 May 6 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests to make sure SQLite does not crash or +# segfault if it sees a corrupt database file. It specifically focuses +# on corrupt SerialTypeLen values. +# +# $Id: corrupt6.test,v 1.2 2008/05/19 15:37:10 shane Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# This module uses hard-coded offsets which do not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} + +# These tests deal with corrupt database files +# +database_may_be_corrupt + +# We must have the page_size pragma for these tests to work. +# +ifcapable !pager_pragmas { + finish_test + return +} + +# Create a simple, small database. +# +do_test corrupt6-1.1 { + execsql { + PRAGMA auto_vacuum=OFF; + PRAGMA page_size=1024; + CREATE TABLE t1(x); + INSERT INTO t1(x) VALUES('varint32-01234567890123456789012345678901234567890123456789'); + INSERT INTO t1(x) VALUES('varint32-01234567890123456789012345678901234567890123456789'); + } + file size test.db +} [expr {1024*2}] + +# Verify that the file format is as we expect. The page size +# should be 1024 bytes. +# +do_test corrupt6-1.2 { + hexio_get_int [hexio_read test.db 16 2] +} 1024 ;# The page size is 1024 +do_test corrupt6-1.3 { + hexio_get_int [hexio_read test.db 20 1] +} 0 ;# Unused bytes per page is 0 + +integrity_check corrupt6-1.4 + +# Verify SerialTypeLen for first field of two records as we expect. +# SerialTypeLen = (len*2+12) = 60*2+12 = 132 +do_test corrupt6-1.5.1 { + hexio_read test.db 1923 2 +} 8103 ;# First text field size is 81 03 == 131 +do_test corrupt6-1.5.2 { + hexio_read test.db 1987 2 +} 8103 ;# Second text field size is 81 03 == 131 + +# Verify simple query results as expected. +do_test corrupt6-1.6 { + db close + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 0 {varint32 varint32} ] +integrity_check corrupt6-1.7 + +# Adjust value of record 1 / field 1 SerialTypeLen and see if the +# corruption is detected. +# Increase SerialTypeLen by 2. +do_test corrupt6-1.8.1 { + db close + hexio_write test.db 1923 8105 + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 1 {database disk image is malformed}] + +# Adjust value of record 1 / field 1 SerialTypeLen and see if the +# corruption is detected. +# Decrease SerialTypeLen by 2. +do_test corrupt6-1.8.2 { + db close + hexio_write test.db 1923 8101 + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 1 {database disk image is malformed}] + +# Put value of record 1 / field 1 SerialTypeLen back. +do_test corrupt6-1.8.3 { + db close + hexio_write test.db 1923 8103 + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 0 {varint32 varint32} ] +integrity_check corrupt6-1.8.4 + +# Adjust value of record 2 / field 1 SerialTypeLen and see if the +# corruption is detected. +# Increase SerialTypeLen by 2. +do_test corrupt6-1.9.1 { + db close + hexio_write test.db 1987 8105 + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 1 {database disk image is malformed}] + +# Adjust value of record 2 / field 2 SerialTypeLen and see if the +# corruption is detected. +# Decrease SerialTypeLen by 2. +do_test corrupt6-1.9.2 { + db close + hexio_write test.db 1987 8101 + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 1 {database disk image is malformed}] + +# Put value of record 1 / field 2 SerialTypeLen back. +do_test corrupt6-1.9.3 { + db close + hexio_write test.db 1987 8103 + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 0 {varint32 varint32} ] +integrity_check corrupt6-1.9.4 + +# Adjust value of record 1 / field 1 SerialTypeLen and see if the +# corruption is detected. +# Set SerialTypeLen to FF 7F (2 bytes) +do_test corrupt6-1.10.1 { + db close + hexio_write test.db 1923 FF7F + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 1 {database disk image is malformed}] + +# Adjust value of record 1 / field 1 SerialTypeLen and see if the +# corruption is detected. +# Set SerialTypeLen to FF FF 7F (3 bytes) +do_test corrupt6-1.10.2 { + db close + hexio_write test.db 1923 FFFF7F + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 1 {database disk image is malformed}] + +# Adjust value of record 1 / field 1 SerialTypeLen and see if the +# corruption is detected. +# Set SerialTypeLen to FF FF FF 7F (4 bytes) +do_test corrupt6-1.10.3 { + db close + hexio_write test.db 1923 FFFFFF7F + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 1 {database disk image is malformed}] + +# Adjust value of record 1 / field 1 SerialTypeLen and see if the +# corruption is detected. +# Set SerialTypeLen to FF FF FF FF 7F (5 bytes) +do_test corrupt6-1.10.4 { + db close + hexio_write test.db 1923 FFFFFFFF7F + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 1 {database disk image is malformed}] + +# Adjust value of record 1 / field 1 SerialTypeLen and see if the +# corruption is detected. +# Set SerialTypeLen to FF FF FF FF FF 7F (6 bytes, and overflows). +do_test corrupt6-1.10.5 { + db close + hexio_write test.db 1923 FFFFFFFFFF7F + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 1 {database disk image is malformed}] + +# Adjust value of record 1 / field 1 SerialTypeLen and see if the +# corruption is detected. +# Set SerialTypeLen to FF FF FF FF FF FF 7F (7 bytes, and overflows). +do_test corrupt6-1.10.6 { + db close + hexio_write test.db 1923 FFFFFFFFFFFF7F + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 1 {database disk image is malformed}] + +# Adjust value of record 1 / field 1 SerialTypeLen and see if the +# corruption is detected. +# Set SerialTypeLen to FF FF FF FF FF FF FF 7F (8 bytes, and overflows). +do_test corrupt6-1.10.7 { + db close + hexio_write test.db 1923 FFFFFFFFFFFFFF7F + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 1 {database disk image is malformed}] + +# Adjust value of record 1 / field 1 SerialTypeLen and see if the +# corruption is detected. +# Set SerialTypeLen to FF FF FF FF FF FF FF FF 7F (9 bytes, and overflows). +do_test corrupt6-1.10.8 { + db close + hexio_write test.db 1923 FFFFFFFFFFFFFFFF7F + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 1 {database disk image is malformed}] + +# Adjust value of record 1 / field 1 SerialTypeLen and see if the +# corruption is detected. +# Set SerialTypeLen to FFFF FF FF FF FF FF FF FF 7F (10 bytes, and overflows). +do_test corrupt6-1.10.9 { + db close + hexio_write test.db 1923 FFFFFFFFFFFFFFFFFF7F + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 1 {database disk image is malformed}] + +finish_test diff --git a/test/corrupt7.test b/test/corrupt7.test new file mode 100644 index 0000000..b62515b --- /dev/null +++ b/test/corrupt7.test @@ -0,0 +1,112 @@ +# 2008 June 11 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests to make sure SQLite does not crash or +# segfault if it sees a corrupt database file. It specifically focuses +# on corrupt cell offsets in a btree page. +# +# $Id: corrupt7.test,v 1.8 2009/08/10 10:18:08 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# This module uses hard-coded offsets which do not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} + +# These tests deal with corrupt database files +# +database_may_be_corrupt + +# We must have the page_size pragma for these tests to work. +# +ifcapable !pager_pragmas { + finish_test + return +} + +# Create a simple, small database. +# +do_test corrupt7-1.1 { + execsql { + PRAGMA auto_vacuum=OFF; + PRAGMA page_size=1024; + CREATE TABLE t1(x); + INSERT INTO t1(x) VALUES(1); + INSERT INTO t1(x) VALUES(2); + INSERT INTO t1(x) SELECT x+2 FROM t1; + INSERT INTO t1(x) SELECT x+4 FROM t1; + INSERT INTO t1(x) SELECT x+8 FROM t1; + } + file size test.db +} [expr {1024*2}] + +# Verify that the file format is as we expect. The page size +# should be 1024 bytes. +# +do_test corrupt7-1.2 { + hexio_get_int [hexio_read test.db 16 2] +} 1024 ;# The page size is 1024 +do_test corrupt7-1.3 { + hexio_get_int [hexio_read test.db 20 1] +} 0 ;# Unused bytes per page is 0 + +integrity_check corrupt7-1.4 + +# Deliberately corrupt some of the cell offsets in the btree page +# on page 2 of the database. +do_test corrupt7-2.1 { + db close + hexio_write test.db 1062 FF + sqlite3 db test.db + db eval {PRAGMA integrity_check(1)} +} {{*** in database main *** +Tree 2 page 2 cell 15: Offset 65457 out of range 945..1020}} +do_test corrupt7-2.2 { + db close + hexio_write test.db 1062 04 + sqlite3 db test.db + db eval {PRAGMA integrity_check(1)} +} {{*** in database main *** +Tree 2 page 2 cell 15: Offset 1201 out of range 945..1020}} + +# The code path that was causing the buffer overrun that this test +# case was checking for was removed. +# +#do_test corrupt7-3.1 { +# execsql { +# DROP TABLE t1; +# CREATE TABLE t1(a, b); +# INSERT INTO t1 VALUES(1, 'one'); +# INSERT INTO t1 VALUES(100, 'one hundred'); +# INSERT INTO t1 VALUES(100000, 'one hundred thousand'); +# CREATE INDEX i1 ON t1(b); +# } +# db close +# +# # Locate the 3rd cell in the index. +# set cell_offset [hexio_get_int [hexio_read test.db [expr 1024*2 + 12] 2]] +# incr cell_offset [expr 1024*2] +# incr cell_offset 1 +# +# # This write corrupts the "header-size" field of the database record +# # stored in the index cell. At one point this was causing sqlite to +# # reference invalid memory. +# hexio_write test.db $cell_offset FFFF7F +# +# sqlite3 db test.db +# catchsql { +# SELECT b FROM t1 WHERE b > 'o' AND b < 'p'; +# } +#} {1 {database disk image is malformed}} + +finish_test diff --git a/test/corrupt8.test b/test/corrupt8.test new file mode 100644 index 0000000..d7bceba --- /dev/null +++ b/test/corrupt8.test @@ -0,0 +1,108 @@ +# 2008 July 9 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests to make sure SQLite does not crash or +# segfault if it sees a corrupt database file. It specifically focuses +# on corrupt pointer map pages. +# +# $Id: corrupt8.test,v 1.2 2008/07/11 03:34:10 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +# These tests deal with corrupt database files +# +database_may_be_corrupt + +# We must have the page_size pragma for these tests to work. +# +ifcapable !pager_pragmas||!autovacuum { + finish_test + return +} + +# Create a database to work with. +# +do_test corrupt8-1.1 { + execsql { + PRAGMA auto_vacuum=1; + PRAGMA page_size=1024; + CREATE TABLE t1(x); + INSERT INTO t1(x) VALUES(1); + INSERT INTO t1(x) VALUES(2); + INSERT INTO t1(x) SELECT x+2 FROM t1; + INSERT INTO t1(x) SELECT x+4 FROM t1; + INSERT INTO t1(x) SELECT x+8 FROM t1; + INSERT INTO t1(x) SELECT x+16 FROM t1; + INSERT INTO t1(x) SELECT x+32 FROM t1; + INSERT INTO t1(x) SELECT x+64 FROM t1; + INSERT INTO t1(x) SELECT x+128 FROM t1; + INSERT INTO t1(x) SELECT x+256 FROM t1; + CREATE TABLE t2(a,b); + INSERT INTO t2 SELECT x, x*x FROM t1; + } + expr {[file size test.db]>1024*12} +} {1} +integrity_check corrupt8-1.2 + +# Loop through each ptrmap entry. Corrupt the entry and make sure the +# corruption is detected by the integrity_check. +# +for {set i 1024} {$i<2048} {incr i 5} { + set oldval [hexio_read test.db $i 1] + if {$oldval==0} break + hexio_write test.db $i 00 + do_test corrupt8-2.$i.0 { + db close + sqlite3 db test.db + set x [db eval {PRAGMA integrity_check}] + expr {$x!="ok"} + } {1} + for {set k 1} {$k<=5} {incr k} { + if {$k==$oldval} continue + hexio_write test.db $i 0$k + do_test corrupt8-2.$i.$k { + db close + sqlite3 db test.db + set x [db eval {PRAGMA integrity_check}] + expr {$x!="ok"} + } {1} + } + hexio_write test.db $i 06 + do_test corrupt8-2.$i.6 { + db close + sqlite3 db test.db + set x [db eval {PRAGMA integrity_check}] + expr {$x!="ok"} + } {1} + hexio_write test.db $i $oldval + if {$oldval>2} { + set i2 [expr {$i+1+$i%4}] + set oldval [hexio_read test.db $i2 1] + hexio_write test.db $i2 [format %02x [expr {($oldval+1)&0xff}]] + do_test corrupt8-2.$i.7 { + db close + sqlite3 db test.db + set x [db eval {PRAGMA integrity_check}] + expr {$x!="ok"} + } {1} + hexio_write test.db $i2 $oldval + } +} + + +finish_test diff --git a/test/corrupt9.test b/test/corrupt9.test new file mode 100644 index 0000000..bb37758 --- /dev/null +++ b/test/corrupt9.test @@ -0,0 +1,140 @@ +# 2008 July 9 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests to make sure SQLite does not crash or +# segfault if it sees a corrupt database file. It specifically focuses +# on corruption in the form of duplicate entries on the freelist. +# +# $Id: corrupt9.test,v 1.3 2009/06/04 02:47:04 shane Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +# These tests deal with corrupt database files +# +database_may_be_corrupt + +# We must have the page_size pragma for these tests to work. +# +ifcapable !pager_pragmas { + finish_test + return +} + +# Return the offset to the first (trunk) page of the freelist. Return +# zero of the freelist is empty. +# +proc freelist_trunk_offset {filename} { + if {[hexio_read $filename 36 4]==0} {return 0} + set pgno [hexio_get_int [hexio_read $filename 32 4]] + return [expr {($pgno-1)*[hexio_get_int [hexio_read $filename 16 2]]}] +} + +# This procedure looks at the first trunk page of the freelist and +# corrupts that page by overwriting up to N entries with duplicates +# of the first entry. +# +proc corrupt_freelist {filename N} { + set offset [freelist_trunk_offset $filename] + if {$offset==0} {error "Freelist is empty"} + set cnt [hexio_get_int [hexio_read $filename [expr {$offset+4}] 4]] + set pgno [hexio_read $filename [expr {$offset+8}] 4] + for {set i 12} {$N>0 && $i<8+4*$cnt} {incr i 4; incr N -1} { + hexio_write $filename [expr {$offset+$i}] $pgno + } +} + +# Create a database to work with. Make sure there are plenty of +# entries on the freelist. +# +do_test corrupt9-1.1 { + execsql { + PRAGMA auto_vacuum=NONE; + PRAGMA page_size=1024; + CREATE TABLE t1(x); + INSERT INTO t1(x) VALUES(1); + INSERT INTO t1(x) VALUES(2); + INSERT INTO t1(x) SELECT x+2 FROM t1; + INSERT INTO t1(x) SELECT x+4 FROM t1; + INSERT INTO t1(x) SELECT x+8 FROM t1; + INSERT INTO t1(x) SELECT x+16 FROM t1; + INSERT INTO t1(x) SELECT x+32 FROM t1; + INSERT INTO t1(x) SELECT x+64 FROM t1; + INSERT INTO t1(x) SELECT x+128 FROM t1; + INSERT INTO t1(x) SELECT x+256 FROM t1; + CREATE TABLE t2(a,b); + INSERT INTO t2 SELECT x, x*x FROM t1; + CREATE INDEX i1 ON t1(x); + CREATE INDEX i2 ON t2(b,a); + DROP INDEX i2; + } + expr {[file size test.db]>1024*24} +} {1} +integrity_check corrupt9-1.2 + +# Corrupt the freelist by adding duplicate entries to the freelist. +# Make sure the corruption is detected. +# +db close +forcecopy test.db test.db-template + +corrupt_freelist test.db 1 +sqlite3 db test.db +do_test corrupt9-2.1 { + set x [db eval {PRAGMA integrity_check}] + expr {$x!="ok"} +} {1} +do_test corrupt9-2.2 { + catchsql { + CREATE INDEX i2 ON t2(b,a); + REINDEX; + } +} {1 {database disk image is malformed}} + + +db close +forcecopy test.db-template test.db +corrupt_freelist test.db 2 +sqlite3 db test.db +do_test corrupt9-3.1 { + set x [db eval {PRAGMA integrity_check}] + expr {$x!="ok"} +} {1} +do_test corrupt9-3.2 { + catchsql { + CREATE INDEX i2 ON t2(b,a); + REINDEX; + } +} {1 {database disk image is malformed}} + +db close +forcecopy test.db-template test.db +corrupt_freelist test.db 3 +sqlite3 db test.db +do_test corrupt9-4.1 { + set x [db eval {PRAGMA integrity_check}] + expr {$x!="ok"} +} {1} +do_test corrupt9-4.2 { + catchsql { + CREATE INDEX i2 ON t2(b,a); + REINDEX; + } +} {1 {database disk image is malformed}} + + +finish_test diff --git a/test/corruptA.test b/test/corruptA.test new file mode 100644 index 0000000..12d9186 --- /dev/null +++ b/test/corruptA.test @@ -0,0 +1,83 @@ +# 2008 July 11 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests to make sure SQLite does not crash or +# segfault if it sees a corrupt database file. It specifically focuses +# on corrupt database headers. +# +# $Id: corruptA.test,v 1.1 2008/07/11 16:39:23 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +# These tests deal with corrupt database files +# +database_may_be_corrupt + + +# Create a database to work with. +# +do_test corruptA-1.1 { + execsql { + CREATE TABLE t1(x); + INSERT INTO t1(x) VALUES(1); + } + expr {[file size test.db]>=1024} +} {1} +integrity_check corruptA-1.2 + +# Corrupt the file header in various ways and make sure the corruption +# is detected when opening the database file. +# +db close +forcecopy test.db test.db-template + +set unreadable_version 02 +ifcapable wal { set unreadable_version 03 } +do_test corruptA-2.1 { + forcecopy test.db-template test.db + hexio_write test.db 19 $unreadable_version ;# the read format number + sqlite3 db test.db + catchsql {SELECT * FROM t1} +} {1 {file is not a database}} + +do_test corruptA-2.2 { + db close + forcecopy test.db-template test.db + hexio_write test.db 21 41 ;# max embedded payload fraction + sqlite3 db test.db + catchsql {SELECT * FROM t1} +} {1 {file is not a database}} + +do_test corruptA-2.3 { + db close + forcecopy test.db-template test.db + hexio_write test.db 22 1f ;# min embedded payload fraction + sqlite3 db test.db + catchsql {SELECT * FROM t1} +} {1 {file is not a database}} + +do_test corruptA-2.4 { + db close + forcecopy test.db-template test.db + hexio_write test.db 23 21 ;# min leaf payload fraction + sqlite3 db test.db + catchsql {SELECT * FROM t1} +} {1 {file is not a database}} + + +finish_test diff --git a/test/corruptB.test b/test/corruptB.test new file mode 100644 index 0000000..c51cb57 --- /dev/null +++ b/test/corruptB.test @@ -0,0 +1,193 @@ +# 2008 Sep 10 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests to make sure SQLite does not crash or +# segfault if it sees a corrupt database file. It specifically focuses +# on loops in the B-Tree structure. A loop is formed in a B-Tree structure +# when there exists a page that is both an a descendent or ancestor of +# itself. +# +# Also test that an SQLITE_CORRUPT error is returned if a B-Tree page +# contains a (corrupt) reference to a page greater than the configured +# maximum page number. +# +# $Id: corruptB.test,v 1.4 2009/07/21 19:25:24 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +# These tests deal with corrupt database files +# +database_may_be_corrupt + + +do_test corruptB-1.1 { + execsql { + PRAGMA auto_vacuum = 1; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(randomblob(200)); + INSERT INTO t1 SELECT randomblob(200) FROM t1; + INSERT INTO t1 SELECT randomblob(200) FROM t1; + INSERT INTO t1 SELECT randomblob(200) FROM t1; + INSERT INTO t1 SELECT randomblob(200) FROM t1; + INSERT INTO t1 SELECT randomblob(200) FROM t1; + } + expr {[file size test.db] > (1024*9)} +} {1} +integrity_check corruptB-1.2 + +forcecopy test.db bak.db + +# Set the right-child of a B-Tree rootpage to refer to the root-page itself. +# +do_test corruptB-1.3.1 { + set ::root [execsql {SELECT rootpage FROM sqlite_master}] + set ::offset [expr {($::root-1)*1024}] + hexio_write test.db [expr $offset+8] [hexio_render_int32 $::root] +} {4} +do_test corruptB-1.3.2 { + sqlite3 db test.db + catchsql { SELECT * FROM t1 } +} {1 {database disk image is malformed}} + +# Set the left-child of a cell in a B-Tree rootpage to refer to the +# root-page itself. +# +do_test corruptB-1.4.1 { + db close + forcecopy bak.db test.db + set cell_offset [hexio_get_int [hexio_read test.db [expr $offset+12] 2]] + hexio_write test.db [expr $offset+$cell_offset] [hexio_render_int32 $::root] +} {4} +do_test corruptB-1.4.2 { + sqlite3 db test.db + catchsql { SELECT * FROM t1 } +} {1 {database disk image is malformed}} + +# Now grow the table B-Tree so that it is more than 2 levels high. +# +do_test corruptB-1.5.1 { + db close + forcecopy bak.db test.db + sqlite3 db test.db + execsql { + INSERT INTO t1 SELECT randomblob(200) FROM t1; + INSERT INTO t1 SELECT randomblob(200) FROM t1; + INSERT INTO t1 SELECT randomblob(200) FROM t1; + INSERT INTO t1 SELECT randomblob(200) FROM t1; + INSERT INTO t1 SELECT randomblob(200) FROM t1; + INSERT INTO t1 SELECT randomblob(200) FROM t1; + INSERT INTO t1 SELECT randomblob(200) FROM t1; + } +} {} + +forcecopy test.db bak.db + +# Set the right-child pointer of the right-child of the root page to point +# back to the root page. +# +do_test corruptB-1.6.1 { + db close + set iRightChild [hexio_get_int [hexio_read test.db [expr $offset+8] 4]] + set c_offset [expr ($iRightChild-1)*1024] + hexio_write test.db [expr $c_offset+8] [hexio_render_int32 $::root] +} {4} +do_test corruptB-1.6.2 { + sqlite3 db test.db + catchsql { SELECT * FROM t1 } +} {1 {database disk image is malformed}} + +# Set the left-child pointer of a cell of the right-child of the root page to +# point back to the root page. +# +do_test corruptB-1.7.1 { + db close + forcecopy bak.db test.db + set cell_offset [hexio_get_int [hexio_read test.db [expr $c_offset+12] 2]] + hexio_write test.db [expr $c_offset+$cell_offset] [hexio_render_int32 $::root] +} {4} +do_test corruptB-1.7.2 { + sqlite3 db test.db + catchsql { SELECT * FROM t1 } +} {1 {database disk image is malformed}} + +do_test corruptB-1.8.1 { + db close + set cell_offset [hexio_get_int [hexio_read test.db [expr $offset+12] 2]] + set iLeftChild [ + hexio_get_int [hexio_read test.db [expr $offset+$cell_offset] 4] + ] + set c_offset [expr ($iLeftChild-1)*1024] + hexio_write test.db [expr $c_offset+8] [hexio_render_int32 $::root] +} {4} +do_test corruptB-1.8.2 { + sqlite3 db test.db + catchsql { SELECT * FROM t1 } +} {1 {database disk image is malformed}} + +# Set the left-child pointer of a cell of the right-child of the root page to +# point back to the root page. +# +do_test corruptB-1.9.1 { + db close + forcecopy bak.db test.db + set cell_offset [hexio_get_int [hexio_read test.db [expr $c_offset+12] 2]] + hexio_write test.db [expr $c_offset+$cell_offset] [hexio_render_int32 $::root] +} {4} +do_test corruptB-1.9.2 { + sqlite3 db test.db + catchsql { SELECT * FROM t1 } +} {1 {database disk image is malformed}} + +#--------------------------------------------------------------------------- + +do_test corruptB-2.1.1 { + db close + forcecopy bak.db test.db + hexio_write test.db [expr $offset+8] [hexio_render_int32 0x6FFFFFFF] +} {4} +do_test corruptB-2.1.2 { + sqlite3 db test.db + catchsql { SELECT * FROM t1 } +} {1 {database disk image is malformed}} + +#--------------------------------------------------------------------------- + +# Corrupt the header-size field of a database record. +# +do_test corruptB-3.1.1 { + db close + forcecopy bak.db test.db + sqlite3 db test.db + set v [string repeat abcdefghij 200] + execsql { + CREATE TABLE t2(a); + INSERT INTO t2 VALUES($v); + } + set t2_root [execsql {SELECT rootpage FROM sqlite_master WHERE name = 't2'}] + set iPage [expr ($t2_root-1)*1024] + set iCellarray [expr $iPage + 8] + set iRecord [hexio_get_int [hexio_read test.db $iCellarray 2]] + db close + hexio_write test.db [expr $iPage+$iRecord+3] FF00 +} {2} +do_test corruptB-3.1.2 { + sqlite3 db test.db + catchsql { SELECT * FROM t2 } +} {1 {database disk image is malformed}} + +finish_test diff --git a/test/corruptC.test b/test/corruptC.test new file mode 100644 index 0000000..f5733a8 --- /dev/null +++ b/test/corruptC.test @@ -0,0 +1,428 @@ +# 2004 August 30 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests to make sure SQLite does not crash or +# segfault if it sees a corrupt database file. It creates a base +# data base file, then tests that single byte corruptions in +# increasingly larger quantities are handled gracefully. +# +# $Id: corruptC.test,v 1.14 2009/07/11 06:55:34 danielk1977 Exp $ + +catch {forcedelete test.db test.db-journal test.bu} + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +# These tests deal with corrupt database files +# +database_may_be_corrupt + +# Construct a compact, dense database for testing. +# +do_test corruptC-1.1 { + sqlite3_db_config db LEGACY_FILE_FORMAT 1 + execsql { + PRAGMA auto_vacuum = 0; + BEGIN; + CREATE TABLE t1(x,y); + INSERT INTO t1 VALUES(1,1); + INSERT OR IGNORE INTO t1 SELECT x*2,y FROM t1; + INSERT OR IGNORE INTO t1 SELECT x*3,y FROM t1; + INSERT OR IGNORE INTO t1 SELECT x*5,y FROM t1; + INSERT OR IGNORE INTO t1 SELECT x*7,y FROM t1; + INSERT OR IGNORE INTO t1 SELECT x*11,y FROM t1; + INSERT OR IGNORE INTO t1 SELECT x*13,y FROM t1; + CREATE INDEX t1i1 ON t1(x); + CREATE TABLE t2 AS SELECT x,2 as y FROM t1 WHERE rowid%5!=0; + COMMIT; + } +} {} + +ifcapable {integrityck} { + integrity_check corruptC-1.2 +} + +# Generate random integer +# +proc random {range} { + return [expr {round(rand()*$range)}] +} + +# Setup for the tests. Make a backup copy of the good database in test.bu. +# +db close +forcecopy test.db test.bu +sqlite3 db test.db +set fsize [file size test.db] + +# Set a quasi-random random seed. +if {[info exists ::G(issoak)]} { + # If we are doing SOAK tests, we want a different + # random seed for each run. Ideally we would like + # to use [clock clicks] or something like that here. + set qseed [file mtime test.db] +} else { + # If we are not doing soak tests, + # make it repeatable. + set qseed 0 +} +expr srand($qseed) + +# +# First test some specific corruption tests found from earlier runs +# with specific seeds. +# + +# test that a corrupt content offset size is handled (seed 5577) +do_test corruptC-2.1 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 2053 [format %02x 0x04] + + sqlite3 db test.db + catchsql {PRAGMA integrity_check} +} {0 {{*** in database main *** +Tree 3 page 3: free space corruption}}} + +# test that a corrupt content offset size is handled (seed 5649) +# +# Update 2016-12-27: As of check-in [0b86fbca66] "In sqlite3BtreeInsert() when +# replacing a re-existing row, try to overwrite the cell directly rather than +# deallocate and reallocate the cell" on 2016-12-09, this test case no longer +# detects the offset size problem during the UPDATE. We have to run a subsequent +# integrity_check to see it. +do_test corruptC-2.2 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 27 [format %02x 0x08] + hexio_write test.db 233 [format %02x 0x6a] + hexio_write test.db 328 [format %02x 0x67] + hexio_write test.db 750 [format %02x 0x1f] + hexio_write test.db 1132 [format %02x 0x52] + hexio_write test.db 1133 [format %02x 0x84] + hexio_write test.db 1220 [format %02x 0x01] + hexio_write test.db 3688 [format %02x 0xc1] + hexio_write test.db 3714 [format %02x 0x58] + hexio_write test.db 3746 [format %02x 0x9a] + + sqlite3 db test.db + db eval {UPDATE t1 SET y=1} + db eval {PRAGMA integrity_check} +} {/Offset .* out of range/} + +# test that a corrupt free cell size is handled (seed 13329) +do_test corruptC-2.3 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 1094 [format %02x 0x76] + + sqlite3 db test.db + catchsql {UPDATE t1 SET y=1} +} {1 {database disk image is malformed}} + +# test that a corrupt free cell size is handled (seed 169571) +do_test corruptC-2.4 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 3119 [format %02x 0xdf] + + sqlite3 db test.db + catchsql {UPDATE t2 SET y='abcdef-uvwxyz'} +} {1 {database disk image is malformed}} + +# test that a corrupt free cell size is handled (seed 169571) +do_test corruptC-2.5 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 3119 [format %02x 0xdf] + hexio_write test.db 4073 [format %02x 0xbf] + + sqlite3 db test.db + catchsql {BEGIN; UPDATE t2 SET y='abcdef-uvwxyz'; ROLLBACK;} + catchsql {PRAGMA integrity_check} +} {0 {{*** in database main *** +Tree 4 page 4 cell 19: Extends off end of page} {database disk image is malformed}}} + +# {0 {{*** in database main *** +# Corruption detected in cell 710 on page 4 +# Multiple uses for byte 661 of page 4 +# Fragmented space is 249 byte reported as 21 on page 4}}} + +# test that a corrupt free cell size is handled (seed 169595) +do_test corruptC-2.6 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 619 [format %02x 0xe2] + hexio_write test.db 3150 [format %02x 0xa8] + + sqlite3 db test.db + catchsql {BEGIN; UPDATE t2 SET y='abcdef-uvwxyz'; ROLLBACK;} +} {1 {database disk image is malformed}} + +# corruption (seed 178692) +do_test corruptC-2.7 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 3074 [format %02x 0xa0] + + sqlite3 db test.db + catchsql {BEGIN; UPDATE t2 SET y='abcdef-uvwxyz'; ROLLBACK;} +} {1 {database disk image is malformed}} + + +# corruption (seed 179069) +# Obsolete. With single-pass DELETE the corruption in the +# main database is not detected. +if 0 { +do_test corruptC-2.8 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 1393 [format %02x 0x7d] + hexio_write test.db 84 [format %02x 0x19] + hexio_write test.db 3287 [format %02x 0x3b] + hexio_write test.db 2564 [format %02x 0xed] + hexio_write test.db 2139 [format %02x 0x55] + + sqlite3 db test.db + catchsql {BEGIN; DELETE FROM t1 WHERE x>13; ROLLBACK;} +} {1 {database disk image is malformed}} +} + +# corruption (seed 170434) +# +# UPDATE: Prior to 3.8.2, this used to return SQLITE_CORRUPT. It no longer +# does. That is Ok, the point of these tests is to verify that no buffer +# overruns or overreads can be caused by corrupt databases. +do_test corruptC-2.9 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 2095 [format %02x 0xd6] + + sqlite3 db test.db + catchsql {BEGIN; DELETE FROM t1 WHERE x>13; ROLLBACK;} +} {0 {}} + +# corruption (seed 186504) +do_test corruptC-2.10 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 3130 [format %02x 0x02] + + sqlite3 db test.db + catchsql {BEGIN; UPDATE t2 SET y='abcdef-uvwxyz'; ROLLBACK;} +} {1 {database disk image is malformed}} + +# corruption (seed 1589) +do_test corruptC-2.11 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 55 [format %02x 0xa7] + + sqlite3 db test.db + catchsql {BEGIN; CREATE TABLE t3 AS SELECT x,3 as y FROM t2 WHERE rowid%5!=0; ROLLBACK;} +} {1 {database disk image is malformed}} + +# corruption (seed 14166) +do_test corruptC-2.12 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 974 [format %02x 0x2e] + + sqlite3 db test.db + catchsql {SELECT count(*) FROM sqlite_master;} +} {1 {malformed database schema (t1i1) - corrupt database}} + +# corruption (seed 218803) +do_test corruptC-2.13 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 102 [format %02x 0x12] + + sqlite3 db test.db + catchsql {BEGIN; CREATE TABLE t3 AS SELECT x,3 as y FROM t2 WHERE rowid%5!=0; ROLLBACK;} +} {1 {database disk image is malformed}} + +do_test corruptC-2.14 { + db close + forcecopy test.bu test.db + + sqlite3 db test.db + set blob [string repeat abcdefghij 10000] + execsql { INSERT INTO t1 VALUES (1, $blob) } + + sqlite3 db test.db + set filesize [file size test.db] + hexio_write test.db [expr $filesize-2048] 00000001 + catchsql {DELETE FROM t1 WHERE rowid = (SELECT max(rowid) FROM t1)} +} {1 {database disk image is malformed}} + +# At one point this particular corrupt database was causing a buffer +# overread. Which caused a crash in a run of all.test once. +# +do_test corruptC-2.15 { + db close + forcecopy test.bu test.db + hexio_write test.db 986 b9 + sqlite3 db test.db + catchsql {SELECT count(*) FROM sqlite_master;} +} {1 {database disk image is malformed}} + +# +# Now test for a series of quasi-random seeds. +# We loop over the entire file size and touch +# each byte at least once. +for {set tn 0} {$tn<$fsize} {incr tn 1} { + + # setup for test + db close + forcecopy test.bu test.db + sqlite3 db test.db + + # Seek to a random location in the file, and write a random single byte + # value. Then do various operations on the file to make sure that + # the database engine can handle the corruption gracefully. + # + set last 0 + for {set i 1} {$i<=512 && !$last} {incr i 1} { + + db close + if {$i==1} { + # on the first corrupt value, use location $tn + # this ensures that we touch each location in the + # file at least once. + set roffset $tn + } else { + # insert random byte at random location + set roffset [random $fsize] + } + set rbyte [format %02x [random 255]] + + # You can uncomment the following to have it trace + # exactly how it's corrupting the file. This is + # useful for generating the "seed specific" tests + # above. + # set rline "$roffset $rbyte" + # puts stdout $rline + + hexio_write test.db $roffset $rbyte + sqlite3 db test.db + + # do a few random operations to make sure that if + # they error, they error gracefully instead of crashing. + do_test corruptC-3.$tn.($qseed).$i.1 { + catchsql {SELECT count(*) FROM sqlite_master} + set x {} + } {} + do_test corruptC-3.$tn.($qseed).$i.2 { + catchsql {SELECT count(*) FROM t1} + set x {} + } {} + do_test corruptC-3.$tn.($qseed).$i.3 { + catchsql {SELECT count(*) FROM t1 WHERE x>13} + set x {} + } {} + do_test corruptC-3.$tn.($qseed).$i.4 { + catchsql {SELECT count(*) FROM t2} + set x {} + } {} + do_test corruptC-3.$tn.($qseed).$i.5 { + catchsql {SELECT count(*) FROM t2 WHERE x<13} + set x {} + } {} + do_test corruptC-3.$tn.($qseed).$i.6 { + catchsql {BEGIN; UPDATE t1 SET y=1; ROLLBACK;} + set x {} + } {} + do_test corruptC-3.$tn.($qseed).$i.7 { + catchsql {BEGIN; UPDATE t2 SET y='abcdef-uvwxyz'; ROLLBACK;} + set x {} + } {} + do_test corruptC-3.$tn.($qseed).$i.8 { + catchsql {BEGIN; DELETE FROM t1 WHERE x>13; ROLLBACK;} + set x {} + } {} + do_test corruptC-3.$tn.($qseed).$i.9 { + catchsql {BEGIN; DELETE FROM t2 WHERE x<13; ROLLBACK;} + set x {} + } {} + do_test corruptC-3.$tn.($qseed).$i.10 { + catchsql {BEGIN; CREATE TABLE t3 AS SELECT x,3 as y FROM t2 WHERE rowid%5!=0; ROLLBACK;} + set x {} + } {} + + # check the integrity of the database. + # once the corruption is detected, we can stop. + ifcapable {integrityck} { + set res [ catchsql {PRAGMA integrity_check} ] + set ans [lindex $res 1] + if { [ string compare $ans "ok" ] != 0 } { + set last -1 + } + } + # if we are not capable of doing an integrity check, + # stop after corrupting 5 bytes. + ifcapable {!integrityck} { + if { $i > 5 } { + set last -1 + } + } + + # Check that no page references were leaked. + # TBD: need to figure out why this doesn't work + # work with ROLLBACKs... + if {0} { + do_test corruptC-3.$tn.($qseed).$i.11 { + set bt [btree_from_db db] + db_enter db + array set stats [btree_pager_stats $bt] + db_leave db + set stats(ref) + } {0} + } + } + # end for i + +} +# end for tn + +finish_test diff --git a/test/corruptD.test b/test/corruptD.test new file mode 100644 index 0000000..c35388a --- /dev/null +++ b/test/corruptD.test @@ -0,0 +1,145 @@ +# 2009 June 3 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# $Id: corruptD.test,v 1.2 2009/06/05 17:09:12 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +# These tests deal with corrupt database files +# +database_may_be_corrupt + +#-------------------------------------------------------------------------- +# OVERVIEW +# +# This test file attempts to verify that SQLite does not read past the +# end of any in-memory buffers as a result of corrupted database page +# images. Usually this happens because a field within a database page +# that contains an offset to some other structure within the same page +# is set to too large a value. A database page contains the following +# such fields: +# +# 1. The page header field that contains the offset to the first +# free block of space. +# +# 2. The first two bytes of all but the last free block on the free-block +# list (the offset to the next free block). +# +# 3. The page header field containing the number of cells on the page +# (implicitly defines the offset to the final element in the cell offset +# array, which could potentially be off the end of the page). +# +# 4. The page header field containing the offset to the start of the cell +# content area. +# +# 5. The contents of the cell offset array. +# +# 6. The first few bytes of each cell determine the size of the cell +# stored within the page, and hence the offset to the final byte of +# the cell. +# +# If any of the above fields are set to too large a value, then a buffer +# overread may occur. This test script creates and operates on various +# strategically corrupted database files to attempt to provoke such buffer +# overreads. +# +# Very often, a buffer overread passes unnoticed, particularly in workstation +# environments. For this reason, this test script should be run using valgrind +# (or similar) in order to verify that no overreads occur. +# +# TEST PLAN +# +# Test cases corruptD-1.* are white-box tests. They attempt to corrupt +# one of the above fields, then exercise each part of the code in btree.c +# that uses said field. +# +# Offset variables 1, 2, 3 and 4 are all checked to make sure they +# will not result in buffer overruns as part of page initialization in +# sqlite3BtreeInitPage(). Offsets 5 and 6 cannot be tested as part of +# page initialization, as trying to do so causes a performance hit. +# + +do_test corruptD-1.0 { + execsql { + PRAGMA auto_vacuum = 0; + PRAGMA page_size = 1024; + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a, b); + } + for {set ii 1} {$ii < 50} {incr ii} { + execsql { INSERT INTO t1 VALUES($ii, $ii * $ii) } + } + execsql { + DELETE FROM t1 WHERE a = 10; + DELETE FROM t1 WHERE a = 20; + DELETE FROM t1 WHERE a = 30; + DELETE FROM t1 WHERE a = 40; + } + forcecopy test.db test.bu +} {} + +proc incr_change_counter {} { + hexio_write test.db 24 [ + hexio_render_int32 [expr [hexio_get_int [hexio_read test.db 24 4]] + 1] + ] +} + +proc restore_file {} { + db close + forcecopy test.bu test.db + sqlite3 db test.db +} + +#------------------------------------------------------------------------- +# The following tests, corruptD-1.1.*, focus on the page header field +# containing the offset of the first free block in a page. +# +do_test corruptD-1.1.1 { + incr_change_counter + hexio_write test.db [expr 1024+1] FFFF + catchsql { PRAGMA quick_check } +} {0 {{*** in database main *** +Tree 2 page 2: free space corruption}}} +do_test corruptD-1.1.2 { + incr_change_counter + hexio_write test.db [expr 1024+1] [hexio_render_int32 1021] + catchsql { SELECT * FROM t1 ORDER BY rowid } +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +# The following tests, corruptD-1.2.*, focus on the offsets contained +# in the first 2 byte of each free-block on the free-list. +# +do_test corruptD-1.2.1 { + restore_file +} {} +do_test corruptD-1.2.2 { +} {} + +#------------------------------------------------------------------------- +# The following tests, corruptD-1.4.*, ... +# + + +#------------------------------------------------------------------------- +# The following tests, corruptD-1.5.*, focus on the offsets contained +# in the cell offset array. +# +# defragmentPage +# + +finish_test diff --git a/test/corruptE.test b/test/corruptE.test new file mode 100644 index 0000000..8c55623 --- /dev/null +++ b/test/corruptE.test @@ -0,0 +1,152 @@ +# 2010 February 18 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests to make sure SQLite does not crash or +# segfault if it sees a corrupt database file. It specifcally +# focuses on rowid order corruption. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# This module uses hard-coded offsets which do not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} + +# These tests deal with corrupt database files +# +database_may_be_corrupt + +# Do not run the tests in this file if ENABLE_OVERSIZE_CELL_CHECK is on. +# +ifcapable oversize_cell_check { + finish_test + return +} + +# Construct a compact, dense database for testing. +# +do_test corruptE-1.1 { + sqlite3_db_config db LEGACY_FILE_FORMAT 1 + execsql { + PRAGMA auto_vacuum = 0; + BEGIN; + CREATE TABLE t1(x,y); + INSERT INTO t1 VALUES(1,1); + INSERT OR IGNORE INTO t1 SELECT x*2,y FROM t1; + INSERT OR IGNORE INTO t1 SELECT x*3,y FROM t1; + INSERT OR IGNORE INTO t1 SELECT x*5,y FROM t1; + INSERT OR IGNORE INTO t1 SELECT x*7,y FROM t1; + INSERT OR IGNORE INTO t1 SELECT x*11,y FROM t1; + INSERT OR IGNORE INTO t1 SELECT x*13,y FROM t1; + INSERT OR IGNORE INTO t1 SELECT x*17,y FROM t1; + INSERT OR IGNORE INTO t1 SELECT x*19,y FROM t1; + CREATE INDEX t1i1 ON t1(x); + CREATE TABLE t2 AS SELECT x,2 as y FROM t1 WHERE rowid%5!=0 ORDER BY rowid; + COMMIT; + } +} {} + +ifcapable {integrityck} { + integrity_check corruptE-1.2 +} + +# Setup for the tests. Make a backup copy of the good database in test.bu. +# +db close +forcecopy test.db test.bu +sqlite3 db test.db +set fsize [file size test.db] + + +do_test corruptE-2.1 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 2041 [format %02x 0x2e] + + sqlite3 db test.db + + catchsql {PRAGMA integrity_check} +} {/ out of order/} + +do_test corruptE-2.2 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 2047 [format %02x 0x84] + + sqlite3 db test.db + + catchsql {PRAGMA integrity_check} +} {/ Extends off end of page/} + +do_test corruptE-2.3 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 7420 [format %02x 0xa8] + hexio_write test.db 10459 [format %02x 0x8d] + + sqlite3 db test.db + + catchsql {PRAGMA integrity_check} +} {/out of order/} + +do_test corruptE-2.4 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 10233 [format %02x 0xd0] + + sqlite3 db test.db + + catchsql {PRAGMA integrity_check} +} {/out of order/} + + +set tests [list {10233 0xd0} \ + {941 0x42} \ + {2041 0xd0} \ + {2042 0x1f} \ + {2274 0x75} \ + {3267 0xf2} \ + {5113 0x36} \ + {10233 0x84} \ + {10234 0x74} \ + {10239 0x41} \ + {11273 0x28} \ + {11461 0xe6} \ + {12297 0xd7} \ + {13303 0x53} ] + +set tc 1 +foreach test $tests { + do_test corruptE-3.$tc { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db [lindex $test 0] [format %02x [lindex $test 1]] + + sqlite3 db test.db + + catchsql {PRAGMA integrity_check} + } {/out of order/} + incr tc 1 +} + +finish_test diff --git a/test/corruptF.test b/test/corruptF.test new file mode 100644 index 0000000..8c4fd84 --- /dev/null +++ b/test/corruptF.test @@ -0,0 +1,153 @@ +# 2012 January 12 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix corruptF + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +# These tests deal with corrupt database files +# +database_may_be_corrupt + +proc str {i} { format %08d $i } + +# Create a 6 page database containing a single table - t1. Table t1 +# consists of page 2 (the root page) and pages 5 and 6 (leaf pages). +# Database pages 3 and 4 are on the free list. +# +proc create_test_db {} { + catch { db close } + forcedelete test.db + sqlite3 db test.db + db func str str + execsql { + PRAGMA auto_vacuum = 0; + PRAGMA page_size = 1024; + CREATE TABLE t1(x); /* root page = 2 */ + CREATE TABLE t2(x); /* root page = 3 */ + CREATE TABLE t3(x); /* root page = 4 */ + + INSERT INTO t1 VALUES(str(1)); + INSERT INTO t1 SELECT str(rowid+1) FROM t1; + INSERT INTO t1 SELECT str(rowid+2) FROM t1; + INSERT INTO t1 SELECT str(rowid+4) FROM t1; + INSERT INTO t1 SELECT str(rowid+8) FROM t1; + INSERT INTO t1 SELECT str(rowid+16) FROM t1; + INSERT INTO t1 SELECT str(rowid+32) FROM t1; + INSERT INTO t1 SELECT str(rowid+64) FROM t1; + DROP TABLE t2; + DROP TABLE t3; + } + db close +} + +do_test 1.1 { create_test_db } {} + +# Check the db is as we expect. 6 pages in total, with 3 and 4 on the free +# list. Page 3 is the free list trunk and page 4 is a leaf. +# +do_test 1.2 { file size test.db } [expr 6*1024] +do_test 1.3 { hexio_read test.db 32 4 } 00000003 +do_test 1.4 { hexio_read test.db [expr 2*1024] 12 } 000000000000000100000004 + +# Change the free-list entry to page 6 and reopen the db file. +do_test 1.5 { + hexio_write test.db [expr 2*1024 + 8] 00000006 + sqlite3 db test.db +} {} + +# Now create a new table in the database file. The root of the new table +# is page 6, which is also the right-most leaf page in table t1. +# +do_execsql_test 1.6 { + CREATE TABLE t4(x); + SELECT * FROM sqlite_master; +} { + table t1 t1 2 {CREATE TABLE t1(x)} + table t4 t4 6 {CREATE TABLE t4(x)} +} + +# At one point this was causing an assert to fail. +# +# This statement opens a cursor on table t1 and does a full table scan. As +# each row is visited, it is copied into table t4. There is no temporary +# table. +# +# When the t1 cursor reaches page 6 (which is both the right-most leaf of +# t1 and the root of t4), it continues to iterate through the keys within +# it (which at this point are keys that have been inserted into t4). And +# for each row visited, another row is inserted into page 6 - it being the +# root page of t4. Eventually, page 6 becomes full and the height of the +# b-tree for table t4 increased. From the point of view of the t1 cursor, +# this unexpectedly reduces the number of keys on page 6 in the middle of +# its iteration, which causes an assert() to fail. +# +db_save_and_close +if 1 { +for {set i 0} {$i < 128} {incr i} { + db_restore_and_reopen + do_test 1.7.$i { + set res [ + catchsql { INSERT INTO t4 SELECT x FROM t1 WHERE rowid>$i } + ] + if {$res == "0 {}" || $res == "1 {database disk image is malformed}"} { + set res "" + } + set res + } {} +} +} + +do_test 2.1 { create_test_db } {} +do_test 2.2 { file size test.db } [expr 6*1024] +do_test 2.3 { hexio_read test.db 32 4 } 00000003 +do_test 2.4 { hexio_read test.db [expr 2*1024] 12 } 000000000000000100000004 + +# Change the free-list entry to page 5 and reopen the db file. +do_test 2.5 { + hexio_write test.db [expr 2*1024 + 8] 00000005 + sqlite3 db test.db +} {} + +# Now create a new table in the database file. The root of the new table +# is page 5, which is also the right-most leaf page in table t1. +# +do_execsql_test 2.6 { + CREATE TABLE t4(x); + SELECT * FROM sqlite_master; +} { + table t1 t1 2 {CREATE TABLE t1(x)} + table t4 t4 5 {CREATE TABLE t4(x)} +} + +db_save_and_close +for {set i 127} {$i >= 0} {incr i -1} { + db_restore_and_reopen + do_test 2.7.$i { + set res [ + catchsql { + INSERT INTO t4 SELECT x FROM t1 WHERE rowid<$i ORDER BY rowid DESC + } + ] + if {$res == "0 {}" || $res == "1 {database disk image is malformed}"} { + set res "" + } + set res + } {} +} + +finish_test diff --git a/test/corruptG.test b/test/corruptG.test new file mode 100644 index 0000000..9448034 --- /dev/null +++ b/test/corruptG.test @@ -0,0 +1,75 @@ +# 2013-08-01 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix corruptG + +# This module uses hard-coded offsets which do not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} + +# These tests deal with corrupt database files +# +database_may_be_corrupt + +# Create a simple database with a single entry. Then corrupt the +# header-size varint on the index payload so that it maps into a +# negative number. Try to use the database. +# + +do_execsql_test 1.1 { + PRAGMA page_size=512; + CREATE TABLE t1(a,b,c); + INSERT INTO t1(rowid,a,b,c) VALUES(52,'abc','xyz','123'); + CREATE INDEX t1abc ON t1(a,b,c); +} + +set idxroot [db one {SELECT rootpage FROM sqlite_master WHERE name = 't1abc'}] + +# Corrupt the file +db close +hexio_write test.db [expr {$idxroot*512 - 15}] 888080807f +sqlite3 db test.db + +# Try to use the file. +do_test 1.2 { + catchsql { + SELECT c FROM t1 WHERE a>'abc'; + } +} {1 {database disk image is malformed}} +do_test 1.3 { + catchsql { + PRAGMA integrity_check + } +} {1 {database disk image is malformed}} +do_test 1.4 { + catchsql { + SELECT c FROM t1 ORDER BY a; + } +} {1 {database disk image is malformed}} + +# Corrupt the same file in a slightly different way. Make the record header +# sane, but corrupt one of the serial_type value to indicate a huge payload +# such that the payload begins in allocated space but overflows the buffer. +# +db close +hexio_write test.db [expr {$idxroot*512-15}] 0513ff7f01 +sqlite3 db test.db + +do_test 2.1 { + catchsql { + SELECT rowid FROM t1 WHERE a='abc' and b='xyz123456789XYZ'; + } +} {1 {database disk image is malformed}} + +finish_test diff --git a/test/corruptH.test b/test/corruptH.test new file mode 100644 index 0000000..9ba7522 --- /dev/null +++ b/test/corruptH.test @@ -0,0 +1,176 @@ +# 2014-01-20 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix corruptH + +# This module uses hard-coded offsets which do not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} + +database_may_be_corrupt + +# The corruption migrations tested by the code in this file are not detected +# mmap mode. +# +# The reason is that in mmap mode, the different queries may use different +# PgHdr objects for the same page (same data, but different PgHdr container +# objects). And so the corruption is not detected. +# +if {[permutation]=="mmap"} { + finish_test + return +} + +# Initialize the database. +# +do_execsql_test 1.1 { + PRAGMA page_size=1024; + + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + INSERT INTO t1 VALUES(1, 'one'); + INSERT INTO t1 VALUES(2, 'two'); + + CREATE TABLE t2(x); + INSERT INTO t2 VALUES(randomblob(200)); + INSERT INTO t2 SELECT randomblob(200) FROM t2; + INSERT INTO t2 SELECT randomblob(200) FROM t2; + INSERT INTO t2 SELECT randomblob(200) FROM t2; + INSERT INTO t2 SELECT randomblob(200) FROM t2; + INSERT INTO t2 SELECT randomblob(200) FROM t2; + INSERT INTO t2 SELECT randomblob(200) FROM t2; +} {} + +# Corrupt the file so that the root page of t1 is also linked into t2 as +# a leaf page. +# +do_test 1.2 { + db eval { SELECT name, rootpage FROM sqlite_master } { + set r($name) $rootpage + } + db close + hexio_write test.db [expr {($r(t2)-1)*1024 + 11}] [format %.2X $r(t1)] + sqlite3 db test.db +} {} + +do_test 1.3 { + db eval { PRAGMA secure_delete=1 } + list [catch { + db eval { SELECT * FROM t1 WHERE a IN (1, 2) } { + db eval { DELETE FROM t2 } + } + } msg] $msg +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +reset_db + +# Initialize the database. +# +do_execsql_test 2.1 { + PRAGMA auto_vacuum=0; + PRAGMA page_size=1024; + + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + INSERT INTO t1 VALUES(1, 'one'); + INSERT INTO t1 VALUES(2, 'two'); + + CREATE TABLE t3(x); + + CREATE TABLE t2(x PRIMARY KEY) WITHOUT ROWID; + INSERT INTO t2 VALUES(randomblob(100)); + + DROP TABLE t3; +} {} + +do_test 2.2 { + db eval { SELECT name, rootpage FROM sqlite_master } { + set r($name) $rootpage + } + db close + set fl [hexio_get_int [hexio_read test.db 32 4]] + + hexio_write test.db [expr {($fl-1) * 1024 + 0}] 00000000 + hexio_write test.db [expr {($fl-1) * 1024 + 4}] 00000001 + hexio_write test.db [expr {($fl-1) * 1024 + 8}] [format %.8X $r(t1)] + hexio_write test.db 36 00000002 + + sqlite3 db test.db +} {} + + +# The trick here is that the root page of the tree scanned by the outer +# query is also currently on the free-list. So while the first seek on +# the table (for a==1) works, by the time the second is attempted The +# "INSERT INTO t2..." statements have recycled the root page of t1 and +# used it as an index leaf. Normally, BtreeMovetoUnpacked() detects +# that the PgHdr object associated with said root page does not match +# the cursor (as it is now marked with PgHdr.intKey==0) and returns +# SQLITE_CORRUPT. +# +set res23 {1 {database disk image is malformed}} +do_test 2.3 { + list [catch { + set res [list] + db eval { SELECT * FROM t1 WHERE a IN (1, 2) } { + db eval { + INSERT INTO t2 SELECT randomblob(100) FROM t2; + INSERT INTO t2 SELECT randomblob(100) FROM t2; + INSERT INTO t2 SELECT randomblob(100) FROM t2; + INSERT INTO t2 SELECT randomblob(100) FROM t2; + INSERT INTO t2 SELECT randomblob(100) FROM t2; + } + lappend res $b + } + set res + } msg] $msg +} $res23 + +#------------------------------------------------------------------------- +reset_db + +# Initialize the database. +# +do_execsql_test 3.1 { + PRAGMA page_size=1024; + + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + INSERT INTO t1 VALUES(1, 'one'); + INSERT INTO t1 VALUES(2, 'two'); + + CREATE TABLE t2(c INTEGER PRAGMA KEY, d); + INSERT INTO t2 VALUES(1, randomblob(1100)); +} {} + +do_test 3.2 { + db eval { SELECT name, rootpage FROM sqlite_master } { + set r($name) $rootpage + } + db close + + hexio_write test.db [expr {($r(t2)-1) * 1024 + 1020}] 00000002 + + sqlite3 db test.db +} {} + +do_test 3.3 { + list [catch { + db eval { SELECT * FROM t1 WHERE a IN (1, 2) } { + db eval { + DELETE FROM t2 WHERE c=1; + } + } + } msg] $msg +} {1 {database disk image is malformed}} + +finish_test diff --git a/test/corruptI.test b/test/corruptI.test new file mode 100644 index 0000000..65ef376 --- /dev/null +++ b/test/corruptI.test @@ -0,0 +1,258 @@ +# 2014-01-20 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix corruptI + +if {[permutation]=="mmap"} { + finish_test + return +} + +# This module uses hard-coded offsets which do not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} + +database_may_be_corrupt + +# Initialize the database. +# +do_execsql_test 1.1 { + PRAGMA page_size=1024; + PRAGMA auto_vacuum=0; + CREATE TABLE t1(a); + CREATE INDEX i1 ON t1(a); + INSERT INTO t1 VALUES('abcdefghijklmnop'); +} {} +db close + +do_test 1.2 { + set offset [hexio_get_int [hexio_read test.db [expr 2*1024 + 8] 2]] + set off [expr 2*1024 + $offset + 1] + hexio_write test.db $off 7f06 + sqlite3 db test.db + catchsql { SELECT * FROM t1 WHERE a = 10 } +} {0 {}} + +do_test 1.3 { + db close + set offset [hexio_get_int [hexio_read test.db [expr 2*1024 + 8] 2]] + set off [expr 2*1024 + $offset + 1] + hexio_write test.db $off FFFF7f02 + sqlite3 db test.db + catchsql { SELECT * FROM t1 WHERE a = 10 } +} {1 {database disk image is malformed}} + +do_test 2.0 { + execsql { + CREATE TABLE r(x); + INSERT INTO r VALUES('ABCDEFGHIJK'); + CREATE INDEX r1 ON r(x); + } + set pg [db one {SELECT rootpage FROM sqlite_master WHERE name = 'r1'}] +} {5} + +do_test 2.1 { + db close + set offset [hexio_get_int [hexio_read test.db [expr (5-1)*1024 + 8] 2]] + set off [expr (5-1)*1024 + $offset + 1] + hexio_write test.db $off FFFF0004 + sqlite3 db test.db + catchsql { SELECT * FROM r WHERE x >= 10.0 } +} {1 {database disk image is malformed}} + +do_test 2.2 { + catchsql { SELECT * FROM r WHERE x >= 10 } +} {1 {database disk image is malformed}} + +if {[db one {SELECT sqlite_compileoption_used('ENABLE_OVERSIZE_CELL_CHECK')}]} { + # The following tests only work if OVERSIZE_CELL_CHECK is disabled +} else { + reset_db + do_execsql_test 3.1 { + PRAGMA auto_vacuum=0; + PRAGMA page_size = 512; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + WITH s(a, b) AS ( + SELECT 2, 'abcdefghij' + UNION ALL + SELECT a+2, b FROM s WHERe a < 40 + ) + INSERT INTO t1 SELECT * FROM s; + } {} + + do_test 3.2 { + hexio_write test.db [expr 512+3] 0054 + db close + sqlite3 db test.db + execsql { INSERT INTO t1 VALUES(5, 'klmnopqrst') } + execsql { INSERT INTO t1 VALUES(7, 'klmnopqrst') } + } {} + + db close + sqlite3 db test.db + do_catchsql_test 3.3 { + INSERT INTO t1 VALUES(9, 'klmnopqrst'); + } {1 {database disk image is malformed}} +} ;# end-if !defined(ENABLE_OVERSIZE_CELL_CHECK) + + +#------------------------------------------------------------------------- +# Test that an assert() failure discovered by AFL corrupt database file +# testing has been fixed. +# +reset_db +do_execsql_test 4.0 { + PRAGMA page_size = 65536; + PRAGMA autovacuum = 0; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + INSERT INTO t1 VALUES(-1, 'abcdefghij'); + INSERT INTO t1 VALUES(0, 'abcdefghij'); +} + +set root [db one {SELECT rootpage FROM sqlite_master}] +set offset [expr ($root-1) * 65536] + +do_test 4.1 { + db close + hexio_write test.db [expr $offset + 8 + 2] 0000 + hexio_write test.db [expr $offset + 5] 0000 + sqlite3 db test.db + catchsql { DELETE FROM t1 WHERE a=0 } +} {1 {database disk image is malformed}} + + +#------------------------------------------------------------------------- +# Database properties: +# +# * Incremental vacuum mode. +# * Database root table has a single leaf page. +# * Free list consists of a single trunk page. +# +# The db is then corrupted by adding the root table leaf page as a free-list +# leaf page (so that it is referenced twice). +# +# Then, a new table is created. The new root page is the current free-list +# trunk. This means that the root table leaf page is made into the new +# free list trunk, which corrupts its header. Then, when the new entry is +# inserted into the root table, things would get chaotic. +# +reset_db +do_test 5.0 { + execsql { + PRAGMA page_size = 512; + PRAGMA auto_vacuum = 2; + } + for {set i 3} {1} {incr i} { + execsql "CREATE TABLE t${i}(x)" + if {[db one {PRAGMA page_count}]>$i} break + } + set nPage [db one {PRAGMA page_count}] + execsql { + CREATE TABLE t100(x); + DROP TABLE t100; + } +} {} + +do_execsql_test 5.1 { + PRAGMA page_count +} [expr $nPage+1] + +do_test 5.2 { + # The last page of the db is now the only leaf of the sqlite_master table. + # Corrupt the db by adding it to the free-list as well (the second last + # page of the db is the free-list trunk). + db close + hexio_write test.db [expr 512*($nPage-1)] [ + format "%.8X%.8X%.8X" 0 1 [expr $nPage+1] + ] +} {12} + +do_test 5.3 { + sqlite3 db test.db + catchsql { CREATE TABLE tx(x); } +} {1 {database disk image is malformed}} + + +#------------------------------------------------------------------------- +# Set the payload size of a cell to just less than 2^32 bytes (not +# possible in an uncorrupted db). Then try to delete the cell. At one +# point this led to an integer overflow that caused an assert() to fail. +# +reset_db +do_execsql_test 6.0 { + PRAGMA page_size = 512; + PRAGMA auto_vacuum=0; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(zeroblob(300)); + INSERT INTO t1 VALUES(zeroblob(600)); +} {} +do_test 6.1 { + db close + hexio_write test.db 616 8FFFFFFF7F02 + sqlite3 db test.db + execsql { DELETE FROM t1 WHERE rowid=2 } +} {} + +#------------------------------------------------------------------------- +# See what happens if the sqlite_master entry associated with a PRIMARY +# KEY or UNIQUE index is removed. +# +reset_db +do_execsql_test 7.0 { + PRAGMA auto_vacuum=0; + CREATE TABLE t1(x PRIMARY KEY, y); + INSERT INTO t1 VALUES('a', 'A'); + INSERT INTO t1 VALUES('b', 'A'); + INSERT INTO t1 VALUES('c', 'A'); + SELECT name FROM sqlite_master; +} {t1 sqlite_autoindex_t1_1} +sqlite3_db_config db DEFENSIVE 0 +do_execsql_test 7.1 { + PRAGMA writable_schema = 1; + DELETE FROM sqlite_master WHERE name = 'sqlite_autoindex_t1_1'; +} +do_test 7.2 { + db close + sqlite3 db test.db + catchsql { UPDATE t1 SET x='d' AND y='D' WHERE rowid = 2 } +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +# At one point an assert() would fail if attempt was made to free page 1. +# +reset_db +do_execsql_test 8.0 { + PRAGMA auto_vacuum=0; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(zeroblob(300)); + INSERT INTO t1 VALUES(zeroblob(300)); + INSERT INTO t1 VALUES(zeroblob(300)); + INSERT INTO t1 VALUES(zeroblob(300)); +} {} + +do_test 8.1 { + db close + hexio_write test.db [expr 1024 + 8] 00000001 + sqlite3 db test.db + catchsql { DELETE FROM t1 } +} {1 {database disk image is malformed}} + +do_test 8.2 { + db close + sqlite3 db test.db + execsql { PRAGMA integrity_check } +} {/.*in database main.*/} + + +finish_test diff --git a/test/corruptJ.test b/test/corruptJ.test new file mode 100644 index 0000000..732adb0 --- /dev/null +++ b/test/corruptJ.test @@ -0,0 +1,80 @@ +# 2015-03-30 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Corruption consisting of a database page that thinks it is a child +# of itself. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix corruptJ + +if {[permutation]=="mmap"} { + finish_test + return +} + +# This module uses hard-coded offsets which do not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} + +database_may_be_corrupt + +# Initialize the database. +# +do_execsql_test 1.1 { + PRAGMA page_size=1024; + PRAGMA auto_vacuum=0; + CREATE TABLE t1(a,b); + WITH RECURSIVE c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<10) + INSERT INTO t1(a,b) SELECT i, zeroblob(700) FROM c; +} {} +db close + +# Corrupt the root page of the t1 table such that the left-child pointer +# for the very first cell points back to the root. Then try to DROP the +# table. The clearDatabasePage() routine should not loop. +# +do_test 1.2 { + hexio_write test.db [expr {2*1024-2}] 02 + sqlite3 db test.db + catchsql { DROP TABLE t1 } +} {1 {database disk image is malformed}} + +# Similar test using a WITHOUT ROWID table +# +do_test 2.1 { + db close + forcedelete test.db + sqlite3 db test.db + db eval { + PRAGMA page_size=1024; + PRAGMA auto_vacuum=0; + CREATE TABLE t1(a,b,PRIMARY KEY(a,b)) WITHOUT ROWID; + WITH RECURSIVE c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<100) + INSERT INTO t1(a,b) SELECT i, zeroblob(200) FROM c; + } +} {} + +# The table is three levels deep. Corrupt the left child of an intermediate +# page so that it points back to the root page. +# +do_test 2.2 { + db close + hexio_read test.db [expr {9*1024+391}] 8 +} {00000008814D0401} +do_test 2.2b { + hexio_write test.db [expr {9*1024+391}] 00000002 + sqlite3 db test.db + catchsql { PRAGMA secure_delete=ON; DROP TABLE t1; } +} {1 {database disk image is malformed}} + +finish_test diff --git a/test/corruptK.test b/test/corruptK.test new file mode 100644 index 0000000..1569afe --- /dev/null +++ b/test/corruptK.test @@ -0,0 +1,234 @@ +# 2017-03-03 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix corruptK + +if {[permutation]=="mmap"} { + finish_test + return +} + +# This module uses hard-coded offsets which do not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} +database_may_be_corrupt + +# Initialize the database. +# +do_execsql_test 1.1 { + PRAGMA page_size=1024; + PRAGMA auto_vacuum=0; + CREATE TABLE t1(x); + + INSERT INTO t1 VALUES(randomblob(20)); + INSERT INTO t1 VALUES(randomblob(100)); -- make this into a free slot + INSERT INTO t1 VALUES(randomblob(27)); -- this one will be corrupt + INSERT INTO t1 VALUES(randomblob(800)); + + DELETE FROM t1 WHERE rowid=2; -- free the 100 byte slot + PRAGMA page_count +} {2} + + +# Corrupt the database so that the blob stored immediately before +# the free slot (rowid==3) has an overlarge length field. So that +# we can use sqlite3_blob_write() to manipulate the size field of +# the free slot. +# +# Then use sqlite3_blob_write() to set the size of said free slot +# to 24 bytes (instead of the actual 100). +# +# Then use the new 24 byte slot. Leaving the in-memory version of +# the page with zero free slots and a large nFree value. Then try +# to allocate another slot to get to defragmentPage(). +# +do_test 1.2 { + db close + hexio_write test.db [expr 1024 + 0x360] 21 + hexio_write test.db [expr 1024 + 0x363] [format %x [expr 31*2 + 12]] + sqlite3 db test.db + + set fd [db incrblob t1 x 3] + fconfigure $fd -translation binary -encoding binary + seek $fd 30 + puts -nonewline $fd "\x18" + close $fd +} {} +do_execsql_test 1.3 { + INSERT INTO t1 VALUES(randomblob(20)); +} + +# This test no longer functions due to the deferred computation of +# MemPage.nFree. +# +if 0 { +do_catchsql_test 1.4 { + INSERT INTO t1 VALUES(randomblob(90)); +} {1 {database disk image is malformed}} +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 2.1 { + PRAGMA page_size=1024; + PRAGMA auto_vacuum=0; + CREATE TABLE t1(x); + + INSERT INTO t1 VALUES(randomblob(20)); + INSERT INTO t1 VALUES(randomblob(20)); -- free this one + INSERT INTO t1 VALUES(randomblob(20)); + INSERT INTO t1 VALUES(randomblob(20)); -- and this one + INSERT INTO t1 VALUES(randomblob(20)); -- corrupt this one. + + DELETE FROM t1 WHERE rowid IN(2, 4); + PRAGMA page_count +} {2} + +do_test 2.2 { + db close + hexio_write test.db [expr 1024 + 0x388] 53 + hexio_write test.db [expr 1024 + 0x38A] 03812C + + sqlite3 db test.db + set fd [db incrblob t1 x 5] + fconfigure $fd -translation binary -encoding binary + + seek $fd 22 + puts -nonewline $fd "\x5d" + close $fd +} {} + +do_catchsql_test 2.3 { + INSERT INTO t1 VALUES(randomblob(900)); +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- + +ifcapable vtab { +if {[permutation]!="inmemory_journal"} { + + proc hex2blob {hex} { + # Split on newlines: + set bytes [list] + foreach l [split $hex "\n"] { + if {[string is space $l]} continue + set L [list] + foreach b [split $l] { + if {[string is xdigit $b] && [string length $b]==2} { + lappend L [expr "0x$b"] + } + } + if {[llength $L]!=16} { + error "Badly formed hex (1)" + } + set bytes [concat $bytes $L] + } + + binary format c* $bytes + } + + reset_db + db func hex2blob hex2blob + + do_execsql_test 3.1 { + PRAGMA page_size=1024; + CREATE TABLE t1(a, b, c); + CREATE TABLE t2(a, b, c); + CREATE TABLE t3(a, b, c); + CREATE TABLE t4(a, b, c); + CREATE TABLE t5(a, b, c); + } + sqlite3_db_config db DEFENSIVE 0 + do_execsql_test 3.2 { + UPDATE sqlite_dbpage SET data = hex2blob(' + 000: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. + 010: 04 00 01 01 20 40 20 20 00 00 3e d9 00 00 00 06 .... @ ..>..... + 020: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 04 ................ + 030: 0f 00 00 00 00 00 00 00 00 00 00 01 00 00 83 00 ................ + 040: 00 00 00 00 00 00 00 00 00 00 00 00 00 38 00 00 .............8.. + 050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3e d9 ..............>. + 060: 00 2d e6 07 0d 00 00 00 01 03 a0 00 03 e0 00 00 .-.............. + 070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 0a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 0b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 0c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 0d0: 00 00 00 00 00 c1 00 00 00 00 00 00 00 00 00 00 ................ + 0e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 0f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 110: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 120: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 150: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 160: 00 83 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 170: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 180: 00 00 00 00 00 00 00 00 00 00 07 00 30 00 00 00 ............0... + 190: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 1a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 1b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 1c0: 02 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 ................ + 1d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 1e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 1f0: 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 200: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 210: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 220: 00 00 0e 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 230: 0c 00 00 00 00 00 00 60 00 00 00 06 00 00 c3 00 .......`........ + 240: 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 250: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 260: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 270: 00 00 00 18 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 280: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 290: 04 00 0e 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 2a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 2b0: 00 00 00 00 83 00 8c 00 00 00 00 00 00 00 00 00 ................ + 2c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 2d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 2e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 2f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 300: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 310: 00 78 00 00 00 00 00 00 00 00 00 00 00 00 70 00 .x............p. + 320: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 330: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 340: 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 350: 00 00 00 00 00 68 00 00 00 00 00 00 00 00 00 00 .....h.......... + 360: 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 ................ + 370: 00 00 00 00 00 00 00 00 00 00 00 00 00 08 00 00 ................ + 380: 00 00 00 00 70 00 00 00 00 00 00 00 00 00 00 00 ....p........... + 390: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 3a0: 5e 01 07 17 1b 1b 01 81 13 74 61 62 6c 65 73 65 ^........tablese + 3b0: 6e 73 6f 32 73 73 65 6e 73 6f 72 73 02 43 52 45 nso2ssensors.CRE + 3c0: 41 54 45 20 54 41 42 4c 45 20 73 65 6e 73 6f 72 ATE TABLE sensor + 3d0: 73 20 0a 20 20 24 20 20 20 20 20 20 20 20 20 20 s . $ + 3e0: b8 6e 61 6d 65 21 74 65 78 74 2c 20 79 61 6c 20 .name!text, yal + 3f0: 72 65 61 6c 2c 20 74 69 6d 65 20 74 65 78 74 29 real, time text) + ') WHERE pgno=1 + } + + db close + sqlite3 db test.db + + do_catchsql_test 3.3 { + PRAGMA integrity_check; + } {1 {database disk image is malformed}} + +} ;# [permutation]!="inmemory_journal" +} ;# ifcapable vtab + + + +finish_test diff --git a/test/corruptL.test b/test/corruptL.test new file mode 100644 index 0000000..cf38764 --- /dev/null +++ b/test/corruptL.test @@ -0,0 +1,1508 @@ +# 2019-01-11 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix corruptL + +database_may_be_corrupt + +#------------------------------------------------------------------------- +reset_db +do_test 1.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 356352 pagesize 4096 filename crash-acaae0347204ae.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 d0 00 00 00 .....@ ........ +| 32: 40 00 ea 00 00 00 00 00 00 40 00 00 00 40 00 00 @........@...@.. +| 96: 00 00 00 00 0d 00 00 00 04 0e 9c 00 0f ad 0f 4f ...............O +| 112: 0e fc 0e 9c 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 3728: 00 00 00 00 00 00 00 00 00 00 00 00 5e 04 07 17 ............^... +| 3744: 1f 1f 01 81 0b 74 61 62 6c 65 74 31 5f 70 61 72 .....tablet1_par +| 3760: 65 6e 74 74 31 5f 70 61 72 65 6e 74 04 43 52 45 entt1_parent.CRE +| 3776: 41 54 45 20 54 41 42 4c 45 20 22 74 31 5f 70 61 ATE TABLE .t1_pa +| 3792: 72 65 6e 74 22 28 6e 6f 64 65 6e 6f 20 49 4e 54 rent.(nodeno INT +| 3808: 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 EGER PRIMARY KEY +| 3824: 2c 70 61 72 65 6e 74 6e 6f 64 65 29 51 03 06 17 ,parentnode)Q... +| 3840: 1b 1b 01 7b 74 61 62 6c 65 74 31 5f 6e 6f 64 65 ....tablet1_node +| 3856: 74 31 5f 6e 6f 64 65 03 43 52 45 41 54 45 20 54 t1_node.CREATE T +| 3872: 41 42 4c 45 20 22 74 31 5f 6e 6f 64 65 22 28 6e ABLE .t1_node.(n +| 3888: 6f 64 65 6e 6f 20 49 4e 54 45 47 45 52 20 50 52 odeno INTEGER PR +| 3904: 49 4d 41 52 59 20 4b 45 59 2c 64 61 74 61 29 5c IMARY KEY,data). +| 3920: 02 07 17 1d 1d 01 81 0b 74 61 62 6c 65 74 31 5f ........tablet1_ +| 3936: 72 6f 77 69 64 74 31 5f 72 6f 77 69 64 02 43 52 rowidt1_rowid.CR +| 3952: 45 41 54 45 20 54 41 42 4c 45 20 22 74 31 5f 72 EATE TABLE .t1_r +| 3968: 6f 77 69 64 22 28 72 6f 77 69 64 20 49 4e 54 45 owid.(rowid INTE +| 3984: 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c GER PRIMARY KEY, +| 4000: 6e 6f 64 65 6e 6f 2c 61 30 2c 61 31 29 51 01 07 nodeno,a0,a1)Q.. +| 4016: 17 11 11 08 81 0f 74 61 62 6c 65 74 31 74 31 43 ......tablet1t1C +| 4032: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 REATE VIRTUAL TA +| 4048: 42 4c 45 20 74 31 20 55 53 49 4e 47 20 72 74 72 BLE t1 USING rtr +| 4064: 65 65 28 69 64 2c 78 30 20 50 52 49 4d 41 52 59 ee(id,x0 PRIMARY +| 4080: 20 4b 45 59 2c 70 61 72 65 6e 74 6e 6f 64 65 29 KEY,parentnode) +| page 2 offset 4096 +| 0: 51 03 06 17 1b 1b 01 7b 74 61 62 6c 65 74 31 5f Q.......tablet1_ +| 16: 6e 6f 64 65 74 31 5f 6e 6f 64 65 03 43 52 45 41 nodet1_node.CREA +| 32: 54 45 20 54 41 42 4c 45 20 22 74 31 5f 6e 6f 64 TE TABLE .t1_nod +| 48: 65 22 28 6e 6f 64 65 6e 6f 20 49 4e 54 45 47 45 e.(nodeno INTEGE +| 64: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 64 61 R PRIMARY KEY,da +| 80: 74 61 29 5c 02 07 17 1d 1d 01 81 0b 74 61 62 6c ta).........tabl +| 96: 65 74 31 5f 72 6f 77 69 64 74 31 5f 72 6f 77 69 et1_rowidt1_rowi +| 112: 64 02 43 52 45 41 54 45 20 54 41 42 4c 45 00 00 d.CREATE TABLE.. +| 128: 01 0a 02 00 00 00 01 0e 0d 00 00 00 00 24 0e 0d .............$.. +| 144: 0c 1a 06 85 50 46 60 27 70 08 00 00 00 00 00 00 ....PF`'p....... +| 3824: 00 00 00 00 00 00 00 0d 0e 05 00 09 1d 00 74 6f ..............to +| 3840: 79 20 68 61 6c 66 10 0d 05 00 09 23 00 62 6f 74 y half.....#.bot +| 3856: 74 6f 6d 20 68 61 6c 66 0f 0c 05 00 09 21 00 72 tom half.....!.r +| 3872: 69 67 68 74 20 68 61 6c 66 0e 0b 05 00 09 1f 00 ight half....... +| 3888: 6c 65 66 74 20 43 15 f6 e6 f6 46 50 34 35 24 54 left C....FP45$T +| 3904: 15 44 52 05 44 14 24 c4 52 02 27 43 15 f6 e6 f6 .DR.D.$.R.'C.... +| 3920: 46 52 22 8e 6f 64 65 6e 6f 20 49 4e 54 45 47 45 FR..odeno INTEGE +| 3936: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 64 61 R PRIMARY KEY,da +| 3952: 74 61 29 5c 02 07 17 1d 1d 01 81 0b 74 61 62 6c ta).........tabl +| 3968: 65 74 31 5f 72 6f 74 74 6f 6d 20 65 64 67 65 0f et1_rottom edge. +| 3984: 07 05 00 09 21 00 72 69 67 68 74 20 65 64 67 65 ....!.right edge +| 4000: 0e 06 05 00 09 1f 00 6c 65 66 74 20 65 64 67 65 .......left edge +| 4016: 0b 05 05 00 09 19 00 63 65 6e 74 65 72 17 04 05 .......center... +| 4032: 00 09 31 00 75 70 70 65 72 2d 72 69 67 68 74 20 ..1.upper-right +| 4048: 63 6f 72 6e 65 72 17 03 05 00 09 31 00 6c 6f 77 corner.....1.low +| 4064: 65 72 2d 72 69 67 68 74 20 63 6f 72 6e 65 72 16 er-right corner. +| 4080: 02 05 00 09 2f 00 75 70 70 65 72 2d 6c 65 66 74 ..../.upper-left +| page 3 offset 8192 +| 0: 20 63 6f 72 6e 65 72 16 01 05 00 09 2f 01 8c 6f corner...../..o +| 16: 77 65 72 2d 6c 53 51 4c 69 74 65 20 66 6f 72 6d wer-lSQLite form +| 32: 61 74 20 33 00 10 00 01 01 00 40 20 20 00 00 00 at 3......@ ... +| 48: 00 00 00 00 2f 00 00 0d eb 13 00 00 00 03 00 00 ..../........... +| 64: 00 04 00 00 00 00 00 00 00 06 00 00 00 01 00 00 ................ +| 80: 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 ................ +| page 6 offset 20480 +| 128: 00 00 00 00 00 00 00 00 97 3d 04 ae 7c 01 00 00 .........=..|... +| 624: 00 00 00 00 00 00 21 97 3d 04 ae 7c 01 00 00 00 ......!.=..|.... +| 1120: 00 00 00 00 00 20 97 3d 04 ae 7c 01 00 00 00 00 ..... .=..|..... +| 1616: 00 00 00 00 1f 97 3d 04 ae 7c 01 00 00 00 00 00 ......=..|...... +| 2112: 00 00 00 1e 97 3d 04 ae 7c 01 00 00 00 00 00 00 .....=..|....... +| 2608: 00 00 1d 97 d3 d0 4a e7 c0 00 00 00 00 00 00 00 ......J......... +| 3088: 00 00 00 00 00 00 00 00 00 00 00 00 01 f3 00 00 ................ +| 3600: 23 97 3d 04 ae 7c 01 00 00 00 00 00 00 00 00 00 #.=..|.......... +| 4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 26 ...............& +| page 8 offset 28672 +| 0: 0d 00 00 00 01 04 30 00 04 30 00 00 00 00 00 00 ......0..0...... +| 1072: 97 4d 1e 14 00 ae 7c 00 00 00 00 00 00 00 00 00 .M....|......... +| 1088: 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 ................ +| 4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 ................ +| page 10 offset 36864 +| 0: 0d 00 00 00 01 04 30 00 04 30 00 00 00 00 00 00 ......0..0...... +| 1072: 9a ee c1 80 fd 78 1f ce 1b ae eb b4 00 00 00 00 .....x.......... +| 1088: 13 20 ff 20 00 70 00 00 00 60 50 00 00 00 11 e0 . . .p...`P..... +| 1104: 00 00 00 70 00 00 00 60 50 05 35 14 c6 97 46 52 ...p...`P.5...FR +| 1120: 06 66 f7 26 d6 17 42 03 30 01 00 00 10 10 04 02 .f.&..B.0....... +| 1136: 02 00 00 00 00 00 00 00 00 40 00 00 00 00 00 00 .........@...... +| 1152: 00 00 00 00 00 40 00 00 00 40 00 00 00 00 00 00 .....@...@...... +| 4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 ................ +| page 12 offset 45056 +| 0: 0d 00 00 00 01 04 30 00 04 30 e1 b4 30 97 4d 46 ......0..0..0.MF +| 16: 14 00 ae 7c 00 00 00 00 00 00 00 03 00 00 43 00 ...|..........C. +| page 47 offset 188416 +| 2512: 00 00 00 00 00 00 00 00 be 00 00 00 00 00 00 00 ................ +| page 87 offset 352256 +| 2512: 00 00 00 00 00 00 00 00 aa 00 00 00 00 00 00 00 ................ +| end crash-acaae0347204ae.db +}]} {} + +do_catchsql_test 1.1 { + PRAGMA cell_size_check = off; + DROP INDEX t1x1; +} {1 {database disk image is malformed}} + +do_catchsql_test 1.2 { + SELECT sum(s+length(b)) FROM t1 WHERE a IN (110,10,150) AND q IS NULL; +} {1 {database disk image is malformed}} + +do_catchsql_test 1.3 { + REINDEX t1; +} {1 {database disk image is malformed}} + +do_catchsql_test 1.4 { + PRAGMA integrity_check +} {1 {database disk image is malformed}} + + +#------------------------------------------------------------------------- +reset_db +do_test 2.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 20480 pagesize 4096 filename crash.txt.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 05 .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ +| 96: 00 00 00 00 0d 00 00 00 05 0e 55 00 0f 74 0f 3c ..........U..t.< +| 112: 0e f9 0e d1 0e 55 00 00 00 00 00 00 00 00 00 00 .....U.......... +| 3664: 00 00 00 00 00 7a 05 07 15 11 11 08 81 63 76 69 .....z.......cvi +| 3680: 65 77 76 31 76 31 43 52 45 41 54 45 20 56 49 45 ewv1v1CREATE VIE +| 3696: 57 20 76 31 28 78 2c 79 29 20 41 53 0a 53 45 4c W v1(x,y) AS.SEL +| 3712: 45 43 54 20 74 31 2e 62 2c 74 32 2e 62 20 46 52 ECT t1.b,t2.b FR +| 3728: 4f 4d 20 74 31 2c 74 32 20 57 48 45 52 45 20 74 OM t1,t2 WHERE t +| 3744: 31 2e 61 3d 74 32 2e 61 20 47 52 4f 55 50 20 42 1.a=t2.a GROUP B +| 3760: 59 20 31 20 48 41 56 49 4e 47 20 74 32 2e 63 20 Y 1 HAVING t2.c +| 3776: 4e 4f 54 20 4e 55 4c 4c 0a 4c 49 4d 49 54 20 31 NOT NULL.LIMIT 1 +| 3792: 30 26 04 06 17 11 11 01 39 74 61 62 6c 65 74 32 0&......9tablet2 +| 3808: 74 32 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 t2.CREATE TABLE +| 3824: 74 32 28 61 2c 62 2c 63 29 41 03 06 17 15 11 01 t2(a,b,c)A...... +| 3840: 6b 69 6e 64 65 78 74 31 78 31 74 31 04 43 52 45 kindext1x1t1.CRE +| 3856: 41 54 45 20 49 4e 44 45 58 20 73 31 78 31 20 4f ATE INDEX s1x1 O +| 3872: 4e 20 74 31 28 64 29 20 57 48 45 52 45 20 65 65 N t1(d) WHERE ee +| 3888: 20 49 53 20 4e 4f 54 20 4e 55 4c 4c 36 02 06 17 IS NOT NULL6... +| 3904: 17 11 01 53 69 6e 64 65 78 74 31 61 62 63 74 31 ...Sindext1abct1 +| 3920: 03 43 52 45 41 54 45 20 49 4e 44 45 58 20 74 31 .CREATE INDEX t1 +| 3936: 61 62 63 20 4f 4e 20 74 31 28 61 2c 62 2c 63 2b abc ON t1(a,b,c+ +| 3952: 64 2b 65 29 81 09 01 07 17 11 11 01 81 7d 74 61 d+e)..........ta +| 3968: 62 6c 65 74 31 74 31 02 43 52 45 41 54 45 20 54 blet1t1.CREATE T +| 3984: 41 42 4c 45 20 74 31 28 61 2c 62 2c 63 2c 64 2c ABLE t1(a,b,c,d, +| 4000: 65 2c 66 2c 67 2c 68 2c 6a 2c 6a 6a 2c 6a 6a 6a e,f,g,h,j,jj,jjj +| 4016: 2c 6b 2c 61 61 2c 62 62 2c 63 63 2c 64 64 2c 65 ,k,aa,bb,cc,dd,e +| 4032: 65 20 44 45 46 41 55 4c 54 20 33 2e 31 34 2c 0a e DEFAULT 3.14,. +| 4048: 66 66 20 44 45 46 41 55 4c 54 28 27 68 69 63 63 ff DEFAULT('hicc +| 4064: 75 70 27 29 2c 67 67 20 4e 4f 54 20 4e 55 4c 4c up'),gg NOT NULL +| 4080: 20 44 45 46 41 55 4c 54 28 66 61 6c 73 65 29 29 DEFAULT(false)) +| page 2 offset 4096 +| 0: 0d 00 00 00 0a 0e 7b 00 0f dc 0f b6 0f 8f 0f 68 ...............h +| 16: 0f 41 0f 1a 0e f3 0e cb 0e a3 0e 7b 00 00 00 00 .A.............. +| 3696: 00 00 00 00 00 00 00 00 00 00 00 26 0a 14 01 01 ...........&.... +| 3712: 02 08 00 00 00 00 00 00 00 00 00 00 00 00 07 19 ................ +| 3728: 08 09 5a 00 b4 40 09 1e b8 51 eb 85 1f 68 69 63 ..Z..@...Q...hic +| 3744: 63 75 70 26 09 14 01 01 02 08 00 00 00 00 00 00 cup&............ +| 3760: 00 00 00 00 00 00 07 19 08 08 50 00 a0 40 09 1e ..........P..@.. +| 3776: b8 51 eb 85 1f 68 69 63 63 75 70 26 08 14 01 01 .Q...hiccup&.... +| 3792: 02 08 00 00 00 00 00 00 00 00 00 00 00 00 07 19 ................ +| 3808: 08 07 46 00 8c 40 09 1e b8 51 eb 85 1f 68 69 63 ..F..@...Q...hic +| 3824: 63 75 70 25 07 14 01 01 01 08 00 00 00 00 00 00 cup%............ +| 3840: 00 00 00 00 00 00 07 b9 08 06 3c 78 40 09 1e b8 .............|......... +| 1088: 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 ................ +| 4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 13 ................ +| page 26 offset 102400 +| 2512: 00 00 00 00 00 00 00 0a 00 00 00 00 00 00 00 00 ................ +| page 27 offset 106496 +| 0: 00 00 00 00 00 00 00 12 00 00 00 07 00 00 00 1d ................ +| 16: 00 00 00 09 00 00 00 1f 00 00 00 0b 00 00 00 21 ...............! +| 32: 00 00 00 0d 00 00 00 25 00 00 00 0f 00 00 00 19 .......%........ +| 48: 00 00 00 11 00 00 00 29 00 00 00 13 00 00 00 2b .......).......+ +| 64: 00 00 00 15 00 00 00 2d 00 00 00 2e 00 00 00 17 .......-........ +| page 28 offset 110592 +| 2512: 00 00 00 00 00 00 00 1e 00 00 00 00 00 00 00 00 ................ +| page 30 offset 118784 +| 2512: 00 00 00 00 00 00 00 32 00 00 00 00 00 00 00 00 .......2........ +| page 32 offset 126976 +| 2512: 00 00 00 00 00 00 00 46 00 00 00 00 00 00 00 00 .......F........ +| page 34 offset 135168 +| 2512: 00 00 00 00 00 00 00 5a 00 00 00 00 00 00 00 00 .......Z........ +| page 35 offset 139264 +| 0: 0a 08 44 00 05 02 77 00 0e 11 0a 33 06 55 02 77 ..D...w....3.U.w +| 16: 04 66 00 88 00 88 00 88 00 00 00 00 00 00 00 00 .f.............. +| 128: 00 00 00 00 00 00 00 00 04 66 01 ef 00 00 00 00 .........f...... +| 624: 00 00 00 00 00 00 00 97 3d 04 ae 7c 01 00 00 00 ........=..|.... +| 1120: 00 00 00 00 00 20 97 3d 04 ae 7c 01 00 00 00 00 ..... .=..|..... +| 1616: 00 00 00 00 22 97 3d 04 ae 7c 01 00 00 00 00 00 ......=..|...... +| 2112: 00 00 00 1e 0c 22 01 ef 00 00 00 00 00 00 00 00 ................ +| 2608: 00 00 00 97 3d 04 ae 7c 01 00 00 00 00 00 00 00 ....=..|........ +| 3104: 00 1c 00 00 01 ef 00 00 00 00 00 00 00 00 00 00 ................ +| 3600: 00 97 3d 04 ae 7c 01 00 00 00 00 00 00 00 00 00 ..=..|.......... +| 4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1a ................ +| page 36 offset 143360 +| 0: 0a 08 44 00 04 02 77 00 06 55 02 77 04 66 0e 11 ..D...w..U.w.f.. +| 16: 00 88 00 88 00 88 0e 11 00 00 00 00 00 00 00 00 ................ +| 128: 00 00 00 00 00 00 00 00 04 76 01 ef 00 00 00 00 .........v...... +| 624: 00 00 00 00 00 00 00 97 3e 04 ae 7c 02 00 00 00 ........>..|.... +| 1120: 00 00 00 00 00 2a 97 3e 04 ae 7c 02 00 00 00 00 .....*.>..|..... +| 1616: 00 00 00 00 2c 97 3e 04 ae 7c 02 00 00 00 00 00 ....,.>..|...... +| 2112: 00 00 00 28 00 00 05 cd 00 00 00 00 00 00 00 00 ...(............ +| 3600: 00 97 3e 04 ae 7c 02 00 00 00 00 00 00 00 00 00 ..>..|.......... +| 4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2f .............../ +| page 38 offset 151552 +| 2512: 00 00 00 00 00 00 00 6e 00 00 00 00 00 00 00 00 .......n........ +| page 40 offset 159744 +| 2512: 00 00 00 00 00 00 00 00 82 00 00 00 00 00 00 00 ................ +| page 42 offset 167936 +| 2512: 00 00 00 00 00 00 00 00 96 00 00 00 00 00 00 00 ................ +| page 44 offset 176128 +| 2512: 00 00 00 00 00 00 00 00 aa 00 00 00 00 00 00 00 ................ +| page 47 offset 188416 +| 2512: 00 00 00 00 00 00 00 00 be 00 00 00 00 00 00 00 ................ +| end crash-9ae5502296c949.db +}]} {} + +do_catchsql_test 5.1 { + INSERT INTO t1(b) VALUES(zeroblob(40000)); +} {1 {database disk image is malformed}} + +do_catchsql_test 5.2 { + DROP INDEX t1x2; +} {0 {}} + +do_catchsql_test 5.3 { + INSERT INTO t1(b) VALUES(zeroblob(40000)); +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +reset_db +do_test 6.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 20480 pagesize 4096 filename crash-d260f001fa015c.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 05 .....@ ........ +| 32: 00 00 00 00 00 ff ff f0 00 00 00 02 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 64 00 00 00 01 00 00 00 00 .......d........ +| 96: 00 00 00 00 0d 0f f8 00 04 0e ce 00 0f 4c 0f d3 .............L.. +| 112: 0e fa 0e ce 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 3776: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2a 04 ..............*. +| 3792: 06 17 13 11 01 3f 69 6e 64 65 78 74 31 62 74 31 .....?indext1bt1 +| 3808: 05 43 52 45 41 54 45 20 49 4e 44 45 58 20 74 31 .CREATE INDEX t1 +| 3824: 62 20 4f 4e 20 74 31 28 62 29 50 03 06 17 2b 2b b ON t1(b)P...++ +| 3840: 01 59 74 61 62 6c 65 73 71 6c 69 74 65 5f 73 65 .Ytablesqlite_se +| 3856: 71 75 65 6e 63 65 73 71 6c 69 74 65 5f 73 65 71 quencesqlite_seq +| 3872: 75 65 6e 63 65 04 43 52 45 41 54 45 20 54 41 42 uence.CREATE TAB +| 3888: 4c 45 20 73 71 6c 69 74 65 5f 73 65 71 75 65 6e LE sqlite_sequen +| 3904: 63 65 28 6e 61 6d 65 2c 73 65 71 29 81 04 01 07 ce(name,seq).... +| 3920: 17 11 11 01 81 73 74 61 62 6c 65 74 31 74 31 02 .....stablet1t1. +| 3936: 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 31 28 CREATE TABLE t1( +| 3952: 61 20 52 45 41 4c 20 4e 4f 54 20 4e 55 4c 4c 20 a REAL NOT NULL +| 3968: 44 45 46 41 55 4c 54 28 32 35 2b 33 32 29 2c 62 DEFAULT(25+32),b +| 3984: 20 46 4c 4f 41 54 2c 63 20 44 4f 55 42 4c 45 20 FLOAT,c DOUBLE +| 4000: 55 4e 49 51 55 45 2c 0a 64 20 43 4c 4f 42 2c 65 UNIQUE,.d CLOB,e +| 4016: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 INTEGER PRIMARY +| 4032: 20 4b 45 59 20 41 55 54 4f 49 4e 43 52 45 4d 45 KEY AUTOINCREME +| 4048: 4e 54 29 23 02 06 17 37 11 01 00 69 6e 64 65 78 NT)#...7...index +| 4064: 73 71 6c 69 74 65 5f 61 75 74 6f 69 6e 64 65 78 sqlite_autoindex +| 4080: 5f 74 31 5f 31 74 31 05 00 00 00 08 00 00 00 00 _t1_1t1......... +| page 2 offset 4096 +| 0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................ +| page 3 offset 8192 +| 0: 0a 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................ +| page 4 offset 12288 +| 0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................ +| page 5 offset 16384 +| 0: 0a 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................ +| end crash-d260f001fa015c.db +}]} {} + +do_catchsql_test 6.1 { + BEGIN; + INSERT INTO t1(b) VALUES(1); + INSERT INTO t1(b) VALUES(2); + COMMIT; +} {1 {malformed database schema (t1b) - invalid rootpage}} + +#------------------------------------------------------------------------- +reset_db +do_test 7.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 20480 pagesize 4096 filename crash-8391315d75edff.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 05 .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ +| 96: 00 00 00 00 0d 00 00 00 05 0e 55 00 0f 74 0f 3c ..........U..t.< +| 112: 0e f9 0e d1 0e 55 00 00 00 00 00 00 00 00 00 00 .....U.......... +| 3664: 00 00 00 00 00 7a 05 07 15 11 11 08 81 63 76 69 .....z.......cvi +| 3680: 65 77 76 31 76 31 43 52 45 41 54 45 20 56 49 45 ewv1v1CREATE VIE +| 3696: 57 20 76 31 28 78 2c 69 29 20 41 53 0a 53 45 4c W v1(x,i) AS.SEL +| 3712: 45 43 54 20 74 31 2e 62 2c 74 32 2e 62 20 46 52 ECT t1.b,t2.b FR +| 3728: 4f 4d 20 74 31 2c 74 32 20 57 48 45 52 45 20 74 OM t1,t2 WHERE t +| 3744: 31 2e 61 3d 74 32 2e 61 20 47 52 4f 55 50 20 42 1.a=t2.a GROUP B +| 3760: 59 20 31 20 48 41 56 49 4e 47 20 74 32 2e 63 20 Y 1 HAVING t2.c +| 3776: 4e 4f 54 20 4e 55 4c 4c 0a 4c 49 4d 49 54 20 31 NOT NULL.LIMIT 1 +| 3792: 30 26 04 06 17 11 11 01 39 74 61 62 6c 65 74 32 0&......9tablet2 +| 3808: 74 32 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 t2.CREATE TABLE +| 3824: 74 32 28 61 2c 62 2c 63 29 41 03 06 17 15 11 01 t2(a,b,c)A...... +| 3840: 6b 69 6e 64 65 78 74 31 78 31 74 31 03 43 52 45 kindext1x1t1.CRE +| 3856: 41 54 45 20 49 4e 44 45 58 20 74 31 78 31 20 4f ATE INDEX t1x1 O +| 3872: 4e 20 74 31 28 64 29 20 57 48 45 52 45 20 65 65 N t1(d) WHERE ee +| 3888: 20 49 53 20 4e 4f 54 20 4e 55 4c 4c 36 02 06 17 IS NOT NULL6... +| 3904: 17 11 01 53 69 6e 64 65 78 74 31 61 62 63 74 31 ...Sindext1abct1 +| 3920: 03 43 52 45 41 54 45 20 49 4e 44 45 58 20 74 31 .CREATE INDEX t1 +| 3936: 61 62 63 20 4f 4e 20 74 31 28 61 2c 62 2c 63 2b abc ON t1(a,b,c+ +| 3952: 64 2b 65 29 81 09 01 07 17 11 11 01 81 7d 74 61 d+e)..........ta +| 3968: 62 6c 65 74 31 74 31 02 43 52 45 41 54 45 20 54 blet1t1.CREATE T +| 3984: 41 42 4c 45 20 74 31 28 61 2c 62 2c 63 2c 64 2c ABLE t1(a,b,c,d, +| 4000: 65 2c 66 2c 67 2c 68 2c 6a 2c 6a 6a 2c 6a 6a 6a e,f,g,h,j,jj,jjj +| 4016: 2c 6b 2c 61 61 2c 62 69 8c 63 63 2c 64 64 2c 65 ,k,aa,bi.cc,dd,e +| 4032: 65 20 44 45 46 41 55 4c 54 20 33 2e 31 34 2c 0a e DEFAULT 3.14,. +| 4048: 66 66 20 44 45 46 41 55 4c 54 28 27 68 69 63 63 ff DEFAULT('hicc +| 4064: 75 70 27 29 2c 67 67 20 4e 4f 54 20 4e 55 4c 4c up'),gg NOT NULL +| 4080: 20 44 45 46 41 55 4c 54 28 66 61 6c 73 65 29 29 DEFAULT(false)) +| page 2 offset 4096 +| 0: 0d 00 00 00 0a 0e 7b 00 0f dc 0f b6 0f 8f 0f 68 ...............h +| 16: 0f 41 0f 1a 0e f3 0e cb 0e a3 0e 22 00 00 00 00 .A.............. +| 3696: 00 00 00 00 00 00 00 00 00 00 00 26 0a 14 01 01 ...........&.... +| 3712: 02 08 00 00 00 00 00 00 00 00 00 00 00 00 07 19 ................ +| 3728: 08 09 5a 00 b4 40 09 1e b8 51 eb 95 1f 68 69 63 ..Z..@...Q...hic +| 3744: 63 75 70 26 09 14 01 01 02 08 00 00 00 00 00 00 cup&............ +| 3760: 00 00 00 00 00 00 07 19 08 08 50 00 a0 40 09 1e ..........P..@.. +| 3776: b8 51 eb 85 1f 68 69 63 63 74 70 26 08 14 01 01 .Q...hicctp&.... +| 3792: 03 08 00 00 00 00 00 00 00 00 00 00 00 00 07 19 ................ +| 3808: 08 07 46 00 8c 40 09 1e b8 51 eb 85 1f 68 69 63 ..F..@...Q...hic +| 3824: 63 75 70 25 07 14 01 01 01 08 00 00 00 00 00 00 cup%............ +| 3840: 00 00 00 00 00 10 07 19 08 06 3c 78 40 09 1e b8 .................. +| 1616: 00 00 00 00 1f 97 00 00 00 00 00 00 00 00 00 00 ................ +| 2112: 00 00 00 1e 97 3d 00 00 00 00 00 00 00 00 00 00 .....=.......... +| 2608: 00 1d 97 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| page 8 offset 28672 +| 1184: 00 00 00 00 00 00 00 00 00 97 4d 1e 13 ff ae 7c ..........M....| +| 4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 90 ................ +| page 9 offset 32768 +| 256: 0d 01 c0 00 01 04 30 00 04 30 00 00 00 00 00 00 ......0..0...... +| page 10 offset 36864 +| 0: 0d 00 22 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 ................ +| page 12 offset 45056 +| 0: 0d 00 00 00 01 04 30 00 00 00 00 00 00 00 00 00 ......0......... +| page 14 offset 53248 +| 0: 0d 00 00 00 01 04 30 00 04 30 00 00 00 00 00 00 ......0..0...... +| 1072: 96 4d 5a 14 00 00 00 00 00 00 00 00 00 00 00 00 .MZ............. +| page 16 offset 61440 +| 0: 0d 00 00 00 01 04 30 00 04 30 00 00 00 00 00 00 ......0..0...... +| 1072: 97 4d 6e 14 00 ae 7b ff ff ff ff 00 00 00 00 00 .Mn............. +| page 18 offset 69632 +| 1056: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 97 ................ +| 1072: 4d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 M............... +| 4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0d ................ +| page 20 offset 77824 +| 1056: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 97 ................ +| 1072: 4d 81 16 14 00 ae 00 00 00 00 00 00 00 00 00 00 M............... +| 4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0f ................ +| page 22 offset 86016 +| 0: 0d 00 00 00 01 04 2f 00 04 2f 01 00 00 00 00 00 ....../../...... +| 1056: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 97 ................ +| 1072: 4d 81 2a 14 00 00 00 00 00 00 00 00 00 00 00 00 M.*............. +| page 24 offset 94208 +| 1072: 00 97 4c 0a 14 00 ae 7c 00 00 00 00 00 00 00 00 ..L....|........ +| page 25 offset 98304 +| 1056: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 97 ................ +| 1072: 4d 81 3e 14 00 ae 7c 00 00 18 ff 00 00 00 00 00 M.>...|......... +| page 27 offset 106496 +| 0: 00 00 00 00 00 00 00 12 00 00 00 07 00 00 00 1d ................ +| 16: 00 00 00 09 00 00 00 1f 00 00 00 0b 00 00 00 21 ...............! +| 32: 00 00 00 0d 00 10 00 25 00 00 00 0f 00 00 00 27 .......%.......' +| 48: 00 00 00 11 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| page 32 offset 126976 +| 2512: 00 00 00 00 00 00 00 45 21 00 00 00 00 00 00 00 .......E!....... +| page 35 offset 139264 +| 0: 00 0a 08 44 00 05 02 77 00 0e 11 0a 92 00 00 00 ...D...w........ +| 1120: 00 00 00 00 00 20 97 00 00 00 00 00 00 00 00 00 ..... .......... +| 1616: 00 00 00 00 22 00 00 00 00 00 00 00 00 00 00 00 ................ +| 2608: 00 00 00 97 3d 04 00 00 00 00 00 00 00 00 00 00 ....=........... +| 3104: 00 1c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 3600: 00 97 3d 04 ae 7c 00 00 00 00 00 00 00 00 00 00 ..=..|.......... +| 4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1a ................ +| page 36 offset 143360 +| 0: 0a 08 44 00 04 02 00 00 00 00 00 00 00 00 00 00 ..D............. +| 1120: 00 00 00 00 00 2a 97 3e 04 00 00 00 00 00 00 00 .....*.>........ +| 1616: 00 00 00 00 2c 97 3e 00 00 00 00 00 00 00 00 00 ....,.>......... +| 2112: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 38 ...............8 +| 2128: 00 00 05 cd 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 3600: 00 97 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| page 38 offset 151552 +| 2464: 00 00 00 00 00 00 00 00 00 6e 00 00 00 00 00 00 .........n...... +| page 40 offset 159744 +| 2512: 00 00 00 00 00 00 00 00 82 00 00 00 00 00 00 00 ................ +| page 42 offset 167936 +| 2512: 00 00 00 00 00 00 00 96 00 00 00 00 00 00 00 00 ................ +| page 44 offset 176128 +| 2512: 00 00 00 00 00 00 00 00 aa 00 00 00 00 00 00 00 ................ +| end crash-41390d95d613b6.db +}]} {} + +do_catchsql_test 10.1 { + PRAGMA writable_schema=ON; -- bypass improved sqlite_master consistency checking + SELECT * FROM t1 WHERE a<='2019-05-09' ORDER BY a DESC; +} {1 {database disk image is malformed}} + + +#------------------------------------------------------------------------- +reset_db +do_test 11.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 595 pagesize 512 filename x.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 02 00 00 01 00 40 20 20 00 01 00 0c 00 00 00 07 .....@ ........ +| 32: 00 00 00 05 07 a1 1f fa 00 00 00 08 00 00 00 04 ................ +| 48: 00 00 01 00 00 49 00 00 00 00 00 05 00 00 00 00 .....I.......... +| 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1c ................ +| 96: 00 2e 2c 50 0d 00 00 00 06 01 06 00 01 da 01 b0 ..,P............ +| 112: 01 56 01 86 01 2a 01 06 00 00 62 00 00 00 00 00 .V...*....b..... +| 128: 00 ed e2 78 74 64 33 ff 43 52 45 41 54 45 20 49 ...xtd3.CREATE I +| 144: 4e 44 45 58 20 74 33 78 20 4f 4e 20 74 33 28 38 NDEX t3x ON t3(8 +| 160: 29 2e 04 06 17 15 11 01 45 69 6e 64 65 68 74 32 ).......Eindeht2 +| 176: 63 64 74 31 e5 43 52 45 41 54 45 20 49 4e 44 45 cdt1.CREATE INDE +| 192: 58 20 74 32 63 c4 20 4f 4e 20 74 32 28 63 2c 64 X t2c. ON t2(c,d +| 208: 29 28 05 06 17 01 11 11 3d 74 61 6c 36 74 62 74 )(......=tal6tbt +| 224: 65 32 04 43 52 45 41 54 45 20 54 41 42 4c 45 20 e2.CREATE TABLE +| 240: 74 00 04 00 00 00 00 00 00 00 00 00 00 00 00 00 t............... +| 256: 00 00 00 00 00 00 22 07 06 17 11 11 01 30 e8 03 .............0.. +| 272: 62 6c 65 74 34 74 35 02 43 52 45 41 54 45 20 54 blet4t5.CREATE T +| 288: 41 42 4c 45 20 74 34 28 94 29 2a 06 06 17 13 11 ABLE t4(.)*..... +| 304: 01 3f 69 33 74 6e 65 78 78 74 64 33 ff 43 52 45 .?i3tnexxtd3.CRE +| 320: 41 54 45 20 49 4e 44 45 58 20 74 33 78 20 4f 4e ATE INDEX t3x ON +| 336: 20 74 31 28 38 29 2e 04 06 17 15 11 01 45 69 6e t1(8).......Ein +| 352: 64 65 68 74 32 63 64 74 31 e5 43 52 45 41 54 45 deht2cdt1.CREATE +| 368: 20 49 4e 44 45 58 20 74 32 63 c4 20 4f 4e 20 74 INDEX t2c. ON t +| 384: 32 28 63 2c 64 29 28 05 06 17 01 11 11 3d 74 61 2(c,d)(......=ta +| 400: 6c 32 74 62 74 65 32 04 43 52 45 41 54 45 20 54 l2tbte2.CREATE T +| 416: 41 42 4c 45 20 74 33 28 63 2c 78 2c 65 2c 66 29 ABLE t3(c,x,e,f) +| 432: 28 02 06 17 11 11 01 3d 74 61 9e 93 65 74 32 74 (......=ta..et2t +| 448: 32 03 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 2.CREATE TABLE t +| 464: 32 28 63 2c 64 2c 65 2c 66 29 24 01 06 17 11 11 2(c,d,e,f)$..... +| 480: 01 35 55 61 62 6c 88 74 31 74 31 02 43 52 45 41 .5Uabl.t1t1.CREA +| 496: 54 45 20 54 41 42 4c 45 20 74 31 28 61 2c 62 29 TE TABLE t1(a,b) +| page 2 offset 512 +| 0: 0d 00 00 00 0d 25 00 01 cf 00 01 fa 01 f3 01 de .....%.......... +| 16: 01 00 00 00 fd 00 00 0d 00 00 00 00 45 20 54 41 ............E TA +| 32: 42 4c 45 20 74 34 28 94 29 2a 06 06 17 13 11 01 BLE t4(.)*...... +| 48: 3f 69 33 74 6e 65 78 78 74 64 33 ff 43 52 45 a0 ?i3tnexxtd3.CRE. +| 64: a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 74 13 11 01 ............t... +| 80: 49 45 74 00 00 00 00 00 00 00 00 00 00 00 00 00 IEt............. +| end x.db +}]} {} + +do_catchsql_test 11.1 { + PRAGMA writable_schema=ON; -- bypass improved sqlite_master consistency checking + DELETE FROM t3 WHERE x IN (SELECT x FROM t4); +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +reset_db +do_test 12.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 12288 pagesize 4096 filename crash-e6d070858a3a85.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 00 .....@ ........ +| 96: 00 00 00 00 0d 00 00 00 02 0f 8f 00 0f bf 0f 8f ................ +| 3968: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2e ................ +| 3984: 02 06 17 15 11 01 45 69 6e 64 65 78 74 31 63 62 ......Eindext1cb +| 4000: 74 31 03 43 52 45 41 54 45 20 49 4e 44 45 58 20 t1.CREATE INDEX +| 4016: 74 31 63 62 20 4f 4e 20 74 31 28 63 2c 62 29 3f t1cb ON t1(c,b)? +| 4032: 01 06 17 11 11 01 6b 74 61 62 6c 65 74 31 74 31 ......ktablet1t1 +| 4048: 02 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 31 .CREATE TABLE t1 +| 4064: 28 61 20 49 4e 54 2c 20 62 20 49 4e 54 2c 20 43 (a INT, b INT, C +| 4080: 20 49 4e 54 20 44 45 46 41 55 4c 54 20 31 36 29 INT DEFAULT 16) +| page 2 offset 4096 +| 0: 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 4000: 00 00 00 00 00 00 00 00 07 0b 04 01 01 01 63 63 ..............cc +| 4016: 11 05 0a 04 00 00 01 11 05 09 04 08 08 01 0f 05 ................ +| 4032: 08 04 00 00 01 01 56 07 04 01 08 01 07 10 07 06 ......V......... +| 4048: 14 01 01 01 06 08 10 06 05 04 f5 00 01 05 10 07 ................ +| 4064: 04 04 01 01 01 04 03 10 06 03 04 01 09 01 03 10 ................ +| 4080: 06 02 04 01 00 01 02 10 06 01 04 09 01 01 02 10 ................ +| page 3 offset 8192 +| 0: 0a 00 00 00 0b 0f b0 00 0f f9 0f f2 0f eb 0f e4 ................ +| 16: 0f dd 0f d6 0f 9f 0f c7 0f be 00 00 00 00 00 00 ................ +| 4016: 07 04 01 01 01 11 e2 0b 06 04 91 00 01 11 0a 07 ................ +| 4032: 04 01 01 01 10 08 06 07 04 01 01 01 10 04 04 06 ................ +| 4048: 04 01 01 09 10 02 06 04 01 0a 01 10 00 00 00 00 ................ +| end crash-e6d070858a3a85.db +}]} {} + +do_catchsql_test 12.1 { + SELECT CAST((SELECT b FROM t1 WHERE 16=c) AS int) FROM t1 WHERE 16=c; +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +reset_db +do_test 13.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 8192 pagesize 4096 filename crash-81dd2952aef34f.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 02 .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ +| 96: 00 00 00 00 0d 00 00 00 01 0f c4 00 0f c4 00 00 ................ +| 4032: 00 00 00 00 3a 11 06 17 11 11 01 61 74 61 62 6c ....:......atabl +| 4048: 65 74 31 74 31 02 43 52 45 41 54 45 20 54 41 42 et1t1.CREATE TAB +| 4064: 4c 45 20 74 31 28 61 20 49 4e 54 45 47 45 52 20 LE t1(a INTEGER +| 4080: 50 52 49 4d 41 52 59 20 4b 45 59 2c 62 2c 63 29 PRIMARY KEY,b,c) +| page 2 offset 4096 +| 0: 0d 07 70 00 02 0f eb 00 0f fa 00 00 00 00 00 00 ..p............. +| 4064: 00 00 00 00 00 00 00 00 00 00 00 05 bf ff ff ff ................ +| 4080: ff ff ff ff ff 04 00 01 00 02 04 01 00 00 00 00 ................ +| end crash-81dd2952aef34f.db +}]} {} + +do_catchsql_test 13.1 { + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x-2019 FROM c WHERE x<2) + INSERT INTO t1(b,c) SELECT last_insert_rowid(), x FROM c; +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +reset_db +do_test 14.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 512 pagesize 65536 filename clusterfuzz-testcase-minimized-sqlite3_dbfuzz2_fuzzer-4806406219825152 +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 00 01 02 01 00 40 20 20 00 63 2e 78 00 00 00 07 .....@ .c.x.... +| 32: 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 01 00 35 05 43 00 04 00 00 00 ........5.C..... +| 80: 00 00 00 00 00 00 00 00 08 00 00 00 00 00 00 0c ................ +| 96: 00 2e 2c 50 0d 00 00 00 03 00 00 00 01 da 01 b0 ..,P............ +| 112: 01 56 01 86 01 2a 01 02 00 00 00 00 00 00 00 1c .V...*.......... +| 128: 00 38 80 b2 e6 0e 00 00 00 00 00 00 00 00 00 10 .8.............. +| 144: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 ................ +| 160: 00 00 00 00 00 00 00 00 00 00 00 00 45 20 54 41 ............E TA +| 256: 00 00 00 00 00 00 22 07 06 17 11 11 01 35 74 61 .............5ta +| 272: 62 6c 00 10 00 00 34 07 43 52 54 45 20 54 41 42 bl....4.CRTE TAB +| 288: 4c 45 20 74 33 28 63 2e 78 2c 65 2c 66 15 28 3a LE t3(c.x,e,f.(: +| 304: 06 17 11 11 01 65 78 8c cc 87 85 35 05 43 72 45 .....ex....5.CrE +| 320: 41 54 48 20 49 4e 44 45 58 20 74 33 78 20 4f 4e ATH INDEX t3x ON +| 336: 20 74 33 28 78 39 2e 04 06 17 15 11 01 45 69 6e t3(x9.......Ein +| 352: 64 65 78 74 32 63 64 74 32 05 43 52 45 41 54 45 dext2cdt2.CREATE +| 368: 20 49 4e 44 45 58 20 74 32 63 64 20 4f 4e 20 74 INDEX t2cd ON t +| 384: 32 28 63 2a 44 29 28 05 fa e8 ee ed 01 3d 74 63 2(c*D)(......=tc +| 400: 62 6c 65 74 33 74 33 07 43 52 45 41 54 45 20 54 blet3t3.CREATE T +| 416: 41 42 4c 45 20 74 33 28 63 2e 78 2c 65 2c 66 15 ABLE t3(c.x,e,f. +| 432: 28 3a 06 17 11 11 01 3d 74 61 62 6c 65 74 32 74 (:.....=tablet2t +| 448: 32 03 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 2.CREATE TABLE t +| 464: 32 28 63 2c 64 2c 65 2c 66 29 24 01 06 17 11 11 2(c,d,e,f)$..... +| 480: 01 35 74 61 62 6c 65 74 31 74 31 02 43 52 45 41 .5tablet1t1.CREA +| 496: 54 45 20 54 41 42 4c 45 20 74 31 28 61 2c 63 29 TE TABLE t1(a,c) +| end clusterfuzz-testcase-minimized-sqlite3_dbfuzz2_fuzzer-4806406219825152 +}]} {} + +extra_schema_checks 0 +do_catchsql_test 14.1 { + PRAGMA integrity_check; +} {1 {database disk image is malformed}} + +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. +ifcapable altertable { + do_catchsql_test 14.2 { + ALTER TABLE t1 RENAME TO alkjalkjdfiiiwuer987lkjwer82mx97sf98788s9789s; + } {1 {database disk image is malformed}} +} +extra_schema_checks 1 + +#------------------------------------------------------------------------- +reset_db +do_test 15.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 28672 pagesize 4096 filename crash-3afa1ca9e9c1bd.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07 .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ +| 96: 00 00 00 00 0d 00 00 00 06 0e 88 00 0f b8 0f 6d ...............m +| 112: 0f 3a 0f 0b 0e d5 0e 88 01 00 00 00 00 00 00 00 .:.............. +| 3712: 00 00 00 00 00 00 00 00 4b 06 06 17 25 25 01 5b ........K...%%.[ +| 3728: 74 61 62 6c 65 73 71 6c 69 74 65 5f 73 74 61 74 tablesqlite_stat +| 3744: 31 73 71 6c 69 74 65 5f 73 74 61 74 31 07 43 52 1sqlite_stat1.CR +| 3760: 45 41 54 45 20 54 41 42 4c 45 20 73 71 6c 69 74 EATE TABLE sqlit +| 3776: 65 5f 73 74 61 74 31 28 74 62 6c 2c 69 64 78 2c e_stat1(tbl,idx, +| 3792: 73 74 61 74 29 34 05 06 17 13 11 01 53 69 6e 64 stat)4......Sind +| 3808: 65 78 63 31 63 63 31 06 43 52 45 41 54 45 20 55 exc1cc1.CREATE U +| 3824: 4e 49 51 55 45 20 49 4e 44 45 58 20 63 31 63 20 NIQUE INDEX c1c +| 3840: 4f 4e 20 63 31 28 63 2c 20 62 29 2d 04 06 17 13 ON c1(c, b)-.... +| 3856: 11 01 45 69 6e 64 65 78 63 31 64 63 31 05 43 52 ..Eindexc1dc1.CR +| 3872: 45 41 54 45 20 49 4e 44 45 58 20 63 31 64 20 4f EATE INDEX c1d O +| 3888: 4e 20 63 31 28 64 2c 20 62 29 31 03 06 17 13 11 N c1(d, b)1..... +| 3904: 01 4d 69 6e 64 65 78 62 31 63 62 31 05 43 52 45 .Mindexb1cb1.CRE +| 3920: 41 54 45 20 55 4e 49 51 55 45 20 49 4e 44 45 58 ATE UNIQUE INDEX +| 3936: 20 62 31 63 20 4f 4e 20 62 31 28 63 29 49 02 06 b1c ON b1(c)I.. +| 3952: 17 11 11 0f 7f 74 61 62 6c 65 63 31 63 31 03 43 .....tablec1c1.C +| 3968: 52 45 41 54 45 20 54 41 42 4c 45 20 63 31 28 61 REATE TABLE c1(a +| 3984: 20 49 4e 54 20 50 52 49 4d 41 52 59 20 4b 45 59 INT PRIMARY KEY +| 4000: 2c 20 62 2c 20 63 2c 20 64 29 20 57 49 54 48 4f , b, c, d) WITHO +| 4016: 55 54 20 52 4f 57 49 44 46 01 06 17 11 11 01 79 UT ROWIDF......y +| 4032: 74 61 62 6c 65 62 31 62 31 02 43 52 45 41 54 45 tableb1b1.CREATE +| 4048: 20 54 41 42 4c 45 20 62 31 28 61 20 49 4e 54 20 TABLE b1(a INT +| 4064: 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 62 2c 20 PRIMARY KEY, b, +| 4080: 63 29 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 c) WITHOUT ROWID +| page 2 offset 4096 +| 0: 0a 00 00 00 07 0f ca 00 0f fa 0f f2 0f ea 0f e2 ................ +| 16: 0f da 00 00 00 01 00 00 00 00 00 00 00 00 00 00 ................ +| 4032: 00 00 00 00 00 00 00 00 00 00 07 04 01 0f 01 06 ................ +| 4048: 67 07 07 04 01 0f 01 06 66 06 07 04 01 0f 01 05 g.......f....... +| 4064: 65 05 07 04 01 0f 01 04 64 04 07 04 01 0f 01 03 e.......d....... +| 4080: 63 03 07 04 01 0f 01 02 62 0f 05 04 09 0f 09 61 c.......b......a +| page 3 offset 8192 +| 0: 0a 00 00 00 07 0f bd 00 0f f9 0f ef 0f e5 0f db ................ +| 16: 0f d1 0f c7 0f bd 00 00 00 00 01 00 00 00 00 00 ................ +| 4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 09 05 01 ................ +| 4032: 0f 01 01 07 61 07 07 09 05 01 0f 01 01 06 61 06 ....a.........a. +| 4048: 06 09 05 01 0f 01 01 05 61 05 05 09 05 01 0f 01 ........a....... +| 4064: 01 04 61 04 04 09 05 01 0f 01 01 03 61 03 03 09 ..a.........a... +| 4080: 05 01 0f 01 01 02 61 0f 02 06 05 09 0f 09 09 61 ......a........a +| page 4 offset 12288 +| 0: 0a 00 00 00 07 0f d8 00 0f fc 0f f0 0f ea 0f e4 ................ +| 16: 0f de 0f d8 0f f6 00 00 00 00 00 00 00 00 00 00 ................ +| 4048: 00 00 00 00 00 00 00 00 05 03 01 01 07 07 05 03 ................ +| 4064: 01 01 06 06 05 03 01 01 05 05 05 03 01 01 04 04 ................ +| 4080: 05 03 01 01 03 03 05 03 01 01 0f 02 03 03 09 09 ................ +| page 5 offset 16384 +| 0: 0a 00 00 00 07 0f ca 00 0f fa 0f f2 0f ea 0f 00 ................ +| 4032: 00 00 00 00 00 00 00 00 00 00 07 04 01 0f 01 07 ................ +| 4048: 61 07 07 04 01 0f 01 06 61 06 07 04 01 0f 01 05 a.......a....... +| 4064: 61 05 07 04 01 1f 01 04 61 04 07 04 01 0f 01 03 a.......a....... +| 4080: 61 03 07 04 01 0f 01 02 61 02 05 04 09 0f 09 61 a.......a......a +| page 6 offset 20480 +| 0: 0a 00 00 00 07 0f ca 00 0f fa 0f ea 0f e2 00 00 ................ +| 4032: 00 00 00 00 00 00 00 00 00 00 07 04 01 0f 01 07 ................ +| 4048: 61 07 07 04 01 0f 01 06 61 06 07 04 01 0f 01 05 a.......a....... +| 4064: 61 05 07 04 01 0f 01 04 61 04 07 04 01 0f 01 03 a.......a....... +| 4080: 61 03 07 04 01 0f 01 0f 61 02 05 04 09 0f 09 61 a.......a......a +| page 7 offset 24576 +| 0: 0d 00 00 00 05 0f 1c 00 0f f0 0f e0 0f d3 0f c5 ................ +| 16: 0f b8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 4016: 00 00 00 00 00 00 00 00 0b 05 04 11 11 13 62 31 ..............b1 +| 4032: 62 31 37 20 31 0c 04 04 11 13 13 62 31 62 31 63 b17 1......b1b1c +| 4048: 37 20 31 0b 03 04 11 11 13 63 31 63 31 37 20 31 7 1......c1c17 1 +| 4064: 0e 02 04 11 13 07 63 31 63 31 64 37 20 31 20 31 ......c1c1d7 1 1 +| 4080: 0e 01 04 11 13 17 63 31 63 31 63 37 20 31 00 00 ......c1c1c7 1.. +| end crash-3afa1ca9e9c1bd.db +}]} {} + +extra_schema_checks 0 +optimization_control db one-pass off +do_catchsql_test 15.1 { + PRAGMA cell_size_check = 0; + UPDATE c1 SET c= NOT EXISTS(SELECT 1 FROM c1 ORDER BY (SELECT 1 FROM c1 ORDER BY a)) +10 WHERE d BETWEEN 4 AND 7; +} {1 {database disk image is malformed}} +extra_schema_checks 1 +do_execsql_test 15.2 { + PRAGMA integrity_check; +} {/in database main/} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 16.0 { + CREATE TABLE t1(w, x, y, z, UNIQUE(w, x), UNIQUE(y, z)); + INSERT INTO t1 VALUES(1, 1, 1, 1); + + CREATE TABLE t1idx(x, y, i INTEGER, PRIMARY KEY(x)) WITHOUT ROWID; + INSERT INTO t1idx VALUES(10, NULL, 5); + + PRAGMA writable_schema = 1; + UPDATE sqlite_master SET rootpage = ( + SELECT rootpage FROM sqlite_master WHERE name='t1idx' + ) WHERE type = 'index'; +} + +extra_schema_checks 0 +db close +sqlite3 db test.db +extra_schema_checks 1 + +do_catchsql_test 16.1 { + PRAGMA writable_schema = ON; + INSERT INTO t1(rowid, w, x, y, z) VALUES(5, 10, 11, 10, NULL); +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +# Test that corruption is reported from within a checkpoint if the +# expected final size of the database (according to the last commit +# frame in the wal file) is greater than the combined initial sizes +# of the database and wal file. +# +if {[wal_is_capable]} { + reset_db + do_execsql_test 17.0 { + CREATE TABLE t1(o INTEGER PRIMARY KEY, t UNIQUE); + INSERT INTO t1(t) VALUES(randomblob(123)); + INSERT INTO t1(t) SELECT randomblob(123) FROM t1; + INSERT INTO t1(t) SELECT randomblob(123) FROM t1; + INSERT INTO t1(t) SELECT randomblob(123) FROM t1; + INSERT INTO t1(t) SELECT randomblob(123) FROM t1; + INSERT INTO t1(t) SELECT randomblob(123) FROM t1; + INSERT INTO t1(t) SELECT randomblob(123) FROM t1; + INSERT INTO t1(t) SELECT randomblob(123) FROM t1; + INSERT INTO t1(t) SELECT randomblob(123) FROM t1; + INSERT INTO t1(t) SELECT randomblob(123) FROM t1; + + PRAGMA journal_mode = wal; + INSERT INTO t1 VALUES(-1, 'b'); + } {wal} + + do_test 17.1 { + set fd [open test.db r+] + chan truncate $fd 2048 + file size test.db + } {2048} + + do_catchsql_test 17.2 { + PRAGMA wal_checkpoint + } {1 {database disk image is malformed}} + + do_test 17.3 { + close $fd + } {} +} + +#------------------------------------------------------------------------- +reset_db +do_test 18.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +.open --hexdb +| size 12288 pagesize 4096 filename crash-40d5739835cbdb.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 00 .....@ ........ +| 96: 00 00 00 00 0d 00 00 00 02 0f 4e 00 0f a2 0f 4e ..........N....N +| 3904: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 52 02 ..............R. +| 3920: 07 17 11 11 01 81 0f 74 61 62 6c 65 74 32 74 32 .......tablet2t2 +| 3936: 03 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 32 .CREATE TABLE t2 +| 3952: 28 61 20 49 4e 54 2c 20 62 20 49 4e 54 45 47 45 (a INT, b INTEGE +| 3968: 52 2c 20 50 52 49 4d 41 52 59 20 4b 45 59 28 61 R, PRIMARY KEY(a +| 3984: 2c 62 29 29 20 57 49 54 48 4f 55 54 20 52 4f 57 ,b)) WITHOUT ROW +| 4000: 49 44 5c 01 07 16 11 11 01 81 23 74 61 62 6c 65 ID........#table +| 4016: 74 31 74 31 02 43 52 45 41 54 45 20 54 41 42 4c t1t1.CREATE TABL +| 4032: 45 20 74 31 28 61 20 49 4e 54 20 50 52 49 4d 41 E t1(a INT PRIMA +| 4048: 52 59 20 4b 45 59 2c 20 62 20 54 45 58 54 2c 20 RY KEY, b TEXT, +| 4064: 63 20 54 45 58 54 2c 20 64 20 49 4e 54 45 47 45 c TEXT, d INTEGE +| 4080: 52 29 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 R) WITHOUT ROWID +| page 2 offset 4096 +| 0: 0a 00 00 00 06 0f a7 00 0f f4 0f e5 0f d5 0f c5 ................ +| 16: 0f b6 0f 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 4000: 00 00 00 00 00 00 00 0f 05 01 15 13 01 06 65 7f ..............e. +| 4016: 25 6e 73 69 78 06 0e 05 01 13 15 03 b5 6f 64 64 %nsix........odd +| 4032: 66 69 76 65 05 0f 05 01 15 15 01 04 65 76 65 61 five........evea +| 4048: e6 6f 75 82 04 0f 05 01 13 17 01 03 6f 64 64 74 .ou.........oddt +| 4064: 68 72 61 15 03 0e 05 01 15 12 01 02 64 76 64 6e hra.........dvdn +| 4080: 74 77 6f 02 00 00 00 00 00 00 00 00 00 00 00 00 two............. +| page 3 offset 8192 +| 2816: 00 00 00 00 00 00 00 00 00 00 00 06 03 02 01 00 ................ +| 2832: c8 07 06 03 02 01 00 c7 11 06 03 02 01 02 a6 52 ...............R +| 2848: 06 d5 02 01 10 c5 1b 06 03 02 00 ef c4 53 06 03 .............S.. +| 2864: 02 01 00 c3 22 06 04 02 01 00 c2 26 06 03 02 01 ...........&.... +| 2880: 00 c2 1e 02 b3 02 01 00 c0 3a 06 03 3c 01 00 bf .........:..<... +| 2896: 2c 06 03 02 01 00 be 27 00 83 02 01 01 bd 15 06 ,......'........ +| 2912: 03 02 01 00 bc 21 06 03 02 01 00 bb 54 16 13 02 .....!......T... +| 2928: 01 09 9a 0a 06 03 02 01 00 b9 53 06 03 02 01 00 ..........S..... +| 2944: b8 52 06 13 02 01 00 b7 1e 06 03 02 01 00 b6 34 .R.............4 +| 2960: 06 13 02 01 00 b5 3a 05 f3 12 01 00 b4 45 05 03 ......:......E.. +| 2976: 02 00 00 b4 6f 06 03 02 01 00 b2 03 06 03 02 01 ....o........... +| 2992: 00 b1 63 06 03 02 01 00 b0 24 06 03 02 01 00 9f ..c......$...... +| 3008: ac 06 03 02 01 00 a2 2f 07 03 02 01 01 ad 21 06 ......./......!. +| 3024: 03 02 01 fb cd 5b 06 c0 01 f1 00 ab 23 06 03 02 .....[......#... +| 3040: 01 00 aa 5b 06 03 02 01 00 a3 ce 06 02 03 01 00 ...[............ +| 3056: a8 0e 06 03 02 01 00 a7 0c 06 02 f1 01 00 a6 0d ................ +| 3072: 06 03 02 01 00 95 25 06 03 02 01 00 a4 17 06 03 ......%......... +| 3088: 02 01 00 a3 09 06 03 02 01 00 a2 51 06 03 02 02 ...........Q.... +| 3104: 00 a1 40 06 01 e2 00 00 a0 4b 06 13 02 00 00 9e ..@......K...... +| 3120: 5d 06 03 02 01 10 9e 81 06 03 02 01 00 9d 42 06 ].............B. +| 3136: 03 69 01 00 9c 48 06 03 02 01 00 9b 48 06 03 01 .i...H......H... +| 3152: 01 00 9a 09 06 03 02 01 00 99 2f 06 03 02 01 00 ........../..... +| 3168: 98 3a 06 03 02 01 00 97 24 06 03 02 01 00 96 4a .:......$......J +| 3184: 06 03 02 11 00 f9 50 02 93 02 01 00 94 2f 06 03 ......P....../.. +| 3200: 02 11 04 93 1a 06 03 01 04 e0 92 1a 06 03 02 01 ................ +| 3216: 00 91 27 06 03 02 01 00 90 23 06 03 02 01 00 8f ..'......#...... +| 3232: 3b 06 03 02 01 00 8e 46 06 16 02 01 00 8d 1d 07 ;......F........ +| 3248: 23 12 01 00 8c 5a 06 03 02 01 00 8a 39 06 03 02 #....Z......9... +| 3264: 00 ff 84 b5 06 03 02 01 00 89 07 06 03 02 11 00 ................ +| 3280: 88 02 06 03 02 01 00 87 19 06 03 02 01 00 86 4d ...............M +| 3296: 06 13 12 00 00 85 4b 06 03 02 01 00 84 37 06 13 ......K......7.. +| 3312: 02 01 00 83 2c 06 03 02 01 00 81 60 06 13 02 11 ....,......`.... +| 3328: 00 81 3b 06 03 02 01 0a b0 5a 06 03 01 01 7f 22 ..;......Z...... +| 3344: 05 03 01 01 7e 21 05 03 01 01 7d 0b 15 03 01 02 ....~!.......... +| 3360: 7b 08 05 03 06 91 7b 22 05 03 01 01 7a 58 05 03 ............zX.. +| 3376: 01 01 7a 4f 05 03 01 01 78 49 05 03 01 01 77 16 ..zO....xI....w. +| 3392: 05 03 01 01 76 5f 05 03 01 01 75 0f 05 03 01 01 ....v_....u..... +| 3408: 74 2f 05 03 01 01 3f 1f 05 03 01 02 72 14 05 03 t/....?.....r... +| 3424: 00 f1 71 08 05 03 01 01 70 0c 05 03 01 47 7f 29 ..q.....p....G.) +| 3440: 05 03 01 01 6e 57 05 03 01 01 6d 33 05 13 00 f1 ....nW....m3.... +| 3456: 6c 0b 05 03 01 01 6b 49 05 03 01 01 69 05 05 03 l.....kI....i... +| 3472: 01 02 ed 23 00 00 01 00 00 00 00 00 00 00 00 00 ...#............ +| end crash-40d5739835cbdb.db +}]} {} + +ifcapable json1 { +do_catchsql_test 18.1 { + SELECT + json_group_array(c) OVER win4 + FROM t1 + WINDOW win4 AS ( + ORDER BY a COLLATE nocase RANGE BETWEEN 1.0 PRECEDING AND CURRENT ROW + ) +} {1 {JSON cannot hold BLOB values}} +} ;# ifcapable json1 + +#------------------------------------------------------------------------- +reset_db +do_test 19.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +.open --hexdb +| size 20480 pagesize 4096 filename crash-f022eb0ce64d27.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 05 .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ +| 96: 00 00 00 00 0d 0f f8 00 04 0e d2 00 0f 08 0f d3 ................ +| 112: 0f ae 0e d2 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 3792: 00 00 34 04 06 17 0f 11 01 57 69 6e 64 65 78 61 ..4......Windexa +| 3808: 74 31 05 43 52 45 41 54 45 20 55 4e 49 51 55 45 t1.CREATE UNIQUE +| 3824: 20 49 4e 44 45 58 20 61 20 4f 4e 20 74 31 28 61 INDEX a ON t1(a +| 3840: 2c 20 30 20 7c 20 61 29 81 23 01 07 17 11 11 01 , 0 | a).#...... +| 3856: 82 31 74 61 62 6c 65 74 31 74 31 02 43 52 45 41 .1tablet1t1.CREA +| 3872: 54 45 20 54 41 42 4c 45 20 74 31 28 0a 20 20 20 TE TABLE t1(. +| 3888: 20 67 63 62 20 41 53 20 28 62 2a 31 29 2c 0a 20 gcb AS (b*1),. +| 3904: 20 20 20 61 20 49 34 54 45 47 45 52 20 50 52 49 a I4TEGER PRI +| 3920: 4d 41 52 59 20 4b 45 59 2c 0a 20 20 20 20 67 63 MARY KEY,. gc +| 3936: 63 20 41 53 20 28 74 32 2b 30 29 2c 0a 20 20 20 c AS (t2+0),. +| 3952: 20 62 20 55 4e 49 51 55 45 2c 0a 20 20 20 20 67 b UNIQUE,. g +| 3968: 63 61 20 41 53 20 28 31 2a 61 2b 30 29 2c 0a 20 ca AS (1*a+0),. +| 3984: 20 20 20 74 32 20 55 4e 49 51 55 45 0a 20 20 29 t2 UNIQUE. ) +| 4000: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 23 03 WITHOUT ROWID#. +| 4016: 06 17 37 11 01 00 69 6e 64 65 78 73 71 6c 69 74 ..7...indexsqlit +| 4032: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 33 e_autoindex_t1_3 +| 4048: 74 31 02 23 02 06 17 37 11 01 00 69 6e 64 65 78 t1.#...7...index +| 4064: 73 71 6c 69 74 65 5f 61 75 74 6f 69 6e 64 65 78 sqlite_autoindex +| 4080: 5f 74 31 5f 32 74 31 02 00 00 00 08 00 00 00 00 _t1_2t1......... +| page 2 offset 4096 +| 0: 0a 00 00 00 05 0f d8 00 0f f8 0f f8 9f e8 0f e0 ................ +| 16: 0f d8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 4048: 00 00 00 00 00 00 00 00 07 04 01 02 00 0f 13 88 ................ +| 4064: 07 04 01 02 00 0e 0f a0 07 04 01 02 00 0d 0b b8 ................ +| 4080: 07 04 01 02 00 0c 07 d0 07 04 01 02 00 0b 03 e8 ................ +| page 5 offset 16384 +| 0: 0a 00 00 00 05 0f e2 00 0f fa 0f f4 0f ee 0f e8 ................ +| 16: 0f e2 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 4064: 00 00 05 03 01 01 0f 0f 05 03 01 01 0e 0e 05 03 ................ +| 4080: 01 01 0d 0d 05 03 01 01 0c 0c 05 03 01 01 0b 0b ................ +| end crash-f022eb0ce64d27.db +}]} {} + +do_execsql_test 19.1 { + PRAGMA writable_schema=ON; +} +do_catchsql_test 19.2 { + UPDATE t1 SET a=1; +} {1 {database disk image is malformed}} + +reset_db +do_execsql_test 19.3 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c INTEGER, d TEXT); + CREATE INDEX i1 ON t1((NULL)); + INSERT INTO t1 VALUES(1, NULL, 1, 'text value'); + PRAGMA writable_schema = on; + UPDATE sqlite_schema SET + sql = 'CREATE INDEX i1 ON t1(b, c, d)', + tbl_name = 't1', + type='index' + WHERE name='i1'; +} +db close +sqlite3 db test.db +do_catchsql_test 19.4 { + PRAGMA integrity_check; +} {1 {database disk image is malformed}} + +finish_test diff --git a/test/corruptM.test b/test/corruptM.test new file mode 100644 index 0000000..15fc8d6 --- /dev/null +++ b/test/corruptM.test @@ -0,0 +1,186 @@ +# 2019-08-12 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Check to ensure that the type, name, and tbl_name fields of the +# sqlite_master table are validated and errors are reported if they +# are inconsistent with the sql. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix corruptM + +# These tests deal with corrupt database files +# +database_may_be_corrupt + +proc open_db2_and_catchsql {sql} { + set rc [catch { sqlite3 db2 test.db } msg] + if {$rc} { + return [list $rc $msg] + } + set res [catchsql $sql db2] + db2 close + set res +} + +db close +forcedelete test.db +sqlite3 db test.db +do_execsql_test corruptM-100 { + CREATE TABLE t1(a,b,c); + INSERT INTO t1 VALUES(111,222,333); + CREATE INDEX i1 ON t1(b); + CREATE VIEW v2 AS SELECT 15,22; + CREATE TRIGGER r1 AFTER INSERT ON t1 BEGIN SELECT 5; END; + SELECT type, name, tbl_name, '|' FROM sqlite_master; +} {table t1 t1 | index i1 t1 | view v2 v2 | trigger r1 t1 |} +do_execsql_test corruptM-101 { + PRAGMA writable_schema=on; + UPDATE sqlite_master SET tbl_name=NULL WHERE name='t1'; + SELECT type, name, tbl_name, '|' FROM sqlite_master; +} {table t1 {} | index i1 t1 | view v2 v2 | trigger r1 t1 |} +do_test corruptM-102 { + open_db2_and_catchsql { + PRAGMA quick_check; + } +} {1 {malformed database schema (t1)}} + +do_execsql_test corruptM-110 { + UPDATE sqlite_master SET tbl_name='tx' WHERE name='t1'; + SELECT type, name, tbl_name, '|' FROM sqlite_master; +} {table t1 tx | index i1 t1 | view v2 v2 | trigger r1 t1 |} +do_test corruptM-111 { + open_db2_and_catchsql { + PRAGMA quick_check; + } +} {1 {malformed database schema (t1)}} +do_execsql_test corruptM-112 { + UPDATE sqlite_master SET tbl_name='t1', type='tabl' WHERE name='t1'; + SELECT type, name, tbl_name, '|' FROM sqlite_master; +} {tabl t1 t1 | index i1 t1 | view v2 v2 | trigger r1 t1 |} +do_test corruptM-113 { + open_db2_and_catchsql { + PRAGMA quick_check; + } +} {1 {malformed database schema (t1)}} +do_execsql_test corruptM-114 { + UPDATE sqlite_master SET tbl_name='t9',type='table',name='t9'WHERE name='t1'; + SELECT type, name, tbl_name, '|' FROM sqlite_master; +} {table t9 t9 | index i1 t1 | view v2 v2 | trigger r1 t1 |} +do_test corruptM-114 { + open_db2_and_catchsql { + PRAGMA quick_check; + } +} {1 {malformed database schema (t9)}} + +do_execsql_test corruptM-120 { + UPDATE sqlite_master SET name='t1',tbl_name='T1' WHERE name='t9'; + SELECT type, name, tbl_name, '|' FROM sqlite_master; +} {table t1 T1 | index i1 t1 | view v2 v2 | trigger r1 t1 |} +do_test corruptM-121 { + open_db2_and_catchsql { + PRAGMA quick_check; + SELECT * FROM t1, v2; + } +} {0 {ok 111 222 333 15 22}} + +do_execsql_test corruptM-130 { + UPDATE sqlite_master SET type='view' WHERE name='t1'; + SELECT type, name, tbl_name, '|' FROM sqlite_master; +} {view t1 T1 | index i1 t1 | view v2 v2 | trigger r1 t1 |} +do_test corruptM-131 { + open_db2_and_catchsql { + PRAGMA quick_check; + SELECT * FROM t1, v2; + } +} {1 {malformed database schema (t1)}} + +do_execsql_test corruptM-140 { + UPDATE sqlite_master SET type='table', tbl_name='t1' WHERE name='t1'; + UPDATE sqlite_master SET tbl_name='tx' WHERE name='i1'; + SELECT type, name, tbl_name, '|' FROM sqlite_master; +} {table t1 t1 | index i1 tx | view v2 v2 | trigger r1 t1 |} +do_test corruptM-141 { + open_db2_and_catchsql { + PRAGMA quick_check; + SELECT * FROM t1, v2; + } +} {1 {malformed database schema (i1)}} + +do_execsql_test corruptM-150 { + UPDATE sqlite_master SET type='table', tbl_name='t1' WHERE name='i1'; + SELECT type, name, tbl_name, '|' FROM sqlite_master; +} {table t1 t1 | table i1 t1 | view v2 v2 | trigger r1 t1 |} +do_test corruptM-151 { + open_db2_and_catchsql { + PRAGMA quick_check; + SELECT * FROM t1, v2; + } +} {1 {malformed database schema (i1)}} + +do_execsql_test corruptM-160 { + UPDATE sqlite_master SET type='view', tbl_name='t1' WHERE name='i1'; + SELECT type, name, tbl_name, '|' FROM sqlite_master; +} {table t1 t1 | view i1 t1 | view v2 v2 | trigger r1 t1 |} +do_test corruptM-161 { + open_db2_and_catchsql { + PRAGMA quick_check; + SELECT * FROM t1, v2; + } +} {1 {malformed database schema (i1)}} + +do_execsql_test corruptM-170 { + UPDATE sqlite_master SET type='index', tbl_name='t1' WHERE name='i1'; + UPDATE sqlite_master SET type='table', tbl_name='v2' WHERE name='v2'; + SELECT type, name, tbl_name, '|' FROM sqlite_master; +} {table t1 t1 | index i1 t1 | table v2 v2 | trigger r1 t1 |} +do_test corruptM-171 { + open_db2_and_catchsql { + PRAGMA quick_check; + SELECT * FROM t1, v2; + } +} {1 {malformed database schema (v2)}} + +do_execsql_test corruptM-180 { + UPDATE sqlite_master SET type='view',name='v3',tbl_name='v3' WHERE name='v2'; + SELECT type, name, tbl_name, '|' FROM sqlite_master; +} {table t1 t1 | index i1 t1 | view v3 v3 | trigger r1 t1 |} +do_test corruptM-181 { + open_db2_and_catchsql { + PRAGMA quick_check; + SELECT * FROM t1, v2; + } +} {1 {malformed database schema (v3)}} + +do_execsql_test corruptM-190 { + UPDATE sqlite_master SET type='view',name='v2',tbl_name='v2' WHERE name='v3'; + UPDATE sqlite_master SET type='view' WHERE name='r1'; + SELECT type, name, tbl_name, '|' FROM sqlite_master; +} {table t1 t1 | index i1 t1 | view v2 v2 | view r1 t1 |} +do_test corruptM-191 { + open_db2_and_catchsql { + PRAGMA quick_check; + SELECT * FROM t1, v2; + } +} {1 {malformed database schema (r1)}} +do_execsql_test corruptM-192 { + UPDATE sqlite_master SET type='trigger',tbl_name='v2' WHERE name='r1'; + SELECT type, name, tbl_name, '|' FROM sqlite_master; +} {table t1 t1 | index i1 t1 | view v2 v2 | trigger r1 v2 |} +do_test corruptM-193 { + open_db2_and_catchsql { + PRAGMA quick_check; + SELECT * FROM t1, v2; + } +} {1 {malformed database schema (r1)}} + +finish_test diff --git a/test/corruptN.test b/test/corruptN.test new file mode 100644 index 0000000..376325f --- /dev/null +++ b/test/corruptN.test @@ -0,0 +1,279 @@ +# 2020-12-16 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix corruptN + +# These tests deal with corrupt database files +# +database_may_be_corrupt + +reset_db +do_test 1.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +.open --hexdb +| size 4096 pagesize 512 filename sql024239.txt.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 02 00 01 01 00 40 20 20 00 00 00 0c 00 00 00 07 .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 04 ................ +| 48: 00 00 00 00 89 00 00 04 00 10 00 01 0a 00 00 01 ................ +| 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0c ................ +| 96: 00 2e 2c 50 0d 00 00 00 06 01 06 00 01 da 01 b0 ..,P............ +| 112: 01 56 01 86 01 2a 01 06 00 00 00 00 00 00 00 00 .V...*.......... +| 256: 00 00 00 00 00 00 22 07 06 17 11 11 01 31 74 61 .............1ta +| 272: 62 6c 65 74 34 74 34 07 43 52 45 41 54 45 20 54 blet4t4.CREATE T +| 288: 41 42 4c 45 20 74 34 28 78 29 2a 06 06 17 13 11 ABLE t4(x)*..... +| 304: 01 3f 69 6e 64 65 78 74 33 78 74 33 05 43 52 45 .?indext3xt3.CRE +| 320: 41 54 45 20 49 4e 44 45 58 20 74 33 78 20 4f 4e ATE INDEX t3x ON +| 336: 20 74 33 28 78 29 2e 04 06 17 15 11 01 45 69 6e t3(x).......Ein +| 352: 64 65 78 74 32 63 64 74 32 05 43 52 45 41 54 45 dext2cdt2.CREATE +| 368: 20 49 4e 44 45 58 20 74 32 63 64 20 4f 4e 20 74 INDEX t2cd ON t +| 384: 32 28 63 2c 64 29 28 05 06 17 11 11 01 3d 74 61 2(c,d)(......=ta +| 400: 62 6c 65 74 33 74 33 07 43 52 45 41 54 45 20 54 blet3t3.CREATE T +| 416: 41 42 4c 45 20 74 33 28 63 2c 78 2c 65 2c 66 29 ABLE t3(c,x,e,f) +| 432: 28 02 06 17 11 11 01 3d 74 61 62 6c 65 74 32 74 (......=tablet2t +| 448: 32 03 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 2.CREATE TABLE t +| 464: 32 28 63 2c 64 2c 65 2c 66 29 24 01 06 17 11 11 2(c,d,e,f)$..... +| 480: 01 35 74 61 62 6c 65 74 31 74 31 02 43 52 45 41 .5tablet1t1.CREA +| 496: 54 45 20 54 41 42 4c 45 20 74 31 28 61 2c 62 29 TE TABLE t1(a,b) +| page 2 offset 512 +| 0: 0d 00 00 00 04 01 41 00 01 fa 01 f3 01 de 01 cf ......A......... +| 160: 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 .. ............. +| 448: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0d ................ +| 464: 04 03 17 17 73 65 76 65 6e 65 69 67 68 74 13 03 ....seveneight.. +| 480: 03 07 07 40 14 00 00 00 00 00 00 40 18 00 00 00 ...@.......@.... +| 496: 00 00 00 05 02 03 01 01 03 04 04 01 03 09 01 02 ................ +| page 3 offset 1024 +| 0: 0d 00 00 00 08 01 54 00 01 f7 01 ec 01 c5 01 aa ......T......... +| 16: 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 112: 00 00 dd 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 336: 00 00 00 00 19 08 05 17 17 17 17 65 69 67 68 74 ...........eight +| 352: 65 69 67 68 74 73 65 76 65 6e 73 65 76 65 6e 25 eightsevenseven% +| 368: 07 05 07 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 432: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 ................ +| 480: 00 00 0f 04 17 17 01 65 69 67 68 74 65 69 67 68 .......eighteigh +| 496: 74 08 15 04 07 07 01 40 18 00 00 00 00 00 00 40 t......@.......@ +| page 4 offset 1536 +| 0: 18 00 00 00 00 00 00 07 07 04 01 01 01 04 04 06 ................ +| 16: 07 04 01 01 01 02 02 05 0f 04 17 17 01 73 6d 76 .............smv +| 32: 65 6e 65 69 67 68 74 04 15 04 07 07 01 40 14 00 eneight......@.. +| page 5 offset 2048 +| 0: 0a 00 00 00 08 01 96 00 01 fa 01 c4 01 f2 01 bc ................ +| 16: 01 dc 01 e1 01 96 01 cc 00 00 00 00 00 00 00 00 ................ +| 160: 00 00 00 00 00 00 32 00 00 00 00 00 00 00 00 00 ......2......... +| 368: 00 00 00 08 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 400: 00 00 00 00 00 00 0f 04 17 17 01 85 69 67 68 74 ............ight +| 416: 65 69 67 68 74 08 15 04 07 07 01 40 18 00 00 00 eight......@.... +| 432: 00 00 00 40 18 00 00 00 00 00 00 07 07 04 01 01 ...@............ +| 448: 01 04 04 06 07 04 01 01 01 02 02 05 0f 04 17 17 ................ +| 464: 01 73 6d 76 65 6e 65 69 67 68 74 04 15 04 07 07 .smveneight..... +| 480: 01 40 14 00 00 00 00 00 00 40 18 00 00 00 00 00 .@.......@...... +| 496: 00 03 07 04 01 01 01 03 04 02 05 04 03 01 09 02 ................ +| page 6 offset 2560 +| 0: 0a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 16: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10 00 ................ +| 304: 00 00 00 26 00 00 00 00 00 00 00 00 00 00 00 00 ...&............ +| page 7 offset 3072 +| 0: 0d 00 00 00 08 01 c2 00 01 fb 01 f6 01 f1 01 ec ................ +| 16: 01 e0 01 d4 01 cb 01 c2 00 00 00 00 00 00 00 00 ................ +| 128: 00 00 00 00 00 00 00 00 00 00 00 00 00 20 00 04 ............. .. +| 384: 00 00 00 00 00 00 00 00 00 07 08 02 17 65 69 fc .............ei. +| 400: 68 74 07 07 02 17 65 69 67 68 74 0a fb fd f8 bf ht....eight..... +| 416: e7 ff ff ff 00 00 00 0a 05 02 07 40 18 00 00 00 ...........@.... +| 432: 00 00 00 03 04 02 01 04 03 03 02 01 04 03 02 01 ................ +| 448: ff ff ff ff ff ff 00 00 00 00 00 00 00 00 00 00 ................ +| end sql024239.txt.db +}]} {} + +do_catchsql_test 1.1 { + VACUUM; +} {1 {database disk image is malformed}} + +# 2021-04-05 dbsqlfuzz b92b72e4de80b5140c30ab71372ca719b8feb618 +do_test 2.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 16384 pagesize 4096 filename c-b92b.txt.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 04 .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ +| 96: 00 00 00 00 0d 0f f8 00 04 0f 12 00 0f 91 0f d3 ................ +| 112: 0f 67 0f 12 00 00 00 00 00 00 00 00 00 00 00 00 .g.............. +| 3856: 00 00 53 04 07 1b 13 11 08 81 0d 74 72 69 67 67 ..S........trigg +| 3872: 65 72 74 72 30 74 31 43 52 45 41 54 45 20 54 52 ertr0t1CREATE TR +| 3888: 49 47 47 45 52 20 74 72 30 20 44 45 4c 45 54 45 IGGER tr0 DELETE +| 3904: 20 4f 4e 20 74 31 20 42 45 47 49 4e 0a 20 20 55 ON t1 BEGIN. U +| 3920: 50 44 41 54 45 20 74 31 20 53 45 54 20 62 20 3d PDATE t1 SET b = +| 3936: 20 61 3b 0a 45 4e 44 28 03 06 17 11 11 01 3d 69 a;.END(......=i +| 3952: 6e 64 65 78 69 30 74 31 04 43 52 45 41 54 45 20 ndexi0t1.CREATE +| 3968: 49 4e 44 45 58 20 69 30 20 4f 4e 20 74 31 28 62 INDEX i0 ON t1(b +| 3984: 29 40 01 06 17 11 11 01 6d 74 61 62 6c 65 74 31 )@......mtablet1 +| 4000: 74 31 02 43 52 45 41 54 45 20 54 41 42 4c 45 20 t1.CREATE TABLE +| 4016: 74 31 28 61 20 55 4e 49 51 55 45 20 4f 4e 20 43 t1(a UNIQUE ON C +| 4032: 4f 4e 46 4c 49 43 54 20 52 45 50 4c 41 43 45 2c ONFLICT REPLACE, +| 4048: 20 62 29 23 02 06 17 37 11 01 00 69 6e 64 65 78 b)#...7...index +| 4064: 73 71 6c 69 74 65 5f 61 75 74 6f 69 6e 64 65 78 sqlite_autoindex +| 4080: 5f 74 31 5f 31 74 31 03 00 00 00 08 00 00 00 00 _t1_1t1......... +| page 2 offset 4096 +| 0: 0d 00 00 00 02 0f 00 00 00 00 00 00 00 00 00 00 ................ +| 4080: 00 00 05 02 03 01 01 09 0d 05 01 03 01 01 04 0c ................ +| page 3 offset 8192 +| 0: 0a 00 00 00 02 0f f5 00 0f fb 0f f5 00 00 00 00 ................ +| 4080: 00 00 00 00 00 05 03 01 01 09 02 04 03 01 09 04 ................ +| page 4 offset 12288 +| 0: 0a 00 00 00 02 0f f5 00 0f fb 0f f5 00 00 00 00 ................ +| 4080: 00 00 00 00 00 05 03 01 01 0d 02 04 03 00 00 00 ................ +| end c-b92b.txt.db +}]} {} + +# This test only works with the legacy RC4 PRNG +if 0 { + prng_seed 0 db + do_catchsql_test 2.1 { + SELECT count(*) FROM sqlite_schema; + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<1000) + INSERT INTO t1(a) SELECT randomblob(null) FROM c; + } {1 {database disk image is malformed}} +} + +reset_db +if {![info exists ::G(perm:presql)]} { + do_execsql_test 3.0 { + CREATE TABLE t1(x INTEGER PRIMARY KEY AUTOINCREMENT, y); + PRAGMA writable_schema = 1; + UPDATE sqlite_schema + SET sql = 'CREATE TABLE sqlite_sequence(name-seq)' + WHERE name = 'sqlite_sequence'; + } + db close + sqlite3 db test.db + do_catchsql_test 3.1 { + PRAGMA writable_schema = 1; + INSERT INTO t1(y) VALUES('abc'); + } {1 {database disk image is malformed}} + reset_db + + do_execsql_test 4.1 { + CREATE TABLE x1(a INTEGER PRIMARY KEY, b UNIQUE, c UNIQUE); + INSERT INTO x1 VALUES(1, 1, 2); + INSERT INTO x1 VALUES(2, 2, 3); + INSERT INTO x1 VALUES(3, 3, 4); + INSERT INTO x1 VALUES(4, 5, 6); + PRAGMA writable_schema = 1; + + UPDATE sqlite_schema SET rootpage = ( + SELECT rootpage FROM sqlite_schema WHERE name = 'sqlite_autoindex_x1_2' + ) WHERE name = 'sqlite_autoindex_x1_1'; + } + + db close + sqlite3 db test.db + breakpoint + do_catchsql_test 4.2 { + PRAGMA writable_schema = 1; + REPLACE INTO x1 VALUES(5, 2, 3); + } {0 {}} + +} + +#------------------------------------------------------------------------- + +reset_db + +ifcapable json1&&vtab { + db func strreplace strreplace + proc strreplace {orig a b} { + string map [list $a $b] $orig + } + + do_execsql_test 5.0 { + CREATE TABLE t1(a, b); + CREATE INDEX t1a ON t1(a); + CREATE INDEX t1b ON t1(b); + + PRAGMA writable_schema = 1; + UPDATE sqlite_schema + SET sql = strreplace(sql, 't1', 'json_each') + WHERE type='index'; + } + + # Do not run this tests if there is any presql (SQL run from within + # the [sqlite3] command) configured. In this case the schema is parsed + # before the "PRAGMA writable_schema" command is executed and the + # script throws and exception. + if {[info exists ::G(perm:presql)]==0 || $::G(perm:presql)==""} { + db close + sqlite3 db test.db + + do_execsql_test 5.1 { + PRAGMA writable_schema = 1; + SELECT * FROM t1 + } + } +}; # ifcapable json1&&vtab + +#------------------------------------------------------------------------- +reset_db + +do_execsql_test 6.0 { + PRAGMA auto_vacuum = 0; + PRAGMA page_size=1024; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + INSERT INTO t1(b) VALUES(zeroblob(300)),(zeroblob(300)),(zeroblob(300)),(zeroblob(300)); + CREATE TABLE t2(a); + CREATE TRIGGER t1tr BEFORE UPDATE ON t1 BEGIN DELETE FROM t2; END; + PRAGMA writable_schema=ON; + UPDATE sqlite_schema SET rootpage=3 WHERE rowid=2; + PRAGMA writable_schema=RESET; + INSERT INTO t2 VALUES('active'),('boomer'),('atom'),('atomic'), + ('alpha channel backup abandon test aback boomer atom alpha active'); +} +do_catchsql_test 6.1 { + UPDATE t1 SET b=zeroblob(299); +} {1 {database disk image is malformed}} + +reset_db +do_execsql_test 6.2 { + -- Make "t1" a large table. Large enough that the children of the root + -- node are interior nodes. + PRAGMA page_size = 1024; + PRAGMA auto_vacuum = 0; + CREATE TABLE t1(x); + WITH s(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<500 + ) + INSERT INTO t1 SELECT zeroblob(300) FROM s; + + CREATE TABLE t2(y); + CREATE TRIGGER tr BEFORE UPDATE ON t1 BEGIN + DELETE FROM t2; + END; + + -- Set the root of table t2 to 137 - the leftmost child of the root of t1. + PRAGMA writable_schema = ON; + UPDATE sqlite_schema SET rootpage = 137 WHERE name='t2'; + PRAGMA writable_schema = RESET; +} + +do_catchsql_test 6.3 { + -- Run an UPDATE on t1 that will hit a child of page 136. Have the trigger + -- clear page 136 and its children. Assert fails. + UPDATE t1 SET x='hello world' WHERE rowid=1; +} {1 {database disk image is malformed}} + +finish_test diff --git a/test/cost.test b/test/cost.test new file mode 100644 index 0000000..5684177 --- /dev/null +++ b/test/cost.test @@ -0,0 +1,289 @@ +# 2014-04-26 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix cost + + +do_execsql_test 1.1 { + CREATE TABLE t3(id INTEGER PRIMARY KEY, b NOT NULL); + CREATE TABLE t4(c, d, e); + CREATE UNIQUE INDEX i3 ON t3(b); + CREATE UNIQUE INDEX i4 ON t4(c, d); +} +do_eqp_test 1.2 { + SELECT e FROM t3, t4 WHERE b=c ORDER BY b, d; +} { + QUERY PLAN + |--SCAN t3 USING COVERING INDEX i3 + `--SEARCH t4 USING INDEX i4 (c=?) +} + + +do_execsql_test 2.1 { + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a); +} + +# It is better to use an index for ORDER BY than sort externally, even +# if the index is a non-covering index. +do_eqp_test 2.2 { + SELECT * FROM t1 ORDER BY a; +} {SCAN t1 USING INDEX i1} + +do_execsql_test 3.1 { + CREATE TABLE t5(a INTEGER PRIMARY KEY,b,c,d,e,f,g); + CREATE INDEX t5b ON t5(b); + CREATE INDEX t5c ON t5(c); + CREATE INDEX t5d ON t5(d); + CREATE INDEX t5e ON t5(e); + CREATE INDEX t5f ON t5(f); + CREATE INDEX t5g ON t5(g); +} + +do_eqp_test 3.2 { + SELECT a FROM t5 + WHERE b IS NULL OR c IS NULL OR d IS NULL + ORDER BY a; +} { + QUERY PLAN + |--MULTI-INDEX OR + | |--INDEX 1 + | | `--SEARCH t5 USING INDEX t5b (b=?) + | |--INDEX 2 + | | `--SEARCH t5 USING INDEX t5c (c=?) + | `--INDEX 3 + | `--SEARCH t5 USING INDEX t5d (d=?) + `--USE TEMP B-TREE FOR ORDER BY +} + +#------------------------------------------------------------------------- +# If there is no likelihood() or stat3 data, SQLite assumes that a closed +# range scan (e.g. one constrained by "col BETWEEN ? AND ?" constraint) +# visits 1/64 of the rows in a table. +# +# Note: 1/63 =~ 0.016 +# Note: 1/65 =~ 0.015 +# +reset_db +do_execsql_test 4.1 { + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a); + CREATE INDEX i2 ON t1(b); +} +do_eqp_test 4.2 { + SELECT * FROM t1 WHERE likelihood(a=?, 0.014) AND b BETWEEN ? AND ?; +} {SEARCH t1 USING INDEX i1 (a=?)} + +do_eqp_test 4.3 { + SELECT * FROM t1 WHERE likelihood(a=?, 0.016) AND b BETWEEN ? AND ?; +} {SEARCH t1 USING INDEX i2 (b>? AND b? AND x? AND b=950 AND b<=1010) OR (b IS NULL AND c NOT NULL) + ORDER BY a +} { + QUERY PLAN + |--MULTI-INDEX OR + | |--INDEX 1 + | | `--SEARCH t1 USING INDEX t1b (b>? AND b=0} { + return 1; + } + return 0 +} + +do_test count-2.1 { + execsql { + CREATE TABLE t2(a, b); + } + uses_op_count {SELECT count(*) FROM t2} +} {1} +do_test count-2.2 { + catchsql {SELECT count(DISTINCT *) FROM t2} +} {1 {near "*": syntax error}} +do_test count-2.3 { + uses_op_count {SELECT count(DISTINCT a) FROM t2} +} {0} +do_test count-2.4 { + uses_op_count {SELECT count(a) FROM t2} +} {0} +do_test count-2.5 { + uses_op_count {SELECT count() FROM t2} +} {1} +do_test count-2.6 { + catchsql {SELECT count(DISTINCT) FROM t2} +} {1 {DISTINCT aggregates must have exactly one argument}} +do_test count-2.7 { + uses_op_count {SELECT count(*)+1 FROM t2} +} {0} +do_test count-2.8 { + uses_op_count {SELECT count(*) FROM t2 WHERE a IS NOT NULL} +} {0} +do_execsql_test count-2.9a { + SELECT count(*) FROM t2 HAVING count(*)>1; +} {} +do_execsql_test count-2.9b { + SELECT count(*) FROM t2 HAVING count(*)<10; +} {0} +do_test count-2.10 { + uses_op_count {SELECT count(*) FROM (SELECT 1)} +} {0} +do_test count-2.11 { + execsql { CREATE VIEW v1 AS SELECT 1 AS a } + uses_op_count {SELECT count(*) FROM v1} +} {0} +do_test count-2.12 { + uses_op_count {SELECT count(*), max(a) FROM t2} +} {0} +do_test count-2.13 { + uses_op_count {SELECT count(*) FROM t1, t2} +} {0} + +ifcapable vtab { + register_echo_module [sqlite3_connection_pointer db] + do_test count-2.14 { + execsql { CREATE VIRTUAL TABLE techo USING echo(t1); } + uses_op_count {SELECT count(*) FROM techo} + } {0} +} + +do_test count-3.1 { + execsql { + CREATE TABLE t3(a, b); + SELECT a FROM (SELECT count(*) AS a FROM t3) WHERE a==0; + } +} {0} +do_test count-3.2 { + execsql { + SELECT a FROM (SELECT count(*) AS a FROM t3) WHERE a==1; + } +} {} + +do_test count-4.1 { + execsql { + CREATE TABLE t4(a, b); + INSERT INTO t4 VALUES('a', 'b'); + CREATE INDEX t4i1 ON t4(b, a); + SELECT count(*) FROM t4; + } +} {1} +do_test count-4.2 { + execsql { + CREATE INDEX t4i2 ON t4(b); + SELECT count(*) FROM t4; + } +} {1} +do_test count-4.3 { + execsql { + DROP INDEX t4i1; + CREATE INDEX t4i1 ON t4(b, a); + SELECT count(*) FROM t4; + } +} {1} + +do_execsql_test count-5.1 { + CREATE TABLE t5(a TEXT PRIMARY KEY, b VARCHAR(50)) WITHOUT ROWID; + INSERT INTO t5 VALUES('bison','jazz'); + SELECT count(*) FROM t5; +} {1} + +do_catchsql_test count-6.1 { + CREATE TABLE t6(x); + SELECT count(DISTINCT) FROM t6 GROUP BY x; +} {1 {DISTINCT aggregates must have exactly one argument}} + +# 2020-05-08. +# The count() optimization should honor the NOT INDEXED clause +# +reset_db +do_execsql_test count-7.1 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b INT, c VARCHAR(1000)); + CREATE INDEX t1b ON t1(b); + INSERT INTO t1(a,b,c) values(1,2,'count.test cases for NOT INDEXED'); + ANALYZE; + UPDATE sqlite_stat1 SET stat='1000000 10' WHERE idx='t1b'; + ANALYZE sqlite_master; +} +do_eqp_test count-7.2 { + SELECT count(1) FROM t1; +} { + QUERY PLAN + `--SCAN t1 USING COVERING INDEX t1b +} +do_eqp_test count-7.3 { + SELECT count(1) FROM t1 NOT INDEXED +} { + QUERY PLAN + `--SCAN t1 +} +do_eqp_test count-7.3 { + SELECT count(*) FROM t1; +} { + QUERY PLAN + `--SCAN t1 USING COVERING INDEX t1b +} +do_eqp_test count-7.4 { + SELECT count(*) FROM t1 NOT INDEXED +} { + QUERY PLAN + `--SCAN t1 +} + +do_execsql_test count-8.0 { + CREATE TABLE t7(a INT,b TEXT,c BLOB,d REAL); + CREATE TABLE t8(a INT,b TEXT,c BLOB,d REAL); + CREATE INDEX t8a ON t8(a); +} +do_catchsql_test count-8.1 { + SELECT * FROM t8 WHERE (a, b) IN ( + SELECT count(t8.b), count(*) FROM t7 AS ra0 ORDER BY count(*) + ) AND t8.b=0; +} {1 {misuse of aggregate: count()}} + + +finish_test diff --git a/test/countofview.test b/test/countofview.test new file mode 100644 index 0000000..cea6fa4 --- /dev/null +++ b/test/countofview.test @@ -0,0 +1,107 @@ +# 2018-08-04 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/malloc_common.tcl +set testprefix countofview + +do_execsql_test 1.0 { + CREATE TABLE t2(c); + CREATE TABLE t3(f); + + INSERT INTO t2 VALUES(1), (2); + INSERT INTO t3 VALUES(3); +} + +do_execsql_test 1.1 { + select c from t2 union all select f from t3 limit 1 offset 1 +} {2} + +do_execsql_test 1.2 { + select count(*) from ( + select c from t2 union all select f from t3 limit 1 offset 1 + ) +} {1} + +do_execsql_test 1.3 { + select count(*) from ( + select c from t2 union all select f from t3 + ) +} {3} + +# 2019-05-15 +do_execsql_test 2.0 { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(1),(99),('abc'); + CREATE VIEW v1(x,y) AS SELECT x,1 FROM t1 UNION ALL SELECT x,2 FROM t1; + SELECT count(*) FROM v1 WHERE x<>1; +} {4} +do_execsql_test 2.1 { + SELECT count(*) FROM v1 GROUP BY y; +} {3 3} + +# 2023-03-01 dbsqlfuzz ef8623915d843b150c159166ee4548c78cc6895a +# count-of-view should not apply to CTEs. +# +ifcapable progress { + proc progress_stop args {return 1} + db progress 1000 progress_stop + do_catchsql_test 3.1 { + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c) + SELECT count(*) FROM c; + } {1 interrupted} +} + +# 2023-03-07 dbsqlfuzz 23d782160b71c3f8f535ccb2da313dfc8eb8c631 +# +do_execsql_test 4.1 { + DROP TABLE t1; + DROP TABLE t2; + DROP TABLE t3; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT); + INSERT INTO t1 VALUES(4,'four'); + CREATE TABLE t2(c INTEGER PRIMARY KEY, d TEXT); + CREATE VIEW t3 AS SELECT a, b FROM t1 UNION ALL SELECT c, d FROM t2; + SELECT count(*) FROM t3 ORDER BY sum(a); +} 1 + +# 2023-03-31 dbsqlfuzz 6a107e3055bd22afab31cfddabc2d9d54fcbaf69 +# Having clauses should disqualify count-of-view +# +reset_db +do_execsql_test 5.1 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT); + INSERT INTO t1 VALUES(1,'one'),(4,'four'); + CREATE TABLE t2(c INTEGER PRIMARY KEY, d TEXT); + INSERT INTO t2 VALUES(2,'two'),(5,'five'); + CREATE VIEW t3 AS SELECT a, b FROM t1 UNION ALL SELECT c, d FROM t2; + SELECT count(*) FROM t3 HAVING count(*)>0; +} 4 +do_execsql_test 5.2 { + SELECT count(*) FROM t3 HAVING count(*)>5; +} {} +do_execsql_test 5.3 { + SELECT count(*) FROM t3 HAVING max(b)>'mmm'; +} 4 +do_execsql_test 5.4 { + SELECT count(*) FROM t3 HAVING min(b)>'mmm'; +} {} +do_execsql_test 5.5 { + SELECT count(*) FROM ( + SELECT a, max(b) FROM t1 HAVING a<100 UNION ALL SELECT c, d FROM t2 + ) +} 3 + + +finish_test diff --git a/test/coveridxscan.test b/test/coveridxscan.test new file mode 100644 index 0000000..c87227c --- /dev/null +++ b/test/coveridxscan.test @@ -0,0 +1,119 @@ +# 2012 September 17 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Tests for the optimization which attempts to use a covering index +# for a full-table scan (under the theory that the index will be smaller +# and require less I/O and hence will run faster.) +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +set testprefix coveridxscan + +do_test 1.1 { + db eval { + CREATE TABLE t1(a,b,c); + INSERT INTO t1 VALUES(5,4,3), (4,8,2), (3,2,1); + CREATE INDEX t1ab ON t1(a,b); + CREATE INDEX t1b ON t1(b); + SELECT a FROM t1; + } + # covering index used for the scan, hence values are increasing +} {3 4 5} + +do_test 1.2 { + db eval { + SELECT a, c FROM t1; + } + # There is no covering index, hence the values are in rowid order +} {5 3 4 2 3 1} + +do_test 1.3 { + db eval { + SELECT b FROM t1; + } + # Choice of two indices: use the one with fewest columns +} {2 4 8} + +do_test 2.1 { + optimization_control db cover-idx-scan 0 + db eval {SELECT a FROM t1} + # With the optimization turned off, output in rowid order +} {5 4 3} +do_test 2.2 { + db eval {SELECT a, c FROM t1} +} {5 3 4 2 3 1} +do_test 2.3 { + db eval {SELECT b FROM t1} +} {4 8 2} + +db close +sqlite3_shutdown +sqlite3_config_cis 0 +sqlite3 db test.db + +do_test 3.1 { + db eval {SELECT a FROM t1} + # With the optimization configured off, output in rowid order +} {5 4 3} +do_test 3.2 { + db eval {SELECT a, c FROM t1} +} {5 3 4 2 3 1} +do_test 3.3 { + db eval {SELECT b FROM t1} +} {4 8 2} + +db close +sqlite3_shutdown +sqlite3_config_cis 1 +sqlite3 db test.db + +# The CIS optimization is enabled again. Covering indices are once again +# used for all table scans. +do_test 4.1 { + db eval {SELECT a FROM t1} +} {3 4 5} +do_test 4.2 { + db eval {SELECT a, c FROM t1} +} {5 3 4 2 3 1} +do_test 4.3 { + db eval {SELECT b FROM t1} +} {2 4 8} + +#------------------------------------------------------------------------- +# Test that indexes with large numbers of columns can be correctly +# identified as covering indexes. +reset_db +set L [list] +for {set i 1} {$i<120} {incr i} { + lappend L "c$i" +} +set cols [join $L ,] + +do_execsql_test 5.1.0 " + CREATE TABLE t1(a, b, c, $cols, PRIMARY KEY(a, b, c)) WITHOUT ROWID; + CREATE INDEX i1 ON t1($cols); + + CREATE TABLE t2(i INTEGER PRIMARY KEY, $cols); + CREATE INDEX i2 ON t2($cols); +" + +do_eqp_test 5.1.1 { + SELECT * FROM t1 ORDER BY c1, c2; +} {SCAN t1 USING COVERING INDEX i1} + +do_eqp_test 5.1.2 { + SELECT * FROM t2 ORDER BY c1, c2; +} {SCAN t2 USING COVERING INDEX i2} + + +finish_test diff --git a/test/crash.test b/test/crash.test new file mode 100644 index 0000000..c1901da --- /dev/null +++ b/test/crash.test @@ -0,0 +1,411 @@ +# 2001 September 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# The focus of this file is testing the ability of the database to +# uses its rollback journal to recover intact (no database corruption) +# from a power failure during the middle of a COMMIT. The OS interface +# modules are overloaded using the modified I/O routines found in test6.c. +# These routines allow us to simulate the kind of file damage that +# occurs after a power failure. +# +# $Id: crash.test,v 1.27 2008/01/08 15:18:52 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !crashtest { + finish_test + return +} + +set repeats 100 +#set repeats 10 + +# The following procedure computes a "signature" for table "abc". If +# abc changes in any way, the signature should change. +proc signature {} { + return [db eval {SELECT count(*), md5sum(a), md5sum(b), md5sum(c) FROM abc}] +} +proc signature2 {} { + return [db eval {SELECT count(*), md5sum(a), md5sum(b), md5sum(c) FROM abc2}] +} + +#-------------------------------------------------------------------------- +# Simple crash test: +# +# crash-1.1: Create a database with a table with two rows. +# crash-1.2: Run a 'DELETE FROM abc WHERE a = 1' that crashes during +# the first journal-sync. +# crash-1.3: Ensure the database is in the same state as after crash-1.1. +# crash-1.4: Run a 'DELETE FROM abc WHERE a = 1' that crashes during +# the first database-sync. +# crash-1.5: Ensure the database is in the same state as after crash-1.1. +# crash-1.6: Run a 'DELETE FROM abc WHERE a = 1' that crashes during +# the second journal-sync. +# crash-1.7: Ensure the database is in the same state as after crash-1.1. +# +# Tests 1.8 through 1.11 test for crashes on the third journal sync and +# second database sync. Neither of these is required in such a small test +# case, so these tests are just to verify that the test infrastructure +# operates as expected. +# +do_test crash-1.1 { + execsql { + CREATE TABLE abc(a, b, c); + INSERT INTO abc VALUES(1, 2, 3); + INSERT INTO abc VALUES(4, 5, 6); + } + set ::sig [signature] + expr 0 +} {0} +for {set i 0} {$i<10} {incr i} { + set seed [expr {int(abs(rand()*10000))}] + do_test crash-1.2.$i { + crashsql -delay 1 -file test.db-journal -seed $seed { + DELETE FROM abc WHERE a = 1; + } + } {1 {child process exited abnormally}} + do_test crash-1.3.$i { + signature + } $::sig +} +do_test crash-1.4 { + crashsql -delay 1 -file test.db { + DELETE FROM abc WHERE a = 1; + } +} {1 {child process exited abnormally}} +do_test crash-1.5 { + signature +} $::sig +do_test crash-1.6 { + crashsql -delay 2 -file test.db-journal { + DELETE FROM abc WHERE a = 1; + } +} {1 {child process exited abnormally}} +do_test crash-1.7 { + catchsql { + SELECT * FROM abc; + } +} {0 {1 2 3 4 5 6}} + +do_test crash-1.8 { + crashsql -delay 3 -file test.db-journal { + DELETE FROM abc WHERE a = 1; + } +} {0 {}} +do_test crash-1.9 { + catchsql { + SELECT * FROM abc; + } +} {0 {4 5 6}} +do_test crash-1.10 { + crashsql -delay 2 -file test.db { + DELETE FROM abc WHERE a = 4; + } +} {0 {}} +do_test crash-1.11 { + catchsql { + SELECT * FROM abc; + } +} {0 {}} + +#-------------------------------------------------------------------------- +# The following tests test recovery when both the database file and the +# journal file contain corrupt data. This can happen after pages are +# written to the database file before a transaction is committed due to +# cache-pressure. +# +# crash-2.1: Insert 18 pages of data into the database. +# crash-2.2: Check the database file size looks ok. +# crash-2.3: Delete 15 or so pages (with a 10 page page-cache), then crash. +# crash-2.4: Ensure the database is in the same state as after crash-2.1. +# +# Test cases crash-2.5 and crash-2.6 check that the database is OK if the +# crash occurs during the main database file sync. But this isn't really +# different from the crash-1.* cases. +# +do_test crash-2.1 { + execsql { BEGIN } + for {set n 0} {$n < 1000} {incr n} { + execsql "INSERT INTO abc VALUES($n, [expr 2*$n], [expr 3*$n])" + } + execsql { COMMIT } + set ::sig [signature] + execsql { SELECT sum(a), sum(b), sum(c) from abc } +} {499500 999000 1498500} +do_test crash-2.2 { + expr ([file size test.db] / 1024)>16 +} {1} +do_test crash-2.3 { + crashsql -delay 2 -file test.db-journal { + DELETE FROM abc WHERE a < 800; + } +} {1 {child process exited abnormally}} +do_test crash-2.4 { + signature +} $sig +do_test crash-2.5 { + crashsql -delay 1 -file test.db { + DELETE FROM abc WHERE a<800; + } +} {1 {child process exited abnormally}} +do_test crash-2.6 { + signature +} $sig + +#-------------------------------------------------------------------------- +# The crash-3.* test cases are essentially the same test as test case +# crash-2.*, but with a more complicated data set. +# +# The test is repeated a few times with different seeds for the random +# number generator in the crashing executable. Because there is no way to +# seed the random number generator directly, some SQL is added to the test +# case to 'use up' a different quantity random numbers before the test SQL +# is executed. +# + +# Make sure the file is much bigger than the pager-cache (10 pages). This +# ensures that cache-spills happen regularly. +do_test crash-3.0 { + execsql { + INSERT INTO abc SELECT * FROM abc; + INSERT INTO abc SELECT * FROM abc; + INSERT INTO abc SELECT * FROM abc; + INSERT INTO abc SELECT * FROM abc; + INSERT INTO abc SELECT * FROM abc; + } + expr ([file size test.db] / 1024) > 450 +} {1} +for {set i 1} {$i < $repeats} {incr i} { + set sig [signature] + do_test crash-3.$i.1 { + set seed [expr {int(abs(rand()*10000))}] + crashsql -delay [expr $i%5 + 1] -file test.db-journal -seed $seed " + BEGIN; + SELECT random() FROM abc LIMIT $i; + INSERT INTO abc VALUES(randstr(10,10), 0, 0); + DELETE FROM abc WHERE random()%10!=0; + COMMIT; + " + } {1 {child process exited abnormally}} + do_test crash-3.$i.2 { + signature + } $sig +} + +#-------------------------------------------------------------------------- +# The following test cases - crash-4.* - test the correct recovery of the +# database when a crash occurs during a multi-file transaction. +# +# crash-4.1.*: Test recovery when crash occurs during sync() of the +# main database journal file. +# crash-4.2.*: Test recovery when crash occurs during sync() of an +# attached database journal file. +# crash-4.3.*: Test recovery when crash occurs during sync() of the master +# journal file. +# +ifcapable attach { + do_test crash-4.0 { + forcedelete test2.db + forcedelete test2.db-journal + execsql { + ATTACH 'test2.db' AS aux; + PRAGMA aux.default_cache_size = 10; + CREATE TABLE aux.abc2 AS SELECT 2*a as a, 2*b as b, 2*c as c FROM abc; + } + expr ([file size test2.db] / 1024) > 450 + } {1} + + set fin 0 + for {set i 1} {$i<$repeats} {incr i} { + set seed [expr {int(abs(rand()*10000))}] + set sig [signature] + set sig2 [signature2] + do_test crash-4.1.$i.1 { + set c [crashsql -delay $i -file test.db-journal -seed $::seed " + ATTACH 'test2.db' AS aux; + BEGIN; + SELECT randstr($i,$i) FROM abc LIMIT $i; + INSERT INTO abc VALUES(randstr(10,10), 0, 0); + DELETE FROM abc WHERE random()%10!=0; + INSERT INTO abc2 VALUES(randstr(10,10), 0, 0); + DELETE FROM abc2 WHERE random()%10!=0; + COMMIT; + "] + if { $c == {0 {}} } { + set ::fin 1 + set c {1 {child process exited abnormally}} + } + set c + } {1 {child process exited abnormally}} + if {$::fin} break + do_test crash-4.1.$i.2 { + signature + } $sig + do_test crash-4.1.$i.3 { + signature2 + } $sig2 + } + set i 0 + set fin 0 + while {[incr i]} { + set seed [expr {int(abs(rand()*10000))}] + set sig [signature] + set sig2 [signature2] + set ::fin 0 + do_test crash-4.2.$i.1 { + set c [crashsql -delay $i -file test2.db-journal -seed $::seed " + ATTACH 'test2.db' AS aux; + BEGIN; + SELECT randstr($i,$i) FROM abc LIMIT $i; + INSERT INTO abc VALUES(randstr(10,10), 0, 0); + DELETE FROM abc WHERE random()%10!=0; + INSERT INTO abc2 VALUES(randstr(10,10), 0, 0); + DELETE FROM abc2 WHERE random()%10!=0; + COMMIT; + "] + if { $c == {0 {}} } { + set ::fin 1 + set c {1 {child process exited abnormally}} + } + set c + } {1 {child process exited abnormally}} + if { $::fin } break + do_test crash-4.2.$i.2 { + signature + } $sig + do_test crash-4.2.$i.3 { + signature2 + } $sig2 + } + for {set i 1} {$i < 5} {incr i} { + set sig [signature] + set sig2 [signature2] + do_test crash-4.3.$i.1 { + crashsql -delay 1 -file test.db-mj* " + ATTACH 'test2.db' AS aux; + BEGIN; + SELECT random() FROM abc LIMIT $i; + INSERT INTO abc VALUES(randstr(10,10), 0, 0); + DELETE FROM abc WHERE random()%10!=0; + INSERT INTO abc2 VALUES(randstr(10,10), 0, 0); + DELETE FROM abc2 WHERE random()%10!=0; + COMMIT; + " + } {1 {child process exited abnormally}} + do_test crash-4.3.$i.2 { + signature + } $sig + do_test crash-4.3.$i.3 { + signature2 + } $sig2 + } +} + +#-------------------------------------------------------------------------- +# The following test cases - crash-5.* - exposes a bug that existed in the +# sqlite3pager_movepage() API used by auto-vacuum databases. +# database when a crash occurs during a multi-file transaction. See comments +# in test crash-5.3 for details. +# +db close +forcedelete test.db +sqlite3 db test.db +do_test crash-5.1 { + execsql { + CREATE TABLE abc(a, b, c); -- Root page 3 + INSERT INTO abc VALUES(randstr(1500,1500), 0, 0); -- Overflow page 4 + INSERT INTO abc SELECT * FROM abc; + INSERT INTO abc SELECT * FROM abc; + INSERT INTO abc SELECT * FROM abc; + } +} {} +do_test crash-5.2 { + expr [file size test.db] / 1024 +} [expr [string match [execsql {pragma auto_vacuum}] 1] ? 11 : 10] +set sig [signature] +do_test crash-5.3 { +# The SQL below is used to expose a bug that existed in +# sqlite3pager_movepage() during development of the auto-vacuum feature. It +# functions as follows: +# +# 1: Begin a transaction. +# 2: Put page 4 on the free-list (was the overflow page for the row deleted). +# 3: Write data to page 4 (it becomes the overflow page for the row inserted). +# The old page 4 data has been written to the journal file, but the +# journal file has not been sync()hronized. +# 4: Create a table, which calls sqlite3pager_movepage() to move page 4 +# to the end of the database (page 12) to make room for the new root-page. +# 5: Put pressure on the pager-cache. This results in page 4 being written +# to the database file to make space in the cache to load a new page. The +# bug was that page 4 was written to the database file before the journal +# is sync()hronized. +# 6: Commit. A crash occurs during the sync of the journal file. +# +# End result: Before the bug was fixed, data has been written to page 4 of the +# database file and the journal file does not contain trustworthy rollback +# data for this page. +# + crashsql -delay 1 -file test.db-journal { + BEGIN; -- 1 + DELETE FROM abc WHERE oid = 1; -- 2 + INSERT INTO abc VALUES(randstr(1500,1500), 0, 0); -- 3 + CREATE TABLE abc2(a, b, c); -- 4 + SELECT * FROM abc; -- 5 + COMMIT; -- 6 + } +} {1 {child process exited abnormally}} +integrity_check crash-5.4 +do_test crash-5.5 { + signature +} $sig + +#-------------------------------------------------------------------------- +# The following test cases - crash-6.* - test that a DROP TABLE operation +# is correctly rolled back in the event of a crash while the database file +# is being written. This is mainly to test that all pages are written to the +# journal file before truncation in an auto-vacuum database. +# +do_test crash-6.1 { + crashsql -delay 1 -file test.db { + DROP TABLE abc; + } +} {1 {child process exited abnormally}} +do_test crash-6.2 { + signature +} $sig + +#-------------------------------------------------------------------------- +# These test cases test the case where the master journal file name is +# corrupted slightly so that the corruption has to be detected by the +# checksum. +do_test crash-7.1 { + crashsql -delay 1 -file test.db { + ATTACH 'test2.db' AS aux; + BEGIN; + INSERT INTO abc VALUES(randstr(1500,1500), 0, 0); + INSERT INTO abc2 VALUES(randstr(1500,1500), 0, 0); + COMMIT; + } + + # Change the checksum value for the master journal name. + set f [open test.db-journal a] + fconfigure $f -encoding binary + seek $f [expr [file size test.db-journal] - 12] + puts -nonewline $f "\00\00\00\00" + close $f +} {} +do_test crash-7.2 { + signature +} $sig + +finish_test diff --git a/test/crash2.test b/test/crash2.test new file mode 100644 index 0000000..c74f6c2 --- /dev/null +++ b/test/crash2.test @@ -0,0 +1,133 @@ +# 2001 September 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# The focus of this file is testing the ability of the database to +# uses its rollback journal to recover intact (no database corruption) +# from a power failure during the middle of a COMMIT. Even more +# specifically, the tests in this file verify this functionality +# for storage mediums with various sector sizes. +# +# $Id: crash2.test,v 1.6 2008/08/25 07:12:29 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !crashtest { + finish_test + return +} + +db close + +# This test is designed to check that the crash-test infrastructure +# can create files that do not consist of an integer number of +# simulated disk blocks (i.e. 3KB file using 2KB disk blocks). +# +do_test crash2-1.1 { + crashsql -delay 500 -file test.db -blocksize 2048 { + PRAGMA auto_vacuum=OFF; + PRAGMA page_size=1024; + BEGIN; + CREATE TABLE abc AS SELECT 1 AS a, 2 AS b, 3 AS c; + CREATE TABLE def AS SELECT 1 AS d, 2 AS e, 3 AS f; + COMMIT; + } + file size test.db +} {3072} + +for {set ii 0} {$ii < 5} {incr ii} { + + # Simple test using the database created above: Create a new + # table so that page 1 and page 4 are modified. Using a + # block-size of 2048 and page-size of 1024, this means + # pages 2 and 3 must also be saved in the journal to avoid + # risking corruption. + # + # The loop is so that this test can be run with a couple + # of different seeds for the random number generator. + # + do_test crash2-1.2.$ii { + crashsql -file test.db -blocksize 2048 [subst { + [string repeat {SELECT random();} $ii] + CREATE TABLE hij(h, i, j); + }] + sqlite3 db test.db + db eval {PRAGMA integrity_check} + } {ok} +} + +proc signature {} { + return [db eval {SELECT count(*), md5sum(a), md5sum(b), md5sum(c) FROM abc}] +} + +# Test case for crashing during journal sync with simulated +# sector-size values from 1024 to 8192. +# +do_test crash2-2.0 { + execsql BEGIN + for {set n 0} {$n < 1000} {incr n} { + execsql "INSERT INTO abc VALUES($n, [expr 2*$n], [expr 3*$n])" + } + execsql { + INSERT INTO abc SELECT * FROM abc; + INSERT INTO abc SELECT * FROM abc; + INSERT INTO abc SELECT * FROM abc; + INSERT INTO abc SELECT * FROM abc; + INSERT INTO abc SELECT * FROM abc; + } + execsql COMMIT + expr ([file size test.db] / 1024) > 450 +} {1} +for {set i 1} {$i < 30} {incr i} { + set sig [signature] + set sector [expr 1024 * 1<<($i%4)] + db close + do_test crash2-2.$i.1 { + crashsql -blocksize $sector -delay [expr $i%5 + 1] -file test.db-journal " + PRAGMA temp_store = memory; + BEGIN; + SELECT random() FROM abc LIMIT $i; + INSERT INTO abc SELECT randstr(10,10), 0, 0 FROM abc WHERE random()%2==0; + DELETE FROM abc WHERE random()%2!=0; + COMMIT; + " + } {1 {child process exited abnormally}} + do_test crash2-2.$i.2 { + sqlite3 db test.db + signature + } $sig +} + + +# Test case for crashing during database sync with simulated +# sector-size values from 1024 to 8192. +# +for {set i 1} {$i < 10} {incr i} { + set sig [signature] + set sector [expr 1024 * 1<<($i%4)] + db close + do_test crash2-3.$i.1 { + crashsql -blocksize $sector -file test.db " + BEGIN; + SELECT random() FROM abc LIMIT $i; + INSERT INTO abc SELECT randstr(10,10), 0, 0 FROM abc WHERE random()%2==0; + DELETE FROM abc WHERE random()%2!=0; + COMMIT; + " + } {1 {child process exited abnormally}} + do_test crash2-3.$i.2 { + sqlite3 db test.db + signature + } $sig +} + +finish_test diff --git a/test/crash3.test b/test/crash3.test new file mode 100644 index 0000000..7958af9 --- /dev/null +++ b/test/crash3.test @@ -0,0 +1,190 @@ +# 2007 August 23 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file contains tests that verify that SQLite can correctly rollback +# databases after crashes when using the special IO modes triggered +# by device IOCAP flags. +# +# $Id: crash3.test,v 1.4 2008/07/12 14:52:20 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !crashtest { + finish_test + return +} + +proc do_test2 {name tcl res1 res2} { + set script [subst -nocommands { + do_test $name { + set res1 {$res1} + set res2 {$res2} + set res [eval {$tcl}] + if {[set res] eq [set res1] || [set res] eq [set res2]} { + set res "{[set res1]} or {[set res2]}" + } + set res + } {{$res1} or {$res2}} + }] + uplevel $script +} + +# This block tests crash-recovery when the IOCAP_ATOMIC flags is set. +# +# Each iteration of the following loop sets up the database to contain +# the following schema and data: +# +# CREATE TABLE abc(a, b, c); +# INSERT INTO abc VALUES(1, 2, 3); +# +# Then execute the SQL statement, scheduling a crash for part-way through +# the first sync() of either the database file or the journal file (often +# the journal file is not required - meaning no crash occurs). +# +# After the crash (or absence of a crash), open the database and +# verify that: +# +# * The integrity check passes, and +# * The contents of table abc is either {1 2 3} or the value specified +# to the right of the SQL statement below. +# +# The procedure is repeated 10 times for each SQL statement. Five times +# with the crash scheduled for midway through the first journal sync (if +# any), and five times with the crash midway through the database sync. +# +set tn 1 +foreach {sql res2} [list \ + {INSERT INTO abc VALUES(4, 5, 6)} {1 2 3 4 5 6} \ + {DELETE FROM abc} {} \ + {INSERT INTO abc SELECT * FROM abc} {1 2 3 1 2 3} \ + {UPDATE abc SET a = 2} {2 2 3} \ + {INSERT INTO abc VALUES(4, 5, randstr(1000,1000))} {n/a} \ + {CREATE TABLE def(d, e, f)} {n/a} \ +] { + for {set ii 0} {$ii < 10} {incr ii} { + + db close + forcedelete test.db test.db-journal + sqlite3 db test.db + do_test crash3-1.$tn.1 { + execsql { + PRAGMA page_size = 1024; + BEGIN; + CREATE TABLE abc(a, b, c); + INSERT INTO abc VALUES(1, 2, 3); + COMMIT; + } + } {} + db close + + set crashfile test.db + if {($ii%2)==0} { append crashfile -journal } + set rand "SELECT randstr($tn,$tn);" + do_test crash3-1.$tn.2 [subst { + crashsql -file $crashfile -char atomic {$rand $sql} + sqlite3 db test.db + execsql { PRAGMA integrity_check; } + }] {ok} + + do_test2 crash3-1.$tn.3 { + execsql { SELECT * FROM abc } + } {1 2 3} $res2 + + incr tn + } +} + +# This block tests both the IOCAP_SEQUENTIAL and IOCAP_SAFE_APPEND flags. +# +db close +forcedelete test.db test.db-journal +sqlite3 db test.db +do_test crash3-2.0 { + execsql { + BEGIN; + CREATE TABLE abc(a PRIMARY KEY, b, c); + CREATE TABLE def(d PRIMARY KEY, e, f); + PRAGMA default_cache_size = 10; + INSERT INTO abc VALUES(randstr(10,1000),randstr(10,1000),randstr(10,1000)); + INSERT INTO abc + SELECT randstr(10,1000),randstr(10,1000),randstr(10,1000) FROM abc; + INSERT INTO abc + SELECT randstr(10,1000),randstr(10,1000),randstr(10,1000) FROM abc; + INSERT INTO abc + SELECT randstr(10,1000),randstr(10,1000),randstr(10,1000) FROM abc; + INSERT INTO abc + SELECT randstr(10,1000),randstr(10,1000),randstr(10,1000) FROM abc; + INSERT INTO abc + SELECT randstr(10,1000),randstr(10,1000),randstr(10,1000) FROM abc; + INSERT INTO abc + SELECT randstr(10,1000),randstr(10,1000),randstr(10,1000) FROM abc; + COMMIT; + } +} {} + +set tn 1 +foreach {::crashfile ::delay ::char} { + test.db 1 sequential + test.db 1 safe_append + test.db-journal 1 sequential + test.db-journal 1 safe_append + test.db-journal 2 safe_append + test.db-journal 2 sequential + test.db-journal 3 sequential + test.db-journal 3 safe_append +} { + for {set ii 0} {$ii < 100} {incr ii} { + set ::SQL [subst { + SELECT randstr($ii,$ii+10); + BEGIN; + DELETE FROM abc WHERE random()%5; + INSERT INTO abc + SELECT randstr(10,1000),randstr(10,1000),randstr(10,1000) + FROM abc + WHERE (random()%5)==0; + DELETE FROM def WHERE random()%5; + INSERT INTO def + SELECT randstr(10,1000),randstr(10,1000),randstr(10,1000) + FROM def + WHERE (random()%5)==0; + COMMIT; + }] + + do_test crash3-2.$tn.$ii { + crashsql -file $::crashfile -delay $::delay -char $::char $::SQL + db close + sqlite3 db test.db + execsql {PRAGMA integrity_check} + } {ok} + } + incr tn +} + +# The following block tests an interaction between IOCAP_ATOMIC and +# IOCAP_SEQUENTIAL. At one point, if both flags were set, small +# journal files that contained only a single page, but were required +# for some other reason (i.e. nTrunk) were not being written to +# disk. +# +for {set ii 0} {$ii < 10} {incr ii} { + db close + forcedelete test.db test.db-journal + crashsql -file test.db -char {sequential atomic} { + CREATE TABLE abc(a, b, c); + } + sqlite3 db test.db + do_test crash3-3.$ii { + execsql {PRAGMA integrity_check} + } {ok} +} + +finish_test diff --git a/test/crash4.test b/test/crash4.test new file mode 100644 index 0000000..f68caec --- /dev/null +++ b/test/crash4.test @@ -0,0 +1,102 @@ +# 2008 January 8 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file contains additional tests to verify that SQLite database +# file survive a power loss or OS crash. +# +# $Id: crash4.test,v 1.3 2008/01/16 17:46:38 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !crashtest { + finish_test + return +} + + +# A sequence of SQL commands: +# +set sql_cmd_list { + {CREATE TABLE a(id INTEGER, name CHAR(50))} + {INSERT INTO a(id,name) VALUES(1,'one')} + {INSERT INTO a(id,name) VALUES(2,'two')} + {INSERT INTO a(id,name) VALUES(3,'three')} + {INSERT INTO a(id,name) VALUES(4,'four')} + {INSERT INTO a(id,name) VALUES(5,'five')} + {INSERT INTO a(id,name) VALUES(6,'six')} + {INSERT INTO a(id,name) VALUES(7,'seven')} + {INSERT INTO a(id,name) VALUES(8,'eight')} + {INSERT INTO a(id,name) VALUES(9,'nine')} + {INSERT INTO a(id,name) VALUES(10,'ten')} + {UPDATE A SET name='new text for row 3' WHERE id=3} +} + +# Assume that a database is created by evaluating the SQL statements +# in $sql_cmd_list. Compute a set of checksums that capture the state +# of the database after each statement. Also include a checksum for +# the state of the database prior to any of these statements. +# +set crash4_cksum_set {} +lappend crash4_cksum_set [allcksum db] +foreach cmd $sql_cmd_list { + db eval $cmd + lappend crash4_cksum_set [allcksum db] +} + +# Run the sequence of SQL statements shown above repeatedly. +# Close and reopen the database right before the UPDATE statement. +# On each repetition, introduce database corruption typical of +# what might be seen in a power loss or OS crash. +# +# Slowly increase the delay before the crash, repeating the test +# over and over. Stop testing when the entire sequence of SQL +# statements runs to completing without hitting the crash. +# +for {set cnt 1; set fin 0} {!$fin} {incr cnt} { + db close + forcedelete test.db test.db-journal + do_test crash4-1.$cnt.1 { + set seed [expr {int(abs(rand()*10000))}] + set delay [expr {int($cnt/50)+1}] + set file [expr {($cnt&1)?"test.db":"test.db-journal"}] + set c [crashsql -delay $delay -file $file -seed $seed -tclbody { + db eval {CREATE TABLE a(id INTEGER, name CHAR(50))} + db eval {INSERT INTO a(id,name) VALUES(1,'one')} + db eval {INSERT INTO a(id,name) VALUES(2,'two')} + db eval {INSERT INTO a(id,name) VALUES(3,'three')} + db eval {INSERT INTO a(id,name) VALUES(4,'four')} + db eval {INSERT INTO a(id,name) VALUES(5,'five')} + db eval {INSERT INTO a(id,name) VALUES(6,'six')} + db eval {INSERT INTO a(id,name) VALUES(7,'seven')} + db eval {INSERT INTO a(id,name) VALUES(8,'eight')} + db eval {INSERT INTO a(id,name) VALUES(9,'nine')} + db eval {INSERT INTO a(id,name) VALUES(10,'ten')} + db close + sqlite3 db test.db + db eval {UPDATE A SET name='new text for row 3' WHERE id=3} + db close + } {}] + if {$c==[list 0 {}]} { + set ::fin 1 + set c [list 1 {child process exited abnormally}] + } + set c + } {1 {child process exited abnormally}} + sqlite3 db test.db + integrity_check crash4-1.$cnt.2 + do_test crash4-1.$cnt.3 { + set x [lsearch $::crash4_cksum_set [allcksum db]] + expr {$x>=0} + } {1} +} + +finish_test diff --git a/test/crash5.test b/test/crash5.test new file mode 100644 index 0000000..fc078b3 --- /dev/null +++ b/test/crash5.test @@ -0,0 +1,127 @@ + +# 2007 Aug 13 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file tests aspects of recovery from a malloc() failure +# in a CREATE INDEX statement. +# +# $Id: crash5.test,v 1.3 2008/07/12 14:52:20 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Only run these tests if memory debugging is turned on. +# +ifcapable !crashtest||!memorymanage { + puts "Skipping crash5 tests: not compiled with -DSQLITE_ENABLE_MEMORY_MANAGEMENT..." + finish_test + return +} + +db close + +for {set ii 0} {$ii < 10} {incr ii} { + for {set jj 1} {$jj < 100} {incr jj} { + + # Set up the database so that it is an auto-vacuum database + # containing a single table (root page 3) with a single row. + # The row has an overflow page (page 4). + forcedelete test.db test.db-journal + sqlite3 db test.db + set c [string repeat 3 1500] + db eval { + pragma auto_vacuum = 1; + CREATE TABLE t1(a, b, c); + INSERT INTO t1 VALUES('1111111111', '2222222222', $c); + } + db close + + do_test crash5-$ii.$jj.1 { + crashsql -delay 1 -file test.db-journal -seed $ii -tclbody [join [list \ + [list set iFail $jj] { + proc get_pwd {} { + if {$::tcl_platform(platform) eq "windows"} { + if {[info exists ::env(ComSpec)]} { + set comSpec $::env(ComSpec) + } else { + # NOTE: Hard-code the typical default value. + set comSpec {C:\Windows\system32\cmd.exe} + } + return [string map [list \\ /] \ + [string trim [exec -- $comSpec /c echo %CD%]]] + } else { + return [pwd] + } + } + sqlite3_crashparams 0 [file join [get_pwd] test.db-journal] + + # Begin a transaction and evaluate a "CREATE INDEX" statement + # with the iFail'th malloc() set to fail. This operation will + # have to move the current contents of page 4 (the overflow + # page) to make room for the new root page. The bug is that + # if malloc() fails at a particular point in sqlite3PagerMovepage(), + # sqlite mistakenly thinks that the page being moved (page 4) has + # been safely synced into the journal. If the page is written + # to later in the transaction, it may be written out to the database + # before the relevant part of the journal has been synced. + # + db eval BEGIN + sqlite3_memdebug_fail $iFail -repeat 0 + set rc [catch {db eval { CREATE UNIQUE INDEX i1 ON t1(a); }} msg] +# puts "$msg ac=[sqlite3_get_autocommit db] iFail=$iFail" +# puts "fail=[sqlite3_memdebug_fail -1]" + + if {$rc} { + # If the transaction is still active (it may not be if the malloc() + # failure occurred in the OS layer), write to the database. Make sure + # page 4 is among those written. + # + if {![sqlite3_get_autocommit db]} { + db eval { + DELETE FROM t1; -- This will put page 4 on the free list. + INSERT INTO t1 VALUES('111111111', '2222222222', '33333333'); + INSERT INTO t1 SELECT * FROM t1; -- 2 + INSERT INTO t1 SELECT * FROM t1; -- 4 + INSERT INTO t1 SELECT * FROM t1; -- 8 + INSERT INTO t1 SELECT * FROM t1; -- 16 + INSERT INTO t1 SELECT * FROM t1; -- 32 + INSERT INTO t1 SELECT * FROM t1 WHERE rowid%2; -- 48 + } + } + + # If the right malloc() failed during the 'CREATE INDEX' above and + # the transaction was not rolled back, then the sqlite cache now + # has a dirty page 4 that it incorrectly believes is already safely + # in the synced part of the journal file. When + # sqlite3_release_memory() is called sqlite tries to free memory + # by writing page 4 out to the db file. If it crashes later on, + # before syncing the journal... Corruption! + # + sqlite3_crashparams 1 [file join [get_pwd] test.db-journal] + sqlite3_release_memory 8092 + } + }]] {} + expr 1 + } {1} + + sqlite3 db test.db + do_test crash5-$ii.$jj.2 { + db eval {pragma integrity_check} + } {ok} + do_test crash5-$ii.$jj.3 { + db eval {SELECT * FROM t1} + } [list 1111111111 2222222222 $::c] + db close + } +} + + +finish_test diff --git a/test/crash6.test b/test/crash6.test new file mode 100644 index 0000000..69c1946 --- /dev/null +++ b/test/crash6.test @@ -0,0 +1,118 @@ +# 2001 September 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file tests that rollback journals for databases that use a +# page-size other than the default page-size can be rolled back Ok. +# +# $Id: crash6.test,v 1.2 2008/04/14 15:27:19 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !crashtest { + finish_test + return +} + +for {set ii 0} {$ii < 10} {incr ii} { + catch {db close} + forcedelete test.db test.db-journal + crashsql -delay 2 -file test.db { + PRAGMA auto_vacuum=OFF; + PRAGMA page_size=4096; + BEGIN; + CREATE TABLE abc AS SELECT 1 AS a, 2 AS b, 3 AS c; + COMMIT; + BEGIN; + CREATE TABLE def AS SELECT 1 AS d, 2 AS e, 3 AS f; + COMMIT; + } + sqlite3 db test.db + integrity_check crash6-1.$ii +} + +for {set ii 0} {$ii < 10} {incr ii} { + catch {db close} + forcedelete test.db test.db-journal + sqlite3 db test.db + execsql { + PRAGMA auto_vacuum=OFF; + PRAGMA page_size=2048; + BEGIN; + CREATE TABLE abc AS SELECT 1 AS a, 2 AS b, 3 AS c; + COMMIT; + } + db close + crashsql -delay 1 -file test.db { + INSERT INTO abc VALUES(5, 6, 7); + } + sqlite3 db test.db + integrity_check crash6-2.$ii +} + +proc signature {} { + return [db eval {SELECT count(*), md5sum(a), md5sum(b), md5sum(c) FROM abc}] +} + +# Test case for crashing during database sync with page-size values +# from 1024 to 8192. +# +for {set ii 0} {$ii < 30} {incr ii} { + db close + forcedelete test.db + sqlite3 db test.db + + set pagesize [expr 1024 << ($ii % 4)] + if {$pagesize>$::SQLITE_MAX_PAGE_SIZE} { + set pagesize $::SQLITE_MAX_PAGE_SIZE + } + do_test crash6-3.$ii.0 { + execsql "pragma page_size = $pagesize" + execsql "pragma page_size" + } $pagesize + + do_test crash6-3.$ii.1 { + + execsql BEGIN + execsql {CREATE TABLE abc(a, b, c)} + for {set n 0} {$n < 1000} {incr n} { + execsql "INSERT INTO abc VALUES($n, [expr 2*$n], [expr 3*$n])" + } + execsql { + INSERT INTO abc SELECT * FROM abc; + INSERT INTO abc SELECT * FROM abc; + INSERT INTO abc SELECT * FROM abc; + INSERT INTO abc SELECT * FROM abc; + INSERT INTO abc SELECT * FROM abc; + } + execsql COMMIT + expr ([file size test.db] / 1024) > 450 + } {1} + + set sig [signature] + db close + + do_test crash6-3.$ii.2 { + crashsql -file test.db " + BEGIN; + SELECT random() FROM abc LIMIT $ii; + INSERT INTO abc SELECT randstr(10,10), 0, 0 FROM abc WHERE random()%2==0; + DELETE FROM abc WHERE random()%2!=0; + COMMIT; + " + } {1 {child process exited abnormally}} + + do_test crash6-3.$ii.3 { + sqlite3 db test.db + signature + } $sig +} + +finish_test diff --git a/test/crash7.test b/test/crash7.test new file mode 100644 index 0000000..482999c --- /dev/null +++ b/test/crash7.test @@ -0,0 +1,116 @@ +# 2008 March 20 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# $Id: crash7.test,v 1.1 2008/04/03 14:36:26 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix crash7 + +ifcapable !crashtest { + finish_test + return +} + +proc signature {} { + return [db eval {SELECT count(*), md5sum(a), md5sum(b), md5sum(c) FROM abc}] +} + +foreach f [list test.db test.db-journal] { + for {set ii 1} {$ii < 64} {incr ii} { + db close + delete_file test.db + sqlite3 db test.db + + set from_size [expr 1024 << ($ii&3)] + set to_size [expr 1024 << (($ii>>2)&3)] + + execsql " + PRAGMA page_size = $from_size; + BEGIN; + CREATE TABLE abc(a PRIMARY KEY, b, c); + INSERT INTO abc VALUES(randomblob(100), randomblob(200), randomblob(1000)); + INSERT INTO abc + SELECT randomblob(1000), randomblob(200), randomblob(100) + FROM abc; + INSERT INTO abc + SELECT randomblob(100), randomblob(200), randomblob(1000) + FROM abc; + INSERT INTO abc + SELECT randomblob(100), randomblob(200), randomblob(1000) + FROM abc; + INSERT INTO abc + SELECT randomblob(100), randomblob(200), randomblob(1000) + FROM abc; + INSERT INTO abc + SELECT randomblob(100), randomblob(200), randomblob(1000) + FROM abc WHERE [expr $ii&16]; + INSERT INTO abc + SELECT randomblob(25), randomblob(45), randomblob(9456) + FROM abc WHERE [expr $ii&32]; + INSERT INTO abc + SELECT randomblob(100), randomblob(200), randomblob(1000) + FROM abc WHERE [expr $ii&8]; + INSERT INTO abc + SELECT randomblob(25), randomblob(45), randomblob(9456) + FROM abc WHERE [expr $ii&4]; + COMMIT; + " + + set sig [signature] + db close + + do_test crash7-1.$ii.crash { + crashsql -file $f " + PRAGMA page_size = $to_size; + VACUUM; + " + } {1 {child process exited abnormally}} + + sqlite3 db test.db + integrity_check crash7-1.$ii.integrity + } +} + +db close +forcedelete test.db +sqlite3 db test.db +do_execsql_test 2.0 { + CREATE TABLE t1(a, b, UNIQUE(a, b)); + INSERT INTO t1 VALUES(randomblob(100), randomblob(100)); + INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM t1; + INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM t1; + INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM t1; + INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM t1; + INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM t1; + INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM t1; + INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM t1; + INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM t1; + INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM t1; + INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM t1; + INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM t1; + INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM t1; + INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM t1; + INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM t1; + DELETE FROM t1 WHERE rowid%2; +} +db_save_and_close + +for {set i 0} {$i < 20} {incr i} { + db_restore_and_reopen + do_test 2.[expr $i+1].1 { + crashsql -file test.db -seed $i {VACUUM} + } {1 {child process exited abnormally}} + do_execsql_test 2.[expr $i+1].2 { PRAGMA integrity_check } {ok} +} + + +finish_test diff --git a/test/crash8.test b/test/crash8.test new file mode 100644 index 0000000..c078299 --- /dev/null +++ b/test/crash8.test @@ -0,0 +1,419 @@ +# 2009 January 8 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This test verifies a couple of specific potential data corruption +# scenarios involving crashes or power failures. +# +# Later: Also, some other specific scenarios required for coverage +# testing that do not lead to corruption. +# +# $Id: crash8.test,v 1.4 2009/01/11 00:44:48 drh Exp $ + + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !crashtest { + finish_test + return +} +do_not_use_codec + +do_test crash8-1.1 { + execsql { + PRAGMA auto_vacuum=OFF; + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a, b); + INSERT INTO t1 VALUES(1, randstr(1000,1000)); + INSERT INTO t1 VALUES(2, randstr(1000,1000)); + INSERT INTO t1 VALUES(3, randstr(1000,1000)); + INSERT INTO t1 VALUES(4, randstr(1000,1000)); + INSERT INTO t1 VALUES(5, randstr(1000,1000)); + INSERT INTO t1 VALUES(6, randstr(1000,1000)); + CREATE TABLE t2(a, b); + CREATE TABLE t3(a, b); + CREATE TABLE t4(a, b); + CREATE TABLE t5(a, b); + CREATE TABLE t6(a, b); + CREATE TABLE t7(a, b); + CREATE TABLE t8(a, b); + CREATE TABLE t9(a, b); + CREATE TABLE t10(a, b); + PRAGMA integrity_check + } +} {ok} + + +# Potential corruption scenario 1. A second process opens the database +# and modifies a large portion of it. It then opens a second transaction +# and modifies a small part of the database, but crashes before it commits +# the transaction. +# +# When the first process accessed the database again, it was rolling back +# the aborted transaction, but was not purging its in-memory cache (which +# was loaded before the second process made its first, successful, +# modification). Producing an inconsistent cache. +# +do_test crash8-1.2 { + crashsql -delay 2 -file test.db { + PRAGMA cache_size = 10; + UPDATE t1 SET b = randstr(1000,1000); + INSERT INTO t9 VALUES(1, 2); + } +} {1 {child process exited abnormally}} +do_test crash8-1.3 { + execsql {PRAGMA integrity_check} +} {ok} + +# Potential corruption scenario 2. The second process, operating in +# persistent-journal mode, makes a large change to the database file +# with a small in-memory cache. Such that more than one journal-header +# was written to the file. It then opens a second transaction and makes +# a smaller change that requires only a single journal-header to be +# written to the journal file. The second change is such that the +# journal content written to the persistent journal file exactly overwrites +# the first journal-header and set of subsequent records written by the +# first, successful, change. The second process crashes before it can +# commit its second change. +# +# When the first process accessed the database again, it was rolling back +# the second aborted transaction, then continuing to rollback the second +# and subsequent journal-headers written by the first, successful, change. +# Database corruption. +# +do_test crash8.2.1 { + crashsql -delay 2 -file test.db { + PRAGMA journal_mode = persist; + PRAGMA cache_size = 10; + UPDATE t1 SET b = randstr(1000,1000); + PRAGMA cache_size = 100; + BEGIN; + INSERT INTO t2 VALUES('a', 'b'); + INSERT INTO t3 VALUES('a', 'b'); + INSERT INTO t4 VALUES('a', 'b'); + INSERT INTO t5 VALUES('a', 'b'); + INSERT INTO t6 VALUES('a', 'b'); + INSERT INTO t7 VALUES('a', 'b'); + INSERT INTO t8 VALUES('a', 'b'); + INSERT INTO t9 VALUES('a', 'b'); + INSERT INTO t10 VALUES('a', 'b'); + COMMIT; + } +} {1 {child process exited abnormally}} + +do_test crash8-2.3 { + execsql {PRAGMA integrity_check} +} {ok} + +proc read_file {zFile} { + set fd [open $zFile] + fconfigure $fd -translation binary + set zData [read $fd] + close $fd + return $zData +} +proc write_file {zFile zData} { + set fd [open $zFile w] + fconfigure $fd -translation binary + puts -nonewline $fd $zData + close $fd +} + +# The following tests check that SQLite will not roll back a hot-journal +# file if the sector-size field in the first journal file header is +# suspect. Definition of suspect: +# +# a) Not a power of 2, or (crash8-3.5) +# b) Greater than 0x01000000 (16MB), or (crash8-3.6) +# c) Less than 512. (crash8-3.7) +# +# Also test that SQLite will not rollback a hot-journal file with a +# suspect page-size. In this case "suspect" means: +# +# a) Not a power of 2, or +# b) Less than 512, or +# c) Greater than SQLITE_MAX_PAGE_SIZE +# +if {[atomic_batch_write test.db]==0} { +do_test crash8-3.1 { + list [file exists test.db-joural] [file exists test.db] +} {0 1} +do_test crash8-3.2 { + execsql { + PRAGMA synchronous = off; + BEGIN; + DELETE FROM t1; + SELECT count(*) FROM t1; + } +} {0} +do_test crash8-3.3 { + set zJournal [read_file test.db-journal] + execsql { + COMMIT; + SELECT count(*) FROM t1; + } +} {0} +do_test crash8-3.4 { + binary scan [string range $zJournal 20 23] I nSector + set nSector +} {512} + +do_test crash8-3.5 { + set zJournal2 [string replace $zJournal 20 23 [binary format I 513]] + write_file test.db-journal $zJournal2 + + execsql { + SELECT count(*) FROM t1; + PRAGMA integrity_check + } +} {0 ok} +do_test crash8-3.6 { + set zJournal2 [string replace $zJournal 20 23 [binary format I 0x2000000]] + write_file test.db-journal $zJournal2 + execsql { + SELECT count(*) FROM t1; + PRAGMA integrity_check + } +} {0 ok} +do_test crash8-3.7 { + set zJournal2 [string replace $zJournal 20 23 [binary format I 256]] + write_file test.db-journal $zJournal2 + execsql { + SELECT count(*) FROM t1; + PRAGMA integrity_check + } +} {0 ok} + +do_test crash8-3.8 { + set zJournal2 [string replace $zJournal 24 27 [binary format I 513]] + write_file test.db-journal $zJournal2 + + execsql { + SELECT count(*) FROM t1; + PRAGMA integrity_check + } +} {0 ok} +do_test crash8-3.9 { + set big [expr $SQLITE_MAX_PAGE_SIZE * 2] + set zJournal2 [string replace $zJournal 24 27 [binary format I $big]] + write_file test.db-journal $zJournal2 + execsql { + SELECT count(*) FROM t1; + PRAGMA integrity_check + } +} {0 ok} +do_test crash8-3.10 { + set zJournal2 [string replace $zJournal 24 27 [binary format I 256]] + write_file test.db-journal $zJournal2 + execsql { + SELECT count(*) FROM t1; + PRAGMA integrity_check + } +} {0 ok} + +do_test crash8-3.11 { + set fd [open test.db-journal w] + fconfigure $fd -translation binary + puts -nonewline $fd $zJournal + close $fd + execsql { + SELECT count(*) FROM t1; + PRAGMA integrity_check + } +} {6 ok} +} + + +# If a connection running in persistent-journal mode is part of a +# multi-file transaction, it must ensure that the master-journal name +# appended to the journal file contents during the commit is located +# at the end of the physical journal file. If there was already a +# large journal file allocated at the start of the transaction, this +# may mean truncating the file so that the master journal name really +# is at the physical end of the file. +# +# This block of tests test that SQLite correctly truncates such +# journal files, and that the results behave correctly if a hot-journal +# rollback occurs. +# +ifcapable pragma { + reset_db + forcedelete test2.db + + do_test crash8-4.1 { + execsql { + PRAGMA journal_mode = persist; + CREATE TABLE ab(a, b); + INSERT INTO ab VALUES(0, 'abc'); + INSERT INTO ab VALUES(1, NULL); + INSERT INTO ab VALUES(2, NULL); + INSERT INTO ab VALUES(3, NULL); + INSERT INTO ab VALUES(4, NULL); + INSERT INTO ab VALUES(5, NULL); + INSERT INTO ab VALUES(6, NULL); + UPDATE ab SET b = randstr(1000,1000); + ATTACH 'test2.db' AS aux; + PRAGMA aux.journal_mode = persist; + CREATE TABLE aux.ab(a, b); + INSERT INTO aux.ab SELECT * FROM main.ab; + + UPDATE aux.ab SET b = randstr(1000,1000) WHERE a>=1; + UPDATE ab SET b = randstr(1000,1000) WHERE a>=1; + } + } {persist persist} + if {[atomic_batch_write test.db]==0} { + do_test crash8.4.1.1 { + list [file exists test.db-journal] [file exists test2.db-journal] + } {1 1} + } + + do_test crash8-4.2 { + execsql { + BEGIN; + UPDATE aux.ab SET b = 'def' WHERE a = 0; + UPDATE main.ab SET b = 'def' WHERE a = 0; + COMMIT; + } + } {} + + do_test crash8-4.3 { + execsql { + UPDATE aux.ab SET b = randstr(1000,1000) WHERE a>=1; + UPDATE ab SET b = randstr(1000,1000) WHERE a>=1; + } + } {} + + set contents_main [db eval {SELECT b FROM main.ab WHERE a = 1}] + set contents_aux [db eval {SELECT b FROM aux.ab WHERE a = 1}] + + do_test crash8-4.4 { + crashsql -file test2.db -delay 1 { + ATTACH 'test2.db' AS aux; + BEGIN; + UPDATE aux.ab SET b = 'ghi' WHERE a = 0; + UPDATE main.ab SET b = 'ghi' WHERE a = 0; + COMMIT; + } + } {1 {child process exited abnormally}} + + do_test crash8-4.5 { + list [file exists test.db-journal] [file exists test2.db-journal] + } {1 1} + + do_test crash8-4.6 { + execsql { + SELECT b FROM main.ab WHERE a = 0; + SELECT b FROM aux.ab WHERE a = 0; + } + } {def def} + + do_test crash8-4.7 { + crashsql -file test2.db -delay 1 { + ATTACH 'test2.db' AS aux; + BEGIN; + UPDATE aux.ab SET b = 'jkl' WHERE a = 0; + UPDATE main.ab SET b = 'jkl' WHERE a = 0; + COMMIT; + } + } {1 {child process exited abnormally}} + + do_test crash8-4.8 { + set fd [open test.db-journal] + fconfigure $fd -translation binary + seek $fd -16 end + binary scan [read $fd 4] I len + + seek $fd [expr {-1 * ($len + 16)}] end + set zMasterJournal [read $fd $len] + close $fd + + file exists $zMasterJournal + } {1} + + do_test crash8-4.9 { + execsql { SELECT b FROM aux.ab WHERE a = 0 } + } {def} + + do_test crash8-4.10 { + delete_file $zMasterJournal + execsql { SELECT b FROM main.ab WHERE a = 0 } + } {jkl} +} + +# +# Since the following tests (crash8-5.*) rely upon being able +# to copy a file while open, they will not work on Windows. +# +# They also depend on being able to copy the journal file, which +# is not created on F2FS file-systems that support atomic +# write. So do not run these tests in that case either. +# +if {$::tcl_platform(platform)=="unix" && [atomic_batch_write test.db]==0 } { + for {set i 1} {$i < 10} {incr i} { + catch { db close } + forcedelete test.db test.db-journal + sqlite3 db test.db + do_test crash8-5.$i.1 { + execsql { + CREATE TABLE t1(x PRIMARY KEY); + INSERT INTO t1 VALUES(randomblob(900)); + INSERT INTO t1 SELECT randomblob(900) FROM t1; + INSERT INTO t1 SELECT randomblob(900) FROM t1; + INSERT INTO t1 SELECT randomblob(900) FROM t1; + INSERT INTO t1 SELECT randomblob(900) FROM t1; + INSERT INTO t1 SELECT randomblob(900) FROM t1; + INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 64 rows */ + } + crashsql -file test.db -delay [expr ($::i%2) + 1] { + PRAGMA cache_size = 10; + BEGIN; + UPDATE t1 SET x = randomblob(900); + ROLLBACK; + INSERT INTO t1 VALUES(randomblob(900)); + } + execsql { PRAGMA integrity_check } + } {ok} + + catch { db close } + forcedelete test.db test.db-journal + sqlite3 db test.db + do_test crash8-5.$i.2 { + execsql { + PRAGMA cache_size = 10; + CREATE TABLE t1(x PRIMARY KEY); + INSERT INTO t1 VALUES(randomblob(900)); + INSERT INTO t1 SELECT randomblob(900) FROM t1; + INSERT INTO t1 SELECT randomblob(900) FROM t1; + INSERT INTO t1 SELECT randomblob(900) FROM t1; + INSERT INTO t1 SELECT randomblob(900) FROM t1; + INSERT INTO t1 SELECT randomblob(900) FROM t1; + INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 64 rows */ + BEGIN; + UPDATE t1 SET x = randomblob(900); + } + forcedelete testX.db testX.db-journal testX.db-wal + forcecopy test.db testX.db + forcecopy test.db-journal testX.db-journal + db close + + crashsql -file test.db -delay [expr ($::i%2) + 1] { + SELECT * FROM sqlite_master; + INSERT INTO t1 VALUES(randomblob(900)); + } + + sqlite3 db2 testX.db + execsql { PRAGMA integrity_check } db2 + } {ok} + } + catch {db2 close} +} + +finish_test diff --git a/test/crashM.test b/test/crashM.test new file mode 100644 index 0000000..de10c45 --- /dev/null +++ b/test/crashM.test @@ -0,0 +1,80 @@ +# 2015 Mar 13 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Crash tests for the multiplex module with 8.3 filenames enabled. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix crashM + +ifcapable !crashtest||!8_3_names { + finish_test + return +} + +db close +sqlite3_shutdown +sqlite3_config_uri 1 + +foreach f [glob -nocomplain test1.* test2.*] { forcedelete $f } +sqlite3_multiplex_initialize "" 1 +sqlite3 db file:test1.db?8_3_names=1 +sqlite3_multiplex_control db main chunk_size [expr 64*1024] + +do_execsql_test 1.0 { + ATTACH 'file:test2.db?8_3_names=1' AS aux; + + CREATE TABLE t1(x, y); + CREATE INDEX t1x ON t1(x); + CREATE INDEX t1y ON t1(y); + + CREATE TABLE aux.t2(x, y); + CREATE INDEX aux.t2x ON t2(x); + CREATE INDEX aux.t2y ON t2(y); + + WITH s(a) AS ( + SELECT 1 UNION ALL SELECT a+1 FROM s WHERE a<1000 + ) + INSERT INTO t1 SELECT a, randomblob(500) FROM s; + + WITH s(a) AS ( + SELECT 1 UNION ALL SELECT a+1 FROM s WHERE a<1000 + ) + INSERT INTO t2 SELECT a, randomblob(500) FROM s; +} {} + +for {set i 0} {$i < 20} {incr i} { + do_test 2.$i.1 { + crashsql -delay 1 -file test1.db -opendb { + sqlite3_shutdown + sqlite3_config_uri 1 + sqlite3_multiplex_initialize crash 1 + sqlite3 db file:test1.db?8_3_names=1 + sqlite3_multiplex_control db main chunk_size [expr 64*1024] + } { + ATTACH 'file:test2.db?8_3_names=1' AS aux; + BEGIN; + UPDATE t1 SET y = randomblob(500) WHERE (x%10)==0; + UPDATE t2 SET y = randomblob(500) WHERE (x%10)==0; + COMMIT; + } + } {1 {child process exited abnormally}} + + do_execsql_test 2.$i.2 { + PRAGMA main.integrity_check; + PRAGMA aux.integrity_check; + } {ok ok} +} + +catch { db close } +sqlite3_multiplex_shutdown +finish_test diff --git a/test/crashtest1.c b/test/crashtest1.c new file mode 100644 index 0000000..1f7035d --- /dev/null +++ b/test/crashtest1.c @@ -0,0 +1,96 @@ +/* +** This program tests the ability of SQLite database to recover from a crash. +** This program runs under Unix only, but the results are applicable to all +** systems. +** +** The main process first constructs a test database, then starts creating +** subprocesses that write to that database. Each subprocess is killed off, +** without a chance to clean up its database connection, after a random +** delay. This killing of the subprocesses simulates a crash or power +** failure. The next subprocess to open the database should rollback +** whatever operation was in process at the time of the simulated crash. +** +** If any problems are encountered, an error is reported and the test stops. +** If no problems are seen after a large number of tests, we assume that +** the rollback mechanism is working. +*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include "sqlite.h" + +static void do_some_sql(int parent){ + char *zErr; + int rc = SQLITE_OK; + sqlite *db; + int cnt = 0; + static char zBig[] = + "-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + "-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + + if( access("./test.db-journal",0)==0 ){ + /*printf("pid %d: journal exists. rollback will be required\n",getpid());*/ unlink("test.db-saved"); + system("cp test.db test.db-saved"); + unlink("test.db-journal-saved"); + system("cp test.db-journal test.db-journal-saved"); + } + db = sqlite_open("./test.db", 0, &zErr); + if( db==0 ){ + printf("ERROR: %s\n", zErr); + if( strcmp(zErr,"database disk image is malformed")==0 ){ + kill(parent, SIGKILL); + } + exit(1); + } + srand(getpid()); + while( rc==SQLITE_OK ){ + cnt++; + rc = sqlite_exec_printf(db, + "INSERT INTO t1 VALUES(%d,'%d%s')", 0, 0, &zErr, + rand(), rand(), zBig); + } + if( rc!=SQLITE_OK ){ + printf("ERROR #%d: %s\n", rc, zErr); + if( rc==SQLITE_CORRUPT ){ + kill(parent, SIGKILL); + } + } + printf("pid %d: cnt=%d\n", getpid(), cnt); +} + + +int main(int argc, char **argv){ + int i; + sqlite *db; + char *zErr; + int status; + int parent = getpid(); + + unlink("test.db"); + unlink("test.db-journal"); + db = sqlite_open("test.db", 0, &zErr); + if( db==0 ){ + printf("Cannot initialize: %s\n", zErr); + return 1; + } + sqlite_exec(db, "CREATE TABLE t1(a,b)", 0, 0, 0); + sqlite_close(db); + for(i=0; i<10000; i++){ + int pid = fork(); + if( pid==0 ){ + sched_yield(); + do_some_sql(parent); + return 0; + } + printf("test %d, pid=%d\n", i, pid); + usleep(rand()%10000 + 1000); + kill(pid, SIGKILL); + waitpid(pid, &status, 0); + } + return 0; +} diff --git a/test/createtab.test b/test/createtab.test new file mode 100644 index 0000000..5773fbf --- /dev/null +++ b/test/createtab.test @@ -0,0 +1,154 @@ +# 2007 May 02 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing that it is OK to create new tables +# and indices while creating existing tables and indices. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable autovacuum { + set upperBound 2 +} else { + set upperBound 0 +} + +# Run these tests for all possible values of autovacuum. +# +for {set av 0} {$av<=$upperBound} {incr av} { + db close + forcedelete test.db test.db-journal + sqlite3 db test.db + + # Create a table that spans multiple pages. It is important + # that part of the database be in pages beyond the root page. + # + do_test createtab-$av.1 { + execsql "PRAGMA auto_vacuum=$av" + execsql { + PRAGMA page_size=1024; + CREATE TABLE t1(x INTEGER PRIMARY KEY, y); + INSERT INTO t1 VALUES(1, hex(randomblob(200))); + INSERT INTO t1 VALUES(2, hex(randomblob(200))); + INSERT INTO t1 VALUES(3, hex(randomblob(200))); + INSERT INTO t1 VALUES(4, hex(randomblob(200))); + SELECT count(*) FROM t1; + } + } {4} + + set isUtf16 0 + ifcapable utf16 { + set isUtf16 [expr {[execsql {PRAGMA encoding}] != "UTF-8"}] + } + + do_test createtab-$av.2 { + file size test.db + } [expr {1024*(4+($av!=0)+(${isUtf16}*2))}] + + # Start reading the table + # + do_test createtab-$av.3 { + set STMT [sqlite3_prepare db {SELECT x FROM t1} -1 TAIL] + sqlite3_step $STMT + } {SQLITE_ROW} + do_test createtab-$av.4 { + sqlite3_column_int $STMT 0 + } {1} + + # While still reading the table, create a new table. + # + do_test createtab-$av.5 { + execsql { + CREATE TABLE t2(a,b); + INSERT INTO t2 VALUES(1,2); + SELECT * FROM t2; + } + } {1 2} + + # Continue reading the original table. + # + do_test createtab-$av.6 { + sqlite3_column_int $STMT 0 + } {1} + do_test createtab-$av.7 { + sqlite3_step $STMT + } {SQLITE_ROW} + do_test createtab-$av.8 { + sqlite3_column_int $STMT 0 + } {2} + + # Do another cycle of creating a new database table while contining + # to read the original table. + # + do_test createtab-$av.11 { + execsql { + CREATE TABLE t3(a,b); + INSERT INTO t3 VALUES(4,5); + SELECT * FROM t3; + } + } {4 5} + do_test createtab-$av.12 { + sqlite3_column_int $STMT 0 + } {2} + do_test createtab-$av.13 { + sqlite3_step $STMT + } {SQLITE_ROW} + do_test createtab-$av.14 { + sqlite3_column_int $STMT 0 + } {3} + + # One more cycle. + # + do_test createtab-$av.21 { + execsql { + CREATE TABLE t4(a,b); + INSERT INTO t4 VALUES('abc','xyz'); + SELECT * FROM t4; + } + } {abc xyz} + do_test createtab-$av.22 { + sqlite3_column_int $STMT 0 + } {3} + do_test createtab-$av.23 { + sqlite3_step $STMT + } {SQLITE_ROW} + do_test createtab-$av.24 { + sqlite3_column_int $STMT 0 + } {4} + + # Finish reading. Do an integrity check on the database. + # + do_test createtab-$av.30 { + sqlite3_step $STMT + } {SQLITE_DONE} + do_test createtab-$av.31 { + sqlite3_finalize $STMT + } {SQLITE_OK} + do_test createtab-$av.32 { + execsql { + SELECT name FROM sqlite_master WHERE type='table' ORDER BY 1 + } + } {t1 t2 t3 t4} + integrity_check createtab-$av.40 + +} + +# 2019-03-31 Ensure that a proper error is returned for an index +# with too many columns. +# +do_test createtab-3.1 { + db eval {DROP TABLE IF EXISTS t1;} + set sql "CREATE TABLE t1(x,UNIQUE(x[string repeat ,x 100000]))" + catchsql $sql +} {1 {too many columns in index}} + +finish_test diff --git a/test/cse.test b/test/cse.test new file mode 100644 index 0000000..3912bc3 --- /dev/null +++ b/test/cse.test @@ -0,0 +1,200 @@ +# 2008 April 1 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Test cases designed to exercise and verify the logic for +# factoring constant expressions out of loops and for +# common subexpression eliminations. +# +# $Id: cse.test,v 1.6 2008/08/04 03:51:24 danielk1977 Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix cse + +do_test cse-1.1 { + execsql { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, d, e, f); + INSERT INTO t1 VALUES(1,11,12,13,14,15); + INSERT INTO t1 VALUES(2,21,22,23,24,25); + } + execsql { + SELECT b, -b, ~b, NOT b, NOT NOT b, b-b, b+b, b*b, b/b, b FROM t1 + } +} {11 -11 -12 0 1 0 22 121 1 11 21 -21 -22 0 1 0 42 441 1 21} +do_test cse-1.2 { + execsql { + SELECT b, b%b, b==b, b!=b, b49} {set r [expr {99-$r}]} + lappend colset a$j a$r + lappend answer $j $r + } + set sql "SELECT [join $colset ,] FROM t2" + do_test cse-2.2.$i { + # explain $::sql + execsql $::sql + } $answer +} + +#------------------------------------------------------------------------- +# Ticket fd1bda016d1a +# +reset_db +do_execsql_test 3.0 { + CREATE TABLE t1(a TEXT, b); + INSERT INTO t1 VALUES('hello', 0); + INSERT INTO t1 VALUES('world', 0); + + CREATE TABLE t2(x TEXT); + INSERT INTO t2 VALUES('hello'); + INSERT INTO t2 VALUES('world'); + + CREATE TABLE t3(y); + INSERT INTO t3 VALUES(1000); +} {} + +do_execsql_test 3.1 { + SELECT 1000 = y FROM t3 +} {1} + +do_execsql_test 3.2 { + SELECT 1000 IN (SELECT x FROM t2), 1000 = y FROM t3 +} {0 1} + +do_execsql_test 3.3 { + SELECT 0 IN (SELECT a), (SELECT a LIMIT 0) FROM t1 +} {0 {} 0 {}} + +do_execsql_test 3.4 { + SELECT 0 IN (SELECT a) FROM t1 WHERE a = 'hello' OR (SELECT a LIMIT 0); +} {0} + +do_execsql_test 3.5 { + CREATE TABLE v0(v1 VARCHAR0); + INSERT INTO v0 VALUES(2), (3); + SELECT 0 IN(SELECT v1) FROM v0 WHERE v1 = 2 OR(SELECT v1 LIMIT 0); +} {0} + +finish_test diff --git a/test/csv01.test b/test/csv01.test new file mode 100644 index 0000000..ecb1a96 --- /dev/null +++ b/test/csv01.test @@ -0,0 +1,279 @@ +# 2016-06-02 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Test cases for CSV virtual table. + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix csv01 + +ifcapable !vtab||!cte { finish_test ; return } + +load_static_extension db csv + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE temp.t1 USING csv( + data= +'1,2,3,4 +5,6,7,8 +9,10,11,12 +13,14,15,16 +', + columns=4 + ); + SELECT * FROM t1 WHERE c1=10; +} {9 10 11 12} +do_execsql_test 1.1 { + SELECT * FROM t1 WHERE c1='10'; +} {9 10 11 12} +do_execsql_test 1.2 { + SELECT rowid FROM t1; +} {1 2 3 4} + +do_execsql_test 1.3 { + DROP TABLE temp.t1; + CREATE VIRTUAL TABLE temp.t1 USING csv( + data= +'a,b,"mix-bloom-eel","soft opinion" +1,2,3,4 +5,6,7,8 +9,10,11,12 +13,14,15,16 +', + header=1 + ); + SELECT * FROM t1 WHERE "soft opinion"=12; +} {9 10 11 12} +do_execsql_test 1.4 { + SELECT name FROM pragma_table_xinfo('t1'); +} {a b mix-bloom-eel {soft opinion}} + +do_execsql_test 1.5 { + DROP TABLE temp.t1; + CREATE VIRTUAL TABLE temp.t1 USING csv( + data= +'a,b,"mix-bloom-eel","soft opinion" +1,2,3,4 +5,6,7,8 +9,10,11,12 +13,14,15,16 +', + header=false + ); + SELECT * FROM t1 WHERE c1='b'; +} {a b mix-bloom-eel {soft opinion}} +do_execsql_test 1.6 { + SELECT name FROM pragma_table_xinfo('t1'); +} {c0 c1 c2 c3} + +do_execsql_test 1.7 { + DROP TABLE temp.t1; + CREATE VIRTUAL TABLE temp.t1 USING csv( + data= +'a,b,"mix-bloom-eel","soft opinion" +1,2,3,4 +5,6,7,8 +9,10,11,12 +13,14,15,16 +', + header, + schema='CREATE TABLE x(x0,x1,x2,x3,x4)', + columns=5 + ); + SELECT * FROM t1 WHERE x1='6'; +} {5 6 7 8 {}} +do_execsql_test 1.8 { + SELECT name FROM pragma_table_xinfo('t1'); +} {x0 x1 x2 x3 x4} + + +do_execsql_test 2.0 { + DROP TABLE t1; + CREATE VIRTUAL TABLE temp.t2 USING csv( + data= +'1,2,3,4 +5,6,7,8 +9,10,11,12 +13,14,15,16 +', + columns=4, + schema='CREATE TABLE t2(a INT, b TEXT, c REAL, d BLOB)' + ); + SELECT * FROM t2 WHERE a=9; +} {9 10 11 12} +do_execsql_test 2.1 { + SELECT * FROM t2 WHERE b=10; +} {9 10 11 12} +do_execsql_test 2.2 { + SELECT * FROM t2 WHERE c=11; +} {9 10 11 12} +do_execsql_test 2.3 { + SELECT * FROM t2 WHERE d=12; +} {} +do_execsql_test 2.4 { + SELECT * FROM t2 WHERE d='12'; +} {9 10 11 12} +do_execsql_test 2.5 { + SELECT * FROM t2 WHERE a='9'; +} {9 10 11 12} + +do_execsql_test 3.0 { + DROP TABLE t2; + CREATE VIRTUAL TABLE temp.t3 USING csv( + data= +'1,2,3,4 +5,6,7,8 +9,10,11,12 +13,14,15,16 +', + columns=4, + schema= + 'CREATE TABLE t3(a PRIMARY KEY,b TEXT,c TEXT,d TEXT) WITHOUT ROWID', + testflags=1 + ); + SELECT a FROM t3 WHERE b=6 OR c=7 OR d=12 ORDER BY +a; +} {5 9} +do_execsql_test 3.1 { + SELECT a FROM t3 WHERE +b=6 OR c=7 OR d=12 ORDER BY +a; +} {5 9} + +# The rowid column is not visible on a WITHOUT ROWID virtual table +do_catchsql_test 3.2 { + SELECT rowid, a FROM t3; +} {1 {no such column: rowid}} + +# Multi-column WITHOUT ROWID virtual tables may not be writable. +do_catchsql_test 4.0 { + DROP TABLE t3; + CREATE VIRTUAL TABLE temp.t4 USING csv_wr( + data= +'1,2,3,4 +5,6,7,8 +9,10,11,12 +13,14,15,16', + columns=4, + schema= + 'CREATE TABLE t3(a,b,c,d,PRIMARY KEY(a,b)) WITHOUT ROWID', + testflags=1 + ); +} {1 {bad schema: 'CREATE TABLE t3(a,b,c,d,PRIMARY KEY(a,b)) WITHOUT ROWID' - not an error}} + +# WITHOUT ROWID tables with a single-column PRIMARY KEY may be writable. +do_catchsql_test 4.1 { + DROP TABLE IF EXISTS t4; + CREATE VIRTUAL TABLE temp.t4 USING csv_wr( + data= +'1,2,3,4 +5,6,7,8 +9,10,11,12 +13,14,15,16', + columns=4, + schema= + 'CREATE TABLE t3(a,b,c,d,PRIMARY KEY(b)) WITHOUT ROWID', + testflags=1 + ); +} {0 {}} + +do_catchsql_test 4.2 { + DROP TABLE IF EXISTS t5; + CREATE VIRTUAL TABLE temp.t5 USING csv_wr( + data= + '1,2,3,4 + 5,6,7,8 + 9,10,11,12 + 13,14,15,16', + columns=4, + schema= + 'CREATE TABLE t3(a,b,c,d) WITHOUT ROWID', + testflags=1 + ); +} {1 {bad schema: 'CREATE TABLE t3(a,b,c,d) WITHOUT ROWID' - PRIMARY KEY missing on table t3}} + +# 2018-04-24 +# Memory leak reported on the sqlite-users mailing list by Ralf Junker. +# +do_catchsql_test 4.3 { + CREATE VIRTUAL TABLE IF NOT EXISTS temp.t1 + USING csv(filename='FileDoesNotExist.csv'); +} {1 {cannot open 'FileDoesNotExist.csv' for reading}} + +# 2018-06-02 +# Problem with single-column CSV support reported on the mailing list +# by Trent W. Buck. +# +do_execsql_test 4.4 { + CREATE VIRTUAL TABLE temp.trent USING csv(data='1'); + SELECT * FROM trent; +} {1} + +# 2018-12-26 +# Bug report on the mailing list +# +forcedelete csv01.csv +set fd [open csv01.csv wb] +puts $fd "a,b,c,d\r\n1,2,3,4\r\none,two,three,four\r\n5,6,7,8" +close $fd +do_execsql_test 5.1 { + CREATE VIRTUAL TABLE t5_1 USING csv(filename='csv01.csv'); + SELECT name FROM temp.pragma_table_info('t5_1'); +} {c0 c1 c2 c3} +do_execsql_test 5.2 { + SELECT *, '|' FROM t5_1; +} {a b c d | 1 2 3 4 | one two three four | 5 6 7 8 |} +do_execsql_test 5.3 { + DROP TABLE t5_1; + CREATE VIRTUAL TABLE t5_1 USING csv(filename='csv01.csv', header); + SELECT name FROM temp.pragma_table_info('t5_1'); +} {a b c d} +do_execsql_test 5.4 { + SELECT *, '|' FROM t5_1; +} {1 2 3 4 | one two three four | 5 6 7 8 |} + +#------------------------------------------------------------------------- + +proc randomtext {n} { + string range [db one {SELECT hex(randomblob($n))}] 1 $n +} + +for {set ii 0} {$ii < 200} {incr ii} { + reset_db + load_static_extension db csv + set fd [open csv.data w] + puts $fd "a,b" + puts $fd "[randomtext $ii],abcd" + close $fd + do_execsql_test 6.$ii.1 { + CREATE VIRTUAL TABLE abc USING csv(filename='csv.data', header=true); + } + do_execsql_test 6.$ii.2 { + SELECT count(*) FROM abc + } 1 +} + +for {set ii 0} {$ii < 20} {incr ii} { + reset_db + load_static_extension db csv + set T [randomtext $ii] + set fd [open csv.data w] + puts $fd "a,b" + puts -nonewline $fd "abcd,$T" + close $fd + do_execsql_test 7.$ii.1 { + CREATE VIRTUAL TABLE abc USING csv(filename='csv.data', header=true); + } + breakpoint + do_execsql_test 7.$ii.2 { + SELECT * FROM abc + } [list abcd $T] +} + + +finish_test diff --git a/test/ctime.test b/test/ctime.test new file mode 100644 index 0000000..26b2fa2 --- /dev/null +++ b/test/ctime.test @@ -0,0 +1,259 @@ +# 2009 February 24 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests for the compile time diagnostic +# functions. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Test organization: +# +# ctime-1.*: Test pragma support. +# ctime-2.*: Test function support. +# + +ifcapable !pragma||!compileoption_diags { + finish_test + return +} + +##################### +# ctime-1.*: Test pragma support. + +do_test ctime-1.1.1 { + catchsql { + PRAGMA compile_options(); + } +} {1 {near ")": syntax error}} +do_test ctime-1.1.2 { + catchsql { + PRAGMA compile_options(NULL); + } +} {1 {near "NULL": syntax error}} +do_test ctime-1.1.3 { + catchsql { + PRAGMA compile_options *; + } +} {1 {near "*": syntax error}} + +do_test ctime-1.2.1 { + set ans [ catchsql { + PRAGMA compile_options; + } ] + list [ lindex $ans 0 ] +} {0} +# the results should be in sorted order already +do_test ctime-1.2.2 { + set ans [ catchsql { + PRAGMA compile_options; + } ] + list [ lindex $ans 0 ] [ expr { [lsort [lindex $ans 1]]==[lindex $ans 1] } ] +} {0 1} + +# Check the THREADSAFE option for SQLITE_THREADSAFE=2 builds (there are +# a couple of these configurations in releasetest.tcl). +# +ifcapable threadsafe2 { + foreach {tn opt res} { + 1 SQLITE_THREADSAFE 1 + 2 THREADSAFE 1 + 3 THREADSAFE=0 0 + 4 THREADSAFE=1 0 + 5 THREADSAFE=2 1 + 6 THREADSAFE= 0 + } { + do_execsql_test ctime-1.3.$tn { + SELECT sqlite_compileoption_used($opt) + } $res + } +} + +# SQLITE_THREADSAFE should pretty much always be defined +# one way or the other, and it must have a value of 0 or 1. +sqlite3_db_config db SQLITE_DBCONFIG_DQS_DML 1 +do_test ctime-1.4.1 { + catchsql { + SELECT sqlite_compileoption_used('SQLITE_THREADSAFE'); + } +} {0 1} +do_test ctime-1.4.2 { + catchsql { + SELECT sqlite_compileoption_used('THREADSAFE'); + } +} {0 1} +do_test ctime-1.4.3 { + catchsql { + SELECT sqlite_compileoption_used("THREADSAFE"); + } +} {0 1} + +do_test ctime-1.5 { + set ans1 [ catchsql { + SELECT sqlite_compileoption_used('THREADSAFE=0'); + } ] + set ans2 [ catchsql { + SELECT sqlite_compileoption_used('THREADSAFE=1'); + } ] + set ans3 [ catchsql { + SELECT sqlite_compileoption_used('THREADSAFE=2'); + } ] + lsort [ list $ans1 $ans2 $ans3 ] +} {{0 0} {0 0} {0 1}} + +do_test ctime-1.6 { + execsql { + SELECT sqlite_compileoption_used('THREADSAFE='); + } +} {0} + +do_test ctime-1.7.1 { + execsql { + SELECT sqlite_compileoption_used('SQLITE_OMIT_COMPILEOPTION_DIAGS'); + } +} {0} +do_test ctime-1.7.2 { + execsql { + SELECT sqlite_compileoption_used('OMIT_COMPILEOPTION_DIAGS'); + } +} {0} + +##################### +# ctime-2.*: Test function support. + +do_test ctime-2.1.1 { + catchsql { + SELECT sqlite_compileoption_used(); + } +} {1 {wrong number of arguments to function sqlite_compileoption_used()}} +do_test ctime-2.1.2 { + catchsql { + SELECT sqlite_compileoption_used(NULL); + } +} {0 {{}}} +do_test ctime-2.1.3 { + catchsql { + SELECT sqlite_compileoption_used(""); + } +} {0 0} +do_test ctime-2.1.4 { + catchsql { + SELECT sqlite_compileoption_used(''); + } +} {0 0} +do_test ctime-2.1.5 { + catchsql { + SELECT sqlite_compileoption_used(foo); + } +} {1 {no such column: foo}} +do_test ctime-2.1.6 { + catchsql { + SELECT sqlite_compileoption_used('THREADSAFE', 0); + } +} {1 {wrong number of arguments to function sqlite_compileoption_used()}} +do_test ctime-2.1.7 { + catchsql { + SELECT sqlite_compileoption_used(0); + } +} {0 0} +do_test ctime-2.1.8 { + catchsql { + SELECT sqlite_compileoption_used('0'); + } +} {0 0} +do_test ctime-2.1.9 { + catchsql { + SELECT sqlite_compileoption_used(1.0); + } +} {0 0} + +do_test ctime-2.2.1 { + catchsql { + SELECT sqlite_compileoption_get(); + } +} {1 {wrong number of arguments to function sqlite_compileoption_get()}} +do_test ctime-2.2.2 { + catchsql { + SELECT sqlite_compileoption_get(0, 0); + } +} {1 {wrong number of arguments to function sqlite_compileoption_get()}} + +# This assumes there is at least 1 compile time option +# (see SQLITE_THREADSAFE above). +do_test ctime-2.3 { + catchsql { + SELECT sqlite_compileoption_used(sqlite_compileoption_get(0)); + } +} {0 1} + +# This assumes there is at least 1 compile time option +# (see SQLITE_THREADSAFE above). +do_test ctime-2.4 { + set ans [ catchsql { + SELECT sqlite_compileoption_get(0); + } ] + list [lindex $ans 0] +} {0} + +# Get the list of defines using the pragma, +# then try querying each one with the functions. +set ans [ catchsql { + PRAGMA compile_options; +} ] +set opts [ lindex $ans 1 ] +set tc 1 +foreach opt $opts { + do_test ctime-2.5.$tc { + set N [ expr {$tc-1} ] + set ans1 [catch {db one { + SELECT sqlite_compileoption_get($N); + }} msg] + lappend ans1 $msg + set ans2 [ catchsql { + SELECT sqlite_compileoption_used($opt); + } ] + list [ lindex $ans1 0 ] [ expr { [lindex $ans1 1]==$opt } ] \ + [ expr { $ans2 } ] + } {0 1 {0 1}} + incr tc 1 +} +# test 1 past array bounds +do_test ctime-2.5.$tc { + set N [ expr {$tc-1} ] + set ans [ catchsql { + SELECT sqlite_compileoption_get($N); + } ] +} {0 {{}}} +incr tc 1 +# test 1 before array bounds (N=-1) +do_test ctime-2.5.$tc { + set N -1 + set ans [ catchsql { + SELECT sqlite_compileoption_get($N); + } ] +} {0 {{}}} + +#-------------------------------------------------------------------------- +# Test that SQLITE_DIRECT_OVERFLOW_READ is reflected in the output of +# "PRAGMA compile_options". +# +ifcapable direct_read { + set res 1 +} else { + set res 0 +} +do_test ctime-3.0.1 { + expr [lsearch [db eval {PRAGMA compile_options}] DIRECT_OVERFLOW_READ]>=0 +} $res + +finish_test diff --git a/test/cursorhint.test b/test/cursorhint.test new file mode 100644 index 0000000..d1bd4e8 --- /dev/null +++ b/test/cursorhint.test @@ -0,0 +1,214 @@ +# 2014 July 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix cursorhint + +ifcapable !cursorhints { + finish_test + return +} + +do_execsql_test 1.0 { + CREATE TABLE t1(a,b,c,d); + CREATE TABLE t2(x,y,z); + INSERT INTO t1(a,b) VALUES(10, 15); + INSERT INTO t1(a,b) VALUES(20, 25); + INSERT INTO t2(x,y) VALUES('ten', 'fifteen'); + INSERT INTO t2(x,y) VALUES('twenty', 'twentyfive'); + CREATE TABLE t3(id TEXT PRIMARY KEY, a, b, c, d) WITHOUT ROWID; + INSERT INTO t3(id,a,b,c,d) SELECT rowid, a, b, c, d FROM t1; + PRAGMA automatic_index = 0; +} + +# Run EXPLAIN on $sql. Return a list of P4 values for all $opcode +# opcodes. +# +proc p4_of_opcode {db opcode sql} { + set res {} + $db eval "EXPLAIN $sql" x { + if {$x(opcode)==$opcode} {lappend res $x(p4)} + } + return $res +} + +# Run EXPLAIN on $sql. Return a list of P5 values for all $opcode +# opcodes that contain regexp $comment in their comment +# +proc p5_of_opcode {db opcode sql} { + set res {} + $db eval "EXPLAIN $sql" x { + if {$x(opcode)==$opcode} { + lappend res $x(p5) + } + } + return $res +} + +# Verify that when t1 is in the outer loop and t2 is in the inner loop, +# no cursor hints occur for t1 (since it is a full table scan) but that +# each t2 access has a cursor hint based on the current t1.a value. +# +do_test 1.1 { + p4_of_opcode db CursorHint { + SELECT * FROM t1 CROSS JOIN t2 WHERE a=x + } +} {{EQ(r[1],c0)}} +do_test 1.2 { + p5_of_opcode db OpenRead { + SELECT * FROM t1 CROSS JOIN t2 WHERE a=x + } +} {0 0} + +# Do the same test the other way around. +# +do_test 2.1 { + p4_of_opcode db CursorHint { + SELECT * FROM t2 CROSS JOIN t1 WHERE a=x + } +} {{EQ(c0,r[1])}} +do_test 2.2 { + p5_of_opcode db OpenRead { + SELECT * FROM t2 CROSS JOIN t1 WHERE a=x + } +} {0 0} + +# Various expressions captured by CursorHint +# +do_test 3.1 { + p4_of_opcode db CursorHint { + SELECT * FROM t1 WHERE a=15 AND c=22 AND rowid!=98 + } +} {AND(AND(EQ(c0,15),EQ(c2,22)),NE(rowid,98))} +do_test 3.2 { + p4_of_opcode db CursorHint { + SELECT * FROM t3 WHERE a<15 AND b>22 AND id!=98 + } +} {AND(AND(LT(c1,15),GT(c2,22)),NE(c0,98))} + +# Indexed queries +# +do_test 4.1asc { + db eval { + CREATE INDEX t1bc ON t1(b,c); + CREATE INDEX t2yz ON t2(y,z); + } + p4_of_opcode db CursorHint { + SELECT * FROM t1 WHERE b>11 ORDER BY b ASC; + } +} {} +do_test 4.1desc { + p4_of_opcode db CursorHint { + SELECT * FROM t1 WHERE b>11 ORDER BY b DESC; + } +} {GT(c0,11)} +do_test 4.2 { + p5_of_opcode db OpenRead { + SELECT * FROM t1 WHERE b>11; + } +} {2 0} +do_test 4.3asc { + p4_of_opcode db CursorHint { + SELECT c FROM t1 WHERE b<11 ORDER BY b ASC; + } +} {LT(c0,11)} +do_test 4.3desc { + p4_of_opcode db CursorHint { + SELECT c FROM t1 WHERE b<11 ORDER BY b DESC; + } +} {} +do_test 4.4 { + p5_of_opcode db OpenRead { + SELECT c FROM t1 WHERE b<11; + } +} {0} + +do_test 4.5asc { + p4_of_opcode db CursorHint { + SELECT c FROM t1 WHERE b>=10 AND b<=20 ORDER BY b ASC; + } +} {LE(c0,20)} +do_test 4.5desc { + p4_of_opcode db CursorHint { + SELECT c FROM t1 WHERE b>=10 AND b<=20 ORDER BY b DESC; + } +} {GE(c0,10)} + +# If there are any equality terms used in the constraint, then all terms +# should be hinted. +# +do_test 4.6asc { + p4_of_opcode db CursorHint { + SELECT rowid FROM t1 WHERE b=22 AND c>=10 AND c<=20 ORDER BY b,c ASC; + } +} {AND(AND(EQ(c0,22),GE(c1,10)),LE(c1,20))} +do_test 4.6desc { + p4_of_opcode db CursorHint { + SELECT rowid FROM t1 WHERE b=22 AND c>=10 AND c<=20 ORDER BY b,c DESC; + } +} {AND(AND(EQ(c0,22),GE(c1,10)),LE(c1,20))} + +# 2023-03-24 https://sqlite.org/forum/forumpost/591006b1cc +# +reset_db +do_execsql_test 5.0 { + CREATE TABLE t1(x TEXT PRIMARY KEY) WITHOUT ROWID; + CREATE VIEW t2 AS SELECT 0 FROM t1 WHERE x>='a' OR x='1'; + SELECT * FROM t2 RIGHT JOIN t1 ON true; +} +# Additional test case from https://sqlite.org/forum/forumpost/d34ad68c36?t=c +# which is a different way to acces the same problem. +# +do_execsql_test 5.1 { + CREATE TABLE v1 (c1, PRIMARY KEY( c1 )) WITHOUT ROWID; + CREATE VIEW v2 AS SELECT 0 FROM v1 WHERE c1 IS '' OR c1 > ''; + CREATE VIEW v3 AS SELECT 0 FROM v2 JOIN (v2 RIGHT JOIN v1); + CREATE VIEW v4 AS SELECT 0 FROM v3, v3; + SELECT * FROM v3 JOIN v3 AS a0, v4 AS a1, v4 AS a2, v3 AS a3, + v3 AS a4, v4 AS a5 + ORDER BY 1; +} + +# 2023-04-10 https://sqlite.org/forum/forumpost/0b53708c95 +# +do_execsql_test 6.0 { + CREATE TABLE t6(a TEXT UNIQUE, b TEXT); + INSERT INTO t6(a,b) VALUES('uvw','xyz'),('abc','def'); + WITH v1(a) AS (SELECT a COLLATE NOCASE FROM t6) + SELECT v1.a, count(*) FROM t6 LEFT JOIN v1 ON true + GROUP BY 1 + HAVING (SELECT true FROM t6 AS aa LEFT JOIN t6 AS bb ON length(v1.a)>5); +} {abc 2 uvw 2} + + +# 2023-05-04 https://sqlite.org/forum/forumpost/29a47cf6d1 +# +# codeCursorHint() should not walk expressions that have been optimized +# out and converted to TRUE or FALSE. This only comes up when compiling +# with SQLITE_ENABLE_CURSOR_HINTS +# +reset_db +do_execsql_test 7.1 { + CREATE TABLE t1(a INT PRIMARY KEY) WITHOUT ROWID; + CREATE TABLE t2(b INT PRIMARY KEY) WITHOUT ROWID; + CREATE TABLE t3(c INT PRIMARY KEY) WITHOUT ROWID; + INSERT INTO t1(a) VALUES(1),(2); + INSERT INTO t2(b) VALUES(4),(8); + INSERT INTO t3(c) VALUES(16),(32); + CREATE VIEW v4(d) AS SELECT c FROM t3; + SELECT * FROM t1 RIGHT JOIN t2 ON true JOIN v4 ON (d IS NULL); +} {} + + +finish_test diff --git a/test/cursorhint2.test b/test/cursorhint2.test new file mode 100644 index 0000000..a78d151 --- /dev/null +++ b/test/cursorhint2.test @@ -0,0 +1,204 @@ +# 2016 June 17 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus is on testing that cursor-hints are correct for queries +# involving LEFT JOIN. +# + + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix cursorhint2 + +ifcapable !cursorhints { + finish_test + return +} + +proc extract_hints {sql} { + + db eval "SELECT tbl_name, rootpage FROM sqlite_master where rootpage" { + set lookup($rootpage) $tbl_name + } + + set ret [list] + db eval "EXPLAIN $sql" a { + switch -- $a(opcode) { + OpenRead { + set csr($a(p1)) $lookup($a(p2)) + } + CursorHint { + lappend ret $csr($a(p1)) $a(p4) + } + } + } + + set ret +} + +proc do_extract_hints_test {tn sql ret} { + uplevel [list do_test $tn [list extract_hints $sql] [list {*}$ret]] +} + +do_execsql_test 1.0 { + PRAGMA automatic_index = 0; + CREATE TABLE t1(a, b); + CREATE TABLE t2(c, d); + CREATE TABLE t3(e, f); +} + +do_extract_hints_test 1.1 { + SELECT * FROM t1 WHERE a=1; +} { + t1 EQ(c0,1) +} + +do_extract_hints_test 1.2 { + SELECT * FROM t1 CROSS JOIN t2 ON (a=c) WHERE d IS NULL; +} { + t2 {AND(ISNULL(c1),EQ(r[1],c0))} +} + +do_extract_hints_test 1.3 { + SELECT * FROM t1 LEFT JOIN t2 ON (a=c) WHERE d IS NULL; +} { + t2 {EQ(r[2],c0)} +} + +do_extract_hints_test 1.4 { + SELECT * FROM t1 LEFT JOIN t2 ON (a=c AND a=10) WHERE d IS NULL; +} { + t2 {AND(EQ(r[2],c0),EQ(r[3],10))} +} + +do_extract_hints_test 1.5 { + SELECT * FROM t1 CROSS JOIN t2 ON (a=c AND a=10) WHERE d IS NULL; +} { + t1 EQ(c0,10) t2 {AND(ISNULL(c1),EQ(r[3],c0))} +} + +do_extract_hints_test 1.6 { + SELECT * FROM t1 LEFT JOIN t2 ON (a=c) LEFT JOIN t3 ON (d=f); +} { + t2 {EQ(r[2],c0)} t3 {EQ(r[6],c1)} +} + +if 0 { + do_extract_hints_test 1.7 { + SELECT * FROM t1 LEFT JOIN t2 ON (a=c AND d=e) LEFT JOIN t3 ON (d=f); + } { + t2 {EQ(r[2],c0)} t3 {AND(EQ(r[6],c0),EQ(r[7],c1))} + } +} + +#------------------------------------------------------------------------- +# +do_execsql_test 2.0 { + CREATE TABLE x1(x, y); + CREATE TABLE x2(a, b); +} + +do_extract_hints_test 2.1 { + SELECT * FROM x1 LEFT JOIN x2 ON (a=x) WHERE b IS NULL; +} { + x2 {EQ(c0,r[2])} +} + +do_extract_hints_test 2.2 { + SELECT * FROM x1 LEFT JOIN x2 ON (a=x) WHERE b IS +NULL; +} { + x2 {EQ(c0,r[2])} +} + +do_extract_hints_test 2.3 { + SELECT * FROM x1 LEFT JOIN x2 ON (a=x) WHERE 1 = (b IS NULL) +} { + x2 {EQ(c0,r[2])} +} + +do_extract_hints_test 2.4 { + SELECT * FROM x1 LEFT JOIN x2 ON (a=x) WHERE 1 = coalesce(b, 1) +} { + x2 {EQ(c0,r[2])} +} + +do_extract_hints_test 2.5 { + SELECT * FROM x1 LEFT JOIN x2 ON (a=x) WHERE 1 = coalesce(b, 1) +} { + x2 {EQ(c0,r[2])} +} + +if {0} { + # These tests no longer work due to the LEFT-JOIN strength reduction + # optimization + do_extract_hints_test 2.6 { + SELECT * FROM x1 CROSS JOIN x2 ON (a=x) WHERE 0 = (b IS NOT NULL) + } { + x2 {EQ(c0,r[2])} + } + + do_extract_hints_test 2.7 { + SELECT * FROM x1 LEFT JOIN x2 ON (a=x) WHERE 0 = (b IS NOT +NULL) + } { + x2 {EQ(c0,r[2])} + } + + do_extract_hints_test 2.8 { + SELECT * FROM x1 LEFT JOIN x2 ON (a=x) WHERE b IS NOT +NULL + } { + x2 {EQ(c0,r[2])} + } + + do_extract_hints_test 2.9 { + SELECT * FROM x1 LEFT JOIN x2 ON (a=x) + WHERE CASE b WHEN 0 THEN 0 ELSE 1 END; + } { + x2 {EQ(c0,r[2])} + } + + do_extract_hints_test 2.10 { + SELECT * FROM x1 LEFT JOIN x2 ON (a=x) WHERE x2.b = 32+32 + } { + x2 {AND(EQ(c1,ADD(32,32)),EQ(c0,r[2]))} + } + + ifcapable !icu { + # This test only works using the built-in LIKE, not the ICU LIKE extension. + do_extract_hints_test 2.11 { + SELECT * FROM x1 LEFT JOIN x2 ON (a=x) WHERE x2.b LIKE 'abc%' + } { + x2 {AND(expr,EQ(c0,r[2]))} + } + } +} + +do_extract_hints_test 2.12 { + SELECT * FROM x1 LEFT JOIN x2 ON (a=x) WHERE coalesce(x2.b, 1) +} { + x2 {EQ(c0,r[2])} +} + +reset_db +do_execsql_test 3.0 { + CREATE TABLE t1 (i1 TEXT); + CREATE TABLE t2 (i2 TEXT UNIQUE); + INSERT INTO t1 VALUES('0'); + INSERT INTO t2 VALUES('0'); +} + +do_extract_hints_test 3.1 { + SELECT * FROM t1 CROSS JOIN t2 WHERE (t1.i1 = t2.i2) AND t2.i2 = 1; +} { + t1 {EQ(c0,r[1])} t2 EQ(c0,1) +} + + +finish_test diff --git a/test/dataversion1.test b/test/dataversion1.test new file mode 100644 index 0000000..55f7aad --- /dev/null +++ b/test/dataversion1.test @@ -0,0 +1,87 @@ +# 2018-07-18 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Test case for SQLITE_FCNTL_DATA_VERSION +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Construct a database and get its initial data version +sqlite3 db test.db +do_test dataversion1-100 { + db eval { + CREATE TABLE t1(x); + INSERT INTO t1(x) VALUES(99); + SELECT * FROM t1; + } +} {99} +set dv1 [file_control_data_version db main] + +# The data version does not change by ATTACH or by changes to +# other schemas within the same connection. +# +do_test dataversion1-101 { + db eval { + ATTACH ':memory:' AS aux1; + CREATE TABLE aux1.t2(y); + CREATE TEMP TABLE t3(z); + } + file_control_data_version db main +} $dv1 + +# The data version does change when SQL modifies the table +do_test dataversion1-110 { + db eval { + UPDATE t1 SET x=x+1; + } + set dv2 [file_control_data_version db] + expr {$::dv1==$dv2} +} {0} + +# But the data version is constant if there are changes to other +# schemas +set dv1 [file_control_data_version db main] +do_test dataversion1-120 { + db eval { + UPDATE t2 SET y=y+1; + } + file_control_data_version db +} $dv1 + +# Changes to the database via another connection are not detected +# until there is a read transaction. +# +sqlite3 db2 test.db +do_test dataversion1-130 { + db2 eval { + SELECT * FROM t1 + } +} {100} +do_test dataversion1-131 { + file_control_data_version db +} $dv1 +do_test dataversion1-132 { + db2 eval { + UPDATE t1 SET x=x+1; + } + set dv2 [file_control_data_version db] + expr {$::dv1==$dv2} +} {1} +do_test dataversion1-133 { + db eval {SELECT * FROM t1} + set dv2 [file_control_data_version db] + expr {$::dv1==$dv2} +} {0} + + + +finish_test diff --git a/test/date.test b/test/date.test new file mode 100644 index 0000000..19cecc2 --- /dev/null +++ b/test/date.test @@ -0,0 +1,576 @@ +# 2003 October 31 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing date and time functions. +# +# $Id: date.test,v 1.34 2009/04/16 12:58:03 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +# Skip this whole file if date and time functions are omitted +# at compile-time +# +ifcapable {!datetime} { + finish_test + return +} + +proc datetest {tnum expr result} { + do_test date-$tnum [subst { + execsql "SELECT coalesce($expr,'NULL')" + }] [list $result] +} +set tcl_precision 15 +datetest 1.1 julianday('2000-01-01') 2451544.5 +datetest 1.2 julianday('1970-01-01') 2440587.5 +datetest 1.3 julianday('1910-04-20') 2418781.5 +datetest 1.4 julianday('1986-02-09') 2446470.5 +datetest 1.5 julianday('12:00:00') 2451545.0 +datetest 1.6 {julianday('2000-01-01 12:00:00')} 2451545.0 +datetest 1.7 {julianday('2000-01-01 12:00')} 2451545.0 +datetest 1.8 julianday('bogus') NULL +datetest 1.9 julianday('1999-12-31') 2451543.5 +datetest 1.10 julianday('1999-12-32') NULL +datetest 1.11 julianday('1999-13-01') NULL +datetest 1.12 julianday('2003-02-31') 2452701.5 +datetest 1.13 julianday('2003-03-03') 2452701.5 +datetest 1.14 julianday('+2000-01-01') NULL +datetest 1.15 julianday('200-01-01') NULL +datetest 1.16 julianday('2000-1-01') NULL +datetest 1.17 julianday('2000-01-1') NULL +datetest 1.18.1 {julianday('2000-01-01 12:00:00')} 2451545.0 +datetest 1.18.2 {julianday('2000-01-01T12:00:00')} 2451545.0 +datetest 1.18.3 {julianday('2000-01-01 T12:00:00')} 2451545.0 +datetest 1.18.4 {julianday('2000-01-01T 12:00:00')} 2451545.0 +datetest 1.18.4 {julianday('2000-01-01 T 12:00:00')} 2451545.0 +datetest 1.19 {julianday('2000-01-01 12:00:00.1')} 2451545.00000116 +datetest 1.20 {julianday('2000-01-01 12:00:00.01')} 2451545.00000012 +datetest 1.21 {julianday('2000-01-01 12:00:00.001')} 2451545.00000001 +datetest 1.22 {julianday('2000-01-01 12:00:00.')} NULL +datetest 1.23 julianday(12345.6) 12345.6 +datetest 1.23b julianday(1721059.5) 1721059.5 +datetest 1.24 {julianday('2001-01-01 12:00:00 bogus')} NULL +datetest 1.25 {julianday('2001-01-01 bogus')} NULL +datetest 1.26 {julianday('2001-01-01 12:60:00')} NULL +datetest 1.27 {julianday('2001-01-01 12:59:60')} NULL +datetest 1.28 {julianday('2001-00-01')} NULL +datetest 1.29 {julianday('2001-01-00')} NULL + +datetest 2.1 datetime(0,'unixepoch') {1970-01-01 00:00:00} +datetest 2.1b datetime(0,'unixepoc') NULL +datetest 2.1c datetime(0,'unixepochx') NULL +datetest 2.1d datetime('2003-10-22','unixepoch') NULL +datetest 2.2 datetime(946684800,'unixepoch') {2000-01-01 00:00:00} +datetest 2.2b datetime('946684800','unixepoch') {2000-01-01 00:00:00} +for {set i 0} {$i<1000} {incr i} { + set sql [format {strftime('%%H:%%M:%%f',1237962480.%03d,'unixepoch')} $i] + set res [format {06:28:00.%03d} $i] + datetest 2.2c-$i $sql $res +} +datetest 2.3 {date('2003-10-22','weekday 0')} 2003-10-26 +datetest 2.4 {date('2003-10-22','weekday 1')} 2003-10-27 +datetest 2.4a {date('2003-10-22','weekday 1')} 2003-10-27 +datetest 2.4b {date('2003-10-22','weekday 1x')} NULL +datetest 2.4c {date('2003-10-22','weekday -1')} NULL +datetest 2.4d {date('2003-10-22','weakday 1x')} NULL +datetest 2.4e {date('2003-10-22','weekday ')} NULL +datetest 2.5 {date('2003-10-22','weekday 2')} 2003-10-28 +datetest 2.6 {date('2003-10-22','weekday 3')} 2003-10-22 +datetest 2.7 {date('2003-10-22','weekday 4')} 2003-10-23 +datetest 2.8 {date('2003-10-22','weekday 5')} 2003-10-24 +datetest 2.9 {date('2003-10-22','weekday 6')} 2003-10-25 +datetest 2.10 {date('2003-10-22','weekday 7')} NULL +datetest 2.11 {date('2003-10-22','weekday 5.5')} NULL +datetest 2.12 {datetime('2003-10-22 12:34','weekday 0')} {2003-10-26 12:34:00} +datetest 2.13 {datetime('2003-10-22 12:34','start of month')} \ + {2003-10-01 00:00:00} +datetest 2.14 {datetime('2003-10-22 12:34','start of year')} \ + {2003-01-01 00:00:00} +datetest 2.15 {datetime('2003-10-22 12:34','start of day')} \ + {2003-10-22 00:00:00} +datetest 2.15a {datetime('2003-10-22 12:34','start of')} NULL +datetest 2.15b {datetime('2003-10-22 12:34','start of bogus')} NULL +datetest 2.16 time('12:34:56.43') 12:34:56 +datetest 2.17 {datetime('2003-10-22 12:34','1 day')} {2003-10-23 12:34:00} +datetest 2.18 {datetime('2003-10-22 12:34','+1 day')} {2003-10-23 12:34:00} +datetest 2.19 {datetime('2003-10-22 12:34','+1.25 day')} {2003-10-23 18:34:00} +datetest 2.20 {datetime('2003-10-22 12:34','-1.0 day')} {2003-10-21 12:34:00} +datetest 2.21 {datetime('2003-10-22 12:34','1 month')} {2003-11-22 12:34:00} +datetest 2.22 {datetime('2003-10-22 12:34','11 month')} {2004-09-22 12:34:00} +datetest 2.23 {datetime('2003-10-22 12:34','-13 month')} {2002-09-22 12:34:00} +datetest 2.24 {datetime('2003-10-22 12:34','1.5 months')} {2003-12-07 12:34:00} +datetest 2.25 {datetime('2003-10-22 12:34','-5 years')} {1998-10-22 12:34:00} +datetest 2.26 {datetime('2003-10-22 12:34','+10.5 minutes')} \ + {2003-10-22 12:44:30} +datetest 2.27 {datetime('2003-10-22 12:34','-1.25 hours')} \ + {2003-10-22 11:19:00} +datetest 2.28 {datetime('2003-10-22 12:34','11.25 seconds')} \ + {2003-10-22 12:34:11} +datetest 2.29 {datetime('2003-10-22 12:24','+5 bogus')} NULL +datetest 2.30 {datetime('2003-10-22 12:24','+++')} NULL +datetest 2.31 {datetime('2003-10-22 12:24','+12.3e4 femtoseconds')} NULL +datetest 2.32 {datetime('2003-10-22 12:24','+12.3e4 uS')} NULL +datetest 2.33 {datetime('2003-10-22 12:24','+1 abc')} NULL +datetest 2.34 {datetime('2003-10-22 12:24','+1 abcd')} NULL +datetest 2.35 {datetime('2003-10-22 12:24','+1 abcde')} NULL +datetest 2.36 {datetime('2003-10-22 12:24','+1 abcdef')} NULL +datetest 2.37 {datetime('2003-10-22 12:24','+1 abcdefg')} NULL +datetest 2.38 {datetime('2003-10-22 12:24','+1 abcdefgh')} NULL +datetest 2.39 {datetime('2003-10-22 12:24','+1 abcdefghi')} NULL +set sqlite_current_time 1199243045 +datetest 2.40 {datetime()} {2008-01-02 03:04:05} +set sqlite_current_time 0 +datetest 2.41 {datetime('2003-10-22 12:24','23 seconds')} {2003-10-22 12:24:23} +datetest 2.42 {datetime('2003-10-22 12:24','345 second')} {2003-10-22 12:29:45} +datetest 2.43 {datetime('2003-10-22 12:24','4 second')} {2003-10-22 12:24:04} +datetest 2.44 {datetime('2003-10-22 12:24','56 second')} {2003-10-22 12:24:56} +datetest 2.45 {datetime('2003-10-22 12:24','60 second')} {2003-10-22 12:25:00} +datetest 2.46 {datetime('2003-10-22 12:24','70 second')} {2003-10-22 12:25:10} +datetest 2.47 {datetime('2003-10-22 12:24','8.6 seconds')} {2003-10-22 12:24:08} +datetest 2.48 {datetime('2003-10-22 12:24','9.4 second')} {2003-10-22 12:24:09} +datetest 2.49 {datetime('2003-10-22 12:24','0000 second')} {2003-10-22 12:24:00} +datetest 2.50 {datetime('2003-10-22 12:24','0001 second')} {2003-10-22 12:24:01} +datetest 2.51 {datetime('2003-10-22 12:24','nonsense')} NULL + +datetest 2.60 {datetime('2023-02-31')} {2023-03-03 00:00:00} + +datetest 3.1 {strftime('%d','2003-10-31 12:34:56.432')} 31 +datetest 3.2.1 {strftime('pre%fpost','2003-10-31 12:34:56.432')} pre56.432post +datetest 3.2.2 {strftime('%f','2003-10-31 12:34:59.9999999')} 59.999 +datetest 3.3 {strftime('%H','2003-10-31 12:34:56.432')} 12 +datetest 3.4 {strftime('%j','2003-10-31 12:34:56.432')} 304 +datetest 3.5 {strftime('%J','2003-10-31 12:34:56.432')} 2452944.024264259 +datetest 3.6 {strftime('%m','2003-10-31 12:34:56.432')} 10 +datetest 3.7 {strftime('%M','2003-10-31 12:34:56.432')} 34 +datetest 3.8.1 {strftime('%s','2003-10-31 12:34:56.432')} 1067603696 +datetest 3.8.2 {strftime('%s','2038-01-19 03:14:07')} 2147483647 +datetest 3.8.3 {strftime('%s','2038-01-19 03:14:08')} 2147483648 +datetest 3.8.4 {strftime('%s','2201-04-09 12:00:00')} 7298164800 +datetest 3.8.5 {strftime('%s','9999-12-31 23:59:59')} 253402300799 +datetest 3.8.6 {strftime('%s','1969-12-31 23:59:59')} -1 +datetest 3.8.7 {strftime('%s','1901-12-13 20:45:52')} -2147483648 +datetest 3.8.8 {strftime('%s','1901-12-13 20:45:51')} -2147483649 +datetest 3.8.9 {strftime('%s','1776-07-04 00:00:00')} -6106060800 +datetest 3.9 {strftime('%S','2003-10-31 12:34:56.432')} 56 +datetest 3.10 {strftime('%w','2003-10-31 12:34:56.432')} 5 +datetest 3.11.1 {strftime('%W','2003-10-31 12:34:56.432')} 43 +datetest 3.11.2 {strftime('%W','2004-01-01')} 00 +datetest 3.11.3 {strftime('%W','2004-01-02')} 00 +datetest 3.11.4 {strftime('%W','2004-01-03')} 00 +datetest 3.11.5 {strftime('abc%Wxyz','2004-01-04')} abc00xyz +datetest 3.11.6 {strftime('%W','2004-01-05')} 01 +datetest 3.11.7 {strftime('%W','2004-01-06')} 01 +datetest 3.11.8 {strftime('%W','2004-01-07')} 01 +datetest 3.11.9 {strftime('%W','2004-01-08')} 01 +datetest 3.11.10 {strftime('%W','2004-01-09')} 01 +datetest 3.11.11 {strftime('%W','2004-07-18')} 28 +datetest 3.11.12 {strftime('%W','2004-12-31')} 52 +datetest 3.11.13 {strftime('%W','2007-12-31')} 53 +datetest 3.11.14 {strftime('%W','2007-01-01')} 01 +datetest 3.11.15 {strftime('%W %j',2454109.04140970)} {02 008} +datetest 3.11.16 {strftime('%W %j',2454109.04140971)} {02 008} +datetest 3.11.17 {strftime('%W %j',2454109.04140972)} {02 008} +datetest 3.11.18 {strftime('%W %j',2454109.04140973)} {02 008} +datetest 3.11.19 {strftime('%W %j',2454109.04140974)} {02 008} +datetest 3.11.20 {strftime('%W %j',2454109.04140975)} {02 008} +datetest 3.11.21 {strftime('%W %j',2454109.04140976)} {02 008} +datetest 3.11.22 {strftime('%W %j',2454109.04140977)} {02 008} +datetest 3.11.23 {strftime('%W %j',2454109.04140978)} {02 008} +datetest 3.11.24 {strftime('%W %j',2454109.04140979)} {02 008} +datetest 3.11.25 {strftime('%W %j',2454109.04140980)} {02 008} +datetest 3.11.99 {strftime('%W %j','2454109.04140970')} {02 008} +datetest 3.12 {strftime('%Y','2003-10-31 12:34:56.432')} 2003 +datetest 3.13 {strftime('%%','2003-10-31 12:34:56.432')} % +datetest 3.14 {strftime('%_','2003-10-31 12:34:56.432')} NULL +datetest 3.15 {strftime('%Y-%m-%d','2003-10-31')} 2003-10-31 +proc repeat {n txt} { + set x {} + while {$n>0} { + append x $txt + incr n -1 + } + return $x +} +datetest 3.16 "strftime('[repeat 200 %Y]','2003-10-31')" [repeat 200 2003] +datetest 3.17 "strftime('[repeat 200 abc%m123]','2003-10-31')" \ + [repeat 200 abc10123] + +foreach c {a b c g h i n o q r t v x y z + A B C D E G K L N O Q V Z + 0 1 2 3 4 5 6 6 7 9 _} { + datetest 3.18.$c "strftime('%$c','2003-10-31')" NULL +} +datetest 3.20 {strftime('%e','2023-08-09')} { 9} +datetest 3.21 {strftime('%F %T','2023-08-09 01:23')} {2023-08-09 01:23:00} +datetest 3.22 {strftime('%k','2023-08-09 04:59:59')} { 4} +datetest 3.23 {strftime('%I%P','2023-08-09 11:59:59')} {11am} +datetest 3.24 {strftime('%I%p','2023-08-09 12:00:00')} {12PM} +datetest 3.25 {strftime('%I%P','2023-08-09 12:59:59.9')} {12pm} +datetest 3.26 {strftime('%I%p','2023-08-09 13:00:00')} {01PM} +datetest 3.27 {strftime('%I%P','2023-08-09 23:59:59')} {11pm} +datetest 3.28 {strftime('%I%p','2023-08-09 00:00:00')} {12AM} +datetest 3.29 {strftime('%l:%M%P','2023-08-09 13:00:00')} { 1:00pm} +datetest 3.30 {strftime('%F %R','2023-08-09 12:34:56')} {2023-08-09 12:34} +datetest 3.31 {strftime('%w %u','2023-01-01')} {0 7} +datetest 3.32 {strftime('%w %u','2023-01-02')} {1 1} +datetest 3.33 {strftime('%w %u','2023-01-03')} {2 2} +datetest 3.34 {strftime('%w %u','2023-01-04')} {3 3} +datetest 3.35 {strftime('%w %u','2023-01-05')} {4 4} +datetest 3.36 {strftime('%w %u','2023-01-06')} {5 5} +datetest 3.37 {strftime('%w %u','2023-01-07')} {6 6} + +# Ticket #2276. Make sure leading zeros are inserted where appropriate. +# +datetest 3.40 \ + {strftime('%d/%f/%H/%W/%j/%m/%M/%S/%Y','0421-01-02 03:04:05.006')} \ + 02/05.006/03/00/002/01/04/05/0421 + +set sqlite_current_time 1157124367 +datetest 4.1 {date('now')} {2006-09-01} +set sqlite_current_time 0 + +datetest 5.1 {datetime('1994-04-16 14:00:00 +05:00')} {1994-04-16 09:00:00} +datetest 5.2 {datetime('1994-04-16 14:00:00 -05:15')} {1994-04-16 19:15:00} +datetest 5.3 {datetime('1994-04-16 05:00:00 +08:30')} {1994-04-15 20:30:00} +datetest 5.4 {datetime('1994-04-16 14:00:00 -11:55')} {1994-04-17 01:55:00} +datetest 5.5 {datetime('1994-04-16 14:00:00 -11:60')} NULL +datetest 5.6 {datetime('1994-04-16 14:00:00 -11:55 ')} {1994-04-17 01:55:00} +datetest 5.7 {datetime('1994-04-16 14:00:00 -11:55 x')} NULL +datetest 5.8 {datetime('1994-04-16T14:00:00Z')} {1994-04-16 14:00:00} +datetest 5.9 {datetime('1994-04-16 14:00:00z')} {1994-04-16 14:00:00} +datetest 5.10 {datetime('1994-04-16 14:00:00 Z')} {1994-04-16 14:00:00} +datetest 5.11 {datetime('1994-04-16 14:00:00z ')} {1994-04-16 14:00:00} +datetest 5.12 {datetime('1994-04-16 14:00:00 z ')} {1994-04-16 14:00:00} +datetest 5.13 {datetime('1994-04-16 14:00:00Zulu')} NULL +datetest 5.14 {datetime('1994-04-16 14:00:00Z +05:00')} NULL +datetest 5.15 {datetime('1994-04-16 14:00:00 +05:00 Z')} NULL + +# localtime->utc and utc->localtime conversions. +# +# Use SQLITE_TESTCTRL_LOCALTIME_FAULT=2 to set an alternative localtime_r() +# implementation that is not locale-dependent. This testing localtime_r() +# operates as follows: +# +# (1) Localtime is 30 minutes earlier than (west of) UTC on +# even days (counting from 1970-01-01) +# +# (2) Localtime is 30 minutes later than (east of) UTC on odd days. +# +# (3) The function fails for the specific date/time value +# of 2000-05-29 14:16:00 in order to test the ability of +# SQLite to deal with localtime_r() failures. +# +proc local_to_utc {tn utc local} { + do_execsql_test date-$tn "SELECT datetime('$utc','localtime')" [list $local] +} +proc utc_to_local {tn local utc} { + do_execsql_test date-$tn "SELECT datetime('$local','utc')" [list $utc] +} + +sqlite3_test_control SQLITE_TESTCTRL_LOCALTIME_FAULT 2 +local_to_utc 6.1 {2000-10-29 12:00:00} {2000-10-29 12:30:00} +utc_to_local 6.2 {2000-10-29 12:30:00} {2000-10-29 12:00:00} +local_to_utc 6.3 {2000-10-30 12:00:00} {2000-10-30 11:30:00} +utc_to_local 6.4 {2000-10-30 11:30:00} {2000-10-30 12:00:00} + +local_to_utc 6.5 {2000-10-28 23:59:59} {2000-10-28 23:29:59} +local_to_utc 6.6 {2000-10-29 00:00:00} {2000-10-29 00:30:00} + +# The previous two cases establish that no such localtime as +# 2000-10-29 00:10:00 exists. Verify that we get a reasonable +# answer if we try to convert this non-existant localtime to utc? +# +utc_to_local 6.7 {2000-10-29 00:10:00} {2000-10-28 23:40:00} + +local_to_utc 6.8 {2022-02-10 23:59:59} {2022-02-11 00:29:59} +local_to_utc 6.9 {2022-02-11 00:00:00} {2022-02-10 23:30:00} +local_to_utc 6.10 {2022-02-10 23:45:00} {2022-02-11 00:15:00} +local_to_utc 6.11 {2022-02-11 00:45:00} {2022-02-11 00:15:00} + +# The previous two cases show that two different UTC values give +# the same localtime of 2022-02-11 00:15:00. When converting from +# that localtime back to UTC, we should get one or the other of +# the two UTC values. +# +utc_to_local 6.12 {2022-02-11 00:15:00} {2022-02-11 00:45:00} + +# If localtime_r() fails, the datetime() SQL function should raise an error +# +do_catchsql_test date-6.20 { + SELECT datetime('2000-05-29 14:16:00','localtime'); +} {1 {local time unavailable}} + +# Modifiers work for dates that are way out of band for localtime_r() +# +local_to_utc 6.21 {1800-10-29 12:00:00} {1800-10-29 12:30:00} +utc_to_local 6.22 {1800-10-29 12:30:00} {1800-10-29 12:00:00} +local_to_utc 6.23 {3000-10-30 12:00:00} {3000-10-30 11:30:00} +utc_to_local 6.24 {3000-10-30 11:30:00} {3000-10-30 12:00:00} + +# Restore the use of the OS localtime_r() before going on... +sqlite3_test_control SQLITE_TESTCTRL_LOCALTIME_FAULT 0 + +# Date-time functions that contain NULL arguments return a NULL +# result. +# +datetest 7.1 {datetime(null)} NULL +datetest 7.2 {datetime('now',null)} NULL +datetest 7.3 {datetime('now','localtime',null)} NULL +datetest 7.4 {time(null)} NULL +datetest 7.5 {time('now',null)} NULL +datetest 7.6 {time('now','localtime',null)} NULL +datetest 7.7 {date(null)} NULL +datetest 7.8 {date('now',null)} NULL +datetest 7.9 {date('now','localtime',null)} NULL +datetest 7.10 {julianday(null)} NULL +datetest 7.11 {julianday('now',null)} NULL +datetest 7.12 {julianday('now','localtime',null)} NULL +datetest 7.13 {strftime(null,'now')} NULL +datetest 7.14 {strftime('%s',null)} NULL +datetest 7.15 {strftime('%s','now',null)} NULL +datetest 7.16 {strftime('%s','now','localtime',null)} NULL + +# Test modifiers when the date begins as a julian day number - to +# make sure the HH:MM:SS is preserved. Ticket #551. +# +set sqlite_current_time [db eval {SELECT strftime('%s','2003-10-22 12:34:00')}] +datetest 8.1 {datetime('now','weekday 0')} {2003-10-26 12:34:00} +datetest 8.2 {datetime('now','weekday 1')} {2003-10-27 12:34:00} +datetest 8.3 {datetime('now','weekday 2')} {2003-10-28 12:34:00} +datetest 8.4 {datetime('now','weekday 3')} {2003-10-22 12:34:00} +datetest 8.5 {datetime('now','start of month')} {2003-10-01 00:00:00} +datetest 8.6 {datetime('now','start of year')} {2003-01-01 00:00:00} +datetest 8.7 {datetime('now','start of day')} {2003-10-22 00:00:00} +datetest 8.8 {datetime('now','1 day')} {2003-10-23 12:34:00} +datetest 8.9 {datetime('now','+1 day')} {2003-10-23 12:34:00} +datetest 8.10 {datetime('now','+1.25 day')} {2003-10-23 18:34:00} +datetest 8.11 {datetime('now','-1.0 day')} {2003-10-21 12:34:00} +datetest 8.12 {datetime('now','1 month')} {2003-11-22 12:34:00} +datetest 8.13 {datetime('now','11 month')} {2004-09-22 12:34:00} +datetest 8.14 {datetime('now','-13 month')} {2002-09-22 12:34:00} +datetest 8.15 {datetime('now','1.5 months')} {2003-12-07 12:34:00} +datetest 8.16 {datetime('now','-5 years')} {1998-10-22 12:34:00} +datetest 8.17 {datetime('now','+10.5 minutes')} {2003-10-22 12:44:30} +datetest 8.18 {datetime('now','-1.25 hours')} {2003-10-22 11:19:00} +datetest 8.19 {datetime('now','11.25 seconds')} {2003-10-22 12:34:11} +datetest 8.90 {datetime('now','abcdefghijklmnopqrstuvwyxzABCDEFGHIJLMNOP')} NULL +set sqlite_current_time 0 + +# Negative years work. Example: '-4713-11-26' is JD 1.5. +# +datetest 9.1 {julianday('-4713-11-24 12:00:00')} {0.0} +datetest 9.2 {julianday(datetime(5))} {5.0} +datetest 9.3 {julianday(datetime(10))} {10.0} +datetest 9.4 {julianday(datetime(100))} {100.0} +datetest 9.5 {julianday(datetime(1000))} {1000.0} +datetest 9.6 {julianday(datetime(10000))} {10000.0} +datetest 9.7 {julianday(datetime(100000))} {100000.0} + +# datetime() with just an HH:MM:SS correctly inserts the date 2000-01-01. +# +datetest 10.1 {datetime('01:02:03')} {2000-01-01 01:02:03} +datetest 10.2 {date('01:02:03')} {2000-01-01} +datetest 10.3 {strftime('%Y-%m-%d %H:%M','01:02:03')} {2000-01-01 01:02} + +# Test the new HH:MM:SS modifier +# +datetest 11.1 {datetime('2004-02-28 20:00:00', '-01:20:30')} \ + {2004-02-28 18:39:30} +datetest 11.2 {datetime('2004-02-28 20:00:00', '+12:30:00')} \ + {2004-02-29 08:30:00} +datetest 11.3 {datetime('2004-02-28 20:00:00', '+12:30')} \ + {2004-02-29 08:30:00} +datetest 11.4 {datetime('2004-02-28 20:00:00', '12:30')} \ + {2004-02-29 08:30:00} +datetest 11.5 {datetime('2004-02-28 20:00:00', '-12:00')} \ + {2004-02-28 08:00:00} +datetest 11.6 {datetime('2004-02-28 20:00:00', '-12:01')} \ + {2004-02-28 07:59:00} +datetest 11.7 {datetime('2004-02-28 20:00:00', '-11:59')} \ + {2004-02-28 08:01:00} +datetest 11.8 {datetime('2004-02-28 20:00:00', '11:59')} \ + {2004-02-29 07:59:00} +datetest 11.9 {datetime('2004-02-28 20:00:00', '12:01')} \ + {2004-02-29 08:01:00} +datetest 11.10 {datetime('2004-02-28 20:00:00', '12:60')} NULL + +# Ticket #1964 +datetest 12.1 {datetime('2005-09-01')} {2005-09-01 00:00:00} +datetest 12.2 {datetime('2005-09-01','+0 hours')} {2005-09-01 00:00:00} + +# Ticket #1991 +do_test date-13.1 { + execsql { + SELECT strftime('%Y-%m-%d %H:%M:%f', julianday('2006-09-24T10:50:26.047')) + } +} {{2006-09-24 10:50:26.047}} + +# Ticket #2153 +datetest 13.2 {strftime('%Y-%m-%d %H:%M:%S', '2007-01-01 12:34:59.6')} \ + {2007-01-01 12:34:59} +datetest 13.3 {strftime('%Y-%m-%d %H:%M:%f', '2007-01-01 12:34:59.6')} \ + {2007-01-01 12:34:59.600} +datetest 13.4 {strftime('%Y-%m-%d %H:%M:%S', '2007-01-01 12:59:59.6')} \ + {2007-01-01 12:59:59} +datetest 13.5 {strftime('%Y-%m-%d %H:%M:%f', '2007-01-01 12:59:59.6')} \ + {2007-01-01 12:59:59.600} +datetest 13.6 {strftime('%Y-%m-%d %H:%M:%S', '2007-01-01 23:59:59.6')} \ + {2007-01-01 23:59:59} +datetest 13.7 {strftime('%Y-%m-%d %H:%M:%f', '2007-01-01 23:59:59.6')} \ + {2007-01-01 23:59:59.600} + +# Ticket #3618 +datetest 13.11 {julianday(2454832.5,'-1 day')} {2454831.5} +datetest 13.12 {julianday(2454832.5,'+1 day')} {2454833.5} +datetest 13.13 {julianday(2454832.5,'-1.5 day')} {2454831.0} +datetest 13.14 {julianday(2454832.5,'+1.5 day')} {2454834.0} +datetest 13.15 {julianday(2454832.5,'-3 hours')} {2454832.375} +datetest 13.16 {julianday(2454832.5,'+3 hours')} {2454832.625} +datetest 13.17 {julianday(2454832.5,'-45 minutes')} {2454832.46875} +datetest 13.18 {julianday(2454832.5,'+45 minutes')} {2454832.53125} +datetest 13.19 {julianday(2454832.5,'-675 seconds')} {2454832.4921875} +datetest 13.20 {julianday(2454832.5,'+675 seconds')} {2454832.5078125} +datetest 13.21 {julianday(2454832.5,'-1.5 months')} {2454786.5} +datetest 13.22 {julianday(2454832.5,'+1.5 months')} {2454878.5} +datetest 13.23 {julianday(2454832.5,'-1.5 years')} {2454284.0} +datetest 13.24 {julianday(2454832.5,'+1.5 years')} {2455380.0} + +datetest 13.30 {date('2000-01-01','+1.5 years')} {2001-07-02} +datetest 13.31 {date('2001-01-01','+1.5 years')} {2002-07-02} +datetest 13.32 {date('2002-01-01','+1.5 years')} {2003-07-02} +datetest 13.33 {date('2002-01-01','-1.5 years')} {2000-07-02} +datetest 13.34 {date('2001-01-01','-1.5 years')} {1999-07-02} +datetest 13.35 {date('2023-02-28')} {2023-02-28} +datetest 13.36 {date('2023-02-29')} {2023-03-01} +datetest 13.37 {date('2023-04-31')} {2023-05-01} + +# Test for issues reported by BareFeet (list.sql at tandb.com.au) +# on mailing list on 2008-06-12. +# +# Put a floating point number in the database so that we can manipulate +# raw bits using the hexio interface. +# +if {0==[sqlite3 -has-codec]} { + do_test date-14.1 { + execsql { + PRAGMA auto_vacuum=OFF; + PRAGMA page_size = 1024; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(1.1); + } + db close + hexio_write test.db 2040 4142ba32bffffff9 + sqlite3 db test.db + db eval {SELECT * FROM t1} + } {2454629.5} + + # Changing the least significant byte of the floating point value between + # 00 and FF should always generate a time of either 23:59:59 or 00:00:00, + # never 24:00:00 + # + for {set i 0} {$i<=255} {incr i} { + db close + hexio_write test.db 2047 [format %02x $i] + sqlite3 db test.db + do_test date-14.2.$i { + set date [db one {SELECT datetime(x) FROM t1}] + expr {$date eq "2008-06-12 00:00:00" || $date eq "2008-06-11 23:59:59"} + } {1} + } +} + +# Verify that multiple calls to date functions with 'now' return the +# same answer. +# +# EVIDENCE-OF: R-34818-13664 The 'now' argument to date and time +# functions always returns exactly the same value for multiple +# invocations within the same sqlite3_step() call. +# +proc sleeper {} {after 100} +do_test date-15.1 { + db func sleeper sleeper + db eval { + SELECT c - a FROM (SELECT julianday('now') AS a, + sleeper(), julianday('now') AS c); + } +} {0.0} +do_test date-15.2 { + db eval { + SELECT a==b FROM (SELECT current_timestamp AS a, + sleeper(), current_timestamp AS b); + } +} {1} + +# Tests of extreme values in date/time functions. Run with UBSan or the +# equivalent to verify no signed interger overflow warnings. +# +datetest 16.1 {date(147483649)} NULL +datetest 16.2 {datetime(0)} {-4713-11-24 12:00:00} +datetest 16.3 {datetime(5373484.49999999)} {9999-12-31 23:59:59} +datetest 16.4 {julianday('-4713-11-24 12:00:00')} 0.0 +datetest 16.5 {julianday('9999-12-31 23:59:59.999')} 5373484.49999999 +datetest 16.6 {datetime(0,'+464269060799 seconds')} {9999-12-31 23:59:59} +datetest 16.7 {datetime(0,'+464269060800 seconds')} NULL +datetest 16.8 {datetime(0,'+7737817679 minutes')} {9999-12-31 23:59:00} +datetest 16.9 {datetime(0,'+7737817680 minutes')} NULL +datetest 16.10 {datetime(0,'+128963627 hours')} {9999-12-31 23:00:00} +datetest 16.11 {datetime(0,'+128963628 hours')} NULL +datetest 16.12 {datetime(0,'+5373484 days')} {9999-12-31 12:00:00} +datetest 16.13 {datetime(0,'+5373485 days')} NULL +datetest 16.14 {datetime(0,'+176545 months')} {9999-12-24 12:00:00} +datetest 16.15 {datetime(0,'+176546 months')} NULL +datetest 16.16 {datetime(0,'+14712 years')} {9999-11-24 12:00:00} +datetest 16.17 {datetime(0,'+14713 years')} NULL +datetest 16.20 {datetime(5373484.4999999,'-464269060799 seconds')} \ + {-4713-11-24 12:00:00} +datetest 16.21 {datetime(5373484,'-464269060800 seconds')} NULL +datetest 16.22 {datetime(5373484.4999999,'-7737817679 minutes')} \ + {-4713-11-24 12:00:59} +datetest 16.23 {datetime(5373484,'-7737817680 minutes')} NULL +datetest 16.24 {datetime(5373484.4999999,'-128963627 hours')} \ + {-4713-11-24 12:59:59} +datetest 16.25 {datetime(5373484,'-128963628 hours')} NULL +datetest 16.26 {datetime(5373484,'-5373484 days')} {-4713-11-24 12:00:00} +datetest 16.27 {datetime(5373484,'-5373485 days')} NULL +datetest 16.28 {datetime(5373484,'-176545 months')} {-4713-12-01 12:00:00} +datetest 16.29 {datetime(5373484,'-176546 months')} NULL +datetest 16.30 {datetime(5373484,'-14712 years')} {-4713-12-31 12:00:00} +datetest 16.31 {datetime(5373484,'-14713 years')} NULL + +# 2017-03-02: Wrong 'start of day' computation. +# https://www.sqlite.org/src/info/6097cb92745327a1 +# +datetest 17.1 {datetime(2457754, 'start of day')} {2016-12-31 00:00:00} +datetest 17.2 {datetime(2457828)} {2017-03-15 12:00:00} +datetest 17.3 {datetime(2457828,'start of day')} {2017-03-15 00:00:00} +datetest 17.4 {datetime(2457828,'start of month')} {2017-03-01 00:00:00} +datetest 17.5 {datetime(2457828,'start of year')} {2017-01-01 00:00:00} +datetest 17.6 {datetime(37,'start of year')} NULL +datetest 17.7 {datetime(38,'start of year')} {-4712-01-01 00:00:00} + +# 2022-03-04 https://sqlite.org/forum/forumpost/2ffbaa2c3fd7fb82 +# The 'localtime' modifier should preserve fractional seconds. +# +datetest 18.1 {strftime('%f',1.234,'unixepoch','localtime')} {01.234} + +# 2023-04 The 'subsecond' (or 'subsec') modifier alters resolutions +# to at least milliseconds. Added for release 3.42.0 . +datetest 18.2 {unixepoch('1970-01-01T00:00:00.1', 'subsec')} {0.1} +datetest 18.3 {unixepoch('1970-01-01T00:00:00.2', 'subsecond')} {0.2} +datetest 18.4 {julianday('-4713-11-24 13:40:48.864', 'subsec')} {0.07001} +datetest 18.5 {typeof(unixepoch('now', 'subsecond'))} {real} +finish_test diff --git a/test/date2.test b/test/date2.test new file mode 100644 index 0000000..a16e25c --- /dev/null +++ b/test/date2.test @@ -0,0 +1,176 @@ +# 2017-07-20 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing date and time functions used in +# check constraints and index expressions. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Skip this whole file if date and time functions are omitted +# at compile-time +# +ifcapable {!datetime} { + finish_test + return +} + +do_execsql_test date2-100 { + CREATE TABLE t1(x, y, CHECK( date(x) BETWEEN '2017-07-01' AND '2017-07-31' )); + INSERT INTO t1(x,y) VALUES('2017-07-20','one'); +} {} +do_catchsql_test date2-110 { + INSERT INTO t1(x,y) VALUES('now','two'); +} {1 {non-deterministic use of date() in a CHECK constraint}} +do_execsql_test date2-120 { + SELECT * FROM t1; +} {2017-07-20 one} +do_catchsql_test date2-130 { + INSERT INTO t1(x,y) VALUES('2017-08-01','two'); +} {1 {CHECK constraint failed: date(x) BETWEEN '2017-07-01' AND '2017-07-31'}} + +# 2021-03-16 Forum post https://sqlite.org/forum/forumpost/464afd4086 +do_catchsql_test date2-140 { + DROP TABLE t1; + CREATE TABLE t1(x, y, z AS (date())); + INSERT INTO t1(x,y) VALUES(1,2); +} {1 {non-deterministic use of date() in a generated column}} + +do_execsql_test date2-200 { + CREATE TABLE t2(x,y); + INSERT INTO t2(x,y) VALUES(1, '2017-07-20'), (2, 'xyzzy'); + CREATE INDEX t2y ON t2(date(y)); +} +do_catchsql_test date2-210 { + INSERT INTO t2(x,y) VALUES(3, 'now'); +} {1 {non-deterministic use of date() in an index}} +do_execsql_test date2-220 { + SELECT x, y FROM t2 ORDER BY x; +} {1 2017-07-20 2 xyzzy} + +do_execsql_test date2-300 { + CREATE TABLE t3(a INTEGER PRIMARY KEY,b); + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<1000) + INSERT INTO t3(a,b) SELECT x, julianday('2017-07-01')+x FROM c; + UPDATE t3 SET b='now' WHERE a=500; +} +do_catchsql_test date2-310 { + CREATE INDEX t3b1 ON t3(datetime(b)); +} {1 {non-deterministic use of datetime() in an index}} +do_catchsql_test date2-320 { + CREATE INDEX t3b1 ON t3(datetime(b)) WHERE typeof(b)='real'; +} {0 {}} +do_execsql_test date2-330 { + EXPLAIN QUERY PLAN + SELECT a FROM t3 + WHERE typeof(b)='real' + AND datetime(b) BETWEEN '2017-07-04' AND '2017-07-08'; +} {/USING INDEX t3b/} +do_execsql_test date2-331 { + SELECT a FROM t3 + WHERE typeof(b)='real' + AND datetime(b) BETWEEN '2017-07-04' AND '2017-07-08' + ORDER BY a; +} {3 4 5 6} + +do_execsql_test date2-400 { + CREATE TABLE t4(a INTEGER PRIMARY KEY,b); + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<1000) + INSERT INTO t4(a,b) SELECT x, julianday('2017-07-01')+x FROM c; + UPDATE t4 SET b='now' WHERE a=500; +} +do_catchsql_test date2-410 { + CREATE INDEX t4b1 ON t4(b) + WHERE date(b) BETWEEN '2017-06-01' AND '2017-08-31'; +} {1 {non-deterministic use of date() in an index}} +do_execsql_test date2-420 { + DELETE FROM t4 WHERE a=500; + CREATE INDEX t4b1 ON t4(b) + WHERE date(b) BETWEEN '2017-06-01' AND '2017-08-31'; +} +do_catchsql_test date2-430 { + INSERT INTO t4(a,b) VALUES(9999,'now'); +} {1 {non-deterministic use of date() in an index}} + +do_execsql_test date2-500 { + CREATE TABLE mods(x); + INSERT INTO mods(x) VALUES + ('+10 days'), + ('-10 days'), + ('+10 hours'), + ('-10 hours'), + ('+10 minutes'), + ('-10 minutes'), + ('+10 seconds'), + ('-10 seconds'), + ('+10 months'), + ('-10 months'), + ('+10 years'), + ('-10 years'), + ('start of month'), + ('start of year'), + ('start of day'), + ('weekday 1'), + ('unixepoch'); + CREATE TABLE t5(y,m); + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<5) + INSERT INTO t5(y,m) SELECT julianday('2017-07-01')+c.x, mods.x FROM c, mods; + CREATE INDEX t5x1 on t5(y) WHERE datetime(y,m) IS NOT NULL; +} +do_catchsql_test date2-510 { + INSERT INTO t5(y,m) VALUES('2017-07-20','localtime'); +} {1 {non-deterministic use of datetime() in an index}} +do_catchsql_test date2-520 { + INSERT INTO t5(y,m) VALUES('2017-07-20','utc'); +} {1 {non-deterministic use of datetime() in an index}} + +# 2019-10-30 Ticket 830277d9db6c3ba1 +# +do_catchsql_test date2-600 { + CREATE TABLE t600(a REAL CHECK( a datetime(unixepoch('1970-01-01',format('%+d days',x)),'auto'); +} {63} + +finish_test diff --git a/test/date4.test b/test/date4.test new file mode 100644 index 0000000..0d820a0 --- /dev/null +++ b/test/date4.test @@ -0,0 +1,38 @@ +# 2023-08-29 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Test cases for the strftime() SQL function. Comparisons against the +# C-library strftime() function. + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Skip this whole file if date and time functions are omitted +# at compile-time +# +ifcapable {!datetime} { + finish_test + return +} + +if {$tcl_platform(os)=="Linux"} { + set FMT {%d,%e,%F,%H,%k,%I,%l,%j,%m,%M,%u,%w,%W,%Y,%%,%P,%p} +} else { + set FMT {%d,%e,%F,%H,%I,%j,%p,%R,%u,%w,%W,%%} +} +for {set i 0} {$i<=24854} {incr i} { + set TS [expr {$i*86401}] + do_execsql_test date4-$i { + SELECT strftime($::FMT,$::TS,'unixepoch'); + } [list [strftime $FMT $TS]] +} + +finish_test diff --git a/test/dbdata.test b/test/dbdata.test new file mode 100644 index 0000000..5b1150c --- /dev/null +++ b/test/dbdata.test @@ -0,0 +1,115 @@ +# 2019-04-11 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing the sqlite_dbpage virtual table. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix dbdata + +ifcapable !vtab||!compound { + finish_test + return +} +if { [catch { db enable_load_extension 1 }] + || [catch { db eval { SELECT load_extension('../dbdata') } }] +} { + finish_test + return +} + +do_execsql_test 1.0 { + CREATE TABLE T1(a, b); + INSERT INTO t1(rowid, a ,b) VALUES(5, 'v', 'five'); + INSERT INTO t1(rowid, a, b) VALUES(10, 'x', 'ten'); +} + +do_execsql_test 1.1 { + SELECT pgno, cell, field, quote(value) FROM sqlite_dbdata WHERE pgno=2; +} { + 2 0 -1 5 + 2 0 0 'v' + 2 0 1 'five' + 2 1 -1 10 + 2 1 0 'x' + 2 1 1 'ten' +} + +breakpoint +do_execsql_test 1.2 { + SELECT pgno, cell, field, quote(value) FROM sqlite_dbdata; +} { + 1 0 -1 1 + 1 0 0 'table' + 1 0 1 'T1' + 1 0 2 'T1' + 1 0 3 2 + 1 0 4 {'CREATE TABLE T1(a, b)'} + 2 0 -1 5 + 2 0 0 'v' + 2 0 1 'five' + 2 1 -1 10 + 2 1 0 'x' + 2 1 1 'ten' +} + +set big [string repeat big 2000] +do_execsql_test 1.3 { + INSERT INTO t1 VALUES(NULL, $big); + SELECT value FROM sqlite_dbdata WHERE pgno=2 AND cell=2 AND field=1; +} $big + +do_execsql_test 1.4 { + DELETE FROM t1; + INSERT INTO t1 VALUES(NULL, randomblob(5050)); +} +do_test 1.5 { + execsql { + SELECT quote(value) FROM sqlite_dbdata WHERE pgno=2 AND cell=0 AND field=1; + } +} [db one {SELECT quote(b) FROM t1}] + +#------------------------------------------------------------------------- +reset_db +db enable_load_extension 1 +db eval { SELECT load_extension('../dbdata') } + +do_execsql_test 2.0 { + CREATE TABLE t1(a); + CREATE INDEX i1 ON t1(a); + WITH s(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<10 + ) + INSERT INTO t1 SELECT randomblob(900) FROM s; +} + +do_execsql_test 2.1 { + SELECT * FROM sqlite_dbptr WHERE pgno=2; +} { + 2 25 2 6 2 7 2 9 2 11 2 13 2 15 2 17 2 19 2 21 +} + +do_execsql_test 2.2 { + SELECT * FROM sqlite_dbptr WHERE pgno=3; +} { + 3 24 3 23 +} + +do_execsql_test 2.3 { + SELECT * FROM sqlite_dbptr +} { + 2 25 2 6 2 7 2 9 2 11 2 13 2 15 2 17 2 19 2 21 + 3 24 3 23 +} + + +finish_test diff --git a/test/dbfuzz.c b/test/dbfuzz.c new file mode 100644 index 0000000..ca1c6ea --- /dev/null +++ b/test/dbfuzz.c @@ -0,0 +1,754 @@ +/* +** 2016-12-17 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +************************************************************************* +** +** This program is designed for fuzz-testing SQLite database files. +** +** This program reads fuzzed database files from the disk files named +** on the command-line. Each database is loaded into an in-memory +** filesystem so that the original database file is unmolested. +** +** The fuzzed database is then opened, and series of SQL statements +** are run against the database to ensure that SQLite can safely handle +** the fuzzed database. +*/ +#include +#include +#include +#include +#include +#include +#define ISSPACE(X) isspace((unsigned char)(X)) +#define ISDIGIT(X) isdigit((unsigned char)(X)) +#include "sqlite3.h" +#ifdef __unix__ +# include +# include +#endif + +/* +** Print sketchy documentation for this utility program +*/ +static void showHelp(const char *zArgv0){ + printf("Usage: %s [options] DATABASE ...\n", zArgv0); + printf( +"Read databases into an in-memory filesystem. Run test SQL as specified\n" +"by command-line arguments or from\n" +"\n" +" SELECT group_concat(sql) FROM autoexec;\n" +"\n" +"Options:\n" +" --help Show this help text\n" +" -q|--quiet Reduced output\n" +" --limit-mem N Limit memory used by test SQLite instances to N bytes\n" +" --limit-vdbe Panic if any test runs for more than 100,000 cycles\n" +" --no-lookaside Disable the lookaside memory allocator\n" +" --timeout N Timeout after N seconds.\n" +" --trace Show the results of each SQL command\n" +" -v|--verbose Increased output. Repeat for more output.\n" + ); + exit(0); +} + +/* +** Print an error message and quit. +*/ +static void fatalError(const char *zFormat, ...){ + va_list ap; + va_start(ap, zFormat); + vfprintf(stderr, zFormat, ap); + va_end(ap); + fprintf(stderr, "\n"); + exit(1); +} + +/* +** Files in the virtual file system. +*/ +typedef struct VFile VFile; +typedef struct VHandle VHandle; +struct VFile { + char *zFilename; /* Filename. NULL for delete-on-close. From malloc() */ + int sz; /* Size of the file in bytes */ + int nRef; /* Number of references to this file */ + unsigned char *a; /* Content of the file. From malloc() */ +}; +struct VHandle { + sqlite3_file base; /* Base class. Must be first */ + VFile *pVFile; /* The underlying file */ +}; + +/* +** Maximum number of files in the in-memory virtual filesystem. +*/ +#define MX_FILE 10 + +/* +** Maximum allowed file size +*/ +#define MX_FILE_SZ 1000000 + +/* +** All global variables are gathered into the "g" singleton. +*/ +static struct GlobalVars { + VFile aFile[MX_FILE]; /* The virtual filesystem */ +} g; + + +/* +** Initialize the virtual file system. +*/ +static void formatVfs(void){ + int i; + for(i=0; i0 ){ + fatalError("file %d still open. nRef=%d", i, g.aFile[i].nRef); + } + g.aFile[i].sz = -1; + free(g.aFile[i].a); + g.aFile[i].a = 0; + g.aFile[i].nRef = 0; + } +} + +/* +** Find a VFile by name +*/ +static VFile *findVFile(const char *zName){ + int i; + if( zName==0 ) return 0; + for(i=0; i=0; i++){} + if( i>=MX_FILE ) return 0; + if( zDiskFile ){ + in = fopen(zDiskFile, "rb"); + if( in==0 ) fatalError("no such file: \"%s\"", zDiskFile); + fseek(in, 0, SEEK_END); + sz = ftell(in); + rewind(in); + } + pNew = &g.aFile[i]; + if( zName ){ + int nName = (int)strlen(zName)+1; + pNew->zFilename = malloc(nName); + if( pNew->zFilename==0 ){ + if( in ) fclose(in); + return 0; + } + memcpy(pNew->zFilename, zName, nName); + }else{ + pNew->zFilename = 0; + } + pNew->nRef = 0; + pNew->sz = sz; + pNew->a = malloc(sz); + if( sz>0 ){ + if( pNew->a==0 || fread(pNew->a, sz, 1, in)<1 ){ + free(pNew->zFilename); + free(pNew->a); + pNew->a = 0; + pNew->zFilename = 0; + pNew->sz = -1; + pNew = 0; + } + } + if( in ) fclose(in); + return pNew; +} + +/* Methods for the VHandle object +*/ +static int inmemClose(sqlite3_file *pFile){ + VHandle *p = (VHandle*)pFile; + VFile *pVFile = p->pVFile; + pVFile->nRef--; + if( pVFile->nRef==0 && pVFile->zFilename==0 ){ + pVFile->sz = -1; + free(pVFile->a); + pVFile->a = 0; + } + return SQLITE_OK; +} +static int inmemRead( + sqlite3_file *pFile, /* Read from this open file */ + void *pData, /* Store content in this buffer */ + int iAmt, /* Bytes of content */ + sqlite3_int64 iOfst /* Start reading here */ +){ + VHandle *pHandle = (VHandle*)pFile; + VFile *pVFile = pHandle->pVFile; + if( iOfst<0 || iOfst>=pVFile->sz ){ + memset(pData, 0, iAmt); + return SQLITE_IOERR_SHORT_READ; + } + if( iOfst+iAmt>pVFile->sz ){ + memset(pData, 0, iAmt); + iAmt = (int)(pVFile->sz - iOfst); + memcpy(pData, pVFile->a, iAmt); + return SQLITE_IOERR_SHORT_READ; + } + memcpy(pData, pVFile->a + iOfst, iAmt); + return SQLITE_OK; +} +static int inmemWrite( + sqlite3_file *pFile, /* Write to this file */ + const void *pData, /* Content to write */ + int iAmt, /* bytes to write */ + sqlite3_int64 iOfst /* Start writing here */ +){ + VHandle *pHandle = (VHandle*)pFile; + VFile *pVFile = pHandle->pVFile; + if( iOfst+iAmt > pVFile->sz ){ + unsigned char *aNew; + if( iOfst+iAmt >= MX_FILE_SZ ){ + return SQLITE_FULL; + } + aNew = realloc(pVFile->a, (int)(iOfst+iAmt)); + if( aNew==0 ){ + return SQLITE_FULL; + } + pVFile->a = aNew; + if( iOfst > pVFile->sz ){ + memset(pVFile->a + pVFile->sz, 0, (int)(iOfst - pVFile->sz)); + } + pVFile->sz = (int)(iOfst + iAmt); + } + memcpy(pVFile->a + iOfst, pData, iAmt); + return SQLITE_OK; +} +static int inmemTruncate(sqlite3_file *pFile, sqlite3_int64 iSize){ + VHandle *pHandle = (VHandle*)pFile; + VFile *pVFile = pHandle->pVFile; + if( pVFile->sz>iSize && iSize>=0 ) pVFile->sz = (int)iSize; + return SQLITE_OK; +} +static int inmemSync(sqlite3_file *pFile, int flags){ + return SQLITE_OK; +} +static int inmemFileSize(sqlite3_file *pFile, sqlite3_int64 *pSize){ + *pSize = ((VHandle*)pFile)->pVFile->sz; + return SQLITE_OK; +} +static int inmemLock(sqlite3_file *pFile, int type){ + return SQLITE_OK; +} +static int inmemUnlock(sqlite3_file *pFile, int type){ + return SQLITE_OK; +} +static int inmemCheckReservedLock(sqlite3_file *pFile, int *pOut){ + *pOut = 0; + return SQLITE_OK; +} +static int inmemFileControl(sqlite3_file *pFile, int op, void *pArg){ + return SQLITE_NOTFOUND; +} +static int inmemSectorSize(sqlite3_file *pFile){ + return 512; +} +static int inmemDeviceCharacteristics(sqlite3_file *pFile){ + return + SQLITE_IOCAP_SAFE_APPEND | + SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN | + SQLITE_IOCAP_POWERSAFE_OVERWRITE; +} + + +/* Method table for VHandle +*/ +static sqlite3_io_methods VHandleMethods = { + /* iVersion */ 1, + /* xClose */ inmemClose, + /* xRead */ inmemRead, + /* xWrite */ inmemWrite, + /* xTruncate */ inmemTruncate, + /* xSync */ inmemSync, + /* xFileSize */ inmemFileSize, + /* xLock */ inmemLock, + /* xUnlock */ inmemUnlock, + /* xCheck... */ inmemCheckReservedLock, + /* xFileCtrl */ inmemFileControl, + /* xSectorSz */ inmemSectorSize, + /* xDevchar */ inmemDeviceCharacteristics, + /* xShmMap */ 0, + /* xShmLock */ 0, + /* xShmBarrier */ 0, + /* xShmUnmap */ 0, + /* xFetch */ 0, + /* xUnfetch */ 0 +}; + +/* +** Open a new file in the inmem VFS. All files are anonymous and are +** delete-on-close. +*/ +static int inmemOpen( + sqlite3_vfs *pVfs, + const char *zFilename, + sqlite3_file *pFile, + int openFlags, + int *pOutFlags +){ + VFile *pVFile = createVFile(zFilename, 0); + VHandle *pHandle = (VHandle*)pFile; + if( pVFile==0 ){ + return SQLITE_FULL; + } + pHandle->pVFile = pVFile; + pVFile->nRef++; + pFile->pMethods = &VHandleMethods; + if( pOutFlags ) *pOutFlags = openFlags; + return SQLITE_OK; +} + +/* +** Delete a file by name +*/ +static int inmemDelete( + sqlite3_vfs *pVfs, + const char *zFilename, + int syncdir +){ + VFile *pVFile = findVFile(zFilename); + if( pVFile==0 ) return SQLITE_OK; + if( pVFile->nRef==0 ){ + free(pVFile->zFilename); + pVFile->zFilename = 0; + pVFile->sz = -1; + free(pVFile->a); + pVFile->a = 0; + return SQLITE_OK; + } + return SQLITE_IOERR_DELETE; +} + +/* Check for the existance of a file +*/ +static int inmemAccess( + sqlite3_vfs *pVfs, + const char *zFilename, + int flags, + int *pResOut +){ + VFile *pVFile = findVFile(zFilename); + *pResOut = pVFile!=0; + return SQLITE_OK; +} + +/* Get the canonical pathname for a file +*/ +static int inmemFullPathname( + sqlite3_vfs *pVfs, + const char *zFilename, + int nOut, + char *zOut +){ + sqlite3_snprintf(nOut, zOut, "%s", zFilename); + return SQLITE_OK; +} + +/* +** Register the VFS that reads from the g.aFile[] set of files. +*/ +static void inmemVfsRegister(void){ + static sqlite3_vfs inmemVfs; + sqlite3_vfs *pDefault = sqlite3_vfs_find(0); + inmemVfs.iVersion = 3; + inmemVfs.szOsFile = sizeof(VHandle); + inmemVfs.mxPathname = 200; + inmemVfs.zName = "inmem"; + inmemVfs.xOpen = inmemOpen; + inmemVfs.xDelete = inmemDelete; + inmemVfs.xAccess = inmemAccess; + inmemVfs.xFullPathname = inmemFullPathname; + inmemVfs.xRandomness = pDefault->xRandomness; + inmemVfs.xSleep = pDefault->xSleep; + inmemVfs.xCurrentTimeInt64 = pDefault->xCurrentTimeInt64; + sqlite3_vfs_register(&inmemVfs, 0); +}; + +/* +** Timeout handler +*/ +#ifdef __unix__ +static void timeoutHandler(int NotUsed){ + (void)NotUsed; + fatalError("timeout\n"); +} +#endif + +/* +** Set the an alarm to go off after N seconds. Disable the alarm +** if N==0 +*/ +static void setAlarm(int N){ +#ifdef __unix__ + alarm(N); +#else + (void)N; +#endif +} +/*************************************************************************** +** String accumulator object +*/ +typedef struct Str Str; +struct Str { + char *z; /* The string. Memory from malloc() */ + sqlite3_uint64 n; /* Bytes of input used */ + sqlite3_uint64 nAlloc; /* Bytes allocated to z[] */ + int oomErr; /* OOM error has been seen */ +}; + +/* Initialize a Str object */ +static void StrInit(Str *p){ + memset(p, 0, sizeof(*p)); +} + +/* Append text to the end of a Str object */ +static void StrAppend(Str *p, const char *z){ + sqlite3_uint64 n = strlen(z); + if( p->n + n >= p->nAlloc ){ + char *zNew; + sqlite3_uint64 nNew; + if( p->oomErr ) return; + nNew = p->nAlloc*2 + 100 + n; + zNew = sqlite3_realloc64(p->z, nNew); + if( zNew==0 ){ + sqlite3_free(p->z); + memset(p, 0, sizeof(*p)); + p->oomErr = 1; + return; + } + p->z = zNew; + p->nAlloc = nNew; + } + memcpy(p->z + p->n, z, (int)n); + p->n += n; + p->z[p->n] = 0; +} + +/* Return the current string content */ +static char *StrStr(Str *p){ + return p->z; +} + +/* Free the string */ +static void StrFree(Str *p){ + sqlite3_free(p->z); + StrInit(p); +} + +/* +** Return the value of a hexadecimal digit. Return -1 if the input +** is not a hex digit. +*/ +static int hexDigitValue(char c){ + if( c>='0' && c<='9' ) return c - '0'; + if( c>='a' && c<='f' ) return c - 'a' + 10; + if( c>='A' && c<='F' ) return c - 'A' + 10; + return -1; +} + +/* +** Interpret zArg as an integer value, possibly with suffixes. +*/ +static int integerValue(const char *zArg){ + sqlite3_int64 v = 0; + static const struct { char *zSuffix; int iMult; } aMult[] = { + { "KiB", 1024 }, + { "MiB", 1024*1024 }, + { "GiB", 1024*1024*1024 }, + { "KB", 1000 }, + { "MB", 1000000 }, + { "GB", 1000000000 }, + { "K", 1000 }, + { "M", 1000000 }, + { "G", 1000000000 }, + }; + int i; + int isNeg = 0; + if( zArg[0]=='-' ){ + isNeg = 1; + zArg++; + }else if( zArg[0]=='+' ){ + zArg++; + } + if( zArg[0]=='0' && zArg[1]=='x' ){ + int x; + zArg += 2; + while( (x = hexDigitValue(zArg[0]))>=0 ){ + v = (v<<4) + x; + zArg++; + } + }else{ + while( ISDIGIT(zArg[0]) ){ + v = v*10 + zArg[0] - '0'; + zArg++; + } + } + for(i=0; i0x7fffffff ) fatalError("parameter too large - max 2147483648"); + return (int)(isNeg? -v : v); +} + +/* +** This callback is invoked by sqlite3_log(). +*/ +static void sqlLog(void *pNotUsed, int iErrCode, const char *zMsg){ + printf("LOG: (%d) %s\n", iErrCode, zMsg); + fflush(stdout); +} + +#ifndef SQLITE_OMIT_PROGRESS_CALLBACK +/* +** This an SQL progress handler. After an SQL statement has run for +** many steps, we want to interrupt it. This guards against infinite +** loops from recursive common table expressions. +** +** *pVdbeLimitFlag is true if the --limit-vdbe command-line option is used. +** In that case, hitting the progress handler is a fatal error. +*/ +static int progressHandler(void *pVdbeLimitFlag){ + if( *(int*)pVdbeLimitFlag ) fatalError("too many VDBE cycles"); + return 1; +} +#endif + +/* +** Allowed values for the runFlags parameter to runSql() +*/ +#define SQL_TRACE 0x0001 /* Print each SQL statement as it is prepared */ +#define SQL_OUTPUT 0x0002 /* Show the SQL output */ + +/* +** Run multiple commands of SQL. Similar to sqlite3_exec(), but does not +** stop if an error is encountered. +*/ +static void runSql(sqlite3 *db, const char *zSql, unsigned runFlags){ + const char *zMore; + const char *zEnd = &zSql[strlen(zSql)]; + sqlite3_stmt *pStmt; + + while( zSql && zSql[0] ){ + zMore = 0; + pStmt = 0; + sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zMore); + assert( zMore<=zEnd ); + if( zMore==zSql ) break; + if( runFlags & SQL_TRACE ){ + const char *z = zSql; + int n; + while( z0 && ISSPACE(z[n-1]) ) n--; + if( n==0 ) break; + if( pStmt==0 ){ + printf("TRACE: %.*s (error: %s)\n", n, z, sqlite3_errmsg(db)); + }else{ + printf("TRACE: %.*s\n", n, z); + } + } + zSql = zMore; + if( pStmt ){ + if( (runFlags & SQL_OUTPUT)==0 ){ + while( SQLITE_ROW==sqlite3_step(pStmt) ){} + }else{ + int nCol = -1; + int nRow; + for(nRow=0; SQLITE_ROW==sqlite3_step(pStmt); nRow++){ + int i; + if( nCol<0 ){ + nCol = sqlite3_column_count(pStmt); + } + for(i=0; i0 ){ + void *pHeap = malloc( nHeap ); + if( pHeap==0 ) fatalError("cannot allocate %d-byte heap\n", nHeap); + rc = sqlite3_config(SQLITE_CONFIG_HEAP, pHeap, nHeap, 32); + if( rc ) fatalError("heap configuration failed: %d\n", rc); + } + if( noLookaside ){ + sqlite3_config(SQLITE_CONFIG_LOOKASIDE, 0, 0); + } + inmemVfsRegister(); + formatVfs(); + StrInit(&sql); +#ifdef __unix__ + signal(SIGALRM, timeoutHandler); +#endif + for(i=0; i1 ){ + printf("DATABASE-FILE: %s\n", azDb[i]); + fflush(stdout); + } + if( iTimeout ) setAlarm(iTimeout); + createVFile("test.db", azDb[i]); + rc = sqlite3_open_v2("test.db", &db, SQLITE_OPEN_READWRITE, "inmem"); + if( rc ){ + printf("cannot open test.db for \"%s\"\n", azDb[i]); + reformatVfs(); + continue; + } +#ifndef SQLITE_OMIT_PROGRESS_CALLBACK + if( vdbeLimitFlag ){ + sqlite3_progress_handler(db, 100000, progressHandler, &vdbeLimitFlag); + } +#endif + rc = sqlite3_prepare_v2(db, "SELECT sql FROM autoexec", -1, &pStmt, 0); + if( rc==SQLITE_OK ){ + while( SQLITE_ROW==sqlite3_step(pStmt) ){ + StrAppend(&sql, (const char*)sqlite3_column_text(pStmt, 0)); + StrAppend(&sql, "\n"); + } + } + sqlite3_finalize(pStmt); + StrAppend(&sql, "PRAGMA integrity_check;\n"); + runSql(db, StrStr(&sql), runFlags); + sqlite3_close(db); + reformatVfs(); + StrFree(&sql); + if( sqlite3_memory_used()>0 ){ + free(azDb); + reformatVfs(); + fatalError("memory leak of %lld bytes", sqlite3_memory_used()); + } + } + StrFree(&sql); + reformatVfs(); + return 0; +} diff --git a/test/dbfuzz001.test b/test/dbfuzz001.test new file mode 100644 index 0000000..228dd16 --- /dev/null +++ b/test/dbfuzz001.test @@ -0,0 +1,397 @@ +# 2012-12-13 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Test cases for corrupt database files. + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !deserialize { + finish_test + return +} +database_may_be_corrupt + +# In the following database file, there is 384 bytes of free space +# on page 8 that does not appear on the freeblock list. +# +do_test dbfuzz001-100 { + sqlite3 db {} + db deserialize [decode_hexdb { + | size 5632 pagesize 512 filename c4.db + | page 1 offset 0 + | 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. + | 16: 02 00 01 01 00 40 20 20 00 00 00 02 00 00 00 0b .....@ ........ + | 32: 00 00 00 06 00 00 00 01 00 00 00 28 00 00 00 04 ...........(.... + | 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ + | 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 ................ + | 96: 00 2e 30 38 0d 00 00 00 06 01 06 00 01 da 01 b0 ..08............ + | 112: 01 56 01 86 01 2a 01 06 00 00 00 00 00 00 00 00 .V...*.......... + | 256: 00 00 00 00 00 00 22 07 06 17 11 11 01 31 74 61 ......"......1ta + | 272: 62 6c 65 74 34 74 34 07 43 52 45 41 54 45 20 54 blet4t4.CREATE T + | 288: 41 42 4c 45 20 74 34 28 78 29 2a 06 06 17 13 11 ABLE t4(x)*..... + | 304: 01 3f 69 6e 64 65 78 00 00 00 00 00 00 00 00 00 .?index......... + | 336: 20 74 33 28 78 29 2e 04 06 17 15 11 01 45 69 6e t3(x).......Ein + | 352: 64 65 78 74 32 63 64 74 32 05 43 52 45 41 54 45 dext2cdt2.CREATE + | 368: 20 49 4e 44 45 58 20 74 32 63 64 20 4f 4e 20 74 INDEX t2cd ON t + | 384: 32 28 63 2c 64 29 28 05 06 17 11 11 01 3d 74 61 2(c,d)(......=ta + | 400: 62 6c 65 74 33 74 33 04 43 52 45 41 54 45 20 54 blet3t3.CREATE T + | 416: 41 42 4c 45 20 74 33 28 63 2c 78 2c 65 2c 66 29 ABLE t3(c,x,e,f) + | 432: 28 02 06 17 11 11 01 3d 74 61 62 6c 65 74 32 74 (......=tablet2t + | 448: 32 03 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 2.CREATE TABLE t + | 464: 32 28 63 2c 64 2c 65 2c 66 29 24 01 06 17 11 11 2(c,d,e,f)$..... + | 480: 01 35 74 61 62 6c 65 74 31 74 31 02 43 52 45 41 .5tablet1t1.CREA + | 496: 54 45 20 54 41 42 4c 45 20 74 31 28 61 2c 62 29 TE TABLE t1(a,b) + | page 2 offset 512 + | 0: 0d 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 ................ + | page 3 offset 1024 + | 0: 0d 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 ................ + | page 4 offset 1536 + | 0: 05 00 00 00 03 01 f1 00 00 00 00 0b 01 fb 01 f6 ................ + | 16: 01 f1 00 16 00 00 09 06 05 01 01 01 01 04 04 03 ................ + | 32: 03 07 05 05 01 01 09 09 02 02 19 04 05 17 17 17 ................ + | 48: 17 73 65 76 65 6e 65 69 67 68 74 65 69 67 68 74 .seveneighteight + | 64: 73 65 76 65 6e 25 03 05 07 07 07 07 40 14 00 00 seven%......@... + | 80: 00 00 00 00 40 18 00 00 00 00 00 00 40 18 00 00 ....@.......@... + | 96: 00 00 00 00 40 14 00 00 00 00 00 00 09 02 05 01 ....@........... + | 112: 01 01 01 03 04 04 03 07 01 05 09 01 01 09 02 02 ................ + | 352: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1a ................ + | 496: 00 00 00 00 0a 3e 00 00 00 09 21 00 00 00 08 06 .....>....!..... + | page 5 offset 2048 + | 0: 0a 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 ................ + | page 7 offset 3072 + | 0: 0d 00 00 00 08 01 c2 00 01 fb 01 f6 01 f1 01 ec ................ + | 16: 01 e0 01 d4 01 cb 01 c2 00 00 00 00 00 00 00 00 ................ + | 96: 00 00 00 00 13 00 00 00 00 00 00 00 00 00 00 00 ................ + | 224: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 ................ + | 288: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 ................ + | 448: 00 00 07 08 02 17 65 69 67 68 74 07 07 02 17 65 ......eight....e + | 464: 69 67 68 74 0a 06 02 07 40 18 00 00 00 00 00 00 ight....@....... + | 480: 0a 05 02 07 40 18 00 00 00 00 00 00 03 04 02 01 ....@........... + | 496: 04 03 03 02 01 04 03 02 02 01 02 03 01 02 01 02 ................ + | page 8 offset 3584 + | 0: 0d 00 21 00 01 00 16 00 00 16 00 16 00 16 00 16 ..!............. + | 16: 00 16 00 16 00 00 09 06 05 01 01 01 01 04 04 03 ................ + | 32: 03 00 00 00 5f 01 09 09 02 02 00 00 00 56 17 17 ...._........V.. + | 48: 17 73 65 76 65 6e 65 69 67 68 74 65 69 67 68 74 .seveneighteight + | 64: 73 65 76 65 6e 00 00 00 3b 07 07 07 40 14 00 00 seven...;...@... + | 80: 00 00 00 00 40 18 00 00 00 00 00 00 40 18 00 00 ....@.......@... + | 96: 00 00 00 00 40 14 00 00 00 00 00 00 00 00 00 14 ....@........... + | 112: 01 01 01 03 04 04 03 00 00 00 09 01 01 09 02 02 ................ + | 352: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1a ................ + | page 9 offset 4096 + | 0: 0d 00 00 00 1b 00 47 00 01 d9 01 be 01 af 01 a0 ......G......... + | 16: 01 91 01 82 01 73 01 64 01 55 01 46 01 37 01 28 .....s.d.U.F.7.( + | 32: 01 19 01 0a 00 fb 00 ec 00 dd 00 ce 00 bf 00 b0 ................ + | 48: 00 a1 00 92 00 83 00 74 00 65 00 56 00 47 00 00 .......t.e.V.G.. + | 64: 00 00 00 00 00 00 00 0d 21 00 00 48 01 54 00 01 ........!..H.T.. + | 80: f7 01 ec 01 c5 01 0d 20 00 00 48 01 54 00 01 f7 ....... ..H.T... + | 96: 01 ec 01 c5 01 0d 1f 00 00 48 01 54 00 01 f7 01 .........H.T.... + | 112: ec 01 c5 01 0d 1e 00 00 48 01 54 00 01 f7 01 ec ........H.T..... + | 128: 01 c5 01 0d 1d 00 00 48 01 54 00 01 f7 01 ec 01 .......H.T...... + | 144: c5 01 0d 1c 00 00 48 01 54 00 01 f7 01 ec 01 c5 ......H.T....... + | 160: 01 0d 1b 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 .....H.T........ + | 176: 0d 1a 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 0d ....H.T......... + | 192: 19 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 0d 18 ...H.T.......... + | 208: 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 0d 17 00 ..H.T........... + | 224: 00 48 01 54 00 01 f7 01 ec 01 c5 01 0d 16 00 00 .H.T............ + | 240: 48 01 54 00 01 f7 01 ec 01 c5 01 0d 15 00 00 48 H.T............H + | 256: 01 54 00 01 f7 01 ec 01 c5 01 0d 14 00 00 48 01 .T............H. + | 272: 54 00 01 f7 01 ec 01 c5 01 0d 13 00 00 48 01 54 T............H.T + | 288: 00 01 f7 01 ec 01 c5 01 0d 12 00 00 48 01 54 00 ............H.T. + | 304: 01 f7 01 ec 01 c5 01 0d 11 00 00 48 01 54 00 01 ...........H.T.. + | 320: f7 01 ec 01 c5 01 0d 10 00 00 48 01 54 00 01 f7 ..........H.T... + | 336: 01 ec 01 c5 01 0d 0f 00 00 48 01 54 00 01 f7 01 .........H.T.... + | 352: ec 01 c5 01 0d 0e 00 00 48 01 54 00 01 f7 01 ec ........H.T..... + | 368: 01 c5 01 0d 0d 00 00 48 01 54 00 01 f7 01 ec 01 .......H.T...... + | 384: c5 01 0d 0c 00 00 48 01 54 00 01 f7 01 ec 01 c5 ......H.T....... + | 400: 01 0d 0b 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 .....H.T........ + | 416: 0d 0a 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 0d ....H.T......... + | 432: 09 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 19 08 ...H.T.......... + | 448: 05 17 17 17 17 65 69 67 68 74 65 69 67 68 74 73 .....eighteights + | 464: 65 76 65 6e 73 65 76 65 6e 25 07 05 07 07 07 07 evenseven%...... + | 480: 40 18 00 00 00 00 00 00 40 18 00 00 00 00 00 00 @.......@....... + | 496: 40 14 00 00 00 00 00 00 40 14 00 00 00 00 00 00 @.......@....... + | page 10 offset 4608 + | 0: 0d 00 00 00 1d 00 4d 00 01 f1 01 e2 01 d3 01 c4 ......M......... + | 16: 01 b5 01 a6 01 97 01 88 01 79 01 6a 01 5b 01 4c .........y.j.[.L + | 32: 01 3d 01 2e 01 1f 01 10 01 01 00 f2 00 e3 00 d4 .=.............. + | 48: 00 c5 00 b6 00 a7 00 98 00 89 00 7a 00 6b 00 5c ...........z.k.\ + | 64: 00 4d 00 00 00 00 00 00 00 00 00 00 00 0d 3e 00 .M............>. + | 80: 00 48 01 54 00 01 f7 01 ec 01 c5 01 0d 3d 00 00 .H.T.........=.. + | 96: 48 01 54 00 01 f7 01 ec 01 c5 01 0d 3c 00 00 48 H.T.........<..H + | 112: 01 54 00 01 f7 01 ec 01 c5 01 0d 3b 00 00 48 01 .T.........;..H. + | 128: 54 00 01 f7 01 ec 01 c5 01 0d 3a 00 00 48 01 54 T.........:..H.T + | 144: 00 01 f7 01 ec 01 c5 01 0d 39 00 00 48 01 54 00 .........9..H.T. + | 160: 01 f7 01 ec 01 c5 01 0d 38 00 00 48 01 54 00 01 ........8..H.T.. + | 176: f7 01 ec 01 c5 01 0d 37 00 00 48 01 54 00 01 f7 .......7..H.T... + | 192: 01 ec 01 c5 01 0d 36 00 00 48 01 54 00 01 f7 01 ......6..H.T.... + | 208: ec 01 c5 01 0d 35 00 00 48 01 54 00 01 f7 01 ec .....5..H.T..... + | 224: 01 c5 01 0d 34 00 00 48 01 54 00 01 f7 01 ec 01 ....4..H.T...... + | 240: c5 01 0d 33 00 00 48 01 54 00 01 f7 01 ec 01 c5 ...3..H.T....... + | 256: 01 0d 32 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 ..2..H.T........ + | 272: 0d 31 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 0d .1..H.T......... + | 288: 30 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 0d 2f 0..H.T........./ + | 304: 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 0d 2e 00 ..H.T........... + | 320: 00 48 01 54 00 01 f7 01 ec 01 c5 01 0d 2d 00 00 .H.T.........-.. + | 336: 48 01 54 00 01 f7 01 ec 01 c5 01 0d 2c 00 00 48 H.T.........,..H + | 352: 01 54 00 01 f7 01 ec 01 c5 01 0d 2b 00 00 48 01 .T.........+..H. + | 368: 54 00 01 f7 01 ec 01 c5 01 0d 2a 00 00 48 01 54 T.........*..H.T + | 384: 00 01 f7 01 ec 01 c5 01 0d 29 00 00 48 01 54 00 .........)..H.T. + | 400: 01 f7 01 ec 01 c5 01 0d 28 00 00 48 01 54 00 01 ........(..H.T.. + | 416: f7 01 ec 01 c5 01 0d 27 00 00 48 01 54 00 01 f7 .......'..H.T... + | 432: 01 ec 01 c5 01 0d 26 00 00 48 01 54 00 01 f7 01 ......&..H.T.... + | 448: ec 01 c5 01 0d 25 00 00 48 01 54 00 01 f7 01 ec .....%..H.T..... + | 464: 01 c5 01 0d 24 00 00 48 01 54 00 01 f7 01 ec 01 ....$..H.T...... + | 480: c5 01 0d 23 00 00 48 01 54 00 01 f7 01 ec 01 c5 ...#..H.T....... + | 496: 01 0d 22 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 .."..H.T........ + | page 11 offset 5120 + | 0: 0d 00 00 00 0a 01 6a 00 01 f1 01 e2 01 d3 01 c4 ......j......... + | 16: 01 b5 01 a6 01 97 01 88 01 79 01 6a 00 00 00 00 .........y.j.... + | 352: 00 00 00 00 00 00 00 00 00 00 0d 48 00 00 48 01 ...........H..H. + | 368: 54 00 01 f7 01 ec 01 c5 01 0d 47 00 00 48 01 54 T.........G..H.T + | 384: 00 01 f7 01 ec 01 c5 01 0d 46 00 00 48 01 54 00 .........F..H.T. + | 400: 01 f7 01 ec 01 c5 01 0d 45 00 00 48 01 54 00 01 ........E..H.T.. + | 416: f7 01 ec 01 c5 01 0d 44 00 00 48 01 54 00 01 f7 .......D..H.T... + | 432: 01 ec 01 c5 01 0d 43 00 00 48 01 54 00 01 f7 01 ......C..H.T.... + | 448: ec 01 c5 01 0d 42 00 00 48 01 54 00 01 f7 01 ec .....B..H.T..... + | 464: 01 c5 01 0d 41 00 00 48 01 54 00 01 f7 01 ec 01 ....A..H.T...... + | 480: c5 01 0d 40 00 00 48 01 54 00 01 f7 01 ec 01 c5 ...@..H.T....... + | 496: 01 0d 3f 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 ..?..H.T........ + | end c4.db + }] +} {} + +ifcapable !oversize_cell_check { + # Non SQLITE_ENABLE_OVERSIZE_CELL_CHECK builds: + do_test dbfuzz001-101a { + db eval {PRAGMA writable_schema=on; PRAGMA integrity_check} + } {/Fragmentation of 384 bytes reported as 0 on page 8/} +} else { + # SQLITE_ENABLE_OVERSIZE_CELL_CHECK builds: + do_catchsql_test dbfuzz001-101b { + PRAGMA writable_schema=on; + PRAGMA integrity_check; + } {1 {database disk image is malformed}} +} + +# The DELETE query below deletes the very last cell from page 8. +# Prior to a certain fix to sqlite3BtreeDelete() and because of the +# corruption to the freeblock list on page 8, this would fail to +# cause a rebalance operation, which would leave the btree in a weird +# state that would lead to segfaults and or assertion faults. +# +do_execsql_test dbfuzz001-110 { + DELETE FROM t3 WHERE x IS NOT NULL AND +rowid=6; +} {} + +# This is a dbfuzz2-generate test case that can cause a page with +# pPage->nCell==0 to enter the balancer. +# +do_test dbfuzz001-200 { + db deserialize [decode_hexdb { + | size 3076 pagesize 512 filename c03.db + | page 1 offset 0 + | 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. + | 16: 02 00 01 01 00 40 20 20 00 00 00 0c 00 00 00 07 .....@ ........ + | 32: 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 04 ................ + | 48: 00 00 00 00 00 00 00 03 e8 00 00 01 00 00 00 00 ................ + | 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0c ................ + | 96: 00 2e 2c 50 0d 00 00 00 06 01 06 00 01 da 01 b0 ..,P............ + | 112: 01 56 01 86 01 2a 01 06 00 00 00 00 00 00 00 00 .V...*.......... + | 128: 00 00 00 00 00 00 00 00 ef 00 00 00 00 00 00 00 ................ + | 192: 00 7f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + | 224: 00 00 00 00 00 00 00 00 00 00 00 00 00 ff e9 00 ................ + | 256: 00 00 00 00 00 00 22 07 06 17 11 11 01 31 74 61 ......"......1ta + | 272: 62 6c 65 74 34 74 34 07 43 52 45 41 54 45 20 54 blet4t4.CREATE T + | 288: 41 42 4c 45 20 74 34 28 78 29 2a 06 06 17 13 11 ABLE t4(x)*..... + | 304: 01 3f 69 6e 64 65 78 74 33 78 74 33 06 43 52 45 .?indext3xt3.CRE + | 320: 41 54 45 20 49 4e 44 45 58 20 74 33 64 20 4f 4e ATE INDEX t3d ON + | 336: 20 74 33 28 78 29 2e 04 06 17 15 11 01 45 69 6e t3(x).......Ein + | 352: 64 65 78 74 32 63 64 74 32 05 43 52 45 41 54 45 dext2cdt2.CREATE + | 368: 20 49 4e 44 45 58 20 74 32 63 64 20 4f 4e 20 74 INDEX t2cd ON t + | 384: 32 28 63 2c 64 29 28 05 06 17 11 11 01 3d 74 61 2(c,d)(......=ta + | 400: 62 6c 65 74 33 74 33 04 43 52 45 41 54 45 20 54 blet3t3.CREATE T + | 416: 41 42 4c 45 20 74 33 28 63 2c 78 2c 65 2c 66 29 ABLE t3(c,x,e,f) + | 432: 28 02 06 17 11 11 01 3d 74 61 62 6c 65 74 32 74 (......=tablet2t + | 448: 32 03 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 2.CREATE TABLE t + | 464: 32 28 63 2c 64 2c 65 2c 66 29 24 01 06 17 11 11 2(c,d,e,f)$..... + | 480: 01 35 74 61 62 6c 65 74 31 74 31 02 43 52 45 41 .5tablet1t1.CREA + | 496: 54 45 20 54 41 42 4c 45 20 74 31 28 61 2c 62 29 TE TABLE t1(a,b) + | page 2 offset 512 + | 0: 0d 00 00 00 04 01 cf 00 01 fa 01 f3 01 de 01 cf ................ + | 176: 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + | 256: 00 00 14 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + | 368: 00 00 00 00 00 00 00 00 00 00 00 00 1e 00 00 00 ................ + | 416: 00 00 00 1b 00 00 00 00 04 00 00 00 00 00 00 00 ................ + | 448: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0d ................ + | 464: 04 03 17 17 73 65 76 65 6e 65 69 67 68 74 13 03 ....seveneight.. + | 480: 03 07 07 40 14 00 00 00 00 00 00 40 18 00 00 00 ...@.......@.... + | 496: 00 00 00 05 02 03 01 01 03 04 04 01 03 09 01 02 ................ + | page 3 offset 1024 + | 0: 0d 00 00 00 08 01 54 00 01 f7 01 ec 01 c5 01 aa ......T......... + | 16: 01 a1 01 96 01 6f 01 54 00 00 00 00 00 00 00 00 .....o.T........ + | 32: 00 00 00 00 00 00 00 03 e8 00 00 00 00 00 00 00 ................ + | 336: 00 00 00 00 19 08 05 16 17 17 17 65 69 67 68 74 ...........eight + | 352: 65 69 67 68 74 73 65 76 65 6e 73 65 76 ff ff ff eightsevensev... + | 368: 0e 05 07 07 07 07 40 18 00 00 00 00 00 00 40 18 ......@.......@. + | 384: 00 00 00 00 00 00 40 14 00 00 00 00 00 00 40 14 ......@.......@. + | 400: 00 00 00 00 00 00 09 06 05 01 01 01 01 04 04 03 ................ + | 416: 03 07 05 05 01 01 09 09 02 02 19 04 05 17 17 17 ................ + | 432: 17 73 65 6f 65 6e 65 69 67 68 74 65 69 67 68 74 .seoeneighteight + | 448: 73 65 76 65 6e 25 03 05 07 07 07 07 40 14 00 00 seven%......@... + | 464: 00 00 00 00 40 18 00 00 00 00 00 00 40 18 00 00 ....@.......@... + | 480: 00 00 00 00 40 14 00 00 00 00 00 00 09 02 05 01 ....@........... + | 496: 01 01 01 03 04 04 03 07 01 05 09 01 01 09 02 02 ................ + | page 4 offset 1536 + | 0: 0d 00 00 00 00 00 10 00 00 00 00 00 00 00 00 00 ................ + | 160: 00 00 00 ea 00 00 00 00 00 00 00 00 00 00 00 00 ................ + | 336: 00 00 00 00 00 00 00 00 00 00 00 00 20 00 00 00 ............ ... + | page 5 offset 2048 + | 0: 0a 00 00 00 08 01 96 00 01 fa 01 c4 01 f2 01 bc ................ + | 16: 01 dc 01 a6 01 96 01 cc 00 00 00 00 00 00 00 00 ................ + | 48: 00 00 00 00 00 00 00 00 00 00 10 00 00 00 00 00 ................ + | 288: 00 00 00 00 00 00 00 00 00 64 00 00 00 2b 00 00 .........d...+.. + | 400: 00 00 00 00 00 00 0f 04 17 17 01 65 69 67 68 74 ...........eight + | 416: 65 69 6f 68 74 08 15 04 07 07 01 40 18 00 00 00 eioht......@.... + | 432: 00 00 00 40 18 00 00 00 00 00 00 07 07 04 01 01 ...@............ + | 448: 01 04 04 06 07 04 01 01 01 02 02 05 0f 04 17 17 ................ + | 464: 01 73 65 76 65 6e 65 69 67 68 74 04 15 04 07 07 .seveneight..... + | 480: 01 40 14 00 00 00 00 00 00 40 18 00 00 00 00 00 .@.......@...... + | 496: 00 03 07 04 01 01 01 03 04 02 05 04 09 01 09 02 ................ + | page 6 offset 2560 + | 0: 0a 00 00 00 00 02 00 00 00 00 00 00 00 0d 00 00 ................ + | 16: 00 08 01 c2 00 01 fb 01 f6 01 f1 01 ec 01 e0 01 ................ + | 32: d4 01 cb 01 c2 00 00 00 00 00 00 00 00 00 00 00 ................ + | 160: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 00 ................ + | 448: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 07 ................ + | 464: 08 02 17 65 69 67 68 74 07 07 02 17 65 69 67 68 ...eight....eigh + | 480: 74 0a 06 02 07 40 18 00 00 00 00 00 00 0a 05 02 t....@.......... + | 496: 07 40 18 00 04 02 01 04 03 03 02 01 04 03 02 02 .@.............. + | end x/c03.db + }] + catchsql {INSERT INTO t3 SELECT * FROM t2;} +} {1 {database disk image is malformed}} + + +do_test dbfuzz001-310 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 3584 pagesize 512 filename x/c02.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 02 00 01 01 00 40 20 20 00 00 00 0c 00 00 00 07 .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 00 ................ +| 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0c ................ +| 96: 00 2e 2c 50 0d 00 00 00 06 01 06 00 01 da 01 b0 ..,P............ +| 112: 01 56 01 86 01 2a 01 06 00 00 00 00 00 00 00 00 .V...*.......... +| 256: 00 00 00 00 00 00 22 07 06 17 11 11 01 31 74 61 ......"......1ta +| 272: 62 6c 65 74 34 74 34 07 43 52 45 41 54 45 20 54 blet4t4.CREATE T +| 288: 41 42 4c 45 20 74 34 28 78 29 2a 06 06 17 13 11 ABLE t4(x)*..... +| 304: 01 3f 69 6e 64 65 78 74 33 78 74 33 05 43 52 45 .?indext3xt3.CRE +| 320: 41 54 45 20 49 4e 44 45 58 20 74 33 78 20 4f 4e ATE INDEX t3x ON +| 336: 20 74 33 28 78 29 2e 04 06 17 15 11 01 45 69 6e t3(x).......Ein +| 352: 64 65 78 74 32 63 64 74 32 05 43 52 45 41 54 45 dext2cdt2.CREATE +| 368: 20 49 4e 44 45 58 20 74 32 63 64 20 4f 4e 20 74 INDEX t2cd ON t +| 384: 32 28 63 2c 64 29 28 05 06 17 11 11 01 3d 74 61 2(c,d)(......=ta +| 400: 62 6c 65 74 33 74 33 07 43 52 45 41 54 45 20 54 blet3t3.CREATE T +| 416: 41 42 4c 45 20 74 33 28 63 2c 78 2c 65 2c 66 29 ABLE t3(c,x,e,f) +| 432: 28 02 06 17 11 11 01 3d 74 61 62 6c 65 74 32 74 (......=tablet2t +| 448: 32 32 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 22CREATE TABLE t +| 464: 32 28 63 2c 64 2c 65 2c 66 29 24 01 06 17 11 11 2(c,d,e,f)$..... +| 480: 01 35 74 61 62 6c 65 74 31 74 31 02 43 52 45 41 .5tablet1t1.CREA +| 496: 54 45 20 54 41 42 4c 45 20 74 31 28 61 2c 62 29 TE TABLE t1(a,b) +| page 2 offset 512 +| 0: 0d 00 00 00 04 01 cf 00 01 fa 01 f3 01 de 01 cf ................ +| 160: 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 .. ............. +| 448: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0d ................ +| 464: 04 03 17 17 73 65 76 65 6e 65 69 67 68 74 13 03 ....seveneight.. +| 480: 03 07 07 40 14 00 00 00 00 00 00 40 18 00 00 00 ...@.......@.... +| 496: 00 00 00 05 02 03 01 01 03 04 04 01 03 09 01 02 ................ +| page 3 offset 1024 +| 0: 0d 00 00 00 08 01 54 00 01 f7 01 ec 01 c5 01 aa ......T......... +| 16: 01 a1 01 96 01 6f 01 54 00 00 00 00 00 00 00 00 .....o.T........ +| 112: 00 00 dd 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 336: 00 00 00 00 19 08 05 17 17 17 17 65 69 67 68 74 ...........eight +| 352: 65 69 67 68 74 73 65 76 65 6e 73 65 76 65 6e 25 eightsevenseven% +| 368: 07 05 07 07 07 07 40 18 00 00 00 00 00 00 40 18 ......@.......@. +| 384: 00 00 00 00 00 00 40 14 00 00 00 00 00 00 40 14 ......@.......@. +| 400: 00 00 00 00 00 00 09 06 05 01 01 01 01 04 04 03 ................ +| 416: 03 07 05 05 01 01 09 09 02 02 19 04 05 17 17 17 ................ +| 432: 17 73 65 76 65 6e 65 69 67 68 74 65 69 67 68 74 .seveneighteight +| 448: 73 65 76 65 6e 25 03 05 07 07 07 07 40 14 00 00 seven%......@... +| 464: 00 00 00 00 40 18 00 00 00 00 00 00 40 18 00 00 ....@.......@... +| 480: 00 00 00 00 40 14 00 00 00 00 00 00 09 02 05 01 ....@........... +| 496: 01 01 01 03 04 04 03 07 01 05 09 01 01 09 02 02 ................ +| page 4 offset 1536 +| 0: 0d 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 ................ +| 192: 00 00 00 00 00 00 7f 00 00 00 00 00 00 00 00 00 ................ +| 208: 00 e5 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| page 5 offset 2048 +| 0: 0a 00 00 00 08 01 96 00 01 fa 01 c4 01 f2 01 bc ................ +| 16: 01 dc 01 a6 01 96 01 cc 00 00 00 00 00 00 00 00 ................ +| 240: 00 00 00 00 00 00 00 00 00 00 00 00 00 0e 00 00 ................ +| 400: 00 00 00 00 00 00 0f 04 17 07 01 65 69 67 68 74 ...........eight +| 416: 65 69 67 68 74 08 15 04 07 07 01 40 18 00 00 00 eight......@.... +| 432: 00 00 00 40 18 00 00 00 00 00 00 07 07 04 01 01 ...@............ +| 448: 01 04 04 06 07 04 01 01 01 02 02 05 0f 04 17 17 ................ +| 464: 01 73 65 76 65 6e 65 69 67 68 74 04 15 04 07 07 .seveneight..... +| 480: 01 40 14 00 00 00 00 00 00 40 18 00 00 00 00 00 .@.......@...... +| 496: 00 03 07 04 01 01 01 03 04 02 05 04 09 01 09 02 ................ +| page 6 offset 2560 +| 0: 0a 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 ................ +| 464: 00 00 00 00 00 00 00 00 00 00 7f 00 00 00 00 00 ................ +| page 7 offset 3072 +| 0: 0d 00 00 00 08 01 c2 00 01 fb 01 f6 01 f1 01 ec ................ +| 16: 01 e0 01 d4 01 cb 01 c2 00 00 00 00 00 00 00 00 ................ +| 448: 00 00 07 08 02 17 65 69 67 68 74 07 07 02 17 65 ......eight....e +| 464: 69 67 68 74 0a 06 02 07 40 18 00 00 00 00 00 00 ight....@....... +| 480: 0a 05 02 07 40 18 00 00 00 00 00 00 03 04 02 01 ....@........... +| 496: 04 03 03 02 01 04 03 02 02 01 02 03 01 02 01 02 ................ +| end x/c02.db + }] +} {} + +extra_schema_checks 0 +do_catchsql_test dbfuzz001-320 { + PRAGMA integrity_check; +} {1 {database disk image is malformed}} + +do_catchsql_test dbfuzz001-330 { + DELETE FROM t3 WHERE x IN (SELECT x FROM t4); +} {1 {database disk image is malformed}} +extra_schema_checks 1 + +#------------------------------------------------------------------------- +reset_db + +do_execsql_test dbfuzz001-430 { + CREATE TABLE t1(a INTEGER, b INT, c DEFAULT 0); +} + +do_execsql_test dbfuzz001-420 { + PRAGMA locking_mode=EXCLUSIVE; + PRAGMA journal_mode = memory; + INSERT INTO t1 VALUES(1,2,3); + PRAGMA journal_mode=PERSIST; +} {exclusive memory persist} + +do_execsql_test dbfuzz001-430 { + INSERT INTO t1 VALUES(4, 5, 6); +} + +do_execsql_test dbfuzz001-440 { + PRAGMA journal_mode=MEMORY; + INSERT INTO t1 VALUES(7, 8, 9); +} {memory} + +finish_test diff --git a/test/dbfuzz2-seed1.db b/test/dbfuzz2-seed1.db new file mode 100644 index 0000000..17f0550 Binary files /dev/null and b/test/dbfuzz2-seed1.db differ diff --git a/test/dbfuzz2.c b/test/dbfuzz2.c new file mode 100644 index 0000000..f006291 --- /dev/null +++ b/test/dbfuzz2.c @@ -0,0 +1,402 @@ +/* +** 2018-10-26 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +************************************************************************* +** +** This program is designed for fuzz-testing SQLite database files using +** the -fsanitize=fuzzer option of clang. +** +** The -fsanitize=fuzzer option causes a main() to be inserted automatically. +** That main() invokes LLVMFuzzerTestOneInput(D,S) to be invoked repeatedly. +** Each D is a fuzzed database file. The code in this file runs various +** SQL statements against that database, trying to provoke a failure. +** +** For best results the seed database files should have these tables: +** +** Table "t1" with columns "a" and "b" +** Tables "t2" and "t3 with the same number of compatible columns +** "t3" should have a column names "x" +** Table "t4" with a column "x" that is compatible with t3.x. +** +** Any of these tables can be virtual tables, for example FTS or RTree tables. +** +** To run this test: +** +** mkdir dir +** cp dbfuzz2-seed*.db dir +** clang-6.0 -I. -g -O1 -fsanitize=fuzzer -DTHREADSAFE=0 \ +** -DSQLITE_ENABLE_DBSTAT_VTAB dbfuzz2.c sqlite3.c -ldl +** ./a.out dir +*/ +#include +#include +#include +#include +#include +#include +#include +#ifndef _WIN32 +#include +#include +#endif +#include "sqlite3.h" + +/* +** This is the is the SQL that is run against the database. +*/ +static const char *azSql[] = { + "PRAGMA integrity_check;", + "SELECT * FROM sqlite_schema;", + "SELECT sum(length(name)) FROM dbstat;", + "UPDATE t1 SET b=a, a=b WHERE a %d bytes\n", + memtraceBase.xSize(p), memtraceBase.xRoundup(n)); + } + return memtraceBase.xRealloc(p, n); +} +static int memtraceSize(void *p){ + return memtraceBase.xSize(p); +} +static int memtraceRoundup(int n){ + return memtraceBase.xRoundup(n); +} +static int memtraceInit(void *p){ + return memtraceBase.xInit(p); +} +static void memtraceShutdown(void *p){ + memtraceBase.xShutdown(p); +} + +/* The substitute memory allocator */ +static sqlite3_mem_methods ersaztMethods = { + memtraceMalloc, + memtraceFree, + memtraceRealloc, + memtraceSize, + memtraceRoundup, + memtraceInit, + memtraceShutdown +}; + +/* Begin tracing memory allocations to out. */ +int sqlite3MemTraceActivate(FILE *out){ + int rc = SQLITE_OK; + if( memtraceBase.xMalloc==0 ){ + rc = sqlite3_config(SQLITE_CONFIG_GETMALLOC, &memtraceBase); + if( rc==SQLITE_OK ){ + rc = sqlite3_config(SQLITE_CONFIG_MALLOC, &ersaztMethods); + } + } + memtraceOut = out; + return rc; +} + +/* Deactivate memory tracing */ +int sqlite3MemTraceDeactivate(void){ + int rc = SQLITE_OK; + if( memtraceBase.xMalloc!=0 ){ + rc = sqlite3_config(SQLITE_CONFIG_MALLOC, &memtraceBase); + if( rc==SQLITE_OK ){ + memset(&memtraceBase, 0, sizeof(memtraceBase)); + } + } + memtraceOut = 0; + return rc; +} +/***** End copy/paste from ext/misc/memtrace.c ***************************/ + +/* +** Progress handler callback +** +** Count the number of callbacks and cause an abort once the limit is +** reached. +*/ +static int progress_handler(void *pNotUsed){ + nCb++; + if( nCb=1 ){ + printf("-- Progress limit of %d reached\n", mxCb); + } + return 1; +} + +/* libFuzzer invokes this routine with fuzzed database files (in aData). +** This routine run SQLite against the malformed database to see if it +** can provoke a failure or malfunction. +*/ +int LLVMFuzzerTestOneInput(const uint8_t *aData, size_t nByte){ + unsigned char *a; + sqlite3 *db; + int rc; + int i; + sqlite3_int64 x; + char *zErr = 0; + + if( eVerbosity>=1 ){ + printf("************** nByte=%d ***************\n", (int)nByte); + fflush(stdout); + } + if( sqlite3_initialize() ) return 0; + rc = sqlite3_open(0, &db); + if( rc ) return 1; + a = sqlite3_malloc64(nByte+1); + if( a==0 ) return 1; + memcpy(a, aData, nByte); + sqlite3_deserialize(db, "main", a, nByte, nByte, + SQLITE_DESERIALIZE_RESIZEABLE | + SQLITE_DESERIALIZE_FREEONCLOSE); + x = szMax; +#ifdef SQLITE_FCNTL_SIZE_LIMIT + sqlite3_file_control(db, "main", SQLITE_FCNTL_SIZE_LIMIT, &x); +#endif + if( bVdbeDebug ){ + sqlite3_exec(db, "PRAGMA vdbe_debug=ON", 0, 0, 0); + } + if( mxCb>0 ){ + sqlite3_progress_handler(db, 10, progress_handler, 0); + } +#ifdef SQLITE_TESTCTRL_PRNG_SEED + sqlite3_test_control(SQLITE_TESTCTRL_PRNG_SEED, 1, db); +#endif + for(i=0; i=1 ){ + printf("%s\n", azSql[i]); + fflush(stdout); + } + zErr = 0; + nCb = 0; + rc = sqlite3_exec(db, azSql[i], 0, 0, &zErr); + if( rc && eVerbosity>=1 ){ + printf("-- rc=%d zErr=%s\n", rc, zErr); + } + sqlite3_free(zErr); + } + rc = sqlite3_close(db); + if( rc!=SQLITE_OK ){ + fprintf(stdout, "sqlite3_close() returns %d\n", rc); + } + if( sqlite3_memory_used()!=0 ){ + int nAlloc = 0; + int nNotUsed = 0; + sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &nAlloc, &nNotUsed, 0); + fprintf(stderr,"Memory leak: %lld bytes in %d allocations\n", + sqlite3_memory_used(), nAlloc); + exit(1); + } + return 0; +} + +/* +** Return the number of "v" characters in a string. Return 0 if there +** are any characters in the string other than "v". +*/ +static int numberOfVChar(const char *z){ + int N = 0; + while( z[0] && z[0]=='v' ){ + z++; + N++; + } + return z[0]==0 ? N : 0; +} + +/* libFuzzer invokes this routine once when the executable starts, to +** process the command-line arguments. +*/ +int LLVMFuzzerInitialize(int *pArgc, char ***pArgv){ + int i, j, n; + int argc = *pArgc; + char **argv = *pArgv; + for(i=j=1; i0 ){ + eVerbosity += n; + continue; + } + if( strcmp(z,"vdbe-debug")==0 ){ + bVdbeDebug = 1; + continue; + } + if( strcmp(z,"limit")==0 ){ + if( i+1==argc ){ + fprintf(stderr, "missing argument to %s\n", argv[i]); + exit(1); + } + mxCb = strtol(argv[++i], 0, 0); + continue; + } + if( strcmp(z,"memtrace")==0 ){ + sqlite3MemTraceActivate(stdout); + continue; + } + if( strcmp(z,"max-db-size")==0 ){ + if( i+1==argc ){ + fprintf(stderr, "missing argument to %s\n", argv[i]); + exit(1); + } + szMax = strtol(argv[++i], 0, 0); + continue; + } + if( strcmp(z, "lookaside")==0 ){ + int sz, nSlot; + if( i+2>=argc ){ + fprintf(stderr, + "--lookaside requires two arguments: slot-size num-slots\n"); + exit(1); + } + sz = atoi(argv[++i]); + nSlot = atoi(argv[++i]); + sqlite3_config(SQLITE_CONFIG_LOOKASIDE, sz, nSlot); + continue; + } +#ifndef _WIN32 + if( strcmp(z,"max-stack")==0 + || strcmp(z,"max-data")==0 + || strcmp(z,"max-as")==0 + ){ + struct rlimit x,y; + int resource = RLIMIT_STACK; + char *zType = "RLIMIT_STACK"; + if( i+1==argc ){ + fprintf(stderr, "missing argument to %s\n", argv[i]); + exit(1); + } + if( z[4]=='d' ){ + resource = RLIMIT_DATA; + zType = "RLIMIT_DATA"; + } + if( z[4]=='a' ){ + resource = RLIMIT_AS; + zType = "RLIMIT_AS"; + } + memset(&x,0,sizeof(x)); + getrlimit(resource, &x); + y.rlim_cur = atoi(argv[++i]); + y.rlim_max = x.rlim_cur; + setrlimit(resource, &y); + memset(&y,0,sizeof(y)); + getrlimit(resource, &y); + printf("%s changed from %d to %d\n", + zType, (int)x.rlim_cur, (int)y.rlim_cur); + continue; + } +#endif /* _WIN32 */ + } + argv[j++] = argv[i]; + } + argv[j] = 0; + *pArgc = j; + return 0; +} + +#ifdef STANDALONE +/* +** Read an entire file into memory. Space to hold the file comes +** from malloc(). +*/ +static unsigned char *readFile(const char *zName, int *pnByte){ + FILE *in = fopen(zName, "rb"); + long nIn; + size_t nRead; + unsigned char *pBuf; + if( in==0 ) return 0; + fseek(in, 0, SEEK_END); + nIn = ftell(in); + rewind(in); + pBuf = malloc( nIn+1 ); + if( pBuf==0 ){ fclose(in); return 0; } + nRead = fread(pBuf, nIn, 1, in); + fclose(in); + if( nRead!=1 ){ + free(pBuf); + return 0; + } + pBuf[nIn] = 0; + if( pnByte ) *pnByte = nIn; + return pBuf; +} +#endif /* STANDALONE */ + +#ifdef STANDALONE +int main(int argc, char **argv){ + int i; + LLVMFuzzerInitialize(&argc, &argv); + for(i=1; i0 ){ + struct rusage x; + printf("SQLite %s\n", sqlite3_sourceid()); + memset(&x, 0, sizeof(x)); + if( getrusage(RUSAGE_SELF, &x)==0 ){ + printf("Maximum RSS = %ld KB\n", x.ru_maxrss); + } + } +#endif + return 0; +} +#endif /*STANDALONE*/ diff --git a/test/dbpage.test b/test/dbpage.test new file mode 100644 index 0000000..0646a70 --- /dev/null +++ b/test/dbpage.test @@ -0,0 +1,111 @@ +# 2017-10-11 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing the sqlite_dbpage virtual table. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix dbpage + +ifcapable !vtab||!compound { + finish_test + return +} + +sqlite3_db_config db DEFENSIVE 0 +do_test 100 { + execsql { + PRAGMA auto_vacuum=0; + PRAGMA page_size=4096; + PRAGMA journal_mode=WAL; + } + execsql { + CREATE TABLE t1(a,b); + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100) + INSERT INTO t1(a,b) SELECT x, printf('%d-x%.*c',x,x,'x') FROM c; + PRAGMA integrity_check; + } +} {ok} +do_execsql_test 110 { + SELECT pgno, quote(substr(data,1,5)) FROM sqlite_dbpage('main') ORDER BY pgno; +} {1 X'53514C6974' 2 X'0500000001' 3 X'0D0000004E' 4 X'0D00000016'} +do_execsql_test 120 { + SELECT pgno, quote(substr(data,1,5)) FROM sqlite_dbpage WHERE pgno=2; +} {2 X'0500000001'} +do_execsql_test 130 { + SELECT pgno, quote(substr(data,1,5)) FROM sqlite_dbpage WHERE pgno=4; +} {4 X'0D00000016'} +do_execsql_test 140 { + SELECT pgno, quote(substr(data,1,5)) FROM sqlite_dbpage WHERE pgno=5; +} {} +do_execsql_test 150 { + SELECT pgno, quote(substr(data,1,5)) FROM sqlite_dbpage WHERE pgno=0; +} {} +do_execsql_test 160 { + ATTACH ':memory:' AS aux1; + PRAGMA aux1.page_size=4096; + CREATE TABLE aux1.t2(a,b,c); + INSERT INTO t2 VALUES(11,12,13); + SELECT pgno, quote(substr(data,1,5)) FROM sqlite_dbpage('aux1'); +} {1 X'53514C6974' 2 X'0D00000001'} +do_execsql_test 170 { + CREATE TABLE aux1.x3(x,y,z); + INSERT INTO x3(x,y,z) VALUES(1,'main',1),(2,'aux1',1); + SELECT pgno, schema, substr(data,1,6) + FROM sqlite_dbpage, x3 + WHERE sqlite_dbpage.schema=x3.y AND sqlite_dbpage.pgno=x3.z + ORDER BY x3.x; +} {1 main SQLite 1 aux1 SQLite} + +do_execsql_test 200 { + CREATE TEMP TABLE saved_content(x); + INSERT INTO saved_content(x) SELECT data FROM sqlite_dbpage WHERE pgno=4; + UPDATE sqlite_dbpage SET data=zeroblob(4096) WHERE pgno=4; +} {} +do_catchsql_test 210 { + PRAGMA integrity_check; +} {1 {database disk image is malformed}} +do_execsql_test 220 { + SELECT pgno, quote(substr(data,1,5)) FROM sqlite_dbpage('main') ORDER BY pgno; +} {1 X'53514C6974' 2 X'0500000001' 3 X'0D0000004E' 4 X'0000000000'} +do_execsql_test 230 { + UPDATE sqlite_dbpage SET data=(SELECT x FROM saved_content) WHERE pgno=4; +} {} +do_catchsql_test 230 { + PRAGMA integrity_check; +} {0 ok} +do_execsql_test 240 { + DELETE FROM saved_content; + INSERT INTO saved_content(x) + SELECT data FROM sqlite_dbpage WHERE schema='aux1' AND pgno=2; +} {} +do_execsql_test 241 { + UPDATE sqlite_dbpage SET data=zeroblob(4096) WHERE pgno=2 AND schema='aux1'; +} {} +do_catchsql_test 250 { + PRAGMA aux1.integrity_check; +} {1 {database disk image is malformed}} +do_execsql_test 260 { + UPDATE sqlite_dbpage SET data=(SELECT x FROM saved_content) + WHERE pgno=2 AND schema='aux1'; +} {} +do_catchsql_test 270 { + PRAGMA aux1.integrity_check; +} {0 ok} + +db close +sqlite3 db :memory: +do_execsql_test 300 { + SELECT * FROM sqlite_temp_schema, sqlite_dbpage; +} {} + +finish_test diff --git a/test/dbpagefault.test b/test/dbpagefault.test new file mode 100644 index 0000000..f27741c --- /dev/null +++ b/test/dbpagefault.test @@ -0,0 +1,86 @@ +# 2022 July 06 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/lock_common.tcl +source $testdir/malloc_common.tcl + +if {[permutation] == "inmemory_journal"} { + finish_test + return +} + +ifcapable !vtab { + finish_test + return +} + +set testprefix dbpagefault + +faultsim_save_and_close +do_faultsim_test 1 -prep { + faultsim_restore_and_reopen + execsql { ATTACH 'test.db2' AS aux; } +} -body { + execsql { + CREATE VIRTUAL TABLE t1 USING sqlite_dbpage(); + } +} -test { + execsql { PRAGMA journal_mode = off } + faultsim_test_result {0 {}} +} + +do_faultsim_test 2 -prep { + sqlite3 db "xyz.db" -vfs memdb + execsql { ATTACH 'test.db2' AS aux; } +} -body { + execsql { + CREATE VIRTUAL TABLE t1 USING sqlite_dbpage(); + UPDATE t1 SET data=zeroblob(1024) WHERE pgno=1 AND schema='aux'; + } +} -test { + execsql { PRAGMA journal_mode = off } + faultsim_test_result {0 {}} {1 {no such schema}} {1 {SQL logic error}} {1 {unable to open a temporary database file for storing temporary tables}} +} + +reset_db +do_execsql_test 3.0 { + CREATE TABLE x1(z, b); + CREATE TRIGGER BEFORE INSERT ON x1 BEGIN + DELETE FROM sqlite_dbpage WHERE pgno=100; + UPDATE sqlite_dbpage SET data=null WHERE pgno=100; + END; +} + +# This test case no longer works, as it is no longer possible to use +# virtual table sqlite_dbpage from within a trigger. +# +do_execsql_test 3.1 { + PRAGMA trusted_schema = 1; +} +do_catchsql_test 3.2 { + PRAGMA trusted_schema = 1; + INSERT INTO x1 DEFAULT VALUES; +} {1 {unsafe use of virtual table "sqlite_dbpage"}} +#do_faultsim_test 3 -prep { +# catch { db close } +# sqlite3 db test.db +# execsql { PRAGMA trusted_schema = 1 } +#} -body { +# execsql { INSERT INTO x1 DEFAULT VALUES; } +#} -test { +# faultsim_test_result {0 {}} +#} + + +finish_test diff --git a/test/dbstatus.test b/test/dbstatus.test new file mode 100644 index 0000000..8d5d834 --- /dev/null +++ b/test/dbstatus.test @@ -0,0 +1,457 @@ +# 2010 March 10 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Tests for the sqlite3_db_status() function +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix dbstatus + +ifcapable !compound { + finish_test + return +} + +# Memory statistics must be enabled for this test. +db close +sqlite3_shutdown +sqlite3_config_memstatus 1 +sqlite3_config_uri 1 +sqlite3_initialize +sqlite3 db test.db + + +# Make sure sqlite3_db_config() and sqlite3_db_status are working. +# +unset -nocomplain PAGESZ +unset -nocomplain BASESZ +do_test dbstatus-1.1 { + db close + sqlite3 db :memory: + db eval { + CREATE TABLE t1(x); + } + set sz1 [lindex [sqlite3_db_status db SQLITE_DBSTATUS_CACHE_USED 0] 1] + db eval { + CREATE TABLE t2(y); + } + set sz2 [lindex [sqlite3_db_status db SQLITE_DBSTATUS_CACHE_USED 0] 1] + set ::PAGESZ [expr {$sz2-$sz1}] + set ::BASESZ [expr {$sz1-$::PAGESZ}] + expr {$::PAGESZ>1024 && $::PAGESZ<1300} +} {1} +do_test dbstatus-1.2 { + db eval { + INSERT INTO t1 VALUES(zeroblob(9000)); + } + lindex [sqlite3_db_status db SQLITE_DBSTATUS_CACHE_USED 0] 1 +} [expr {$BASESZ + 10*$PAGESZ}] + + +proc lookaside {db} { + expr { $::lookaside_buffer_size * + [lindex [sqlite3_db_status $db SQLITE_DBSTATUS_LOOKASIDE_USED 0] 1] + } +} + +ifcapable stat4 { + set STAT3 1 +} else { + set STAT3 0 +} + +#--------------------------------------------------------------------------- +# Run the dbstatus-2 and dbstatus-3 tests with several of different +# lookaside buffer sizes. +# +foreach ::lookaside_buffer_size {0 64 120} { + ifcapable malloc_usable_size break + + # Do not run any of these tests if there is SQL configured to run + # as part of the [sqlite3] command. This prevents the script from + # configuring the size of the lookaside buffer after [sqlite3] has + # returned. + if {[presql] != ""} break + + #------------------------------------------------------------------------- + # Tests for SQLITE_DBSTATUS_SCHEMA_USED. + # + # Each test in the following block works as follows. Each test uses a + # different database schema. + # + # 1. Open a connection to an empty database. Disable statement caching. + # + # 2. Execute the SQL to create the database schema. Measure the total + # heap and lookaside memory allocated by SQLite, and the memory + # allocated for the database schema according to sqlite3_db_status(). + # + # 3. Drop all tables in the database schema. Measure the total memory + # and the schema memory again. + # + # 4. Repeat step 2. + # + # 5. Repeat step 3. + # + # Then test that: + # + # a) The difference in schema memory quantities in steps 2 and 3 is the + # same as the difference in total memory in steps 2 and 3. + # + # b) Step 4 reports the same amount of schema and total memory used as + # in step 2. + # + # c) Step 5 reports the same amount of schema and total memory used as + # in step 3. + # + foreach {tn schema} { + 1 { CREATE TABLE t1(a, b) } + 2 { CREATE TABLE t1(a PRIMARY KEY, b REFERENCES t1, c UNIQUE) } + 3 { + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a, b); + } + 4 { + CREATE TABLE t1(a, b); + CREATE TABLE t2(c, d); + CREATE TRIGGER AFTER INSERT ON t1 BEGIN + INSERT INTO t2 VALUES(new.a, new.b); + SELECT * FROM t1, t2 WHERE a=c AND b=d GROUP BY b HAVING a>5 ORDER BY a; + END; + } + 5 { + CREATE TABLE t1(a, b); + CREATE TABLE t2(c, d); + CREATE VIEW v1 AS SELECT * FROM t1 UNION SELECT * FROM t2; + } + 6k { + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a); + CREATE INDEX i2 ON t1(a,b); + CREATE INDEX i3 ON t1(b,b); + INSERT INTO t1 VALUES(randomblob(20), randomblob(25)); + INSERT INTO t1 SELECT randomblob(20), randomblob(25) FROM t1; + INSERT INTO t1 SELECT randomblob(20), randomblob(25) FROM t1; + INSERT INTO t1 SELECT randomblob(20), randomblob(25) FROM t1; + ANALYZE; + } + 7 { + CREATE TABLE t1(a, b); + CREATE TABLE t2(c, d); + CREATE VIEW v1 AS + SELECT * FROM t1 + UNION + SELECT * FROM t2 + UNION ALL + SELECT c||b, d||a FROM t2 LEFT OUTER JOIN t1 GROUP BY c, d + ORDER BY 1, 2 + ; + CREATE TRIGGER tr1 INSTEAD OF INSERT ON v1 BEGIN + SELECT * FROM v1; + UPDATE t1 SET a=5, b=(SELECT c FROM t2); + END; + SELECT * FROM v1; + } + 8x { + CREATE TABLE t1(a, b, UNIQUE(a, b)); + CREATE VIRTUAL TABLE t2 USING echo(t1); + } + } { + set tn "$::lookaside_buffer_size-$tn" + + # Step 1. + db close + forcedelete test.db + sqlite3 db test.db + sqlite3_db_config_lookaside db 0 $::lookaside_buffer_size 500 + db cache size 0 + + catch { register_echo_module db } + ifcapable !vtab { if {[string match *x $tn]} continue } + + # Step 2. + execsql $schema + set nAlloc1 [lindex [sqlite3_status SQLITE_STATUS_MEMORY_USED 0] 1] + incr nAlloc1 [lookaside db] + set nSchema1 [lindex [sqlite3_db_status db SQLITE_DBSTATUS_SCHEMA_USED 0] 1] + + # Step 3. + drop_all_tables + set nAlloc2 [lindex [sqlite3_status SQLITE_STATUS_MEMORY_USED 0] 1] + incr nAlloc2 [lookaside db] + set nSchema2 [lindex [sqlite3_db_status db SQLITE_DBSTATUS_SCHEMA_USED 0] 1] + + # Step 4. + execsql $schema + set nAlloc3 [lindex [sqlite3_status SQLITE_STATUS_MEMORY_USED 0] 1] + incr nAlloc3 [lookaside db] + set nSchema3 [lindex [sqlite3_db_status db SQLITE_DBSTATUS_SCHEMA_USED 0] 1] + + # Step 5. + drop_all_tables + set nAlloc4 [lindex [sqlite3_status SQLITE_STATUS_MEMORY_USED 0] 1] + incr nAlloc4 [lookaside db] + set nSchema4 [lindex [sqlite3_db_status db SQLITE_DBSTATUS_SCHEMA_USED 0] 1] + set nFree [expr {$nAlloc1-$nAlloc2}] + + # Tests for which the test name ends in an "k" report slightly less + # memory than is actually freed when all schema items are finalized. + # This is because memory allocated by KeyInfo objects is no longer + # counted as "schema memory". + # + # Tests for which the test name ends in an "x" report slightly less + # memory than is actually freed when all schema items are finalized. + # This is because memory allocated by virtual table implementations + # for any reason is not counted as "schema memory". + # + # Additionally, in auto-vacuum mode, dropping tables and indexes causes + # the page-cache to shrink. So the amount of memory freed is always + # much greater than just that reported by DBSTATUS_SCHEMA_USED in this + # case. + # + # Some of the memory used for sqlite_stat4 is unaccounted for by + # dbstatus. + # + # Finally, on osx the estimate of memory used by the schema may be + # slightly low. + # + if {[string match *k $tn] + || [string match *x $tn] || $AUTOVACUUM + || ([string match *y $tn] && $STAT3) + || ($::tcl_platform(os) == "Darwin") + } { + do_test dbstatus-2.$tn.ax { expr {($nSchema1-$nSchema2)<=$nFree} } 1 + } else { + do_test dbstatus-2.$tn.a { expr {$nSchema1-$nSchema2} } $nFree + } + + do_test dbstatus-2.$tn.b { list $nAlloc1 $nSchema1 } "$nAlloc3 $nSchema3" + do_test dbstatus-2.$tn.c { list $nAlloc2 $nSchema2 } "$nAlloc4 $nSchema4" + } + + #------------------------------------------------------------------------- + # Tests for SQLITE_DBSTATUS_STMT_USED. + # + # Each test in the following block works as follows. Each test uses a + # different database schema. + # + # 1. Open a connection to an empty database. Initialized the database + # schema. + # + # 2. Prepare a bunch of SQL statements. Measure the total heap and + # lookaside memory allocated by SQLite, and the memory allocated + # for the prepared statements according to sqlite3_db_status(). + # + # 3. Finalize all prepared statements. Measure the total memory + # and the prepared statement memory again. + # + # 4. Repeat step 2. + # + # 5. Repeat step 3. + # + # Then test that: + # + # a) The difference in schema memory quantities in steps 2 and 3 is the + # same as the difference in total memory in steps 2 and 3. + # + # b) Step 4 reports the same amount of schema and total memory used as + # in step 2. + # + # c) Step 5 reports the same amount of schema and total memory used as + # in step 3. + # + foreach {tn schema statements} { + 1 { CREATE TABLE t1(a, b) } { + SELECT * FROM t1; + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t1 SELECT * FROM t1; + UPDATE t1 SET a=5; + DELETE FROM t1; + } + 2 { + PRAGMA recursive_triggers = 1; + CREATE TABLE t1(a, b); + CREATE TRIGGER tr1 AFTER INSERT ON t1 WHEN (new.a>0) BEGIN + INSERT INTO t1 VALUES(new.a-1, new.b); + END; + } { + INSERT INTO t1 VALUES(5, 'x'); + } + 3 { + PRAGMA recursive_triggers = 1; + CREATE TABLE t1(a, b); + CREATE TABLE t2(a, b); + CREATE TRIGGER tr1 AFTER INSERT ON t1 WHEN (new.a>0) BEGIN + INSERT INTO t2 VALUES(new.a-1, new.b); + END; + CREATE TRIGGER tr2 AFTER INSERT ON t1 WHEN (new.a>0) BEGIN + INSERT INTO t1 VALUES(new.a-1, new.b); + END; + } { + INSERT INTO t1 VALUES(10, 'x'); + } + 4 { + CREATE TABLE t1(a, b); + } { + SELECT count(*) FROM t1 WHERE upper(a)='ABC'; + } + 5x { + CREATE TABLE t1(a, b UNIQUE); + CREATE VIRTUAL TABLE t2 USING echo(t1); + } { + SELECT count(*) FROM t2; + SELECT * FROM t2 WHERE b>5; + SELECT * FROM t2 WHERE b='abcdefg'; + } + } { + set tn "$::lookaside_buffer_size-$tn" + + # Step 1. + db close + forcedelete test.db + sqlite3 db test.db + sqlite3_db_config_lookaside db 0 $::lookaside_buffer_size 500 + db cache size 1000 + + catch { register_echo_module db } + ifcapable !vtab { if {[string match *x $tn]} continue } + + execsql $schema + db cache flush + + # Step 2. + execsql $statements + set nAlloc1 [lindex [sqlite3_status SQLITE_STATUS_MEMORY_USED 0] 1] + incr nAlloc1 [lookaside db] + set nStmt1 [lindex [sqlite3_db_status db SQLITE_DBSTATUS_STMT_USED 0] 1] + execsql $statements + + # Step 3. + db cache flush + set nAlloc2 [lindex [sqlite3_status SQLITE_STATUS_MEMORY_USED 0] 1] + incr nAlloc2 [lookaside db] + set nStmt2 [lindex [sqlite3_db_status db SQLITE_DBSTATUS_STMT_USED 0] 1] + + # Step 3. + execsql $statements + set nAlloc3 [lindex [sqlite3_status SQLITE_STATUS_MEMORY_USED 0] 1] + incr nAlloc3 [lookaside db] + set nStmt3 [lindex [sqlite3_db_status db SQLITE_DBSTATUS_STMT_USED 0] 1] + execsql $statements + + # Step 4. + db cache flush + set nAlloc4 [lindex [sqlite3_status SQLITE_STATUS_MEMORY_USED 0] 1] + incr nAlloc4 [lookaside db] + set nStmt4 [lindex [sqlite3_db_status db SQLITE_DBSTATUS_STMT_USED 0] 1] + + set nFree [expr {$nAlloc1-$nAlloc2}] + + do_test dbstatus-3.$tn.a { expr $nStmt2 } {0} + + # Tests for which the test name ends in an "x" report slightly less + # memory than is actually freed when all statements are finalized. + # This is because a small amount of memory allocated by a virtual table + # implementation using sqlite3_mprintf() is technically considered + # external and so is not counted as "statement memory". + # +#puts "$nStmt1 $nFree" + if {[string match *x $tn]} { + do_test dbstatus-3.$tn.bx { expr $nStmt1<=$nFree } {1} + } else { + do_test dbstatus-3.$tn.b { expr $nStmt1==$nFree } {1} + } + + do_test dbstatus-3.$tn.c { list $nAlloc1 $nStmt1 } [list $nAlloc3 $nStmt3] + do_test dbstatus-3.$tn.d { list $nAlloc2 $nStmt2 } [list $nAlloc4 $nStmt4] + } +} + +#------------------------------------------------------------------------- +# The following tests focus on DBSTATUS_CACHE_USED_SHARED +# +ifcapable shared_cache { + if {([permutation]=="memsys3" + || [permutation]=="memsys5" + || $::tcl_platform(os)=="Linux") && ![sqlite3 -has-codec]} { + proc do_cacheused_test {tn db res} { + set cu [sqlite3_db_status $db SQLITE_DBSTATUS_CACHE_USED 0] + set pcu [sqlite3_db_status $db SQLITE_DBSTATUS_CACHE_USED_SHARED 0] + set cu [lindex $cu 1] + set pcu [lindex $pcu 1] + uplevel [list do_test $tn [list list $cu $pcu] "#/$res/"] + } + reset_db + sqlite3 db file:test.db?cache=shared + + do_execsql_test 4.0 { + PRAGMA auto_vacuum=NONE; + CREATE TABLE t1(a, b, c); + INSERT INTO t1 VALUES(1, 2, 3); + } + do_cacheused_test 4.0.1 db { 4568 4568 } + do_execsql_test 4.1 { + CREATE TEMP TABLE tt(a, b, c); + INSERT INTO tt VALUES(1, 2, 3); + } + do_cacheused_test 4.1.1 db { 9000 9000 } + + sqlite3 db2 file:test.db?cache=shared + do_cacheused_test 4.2.1 db2 { 4568 2284 } + do_cacheused_test 4.2.2 db { 9000 6716 } + db close + do_cacheused_test 4.2.3 db2 { 4568 4568 } + sqlite3 db file:test.db?cache=shared + do_cacheused_test 4.2.4 db2 { 4568 2284 } + db2 close + } +} + +#------------------------------------------------------------------------- +# Test that passing an out-of-range value to sqlite3_stmt_status does +# not cause a crash. +reset_db +do_execsql_test 5.0 { + CREATE TABLE t1(x, y); + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t1 VALUES(3, 4); +} + +do_test 5.1 { + set ::stmt [sqlite3_prepare db "SELECT * FROM t1" -1 dummy] + sqlite3_step $::stmt + sqlite3_step $::stmt + sqlite3_step $::stmt + sqlite3_reset $::stmt +} {SQLITE_OK} + +ifcapable api_armor { + do_test 5.2 { sqlite3_stmt_status $::stmt -1 0 } 0 +} +do_test 5.3 { sqlite3_stmt_status $::stmt 0 0 } 0 +do_test 5.4 { + expr [sqlite3_stmt_status $::stmt 99 0]>0 +} 1 +foreach {tn id res} { + 1 SQLITE_STMTSTATUS_MEMUSED 1 + 2 SQLITE_STMTSTATUS_FULLSCAN_STEP 1 + 3 SQLITE_STMTSTATUS_SORT 0 + 4 SQLITE_STMTSTATUS_AUTOINDEX 0 + 5 SQLITE_STMTSTATUS_VM_STEP 1 + 6 SQLITE_STMTSTATUS_REPREPARE 0 + 7 SQLITE_STMTSTATUS_RUN 1 +} { +if {$tn==2} breakpoint + do_test 5.5.$tn { expr [sqlite3_stmt_status $::stmt $id 0]>0 } $res +} + +sqlite3_finalize $::stmt +finish_test diff --git a/test/dbstatus2.test b/test/dbstatus2.test new file mode 100644 index 0000000..5e9ea88 --- /dev/null +++ b/test/dbstatus2.test @@ -0,0 +1,115 @@ +# 2011 September 20 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Tests for the sqlite3_db_status() function +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +set ::testprefix dbstatus2 + +do_execsql_test 1.0 { + PRAGMA page_size = 1024; + PRAGMA auto_vacuum = 0; + + CREATE TABLE t1(a PRIMARY KEY, b); + INSERT INTO t1 VALUES(1, randomblob(600)); + INSERT INTO t1 VALUES(2, randomblob(600)); + INSERT INTO t1 VALUES(3, randomblob(600)); +} + +proc db_hit_miss {db {reset 0}} { + set nHit [sqlite3_db_status $db CACHE_HIT $reset] + set nMiss [sqlite3_db_status $db CACHE_MISS $reset] + list $nHit $nMiss +} + +proc db_write {db {reset 0}} { + sqlite3_db_status $db CACHE_WRITE $reset +} + +proc db_spill {db {reset 0}} { + sqlite3_db_status $db CACHE_SPILL $reset +} + +do_test 1.1 { + db close + sqlite3 db test.db + execsql { PRAGMA mmap_size = 0 } + expr {[file size test.db] / 1024} +} 6 + +do_test 1.2 { + execsql { SELECT b FROM t1 WHERE a=2 } + db_hit_miss db +} {{0 2 0} {0 4 0}} + +do_test 1.3 { + execsql { SELECT b FROM t1 WHERE a=2 } + db_hit_miss db +} {{0 6 0} {0 4 0}} + +do_test 1.4 { + execsql { SELECT b FROM t1 WHERE a=2 } + db_hit_miss db +} {{0 10 0} {0 4 0}} + +do_test 1.5 { + db_hit_miss db 1 +} {{0 10 0} {0 4 0}} + +do_test 1.6 { + db_hit_miss db 0 +} {{0 0 0} {0 0 0}} + +do_test 1.7 { + set fd [db incrblob main t1 b 1] + fconfigure $fd -translation binary + set len [string length [read $fd]] + close $fd + set len +} 600 +do_test 1.8 { sqlite3_db_status db CACHE_HIT 0 } {0 2 0} +do_test 1.9 { sqlite3_db_status db CACHE_MISS 0 } {0 1 0} + +do_test 2.1 { db_write db } {0 0 0} +do_test 2.2 { + execsql { INSERT INTO t1 VALUES(4, randomblob(600)) } + db_write db +} {0 4 0} +do_test 2.3 { db_write db 1 } {0 4 0} +do_test 2.4 { db_write db 0 } {0 0 0} +do_test 2.5 { db_write db 1 } {0 0 0} + +if {[wal_is_capable]} { + do_test 2.6 { + execsql { PRAGMA journal_mode = WAL } + db_write db 1 + } {0 1 0} +} +do_test 2.7 { + execsql { INSERT INTO t1 VALUES(5, randomblob(600)) } + db_write db +} {0 4 0} +do_test 2.8 { db_write db 1 } {0 4 0} +do_test 2.9 { db_write db 0 } {0 0 0} + +do_test 3.0 { db_spill db 1 } {0 0 0} +do_test 3.1 { db_spill db 0 } {0 0 0} +do_execsql_test 3.2 { + PRAGMA journal_mode=DELETE; + PRAGMA cache_size=3; + UPDATE t1 SET b=randomblob(1000); +} {delete} +do_test 3.3 { db_spill db 0 } {0 8 0} + +finish_test diff --git a/test/decimal.test b/test/decimal.test new file mode 100644 index 0000000..cf4e06a --- /dev/null +++ b/test/decimal.test @@ -0,0 +1,193 @@ +# 2017 December 9 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix decimal + +if {[catch {load_static_extension db decimal} error]} { + puts "Skipping decimal tests, hit load error: $error" + finish_test; return +} + +do_execsql_test 1000 { + SELECT decimal(1); +} {1} +do_execsql_test 1010 { + SELECT decimal('1.0'); +} {1.0} +do_execsql_test 1020 { + SELECT decimal('0001.0'); +} {1.0} +do_execsql_test 1030 { + SELECT decimal('+0001.0'); +} {1.0} +do_execsql_test 1040 { + SELECT decimal('-0001.0'); +} {-1.0} +do_execsql_test 1050 { + SELECT decimal('1.0e72'); +} {1000000000000000000000000000000000000000000000000000000000000000000000000} +# 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123 +do_execsql_test 1060 { + SELECT decimal('1.0e-72'); +} {0.0000000000000000000000000000000000000000000000000000000000000000000000010} +# 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123 +do_execsql_test 1070 { + SELECT decimal('-123e-4'); +} {-0.0123} +do_execsql_test 1080 { + SELECT decimal('+123e+4'); +} {1230000} +do_execsql_test 1081 { + SELECT decimal_exp('+123e+4'); +} {+1.23e+06} + + +do_execsql_test 2000 { + CREATE TABLE t1(seq INTEGER PRIMARY KEY, val TEXT); + INSERT INTO t1 VALUES + (1, '-9999e99'), + (2, '-9998.000e+99'), + (3, '-9999.0'), + (4, '-1'), + (5, '-9999e-20'), + (6, '0'), + (7, '1e-30'), + (8, '1e-29'), + (9, '1'), + (10,'1.00000000000000001'), + (11,'+1.00001'), + (12,'99e+99'); + SELECT *, '|' + FROM t1 AS a, t1 AS b + WHERE a.seq=0; +} {} +do_execsql_test 2010 { + SELECT *, '|' + FROM t1 AS a, t1 AS b + WHERE a.seq<>b.seq + AND decimal_cmp(a.val,b.val)==0; +} {} +do_execsql_test 2020 { + SELECT *, '|' + FROM t1 AS a, t1 AS b + WHERE a.seq>b.seq + AND decimal_cmp(a.val,b.val)<=0; +} {} +do_execsql_test 2030 { + SELECT seq FROM t1 ORDER BY val COLLATE decimal; +} {1 2 3 4 5 6 7 8 9 10 11 12} +do_execsql_test 2040 { + SELECT seq FROM t1 ORDER BY val COLLATE decimal DESC; +} {12 11 10 9 8 7 6 5 4 3 2 1} + +do_execsql_test 3000 { + CREATE TABLE t3(seq INTEGER PRIMARY KEY, val TEXT); + WITH RECURSIVE c(x) AS (VALUES(1) UNION SELECT x+1 FROM c WHERE x<10) + INSERT INTO t3(seq, val) SELECT x, x FROM c; + WITH RECURSIVE c(x) AS (VALUES(1) UNION SELECT x+1 FROM c WHERE x<5) + INSERT INTO t3(seq, val) SELECT x+10, x*1000 FROM c; + SELECT decimal(val) FROM t3 ORDER BY seq; +} {1 2 3 4 5 6 7 8 9 10 1000 2000 3000 4000 5000} +do_execsql_test 3020 { + SELECT decimal_add(val,'0.5') FROM t3 WHERE seq>5 ORDER BY seq +} {6.5 7.5 8.5 9.5 10.5 1000.5 2000.5 3000.5 4000.5 5000.5} +do_execsql_test 3030 { + SELECT decimal_add(val,'-10') FROM t3 ORDER BY seq; +} {-9 -8 -7 -6 -5 -4 -3 -2 -1 0 990 1990 2990 3990 4990} + +do_execsql_test 4000 { + SELECT decimal_sum(val) FROM t3; +} {15055} +do_execsql_test 4010 { + SELECT decimal_sum(decimal_add(val,val||'e+10')) FROM t3; +} {150550000015055} +do_execsql_test 4010 { + SELECT decimal_sum(decimal_add(val||'e+20',decimal_add(val,val||'e-20'))) + FROM t3; +} {1505500000000000000015055.00000000000000015055} + +do_execsql_test 5000 { + WITH RECURSIVE c(x,y,z) AS ( + VALUES(0,'1','1') + UNION ALL + SELECT x+1, decimal_mul(y,'2'), decimal_mul(z,'0.5') + FROM c WHERE x<32 + ) + SELECT count(*) FROM c WHERE decimal_mul(y,z)='1'; +} {33} + +do_execsql_test 5100 { + SELECT decimal_mul('1234.00','2.00'); +} {2468.00} +do_execsql_test 5101 { + SELECT decimal_mul('1234.00','2.0000'); +} {2468.00} +do_execsql_test 5102 { + SELECT decimal_mul('1234.0000','2.000'); +} {2468.000} +do_execsql_test 5103 { + SELECT decimal_mul('1234.0000','2'); +} {2468} + +if {[catch {load_static_extension db ieee754} error]} { + puts "Skipping ieee754 tests, hit load error: $error" + finish_test; return +} + +do_execsql_test 6000 { + CREATE TABLE pow2(x INTEGER PRIMARY KEY, v TEXT); + WITH RECURSIVE c(x,v) AS ( + VALUES(0,'1') + UNION ALL + SELECT x+1, decimal_mul(v,'2') FROM c WHERE x+1<=971 + ) INSERT INTO pow2(x,v) SELECT x, v FROM c; + WITH RECURSIVE c(x,v) AS ( + VALUES(-1,'0.5') + UNION ALL + SELECT x-1, decimal_mul(v,'0.5') FROM c WHERE x-1>=-1075 + ) INSERT INTO pow2(x,v) SELECT x, v FROM c; +} {} +do_execsql_test 6010 { + WITH c(n) AS (SELECT ieee754_from_blob(x'0000000000000001')) +SELECT decimal_mul(ieee754_mantissa(c.n),pow2.v) + FROM pow2, c WHERE pow2.x=ieee754_exponent(c.n); +} {0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004940656458412465441765687928682213723650598026143247644255856825006755072702087518652998363616359923797965646954457177309266567103559397963987747960107818781263007131903114045278458171678489821036887186360569987307230500063874091535649843873124733972731696151400317153853980741262385655911710266585566867681870395603106249319452715914924553293054565444011274801297099995419319894090804165633245247571478690147267801593552386115501348035264934720193790268107107491703332226844753335720832431936092382893458368060106011506169809753078342277318329247904982524730776375927247874656084778203734469699533647017972677717585125660551199131504891101451037862738167250955837389733598993664809941164205702637090279242767544565229087538682506419718265533447265625} +do_execsql_test 6011 { + WITH c(n) AS (SELECT ieee754_from_blob(x'0000000000000001')) +SELECT decimal(c.n) FROM c; +} {0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004940656458412465441765687928682213723650598026143247644255856825006755072702087518652998363616359923797965646954457177309266567103559397963987747960107818781263007131903114045278458171678489821036887186360569987307230500063874091535649843873124733972731696151400317153853980741262385655911710266585566867681870395603106249319452715914924553293054565444011274801297099995419319894090804165633245247571478690147267801593552386115501348035264934720193790268107107491703332226844753335720832431936092382893458368060106011506169809753078342277318329247904982524730776375927247874656084778203734469699533647017972677717585125660551199131504891101451037862738167250955837389733598993664809941164205702637090279242767544565229087538682506419718265533447265625} +do_execsql_test 6020 { + WITH c(n) AS (SELECT ieee754_from_blob(x'7fefffffffffffff')) +SELECT decimal_mul(ieee754_mantissa(c.n),pow2.v) + FROM pow2, c WHERE pow2.x=ieee754_exponent(c.n); +} {179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368} + +do_execsql_test 6100 { + SELECT ieee754(ieee754_from_blob(x'0000000000000001')); +} {ieee754(1,-1074)} +do_execsql_test 6110 { + SELECT ieee754(ieee754_from_blob(x'7fefffffffffffff')); +} {ieee754(9007199254740991,971)} +do_execsql_test 6120 { + SELECT printf('%.8e',ieee754_from_blob(x'0000000000000001')); +} {4.94065646e-324} +do_execsql_test 6130 { + SELECT printf('%.8e',ieee754_from_blob(x'ffefffffffffffff')); +} {-1.79769313e+308} + + + + +finish_test diff --git a/test/default.test b/test/default.test new file mode 100644 index 0000000..06a180c --- /dev/null +++ b/test/default.test @@ -0,0 +1,140 @@ +# 2005 August 18 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this file is testing corner cases of the DEFAULT syntax +# on table definitions. +# +# $Id: default.test,v 1.3 2009/02/19 14:39:25 danielk1977 Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable bloblit { + do_test default-1.1 { + execsql { + CREATE TABLE t1( + a INTEGER, + b BLOB DEFAULT x'6869' + ); + INSERT INTO t1(a) VALUES(1); + SELECT * from t1; + } + } {1 hi} +} +do_test default-1.2 { + execsql { + CREATE TABLE t2( + x INTEGER, + y INTEGER DEFAULT NULL + ); + INSERT INTO t2(x) VALUES(1); + SELECT * FROM t2; + } +} {1 {}} +do_test default-1.3 { + catchsql { + CREATE TABLE t3( + x INTEGER, + y INTEGER DEFAULT (max(x,5)) + ) + } +} {1 {default value of column [y] is not constant}} + +ifcapable pragma { + do_test default-2.1 { + execsql { + CREATE TABLE t4(c DEFAULT 'abc'); + PRAGMA table_info(t4); + } + } {0 c {} 0 'abc' 0} + do_test default-2.2 { + execsql { + INSERT INTO t4 DEFAULT VALUES; + PRAGMA table_info(t4); + } + } {0 c {} 0 'abc' 0} +} + +do_execsql_test default-3.1 { + CREATE TABLE t3( + a INTEGER PRIMARY KEY AUTOINCREMENT, + b INT DEFAULT 12345 UNIQUE NOT NULL CHECK( b>=0 AND b<99999 ), + c VARCHAR(123,456) DEFAULT 'hello' NOT NULL ON CONFLICT REPLACE, + d REAL, + e FLOATING POINT(5,10) DEFAULT 4.36, + f NATIONAL CHARACTER(15) COLLATE RTRIM, + g LONG INTEGER DEFAULT( 3600*12 ) + ); + INSERT INTO t3 VALUES(null, 5, 'row1', '5.25', 'xyz', 321, '432'); + SELECT a, typeof(a), b, typeof(b), c, typeof(c), + d, typeof(d), e, typeof(e), f, typeof(f), + g, typeof(g) FROM t3; +} {1 integer 5 integer row1 text 5.25 real xyz text 321 text 432 integer} +do_execsql_test default-3.2 { + DELETE FROM t3; + INSERT INTO t3 DEFAULT VALUES; + SELECT * FROM t3; +} {2 12345 hello {} 4.36 {} 43200} +do_execsql_test default-3.3 { + CREATE TABLE t300( + a INT DEFAULT 2147483647, + b INT DEFAULT 2147483648, + c INT DEFAULT +9223372036854775807, + d INT DEFAULT -2147483647, + e INT DEFAULT -2147483648, + f INT DEFAULT -9223372036854775808, + g INT DEFAULT (-(-9223372036854775808)), + h INT DEFAULT (-(-9223372036854775807)) + ); + INSERT INTO t300 DEFAULT VALUES; + SELECT * FROM t300; +} {2147483647 2147483648 9223372036854775807 -2147483647 -2147483648 -9223372036854775808 9.22337203685478e+18 9223372036854775807} + +# Do now allow bound parameters in new DEFAULT values. +# Silently convert bound parameters to NULL in DEFAULT causes +# in the sqlite_master table, for backwards compatibility. +# +db close +forcedelete test.db +sqlite3 db test.db +sqlite3_db_config db DEFENSIVE 0 +do_execsql_test default-4.0 { + CREATE TABLE t1(a TEXT, b TEXT DEFAULT(99)); + PRAGMA writable_schema=ON; + UPDATE sqlite_master SET sql='CREATE TABLE t1(a TEXT, b TEXT DEFAULT(:xyz))'; +} {} +db close +sqlite3 db test.db +do_execsql_test default-4.1 { + INSERT INTO t1(a) VALUES('xyzzy'); + SELECT a, quote(b) FROM t1; +} {xyzzy NULL} +do_catchsql_test default-4.2 { + CREATE TABLE t2(a TEXT, b TEXT DEFAULT(:xyz)); +} {1 {default value of column [b] is not constant}} +do_catchsql_test default-4.3 { + CREATE TABLE t2(a TEXT, b TEXT DEFAULT(abs(:xyz))); +} {1 {default value of column [b] is not constant}} +do_catchsql_test default-4.4 { + CREATE TABLE t2(a TEXT, b TEXT DEFAULT(98+coalesce(5,:xyz))); +} {1 {default value of column [b] is not constant}} + +# 2020-03-09 out-of-bounds memory access discovered by "Eternal Sakura" +# and reported to chromium. +# +reset_db +do_catchsql_test default-5.1 { + CREATE TABLE t1 (a,b DEFAULT(random() NOTNULL IN (RAISE(IGNORE),2,3))); + INSERT INTO t1(a) VALUES(1); +} {1 {RAISE() may only be used within a trigger-program}} + +finish_test diff --git a/test/delete.test b/test/delete.test new file mode 100644 index 0000000..214bae6 --- /dev/null +++ b/test/delete.test @@ -0,0 +1,443 @@ +# 2001 September 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing the DELETE FROM statement. +# +# $Id: delete.test,v 1.26 2009/06/05 17:09:12 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Try to delete from a non-existant table. +# +do_test delete-1.1 { + set v [catch {execsql {DELETE FROM test1}} msg] + lappend v $msg +} {1 {no such table: test1}} + +# Try to delete from sqlite_master +# +do_test delete-2.1 { + set v [catch {execsql {DELETE FROM sqlite_master}} msg] + lappend v $msg +} {1 {table sqlite_master may not be modified}} + +# Delete selected entries from a table with and without an index. +# +do_test delete-3.1.1 { + execsql {CREATE TABLE table1(f1 int, f2 int)} + execsql {INSERT INTO table1 VALUES(1,2)} + execsql {INSERT INTO table1 VALUES(2,4)} + execsql {INSERT INTO table1 VALUES(3,8)} + execsql {INSERT INTO table1 VALUES(4,16)} + execsql {SELECT * FROM table1 ORDER BY f1} +} {1 2 2 4 3 8 4 16} +do_test delete-3.1.2 { + execsql {DELETE FROM table1 WHERE f1=3} +} {} +do_test delete-3.1.3 { + execsql {SELECT * FROM table1 ORDER BY f1} +} {1 2 2 4 4 16} +do_test delete-3.1.4 { + execsql {CREATE INDEX index1 ON table1(f1)} + execsql {PRAGMA count_changes=on} + ifcapable explain { + execsql {EXPLAIN DELETE FROM table1 WHERE f1=3} + } + execsql {DELETE FROM 'table1' WHERE f1=3} +} {0} +do_test delete-3.1.5 { + execsql {SELECT * FROM table1 ORDER BY f1} +} {1 2 2 4 4 16} +do_test delete-3.1.6.1 { + execsql {DELETE FROM table1 WHERE f1=2} +} {1} +do_test delete-3.1.6.2 { + db changes +} 1 +do_test delete-3.1.7 { + execsql {SELECT * FROM table1 ORDER BY f1} +} {1 2 4 16} +integrity_check delete-3.2 + +# Semantic errors in the WHERE clause +# +do_test delete-4.1 { + execsql {CREATE TABLE table2(f1 int, f2 int)} + set v [catch {execsql {DELETE FROM table2 WHERE f3=5}} msg] + lappend v $msg +} {1 {no such column: f3}} + +do_test delete-4.2 { + set v [catch {execsql {DELETE FROM table2 WHERE xyzzy(f1+4)}} msg] + lappend v $msg +} {1 {no such function: xyzzy}} +integrity_check delete-4.3 + +# Lots of deletes +# +do_test delete-5.1.1 { + execsql {DELETE FROM table1} +} {2} +do_test delete-5.1.2 { + execsql {SELECT count(*) FROM table1} +} {0} +do_test delete-5.2.1 { + execsql {BEGIN TRANSACTION} + for {set i 1} {$i<=200} {incr i} { + execsql "INSERT INTO table1 VALUES($i,[expr {$i*$i}])" + } + execsql {COMMIT} + execsql {SELECT count(*) FROM table1} +} {200} +do_test delete-5.2.2 { + execsql {DELETE FROM table1} +} {200} +do_test delete-5.2.3 { + execsql {BEGIN TRANSACTION} + for {set i 1} {$i<=200} {incr i} { + execsql "INSERT INTO table1 VALUES($i,[expr {$i*$i}])" + } + execsql {COMMIT} + execsql {SELECT count(*) FROM table1} +} {200} +do_test delete-5.2.4 { + execsql {PRAGMA count_changes=off} + execsql {DELETE FROM table1} +} {} +do_test delete-5.2.5 { + execsql {SELECT count(*) FROM table1} +} {0} +do_test delete-5.2.6 { + execsql {BEGIN TRANSACTION} + for {set i 1} {$i<=200} {incr i} { + execsql "INSERT INTO table1 VALUES($i,[expr {$i*$i}])" + } + execsql {COMMIT} + execsql {SELECT count(*) FROM table1} +} {200} +do_test delete-5.3 { + for {set i 1} {$i<=200} {incr i 4} { + execsql "DELETE FROM table1 WHERE f1==$i" + } + execsql {SELECT count(*) FROM table1} +} {150} +do_test delete-5.4.1 { + execsql "DELETE FROM table1 WHERE f1>50" + db changes +} [db one {SELECT count(*) FROM table1 WHERE f1>50}] +do_test delete-5.4.2 { + execsql {SELECT count(*) FROM table1} +} {37} +do_test delete-5.5 { + for {set i 1} {$i<=70} {incr i 3} { + execsql "DELETE FROM table1 WHERE f1==$i" + } + execsql {SELECT f1 FROM table1 ORDER BY f1} +} {2 3 6 8 11 12 14 15 18 20 23 24 26 27 30 32 35 36 38 39 42 44 47 48 50} +do_test delete-5.6 { + for {set i 1} {$i<40} {incr i} { + execsql "DELETE FROM table1 WHERE f1==$i" + } + execsql {SELECT f1 FROM table1 ORDER BY f1} +} {42 44 47 48 50} +do_test delete-5.7 { + execsql "DELETE FROM table1 WHERE f1!=48" + execsql {SELECT f1 FROM table1 ORDER BY f1} +} {48} +integrity_check delete-5.8 + + +# Delete large quantities of data. We want to test the List overflow +# mechanism in the vdbe. +# +do_test delete-6.1 { + execsql {BEGIN; DELETE FROM table1} + for {set i 1} {$i<=3000} {incr i} { + execsql "INSERT INTO table1 VALUES($i,[expr {$i*$i}])" + } + execsql {DELETE FROM table2} + for {set i 1} {$i<=3000} {incr i} { + execsql "INSERT INTO table2 VALUES($i,[expr {$i*$i}])" + } + execsql {COMMIT} + execsql {SELECT count(*) FROM table1} +} {3000} +do_test delete-6.2 { + execsql {SELECT count(*) FROM table2} +} {3000} +do_test delete-6.3 { + execsql {SELECT f1 FROM table1 WHERE f1<10 ORDER BY f1} +} {1 2 3 4 5 6 7 8 9} +do_test delete-6.4 { + execsql {SELECT f1 FROM table2 WHERE f1<10 ORDER BY f1} +} {1 2 3 4 5 6 7 8 9} +do_test delete-6.5.1 { + execsql {DELETE FROM table1 WHERE f1>7} + db changes +} {2993} +do_test delete-6.5.2 { + execsql {SELECT f1 FROM table1 ORDER BY f1} +} {1 2 3 4 5 6 7} +do_test delete-6.6 { + execsql {DELETE FROM table2 WHERE f1>7} + execsql {SELECT f1 FROM table2 ORDER BY f1} +} {1 2 3 4 5 6 7} +do_test delete-6.7 { + execsql {DELETE FROM table1} + execsql {SELECT f1 FROM table1} +} {} +do_test delete-6.8 { + execsql {INSERT INTO table1 VALUES(2,3)} + execsql {SELECT f1 FROM table1} +} {2} +do_test delete-6.9 { + execsql {DELETE FROM table2} + execsql {SELECT f1 FROM table2} +} {} +do_test delete-6.10 { + execsql {INSERT INTO table2 VALUES(2,3)} + execsql {SELECT f1 FROM table2} +} {2} +integrity_check delete-6.11 + +do_test delete-7.1 { + execsql { + CREATE TABLE t3(a); + INSERT INTO t3 VALUES(1); + INSERT INTO t3 SELECT a+1 FROM t3; + INSERT INTO t3 SELECT a+2 FROM t3; + SELECT * FROM t3; + } +} {1 2 3 4} +ifcapable {trigger} { + do_test delete-7.2 { + execsql { + CREATE TABLE cnt(del); + INSERT INTO cnt VALUES(0); + CREATE TRIGGER r1 AFTER DELETE ON t3 FOR EACH ROW BEGIN + UPDATE cnt SET del=del+1; + END; + DELETE FROM t3 WHERE a<2; + SELECT * FROM t3; + } + } {2 3 4} + do_test delete-7.3 { + execsql { + SELECT * FROM cnt; + } + } {1} + do_test delete-7.4 { + execsql { + DELETE FROM t3; + SELECT * FROM t3; + } + } {} + do_test delete-7.5 { + execsql { + SELECT * FROM cnt; + } + } {4} + do_test delete-7.6 { + execsql { + INSERT INTO t3 VALUES(1); + INSERT INTO t3 SELECT a+1 FROM t3; + INSERT INTO t3 SELECT a+2 FROM t3; + CREATE TABLE t4 AS SELECT * FROM t3; + PRAGMA count_changes=ON; + DELETE FROM t3; + DELETE FROM t4; + } + } {4 4} +} ;# endif trigger +ifcapable {!trigger} { + execsql {DELETE FROM t3} +} +integrity_check delete-7.7 + +# Make sure error messages are consistent when attempting to delete +# from a read-only database. Ticket #304. +# +do_test delete-8.0 { + execsql { + PRAGMA count_changes=OFF; + INSERT INTO t3 VALUES(123); + SELECT * FROM t3; + } +} {123} +db close +catch {forcedelete test.db-journal} +catch {file attributes test.db -permissions 0444} +catch {file attributes test.db -readonly 1} +sqlite3 db test.db +set ::DB [sqlite3_connection_pointer db] +do_test delete-8.1 { + catchsql { + DELETE FROM t3; + } +} {1 {attempt to write a readonly database}} +do_test delete-8.2 { + execsql {SELECT * FROM t3} +} {123} +do_test delete-8.3 { + catchsql { + DELETE FROM t3 WHERE 1; + } +} {1 {attempt to write a readonly database}} +do_test delete-8.4 { + execsql {SELECT * FROM t3} +} {123} + +# Update for v3: In v2 the DELETE statement would succeed because no +# database writes actually occur. Version 3 refuses to open a transaction +# on a read-only file, so the statement fails. +do_test delete-8.5 { + catchsql { + DELETE FROM t3 WHERE a<100; + } +# v2 result: {0 {}} +} {1 {attempt to write a readonly database}} +do_test delete-8.6 { + execsql {SELECT * FROM t3} +} {123} +integrity_check delete-8.7 + +# Need to do the following for tcl 8.5 on mac. On that configuration, the +# -readonly flag is taken so seriously that a subsequent [forcedelete] +# (required before the next test file can be executed) will fail. +# +catch {file attributes test.db -readonly 0} +db close +forcedelete test.db test.db-journal + +# The following tests verify that SQLite correctly handles the case +# where an index B-Tree is being scanned, the rowid column being read +# from each index entry and another statement deletes some rows from +# the index B-Tree. At one point this (obscure) scenario was causing +# SQLite to return spurious SQLITE_CORRUPT errors and arguably incorrect +# query results. +# +do_test delete-9.1 { + sqlite3 db test.db + execsql { + CREATE TABLE t5(a, b); + CREATE TABLE t6(c, d); + INSERT INTO t5 VALUES(1, 2); + INSERT INTO t5 VALUES(3, 4); + INSERT INTO t5 VALUES(5, 6); + INSERT INTO t6 VALUES('a', 'b'); + INSERT INTO t6 VALUES('c', 'd'); + CREATE INDEX i5 ON t5(a); + CREATE INDEX i6 ON t6(c); + } +} {} +do_test delete-9.2 { + set res [list] + db eval { SELECT t5.rowid AS r, c, d FROM t5, t6 ORDER BY a } { + if {$r==2} { db eval { DELETE FROM t5 } } + lappend res $r $c $d + } + set res +} {1 a b 1 c d 2 a b {} c d} +do_test delete-9.3 { + execsql { + INSERT INTO t5 VALUES(1, 2); + INSERT INTO t5 VALUES(3, 4); + INSERT INTO t5 VALUES(5, 6); + } + set res [list] + db eval { SELECT t5.rowid AS r, c, d FROM t5, t6 ORDER BY a } { + if {$r==2} { db eval { DELETE FROM t5 WHERE rowid = 2 } } + lappend res $r $c $d + } + set res +} {1 a b 1 c d 2 a b {} c d 3 a b 3 c d} +do_test delete-9.4 { + execsql { + DELETE FROM t5; + INSERT INTO t5 VALUES(1, 2); + INSERT INTO t5 VALUES(3, 4); + INSERT INTO t5 VALUES(5, 6); + } + set res [list] + db eval { SELECT t5.rowid AS r, c, d FROM t5, t6 ORDER BY a } { + if {$r==2} { db eval { DELETE FROM t5 WHERE rowid = 1 } } + lappend res $r $c $d + } + set res +} {1 a b 1 c d 2 a b 2 c d 3 a b 3 c d} +do_test delete-9.5 { + execsql { + DELETE FROM t5; + INSERT INTO t5 VALUES(1, 2); + INSERT INTO t5 VALUES(3, 4); + INSERT INTO t5 VALUES(5, 6); + } + set res [list] + db eval { SELECT t5.rowid AS r, c, d FROM t5, t6 ORDER BY a } { + if {$r==2} { db eval { DELETE FROM t5 WHERE rowid = 3 } } + lappend res $r $c $d + } + set res +} {1 a b 1 c d 2 a b 2 c d} + +do_execsql_test delete-10.0 { + CREATE TABLE t1(a INT UNIQUE, b INT); + INSERT INTO t1(a,b) VALUES('1','2'); + SELECT * FROM t1 WHERE a='1' AND b='2'; +} {1 2} + +do_execsql_test delete-10.1 { + DELETE FROM t1 WHERE a='1' AND b='2'; +} + +do_execsql_test delete-10.2 { + SELECT * FROM t1 WHERE a='1' AND b='2'; +} + +do_execsql_test delete-11.0 { + CREATE TABLE t11(a INTEGER PRIMARY KEY, b INT); + WITH RECURSIVE cnt(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM cnt WHERE x<20) + INSERT INTO t11(a,b) SELECT x, (x*17)%100 FROM cnt; + SELECT * FROM t11; +} {1 17 2 34 3 51 4 68 5 85 6 2 7 19 8 36 9 53 10 70 11 87 12 4 13 21 14 38 15 55 16 72 17 89 18 6 19 23 20 40} +do_execsql_test delete-11.1 { + DELETE FROM t11 AS xyz + WHERE EXISTS(SELECT 1 FROM t11 WHERE t11.a>xyz.a AND t11.b<=xyz.b); + SELECT * FROM t11; +} {6 2 12 4 18 6 19 23 20 40} + + +# 2023-03-15 +# https://sqlite.org/forum/forumpost/e61252062c9d286d +# +# When the WHERE clause of a DELETE statement contains a subquery +# which uses the table that is being deleted from and there is a +# short-circuit operator of some kind in the WHERE clause such that +# the subquery might not run right away, then the subquery might +# run after one or more rows have been deleted, which can change +# the result of the subquery, and result in the wrong answer. +# +# Similar problem for UPDATE tested by update-21.4 +# https://sqlite.org/forum/forumpost/0007d1fdb1 +# +reset_db +do_execsql_test delete-12.0 { + CREATE TABLE t0(vkey INTEGER, pkey INTEGER,c1 INTEGER); + INSERT INTO t0 VALUES(2,1,-20),(2,2,NULL),(2,3,0),(8,4,95); + DELETE FROM t0 WHERE NOT ( + (t0.vkey <= t0.c1) AND + (t0.vkey <> (SELECT vkey FROM t0 ORDER BY vkey LIMIT 1 OFFSET 2)) + ); + SELECT * FROM t0; +} {8 4 95} + +finish_test diff --git a/test/delete2.test b/test/delete2.test new file mode 100644 index 0000000..1668a3a --- /dev/null +++ b/test/delete2.test @@ -0,0 +1,119 @@ +# 2003 September 6 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script is a test to replicate the bug reported by +# ticket #842. +# +# Ticket #842 was a database corruption problem caused by a DELETE that +# removed an index entry by not the main table entry. To recreate the +# problem do this: +# +# (1) Create a table with an index. Insert some data into that table. +# (2) Start a query on the table but do not complete the query. +# (3) Try to delete a single entry from the table. +# +# Step 3 will fail because there is still a read cursor on the table. +# But the database is corrupted by the DELETE. It turns out that the +# index entry was deleted first, before the table entry. And the index +# delete worked. Thus an entry was deleted from the index but not from +# the table. +# +# The solution to the problem was to detect that the table is locked +# before the index entry is deleted. +# +# $Id: delete2.test,v 1.8 2008/07/08 15:59:52 danielk1977 Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Create a table that has an index. +# +do_test delete2-1.1 { + set DB [sqlite3_connection_pointer db] + execsql { + CREATE TABLE q(s string, id string, constraint pk_q primary key(id)); + BEGIN; + INSERT INTO q(s,id) VALUES('hello','id.1'); + INSERT INTO q(s,id) VALUES('goodbye','id.2'); + INSERT INTO q(s,id) VALUES('again','id.3'); + END; + SELECT * FROM q; + } +} {hello id.1 goodbye id.2 again id.3} +do_test delete2-1.2 { + execsql { + SELECT * FROM q WHERE id='id.1'; + } +} {hello id.1} +integrity_check delete2-1.3 + +# Start a query on the table. The query should not use the index. +# Do not complete the query, thus leaving the table locked. +# +do_test delete2-1.4 { + set STMT [sqlite3_prepare $DB {SELECT * FROM q} -1 TAIL] + sqlite3_step $STMT +} SQLITE_ROW +integrity_check delete2-1.5 + +# Try to delete a row from the table while a read is in process. +# As of 2006-08-16, this is allowed. (It used to fail with SQLITE_LOCKED.) +# +do_test delete2-1.6 { + catchsql { + DELETE FROM q WHERE rowid=1 + } +} {0 {}} +integrity_check delete2-1.7 +do_test delete2-1.8 { + execsql { + SELECT * FROM q; + } +} {goodbye id.2 again id.3} + +# Finalize the query, thus clearing the lock on the table. Then +# retry the delete. The delete should work this time. +# +do_test delete2-1.9 { + sqlite3_finalize $STMT + catchsql { + DELETE FROM q WHERE rowid=1 + } +} {0 {}} +integrity_check delete2-1.10 +do_test delete2-1.11 { + execsql { + SELECT * FROM q; + } +} {goodbye id.2 again id.3} + +do_test delete2-2.1 { + execsql { + CREATE TABLE t1(a, b); + CREATE TABLE t2(c, d); + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t2 VALUES(3, 4); + INSERT INTO t2 VALUES(5, 6); + } +} {} +do_test delete2-2.2 { + set res [list] + db eval { + SELECT CASE WHEN c = 5 THEN b ELSE NULL END AS b, c, d FROM t1, t2 + } { + db eval {DELETE FROM t1} + lappend res $b $c $d + } + set res +} {{} 3 4 {} 5 6} + +finish_test diff --git a/test/delete3.test b/test/delete3.test new file mode 100644 index 0000000..a31f6ec --- /dev/null +++ b/test/delete3.test @@ -0,0 +1,57 @@ +# 2005 August 24 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script is a test of the DELETE command where a +# large number of rows are deleted. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Create a table that contains a large number of rows. +# +do_test delete3-1.1 { + execsql { + CREATE TABLE t1(x integer primary key); + BEGIN; + INSERT INTO t1 VALUES(1); + INSERT INTO t1 VALUES(2); + INSERT INTO t1 SELECT x+2 FROM t1; + INSERT INTO t1 SELECT x+4 FROM t1; + INSERT INTO t1 SELECT x+8 FROM t1; + INSERT INTO t1 SELECT x+16 FROM t1; + INSERT INTO t1 SELECT x+32 FROM t1; + INSERT INTO t1 SELECT x+64 FROM t1; + INSERT INTO t1 SELECT x+128 FROM t1; + INSERT INTO t1 SELECT x+256 FROM t1; + INSERT INTO t1 SELECT x+512 FROM t1; + INSERT INTO t1 SELECT x+1024 FROM t1; + INSERT INTO t1 SELECT x+2048 FROM t1; + INSERT INTO t1 SELECT x+4096 FROM t1; + INSERT INTO t1 SELECT x+8192 FROM t1; + INSERT INTO t1 SELECT x+16384 FROM t1; + INSERT INTO t1 SELECT x+32768 FROM t1; + INSERT INTO t1 SELECT x+65536 FROM t1; + INSERT INTO t1 SELECT x+131072 FROM t1; + INSERT INTO t1 SELECT x+262144 FROM t1; + COMMIT; + SELECT count(*) FROM t1; + } +} {524288} +do_test delete3-1.2 { + execsql { + DELETE FROM t1 WHERE x%2==0; + SELECT count(*) FROM t1; + } +} {262144} +integrity_check delete3-1.3 + +finish_test diff --git a/test/delete4.test b/test/delete4.test new file mode 100644 index 0000000..8d6a1b8 --- /dev/null +++ b/test/delete4.test @@ -0,0 +1,272 @@ +# 2005 August 24 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script is a test of the DELETE command. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix delete4 + +do_execsql_test 1.1 { + CREATE TABLE t1(x INTEGER PRIMARY KEY, y); + INSERT INTO t1 VALUES(1, 0); + INSERT INTO t1 VALUES(2, 1); + INSERT INTO t1 VALUES(3, 0); + INSERT INTO t1 VALUES(4, 1); + INSERT INTO t1 VALUES(5, 0); + INSERT INTO t1 VALUES(6, 1); + INSERT INTO t1 VALUES(7, 0); + INSERT INTO t1 VALUES(8, 1); +} +do_execsql_test 1.2 { + DELETE FROM t1 WHERE y=1; +} +do_execsql_test 1.3 { + SELECT x FROM t1; +} {1 3 5 7} + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 2.1 { + CREATE TABLE t1(x INTEGER PRIMARY KEY, y, z); + INSERT INTO t1 VALUES(1, 0, randomblob(200)); + INSERT INTO t1 VALUES(2, 1, randomblob(200)); + INSERT INTO t1 VALUES(3, 0, randomblob(200)); + INSERT INTO t1 VALUES(4, 1, randomblob(200)); + INSERT INTO t1 VALUES(5, 0, randomblob(200)); + INSERT INTO t1 VALUES(6, 1, randomblob(200)); + INSERT INTO t1 VALUES(7, 0, randomblob(200)); + INSERT INTO t1 VALUES(8, 1, randomblob(200)); +} +do_execsql_test 2.2 { + DELETE FROM t1 WHERE y=1; +} +do_execsql_test 2.3 { + SELECT x FROM t1; +} {1 3 5 7} + + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 3.0.1 { + CREATE TABLE t1(a, b, PRIMARY KEY(a, b)) WITHOUT ROWID; + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t1 VALUES(2, 4); + INSERT INTO t1 VALUES(1, 5); + DELETE FROM t1 WHERE a=1; + SELECT printf('(%d)',changes()); + SELECT * FROM t1; +} {(2) 2 4} +do_execsql_test 3.0.2 { + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100) + INSERT INTO t1(a,b) SELECT x, x+1 FROM c; + SELECT printf('(%d)',changes()); + DELETE FROM t1; + SELECT printf('(%d)',changes()); +} {(100) (101)} + +#------------------------------------------------------------------------- +# DELETE statement that uses the OR optimization +# +reset_db +do_execsql_test 3.1 { + CREATE TABLE t1(i INTEGER PRIMARY KEY, a, b); + CREATE INDEX i1a ON t1(a); + CREATE INDEX i1b ON t1(b); + INSERT INTO t1 VALUES(1, 'one', 'i'); + INSERT INTO t1 VALUES(2, 'two', 'ii'); + INSERT INTO t1 VALUES(3, 'three', 'iii'); + INSERT INTO t1 VALUES(4, 'four', 'iv'); + INSERT INTO t1 VALUES(5, 'one', 'i'); + INSERT INTO t1 VALUES(6, 'two', 'ii'); + INSERT INTO t1 VALUES(7, 'three', 'iii'); + INSERT INTO t1 VALUES(8, 'four', 'iv'); +} {} + +do_execsql_test 3.2 { + DELETE FROM t1 WHERE a='two' OR b='iv'; +} + +do_execsql_test 3.3 { + SELECT i FROM t1 ORDER BY i; +} {1 3 5 7} + +do_execsql_test 3.4 { + PRAGMA integrity_check; +} {ok} + +# Between 2015-09-14 and 2015-09-28, the following test cases would result +# in corruption (wrong # of entries in index) due to a bug in the ONEPASS +# optimization. +# +do_execsql_test 4.1 { + DROP TABLE IF EXISTS t4; + CREATE TABLE t4(col0, col1); + INSERT INTO "t4" VALUES(14, 'abcde'); + CREATE INDEX idx_t4_0 ON t4 (col1, col0); + CREATE INDEX idx_t4_3 ON t4 (col0); + DELETE FROM t4 WHERE col0=69 OR col0>7; + PRAGMA integrity_check; +} {ok} +do_execsql_test 4.2 { + DROP TABLE IF EXISTS t4; + CREATE TABLE t4(col0, col1); + INSERT INTO "t4" VALUES(14, 'abcde'); + CREATE INDEX idx_t4_3 ON t4 (col0); + CREATE INDEX idx_t4_0 ON t4 (col1, col0); + DELETE FROM t4 WHERE col0=69 OR col0>7; + PRAGMA integrity_check; +} {ok} +do_execsql_test 4.11 { + DROP TABLE IF EXISTS t4; + CREATE TABLE t4(col0, col1, pk PRIMARY KEY) WITHOUT ROWID; + INSERT INTO t4 VALUES(14, 'abcde','xyzzy'); + CREATE INDEX idx_t4_0 ON t4 (col1, col0); + CREATE INDEX idx_t4_3 ON t4 (col0); + DELETE FROM t4 WHERE col0=69 OR col0>7; + PRAGMA integrity_check; +} {ok} +do_execsql_test 4.12 { + DROP TABLE IF EXISTS t4; + CREATE TABLE t4(col0, col1, pk PRIMARY KEY) WITHOUT ROWID; + INSERT INTO t4 VALUES(14, 'abcde','xyzzy'); + CREATE INDEX idx_t4_3 ON t4 (col0); + CREATE INDEX idx_t4_0 ON t4 (col1, col0); + DELETE FROM t4 WHERE col0=69 OR col0>7; + PRAGMA integrity_check; +} {ok} + +# 2016-04-09 +# Ticket https://sqlite.org/src/info/a306e56ff68b8fa5 +# Failure to completely delete when reverse_unordered_selects is +# engaged. +# +db close +forcedelete test.db +sqlite3 db test.db +do_execsql_test 5.0 { + PRAGMA page_size=1024; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c); + CREATE INDEX x1 ON t1(b, c); + INSERT INTO t1(a,b,c) VALUES(1, 1, zeroblob(80)); + INSERT INTO t1(a,b,c) SELECT a+1, 1, c FROM t1; + INSERT INTO t1(a,b,c) SELECT a+2, 1, c FROM t1; + INSERT INTO t1(a,b,c) SELECT a+10, 2, c FROM t1 WHERE b=1; + INSERT INTO t1(a,b,c) SELECT a+20, 3, c FROM t1 WHERE b=1; + PRAGMA reverse_unordered_selects = ON; + DELETE FROM t1 WHERE b=2; + SELECT a FROM t1 WHERE b=2; +} {} + +# 2016-05-02 +# Ticket https://www.sqlite.org/src/tktview/dc6ebeda93960877 +# A subquery in the WHERE clause of a one-pass DELETE can cause an +# incorrect answer. +# +db close +forcedelete test.db +sqlite3 db test.db +do_execsql_test 6.0 { + CREATE TABLE t2(x INT); + INSERT INTO t2(x) VALUES(1),(2),(3),(4),(5); + DELETE FROM t2 WHERE EXISTS(SELECT 1 FROM t2 AS v WHERE v.x=t2.x-1); + SELECT x FROM t2; +} {1} +do_execsql_test 6.1 { + DROP TABLE IF EXISTS t2; + CREATE TABLE t2(x INT); + INSERT INTO t2(x) VALUES(1),(2),(3),(4),(5); + DELETE FROM t2 WHERE EXISTS(SELECT 1 FROM t2 AS v WHERE v.x=t2.x+1); + SELECT x FROM t2; +} {5} + +#------------------------------------------------------------------------- +# Test the effect of failing to find a table row based on an index key +# within a DELETE. Either because the db is corrupt, or a trigger on another +# row already deleted the entry, or because a BEFORE trigger on the current +# row has already deleted it. +# +do_execsql_test 7.1.0 { + CREATE TABLE t3(id INT PRIMARY KEY, a, b) WITHOUT ROWID; + CREATE INDEX t3a ON t3(a); + CREATE INDEX t3b ON t3(b); + + INSERT INTO t3 VALUES(1, 1, 1); + INSERT INTO t3 VALUES(2, 2, 2); + INSERT INTO t3 VALUES(3, 3, 3); + INSERT INTO t3 VALUES(4, 4, 1); +} +do_execsql_test 7.1.1 { + DELETE FROM t3 WHERE a=4 OR b=1; +} +do_execsql_test 7.1.2 { + SELECT * FROM t3; +} { 2 2 2 3 3 3 } + +do_execsql_test 7.2.0 { + CREATE TABLE t4(a PRIMARY KEY, b) WITHOUT ROWID; + CREATE INDEX t4i ON t4(b); + INSERT INTO t4 VALUES(1, 'hello'); + INSERT INTO t4 VALUES(2, 'world'); + + CREATE TABLE t5(a PRIMARY KEY, b) WITHOUT ROWID; + CREATE INDEX t5i ON t5(b); + INSERT INTO t5 VALUES(1, 'hello'); + INSERT INTO t5 VALUES(3, 'world'); + + PRAGMA writable_schema = 1; + UPDATE sqlite_master SET rootpage = ( + SELECT rootpage FROM sqlite_master WHERE name = 't5' + ) WHERE name = 't4'; +} + +db close +sqlite3 db test.db +do_execsql_test 7.2.1 { + DELETE FROM t4 WHERE b='world' +} +reset_db + +do_execsql_test 7.3.0 { + CREATE TABLE t3(id INT PRIMARY KEY, a, b) WITHOUT ROWID; + INSERT INTO t3 VALUES(1, 2, 3); + INSERT INTO t3 VALUES(4, 5, 6); + INSERT INTO t3 VALUES(7, 8, 9); + CREATE TRIGGER t3t BEFORE DELETE ON t3 BEGIN + DELETE FROM t3 WHERE id=old.id+3; + END; +} + +do_execsql_test 7.3.1 { + DELETE FROM t3 WHERE a IN(2, 5, 8); + SELECT * FROM t3; +} {} + +do_execsql_test 7.3.2 { + DROP TRIGGER t3t; + INSERT INTO t3 VALUES(1, 2, 3); + INSERT INTO t3 VALUES(4, 5, 6); + INSERT INTO t3 VALUES(7, 8, 9); + CREATE TRIGGER t3t BEFORE DELETE ON t3 BEGIN + DELETE FROM t3 WHERE id=old.id; + END; +} + +do_execsql_test 7.3.3 { + DELETE FROM t3 WHERE a IN(2, 5, 8); + SELECT * FROM t3; +} {} + + +finish_test diff --git a/test/delete_db.test b/test/delete_db.test new file mode 100644 index 0000000..6edd9c2 --- /dev/null +++ b/test/delete_db.test @@ -0,0 +1,222 @@ +# 2016 September 10 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing the code in test_delete.c (the +# sqlite3_delete_database() API). +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix delete_db + +if {[atomic_batch_write test.db]} { + finish_test + return +} + +proc delete_all {} { + foreach f [glob -nocomplain test2*] { file delete $f } + foreach f [glob -nocomplain test3*] { file delete $f } +} + +proc copydb {} { + foreach f [glob -nocomplain test3*] { file delete $f } + foreach f [glob -nocomplain test2*] { + set p [string range $f 5 end] + file copy "test2$p" "test3$p" + } +} + +proc files {} { + lsort [glob -nocomplain test3*] +} + +db close +delete_all +sqlite3 db test2.database + +#------------------------------------------------------------------------- +# +# 1.1: Journal files. +# 1.2: Wal files. +# 1.3: Multiplexor with journal file. +# 1.4: Multiplexor with wal file. +# +# 2.* are a copy of 1.* with the multiplexor enabled. +# +# 3.* tests errors. +# + +do_test 1.1.0 { + execsql { + CREATE TABLE t1(x, y); + BEGIN; + INSERT INTO t1 VALUES(1, 2); + } + copydb + files +} {test3.database test3.database-journal} + +do_test 1.1.1 { + sqlite3_delete_database test3.database + files +} {} + +do_test 1.2.0 { + execsql { + COMMIT; + PRAGMA journal_mode = wal; + INSERT INTO t1 VALUES(3, 4); + } + copydb + files +} {test3.database test3.database-shm test3.database-wal} +do_test 1.2.1 { + sqlite3_delete_database test3.database + files +} {} + +db close +delete_all +sqlite3_multiplex_initialize "" 0 +sqlite3 db test2.database -vfs multiplex +sqlite3_multiplex_control db "main" chunk_size 32768 + +do_test 1.3.0 { + execsql { PRAGMA auto_vacuum = 0; } + execsql { + CREATE TABLE x1(a, b); + WITH s(i) AS ( VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<1000 ) + INSERT INTO x1 SELECT randomblob(100), randomblob(100) FROM s; + BEGIN; + UPDATE x1 SET a=randomblob(101) + } + copydb + files +} [list {*}{ + test3.database test3.database-journal test3.database001 + test3.database002 test3.database003 +}] +do_test 1.3.1 { + sqlite3_delete_database test3.database + files +} {} + + +do_test 1.4.0 { + execsql { + COMMIT; + PRAGMA journal_mode = wal; + UPDATE x1 SET a=randomblob(102) + } + copydb + files +} [list {*}{ + test3.database test3.database-shm test3.database-wal test3.database001 + test3.database002 test3.database003 +}] +do_test 1.4.1 { + sqlite3_delete_database test3.database + files +} {} + + +ifcapable 8_3_names { + db close + delete_all + sqlite3 db file:test2.db?8_3_names=1 -uri 1 + + do_test 2.1.0 { + execsql { + CREATE TABLE t1(x, y); + BEGIN; + INSERT INTO t1 VALUES(1, 2); + } + copydb + files + } {test3.db test3.nal} + + do_test 2.1.1 { + sqlite3_delete_database test3.db + files + } {} + + do_test 2.2.0 { + execsql { + COMMIT; + PRAGMA journal_mode = wal; + INSERT INTO t1 VALUES(3, 4); + } + copydb + files + } {test3.db test3.shm test3.wal} + do_test 2.2.1 { + sqlite3_delete_database test3.db + files + } {} + + + db close + delete_all + sqlite3_multiplex_initialize "" 0 + sqlite3 db file:test2.db?8_3_names=1 -uri 1 -vfs multiplex + sqlite3_multiplex_control db "main" chunk_size 32768 + + do_test 2.3.0 { + execsql { PRAGMA auto_vacuum = 0; } + execsql { + CREATE TABLE x1(a, b); + WITH s(i) AS ( VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<1000 ) + INSERT INTO x1 SELECT randomblob(100), randomblob(100) FROM s; + BEGIN; + UPDATE x1 SET a=randomblob(101) + } + copydb + files + } [list {*}{ + test3.001 test3.002 test3.003 test3.db test3.nal + }] + do_test 2.3.1 { + sqlite3_delete_database test3.db + files + } {} + + + do_test 2.4.0 { + execsql { + COMMIT; + PRAGMA journal_mode = wal; + UPDATE x1 SET a=randomblob(102) + } + copydb + files + } [list {*}{ + test3.001 test3.002 test3.003 test3.db test3.db-shm test3.wal + }] + do_test 2.4.1 { + sqlite3_delete_database test3.db + files + } {} +} + +db close +delete_all +sqlite3_multiplex_shutdown + +do_test 3.0 { + file mkdir dir2.db + sqlite3_delete_database dir2.db +} {SQLITE_ERROR} +do_test 3.1 { + sqlite3_delete_database dir2.db/test.db +} {SQLITE_OK} + +finish_test diff --git a/test/descidx1.test b/test/descidx1.test new file mode 100644 index 0000000..14be6f8 --- /dev/null +++ b/test/descidx1.test @@ -0,0 +1,365 @@ +# 2005 December 21 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is descending indices. +# +# $Id: descidx1.test,v 1.10 2008/03/19 00:21:31 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +#db eval {PRAGMA legacy_file_format=OFF} +sqlite3_db_config db LEGACY_FILE_FORMAT 0 + +# This procedure sets the value of the file-format in file 'test.db' +# to $newval. Also, the schema cookie is incremented. +# +proc set_file_format {newval} { + hexio_write test.db 44 [hexio_render_int32 $newval] + set schemacookie [hexio_get_int [hexio_read test.db 40 4]] + incr schemacookie + hexio_write test.db 40 [hexio_render_int32 $schemacookie] + return {} +} + +# This procedure returns the value of the file-format in file 'test.db'. +# +proc get_file_format {{fname test.db}} { + return [hexio_get_int [hexio_read $fname 44 4]] +} + + +# Verify that the file format starts as 4. +# +do_test descidx1-1.1 { + execsql { + CREATE TABLE t1(a,b); + CREATE INDEX i1 ON t1(b ASC); + } + get_file_format +} {4} +do_test descidx1-1.2 { + execsql { + CREATE INDEX i2 ON t1(a DESC); + } + get_file_format +} {4} + +# Put some information in the table and verify that the descending +# index actually works. +# +do_test descidx1-2.1 { + execsql { + INSERT INTO t1 VALUES(1,1); + INSERT INTO t1 VALUES(2,2); + INSERT INTO t1 SELECT a+2, a+2 FROM t1; + INSERT INTO t1 SELECT a+4, a+4 FROM t1; + SELECT b FROM t1 WHERE a>3 AND a<7; + } +} {6 5 4} +do_test descidx1-2.2 { + execsql { + SELECT a FROM t1 WHERE b>3 AND b<7; + } +} {4 5 6} +do_test descidx1-2.3 { + execsql { + SELECT b FROM t1 WHERE a>=3 AND a<7; + } +} {6 5 4 3} +do_test descidx1-2.4 { + execsql { + SELECT b FROM t1 WHERE a>3 AND a<=7; + } +} {7 6 5 4} +do_test descidx1-2.5 { + execsql { + SELECT b FROM t1 WHERE a>=3 AND a<=7; + } +} {7 6 5 4 3} +do_test descidx1-2.6 { + execsql { + SELECT a FROM t1 WHERE b>=3 AND b<=7; + } +} {3 4 5 6 7} + +# This procedure executes the SQL. Then it checks to see if the OP_Sort +# opcode was executed. If an OP_Sort did occur, then "sort" is appended +# to the result. If no OP_Sort happened, then "nosort" is appended. +# +# This procedure is used to check to make sure sorting is or is not +# occurring as expected. +# +proc cksort {sql} { + set ::sqlite_sort_count 0 + set data [execsql $sql] + if {$::sqlite_sort_count} {set x sort} {set x nosort} + lappend data $x + return $data +} + +# Test sorting using a descending index. +# +do_test descidx1-3.1 { + cksort {SELECT a FROM t1 ORDER BY a} +} {1 2 3 4 5 6 7 8 nosort} +do_test descidx1-3.2 { + cksort {SELECT a FROM t1 ORDER BY a ASC} +} {1 2 3 4 5 6 7 8 nosort} +do_test descidx1-3.3 { + cksort {SELECT a FROM t1 ORDER BY a DESC} +} {8 7 6 5 4 3 2 1 nosort} +do_test descidx1-3.4 { + cksort {SELECT b FROM t1 ORDER BY a} +} {1 2 3 4 5 6 7 8 nosort} +do_test descidx1-3.5 { + cksort {SELECT b FROM t1 ORDER BY a ASC} +} {1 2 3 4 5 6 7 8 nosort} +do_test descidx1-3.6 { + cksort {SELECT b FROM t1 ORDER BY a DESC} +} {8 7 6 5 4 3 2 1 nosort} +do_test descidx1-3.7 { + cksort {SELECT a FROM t1 ORDER BY b} +} {1 2 3 4 5 6 7 8 nosort} +do_test descidx1-3.8 { + cksort {SELECT a FROM t1 ORDER BY b ASC} +} {1 2 3 4 5 6 7 8 nosort} +do_test descidx1-3.9 { + cksort {SELECT a FROM t1 ORDER BY b DESC} +} {8 7 6 5 4 3 2 1 nosort} +do_test descidx1-3.10 { + cksort {SELECT b FROM t1 ORDER BY b} +} {1 2 3 4 5 6 7 8 nosort} +do_test descidx1-3.11 { + cksort {SELECT b FROM t1 ORDER BY b ASC} +} {1 2 3 4 5 6 7 8 nosort} +do_test descidx1-3.12 { + cksort {SELECT b FROM t1 ORDER BY b DESC} +} {8 7 6 5 4 3 2 1 nosort} + +do_test descidx1-3.21 { + cksort {SELECT a FROM t1 WHERE a>3 AND a<8 ORDER BY a} +} {4 5 6 7 nosort} +do_test descidx1-3.22 { + cksort {SELECT a FROM t1 WHERE a>3 AND a<8 ORDER BY a ASC} +} {4 5 6 7 nosort} +do_test descidx1-3.23 { + cksort {SELECT a FROM t1 WHERE a>3 AND a<8 ORDER BY a DESC} +} {7 6 5 4 nosort} +do_test descidx1-3.24 { + cksort {SELECT b FROM t1 WHERE a>3 AND a<8 ORDER BY a} +} {4 5 6 7 nosort} +do_test descidx1-3.25 { + cksort {SELECT b FROM t1 WHERE a>3 AND a<8 ORDER BY a ASC} +} {4 5 6 7 nosort} +do_test descidx1-3.26 { + cksort {SELECT b FROM t1 WHERE a>3 AND a<8 ORDER BY a DESC} +} {7 6 5 4 nosort} + +# Create a table with indices that are descending on some terms and +# ascending on others. +# +ifcapable bloblit { + do_test descidx1-4.1 { + execsql { + CREATE TABLE t2(a INT, b TEXT, c BLOB, d REAL); + CREATE INDEX i3 ON t2(a ASC, b DESC, c ASC); + CREATE INDEX i4 ON t2(b DESC, a ASC, d DESC); + INSERT INTO t2 VALUES(1,'one',x'31',1.0); + INSERT INTO t2 VALUES(2,'two',x'3232',2.0); + INSERT INTO t2 VALUES(3,'three',x'333333',3.0); + INSERT INTO t2 VALUES(4,'four',x'34343434',4.0); + INSERT INTO t2 VALUES(5,'five',x'3535353535',5.0); + INSERT INTO t2 VALUES(6,'six',x'363636363636',6.0); + INSERT INTO t2 VALUES(2,'two',x'323232',2.1); + INSERT INTO t2 VALUES(2,'zwei',x'3232',2.2); + INSERT INTO t2 VALUES(2,NULL,NULL,2.3); + SELECT count(*) FROM t2; + } + } {9} + do_test descidx1-4.2 { + execsql { + SELECT d FROM t2 ORDER BY a; + } + } {1.0 2.2 2.0 2.1 2.3 3.0 4.0 5.0 6.0} + do_test descidx1-4.3 { + execsql { + SELECT d FROM t2 WHERE a>=2 ORDER BY a; + } + } {2.2 2.0 2.1 2.3 3.0 4.0 5.0 6.0} + do_test descidx1-4.4 { + execsql { + SELECT d FROM t2 WHERE a>2 ORDER BY a; + } + } {3.0 4.0 5.0 6.0} + do_test descidx1-4.5 { + execsql { + SELECT d FROM t2 WHERE a=2 AND b>'two'; + } + } {2.2} + do_test descidx1-4.6 { + execsql { + SELECT d FROM t2 WHERE a=2 AND b>='two'; + } + } {2.2 2.0 2.1} + do_test descidx1-4.7 { + execsql { + SELECT d FROM t2 WHERE a=2 AND b<'two'; + } + } {} + do_test descidx1-4.8 { + execsql { + SELECT d FROM t2 WHERE a=2 AND b<='two'; + } + } {2.0 2.1} +} + +do_test descidx1-5.1 { + execsql { + CREATE TABLE t3(a,b,c,d); + CREATE INDEX t3i1 ON t3(a DESC, b ASC, c DESC, d ASC); + INSERT INTO t3 VALUES(0,0,0,0); + INSERT INTO t3 VALUES(0,0,0,1); + INSERT INTO t3 VALUES(0,0,1,0); + INSERT INTO t3 VALUES(0,0,1,1); + INSERT INTO t3 VALUES(0,1,0,0); + INSERT INTO t3 VALUES(0,1,0,1); + INSERT INTO t3 VALUES(0,1,1,0); + INSERT INTO t3 VALUES(0,1,1,1); + INSERT INTO t3 VALUES(1,0,0,0); + INSERT INTO t3 VALUES(1,0,0,1); + INSERT INTO t3 VALUES(1,0,1,0); + INSERT INTO t3 VALUES(1,0,1,1); + INSERT INTO t3 VALUES(1,1,0,0); + INSERT INTO t3 VALUES(1,1,0,1); + INSERT INTO t3 VALUES(1,1,1,0); + INSERT INTO t3 VALUES(1,1,1,1); + SELECT count(*) FROM t3; + } +} {16} +do_test descidx1-5.2 { + cksort { + SELECT a||b||c||d FROM t3 ORDER BY a,b,c,d; + } +} {0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 sort} +do_test descidx1-5.3 { + cksort { + SELECT a||b||c||d FROM t3 ORDER BY a DESC, b ASC, c DESC, d ASC; + } +} {1010 1011 1000 1001 1110 1111 1100 1101 0010 0011 0000 0001 0110 0111 0100 0101 nosort} +do_test descidx1-5.4 { + cksort { + SELECT a||b||c||d FROM t3 ORDER BY a ASC, b DESC, c ASC, d DESC; + } +} {0101 0100 0111 0110 0001 0000 0011 0010 1101 1100 1111 1110 1001 1000 1011 1010 nosort} +do_test descidx1-5.5 { + cksort { + SELECT a||b||c FROM t3 WHERE d=0 ORDER BY a DESC, b ASC, c DESC + } +} {101 100 111 110 001 000 011 010 nosort} +do_test descidx1-5.6 { + cksort { + SELECT a||b||c FROM t3 WHERE d=0 ORDER BY a ASC, b DESC, c ASC + } +} {010 011 000 001 110 111 100 101 nosort} +do_test descidx1-5.7 { + cksort { + SELECT a||b||c FROM t3 WHERE d=0 ORDER BY a ASC, b DESC, c DESC + } +} {011 010 001 000 111 110 101 100 sort} +do_test descidx1-5.8 { + cksort { + SELECT a||b||c FROM t3 WHERE d=0 ORDER BY a ASC, b ASC, c ASC + } +} {000 001 010 011 100 101 110 111 sort} +do_test descidx1-5.9 { + cksort { + SELECT a||b||c FROM t3 WHERE d=0 ORDER BY a DESC, b DESC, c ASC + } +} {110 111 100 101 010 011 000 001 sort} + +# Test the legacy_file_format pragma here because we have access to +# the get_file_format command. +# +ifcapable legacyformat { + do_test descidx1-6.1 { + db close + forcedelete test.db test.db-journal + sqlite3 db test.db + sqlite3_db_config db LEGACY_FILE_FORMAT + } {1} +} else { + do_test descidx1-6.1 { + db close + forcedelete test.db test.db-journal + sqlite3 db test.db + sqlite3_db_config db LEGACY_FILE_FORMAT + } {0} +} +do_test descidx1-6.2 { + sqlite3_db_config db LEGACY_FILE_FORMAT 1 + sqlite3_db_config db LEGACY_FILE_FORMAT +} {1} +do_test descidx1-6.3 { + execsql { + CREATE TABLE t1(a,b,c); + } + get_file_format +} {1} +ifcapable vacuum { + # Verify that the file format is preserved across a vacuum. + do_test descidx1-6.3.1 { + execsql {VACUUM} + get_file_format + } {1} +} +do_test descidx1-6.4 { + db close + forcedelete test.db test.db-journal + sqlite3 db test.db + sqlite3_db_config db LEGACY_FILE_FORMAT 0 + sqlite3_db_config db LEGACY_FILE_FORMAT +} {0} +do_test descidx1-6.5 { + execsql { + CREATE TABLE t1(a,b,c); + CREATE INDEX i1 ON t1(a ASC, b DESC, c ASC); + INSERT INTO t1 VALUES(1,2,3); + INSERT INTO t1 VALUES(1,1,0); + INSERT INTO t1 VALUES(1,2,1); + INSERT INTO t1 VALUES(1,3,4); + } + get_file_format +} {4} +ifcapable vacuum { + # Verify that the file format is preserved across a vacuum. + do_test descidx1-6.6 { + execsql {VACUUM} + get_file_format + } {4} + do_test descidx1-6.7 { + sqlite3_db_config db LEGACY_FILE_FORMAT 1 + execsql { + VACUUM; + } + get_file_format + } {4} +} + + + +finish_test diff --git a/test/descidx2.test b/test/descidx2.test new file mode 100644 index 0000000..5aefc59 --- /dev/null +++ b/test/descidx2.test @@ -0,0 +1,186 @@ +# 2005 December 21 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is descending indices. +# +# $Id: descidx2.test,v 1.5 2008/03/19 00:21:31 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + + +#db eval {PRAGMA legacy_file_format=OFF} +sqlite3_db_config db LEGACY_FILE_FORMAT 0 + +# This procedure sets the value of the file-format in file 'test.db' +# to $newval. Also, the schema cookie is incremented. +# +proc set_file_format {newval} { + hexio_write test.db 44 [hexio_render_int32 $newval] + set schemacookie [hexio_get_int [hexio_read test.db 40 4]] + incr schemacookie + hexio_write test.db 40 [hexio_render_int32 $schemacookie] + return {} +} + +# This procedure returns the value of the file-format in file 'test.db'. +# +proc get_file_format {{fname test.db}} { + return [hexio_get_int [hexio_read $fname 44 4]] +} + + +# Verify that the file format starts as 4 +# +do_test descidx2-1.1 { + execsql { + CREATE TABLE t1(a,b); + CREATE INDEX i1 ON t1(b ASC); + } + get_file_format +} {4} +do_test descidx2-1.2 { + execsql { + CREATE INDEX i2 ON t1(a DESC); + } + get_file_format +} {4} + +# Before adding any information to the database, set the file format +# back to three. Then close and reopen the database. With the file +# format set to three, SQLite should ignore the DESC argument on the +# index. +# +do_test descidx2-2.0 { + set_file_format 3 + db close + sqlite3 db test.db + get_file_format +} {3} + +# Put some information in the table and verify that the DESC +# on the index is ignored. +# +do_test descidx2-2.1 { + execsql { + INSERT INTO t1 VALUES(1,1); + INSERT INTO t1 VALUES(2,2); + INSERT INTO t1 SELECT a+2, a+2 FROM t1; + INSERT INTO t1 SELECT a+4, a+4 FROM t1; + SELECT b FROM t1 WHERE a>3 AND a<7; + } +} {4 5 6} +do_test descidx2-2.2 { + execsql { + SELECT a FROM t1 WHERE b>3 AND b<7; + } +} {4 5 6} +do_test descidx2-2.3 { + execsql { + SELECT b FROM t1 WHERE a>=3 AND a<7; + } +} {3 4 5 6} +do_test descidx2-2.4 { + execsql { + SELECT b FROM t1 WHERE a>3 AND a<=7; + } +} {4 5 6 7} +do_test descidx2-2.5 { + execsql { + SELECT b FROM t1 WHERE a>=3 AND a<=7; + } +} {3 4 5 6 7} +do_test descidx2-2.6 { + execsql { + SELECT a FROM t1 WHERE b>=3 AND b<=7; + } +} {3 4 5 6 7} + +# This procedure executes the SQL. Then it checks to see if the OP_Sort +# opcode was executed. If an OP_Sort did occur, then "sort" is appended +# to the result. If no OP_Sort happened, then "nosort" is appended. +# +# This procedure is used to check to make sure sorting is or is not +# occurring as expected. +# +proc cksort {sql} { + set ::sqlite_sort_count 0 + set data [execsql $sql] + if {$::sqlite_sort_count} {set x sort} {set x nosort} + lappend data $x + return $data +} + +# Test sorting using a descending index. +# +do_test descidx2-3.1 { + cksort {SELECT a FROM t1 ORDER BY a} +} {1 2 3 4 5 6 7 8 nosort} +do_test descidx2-3.2 { + cksort {SELECT a FROM t1 ORDER BY a ASC} +} {1 2 3 4 5 6 7 8 nosort} +do_test descidx2-3.3 { + cksort {SELECT a FROM t1 ORDER BY a DESC} +} {8 7 6 5 4 3 2 1 nosort} +do_test descidx2-3.4 { + cksort {SELECT b FROM t1 ORDER BY a} +} {1 2 3 4 5 6 7 8 nosort} +do_test descidx2-3.5 { + cksort {SELECT b FROM t1 ORDER BY a ASC} +} {1 2 3 4 5 6 7 8 nosort} +do_test descidx2-3.6 { + cksort {SELECT b FROM t1 ORDER BY a DESC} +} {8 7 6 5 4 3 2 1 nosort} +do_test descidx2-3.7 { + cksort {SELECT a FROM t1 ORDER BY b} +} {1 2 3 4 5 6 7 8 nosort} +do_test descidx2-3.8 { + cksort {SELECT a FROM t1 ORDER BY b ASC} +} {1 2 3 4 5 6 7 8 nosort} +do_test descidx2-3.9 { + cksort {SELECT a FROM t1 ORDER BY b DESC} +} {8 7 6 5 4 3 2 1 nosort} +do_test descidx2-3.10 { + cksort {SELECT b FROM t1 ORDER BY b} +} {1 2 3 4 5 6 7 8 nosort} +do_test descidx2-3.11 { + cksort {SELECT b FROM t1 ORDER BY b ASC} +} {1 2 3 4 5 6 7 8 nosort} +do_test descidx2-3.12 { + cksort {SELECT b FROM t1 ORDER BY b DESC} +} {8 7 6 5 4 3 2 1 nosort} + +do_test descidx2-3.21 { + cksort {SELECT a FROM t1 WHERE a>3 AND a<8 ORDER BY a} +} {4 5 6 7 nosort} +do_test descidx2-3.22 { + cksort {SELECT a FROM t1 WHERE a>3 AND a<8 ORDER BY a ASC} +} {4 5 6 7 nosort} +do_test descidx2-3.23 { + cksort {SELECT a FROM t1 WHERE a>3 AND a<8 ORDER BY a DESC} +} {7 6 5 4 nosort} +do_test descidx2-3.24 { + cksort {SELECT b FROM t1 WHERE a>3 AND a<8 ORDER BY a} +} {4 5 6 7 nosort} +do_test descidx2-3.25 { + cksort {SELECT b FROM t1 WHERE a>3 AND a<8 ORDER BY a ASC} +} {4 5 6 7 nosort} +do_test descidx2-3.26 { + cksort {SELECT b FROM t1 WHERE a>3 AND a<8 ORDER BY a DESC} +} {7 6 5 4 nosort} + +finish_test diff --git a/test/descidx3.test b/test/descidx3.test new file mode 100644 index 0000000..30dd8f8 --- /dev/null +++ b/test/descidx3.test @@ -0,0 +1,155 @@ +# 2006 January 02 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is descending indices. +# +# $Id: descidx3.test,v 1.6 2008/03/19 00:21:31 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +ifcapable !bloblit { + finish_test + return +} +#db eval {PRAGMA legacy_file_format=OFF} +sqlite3_db_config db LEGACY_FILE_FORMAT 0 + +# This procedure sets the value of the file-format in file 'test.db' +# to $newval. Also, the schema cookie is incremented. +# +proc set_file_format {newval} { + hexio_write test.db 44 [hexio_render_int32 $newval] + set schemacookie [hexio_get_int [hexio_read test.db 40 4]] + incr schemacookie + hexio_write test.db 40 [hexio_render_int32 $schemacookie] + return {} +} + +# This procedure returns the value of the file-format in file 'test.db'. +# +proc get_file_format {{fname test.db}} { + return [hexio_get_int [hexio_read $fname 44 4]] +} + +# Verify that the file format starts as 4. +# +do_test descidx3-1.1 { + execsql { + CREATE TABLE t1(i INTEGER PRIMARY KEY,a,b,c,d); + CREATE INDEX t1i1 ON t1(a DESC, b ASC, c DESC); + CREATE INDEX t1i2 ON t1(b DESC, c ASC, d DESC); + } + get_file_format +} {4} + +# Put some information in the table and verify that the descending +# index actually works. +# +do_test descidx3-2.1 { + execsql { + INSERT INTO t1 VALUES(1, NULL, NULL, NULL, NULL); + INSERT INTO t1 VALUES(2, 2, 2, 2, 2); + INSERT INTO t1 VALUES(3, 3, 3, 3, 3); + INSERT INTO t1 VALUES(4, 2.5, 2.5, 2.5, 2.5); + INSERT INTO t1 VALUES(5, -5, -5, -5, -5); + INSERT INTO t1 VALUES(6, 'six', 'six', 'six', 'six'); + INSERT INTO t1 VALUES(7, x'77', x'77', x'77', x'77'); + INSERT INTO t1 VALUES(8, 'eight', 'eight', 'eight', 'eight'); + INSERT INTO t1 VALUES(9, x'7979', x'7979', x'7979', x'7979'); + SELECT count(*) FROM t1; + } +} 9 +do_test descidx3-2.2 { + execsql { + SELECT i FROM t1 ORDER BY a; + } +} {1 5 2 4 3 8 6 7 9} +do_test descidx3-2.3 { + execsql { + SELECT i FROM t1 ORDER BY a DESC; + } +} {9 7 6 8 3 4 2 5 1} + +# The "natural" order for the index is decreasing +do_test descidx3-2.4 { + execsql { + SELECT i FROM t1 WHERE a<=x'7979'; + } +} {9 7 6 8 3 4 2 5} +do_test descidx3-2.5 { + execsql { + SELECT i FROM t1 WHERE a>-99; + } +} {9 7 6 8 3 4 2 5} + +# Even when all values of t1.a are the same, sorting by A returns +# the rows in reverse order because this the natural order of the +# index. +# +do_test descidx3-3.1 { + execsql { + UPDATE t1 SET a=1; + SELECT i FROM t1 ORDER BY a; + } +} {9 7 6 8 3 4 2 5 1} +do_test descidx3-3.2 { + execsql { + SELECT i FROM t1 WHERE a=1 AND b>0 AND b<'zzz' + } +} {2 4 3 8 6} +do_test descidx3-3.3 { + execsql { + SELECT i FROM t1 WHERE b>0 AND b<'zzz' + } +} {6 8 3 4 2} +do_test descidx3-3.4 { + execsql { + SELECT i FROM t1 WHERE a=1 AND b>-9999 AND b-9999 AND b0 AND b<'zzz'; + }] + } {2 3 4 6 8} + do_test descidx3-4.2 { + execsql { + UPDATE t1 SET a=1; + SELECT i FROM t1 WHERE a IN (1,2) AND b>0 AND b<'zzz'; + } + } {2 4 3 8 6} + do_test descidx3-4.3 { + execsql { + UPDATE t1 SET b=2; + SELECT i FROM t1 WHERE a IN (1,2) AND b>0 AND b<'zzz'; + } + } {9 7 6 8 3 4 2 5 1} +} + +finish_test diff --git a/test/diskfull.test b/test/diskfull.test new file mode 100644 index 0000000..391dfb4 --- /dev/null +++ b/test/diskfull.test @@ -0,0 +1,115 @@ +# 2001 October 12 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing for correct handling of disk full +# errors. +# +# $Id: diskfull.test,v 1.8 2008/07/12 14:52:20 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +set sqlite_io_error_persist 0 +set sqlite_io_error_hit 0 +set sqlite_io_error_pending 0 +do_test diskfull-1.1 { + execsql { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(randstr(1000,1000)); + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + CREATE INDEX t1i1 ON t1(x); + CREATE TABLE t2 AS SELECT x AS a, x AS b FROM t1; + CREATE INDEX t2i1 ON t2(b); + } +} {} +set sqlite_diskfull_pending 0 +integrity_check diskfull-1.2 +do_test diskfull-1.3 { + set sqlite_diskfull_pending 1 + catchsql { + INSERT INTO t1 SELECT * FROM t1; + } +} {1 {database or disk is full}} +set sqlite_diskfull_pending 0 +integrity_check diskfull-1.4 +do_test diskfull-1.5 { + set sqlite_diskfull_pending 1 + catchsql { + DELETE FROM t1; + } +} {1 {database or disk is full}} +set sqlite_diskfull_pending 0 +set sqlite_io_error_hit 0 +integrity_check diskfull-1.6 + +proc do_diskfull_test {prefix sql} { + set ::go 1 + set ::sql $sql + set ::i 1 + while {$::go} { + incr ::i + do_test ${prefix}.$::i.1 { + set ::sqlite_diskfull_pending $::i + set ::sqlite_diskfull 0 + set r [catchsql $::sql] + if {!$::sqlite_diskfull} { + set r {1 {database or disk is full}} + set ::go 0 + } + if {$r=="1 {disk I/O error}"} { + set r {1 {database or disk is full}} + } + set r + } {1 {database or disk is full}} + set ::sqlite_diskfull_pending 0 + db close + sqlite3 db test.db + integrity_check ${prefix}.$::i.2 + } +} + +do_diskfull_test diskfull-2 VACUUM + +# db close +# forcedelete test.db +# forcedelete test.db-journal +# sqlite3 db test.db +# +# do_test diskfull-3.1 { +# execsql { +# PRAGMA default_cache_size = 10; +# CREATE TABLE t3(a, b, UNIQUE(a, b)); +# INSERT INTO t3 VALUES( randstr(100, 100), randstr(100, 100) ); +# INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3; +# INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3; +# INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3; +# INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3; +# INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3; +# INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3; +# INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3; +# UPDATE t3 +# SET b = (SELECT a FROM t3 WHERE rowid = (SELECT max(rowid)-1 FROM t3)) +# WHERE rowid = (SELECT max(rowid) FROM t3); +# PRAGMA cache_size; +# } +# } {10} +# +# do_diskfull_test diskfull-3.2 { +# BEGIN; +# INSERT INTO t3 VALUES( randstr(100, 100), randstr(100, 100) ); +# UPDATE t3 SET a = b; +# COMMIT; +# } + +finish_test diff --git a/test/distinct.test b/test/distinct.test new file mode 100644 index 0000000..760b234 --- /dev/null +++ b/test/distinct.test @@ -0,0 +1,408 @@ +# 2011 July 1 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script is the DISTINCT modifier. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !compound { + finish_test + return +} + +set testprefix distinct + + +proc is_distinct_noop {sql} { + set sql1 $sql + set sql2 [string map {DISTINCT ""} $sql] + + set program1 [list] + set program2 [list] + db eval "EXPLAIN $sql1" { + if {$opcode != "Noop" && $opcode != "Explain"} { lappend program1 $opcode } + } + db eval "EXPLAIN $sql2" { + if {$opcode != "Noop" && $opcode != "Explain"} { lappend program2 $opcode } + } + return [expr {$program1==$program2}] +} + +proc do_distinct_noop_test {tn sql} { + uplevel [list do_test $tn [list is_distinct_noop $sql] 1] +} +proc do_distinct_not_noop_test {tn sql} { + uplevel [list do_test $tn [list is_distinct_noop $sql] 0] +} + +proc do_temptables_test {tn sql temptables} { + uplevel [list do_test $tn [subst -novar { + set ret "" + db eval "EXPLAIN [set sql]" { + if {$opcode == "OpenEphemeral" || $opcode == "SorterOpen"} { + if {$p5!=8 && $p5!=0} { error "p5 = $p5" } + if {$p5==8} { + lappend ret hash + } else { + lappend ret btree + } + } + } + set ret + }] $temptables] +} + + +#------------------------------------------------------------------------- +# The following tests - distinct-1.* - check that the planner correctly +# detects cases where a UNIQUE index means that a DISTINCT clause is +# redundant. Currently the planner only detects such cases when there +# is a single table in the FROM clause. +# +do_execsql_test 1.0 { + CREATE TABLE t1(a, b, c, d); + CREATE UNIQUE INDEX i1 ON t1(b, c); + CREATE UNIQUE INDEX i2 ON t1(d COLLATE nocase); + + CREATE TABLE t2(x INTEGER PRIMARY KEY, y); + + CREATE TABLE t3(c1 PRIMARY KEY NOT NULL, c2 NOT NULL); + CREATE INDEX i3 ON t3(c2); + + CREATE TABLE t4(a, b NOT NULL, c NOT NULL, d NOT NULL); + CREATE UNIQUE INDEX t4i1 ON t4(b, c); + CREATE UNIQUE INDEX t4i2 ON t4(d COLLATE nocase); +} +foreach {tn noop sql} { + + 1.1 0 "SELECT DISTINCT b, c FROM t1" + 1.2 1 "SELECT DISTINCT b, c FROM t4" + 2.1 0 "SELECT DISTINCT c FROM t1 WHERE b = ?" + 2.2 1 "SELECT DISTINCT c FROM t4 WHERE b = ?" + 3 1 "SELECT DISTINCT rowid FROM t1" + 4 1 "SELECT DISTINCT rowid, a FROM t1" + 5 1 "SELECT DISTINCT x FROM t2" + 6 1 "SELECT DISTINCT * FROM t2" + 7 1 "SELECT DISTINCT * FROM (SELECT * FROM t2)" + + 8.1 0 "SELECT DISTINCT * FROM t1" + 8.2 1 "SELECT DISTINCT * FROM t4" + + 8 0 "SELECT DISTINCT a, b FROM t1" + + 9 0 "SELECT DISTINCT c FROM t1 WHERE b IN (1,2)" + 10 0 "SELECT DISTINCT c FROM t1" + 11 0 "SELECT DISTINCT b FROM t1" + + 12.1 0 "SELECT DISTINCT a, d FROM t1" + 12.2 0 "SELECT DISTINCT a, d FROM t4" + 13.1 0 "SELECT DISTINCT a, b, c COLLATE nocase FROM t1" + 13.2 0 "SELECT DISTINCT a, b, c COLLATE nocase FROM t4" + 14.1 0 "SELECT DISTINCT a, d COLLATE nocase FROM t1" + 14.2 1 "SELECT DISTINCT a, d COLLATE nocase FROM t4" + + 15 0 "SELECT DISTINCT a, d COLLATE binary FROM t1" + 16.1 0 "SELECT DISTINCT a, b, c COLLATE binary FROM t1" + 16.2 1 "SELECT DISTINCT a, b, c COLLATE binary FROM t4" + + 16 0 "SELECT DISTINCT t1.rowid FROM t1, t2" + 17 0 { /* Technically, it would be possible to detect that DISTINCT + ** is a no-op in cases like the following. But SQLite does not + ** do so. */ + SELECT DISTINCT t1.rowid FROM t1, t2 WHERE t1.rowid=t2.rowid } + + 18 1 "SELECT DISTINCT c1, c2 FROM t3" + 19 1 "SELECT DISTINCT c1 FROM t3" + 20 1 "SELECT DISTINCT * FROM t3" + 21 0 "SELECT DISTINCT c2 FROM t3" + + 22 0 "SELECT DISTINCT * FROM (SELECT 1, 2, 3 UNION SELECT 4, 5, 6)" + + 24 0 "SELECT DISTINCT rowid/2 FROM t1" + 25 1 "SELECT DISTINCT rowid/2, rowid FROM t1" + 26.1 0 "SELECT DISTINCT rowid/2, b FROM t1 WHERE c = ?" + 26.2 1 "SELECT DISTINCT rowid/2, b FROM t4 WHERE c = ?" +} { + if {$noop} { + do_distinct_noop_test 1.$tn $sql + } else { + do_distinct_not_noop_test 1.$tn $sql + } +} + +#------------------------------------------------------------------------- +# The following tests - distinct-2.* - test cases where an index is +# used to deliver results in order of the DISTINCT expressions. +# +drop_all_tables +do_execsql_test 2.0 { + CREATE TABLE t1(a, b, c); + + CREATE INDEX i1 ON t1(a, b); + CREATE INDEX i2 ON t1(b COLLATE nocase, c COLLATE nocase); + + INSERT INTO t1 VALUES('a', 'b', 'c'); + INSERT INTO t1 VALUES('A', 'B', 'C'); + INSERT INTO t1 VALUES('a', 'b', 'c'); + INSERT INTO t1 VALUES('A', 'B', 'C'); +} + +foreach {tn sql temptables res} { + 1 "a, b FROM t1" {} {A B a b} + 2 "b, a FROM t1" {} {B A b a} + 3 "a, b, c FROM t1" {hash} {A B C a b c} + 4 "a, b, c FROM t1 ORDER BY a, b, c" {btree} {A B C a b c} + 5 "b FROM t1 WHERE a = 'a'" {} {b} + 6 "b FROM t1 ORDER BY +b COLLATE binary" {btree hash} {B b} + 7 "a FROM t1" {} {A a} + 8 "b COLLATE nocase FROM t1" {} {b} + 9 "b COLLATE nocase FROM t1 ORDER BY b COLLATE nocase" {} {b} +} { + do_execsql_test 2.$tn.1 "SELECT DISTINCT $sql" $res + do_temptables_test 2.$tn.2 "SELECT DISTINCT $sql" $temptables +} + +do_execsql_test 2.A { + SELECT (SELECT DISTINCT o.a FROM t1 AS i) FROM t1 AS o ORDER BY rowid; +} {a A a A} + +do_test 3.0 { + db eval { + CREATE TABLE t3(a INTEGER, b INTEGER, c, UNIQUE(a,b)); + INSERT INTO t3 VALUES + (null, null, 1), + (null, null, 2), + (null, 3, 4), + (null, 3, 5), + (6, null, 7), + (6, null, 8); + SELECT DISTINCT a, b FROM t3 ORDER BY +a, +b; + } +} {{} {} {} 3 6 {}} +do_test 3.1 { + regexp {OpenEphemeral} [db eval { + EXPLAIN SELECT DISTINCT a, b FROM t3 ORDER BY +a, +b; + }] +} {0} + +#------------------------------------------------------------------------- +# Ticket [fccbde530a6583bf2748400919f1603d5425995c] (2014-01-08) +# The logic that computes DISTINCT sometimes thinks that a zeroblob() +# and a blob of all zeros are different when they should be the same. +# +do_execsql_test 4.1 { + DROP TABLE IF EXISTS t1; + DROP TABLE IF EXISTS t2; + CREATE TABLE t1(a INTEGER); + INSERT INTO t1 VALUES(3); + INSERT INTO t1 VALUES(2); + INSERT INTO t1 VALUES(1); + INSERT INTO t1 VALUES(2); + INSERT INTO t1 VALUES(3); + INSERT INTO t1 VALUES(1); + CREATE TABLE t2(x); + INSERT INTO t2 + SELECT DISTINCT + CASE a WHEN 1 THEN x'0000000000' + WHEN 2 THEN zeroblob(5) + ELSE 'xyzzy' END + FROM t1; + SELECT quote(x) FROM t2 ORDER BY 1; +} {'xyzzy' X'0000000000'} + +#---------------------------------------------------------------------------- +# Ticket [c5ea805691bfc4204b1cb9e9aa0103bd48bc7d34] (2014-12-04) +# Make sure that DISTINCT works together with ORDER BY and descending +# indexes. +# +do_execsql_test 5.1 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(x); + INSERT INTO t1(x) VALUES(3),(1),(5),(2),(6),(4),(5),(1),(3); + CREATE INDEX t1x ON t1(x DESC); + SELECT DISTINCT x FROM t1 ORDER BY x ASC; +} {1 2 3 4 5 6} +do_execsql_test 5.2 { + SELECT DISTINCT x FROM t1 ORDER BY x DESC; +} {6 5 4 3 2 1} +do_execsql_test 5.3 { + SELECT DISTINCT x FROM t1 ORDER BY x; +} {1 2 3 4 5 6} +do_execsql_test 5.4 { + DROP INDEX t1x; + CREATE INDEX t1x ON t1(x ASC); + SELECT DISTINCT x FROM t1 ORDER BY x ASC; +} {1 2 3 4 5 6} +do_execsql_test 5.5 { + SELECT DISTINCT x FROM t1 ORDER BY x DESC; +} {6 5 4 3 2 1} +do_execsql_test 5.6 { + SELECT DISTINCT x FROM t1 ORDER BY x; +} {1 2 3 4 5 6} + +#------------------------------------------------------------------------- +# 2015-11-23. Problem discovered by Kostya Serebryany using libFuzzer +# +db close +sqlite3 db :memory: +do_execsql_test 6.1 { + CREATE TABLE jjj(x); + SELECT (SELECT 'mmm' UNION SELECT DISTINCT max(name) ORDER BY 1) + FROM sqlite_master; +} {jjj} +do_execsql_test 6.2 { + CREATE TABLE nnn(x); + SELECT (SELECT 'mmm' UNION SELECT DISTINCT max(name) ORDER BY 1) + FROM sqlite_master; +} {mmm} + +#------------------------------------------------------------------------- +# Ticket [9c944882] +# +reset_db +do_execsql_test 7.0 { + CREATE TABLE t1(a INTEGER PRIMARY KEY); + CREATE TABLE t3(a INTEGER PRIMARY KEY); + + CREATE TABLE t4(x); + CREATE TABLE t5(y); + + INSERT INTO t5 VALUES(1), (2), (2); + INSERT INTO t1 VALUES(2); + INSERT INTO t3 VALUES(2); + INSERT INTO t4 VALUES(2); +} + +do_execsql_test 7.1 { + WITH t2(b) AS ( + SELECT DISTINCT y FROM t5 ORDER BY y + ) + SELECT * FROM + t4 CROSS JOIN t3 CROSS JOIN t1 + WHERE (t1.a=t3.a) AND (SELECT count(*) FROM t2 AS y WHERE t4.x!='abc')=t1.a +} {2 2 2} + +# 2021-04-06 forum post https://sqlite.org/forum/forumpost/66954e9ece +reset_db +do_execsql_test 8.0 { + CREATE TABLE person ( pid INT) ; + CREATE UNIQUE INDEX idx ON person ( pid ) WHERE pid == 1; + INSERT INTO person VALUES (1), (10), (10); + SELECT DISTINCT pid FROM person where pid = 10; +} {10} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 9.0 { + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES('a', 'a'); + INSERT INTO t1 VALUES('a', 'b'); + INSERT INTO t1 VALUES('a', 'c'); + + INSERT INTO t1 VALUES('b', 'a'); + INSERT INTO t1 VALUES('b', 'b'); + INSERT INTO t1 VALUES('b', 'c'); + + INSERT INTO t1 VALUES('a', 'a'); + INSERT INTO t1 VALUES('b', 'b'); + + INSERT INTO t1 VALUES('A', 'A'); + INSERT INTO t1 VALUES('B', 'B'); +} + +foreach {tn idx} { + 1 { } + 2 { CREATE INDEX i1 ON t1(a, b); } + 3 { CREATE INDEX i1 ON t1(b, a); } + 4 { CREATE INDEX i1 ON t1(a COLLATE nocase, b COLLATE nocase); } + 5 { CREATE INDEX i1 ON t1(b COLLATE nocase, a COLLATE nocase); } +} { + + execsql { DROP INDEX IF EXISTS i1 } + execsql $idx + + do_execsql_test 9.$tn.1 { + SELECT DISTINCT a, b FROM t1 ORDER BY a, b + } { + A A B B + a a a b a c + b a b b b c + } + + do_execsql_test 9.$tn.1 { + SELECT DISTINCT a COLLATE nocase, b COLLATE nocase FROM t1 + ORDER BY a COLLATE nocase, b COLLATE nocase + } { + a a a b a c + b a b b b c + } +} + +# 2023-03-16 +# https://sqlite.org/forum/forumpost/16ce2bb7a639e29b +# ticket c36cdb4afd504dc1 +# ticket 4051a7f931d9ba24 +# ticket d6fd512f50513ab7 +# +do_execsql_test 10.1 { + SELECT DISTINCT + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + ORDER BY + 'x','x','x','x','x','x','x','x','x','x', + 'x','x','x','x','x','x','x','x','x','x', + 'x','x','x','x','x','x','x','x','x','x', + 'x','x','x','x','x','x','x','x','x','x', + 'x','x','x','x','x','x','x','x','x','x', + 'x','x','x','x','x','x','x','x','x','x', + 'x','x','x','x'; +} {1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1} +do_execsql_test 10.2 { + EXPLAIN + SELECT DISTINCT + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + ORDER BY + 'x','x','x','x','x','x','x','x','x','x', + 'x','x','x','x','x','x','x','x','x','x', + 'x','x','x','x','x','x','x','x','x','x', + 'x','x','x','x','x','x','x','x','x','x', + 'x','x','x','x','x','x','x','x','x','x', + 'x','x','x','x','x','x','x','x','x','x', + 'x','x','x','x'; +} {/0 Init 0 /} +do_execsql_test 10.3 { + EXPLAIN CREATE TABLE t2 AS SELECT DISTINCT ':memory:', 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 ORDER BY '%J%j%w%s', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', '%J%j%w%s', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 42e-300, 'unixepoch', 'unixepoch', 'unixepoch' LIMIT 0xda; +} {/0 Init 0/} +do_execsql_test 10.4 { + DROP TABLE IF EXISTS t0; + CREATE TABLE t0 AS SELECT DISTINCT 0xda, 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 0xda-0xda-42e-300, 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0', 'lit0' ORDER BY '%%', '%%', '%%', '%%', '%%', '%%', '%%', '%%', '%%', '%%', '%%', '%%', '%%', '%%', '%%', '%Y-%m-%d', '%%', '%%', '%%', '%%', '%%', '%%', '%%', '%%', '%%', '%%', 'lit0', '%%', '%%', '%%', '%%', '%%', '%%', '%%', '%%', '%%', '%%', '%%', '%%', '%%', 'auto', '%%', '%%', '%%', '%%', '%%', '%%', '%%', '%%', '%%', '%%', '%%', ':memory:', '%%', '%%', '%%', '%%', '%%', '%%', '%%', '%%', '%%', '%%', ''; + SELECT count(*) FROM t0; +} {1} +do_execsql_test 10.5 { + DROP TABLE IF EXISTS t2; + CREATE TABLE t2 AS SELECT DISTINCT ':memory:', 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 0.0*7/0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 ORDER BY '%J%j%w%s', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', '%J%j%w%s', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 'unixepoch', 42e-300, 'unixepoch', 'unixepoch', 'unixepoch' LIMIT 0xda; + SELECT count(*) FROM t2; +} {1} + +finish_test diff --git a/test/distinct2.test b/test/distinct2.test new file mode 100644 index 0000000..958d963 --- /dev/null +++ b/test/distinct2.test @@ -0,0 +1,316 @@ +# 2016-04-15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script is DISTINCT queries using the skip-ahead +# optimization. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +set testprefix distinct2 + +do_execsql_test 100 { + CREATE TABLE t1(x INTEGER PRIMARY KEY); + INSERT INTO t1 VALUES(0),(1),(2); + CREATE TABLE t2 AS + SELECT DISTINCT a.x AS aa, b.x AS bb + FROM t1 a, t1 b; + SELECT *, '|' FROM t2 ORDER BY aa, bb; +} {0 0 | 0 1 | 0 2 | 1 0 | 1 1 | 1 2 | 2 0 | 2 1 | 2 2 |} +do_execsql_test 110 { + DROP TABLE t2; + CREATE TABLE t2 AS + SELECT DISTINCT a.x AS aa, b.x AS bb + FROM t1 a, t1 b + WHERE a.x IN t1 AND b.x IN t1; + SELECT *, '|' FROM t2 ORDER BY aa, bb; +} {0 0 | 0 1 | 0 2 | 1 0 | 1 1 | 1 2 | 2 0 | 2 1 | 2 2 |} +do_execsql_test 120 { + CREATE TABLE t102 (i0 TEXT UNIQUE NOT NULL); + INSERT INTO t102 VALUES ('0'),('1'),('2'); + DROP TABLE t2; + CREATE TABLE t2 AS + SELECT DISTINCT * + FROM t102 AS t0 + JOIN t102 AS t4 ON (t2.i0 IN t102) + NATURAL JOIN t102 AS t3 + JOIN t102 AS t1 ON (t0.i0 IN t102) + JOIN t102 AS t2 ON (t2.i0=+t0.i0 OR (t0.i0<>500 AND t2.i0=t1.i0)); + SELECT *, '|' FROM t2 ORDER BY 1, 2, 3, 4, 5; +} {0 0 0 0 | 0 0 1 0 | 0 0 1 1 | 0 0 2 0 | 0 0 2 2 | 0 1 0 0 | 0 1 1 0 | 0 1 1 1 | 0 1 2 0 | 0 1 2 2 | 0 2 0 0 | 0 2 1 0 | 0 2 1 1 | 0 2 2 0 | 0 2 2 2 | 1 0 0 0 | 1 0 0 1 | 1 0 1 1 | 1 0 2 1 | 1 0 2 2 | 1 1 0 0 | 1 1 0 1 | 1 1 1 1 | 1 1 2 1 | 1 1 2 2 | 1 2 0 0 | 1 2 0 1 | 1 2 1 1 | 1 2 2 1 | 1 2 2 2 | 2 0 0 0 | 2 0 0 2 | 2 0 1 1 | 2 0 1 2 | 2 0 2 2 | 2 1 0 0 | 2 1 0 2 | 2 1 1 1 | 2 1 1 2 | 2 1 2 2 | 2 2 0 0 | 2 2 0 2 | 2 2 1 1 | 2 2 1 2 | 2 2 2 2 |} + +do_execsql_test 400 { + CREATE TABLE t4(a,b,c,d,e,f,g,h,i,j); + INSERT INTO t4 VALUES(0,1,2,3,4,5,6,7,8,9); + INSERT INTO t4 SELECT * FROM t4; + INSERT INTO t4 SELECT * FROM t4; + CREATE INDEX t4x ON t4(c,d,e); + SELECT DISTINCT a,b,c FROM t4 WHERE a=0 AND b=1; +} {0 1 2} +do_execsql_test 410 { + SELECT DISTINCT a,b,c,d FROM t4 WHERE a=0 AND b=1; +} {0 1 2 3} +do_execsql_test 411 { + SELECT DISTINCT d,a,b,c FROM t4 WHERE a=0 AND b=1; +} {3 0 1 2} +do_execsql_test 420 { + SELECT DISTINCT a,b,c,d,e FROM t4 WHERE a=0 AND b=1; +} {0 1 2 3 4} +do_execsql_test 430 { + SELECT DISTINCT a,b,c,d,e,f FROM t4 WHERE a=0 AND b=1; +} {0 1 2 3 4 5} + +do_execsql_test 500 { + CREATE TABLE t5(a INT, b INT); + CREATE UNIQUE INDEX t5x ON t5(a+b); + INSERT INTO t5(a,b) VALUES(0,0),(1,0),(1,1),(0,3); + CREATE TEMP TABLE out AS SELECT DISTINCT a+b FROM t5; + SELECT * FROM out ORDER BY 1; +} {0 1 2 3} + +do_execsql_test 600 { + CREATE TABLE t6a(x INTEGER PRIMARY KEY); + INSERT INTO t6a VALUES(1); + CREATE TABLE t6b(y INTEGER PRIMARY KEY); + INSERT INTO t6b VALUES(2),(3); + SELECT DISTINCT x, x FROM t6a, t6b; +} {1 1} + +do_execsql_test 700 { + CREATE TABLE t7(a, b, c); + WITH s(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM s WHERE (i+1)<200 + ) + INSERT INTO t7 SELECT i/100, i/50, i FROM s; +} +do_execsql_test 710 { + SELECT DISTINCT a, b FROM t7; +} { + 0 0 0 1 + 1 2 1 3 +} +do_execsql_test 720 { + SELECT DISTINCT a, b+1 FROM t7; +} { + 0 1 0 2 + 1 3 1 4 +} +do_execsql_test 730 { + CREATE INDEX i7 ON t7(a, b+1); + ANALYZE; + SELECT DISTINCT a, b+1 FROM t7; +} { + 0 1 0 2 + 1 3 1 4 +} + +do_execsql_test 800 { + CREATE TABLE t8(a, b, c); + WITH s(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM s WHERE (i+1)<100 + ) + INSERT INTO t8 SELECT i/40, i/20, i/40 FROM s; +} + +do_execsql_test 820 { + SELECT DISTINCT a, b, c FROM t8; +} { + 0 0 0 0 1 0 + 1 2 1 1 3 1 + 2 4 2 +} + +do_execsql_test 820 { + SELECT DISTINCT a, b, c FROM t8 WHERE b=3; +} {1 3 1} + +do_execsql_test 830 { + CREATE INDEX i8 ON t8(a, c); + ANALYZE; + SELECT DISTINCT a, b, c FROM t8 WHERE b=3; +} {1 3 1} + +do_execsql_test 900 { + CREATE TABLE t9(v); + INSERT INTO t9 VALUES + ('abcd'), ('Abcd'), ('aBcd'), ('ABcd'), ('abCd'), ('AbCd'), ('aBCd'), + ('ABCd'), ('abcD'), ('AbcD'), ('aBcD'), ('ABcD'), ('abCD'), ('AbCD'), + ('aBCD'), ('ABCD'), + ('wxyz'), ('Wxyz'), ('wXyz'), ('WXyz'), ('wxYz'), ('WxYz'), ('wXYz'), + ('WXYz'), ('wxyZ'), ('WxyZ'), ('wXyZ'), ('WXyZ'), ('wxYZ'), ('WxYZ'), + ('wXYZ'), ('WXYZ'); +} + +do_execsql_test 910 { + SELECT DISTINCT v COLLATE NOCASE, v FROM t9 ORDER BY +v; +} { + ABCD ABCD ABCd ABCd ABcD ABcD ABcd ABcd AbCD + AbCD AbCd AbCd AbcD AbcD Abcd Abcd + WXYZ WXYZ WXYz WXYz WXyZ WXyZ WXyz WXyz WxYZ + WxYZ WxYz WxYz WxyZ WxyZ Wxyz Wxyz + aBCD aBCD aBCd aBCd aBcD aBcD aBcd aBcd abCD + abCD abCd abCd abcD abcD abcd abcd + wXYZ wXYZ wXYz wXYz wXyZ wXyZ wXyz wXyz wxYZ + wxYZ wxYz wxYz wxyZ wxyZ wxyz wxyz +} + +do_execsql_test 920 { + CREATE INDEX i9 ON t9(v COLLATE NOCASE, v); + ANALYZE; + + SELECT DISTINCT v COLLATE NOCASE, v FROM t9 ORDER BY +v; +} { + ABCD ABCD ABCd ABCd ABcD ABcD ABcd ABcd AbCD + AbCD AbCd AbCd AbcD AbcD Abcd Abcd + WXYZ WXYZ WXYz WXYz WXyZ WXyZ WXyz WXyz WxYZ + WxYZ WxYz WxYz WxyZ WxyZ Wxyz Wxyz + aBCD aBCD aBCd aBCd aBcD aBcD aBcd aBcd abCD + abCD abCd abCd abcD abcD abcd abcd + wXYZ wXYZ wXYz wXYz wXyZ wXyZ wXyz wXyz wxYZ + wxYZ wxYz wxYz wxyZ wxyZ wxyz wxyz +} + +# Ticket https://sqlite.org/src/info/ef9318757b152e3a on 2017-11-21 +# Incorrect result due to a skip-ahead-distinct optimization on a +# join where no rows of the inner loop appear in the result set. +# +db close +sqlite3 db :memory: +do_execsql_test 1000 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b INTEGER); + CREATE INDEX t1b ON t1(b); + CREATE TABLE t2(x INTEGER PRIMARY KEY, y INTEGER); + CREATE INDEX t2y ON t2(y); + WITH RECURSIVE c(x) AS (VALUES(0) UNION ALL SELECT x+1 FROM c WHERE x<49) + INSERT INTO t1(b) SELECT x/10 - 1 FROM c; + WITH RECURSIVE c(x) AS (VALUES(-1) UNION ALL SELECT x+1 FROM c WHERE x<19) + INSERT INTO t2(x,y) SELECT x, 1 FROM c; + SELECT DISTINCT y FROM t1, t2 WHERE b=x AND b<>-1; + ANALYZE; + SELECT DISTINCT y FROM t1, t2 WHERE b=x AND b<>-1; +} {1 1} +db close +sqlite3 db :memory: +do_execsql_test 1010 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b INTEGER); + CREATE INDEX t1b ON t1(b); + CREATE TABLE t2(x INTEGER PRIMARY KEY, y INTEGER); + CREATE INDEX t2y ON t2(y); + WITH RECURSIVE c(x) AS (VALUES(0) UNION ALL SELECT x+1 FROM c WHERE x<49) + INSERT INTO t1(b) SELECT -(x/10 - 1) FROM c; + WITH RECURSIVE c(x) AS (VALUES(-1) UNION ALL SELECT x+1 FROM c WHERE x<19) + INSERT INTO t2(x,y) SELECT -x, 1 FROM c; + SELECT DISTINCT y FROM t1, t2 WHERE b=x AND b<>1 ORDER BY y DESC; + ANALYZE; + SELECT DISTINCT y FROM t1, t2 WHERE b=x AND b<>1 ORDER BY y DESC; +} {1 1} +db close +sqlite3 db :memory: +do_execsql_test 1020 { + CREATE TABLE t1(a, b); + CREATE INDEX t1a ON t1(a, b); + -- Lots of rows of (1, 'no'), followed by a single (1, 'yes'). + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100) + INSERT INTO t1(a, b) SELECT 1, 'no' FROM c; + INSERT INTO t1(a, b) VALUES(1, 'yes'); + CREATE TABLE t2(x PRIMARY KEY); + INSERT INTO t2 VALUES('yes'); + SELECT DISTINCT a FROM t1, t2 WHERE x=b; + ANALYZE; + SELECT DISTINCT a FROM t1, t2 WHERE x=b; +} {1 1} + +#------------------------------------------------------------------------- +reset_db + +do_execsql_test 2000 { + CREATE TABLE t0 (c0, c1, c2, PRIMARY KEY (c0, c1)); + CREATE TABLE t1 (c2); + INSERT INTO t0(c2) VALUES (0),(1),(3),(4),(5),(6),(7),(8),(9),(10),(11); + INSERT INTO t0(c1) VALUES ('a'); + INSERT INTO t1(c2) VALUES (0); +} +do_execsql_test 2010 { + SELECT DISTINCT t0.c0, t1._rowid_, t0.c1 FROM t1 CROSS JOIN t0 ORDER BY t0.c0; +} {{} 1 {} {} 1 a} +do_execsql_test 1.2 { + ANALYZE; +} +do_execsql_test 2020 { + SELECT DISTINCT t0.c0, t1._rowid_, t0.c1 FROM t1 CROSS JOIN t0 ORDER BY t0.c0; +} {{} 1 {} {} 1 a} + + +do_execsql_test 2030 { + CREATE TABLE t2(a, b, c); + CREATE INDEX t2ab ON t2(a, b); + + WITH c(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM c WHERE i<64) + INSERT INTO t2 SELECT 'one', i%2, 'one' FROM c; + + WITH c(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM c WHERE i<64) + INSERT INTO t2 SELECT 'two', i%2, 'two' FROM c; + + CREATE TABLE t3(x INTEGER PRIMARY KEY); + INSERT INTO t3 VALUES(1); + + ANALYZE; +} +do_execsql_test 2040 { + SELECT DISTINCT a, b, x FROM t3 CROSS JOIN t2 ORDER BY a, +b; +} { + one 0 1 + one 1 1 + two 0 1 + two 1 1 +} + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 3000 { + CREATE TABLE t0 (c0, c1 NOT NULL DEFAULT 1, c2, PRIMARY KEY (c0, c1)); + INSERT INTO t0(c2) VALUES (NULL), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL); + INSERT INTO t0(c2) VALUES('a'); +} + +do_execsql_test 3010 { + SELECT DISTINCT * FROM t0 WHERE NULL IS t0.c0; +} { + {} 1 {} + {} 1 a +} + +do_execsql_test 3020 { + ANALYZE; +} + +do_execsql_test 3030 { + SELECT DISTINCT * FROM t0 WHERE NULL IS c0; +} { + {} 1 {} + {} 1 a +} + +#------------------------------------------------------------------------- +# +reset_db + +do_execsql_test 4010 { + CREATE TABLE t1(a, b COLLATE RTRIM); + INSERT INTO t1 VALUES(1, ''), (2, ' '), (3, ' '); +} +do_execsql_test 4020 { + SELECT b FROM t1 UNION SELECT 1; +} {1 { }} + +finish_test diff --git a/test/distinctagg.test b/test/distinctagg.test new file mode 100644 index 0000000..199ca06 --- /dev/null +++ b/test/distinctagg.test @@ -0,0 +1,217 @@ +# 2005 September 11 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script is the DISTINCT modifier on aggregate functions. +# +# $Id: distinctagg.test,v 1.3 2009/02/09 13:19:28 drh Exp $ + + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix distinctagg + +do_test distinctagg-1.1 { + execsql { + CREATE TABLE t1(a,b,c); + INSERT INTO t1 VALUES(1,2,3); + INSERT INTO t1 VALUES(1,3,4); + INSERT INTO t1 VALUES(1,3,5); + SELECT count(distinct a), + count(distinct b), + count(distinct c), + count(all a) FROM t1; + } +} {1 2 3 3} +do_test distinctagg-1.2 { + execsql { + SELECT b, count(distinct c) FROM t1 GROUP BY b + } +} {2 1 3 2} +do_test distinctagg-1.3 { + execsql { + INSERT INTO t1 SELECT a+1, b+3, c+5 FROM t1; + INSERT INTO t1 SELECT a+2, b+6, c+10 FROM t1; + INSERT INTO t1 SELECT a+4, b+12, c+20 FROM t1; + SELECT count(*), count(distinct a), count(distinct b) FROM t1 + } +} {24 8 16} +do_test distinctagg-1.4 { + execsql { + SELECT a, count(distinct c) FROM t1 GROUP BY a ORDER BY a + } +} {1 3 2 3 3 3 4 3 5 3 6 3 7 3 8 3} + +do_test distinctagg-2.1 { + catchsql { + SELECT count(distinct) FROM t1; + } +} {1 {DISTINCT aggregates must have exactly one argument}} +do_test distinctagg-2.2 { + catchsql { + SELECT string_agg(distinct a,b) FROM t1; + } +} {1 {DISTINCT aggregates must have exactly one argument}} + +#-------------------------------------------------------------------------- +reset_db +do_execsql_test 3.0 { + CREATE TABLE t1(a, b, c); + CREATE TABLE t2(d, e, f); + + INSERT INTO t1 VALUES (1, 1, 1); + INSERT INTO t1 VALUES (2, 2, 2); + INSERT INTO t1 VALUES (3, 3, 3); + INSERT INTO t1 VALUES (4, 1, 4); + INSERT INTO t1 VALUES (5, 2, 1); + INSERT INTO t1 VALUES (5, 3, 2); + INSERT INTO t1 VALUES (4, 1, 3); + INSERT INTO t1 VALUES (3, 2, 4); + INSERT INTO t1 VALUES (2, 3, 1); + INSERT INTO t1 VALUES (1, 1, 2); + + INSERT INTO t2 VALUES('a', 'a', 'a'); + INSERT INTO t2 VALUES('b', 'b', 'b'); + INSERT INTO t2 VALUES('c', 'c', 'c'); + + CREATE INDEX t1a ON t1(a); + CREATE INDEX t1bc ON t1(b, c); +} + +foreach {tn use_eph sql res} { + 1 0 "SELECT count(DISTINCT a) FROM t1" 5 + 2 0 "SELECT count(DISTINCT b) FROM t1" 3 + 3 1 "SELECT count(DISTINCT c) FROM t1" 4 + 4 0 "SELECT count(DISTINCT c) FROM t1 WHERE b=3" 3 + 5 0 "SELECT count(DISTINCT rowid) FROM t1" 10 + 6 0 "SELECT count(DISTINCT a) FROM t1, t2" 5 + 7 0 "SELECT count(DISTINCT a) FROM t2, t1" 5 + 8 1 "SELECT count(DISTINCT a+b) FROM t1, t2, t2, t2" 6 + 9 0 "SELECT count(DISTINCT c) FROM t1 WHERE c=2" 1 + 10 1 "SELECT count(DISTINCT t1.rowid) FROM t1, t2" 10 +} { + do_test 3.$tn.1 { + set prg [db eval "EXPLAIN $sql"] + set idx [lsearch $prg OpenEphemeral] + expr {$idx>=0} + } $use_eph + + do_execsql_test 3.$tn.2 $sql $res +} + +do_execsql_test 3.10 { + SELECT a, count(DISTINCT b) FROM t1 GROUP BY a; +} { + 1 1 2 2 3 2 4 1 5 2 +} + +#-------------------------------------------------------------------------- +reset_db +do_execsql_test 3.0 { + CREATE TABLE t1(a, b, c); + CREATE INDEX t1a ON t1(a); + CREATE INDEX t1bc ON t1(b, c); + + INSERT INTO t1 VALUES(1, 'A', 1); + INSERT INTO t1 VALUES(1, 'A', 1); + INSERT INTO t1 VALUES(2, 'A', 2); + INSERT INTO t1 VALUES(2, 'A', 2); + INSERT INTO t1 VALUES(1, 'B', 1); + INSERT INTO t1 VALUES(2, 'B', 2); + INSERT INTO t1 VALUES(3, 'B', 3); + INSERT INTO t1 VALUES(NULL, 'B', NULL); + INSERT INTO t1 VALUES(NULL, 'C', NULL); + INSERT INTO t1 VALUES('d', 'D', 'd'); + + CREATE TABLE t2(d, e, f); + CREATE INDEX t2def ON t2(d, e, f); + + INSERT INTO t2 VALUES(1, 1, 'a'); + INSERT INTO t2 VALUES(1, 1, 'a'); + INSERT INTO t2 VALUES(1, 2, 'a'); + INSERT INTO t2 VALUES(1, 2, 'a'); + INSERT INTO t2 VALUES(1, 2, 'b'); + INSERT INTO t2 VALUES(1, 3, 'b'); + INSERT INTO t2 VALUES(1, 3, 'a'); + INSERT INTO t2 VALUES(1, 3, 'b'); + INSERT INTO t2 VALUES(2, 3, 'x'); + INSERT INTO t2 VALUES(2, 3, 'y'); + INSERT INTO t2 VALUES(2, 3, 'z'); + + CREATE TABLE t3(x, y, z); + INSERT INTO t3 VALUES(1,1,1); + INSERT INTO t3 VALUES(2,2,2); +} + +foreach {tn use_eph sql res} { + 1 0 "SELECT count(DISTINCT c) FROM t1 GROUP BY b" {2 3 0 1} + 2 1 "SELECT count(DISTINCT a) FROM t1 GROUP BY b" {2 3 0 1} + 3 1 "SELECT count(DISTINCT a) FROM t1 GROUP BY b+c" {0 1 1 1 1} + + 4 0 "SELECT count(DISTINCT f) FROM t2 GROUP BY d, e" {1 2 2 3} + 5 1 "SELECT count(DISTINCT f) FROM t2 GROUP BY d" {2 3} + 6 0 "SELECT count(DISTINCT f) FROM t2 WHERE d IS 1 GROUP BY e" {1 2 2} +} { + do_test 4.$tn.1 { + set prg [db eval "EXPLAIN $sql"] + set idx [lsearch $prg OpenEphemeral] + expr {$idx>=0} + } $use_eph + + do_execsql_test 4.$tn.2 $sql $res +} + + +set t3root [db one {SELECT rootpage FROM sqlite_schema WHERE name='t3'}] +foreach {tn use_t3 sql res} { + 1 1 "SELECT count(*) FROM t3" 2 + 2 0 "SELECT count(*) FROM t1" 10 + 2 1 "SELECT count(DISTINCT a) FROM t1, t3" 4 + 3 1 "SELECT count(DISTINCT a) FROM t1 LEFT JOIN t3" 4 + 4 1 "SELECT count(DISTINCT a) FROM t1 LEFT JOIN t3 WHERE t3.x=1" 4 + 5 1 "SELECT count(DISTINCT a) FROM t1 LEFT JOIN t3 WHERE t3.x=0" 0 + 6 1 "SELECT count(DISTINCT a) FROM t1 LEFT JOIN t3 ON (t3.x=0)" 4 + 7 1 "SELECT count(DISTINCT x) FROM t1 LEFT JOIN t3" 2 + 8 1 "SELECT count(DISTINCT x) FROM t1 LEFT JOIN t3 WHERE t3.x=1" 1 + 9 1 "SELECT count(DISTINCT x) FROM t1 LEFT JOIN t3 WHERE t3.x=0" 0 + 10 1 "SELECT count(DISTINCT x) FROM t1 LEFT JOIN t3 ON (t3.x=0)" 0 + +} { + unset -nocomplain a + do_test 5.$tn.1 { + set bUse 0 + db eval "EXPLAIN $sql" a { + if {$a(opcode)=="OpenRead" && $a(p2)==$t3root} {set bUse 1} + } + set bUse + } $use_t3 + + do_execsql_test 5.$tn.2 $sql $res +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 6.0 { + CREATE TABLE t1(a, b); + CREATE TABLE t2(c, d); + INSERT INTO t1 VALUES(123,456); + INSERT INTO t2 VALUES(123,456); +} +do_execsql_test 6.1 { + SELECT count(DISTINCT c) FROM t1 LEFT JOIN t2; +} {1} + +do_execsql_test 7.0 { + CREATE TABLE v1 ( v2 UNIQUE, v3 AS( TYPEOF ( NULL ) ) UNIQUE ); + SELECT COUNT ( DISTINCT TRUE ) FROM v1 GROUP BY likelihood ( v3 , 0.100000 ); +} + + +finish_test diff --git a/test/e_blobbytes.test b/test/e_blobbytes.test new file mode 100644 index 0000000..c24318c --- /dev/null +++ b/test/e_blobbytes.test @@ -0,0 +1,79 @@ +# 2014 October 30 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix e_blobbytes + +ifcapable !incrblob { + finish_test + return +} + +do_execsql_test 1.0 { + CREATE TABLE q1(r INTEGER PRIMARY KEY, s TEXT); + WITH d(a, b) AS ( + SELECT 0, '' + UNION ALL + SELECT a+1, b||'.' FROM d WHERE a<10000 + ) + INSERT INTO q1 SELECT * FROM d; +} + + +# EVIDENCE-OF: R-07796-55423 Returns the size in bytes of the BLOB +# accessible via the successfully opened BLOB handle in its only +# argument. +# +proc check_blob_size {tn rowid bytes} { + uplevel [list do_test $tn [subst -nocommands { + sqlite3_blob_open db main q1 s $rowid 0 B + set res [sqlite3_blob_bytes [set B]] + sqlite3_blob_close [set B] + set res + }] $bytes] +} +check_blob_size 1.1 43 43 +check_blob_size 1.2 391 391 +check_blob_size 1.3 6349 6349 +check_blob_size 1.4 2621 2621 +check_blob_size 1.5 7771 7771 +check_blob_size 1.6 7949 7949 +check_blob_size 1.7 4374 4374 +check_blob_size 1.8 2578 2578 +check_blob_size 1.9 7004 7004 +check_blob_size 1.10 2180 2180 +check_blob_size 1.11 3796 3796 +check_blob_size 1.12 7101 7101 +check_blob_size 1.13 7449 7449 +check_blob_size 1.14 7224 7224 +check_blob_size 1.15 3038 3038 +check_blob_size 1.16 1083 1083 +check_blob_size 1.17 5157 5157 +check_blob_size 1.18 6686 6686 +check_blob_size 1.19 6592 6592 +check_blob_size 1.20 0 0 + + +# EVIDENCE-OF: R-53088-19343 The incremental blob I/O routines can only +# read or overwriting existing blob content; they cannot change the size +# of a blob. +# +# Also demonstrated in other e_blobXXX.test files. +# +do_test 2.1 { + sqlite3_blob_open db main q1 s 86 1 B + list [catch { sqlite3_blob_write $B 86 "1" 1 } msg] $msg +} {1 SQLITE_ERROR} +sqlite3_blob_close $B + +finish_test diff --git a/test/e_blobclose.test b/test/e_blobclose.test new file mode 100644 index 0000000..40291cf --- /dev/null +++ b/test/e_blobclose.test @@ -0,0 +1,175 @@ +# 2014 October 30 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix e_blobclose + +ifcapable !incrblob { + finish_test + return +} + +set dots [string repeat . 40] +do_execsql_test 1.0 { + CREATE TABLE x1(a INTEGER PRIMARY KEY, b DOTS); + INSERT INTO x1 VALUES(-1, $dots); + INSERT INTO x1 VALUES(-10, $dots); + INSERT INTO x1 VALUES(-100, $dots); + INSERT INTO x1 VALUES(-1000, $dots); + INSERT INTO x1 VALUES(-10000, $dots); +} + +# EVIDENCE-OF: R-03145-46390 This function closes an open BLOB handle. +# +# It's not clear how to test that a blob handle really is closed. +# Attempting to use a closed blob handle will likely crash the process. +# Assume here that if the SHARED lock on the db file is released, +# the blob handle has been closed. +# +do_execsql_test 1.1 { PRAGMA lock_status } {main unlocked temp closed} +sqlite3_blob_open db main x1 b -1 0 B +do_execsql_test 1.2 { PRAGMA lock_status } {main shared temp closed} +sqlite3_blob_close $B +do_execsql_test 1.3 { PRAGMA lock_status } {main unlocked temp closed} + + +# EVIDENCE-OF: R-34027-00617 If the blob handle being closed was opened +# for read-write access, and if the database is in auto-commit mode and +# there are no other open read-write blob handles or active write +# statements, the current transaction is committed. +# +# 2.1.*: Transaction is not committed if there are other open +# read-write blob handles. +# +# 2.2.*: Transaction is not committed if not in auto-commit mode. +# +# 2.3.*: Active write statements. +# +do_test 2.1.1 { + sqlite3_blob_open db main x1 b -100 1 B1 + sqlite3_blob_open db main x1 b -1000 1 B2 + sqlite3_blob_open db main x1 b -10000 1 B3 + sqlite3_blob_open db main x1 b -10000 0 B4 ;# B4 is read-only! + execsql { PRAGMA lock_status } +} {main reserved temp closed} +do_test 2.1.2 { + sqlite3_blob_close $B1 + execsql { PRAGMA lock_status } +} {main reserved temp closed} +do_test 2.1.3 { + sqlite3_blob_close $B2 + execsql { PRAGMA lock_status } +} {main reserved temp closed} +do_test 2.1.4 { + sqlite3_blob_close $B3 + execsql { PRAGMA lock_status } +} {main shared temp closed} +do_test 2.1.5 { + sqlite3_blob_close $B4 + execsql { PRAGMA lock_status } +} {main unlocked temp closed} + +do_test 2.2.1 { + sqlite3_blob_open db main x1 b -100 1 B1 + execsql { PRAGMA lock_status } +} {main reserved temp closed} +do_test 2.2.2 { + execsql { BEGIN } + sqlite3_blob_close $B1 + execsql { PRAGMA lock_status } +} {main reserved temp closed} +do_test 2.2.3 { + execsql { COMMIT } + execsql { PRAGMA lock_status } +} {main unlocked temp closed} + +proc val {} { + sqlite3_blob_close $::B + db eval { PRAGMA lock_status } +} +db func val val +do_test 2.3.1 { + sqlite3_blob_open db main x1 b -100 1 B + execsql { PRAGMA lock_status } +} {main reserved temp closed} +do_test 2.3.2 { + execsql { INSERT INTO x1 VALUES(15, val()) } + execsql { PRAGMA lock_status } +} {main unlocked temp closed} +do_test 2.3.3 { + execsql { SELECT * FROM x1 WHERE a = 15 } +} {15 {main reserved temp closed}} + +# A reader does not inhibit commit. +do_test 2.3.4 { + sqlite3_blob_open db main x1 b -100 1 B + execsql { PRAGMA lock_status } +} {main reserved temp closed} +do_test 2.3.5 { + execsql { SELECT a, val() FROM x1 LIMIT 1 } +} {-10000 {main shared temp closed}} + + +do_test 3.1 { + sqlite3_blob_open db main x1 b -10 1 B + execsql { + INSERT INTO x1 VALUES(1, 'abc'); + SELECT * FROM x1 WHERE a=1; + } +} {1 abc} +do_test 3.2 { + sqlite3_blob_write $B 0 "abcdefghij" 10 + execsql { SELECT * FROM x1 WHERE a=-10 } +} {-10 abcdefghij..............................} + +do_test 3.3 { + sqlite3 db2 test.db + execsql { BEGIN ; SELECT * FROM x1 } db2 + sqlite3_blob_close $B +} {SQLITE_BUSY} + +# EVIDENCE-OF: R-41959-38737 Otherwise, if this function is passed a +# valid open blob handle, the values returned by the sqlite3_errcode() +# and sqlite3_errmsg() functions are set before returning. +# +do_test 3.4 { + list [sqlite3_errcode db] [sqlite3_errmsg db] +} {SQLITE_BUSY {database is locked}} + +# EVIDENCE-OF: R-37801-37633 The BLOB handle is closed unconditionally. +# Even if this routine returns an error code, the handle is still +# closed. +# +# Test that the lock has been released. Assume this means the handle +# is closed, even though blob_close() returned SQLITE_BUSY. +# +do_execsql_test 3.4 { PRAGMA lock_status } {main unlocked temp closed} + +# EVIDENCE-OF: R-35111-05628 If an error occurs while committing the +# transaction, an error code is returned and the transaction rolled +# back. +# +# Row 1 is removed (it was inserted this transaction) and row -10 +# is restored to its original state. Transaction has been rolled back. +# +do_execsql_test 3.5 { + SELECT * FROM x1 WHERE a IN (1, -10); +} {-10 ........................................} + +# EVIDENCE-OF: R-25894-51060 Calling this routine with a null pointer +# (such as would be returned by a failed call to sqlite3_blob_open()) is +# a harmless no-op. +# +do_test 4.0 { sqlite3_blob_close 0 } {} + +finish_test diff --git a/test/e_blobopen.test b/test/e_blobopen.test new file mode 100644 index 0000000..41fd13c --- /dev/null +++ b/test/e_blobopen.test @@ -0,0 +1,553 @@ +# 2014 October 30 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix e_blobopen + +ifcapable !incrblob { + finish_test + return +} + +forcedelete test.db2 + +do_execsql_test 1.0 { + ATTACH 'test.db2' AS aux; + + CREATE TABLE main.t1(a INTEGER PRIMARY KEY, b TEXT, c BLOB); + CREATE TEMP TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c BLOB); + CREATE TABLE aux.t1(a INTEGER PRIMARY KEY, b TEXT, c BLOB); + + CREATE TABLE main.x1(a INTEGER PRIMARY KEY, b TEXT, c BLOB); + CREATE TEMP TABLE x2(a INTEGER PRIMARY KEY, b TEXT, c BLOB); + CREATE TABLE aux.x3(a INTEGER PRIMARY KEY, b TEXT, c BLOB); + + INSERT INTO main.t1 VALUES(1, 'main one', X'0101'); + INSERT INTO main.t1 VALUES(2, 'main two', X'0102'); + INSERT INTO main.t1 VALUES(3, 'main three', X'0103'); + INSERT INTO main.t1 VALUES(4, 'main four', X'0104'); + INSERT INTO main.t1 VALUES(5, 'main five', X'0105'); + + INSERT INTO main.x1 VALUES(1, 'x main one', X'000101'); + INSERT INTO main.x1 VALUES(2, 'x main two', X'000102'); + INSERT INTO main.x1 VALUES(3, 'x main three', X'000103'); + INSERT INTO main.x1 VALUES(4, 'x main four', X'000104'); + INSERT INTO main.x1 VALUES(5, 'x main five', X'000105'); + + INSERT INTO temp.t1 VALUES(1, 'temp one', X'0201'); + INSERT INTO temp.t1 VALUES(2, 'temp two', X'0202'); + INSERT INTO temp.t1 VALUES(3, 'temp three', X'0203'); + INSERT INTO temp.t1 VALUES(4, 'temp four', X'0204'); + INSERT INTO temp.t1 VALUES(5, 'temp five', X'0205'); + + INSERT INTO temp.x2 VALUES(1, 'x temp one', X'000201'); + INSERT INTO temp.x2 VALUES(2, 'x temp two', X'000202'); + INSERT INTO temp.x2 VALUES(3, 'x temp three', X'000203'); + INSERT INTO temp.x2 VALUES(4, 'x temp four', X'000204'); + INSERT INTO temp.x2 VALUES(5, 'x temp five', X'000205'); + + INSERT INTO aux.t1 VALUES(1, 'aux one', X'0301'); + INSERT INTO aux.t1 VALUES(2, 'aux two', X'0302'); + INSERT INTO aux.t1 VALUES(3, 'aux three', X'0303'); + INSERT INTO aux.t1 VALUES(4, 'aux four', X'0304'); + INSERT INTO aux.t1 VALUES(5, 'aux five', X'0305'); + + INSERT INTO aux.x3 VALUES(1, 'x aux one', X'000301'); + INSERT INTO aux.x3 VALUES(2, 'x aux two', X'000302'); + INSERT INTO aux.x3 VALUES(3, 'x aux three', X'000303'); + INSERT INTO aux.x3 VALUES(4, 'x aux four', X'000304'); + INSERT INTO aux.x3 VALUES(5, 'x aux five', X'000305'); +} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-37639-55938 This interfaces opens a handle to the BLOB +# located in row iRow, column zColumn, table zTable in database zDb; in +# other words, the same BLOB that would be selected by: SELECT zColumn +# FROM zDb.zTable WHERE rowid = iRow; +# +proc read_blob {zDb zTab zCol iRow} { + sqlite3_blob_open db $zDb $zTab $zCol $iRow 0 B + set nByte [sqlite3_blob_bytes $B] + set data [sqlite3_blob_read $B 0 $nByte] + sqlite3_blob_close $B + return $data +} + +do_test 1.1.1 { read_blob main t1 b 1 } "main one" +do_test 1.1.2 { read_blob main t1 c 1 } "\01\01" +do_test 1.1.3 { read_blob temp t1 b 1 } "temp one" +do_test 1.1.4 { read_blob temp t1 c 1 } "\02\01" +do_test 1.1.6 { read_blob aux t1 b 1 } "aux one" +do_test 1.1.7 { read_blob aux t1 c 1 } "\03\01" + +do_test 1.2.1 { read_blob main t1 b 4 } "main four" +do_test 1.2.2 { read_blob main t1 c 4 } "\01\04" +do_test 1.2.3 { read_blob temp t1 b 4 } "temp four" +do_test 1.2.4 { read_blob temp t1 c 4 } "\02\04" +do_test 1.2.6 { read_blob aux t1 b 4 } "aux four" +do_test 1.2.7 { read_blob aux t1 c 4 } "\03\04" + +do_test 1.3.1 { read_blob main x1 b 2 } "x main two" +do_test 1.3.2 { read_blob main x1 c 2 } "\00\01\02" +do_test 1.3.3 { read_blob temp x2 b 2 } "x temp two" +do_test 1.3.4 { read_blob temp x2 c 2 } "\00\02\02" +do_test 1.3.6 { read_blob aux x3 b 2 } "x aux two" +do_test 1.3.7 { read_blob aux x3 c 2 } "\00\03\02" + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-27234-05761 Parameter zDb is not the filename that +# contains the database, but rather the symbolic name of the database. +# For attached databases, this is the name that appears after the AS +# keyword in the ATTACH statement. For the main database file, the +# database name is "main". For TEMP tables, the database name is "temp". +# +# The test cases immediately above demonstrate that the database name +# for the main db, for TEMP tables and for those in attached databases +# is correct. The following tests check that filenames cannot be +# used as well. +# +do_test 2.1 { + list [catch { sqlite3_blob_open db "test.db" t1 b 1 0 B } msg] $msg +} {1 SQLITE_ERROR} +do_test 2.2 { + list [catch { sqlite3_blob_open db "test.db2" t1 b 1 0 B } msg] $msg +} {1 SQLITE_ERROR} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-50854-53979 If the flags parameter is non-zero, then +# the BLOB is opened for read and write access. +# +# EVIDENCE-OF: R-03922-41160 If the flags parameter is zero, the BLOB is +# opened for read-only access. +# +foreach {tn iRow flags} { + 1 1 0 + 2 2 1 + 3 3 -1 + 4 4 2147483647 + 5 5 -2147483648 +} { + do_test 3.$tn.1 { + sqlite3_blob_open db main x1 c $iRow $flags B + set n [sqlite3_blob_bytes $B] + sqlite3_blob_read $B 0 $n + } [binary format ccc 0 1 $iRow] + + if {$flags==0} { + # Blob was opened for read-only access - writing returns an error. + do_test 3.$tn.2 { + list [catch { sqlite3_blob_write $B 0 xxx 3 } msg] $msg + } {1 SQLITE_READONLY} + + do_execsql_test 3.$tn.3 { + SELECT c FROM x1 WHERE a=$iRow; + } [binary format ccc 0 1 $iRow] + } else { + # Blob was opened for read/write access - writing succeeds + do_test 3.$tn.4 { + list [catch { sqlite3_blob_write $B 0 xxx 3 } msg] $msg + } {0 {}} + + do_execsql_test 3.$tn.5 { + SELECT c FROM x1 WHERE a=$iRow; + } {xxx} + } + + sqlite3_blob_close $B +} + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 4.0 { + CREATE TABLE t1(x, y); + INSERT INTO t1 VALUES('abcd', 152); + INSERT INTO t1 VALUES(NULL, X'00010203'); + INSERT INTO t1 VALUES('', 154.2); + + CREATE TABLE t2(x PRIMARY KEY, y) WITHOUT ROWID; + INSERT INTO t2 VALUES(1, 'blob'); + + CREATE TABLE t3(a PRIMARY KEY, b, c, d, e, f, UNIQUE(e, f)); + INSERT INTO t3 VALUES('aaaa', 'bbbb', 'cccc', 'dddd', 'eeee', 'ffff'); + CREATE INDEX t3b ON t3(b); + + CREATE TABLE p1(x PRIMARY KEY); + INSERT INTO p1 VALUES('abc'); + + CREATE TABLE c1(a INTEGER PRIMARY KEY, b REFERENCES p1); + INSERT INTO c1 VALUES(45, 'abc'); +} + +proc test_blob_open {tn zDb zTab zCol iRow flags errcode errmsg} { + global B + set B "0x1234" + + if {$errcode=="SQLITE_OK"} { + set expected "0 {}" + } else { + set expected "1 $errcode" + } + + set ::res [list [ + catch { sqlite3_blob_open db $zDb $zTab $zCol $iRow $flags B } msg + ] $msg] + do_test 4.$tn.1 { set ::res } $expected + + # EVIDENCE-OF: R-08940-21305 Unless it returns SQLITE_MISUSE, this + # function sets the database connection error code and message + # accessible via sqlite3_errcode() and sqlite3_errmsg() and related + # functions. + # + # This proc (test_blob_open) is used below to test various error and + # non-error conditions. But never SQLITE_MISUSE conditions. So these + # test cases are considered as partly verifying the requirement above. + # See below for a test of the SQLITE_MISUSE case. + # + do_test 4.$tn.2 { + sqlite3_errcode db + } $errcode + do_test 4.$tn.3 { + sqlite3_errmsg db + } $errmsg + + # EVIDENCE-OF: R-31086-35521 On success, SQLITE_OK is returned and the + # new BLOB handle is stored in *ppBlob. Otherwise an error code is + # returned and, unless the error code is SQLITE_MISUSE, *ppBlob is set + # to NULL. + # + do_test 4.$tn.4 { + expr {$B == "0"} + } [expr {$errcode != "SQLITE_OK"}] + + # EVIDENCE-OF: R-63421-15521 This means that, provided the API is not + # misused, it is always safe to call sqlite3_blob_close() on *ppBlob + # after this function it returns. + do_test 4.$tn.5 { + sqlite3_blob_close $B + } {} +} + +# EVIDENCE-OF: R-31204-44780 Database zDb does not exist +test_blob_open 1 nosuchdb t1 x 1 0 SQLITE_ERROR "no such table: nosuchdb.t1" + +# EVIDENCE-OF: R-28676-08005 Table zTable does not exist within database zDb +test_blob_open 2 main tt1 x 1 0 SQLITE_ERROR "no such table: main.tt1" + +# EVIDENCE-OF: R-40134-30296 Table zTable is a WITHOUT ROWID table +test_blob_open 3 main t2 y 1 0 SQLITE_ERROR \ + "cannot open table without rowid: t2" + +# EVIDENCE-OF: R-56376-21261 Column zColumn does not exist +test_blob_open 4 main t1 z 2 0 SQLITE_ERROR "no such column: \"z\"" + +# EVIDENCE-OF: R-28258-23166 Row iRow is not present in the table +test_blob_open 5 main t1 y 6 0 SQLITE_ERROR "no such rowid: 6" + +# EVIDENCE-OF: R-11683-62380 The specified column of row iRow contains a +# value that is not a TEXT or BLOB value +test_blob_open 6 main t1 x 2 0 SQLITE_ERROR "cannot open value of type null" +test_blob_open 7 main t1 y 1 0 SQLITE_ERROR "cannot open value of type integer" +test_blob_open 8 main t1 y 3 0 SQLITE_ERROR "cannot open value of type real" + +# EVIDENCE-OF: R-34146-30782 Column zColumn is part of an index, PRIMARY +# KEY or UNIQUE constraint and the blob is being opened for read/write +# access +# +# Test cases 8.1.* show that such columns can be opened for read-access. +# Tests 8.2.* show that read-write access is different. Columns "c" and "c" +# are not part of an index, PK or UNIQUE constraint, so they work in both +# cases. +# +test_blob_open 8.1.1 main t3 a 1 0 SQLITE_OK "not an error" +test_blob_open 8.1.2 main t3 b 1 0 SQLITE_OK "not an error" +test_blob_open 8.1.3 main t3 c 1 0 SQLITE_OK "not an error" +test_blob_open 8.1.4 main t3 d 1 0 SQLITE_OK "not an error" +test_blob_open 8.1.5 main t3 e 1 0 SQLITE_OK "not an error" +test_blob_open 8.1.6 main t3 f 1 0 SQLITE_OK "not an error" + +set cannot "cannot open indexed column for writing" +test_blob_open 8.2.1 main t3 a 1 8 SQLITE_ERROR $cannot +test_blob_open 8.2.2 main t3 b 1 8 SQLITE_ERROR $cannot +test_blob_open 8.2.3 main t3 c 1 8 SQLITE_OK "not an error" +test_blob_open 8.2.4 main t3 d 1 8 SQLITE_OK "not an error" +test_blob_open 8.2.5 main t3 e 1 8 SQLITE_ERROR $cannot +test_blob_open 8.2.6 main t3 f 1 8 SQLITE_ERROR $cannot + +# EVIDENCE-OF: R-50117-55204 Foreign key constraints are enabled, column +# zColumn is part of a child key definition and the blob is being opened +# for read/write access +# +# 9.1: FK disabled, read-only access. +# 9.2: FK disabled, read-only access. +# 9.3: FK enabled, read/write access. +# 9.4: FK enabled, read/write access. +# +test_blob_open 9.1 main c1 b 45 0 SQLITE_OK "not an error" +test_blob_open 9.2 main c1 b 45 1 SQLITE_OK "not an error" +execsql { PRAGMA foreign_keys = ON } +test_blob_open 9.3 main c1 b 45 0 SQLITE_OK "not an error" +test_blob_open 9.4 main c1 b 45 1 SQLITE_ERROR \ + "cannot open foreign key column for writing" + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-08940-21305 Unless it returns SQLITE_MISUSE, this +# function sets the database connection error code and message +# accessible via sqlite3_errcode() and sqlite3_errmsg() and related +# functions. +# +# This requirement is partially verified by the many uses of test +# command [test_blob_open] above. All that is left is to verify the +# SQLITE_MISUSE case. +# +# SQLITE_MISUSE is only returned if SQLITE_ENABLE_API_ARMOR is defined +# during compilation. +# +ifcapable api_armor { + sqlite3_blob_open db main t1 x 1 0 B + + do_test 10.1.1 { + list [catch {sqlite3_blob_open $B main t1 x 1 0 B2} msg] $msg + } {1 SQLITE_MISUSE} + do_test 10.1.2 { + list [sqlite3_errcode db] [sqlite3_errmsg db] + } {SQLITE_OK {not an error}} + sqlite3_blob_close $B + + do_test 10.2.1 { + list [catch {sqlite3_blob_open db main {} x 1 0 B} msg] $msg + } {1 SQLITE_MISUSE} + do_test 10.2.2 { + list [sqlite3_errcode db] [sqlite3_errmsg db] + } {SQLITE_OK {not an error}} +} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-50542-62589 If the row that a BLOB handle points to is +# modified by an UPDATE, DELETE, or by ON CONFLICT side-effects then the +# BLOB handle is marked as "expired". This is true if any column of the +# row is changed, even a column other than the one the BLOB handle is +# open on. +# +# EVIDENCE-OF: R-48367-20048 Calls to sqlite3_blob_read() and +# sqlite3_blob_write() for an expired BLOB handle fail with a return +# code of SQLITE_ABORT. +# +# 11.2: read-only handle, DELETE. +# 11.3: read-only handle, UPDATE. +# 11.4: read-only handle, REPLACE. +# 11.5: read/write handle, DELETE. +# 11.6: read/write handle, UPDATE. +# 11.7: read/write handle, REPLACE. +# +do_execsql_test 11.1 { + CREATE TABLE b1(a INTEGER PRIMARY KEY, b, c UNIQUE); + INSERT INTO b1 VALUES(1, '1234567890', 1); + INSERT INTO b1 VALUES(2, '1234567890', 2); + INSERT INTO b1 VALUES(3, '1234567890', 3); + INSERT INTO b1 VALUES(4, '1234567890', 4); + INSERT INTO b1 VALUES(5, '1234567890', 5); + INSERT INTO b1 VALUES(6, '1234567890', 6); + + CREATE TABLE b2(a INTEGER PRIMARY KEY, b, c UNIQUE); + INSERT INTO b2 VALUES(1, '1234567890', 1); + INSERT INTO b2 VALUES(2, '1234567890', 2); + INSERT INTO b2 VALUES(3, '1234567890', 3); + INSERT INTO b2 VALUES(4, '1234567890', 4); + INSERT INTO b2 VALUES(5, '1234567890', 5); + INSERT INTO b2 VALUES(6, '1234567890', 6); +} + +do_test 11.2.1 { + sqlite3_blob_open db main b1 b 2 0 B + sqlite3_blob_read $B 0 10 +} {1234567890} +do_test 11.2.2 { + # Deleting a different row does not invalidate the blob handle. + execsql { DELETE FROM b1 WHERE a = 1 } + sqlite3_blob_read $B 0 10 +} {1234567890} +do_test 11.2.3 { + execsql { DELETE FROM b1 WHERE a = 2 } + list [catch { sqlite3_blob_read $B 0 10 } msg] $msg +} {1 SQLITE_ABORT} +do_test 11.2.4 { + sqlite3_blob_close $B +} {} + +do_test 11.3.1 { + sqlite3_blob_open db main b1 b 3 0 B + sqlite3_blob_read $B 0 10 +} {1234567890} +do_test 11.3.2 { + # Updating a different row + execsql { UPDATE b1 SET c = 42 WHERE a=4 } + sqlite3_blob_read $B 0 10 +} {1234567890} +do_test 11.3.3 { + execsql { UPDATE b1 SET c = 43 WHERE a=3 } + list [catch { sqlite3_blob_read $B 0 10 } msg] $msg +} {1 SQLITE_ABORT} +do_test 11.3.4 { + sqlite3_blob_close $B +} {} + +do_test 11.4.1 { + sqlite3_blob_open db main b1 b 6 0 B + sqlite3_blob_read $B 0 10 +} {1234567890} +do_test 11.4.2 { + # Replace a different row + execsql { INSERT OR REPLACE INTO b1 VALUES(10, 'abcdefghij', 5) } + sqlite3_blob_read $B 0 10 +} {1234567890} +do_test 11.4.3 { + execsql { INSERT OR REPLACE INTO b1 VALUES(11, 'abcdefghij', 6) } + list [catch { sqlite3_blob_read $B 0 10 } msg] $msg +} {1 SQLITE_ABORT} +do_test 11.4.4 { + sqlite3_blob_close $B +} {} + +do_test 11.4.1 { + sqlite3_blob_open db main b2 b 2 1 B + sqlite3_blob_write $B 0 "abcdefghij" +} {} +do_test 11.4.2 { + # Deleting a different row does not invalidate the blob handle. + execsql { DELETE FROM b2 WHERE a = 1 } + sqlite3_blob_write $B 0 "ABCDEFGHIJ" +} {} +do_test 11.4.3 { + execsql { DELETE FROM b2 WHERE a = 2 } + list [catch { sqlite3_blob_write $B 0 "0987654321" } msg] $msg +} {1 SQLITE_ABORT} +do_test 11.4.4 { + sqlite3_blob_close $B +} {} + +do_test 11.5.1 { + sqlite3_blob_open db main b2 b 3 1 B + sqlite3_blob_write $B 0 "abcdefghij" +} {} +do_test 11.5.2 { + # Updating a different row + execsql { UPDATE b2 SET c = 42 WHERE a=4 } + sqlite3_blob_write $B 0 "ABCDEFGHIJ" +} {} +do_test 11.5.3 { + execsql { UPDATE b2 SET c = 43 WHERE a=3 } + list [catch { sqlite3_blob_write $B 0 "0987654321" } msg] $msg +} {1 SQLITE_ABORT} +do_test 11.5.4 { + sqlite3_blob_close $B +} {} + +do_test 11.6.1 { + sqlite3_blob_open db main b2 b 6 1 B + sqlite3_blob_write $B 0 "abcdefghij" +} {} +do_test 11.6.2 { + # Replace a different row + execsql { INSERT OR REPLACE INTO b2 VALUES(10, 'abcdefghij', 5) } + sqlite3_blob_write $B 0 "ABCDEFGHIJ" +} {} +do_test 11.6.3 { + execsql { INSERT OR REPLACE INTO b2 VALUES(11, 'abcdefghij', 6) } + list [catch { sqlite3_blob_write $B 0 "0987654321" } msg] $msg +} {1 SQLITE_ABORT} +do_test 11.6.4 { + sqlite3_blob_close $B +} {} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-45408-40694 Changes written into a BLOB prior to the +# BLOB expiring are not rolled back by the expiration of the BLOB. Such +# changes will eventually commit if the transaction continues to +# completion. +# +do_execsql_test 12.1 { + CREATE TABLE b3(x INTEGER PRIMARY KEY, y TEXT, z INTEGER); + INSERT INTO b3 VALUES(22, '..........', NULL); +} +do_test 12.2 { + sqlite3_blob_open db main b3 y 22 1 B + sqlite3_blob_write $B 0 "xxxxx" 5 +} {} +do_execsql_test 12.3 { + UPDATE b3 SET z = 'not null'; +} +do_test 12.4 { + list [catch {sqlite3_blob_write $B 5 "xxxxx" 5} msg] $msg +} {1 SQLITE_ABORT} +do_execsql_test 12.5 { + SELECT * FROM b3; +} {22 xxxxx..... {not null}} +do_test 12.5 { + sqlite3_blob_close $B +} {} +do_execsql_test 12.6 { + SELECT * FROM b3; +} {22 xxxxx..... {not null}} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-58813-55036 The sqlite3_bind_zeroblob() and +# sqlite3_result_zeroblob() interfaces and the built-in zeroblob SQL +# function may be used to create a zero-filled blob to read or write +# using the incremental-blob interface. +# +do_execsql_test 13.1 { + CREATE TABLE c2(i INTEGER PRIMARY KEY, j); + INSERT INTO c2 VALUES(10, zeroblob(24)); +} + +do_test 13.2 { + set stmt [sqlite3_prepare_v2 db "INSERT INTO c2 VALUES(11, ?)" -1] + sqlite3_bind_zeroblob $stmt 1 45 + sqlite3_step $stmt + sqlite3_finalize $stmt +} {SQLITE_OK} + +# The blobs can be read: +# +do_test 13.3.1 { + sqlite3_blob_open db main c2 j 10 1 B + sqlite3_blob_open db main c2 j 11 1 B2 + list [sqlite3_blob_bytes $B] [sqlite3_blob_bytes $B2] +} {24 45} +do_test 13.3.2 { + sqlite3_blob_read $B 0 24 +} [string repeat [binary format c 0] 24] +do_test 13.3.3 { + sqlite3_blob_read $B2 0 45 +} [string repeat [binary format c 0] 45] + +# And also written: +# +do_test 13.4.1 { + sqlite3_blob_write $B 0 [string repeat [binary format c 1] 24] +} {} +do_test 13.4.2 { + sqlite3_blob_write $B2 0 [string repeat [binary format c 1] 45] +} {} +do_test 13.5 { + sqlite3_blob_close $B + sqlite3_blob_close $B2 + execsql { SELECT j FROM c2 } +} [list \ + [string repeat [binary format c 1] 24] \ + [string repeat [binary format c 1] 45] \ +] + + +finish_test diff --git a/test/e_blobwrite.test b/test/e_blobwrite.test new file mode 100644 index 0000000..8d8588e --- /dev/null +++ b/test/e_blobwrite.test @@ -0,0 +1,208 @@ +# 2014 October 30 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix e_blobwrite + +ifcapable !incrblob { + finish_test + return +} + +#-------------------------------------------------------------------------- +# EVIDENCE-OF: R-62898-22698 This function is used to write data into an +# open BLOB handle from a caller-supplied buffer. N bytes of data are +# copied from the buffer Z into the open BLOB, starting at offset +# iOffset. +# +set dots [string repeat . 40] +do_execsql_test 1.0 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, t TEXT); + INSERT INTO t1 VALUES(-1, $dots); + INSERT INTO t1 VALUES(-2, $dots); + INSERT INTO t1 VALUES(-3, $dots); + INSERT INTO t1 VALUES(-4, $dots); + INSERT INTO t1 VALUES(-5, $dots); + INSERT INTO t1 VALUES(-6, $dots); +} + +proc blob_write_test {tn id iOffset blob nData final} { + sqlite3_blob_open db main t1 t $id 1 B + + # EVIDENCE-OF: R-45864-01884 On success, sqlite3_blob_write() returns + # SQLITE_OK. Otherwise, an error code or an extended error code is + # returned. + # + # This block tests the SQLITE_OK case in the requirement above (the + # Tcl sqlite3_blob_write() wrapper uses an empty string in place of + # "SQLITE_OK"). The error cases are tested by the "blob_write_error_test" + # tests below. + # + set res [sqlite3_blob_write $B $iOffset $blob $nData] + uplevel [list do_test $tn.1 [list set {} $res] {}] + + sqlite3_blob_close $B + uplevel [list do_execsql_test $tn.3 "SELECT t FROM t1 WHERE a=$id" $final] +} + +set blob "0123456789012345678901234567890123456789" +blob_write_test 1.1 -1 0 $blob 10 { 0123456789.............................. } +blob_write_test 1.2 -2 8 $blob 10 { ........0123456789...................... } +blob_write_test 1.3 -3 8 $blob 1 { ........0............................... } +blob_write_test 1.4 -4 18 $blob 22 { ..................0123456789012345678901 } +blob_write_test 1.5 -5 18 $blob 0 { ........................................ } +blob_write_test 1.6 -6 0 $blob 40 { 0123456789012345678901234567890123456789 } + + +proc blob_write_error_test {tn B iOffset blob nData errcode errmsg} { + + # In cases where the underlying sqlite3_blob_write() function returns + # SQLITE_OK, the Tcl wrapper returns an empty string. If the underlying + # function returns an error, the Tcl wrapper throws an exception with + # the error code as the Tcl exception message. + # + if {$errcode=="SQLITE_OK"} { + set ret "" + set isError 0 + } else { + set ret $errcode + set isError 1 + } + + set cmd [list sqlite3_blob_write $B $iOffset $blob $nData] + uplevel [list do_test $tn.1 [subst -nocommands { + list [catch {$cmd} msg] [set msg] + }] [list $isError $ret]] + + # EVIDENCE-OF: R-34782-18311 Unless SQLITE_MISUSE is returned, this + # function sets the database connection error code and message + # accessible via sqlite3_errcode() and sqlite3_errmsg() and related + # functions. + # + if {$errcode == "SQLITE_MISUSE"} { error "test proc misuse!" } + uplevel [list do_test $tn.2 [list sqlite3_errcode db] $errcode] + uplevel [list do_test $tn.3 [list sqlite3_errmsg db] $errmsg] +} + +do_execsql_test 2.0 { + CREATE TABLE t2(a TEXT, b INTEGER PRIMARY KEY); + INSERT INTO t2 VALUES($dots, 43); + INSERT INTO t2 VALUES($dots, 44); + INSERT INTO t2 VALUES($dots, 45); +} + +# EVIDENCE-OF: R-63341-57517 If the BLOB handle passed as the first +# argument was not opened for writing (the flags parameter to +# sqlite3_blob_open() was zero), this function returns SQLITE_READONLY. +# +sqlite3_blob_open db main t2 a 43 0 B +blob_write_error_test 2.1 $B 0 $blob 10 \ + SQLITE_READONLY {attempt to write a readonly database} +sqlite3_blob_close $B + +# EVIDENCE-OF: R-29804-27366 If offset iOffset is less than N bytes from +# the end of the BLOB, SQLITE_ERROR is returned and no data is written. +# +sqlite3_blob_open db main t2 a 44 3 B +blob_write_error_test 2.2.1 $B 31 $blob 10 \ + SQLITE_ERROR {SQL logic error} + +# Make a successful write to the blob handle. This shows that the +# sqlite3_errcode() and sqlite3_errmsg() values are set even if the +# blob_write() call succeeds (see requirement in the [blob_write_error_test] +# proc). +blob_write_error_test 2.2.1 $B 30 $blob 10 SQLITE_OK {not an error} + +# EVIDENCE-OF: R-58570-38916 If N or iOffset are less than zero +# SQLITE_ERROR is returned and no data is written. +# +blob_write_error_test 2.2.2 $B 31 $blob -1 \ + SQLITE_ERROR {SQL logic error} +blob_write_error_test 2.2.3 $B 20 $blob 10 SQLITE_OK {not an error} +blob_write_error_test 2.2.4 $B -1 $blob 10 \ + SQLITE_ERROR {SQL logic error} +sqlite3_blob_close $B + +# EVIDENCE-OF: R-20958-54138 An attempt to write to an expired BLOB +# handle fails with an error code of SQLITE_ABORT. +# +do_test 2.3 { + sqlite3_blob_open db main t2 a 43 0 B + execsql { DELETE FROM t2 WHERE b=43 } +} {} +blob_write_error_test 2.3.1 $B 5 $blob 5 \ + SQLITE_ABORT {query aborted} +do_test 2.3.2 { + execsql { SELECT 1, 2, 3 } + sqlite3_errcode db +} {SQLITE_OK} +blob_write_error_test 2.3.3 $B 5 $blob 5 \ + SQLITE_ABORT {query aborted} +sqlite3_blob_close $B + +# EVIDENCE-OF: R-08382-59936 Writes to the BLOB that occurred before the +# BLOB handle expired are not rolled back by the expiration of the +# handle, though of course those changes might have been overwritten by +# the statement that expired the BLOB handle or by other independent +# statements. +# +# 3.1.*: not rolled back, +# 3.2.*: overwritten. +# +do_execsql_test 3.0 { + CREATE TABLE t3(i INTEGER PRIMARY KEY, j TEXT, k TEXT); + INSERT INTO t3 VALUES(1, $dots, $dots); + INSERT INTO t3 VALUES(2, $dots, $dots); + SELECT * FROM t3 WHERE i=1; +} { + 1 + ........................................ + ........................................ +} +sqlite3_blob_open db main t3 j 1 1 B +blob_write_error_test 3.1.1 $B 5 $blob 10 SQLITE_OK {not an error} +do_execsql_test 3.1.2 { + UPDATE t3 SET k = 'xyz' WHERE i=1; + SELECT * FROM t3 WHERE i=1; +} { + 1 .....0123456789......................... xyz +} +blob_write_error_test 3.1.3 $B 15 $blob 10 \ + SQLITE_ABORT {query aborted} +sqlite3_blob_close $B +do_execsql_test 3.1.4 { + SELECT * FROM t3 WHERE i=1; +} { + 1 .....0123456789......................... xyz +} + +sqlite3_blob_open db main t3 j 2 1 B +blob_write_error_test 3.2.1 $B 5 $blob 10 SQLITE_OK {not an error} +do_execsql_test 3.2.2 { + UPDATE t3 SET j = 'xyz' WHERE i=2; + SELECT * FROM t3 WHERE i=2; +} { + 2 xyz ........................................ +} +blob_write_error_test 3.2.3 $B 15 $blob 10 \ + SQLITE_ABORT {query aborted} +sqlite3_blob_close $B +do_execsql_test 3.2.4 { + SELECT * FROM t3 WHERE i=2; +} { + 2 xyz ........................................ +} + + + +finish_test diff --git a/test/e_changes.test b/test/e_changes.test new file mode 100644 index 0000000..2eb77d3 --- /dev/null +++ b/test/e_changes.test @@ -0,0 +1,443 @@ +# 2011 October 28 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix e_changes + +# Like [do_execsql_test], except it appends the value returned by +# [db changes] to the result of executing the SQL script. +# +proc do_changes_test {tn sql res} { + uplevel [list \ + do_test $tn "concat \[execsql {$sql}\] \[db changes\]" $res + ] +} + + +#-------------------------------------------------------------------------- +# EVIDENCE-OF: R-58361-29089 The changes() function returns the number +# of database rows that were changed or inserted or deleted by the most +# recently completed INSERT, DELETE, or UPDATE statement, exclusive of +# statements in lower-level triggers. +# +do_execsql_test 1.0 { + CREATE TABLE t1(a, b); + CREATE TABLE t2(x, y, PRIMARY KEY(x, y)) WITHOUT ROWID; + CREATE INDEX i1 ON t1(a); + CREATE INDEX i2 ON t2(y); +} +foreach {tn schema} { + 1 { + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(b); + } + 2 { + CREATE TABLE t1(a, b, PRIMARY KEY(a, b)) WITHOUT ROWID; + CREATE INDEX i1 ON t1(b); + } +} { + reset_db + execsql $schema + + # Insert 1 row. + do_changes_test 1.$tn.1 { INSERT INTO t1 VALUES(0, 0) } 1 + + # Insert 10 rows. + do_changes_test 1.$tn.2 { + WITH rows(i, j) AS ( + SELECT 1, 1 UNION ALL SELECT i+1, j+i FROM rows WHERE i<10 + ) + INSERT INTO t1 SELECT * FROM rows + } 10 + + # Modify 5 rows. + do_changes_test 1.$tn.3 { + UPDATE t1 SET b=b+1 WHERE a<5; + } 5 + + # Delete 4 rows + do_changes_test 1.$tn.4 { + DELETE FROM t1 WHERE a>6 + } 4 + + # Check the "on the database connecton specified" part of hte + # requirement - changes made by other connections do not show up in + # the return value of sqlite3_changes(). + do_test 1.$tn.5 { + sqlite3 db2 test.db + execsql { INSERT INTO t1 VALUES(-1, -1) } db2 + db2 changes + } 1 + do_test 1.$tn.6 { + db changes + } 4 + db2 close + + # Test that statements that modify no rows because they hit UNIQUE + # constraints set the sqlite3_changes() value to 0. Regardless of + # whether or not they are executed inside an explicit transaction. + # + # 1.$tn.8-9: outside of a transaction + # 1.$tn.10-12: inside a transaction + # + do_changes_test 1.$tn.7 { + CREATE UNIQUE INDEX i2 ON t1(a); + } 4 + do_catchsql_test 1.$tn.8 { + INSERT INTO t1 VALUES('a', 0), ('b', 0), ('c', 0), (0, 11); + } {1 {UNIQUE constraint failed: t1.a}} + do_test 1.$tn.9 { db changes } 0 + do_catchsql_test 1.$tn.10 { + BEGIN; + INSERT INTO t1 VALUES('a', 0), ('b', 0), ('c', 0), (0, 11); + } {1 {UNIQUE constraint failed: t1.a}} + do_test 1.$tn.11 { db changes } 0 + do_changes_test 1.$tn.12 COMMIT 0 + +} + + +#-------------------------------------------------------------------------- +# X-EVIDENCE-OF: R-44877-05564 Executing any other type of SQL statement +# does not modify the value returned by this function. +# +reset_db +do_changes_test 2.1 { CREATE TABLE t1(x) } 0 +do_changes_test 2.2 { + WITH d(y) AS (SELECT 1 UNION ALL SELECT y+1 FROM d WHERE y<47) + INSERT INTO t1 SELECT y FROM d; +} 47 + +# The statement above set changes() to 47. Check that none of the following +# modify this. +do_changes_test 2.3 { SELECT count(x) FROM t1 } {47 47} +do_changes_test 2.4 { DROP TABLE t1 } 47 +do_changes_test 2.5 { CREATE TABLE t1(x) } 47 +ifcapable altertable { + do_changes_test 2.6 { ALTER TABLE t1 ADD COLUMN b } 47 +} + + +#-------------------------------------------------------------------------- +# EVIDENCE-OF: R-53938-27527 Only changes made directly by the INSERT, +# UPDATE or DELETE statement are considered - auxiliary changes caused +# by triggers, foreign key actions or REPLACE constraint resolution are +# not counted. +# +# 3.1.*: triggers +# 3.2.*: foreign key actions +# 3.3.*: replace constraints +# +reset_db +do_execsql_test 3.1.0 { + CREATE TABLE log(x); + CREATE TABLE p1(one PRIMARY KEY, two); + + CREATE TRIGGER tr_ai AFTER INSERT ON p1 BEGIN + INSERT INTO log VALUES('insert'); + END; + CREATE TRIGGER tr_bd BEFORE DELETE ON p1 BEGIN + INSERT INTO log VALUES('delete'); + END; + CREATE TRIGGER tr_au AFTER UPDATE ON p1 BEGIN + INSERT INTO log VALUES('update'); + END; + +} + +do_changes_test 3.1.1 { + INSERT INTO p1 VALUES('a', 'A'), ('b', 'B'), ('c', 'C'); +} 3 +do_changes_test 3.1.2 { + UPDATE p1 SET two = two||two; +} 3 +do_changes_test 3.1.3 { + DELETE FROM p1 WHERE one IN ('a', 'c'); +} 2 +do_execsql_test 3.1.4 { + -- None of the inserts on table log were counted. + SELECT count(*) FROM log +} 8 + +do_execsql_test 3.2.0 { + DELETE FROM p1; + INSERT INTO p1 VALUES('a', 'A'), ('b', 'B'), ('c', 'C'); + + CREATE TABLE c1(a, b, FOREIGN KEY(a) REFERENCES p1 ON DELETE SET NULL); + CREATE TABLE c2(a, b, FOREIGN KEY(a) REFERENCES p1 ON DELETE SET DEFAULT); + CREATE TABLE c3(a, b, FOREIGN KEY(a) REFERENCES p1 ON DELETE CASCADE); + INSERT INTO c1 VALUES('a', 'aaa'); + INSERT INTO c2 VALUES('b', 'bbb'); + INSERT INTO c3 VALUES('c', 'ccc'); + + INSERT INTO p1 VALUES('d', 'D'), ('e', 'E'), ('f', 'F'); + CREATE TABLE c4(a, b, FOREIGN KEY(a) REFERENCES p1 ON UPDATE SET NULL); + CREATE TABLE c5(a, b, FOREIGN KEY(a) REFERENCES p1 ON UPDATE SET DEFAULT); + CREATE TABLE c6(a, b, FOREIGN KEY(a) REFERENCES p1 ON UPDATE CASCADE); + INSERT INTO c4 VALUES('d', 'aaa'); + INSERT INTO c5 VALUES('e', 'bbb'); + INSERT INTO c6 VALUES('f', 'ccc'); + + PRAGMA foreign_keys = ON; +} + +do_changes_test 3.2.1 { DELETE FROM p1 WHERE one = 'a' } 1 +do_changes_test 3.2.2 { DELETE FROM p1 WHERE one = 'b' } 1 +do_changes_test 3.2.3 { DELETE FROM p1 WHERE one = 'c' } 1 +do_execsql_test 3.2.4 { + SELECT * FROM c1; + SELECT * FROM c2; + SELECT * FROM c3; +} {{} aaa {} bbb} + +do_changes_test 3.2.5 { UPDATE p1 SET one = 'g' WHERE one = 'd' } 1 +do_changes_test 3.2.6 { UPDATE p1 SET one = 'h' WHERE one = 'e' } 1 +do_changes_test 3.2.7 { UPDATE p1 SET one = 'i' WHERE one = 'f' } 1 +do_execsql_test 3.2.8 { + SELECT * FROM c4; + SELECT * FROM c5; + SELECT * FROM c6; +} {{} aaa {} bbb i ccc} + +do_execsql_test 3.3.0 { + CREATE TABLE r1(a UNIQUE, b UNIQUE); + INSERT INTO r1 VALUES('i', 'i'); + INSERT INTO r1 VALUES('ii', 'ii'); + INSERT INTO r1 VALUES('iii', 'iii'); + INSERT INTO r1 VALUES('iv', 'iv'); + INSERT INTO r1 VALUES('v', 'v'); + INSERT INTO r1 VALUES('vi', 'vi'); + INSERT INTO r1 VALUES('vii', 'vii'); +} + +do_changes_test 3.3.1 { INSERT OR REPLACE INTO r1 VALUES('i', 1) } 1 +do_changes_test 3.3.2 { INSERT OR REPLACE INTO r1 VALUES('iv', 'v') } 1 +do_changes_test 3.3.3 { UPDATE OR REPLACE r1 SET b='v' WHERE a='iii' } 1 +do_changes_test 3.3.4 { UPDATE OR REPLACE r1 SET b='vi',a='vii' WHERE a='ii' } 1 +do_execsql_test 3.3.5 { + SELECT * FROM r1 ORDER BY a; +} {i 1 iii v vii vi} + + +#-------------------------------------------------------------------------- +# EVIDENCE-OF: R-09813-48563 The value returned by sqlite3_changes() +# immediately after an INSERT, UPDATE or DELETE statement run on a view +# is always zero. +# +reset_db +do_execsql_test 4.1 { + CREATE TABLE log(log); + CREATE TABLE t1(x, y); + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t1 VALUES(3, 4); + INSERT INTO t1 VALUES(5, 6); + + CREATE VIEW v1 AS SELECT * FROM t1; + CREATE TRIGGER v1_i INSTEAD OF INSERT ON v1 BEGIN + INSERT INTO log VALUES('insert'); + END; + CREATE TRIGGER v1_u INSTEAD OF UPDATE ON v1 BEGIN + INSERT INTO log VALUES('update'), ('update'); + END; + CREATE TRIGGER v1_d INSTEAD OF DELETE ON v1 BEGIN + INSERT INTO log VALUES('delete'), ('delete'), ('delete'); + END; +} + +do_changes_test 4.2.1 { INSERT INTO t1 SELECT * FROM t1 } 3 +do_changes_test 4.2.2 { INSERT INTO v1 VALUES(1, 2) } 0 + +do_changes_test 4.3.1 { INSERT INTO t1 SELECT * FROM t1 } 6 +do_changes_test 4.3.2 { UPDATE v1 SET y='xyz' WHERE x=1 } 0 + +do_changes_test 4.4.1 { INSERT INTO t1 SELECT * FROM t1 } 12 +do_changes_test 4.4.2 { DELETE FROM v1 WHERE x=5 } 0 + + +#-------------------------------------------------------------------------- +# EVIDENCE-OF: R-32918-61474 Before entering a trigger program the value +# returned by sqlite3_changes() function is saved. After the trigger +# program has finished, the original value is restored. +# +reset_db +db func my_changes my_changes +set ::changes [list] +proc my_changes {x} { + set res [db changes] + lappend ::changes $x $res + return $res +} + +do_execsql_test 5.1.0 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + CREATE TABLE t2(x); + INSERT INTO t1 VALUES(1, NULL); + INSERT INTO t1 VALUES(2, NULL); + INSERT INTO t1 VALUES(3, NULL); + CREATE TRIGGER AFTER UPDATE ON t1 BEGIN + INSERT INTO t2 VALUES('a'), ('b'), ('c'); + SELECT my_changes('trigger'); + END; +} + +do_execsql_test 5.1.1 { + INSERT INTO t2 VALUES('a'), ('b'); + UPDATE t1 SET b = my_changes('update'); + SELECT * FROM t1; +} {1 2 2 2 3 2} + +# Value is being restored to "2" when the trigger program exits. +do_test 5.1.2 { + set ::changes +} {update 2 trigger 3 update 2 trigger 3 update 2 trigger 3} + + +reset_db +do_execsql_test 5.2.0 { + CREATE TABLE t1(a, b); + CREATE TABLE log(x); + INSERT INTO t1 VALUES(1, 0); + INSERT INTO t1 VALUES(2, 0); + INSERT INTO t1 VALUES(3, 0); + CREATE TRIGGER t1_a_u AFTER UPDATE ON t1 BEGIN + INSERT INTO log VALUES(old.b || ' -> ' || new.b || ' c = ' || changes() ); + END; + CREATE TABLE t2(a); + INSERT INTO t2 VALUES(1), (2), (3); + UPDATE t1 SET b = changes(); +} +do_execsql_test 5.2.1 { + SELECT * FROM t1; +} {1 3 2 3 3 3} +do_execsql_test 5.2.2 { + SELECT * FROM log; +} {{0 -> 3 c = 3} {0 -> 3 c = 3} {0 -> 3 c = 3}} + + +#-------------------------------------------------------------------------- +# EVIDENCE-OF: R-17146-37073 Within a trigger program each INSERT, +# UPDATE and DELETE statement sets the value returned by +# sqlite3_changes() upon completion as normal. Of course, this value +# will not include any changes performed by sub-triggers, as the +# sqlite3_changes() value will be saved and restored after each +# sub-trigger has run. +reset_db +do_execsql_test 6.0 { + + CREATE TABLE t1(a, b); + CREATE TABLE t2(a, b); + CREATE TABLE t3(a, b); + CREATE TABLE log(x); + + CREATE TRIGGER t1_i BEFORE INSERT ON t1 BEGIN + INSERT INTO t2 VALUES(new.a, new.b), (new.a, new.b); + INSERT INTO log VALUES('t2->' || changes()); + END; + + CREATE TRIGGER t2_i AFTER INSERT ON t2 BEGIN + INSERT INTO t3 VALUES(new.a, new.b), (new.a, new.b), (new.a, new.b); + INSERT INTO log VALUES('t3->' || changes()); + END; + + CREATE TRIGGER t1_u AFTER UPDATE ON t1 BEGIN + UPDATE t2 SET b=new.b WHERE a=old.a; + INSERT INTO log VALUES('t2->' || changes()); + END; + + CREATE TRIGGER t2_u BEFORE UPDATE ON t2 BEGIN + UPDATE t3 SET b=new.b WHERE a=old.a; + INSERT INTO log VALUES('t3->' || changes()); + END; + + CREATE TRIGGER t1_d AFTER DELETE ON t1 BEGIN + DELETE FROM t2 WHERE a=old.a AND b=old.b; + INSERT INTO log VALUES('t2->' || changes()); + END; + + CREATE TRIGGER t2_d BEFORE DELETE ON t2 BEGIN + DELETE FROM t3 WHERE a=old.a AND b=old.b; + INSERT INTO log VALUES('t3->' || changes()); + END; +} + +do_changes_test 6.1 { + INSERT INTO t1 VALUES('+', 'o'); + SELECT * FROM log; +} {t3->3 t3->3 t2->2 1} + +do_changes_test 6.2 { + DELETE FROM log; + UPDATE t1 SET b='*'; + SELECT * FROM log; +} {t3->6 t3->6 t2->2 1} + +do_changes_test 6.3 { + DELETE FROM log; + DELETE FROM t1; + SELECT * FROM log; +} {t3->6 t3->0 t2->2 1} + + +#-------------------------------------------------------------------------- +# EVIDENCE-OF: R-43399-09409 This means that if the changes() SQL +# function (or similar) is used by the first INSERT, UPDATE or DELETE +# statement within a trigger, it returns the value as set when the +# calling statement began executing. +# +# EVIDENCE-OF: R-53215-27584 If it is used by the second or subsequent +# such statement within a trigger program, the value returned reflects +# the number of rows modified by the previous INSERT, UPDATE or DELETE +# statement within the same trigger. +# +reset_db +do_execsql_test 7.1 { + CREATE TABLE q1(t); + CREATE TABLE q2(u, v); + CREATE TABLE q3(w); + + CREATE TRIGGER q2_insert BEFORE INSERT ON q2 BEGIN + + /* changes() returns value from previous I/U/D in callers context */ + INSERT INTO q1 VALUES('1:' || changes()); + + /* changes() returns value of previous I/U/D in this context */ + INSERT INTO q3 VALUES(changes()), (2), (3); + INSERT INTO q1 VALUES('2:' || changes()); + INSERT INTO q3 VALUES(changes() + 3), (changes()+4); + SELECT 'this does not affect things!'; + INSERT INTO q1 VALUES('3:' || changes()); + UPDATE q3 SET w = w+10 WHERE w%2; + INSERT INTO q1 VALUES('4:' || changes()); + DELETE FROM q3; + INSERT INTO q1 VALUES('5:' || changes()); + END; +} + +do_execsql_test 7.2 { + INSERT INTO q2 VALUES('x', 'y'); + SELECT * FROM q1; +} { + 1:0 2:3 3:2 4:3 5:5 +} + +do_execsql_test 7.3 { + DELETE FROM q1; + INSERT INTO q2 VALUES('x', 'y'); + SELECT * FROM q1; +} { + 1:5 2:3 3:2 4:3 5:5 +} + + + +finish_test diff --git a/test/e_createtable.test b/test/e_createtable.test new file mode 100644 index 0000000..92ccc80 --- /dev/null +++ b/test/e_createtable.test @@ -0,0 +1,1970 @@ +# 2010 September 25 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file implements tests to verify that the "testable statements" in +# the lang_createtable.html document are correct. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +set ::testprefix e_createtable + +# Test organization: +# +# e_createtable-0.*: Test that the syntax diagrams are correct. +# +# e_createtable-1.*: Test statements related to table and database names, +# the TEMP and TEMPORARY keywords, and the IF NOT EXISTS clause. +# +# e_createtable-2.*: Test "CREATE TABLE AS" statements. +# + +proc do_createtable_tests {nm args} { + uplevel do_select_tests [list e_createtable-$nm] $args +} + + +#------------------------------------------------------------------------- +# This command returns a serialized tcl array mapping from the name of +# each attached database to a list of tables in that database. For example, +# if the database schema is created with: +# +# CREATE TABLE t1(x); +# CREATE TEMP TABLE t2(x); +# CREATE TEMP TABLE t3(x); +# +# Then this command returns "main t1 temp {t2 t3}". +# +proc table_list {} { + set res [list] + db eval { pragma database_list } a { + set dbname $a(name) + set master $a(name).sqlite_master + if {$dbname == "temp"} { set master sqlite_temp_master } + lappend res $dbname [ + db eval "SELECT DISTINCT tbl_name FROM $master ORDER BY tbl_name" + ] + } + set res +} + + +do_createtable_tests 0.1.1 -repair { + drop_all_tables +} { + 1 "CREATE TABLE t1(c1 one)" {} + 2 "CREATE TABLE t1(c1 one two)" {} + 3 "CREATE TABLE t1(c1 one two three)" {} + 4 "CREATE TABLE t1(c1 one two three four)" {} + 5 "CREATE TABLE t1(c1 one two three four(14))" {} + 6 "CREATE TABLE t1(c1 one two three four(14, 22))" {} + 7 "CREATE TABLE t1(c1 var(+14, -22.3))" {} + 8 "CREATE TABLE t1(c1 var(1.0e10))" {} +} +do_createtable_tests 0.1.2 -error { + near "%s": syntax error +} { + 1 "CREATE TABLE t1(c1 one(number))" {number} +} + + +# syntax diagram column-constraint +# +do_createtable_tests 0.2.1 -repair { + drop_all_tables + execsql { CREATE TABLE t2(x PRIMARY KEY) } +} { + 1.1 "CREATE TABLE t1(c1 text PRIMARY KEY)" {} + 1.2 "CREATE TABLE t1(c1 text PRIMARY KEY ASC)" {} + 1.3 "CREATE TABLE t1(c1 text PRIMARY KEY DESC)" {} + 1.4 "CREATE TABLE t1(c1 text CONSTRAINT cons PRIMARY KEY DESC)" {} + + 2.1 "CREATE TABLE t1(c1 text NOT NULL)" {} + 2.2 "CREATE TABLE t1(c1 text CONSTRAINT nm NOT NULL)" {} + 2.3 "CREATE TABLE t1(c1 text NULL)" {} + 2.4 "CREATE TABLE t1(c1 text CONSTRAINT nm NULL)" {} + + 3.1 "CREATE TABLE t1(c1 text UNIQUE)" {} + 3.2 "CREATE TABLE t1(c1 text CONSTRAINT un UNIQUE)" {} + + 4.1 "CREATE TABLE t1(c1 text CHECK(c1!=0))" {} + 4.2 "CREATE TABLE t1(c1 text CONSTRAINT chk CHECK(c1!=0))" {} + + 5.1 "CREATE TABLE t1(c1 text DEFAULT 1)" {} + 5.2 "CREATE TABLE t1(c1 text DEFAULT -1)" {} + 5.3 "CREATE TABLE t1(c1 text DEFAULT +1)" {} + 5.4 "CREATE TABLE t1(c1 text DEFAULT -45.8e22)" {} + 5.5 "CREATE TABLE t1(c1 text DEFAULT (1+1))" {} + 5.6 "CREATE TABLE t1(c1 text CONSTRAINT \"1 2\" DEFAULT (1+1))" {} + + 6.1 "CREATE TABLE t1(c1 text COLLATE nocase)" {} + 6.2 "CREATE TABLE t1(c1 text CONSTRAINT 'a x' COLLATE nocase)" {} + + 7.1 "CREATE TABLE t1(c1 REFERENCES t2)" {} + 7.2 "CREATE TABLE t1(c1 CONSTRAINT abc REFERENCES t2)" {} + + 8.1 { + CREATE TABLE t1(c1 + PRIMARY KEY NOT NULL UNIQUE CHECK(c1 IS 'ten') DEFAULT 123 REFERENCES t1 + ); + } {} + 8.2 { + CREATE TABLE t1(c1 + REFERENCES t1 DEFAULT 123 CHECK(c1 IS 'ten') UNIQUE NOT NULL PRIMARY KEY + ); + } {} +} + +# -- syntax diagram table-constraint +# +do_createtable_tests 0.3.1 -repair { + drop_all_tables + execsql { CREATE TABLE t2(x PRIMARY KEY) } +} { + 1.1 "CREATE TABLE t1(c1, c2, PRIMARY KEY(c1))" {} + 1.2 "CREATE TABLE t1(c1, c2, PRIMARY KEY(c1, c2))" {} + 1.3 "CREATE TABLE t1(c1, c2, PRIMARY KEY(c1, c2) ON CONFLICT IGNORE)" {} + + 2.1 "CREATE TABLE t1(c1, c2, UNIQUE(c1))" {} + 2.2 "CREATE TABLE t1(c1, c2, UNIQUE(c1, c2))" {} + 2.3 "CREATE TABLE t1(c1, c2, UNIQUE(c1, c2) ON CONFLICT IGNORE)" {} + + 3.1 "CREATE TABLE t1(c1, c2, CHECK(c1 IS NOT c2))" {} + + 4.1 "CREATE TABLE t1(c1, c2, FOREIGN KEY(c1) REFERENCES t2)" {} +} + +# -- syntax diagram column-def +# +do_createtable_tests 0.4.1 -repair { + drop_all_tables +} { + 1 {CREATE TABLE t1( + col1, + col2 TEXT, + col3 INTEGER UNIQUE, + col4 VARCHAR(10, 10) PRIMARY KEY, + "name with spaces" REFERENCES t1 + ); + } {} +} + +# -- syntax diagram create-table-stmt +# +do_createtable_tests 0.5.1 -repair { + drop_all_tables + execsql { CREATE TABLE t2(a, b, c) } +} { + 1 "CREATE TABLE t1(a, b, c)" {} + 2 "CREATE TEMP TABLE t1(a, b, c)" {} + 3 "CREATE TEMPORARY TABLE t1(a, b, c)" {} + 4 "CREATE TABLE IF NOT EXISTS t1(a, b, c)" {} + 5 "CREATE TEMP TABLE IF NOT EXISTS t1(a, b, c)" {} + 6 "CREATE TEMPORARY TABLE IF NOT EXISTS t1(a, b, c)" {} + + 7 "CREATE TABLE main.t1(a, b, c)" {} + 8 "CREATE TEMP TABLE temp.t1(a, b, c)" {} + 9 "CREATE TEMPORARY TABLE temp.t1(a, b, c)" {} + 10 "CREATE TABLE IF NOT EXISTS main.t1(a, b, c)" {} + 11 "CREATE TEMP TABLE IF NOT EXISTS temp.t1(a, b, c)" {} + 12 "CREATE TEMPORARY TABLE IF NOT EXISTS temp.t1(a, b, c)" {} + + 13 "CREATE TABLE t1 AS SELECT * FROM t2" {} + 14 "CREATE TEMP TABLE t1 AS SELECT c, b, a FROM t2" {} + 15 "CREATE TABLE t1 AS SELECT count(*), max(b), min(a) FROM t2" {} +} + +# +# 1: Explicit parent-key columns. +# 2: Implicit child-key columns. +# +# 1: MATCH FULL +# 2: MATCH PARTIAL +# 3: MATCH SIMPLE +# 4: MATCH STICK +# 5: +# +# 1: ON DELETE SET NULL +# 2: ON DELETE SET DEFAULT +# 3: ON DELETE CASCADE +# 4: ON DELETE RESTRICT +# 5: ON DELETE NO ACTION +# 6: +# +# 1: ON UPDATE SET NULL +# 2: ON UPDATE SET DEFAULT +# 3: ON UPDATE CASCADE +# 4: ON UPDATE RESTRICT +# 5: ON UPDATE NO ACTION +# 6: +# +# 1: NOT DEFERRABLE INITIALLY DEFERRED +# 2: NOT DEFERRABLE INITIALLY IMMEDIATE +# 3: NOT DEFERRABLE +# 4: DEFERRABLE INITIALLY DEFERRED +# 5: DEFERRABLE INITIALLY IMMEDIATE +# 6: DEFERRABLE +# 7: +# +do_createtable_tests 0.6.1 -repair { + drop_all_tables + execsql { CREATE TABLE t2(x PRIMARY KEY, y) } + execsql { CREATE TABLE t3(i, j, UNIQUE(i, j) ) } +} { + 11146 { CREATE TABLE t1(a + REFERENCES t2(x) MATCH FULL + ON DELETE SET NULL ON UPDATE RESTRICT DEFERRABLE + )} {} + 11412 { CREATE TABLE t1(a + REFERENCES t2(x) + ON DELETE RESTRICT ON UPDATE SET NULL MATCH FULL + NOT DEFERRABLE INITIALLY IMMEDIATE + )} {} + 12135 { CREATE TABLE t1(a + REFERENCES t2(x) MATCH PARTIAL + ON DELETE SET NULL ON UPDATE CASCADE DEFERRABLE INITIALLY IMMEDIATE + )} {} + 12427 { CREATE TABLE t1(a + REFERENCES t2(x) MATCH PARTIAL + ON DELETE RESTRICT ON UPDATE SET DEFAULT + )} {} + 12446 { CREATE TABLE t1(a + REFERENCES t2(x) MATCH PARTIAL + ON DELETE RESTRICT ON UPDATE RESTRICT DEFERRABLE + )} {} + 12522 { CREATE TABLE t1(a + REFERENCES t2(x) MATCH PARTIAL + ON DELETE NO ACTION ON UPDATE SET DEFAULT NOT DEFERRABLE INITIALLY IMMEDIATE + )} {} + 13133 { CREATE TABLE t1(a + REFERENCES t2(x) MATCH SIMPLE + ON DELETE SET NULL ON UPDATE CASCADE NOT DEFERRABLE + )} {} + 13216 { CREATE TABLE t1(a + REFERENCES t2(x) MATCH SIMPLE + ON DELETE SET DEFAULT ON UPDATE SET NULL DEFERRABLE + )} {} + 13263 { CREATE TABLE t1(a + REFERENCES t2(x) MATCH SIMPLE + ON DELETE SET DEFAULT NOT DEFERRABLE + )} {} + 13421 { CREATE TABLE t1(a + REFERENCES t2(x) MATCH SIMPLE + ON DELETE RESTRICT ON UPDATE SET DEFAULT NOT DEFERRABLE INITIALLY DEFERRED + )} {} + 13432 { CREATE TABLE t1(a + REFERENCES t2(x) MATCH SIMPLE + ON DELETE RESTRICT ON UPDATE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE + )} {} + 13523 { CREATE TABLE t1(a + REFERENCES t2(x) MATCH SIMPLE + ON DELETE NO ACTION ON UPDATE SET DEFAULT NOT DEFERRABLE + )} {} + 14336 { CREATE TABLE t1(a + REFERENCES t2(x) MATCH STICK + ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE + )} {} + 14611 { CREATE TABLE t1(a + REFERENCES t2(x) MATCH STICK + ON UPDATE SET NULL NOT DEFERRABLE INITIALLY DEFERRED + )} {} + 15155 { CREATE TABLE t1(a + REFERENCES t2(x) + ON DELETE SET NULL ON UPDATE NO ACTION DEFERRABLE INITIALLY IMMEDIATE + )} {} + 15453 { CREATE TABLE t1(a + REFERENCES t2(x) ON DELETE RESTRICT ON UPDATE NO ACTION NOT DEFERRABLE + )} {} + 15661 { CREATE TABLE t1(a + REFERENCES t2(x) NOT DEFERRABLE INITIALLY DEFERRED + )} {} + 21115 { CREATE TABLE t1(a + REFERENCES t2 MATCH FULL + ON DELETE SET NULL ON UPDATE SET NULL DEFERRABLE INITIALLY IMMEDIATE + )} {} + 21123 { CREATE TABLE t1(a + REFERENCES t2 MATCH FULL + ON DELETE SET NULL ON UPDATE SET DEFAULT NOT DEFERRABLE + )} {} + 21217 { CREATE TABLE t1(a + REFERENCES t2 MATCH FULL ON DELETE SET DEFAULT ON UPDATE SET NULL + )} {} + 21362 { CREATE TABLE t1(a + REFERENCES t2 MATCH FULL + ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE + )} {} + 22143 { CREATE TABLE t1(a + REFERENCES t2 MATCH PARTIAL + ON DELETE SET NULL ON UPDATE RESTRICT NOT DEFERRABLE + )} {} + 22156 { CREATE TABLE t1(a + REFERENCES t2 MATCH PARTIAL + ON DELETE SET NULL ON UPDATE NO ACTION DEFERRABLE + )} {} + 22327 { CREATE TABLE t1(a + REFERENCES t2 MATCH PARTIAL ON DELETE CASCADE ON UPDATE SET DEFAULT + )} {} + 22663 { CREATE TABLE t1(a + REFERENCES t2 MATCH PARTIAL NOT DEFERRABLE + )} {} + 23236 { CREATE TABLE t1(a + REFERENCES t2 MATCH SIMPLE + ON DELETE SET DEFAULT ON UPDATE CASCADE DEFERRABLE + )} {} + 24155 { CREATE TABLE t1(a + REFERENCES t2 MATCH STICK + ON DELETE SET NULL ON UPDATE NO ACTION DEFERRABLE INITIALLY IMMEDIATE + )} {} + 24522 { CREATE TABLE t1(a + REFERENCES t2 MATCH STICK + ON DELETE NO ACTION ON UPDATE SET DEFAULT NOT DEFERRABLE INITIALLY IMMEDIATE + )} {} + 24625 { CREATE TABLE t1(a + REFERENCES t2 MATCH STICK + ON UPDATE SET DEFAULT DEFERRABLE INITIALLY IMMEDIATE + )} {} + 25454 { CREATE TABLE t1(a + REFERENCES t2 + ON DELETE RESTRICT ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED + )} {} +} + +#------------------------------------------------------------------------- +# Test cases e_createtable-1.* - test statements related to table and +# database names, the TEMP and TEMPORARY keywords, and the IF NOT EXISTS +# clause. +# +drop_all_tables +forcedelete test.db2 test.db3 + +do_execsql_test e_createtable-1.0 { + ATTACH 'test.db2' AS auxa; + ATTACH 'test.db3' AS auxb; +} {} + +# EVIDENCE-OF: R-17899-04554 Table names that begin with "sqlite_" are +# reserved for internal use. It is an error to attempt to create a table +# with a name that starts with "sqlite_". +# +do_createtable_tests 1.1.1 -error { + object name reserved for internal use: %s +} { + 1 "CREATE TABLE sqlite_abc(a, b, c)" sqlite_abc + 2 "CREATE TABLE temp.sqlite_helloworld(x)" sqlite_helloworld + 3 {CREATE TABLE auxa."sqlite__"(x, y)} sqlite__ + 4 {CREATE TABLE auxb."sqlite_"(z)} sqlite_ + 5 {CREATE TABLE "SQLITE_TBL"(z)} SQLITE_TBL +} +do_createtable_tests 1.1.2 { + 1 "CREATE TABLE sqlit_abc(a, b, c)" {} + 2 "CREATE TABLE temp.sqlitehelloworld(x)" {} + 3 {CREATE TABLE auxa."sqlite"(x, y)} {} + 4 {CREATE TABLE auxb."sqlite-"(z)} {} + 5 {CREATE TABLE "SQLITE-TBL"(z)} {} +} + + +# EVIDENCE-OF: R-18448-33677 If a schema-name is specified, it must be +# either "main", "temp", or the name of an attached database. +# +# EVIDENCE-OF: R-39822-07822 In this case the new table is created in +# the named database. +# +# Test cases 1.2.* test the first of the two requirements above. The +# second is verified by cases 1.3.*. +# +do_createtable_tests 1.2.1 -error { + unknown database %s +} { + 1 "CREATE TABLE george.t1(a, b)" george + 2 "CREATE TABLE _.t1(a, b)" _ +} +do_createtable_tests 1.2.2 { + 1 "CREATE TABLE main.abc(a, b, c)" {} + 2 "CREATE TABLE temp.helloworld(x)" {} + 3 {CREATE TABLE auxa."t 1"(x, y)} {} + 4 {CREATE TABLE auxb.xyz(z)} {} +} +drop_all_tables +if {[permutation]!="maindbname"} { + do_createtable_tests 1.3 -tclquery { + unset -nocomplain X + array set X [table_list] + list $X(main) $X(temp) $X(auxa) $X(auxb) + } { + 1 "CREATE TABLE main.abc(a, b, c)" {abc {} {} {}} + 2 "CREATE TABLE main.t1(a, b, c)" {{abc t1} {} {} {}} + 3 "CREATE TABLE temp.tmp(a, b, c)" {{abc t1} tmp {} {}} + 4 "CREATE TABLE auxb.tbl(x, y)" {{abc t1} tmp {} tbl} + 5 "CREATE TABLE auxb.t1(k, v)" {{abc t1} tmp {} {t1 tbl}} + 6 "CREATE TABLE auxa.next(c, d)" {{abc t1} tmp next {t1 tbl}} + } +} + +# EVIDENCE-OF: R-18895-27365 If the "TEMP" or "TEMPORARY" keyword occurs +# between the "CREATE" and "TABLE" then the new table is created in the +# temp database. +# +drop_all_tables +if {[permutation]!="maindbname"} { + do_createtable_tests 1.4 -tclquery { + unset -nocomplain X + array set X [table_list] + list $X(main) $X(temp) $X(auxa) $X(auxb) + } { + 1 "CREATE TEMP TABLE t1(a, b)" {{} t1 {} {}} + 2 "CREATE TEMPORARY TABLE t2(a, b)" {{} {t1 t2} {} {}} + } +} + +# EVIDENCE-OF: R-23976-43329 It is an error to specify both a +# schema-name and the TEMP or TEMPORARY keyword, unless the schema-name +# is "temp". +# +drop_all_tables +do_createtable_tests 1.5.1 -error { + temporary table name must be unqualified +} { + 1 "CREATE TEMP TABLE main.t1(a, b)" {} + 2 "CREATE TEMPORARY TABLE auxa.t2(a, b)" {} + 3 "CREATE TEMP TABLE auxb.t3(a, b)" {} + 4 "CREATE TEMPORARY TABLE main.xxx(x)" {} +} +drop_all_tables +if {[permutation]!="maindbname"} { + do_createtable_tests 1.5.2 -tclquery { + unset -nocomplain X + array set X [table_list] + list $X(main) $X(temp) $X(auxa) $X(auxb) + } { + 1 "CREATE TEMP TABLE temp.t1(a, b)" {{} t1 {} {}} + 2 "CREATE TEMPORARY TABLE temp.t2(a, b)" {{} {t1 t2} {} {}} + 3 "CREATE TEMP TABLE TEMP.t3(a, b)" {{} {t1 t2 t3} {} {}} + 4 "CREATE TEMPORARY TABLE TEMP.xxx(x)" {{} {t1 t2 t3 xxx} {} {}} + } +} + +# EVIDENCE-OF: R-31997-24564 If no schema name is specified and the TEMP +# keyword is not present then the table is created in the main database. +# +drop_all_tables +if {[permutation]!="maindbname"} { + do_createtable_tests 1.6 -tclquery { + unset -nocomplain X + array set X [table_list] + list $X(main) $X(temp) $X(auxa) $X(auxb) + } { + 1 "CREATE TABLE t1(a, b)" {t1 {} {} {}} + 2 "CREATE TABLE t2(a, b)" {{t1 t2} {} {} {}} + 3 "CREATE TABLE t3(a, b)" {{t1 t2 t3} {} {} {}} + 4 "CREATE TABLE xxx(x)" {{t1 t2 t3 xxx} {} {} {}} + } +} + +drop_all_tables +do_execsql_test e_createtable-1.7.0 { + CREATE TABLE t1(x, y); + CREATE INDEX i1 ON t1(x); + CREATE VIEW v1 AS SELECT * FROM t1; + + CREATE TABLE auxa.tbl1(x, y); + CREATE INDEX auxa.idx1 ON tbl1(x); + CREATE VIEW auxa.view1 AS SELECT * FROM tbl1; +} {} + +# EVIDENCE-OF: R-01232-54838 It is usually an error to attempt to create +# a new table in a database that already contains a table, index or view +# of the same name. +# +# Test cases 1.7.1.* verify that creating a table in a database with a +# table/index/view of the same name does fail. 1.7.2.* tests that creating +# a table with the same name as a table/index/view in a different database +# is Ok. +# +do_createtable_tests 1.7.1 -error { %s } { + 1 "CREATE TABLE t1(a, b)" {{table t1 already exists}} + 2 "CREATE TABLE i1(a, b)" {{there is already an index named i1}} + 3 "CREATE TABLE v1(a, b)" {{view v1 already exists}} + 4 "CREATE TABLE auxa.tbl1(a, b)" {{table tbl1 already exists}} + 5 "CREATE TABLE auxa.idx1(a, b)" {{there is already an index named idx1}} + 6 "CREATE TABLE auxa.view1(a, b)" {{view view1 already exists}} +} +do_createtable_tests 1.7.2 { + 1 "CREATE TABLE auxa.t1(a, b)" {} + 2 "CREATE TABLE auxa.i1(a, b)" {} + 3 "CREATE TABLE auxa.v1(a, b)" {} + 4 "CREATE TABLE tbl1(a, b)" {} + 5 "CREATE TABLE idx1(a, b)" {} + 6 "CREATE TABLE view1(a, b)" {} +} + +# EVIDENCE-OF: R-33917-24086 However, if the "IF NOT EXISTS" clause is +# specified as part of the CREATE TABLE statement and a table or view of +# the same name already exists, the CREATE TABLE command simply has no +# effect (and no error message is returned). +# +drop_all_tables +do_execsql_test e_createtable-1.8.0 { + CREATE TABLE t1(x, y); + CREATE INDEX i1 ON t1(x); + CREATE VIEW v1 AS SELECT * FROM t1; + CREATE TABLE auxa.tbl1(x, y); + CREATE INDEX auxa.idx1 ON tbl1(x); + CREATE VIEW auxa.view1 AS SELECT * FROM tbl1; +} {} +do_createtable_tests 1.8 { + 1 "CREATE TABLE IF NOT EXISTS t1(a, b)" {} + 2 "CREATE TABLE IF NOT EXISTS auxa.tbl1(a, b)" {} + 3 "CREATE TABLE IF NOT EXISTS v1(a, b)" {} + 4 "CREATE TABLE IF NOT EXISTS auxa.view1(a, b)" {} +} + +# EVIDENCE-OF: R-16465-40078 An error is still returned if the table +# cannot be created because of an existing index, even if the "IF NOT +# EXISTS" clause is specified. +# +do_createtable_tests 1.9 -error { %s } { + 1 "CREATE TABLE IF NOT EXISTS i1(a, b)" + {{there is already an index named i1}} + 2 "CREATE TABLE IF NOT EXISTS auxa.idx1(a, b)" + {{there is already an index named idx1}} +} + +# EVIDENCE-OF: R-05513-33819 It is not an error to create a table that +# has the same name as an existing trigger. +# +drop_all_tables +do_execsql_test e_createtable-1.10.0 { + CREATE TABLE t1(x, y); + CREATE TABLE auxb.t2(x, y); + + CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN + SELECT 1; + END; + CREATE TRIGGER auxb.tr2 AFTER INSERT ON t2 BEGIN + SELECT 1; + END; +} {} +do_createtable_tests 1.10 { + 1 "CREATE TABLE tr1(a, b)" {} + 2 "CREATE TABLE tr2(a, b)" {} + 3 "CREATE TABLE auxb.tr1(a, b)" {} + 4 "CREATE TABLE auxb.tr2(a, b)" {} +} + +# EVIDENCE-OF: R-22283-14179 Tables are removed using the DROP TABLE +# statement. +# +drop_all_tables +do_execsql_test e_createtable-1.11.0 { + CREATE TABLE t1(a, b); + CREATE TABLE t2(a, b); + CREATE TABLE auxa.t3(a, b); + CREATE TABLE auxa.t4(a, b); +} {} + +do_execsql_test e_createtable-1.11.1.1 { + SELECT * FROM t1; + SELECT * FROM t2; + SELECT * FROM t3; + SELECT * FROM t4; +} {} +do_execsql_test e_createtable-1.11.1.2 { DROP TABLE t1 } {} +do_catchsql_test e_createtable-1.11.1.3 { + SELECT * FROM t1 +} {1 {no such table: t1}} +do_execsql_test e_createtable-1.11.1.4 { DROP TABLE t3 } {} +do_catchsql_test e_createtable-1.11.1.5 { + SELECT * FROM t3 +} {1 {no such table: t3}} + +do_execsql_test e_createtable-1.11.2.1 { + SELECT name FROM sqlite_master; + SELECT name FROM auxa.sqlite_master; +} {t2 t4} +do_execsql_test e_createtable-1.11.2.2 { DROP TABLE t2 } {} +do_execsql_test e_createtable-1.11.2.3 { DROP TABLE t4 } {} +do_execsql_test e_createtable-1.11.2.4 { + SELECT name FROM sqlite_master; + SELECT name FROM auxa.sqlite_master; +} {} + +#------------------------------------------------------------------------- +# Test cases e_createtable-2.* - test statements related to the CREATE +# TABLE AS ... SELECT statement. +# + +# Three Tcl commands: +# +# select_column_names SQL +# The argument must be a SELECT statement. Return a list of the names +# of the columns of the result-set that would be returned by executing +# the SELECT. +# +# table_column_names TBL +# The argument must be a table name. Return a list of column names, from +# left to right, for the table. +# +# table_column_decltypes TBL +# The argument must be a table name. Return a list of column declared +# types, from left to right, for the table. +# +proc sci {select cmd} { + set res [list] + set STMT [sqlite3_prepare_v2 db $select -1 dummy] + for {set i 0} {$i < [sqlite3_column_count $STMT]} {incr i} { + lappend res [$cmd $STMT $i] + } + sqlite3_finalize $STMT + set res +} +proc tci {tbl cmd} { sci "SELECT * FROM $tbl" $cmd } +proc select_column_names {sql} { sci $sql sqlite3_column_name } +proc table_column_names {tbl} { tci $tbl sqlite3_column_name } +proc table_column_decltypes {tbl} { tci $tbl sqlite3_column_decltype } + +# Create a database schema. This schema is used by tests 2.1.* through 2.3.*. +# +drop_all_tables +do_execsql_test e_createtable-2.0 { + CREATE TABLE t1(a, b, c); + CREATE TABLE t2(d, e, f); + CREATE TABLE t3(g BIGINT, h VARCHAR(10)); + CREATE TABLE t4(i BLOB, j ANYOLDATA); + CREATE TABLE t5(k FLOAT, l INTEGER); + CREATE TABLE t6(m DEFAULT 10, n DEFAULT 5, PRIMARY KEY(m, n)); + CREATE TABLE t7(x INTEGER PRIMARY KEY); + CREATE TABLE t8(o COLLATE nocase DEFAULT 'abc'); + CREATE TABLE t9(p NOT NULL, q DOUBLE CHECK (q!=0), r STRING UNIQUE); +} {} + +# EVIDENCE-OF: R-64828-59568 The table has the same number of columns as +# the rows returned by the SELECT statement. The name of each column is +# the same as the name of the corresponding column in the result set of +# the SELECT statement. +# +do_createtable_tests 2.1 -tclquery { + table_column_names x1 +} -repair { + catchsql { DROP TABLE x1 } +} { + 1 "CREATE TABLE x1 AS SELECT * FROM t1" {a b c} + 2 "CREATE TABLE x1 AS SELECT c, b, a FROM t1" {c b a} + 3 "CREATE TABLE x1 AS SELECT * FROM t1, t2" {a b c d e f} + 4 "CREATE TABLE x1 AS SELECT count(*) FROM t1" {count(*)} + 5 "CREATE TABLE x1 AS SELECT count(a) AS a, max(b) FROM t1" {a max(b)} +} + +# EVIDENCE-OF: R-55407-45319 The declared type of each column is +# determined by the expression affinity of the corresponding expression +# in the result set of the SELECT statement, as follows: Expression +# Affinity Column Declared Type TEXT "TEXT" NUMERIC "NUM" INTEGER "INT" +# REAL "REAL" BLOB (a.k.a "NONE") "" (empty string) +# +do_createtable_tests 2.2 -tclquery { + table_column_decltypes x1 +} -repair { + catchsql { DROP TABLE x1 } +} { + 1 "CREATE TABLE x1 AS SELECT a FROM t1" {""} + 2 "CREATE TABLE x1 AS SELECT * FROM t3" {INT TEXT} + 3 "CREATE TABLE x1 AS SELECT * FROM t4" {"" NUM} + 4 "CREATE TABLE x1 AS SELECT * FROM t5" {REAL INT} +} + +# EVIDENCE-OF: R-16667-09772 A table created using CREATE TABLE AS has +# no PRIMARY KEY and no constraints of any kind. The default value of +# each column is NULL. The default collation sequence for each column of +# the new table is BINARY. +# +# The following tests create tables based on SELECT statements that read +# from tables that have primary keys, constraints and explicit default +# collation sequences. None of this is transfered to the definition of +# the new table as stored in the sqlite_master table. +# +# Tests 2.3.2.* show that the default value of each column is NULL. +# +do_createtable_tests 2.3.1 -query { + SELECT sql FROM sqlite_master ORDER BY rowid DESC LIMIT 1 +} { + 1 "CREATE TABLE x1 AS SELECT * FROM t6" {{CREATE TABLE x1(m,n)}} + 2 "CREATE TABLE x2 AS SELECT * FROM t7" {{CREATE TABLE x2(x INT)}} + 3 "CREATE TABLE x3 AS SELECT * FROM t8" {{CREATE TABLE x3(o)}} + 4 "CREATE TABLE x4 AS SELECT * FROM t9" {{CREATE TABLE x4(p,q REAL,r NUM)}} +} +do_execsql_test e_createtable-2.3.2.1 { + INSERT INTO x1 DEFAULT VALUES; + INSERT INTO x2 DEFAULT VALUES; + INSERT INTO x3 DEFAULT VALUES; + INSERT INTO x4 DEFAULT VALUES; +} {} +db nullvalue null +do_execsql_test e_createtable-2.3.2.2 { SELECT * FROM x1 } {null null} +do_execsql_test e_createtable-2.3.2.3 { SELECT * FROM x2 } {null} +do_execsql_test e_createtable-2.3.2.4 { SELECT * FROM x3 } {null} +do_execsql_test e_createtable-2.3.2.5 { SELECT * FROM x4 } {null null null} +db nullvalue {} + +drop_all_tables +do_execsql_test e_createtable-2.4.0 { + CREATE TABLE t1(x, y); + INSERT INTO t1 VALUES('i', 'one'); + INSERT INTO t1 VALUES('ii', 'two'); + INSERT INTO t1 VALUES('iii', 'three'); +} {} + +# EVIDENCE-OF: R-24153-28352 Tables created using CREATE TABLE AS are +# initially populated with the rows of data returned by the SELECT +# statement. +# +# EVIDENCE-OF: R-08224-30249 Rows are assigned contiguously ascending +# rowid values, starting with 1, in the order that they are returned by +# the SELECT statement. +# +# Each test case below is specified as the name of a table to create +# using "CREATE TABLE ... AS SELECT ..." and a SELECT statement to use in +# creating it. The table is created. +# +# Test cases 2.4.*.1 check that after it has been created, the data in the +# table is the same as the data returned by the SELECT statement executed as +# a standalone command, verifying the first testable statement above. +# +# Test cases 2.4.*.2 check that the rowids were allocated contiguously +# as required by the second testable statement above. That the rowids +# from the contiguous block were allocated to rows in the order rows are +# returned by the SELECT statement is verified by 2.4.*.1. +# +# EVIDENCE-OF: R-32365-09043 A "CREATE TABLE ... AS SELECT" statement +# creates and populates a database table based on the results of a +# SELECT statement. +# +# The above is also considered to be tested by the following. It is +# clear that tables are being created and populated by the command in +# question. +# +foreach {tn tbl select} { + 1 x1 "SELECT * FROM t1" + 2 x2 "SELECT * FROM t1 ORDER BY x DESC" + 3 x3 "SELECT * FROM t1 ORDER BY x ASC" +} { + # Create the table using a "CREATE TABLE ... AS SELECT ..." command. + execsql [subst {CREATE TABLE $tbl AS $select}] + + # Check that the rows inserted into the table, sorted in ascending rowid + # order, match those returned by executing the SELECT statement as a + # standalone command. + do_execsql_test e_createtable-2.4.$tn.1 [subst { + SELECT * FROM $tbl ORDER BY rowid; + }] [execsql $select] + + # Check that the rowids in the new table are a contiguous block starting + # with rowid 1. Note that this will fail if SELECT statement $select + # returns 0 rows (as max(rowid) will be NULL). + do_execsql_test e_createtable-2.4.$tn.2 [subst { + SELECT min(rowid), count(rowid)==max(rowid) FROM $tbl + }] {1 1} +} + +#-------------------------------------------------------------------------- +# Test cases for column defintions in CREATE TABLE statements that do not +# use a SELECT statement. Not including data constraints. In other words, +# tests for the specification of: +# +# * declared types, +# * default values, and +# * default collation sequences. +# + +# EVIDENCE-OF: R-27219-49057 Unlike most SQL databases, SQLite does not +# restrict the type of data that may be inserted into a column based on +# the columns declared type. +# +# Test this by creating a few tables with varied declared types, then +# inserting various different types of values into them. +# +drop_all_tables +do_execsql_test e_createtable-3.1.0 { + CREATE TABLE t1(x VARCHAR(10), y INTEGER, z DOUBLE); + CREATE TABLE t2(a DATETIME, b STRING, c REAL); + CREATE TABLE t3(o, t); +} {} + +# value type -> declared column type +# ---------------------------------- +# integer -> VARCHAR(10) +# string -> INTEGER +# blob -> DOUBLE +# +do_execsql_test e_createtable-3.1.1 { + INSERT INTO t1 VALUES(14, 'quite a lengthy string', X'555655'); + SELECT * FROM t1; +} {14 {quite a lengthy string} UVU} + +# string -> DATETIME +# integer -> STRING +# time -> REAL +# +do_execsql_test e_createtable-3.1.2 { + INSERT INTO t2 VALUES('not a datetime', 13, '12:41:59'); + SELECT * FROM t2; +} {{not a datetime} 13 12:41:59} + +# EVIDENCE-OF: R-10565-09557 The declared type of a column is used to +# determine the affinity of the column only. +# +# Affinities are tested in more detail elsewhere (see document +# datatype3.html). Here, just test that affinity transformations +# consistent with the expected affinity of each column (based on +# the declared type) appear to take place. +# +# Affinities of t1 (test cases 3.2.1.*): TEXT, INTEGER, REAL +# Affinities of t2 (test cases 3.2.2.*): NUMERIC, NUMERIC, REAL +# Affinities of t3 (test cases 3.2.3.*): NONE, NONE +# +do_execsql_test e_createtable-3.2.0 { DELETE FROM t1; DELETE FROM t2; } {} + +do_createtable_tests 3.2.1 -query { + SELECT quote(x), quote(y), quote(z) FROM t1 ORDER BY rowid DESC LIMIT 1; +} { + 1 "INSERT INTO t1 VALUES(15, '22.0', '14')" {'15' 22 14.0} + 2 "INSERT INTO t1 VALUES(22.0, 22.0, 22.0)" {'22.0' 22 22.0} +} +do_createtable_tests 3.2.2 -query { + SELECT quote(a), quote(b), quote(c) FROM t2 ORDER BY rowid DESC LIMIT 1; +} { + 1 "INSERT INTO t2 VALUES(15, '22.0', '14')" {15 22 14.0} + 2 "INSERT INTO t2 VALUES(22.0, 22.0, 22.0)" {22 22 22.0} +} +do_createtable_tests 3.2.3 -query { + SELECT quote(o), quote(t) FROM t3 ORDER BY rowid DESC LIMIT 1; +} { + 1 "INSERT INTO t3 VALUES('15', '22.0')" {'15' '22.0'} + 2 "INSERT INTO t3 VALUES(15, 22.0)" {15 22.0} +} + +# EVIDENCE-OF: R-42316-09582 If there is no explicit DEFAULT clause +# attached to a column definition, then the default value of the column +# is NULL. +# +# None of the columns in table t1 have an explicit DEFAULT clause. +# So testing that the default value of all columns in table t1 is +# NULL serves to verify the above. +# +do_createtable_tests 3.2.3 -query { + SELECT quote(x), quote(y), quote(z) FROM t1 +} -repair { + execsql { DELETE FROM t1 } +} { + 1 "INSERT INTO t1(x, y) VALUES('abc', 'xyz')" {'abc' 'xyz' NULL} + 2 "INSERT INTO t1(x, z) VALUES('abc', 'xyz')" {'abc' NULL 'xyz'} + 3 "INSERT INTO t1 DEFAULT VALUES" {NULL NULL NULL} +} + +# EVIDENCE-OF: R-07343-35026 An explicit DEFAULT clause may specify that +# the default value is NULL, a string constant, a blob constant, a +# signed-number, or any constant expression enclosed in parentheses. A +# default value may also be one of the special case-independent keywords +# CURRENT_TIME, CURRENT_DATE or CURRENT_TIMESTAMP. +# +do_execsql_test e_createtable-3.3.1 { + CREATE TABLE t4( + a DEFAULT NULL, + b DEFAULT 'string constant', + c DEFAULT X'424C4F42', + d DEFAULT 1, + e DEFAULT -1, + f DEFAULT 3.14, + g DEFAULT -3.14, + h DEFAULT ( substr('abcd', 0, 2) || 'cd' ), + i DEFAULT CURRENT_TIME, + j DEFAULT CURRENT_DATE, + k DEFAULT CURRENT_TIMESTAMP + ); +} {} + +# EVIDENCE-OF: R-33440-07331 For the purposes of the DEFAULT clause, an +# expression is considered constant if it contains no sub-queries, +# column or table references, bound parameters, or string literals +# enclosed in double-quotes instead of single-quotes. +# +do_createtable_tests 3.4.1 -error { + default value of column [x] is not constant +} { + 1 {CREATE TABLE t5(x DEFAULT ( (SELECT 1) ))} {} + 2 {CREATE TABLE t5(x DEFAULT ( "abc" ))} {} + 3 {CREATE TABLE t5(x DEFAULT ( 1 IN (SELECT 1) ))} {} + 4 {CREATE TABLE t5(x DEFAULT ( EXISTS (SELECT 1) ))} {} + 5 {CREATE TABLE t5(x DEFAULT ( x!=?1 ))} {} +} +do_createtable_tests 3.4.2 -repair { + catchsql { DROP TABLE t5 } +} { + 1 {CREATE TABLE t5(x DEFAULT ( 'abc' ))} {} + 2 {CREATE TABLE t5(x DEFAULT ( 1 IN (1, 2, 3) ))} {} +} + +# EVIDENCE-OF: R-18814-23501 Each time a row is inserted into the table +# by an INSERT statement that does not provide explicit values for all +# table columns the values stored in the new row are determined by their +# default values +# +# Verify this with some assert statements for which all, some and no +# columns lack explicit values. +# +set sqlite_current_time 1000000000 +do_createtable_tests 3.5 -query { + SELECT quote(a), quote(b), quote(c), quote(d), quote(e), quote(f), + quote(g), quote(h), quote(i), quote(j), quote(k) + FROM t4 ORDER BY rowid DESC LIMIT 1; +} { + 1 "INSERT INTO t4 DEFAULT VALUES" { + NULL {'string constant'} X'424C4F42' 1 -1 3.14 -3.14 + 'acd' '01:46:40' '2001-09-09' {'2001-09-09 01:46:40'} + } + + 2 "INSERT INTO t4(a, b, c) VALUES(1, 2, 3)" { + 1 2 3 1 -1 3.14 -3.14 'acd' '01:46:40' '2001-09-09' {'2001-09-09 01:46:40'} + } + + 3 "INSERT INTO t4(k, j, i) VALUES(1, 2, 3)" { + NULL {'string constant'} X'424C4F42' 1 -1 3.14 -3.14 'acd' 3 2 1 + } + + 4 "INSERT INTO t4(a,b,c,d,e,f,g,h,i,j,k) VALUES(1,2,3,4,5,6,7,8,9,10,11)" { + 1 2 3 4 5 6 7 8 9 10 11 + } +} + +# EVIDENCE-OF: R-12572-62501 If the default value of the column is a +# constant NULL, text, blob or signed-number value, then that value is +# used directly in the new row. +# +do_execsql_test e_createtable-3.6.1 { + CREATE TABLE t5( + a DEFAULT NULL, + b DEFAULT 'text value', + c DEFAULT X'424C4F42', + d DEFAULT -45678.6, + e DEFAULT 394507 + ); +} {} +do_execsql_test e_createtable-3.6.2 { + INSERT INTO t5 DEFAULT VALUES; + SELECT quote(a), quote(b), quote(c), quote(d), quote(e) FROM t5; +} {NULL {'text value'} X'424C4F42' -45678.6 394507} + +# EVIDENCE-OF: R-60616-50251 If the default value of a column is an +# expression in parentheses, then the expression is evaluated once for +# each row inserted and the results used in the new row. +# +# Test case 3.6.4 demonstrates that the expression is evaluated +# separately for each row if the INSERT is an "INSERT INTO ... SELECT ..." +# command. +# +set ::nextint 0 +proc nextint {} { incr ::nextint } +db func nextint nextint + +do_execsql_test e_createtable-3.7.1 { + CREATE TABLE t6(a DEFAULT ( nextint() ), b DEFAULT ( nextint() )); +} {} +do_execsql_test e_createtable-3.7.2 { + INSERT INTO t6 DEFAULT VALUES; + SELECT quote(a), quote(b) FROM t6; +} {1 2} +do_execsql_test e_createtable-3.7.3 { + INSERT INTO t6(a) VALUES('X'); + SELECT quote(a), quote(b) FROM t6; +} {1 2 'X' 3} +do_execsql_test e_createtable-3.7.4 { + INSERT INTO t6(a) SELECT a FROM t6; + SELECT quote(a), quote(b) FROM t6; +} {1 2 'X' 3 1 4 'X' 5} + +# EVIDENCE-OF: R-15363-55230 If the default value of a column is +# CURRENT_TIME, CURRENT_DATE or CURRENT_TIMESTAMP, then the value used +# in the new row is a text representation of the current UTC date and/or +# time. +# +# This is difficult to test literally without knowing what time the +# user will run the tests. Instead, we test that the three cases +# above set the value to the current date and/or time according to +# the xCurrentTime() method of the VFS. Which is usually the same +# as UTC. In this case, however, we instrument it to always return +# a time equivalent to "2001-09-09 01:46:40 UTC". +# +set sqlite_current_time 1000000000 +do_execsql_test e_createtable-3.8.1 { + CREATE TABLE t7( + a DEFAULT CURRENT_TIME, + b DEFAULT CURRENT_DATE, + c DEFAULT CURRENT_TIMESTAMP + ); +} {} +do_execsql_test e_createtable-3.8.2 { + INSERT INTO t7 DEFAULT VALUES; + SELECT quote(a), quote(b), quote(c) FROM t7; +} {'01:46:40' '2001-09-09' {'2001-09-09 01:46:40'}} + + +# EVIDENCE-OF: R-62327-53843 For CURRENT_TIME, the format of the value +# is "HH:MM:SS". +# +# EVIDENCE-OF: R-03775-43471 For CURRENT_DATE, "YYYY-MM-DD". +# +# EVIDENCE-OF: R-07677-44926 The format for CURRENT_TIMESTAMP is +# "YYYY-MM-DD HH:MM:SS". +# +# The three above are demonstrated by tests 1, 2 and 3 below. +# Respectively. +# +do_createtable_tests 3.8.3 -query { + SELECT a, b, c FROM t7 ORDER BY rowid DESC LIMIT 1; +} { + 1 "INSERT INTO t7(b, c) VALUES('x', 'y')" {01:46:40 x y} + 2 "INSERT INTO t7(c, a) VALUES('x', 'y')" {y 2001-09-09 x} + 3 "INSERT INTO t7(a, b) VALUES('x', 'y')" {x y {2001-09-09 01:46:40}} +} + +# EVIDENCE-OF: R-55061-47754 The COLLATE clause specifies the name of a +# collating sequence to use as the default collation sequence for the +# column. +# +# EVIDENCE-OF: R-40275-54363 If no COLLATE clause is specified, the +# default collation sequence is BINARY. +# +do_execsql_test e_createtable-3-9.1 { + CREATE TABLE t8(a COLLATE nocase, b COLLATE rtrim, c COLLATE binary, d); + INSERT INTO t8 VALUES('abc', 'abc', 'abc', 'abc'); + INSERT INTO t8 VALUES('abc ', 'abc ', 'abc ', 'abc '); + INSERT INTO t8 VALUES('ABC ', 'ABC ', 'ABC ', 'ABC '); + INSERT INTO t8 VALUES('ABC', 'ABC', 'ABC', 'ABC'); +} {} +do_createtable_tests 3.9 { + 2 "SELECT a FROM t8 ORDER BY a, rowid" {abc ABC {abc } {ABC }} + 3 "SELECT b FROM t8 ORDER BY b, rowid" {{ABC } ABC abc {abc }} + 4 "SELECT c FROM t8 ORDER BY c, rowid" {ABC {ABC } abc {abc }} + 5 "SELECT d FROM t8 ORDER BY d, rowid" {ABC {ABC } abc {abc }} +} + +# EVIDENCE-OF: R-25473-20557 The number of columns in a table is limited +# by the SQLITE_MAX_COLUMN compile-time parameter. +# +proc columns {n} { + set res [list] + for {set i 0} {$i < $n} {incr i} { lappend res "c$i" } + join $res ", " +} +do_execsql_test e_createtable-3.10.1 [subst { + CREATE TABLE t9([columns $::SQLITE_MAX_COLUMN]); +}] {} +do_catchsql_test e_createtable-3.10.2 [subst { + CREATE TABLE t10([columns [expr $::SQLITE_MAX_COLUMN+1]]); +}] {1 {too many columns on t10}} + +# EVIDENCE-OF: R-27775-64721 Both of these limits can be lowered at +# runtime using the sqlite3_limit() C/C++ interface. +# +# A 30,000 byte blob consumes 30,003 bytes of record space. A record +# that contains 3 such blobs consumes (30,000*3)+1 bytes of space. Tests +# 3.11.4 and 3.11.5, which verify that SQLITE_MAX_LENGTH may be lowered +# at runtime, are based on this calculation. +# +sqlite3_limit db SQLITE_LIMIT_COLUMN 500 +do_execsql_test e_createtable-3.11.1 [subst { + CREATE TABLE t10([columns 500]); +}] {} +do_catchsql_test e_createtable-3.11.2 [subst { + CREATE TABLE t11([columns 501]); +}] {1 {too many columns on t11}} + +# Check that it is not possible to raise the column limit above its +# default compile time value. +# +sqlite3_limit db SQLITE_LIMIT_COLUMN [expr $::SQLITE_MAX_COLUMN+2] +do_catchsql_test e_createtable-3.11.3 [subst { + CREATE TABLE t11([columns [expr $::SQLITE_MAX_COLUMN+1]]); +}] {1 {too many columns on t11}} + +sqlite3_limit db SQLITE_LIMIT_LENGTH 90010 +do_execsql_test e_createtable-3.11.4 { + CREATE TABLE t12(a, b, c); + INSERT INTO t12 VALUES(randomblob(30000),randomblob(30000),randomblob(30000)); +} {} +do_catchsql_test e_createtable-3.11.5 { + INSERT INTO t12 VALUES(randomblob(30001),randomblob(30000),randomblob(30000)); +} {1 {string or blob too big}} + +#------------------------------------------------------------------------- +# Tests for statements regarding constraints (PRIMARY KEY, UNIQUE, NOT +# NULL and CHECK constraints). +# + +# EVIDENCE-OF: R-52382-54248 Each table in SQLite may have at most one +# PRIMARY KEY. +# +# EVIDENCE-OF: R-31826-01813 An error is raised if more than one PRIMARY +# KEY clause appears in a CREATE TABLE statement. +# +# To test the two above, show that zero primary keys is Ok, one primary +# key is Ok, and two or more primary keys is an error. +# +drop_all_tables +do_createtable_tests 4.1.1 { + 1 "CREATE TABLE t1(a, b, c)" {} + 2 "CREATE TABLE t2(a PRIMARY KEY, b, c)" {} + 3 "CREATE TABLE t3(a, b, c, PRIMARY KEY(a))" {} + 4 "CREATE TABLE t4(a, b, c, PRIMARY KEY(c,b,a))" {} +} +do_createtable_tests 4.1.2 -error { + table "t5" has more than one primary key +} { + 1 "CREATE TABLE t5(a PRIMARY KEY, b PRIMARY KEY, c)" {} + 2 "CREATE TABLE t5(a, b PRIMARY KEY, c, PRIMARY KEY(a))" {} + 3 "CREATE TABLE t5(a INTEGER PRIMARY KEY, b PRIMARY KEY, c)" {} + 4 "CREATE TABLE t5(a INTEGER PRIMARY KEY, b, c, PRIMARY KEY(b, c))" {} + 5 "CREATE TABLE t5(a PRIMARY KEY, b, c, PRIMARY KEY(a))" {} + 6 "CREATE TABLE t5(a INTEGER PRIMARY KEY, b, c, PRIMARY KEY(a))" {} +} + +# EVIDENCE-OF: R-54755-39291 The PRIMARY KEY is optional for ordinary +# tables but is required for WITHOUT ROWID tables. +# +do_catchsql_test 4.1.3 { + CREATE TABLE t6(a, b); --ok +} {0 {}} +do_catchsql_test 4.1.4 { + CREATE TABLE t7(a, b) WITHOUT ROWID; --Error, no PRIMARY KEY +} {1 {PRIMARY KEY missing on table t7}} + + +proc table_pk {tbl} { + set pk [list] + db eval "pragma table_info($tbl)" a { + if {$a(pk)} { lappend pk $a(name) } + } + set pk +} + +# EVIDENCE-OF: R-41411-18837 If the keywords PRIMARY KEY are added to a +# column definition, then the primary key for the table consists of that +# single column. +# +# The above is tested by 4.2.1.* +# +# EVIDENCE-OF: R-31775-48204 Or, if a PRIMARY KEY clause is specified as +# a table-constraint, then the primary key of the table consists of the +# list of columns specified as part of the PRIMARY KEY clause. +# +# The above is tested by 4.2.2.* +# +do_createtable_tests 4.2 -repair { + catchsql { DROP TABLE t5 } +} -tclquery { + table_pk t5 +} { + 1.1 "CREATE TABLE t5(a, b INTEGER PRIMARY KEY, c)" {b} + 1.2 "CREATE TABLE t5(a PRIMARY KEY, b, c)" {a} + + 2.1 "CREATE TABLE t5(a, b, c, PRIMARY KEY(a))" {a} + 2.2 "CREATE TABLE t5(a, b, c, PRIMARY KEY(c,b,a))" {a b c} + 2.3 "CREATE TABLE t5(a, b INTEGER PRIMARY KEY, c)" {b} +} + +# EVIDENCE-OF: R-59124-61339 Each row in a table with a primary key must +# have a unique combination of values in its primary key columns. +# +# EVIDENCE-OF: R-06471-16287 If an INSERT or UPDATE statement attempts +# to modify the table content so that two or more rows have identical +# primary key values, that is a constraint violation. +# +drop_all_tables +do_execsql_test 4.3.0 { + CREATE TABLE t1(x PRIMARY KEY, y); + INSERT INTO t1 VALUES(0, 'zero'); + INSERT INTO t1 VALUES(45.5, 'one'); + INSERT INTO t1 VALUES('brambles', 'two'); + INSERT INTO t1 VALUES(X'ABCDEF', 'three'); + + CREATE TABLE t2(x, y, PRIMARY KEY(x, y)); + INSERT INTO t2 VALUES(0, 'zero'); + INSERT INTO t2 VALUES(45.5, 'one'); + INSERT INTO t2 VALUES('brambles', 'two'); + INSERT INTO t2 VALUES(X'ABCDEF', 'three'); +} {} + +do_createtable_tests 4.3.1 -error {UNIQUE constraint failed: t1.x} { + 1 "INSERT INTO t1 VALUES(0, 0)" {"column x is"} + 2 "INSERT INTO t1 VALUES(45.5, 'abc')" {"column x is"} + 3 "INSERT INTO t1 VALUES(0.0, 'abc')" {"column x is"} + 4 "INSERT INTO t1 VALUES('brambles', 'abc')" {"column x is"} + 5 "INSERT INTO t1 VALUES(X'ABCDEF', 'abc')" {"column x is"} +} +do_createtable_tests 4.3.1 -error {UNIQUE constraint failed: t2.x, t2.y} { + 6 "INSERT INTO t2 VALUES(0, 'zero')" {"columns x, y are"} + 7 "INSERT INTO t2 VALUES(45.5, 'one')" {"columns x, y are"} + 8 "INSERT INTO t2 VALUES(0.0, 'zero')" {"columns x, y are"} + 9 "INSERT INTO t2 VALUES('brambles', 'two')" {"columns x, y are"} + 10 "INSERT INTO t2 VALUES(X'ABCDEF', 'three')" {"columns x, y are"} +} +do_createtable_tests 4.3.2 { + 1 "INSERT INTO t1 VALUES(-1, 0)" {} + 2 "INSERT INTO t1 VALUES(45.2, 'abc')" {} + 3 "INSERT INTO t1 VALUES(0.01, 'abc')" {} + 4 "INSERT INTO t1 VALUES('bramble', 'abc')" {} + 5 "INSERT INTO t1 VALUES(X'ABCDEE', 'abc')" {} + + 6 "INSERT INTO t2 VALUES(0, 0)" {} + 7 "INSERT INTO t2 VALUES(45.5, 'abc')" {} + 8 "INSERT INTO t2 VALUES(0.0, 'abc')" {} + 9 "INSERT INTO t2 VALUES('brambles', 'abc')" {} + 10 "INSERT INTO t2 VALUES(X'ABCDEF', 'abc')" {} +} +do_createtable_tests 4.3.3 -error {UNIQUE constraint failed: t1.x} { + 1 "UPDATE t1 SET x=0 WHERE y='two'" {"column x is"} + 2 "UPDATE t1 SET x='brambles' WHERE y='three'" {"column x is"} + 3 "UPDATE t1 SET x=45.5 WHERE y='zero'" {"column x is"} + 4 "UPDATE t1 SET x=X'ABCDEF' WHERE y='one'" {"column x is"} + 5 "UPDATE t1 SET x=0.0 WHERE y='three'" {"column x is"} +} +do_createtable_tests 4.3.3 -error {UNIQUE constraint failed: t2.x, t2.y} { + 6 "UPDATE t2 SET x=0, y='zero' WHERE y='two'" {"columns x, y are"} + 7 "UPDATE t2 SET x='brambles', y='two' WHERE y='three'" + {"columns x, y are"} + 8 "UPDATE t2 SET x=45.5, y='one' WHERE y='zero'" {"columns x, y are"} + 9 "UPDATE t2 SET x=X'ABCDEF', y='three' WHERE y='one'" + {"columns x, y are"} + 10 "UPDATE t2 SET x=0.0, y='zero' WHERE y='three'" + {"columns x, y are"} +} + + +# EVIDENCE-OF: R-52572-02078 For the purposes of determining the +# uniqueness of primary key values, NULL values are considered distinct +# from all other values, including other NULLs. +# +do_createtable_tests 4.4 { + 1 "INSERT INTO t1 VALUES(NULL, 0)" {} + 2 "INSERT INTO t1 VALUES(NULL, 0)" {} + 3 "INSERT INTO t1 VALUES(NULL, 0)" {} + + 4 "INSERT INTO t2 VALUES(NULL, 'zero')" {} + 5 "INSERT INTO t2 VALUES(NULL, 'one')" {} + 6 "INSERT INTO t2 VALUES(NULL, 'two')" {} + 7 "INSERT INTO t2 VALUES(NULL, 'three')" {} + + 8 "INSERT INTO t2 VALUES(0, NULL)" {} + 9 "INSERT INTO t2 VALUES(45.5, NULL)" {} + 10 "INSERT INTO t2 VALUES(0.0, NULL)" {} + 11 "INSERT INTO t2 VALUES('brambles', NULL)" {} + 12 "INSERT INTO t2 VALUES(X'ABCDEF', NULL)" {} + + 13 "INSERT INTO t2 VALUES(NULL, NULL)" {} + 14 "INSERT INTO t2 VALUES(NULL, NULL)" {} +} + +# EVIDENCE-OF: R-40010-16873 Unless the column is an INTEGER PRIMARY KEY +# or the table is a WITHOUT ROWID table or a STRICT table or the column +# is declared NOT NULL, SQLite allows NULL values in a PRIMARY KEY +# column. +# +# If the column is an integer primary key, attempting to insert a NULL +# into the column triggers the auto-increment behavior. Attempting +# to use UPDATE to set an ipk column to a NULL value is an error. +# +do_createtable_tests 4.5.1 { + 1 "SELECT count(*) FROM t1 WHERE x IS NULL" 3 + 2 "SELECT count(*) FROM t2 WHERE x IS NULL" 6 + 3 "SELECT count(*) FROM t2 WHERE y IS NULL" 7 + 4 "SELECT count(*) FROM t2 WHERE x IS NULL AND y IS NULL" 2 +} +do_execsql_test 4.5.2 { + CREATE TABLE t3(s, u INTEGER PRIMARY KEY, v); + INSERT INTO t3 VALUES(1, NULL, 2); + INSERT INTO t3 VALUES('x', NULL, 'y'); + SELECT u FROM t3; +} {1 2} +do_catchsql_test 4.5.3 { + INSERT INTO t3 VALUES(2, 5, 3); + UPDATE t3 SET u = NULL WHERE s = 2; +} {1 {datatype mismatch}} +do_catchsql_test 4.5.4 { + CREATE TABLE t4(s, u INT PRIMARY KEY, v) WITHOUT ROWID; + INSERT INTO t4 VALUES(1, NULL, 2); +} {1 {NOT NULL constraint failed: t4.u}} +do_catchsql_test 4.5.5 { + CREATE TABLE t5(s, u INT PRIMARY KEY NOT NULL, v); + INSERT INTO t5 VALUES(1, NULL, 2); +} {1 {NOT NULL constraint failed: t5.u}} +do_catchsql_test 4.5.6 { + CREATE TABLE t6(s INT, u INT PRIMARY KEY, v INT) STRICT; + INSERT INTO t6 VALUES(1, NULL, 2); +} {1 {NOT NULL constraint failed: t6.u}} +do_catchsql_test 4.5.7 { + CREATE TABLE t7(s INT, u INT PRIMARY KEY NOT NULL, v INT) STRICT; + INSERT INTO t7 VALUES(1, NULL, 2); +} {1 {NOT NULL constraint failed: t7.u}} + +# EVIDENCE-OF: R-00227-21080 A UNIQUE constraint is similar to a PRIMARY +# KEY constraint, except that a single table may have any number of +# UNIQUE constraints. +# +drop_all_tables +do_createtable_tests 4.6 { + 1 "CREATE TABLE t1(a UNIQUE, b UNIQUE)" {} + 2 "CREATE TABLE t2(a UNIQUE, b, c, UNIQUE(c, b))" {} + 3 "CREATE TABLE t3(a, b, c, UNIQUE(a), UNIQUE(b), UNIQUE(c))" {} + 4 "CREATE TABLE t4(a, b, c, UNIQUE(a, b, c))" {} +} + +# EVIDENCE-OF: R-30981-64168 For each UNIQUE constraint on the table, +# each row must contain a unique combination of values in the columns +# identified by the UNIQUE constraint. +# +# EVIDENCE-OF: R-59124-61339 Each row in a table with a primary key must +# have a unique combination of values in its primary key columns. +# +do_execsql_test 4.7.0 { + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t1 VALUES(4.3, 5.5); + INSERT INTO t1 VALUES('reveal', 'variableness'); + INSERT INTO t1 VALUES(X'123456', X'654321'); + + INSERT INTO t4 VALUES('xyx', 1, 1); + INSERT INTO t4 VALUES('xyx', 2, 1); + INSERT INTO t4 VALUES('uvw', 1, 1); +} +do_createtable_tests 4.7.1 -error {UNIQUE constraint failed: %s} { + 1 "INSERT INTO t1 VALUES(1, 'one')" {{t1.a}} + 2 "INSERT INTO t1 VALUES(4.3, 'two')" {{t1.a}} + 3 "INSERT INTO t1 VALUES('reveal', 'three')" {{t1.a}} + 4 "INSERT INTO t1 VALUES(X'123456', 'four')" {{t1.a}} + + 5 "UPDATE t1 SET a = 1 WHERE rowid=2" {{t1.a}} + 6 "UPDATE t1 SET a = 4.3 WHERE rowid=3" {{t1.a}} + 7 "UPDATE t1 SET a = 'reveal' WHERE rowid=4" {{t1.a}} + 8 "UPDATE t1 SET a = X'123456' WHERE rowid=1" {{t1.a}} + + 9 "INSERT INTO t4 VALUES('xyx', 1, 1)" {{t4.a, t4.b, t4.c}} + 10 "INSERT INTO t4 VALUES('xyx', 2, 1)" {{t4.a, t4.b, t4.c}} + 11 "INSERT INTO t4 VALUES('uvw', 1, 1)" {{t4.a, t4.b, t4.c}} + + 12 "UPDATE t4 SET a='xyx' WHERE rowid=3" {{t4.a, t4.b, t4.c}} + 13 "UPDATE t4 SET b=1 WHERE rowid=2" {{t4.a, t4.b, t4.c}} + 14 "UPDATE t4 SET a=0, b=0, c=0" {{t4.a, t4.b, t4.c}} +} + +# EVIDENCE-OF: R-00404-17670 For the purposes of UNIQUE constraints, +# NULL values are considered distinct from all other values, including +# other NULLs. +# +do_createtable_tests 4.8 { + 1 "INSERT INTO t1 VALUES(NULL, NULL)" {} + 2 "INSERT INTO t1 VALUES(NULL, NULL)" {} + 3 "UPDATE t1 SET a = NULL" {} + 4 "UPDATE t1 SET b = NULL" {} + + 5 "INSERT INTO t4 VALUES(NULL, NULL, NULL)" {} + 6 "INSERT INTO t4 VALUES(NULL, NULL, NULL)" {} + 7 "UPDATE t4 SET a = NULL" {} + 8 "UPDATE t4 SET b = NULL" {} + 9 "UPDATE t4 SET c = NULL" {} +} + +# EVIDENCE-OF: R-55820-29984 In most cases, UNIQUE and PRIMARY KEY +# constraints are implemented by creating a unique index in the +# database. +do_createtable_tests 4.9 -repair drop_all_tables -query { + SELECT count(*) FROM sqlite_master WHERE type='index' +} { + 1 "CREATE TABLE t1(a TEXT PRIMARY KEY, b)" 1 + 2 "CREATE TABLE t1(a INTEGER PRIMARY KEY, b)" 0 + 3 "CREATE TABLE t1(a TEXT UNIQUE, b)" 1 + 4 "CREATE TABLE t1(a PRIMARY KEY, b TEXT UNIQUE)" 2 + 5 "CREATE TABLE t1(a PRIMARY KEY, b, c, UNIQUE(c, b))" 2 +} + +# Obsolete: R-02252-33116 Such an index is used like any other index +# in the database to optimize queries. +# +do_execsql_test 4.10.0 { + CREATE TABLE t1(a, b PRIMARY KEY); + CREATE TABLE t2(a, b, c, UNIQUE(b, c)); +} +do_createtable_tests 4.10 { + 1 "EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE b = 5" + {/*SEARCH t1 USING INDEX sqlite_autoindex_t1_1 (b=?)*/} + + 2 "EXPLAIN QUERY PLAN SELECT * FROM t2 ORDER BY b, c" + {/*SCAN t2 USING INDEX sqlite_autoindex_t2_1*/} + + 3 "EXPLAIN QUERY PLAN SELECT * FROM t2 WHERE b=10 AND c>10" + {/*SEARCH t2 USING INDEX sqlite_autoindex_t2_1 (b=? AND c>?)*/} +} + +# EVIDENCE-OF: R-45493-35653 A CHECK constraint may be attached to a +# column definition or specified as a table constraint. In practice it +# makes no difference. +# +# All the tests that deal with CHECK constraints below (4.11.* and +# 4.12.*) are run once for a table with the check constraint attached +# to a column definition, and once with a table where the check +# condition is specified as a table constraint. +# +# EVIDENCE-OF: R-55435-14303 Each time a new row is inserted into the +# table or an existing row is updated, the expression associated with +# each CHECK constraint is evaluated and cast to a NUMERIC value in the +# same way as a CAST expression. If the result is zero (integer value 0 +# or real value 0.0), then a constraint violation has occurred. +# +drop_all_tables +do_execsql_test 4.11 { + CREATE TABLE x1(a TEXT, b INTEGER CHECK( b>0 )); + CREATE TABLE t1(a TEXT, b INTEGER, CHECK( b>0 )); + INSERT INTO x1 VALUES('x', 'xx'); + INSERT INTO x1 VALUES('y', 'yy'); + INSERT INTO t1 SELECT * FROM x1; + + CREATE TABLE x2(a CHECK( a||b ), b); + CREATE TABLE t2(a, b, CHECK( a||b )); + INSERT INTO x2 VALUES(1, 'xx'); + INSERT INTO x2 VALUES(1, 'yy'); + INSERT INTO t2 SELECT * FROM x2; +} + +do_createtable_tests 4.11 -error {CHECK constraint failed: %s} { + 1a "INSERT INTO x1 VALUES('one', 0)" {b>0} + 1b "INSERT INTO t1 VALUES('one', -4.0)" {b>0} + + 2a "INSERT INTO x2 VALUES('abc', 1)" {a||b} + 2b "INSERT INTO t2 VALUES('abc', 1)" {a||b} + + 3a "INSERT INTO x2 VALUES(0, 'abc')" {a||b} + 3b "INSERT INTO t2 VALUES(0, 'abc')" {a||b} + + 4a "UPDATE t1 SET b=-1 WHERE rowid=1" {b>0} + 4b "UPDATE x1 SET b=-1 WHERE rowid=1" {b>0} + + 4a "UPDATE x2 SET a='' WHERE rowid=1" {a||b} + 4b "UPDATE t2 SET a='' WHERE rowid=1" {a||b} +} + +# EVIDENCE-OF: R-34109-39108 If the CHECK expression evaluates to NULL, +# or any other non-zero value, it is not a constraint violation. +# +do_createtable_tests 4.12 { + 1a "INSERT INTO x1 VALUES('one', NULL)" {} + 1b "INSERT INTO t1 VALUES('one', NULL)" {} + + 2a "INSERT INTO x1 VALUES('one', 2)" {} + 2b "INSERT INTO t1 VALUES('one', 2)" {} + + 3a "INSERT INTO x2 VALUES(1, 'abc')" {} + 3b "INSERT INTO t2 VALUES(1, 'abc')" {} +} + +# EVIDENCE-OF: R-02060-64547 A NOT NULL constraint may only be attached +# to a column definition, not specified as a table constraint. +# +drop_all_tables +do_createtable_tests 4.13.1 { + 1 "CREATE TABLE t1(a NOT NULL, b)" {} + 2 "CREATE TABLE t2(a PRIMARY KEY NOT NULL, b)" {} + 3 "CREATE TABLE t3(a NOT NULL, b NOT NULL, c NOT NULL UNIQUE)" {} +} +do_createtable_tests 4.13.2 -error { + near "NOT": syntax error +} { + 1 "CREATE TABLE t4(a, b, NOT NULL(a))" {} + 2 "CREATE TABLE t4(a PRIMARY KEY, b, NOT NULL(a))" {} + 3 "CREATE TABLE t4(a, b, c UNIQUE, NOT NULL(a, b, c))" {} +} + +# EVIDENCE-OF: R-31795-57643 a NOT NULL constraint dictates that the +# associated column may not contain a NULL value. Attempting to set the +# column value to NULL when inserting a new row or updating an existing +# one causes a constraint violation. +# +# These tests use the tables created by 4.13. +# +do_execsql_test 4.14.0 { + INSERT INTO t1 VALUES('x', 'y'); + INSERT INTO t1 VALUES('z', NULL); + + INSERT INTO t2 VALUES('x', 'y'); + INSERT INTO t2 VALUES('z', NULL); + + INSERT INTO t3 VALUES('x', 'y', 'z'); + INSERT INTO t3 VALUES(1, 2, 3); +} +do_createtable_tests 4.14 -error {NOT NULL constraint failed: %s} { + 1 "INSERT INTO t1 VALUES(NULL, 'a')" {t1.a} + 2 "INSERT INTO t2 VALUES(NULL, 'b')" {t2.a} + 3 "INSERT INTO t3 VALUES('c', 'd', NULL)" {t3.c} + 4 "INSERT INTO t3 VALUES('e', NULL, 'f')" {t3.b} + 5 "INSERT INTO t3 VALUES(NULL, 'g', 'h')" {t3.a} +} + +# EVIDENCE-OF: R-34093-09213 PRIMARY KEY, UNIQUE and NOT NULL +# constraints may be explicitly assigned another default conflict +# resolution algorithm by including a conflict-clause in their +# definitions. +# +# Conflict clauses: ABORT, ROLLBACK, IGNORE, FAIL, REPLACE +# +# Test cases 4.15.*, 4.16.* and 4.17.* focus on PRIMARY KEY, NOT NULL +# and UNIQUE constraints, respectively. +# +drop_all_tables +do_execsql_test 4.15.0 { + CREATE TABLE t1_ab(a PRIMARY KEY ON CONFLICT ABORT, b); + CREATE TABLE t1_ro(a PRIMARY KEY ON CONFLICT ROLLBACK, b); + CREATE TABLE t1_ig(a PRIMARY KEY ON CONFLICT IGNORE, b); + CREATE TABLE t1_fa(a PRIMARY KEY ON CONFLICT FAIL, b); + CREATE TABLE t1_re(a PRIMARY KEY ON CONFLICT REPLACE, b); + CREATE TABLE t1_xx(a PRIMARY KEY, b); + + INSERT INTO t1_ab VALUES(1, 'one'); + INSERT INTO t1_ab VALUES(2, 'two'); + INSERT INTO t1_ro SELECT * FROM t1_ab; + INSERT INTO t1_ig SELECT * FROM t1_ab; + INSERT INTO t1_fa SELECT * FROM t1_ab; + INSERT INTO t1_re SELECT * FROM t1_ab; + INSERT INTO t1_xx SELECT * FROM t1_ab; + + CREATE TABLE t2_ab(a, b NOT NULL ON CONFLICT ABORT); + CREATE TABLE t2_ro(a, b NOT NULL ON CONFLICT ROLLBACK); + CREATE TABLE t2_ig(a, b NOT NULL ON CONFLICT IGNORE); + CREATE TABLE t2_fa(a, b NOT NULL ON CONFLICT FAIL); + CREATE TABLE t2_re(a, b NOT NULL ON CONFLICT REPLACE); + CREATE TABLE t2_xx(a, b NOT NULL); + + INSERT INTO t2_ab VALUES(1, 'one'); + INSERT INTO t2_ab VALUES(2, 'two'); + INSERT INTO t2_ro SELECT * FROM t2_ab; + INSERT INTO t2_ig SELECT * FROM t2_ab; + INSERT INTO t2_fa SELECT * FROM t2_ab; + INSERT INTO t2_re SELECT * FROM t2_ab; + INSERT INTO t2_xx SELECT * FROM t2_ab; + + CREATE TABLE t3_ab(a, b, UNIQUE(a, b) ON CONFLICT ABORT); + CREATE TABLE t3_ro(a, b, UNIQUE(a, b) ON CONFLICT ROLLBACK); + CREATE TABLE t3_ig(a, b, UNIQUE(a, b) ON CONFLICT IGNORE); + CREATE TABLE t3_fa(a, b, UNIQUE(a, b) ON CONFLICT FAIL); + CREATE TABLE t3_re(a, b, UNIQUE(a, b) ON CONFLICT REPLACE); + CREATE TABLE t3_xx(a, b, UNIQUE(a, b)); + + INSERT INTO t3_ab VALUES(1, 'one'); + INSERT INTO t3_ab VALUES(2, 'two'); + INSERT INTO t3_ro SELECT * FROM t3_ab; + INSERT INTO t3_ig SELECT * FROM t3_ab; + INSERT INTO t3_fa SELECT * FROM t3_ab; + INSERT INTO t3_re SELECT * FROM t3_ab; + INSERT INTO t3_xx SELECT * FROM t3_ab; +} + +foreach {tn tbl res ac data} { + 1 t1_ab {1 {UNIQUE constraint failed: t1_ab.a}} 0 {1 one 2 two 3 three} + 2 t1_ro {1 {UNIQUE constraint failed: t1_ro.a}} 1 {1 one 2 two} + 3 t1_fa {1 {UNIQUE constraint failed: t1_fa.a}} 0 {1 one 2 two 3 three 4 string} + 4 t1_ig {0 {}} 0 {1 one 2 two 3 three 4 string 6 string} + 5 t1_re {0 {}} 0 {1 one 2 two 4 string 3 string 6 string} + 6 t1_xx {1 {UNIQUE constraint failed: t1_xx.a}} 0 {1 one 2 two 3 three} +} { + catchsql COMMIT + do_execsql_test 4.15.$tn.1 "BEGIN; INSERT INTO $tbl VALUES(3, 'three')" + + do_catchsql_test 4.15.$tn.2 " + INSERT INTO $tbl SELECT ((a%2)*a+3), 'string' FROM $tbl; + " $res + + do_test e_createtable-4.15.$tn.3 { sqlite3_get_autocommit db } $ac + do_execsql_test 4.15.$tn.4 "SELECT * FROM $tbl" $data +} +foreach {tn tbl res ac data} { + 1 t2_ab {1 {NOT NULL constraint failed: t2_ab.b}} 0 {1 one 2 two 3 three} + 2 t2_ro {1 {NOT NULL constraint failed: t2_ro.b}} 1 {1 one 2 two} + 3 t2_fa {1 {NOT NULL constraint failed: t2_fa.b}} 0 {1 one 2 two 3 three 4 xx} + 4 t2_ig {0 {}} 0 {1 one 2 two 3 three 4 xx 6 xx} + 5 t2_re {1 {NOT NULL constraint failed: t2_re.b}} 0 {1 one 2 two 3 three} + 6 t2_xx {1 {NOT NULL constraint failed: t2_xx.b}} 0 {1 one 2 two 3 three} +} { + catchsql COMMIT + do_execsql_test 4.16.$tn.1 "BEGIN; INSERT INTO $tbl VALUES(3, 'three')" + + do_catchsql_test 4.16.$tn.2 " + INSERT INTO $tbl SELECT a+3, CASE a WHEN 2 THEN NULL ELSE 'xx' END FROM $tbl + " $res + + do_test e_createtable-4.16.$tn.3 { sqlite3_get_autocommit db } $ac + do_execsql_test 4.16.$tn.4 "SELECT * FROM $tbl" $data +} +foreach {tn tbl res ac data} { + 1 t3_ab {1 {UNIQUE constraint failed: t3_ab.a, t3_ab.b}} + 0 {1 one 2 two 3 three} + 2 t3_ro {1 {UNIQUE constraint failed: t3_ro.a, t3_ro.b}} + 1 {1 one 2 two} + 3 t3_fa {1 {UNIQUE constraint failed: t3_fa.a, t3_fa.b}} + 0 {1 one 2 two 3 three 4 three} + 4 t3_ig {0 {}} 0 {1 one 2 two 3 three 4 three 6 three} + 5 t3_re {0 {}} 0 {1 one 2 two 4 three 3 three 6 three} + 6 t3_xx {1 {UNIQUE constraint failed: t3_xx.a, t3_xx.b}} + 0 {1 one 2 two 3 three} +} { + catchsql COMMIT + do_execsql_test 4.17.$tn.1 "BEGIN; INSERT INTO $tbl VALUES(3, 'three')" + + do_catchsql_test 4.17.$tn.2 " + INSERT INTO $tbl SELECT ((a%2)*a+3), 'three' FROM $tbl + " $res + + do_test e_createtable-4.17.$tn.3 { sqlite3_get_autocommit db } $ac + do_execsql_test 4.17.$tn.4 "SELECT * FROM $tbl ORDER BY rowid" $data +} +catchsql COMMIT + +# EVIDENCE-OF: R-17539-59899 Or, if a constraint definition does not +# include a conflict-clause, the default conflict resolution algorithm +# is ABORT. +# +# The first half of the above is tested along with explicit ON +# CONFLICT clauses above (specifically, the tests involving t1_xx, t2_xx +# and t3_xx). The following just tests that the default conflict +# handling for CHECK constraints is ABORT. +# +do_execsql_test 4.18.1 { + CREATE TABLE t4(a, b CHECK (b!=10)); + INSERT INTO t4 VALUES(1, 2); + INSERT INTO t4 VALUES(3, 4); +} +do_execsql_test 4.18.2 { BEGIN; INSERT INTO t4 VALUES(5, 6) } +do_catchsql_test 4.18.3 { + INSERT INTO t4 SELECT a+4, b+4 FROM t4 +} {1 {CHECK constraint failed: b!=10}} +do_test e_createtable-4.18.4 { sqlite3_get_autocommit db } 0 +do_execsql_test 4.18.5 { SELECT * FROM t4 } {1 2 3 4 5 6} + +# EVIDENCE-OF: R-19114-56113 Different constraints within the same table +# may have different default conflict resolution algorithms. +# +do_execsql_test 4.19.0 { + CREATE TABLE t5(a NOT NULL ON CONFLICT IGNORE, b NOT NULL ON CONFLICT ABORT); +} +do_catchsql_test 4.19.1 { INSERT INTO t5 VALUES(NULL, 'not null') } {0 {}} +do_execsql_test 4.19.2 { SELECT * FROM t5 } {} +do_catchsql_test 4.19.3 { INSERT INTO t5 VALUES('not null', NULL) } \ + {1 {NOT NULL constraint failed: t5.b}} +do_execsql_test 4.19.4 { SELECT * FROM t5 } {} + +#------------------------------------------------------------------------ +# Tests for INTEGER PRIMARY KEY and rowid related statements. +# + +# EVIDENCE-OF: R-52584-04009 The rowid value can be accessed using one +# of the special case-independent names "rowid", "oid", or "_rowid_" in +# place of a column name. +# +# EVIDENCE-OF: R-06726-07466 A column name can be any of the names +# defined in the CREATE TABLE statement or one of the following special +# identifiers: "ROWID", "OID", or "_ROWID_". +# +drop_all_tables +do_execsql_test 5.1.0 { + CREATE TABLE t1(x, y); + INSERT INTO t1 VALUES('one', 'first'); + INSERT INTO t1 VALUES('two', 'second'); + INSERT INTO t1 VALUES('three', 'third'); +} +do_createtable_tests 5.1 { + 1 "SELECT rowid FROM t1" {1 2 3} + 2 "SELECT oid FROM t1" {1 2 3} + 3 "SELECT _rowid_ FROM t1" {1 2 3} + 4 "SELECT ROWID FROM t1" {1 2 3} + 5 "SELECT OID FROM t1" {1 2 3} + 6 "SELECT _ROWID_ FROM t1" {1 2 3} + 7 "SELECT RoWiD FROM t1" {1 2 3} + 8 "SELECT OiD FROM t1" {1 2 3} + 9 "SELECT _RoWiD_ FROM t1" {1 2 3} +} + +# EVIDENCE-OF: R-26501-17306 If a table contains a user defined column +# named "rowid", "oid" or "_rowid_", then that name always refers the +# explicitly declared column and cannot be used to retrieve the integer +# rowid value. +# +# EVIDENCE-OF: R-44615-33286 The special identifiers only refer to the +# row key if the CREATE TABLE statement does not define a real column +# with the same name. +# +do_execsql_test 5.2.0 { + CREATE TABLE t2(oid, b); + CREATE TABLE t3(a, _rowid_); + CREATE TABLE t4(a, b, rowid); + + INSERT INTO t2 VALUES('one', 'two'); + INSERT INTO t2 VALUES('three', 'four'); + + INSERT INTO t3 VALUES('five', 'six'); + INSERT INTO t3 VALUES('seven', 'eight'); + + INSERT INTO t4 VALUES('nine', 'ten', 'eleven'); + INSERT INTO t4 VALUES('twelve', 'thirteen', 'fourteen'); +} +do_createtable_tests 5.2 { + 1 "SELECT oid, rowid, _rowid_ FROM t2" {one 1 1 three 2 2} + 2 "SELECT oid, rowid, _rowid_ FROM t3" {1 1 six 2 2 eight} + 3 "SELECT oid, rowid, _rowid_ FROM t4" {1 eleven 1 2 fourteen 2} +} + + +# Argument $tbl is the name of a table in the database. Argument $col is +# the name of one of the tables columns. Return 1 if $col is an alias for +# the rowid, or 0 otherwise. +# +proc is_integer_primary_key {tbl col} { + lindex [db eval [subst { + DELETE FROM $tbl; + INSERT INTO $tbl ($col) VALUES(0); + SELECT (rowid==$col) FROM $tbl; + DELETE FROM $tbl; + }]] 0 +} + +# EVIDENCE-OF: R-47901-33947 With one exception noted below, if a rowid +# table has a primary key that consists of a single column and the +# declared type of that column is "INTEGER" in any mixture of upper and +# lower case, then the column becomes an alias for the rowid. +# +# EVIDENCE-OF: R-45951-08347 if the declaration of a column with +# declared type "INTEGER" includes an "PRIMARY KEY DESC" clause, it does +# not become an alias for the rowid and is not classified as an integer +# primary key. +# +do_createtable_tests 5.3 -tclquery { + is_integer_primary_key t5 pk +} -repair { + catchsql { DROP TABLE t5 } +} { + 1 "CREATE TABLE t5(pk integer primary key)" 1 + 2 "CREATE TABLE t5(pk integer, primary key(pk))" 1 + 3 "CREATE TABLE t5(pk integer, v integer, primary key(pk))" 1 + 4 "CREATE TABLE t5(pk integer, v integer, primary key(pk, v))" 0 + 5 "CREATE TABLE t5(pk int, v integer, primary key(pk, v))" 0 + 6 "CREATE TABLE t5(pk int, v integer, primary key(pk))" 0 + 7 "CREATE TABLE t5(pk int primary key, v integer)" 0 + 8 "CREATE TABLE t5(pk inTEger primary key)" 1 + 9 "CREATE TABLE t5(pk inteGEr, primary key(pk))" 1 + 10 "CREATE TABLE t5(pk INTEGER, v integer, primary key(pk))" 1 +} + +# EVIDENCE-OF: R-41444-49665 Other integer type names like "INT" or +# "BIGINT" or "SHORT INTEGER" or "UNSIGNED INTEGER" causes the primary +# key column to behave as an ordinary table column with integer affinity +# and a unique index, not as an alias for the rowid. +# +do_execsql_test 5.4.1 { + CREATE TABLE t6(pk INT primary key); + CREATE TABLE t7(pk BIGINT primary key); + CREATE TABLE t8(pk SHORT INTEGER primary key); + CREATE TABLE t9(pk UNSIGNED INTEGER primary key); +} +do_test e_createtable-5.4.2.1 { is_integer_primary_key t6 pk } 0 +do_test e_createtable-5.4.2.2 { is_integer_primary_key t7 pk } 0 +do_test e_createtable-5.4.2.3 { is_integer_primary_key t8 pk } 0 +do_test e_createtable-5.4.2.4 { is_integer_primary_key t9 pk } 0 + +do_execsql_test 5.4.3 { + INSERT INTO t6 VALUES('2.0'); + INSERT INTO t7 VALUES('2.0'); + INSERT INTO t8 VALUES('2.0'); + INSERT INTO t9 VALUES('2.0'); + SELECT typeof(pk), pk FROM t6; + SELECT typeof(pk), pk FROM t7; + SELECT typeof(pk), pk FROM t8; + SELECT typeof(pk), pk FROM t9; +} {integer 2 integer 2 integer 2 integer 2} + +do_catchsql_test 5.4.4.1 { + INSERT INTO t6 VALUES(2) +} {1 {UNIQUE constraint failed: t6.pk}} +do_catchsql_test 5.4.4.2 { + INSERT INTO t7 VALUES(2) +} {1 {UNIQUE constraint failed: t7.pk}} +do_catchsql_test 5.4.4.3 { + INSERT INTO t8 VALUES(2) +} {1 {UNIQUE constraint failed: t8.pk}} +do_catchsql_test 5.4.4.4 { + INSERT INTO t9 VALUES(2) +} {1 {UNIQUE constraint failed: t9.pk}} + +# EVIDENCE-OF: R-56094-57830 the following three table declarations all +# cause the column "x" to be an alias for the rowid (an integer primary +# key): CREATE TABLE t(x INTEGER PRIMARY KEY ASC, y, z); CREATE TABLE +# t(x INTEGER, y, z, PRIMARY KEY(x ASC)); CREATE TABLE t(x INTEGER, y, +# z, PRIMARY KEY(x DESC)); +# +# EVIDENCE-OF: R-20149-25884 the following declaration does not result +# in "x" being an alias for the rowid: CREATE TABLE t(x INTEGER PRIMARY +# KEY DESC, y, z); +# +do_createtable_tests 5 -tclquery { + is_integer_primary_key t x +} -repair { + catchsql { DROP TABLE t } +} { + 5.1 "CREATE TABLE t(x INTEGER PRIMARY KEY ASC, y, z)" 1 + 5.2 "CREATE TABLE t(x INTEGER, y, z, PRIMARY KEY(x ASC))" 1 + 5.3 "CREATE TABLE t(x INTEGER, y, z, PRIMARY KEY(x DESC))" 1 + 6.1 "CREATE TABLE t(x INTEGER PRIMARY KEY DESC, y, z)" 0 +} + +# EVIDENCE-OF: R-03733-29734 Rowid values may be modified using an +# UPDATE statement in the same way as any other column value can, either +# using one of the built-in aliases ("rowid", "oid" or "_rowid_") or by +# using an alias created by an integer primary key. +# +do_execsql_test 5.7.0 { + CREATE TABLE t10(a, b); + INSERT INTO t10 VALUES('ten', 10); + + CREATE TABLE t11(a, b INTEGER PRIMARY KEY); + INSERT INTO t11 VALUES('ten', 10); +} +do_createtable_tests 5.7.1 -query { + SELECT rowid, _rowid_, oid FROM t10; +} { + 1 "UPDATE t10 SET rowid = 5" {5 5 5} + 2 "UPDATE t10 SET _rowid_ = 6" {6 6 6} + 3 "UPDATE t10 SET oid = 7" {7 7 7} +} +do_createtable_tests 5.7.2 -query { + SELECT rowid, _rowid_, oid, b FROM t11; +} { + 1 "UPDATE t11 SET rowid = 5" {5 5 5 5} + 2 "UPDATE t11 SET _rowid_ = 6" {6 6 6 6} + 3 "UPDATE t11 SET oid = 7" {7 7 7 7} + 4 "UPDATE t11 SET b = 8" {8 8 8 8} +} + +# EVIDENCE-OF: R-58706-14229 Similarly, an INSERT statement may provide +# a value to use as the rowid for each row inserted. +# +do_createtable_tests 5.8.1 -query { + SELECT rowid, _rowid_, oid FROM t10; +} -repair { + execsql { DELETE FROM t10 } +} { + 1 "INSERT INTO t10(oid) VALUES(15)" {15 15 15} + 2 "INSERT INTO t10(rowid) VALUES(16)" {16 16 16} + 3 "INSERT INTO t10(_rowid_) VALUES(17)" {17 17 17} + 4 "INSERT INTO t10(a, b, oid) VALUES(1,2,3)" {3 3 3} +} +do_createtable_tests 5.8.2 -query { + SELECT rowid, _rowid_, oid, b FROM t11; +} -repair { + execsql { DELETE FROM t11 } +} { + 1 "INSERT INTO t11(oid) VALUES(15)" {15 15 15 15} + 2 "INSERT INTO t11(rowid) VALUES(16)" {16 16 16 16} + 3 "INSERT INTO t11(_rowid_) VALUES(17)" {17 17 17 17} + 4 "INSERT INTO t11(a, b) VALUES(1,2)" {2 2 2 2} +} + +# EVIDENCE-OF: R-32326-44592 Unlike normal SQLite columns, an integer +# primary key or rowid column must contain integer values. Integer +# primary key or rowid columns are not able to hold floating point +# values, strings, BLOBs, or NULLs. +# +# This is considered by the tests for the following 3 statements, +# which show that: +# +# 1. Attempts to UPDATE a rowid column to a non-integer value fail, +# 2. Attempts to INSERT a real, string or blob value into a rowid +# column fail, and +# 3. Attempting to INSERT a NULL value into a rowid column causes the +# system to automatically select an integer value to use. +# + + +# EVIDENCE-OF: R-64224-62578 If an UPDATE statement attempts to set an +# integer primary key or rowid column to a NULL or blob value, or to a +# string or real value that cannot be losslessly converted to an +# integer, a "datatype mismatch" error occurs and the statement is +# aborted. +# +drop_all_tables +do_execsql_test 5.9.0 { + CREATE TABLE t12(x INTEGER PRIMARY KEY, y); + INSERT INTO t12 VALUES(5, 'five'); +} +do_createtable_tests 5.9.1 -query { SELECT typeof(x), x FROM t12 } { + 1 "UPDATE t12 SET x = 4" {integer 4} + 2 "UPDATE t12 SET x = 10.0" {integer 10} + 3 "UPDATE t12 SET x = '12.0'" {integer 12} + 4 "UPDATE t12 SET x = '-15.0'" {integer -15} +} +do_createtable_tests 5.9.2 -error { + datatype mismatch +} { + 1 "UPDATE t12 SET x = 4.1" {} + 2 "UPDATE t12 SET x = 'hello'" {} + 3 "UPDATE t12 SET x = NULL" {} + 4 "UPDATE t12 SET x = X'ABCD'" {} + 5 "UPDATE t12 SET x = X'3900'" {} + 6 "UPDATE t12 SET x = X'39'" {} +} + +# EVIDENCE-OF: R-05734-13629 If an INSERT statement attempts to insert a +# blob value, or a string or real value that cannot be losslessly +# converted to an integer into an integer primary key or rowid column, a +# "datatype mismatch" error occurs and the statement is aborted. +# +do_execsql_test 5.10.0 { DELETE FROM t12 } +do_createtable_tests 5.10.1 -error { + datatype mismatch +} { + 1 "INSERT INTO t12(x) VALUES(4.1)" {} + 2 "INSERT INTO t12(x) VALUES('hello')" {} + 3 "INSERT INTO t12(x) VALUES(X'ABCD')" {} + 4 "INSERT INTO t12(x) VALUES(X'3900')" {} + 5 "INSERT INTO t12(x) VALUES(X'39')" {} +} +do_createtable_tests 5.10.2 -query { + SELECT typeof(x), x FROM t12 +} -repair { + execsql { DELETE FROM t12 } +} { + 1 "INSERT INTO t12(x) VALUES(4)" {integer 4} + 2 "INSERT INTO t12(x) VALUES(10.0)" {integer 10} + 3 "INSERT INTO t12(x) VALUES('12.0')" {integer 12} + 4 "INSERT INTO t12(x) VALUES('4e3')" {integer 4000} + 5 "INSERT INTO t12(x) VALUES('-14.0')" {integer -14} +} + +# EVIDENCE-OF: R-07986-46024 If an INSERT statement attempts to insert a +# NULL value into a rowid or integer primary key column, the system +# chooses an integer value to use as the rowid automatically. +# +do_execsql_test 5.11.0 { DELETE FROM t12 } +do_createtable_tests 5.11 -query { + SELECT typeof(x), x FROM t12 WHERE y IS (SELECT max(y) FROM t12) +} { + 1 "INSERT INTO t12 DEFAULT VALUES" {integer 1} + 2 "INSERT INTO t12(y) VALUES(5)" {integer 2} + 3 "INSERT INTO t12(x,y) VALUES(NULL, 10)" {integer 3} + 4 "INSERT INTO t12(x,y) SELECT NULL, 15 FROM t12" + {integer 4 integer 5 integer 6} + 5 "INSERT INTO t12(y) SELECT 20 FROM t12 LIMIT 3" + {integer 7 integer 8 integer 9} +} + +finish_test diff --git a/test/e_delete.test b/test/e_delete.test new file mode 100644 index 0000000..9bd9322 --- /dev/null +++ b/test/e_delete.test @@ -0,0 +1,477 @@ +# 2010 September 21 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file implements tests to verify that the "testable statements" in +# the lang_delete.html document are correct. +# +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !compound { + finish_test + return +} + +proc do_delete_tests {args} { + uplevel do_select_tests $args +} + +do_execsql_test e_delete-0.0 { + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a); +} {} + +# -- syntax diagram delete-stmt +# -- syntax diagram qualified-table-name +# +do_delete_tests e_delete-0.1 { + 1 "DELETE FROM t1" {} + 2 "DELETE FROM t1 INDEXED BY i1" {} + 3 "DELETE FROM t1 NOT INDEXED" {} + 4 "DELETE FROM main.t1" {} + 5 "DELETE FROM main.t1 INDEXED BY i1" {} + 6 "DELETE FROM main.t1 NOT INDEXED" {} + 7 "DELETE FROM t1 WHERE a>2" {} + 8 "DELETE FROM t1 INDEXED BY i1 WHERE a>2" {} + 9 "DELETE FROM t1 NOT INDEXED WHERE a>2" {} + 10 "DELETE FROM main.t1 WHERE a>2" {} + 11 "DELETE FROM main.t1 INDEXED BY i1 WHERE a>2" {} + 12 "DELETE FROM main.t1 NOT INDEXED WHERE a>2" {} +} + +# EVIDENCE-OF: R-20205-17349 If the WHERE clause is not present, all +# records in the table are deleted. +# +drop_all_tables +do_test e_delete-1.0 { + db transaction { + foreach t {t1 t2 t3 t4 t5 t6} { + execsql [string map [list %T% $t] { + CREATE TABLE %T%(x, y); + INSERT INTO %T% VALUES(1, 'one'); + INSERT INTO %T% VALUES(2, 'two'); + INSERT INTO %T% VALUES(3, 'three'); + INSERT INTO %T% VALUES(4, 'four'); + INSERT INTO %T% VALUES(5, 'five'); + }] + } + } +} {} +do_delete_tests e_delete-1.1 { + 1 "DELETE FROM t1 ; SELECT * FROM t1" {} + 2 "DELETE FROM main.t2 ; SELECT * FROM t2" {} +} + +# EVIDENCE-OF: R-26300-50198 If a WHERE clause is supplied, then only +# those rows for which the WHERE clause boolean expression is true are +# deleted. +# +# EVIDENCE-OF: R-23360-48280 Rows for which the expression is false or +# NULL are retained. +# +do_delete_tests e_delete-1.2 { + 1 "DELETE FROM t3 WHERE 1 ; SELECT x FROM t3" {} + 2 "DELETE FROM main.t4 WHERE 0 ; SELECT x FROM t4" {1 2 3 4 5} + 3 "DELETE FROM t4 WHERE 0.0 ; SELECT x FROM t4" {1 2 3 4 5} + 4 "DELETE FROM t4 WHERE NULL ; SELECT x FROM t4" {1 2 3 4 5} + 5 "DELETE FROM t4 WHERE y!='two'; SELECT x FROM t4" {2} + 6 "DELETE FROM t4 WHERE y='two' ; SELECT x FROM t4" {} + 7 "DELETE FROM t5 WHERE x=(SELECT max(x) FROM t5);SELECT x FROM t5" {1 2 3 4} + 8 "DELETE FROM t5 WHERE (SELECT max(x) FROM t4) ;SELECT x FROM t5" {1 2 3 4} + 9 "DELETE FROM t5 WHERE (SELECT max(x) FROM t6) ;SELECT x FROM t5" {} + 10 "DELETE FROM t6 WHERE y>'seven' ; SELECT y FROM t6" {one four five} +} + + +#------------------------------------------------------------------------- +# Tests for restrictions on DELETE statements that appear within trigger +# programs. +# +forcedelete test.db2 +forcedelete test.db3 +do_execsql_test e_delete-2.0 { + ATTACH 'test.db2' AS aux; + ATTACH 'test.db3' AS aux2; + + CREATE TABLE temp.t7(a, b); INSERT INTO temp.t7 VALUES(1, 2); + CREATE TABLE main.t7(a, b); INSERT INTO main.t7 VALUES(3, 4); + CREATE TABLE aux.t7(a, b); INSERT INTO aux.t7 VALUES(5, 6); + CREATE TABLE aux2.t7(a, b); INSERT INTO aux2.t7 VALUES(7, 8); + + CREATE TABLE main.t8(a, b); INSERT INTO main.t8 VALUES(1, 2); + CREATE TABLE aux.t8(a, b); INSERT INTO aux.t8 VALUES(3, 4); + CREATE TABLE aux2.t8(a, b); INSERT INTO aux2.t8 VALUES(5, 6); + + CREATE TABLE aux.t9(a, b); INSERT INTO aux.t9 VALUES(1, 2); + CREATE TABLE aux2.t9(a, b); INSERT INTO aux2.t9 VALUES(3, 4); + + CREATE TABLE aux2.t10(a, b); INSERT INTO aux2.t10 VALUES(1, 2); +} {} + + +# EVIDENCE-OF: R-09681-58560 The table-name specified as part of a +# DELETE statement within a trigger body must be unqualified. +# +# EVIDENCE-OF: R-12275-20298 In other words, the schema-name. prefix on +# the table name is not allowed within triggers. +# +do_delete_tests e_delete-2.1 -error { + qualified table names are not allowed on INSERT, UPDATE, and DELETE statements within triggers +} { + 1 { + CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN + DELETE FROM main.t2; + END; + } {} + + 2 { + CREATE TRIGGER tr1 BEFORE UPDATE ON t2 BEGIN + DELETE FROM temp.t7 WHERE a=new.a; + END; + } {} + + 3 { + CREATE TRIGGER tr1 AFTER UPDATE ON t8 BEGIN + DELETE FROM aux2.t8 WHERE b!=a; + END; + } {} +} + +# EVIDENCE-OF: R-28818-63526 If the table to which the trigger is +# attached is not in the temp database, then DELETE statements within +# the trigger body must operate on tables within the same database as +# it. +# +# This is tested in two parts. First, check that if a table of the +# specified name does not exist, an error is raised. Secondly, test +# that if tables with the specified name exist in multiple databases, +# the local database table is used. +# +do_delete_tests e_delete-2.2.1 -error { no such table: %s } { + 1 { + CREATE TRIGGER main.tr1 AFTER INSERT ON main.t7 BEGIN + DELETE FROM t9; + END; + INSERT INTO main.t7 VALUES(1, 2); + } {main.t9} + + 2 { + CREATE TRIGGER aux.tr2 BEFORE UPDATE ON t9 BEGIN + DELETE FROM t10; + END; + UPDATE t9 SET a=1; + } {aux.t10} +} +do_execsql_test e_delete-2.2.X { + DROP TRIGGER main.tr1; + DROP TRIGGER aux.tr2; +} {} + +do_delete_tests e_delete-2.2.2 { + 1 { + CREATE TRIGGER aux.tr1 AFTER INSERT ON t8 BEGIN + DELETE FROM t9; + END; + INSERT INTO aux.t8 VALUES(1, 2); + + SELECT count(*) FROM aux.t9 + UNION ALL + SELECT count(*) FROM aux2.t9; + } {0 1} + + 2 { + CREATE TRIGGER main.tr1 AFTER INSERT ON t8 BEGIN + DELETE FROM t7; + END; + INSERT INTO main.t8 VALUES(1, 2); + + SELECT count(*) FROM temp.t7 + UNION ALL + SELECT count(*) FROM main.t7 + UNION ALL + SELECT count(*) FROM aux.t7 + UNION ALL + SELECT count(*) FROM aux2.t7; + } {1 0 1 1} +} + +# EVIDENCE-OF: R-31567-38587 If the table to which the trigger is +# attached is in the TEMP database, then the unqualified name of the +# table being deleted is resolved in the same way as it is for a +# top-level statement (by searching first the TEMP database, then the +# main database, then any other databases in the order they were +# attached). +# +do_execsql_test e_delete-2.3.0 { + DROP TRIGGER aux.tr1; + DROP TRIGGER main.tr1; + DELETE FROM main.t8 WHERE oid>1; + DELETE FROM aux.t8 WHERE oid>1; + INSERT INTO aux.t9 VALUES(1, 2); + INSERT INTO main.t7 VALUES(3, 4); +} {} +do_execsql_test e_delete-2.3.1 { + SELECT count(*) FROM temp.t7 UNION ALL SELECT count(*) FROM main.t7 UNION ALL + SELECT count(*) FROM aux.t7 UNION ALL SELECT count(*) FROM aux2.t7; + + SELECT count(*) FROM main.t8 UNION ALL SELECT count(*) FROM aux.t8 + UNION ALL SELECT count(*) FROM aux2.t8; + + SELECT count(*) FROM aux.t9 UNION ALL SELECT count(*) FROM aux2.t9; + + SELECT count(*) FROM aux2.t10; +} {1 1 1 1 1 1 1 1 1 1} +do_execsql_test e_delete-2.3.2 { + CREATE TRIGGER temp.tr1 AFTER INSERT ON t7 BEGIN + DELETE FROM t7; + DELETE FROM t8; + DELETE FROM t9; + DELETE FROM t10; + END; + INSERT INTO temp.t7 VALUES('hello', 'world'); +} {} +do_execsql_test e_delete-2.3.3 { + SELECT count(*) FROM temp.t7 UNION ALL SELECT count(*) FROM main.t7 UNION ALL + SELECT count(*) FROM aux.t7 UNION ALL SELECT count(*) FROM aux2.t7; + + SELECT count(*) FROM main.t8 UNION ALL SELECT count(*) FROM aux.t8 + UNION ALL SELECT count(*) FROM aux2.t8; + + SELECT count(*) FROM aux.t9 UNION ALL SELECT count(*) FROM aux2.t9; + + SELECT count(*) FROM aux2.t10; +} {0 1 1 1 0 1 1 0 1 0} + +# EVIDENCE-OF: R-28691-49464 The INDEXED BY and NOT INDEXED clauses are +# not allowed on DELETE statements within triggers. +# +do_execsql_test e_delete-2.4.0 { + CREATE INDEX i8 ON t8(a, b); +} {} +do_delete_tests e_delete-2.4 -error { + the %s %s clause is not allowed on UPDATE or DELETE statements within triggers +} { + 1 { + CREATE TRIGGER tr3 AFTER INSERT ON t8 BEGIN + DELETE FROM t8 INDEXED BY i8 WHERE a=5; + END; + } {INDEXED BY} + 2 { + CREATE TRIGGER tr3 AFTER INSERT ON t8 BEGIN + DELETE FROM t8 NOT INDEXED WHERE a=5; + END; + } {NOT INDEXED} +} + +ifcapable update_delete_limit { + +# EVIDENCE-OF: R-64942-06615 The LIMIT and ORDER BY clauses (described +# below) are unsupported for DELETE statements within triggers. +# +do_delete_tests e_delete-2.5 -error { near "%s": syntax error } { + 1 { + CREATE TRIGGER tr3 AFTER INSERT ON t8 BEGIN + DELETE FROM t8 LIMIT 10; + END; + } {LIMIT} + 2 { + CREATE TRIGGER tr3 AFTER INSERT ON t8 BEGIN + DELETE FROM t8 ORDER BY a LIMIT 5; + END; + } {ORDER} +} + +# EVIDENCE-OF: R-40026-10531 If SQLite is compiled with the +# SQLITE_ENABLE_UPDATE_DELETE_LIMIT compile-time option, then the syntax +# of the DELETE statement is extended by the addition of optional ORDER +# BY and LIMIT clauses: +# +# -- syntax diagram delete-stmt-limited +# +do_delete_tests e_delete-3.1 { + 1 "DELETE FROM t1 LIMIT 5" {} + 2 "DELETE FROM t1 LIMIT 5-1 OFFSET 2+2" {} + 3 "DELETE FROM t1 LIMIT 2+2, 16/4" {} + 4 "DELETE FROM t1 ORDER BY x LIMIT 5" {} + 5 "DELETE FROM t1 ORDER BY x LIMIT 5-1 OFFSET 2+2" {} + 6 "DELETE FROM t1 ORDER BY x LIMIT 2+2, 16/4" {} + 7 "DELETE FROM t1 WHERE x>2 LIMIT 5" {} + 8 "DELETE FROM t1 WHERE x>2 LIMIT 5-1 OFFSET 2+2" {} + 9 "DELETE FROM t1 WHERE x>2 LIMIT 2+2, 16/4" {} + 10 "DELETE FROM t1 WHERE x>2 ORDER BY x LIMIT 5" {} + 11 "DELETE FROM t1 WHERE x>2 ORDER BY x LIMIT 5-1 OFFSET 2+2" {} + 12 "DELETE FROM t1 WHERE x>2 ORDER BY x LIMIT 2+2, 16/4" {} +} + +drop_all_tables +proc rebuild_t1 {} { + catchsql { DROP TABLE t1 } + execsql { + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 'one'); + INSERT INTO t1 VALUES(2, 'two'); + INSERT INTO t1 VALUES(3, 'three'); + INSERT INTO t1 VALUES(4, 'four'); + INSERT INTO t1 VALUES(5, 'five'); + } +} + +# EVIDENCE-OF: R-44062-08550 If a DELETE statement has a LIMIT clause, +# the maximum number of rows that will be deleted is found by evaluating +# the accompanying expression and casting it to an integer value. +# +rebuild_t1 +do_delete_tests e_delete-3.2 -repair rebuild_t1 -query { + SELECT a FROM t1 +} { + 1 "DELETE FROM t1 LIMIT 3" {4 5} + 2 "DELETE FROM t1 LIMIT 1+1" {3 4 5} + 3 "DELETE FROM t1 LIMIT '4'" {5} + 4 "DELETE FROM t1 LIMIT '1.0'" {2 3 4 5} +} + +# EVIDENCE-OF: R-02661-56399 If the result of the evaluating the LIMIT +# clause cannot be losslessly converted to an integer value, it is an +# error. +# +do_delete_tests e_delete-3.3 -error { datatype mismatch } { + 1 "DELETE FROM t1 LIMIT 'abc'" {} + 2 "DELETE FROM t1 LIMIT NULL" {} + 3 "DELETE FROM t1 LIMIT X'ABCD'" {} + 4 "DELETE FROM t1 LIMIT 1.2" {} +} + +# EVIDENCE-OF: R-00598-03741 A negative LIMIT value is interpreted as +# "no limit". +# +do_delete_tests e_delete-3.4 -repair rebuild_t1 -query { + SELECT a FROM t1 +} { + 1 "DELETE FROM t1 LIMIT -1" {} + 2 "DELETE FROM t1 LIMIT 2-4" {} + 3 "DELETE FROM t1 LIMIT -4.0" {} + 4 "DELETE FROM t1 LIMIT 5*-1" {} +} + +# EVIDENCE-OF: R-26377-49195 If the DELETE statement also has an OFFSET +# clause, then it is similarly evaluated and cast to an integer value. +# Again, it is an error if the value cannot be losslessly converted to +# an integer. +# +do_delete_tests e_delete-3.5 -error { datatype mismatch } { + 1 "DELETE FROM t1 LIMIT 1 OFFSET 'abc'" {} + 2 "DELETE FROM t1 LIMIT 1 OFFSET NULL" {} + 3 "DELETE FROM t1 LIMIT 1 OFFSET X'ABCD'" {} + 4 "DELETE FROM t1 LIMIT 1 OFFSET 1.2" {} + 5 "DELETE FROM t1 LIMIT 'abc', 1" {} + 6 "DELETE FROM t1 LIMIT NULL, 1" {} + 7 "DELETE FROM t1 LIMIT X'ABCD', 1" {} + 8 "DELETE FROM t1 LIMIT 1.2, 1" {} +} + + +# EVIDENCE-OF: R-64004-53814 If there is no OFFSET clause, or the +# calculated integer value is negative, the effective OFFSET value is +# zero. +# +do_delete_tests e_delete-3.6 -repair rebuild_t1 -query { + SELECT a FROM t1 +} { + 1a "DELETE FROM t1 LIMIT 3 OFFSET 0" {4 5} + 1b "DELETE FROM t1 LIMIT 3" {4 5} + 1c "DELETE FROM t1 LIMIT 3 OFFSET -1" {4 5} + 2a "DELETE FROM t1 LIMIT 1+1 OFFSET 0" {3 4 5} + 2b "DELETE FROM t1 LIMIT 1+1" {3 4 5} + 2c "DELETE FROM t1 LIMIT 1+1 OFFSET 2-5" {3 4 5} + 3a "DELETE FROM t1 LIMIT '4' OFFSET 0" {5} + 3b "DELETE FROM t1 LIMIT '4'" {5} + 3c "DELETE FROM t1 LIMIT '4' OFFSET -1.0" {5} + 4a "DELETE FROM t1 LIMIT '1.0' OFFSET 0" {2 3 4 5} + 4b "DELETE FROM t1 LIMIT '1.0'" {2 3 4 5} + 4c "DELETE FROM t1 LIMIT '1.0' OFFSET -11" {2 3 4 5} +} + +# EVIDENCE-OF: R-48141-52334 If the DELETE statement has an ORDER BY +# clause, then all rows that would be deleted in the absence of the +# LIMIT clause are sorted according to the ORDER BY. The first M rows, +# where M is the value found by evaluating the OFFSET clause expression, +# are skipped, and the following N, where N is the value of the LIMIT +# expression, are deleted. +# +do_delete_tests e_delete-3.7 -repair rebuild_t1 -query { + SELECT a FROM t1 +} { + 1 "DELETE FROM t1 ORDER BY b LIMIT 2" {1 2 3} + 2 "DELETE FROM t1 ORDER BY length(b), a LIMIT 3" {3 5} + 3 "DELETE FROM t1 ORDER BY a DESC LIMIT 1 OFFSET 0" {1 2 3 4} + 4 "DELETE FROM t1 ORDER BY a DESC LIMIT 1 OFFSET 1" {1 2 3 5} + 5 "DELETE FROM t1 ORDER BY a DESC LIMIT 1 OFFSET 2" {1 2 4 5} +} + +# EVIDENCE-OF: R-64535-08414 If there are less than N rows remaining +# after taking the OFFSET clause into account, or if the LIMIT clause +# evaluated to a negative value, then all remaining rows are deleted. +# +do_delete_tests e_delete-3.8 -repair rebuild_t1 -query { + SELECT a FROM t1 +} { + 1 "DELETE FROM t1 ORDER BY a ASC LIMIT 10" {} + 2 "DELETE FROM t1 ORDER BY a ASC LIMIT -1" {} + 3 "DELETE FROM t1 ORDER BY a ASC LIMIT 4 OFFSET 2" {1 2} +} + +# EVIDENCE-OF: R-37284-06965 If the DELETE statement has no ORDER BY +# clause, then all rows that would be deleted in the absence of the +# LIMIT clause are assembled in an arbitrary order before applying the +# LIMIT and OFFSET clauses to determine the subset that are actually +# deleted. +# +# In practice, the "arbitrary order" is rowid order. +# +do_delete_tests e_delete-3.9 -repair rebuild_t1 -query { + SELECT a FROM t1 +} { + 1 "DELETE FROM t1 LIMIT 2" {3 4 5} + 2 "DELETE FROM t1 LIMIT 3" {4 5} + 3 "DELETE FROM t1 LIMIT 1 OFFSET 0" {2 3 4 5} + 4 "DELETE FROM t1 LIMIT 1 OFFSET 1" {1 3 4 5} + 5 "DELETE FROM t1 LIMIT 1 OFFSET 2" {1 2 4 5} +} + + +# EVIDENCE-OF: R-07548-13422 The ORDER BY clause on a DELETE statement +# is used only to determine which rows fall within the LIMIT. The order +# in which rows are deleted is arbitrary and is not influenced by the +# ORDER BY clause. +# +# In practice, rows are always deleted in rowid order. +# +do_delete_tests e_delete-3.10 -repair { + rebuild_t1 + catchsql { DROP TABLE t1log } + execsql { + CREATE TABLE t1log(x); + CREATE TRIGGER tr1 AFTER DELETE ON t1 BEGIN + INSERT INTO t1log VALUES(old.a); + END; + } +} -query { + SELECT x FROM t1log +} { + 1 "DELETE FROM t1 ORDER BY a DESC LIMIT 2" {4 5} + 2 "DELETE FROM t1 ORDER BY a DESC LIMIT -1" {1 2 3 4 5} + 3 "DELETE FROM t1 ORDER BY a ASC LIMIT 2" {1 2} + 4 "DELETE FROM t1 ORDER BY a ASC LIMIT -1" {1 2 3 4 5} +} + +} + +finish_test diff --git a/test/e_droptrigger.test b/test/e_droptrigger.test new file mode 100644 index 0000000..5cd5d0a --- /dev/null +++ b/test/e_droptrigger.test @@ -0,0 +1,218 @@ +# 2010 November 29 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file implements tests to verify that the "testable statements" in +# the lang_droptrigger.html document are correct. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix e_droptrigger + +ifcapable !trigger { finish_test ; return } + +proc do_droptrigger_tests {nm args} { + uplevel do_select_tests [list e_createtable-$nm] $args +} + +proc list_all_triggers {{db db}} { + set res [list] + $db eval { PRAGMA database_list } { + if {$name == "temp"} { + set tbl sqlite_temp_master + } else { + set tbl "$name.sqlite_master" + } + lappend res {*}[ + db eval "SELECT '$name.' || name FROM $tbl WHERE type = 'trigger'" + ] + } + set res +} + + +proc droptrigger_reopen_db {{event INSERT}} { + db close + forcedelete test.db test.db2 + sqlite3 db test.db + + set ::triggers_fired [list] + proc r {x} { lappend ::triggers_fired $x } + db func r r + + db eval " + ATTACH 'test.db2' AS aux; + + CREATE TEMP TABLE t1(a, b); + INSERT INTO t1 VALUES('a', 'b'); + CREATE TRIGGER tr1 AFTER $event ON t1 BEGIN SELECT r('temp.tr1') ; END; + + CREATE TABLE t2(a, b); + INSERT INTO t2 VALUES('a', 'b'); + CREATE TRIGGER tr1 BEFORE $event ON t2 BEGIN SELECT r('main.tr1') ; END; + CREATE TRIGGER tr2 AFTER $event ON t2 BEGIN SELECT r('main.tr2') ; END; + + CREATE TABLE aux.t3(a, b); + INSERT INTO t3 VALUES('a', 'b'); + CREATE TRIGGER aux.tr1 BEFORE $event ON t3 BEGIN SELECT r('aux.tr1') ; END; + CREATE TRIGGER aux.tr2 AFTER $event ON t3 BEGIN SELECT r('aux.tr2') ; END; + CREATE TRIGGER aux.tr3 AFTER $event ON t3 BEGIN SELECT r('aux.tr3') ; END; + " +} + + +# -- syntax diagram drop-trigger-stmt +# +do_droptrigger_tests 1.1 -repair { + droptrigger_reopen_db +} -tclquery { + list_all_triggers +} { + 1 "DROP TRIGGER main.tr1" + {main.tr2 temp.tr1 aux.tr1 aux.tr2 aux.tr3} + 2 "DROP TRIGGER IF EXISTS main.tr1" + {main.tr2 temp.tr1 aux.tr1 aux.tr2 aux.tr3} + 3 "DROP TRIGGER tr1" + {main.tr1 main.tr2 aux.tr1 aux.tr2 aux.tr3} + 4 "DROP TRIGGER IF EXISTS tr1" + {main.tr1 main.tr2 aux.tr1 aux.tr2 aux.tr3} + + 5 "DROP TRIGGER aux.tr1" + {main.tr1 main.tr2 temp.tr1 aux.tr2 aux.tr3} + 6 "DROP TRIGGER IF EXISTS aux.tr1" + {main.tr1 main.tr2 temp.tr1 aux.tr2 aux.tr3} + + 7 "DROP TRIGGER IF EXISTS aux.xxx" + {main.tr1 main.tr2 temp.tr1 aux.tr1 aux.tr2 aux.tr3} + 8 "DROP TRIGGER IF EXISTS aux.xxx" + {main.tr1 main.tr2 temp.tr1 aux.tr1 aux.tr2 aux.tr3} +} + +# EVIDENCE-OF: R-61172-15671 The DROP TRIGGER statement removes a +# trigger created by the CREATE TRIGGER statement. +# +foreach {tn tbl droptrigger before after} { + 1 t1 "DROP TRIGGER tr1" {temp.tr1} {} + 2 t2 "DROP TRIGGER tr1" {main.tr1 main.tr2} {main.tr1 main.tr2} + 3 t3 "DROP TRIGGER tr1" {aux.tr1 aux.tr3 aux.tr2} {aux.tr1 aux.tr3 aux.tr2} + + 4 t1 "DROP TRIGGER tr2" {temp.tr1} {temp.tr1} + 5 t2 "DROP TRIGGER tr2" {main.tr1 main.tr2} {main.tr1} + 6 t3 "DROP TRIGGER tr2" {aux.tr1 aux.tr3 aux.tr2} {aux.tr1 aux.tr3 aux.tr2} + + 7 t1 "DROP TRIGGER tr3" {temp.tr1} {temp.tr1} + 8 t2 "DROP TRIGGER tr3" {main.tr1 main.tr2} {main.tr1 main.tr2} + 9 t3 "DROP TRIGGER tr3" {aux.tr1 aux.tr3 aux.tr2} {aux.tr1 aux.tr2} +} { + + do_test 2.$tn.1 { + droptrigger_reopen_db + execsql " INSERT INTO $tbl VALUES('1', '2') " + set ::triggers_fired + } $before + + do_test 2.$tn.2 { + droptrigger_reopen_db + execsql $droptrigger + execsql " INSERT INTO $tbl VALUES('1', '2') " + set ::triggers_fired + } $after +} + +# EVIDENCE-OF: R-04950-25529 Once removed, the trigger definition is no +# longer present in the sqlite_schema (or sqlite_temp_schema) table and +# is not fired by any subsequent INSERT, UPDATE or DELETE statements. +# +# Test cases e_droptrigger-1.* test the first part of this statement +# (that dropped triggers do not appear in the schema table), and tests +# droptrigger-2.* test that dropped triggers are not fired by INSERT +# statements. The following tests verify that they are not fired by +# UPDATE or DELETE statements. +# +foreach {tn tbl droptrigger before after} { + 1 t1 "DROP TRIGGER tr1" {temp.tr1} {} + 2 t2 "DROP TRIGGER tr1" {main.tr1 main.tr2} {main.tr1 main.tr2} + 3 t3 "DROP TRIGGER tr1" {aux.tr1 aux.tr3 aux.tr2} {aux.tr1 aux.tr3 aux.tr2} + + 4 t1 "DROP TRIGGER tr2" {temp.tr1} {temp.tr1} + 5 t2 "DROP TRIGGER tr2" {main.tr1 main.tr2} {main.tr1} + 6 t3 "DROP TRIGGER tr2" {aux.tr1 aux.tr3 aux.tr2} {aux.tr1 aux.tr3 aux.tr2} + + 7 t1 "DROP TRIGGER tr3" {temp.tr1} {temp.tr1} + 8 t2 "DROP TRIGGER tr3" {main.tr1 main.tr2} {main.tr1 main.tr2} + 9 t3 "DROP TRIGGER tr3" {aux.tr1 aux.tr3 aux.tr2} {aux.tr1 aux.tr2} +} { + + do_test 3.1.$tn.1 { + droptrigger_reopen_db UPDATE + execsql "UPDATE $tbl SET a = 'abc'" + set ::triggers_fired + } $before + + do_test 3.1.$tn.2 { + droptrigger_reopen_db UPDATE + execsql $droptrigger + execsql "UPDATE $tbl SET a = 'abc'" + set ::triggers_fired + } $after +} +foreach {tn tbl droptrigger before after} { + 1 t1 "DROP TRIGGER tr1" {temp.tr1} {} + 2 t2 "DROP TRIGGER tr1" {main.tr1 main.tr2} {main.tr1 main.tr2} + 3 t3 "DROP TRIGGER tr1" {aux.tr1 aux.tr3 aux.tr2} {aux.tr1 aux.tr3 aux.tr2} + + 4 t1 "DROP TRIGGER tr2" {temp.tr1} {temp.tr1} + 5 t2 "DROP TRIGGER tr2" {main.tr1 main.tr2} {main.tr1} + 6 t3 "DROP TRIGGER tr2" {aux.tr1 aux.tr3 aux.tr2} {aux.tr1 aux.tr3 aux.tr2} + + 7 t1 "DROP TRIGGER tr3" {temp.tr1} {temp.tr1} + 8 t2 "DROP TRIGGER tr3" {main.tr1 main.tr2} {main.tr1 main.tr2} + 9 t3 "DROP TRIGGER tr3" {aux.tr1 aux.tr3 aux.tr2} {aux.tr1 aux.tr2} +} { + + do_test 3.2.$tn.1 { + droptrigger_reopen_db DELETE + execsql "DELETE FROM $tbl" + set ::triggers_fired + } $before + + do_test 3.2.$tn.2 { + droptrigger_reopen_db DELETE + execsql $droptrigger + execsql "DELETE FROM $tbl" + set ::triggers_fired + } $after +} + +# EVIDENCE-OF: R-37808-62273 Note that triggers are automatically +# dropped when the associated table is dropped. +# +do_test 4.1 { + droptrigger_reopen_db + list_all_triggers +} {main.tr1 main.tr2 temp.tr1 aux.tr1 aux.tr2 aux.tr3} +do_test 4.2 { + droptrigger_reopen_db + execsql "DROP TABLE t1" + list_all_triggers +} {main.tr1 main.tr2 aux.tr1 aux.tr2 aux.tr3} +do_test 4.3 { + droptrigger_reopen_db + execsql "DROP TABLE t1" + list_all_triggers +} {main.tr1 main.tr2 aux.tr1 aux.tr2 aux.tr3} +do_test 4.4 { + droptrigger_reopen_db + execsql "DROP TABLE t1" + list_all_triggers +} {main.tr1 main.tr2 aux.tr1 aux.tr2 aux.tr3} + +finish_test diff --git a/test/e_dropview.test b/test/e_dropview.test new file mode 100644 index 0000000..00f59dd --- /dev/null +++ b/test/e_dropview.test @@ -0,0 +1,192 @@ +# 2010 November 30 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file implements tests to verify that the "testable statements" in +# the lang_dropview.html document are correct. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix e_dropview + +proc dropview_reopen_db {} { + db close + forcedelete test.db test.db2 + sqlite3 db test.db + + db eval { + ATTACH 'test.db2' AS aux; + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES('a main', 'b main'); + CREATE VIEW v1 AS SELECT * FROM t1; + CREATE VIEW v2 AS SELECT * FROM t1; + + CREATE TEMP TABLE t1(a, b); + INSERT INTO temp.t1 VALUES('a temp', 'b temp'); + CREATE VIEW temp.v1 AS SELECT * FROM t1; + + CREATE TABLE aux.t1(a, b); + INSERT INTO aux.t1 VALUES('a aux', 'b aux'); + CREATE VIEW aux.v1 AS SELECT * FROM t1; + CREATE VIEW aux.v2 AS SELECT * FROM t1; + CREATE VIEW aux.v3 AS SELECT * FROM t1; + } +} + +proc list_all_views {{db db}} { + set res [list] + $db eval { PRAGMA database_list } { + set tbl "$name.sqlite_master" + if {$name == "temp"} { set tbl temp.sqlite_master } + + set sql "SELECT '$name.' || name FROM $tbl WHERE type = 'view'" + lappend res {*}[$db eval $sql] + } + set res +} + +proc list_all_data {{db db}} { + set res [list] + $db eval { PRAGMA database_list } { + set tbl "$name.sqlite_master" + if {$name == "temp"} { set tbl sqlite_temp_master } + + db eval "SELECT '$name.' || name AS x FROM $tbl WHERE type = 'table'" { + lappend res [list $x [db eval "SELECT * FROM $x"]] + } + } + set res +} + +proc do_dropview_tests {nm args} { + uplevel do_select_tests $nm $args +} + +# -- syntax diagram drop-view-stmt +# +# All paths in the syntax diagram for DROP VIEW are tested by tests 1.*. +# +do_dropview_tests 1 -repair { + dropview_reopen_db +} -tclquery { + list_all_views +} { + 1 "DROP VIEW v1" {main.v1 main.v2 aux.v1 aux.v2 aux.v3} + 2 "DROP VIEW v2" {main.v1 temp.v1 aux.v1 aux.v2 aux.v3} + 3 "DROP VIEW main.v1" {main.v2 temp.v1 aux.v1 aux.v2 aux.v3} + 4 "DROP VIEW main.v2" {main.v1 temp.v1 aux.v1 aux.v2 aux.v3} + 5 "DROP VIEW IF EXISTS v1" {main.v1 main.v2 aux.v1 aux.v2 aux.v3} + 6 "DROP VIEW IF EXISTS v2" {main.v1 temp.v1 aux.v1 aux.v2 aux.v3} + 7 "DROP VIEW IF EXISTS main.v1" {main.v2 temp.v1 aux.v1 aux.v2 aux.v3} + 8 "DROP VIEW IF EXISTS main.v2" {main.v1 temp.v1 aux.v1 aux.v2 aux.v3} +} + +# EVIDENCE-OF: R-27002-52307 The DROP VIEW statement removes a view +# created by the CREATE VIEW statement. +# +dropview_reopen_db +do_execsql_test 2.1 { + CREATE VIEW "new view" AS SELECT * FROM t1 AS x, t1 AS y; + SELECT * FROM "new view"; +} {{a main} {b main} {a main} {b main}} +do_execsql_test 2.2 {; + SELECT * FROM sqlite_master WHERE name = 'new view'; +} { + view {new view} {new view} 0 + {CREATE VIEW "new view" AS SELECT * FROM t1 AS x, t1 AS y} +} +do_execsql_test 2.3 { + DROP VIEW "new view"; + SELECT * FROM sqlite_master WHERE name = 'new view'; +} {} +do_catchsql_test 2.4 { + SELECT * FROM "new view" +} {1 {no such table: new view}} + +# EVIDENCE-OF: R-00359-41639 The view definition is removed from the +# database schema, but no actual data in the underlying base tables is +# modified. +# +# For each view in the database, check that it can be queried. Then drop +# it. Check that it can no longer be queried and is no longer listed +# in any schema table. Then check that the contents of the db tables have +# not changed +# +set databasedata [list_all_data] + +do_execsql_test 3.1.0 { SELECT * FROM temp.v1 } {{a temp} {b temp}} +do_execsql_test 3.1.1 { DROP VIEW temp.v1 } {} +do_catchsql_test 3.1.2 { SELECT * FROM temp.v1 } {1 {no such table: temp.v1}} +do_test 3.1.3 { list_all_views } {main.v1 main.v2 aux.v1 aux.v2 aux.v3} +do_test 3.1.4 { string compare [list_all_data] $databasedata } 0 + +do_execsql_test 3.2.0 { SELECT * FROM v1 } {{a main} {b main}} +do_execsql_test 3.2.1 { DROP VIEW v1 } {} +do_catchsql_test 3.2.2 { SELECT * FROM main.v1 } {1 {no such table: main.v1}} +do_test 3.2.3 { list_all_views } {main.v2 aux.v1 aux.v2 aux.v3} +do_test 3.2.4 { string compare [list_all_data] $databasedata } 0 + +do_execsql_test 3.3.0 { SELECT * FROM v2 } {{a main} {b main}} +do_execsql_test 3.3.1 { DROP VIEW v2 } {} +do_catchsql_test 3.3.2 { SELECT * FROM main.v2 } {1 {no such table: main.v2}} +do_test 3.3.3 { list_all_views } {aux.v1 aux.v2 aux.v3} +do_test 3.3.4 { string compare [list_all_data] $databasedata } 0 + +do_execsql_test 3.4.0 { SELECT * FROM v1 } {{a aux} {b aux}} +do_execsql_test 3.4.1 { DROP VIEW v1 } {} +do_catchsql_test 3.4.2 { SELECT * FROM v1 } {1 {no such table: v1}} +do_test 3.4.3 { list_all_views } {aux.v2 aux.v3} +do_test 3.4.4 { string compare [list_all_data] $databasedata } 0 + +do_execsql_test 3.5.0 { SELECT * FROM aux.v2 } {{a aux} {b aux}} +do_execsql_test 3.5.1 { DROP VIEW aux.v2 } {} +do_catchsql_test 3.5.2 { SELECT * FROM aux.v2 } {1 {no such table: aux.v2}} +do_test 3.5.3 { list_all_views } {aux.v3} +do_test 3.5.4 { string compare [list_all_data] $databasedata } 0 + +do_execsql_test 3.6.0 { SELECT * FROM v3 } {{a aux} {b aux}} +do_execsql_test 3.6.1 { DROP VIEW v3 } {} +do_catchsql_test 3.6.2 { SELECT * FROM v3 } {1 {no such table: v3}} +do_test 3.6.3 { list_all_views } {} +do_test 3.6.4 { string compare [list_all_data] $databasedata } 0 + +# EVIDENCE-OF: R-25558-37487 If the specified view cannot be found and +# the IF EXISTS clause is not present, it is an error. +# +do_dropview_tests 4 -repair { + dropview_reopen_db +} -errorformat { + no such view: %s +} { + 1 "DROP VIEW xx" xx + 2 "DROP VIEW main.xx" main.xx + 3 "DROP VIEW temp.v2" temp.v2 +} + +# EVIDENCE-OF: R-07490-32536 If the specified view cannot be found and +# an IF EXISTS clause is present in the DROP VIEW statement, then the +# statement is a no-op. +# +do_dropview_tests 5 -repair { + dropview_reopen_db +} -tclquery { + list_all_views + #expr {[list_all_views] == "main.v1 main.v2 temp.v1 aux.v1 aux.v2 aux.v3"} +} { + 1 "DROP VIEW IF EXISTS xx" "main.v1 main.v2 temp.v1 aux.v1 aux.v2 aux.v3" + 2 "DROP VIEW IF EXISTS main.xx" "main.v1 main.v2 temp.v1 aux.v1 aux.v2 aux.v3" + 3 "DROP VIEW IF EXISTS temp.v2" "main.v1 main.v2 temp.v1 aux.v1 aux.v2 aux.v3" +} + + + + +finish_test diff --git a/test/e_expr.test b/test/e_expr.test new file mode 100644 index 0000000..0db63a8 --- /dev/null +++ b/test/e_expr.test @@ -0,0 +1,1989 @@ +# 2010 July 16 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file implements tests to verify that the "testable statements" in +# the lang_expr.html document are correct. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/malloc_common.tcl + +ifcapable !compound { + finish_test + return +} + +proc do_expr_test {tn expr type value} { + uplevel do_execsql_test $tn [list "SELECT typeof($expr), $expr"] [ + list [list $type $value] + ] +} + +proc do_qexpr_test {tn expr value} { + uplevel do_execsql_test $tn [list "SELECT quote($expr)"] [list $value] +} + +# Set up three global variables: +# +# ::opname An array mapping from SQL operator to an easy to parse +# name. The names are used as part of test case names. +# +# ::opprec An array mapping from SQL operator to a numeric +# precedence value. Operators that group more tightly +# have lower numeric precedences. +# +# ::oplist A list of all SQL operators supported by SQLite. +# +foreach {op opn} { + || cat * mul / div % mod + add + - sub << lshift >> rshift & bitand | bitor + < less <= lesseq > more >= moreeq = eq1 + == eq2 <> ne1 != ne2 IS is LIKE like + GLOB glob AND and OR or MATCH match REGEXP regexp + {IS NOT} isnt +} { + set ::opname($op) $opn +} +set oplist [list] +foreach {prec opl} { + 1 || + 2 {* / %} + 3 {+ -} + 4 {<< >> & |} + 5 {< <= > >=} + 6 {= == != <> IS {IS NOT} LIKE GLOB MATCH REGEXP} + 7 AND + 8 OR +} { + foreach op $opl { + set ::opprec($op) $prec + lappend oplist $op + } +} + + +# Hook in definitions of MATCH and REGEX. The following implementations +# cause MATCH and REGEX to behave similarly to the == operator. +# +proc matchfunc {a b} { return [expr {$a==$b}] } +proc regexfunc {a b} { return [expr {$a==$b}] } +db func match -argcount 2 matchfunc +db func regexp -argcount 2 regexfunc + +#------------------------------------------------------------------------- +# Test cases e_expr-1.* attempt to verify that all binary operators listed +# in the documentation exist and that the relative precedences of the +# operators are also as the documentation suggests. +# +# X-EVIDENCE-OF: R-15514-65163 SQLite understands the following binary +# operators, in order from highest to lowest precedence: || * / % + - +# << >> & | < <= > >= = == != <> IS IS +# NOT IN LIKE GLOB MATCH REGEXP AND OR +# +# X-EVIDENCE-OF: R-38759-38789 Operators IS and IS NOT have the same +# precedence as =. +# + +unset -nocomplain untested +foreach op1 $oplist { + foreach op2 $oplist { + set untested($op1,$op2) 1 + foreach {tn A B C} { + 1 22 45 66 + 2 0 0 0 + 3 0 0 1 + 4 0 1 0 + 5 0 1 1 + 6 1 0 0 + 7 1 0 1 + 8 1 1 0 + 9 1 1 1 + 10 5 6 1 + 11 1 5 6 + 12 1 5 5 + 13 5 5 1 + + 14 5 2 1 + 15 1 4 1 + 16 -1 0 1 + 17 0 1 -1 + + } { + set testname "e_expr-1.$opname($op1).$opname($op2).$tn" + + # If $op2 groups more tightly than $op1, then the result + # of executing $sql1 whould be the same as executing $sql3. + # If $op1 groups more tightly, or if $op1 and $op2 have + # the same precedence, then executing $sql1 should return + # the same value as $sql2. + # + set sql1 "SELECT $A $op1 $B $op2 $C" + set sql2 "SELECT ($A $op1 $B) $op2 $C" + set sql3 "SELECT $A $op1 ($B $op2 $C)" + + set a2 [db one $sql2] + set a3 [db one $sql3] + + do_execsql_test $testname $sql1 [list [ + if {$opprec($op2) < $opprec($op1)} {set a3} {set a2} + ]] + if {$a2 != $a3} { unset -nocomplain untested($op1,$op2) } + } + } +} + +foreach op {* AND OR + || & |} { unset untested($op,$op) } +unset untested(+,-) ;# Since (a+b)-c == a+(b-c) +unset untested(*,<<) ;# Since (a*b)< work as the not-equals operator. +# +# EVIDENCE-OF: R-03679-60639 Equals can be either = or ==. +# +# EVIDENCE-OF: R-49372-18364 The not-equal operator can be either != or +# <>. +# +foreach {tn literal different} { + 1 'helloworld' '12345' + 2 22 23 + 3 'xyz' X'78797A' + 4 X'78797A00' 'xyz' +} { + do_execsql_test e_expr-4.$tn " + SELECT $literal = $literal, $literal == $literal, + $literal = $different, $literal == $different, + $literal = NULL, $literal == NULL, + $literal != $literal, $literal <> $literal, + $literal != $different, $literal <> $different, + $literal != NULL, $literal != NULL + + " {1 1 0 0 {} {} 0 0 1 1 {} {}} +} + +#------------------------------------------------------------------------- +# Test the || operator. +# +# EVIDENCE-OF: R-44409-62641 The || operator is "concatenate" - it joins +# together the two strings of its operands. +# +foreach {tn a b} { + 1 'helloworld' '12345' + 2 22 23 +} { + set as [db one "SELECT $a"] + set bs [db one "SELECT $b"] + + do_execsql_test e_expr-5.$tn "SELECT $a || $b" [list "${as}${bs}"] +} + +#------------------------------------------------------------------------- +# Test the % operator. +# +# EVIDENCE-OF: R-53431-59159 The % operator casts both of its operands +# to type INTEGER and then computes the remainder after dividing the +# left integer by the right integer. +# +do_execsql_test e_expr-6.1 {SELECT 72%5} {2} +do_execsql_test e_expr-6.2 {SELECT 72%-5} {2} +do_execsql_test e_expr-6.3 {SELECT -72%-5} {-2} +do_execsql_test e_expr-6.4 {SELECT -72%5} {-2} +do_execsql_test e_expr-6.5 {SELECT 72.35%5} {2.0} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-15904-00746 The result of any binary operator is either +# a numeric value or NULL, except for the || concatenation operator, and +# the -> and ->> extract operators which evaluate to either +# NULL or a text value. +# +set literals { + 1 'abc' 2 'hexadecimal' 3 '' + 4 123 5 -123 6 0 + 7 123.4 8 0.0 9 -123.4 + 10 X'ABCDEF' 11 X'' 12 X'0000' + 13 NULL +} +foreach op $oplist { + foreach {n1 rhs} $literals { + foreach {n2 lhs} $literals { + + set t [db one " SELECT typeof($lhs $op $rhs) "] + do_test e_expr-7.$opname($op).$n1.$n2 { + expr { + ($op=="||" && ($t == "text" || $t == "null")) + || ($op!="||" && ($t == "integer" || $t == "real" || $t == "null")) + } + } 1 + + }} +} + +#------------------------------------------------------------------------- +# Test the IS and IS NOT operators. +# +# EVIDENCE-OF: R-24731-45773 The IS and IS NOT operators work like = and +# != except when one or both of the operands are NULL. +# +# EVIDENCE-OF: R-06325-15315 In this case, if both operands are NULL, +# then the IS operator evaluates to 1 (true) and the IS NOT operator +# evaluates to 0 (false). +# +# EVIDENCE-OF: R-19812-36779 If one operand is NULL and the other is +# not, then the IS operator evaluates to 0 (false) and the IS NOT +# operator is 1 (true). +# +# EVIDENCE-OF: R-61975-13410 It is not possible for an IS or IS NOT +# expression to evaluate to NULL. +# +do_execsql_test e_expr-8.1.1 { SELECT NULL IS NULL } {1} +do_execsql_test e_expr-8.1.2 { SELECT 'ab' IS NULL } {0} +do_execsql_test e_expr-8.1.3 { SELECT NULL IS 'ab' } {0} +do_execsql_test e_expr-8.1.4 { SELECT 'ab' IS 'ab' } {1} +do_execsql_test e_expr-8.1.5 { SELECT NULL == NULL } {{}} +do_execsql_test e_expr-8.1.6 { SELECT 'ab' == NULL } {{}} +do_execsql_test e_expr-8.1.7 { SELECT NULL == 'ab' } {{}} +do_execsql_test e_expr-8.1.8 { SELECT 'ab' == 'ab' } {1} +do_execsql_test e_expr-8.1.9 { SELECT NULL IS NOT NULL } {0} +do_execsql_test e_expr-8.1.10 { SELECT 'ab' IS NOT NULL } {1} +do_execsql_test e_expr-8.1.11 { SELECT NULL IS NOT 'ab' } {1} +do_execsql_test e_expr-8.1.12 { SELECT 'ab' IS NOT 'ab' } {0} +do_execsql_test e_expr-8.1.13 { SELECT NULL != NULL } {{}} +do_execsql_test e_expr-8.1.14 { SELECT 'ab' != NULL } {{}} +do_execsql_test e_expr-8.1.15 { SELECT NULL != 'ab' } {{}} +do_execsql_test e_expr-8.1.16 { SELECT 'ab' != 'ab' } {0} + +foreach {n1 rhs} $literals { + foreach {n2 lhs} $literals { + if {$rhs!="NULL" && $lhs!="NULL"} { + set eq [execsql "SELECT $lhs = $rhs, $lhs != $rhs"] + } else { + set eq [list [expr {$lhs=="NULL" && $rhs=="NULL"}] \ + [expr {$lhs!="NULL" || $rhs!="NULL"}] + ] + } + set test e_expr-8.2.$n1.$n2 + do_execsql_test $test.1 "SELECT $lhs IS $rhs, $lhs IS NOT $rhs" $eq + do_execsql_test $test.2 " + SELECT ($lhs IS $rhs) IS NULL, ($lhs IS NOT $rhs) IS NULL + " {0 0} + } +} + +#------------------------------------------------------------------------- +# Run some tests on the COLLATE "unary postfix operator". +# +# This collation sequence reverses both arguments before using +# [string compare] to compare them. For example, when comparing the +# strings 'one' and 'four', return the result of: +# +# string compare eno ruof +# +proc reverse_str {zStr} { + set out "" + foreach c [split $zStr {}] { set out "${c}${out}" } + set out +} +proc reverse_collate {zLeft zRight} { + string compare [reverse_str $zLeft] [reverse_str $zRight] +} +db collate reverse reverse_collate + +# EVIDENCE-OF: R-59577-33471 The COLLATE operator is a unary postfix +# operator that assigns a collating sequence to an expression. +# +# X-EVIDENCE-OF: R-36231-30731 The COLLATE operator has a higher +# precedence (binds more tightly) than any binary operator and any unary +# prefix operator except "~". +# +do_execsql_test e_expr-9.1 { SELECT 'abcd' < 'bbbb' COLLATE reverse } 0 +do_execsql_test e_expr-9.2 { SELECT ('abcd' < 'bbbb') COLLATE reverse } 1 +do_execsql_test e_expr-9.3 { SELECT 'abcd' <= 'bbbb' COLLATE reverse } 0 +do_execsql_test e_expr-9.4 { SELECT ('abcd' <= 'bbbb') COLLATE reverse } 1 + +do_execsql_test e_expr-9.5 { SELECT 'abcd' > 'bbbb' COLLATE reverse } 1 +do_execsql_test e_expr-9.6 { SELECT ('abcd' > 'bbbb') COLLATE reverse } 0 +do_execsql_test e_expr-9.7 { SELECT 'abcd' >= 'bbbb' COLLATE reverse } 1 +do_execsql_test e_expr-9.8 { SELECT ('abcd' >= 'bbbb') COLLATE reverse } 0 + +do_execsql_test e_expr-9.10 { SELECT 'abcd' = 'ABCD' COLLATE nocase } 1 +do_execsql_test e_expr-9.11 { SELECT ('abcd' = 'ABCD') COLLATE nocase } 0 +do_execsql_test e_expr-9.12 { SELECT 'abcd' == 'ABCD' COLLATE nocase } 1 +do_execsql_test e_expr-9.13 { SELECT ('abcd' == 'ABCD') COLLATE nocase } 0 +do_execsql_test e_expr-9.14 { SELECT 'abcd' IS 'ABCD' COLLATE nocase } 1 +do_execsql_test e_expr-9.15 { SELECT ('abcd' IS 'ABCD') COLLATE nocase } 0 + +do_execsql_test e_expr-9.16 { SELECT 'abcd' != 'ABCD' COLLATE nocase } 0 +do_execsql_test e_expr-9.17 { SELECT ('abcd' != 'ABCD') COLLATE nocase } 1 +do_execsql_test e_expr-9.18 { SELECT 'abcd' <> 'ABCD' COLLATE nocase } 0 +do_execsql_test e_expr-9.19 { SELECT ('abcd' <> 'ABCD') COLLATE nocase } 1 +do_execsql_test e_expr-9.20 { SELECT 'abcd' IS NOT 'ABCD' COLLATE nocase } 0 +do_execsql_test e_expr-9.21 { SELECT ('abcd' IS NOT 'ABCD') COLLATE nocase } 1 + +do_execsql_test e_expr-9.22 { + SELECT 'bbb' BETWEEN 'AAA' AND 'CCC' COLLATE nocase +} 1 +do_execsql_test e_expr-9.23 { + SELECT ('bbb' BETWEEN 'AAA' AND 'CCC') COLLATE nocase +} 0 + +# EVIDENCE-OF: R-58731-25439 The collating sequence set by the COLLATE +# operator overrides the collating sequence determined by the COLLATE +# clause in a table column definition. +# +do_execsql_test e_expr-9.24 { + CREATE TABLE t24(a COLLATE NOCASE, b); + INSERT INTO t24 VALUES('aaa', 1); + INSERT INTO t24 VALUES('bbb', 2); + INSERT INTO t24 VALUES('ccc', 3); +} {} +do_execsql_test e_expr-9.25 { SELECT 'BBB' = a FROM t24 } {0 1 0} +do_execsql_test e_expr-9.25 { SELECT a = 'BBB' FROM t24 } {0 1 0} +do_execsql_test e_expr-9.25 { SELECT 'BBB' = a COLLATE binary FROM t24 } {0 0 0} +do_execsql_test e_expr-9.25 { SELECT a COLLATE binary = 'BBB' FROM t24 } {0 0 0} + +#------------------------------------------------------------------------- +# Test statements related to literal values. +# +# EVIDENCE-OF: R-31536-32008 Literal values may be integers, floating +# point numbers, strings, BLOBs, or NULLs. +# +do_execsql_test e_expr-10.1.1 { SELECT typeof(5) } {integer} +do_execsql_test e_expr-10.1.2 { SELECT typeof(5.1) } {real} +do_execsql_test e_expr-10.1.3 { SELECT typeof('5.1') } {text} +do_execsql_test e_expr-10.1.4 { SELECT typeof(X'ABCD') } {blob} +do_execsql_test e_expr-10.1.5 { SELECT typeof(NULL) } {null} + +# "Scientific notation is supported for point literal values." +# +do_execsql_test e_expr-10.2.1 { SELECT typeof(3.4e-02) } {real} +do_execsql_test e_expr-10.2.2 { SELECT typeof(3e+5) } {real} +do_execsql_test e_expr-10.2.3 { SELECT 3.4e-02 } {0.034} +do_execsql_test e_expr-10.2.4 { SELECT 3e+4 } {30000.0} + +# EVIDENCE-OF: R-35229-17830 A string constant is formed by enclosing +# the string in single quotes ('). +# +# EVIDENCE-OF: R-07100-06606 A single quote within the string can be +# encoded by putting two single quotes in a row - as in Pascal. +# +do_execsql_test e_expr-10.3.1 { SELECT 'is not' } {{is not}} +do_execsql_test e_expr-10.3.2 { SELECT typeof('is not') } {text} +do_execsql_test e_expr-10.3.3 { SELECT 'isn''t' } {isn't} +do_execsql_test e_expr-10.3.4 { SELECT typeof('isn''t') } {text} + +# EVIDENCE-OF: R-09593-03321 BLOB literals are string literals +# containing hexadecimal data and preceded by a single "x" or "X" +# character. +# +# EVIDENCE-OF: R-19836-11244 Example: X'53514C697465' +# +do_execsql_test e_expr-10.4.1 { SELECT typeof(X'0123456789ABCDEF') } blob +do_execsql_test e_expr-10.4.2 { SELECT typeof(x'0123456789ABCDEF') } blob +do_execsql_test e_expr-10.4.3 { SELECT typeof(X'0123456789abcdef') } blob +do_execsql_test e_expr-10.4.4 { SELECT typeof(x'0123456789abcdef') } blob +do_execsql_test e_expr-10.4.5 { SELECT typeof(X'53514C697465') } blob + +# EVIDENCE-OF: R-23914-51476 A literal value can also be the token +# "NULL". +# +do_execsql_test e_expr-10.5.1 { SELECT NULL } {{}} +do_execsql_test e_expr-10.5.2 { SELECT typeof(NULL) } {null} + +#------------------------------------------------------------------------- +# Test statements related to bound parameters +# + +proc parameter_test {tn sql params result} { + set stmt [sqlite3_prepare_v2 db $sql -1] + + foreach {number name} $params { + set nm [sqlite3_bind_parameter_name $stmt $number] + do_test $tn.name.$number [list set {} $nm] $name + sqlite3_bind_int $stmt $number [expr -1 * $number] + } + + sqlite3_step $stmt + + set res [list] + for {set i 0} {$i < [sqlite3_column_count $stmt]} {incr i} { + lappend res [sqlite3_column_text $stmt $i] + } + + set rc [sqlite3_finalize $stmt] + do_test $tn.rc [list set {} $rc] SQLITE_OK + do_test $tn.res [list set {} $res] $result +} + +# EVIDENCE-OF: R-33509-39458 A question mark followed by a number NNN +# holds a spot for the NNN-th parameter. NNN must be between 1 and +# SQLITE_MAX_VARIABLE_NUMBER. +# +set mvn $SQLITE_MAX_VARIABLE_NUMBER +parameter_test e_expr-11.1 " + SELECT ?1, ?123, ?$SQLITE_MAX_VARIABLE_NUMBER, ?123, ?4 +" "1 ?1 123 ?123 $mvn ?$mvn 4 ?4" "-1 -123 -$mvn -123 -4" + +set errmsg "variable number must be between ?1 and ?$SQLITE_MAX_VARIABLE_NUMBER" +foreach {tn param_number} [list \ + 2 0 \ + 3 [expr $SQLITE_MAX_VARIABLE_NUMBER+1] \ + 4 [expr $SQLITE_MAX_VARIABLE_NUMBER+2] \ + 5 12345678903456789034567890234567890 \ + 6 2147483648 \ + 7 2147483649 \ + 8 4294967296 \ + 9 4294967297 \ + 10 9223372036854775808 \ + 11 9223372036854775809 \ + 12 18446744073709551616 \ + 13 18446744073709551617 \ +] { + do_catchsql_test e_expr-11.1.$tn "SELECT ?$param_number" [list 1 $errmsg] +} + +# EVIDENCE-OF: R-33670-36097 A question mark that is not followed by a +# number creates a parameter with a number one greater than the largest +# parameter number already assigned. +# +# EVIDENCE-OF: R-42938-07030 If this means the parameter number is +# greater than SQLITE_MAX_VARIABLE_NUMBER, it is an error. +# +parameter_test e_expr-11.2.1 "SELECT ?" {1 {}} -1 +parameter_test e_expr-11.2.2 "SELECT ?, ?" {1 {} 2 {}} {-1 -2} +parameter_test e_expr-11.2.3 "SELECT ?5, ?" {5 ?5 6 {}} {-5 -6} +parameter_test e_expr-11.2.4 "SELECT ?, ?5" {1 {} 5 ?5} {-1 -5} +parameter_test e_expr-11.2.5 "SELECT ?, ?456, ?" { + 1 {} 456 ?456 457 {} +} {-1 -456 -457} +parameter_test e_expr-11.2.5 "SELECT ?, ?456, ?4, ?" { + 1 {} 456 ?456 4 ?4 457 {} +} {-1 -456 -4 -457} +foreach {tn sql} [list \ + 1 "SELECT ?$mvn, ?" \ + 2 "SELECT ?[expr $mvn-5], ?, ?, ?, ?, ?, ?" \ + 3 "SELECT ?[expr $mvn], ?5, ?6, ?" \ +] { + do_catchsql_test e_expr-11.3.$tn $sql [list 1 {too many SQL variables}] +} + +# EVIDENCE-OF: R-11620-22743 A colon followed by an identifier name +# holds a spot for a named parameter with the name :AAAA. +# +# Identifiers in SQLite consist of alphanumeric, '_' and '$' characters, +# and any UTF characters with codepoints larger than 127 (non-ASCII +# characters). +# +parameter_test e_expr-11.2.1 {SELECT :AAAA} {1 :AAAA} -1 +parameter_test e_expr-11.2.2 {SELECT :123} {1 :123} -1 +parameter_test e_expr-11.2.3 {SELECT :__} {1 :__} -1 +parameter_test e_expr-11.2.4 {SELECT :_$_} {1 :_$_} -1 +parameter_test e_expr-11.2.5 " + SELECT :\u0e40\u0e2d\u0e28\u0e02\u0e39\u0e40\u0e2d\u0e25 +" "1 :\u0e40\u0e2d\u0e28\u0e02\u0e39\u0e40\u0e2d\u0e25" -1 +parameter_test e_expr-11.2.6 "SELECT :\u0080" "1 :\u0080" -1 + +# EVIDENCE-OF: R-49783-61279 An "at" sign works exactly like a colon, +# except that the name of the parameter created is @AAAA. +# +parameter_test e_expr-11.3.1 {SELECT @AAAA} {1 @AAAA} -1 +parameter_test e_expr-11.3.2 {SELECT @123} {1 @123} -1 +parameter_test e_expr-11.3.3 {SELECT @__} {1 @__} -1 +parameter_test e_expr-11.3.4 {SELECT @_$_} {1 @_$_} -1 +parameter_test e_expr-11.3.5 " + SELECT @\u0e40\u0e2d\u0e28\u0e02\u0e39\u0e40\u0e2d\u0e25 +" "1 @\u0e40\u0e2d\u0e28\u0e02\u0e39\u0e40\u0e2d\u0e25" -1 +parameter_test e_expr-11.3.6 "SELECT @\u0080" "1 @\u0080" -1 + +# EVIDENCE-OF: R-62610-51329 A dollar-sign followed by an identifier +# name also holds a spot for a named parameter with the name $AAAA. +# +# EVIDENCE-OF: R-55025-21042 The identifier name in this case can +# include one or more occurrences of "::" and a suffix enclosed in +# "(...)" containing any text at all. +# +# Note: Looks like an identifier cannot consist entirely of "::" +# characters or just a suffix. Also, the other named variable characters +# (: and @) work the same way internally. Why not just document it that way? +# +parameter_test e_expr-11.4.1 {SELECT $AAAA} {1 $AAAA} -1 +parameter_test e_expr-11.4.2 {SELECT $123} {1 $123} -1 +parameter_test e_expr-11.4.3 {SELECT $__} {1 $__} -1 +parameter_test e_expr-11.4.4 {SELECT $_$_} {1 $_$_} -1 +parameter_test e_expr-11.4.5 " + SELECT \$\u0e40\u0e2d\u0e28\u0e02\u0e39\u0e40\u0e2d\u0e25 +" "1 \$\u0e40\u0e2d\u0e28\u0e02\u0e39\u0e40\u0e2d\u0e25" -1 +parameter_test e_expr-11.4.6 "SELECT \$\u0080" "1 \$\u0080" -1 + +parameter_test e_expr-11.5.1 {SELECT $::::a(++--++)} {1 $::::a(++--++)} -1 +parameter_test e_expr-11.5.2 {SELECT $::a()} {1 $::a()} -1 +parameter_test e_expr-11.5.3 {SELECT $::1(::#$)} {1 $::1(::#$)} -1 + +# EVIDENCE-OF: R-11370-04520 Named parameters are also numbered. The +# number assigned is one greater than the largest parameter number +# already assigned. +# +# EVIDENCE-OF: R-42620-22184 If this means the parameter would be +# assigned a number greater than SQLITE_MAX_VARIABLE_NUMBER, it is an +# error. +# +parameter_test e_expr-11.6.1 "SELECT ?, @abc" {1 {} 2 @abc} {-1 -2} +parameter_test e_expr-11.6.2 "SELECT ?123, :a1" {123 ?123 124 :a1} {-123 -124} +parameter_test e_expr-11.6.3 {SELECT $a, ?8, ?, $b, ?2, $c} { + 1 $a 8 ?8 9 {} 10 $b 2 ?2 11 $c +} {-1 -8 -9 -10 -2 -11} +foreach {tn sql} [list \ + 1 "SELECT ?$mvn, \$::a" \ + 2 "SELECT ?$mvn, ?4, @a1" \ + 3 "SELECT ?[expr $mvn-2], :bag, @123, \$x" \ +] { + do_catchsql_test e_expr-11.7.$tn $sql [list 1 {too many SQL variables}] +} + +# EVIDENCE-OF: R-14068-49671 Parameters that are not assigned values +# using sqlite3_bind() are treated as NULL. +# +do_test e_expr-11.7.1 { + set stmt [sqlite3_prepare_v2 db { SELECT ?, :a, @b, $d } -1] + sqlite3_step $stmt + + list [sqlite3_column_type $stmt 0] \ + [sqlite3_column_type $stmt 1] \ + [sqlite3_column_type $stmt 2] \ + [sqlite3_column_type $stmt 3] +} {NULL NULL NULL NULL} +do_test e_expr-11.7.1 { sqlite3_finalize $stmt } SQLITE_OK + +#------------------------------------------------------------------------- +# "Test" the syntax diagrams in lang_expr.html. +# +# -- syntax diagram signed-number +# +do_execsql_test e_expr-12.1.1 { SELECT 0, +0, -0 } {0 0 0} +do_execsql_test e_expr-12.1.2 { SELECT 1, +1, -1 } {1 1 -1} +do_execsql_test e_expr-12.1.3 { SELECT 2, +2, -2 } {2 2 -2} +do_execsql_test e_expr-12.1.4 { + SELECT 1.4, +1.4, -1.4 +} {1.4 1.4 -1.4} +do_execsql_test e_expr-12.1.5 { + SELECT 1.5e+5, +1.5e+5, -1.5e+5 +} {150000.0 150000.0 -150000.0} +do_execsql_test e_expr-12.1.6 { + SELECT 0.0001, +0.0001, -0.0001 +} {0.0001 0.0001 -0.0001} + +# -- syntax diagram literal-value +# +set sqlite_current_time 1 +do_execsql_test e_expr-12.2.1 {SELECT 123} {123} +do_execsql_test e_expr-12.2.2 {SELECT 123.4e05} {12340000.0} +do_execsql_test e_expr-12.2.3 {SELECT 'abcde'} {abcde} +do_execsql_test e_expr-12.2.4 {SELECT X'414243'} {ABC} +do_execsql_test e_expr-12.2.5 {SELECT NULL} {{}} +do_execsql_test e_expr-12.2.6 {SELECT CURRENT_TIME} {00:00:01} +do_execsql_test e_expr-12.2.7 {SELECT CURRENT_DATE} {1970-01-01} +do_execsql_test e_expr-12.2.8 {SELECT CURRENT_TIMESTAMP} {{1970-01-01 00:00:01}} +set sqlite_current_time 0 + +# -- syntax diagram expr +# +forcedelete test.db2 +execsql { + ATTACH 'test.db2' AS dbname; + CREATE TABLE dbname.tblname(cname); +} + +proc glob {args} {return 1} +db function glob glob +db function match glob +db function regexp glob + +foreach {tn expr} { + 1 123 + 2 123.4e05 + 3 'abcde' + 4 X'414243' + 5 NULL + 6 CURRENT_TIME + 7 CURRENT_DATE + 8 CURRENT_TIMESTAMP + + 9 ? + 10 ?123 + 11 @hello + 12 :world + 13 $tcl + 14 $tcl(array) + + 15 cname + 16 tblname.cname + 17 dbname.tblname.cname + + 18 "+ EXPR" + 19 "- EXPR" + 20 "NOT EXPR" + 21 "~ EXPR" + + 22 "EXPR1 || EXPR2" + 23 "EXPR1 * EXPR2" + 24 "EXPR1 / EXPR2" + 25 "EXPR1 % EXPR2" + 26 "EXPR1 + EXPR2" + 27 "EXPR1 - EXPR2" + 28 "EXPR1 << EXPR2" + 29 "EXPR1 >> EXPR2" + 30 "EXPR1 & EXPR2" + 31 "EXPR1 | EXPR2" + 32 "EXPR1 < EXPR2" + 33 "EXPR1 <= EXPR2" + 34 "EXPR1 > EXPR2" + 35 "EXPR1 >= EXPR2" + 36 "EXPR1 = EXPR2" + 37 "EXPR1 == EXPR2" + 38 "EXPR1 != EXPR2" + 39 "EXPR1 <> EXPR2" + 40 "EXPR1 IS EXPR2" + 41 "EXPR1 IS NOT EXPR2" + 42 "EXPR1 AND EXPR2" + 43 "EXPR1 OR EXPR2" + + 44 "count(*)" + 45 "count(DISTINCT EXPR)" + 46 "substr(EXPR, 10, 20)" + 47 "changes()" + + 48 "( EXPR )" + + 49 "CAST ( EXPR AS integer )" + 50 "CAST ( EXPR AS 'abcd' )" + 51 "CAST ( EXPR AS 'ab$ $cd' )" + + 52 "EXPR COLLATE nocase" + 53 "EXPR COLLATE binary" + + 54 "EXPR1 LIKE EXPR2" + 55 "EXPR1 LIKE EXPR2 ESCAPE EXPR" + 56 "EXPR1 GLOB EXPR2" + 57 "EXPR1 GLOB EXPR2 ESCAPE EXPR" + 58 "EXPR1 REGEXP EXPR2" + 59 "EXPR1 REGEXP EXPR2 ESCAPE EXPR" + 60 "EXPR1 MATCH EXPR2" + 61 "EXPR1 MATCH EXPR2 ESCAPE EXPR" + 62 "EXPR1 NOT LIKE EXPR2" + 63 "EXPR1 NOT LIKE EXPR2 ESCAPE EXPR" + 64 "EXPR1 NOT GLOB EXPR2" + 65 "EXPR1 NOT GLOB EXPR2 ESCAPE EXPR" + 66 "EXPR1 NOT REGEXP EXPR2" + 67 "EXPR1 NOT REGEXP EXPR2 ESCAPE EXPR" + 68 "EXPR1 NOT MATCH EXPR2" + 69 "EXPR1 NOT MATCH EXPR2 ESCAPE EXPR" + + 70 "EXPR ISNULL" + 71 "EXPR NOTNULL" + 72 "EXPR NOT NULL" + + 73 "EXPR1 IS EXPR2" + 74 "EXPR1 IS NOT EXPR2" + + 75 "EXPR NOT BETWEEN EXPR1 AND EXPR2" + 76 "EXPR BETWEEN EXPR1 AND EXPR2" + + 77 "EXPR NOT IN (SELECT cname FROM tblname)" + 78 "EXPR NOT IN (1)" + 79 "EXPR NOT IN (1, 2, 3)" + 80 "EXPR NOT IN tblname" + 81 "EXPR NOT IN dbname.tblname" + 82 "EXPR IN (SELECT cname FROM tblname)" + 83 "EXPR IN (1)" + 84 "EXPR IN (1, 2, 3)" + 85 "EXPR IN tblname" + 86 "EXPR IN dbname.tblname" + + 87 "EXISTS (SELECT cname FROM tblname)" + 88 "NOT EXISTS (SELECT cname FROM tblname)" + + 89 "CASE EXPR WHEN EXPR1 THEN EXPR2 ELSE EXPR END" + 90 "CASE EXPR WHEN EXPR1 THEN EXPR2 END" + 91 "CASE EXPR WHEN EXPR1 THEN EXPR2 WHEN EXPR THEN EXPR1 ELSE EXPR2 END" + 92 "CASE EXPR WHEN EXPR1 THEN EXPR2 WHEN EXPR THEN EXPR1 END" + 93 "CASE WHEN EXPR1 THEN EXPR2 ELSE EXPR END" + 94 "CASE WHEN EXPR1 THEN EXPR2 END" + 95 "CASE WHEN EXPR1 THEN EXPR2 WHEN EXPR THEN EXPR1 ELSE EXPR2 END" + 96 "CASE WHEN EXPR1 THEN EXPR2 WHEN EXPR THEN EXPR1 END" +} { + + # If the expression string being parsed contains "EXPR2", then replace + # string "EXPR1" and "EXPR2" with arbitrary SQL expressions. If it + # contains "EXPR", then replace EXPR with an arbitrary SQL expression. + # + set elist [list $expr] + if {[string match *EXPR2* $expr]} { + set elist [list] + foreach {e1 e2} { cname "34+22" } { + lappend elist [string map [list EXPR1 $e1 EXPR2 $e2] $expr] + } + } + if {[string match *EXPR* $expr]} { + set elist2 [list] + foreach el $elist { + foreach e { cname "34+22" } { + lappend elist2 [string map [list EXPR $e] $el] + } + } + set elist $elist2 + } + + set x 0 + foreach e $elist { + incr x + do_test e_expr-12.3.$tn.$x { + set rc [catch { execsql "SELECT $e FROM tblname" } msg] + } {0} + } +} + +# -- syntax diagram raise-function +# +foreach {tn raiseexpr} { + 1 "RAISE(IGNORE)" + 2 "RAISE(ROLLBACK, 'error message')" + 3 "RAISE(ABORT, 'error message')" + 4 "RAISE(FAIL, 'error message')" +} { + do_execsql_test e_expr-12.4.$tn " + CREATE TRIGGER dbname.tr$tn BEFORE DELETE ON tblname BEGIN + SELECT $raiseexpr ; + END; + " {} +} + +#------------------------------------------------------------------------- +# Test the statements related to the BETWEEN operator. +# +# EVIDENCE-OF: R-40079-54503 The BETWEEN operator is logically +# equivalent to a pair of comparisons. "x BETWEEN y AND z" is equivalent +# to "x>=y AND x<=z" except that with BETWEEN, the x expression is +# only evaluated once. +# +db func x x +proc x {} { incr ::xcount ; return [expr $::x] } +foreach {tn x expr res nEval} { + 1 10 "x() >= 5 AND x() <= 15" 1 2 + 2 10 "x() BETWEEN 5 AND 15" 1 1 + + 3 5 "x() >= 5 AND x() <= 5" 1 2 + 4 5 "x() BETWEEN 5 AND 5" 1 1 + + 5 9 "(x(),8) >= (9,7) AND (x(),8)<=(9,10)" 1 2 + 6 9 "(x(),8) BETWEEN (9,7) AND (9,10)" 1 1 +} { + do_test e_expr-13.1.$tn { + set ::xcount 0 + set a [execsql "SELECT $expr"] + list $::xcount $a + } [list $nEval $res] +} + +# X-EVIDENCE-OF: R-05155-34454 The precedence of the BETWEEN operator is +# the same as the precedence as operators == and != and LIKE and groups +# left to right. +# +# Therefore, BETWEEN groups more tightly than operator "AND", but less +# so than "<". +# +do_execsql_test e_expr-13.2.1 { SELECT 1 == 10 BETWEEN 0 AND 2 } 1 +do_execsql_test e_expr-13.2.2 { SELECT (1 == 10) BETWEEN 0 AND 2 } 1 +do_execsql_test e_expr-13.2.3 { SELECT 1 == (10 BETWEEN 0 AND 2) } 0 +do_execsql_test e_expr-13.2.4 { SELECT 6 BETWEEN 4 AND 8 == 1 } 1 +do_execsql_test e_expr-13.2.5 { SELECT (6 BETWEEN 4 AND 8) == 1 } 1 +do_execsql_test e_expr-13.2.6 { SELECT 6 BETWEEN 4 AND (8 == 1) } 0 + +do_execsql_test e_expr-13.2.7 { SELECT 5 BETWEEN 0 AND 0 != 1 } 1 +do_execsql_test e_expr-13.2.8 { SELECT (5 BETWEEN 0 AND 0) != 1 } 1 +do_execsql_test e_expr-13.2.9 { SELECT 5 BETWEEN 0 AND (0 != 1) } 0 +do_execsql_test e_expr-13.2.10 { SELECT 1 != 0 BETWEEN 0 AND 2 } 1 +do_execsql_test e_expr-13.2.11 { SELECT (1 != 0) BETWEEN 0 AND 2 } 1 +do_execsql_test e_expr-13.2.12 { SELECT 1 != (0 BETWEEN 0 AND 2) } 0 + +do_execsql_test e_expr-13.2.13 { SELECT 1 LIKE 10 BETWEEN 0 AND 2 } 1 +do_execsql_test e_expr-13.2.14 { SELECT (1 LIKE 10) BETWEEN 0 AND 2 } 1 +do_execsql_test e_expr-13.2.15 { SELECT 1 LIKE (10 BETWEEN 0 AND 2) } 0 +do_execsql_test e_expr-13.2.16 { SELECT 6 BETWEEN 4 AND 8 LIKE 1 } 1 +do_execsql_test e_expr-13.2.17 { SELECT (6 BETWEEN 4 AND 8) LIKE 1 } 1 +do_execsql_test e_expr-13.2.18 { SELECT 6 BETWEEN 4 AND (8 LIKE 1) } 0 + +do_execsql_test e_expr-13.2.19 { SELECT 0 AND 0 BETWEEN 0 AND 1 } 0 +do_execsql_test e_expr-13.2.20 { SELECT 0 AND (0 BETWEEN 0 AND 1) } 0 +do_execsql_test e_expr-13.2.21 { SELECT (0 AND 0) BETWEEN 0 AND 1 } 1 +do_execsql_test e_expr-13.2.22 { SELECT 0 BETWEEN -1 AND 1 AND 0 } 0 +do_execsql_test e_expr-13.2.23 { SELECT (0 BETWEEN -1 AND 1) AND 0 } 0 +do_execsql_test e_expr-13.2.24 { SELECT 0 BETWEEN -1 AND (1 AND 0) } 1 + +do_execsql_test e_expr-13.2.25 { SELECT 2 < 3 BETWEEN 0 AND 1 } 1 +do_execsql_test e_expr-13.2.26 { SELECT (2 < 3) BETWEEN 0 AND 1 } 1 +do_execsql_test e_expr-13.2.27 { SELECT 2 < (3 BETWEEN 0 AND 1) } 0 +do_execsql_test e_expr-13.2.28 { SELECT 2 BETWEEN 1 AND 2 < 3 } 0 +do_execsql_test e_expr-13.2.29 { SELECT 2 BETWEEN 1 AND (2 < 3) } 0 +do_execsql_test e_expr-13.2.30 { SELECT (2 BETWEEN 1 AND 2) < 3 } 1 + +#------------------------------------------------------------------------- +# Test the statements related to the LIKE and GLOB operators. +# +# EVIDENCE-OF: R-16584-60189 The LIKE operator does a pattern matching +# comparison. +# +# EVIDENCE-OF: R-11295-04657 The operand to the right of the LIKE +# operator contains the pattern and the left hand operand contains the +# string to match against the pattern. +# +do_execsql_test e_expr-14.1.1 { SELECT 'abc%' LIKE 'abcde' } 0 +do_execsql_test e_expr-14.1.2 { SELECT 'abcde' LIKE 'abc%' } 1 + +# EVIDENCE-OF: R-55406-38524 A percent symbol ("%") in the LIKE pattern +# matches any sequence of zero or more characters in the string. +# +do_execsql_test e_expr-14.2.1 { SELECT 'abde' LIKE 'ab%de' } 1 +do_execsql_test e_expr-14.2.2 { SELECT 'abXde' LIKE 'ab%de' } 1 +do_execsql_test e_expr-14.2.3 { SELECT 'abABCde' LIKE 'ab%de' } 1 + +# EVIDENCE-OF: R-30433-25443 An underscore ("_") in the LIKE pattern +# matches any single character in the string. +# +do_execsql_test e_expr-14.3.1 { SELECT 'abde' LIKE 'ab_de' } 0 +do_execsql_test e_expr-14.3.2 { SELECT 'abXde' LIKE 'ab_de' } 1 +do_execsql_test e_expr-14.3.3 { SELECT 'abABCde' LIKE 'ab_de' } 0 + +# EVIDENCE-OF: R-59007-20454 Any other character matches itself or its +# lower/upper case equivalent (i.e. case-insensitive matching). +# +do_execsql_test e_expr-14.4.1 { SELECT 'abc' LIKE 'aBc' } 1 +do_execsql_test e_expr-14.4.2 { SELECT 'aBc' LIKE 'aBc' } 1 +do_execsql_test e_expr-14.4.3 { SELECT 'ac' LIKE 'aBc' } 0 + +# EVIDENCE-OF: R-23648-58527 SQLite only understands upper/lower case +# for ASCII characters by default. +# +# EVIDENCE-OF: R-04532-11527 The LIKE operator is case sensitive by +# default for unicode characters that are beyond the ASCII range. +# +# EVIDENCE-OF: R-44381-11669 the expression +# 'a' LIKE 'A' is TRUE but +# 'æ' LIKE 'Æ' is FALSE. +# +# The restriction to ASCII characters does not apply if the ICU +# library is compiled in. When ICU is enabled SQLite does not act +# as it does "by default". +# +do_execsql_test e_expr-14.5.1 { SELECT 'A' LIKE 'a' } 1 +ifcapable !icu { + do_execsql_test e_expr-14.5.2 "SELECT '\u00c6' LIKE '\u00e6'" 0 +} + +# EVIDENCE-OF: R-56683-13731 If the optional ESCAPE clause is present, +# then the expression following the ESCAPE keyword must evaluate to a +# string consisting of a single character. +# +do_catchsql_test e_expr-14.6.1 { + SELECT 'A' LIKE 'a' ESCAPE '12' +} {1 {ESCAPE expression must be a single character}} +do_catchsql_test e_expr-14.6.2 { + SELECT 'A' LIKE 'a' ESCAPE '' +} {1 {ESCAPE expression must be a single character}} +do_catchsql_test e_expr-14.6.3 { SELECT 'A' LIKE 'a' ESCAPE 'x' } {0 1} +do_catchsql_test e_expr-14.6.4 "SELECT 'A' LIKE 'a' ESCAPE '\u00e6'" {0 1} + +# EVIDENCE-OF: R-02045-23762 This character may be used in the LIKE +# pattern to include literal percent or underscore characters. +# +# EVIDENCE-OF: R-13345-31830 The escape character followed by a percent +# symbol (%), underscore (_), or a second instance of the escape +# character itself matches a literal percent symbol, underscore, or a +# single escape character, respectively. +# +do_execsql_test e_expr-14.7.1 { SELECT 'abc%' LIKE 'abcX%' ESCAPE 'X' } 1 +do_execsql_test e_expr-14.7.2 { SELECT 'abc5' LIKE 'abcX%' ESCAPE 'X' } 0 +do_execsql_test e_expr-14.7.3 { SELECT 'abc' LIKE 'abcX%' ESCAPE 'X' } 0 +do_execsql_test e_expr-14.7.4 { SELECT 'abcX%' LIKE 'abcX%' ESCAPE 'X' } 0 +do_execsql_test e_expr-14.7.5 { SELECT 'abc%%' LIKE 'abcX%' ESCAPE 'X' } 0 + +do_execsql_test e_expr-14.7.6 { SELECT 'abc_' LIKE 'abcX_' ESCAPE 'X' } 1 +do_execsql_test e_expr-14.7.7 { SELECT 'abc5' LIKE 'abcX_' ESCAPE 'X' } 0 +do_execsql_test e_expr-14.7.8 { SELECT 'abc' LIKE 'abcX_' ESCAPE 'X' } 0 +do_execsql_test e_expr-14.7.9 { SELECT 'abcX_' LIKE 'abcX_' ESCAPE 'X' } 0 +do_execsql_test e_expr-14.7.10 { SELECT 'abc__' LIKE 'abcX_' ESCAPE 'X' } 0 + +do_execsql_test e_expr-14.7.11 { SELECT 'abcX' LIKE 'abcXX' ESCAPE 'X' } 1 +do_execsql_test e_expr-14.7.12 { SELECT 'abc5' LIKE 'abcXX' ESCAPE 'X' } 0 +do_execsql_test e_expr-14.7.13 { SELECT 'abc' LIKE 'abcXX' ESCAPE 'X' } 0 +do_execsql_test e_expr-14.7.14 { SELECT 'abcXX' LIKE 'abcXX' ESCAPE 'X' } 0 + +# EVIDENCE-OF: R-51359-17496 The infix LIKE operator is implemented by +# calling the application-defined SQL functions like(Y,X) or like(Y,X,Z). +# +proc likefunc {args} { + eval lappend ::likeargs $args + return 1 +} +db func like -argcount 2 likefunc +db func like -argcount 3 likefunc +set ::likeargs [list] +do_execsql_test e_expr-15.1.1 { SELECT 'abc' LIKE 'def' } 1 +do_test e_expr-15.1.2 { set likeargs } {def abc} +set ::likeargs [list] +do_execsql_test e_expr-15.1.3 { SELECT 'abc' LIKE 'def' ESCAPE 'X' } 1 +do_test e_expr-15.1.4 { set likeargs } {def abc X} +db close +sqlite3 db test.db + +# EVIDENCE-OF: R-22868-25880 The LIKE operator can be made case +# sensitive using the case_sensitive_like pragma. +# +do_execsql_test e_expr-16.1.1 { SELECT 'abcxyz' LIKE 'ABC%' } 1 +do_execsql_test e_expr-16.1.1b { SELECT 'abc%xyz' LIKE 'ABC\%x%' ESCAPE '\' } 1 +do_execsql_test e_expr-16.1.2 { PRAGMA case_sensitive_like = 1 } {} +do_execsql_test e_expr-16.1.3 { SELECT 'abcxyz' LIKE 'ABC%' } 0 +do_execsql_test e_expr-16.1.3b { SELECT 'abc%xyz' LIKE 'ABC\%X%' ESCAPE '\' } 0 +do_execsql_test e_expr-16.1.4 { SELECT 'ABCxyz' LIKE 'ABC%' } 1 +do_execsql_test e_expr-16.1.4b { SELECT 'ABC%xyz' LIKE 'ABC\%x%' ESCAPE '\' } 1 +do_execsql_test e_expr-16.1.5 { PRAGMA case_sensitive_like = 0 } {} +do_execsql_test e_expr-16.1.6 { SELECT 'abcxyz' LIKE 'ABC%' } 1 +do_execsql_test e_expr-16.1.6b { SELECT 'abc%xyz' LIKE 'ABC\%X%' ESCAPE '\' } 1 +do_execsql_test e_expr-16.1.7 { SELECT 'ABCxyz' LIKE 'ABC%' } 1 +do_execsql_test e_expr-16.1.7b { SELECT 'ABC%xyz' LIKE 'ABC\%X%' ESCAPE '\' } 1 + +# EVIDENCE-OF: R-52087-12043 The GLOB operator is similar to LIKE but +# uses the Unix file globbing syntax for its wildcards. +# +# EVIDENCE-OF: R-09813-17279 Also, GLOB is case sensitive, unlike LIKE. +# +do_execsql_test e_expr-17.1.1 { SELECT 'abcxyz' GLOB 'abc%' } 0 +do_execsql_test e_expr-17.1.2 { SELECT 'abcxyz' GLOB 'abc*' } 1 +do_execsql_test e_expr-17.1.3 { SELECT 'abcxyz' GLOB 'abc___' } 0 +do_execsql_test e_expr-17.1.4 { SELECT 'abcxyz' GLOB 'abc???' } 1 + +do_execsql_test e_expr-17.1.5 { SELECT 'abcxyz' GLOB 'abc*' } 1 +do_execsql_test e_expr-17.1.6 { SELECT 'ABCxyz' GLOB 'abc*' } 0 +do_execsql_test e_expr-17.1.7 { SELECT 'abcxyz' GLOB 'ABC*' } 0 + +# EVIDENCE-OF: R-39616-20555 Both GLOB and LIKE may be preceded by the +# NOT keyword to invert the sense of the test. +# +do_execsql_test e_expr-17.2.1 { SELECT 'abcxyz' NOT GLOB 'ABC*' } 1 +do_execsql_test e_expr-17.2.2 { SELECT 'abcxyz' NOT GLOB 'abc*' } 0 +do_execsql_test e_expr-17.2.3 { SELECT 'abcxyz' NOT LIKE 'ABC%' } 0 +do_execsql_test e_expr-17.2.4 { SELECT 'abcxyz' NOT LIKE 'abc%' } 0 +do_execsql_test e_expr-17.2.5 { SELECT 'abdxyz' NOT LIKE 'abc%' } 1 + +db nullvalue null +do_execsql_test e_expr-17.2.6 { SELECT 'abcxyz' NOT GLOB NULL } null +do_execsql_test e_expr-17.2.7 { SELECT 'abcxyz' NOT LIKE NULL } null +do_execsql_test e_expr-17.2.8 { SELECT NULL NOT GLOB 'abc*' } null +do_execsql_test e_expr-17.2.9 { SELECT NULL NOT LIKE 'ABC%' } null +db nullvalue {} + +# EVIDENCE-OF: R-39414-35489 The infix GLOB operator is implemented by +# calling the function glob(Y,X) and can be modified by overriding that +# function. +proc globfunc {args} { + eval lappend ::globargs $args + return 1 +} +db func glob -argcount 2 globfunc +set ::globargs [list] +do_execsql_test e_expr-17.3.1 { SELECT 'abc' GLOB 'def' } 1 +do_test e_expr-17.3.2 { set globargs } {def abc} +set ::globargs [list] +do_execsql_test e_expr-17.3.3 { SELECT 'X' NOT GLOB 'Y' } 0 +do_test e_expr-17.3.4 { set globargs } {Y X} +sqlite3 db test.db + +# EVIDENCE-OF: R-41650-20872 No regexp() user function is defined by +# default and so use of the REGEXP operator will normally result in an +# error message. +# +# There is a regexp function if ICU is enabled though. +# +ifcapable !icu { + do_catchsql_test e_expr-18.1.1 { + SELECT regexp('abc', 'def') + } {1 {no such function: regexp}} + do_catchsql_test e_expr-18.1.2 { + SELECT 'abc' REGEXP 'def' + } {1 {no such function: REGEXP}} +} + +# EVIDENCE-OF: R-33693-50180 The REGEXP operator is a special syntax for +# the regexp() user function. +# +# EVIDENCE-OF: R-65524-61849 If an application-defined SQL function +# named "regexp" is added at run-time, then the "X REGEXP Y" operator +# will be implemented as a call to "regexp(Y,X)". +# +proc regexpfunc {args} { + eval lappend ::regexpargs $args + return 1 +} +db func regexp -argcount 2 regexpfunc +set ::regexpargs [list] +do_execsql_test e_expr-18.2.1 { SELECT 'abc' REGEXP 'def' } 1 +do_test e_expr-18.2.2 { set regexpargs } {def abc} +set ::regexpargs [list] +do_execsql_test e_expr-18.2.3 { SELECT 'X' NOT REGEXP 'Y' } 0 +do_test e_expr-18.2.4 { set regexpargs } {Y X} +sqlite3 db test.db + +# EVIDENCE-OF: R-42037-37826 The default match() function implementation +# raises an exception and is not really useful for anything. +# +do_catchsql_test e_expr-19.1.1 { + SELECT 'abc' MATCH 'def' +} {1 {unable to use function MATCH in the requested context}} +do_catchsql_test e_expr-19.1.2 { + SELECT match('abc', 'def') +} {1 {unable to use function MATCH in the requested context}} + +# EVIDENCE-OF: R-37916-47407 The MATCH operator is a special syntax for +# the match() application-defined function. +# +# EVIDENCE-OF: R-06021-09373 But extensions can override the match() +# function with more helpful logic. +# +proc matchfunc {args} { + eval lappend ::matchargs $args + return 1 +} +db func match -argcount 2 matchfunc +set ::matchargs [list] +do_execsql_test e_expr-19.2.1 { SELECT 'abc' MATCH 'def' } 1 +do_test e_expr-19.2.2 { set matchargs } {def abc} +set ::matchargs [list] +do_execsql_test e_expr-19.2.3 { SELECT 'X' NOT MATCH 'Y' } 0 +do_test e_expr-19.2.4 { set matchargs } {Y X} +sqlite3 db test.db + +#------------------------------------------------------------------------- +# Test cases for the testable statements related to the CASE expression. +# +# EVIDENCE-OF: R-57495-24088 There are two fundamental forms of the CASE +# expression: those with a base expression and those without. +# +do_execsql_test e_expr-20.1 { + SELECT CASE WHEN 1 THEN 'true' WHEN 0 THEN 'false' ELSE 'else' END; +} {true} +do_execsql_test e_expr-20.2 { + SELECT CASE 0 WHEN 1 THEN 'true' WHEN 0 THEN 'false' ELSE 'else' END; +} {false} + +proc var {nm} { + lappend ::varlist $nm + return [set "::$nm"] +} +db func var var + +# EVIDENCE-OF: R-30638-59954 In a CASE without a base expression, each +# WHEN expression is evaluated and the result treated as a boolean, +# starting with the leftmost and continuing to the right. +# +foreach {a b c} {0 0 0} break +set varlist [list] +do_execsql_test e_expr-21.1.1 { + SELECT CASE WHEN var('a') THEN 'A' + WHEN var('b') THEN 'B' + WHEN var('c') THEN 'C' END +} {{}} +do_test e_expr-21.1.2 { set varlist } {a b c} +set varlist [list] +do_execsql_test e_expr-21.1.3 { + SELECT CASE WHEN var('c') THEN 'C' + WHEN var('b') THEN 'B' + WHEN var('a') THEN 'A' + ELSE 'no result' + END +} {{no result}} +do_test e_expr-21.1.4 { set varlist } {c b a} + +# EVIDENCE-OF: R-39009-25596 The result of the CASE expression is the +# evaluation of the THEN expression that corresponds to the first WHEN +# expression that evaluates to true. +# +foreach {a b c} {0 1 0} break +do_execsql_test e_expr-21.2.1 { + SELECT CASE WHEN var('a') THEN 'A' + WHEN var('b') THEN 'B' + WHEN var('c') THEN 'C' + ELSE 'no result' + END +} {B} +foreach {a b c} {0 1 1} break +do_execsql_test e_expr-21.2.2 { + SELECT CASE WHEN var('a') THEN 'A' + WHEN var('b') THEN 'B' + WHEN var('c') THEN 'C' + ELSE 'no result' + END +} {B} +foreach {a b c} {0 0 1} break +do_execsql_test e_expr-21.2.3 { + SELECT CASE WHEN var('a') THEN 'A' + WHEN var('b') THEN 'B' + WHEN var('c') THEN 'C' + ELSE 'no result' + END +} {C} + +# EVIDENCE-OF: R-24227-04807 Or, if none of the WHEN expressions +# evaluate to true, the result of evaluating the ELSE expression, if +# any. +# +foreach {a b c} {0 0 0} break +do_execsql_test e_expr-21.3.1 { + SELECT CASE WHEN var('a') THEN 'A' + WHEN var('b') THEN 'B' + WHEN var('c') THEN 'C' + ELSE 'no result' + END +} {{no result}} + +# EVIDENCE-OF: R-14168-07579 If there is no ELSE expression and none of +# the WHEN expressions are true, then the overall result is NULL. +# +db nullvalue null +do_execsql_test e_expr-21.3.2 { + SELECT CASE WHEN var('a') THEN 'A' + WHEN var('b') THEN 'B' + WHEN var('c') THEN 'C' + END +} {null} +db nullvalue {} + +# EVIDENCE-OF: R-13943-13592 A NULL result is considered untrue when +# evaluating WHEN terms. +# +do_execsql_test e_expr-21.4.1 { + SELECT CASE WHEN NULL THEN 'A' WHEN 1 THEN 'B' END, iif(NULL,8,99); +} {B 99} +do_execsql_test e_expr-21.4.2 { + SELECT CASE WHEN 0 THEN 'A' WHEN NULL THEN 'B' ELSE 'C' END, iif(0,8,99); +} {C 99} + +# EVIDENCE-OF: R-38620-19499 In a CASE with a base expression, the base +# expression is evaluated just once and the result is compared against +# the evaluation of each WHEN expression from left to right. +# +# Note: This test case tests the "evaluated just once" part of the above +# statement. Tests associated with the next two statements test that the +# comparisons take place. +# +foreach {a b c} [list [expr 3] [expr 4] [expr 5]] break +set ::varlist [list] +do_execsql_test e_expr-22.1.1 { + SELECT CASE var('a') WHEN 1 THEN 'A' WHEN 2 THEN 'B' WHEN 3 THEN 'C' END +} {C} +do_test e_expr-22.1.2 { set ::varlist } {a} + +# EVIDENCE-OF: R-07667-49537 The result of the CASE expression is the +# evaluation of the THEN expression that corresponds to the first WHEN +# expression for which the comparison is true. +# +do_execsql_test e_expr-22.2.1 { + SELECT CASE 23 WHEN 1 THEN 'A' WHEN 23 THEN 'B' WHEN 23 THEN 'C' END +} {B} +do_execsql_test e_expr-22.2.2 { + SELECT CASE 1 WHEN 1 THEN 'A' WHEN 23 THEN 'B' WHEN 23 THEN 'C' END +} {A} + +# EVIDENCE-OF: R-47543-32145 Or, if none of the WHEN expressions +# evaluate to a value equal to the base expression, the result of +# evaluating the ELSE expression, if any. +# +do_execsql_test e_expr-22.3.1 { + SELECT CASE 24 WHEN 1 THEN 'A' WHEN 23 THEN 'B' WHEN 23 THEN 'C' ELSE 'D' END +} {D} + +# EVIDENCE-OF: R-54721-48557 If there is no ELSE expression and none of +# the WHEN expressions produce a result equal to the base expression, +# the overall result is NULL. +# +do_execsql_test e_expr-22.4.1 { + SELECT CASE 24 WHEN 1 THEN 'A' WHEN 23 THEN 'B' WHEN 23 THEN 'C' END +} {{}} +db nullvalue null +do_execsql_test e_expr-22.4.2 { + SELECT CASE 24 WHEN 1 THEN 'A' WHEN 23 THEN 'B' WHEN 23 THEN 'C' END +} {null} +db nullvalue {} + +# EVIDENCE-OF: R-11479-62774 When comparing a base expression against a +# WHEN expression, the same collating sequence, affinity, and +# NULL-handling rules apply as if the base expression and WHEN +# expression are respectively the left- and right-hand operands of an = +# operator. +# +proc rev {str} { + set ret "" + set chars [split $str] + for {set i [expr [llength $chars]-1]} {$i>=0} {incr i -1} { + append ret [lindex $chars $i] + } + set ret +} +proc reverse {lhs rhs} { + string compare [rev $lhs] [rev $rhs] +} +db collate reverse reverse +do_execsql_test e_expr-23.1.1 { + CREATE TABLE t1( + a TEXT COLLATE NOCASE, + b COLLATE REVERSE, + c INTEGER, + d BLOB + ); + INSERT INTO t1 VALUES('abc', 'cba', 55, 34.5); +} {} +do_execsql_test e_expr-23.1.2 { + SELECT CASE a WHEN 'xyz' THEN 'A' WHEN 'AbC' THEN 'B' END FROM t1 +} {B} +do_execsql_test e_expr-23.1.3 { + SELECT CASE 'AbC' WHEN 'abc' THEN 'A' WHEN a THEN 'B' END FROM t1 +} {B} +do_execsql_test e_expr-23.1.4 { + SELECT CASE a WHEN b THEN 'A' ELSE 'B' END FROM t1 +} {B} +do_execsql_test e_expr-23.1.5 { + SELECT CASE b WHEN a THEN 'A' ELSE 'B' END FROM t1 +} {B} +do_execsql_test e_expr-23.1.6 { + SELECT CASE 55 WHEN '55' THEN 'A' ELSE 'B' END +} {B} +do_execsql_test e_expr-23.1.7 { + SELECT CASE c WHEN '55' THEN 'A' ELSE 'B' END FROM t1 +} {A} +do_execsql_test e_expr-23.1.8 { + SELECT CASE '34.5' WHEN d THEN 'A' ELSE 'B' END FROM t1 +} {B} +do_execsql_test e_expr-23.1.9 { + SELECT CASE NULL WHEN NULL THEN 'A' ELSE 'B' END +} {B} + +# EVIDENCE-OF: R-37304-39405 If the base expression is NULL then the +# result of the CASE is always the result of evaluating the ELSE +# expression if it exists, or NULL if it does not. +# +do_execsql_test e_expr-24.1.1 { + SELECT CASE NULL WHEN 'abc' THEN 'A' WHEN 'def' THEN 'B' END; +} {{}} +do_execsql_test e_expr-24.1.2 { + SELECT CASE NULL WHEN 'abc' THEN 'A' WHEN 'def' THEN 'B' ELSE 'C' END; +} {C} + +# EVIDENCE-OF: R-56280-17369 Both forms of the CASE expression use lazy, +# or short-circuit, evaluation. +# +set varlist [list] +foreach {a b c} {0 1 0} break +do_execsql_test e_expr-25.1.1 { + SELECT CASE WHEN var('a') THEN 'A' + WHEN var('b') THEN 'B' + WHEN var('c') THEN 'C' + END +} {B} +do_test e_expr-25.1.2 { set ::varlist } {a b} +set varlist [list] +do_execsql_test e_expr-25.1.3 { + SELECT CASE '0' WHEN var('a') THEN 'A' + WHEN var('b') THEN 'B' + WHEN var('c') THEN 'C' + END +} {A} +do_test e_expr-25.1.4 { set ::varlist } {a} + +# EVIDENCE-OF: R-34773-62253 The only difference between the following +# two CASE expressions is that the x expression is evaluated exactly +# once in the first example but might be evaluated multiple times in the +# second: CASE x WHEN w1 THEN r1 WHEN w2 THEN r2 ELSE r3 END CASE WHEN +# x=w1 THEN r1 WHEN x=w2 THEN r2 ELSE r3 END +# +proc ceval {x} { + incr ::evalcount + return $x +} +db func ceval ceval +set ::evalcount 0 + +do_execsql_test e_expr-26.1.1 { + CREATE TABLE t2(x, w1, r1, w2, r2, r3); + INSERT INTO t2 VALUES(1, 1, 'R1', 2, 'R2', 'R3'); + INSERT INTO t2 VALUES(2, 1, 'R1', 2, 'R2', 'R3'); + INSERT INTO t2 VALUES(3, 1, 'R1', 2, 'R2', 'R3'); +} {} +do_execsql_test e_expr-26.1.2 { + SELECT CASE x WHEN w1 THEN r1 WHEN w2 THEN r2 ELSE r3 END FROM t2 +} {R1 R2 R3} +do_execsql_test e_expr-26.1.3 { + SELECT CASE WHEN x=w1 THEN r1 WHEN x=w2 THEN r2 ELSE r3 END FROM t2 +} {R1 R2 R3} + +do_execsql_test e_expr-26.1.4 { + SELECT CASE ceval(x) WHEN w1 THEN r1 WHEN w2 THEN r2 ELSE r3 END FROM t2 +} {R1 R2 R3} +do_test e_expr-26.1.5 { set ::evalcount } {3} +set ::evalcount 0 +do_execsql_test e_expr-26.1.6 { + SELECT CASE + WHEN ceval(x)=w1 THEN r1 + WHEN ceval(x)=w2 THEN r2 + ELSE r3 END + FROM t2 +} {R1 R2 R3} +do_test e_expr-26.1.6 { set ::evalcount } {5} + + +#------------------------------------------------------------------------- +# Test statements related to CAST expressions. +# +# EVIDENCE-OF: R-20854-17109 A CAST conversion is similar to the +# conversion that takes place when a column affinity is applied to a +# value except that with the CAST operator the conversion always takes +# place even if the conversion lossy and irreversible, whereas column +# affinity only changes the data type of a value if the change is +# lossless and reversible. +# +do_execsql_test e_expr-27.1.1 { + CREATE TABLE t3(a TEXT, b REAL, c INTEGER); + INSERT INTO t3 VALUES(X'555655', '1.23abc', 4.5); + SELECT typeof(a), a, typeof(b), b, typeof(c), c FROM t3; +} {blob UVU text 1.23abc real 4.5} +do_execsql_test e_expr-27.1.2 { + SELECT + typeof(CAST(X'555655' as TEXT)), CAST(X'555655' as TEXT), + typeof(CAST('1.23abc' as REAL)), CAST('1.23abc' as REAL), + typeof(CAST(4.5 as INTEGER)), CAST(4.5 as INTEGER) +} {text UVU real 1.23 integer 4} + +# EVIDENCE-OF: R-32434-09092 If the value of expr is NULL, then the +# result of the CAST expression is also NULL. +# +do_expr_test e_expr-27.2.1 { CAST(NULL AS integer) } null {} +do_expr_test e_expr-27.2.2 { CAST(NULL AS text) } null {} +do_expr_test e_expr-27.2.3 { CAST(NULL AS blob) } null {} +do_expr_test e_expr-27.2.4 { CAST(NULL AS number) } null {} + +# EVIDENCE-OF: R-29283-15561 Otherwise, the storage class of the result +# is determined by applying the rules for determining column affinity to +# the type-name. +# +# The R-29283-15561 requirement above is demonstrated by all of the +# subsequent e_expr-26 tests. +# +# EVIDENCE-OF: R-43522-35548 Casting a value to a type-name with no +# affinity causes the value to be converted into a BLOB. +# +do_expr_test e_expr-27.3.1 { CAST('abc' AS blob) } blob abc +do_expr_test e_expr-27.3.2 { CAST('def' AS shobblob_x) } blob def +do_expr_test e_expr-27.3.3 { CAST('ghi' AS abbLOb10) } blob ghi + +# EVIDENCE-OF: R-22956-37754 Casting to a BLOB consists of first casting +# the value to TEXT in the encoding of the database connection, then +# interpreting the resulting byte sequence as a BLOB instead of as TEXT. +# +do_qexpr_test e_expr-27.4.1 { CAST('ghi' AS blob) } X'676869' +do_qexpr_test e_expr-27.4.2 { CAST(456 AS blob) } X'343536' +do_qexpr_test e_expr-27.4.3 { CAST(1.78 AS blob) } X'312E3738' +rename db db2 +sqlite3 db :memory: +ifcapable {utf16} { +db eval { PRAGMA encoding = 'utf-16le' } +do_qexpr_test e_expr-27.4.4 { CAST('ghi' AS blob) } X'670068006900' +do_qexpr_test e_expr-27.4.5 { CAST(456 AS blob) } X'340035003600' +do_qexpr_test e_expr-27.4.6 { CAST(1.78 AS blob) } X'31002E0037003800' +} +db close +sqlite3 db :memory: +db eval { PRAGMA encoding = 'utf-16be' } +ifcapable {utf16} { +do_qexpr_test e_expr-27.4.7 { CAST('ghi' AS blob) } X'006700680069' +do_qexpr_test e_expr-27.4.8 { CAST(456 AS blob) } X'003400350036' +do_qexpr_test e_expr-27.4.9 { CAST(1.78 AS blob) } X'0031002E00370038' +} +db close +rename db2 db + +# EVIDENCE-OF: R-04207-37981 To cast a BLOB value to TEXT, the sequence +# of bytes that make up the BLOB is interpreted as text encoded using +# the database encoding. +# +do_expr_test e_expr-28.1.1 { CAST (X'676869' AS text) } text ghi +do_expr_test e_expr-28.1.2 { CAST (X'670068006900' AS text) } text g +rename db db2 +sqlite3 db :memory: +db eval { PRAGMA encoding = 'utf-16le' } +ifcapable {utf16} { +do_expr_test e_expr-28.1.3 { CAST (X'676869' AS text) == 'ghi' } integer 0 +do_expr_test e_expr-28.1.4 { CAST (X'670068006900' AS text) } text ghi +} +db close +rename db2 db + +# EVIDENCE-OF: R-22235-47006 Casting an INTEGER or REAL value into TEXT +# renders the value as if via sqlite3_snprintf() except that the +# resulting TEXT uses the encoding of the database connection. +# +do_expr_test e_expr-28.2.1 { CAST (1 AS text) } text 1 +do_expr_test e_expr-28.2.2 { CAST (45 AS text) } text 45 +do_expr_test e_expr-28.2.3 { CAST (-45 AS text) } text -45 +do_expr_test e_expr-28.2.4 { CAST (8.8 AS text) } text 8.8 +do_expr_test e_expr-28.2.5 { CAST (2.3e+5 AS text) } text 230000.0 +do_expr_test e_expr-28.2.6 { CAST (-2.3e-5 AS text) } text -2.3e-05 +do_expr_test e_expr-28.2.7 { CAST (0.0 AS text) } text 0.0 +do_expr_test e_expr-28.2.7 { CAST (0 AS text) } text 0 + +# EVIDENCE-OF: R-26346-36443 When casting a BLOB value to a REAL, the +# value is first converted to TEXT. +# +do_expr_test e_expr-29.1.1 { CAST (X'312E3233' AS REAL) } real 1.23 +do_expr_test e_expr-29.1.2 { CAST (X'3233302E30' AS REAL) } real 230.0 +do_expr_test e_expr-29.1.3 { CAST (X'2D392E3837' AS REAL) } real -9.87 +do_expr_test e_expr-29.1.4 { CAST (X'302E30303031' AS REAL) } real 0.0001 +rename db db2 +sqlite3 db :memory: +ifcapable {utf16} { +db eval { PRAGMA encoding = 'utf-16le' } +do_expr_test e_expr-29.1.5 { + CAST (X'31002E0032003300' AS REAL) } real 1.23 +do_expr_test e_expr-29.1.6 { + CAST (X'3200330030002E003000' AS REAL) } real 230.0 +do_expr_test e_expr-29.1.7 { + CAST (X'2D0039002E0038003700' AS REAL) } real -9.87 +do_expr_test e_expr-29.1.8 { + CAST (X'30002E003000300030003100' AS REAL) } real 0.0001 +} +db close +rename db2 db + +# EVIDENCE-OF: R-54898-34554 When casting a TEXT value to REAL, the +# longest possible prefix of the value that can be interpreted as a real +# number is extracted from the TEXT value and the remainder ignored. +# +do_expr_test e_expr-29.2.1 { CAST('1.23abcd' AS REAL) } real 1.23 +do_expr_test e_expr-29.2.2 { CAST('1.45.23abcd' AS REAL) } real 1.45 +do_expr_test e_expr-29.2.3 { CAST('-2.12e-01ABC' AS REAL) } real -0.212 +do_expr_test e_expr-29.2.4 { CAST('1 2 3 4' AS REAL) } real 1.0 + +# EVIDENCE-OF: R-11321-47427 Any leading spaces in the TEXT value are +# ignored when converging from TEXT to REAL. +# +do_expr_test e_expr-29.3.1 { CAST(' 1.23abcd' AS REAL) } real 1.23 +do_expr_test e_expr-29.3.2 { CAST(' 1.45.23abcd' AS REAL) } real 1.45 +do_expr_test e_expr-29.3.3 { CAST(' -2.12e-01ABC' AS REAL) } real -0.212 +do_expr_test e_expr-29.3.4 { CAST(' 1 2 3 4' AS REAL) } real 1.0 + +# EVIDENCE-OF: R-22662-28218 If there is no prefix that can be +# interpreted as a real number, the result of the conversion is 0.0. +# +do_expr_test e_expr-29.4.1 { CAST('' AS REAL) } real 0.0 +do_expr_test e_expr-29.4.2 { CAST('not a number' AS REAL) } real 0.0 +do_expr_test e_expr-29.4.3 { CAST('XXI' AS REAL) } real 0.0 + +# EVIDENCE-OF: R-21829-14563 When casting a BLOB value to INTEGER, the +# value is first converted to TEXT. +# +do_expr_test e_expr-30.1.1 { CAST(X'313233' AS INTEGER) } integer 123 +do_expr_test e_expr-30.1.2 { CAST(X'2D363738' AS INTEGER) } integer -678 +do_expr_test e_expr-30.1.3 { + CAST(X'31303030303030' AS INTEGER) +} integer 1000000 +do_expr_test e_expr-30.1.4 { + CAST(X'2D31313235383939393036383432363234' AS INTEGER) +} integer -1125899906842624 + +rename db db2 +sqlite3 db :memory: +ifcapable {utf16} { +execsql { PRAGMA encoding = 'utf-16be' } +do_expr_test e_expr-30.1.5 { CAST(X'003100320033' AS INTEGER) } integer 123 +do_expr_test e_expr-30.1.6 { CAST(X'002D003600370038' AS INTEGER) } integer -678 +do_expr_test e_expr-30.1.7 { + CAST(X'0031003000300030003000300030' AS INTEGER) +} integer 1000000 +do_expr_test e_expr-30.1.8 { + CAST(X'002D0031003100320035003800390039003900300036003800340032003600320034' AS INTEGER) +} integer -1125899906842624 +} +db close +rename db2 db + +# EVIDENCE-OF: R-47612-45842 When casting a TEXT value to INTEGER, the +# longest possible prefix of the value that can be interpreted as an +# integer number is extracted from the TEXT value and the remainder +# ignored. +# +do_expr_test e_expr-30.2.1 { CAST('123abcd' AS INT) } integer 123 +do_expr_test e_expr-30.2.2 { CAST('14523abcd' AS INT) } integer 14523 +do_expr_test e_expr-30.2.3 { CAST('-2.12e-01ABC' AS INT) } integer -2 +do_expr_test e_expr-30.2.4 { CAST('1 2 3 4' AS INT) } integer 1 + +# EVIDENCE-OF: R-34400-33772 Any leading spaces in the TEXT value when +# converting from TEXT to INTEGER are ignored. +# +do_expr_test e_expr-30.3.1 { CAST(' 123abcd' AS INT) } integer 123 +do_expr_test e_expr-30.3.2 { CAST(' 14523abcd' AS INT) } integer 14523 +do_expr_test e_expr-30.3.3 { CAST(' -2.12e-01ABC' AS INT) } integer -2 +do_expr_test e_expr-30.3.4 { CAST(' 1 2 3 4' AS INT) } integer 1 + +# EVIDENCE-OF: R-43164-44276 If there is no prefix that can be +# interpreted as an integer number, the result of the conversion is 0. +# +do_expr_test e_expr-30.4.1 { CAST('' AS INTEGER) } integer 0 +do_expr_test e_expr-30.4.2 { CAST('not a number' AS INTEGER) } integer 0 +do_expr_test e_expr-30.4.3 { CAST('XXI' AS INTEGER) } integer 0 + +# EVIDENCE-OF: R-08980-53124 The CAST operator understands decimal +# integers only — conversion of hexadecimal integers stops at +# the "x" in the "0x" prefix of the hexadecimal integer string and thus +# result of the CAST is always zero. +do_expr_test e_expr-30.5.1 { CAST('0x1234' AS INTEGER) } integer 0 +do_expr_test e_expr-30.5.2 { CAST('0X1234' AS INTEGER) } integer 0 + +# EVIDENCE-OF: R-02752-50091 A cast of a REAL value into an INTEGER +# results in the integer between the REAL value and zero that is closest +# to the REAL value. +# +do_expr_test e_expr-31.1.1 { CAST(3.14159 AS INTEGER) } integer 3 +do_expr_test e_expr-31.1.2 { CAST(1.99999 AS INTEGER) } integer 1 +do_expr_test e_expr-31.1.3 { CAST(-1.99999 AS INTEGER) } integer -1 +do_expr_test e_expr-31.1.4 { CAST(-0.99999 AS INTEGER) } integer 0 + +# EVIDENCE-OF: R-51517-40824 If a REAL is greater than the greatest +# possible signed integer (+9223372036854775807) then the result is the +# greatest possible signed integer and if the REAL is less than the +# least possible signed integer (-9223372036854775808) then the result +# is the least possible signed integer. +# +do_expr_test e_expr-31.2.1 { CAST(2e+50 AS INT) } integer 9223372036854775807 +do_expr_test e_expr-31.2.2 { CAST(-2e+50 AS INT) } integer -9223372036854775808 +do_expr_test e_expr-31.2.3 { + CAST(-9223372036854775809.0 AS INT) +} integer -9223372036854775808 +do_expr_test e_expr-31.2.4 { + CAST(9223372036854775809.0 AS INT) +} integer 9223372036854775807 + + +# EVIDENCE-OF: R-55084-10555 Casting a TEXT or BLOB value into NUMERIC +# yields either an INTEGER or a REAL result. +# +# EVIDENCE-OF: R-48945-04866 If the input text looks like an integer +# (there is no decimal point nor exponent) and the value is small enough +# to fit in a 64-bit signed integer, then the result will be INTEGER. +# +# EVIDENCE-OF: R-47045-23194 Input text that looks like floating point +# (there is a decimal point and/or an exponent) and the text describes a +# value that can be losslessly converted back and forth between IEEE 754 +# 64-bit float and a 51-bit signed integer, then the result is INTEGER. +# +do_expr_test e_expr-32.1.1 { CAST('45' AS NUMERIC) } integer 45 +do_expr_test e_expr-32.1.2 { CAST('45.0' AS NUMERIC) } integer 45 +do_expr_test e_expr-32.1.3 { CAST('45.2' AS NUMERIC) } real 45.2 +do_expr_test e_expr-32.1.4 { CAST('11abc' AS NUMERIC) } integer 11 +do_expr_test e_expr-32.1.5 { CAST('11.1abc' AS NUMERIC) } real 11.1 +do_expr_test e_expr-32.1.6 {CAST( '9.223372036e14' AS NUMERIC)} integer 922337203600000 +do_expr_test e_expr-32.1.7 {CAST('-9.223372036e14' AS NUMERIC)} integer -922337203600000 +do_test e_expr-32.1.8 { + set expr {CAST( '9.223372036e15' AS NUMERIC)} + db eval "SELECT typeof($expr) AS type, printf('%.5e',$expr) AS value" break; + list $type $value +} {real 9.22337e+15} +do_test e_expr-32.1.9 { + set expr {CAST('-9.223372036e15' AS NUMERIC)} + db eval "SELECT typeof($expr) AS type, printf('%.5e',$expr) AS value" break; + list $type $value +} {real -9.22337e+15} + +# EVIDENCE-OF: R-50300-26941 Any text input that describes a value +# outside the range of a 64-bit signed integer yields a REAL result. +# +do_expr_test e_expr-32.1.20 { CAST('9223372036854775807' AS numeric) } \ + integer 9223372036854775807 +do_expr_test e_expr-32.1.21 { CAST('9223372036854775808' AS numeric) } \ + real 9.22337203685478e+18 +do_expr_test e_expr-32.1.22 { CAST('-9223372036854775808' AS numeric) } \ + integer -9223372036854775808 +do_expr_test e_expr-32.1.23 { CAST('-9223372036854775809' AS numeric) } \ + real -9.22337203685478e+18 + +# EVIDENCE-OF: R-30347-18702 Casting a REAL or INTEGER value to NUMERIC +# is a no-op, even if a real value could be losslessly converted to an +# integer. +# +do_expr_test e_expr-32.2.1 { CAST(13.0 AS NUMERIC) } real 13.0 +do_expr_test e_expr-32.2.2 { CAST(13.5 AS NUMERIC) } real 13.5 + +do_expr_test e_expr-32.2.3 { + CAST(-9223372036854775808 AS NUMERIC) +} integer -9223372036854775808 +do_expr_test e_expr-32.2.4 { + CAST(9223372036854775807 AS NUMERIC) +} integer 9223372036854775807 +do_expr_test e_expr-32.2.5 { + CAST('9223372036854775807 ' AS NUMERIC) +} integer 9223372036854775807 +do_expr_test e_expr-32.2.6 { + CAST(' 9223372036854775807 ' AS NUMERIC) +} integer 9223372036854775807 +do_expr_test e_expr-32.2.7 { + CAST(' ' AS NUMERIC) +} integer 0 +do_execsql_test e_expr-32.2.8 { + WITH t1(x) AS (VALUES + ('9000000000000000001'), + ('9000000000000000001x'), + ('9000000000000000001 '), + (' 9000000000000000001 '), + (' 9000000000000000001'), + (' 9000000000000000001.'), + ('9223372036854775807'), + ('9223372036854775807 '), + (' 9223372036854775807 '), + ('9223372036854775808'), + (' 9223372036854775808 '), + ('9223372036854775807.0'), + ('9223372036854775807e+0'), + ('-5.0'), + ('-5e+0')) + SELECT typeof(CAST(x AS NUMERIC)), CAST(x AS NUMERIC)||'' FROM t1; +} [list \ + integer 9000000000000000001 \ + integer 9000000000000000001 \ + integer 9000000000000000001 \ + integer 9000000000000000001 \ + integer 9000000000000000001 \ + real 9.0e+18 \ + integer 9223372036854775807 \ + integer 9223372036854775807 \ + integer 9223372036854775807 \ + real 9.22337203685478e+18 \ + real 9.22337203685478e+18 \ + real 9.22337203685478e+18 \ + real 9.22337203685478e+18 \ + integer -5 \ + integer -5 \ +] + +# EVIDENCE-OF: R-64550-29191 Note that the result from casting any +# non-BLOB value into a BLOB and the result from casting any BLOB value +# into a non-BLOB value may be different depending on whether the +# database encoding is UTF-8, UTF-16be, or UTF-16le. +# +ifcapable {utf16} { +sqlite3 db1 :memory: ; db1 eval { PRAGMA encoding = 'utf-8' } +sqlite3 db2 :memory: ; db2 eval { PRAGMA encoding = 'utf-16le' } +sqlite3 db3 :memory: ; db3 eval { PRAGMA encoding = 'utf-16be' } +foreach {tn castexpr differs} { + 1 { CAST(123 AS BLOB) } 1 + 2 { CAST('' AS BLOB) } 0 + 3 { CAST('abcd' AS BLOB) } 1 + + 4 { CAST(X'abcd' AS TEXT) } 1 + 5 { CAST(X'' AS TEXT) } 0 +} { + set r1 [db1 eval "SELECT typeof($castexpr), quote($castexpr)"] + set r2 [db2 eval "SELECT typeof($castexpr), quote($castexpr)"] + set r3 [db3 eval "SELECT typeof($castexpr), quote($castexpr)"] + + if {$differs} { + set res [expr {$r1!=$r2 && $r2!=$r3}] + } else { + set res [expr {$r1==$r2 && $r2==$r3}] + } + + do_test e_expr-33.1.$tn {set res} 1 +} +db1 close +db2 close +db3 close +} + +#------------------------------------------------------------------------- +# Test statements related to the EXISTS and NOT EXISTS operators. +# +catch { db close } +forcedelete test.db +sqlite3 db test.db + +do_execsql_test e_expr-34.1 { + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t1 VALUES(NULL, 2); + INSERT INTO t1 VALUES(1, NULL); + INSERT INTO t1 VALUES(NULL, NULL); +} {} + +# EVIDENCE-OF: R-25588-27181 The EXISTS operator always evaluates to one +# of the integer values 0 and 1. +# +# This statement is not tested by itself. Instead, all e_expr-34.* tests +# following this point explicitly test that specific invocations of EXISTS +# return either integer 0 or integer 1. +# + +# EVIDENCE-OF: R-58553-63740 If executing the SELECT statement specified +# as the right-hand operand of the EXISTS operator would return one or +# more rows, then the EXISTS operator evaluates to 1. +# +foreach {tn expr} { + 1 { EXISTS ( SELECT a FROM t1 ) } + 2 { EXISTS ( SELECT b FROM t1 ) } + 3 { EXISTS ( SELECT 24 ) } + 4 { EXISTS ( SELECT NULL ) } + 5 { EXISTS ( SELECT a FROM t1 WHERE a IS NULL ) } +} { + do_expr_test e_expr-34.2.$tn $expr integer 1 +} + +# EVIDENCE-OF: R-19673-40972 If executing the SELECT would return no +# rows at all, then the EXISTS operator evaluates to 0. +# +foreach {tn expr} { + 1 { EXISTS ( SELECT a FROM t1 WHERE 0) } + 2 { EXISTS ( SELECT b FROM t1 WHERE a = 5) } + 3 { EXISTS ( SELECT 24 WHERE 0) } + 4 { EXISTS ( SELECT NULL WHERE 1=2) } +} { + do_expr_test e_expr-34.3.$tn $expr integer 0 +} + +# EVIDENCE-OF: R-35109-49139 The number of columns in each row returned +# by the SELECT statement (if any) and the specific values returned have +# no effect on the results of the EXISTS operator. +# +foreach {tn expr res} { + 1 { EXISTS ( SELECT * FROM t1 ) } 1 + 2 { EXISTS ( SELECT *, *, * FROM t1 ) } 1 + 3 { EXISTS ( SELECT 24, 25 ) } 1 + 4 { EXISTS ( SELECT NULL, NULL, NULL ) } 1 + 5 { EXISTS ( SELECT a,b,a||b FROM t1 WHERE a IS NULL ) } 1 + + 6 { EXISTS ( SELECT a, a FROM t1 WHERE 0) } 0 + 7 { EXISTS ( SELECT b, b, a FROM t1 WHERE a = 5) } 0 + 8 { EXISTS ( SELECT 24, 46, 89 WHERE 0) } 0 + 9 { EXISTS ( SELECT NULL, NULL WHERE 1=2) } 0 +} { + do_expr_test e_expr-34.4.$tn $expr integer $res +} + +# EVIDENCE-OF: R-10645-12439 In particular, rows containing NULL values +# are not handled any differently from rows without NULL values. +# +foreach {tn e1 e2} { + 1 { EXISTS (SELECT 'not null') } { EXISTS (SELECT NULL) } + 2 { EXISTS (SELECT NULL FROM t1) } { EXISTS (SELECT 'bread' FROM t1) } +} { + set res [db one "SELECT $e1"] + do_expr_test e_expr-34.5.${tn}a $e1 integer $res + do_expr_test e_expr-34.5.${tn}b $e2 integer $res +} + +#------------------------------------------------------------------------- +# Test statements related to scalar sub-queries. +# + +catch { db close } +forcedelete test.db +sqlite3 db test.db +do_test e_expr-35.0 { + execsql { + CREATE TABLE t2(a, b); + INSERT INTO t2 VALUES('one', 'two'); + INSERT INTO t2 VALUES('three', NULL); + INSERT INTO t2 VALUES(4, 5.0); + } +} {} + +# EVIDENCE-OF: R-43573-23448 A SELECT statement enclosed in parentheses +# is a subquery. +# +# EVIDENCE-OF: R-56294-03966 All types of SELECT statement, including +# aggregate and compound SELECT queries (queries with keywords like +# UNION or EXCEPT) are allowed as scalar subqueries. +# +do_expr_test e_expr-35.1.1 { (SELECT 35) } integer 35 +do_expr_test e_expr-35.1.2 { (SELECT NULL) } null {} + +do_expr_test e_expr-35.1.3 { (SELECT count(*) FROM t2) } integer 3 +do_expr_test e_expr-35.1.4 { (SELECT 4 FROM t2) } integer 4 + +do_expr_test e_expr-35.1.5 { + (SELECT b FROM t2 UNION SELECT a+1 FROM t2) +} null {} +do_expr_test e_expr-35.1.6 { + (SELECT a FROM t2 UNION SELECT COALESCE(b, 55) FROM t2 ORDER BY 1) +} integer 4 + +# EVIDENCE-OF: R-43101-20178 A subquery that returns two or more columns +# is a row value subquery and can only be used as an operand of a +# comparison operator or as the value in an UPDATE SET clause whose +# column name list has the same size. +# +# The following block tests that errors are returned in a bunch of cases +# where a subquery returns more than one column. +# +set M {/1 {sub-select returns [23] columns - expected 1}/} +foreach {tn sql} { + 1 { SELECT (SELECT * FROM t2 UNION SELECT a+1, b+1 FROM t2) } + 2 { SELECT (SELECT * FROM t2 UNION SELECT a+1, b+1 FROM t2 ORDER BY 1) } + 3 { SELECT (SELECT 1, 2) } + 4 { SELECT (SELECT NULL, NULL, NULL) } + 5 { SELECT (SELECT * FROM t2) } + 6 { SELECT (SELECT * FROM (SELECT 1, 2, 3)) } +} { + do_catchsql_test e_expr-35.2.$tn $sql $M +} + +# EVIDENCE-OF: R-18318-14995 The value of a subquery expression is the +# first row of the result from the enclosed SELECT statement. +# +do_execsql_test e_expr-36.3.1 { + CREATE TABLE t4(x, y); + INSERT INTO t4 VALUES(1, 'one'); + INSERT INTO t4 VALUES(2, 'two'); + INSERT INTO t4 VALUES(3, 'three'); +} {} + +foreach {tn expr restype resval} { + 2 { ( SELECT x FROM t4 ORDER BY x ) } integer 1 + 3 { ( SELECT x FROM t4 ORDER BY y ) } integer 1 + 4 { ( SELECT x FROM t4 ORDER BY x DESC ) } integer 3 + 5 { ( SELECT x FROM t4 ORDER BY y DESC ) } integer 2 + 6 { ( SELECT y FROM t4 ORDER BY y DESC ) } text two + + 7 { ( SELECT sum(x) FROM t4 ) } integer 6 + 8 { ( SELECT string_agg(y,'') FROM t4 ) } text onetwothree + 9 { ( SELECT max(x) FROM t4 WHERE y LIKE '___') } integer 2 + +} { + do_expr_test e_expr-36.3.$tn $expr $restype $resval +} + +# EVIDENCE-OF: R-52325-25449 The value of a subquery expression is NULL +# if the enclosed SELECT statement returns no rows. +# +foreach {tn expr} { + 1 { ( SELECT x FROM t4 WHERE x>3 ORDER BY x ) } + 2 { ( SELECT x FROM t4 WHERE y<'one' ORDER BY y ) } +} { + do_expr_test e_expr-36.4.$tn $expr null {} +} + +# EVIDENCE-OF: R-62477-06476 For example, the values NULL, 0.0, 0, +# 'english' and '0' are all considered to be false. +# +do_execsql_test e_expr-37.1 { + SELECT CASE WHEN NULL THEN 'true' ELSE 'false' END, iif(NULL,'true','false'); +} {false false} +do_execsql_test e_expr-37.2 { + SELECT CASE WHEN 0.0 THEN 'true' ELSE 'false' END, iif(0.0,'true','false'); +} {false false} +do_execsql_test e_expr-37.3 { + SELECT CASE WHEN 0 THEN 'true' ELSE 'false' END, iif(0,'true','false'); +} {false false} +do_execsql_test e_expr-37.4 { + SELECT CASE WHEN 'engligh' THEN 'true' ELSE 'false' END, iif('engligh','true','false'); +} {false false} +do_execsql_test e_expr-37.5 { + SELECT CASE WHEN '0' THEN 'true' ELSE 'false' END, iif('0','true','false'); +} {false false} + +# EVIDENCE-OF: R-55532-10108 Values 1, 1.0, 0.1, -0.1 and '1english' are +# considered to be true. +# +do_execsql_test e_expr-37.6 { + SELECT CASE WHEN 1 THEN 'true' ELSE 'false' END, iif(1,'true','false'); +} {true true} +do_execsql_test e_expr-37.7 { + SELECT CASE WHEN 1.0 THEN 'true' ELSE 'false' END, iif(1.0,'true','false'); +} {true true} +do_execsql_test e_expr-37.8 { + SELECT CASE WHEN 0.1 THEN 'true' ELSE 'false' END, iif(0.1,'true','false'); +} {true true} +do_execsql_test e_expr-37.9 { + SELECT CASE WHEN -0.1 THEN 'true' ELSE 'false' END, iif(-0.1,'true','false'); +} {true true} +do_execsql_test e_expr-37.10 { + SELECT CASE WHEN '1english' THEN 'true' ELSE 'false' END, iif('1engl','true','false'); +} {true true} + + +finish_test diff --git a/test/e_fkey.test b/test/e_fkey.test new file mode 100644 index 0000000..3662a39 --- /dev/null +++ b/test/e_fkey.test @@ -0,0 +1,3047 @@ +# 2009 October 7 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file implements tests to verify the "testable statements" in the +# foreignkeys.in document. +# +# The tests in this file are arranged to mirror the structure of +# foreignkey.in, with one exception: The statements in section 2, which +# deals with enabling/disabling foreign key support, is tested first, +# before section 1. This is because some statements in section 2 deal +# with builds that do not include complete foreign key support (because +# either SQLITE_OMIT_TRIGGER or SQLITE_OMIT_FOREIGN_KEY was defined +# at build time). +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +proc eqp {sql {db db}} { + uplevel [subst -nocommands { + set eqpres [list] + $db eval "$sql" { + lappend eqpres [set detail] + } + set eqpres + }] +} + +proc do_detail_test {tn sql res} { + set normalres [list {*}$res] + uplevel [subst -nocommands { + do_test $tn { + eqp { $sql } + } {$normalres} + }] +} + +########################################################################### +### SECTION 2: Enabling Foreign Key Support +########################################################################### + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-37672-59189 In order to use foreign key constraints in +# SQLite, the library must be compiled with neither +# SQLITE_OMIT_FOREIGN_KEY nor SQLITE_OMIT_TRIGGER defined. +# +ifcapable trigger&&foreignkey { + do_test e_fkey-1 { + execsql { + PRAGMA foreign_keys = ON; + CREATE TABLE p(i PRIMARY KEY); + CREATE TABLE c(j REFERENCES p ON UPDATE CASCADE); + INSERT INTO p VALUES('hello'); + INSERT INTO c VALUES('hello'); + UPDATE p SET i = 'world'; + SELECT * FROM c; + } + } {world} +} + +#------------------------------------------------------------------------- +# Test the effects of defining OMIT_TRIGGER but not OMIT_FOREIGN_KEY. +# +# EVIDENCE-OF: R-10109-20452 If SQLITE_OMIT_TRIGGER is defined but +# SQLITE_OMIT_FOREIGN_KEY is not, then SQLite behaves as it did prior to +# version 3.6.19 (2009-10-14) - foreign key definitions are parsed and +# may be queried using PRAGMA foreign_key_list, but foreign key +# constraints are not enforced. +# +# Specifically, test that "PRAGMA foreign_keys" is a no-op in this case. +# When using the pragma to query the current setting, 0 rows are returned. +# +# EVIDENCE-OF: R-22567-44039 The PRAGMA foreign_keys command is a no-op +# in this configuration. +# +# EVIDENCE-OF: R-41784-13339 Tip: If the command "PRAGMA foreign_keys" +# returns no data instead of a single row containing "0" or "1", then +# the version of SQLite you are using does not support foreign keys +# (either because it is older than 3.6.19 or because it was compiled +# with SQLITE_OMIT_FOREIGN_KEY or SQLITE_OMIT_TRIGGER defined). +# +reset_db +ifcapable !trigger&&foreignkey { + do_test e_fkey-2.1 { + execsql { + PRAGMA foreign_keys = ON; + CREATE TABLE p(i PRIMARY KEY); + CREATE TABLE c(j REFERENCES p ON UPDATE CASCADE); + INSERT INTO p VALUES('hello'); + INSERT INTO c VALUES('hello'); + UPDATE p SET i = 'world'; + SELECT * FROM c; + } + } {hello} + do_test e_fkey-2.2 { + execsql { PRAGMA foreign_key_list(c) } + } {0 0 p j {} CASCADE {NO ACTION} NONE} + do_test e_fkey-2.3 { + execsql { PRAGMA foreign_keys } + } {} +} + + +#------------------------------------------------------------------------- +# Test the effects of defining OMIT_FOREIGN_KEY. +# +# EVIDENCE-OF: R-58428-36660 If OMIT_FOREIGN_KEY is defined, then +# foreign key definitions cannot even be parsed (attempting to specify a +# foreign key definition is a syntax error). +# +# Specifically, test that foreign key constraints cannot even be parsed +# in such a build. +# +reset_db +ifcapable !foreignkey { + do_test e_fkey-3.1 { + execsql { CREATE TABLE p(i PRIMARY KEY) } + catchsql { CREATE TABLE c(j REFERENCES p ON UPDATE CASCADE) } + } {1 {near "ON": syntax error}} + do_test e_fkey-3.2 { + # This is allowed, as in this build, "REFERENCES" is not a keyword. + # The declared datatype of column j is "REFERENCES p". + execsql { CREATE TABLE c(j REFERENCES p) } + } {} + do_test e_fkey-3.3 { + execsql { PRAGMA table_info(c) } + } {0 j {REFERENCES p} 0 {} 0} + do_test e_fkey-3.4 { + execsql { PRAGMA foreign_key_list(c) } + } {} + do_test e_fkey-3.5 { + execsql { PRAGMA foreign_keys } + } {} +} + +ifcapable !foreignkey||!trigger { finish_test ; return } +reset_db + + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-07280-60510 Assuming the library is compiled with +# foreign key constraints enabled, it must still be enabled by the +# application at runtime, using the PRAGMA foreign_keys command. +# +# This also tests that foreign key constraints are disabled by default. +# +# EVIDENCE-OF: R-44261-39702 Foreign key constraints are disabled by +# default (for backwards compatibility), so must be enabled separately +# for each database connection. +# +drop_all_tables +do_test e_fkey-4.1 { + execsql { + CREATE TABLE p(i PRIMARY KEY); + CREATE TABLE c(j REFERENCES p ON UPDATE CASCADE); + INSERT INTO p VALUES('hello'); + INSERT INTO c VALUES('hello'); + UPDATE p SET i = 'world'; + SELECT * FROM c; + } +} {hello} +do_test e_fkey-4.2 { + execsql { + DELETE FROM c; + DELETE FROM p; + PRAGMA foreign_keys = ON; + INSERT INTO p VALUES('hello'); + INSERT INTO c VALUES('hello'); + UPDATE p SET i = 'world'; + SELECT * FROM c; + } +} {world} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-08013-37737 The application can also use a PRAGMA +# foreign_keys statement to determine if foreign keys are currently +# enabled. + +# +# This also tests the example code in section 2 of foreignkeys.in. +# +# EVIDENCE-OF: R-11255-19907 +# +reset_db +do_test e_fkey-5.1 { + execsql { PRAGMA foreign_keys } +} {0} +do_test e_fkey-5.2 { + execsql { + PRAGMA foreign_keys = ON; + PRAGMA foreign_keys; + } +} {1} +do_test e_fkey-5.3 { + execsql { + PRAGMA foreign_keys = OFF; + PRAGMA foreign_keys; + } +} {0} + +#------------------------------------------------------------------------- +# Test that it is not possible to enable or disable foreign key support +# while not in auto-commit mode. +# +# EVIDENCE-OF: R-46649-58537 It is not possible to enable or disable +# foreign key constraints in the middle of a multi-statement transaction +# (when SQLite is not in autocommit mode). Attempting to do so does not +# return an error; it simply has no effect. +# +reset_db +do_test e_fkey-6.1 { + execsql { + PRAGMA foreign_keys = ON; + CREATE TABLE t1(a UNIQUE, b); + CREATE TABLE t2(c, d REFERENCES t1(a)); + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t2 VALUES(2, 1); + BEGIN; + PRAGMA foreign_keys = OFF; + } + catchsql { + DELETE FROM t1 + } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-6.2 { + execsql { PRAGMA foreign_keys } +} {1} +do_test e_fkey-6.3 { + execsql { + COMMIT; + PRAGMA foreign_keys = OFF; + BEGIN; + PRAGMA foreign_keys = ON; + DELETE FROM t1; + PRAGMA foreign_keys; + } +} {0} +do_test e_fkey-6.4 { + execsql COMMIT +} {} + +########################################################################### +### SECTION 1: Introduction to Foreign Key Constraints +########################################################################### +execsql "PRAGMA foreign_keys = ON" + +#------------------------------------------------------------------------- +# Verify that the syntax in the first example in section 1 is valid. +# +# EVIDENCE-OF: R-04042-24825 To do so, a foreign key definition may be +# added by modifying the declaration of the track table to the +# following: CREATE TABLE track( trackid INTEGER, trackname TEXT, +# trackartist INTEGER, FOREIGN KEY(trackartist) REFERENCES +# artist(artistid) ); +# +do_test e_fkey-7.1 { + execsql { + CREATE TABLE artist( + artistid INTEGER PRIMARY KEY, + artistname TEXT + ); + CREATE TABLE track( + trackid INTEGER, + trackname TEXT, + trackartist INTEGER, + FOREIGN KEY(trackartist) REFERENCES artist(artistid) + ); + } +} {} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-61362-32087 Attempting to insert a row into the track +# table that does not correspond to any row in the artist table will +# fail, +# +do_test e_fkey-8.1 { + catchsql { INSERT INTO track VALUES(1, 'track 1', 1) } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-8.2 { + execsql { INSERT INTO artist VALUES(2, 'artist 1') } + catchsql { INSERT INTO track VALUES(1, 'track 1', 1) } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-8.2 { + execsql { INSERT INTO track VALUES(1, 'track 1', 2) } +} {} + +#------------------------------------------------------------------------- +# Attempting to delete a row from the 'artist' table while there are +# dependent rows in the track table also fails. +# +# EVIDENCE-OF: R-24401-52400 as will attempting to delete a row from the +# artist table when there exist dependent rows in the track table +# +do_test e_fkey-9.1 { + catchsql { DELETE FROM artist WHERE artistid = 2 } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-9.2 { + execsql { + DELETE FROM track WHERE trackartist = 2; + DELETE FROM artist WHERE artistid = 2; + } +} {} + +#------------------------------------------------------------------------- +# If the foreign key column (trackartist) in table 'track' is set to NULL, +# there is no requirement for a matching row in the 'artist' table. +# +# EVIDENCE-OF: R-23980-48859 There is one exception: if the foreign key +# column in the track table is NULL, then no corresponding entry in the +# artist table is required. +# +do_test e_fkey-10.1 { + execsql { + INSERT INTO track VALUES(1, 'track 1', NULL); + INSERT INTO track VALUES(2, 'track 2', NULL); + } +} {} +do_test e_fkey-10.2 { + execsql { SELECT * FROM artist } +} {} +do_test e_fkey-10.3 { + # Setting the trackid to a non-NULL value fails, of course. + catchsql { UPDATE track SET trackartist = 5 WHERE trackid = 1 } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-10.4 { + execsql { + INSERT INTO artist VALUES(5, 'artist 5'); + UPDATE track SET trackartist = 5 WHERE trackid = 1; + } + catchsql { DELETE FROM artist WHERE artistid = 5} +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-10.5 { + execsql { + UPDATE track SET trackartist = NULL WHERE trackid = 1; + DELETE FROM artist WHERE artistid = 5; + } +} {} + +#------------------------------------------------------------------------- +# Test that the following is true fo all rows in the track table: +# +# trackartist IS NULL OR +# EXISTS(SELECT 1 FROM artist WHERE artistid=trackartist) +# +# EVIDENCE-OF: R-52486-21352 Expressed in SQL, this means that for every +# row in the track table, the following expression evaluates to true: +# trackartist IS NULL OR EXISTS(SELECT 1 FROM artist WHERE +# artistid=trackartist) + +# This procedure executes a test case to check that statement +# R-52486-21352 is true after executing the SQL statement passed. +# as the second argument. +proc test_r52486_21352 {tn sql} { + set res [catchsql $sql] + set results { + {0 {}} + {1 {UNIQUE constraint failed: artist.artistid}} + {1 {FOREIGN KEY constraint failed}} + } + if {[lsearch $results $res]<0} { + error $res + } + + do_test e_fkey-11.$tn { + execsql { + SELECT count(*) FROM track WHERE NOT ( + trackartist IS NULL OR + EXISTS(SELECT 1 FROM artist WHERE artistid=trackartist) + ) + } + } {0} +} + +# Execute a series of random INSERT, UPDATE and DELETE operations +# (some of which may fail due to FK or PK constraint violations) on +# the two tables in the example schema. Test that R-52486-21352 +# is true after executing each operation. +# +set Template { + {INSERT INTO track VALUES($t, 'track $t', $a)} + {DELETE FROM track WHERE trackid = $t} + {UPDATE track SET trackartist = $a WHERE trackid = $t} + {INSERT INTO artist VALUES($a, 'artist $a')} + {DELETE FROM artist WHERE artistid = $a} + {UPDATE artist SET artistid = $a2 WHERE artistid = $a} +} +for {set i 0} {$i < 500} {incr i} { + set a [expr int(rand()*10)] + set a2 [expr int(rand()*10)] + set t [expr int(rand()*50)] + set sql [subst [lindex $Template [expr int(rand()*6)]]] + + test_r52486_21352 $i $sql +} + +#------------------------------------------------------------------------- +# Check that a NOT NULL constraint can be added to the example schema +# to prohibit NULL child keys from being inserted. +# +# EVIDENCE-OF: R-42412-59321 Tip: If the application requires a stricter +# relationship between artist and track, where NULL values are not +# permitted in the trackartist column, simply add the appropriate "NOT +# NULL" constraint to the schema. +# +drop_all_tables +do_test e_fkey-12.1 { + execsql { + CREATE TABLE artist( + artistid INTEGER PRIMARY KEY, + artistname TEXT + ); + CREATE TABLE track( + trackid INTEGER, + trackname TEXT, + trackartist INTEGER NOT NULL, + FOREIGN KEY(trackartist) REFERENCES artist(artistid) + ); + } +} {} +do_test e_fkey-12.2 { + catchsql { INSERT INTO track VALUES(14, 'Mr. Bojangles', NULL) } +} {1 {NOT NULL constraint failed: track.trackartist}} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-16127-35442 +# +# Test an example from foreignkeys.html. +# +drop_all_tables +do_test e_fkey-13.1 { + execsql { + CREATE TABLE artist( + artistid INTEGER PRIMARY KEY, + artistname TEXT + ); + CREATE TABLE track( + trackid INTEGER, + trackname TEXT, + trackartist INTEGER, + FOREIGN KEY(trackartist) REFERENCES artist(artistid) + ); + INSERT INTO artist VALUES(1, 'Dean Martin'); + INSERT INTO artist VALUES(2, 'Frank Sinatra'); + INSERT INTO track VALUES(11, 'That''s Amore', 1); + INSERT INTO track VALUES(12, 'Christmas Blues', 1); + INSERT INTO track VALUES(13, 'My Way', 2); + } +} {} +do_test e_fkey-13.2 { + catchsql { INSERT INTO track VALUES(14, 'Mr. Bojangles', 3) } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-13.3 { + execsql { INSERT INTO track VALUES(14, 'Mr. Bojangles', NULL) } +} {} +do_test e_fkey-13.4 { + catchsql { + UPDATE track SET trackartist = 3 WHERE trackname = 'Mr. Bojangles'; + } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-13.5 { + execsql { + INSERT INTO artist VALUES(3, 'Sammy Davis Jr.'); + UPDATE track SET trackartist = 3 WHERE trackname = 'Mr. Bojangles'; + INSERT INTO track VALUES(15, 'Boogie Woogie', 3); + } +} {} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-15958-50233 +# +# Test the second example from the first section of foreignkeys.html. +# +do_test e_fkey-14.1 { + catchsql { + DELETE FROM artist WHERE artistname = 'Frank Sinatra'; + } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-14.2 { + execsql { + DELETE FROM track WHERE trackname = 'My Way'; + DELETE FROM artist WHERE artistname = 'Frank Sinatra'; + } +} {} +do_test e_fkey-14.3 { + catchsql { + UPDATE artist SET artistid=4 WHERE artistname = 'Dean Martin'; + } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-14.4 { + execsql { + DELETE FROM track WHERE trackname IN('That''s Amore', 'Christmas Blues'); + UPDATE artist SET artistid=4 WHERE artistname = 'Dean Martin'; + } +} {} + + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-56032-24923 The foreign key constraint is satisfied if +# for each row in the child table either one or more of the child key +# columns are NULL, or there exists a row in the parent table for which +# each parent key column contains a value equal to the value in its +# associated child key column. +# +# Test also that the usual comparison rules are used when testing if there +# is a matching row in the parent table of a foreign key constraint. +# +# EVIDENCE-OF: R-57765-12380 In the above paragraph, the term "equal" +# means equal when values are compared using the rules specified here. +# +drop_all_tables +do_test e_fkey-15.1 { + execsql { + CREATE TABLE par(p PRIMARY KEY); + CREATE TABLE chi(c REFERENCES par); + + INSERT INTO par VALUES(1); + INSERT INTO par VALUES('1'); + INSERT INTO par VALUES(X'31'); + SELECT typeof(p) FROM par; + } +} {integer text blob} + +proc test_efkey_45 {tn isError sql} { + do_test e_fkey-15.$tn.1 " + catchsql {$sql} + " [lindex {{0 {}} {1 {FOREIGN KEY constraint failed}}} $isError] + + do_test e_fkey-15.$tn.2 { + execsql { + SELECT * FROM chi WHERE c IS NOT NULL AND c NOT IN (SELECT p FROM par) + } + } {} +} + +test_efkey_45 1 0 "INSERT INTO chi VALUES(1)" +test_efkey_45 2 1 "INSERT INTO chi VALUES('1.0')" +test_efkey_45 3 0 "INSERT INTO chi VALUES('1')" +test_efkey_45 4 1 "DELETE FROM par WHERE p = '1'" +test_efkey_45 5 0 "DELETE FROM chi WHERE c = '1'" +test_efkey_45 6 0 "DELETE FROM par WHERE p = '1'" +test_efkey_45 7 1 "INSERT INTO chi VALUES('1')" +test_efkey_45 8 0 "INSERT INTO chi VALUES(X'31')" +test_efkey_45 9 1 "INSERT INTO chi VALUES(X'32')" + +#------------------------------------------------------------------------- +# Specifically, test that when comparing child and parent key values the +# default collation sequence of the parent key column is used. +# +# EVIDENCE-OF: R-15796-47513 When comparing text values, the collating +# sequence associated with the parent key column is always used. +# +drop_all_tables +do_test e_fkey-16.1 { + execsql { + CREATE TABLE t1(a COLLATE nocase PRIMARY KEY); + CREATE TABLE t2(b REFERENCES t1); + } +} {} +do_test e_fkey-16.2 { + execsql { + INSERT INTO t1 VALUES('oNe'); + INSERT INTO t2 VALUES('one'); + INSERT INTO t2 VALUES('ONE'); + UPDATE t2 SET b = 'OnE'; + UPDATE t1 SET a = 'ONE'; + } +} {} +do_test e_fkey-16.3 { + catchsql { UPDATE t2 SET b = 'two' WHERE rowid = 1 } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-16.4 { + catchsql { DELETE FROM t1 WHERE rowid = 1 } +} {1 {FOREIGN KEY constraint failed}} + +#------------------------------------------------------------------------- +# Specifically, test that when comparing child and parent key values the +# affinity of the parent key column is applied to the child key value +# before the comparison takes place. +# +# EVIDENCE-OF: R-04240-13860 When comparing values, if the parent key +# column has an affinity, then that affinity is applied to the child key +# value before the comparison is performed. +# +drop_all_tables +do_test e_fkey-17.1 { + execsql { + CREATE TABLE t1(a NUMERIC PRIMARY KEY); + CREATE TABLE t2(b TEXT REFERENCES t1); + } +} {} +do_test e_fkey-17.2 { + execsql { + INSERT INTO t1 VALUES(1); + INSERT INTO t1 VALUES(2); + INSERT INTO t1 VALUES('three'); + INSERT INTO t2 VALUES('2.0'); + SELECT b, typeof(b) FROM t2; + } +} {2.0 text} +do_test e_fkey-17.3 { + execsql { SELECT typeof(a) FROM t1 } +} {integer integer text} +do_test e_fkey-17.4 { + catchsql { DELETE FROM t1 WHERE rowid = 2 } +} {1 {FOREIGN KEY constraint failed}} + +########################################################################### +### SECTION 3: Required and Suggested Database Indexes +########################################################################### + +#------------------------------------------------------------------------- +# A parent key must be either a PRIMARY KEY, subject to a UNIQUE +# constraint, or have a UNIQUE index created on it. +# +# EVIDENCE-OF: R-13435-26311 Usually, the parent key of a foreign key +# constraint is the primary key of the parent table. If they are not the +# primary key, then the parent key columns must be collectively subject +# to a UNIQUE constraint or have a UNIQUE index. +# +# Also test that if a parent key is not subject to a PRIMARY KEY or UNIQUE +# constraint, but does have a UNIQUE index created on it, then the UNIQUE index +# must use the default collation sequences associated with the parent key +# columns. +# +# EVIDENCE-OF: R-00376-39212 If the parent key columns have a UNIQUE +# index, then that index must use the collation sequences that are +# specified in the CREATE TABLE statement for the parent table. +# +drop_all_tables +do_test e_fkey-18.1 { + execsql { + CREATE TABLE t2(a REFERENCES t1(x)); + } +} {} +proc test_efkey_57 {tn isError sql} { + catchsql { DROP TABLE t1 } + execsql $sql + do_test e_fkey-18.$tn { + catchsql { INSERT INTO t2 VALUES(NULL) } + } [lindex {{0 {}} {/1 {foreign key mismatch - ".*" referencing ".*"}/}} \ + $isError] +} +test_efkey_57 2 0 { CREATE TABLE t1(x PRIMARY KEY) } +test_efkey_57 3 0 { CREATE TABLE t1(x UNIQUE) } +test_efkey_57 4 0 { CREATE TABLE t1(x); CREATE UNIQUE INDEX t1i ON t1(x) } +test_efkey_57 5 1 { + CREATE TABLE t1(x); + CREATE UNIQUE INDEX t1i ON t1(x COLLATE nocase); +} +test_efkey_57 6 1 { CREATE TABLE t1(x) } +test_efkey_57 7 1 { CREATE TABLE t1(x, y, PRIMARY KEY(x, y)) } +test_efkey_57 8 1 { CREATE TABLE t1(x, y, UNIQUE(x, y)) } +test_efkey_57 9 1 { + CREATE TABLE t1(x, y); + CREATE UNIQUE INDEX t1i ON t1(x, y); +} + + +#------------------------------------------------------------------------- +# This block tests an example in foreignkeys.html. Several testable +# statements refer to this example, as follows +# +# EVIDENCE-OF: R-27484-01467 +# +# FK Constraints on child1, child2 and child3 are Ok. +# +# Problem with FK on child4: +# +# EVIDENCE-OF: R-51039-44840 The foreign key declared as part of table +# child4 is an error because even though the parent key column is +# indexed, the index is not UNIQUE. +# +# Problem with FK on child5: +# +# EVIDENCE-OF: R-01060-48788 The foreign key for table child5 is an +# error because even though the parent key column has a unique index, +# the index uses a different collating sequence. +# +# Problem with FK on child6 and child7: +# +# EVIDENCE-OF: R-63088-37469 Tables child6 and child7 are incorrect +# because while both have UNIQUE indices on their parent keys, the keys +# are not an exact match to the columns of a single UNIQUE index. +# +drop_all_tables +do_test e_fkey-19.1 { + execsql { + CREATE TABLE parent(a PRIMARY KEY, b UNIQUE, c, d, e, f); + CREATE UNIQUE INDEX i1 ON parent(c, d); + CREATE INDEX i2 ON parent(e); + CREATE UNIQUE INDEX i3 ON parent(f COLLATE nocase); + + CREATE TABLE child1(f, g REFERENCES parent(a)); -- Ok + CREATE TABLE child2(h, i REFERENCES parent(b)); -- Ok + CREATE TABLE child3(j, k, FOREIGN KEY(j, k) REFERENCES parent(c, d)); -- Ok + CREATE TABLE child4(l, m REFERENCES parent(e)); -- Err + CREATE TABLE child5(n, o REFERENCES parent(f)); -- Err + CREATE TABLE child6(p, q, FOREIGN KEY(p,q) REFERENCES parent(b, c)); -- Err + CREATE TABLE child7(r REFERENCES parent(c)); -- Err + } +} {} +do_test e_fkey-19.2 { + execsql { + INSERT INTO parent VALUES(1, 2, 3, 4, 5, 6); + INSERT INTO child1 VALUES('xxx', 1); + INSERT INTO child2 VALUES('xxx', 2); + INSERT INTO child3 VALUES(3, 4); + } +} {} +do_test e_fkey-19.2 { + catchsql { INSERT INTO child4 VALUES('xxx', 5) } +} {1 {foreign key mismatch - "child4" referencing "parent"}} +do_test e_fkey-19.3 { + catchsql { INSERT INTO child5 VALUES('xxx', 6) } +} {1 {foreign key mismatch - "child5" referencing "parent"}} +do_test e_fkey-19.4 { + catchsql { INSERT INTO child6 VALUES(2, 3) } +} {1 {foreign key mismatch - "child6" referencing "parent"}} +do_test e_fkey-19.5 { + catchsql { INSERT INTO child7 VALUES(3) } +} {1 {foreign key mismatch - "child7" referencing "parent"}} + +#------------------------------------------------------------------------- +# Test errors in the database schema that are detected while preparing +# DML statements. The error text for these messages always matches +# either "foreign key mismatch" or "no such table*" (using [string match]). +# +# EVIDENCE-OF: R-45488-08504 If the database schema contains foreign key +# errors that require looking at more than one table definition to +# identify, then those errors are not detected when the tables are +# created. +# +# EVIDENCE-OF: R-48391-38472 Instead, such errors prevent the +# application from preparing SQL statements that modify the content of +# the child or parent tables in ways that use the foreign keys. +# +# EVIDENCE-OF: R-03108-63659 The English language error message for +# foreign key DML errors is usually "foreign key mismatch" but can also +# be "no such table" if the parent table does not exist. +# +# EVIDENCE-OF: R-35763-48267 Foreign key DML errors are reported if: The +# parent table does not exist, or The parent key columns named in the +# foreign key constraint do not exist, or The parent key columns named +# in the foreign key constraint are not the primary key of the parent +# table and are not subject to a unique constraint using collating +# sequence specified in the CREATE TABLE, or The child table references +# the primary key of the parent without specifying the primary key +# columns and the number of primary key columns in the parent do not +# match the number of child key columns. +# +do_test e_fkey-20.1 { + execsql { + CREATE TABLE c1(c REFERENCES nosuchtable, d); + + CREATE TABLE p2(a, b, UNIQUE(a, b)); + CREATE TABLE c2(c, d, FOREIGN KEY(c, d) REFERENCES p2(a, x)); + + CREATE TABLE p3(a PRIMARY KEY, b); + CREATE TABLE c3(c REFERENCES p3(b), d); + + CREATE TABLE p4(a PRIMARY KEY, b); + CREATE UNIQUE INDEX p4i ON p4(b COLLATE nocase); + CREATE TABLE c4(c REFERENCES p4(b), d); + + CREATE TABLE p5(a PRIMARY KEY, b COLLATE nocase); + CREATE UNIQUE INDEX p5i ON p5(b COLLATE binary); + CREATE TABLE c5(c REFERENCES p5(b), d); + + CREATE TABLE p6(a PRIMARY KEY, b); + CREATE TABLE c6(c, d, FOREIGN KEY(c, d) REFERENCES p6); + + CREATE TABLE p7(a, b, PRIMARY KEY(a, b)); + CREATE TABLE c7(c, d REFERENCES p7); + } +} {} + +foreach {tn tbl ptbl err} { + 2 c1 {} "no such table: main.nosuchtable" + 3 c2 p2 "foreign key mismatch - \"c2\" referencing \"p2\"" + 4 c3 p3 "foreign key mismatch - \"c3\" referencing \"p3\"" + 5 c4 p4 "foreign key mismatch - \"c4\" referencing \"p4\"" + 6 c5 p5 "foreign key mismatch - \"c5\" referencing \"p5\"" + 7 c6 p6 "foreign key mismatch - \"c6\" referencing \"p6\"" + 8 c7 p7 "foreign key mismatch - \"c7\" referencing \"p7\"" +} { + do_test e_fkey-20.$tn.1 { + catchsql "INSERT INTO $tbl VALUES('a', 'b')" + } [list 1 $err] + do_test e_fkey-20.$tn.2 { + catchsql "UPDATE $tbl SET c = ?, d = ?" + } [list 1 $err] + do_test e_fkey-20.$tn.3 { + catchsql "INSERT INTO $tbl SELECT ?, ?" + } [list 1 $err] + + if {$ptbl ne ""} { + do_test e_fkey-20.$tn.4 { + catchsql "DELETE FROM $ptbl" + } [list 1 $err] + do_test e_fkey-20.$tn.5 { + catchsql "UPDATE $ptbl SET a = ?, b = ?" + } [list 1 $err] + do_test e_fkey-20.$tn.6 { + catchsql "INSERT INTO $ptbl SELECT ?, ?" + } [list 1 $err] + } +} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-19353-43643 +# +# Test the example of foreign key mismatch errors caused by implicitly +# mapping a child key to the primary key of the parent table when the +# child key consists of a different number of columns to that primary key. +# +drop_all_tables +do_test e_fkey-21.1 { + execsql { + CREATE TABLE parent2(a, b, PRIMARY KEY(a,b)); + + CREATE TABLE child8(x, y, FOREIGN KEY(x,y) REFERENCES parent2); -- Ok + CREATE TABLE child9(x REFERENCES parent2); -- Err + CREATE TABLE child10(x,y,z, FOREIGN KEY(x,y,z) REFERENCES parent2); -- Err + } +} {} +do_test e_fkey-21.2 { + execsql { + INSERT INTO parent2 VALUES('I', 'II'); + INSERT INTO child8 VALUES('I', 'II'); + } +} {} +do_test e_fkey-21.3 { + catchsql { INSERT INTO child9 VALUES('I') } +} {1 {foreign key mismatch - "child9" referencing "parent2"}} +do_test e_fkey-21.4 { + catchsql { INSERT INTO child9 VALUES('II') } +} {1 {foreign key mismatch - "child9" referencing "parent2"}} +do_test e_fkey-21.5 { + catchsql { INSERT INTO child9 VALUES(NULL) } +} {1 {foreign key mismatch - "child9" referencing "parent2"}} +do_test e_fkey-21.6 { + catchsql { INSERT INTO child10 VALUES('I', 'II', 'III') } +} {1 {foreign key mismatch - "child10" referencing "parent2"}} +do_test e_fkey-21.7 { + catchsql { INSERT INTO child10 VALUES(1, 2, 3) } +} {1 {foreign key mismatch - "child10" referencing "parent2"}} +do_test e_fkey-21.8 { + catchsql { INSERT INTO child10 VALUES(NULL, NULL, NULL) } +} {1 {foreign key mismatch - "child10" referencing "parent2"}} + +#------------------------------------------------------------------------- +# Test errors that are reported when creating the child table. +# Specifically: +# +# * different number of child and parent key columns, and +# * child columns that do not exist. +# +# EVIDENCE-OF: R-23682-59820 By contrast, if foreign key errors can be +# recognized simply by looking at the definition of the child table and +# without having to consult the parent table definition, then the CREATE +# TABLE statement for the child table fails. +# +# These errors are reported whether or not FK support is enabled. +# +# EVIDENCE-OF: R-33883-28833 Foreign key DDL errors are reported +# regardless of whether or not foreign key constraints are enabled when +# the table is created. +# +drop_all_tables +foreach fk [list OFF ON] { + execsql "PRAGMA foreign_keys = $fk" + set i 0 + foreach {sql error} { + "CREATE TABLE child1(a, b, FOREIGN KEY(a, b) REFERENCES p(c))" + {number of columns in foreign key does not match the number of columns in the referenced table} + "CREATE TABLE child2(a, b, FOREIGN KEY(a, b) REFERENCES p(c, d, e))" + {number of columns in foreign key does not match the number of columns in the referenced table} + "CREATE TABLE child2(a, b, FOREIGN KEY(a, c) REFERENCES p(c, d))" + {unknown column "c" in foreign key definition} + "CREATE TABLE child2(a, b, FOREIGN KEY(c, b) REFERENCES p(c, d))" + {unknown column "c" in foreign key definition} + } { + do_test e_fkey-22.$fk.[incr i] { + catchsql $sql + } [list 1 $error] + } +} + +#------------------------------------------------------------------------- +# Test that a REFERENCING clause that does not specify parent key columns +# implicitly maps to the primary key of the parent table. +# +# EVIDENCE-OF: R-43879-08025 Attaching a "REFERENCES " +# clause to a column definition creates a foreign +# key constraint that maps the column to the primary key of +# . +# +do_test e_fkey-23.1 { + execsql { + CREATE TABLE p1(a, b, PRIMARY KEY(a, b)); + CREATE TABLE p2(a, b PRIMARY KEY); + CREATE TABLE c1(c, d, FOREIGN KEY(c, d) REFERENCES p1); + CREATE TABLE c2(a, b REFERENCES p2); + } +} {} +proc test_efkey_60 {tn isError sql} { + do_test e_fkey-23.$tn " + catchsql {$sql} + " [lindex {{0 {}} {1 {FOREIGN KEY constraint failed}}} $isError] +} + +test_efkey_60 2 1 "INSERT INTO c1 VALUES(239, 231)" +test_efkey_60 3 0 "INSERT INTO p1 VALUES(239, 231)" +test_efkey_60 4 0 "INSERT INTO c1 VALUES(239, 231)" +test_efkey_60 5 1 "INSERT INTO c2 VALUES(239, 231)" +test_efkey_60 6 0 "INSERT INTO p2 VALUES(239, 231)" +test_efkey_60 7 0 "INSERT INTO c2 VALUES(239, 231)" + +#------------------------------------------------------------------------- +# Test that an index on on the child key columns of an FK constraint +# is optional. +# +# EVIDENCE-OF: R-15417-28014 Indices are not required for child key +# columns +# +# Also test that if an index is created on the child key columns, it does +# not make a difference whether or not it is a UNIQUE index. +# +# EVIDENCE-OF: R-15741-50893 The child key index does not have to be +# (and usually will not be) a UNIQUE index. +# +drop_all_tables +do_test e_fkey-24.1 { + execsql { + CREATE TABLE parent(x, y, UNIQUE(y, x)); + CREATE TABLE c1(a, b, FOREIGN KEY(a, b) REFERENCES parent(x, y)); + CREATE TABLE c2(a, b, FOREIGN KEY(a, b) REFERENCES parent(x, y)); + CREATE TABLE c3(a, b, FOREIGN KEY(a, b) REFERENCES parent(x, y)); + CREATE INDEX c2i ON c2(a, b); + CREATE UNIQUE INDEX c3i ON c2(b, a); + } +} {} +proc test_efkey_61 {tn isError sql} { + do_test e_fkey-24.$tn " + catchsql {$sql} + " [lindex {{0 {}} {1 {FOREIGN KEY constraint failed}}} $isError] +} +foreach {tn c} [list 2 c1 3 c2 4 c3] { + test_efkey_61 $tn.1 1 "INSERT INTO $c VALUES(1, 2)" + test_efkey_61 $tn.2 0 "INSERT INTO parent VALUES(1, 2)" + test_efkey_61 $tn.3 0 "INSERT INTO $c VALUES(1, 2)" + + execsql "DELETE FROM $c ; DELETE FROM parent" +} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-00279-52283 +# +# Test an example showing that when a row is deleted from the parent +# table, the child table is queried for orphaned rows as follows: +# +# SELECT rowid FROM track WHERE trackartist = ? +# +# EVIDENCE-OF: R-23302-30956 If this SELECT returns any rows at all, +# then SQLite concludes that deleting the row from the parent table +# would violate the foreign key constraint and returns an error. +# +do_test e_fkey-25.1 { + execsql { + CREATE TABLE artist( + artistid INTEGER PRIMARY KEY, + artistname TEXT + ); + CREATE TABLE track( + trackid INTEGER, + trackname TEXT, + trackartist INTEGER, + FOREIGN KEY(trackartist) REFERENCES artist(artistid) + ); + } +} {} +do_detail_test e_fkey-25.2 { + PRAGMA foreign_keys = OFF; + EXPLAIN QUERY PLAN DELETE FROM artist WHERE 1; + EXPLAIN QUERY PLAN SELECT rowid FROM track WHERE trackartist = ?; +} { + {SCAN artist} + {SCAN track} +} +do_detail_test e_fkey-25.3 { + PRAGMA foreign_keys = ON; + EXPLAIN QUERY PLAN DELETE FROM artist WHERE 1; +} { + {SCAN artist} + {SCAN track} +} +do_test e_fkey-25.4 { + execsql { + INSERT INTO artist VALUES(5, 'artist 5'); + INSERT INTO artist VALUES(6, 'artist 6'); + INSERT INTO artist VALUES(7, 'artist 7'); + INSERT INTO track VALUES(1, 'track 1', 5); + INSERT INTO track VALUES(2, 'track 2', 6); + } +} {} + +do_test e_fkey-25.5 { + concat \ + [execsql { SELECT rowid FROM track WHERE trackartist = 5 }] \ + [catchsql { DELETE FROM artist WHERE artistid = 5 }] +} {1 1 {FOREIGN KEY constraint failed}} + +do_test e_fkey-25.6 { + concat \ + [execsql { SELECT rowid FROM track WHERE trackartist = 7 }] \ + [catchsql { DELETE FROM artist WHERE artistid = 7 }] +} {0 {}} + +do_test e_fkey-25.7 { + concat \ + [execsql { SELECT rowid FROM track WHERE trackartist = 6 }] \ + [catchsql { DELETE FROM artist WHERE artistid = 6 }] +} {2 1 {FOREIGN KEY constraint failed}} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-47936-10044 Or, more generally: +# SELECT rowid FROM WHERE = :parent_key_value +# +# Test that when a row is deleted from the parent table of an FK +# constraint, the child table is queried for orphaned rows. The +# query is equivalent to: +# +# SELECT rowid FROM WHERE = :parent_key_value +# +# Also test that when a row is inserted into the parent table, or when the +# parent key values of an existing row are modified, a query equivalent +# to the following is planned. In some cases it is not executed, but it +# is always planned. +# +# SELECT rowid FROM WHERE = :parent_key_value +# +# EVIDENCE-OF: R-61616-46700 Similar queries may be run if the content +# of the parent key is modified or a new row is inserted into the parent +# table. +# +# +drop_all_tables +do_test e_fkey-26.1 { + execsql { CREATE TABLE parent(x, y, UNIQUE(y, x)) } +} {} +foreach {tn sql} { + 2 { + CREATE TABLE child(a, b, FOREIGN KEY(a, b) REFERENCES parent(x, y)) + } + 3 { + CREATE TABLE child(a, b, FOREIGN KEY(a, b) REFERENCES parent(x, y)); + CREATE INDEX childi ON child(a, b); + } + 4 { + CREATE TABLE child(a, b, FOREIGN KEY(a, b) REFERENCES parent(x, y)); + CREATE UNIQUE INDEX childi ON child(b, a); + } +} { + execsql $sql + + execsql {PRAGMA foreign_keys = OFF} + set delete [concat \ + [eqp "DELETE FROM parent WHERE 1"] \ + [eqp "SELECT rowid FROM child WHERE a = ? AND b = ?"] + ] + set update [concat \ + [eqp "UPDATE parent SET x=?, y=?"] \ + [eqp "SELECT rowid FROM child WHERE a = ? AND b = ?"] \ + [eqp "SELECT rowid FROM child WHERE a = ? AND b = ?"] + ] + execsql {PRAGMA foreign_keys = ON} + + do_test e_fkey-26.$tn.1 { eqp "DELETE FROM parent WHERE 1" } $delete + do_test e_fkey-26.$tn.2 { eqp "UPDATE parent set x=?, y=?" } $update + + execsql {DROP TABLE child} +} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-14553-34013 +# +# Test the example schema at the end of section 3. Also test that is +# is "efficient". In this case "efficient" means that foreign key +# related operations on the parent table do not provoke linear scans. +# +drop_all_tables +do_test e_fkey-27.1 { + execsql { + CREATE TABLE artist( + artistid INTEGER PRIMARY KEY, + artistname TEXT + ); + CREATE TABLE track( + trackid INTEGER, + trackname TEXT, + trackartist INTEGER REFERENCES artist + ); + CREATE INDEX trackindex ON track(trackartist); + } +} {} +do_test e_fkey-27.2 { + eqp { INSERT INTO artist VALUES(?, ?) } +} {} +do_detail_test e_fkey-27.3 { + EXPLAIN QUERY PLAN UPDATE artist SET artistid = ?, artistname = ? +} { + {SCAN artist} + {SEARCH track USING COVERING INDEX trackindex (trackartist=?)} + {SEARCH track USING COVERING INDEX trackindex (trackartist=?)} +} +do_detail_test e_fkey-27.4 { + EXPLAIN QUERY PLAN DELETE FROM artist +} { + {SCAN artist} + {SEARCH track USING COVERING INDEX trackindex (trackartist=?)} +} + +########################################################################### +### SECTION 4.1: Composite Foreign Key Constraints +########################################################################### + +#------------------------------------------------------------------------- +# Check that parent and child keys must have the same number of columns. +# +# EVIDENCE-OF: R-41062-34431 Parent and child keys must have the same +# cardinality. +# +foreach {tn sql err} { + 1 "CREATE TABLE c(jj REFERENCES p(x, y))" + {foreign key on jj should reference only one column of table p} + + 2 "CREATE TABLE c(jj REFERENCES p())" {near ")": syntax error} + + 3 "CREATE TABLE c(jj, FOREIGN KEY(jj) REFERENCES p(x, y))" + {number of columns in foreign key does not match the number of columns in the referenced table} + + 4 "CREATE TABLE c(jj, FOREIGN KEY(jj) REFERENCES p())" + {near ")": syntax error} + + 5 "CREATE TABLE c(ii, jj, FOREIGN KEY(jj, ii) REFERENCES p())" + {near ")": syntax error} + + 6 "CREATE TABLE c(ii, jj, FOREIGN KEY(jj, ii) REFERENCES p(x))" + {number of columns in foreign key does not match the number of columns in the referenced table} + + 7 "CREATE TABLE c(ii, jj, FOREIGN KEY(jj, ii) REFERENCES p(x,y,z))" + {number of columns in foreign key does not match the number of columns in the referenced table} +} { + drop_all_tables + do_test e_fkey-28.$tn [list catchsql $sql] [list 1 $err] +} +do_test e_fkey-28.8 { + drop_all_tables + execsql { + CREATE TABLE p(x PRIMARY KEY); + CREATE TABLE c(a, b, FOREIGN KEY(a,b) REFERENCES p); + } + catchsql {DELETE FROM p} +} {1 {foreign key mismatch - "c" referencing "p"}} +do_test e_fkey-28.9 { + drop_all_tables + execsql { + CREATE TABLE p(x, y, PRIMARY KEY(x,y)); + CREATE TABLE c(a REFERENCES p); + } + catchsql {DELETE FROM p} +} {1 {foreign key mismatch - "c" referencing "p"}} + + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-24676-09859 +# +# Test the example schema in the "Composite Foreign Key Constraints" +# section. +# +do_test e_fkey-29.1 { + execsql { + CREATE TABLE album( + albumartist TEXT, + albumname TEXT, + albumcover BINARY, + PRIMARY KEY(albumartist, albumname) + ); + CREATE TABLE song( + songid INTEGER, + songartist TEXT, + songalbum TEXT, + songname TEXT, + FOREIGN KEY(songartist, songalbum) REFERENCES album(albumartist,albumname) + ); + } +} {} + +do_test e_fkey-29.2 { + execsql { + INSERT INTO album VALUES('Elvis Presley', 'Elvis'' Christmas Album', NULL); + INSERT INTO song VALUES( + 1, 'Elvis Presley', 'Elvis'' Christmas Album', 'Here Comes Santa Clause' + ); + } +} {} +do_test e_fkey-29.3 { + catchsql { + INSERT INTO song VALUES(2, 'Elvis Presley', 'Elvis Is Back!', 'Fever'); + } +} {1 {FOREIGN KEY constraint failed}} + + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-33626-48418 In SQLite, if any of the child key columns +# (in this case songartist and songalbum) are NULL, then there is no +# requirement for a corresponding row in the parent table. +# +do_test e_fkey-30.1 { + execsql { + INSERT INTO song VALUES(2, 'Elvis Presley', NULL, 'Fever'); + INSERT INTO song VALUES(3, NULL, 'Elvis Is Back', 'Soldier Boy'); + } +} {} + +########################################################################### +### SECTION 4.2: Deferred Foreign Key Constraints +########################################################################### + +#------------------------------------------------------------------------- +# Test that if a statement violates an immediate FK constraint, and the +# database does not satisfy the FK constraint once all effects of the +# statement have been applied, an error is reported and the effects of +# the statement rolled back. +# +# EVIDENCE-OF: R-09323-30470 If a statement modifies the contents of the +# database so that an immediate foreign key constraint is in violation +# at the conclusion the statement, an exception is thrown and the +# effects of the statement are reverted. +# +drop_all_tables +do_test e_fkey-31.1 { + execsql { + CREATE TABLE king(a, b, PRIMARY KEY(a)); + CREATE TABLE prince(c REFERENCES king, d); + } +} {} + +do_test e_fkey-31.2 { + # Execute a statement that violates the immediate FK constraint. + catchsql { INSERT INTO prince VALUES(1, 2) } +} {1 {FOREIGN KEY constraint failed}} + +do_test e_fkey-31.3 { + # This time, use a trigger to fix the constraint violation before the + # statement has finished executing. Then execute the same statement as + # in the previous test case. This time, no error. + execsql { + CREATE TRIGGER kt AFTER INSERT ON prince WHEN + NOT EXISTS (SELECT a FROM king WHERE a = new.c) + BEGIN + INSERT INTO king VALUES(new.c, NULL); + END + } + execsql { INSERT INTO prince VALUES(1, 2) } +} {} + +# Test that operating inside a transaction makes no difference to +# immediate constraint violation handling. +do_test e_fkey-31.4 { + execsql { + BEGIN; + INSERT INTO prince VALUES(2, 3); + DROP TRIGGER kt; + } + catchsql { INSERT INTO prince VALUES(3, 4) } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-31.5 { + execsql { + COMMIT; + SELECT * FROM king; + } +} {1 {} 2 {}} + +#------------------------------------------------------------------------- +# Test that if a deferred constraint is violated within a transaction, +# nothing happens immediately and the database is allowed to persist +# in a state that does not satisfy the FK constraint. However attempts +# to COMMIT the transaction fail until the FK constraint is satisfied. +# +# EVIDENCE-OF: R-49178-21358 By contrast, if a statement modifies the +# contents of the database such that a deferred foreign key constraint +# is violated, the violation is not reported immediately. +# +# EVIDENCE-OF: R-39692-12488 Deferred foreign key constraints are not +# checked until the transaction tries to COMMIT. +# +# EVIDENCE-OF: R-55147-47664 For as long as the user has an open +# transaction, the database is allowed to exist in a state that violates +# any number of deferred foreign key constraints. +# +# EVIDENCE-OF: R-29604-30395 However, COMMIT will fail as long as +# foreign key constraints remain in violation. +# +proc test_efkey_34 {tn isError sql} { + do_test e_fkey-32.$tn " + catchsql {$sql} + " [lindex {{0 {}} {1 {FOREIGN KEY constraint failed}}} $isError] +} +drop_all_tables + +test_efkey_34 1 0 { + CREATE TABLE ll(k PRIMARY KEY); + CREATE TABLE kk(c REFERENCES ll DEFERRABLE INITIALLY DEFERRED); +} +test_efkey_34 2 0 "BEGIN" +test_efkey_34 3 0 "INSERT INTO kk VALUES(5)" +test_efkey_34 4 0 "INSERT INTO kk VALUES(10)" +test_efkey_34 5 1 "COMMIT" +test_efkey_34 6 0 "INSERT INTO ll VALUES(10)" +test_efkey_34 7 1 "COMMIT" +test_efkey_34 8 0 "INSERT INTO ll VALUES(5)" +test_efkey_34 9 0 "COMMIT" + +#------------------------------------------------------------------------- +# When not running inside a transaction, a deferred constraint is similar +# to an immediate constraint (violations are reported immediately). +# +# EVIDENCE-OF: R-56844-61705 If the current statement is not inside an +# explicit transaction (a BEGIN/COMMIT/ROLLBACK block), then an implicit +# transaction is committed as soon as the statement has finished +# executing. In this case deferred constraints behave the same as +# immediate constraints. +# +drop_all_tables +proc test_efkey_35 {tn isError sql} { + do_test e_fkey-33.$tn " + catchsql {$sql} + " [lindex {{0 {}} {1 {FOREIGN KEY constraint failed}}} $isError] +} +do_test e_fkey-33.1 { + execsql { + CREATE TABLE parent(x, y); + CREATE UNIQUE INDEX pi ON parent(x, y); + CREATE TABLE child(a, b, + FOREIGN KEY(a, b) REFERENCES parent(x, y) DEFERRABLE INITIALLY DEFERRED + ); + } +} {} +test_efkey_35 2 1 "INSERT INTO child VALUES('x', 'y')" +test_efkey_35 3 0 "INSERT INTO parent VALUES('x', 'y')" +test_efkey_35 4 0 "INSERT INTO child VALUES('x', 'y')" + + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-12782-61841 +# +# Test that an FK constraint is made deferred by adding the following +# to the definition: +# +# DEFERRABLE INITIALLY DEFERRED +# +# EVIDENCE-OF: R-09005-28791 +# +# Also test that adding any of the following to a foreign key definition +# makes the constraint IMMEDIATE: +# +# NOT DEFERRABLE INITIALLY DEFERRED +# NOT DEFERRABLE INITIALLY IMMEDIATE +# NOT DEFERRABLE +# DEFERRABLE INITIALLY IMMEDIATE +# DEFERRABLE +# +# Foreign keys are IMMEDIATE by default (if there is no DEFERRABLE or NOT +# DEFERRABLE clause). +# +# EVIDENCE-OF: R-35290-16460 Foreign key constraints are immediate by +# default. +# +# EVIDENCE-OF: R-30323-21917 Each foreign key constraint in SQLite is +# classified as either immediate or deferred. +# +drop_all_tables +do_test e_fkey-34.1 { + execsql { + CREATE TABLE parent(x, y, z, PRIMARY KEY(x,y,z)); + CREATE TABLE c1(a, b, c, + FOREIGN KEY(a, b, c) REFERENCES parent NOT DEFERRABLE INITIALLY DEFERRED + ); + CREATE TABLE c2(a, b, c, + FOREIGN KEY(a, b, c) REFERENCES parent NOT DEFERRABLE INITIALLY IMMEDIATE + ); + CREATE TABLE c3(a, b, c, + FOREIGN KEY(a, b, c) REFERENCES parent NOT DEFERRABLE + ); + CREATE TABLE c4(a, b, c, + FOREIGN KEY(a, b, c) REFERENCES parent DEFERRABLE INITIALLY IMMEDIATE + ); + CREATE TABLE c5(a, b, c, + FOREIGN KEY(a, b, c) REFERENCES parent DEFERRABLE + ); + CREATE TABLE c6(a, b, c, FOREIGN KEY(a, b, c) REFERENCES parent); + + -- This FK constraint is the only deferrable one. + CREATE TABLE c7(a, b, c, + FOREIGN KEY(a, b, c) REFERENCES parent DEFERRABLE INITIALLY DEFERRED + ); + + INSERT INTO parent VALUES('a', 'b', 'c'); + INSERT INTO parent VALUES('d', 'e', 'f'); + INSERT INTO parent VALUES('g', 'h', 'i'); + INSERT INTO parent VALUES('j', 'k', 'l'); + INSERT INTO parent VALUES('m', 'n', 'o'); + INSERT INTO parent VALUES('p', 'q', 'r'); + INSERT INTO parent VALUES('s', 't', 'u'); + + INSERT INTO c1 VALUES('a', 'b', 'c'); + INSERT INTO c2 VALUES('d', 'e', 'f'); + INSERT INTO c3 VALUES('g', 'h', 'i'); + INSERT INTO c4 VALUES('j', 'k', 'l'); + INSERT INTO c5 VALUES('m', 'n', 'o'); + INSERT INTO c6 VALUES('p', 'q', 'r'); + INSERT INTO c7 VALUES('s', 't', 'u'); + } +} {} + +proc test_efkey_29 {tn sql isError} { + do_test e_fkey-34.$tn "catchsql {$sql}" [ + lindex {{0 {}} {1 {FOREIGN KEY constraint failed}}} $isError + ] +} +test_efkey_29 2 "BEGIN" 0 +test_efkey_29 3 "DELETE FROM parent WHERE x = 'a'" 1 +test_efkey_29 4 "DELETE FROM parent WHERE x = 'd'" 1 +test_efkey_29 5 "DELETE FROM parent WHERE x = 'g'" 1 +test_efkey_29 6 "DELETE FROM parent WHERE x = 'j'" 1 +test_efkey_29 7 "DELETE FROM parent WHERE x = 'm'" 1 +test_efkey_29 8 "DELETE FROM parent WHERE x = 'p'" 1 +test_efkey_29 9 "DELETE FROM parent WHERE x = 's'" 0 +test_efkey_29 10 "COMMIT" 1 +test_efkey_29 11 "ROLLBACK" 0 + +test_efkey_29 9 "BEGIN" 0 +test_efkey_29 10 "UPDATE parent SET z = 'z' WHERE z = 'c'" 1 +test_efkey_29 11 "UPDATE parent SET z = 'z' WHERE z = 'f'" 1 +test_efkey_29 12 "UPDATE parent SET z = 'z' WHERE z = 'i'" 1 +test_efkey_29 13 "UPDATE parent SET z = 'z' WHERE z = 'l'" 1 +test_efkey_29 14 "UPDATE parent SET z = 'z' WHERE z = 'o'" 1 +test_efkey_29 15 "UPDATE parent SET z = 'z' WHERE z = 'r'" 1 +test_efkey_29 16 "UPDATE parent SET z = 'z' WHERE z = 'u'" 0 +test_efkey_29 17 "COMMIT" 1 +test_efkey_29 18 "ROLLBACK" 0 + +test_efkey_29 17 "BEGIN" 0 +test_efkey_29 18 "INSERT INTO c1 VALUES(1, 2, 3)" 1 +test_efkey_29 19 "INSERT INTO c2 VALUES(1, 2, 3)" 1 +test_efkey_29 20 "INSERT INTO c3 VALUES(1, 2, 3)" 1 +test_efkey_29 21 "INSERT INTO c4 VALUES(1, 2, 3)" 1 +test_efkey_29 22 "INSERT INTO c5 VALUES(1, 2, 3)" 1 +test_efkey_29 22 "INSERT INTO c6 VALUES(1, 2, 3)" 1 +test_efkey_29 22 "INSERT INTO c7 VALUES(1, 2, 3)" 0 +test_efkey_29 23 "COMMIT" 1 +test_efkey_29 24 "INSERT INTO parent VALUES(1, 2, 3)" 0 +test_efkey_29 25 "COMMIT" 0 + +test_efkey_29 26 "BEGIN" 0 +test_efkey_29 27 "UPDATE c1 SET a = 10" 1 +test_efkey_29 28 "UPDATE c2 SET a = 10" 1 +test_efkey_29 29 "UPDATE c3 SET a = 10" 1 +test_efkey_29 30 "UPDATE c4 SET a = 10" 1 +test_efkey_29 31 "UPDATE c5 SET a = 10" 1 +test_efkey_29 31 "UPDATE c6 SET a = 10" 1 +test_efkey_29 31 "UPDATE c7 SET a = 10" 0 +test_efkey_29 32 "COMMIT" 1 +test_efkey_29 33 "ROLLBACK" 0 + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-24499-57071 +# +# Test an example from foreignkeys.html dealing with a deferred foreign +# key constraint. +# +do_test e_fkey-35.1 { + drop_all_tables + execsql { + CREATE TABLE artist( + artistid INTEGER PRIMARY KEY, + artistname TEXT + ); + CREATE TABLE track( + trackid INTEGER, + trackname TEXT, + trackartist INTEGER REFERENCES artist(artistid) DEFERRABLE INITIALLY DEFERRED + ); + } +} {} +do_test e_fkey-35.2 { + execsql { + BEGIN; + INSERT INTO track VALUES(1, 'White Christmas', 5); + } + catchsql COMMIT +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-35.3 { + execsql { + INSERT INTO artist VALUES(5, 'Bing Crosby'); + COMMIT; + } +} {} + +#------------------------------------------------------------------------- +# Verify that a nested savepoint may be released without satisfying +# deferred foreign key constraints. +# +# EVIDENCE-OF: R-07223-48323 A nested savepoint transaction may be +# RELEASEd while the database is in a state that does not satisfy a +# deferred foreign key constraint. +# +drop_all_tables +do_test e_fkey-36.1 { + execsql { + CREATE TABLE t1(a PRIMARY KEY, + b REFERENCES t1 DEFERRABLE INITIALLY DEFERRED + ); + INSERT INTO t1 VALUES(1, 1); + INSERT INTO t1 VALUES(2, 2); + INSERT INTO t1 VALUES(3, 3); + } +} {} +do_test e_fkey-36.2 { + execsql { + BEGIN; + SAVEPOINT one; + INSERT INTO t1 VALUES(4, 5); + RELEASE one; + } +} {} +do_test e_fkey-36.3 { + catchsql COMMIT +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-36.4 { + execsql { + UPDATE t1 SET a = 5 WHERE a = 4; + COMMIT; + } +} {} + + +#------------------------------------------------------------------------- +# Check that a transaction savepoint (an outermost savepoint opened when +# the database was in auto-commit mode) cannot be released without +# satisfying deferred foreign key constraints. It may be rolled back. +# +# EVIDENCE-OF: R-44295-13823 A transaction savepoint (a non-nested +# savepoint that was opened while there was not currently an open +# transaction), on the other hand, is subject to the same restrictions +# as a COMMIT - attempting to RELEASE it while the database is in such a +# state will fail. +# +do_test e_fkey-37.1 { + execsql { + SAVEPOINT one; + SAVEPOINT two; + INSERT INTO t1 VALUES(6, 7); + RELEASE two; + } +} {} +do_test e_fkey-37.2 { + catchsql {RELEASE one} +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-37.3 { + execsql { + UPDATE t1 SET a = 7 WHERE a = 6; + RELEASE one; + } +} {} +do_test e_fkey-37.4 { + execsql { + SAVEPOINT one; + SAVEPOINT two; + INSERT INTO t1 VALUES(9, 10); + RELEASE two; + } +} {} +do_test e_fkey-37.5 { + catchsql {RELEASE one} +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-37.6 { + execsql {ROLLBACK TO one ; RELEASE one} +} {} + +#------------------------------------------------------------------------- +# Test that if a COMMIT operation fails due to deferred foreign key +# constraints, any nested savepoints remain open. +# +# EVIDENCE-OF: R-37736-42616 If a COMMIT statement (or the RELEASE of a +# transaction SAVEPOINT) fails because the database is currently in a +# state that violates a deferred foreign key constraint and there are +# currently nested savepoints, the nested savepoints remain open. +# +do_test e_fkey-38.1 { + execsql { + DELETE FROM t1 WHERE a>3; + SELECT * FROM t1; + } +} {1 1 2 2 3 3} +do_test e_fkey-38.2 { + execsql { + BEGIN; + INSERT INTO t1 VALUES(4, 4); + SAVEPOINT one; + INSERT INTO t1 VALUES(5, 6); + SELECT * FROM t1; + } +} {1 1 2 2 3 3 4 4 5 6} +do_test e_fkey-38.3 { + catchsql COMMIT +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-38.4 { + execsql { + ROLLBACK TO one; + COMMIT; + SELECT * FROM t1; + } +} {1 1 2 2 3 3 4 4} + +do_test e_fkey-38.5 { + execsql { + SAVEPOINT a; + INSERT INTO t1 VALUES(5, 5); + SAVEPOINT b; + INSERT INTO t1 VALUES(6, 7); + SAVEPOINT c; + INSERT INTO t1 VALUES(7, 8); + } +} {} +do_test e_fkey-38.6 { + catchsql {RELEASE a} +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-38.7 { + execsql {ROLLBACK TO c} + catchsql {RELEASE a} +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-38.8 { + execsql { + ROLLBACK TO b; + RELEASE a; + SELECT * FROM t1; + } +} {1 1 2 2 3 3 4 4 5 5} + +########################################################################### +### SECTION 4.3: ON DELETE and ON UPDATE Actions +########################################################################### + +#------------------------------------------------------------------------- +# Test that configured ON DELETE and ON UPDATE actions take place when +# deleting or modifying rows of the parent table, respectively. +# +# EVIDENCE-OF: R-48270-44282 Foreign key ON DELETE and ON UPDATE clauses +# are used to configure actions that take place when deleting rows from +# the parent table (ON DELETE), or modifying the parent key values of +# existing rows (ON UPDATE). +# +# Test that a single FK constraint may have different actions configured +# for ON DELETE and ON UPDATE. +# +# EVIDENCE-OF: R-48124-63225 A single foreign key constraint may have +# different actions configured for ON DELETE and ON UPDATE. +# +do_test e_fkey-39.1 { + execsql { + CREATE TABLE p(a, b PRIMARY KEY, c); + CREATE TABLE c1(d, e, f DEFAULT 'k0' REFERENCES p + ON UPDATE SET DEFAULT + ON DELETE SET NULL + ); + + INSERT INTO p VALUES(0, 'k0', ''); + INSERT INTO p VALUES(1, 'k1', 'I'); + INSERT INTO p VALUES(2, 'k2', 'II'); + INSERT INTO p VALUES(3, 'k3', 'III'); + + INSERT INTO c1 VALUES(1, 'xx', 'k1'); + INSERT INTO c1 VALUES(2, 'xx', 'k2'); + INSERT INTO c1 VALUES(3, 'xx', 'k3'); + } +} {} +do_test e_fkey-39.2 { + execsql { + UPDATE p SET b = 'k4' WHERE a = 1; + SELECT * FROM c1; + } +} {1 xx k0 2 xx k2 3 xx k3} +do_test e_fkey-39.3 { + execsql { + DELETE FROM p WHERE a = 2; + SELECT * FROM c1; + } +} {1 xx k0 2 xx {} 3 xx k3} +do_test e_fkey-39.4 { + execsql { + CREATE UNIQUE INDEX pi ON p(c); + REPLACE INTO p VALUES(5, 'k5', 'III'); + SELECT * FROM c1; + } +} {1 xx k0 2 xx {} 3 xx {}} + +#------------------------------------------------------------------------- +# Each foreign key in the system has an ON UPDATE and ON DELETE action, +# either "NO ACTION", "RESTRICT", "SET NULL", "SET DEFAULT" or "CASCADE". +# +# EVIDENCE-OF: R-33326-45252 The ON DELETE and ON UPDATE action +# associated with each foreign key in an SQLite database is one of "NO +# ACTION", "RESTRICT", "SET NULL", "SET DEFAULT" or "CASCADE". +# +# If none is specified explicitly, "NO ACTION" is the default. +# +# EVIDENCE-OF: R-19803-45884 If an action is not explicitly specified, +# it defaults to "NO ACTION". +# +drop_all_tables +do_test e_fkey-40.1 { + execsql { + CREATE TABLE parent(x PRIMARY KEY, y); + CREATE TABLE child1(a, + b REFERENCES parent ON UPDATE NO ACTION ON DELETE RESTRICT + ); + CREATE TABLE child2(a, + b REFERENCES parent ON UPDATE RESTRICT ON DELETE SET NULL + ); + CREATE TABLE child3(a, + b REFERENCES parent ON UPDATE SET NULL ON DELETE SET DEFAULT + ); + CREATE TABLE child4(a, + b REFERENCES parent ON UPDATE SET DEFAULT ON DELETE CASCADE + ); + + -- Create some foreign keys that use the default action - "NO ACTION" + CREATE TABLE child5(a, b REFERENCES parent ON UPDATE CASCADE); + CREATE TABLE child6(a, b REFERENCES parent ON DELETE RESTRICT); + CREATE TABLE child7(a, b REFERENCES parent ON DELETE NO ACTION); + CREATE TABLE child8(a, b REFERENCES parent ON UPDATE NO ACTION); + } +} {} + +foreach {tn zTab lRes} { + 2 child1 {0 0 parent b {} {NO ACTION} RESTRICT NONE} + 3 child2 {0 0 parent b {} RESTRICT {SET NULL} NONE} + 4 child3 {0 0 parent b {} {SET NULL} {SET DEFAULT} NONE} + 5 child4 {0 0 parent b {} {SET DEFAULT} CASCADE NONE} + 6 child5 {0 0 parent b {} CASCADE {NO ACTION} NONE} + 7 child6 {0 0 parent b {} {NO ACTION} RESTRICT NONE} + 8 child7 {0 0 parent b {} {NO ACTION} {NO ACTION} NONE} + 9 child8 {0 0 parent b {} {NO ACTION} {NO ACTION} NONE} +} { + do_test e_fkey-40.$tn { execsql "PRAGMA foreign_key_list($zTab)" } $lRes +} + +#------------------------------------------------------------------------- +# Test that "NO ACTION" means that nothing happens to a child row when +# it's parent row is updated or deleted. +# +# EVIDENCE-OF: R-19971-54976 Configuring "NO ACTION" means just that: +# when a parent key is modified or deleted from the database, no special +# action is taken. +# +drop_all_tables +do_test e_fkey-41.1 { + execsql { + CREATE TABLE parent(p1, p2, PRIMARY KEY(p1, p2)); + CREATE TABLE child(c1, c2, + FOREIGN KEY(c1, c2) REFERENCES parent + ON UPDATE NO ACTION + ON DELETE NO ACTION + DEFERRABLE INITIALLY DEFERRED + ); + INSERT INTO parent VALUES('j', 'k'); + INSERT INTO parent VALUES('l', 'm'); + INSERT INTO child VALUES('j', 'k'); + INSERT INTO child VALUES('l', 'm'); + } +} {} +do_test e_fkey-41.2 { + execsql { + BEGIN; + UPDATE parent SET p1='k' WHERE p1='j'; + DELETE FROM parent WHERE p1='l'; + SELECT * FROM child; + } +} {j k l m} +do_test e_fkey-41.3 { + catchsql COMMIT +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-41.4 { + execsql ROLLBACK +} {} + +#------------------------------------------------------------------------- +# Test that "RESTRICT" means the application is prohibited from deleting +# or updating a parent table row when there exists one or more child keys +# mapped to it. +# +# EVIDENCE-OF: R-04272-38653 The "RESTRICT" action means that the +# application is prohibited from deleting (for ON DELETE RESTRICT) or +# modifying (for ON UPDATE RESTRICT) a parent key when there exists one +# or more child keys mapped to it. +# +drop_all_tables +do_test e_fkey-41.1 { + execsql { + CREATE TABLE parent(p1, p2); + CREATE UNIQUE INDEX parent_i ON parent(p1, p2); + CREATE TABLE child1(c1, c2, + FOREIGN KEY(c2, c1) REFERENCES parent(p1, p2) ON DELETE RESTRICT + ); + CREATE TABLE child2(c1, c2, + FOREIGN KEY(c2, c1) REFERENCES parent(p1, p2) ON UPDATE RESTRICT + ); + } +} {} +do_test e_fkey-41.2 { + execsql { + INSERT INTO parent VALUES('a', 'b'); + INSERT INTO parent VALUES('c', 'd'); + INSERT INTO child1 VALUES('b', 'a'); + INSERT INTO child2 VALUES('d', 'c'); + } +} {} +do_test e_fkey-41.3 { + catchsql { DELETE FROM parent WHERE p1 = 'a' } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-41.4 { + catchsql { UPDATE parent SET p2 = 'e' WHERE p1 = 'c' } +} {1 {FOREIGN KEY constraint failed}} + +#------------------------------------------------------------------------- +# Test that RESTRICT is slightly different from NO ACTION for IMMEDIATE +# constraints, in that it is enforced immediately, not at the end of the +# statement. +# +# EVIDENCE-OF: R-37997-42187 The difference between the effect of a +# RESTRICT action and normal foreign key constraint enforcement is that +# the RESTRICT action processing happens as soon as the field is updated +# - not at the end of the current statement as it would with an +# immediate constraint, or at the end of the current transaction as it +# would with a deferred constraint. +# +drop_all_tables +do_test e_fkey-42.1 { + execsql { + CREATE TABLE parent(x PRIMARY KEY); + CREATE TABLE child1(c REFERENCES parent ON UPDATE RESTRICT); + CREATE TABLE child2(c REFERENCES parent ON UPDATE NO ACTION); + + INSERT INTO parent VALUES('key1'); + INSERT INTO parent VALUES('key2'); + INSERT INTO child1 VALUES('key1'); + INSERT INTO child2 VALUES('key2'); + + CREATE TRIGGER parent_t AFTER UPDATE ON parent BEGIN + UPDATE child1 set c = new.x WHERE c = old.x; + UPDATE child2 set c = new.x WHERE c = old.x; + END; + } +} {} +do_test e_fkey-42.2 { + catchsql { UPDATE parent SET x = 'key one' WHERE x = 'key1' } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-42.3 { + execsql { + UPDATE parent SET x = 'key two' WHERE x = 'key2'; + SELECT * FROM child2; + } +} {{key two}} + +drop_all_tables +do_test e_fkey-42.4 { + execsql { + CREATE TABLE parent(x PRIMARY KEY); + CREATE TABLE child1(c REFERENCES parent ON DELETE RESTRICT); + CREATE TABLE child2(c REFERENCES parent ON DELETE NO ACTION); + + INSERT INTO parent VALUES('key1'); + INSERT INTO parent VALUES('key2'); + INSERT INTO child1 VALUES('key1'); + INSERT INTO child2 VALUES('key2'); + + CREATE TRIGGER parent_t AFTER DELETE ON parent BEGIN + UPDATE child1 SET c = NULL WHERE c = old.x; + UPDATE child2 SET c = NULL WHERE c = old.x; + END; + } +} {} +do_test e_fkey-42.5 { + catchsql { DELETE FROM parent WHERE x = 'key1' } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-42.6 { + execsql { + DELETE FROM parent WHERE x = 'key2'; + SELECT * FROM child2; + } +} {{}} + +drop_all_tables +do_test e_fkey-42.7 { + execsql { + CREATE TABLE parent(x PRIMARY KEY); + CREATE TABLE child1(c REFERENCES parent ON DELETE RESTRICT); + CREATE TABLE child2(c REFERENCES parent ON DELETE NO ACTION); + + INSERT INTO parent VALUES('key1'); + INSERT INTO parent VALUES('key2'); + INSERT INTO child1 VALUES('key1'); + INSERT INTO child2 VALUES('key2'); + } +} {} +do_test e_fkey-42.8 { + catchsql { REPLACE INTO parent VALUES('key1') } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-42.9 { + execsql { + REPLACE INTO parent VALUES('key2'); + SELECT * FROM child2; + } +} {key2} + +#------------------------------------------------------------------------- +# Test that RESTRICT is enforced immediately, even for a DEFERRED constraint. +# +# EVIDENCE-OF: R-24179-60523 Even if the foreign key constraint it is +# attached to is deferred, configuring a RESTRICT action causes SQLite +# to return an error immediately if a parent key with dependent child +# keys is deleted or modified. +# +drop_all_tables +do_test e_fkey-43.1 { + execsql { + CREATE TABLE parent(x PRIMARY KEY); + CREATE TABLE child1(c REFERENCES parent ON UPDATE RESTRICT + DEFERRABLE INITIALLY DEFERRED + ); + CREATE TABLE child2(c REFERENCES parent ON UPDATE NO ACTION + DEFERRABLE INITIALLY DEFERRED + ); + + INSERT INTO parent VALUES('key1'); + INSERT INTO parent VALUES('key2'); + INSERT INTO child1 VALUES('key1'); + INSERT INTO child2 VALUES('key2'); + BEGIN; + } +} {} +do_test e_fkey-43.2 { + catchsql { UPDATE parent SET x = 'key one' WHERE x = 'key1' } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-43.3 { + execsql { UPDATE parent SET x = 'key two' WHERE x = 'key2' } +} {} +do_test e_fkey-43.4 { + catchsql COMMIT +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-43.5 { + execsql { + UPDATE child2 SET c = 'key two'; + COMMIT; + } +} {} + +drop_all_tables +do_test e_fkey-43.6 { + execsql { + CREATE TABLE parent(x PRIMARY KEY); + CREATE TABLE child1(c REFERENCES parent ON DELETE RESTRICT + DEFERRABLE INITIALLY DEFERRED + ); + CREATE TABLE child2(c REFERENCES parent ON DELETE NO ACTION + DEFERRABLE INITIALLY DEFERRED + ); + + INSERT INTO parent VALUES('key1'); + INSERT INTO parent VALUES('key2'); + INSERT INTO child1 VALUES('key1'); + INSERT INTO child2 VALUES('key2'); + BEGIN; + } +} {} +do_test e_fkey-43.7 { + catchsql { DELETE FROM parent WHERE x = 'key1' } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-43.8 { + execsql { DELETE FROM parent WHERE x = 'key2' } +} {} +do_test e_fkey-43.9 { + catchsql COMMIT +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-43.10 { + execsql { + UPDATE child2 SET c = NULL; + COMMIT; + } +} {} + +#------------------------------------------------------------------------- +# Test SET NULL actions. +# +# EVIDENCE-OF: R-03353-05327 If the configured action is "SET NULL", +# then when a parent key is deleted (for ON DELETE SET NULL) or modified +# (for ON UPDATE SET NULL), the child key columns of all rows in the +# child table that mapped to the parent key are set to contain SQL NULL +# values. +# +drop_all_tables +do_test e_fkey-44.1 { + execsql { + CREATE TABLE pA(x PRIMARY KEY); + CREATE TABLE cA(c REFERENCES pA ON DELETE SET NULL); + CREATE TABLE cB(c REFERENCES pA ON UPDATE SET NULL); + + INSERT INTO pA VALUES(X'ABCD'); + INSERT INTO pA VALUES(X'1234'); + INSERT INTO cA VALUES(X'ABCD'); + INSERT INTO cB VALUES(X'1234'); + } +} {} +do_test e_fkey-44.2 { + execsql { + DELETE FROM pA WHERE rowid = 1; + SELECT quote(x) FROM pA; + } +} {X'1234'} +do_test e_fkey-44.3 { + execsql { + SELECT quote(c) FROM cA; + } +} {NULL} +do_test e_fkey-44.4 { + execsql { + UPDATE pA SET x = X'8765' WHERE rowid = 2; + SELECT quote(x) FROM pA; + } +} {X'8765'} +do_test e_fkey-44.5 { + execsql { SELECT quote(c) FROM cB } +} {NULL} + +#------------------------------------------------------------------------- +# Test SET DEFAULT actions. +# +# EVIDENCE-OF: R-55814-22637 The "SET DEFAULT" actions are similar to +# "SET NULL", except that each of the child key columns is set to +# contain the column's default value instead of NULL. +# +drop_all_tables +do_test e_fkey-45.1 { + execsql { + CREATE TABLE pA(x PRIMARY KEY); + CREATE TABLE cA(c DEFAULT X'0000' REFERENCES pA ON DELETE SET DEFAULT); + CREATE TABLE cB(c DEFAULT X'9999' REFERENCES pA ON UPDATE SET DEFAULT); + + INSERT INTO pA(rowid, x) VALUES(1, X'0000'); + INSERT INTO pA(rowid, x) VALUES(2, X'9999'); + INSERT INTO pA(rowid, x) VALUES(3, X'ABCD'); + INSERT INTO pA(rowid, x) VALUES(4, X'1234'); + + INSERT INTO cA VALUES(X'ABCD'); + INSERT INTO cB VALUES(X'1234'); + } +} {} +do_test e_fkey-45.2 { + execsql { + DELETE FROM pA WHERE rowid = 3; + SELECT quote(x) FROM pA ORDER BY rowid; + } +} {X'0000' X'9999' X'1234'} +do_test e_fkey-45.3 { + execsql { SELECT quote(c) FROM cA } +} {X'0000'} +do_test e_fkey-45.4 { + execsql { + UPDATE pA SET x = X'8765' WHERE rowid = 4; + SELECT quote(x) FROM pA ORDER BY rowid; + } +} {X'0000' X'9999' X'8765'} +do_test e_fkey-45.5 { + execsql { SELECT quote(c) FROM cB } +} {X'9999'} + +#------------------------------------------------------------------------- +# Test ON DELETE CASCADE actions. +# +# EVIDENCE-OF: R-61376-57267 A "CASCADE" action propagates the delete or +# update operation on the parent key to each dependent child key. +# +# EVIDENCE-OF: R-61809-62207 For an "ON DELETE CASCADE" action, this +# means that each row in the child table that was associated with the +# deleted parent row is also deleted. +# +drop_all_tables +do_test e_fkey-46.1 { + execsql { + CREATE TABLE p1(a, b UNIQUE); + CREATE TABLE c1(c REFERENCES p1(b) ON DELETE CASCADE, d); + INSERT INTO p1 VALUES(NULL, NULL); + INSERT INTO p1 VALUES(4, 4); + INSERT INTO p1 VALUES(5, 5); + INSERT INTO c1 VALUES(NULL, NULL); + INSERT INTO c1 VALUES(4, 4); + INSERT INTO c1 VALUES(5, 5); + SELECT count(*) FROM c1; + } +} {3} +do_test e_fkey-46.2 { + execsql { + DELETE FROM p1 WHERE a = 4; + SELECT d, c FROM c1; + } +} {{} {} 5 5} +do_test e_fkey-46.3 { + execsql { + DELETE FROM p1; + SELECT d, c FROM c1; + } +} {{} {}} +do_test e_fkey-46.4 { + execsql { SELECT * FROM p1 } +} {} + + +#------------------------------------------------------------------------- +# Test ON UPDATE CASCADE actions. +# +# EVIDENCE-OF: R-13877-64542 For an "ON UPDATE CASCADE" action, it means +# that the values stored in each dependent child key are modified to +# match the new parent key values. +# +# EVIDENCE-OF: R-61376-57267 A "CASCADE" action propagates the delete or +# update operation on the parent key to each dependent child key. +# +drop_all_tables +do_test e_fkey-47.1 { + execsql { + CREATE TABLE p1(a, b UNIQUE); + CREATE TABLE c1(c REFERENCES p1(b) ON UPDATE CASCADE, d); + INSERT INTO p1 VALUES(NULL, NULL); + INSERT INTO p1 VALUES(4, 4); + INSERT INTO p1 VALUES(5, 5); + INSERT INTO c1 VALUES(NULL, NULL); + INSERT INTO c1 VALUES(4, 4); + INSERT INTO c1 VALUES(5, 5); + SELECT count(*) FROM c1; + } +} {3} +do_test e_fkey-47.2 { + execsql { + UPDATE p1 SET b = 10 WHERE b = 5; + SELECT d, c FROM c1; + } +} {{} {} 4 4 5 10} +do_test e_fkey-47.3 { + execsql { + UPDATE p1 SET b = 11 WHERE b = 4; + SELECT d, c FROM c1; + } +} {{} {} 4 11 5 10} +do_test e_fkey-47.4 { + execsql { + UPDATE p1 SET b = 6 WHERE b IS NULL; + SELECT d, c FROM c1; + } +} {{} {} 4 11 5 10} +do_test e_fkey-46.5 { + execsql { SELECT * FROM p1 } +} {{} 6 4 11 5 10} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-65058-57158 +# +# Test an example from the "ON DELETE and ON UPDATE Actions" section +# of foreignkeys.html. +# +drop_all_tables +do_test e_fkey-48.1 { + execsql { + CREATE TABLE artist( + artistid INTEGER PRIMARY KEY, + artistname TEXT + ); + CREATE TABLE track( + trackid INTEGER, + trackname TEXT, + trackartist INTEGER REFERENCES artist(artistid) ON UPDATE CASCADE + ); + + INSERT INTO artist VALUES(1, 'Dean Martin'); + INSERT INTO artist VALUES(2, 'Frank Sinatra'); + INSERT INTO track VALUES(11, 'That''s Amore', 1); + INSERT INTO track VALUES(12, 'Christmas Blues', 1); + INSERT INTO track VALUES(13, 'My Way', 2); + } +} {} +do_test e_fkey-48.2 { + execsql { + UPDATE artist SET artistid = 100 WHERE artistname = 'Dean Martin'; + } +} {} +do_test e_fkey-48.3 { + execsql { SELECT * FROM artist } +} {2 {Frank Sinatra} 100 {Dean Martin}} +do_test e_fkey-48.4 { + execsql { SELECT * FROM track } +} {11 {That's Amore} 100 12 {Christmas Blues} 100 13 {My Way} 2} + + +#------------------------------------------------------------------------- +# Verify that adding an FK action does not absolve the user of the +# requirement not to violate the foreign key constraint. +# +# EVIDENCE-OF: R-53968-51642 Configuring an ON UPDATE or ON DELETE +# action does not mean that the foreign key constraint does not need to +# be satisfied. +# +drop_all_tables +do_test e_fkey-49.1 { + execsql { + CREATE TABLE parent(a COLLATE nocase, b, c, PRIMARY KEY(c, a)); + CREATE TABLE child(d DEFAULT 'a', e, f DEFAULT 'c', + FOREIGN KEY(f, d) REFERENCES parent ON UPDATE SET DEFAULT + ); + + INSERT INTO parent VALUES('A', 'b', 'c'); + INSERT INTO parent VALUES('ONE', 'two', 'three'); + INSERT INTO child VALUES('one', 'two', 'three'); + } +} {} +do_test e_fkey-49.2 { + execsql { + BEGIN; + UPDATE parent SET a = '' WHERE a = 'oNe'; + SELECT * FROM child; + } +} {a two c} +do_test e_fkey-49.3 { + execsql { + ROLLBACK; + DELETE FROM parent WHERE a = 'A'; + SELECT * FROM parent; + } +} {ONE two three} +do_test e_fkey-49.4 { + catchsql { UPDATE parent SET a = '' WHERE a = 'oNe' } +} {1 {FOREIGN KEY constraint failed}} + + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-11856-19836 +# +# Test an example from the "ON DELETE and ON UPDATE Actions" section +# of foreignkeys.html. This example shows that adding an "ON DELETE DEFAULT" +# clause does not abrogate the need to satisfy the foreign key constraint +# (R-28220-46694). +# +# EVIDENCE-OF: R-28220-46694 For example, if an "ON DELETE SET DEFAULT" +# action is configured, but there is no row in the parent table that +# corresponds to the default values of the child key columns, deleting a +# parent key while dependent child keys exist still causes a foreign key +# violation. +# +drop_all_tables +do_test e_fkey-50.1 { + execsql { + CREATE TABLE artist( + artistid INTEGER PRIMARY KEY, + artistname TEXT + ); + CREATE TABLE track( + trackid INTEGER, + trackname TEXT, + trackartist INTEGER DEFAULT 0 REFERENCES artist(artistid) ON DELETE SET DEFAULT + ); + INSERT INTO artist VALUES(3, 'Sammy Davis Jr.'); + INSERT INTO track VALUES(14, 'Mr. Bojangles', 3); + } +} {} +do_test e_fkey-50.2 { + catchsql { DELETE FROM artist WHERE artistname = 'Sammy Davis Jr.' } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-50.3 { + execsql { + INSERT INTO artist VALUES(0, 'Unknown Artist'); + DELETE FROM artist WHERE artistname = 'Sammy Davis Jr.'; + } +} {} +do_test e_fkey-50.4 { + execsql { SELECT * FROM artist } +} {0 {Unknown Artist}} +do_test e_fkey-50.5 { + execsql { SELECT * FROM track } +} {14 {Mr. Bojangles} 0} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-09564-22170 +# +# Check that the order of steps in an UPDATE or DELETE on a parent +# table is as follows: +# +# 1. Execute applicable BEFORE trigger programs, +# 2. Check local (non foreign key) constraints, +# 3. Update or delete the row in the parent table, +# 4. Perform any required foreign key actions, +# 5. Execute applicable AFTER trigger programs. +# +drop_all_tables +do_test e_fkey-51.1 { + proc maxparent {args} { db one {SELECT max(x) FROM parent} } + db func maxparent maxparent + + execsql { + CREATE TABLE parent(x PRIMARY KEY); + + CREATE TRIGGER bu BEFORE UPDATE ON parent BEGIN + INSERT INTO parent VALUES(new.x-old.x); + END; + CREATE TABLE child( + a DEFAULT (maxparent()) REFERENCES parent ON UPDATE SET DEFAULT + ); + CREATE TRIGGER au AFTER UPDATE ON parent BEGIN + INSERT INTO parent VALUES(new.x+old.x); + END; + + INSERT INTO parent VALUES(1); + INSERT INTO child VALUES(1); + } +} {} +do_test e_fkey-51.2 { + execsql { + UPDATE parent SET x = 22; + SELECT * FROM parent ORDER BY rowid; SELECT 'xxx' ; SELECT a FROM child; + } +} {22 21 23 xxx 22} +do_test e_fkey-51.3 { + execsql { + DELETE FROM child; + DELETE FROM parent; + INSERT INTO parent VALUES(-1); + INSERT INTO child VALUES(-1); + UPDATE parent SET x = 22; + SELECT * FROM parent ORDER BY rowid; SELECT 'xxx' ; SELECT a FROM child; + } +} {22 23 21 xxx 23} + + +#------------------------------------------------------------------------- +# Verify that ON UPDATE actions only actually take place if the parent key +# is set to a new value that is distinct from the old value. The default +# collation sequence and affinity are used to determine if the new value +# is 'distinct' from the old or not. +# +# EVIDENCE-OF: R-27383-10246 An ON UPDATE action is only taken if the +# values of the parent key are modified so that the new parent key +# values are not equal to the old. +# +drop_all_tables +do_test e_fkey-52.1 { + execsql { + CREATE TABLE zeus(a INTEGER COLLATE NOCASE, b, PRIMARY KEY(a, b)); + CREATE TABLE apollo(c, d, + FOREIGN KEY(c, d) REFERENCES zeus ON UPDATE CASCADE + ); + INSERT INTO zeus VALUES('abc', 'xyz'); + INSERT INTO apollo VALUES('ABC', 'xyz'); + } + execsql { + UPDATE zeus SET a = 'aBc'; + SELECT * FROM apollo; + } +} {ABC xyz} +do_test e_fkey-52.2 { + execsql { + UPDATE zeus SET a = 1, b = 1; + SELECT * FROM apollo; + } +} {1 1} +do_test e_fkey-52.3 { + execsql { + UPDATE zeus SET a = 1, b = 1; + SELECT typeof(c), c, typeof(d), d FROM apollo; + } +} {integer 1 integer 1} +do_test e_fkey-52.4 { + execsql { + UPDATE zeus SET a = '1'; + SELECT typeof(c), c, typeof(d), d FROM apollo; + } +} {integer 1 integer 1} +do_test e_fkey-52.5 { + execsql { + UPDATE zeus SET b = '1'; + SELECT typeof(c), c, typeof(d), d FROM apollo; + } +} {integer 1 text 1} +do_test e_fkey-52.6 { + execsql { + UPDATE zeus SET b = NULL; + SELECT typeof(c), c, typeof(d), d FROM apollo; + } +} {integer 1 null {}} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-35129-58141 +# +# Test an example from the "ON DELETE and ON UPDATE Actions" section +# of foreignkeys.html. This example demonstrates that ON UPDATE actions +# only take place if at least one parent key column is set to a value +# that is distinct from its previous value. +# +drop_all_tables +do_test e_fkey-53.1 { + execsql { + CREATE TABLE parent(x PRIMARY KEY); + CREATE TABLE child(y REFERENCES parent ON UPDATE SET NULL); + INSERT INTO parent VALUES('key'); + INSERT INTO child VALUES('key'); + } +} {} +do_test e_fkey-53.2 { + execsql { + UPDATE parent SET x = 'key'; + SELECT IFNULL(y, 'null') FROM child; + } +} {key} +do_test e_fkey-53.3 { + execsql { + UPDATE parent SET x = 'key2'; + SELECT IFNULL(y, 'null') FROM child; + } +} {null} + +########################################################################### +### SECTION 5: CREATE, ALTER and DROP TABLE commands +########################################################################### + +#------------------------------------------------------------------------- +# Test that parent keys are not checked when tables are created. +# +# EVIDENCE-OF: R-36018-21755 The parent key definitions of foreign key +# constraints are not checked when a table is created. +# +# EVIDENCE-OF: R-25384-39337 There is nothing stopping the user from +# creating a foreign key definition that refers to a parent table that +# does not exist, or to parent key columns that do not exist or are not +# collectively bound by a PRIMARY KEY or UNIQUE constraint. +# +# Child keys are checked to ensure all component columns exist. If parent +# key columns are explicitly specified, SQLite checks to make sure there +# are the same number of columns in the child and parent keys. (TODO: This +# is tested but does not correspond to any testable statement.) +# +# Also test that the above statements are true regardless of whether or not +# foreign keys are enabled: "A CREATE TABLE command operates the same whether +# or not foreign key constraints are enabled." +# +# EVIDENCE-OF: R-08908-23439 A CREATE TABLE command operates the same +# whether or not foreign key constraints are enabled. +# +foreach {tn zCreateTbl lRes} { + 1 "CREATE TABLE t1(a, b REFERENCES t1)" {0 {}} + 2 "CREATE TABLE t1(a, b REFERENCES t2)" {0 {}} + 3 "CREATE TABLE t1(a, b, FOREIGN KEY(a,b) REFERENCES t1)" {0 {}} + 4 "CREATE TABLE t1(a, b, FOREIGN KEY(a,b) REFERENCES t2)" {0 {}} + 5 "CREATE TABLE t1(a, b, FOREIGN KEY(a,b) REFERENCES t2)" {0 {}} + 6 "CREATE TABLE t1(a, b, FOREIGN KEY(a,b) REFERENCES t2(n,d))" {0 {}} + 7 "CREATE TABLE t1(a, b, FOREIGN KEY(a,b) REFERENCES t1(a,b))" {0 {}} + + A "CREATE TABLE t1(a, b, FOREIGN KEY(c,b) REFERENCES t2)" + {1 {unknown column "c" in foreign key definition}} + B "CREATE TABLE t1(a, b, FOREIGN KEY(c,b) REFERENCES t2(d))" + {1 {number of columns in foreign key does not match the number of columns in the referenced table}} +} { + do_test e_fkey-54.$tn.off { + drop_all_tables + execsql {PRAGMA foreign_keys = OFF} + catchsql $zCreateTbl + } $lRes + do_test e_fkey-54.$tn.on { + drop_all_tables + execsql {PRAGMA foreign_keys = ON} + catchsql $zCreateTbl + } $lRes +} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-47952-62498 It is not possible to use the "ALTER TABLE +# ... ADD COLUMN" syntax to add a column that includes a REFERENCES +# clause, unless the default value of the new column is NULL. Attempting +# to do so returns an error. +# +proc test_efkey_6 {tn zAlter isError} { + drop_all_tables + + do_test e_fkey-56.$tn.1 " + execsql { CREATE TABLE tbl(a, b); INSERT INTO tbl VALUES(1, 2); } + [list catchsql $zAlter] + " [lindex {{0 {}} {1 {Cannot add a REFERENCES column with non-NULL default value}}} $isError] + +} + +ifcapable altertable { + test_efkey_6 1 "ALTER TABLE tbl ADD COLUMN c REFERENCES xx" 0 + test_efkey_6 2 "ALTER TABLE tbl ADD COLUMN c DEFAULT NULL REFERENCES xx" 0 + test_efkey_6 3 "ALTER TABLE tbl ADD COLUMN c DEFAULT 0 REFERENCES xx" 1 +} + +#------------------------------------------------------------------------- +# Test that ALTER TABLE adjusts REFERENCES clauses when the parent table +# is RENAMED. +# +# EVIDENCE-OF: R-47080-02069 If an "ALTER TABLE ... RENAME TO" command +# is used to rename a table that is the parent table of one or more +# foreign key constraints, the definitions of the foreign key +# constraints are modified to refer to the parent table by its new name +# +# Test that these adjustments are visible in the sqlite_master table. +# +# EVIDENCE-OF: R-43040-62530 The text of the child CREATE TABLE +# statement or statements stored in the sqlite_schema table are modified +# to reflect the new parent table name. +# +ifcapable altertable { +do_test e_fkey-56.1 { + drop_all_tables + execsql { + CREATE TABLE 'p 1 "parent one"'(a REFERENCES 'p 1 "parent one"', b, PRIMARY KEY(b)); + + CREATE TABLE c1(c, d REFERENCES 'p 1 "parent one"' ON UPDATE CASCADE); + CREATE TABLE c2(e, f, FOREIGN KEY(f) REFERENCES 'p 1 "parent one"' ON UPDATE CASCADE); + CREATE TABLE c3(e, 'f col 2', FOREIGN KEY('f col 2') REFERENCES 'p 1 "parent one"' ON UPDATE CASCADE); + + INSERT INTO 'p 1 "parent one"' VALUES(1, 1); + INSERT INTO c1 VALUES(1, 1); + INSERT INTO c2 VALUES(1, 1); + INSERT INTO c3 VALUES(1, 1); + + -- CREATE TABLE q(a, b, PRIMARY KEY(b)); + } +} {} +do_test e_fkey-56.2 { + execsql { ALTER TABLE 'p 1 "parent one"' RENAME TO p } +} {} +do_test e_fkey-56.3 { + execsql { + UPDATE p SET a = 'xxx', b = 'xxx'; + SELECT * FROM p; + SELECT * FROM c1; + SELECT * FROM c2; + SELECT * FROM c3; + } +} {xxx xxx 1 xxx 1 xxx 1 xxx} +do_test e_fkey-56.4 { + execsql { SELECT sql FROM sqlite_master WHERE type = 'table'} +} [list \ + {CREATE TABLE "p"(a REFERENCES "p", b, PRIMARY KEY(b))} \ + {CREATE TABLE c1(c, d REFERENCES "p" ON UPDATE CASCADE)} \ + {CREATE TABLE c2(e, f, FOREIGN KEY(f) REFERENCES "p" ON UPDATE CASCADE)} \ + {CREATE TABLE c3(e, 'f col 2', FOREIGN KEY('f col 2') REFERENCES "p" ON UPDATE CASCADE)} \ +] +} + +#------------------------------------------------------------------------- +# Check that a DROP TABLE does an implicit DELETE FROM. Which does not +# cause any triggers to fire, but does fire foreign key actions. +# +# EVIDENCE-OF: R-14208-23986 If foreign key constraints are enabled when +# it is prepared, the DROP TABLE command performs an implicit DELETE to +# remove all rows from the table before dropping it. +# +# EVIDENCE-OF: R-11078-03945 The implicit DELETE does not cause any SQL +# triggers to fire, but may invoke foreign key actions or constraint +# violations. +# +do_test e_fkey-57.1 { + drop_all_tables + execsql { + CREATE TABLE p(a, b, PRIMARY KEY(a, b)); + + CREATE TABLE c1(c, d, FOREIGN KEY(c, d) REFERENCES p ON DELETE SET NULL); + CREATE TABLE c2(c, d, FOREIGN KEY(c, d) REFERENCES p ON DELETE SET DEFAULT); + CREATE TABLE c3(c, d, FOREIGN KEY(c, d) REFERENCES p ON DELETE CASCADE); + CREATE TABLE c4(c, d, FOREIGN KEY(c, d) REFERENCES p ON DELETE RESTRICT); + CREATE TABLE c5(c, d, FOREIGN KEY(c, d) REFERENCES p ON DELETE NO ACTION); + + CREATE TABLE c6(c, d, + FOREIGN KEY(c, d) REFERENCES p ON DELETE RESTRICT + DEFERRABLE INITIALLY DEFERRED + ); + CREATE TABLE c7(c, d, + FOREIGN KEY(c, d) REFERENCES p ON DELETE NO ACTION + DEFERRABLE INITIALLY DEFERRED + ); + + CREATE TABLE log(msg); + CREATE TRIGGER tt AFTER DELETE ON p BEGIN + INSERT INTO log VALUES('delete ' || old.rowid); + END; + } +} {} + +do_test e_fkey-57.2 { + execsql { + INSERT INTO p VALUES('a', 'b'); + INSERT INTO c1 VALUES('a', 'b'); + INSERT INTO c2 VALUES('a', 'b'); + INSERT INTO c3 VALUES('a', 'b'); + BEGIN; + DROP TABLE p; + SELECT * FROM c1; + } +} {{} {}} +do_test e_fkey-57.3 { + execsql { SELECT * FROM c2 } +} {{} {}} +do_test e_fkey-57.4 { + execsql { SELECT * FROM c3 } +} {} +do_test e_fkey-57.5 { + execsql { SELECT * FROM log } +} {} +do_test e_fkey-57.6 { + execsql ROLLBACK +} {} +do_test e_fkey-57.7 { + execsql { + BEGIN; + DELETE FROM p; + SELECT * FROM log; + ROLLBACK; + } +} {{delete 1}} + +#------------------------------------------------------------------------- +# If an IMMEDIATE foreign key fails as a result of a DROP TABLE, the +# DROP TABLE command fails. +# +# EVIDENCE-OF: R-32768-47925 If an immediate foreign key constraint is +# violated, the DROP TABLE statement fails and the table is not dropped. +# +do_test e_fkey-58.1 { + execsql { + DELETE FROM c1; + DELETE FROM c2; + DELETE FROM c3; + } + execsql { INSERT INTO c5 VALUES('a', 'b') } + catchsql { DROP TABLE p } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-58.2 { + execsql { SELECT * FROM p } +} {a b} +do_test e_fkey-58.3 { + catchsql { + BEGIN; + DROP TABLE p; + } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-58.4 { + execsql { + SELECT * FROM p; + SELECT * FROM c5; + ROLLBACK; + } +} {a b a b} + +#------------------------------------------------------------------------- +# If a DEFERRED foreign key fails as a result of a DROP TABLE, attempting +# to commit the transaction fails unless the violation is fixed. +# +# EVIDENCE-OF: R-05903-08460 If a deferred foreign key constraint is +# violated, then an error is reported when the user attempts to commit +# the transaction if the foreign key constraint violations still exist +# at that point. +# +do_test e_fkey-59.1 { + execsql { + DELETE FROM c1 ; DELETE FROM c2 ; DELETE FROM c3 ; + DELETE FROM c4 ; DELETE FROM c5 ; DELETE FROM c6 ; + DELETE FROM c7 + } +} {} +do_test e_fkey-59.2 { + execsql { INSERT INTO c7 VALUES('a', 'b') } + execsql { + BEGIN; + DROP TABLE p; + } +} {} +do_test e_fkey-59.3 { + catchsql COMMIT +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-59.4 { + execsql { CREATE TABLE p(a, b, PRIMARY KEY(a, b)) } + catchsql COMMIT +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-59.5 { + execsql { INSERT INTO p VALUES('a', 'b') } + execsql COMMIT +} {} + +#------------------------------------------------------------------------- +# Any "foreign key mismatch" errors encountered while running an implicit +# "DELETE FROM tbl" are ignored. +# +# EVIDENCE-OF: R-57242-37005 Any "foreign key mismatch" errors +# encountered as part of an implicit DELETE are ignored. +# +drop_all_tables +do_test e_fkey-60.1 { + execsql { + PRAGMA foreign_keys = OFF; + + CREATE TABLE p(a PRIMARY KEY, b REFERENCES nosuchtable); + CREATE TABLE c1(c, d, FOREIGN KEY(c, d) REFERENCES a); + CREATE TABLE c2(c REFERENCES p(b), d); + CREATE TABLE c3(c REFERENCES p ON DELETE SET NULL, d); + + INSERT INTO p VALUES(1, 2); + INSERT INTO c1 VALUES(1, 2); + INSERT INTO c2 VALUES(1, 2); + INSERT INTO c3 VALUES(1, 2); + } +} {} +do_test e_fkey-60.2 { + execsql { PRAGMA foreign_keys = ON } + catchsql { DELETE FROM p } +} {1 {no such table: main.nosuchtable}} +do_test e_fkey-60.3 { + execsql { + BEGIN; + DROP TABLE p; + SELECT * FROM c3; + ROLLBACK; + } +} {{} 2} +do_test e_fkey-60.4 { + execsql { CREATE TABLE nosuchtable(x PRIMARY KEY) } + catchsql { DELETE FROM p } +} {1 {foreign key mismatch - "c2" referencing "p"}} +do_test e_fkey-60.5 { + execsql { DROP TABLE c1 } + catchsql { DELETE FROM p } +} {1 {foreign key mismatch - "c2" referencing "p"}} +do_test e_fkey-60.6 { + execsql { DROP TABLE c2 } + execsql { DELETE FROM p } +} {} + +#------------------------------------------------------------------------- +# Test that the special behaviors of ALTER and DROP TABLE are only +# activated when foreign keys are enabled. Special behaviors are: +# +# 1. ADD COLUMN not allowing a REFERENCES clause with a non-NULL +# default value. +# 2. Modifying foreign key definitions when a parent table is RENAMEd. +# 3. Running an implicit DELETE FROM command as part of DROP TABLE. +# +# EVIDENCE-OF: R-54142-41346 The properties of the DROP TABLE and ALTER +# TABLE commands described above only apply if foreign keys are enabled. +# +ifcapable altertable { +do_test e_fkey-61.1.1 { + drop_all_tables + execsql { CREATE TABLE t1(a, b) ; INSERT INTO t1 VALUES(1, 2) } + catchsql { ALTER TABLE t1 ADD COLUMN c DEFAULT 'xxx' REFERENCES t2 } +} {1 {Cannot add a REFERENCES column with non-NULL default value}} +do_test e_fkey-61.1.2 { + execsql { PRAGMA foreign_keys = OFF } + execsql { ALTER TABLE t1 ADD COLUMN c DEFAULT 'xxx' REFERENCES t2 } + execsql { SELECT sql FROM sqlite_master WHERE name = 't1' } +} {{CREATE TABLE t1(a, b, c DEFAULT 'xxx' REFERENCES t2)}} +do_test e_fkey-61.1.3 { + execsql { PRAGMA foreign_keys = ON } +} {} + +do_test e_fkey-61.2.1 { + drop_all_tables + execsql { + CREATE TABLE p(a UNIQUE); + CREATE TABLE c(b REFERENCES p(a)); + BEGIN; + ALTER TABLE p RENAME TO parent; + SELECT sql FROM sqlite_master WHERE name = 'c'; + ROLLBACK; + } +} {{CREATE TABLE c(b REFERENCES "parent"(a))}} +do_test e_fkey-61.2.2 { + execsql { + PRAGMA foreign_keys = OFF; + PRAGMA legacy_alter_table = ON; + ALTER TABLE p RENAME TO parent; + SELECT sql FROM sqlite_master WHERE name = 'c'; + } +} {{CREATE TABLE c(b REFERENCES p(a))}} +do_test e_fkey-61.2.3 { + execsql { PRAGMA foreign_keys = ON } + execsql { PRAGMA legacy_alter_table = OFF } +} {} + +do_test e_fkey-61.3.1 { + drop_all_tables + execsql { + CREATE TABLE p(a UNIQUE); + CREATE TABLE c(b REFERENCES p(a) ON DELETE SET NULL); + INSERT INTO p VALUES('x'); + INSERT INTO c VALUES('x'); + BEGIN; + DROP TABLE p; + SELECT * FROM c; + ROLLBACK; + } +} {{}} +do_test e_fkey-61.3.2 { + execsql { + PRAGMA foreign_keys = OFF; + DROP TABLE p; + SELECT * FROM c; + } +} {x} +do_test e_fkey-61.3.3 { + execsql { PRAGMA foreign_keys = ON } +} {} +} + +########################################################################### +### SECTION 6: Limits and Unsupported Features +########################################################################### + +#------------------------------------------------------------------------- +# Test that MATCH clauses are parsed, but SQLite treats every foreign key +# constraint as if it were "MATCH SIMPLE". +# +# EVIDENCE-OF: R-24728-13230 SQLite parses MATCH clauses (i.e. does not +# report a syntax error if you specify one), but does not enforce them. +# +# EVIDENCE-OF: R-24450-46174 All foreign key constraints in SQLite are +# handled as if MATCH SIMPLE were specified. +# +foreach zMatch [list SIMPLE PARTIAL FULL Simple parTIAL FuLL ] { + drop_all_tables + do_test e_fkey-62.$zMatch.1 { + execsql " + CREATE TABLE p(a, b, c, PRIMARY KEY(b, c)); + CREATE TABLE c(d, e, f, FOREIGN KEY(e, f) REFERENCES p MATCH $zMatch); + " + } {} + do_test e_fkey-62.$zMatch.2 { + execsql { INSERT INTO p VALUES(1, 2, 3) } + + # MATCH SIMPLE behavior: Allow any child key that contains one or more + # NULL value to be inserted. Non-NULL values do not have to map to any + # parent key values, so long as at least one field of the child key is + # NULL. + execsql { INSERT INTO c VALUES('w', 2, 3) } + execsql { INSERT INTO c VALUES('x', 'x', NULL) } + execsql { INSERT INTO c VALUES('y', NULL, 'x') } + execsql { INSERT INTO c VALUES('z', NULL, NULL) } + + # Check that the FK is enforced properly if there are no NULL values + # in the child key columns. + catchsql { INSERT INTO c VALUES('a', 2, 4) } + } {1 {FOREIGN KEY constraint failed}} +} + +#------------------------------------------------------------------------- +# Test that SQLite does not support the SET CONSTRAINT statement. And +# that it is possible to create both immediate and deferred constraints. +# +# EVIDENCE-OF: R-21599-16038 In SQLite, a foreign key constraint is +# permanently marked as deferred or immediate when it is created. +# +drop_all_tables +do_test e_fkey-62.1 { + catchsql { SET CONSTRAINTS ALL IMMEDIATE } +} {1 {near "SET": syntax error}} +do_test e_fkey-62.2 { + catchsql { SET CONSTRAINTS ALL DEFERRED } +} {1 {near "SET": syntax error}} + +do_test e_fkey-62.3 { + execsql { + CREATE TABLE p(a, b, PRIMARY KEY(a, b)); + CREATE TABLE cd(c, d, + FOREIGN KEY(c, d) REFERENCES p DEFERRABLE INITIALLY DEFERRED); + CREATE TABLE ci(c, d, + FOREIGN KEY(c, d) REFERENCES p DEFERRABLE INITIALLY IMMEDIATE); + BEGIN; + } +} {} +do_test e_fkey-62.4 { + catchsql { INSERT INTO ci VALUES('x', 'y') } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-62.5 { + catchsql { INSERT INTO cd VALUES('x', 'y') } +} {0 {}} +do_test e_fkey-62.6 { + catchsql { COMMIT } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-62.7 { + execsql { + DELETE FROM cd; + COMMIT; + } +} {} + +#------------------------------------------------------------------------- +# Test that the maximum recursion depth of foreign key action programs is +# governed by the SQLITE_MAX_TRIGGER_DEPTH and SQLITE_LIMIT_TRIGGER_DEPTH +# settings. +# +# EVIDENCE-OF: R-42264-30503 The SQLITE_MAX_TRIGGER_DEPTH and +# SQLITE_LIMIT_TRIGGER_DEPTH settings determine the maximum allowable +# depth of trigger program recursion. For the purposes of these limits, +# foreign key actions are considered trigger programs. +# +proc test_on_delete_recursion {limit} { + drop_all_tables + execsql { + BEGIN; + CREATE TABLE t0(a PRIMARY KEY, b); + INSERT INTO t0 VALUES('x0', NULL); + } + for {set i 1} {$i <= $limit} {incr i} { + execsql " + CREATE TABLE t$i ( + a PRIMARY KEY, b REFERENCES t[expr $i-1] ON DELETE CASCADE + ); + INSERT INTO t$i VALUES('x$i', 'x[expr $i-1]'); + " + } + execsql COMMIT + catchsql " + DELETE FROM t0; + SELECT count(*) FROM t$limit; + " +} +proc test_on_update_recursion {limit} { + drop_all_tables + execsql { + BEGIN; + CREATE TABLE t0(a PRIMARY KEY); + INSERT INTO t0 VALUES('xxx'); + } + for {set i 1} {$i <= $limit} {incr i} { + set j [expr $i-1] + + execsql " + CREATE TABLE t$i (a PRIMARY KEY REFERENCES t$j ON UPDATE CASCADE); + INSERT INTO t$i VALUES('xxx'); + " + } + execsql COMMIT + catchsql " + UPDATE t0 SET a = 'yyy'; + SELECT NOT (a='yyy') FROM t$limit; + " +} + +# If the current build was created using clang with the -fsanitize=address +# switch, then the library uses considerably more stack space than usual. +# So much more, that some of the following tests cause stack overflows +# if they are run under this configuration. +# +if {[clang_sanitize_address]==0} { + do_test e_fkey-63.1.1 { + test_on_delete_recursion $SQLITE_MAX_TRIGGER_DEPTH + } {0 0} + do_test e_fkey-63.1.2 { + test_on_delete_recursion [expr $SQLITE_MAX_TRIGGER_DEPTH+1] + } {1 {too many levels of trigger recursion}} + do_test e_fkey-63.1.3 { + sqlite3_limit db SQLITE_LIMIT_TRIGGER_DEPTH 5 + test_on_delete_recursion 5 + } {0 0} + do_test e_fkey-63.1.4 { + test_on_delete_recursion 6 + } {1 {too many levels of trigger recursion}} + do_test e_fkey-63.1.5 { + sqlite3_limit db SQLITE_LIMIT_TRIGGER_DEPTH 1000000 + } {5} + do_test e_fkey-63.2.1 { + test_on_update_recursion $SQLITE_MAX_TRIGGER_DEPTH + } {0 0} + do_test e_fkey-63.2.2 { + test_on_update_recursion [expr $SQLITE_MAX_TRIGGER_DEPTH+1] + } {1 {too many levels of trigger recursion}} + do_test e_fkey-63.2.3 { + sqlite3_limit db SQLITE_LIMIT_TRIGGER_DEPTH 5 + test_on_update_recursion 5 + } {0 0} + do_test e_fkey-63.2.4 { + test_on_update_recursion 6 + } {1 {too many levels of trigger recursion}} + do_test e_fkey-63.2.5 { + sqlite3_limit db SQLITE_LIMIT_TRIGGER_DEPTH 1000000 + } {5} +} + +#------------------------------------------------------------------------- +# The setting of the recursive_triggers pragma does not affect foreign +# key actions. +# +# EVIDENCE-OF: R-44355-00270 The PRAGMA recursive_triggers setting does +# not affect the operation of foreign key actions. +# +foreach recursive_triggers_setting [list 0 1 ON OFF] { + drop_all_tables + execsql "PRAGMA recursive_triggers = $recursive_triggers_setting" + + do_test e_fkey-64.$recursive_triggers_setting.1 { + execsql { + CREATE TABLE t1(a PRIMARY KEY, b REFERENCES t1 ON DELETE CASCADE); + INSERT INTO t1 VALUES(1, NULL); + INSERT INTO t1 VALUES(2, 1); + INSERT INTO t1 VALUES(3, 2); + INSERT INTO t1 VALUES(4, 3); + INSERT INTO t1 VALUES(5, 4); + SELECT count(*) FROM t1; + } + } {5} + do_test e_fkey-64.$recursive_triggers_setting.2 { + execsql { SELECT count(*) FROM t1 WHERE a = 1 } + } {1} + do_test e_fkey-64.$recursive_triggers_setting.3 { + execsql { + DELETE FROM t1 WHERE a = 1; + SELECT count(*) FROM t1; + } + } {0} +} + +finish_test diff --git a/test/e_fts3.test b/test/e_fts3.test new file mode 100644 index 0000000..c06feab --- /dev/null +++ b/test/e_fts3.test @@ -0,0 +1,707 @@ +# 2009 November 28 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file implements tests to verify the "testable statements" in the +# fts3.in document. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If this build does not include FTS3, skip the tests in this file. +# +ifcapable !fts3 { finish_test ; return } +source $testdir/fts3_common.tcl +source $testdir/malloc_common.tcl + +# Procs used to make the tests in this file easier to read. +# +proc ddl_test {tn ddl} { + uplevel [list do_write_test e_fts3-$tn sqlite_master $ddl] +} +proc write_test {tn tbl sql} { + uplevel [list do_write_test e_fts3-$tn $tbl $sql] +} +proc read_test {tn sql result} { + uplevel [list do_select_test e_fts3-$tn $sql $result] +} +proc error_test {tn sql result} { + uplevel [list do_error_test e_fts3-$tn $sql $result] +} + + +#------------------------------------------------------------------------- +# The body of the following [foreach] block contains test cases to verify +# that the example code in fts3.html works as expected. The tests run three +# times, with different values for DO_MALLOC_TEST. +# +# DO_MALLOC_TEST=0: Run tests with no OOM errors. +# DO_MALLOC_TEST=1: Run tests with transient OOM errors. +# DO_MALLOC_TEST=2: Run tests with persistent OOM errors. +# +foreach {DO_MALLOC_TEST enc} { + 0 utf-8 + 1 utf-8 + 2 utf-8 + 1 utf-16 +} { + +#if {$DO_MALLOC_TEST} break + +# Reset the database and database connection. If this iteration of the +# [foreach] loop is testing with OOM errors, disable the lookaside buffer. +# +db close +forcedelete test.db test.db-journal +sqlite3 db test.db +if {$DO_MALLOC_TEST} { sqlite3_db_config_lookaside db 0 0 0 } +db eval "PRAGMA encoding = '$enc'" + +proc mit {blob} { + set scan(littleEndian) i* + set scan(bigEndian) I* + binary scan $blob $scan($::tcl_platform(byteOrder)) r + return $r +} +db func mit mit + +########################################################################## +# Test the example CREATE VIRTUAL TABLE statements in section 1.1 +# of fts3.in. +# +ddl_test 1.1.1.1 {CREATE VIRTUAL TABLE data USING fts3()} +read_test 1.1.1.2 {PRAGMA table_info(data)} {0 content {} 0 {} 0} + +ddl_test 1.1.2.1 { + CREATE VIRTUAL TABLE pages USING fts3(title, keywords, body) +} +read_test 1.1.2.2 { + PRAGMA table_info(pages) +} {0 title {} 0 {} 0 1 keywords {} 0 {} 0 2 body {} 0 {} 0} + +ddl_test 1.1.3.1 { + CREATE VIRTUAL TABLE mail USING fts3( + subject VARCHAR(256) NOT NULL, + body TEXT CHECK(length(body)<10240) + ) +} +read_test 1.1.3.2 { + PRAGMA table_info(mail) +} {0 subject {} 0 {} 0 1 body {} 0 {} 0} + +# A very large string. Used to test if the constraint on column "body" of +# table "mail" is enforced (it should not be - FTS3 tables do not support +# constraints). +set largetext [string repeat "the quick brown fox " 5000] +write_test 1.1.3.3 mail_content { INSERT INTO mail VALUES(NULL, $largetext) } +read_test 1.1.3.4 { + SELECT subject IS NULL, length(body) FROM mail +} [list 1 100000] + +ddl_test 1.1.4.1 { + CREATE VIRTUAL TABLE papers USING fts3(author, document, tokenize=porter) +} +read_test 1.1.4.2 { + PRAGMA table_info(papers) +} {0 author {} 0 {} 0 1 document {} 0 {} 0} + +ddl_test 1.1.5.1 { + CREATE VIRTUAL TABLE simpledata USING fts3(tokenize=simple) +} +read_test 1.1.5.2 { + PRAGMA table_info(simpledata) +} {0 content {} 0 {} 0} + +ifcapable icu { + ddl_test 1.1.6.1 { + CREATE VIRTUAL TABLE names USING fts3(a, b, tokenize=icu en_AU) + } + read_test 1.1.6.2 { + PRAGMA table_info(names) + } {0 a {} 0 {} 0 1 b {} 0 {} 0} +} + +ddl_test 1.1.7.1 {DROP TABLE data} +ddl_test 1.1.7.2 {DROP TABLE pages} +ddl_test 1.1.7.3 {DROP TABLE mail} +ddl_test 1.1.7.4 {DROP TABLE papers} +ddl_test 1.1.7.5 {DROP TABLE simpledata} +read_test 1.1.7.6 {SELECT * FROM sqlite_master} {} + +# The following is not one of the examples in section 1.1. It tests +# specifying an FTS3 table with no module arguments using a slightly +# different syntax. +ddl_test 1.1.8.1 {CREATE VIRTUAL TABLE data USING fts3;} +read_test 1.1.8.2 {PRAGMA table_info(data)} {0 content {} 0 {} 0} +ddl_test 1.1.8.3 {DROP TABLE data} + +########################################################################## +# Test the examples in section 1.2 (populating fts3 tables) +# +ddl_test 1.2.1.1 { + CREATE VIRTUAL TABLE pages USING fts3(title, body); +} +write_test 1.2.1.2 pages_content { + INSERT INTO pages(docid, title, body) + VALUES(53, 'Home Page', 'SQLite is a software...'); +} +read_test 1.2.1.3 { + SELECT docid, * FROM pages +} {53 {Home Page} {SQLite is a software...}} + +write_test 1.2.1.4 pages_content { + INSERT INTO pages(title, body) + VALUES('Download', 'All SQLite source code...'); +} +read_test 1.2.1.5 { + SELECT docid, * FROM pages +} {53 {Home Page} {SQLite is a software...} 54 Download {All SQLite source code...}} + +write_test 1.2.1.6 pages_content { + UPDATE pages SET title = 'Download SQLite' WHERE rowid = 54 +} +read_test 1.2.1.7 { + SELECT docid, * FROM pages +} {53 {Home Page} {SQLite is a software...} 54 {Download SQLite} {All SQLite source code...}} + +write_test 1.2.1.8 pages_content { DELETE FROM pages } +read_test 1.2.1.9 { SELECT docid, * FROM pages } {} + +do_error_test fts3-1.2.1.10 { + INSERT INTO pages(rowid, docid, title, body) VALUES(1, 2, 'A title', 'A document body'); +} {SQL logic error} + +# Test the optimize() function example: +ddl_test 1.2.2.1 { CREATE VIRTUAL TABLE docs USING fts3 } +write_test 1.2.2.2 docs_content { + INSERT INTO docs VALUES('Others translate the first clause as'); +} +write_test 1.2.2.3 docs_content { + INSERT INTO docs VALUES('"which is for Solomon," meaning that'); +} +write_test 1.2.2.4 docs_content { + INSERT INTO docs VALUES('the book is dedicated to Solomon.'); +} +read_test 1.2.2.5 { SELECT count(*) FROM docs_segdir } {3} +write_test 1.2.2.6 docs_segdir { + INSERT INTO docs(docs) VALUES('optimize'); +} +read_test 1.2.2.7 { SELECT count(*) FROM docs_segdir } {1} +ddl_test 1.2.2.8 { DROP TABLE docs } + +########################################################################## +# Test the examples in section 1.3 (querying FTS3 tables) +# +ddl_test 1.3.1.1 { CREATE VIRTUAL TABLE mail USING fts3(subject, body) } +read_test 1.3.1.2 { + SELECT * FROM mail WHERE rowid = 15; -- Fast. Rowid lookup. + SELECT * FROM mail WHERE body MATCH 'sqlite'; -- Fast. Full-text query. + SELECT * FROM mail WHERE mail MATCH 'search'; -- Fast. Full-text query. + SELECT * FROM mail WHERE rowid BETWEEN 15 AND 20; -- Slow. Linear scan. + SELECT * FROM mail WHERE subject = 'database'; -- Slow. Linear scan. + SELECT * FROM mail WHERE subject MATCH 'database'; -- Fast. Full-text query. +} {} +ddl_test 1.3.1.3 { DROP TABLE mail } + +ddl_test 1.3.2.1 { CREATE VIRTUAL TABLE mail USING fts3(subject, body) } + +write_test 1.3.2.2 mail_content { + INSERT INTO mail(docid, subject, body) + VALUES(1, 'software feedback', 'found it too slow') +} +write_test 1.3.2.3 mail_content { + INSERT INTO mail(docid, subject, body) + VALUES(2, 'software feedback', 'no feedback') +} +write_test 1.3.2.4 mail_content { + INSERT INTO mail(docid, subject, body) + VALUES(3, 'slow lunch order', 'was a software problem') +} +read_test 1.3.2.5 { + SELECT * FROM mail WHERE subject MATCH 'software' +} {{software feedback} {found it too slow} {software feedback} {no feedback}} +read_test 1.3.2.6 { + SELECT * FROM mail WHERE body MATCH 'feedback' +} {{software feedback} {no feedback}} +read_test 1.3.2.7 { + SELECT * FROM mail WHERE mail MATCH 'software' +} {{software feedback} {found it too slow} {software feedback} {no feedback} {slow lunch order} {was a software problem}} +read_test 1.3.2.7 { + SELECT * FROM mail WHERE mail MATCH 'slow' +} {{software feedback} {found it too slow} {slow lunch order} {was a software problem}} +ddl_test 1.3.2.8 { DROP TABLE mail } + +ddl_test 1.3.3.1 { CREATE VIRTUAL TABLE docs USING fts3(content) } +read_test 1.3.3.2 { SELECT * FROM docs WHERE docs MATCH 'sqlite' } {} +read_test 1.3.3.3 { SELECT * FROM docs WHERE docs.docs MATCH 'sqlite' } {} +read_test 1.3.3.4 { SELECT * FROM docs WHERE main.docs.docs MATCH 'sqlite' } {} +do_error_test e_fts3-1.3.3.5 { + SELECT * FROM docs WHERE main.docs MATCH 'sqlite' +} {no such column: main.docs} +ddl_test 1.3.2.8 { DROP TABLE docs } + +########################################################################## +# Test the examples in section 3 (full-text index queries). +# +ddl_test 1.4.1.1 { CREATE VIRTUAL TABLE docs USING fts3(title, body) } +unset -nocomplain R +foreach {tn title body} { + 2 "linux driver" "a device" + 3 "driver" "linguistic trick" + 4 "problems" "linux problems" + 5 "linux" "big problems" + 6 "linux driver" "a device driver problem" + 7 "good times" "applications for linux" + 8 "not so good" "linux applications" + 9 "alternative" "linoleum appliances" + 10 "no L I N" "to be seen" +} { + write_test 1.4.1.$tn docs_content { INSERT INTO docs VALUES($title,$body) } + set R($tn) [list $title $body] +} + +read_test 1.4.1.11 { + SELECT * FROM docs WHERE docs MATCH 'linux' +} [concat $R(2) $R(4) $R(5) $R(6) $R(7) $R(8)] +read_test 1.4.1.12 { + SELECT * FROM docs WHERE docs MATCH 'lin*' +} [concat $R(2) $R(3) $R(4) $R(5) $R(6) $R(7) $R(8) $R(9)] +read_test 1.4.1.13 { + SELECT * FROM docs WHERE docs MATCH 'title:linux problems' +} [concat $R(5)] +read_test 1.4.1.14 { + SELECT * FROM docs WHERE body MATCH 'title:linux driver' +} [concat $R(6)] +read_test 1.4.1.15 { + SELECT * FROM docs WHERE docs MATCH '"linux applications"' +} [concat $R(8)] +read_test 1.4.1.16 { + SELECT * FROM docs WHERE docs MATCH '"lin* app*"' +} [concat $R(8) $R(9)] +ddl_test 1.4.1.17 { DROP TABLE docs } +unset R + +ddl_test 1.4.2.1 { CREATE VIRTUAL TABLE docs USING fts3() } +write_test 1.4.2.2 docs_content { + INSERT INTO docs VALUES( + 'SQLite is an ACID compliant embedded relational database management system') +} +foreach {tn query hit} { +3 {SELECT * FROM docs WHERE docs MATCH 'sqlite NEAR database'} 1 +4 {SELECT * FROM docs WHERE docs MATCH 'database NEAR/6 sqlite'} 1 +5 {SELECT * FROM docs WHERE docs MATCH 'database NEAR/5 sqlite'} 0 +6 {SELECT * FROM docs WHERE docs MATCH 'database NEAR/2 "ACID compliant"'} 1 +7 {SELECT * FROM docs WHERE docs MATCH '"ACID compliant" NEAR/2 sqlite'} 1 +8 {SELECT * FROM docs WHERE docs MATCH 'sqlite NEAR/2 acid NEAR/2 relational'} 1 +9 {SELECT * FROM docs WHERE docs MATCH 'acid NEAR/2 sqlite NEAR/2 relational'} 0 +} { + set res [db eval {SELECT * FROM docs WHERE $hit}] + read_test 1.4.2.$tn $query $res +} +ddl_test 1.4.2.10 { DROP TABLE docs } + +########################################################################## +# Test the example in section 3.1 (set operators with enhanced syntax). +# +set sqlite_fts3_enable_parentheses 1 +ddl_test 1.5.1.1 { CREATE VIRTUAL TABLE docs USING fts3() } +foreach {tn docid content} { + 2 1 "a database is a software system" + 3 2 "sqlite is a software system" + 4 3 "sqlite is a database" +} { + set R($docid) $content + write_test 1.5.1.$tn docs_content { + INSERT INTO docs(docid, content) VALUES($docid, $content) + } +} +read_test 1.5.1.4 { + SELECT * FROM docs WHERE docs MATCH 'sqlite AND database' +} [list $R(3)] +read_test 1.5.1.5 { + SELECT * FROM docs WHERE docs MATCH 'database sqlite' +} [list $R(3)] +read_test 1.5.1.6 { + SELECT * FROM docs WHERE docs MATCH 'sqlite OR database' +} [list $R(1) $R(2) $R(3)] +read_test 1.5.1.7 { + SELECT * FROM docs WHERE docs MATCH 'database NOT sqlite' +} [list $R(1)] +read_test 1.5.1.8 { + SELECT * FROM docs WHERE docs MATCH 'database and sqlite' +} {} + +write_test 1.5.2.1 docs_content { + INSERT INTO docs + SELECT 'sqlite is also a library' UNION ALL + SELECT 'library software' +} +read_test 1.5.2.2 { + SELECT docid FROM docs WHERE docs MATCH 'sqlite AND database OR library' +} {3 4 5} +read_test 1.5.2.3 { + SELECT docid FROM docs WHERE docs MATCH 'sqlite AND database' + UNION + SELECT docid FROM docs WHERE docs MATCH 'library' +} {3 4 5} +write_test 1.5.2.4 docs_content { + INSERT INTO docs + SELECT 'the sqlite library runs on linux' UNION ALL + SELECT 'as does the sqlite database (on linux)' UNION ALL + SELECT 'the sqlite database is accessed by the sqlite library' +} +read_test 1.5.2.2 { + SELECT docid FROM docs + WHERE docs MATCH '("sqlite database" OR "sqlite library") AND linux'; +} {6 7} +read_test 1.5.2.3 { + SELECT docid FROM docs WHERE docs MATCH 'linux' + INTERSECT + SELECT docid FROM ( + SELECT docid FROM docs WHERE docs MATCH '"sqlite library"' + UNION + SELECT docid FROM docs WHERE docs MATCH '"sqlite database"' + ); +} {6 7} + +########################################################################## +# Test the examples in section 3.2 (set operators with standard syntax). +# These tests reuse the table populated by the block above. +# +set sqlite_fts3_enable_parentheses 0 +read_test 1.6.1.1 { + SELECT * FROM docs WHERE docs MATCH 'sqlite -database' +} {{sqlite is a software system} {sqlite is also a library} {the sqlite library runs on linux}} +read_test 1.6.1.2 { + SELECT * FROM docs WHERE docs MATCH 'sqlite OR database library' +} {{sqlite is also a library} {the sqlite library runs on linux} {the sqlite database is accessed by the sqlite library}} + +set sqlite_fts3_enable_parentheses 1 +read_test 1.6.1.3 { + SELECT * FROM docs WHERE docs MATCH 'sqlite OR database library' +} {{sqlite is a software system} {sqlite is a database} {sqlite is also a library} {the sqlite library runs on linux} {as does the sqlite database (on linux)} {the sqlite database is accessed by the sqlite library}} +read_test 1.6.1.4 { + SELECT * FROM docs WHERE docs MATCH '(sqlite OR database) library' +} {{sqlite is also a library} {the sqlite library runs on linux} {the sqlite database is accessed by the sqlite library}} +set sqlite_fts3_enable_parentheses 0 +ddl_test 1.6.1.5 { DROP TABLE docs } + +########################################################################## +# Test the examples in section 4 (auxillary functions). +# +ddl_test 1.7.1.1 { CREATE VIRTUAL TABLE mail USING fts3(subject, body) } + +write_test 1.7.1.2 mail_content { + INSERT INTO mail VALUES( + 'hello world', 'This message is a hello world message.'); +} +write_test 1.7.1.3 mail_content { + INSERT INTO mail VALUES( + 'urgent: serious', 'This mail is seen as a more serious mail'); +} + +read_test 1.7.1.4 { + SELECT offsets(mail) FROM mail WHERE mail MATCH 'world'; +} {{0 0 6 5 1 0 24 5}} +read_test 1.7.1.5 { + SELECT offsets(mail) FROM mail WHERE mail MATCH 'message' +} {{1 0 5 7 1 0 30 7}} +read_test 1.7.1.6 { + SELECT offsets(mail) FROM mail WHERE mail MATCH '"serious mail"' +} {{1 0 28 7 1 1 36 4}} + +ddl_test 1.7.2.1 { CREATE VIRTUAL TABLE text USING fts3() } + +write_test 1.7.2.2 text_content { + INSERT INTO text VALUES(' + During 30 Nov-1 Dec, 2-3oC drops. Cool in the upper portion, minimum temperature 14-16oC and cool elsewhere, minimum temperature 17-20oC. Cold to very cold on mountaintops, minimum temperature 6-12oC. Northeasterly winds 15-30 km/hr. After that, temperature increases. Northeasterly winds 15-30 km/hr. + '); +} + +read_test 1.7.2.3 { + SELECT snippet(text) FROM text WHERE text MATCH 'cold' +} {{...cool elsewhere, minimum temperature 17-20oC. Cold to very cold on mountaintops, minimum temperature 6...}} + +read_test 1.7.2.4 { + SELECT snippet(text, '[', ']', '...') FROM text WHERE text MATCH '"min* tem*"' +} {{...the upper portion, [minimum] [temperature] 14-16oC and cool elsewhere, [minimum] [temperature] 17-20oC. Cold...}} + +ddl_test 1.7.3.1 { DROP TABLE IF EXISTS t1 } +ddl_test 1.7.3.2 { CREATE VIRTUAL TABLE t1 USING fts3(a, b) } +write_test 1.7.3.3 t1_content { + INSERT INTO t1 VALUES( + 'transaction default models default', 'Non transaction reads'); +} +write_test 1.7.3.4 t1_content { + INSERT INTO t1 VALUES('the default transaction', 'these semantics present'); +} +write_test 1.7.3.5 t1_content { + INSERT INTO t1 VALUES('single request', 'default data'); +} +read_test 1.7.3.6 { + SELECT mit(matchinfo(t1)) FROM t1 + WHERE t1 MATCH 'default transaction "these semantics"'; +} {{3 2 1 3 2 0 1 1 1 2 2 0 1 1 0 0 0 1 1 1}} + +########################################################################## +# Test the example in section 5 (custom tokenizers). +# +ddl_test 1.8.1.1 { CREATE VIRTUAL TABLE simple USING fts3(tokenize=simple) } +write_test 1.8.1.2 simple_content { + INSERT INTO simple VALUES('Right now they''re very frustrated') +} +read_test 1.8.1.3 {SELECT docid FROM simple WHERE simple MATCH 'Frustrated'} {1} +read_test 1.8.1.4 {SELECT docid FROM simple WHERE simple MATCH 'Frustration'} {} + +ddl_test 1.8.2.1 { CREATE VIRTUAL TABLE porter USING fts3(tokenize=porter) } +write_test 1.8.2.2 porter_content { + INSERT INTO porter VALUES('Right now they''re very frustrated') +} +read_test 1.8.2.4 { + SELECT docid FROM porter WHERE porter MATCH 'Frustration' +} {1} + +} +# End of tests of example code in fts3.html +#------------------------------------------------------------------------- + +#------------------------------------------------------------------------- +# Test that errors in the arguments passed to the snippet and offsets +# functions are handled correctly. +# +set DO_MALLOC_TEST 0 +ddl_test 2.1.0 { DROP TABLE IF EXISTS t1 } +ddl_test 2.1.1 { CREATE VIRTUAL TABLE t1 USING fts3(a, b) } +write_test 2.1.2 t1_content { + INSERT INTO t1 VALUES('one two three', x'A1B2C3D4E5F6'); +} +error_test 2.1.3 { + SELECT offsets(a) FROM t1 WHERE a MATCH 'one' +} {illegal first argument to offsets} +error_test 2.1.4 { + SELECT offsets(b) FROM t1 WHERE a MATCH 'one' +} {illegal first argument to offsets} +error_test 2.1.5 { + SELECT optimize(a) FROM t1 LIMIT 1 +} {illegal first argument to optimize} +error_test 2.1.6 { + SELECT snippet(a) FROM t1 WHERE a MATCH 'one' +} {illegal first argument to snippet} +error_test 2.1.7 { + SELECT snippet() FROM t1 WHERE a MATCH 'one' +} {unable to use function snippet in the requested context} +error_test 2.1.8 { + SELECT snippet(a, b, 'A', 'B', 'C', 'D', 'E') FROM t1 WHERE a MATCH 'one' +} {wrong number of arguments to function snippet()} +#------------------------------------------------------------------------- + +#------------------------------------------------------------------------- +# Test the effect of an OOM error while installing the FTS3 module (i.e. +# opening a database handle). This case was not tested by the OOM testing +# of the document examples above. +# +do_malloc_test e_fts3-3 -tclbody { + if {[catch {sqlite3 db test.db}]} { error "out of memory" } +} +#------------------------------------------------------------------------- + +#------------------------------------------------------------------------- +# Verify the return values of the optimize() function. If no error occurs, +# the returned value should be "Index optimized" if the data structure +# was modified, or "Index already optimal" if it were not. +# +set DO_MALLOC_TEST 0 +ddl_test 4.1 { CREATE VIRTUAL TABLE t4 USING fts3(a, b) } +write_test 4.2 t4_content { + INSERT INTO t4 VALUES('In Xanadu', 'did Kubla Khan'); +} +write_test 4.3 t4_content { + INSERT INTO t4 VALUES('a stately pleasure', 'dome decree'); +} +do_test e_fts3-4.4 { + execsql { SELECT optimize(t4) FROM t4 LIMIT 1 } +} {{Index optimized}} +do_test e_fts3-4.5 { + execsql { SELECT optimize(t4) FROM t4 LIMIT 1 } +} {{Index already optimal}} +#------------------------------------------------------------------------- + +#------------------------------------------------------------------------- +# Test that the snippet function appears to work correctly with 1, 2, 3 +# or 4 arguments passed to it. +# +set DO_MALLOC_TEST 0 +ddl_test 5.1 { CREATE VIRTUAL TABLE t5 USING fts3(x) } +write_test 5.2 t5_content { + INSERT INTO t5 VALUES('In Xanadu did Kubla Khan A stately pleasure-dome decree Where Alph, the sacred river, ran Through caverns measureless to man Down to a sunless sea. So twice five miles of fertile ground With walls and towers were girdled round : And there were gardens bright with sinuous rills, Where blossomed many an incense-bearing tree ; And here were forests ancient as the hills, Enfolding sunny spots of greenery.'); +} +read_test 5.3 { + SELECT snippet(t5) FROM t5 WHERE t5 MATCH 'miles' +} {{...to a sunless sea. So twice five miles of fertile ground With walls and towers...}} +read_test 5.4 { + SELECT snippet(t5, '') FROM t5 WHERE t5 MATCH 'miles' +} {{...to a sunless sea. So twice five miles of fertile ground With walls and towers...}} +read_test 5.5 { + SELECT snippet(t5, '', '') FROM t5 WHERE t5 MATCH 'miles' +} {{...to a sunless sea. So twice five miles of fertile ground With walls and towers...}} +read_test 5.6 { + SELECT snippet(t5, '', '', 'XXX') FROM t5 WHERE t5 MATCH 'miles' +} {{XXXto a sunless sea. So twice five miles of fertile ground With walls and towersXXX}} +#------------------------------------------------------------------------- + +#------------------------------------------------------------------------- +# Test that an empty MATCH expression returns an empty result set. As +# does passing a NULL value as a MATCH expression. +# +set DO_MALLOC_TEST 0 +ddl_test 6.1 { CREATE VIRTUAL TABLE t6 USING fts3(x) } +write_test 6.2 t5_content { INSERT INTO t6 VALUES('a'); } +write_test 6.3 t5_content { INSERT INTO t6 VALUES('b'); } +write_test 6.4 t5_content { INSERT INTO t6 VALUES('c'); } +read_test 6.5 { SELECT * FROM t6 WHERE t6 MATCH '' } {} +read_test 6.6 { SELECT * FROM t6 WHERE x MATCH '' } {} +read_test 6.7 { SELECT * FROM t6 WHERE t6 MATCH NULL } {} +read_test 6.8 { SELECT * FROM t6 WHERE x MATCH NULL } {} +#------------------------------------------------------------------------- + +#------------------------------------------------------------------------- +# Test a few facets of the FTS3 xFilter() callback implementation: +# +# 1. That the sqlite3_index_constraint.usable flag is respected. +# +# 2. That it is an error to use the "docid" or "rowid" column of +# an FTS3 table as the LHS of a MATCH operator. +# +# 3. That it is an error to AND together two MATCH expressions in +# that refer to a single FTS3 table in a WHERE clause. +# +# +set DO_MALLOC_TEST 0 +ddl_test 7.1.1 { CREATE VIRTUAL TABLE t7 USING fts3(a) } +ddl_test 7.1.2 { CREATE VIRTUAL TABLE t8 USING fts3(b) } +write_test 7.1.3 t7_content { INSERT INTO t7(docid, a) VALUES(4,'number four') } +write_test 7.1.4 t7_content { INSERT INTO t7(docid, a) VALUES(5,'number five') } +write_test 7.1.5 t8_content { INSERT INTO t8(docid, b) VALUES(4,'letter D') } +write_test 7.1.6 t8_content { INSERT INTO t8(docid, b) VALUES(5,'letter E') } +read_test 7.1.7 { + SELECT a || ':' || b FROM t7 JOIN t8 USING(docid) +} {{number four:letter D} {number five:letter E}} + +error_test 7.2.1 { + SELECT * FROM t7 WHERE docid MATCH 'number' +} {unable to use function MATCH in the requested context} +error_test 7.2.2 { + SELECT * FROM t7 WHERE rowid MATCH 'number' +} {unable to use function MATCH in the requested context} + +error_test 7.3.1 { + SELECT * FROM t7 WHERE a MATCH 'number' AND a MATCH 'four' +} {unable to use function MATCH in the requested context} +error_test 7.3.2 { + SELECT * FROM t7, t8 WHERE a MATCH 'number' AND a MATCH 'four' +} {unable to use function MATCH in the requested context} +error_test 7.3.3 { + SELECT * FROM t7, t8 WHERE b MATCH 'letter' AND b MATCH 'd' +} {unable to use function MATCH in the requested context} +read_test 7.3.4 { + SELECT * FROM t7, t8 WHERE a MATCH 'number' AND b MATCH 'letter' +} {{number four} {letter D} {number four} {letter E} {number five} {letter D} {number five} {letter E}} +read_test 7.3.5 { + SELECT * FROM t7 WHERE a MATCH 'number' AND docid = 4 +} {{number four}} + +#------------------------------------------------------------------------- +# Test the quoting of FTS3 table column names. Names may be quoted using +# any of "", '', ``` or []. +# +set DO_MALLOC_TEST 0 +ddl_test 8.1.1 { CREATE VIRTUAL TABLE t9a USING fts3("c1", [c2]) } +ddl_test 8.1.2 { CREATE VIRTUAL TABLE t9b USING fts3('c1', `c2`) } +read_test 8.1.3 { PRAGMA table_info(t9a) } {0 c1 {} 0 {} 0 1 c2 {} 0 {} 0} +read_test 8.1.4 { PRAGMA table_info(t9b) } {0 c1 {} 0 {} 0 1 c2 {} 0 {} 0} +ddl_test 8.2.1 { CREATE VIRTUAL TABLE t9c USING fts3("c""1", 'c''2') } +read_test 8.2.2 { PRAGMA table_info(t9c) } {0 c\"1 {} 0 {} 0 1 c'2 {} 0 {} 0} +#------------------------------------------------------------------------- + +#------------------------------------------------------------------------- +# Test that FTS3 tables can be renamed using the ALTER RENAME command. +# OOM errors are tested during ALTER RENAME commands also. +# +foreach DO_MALLOC_TEST {0 1 2} { + db close + forcedelete test.db test.db-journal + sqlite3 db test.db + if {$DO_MALLOC_TEST} { sqlite3_db_config_lookaside db 0 0 0 } + + ddl_test 9.1.1 { CREATE VIRTUAL TABLE t10 USING fts3(x) } + write_test 9.1.2 t10_content { INSERT INTO t10 VALUES('fts3 tables') } + write_test 9.1.3 t10_content { INSERT INTO t10 VALUES('are renameable') } + + read_test 9.1.4 { + SELECT * FROM t10 WHERE t10 MATCH 'table*' + } {{fts3 tables}} + read_test 9.1.5 { + SELECT * FROM t10 WHERE x MATCH 'rename*' + } {{are renameable}} + + ddl_test 9.1.6 { ALTER TABLE t10 RENAME TO t11 } + + read_test 9.1.7 { + SELECT * FROM t11 WHERE t11 MATCH 'table*' + } {{fts3 tables}} + read_test 9.1.8 { + SELECT * FROM t11 WHERE x MATCH 'rename*' + } {{are renameable}} +} +#------------------------------------------------------------------------- + +#------------------------------------------------------------------------- +# Test a couple of cases involving corrupt data structures: +# +# 1) A case where a document referenced by the full-text index is +# not present in the %_content table. +# +# 2) A badly formatted b-tree segment node. +# +set DO_MALLOC_TEST 0 +ddl_test 10.1.1 { CREATE VIRTUAL TABLE ta USING fts3 } +write_test 10.1.2 ta_content { + INSERT INTO ta VALUES('During a summer vacation in 1790') } +write_test 10.1.3 ta_content { + INSERT INTO ta VALUES('Wordsworth went on a walking tour') } +sqlite3_db_config db DEFENSIVE 0 +write_test 10.1.4 ta_content { DELETE FROM ta_content WHERE rowid = 2 } +read_test 10.1.5 { + SELECT * FROM ta WHERE ta MATCH 'summer' +} {{During a summer vacation in 1790}} +error_test 10.1.6 { + SELECT * FROM ta WHERE ta MATCH 'walking' +} {database disk image is malformed} + +write_test 10.2.1 ta_content { DELETE FROM ta } +write_test 10.2.2 ta_content { + INSERT INTO ta VALUES('debate demonstrated the rising difficulty') } +write_test 10.2.3 ta_content { + INSERT INTO ta VALUES('Google released its browser beta') } + +set blob [db one {SELECT root FROM ta_segdir WHERE rowid = 2}] +binary scan $blob "a6 a3 a*" start middle end +set middle "\x0E\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x06\x06" +set blob [binary format "a6 a* a*" $start $middle $end] +write_test 10.2.4 ta_segdir { + UPDATE ta_segdir SET root = $blob WHERE rowid = 2 +} +error_test 10.2.5 { + SELECT * FROM ta WHERE ta MATCH 'beta' +} {database disk image is malformed} + + +finish_test diff --git a/test/e_insert.test b/test/e_insert.test new file mode 100644 index 0000000..7561e58 --- /dev/null +++ b/test/e_insert.test @@ -0,0 +1,431 @@ +# 2010 September 18 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# The majority of this file implements tests to verify that the "testable +# statements" in the lang_insert.html document are correct. +# +# Also, it contains tests to verify the statements in (the very short) +# lang_replace.html. +# +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !compound { + finish_test + return +} + +# Organization of tests: +# +# e_insert-0.*: Test the syntax diagram. +# +# e_insert-1.*: Test statements of the form "INSERT ... VALUES(...)". +# +# e_insert-2.*: Test statements of the form "INSERT ... SELECT ...". +# +# e_insert-3.*: Test statements of the form "INSERT ... DEFAULT VALUES". +# +# e_insert-4.*: Test statements regarding the conflict clause. +# +# e_insert-5.*: Test that the qualified table name and "DEFAULT VALUES" +# syntaxes do not work in trigger bodies. +# + +do_execsql_test e_insert-0.0 { + CREATE TABLE a1(a, b); + CREATE TABLE a2(a, b, c DEFAULT 'xyz'); + CREATE TABLE a3(x DEFAULT 1.0, y DEFAULT 'string', z); + CREATE TABLE a4(c UNIQUE, d); +} {} + +proc do_insert_tests {args} { + uplevel do_select_tests $args +} + +# -- syntax diagram insert-stmt +# +do_insert_tests e_insert-0 { + 1 "INSERT INTO a1 DEFAULT VALUES" {} + 2 "INSERT INTO main.a1 DEFAULT VALUES" {} + 3 "INSERT OR ROLLBACK INTO main.a1 DEFAULT VALUES" {} + 4 "INSERT OR ROLLBACK INTO a1 DEFAULT VALUES" {} + 5 "INSERT OR ABORT INTO main.a1 DEFAULT VALUES" {} + 6 "INSERT OR ABORT INTO a1 DEFAULT VALUES" {} + 7 "INSERT OR REPLACE INTO main.a1 DEFAULT VALUES" {} + 8 "INSERT OR REPLACE INTO a1 DEFAULT VALUES" {} + 9 "INSERT OR FAIL INTO main.a1 DEFAULT VALUES" {} + 10 "INSERT OR FAIL INTO a1 DEFAULT VALUES" {} + 11 "INSERT OR FAIL INTO main.a1 DEFAULT VALUES" {} + 12 "INSERT OR IGNORE INTO a1 DEFAULT VALUES" {} + 13 "REPLACE INTO a1 DEFAULT VALUES" {} + 14 "REPLACE INTO main.a1 DEFAULT VALUES" {} + 15 "INSERT INTO a1 VALUES(1, 2)" {} + 16 "INSERT INTO main.a1 VALUES(1, 2)" {} + 17 "INSERT OR ROLLBACK INTO main.a1 VALUES(1, 2)" {} + 18 "INSERT OR ROLLBACK INTO a1 VALUES(1, 2)" {} + 19 "INSERT OR ABORT INTO main.a1 VALUES(1, 2)" {} + 20 "INSERT OR ABORT INTO a1 VALUES(1, 2)" {} + 21 "INSERT OR REPLACE INTO main.a1 VALUES(1, 2)" {} + 22 "INSERT OR REPLACE INTO a1 VALUES(1, 2)" {} + 23 "INSERT OR FAIL INTO main.a1 VALUES(1, 2)" {} + 24 "INSERT OR FAIL INTO a1 VALUES(1, 2)" {} + 25 "INSERT OR FAIL INTO main.a1 VALUES(1, 2)" {} + 26 "INSERT OR IGNORE INTO a1 VALUES(1, 2)" {} + 27 "REPLACE INTO a1 VALUES(1, 2)" {} + 28 "REPLACE INTO main.a1 VALUES(1, 2)" {} + 29 "INSERT INTO a1 (b, a) VALUES(1, 2)" {} + 30 "INSERT INTO main.a1 (b, a) VALUES(1, 2)" {} + 31 "INSERT OR ROLLBACK INTO main.a1 (b, a) VALUES(1, 2)" {} + 32 "INSERT OR ROLLBACK INTO a1 (b, a) VALUES(1, 2)" {} + 33 "INSERT OR ABORT INTO main.a1 (b, a) VALUES(1, 2)" {} + 34 "INSERT OR ABORT INTO a1 (b, a) VALUES(1, 2)" {} + 35 "INSERT OR REPLACE INTO main.a1 (b, a) VALUES(1, 2)" {} + 36 "INSERT OR REPLACE INTO a1 (b, a) VALUES(1, 2)" {} + 37 "INSERT OR FAIL INTO main.a1 (b, a) VALUES(1, 2)" {} + 38 "INSERT OR FAIL INTO a1 (b, a) VALUES(1, 2)" {} + 39 "INSERT OR FAIL INTO main.a1 (b, a) VALUES(1, 2)" {} + 40 "INSERT OR IGNORE INTO a1 (b, a) VALUES(1, 2)" {} + 41 "REPLACE INTO a1 (b, a) VALUES(1, 2)" {} + 42 "REPLACE INTO main.a1 (b, a) VALUES(1, 2)" {} + 43 "INSERT INTO a1 SELECT c, b FROM a2" {} + 44 "INSERT INTO main.a1 SELECT c, b FROM a2" {} + 45 "INSERT OR ROLLBACK INTO main.a1 SELECT c, b FROM a2" {} + 46 "INSERT OR ROLLBACK INTO a1 SELECT c, b FROM a2" {} + 47 "INSERT OR ABORT INTO main.a1 SELECT c, b FROM a2" {} + 48 "INSERT OR ABORT INTO a1 SELECT c, b FROM a2" {} + 49 "INSERT OR REPLACE INTO main.a1 SELECT c, b FROM a2" {} + 50 "INSERT OR REPLACE INTO a1 SELECT c, b FROM a2" {} + 51 "INSERT OR FAIL INTO main.a1 SELECT c, b FROM a2" {} + 52 "INSERT OR FAIL INTO a1 SELECT c, b FROM a2" {} + 53 "INSERT OR FAIL INTO main.a1 SELECT c, b FROM a2" {} + 54 "INSERT OR IGNORE INTO a1 SELECT c, b FROM a2" {} + 55 "REPLACE INTO a1 SELECT c, b FROM a2" {} + 56 "REPLACE INTO main.a1 SELECT c, b FROM a2" {} + 57 "INSERT INTO a1 (b, a) SELECT c, b FROM a2" {} + 58 "INSERT INTO main.a1 (b, a) SELECT c, b FROM a2" {} + 59 "INSERT OR ROLLBACK INTO main.a1 (b, a) SELECT c, b FROM a2" {} + 60 "INSERT OR ROLLBACK INTO a1 (b, a) SELECT c, b FROM a2" {} + 61 "INSERT OR ABORT INTO main.a1 (b, a) SELECT c, b FROM a2" {} + 62 "INSERT OR ABORT INTO a1 (b, a) SELECT c, b FROM a2" {} + 63 "INSERT OR REPLACE INTO main.a1 (b, a) SELECT c, b FROM a2" {} + 64 "INSERT OR REPLACE INTO a1 (b, a) SELECT c, b FROM a2" {} + 65 "INSERT OR FAIL INTO main.a1 (b, a) SELECT c, b FROM a2" {} + 66 "INSERT OR FAIL INTO a1 (b, a) SELECT c, b FROM a2" {} + 67 "INSERT OR FAIL INTO main.a1 (b, a) SELECT c, b FROM a2" {} + 68 "INSERT OR IGNORE INTO a1 (b, a) SELECT c, b FROM a2" {} + 69 "REPLACE INTO a1 (b, a) SELECT c, b FROM a2" {} + 70 "REPLACE INTO main.a1 (b, a) SELECT c, b FROM a2" {} + 71 "INSERT INTO a1 (b, a) VALUES(1, 2),(3,4)" {} + 72 "INSERT INTO main.a1 (b, a) VALUES(1, 2),(3,4)" {} + 73 "INSERT OR ROLLBACK INTO main.a1 (b, a) VALUES(1, 2),(3,4)" {} + 74 "INSERT OR ROLLBACK INTO a1 (b, a) VALUES(1, 2),(3,4)" {} + 75 "INSERT OR ABORT INTO main.a1 (b, a) VALUES(1, 2),(3,4)" {} + 76 "INSERT OR ABORT INTO a1 (b, a) VALUES(1, 2),(3,4)" {} + 77 "INSERT OR REPLACE INTO main.a1 (b, a) VALUES(1, 2),(3,4)" {} + 78 "INSERT OR REPLACE INTO a1 (b, a) VALUES(1, 2),(3,4)" {} + 79 "INSERT OR FAIL INTO main.a1 (b, a) VALUES(1, 2),(3,4)" {} + 80 "INSERT OR FAIL INTO a1 (b, a) VALUES(1, 2),(3,4)" {} + 81 "INSERT OR FAIL INTO main.a1 (b, a) VALUES(1, 2),(3,4)" {} + 82 "INSERT OR IGNORE INTO a1 (b, a) VALUES(1, 2),(3,4)" {} + 83 "REPLACE INTO a1 (b, a) VALUES(1, 2),(3,4)" {} + 84 "REPLACE INTO main.a1 (b, a) VALUES(1, 2),(3,4)" {} +} + +delete_all_data + +# EVIDENCE-OF: R-21490-41092 The first form (with the "VALUES" keyword) +# creates one or more new rows in an existing table. +# +do_insert_tests e_insert-1.1 { + 0 "SELECT count(*) FROM a2" {0} + + 1a "INSERT INTO a2 VALUES(1, 2, 3)" {} + 1b "SELECT count(*) FROM a2" {1} + + 2a "INSERT INTO a2(a, b) VALUES(1, 2)" {} + 2b "SELECT count(*) FROM a2" {2} + + 3a "INSERT INTO a2(a) VALUES(3),(4)" {} + 3b "SELECT count(*) FROM a2" {4} +} + +# EVIDENCE-OF: R-19218-01018 If the column-name list after table-name is +# omitted then the number of values inserted into each row must be the +# same as the number of columns in the table. +# +# A test in the block above verifies that if the VALUES list has the +# correct number of columns (for table a2, 3 columns) works. So these +# tests just show that other values cause an error. +# +do_insert_tests e_insert-1.2 -error { + table %s has %d columns but %d values were supplied +} { + 1 "INSERT INTO a2 VALUES(1)" {a2 3 1} + 2 "INSERT INTO a2 VALUES(1,2)" {a2 3 2} + 3 "INSERT INTO a2 VALUES(1,2,3,4)" {a2 3 4} + 4 "INSERT INTO a2 VALUES(1,2,3,4,5)" {a2 3 5} +} + +# EVIDENCE-OF: R-29730-42609 In this case the result of evaluating the +# left-most expression from each term of the VALUES list is inserted +# into the left-most column of each new row, and so forth for each +# subsequent expression. +# +delete_all_data +do_insert_tests e_insert-1.3 { + 1a "INSERT INTO a2 VALUES(1, 2, 3)" {} + 1b "SELECT * FROM a2 WHERE oid=last_insert_rowid()" {1 2 3} + + 2a "INSERT INTO a2 VALUES('abc', NULL, 3*3+1)" {} + 2b "SELECT * FROM a2 WHERE oid=last_insert_rowid()" {abc {} 10} + + 3a "INSERT INTO a2 VALUES((SELECT count(*) FROM a2), 'x', 'y')" {} + 3b "SELECT * FROM a2 WHERE oid=last_insert_rowid()" {2 x y} +} + +# EVIDENCE-OF: R-21115-58321 If a column-name list is specified, then +# the number of values in each term of the VALUE list must match the +# number of specified columns. +# +do_insert_tests e_insert-1.4 -error { + %d values for %d columns +} { + 1 "INSERT INTO a2(a, b, c) VALUES(1)" {1 3} + 2 "INSERT INTO a2(a, b, c) VALUES(1,2)" {2 3} + 3 "INSERT INTO a2(a, b, c) VALUES(1,2,3,4)" {4 3} + 4 "INSERT INTO a2(a, b, c) VALUES(1,2,3,4,5)" {5 3} + + 5 "INSERT INTO a2(c, a) VALUES(1)" {1 2} + 6 "INSERT INTO a2(c, a) VALUES(1,2,3)" {3 2} + 7 "INSERT INTO a2(c, a) VALUES(1,2,3,4)" {4 2} + 8 "INSERT INTO a2(c, a) VALUES(1,2,3,4,5)" {5 2} +} + +# EVIDENCE-OF: R-07016-26442 Each of the named columns of the new row is +# populated with the results of evaluating the corresponding VALUES +# expression. +# +# EVIDENCE-OF: R-12183-43719 Table columns that do not appear in the +# column list are populated with the default column value (specified as +# part of the CREATE TABLE statement), or with NULL if no default value +# is specified. +# +delete_all_data +do_insert_tests e_insert-1.5 { + 1a "INSERT INTO a2(b, c) VALUES('b', 'c')" {} + 1b "SELECT * FROM a2" {{} b c} + + 2a "INSERT INTO a2(a, b) VALUES('a', 'b')" {} + 2b "SELECT * FROM a2" {{} b c a b xyz} +} + +# EVIDENCE-OF: R-52173-30215 A new entry is inserted into the table for +# each row of data returned by executing the SELECT statement. +# +delete_all_data +do_insert_tests e_insert-2.1 { + 0 "SELECT count(*) FROM a1" {0} + + 1a "SELECT count(*) FROM (SELECT 1, 2)" {1} + 1b "INSERT INTO a1 SELECT 1, 2" {} + 1c "SELECT count(*) FROM a1" {1} + + 2a "SELECT count(*) FROM (SELECT b, a FROM a1)" {1} + 2b "INSERT INTO a1 SELECT b, a FROM a1" {} + 2c "SELECT count(*) FROM a1" {2} + + 3a "SELECT count(*) FROM (SELECT b, a FROM a1)" {2} + 3b "INSERT INTO a1 SELECT b, a FROM a1" {} + 3c "SELECT count(*) FROM a1" {4} + + 4a "SELECT count(*) FROM (SELECT b, a FROM a1)" {4} + 4b "INSERT INTO a1 SELECT b, a FROM a1" {} + 4c "SELECT count(*) FROM a1" {8} + + 4a "SELECT count(*) FROM (SELECT min(b), min(a) FROM a1)" {1} + 4b "INSERT INTO a1 SELECT min(b), min(a) FROM a1" {} + 4c "SELECT count(*) FROM a1" {9} +} + + +# EVIDENCE-OF: R-63614-47421 If a column-list is specified, the number +# of columns in the result of the SELECT must be the same as the number +# of items in the column-list. +# +do_insert_tests e_insert-2.2 -error { + %d values for %d columns +} { + 1 "INSERT INTO a3(x, y) SELECT a, b, c FROM a2" {3 2} + 2 "INSERT INTO a3(x, y) SELECT * FROM a2" {3 2} + 3 "INSERT INTO a3(x, y) SELECT * FROM a2 CROSS JOIN a1" {5 2} + 4 "INSERT INTO a3(x, y) SELECT * FROM a2 NATURAL JOIN a1" {3 2} + 5 "INSERT INTO a3(x, y) SELECT a2.a FROM a2,a1" {1 2} + + 6 "INSERT INTO a3(z) SELECT a, b, c FROM a2" {3 1} + 7 "INSERT INTO a3(z) SELECT * FROM a2" {3 1} + 8 "INSERT INTO a3(z) SELECT * FROM a2 CROSS JOIN a1" {5 1} + 9 "INSERT INTO a3(z) SELECT * FROM a2 NATURAL JOIN a1" {3 1} + 10 "INSERT INTO a3(z) SELECT a1.* FROM a2,a1" {2 1} +} + +# EVIDENCE-OF: R-58951-07798 Otherwise, if no column-list is specified, +# the number of columns in the result of the SELECT must be the same as +# the number of columns in the table. +# +do_insert_tests e_insert-2.3 -error { + table %s has %d columns but %d values were supplied +} { + 1 "INSERT INTO a1 SELECT a, b, c FROM a2" {a1 2 3} + 2 "INSERT INTO a1 SELECT * FROM a2" {a1 2 3} + 3 "INSERT INTO a1 SELECT * FROM a2 CROSS JOIN a1" {a1 2 5} + 4 "INSERT INTO a1 SELECT * FROM a2 NATURAL JOIN a1" {a1 2 3} + 5 "INSERT INTO a1 SELECT a2.a FROM a2,a1" {a1 2 1} +} + +# EVIDENCE-OF: R-31074-37730 Any SELECT statement, including compound +# SELECTs and SELECT statements with ORDER BY and/or LIMIT clauses, may +# be used in an INSERT statement of this form. +# +delete_all_data +do_execsql_test e_insert-2.3.0 { + INSERT INTO a1 VALUES('x', 'y'); +} {} +do_insert_tests e_insert-2.3 { + 1 "INSERT INTO a1 SELECT a,b FROM a1 UNION SELECT b,a FROM a1 ORDER BY 1" {} + 2 "INSERT INTO a1(b, a) SELECT * FROM a1 LIMIT 1" {} + 3 "INSERT INTO a1 SELECT 'a'||a, 'b'||b FROM a1 LIMIT 2 OFFSET 1" {} + 4 "INSERT INTO a1 SELECT * FROM a1 ORDER BY b, a" {} + S "SELECT * FROM a1" { + x y + x y y x + y x + ax by ay bx + ay bx ax by y x y x x y x y + } +} + +# EVIDENCE-OF: R-25149-22012 The INSERT ... DEFAULT VALUES statement +# inserts a single new row into the named table. +# +delete_all_data +do_insert_tests e_insert-3.1 { + 1 "SELECT count(*) FROM a3" {0} + 2a "INSERT INTO a3 DEFAULT VALUES" {} + 2b "SELECT count(*) FROM a3" {1} +} + +# EVIDENCE-OF: R-18927-01951 Each column of the new row is populated +# with its default value, or with a NULL if no default value is +# specified as part of the column definition in the CREATE TABLE +# statement. +# +delete_all_data +do_insert_tests e_insert-3.2 { + 1.1 "INSERT INTO a3 DEFAULT VALUES" {} + 1.2 "SELECT * FROM a3" {1.0 string {}} + + 2.1 "INSERT INTO a3 DEFAULT VALUES" {} + 2.2 "SELECT * FROM a3" {1.0 string {} 1.0 string {}} + + 3.1 "INSERT INTO a2 DEFAULT VALUES" {} + 3.2 "SELECT * FROM a2" {{} {} xyz} + + 4.1 "INSERT INTO a2 DEFAULT VALUES" {} + 4.2 "SELECT * FROM a2" {{} {} xyz {} {} xyz} + + 5.1 "INSERT INTO a1 DEFAULT VALUES" {} + 5.2 "SELECT * FROM a1" {{} {}} + + 6.1 "INSERT INTO a1 DEFAULT VALUES" {} + 6.2 "SELECT * FROM a1" {{} {} {} {}} +} + +# EVIDENCE-OF: R-00267-47727 The initial "INSERT" keyword can be +# replaced by "REPLACE" or "INSERT OR action" to specify an alternative +# constraint conflict resolution algorithm to use during that one INSERT +# command. +# +# EVIDENCE-OF: R-23110-47146 the parser allows the use of the single +# keyword REPLACE as an alias for "INSERT OR REPLACE". +# +# The two requirements above are tested by e_select-4.1.* and +# e_select-4.2.*, respectively. +# +# EVIDENCE-OF: R-03421-22330 The REPLACE command is an alias for the +# "INSERT OR REPLACE" variant of the INSERT command. +# +# This is a dup of R-23110-47146. Therefore it is also verified +# by e_select-4.2.*. This requirement is the only one from +# lang_replace.html. +# +do_execsql_test e_insert-4.1.0 { + INSERT INTO a4 VALUES(1, 'a'); + INSERT INTO a4 VALUES(2, 'a'); + INSERT INTO a4 VALUES(3, 'a'); +} {} +foreach {tn sql error ac data } { + 1.1 "INSERT INTO a4 VALUES(2,'b')" {UNIQUE constraint failed: a4.c} 1 {1 a 2 a 3 a} + 1.2 "INSERT OR REPLACE INTO a4 VALUES(2, 'b')" {} 1 {1 a 3 a 2 b} + 1.3 "INSERT OR IGNORE INTO a4 VALUES(3, 'c')" {} 1 {1 a 3 a 2 b} + 1.4 "BEGIN" {} 0 {1 a 3 a 2 b} + 1.5 "INSERT INTO a4 VALUES(1, 'd')" {UNIQUE constraint failed: a4.c} 0 {1 a 3 a 2 b} + 1.6 "INSERT OR ABORT INTO a4 VALUES(1, 'd')" + {UNIQUE constraint failed: a4.c} 0 {1 a 3 a 2 b} + 1.7 "INSERT OR ROLLBACK INTO a4 VALUES(1, 'd')" + {UNIQUE constraint failed: a4.c} 1 {1 a 3 a 2 b} + 1.8 "INSERT INTO a4 SELECT 4, 'e' UNION ALL SELECT 3, 'e'" + {UNIQUE constraint failed: a4.c} 1 {1 a 3 a 2 b} + 1.9 "INSERT OR FAIL INTO a4 SELECT 4, 'e' UNION ALL SELECT 3, 'e'" + {UNIQUE constraint failed: a4.c} 1 {1 a 3 a 2 b 4 e} + + 2.1 "INSERT INTO a4 VALUES(2,'f')" + {UNIQUE constraint failed: a4.c} 1 {1 a 3 a 2 b 4 e} + 2.2 "REPLACE INTO a4 VALUES(2, 'f')" {} 1 {1 a 3 a 4 e 2 f} +} { + do_catchsql_test e_insert-4.1.$tn.1 $sql [list [expr {$error!=""}] $error] + do_execsql_test e_insert-4.1.$tn.2 {SELECT * FROM a4} [list {*}$data] + do_test e_insert-4.1.$tn.3 {sqlite3_get_autocommit db} $ac +} + +# EVIDENCE-OF: R-59829-49719 The optional "schema-name." prefix on the +# table-name is supported for top-level INSERT statements only. +# +# EVIDENCE-OF: R-05731-00924 The table name must be unqualified for +# INSERT statements that occur within CREATE TRIGGER statements. +# +set err {1 {qualified table names are not allowed on INSERT, UPDATE, and DELETE statements within triggers}} + +do_catchsql_test e_insert-5.1.1 { + CREATE TRIGGER AFTER UPDATE ON a1 BEGIN + INSERT INTO main.a4 VALUES(new.a, new.b); + END; +} $err +do_catchsql_test e_insert-5.1.2 { + CREATE TEMP TABLE IF NOT EXISTS tmptable(a, b); + CREATE TRIGGER AFTER DELETE ON a3 BEGIN + INSERT INTO temp.tmptable VALUES(1, 2); + END; +} $err + +# EVIDENCE-OF: R-15888-36326 Similarly, the "DEFAULT VALUES" form of the +# INSERT statement is supported for top-level INSERT statements only and +# not for INSERT statements within triggers. +# +do_catchsql_test e_insert-5.2.1 { + CREATE TRIGGER AFTER UPDATE ON a1 BEGIN + INSERT INTO a4 DEFAULT VALUES; + END; +} {1 {near "DEFAULT": syntax error}} + + +delete_all_data + +finish_test diff --git a/test/e_reindex.test b/test/e_reindex.test new file mode 100644 index 0000000..00291b7 --- /dev/null +++ b/test/e_reindex.test @@ -0,0 +1,299 @@ +# 2010 September 24 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file implements tests to verify that the "testable statements" in +# the lang_reindex.html document are correct. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +proc do_reindex_tests {args} { + uplevel do_select_tests $args +} + +do_execsql_test e_reindex-0.0 { + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a, b); + CREATE INDEX i2 ON t1(b, a); +} {} + +# -- syntax diagram reindex-stmt +# +do_reindex_tests e_reindex-0.1 { + 1 "REINDEX" {} + 2 "REINDEX nocase" {} + 3 "REINDEX binary" {} + 4 "REINDEX t1" {} + 5 "REINDEX main.t1" {} + 6 "REINDEX i1" {} + 7 "REINDEX main.i1" {} +} + +# EVIDENCE-OF: R-52173-44778 The REINDEX command is used to delete and +# recreate indices from scratch. +# +# Test this by corrupting some database indexes, running REINDEX, and +# observing that the corruption is gone. +# +sqlite3_db_config db DEFENSIVE 0 +do_execsql_test e_reindex-1.1 { + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t1 VALUES(3, 4); + INSERT INTO t1 VALUES(5, 6); + + CREATE TABLE saved(a,b,c,d,e); + INSERT INTO saved SELECT * FROM sqlite_master WHERE type = 'index'; + PRAGMA writable_schema = 1; + DELETE FROM sqlite_master WHERE type = 'index'; +} {} + +db close +sqlite3 db test.db +sqlite3_db_config db DEFENSIVE 0 +do_execsql_test e_reindex-1.2 { + DELETE FROM t1 WHERE a = 3; + INSERT INTO t1 VALUES(7, 8); + INSERT INTO t1 VALUES(9, 10); + PRAGMA writable_schema = 1; + INSERT INTO sqlite_master SELECT * FROM saved; + DROP TABLE saved; +} {} + +db close +sqlite3 db test.db +do_execsql_test e_reindex-1.3 { + PRAGMA integrity_check; +} [list \ + {row 3 missing from index i2} \ + {row 3 missing from index i1} \ + {row 4 missing from index i2} \ + {row 4 missing from index i1} \ + {wrong # of entries in index i2} \ + {wrong # of entries in index i1} +] + +do_execsql_test e_reindex-1.4 { + REINDEX; + PRAGMA integrity_check; +} {ok} + +#------------------------------------------------------------------------- +# The remaining tests in this file focus on testing that the REINDEX +# command reindexes the correct subset of the indexes in the database. +# They all use the following dataset. +# +db close +forcedelete test.db2 +forcedelete test.db +sqlite3 db test.db + +proc sort_by_length {lhs rhs} { + set res [expr {[string length $lhs] - [string length $rhs]}] + if {$res!=0} {return $res} + return [string compare $lhs $rhs] +} +array set V {one 1 two 2 three 3 four 4 five 5 six 6 seven 7 eight 8} +proc sort_by_value {lhs rhs} { + global V + set res [expr {$V($lhs) - $V($rhs)}] + if {$res!=0} {return $res} + return [string compare $lhs $rhs] +} + +db collate collA sort_by_length +db collate collB sort_by_value + +set BY(length) {one six two five four eight seven three} +set BY(value) {one two three four five six seven eight} + +do_execsql_test e_reindex-2.0 { + ATTACH 'test.db2' AS aux; + + CREATE TABLE t1(x); + CREATE INDEX i1_a ON t1(x COLLATE collA); + CREATE INDEX i1_b ON t1(x COLLATE collB); + INSERT INTO t1 VALUES('one'); + INSERT INTO t1 VALUES('two'); + INSERT INTO t1 VALUES('three'); + INSERT INTO t1 VALUES('four'); + INSERT INTO t1 VALUES('five'); + INSERT INTO t1 VALUES('six'); + INSERT INTO t1 VALUES('seven'); + INSERT INTO t1 VALUES('eight'); + + CREATE TABLE t2(x); + CREATE INDEX i2_a ON t2(x COLLATE collA); + CREATE INDEX i2_b ON t2(x COLLATE collB); + INSERT INTO t2 SELECT x FROM t1; + + CREATE TABLE aux.t1(x); + CREATE INDEX aux.i1_a ON t1(x COLLATE collA); + CREATE INDEX aux.i1_b ON t1(x COLLATE collB); + INSERT INTO aux.t1 SELECT x FROM main.t1; + +} {} + +proc test_index {tn tbl collation expected} { + set sql "SELECT x FROM $tbl ORDER BY x COLLATE $collation" + uplevel do_execsql_test e_reindex-2.$tn [list $sql] [list $::BY($expected)] +} + +proc set_collations {a b} { + db collate collA "sort_by_$a" + db collate collB "sort_by_$b" +} + +test_index 1.1 t1 collA length +test_index 1.2 t1 collB value +test_index 1.3 t2 collA length +test_index 1.4 t2 collB value +test_index 1.5 aux.t1 collA length +test_index 1.6 aux.t1 collB value + + +# EVIDENCE-OF: R-47362-07898 If the REINDEX keyword is not followed by a +# collation-sequence or database object identifier, then all indices in +# all attached databases are rebuilt. +# +set_collations value length +do_execsql_test e_reindex-2.2.1 "REINDEX" {} +test_index 2.2 t1 collA value +test_index 2.3 t1 collB length +test_index 2.4 t2 collA value +test_index 2.5 t2 collB length +test_index 2.6 aux.t1 collA value +test_index 2.7 aux.t1 collB length + +# EVIDENCE-OF: R-45878-07697 If the REINDEX keyword is followed by a +# collation-sequence name, then all indices in all attached databases +# that use the named collation sequences are recreated. +# +set_collations length value +do_execsql_test e_reindex-2.3.1 "REINDEX collA" {} +test_index 3.2 t1 collA length +test_index 3.3 t1 collB length +test_index 3.4 t2 collA length +test_index 3.5 t2 collB length +test_index 3.6 aux.t1 collA length +test_index 3.7 aux.t1 collB length +do_execsql_test e_reindex-2.3.8 "REINDEX collB" {} +test_index 3.9 t1 collA length +test_index 3.10 t1 collB value +test_index 3.11 t2 collA length +test_index 3.12 t2 collB value +test_index 3.13 aux.t1 collA length +test_index 3.14 aux.t1 collB value + +# EVIDENCE-OF: R-49616-30196 Or, if the argument attached to the REINDEX +# identifies a specific database table, then all indices attached to the +# database table are rebuilt. +# +set_collations value length +do_execsql_test e_reindex-2.4.1 "REINDEX t1" {} +test_index 4.2 t1 collA value +test_index 4.3 t1 collB length +test_index 4.4 t2 collA length +test_index 4.5 t2 collB value +test_index 4.6 aux.t1 collA length +test_index 4.7 aux.t1 collB value +do_execsql_test e_reindex-2.4.8 "REINDEX aux.t1" {} +test_index 4.9 t1 collA value +test_index 4.10 t1 collB length +test_index 4.11 t2 collA length +test_index 4.12 t2 collB value +test_index 4.13 aux.t1 collA value +test_index 4.14 aux.t1 collB length +do_execsql_test e_reindex-2.4.15 "REINDEX t2" {} +test_index 4.16 t1 collA value +test_index 4.17 t1 collB length +test_index 4.18 t2 collA value +test_index 4.19 t2 collB length +test_index 4.20 aux.t1 collA value +test_index 4.21 aux.t1 collB length + +# EVIDENCE-OF: R-58823-28748 If it identifies a specific database index, +# then just that index is recreated. +# +set_collations length value +do_execsql_test e_reindex-2.5.1 "REINDEX i1_a" {} +test_index 5.2 t1 collA length +test_index 5.3 t1 collB length +test_index 5.4 t2 collA value +test_index 5.5 t2 collB length +test_index 5.6 aux.t1 collA value +test_index 5.7 aux.t1 collB length +do_execsql_test e_reindex-2.5.8 "REINDEX i2_b" {} +test_index 5.9 t1 collA length +test_index 5.10 t1 collB length +test_index 5.11 t2 collA value +test_index 5.12 t2 collB value +test_index 5.13 aux.t1 collA value +test_index 5.14 aux.t1 collB length +do_execsql_test e_reindex-2.5.15 "REINDEX aux.i1_b" {} +test_index 5.16 t1 collA length +test_index 5.17 t1 collB length +test_index 5.18 t2 collA value +test_index 5.19 t2 collB value +test_index 5.20 aux.t1 collA value +test_index 5.21 aux.t1 collB value +do_execsql_test e_reindex-2.5.22 "REINDEX i1_b" {} +test_index 5.23 t1 collA length +test_index 5.24 t1 collB value +test_index 5.25 t2 collA value +test_index 5.26 t2 collB value +test_index 5.27 aux.t1 collA value +test_index 5.28 aux.t1 collB value +do_execsql_test e_reindex-2.5.29 "REINDEX i2_a" {} +test_index 5.30 t1 collA length +test_index 5.31 t1 collB value +test_index 5.32 t2 collA length +test_index 5.33 t2 collB value +test_index 5.34 aux.t1 collA value +test_index 5.35 aux.t1 collB value +do_execsql_test e_reindex-2.5.36 "REINDEX aux.i1_a" {} +test_index 5.37 t1 collA length +test_index 5.38 t1 collB value +test_index 5.39 t2 collA length +test_index 5.40 t2 collB value +test_index 5.41 aux.t1 collA length +test_index 5.42 aux.t1 collB value + +# EVIDENCE-OF: R-35892-30289 For a command of the form "REINDEX name", a +# match against collation-name takes precedence over a match against +# index-name or table-name. +# +set_collations value length +do_execsql_test e_reindex-2.6.0 { + CREATE TABLE collA(x); + CREATE INDEX icolla_a ON collA(x COLLATE collA); + CREATE INDEX icolla_b ON collA(x COLLATE collB); + + INSERT INTO collA SELECT x FROM t1; +} {} + +test_index 6.1 collA collA value +test_index 6.2 collA collB length + +set_collations length value +do_execsql_test e_reindex-2.6.3 "REINDEX collA" {} +test_index 6.4 collA collA length +test_index 6.5 collA collB length +do_execsql_test e_reindex-2.6.3 "REINDEX main.collA" {} +test_index 6.4 collA collA length +test_index 6.5 collA collB value + +set_collations value length +do_execsql_test e_reindex-2.6.6 "REINDEX main.collA" {} +test_index 6.7 collA collA value +test_index 6.8 collA collB length + +finish_test diff --git a/test/e_resolve.test b/test/e_resolve.test new file mode 100644 index 0000000..f4bb1a4 --- /dev/null +++ b/test/e_resolve.test @@ -0,0 +1,135 @@ +# 2010 November 30 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file implements tests to verify that the "testable statements" in +# the lang_naming.html document are correct. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix e_resolve + +# An example database schema for testing name resolution: +# +set schema { + ATTACH 'test.db2' AS at1; + ATTACH 'test.db3' AS at2; + + CREATE TABLE temp.n1(x, y); INSERT INTO temp.n1 VALUES('temp', 'n1'); + CREATE TRIGGER temp.n3 AFTER INSERT ON n1 BEGIN SELECT 1; END; + CREATE INDEX temp.n4 ON n1(x, y); + + CREATE TABLE main.n1(x, y); INSERT INTO main.n1 VALUES('main', 'n1'); + CREATE TABLE main.n2(x, y); INSERT INTO main.n2 VALUES('main', 'n2'); + CREATE INDEX main.n3 ON n2(y, x); + CREATE TRIGGER main.n4 BEFORE INSERT ON n2 BEGIN SELECT 1; END; + + CREATE TABLE at1.n1(x, y); INSERT INTO at1.n1 VALUES('at1', 'n1'); + CREATE TABLE at1.n2(x, y); INSERT INTO at1.n2 VALUES('at1', 'n2'); + CREATE TABLE at1.n3(x, y); INSERT INTO at1.n3 VALUES('at1', 'n3'); + + CREATE TABLE at2.n1(x, y); INSERT INTO at2.n1 VALUES('at2', 'n1'); + CREATE TABLE at2.n2(x, y); INSERT INTO at2.n2 VALUES('at2', 'n2'); + CREATE TABLE at2.n3(x, y); INSERT INTO at2.n3 VALUES('at2', 'n3'); + CREATE TABLE at2.n4(x, y); INSERT INTO at2.n4 VALUES('at2', 'n4'); + CREATE TRIGGER at2.n4 BEFORE INSERT ON n4 BEGIN SELECT 1; END; +} + +proc resolve_reopen_db {} { + db close + forcedelete test.db test.db2 test.db3 + sqlite3 db test.db + db eval $::schema +} + + + +# EVIDENCE-OF: R-33528-20612 If no database is specified as part of the +# object reference, then SQLite searches the main, temp and all attached +# databases for an object with a matching name. The temp database is +# searched first, followed by the main database, followed all attached +# databases in the order that they were attached. The reference resolves +# to the first match found. +# +resolve_reopen_db +do_execsql_test 1.1 { SELECT * FROM n1 } {temp n1} +do_execsql_test 1.2 { SELECT * FROM n2 } {main n2} +do_execsql_test 1.3 { SELECT * FROM n3 } {at1 n3} +do_execsql_test 1.4 { SELECT * FROM n4 } {at2 n4} + +# EVIDENCE-OF: R-00634-08585 If a schema name is specified as part of an +# object reference, it must be either "main", or "temp" or the +# schema-name of an attached database. +# +# Or else it is a "no such table: xxx" error. +# +resolve_reopen_db +do_execsql_test 2.1.1 { SELECT * FROM main.n1 } {main n1} +do_execsql_test 2.1.2 { SELECT * FROM temp.n1 } {temp n1} +do_execsql_test 2.1.3 { SELECT * FROM at1.n1 } {at1 n1} +do_execsql_test 2.1.4 { SELECT * FROM at2.n1 } {at2 n1} + +do_catchsql_test 2.2 { SELECT * FROM xxx.n1 } {1 {no such table: xxx.n1}} + +# EVIDENCE-OF: R-17446-42210 Like other SQL identifiers, schema names +# are case-insensitive. +# +resolve_reopen_db +do_execsql_test 3.1 { SELECT * FROM MAIN.n1 } {main n1} +do_execsql_test 3.2 { SELECT * FROM tEmP.n1 } {temp n1} +do_execsql_test 3.3 { SELECT * FROM aT1.n1 } {at1 n1} +do_execsql_test 3.4 { SELECT * FROM At2.n1 } {at2 n1} + +# EVIDENCE-OF: R-14755-58619 If a schema name is specified, then only +# that one schema is searched for the named object. +# +do_catchsql_test 4.1 { SELECT * FROM temp.n2 } {1 {no such table: temp.n2}} +do_catchsql_test 4.2 { SELECT * FROM main.n2 } {0 {main n2}} +do_catchsql_test 4.3 { SELECT * FROM at1.n2 } {0 {at1 n2}} +do_catchsql_test 4.4 { SELECT * FROM at2.n2 } {0 {at2 n2}} + +# EVIDENCE-OF: R-08951-19801 When searching database schemas for a named +# object, objects of types that cannot be used in the context of the +# reference are always ignored. +# +# In this case, "types that cannot be used" are triggers and indexes. +# The temp and main databases both contain triggers and indexes named +# "n3" and "n4". Database "at2" contains a trigger called "n4". And yet: +# +do_execsql_test 5.1 { SELECT * FROM n3 } {at1 n3} +do_execsql_test 5.2 { SELECT * FROM n4 } {at2 n4} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-37286-42536 +# +db close +forcedelete test.db file.db +sqlite3 db test.db +do_execsql_test 6.1 { + ATTACH 'file.db' AS aux; + CREATE TABLE t1(x, y); + CREATE TEMP TABLE t1(x, y); + CREATE TABLE aux.t1(x, y); +} + +do_execsql_test 6.2.0 { DROP TABLE t1 } +do_catchsql_test 6.2.1 { SELECT * FROM temp.t1 } {1 {no such table: temp.t1}} +do_catchsql_test 6.2.2 { SELECT * FROM main.t1 } {0 {}} +do_catchsql_test 6.2.3 { SELECT * FROM aux.t1 } {0 {}} + +do_execsql_test 6.3.0 { DROP TABLE t1 } +do_catchsql_test 6.3.1 { SELECT * FROM main.t1 } {1 {no such table: main.t1}} +do_catchsql_test 6.3.3 { SELECT * FROM aux.t1 } {0 {}} + +do_execsql_test 6.4.0 { DROP TABLE t1 } +do_catchsql_test 6.4.1 { SELECT * FROM aux.t1 } {1 {no such table: aux.t1}} + +finish_test diff --git a/test/e_select.test b/test/e_select.test new file mode 100644 index 0000000..e2e969d --- /dev/null +++ b/test/e_select.test @@ -0,0 +1,2174 @@ +# 2010 July 16 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file implements tests to verify that the "testable statements" in +# the lang_select.html document are correct. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !compound { + finish_test + return +} + +do_execsql_test e_select-1.0 { + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES('a', 'one'); + INSERT INTO t1 VALUES('b', 'two'); + INSERT INTO t1 VALUES('c', 'three'); + + CREATE TABLE t2(a, b); + INSERT INTO t2 VALUES('a', 'I'); + INSERT INTO t2 VALUES('b', 'II'); + INSERT INTO t2 VALUES('c', 'III'); + + CREATE TABLE t3(a, c); + INSERT INTO t3 VALUES('a', 1); + INSERT INTO t3 VALUES('b', 2); + + CREATE TABLE t4(a, c); + INSERT INTO t4 VALUES('a', NULL); + INSERT INTO t4 VALUES('b', 2); +} {} +set t1_cross_t2 [list \ + a one a I a one b II \ + a one c III b two a I \ + b two b II b two c III \ + c three a I c three b II \ + c three c III \ +] +set t1_cross_t1 [list \ + a one a one a one b two \ + a one c three b two a one \ + b two b two b two c three \ + c three a one c three b two \ + c three c three \ +] + + +# This proc is a specialized version of [do_execsql_test]. +# +# The second argument to this proc must be a SELECT statement that +# features a cross join of some time. Instead of the usual ",", +# "CROSS JOIN" or "INNER JOIN" join-op, the string %JOIN% must be +# substituted. +# +# This test runs the SELECT three times - once with: +# +# * s/%JOIN%/,/ +# * s/%JOIN%/JOIN/ +# * s/%JOIN%/INNER JOIN/ +# * s/%JOIN%/CROSS JOIN/ +# +# and checks that each time the results of the SELECT are $res. +# +proc do_join_test {tn select res} { + foreach {tn2 joinop} [list 1 , 2 "CROSS JOIN" 3 "INNER JOIN"] { + set S [string map [list %JOIN% $joinop] $select] + uplevel do_execsql_test $tn.$tn2 [list $S] [list $res] + } +} + +#------------------------------------------------------------------------- +# The following tests check that all paths on the syntax diagrams on +# the lang_select.html page may be taken. +# +# -- syntax diagram join-constraint +# +do_join_test e_select-0.1.1 { + SELECT count(*) FROM t1 %JOIN% t2 ON (t1.a=t2.a) +} {3} +do_join_test e_select-0.1.2 { + SELECT count(*) FROM t1 %JOIN% t2 USING (a) +} {3} +do_join_test e_select-0.1.3 { + SELECT count(*) FROM t1 %JOIN% t2 +} {9} +do_catchsql_test e_select-0.1.4 { + SELECT count(*) FROM t1, t2 ON (t1.a=t2.a) USING (a) +} {1 {near "USING": syntax error}} +do_catchsql_test e_select-0.1.5 { + SELECT count(*) FROM t1, t2 USING (a) ON (t1.a=t2.a) +} {1 {near "ON": syntax error}} + +# -- syntax diagram select-core +# +# 0: SELECT ... +# 1: SELECT DISTINCT ... +# 2: SELECT ALL ... +# +# 0: No FROM clause +# 1: Has FROM clause +# +# 0: No WHERE clause +# 1: Has WHERE clause +# +# 0: No GROUP BY clause +# 1: Has GROUP BY clause +# 2: Has GROUP BY and HAVING clauses +# +do_select_tests e_select-0.2 { + 0000.1 "SELECT 1, 2, 3 " {1 2 3} + 1000.1 "SELECT DISTINCT 1, 2, 3 " {1 2 3} + 2000.1 "SELECT ALL 1, 2, 3 " {1 2 3} + + 0100.1 "SELECT a, b, a||b FROM t1 " { + a one aone b two btwo c three cthree + } + 1100.1 "SELECT DISTINCT a, b, a||b FROM t1 " { + a one aone b two btwo c three cthree + } + 1200.1 "SELECT ALL a, b, a||b FROM t1 " { + a one aone b two btwo c three cthree + } + + 0010.1 "SELECT 1, 2, 3 WHERE 1 " {1 2 3} + 0010.2 "SELECT 1, 2, 3 WHERE 0 " {} + 0010.3 "SELECT 1, 2, 3 WHERE NULL " {} + + 1010.1 "SELECT DISTINCT 1, 2, 3 WHERE 1 " {1 2 3} + + 2010.1 "SELECT ALL 1, 2, 3 WHERE 1 " {1 2 3} + + 0110.1 "SELECT a, b, a||b FROM t1 WHERE a!='x' " { + a one aone b two btwo c three cthree + } + 0110.2 "SELECT a, b, a||b FROM t1 WHERE a=='x'" {} + + 1110.1 "SELECT DISTINCT a, b, a||b FROM t1 WHERE a!='x' " { + a one aone b two btwo c three cthree + } + + 2110.0 "SELECT ALL a, b, a||b FROM t1 WHERE a=='x'" {} + + 0001.1 "SELECT 1, 2, 3 GROUP BY 2" {1 2 3} + 0002.1 "SELECT 1, 2, 3 GROUP BY 2 HAVING count(*)=1" {1 2 3} + 0002.2 "SELECT 1, 2, 3 GROUP BY 2 HAVING count(*)>1" {} + + 1001.1 "SELECT DISTINCT 1, 2, 3 GROUP BY 2" {1 2 3} + 1002.1 "SELECT DISTINCT 1, 2, 3 GROUP BY 2 HAVING count(*)=1" {1 2 3} + 1002.2 "SELECT DISTINCT 1, 2, 3 GROUP BY 2 HAVING count(*)>1" {} + + 2001.1 "SELECT ALL 1, 2, 3 GROUP BY 2" {1 2 3} + 2002.1 "SELECT ALL 1, 2, 3 GROUP BY 2 HAVING count(*)=1" {1 2 3} + 2002.2 "SELECT ALL 1, 2, 3 GROUP BY 2 HAVING count(*)>1" {} + + 0101.1 "SELECT count(*), max(a) FROM t1 GROUP BY b" {1 a 1 c 1 b} + 0102.1 "SELECT count(*), max(a) FROM t1 GROUP BY b HAVING count(*)=1" { + 1 a 1 c 1 b + } + 0102.2 "SELECT count(*), max(a) FROM t1 GROUP BY b HAVING count(*)=2" {} + + 1101.1 "SELECT DISTINCT count(*), max(a) FROM t1 GROUP BY b" {1 a 1 c 1 b} + 1102.1 "SELECT DISTINCT count(*), max(a) FROM t1 + GROUP BY b HAVING count(*)=1" { + 1 a 1 c 1 b + } + 1102.2 "SELECT DISTINCT count(*), max(a) FROM t1 + GROUP BY b HAVING count(*)=2" {} + + 2101.1 "SELECT ALL count(*), max(a) FROM t1 GROUP BY b" {1 a 1 c 1 b} + 2102.1 "SELECT ALL count(*), max(a) FROM t1 + GROUP BY b HAVING count(*)=1" { + 1 a 1 c 1 b + } + 2102.2 "SELECT ALL count(*), max(a) FROM t1 + GROUP BY b HAVING count(*)=2" {} + + 0011.1 "SELECT 1, 2, 3 WHERE 1 GROUP BY 2" {1 2 3} + 0012.1 "SELECT 1, 2, 3 WHERE 0 GROUP BY 2 HAVING count(*)=1" {} + 0012.2 "SELECT 1, 2, 3 WHERE 0 GROUP BY 2 HAVING count(*)>1" {} + + 1011.1 "SELECT DISTINCT 1, 2, 3 WHERE 0 GROUP BY 2" {} + 1012.1 "SELECT DISTINCT 1, 2, 3 WHERE 1 GROUP BY 2 HAVING count(*)=1" + {1 2 3} + 1012.2 "SELECT DISTINCT 1, 2, 3 WHERE NULL GROUP BY 2 HAVING count(*)>1" {} + + 2011.1 "SELECT ALL 1, 2, 3 WHERE 1 GROUP BY 2" {1 2 3} + 2012.1 "SELECT ALL 1, 2, 3 WHERE 0 GROUP BY 2 HAVING count(*)=1" {} + 2012.2 "SELECT ALL 1, 2, 3 WHERE 'abc' GROUP BY 2 HAVING count(*)>1" {} + + 0111.1 "SELECT count(*), max(a) FROM t1 WHERE a='a' GROUP BY b" {1 a} + 0112.1 "SELECT count(*), max(a) FROM t1 + WHERE a='c' GROUP BY b HAVING count(*)=1" {1 c} + 0112.2 "SELECT count(*), max(a) FROM t1 + WHERE 0 GROUP BY b HAVING count(*)=2" {} + 1111.1 "SELECT DISTINCT count(*), max(a) FROM t1 WHERE a<'c' GROUP BY b" + {1 a 1 b} + 1112.1 "SELECT DISTINCT count(*), max(a) FROM t1 WHERE a>'a' + GROUP BY b HAVING count(*)=1" { + 1 c 1 b + } + 1112.2 "SELECT DISTINCT count(*), max(a) FROM t1 WHERE 0 + GROUP BY b HAVING count(*)=2" {} + + 2111.1 "SELECT ALL count(*), max(a) FROM t1 WHERE b>'one' GROUP BY b" + {1 c 1 b} + 2112.1 "SELECT ALL count(*), max(a) FROM t1 WHERE a!='b' + GROUP BY b HAVING count(*)=1" { + 1 a 1 c + } + 2112.2 "SELECT ALL count(*), max(a) FROM t1 + WHERE 0 GROUP BY b HAVING count(*)=2" {} +} + + +# -- syntax diagram result-column +# +do_select_tests e_select-0.3 { + 1 "SELECT * FROM t1" {a one b two c three} + 2 "SELECT t1.* FROM t1" {a one b two c three} + 3 "SELECT 'x'||a||'x' FROM t1" {xax xbx xcx} + 4 "SELECT 'x'||a||'x' alias FROM t1" {xax xbx xcx} + 5 "SELECT 'x'||a||'x' AS alias FROM t1" {xax xbx xcx} +} + +# -- syntax diagram join-source +# +# -- syntax diagram join-op +# +do_select_tests e_select-0.4 { + 1 "SELECT t1.rowid FROM t1" {1 2 3} + 2 "SELECT t1.rowid FROM t1,t2" {1 1 1 2 2 2 3 3 3} + 3 "SELECT t1.rowid FROM t1,t2,t3" {1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3} + + 4 "SELECT t1.rowid FROM t1" {1 2 3} + 5 "SELECT t1.rowid FROM t1 JOIN t2" {1 1 1 2 2 2 3 3 3} + 6 "SELECT t1.rowid FROM t1 JOIN t2 JOIN t3" + {1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3} + + 7 "SELECT t1.rowid FROM t1 NATURAL JOIN t3" {1 2} + 8 "SELECT t1.rowid FROM t1 NATURAL LEFT OUTER JOIN t3" {1 2 3} + 9 "SELECT t1.rowid FROM t1 NATURAL LEFT JOIN t3" {1 2 3} + 10 "SELECT t1.rowid FROM t1 NATURAL INNER JOIN t3" {1 2} + 11 "SELECT t1.rowid FROM t1 NATURAL CROSS JOIN t3" {1 2} + + 12 "SELECT t1.rowid FROM t1 JOIN t3" {1 1 2 2 3 3} + 13 "SELECT t1.rowid FROM t1 LEFT OUTER JOIN t3" {1 1 2 2 3 3} + 14 "SELECT t1.rowid FROM t1 LEFT JOIN t3" {1 1 2 2 3 3} + 15 "SELECT t1.rowid FROM t1 INNER JOIN t3" {1 1 2 2 3 3} + 16 "SELECT t1.rowid FROM t1 CROSS JOIN t3" {1 1 2 2 3 3} +} + +# -- syntax diagram compound-operator +# +do_select_tests e_select-0.5 { + 1 "SELECT rowid FROM t1 UNION ALL SELECT rowid+2 FROM t4" {1 2 3 3 4} + 2 "SELECT rowid FROM t1 UNION SELECT rowid+2 FROM t4" {1 2 3 4} + 3 "SELECT rowid FROM t1 INTERSECT SELECT rowid+2 FROM t4" {3} + 4 "SELECT rowid FROM t1 EXCEPT SELECT rowid+2 FROM t4" {1 2} +} + +# -- syntax diagram ordering-term +# +do_select_tests e_select-0.6 { + 1 "SELECT b||a FROM t1 ORDER BY b||a" {onea threec twob} + 2 "SELECT b||a FROM t1 ORDER BY (b||a) COLLATE nocase" {onea threec twob} + 3 "SELECT b||a FROM t1 ORDER BY (b||a) ASC" {onea threec twob} + 4 "SELECT b||a FROM t1 ORDER BY (b||a) DESC" {twob threec onea} +} + +# -- syntax diagram select-stmt +# +do_select_tests e_select-0.7 { + 1 "SELECT * FROM t1" {a one b two c three} + 2 "SELECT * FROM t1 ORDER BY b" {a one c three b two} + 3 "SELECT * FROM t1 ORDER BY b, a" {a one c three b two} + + 4 "SELECT * FROM t1 LIMIT 10" {a one b two c three} + 5 "SELECT * FROM t1 LIMIT 10 OFFSET 5" {} + 6 "SELECT * FROM t1 LIMIT 10, 5" {} + + 7 "SELECT * FROM t1 ORDER BY a LIMIT 10" {a one b two c three} + 8 "SELECT * FROM t1 ORDER BY b LIMIT 10 OFFSET 5" {} + 9 "SELECT * FROM t1 ORDER BY a,b LIMIT 10, 5" {} + + 10 "SELECT * FROM t1 UNION SELECT b, a FROM t1" + {a one b two c three one a three c two b} + 11 "SELECT * FROM t1 UNION SELECT b, a FROM t1 ORDER BY b" + {one a two b three c a one c three b two} + 12 "SELECT * FROM t1 UNION SELECT b, a FROM t1 ORDER BY b, a" + {one a two b three c a one c three b two} + 13 "SELECT * FROM t1 UNION SELECT b, a FROM t1 LIMIT 10" + {a one b two c three one a three c two b} + 14 "SELECT * FROM t1 UNION SELECT b, a FROM t1 LIMIT 10 OFFSET 5" + {two b} + 15 "SELECT * FROM t1 UNION SELECT b, a FROM t1 LIMIT 10, 5" + {} + 16 "SELECT * FROM t1 UNION SELECT b, a FROM t1 ORDER BY a LIMIT 10" + {a one b two c three one a three c two b} + 17 "SELECT * FROM t1 UNION SELECT b, a FROM t1 ORDER BY b LIMIT 10 OFFSET 5" + {b two} + 18 "SELECT * FROM t1 UNION SELECT b, a FROM t1 ORDER BY a,b LIMIT 10, 5" + {} +} + +#------------------------------------------------------------------------- +# The following tests focus on FROM clause (join) processing. +# + +# EVIDENCE-OF: R-16074-54196 If the FROM clause is omitted from a simple +# SELECT statement, then the input data is implicitly a single row zero +# columns wide +# +do_select_tests e_select-1.1 { + 1 "SELECT 'abc'" {abc} + 2 "SELECT 'abc' WHERE NULL" {} + 3 "SELECT NULL" {{}} + 4 "SELECT count(*)" {1} + 5 "SELECT count(*) WHERE 0" {0} + 6 "SELECT count(*) WHERE 1" {1} +} + +# EVIDENCE-OF: R-45424-07352 If there is only a single table or subquery +# in the FROM clause, then the input data used by the SELECT statement +# is the contents of the named table. +# +# The results of the SELECT queries suggest that they are operating on the +# contents of the table 'xx'. +# +do_execsql_test e_select-1.2.0 { + CREATE TABLE xx(x, y); + INSERT INTO xx VALUES('IiJlsIPepMuAhU', X'10B00B897A15BAA02E3F98DCE8F2'); + INSERT INTO xx VALUES(NULL, -16.87); + INSERT INTO xx VALUES(-17.89, 'linguistically'); +} {} +do_select_tests e_select-1.2 { + 1 "SELECT quote(x), quote(y) FROM xx" { + 'IiJlsIPepMuAhU' X'10B00B897A15BAA02E3F98DCE8F2' + NULL -16.87 + -17.89 'linguistically' + } + + 2 "SELECT count(*), count(x), count(y) FROM xx" {3 2 3} + 3 "SELECT sum(x), sum(y) FROM xx" {-17.89 -16.87} +} + +# EVIDENCE-OF: R-28355-09804 If there is more than one table or subquery +# in FROM clause then the contents of all tables and/or subqueries are +# joined into a single dataset for the simple SELECT statement to +# operate on. +# +# There are more detailed tests for subsequent requirements that add +# more detail to this idea. We just add a single test that shows that +# data is coming from each of the three tables following the FROM clause +# here to show that the statement, vague as it is, is not incorrect. +# +do_select_tests e_select-1.3 { + 1 "SELECT * FROM t1, t2, t3" { + a one a I a 1 a one a I b 2 a one b II a 1 + a one b II b 2 a one c III a 1 a one c III b 2 + b two a I a 1 b two a I b 2 b two b II a 1 + b two b II b 2 b two c III a 1 b two c III b 2 + c three a I a 1 c three a I b 2 c three b II a 1 + c three b II b 2 c three c III a 1 c three c III b 2 + } +} + +# +# The following block of tests - e_select-1.4.* - test that the description +# of cartesian joins in the SELECT documentation is consistent with SQLite. +# In doing so, we test the following three requirements as a side-effect: +# +# EVIDENCE-OF: R-49872-03192 If the join-operator is "CROSS JOIN", +# "INNER JOIN", "JOIN" or a comma (",") and there is no ON or USING +# clause, then the result of the join is simply the cartesian product of +# the left and right-hand datasets. +# +# The tests are built on this assertion. Really, they test that the output +# of a CROSS JOIN, JOIN, INNER JOIN or "," join matches the expected result +# of calculating the cartesian product of the left and right-hand datasets. +# +# EVIDENCE-OF: R-46256-57243 There is no difference between the "INNER +# JOIN", "JOIN" and "," join operators. +# +# EVIDENCE-OF: R-25071-21202 The "CROSS JOIN" join operator produces the +# same result as the "INNER JOIN", "JOIN" and "," operators +# +# All tests are run 4 times, with the only difference in each run being +# which of the 4 equivalent cartesian product join operators are used. +# Since the output data is the same in all cases, we consider that this +# qualifies as testing the two statements above. +# +do_execsql_test e_select-1.4.0 { + CREATE TABLE x1(a, b); + CREATE TABLE x2(c, d, e); + CREATE TABLE x3(f, g, h, i); + + -- x1: 3 rows, 2 columns + INSERT INTO x1 VALUES(24, 'converging'); + INSERT INTO x1 VALUES(NULL, X'CB71'); + INSERT INTO x1 VALUES('blonds', 'proprietary'); + + -- x2: 2 rows, 3 columns + INSERT INTO x2 VALUES(-60.06, NULL, NULL); + INSERT INTO x2 VALUES(-58, NULL, 1.21); + + -- x3: 5 rows, 4 columns + INSERT INTO x3 VALUES(-39.24, NULL, 'encompass', -1); + INSERT INTO x3 VALUES('presenting', 51, 'reformation', 'dignified'); + INSERT INTO x3 VALUES('conducting', -87.24, 37.56, NULL); + INSERT INTO x3 VALUES('coldest', -96, 'dramatists', 82.3); + INSERT INTO x3 VALUES('alerting', NULL, -93.79, NULL); +} {} + +# EVIDENCE-OF: R-59089-25828 The columns of the cartesian product +# dataset are, in order, all the columns of the left-hand dataset +# followed by all the columns of the right-hand dataset. +# +do_join_test e_select-1.4.1.1 { + SELECT * FROM x1 %JOIN% x2 LIMIT 1 +} [concat {24 converging} {-60.06 {} {}}] + +do_join_test e_select-1.4.1.2 { + SELECT * FROM x2 %JOIN% x1 LIMIT 1 +} [concat {-60.06 {} {}} {24 converging}] + +do_join_test e_select-1.4.1.3 { + SELECT * FROM x3 %JOIN% x2 LIMIT 1 +} [concat {-39.24 {} encompass -1} {-60.06 {} {}}] + +do_join_test e_select-1.4.1.4 { + SELECT * FROM x2 %JOIN% x3 LIMIT 1 +} [concat {-60.06 {} {}} {-39.24 {} encompass -1}] + +# EVIDENCE-OF: R-44414-54710 There is a row in the cartesian product +# dataset formed by combining each unique combination of a row from the +# left-hand and right-hand datasets. +# +do_join_test e_select-1.4.2.1 { + SELECT * FROM x2 %JOIN% x3 ORDER BY +c, +f +} [list -60.06 {} {} -39.24 {} encompass -1 \ + -60.06 {} {} alerting {} -93.79 {} \ + -60.06 {} {} coldest -96 dramatists 82.3 \ + -60.06 {} {} conducting -87.24 37.56 {} \ + -60.06 {} {} presenting 51 reformation dignified \ + -58 {} 1.21 -39.24 {} encompass -1 \ + -58 {} 1.21 alerting {} -93.79 {} \ + -58 {} 1.21 coldest -96 dramatists 82.3 \ + -58 {} 1.21 conducting -87.24 37.56 {} \ + -58 {} 1.21 presenting 51 reformation dignified \ +] +# TODO: Come back and add a few more like the above. + +# EVIDENCE-OF: R-18439-38548 In other words, if the left-hand dataset +# consists of Nleft rows of Mleft columns, and the right-hand dataset of +# Nright rows of Mright columns, then the cartesian product is a dataset +# of Nleft×Nright rows, each containing Mleft+Mright columns. +# +# x1, x2 (Nlhs=3, Nrhs=2) (Mlhs=2, Mrhs=3) +do_join_test e_select-1.4.3.1 { + SELECT count(*) FROM x1 %JOIN% x2 +} [expr 3*2] +do_test e_select-1.4.3.2 { + expr {[llength [execsql {SELECT * FROM x1, x2}]] / 6} +} [expr 2+3] + +# x2, x3 (Nlhs=2, Nrhs=5) (Mlhs=3, Mrhs=4) +do_join_test e_select-1.4.3.3 { + SELECT count(*) FROM x2 %JOIN% x3 +} [expr 2*5] +do_test e_select-1.4.3.4 { + expr {[llength [execsql {SELECT * FROM x2 JOIN x3}]] / 10} +} [expr 3+4] + +# x3, x1 (Nlhs=5, Nrhs=3) (Mlhs=4, Mrhs=2) +do_join_test e_select-1.4.3.5 { + SELECT count(*) FROM x3 %JOIN% x1 +} [expr 5*3] +do_test e_select-1.4.3.6 { + expr {[llength [execsql {SELECT * FROM x3 CROSS JOIN x1}]] / 15} +} [expr 4+2] + +# x3, x3 (Nlhs=5, Nrhs=5) (Mlhs=4, Mrhs=4) +do_join_test e_select-1.4.3.7 { + SELECT count(*) FROM x3 %JOIN% x3 +} [expr 5*5] +do_test e_select-1.4.3.8 { + expr {[llength [execsql {SELECT * FROM x3 INNER JOIN x3 AS x4}]] / 25} +} [expr 4+4] + +# Some extra cartesian product tests using tables t1 and t2. +# +do_execsql_test e_select-1.4.4.1 { SELECT * FROM t1, t2 } $t1_cross_t2 +do_execsql_test e_select-1.4.4.2 { SELECT * FROM t1 AS x, t1 AS y} $t1_cross_t1 + +do_select_tests e_select-1.4.5 [list \ + 1 { SELECT * FROM t1 CROSS JOIN t2 } $t1_cross_t2 \ + 2 { SELECT * FROM t1 AS y CROSS JOIN t1 AS x } $t1_cross_t1 \ + 3 { SELECT * FROM t1 INNER JOIN t2 } $t1_cross_t2 \ + 4 { SELECT * FROM t1 AS y INNER JOIN t1 AS x } $t1_cross_t1 \ +] + +# EVIDENCE-OF: R-38465-03616 If there is an ON clause then the ON +# expression is evaluated for each row of the cartesian product as a +# boolean expression. Only rows for which the expression evaluates to +# true are included from the dataset. +# +foreach {tn select res} [list \ + 1 { SELECT * FROM t1 %JOIN% t2 ON (1) } $t1_cross_t2 \ + 2 { SELECT * FROM t1 %JOIN% t2 ON (0) } [list] \ + 3 { SELECT * FROM t1 %JOIN% t2 ON (NULL) } [list] \ + 4 { SELECT * FROM t1 %JOIN% t2 ON ('abc') } [list] \ + 5 { SELECT * FROM t1 %JOIN% t2 ON ('1ab') } $t1_cross_t2 \ + 6 { SELECT * FROM t1 %JOIN% t2 ON (0.9) } $t1_cross_t2 \ + 7 { SELECT * FROM t1 %JOIN% t2 ON ('0.9') } $t1_cross_t2 \ + 8 { SELECT * FROM t1 %JOIN% t2 ON (0.0) } [list] \ + \ + 9 { SELECT t1.b, t2.b FROM t1 %JOIN% t2 ON (t1.a = t2.a) } \ + {one I two II three III} \ + 10 { SELECT t1.b, t2.b FROM t1 %JOIN% t2 ON (t1.a = 'a') } \ + {one I one II one III} \ + 11 { SELECT t1.b, t2.b + FROM t1 %JOIN% t2 ON (CASE WHEN t1.a = 'a' THEN NULL ELSE 1 END) } \ + {two I two II two III three I three II three III} \ +] { + do_join_test e_select-1.3.$tn $select $res +} + +# EVIDENCE-OF: R-49933-05137 If there is a USING clause then each of the +# column names specified must exist in the datasets to both the left and +# right of the join-operator. +# +do_select_tests e_select-1.4 -error { + cannot join using column %s - column not present in both tables +} { + 1 { SELECT * FROM t1, t3 USING (b) } "b" + 2 { SELECT * FROM t3, t1 USING (c) } "c" + 3 { SELECT * FROM t3, (SELECT a AS b, b AS c FROM t1) USING (a) } "a" +} + +# EVIDENCE-OF: R-22776-52830 For each pair of named columns, the +# expression "lhs.X = rhs.X" is evaluated for each row of the cartesian +# product as a boolean expression. Only rows for which all such +# expressions evaluates to true are included from the result set. +# +do_select_tests e_select-1.5 { + 1 { SELECT * FROM t1, t3 USING (a) } {a one 1 b two 2} + 2 { SELECT * FROM t3, t4 USING (a,c) } {b 2} +} + +# EVIDENCE-OF: R-54046-48600 When comparing values as a result of a +# USING clause, the normal rules for handling affinities, collation +# sequences and NULL values in comparisons apply. +# +# EVIDENCE-OF: R-38422-04402 The column from the dataset on the +# left-hand side of the join-operator is considered to be on the +# left-hand side of the comparison operator (=) for the purposes of +# collation sequence and affinity precedence. +# +do_execsql_test e_select-1.6.0 { + CREATE TABLE t5(a COLLATE nocase, b COLLATE binary); + INSERT INTO t5 VALUES('AA', 'cc'); + INSERT INTO t5 VALUES('BB', 'dd'); + INSERT INTO t5 VALUES(NULL, NULL); + CREATE TABLE t6(a COLLATE binary, b COLLATE nocase); + INSERT INTO t6 VALUES('aa', 'cc'); + INSERT INTO t6 VALUES('bb', 'DD'); + INSERT INTO t6 VALUES(NULL, NULL); +} {} +foreach {tn select res} { + 1 { SELECT * FROM t5 %JOIN% t6 USING (a) } {AA cc cc BB dd DD} + 2 { SELECT * FROM t6 %JOIN% t5 USING (a) } {} + 3 { SELECT * FROM (SELECT a COLLATE nocase, b FROM t6) %JOIN% t5 USING (a) } + {aa cc cc bb DD dd} + 4 { SELECT * FROM t5 %JOIN% t6 USING (a,b) } {AA cc} + 5 { SELECT * FROM t6 %JOIN% t5 USING (a,b) } {} +} { + do_join_test e_select-1.6.$tn $select $res +} + +# EVIDENCE-OF: R-57047-10461 For each pair of columns identified by a +# USING clause, the column from the right-hand dataset is omitted from +# the joined dataset. +# +# EVIDENCE-OF: R-56132-15700 This is the only difference between a USING +# clause and its equivalent ON constraint. +# +foreach {tn select res} { + 1a { SELECT * FROM t1 %JOIN% t2 USING (a) } + {a one I b two II c three III} + 1b { SELECT * FROM t1 %JOIN% t2 ON (t1.a=t2.a) } + {a one a I b two b II c three c III} + + 2a { SELECT * FROM t3 %JOIN% t4 USING (a) } + {a 1 {} b 2 2} + 2b { SELECT * FROM t3 %JOIN% t4 ON (t3.a=t4.a) } + {a 1 a {} b 2 b 2} + + 3a { SELECT * FROM t3 %JOIN% t4 USING (a,c) } {b 2} + 3b { SELECT * FROM t3 %JOIN% t4 ON (t3.a=t4.a AND t3.c=t4.c) } {b 2 b 2} + + 4a { SELECT * FROM (SELECT a COLLATE nocase, b FROM t6) AS x + %JOIN% t5 USING (a) } + {aa cc cc bb DD dd} + 4b { SELECT * FROM (SELECT a COLLATE nocase, b FROM t6) AS x + %JOIN% t5 ON (x.a=t5.a) } + {aa cc AA cc bb DD BB dd} +} { + do_join_test e_select-1.7.$tn $select $res +} + +# EVIDENCE-OF: R-24610-05866 If the join-operator is a "LEFT JOIN" or +# "LEFT OUTER JOIN", then after the ON or USING filtering clauses have +# been applied, an extra row is added to the output for each row in the +# original left-hand input dataset that does not match any row in the +# right-hand dataset. +# +do_execsql_test e_select-1.8.0 { + CREATE TABLE t7(a, b, c); + CREATE TABLE t8(a, d, e); + + INSERT INTO t7 VALUES('x', 'ex', 24); + INSERT INTO t7 VALUES('y', 'why', 25); + + INSERT INTO t8 VALUES('x', 'abc', 24); + INSERT INTO t8 VALUES('z', 'ghi', 26); +} {} + +do_select_tests e_select-1.8 { + 1a "SELECT count(*) FROM t7 JOIN t8 ON (t7.a=t8.a)" {1} + 1b "SELECT count(*) FROM t7 LEFT JOIN t8 ON (t7.a=t8.a)" {2} + 2a "SELECT count(*) FROM t7 JOIN t8 USING (a)" {1} + 2b "SELECT count(*) FROM t7 LEFT JOIN t8 USING (a)" {2} +} + + +# EVIDENCE-OF: R-15607-52988 The added rows contain NULL values in the +# columns that would normally contain values copied from the right-hand +# input dataset. +# +do_select_tests e_select-1.9 { + 1a "SELECT * FROM t7 JOIN t8 ON (t7.a=t8.a)" {x ex 24 x abc 24} + 1b "SELECT * FROM t7 LEFT JOIN t8 ON (t7.a=t8.a)" + {x ex 24 x abc 24 y why 25 {} {} {}} + 2a "SELECT * FROM t7 JOIN t8 USING (a)" {x ex 24 abc 24} + 2b "SELECT * FROM t7 LEFT JOIN t8 USING (a)" {x ex 24 abc 24 y why 25 {} {}} +} + +# EVIDENCE-OF: R-04932-55942 If the NATURAL keyword is in the +# join-operator then an implicit USING clause is added to the +# join-constraints. The implicit USING clause contains each of the +# column names that appear in both the left and right-hand input +# datasets. +# +do_select_tests e_select-1-10 { + 1a "SELECT * FROM t7 JOIN t8 USING (a)" {x ex 24 abc 24} + 1b "SELECT * FROM t7 NATURAL JOIN t8" {x ex 24 abc 24} + + 2a "SELECT * FROM t8 JOIN t7 USING (a)" {x abc 24 ex 24} + 2b "SELECT * FROM t8 NATURAL JOIN t7" {x abc 24 ex 24} + + 3a "SELECT * FROM t7 LEFT JOIN t8 USING (a)" {x ex 24 abc 24 y why 25 {} {}} + 3b "SELECT * FROM t7 NATURAL LEFT JOIN t8" {x ex 24 abc 24 y why 25 {} {}} + + 4a "SELECT * FROM t8 LEFT JOIN t7 USING (a)" {x abc 24 ex 24 z ghi 26 {} {}} + 4b "SELECT * FROM t8 NATURAL LEFT JOIN t7" {x abc 24 ex 24 z ghi 26 {} {}} + + 5a "SELECT * FROM t3 JOIN t4 USING (a,c)" {b 2} + 5b "SELECT * FROM t3 NATURAL JOIN t4" {b 2} + + 6a "SELECT * FROM t3 LEFT JOIN t4 USING (a,c)" {a 1 b 2} + 6b "SELECT * FROM t3 NATURAL LEFT JOIN t4" {a 1 b 2} +} + +# EVIDENCE-OF: R-49566-01570 If the left and right-hand input datasets +# feature no common column names, then the NATURAL keyword has no effect +# on the results of the join. +# +do_execsql_test e_select-1.11.0 { + CREATE TABLE t10(x, y); + INSERT INTO t10 VALUES(1, 'true'); + INSERT INTO t10 VALUES(0, 'false'); +} {} +do_select_tests e_select-1-11 { + 1a "SELECT a, x FROM t1 CROSS JOIN t10" {a 1 a 0 b 1 b 0 c 1 c 0} + 1b "SELECT a, x FROM t1 NATURAL CROSS JOIN t10" {a 1 a 0 b 1 b 0 c 1 c 0} +} + +# EVIDENCE-OF: R-39625-59133 A USING or ON clause may not be added to a +# join that specifies the NATURAL keyword. +# +foreach {tn sql} { + 1 {SELECT * FROM t1 NATURAL LEFT JOIN t2 USING (a)} + 2 {SELECT * FROM t1 NATURAL LEFT JOIN t2 ON (t1.a=t2.a)} + 3 {SELECT * FROM t1 NATURAL LEFT JOIN t2 ON (45)} +} { + do_catchsql_test e_select-1.12.$tn " + $sql + " {1 {a NATURAL join may not have an ON or USING clause}} +} + +#------------------------------------------------------------------------- +# The next block of tests - e_select-3.* - concentrate on verifying +# statements made regarding WHERE clause processing. +# +drop_all_tables +do_execsql_test e_select-3.0 { + CREATE TABLE x1(k, x, y, z); + INSERT INTO x1 VALUES(1, 'relinquished', 'aphasia', 78.43); + INSERT INTO x1 VALUES(2, X'A8E8D66F', X'07CF', -81); + INSERT INTO x1 VALUES(3, -22, -27.57, NULL); + INSERT INTO x1 VALUES(4, NULL, 'bygone', 'picky'); + INSERT INTO x1 VALUES(5, NULL, 96.28, NULL); + INSERT INTO x1 VALUES(6, 0, 1, 2); + + CREATE TABLE x2(k, x, y2); + INSERT INTO x2 VALUES(1, 50, X'B82838'); + INSERT INTO x2 VALUES(5, 84.79, 65.88); + INSERT INTO x2 VALUES(3, -22, X'0E1BE452A393'); + INSERT INTO x2 VALUES(7, 'mistrusted', 'standardized'); +} {} + +# EVIDENCE-OF: R-60775-64916 If a WHERE clause is specified, the WHERE +# expression is evaluated for each row in the input data as a boolean +# expression. Only rows for which the WHERE clause expression evaluates +# to true are included from the dataset before continuing. +# +do_execsql_test e_select-3.1.1 { SELECT k FROM x1 WHERE x } {3} +do_execsql_test e_select-3.1.2 { SELECT k FROM x1 WHERE y } {3 5 6} +do_execsql_test e_select-3.1.3 { SELECT k FROM x1 WHERE z } {1 2 6} +do_execsql_test e_select-3.1.4 { SELECT k FROM x1 WHERE '1'||z } {1 2 4 6} +do_execsql_test e_select-3.1.5 { SELECT k FROM x1 WHERE x IS NULL } {4 5} +do_execsql_test e_select-3.1.6 { SELECT k FROM x1 WHERE z - 78.43 } {2 4 6} + +do_execsql_test e_select-3.2.1a { + SELECT k FROM x1 LEFT JOIN x2 USING(k) +} {1 2 3 4 5 6} +do_execsql_test e_select-3.2.1b { + SELECT k FROM x1 LEFT JOIN x2 USING(k) WHERE x2.k ORDER BY +k +} {1 3 5} +do_execsql_test e_select-3.2.2 { + SELECT k FROM x1 LEFT JOIN x2 USING(k) WHERE x2.k IS NULL +} {2 4 6} + +do_execsql_test e_select-3.2.3 { + SELECT k FROM x1 NATURAL JOIN x2 WHERE x2.k +} {3} +do_execsql_test e_select-3.2.4 { + SELECT k FROM x1 NATURAL JOIN x2 WHERE x2.k-3 +} {} + +#------------------------------------------------------------------------- +# Tests below this point are focused on verifying the testable statements +# related to caculating the result rows of a simple SELECT statement. +# + +drop_all_tables +do_execsql_test e_select-4.0 { + CREATE TABLE z1(a, b, c); + CREATE TABLE z2(d, e); + CREATE TABLE z3(a, b); + + INSERT INTO z1 VALUES(51.65, -59.58, 'belfries'); + INSERT INTO z1 VALUES(-5, NULL, 75); + INSERT INTO z1 VALUES(-2.2, -23.18, 'suiters'); + INSERT INTO z1 VALUES(NULL, 67, 'quartets'); + INSERT INTO z1 VALUES(-1.04, -32.3, 'aspen'); + INSERT INTO z1 VALUES(63, 'born', -26); + + INSERT INTO z2 VALUES(NULL, 21); + INSERT INTO z2 VALUES(36, 6); + + INSERT INTO z3 VALUES('subsistence', 'gauze'); + INSERT INTO z3 VALUES(49.17, -67); +} {} + +# EVIDENCE-OF: R-36327-17224 If a result expression is the special +# expression "*" then all columns in the input data are substituted for +# that one expression. +# +# EVIDENCE-OF: R-43693-30522 If the expression is the alias of a table +# or subquery in the FROM clause followed by ".*" then all columns from +# the named table or subquery are substituted for the single expression. +# +do_select_tests e_select-4.1 { + 1 "SELECT * FROM z1 LIMIT 1" {51.65 -59.58 belfries} + 2 "SELECT * FROM z1,z2 LIMIT 1" {51.65 -59.58 belfries {} 21} + 3 "SELECT z1.* FROM z1,z2 LIMIT 1" {51.65 -59.58 belfries} + 4 "SELECT z2.* FROM z1,z2 LIMIT 1" {{} 21} + 5 "SELECT z2.*, z1.* FROM z1,z2 LIMIT 1" {{} 21 51.65 -59.58 belfries} + + 6 "SELECT count(*), * FROM z1" {6 51.65 -59.58 belfries} + 7 "SELECT max(a), * FROM z1" {63 63 born -26} + 8 "SELECT *, min(a) FROM z1" {-5 {} 75 -5} + + 9 "SELECT *,* FROM z1,z2 LIMIT 1" { + 51.65 -59.58 belfries {} 21 51.65 -59.58 belfries {} 21 + } + 10 "SELECT z1.*,z1.* FROM z2,z1 LIMIT 1" { + 51.65 -59.58 belfries 51.65 -59.58 belfries + } +} + +# EVIDENCE-OF: R-38023-18396 It is an error to use a "*" or "alias.*" +# expression in any context other than a result expression list. +# +# EVIDENCE-OF: R-44324-41166 It is also an error to use a "*" or +# "alias.*" expression in a simple SELECT query that does not have a +# FROM clause. +# +foreach {tn select err} { + 1.1 "SELECT a, b, c FROM z1 WHERE *" {near "*": syntax error} + 1.2 "SELECT a, b, c FROM z1 GROUP BY *" {near "*": syntax error} + 1.3 "SELECT 1 + * FROM z1" {near "*": syntax error} + 1.4 "SELECT * + 1 FROM z1" {near "+": syntax error} + + 2.1 "SELECT *" {no tables specified} + 2.2 "SELECT * WHERE 1" {no tables specified} + 2.3 "SELECT * WHERE 0" {no tables specified} + 2.4 "SELECT count(*), *" {no tables specified} +} { + do_catchsql_test e_select-4.2.$tn $select [list 1 $err] +} + +# EVIDENCE-OF: R-08669-22397 The number of columns in the rows returned +# by a simple SELECT statement is equal to the number of expressions in +# the result expression list after substitution of * and alias.* +# expressions. +# +foreach {tn select nCol} { + 1 "SELECT * FROM z1" 3 + 2 "SELECT * FROM z1 NATURAL JOIN z3" 3 + 3 "SELECT z1.* FROM z1 NATURAL JOIN z3" 3 + 4 "SELECT z3.* FROM z1 NATURAL JOIN z3" 2 + 5 "SELECT z1.*, z3.* FROM z1 NATURAL JOIN z3" 5 + 6 "SELECT 1, 2, z1.* FROM z1" 5 + 7 "SELECT a, *, b, c FROM z1" 6 +} { + set ::stmt [sqlite3_prepare_v2 db $select -1 DUMMY] + do_test e_select-4.3.$tn { sqlite3_column_count $::stmt } $nCol + sqlite3_finalize $::stmt +} + + + +# In lang_select.html, a non-aggregate query is defined as any simple SELECT +# that has no GROUP BY clause and no aggregate expressions in the result +# expression list. Other queries are aggregate queries. Test cases +# e_select-4.4.* through e_select-4.12.*, inclusive, which test the part of +# simple SELECT that is different for aggregate and non-aggregate queries +# verify (in a way) that these definitions are consistent: +# +# EVIDENCE-OF: R-20637-43463 A simple SELECT statement is an aggregate +# query if it contains either a GROUP BY clause or one or more aggregate +# functions in the result-set. +# +# EVIDENCE-OF: R-23155-55597 Otherwise, if a simple SELECT contains no +# aggregate functions or a GROUP BY clause, it is a non-aggregate query. +# + +# EVIDENCE-OF: R-44050-47362 If the SELECT statement is a non-aggregate +# query, then each expression in the result expression list is evaluated +# for each row in the dataset filtered by the WHERE clause. +# +do_select_tests e_select-4.4 { + 1 "SELECT a, b FROM z1" + {51.65 -59.58 -5 {} -2.2 -23.18 {} 67 -1.04 -32.3 63 born} + + 2 "SELECT a IS NULL, b+1, * FROM z1" { + 0 -58.58 51.65 -59.58 belfries + 0 {} -5 {} 75 + 0 -22.18 -2.2 -23.18 suiters + 1 68 {} 67 quartets + 0 -31.3 -1.04 -32.3 aspen + 0 1 63 born -26 + } + + 3 "SELECT 32*32, d||e FROM z2" {1024 {} 1024 366} +} + + +# Test cases e_select-4.5.* and e_select-4.6.* together show that: +# +# EVIDENCE-OF: R-51988-01124 The single row of result-set data created +# by evaluating the aggregate and non-aggregate expressions in the +# result-set forms the result of an aggregate query without a GROUP BY +# clause. +# + +# EVIDENCE-OF: R-57629-25253 If the SELECT statement is an aggregate +# query without a GROUP BY clause, then each aggregate expression in the +# result-set is evaluated once across the entire dataset. +# +do_select_tests e_select-4.5 { + 1 "SELECT count(a), max(a), count(b), max(b) FROM z1" {5 63 5 born} + 2 "SELECT count(*), max(1)" {1 1} + + 3 "SELECT sum(b+1) FROM z1 NATURAL LEFT JOIN z3" {-43.06} + 4 "SELECT sum(b+2) FROM z1 NATURAL LEFT JOIN z3" {-38.06} + 5 "SELECT sum(b IS NOT NULL) FROM z1 NATURAL LEFT JOIN z3" {5} +} + +# EVIDENCE-OF: R-26684-40576 Each non-aggregate expression in the +# result-set is evaluated once for an arbitrarily selected row of the +# dataset. +# +# EVIDENCE-OF: R-27994-60376 The same arbitrarily selected row is used +# for each non-aggregate expression. +# +# Note: The results of many of the queries in this block of tests are +# technically undefined, as the documentation does not specify which row +# SQLite will arbitrarily select to use for the evaluation of the +# non-aggregate expressions. +# +drop_all_tables +do_execsql_test e_select-4.6.0 { + CREATE TABLE a1(one PRIMARY KEY, two); + INSERT INTO a1 VALUES(1, 1); + INSERT INTO a1 VALUES(2, 3); + INSERT INTO a1 VALUES(3, 6); + INSERT INTO a1 VALUES(4, 10); + + CREATE TABLE a2(one PRIMARY KEY, three); + INSERT INTO a2 VALUES(1, 1); + INSERT INTO a2 VALUES(3, 2); + INSERT INTO a2 VALUES(6, 3); + INSERT INTO a2 VALUES(10, 4); +} {} +do_select_tests e_select-4.6 { + 1 "SELECT one, two, count(*) FROM a1" {1 1 4} + 2 "SELECT one, two, count(*) FROM a1 WHERE one<3" {1 1 2} + 3 "SELECT one, two, count(*) FROM a1 WHERE one>3" {4 10 1} + 4 "SELECT *, count(*) FROM a1 JOIN a2" {1 1 1 1 16} + 5 "SELECT *, sum(three) FROM a1 NATURAL JOIN a2" {1 1 1 3} + 6 "SELECT *, sum(three) FROM a1 NATURAL JOIN a2" {1 1 1 3} + 7 "SELECT string_agg(three, ''), a1.* FROM a1 NATURAL JOIN a2" {12 1 1} +} + +# EVIDENCE-OF: R-04486-07266 Or, if the dataset contains zero rows, then +# each non-aggregate expression is evaluated against a row consisting +# entirely of NULL values. +# +do_select_tests e_select-4.7 { + 1 "SELECT one, two, count(*) FROM a1 WHERE 0" {{} {} 0} + 2 "SELECT sum(two), * FROM a1, a2 WHERE three>5" {{} {} {} {} {}} + 3 "SELECT max(one) IS NULL, one IS NULL, two IS NULL FROM a1 WHERE two=7" { + 1 1 1 + } +} + +# EVIDENCE-OF: R-64138-28774 An aggregate query without a GROUP BY +# clause always returns exactly one row of data, even if there are zero +# rows of input data. +# +foreach {tn select} { + 8.1 "SELECT count(*) FROM a1" + 8.2 "SELECT count(*) FROM a1 WHERE 0" + 8.3 "SELECT count(*) FROM a1 WHERE 1" + 8.4 "SELECT max(a1.one)+min(two), a1.one, two, * FROM a1, a2 WHERE 1" + 8.5 "SELECT max(a1.one)+min(two), a1.one, two, * FROM a1, a2 WHERE 0" +} { + # Set $nRow to the number of rows returned by $select: + set ::stmt [sqlite3_prepare_v2 db $select -1 DUMMY] + set nRow 0 + while {"SQLITE_ROW" == [sqlite3_step $::stmt]} { incr nRow } + set rc [sqlite3_finalize $::stmt] + + # Test that $nRow==1 and that statement execution was successful + # (rc==SQLITE_OK). + do_test e_select-4.$tn [list list $rc $nRow] {SQLITE_OK 1} +} + +drop_all_tables +do_execsql_test e_select-4.9.0 { + CREATE TABLE b1(one PRIMARY KEY, two); + INSERT INTO b1 VALUES(1, 'o'); + INSERT INTO b1 VALUES(4, 'f'); + INSERT INTO b1 VALUES(3, 't'); + INSERT INTO b1 VALUES(2, 't'); + INSERT INTO b1 VALUES(5, 'f'); + INSERT INTO b1 VALUES(7, 's'); + INSERT INTO b1 VALUES(6, 's'); + + CREATE TABLE b2(x, y); + INSERT INTO b2 VALUES(NULL, 0); + INSERT INTO b2 VALUES(NULL, 1); + INSERT INTO b2 VALUES('xyz', 2); + INSERT INTO b2 VALUES('abc', 3); + INSERT INTO b2 VALUES('xyz', 4); + + CREATE TABLE b3(a COLLATE nocase, b COLLATE binary); + INSERT INTO b3 VALUES('abc', 'abc'); + INSERT INTO b3 VALUES('aBC', 'aBC'); + INSERT INTO b3 VALUES('Def', 'Def'); + INSERT INTO b3 VALUES('dEF', 'dEF'); +} {} + +# EVIDENCE-OF: R-40855-36147 If the SELECT statement is an aggregate +# query with a GROUP BY clause, then each of the expressions specified +# as part of the GROUP BY clause is evaluated for each row of the +# dataset according to the processing rules stated below for ORDER BY +# expressions. Each row is then assigned to a "group" based on the +# results; rows for which the results of evaluating the GROUP BY +# expressions are the same get assigned to the same group. +# +# These tests also show that the following is not untrue: +# +# EVIDENCE-OF: R-25883-55063 The expressions in the GROUP BY clause do +# not have to be expressions that appear in the result. +# +do_select_tests e_select-4.9 { + 1 "SELECT group_concat(one), two FROM b1 GROUP BY two" { + /#,# f 1 o #,# s #,# t/ + } + 2 "SELECT group_concat(one), sum(one) FROM b1 GROUP BY (one>4)" { + 1,2,3,4 10 5,6,7 18 + } + 3 "SELECT group_concat(one) FROM b1 GROUP BY (two>'o'), one%2" { + 4 1,5 2,6 3,7 + } + 4 "SELECT group_concat(one) FROM b1 GROUP BY (one==2 OR two=='o')" { + 4,3,5,7,6 1,2 + } +} + +# EVIDENCE-OF: R-14926-50129 For the purposes of grouping rows, NULL +# values are considered equal. +# +do_select_tests e_select-4.10 { + 1 "SELECT group_concat(y) FROM b2 GROUP BY x" {/#,# 3 #,#/} + 2 "SELECT count(*) FROM b2 GROUP BY CASE WHEN y<4 THEN NULL ELSE 0 END" {4 1} +} + +# EVIDENCE-OF: R-10470-30318 The usual rules for selecting a collation +# sequence with which to compare text values apply when evaluating +# expressions in a GROUP BY clause. +# +do_select_tests e_select-4.11 { + 1 "SELECT count(*) FROM b3 GROUP BY b" {1 1 1 1} + 2 "SELECT count(*) FROM b3 GROUP BY a" {2 2} + 3 "SELECT count(*) FROM b3 GROUP BY +b" {1 1 1 1} + 4 "SELECT count(*) FROM b3 GROUP BY +a" {2 2} + 5 "SELECT count(*) FROM b3 GROUP BY b||''" {1 1 1 1} + 6 "SELECT count(*) FROM b3 GROUP BY a||''" {1 1 1 1} +} + +# EVIDENCE-OF: R-63573-50730 The expressions in a GROUP BY clause may +# not be aggregate expressions. +# +foreach {tn select} { + 12.1 "SELECT * FROM b3 GROUP BY count(*)" + 12.2 "SELECT max(a) FROM b3 GROUP BY max(b)" + 12.3 "SELECT group_concat(a) FROM b3 GROUP BY a, max(b)" +} { + set res {1 {aggregate functions are not allowed in the GROUP BY clause}} + do_catchsql_test e_select-4.$tn $select $res +} + +# EVIDENCE-OF: R-31537-00101 If a HAVING clause is specified, it is +# evaluated once for each group of rows as a boolean expression. If the +# result of evaluating the HAVING clause is false, the group is +# discarded. +# +# This requirement is tested by all e_select-4.13.* tests. +# +# EVIDENCE-OF: R-04132-09474 If the HAVING clause is an aggregate +# expression, it is evaluated across all rows in the group. +# +# Tested by e_select-4.13.1.* +# +# EVIDENCE-OF: R-28262-47447 If a HAVING clause is a non-aggregate +# expression, it is evaluated with respect to an arbitrarily selected +# row from the group. +# +# Tested by e_select-4.13.2.* +# +# Tests in this block also show that this is not untrue: +# +# EVIDENCE-OF: R-55403-13450 The HAVING expression may refer to values, +# even aggregate functions, that are not in the result. +# +do_execsql_test e_select-4.13.0 { + CREATE TABLE c1(up, down); + INSERT INTO c1 VALUES('x', 1); + INSERT INTO c1 VALUES('x', 2); + INSERT INTO c1 VALUES('x', 4); + INSERT INTO c1 VALUES('x', 8); + INSERT INTO c1 VALUES('y', 16); + INSERT INTO c1 VALUES('y', 32); + + CREATE TABLE c2(i, j); + INSERT INTO c2 VALUES(1, 0); + INSERT INTO c2 VALUES(2, 1); + INSERT INTO c2 VALUES(3, 3); + INSERT INTO c2 VALUES(4, 6); + INSERT INTO c2 VALUES(5, 10); + INSERT INTO c2 VALUES(6, 15); + INSERT INTO c2 VALUES(7, 21); + INSERT INTO c2 VALUES(8, 28); + INSERT INTO c2 VALUES(9, 36); + + CREATE TABLE c3(i PRIMARY KEY, k TEXT); + INSERT INTO c3 VALUES(1, 'hydrogen'); + INSERT INTO c3 VALUES(2, 'helium'); + INSERT INTO c3 VALUES(3, 'lithium'); + INSERT INTO c3 VALUES(4, 'beryllium'); + INSERT INTO c3 VALUES(5, 'boron'); + INSERT INTO c3 VALUES(94, 'plutonium'); +} {} + +do_select_tests e_select-4.13 { + 1.1 "SELECT up FROM c1 GROUP BY up HAVING count(*)>3" {x} + 1.2 "SELECT up FROM c1 GROUP BY up HAVING sum(down)>16" {y} + 1.3 "SELECT up FROM c1 GROUP BY up HAVING sum(down)<16" {x} + 1.4 "SELECT up||down FROM c1 GROUP BY (down<5) HAVING max(down)<10" {x4} + + 2.1 "SELECT up FROM c1 GROUP BY up HAVING down>10" {y} + 2.2 "SELECT up FROM c1 GROUP BY up HAVING up='y'" {y} + + 2.3 "SELECT i, j FROM c2 GROUP BY i>4 HAVING j>6" {5 10} +} + +# EVIDENCE-OF: R-23927-54081 Each expression in the result-set is then +# evaluated once for each group of rows. +# +# EVIDENCE-OF: R-53735-47017 If the expression is an aggregate +# expression, it is evaluated across all rows in the group. +# +do_select_tests e_select-4.15 { + 1 "SELECT sum(down) FROM c1 GROUP BY up" {15 48} + 2 "SELECT sum(j), max(j) FROM c2 GROUP BY (i%3)" {54 36 27 21 39 28} + 3 "SELECT sum(j), max(j) FROM c2 GROUP BY (j%2)" {80 36 40 21} + 4 "SELECT 1+sum(j), max(j)+1 FROM c2 GROUP BY (j%2)" {81 37 41 22} + 5 "SELECT count(*), round(avg(i),2) FROM c1, c2 ON (i=down) GROUP BY j%2" + {3 4.33 1 2.0} +} + +# EVIDENCE-OF: R-62913-19830 Otherwise, it is evaluated against a single +# arbitrarily chosen row from within the group. +# +# EVIDENCE-OF: R-53924-08809 If there is more than one non-aggregate +# expression in the result-set, then all such expressions are evaluated +# for the same row. +# +do_select_tests e_select-4.15 { + 1 "SELECT i, j FROM c2 GROUP BY i%2" {2 1 1 0} + 2 "SELECT i, j FROM c2 GROUP BY i%2 HAVING j<30" {2 1 1 0} + 3 "SELECT i, j FROM c2 GROUP BY i%2 HAVING j>30" {} + 4 "SELECT i, j FROM c2 GROUP BY i%2 HAVING j>30" {} + 5 "SELECT count(*), i, k FROM c2 NATURAL JOIN c3 GROUP BY substr(k, 1, 1)" + {2 4 beryllium 2 1 hydrogen 1 3 lithium} +} + +# EVIDENCE-OF: R-19334-12811 Each group of input dataset rows +# contributes a single row to the set of result rows. +# +# EVIDENCE-OF: R-02223-49279 Subject to filtering associated with the +# DISTINCT keyword, the number of rows returned by an aggregate query +# with a GROUP BY clause is the same as the number of groups of rows +# produced by applying the GROUP BY and HAVING clauses to the filtered +# input dataset. +# +do_select_tests e_select.4.16 -count { + 1 "SELECT i, j FROM c2 GROUP BY i%2" 2 + 2 "SELECT i, j FROM c2 GROUP BY i" 9 + 3 "SELECT i, j FROM c2 GROUP BY i HAVING i<5" 4 +} + +#------------------------------------------------------------------------- +# The following tests attempt to verify statements made regarding the ALL +# and DISTINCT keywords. +# +drop_all_tables +do_execsql_test e_select-5.1.0 { + CREATE TABLE h1(a, b); + INSERT INTO h1 VALUES(1, 'one'); + INSERT INTO h1 VALUES(1, 'I'); + INSERT INTO h1 VALUES(1, 'i'); + INSERT INTO h1 VALUES(4, 'four'); + INSERT INTO h1 VALUES(4, 'IV'); + INSERT INTO h1 VALUES(4, 'iv'); + + CREATE TABLE h2(x COLLATE nocase); + INSERT INTO h2 VALUES('One'); + INSERT INTO h2 VALUES('Two'); + INSERT INTO h2 VALUES('Three'); + INSERT INTO h2 VALUES('Four'); + INSERT INTO h2 VALUES('one'); + INSERT INTO h2 VALUES('two'); + INSERT INTO h2 VALUES('three'); + INSERT INTO h2 VALUES('four'); + + CREATE TABLE h3(c, d); + INSERT INTO h3 VALUES(1, NULL); + INSERT INTO h3 VALUES(2, NULL); + INSERT INTO h3 VALUES(3, NULL); + INSERT INTO h3 VALUES(4, '2'); + INSERT INTO h3 VALUES(5, NULL); + INSERT INTO h3 VALUES(6, '2,3'); + INSERT INTO h3 VALUES(7, NULL); + INSERT INTO h3 VALUES(8, '2,4'); + INSERT INTO h3 VALUES(9, '3'); +} {} + +# EVIDENCE-OF: R-60770-10612 One of the ALL or DISTINCT keywords may +# follow the SELECT keyword in a simple SELECT statement. +# +do_select_tests e_select-5.1 { + 1 "SELECT ALL a FROM h1" {1 1 1 4 4 4} + 2 "SELECT DISTINCT a FROM h1" {1 4} +} + +# EVIDENCE-OF: R-08861-34280 If the simple SELECT is a SELECT ALL, then +# the entire set of result rows are returned by the SELECT. +# +# EVIDENCE-OF: R-01256-01950 If neither ALL or DISTINCT are present, +# then the behavior is as if ALL were specified. +# +# EVIDENCE-OF: R-14442-41305 If the simple SELECT is a SELECT DISTINCT, +# then duplicate rows are removed from the set of result rows before it +# is returned. +# +# The three testable statements above are tested by e_select-5.2.*, +# 5.3.* and 5.4.* respectively. +# +do_select_tests e_select-5 { + 3.1 "SELECT ALL x FROM h2" {One Two Three Four one two three four} + 3.2 "SELECT ALL x FROM h1, h2 ON (x=b)" {One one Four four} + + 3.1 "SELECT x FROM h2" {One Two Three Four one two three four} + 3.2 "SELECT x FROM h1, h2 ON (x=b)" {One one Four four} + + 4.1 "SELECT DISTINCT x FROM h2" {One Two Three Four} + 4.2 "SELECT DISTINCT x FROM h1, h2 ON (x=b)" {One Four} +} + +# EVIDENCE-OF: R-02054-15343 For the purposes of detecting duplicate +# rows, two NULL values are considered to be equal. +# +do_select_tests e_select-5.5 { + 1 "SELECT DISTINCT d FROM h3" {{} 2 2,3 2,4 3} +} + +# EVIDENCE-OF: R-47709-27231 The usual rules apply for selecting a +# collation sequence to compare text values. +# +do_select_tests e_select-5.6 { + 1 "SELECT DISTINCT b FROM h1" {one I i four IV iv} + 2 "SELECT DISTINCT b COLLATE nocase FROM h1" {one I four IV} + 3 "SELECT DISTINCT x FROM h2" {One Two Three Four} + 4 "SELECT DISTINCT x COLLATE binary FROM h2" { + One Two Three Four one two three four + } +} + +#------------------------------------------------------------------------- +# The following tests - e_select-7.* - test that statements made to do +# with compound SELECT statements are correct. +# + +# EVIDENCE-OF: R-39368-64333 In a compound SELECT, all the constituent +# SELECTs must return the same number of result columns. +# +# All the other tests in this section use compound SELECTs created +# using component SELECTs that do return the same number of columns. +# So the tests here just show that it is an error to attempt otherwise. +# +drop_all_tables +do_execsql_test e_select-7.1.0 { + CREATE TABLE j1(a, b, c); + CREATE TABLE j2(e, f); + CREATE TABLE j3(g); +} {} +do_select_tests e_select-7.1 -error { + SELECTs to the left and right of %s do not have the same number of result columns +} { + 1 "SELECT a, b FROM j1 UNION ALL SELECT g FROM j3" {{UNION ALL}} + 2 "SELECT * FROM j1 UNION ALL SELECT * FROM j3" {{UNION ALL}} + 3 "SELECT a, b FROM j1 UNION ALL SELECT g FROM j3" {{UNION ALL}} + 4 "SELECT a, b FROM j1 UNION ALL SELECT * FROM j3,j2" {{UNION ALL}} + 5 "SELECT * FROM j3,j2 UNION ALL SELECT a, b FROM j1" {{UNION ALL}} + + 6 "SELECT a, b FROM j1 UNION SELECT g FROM j3" {UNION} + 7 "SELECT * FROM j1 UNION SELECT * FROM j3" {UNION} + 8 "SELECT a, b FROM j1 UNION SELECT g FROM j3" {UNION} + 9 "SELECT a, b FROM j1 UNION SELECT * FROM j3,j2" {UNION} + 10 "SELECT * FROM j3,j2 UNION SELECT a, b FROM j1" {UNION} + + 11 "SELECT a, b FROM j1 INTERSECT SELECT g FROM j3" {INTERSECT} + 12 "SELECT * FROM j1 INTERSECT SELECT * FROM j3" {INTERSECT} + 13 "SELECT a, b FROM j1 INTERSECT SELECT g FROM j3" {INTERSECT} + 14 "SELECT a, b FROM j1 INTERSECT SELECT * FROM j3,j2" {INTERSECT} + 15 "SELECT * FROM j3,j2 INTERSECT SELECT a, b FROM j1" {INTERSECT} + + 16 "SELECT a, b FROM j1 EXCEPT SELECT g FROM j3" {EXCEPT} + 17 "SELECT * FROM j1 EXCEPT SELECT * FROM j3" {EXCEPT} + 18 "SELECT a, b FROM j1 EXCEPT SELECT g FROM j3" {EXCEPT} + 19 "SELECT a, b FROM j1 EXCEPT SELECT * FROM j3,j2" {EXCEPT} + 20 "SELECT * FROM j3,j2 EXCEPT SELECT a, b FROM j1" {EXCEPT} +} + +# EVIDENCE-OF: R-01450-11152 As the components of a compound SELECT must +# be simple SELECT statements, they may not contain ORDER BY or LIMIT +# clauses. +# +foreach {tn select op1 op2} { + 1 "SELECT * FROM j1 ORDER BY a UNION ALL SELECT * FROM j2,j3" + {ORDER BY} {UNION ALL} + 2 "SELECT count(*) FROM j1 ORDER BY 1 UNION ALL SELECT max(e) FROM j2" + {ORDER BY} {UNION ALL} + 3 "SELECT count(*), * FROM j1 ORDER BY 1,2,3 UNION ALL SELECT *,* FROM j2" + {ORDER BY} {UNION ALL} + 4 "SELECT * FROM j1 LIMIT 10 UNION ALL SELECT * FROM j2,j3" + LIMIT {UNION ALL} + 5 "SELECT * FROM j1 LIMIT 10 OFFSET 5 UNION ALL SELECT * FROM j2,j3" + LIMIT {UNION ALL} + 6 "SELECT a FROM j1 LIMIT (SELECT e FROM j2) UNION ALL SELECT g FROM j2,j3" + LIMIT {UNION ALL} + + 7 "SELECT * FROM j1 ORDER BY a UNION SELECT * FROM j2,j3" + {ORDER BY} {UNION} + 8 "SELECT count(*) FROM j1 ORDER BY 1 UNION SELECT max(e) FROM j2" + {ORDER BY} {UNION} + 9 "SELECT count(*), * FROM j1 ORDER BY 1,2,3 UNION SELECT *,* FROM j2" + {ORDER BY} {UNION} + 10 "SELECT * FROM j1 LIMIT 10 UNION SELECT * FROM j2,j3" + LIMIT {UNION} + 11 "SELECT * FROM j1 LIMIT 10 OFFSET 5 UNION SELECT * FROM j2,j3" + LIMIT {UNION} + 12 "SELECT a FROM j1 LIMIT (SELECT e FROM j2) UNION SELECT g FROM j2,j3" + LIMIT {UNION} + + 13 "SELECT * FROM j1 ORDER BY a EXCEPT SELECT * FROM j2,j3" + {ORDER BY} {EXCEPT} + 14 "SELECT count(*) FROM j1 ORDER BY 1 EXCEPT SELECT max(e) FROM j2" + {ORDER BY} {EXCEPT} + 15 "SELECT count(*), * FROM j1 ORDER BY 1,2,3 EXCEPT SELECT *,* FROM j2" + {ORDER BY} {EXCEPT} + 16 "SELECT * FROM j1 LIMIT 10 EXCEPT SELECT * FROM j2,j3" + LIMIT {EXCEPT} + 17 "SELECT * FROM j1 LIMIT 10 OFFSET 5 EXCEPT SELECT * FROM j2,j3" + LIMIT {EXCEPT} + 18 "SELECT a FROM j1 LIMIT (SELECT e FROM j2) EXCEPT SELECT g FROM j2,j3" + LIMIT {EXCEPT} + + 19 "SELECT * FROM j1 ORDER BY a INTERSECT SELECT * FROM j2,j3" + {ORDER BY} {INTERSECT} + 20 "SELECT count(*) FROM j1 ORDER BY 1 INTERSECT SELECT max(e) FROM j2" + {ORDER BY} {INTERSECT} + 21 "SELECT count(*), * FROM j1 ORDER BY 1,2,3 INTERSECT SELECT *,* FROM j2" + {ORDER BY} {INTERSECT} + 22 "SELECT * FROM j1 LIMIT 10 INTERSECT SELECT * FROM j2,j3" + LIMIT {INTERSECT} + 23 "SELECT * FROM j1 LIMIT 10 OFFSET 5 INTERSECT SELECT * FROM j2,j3" + LIMIT {INTERSECT} + 24 "SELECT a FROM j1 LIMIT (SELECT e FROM j2) INTERSECT SELECT g FROM j2,j3" + LIMIT {INTERSECT} +} { + set err "$op1 clause should come after $op2 not before" + do_catchsql_test e_select-7.2.$tn $select [list 1 $err] +} + +# EVIDENCE-OF: R-45440-25633 ORDER BY and LIMIT clauses may only occur +# at the end of the entire compound SELECT, and then only if the final +# element of the compound is not a VALUES clause. +# +foreach {tn select} { + 1 "SELECT * FROM j1 UNION ALL SELECT * FROM j2,j3 ORDER BY a" + 2 "SELECT count(*) FROM j1 UNION ALL SELECT max(e) FROM j2 ORDER BY 1" + 3 "SELECT count(*), * FROM j1 UNION ALL SELECT *,* FROM j2 ORDER BY 1,2,3" + 4 "SELECT * FROM j1 UNION ALL SELECT * FROM j2,j3 LIMIT 10" + 5 "SELECT * FROM j1 UNION ALL SELECT * FROM j2,j3 LIMIT 10 OFFSET 5" + 6 "SELECT a FROM j1 UNION ALL SELECT g FROM j2,j3 LIMIT (SELECT 10)" + + 7 "SELECT * FROM j1 UNION SELECT * FROM j2,j3 ORDER BY a" + 8 "SELECT count(*) FROM j1 UNION SELECT max(e) FROM j2 ORDER BY 1" + 8b "VALUES('8b') UNION SELECT max(e) FROM j2 ORDER BY 1" + 9 "SELECT count(*), * FROM j1 UNION SELECT *,* FROM j2 ORDER BY 1,2,3" + 10 "SELECT * FROM j1 UNION SELECT * FROM j2,j3 LIMIT 10" + 11 "SELECT * FROM j1 UNION SELECT * FROM j2,j3 LIMIT 10 OFFSET 5" + 12 "SELECT a FROM j1 UNION SELECT g FROM j2,j3 LIMIT (SELECT 10)" + + 13 "SELECT * FROM j1 EXCEPT SELECT * FROM j2,j3 ORDER BY a" + 14 "SELECT count(*) FROM j1 EXCEPT SELECT max(e) FROM j2 ORDER BY 1" + 15 "SELECT count(*), * FROM j1 EXCEPT SELECT *,* FROM j2 ORDER BY 1,2,3" + 16 "SELECT * FROM j1 EXCEPT SELECT * FROM j2,j3 LIMIT 10" + 17 "SELECT * FROM j1 EXCEPT SELECT * FROM j2,j3 LIMIT 10 OFFSET 5" + 18 "SELECT a FROM j1 EXCEPT SELECT g FROM j2,j3 LIMIT (SELECT 10)" + + 19 "SELECT * FROM j1 INTERSECT SELECT * FROM j2,j3 ORDER BY a" + 20 "SELECT count(*) FROM j1 INTERSECT SELECT max(e) FROM j2 ORDER BY 1" + 21 "SELECT count(*), * FROM j1 INTERSECT SELECT *,* FROM j2 ORDER BY 1,2,3" + 22 "SELECT * FROM j1 INTERSECT SELECT * FROM j2,j3 LIMIT 10" + 23 "SELECT * FROM j1 INTERSECT SELECT * FROM j2,j3 LIMIT 10 OFFSET 5" + 24 "SELECT a FROM j1 INTERSECT SELECT g FROM j2,j3 LIMIT (SELECT 10)" +} { + do_test e_select-7.3.$tn { catch {execsql $select} msg } 0 +} +foreach {tn select} { + 50 "SELECT * FROM j1 ORDER BY 1 UNION ALL SELECT * FROM j2,j3" + 51 "SELECT * FROM j1 LIMIT 1 UNION ALL SELECT * FROM j2,j3" + 52 "SELECT count(*) FROM j1 UNION ALL VALUES(11) ORDER BY 1" + 53 "SELECT count(*) FROM j1 UNION ALL VALUES(11) LIMIT 1" +} { + do_test e_select-7.3.$tn { catch {execsql $select} msg } 1 +} + +# EVIDENCE-OF: R-08531-36543 A compound SELECT created using UNION ALL +# operator returns all the rows from the SELECT to the left of the UNION +# ALL operator, and all the rows from the SELECT to the right of it. +# +drop_all_tables +do_execsql_test e_select-7.4.0 { + CREATE TABLE q1(a TEXT, b INTEGER, c); + CREATE TABLE q2(d NUMBER, e BLOB); + CREATE TABLE q3(f REAL, g); + + INSERT INTO q1 VALUES(16, -87.66, NULL); + INSERT INTO q1 VALUES('legible', 94, -42.47); + INSERT INTO q1 VALUES('beauty', 36, NULL); + + INSERT INTO q2 VALUES('legible', 1); + INSERT INTO q2 VALUES('beauty', 2); + INSERT INTO q2 VALUES(-65.91, 4); + INSERT INTO q2 VALUES('emanating', -16.56); + + INSERT INTO q3 VALUES('beauty', 2); + INSERT INTO q3 VALUES('beauty', 2); +} {} +do_select_tests e_select-7.4 { + 1 {SELECT a FROM q1 UNION ALL SELECT d FROM q2} + {16 legible beauty legible beauty -65.91 emanating} + + 2 {SELECT * FROM q1 WHERE a=16 UNION ALL SELECT 'x', * FROM q2 WHERE oid=1} + {16 -87.66 {} x legible 1} + + 3 {SELECT count(*) FROM q1 UNION ALL SELECT min(e) FROM q2} + {3 -16.56} + + 4 {SELECT * FROM q2 UNION ALL SELECT * FROM q3} + {legible 1 beauty 2 -65.91 4 emanating -16.56 beauty 2 beauty 2} +} + +# EVIDENCE-OF: R-20560-39162 The UNION operator works the same way as +# UNION ALL, except that duplicate rows are removed from the final +# result set. +# +do_select_tests e_select-7.5 { + 1 {SELECT a FROM q1 UNION SELECT d FROM q2} + {-65.91 16 beauty emanating legible} + + 2 {SELECT * FROM q1 WHERE a=16 UNION SELECT 'x', * FROM q2 WHERE oid=1} + {16 -87.66 {} x legible 1} + + 3 {SELECT count(*) FROM q1 UNION SELECT min(e) FROM q2} + {-16.56 3} + + 4 {SELECT * FROM q2 UNION SELECT * FROM q3} + {-65.91 4 beauty 2 emanating -16.56 legible 1} +} + +# EVIDENCE-OF: R-45764-31737 The INTERSECT operator returns the +# intersection of the results of the left and right SELECTs. +# +do_select_tests e_select-7.6 { + 1 {SELECT a FROM q1 INTERSECT SELECT d FROM q2} {beauty legible} + 2 {SELECT * FROM q2 INTERSECT SELECT * FROM q3} {beauty 2} +} + +# EVIDENCE-OF: R-25787-28949 The EXCEPT operator returns the subset of +# rows returned by the left SELECT that are not also returned by the +# right-hand SELECT. +# +do_select_tests e_select-7.7 { + 1 {SELECT a FROM q1 EXCEPT SELECT d FROM q2} {16} + + 2 {SELECT * FROM q2 EXCEPT SELECT * FROM q3} + {-65.91 4 emanating -16.56 legible 1} +} + +# EVIDENCE-OF: R-40729-56447 Duplicate rows are removed from the results +# of INTERSECT and EXCEPT operators before the result set is returned. +# +do_select_tests e_select-7.8 { + 0 {SELECT * FROM q3} {beauty 2 beauty 2} + + 1 {SELECT * FROM q3 INTERSECT SELECT * FROM q3} {beauty 2} + 2 {SELECT * FROM q3 EXCEPT SELECT a,b FROM q1} {beauty 2} +} + +# EVIDENCE-OF: R-46765-43362 For the purposes of determining duplicate +# rows for the results of compound SELECT operators, NULL values are +# considered equal to other NULL values and distinct from all non-NULL +# values. +# +db nullvalue null +do_select_tests e_select-7.9 { + 1 {SELECT NULL UNION ALL SELECT NULL} {null null} + 2 {SELECT NULL UNION SELECT NULL} {null} + 3 {SELECT NULL INTERSECT SELECT NULL} {null} + 4 {SELECT NULL EXCEPT SELECT NULL} {} + + 5 {SELECT NULL UNION ALL SELECT 'ab'} {null ab} + 6 {SELECT NULL UNION SELECT 'ab'} {null ab} + 7 {SELECT NULL INTERSECT SELECT 'ab'} {} + 8 {SELECT NULL EXCEPT SELECT 'ab'} {null} + + 9 {SELECT NULL UNION ALL SELECT 0} {null 0} + 10 {SELECT NULL UNION SELECT 0} {null 0} + 11 {SELECT NULL INTERSECT SELECT 0} {} + 12 {SELECT NULL EXCEPT SELECT 0} {null} + + 13 {SELECT c FROM q1 UNION ALL SELECT g FROM q3} {null -42.47 null 2 2} + 14 {SELECT c FROM q1 UNION SELECT g FROM q3} {null -42.47 2} + 15 {SELECT c FROM q1 INTERSECT SELECT g FROM q3} {} + 16 {SELECT c FROM q1 EXCEPT SELECT g FROM q3} {null -42.47} +} +db nullvalue {} + +# EVIDENCE-OF: R-51232-50224 The collation sequence used to compare two +# text values is determined as if the columns of the left and right-hand +# SELECT statements were the left and right-hand operands of the equals +# (=) operator, except that greater precedence is not assigned to a +# collation sequence specified with the postfix COLLATE operator. +# +drop_all_tables +do_execsql_test e_select-7.10.0 { + CREATE TABLE y1(a COLLATE nocase, b COLLATE binary, c); + INSERT INTO y1 VALUES('Abc', 'abc', 'aBC'); +} {} +do_select_tests e_select-7.10 { + 1 {SELECT 'abc' UNION SELECT 'ABC'} {ABC abc} + 2 {SELECT 'abc' COLLATE nocase UNION SELECT 'ABC'} {ABC} + 3 {SELECT 'abc' UNION SELECT 'ABC' COLLATE nocase} {ABC} + 4 {SELECT 'abc' COLLATE binary UNION SELECT 'ABC' COLLATE nocase} {ABC abc} + 5 {SELECT 'abc' COLLATE nocase UNION SELECT 'ABC' COLLATE binary} {ABC} + + 6 {SELECT a FROM y1 UNION SELECT b FROM y1} {abc} + 7 {SELECT b FROM y1 UNION SELECT a FROM y1} {Abc abc} + 8 {SELECT a FROM y1 UNION SELECT c FROM y1} {aBC} + + 9 {SELECT a FROM y1 UNION SELECT c COLLATE binary FROM y1} {aBC} +} + +# EVIDENCE-OF: R-32706-07403 No affinity transformations are applied to +# any values when comparing rows as part of a compound SELECT. +# +drop_all_tables +do_execsql_test e_select-7.10.0 { + CREATE TABLE w1(a TEXT, b NUMBER); + CREATE TABLE w2(a, b TEXT); + + INSERT INTO w1 VALUES('1', 4.1); + INSERT INTO w2 VALUES(1, 4.1); +} {} + +do_select_tests e_select-7.11 { + 1 { SELECT a FROM w1 UNION SELECT a FROM w2 } {1 1} + 2 { SELECT a FROM w2 UNION SELECT a FROM w1 } {1 1} + 3 { SELECT b FROM w1 UNION SELECT b FROM w2 } {4.1 4.1} + 4 { SELECT b FROM w2 UNION SELECT b FROM w1 } {4.1 4.1} + + 5 { SELECT a FROM w1 INTERSECT SELECT a FROM w2 } {} + 6 { SELECT a FROM w2 INTERSECT SELECT a FROM w1 } {} + 7 { SELECT b FROM w1 INTERSECT SELECT b FROM w2 } {} + 8 { SELECT b FROM w2 INTERSECT SELECT b FROM w1 } {} + + 9 { SELECT a FROM w1 EXCEPT SELECT a FROM w2 } {1} + 10 { SELECT a FROM w2 EXCEPT SELECT a FROM w1 } {1} + 11 { SELECT b FROM w1 EXCEPT SELECT b FROM w2 } {4.1} + 12 { SELECT b FROM w2 EXCEPT SELECT b FROM w1 } {4.1} +} + + +# EVIDENCE-OF: R-32562-20566 When three or more simple SELECTs are +# connected into a compound SELECT, they group from left to right. In +# other words, if "A", "B" and "C" are all simple SELECT statements, (A +# op B op C) is processed as ((A op B) op C). +# +# e_select-7.12.1: Precedence of UNION vs. INTERSECT +# e_select-7.12.2: Precedence of UNION vs. UNION ALL +# e_select-7.12.3: Precedence of UNION vs. EXCEPT +# e_select-7.12.4: Precedence of INTERSECT vs. UNION ALL +# e_select-7.12.5: Precedence of INTERSECT vs. EXCEPT +# e_select-7.12.6: Precedence of UNION ALL vs. EXCEPT +# e_select-7.12.7: Check that "a EXCEPT b EXCEPT c" is processed as +# "(a EXCEPT b) EXCEPT c". +# +# The INTERSECT and EXCEPT operations are mutually commutative. So +# the e_select-7.12.5 test cases do not prove very much. +# +drop_all_tables +do_execsql_test e_select-7.12.0 { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(1); + INSERT INTO t1 VALUES(2); + INSERT INTO t1 VALUES(3); +} {} +foreach {tn select res} { + 1a "(1,2) INTERSECT (1) UNION (3)" {1 3} + 1b "(3) UNION (1,2) INTERSECT (1)" {1} + + 2a "(1,2) UNION (3) UNION ALL (1)" {1 2 3 1} + 2b "(1) UNION ALL (3) UNION (1,2)" {1 2 3} + + 3a "(1,2) UNION (3) EXCEPT (1)" {2 3} + 3b "(1,2) EXCEPT (3) UNION (1)" {1 2} + + 4a "(1,2) INTERSECT (1) UNION ALL (3)" {1 3} + 4b "(3) UNION (1,2) INTERSECT (1)" {1} + + 5a "(1,2) INTERSECT (2) EXCEPT (2)" {} + 5b "(2,3) EXCEPT (2) INTERSECT (2)" {} + + 6a "(2) UNION ALL (2) EXCEPT (2)" {} + 6b "(2) EXCEPT (2) UNION ALL (2)" {2} + + 7 "(2,3) EXCEPT (2) EXCEPT (3)" {} +} { + set select [string map {( {SELECT x FROM t1 WHERE x IN (}} $select] + do_execsql_test e_select-7.12.$tn $select [list {*}$res] +} + + +#------------------------------------------------------------------------- +# ORDER BY clauses +# + +drop_all_tables +do_execsql_test e_select-8.1.0 { + CREATE TABLE d1(x, y, z); + + INSERT INTO d1 VALUES(1, 2, 3); + INSERT INTO d1 VALUES(2, 5, -1); + INSERT INTO d1 VALUES(1, 2, 8); + INSERT INTO d1 VALUES(1, 2, 7); + INSERT INTO d1 VALUES(2, 4, 93); + INSERT INTO d1 VALUES(1, 2, -20); + INSERT INTO d1 VALUES(1, 4, 93); + INSERT INTO d1 VALUES(1, 5, -1); + + CREATE TABLE d2(a, b); + INSERT INTO d2 VALUES('gently', 'failings'); + INSERT INTO d2 VALUES('commercials', 'bathrobe'); + INSERT INTO d2 VALUES('iterate', 'sexton'); + INSERT INTO d2 VALUES('babied', 'charitableness'); + INSERT INTO d2 VALUES('solemnness', 'annexed'); + INSERT INTO d2 VALUES('rejoicing', 'liabilities'); + INSERT INTO d2 VALUES('pragmatist', 'guarded'); + INSERT INTO d2 VALUES('barked', 'interrupted'); + INSERT INTO d2 VALUES('reemphasizes', 'reply'); + INSERT INTO d2 VALUES('lad', 'relenting'); +} {} + +# EVIDENCE-OF: R-44988-41064 Rows are first sorted based on the results +# of evaluating the left-most expression in the ORDER BY list, then ties +# are broken by evaluating the second left-most expression and so on. +# +do_select_tests e_select-8.1 { + 1 "SELECT * FROM d1 ORDER BY x, y, z" { + 1 2 -20 1 2 3 1 2 7 1 2 8 + 1 4 93 1 5 -1 2 4 93 2 5 -1 + } +} + +# EVIDENCE-OF: R-06617-54588 Each ORDER BY expression may be optionally +# followed by one of the keywords ASC (smaller values are returned +# first) or DESC (larger values are returned first). +# +# Test cases e_select-8.2.* test the above. +# +# EVIDENCE-OF: R-18705-33393 If neither ASC or DESC are specified, rows +# are sorted in ascending (smaller values first) order by default. +# +# Test cases e_select-8.3.* test the above. All 8.3 test cases are +# copies of 8.2 test cases with the explicit "ASC" removed. +# +do_select_tests e_select-8 { + 2.1 "SELECT * FROM d1 ORDER BY x ASC, y ASC, z ASC" { + 1 2 -20 1 2 3 1 2 7 1 2 8 + 1 4 93 1 5 -1 2 4 93 2 5 -1 + } + 2.2 "SELECT * FROM d1 ORDER BY x DESC, y DESC, z DESC" { + 2 5 -1 2 4 93 1 5 -1 1 4 93 + 1 2 8 1 2 7 1 2 3 1 2 -20 + } + 2.3 "SELECT * FROM d1 ORDER BY x DESC, y ASC, z DESC" { + 2 4 93 2 5 -1 1 2 8 1 2 7 + 1 2 3 1 2 -20 1 4 93 1 5 -1 + } + 2.4 "SELECT * FROM d1 ORDER BY x DESC, y ASC, z ASC" { + 2 4 93 2 5 -1 1 2 -20 1 2 3 + 1 2 7 1 2 8 1 4 93 1 5 -1 + } + + 3.1 "SELECT * FROM d1 ORDER BY x, y, z" { + 1 2 -20 1 2 3 1 2 7 1 2 8 + 1 4 93 1 5 -1 2 4 93 2 5 -1 + } + 3.3 "SELECT * FROM d1 ORDER BY x DESC, y, z DESC" { + 2 4 93 2 5 -1 1 2 8 1 2 7 + 1 2 3 1 2 -20 1 4 93 1 5 -1 + } + 3.4 "SELECT * FROM d1 ORDER BY x DESC, y, z" { + 2 4 93 2 5 -1 1 2 -20 1 2 3 + 1 2 7 1 2 8 1 4 93 1 5 -1 + } +} + +# EVIDENCE-OF: R-29779-04281 If the ORDER BY expression is a constant +# integer K then the expression is considered an alias for the K-th +# column of the result set (columns are numbered from left to right +# starting with 1). +# +do_select_tests e_select-8.4 { + 1 "SELECT * FROM d1 ORDER BY 1 ASC, 2 ASC, 3 ASC" { + 1 2 -20 1 2 3 1 2 7 1 2 8 + 1 4 93 1 5 -1 2 4 93 2 5 -1 + } + 2 "SELECT * FROM d1 ORDER BY 1 DESC, 2 DESC, 3 DESC" { + 2 5 -1 2 4 93 1 5 -1 1 4 93 + 1 2 8 1 2 7 1 2 3 1 2 -20 + } + 3 "SELECT * FROM d1 ORDER BY 1 DESC, 2 ASC, 3 DESC" { + 2 4 93 2 5 -1 1 2 8 1 2 7 + 1 2 3 1 2 -20 1 4 93 1 5 -1 + } + 4 "SELECT * FROM d1 ORDER BY 1 DESC, 2 ASC, 3 ASC" { + 2 4 93 2 5 -1 1 2 -20 1 2 3 + 1 2 7 1 2 8 1 4 93 1 5 -1 + } + 5 "SELECT * FROM d1 ORDER BY 1, 2, 3" { + 1 2 -20 1 2 3 1 2 7 1 2 8 + 1 4 93 1 5 -1 2 4 93 2 5 -1 + } + 6 "SELECT * FROM d1 ORDER BY 1 DESC, 2, 3 DESC" { + 2 4 93 2 5 -1 1 2 8 1 2 7 + 1 2 3 1 2 -20 1 4 93 1 5 -1 + } + 7 "SELECT * FROM d1 ORDER BY 1 DESC, 2, 3" { + 2 4 93 2 5 -1 1 2 -20 1 2 3 + 1 2 7 1 2 8 1 4 93 1 5 -1 + } + 8 "SELECT z, x FROM d1 ORDER BY 2" { + /# 1 # 1 # 1 # 1 + # 1 # 1 # 2 # 2/ + } + 9 "SELECT z, x FROM d1 ORDER BY 1" { + /-20 1 -1 # -1 # 3 1 + 7 1 8 1 93 # 93 #/ + } +} + +# EVIDENCE-OF: R-63286-51977 If the ORDER BY expression is an identifier +# that corresponds to the alias of one of the output columns, then the +# expression is considered an alias for that column. +# +do_select_tests e_select-8.5 { + 1 "SELECT z+1 AS abc FROM d1 ORDER BY abc" { + -19 0 0 4 8 9 94 94 + } + 2 "SELECT z+1 AS abc FROM d1 ORDER BY abc DESC" { + 94 94 9 8 4 0 0 -19 + } + 3 "SELECT z AS x, x AS z FROM d1 ORDER BY z" { + /# 1 # 1 # 1 # 1 # 1 # 1 # 2 # 2/ + } + 4 "SELECT z AS x, x AS z FROM d1 ORDER BY x" { + /-20 1 -1 # -1 # 3 1 7 1 8 1 93 # 93 #/ + } +} + +# EVIDENCE-OF: R-65068-27207 Otherwise, if the ORDER BY expression is +# any other expression, it is evaluated and the returned value used to +# order the output rows. +# +# EVIDENCE-OF: R-03421-57988 If the SELECT statement is a simple SELECT, +# then an ORDER BY may contain any arbitrary expressions. +# +do_select_tests e_select-8.6 { + 1 "SELECT * FROM d1 ORDER BY x+y+z" { + 1 2 -20 1 5 -1 1 2 3 2 5 -1 + 1 2 7 1 2 8 1 4 93 2 4 93 + } + 2 "SELECT * FROM d1 ORDER BY x*z" { + 1 2 -20 2 5 -1 1 5 -1 1 2 3 + 1 2 7 1 2 8 1 4 93 2 4 93 + } + 3 "SELECT * FROM d1 ORDER BY y*z" { + 1 2 -20 2 5 -1 1 5 -1 1 2 3 + 1 2 7 1 2 8 2 4 93 1 4 93 + } +} + +# EVIDENCE-OF: R-28853-08147 However, if the SELECT is a compound +# SELECT, then ORDER BY expressions that are not aliases to output +# columns must be exactly the same as an expression used as an output +# column. +# +do_select_tests e_select-8.7.1 -error { + %s ORDER BY term does not match any column in the result set +} { + 1 "SELECT x FROM d1 UNION ALL SELECT a FROM d2 ORDER BY x*z" 1st + 2 "SELECT x,z FROM d1 UNION ALL SELECT a,b FROM d2 ORDER BY x, x/z" 2nd +} + +do_select_tests e_select-8.7.2 { + 1 "SELECT x*z FROM d1 UNION ALL SELECT a FROM d2 ORDER BY x*z" { + -20 -2 -1 3 7 8 93 186 babied barked commercials gently + iterate lad pragmatist reemphasizes rejoicing solemnness + } + 2 "SELECT x, x/z FROM d1 UNION ALL SELECT a,b FROM d2 ORDER BY x, x/z" { + 1 -1 1 0 1 0 1 0 1 0 1 0 2 -2 2 0 + babied charitableness barked interrupted commercials bathrobe gently + failings iterate sexton lad relenting pragmatist guarded reemphasizes reply + rejoicing liabilities solemnness annexed + } +} + +do_execsql_test e_select-8.8.0 { + CREATE TABLE d3(a); + INSERT INTO d3 VALUES('text'); + INSERT INTO d3 VALUES(14.1); + INSERT INTO d3 VALUES(13); + INSERT INTO d3 VALUES(X'78787878'); + INSERT INTO d3 VALUES(15); + INSERT INTO d3 VALUES(12.9); + INSERT INTO d3 VALUES(null); + + CREATE TABLE d4(x COLLATE nocase); + INSERT INTO d4 VALUES('abc'); + INSERT INTO d4 VALUES('ghi'); + INSERT INTO d4 VALUES('DEF'); + INSERT INTO d4 VALUES('JKL'); +} {} + +# EVIDENCE-OF: R-10883-17697 For the purposes of sorting rows, values +# are compared in the same way as for comparison expressions. +# +# The following tests verify that values of different types are sorted +# correctly, and that mixed real and integer values are compared properly. +# +do_execsql_test e_select-8.8.1 { + SELECT a FROM d3 ORDER BY a +} {{} 12.9 13 14.1 15 text xxxx} +do_execsql_test e_select-8.8.2 { + SELECT a FROM d3 ORDER BY a DESC +} {xxxx text 15 14.1 13 12.9 {}} + + +# EVIDENCE-OF: R-64199-22471 If the ORDER BY expression is assigned a +# collation sequence using the postfix COLLATE operator, then the +# specified collation sequence is used. +# +do_execsql_test e_select-8.9.1 { + SELECT x FROM d4 ORDER BY 1 COLLATE binary +} {DEF JKL abc ghi} +do_execsql_test e_select-8.9.2 { + SELECT x COLLATE binary FROM d4 ORDER BY 1 COLLATE nocase +} {abc DEF ghi JKL} + +# EVIDENCE-OF: R-09398-26102 Otherwise, if the ORDER BY expression is +# an alias to an expression that has been assigned a collation sequence +# using the postfix COLLATE operator, then the collation sequence +# assigned to the aliased expression is used. +# +# In the test 8.10.2, the only result-column expression has no alias. So the +# ORDER BY expression is not a reference to it and therefore does not inherit +# the collation sequence. In test 8.10.3, "x" is the alias (as well as the +# column name), so the ORDER BY expression is interpreted as an alias and the +# collation sequence attached to the result column is used for sorting. +# +do_execsql_test e_select-8.10.1 { + SELECT x COLLATE binary FROM d4 ORDER BY 1 +} {DEF JKL abc ghi} +do_execsql_test e_select-8.10.2 { + SELECT x COLLATE binary FROM d4 ORDER BY x +} {abc DEF ghi JKL} +do_execsql_test e_select-8.10.3 { + SELECT x COLLATE binary AS x FROM d4 ORDER BY x +} {DEF JKL abc ghi} + +# EVIDENCE-OF: R-27301-09658 Otherwise, if the ORDER BY expression is a +# column or an alias of an expression that is a column, then the default +# collation sequence for the column is used. +# +do_execsql_test e_select-8.11.1 { + SELECT x AS y FROM d4 ORDER BY y +} {abc DEF ghi JKL} +do_execsql_test e_select-8.11.2 { + SELECT x||'' FROM d4 ORDER BY x +} {abc DEF ghi JKL} + +# EVIDENCE-OF: R-49925-55905 Otherwise, the BINARY collation sequence is +# used. +# +do_execsql_test e_select-8.12.1 { + SELECT x FROM d4 ORDER BY x||'' +} {DEF JKL abc ghi} + +# EVIDENCE-OF: R-44130-32593 If an ORDER BY expression is not an integer +# alias, then SQLite searches the left-most SELECT in the compound for a +# result column that matches either the second or third rules above. If +# a match is found, the search stops and the expression is handled as an +# alias for the result column that it has been matched against. +# Otherwise, the next SELECT to the right is tried, and so on. +# +do_execsql_test e_select-8.13.0 { + CREATE TABLE d5(a, b); + CREATE TABLE d6(c, d); + CREATE TABLE d7(e, f); + + INSERT INTO d5 VALUES(1, 'f'); + INSERT INTO d6 VALUES(2, 'e'); + INSERT INTO d7 VALUES(3, 'd'); + INSERT INTO d5 VALUES(4, 'c'); + INSERT INTO d6 VALUES(5, 'b'); + INSERT INTO d7 VALUES(6, 'a'); + + CREATE TABLE d8(x COLLATE nocase); + CREATE TABLE d9(y COLLATE nocase); + + INSERT INTO d8 VALUES('a'); + INSERT INTO d9 VALUES('B'); + INSERT INTO d8 VALUES('c'); + INSERT INTO d9 VALUES('D'); +} {} +do_select_tests e_select-8.13 { + 1 { SELECT a FROM d5 UNION ALL SELECT c FROM d6 UNION ALL SELECT e FROM d7 + ORDER BY a + } {1 2 3 4 5 6} + 2 { SELECT a FROM d5 UNION ALL SELECT c FROM d6 UNION ALL SELECT e FROM d7 + ORDER BY c + } {1 2 3 4 5 6} + 3 { SELECT a FROM d5 UNION ALL SELECT c FROM d6 UNION ALL SELECT e FROM d7 + ORDER BY e + } {1 2 3 4 5 6} + 4 { SELECT a FROM d5 UNION ALL SELECT c FROM d6 UNION ALL SELECT e FROM d7 + ORDER BY 1 + } {1 2 3 4 5 6} + + 5 { SELECT a, b FROM d5 UNION ALL SELECT b, a FROM d5 ORDER BY b } + {f 1 c 4 4 c 1 f} + 6 { SELECT a, b FROM d5 UNION ALL SELECT b, a FROM d5 ORDER BY 2 } + {f 1 c 4 4 c 1 f} + + 7 { SELECT a, b FROM d5 UNION ALL SELECT b, a FROM d5 ORDER BY a } + {1 f 4 c c 4 f 1} + 8 { SELECT a, b FROM d5 UNION ALL SELECT b, a FROM d5 ORDER BY 1 } + {1 f 4 c c 4 f 1} + + 9 { SELECT a, b FROM d5 UNION ALL SELECT b, a+1 FROM d5 ORDER BY a+1 } + {f 2 c 5 4 c 1 f} + 10 { SELECT a, b FROM d5 UNION ALL SELECT b, a+1 FROM d5 ORDER BY 2 } + {f 2 c 5 4 c 1 f} + + 11 { SELECT a+1, b FROM d5 UNION ALL SELECT b, a+1 FROM d5 ORDER BY a+1 } + {2 f 5 c c 5 f 2} + 12 { SELECT a+1, b FROM d5 UNION ALL SELECT b, a+1 FROM d5 ORDER BY 1 } + {2 f 5 c c 5 f 2} +} + +# EVIDENCE-OF: R-39265-04070 If no matching expression can be found in +# the result columns of any constituent SELECT, it is an error. +# +do_select_tests e_select-8.14 -error { + %s ORDER BY term does not match any column in the result set +} { + 1 { SELECT a FROM d5 UNION SELECT c FROM d6 ORDER BY a+1 } 1st + 2 { SELECT a FROM d5 UNION SELECT c FROM d6 ORDER BY a, a+1 } 2nd + 3 { SELECT * FROM d5 INTERSECT SELECT * FROM d6 ORDER BY 'hello' } 1st + 4 { SELECT * FROM d5 INTERSECT SELECT * FROM d6 ORDER BY blah } 1st + 5 { SELECT * FROM d5 INTERSECT SELECT * FROM d6 ORDER BY c,d,c+d } 3rd + 6 { SELECT * FROM d5 EXCEPT SELECT * FROM d7 ORDER BY 1,2,b,a/b } 4th +} + +# EVIDENCE-OF: R-03407-11483 Each term of the ORDER BY clause is +# processed separately and may be matched against result columns from +# different SELECT statements in the compound. +# +do_select_tests e_select-8.15 { + 1 { SELECT a, b FROM d5 UNION ALL SELECT c-1, d FROM d6 ORDER BY a, d } + {1 e 1 f 4 b 4 c} + 2 { SELECT a, b FROM d5 UNION ALL SELECT c-1, d FROM d6 ORDER BY c-1, b } + {1 e 1 f 4 b 4 c} + 3 { SELECT a, b FROM d5 UNION ALL SELECT c-1, d FROM d6 ORDER BY 1, 2 } + {1 e 1 f 4 b 4 c} +} + + +#------------------------------------------------------------------------- +# Tests related to statements made about the LIMIT/OFFSET clause. +# +do_execsql_test e_select-9.0 { + CREATE TABLE f1(a, b); + INSERT INTO f1 VALUES(26, 'z'); + INSERT INTO f1 VALUES(25, 'y'); + INSERT INTO f1 VALUES(24, 'x'); + INSERT INTO f1 VALUES(23, 'w'); + INSERT INTO f1 VALUES(22, 'v'); + INSERT INTO f1 VALUES(21, 'u'); + INSERT INTO f1 VALUES(20, 't'); + INSERT INTO f1 VALUES(19, 's'); + INSERT INTO f1 VALUES(18, 'r'); + INSERT INTO f1 VALUES(17, 'q'); + INSERT INTO f1 VALUES(16, 'p'); + INSERT INTO f1 VALUES(15, 'o'); + INSERT INTO f1 VALUES(14, 'n'); + INSERT INTO f1 VALUES(13, 'm'); + INSERT INTO f1 VALUES(12, 'l'); + INSERT INTO f1 VALUES(11, 'k'); + INSERT INTO f1 VALUES(10, 'j'); + INSERT INTO f1 VALUES(9, 'i'); + INSERT INTO f1 VALUES(8, 'h'); + INSERT INTO f1 VALUES(7, 'g'); + INSERT INTO f1 VALUES(6, 'f'); + INSERT INTO f1 VALUES(5, 'e'); + INSERT INTO f1 VALUES(4, 'd'); + INSERT INTO f1 VALUES(3, 'c'); + INSERT INTO f1 VALUES(2, 'b'); + INSERT INTO f1 VALUES(1, 'a'); +} {} + +# EVIDENCE-OF: R-30481-56627 Any scalar expression may be used in the +# LIMIT clause, so long as it evaluates to an integer or a value that +# can be losslessly converted to an integer. +# +do_select_tests e_select-9.1 { + 1 { SELECT b FROM f1 ORDER BY a LIMIT 5 } {a b c d e} + 2 { SELECT b FROM f1 ORDER BY a LIMIT 2+3 } {a b c d e} + 3 { SELECT b FROM f1 ORDER BY a LIMIT (SELECT a FROM f1 WHERE b = 'e') } + {a b c d e} + 4 { SELECT b FROM f1 ORDER BY a LIMIT 5.0 } {a b c d e} + 5 { SELECT b FROM f1 ORDER BY a LIMIT '5' } {a b c d e} +} + +# EVIDENCE-OF: R-46155-47219 If the expression evaluates to a NULL value +# or any other value that cannot be losslessly converted to an integer, +# an error is returned. +# + +do_select_tests e_select-9.2 -error "datatype mismatch" { + 1 { SELECT b FROM f1 ORDER BY a LIMIT 'hello' } {} + 2 { SELECT b FROM f1 ORDER BY a LIMIT NULL } {} + 3 { SELECT b FROM f1 ORDER BY a LIMIT X'ABCD' } {} + 4 { SELECT b FROM f1 ORDER BY a LIMIT 5.1 } {} + 5 { SELECT b FROM f1 ORDER BY a LIMIT (SELECT group_concat(b) FROM f1) } {} +} + +# EVIDENCE-OF: R-03014-26414 If the LIMIT expression evaluates to a +# negative value, then there is no upper bound on the number of rows +# returned. +# +do_select_tests e_select-9.4 { + 1 { SELECT b FROM f1 ORDER BY a LIMIT -1 } + {a b c d e f g h i j k l m n o p q r s t u v w x y z} + 2 { SELECT b FROM f1 ORDER BY a LIMIT length('abc')-100 } + {a b c d e f g h i j k l m n o p q r s t u v w x y z} + 3 { SELECT b FROM f1 ORDER BY a LIMIT (SELECT count(*) FROM f1)/2 - 14 } + {a b c d e f g h i j k l m n o p q r s t u v w x y z} +} + +# EVIDENCE-OF: R-33750-29536 Otherwise, the SELECT returns the first N +# rows of its result set only, where N is the value that the LIMIT +# expression evaluates to. +# +do_select_tests e_select-9.5 { + 1 { SELECT b FROM f1 ORDER BY a LIMIT 0 } {} + 2 { SELECT b FROM f1 ORDER BY a DESC LIMIT 4 } {z y x w} + 3 { SELECT b FROM f1 ORDER BY a DESC LIMIT 8 } {z y x w v u t s} + 4 { SELECT b FROM f1 ORDER BY a DESC LIMIT '12.0' } {z y x w v u t s r q p o} +} + +# EVIDENCE-OF: R-54935-19057 Or, if the SELECT statement would return +# less than N rows without a LIMIT clause, then the entire result set is +# returned. +# +do_select_tests e_select-9.6 { + 1 { SELECT b FROM f1 WHERE a>21 ORDER BY a LIMIT 10 } {v w x y z} + 2 { SELECT count(*) FROM f1 GROUP BY a/5 ORDER BY 1 LIMIT 10 } {2 4 5 5 5 5} +} + + +# EVIDENCE-OF: R-24188-24349 The expression attached to the optional +# OFFSET clause that may follow a LIMIT clause must also evaluate to an +# integer, or a value that can be losslessly converted to an integer. +# +foreach {tn select} { + 1 { SELECT b FROM f1 ORDER BY a LIMIT 2 OFFSET 'hello' } + 2 { SELECT b FROM f1 ORDER BY a LIMIT 2 OFFSET NULL } + 3 { SELECT b FROM f1 ORDER BY a LIMIT 2 OFFSET X'ABCD' } + 4 { SELECT b FROM f1 ORDER BY a LIMIT 2 OFFSET 5.1 } + 5 { SELECT b FROM f1 ORDER BY a + LIMIT 2 OFFSET (SELECT group_concat(b) FROM f1) + } +} { + do_catchsql_test e_select-9.7.$tn $select {1 {datatype mismatch}} +} + +# EVIDENCE-OF: R-20467-43422 If an expression has an OFFSET clause, then +# the first M rows are omitted from the result set returned by the +# SELECT statement and the next N rows are returned, where M and N are +# the values that the OFFSET and LIMIT clauses evaluate to, +# respectively. +# +do_select_tests e_select-9.8 { + 1 { SELECT b FROM f1 ORDER BY a LIMIT 10 OFFSET 5} {f g h i j k l m n o} + 2 { SELECT b FROM f1 ORDER BY a LIMIT 2+3 OFFSET 10} {k l m n o} + 3 { SELECT b FROM f1 ORDER BY a + LIMIT (SELECT a FROM f1 WHERE b='j') + OFFSET (SELECT a FROM f1 WHERE b='b') + } {c d e f g h i j k l} + 4 { SELECT b FROM f1 ORDER BY a LIMIT '5' OFFSET 3.0 } {d e f g h} + 5 { SELECT b FROM f1 ORDER BY a LIMIT '5' OFFSET 0 } {a b c d e} + 6 { SELECT b FROM f1 ORDER BY a LIMIT 0 OFFSET 10 } {} + 7 { SELECT b FROM f1 ORDER BY a LIMIT 3 OFFSET '1'||'5' } {p q r} +} + +# EVIDENCE-OF: R-34648-44875 Or, if the SELECT would return less than +# M+N rows if it did not have a LIMIT clause, then the first M rows are +# skipped and the remaining rows (if any) are returned. +# +do_select_tests e_select-9.9 { + 1 { SELECT b FROM f1 ORDER BY a LIMIT 10 OFFSET 20} {u v w x y z} + 2 { SELECT a FROM f1 ORDER BY a DESC LIMIT 100 OFFSET 18+4} {4 3 2 1} +} + + +# EVIDENCE-OF: R-23293-62447 If the OFFSET clause evaluates to a +# negative value, the results are the same as if it had evaluated to +# zero. +# +do_select_tests e_select-9.10 { + 1 { SELECT b FROM f1 ORDER BY a LIMIT 5 OFFSET -1 } {a b c d e} + 2 { SELECT b FROM f1 ORDER BY a LIMIT 5 OFFSET -500 } {a b c d e} + 3 { SELECT b FROM f1 ORDER BY a LIMIT 5 OFFSET 0 } {a b c d e} +} + +# EVIDENCE-OF: R-19509-40356 Instead of a separate OFFSET clause, the +# LIMIT clause may specify two scalar expressions separated by a comma. +# +# EVIDENCE-OF: R-33788-46243 In this case, the first expression is used +# as the OFFSET expression and the second as the LIMIT expression. +# +do_select_tests e_select-9.11 { + 1 { SELECT b FROM f1 ORDER BY a LIMIT 5, 10 } {f g h i j k l m n o} + 2 { SELECT b FROM f1 ORDER BY a LIMIT 10, 2+3 } {k l m n o} + 3 { SELECT b FROM f1 ORDER BY a + LIMIT (SELECT a FROM f1 WHERE b='b'), (SELECT a FROM f1 WHERE b='j') + } {c d e f g h i j k l} + 4 { SELECT b FROM f1 ORDER BY a LIMIT 3.0, '5' } {d e f g h} + 5 { SELECT b FROM f1 ORDER BY a LIMIT 0, '5' } {a b c d e} + 6 { SELECT b FROM f1 ORDER BY a LIMIT 10, 0 } {} + 7 { SELECT b FROM f1 ORDER BY a LIMIT '1'||'5', 3 } {p q r} + + 8 { SELECT b FROM f1 ORDER BY a LIMIT 20, 10 } {u v w x y z} + 9 { SELECT a FROM f1 ORDER BY a DESC LIMIT 18+4, 100 } {4 3 2 1} + + 10 { SELECT b FROM f1 ORDER BY a LIMIT -1, 5 } {a b c d e} + 11 { SELECT b FROM f1 ORDER BY a LIMIT -500, 5 } {a b c d e} + 12 { SELECT b FROM f1 ORDER BY a LIMIT 0, 5 } {a b c d e} +} + +finish_test diff --git a/test/e_select2.test b/test/e_select2.test new file mode 100644 index 0000000..8330894 --- /dev/null +++ b/test/e_select2.test @@ -0,0 +1,580 @@ +# 2010 September 24 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file implements tests to verify that the "testable statements" in +# the lang_select.html document are correct. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +#------------------------------------------------------------------------- +# te_* commands: +# +# +# te_read_sql DB SELECT-STATEMENT +# te_read_tbl DB TABLENAME +# +# These two commands are used to read a dataset from the database. A dataset +# consists of N rows of M named columns of values each, where each value has a +# type (null, integer, real, text or blob) and a value within the types domain. +# The tcl format for a "dataset" is a list of two elements: +# +# * A list of the column names. +# * A list of data rows. Each row is itself a list, where each element is +# the contents of a column of the row. Each of these is a list of two +# elements, the type name and the actual value. +# +# For example, the contents of table [t1] as a dataset is: +# +# CREATE TABLE t1(a, b); +# INSERT INTO t1 VALUES('abc', NULL); +# INSERT INTO t1 VALUES(43.1, 22); +# +# {a b} {{{TEXT abc} {NULL {}}} {{REAL 43.1} {INTEGER 22}}} +# +# The [te_read_tbl] command returns a dataset read from a table. The +# [te_read_sql] returns the dataset that results from executing a SELECT +# command. +# +# +# te_tbljoin ?SWITCHES? LHS-TABLE RHS-TABLE +# te_join ?SWITCHES? LHS-DATASET RHS-DATASET +# +# This command joins the two datasets and returns the resulting dataset. If +# there are no switches specified, then the results is the cartesian product +# of the two inputs. The [te_tbljoin] command reads the left and right-hand +# datasets from the specified tables. The [te_join] command is passed the +# datasets directly. +# +# Optional switches are as follows: +# +# -on SCRIPT +# -using COLUMN-LIST +# -left +# +# The -on option specifies a tcl script that is executed for each row in the +# cartesian product of the two datasets. The script has 4 arguments appended +# to it, in the following order: +# +# * The list of column-names from the left-hand dataset. +# * A single row from the left-hand dataset (one "data row" list as +# described above. +# * The list of column-names from the right-hand dataset. +# * A single row from the right-hand dataset. +# +# The script must return a boolean value - true if the combination of rows +# should be included in the output dataset, or false otherwise. +# +# The -using option specifies a list of the columns from the right-hand +# dataset that should be omitted from the output dataset. +# +# If the -left option is present, the join is done LEFT JOIN style. +# Specifically, an extra row is inserted if after the -on script is run there +# exist rows in the left-hand dataset that have no corresponding rows in +# the output. See the implementation for more specific comments. +# +# +# te_equals ?SWITCHES? COLNAME1 COLNAME2 <-on script args> +# +# The only supported switch is "-nocase". If it is present, then text values +# are compared in a case-independent fashion. Otherwise, they are compared +# as if using the SQLite BINARY collation sequence. +# +# +# te_and ONSCRIPT1 ONSCRIPT2... +# +# + + +# +# te_read_tbl DB TABLENAME +# te_read_sql DB SELECT-STATEMENT +# +# These two procs are used to extract datasets from the database, either +# by reading the contents of a named table (te_read_tbl), or by executing +# a SELECT statement (t3_read_sql). +# +# See the comment above, describing "te_* commands", for details of the +# return values. +# +proc te_read_tbl {db tbl} { + te_read_sql $db "SELECT * FROM '$tbl'" +} +proc te_read_sql {db sql} { + set S [sqlite3_prepare_v2 $db $sql -1 DUMMY] + + set cols [list] + for {set i 0} {$i < [sqlite3_column_count $S]} {incr i} { + lappend cols [sqlite3_column_name $S $i] + } + + set rows [list] + while {[sqlite3_step $S] == "SQLITE_ROW"} { + set r [list] + for {set i 0} {$i < [sqlite3_column_count $S]} {incr i} { + lappend r [list [sqlite3_column_type $S $i] [sqlite3_column_text $S $i]] + } + lappend rows $r + } + sqlite3_finalize $S + + return [list $cols $rows] +} + +#------- +# Usage: te_join ... +# +# Where a join-spec is an optional list of arguments as follows: +# +# ?-left? +# ?-using colname-list? +# ?-on on-expr-proc? +# +proc te_join {data1 data2 args} { + + set testproc "" + set usinglist [list] + set isleft 0 + for {set i 0} {$i < [llength $args]} {incr i} { + set a [lindex $args $i] + switch -- $a { + -on { set testproc [lindex $args [incr i]] } + -using { set usinglist [lindex $args [incr i]] } + -left { set isleft 1 } + default { + error "Unknown argument: $a" + } + } + } + + set c1 [lindex $data1 0] + set c2 [lindex $data2 0] + set omitlist [list] + set nullrowlist [list] + set cret $c1 + + set cidx 0 + foreach col $c2 { + set idx [lsearch $usinglist $col] + if {$idx>=0} {lappend omitlist $cidx} + if {$idx<0} { + lappend nullrowlist {NULL {}} + lappend cret $col + } + incr cidx + } + set omitlist [lsort -integer -decreasing $omitlist] + + + set rret [list] + foreach r1 [lindex $data1 1] { + set one 0 + foreach r2 [lindex $data2 1] { + set ok 1 + if {$testproc != ""} { + set ok [eval $testproc [list $c1 $r1 $c2 $r2]] + } + if {$ok} { + set one 1 + foreach idx $omitlist {set r2 [lreplace $r2 $idx $idx]} + lappend rret [concat $r1 $r2] + } + } + + if {$isleft && $one==0} { + lappend rret [concat $r1 $nullrowlist] + } + } + + list $cret $rret +} + +proc te_tbljoin {db t1 t2 args} { + te_join [te_read_tbl $db $t1] [te_read_tbl $db $t2] {*}$args +} + +proc te_apply_affinity {affinity typevar valvar} { + upvar $typevar type + upvar $valvar val + + switch -- $affinity { + integer { + if {[string is double $val]} { set type REAL } + if {[string is wideinteger $val]} { set type INTEGER } + if {$type == "REAL" && int($val)==$val} { + set type INTEGER + set val [expr {int($val)}] + } + } + text { + set type TEXT + } + none { } + + default { error "invalid affinity: $affinity" } + } +} + +#---------- +# te_equals ?SWITCHES? c1 c2 cols1 row1 cols2 row2 +# +proc te_equals {args} { + + if {[llength $args]<6} {error "invalid arguments to te_equals"} + foreach {c1 c2 cols1 row1 cols2 row2} [lrange $args end-5 end] break + + set nocase 0 + set affinity none + + for {set i 0} {$i < ([llength $args]-6)} {incr i} { + set a [lindex $args $i] + switch -- $a { + -nocase { + set nocase 1 + } + -affinity { + set affinity [string tolower [lindex $args [incr i]]] + } + default { + error "invalid arguments to te_equals" + } + } + } + + set idx2 [if {[string is integer $c2]} { set c2 } else { lsearch $cols2 $c2 }] + set idx1 [if {[string is integer $c1]} { set c1 } else { lsearch $cols1 $c1 }] + + set t1 [lindex $row1 $idx1 0] + set t2 [lindex $row2 $idx2 0] + set v1 [lindex $row1 $idx1 1] + set v2 [lindex $row2 $idx2 1] + + te_apply_affinity $affinity t1 v1 + te_apply_affinity $affinity t2 v2 + + if {$t1 == "NULL" || $t2 == "NULL"} { return 0 } + if {$nocase && $t1 == "TEXT"} { set v1 [string tolower $v1] } + if {$nocase && $t2 == "TEXT"} { set v2 [string tolower $v2] } + + + set res [expr {$t1 == $t2 && [string equal $v1 $v2]}] + return $res +} + +proc te_false {args} { return 0 } +proc te_true {args} { return 1 } + +proc te_and {args} { + foreach a [lrange $args 0 end-4] { + set res [eval $a [lrange $args end-3 end]] + if {$res == 0} {return 0} + } + return 1 +} + + +proc te_dataset_eq {testname got expected} { + uplevel #0 [list do_test $testname [list set {} $got] $expected] +} +proc te_dataset_eq_unordered {testname got expected} { + lset got 1 [lsort [lindex $got 1]] + lset expected 1 [lsort [lindex $expected 1]] + te_dataset_eq $testname $got $expected +} + +proc te_dataset_ne {testname got unexpected} { + uplevel #0 [list do_test $testname [list string equal $got $unexpected] 0] +} +proc te_dataset_ne_unordered {testname got unexpected} { + lset got 1 [lsort [lindex $got 1]] + lset unexpected 1 [lsort [lindex $unexpected 1]] + te_dataset_ne $testname $got $unexpected +} + + +#------------------------------------------------------------------------- +# +proc test_join {tn sqljoin tbljoinargs} { + set sql [te_read_sql db "SELECT * FROM $sqljoin"] + set te [te_tbljoin db {*}$tbljoinargs] + te_dataset_eq_unordered $tn $sql $te +} + +drop_all_tables +do_execsql_test e_select-2.0 { + CREATE TABLE t1(a, b); + CREATE TABLE t2(a, b); + CREATE TABLE t3(b COLLATE nocase); + + INSERT INTO t1 VALUES(2, 'B'); + INSERT INTO t1 VALUES(1, 'A'); + INSERT INTO t1 VALUES(4, 'D'); + INSERT INTO t1 VALUES(NULL, NULL); + INSERT INTO t1 VALUES(3, NULL); + + INSERT INTO t2 VALUES(1, 'A'); + INSERT INTO t2 VALUES(2, NULL); + INSERT INTO t2 VALUES(5, 'E'); + INSERT INTO t2 VALUES(NULL, NULL); + INSERT INTO t2 VALUES(3, 'C'); + + INSERT INTO t3 VALUES('a'); + INSERT INTO t3 VALUES('c'); + INSERT INTO t3 VALUES('b'); +} {} + +foreach {tn indexes} { + e_select-2.1.1 { } + e_select-2.1.2 { CREATE INDEX i1 ON t1(a) } + e_select-2.1.3 { CREATE INDEX i1 ON t2(a) } + e_select-2.1.4 { CREATE INDEX i1 ON t3(b) } +} { + + catchsql { DROP INDEX i1 } + catchsql { DROP INDEX i2 } + catchsql { DROP INDEX i3 } + execsql $indexes + + # EVIDENCE-OF: R-49872-03192 If the join-operator is "CROSS JOIN", + # "INNER JOIN", "JOIN" or a comma (",") and there is no ON or USING + # clause, then the result of the join is simply the cartesian product of + # the left and right-hand datasets. + # + # EVIDENCE-OF: R-46256-57243 There is no difference between the "INNER + # JOIN", "JOIN" and "," join operators. + # + # EVIDENCE-OF: R-25071-21202 The "CROSS JOIN" join operator produces the + # same result as the "INNER JOIN", "JOIN" and "," operators + # + test_join $tn.1.1 "t1, t2" {t1 t2} + test_join $tn.1.2 "t1 INNER JOIN t2" {t1 t2} + test_join $tn.1.3 "t1 CROSS JOIN t2" {t1 t2} + test_join $tn.1.4 "t1 JOIN t2" {t1 t2} + test_join $tn.1.5 "t2, t3" {t2 t3} + test_join $tn.1.6 "t2 INNER JOIN t3" {t2 t3} + test_join $tn.1.7 "t2 CROSS JOIN t3" {t2 t3} + test_join $tn.1.8 "t2 JOIN t3" {t2 t3} + test_join $tn.1.9 "t2, t2 AS x" {t2 t2} + test_join $tn.1.10 "t2 INNER JOIN t2 AS x" {t2 t2} + test_join $tn.1.11 "t2 CROSS JOIN t2 AS x" {t2 t2} + test_join $tn.1.12 "t2 JOIN t2 AS x" {t2 t2} + + # EVIDENCE-OF: R-38465-03616 If there is an ON clause then the ON + # expression is evaluated for each row of the cartesian product as a + # boolean expression. Only rows for which the expression evaluates to + # true are included from the dataset. + # + test_join $tn.2.1 "t1, t2 ON (t1.a=t2.a)" {t1 t2 -on {te_equals a a}} + test_join $tn.2.2 "t2, t1 ON (t1.a=t2.a)" {t2 t1 -on {te_equals a a}} + test_join $tn.2.3 "t2, t1 ON (1)" {t2 t1 -on te_true} + test_join $tn.2.4 "t2, t1 ON (NULL)" {t2 t1 -on te_false} + test_join $tn.2.5 "t2, t1 ON (1.1-1.1)" {t2 t1 -on te_false} + test_join $tn.2.6 "t1, t2 ON (1.1-1.0)" {t1 t2 -on te_true} + + + test_join $tn.3 "t1 LEFT JOIN t2 ON (t1.a=t2.a)" {t1 t2 -left -on {te_equals a a}} + test_join $tn.4 "t1 LEFT JOIN t2 USING (a)" { + t1 t2 -left -using a -on {te_equals a a} + } + test_join $tn.5 "t1 CROSS JOIN t2 USING(b, a)" { + t1 t2 -using {a b} -on {te_and {te_equals a a} {te_equals b b}} + } + test_join $tn.6 "t1 NATURAL JOIN t2" { + t1 t2 -using {a b} -on {te_and {te_equals a a} {te_equals b b}} + } + test_join $tn.7 "t1 NATURAL INNER JOIN t2" { + t1 t2 -using {a b} -on {te_and {te_equals a a} {te_equals b b}} + } + test_join $tn.8 "t1 NATURAL CROSS JOIN t2" { + t1 t2 -using {a b} -on {te_and {te_equals a a} {te_equals b b}} + } + test_join $tn.9 "t1 NATURAL INNER JOIN t2" { + t1 t2 -using {a b} -on {te_and {te_equals a a} {te_equals b b}} + } + test_join $tn.10 "t1 NATURAL LEFT JOIN t2" { + t1 t2 -left -using {a b} -on {te_and {te_equals a a} {te_equals b b}} + } + test_join $tn.11 "t1 NATURAL LEFT OUTER JOIN t2" { + t1 t2 -left -using {a b} -on {te_and {te_equals a a} {te_equals b b}} + } + test_join $tn.12 "t2 NATURAL JOIN t1" { + t2 t1 -using {a b} -on {te_and {te_equals a a} {te_equals b b}} + } + test_join $tn.13 "t2 NATURAL INNER JOIN t1" { + t2 t1 -using {a b} -on {te_and {te_equals a a} {te_equals b b}} + } + test_join $tn.14 "t2 NATURAL CROSS JOIN t1" { + t2 t1 -using {a b} -on {te_and {te_equals a a} {te_equals b b}} + } + test_join $tn.15 "t2 NATURAL INNER JOIN t1" { + t2 t1 -using {a b} -on {te_and {te_equals a a} {te_equals b b}} + } + test_join $tn.16 "t2 NATURAL LEFT JOIN t1" { + t2 t1 -left -using {a b} -on {te_and {te_equals a a} {te_equals b b}} + } + test_join $tn.17 "t2 NATURAL LEFT OUTER JOIN t1" { + t2 t1 -left -using {a b} -on {te_and {te_equals a a} {te_equals b b}} + } + test_join $tn.18 "t1 LEFT JOIN t2 USING (b)" { + t1 t2 -left -using b -on {te_equals b b} + } + test_join $tn.19 "t1 JOIN t3 USING(b)" {t1 t3 -using b -on {te_equals b b}} + test_join $tn.20 "t3 JOIN t1 USING(b)" { + t3 t1 -using b -on {te_equals -nocase b b} + } + test_join $tn.21 "t1 NATURAL JOIN t3" { + t1 t3 -using b -on {te_equals b b} + } + test_join $tn.22 "t3 NATURAL JOIN t1" { + t3 t1 -using b -on {te_equals -nocase b b} + } + test_join $tn.23 "t1 NATURAL LEFT JOIN t3" { + t1 t3 -left -using b -on {te_equals b b} + } + test_join $tn.24 "t3 NATURAL LEFT JOIN t1" { + t3 t1 -left -using b -on {te_equals -nocase b b} + } + test_join $tn.25 "t1 LEFT JOIN t3 ON (t3.b=t1.b)" { + t1 t3 -left -on {te_equals -nocase b b} + } + test_join $tn.26 "t1 LEFT JOIN t3 ON (t1.b=t3.b)" { + t1 t3 -left -on {te_equals b b} + } + test_join $tn.27 "t1 JOIN t3 ON (t1.b=t3.b)" { t1 t3 -on {te_equals b b} } + + # EVIDENCE-OF: R-28760-53843 When more than two tables are joined + # together as part of a FROM clause, the join operations are processed + # in order from left to right. In other words, the FROM clause (A + # join-op-1 B join-op-2 C) is computed as ((A join-op-1 B) join-op-2 C). + # + # Tests 28a and 28b show that the statement above is true for this case. + # Test 28c shows that if the parenthesis force a different order of + # evaluation the result is different. Test 28d verifies that the result + # of the query with the parenthesis forcing a different order of evaluation + # is as calculated by the [te_*] procs. + # + set t3_natural_left_join_t2 [ + te_tbljoin db t3 t2 -left -using {b} -on {te_equals -nocase b b} + ] + set t1 [te_read_tbl db t1] + te_dataset_eq_unordered $tn.28a [ + te_read_sql db "SELECT * FROM t3 NATURAL LEFT JOIN t2 NATURAL JOIN t1" + ] [te_join $t3_natural_left_join_t2 $t1 \ + -using {a b} -on {te_and {te_equals a a} {te_equals -nocase b b}} \ + ] + + te_dataset_eq_unordered $tn.28b [ + te_read_sql db "SELECT * FROM (t3 NATURAL LEFT JOIN t2) NATURAL JOIN t1" + ] [te_join $t3_natural_left_join_t2 $t1 \ + -using {a b} -on {te_and {te_equals a a} {te_equals -nocase b b}} \ + ] + + te_dataset_ne_unordered $tn.28c [ + te_read_sql db "SELECT * FROM (t3 NATURAL LEFT JOIN t2) NATURAL JOIN t1" + ] [ + te_read_sql db "SELECT * FROM t3 NATURAL LEFT JOIN (t2 NATURAL JOIN t1)" + ] + + set t2_natural_join_t1 [te_tbljoin db t2 t1 -using {a b} \ + -using {a b} -on {te_and {te_equals a a} {te_equals -nocase b b}} \ + ] + set t3 [te_read_tbl db t3] + te_dataset_eq_unordered $tn.28d [ + te_read_sql db "SELECT * FROM t3 NATURAL LEFT JOIN (t2 NATURAL JOIN t1)" + ] [te_join $t3 $t2_natural_join_t1 \ + -left -using {b} -on {te_equals -nocase b b} \ + ] +} + +do_execsql_test e_select-2.2.0 { + CREATE TABLE t4(x TEXT COLLATE nocase); + CREATE TABLE t5(y INTEGER, z TEXT COLLATE binary); + + INSERT INTO t4 VALUES('2.0'); + INSERT INTO t4 VALUES('TWO'); + INSERT INTO t5 VALUES(2, 'two'); +} {} + +# EVIDENCE-OF: R-59237-46742 A subquery specified in the +# table-or-subquery following the FROM clause in a simple SELECT +# statement is handled as if it was a table containing the data returned +# by executing the subquery statement. +# +# EVIDENCE-OF: R-27438-53558 Each column of the subquery has the +# collation sequence and affinity of the corresponding expression in the +# subquery statement. +# +foreach {tn subselect select spec} { + 1 "SELECT * FROM t2" "SELECT * FROM t1 JOIN %ss%" + {t1 %ss%} + + 2 "SELECT * FROM t2" "SELECT * FROM t1 JOIN %ss% AS x ON (t1.a=x.a)" + {t1 %ss% -on {te_equals 0 0}} + + 3 "SELECT * FROM t2" "SELECT * FROM %ss% AS x JOIN t1 ON (t1.a=x.a)" + {%ss% t1 -on {te_equals 0 0}} + + 4 "SELECT * FROM t1, t2" "SELECT * FROM %ss% AS x JOIN t3" + {%ss% t3} + + 5 "SELECT * FROM t1, t2" "SELECT * FROM %ss% NATURAL JOIN t3" + {%ss% t3 -using b -on {te_equals 1 0}} + + 6 "SELECT * FROM t1, t2" "SELECT * FROM t3 NATURAL JOIN %ss%" + {t3 %ss% -using b -on {te_equals -nocase 0 1}} + + 7 "SELECT * FROM t1, t2" "SELECT * FROM t3 NATURAL LEFT JOIN %ss%" + {t3 %ss% -left -using b -on {te_equals -nocase 0 1}} + + 8 "SELECT count(*) AS y FROM t4" "SELECT * FROM t5, %ss% USING (y)" + {t5 %ss% -using y -on {te_equals -affinity text 0 0}} + + 9 "SELECT count(*) AS y FROM t4" "SELECT * FROM %ss%, t5 USING (y)" + {%ss% t5 -using y -on {te_equals -affinity text 0 0}} + + 10 "SELECT x AS y FROM t4" "SELECT * FROM %ss% JOIN t5 USING (y)" + {%ss% t5 -using y -on {te_equals -nocase -affinity integer 0 0}} + + 11 "SELECT x AS y FROM t4" "SELECT * FROM t5 JOIN %ss% USING (y)" + {t5 %ss% -using y -on {te_equals -nocase -affinity integer 0 0}} + + 12 "SELECT y AS x FROM t5" "SELECT * FROM %ss% JOIN t4 USING (x)" + {%ss% t4 -using x -on {te_equals -nocase -affinity integer 0 0}} + + 13 "SELECT y AS x FROM t5" "SELECT * FROM t4 JOIN %ss% USING (x)" + {t4 %ss% -using x -on {te_equals -nocase -affinity integer 0 0}} + + 14 "SELECT +y AS x FROM t5" "SELECT * FROM %ss% JOIN t4 USING (x)" + {%ss% t4 -using x -on {te_equals -nocase -affinity text 0 0}} + + 15 "SELECT +y AS x FROM t5" "SELECT * FROM t4 JOIN %ss% USING (x)" + {t4 %ss% -using x -on {te_equals -nocase -affinity text 0 0}} +} { + + # Create a temporary table named %ss% containing the data returned by + # the sub-select. Then have the [te_tbljoin] proc use this table to + # compute the expected results of the $select query. Drop the temporary + # table before continuing. + # + execsql "CREATE TEMP TABLE '%ss%' AS $subselect" + set te [eval te_tbljoin db $spec] + execsql "DROP TABLE '%ss%'" + + # Check that the actual data returned by the $select query is the same + # as the expected data calculated using [te_tbljoin] above. + # + te_dataset_eq_unordered e_select-2.2.1.$tn [ + te_read_sql db [string map [list %ss% "($subselect)"] $select] + ] $te +} + +finish_test diff --git a/test/e_totalchanges.test b/test/e_totalchanges.test new file mode 100644 index 0000000..bb5cfba --- /dev/null +++ b/test/e_totalchanges.test @@ -0,0 +1,214 @@ +# 2011 May 06 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix e_totalchanges + +# Like [do_execsql_test], except it appends the value returned by +# [db total_changes] to the result of executing the SQL script. +# +proc do_tc_test {tn sql res} { + uplevel [list \ + do_test $tn "concat \[execsql {$sql}\] \[db total_changes\]" $res + ] +} + +do_execsql_test 1.0 { + CREATE TABLE t1(a, b); + CREATE INDEX t1_b ON t1(b); + CREATE TABLE t2(x, y, PRIMARY KEY(x, y)) WITHOUT ROWID; + CREATE INDEX t2_y ON t2(y); +} + + +#-------------------------------------------------------------------------- +# EVIDENCE-OF: R-38914-26427 The total_changes() function returns the +# number of row changes caused by INSERT, UPDATE or DELETE statements +# since the current database connection was opened. +# +# 1.1.*: different types of I/U/D statements, +# 1.2.*: trigger programs. +# +do_tc_test 1.1.1 { + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t1 VALUES(3, 4); + UPDATE t1 SET a = a+1; + DELETE FROM t1; +} {6} +do_tc_test 1.1.2 { + DELETE FROM t1 +} {6} + +do_tc_test 1.1.3 { + WITH data(a,b) AS ( + SELECT 0, 0 UNION ALL SELECT a+1, b+1 FROM data WHERE a<99 + ) + INSERT INTO t1 SELECT * FROM data; +} {106} + +do_tc_test 1.1.4 { + INSERT INTO t2 SELECT * FROM t1 WHERE a<50; + UPDATE t2 SET y=y+1; +} {206} + +do_tc_test 1.1.5 { + DELETE FROM t2 WHERE y<=25 +} {231} + +do_execsql_test 1.2.1 { + DELETE FROM t1; + DELETE FROM t2; +} +sqlite3 db test.db ; # To reset total_changes +do_tc_test 1.2.2 { + CREATE TABLE log(detail); + CREATE TRIGGER t1_after_insert AFTER INSERT ON t1 BEGIN + INSERT INTO log VALUES('inserted into t1'); + END; + + CREATE TRIGGER t1_before_delete BEFORE DELETE ON t1 BEGIN + INSERT INTO log VALUES('deleting from t1'); + INSERT INTO log VALUES('here we go!'); + END; + + CREATE TRIGGER t1_after_update AFTER UPDATE ON t1 BEGIN + INSERT INTO log VALUES('update'); + DELETE FROM log; + END; + + INSERT INTO t1 VALUES('a', 'b'); -- 1 + 1 + UPDATE t1 SET b='c'; -- 1 + 1 + 2 + DELETE FROM t1; -- 1 + 1 + 1 +} {9} + +#-------------------------------------------------------------------------- +# EVIDENCE-OF: R-61766-15253 Executing any other type of SQL statement +# does not affect the value returned by sqlite3_total_changes(). +ifcapable altertable { + do_tc_test 2.1 { + INSERT INTO t1 VALUES(1, 2), (3, 4); + INSERT INTO t2 VALUES(1, 2), (3, 4); + } {15} + do_tc_test 2.2 { + SELECT count(*) FROM t1; + } {2 15} + do_tc_test 2.3 { + CREATE TABLE t4(a, b); + ALTER TABLE t4 ADD COLUMN c; + CREATE INDEX i4 ON t4(c); + ALTER TABLE t4 RENAME TO t5; + ANALYZE; + BEGIN; + DROP TABLE t2; + ROLLBACK; + VACUUM; + } {15} +} + + +#-------------------------------------------------------------------------- +# EVIDENCE-OF: R-36043-10590 Changes made as part of foreign key +# actions are included in the count, but those made as part of REPLACE +# constraint resolution are not. +# +# 3.1.*: foreign key actions +# 3.2.*: REPLACE constraints. +# +sqlite3 db test.db ; # To reset total_changes +do_tc_test 3.1.1 { + CREATE TABLE p1(c PRIMARY KEY, d); + CREATE TABLE c1(a, b, FOREIGN KEY(a) REFERENCES p1 ON DELETE SET NULL); + CREATE TABLE c2(a, b, FOREIGN KEY(a) REFERENCES p1 ON DELETE CASCADE); + CREATE TABLE c3(a, b, FOREIGN KEY(a) REFERENCES p1 ON DELETE SET DEFAULT); + + INSERT INTO p1 VALUES(1, 'one'); + INSERT INTO p1 VALUES(2, 'two'); + INSERT INTO p1 VALUES(3, 'three'); + INSERT INTO p1 VALUES(4, 'four'); + + INSERT INTO c1 VALUES(1, 'i'); + INSERT INTO c2 VALUES(2, 'ii'); + INSERT INTO c3 VALUES(3, 'iii'); + PRAGMA foreign_keys = ON; +} {7} + +do_tc_test 3.1.2 { DELETE FROM p1 WHERE c=1; } {9} +do_tc_test 3.1.3 { DELETE FROM p1 WHERE c=2; } {11} +do_tc_test 3.1.4 { DELETE FROM p1 WHERE c=3; } {13} +do_tc_test 3.1.5 { DELETE FROM p1 WHERE c=4; } {14} ; # only 1 this time. + +sqlite3 db test.db ; # To reset total_changes +do_tc_test 3.1.6 { + DROP TABLE c1; + DROP TABLE c2; + DROP TABLE c3; + CREATE TABLE c1(a, b, FOREIGN KEY(a) REFERENCES p1 ON UPDATE SET NULL); + CREATE TABLE c2(a, b, FOREIGN KEY(a) REFERENCES p1 ON UPDATE CASCADE); + CREATE TABLE c3(a, b, FOREIGN KEY(a) REFERENCES p1 ON UPDATE SET DEFAULT); + + INSERT INTO p1 VALUES(1, 'one'); + INSERT INTO p1 VALUES(2, 'two'); + INSERT INTO p1 VALUES(3, 'three'); + INSERT INTO p1 VALUES(4, 'four'); + + INSERT INTO c1 VALUES(1, 'i'); + INSERT INTO c2 VALUES(2, 'ii'); + INSERT INTO c3 VALUES(3, 'iii'); + PRAGMA foreign_keys = ON; +} {7} + +do_tc_test 3.1.7 { UPDATE p1 SET c=c+4 WHERE c=1; } {9} +do_tc_test 3.1.8 { UPDATE p1 SET c=c+4 WHERE c=2; } {11} +do_tc_test 3.1.9 { UPDATE p1 SET c=c+4 WHERE c=3; } {13} +do_tc_test 3.1.10 { UPDATE p1 SET c=c+4 WHERE c=4; } {14} ; # only 1 this time. + +sqlite3 db test.db ; # To reset total_changes +do_tc_test 3.2.1 { + CREATE TABLE t3(a UNIQUE, b UNIQUE); + INSERT INTO t3 VALUES('one', 'one'); + INSERT INTO t3 VALUES('two', 'two'); + INSERT OR REPLACE INTO t3 VALUES('one', 'two'); +} {3} + +do_tc_test 3.2.2 { + INSERT INTO t3 VALUES('three', 'one'); + UPDATE OR REPLACE t3 SET b='two' WHERE b='one'; + SELECT * FROM t3; +} {three two 5} + +#-------------------------------------------------------------------------- +# EVIDENCE-OF: R-54872-08741 Changes to a view that are intercepted by +# INSTEAD OF triggers are not counted. +# +sqlite3 db test.db ; # To reset total_changes +do_tc_test 4.1 { + CREATE TABLE t6(x); + CREATE VIEW v1 AS SELECT * FROM t6; + CREATE TRIGGER v1_tr1 INSTEAD OF INSERT ON v1 BEGIN + SELECT 'no-op'; + END; + + INSERT INTO v1 VALUES('a'); + INSERT INTO v1 VALUES('b'); +} {0} +do_tc_test 4.2 { + CREATE TRIGGER v1_tr2 INSTEAD OF INSERT ON v1 BEGIN + INSERT INTO t6 VALUES(new.x); + END; + + INSERT INTO v1 VALUES('c'); + INSERT INTO v1 VALUES('d'); +} {2} + + +finish_test diff --git a/test/e_update.test b/test/e_update.test new file mode 100644 index 0000000..a13b059 --- /dev/null +++ b/test/e_update.test @@ -0,0 +1,605 @@ +# 2010 September 20 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file implements tests to verify that the "testable statements" in +# the lang_update.html document are correct. +# +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +#-------------------- +# Test organization: +# +# e_update-1.*: Test statements describing the workings of UPDATE statements. +# +# e_update-2.*: Test the restrictions on the UPDATE statement syntax that +# can be used within triggers. +# +# e_update-3.*: Test the special LIMIT/OFFSET and ORDER BY clauses that can +# be used with UPDATE when SQLite is compiled with +# SQLITE_ENABLE_UPDATE_DELETE_LIMIT. +# + +forcedelete test.db2 + +do_execsql_test e_update-0.0 { + ATTACH 'test.db2' AS aux; + CREATE TABLE t1(a, b); + CREATE TABLE t2(a, b, c); + CREATE TABLE t3(a, b UNIQUE); + CREATE TABLE t6(x, y); + CREATE INDEX i1 ON t1(a); + + CREATE TEMP TABLE t4(x, y); + CREATE TEMP TABLE t6(x, y); + + CREATE TABLE aux.t1(a, b); + CREATE TABLE aux.t5(a, b); +} {} + +proc do_update_tests {args} { + uplevel do_select_tests $args +} + +# -- syntax diagram update-stmt +# +do_update_tests e_update-0 { + 1 "UPDATE t1 SET a=10" {} + 2 "UPDATE t1 SET a=10, b=5" {} + 3 "UPDATE t1 SET a=10 WHERE b=5" {} + 4 "UPDATE t1 SET b=5,a=10 WHERE 1" {} + 5 "UPDATE main.t1 SET a=10" {} + 6 "UPDATE main.t1 SET a=10, b=5" {} + 7 "UPDATE main.t1 SET a=10 WHERE b=5" {} + 9 "UPDATE OR ROLLBACK t1 SET a=10" {} + 10 "UPDATE OR ROLLBACK t1 SET a=10, b=5" {} + 11 "UPDATE OR ROLLBACK t1 SET a=10 WHERE b=5" {} + 12 "UPDATE OR ROLLBACK t1 SET b=5,a=10 WHERE 1" {} + 13 "UPDATE OR ROLLBACK main.t1 SET a=10" {} + 14 "UPDATE OR ROLLBACK main.t1 SET a=10, b=5" {} + 15 "UPDATE OR ROLLBACK main.t1 SET a=10 WHERE b=5" {} + 16 "UPDATE OR ROLLBACK main.t1 SET b=5,a=10 WHERE 1" {} + 17 "UPDATE OR ABORT t1 SET a=10" {} + 18 "UPDATE OR ABORT t1 SET a=10, b=5" {} + 19 "UPDATE OR ABORT t1 SET a=10 WHERE b=5" {} + 20 "UPDATE OR ABORT t1 SET b=5,a=10 WHERE 1" {} + 21 "UPDATE OR ABORT main.t1 SET a=10" {} + 22 "UPDATE OR ABORT main.t1 SET a=10, b=5" {} + 23 "UPDATE OR ABORT main.t1 SET a=10 WHERE b=5" {} + 24 "UPDATE OR ABORT main.t1 SET b=5,a=10 WHERE 1" {} + 25 "UPDATE OR REPLACE t1 SET a=10" {} + 26 "UPDATE OR REPLACE t1 SET a=10, b=5" {} + 27 "UPDATE OR REPLACE t1 SET a=10 WHERE b=5" {} + 28 "UPDATE OR REPLACE t1 SET b=5,a=10 WHERE 1" {} + 29 "UPDATE OR REPLACE main.t1 SET a=10" {} + 30 "UPDATE OR REPLACE main.t1 SET a=10, b=5" {} + 31 "UPDATE OR REPLACE main.t1 SET a=10 WHERE b=5" {} + 32 "UPDATE OR REPLACE main.t1 SET b=5,a=10 WHERE 1" {} + 33 "UPDATE OR FAIL t1 SET a=10" {} + 34 "UPDATE OR FAIL t1 SET a=10, b=5" {} + 35 "UPDATE OR FAIL t1 SET a=10 WHERE b=5" {} + 36 "UPDATE OR FAIL t1 SET b=5,a=10 WHERE 1" {} + 37 "UPDATE OR FAIL main.t1 SET a=10" {} + 38 "UPDATE OR FAIL main.t1 SET a=10, b=5" {} + 39 "UPDATE OR FAIL main.t1 SET a=10 WHERE b=5" {} + 40 "UPDATE OR FAIL main.t1 SET b=5,a=10 WHERE 1" {} + 41 "UPDATE OR IGNORE t1 SET a=10" {} + 42 "UPDATE OR IGNORE t1 SET a=10, b=5" {} + 43 "UPDATE OR IGNORE t1 SET a=10 WHERE b=5" {} + 44 "UPDATE OR IGNORE t1 SET b=5,a=10 WHERE 1" {} + 45 "UPDATE OR IGNORE main.t1 SET a=10" {} + 46 "UPDATE OR IGNORE main.t1 SET a=10, b=5" {} + 47 "UPDATE OR IGNORE main.t1 SET a=10 WHERE b=5" {} + 48 "UPDATE OR IGNORE main.t1 SET b=5,a=10 WHERE 1" {} +} + +# EVIDENCE-OF: R-38515-45264 An UPDATE statement is used to modify a +# subset of the values stored in zero or more rows of the database table +# identified by the qualified-table-name specified as part of the UPDATE +# statement. +# +# Test cases e_update-1.1.1.* test the "identified by the +# qualified-table-name" part of the statement above. Tests +# e_update-1.1.2.* show that the "zero or more rows" part is +# accurate. +# +do_execsql_test e_update-1.1.0 { + INSERT INTO main.t1 VALUES(1, 'i'); + INSERT INTO main.t1 VALUES(2, 'ii'); + INSERT INTO main.t1 VALUES(3, 'iii'); + + INSERT INTO aux.t1 VALUES(1, 'I'); + INSERT INTO aux.t1 VALUES(2, 'II'); + INSERT INTO aux.t1 VALUES(3, 'III'); +} {} +do_update_tests e_update-1.1 { + 1.1 "UPDATE t1 SET a = a+1; SELECT * FROM t1" {2 i 3 ii 4 iii} + 1.2 "UPDATE main.t1 SET a = a+1; SELECT * FROM main.t1" {3 i 4 ii 5 iii} + 1.3 "UPDATE aux.t1 SET a = a+1; SELECT * FROM aux.t1" {2 I 3 II 4 III} + + 2.1 "UPDATE t1 SET a = a+1 WHERE a = 1; SELECT * FROM t1" {3 i 4 ii 5 iii} + 2.2 "UPDATE t1 SET a = a+1 WHERE a = 4; SELECT * FROM t1" {3 i 5 ii 5 iii} +} + +# EVIDENCE-OF: R-55869-30521 If the UPDATE statement does not have a +# WHERE clause, all rows in the table are modified by the UPDATE. +# +do_execsql_test e_update-1.2.0 { + DELETE FROM main.t1; + INSERT INTO main.t1 VALUES(1, 'i'); + INSERT INTO main.t1 VALUES(2, 'ii'); + INSERT INTO main.t1 VALUES(3, 'iii'); +} {} +do_update_tests e_update-1.2 { + 1 "UPDATE t1 SET b = 'roman' ; SELECT * FROM t1" + {1 roman 2 roman 3 roman} + + 2 "UPDATE t1 SET a = 'greek' ; SELECT * FROM t1" + {greek roman greek roman greek roman} +} + +# EVIDENCE-OF: R-58095-46013 Otherwise, the UPDATE affects only those +# rows for which the WHERE clause boolean expression is true. +# +do_execsql_test e_update-1.3.0 { + DELETE FROM main.t1; + INSERT INTO main.t1 VALUES(NULL, ''); + INSERT INTO main.t1 VALUES(1, 'i'); + INSERT INTO main.t1 VALUES(2, 'ii'); + INSERT INTO main.t1 VALUES(3, 'iii'); +} {} +do_update_tests e_update-1.3 { + 1 "UPDATE t1 SET b = 'roman' WHERE a<2 ; SELECT * FROM t1" + {{} {} 1 roman 2 ii 3 iii} + + 2 "UPDATE t1 SET b = 'egyptian' WHERE (a-3)/10.0 ; SELECT * FROM t1" + {{} {} 1 egyptian 2 egyptian 3 iii} + + 3 "UPDATE t1 SET b = 'macedonian' WHERE a; SELECT * FROM t1" + {{} {} 1 macedonian 2 macedonian 3 macedonian} + + 4 "UPDATE t1 SET b = 'lithuanian' WHERE a IS NULL; SELECT * FROM t1" + {{} lithuanian 1 macedonian 2 macedonian 3 macedonian} +} + +# EVIDENCE-OF: R-58129-20729 It is not an error if the WHERE clause does +# not evaluate to true for any row in the table - this just means that +# the UPDATE statement affects zero rows. +# +do_execsql_test e_update-1.4.0 { + DELETE FROM main.t1; + INSERT INTO main.t1 VALUES(NULL, ''); + INSERT INTO main.t1 VALUES(1, 'i'); + INSERT INTO main.t1 VALUES(2, 'ii'); + INSERT INTO main.t1 VALUES(3, 'iii'); +} {} +do_update_tests e_update-1.4 -query { + SELECT * FROM t1 +} { + 1 "UPDATE t1 SET b = 'burmese' WHERE a=5" {{} {} 1 i 2 ii 3 iii} + + 2 "UPDATE t1 SET b = 'burmese' WHERE length(b)<1 AND a IS NOT NULL" + {{} {} 1 i 2 ii 3 iii} + + 3 "UPDATE t1 SET b = 'burmese' WHERE 0" {{} {} 1 i 2 ii 3 iii} + + 4 "UPDATE t1 SET b = 'burmese' WHERE (SELECT a FROM t1 WHERE rowid=1)" + {{} {} 1 i 2 ii 3 iii} +} + +# EVIDENCE-OF: R-40598-36595 For each affected row, the named columns +# are set to the values found by evaluating the corresponding scalar +# expressions. +# +# EVIDENCE-OF: R-40472-60438 Columns that do not appear in the list of +# assignments are left unmodified. +# +do_execsql_test e_update-1.5.0 { + INSERT INTO t2(rowid, a, b, c) VALUES(1, 3, 1, 4); + INSERT INTO t2(rowid, a, b, c) VALUES(2, 1, 5, 9); + INSERT INTO t2(rowid, a, b, c) VALUES(3, 2, 6, 5); +} {} +do_update_tests e_update-1.5 -query { + SELECT * FROM t2 +} { + 1 "UPDATE t2 SET c = 1+1 WHERE a=2" + {3 1 4 1 5 9 2 6 2} + + 2 "UPDATE t2 SET b = 4/2, c=CAST((0.4*5) AS INTEGER) WHERE a<3" + {3 1 4 1 2 2 2 2 2} + + 3 "UPDATE t2 SET a = 1" + {1 1 4 1 2 2 1 2 2} + + 4 "UPDATE t2 SET b = (SELECT count(*)+2 FROM t2), c = 24/3+1 WHERE rowid=2" + {1 1 4 1 5 9 1 2 2} + + 5 "UPDATE t2 SET a = 3 WHERE c = 4" + {3 1 4 1 5 9 1 2 2} + + 6 "UPDATE t2 SET a = b WHERE rowid>2" + {3 1 4 1 5 9 2 2 2} + + 6 "UPDATE t2 SET b=6, c=5 WHERE a=b AND b=c" + {3 1 4 1 5 9 2 6 5} +} + +# EVIDENCE-OF: R-34751-18293 If a single column-name appears more than +# once in the list of assignment expressions, all but the rightmost +# occurrence is ignored. +# +do_update_tests e_update-1.6 -query { + SELECT * FROM t2 +} { + 1 "UPDATE t2 SET c=5, c=6, c=7 WHERE rowid=1" {3 1 7 1 5 9 2 6 5} + 2 "UPDATE t2 SET c=7, c=6, c=5 WHERE rowid=1" {3 1 5 1 5 9 2 6 5} + 3 "UPDATE t2 SET c=5, b=6, c=7 WHERE rowid=1" {3 6 7 1 5 9 2 6 5} +} + +# EVIDENCE-OF: R-36239-04077 The scalar expressions may refer to columns +# of the row being updated. +# +# EVIDENCE-OF: R-04558-24451 In this case all scalar expressions are +# evaluated before any assignments are made. +# +do_execsql_test e_update-1.7.0 { + DELETE FROM t2; + INSERT INTO t2(rowid, a, b, c) VALUES(1, 3, 1, 4); + INSERT INTO t2(rowid, a, b, c) VALUES(2, 1, 5, 9); + INSERT INTO t2(rowid, a, b, c) VALUES(3, 2, 6, 5); +} {} +do_update_tests e_update-1.7 -query { + SELECT * FROM t2 +} { + 1 "UPDATE t2 SET a=b+c" {5 1 4 14 5 9 11 6 5} + 2 "UPDATE t2 SET a=b, b=a" {1 5 4 5 14 9 6 11 5} + 3 "UPDATE t2 SET a=c||c, c=NULL" {44 5 {} 99 14 {} 55 11 {}} +} + +# EVIDENCE-OF: R-28518-13457 The optional "OR action" conflict clause +# that follows the UPDATE keyword allows the user to nominate a specific +# constraint conflict resolution algorithm to use during this one UPDATE +# command. +# +do_execsql_test e_update-1.8.0 { + DELETE FROM t3; + INSERT INTO t3 VALUES(1, 'one'); + INSERT INTO t3 VALUES(2, 'two'); + INSERT INTO t3 VALUES(3, 'three'); + INSERT INTO t3 VALUES(4, 'four'); +} {} +foreach {tn sql error ac data } { + 1 "UPDATE t3 SET b='one' WHERE a=3" + {UNIQUE constraint failed: t3.b} 1 {1 one 2 two 3 three 4 four} + + 2 "UPDATE OR REPLACE t3 SET b='one' WHERE a=3" + {} 1 {2 two 3 one 4 four} + + 3 "UPDATE OR FAIL t3 SET b='three'" + {UNIQUE constraint failed: t3.b} 1 {2 three 3 one 4 four} + + 4 "UPDATE OR IGNORE t3 SET b='three' WHERE a=3" + {} 1 {2 three 3 one 4 four} + + 5 "UPDATE OR ABORT t3 SET b='three' WHERE a=3" + {UNIQUE constraint failed: t3.b} 1 {2 three 3 one 4 four} + + 6 "BEGIN" {} 0 {2 three 3 one 4 four} + + 7 "UPDATE t3 SET b='three' WHERE a=3" + {UNIQUE constraint failed: t3.b} 0 {2 three 3 one 4 four} + + 8 "UPDATE OR ABORT t3 SET b='three' WHERE a=3" + {UNIQUE constraint failed: t3.b} 0 {2 three 3 one 4 four} + + 9 "UPDATE OR FAIL t3 SET b='two'" + {UNIQUE constraint failed: t3.b} 0 {2 two 3 one 4 four} + + 10 "UPDATE OR IGNORE t3 SET b='four' WHERE a=3" + {} 0 {2 two 3 one 4 four} + + 11 "UPDATE OR REPLACE t3 SET b='four' WHERE a=3" + {} 0 {2 two 3 four} + + 12 "UPDATE OR ROLLBACK t3 SET b='four'" + {UNIQUE constraint failed: t3.b} 1 {2 three 3 one 4 four} +} { + do_catchsql_test e_update-1.8.$tn.1 $sql [list [expr {$error!=""}] $error] + do_execsql_test e_update-1.8.$tn.2 {SELECT * FROM t3} [list {*}$data] + do_test e_update-1.8.$tn.3 {sqlite3_get_autocommit db} $ac +} + + + +# EVIDENCE-OF: R-12123-54095 The table-name specified as part of an +# UPDATE statement within a trigger body must be unqualified. +# +# EVIDENCE-OF: R-43190-62442 In other words, the schema-name. prefix on +# the table name of the UPDATE is not allowed within triggers. +# +do_update_tests e_update-2.1 -error { + qualified table names are not allowed on INSERT, UPDATE, and DELETE statements within triggers +} { + 1 { + CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN + UPDATE main.t2 SET a=1, b=2, c=3; + END; + } {} + + 2 { + CREATE TRIGGER tr1 BEFORE UPDATE ON t2 BEGIN + UPDATE aux.t1 SET a=1, b=2; + END; + } {} + + 3 { + CREATE TRIGGER tr1 AFTER DELETE ON t4 BEGIN + UPDATE main.t1 SET a=1, b=2; + END; + } {} +} + +# EVIDENCE-OF: R-06085-13761 Unless the table to which the trigger is +# attached is in the TEMP database, the table being updated by the +# trigger program must reside in the same database as it. +# +do_update_tests e_update-2.2 -error { + no such table: %s +} { + 1 { + CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN + UPDATE t4 SET x=x+1; + END; + INSERT INTO t1 VALUES(1, 2); + } "main.t4" + + 2 { + CREATE TRIGGER aux.tr1 AFTER INSERT ON t5 BEGIN + UPDATE t4 SET x=x+1; + END; + INSERT INTO t5 VALUES(1, 2); + } "aux.t4" +} +do_execsql_test e_update-2.2.X { + DROP TRIGGER tr1; + DROP TRIGGER aux.tr1; +} {} + +# EVIDENCE-OF: R-29512-54644 If the table to which the trigger is +# attached is in the TEMP database, then the unqualified name of the +# table being updated is resolved in the same way as it is for a +# top-level statement (by searching first the TEMP database, then the +# main database, then any other databases in the order they were +# attached). +# +do_execsql_test e_update-2.3.0 { + SELECT 'main', tbl_name FROM main.sqlite_master WHERE type = 'table'; + SELECT 'temp', tbl_name FROM sqlite_temp_master WHERE type = 'table'; + SELECT 'aux', tbl_name FROM aux.sqlite_master WHERE type = 'table'; +} [list {*}{ + main t1 + main t2 + main t3 + main t6 + temp t4 + temp t6 + aux t1 + aux t5 +}] +do_execsql_test e_update-2.3.1 { + DELETE FROM main.t6; + DELETE FROM temp.t6; + INSERT INTO main.t6 VALUES(1, 2); + INSERT INTO temp.t6 VALUES(1, 2); + + CREATE TRIGGER temp.tr1 AFTER INSERT ON t4 BEGIN + UPDATE t6 SET x=x+1; + END; + + INSERT INTO t4 VALUES(1, 2); + SELECT * FROM main.t6; + SELECT * FROM temp.t6; +} {1 2 2 2} +do_execsql_test e_update-2.3.2 { + DELETE FROM main.t1; + DELETE FROM aux.t1; + INSERT INTO main.t1 VALUES(1, 2); + INSERT INTO aux.t1 VALUES(1, 2); + + CREATE TRIGGER temp.tr2 AFTER DELETE ON t4 BEGIN + UPDATE t1 SET a=a+1; + END; + + DELETE FROM t4; + SELECT * FROM main.t1; + SELECT * FROM aux.t1; +} {2 2 1 2} +do_execsql_test e_update-2.3.3 { + DELETE FROM aux.t5; + INSERT INTO aux.t5 VALUES(1, 2); + + INSERT INTO t4 VALUES('x', 'y'); + CREATE TRIGGER temp.tr3 AFTER UPDATE ON t4 BEGIN + UPDATE t5 SET a=a+1; + END; + + UPDATE t4 SET x=10; + SELECT * FROM aux.t5; +} {2 2} + +# EVIDENCE-OF: R-19619-42762 The INDEXED BY and NOT INDEXED clauses are +# not allowed on UPDATE statements within triggers. +# +do_update_tests e_update-2.4 -error { + the %s %s clause is not allowed on UPDATE or DELETE statements within triggers +} { + 1 { + CREATE TRIGGER tr1 AFTER INSERT ON t2 BEGIN + UPDATE t1 INDEXED BY i1 SET a=a+1; + END; + } {INDEXED BY} + + 2 { + CREATE TRIGGER tr1 AFTER INSERT ON t2 BEGIN + UPDATE t1 NOT INDEXED SET a=a+1; + END; + } {NOT INDEXED} +} + +ifcapable update_delete_limit { + +# EVIDENCE-OF: R-57359-59558 The LIMIT and ORDER BY clauses for UPDATE +# are unsupported within triggers, regardless of the compilation options +# used to build SQLite. +# +do_update_tests e_update-2.5 -error { + near "%s": syntax error +} { + 1 { + CREATE TRIGGER tr1 AFTER INSERT ON t2 BEGIN + UPDATE t1 SET a=a+1 LIMIT 10; + END; + } {LIMIT} + + 2 { + CREATE TRIGGER tr1 AFTER INSERT ON t2 BEGIN + UPDATE t1 SET a=a+1 ORDER BY a LIMIT 10; + END; + } {ORDER} + + 3 { + CREATE TRIGGER tr1 AFTER INSERT ON t2 BEGIN + UPDATE t1 SET a=a+1 ORDER BY a LIMIT 10 OFFSET 2; + END; + } {ORDER} + + 4 { + CREATE TRIGGER tr1 AFTER INSERT ON t2 BEGIN + UPDATE t1 SET a=a+1 LIMIT 10 OFFSET 2; + END; + } {LIMIT} +} + +# EVIDENCE-OF: R-59581-44104 If SQLite is built with the +# SQLITE_ENABLE_UPDATE_DELETE_LIMIT compile-time option then the syntax +# of the UPDATE statement is extended with optional ORDER BY and LIMIT +# clauses +# +# -- syntax diagram update-stmt-limited +# +do_update_tests e_update-3.0 { + 1 "UPDATE t1 SET a=b LIMIT 5" {} + 2 "UPDATE t1 SET a=b LIMIT 5-1 OFFSET 2+2" {} + 3 "UPDATE t1 SET a=b LIMIT 2+2, 16/4" {} + 4 "UPDATE t1 SET a=b ORDER BY a LIMIT 5" {} + 5 "UPDATE t1 SET a=b ORDER BY a LIMIT 5-1 OFFSET 2+2" {} + 6 "UPDATE t1 SET a=b ORDER BY a LIMIT 2+2, 16/4" {} + 7 "UPDATE t1 SET a=b WHERE a>2 LIMIT 5" {} + 8 "UPDATE t1 SET a=b WHERE a>2 LIMIT 5-1 OFFSET 2+2" {} + 9 "UPDATE t1 SET a=b WHERE a>2 LIMIT 2+2, 16/4" {} + 10 "UPDATE t1 SET a=b WHERE a>2 ORDER BY a LIMIT 5" {} + 11 "UPDATE t1 SET a=b WHERE a>2 ORDER BY a LIMIT 5-1 OFFSET 2+2" {} + 12 "UPDATE t1 SET a=b WHERE a>2 ORDER BY a LIMIT 2+2, 16/4" {} +} + +do_execsql_test e_update-3.1.0 { + CREATE TABLE t7(q, r, s); + INSERT INTO t7 VALUES(1, 'one', 'X'); + INSERT INTO t7 VALUES(2, 'two', 'X'); + INSERT INTO t7 VALUES(3, 'three', 'X'); + INSERT INTO t7 VALUES(4, 'four', 'X'); + INSERT INTO t7 VALUES(5, 'five', 'X'); + INSERT INTO t7 VALUES(6, 'six', 'X'); + INSERT INTO t7 VALUES(7, 'seven', 'X'); + INSERT INTO t7 VALUES(8, 'eight', 'X'); + INSERT INTO t7 VALUES(9, 'nine', 'X'); + INSERT INTO t7 VALUES(10, 'ten', 'X'); +} {} + +# EVIDENCE-OF: R-58862-44169 If an UPDATE statement has a LIMIT clause, +# the maximum number of rows that will be updated is found by evaluating +# the accompanying expression and casting it to an integer value. +# +do_update_tests e_update-3.1 -query { SELECT s FROM t7 } { + 1 "UPDATE t7 SET s = q LIMIT 5" {1 2 3 4 5 X X X X X} + 2 "UPDATE t7 SET s = r WHERE q>2 LIMIT 4" {1 2 three four five six X X X X} + 3 "UPDATE t7 SET s = q LIMIT 0" {1 2 three four five six X X X X} +} + +# EVIDENCE-OF: R-63582-45120 A negative value is interpreted as "no limit". +# +do_update_tests e_update-3.2 -query { SELECT s FROM t7 } { + 1 "UPDATE t7 SET s = q LIMIT -1" {1 2 3 4 5 6 7 8 9 10} + 2 "UPDATE t7 SET s = r WHERE q>4 LIMIT -1" + {1 2 3 4 five six seven eight nine ten} + 3 "UPDATE t7 SET s = 'X' LIMIT -1" {X X X X X X X X X X} +} + +# EVIDENCE-OF: R-18628-11938 If the LIMIT expression evaluates to +# non-negative value N and the UPDATE statement has an ORDER BY clause, +# then all rows that would be updated in the absence of the LIMIT clause +# are sorted according to the ORDER BY and the first N updated. +# +do_update_tests e_update-3.3 -query { SELECT s FROM t7 } { + 1 "UPDATE t7 SET s = q ORDER BY r LIMIT 3" {X X X 4 5 X X 8 X X} + 2 "UPDATE t7 SET s = r ORDER BY r DESC LIMIT 2" {X two three 4 5 X X 8 X X} + 3 "UPDATE t7 SET s = q ORDER BY q DESC LIMIT 5" {X two three 4 5 6 7 8 9 10} + + X "UPDATE t7 SET s = 'X'" {X X X X X X X X X X} +} + +# EVIDENCE-OF: R-30955-38324 If the UPDATE statement also has an OFFSET +# clause, then it is similarly evaluated and cast to an integer value. +# If the OFFSET expression evaluates to a non-negative value M, then the +# first M rows are skipped and the following N rows updated instead. +# +do_update_tests e_update-3.3 -query { SELECT s FROM t7 } { + 1 "UPDATE t7 SET s = q ORDER BY q LIMIT 3 OFFSET 2" {X X 3 4 5 X X X X X} + 2 "UPDATE t7 SET s = q ORDER BY q DESC LIMIT 2, 3 " {X X 3 4 5 6 7 8 X X} + + X "UPDATE t7 SET s = 'X'" {X X X X X X X X X X} +} + +# EVIDENCE-OF: R-19486-35828 If the UPDATE statement has no ORDER BY +# clause, then all rows that would be updated in the absence of the +# LIMIT clause are assembled in an arbitrary order before applying the +# LIMIT and OFFSET clauses to determine which are actually updated. +# +# In practice, "arbitrary order" is rowid order. This is also tested +# by e_update-3.2.* above. +# +do_update_tests e_update-3.4 -query { SELECT s FROM t7 } { + 1 "UPDATE t7 SET s = q LIMIT 4, 2" {X X X X 5 6 X X X X} + 2 "UPDATE t7 SET s = q LIMIT 2 OFFSET 7" {X X X X 5 6 X 8 9 X} +} + +# EVIDENCE-OF: R-10927-26133 The ORDER BY clause on an UPDATE statement +# is used only to determine which rows fall within the LIMIT. The order +# in which rows are modified is arbitrary and is not influenced by the +# ORDER BY clause. +# +do_execsql_test e_update-3.5.0 { + CREATE TABLE t8(x); + CREATE TRIGGER tr7 BEFORE UPDATE ON t7 BEGIN + INSERT INTO t8 VALUES(old.q); + END; +} {} +do_update_tests e_update-3.5 -query { SELECT x FROM t8 ; DELETE FROM t8 } { + 1 "UPDATE t7 SET s = q ORDER BY r LIMIT -1" {1 2 3 4 5 6 7 8 9 10} + 2 "UPDATE t7 SET s = q ORDER BY r ASC LIMIT -1" {1 2 3 4 5 6 7 8 9 10} + 3 "UPDATE t7 SET s = q ORDER BY r DESC LIMIT -1" {1 2 3 4 5 6 7 8 9 10} + 4 "UPDATE t7 SET s = q ORDER BY q DESC LIMIT 5" {6 7 8 9 10} +} + + +} ;# ifcapable update_delete_limit + +finish_test diff --git a/test/e_uri.test b/test/e_uri.test new file mode 100644 index 0000000..b1fb479 --- /dev/null +++ b/test/e_uri.test @@ -0,0 +1,465 @@ +# 2011 May 06 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix e_uri +do_not_use_codec +db close + +proc parse_uri {uri} { + testvfs tvfs2 + testvfs tvfs + tvfs filter xOpen + tvfs script parse_uri_open_cb + + set ::uri_open [list] + set DB [sqlite3_open_v2 $uri { + SQLITE_OPEN_READWRITE SQLITE_OPEN_CREATE SQLITE_OPEN_WAL + SQLITE_OPEN_EXRESCODE + } tvfs] + set fileName [sqlite3_db_filename $DB main] + sqlite3_close $DB + forcedelete $fileName + tvfs delete + tvfs2 delete + + set ::uri_open +} +proc parse_uri_open_cb {method file arglist} { + set ::uri_open [list $file $arglist] +} + +proc open_uri_error {uri} { + set flags {SQLITE_OPEN_READWRITE SQLITE_OPEN_CREATE SQLITE_OPEN_WAL} + set DB [sqlite3_open_v2 $uri $flags ""] + set e [sqlite3_errmsg $DB] + sqlite3_close $DB + set e +} + +# EVIDENCE-OF: R-35840-33204 If URI filename interpretation is enabled, +# and the filename argument begins with "file:", then the filename is +# interpreted as a URI. +# +# EVIDENCE-OF: R-27632-24205 URI filename interpretation is enabled if +# the SQLITE_OPEN_URI flag is set in the third argument to +# sqlite3_open_v2(), or if it has been enabled globally using the +# SQLITE_CONFIG_URI option with the sqlite3_config() method or by the +# SQLITE_USE_URI compile-time option. +# +if {$tcl_platform(platform) == "unix"} { + set flags [list SQLITE_OPEN_READWRITE SQLITE_OPEN_CREATE] + + # Tests with SQLITE_CONFIG_URI configured to false. URI intepretation is + # only enabled if the SQLITE_OPEN_URI flag is specified. + sqlite3_shutdown + sqlite3_config_uri 0 + do_test 1.1 { + forcedelete file:test.db test.db + set DB [sqlite3_open_v2 file:test.db [concat $flags SQLITE_OPEN_URI] ""] + list [file exists file:test.db] [file exists test.db] + } {0 1} + do_test 1.2 { + forcedelete file:test.db2 test.db2 + set STMT [sqlite3_prepare $DB "ATTACH 'file:test.db2' AS aux" -1 dummy] + sqlite3_step $STMT + sqlite3_finalize $STMT + list [file exists file:test.db2] [file exists test.db2] + } {0 1} + sqlite3_close $DB + do_test 1.3 { + forcedelete file:test.db test.db + set DB [sqlite3_open_v2 file:test.db [concat $flags] ""] + list [file exists file:test.db] [file exists test.db] + } {1 0} + do_test 1.4 { + forcedelete file:test.db2 test.db2 + set STMT [sqlite3_prepare $DB "ATTACH 'file:test.db2' AS aux" -1 dummy] + sqlite3_step $STMT + sqlite3_finalize $STMT + list [file exists file:test.db2] [file exists test.db2] + } {1 0} + sqlite3_close $DB + + # Tests with SQLITE_CONFIG_URI configured to true. URI intepretation is + # enabled with or without SQLITE_OPEN_URI. + # + sqlite3_shutdown + sqlite3_config_uri 1 + do_test 1.5 { + forcedelete file:test.db test.db + set DB [sqlite3_open_v2 file:test.db [concat $flags SQLITE_OPEN_URI] ""] + list [file exists file:test.db] [file exists test.db] + } {0 1} + do_test 1.6 { + forcedelete file:test.db2 test.db2 + set STMT [sqlite3_prepare $DB "ATTACH 'file:test.db2' AS aux" -1 dummy] + sqlite3_step $STMT + sqlite3_finalize $STMT + list [file exists file:test.db2] [file exists test.db2] + } {0 1} + sqlite3_close $DB + do_test 1.7 { + forcedelete file:test.db test.db + set DB [sqlite3_open_v2 file:test.db [concat $flags] ""] + list [file exists file:test.db] [file exists test.db] + } {0 1} + do_test 1.8 { + forcedelete file:test.db2 test.db2 + set STMT [sqlite3_prepare $DB "ATTACH 'file:test.db2' AS aux" -1 dummy] + sqlite3_step $STMT + sqlite3_finalize $STMT + list [file exists file:test.db2] [file exists test.db2] + } {0 1} + sqlite3_close $DB +} + +# ensure uri processing enabled for the rest of the tests +sqlite3_shutdown +sqlite3_config_uri 1 + +# EVIDENCE-OF: R-06842-00595 If the URI contains an authority, then it +# must be either an empty string or the string "localhost". +# +# EVIDENCE-OF: R-17482-00398 If the authority is not an empty string or +# "localhost", an error is returned to the caller. +# +if {$tcl_platform(platform) == "unix"} { + set flags [list SQLITE_OPEN_READWRITE SQLITE_OPEN_CREATE SQLITE_OPEN_URI] + foreach {tn uri error} " + 1 {file://localhost[test_pwd /]test.db} {not an error} + 2 {file://[test_pwd /]test.db} {not an error} + 3 {file://x[test_pwd /]test.db} {invalid uri authority: x} + 4 {file://invalid[test_pwd /]test.db} {invalid uri authority: invalid} + " { + do_test 2.$tn { + set DB [sqlite3_open_v2 $uri $flags ""] + set e [sqlite3_errmsg $DB] + sqlite3_close $DB + set e + } $error + } +} + +# EVIDENCE-OF: R-45981-25528 The fragment component of a URI, if +# present, is ignored. +# +# It is difficult to test that something is ignored correctly. So these tests +# just show that adding a fragment does not interfere with the pathname or +# parameters passed through to the VFS xOpen() methods. +# +foreach {tn uri parse} " + 1 {file:test.db#abc} {[test_pwd / {}]test.db {}} + 2 {file:test.db?a=b#abc} {[test_pwd / {}]test.db {a b}} + 3 {file:test.db?a=b#?c=d} {[test_pwd / {}]test.db {a b}} +" { + do_filepath_test 3.$tn { parse_uri $uri } $parse +} + +# EVIDENCE-OF: R-62557-09390 SQLite uses the path component of the URI +# as the name of the disk file which contains the database. +# +# EVIDENCE-OF: R-28659-11035 If the path begins with a '/' character, +# then it is interpreted as an absolute path. +# +# EVIDENCE-OF: R-46234-61323 If the path does not begin with a '/' +# (meaning that the authority section is omitted from the URI) then the +# path is interpreted as a relative path. +# +foreach {tn uri parse} " + 1 {file:test.db} {[test_pwd / {}]test.db {}} + 2 {file:/test.db} {/test.db {}} + 3 {file:///test.db} {/test.db {}} + 4 {file://localhost/test.db} {/test.db {}} + 5 {file:/a/b/c/test.db} {/a/b/c/test.db {}} +" { + do_filepath_test 4.$tn { parse_uri $uri } $parse +} + +# EVIDENCE-OF: R-01612-30877 The "vfs" parameter may be used to specify +# the name of a VFS object that provides the operating system interface +# that should be used to access the database file on disk. +# +# The above is tested by cases 1.* below. +# +# EVIDENCE-OF: R-52293-58497 If this option is set to an empty string +# the default VFS object is used. +# +# The above is tested by cases 2.* below. +# +# EVIDENCE-OF: R-31855-18665 If sqlite3_open_v2() is used and the vfs +# option is present, then the VFS specified by the option takes +# precedence over the value passed as the fourth parameter to +# sqlite3_open_v2(). +# +# The above is tested by cases 3.* below. +# +proc vfs_open_cb {name args} { + set ::vfs $name +} +foreach {name default} {vfs1 0 vfs2 0 vfs3 1} { + testvfs $name -default $default + $name filter xOpen + $name script [list vfs_open_cb $name] +} +foreach {tn uri defvfs vfs} { + 1.1 "file:test.db?vfs=vfs1" "" vfs1 + 1.2 "file:test.db?vfs=vfs2" "" vfs2 + + 2.1 "file:test.db" vfs1 vfs1 + 2.2 "file:test.db?vfs=" vfs1 vfs3 + + 3.1 "file:test.db?vfs=vfs1" vfs2 vfs1 + 3.2 "file:test.db?vfs=vfs2" vfs1 vfs2 + 3.3 "file:test.db?xvfs=vfs1" vfs2 vfs2 + 3.4 "file:test.db?xvfs=vfs2" vfs1 vfs1 +} { + do_test 5.$tn { + set flags [list SQLITE_OPEN_READWRITE SQLITE_OPEN_CREATE SQLITE_OPEN_URI] + sqlite3_close [ + sqlite3_open_v2 $uri $flags $defvfs + ] + set ::vfs + } $vfs +} +vfs1 delete +vfs2 delete +vfs3 delete + +# EVIDENCE-OF: R-48365-36308 Specifying an unknown VFS is an error. +# +set flags [list SQLITE_OPEN_READWRITE SQLITE_OPEN_CREATE SQLITE_OPEN_URI] +do_test 6.1 { + set DB [sqlite3_open_v2 file:test.db?vfs=nosuchvfs $flags ""] + set errmsg [sqlite3_errmsg $DB] + sqlite3_close $DB + set errmsg +} {no such vfs: nosuchvfs} + + +# EVIDENCE-OF: R-44013-13102 The mode parameter may be set to either +# "ro", "rw", "rwc", or "memory". Attempting to set it to any other +# value is an error +# +sqlite3 db test.db +db close +foreach {tn uri error} " + 1 {file:test.db?mode=ro} {not an error} + 2 {file:test.db?mode=rw} {not an error} + 3 {file:test.db?mode=rwc} {not an error} + 4 {file:test.db?mode=Ro} {no such access mode: Ro} + 5 {file:test.db?mode=Rw} {no such access mode: Rw} + 6 {file:test.db?mode=Rwc} {no such access mode: Rwc} + 7 {file:test.db?mode=memory} {not an error} + 8 {file:test.db?mode=MEMORY} {no such access mode: MEMORY} +" { + do_test 7.$tn { open_uri_error $uri } $error +} + + +# EVIDENCE-OF: R-43036-46756 If "ro" is specified, then the database is +# opened for read-only access, just as if the SQLITE_OPEN_READONLY flag +# had been set in the third argument to sqlite3_open_v2(). +# +# EVIDENCE-OF: R-40137-26050 If the mode option is set to "rw", then the +# database is opened for read-write (but not create) access, as if +# SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had been set. +# +# EVIDENCE-OF: R-26845-32976 Value "rwc" is equivalent to setting both +# SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. +# +foreach {tn uri read write create} { + 1 {file:test.db?mode=ro} 1 0 0 + 2 {file:test.db?mode=rw} 1 1 0 + 3 {file:test.db?mode=rwc} 1 1 1 +} { + set RES(c,0) {1 {unable to open database file}} + set RES(c,1) {0 {}} + set RES(w,0) {1 {attempt to write a readonly database}} + set RES(w,1) {0 {}} + set RES(r,0) {1 {this never happens}} + set RES(r,1) {0 {a b}} + + # Test CREATE access: + forcedelete test.db + do_test 8.$tn.c { list [catch { sqlite3 db $uri } msg] $msg } $RES(c,$create) + catch { db close } + + sqlite3 db test.db + db eval { CREATE TABLE t1(a, b) ; INSERT INTO t1 VALUES('a', 'b') ;} + db close + + # Test READ access: + do_test 8.$tn.r { + sqlite3 db $uri + catchsql { SELECT * FROM t1 } + } $RES(r,$read) + + # Test WRITE access: + do_test 8.$tn.w { + sqlite3 db $uri + catchsql { INSERT INTO t1 VALUES(1, 2) } + } $RES(w,$write) + + catch {db close} +} + +# EVIDENCE-OF: R-20590-08726 It is an error to specify a value for the +# mode parameter that is less restrictive than that specified by the +# flags passed in the third parameter to sqlite3_open_v2(). +# +forcedelete test.db +sqlite3 db test.db +db close +foreach {tn uri flags error} { + 1 {file:test.db?mode=ro} ro {not an error} + 2 {file:test.db?mode=ro} rw {not an error} + 3 {file:test.db?mode=ro} rwc {not an error} + + 4 {file:test.db?mode=rw} ro {access mode not allowed: rw} + 5 {file:test.db?mode=rw} rw {not an error} + 6 {file:test.db?mode=rw} rwc {not an error} + + 7 {file:test.db?mode=rwc} ro {access mode not allowed: rwc} + 8 {file:test.db?mode=rwc} rw {access mode not allowed: rwc} + 9 {file:test.db?mode=rwc} rwc {not an error} +} { + set f(ro) [list SQLITE_OPEN_READONLY SQLITE_OPEN_URI] + set f(rw) [list SQLITE_OPEN_READWRITE SQLITE_OPEN_URI] + set f(rwc) [list SQLITE_OPEN_READWRITE SQLITE_OPEN_CREATE SQLITE_OPEN_URI] + + set DB [sqlite3_open_v2 $uri $f($flags) ""] + set e [sqlite3_errmsg $DB] + sqlite3_close $DB + + do_test 9.$tn { set e } $error +} + +# EVIDENCE-OF: R-23182-54295 The cache parameter may be set to either +# "shared" or "private". +sqlite3 db test.db +db close +foreach {tn uri error} " + 1 {file:test.db?cache=private} {not an error} + 2 {file:test.db?cache=shared} {not an error} + 3 {file:test.db?cache=yes} {no such cache mode: yes} + 4 {file:test.db?cache=} {no such cache mode: } +" { + do_test 10.$tn { open_uri_error $uri } $error +} + +ifcapable shared_cache { +# EVIDENCE-OF: R-23027-03515 Setting it to "shared" is equivalent to +# setting the SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed +# to sqlite3_open_v2(). +# +# EVIDENCE-OF: R-49793-28525 Setting the cache parameter to "private" is +# equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit. +# +# EVIDENCE-OF: R-31773-41793 If sqlite3_open_v2() is used and the +# "cache" parameter is present in a URI filename, its value overrides +# any behavior requested by setting SQLITE_OPEN_PRIVATECACHE or +# SQLITE_OPEN_SHAREDCACHE flag. +# +set orig [sqlite3_enable_shared_cache] +foreach {tn uri flags shared_default isshared} { + 1.1 "file:test.db" "" 0 0 + 1.2 "file:test.db" "" 1 1 + 1.3 "file:test.db" private 0 0 + 1.4 "file:test.db" private 1 0 + 1.5 "file:test.db" shared 0 1 + 1.6 "file:test.db" shared 1 1 + + 2.1 "file:test.db?cache=private" "" 0 0 + 2.2 "file:test.db?cache=private" "" 1 0 + 2.3 "file:test.db?cache=private" private 0 0 + 2.4 "file:test.db?cache=private" private 1 0 + 2.5 "file:test.db?cache=private" shared 0 0 + 2.6 "file:test.db?cache=private" shared 1 0 + + 3.1 "file:test.db?cache=shared" "" 0 1 + 3.2 "file:test.db?cache=shared" "" 1 1 + 3.3 "file:test.db?cache=shared" private 0 1 + 3.4 "file:test.db?cache=shared" private 1 1 + 3.5 "file:test.db?cache=shared" shared 0 1 + 3.6 "file:test.db?cache=shared" shared 1 1 +} { + forcedelete test.db + sqlite3_enable_shared_cache 1 + sqlite3 db test.db + sqlite3_enable_shared_cache 0 + + db eval { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES('ok'); + } + + unset -nocomplain f + set f() {SQLITE_OPEN_READWRITE SQLITE_OPEN_CREATE SQLITE_OPEN_URI} + set f(shared) [concat $f() SQLITE_OPEN_SHAREDCACHE] + set f(private) [concat $f() SQLITE_OPEN_PRIVATECACHE] + + sqlite3_enable_shared_cache $shared_default + set DB [sqlite3_open_v2 $uri $f($flags) ""] + + set STMT [sqlite3_prepare $DB "SELECT * FROM t1" -1 dummy] + + db eval { + BEGIN; + INSERT INTO t1 VALUES('ko'); + } + + sqlite3_step $STMT + sqlite3_finalize $STMT + + set RES(0) {not an error} + set RES(1) {database table is locked: t1} + + do_test 11.$tn { sqlite3_errmsg $DB } $RES($isshared) + + sqlite3_close $DB + db close +} +sqlite3_enable_shared_cache $orig +} ;# End ifcapable shared_chache + +# EVIDENCE-OF: R-63472-46769 Specifying an unknown parameter in the +# query component of a URI is not an error. +# +do_filepath_test 12.1 { + parse_uri file://localhost/test.db?an=unknown¶meter=is&ok= +} {/test.db {an unknown parameter is ok {}}} +do_filepath_test 12.2 { + parse_uri file://localhost/test.db?an&unknown¶meter&is&ok +} {/test.db {an {} unknown {} parameter {} is {} ok {}}} + +# EVIDENCE-OF: R-27458-04043 URI hexadecimal escape sequences (%HH) are +# supported within the path and query components of a URI. +# +# EVIDENCE-OF: R-52765-50368 Before the path or query components of a +# URI filename are interpreted, they are encoded using UTF-8 and all +# hexadecimal escape sequences replaced by a single byte containing the +# corresponding octet. +# +# The second of the two statements above is tested by creating a +# multi-byte utf-8 character using a sequence of %HH escapes. +# +foreach {tn uri parse} " + 1 {file:/test.%64%62} {/test.db {}} + 2 {file:/test.db?%68%65%6c%6c%6f=%77%6f%72%6c%64} {/test.db {hello world}} + 3 {file:/%C3%BF.db} {/\xFF.db {}} +" { + do_filepath_test 13.$tn { parse_uri $uri } $parse +} + +finish_test diff --git a/test/e_vacuum.test b/test/e_vacuum.test new file mode 100644 index 0000000..63bf7c1 --- /dev/null +++ b/test/e_vacuum.test @@ -0,0 +1,347 @@ +# 2010 September 24 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file implements tests to verify that the "testable statements" in +# the lang_vacuum.html document are correct. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +sqlite3_test_control_pending_byte 0x1000000 + +proc create_db {{sql ""}} { + catch { db close } + forcedelete test.db + sqlite3 db test.db + + db transaction { + execsql { PRAGMA page_size = 1024; } + execsql $sql + execsql { + CREATE TABLE t1(a PRIMARY KEY, b UNIQUE); + INSERT INTO t1 VALUES(1, randomblob(400)); + INSERT INTO t1 SELECT a+1, randomblob(400) FROM t1; + INSERT INTO t1 SELECT a+2, randomblob(400) FROM t1; + INSERT INTO t1 SELECT a+4, randomblob(400) FROM t1; + INSERT INTO t1 SELECT a+8, randomblob(400) FROM t1; + INSERT INTO t1 SELECT a+16, randomblob(400) FROM t1; + INSERT INTO t1 SELECT a+32, randomblob(400) FROM t1; + INSERT INTO t1 SELECT a+64, randomblob(400) FROM t1; + + CREATE TABLE t2(a PRIMARY KEY, b UNIQUE); + INSERT INTO t2 SELECT * FROM t1; + } + } + + return [expr {[file size test.db] / 1024}] +} + +# This proc returns the number of contiguous blocks of pages that make up +# the table or index named by the only argument. For example, if the table +# occupies database pages 3, 4, 8 and 9, then this command returns 2 (there +# are 2 fragments - one consisting of pages 3 and 4, the other of fragments +# 8 and 9). +# +proc fragment_count {name} { + execsql { CREATE VIRTUAL TABLE temp.stat USING dbstat } + set nFrag 1 + db eval {SELECT pageno FROM stat WHERE name = 't1' ORDER BY pageno} { + if {[info exists prevpageno] && $prevpageno != $pageno-1} { + incr nFrag + } + set prevpageno $pageno + } + execsql { DROP TABLE temp.stat } + set nFrag +} + + +# -- syntax diagram vacuum-stmt +# +do_execsql_test e_vacuum-0.1 { VACUUM } {} + +# EVIDENCE-OF: R-51469-36013 Unless SQLite is running in +# "auto_vacuum=FULL" mode, when a large amount of data is deleted from +# the database file it leaves behind empty space, or "free" database +# pages. +# +# EVIDENCE-OF: R-60541-63059 Running VACUUM to rebuild the database +# reclaims this space and reduces the size of the database file. +# +foreach {tn avmode sz} { + 1 none 7 + 2 full 8 + 3 incremental 8 +} { + set nPage [create_db "PRAGMA auto_vacuum = $avmode"] + + do_execsql_test e_vacuum-1.1.$tn.1 { + DELETE FROM t1; + DELETE FROM t2; + } {} + + if {$avmode == "full"} { + # This branch tests the "unless ... auto_vacuum=FULL" in the requirement + # above. If auto_vacuum is set to FULL, then no empty space is left in + # the database file. + do_execsql_test e_vacuum-1.1.$tn.2 {PRAGMA freelist_count} 0 + } else { + set freelist [expr {$nPage - $sz}] + if {$avmode == "incremental"} { + # The page size is 1024 bytes. Therefore, assuming the database contains + # somewhere between 207 and 411 pages (it does), there are 2 pointer-map + # pages. + incr freelist -2 + } + do_execsql_test e_vacuum-1.1.$tn.3 {PRAGMA freelist_count} $freelist + do_execsql_test e_vacuum-1.1.$tn.4 {VACUUM} {} + } + + do_test e_vacuum-1.1.$tn.5 { expr {[file size test.db] / 1024} } $sz +} + +# EVIDENCE-OF: R-50943-18433 Frequent inserts, updates, and deletes can +# cause the database file to become fragmented - where data for a single +# table or index is scattered around the database file. +# +# EVIDENCE-OF: R-05791-54928 Running VACUUM ensures that each table and +# index is largely stored contiguously within the database file. +# +# e_vacuum-1.2.1 - Perform many INSERT, UPDATE and DELETE ops on table t1. +# e_vacuum-1.2.2 - Verify that t1 and its indexes are now quite fragmented. +# e_vacuum-1.2.3 - Run VACUUM. +# e_vacuum-1.2.4 - Verify that t1 and its indexes are now much +# less fragmented. +# +ifcapable vtab&&compound { + create_db + register_dbstat_vtab db + do_execsql_test e_vacuum-1.2.1 { + DELETE FROM t1 WHERE a%2; + INSERT INTO t1 SELECT b, a FROM t2 WHERE a%2; + UPDATE t1 SET b=randomblob(600) WHERE (a%2)==0; + } {} + + do_test e_vacuum-1.2.2.1 { expr [fragment_count t1]>100 } 1 + do_test e_vacuum-1.2.2.2 { expr [fragment_count sqlite_autoindex_t1_1]>100 } 1 + do_test e_vacuum-1.2.2.3 { expr [fragment_count sqlite_autoindex_t1_2]>100 } 1 + + do_execsql_test e_vacuum-1.2.3 { VACUUM } {} + + # In practice, the tables and indexes each end up stored as two fragments - + # one containing the root page and another containing all other pages. + # + do_test e_vacuum-1.2.4.1 { fragment_count t1 } 2 + do_test e_vacuum-1.2.4.2 { fragment_count sqlite_autoindex_t1_1 } 2 + do_test e_vacuum-1.2.4.3 { fragment_count sqlite_autoindex_t1_2 } 2 +} + +# EVIDENCE-OF: R-20474-44465 Normally, the database page_size and +# whether or not the database supports auto_vacuum must be configured +# before the database file is actually created. +# +do_test e_vacuum-1.3.1.1 { + create_db "PRAGMA page_size = 1024 ; PRAGMA auto_vacuum = FULL" + execsql { PRAGMA page_size ; PRAGMA auto_vacuum } +} {1024 1} +do_test e_vacuum-1.3.1.2 { + execsql { PRAGMA page_size = 2048 } + execsql { PRAGMA auto_vacuum = NONE } + execsql { PRAGMA page_size ; PRAGMA auto_vacuum } +} {1024 1} + +if {![nonzero_reserved_bytes]} { + # EVIDENCE-OF: R-08570-19916 However, when not in write-ahead log mode, + # the page_size and/or auto_vacuum properties of an existing database + # may be changed by using the page_size and/or pragma auto_vacuum + # pragmas and then immediately VACUUMing the database. + # + do_test e_vacuum-1.3.2.1 { + execsql { PRAGMA journal_mode = delete } + execsql { PRAGMA page_size = 2048 } + execsql { PRAGMA auto_vacuum = NONE } + execsql VACUUM + execsql { PRAGMA page_size ; PRAGMA auto_vacuum } + } {2048 0} + + # EVIDENCE-OF: R-48521-51450 When in write-ahead log mode, only the + # auto_vacuum support property can be changed using VACUUM. + # + if {[wal_is_capable]} { + do_test e_vacuum-1.3.3.1 { + execsql { PRAGMA journal_mode = wal } + execsql { PRAGMA page_size ; PRAGMA auto_vacuum } + } {2048 0} + do_test e_vacuum-1.3.3.2 { + execsql { PRAGMA page_size = 1024 } + execsql { PRAGMA auto_vacuum = FULL } + execsql VACUUM + execsql { PRAGMA page_size ; PRAGMA auto_vacuum } + } {2048 1} + } +} + +# EVIDENCE-OF: R-40347-36128 By default, VACUUM operates on the main +# database. +forcedelete test.db2 +create_db { PRAGMA auto_vacuum = NONE } +do_execsql_test e_vacuum-2.1.1 { + ATTACH 'test.db2' AS aux; + PRAGMA aux.page_size = 1024; + CREATE TABLE aux.t3 AS SELECT * FROM t1; + DELETE FROM t3; +} {} +set original_size [file size test.db2] + +# Vacuuming the main database does not affect aux +do_execsql_test e_vacuum-2.1.3 { VACUUM } {} +do_test e_vacuum-2.1.6 { expr {[file size test.db2]==$::original_size} } 1 + +# EVIDENCE-OF: R-36598-60500 Attached databases can be vacuumed by +# appending the appropriate schema-name to the VACUUM statement. +do_execsql_test e_vacuum-2.1.7 { VACUUM aux; } {} +do_test e_vacuum-2.1.8 { expr {[file size test.db2]<$::original_size} } 1 + +# EVIDENCE-OF: R-17495-17419 The VACUUM command may change the ROWIDs of +# entries in any tables that do not have an explicit INTEGER PRIMARY +# KEY. +# +# Tests e_vacuum-3.1.1 - 3.1.2 demonstrate that rowids can change when +# a database is VACUUMed. Tests e_vacuum-3.1.3 - 3.1.4 show that adding +# an INTEGER PRIMARY KEY column to a table stops this from happening. +# +# Update 2019-01-07: Rowids are now preserved by VACUUM. +# +do_execsql_test e_vacuum-3.1.1 { + CREATE TABLE t4(x); + INSERT INTO t4(x) VALUES('x'); + INSERT INTO t4(x) VALUES('y'); + INSERT INTO t4(x) VALUES('z'); + DELETE FROM t4 WHERE x = 'y'; + SELECT rowid, x FROM t4; +} {1 x 3 z} +do_execsql_test e_vacuum-3.1.2 { + VACUUM; + SELECT rowid, x FROM t4; +} {1 x 2 z} + +# Rowids are preserved if an INTEGER PRIMARY KEY is used +do_execsql_test e_vacuum-3.1.3 { + CREATE TABLE t5(x, y INTEGER PRIMARY KEY); + INSERT INTO t5(x) VALUES('x'); + INSERT INTO t5(x) VALUES('y'); + INSERT INTO t5(x) VALUES('z'); + DELETE FROM t5 WHERE x = 'y'; + SELECT rowid, x FROM t5; +} {1 x 3 z} +do_execsql_test e_vacuum-3.1.4 { + VACUUM; + SELECT rowid, x FROM t5; +} {1 x 3 z} + +# Rowid is preserved for VACUUM INTO +do_execsql_test e_vacuum-3.1.5 { + DROP TABLE t5; + CREATE TABLE t5(x); + INSERT INTO t5(x) VALUES('x'); + INSERT INTO t5(x) VALUES('y'); + INSERT INTO t5(x) VALUES('z'); + DELETE FROM t5 WHERE x = 'y'; + SELECT rowid, x FROM t5; +} {1 x 3 z} +forcedelete test2.db +do_execsql_test e_vacuum-3.1.6 { + VACUUM INTO 'test2.db'; + ATTACH 'test2.db' AS aux1; + SELECT rowid, x FROM aux1.t5; + DETACH aux1; +} {1 x 3 z} + +# Rowids are not renumbered if the table being vacuumed +# has indexes. +do_execsql_test e_vacuum-3.1.7 { + DROP TABLE t5; + CREATE TABLE t5(x,y,z); + INSERT INTO t5(x) VALUES('x'); + INSERT INTO t5(x) VALUES('y'); + INSERT INTO t5(x) VALUES('z'); + UPDATE t5 SET y=x, z=random(); + DELETE FROM t5 WHERE x = 'y'; + CREATE INDEX t5x ON t5(x); + CREATE UNIQUE INDEX t5y ON t5(y); + CREATE INDEX t5zxy ON t5(z,x,y); + SELECT rowid, x FROM t5; +} {1 x 3 z} +do_execsql_test e_vacuum-3.1.8 { + VACUUM; + SELECT rowid, x FROM t5; +} {1 x 3 z} + +# EVIDENCE-OF: R-12218-18073 A VACUUM will fail if there is an open +# transaction on the database connection that is attempting to run the +# VACUUM. +# +do_execsql_test e_vacuum-3.2.1.1 { BEGIN } {} +do_catchsql_test e_vacuum-3.2.1.2 { + VACUUM +} {1 {cannot VACUUM from within a transaction}} +do_execsql_test e_vacuum-3.2.1.3 { COMMIT } {} +do_execsql_test e_vacuum-3.2.1.4 { VACUUM } {} +do_execsql_test e_vacuum-3.2.1.5 { SAVEPOINT x } {} +do_catchsql_test e_vacuum-3.2.1.6 { + VACUUM +} {1 {cannot VACUUM from within a transaction}} +do_execsql_test e_vacuum-3.2.1.7 { COMMIT } {} +do_execsql_test e_vacuum-3.2.1.8 { VACUUM } {} + +create_db +do_test e_vacuum-3.2.2.1 { + set res "" + db eval { SELECT a FROM t1 } { + if {$a == 10} { set res [catchsql VACUUM] } + } + set res +} {1 {cannot VACUUM - SQL statements in progress}} + + +# EVIDENCE-OF: R-55138-13241 An alternative to using the VACUUM command +# to reclaim space after data has been deleted is auto-vacuum mode, +# enabled using the auto_vacuum pragma. +# +do_test e_vacuum-3.3.1 { + create_db { PRAGMA auto_vacuum = FULL } + execsql { PRAGMA auto_vacuum } +} {1} + +# EVIDENCE-OF: R-64844-34873 When auto_vacuum is enabled for a database +# free pages may be reclaimed after deleting data, causing the file to +# shrink, without rebuilding the entire database using VACUUM. +# +do_test e_vacuum-3.3.2.1 { + create_db { PRAGMA auto_vacuum = FULL } + execsql { + DELETE FROM t1; + DELETE FROM t2; + } + expr {[file size test.db] / 1024} +} {8} +do_test e_vacuum-3.3.2.2 { + create_db { PRAGMA auto_vacuum = INCREMENTAL } + execsql { + DELETE FROM t1; + DELETE FROM t2; + PRAGMA incremental_vacuum; + } + expr {[file size test.db] / 1024} +} {8} + +finish_test diff --git a/test/e_wal.test b/test/e_wal.test new file mode 100644 index 0000000..c9c5e96 --- /dev/null +++ b/test/e_wal.test @@ -0,0 +1,231 @@ +# 2011 May 06 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix e_wal + +db close +forcedelete test.db-shm +testvfs oldvfs -iversion 1 + + +# EVIDENCE-OF: R-58297-14483 WAL databases can be created, read, and +# written even if shared memory is unavailable as long as the +# locking_mode is set to EXCLUSIVE before the first attempted access. +# +# EVIDENCE-OF: R-00449-33772 This feature allows WAL databases to be +# created, read, and written by legacy VFSes that lack the "version 2" +# shared-memory methods xShmMap, xShmLock, xShmBarrier, and xShmUnmap on +# the sqlite3_io_methods object. +# +# 1.1: "create" tests. +# 1.2: "read" tests. +# 1.3: "write" tests. +# +# All three done with VFS "oldvfs", which has iVersion==1 and so does +# not support shared memory. +# +sqlite3 db test.db -vfs oldvfs +do_execsql_test 1.1.1 { + PRAGMA journal_mode = WAL; +} {delete} +do_execsql_test 1.1.2 { + PRAGMA locking_mode = EXCLUSIVE; + PRAGMA journal_mode = WAL; +} {exclusive wal} +do_execsql_test 1.1.3 { + CREATE TABLE t1(x, y); + INSERT INTO t1 VALUES(1, 2); +} {} +do_test 1.1.4 { + list [file exists test.db-shm] [file exists test.db-wal] +} {0 1} + +do_test 1.2.1 { + db close + sqlite3 db test.db -vfs oldvfs + catchsql { SELECT * FROM t1 } +} {1 {unable to open database file}} +do_test 1.2.2 { + execsql { PRAGMA locking_mode = EXCLUSIVE } + execsql { SELECT * FROM t1 } +} {1 2} +do_test 1.2.3 { + list [file exists test.db-shm] [file exists test.db-wal] +} {0 1} + +do_test 1.3.1 { + db close + sqlite3 db test.db -vfs oldvfs + catchsql { INSERT INTO t1 VALUES(3, 4) } +} {1 {unable to open database file}} +do_test 1.3.2 { + execsql { PRAGMA locking_mode = EXCLUSIVE } + execsql { INSERT INTO t1 VALUES(3, 4) } + execsql { SELECT * FROM t1 } +} {1 2 3 4} +do_test 1.3.3 { + list [file exists test.db-shm] [file exists test.db-wal] +} {0 1} + +# EVIDENCE-OF: R-31969-57825 If EXCLUSIVE locking mode is set prior to +# the first WAL-mode database access, then SQLite never attempts to call +# any of the shared-memory methods and hence no shared-memory wal-index +# is ever created. +# +db close +sqlite3 db test.db +do_execsql_test 2.1.1 { + PRAGMA locking_mode = EXCLUSIVE; + SELECT * FROM t1; +} {exclusive 1 2 3 4} +do_test 2.1.2 { + list [file exists test.db-shm] [file exists test.db-wal] +} {0 1} + +# EVIDENCE-OF: R-36328-16367 In that case, the database connection +# remains in EXCLUSIVE mode as long as the journal mode is WAL; attempts +# to change the locking mode using "PRAGMA locking_mode=NORMAL;" are +# no-ops. +# +do_execsql_test 2.2.1 { + PRAGMA locking_mode = NORMAL; + SELECT * FROM t1; +} {exclusive 1 2 3 4} +do_test 2.2.2 { + sqlite3 db2 test.db + catchsql {SELECT * FROM t1} db2 +} {1 {database is locked}} +db2 close + +# EVIDENCE-OF: R-63522-46088 The only way to change out of EXCLUSIVE +# locking mode is to first change out of WAL journal mode. +# +do_execsql_test 2.3.1 { + PRAGMA journal_mode = DELETE; + SELECT * FROM t1; +} {delete 1 2 3 4} +do_test 2.3.2 { + sqlite3 db2 test.db + catchsql {SELECT * FROM t1} db2 +} {1 {database is locked}} +do_execsql_test 2.3.3 { + PRAGMA locking_mode = NORMAL; + SELECT * FROM t1; +} {normal 1 2 3 4} +do_test 2.3.4 { + sqlite3 db2 test.db + catchsql {SELECT * FROM t1} db2 +} {0 {1 2 3 4}} +db2 close +db close + + +# EVIDENCE-OF: R-57239-11845 If NORMAL locking mode is in effect for the +# first WAL-mode database access, then the shared-memory wal-index is +# created. +# +do_test 3.0 { + sqlite3 db test.db + execsql { PRAGMA journal_mode = WAL } + db close +} {} +do_test 3.1 { + sqlite3 db test.db + execsql { SELECT * FROM t1 } + list [file exists test.db-shm] [file exists test.db-wal] +} {1 1} + +# EVIDENCE-OF: R-13779-07711 As long as exactly one connection is using +# a shared-memory wal-index, the locking mode can be changed freely +# between NORMAL and EXCLUSIVE. +# +do_execsql_test 3.2.1 { + PRAGMA locking_mode = EXCLUSIVE; + PRAGMA locking_mode = NORMAL; + PRAGMA locking_mode = EXCLUSIVE; + INSERT INTO t1 VALUES(5, 6); +} {exclusive normal exclusive} +do_test 3.2.2 { + sqlite3 db2 test.db + catchsql { SELECT * FROM t1 } db2 +} {1 {database is locked}} + +# EVIDENCE-OF: R-10993-11647 It is only when the shared-memory wal-index +# is omitted, when the locking mode is EXCLUSIVE prior to the first +# WAL-mode database access, that the locking mode is stuck in EXCLUSIVE. +# +do_execsql_test 3.2.3 { + PRAGMA locking_mode = NORMAL; + SELECT * FROM t1; +} {normal 1 2 3 4 5 6} +do_test 3.2.4 { + catchsql { SELECT * FROM t1 } db2 +} {0 {1 2 3 4 5 6}} + +do_catchsql_test 3.2.5 { + PRAGMA locking_mode = EXCLUSIVE; + INSERT INTO t1 VALUES(7, 8); +} {1 {database is locked}} + +db2 close + +# EVIDENCE-OF: R-46197-42811 This means that the underlying VFS must +# support the "version 2" shared-memory. +# +# EVIDENCE-OF: R-55316-21772 If the VFS does not support shared-memory +# methods, then the attempt to open a database that is already in WAL +# mode, or the attempt convert a database into WAL mode, will fail. +# +db close +do_test 3.4.1 { + sqlite3 db test.db -vfs oldvfs + catchsql { SELECT * FROM t1 } +} {1 {unable to open database file}} +db close +do_test 3.4.2 { + forcedelete test.db2 + sqlite3 db test.db2 -vfs oldvfs + catchsql { PRAGMA journal_mode = WAL } +} {0 delete} +db close + + +# EVIDENCE-OF: R-45540-25505 To prevent older versions of SQLite (prior +# to version 3.7.0, 2010-07-22) from trying to recover a WAL-mode +# database (and making matters worse) the database file format version +# numbers (bytes 18 and 19 in the database header) are increased from 1 +# to 2 in WAL mode. +# +reset_db +do_execsql_test 4.1.1 { CREATE TABLE t1(x, y) } +do_test 4.1.2 { hexio_read test.db 18 2 } {0101} +do_execsql_test 4.1.3 { PRAGMA journal_mode = wAL } {wal} +do_test 4.1.4 { hexio_read test.db 18 2 } {0202} + + +# EVIDENCE-OF: R-02535-05811 One can explicitly change out of WAL mode +# using a pragma such as this: PRAGMA journal_mode=DELETE; +# +do_execsql_test 4.2.1 { INSERT INTO t1 VALUES(1, 1); } {} +do_test 4.2.2 { file exists test.db-wal } {1} +do_execsql_test 4.2.3 { PRAGMA journal_mode = delete } {delete} +do_test 4.2.4 { file exists test.db-wal } {0} + +# EVIDENCE-OF: R-60175-02388 Deliberately changing out of WAL mode +# changes the database file format version numbers back to 1 so that +# older versions of SQLite can once again access the database file. +# +do_test 4.3 { hexio_read test.db 18 2 } {0101} + +finish_test diff --git a/test/e_walauto.test b/test/e_walauto.test new file mode 100644 index 0000000..7665b1b --- /dev/null +++ b/test/e_walauto.test @@ -0,0 +1,214 @@ +# 2014 December 04 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/wal_common.tcl +set testprefix e_walauto + +# Do not run this test on OpenBSD, as it depends on read() and mmap both +# accessing the same coherent view of the "test.db-shm" file. This doesn't +# work on OpenBSD. +# +if {$tcl_platform(os) == "OpenBSD"} { + finish_test + return +} + +# This module uses hard-coded offsets which do not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} + + +proc read_nbackfill {} { + seek $::shmfd 96 + binary scan [read $::shmfd 4] n nBackfill + set nBackfill +} +proc read_mxframe {} { + seek $::shmfd 16 + binary scan [read $::shmfd 4] n mxFrame + set mxFrame +} + +# Assuming that the main db for database handle +# +proc do_autocommit_threshold_test {tn value} { + + set nBackfillSaved [read_nbackfill] + while {1} { + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + if {[read_mxframe] >= $value} break + } + + set nBackfillNew [read_nbackfill] + uplevel [list do_test $tn "expr $nBackfillNew > $nBackfillSaved" 1] +} + +# EVIDENCE-OF: R-30135-06439 The wal_autocheckpoint pragma can be used +# to invoke this interface from SQL. +# +# All tests in this file are run twice - once using the +# sqlite3_wal_autocheckpoint() API, and once using "PRAGMA +# wal_autocheckpoint". +# +foreach {tn code} { + 1 { + proc autocheckpoint {db value} { + uplevel [list $db eval "PRAGMA wal_autocheckpoint = $value"] + } + } + + 2 { + proc autocheckpoint {db value} { + uplevel [list sqlite3_wal_autocheckpoint $db $value] + return $value + } + } +} { + + eval $code + + reset_db + execsql { PRAGMA auto_vacuum = 0 } + do_execsql_test 1.$tn.0 { PRAGMA journal_mode = WAL } {wal} + do_execsql_test 1.$tn.1 { CREATE TABLE t1(a, b) } + set shmfd [open "test.db-shm" rb] + + # EVIDENCE-OF: R-41531-51083 Every new database connection defaults to + # having the auto-checkpoint enabled with a threshold of 1000 or + # SQLITE_DEFAULT_WAL_AUTOCHECKPOINT pages. + # + do_autocommit_threshold_test 1.$tn.2 1000 + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + do_autocommit_threshold_test 1.$tn.3 1000 + + # EVIDENCE-OF: R-38128-34102 The sqlite3_wal_autocheckpoint(D,N) is a + # wrapper around sqlite3_wal_hook() that causes any database on database + # connection D to automatically checkpoint after committing a + # transaction if there are N or more frames in the write-ahead log file. + # + do_test 1.$tn.4 { + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + autocheckpoint db 100 + } {100} + do_autocommit_threshold_test 1.$tn.5 100 + + do_test 1.$tn.6 { + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + autocheckpoint db 500 + } {500} + do_autocommit_threshold_test 1.$tn.7 500 + + # EVIDENCE-OF: R-26993-43540 Passing zero or a negative value as the + # nFrame parameter disables automatic checkpoints entirely. + # + do_test 1.$tn.7 { + autocheckpoint db 0 ;# Set to zero + for {set i 0} {$i < 10000} {incr i} { + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + } + expr {[file size test.db-wal] > (5 * 1024 * 1024)} + } 1 + do_test 1.$tn.8 { + sqlite3_wal_checkpoint_v2 db truncate + file size test.db-wal + } 0 + do_test 1.$tn.9 { + autocheckpoint db -4 ;# Set to a negative value + for {set i 0} {$i < 10000} {incr i} { + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + } + expr {[file size test.db-wal] > (5 * 1024 * 1024)} + } 1 + + # EVIDENCE-OF: R-10203-42688 The callback registered by this function + # replaces any existing callback registered using sqlite3_wal_hook(). + # + set ::wal_hook_callback 0 + proc wal_hook_callback {args} { incr ::wal_hook_callback ; return 0 } + do_test 1.$tn.10.1 { + db wal_hook wal_hook_callback + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + set ::wal_hook_callback + } 2 + do_test 1.$tn.10.2 { + autocheckpoint db 100 + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + set ::wal_hook_callback + } 2 + + # EVIDENCE-OF: R-17497-43474 Likewise, registering a callback using + # sqlite3_wal_hook() disables the automatic checkpoint mechanism + # configured by this function. + do_test 1.$tn.11.1 { + sqlite3_wal_checkpoint_v2 db truncate + file size test.db-wal + } 0 + do_test 1.$tn.11.2 { + autocheckpoint db 100 + for {set i 0} {$i < 1000} {incr i} { + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + } + expr {[file size test.db-wal] < (1 * 1024 * 1024)} + } 1 + do_test 1.$tn.11.3 { + db wal_hook wal_hook_callback + for {set i 0} {$i < 1000} {incr i} { + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + } + expr {[file size test.db-wal] < (1 * 1024 * 1024)} + } 0 + + # EVIDENCE-OF: R-33080-59193 Checkpoints initiated by this mechanism + # are PASSIVE. + # + set ::busy_callback_count 0 + proc busy_callback {args} { + incr ::busy_callback_count + return 0 + } + do_test 1.$tn.12.1 { + sqlite3_wal_checkpoint_v2 db truncate + autocheckpoint db 100 + db busy busy_callback + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + } {} + do_test 1.$tn.12.2 { + sqlite3 db2 test.db + db2 eval { BEGIN; SELECT * FROM t1 LIMIT 10; } + read_nbackfill + } {0} + do_test 1.$tn.12.3 { + for {set i 0} {$i < 1000} {incr i} { + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + } + read_nbackfill + } {2} + do_test 1.$tn.12.4 { + set ::busy_callback_count + } {0} + db2 close + + do_test 1.$tn.12.5 { + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + read_nbackfill + } {1559} + + db close + close $shmfd +} + +finish_test diff --git a/test/e_walckpt.test b/test/e_walckpt.test new file mode 100644 index 0000000..3b1f3b0 --- /dev/null +++ b/test/e_walckpt.test @@ -0,0 +1,753 @@ +# 2014 December 04 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/lock_common.tcl +source $testdir/wal_common.tcl +set testprefix e_walckpt + +# The following two commands are used to determine if any of the files +# "test.db", "test.db2" and "test.db3" are modified by a test case. +# +# The [save_db_hashes] command saves a hash of the current contents of +# all three files in global variables. The [compare_db_hashes] compares +# the current contents with the saved hashes and returns a list of the +# files that have changed. +# +proc save_db_hashes {} { + global H + foreach f {test.db test.db2 test.db3} { + set H($f) 0 + catch { set H($f) [md5file $f] } + } +} +proc compare_db_hashes {} { + global H + set ret [list] + foreach f {test.db test.db2 test.db3} { + set expect 0 + catch { set expect [md5file $f] } + if {$H($f) != $expect} { lappend ret $f } + } + set ret +} + +#------------------------------------------------------------------------- +# All calls to the [sqlite3_wal_checkpoint_v2] command made within this +# file use this wrapper. It's sole purpose is to throw an error if the +# following requirement is violated: +# +# EVIDENCE-OF: R-60567-47780 Unless it returns SQLITE_MISUSE, the +# sqlite3_wal_checkpoint_v2() interface sets the error information that +# is queried by sqlite3_errcode() and sqlite3_errmsg(). +# +proc wal_checkpoint_v2 {db args} { + set rc [catch { + uplevel sqlite3_wal_checkpoint_v2 $db $args + } msg] + + set errcode "SQLITE_OK" + if {$rc} { + set errcode [lindex [split $msg " "] 0] + } elseif { [lindex $msg 0] } { + set errcode "SQLITE_BUSY" + } + + if {$errcode != "SQLITE_MISUSE" && [sqlite3_errcode $db] != $errcode} { + error "sqlite3_errcode mismatch! (1) $errcode!=[sqlite3_errcode $db]" + } + + if {$rc==0} { + return $msg + } else { + error $msg + } +} + + +# The following tests are run 3 times, each using a different method of +# invoking a checkpoint: +# +# 1) Using sqlite3_wal_checkpoint_v2() +# 2) Using "PRAGMA wal_checkpoint" +# 3) Using sqlite3_wal_checkpoint() in place of checkpoint_v2(PASSIVE) +# +# Cases (2) and (3) are to show that the following statements are +# correct, respectively: +# +# EVIDENCE-OF: R-36706-10507 The PRAGMA wal_checkpoint command can be +# used to invoke this interface from SQL. +# +# EVIDENCE-OF: R-41613-20553 The sqlite3_wal_checkpoint(D,X) is +# equivalent to +# sqlite3_wal_checkpoint_v2(D,X,SQLITE_CHECKPOINT_PASSIVE,0,0). +# +foreach {tn script} { + 1 { + proc checkpoint {db mode args} { + eval wal_checkpoint_v2 [list $db] [list $mode] $args + } + } + + 2 { + proc checkpoint {db mode args} { + set sql "PRAGMA wal_checkpoint = $mode" + if {[llength $args] && [lindex $args 0]!=""} { + set sql "PRAGMA [lindex $args 0].wal_checkpoint = $mode" + } + set rc [catch { $db eval $sql } msg] + if {$rc} { + regsub {database} $msg {database:} msg + error "[sqlite3_errcode $db] - $msg" + } + set msg + } + } + + 3 { + proc checkpoint {db mode args} { + if {$mode == "passive"} { + set rc [eval sqlite3_wal_checkpoint [list $db] $args] + if {$rc != "SQLITE_OK"} { + error "$rc - [sqlite3_errmsg $db]" + } + } else { + eval wal_checkpoint_v2 [list $db] [list $mode] $args + } + } + } + +} { + + eval $script + + reset_db + forcedelete test.db2 test.db3 test.db4 + execsql { + ATTACH 'test.db2' AS aux; + ATTACH 'test.db3' AS aux2; + ATTACH 'test.db4' AS aux3; + CREATE TABLE t1(x); + CREATE TABLE aux.t2(x); + CREATE TABLE aux2.t3(x); + CREATE TABLE aux3.t4(x); + PRAGMA main.journal_mode = WAL; + PRAGMA aux.journal_mode = WAL; + PRAGMA aux2.journal_mode = WAL; + /* Leave aux4 in rollback mode */ + } + + # EVIDENCE-OF: R-49787-09095 The sqlite3_wal_checkpoint_v2(D,X,M,L,C) + # interface runs a checkpoint operation on database X of database + # connection D in mode M. Status information is written back into + # integers pointed to by L and C. + # + # Tests 1, 2 and 3 below verify the "on database X" part of the + # above. Other parts of this requirement are tested below. + # + # EVIDENCE-OF: R-00653-06026 If parameter zDb is NULL or points to a + # zero length string, then the specified operation is attempted on all + # WAL databases attached to database connection db. + # + # Tests 4 and 5 below test this. + # + foreach {tn2 zDb dblist} { + 1 main test.db + 2 aux test.db2 + 3 aux2 test.db3 + 4 "" {test.db test.db2 test.db3} + 5 - {test.db test.db2 test.db3} + 6 temp {} + } { + do_test $tn.1.$tn2 { + execsql { + INSERT INTO t1 VALUES(1); + INSERT INTO t2 VALUES(2); + INSERT INTO t3 VALUES(3); + } + save_db_hashes + + if {$zDb == "-"} { + checkpoint db passive + } else { + checkpoint db passive $zDb + } + + compare_db_hashes + } $dblist + } + + # EVIDENCE-OF: R-38207-48996 If zDb is not NULL (or a zero length + # string) and is not the name of any attached database, SQLITE_ERROR is + # returned to the caller. + do_test $tn.2.1 { + list [catch { checkpoint db passive notadb } msg] $msg + } {1 {SQLITE_ERROR - unknown database: notadb}} + + # EVIDENCE-OF: R-14303-42483 If database zDb is the name of an attached + # database that is not in WAL mode, SQLITE_OK is returned and both + # *pnLog and *pnCkpt set to -1. + # + if {$tn==3} { + # With sqlite3_wal_checkpoint() the two output variables cannot be + # tested. So just test that no error is returned when attempting to + # checkpoint a db in rollback mode. + do_test $tn.2.2.a { checkpoint db passive aux3 } {} + } else { + do_test $tn.2.2.b { checkpoint db passive aux3 } {0 -1 -1} + } + + # EVIDENCE-OF: R-62028-47212 All calls obtain an exclusive "checkpoint" + # lock on the database file. + db close + testvfs tvfs + tvfs filter xShmLock + tvfs script filelock + proc filelock {method file handle details} { + # Test for an exclusive checkpoint lock. A checkpoint lock locks a + # single byte starting at offset 1. + if {$details == "1 1 lock exclusive"} { set ::seen_checkpoint_lock 1 } + } + sqlite3 db test.db -vfs tvfs + do_test $tn.3.1 { + execsql { INSERT INTO t1 VALUES('xyz') } + unset -nocomplain ::seen_checkpoint_lock + checkpoint db passive + set ::seen_checkpoint_lock + } {1} + db close + tvfs delete + reset_db + + + + + #----------------------------------------------------------------------- + # EVIDENCE-OF: R-10421-19736 If any other process is running a + # checkpoint operation at the same time, the lock cannot be obtained and + # SQLITE_BUSY is returned. + # + # EVIDENCE-OF: R-53820-33897 Even if there is a busy-handler configured, + # it will not be invoked in this case. + # + testvfs tvfs + tvfs filter xWrite + sqlite3 db test.db -vfs tvfs + sqlite3 db2 test.db -vfs tvfs + + do_test $tn.3.2.1 { + db2 eval { + PRAGMA auto_vacuum = 0; + PRAGMA journal_mode = WAL; + CREATE TABLE t1(x, y); + INSERT INTO t1 VALUES(1,2); + INSERT INTO t1 VALUES(3,4); + INSERT INTO t1 VALUES(5,6); + } + file size test.db-wal + } [wal_file_size 5 1024] + + + # Connection [db] runs a checkpoint. During this checkpoint, each + # time it calls xWrite() to write a page into the database file, we + # attempt to start a checkpoint using [db2]. According to the + # first requirement being tested, this should return SQLITE_BUSY. According + # to the second, the busy-handler belonging to [db2] should not be + # invoked. + # + set ::write_count 0 + set ::write_errors [list] + proc busy_callback {args} { + lappend ::write_errors "busy handler called!" + } + proc write_callback {args} { + set rc [catch {checkpoint db2 passive} msg] + if {0==[regexp "database is locked" $msg] && $msg!="1 -1 -1"} { + lappend ::write_errors "$rc $msg" + } + incr ::write_count + } + db2 busy busy_callback + tvfs script write_callback + + do_test $tn.3.2.2 { + db eval {SELECT * FROM sqlite_master} + checkpoint db full + set ::write_count + } {2} + + do_test $tn.3.2.3 { + set ::write_errors + } {} + + db close + db2 close + tvfs delete + + proc busy_handler {mode busy_handler_mode n} { + incr ::busy_handler_counter + switch -- $busy_handler_mode { + 1 { + # Do nothing. Do not block. + return 1 + } + + 2 { + # Close first the reader, then later the writer. Give up before + # closing the [db6] reader. + if {$n==5} { catch {db2 eval commit} } + if {$n==10} { catch {db3 eval commit} } + if {$n==15} { return 1 } + return 0 + } + + 3 { + # Close first the writer, then later the reader. And finally the + # [db6] reader. + if {$n==5} { catch {db2 eval commit} } + if {$n==10} { catch {db3 eval commit} } + if {$n==15} { catch {db6 eval commit} } + return 0 + } + } + } + + foreach {mode busy_handler_mode} { + passive 1 + full 1 full 2 full 3 + restart 1 restart 2 restart 3 + truncate 1 truncate 2 truncate 3 + } { + set tp "$tn.$mode.$busy_handler_mode" + + set ::sync_counter 0 + + # Set up a callback function for xSync and xWrite calls made during + # the checkpoint. + # + set ::checkpoint_ongoing 0 + proc tvfs_callback {method args} { + if {$::checkpoint_ongoing==0} return + + set tail [file tail [lindex $args 0]] + if {$method == "xSync" && $tail == "test.db"} { + incr ::sync_counter + } + if {$method == "xWrite" && $tail=="test.db"} { + if {$::write_ok < 0} { + set ::write_ok [expr ![catch {db5 eval { BEGIN IMMEDIATE }}]] + catch { db5 eval ROLLBACK } + } + if {$::read_ok < 0} { + set ::read_ok [expr ![catch {db5 eval { SELECT * FROM t1 }}]] + } + + # If one has not already been opened, open a read-transaction using + # connection [db6] + catch { db6 eval { BEGIN ; SELECT * FROM sqlite_master } } msg + } + if {$method == "xShmLock" } { + set details [lindex $args 2] + if {$details == "0 1 lock exclusive"} { set ::seen_writer_lock 1 } + } + } + + catch { db close } + forcedelete test.db + testvfs tvfs + sqlite3 db test.db -vfs tvfs + #tvfs filter xSync + tvfs script tvfs_callback + + do_execsql_test $tp.0 { + CREATE TABLE t1(a, b); + CREATE TABLE t2(a, b); + PRAGMA journal_mode = wal; + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t1 VALUES(3, 4); + INSERT INTO t1 VALUES(5, 6); + } {wal} + + # Open a reader on the current database snapshot. + do_test $tp.1 { + sqlite3 db2 test.db -vfs tvfs + execsql { + BEGIN; + SELECT * FROM t1 UNION ALL SELECT * FROM t2; + } db2 + } {1 2 3 4 5 6} + + # Open a writer. Write a transaction. Then begin, but do not commit, + # a second transaction. + do_test $tp.2 { + sqlite3 db3 test.db -vfs tvfs + execsql { + INSERT INTO t2 VALUES(7, 8); + BEGIN; + INSERT INTO t2 VALUES(9, 10); + SELECT * FROM t1 UNION ALL SELECT * FROM t2; + } db3 + } {1 2 3 4 5 6 7 8 9 10} + + sqlite3 db5 test.db -vfs tvfs + sqlite3 db6 test.db -vfs tvfs + + # Register a busy-handler with connection [db]. + # + db busy [list busy_handler $mode $busy_handler_mode] + set ::sync_counter 0 + set ::busy_handler_counter 0 + set ::read_ok -1 + set ::write_ok -1 + set ::seen_writer_lock 0 + + set ::checkpoint_ongoing 1 + do_test $tp.3 { + checkpoint db $mode main + set {} {} + } {} + set ::checkpoint_ongoing 0 + set ::did_restart_blocking [expr {[catch {db6 eval commit}]}] + + if { $mode=="passive" } { + # EVIDENCE-OF: R-16333-64433 Checkpoint as many frames as possible + # without waiting for any database readers or writers to finish, then + # sync the database file if all frames in the log were checkpointed. + # + # "As many frames as possible" means all but the last two transactions + # (the two that write to table t2, of which the scond is unfinished). + # So copying the db file only we see the t1 change, but not the t2 + # modifications. + # + # The busy handler is not invoked (see below) and the db reader and + # writer are still active - so the checkpointer did not wait for either + # readers or writers. As a result the checkpoint was not finished and + # so the db file is not synced. + # + # EVIDENCE-OF: R-62920-47450 The busy-handler callback is never invoked + # in the SQLITE_CHECKPOINT_PASSIVE mode. + # + # It's not. Test case "$tp.6". + # + do_test $tp.4 { + forcecopy test.db abc.db + sqlite3 db4 abc.db + db4 eval { SELECT * FROM t1 UNION ALL SELECT * FROM t2 } + } {1 2 3 4 5 6} + do_test $tp.5 { set ::sync_counter } 0 + do_test $tp.6 { set ::busy_handler_counter } 0 + db4 close + + db2 eval COMMIT + db3 eval COMMIT + + # EVIDENCE-OF: R-65499-53765 On the other hand, passive mode might leave + # the checkpoint unfinished if there are concurrent readers or writers. + # + # The reader and writer have now dropped their locks. And so a + # checkpoint now is able to checkpoint more frames. Showing that the + # attempt above was left "unfinished". + # + # Also, because the checkpoint finishes this time, the db is synced. + # Which is part of R-16333-64433 above. + # + set ::checkpoint_ongoing 1 + do_test $tp.7 { + checkpoint db $mode main + forcecopy test.db abc.db + sqlite3 db4 abc.db + db4 eval { SELECT * FROM t1 UNION ALL SELECT * FROM t2 } + } {1 2 3 4 5 6 7 8 9 10} + set ::checkpoint_ongoing 0 + do_test $tp.7 { set ::sync_counter } 1 + do_test $tp.8 { set ::busy_handler_counter } 0 + db4 close + } + + if { $mode=="full" || $mode=="restart" || $mode=="truncate" } { + + # EVIDENCE-OF: R-59782-36818 The SQLITE_CHECKPOINT_FULL, RESTART and + # TRUNCATE modes also obtain the exclusive "writer" lock on the + # database file. + # + # Or at least attempts to obtain. + # + do_test $tp.9 { + set ::seen_writer_lock + } {1} + + if {$busy_handler_mode==2 || $busy_handler_mode==3} { + # EVIDENCE-OF: R-59171-47567 This mode blocks (it invokes the + # busy-handler callback) until there is no database writer and all + # readers are reading from the most recent database snapshot. + # + # The test below shows that both the reader and writer have + # finished: + # + # Also restated by the following two. That both busy_handler_mode + # values 2 and 3 work show that both of the following are true - as + # they release the reader and writer transactions in different + # orders. + # + # EVIDENCE-OF: R-60642-04082 If the writer lock cannot be obtained + # immediately, and a busy-handler is configured, it is invoked and the + # writer lock retried until either the busy-handler returns 0 or the + # lock is successfully obtained. + # + # EVIDENCE-OF: R-48107-00250 The busy-handler is also invoked while + # waiting for database readers as described above. + # + do_test $tp.7 { + list [catchsql COMMIT db2] [catchsql COMMIT db3] + } [list \ + {1 {cannot commit - no transaction is active}} \ + {1 {cannot commit - no transaction is active}} \ + ] + + # EVIDENCE-OF: R-29177-48281 It then checkpoints all frames in the log + # file and syncs the database file. + # + do_test $tp.8 { + forcecopy test.db abc.db + sqlite3 db4 abc.db + db4 eval { SELECT * FROM t1 UNION ALL SELECT * FROM t2 } + } {1 2 3 4 5 6 7 8 9 10} + do_test $tp.9 { set ::sync_counter } 1 + db4 close + + # EVIDENCE-OF: R-51867-44713 This mode blocks new database writers + # while it is pending, but new database readers are allowed to continue + # unimpeded. + # + # EVIDENCE-OF: R-47276-58266 Like SQLITE_CHECKPOINT_FULL, this mode + # blocks new database writer attempts while it is pending, but does not + # impede readers. + # + # The first of the above two refers to "full" mode. The second + # to "restart". + # + do_test $tp.10.1 { + list $::write_ok $::read_ok + } {0 1} + + # EVIDENCE-OF: R-12410-31217 This mode works the same way as + # SQLITE_CHECKPOINT_FULL with the addition that after checkpointing the + # log file it blocks (calls the busy-handler callback) until all + # readers are reading from the database file only. + # + # The stuff above passed, so the first part of this requirement + # is met. The second part is tested below. If the checkpoint mode + # was "restart" or "truncate", then the busy-handler will have + # been called to block on wal-file readers. + # + do_test $tp.11 { + set ::did_restart_blocking + } [expr {($mode=="restart"||$mode=="truncate")&&$busy_handler_mode==3}] + + # EVIDENCE-OF: R-44699-57140 This mode works the same way as + # SQLITE_CHECKPOINT_RESTART with the addition that it also truncates + # the log file to zero bytes just prior to a successful return. + if {$mode=="truncate" && $busy_handler_mode==3} { + do_test $tp.12 { + file size test.db-wal + } 0 + } + } elseif {$busy_handler_mode==1} { + + # EVIDENCE-OF: R-34519-06271 SQLITE_BUSY is returned in this case. + if {$tn!=2} { + # ($tn==2) is the loop that uses "PRAGMA wal_checkpoint" + do_test $tp.13 { sqlite3_errcode db } {SQLITE_BUSY} + } + + # EVIDENCE-OF: R-49155-63541 If the busy-handler returns 0 before the + # writer lock is obtained or while waiting for database readers, the + # checkpoint operation proceeds from that point in the same way as + # SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible + # without blocking any further. + do_test $tp.14 { + forcecopy test.db abc.db + sqlite3 db4 abc.db + db4 eval { SELECT * FROM t1 UNION ALL SELECT * FROM t2 } + } {1 2 3 4 5 6} + do_test $tp.15 { set ::sync_counter } 0 + do_test $tp.16 { set ::busy_handler_counter } 1 + db4 close + } + } + + db2 close + db3 close + db5 close + db6 close + } + + db close + tvfs delete +} + +#----------------------------------------------------------------------- +# EVIDENCE-OF: R-03996-12088 The M parameter must be a valid checkpoint +# mode: +# +# Valid checkpoint modes are 0, 1, 2 and 3. +# +sqlite3 db test.db +foreach {tn mode res} { + 0 -1001 {1 {SQLITE_MISUSE - not an error}} + 1 -1 {1 {SQLITE_MISUSE - not an error}} + 2 0 {0 {0 -1 -1}} + 3 1 {0 {0 -1 -1}} + 4 2 {0 {0 -1 -1}} + 5 3 {0 {0 -1 -1}} + 6 4 {1 {SQLITE_MISUSE - not an error}} + 7 114 {1 {SQLITE_MISUSE - not an error}} + 8 1000000 {1 {SQLITE_MISUSE - not an error}} +} { + do_test 4.$tn { + list [catch "wal_checkpoint_v2 db $mode" msg] $msg + } $res +} +db close + +foreach tn {1 2 3} { + forcedelete test.db test.db2 test.db3 + testvfs tvfs + + sqlite3 db test.db -vfs tvfs + execsql { + ATTACH 'test.db2' AS aux2; + ATTACH 'test.db3' AS aux3; + PRAGMA main.journal_mode = WAL; + PRAGMA aux2.journal_mode = WAL; + PRAGMA aux3.journal_mode = WAL; + + CREATE TABLE main.t1(x,y); + CREATE TABLE aux2.t2(x,y); + CREATE TABLE aux3.t3(x,y); + + INSERT INTO t1 VALUES('a', 'b'); + INSERT INTO t2 VALUES('a', 'b'); + INSERT INTO t3 VALUES('a', 'b'); + } + sqlite3 db2 test.db2 -vfs tvfs + + switch -- $tn { + 1 { + # EVIDENCE-OF: R-41299-52117 If no error (SQLITE_BUSY or otherwise) is + # encountered while processing the attached databases, SQLITE_OK is + # returned. + do_test 5.$tn.1 { + lindex [wal_checkpoint_v2 db truncate] 0 + } {0} ;# 0 -> SQLITE_OK + do_test 5.$tn.2 { + list [expr [file size test.db-wal]==0] \ + [expr [file size test.db2-wal]==0] \ + [expr [file size test.db3-wal]==0] + } {1 1 1} + } + + 2 { + # EVIDENCE-OF: R-38578-34175 If an SQLITE_BUSY error is encountered when + # processing one or more of the attached WAL databases, the operation is + # still attempted on any remaining attached databases and SQLITE_BUSY is + # returned at the end. + db2 eval { BEGIN; INSERT INTO t2 VALUES('d', 'e'); } + do_test 5.$tn.1 { + lindex [wal_checkpoint_v2 db truncate] 0 + } {1} ;# 1 -> SQLITE_BUSY + do_test 5.$tn.2 { + list [expr [file size test.db-wal]==0] \ + [expr [file size test.db2-wal]==0] \ + [expr [file size test.db3-wal]==0] + } {1 0 1} + db2 eval ROLLBACK + } + + 3 { + # EVIDENCE-OF: R-38049-07913 If any other error occurs while processing + # an attached database, processing is abandoned and the error code is + # returned to the caller immediately. + tvfs filter xWrite + tvfs script inject_ioerr + proc inject_ioerr {method file args} { + if {[file tail $file]=="test.db2"} { + return "SQLITE_IOERR" + } + return 0 + } + do_test 5.$tn.1 { + list [catch { wal_checkpoint_v2 db truncate } msg] $msg + } {1 {SQLITE_IOERR - disk I/O error}} + do_test 5.$tn.2 { + list [expr [file size test.db-wal]==0] \ + [expr [file size test.db2-wal]==0] \ + [expr [file size test.db3-wal]==0] + } {1 0 0} + tvfs script "" + } + } + + db close + db2 close +} + +reset_db +sqlite3 db2 test.db + +do_test 6.1 { + execsql { + PRAGMA auto_vacuum = 0; + PRAGMA journal_mode = WAL; + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 2); + } + file size test.db-wal +} [wal_file_size 3 1024] + +do_test 6.2 { + db2 eval { BEGIN; SELECT * FROM t1; } + db eval { INSERT INTO t1 VALUES(3, 4) } + file size test.db-wal +} [wal_file_size 4 1024] + +# At this point the log file contains 4 frames. 3 of which it should +# be possible to checkpoint. +# +# EVIDENCE-OF: R-16642-42503 If pnLog is not NULL, then *pnLog is set to +# the total number of frames in the log file or to -1 if the checkpoint +# could not run because of an error or because the database is not in +# WAL mode. +# +# EVIDENCE-OF: R-10514-25250 If pnCkpt is not NULL,then *pnCkpt is set +# to the total number of checkpointed frames in the log file (including +# any that were already checkpointed before the function was called) or +# to -1 if the checkpoint could not run due to an error or because the +# database is not in WAL mode. +# +do_test 6.4 { + lrange [wal_checkpoint_v2 db passive] 1 2 +} {4 3} + +# EVIDENCE-OF: R-37257-17813 Note that upon successful completion of an +# SQLITE_CHECKPOINT_TRUNCATE, the log file will have been truncated to +# zero bytes and so both *pnLog and *pnCkpt will be set to zero. +# +do_test 6.5 { + db2 eval COMMIT + wal_checkpoint_v2 db truncate +} {0 0 0} + + + +finish_test diff --git a/test/e_walhook.test b/test/e_walhook.test new file mode 100644 index 0000000..b4a3156 --- /dev/null +++ b/test/e_walhook.test @@ -0,0 +1,200 @@ +# 2014 December 04 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/wal_common.tcl +set testprefix e_walhook + + +# EVIDENCE-OF: R-00752-43975 The sqlite3_wal_hook() function is used to +# register a callback that is invoked each time data is committed to a +# database in wal mode. +# +# 1.1: shows that the wal-hook is not invoked in rollback mode. +# 1.2: but is invoked in wal mode. +# +set ::wal_hook_count 0 +proc my_wal_hook {args} { + incr ::wal_hook_count + return 0 +} + +do_test 1.1.1 { + db wal_hook my_wal_hook + execsql { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(1); + } + set ::wal_hook_count +} 0 +do_test 1.1.2 { + execsql { PRAGMA journal_mode = wal } + set ::wal_hook_count +} 0 + +do_test 1.3 { + execsql { INSERT INTO t1 VALUES(2) } + set wal_hook_count +} 1 + +do_test 1.4 { + execsql { + BEGIN; + INSERT INTO t1 VALUES(3); + INSERT INTO t1 VALUES(4); + COMMIT; + } + set wal_hook_count +} 2 + +# EVIDENCE-OF: R-65366-15139 The callback is invoked by SQLite after the +# commit has taken place and the associated write-lock on the database +# released +# +set ::read_ok 0 +proc my_wal_hook {args} { + sqlite3 db2 test.db + if {[db2 eval { SELECT * FROM t1 }] == "1 2 3 4 5"} { + set ::read_ok 1 + } + db2 close +} +do_test 2.1 { + execsql { INSERT INTO t1 VALUES(5) } + set ::read_ok +} 1 + +# EVIDENCE-OF: R-44294-52863 The third parameter is the name of the +# database that was written to - either "main" or the name of an +# ATTACH-ed database. +# +# EVIDENCE-OF: R-18913-19355 The fourth parameter is the number of pages +# currently in the write-ahead log file, including those that were just +# committed. +# +set ::wal_hook_args [list] +proc my_wal_hook {dbname nEntry} { + set ::wal_hook_args [list $dbname $nEntry] +} +forcedelete test.db2 +do_test 3.0 { + execsql { + ATTACH 'test.db2' AS aux; + CREATE TABLE aux.t2(x); + PRAGMA aux.journal_mode = wal; + } +} {wal} + +# Database "aux" +do_test 3.1.1 { + set wal_hook_args [list] + execsql { INSERT INTO t2 VALUES('a') } +} {} +do_test 3.1.2 { + set wal_hook_args +} [list aux [wal_frame_count test.db2-wal 1024]] + +# Database "main" +do_test 3.2.1 { + set wal_hook_args [list] + execsql { INSERT INTO t1 VALUES(6) } +} {} +do_test 3.1.2 { + set wal_hook_args +} [list main [wal_frame_count test.db-wal 1024]] + +# EVIDENCE-OF: R-14034-00929 If an error code is returned, that error +# will propagate back up through the SQLite code base to cause the +# statement that provoked the callback to report an error, though the +# commit will have still occurred. +# +proc my_wal_hook {args} { return 1 ;# SQLITE_ERROR } +do_catchsql_test 4.1 { + INSERT INTO t1 VALUES(7) +} {1 {SQL logic error}} + +proc my_wal_hook {args} { return 5 ;# SQLITE_BUSY } +do_catchsql_test 4.2 { + INSERT INTO t1 VALUES(8) +} {1 {database is locked}} + +proc my_wal_hook {args} { return 14 ;# SQLITE_CANTOPEN } +do_catchsql_test 4.3 { + INSERT INTO t1 VALUES(9) +} {1 {unable to open database file}} + +do_execsql_test 4.4 { + SELECT * FROM t1 +} {1 2 3 4 5 6 7 8 9} + +# EVIDENCE-OF: R-10466-53920 Calling sqlite3_wal_hook() replaces any +# previously registered write-ahead log callback. +set ::old_wal_hook 0 +proc my_old_wal_hook {args} { + incr ::old_wal_hook + return 0 +} +db wal_hook my_old_wal_hook +do_test 5.1 { + execsql { INSERT INTO t1 VALUES(10) } + set ::old_wal_hook +} {1} + +# Replace old_wal_hook. Observe that it is not invoked after it has +# been replaced. +proc my_new_wal_hook {args} { return 0 } +db wal_hook my_new_wal_hook +do_test 5.2 { + execsql { INSERT INTO t1 VALUES(11) } + set ::old_wal_hook +} {1} + + + +# EVIDENCE-OF: R-57445-43425 Note that the sqlite3_wal_autocheckpoint() +# interface and the wal_autocheckpoint pragma both invoke +# sqlite3_wal_hook() and will overwrite any prior sqlite3_wal_hook() +# settings. +# +set ::old_wal_hook 0 +proc my_old_wal_hook {args} { incr ::old_wal_hook ; return 0 } +db wal_hook my_old_wal_hook +do_test 6.1.1 { + execsql { INSERT INTO t1 VALUES(12) } + set ::old_wal_hook +} {1} +do_test 6.1.2 { + execsql { PRAGMA wal_autocheckpoint = 1000 } + execsql { INSERT INTO t1 VALUES(12) } + set ::old_wal_hook +} {1} + +# EVIDENCE-OF: R-52629-38967 The first parameter passed to the callback +# function when it is invoked is a copy of the third parameter passed to +# sqlite3_wal_hook() when registering the callback. +# +# This is tricky to test using the tcl interface. However, the +# mechanism used to invoke the tcl script registered as a wal-hook +# depends on the context pointer being correctly passed through. And +# since multiple different wal-hook scripts have been successfully +# invoked by this test script, consider this tested. +# +# EVIDENCE-OF: R-23378-42536 The second is a copy of the database +# handle. +# +# There is an assert() in the C wal-hook used by tclsqlite.c to +# prove this. And that hook has been invoked multiple times when +# running this script. So consider this requirement tested as well. +# + +finish_test diff --git a/test/emptytable.test b/test/emptytable.test new file mode 100644 index 0000000..79cd16e --- /dev/null +++ b/test/emptytable.test @@ -0,0 +1,50 @@ +# 2017-02-15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Test cases to show that a join involving an empty table is very fast. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Build some test data +# +do_execsql_test emptytable-100 { + CREATE TABLE t1(a); + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100) + INSERT INTO t1(a) SELECT x FROM c; + CREATE TABLE empty(x); + SELECT count(*) FROM t1; +} {100} + +# Interrupt queries after 1M cycles to prevent burning excess CPU +proc stopDb {args} { + db interrupt +} +db progress 1000000 {stopDb} + +# Prior to the query planner optimization on 2017-02-15, this query would +# take a ridiculous amount of time. If that optimization stops working, +# the result here will be in interrupt for running too long. +# +do_catchsql_test emptytable-110 { + SELECT count(*) FROM t1, t1, t1, t1, t1, t1, empty; +} {0 0} + +do_catchsql_test emptytable-120 { + SELECT count(*) FROM t1, t1 LEFT JOIN empty; +} {0 10000} +do_catchsql_test emptytable-121 { + SELECT count(*) FROM t1, t1 LEFT JOIN t1, empty; +} {0 0} + + +finish_test diff --git a/test/enc.test b/test/enc.test new file mode 100644 index 0000000..ffe2416 --- /dev/null +++ b/test/enc.test @@ -0,0 +1,252 @@ +# 2002 May 24 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The focus of +# this file is testing the SQLite routines used for converting between the +# various suported unicode encodings (UTF-8, UTF-16, UTF-16le and +# UTF-16be). +# +# $Id: enc.test,v 1.7 2007/05/23 16:23:09 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Skip this test if the build does not support multiple encodings. +# +ifcapable {!utf16} { + finish_test + return +} + +proc do_bincmp_test {testname got expect} { + binary scan $expect \c* expectvals + binary scan $got \c* gotvals + do_test $testname [list set dummy $gotvals] $expectvals +} + +# $utf16 is a UTF-16 encoded string. Swap each pair of bytes around +# to change the byte-order of the string. +proc swap_byte_order {utf16} { + binary scan $utf16 \c* ints + + foreach {a b} $ints { + lappend ints2 $b + lappend ints2 $a + } + + return [binary format \c* $ints2] +} + +# +# Test that the SQLite routines for converting between UTF encodings +# produce the same results as their TCL counterparts. +# +# $testname is the prefix to be used for the test names. +# $str is a string to use for testing (encoded in UTF-8, as normal for TCL). +# +# The test procedure is: +# 1. Convert the string from UTF-8 to UTF-16le and check that the TCL and +# SQLite routines produce the same results. +# +# 2. Convert the string from UTF-8 to UTF-16be and check that the TCL and +# SQLite routines produce the same results. +# +# 3. Use the SQLite routines to convert the native machine order UTF-16 +# representation back to the original UTF-8. Check that the result +# matches the original representation. +# +# 4. Add a byte-order mark to each of the UTF-16 representations and +# check that the SQLite routines can convert them back to UTF-8. For +# byte-order mark info, refer to section 3.10 of the unicode standard. +# +# 5. Take the byte-order marked UTF-16 strings from step 4 and ensure +# that SQLite can convert them both to native byte order UTF-16 +# strings, sans BOM. +# +# Coverage: +# +# sqlite_utf8to16be (step 2) +# sqlite_utf8to16le (step 1) +# sqlite_utf16to8 (steps 3, 4) +# sqlite_utf16to16le (step 5) +# sqlite_utf16to16be (step 5) +# +proc test_conversion {testname str} { + + # Step 1. + set utf16le_sqlite3 [test_translate $str UTF8 UTF16LE] + set utf16le_tcl [encoding convertto unicode $str] + append utf16le_tcl "\x00\x00" + if { $::tcl_platform(byteOrder)!="littleEndian" } { + set utf16le_tcl [swap_byte_order $utf16le_tcl] + } + do_bincmp_test $testname.1 $utf16le_sqlite3 $utf16le_tcl + set utf16le $utf16le_tcl + + # Step 2. + set utf16be_sqlite3 [test_translate $str UTF8 UTF16BE] + set utf16be_tcl [encoding convertto unicode $str] + append utf16be_tcl "\x00\x00" + if { $::tcl_platform(byteOrder)=="littleEndian" } { + set utf16be_tcl [swap_byte_order $utf16be_tcl] + } + do_bincmp_test $testname.2 $utf16be_sqlite3 $utf16be_tcl + set utf16be $utf16be_tcl + + # Step 3. + if { $::tcl_platform(byteOrder)=="littleEndian" } { + set utf16 $utf16le + } else { + set utf16 $utf16be + } + set utf8_sqlite3 [test_translate $utf16 UTF16 UTF8] + do_bincmp_test $testname.3 $utf8_sqlite3 [binarize $str] + + # Step 4 (little endian). + append utf16le_bom "\xFF\xFE" $utf16le + set utf8_sqlite3 [test_translate $utf16le_bom UTF16 UTF8 1] + do_bincmp_test $testname.4.le $utf8_sqlite3 [binarize $str] + + # Step 4 (big endian). + append utf16be_bom "\xFE\xFF" $utf16be + set utf8_sqlite3 [test_translate $utf16be_bom UTF16 UTF8] + do_bincmp_test $testname.4.be $utf8_sqlite3 [binarize $str] + + # Step 5 (little endian to little endian). + set utf16_sqlite3 [test_translate $utf16le_bom UTF16LE UTF16LE] + do_bincmp_test $testname.5.le.le $utf16_sqlite3 $utf16le + + # Step 5 (big endian to big endian). + set utf16_sqlite3 [test_translate $utf16be_bom UTF16 UTF16BE] + do_bincmp_test $testname.5.be.be $utf16_sqlite3 $utf16be + + # Step 5 (big endian to little endian). + set utf16_sqlite3 [test_translate $utf16be_bom UTF16 UTF16LE] + do_bincmp_test $testname.5.be.le $utf16_sqlite3 $utf16le + + # Step 5 (little endian to big endian). + set utf16_sqlite3 [test_translate $utf16le_bom UTF16 UTF16BE] + do_bincmp_test $testname.5.le.be $utf16_sqlite3 $utf16be +} + +translate_selftest + +test_conversion enc-1 "hello world" +test_conversion enc-2 "sqlite" +test_conversion enc-3 "" +test_conversion enc-X "\u0100" +test_conversion enc-4 "\u1234" +test_conversion enc-5 "\u4321abc" +test_conversion enc-6 "\u4321\u1234" +test_conversion enc-7 [string repeat "abcde\u00EF\u00EE\uFFFCabc" 100] +test_conversion enc-8 [string repeat "\u007E\u007F\u0080\u0081" 100] +test_conversion enc-9 [string repeat "\u07FE\u07FF\u0800\u0801\uFFF0" 100] +test_conversion enc-10 [string repeat "\uE000" 100] + +proc test_collate {enc zLeft zRight} { + return [string compare $zLeft $zRight] +} +add_test_collate $::DB 0 0 1 +do_test enc-11.1 { + execsql { + CREATE TABLE ab(a COLLATE test_collate, b); + INSERT INTO ab VALUES(CAST (X'C388' AS TEXT), X'888800'); + INSERT INTO ab VALUES(CAST (X'C0808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808388' AS TEXT), X'888800'); + CREATE INDEX ab_i ON ab(a, b); + } +} {} +do_test enc-11.2 { + set cp200 "\u00C8" + execsql { + SELECT count(*) FROM ab WHERE a = $::cp200; + } +} {2} + +#------------------------------------------------------------------------- +reset_db +forcedelete test.db2 +forcedelete test.db3 + +do_execsql_test enc-12.0 { + PRAGMA encoding = 'utf-8'; + CREATE TABLE t1(a, b, c); + INSERT INTO t1 VALUES('a', 'b', 'c'); + ATTACH 'test.db3' AS aux; + CREATE TABLE aux.t3(x, y, z); + INSERT INTO t3 VALUES('xxx', 'yyy', 'zzz'); + PRAGMA encoding; +} {UTF-8} + +do_test enc-12.1 { + sqlite3 db2 test.db2 + db2 eval { + PRAGMA encoding = 'UTF-16le'; + CREATE TABLE t2(d, e, f); + INSERT INTO t2 VALUES('d', 'e', 'f'); + PRAGMA encoding; + } +} {UTF-16le} + +do_test enc-12.2 { + db2 backup test.db + db2 close +} {} + +do_catchsql_test enc-12.3 { + SELECT * FROM t2; +} {1 {attached databases must use the same text encoding as main database}} + +db close +sqlite3 db test.db3 +do_execsql_test enc-12.4 { + SELECT * FROM t3; + PRAGMA encoding = 'UTF-16le'; + SELECT * FROM t3; +} {xxx yyy zzz xxx yyy zzz} + +db close +sqlite3 db test.db3 +breakpoint +do_execsql_test enc-12.5 { + PRAGMA encoding = 'UTF-16le'; + PRAGMA encoding; +} {UTF-8} + +reset_db +do_execsql_test enc-12.6 { + PRAGMA encoding = 'UTF-8'; + CREATE TEMP TABLE t1(a, b, c); + INSERT INTO t1 VALUES('xxx', 'yyy', 'zzz'); +} +do_test enc-12.7 { + sqlite3 db2 test.db2 + db2 backup test.db + db2 close + db eval { + SELECT * FROM t1; + } +} {xxx yyy zzz} +do_catchsql_test enc-12.8 { + SELECT * FROM t2; + SELECT * FROM t1; +} {1 {attached databases must use the same text encoding as main database}} + +db close +sqlite3 db test.db +do_execsql_test enc-12.9 { + CREATE TEMP TABLE t1(a, b, c); + INSERT INTO t1 VALUES('xxx', 'yyy', 'zzz'); +} +do_execsql_test enc-12.10 { + SELECT * FROM t2; + SELECT * FROM t1; +} {d e f xxx yyy zzz} + +finish_test diff --git a/test/enc2.test b/test/enc2.test new file mode 100644 index 0000000..81e7bfd --- /dev/null +++ b/test/enc2.test @@ -0,0 +1,567 @@ +# 2002 May 24 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The focus of +# this file is testing the SQLite routines used for converting between the +# various suported unicode encodings (UTF-8, UTF-16, UTF-16le and +# UTF-16be). +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If UTF16 support is disabled, ignore the tests in this file +# +ifcapable {!utf16} { + finish_test + return +} + +# The rough organisation of tests in this file is: +# +# enc2.1.*: Simple tests with a UTF-8 db. +# enc2.2.*: Simple tests with a UTF-16LE db. +# enc2.3.*: Simple tests with a UTF-16BE db. +# enc2.4.*: Test that attached databases must have the same text encoding +# as the main database. +# enc2.5.*: Test the behavior of the library when a collation sequence is +# not available for the most desirable text encoding. +# enc2.6.*: Similar test for user functions. +# enc2.7.*: Test that the VerifyCookie opcode protects against assuming the +# wrong text encoding for the database. +# enc2.8.*: Test sqlite3_complete16() +# + +db close + +# Return the UTF-8 representation of the supplied UTF-16 string $str. +proc utf8 {str} { + # If $str ends in two 0x00 0x00 bytes, knock these off before + # converting to UTF-8 using TCL. + binary scan $str \c* vals + if {[lindex $vals end]==0 && [lindex $vals end-1]==0} { + set str [binary format \c* [lrange $vals 0 end-2]] + } + + set r [encoding convertfrom unicode $str] + return $r +} + +# +# This proc contains all the tests in this file. It is run +# three times. Each time the file 'test.db' contains a database +# with the following contents: +set dbcontents { + CREATE TABLE t1(a PRIMARY KEY, b, c); + INSERT INTO t1 VALUES('one', 'I', 1); +} +# This proc tests that we can open and manipulate the test.db +# database, and that it is possible to retreive values in +# various text encodings. +# +proc run_test_script {t enc} { + +# Open the database and pull out a (the) row. +do_test $t.1 { + sqlite3 db test.db; set DB [sqlite3_connection_pointer db] + execsql {SELECT * FROM t1} +} {one I 1} + +# Insert some data +do_test $t.2 { + execsql {INSERT INTO t1 VALUES('two', 'II', 2);} + execsql {SELECT * FROM t1} +} {one I 1 two II 2} + +# Insert some data +do_test $t.3 { + execsql { + INSERT INTO t1 VALUES('three','III',3); + INSERT INTO t1 VALUES('four','IV',4); + INSERT INTO t1 VALUES('five','V',5); + } + execsql {SELECT * FROM t1} +} {one I 1 two II 2 three III 3 four IV 4 five V 5} + +# Use the index +do_test $t.4 { + execsql { + SELECT * FROM t1 WHERE a = 'one'; + } +} {one I 1} +do_test $t.5 { + execsql { + SELECT * FROM t1 WHERE a = 'four'; + } +} {four IV 4} +ifcapable subquery { + do_test $t.6 { + execsql { + SELECT * FROM t1 WHERE a IN ('one', 'two'); + } + } {one I 1 two II 2} +} + +# Now check that we can retrieve data in both UTF-16 and UTF-8 +do_test $t.7 { + set STMT [sqlite3_prepare $DB "SELECT a FROM t1 WHERE c>3;" -1 TAIL] + sqlite3_step $STMT + sqlite3_column_text $STMT 0 +} {four} + +do_test $t.8 { + sqlite3_step $STMT + utf8 [sqlite3_column_text16 $STMT 0] +} {five} + +do_test $t.9 { + sqlite3_finalize $STMT +} SQLITE_OK + +ifcapable vacuum { + execsql VACUUM +} + +do_test $t.10 { + db eval {PRAGMA encoding} +} $enc + +} + +# The three unicode encodings understood by SQLite. +set encodings [list UTF-8 UTF-16le UTF-16be] + +set sqlite_os_trace 0 +set i 1 +foreach enc $encodings { + forcedelete test.db + sqlite3 db test.db + db eval "PRAGMA encoding = \"$enc\"" + execsql $dbcontents + do_test enc2-$i.0.1 { + db eval {PRAGMA encoding} + } $enc + do_test enc2-$i.0.2 { + db eval {PRAGMA encoding=UTF8} + db eval {PRAGMA encoding} + } $enc + do_test enc2-$i.0.3 { + db eval {PRAGMA encoding=UTF16le} + db eval {PRAGMA encoding} + } $enc + do_test enc2-$i.0.4 { + db eval {PRAGMA encoding=UTF16be} + db eval {PRAGMA encoding} + } $enc + + db close + run_test_script enc2-$i $enc + db close + incr i +} + +# Test that it is an error to try to attach a database with a different +# encoding to the main database. +ifcapable attach { + do_test enc2-4.1 { + forcedelete test.db + sqlite3 db test.db + db eval "PRAGMA encoding = 'UTF-8'" + db eval "CREATE TABLE abc(a, b, c);" + } {} + do_test enc2-4.2 { + forcedelete test2.db + sqlite3 db2 test2.db + db2 eval "PRAGMA encoding = 'UTF-16'" + db2 eval "CREATE TABLE abc(a, b, c);" + } {} + do_test enc2-4.3 { + catchsql { + ATTACH 'test2.db' as aux; + } + } {1 {attached databases must use the same text encoding as main database}} + db2 close + db close +} + +# The following tests - enc2-5.* - test that SQLite selects the correct +# collation sequence when more than one is available. + +set ::values [list one two three four five] +set ::test_collate_enc INVALID +proc test_collate {enc lhs rhs} { + set ::test_collate_enc $enc + set l [lsearch -exact $::values $lhs] + set r [lsearch -exact $::values $rhs] + set res [expr $l - $r] + # puts "enc=$enc lhs=$lhs/$l rhs=$rhs/$r res=$res" + return $res +} + +forcedelete test.db +sqlite3 db test.db; set DB [sqlite3_connection_pointer db] +do_test enc2-5.0 { + execsql { + CREATE TABLE t5(a); + INSERT INTO t5 VALUES('one'); + INSERT INTO t5 VALUES('two'); + INSERT INTO t5 VALUES('five'); + INSERT INTO t5 VALUES('three'); + INSERT INTO t5 VALUES('four'); + } +} {} +do_test enc2-5.1 { + add_test_collate $DB 1 1 1 + set res [execsql {SELECT * FROM t5 ORDER BY 1 COLLATE test_collate;}] + lappend res $::test_collate_enc +} {one two three four five UTF-8} +do_test enc2-5.2 { + add_test_collate $DB 0 1 0 + set res [execsql {SELECT * FROM t5 ORDER BY 1 COLLATE test_collate}] + lappend res $::test_collate_enc +} {one two three four five UTF-16LE} +do_test enc2-5.3 { + add_test_collate $DB 0 0 1 + set res [execsql {SELECT * FROM t5 ORDER BY 1 COLLATE test_collate}] + lappend res $::test_collate_enc +} {one two three four five UTF-16BE} + +db close +forcedelete test.db +sqlite3 db test.db; set DB [sqlite3_connection_pointer db] +execsql {pragma encoding = 'UTF-16LE'} +do_test enc2-5.4 { + execsql { + CREATE TABLE t5(a); + INSERT INTO t5 VALUES('one'); + INSERT INTO t5 VALUES('two'); + INSERT INTO t5 VALUES('five'); + INSERT INTO t5 VALUES('three'); + INSERT INTO t5 VALUES('four'); + } +} {} +do_test enc2-5.5 { + add_test_collate $DB 1 1 1 + set res [execsql {SELECT * FROM t5 ORDER BY 1 COLLATE test_collate}] + lappend res $::test_collate_enc +} {one two three four five UTF-16LE} +do_test enc2-5.6 { + add_test_collate $DB 1 0 1 + set res [execsql {SELECT * FROM t5 ORDER BY 1 COLLATE test_collate}] + lappend res $::test_collate_enc +} {one two three four five UTF-16BE} +do_test enc2-5.7 { + add_test_collate $DB 1 0 0 + set res [execsql {SELECT * FROM t5 ORDER BY 1 COLLATE test_collate}] + lappend res $::test_collate_enc +} {one two three four five UTF-8} + +db close +forcedelete test.db +sqlite3 db test.db; set DB [sqlite3_connection_pointer db] +execsql {pragma encoding = 'UTF-16BE'} +do_test enc2-5.8 { + execsql { + CREATE TABLE t5(a); + INSERT INTO t5 VALUES('one'); + INSERT INTO t5 VALUES('two'); + INSERT INTO t5 VALUES('five'); + INSERT INTO t5 VALUES('three'); + INSERT INTO t5 VALUES('four'); + } +} {} +do_test enc2-5.9 { + add_test_collate $DB 1 1 1 + set res [execsql {SELECT * FROM t5 ORDER BY 1 COLLATE test_collate}] + lappend res $::test_collate_enc +} {one two three four five UTF-16BE} +do_test enc2-5.10 { + add_test_collate $DB 1 1 0 + set res [execsql {SELECT * FROM t5 ORDER BY 1 COLLATE test_collate}] + lappend res $::test_collate_enc +} {one two three four five UTF-16LE} +do_test enc2-5.11 { + add_test_collate $DB 1 0 0 + set res [execsql {SELECT * FROM t5 ORDER BY 1 COLLATE test_collate}] + lappend res $::test_collate_enc +} {one two three four five UTF-8} + +# Also test that a UTF-16 collation factory works. +do_test enc2-5-12 { + add_test_collate $DB 0 0 0 + catchsql { + SELECT * FROM t5 ORDER BY 1 COLLATE test_collate + } +} {1 {no such collation sequence: test_collate}} +do_test enc2-5.13 { + add_test_collate_needed $DB + set res [execsql {SELECT * FROM t5 ORDER BY 1 COLLATE test_collate; }] + lappend res $::test_collate_enc +} {one two three four five UTF-16BE} +do_test enc2-5.14 { + set ::sqlite_last_needed_collation +} test_collate + +db close +forcedelete test.db + +do_test enc2-5.15 { + sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db] + add_test_collate_needed $::DB + set ::sqlite_last_needed_collation +} {} +do_test enc2-5.16 { + execsql {CREATE TABLE t1(a varchar collate test_collate);} +} {} +do_test enc2-5.17 { + set ::sqlite_last_needed_collation +} {test_collate} + +# The following tests - enc2-6.* - test that SQLite selects the correct +# user function when more than one is available. + +proc test_function {enc arg} { + return "$enc $arg" +} + +db close +forcedelete test.db +sqlite3 db test.db; set DB [sqlite3_connection_pointer db] +execsql {pragma encoding = 'UTF-8'} +do_test enc2-6.0 { + execsql { + CREATE TABLE t5(a); + INSERT INTO t5 VALUES('one'); + } +} {} +do_test enc2-6.1 { + add_test_function $DB 1 1 1 + execsql { + SELECT test_function('sqlite') + } +} {{UTF-8 sqlite}} +db close +sqlite3 db test.db; set DB [sqlite3_connection_pointer db] +do_test enc2-6.2 { + add_test_function $DB 0 1 0 + execsql { + SELECT test_function('sqlite') + } +} {{UTF-16LE sqlite}} +db close +sqlite3 db test.db; set DB [sqlite3_connection_pointer db] +do_test enc2-6.3 { + add_test_function $DB 0 0 1 + execsql { + SELECT test_function('sqlite') + } +} {{UTF-16BE sqlite}} + +db close +forcedelete test.db +sqlite3 db test.db; set DB [sqlite3_connection_pointer db] +execsql {pragma encoding = 'UTF-16LE'} +do_test enc2-6.3 { + execsql { + CREATE TABLE t5(a); + INSERT INTO t5 VALUES('sqlite'); + } +} {} +do_test enc2-6.4 { + add_test_function $DB 1 1 1 + execsql { + SELECT test_function('sqlite') + } +} {{UTF-16LE sqlite}} +db close +sqlite3 db test.db; set DB [sqlite3_connection_pointer db] +do_test enc2-6.5 { + add_test_function $DB 0 1 0 + execsql { + SELECT test_function('sqlite') + } +} {{UTF-16LE sqlite}} +db close +sqlite3 db test.db; set DB [sqlite3_connection_pointer db] +do_test enc2-6.6 { + add_test_function $DB 0 0 1 + execsql { + SELECT test_function('sqlite') + } +} {{UTF-16BE sqlite}} + +db close +forcedelete test.db +sqlite3 db test.db; set DB [sqlite3_connection_pointer db] +execsql {pragma encoding = 'UTF-16BE'} +do_test enc2-6.7 { + execsql { + CREATE TABLE t5(a); + INSERT INTO t5 VALUES('sqlite'); + } +} {} +do_test enc2-6.8 { + add_test_function $DB 1 1 1 + execsql { + SELECT test_function('sqlite') + } +} {{UTF-16BE sqlite}} +db close +sqlite3 db test.db; set DB [sqlite3_connection_pointer db] +do_test enc2-6.9 { + add_test_function $DB 0 1 0 + execsql { + SELECT test_function('sqlite') + } +} {{UTF-16LE sqlite}} +db close +sqlite3 db test.db; set DB [sqlite3_connection_pointer db] +do_test enc2-6.10 { + add_test_function $DB 0 0 1 + execsql { + SELECT test_function('sqlite') + } +} {{UTF-16BE sqlite}} + + +db close +forcedelete test.db + +# The following tests - enc2-7.* - function as follows: +# +# 1: Open an empty database file assuming UTF-16 encoding. +# 2: Open the same database with a different handle assuming UTF-8. Create +# a table using this handle. +# 3: Read the sqlite_master table from the first handle. +# 4: Ensure the first handle recognises the database encoding is UTF-8. +# +do_test enc2-7.1 { + sqlite3 db test.db + execsql { + PRAGMA encoding = 'UTF-16'; + SELECT * FROM sqlite_master; + } +} {} +do_test enc2-7.2 { + set enc [execsql { + PRAGMA encoding; + }] + string range $enc 0 end-2 ;# Chop off the "le" or "be" +} {UTF-16} +do_test enc2-7.3 { + sqlite3 db2 test.db + execsql { + PRAGMA encoding = 'UTF-8'; + CREATE TABLE abc(a, b, c); + } db2 +} {} +do_test enc2-7.4 { + execsql { + SELECT * FROM sqlite_master; + } +} "table abc abc [expr $AUTOVACUUM?3:2] {CREATE TABLE abc(a, b, c)}" +do_test enc2-7.5 { + execsql { + PRAGMA encoding; + } +} {UTF-8} + +db close +db2 close + +proc utf16 {utf8} { + set utf16 [encoding convertto unicode $utf8] + append utf16 "\x00\x00" + return $utf16 +} +ifcapable {complete} { + do_test enc2-8.1 { + sqlite3_complete16 [utf16 "SELECT * FROM t1;"] + } {1} + do_test enc2-8.2 { + sqlite3_complete16 [utf16 "SELECT * FROM"] + } {0} +} + +# Test that the encoding of an empty database may still be set after the +# (empty) schema has been initialized. +forcedelete test.db +do_test enc2-9.1 { + sqlite3 db test.db + execsql { + PRAGMA encoding = 'UTF-8'; + PRAGMA encoding; + } +} {UTF-8} +do_test enc2-9.2 { + sqlite3 db test.db + execsql { + PRAGMA encoding = 'UTF-16le'; + PRAGMA encoding; + } +} {UTF-16le} +do_test enc2-9.3 { + sqlite3 db test.db + execsql { + SELECT * FROM sqlite_master; + PRAGMA encoding = 'UTF-8'; + PRAGMA encoding; + } +} {UTF-8} +do_test enc2-9.4 { + sqlite3 db test.db + execsql { + PRAGMA encoding = 'UTF-16le'; + CREATE TABLE abc(a, b, c); + PRAGMA encoding; + } +} {UTF-16le} +do_test enc2-9.5 { + sqlite3 db test.db + execsql { + PRAGMA encoding = 'UTF-8'; + PRAGMA encoding; + } +} {UTF-16le} + +# Ticket #1987. +# Disallow encoding changes once the encoding has been set. +# +do_test enc2-10.1 { + db close + forcedelete test.db test.db-journal + sqlite3 db test.db + db eval { + PRAGMA encoding=UTF16; + CREATE TABLE t1(a); + PRAGMA encoding=UTF8; + CREATE TABLE t2(b); + } + db close + sqlite3 db test.db + db eval { + SELECT name FROM sqlite_master + } +} {t1 t2} + +# 2020-01-15 ticket a08879a4a476eea9 +# Do not allow a database connection encoding change unless *all* +# attached databases are empty. +# +reset_db +do_execsql_test enc2-11.10 { + PRAGMA encoding=UTF8; + CREATE TEMP TABLE t1(x); + INSERT INTO t1 VALUES('this is a test'); + PRAGMA encoding=UTF16; + SELECT * FROM t1; +} {{this is a test}} + +finish_test diff --git a/test/enc3.test b/test/enc3.test new file mode 100644 index 0000000..c9d39cb --- /dev/null +++ b/test/enc3.test @@ -0,0 +1,107 @@ +# 2002 May 24 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# The focus of this file is testing of the proper handling of conversions +# to the native text representation. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable {utf16} { + do_test enc3-1.1 { + execsql { + PRAGMA encoding=utf16le; + PRAGMA encoding; + } + } {UTF-16le} +} +do_test enc3-1.2 { + execsql { + CREATE TABLE t1(x,y); + INSERT INTO t1 VALUES('abc''123',5); + SELECT * FROM t1 + } +} {abc'123 5} +do_test enc3-1.3 { + execsql { + SELECT quote(x) || ' ' || quote(y) FROM t1 + } +} {{'abc''123' 5}} +ifcapable {bloblit} { + do_test enc3-1.4 { + execsql { + DELETE FROM t1; + INSERT INTO t1 VALUES(x'616263646566',NULL); + SELECT * FROM t1 + } + } {abcdef {}} + do_test enc3-1.5 { + execsql { + SELECT quote(x) || ' ' || quote(y) FROM t1 + } + } {{X'616263646566' NULL}} +} +ifcapable {bloblit && utf16} { + do_test enc3-2.1 { + execsql { + PRAGMA encoding + } + } {UTF-16le} + do_test enc3-2.2 { + execsql { + CREATE TABLE t2(a); + INSERT INTO t2 VALUES(x'61006200630064006500'); + SELECT CAST(a AS text) FROM t2 WHERE CAST(a AS text) LIKE 'abc%'; + } + } {abcde} + do_test enc3-2.3 { + execsql { + SELECT CAST(x'61006200630064006500' AS text); + } + } {abcde} + do_test enc3-2.4 { + execsql { + SELECT rowid FROM t2 + WHERE CAST(a AS text) LIKE CAST(x'610062002500' AS text); + } + } {1} +} + +# Try to attach a database with a different encoding. +# +ifcapable {utf16 && shared_cache} { + db close + forcedelete test8.db test8.db-journal + set ::enable_shared_cache [sqlite3_enable_shared_cache 1] + sqlite3 dbaux test8.db + sqlite3 db test.db + db eval {SELECT 1 FROM sqlite_master LIMIT 1} + do_test enc3-3.1 { + dbaux eval { + PRAGMA encoding='utf8'; + CREATE TABLE t1(x); + PRAGMA encoding + } + } {UTF-8} + do_test enc3-3.2 { + catchsql { + ATTACH 'test.db' AS utf16; + SELECT 1 FROM utf16.sqlite_master LIMIT 1; + } dbaux + } {1 {attached databases must use the same text encoding as main database}} + dbaux close + forcedelete test8.db test8.db-journal + sqlite3_enable_shared_cache $::enable_shared_cache +} + +finish_test diff --git a/test/enc4.test b/test/enc4.test new file mode 100644 index 0000000..94869b6 --- /dev/null +++ b/test/enc4.test @@ -0,0 +1,137 @@ +# 2010 Sept 29 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The focus of +# this file is testing the SQLite routines used for converting between the +# various suported unicode encodings (UTF-8, UTF-16, UTF-16le and +# UTF-16be). +# +# $Id: enc4.test,v 1.0 2010/09/29 08:29:32 shaneh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If UTF16 support is disabled, ignore the tests in this file +# +ifcapable {!utf16} { + finish_test + return +} + +db close + +# The three unicode encodings understood by SQLite. +set encodings [list UTF-8 UTF-16le UTF-16be] + +# initial value to use in SELECT +set inits [list 1 1.0 1. 1e0] + +# vals +set vals [list\ +"922337203685477580792233720368547758079223372036854775807"\ +"100000000000000000000000000000000000000000000000000000000"\ +"1.0000000000000000000000000000000000000000000000000000000"\ +] + +set i 1 +foreach enc $encodings { + + forcedelete test.db + sqlite3 db test.db + db eval "PRAGMA encoding = \"$enc\"" + + do_test enc4-$i.1 { + db eval {PRAGMA encoding} + } $enc + + set j 1 + foreach init $inits { + + do_test enc4-$i.$j.2 { + set S [sqlite3_prepare_v2 db "SELECT $init+?" -1 dummy] + sqlite3_expired $S + } {0} + + set k 1 + foreach val $vals { + for {set x 1} {$x<16} {incr x} { + set part [expr $init + [string range $val 0 [expr $x-1]]] + + do_realnum_test enc4-$i.$j.$k.3.$x { + sqlite3_reset $S + sqlite3_bind_text $S 1 $val $x + sqlite3_step $S + sqlite3_column_text $S 0 + } [list $part] + + do_realnum_test enc4-$i.$j.$k.4.$x { + sqlite3_reset $S + sqlite3_bind_text16 $S 1 [encoding convertto unicode $val] [expr $x*2] + sqlite3_step $S + sqlite3_column_text $S 0 + } [list $part] + } + + incr k + } + + do_test enc4-$i.$j.5 { + sqlite3_finalize $S + } {SQLITE_OK} + + incr j + } + + db close + incr i +} + +forcedelete test.db +sqlite3 db test.db + +do_test enc4-4.1 { + db eval "select 1+1." +} {2.0} + +do_test enc4-4.2.1 { + set S [sqlite3_prepare_v2 db "SELECT 1+1." -1 dummy] + sqlite3_step $S + sqlite3_column_text $S 0 +} {2.0} + +do_test enc4-4.2.2 { + sqlite3_finalize $S +} {SQLITE_OK} + +do_test enc4-4.3.1 { + set S [sqlite3_prepare_v2 db "SELECT 1+?" -1 dummy] + sqlite3_bind_text $S 1 "1." 2 + sqlite3_step $S + sqlite3_column_text $S 0 +} {2.0} + +do_test enc4-4.3.2 { + sqlite3_finalize $S +} {SQLITE_OK} + +do_test enc4-4.4.1 { + set S [sqlite3_prepare_v2 db "SELECT 1+?" -1 dummy] + sqlite3_bind_text $S 1 "1.0" 2 + sqlite3_step $S + sqlite3_column_text $S 0 +} {2.0} + +do_test enc4-4.4.2 { + sqlite3_finalize $S +} {SQLITE_OK} + +db close + +finish_test diff --git a/test/eqp.test b/test/eqp.test new file mode 100644 index 0000000..61fd617 --- /dev/null +++ b/test/eqp.test @@ -0,0 +1,850 @@ +# 2010 November 6 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !compound { + finish_test + return +} + +set testprefix eqp + +#------------------------------------------------------------------------- +# +# eqp-1.*: Assorted tests. +# eqp-2.*: Tests for single select statements. +# eqp-3.*: Select statements that execute sub-selects. +# eqp-4.*: Compound select statements. +# ... +# eqp-7.*: "SELECT count(*) FROM tbl" statements (VDBE code OP_Count). +# + +proc det {args} { uplevel do_eqp_test $args } + +do_execsql_test 1.1 { + CREATE TABLE t1(a INT, b INT, ex TEXT); + CREATE INDEX i1 ON t1(a); + CREATE INDEX i2 ON t1(b); + CREATE TABLE t2(a INT, b INT, ex TEXT); + CREATE TABLE t3(a INT, b INT, ex TEXT); +} + +do_eqp_test 1.2 { + SELECT * FROM t2, t1 WHERE t1.a=1 OR t1.b=2; +} { + QUERY PLAN + |--MULTI-INDEX OR + | |--INDEX 1 + | | `--SEARCH t1 USING INDEX i1 (a=?) + | `--INDEX 2 + | `--SEARCH t1 USING INDEX i2 (b=?) + `--SCAN t2 +} +do_eqp_test 1.3 { + SELECT * FROM t2 CROSS JOIN t1 WHERE t1.a=1 OR t1.b=2; +} { + QUERY PLAN + |--SCAN t2 + `--MULTI-INDEX OR + |--INDEX 1 + | `--SEARCH t1 USING INDEX i1 (a=?) + `--INDEX 2 + `--SEARCH t1 USING INDEX i2 (b=?) +} +do_eqp_test 1.3 { + SELECT a FROM t1 ORDER BY a +} { + QUERY PLAN + `--SCAN t1 USING COVERING INDEX i1 +} +do_eqp_test 1.4 { + SELECT a FROM t1 ORDER BY +a +} { + QUERY PLAN + |--SCAN t1 USING COVERING INDEX i1 + `--USE TEMP B-TREE FOR ORDER BY +} +do_eqp_test 1.5 { + SELECT a FROM t1 WHERE a=4 +} { + QUERY PLAN + `--SEARCH t1 USING COVERING INDEX i1 (a=?) +} +do_eqp_test 1.6 { + SELECT DISTINCT count(*) FROM t3 GROUP BY a; +} { + QUERY PLAN + |--SCAN t3 + |--USE TEMP B-TREE FOR GROUP BY + `--USE TEMP B-TREE FOR DISTINCT +} + +do_eqp_test 1.7.1 { + SELECT * FROM t3 JOIN (SELECT 1) +} { + QUERY PLAN + |--CO-ROUTINE (subquery-xxxxxx) + | `--SCAN CONSTANT ROW + |--SCAN (subquery-xxxxxx) + `--SCAN t3 +} +do_eqp_test 1.7.2 { + SELECT * FROM t3 JOIN (SELECT 1) AS v1 +} { + QUERY PLAN + |--CO-ROUTINE v1 + | `--SCAN CONSTANT ROW + |--SCAN v1 + `--SCAN t3 +} +do_eqp_test 1.7.3 { + SELECT * FROM t3 AS xx JOIN (SELECT 1) AS yy +} { + QUERY PLAN + |--CO-ROUTINE yy + | `--SCAN CONSTANT ROW + |--SCAN yy + `--SCAN xx +} + + +do_eqp_test 1.8 { + SELECT * FROM t3 JOIN (SELECT 1 UNION SELECT 2) +} { + QUERY PLAN + |--CO-ROUTINE (subquery-xxxxxx) + | `--COMPOUND QUERY + | |--LEFT-MOST SUBQUERY + | | `--SCAN CONSTANT ROW + | `--UNION USING TEMP B-TREE + | `--SCAN CONSTANT ROW + |--SCAN (subquery-xxxxxx) + `--SCAN t3 +} +do_eqp_test 1.9 { + SELECT * FROM t3 JOIN (SELECT 1 EXCEPT SELECT a FROM t3 LIMIT 17) AS abc +} { + QUERY PLAN + |--CO-ROUTINE abc + | `--COMPOUND QUERY + | |--LEFT-MOST SUBQUERY + | | `--SCAN CONSTANT ROW + | `--EXCEPT USING TEMP B-TREE + | `--SCAN t3 + |--SCAN abc + `--SCAN t3 +} +do_eqp_test 1.10 { + SELECT * FROM t3 JOIN (SELECT 1 INTERSECT SELECT a FROM t3 LIMIT 17) AS abc +} { + QUERY PLAN + |--CO-ROUTINE abc + | `--COMPOUND QUERY + | |--LEFT-MOST SUBQUERY + | | `--SCAN CONSTANT ROW + | `--INTERSECT USING TEMP B-TREE + | `--SCAN t3 + |--SCAN abc + `--SCAN t3 +} + +do_eqp_test 1.11 { + SELECT * FROM t3 JOIN (SELECT 1 UNION ALL SELECT a FROM t3 LIMIT 17) abc +} { + QUERY PLAN + |--CO-ROUTINE abc + | `--COMPOUND QUERY + | |--LEFT-MOST SUBQUERY + | | `--SCAN CONSTANT ROW + | `--UNION ALL + | `--SCAN t3 + |--SCAN abc + `--SCAN t3 +} + +#------------------------------------------------------------------------- +# Test cases eqp-2.* - tests for single select statements. +# +drop_all_tables +do_execsql_test 2.1 { + CREATE TABLE t1(x INT, y INT, ex TEXT); + + CREATE TABLE t2(x INT, y INT, ex TEXT); + CREATE INDEX t2i1 ON t2(x); +} + +det 2.2.1 "SELECT DISTINCT min(x), max(x) FROM t1 GROUP BY x ORDER BY 1" { + QUERY PLAN + |--SCAN t1 + |--USE TEMP B-TREE FOR GROUP BY + |--USE TEMP B-TREE FOR DISTINCT + `--USE TEMP B-TREE FOR ORDER BY +} +det 2.2.2 "SELECT DISTINCT min(x), max(x) FROM t2 GROUP BY x ORDER BY 1" { + QUERY PLAN + |--SCAN t2 USING COVERING INDEX t2i1 + |--USE TEMP B-TREE FOR DISTINCT + `--USE TEMP B-TREE FOR ORDER BY +} +det 2.2.3 "SELECT DISTINCT * FROM t1" { + QUERY PLAN + |--SCAN t1 + `--USE TEMP B-TREE FOR DISTINCT +} +det 2.2.4 "SELECT DISTINCT * FROM t1, t2" { + QUERY PLAN + |--SCAN t1 + |--SCAN t2 + `--USE TEMP B-TREE FOR DISTINCT +} +det 2.2.5 "SELECT DISTINCT * FROM t1, t2 ORDER BY t1.x" { + QUERY PLAN + |--SCAN t1 + |--SCAN t2 + |--USE TEMP B-TREE FOR DISTINCT + `--USE TEMP B-TREE FOR ORDER BY +} +det 2.2.6 "SELECT DISTINCT t2.x FROM t1, t2 ORDER BY t2.x" { + QUERY PLAN + |--SCAN t2 USING COVERING INDEX t2i1 + `--SCAN t1 +} + +det 2.3.1 "SELECT max(x) FROM t2" { + QUERY PLAN + `--SEARCH t2 USING COVERING INDEX t2i1 +} +det 2.3.2 "SELECT min(x) FROM t2" { + QUERY PLAN + `--SEARCH t2 USING COVERING INDEX t2i1 +} +det 2.3.3 "SELECT min(x), max(x) FROM t2" { + QUERY PLAN + `--SCAN t2 USING COVERING INDEX t2i1 +} + +det 2.4.1 "SELECT * FROM t1 WHERE rowid=?" { + QUERY PLAN + `--SEARCH t1 USING INTEGER PRIMARY KEY (rowid=?) +} + + + +#------------------------------------------------------------------------- +# Test cases eqp-3.* - tests for select statements that use sub-selects. +# +do_eqp_test 3.1.1 { + SELECT (SELECT x FROM t1 AS sub) FROM t1; +} { + QUERY PLAN + |--SCAN t1 + `--SCALAR SUBQUERY xxxxxx + `--SCAN sub +} +do_eqp_test 3.1.2 { + SELECT * FROM t1 WHERE (SELECT x FROM t1 AS sub); +} { + QUERY PLAN + |--SCAN t1 + `--SCALAR SUBQUERY xxxxxx + `--SCAN sub +} +do_eqp_test 3.1.3 { + SELECT * FROM t1 WHERE (SELECT x FROM t1 AS sub ORDER BY y); +} { + QUERY PLAN + |--SCAN t1 + `--SCALAR SUBQUERY xxxxxx + |--SCAN sub + `--USE TEMP B-TREE FOR ORDER BY +} +do_eqp_test 3.1.4 { + SELECT * FROM t1 WHERE (SELECT x FROM t2 ORDER BY x); +} { + QUERY PLAN + |--SCAN t1 + `--SCALAR SUBQUERY xxxxxx + `--SCAN t2 USING COVERING INDEX t2i1 +} + +det 3.2.1 { + SELECT * FROM (SELECT * FROM t1 ORDER BY x LIMIT 10) ORDER BY y LIMIT 5 +} { + QUERY PLAN + |--CO-ROUTINE (subquery-xxxxxx) + | |--SCAN t1 + | `--USE TEMP B-TREE FOR ORDER BY + |--SCAN (subquery-xxxxxx) + `--USE TEMP B-TREE FOR ORDER BY +} +det 3.2.2 { + SELECT * FROM + (SELECT * FROM t1 ORDER BY x LIMIT 10) AS x1, + (SELECT * FROM t2 ORDER BY x LIMIT 10) AS x2 + ORDER BY x2.y LIMIT 5 +} { + QUERY PLAN + |--CO-ROUTINE x1 + | |--SCAN t1 + | `--USE TEMP B-TREE FOR ORDER BY + |--MATERIALIZE x2 + | `--SCAN t2 USING INDEX t2i1 + |--SCAN x1 + |--SCAN x2 + `--USE TEMP B-TREE FOR ORDER BY +} + +det 3.3.1 { + SELECT * FROM t1 WHERE y IN (SELECT y FROM t2) +} { + QUERY PLAN + |--SCAN t1 + `--LIST SUBQUERY xxxxxx + `--SCAN t2 +} +det 3.3.2 { + SELECT * FROM t1 WHERE y IN (SELECT y FROM t2 WHERE t1.x!=t2.x) +} { + QUERY PLAN + |--SCAN t1 + `--CORRELATED LIST SUBQUERY xxxxxx + `--SCAN t2 +} +det 3.3.3 { + SELECT * FROM t1 WHERE EXISTS (SELECT y FROM t2 WHERE t1.x!=t2.x) +} { + QUERY PLAN + |--SCAN t1 + `--CORRELATED SCALAR SUBQUERY xxxxxx + `--SCAN t2 +} + +#------------------------------------------------------------------------- +# Test cases eqp-4.* - tests for composite select statements. +# +do_eqp_test 4.1.1 { + SELECT * FROM t1 UNION ALL SELECT * FROM t2 +} { + QUERY PLAN + `--COMPOUND QUERY + |--LEFT-MOST SUBQUERY + | `--SCAN t1 + `--UNION ALL + `--SCAN t2 +} +do_eqp_test 4.1.2 { + SELECT * FROM t1 UNION ALL SELECT * FROM t2 ORDER BY 2 +} { + QUERY PLAN + `--MERGE (UNION ALL) + |--LEFT + | |--SCAN t1 + | `--USE TEMP B-TREE FOR ORDER BY + `--RIGHT + |--SCAN t2 + `--USE TEMP B-TREE FOR ORDER BY +} +do_eqp_test 4.1.3 { + SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY 2 +} { + QUERY PLAN + `--MERGE (UNION) + |--LEFT + | |--SCAN t1 + | `--USE TEMP B-TREE FOR ORDER BY + `--RIGHT + |--SCAN t2 + `--USE TEMP B-TREE FOR ORDER BY +} +do_eqp_test 4.1.4 { + SELECT * FROM t1 INTERSECT SELECT * FROM t2 ORDER BY 2 +} { + QUERY PLAN + `--MERGE (INTERSECT) + |--LEFT + | |--SCAN t1 + | `--USE TEMP B-TREE FOR ORDER BY + `--RIGHT + |--SCAN t2 + `--USE TEMP B-TREE FOR ORDER BY +} +do_eqp_test 4.1.5 { + SELECT * FROM t1 EXCEPT SELECT * FROM t2 ORDER BY 2 +} { + QUERY PLAN + `--MERGE (EXCEPT) + |--LEFT + | |--SCAN t1 + | `--USE TEMP B-TREE FOR ORDER BY + `--RIGHT + |--SCAN t2 + `--USE TEMP B-TREE FOR ORDER BY +} + +do_eqp_test 4.2.2 { + SELECT * FROM t1 UNION ALL SELECT * FROM t2 ORDER BY 1 +} { + QUERY PLAN + `--MERGE (UNION ALL) + |--LEFT + | |--SCAN t1 + | `--USE TEMP B-TREE FOR ORDER BY + `--RIGHT + `--SCAN t2 USING INDEX t2i1 +} +do_eqp_test 4.2.3 { + SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY 1 +} { + QUERY PLAN + `--MERGE (UNION) + |--LEFT + | |--SCAN t1 + | `--USE TEMP B-TREE FOR ORDER BY + `--RIGHT + |--SCAN t2 USING INDEX t2i1 + `--USE TEMP B-TREE FOR RIGHT PART OF ORDER BY +} +do_eqp_test 4.2.4 { + SELECT * FROM t1 INTERSECT SELECT * FROM t2 ORDER BY 1 +} { + QUERY PLAN + `--MERGE (INTERSECT) + |--LEFT + | |--SCAN t1 + | `--USE TEMP B-TREE FOR ORDER BY + `--RIGHT + |--SCAN t2 USING INDEX t2i1 + `--USE TEMP B-TREE FOR RIGHT PART OF ORDER BY +} +do_eqp_test 4.2.5 { + SELECT * FROM t1 EXCEPT SELECT * FROM t2 ORDER BY 1 +} { + QUERY PLAN + `--MERGE (EXCEPT) + |--LEFT + | |--SCAN t1 + | `--USE TEMP B-TREE FOR ORDER BY + `--RIGHT + |--SCAN t2 USING INDEX t2i1 + `--USE TEMP B-TREE FOR RIGHT PART OF ORDER BY +} + +do_eqp_test 4.3.1 { + SELECT x FROM t1 UNION SELECT x FROM t2 +} { + QUERY PLAN + `--COMPOUND QUERY + |--LEFT-MOST SUBQUERY + | `--SCAN t1 + `--UNION USING TEMP B-TREE + `--SCAN t2 USING COVERING INDEX t2i1 +} + +do_eqp_test 4.3.2 { + SELECT x FROM t1 UNION SELECT x FROM t2 UNION SELECT x FROM t1 +} { + QUERY PLAN + `--COMPOUND QUERY + |--LEFT-MOST SUBQUERY + | `--SCAN t1 + |--UNION USING TEMP B-TREE + | `--SCAN t2 USING COVERING INDEX t2i1 + `--UNION USING TEMP B-TREE + `--SCAN t1 +} +do_eqp_test 4.3.3 { + SELECT x FROM t1 UNION SELECT x FROM t2 UNION SELECT x FROM t1 ORDER BY 1 +} { + QUERY PLAN + `--MERGE (UNION) + |--LEFT + | `--MERGE (UNION) + | |--LEFT + | | |--SCAN t1 + | | `--USE TEMP B-TREE FOR ORDER BY + | `--RIGHT + | `--SCAN t2 USING COVERING INDEX t2i1 + `--RIGHT + |--SCAN t1 + `--USE TEMP B-TREE FOR ORDER BY +} + +if 0 { +#------------------------------------------------------------------------- +# This next block of tests verifies that the examples on the +# lang_explain.html page are correct. +# +drop_all_tables + +# XVIDENCE-OF: R-47779-47605 sqlite> EXPLAIN QUERY PLAN SELECT a, b +# FROM t1 WHERE a=1; +# 0|0|0|SCAN t1 +# +do_execsql_test 5.1.0 { CREATE TABLE t1(a INT, b INT, ex TEXT) } +det 5.1.1 "SELECT a, b FROM t1 WHERE a=1" { + 0 0 0 {SCAN t1} +} + +# XVIDENCE-OF: R-55852-17599 sqlite> CREATE INDEX i1 ON t1(a); +# sqlite> EXPLAIN QUERY PLAN SELECT a, b FROM t1 WHERE a=1; +# 0|0|0|SEARCH t1 USING INDEX i1 +# +do_execsql_test 5.2.0 { CREATE INDEX i1 ON t1(a) } +det 5.2.1 "SELECT a, b FROM t1 WHERE a=1" { + 0 0 0 {SEARCH t1 USING INDEX i1 (a=?)} +} + +# XVIDENCE-OF: R-21179-11011 sqlite> CREATE INDEX i2 ON t1(a, b); +# sqlite> EXPLAIN QUERY PLAN SELECT a, b FROM t1 WHERE a=1; +# 0|0|0|SEARCH t1 USING COVERING INDEX i2 (a=?) +# +do_execsql_test 5.3.0 { CREATE INDEX i2 ON t1(a, b) } +det 5.3.1 "SELECT a, b FROM t1 WHERE a=1" { + 0 0 0 {SEARCH t1 USING COVERING INDEX i2 (a=?)} +} + +# XVIDENCE-OF: R-09991-48941 sqlite> EXPLAIN QUERY PLAN +# SELECT t1.*, t2.* FROM t1, t2 WHERE t1.a=1 AND t1.b>2; +# 0|0|0|SEARCH t1 USING COVERING INDEX i2 (a=? AND b>?) +# 0|1|1|SCAN t2 +# +do_execsql_test 5.4.0 {CREATE TABLE t2(c INT, d INT, ex TEXT)} +det 5.4.1 "SELECT t1.a, t2.c FROM t1, t2 WHERE t1.a=1 AND t1.b>2" { + 0 0 0 {SEARCH t1 USING COVERING INDEX i2 (a=? AND b>?)} + 0 1 1 {SCAN t2} +} + +# XVIDENCE-OF: R-33626-61085 sqlite> EXPLAIN QUERY PLAN +# SELECT t1.*, t2.* FROM t2, t1 WHERE t1.a=1 AND t1.b>2; +# 0|0|1|SEARCH t1 USING COVERING INDEX i2 (a=? AND b>?) +# 0|1|0|SCAN t2 +# +det 5.5 "SELECT t1.a, t2.c FROM t2, t1 WHERE t1.a=1 AND t1.b>2" { + 0 0 1 {SEARCH t1 USING COVERING INDEX i2 (a=? AND b>?)} + 0 1 0 {SCAN t2} +} + +# XVIDENCE-OF: R-04002-25654 sqlite> CREATE INDEX i3 ON t1(b); +# sqlite> EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE a=1 OR b=2; +# 0|0|0|SEARCH t1 USING COVERING INDEX i2 (a=?) +# 0|0|0|SEARCH t1 USING INDEX i3 (b=?) +# +do_execsql_test 5.5.0 {CREATE INDEX i3 ON t1(b)} +det 5.6.1 "SELECT a, b FROM t1 WHERE a=1 OR b=2" { + 0 0 0 {SEARCH t1 USING COVERING INDEX i2 (a=?)} + 0 0 0 {SEARCH t1 USING INDEX i3 (b=?)} +} + +# XVIDENCE-OF: R-24577-38891 sqlite> EXPLAIN QUERY PLAN +# SELECT c, d FROM t2 ORDER BY c; +# 0|0|0|SCAN t2 +# 0|0|0|USE TEMP B-TREE FOR ORDER BY +# +det 5.7 "SELECT c, d FROM t2 ORDER BY c" { + 0 0 0 {SCAN t2} + 0 0 0 {USE TEMP B-TREE FOR ORDER BY} +} + +# XVIDENCE-OF: R-58157-12355 sqlite> CREATE INDEX i4 ON t2(c); +# sqlite> EXPLAIN QUERY PLAN SELECT c, d FROM t2 ORDER BY c; +# 0|0|0|SCAN t2 USING INDEX i4 +# +do_execsql_test 5.8.0 {CREATE INDEX i4 ON t2(c)} +det 5.8.1 "SELECT c, d FROM t2 ORDER BY c" { + 0 0 0 {SCAN t2 USING INDEX i4} +} + +# XVIDENCE-OF: R-13931-10421 sqlite> EXPLAIN QUERY PLAN SELECT +# (SELECT b FROM t1 WHERE a=0), (SELECT a FROM t1 WHERE b=t2.c) FROM t2; +# 0|0|0|SCAN t2 +# 0|0|0|EXECUTE SCALAR SUBQUERY 1 +# 1|0|0|SEARCH t1 USING COVERING INDEX i2 (a=?) +# 0|0|0|EXECUTE CORRELATED SCALAR SUBQUERY 2 +# 2|0|0|SEARCH t1 USING INDEX i3 (b=?) +# +det 5.9 { + SELECT (SELECT b FROM t1 WHERE a=0), (SELECT a FROM t1 WHERE b=t2.c) FROM t2 +} { + 0 0 0 {SCAN t2 USING COVERING INDEX i4} + 0 0 0 {EXECUTE SCALAR SUBQUERY 1} + 1 0 0 {SEARCH t1 USING COVERING INDEX i2 (a=?)} + 0 0 0 {EXECUTE CORRELATED SCALAR SUBQUERY 2} + 2 0 0 {SEARCH t1 USING INDEX i3 (b=?)} +} + +# XVIDENCE-OF: R-50892-45943 sqlite> EXPLAIN QUERY PLAN +# SELECT count(*) FROM (SELECT max(b) AS x FROM t1 GROUP BY a) GROUP BY x; +# 1|0|0|SCAN t1 USING COVERING INDEX i2 +# 0|0|0|SCAN SUBQUERY 1 +# 0|0|0|USE TEMP B-TREE FOR GROUP BY +# +det 5.10 { + SELECT count(*) FROM (SELECT max(b) AS x FROM t1 GROUP BY a) GROUP BY x +} { + 1 0 0 {SCAN t1 USING COVERING INDEX i2} + 0 0 0 {SCAN SUBQUERY 1} + 0 0 0 {USE TEMP B-TREE FOR GROUP BY} +} + +# XVIDENCE-OF: R-46219-33846 sqlite> EXPLAIN QUERY PLAN +# SELECT * FROM (SELECT * FROM t2 WHERE c=1), t1; +# 0|0|0|SEARCH t2 USING INDEX i4 (c=?) +# 0|1|1|SCAN t1 +# +det 5.11 "SELECT a, b FROM (SELECT * FROM t2 WHERE c=1), t1" { + 0 0 0 {SEARCH t2 USING INDEX i4 (c=?)} + 0 1 1 {SCAN t1 USING COVERING INDEX i2} +} + +# XVIDENCE-OF: R-37879-39987 sqlite> EXPLAIN QUERY PLAN +# SELECT a FROM t1 UNION SELECT c FROM t2; +# 1|0|0|SCAN t1 +# 2|0|0|SCAN t2 +# 0|0|0|COMPOUND SUBQUERIES 1 AND 2 USING TEMP B-TREE (UNION) +# +det 5.12 "SELECT a,b FROM t1 UNION SELECT c, 99 FROM t2" { + 1 0 0 {SCAN t1 USING COVERING INDEX i2} + 2 0 0 {SCAN t2 USING COVERING INDEX i4} + 0 0 0 {COMPOUND SUBQUERIES 1 AND 2 USING TEMP B-TREE (UNION)} +} + +# XVIDENCE-OF: R-44864-63011 sqlite> EXPLAIN QUERY PLAN +# SELECT a FROM t1 EXCEPT SELECT d FROM t2 ORDER BY 1; +# 1|0|0|SCAN t1 USING COVERING INDEX i2 +# 2|0|0|SCAN t2 2|0|0|USE TEMP B-TREE FOR ORDER BY +# 0|0|0|COMPOUND SUBQUERIES 1 AND 2 (EXCEPT) +# +det 5.13 "SELECT a FROM t1 EXCEPT SELECT d FROM t2 ORDER BY 1" { + 1 0 0 {SCAN t1 USING COVERING INDEX i1} + 2 0 0 {SCAN t2} + 2 0 0 {USE TEMP B-TREE FOR ORDER BY} + 0 0 0 {COMPOUND SUBQUERIES 1 AND 2 (EXCEPT)} +} + +if {![nonzero_reserved_bytes]} { + #------------------------------------------------------------------------- + # The following tests - eqp-6.* - test that the example C code on + # documentation page eqp.html works. The C code is duplicated in test1.c + # and wrapped in Tcl command [print_explain_query_plan] + # + set boilerplate { + proc explain_query_plan {db sql} { + set stmt [sqlite3_prepare_v2 db $sql -1 DUMMY] + print_explain_query_plan $stmt + sqlite3_finalize $stmt + } + sqlite3 db test.db + explain_query_plan db {%SQL%} + db close + exit + } + + # Do a "Print Explain Query Plan" test. + proc do_peqp_test {tn sql res} { + set fd [open script.tcl w] + puts $fd [string map [list %SQL% $sql] $::boilerplate] + close $fd + + uplevel do_test $tn [list { + set fd [open "|[info nameofexec] script.tcl"] + set data [read $fd] + close $fd + set data + }] [list $res] + } + + do_peqp_test 6.1 { + SELECT a, b FROM t1 EXCEPT SELECT d, 99 FROM t2 ORDER BY 1 + } [string trimleft { +1 0 0 SCAN t1 USING COVERING INDEX i2 +2 0 0 SCAN t2 +2 0 0 USE TEMP B-TREE FOR ORDER BY +0 0 0 COMPOUND SUBQUERIES 1 AND 2 (EXCEPT) +}] +} +} + +#------------------------------------------------------------------------- +# The following tests - eqp-7.* - test that queries that use the OP_Count +# optimization return something sensible with EQP. +# +drop_all_tables + +do_execsql_test 7.0 { + CREATE TABLE t1(a INT, b INT, ex CHAR(100)); + CREATE TABLE t2(a INT, b INT, ex CHAR(100)); + CREATE INDEX i1 ON t2(a); +} + +det 7.1 "SELECT count(*) FROM t1" { + QUERY PLAN + `--SCAN t1 +} + +det 7.2 "SELECT count(*) FROM t2" { + QUERY PLAN + `--SCAN t2 USING COVERING INDEX i1 +} + +do_execsql_test 7.3 { + INSERT INTO t1(a,b) VALUES(1, 2); + INSERT INTO t1(a,b) VALUES(3, 4); + + INSERT INTO t2(a,b) VALUES(1, 2); + INSERT INTO t2(a,b) VALUES(3, 4); + INSERT INTO t2(a,b) VALUES(5, 6); + + ANALYZE; +} + +db close +sqlite3 db test.db + +det 7.4 "SELECT count(*) FROM t1" { + QUERY PLAN + `--SCAN t1 +} + +det 7.5 "SELECT count(*) FROM t2" { + QUERY PLAN + `--SCAN t2 USING COVERING INDEX i1 +} + +#------------------------------------------------------------------------- +# The following tests - eqp-8.* - test that queries that use the OP_Count +# optimization return something sensible with EQP. +# +drop_all_tables + +do_execsql_test 8.0 { + CREATE TABLE t1(a, b, c, PRIMARY KEY(b, c)) WITHOUT ROWID; + CREATE TABLE t2(a, b, c); +} + +det 8.1.1 "SELECT * FROM t2" { + QUERY PLAN + `--SCAN t2 +} + +det 8.1.2 "SELECT * FROM t2 WHERE rowid=?" { + QUERY PLAN + `--SEARCH t2 USING INTEGER PRIMARY KEY (rowid=?) +} + +det 8.1.3 "SELECT count(*) FROM t2" { + QUERY PLAN + `--SCAN t2 +} + +det 8.2.1 "SELECT * FROM t1" { + QUERY PLAN + `--SCAN t1 +} + +det 8.2.2 "SELECT * FROM t1 WHERE b=?" { + QUERY PLAN + `--SEARCH t1 USING PRIMARY KEY (b=?) +} + +det 8.2.3 "SELECT * FROM t1 WHERE b=? AND c=?" { + QUERY PLAN + `--SEARCH t1 USING PRIMARY KEY (b=? AND c=?) +} + +det 8.2.4 "SELECT count(*) FROM t1" { + QUERY PLAN + `--SCAN t1 +} + +# 2018-08-16: While working on Fossil I discovered that EXPLAIN QUERY PLAN +# did not describe IN operators implemented using a ROWID lookup. These +# test cases ensure that problem as been fixed. +# +do_execsql_test 9.0 { + -- Schema from Fossil 2018-08-16 + CREATE TABLE forumpost( + fpid INTEGER PRIMARY KEY, + froot INT, + fprev INT, + firt INT, + fmtime REAL + ); + CREATE INDEX forumthread ON forumpost(froot,fmtime); + CREATE TABLE blob( + rid INTEGER PRIMARY KEY, + rcvid INTEGER, + size INTEGER, + uuid TEXT UNIQUE NOT NULL, + content BLOB, + CHECK( length(uuid)>=40 AND rid>0 ) + ); + CREATE TABLE event( + type TEXT, + mtime DATETIME, + objid INTEGER PRIMARY KEY, + tagid INTEGER, + uid INTEGER REFERENCES user, + bgcolor TEXT, + euser TEXT, + user TEXT, + ecomment TEXT, + comment TEXT, + brief TEXT, + omtime DATETIME + ); + CREATE INDEX event_i1 ON event(mtime); + CREATE TABLE private(rid INTEGER PRIMARY KEY); +} +do_eqp_test 9.1 { + WITH thread(age,duration,cnt,root,last) AS ( + SELECT + julianday('now') - max(fmtime) AS age, + max(fmtime) - min(fmtime) AS duration, + sum(fprev IS NULL) AS msg_count, + froot, + (SELECT fpid FROM forumpost + WHERE froot=x.froot + AND fpid NOT IN private + ORDER BY fmtime DESC LIMIT 1) + FROM forumpost AS x + WHERE fpid NOT IN private --- Ensure this table mentioned in EQP output! + GROUP BY froot + ORDER BY 1 LIMIT 26 OFFSET 5 + ) + SELECT + thread.age, + thread.duration, + thread.cnt, + blob.uuid, + substr(event.comment,instr(event.comment,':')+1) + FROM thread, blob, event + WHERE blob.rid=thread.last + AND event.objid=thread.last + ORDER BY 1; +} { + QUERY PLAN + |--CO-ROUTINE thread + | |--SCAN x USING INDEX forumthread + | |--USING ROWID SEARCH ON TABLE private FOR IN-OPERATOR + | |--CORRELATED SCALAR SUBQUERY xxxxxx + | | |--SEARCH forumpost USING COVERING INDEX forumthread (froot=?) + | | `--USING ROWID SEARCH ON TABLE private FOR IN-OPERATOR + | `--USE TEMP B-TREE FOR ORDER BY + |--SCAN thread + |--SEARCH blob USING INTEGER PRIMARY KEY (rowid=?) + |--SEARCH event USING INTEGER PRIMARY KEY (rowid=?) + `--USE TEMP B-TREE FOR ORDER BY +} + +finish_test diff --git a/test/errmsg.test b/test/errmsg.test new file mode 100644 index 0000000..f32da59 --- /dev/null +++ b/test/errmsg.test @@ -0,0 +1,118 @@ +# 2001 September 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# Test that if sqlite3_prepare_v2() is used to prepare a query, the +# error-message associated with an sqlite3_step() error is available +# immediately. Whereas if sqlite3_prepare() is used, it is not available +# until sqlite3_finalize() or sqlite3_reset() has been called. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +set testprefix errmsg + +# Test organization: +# +# errmsg-1.* User-defined SQL function errors +# errmsg-2.* Errors generated by the VDBE (constraint failures etc.) +# errmsg-3.* SQLITE_SCHEMA and statement recompilation errors. +# + +proc error_messages_worker {prepare sql schema} { + set ret [list] + + set stmt [$prepare db $sql -1 dummy] + execsql $schema + lappend ret [sqlite3_step $stmt] + lappend ret [sqlite3_errmsg db] + lappend ret [sqlite3_finalize $stmt] + lappend ret [sqlite3_errmsg db] + + set ret +} + +proc error_messages_v2 {sql {schema {}}} { + error_messages_worker sqlite3_prepare_v2 $sql $schema +} + +proc error_messages {sql {schema {}}} { + error_messages_worker sqlite3_prepare $sql $schema +} + +proc sql_error {msg} { error $msg } +db func sql_error sql_error + +#------------------------------------------------------------------------- +# Test error messages returned by user-defined SQL functions. +# +do_test 1.1 { + error_messages "SELECT sql_error('custom message')" +} [list {*}{ + SQLITE_ERROR {SQL logic error} + SQLITE_ERROR {custom message} +}] +do_test 1.2 { + error_messages_v2 "SELECT sql_error('custom message')" +} [list {*}{ + SQLITE_ERROR {custom message} + SQLITE_ERROR {custom message} +}] + +#------------------------------------------------------------------------- +# Test error messages generated directly by VDBE code (e.g. constraint +# failures). +# +do_execsql_test 2.1 { + CREATE TABLE t1(a PRIMARY KEY, b UNIQUE); + INSERT INTO t1 VALUES('abc', 'def'); +} +do_test 2.2 { + error_messages "INSERT INTO t1 VALUES('ghi', 'def')" +} [list {*}{ + SQLITE_ERROR {SQL logic error} + SQLITE_CONSTRAINT {UNIQUE constraint failed: t1.b} +}] +verify_ex_errcode 2.2b SQLITE_CONSTRAINT_UNIQUE +do_test 2.3 { + error_messages_v2 "INSERT INTO t1 VALUES('ghi', 'def')" +} [list {*}{ + SQLITE_CONSTRAINT {UNIQUE constraint failed: t1.b} + SQLITE_CONSTRAINT {UNIQUE constraint failed: t1.b} +}] +verify_ex_errcode 2.3b SQLITE_CONSTRAINT_UNIQUE + +#------------------------------------------------------------------------- +# Test SQLITE_SCHEMA errors. And, for _v2(), test that if the schema +# change invalidates the SQL statement itself the error message is returned +# correctly. +# +do_execsql_test 3.1.1 { + CREATE TABLE t2(a PRIMARY KEY, b UNIQUE); + INSERT INTO t2 VALUES('abc', 'def'); +} +do_test 3.1.2 { + error_messages "SELECT a FROM t2" "DROP TABLE t2" +} [list {*}{ + SQLITE_ERROR {SQL logic error} + SQLITE_SCHEMA {database schema has changed} +}] +do_execsql_test 3.2.1 { + CREATE TABLE t2(a PRIMARY KEY, b UNIQUE); + INSERT INTO t2 VALUES('abc', 'def'); +} +do_test 3.2.2 { + error_messages_v2 "SELECT a FROM t2" "DROP TABLE t2" +} [list {*}{ + SQLITE_ERROR {no such table: t2} + SQLITE_ERROR {no such table: t2} +}] + +finish_test diff --git a/test/eval.test b/test/eval.test new file mode 100644 index 0000000..159e875 --- /dev/null +++ b/test/eval.test @@ -0,0 +1,87 @@ +# 2008 July 11 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file experiments with recursion using the "test_eval()" SQL function +# in order to make sure that SQLite is reentrant. +# +# $Id: eval.test,v 1.2 2008/10/13 10:37:50 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Create a table to work with. +# +do_test eval-1.1 { + execsql { + CREATE TABLE t1(x INTEGER PRIMARY KEY); + INSERT INTO t1 VALUES(1); + INSERT INTO t1 VALUES(2); + INSERT INTO t1 SELECT x+2 FROM t1; + INSERT INTO t1 SELECT x+4 FROM t1; + INSERT INTO t1 SELECT x+8 FROM t1; + INSERT INTO t1 SELECT x+16 FROM t1; + INSERT INTO t1 SELECT x+32 FROM t1; + INSERT INTO t1 SELECT x+64 FROM t1; + INSERT INTO t1 SELECT x+128 FROM t1; + INSERT INTO t1 SELECT x+256 FROM t1; + SELECT count(*), max(x) FROM t1; + } +} {512 512} +do_test eval-1.2 { + execsql { + SELECT x, test_eval('SELECT max(x) FROM t1 WHERE x<' || x) FROM t1 LIMIT 5 + } +} {1 {} 2 1 3 2 4 3 5 4} + +# Delete a row out from under a read cursor in the middle of +# collecting the arguments for a single row in a result set. +# Verify that subsequent rows come out as NULL. +# +do_test eval-2.1 { + execsql { + CREATE TABLE t2(x,y); + INSERT INTO t2 SELECT x, x+1 FROM t1 WHERE x<5; + SELECT x, test_eval('DELETE FROM t2 WHERE x='||x), y FROM t2; + } +} {1 {} {} 2 {} {} 3 {} {} 4 {} {}} +do_test eval-2.2 { + execsql { + SELECT * FROM t2 + } +} {} +do_test eval-2.3 { + execsql { + INSERT INTO t2 SELECT x, x+1 FROM t1 WHERE x<5; + SELECT x, test_eval('DELETE FROM t2 WHERE x='||x), y FROM t2 + ORDER BY rowid DESC; + } +} {4 {} {} 3 {} {} 2 {} {} 1 {} {}} +do_test eval-2.4 { + execsql { + SELECT * FROM t2 + } +} {} + +# Modify a row while it is being read. +# +do_test eval-3.1 { + execsql { + INSERT INTO t2 SELECT x, x+1 FROM t1 WHERE x<5; + SELECT x, test_eval('UPDATE t2 SET y=y+100 WHERE x='||x), y FROM t2; + } +} {1 {} 102 2 {} 103 3 {} 104 4 {} 105} + +do_test eval-4.1 { + execsql { SELECT test_eval('SELECT ''abcdefghij''') } +} {abcdefghij} + +finish_test diff --git a/test/exclusive.test b/test/exclusive.test new file mode 100644 index 0000000..494ede7 --- /dev/null +++ b/test/exclusive.test @@ -0,0 +1,540 @@ +# 2007 March 24 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The focus +# of these tests is exclusive access mode (i.e. the thing activated by +# "PRAGMA locking_mode = EXCLUSIVE"). +# +# $Id: exclusive.test,v 1.15 2009/06/26 12:30:40 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable {!pager_pragmas} { + finish_test + return +} + +forcedelete test2.db-journal +forcedelete test2.db +forcedelete test3.db-journal +forcedelete test3.db +forcedelete test4.db-journal +forcedelete test4.db + +#---------------------------------------------------------------------- +# Test cases exclusive-1.X test the PRAGMA logic. +# +do_test exclusive-1.0 { + execsql { + pragma locking_mode; + pragma main.locking_mode; + pragma temp.locking_mode; + } +} [list normal normal exclusive] +do_test exclusive-1.1 { + execsql { + pragma locking_mode = exclusive; + } +} {exclusive} +do_test exclusive-1.2 { + execsql { + pragma locking_mode; + pragma main.locking_mode; + pragma temp.locking_mode; + } +} [list exclusive exclusive exclusive] +do_test exclusive-1.3 { + execsql { + pragma locking_mode = normal; + } +} {normal} +do_test exclusive-1.4 { + execsql { + pragma locking_mode; + pragma main.locking_mode; + pragma temp.locking_mode; + } +} [list normal normal exclusive] +do_test exclusive-1.5 { + execsql { + pragma locking_mode = invalid; + } +} {normal} +do_test exclusive-1.6 { + execsql { + pragma locking_mode; + pragma main.locking_mode; + pragma temp.locking_mode; + } +} [list normal normal exclusive] +ifcapable attach { + do_test exclusive-1.7 { + execsql { + pragma locking_mode = exclusive; + ATTACH 'test2.db' as aux; + } + execsql { + pragma main.locking_mode; + pragma aux.locking_mode; + } + } {exclusive exclusive} + do_test exclusive-1.8 { + execsql { + pragma main.locking_mode = normal; + } + execsql { + pragma main.locking_mode; + pragma temp.locking_mode; + pragma aux.locking_mode; + } + } [list normal exclusive exclusive] + do_test exclusive-1.9 { + execsql { + pragma locking_mode; + } + } {exclusive} + do_test exclusive-1.10 { + execsql { + ATTACH 'test3.db' as aux2; + } + execsql { + pragma main.locking_mode; + pragma aux.locking_mode; + pragma aux2.locking_mode; + } + } {normal exclusive exclusive} + do_test exclusive-1.11 { + execsql { + pragma aux.locking_mode = normal; + } + execsql { + pragma main.locking_mode; + pragma aux.locking_mode; + pragma aux2.locking_mode; + } + } {normal normal exclusive} + do_test exclusive-1.12 { + execsql { + pragma locking_mode = normal; + } + execsql { + pragma main.locking_mode; + pragma temp.locking_mode; + pragma aux.locking_mode; + pragma aux2.locking_mode; + } + } [list normal exclusive normal normal] + do_test exclusive-1.13 { + execsql { + ATTACH 'test4.db' as aux3; + } + execsql { + pragma main.locking_mode; + pragma temp.locking_mode; + pragma aux.locking_mode; + pragma aux2.locking_mode; + pragma aux3.locking_mode; + } + } [list normal exclusive normal normal normal] + + do_test exclusive-1.99 { + execsql { + DETACH aux; + DETACH aux2; + DETACH aux3; + } + } {} +} + +#---------------------------------------------------------------------- +# Test cases exclusive-2.X verify that connections in exclusive +# locking_mode do not relinquish locks. +# +do_test exclusive-2.0 { + execsql { + CREATE TABLE abc(a, b, c); + INSERT INTO abc VALUES(1, 2, 3); + PRAGMA locking_mode = exclusive; + } +} {exclusive} +do_test exclusive-2.1 { + sqlite3 db2 test.db + execsql { + INSERT INTO abc VALUES(4, 5, 6); + SELECT * FROM abc; + } db2 +} {1 2 3 4 5 6} +do_test exclusive-2.2 { + # This causes connection 'db' (in exclusive mode) to establish + # a shared-lock on the db. The other connection should now be + # locked out as a writer. + execsql { + SELECT * FROM abc; + } db +} {1 2 3 4 5 6} +do_test exclusive-2.4 { + execsql { + SELECT * FROM abc; + } db2 +} {1 2 3 4 5 6} +do_test exclusive-2.5 { + catchsql { + INSERT INTO abc VALUES(7, 8, 9); + } db2 +} {1 {database is locked}} +sqlite3_soft_heap_limit 0 +do_test exclusive-2.6 { + # Because connection 'db' only has a shared-lock, the other connection + # will be able to get a RESERVED, but will fail to upgrade to EXCLUSIVE. + execsql { + BEGIN; + INSERT INTO abc VALUES(7, 8, 9); + } db2 + catchsql { + COMMIT + } db2 +} {1 {database is locked}} +do_test exclusive-2.7 { + catchsql { + COMMIT + } db2 +} {1 {database is locked}} +do_test exclusive-2.8 { + execsql { + ROLLBACK; + } db2 +} {} +sqlite3_soft_heap_limit $cmdlinearg(soft-heap-limit) + +do_test exclusive-2.9 { + # Write the database to establish the exclusive lock with connection 'db. + execsql { + INSERT INTO abc VALUES(7, 8, 9); + } db + catchsql { + SELECT * FROM abc; + } db2 +} {1 {database is locked}} +do_test exclusive-2.10 { + # Changing the locking-mode does not release any locks. + execsql { + PRAGMA locking_mode = normal; + } db + catchsql { + SELECT * FROM abc; + } db2 +} {1 {database is locked}} +do_test exclusive-2.11 { + # After changing the locking mode, accessing the db releases locks. + execsql { + SELECT * FROM abc; + } db + execsql { + SELECT * FROM abc; + } db2 +} {1 2 3 4 5 6 7 8 9} +db2 close + +#---------------------------------------------------------------------- +# Tests exclusive-3.X - test that a connection in exclusive mode +# truncates instead of deletes the journal file when committing +# a transaction. +# +# These tests are not run on windows because the windows backend +# opens the journal file for exclusive access, preventing its contents +# from being inspected externally. +# +if {$tcl_platform(platform) != "windows" + && [atomic_batch_write test.db]==0 +} { + + # Return a list of two booleans (either 0 or 1). The first is true + # if the named file exists. The second is true only if the file + # exists and the first 28 bytes contain at least one non-zero byte. + # + proc filestate {fname} { + set exists 0 + set content 0 + if {[file exists $fname]} { + set exists 1 + set hdr [hexio_read $fname 0 28] + set content [expr {0==[string match $hdr [string repeat 0 56]]}] + } + list $exists $content + } + + do_test exclusive-3.0 { + filestate test.db-journal + } {0 0} + do_test exclusive-3.1 { + execsql { + PRAGMA locking_mode = exclusive; + BEGIN; + DELETE FROM abc; + } + filestate test.db-journal + } {1 1} + do_test exclusive-3.2 { + execsql { + COMMIT; + } + filestate test.db-journal + } {1 0} + do_test exclusive-3.3 { + execsql { + INSERT INTO abc VALUES('A', 'B', 'C'); + SELECT * FROM abc; + } + } {A B C} + do_test exclusive-3.4 { + execsql { + BEGIN; + UPDATE abc SET a = 1, b = 2, c = 3; + ROLLBACK; + SELECT * FROM abc; + } + } {A B C} + do_test exclusive-3.5 { + filestate test.db-journal + } {1 0} + do_test exclusive-3.6 { + execsql { + PRAGMA locking_mode = normal; + SELECT * FROM abc; + } + filestate test.db-journal + } {0 0} +} + +#---------------------------------------------------------------------- +# Tests exclusive-4.X - test that rollback works correctly when +# in exclusive-access mode. +# + +# The following procedure computes a "signature" for table "t3". If +# T3 changes in any way, the signature should change. +# +# This is used to test ROLLBACK. We gather a signature for t3, then +# make lots of changes to t3, then rollback and take another signature. +# The two signatures should be the same. +# +proc signature {} { + return [db eval {SELECT count(*), md5sum(x) FROM t3}] +} + +do_test exclusive-4.0 { + execsql { PRAGMA locking_mode = exclusive; } + execsql { PRAGMA default_cache_size = 10; } + execsql { + BEGIN; + CREATE TABLE t3(x TEXT); + INSERT INTO t3 VALUES(randstr(10,400)); + INSERT INTO t3 VALUES(randstr(10,400)); + INSERT INTO t3 SELECT randstr(10,400) FROM t3; + INSERT INTO t3 SELECT randstr(10,400) FROM t3; + INSERT INTO t3 SELECT randstr(10,400) FROM t3; + INSERT INTO t3 SELECT randstr(10,400) FROM t3; + COMMIT; + } + execsql {SELECT count(*) FROM t3;} +} {32} + +set ::X [signature] +do_test exclusive-4.1 { + execsql { + BEGIN; + DELETE FROM t3 WHERE random()%10!=0; + INSERT INTO t3 SELECT randstr(10,10)||x FROM t3; + INSERT INTO t3 SELECT randstr(10,10)||x FROM t3; + SELECT count(*) FROM t3; + ROLLBACK; + } + signature +} $::X + +do_test exclusive-4.2 { + execsql { + BEGIN; + DELETE FROM t3 WHERE random()%10!=0; + INSERT INTO t3 SELECT randstr(10,10)||x FROM t3; + DELETE FROM t3 WHERE random()%10!=0; + INSERT INTO t3 SELECT randstr(10,10)||x FROM t3; + ROLLBACK; + } + signature +} $::X + +do_test exclusive-4.3 { + execsql { + INSERT INTO t3 SELECT randstr(10,400) FROM t3 WHERE random()%10==0; + } +} {} + +do_test exclusive-4.4 { + catch {set ::X [signature]} +} {0} +do_test exclusive-4.5 { + execsql { + PRAGMA locking_mode = NORMAL; + DROP TABLE t3; + DROP TABLE abc; + } +} {normal} + +#---------------------------------------------------------------------- +# Tests exclusive-5.X - test that statement journals are truncated +# instead of deleted when in exclusive access mode. +# +if {[atomic_batch_write test.db]==0} { + +# Close and reopen the database so that the temp database is no +# longer active. +# +db close +sqlite3 db test.db + +# if we're using proxy locks, we use 3 filedescriptors for a db +# that is open but NOT writing changes, normally +# sqlite uses 1 (proxy locking adds the conch and the local lock) +set using_proxy 0 +foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] { + set using_proxy $value +} +set extrafds 0 +if {$using_proxy!=0} { + set extrafds 2 +} + +do_test exclusive-5.0 { + execsql { + CREATE TABLE abc(a UNIQUE, b UNIQUE, c UNIQUE); + BEGIN; + INSERT INTO abc VALUES(1, 2, 3); + INSERT INTO abc SELECT a+1, b+1, c+1 FROM abc; + } +} {} +do_test exclusive-5.1 { + # Three files are open: The db, journal and statement-journal. + # (2016-03-04) The statement-journal is now opened lazily + set sqlite_open_file_count + expr $sqlite_open_file_count-$extrafds +} {2} +do_test exclusive-5.2 { + execsql { + COMMIT; + } + # One file open: the db. + set sqlite_open_file_count + expr $sqlite_open_file_count-$extrafds +} {1} +do_test exclusive-5.3 { + execsql { + PRAGMA locking_mode = exclusive; + BEGIN; + INSERT INTO abc VALUES(5, 6, 7); + } + # Two files open: the db and journal. + set sqlite_open_file_count + expr $sqlite_open_file_count-$extrafds +} {2} +do_test exclusive-5.4 { + execsql { + INSERT INTO abc SELECT a+10, b+10, c+10 FROM abc; + } + # Three files are open: The db, journal and statement-journal. + # 2016-03-04: The statement-journal open is deferred + set sqlite_open_file_count + expr $sqlite_open_file_count-$extrafds +} {2} +do_test exclusive-5.5 { + execsql { + COMMIT; + } + # Three files are still open: The db, journal and statement-journal. + # 2016-03-04: The statement-journal open is deferred + set sqlite_open_file_count + expr $sqlite_open_file_count-$extrafds +} {2} +do_test exclusive-5.6 { + execsql { + PRAGMA locking_mode = normal; + SELECT * FROM abc; + } +} {normal 1 2 3 2 3 4 5 6 7 11 12 13 12 13 14 15 16 17} +do_test exclusive-5.7 { + # Just the db open. + set sqlite_open_file_count + expr $sqlite_open_file_count-$extrafds +} {1} + +#------------------------------------------------------------------------- + +do_execsql_test exclusive-6.1 { + CREATE TABLE t4(a, b); + INSERT INTO t4 VALUES('Eden', 1955); + BEGIN; + INSERT INTO t4 VALUES('Macmillan', 1957); + INSERT INTO t4 VALUES('Douglas-Home', 1963); + INSERT INTO t4 VALUES('Wilson', 1964); +} +do_test exclusive-6.2 { + forcedelete test2.db test2.db-journal + copy_file test.db test2.db + copy_file test.db-journal test2.db-journal + sqlite3 db test2.db +} {} + +do_execsql_test exclusive-6.3 { + PRAGMA locking_mode = EXCLUSIVE; + SELECT * FROM t4; +} {exclusive Eden 1955} + +do_test exclusive-6.4 { + db close + forcedelete test.db test.db-journal + set fd [open test.db-journal w] + puts $fd x + close $fd + sqlite3 db test.db +} {} + +do_execsql_test exclusive-6.5 { + PRAGMA locking_mode = EXCLUSIVE; + SELECT * FROM sqlite_master; +} {exclusive} + +# 2019-12-26 ticket fb3b3024ea238d5c +if {[permutation]!="journaltest"} { + # The custom VFS used by the "journaltest" permutation cannot open the + # shared-memory file. So, while it is able to switch the db file to + # journal_mode=WAL when locking_mode=EXCLUSIVE, it can no longer access + # it once the locking_mode is changed back to NORMAL. + do_test exclusive-7.1 { + db close + forcedelete test.db test.db-journal test.db-wal + sqlite3 db test.db + # The following sequence of pragmas would trigger an assert() + # associated with Pager.changeCountDone inside of assert_pager_state(), + # prior to the fix. + db eval { + PRAGMA locking_mode = EXCLUSIVE; + PRAGMA journal_mode = WAL; + PRAGMA locking_mode = NORMAL; + PRAGMA user_version; + PRAGMA journal_mode = DELETE; + } + } {exclusive wal normal 0 delete} +} + + +} ;# atomic_batch_write==0 + +finish_test diff --git a/test/exclusive2.test b/test/exclusive2.test new file mode 100644 index 0000000..92fcd76 --- /dev/null +++ b/test/exclusive2.test @@ -0,0 +1,324 @@ +# 2007 March 24 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# $Id: exclusive2.test,v 1.10 2008/11/27 02:22:11 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +ifcapable {!pager_pragmas} { + finish_test + return +} + +# Tests in this file verify that locking_mode=exclusive causes SQLite to +# use cached pages even if the database is changed on disk. This doesn't +# work with mmap. +if {[permutation]=="mmap"} { + finish_test + return +} + +# This module does not work right if the cache spills at unexpected +# moments. So disable the soft-heap-limit. +# +sqlite3_soft_heap_limit 0 + +proc pagerChangeCounter {filename new {fd ""}} { + if {$fd==""} { + set fd [open $filename RDWR] + fconfigure $fd -translation binary -encoding binary + set needClose 1 + } else { + set needClose 0 + } + if {$new ne ""} { + seek $fd 24 + set a [expr {($new&0xFF000000)>>24}] + set b [expr {($new&0x00FF0000)>>16}] + set c [expr {($new&0x0000FF00)>>8}] + set d [expr {($new&0x000000FF)}] + puts -nonewline $fd [binary format cccc $a $b $c $d] + flush $fd + } + + seek $fd 24 + foreach {a b c d} [list 0 0 0 0] {} + binary scan [read $fd 4] cccc a b c d + set ret [expr ($a&0x000000FF)<<24] + incr ret [expr ($b&0x000000FF)<<16] + incr ret [expr ($c&0x000000FF)<<8] + incr ret [expr ($d&0x000000FF)<<0] + + if {$needClose} {close $fd} + return $ret +} + +proc readPagerChangeCounter {filename} { + set fd [open $filename RDONLY] + fconfigure $fd -translation binary -encoding binary + + seek $fd 24 + foreach {a b c d} [list 0 0 0 0] {} + binary scan [read $fd 4] cccc a b c d + set ret [expr ($a&0x000000FF)<<24] + incr ret [expr ($b&0x000000FF)<<16] + incr ret [expr ($c&0x000000FF)<<8] + incr ret [expr ($d&0x000000FF)<<0] + + close $fd + return $ret +} + + +proc t1sig {{db db}} { + execsql {SELECT count(*), md5sum(a) FROM t1} $db +} +do_test exclusive2-1.0 { + readPagerChangeCounter test.db +} {0} + +#----------------------------------------------------------------------- +# The following tests - exclusive2-1.X - check that: +# +# 1-3: Build a database with connection 1, calculate a signature. +# 4-7: Modify the database using a second connection in a way that +# does not modify the freelist, then reset the pager change-counter +# to the value it had before the modifications. +# 8: Check that using the first connection, the database signature +# is still the same. This is because it uses the in-memory cache. +# It can't tell the db has changed because we reset the change-counter. +# 9: Increment the change-counter. +# 10: Ensure that the first connection now sees the updated database. It +# sees the change-counter has been incremented and discards the +# invalid in-memory cache. +# +# This will only work if the database cache is large enough to hold +# the entire database. In the case of 1024 byte pages, this means +# the cache size must be at least 17. Otherwise, some pages will be +# loaded from the database file in step 8. +# +# For similar reasons, this test does not work with the memsubsys1 permutation. +# Permutation memsubsys1 configures the pcache subsystem to use a static +# allocation of 24 pages (shared between all pagers). This is not enough for +# this test. +# +do_test exclusive2-1.1 { + execsql { + BEGIN; + CREATE TABLE t1(a, b); + INSERT INTO t1(a, b) VALUES(randstr(10, 400), 0); + INSERT INTO t1(a, b) VALUES(randstr(10, 400), 0); + INSERT INTO t1(a, b) SELECT randstr(10, 400), 0 FROM t1; + INSERT INTO t1(a, b) SELECT randstr(10, 400), 0 FROM t1; + INSERT INTO t1(a, b) SELECT randstr(10, 400), 0 FROM t1; + INSERT INTO t1(a, b) SELECT randstr(10, 400), 0 FROM t1; + INSERT INTO t1(a, b) SELECT randstr(10, 400), 0 FROM t1; + COMMIT; + SELECT count(*) FROM t1; + } +} {64} +do_test exclusive2-1.2.1 { + # Make sure the pager cache is large enough to store the + # entire database. + set nPage [expr [file size test.db]/1024] + if {$::SQLITE_DEFAULT_CACHE_SIZE < $nPage} { + execsql "PRAGMA cache_size = $nPage" + } + expr {[execsql {PRAGMA cache_size}] >= $nPage} +} {1} +do_test exclusive2-1.2 { + set ::sig [t1sig] + readPagerChangeCounter test.db +} {1} +do_test exclusive2-1.3 { + t1sig +} $::sig +do_test exclusive2-1.4 { + sqlite3 db2 test.db + t1sig db2 +} $::sig +do_test exclusive2-1.5 { + execsql { + UPDATE t1 SET b=a, a=0; + } db2 + expr {[t1sig db2] eq $::sig} +} 0 +do_test exclusive2-1.6 { + readPagerChangeCounter test.db +} {2} +do_test exclusive2-1.7 { + pagerChangeCounter test.db 1 +} {1} +if {[permutation] != "memsubsys1"} { + do_test exclusive2-1.9 { + t1sig + expr {[t1sig] eq $::sig} + } {1} +} +do_test exclusive2-1.10 { + pagerChangeCounter test.db 2 +} {2} +do_test exclusive2-1.11 { + expr {[t1sig] eq $::sig} +} {0} +db2 close + +#-------------------------------------------------------------------- +# These tests - exclusive2-2.X - are similar to exclusive2-1.X, +# except that they are run with locking_mode=EXCLUSIVE. +# +# 1-3: Build a database with exclusive-access connection 1, +# calculate a signature. +# 4: Corrupt the database by writing 10000 bytes of garbage +# starting at the beginning of page 2. Check that connection 1 +# still works. It should be accessing the in-memory cache. +# 5-6: Modify the dataase change-counter. Connection 1 still works +# entirely from in-memory cache, because it doesn't check the +# change-counter. +# 7-8 Set the locking-mode back to normal. After the db is unlocked, +# SQLite detects the modified change-counter and discards the +# in-memory cache. Then it finds the corruption caused in step 4.... +# +# As above, this test is only applicable if the pager cache is +# large enough to hold the entire database. With 1024 byte pages, +# this means 19 pages. We also need to disable the soft-heap-limit +# to prevent memory-induced cache spills. +# +do_test exclusive2-2.1 { + execsql {PRAGMA cache_size=1000;} + execsql {PRAGMA locking_mode = exclusive;} + execsql { + BEGIN; + DELETE FROM t1; + INSERT INTO t1(a) VALUES(randstr(10, 400)); + INSERT INTO t1(a) VALUES(randstr(10, 400)); + INSERT INTO t1(a) SELECT randstr(10, 400) FROM t1; + INSERT INTO t1(a) SELECT randstr(10, 400) FROM t1; + INSERT INTO t1(a) SELECT randstr(10, 400) FROM t1; + INSERT INTO t1(a) SELECT randstr(10, 400) FROM t1; + INSERT INTO t1(a) SELECT randstr(10, 400) FROM t1; + COMMIT; + SELECT count(*) FROM t1; + } +} {64} +do_test exclusive2-2.2.1 { + # Make sure the pager cache is large enough to store the + # entire database. + set nPage [expr [file size test.db]/1024] + if {$::SQLITE_DEFAULT_CACHE_SIZE < $nPage} { + execsql "PRAGMA cache_size = $nPage" + } + expr {[execsql {PRAGMA cache_size}] >= $nPage} +} {1} +do_test exclusive2-2.2 { + set ::sig [t1sig] + readPagerChangeCounter test.db +} {3} +do_test exclusive2-2.3 { + t1sig +} $::sig + +do_test exclusive2-2.4 { + set ::fd [open test.db RDWR] + fconfigure $::fd -translation binary + seek $::fd 1024 + puts -nonewline $::fd [string repeat [binary format c 0] 10000] + flush $::fd + t1sig +} $::sig + +do_test exclusive2-2.5 { + pagerChangeCounter test.db 5 $::fd +} {5} +do_test exclusive2-2.6 { + t1sig +} $::sig +do_test exclusive2-2.7 { + execsql {PRAGMA locking_mode = normal} + t1sig +} $::sig + +do_test exclusive2-2.8 { + set rc [catch {t1sig} msg] + list $rc $msg +} {1 {database disk image is malformed}} + +#-------------------------------------------------------------------- +# These tests - exclusive2-3.X - verify that the pager change-counter +# is only incremented by the first change when in exclusive access +# mode. In normal mode, the change-counter is incremented once +# per write-transaction. +# + +db close +catch {close $::fd} +forcedelete test.db +forcedelete test.db-journal + +do_test exclusive2-3.0 { + sqlite3 db test.db + execsql { + BEGIN; + CREATE TABLE t1(a UNIQUE); + INSERT INTO t1 VALUES(randstr(200, 200)); + INSERT INTO t1 VALUES(randstr(200, 200)); + COMMIT; + } + readPagerChangeCounter test.db +} {1} +do_test exclusive2-3.1 { + execsql { + INSERT INTO t1 VALUES(randstr(200, 200)); + } + readPagerChangeCounter test.db +} {2} +do_test exclusive2-3.2 { + execsql { + INSERT INTO t1 VALUES(randstr(200, 200)); + } + readPagerChangeCounter test.db +} {3} +do_test exclusive2-3.3 { + execsql { + PRAGMA locking_mode = exclusive; + INSERT INTO t1 VALUES(randstr(200, 200)); + } + readPagerChangeCounter test.db +} {4} +do_test exclusive2-3.4 { + execsql { + INSERT INTO t1 VALUES(randstr(200, 200)); + } + readPagerChangeCounter test.db +} {4} +do_test exclusive2-3.5 { + execsql { + PRAGMA locking_mode = normal; + INSERT INTO t1 VALUES(randstr(200, 200)); + } + readPagerChangeCounter test.db +} {4} +do_test exclusive2-3.6 { + execsql { + INSERT INTO t1 VALUES(randstr(200, 200)); + } + readPagerChangeCounter test.db +} {5} +sqlite3_soft_heap_limit $cmdlinearg(soft-heap-limit) + +finish_test diff --git a/test/exec.test b/test/exec.test new file mode 100644 index 0000000..dbcc626 --- /dev/null +++ b/test/exec.test @@ -0,0 +1,37 @@ +# 2008 Jan 21 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests for the sqlite3_exec interface +# +# $Id: exec.test,v 1.1 2008/01/21 16:22:46 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +do_test exec-1.1 { + execsql { + CREATE TABLE t1(a,b); + INSERT INTO t1 VALUES(1,2); + SELECT * FROM t1; + } +} {1 2} +do_test exec-1.2 { + sqlite3_exec db {/* comment */;;; SELECT * FROM t1; /* comment */} +} {0 {a b 1 2}} +do_test exec-1.3 { + sqlite3 db2 test.db + db2 eval {CREATE TABLE t2(x, y);} + db2 close + sqlite3_exec db {SELECT * FROM t1} +} {0 {a b 1 2}} + +finish_test diff --git a/test/exists.test b/test/exists.test new file mode 100644 index 0000000..5f9e36e --- /dev/null +++ b/test/exists.test @@ -0,0 +1,199 @@ +# 2011 April 9 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing the various schema modification statements +# that feature "IF EXISTS" or "IF NOT EXISTS" clauses. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/lock_common.tcl + + +foreach jm {rollback wal} { + if {![wal_is_capable] && $jm=="wal"} continue + + set testprefix exists-$jm + + # This block of tests is targeted at CREATE XXX IF NOT EXISTS statements. + # + do_multiclient_test tn { + + # TABLE objects. + # + do_test 1.$tn.1.1 { + if {$jm == "wal"} { sql2 { PRAGMA journal_mode = WAL } } + sql2 { CREATE TABLE t1(x) } + sql1 { CREATE TABLE IF NOT EXISTS t1(a, b) } + sql2 { DROP TABLE t1 } + sql1 { CREATE TABLE IF NOT EXISTS t1(a, b) } + sql2 { SELECT name FROM sqlite_master WHERE type = 'table' } + } {t1} + + do_test 1.$tn.1.2 { + sql2 { CREATE TABLE t2(x) } + sql1 { CREATE TABLE IF NOT EXISTS t2 AS SELECT * FROM t1 } + sql2 { DROP TABLE t2 } + sql1 { CREATE TABLE IF NOT EXISTS t2 AS SELECT * FROM t1 } + sql2 { SELECT name FROM sqlite_master WHERE type = 'table' } + } {t1 t2} + + + # INDEX objects. + # + do_test 1.$tn.2 { + sql2 { CREATE INDEX i1 ON t1(a) } + sql1 { CREATE INDEX IF NOT EXISTS i1 ON t1(a, b) } + sql2 { DROP INDEX i1 } + sql1 { CREATE INDEX IF NOT EXISTS i1 ON t1(a, b) } + sql2 { SELECT name FROM sqlite_master WHERE type = 'index' } + } {i1} + + # VIEW objects. + # + do_test 1.$tn.3 { + sql2 { CREATE VIEW v1 AS SELECT * FROM t1 } + sql1 { CREATE VIEW IF NOT EXISTS v1 AS SELECT * FROM t1 } + sql2 { DROP VIEW v1 } + sql1 { CREATE VIEW IF NOT EXISTS v1 AS SELECT * FROM t1 } + sql2 { SELECT name FROM sqlite_master WHERE type = 'view' } + } {v1} + + # TRIGGER objects. + # + do_test $tn.4 { + sql2 { CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN SELECT 1; END } + sql1 { CREATE TRIGGER IF NOT EXISTS tr1 AFTER INSERT ON t1 BEGIN SELECT 1; END } + sql2 { DROP TRIGGER tr1 } + sql1 { CREATE TRIGGER IF NOT EXISTS tr1 AFTER INSERT ON t1 BEGIN SELECT 1; END } + sql2 { SELECT name FROM sqlite_master WHERE type = 'trigger' } + } {tr1} + } + + # This block of tests is targeted at DROP XXX IF EXISTS statements. + # + do_multiclient_test tn { + + # TABLE objects. + # + do_test 2.$tn.1 { + if {$jm == "wal"} { sql1 { PRAGMA journal_mode = WAL } } + sql1 { DROP TABLE IF EXISTS t1 } + sql2 { CREATE TABLE t1(x) } + sql1 { DROP TABLE IF EXISTS t1 } + sql2 { SELECT name FROM sqlite_master WHERE type = 'table' } + } {} + + # INDEX objects. + # + do_test 2.$tn.2 { + sql1 { CREATE TABLE t2(x) } + sql1 { DROP INDEX IF EXISTS i2 } + sql2 { CREATE INDEX i2 ON t2(x) } + sql1 { DROP INDEX IF EXISTS i2 } + sql2 { SELECT name FROM sqlite_master WHERE type = 'index' } + } {} + + # VIEW objects. + # + do_test 2.$tn.3 { + sql1 { DROP VIEW IF EXISTS v1 } + sql2 { CREATE VIEW v1 AS SELECT * FROM t2 } + sql1 { DROP VIEW IF EXISTS v1 } + sql2 { SELECT name FROM sqlite_master WHERE type = 'view' } + } {} + + # TRIGGER objects. + # + do_test 2.$tn.4 { + sql1 { DROP TRIGGER IF EXISTS tr1 } + sql2 { CREATE TRIGGER tr1 AFTER INSERT ON t2 BEGIN SELECT 1; END } + sql1 { DROP TRIGGER IF EXISTS tr1 } + sql2 { SELECT name FROM sqlite_master WHERE type = 'trigger' } + } {} + } + + # This block of tests is targeted at DROP XXX IF EXISTS statements with + # attached databases. + # + do_multiclient_test tn { + + forcedelete test.db2 + do_test 3.$tn.0 { + sql1 { ATTACH 'test.db2' AS aux } + sql2 { ATTACH 'test.db2' AS aux } + } {} + + # TABLE objects. + # + do_test 3.$tn.1.1 { + sql1 { DROP TABLE IF EXISTS aux.t1 } + sql2 { CREATE TABLE aux.t1(x) } + sql1 { DROP TABLE IF EXISTS aux.t1 } + sql2 { SELECT name FROM aux.sqlite_master WHERE type = 'table' } + } {} + do_test 3.$tn.1.2 { + sql1 { DROP TABLE IF EXISTS t1 } + sql2 { CREATE TABLE aux.t1(x) } + sql1 { DROP TABLE IF EXISTS t1 } + sql2 { SELECT name FROM aux.sqlite_master WHERE type = 'table' } + } {} + + # INDEX objects. + # + do_test 3.$tn.2.1 { + sql1 { CREATE TABLE aux.t2(x) } + sql1 { DROP INDEX IF EXISTS aux.i2 } + sql2 { CREATE INDEX aux.i2 ON t2(x) } + sql1 { DROP INDEX IF EXISTS aux.i2 } + sql2 { SELECT name FROM aux.sqlite_master WHERE type = 'index' } + } {} + do_test 3.$tn.2.2 { + sql1 { DROP INDEX IF EXISTS i2 } + sql2 { CREATE INDEX aux.i2 ON t2(x) } + sql1 { DROP INDEX IF EXISTS i2 } + sql2 { SELECT * FROM aux.sqlite_master WHERE type = 'index' } + } {} + + # VIEW objects. + # + do_test 3.$tn.3.1 { + sql1 { DROP VIEW IF EXISTS aux.v1 } + sql2 { CREATE VIEW aux.v1 AS SELECT * FROM t2 } + sql1 { DROP VIEW IF EXISTS aux.v1 } + sql2 { SELECT name FROM aux.sqlite_master WHERE type = 'view' } + } {} + do_test 3.$tn.3.2 { + sql1 { DROP VIEW IF EXISTS v1 } + sql2 { CREATE VIEW aux.v1 AS SELECT * FROM t2 } + sql1 { DROP VIEW IF EXISTS v1 } + sql2 { SELECT name FROM aux.sqlite_master WHERE type = 'view' } + } {} + + # TRIGGER objects. + # + do_test 3.$tn.4.1 { + sql1 { DROP TRIGGER IF EXISTS aux.tr1 } + sql2 { CREATE TRIGGER aux.tr1 AFTER INSERT ON t2 BEGIN SELECT 1; END } + sql1 { DROP TRIGGER IF EXISTS aux.tr1 } + sql2 { SELECT name FROM aux.sqlite_master WHERE type = 'trigger' } + } {} + do_test 3.$tn.4.2 { + sql1 { DROP TRIGGER IF EXISTS tr1 } + sql2 { CREATE TRIGGER aux.tr1 AFTER INSERT ON t2 BEGIN SELECT 1; END } + sql1 { DROP TRIGGER IF EXISTS tr1 } + sql2 { SELECT name FROM aux.sqlite_master WHERE type = 'trigger' } + } {} + } +} + + +finish_test diff --git a/test/expr.test b/test/expr.test new file mode 100644 index 0000000..55b1dc9 --- /dev/null +++ b/test/expr.test @@ -0,0 +1,1084 @@ +# 2001 September 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing expressions. +# +# $Id: expr.test,v 1.67 2009/02/04 03:59:25 shane Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Create a table to work with. +# +ifcapable floatingpoint { + execsql {CREATE TABLE test1(i1 int, i2 int, r1 real, r2 real, t1 text, t2 text)} + execsql {INSERT INTO test1 VALUES(1,2,1.1,2.2,'hello','world')} +} +ifcapable !floatingpoint { + execsql {CREATE TABLE test1(i1 int, i2 int, t1 text, t2 text)} + execsql {INSERT INTO test1 VALUES(1,2,'hello','world')} +} + +proc test_expr {name settings expr result} { + do_test $name [format { + execsql {BEGIN; UPDATE test1 SET %s; SELECT %s FROM test1; ROLLBACK;} + } $settings $expr] $result +} +proc test_realnum_expr {name settings expr result} { + do_realnum_test $name [format { + execsql {BEGIN; UPDATE test1 SET %s; SELECT %s FROM test1; ROLLBACK;} + } $settings $expr] $result +} + +test_expr expr-1.1 {i1=10, i2=20} {i1+i2} 30 +test_expr expr-1.2 {i1=10, i2=20} {i1-i2} -10 +test_expr expr-1.3 {i1=10, i2=20} {i1*i2} 200 +test_expr expr-1.4 {i1=10, i2=20} {i1/i2} 0 +test_expr expr-1.5 {i1=10, i2=20} {i2/i1} 2 +test_expr expr-1.6 {i1=10, i2=20} {i2i1} 1 +test_expr expr-1.9 {i1=10, i2=20} {i2>=i1} 1 +test_expr expr-1.10 {i1=10, i2=20} {i2!=i1} 1 +test_expr expr-1.11 {i1=10, i2=20} {i2=i1} 0 +test_expr expr-1.12 {i1=10, i2=20} {i2<>i1} 1 +test_expr expr-1.13 {i1=10, i2=20} {i2==i1} 0 +test_expr expr-1.14 {i1=20, i2=20} {i2i1} 0 +test_expr expr-1.17 {i1=20, i2=20} {i2>=i1} 1 +test_expr expr-1.18 {i1=20, i2=20} {i2!=i1} 0 +test_expr expr-1.19 {i1=20, i2=20} {i2=i1} 1 +test_expr expr-1.20 {i1=20, i2=20} {i2<>i1} 0 +test_expr expr-1.21 {i1=20, i2=20} {i2==i1} 1 +ifcapable floatingpoint { + test_expr expr-1.22 {i1=1, i2=2, r1=3.0} {i1+i2*r1} {7.0} + test_expr expr-1.23 {i1=1, i2=2, r1=3.0} {(i1+i2)*r1} {9.0} +} +test_expr expr-1.24 {i1=1, i2=2} {min(i1,i2,i1+i2,i1-i2)} {-1} +test_expr expr-1.25 {i1=1, i2=2} {max(i1,i2,i1+i2,i1-i2)} {3} +test_expr expr-1.26 {i1=1, i2=2} {max(i1,i2,i1+i2,i1-i2)} {3} +test_expr expr-1.27 {i1=1, i2=2} {i1==1 AND i2=2} {1} +test_expr expr-1.28 {i1=1, i2=2} {i1=2 AND i2=1} {0} +test_expr expr-1.29 {i1=1, i2=2} {i1=1 AND i2=1} {0} +test_expr expr-1.30 {i1=1, i2=2} {i1=2 AND i2=2} {0} +test_expr expr-1.31 {i1=1, i2=2} {i1==1 OR i2=2} {1} +test_expr expr-1.32 {i1=1, i2=2} {i1=2 OR i2=1} {0} +test_expr expr-1.33 {i1=1, i2=2} {i1=1 OR i2=1} {1} +test_expr expr-1.34 {i1=1, i2=2} {i1=2 OR i2=2} {1} +test_expr expr-1.35 {i1=1, i2=2} {i1-i2=-1} {1} +test_expr expr-1.36 {i1=1, i2=0} {not i1} {0} +test_expr expr-1.37 {i1=1, i2=0} {not i2} {1} +test_expr expr-1.38 {i1=1} {-i1} {-1} +test_expr expr-1.39 {i1=1} {+i1} {1} +test_expr expr-1.40 {i1=1, i2=2} {+(i2+i1)} {3} +test_expr expr-1.41 {i1=1, i2=2} {-(i2+i1)} {-3} +test_expr expr-1.42 {i1=1, i2=2} {i1|i2} {3} +test_expr expr-1.42b {i1=1, i2=2} {4|2} {6} +test_expr expr-1.43 {i1=1, i2=2} {i1&i2} {0} +test_expr expr-1.43b {i1=1, i2=2} {4&5} {4} +test_expr expr-1.44 {i1=1} {~i1} {-2} +test_expr expr-1.44b {i1=NULL} {~i1} {{}} +test_expr expr-1.45a {i1=1, i2=3} {i1<>i2} {8} +test_expr expr-1.45c {i1=1, i2=0} {i1<>i2} {0} +test_expr expr-1.46a {i1=32, i2=3} {i1>>i2} {4} +test_expr expr-1.46b {i1=32, i2=6} {i1>>i2} {0} +test_expr expr-1.46c {i1=-32, i2=3} {i1>>i2} {-4} +test_expr expr-1.46d {i1=-32, i2=100} {i1>>i2} {-1} +test_expr expr-1.46e {i1=32, i2=-3} {i1>>i2} {256} +test_expr expr-1.47 {i1=9999999999, i2=8888888888} {i1i2} 1 +test_expr expr-1.50 {i1=99999999999, i2=99999999998} {i1i2} 1 +test_expr expr-1.53 {i1=099999999999, i2=99999999999} {i1i2} 0 +test_expr expr-1.56 {i1=25, i2=11} {i1%i2} 3 +test_expr expr-1.58 {i1=NULL, i2=1} {coalesce(i1+i2,99)} 99 +test_expr expr-1.59 {i1=1, i2=NULL} {coalesce(i1+i2,99)} 99 +test_expr expr-1.60 {i1=NULL, i2=NULL} {coalesce(i1+i2,99)} 99 +test_expr expr-1.61 {i1=NULL, i2=1} {coalesce(i1-i2,99)} 99 +test_expr expr-1.62 {i1=1, i2=NULL} {coalesce(i1-i2,99)} 99 +test_expr expr-1.63 {i1=NULL, i2=NULL} {coalesce(i1-i2,99)} 99 +test_expr expr-1.64 {i1=NULL, i2=1} {coalesce(i1*i2,99)} 99 +test_expr expr-1.65 {i1=1, i2=NULL} {coalesce(i1*i2,99)} 99 +test_expr expr-1.66 {i1=NULL, i2=NULL} {coalesce(i1*i2,99)} 99 +test_expr expr-1.67 {i1=NULL, i2=1} {coalesce(i1/i2,99)} 99 +test_expr expr-1.68 {i1=1, i2=NULL} {coalesce(i1/i2,99)} 99 +test_expr expr-1.69 {i1=NULL, i2=NULL} {coalesce(i1/i2,99)} 99 +test_expr expr-1.70 {i1=NULL, i2=1} {coalesce(i1i2,99)} 99 +test_expr expr-1.72 {i1=NULL, i2=NULL} {coalesce(i1<=i2,99)} 99 +test_expr expr-1.73 {i1=NULL, i2=1} {coalesce(i1>=i2,99)} 99 +test_expr expr-1.74 {i1=1, i2=NULL} {coalesce(i1!=i2,99)} 99 +test_expr expr-1.75 {i1=NULL, i2=NULL} {coalesce(i1==i2,99)} 99 +test_expr expr-1.76 {i1=NULL, i2=NULL} {coalesce(not i1,99)} 99 +test_expr expr-1.77 {i1=NULL, i2=NULL} {coalesce(-i1,99)} 99 +test_expr expr-1.78 {i1=NULL, i2=NULL} {coalesce(i1 IS NULL AND i2=5,99)} 99 +test_expr expr-1.79 {i1=NULL, i2=NULL} {coalesce(i1 IS NULL OR i2=5,99)} 1 +test_expr expr-1.80 {i1=NULL, i2=NULL} {coalesce(i1=5 AND i2 IS NULL,99)} 99 +test_expr expr-1.81 {i1=NULL, i2=NULL} {coalesce(i1=5 OR i2 IS NULL,99)} 1 +test_expr expr-1.82 {i1=NULL, i2=3} {coalesce(min(i1,i2,1),99)} 99 +test_expr expr-1.83 {i1=NULL, i2=3} {coalesce(max(i1,i2,1),99)} 99 +test_expr expr-1.84 {i1=3, i2=NULL} {coalesce(min(i1,i2,1),99)} 99 +test_expr expr-1.85 {i1=3, i2=NULL} {coalesce(max(i1,i2,1),99)} 99 +test_expr expr-1.86 {i1=3, i2=8} {5 between i1 and i2} 1 +test_expr expr-1.87 {i1=3, i2=8} {5 not between i1 and i2} 0 +test_expr expr-1.88 {i1=3, i2=8} {55 between i1 and i2} 0 +test_expr expr-1.89 {i1=3, i2=8} {55 not between i1 and i2} 1 +test_expr expr-1.90 {i1=3, i2=NULL} {5 between i1 and i2} {{}} +test_expr expr-1.91 {i1=3, i2=NULL} {5 not between i1 and i2} {{}} +test_expr expr-1.92 {i1=3, i2=NULL} {2 between i1 and i2} 0 +test_expr expr-1.93 {i1=3, i2=NULL} {2 not between i1 and i2} 1 +test_expr expr-1.94 {i1=NULL, i2=8} {2 between i1 and i2} {{}} +test_expr expr-1.95 {i1=NULL, i2=8} {2 not between i1 and i2} {{}} +test_expr expr-1.94 {i1=NULL, i2=8} {55 between i1 and i2} 0 +test_expr expr-1.95 {i1=NULL, i2=8} {55 not between i1 and i2} 1 +test_expr expr-1.96 {i1=NULL, i2=3} {coalesce(i1<>i2,99)} 99 +test_expr expr-1.98 {i1=NULL, i2=NULL} {coalesce(i1|i2,99)} 99 +test_expr expr-1.99 {i1=32, i2=NULL} {coalesce(i1&i2,99)} 99 +test_expr expr-1.100 {i1=1, i2=''} {i1=i2} 0 +test_expr expr-1.101 {i1=0, i2=''} {i1=i2} 0 + +# Check for proper handling of 64-bit integer values. +# +if {[working_64bit_int]} { + test_expr expr-1.102 {i1=40, i2=1} {i2<1} 1 +} + +if {[working_64bit_int]} { + test_realnum_expr expr-1.106 {i1=0} {-9223372036854775808/-1} 9.22337203685478e+18 +} + +test_expr expr-1.107 {i1=0} {-9223372036854775808%-1} 0 +test_expr expr-1.108 {i1=0} {1%0} {{}} +test_expr expr-1.109 {i1=0} {1/0} {{}} + +if {[working_64bit_int]} { + test_expr expr-1.110 {i1=0} {-9223372036854775807/-1} 9223372036854775807 +} + +test_expr expr-1.111 {i1=NULL, i2=8} {i1 IS i2} 0 +test_expr expr-1.111b {i1=NULL, i2=8} {i1 IS NOT DISTINCT FROM i2} 0 +test_expr expr-1.112 {i1=NULL, i2=NULL} {i1 IS i2} 1 +test_expr expr-1.112b {i1=NULL, i2=NULL} {i1 IS NOT DISTINCT FROM i2} 1 +test_expr expr-1.113 {i1=6, i2=NULL} {i1 IS i2} 0 +test_expr expr-1.113b {i1=6, i2=NULL} {i1 IS NOT DISTINCT FROM i2} 0 +test_expr expr-1.114 {i1=6, i2=6} {i1 IS i2} 1 +test_expr expr-1.114b {i1=6, i2=6} {i1 IS NOT DISTINCT FROM i2} 1 +test_expr expr-1.115 {i1=NULL, i2=8} \ + {CASE WHEN i1 IS i2 THEN 'yes' ELSE 'no' END} no +test_expr expr-1.115b {i1=NULL, i2=8} \ + {CASE WHEN i1 IS NOT DISTINCT FROM i2 THEN 'yes' ELSE 'no' END} no +test_expr expr-1.116 {i1=NULL, i2=NULL} \ + {CASE WHEN i1 IS i2 THEN 'yes' ELSE 'no' END} yes +test_expr expr-1.116b {i1=NULL, i2=NULL} \ + {CASE WHEN i1 IS NOT DISTINCT FROM i2 THEN 'yes' ELSE 'no' END} yes +test_expr expr-1.117 {i1=6, i2=NULL} \ + {CASE WHEN i1 IS i2 THEN 'yes' ELSE 'no' END} no +test_expr expr-1.117b {i1=6, i2=NULL} \ + {CASE WHEN i1 IS NOT DISTINCT FROM i2 THEN 'yes' ELSE 'no' END} no +test_expr expr-1.118 {i1=8, i2=8} \ + {CASE WHEN i1 IS i2 THEN 'yes' ELSE 'no' END} yes +test_expr expr-1.118b {i1=8, i2=8} \ + {CASE WHEN i1 IS NOT DISTINCT FROM i2 THEN 'yes' ELSE 'no' END} yes +test_expr expr-1.119 {i1=NULL, i2=8} {i1 IS NOT i2} 1 +test_expr expr-1.119b {i1=NULL, i2=8} {i1 IS DISTINCT FROM i2} 1 +test_expr expr-1.120 {i1=NULL, i2=NULL} {i1 IS NOT i2} 0 +test_expr expr-1.120b {i1=NULL, i2=NULL} {i1 IS DISTINCT FROM i2} 0 +test_expr expr-1.121 {i1=6, i2=NULL} {i1 IS NOT i2} 1 +test_expr expr-1.121b {i1=6, i2=NULL} {i1 IS DISTINCT FROM i2} 1 +test_expr expr-1.122 {i1=6, i2=6} {i1 IS NOT i2} 0 +test_expr expr-1.122b {i1=6, i2=6} {i1 IS DISTINCT FROM i2} 0 +test_expr expr-1.123 {i1=NULL, i2=8} \ + {CASE WHEN i1 IS NOT i2 THEN 'yes' ELSE 'no' END} yes +test_expr expr-1.123b {i1=NULL, i2=8} \ + {CASE WHEN i1 IS DISTINCT FROM i2 THEN 'yes' ELSE 'no' END} yes +test_expr expr-1.124 {i1=NULL, i2=NULL} \ + {CASE WHEN i1 IS NOT i2 THEN 'yes' ELSE 'no' END} no +test_expr expr-1.124b {i1=NULL, i2=NULL} \ + {CASE WHEN i1 IS DISTINCT FROM i2 THEN 'yes' ELSE 'no' END} no +test_expr expr-1.125 {i1=6, i2=NULL} \ + {CASE WHEN i1 IS NOT i2 THEN 'yes' ELSE 'no' END} yes +test_expr expr-1.125b {i1=6, i2=NULL} \ + {CASE WHEN i1 IS DISTINCT FROM i2 THEN 'yes' ELSE 'no' END} yes +test_expr expr-1.126 {i1=8, i2=8} \ + {CASE WHEN i1 IS NOT i2 THEN 'yes' ELSE 'no' END} no +test_expr expr-1.126b {i1=8, i2=8} \ + {CASE WHEN i1 IS DISTINCT FROM i2 THEN 'yes' ELSE 'no' END} no + +do_catchsql_test expr-1.127 { + SELECT 1 IS #1; +} {1 {near "#1": syntax error}} + +ifcapable floatingpoint {if {[working_64bit_int]} { + test_expr expr-1.200\ + {i1=9223372036854775806, i2=1} {i1+i2} 9223372036854775807 + test_realnum_expr expr-1.201\ + {i1=9223372036854775806, i2=2} {i1+i2} 9.22337203685478e+18 + test_realnum_expr expr-1.202\ + {i1=9223372036854775806, i2=100000} {i1+i2} 9.22337203685488e+18 + test_realnum_expr expr-1.203\ + {i1=9223372036854775807, i2=0} {i1+i2} 9223372036854775807 + test_realnum_expr expr-1.204\ + {i1=9223372036854775807, i2=1} {i1+i2} 9.22337203685478e+18 + test_realnum_expr expr-1.205\ + {i2=9223372036854775806, i1=1} {i1+i2} 9223372036854775807 + test_realnum_expr expr-1.206\ + {i2=9223372036854775806, i1=2} {i1+i2} 9.22337203685478e+18 + test_realnum_expr expr-1.207\ + {i2=9223372036854775806, i1=100000} {i1+i2} 9.22337203685488e+18 + test_realnum_expr expr-1.208\ + {i2=9223372036854775807, i1=0} {i1+i2} 9223372036854775807 + test_realnum_expr expr-1.209\ + {i2=9223372036854775807, i1=1} {i1+i2} 9.22337203685478e+18 + test_realnum_expr expr-1.210\ + {i1=-9223372036854775807, i2=-1} {i1+i2} -9223372036854775808 + test_realnum_expr expr-1.211\ + {i1=-9223372036854775807, i2=-2} {i1+i2} -9.22337203685478e+18 + test_realnum_expr expr-1.212\ + {i1=-9223372036854775807, i2=-100000} {i1+i2} -9.22337203685488e+18 + test_realnum_expr expr-1.213\ + {i1=-9223372036854775808, i2=0} {i1+i2} -9223372036854775808 + test_realnum_expr expr-1.214\ + {i1=-9223372036854775808, i2=-1} {i1+i2} -9.22337203685478e+18 + test_realnum_expr expr-1.215\ + {i2=-9223372036854775807, i1=-1} {i1+i2} -9223372036854775808 + test_realnum_expr expr-1.216\ + {i2=-9223372036854775807, i1=-2} {i1+i2} -9.22337203685478e+18 + test_realnum_expr expr-1.217\ + {i2=-9223372036854775807, i1=-100000} {i1+i2} -9.22337203685488e+18 + test_realnum_expr expr-1.218\ + {i2=-9223372036854775808, i1=0} {i1+i2} -9223372036854775808 + test_realnum_expr expr-1.219\ + {i2=-9223372036854775808, i1=-1} {i1+i2} -9.22337203685478e+18 + test_realnum_expr expr-1.220\ + {i1=9223372036854775806, i2=-1} {i1-i2} 9223372036854775807 + test_realnum_expr expr-1.221\ + {i1=9223372036854775806, i2=-2} {i1-i2} 9.22337203685478e+18 + test_realnum_expr expr-1.222\ + {i1=9223372036854775806, i2=-100000} {i1-i2} 9.22337203685488e+18 + test_realnum_expr expr-1.223\ + {i1=9223372036854775807, i2=0} {i1-i2} 9223372036854775807 + test_realnum_expr expr-1.224\ + {i1=9223372036854775807, i2=-1} {i1-i2} 9.22337203685478e+18 + test_realnum_expr expr-1.225\ + {i2=-9223372036854775806, i1=1} {i1-i2} 9223372036854775807 + test_realnum_expr expr-1.226\ + {i2=-9223372036854775806, i1=2} {i1-i2} 9.22337203685478e+18 + test_realnum_expr expr-1.227\ + {i2=-9223372036854775806, i1=100000} {i1-i2} 9.22337203685488e+18 + test_realnum_expr expr-1.228\ + {i2=-9223372036854775807, i1=0} {i1-i2} 9223372036854775807 + test_realnum_expr expr-1.229\ + {i2=-9223372036854775807, i1=1} {i1-i2} 9.22337203685478e+18 + test_realnum_expr expr-1.230\ + {i1=-9223372036854775807, i2=1} {i1-i2} -9223372036854775808 + test_realnum_expr expr-1.231\ + {i1=-9223372036854775807, i2=2} {i1-i2} -9.22337203685478e+18 + test_realnum_expr expr-1.232\ + {i1=-9223372036854775807, i2=100000} {i1-i2} -9.22337203685488e+18 + test_realnum_expr expr-1.233\ + {i1=-9223372036854775808, i2=0} {i1-i2} -9223372036854775808 + test_realnum_expr expr-1.234\ + {i1=-9223372036854775808, i2=1} {i1-i2} -9.22337203685478e+18 + test_realnum_expr expr-1.235\ + {i2=9223372036854775807, i1=-1} {i1-i2} -9223372036854775808 + test_realnum_expr expr-1.236\ + {i2=9223372036854775807, i1=-2} {i1-i2} -9.22337203685478e+18 + test_realnum_expr expr-1.237\ + {i2=9223372036854775807, i1=-100000} {i1-i2} -9.22337203685488e+18 + test_realnum_expr expr-1.238\ + {i2=9223372036854775807, i1=0} {i1-i2} -9223372036854775807 + test_realnum_expr expr-1.239\ + {i2=9223372036854775807, i1=-1} {i1-i2} -9223372036854775808 + + test_realnum_expr expr-1.250\ + {i1=4294967296, i2=2147483648} {i1*i2} 9.22337203685478e+18 + test_realnum_expr expr-1.251\ + {i1=4294967296, i2=2147483647} {i1*i2} 9223372032559808512 + test_realnum_expr expr-1.252\ + {i1=-4294967296, i2=2147483648} {i1*i2} -9223372036854775808 + test_realnum_expr expr-1.253\ + {i1=-4294967296, i2=2147483647} {i1*i2} -9223372032559808512 + test_realnum_expr expr-1.254\ + {i1=4294967296, i2=-2147483648} {i1*i2} -9223372036854775808 + test_realnum_expr expr-1.255\ + {i1=4294967296, i2=-2147483647} {i1*i2} -9223372032559808512 + test_realnum_expr expr-1.256\ + {i1=-4294967296, i2=-2147483648} {i1*i2} 9.22337203685478e+18 + test_realnum_expr expr-1.257\ + {i1=-4294967296, i2=-2147483647} {i1*i2} 9223372032559808512 + + test_realnum_expr expr-1.260\ + {i1=3037000500, i2=3037000500} {i1*i2} 9.22337203700025e+18 + test_realnum_expr expr-1.261\ + {i1=3037000500, i2=-3037000500} {i1*i2} -9.22337203700025e+18 + test_realnum_expr expr-1.262\ + {i1=-3037000500, i2=3037000500} {i1*i2} -9.22337203700025e+18 + test_realnum_expr expr-1.263\ + {i1=-3037000500, i2=-3037000500} {i1*i2} 9.22337203700025e+18 + + test_realnum_expr expr-1.264\ + {i1=3037000500, i2=3037000499} {i1*i2} 9223372033963249500 + test_realnum_expr expr-1.265\ + {i1=3037000500, i2=-3037000499} {i1*i2} -9223372033963249500 + test_realnum_expr expr-1.266\ + {i1=-3037000500, i2=3037000499} {i1*i2} -9223372033963249500 + test_realnum_expr expr-1.267\ + {i1=-3037000500, i2=-3037000499} {i1*i2} 9223372033963249500 + + test_realnum_expr expr-1.268\ + {i1=3037000499, i2=3037000500} {i1*i2} 9223372033963249500 + test_realnum_expr expr-1.269\ + {i1=3037000499, i2=-3037000500} {i1*i2} -9223372033963249500 + test_realnum_expr expr-1.270\ + {i1=-3037000499, i2=3037000500} {i1*i2} -9223372033963249500 + test_realnum_expr expr-1.271\ + {i1=-3037000499, i2=-3037000500} {i1*i2} 9223372033963249500 + +}} + +ifcapable floatingpoint { + test_expr expr-2.1 {r1=1.23, r2=2.34} {r1+r2} 3.57 + test_expr expr-2.2 {r1=1.23, r2=2.34} {r1-r2} -1.11 + test_expr expr-2.3 {r1=1.23, r2=2.34} {r1*r2} 2.8782 +} +set tcl_precision 15 +ifcapable floatingpoint { + test_expr expr-2.4 {r1=1.23, r2=2.34} {r1/r2} 0.525641025641026 + test_expr expr-2.5 {r1=1.23, r2=2.34} {r2/r1} 1.90243902439024 + test_expr expr-2.6 {r1=1.23, r2=2.34} {r2r1} 1 + test_expr expr-2.9 {r1=1.23, r2=2.34} {r2>=r1} 1 + test_expr expr-2.10 {r1=1.23, r2=2.34} {r2!=r1} 1 + test_expr expr-2.11 {r1=1.23, r2=2.34} {r2=r1} 0 + test_expr expr-2.12 {r1=1.23, r2=2.34} {r2<>r1} 1 + test_expr expr-2.13 {r1=1.23, r2=2.34} {r2==r1} 0 + test_expr expr-2.14 {r1=2.34, r2=2.34} {r2r1} 0 + test_expr expr-2.17 {r1=2.34, r2=2.34} {r2>=r1} 1 + test_expr expr-2.18 {r1=2.34, r2=2.34} {r2!=r1} 0 + test_expr expr-2.19 {r1=2.34, r2=2.34} {r2=r1} 1 + test_expr expr-2.20 {r1=2.34, r2=2.34} {r2<>r1} 0 + test_expr expr-2.21 {r1=2.34, r2=2.34} {r2==r1} 1 + test_expr expr-2.22 {r1=1.23, r2=2.34} {min(r1,r2,r1+r2,r1-r2)} {-1.11} + test_expr expr-2.23 {r1=1.23, r2=2.34} {max(r1,r2,r1+r2,r1-r2)} {3.57} + test_expr expr-2.24 {r1=25.0, r2=11.0} {r1%r2} 3.0 + test_expr expr-2.25 {r1=1.23, r2=NULL} {coalesce(r1+r2,99.0)} 99.0 + test_expr expr-2.26 {r1=1e300, r2=1e300} {coalesce((r1*r2)*0.0,99.0)} 99.0 + test_expr expr-2.26b {r1=1e300, r2=-1e300} {coalesce((r1*r2)*0.0,99.0)} 99.0 + test_expr expr-2.27 {r1=1.1, r2=0.0} {r1/r2} {{}} + test_expr expr-2.28 {r1=1.1, r2=0.0} {r1%r2} {{}} +} + +test_expr expr-3.1 {t1='abc', t2='xyz'} {t1t2} 0 +test_expr expr-3.8 {t1='xyz', t2='abc'} {t1>t2} 1 +test_expr expr-3.9 {t1='abc', t2='abc'} {t1>t2} 0 +test_expr expr-3.10 {t1='abc', t2='xyz'} {t1>=t2} 0 +test_expr expr-3.11 {t1='xyz', t2='abc'} {t1>=t2} 1 +test_expr expr-3.12 {t1='abc', t2='abc'} {t1>=t2} 1 +test_expr expr-3.13 {t1='abc', t2='xyz'} {t1=t2} 0 +test_expr expr-3.14 {t1='xyz', t2='abc'} {t1=t2} 0 +test_expr expr-3.15 {t1='abc', t2='abc'} {t1=t2} 1 +test_expr expr-3.16 {t1='abc', t2='xyz'} {t1==t2} 0 +test_expr expr-3.17 {t1='xyz', t2='abc'} {t1==t2} 0 +test_expr expr-3.18 {t1='abc', t2='abc'} {t1==t2} 1 +test_expr expr-3.19 {t1='abc', t2='xyz'} {t1<>t2} 1 +test_expr expr-3.20 {t1='xyz', t2='abc'} {t1<>t2} 1 +test_expr expr-3.21 {t1='abc', t2='abc'} {t1<>t2} 0 +test_expr expr-3.22 {t1='abc', t2='xyz'} {t1!=t2} 1 +test_expr expr-3.23 {t1='xyz', t2='abc'} {t1!=t2} 1 +test_expr expr-3.24 {t1='abc', t2='abc'} {t1!=t2} 0 +test_expr expr-3.25 {t1=NULL, t2='hi'} {t1 isnull} 1 +test_expr expr-3.25b {t1=NULL, t2='hi'} {t1 is null} 1 +test_expr expr-3.26 {t1=NULL, t2='hi'} {t2 isnull} 0 +test_expr expr-3.27 {t1=NULL, t2='hi'} {t1 notnull} 0 +test_expr expr-3.28 {t1=NULL, t2='hi'} {t2 notnull} 1 +test_expr expr-3.28b {t1=NULL, t2='hi'} {t2 is not null} 1 +test_expr expr-3.29 {t1='xyz', t2='abc'} {t1||t2} {xyzabc} +test_expr expr-3.30 {t1=NULL, t2='abc'} {t1||t2} {{}} +test_expr expr-3.31 {t1='xyz', t2=NULL} {t1||t2} {{}} +test_expr expr-3.32 {t1='xyz', t2='abc'} {t1||' hi '||t2} {{xyz hi abc}} +test_expr epxr-3.33 {t1='abc', t2=NULL} {coalesce(t1t2,99)} 99 +test_expr epxr-3.36 {t1='abc', t2=NULL} {coalesce(t2>t1,99)} 99 +test_expr epxr-3.37 {t1='abc', t2=NULL} {coalesce(t1<=t2,99)} 99 +test_expr epxr-3.38 {t1='abc', t2=NULL} {coalesce(t2<=t1,99)} 99 +test_expr epxr-3.39 {t1='abc', t2=NULL} {coalesce(t1>=t2,99)} 99 +test_expr epxr-3.40 {t1='abc', t2=NULL} {coalesce(t2>=t1,99)} 99 +test_expr epxr-3.41 {t1='abc', t2=NULL} {coalesce(t1==t2,99)} 99 +test_expr epxr-3.42 {t1='abc', t2=NULL} {coalesce(t2==t1,99)} 99 +test_expr epxr-3.43 {t1='abc', t2=NULL} {coalesce(t1!=t2,99)} 99 +test_expr epxr-3.44 {t1='abc', t2=NULL} {coalesce(t2!=t1,99)} 99 + +test_expr expr-4.1 {t1='abc', t2='Abc'} {t1t2} 1 +test_expr expr-4.3 {t1='abc', t2='Bbc'} {t1t2} 1 +test_expr expr-4.5 {t1='0', t2='0.0'} {t1==t2} 0 +test_expr expr-4.6 {t1='0.000', t2='0.0'} {t1==t2} 0 +test_expr expr-4.7 {t1=' 0.000', t2=' 0.0'} {t1==t2} 0 +test_expr expr-4.8 {t1='0.0', t2='abc'} {t1r2} 0 + test_expr expr-4.11 {r1='abc', r2='Abc'} {r1r2} 1 + test_expr expr-4.13 {r1='abc', r2='Bbc'} {r1r2} 1 + test_expr expr-4.15 {r1='0', r2='0.0'} {r1==r2} 1 + test_expr expr-4.16 {r1='0.000', r2='0.0'} {r1==r2} 1 + test_expr expr-4.17 {r1=' 0.000', r2=' 0.0'} {r1==r2} 1 + test_expr expr-4.18 {r1='0.0', r2='abc'} {r1r2} 0 +} + +# CSL is true if LIKE is case sensitive and false if not. +# NCSL is the opposite. Use these variables as the result +# on operations where case makes a difference. +set CSL $sqlite_options(casesensitivelike) +set NCSL [expr {!$CSL}] + +test_expr expr-5.1 {t1='abc', t2='xyz'} {t1 LIKE t2} 0 +test_expr expr-5.2a {t1='abc', t2='abc'} {t1 LIKE t2} 1 +test_expr expr-5.2b {t1='abc', t2='ABC'} {t1 LIKE t2} $NCSL +test_expr expr-5.3a {t1='abc', t2='a_c'} {t1 LIKE t2} 1 +test_expr expr-5.3b {t1='abc', t2='A_C'} {t1 LIKE t2} $NCSL +test_expr expr-5.4 {t1='abc', t2='abc_'} {t1 LIKE t2} 0 +test_expr expr-5.5a {t1='abc', t2='a%c'} {t1 LIKE t2} 1 +test_expr expr-5.5b {t1='abc', t2='A%C'} {t1 LIKE t2} $NCSL +test_expr expr-5.5c {t1='abdc', t2='a%c'} {t1 LIKE t2} 1 +test_expr expr-5.5d {t1='ac', t2='a%c'} {t1 LIKE t2} 1 +test_expr expr-5.5e {t1='ac', t2='A%C'} {t1 LIKE t2} $NCSL +test_expr expr-5.6a {t1='abxyzzyc', t2='a%c'} {t1 LIKE t2} 1 +test_expr expr-5.6b {t1='abxyzzyc', t2='A%C'} {t1 LIKE t2} $NCSL +test_expr expr-5.7a {t1='abxyzzy', t2='a%c'} {t1 LIKE t2} 0 +test_expr expr-5.7b {t1='abxyzzy', t2='A%C'} {t1 LIKE t2} 0 +test_expr expr-5.8a {t1='abxyzzycx', t2='a%c'} {t1 LIKE t2} 0 +test_expr expr-5.8b {t1='abxyzzycy', t2='a%cx'} {t1 LIKE t2} 0 +test_expr expr-5.8c {t1='abxyzzycx', t2='A%C'} {t1 LIKE t2} 0 +test_expr expr-5.8d {t1='abxyzzycy', t2='A%CX'} {t1 LIKE t2} 0 +test_expr expr-5.9a {t1='abc', t2='a%_c'} {t1 LIKE t2} 1 +test_expr expr-5.9b {t1='ac', t2='a%_c'} {t1 LIKE t2} 0 +test_expr expr-5.9c {t1='abc', t2='A%_C'} {t1 LIKE t2} $NCSL +test_expr expr-5.9d {t1='ac', t2='A%_C'} {t1 LIKE t2} 0 +test_expr expr-5.10a {t1='abxyzzyc', t2='a%_c'} {t1 LIKE t2} 1 +test_expr expr-5.10b {t1='abxyzzyc', t2='A%_C'} {t1 LIKE t2} $NCSL +test_expr expr-5.11 {t1='abc', t2='xyz'} {t1 NOT LIKE t2} 1 +test_expr expr-5.12a {t1='abc', t2='abc'} {t1 NOT LIKE t2} 0 +test_expr expr-5.12b {t1='abc', t2='ABC'} {t1 NOT LIKE t2} $CSL +test_expr expr-5.13 {t1='A'} {t1 LIKE 'A%_'} 0 +test_expr expr-5.14 {t1='AB'} {t1 LIKE 'A%b' ESCAPE 'b'} 0 + +# The following tests only work on versions of TCL that support Unicode +# +if {"\u1234"!="u1234"} { + test_expr expr-5.13a "t1='a\u0080c', t2='a_c'" {t1 LIKE t2} 1 + test_expr expr-5.13b "t1='a\u0080c', t2='A_C'" {t1 LIKE t2} $NCSL + test_expr expr-5.14a "t1='a\u07FFc', t2='a_c'" {t1 LIKE t2} 1 + test_expr expr-5.14b "t1='a\u07FFc', t2='A_C'" {t1 LIKE t2} $NCSL + test_expr expr-5.15a "t1='a\u0800c', t2='a_c'" {t1 LIKE t2} 1 + test_expr expr-5.15b "t1='a\u0800c', t2='A_C'" {t1 LIKE t2} $NCSL + test_expr expr-5.16a "t1='a\uFFFFc', t2='a_c'" {t1 LIKE t2} 1 + test_expr expr-5.16b "t1='a\uFFFFc', t2='A_C'" {t1 LIKE t2} $NCSL + test_expr expr-5.17 "t1='a\u0080', t2='A__'" {t1 LIKE t2} 0 + test_expr expr-5.18 "t1='a\u07FF', t2='A__'" {t1 LIKE t2} 0 + test_expr expr-5.19 "t1='a\u0800', t2='A__'" {t1 LIKE t2} 0 + test_expr expr-5.20 "t1='a\uFFFF', t2='A__'" {t1 LIKE t2} 0 + test_expr expr-5.21a "t1='ax\uABCD', t2='a_\uABCD'" {t1 LIKE t2} 1 + test_expr expr-5.21b "t1='ax\uABCD', t2='A_\uABCD'" {t1 LIKE t2} $NCSL + test_expr expr-5.22a "t1='ax\u1234', t2='a%\u1234'" {t1 LIKE t2} 1 + test_expr expr-5.22b "t1='ax\u1234', t2='A%\u1234'" {t1 LIKE t2} $NCSL + test_expr expr-5.23a "t1='ax\uFEDC', t2='a_%'" {t1 LIKE t2} 1 + test_expr expr-5.23b "t1='ax\uFEDC', t2='A_%'" {t1 LIKE t2} $NCSL + test_expr expr-5.24a "t1='ax\uFEDCy\uFEDC', t2='a%\uFEDC'" {t1 LIKE t2} 1 + test_expr expr-5.24b "t1='ax\uFEDCy\uFEDC', t2='A%\uFEDC'" {t1 LIKE t2} $NCSL +} + +test_expr expr-5.54 {t1='abc', t2=NULL} {t1 LIKE t2} {{}} +test_expr expr-5.55 {t1='abc', t2=NULL} {t1 NOT LIKE t2} {{}} +test_expr expr-5.56 {t1='abc', t2=NULL} {t2 LIKE t1} {{}} +test_expr expr-5.57 {t1='abc', t2=NULL} {t2 NOT LIKE t1} {{}} + +# LIKE expressions that use ESCAPE characters. +test_expr expr-5.58a {t1='abc', t2='a_c'} {t1 LIKE t2 ESCAPE '7'} 1 +test_expr expr-5.58b {t1='abc', t2='A_C'} {t1 LIKE t2 ESCAPE '7'} $NCSL +test_expr expr-5.59a {t1='a_c', t2='a7_c'} {t1 LIKE t2 ESCAPE '7'} 1 +test_expr expr-5.59b {t1='a_c', t2='A7_C'} {t1 LIKE t2 ESCAPE '7'} $NCSL +test_expr expr-5.60a {t1='abc', t2='a7_c'} {t1 LIKE t2 ESCAPE '7'} 0 +test_expr expr-5.60b {t1='abc', t2='A7_C'} {t1 LIKE t2 ESCAPE '7'} 0 +test_expr expr-5.61a {t1='a7Xc', t2='a7_c'} {t1 LIKE t2 ESCAPE '7'} 0 +test_expr expr-5.61b {t1='a7Xc', t2='A7_C'} {t1 LIKE t2 ESCAPE '7'} 0 +test_expr expr-5.62a {t1='abcde', t2='a%e'} {t1 LIKE t2 ESCAPE '7'} 1 +test_expr expr-5.62b {t1='abcde', t2='A%E'} {t1 LIKE t2 ESCAPE '7'} $NCSL +test_expr expr-5.63a {t1='abcde', t2='a7%e'} {t1 LIKE t2 ESCAPE '7'} 0 +test_expr expr-5.63b {t1='abcde', t2='A7%E'} {t1 LIKE t2 ESCAPE '7'} 0 +test_expr expr-5.64a {t1='a7cde', t2='a7%e'} {t1 LIKE t2 ESCAPE '7'} 0 +test_expr expr-5.64b {t1='a7cde', t2='A7%E'} {t1 LIKE t2 ESCAPE '7'} 0 +test_expr expr-5.65a {t1='a7cde', t2='a77%e'} {t1 LIKE t2 ESCAPE '7'} 1 +test_expr expr-5.65b {t1='a7cde', t2='A77%E'} {t1 LIKE t2 ESCAPE '7'} $NCSL +test_expr expr-5.66a {t1='abc7', t2='a%77'} {t1 LIKE t2 ESCAPE '7'} 1 +test_expr expr-5.66b {t1='abc7', t2='A%77'} {t1 LIKE t2 ESCAPE '7'} $NCSL +test_expr expr-5.67a {t1='abc_', t2='a%7_'} {t1 LIKE t2 ESCAPE '7'} 1 +test_expr expr-5.67b {t1='abc_', t2='A%7_'} {t1 LIKE t2 ESCAPE '7'} $NCSL +test_expr expr-5.68a {t1='abc7', t2='a%7_'} {t1 LIKE t2 ESCAPE '7'} 0 +test_expr expr-5.68b {t1='abc7', t2='A%7_'} {t1 LIKE t2 ESCAPE '7'} 0 + +# These are the same test as the block above, but using a multi-byte +# character as the escape character. +if {"\u1234"!="u1234"} { + test_expr expr-5.69a "t1='abc', t2='a_c'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 1 + test_expr expr-5.69b "t1='abc', t2='A_C'" \ + "t1 LIKE t2 ESCAPE '\u1234'" $NCSL + test_expr expr-5.70a "t1='a_c', t2='a\u1234_c'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 1 + test_expr expr-5.70b "t1='a_c', t2='A\u1234_C'" \ + "t1 LIKE t2 ESCAPE '\u1234'" $NCSL + test_expr expr-5.71a "t1='abc', t2='a\u1234_c'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 0 + test_expr expr-5.71b "t1='abc', t2='A\u1234_C'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 0 + test_expr expr-5.72a "t1='a\u1234Xc', t2='a\u1234_c'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 0 + test_expr expr-5.72b "t1='a\u1234Xc', t2='A\u1234_C'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 0 + test_expr expr-5.73a "t1='abcde', t2='a%e'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 1 + test_expr expr-5.73b "t1='abcde', t2='A%E'" \ + "t1 LIKE t2 ESCAPE '\u1234'" $NCSL + test_expr expr-5.74a "t1='abcde', t2='a\u1234%e'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 0 + test_expr expr-5.74b "t1='abcde', t2='A\u1234%E'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 0 + test_expr expr-5.75a "t1='a\u1234cde', t2='a\u1234%e'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 0 + test_expr expr-5.75b "t1='a\u1234cde', t2='A\u1234%E'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 0 + test_expr expr-5.76a "t1='a\u1234cde', t2='a\u1234\u1234%e'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 1 + test_expr expr-5.76b "t1='a\u1234cde', t2='A\u1234\u1234%E'" \ + "t1 LIKE t2 ESCAPE '\u1234'" $NCSL + test_expr expr-5.77a "t1='abc\u1234', t2='a%\u1234\u1234'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 1 + test_expr expr-5.77b "t1='abc\u1234', t2='A%\u1234\u1234'" \ + "t1 LIKE t2 ESCAPE '\u1234'" $NCSL + test_expr expr-5.78a "t1='abc_', t2='a%\u1234_'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 1 + test_expr expr-5.78b "t1='abc_', t2='A%\u1234_'" \ + "t1 LIKE t2 ESCAPE '\u1234'" $NCSL + test_expr expr-5.79a "t1='abc\u1234', t2='a%\u1234_'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 0 + test_expr expr-5.79b "t1='abc\u1234', t2='A%\u1234_'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 0 +} + +test_expr expr-6.1 {t1='abc', t2='xyz'} {t1 GLOB t2} 0 +test_expr expr-6.2 {t1='abc', t2='ABC'} {t1 GLOB t2} 0 +test_expr expr-6.3 {t1='abc', t2='A?C'} {t1 GLOB t2} 0 +test_expr expr-6.4 {t1='abc', t2='a?c'} {t1 GLOB t2} 1 +test_expr expr-6.5 {t1='abc', t2='abc?'} {t1 GLOB t2} 0 +test_expr expr-6.6 {t1='abc', t2='A*C'} {t1 GLOB t2} 0 +test_expr expr-6.7 {t1='abc', t2='a*c'} {t1 GLOB t2} 1 +test_expr expr-6.8 {t1='abxyzzyc', t2='a*c'} {t1 GLOB t2} 1 +test_expr expr-6.9 {t1='abxyzzy', t2='a*c'} {t1 GLOB t2} 0 +test_expr expr-6.10 {t1='abxyzzycx', t2='a*c'} {t1 GLOB t2} 0 +test_expr expr-6.11 {t1='abc', t2='xyz'} {t1 NOT GLOB t2} 1 +test_expr expr-6.12 {t1='abc', t2='abc'} {t1 NOT GLOB t2} 0 +test_expr expr-6.13 {t1='abc', t2='a[bx]c'} {t1 GLOB t2} 1 +test_expr expr-6.14 {t1='abc', t2='a[cx]c'} {t1 GLOB t2} 0 +test_expr expr-6.15 {t1='abc', t2='a[a-d]c'} {t1 GLOB t2} 1 +test_expr expr-6.16 {t1='abc', t2='a[^a-d]c'} {t1 GLOB t2} 0 +test_expr expr-6.17 {t1='abc', t2='a[A-Dc]c'} {t1 GLOB t2} 0 +test_expr expr-6.18 {t1='abc', t2='a[^A-Dc]c'} {t1 GLOB t2} 1 +test_expr expr-6.19 {t1='abc', t2='a[]b]c'} {t1 GLOB t2} 1 +test_expr expr-6.20 {t1='abc', t2='a[^]b]c'} {t1 GLOB t2} 0 +test_expr expr-6.21a {t1='abcdefg', t2='a*[de]g'} {t1 GLOB t2} 0 +test_expr expr-6.21b {t1='abcdefg', t2='a*[df]g'} {t1 GLOB t2} 1 +test_expr expr-6.21c {t1='abcdefg', t2='a*[d-h]g'} {t1 GLOB t2} 1 +test_expr expr-6.21d {t1='abcdefg', t2='a*[b-e]g'} {t1 GLOB t2} 0 +test_expr expr-6.22a {t1='abcdefg', t2='a*[^de]g'} {t1 GLOB t2} 1 +test_expr expr-6.22b {t1='abcdefg', t2='a*[^def]g'} {t1 GLOB t2} 0 +test_expr expr-6.23 {t1='abcdefg', t2='a*?g'} {t1 GLOB t2} 1 +test_expr expr-6.24 {t1='ac', t2='a*c'} {t1 GLOB t2} 1 +test_expr expr-6.25 {t1='ac', t2='a*?c'} {t1 GLOB t2} 0 +test_expr expr-6.26 {t1='a*c', t2='a[*]c'} {t1 GLOB t2} 1 +test_expr expr-6.27 {t1='a?c', t2='a[?]c'} {t1 GLOB t2} 1 +test_expr expr-6.28 {t1='a[c', t2='a[[]c'} {t1 GLOB t2} 1 + + +# These tests only work on versions of TCL that support Unicode +# +if {"\u1234"!="u1234"} { + test_expr expr-6.26 "t1='a\u0080c', t2='a?c'" {t1 GLOB t2} 1 + test_expr expr-6.27 "t1='a\u07ffc', t2='a?c'" {t1 GLOB t2} 1 + test_expr expr-6.28 "t1='a\u0800c', t2='a?c'" {t1 GLOB t2} 1 + test_expr expr-6.29 "t1='a\uffffc', t2='a?c'" {t1 GLOB t2} 1 + test_expr expr-6.30 "t1='a\u1234', t2='a?'" {t1 GLOB t2} 1 + test_expr expr-6.31 "t1='a\u1234', t2='a??'" {t1 GLOB t2} 0 + test_expr expr-6.32 "t1='ax\u1234', t2='a?\u1234'" {t1 GLOB t2} 1 + test_expr expr-6.33 "t1='ax\u1234', t2='a*\u1234'" {t1 GLOB t2} 1 + test_expr expr-6.34 "t1='ax\u1234y\u1234', t2='a*\u1234'" {t1 GLOB t2} 1 + test_expr expr-6.35 "t1='a\u1234b', t2='a\[x\u1234y\]b'" {t1 GLOB t2} 1 + test_expr expr-6.36 "t1='a\u1234b', t2='a\[\u1233-\u1235\]b'" {t1 GLOB t2} 1 + test_expr expr-6.37 "t1='a\u1234b', t2='a\[\u1234-\u124f\]b'" {t1 GLOB t2} 1 + test_expr expr-6.38 "t1='a\u1234b', t2='a\[\u1235-\u124f\]b'" {t1 GLOB t2} 0 + test_expr expr-6.39 "t1='a\u1234b', t2='a\[a-\u1235\]b'" {t1 GLOB t2} 1 + test_expr expr-6.40 "t1='a\u1234b', t2='a\[a-\u1234\]b'" {t1 GLOB t2} 1 + test_expr expr-6.41 "t1='a\u1234b', t2='a\[a-\u1233\]b'" {t1 GLOB t2} 0 +} + +test_expr expr-6.51 {t1='ABC', t2='xyz'} {t1 GLOB t2} 0 +test_expr expr-6.52 {t1='ABC', t2='abc'} {t1 GLOB t2} 0 +test_expr expr-6.53 {t1='ABC', t2='a?c'} {t1 GLOB t2} 0 +test_expr expr-6.54 {t1='ABC', t2='A?C'} {t1 GLOB t2} 1 +test_expr expr-6.55 {t1='ABC', t2='abc?'} {t1 GLOB t2} 0 +test_expr expr-6.56 {t1='ABC', t2='a*c'} {t1 GLOB t2} 0 +test_expr expr-6.57 {t1='ABC', t2='A*C'} {t1 GLOB t2} 1 +test_expr expr-6.58 {t1='ABxyzzyC', t2='A*C'} {t1 GLOB t2} 1 +test_expr expr-6.59 {t1='ABxyzzy', t2='A*C'} {t1 GLOB t2} 0 +test_expr expr-6.60 {t1='ABxyzzyCx', t2='A*C'} {t1 GLOB t2} 0 +test_expr expr-6.61 {t1='ABC', t2='xyz'} {t1 NOT GLOB t2} 1 +test_expr expr-6.62 {t1='ABC', t2='ABC'} {t1 NOT GLOB t2} 0 +test_expr expr-6.63 {t1='ABC', t2='A[Bx]C'} {t1 GLOB t2} 1 +test_expr expr-6.64 {t1='ABC', t2='A[Cx]C'} {t1 GLOB t2} 0 +test_expr expr-6.65 {t1='ABC', t2='A[A-D]C'} {t1 GLOB t2} 1 +test_expr expr-6.66 {t1='ABC', t2='A[^A-D]C'} {t1 GLOB t2} 0 +test_expr expr-6.67 {t1='ABC', t2='A[a-dC]C'} {t1 GLOB t2} 0 +test_expr expr-6.68 {t1='ABC', t2='A[^a-dC]C'} {t1 GLOB t2} 1 +test_expr expr-6.69a {t1='ABC', t2='A[]B]C'} {t1 GLOB t2} 1 +test_expr expr-6.69b {t1='A]C', t2='A[]B]C'} {t1 GLOB t2} 1 +test_expr expr-6.70a {t1='ABC', t2='A[^]B]C'} {t1 GLOB t2} 0 +test_expr expr-6.70b {t1='AxC', t2='A[^]B]C'} {t1 GLOB t2} 1 +test_expr expr-6.70c {t1='A]C', t2='A[^]B]C'} {t1 GLOB t2} 0 +test_expr expr-6.71 {t1='ABCDEFG', t2='A*[DE]G'} {t1 GLOB t2} 0 +test_expr expr-6.72 {t1='ABCDEFG', t2='A*[^DE]G'} {t1 GLOB t2} 1 +test_expr expr-6.73 {t1='ABCDEFG', t2='A*?G'} {t1 GLOB t2} 1 +test_expr expr-6.74 {t1='AC', t2='A*C'} {t1 GLOB t2} 1 +test_expr expr-6.75 {t1='AC', t2='A*?C'} {t1 GLOB t2} 0 + +test_expr expr-6.63 {t1=NULL, t2='a*?c'} {t1 GLOB t2} {{}} +test_expr expr-6.64 {t1='ac', t2=NULL} {t1 GLOB t2} {{}} +test_expr expr-6.65 {t1=NULL, t2='a*?c'} {t1 NOT GLOB t2} {{}} +test_expr expr-6.66 {t1='ac', t2=NULL} {t1 NOT GLOB t2} {{}} + +# Check that the affinity of a CAST expression is calculated correctly. +ifcapable cast { + test_expr expr-6.67 {t1='01', t2=1} {t1 = t2} 0 + test_expr expr-6.68 {t1='1', t2=1} {t1 = t2} 1 + test_expr expr-6.69 {t1='01', t2=1} {CAST(t1 AS INTEGER) = t2} 1 +} + +test_expr expr-case.1 {i1=1, i2=2} \ + {CASE WHEN i1 = i2 THEN 'eq' ELSE 'ne' END} ne +test_expr expr-case.2 {i1=2, i2=2} \ + {CASE WHEN i1 = i2 THEN 'eq' ELSE 'ne' END} eq +test_expr expr-case.3 {i1=NULL, i2=2} \ + {CASE WHEN i1 = i2 THEN 'eq' ELSE 'ne' END} ne +test_expr expr-case.4 {i1=2, i2=NULL} \ + {CASE WHEN i1 = i2 THEN 'eq' ELSE 'ne' END} ne +test_expr expr-case.5 {i1=2} \ + {CASE i1 WHEN 1 THEN 'one' WHEN 2 THEN 'two' ELSE 'error' END} two +test_expr expr-case.6 {i1=1} \ + {CASE i1 WHEN 1 THEN 'one' WHEN NULL THEN 'two' ELSE 'error' END} one +test_expr expr-case.7 {i1=2} \ + {CASE i1 WHEN 1 THEN 'one' WHEN NULL THEN 'two' ELSE 'error' END} error +test_expr expr-case.8 {i1=3} \ + {CASE i1 WHEN 1 THEN 'one' WHEN NULL THEN 'two' ELSE 'error' END} error +test_expr expr-case.9 {i1=3} \ + {CASE i1 WHEN 1 THEN 'one' WHEN 2 THEN 'two' ELSE 'error' END} error +test_expr expr-case.10 {i1=3} \ + {CASE i1 WHEN 1 THEN 'one' WHEN 2 THEN 'two' END} {{}} +test_expr expr-case.11 {i1=null} \ + {CASE i1 WHEN 1 THEN 'one' WHEN 2 THEN 'two' ELSE 3 END} 3 +test_expr expr-case.12 {i1=1} \ + {CASE i1 WHEN 1 THEN null WHEN 2 THEN 'two' ELSE 3 END} {{}} +test_expr expr-case.13 {i1=7} \ + { CASE WHEN i1 < 5 THEN 'low' + WHEN i1 < 10 THEN 'medium' + WHEN i1 < 15 THEN 'high' ELSE 'error' END} medium + + +# The sqliteExprIfFalse and sqliteExprIfTrue routines are only +# executed as part of a WHERE clause. Create a table suitable +# for testing these functions. +# +execsql {DROP TABLE test1} +execsql {CREATE TABLE test1(a int, b int);} +for {set i 1} {$i<=20} {incr i} { + execsql "INSERT INTO test1 VALUES($i,[expr {1<<$i}])" +} +execsql "INSERT INTO test1 VALUES(NULL,0)" +do_test expr-7.1 { + execsql {SELECT * FROM test1 ORDER BY a} +} {{} 0 1 2 2 4 3 8 4 16 5 32 6 64 7 128 8 256 9 512 10 1024 11 2048 12 4096 13 8192 14 16384 15 32768 16 65536 17 131072 18 262144 19 524288 20 1048576} + +proc test_expr2 {name expr result} { + do_test $name [format { + execsql {SELECT a FROM test1 WHERE %s ORDER BY a} + } $expr] $result +} + +test_expr2 expr-7.2 {a<10 AND a>8} {9} +test_expr2 expr-7.3 {a<=10 AND a>=8} {8 9 10} +test_expr2 expr-7.4 {a>=8 AND a<=10} {8 9 10} +test_expr2 expr-7.5 {a>=20 OR a<=1} {1 20} +test_expr2 expr-7.6 {b!=4 AND a<=3} {1 3} +test_expr2 expr-7.7 {b==8 OR b==16 OR b==32} {3 4 5} +test_expr2 expr-7.8 {NOT b<>8 OR b==1024} {3 10} +test_expr2 expr-7.9 {b LIKE '10%'} {10 20} +test_expr2 expr-7.10 {b LIKE '_4'} {6} +test_expr2 expr-7.11 {a GLOB '1?'} {10 11 12 13 14 15 16 17 18 19} +test_expr2 expr-7.12 {b GLOB '1*4'} {10 14} +test_expr2 expr-7.13 {b GLOB '*1[456]'} {4} +test_expr2 expr-7.14 {a ISNULL} {{}} +test_expr2 expr-7.15 {a NOTNULL AND a<3} {1 2} +test_expr2 expr-7.16 {a AND a<3} {1 2} +test_expr2 expr-7.17 {NOT a} {} +test_expr2 expr-7.18 {a==11 OR (b>1000 AND b<2000)} {10 11} +test_expr2 expr-7.19 {a<=1 OR a>=20} {1 20} +test_expr2 expr-7.20 {a<1 OR a>20} {} +test_expr2 expr-7.21 {a>19 OR a<1} {20} +test_expr2 expr-7.22 {a!=1 OR a=100} \ + {2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20} +test_expr2 expr-7.23 {(a notnull AND a<4) OR a==8} {1 2 3 8} +test_expr2 expr-7.24 {a LIKE '2_' OR a==8} {8 20} +test_expr2 expr-7.25 {a GLOB '2?' OR a==8} {8 20} +test_expr2 expr-7.26 {a isnull OR a=8} {{} 8} +test_expr2 expr-7.27 {a notnull OR a=8} \ + {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20} +test_expr2 expr-7.28 {a<0 OR b=0} {{}} +test_expr2 expr-7.29 {b=0 OR a<0} {{}} +test_expr2 expr-7.30 {a<0 AND b=0} {} +test_expr2 expr-7.31 {b=0 AND a<0} {} +test_expr2 expr-7.32 {a IS NULL AND (a<0 OR b=0)} {{}} +test_expr2 expr-7.33 {a IS NULL AND (b=0 OR a<0)} {{}} +test_expr2 expr-7.34 {a IS NULL AND (a<0 AND b=0)} {} +test_expr2 expr-7.35 {a IS NULL AND (b=0 AND a<0)} {} +test_expr2 expr-7.32 {(a<0 OR b=0) AND a IS NULL} {{}} +test_expr2 expr-7.33 {(b=0 OR a<0) AND a IS NULL} {{}} +test_expr2 expr-7.34 {(a<0 AND b=0) AND a IS NULL} {} +test_expr2 expr-7.35 {(b=0 AND a<0) AND a IS NULL} {} +test_expr2 expr-7.36 {a<2 OR (a<0 OR b=0)} {{} 1} +test_expr2 expr-7.37 {a<2 OR (b=0 OR a<0)} {{} 1} +test_expr2 expr-7.38 {a<2 OR (a<0 AND b=0)} {1} +test_expr2 expr-7.39 {a<2 OR (b=0 AND a<0)} {1} +ifcapable floatingpoint { + test_expr2 expr-7.40 {((a<2 OR a IS NULL) AND b<3) OR b>1e10} {{} 1} +} +test_expr2 expr-7.41 {a BETWEEN -1 AND 1} {1} +test_expr2 expr-7.42 {a NOT BETWEEN 2 AND 100} {1} +test_expr2 expr-7.43 {(b+1234)||'this is a string that is at least 32 characters long' BETWEEN 1 AND 2} {} +test_expr2 expr-7.44 {123||'xabcdefghijklmnopqrstuvwyxz01234567890'||a BETWEEN '123a' AND '123b'} {} +test_expr2 expr-7.45 {((123||'xabcdefghijklmnopqrstuvwyxz01234567890'||a) BETWEEN '123a' AND '123b')<0} {} +test_expr2 expr-7.46 {((123||'xabcdefghijklmnopqrstuvwyxz01234567890'||a) BETWEEN '123a' AND '123z')>0} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20} + +test_expr2 expr-7.50 {((a between 1 and 2 OR 0) AND 1) OR 0} {1 2} +test_expr2 expr-7.51 {((a not between 3 and 100 OR 0) AND 1) OR 0} {1 2} + +ifcapable subquery { + test_expr2 expr-7.52 {((a in (1,2) OR 0) AND 1) OR 0} {1 2} + test_expr2 expr-7.53 \ + {((a not in (3,4,5,6,7,8,9,10) OR 0) AND a<11) OR 0} {1 2} +} +test_expr2 expr-7.54 {((a>0 OR 0) AND a<3) OR 0} {1 2} +ifcapable subquery { + test_expr2 expr-7.55 {((a in (1,2) OR 0) IS NULL AND 1) OR 0} {{}} + test_expr2 expr-7.56 \ + {((a not in (3,4,5,6,7,8,9,10) IS NULL OR 0) AND 1) OR 0} {{}} +} +test_expr2 expr-7.57 {((a>0 IS NULL OR 0) AND 1) OR 0} {{}} + +test_expr2 expr-7.58 {(a||'')<='1'} {1} + +test_expr2 expr-7.59 {LIKE('10%',b)} {10 20} +test_expr2 expr-7.60 {LIKE('_4',b)} {6} +test_expr2 expr-7.61 {GLOB('1?',a)} {10 11 12 13 14 15 16 17 18 19} +test_expr2 expr-7.62 {GLOB('1*4',b)} {10 14} +test_expr2 expr-7.63 {GLOB('*1[456]',b)} {4} +test_expr2 expr-7.64 {b = abs(-2)} {1} +test_expr2 expr-7.65 {b = abs(+-2)} {1} +test_expr2 expr-7.66 {b = abs(++-2)} {1} +test_expr2 expr-7.67 {b = abs(+-+-2)} {1} +test_expr2 expr-7.68 {b = abs(+-++-2)} {1} +test_expr2 expr-7.69 {b = abs(++++-2)} {1} +test_expr2 expr-7.70 {b = 5 - abs(+3)} {1} +test_expr2 expr-7.71 {b = 5 - abs(-3)} {1} +ifcapable floatingpoint { + test_expr2 expr-7.72 {b = abs(-2.0)} {1} +} +test_expr2 expr-7.73 {b = 6 - abs(-a)} {2} +ifcapable floatingpoint { + test_expr2 expr-7.74 {b = abs(8.0)} {3} +} + +# Test the CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP expressions. +# +ifcapable {floatingpoint} { + set sqlite_current_time 1157124849 + do_test expr-8.1 { + execsql {SELECT CURRENT_TIME} + } {15:34:09} + do_test expr-8.2 { + execsql {SELECT CURRENT_DATE} + } {2006-09-01} + do_test expr-8.3 { + execsql {SELECT CURRENT_TIMESTAMP} + } {{2006-09-01 15:34:09}} +} +ifcapable datetime { + do_test expr-8.4 { + execsql {SELECT CURRENT_TIME==time('now');} + } 1 + do_test expr-8.5 { + execsql {SELECT CURRENT_DATE==date('now');} + } 1 + do_test expr-8.6 { + execsql {SELECT CURRENT_TIMESTAMP==datetime('now');} + } 1 +} +set sqlite_current_time 0 + +ifcapable floatingpoint { + do_test expr-9.1 { + execsql {SELECT round(-('-'||'123'))} + } 123.0 +} + +# Test an error message that can be generated by the LIKE expression +do_test expr-10.1 { + catchsql {SELECT 'abc' LIKE 'abc' ESCAPE ''} +} {1 {ESCAPE expression must be a single character}} +do_test expr-10.2 { + catchsql {SELECT 'abc' LIKE 'abc' ESCAPE 'ab'} +} {1 {ESCAPE expression must be a single character}} + +# If we specify an integer constant that is bigger than the largest +# possible integer, code the integer as a real number. +# +do_test expr-11.1 { + execsql {SELECT typeof(9223372036854775807)} +} {integer} +do_test expr-11.2 { + execsql {SELECT typeof(00000009223372036854775807)} +} {integer} +do_test expr-11.3 { + execsql {SELECT typeof(+9223372036854775807)} +} {integer} +do_test expr-11.4 { + execsql {SELECT typeof(+000000009223372036854775807)} +} {integer} +do_test expr-11.5 { + execsql {SELECT typeof(9223372036854775808)} +} {real} +do_test expr-11.6 { + execsql {SELECT typeof(00000009223372036854775808)} +} {real} +do_test expr-11.7 { + execsql {SELECT typeof(+9223372036854775808)} +} {real} +do_test expr-11.8 { + execsql {SELECT typeof(+0000009223372036854775808)} +} {real} +do_test expr-11.11 { + execsql {SELECT typeof(-9223372036854775808)} +} {integer} +do_test expr-11.12 { + execsql {SELECT typeof(-00000009223372036854775808)} +} {integer} +ifcapable floatingpoint { + do_test expr-11.13 { + execsql {SELECT typeof(-9223372036854775809)} + } {real} + do_test expr-11.14 { + execsql {SELECT typeof(-00000009223372036854775809)} + } {real} +} + +# These two statements used to leak memory (because of missing %destructor +# directives in parse.y). +do_test expr-12.1 { + catchsql { + SELECT (CASE a>4 THEN 1 ELSE 0 END) FROM test1; + } +} {1 {near "THEN": syntax error}} +do_test expr-12.2 { + catchsql { + SELECT (CASE WHEN a>4 THEN 1 ELSE 0) FROM test1; + } +} {1 {near ")": syntax error}} + +ifcapable floatingpoint { + do_realnum_test expr-13.1 { + execsql { + SELECT 12345678901234567890; + } + } {1.23456789012346e+19} +} + +# Implicit String->Integer conversion is used when possible. +# +if {[working_64bit_int]} { + do_test expr-13.2 { + execsql { + SELECT 0+'9223372036854775807' + } + } {9223372036854775807} + do_test expr-13.3 { + execsql { + SELECT '9223372036854775807'+0 + } + } {9223372036854775807} +} + +# If the value is too large, use String->Float conversion. +# +ifcapable floatingpoint { + do_realnum_test expr-13.4 { + execsql { + SELECT 0+'9223372036854775808' + } + } {9.22337203685478e+18} + do_realnum_test expr-13.5 { + execsql { + SELECT '9223372036854775808'+0 + } + } {9.22337203685478e+18} +} + +# Use String->float conversion if the value is explicitly a floating +# point value. +# +do_realnum_test expr-13.6 { + execsql { + SELECT 0+'9223372036854775807.0' + } +} {9.22337203685478e+18} +do_realnum_test expr-13.7 { + execsql { + SELECT '9223372036854775807.0'+0 + } +} {9.22337203685478e+18} + +sqlite3_db_config db SQLITE_DBCONFIG_DQS_DML 1 +do_execsql_test expr-13.8 { + SELECT "" <= ''; +} {1} +do_execsql_test expr-13.9 { + SELECT '' <= ""; +} {1} + +# 2018-02-26. Ticket https://www.sqlite.org/src/tktview/36fae083b450e3af85 +# +do_execsql_test expr-14.1 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(0),(1),(NULL),(0.5),('1x'),('0x'); + SELECT count(*) FROM t1 + WHERE (x OR (8==9)) != (CASE WHEN x THEN 1 ELSE 0 END); +} {0} +do_execsql_test expr-14.2 { + SELECT count(*) FROM t1 + WHERE (x OR (8==9)) != (NOT NOT x); +} {0} +do_execsql_test expr-14.3 { + SELECT sum(NOT x) FROM t1 + WHERE x +} {0} +do_execsql_test expr-14.4 { + SELECT sum(CASE WHEN x THEN 0 ELSE 1 END) FROM t1 + WHERE x +} {0} + + +foreach {tn val} [list 1 NaN 2 -NaN 3 NaN0 4 -NaN0 5 Inf 6 -Inf] { + do_execsql_test expr-15.$tn.1 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(0),(1),(NULL),(0.5),('1x'),('0x'); + } + + do_test expr-15.$tn.2 { + set ::STMT [sqlite3_prepare db "INSERT INTO t1 VALUES(?)" -1 TAIL] + sqlite3_bind_double $::STMT 1 $val + sqlite3_step $::STMT + sqlite3_reset $::STMT + sqlite3_finalize $::STMT + } {SQLITE_OK} + + do_execsql_test expr-15.$tn.3 { + SELECT count(*) FROM t1 + WHERE (x OR (8==9)) != (CASE WHEN x THEN 1 ELSE 0 END); + } {0} + + do_execsql_test expr-15.$tn.4 { + SELECT count(*) FROM t1 + WHERE (x OR (8==9)) != (NOT NOT x); + } {0} + + do_execsql_test expr-15.$tn.5 { + SELECT sum(NOT x) FROM t1 + WHERE x + } {0} + + do_execsql_test expr-15.$tn.6 { + SELECT sum(CASE WHEN x THEN 0 ELSE 1 END) FROM t1 + WHERE x + } {0} +} + +reset_db +sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db +do_execsql_test expr-16.1 { + CREATE TABLE t1(a,b,c); + CREATE TABLE dual(dummy); + INSERT INTO dual VALUES('X'); +} {} +do_execsql_test expr-16.100 { + SELECT implies_nonnull_row( (b=1 AND 0)>(b=3 AND 0),a) + FROM dual LEFT JOIN t1; +} {0} +do_execsql_test expr-16.101 { + SELECT implies_nonnull_row( (b=1 AND 0)>(b=3 AND a=4),a) + FROM dual LEFT JOIN t1; +} {1} +do_execsql_test expr-16.102 { + SELECT implies_nonnull_row( (b=1 AND a=2)>(b=3 AND a=4),a) + FROM dual LEFT JOIN t1; +} {1} + +finish_test diff --git a/test/expr2.test b/test/expr2.test new file mode 100644 index 0000000..3dfbadc --- /dev/null +++ b/test/expr2.test @@ -0,0 +1,54 @@ +# 2019 May 20 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing expressions. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix expr2 + +do_execsql_test 1.0 { + CREATE TABLE t0(c0); + INSERT INTO t0(c0) VALUES ('val'); +} + +do_execsql_test 1.1 { + SELECT * FROM t0 WHERE ( + ( (0 IS NOT FALSE) OR NOT (0 IS FALSE OR (t0.c0 = 1)) ) IS 0 + ) +} {val} + +do_execsql_test 1.2.1 { + SELECT + ( (0 IS NOT FALSE) OR NOT (0 IS FALSE OR (t0.c0 = 1)) ) IS 0 + FROM t0 +} {1} + +do_execsql_test 1.2.2 { + SELECT + ( (0 IS NOT FALSE) OR NOT (0 IS 0 OR (t0.c0 = 1)) ) IS 0 + FROM t0 +} {1} + +do_execsql_test 1.3 { + SELECT ( (0 IS NOT FALSE) OR NOT (0 IS FALSE OR (t0.c0 = 1)) ) FROM t0 +} {0} + +do_execsql_test 1.4.1 { + SELECT (0 IS NOT FALSE) FROM t0 +} {0} +do_execsql_test 1.4.2 { + SELECT NOT (0 IS FALSE OR (t0.c0 = 1)) FROM t0 +} {0} + + +finish_test diff --git a/test/exprfault.test b/test/exprfault.test new file mode 100644 index 0000000..f0abe9a --- /dev/null +++ b/test/exprfault.test @@ -0,0 +1,45 @@ +# 2021 April 17 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix exprfault + +do_execsql_test 1.0 { + CREATE TABLE t1(a); + CREATE TABLE t2(d); +} +faultsim_save_and_close + +do_faultsim_test 1.1 -faults oom* -prep { + faultsim_restore_and_reopen +} -body { + execsql { + SELECT a = ( SELECT d FROM (SELECT d FROM t2) ) FROM t1 + } +} -test { + faultsim_test_result {0 {}} +} + +do_faultsim_test 2 -faults oom* -prep { + faultsim_restore_and_reopen +} -body { + execsql { + SELECT hex ( unhex('ABCDEF') ); + } +} -test { + faultsim_test_result {0 ABCDEF} +} + + +finish_test diff --git a/test/extension01.test b/test/extension01.test new file mode 100644 index 0000000..97b7726 --- /dev/null +++ b/test/extension01.test @@ -0,0 +1,83 @@ +# 2014-06-16 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file implements tests for various small extensions. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix extension01 + +load_static_extension db fileio +do_test 1.0 { + forcedelete file1.txt + set out [open ./file1.txt wb] + puts -nonewline $out "This is a text file without a line ending" + close $out + db eval { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT); + INSERT INTO t1 VALUES(1, readfile('./file1.txt')); + SELECT * FROM t1; + } +} {1 {This is a text file without a line ending}} +do_test 1.1 { + forcedelete file2.txt + db nullvalue nil + db eval { + DELETE FROM t1; + INSERT INTO t1 VALUES(2, readfile(NULL)),(3, readfile('file2.txt')); + SELECT a, b, typeof(b) FROM t1; + } +} {2 nil null 3 nil null} + +do_test 1.2 { + db eval { + SELECT writefile('./file2.txt', 'A second test line'); + } +} {18} +do_test 1.3 { + set in [open ./file2.txt rb] + set x [read $in] + close $in + list $x [file size file2.txt] +} {{A second test line} 18} + +do_test 1.4 { + db eval { + SELECT writefile('./file2.txt', NULL); + } +} {0} +do_test 1.5 { + file size ./file2.txt +} {0} + +do_test 1.6 { + if {$::tcl_platform(platform)=="unix"} { + file attributes ./file2.txt -permissions r--r--r-- + } else { + file attributes ./file2.txt -readonly 1 + } + db eval { + SELECT writefile('./file2.txt', 'Another test'); + } +} {nil} +do_test 1.7 { + if {$::tcl_platform(platform)=="unix"} { + file attributes ./file2.txt -permissions rw-r--r-- + } else { + file attributes ./file2.txt -readonly 0 + } + db eval { + SELECT writefile(NULL, 'Another test'); + } +} {nil} + +finish_test diff --git a/test/external_reader.test b/test/external_reader.test new file mode 100644 index 0000000..5d29398 --- /dev/null +++ b/test/external_reader.test @@ -0,0 +1,74 @@ +# 2021 April 2 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/lock_common.tcl +set testprefix external_reader + +ifcapable !wal { + finish_test + return +} +if {$::tcl_platform(platform)!="unix"} { + finish_test + return +} + +do_multiclient_test tn { + + set bExternal 1 + if {[info commands db3]!=""} { set bExternal 0 } + + do_test 1.$tn.0 { + sql1 { + PRAGMA journal_mode = wal; + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 2); + } + } {wal} + + do_test 1.$tn.1 { + sql2 { SELECT * FROM t1 } + } {1 2} + + do_test 1.$tn.2 { + code1 { + file_control_external_reader db + } + } {0} + + do_test 1.$tn.3 { + sql2 { + BEGIN; + SELECT * FROM t1; + } + } {1 2} + + do_test 1.$tn.4 { + code1 { + file_control_external_reader db + } + } $bExternal + + do_test 1.$tn.5 { + sql2 { COMMIT } + } {} + + do_test 1.$tn.6 { + code1 { file_control_external_reader db } + } 0 + +} + + +finish_test diff --git a/test/extraquick.test b/test/extraquick.test new file mode 100644 index 0000000..f453564 --- /dev/null +++ b/test/extraquick.test @@ -0,0 +1,16 @@ +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file runs most of the tests run by veryquick.test except for those +# that take a long time. +# + +set testdir [file dirname $argv0] +source $testdir/permutations.test + +run_test_suite extraquick + +finish_test diff --git a/test/fallocate.test b/test/fallocate.test new file mode 100644 index 0000000..3e15448 --- /dev/null +++ b/test/fallocate.test @@ -0,0 +1,157 @@ +# 2010 July 28 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +file_control_chunksize_test db main [expr 1024*1024] + +do_test fallocate-1.1 { + execsql { + PRAGMA page_size = 1024; + PRAGMA auto_vacuum = 1; + CREATE TABLE t1(a, b); + } + file size test.db +} [expr 1*1024*1024] + +do_test fallocate-1.2 { + execsql { INSERT INTO t1 VALUES(1, zeroblob(1024*900)) } + file size test.db +} [expr 1*1024*1024] + +do_test fallocate-1.3 { + execsql { INSERT INTO t1 VALUES(2, zeroblob(1024*900)) } + file size test.db +} [expr 2*1024*1024] + +do_test fallocate-1.4 { + execsql { DELETE FROM t1 WHERE a = 1 } + file size test.db +} [expr 1*1024*1024] + +do_test fallocate-1.5 { + execsql { DELETE FROM t1 WHERE a = 2 } + file size test.db +} [expr 1*1024*1024] + +do_test fallocate-1.6 { + execsql { PRAGMA freelist_count } +} {0} + +# Start a write-transaction and read the "database file size" field from +# the journal file. This field should be set to the number of pages in +# the database file based on the size of the file on disk, not the actual +# logical size of the database within the file. +# +# We need to check this to verify that if in the unlikely event a rollback +# causes a database file to grow, the database grows to its previous size +# on disk, not to the minimum size required to hold the database image. +# +do_test fallocate-1.7 { + execsql { BEGIN; INSERT INTO t1 VALUES(1, 2); } + if {[permutation] != "inmemory_journal" + && [permutation] != "atomic-batch-write" + && [atomic_batch_write test.db]==0 + } { + hexio_get_int [hexio_read test.db-journal 16 4] + } else { + set {} 1024 + } +} {1024} +do_test fallocate-1.8 { execsql { COMMIT } } {} + +do_test fallocate-1.8 { + set nPg [db one {PRAGMA page_count}] + set nFile [expr [file size test.db] / 1024] + list [expr $nPg<100] [expr $nFile>100] +} {1 1} + +do_execsql_test fallocate-1.9 { + PRAGMA max_page_count = 100; +} {100} + +#------------------------------------------------------------------------- +# The following tests - fallocate-2.* - test that things work in WAL +# mode as well. +# +set skipwaltests [expr { + [permutation]=="journaltest" || [permutation]=="inmemory_journal" +}] +ifcapable !wal { set skipwaltests 1 } + +if {!$skipwaltests} { + db close + forcedelete test.db + sqlite3 db test.db + file_control_chunksize_test db main [expr 32*1024] + + do_test fallocate-2.1 { + execsql { + PRAGMA page_size = 1024; + PRAGMA journal_mode = WAL; + CREATE TABLE t1(a, b); + } + file size test.db + } [expr 32*1024] + + do_test fallocate-2.2 { + execsql { INSERT INTO t1 VALUES(1, zeroblob(35*1024)) } + execsql { PRAGMA wal_checkpoint } + file size test.db + } [expr 64*1024] + + do_test fallocate-2.3 { + execsql { DELETE FROM t1 } + execsql { VACUUM } + file size test.db + } [expr 64*1024] + + do_test fallocate-2.4 { + execsql { PRAGMA wal_checkpoint } + file size test.db + } [expr 32*1024] + + do_test fallocate-2.5 { + execsql { + INSERT INTO t1 VALUES(2, randomblob(35*1024)); + PRAGMA wal_checkpoint; + INSERT INTO t1 VALUES(3, randomblob(128)); + DELETE FROM t1 WHERE a = 2; + VACUUM; + } + file size test.db + } [expr 64*1024] + + do_test fallocate-2.6 { + sqlite3 db2 test.db + execsql { BEGIN ; SELECT count(a) FROM t1 } db2 + execsql { + INSERT INTO t1 VALUES(4, randomblob(128)); + PRAGMA wal_checkpoint; + } + file size test.db + } [expr 64*1024] + + do_test fallocate-2.7 { + execsql { SELECT count(b) FROM t1 } db2 + } {1} + + do_test fallocate-2.8 { + execsql { COMMIT } db2 + execsql { PRAGMA wal_checkpoint } + file size test.db + } [expr 32*1024] +} + + +finish_test diff --git a/test/filectrl.test b/test/filectrl.test new file mode 100644 index 0000000..460b71e --- /dev/null +++ b/test/filectrl.test @@ -0,0 +1,72 @@ +# 2008 Jan 22 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# $Id: filectrl.test,v 1.2 2008/11/21 00:10:35 aswift Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + + +do_test filectrl-1.1 { + file_control_test db +} {} +do_test filectrl-1.2 { + db eval {CREATE TEMP TABLE x(y);} + file_control_test db +} {} +do_test filectrl-1.3 { + db close + sqlite3 db :memory: + file_control_test db +} {} +do_test filectrl-1.4 { + sqlite3 db test.db + file_control_lasterrno_test db +} {} +do_test filectrl-1.5 { + db close + sqlite3 db test_control_lockproxy.db + file_control_lockproxy_test db [get_pwd] +} {} +do_test filectrl-1.6 { + sqlite3 db test.db + set fn [file_control_tempfilename db] + set fn +} {/etilqs_/} +db close +forcedelete .test_control_lockproxy.db-conch test.proxy +forcedelete test.db test2.db + +if {$tcl_platform(platform)=="windows"} { + do_test filectrl-2.1 { + sqlite3 db test2.db + set size [file size test2.db] + set handle [file_control_win32_get_handle db] + db close + forcedelete test2.db + list $size $handle [expr {$handle != 0}] + } {/^0 \{0 [0-9A-Fa-f]+\} 1$/} + + do_test filectrl-2.2 { + sqlite3 db test2.db + execsql { + CREATE TABLE t1(x); + INSERT INTO t1 (x) VALUES(RANDOMBLOB(1048576)); + } + set size [file size test2.db] + set handle [file_control_win32_get_handle db] + db close + forcedelete test2.db + list $size $handle [expr {$handle != 0}] + } {/^1\d+ \{0 [0-9A-Fa-f]+\} 1$/} +} + +finish_test diff --git a/test/filefmt.test b/test/filefmt.test new file mode 100644 index 0000000..b44ef8e --- /dev/null +++ b/test/filefmt.test @@ -0,0 +1,254 @@ +# 2007 April 6 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests to verify database file format. +# +# $Id: filefmt.test,v 1.3 2009/06/18 11:34:43 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +db close +forcedelete test.db test.db-journal + +# Database begins with valid 16-byte header string. +# +do_test filefmt-1.1 { + sqlite3 db test.db + db eval {CREATE TABLE t1(x)} + db close + hexio_read test.db 0 16 +} {53514C69746520666F726D6174203300} + +# If the 16-byte header is changed, the file will not open +# +do_test filefmt-1.2 { + hexio_write test.db 0 54 + set x [catch {sqlite3 db test.db} err] + lappend x $err +} {0 {}} +do_test filefmt-1.3 { + catchsql { + SELECT count(*) FROM sqlite_master + } +} {1 {file is not a database}} +do_test filefmt-1.4 { + db close + hexio_write test.db 0 53 + sqlite3 db test.db + catchsql { + SELECT count(*) FROM sqlite_master + } +} {0 1} + +# The page-size is stored at offset 16 +# +ifcapable pager_pragmas { + foreach pagesize {512 1024 2048 4096 8192 16384 32768} { + if {[info exists SQLITE_MAX_PAGE_SIZE] + && $pagesize>$SQLITE_MAX_PAGE_SIZE} continue + do_test filefmt-1.5.$pagesize.1 { + db close + forcedelete test.db + sqlite3 db test.db + db eval "PRAGMA auto_vacuum=OFF" + db eval "PRAGMA page_size=$pagesize" + db eval {CREATE TABLE t1(x)} + file size test.db + } [expr $pagesize*2] + do_test filefmt-1.5.$pagesize.2 { + hexio_get_int [hexio_read test.db 16 2] + } $pagesize + } +} + +# The page-size must be a power of 2 +# +do_test filefmt-1.6 { + db close + hexio_write test.db 16 [hexio_render_int16 1025] + sqlite3 db test.db + catchsql { + SELECT count(*) FROM sqlite_master + } +} {1 {file is not a database}} + + +# The page-size must be at least 512 bytes +# +do_test filefmt-1.7 { + db close + hexio_write test.db 16 [hexio_render_int16 256] + sqlite3 db test.db + catchsql { + SELECT count(*) FROM sqlite_master + } +} {1 {file is not a database}} + +# Usable space per page (page-size minus unused space per page) +# must be at least 480 bytes +# +ifcapable pager_pragmas { + do_test filefmt-1.8 { + db close + forcedelete test.db + sqlite3 db test.db + db eval {PRAGMA page_size=512; CREATE TABLE t1(x)} + db close + hexio_write test.db 20 21 + sqlite3 db test.db + catchsql { + SELECT count(*) FROM sqlite_master + } + } {1 {file is not a database}} +} + +#------------------------------------------------------------------------- +# The following block of tests - filefmt-2.* - test that versions 3.7.0 +# and later can read and write databases that have been modified or created +# by 3.6.23.1 and earlier. The difference difference is that 3.7.0 stores +# the size of the database in the database file header, whereas 3.6.23.1 +# always derives this from the size of the file. +# +db close +forcedelete test.db + +set a_string_counter 1 +proc a_string {n} { + incr ::a_string_counter + string range [string repeat "${::a_string_counter}." $n] 1 $n +} +sqlite3 db test.db +db func a_string a_string + +do_execsql_test filefmt-2.1.1 { + PRAGMA page_size = 1024; + PRAGMA auto_vacuum = 0; + CREATE TABLE t1(a); + CREATE INDEX i1 ON t1(a); + INSERT INTO t1 VALUES(a_string(3000)); + CREATE TABLE t2(a); + INSERT INTO t2 VALUES(1); +} {} +if {![nonzero_reserved_bytes]} { + do_test filefmt-2.1.2 { + hexio_read test.db 28 4 + } {00000009} +} + +do_test filefmt-2.1.3 { + sql36231 { INSERT INTO t1 VALUES(a_string(3000)) } +} {} + +do_execsql_test filefmt-2.1.4 { INSERT INTO t2 VALUES(2) } {} +integrity_check filefmt-2.1.5 +do_test filefmt-2.1.6 { hexio_read test.db 28 4 } {00000010} + +db close +forcedelete test.db +sqlite3 db test.db +db func a_string a_string + +do_execsql_test filefmt-2.2.1 { + PRAGMA page_size = 1024; + PRAGMA auto_vacuum = 0; + CREATE TABLE t1(a); + CREATE INDEX i1 ON t1(a); + INSERT INTO t1 VALUES(a_string(3000)); + CREATE TABLE t2(a); + INSERT INTO t2 VALUES(1); +} {} +if {![nonzero_reserved_bytes]} { + do_test filefmt-2.2.2 { + hexio_read test.db 28 4 + } {00000009} +} + +do_test filefmt-2.2.3 { + sql36231 { INSERT INTO t1 VALUES(a_string(3000)) } +} {} + +do_execsql_test filefmt-2.2.4 { + PRAGMA integrity_check; + BEGIN; + INSERT INTO t2 VALUES(2); + SAVEPOINT a; + INSERT INTO t2 VALUES(3); + ROLLBACK TO a; +} {ok} + +integrity_check filefmt-2.2.5 +do_execsql_test filefmt-2.2.6 { COMMIT } {} +db close +sqlite3 db test.db +integrity_check filefmt-2.2.7 + +#-------------------------------------------------------------------------- +# Check that ticket 89b8c9ac54 is fixed. Before the fix, the SELECT +# statement would return SQLITE_CORRUPT. The database file was not actually +# corrupted, but SQLite was reporting that it was. +# +db close +forcedelete test.db +sqlite3 db test.db +do_execsql_test filefmt-3.1 { + PRAGMA auto_vacuum = 1; + CREATE TABLE t1(a, b); +} {} +do_test filefmt-3.2 { + sql36231 { DROP TABLE t1 } +} {} +do_execsql_test filefmt-3.3 { + SELECT * FROM sqlite_master; + PRAGMA integrity_check; +} {ok} + +reset_db +do_execsql_test filefmt-4.1 { + PRAGMA auto_vacuum = 1; + CREATE TABLE t1(x, y); + CREATE TABLE t2(x, y); + + INSERT INTO t1 VALUES(randomblob(100), randomblob(100)); + INSERT INTO t1 VALUES(randomblob(100), randomblob(100)); + INSERT INTO t1 VALUES(randomblob(100), randomblob(100)); + INSERT INTO t1 VALUES(randomblob(100), randomblob(100)); + INSERT INTO t1 VALUES(randomblob(100), randomblob(100)); + INSERT INTO t1 VALUES(randomblob(100), randomblob(100)); + + INSERT INTO t2 SELECT randomblob(100), randomblob(100) FROM t1; + INSERT INTO t2 SELECT randomblob(100), randomblob(100) FROM t1; + INSERT INTO t2 SELECT randomblob(100), randomblob(100) FROM t1; + INSERT INTO t2 SELECT randomblob(100), randomblob(100) FROM t1; +} + +do_test filefmt-4.2 { + sql36231 { INSERT INTO t2 SELECT * FROM t1 } +} {} + +do_test filefmt-4.3 { + forcedelete bak.db + db backup bak.db +} {} + +do_test filefmt-4.4 { + sqlite3 db2 bak.db + db2 eval { PRAGMA integrity_check } +} {ok} +db2 close + +finish_test diff --git a/test/filter1.test b/test/filter1.test new file mode 100644 index 0000000..bb36e17 --- /dev/null +++ b/test/filter1.test @@ -0,0 +1,237 @@ +# 2018 May 8 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix filter1 + +ifcapable !windowfunc { + finish_test + return +} + +do_execsql_test 1.0 { + CREATE TABLE t1(a); + CREATE INDEX i1 ON t1(a); + INSERT INTO t1 VALUES(1), (2), (3), (4), (5), (6), (7), (8), (9); +} + +do_execsql_test 1.1 { SELECT sum(a) FROM t1; } 45 +do_execsql_test 1.2 { SELECT sum(a) FILTER( WHERE a<5 ) FROM t1; } 10 + +do_execsql_test 1.3 { + SELECT sum(a) FILTER( WHERE a>9 ), + sum(a) FILTER( WHERE a>8 ), + sum(a) FILTER( WHERE a>7 ), + sum(a) FILTER( WHERE a>6 ), + sum(a) FILTER( WHERE a>5 ), + sum(a) FILTER( WHERE a>4 ), + sum(a) FILTER( WHERE a>3 ), + sum(a) FILTER( WHERE a>2 ), + sum(a) FILTER( WHERE a>1 ), + sum(a) FILTER( WHERE a>0 ) + FROM t1; +} {{} 9 17 24 30 35 39 42 44 45} + +do_execsql_test 1.4 { + SELECT max(a) FILTER (WHERE (a % 2)==0) FROM t1 +} {8} + +do_execsql_test 1.5 { + SELECT min(a) FILTER (WHERE a>4) FROM t1 +} {5} + +do_execsql_test 1.6 { + SELECT count(*) FILTER (WHERE a!=5) FROM t1 +} {8} + +do_execsql_test 1.7 { + SELECT min(a) FILTER (WHERE a>3) FROM t1 GROUP BY (a%2) ORDER BY 1; +} {4 5} + +do_execsql_test 1.8 { + CREATE VIEW vv AS + SELECT sum(a) FILTER( WHERE a>9 ), + sum(a) FILTER( WHERE a>8 ), + sum(a) FILTER( WHERE a>7 ), + sum(a) FILTER( WHERE a>6 ), + sum(a) FILTER( WHERE a>5 ), + sum(a) FILTER( WHERE a>4 ), + sum(a) FILTER( WHERE a>3 ), + sum(a) FILTER( WHERE a>2 ), + sum(a) FILTER( WHERE a>1 ), + sum(a) FILTER( WHERE a>0 ) + FROM t1; + SELECT * FROM vv; +} {{} 9 17 24 30 35 39 42 44 45} + + +#------------------------------------------------------------------------- +# Test some errors: +# +# .1 FILTER on a non-aggregate function, +# .2 Window function in FILTER clause, +# .3 Aggregate function in FILTER clause, +# +reset_db +do_execsql_test 2.0 { + CREATE TABLE t1(a); + INSERT INTO t1 VALUES(1), (2), (3), (4), (5), (6), (7), (8), (9); +} + +do_catchsql_test 2.1 { + SELECT upper(a) FILTER (WHERE a=1) FROM t1 +} {1 {FILTER may not be used with non-aggregate upper()}} + +do_catchsql_test 2.2 { + SELECT sum(a) FILTER (WHERE 1 - max(a) OVER () > 0) FROM t1 +} {1 {misuse of window function max()}} + +do_catchsql_test 2.3 { + SELECT sum(a) FILTER (WHERE 1 - count(a)) FROM t1 +} {1 {misuse of aggregate function count()}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 3.0 { + CREATE TABLE t1(a,b); + INSERT INTO t1 VALUES(1, 1); +} +do_execsql_test 3.1 { + SELECT b, max(a) FILTER (WHERE b='x') FROM t1; +} {1 {}} + +do_execsql_test 3.2 { + CREATE TABLE t2(a, b, c); + INSERT INTO t2 VALUES(1, 2, 3); + INSERT INTO t2 VALUES(1, 3, 4); + INSERT INTO t2 VALUES(2, 5, 6); + INSERT INTO t2 VALUES(2, 7, 8); +} +do_execsql_test 3.3 { + SELECT a, c, max(b) FILTER (WHERE c='x') FROM t2 GROUP BY a; +} {1 3 {} 2 6 {}} + +do_execsql_test 3.4 { + DELETE FROM t2; + INSERT INTO t2 VALUES(1, 5, 'x'); + INSERT INTO t2 VALUES(1, 2, 3); + INSERT INTO t2 VALUES(1, 4, 'x'); + INSERT INTO t2 VALUES(2, 5, 6); + INSERT INTO t2 VALUES(2, 7, 8); +} +do_execsql_test 3.5 { + SELECT a, c, max(b) FILTER (WHERE c='x') FROM t2 GROUP BY a; +} {1 x 5 2 6 {}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 4.0 { + CREATE TABLE t1(a, b, c); + INSERT INTO t1 VALUES('a', 0, 5); + INSERT INTO t1 VALUES('a', 1, 10); + INSERT INTO t1 VALUES('a', 0, 15); + + INSERT INTO t1 VALUES('b', 0, 5); + INSERT INTO t1 VALUES('b', 1, 1000); + INSERT INTO t1 VALUES('b', 0, 5); + + INSERT INTO t1 VALUES('c', 0, 1); + INSERT INTO t1 VALUES('c', 1, 2); + INSERT INTO t1 VALUES('c', 0, 3); +} + +do_execsql_test 4.1 { + SELECT avg(c) FILTER (WHERE b!=1) AS h FROM t1 GROUP BY a ORDER BY h; +} {2.0 5.0 10.0} +do_execsql_test 4.2 { + SELECT avg(c) FILTER (WHERE b!=1) AS h FROM t1 GROUP BY a ORDER BY (h+1.0); +} {2.0 5.0 10.0} +do_execsql_test 4.3 { + SELECT a, avg(c) FILTER (WHERE b!=1) AS h FROM t1 GROUP BY a ORDER BY avg(c); +} {c 2.0 a 10.0 b 5.0} +do_execsql_test 4.4 { + SELECT a, avg(c) FILTER (WHERE b!=1) FROM t1 GROUP BY a ORDER BY 2 +} {c 2.0 b 5.0 a 10.0} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 5.0 { + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t1 VALUES(1, 3); +} + +do_execsql_test 5.1 { + SELECT count(*) FILTER (WHERE b>2) FROM (SELECT * FROM t1) +} {1} + +do_execsql_test 5.2 { + SELECT count(*) FILTER (WHERE b>2) OVER () FROM (SELECT * FROM t1) +} {1 1} + +do_execsql_test 5.3 { + SELECT count(*) FILTER (WHERE b>2) OVER (ORDER BY b) FROM (SELECT * FROM t1) +} {0 1} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 6.0 { + CREATE TABLE t1(a,b); + INSERT INTO t1 VALUES(1,1); + INSERT INTO t1 VALUES(2,2); + CREATE TABLE t2(x,y); + INSERT INTO t2 VALUES(1,1); +} + +do_execsql_test 6.1 { + SELECT (SELECT COUNT(a) FILTER(WHERE x) FROM t2) FROM t1; +} {1 1} +do_execsql_test 6.2 { + SELECT (SELECT COUNT(a+x) FROM t2) FROM t1; +} {1 1} +do_execsql_test 6.3 { + SELECT (SELECT COUNT(a) FROM t2) FROM t1; +} {2} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 7.0 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + INSERT INTO t1 VALUES(321, 100000); + INSERT INTO t1 VALUES(111, 110000); + INSERT INTO t1 VALUES(444, 120000); + INSERT INTO t1 VALUES(222, 130000); +} + +do_execsql_test 7.1 { + SELECT max(a), max(a) FILTER (WHERE b<12345), b FROM t1; +} { + 444 {} 120000 +} + +# 2023-02-17 dbsqlfuzz 4f8e0de6e272bbbb3e1b41cb5aea31e0b47297e3 +# count() with FILTER clause using the COUNTOFVIEW optimization. +# +reset_db +do_execsql_test 8.0 { + CREATE TABLE t0(c0 INT); + CREATE TABLE t1a(a INTEGER PRIMARY KEY, b TEXT); + INSERT INTO t1a VALUES(1,'one'),(2,NULL),(3,'three'); + CREATE TABLE t1b(c INTEGER PRIMARY KEY, d TEXT); + INSERT INTO t1b VALUES(4,'four'),(5,NULL),(6,'six'); + CREATE VIEW t1 AS SELECT a, b FROM t1a UNION ALL SELECT c, d FROM t1b; + SELECT count()FILTER(WHERE b IS NULL) FROM t1; +} 2 + +finish_test diff --git a/test/filter2.tcl b/test/filter2.tcl new file mode 100644 index 0000000..f3871f8 --- /dev/null +++ b/test/filter2.tcl @@ -0,0 +1,132 @@ +# 2018 May 19 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +source [file join [file dirname $argv0] pg_common.tcl] + +#========================================================================= + + +start_test filter2 "2019 July 2" + +ifcapable !windowfunc + +execsql_test 1.0 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b INTEGER); + INSERT INTO t1 VALUES + (1, 7), (2, 3), (3, 5), (4, 30), (5, 26), (6, 23), (7, 27), + (8, 3), (9, 17), (10, 26), (11, 33), (12, 25), (13, NULL), (14, 47), + (15, 36), (16, 13), (17, 45), (18, 31), (19, 11), (20, 36), (21, 37), + (22, 21), (23, 22), (24, 14), (25, 16), (26, 3), (27, 7), (28, 29), + (29, 50), (30, 38), (31, 3), (32, 36), (33, 12), (34, 4), (35, 46), + (36, 3), (37, 48), (38, 23), (39, NULL), (40, 24), (41, 5), (42, 46), + (43, 11), (44, NULL), (45, 18), (46, 25), (47, 15), (48, 18), (49, 23); +} + +execsql_test 1.1 { SELECT sum(b) FROM t1 } + +execsql_test 1.2 { SELECT sum(b) FILTER (WHERE a<10) FROM t1 } + +execsql_test 1.3 { SELECT count(DISTINCT b) FROM t1 } + +execsql_test 1.4 { SELECT count(DISTINCT b) FILTER (WHERE a!=19) FROM t1 } + +execsql_test 1.5 { + SELECT min(b) FILTER (WHERE a>19), + min(b) FILTER (WHERE a>0), + max(a+b) FILTER (WHERE a>19), + max(b+a) FILTER (WHERE a BETWEEN 10 AND 40) + FROM t1; +} + +execsql_test 1.6 { + SELECT min(b), + min(b), + max(a+b), + max(b+a) + FROM t1 + GROUP BY (a%10) + ORDER BY 1, 2, 3, 4; +} + +execsql_test 1.7 { + SELECT min(b) FILTER (WHERE a>19), + min(b) FILTER (WHERE a>0), + max(a+b) FILTER (WHERE a>19), + max(b+a) FILTER (WHERE a BETWEEN 10 AND 40) + FROM t1 + GROUP BY (a%10) + ORDER BY 1, 2, 3, 4; +} + +execsql_test 1.8 { + SELECT sum(a+b) FILTER (WHERE a=NULL) FROM t1 +} + +execsql_test 1.9 { + SELECT (a%5) FROM t1 GROUP BY (a%5) + HAVING sum(b) FILTER (WHERE b<20) > 34 + ORDER BY 1 +} + +execsql_test 1.10 { + SELECT (a%5), sum(b) FILTER (WHERE b<20) AS bbb + FROM t1 + GROUP BY (a%5) HAVING sum(b) FILTER (WHERE b<20) >34 + ORDER BY 1 +} + +execsql_test 1.11 { + SELECT (a%5), sum(b) FILTER (WHERE b<20) AS bbb + FROM t1 + GROUP BY (a%5) HAVING sum(b) FILTER (WHERE b<20) >34 + ORDER BY 2 +} + +execsql_test 1.12 { + SELECT (a%5), + sum(b) FILTER (WHERE b<20) AS bbb, + count(distinct b) FILTER (WHERE b<20 OR a=13) AS ccc + FROM t1 GROUP BY (a%5) + ORDER BY 2 +} + +execsql_test 1.13 { + SELECT + string_agg(CAST(b AS TEXT), '_') FILTER (WHERE b%2!=0), + string_agg(CAST(b AS TEXT), '_') FILTER (WHERE b%2!=1), + count(*) FILTER (WHERE b%2!=0), + count(*) FILTER (WHERE b%2!=1) + FROM t1; +} + +execsql_float_test 1.14 { + SELECT + avg(b) FILTER (WHERE b>a), + avg(b) FILTER (WHERE b19), + min(b) FILTER (WHERE a>0), + max(a+b) FILTER (WHERE a>19), + max(b+a) FILTER (WHERE a BETWEEN 10 AND 40) + FROM t1; +} {3 3 88 85} + +do_execsql_test 1.6 { + SELECT min(b), + min(b), + max(a+b), + max(b+a) + FROM t1 + GROUP BY (a%10) + ORDER BY 1, 2, 3, 4; +} {3 3 58 58 3 3 66 66 3 3 71 71 3 3 88 88 4 4 61 61 5 5 54 54 + 7 7 85 85 11 11 79 79 16 16 81 81 24 24 68 68} + +do_execsql_test 1.7 { + SELECT min(b) FILTER (WHERE a>19), + min(b) FILTER (WHERE a>0), + max(a+b) FILTER (WHERE a>19), + max(b+a) FILTER (WHERE a BETWEEN 10 AND 40) + FROM t1 + GROUP BY (a%10) + ORDER BY 1, 2, 3, 4; +} {3 3 58 58 3 3 71 39 4 4 38 61 7 7 85 85 11 5 54 45 16 16 81 81 + 18 3 66 61 21 3 88 68 23 11 79 79 24 24 68 68} + +do_execsql_test 1.8 { + SELECT sum(a+b) FILTER (WHERE a=NULL) FROM t1 +} {{}} + +do_execsql_test 1.9 { + SELECT (a%5) FROM t1 GROUP BY (a%5) + HAVING sum(b) FILTER (WHERE b<20) > 34 + ORDER BY 1 +} {3 4} + +do_execsql_test 1.10 { + SELECT (a%5), sum(b) FILTER (WHERE b<20) AS bbb + FROM t1 + GROUP BY (a%5) HAVING sum(b) FILTER (WHERE b<20) >34 + ORDER BY 1 +} {3 49 4 46} + +do_execsql_test 1.11 { + SELECT (a%5), sum(b) FILTER (WHERE b<20) AS bbb + FROM t1 + GROUP BY (a%5) HAVING sum(b) FILTER (WHERE b<20) >34 + ORDER BY 2 +} {4 46 3 49} + +do_execsql_test 1.12 { + SELECT (a%5), + sum(b) FILTER (WHERE b<20) AS bbb, + count(distinct b) FILTER (WHERE b<20 OR a=13) AS ccc + FROM t1 GROUP BY (a%5) + ORDER BY 2 +} {2 25 3 0 34 2 1 34 4 4 46 4 3 49 5} + +do_execsql_test 1.13 { + SELECT + string_agg(CAST(b AS TEXT), '_') FILTER (WHERE b%2!=0), + group_concat(CAST(b AS TEXT), '_') FILTER (WHERE b%2!=1), + count(*) FILTER (WHERE b%2!=0), + count(*) FILTER (WHERE b%2!=1) + FROM t1; +} {7_3_5_23_27_3_17_33_25_47_13_45_31_11_37_21_3_7_29_3_3_23_5_11_25_15_23 30_26_26_36_36_22_14_16_50_38_36_12_4_46_48_24_46_18_18 27 19} + + +do_test 1.14 { + set myres {} + foreach r [db eval {SELECT + avg(b) FILTER (WHERE b>a), + avg(b) FILTER (WHERE b([set r2]+0.0001)} { + error "list element [set i] does not match: got=[set r] expected=[set r2]" + } + incr i + } + set {} {} +} {} + +do_execsql_test 1.15 { + SELECT + a/5, + sum(b) FILTER (WHERE a%5=0), + sum(b) FILTER (WHERE a%5=1), + sum(b) FILTER (WHERE a%5=2), + sum(b) FILTER (WHERE a%5=3), + sum(b) FILTER (WHERE a%5=4) + FROM t1 GROUP BY (a/5) ORDER BY 1; +} {0 {} 7 3 5 30 1 26 23 27 3 17 2 26 33 25 {} 47 3 36 13 45 31 11 + 4 36 37 21 22 14 5 16 3 7 29 50 6 38 3 36 12 4 7 46 3 48 23 {} + 8 24 5 46 11 {} 9 18 25 15 18 23} + +finish_test diff --git a/test/filterfault.test b/test/filterfault.test new file mode 100644 index 0000000..a8cde1f --- /dev/null +++ b/test/filterfault.test @@ -0,0 +1,44 @@ +# 2018 May 8 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix filterfault + +ifcapable !windowfunc { + finish_test + return +} + +do_execsql_test 1.0 { + CREATE TABLE t1(a, b, c, d); + INSERT INTO t1 VALUES(1, 2, 3, 4); + INSERT INTO t1 VALUES(5, 6, 7, 8); + INSERT INTO t1 VALUES(9, 10, 11, 12); +} +faultsim_save_and_close + +do_faultsim_test 1 -faults oom-t* -prep { + faultsim_restore_and_reopen +} -body { + execsql { + SELECT sum(a) FILTER (WHERE b<5), + count() FILTER (WHERE d!=c) + FROM t1 GROUP BY c ORDER BY 1; + } +} -test { + faultsim_test_result {0 {{} 1 {} 1 1 1}} +} + + +finish_test diff --git a/test/fkey1.test b/test/fkey1.test new file mode 100644 index 0000000..46e7f64 --- /dev/null +++ b/test/fkey1.test @@ -0,0 +1,286 @@ +# 2001 September 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests for foreign keys. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fkey1 + +ifcapable {!foreignkey} { + finish_test + return +} + +# Create a table and some data to work with. +# +do_test fkey1-1.0 { + execsql { + CREATE TABLE t1( + a INTEGER PRIMARY KEY, + b INTEGER + REFERENCES t1 ON DELETE CASCADE + REFERENCES t2, + c TEXT, + FOREIGN KEY (b,c) REFERENCES t2(x,y) ON UPDATE CASCADE + ); + } +} {} +do_test fkey1-1.1 { + execsql { + CREATE TABLE t2( + x INTEGER PRIMARY KEY, + y TEXT + ); + } +} {} +do_test fkey1-1.2 { + execsql { + CREATE TABLE t3( + a INTEGER REFERENCES t2, + b INTEGER REFERENCES t1, + FOREIGN KEY (a,b) REFERENCES t2(x,y) + ); + } +} {} + +do_test fkey1-2.1 { + execsql { + CREATE TABLE t4(a integer primary key); + CREATE TABLE t5(x references t4); + CREATE TABLE t6(x references t4); + CREATE TABLE t7(x references t4); + CREATE TABLE t8(x references t4); + CREATE TABLE t9(x references t4); + CREATE TABLE t10(x references t4); + DROP TABLE t7; + DROP TABLE t9; + DROP TABLE t5; + DROP TABLE t8; + DROP TABLE t6; + DROP TABLE t10; + } +} {} + +do_test fkey1-3.1 { + execsql { + CREATE TABLE t5(a PRIMARY KEY, b, c); + CREATE TABLE t6( + d REFERENCES t5, + e REFERENCES t5(c) + ); + PRAGMA foreign_key_list(t6); + } +} [concat \ + {0 0 t5 e c {NO ACTION} {NO ACTION} NONE} \ + {1 0 t5 d {} {NO ACTION} {NO ACTION} NONE} \ +] +do_test fkey1-3.2 { + execsql { + CREATE TABLE t7(d, e, f, + FOREIGN KEY (d, e) REFERENCES t5(a, b) + ); + PRAGMA foreign_key_list(t7); + } +} [concat \ + {0 0 t5 d a {NO ACTION} {NO ACTION} NONE} \ + {0 1 t5 e b {NO ACTION} {NO ACTION} NONE} \ +] +do_test fkey1-3.3 { + execsql { + CREATE TABLE t8(d, e, f, + FOREIGN KEY (d, e) REFERENCES t5 ON DELETE CASCADE ON UPDATE SET NULL + ); + PRAGMA foreign_key_list(t8); + } +} [concat \ + {0 0 t5 d {} {SET NULL} CASCADE NONE} \ + {0 1 t5 e {} {SET NULL} CASCADE NONE} \ +] +do_test fkey1-3.4 { + execsql { + CREATE TABLE t9(d, e, f, + FOREIGN KEY (d, e) REFERENCES t5 ON DELETE CASCADE ON UPDATE SET DEFAULT + ); + PRAGMA foreign_key_list(t9); + } +} [concat \ + {0 0 t5 d {} {SET DEFAULT} CASCADE NONE} \ + {0 1 t5 e {} {SET DEFAULT} CASCADE NONE} \ +] +do_test fkey1-3.5 { + sqlite3_db_status db DBSTATUS_DEFERRED_FKS 0 +} {0 0 0} + +# Stress the dequoting logic. The first test is not so bad. +do_execsql_test fkey1-4.0 { + PRAGMA foreign_keys=ON; + CREATE TABLE "xx1"("xx2" TEXT PRIMARY KEY, "xx3" TEXT); + INSERT INTO "xx1"("xx2","xx3") VALUES('abc','def'); + CREATE TABLE "xx4"("xx5" TEXT REFERENCES "xx1" ON DELETE CASCADE); + INSERT INTO "xx4"("xx5") VALUES('abc'); + INSERT INTO "xx1"("xx2","xx3") VALUES('uvw','xyz'); + SELECT 1, "xx5" FROM "xx4"; + DELETE FROM "xx1"; + SELECT 2, "xx5" FROM "xx4"; +} {1 abc} + +# This case is identical to the previous except the "xx" in each name +# is changed to a single escaped double-quote character. +do_execsql_test fkey1-4.1 { + PRAGMA foreign_keys=ON; + CREATE TABLE """1"("""2" TEXT PRIMARY KEY, """3" TEXT); + INSERT INTO """1"("""2","""3") VALUES('abc','def'); + CREATE TABLE """4"("""5" TEXT REFERENCES """1" ON DELETE CASCADE); + INSERT INTO """4"("""5") VALUES('abc'); + INSERT INTO """1"("""2","""3") VALUES('uvw','xyz'); + SELECT 1, """5" FROM """4"; + DELETE FROM """1"; + SELECT 2, """5" FROM """4"; +} {1 abc} +do_execsql_test fkey1-4.2 { + PRAGMA table_info="""1"; +} {0 {"2} TEXT 0 {} 1 1 {"3} TEXT 0 {} 0} + +#------------------------------------------------------------------------- +# +do_execsql_test fkey1-5.1 { + CREATE TABLE t11( + x INTEGER PRIMARY KEY, + parent REFERENCES t11 ON DELETE CASCADE + ); + INSERT INTO t11 VALUES (1, NULL), (2, 1), (3, 2); +} {} + +# The REPLACE part of this statement deletes the row (2, 1). Then the +# DELETE CASCADE caused by deleting that row removes the (3, 2) row. Which +# would have been the parent of the new row being inserted. Causing an +# FK violation. +# +do_catchsql_test fkey1-5.2 { + INSERT OR REPLACE INTO t11 VALUES (2, 3); +} {1 {FOREIGN KEY constraint failed}} + +# Make sure sqlite3_trace() output works with triggers used to implement +# FK constraints +# +ifcapable trace { + proc sqltrace {txt} { + global traceoutput + lappend traceoutput $txt + } + do_test fkey1-5.2.1 { + unset -nocomplain traceoutput + db trace sqltrace + catch {db eval {INSERT OR REPLACE INTO t11 VALUES(2,3);}} + set traceoutput + } {{INSERT OR REPLACE INTO t11 VALUES(2,3);} {INSERT OR REPLACE INTO t11 VALUES(2,3);} {INSERT OR REPLACE INTO t11 VALUES(2,3);}} +} + +# A similar test to the above. +do_execsql_test fkey1-5.3 { + CREATE TABLE Foo ( + Id INTEGER PRIMARY KEY, + ParentId INTEGER REFERENCES Foo(Id) ON DELETE CASCADE, C1 + ); + INSERT OR REPLACE INTO Foo(Id, ParentId, C1) VALUES (1, null, 'A'); + INSERT OR REPLACE INTO Foo(Id, ParentId, C1) VALUES (2, 1, 'A-2-1'); + INSERT OR REPLACE INTO Foo(Id, ParentId, C1) VALUES (3, 2, 'A-3-2'); + INSERT OR REPLACE INTO Foo(Id, ParentId, C1) VALUES (4, 3, 'A-4-3'); +} +do_catchsql_test fkey1-5.4 { + INSERT OR REPLACE INTO Foo(Id, ParentId, C1) VALUES (2, 3, 'A-2-3'); +} {1 {FOREIGN KEY constraint failed}} + +#------------------------------------------------------------------------- +# Check that foreign key processing is not fooled by partial indexes +# on the parent table. +# +do_execsql_test 6.0 { + CREATE TABLE p1(x, y); + CREATE UNIQUE INDEX p1x ON p1(x) WHERE y<2; + INSERT INTO p1 VALUES(1, 1); + CREATE TABLE c1(a REFERENCES p1(x)); +} + +do_catchsql_test 6.1 { + INSERT INTO c1 VALUES(1); +} {1 {foreign key mismatch - "c1" referencing "p1"}} + +do_execsql_test 6.2 { + CREATE UNIQUE INDEX p1x2 ON p1(x); + INSERT INTO c1 VALUES(1); +} {} + +# 2021-07-03 https://sqlite.org/forum/forumpost/a6b0c05277 +# 2021-07-07 https://sqlite.org/forum/forumpost/79c9e4797d +# Failure to allocate enough registers in the VDBE for a +# PRAGMA foreign_key_check when the foreign key has more +# columns than the table. +# +reset_db +do_execsql_test 7.1 { + PRAGMA foreign_keys=OFF; + CREATE TABLE t1(a,b,c,FOREIGN KEY(a,a,a,a,a,a,a,a,a,a,a,a,a,a) REFERENCES t0); + INSERT INTO t1 VALUES(1,2,3); + PRAGMA foreign_key_check; +} {t1 1 t0 0} +do_execsql_test 7.2 { + DROP TABLE t1; + CREATE TABLE t1(a,b,c AS(1),d, FOREIGN KEY(c,d,b,a,b,d,b,c) REFERENCES t0); + PRAGMA foreign_key_check; +} {} + +# 2021-12-31 forum https://sqlite.org/forum/forumpost/24bd1fef7e9323ef +# Memory leak caused by sqlite3NestedParse() running on a corrupt system +# table. Discovered by Jingzhou Fu. +# +reset_db +do_execsql_test 8.1 { + PRAGMA writable_schema=ON; + PRAGMA foreign_keys = ON; + CREATE TABLE sqlite_stat1 (tbl INTEGER PRIMARY KEY DESC, idx UNIQUE DEFAULT NULL) WITHOUT ROWID; + PRAGMA writable_schema=OFF; + CREATE TABLE sqlsim4(stat PRIMARY KEY);; + CREATE TABLE t1(sqlsim7 REFERENCES sqlite_stat1 ON DELETE CASCADE); + DROP table "sqlsim4"; +} {} +# 2022-01-01 dbsqlfuzz 1c57440219f6f0aedf5e8f72a8ddd75f15aea381 +# Follow-up case to the above. Assertion is not true if the schema +# is corrupt. +reset_db +database_may_be_corrupt +do_execsql_test 8.2 { + CREATE TABLE t1(a REFERENCES sqlite_stat1 ON DELETE CASCADE); + CREATE TABLE t2(a TEXT PRIMARY KEY); + PRAGMA writable_schema=ON; + CREATE TABLE sqlite_stat1(tbl INTEGER PRIMARY KEY DESC, idx UNIQUE DEFAULT NULL) WITHOUT ROWID; + UPDATE sqlite_schema SET name='sqlite_autoindex_sqlite_stat1_1' WHERE name='sqlite_autoindex_sqlite_stat1_2'; + PRAGMA writable_schema=RESET; +} {} +do_catchsql_test 8.3 { + REINDEX; +} {1 {database disk image is malformed}} + +# 2023-04-13 https://bugs.chromium.org/p/chromium/issues/detail?id=1405220 +# Avoid double-de-quoting of table names when processing foreign keys. +# +reset_db +do_execsql_test 9.1 { + PRAGMA foreign_keys = ON; + CREATE TABLE """1"("""2", """3" PRIMARY KEY); + CREATE TABLE """4"("""5" REFERENCES """1" ON DELETE RESTRICT); + DELETE FROM """1"; +} + +finish_test diff --git a/test/fkey2.test b/test/fkey2.test new file mode 100644 index 0000000..6f9bdc2 --- /dev/null +++ b/test/fkey2.test @@ -0,0 +1,2047 @@ +# 2009 September 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests for foreign keys. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable {!foreignkey||!trigger} { + finish_test + return +} + +#------------------------------------------------------------------------- +# Test structure: +# +# fkey2-1.*: Simple tests to check that immediate and deferred foreign key +# constraints work when not inside a transaction. +# +# fkey2-2.*: Tests to verify that deferred foreign keys work inside +# explicit transactions (i.e that processing really is deferred). +# +# fkey2-3.*: Tests that a statement transaction is rolled back if an +# immediate foreign key constraint is violated. +# +# fkey2-4.*: Test that FK actions may recurse even when recursive triggers +# are disabled. +# +# fkey2-5.*: Check that if foreign-keys are enabled, it is not possible +# to write to an FK column using the incremental blob API. +# +# fkey2-6.*: Test that FK processing is automatically disabled when +# running VACUUM. +# +# fkey2-7.*: Test using an IPK as the key in the child (referencing) table. +# +# fkey2-8.*: Test that enabling/disabling foreign key support while a +# transaction is active is not possible. +# +# fkey2-9.*: Test SET DEFAULT actions. +# +# fkey2-10.*: Test errors. +# +# fkey2-11.*: Test CASCADE actions. +# +# fkey2-12.*: Test RESTRICT actions. +# +# fkey2-13.*: Test that FK processing is performed when a row is REPLACED by +# an UPDATE or INSERT statement. +# +# fkey2-14.*: Test the ALTER TABLE and DROP TABLE commands. +# +# fkey2-15.*: Test that if there are no (known) outstanding foreign key +# constraint violations in the database, inserting into a parent +# table or deleting from a child table does not cause SQLite +# to check if this has repaired an outstanding violation. +# +# fkey2-16.*: Test that rows that refer to themselves may be inserted, +# updated and deleted. +# +# fkey2-17.*: Test that the "count_changes" pragma does not interfere with +# FK constraint processing. +# +# fkey2-18.*: Test that the authorization callback is invoked when processing +# FK constraints. +# +# fkey2-20.*: Test that ON CONFLICT clauses specified as part of statements +# do not affect the operation of FK constraints. +# +# fkey2-genfkey.*: Tests that were used with the shell tool .genfkey +# command. Recycled to test the built-in implementation. +# +# fkey2-dd08e5.*: Tests to verify that ticket dd08e5a988d00decc4a543daa8d +# has been fixed. +# + + +execsql { PRAGMA foreign_keys = on } + +set FkeySimpleSchema { + PRAGMA foreign_keys = on; + CREATE TABLE t1(a PRIMARY KEY, b); + CREATE TABLE t2(c REFERENCES t1(a) /D/ , d); + + CREATE TABLE t3(a PRIMARY KEY, b); + CREATE TABLE t4(c REFERENCES t3 /D/, d); + + CREATE TABLE t7(a, b INTEGER PRIMARY KEY); + CREATE TABLE t8(c REFERENCES t7 /D/, d); + + CREATE TABLE t9(a REFERENCES nosuchtable, b); + CREATE TABLE t10(a REFERENCES t9(c) /D/, b); +} + + +set FkeySimpleTests { + 1.1 "INSERT INTO t2 VALUES(1, 3)" {1 {FOREIGN KEY constraint failed}} + 1.2 "INSERT INTO t1 VALUES(1, 2)" {0 {}} + 1.3 "INSERT INTO t2 VALUES(1, 3)" {0 {}} + 1.4 "INSERT INTO t2 VALUES(2, 4)" {1 {FOREIGN KEY constraint failed}} + 1.5 "INSERT INTO t2 VALUES(NULL, 4)" {0 {}} + 1.6 "UPDATE t2 SET c=2 WHERE d=4" {1 {FOREIGN KEY constraint failed}} + 1.7 "UPDATE t2 SET c=1 WHERE d=4" {0 {}} + 1.9 "UPDATE t2 SET c=1 WHERE d=4" {0 {}} + 1.10 "UPDATE t2 SET c=NULL WHERE d=4" {0 {}} + 1.11 "DELETE FROM t1 WHERE a=1" {1 {FOREIGN KEY constraint failed}} + 1.12 "UPDATE t1 SET a = 2" {1 {FOREIGN KEY constraint failed}} + 1.13 "UPDATE t1 SET a = 1" {0 {}} + + 2.1 "INSERT INTO t4 VALUES(1, 3)" {1 {FOREIGN KEY constraint failed}} + 2.2 "INSERT INTO t3 VALUES(1, 2)" {0 {}} + 2.3 "INSERT INTO t4 VALUES(1, 3)" {0 {}} + + 4.1 "INSERT INTO t8 VALUES(1, 3)" {1 {FOREIGN KEY constraint failed}} + 4.2 "INSERT INTO t7 VALUES(2, 1)" {0 {}} + 4.3 "INSERT INTO t8 VALUES(1, 3)" {0 {}} + 4.4 "INSERT INTO t8 VALUES(2, 4)" {1 {FOREIGN KEY constraint failed}} + 4.5 "INSERT INTO t8 VALUES(NULL, 4)" {0 {}} + 4.6 "UPDATE t8 SET c=2 WHERE d=4" {1 {FOREIGN KEY constraint failed}} + 4.7 "UPDATE t8 SET c=1 WHERE d=4" {0 {}} + 4.9 "UPDATE t8 SET c=1 WHERE d=4" {0 {}} + 4.10 "UPDATE t8 SET c=NULL WHERE d=4" {0 {}} + 4.11 "DELETE FROM t7 WHERE b=1" {1 {FOREIGN KEY constraint failed}} + 4.12 "UPDATE t7 SET b = 2" {1 {FOREIGN KEY constraint failed}} + 4.13 "UPDATE t7 SET b = 1" {0 {}} + 4.14 "INSERT INTO t8 VALUES('a', 'b')" {1 {FOREIGN KEY constraint failed}} + 4.15 "UPDATE t7 SET b = 5" {1 {FOREIGN KEY constraint failed}} + 4.16 "UPDATE t7 SET rowid = 5" {1 {FOREIGN KEY constraint failed}} + 4.17 "UPDATE t7 SET a = 10" {0 {}} + + 5.1 "INSERT INTO t9 VALUES(1, 3)" {1 {no such table: main.nosuchtable}} + 5.2 "INSERT INTO t10 VALUES(1, 3)" + {1 {foreign key mismatch - "t10" referencing "t9"}} +} + +do_test fkey2-1.1.0 { + execsql [string map {/D/ {}} $FkeySimpleSchema] +} {} +foreach {tn zSql res} $FkeySimpleTests { + do_test fkey2-1.1.$tn.1 { catchsql $zSql } $res + do_test fkey2-1.1.$tn.2 { execsql {PRAGMA foreign_key_check(t1)} } {} + do_test fkey2-1.1.$tn.3 { execsql {PRAGMA foreign_key_check(t2)} } {} + do_test fkey2-1.1.$tn.4 { execsql {PRAGMA foreign_key_check(t3)} } {} + do_test fkey2-1.1.$tn.5 { execsql {PRAGMA foreign_key_check(t4)} } {} + do_test fkey2-1.1.$tn.6 { execsql {PRAGMA foreign_key_check(t7)} } {} + do_test fkey2-1.1.$tn.7 { execsql {PRAGMA foreign_key_check(t8)} } {} +} +drop_all_tables + +do_test fkey2-1.2.0 { + execsql [string map {/D/ {DEFERRABLE INITIALLY DEFERRED}} $FkeySimpleSchema] +} {} +foreach {tn zSql res} $FkeySimpleTests { + do_test fkey2-1.2.$tn { catchsql $zSql } $res + do_test fkey2-1.2.$tn.2 { execsql {PRAGMA foreign_key_check(t1)} } {} + do_test fkey2-1.2.$tn.3 { execsql {PRAGMA foreign_key_check(t2)} } {} + do_test fkey2-1.2.$tn.4 { execsql {PRAGMA foreign_key_check(t3)} } {} + do_test fkey2-1.2.$tn.5 { execsql {PRAGMA foreign_key_check(t4)} } {} + do_test fkey2-1.2.$tn.6 { execsql {PRAGMA foreign_key_check(t7)} } {} + do_test fkey2-1.2.$tn.7 { execsql {PRAGMA foreign_key_check(t8)} } {} +} +drop_all_tables + +do_test fkey2-1.3.0 { + execsql [string map {/D/ {}} $FkeySimpleSchema] + execsql { PRAGMA count_changes = 1 } +} {} +foreach {tn zSql res} $FkeySimpleTests { + if {$res == "0 {}"} { set res {0 1} } + do_test fkey2-1.3.$tn { catchsql $zSql } $res + do_test fkey2-1.3.$tn.2 { execsql {PRAGMA foreign_key_check(t1)} } {} + do_test fkey2-1.3.$tn.3 { execsql {PRAGMA foreign_key_check(t2)} } {} + do_test fkey2-1.3.$tn.4 { execsql {PRAGMA foreign_key_check(t3)} } {} + do_test fkey2-1.3.$tn.5 { execsql {PRAGMA foreign_key_check(t4)} } {} + do_test fkey2-1.3.$tn.6 { execsql {PRAGMA foreign_key_check(t7)} } {} + do_test fkey2-1.3.$tn.7 { execsql {PRAGMA foreign_key_check(t8)} } {} +} +execsql { PRAGMA count_changes = 0 } +drop_all_tables + +do_test fkey2-1.4.0 { + execsql [string map {/D/ {}} $FkeySimpleSchema] + execsql { PRAGMA count_changes = 1 } +} {} +foreach {tn zSql res} $FkeySimpleTests { + if {$res == "0 {}"} { set res {0 1} } + execsql BEGIN + do_test fkey2-1.4.$tn { catchsql $zSql } $res + execsql COMMIT +} +execsql { PRAGMA count_changes = 0 } +drop_all_tables + +# Special test: When the parent key is an IPK, make sure the affinity of +# the IPK is not applied to the child key value before it is inserted +# into the child table. +do_test fkey2-1.5.1 { + execsql { + CREATE TABLE i(i INTEGER PRIMARY KEY); + CREATE TABLE j(j REFERENCES i); + INSERT INTO i VALUES(35); + INSERT INTO j VALUES('35.0'); + SELECT j, typeof(j) FROM j; + } +} {35.0 text} +do_test fkey2-1.5.2 { + catchsql { DELETE FROM i } +} {1 {FOREIGN KEY constraint failed}} + +# Same test using a regular primary key with integer affinity. +drop_all_tables +do_test fkey2-1.6.1 { + execsql { + CREATE TABLE i(i INT UNIQUE); + CREATE TABLE j(j REFERENCES i(i)); + INSERT INTO i VALUES('35.0'); + INSERT INTO j VALUES('35.0'); + SELECT j, typeof(j) FROM j; + SELECT i, typeof(i) FROM i; + } +} {35.0 text 35 integer} +do_test fkey2-1.6.2 { + catchsql { DELETE FROM i } +} {1 {FOREIGN KEY constraint failed}} + +# Use a collation sequence on the parent key. +drop_all_tables +do_test fkey2-1.7.1 { + execsql { + CREATE TABLE i(i TEXT COLLATE nocase PRIMARY KEY); + CREATE TABLE j(j TEXT COLLATE binary REFERENCES i(i)); + INSERT INTO i VALUES('SQLite'); + INSERT INTO j VALUES('sqlite'); + } + catchsql { DELETE FROM i } +} {1 {FOREIGN KEY constraint failed}} + +# Use the parent key collation even if it is default and the child key +# has an explicit value. +drop_all_tables +do_test fkey2-1.7.2 { + execsql { + CREATE TABLE i(i TEXT PRIMARY KEY); -- Colseq is "BINARY" + CREATE TABLE j(j TEXT COLLATE nocase REFERENCES i(i)); + INSERT INTO i VALUES('SQLite'); + } + catchsql { INSERT INTO j VALUES('sqlite') } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-1.7.3 { + execsql { + INSERT INTO i VALUES('sqlite'); + INSERT INTO j VALUES('sqlite'); + DELETE FROM i WHERE i = 'SQLite'; + } + catchsql { DELETE FROM i WHERE i = 'sqlite' } +} {1 {FOREIGN KEY constraint failed}} + +#------------------------------------------------------------------------- +# This section (test cases fkey2-2.*) contains tests to check that the +# deferred foreign key constraint logic works. +# +proc fkey2-2-test {tn nocommit sql {res {}}} { + if {$res eq "FKV"} { + set expected {1 {FOREIGN KEY constraint failed}} + } else { + set expected [list 0 $res] + } + do_test fkey2-2.$tn [list catchsql $sql] $expected + if {$nocommit} { + do_test fkey2-2.${tn}c { + catchsql COMMIT + } {1 {FOREIGN KEY constraint failed}} + } +} + +fkey2-2-test 1 0 { + CREATE TABLE node( + nodeid PRIMARY KEY, + parent REFERENCES node DEFERRABLE INITIALLY DEFERRED + ); + CREATE TABLE leaf( + cellid PRIMARY KEY, + parent REFERENCES node DEFERRABLE INITIALLY DEFERRED + ); +} + +fkey2-2-test 1 0 "INSERT INTO node VALUES(1, 0)" FKV +fkey2-2-test 2 0 "BEGIN" +fkey2-2-test 3 1 "INSERT INTO node VALUES(1, 0)" +fkey2-2-test 4 0 "UPDATE node SET parent = NULL" +fkey2-2-test 5 0 "COMMIT" +fkey2-2-test 6 0 "SELECT * FROM node" {1 {}} + +fkey2-2-test 7 0 "BEGIN" +fkey2-2-test 8 1 "INSERT INTO leaf VALUES('a', 2)" +fkey2-2-test 9 1 "INSERT INTO node VALUES(2, 0)" +fkey2-2-test 10 0 "UPDATE node SET parent = 1 WHERE nodeid = 2" +fkey2-2-test 11 0 "COMMIT" +fkey2-2-test 12 0 "SELECT * FROM node" {1 {} 2 1} +fkey2-2-test 13 0 "SELECT * FROM leaf" {a 2} + +fkey2-2-test 14 0 "BEGIN" +fkey2-2-test 15 1 "DELETE FROM node WHERE nodeid = 2" +fkey2-2-test 16 0 "INSERT INTO node VALUES(2, NULL)" +fkey2-2-test 17 0 "COMMIT" +fkey2-2-test 18 0 "SELECT * FROM node" {1 {} 2 {}} +fkey2-2-test 19 0 "SELECT * FROM leaf" {a 2} + +fkey2-2-test 20 0 "BEGIN" +fkey2-2-test 21 0 "INSERT INTO leaf VALUES('b', 1)" +fkey2-2-test 22 0 "SAVEPOINT save" +fkey2-2-test 23 0 "DELETE FROM node WHERE nodeid = 1" +fkey2-2-test 24 0 "ROLLBACK TO save" +fkey2-2-test 25 0 "COMMIT" +fkey2-2-test 26 0 "SELECT * FROM node" {1 {} 2 {}} +fkey2-2-test 27 0 "SELECT * FROM leaf" {a 2 b 1} + +fkey2-2-test 28 0 "BEGIN" +fkey2-2-test 29 0 "INSERT INTO leaf VALUES('c', 1)" +fkey2-2-test 30 0 "SAVEPOINT save" +fkey2-2-test 31 0 "DELETE FROM node WHERE nodeid = 1" +fkey2-2-test 32 1 "RELEASE save" +fkey2-2-test 33 1 "DELETE FROM leaf WHERE cellid = 'b'" +fkey2-2-test 34 0 "DELETE FROM leaf WHERE cellid = 'c'" +fkey2-2-test 35 0 "COMMIT" +fkey2-2-test 36 0 "SELECT * FROM node" {2 {}} +fkey2-2-test 37 0 "SELECT * FROM leaf" {a 2} + +fkey2-2-test 38 0 "SAVEPOINT outer" +fkey2-2-test 39 1 "INSERT INTO leaf VALUES('d', 3)" +fkey2-2-test 40 1 "RELEASE outer" FKV +fkey2-2-test 41 1 "INSERT INTO leaf VALUES('e', 3)" +fkey2-2-test 42 0 "INSERT INTO node VALUES(3, 2)" +fkey2-2-test 43 0 "RELEASE outer" + +fkey2-2-test 44 0 "SAVEPOINT outer" +fkey2-2-test 45 1 "DELETE FROM node WHERE nodeid=3" +fkey2-2-test 47 0 "INSERT INTO node VALUES(3, 2)" +fkey2-2-test 48 0 "ROLLBACK TO outer" +fkey2-2-test 49 0 "RELEASE outer" + +fkey2-2-test 50 0 "SAVEPOINT outer" +fkey2-2-test 51 1 "INSERT INTO leaf VALUES('f', 4)" +fkey2-2-test 52 1 "SAVEPOINT inner" +fkey2-2-test 53 1 "INSERT INTO leaf VALUES('g', 4)" +fkey2-2-test 54 1 "RELEASE outer" FKV +fkey2-2-test 55 1 "ROLLBACK TO inner" +fkey2-2-test 56 0 "COMMIT" FKV +fkey2-2-test 57 0 "INSERT INTO node VALUES(4, NULL)" +fkey2-2-test 58 0 "RELEASE outer" +fkey2-2-test 59 0 "SELECT * FROM node" {2 {} 3 2 4 {}} +fkey2-2-test 60 0 "SELECT * FROM leaf" {a 2 d 3 e 3 f 4} + +# The following set of tests check that if a statement that affects +# multiple rows violates some foreign key constraints, then strikes a +# constraint that causes the statement-transaction to be rolled back, +# the deferred constraint counter is correctly reset to the value it +# had before the statement-transaction was opened. +# +fkey2-2-test 61 0 "BEGIN" +fkey2-2-test 62 0 "DELETE FROM leaf" +fkey2-2-test 63 0 "DELETE FROM node" +fkey2-2-test 64 1 "INSERT INTO leaf VALUES('a', 1)" +fkey2-2-test 65 1 "INSERT INTO leaf VALUES('b', 2)" +fkey2-2-test 66 1 "INSERT INTO leaf VALUES('c', 1)" +do_test fkey2-2-test-67 { + catchsql "INSERT INTO node SELECT parent, 3 FROM leaf" +} {1 {UNIQUE constraint failed: node.nodeid}} +fkey2-2-test 68 0 "COMMIT" FKV +fkey2-2-test 69 1 "INSERT INTO node VALUES(1, NULL)" +fkey2-2-test 70 0 "INSERT INTO node VALUES(2, NULL)" +fkey2-2-test 71 0 "COMMIT" + +fkey2-2-test 72 0 "BEGIN" +fkey2-2-test 73 1 "DELETE FROM node" +fkey2-2-test 74 0 "INSERT INTO node(nodeid) SELECT DISTINCT parent FROM leaf" +fkey2-2-test 75 0 "COMMIT" + +#------------------------------------------------------------------------- +# Test cases fkey2-3.* test that a program that executes foreign key +# actions (CASCADE, SET DEFAULT, SET NULL etc.) or tests FK constraints +# opens a statement transaction if required. +# +# fkey2-3.1.*: Test UPDATE statements. +# fkey2-3.2.*: Test DELETE statements. +# +drop_all_tables +do_test fkey2-3.1.1 { + execsql { + CREATE TABLE ab(a PRIMARY KEY, b); + CREATE TABLE cd( + c PRIMARY KEY REFERENCES ab ON UPDATE CASCADE ON DELETE CASCADE, + d + ); + CREATE TABLE ef( + e REFERENCES cd ON UPDATE CASCADE, + f, CHECK (e!=5) + ); + } +} {} +do_test fkey2-3.1.2 { + execsql { + INSERT INTO ab VALUES(1, 'b'); + INSERT INTO cd VALUES(1, 'd'); + INSERT INTO ef VALUES(1, 'e'); + } +} {} +do_test fkey2-3.1.3 { + catchsql { UPDATE ab SET a = 5 } +} {1 {CHECK constraint failed: e!=5}} +do_test fkey2-3.1.4 { + execsql { SELECT * FROM ab } +} {1 b} +do_test fkey2-3.1.4 { + execsql BEGIN; + catchsql { UPDATE ab SET a = 5 } +} {1 {CHECK constraint failed: e!=5}} +do_test fkey2-3.1.5 { + execsql COMMIT; + execsql { SELECT * FROM ab; SELECT * FROM cd; SELECT * FROM ef } +} {1 b 1 d 1 e} + +do_test fkey2-3.2.1 { + execsql BEGIN; + catchsql { DELETE FROM ab } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-3.2.2 { + execsql COMMIT + execsql { SELECT * FROM ab; SELECT * FROM cd; SELECT * FROM ef } +} {1 b 1 d 1 e} + +#------------------------------------------------------------------------- +# Test cases fkey2-4.* test that recursive foreign key actions +# (i.e. CASCADE) are allowed even if recursive triggers are disabled. +# +drop_all_tables +do_test fkey2-4.1 { + execsql { + CREATE TABLE t1( + node PRIMARY KEY, + parent REFERENCES t1 ON DELETE CASCADE + ); + CREATE TABLE t2(node PRIMARY KEY, parent); + CREATE TRIGGER t2t AFTER DELETE ON t2 BEGIN + DELETE FROM t2 WHERE parent = old.node; + END; + INSERT INTO t1 VALUES(1, NULL); + INSERT INTO t1 VALUES(2, 1); + INSERT INTO t1 VALUES(3, 1); + INSERT INTO t1 VALUES(4, 2); + INSERT INTO t1 VALUES(5, 2); + INSERT INTO t1 VALUES(6, 3); + INSERT INTO t1 VALUES(7, 3); + INSERT INTO t2 SELECT * FROM t1; + } +} {} +do_test fkey2-4.2 { + execsql { PRAGMA recursive_triggers = off } + execsql { + BEGIN; + DELETE FROM t1 WHERE node = 1; + SELECT node FROM t1; + } +} {} +do_test fkey2-4.3 { + execsql { + DELETE FROM t2 WHERE node = 1; + SELECT node FROM t2; + ROLLBACK; + } +} {4 5 6 7} +do_test fkey2-4.4 { + execsql { PRAGMA recursive_triggers = on } + execsql { + BEGIN; + DELETE FROM t1 WHERE node = 1; + SELECT node FROM t1; + } +} {} +do_test fkey2-4.3 { + execsql { + DELETE FROM t2 WHERE node = 1; + SELECT node FROM t2; + ROLLBACK; + } +} {} + +#------------------------------------------------------------------------- +# Test cases fkey2-5.* verify that the incremental blob API may not +# write to a foreign key column while foreign-keys are enabled. +# +drop_all_tables +ifcapable incrblob { + do_test fkey2-5.1 { + execsql { + CREATE TABLE t1(a PRIMARY KEY, b); + CREATE TABLE t2(a PRIMARY KEY, b REFERENCES t1(a)); + INSERT INTO t1 VALUES('hello', 'world'); + INSERT INTO t2 VALUES('key', 'hello'); + } + } {} + do_test fkey2-5.2 { + set rc [catch { set fd [db incrblob t2 b 1] } msg] + list $rc $msg + } {1 {cannot open foreign key column for writing}} + do_test fkey2-5.3 { + set rc [catch { set fd [db incrblob -readonly t2 b 1] } msg] + close $fd + set rc + } {0} + do_test fkey2-5.4 { + execsql { PRAGMA foreign_keys = off } + set rc [catch { set fd [db incrblob t2 b 1] } msg] + close $fd + set rc + } {0} + do_test fkey2-5.5 { + execsql { PRAGMA foreign_keys = on } + } {} +} + +drop_all_tables +ifcapable vacuum { + do_test fkey2-6.1 { + execsql { + CREATE TABLE t1(a REFERENCES t2(c), b); + CREATE TABLE t2(c UNIQUE, b); + INSERT INTO t2 VALUES(1, 2); + INSERT INTO t1 VALUES(1, 2); + VACUUM; + } + } {} +} + +#------------------------------------------------------------------------- +# Test that it is possible to use an INTEGER PRIMARY KEY as the child key +# of a foreign constraint. +# +drop_all_tables +do_test fkey2-7.1 { + execsql { + CREATE TABLE t1(a PRIMARY KEY, b); + CREATE TABLE t2(c INTEGER PRIMARY KEY REFERENCES t1, b); + } +} {} +do_test fkey2-7.2 { + catchsql { INSERT INTO t2 VALUES(1, 'A'); } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-7.3 { + execsql { + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t1 VALUES(2, 3); + INSERT INTO t2 VALUES(1, 'A'); + } +} {} +do_test fkey2-7.4 { + execsql { UPDATE t2 SET c = 2 } +} {} +do_test fkey2-7.5 { + catchsql { UPDATE t2 SET c = 3 } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-7.6 { + catchsql { DELETE FROM t1 WHERE a = 2 } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-7.7 { + execsql { DELETE FROM t1 WHERE a = 1 } +} {} +do_test fkey2-7.8 { + catchsql { UPDATE t1 SET a = 3 } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-7.9 { + catchsql { UPDATE t2 SET rowid = 3 } +} {1 {FOREIGN KEY constraint failed}} + +#------------------------------------------------------------------------- +# Test that it is not possible to enable/disable FK support while a +# transaction is open. +# +drop_all_tables +proc fkey2-8-test {tn zSql value} { + do_test fkey-2.8.$tn.1 [list execsql $zSql] {} + do_test fkey-2.8.$tn.2 { execsql "PRAGMA foreign_keys" } $value +} +fkey2-8-test 1 { PRAGMA foreign_keys = 0 } 0 +fkey2-8-test 2 { PRAGMA foreign_keys = 1 } 1 +fkey2-8-test 3 { BEGIN } 1 +fkey2-8-test 4 { PRAGMA foreign_keys = 0 } 1 +fkey2-8-test 5 { COMMIT } 1 +fkey2-8-test 6 { PRAGMA foreign_keys = 0 } 0 +fkey2-8-test 7 { BEGIN } 0 +fkey2-8-test 8 { PRAGMA foreign_keys = 1 } 0 +fkey2-8-test 9 { COMMIT } 0 +fkey2-8-test 10 { PRAGMA foreign_keys = 1 } 1 +fkey2-8-test 11 { PRAGMA foreign_keys = off } 0 +fkey2-8-test 12 { PRAGMA foreign_keys = on } 1 +fkey2-8-test 13 { PRAGMA foreign_keys = no } 0 +fkey2-8-test 14 { PRAGMA foreign_keys = yes } 1 +fkey2-8-test 15 { PRAGMA foreign_keys = false } 0 +fkey2-8-test 16 { PRAGMA foreign_keys = true } 1 + +#------------------------------------------------------------------------- +# The following tests, fkey2-9.*, test SET DEFAULT actions. +# +drop_all_tables +do_test fkey2-9.1.1 { + execsql { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + CREATE TABLE t2( + c INTEGER PRIMARY KEY, + d INTEGER DEFAULT 1 REFERENCES t1 ON DELETE SET DEFAULT + ); + DELETE FROM t1; + } +} {} +do_test fkey2-9.1.2 { + execsql { + INSERT INTO t1 VALUES(1, 'one'); + INSERT INTO t1 VALUES(2, 'two'); + INSERT INTO t2 VALUES(1, 2); + SELECT * FROM t2; + DELETE FROM t1 WHERE a = 2; + SELECT * FROM t2; + } +} {1 2 1 1} +do_test fkey2-9.1.3 { + execsql { + INSERT INTO t1 VALUES(2, 'two'); + UPDATE t2 SET d = 2; + DELETE FROM t1 WHERE a = 1; + SELECT * FROM t2; + } +} {1 2} +do_test fkey2-9.1.4 { + execsql { SELECT * FROM t1 } +} {2 two} +do_test fkey2-9.1.5 { + catchsql { DELETE FROM t1 } +} {1 {FOREIGN KEY constraint failed}} + +do_test fkey2-9.2.1 { + execsql { + CREATE TABLE pp(a, b, c, PRIMARY KEY(b, c)); + CREATE TABLE cc(d DEFAULT 3, e DEFAULT 1, f DEFAULT 2, + FOREIGN KEY(f, d) REFERENCES pp + ON UPDATE SET DEFAULT + ON DELETE SET NULL + ); + INSERT INTO pp VALUES(1, 2, 3); + INSERT INTO pp VALUES(4, 5, 6); + INSERT INTO pp VALUES(7, 8, 9); + } +} {} +do_test fkey2-9.2.2 { + execsql { + INSERT INTO cc VALUES(6, 'A', 5); + INSERT INTO cc VALUES(6, 'B', 5); + INSERT INTO cc VALUES(9, 'A', 8); + INSERT INTO cc VALUES(9, 'B', 8); + UPDATE pp SET b = 1 WHERE a = 7; + SELECT * FROM cc; + } +} {6 A 5 6 B 5 3 A 2 3 B 2} +do_test fkey2-9.2.3 { + execsql { + DELETE FROM pp WHERE a = 4; + SELECT * FROM cc; + } +} {{} A {} {} B {} 3 A 2 3 B 2} +do_execsql_test fkey2-9.3.0 { + CREATE TABLE t3(x PRIMARY KEY REFERENCES t3 ON DELETE SET NULL); + INSERT INTO t3(x) VALUES(12345); + DROP TABLE t3; +} {} + +#------------------------------------------------------------------------- +# The following tests, fkey2-10.*, test "foreign key mismatch" and +# other errors. +# +set tn 0 +foreach zSql [list { + CREATE TABLE p(a PRIMARY KEY, b); + CREATE TABLE c(x REFERENCES p(c)); +} { + CREATE TABLE c(x REFERENCES v(y)); + CREATE VIEW v AS SELECT x AS y FROM c; +} { + CREATE TABLE p(a, b, PRIMARY KEY(a, b)); + CREATE TABLE c(x REFERENCES p); +} { + CREATE TABLE p(a COLLATE binary, b); + CREATE UNIQUE INDEX i ON p(a COLLATE nocase); + CREATE TABLE c(x REFERENCES p(a)); +}] { + drop_all_tables + do_test fkey2-10.1.[incr tn] { + execsql $zSql + catchsql { INSERT INTO c DEFAULT VALUES } + } {/1 {foreign key mismatch - "c" referencing "."}/} +} + +# "rowid" cannot be used as part of a child or parent key definition +# unless it happens to be the name of an explicitly declared column. +# +do_test fkey2-10.2.1 { + drop_all_tables + catchsql { + CREATE TABLE t1(a PRIMARY KEY, b); + CREATE TABLE t2(c, d, FOREIGN KEY(rowid) REFERENCES t1(a)); + } +} {1 {unknown column "rowid" in foreign key definition}} +do_test fkey2-10.2.2 { + drop_all_tables + catchsql { + CREATE TABLE t1(a PRIMARY KEY, b); + CREATE TABLE t2(rowid, d, FOREIGN KEY(rowid) REFERENCES t1(a)); + } +} {0 {}} +do_test fkey2-10.2.1 { + drop_all_tables + catchsql { + CREATE TABLE t1(a, b); + CREATE TABLE t2(c, d, FOREIGN KEY(c) REFERENCES t1(rowid)); + INSERT INTO t1(rowid, a, b) VALUES(1, 1, 1); + INSERT INTO t2 VALUES(1, 1); + } +} {1 {foreign key mismatch - "t2" referencing "t1"}} +do_test fkey2-10.2.2 { + drop_all_tables + catchsql { + CREATE TABLE t1(rowid PRIMARY KEY, b); + CREATE TABLE t2(c, d, FOREIGN KEY(c) REFERENCES t1(rowid)); + INSERT INTO t1(rowid, b) VALUES(1, 1); + INSERT INTO t2 VALUES(1, 1); + } +} {0 {}} + + +#------------------------------------------------------------------------- +# The following tests, fkey2-11.*, test CASCADE actions. +# +drop_all_tables +do_test fkey2-11.1.1 { + execsql { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, rowid, _rowid_, oid); + CREATE TABLE t2(c, d, FOREIGN KEY(c) REFERENCES t1(a) ON UPDATE CASCADE); + + INSERT INTO t1 VALUES(10, 100, 'abc', 'def', 'ghi'); + INSERT INTO t2 VALUES(10, 100); + UPDATE t1 SET a = 15; + SELECT * FROM t2; + } +} {15 100} + +#------------------------------------------------------------------------- +# The following tests, fkey2-12.*, test RESTRICT actions. +# +drop_all_tables +do_test fkey2-12.1.1 { + execsql { + CREATE TABLE t1(a, b PRIMARY KEY); + CREATE TABLE t2( + x REFERENCES t1 ON UPDATE RESTRICT DEFERRABLE INITIALLY DEFERRED + ); + INSERT INTO t1 VALUES(1, 'one'); + INSERT INTO t1 VALUES(2, 'two'); + INSERT INTO t1 VALUES(3, 'three'); + } +} {} +do_test fkey2-12.1.2 { + execsql "BEGIN" + execsql "INSERT INTO t2 VALUES('two')" +} {} +do_test fkey2-12.1.3 { + execsql "UPDATE t1 SET b = 'four' WHERE b = 'one'" +} {} +do_test fkey2-12.1.4 { + catchsql "UPDATE t1 SET b = 'five' WHERE b = 'two'" +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-12.1.5 { + execsql "DELETE FROM t1 WHERE b = 'two'" +} {} +do_test fkey2-12.1.6 { + catchsql "COMMIT" +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-12.1.7 { + execsql { + INSERT INTO t1 VALUES(2, 'two'); + COMMIT; + } +} {} + +drop_all_tables +do_test fkey2-12.2.1 { + execsql { + CREATE TABLE t1(x COLLATE NOCASE PRIMARY KEY); + CREATE TRIGGER tt1 AFTER DELETE ON t1 + WHEN EXISTS ( SELECT 1 FROM t2 WHERE old.x = y ) + BEGIN + INSERT INTO t1 VALUES(old.x); + END; + CREATE TABLE t2(y REFERENCES t1); + INSERT INTO t1 VALUES('A'); + INSERT INTO t1 VALUES('B'); + INSERT INTO t2 VALUES('a'); + INSERT INTO t2 VALUES('b'); + + SELECT * FROM t1; + SELECT * FROM t2; + } +} {A B a b} +do_test fkey2-12.2.2 { + execsql { DELETE FROM t1 } + execsql { + SELECT * FROM t1; + SELECT * FROM t2; + } +} {A B a b} +do_test fkey2-12.2.3 { + execsql { + DROP TABLE t2; + CREATE TABLE t2(y REFERENCES t1 ON DELETE RESTRICT); + INSERT INTO t2 VALUES('a'); + INSERT INTO t2 VALUES('b'); + } + catchsql { DELETE FROM t1 } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-12.2.4 { + execsql { + SELECT * FROM t1; + SELECT * FROM t2; + } +} {A B a b} + +drop_all_tables +do_test fkey2-12.3.1 { + execsql { + CREATE TABLE up( + c00, c01, c02, c03, c04, c05, c06, c07, c08, c09, + c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, + c20, c21, c22, c23, c24, c25, c26, c27, c28, c29, + c30, c31, c32, c33, c34, c35, c36, c37, c38, c39, + PRIMARY KEY(c34, c35) + ); + CREATE TABLE down( + c00, c01, c02, c03, c04, c05, c06, c07, c08, c09, + c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, + c20, c21, c22, c23, c24, c25, c26, c27, c28, c29, + c30, c31, c32, c33, c34, c35, c36, c37, c38, c39, + FOREIGN KEY(c39, c38) REFERENCES up ON UPDATE CASCADE + ); + } +} {} +do_test fkey2-12.3.2 { + execsql { + INSERT INTO up(c34, c35) VALUES('yes', 'no'); + INSERT INTO down(c39, c38) VALUES('yes', 'no'); + UPDATE up SET c34 = 'possibly'; + SELECT c38, c39 FROM down; + DELETE FROM down; + } +} {no possibly} +do_test fkey2-12.3.3 { + catchsql { INSERT INTO down(c39, c38) VALUES('yes', 'no') } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-12.3.4 { + execsql { + INSERT INTO up(c34, c35) VALUES('yes', 'no'); + INSERT INTO down(c39, c38) VALUES('yes', 'no'); + } + catchsql { DELETE FROM up WHERE c34 = 'yes' } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-12.3.5 { + execsql { + DELETE FROM up WHERE c34 = 'possibly'; + SELECT c34, c35 FROM up; + SELECT c39, c38 FROM down; + } +} {yes no yes no} + +#------------------------------------------------------------------------- +# The following tests, fkey2-13.*, test that FK processing is performed +# when rows are REPLACEd. +# +drop_all_tables +do_test fkey2-13.1.1 { + execsql { + CREATE TABLE pp(a UNIQUE, b, c, PRIMARY KEY(b, c)); + CREATE TABLE cc(d, e, f UNIQUE, FOREIGN KEY(d, e) REFERENCES pp); + INSERT INTO pp VALUES(1, 2, 3); + INSERT INTO cc VALUES(2, 3, 1); + } +} {} +foreach {tn stmt} { + 1 "REPLACE INTO pp VALUES(1, 4, 5)" + 2 "REPLACE INTO pp(rowid, a, b, c) VALUES(1, 2, 3, 4)" +} { + do_test fkey2-13.1.$tn.1 { + catchsql $stmt + } {1 {FOREIGN KEY constraint failed}} + do_test fkey2-13.1.$tn.2 { + execsql { + SELECT * FROM pp; + SELECT * FROM cc; + } + } {1 2 3 2 3 1} + do_test fkey2-13.1.$tn.3 { + execsql BEGIN; + catchsql $stmt + } {1 {FOREIGN KEY constraint failed}} + do_test fkey2-13.1.$tn.4 { + execsql { + COMMIT; + SELECT * FROM pp; + SELECT * FROM cc; + } + } {1 2 3 2 3 1} +} +do_test fkey2-13.1.3 { + execsql { + REPLACE INTO pp(rowid, a, b, c) VALUES(1, 2, 2, 3); + SELECT rowid, * FROM pp; + SELECT * FROM cc; + } +} {1 2 2 3 2 3 1} +do_test fkey2-13.1.4 { + execsql { + REPLACE INTO pp(rowid, a, b, c) VALUES(2, 2, 2, 3); + SELECT rowid, * FROM pp; + SELECT * FROM cc; + } +} {2 2 2 3 2 3 1} + +#------------------------------------------------------------------------- +# The following tests, fkey2-14.*, test that the "DROP TABLE" and "ALTER +# TABLE" commands work as expected wrt foreign key constraints. +# +# fkey2-14.1*: ALTER TABLE ADD COLUMN +# fkey2-14.2*: ALTER TABLE RENAME TABLE +# fkey2-14.3*: DROP TABLE +# +drop_all_tables +ifcapable altertable { + do_test fkey2-14.1.1 { + # Adding a column with a REFERENCES clause is not supported. + execsql { + CREATE TABLE t1(a PRIMARY KEY); + CREATE TABLE t2(a, b); + INSERT INTO t2 VALUES(1,2); + } + catchsql { ALTER TABLE t2 ADD COLUMN c REFERENCES t1 } + } {0 {}} + do_test fkey2-14.1.2 { + catchsql { ALTER TABLE t2 ADD COLUMN d DEFAULT NULL REFERENCES t1 } + } {0 {}} + do_test fkey2-14.1.3 { + catchsql { ALTER TABLE t2 ADD COLUMN e REFERENCES t1 DEFAULT NULL} + } {0 {}} + do_test fkey2-14.1.4 { + catchsql { ALTER TABLE t2 ADD COLUMN f REFERENCES t1 DEFAULT 'text'} + } {1 {Cannot add a REFERENCES column with non-NULL default value}} + do_test fkey2-14.1.5 { + catchsql { ALTER TABLE t2 ADD COLUMN g DEFAULT CURRENT_TIME REFERENCES t1 } + } {1 {Cannot add a REFERENCES column with non-NULL default value}} + do_test fkey2-14.1.6 { + execsql { + PRAGMA foreign_keys = off; + ALTER TABLE t2 ADD COLUMN h DEFAULT 'text' REFERENCES t1; + PRAGMA foreign_keys = on; + SELECT sql FROM sqlite_master WHERE name='t2'; + } + } {{CREATE TABLE t2(a, b, c REFERENCES t1, d DEFAULT NULL REFERENCES t1, e REFERENCES t1 DEFAULT NULL, h DEFAULT 'text' REFERENCES t1)}} + + + # Test the sqlite_rename_parent() function directly. + # + proc test_rename_parent {zCreate zOld zNew} { + db eval {SELECT sqlite_rename_table( + 'main', 'table', 't1', $zCreate, $zOld, $zNew, 0 + )} + } + sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db + do_test fkey2-14.2.1.1 { + test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t2 t3 + } {{CREATE TABLE t1(a REFERENCES "t3")}} + do_test fkey2-14.2.1.2 { + test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t4 t3 + } {{CREATE TABLE t1(a REFERENCES t2)}} + do_test fkey2-14.2.1.3 { + test_rename_parent {CREATE TABLE t1(a REFERENCES "t2")} t2 t3 + } {{CREATE TABLE t1(a REFERENCES "t3")}} + sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db + + # Test ALTER TABLE RENAME TABLE a bit. + # + do_test fkey2-14.2.2.1 { + drop_all_tables + execsql { + CREATE TABLE t1(a PRIMARY KEY, b REFERENCES t1); + CREATE TABLE t2(a PRIMARY KEY, b REFERENCES t1, c REFERENCES t2); + CREATE TABLE t3(a REFERENCES t1, b REFERENCES t2, c REFERENCES t1); + } + execsql { SELECT sql FROM sqlite_master WHERE type = 'table'} + } [list \ + {CREATE TABLE t1(a PRIMARY KEY, b REFERENCES t1)} \ + {CREATE TABLE t2(a PRIMARY KEY, b REFERENCES t1, c REFERENCES t2)} \ + {CREATE TABLE t3(a REFERENCES t1, b REFERENCES t2, c REFERENCES t1)} \ + ] + do_test fkey2-14.2.2.2 { + execsql { ALTER TABLE t1 RENAME TO t4 } + execsql { SELECT sql FROM sqlite_master WHERE type = 'table'} + } [list \ + {CREATE TABLE "t4"(a PRIMARY KEY, b REFERENCES "t4")} \ + {CREATE TABLE t2(a PRIMARY KEY, b REFERENCES "t4", c REFERENCES t2)} \ + {CREATE TABLE t3(a REFERENCES "t4", b REFERENCES t2, c REFERENCES "t4")} \ + ] + do_test fkey2-14.2.2.3 { + catchsql { INSERT INTO t3 VALUES(1, 2, 3) } + } {1 {FOREIGN KEY constraint failed}} + do_test fkey2-14.2.2.4 { + execsql { INSERT INTO t4 VALUES(1, NULL) } + } {} + do_test fkey2-14.2.2.5 { + catchsql { UPDATE t4 SET b = 5 } + } {1 {FOREIGN KEY constraint failed}} + do_test fkey2-14.2.2.6 { + catchsql { UPDATE t4 SET b = 1 } + } {0 {}} + do_test fkey2-14.2.2.7 { + execsql { INSERT INTO t3 VALUES(1, NULL, 1) } + } {} + + # Repeat for TEMP tables + # + drop_all_tables + do_test fkey2-14.1tmp.1 { + # Adding a column with a REFERENCES clause is not supported. + execsql { + CREATE TEMP TABLE t1(a PRIMARY KEY); + CREATE TEMP TABLE t2(a, b); + INSERT INTO temp.t2 VALUES(1,2); + } + catchsql { ALTER TABLE t2 ADD COLUMN c REFERENCES t1 } + } {0 {}} + do_test fkey2-14.1tmp.2 { + catchsql { ALTER TABLE t2 ADD COLUMN d DEFAULT NULL REFERENCES t1 } + } {0 {}} + do_test fkey2-14.1tmp.3 { + catchsql { ALTER TABLE t2 ADD COLUMN e REFERENCES t1 DEFAULT NULL} + } {0 {}} + do_test fkey2-14.1tmp.4 { + catchsql { ALTER TABLE t2 ADD COLUMN f REFERENCES t1 DEFAULT 'text'} + } {1 {Cannot add a REFERENCES column with non-NULL default value}} + do_test fkey2-14.1tmp.5 { + catchsql { ALTER TABLE t2 ADD COLUMN g DEFAULT CURRENT_TIME REFERENCES t1 } + } {1 {Cannot add a REFERENCES column with non-NULL default value}} + do_test fkey2-14.1tmp.6 { + execsql { + PRAGMA foreign_keys = off; + ALTER TABLE t2 ADD COLUMN h DEFAULT 'text' REFERENCES t1; + PRAGMA foreign_keys = on; + SELECT sql FROM temp.sqlite_master WHERE name='t2'; + } + } {{CREATE TABLE t2(a, b, c REFERENCES t1, d DEFAULT NULL REFERENCES t1, e REFERENCES t1 DEFAULT NULL, h DEFAULT 'text' REFERENCES t1)}} + + sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db + do_test fkey2-14.2tmp.1.1 { + test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t2 t3 + } {{CREATE TABLE t1(a REFERENCES "t3")}} + do_test fkey2-14.2tmp.1.2 { + test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t4 t3 + } {{CREATE TABLE t1(a REFERENCES t2)}} + do_test fkey2-14.2tmp.1.3 { + test_rename_parent {CREATE TABLE t1(a REFERENCES "t2")} t2 t3 + } {{CREATE TABLE t1(a REFERENCES "t3")}} + sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db + + # Test ALTER TABLE RENAME TABLE a bit. + # + do_test fkey2-14.2tmp.2.1 { + drop_all_tables + execsql { + CREATE TEMP TABLE t1(a PRIMARY KEY, b REFERENCES t1); + CREATE TEMP TABLE t2(a PRIMARY KEY, b REFERENCES t1, c REFERENCES t2); + CREATE TEMP TABLE t3(a REFERENCES t1, b REFERENCES t2, c REFERENCES t1); + } + execsql { SELECT sql FROM sqlite_temp_master WHERE type = 'table'} + } [list \ + {CREATE TABLE t1(a PRIMARY KEY, b REFERENCES t1)} \ + {CREATE TABLE t2(a PRIMARY KEY, b REFERENCES t1, c REFERENCES t2)} \ + {CREATE TABLE t3(a REFERENCES t1, b REFERENCES t2, c REFERENCES t1)} \ + ] + do_test fkey2-14.2tmp.2.2 { + execsql { ALTER TABLE t1 RENAME TO t4 } + execsql { SELECT sql FROM temp.sqlite_master WHERE type = 'table'} + } [list \ + {CREATE TABLE "t4"(a PRIMARY KEY, b REFERENCES "t4")} \ + {CREATE TABLE t2(a PRIMARY KEY, b REFERENCES "t4", c REFERENCES t2)} \ + {CREATE TABLE t3(a REFERENCES "t4", b REFERENCES t2, c REFERENCES "t4")} \ + ] + do_test fkey2-14.2tmp.2.3 { + catchsql { INSERT INTO t3 VALUES(1, 2, 3) } + } {1 {FOREIGN KEY constraint failed}} + do_test fkey2-14.2tmp.2.4 { + execsql { INSERT INTO t4 VALUES(1, NULL) } + } {} + do_test fkey2-14.2tmp.2.5 { + catchsql { UPDATE t4 SET b = 5 } + } {1 {FOREIGN KEY constraint failed}} + do_test fkey2-14.2tmp.2.6 { + catchsql { UPDATE t4 SET b = 1 } + } {0 {}} + do_test fkey2-14.2tmp.2.7 { + execsql { INSERT INTO t3 VALUES(1, NULL, 1) } + } {} + + # Repeat for ATTACH-ed tables + # + drop_all_tables + do_test fkey2-14.1aux.1 { + # Adding a column with a REFERENCES clause is not supported. + execsql { + ATTACH ':memory:' AS aux; + CREATE TABLE aux.t1(a PRIMARY KEY); + CREATE TABLE aux.t2(a, b); + INSERT INTO aux.t2(a,b) VALUES(1,2); + } + catchsql { ALTER TABLE t2 ADD COLUMN c REFERENCES t1 } + } {0 {}} + do_test fkey2-14.1aux.2 { + catchsql { ALTER TABLE t2 ADD COLUMN d DEFAULT NULL REFERENCES t1 } + } {0 {}} + do_test fkey2-14.1aux.3 { + catchsql { ALTER TABLE t2 ADD COLUMN e REFERENCES t1 DEFAULT NULL} + } {0 {}} + do_test fkey2-14.1aux.4 { + catchsql { ALTER TABLE t2 ADD COLUMN f REFERENCES t1 DEFAULT 'text'} + } {1 {Cannot add a REFERENCES column with non-NULL default value}} + do_test fkey2-14.1aux.5 { + catchsql { ALTER TABLE t2 ADD COLUMN g DEFAULT CURRENT_TIME REFERENCES t1 } + } {1 {Cannot add a REFERENCES column with non-NULL default value}} + do_test fkey2-14.1aux.6 { + execsql { + PRAGMA foreign_keys = off; + ALTER TABLE t2 ADD COLUMN h DEFAULT 'text' REFERENCES t1; + PRAGMA foreign_keys = on; + SELECT sql FROM aux.sqlite_master WHERE name='t2'; + } + } {{CREATE TABLE t2(a, b, c REFERENCES t1, d DEFAULT NULL REFERENCES t1, e REFERENCES t1 DEFAULT NULL, h DEFAULT 'text' REFERENCES t1)}} + + sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db + do_test fkey2-14.2aux.1.1 { + test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t2 t3 + } {{CREATE TABLE t1(a REFERENCES "t3")}} + do_test fkey2-14.2aux.1.2 { + test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t4 t3 + } {{CREATE TABLE t1(a REFERENCES t2)}} + do_test fkey2-14.2aux.1.3 { + test_rename_parent {CREATE TABLE t1(a REFERENCES "t2")} t2 t3 + } {{CREATE TABLE t1(a REFERENCES "t3")}} + sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db + + # Test ALTER TABLE RENAME TABLE a bit. + # + do_test fkey2-14.2aux.2.1 { + drop_all_tables + execsql { + CREATE TABLE aux.t1(a PRIMARY KEY, b REFERENCES t1); + CREATE TABLE aux.t2(a PRIMARY KEY, b REFERENCES t1, c REFERENCES t2); + CREATE TABLE aux.t3(a REFERENCES t1, b REFERENCES t2, c REFERENCES t1); + } + execsql { SELECT sql FROM aux.sqlite_master WHERE type = 'table'} + } [list \ + {CREATE TABLE t1(a PRIMARY KEY, b REFERENCES t1)} \ + {CREATE TABLE t2(a PRIMARY KEY, b REFERENCES t1, c REFERENCES t2)} \ + {CREATE TABLE t3(a REFERENCES t1, b REFERENCES t2, c REFERENCES t1)} \ + ] + do_test fkey2-14.2aux.2.2 { + execsql { ALTER TABLE t1 RENAME TO t4 } + execsql { SELECT sql FROM aux.sqlite_master WHERE type = 'table'} + } [list \ + {CREATE TABLE "t4"(a PRIMARY KEY, b REFERENCES "t4")} \ + {CREATE TABLE t2(a PRIMARY KEY, b REFERENCES "t4", c REFERENCES t2)} \ + {CREATE TABLE t3(a REFERENCES "t4", b REFERENCES t2, c REFERENCES "t4")} \ + ] + do_test fkey2-14.2aux.2.3 { + catchsql { INSERT INTO t3 VALUES(1, 2, 3) } + } {1 {FOREIGN KEY constraint failed}} + do_test fkey2-14.2aux.2.4 { + execsql { INSERT INTO t4 VALUES(1, NULL) } + } {} + do_test fkey2-14.2aux.2.5 { + catchsql { UPDATE t4 SET b = 5 } + } {1 {FOREIGN KEY constraint failed}} + do_test fkey2-14.2aux.2.6 { + catchsql { UPDATE t4 SET b = 1 } + } {0 {}} + do_test fkey2-14.2aux.2.7 { + execsql { INSERT INTO t3 VALUES(1, NULL, 1) } + } {} +} + +do_test fkey-2.14.3.1 { + drop_all_tables + execsql { + CREATE TABLE t1(a, b REFERENCES nosuchtable); + DROP TABLE t1; + } +} {} +do_test fkey-2.14.3.2 { + execsql { + CREATE TABLE t1(a PRIMARY KEY, b); + INSERT INTO t1 VALUES('a', 1); + CREATE TABLE t2(x REFERENCES t1); + INSERT INTO t2 VALUES('a'); + } +} {} +do_test fkey-2.14.3.3 { + catchsql { DROP TABLE t1 } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey-2.14.3.4 { + execsql { + DELETE FROM t2; + DROP TABLE t1; + } +} {} +do_test fkey-2.14.3.4 { + catchsql { INSERT INTO t2 VALUES('x') } +} {1 {no such table: main.t1}} +do_test fkey-2.14.3.5 { + execsql { + CREATE TABLE t1(x PRIMARY KEY); + INSERT INTO t1 VALUES('x'); + } + execsql { INSERT INTO t2 VALUES('x') } +} {} +do_test fkey-2.14.3.6 { + catchsql { DROP TABLE t1 } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey-2.14.3.7 { + execsql { + DROP TABLE t2; + DROP TABLE t1; + } +} {} +do_test fkey-2.14.3.8 { + execsql { + CREATE TABLE pp(x, y, PRIMARY KEY(x, y)); + CREATE TABLE cc(a, b, FOREIGN KEY(a, b) REFERENCES pp(x, z)); + } + catchsql { INSERT INTO cc VALUES(1, 2) } +} {1 {foreign key mismatch - "cc" referencing "pp"}} +do_test fkey-2.14.3.9 { + execsql { DROP TABLE cc } +} {} +do_test fkey-2.14.3.10 { + execsql { + CREATE TABLE cc(a, b, + FOREIGN KEY(a, b) REFERENCES pp DEFERRABLE INITIALLY DEFERRED + ); + } + execsql { + INSERT INTO pp VALUES('a', 'b'); + INSERT INTO cc VALUES('a', 'b'); + BEGIN; + DROP TABLE pp; + CREATE TABLE pp(a, b, c, PRIMARY KEY(b, c)); + INSERT INTO pp VALUES(1, 'a', 'b'); + COMMIT; + } +} {} +do_test fkey-2.14.3.11 { + execsql { + BEGIN; + DROP TABLE cc; + DROP TABLE pp; + COMMIT; + } +} {} +do_test fkey-2.14.3.12 { + execsql { + CREATE TABLE b1(a, b); + CREATE TABLE b2(a, b REFERENCES b1); + DROP TABLE b1; + } +} {} +do_test fkey-2.14.3.13 { + execsql { + CREATE TABLE b3(a, b REFERENCES b2 DEFERRABLE INITIALLY DEFERRED); + DROP TABLE b2; + } +} {} + +# Test that nothing goes wrong when dropping a table that refers to a view. +# Or dropping a view that an existing FK (incorrectly) refers to. Or either +# of the above scenarios with a virtual table. +drop_all_tables +do_test fkey-2.14.4.1 { + execsql { + CREATE TABLE t1(x REFERENCES v); + CREATE VIEW v AS SELECT * FROM t1; + } +} {} +do_test fkey-2.14.4.2 { + execsql { + DROP VIEW v; + } +} {} +ifcapable vtab { + register_echo_module db + do_test fkey-2.14.4.3 { + execsql { CREATE VIRTUAL TABLE v USING echo(t1) } + } {} + do_test fkey-2.14.4.2 { + execsql { + DROP TABLE v; + } + } {} +} + +#------------------------------------------------------------------------- +# The following tests, fkey2-15.*, test that unnecessary FK related scans +# and lookups are avoided when the constraint counters are zero. +# +drop_all_tables +proc execsqlS {zSql} { + set ::sqlite_search_count 0 + set ::sqlite_found_count 0 + set res [uplevel [list execsql $zSql]] + concat [expr $::sqlite_found_count + $::sqlite_search_count] $res +} +do_test fkey2-15.1.1 { + execsql { + CREATE TABLE pp(a PRIMARY KEY, b); + CREATE TABLE cc(x, y REFERENCES pp DEFERRABLE INITIALLY DEFERRED); + INSERT INTO pp VALUES(1, 'one'); + INSERT INTO pp VALUES(2, 'two'); + INSERT INTO cc VALUES('neung', 1); + INSERT INTO cc VALUES('song', 2); + } +} {} +do_test fkey2-15.1.2 { + execsqlS { INSERT INTO pp VALUES(3, 'three') } +} {0} +do_test fkey2-15.1.3 { + execsql { + BEGIN; + INSERT INTO cc VALUES('see', 4); -- Violates deferred constraint + } + execsqlS { INSERT INTO pp VALUES(5, 'five') } +} {2} +do_test fkey2-15.1.4 { + execsql { DELETE FROM cc WHERE x = 'see' } + execsqlS { INSERT INTO pp VALUES(6, 'six') } +} {0} +do_test fkey2-15.1.5 { + execsql COMMIT +} {} +do_test fkey2-15.1.6 { + execsql BEGIN + execsqlS { + DELETE FROM cc WHERE x = 'neung'; + ROLLBACK; + } +} {1} +do_test fkey2-15.1.7 { + execsql { + BEGIN; + DELETE FROM pp WHERE a = 2; + } + execsqlS { + DELETE FROM cc WHERE x = 'neung'; + ROLLBACK; + } +} {2} + +#------------------------------------------------------------------------- +# This next block of tests, fkey2-16.*, test that rows that refer to +# themselves may be inserted and deleted. +# +foreach {tn zSchema} { + 1 { CREATE TABLE self(a INTEGER PRIMARY KEY, b REFERENCES self(a)) } + 2 { CREATE TABLE self(a PRIMARY KEY, b REFERENCES self(a)) } + 3 { CREATE TABLE self(a UNIQUE, b INTEGER PRIMARY KEY REFERENCES self(a)) } +} { + drop_all_tables + do_test fkey2-16.1.$tn.1 { + execsql $zSchema + execsql { INSERT INTO self VALUES(13, 13) } + } {} + do_test fkey2-16.1.$tn.2 { + execsql { UPDATE self SET a = 14, b = 14 } + } {} + + do_test fkey2-16.1.$tn.3 { + catchsql { UPDATE self SET b = 15 } + } {1 {FOREIGN KEY constraint failed}} + + do_test fkey2-16.1.$tn.4 { + catchsql { UPDATE self SET a = 15 } + } {1 {FOREIGN KEY constraint failed}} + + do_test fkey2-16.1.$tn.5 { + catchsql { UPDATE self SET a = 15, b = 16 } + } {1 {FOREIGN KEY constraint failed}} + + do_test fkey2-16.1.$tn.6 { + catchsql { UPDATE self SET a = 17, b = 17 } + } {0 {}} + + do_test fkey2-16.1.$tn.7 { + execsql { DELETE FROM self } + } {} + do_test fkey2-16.1.$tn.8 { + catchsql { INSERT INTO self VALUES(20, 21) } + } {1 {FOREIGN KEY constraint failed}} +} + +#------------------------------------------------------------------------- +# This next block of tests, fkey2-17.*, tests that if "PRAGMA count_changes" +# is turned on statements that violate immediate FK constraints return +# SQLITE_CONSTRAINT immediately, not after returning a number of rows. +# Whereas statements that violate deferred FK constraints return the number +# of rows before failing. +# +# Also test that rows modified by FK actions are not counted in either the +# returned row count or the values returned by sqlite3_changes(). Like +# trigger related changes, they are included in sqlite3_total_changes() though. +# +drop_all_tables +do_test fkey2-17.1.1 { + execsql { PRAGMA count_changes = 1 } + execsql { + CREATE TABLE one(a, b, c, UNIQUE(b, c)); + CREATE TABLE two(d, e, f, FOREIGN KEY(e, f) REFERENCES one(b, c)); + INSERT INTO one VALUES(1, 2, 3); + } +} {1} +do_test fkey2-17.1.2 { + set STMT [sqlite3_prepare_v2 db "INSERT INTO two VALUES(4, 5, 6)" -1 dummy] + sqlite3_step $STMT +} {SQLITE_CONSTRAINT} +verify_ex_errcode fkey2-17.1.2b SQLITE_CONSTRAINT_FOREIGNKEY +ifcapable autoreset { + do_test fkey2-17.1.3 { + sqlite3_step $STMT + } {SQLITE_CONSTRAINT} + verify_ex_errcode fkey2-17.1.3b SQLITE_CONSTRAINT_FOREIGNKEY +} else { + do_test fkey2-17.1.3 { + sqlite3_step $STMT + } {SQLITE_MISUSE} +} +do_test fkey2-17.1.4 { + sqlite3_finalize $STMT +} {SQLITE_CONSTRAINT} +verify_ex_errcode fkey2-17.1.4b SQLITE_CONSTRAINT_FOREIGNKEY +do_test fkey2-17.1.5 { + execsql { + INSERT INTO one VALUES(2, 3, 4); + INSERT INTO one VALUES(3, 4, 5); + INSERT INTO two VALUES(1, 2, 3); + INSERT INTO two VALUES(2, 3, 4); + INSERT INTO two VALUES(3, 4, 5); + } +} {1 1 1 1 1} +do_test fkey2-17.1.6 { + catchsql { + BEGIN; + INSERT INTO one VALUES(0, 0, 0); + UPDATE two SET e=e+1, f=f+1; + } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-17.1.7 { + execsql { SELECT * FROM one } +} {1 2 3 2 3 4 3 4 5 0 0 0} +do_test fkey2-17.1.8 { + execsql { SELECT * FROM two } +} {1 2 3 2 3 4 3 4 5} +do_test fkey2-17.1.9 { + execsql COMMIT +} {} +do_test fkey2-17.1.10 { + execsql { + CREATE TABLE three( + g, h, i, + FOREIGN KEY(h, i) REFERENCES one(b, c) DEFERRABLE INITIALLY DEFERRED + ); + } +} {} +do_test fkey2-17.1.11 { + set STMT [sqlite3_prepare_v2 db "INSERT INTO three VALUES(7, 8, 9)" -1 dummy] + sqlite3_step $STMT +} {SQLITE_ROW} +do_test fkey2-17.1.12 { + sqlite3_column_text $STMT 0 +} {1} +do_test fkey2-17.1.13 { + sqlite3_step $STMT +} {SQLITE_CONSTRAINT} +verify_ex_errcode fkey2-17.1.13b SQLITE_CONSTRAINT_FOREIGNKEY +do_test fkey2-17.1.14 { + sqlite3_finalize $STMT +} {SQLITE_CONSTRAINT} +verify_ex_errcode fkey2-17.1.14b SQLITE_CONSTRAINT_FOREIGNKEY + +drop_all_tables +do_test fkey2-17.2.1 { + execsql { + CREATE TABLE high("a'b!" PRIMARY KEY, b); + CREATE TABLE low( + c, + "d&6" REFERENCES high ON UPDATE CASCADE ON DELETE CASCADE + ); + } +} {} +do_test fkey2-17.2.2 { + execsql { + INSERT INTO high VALUES('a', 'b'); + INSERT INTO low VALUES('b', 'a'); + } + db changes +} {1} +set nTotal [db total_changes] +do_test fkey2-17.2.3 { + execsql { UPDATE high SET "a'b!" = 'c' } +} {1} +do_test fkey2-17.2.4 { + db changes +} {1} +do_test fkey2-17.2.5 { + expr [db total_changes] - $nTotal +} {2} +do_test fkey2-17.2.6 { + execsql { SELECT * FROM high ; SELECT * FROM low } +} {c b b c} +do_test fkey2-17.2.7 { + execsql { DELETE FROM high } +} {1} +do_test fkey2-17.2.8 { + db changes +} {1} +do_test fkey2-17.2.9 { + expr [db total_changes] - $nTotal +} {4} +do_test fkey2-17.2.10 { + execsql { SELECT * FROM high ; SELECT * FROM low } +} {} +execsql { PRAGMA count_changes = 0 } + +#------------------------------------------------------------------------- +# Test that the authorization callback works. +# + +ifcapable auth { + do_test fkey2-18.1 { + execsql { + CREATE TABLE long(a, b PRIMARY KEY, c); + CREATE TABLE short(d, e, f REFERENCES long); + CREATE TABLE mid(g, h, i REFERENCES long DEFERRABLE INITIALLY DEFERRED); + } + } {} + + proc auth {args} {eval lappend ::authargs [lrange $args 0 4]; return SQLITE_OK} + db auth auth + + # An insert on the parent table must read the child key of any deferred + # foreign key constraints. But not the child key of immediate constraints. + set authargs {} + do_test fkey2-18.2 { + execsql { INSERT INTO long VALUES(1, 2, 3) } + set authargs + } {SQLITE_INSERT long {} main {} SQLITE_READ mid i main {}} + + # An insert on the child table of an immediate constraint must read the + # parent key columns (to see if it is a violation or not). + set authargs {} + do_test fkey2-18.3 { + execsql { INSERT INTO short VALUES(1, 3, 2) } + set authargs + } {SQLITE_INSERT short {} main {} SQLITE_READ long b main {}} + + # As must an insert on the child table of a deferred constraint. + set authargs {} + do_test fkey2-18.4 { + execsql { INSERT INTO mid VALUES(1, 3, 2) } + set authargs + } {SQLITE_INSERT mid {} main {} SQLITE_READ long b main {}} + + do_test fkey2-18.5 { + execsql { + CREATE TABLE nought(a, b PRIMARY KEY, c); + CREATE TABLE cross(d, e, f, + FOREIGN KEY(e) REFERENCES nought(b) ON UPDATE CASCADE + ); + } + execsql { INSERT INTO nought VALUES(2, 1, 2) } + execsql { INSERT INTO cross VALUES(0, 1, 0) } + set authargs [list] + execsql { UPDATE nought SET b = 5 } + set authargs + } {SQLITE_UPDATE nought b main {} SQLITE_READ cross e main {} SQLITE_READ cross e main {} SQLITE_READ nought b main {} SQLITE_READ nought b main {} SQLITE_READ nought b main {} SQLITE_UPDATE cross e main {} SQLITE_READ nought b main {} SQLITE_READ cross e main {} SQLITE_READ nought b main {} SQLITE_READ nought b main {}} + + do_test fkey2-18.6 { + execsql {SELECT * FROM cross} + } {0 5 0} + + do_test fkey2-18.7 { + execsql { + CREATE TABLE one(a INTEGER PRIMARY KEY, b); + CREATE TABLE two(b, c REFERENCES one); + INSERT INTO one VALUES(101, 102); + } + set authargs [list] + execsql { INSERT INTO two VALUES(100, 101); } + set authargs + } {SQLITE_INSERT two {} main {} SQLITE_READ one a main {}} + + # Return SQLITE_IGNORE to requests to read from the parent table. This + # causes inserts of non-NULL keys into the child table to fail. + # + rename auth {} + proc auth {args} { + if {[lindex $args 1] == "long"} {return SQLITE_IGNORE} + return SQLITE_OK + } + do_test fkey2-18.8 { + catchsql { INSERT INTO short VALUES(1, 3, 2) } + } {1 {FOREIGN KEY constraint failed}} + do_test fkey2-18.9 { + execsql { INSERT INTO short VALUES(1, 3, NULL) } + } {} + do_test fkey2-18.10 { + execsql { SELECT * FROM short } + } {1 3 2 1 3 {}} + do_test fkey2-18.11 { + catchsql { UPDATE short SET f = 2 WHERE f IS NULL } + } {1 {FOREIGN KEY constraint failed}} + + db auth {} + unset authargs +} + + +do_test fkey2-19.1 { + execsql { + CREATE TABLE main(id INTEGER PRIMARY KEY); + CREATE TABLE sub(id INT REFERENCES main(id)); + INSERT INTO main VALUES(1); + INSERT INTO main VALUES(2); + INSERT INTO sub VALUES(2); + } +} {} +do_test fkey2-19.2 { + set S [sqlite3_prepare_v2 db "DELETE FROM main WHERE id = ?" -1 dummy] + sqlite3_bind_int $S 1 2 + sqlite3_step $S +} {SQLITE_CONSTRAINT} +verify_ex_errcode fkey2-19.2b SQLITE_CONSTRAINT_FOREIGNKEY +do_test fkey2-19.3 { + sqlite3_reset $S +} {SQLITE_CONSTRAINT} +verify_ex_errcode fkey2-19.3b SQLITE_CONSTRAINT_FOREIGNKEY +do_test fkey2-19.4 { + sqlite3_bind_int $S 1 1 + sqlite3_step $S +} {SQLITE_DONE} +do_test fkey2-19.4 { + sqlite3_finalize $S +} {SQLITE_OK} + +drop_all_tables +do_test fkey2-20.1 { + execsql { + CREATE TABLE pp(a PRIMARY KEY, b); + CREATE TABLE cc(c PRIMARY KEY, d REFERENCES pp); + } +} {} + +foreach {tn insert} { + 1 "INSERT" + 2 "INSERT OR IGNORE" + 3 "INSERT OR ABORT" + 4 "INSERT OR ROLLBACK" + 5 "INSERT OR REPLACE" + 6 "INSERT OR FAIL" +} { + do_test fkey2-20.2.$tn.1 { + catchsql "$insert INTO cc VALUES(1, 2)" + } {1 {FOREIGN KEY constraint failed}} + do_test fkey2-20.2.$tn.2 { + execsql { SELECT * FROM cc } + } {} + do_test fkey2-20.2.$tn.3 { + execsql { + BEGIN; + INSERT INTO pp VALUES(2, 'two'); + INSERT INTO cc VALUES(1, 2); + } + catchsql "$insert INTO cc VALUES(3, 4)" + } {1 {FOREIGN KEY constraint failed}} + do_test fkey2-20.2.$tn.4 { + execsql { COMMIT ; SELECT * FROM cc } + } {1 2} + do_test fkey2-20.2.$tn.5 { + execsql { DELETE FROM cc ; DELETE FROM pp } + } {} +} + +foreach {tn update} { + 1 "UPDATE" + 2 "UPDATE OR IGNORE" + 3 "UPDATE OR ABORT" + 4 "UPDATE OR ROLLBACK" + 5 "UPDATE OR REPLACE" + 6 "UPDATE OR FAIL" +} { + do_test fkey2-20.3.$tn.1 { + execsql { + INSERT INTO pp VALUES(2, 'two'); + INSERT INTO cc VALUES(1, 2); + } + } {} + do_test fkey2-20.3.$tn.2 { + catchsql "$update pp SET a = 1" + } {1 {FOREIGN KEY constraint failed}} + do_test fkey2-20.3.$tn.3 { + execsql { SELECT * FROM pp } + } {2 two} + do_test fkey2-20.3.$tn.4 { + catchsql "$update cc SET d = 1" + } {1 {FOREIGN KEY constraint failed}} + do_test fkey2-20.3.$tn.5 { + execsql { SELECT * FROM cc } + } {1 2} + do_test fkey2-20.3.$tn.6 { + execsql { + BEGIN; + INSERT INTO pp VALUES(3, 'three'); + } + catchsql "$update pp SET a = 1 WHERE a = 2" + } {1 {FOREIGN KEY constraint failed}} + do_test fkey2-20.3.$tn.7 { + execsql { COMMIT ; SELECT * FROM pp } + } {2 two 3 three} + do_test fkey2-20.3.$tn.8 { + execsql { + BEGIN; + INSERT INTO cc VALUES(2, 2); + } + catchsql "$update cc SET d = 1 WHERE c = 1" + } {1 {FOREIGN KEY constraint failed}} + do_test fkey2-20.3.$tn.9 { + execsql { COMMIT ; SELECT * FROM cc } + } {1 2 2 2} + do_test fkey2-20.3.$tn.10 { + execsql { DELETE FROM cc ; DELETE FROM pp } + } {} +} + +#------------------------------------------------------------------------- +# The following block of tests, those prefixed with "fkey2-genfkey.", are +# the same tests that were used to test the ".genfkey" command provided +# by the shell tool. So these tests show that the built-in foreign key +# implementation is more or less compatible with the triggers generated +# by genfkey. +# +drop_all_tables +do_test fkey2-genfkey.1.1 { + execsql { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, UNIQUE(b, c)); + CREATE TABLE t2(e REFERENCES t1, f); + CREATE TABLE t3(g, h, i, FOREIGN KEY (h, i) REFERENCES t1(b, c)); + } +} {} +do_test fkey2-genfkey.1.2 { + catchsql { INSERT INTO t2 VALUES(1, 2) } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-genfkey.1.3 { + execsql { + INSERT INTO t1 VALUES(1, 2, 3); + INSERT INTO t2 VALUES(1, 2); + } +} {} +do_test fkey2-genfkey.1.4 { + execsql { INSERT INTO t2 VALUES(NULL, 3) } +} {} +do_test fkey2-genfkey.1.5 { + catchsql { UPDATE t2 SET e = 5 WHERE e IS NULL } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-genfkey.1.6 { + execsql { UPDATE t2 SET e = 1 WHERE e IS NULL } +} {} +do_test fkey2-genfkey.1.7 { + execsql { UPDATE t2 SET e = NULL WHERE f = 3 } +} {} +do_test fkey2-genfkey.1.8 { + catchsql { UPDATE t1 SET a = 10 } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-genfkey.1.9 { + catchsql { UPDATE t1 SET a = NULL } +} {1 {datatype mismatch}} +do_test fkey2-genfkey.1.10 { + catchsql { DELETE FROM t1 } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-genfkey.1.11 { + execsql { UPDATE t2 SET e = NULL } +} {} +do_test fkey2-genfkey.1.12 { + execsql { + UPDATE t1 SET a = 10; + DELETE FROM t1; + DELETE FROM t2; + } +} {} +do_test fkey2-genfkey.1.13 { + execsql { + INSERT INTO t3 VALUES(1, NULL, NULL); + INSERT INTO t3 VALUES(1, 2, NULL); + INSERT INTO t3 VALUES(1, NULL, 3); + } +} {} +do_test fkey2-genfkey.1.14 { + catchsql { INSERT INTO t3 VALUES(3, 1, 4) } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-genfkey.1.15 { + execsql { + INSERT INTO t1 VALUES(1, 1, 4); + INSERT INTO t3 VALUES(3, 1, 4); + } +} {} +do_test fkey2-genfkey.1.16 { + catchsql { DELETE FROM t1 } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-genfkey.1.17 { + catchsql { UPDATE t1 SET b = 10} +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-genfkey.1.18 { + execsql { UPDATE t1 SET a = 10} +} {} +do_test fkey2-genfkey.1.19 { + catchsql { UPDATE t3 SET h = 'hello' WHERE i = 3} +} {1 {FOREIGN KEY constraint failed}} + +drop_all_tables +do_test fkey2-genfkey.2.1 { + execsql { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, UNIQUE(b, c)); + CREATE TABLE t2(e REFERENCES t1 ON UPDATE CASCADE ON DELETE CASCADE, f); + CREATE TABLE t3(g, h, i, + FOREIGN KEY (h, i) + REFERENCES t1(b, c) ON UPDATE CASCADE ON DELETE CASCADE + ); + } +} {} +do_test fkey2-genfkey.2.2 { + execsql { + INSERT INTO t1 VALUES(1, 2, 3); + INSERT INTO t1 VALUES(4, 5, 6); + INSERT INTO t2 VALUES(1, 'one'); + INSERT INTO t2 VALUES(4, 'four'); + } +} {} +do_test fkey2-genfkey.2.3 { + execsql { + UPDATE t1 SET a = 2 WHERE a = 1; + SELECT * FROM t2; + } +} {2 one 4 four} +do_test fkey2-genfkey.2.4 { + execsql { + DELETE FROM t1 WHERE a = 4; + SELECT * FROM t2; + } +} {2 one} + +do_test fkey2-genfkey.2.5 { + execsql { + INSERT INTO t3 VALUES('hello', 2, 3); + UPDATE t1 SET c = 2; + SELECT * FROM t3; + } +} {hello 2 2} +do_test fkey2-genfkey.2.6 { + execsql { + DELETE FROM t1; + SELECT * FROM t3; + } +} {} + +drop_all_tables +do_test fkey2-genfkey.3.1 { + execsql { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, UNIQUE(c, b)); + CREATE TABLE t2(e REFERENCES t1 ON UPDATE SET NULL ON DELETE SET NULL, f); + CREATE TABLE t3(g, h, i, + FOREIGN KEY (h, i) + REFERENCES t1(b, c) ON UPDATE SET NULL ON DELETE SET NULL + ); + } +} {} +do_test fkey2-genfkey.3.2 { + execsql { + INSERT INTO t1 VALUES(1, 2, 3); + INSERT INTO t1 VALUES(4, 5, 6); + INSERT INTO t2 VALUES(1, 'one'); + INSERT INTO t2 VALUES(4, 'four'); + } +} {} +do_test fkey2-genfkey.3.3 { + execsql { + UPDATE t1 SET a = 2 WHERE a = 1; + SELECT * FROM t2; + } +} {{} one 4 four} +do_test fkey2-genfkey.3.4 { + execsql { + DELETE FROM t1 WHERE a = 4; + SELECT * FROM t2; + } +} {{} one {} four} +do_test fkey2-genfkey.3.5 { + execsql { + INSERT INTO t3 VALUES('hello', 2, 3); + UPDATE t1 SET c = 2; + SELECT * FROM t3; + } +} {hello {} {}} +do_test fkey2-genfkey.3.6 { + execsql { + UPDATE t3 SET h = 2, i = 2; + DELETE FROM t1; + SELECT * FROM t3; + } +} {hello {} {}} + +#------------------------------------------------------------------------- +# Verify that ticket dd08e5a988d00decc4a543daa8dbbfab9c577ad8 has been +# fixed. +# +do_test fkey2-dd08e5.1.1 { + execsql { + PRAGMA foreign_keys=ON; + CREATE TABLE tdd08(a INTEGER PRIMARY KEY, b); + CREATE UNIQUE INDEX idd08 ON tdd08(a,b); + INSERT INTO tdd08 VALUES(200,300); + + CREATE TABLE tdd08_b(w,x,y, FOREIGN KEY(x,y) REFERENCES tdd08(a,b)); + INSERT INTO tdd08_b VALUES(100,200,300); + } +} {} +do_test fkey2-dd08e5.1.2 { + catchsql { + DELETE FROM tdd08; + } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-dd08e5.1.3 { + execsql { + SELECT * FROM tdd08; + } +} {200 300} +do_test fkey2-dd08e5.1.4 { + catchsql { + INSERT INTO tdd08_b VALUES(400,500,300); + } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-dd08e5.1.5 { + catchsql { + UPDATE tdd08_b SET x=x+1; + } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-dd08e5.1.6 { + catchsql { + UPDATE tdd08 SET a=a+1; + } +} {1 {FOREIGN KEY constraint failed}} + +#------------------------------------------------------------------------- +# Verify that ticket ce7c133ea6cc9ccdc1a60d80441f80b6180f5eba +# fixed. +# +do_test fkey2-ce7c13.1.1 { + execsql { + CREATE TABLE tce71(a INTEGER PRIMARY KEY, b); + CREATE UNIQUE INDEX ice71 ON tce71(a,b); + INSERT INTO tce71 VALUES(100,200); + CREATE TABLE tce72(w, x, y, FOREIGN KEY(x,y) REFERENCES tce71(a,b)); + INSERT INTO tce72 VALUES(300,100,200); + UPDATE tce71 set b = 200 where a = 100; + SELECT * FROM tce71, tce72; + } +} {100 200 300 100 200} +do_test fkey2-ce7c13.1.2 { + catchsql { + UPDATE tce71 set b = 201 where a = 100; + } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-ce7c13.1.3 { + catchsql { + UPDATE tce71 set a = 101 where a = 100; + } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-ce7c13.1.4 { + execsql { + CREATE TABLE tce73(a INTEGER PRIMARY KEY, b, UNIQUE(a,b)); + INSERT INTO tce73 VALUES(100,200); + CREATE TABLE tce74(w, x, y, FOREIGN KEY(x,y) REFERENCES tce73(a,b)); + INSERT INTO tce74 VALUES(300,100,200); + UPDATE tce73 set b = 200 where a = 100; + SELECT * FROM tce73, tce74; + } +} {100 200 300 100 200} +do_test fkey2-ce7c13.1.5 { + catchsql { + UPDATE tce73 set b = 201 where a = 100; + } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-ce7c13.1.6 { + catchsql { + UPDATE tce73 set a = 101 where a = 100; + } +} {1 {FOREIGN KEY constraint failed}} + +# 2015-04-16: Foreign key errors propagate back up to the parser. +# +do_test fkey2-20150416-100 { + db close + sqlite3 db :memory: + catchsql { + PRAGMA foreign_keys=1; + CREATE TABLE t1(x PRIMARY KEY); + CREATE TABLE t(y REFERENCES t0(x)ON DELETE SET DEFAULT); + CREATE TABLE t0(y REFERENCES t1 ON DELETE SET NULL); + REPLACE INTO t1 SELECT(0);CREATE TABLE t2(x);CREATE TABLE t3; + } +} {1 {foreign key mismatch - "t" referencing "t0"}} + +finish_test diff --git a/test/fkey3.test b/test/fkey3.test new file mode 100644 index 0000000..a8d0382 --- /dev/null +++ b/test/fkey3.test @@ -0,0 +1,186 @@ +# 2009 September 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests for foreign keys. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable {!foreignkey||!trigger} { + finish_test + return +} + +set testprefix fkey3 + +# Create a table and some data to work with. +# +do_test fkey3-1.1 { + execsql { + PRAGMA foreign_keys=ON; + CREATE TABLE t1(x INTEGER PRIMARY KEY); + INSERT INTO t1 VALUES(100); + INSERT INTO t1 VALUES(101); + CREATE TABLE t2(y INTEGER REFERENCES t1 (x)); + INSERT INTO t2 VALUES(100); + INSERT INTO t2 VALUES(101); + SELECT 1, x FROM t1; + SELECT 2, y FROM t2; + } +} {1 100 1 101 2 100 2 101} + +do_test fkey3-1.2 { + catchsql { + DELETE FROM t1 WHERE x=100; + } +} {1 {FOREIGN KEY constraint failed}} + +do_test fkey3-1.3 { + catchsql { + DROP TABLE t1; + } +} {1 {FOREIGN KEY constraint failed}} + +do_test fkey3-1.4 { + execsql { + DROP TABLE t2; + } +} {} + +do_test fkey3-1.5 { + execsql { + DROP TABLE t1; + } +} {} + +do_test fkey3-2.1 { + execsql { + PRAGMA foreign_keys=ON; + CREATE TABLE t1(x INTEGER PRIMARY KEY); + INSERT INTO t1 VALUES(100); + INSERT INTO t1 VALUES(101); + CREATE TABLE t2(y INTEGER PRIMARY KEY REFERENCES t1 (x) ON UPDATE SET NULL); + } + execsql { + INSERT INTO t2 VALUES(100); + INSERT INTO t2 VALUES(101); + SELECT 1, x FROM t1; + SELECT 2, y FROM t2; + } +} {1 100 1 101 2 100 2 101} + + +#------------------------------------------------------------------------- +# The following tests - fkey-3.* - test some edge cases to do with +# inserting rows into tables that have foreign keys where the parent +# table is the same as the child table. Especially cases where the +# new row being inserted matches itself. +# +do_execsql_test 3.1.1 { + CREATE TABLE t3(a, b, c, d, + UNIQUE(a, b), + FOREIGN KEY(c, d) REFERENCES t3(a, b) + ); + INSERT INTO t3 VALUES(1, 2, 1, 2); +} {} +do_catchsql_test 3.1.2 { + INSERT INTO t3 VALUES(NULL, 2, 5, 2); +} {1 {FOREIGN KEY constraint failed}} +do_catchsql_test 3.1.3 { + INSERT INTO t3 VALUES(NULL, 3, 5, 2); +} {1 {FOREIGN KEY constraint failed}} + +do_execsql_test 3.2.1 { + CREATE TABLE t4(a UNIQUE, b REFERENCES t4(a)); +} +do_catchsql_test 3.2.2 { + INSERT INTO t4 VALUES(NULL, 1); +} {1 {FOREIGN KEY constraint failed}} + +do_execsql_test 3.3.1 { + CREATE TABLE t5(a INTEGER PRIMARY KEY, b REFERENCES t5(a)); + INSERT INTO t5 VALUES(NULL, 1); +} {} +do_catchsql_test 3.3.2 { + INSERT INTO t5 VALUES(NULL, 3); +} {1 {FOREIGN KEY constraint failed}} + +do_execsql_test 3.4.1 { + CREATE TABLE t6(a INTEGER PRIMARY KEY, b, c, d, + FOREIGN KEY(c, d) REFERENCES t6(a, b) + ); + CREATE UNIQUE INDEX t6i ON t6(b, a); +} +do_execsql_test 3.4.2 { INSERT INTO t6 VALUES(NULL, 'a', 1, 'a'); } {} +do_execsql_test 3.4.3 { INSERT INTO t6 VALUES(2, 'a', 2, 'a'); } {} +do_execsql_test 3.4.4 { INSERT INTO t6 VALUES(NULL, 'a', 1, 'a'); } {} +do_execsql_test 3.4.5 { INSERT INTO t6 VALUES(5, 'a', 2, 'a'); } {} +do_catchsql_test 3.4.6 { + INSERT INTO t6 VALUES(NULL, 'a', 65, 'a'); +} {1 {FOREIGN KEY constraint failed}} + +do_execsql_test 3.4.7 { + INSERT INTO t6 VALUES(100, 'one', 100, 'one'); + DELETE FROM t6 WHERE a = 100; +} +do_execsql_test 3.4.8 { + INSERT INTO t6 VALUES(100, 'one', 100, 'one'); + UPDATE t6 SET c = 1, d = 'a' WHERE a = 100; + DELETE FROM t6 WHERE a = 100; +} + +do_execsql_test 3.5.1 { + CREATE TABLE t7(a, b, c, d INTEGER PRIMARY KEY, + FOREIGN KEY(c, d) REFERENCES t7(a, b) + ); + CREATE UNIQUE INDEX t7i ON t7(a, b); +} +do_execsql_test 3.5.2 { INSERT INTO t7 VALUES('x', 1, 'x', NULL) } {} +do_execsql_test 3.5.3 { INSERT INTO t7 VALUES('x', 2, 'x', 2) } {} +do_catchsql_test 3.5.4 { + INSERT INTO t7 VALUES('x', 450, 'x', NULL); +} {1 {FOREIGN KEY constraint failed}} +do_catchsql_test 3.5.5 { + INSERT INTO t7 VALUES('x', 450, 'x', 451); +} {1 {FOREIGN KEY constraint failed}} + + +do_execsql_test 3.6.1 { + CREATE TABLE t8(a, b, c, d, e, FOREIGN KEY(c, d) REFERENCES t8(a, b)); + CREATE UNIQUE INDEX t8i1 ON t8(a, b); + CREATE UNIQUE INDEX t8i2 ON t8(c); + INSERT INTO t8 VALUES(1, 1, 1, 1, 1); +} +do_catchsql_test 3.6.2 { + UPDATE t8 SET d = 2; +} {1 {FOREIGN KEY constraint failed}} +do_execsql_test 3.6.3 { UPDATE t8 SET d = 1; } +do_execsql_test 3.6.4 { UPDATE t8 SET e = 2; } + +do_catchsql_test 3.6.5 { + CREATE TABLE TestTable ( + id INTEGER PRIMARY KEY, + name text, + source_id integer not null, + parent_id integer, + + foreign key(source_id, parent_id) references TestTable(source_id, id) + ); + CREATE UNIQUE INDEX testindex on TestTable(source_id, id); + PRAGMA foreign_keys=1; + INSERT INTO TestTable VALUES (1, 'parent', 1, null); + INSERT INTO TestTable VALUES (2, 'child', 1, 1); + UPDATE TestTable SET parent_id=1000 where id=2; +} {1 {FOREIGN KEY constraint failed}} + +finish_test diff --git a/test/fkey4.test b/test/fkey4.test new file mode 100644 index 0000000..79cf663 --- /dev/null +++ b/test/fkey4.test @@ -0,0 +1,57 @@ +# 2011 Feb 04 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file test deferred foreign key constraint processing to make +# sure that when a statement not within BEGIN...END fails a constraint, +# that statement doesn't hold the transaction open thus allowing +# a subsequent statement to fail a deferred constraint with impunity. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable {!foreignkey||!trigger} { + finish_test + return +} + +# Create a table and some data to work with. +# +do_test fkey4-1.1 { + execsql { + PRAGMA foreign_keys = ON; + CREATE TABLE t1(a PRIMARY KEY, b); + CREATE TABLE t2(c REFERENCES t1 DEFERRABLE INITIALLY DEFERRED, d); + INSERT INTO t1 VALUES(1,2); + INSERT INTO t2 VALUES(1,3); + } +} {} + +do_test fkey4-1.2 { + set ::DB [sqlite3_connection_pointer db] + set ::SQL {INSERT INTO t2 VALUES(2,4)} + set ::STMT1 [sqlite3_prepare_v2 $::DB $::SQL -1 TAIL] + sqlite3_step $::STMT1 +} {SQLITE_CONSTRAINT} +verify_ex_errcode fkey4-1.2b SQLITE_CONSTRAINT_FOREIGNKEY +do_test fkey4-1.3 { + set ::STMT2 [sqlite3_prepare_v2 $::DB $::SQL -1 TAIL] + sqlite3_step $::STMT2 +} {SQLITE_CONSTRAINT} +verify_ex_errcode fkey4-1.3b SQLITE_CONSTRAINT_FOREIGNKEY +do_test fkey4-1.4 { + db eval {SELECT * FROM t2} +} {1 3} +sqlite3_finalize $::STMT1 +sqlite3_finalize $::STMT2 + +finish_test diff --git a/test/fkey5.test b/test/fkey5.test new file mode 100644 index 0000000..d467a64 --- /dev/null +++ b/test/fkey5.test @@ -0,0 +1,492 @@ +# 2012 December 17 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file tests the PRAGMA foreign_key_check command. +# +# EVIDENCE-OF: R-15402-03103 PRAGMA schema.foreign_key_check; PRAGMA +# schema.foreign_key_check(table-name); +# +# EVIDENCE-OF: R-41653-15278 The foreign_key_check pragma checks the +# database, or the table called "table-name", for foreign key +# constraints that are violated. The foreign_key_check pragma returns +# one row output for each foreign key violation. + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fkey5 + +ifcapable {!foreignkey} { + finish_test + return +} + +do_test fkey5-1.1 { + db eval { + CREATE TABLE p1(a INTEGER PRIMARY KEY); INSERT INTO p1 VALUES(88),(89); + CREATE TABLE p2(a INT PRIMARY KEY); INSERT INTO p2 VALUES(77),(78); + CREATE TABLE p3(a TEXT PRIMARY KEY); + INSERT INTO p3 VALUES(66),(67),('alpha'),('BRAVO'); + CREATE TABLE p4(a TEXT PRIMARY KEY COLLATE nocase); + INSERT INTO p4 VALUES('alpha'),('BRAVO'),('55'),('Delta'),('ECHO'); + CREATE TABLE p5(a INTEGER PRIMARY KEY, b, c, UNIQUE(b,c)); + INSERT INTO p5 VALUES(1,'Alpha','abc'),(2,'beta','def'); + CREATE TABLE p6(a INTEGER PRIMARY KEY, b TEXT COLLATE nocase, + c TEXT COLLATE rtrim, UNIQUE(b,c)); + INSERT INTO p6 VALUES(1,'Alpha','abc '),(2,'bETA','def '); + + CREATE TABLE c1(x INTEGER PRIMARY KEY references p1); + CREATE TABLE c2(x INTEGER PRIMARY KEY references p2); + CREATE TABLE c3(x INTEGER PRIMARY KEY references p3); + CREATE TABLE c4(x INTEGER PRIMARY KEY references p4); + CREATE TABLE c5(x INT references p1); + CREATE TABLE c6(x INT references p2); + CREATE TABLE c7(x INT references p3); + CREATE TABLE c8(x INT references p4); + CREATE TABLE c9(x TEXT UNIQUE references p1); + CREATE TABLE c10(x TEXT UNIQUE references p2); + CREATE TABLE c11(x TEXT UNIQUE references p3); + CREATE TABLE c12(x TEXT UNIQUE references p4); + CREATE TABLE c13(x TEXT COLLATE nocase references p3); + CREATE TABLE c14(x TEXT COLLATE nocase references p4); + CREATE TABLE c15(x, y, FOREIGN KEY(x,y) REFERENCES p5(b,c)); + CREATE TABLE c16(x, y, FOREIGN KEY(x,y) REFERENCES p5(c,b)); + CREATE TABLE c17(x, y, FOREIGN KEY(x,y) REFERENCES p6(b,c)); + CREATE TABLE c18(x, y, FOREIGN KEY(x,y) REFERENCES p6(c,b)); + CREATE TABLE c19(x TEXT COLLATE nocase, y TEXT COLLATE rtrim, + FOREIGN KEY(x,y) REFERENCES p5(b,c)); + CREATE TABLE c20(x TEXT COLLATE nocase, y TEXT COLLATE rtrim, + FOREIGN KEY(x,y) REFERENCES p5(c,b)); + CREATE TABLE c21(x TEXT COLLATE nocase, y TEXT COLLATE rtrim, + FOREIGN KEY(x,y) REFERENCES p6(b,c)); + CREATE TABLE c22(x TEXT COLLATE nocase, y TEXT COLLATE rtrim, + FOREIGN KEY(x,y) REFERENCES p6(c,b)); + + PRAGMA foreign_key_check; + } +} {} +do_test fkey5-1.2 { + db eval { + INSERT INTO c1 VALUES(90),(87),(88); + PRAGMA foreign_key_check; + } +} {c1 87 p1 0 c1 90 p1 0} +do_test fkey5-1.2b { + db eval { + PRAGMA main.foreign_key_check; + } +} {c1 87 p1 0 c1 90 p1 0} +do_test fkey5-1.2c { + db eval { + PRAGMA temp.foreign_key_check; + } +} {} +do_test fkey5-1.3 { + db eval { + PRAGMA foreign_key_check(c1); + } +} {c1 87 p1 0 c1 90 p1 0} +do_test fkey5-1.4 { + db eval { + PRAGMA foreign_key_check(c2); + } +} {} +do_test fkey5-1.5 { + db eval { + PRAGMA main.foreign_key_check(c2); + } +} {} +do_test fkey5-1.6 { + catchsql { + PRAGMA temp.foreign_key_check(c2); + } +} {1 {no such table: temp.c2}} + +# EVIDENCE-OF: R-45728-08709 There are four columns in each result row. +# +# EVIDENCE-OF: R-55672-01620 The first column is the name of the table +# that contains the REFERENCES clause. +# +# EVIDENCE-OF: R-00471-55166 The second column is the rowid of the row +# that contains the invalid REFERENCES clause, or NULL if the child +# table is a WITHOUT ROWID table. +# +# The second clause in the previous is tested by fkey5-10.3. +# +# EVIDENCE-OF: R-40482-20265 The third column is the name of the table +# that is referred to. +# +# EVIDENCE-OF: R-62839-07969 The fourth column is the index of the +# specific foreign key constraint that failed. +# +do_test fkey5-2.0 { + db eval { + INSERT INTO c5 SELECT x FROM c1; + DELETE FROM c1; + PRAGMA foreign_key_check; + } +} {c5 1 p1 0 c5 3 p1 0} +do_test fkey5-2.1 { + db eval { + PRAGMA foreign_key_check(c5); + } +} {c5 1 p1 0 c5 3 p1 0} +do_test fkey5-2.2 { + db eval { + PRAGMA foreign_key_check(c1); + } +} {} +do_execsql_test fkey5-2.3 { + PRAGMA foreign_key_list(c5); +} {0 0 p1 x {} {NO ACTION} {NO ACTION} NONE} + +do_test fkey5-3.0 { + db eval { + INSERT INTO c9 SELECT x FROM c5; + DELETE FROM c5; + PRAGMA foreign_key_check; + } +} {c9 1 p1 0 c9 3 p1 0} +do_test fkey5-3.1 { + db eval { + PRAGMA foreign_key_check(c9); + } +} {c9 1 p1 0 c9 3 p1 0} +do_test fkey5-3.2 { + db eval { + PRAGMA foreign_key_check(c5); + } +} {} + +do_test fkey5-4.0 { + db eval { + DELETE FROM c9; + INSERT INTO c2 VALUES(79),(77),(76); + PRAGMA foreign_key_check; + } +} {c2 76 p2 0 c2 79 p2 0} +do_test fkey5-4.1 { + db eval { + PRAGMA foreign_key_check(c2); + } +} {c2 76 p2 0 c2 79 p2 0} +do_test fkey5-4.2 { + db eval { + INSERT INTO c6 SELECT x FROM c2; + DELETE FROM c2; + PRAGMA foreign_key_check; + } +} {c6 1 p2 0 c6 3 p2 0} +do_test fkey5-4.3 { + db eval { + PRAGMA foreign_key_check(c6); + } +} {c6 1 p2 0 c6 3 p2 0} +do_test fkey5-4.4 { + db eval { + INSERT INTO c10 SELECT x FROM c6; + DELETE FROM c6; + PRAGMA foreign_key_check; + } +} {c10 1 p2 0 c10 3 p2 0} +do_test fkey5-4.5 { + db eval { + PRAGMA foreign_key_check(c10); + } +} {c10 1 p2 0 c10 3 p2 0} + +do_test fkey5-5.0 { + db eval { + DELETE FROM c10; + INSERT INTO c3 VALUES(68),(67),(65); + PRAGMA foreign_key_check; + } +} {c3 65 p3 0 c3 68 p3 0} +do_test fkey5-5.1 { + db eval { + PRAGMA foreign_key_check(c3); + } +} {c3 65 p3 0 c3 68 p3 0} +do_test fkey5-5.2 { + db eval { + INSERT INTO c7 SELECT x FROM c3; + INSERT INTO c7 VALUES('Alpha'),('alpha'),('foxtrot'); + DELETE FROM c3; + PRAGMA foreign_key_check; + } +} {c7 1 p3 0 c7 3 p3 0 c7 4 p3 0 c7 6 p3 0} +do_test fkey5-5.3 { + db eval { + PRAGMA foreign_key_check(c7); + } +} {c7 1 p3 0 c7 3 p3 0 c7 4 p3 0 c7 6 p3 0} +do_test fkey5-5.4 { + db eval { + INSERT INTO c11 SELECT x FROM c7; + DELETE FROM c7; + PRAGMA foreign_key_check; + } +} {c11 1 p3 0 c11 3 p3 0 c11 4 p3 0 c11 6 p3 0} +do_test fkey5-5.5 { + db eval { + PRAGMA foreign_key_check(c11); + } +} {c11 1 p3 0 c11 3 p3 0 c11 4 p3 0 c11 6 p3 0} + +do_test fkey5-6.0 { + db eval { + DELETE FROM c11; + INSERT INTO c4 VALUES(54),(55),(56); + PRAGMA foreign_key_check; + } +} {c4 54 p4 0 c4 56 p4 0} +do_test fkey5-6.1 { + db eval { + PRAGMA foreign_key_check(c4); + } +} {c4 54 p4 0 c4 56 p4 0} +do_test fkey5-6.2 { + db eval { + INSERT INTO c8 SELECT x FROM c4; + INSERT INTO c8 VALUES('Alpha'),('ALPHA'),('foxtrot'); + DELETE FROM c4; + PRAGMA foreign_key_check; + } +} {c8 1 p4 0 c8 3 p4 0 c8 6 p4 0} +do_test fkey5-6.3 { + db eval { + PRAGMA foreign_key_check(c8); + } +} {c8 1 p4 0 c8 3 p4 0 c8 6 p4 0} +do_test fkey5-6.4 { + db eval { + INSERT INTO c12 SELECT x FROM c8; + DELETE FROM c8; + PRAGMA foreign_key_check; + } +} {c12 1 p4 0 c12 3 p4 0 c12 6 p4 0} +do_test fkey5-6.5 { + db eval { + PRAGMA foreign_key_check(c12); + } +} {c12 1 p4 0 c12 3 p4 0 c12 6 p4 0} + +do_test fkey5-7.1 { + set res {} + db eval { + INSERT OR IGNORE INTO c13 SELECT * FROM c12; + INSERT OR IGNORE INTO C14 SELECT * FROM c12; + DELETE FROM c12; + PRAGMA foreign_key_check; + } { + lappend res [list $table $rowid $fkid $parent] + } + lsort $res +} {{c13 1 0 p3} {c13 2 0 p3} {c13 3 0 p3} {c13 4 0 p3} {c13 5 0 p3} {c13 6 0 p3} {c14 1 0 p4} {c14 3 0 p4} {c14 6 0 p4}} +do_test fkey5-7.2 { + db eval { + PRAGMA foreign_key_check(c14); + } +} {c14 1 p4 0 c14 3 p4 0 c14 6 p4 0} +do_test fkey5-7.3 { + db eval { + PRAGMA foreign_key_check(c13); + } +} {c13 1 p3 0 c13 2 p3 0 c13 3 p3 0 c13 4 p3 0 c13 5 p3 0 c13 6 p3 0} + +do_test fkey5-8.0 { + db eval { + DELETE FROM c13; + DELETE FROM c14; + INSERT INTO c19 VALUES('alpha','abc'); + PRAGMA foreign_key_check(c19); + } +} {c19 1 p5 0} +do_test fkey5-8.1 { + db eval { + DELETE FROM c19; + INSERT INTO c19 VALUES('Alpha','abc'); + PRAGMA foreign_key_check(c19); + } +} {} +do_test fkey5-8.2 { + db eval { + INSERT INTO c20 VALUES('Alpha','abc'); + PRAGMA foreign_key_check(c20); + } +} {c20 1 p5 0} +do_test fkey5-8.3 { + db eval { + DELETE FROM c20; + INSERT INTO c20 VALUES('abc','Alpha'); + PRAGMA foreign_key_check(c20); + } +} {} +do_test fkey5-8.4 { + db eval { + INSERT INTO c21 VALUES('alpha','abc '); + PRAGMA foreign_key_check(c21); + } +} {} +do_test fkey5-8.5 { + db eval { + DELETE FROM c21; + INSERT INTO c19 VALUES('Alpha','abc'); + PRAGMA foreign_key_check(c21); + } +} {} +do_test fkey5-8.6 { + db eval { + INSERT INTO c22 VALUES('Alpha','abc'); + PRAGMA foreign_key_check(c22); + } +} {c22 1 p6 0} +do_test fkey5-8.7 { + db eval { + DELETE FROM c22; + INSERT INTO c22 VALUES('abc ','ALPHA'); + PRAGMA foreign_key_check(c22); + } +} {} + + +#------------------------------------------------------------------------- +# Tests 9.* verify that missing parent tables are handled correctly. +# +do_execsql_test 9.1.1 { + CREATE TABLE k1(x REFERENCES s1); + PRAGMA foreign_key_check(k1); +} {} +do_execsql_test 9.1.2 { + INSERT INTO k1 VALUES(NULL); + PRAGMA foreign_key_check(k1); +} {} +do_execsql_test 9.1.3 { + INSERT INTO k1 VALUES(1); + PRAGMA foreign_key_check(k1); +} {k1 2 s1 0} + +do_execsql_test 9.2.1 { + CREATE TABLE k2(x, y, FOREIGN KEY(x, y) REFERENCES s1(a, b)); + PRAGMA foreign_key_check(k2); +} {} +do_execsql_test 9.2 { + INSERT INTO k2 VALUES(NULL, 'five'); + PRAGMA foreign_key_check(k2); +} {} +do_execsql_test 9.3 { + INSERT INTO k2 VALUES('one', NULL); + PRAGMA foreign_key_check(k2); +} {} +do_execsql_test 9.4 { + INSERT INTO k2 VALUES('six', 'seven'); + PRAGMA foreign_key_check(k2); +} {k2 3 s1 0} + +#------------------------------------------------------------------------- +# Test using a WITHOUT ROWID table as the child table with an INTEGER +# PRIMARY KEY as the parent key. +# +reset_db +do_execsql_test 10.1 { + CREATE TABLE p30 (id INTEGER PRIMARY KEY); + CREATE TABLE IF NOT EXISTS c30 ( + line INTEGER, + master REFERENCES p30(id), + PRIMARY KEY(master) + ) WITHOUT ROWID; + + INSERT INTO p30 (id) VALUES (1); + INSERT INTO c30 (master, line) VALUES (1, 999); +} +do_execsql_test 10.2 { + PRAGMA foreign_key_check; +} +# EVIDENCE-OF: R-00471-55166 The second column is the rowid of the row +# that contains the invalid REFERENCES clause, or NULL if the child +# table is a WITHOUT ROWID table. +do_execsql_test 10.3 { + INSERT INTO c30 VALUES(45, 45); + PRAGMA foreign_key_check; +} {c30 {} p30 0} + +#------------------------------------------------------------------------- +# Test "foreign key mismatch" errors. +# +reset_db +do_execsql_test 11.0 { + CREATE TABLE tt(y); + CREATE TABLE c11(x REFERENCES tt(y)); +} +do_catchsql_test 11.1 { + PRAGMA foreign_key_check; +} {1 {foreign key mismatch - "c11" referencing "tt"}} + +# 2020-07-03 Bug in foreign_key_check discovered while working on the +# forum reports that pragma_foreign_key_check does not accept an argument: +# If two separate schemas seem to reference one another, that causes +# problems for foreign_key_check. +# +reset_db +do_execsql_test 12.0 { + ATTACH ':memory:' as aux; + CREATE TABLE aux.t1(a INTEGER PRIMARY KEY, b TEXT REFERENCES t2); + CREATE TABLE main.t2(x TEXT PRIMARY KEY, y INT); + INSERT INTO main.t2 VALUES('abc',11),('def',22),('xyz',99); + INSERT INTO aux.t1 VALUES(5,'abc'),(7,'xyz'),(9,'oops'); + PRAGMA foreign_key_check=t1; +} {t1 5 t2 0 t1 7 t2 0 t1 9 t2 0} +do_execsql_test 12.1 { + CREATE TABLE aux.t2(x TEXT PRIMARY KEY, y INT); + INSERT INTO aux.t2 VALUES('abc',11),('def',22),('xyz',99); + PRAGMA foreign_key_check=t1; +} {t1 9 t2 0} + +# 2020-07-03: the pragma_foreign_key_check virtual table should +# accept arguments for the table name and/or schema name. +# +ifcapable vtab { + do_execsql_test 13.0 { + SELECT *, 'x' FROM pragma_foreign_key_check('t1'); + } {t1 9 t2 0 x} + do_catchsql_test 13.1 { + SELECT *, 'x' FROM pragma_foreign_key_check('t1','main'); + } {1 {no such table: main.t1}} + do_execsql_test 13.2 { + SELECT *, 'x' FROM pragma_foreign_key_check('t1','aux'); + } {t1 9 t2 0 x} +} + +ifcapable vtab { + reset_db + do_execsql_test 13.10 { + PRAGMA foreign_keys=OFF; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT REFERENCES t2); + CREATE TABLE t2(x TEXT PRIMARY KEY, y INT); + CREATE TABLE t3(w TEXT, z INT REFERENCES t1); + INSERT INTO t2 VALUES('abc',11),('def',22),('xyz',99); + INSERT INTO t1 VALUES(5,'abc'),(7,'xyz'),(9,'oops'); + INSERT INTO t3 VALUES(11,7),(22,19); + } {} + do_execsql_test 13.11 { + SELECT x.*, '|' + FROM sqlite_schema, pragma_foreign_key_check(name) AS x + WHERE type='table' + ORDER BY x."table"; + } {t1 9 t2 0 | t3 2 t1 0 |} + do_execsql_test 13.12 { + SELECT *, '|' + FROM pragma_foreign_key_check AS x + ORDER BY x."table"; + } {t1 9 t2 0 | t3 2 t1 0 |} +} + +finish_test diff --git a/test/fkey6.test b/test/fkey6.test new file mode 100644 index 0000000..b658f20 --- /dev/null +++ b/test/fkey6.test @@ -0,0 +1,229 @@ +# 2012 December 17 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file tests the PRAGMA defer_foreign_keys and +# SQLITE_DBSTATUS_DEFERRED_FKS +# +# EVIDENCE-OF: R-18981-16292 When the defer_foreign_keys PRAGMA is on, +# enforcement of all foreign key constraints is delayed until the +# outermost transaction is committed. +# +# EVIDENCE-OF: R-28911-57501 The defer_foreign_keys pragma defaults to +# OFF so that foreign key constraints are only deferred if they are +# created as "DEFERRABLE INITIALLY DEFERRED". + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fkey6 + +ifcapable {!foreignkey} { + finish_test + return +} + +do_execsql_test fkey6-1.0 { + PRAGMA defer_foreign_keys; +} {0} + +do_execsql_test fkey6-1.1 { + PRAGMA foreign_keys=ON; + CREATE TABLE t1(x INTEGER PRIMARY KEY); + CREATE TABLE t2(y INTEGER PRIMARY KEY, + z INTEGER REFERENCES t1(x) DEFERRABLE INITIALLY DEFERRED); + CREATE INDEX t2z ON t2(z); + CREATE TABLE t3(u INTEGER PRIMARY KEY, v INTEGER REFERENCES t1(x)); + CREATE INDEX t3v ON t3(v); + INSERT INTO t1 VALUES(1),(2),(3),(4),(5); + INSERT INTO t2 VALUES(1,1),(2,2); + INSERT INTO t3 VALUES(3,3),(4,4); +} {} +do_test fkey6-1.2 { + catchsql {DELETE FROM t1 WHERE x=2;} +} {1 {FOREIGN KEY constraint failed}} +do_test fkey6-1.3 { + sqlite3_db_status db DBSTATUS_DEFERRED_FKS 0 +} {0 0 0} +do_test fkey6-1.4 { + execsql { + BEGIN; + DELETE FROM t1 WHERE x=1; + } +} {} +do_test fkey6-1.5.1 { + sqlite3_db_status db DBSTATUS_DEFERRED_FKS 1 +} {0 1 0} +do_test fkey6-1.5.2 { + sqlite3_db_status db DBSTATUS_DEFERRED_FKS 0 +} {0 1 0} +do_test fkey6-1.6 { + execsql { + ROLLBACK; + } +} {} +do_test fkey6-1.7 { + sqlite3_db_status db DBSTATUS_DEFERRED_FKS 0 +} {0 0 0} +do_test fkey6-1.8 { + execsql { + PRAGMA defer_foreign_keys=ON; + BEGIN; + DELETE FROM t1 WHERE x=3; + } +} {} +do_test fkey6-1.9 { + sqlite3_db_status db DBSTATUS_DEFERRED_FKS 0 +} {0 1 0} + +# EVIDENCE-OF: R-21752-26913 The defer_foreign_keys pragma is +# automatically switched off at each COMMIT or ROLLBACK. Hence, the +# defer_foreign_keys pragma must be separately enabled for each +# transaction. +do_execsql_test fkey6-1.10.1 { + PRAGMA defer_foreign_keys; + ROLLBACK; + PRAGMA defer_foreign_keys; + BEGIN; + PRAGMA defer_foreign_keys=ON; + PRAGMA defer_foreign_keys; + COMMIT; + PRAGMA defer_foreign_keys; + BEGIN; +} {1 0 1 0} +do_test fkey6-1.10.2 { + catchsql {DELETE FROM t1 WHERE x=3} +} {1 {FOREIGN KEY constraint failed}} +db eval {ROLLBACK} + +do_test fkey6-1.20 { + execsql { + BEGIN; + DELETE FROM t1 WHERE x=1; + } + sqlite3_db_status db DBSTATUS_DEFERRED_FKS 0 +} {0 1 0} +do_test fkey6-1.21 { + execsql { + DELETE FROM t2 WHERE y=1; + } + sqlite3_db_status db DBSTATUS_DEFERRED_FKS 0 +} {0 0 0} +do_test fkey6-1.22 { + execsql { + COMMIT; + } +} {} + +do_execsql_test fkey6-2.1 { + CREATE TABLE p1(a PRIMARY KEY); + INSERT INTO p1 VALUES('one'), ('two'); + CREATE TABLE c1(x REFERENCES p1); + INSERT INTO c1 VALUES('two'), ('one'); +} + +do_execsql_test fkey6-2.2 { + BEGIN; + PRAGMA defer_foreign_keys = 1; + DELETE FROM p1; + ROLLBACK; + PRAGMA defer_foreign_keys; +} {0} + +do_execsql_test fkey6-2.3 { + BEGIN; + PRAGMA defer_foreign_keys = 1; + DROP TABLE p1; + PRAGMA vdbe_trace = 0; + ROLLBACK; + PRAGMA defer_foreign_keys; +} {0} + +do_execsql_test fkey6-2.4 { + BEGIN; + PRAGMA defer_foreign_keys = 1; + DELETE FROM p1; + DROP TABLE c1; + COMMIT; + PRAGMA defer_foreign_keys; +} {0} + +do_execsql_test fkey6-2.5 { + DROP TABLE p1; + CREATE TABLE p1(a PRIMARY KEY); + INSERT INTO p1 VALUES('one'), ('two'); + CREATE TABLE c1(x REFERENCES p1); + INSERT INTO c1 VALUES('two'), ('one'); +} + +do_execsql_test fkey6-2.6 { + BEGIN; + PRAGMA defer_foreign_keys = 1; + INSERT INTO c1 VALUES('three'); + DROP TABLE c1; + COMMIT; + PRAGMA defer_foreign_keys; +} {0} + +#-------------------------------------------------------------------------- +# Test that defer_foreign_keys disables RESTRICT. +# +do_execsql_test 3.1 { + CREATE TABLE p2(a PRIMARY KEY, b); + CREATE TABLE c2(x, y REFERENCES p2 ON DELETE RESTRICT ON UPDATE RESTRICT); + INSERT INTO p2 VALUES(1, 'one'); + INSERT INTO p2 VALUES(2, 'two'); + INSERT INTO c2 VALUES('i', 1); +} + +do_catchsql_test 3.2.1 { + BEGIN; + UPDATE p2 SET a=a-1; +} {1 {FOREIGN KEY constraint failed}} +do_execsql_test 3.2.2 { COMMIT } + +do_execsql_test 3.2.3 { + BEGIN; + PRAGMA defer_foreign_keys = 1; + UPDATE p2 SET a=a-1; + COMMIT; +} + +do_execsql_test 3.2.4 { + BEGIN; + PRAGMA defer_foreign_keys = 1; + UPDATE p2 SET a=a-1; +} +do_catchsql_test 3.2.5 { + COMMIT; +} {1 {FOREIGN KEY constraint failed}} +do_execsql_test 3.2.6 { ROLLBACK } + +do_execsql_test 3.3.1 { + CREATE TRIGGER p2t AFTER DELETE ON p2 BEGIN + INSERT INTO p2 VALUES(old.a, 'deleted!'); + END; +} +do_catchsql_test 3.3.2 { + BEGIN; + DELETE FROM p2 WHERE a=1; +} {1 {FOREIGN KEY constraint failed}} +do_execsql_test 3.3.3 { COMMIT } + +do_execsql_test 3.3.4 { + BEGIN; + PRAGMA defer_foreign_keys = 1; + DELETE FROM p2 WHERE a=1; + COMMIT; + SELECT * FROM p2; +} {0 one 1 deleted!} + + +finish_test diff --git a/test/fkey7.test b/test/fkey7.test new file mode 100644 index 0000000..77870a7 --- /dev/null +++ b/test/fkey7.test @@ -0,0 +1,121 @@ +# 2001 September 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests for foreign keys. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fkey7 + +ifcapable {!foreignkey} { + finish_test + return +} + +do_execsql_test 1.1 { + PRAGMA foreign_keys = 1; + + CREATE TABLE s1(a PRIMARY KEY, b); + CREATE TABLE par(a, b REFERENCES s1, c UNIQUE, PRIMARY KEY(a)); + + CREATE TABLE c1(a, b REFERENCES par); + CREATE TABLE c2(a, b REFERENCES par); + CREATE TABLE c3(a, b REFERENCES par(c)); +} + +proc auth {op tbl args} { + if {$op == "SQLITE_READ"} { set ::tbls($tbl) 1 } + return "SQLITE_OK" +} +db auth auth +db cache size 0 +proc do_tblsread_test {tn sql tbllist} { + array unset ::tbls + uplevel [list execsql $sql] + uplevel [list do_test $tn {lsort [array names ::tbls]} $tbllist] +} + +do_tblsread_test 1.2 { UPDATE par SET b=? WHERE a=? } {par s1} +do_tblsread_test 1.3 { UPDATE par SET a=? WHERE b=? } {c1 c2 par} +do_tblsread_test 1.4 { UPDATE par SET c=? WHERE b=? } {c3 par} +do_tblsread_test 1.5 { UPDATE par SET a=?,b=?,c=? WHERE b=? } {c1 c2 c3 par s1} + +ifcapable incrblob { + do_execsql_test 2.0 { + CREATE TABLE pX(x PRIMARY KEY); + CREATE TABLE cX(a INTEGER PRIMARY KEY, b REFERENCES pX); + } + + do_catchsql_test 2.1 { + INSERT INTO cX VALUES(11, zeroblob(40)); + } {1 {FOREIGN KEY constraint failed}} + + do_test 2.2 { + set stmt [sqlite3_prepare_v2 db "INSERT INTO cX VALUES(11, ?)" -1] + sqlite3_bind_zeroblob $stmt 1 45 + sqlite3_step $stmt + sqlite3_finalize $stmt + } {SQLITE_CONSTRAINT} +} + +ifcapable stat4 { + do_execsql_test 3.0 { + CREATE TABLE p4 (id INTEGER NOT NULL PRIMARY KEY); + INSERT INTO p4 VALUES(1), (2), (3); + + CREATE TABLE c4(x INTEGER REFERENCES p4(id) DEFERRABLE INITIALLY DEFERRED); + CREATE INDEX c4_x ON c4(x); + INSERT INTO c4 VALUES(1), (2), (3); + + ANALYZE; + INSERT INTO p4(id) VALUES(4); + } +} + + +do_execsql_test 4.0 { + PRAGMA foreign_keys = true; + CREATE TABLE parent( + p PRIMARY KEY + ); + CREATE TABLE child( + c UNIQUE REFERENCES parent(p) + ); +} + +do_catchsql_test 4.1 { + INSERT OR FAIL INTO child VALUES(123), (123); +} {1 {FOREIGN KEY constraint failed}} + +do_execsql_test 4.2 { + SELECT * FROM child; +} {} + +do_execsql_test 4.3 { + PRAGMA foreign_key_check; +} {} + +do_catchsql_test 4.4 { + INSERT INTO parent VALUES(123); + INSERT OR FAIL INTO child VALUES(123), (123); +} {1 {UNIQUE constraint failed: child.c}} + +do_execsql_test 4.5 { + SELECT * FROM child; +} {123} + +do_execsql_test 4.6 { + PRAGMA foreign_key_check; +} {} + +finish_test diff --git a/test/fkey8.test b/test/fkey8.test new file mode 100644 index 0000000..2d72f6f --- /dev/null +++ b/test/fkey8.test @@ -0,0 +1,253 @@ +# 2001 September 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests for foreign keys. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fkey8 + +ifcapable {!foreignkey} { + finish_test + return +} +do_execsql_test 1.0 { PRAGMA foreign_keys = 1; } + + +foreach {tn use_stmt sql schema} { + 1 1 "DELETE FROM p1" { + CREATE TABLE p1(a PRIMARY KEY); + CREATE TABLE c1(b REFERENCES p1); + } + + 2.1 0 "DELETE FROM p1" { + CREATE TABLE p1(a PRIMARY KEY); + CREATE TABLE c1(b REFERENCES p1 ON DELETE CASCADE); + } + 2.2 0 "DELETE FROM p1" { + CREATE TABLE p1(a PRIMARY KEY); + CREATE TABLE c1(b REFERENCES p1 ON DELETE SET NULL); + } + 2.3 1 "DELETE FROM p1" { + CREATE TABLE p1(a PRIMARY KEY); + CREATE TABLE c1(b REFERENCES p1 ON DELETE SET DEFAULT); + } + + 3 1 "DELETE FROM p1" { + CREATE TABLE p1(a PRIMARY KEY); + CREATE TABLE c1(b REFERENCES p1 ON DELETE CASCADE); + CREATE TRIGGER ct1 AFTER DELETE ON c1 BEGIN + INSERT INTO p1 VALUES('x'); + END; + } + + 4 1 "DELETE FROM p1" { + CREATE TABLE p1(a PRIMARY KEY); + CREATE TABLE c1(b REFERENCES p1 ON DELETE CASCADE, c PRIMARY KEY); + CREATE TABLE cc1(d REFERENCES c1); + } + + 5.1 0 "DELETE FROM p1" { + CREATE TABLE p1(a PRIMARY KEY); + CREATE TABLE c1(b REFERENCES p1 ON DELETE CASCADE, c PRIMARY KEY); + CREATE TABLE cc1(d REFERENCES c1 ON DELETE CASCADE); + } + 5.2 0 "DELETE FROM p1" { + CREATE TABLE p1(a PRIMARY KEY); + CREATE TABLE c1(b REFERENCES p1 ON DELETE CASCADE, c PRIMARY KEY); + CREATE TABLE cc1(d REFERENCES c1 ON DELETE SET NULL); + } + 5.3 1 "DELETE FROM p1" { + CREATE TABLE p1(a PRIMARY KEY); + CREATE TABLE c1(b REFERENCES p1 ON DELETE CASCADE, c PRIMARY KEY); + CREATE TABLE cc1(d REFERENCES c1 ON DELETE SET DEFAULT); + } + + 6.1 1 "UPDATE p1 SET a = ?" { + CREATE TABLE p1(a PRIMARY KEY); + CREATE TABLE c1(b REFERENCES p1 ON UPDATE SET NULL, c); + } + 6.2 0 "UPDATE OR IGNORE p1 SET a = ?" { + CREATE TABLE p1(a PRIMARY KEY); + CREATE TABLE c1(b REFERENCES p1 ON UPDATE SET NULL, c); + } + 6.3 1 "UPDATE OR IGNORE p1 SET a = ?" { + CREATE TABLE p1(a PRIMARY KEY); + CREATE TABLE c1(b REFERENCES p1 ON UPDATE CASCADE, c); + } + 6.4 1 "UPDATE OR IGNORE p1 SET a = ?" { + CREATE TABLE p1(a PRIMARY KEY); + CREATE TABLE c1(b NOT NULL REFERENCES p1 ON UPDATE SET NULL, c); + } + +} { + drop_all_tables + do_test 1.$tn { + execsql $schema + set stmt [sqlite3_prepare_v2 db $sql -1 dummy] + set ret [uses_stmt_journal $stmt] + sqlite3_finalize $stmt + set ret + } $use_stmt +} + +#------------------------------------------------------------------------- +# The following tests check that foreign key constaint counters are +# correctly updated for any implicit DELETE operations that occur +# when a REPLACE command is executed against a WITHOUT ROWID table +# that has no triggers or auxiliary indexes. +# +reset_db +do_execsql_test 2.1.0 { + PRAGMA foreign_keys = on; + CREATE TABLE p1(a PRIMARY KEY, b) WITHOUT ROWID; + CREATE TABLE c1(x REFERENCES p1 DEFERRABLE INITIALLY DEFERRED); + + INSERT INTO p1 VALUES(1, 'one'); + INSERT INTO p1 VALUES(2, 'two'); + INSERT INTO c1 VALUES(1); + INSERT INTO c1 VALUES(2); +} + +do_catchsql_test 2.1.2 { + BEGIN; + DELETE FROM p1 WHERE a=1; + INSERT OR REPLACE INTO p1 VALUES(2, 'two'); + COMMIT; +} {1 {FOREIGN KEY constraint failed}} + +reset_db +do_execsql_test 2.2.0 { + PRAGMA foreign_keys = on; + CREATE TABLE p2(a PRIMARY KEY, b); + CREATE TABLE c2( + x PRIMARY KEY, + y REFERENCES p2 DEFERRABLE INITIALLY DEFERRED + ) WITHOUT ROWID; +} + +do_catchsql_test 2.2.1 { + BEGIN; + INSERT INTO c2 VALUES(13, 13); + INSERT OR REPLACE INTO c2 VALUES(13, 13); + DELETE FROM c2; + COMMIT; +} {0 {}} + +reset_db +do_execsql_test 2.3.0 { + PRAGMA foreign_keys = on; + CREATE TABLE p3(a PRIMARY KEY, b) WITHOUT ROWID; + CREATE TABLE c3(x REFERENCES p3); + + INSERT INTO p3 VALUES(1, 'one'); + INSERT INTO p3 VALUES(2, 'two'); + INSERT INTO c3 VALUES(1); + INSERT INTO c3 VALUES(2); + + CREATE TRIGGER p3d AFTER DELETE ON p3 WHEN old.a=1 BEGIN + INSERT OR REPLACE INTO p3 VALUES(2, 'three'); + END; +} + +do_catchsql_test 2.3.1 { + DELETE FROM p3 WHERE a=1 +} {1 {FOREIGN KEY constraint failed}} + + +do_execsql_test 3.0 { + PRAGMA foreign_keys=ON; + CREATE TABLE t2( + a PRIMARY KEY, b, c, d, e, + FOREIGN KEY(b, c) REFERENCES t2(d, e) + ) WITHOUT ROWID; + CREATE UNIQUE INDEX idx ON t2(d, e); + + INSERT INTO t2 VALUES(1, 'one', 'one', 'one', 'one'); -- row is parent of self + INSERT INTO t2 VALUES(2, 'one', 'one', 'one', NULL); -- parent is row 1 +} + +do_catchsql_test 3.1 { + DELETE FROM t2 WHERE a=1; +} {1 {FOREIGN KEY constraint failed}} + +do_execsql_test 4.0 { + CREATE TABLE t1 ( + c1 PRIMARY KEY, + c2 NUMERIC, + FOREIGN KEY(c1) REFERENCES t1(c2) + ) WITHOUT ROWID ; + CREATE INDEX t1c1 ON t1(c1); + CREATE UNIQUE INDEX t1c1unique ON t1(c2); +} +do_catchsql_test 4.1 { + INSERT OR REPLACE INTO t1 VALUES(10000, 20000); +} {1 {FOREIGN KEY constraint failed}} +do_execsql_test 4.2 { + INSERT OR REPLACE INTO t1 VALUES(20000, 20000); +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 5.0 { + PRAGMA foreign_keys = true; + CREATE TABLE parent( + p TEXT PRIMARY KEY + ); + CREATE TABLE child( + c INTEGER UNIQUE, + FOREIGN KEY(c) REFERENCES parent(p) DEFERRABLE INITIALLY DEFERRED + ); + BEGIN; + INSERT INTO child VALUES(123); + INSERT INTO parent VALUES('123'); + COMMIT; +} +do_execsql_test 5.1 { + PRAGMA integrity_check; +} {ok} + +do_execsql_test 5.2 { + INSERT INTO parent VALUES(1200); + BEGIN; + INSERT INTO child VALUES(456); + UPDATE parent SET p = '456' WHERE p=1200; + COMMIT; +} +do_execsql_test 5.3 { + PRAGMA integrity_check; +} {ok} + +#------------------------------------------------------------------------- +reset_db +forcedelete test.db2 +do_execsql_test 6.1 { + PRAGMA foreign_keys = on; + CREATE TABLE c1(b); + INSERT INTO c1 VALUES(123); +} + +do_execsql_test 6.2 { + ATTACH 'test.db2' AS aux; + CREATE TABLE aux.p1(a INTEGER PRIMARY KEY); + CREATE TABLE aux.c1(b REFERENCES p1(a) ON DELETE RESTRICT); + + INSERT INTO aux.p1 VALUES(123); +} + +do_execsql_test 6.3 { + DELETE FROM aux.p1 WHERE a=123; +} + + +finish_test diff --git a/test/fkey_malloc.test b/test/fkey_malloc.test new file mode 100644 index 0000000..382e6f6 --- /dev/null +++ b/test/fkey_malloc.test @@ -0,0 +1,134 @@ +# 2009 September 22 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !foreignkey||!trigger { + finish_test + return +} +source $testdir/malloc_common.tcl + +do_malloc_test fkey_malloc-1 -sqlprep { + PRAGMA foreign_keys = 1; + CREATE TABLE t1(a PRIMARY KEY, b UNIQUE); + CREATE TABLE t2(x REFERENCES t1 ON UPDATE CASCADE ON DELETE CASCADE); +} -sqlbody { + INSERT INTO t1 VALUES('aaa', 1); + INSERT INTO t2 VALUES('aaa'); + UPDATE t1 SET a = 'bbb'; + DELETE FROM t1; + PRAGMA foreign_key_check; +} + +do_malloc_test fkey_malloc-2 -sqlprep { + PRAGMA foreign_keys = 1; + CREATE TABLE t1(a, b, UNIQUE(a, b)); +} -sqlbody { + CREATE TABLE t2(x, y, + FOREIGN KEY(x, y) REFERENCES t1(a, b) DEFERRABLE INITIALLY DEFERRED + ); + BEGIN; + INSERT INTO t2 VALUES('a', 'b'); + INSERT INTO t1 VALUES('a', 'b'); + UPDATE t1 SET a = 'c'; + DELETE FROM t2; + INSERT INTO t2 VALUES('d', 'b'); + UPDATE t2 SET x = 'c'; + COMMIT; +} + +do_malloc_test fkey_malloc-3 -sqlprep { + PRAGMA foreign_keys = 1; + CREATE TABLE t1(x INTEGER PRIMARY KEY); + CREATE TABLE t2(y DEFAULT 14 REFERENCES t1(x) ON UPDATE SET DEFAULT); + CREATE TABLE t3(y REFERENCES t1 ON UPDATE SET NULL); + INSERT INTO t1 VALUES(13); + INSERT INTO t2 VALUES(13); + INSERT INTO t3 VALUES(13); +} -sqlbody { + UPDATE t1 SET x = 14; +} + +proc catch_fk_error {zSql} { + set rc [catch {db eval $zSql} msg] + if {$rc==0} { + return $msg + } + if {[string match {*foreign key*} $msg]} { + return "" + } + if {$msg eq "out of memory" + || $msg eq "FOREIGN KEY constraint failed" + || $msg eq "constraint failed" + } { + error 1 + } + error $msg +} + +do_malloc_test fkey_malloc-4 -sqlprep { + PRAGMA foreign_keys = 1; + CREATE TABLE t1(x INTEGER PRIMARY KEY, y UNIQUE); + CREATE TABLE t2(z REFERENCES t1(x), a REFERENCES t1(y)); + CREATE TABLE t3(x); + CREATE TABLE t4(z REFERENCES t3); + CREATE TABLE t5(x, y); + CREATE TABLE t6(z REFERENCES t5(x)); + CREATE INDEX i51 ON t5(x); + CREATE INDEX i52 ON t5(y, x); + INSERT INTO t1 VALUES(1, 2); +} -tclbody { + catch_fk_error {INSERT INTO t2 VALUES(1, 3)} + catch_fk_error {INSERT INTO t4 VALUES(2)} + catch_fk_error {INSERT INTO t6 VALUES(2)} +} + +do_malloc_test fkey_malloc-5 -sqlprep { + PRAGMA foreign_keys = 1; + CREATE TABLE t1(x, y, PRIMARY KEY(x, y)); + CREATE TABLE t2(a, b, FOREIGN KEY(a, b) REFERENCES t1 ON UPDATE CASCADE); + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t2 VALUES(1, 2); +} -sqlbody { + UPDATE t1 SET x = 5; +} + +do_malloc_test fkey_malloc-6 -sqlprep { + PRAGMA foreign_keys = 1; + CREATE TABLE t1( + x PRIMARY KEY, + y REFERENCES t1 ON DELETE RESTRICT ON UPDATE SET DEFAULT + ); + INSERT INTO t1 VALUES('abc', 'abc'); + INSERT INTO t1 VALUES('def', 'def'); +} -sqlbody { + INSERT INTO t1 VALUES('ghi', 'ghi'); + DELETE FROM t1 WHERE rowid>1; + UPDATE t1 SET x='jkl', y='jkl'; +} + +do_malloc_test fkey_malloc-7 -sqlprep { + PRAGMA foreign_keys = 1; + CREATE TABLE x(a, b, PRIMARY KEY(a, b)); + CREATE TABLE y(c, d, + FOREIGN KEY(d, c) REFERENCES x DEFERRABLE INITIALLY DEFERRED + ); + CREATE TABLE z(e, f, FOREIGN KEY(e, f) REFERENCES x); +} -sqlbody { + DROP TABLE y; + DROP TABLE x; +} + +finish_test diff --git a/test/fordelete.test b/test/fordelete.test new file mode 100644 index 0000000..39c0c35 --- /dev/null +++ b/test/fordelete.test @@ -0,0 +1,209 @@ +# 2001 September 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing the SELECT statement. +# +# $Id: select1.test,v 1.70 2009/05/28 01:00:56 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix fordelete + +# This function returns a list of the tables or indexes opened with +# OP_OpenWrite instructions when the SQL statement passed as the only +# argument is executed. If the OPFLAG_FORDELETE flag is specified on +# the OP_OpenWrite, an asterix is appended to the object name. The list +# is sorted in [lsort] order before it is returned. +# +proc analyze_delete_program {sql} { + # Build a map from root page to table/index name. + db eval { + SELECT name, rootpage FROM sqlite_master + } { + set T($rootpage) $name + } + + # For each OpenWrite instruction generated for the proposed DELETE + # statement, add the following array entries: + # + # $M() -> + # $O() -> "*" | "" + # + # The O() entry is set to "*" if the BTREE_FORDELETE flag is specified, + # or "" otherwise. + # + db eval "EXPLAIN $sql" R { + if {$R(opcode)=="OpenWrite"} { + set root $R(p2) + set csr $R(p1) + if {[info exists T($root)]} { set M($csr) $T($root) } + + set obj $T($root) + set O($obj) "" + if {$R(p5) & 0x08} { + set O($obj) * + } else { + set O($obj) "" + } + } + } + + db eval "EXPLAIN $sql" R { + if {$R(opcode) == "Delete"} { + set csr $R(p1) + if {[info exists M($csr)]} { + set idxdelete [expr {("0x$R(p5)" & 0x04) ? 1 : 0}] + if {$idxdelete} { + append O($M($csr)) "+" + } + } + } + } + + set res [list] + foreach {k v} [array get O] { + lappend res "${k}${v}" + } + + lsort $res +} + +proc do_adp_test {tn sql res} { + uplevel [list do_test $tn [list analyze_delete_program $sql] [list {*}$res]] +} + +do_execsql_test 1.0 { + CREATE TABLE t1(a PRIMARY KEY, b); +} + +foreach {tn sql res} { + 1 { DELETE FROM t1 WHERE a=?} { sqlite_autoindex_t1_1 t1*+ } + 2 { DELETE FROM t1 WHERE a=? AND b=? } { sqlite_autoindex_t1_1 t1+ } + 3 { DELETE FROM t1 WHERE a>? } { sqlite_autoindex_t1_1 t1*+ } + 4 { DELETE FROM t1 WHERE rowid=? } { sqlite_autoindex_t1_1* t1 } +} { + do_adp_test 1.$tn $sql $res +} + +do_execsql_test 2.0 { + CREATE TABLE t2(a, b, c); + CREATE INDEX t2a ON t2(a); + CREATE INDEX t2b ON t2(b); + CREATE INDEX t2c ON t2(c); +} +foreach {tn sql res} { + 1 { DELETE FROM t2 WHERE a=?} { t2*+ t2a t2b* t2c* } + 2 { DELETE FROM t2 WHERE a=? AND +b=?} { t2+ t2a t2b* t2c* } + 3 { DELETE FROM t2 WHERE a=? OR b=?} { t2 t2a* t2b* t2c* } + 4 { DELETE FROM t2 WHERE +a=? } { t2 t2a* t2b* t2c* } + 5 { DELETE FROM t2 WHERE rowid=? } { t2 t2a* t2b* t2c* } +} { + do_adp_test 2.$tn $sql $res +} + +#------------------------------------------------------------------------- +# Test that a record that consists of the bytes: +# +# 0x01 0x00 +# +# is interpreted by OP_Column as a vector of NULL values (assuming the +# default column values are NULL). Also test that: +# +# 0x00 +# +# is handled in the same way. +# +do_execsql_test 3.0 { + CREATE TABLE x1(a INTEGER PRIMARY KEY, b, c, d); + CREATE TABLE x2(a INTEGER PRIMARY KEY, b, c, d); +} + +do_test 3.1 { + set root [db one { SELECT rootpage FROM sqlite_master WHERE name = 'x1' }] + db eval { + BEGIN IMMEDIATE; + } + set bt [btree_from_db db] + set csr [btree_cursor $bt $root 1] + btree_insert $csr 5 "\000" + btree_close_cursor $csr + db eval { COMMIT } + + db eval { + SELECT * FROM x1; + } +} {5 {} {} {}} + +do_test 3.2 { + set root [db one { SELECT rootpage FROM sqlite_master WHERE name = 'x2' }] + db eval { + BEGIN IMMEDIATE; + } + set bt [btree_from_db db] + set csr [btree_cursor $bt $root 1] + btree_insert $csr 6 "\000" + btree_close_cursor $csr + db eval { COMMIT } + + db eval { + SELECT * FROM x2; + } +} {6 {} {} {}} + + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 4.0 { + CREATE TABLE log(x); + CREATE TABLE p1(one PRIMARY KEY, two); + + CREATE TRIGGER tr_bd BEFORE DELETE ON p1 BEGIN + INSERT INTO log VALUES('delete'); + END; + INSERT INTO p1 VALUES('a', 'A'), ('b', 'B'), ('c', 'C'); + DELETE FROM p1 WHERE one = 'a'; +} + +reset_db +do_execsql_test 4.1 { + BEGIN TRANSACTION; + CREATE TABLE tbl(a PRIMARY KEY, b, c); + CREATE TABLE log(a, b, c); + INSERT INTO "tbl" VALUES(1,2,3); + CREATE TRIGGER the_trigger BEFORE DELETE ON tbl BEGIN + INSERT INTO log VALUES(1, 2,3); + END; + COMMIT; + DELETE FROM tbl WHERE a=1; +} + +reset_db +do_execsql_test 5.1 { + PRAGMA foreign_keys = 1; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + CREATE TABLE t2( + c INTEGER PRIMARY KEY, + d INTEGER DEFAULT 1 REFERENCES t1 ON DELETE SET DEFAULT + ); +} {} +do_execsql_test 5.2 { + INSERT INTO t1 VALUES(1, 'one'); + INSERT INTO t1 VALUES(2, 'two'); + INSERT INTO t2 VALUES(1, 2); + SELECT * FROM t2; +} {1 2} +do_execsql_test 5.3 { + DELETE FROM t1 WHERE a = 2; +} {} + + +finish_test diff --git a/test/format4.test b/test/format4.test new file mode 100644 index 0000000..a850ce2 --- /dev/null +++ b/test/format4.test @@ -0,0 +1,66 @@ +# 2005 December 29 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests to verify that the new serial_type +# values of 8 (integer 0) and 9 (integer 1) work correctly. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +#db eval {PRAGMA legacy_file_format=OFF} +sqlite3_db_config db LEGACY_FILE_FORMAT 0 + +# The size of the database depends on whether or not autovacuum +# is enabled. +# +ifcapable autovacuum { + if {[db one {PRAGMA auto_vacuum}]} { + set small 3072 + set large 5120 + } else { + set small 2048 + set large 4096 + } +} else { + set small 2048 + set large 4096 +} + +do_test format4-1.1 { + execsql { + CREATE TABLE t1(x0,x1,x2,x3,x4,x5,x6,x7,x8,x9); + INSERT INTO t1 VALUES(0,0,0,0,0,0,0,0,0,0); + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + } + file size test.db +} $small +do_test format4-1.2 { + execsql { + UPDATE t1 SET x0=1, x1=1, x2=1, x3=1, x4=1, x5=1, x6=1, x7=1, x8=1, x9=1 + } + file size test.db +} $small +do_test format4-1.3 { + execsql { + UPDATE t1 SET x0=2, x1=2, x2=2, x3=2, x4=2, x5=2, x6=2, x7=2, x8=2, x9=2 + } + file size test.db +} $large + + +finish_test diff --git a/test/fp-speed-1.c b/test/fp-speed-1.c new file mode 100644 index 0000000..5eeb95d --- /dev/null +++ b/test/fp-speed-1.c @@ -0,0 +1,164 @@ +/* +** Performance testing of floating-point binary-to-decimal conversion for +** SQLite versus the standard library. +** +** To compile: +** +** make sqlite3.c +** gcc -Os -c sqlite3.c +** gcc -I. -Os test/fp-speed-1.c sqlite3.o -ldl -lm -lpthread +** +** To run the test: +** +** time ./a.out 0 10000000 <-- standard library +** time ./a.out 1 10000000 <-- SQLite +** time ./a.out 2 10000000 <-- SQLite with long-double disabled +*/ +static double aVal[] = { + -1.0163830486285643089e+063, + +0.0049243807391586981e-019, + +7.3818732407343994867e-095, + +7.0678595219225717143e+000, + +9.2807266319850025655e+120, + +5.8871050861933394663e+135, + -2.2998023621259662805e-168, + -1.5903581924910847482e+181, + +2.4313441816844978216e-001, + -3.8290987328945399091e-147, + +1.8787914062744001349e-009, + +0.7270653560487146653e-014, + +0.0639577697913183665e+107, + +5.2292338879315861930e-103, + +6.3747682672872231319e-021, + +8.6972339538329106984e-129, + -9.5074486051597691937e-026, + -8.6480257845368753018e-005, + -3.5657595775797470332e+017, + -7.8323106179731761351e+161, + +7.7813875274120800372e+077, + -1.8739718928360196596e-050, + +8.6898145915593357218e-051, + +6.0566766359877837871e+002, + +4.1703379217148160678e+199, + +2.1283871288746651560e+150, + -6.8395236083891810637e+128, + -6.2114299763939529155e-147, + -2.0753525742614637350e-149, + +5.8727459803944290257e-007, + +8.5888991062002101817e+010, + +6.8624461031355917632e+026, + -3.3053986756670905167e-075, + -4.3596843152763444945e-108, + +0.0834139520104099673e+098, + -8.8581986548904222440e-192, + -3.6622095428727698202e+038, + -6.6965852297025063260e+005, + +1.8204169347406488441e-054, + +6.5234508038649000384e-065, + +1.5923006018219011453e+083, + +1.7362555291656389480e+018, + +7.2875431976854785882e+160, + +1.2835880105958926748e-146, + +8.0516253320320819420e-113, + +6.6324633399381145440e-030, + -1.7126500070280062058e-149, + +1.6995738341583712335e+042, + +7.6048766923738663725e-112, + +0.6159117235449455043e-004, + +5.7544894355415943289e-135, + +8.2970228592690581890e-023, + -6.5531925360163067447e+020, + +5.8321334606187030050e+120, + +5.6557166509571891727e+095, + +0.3322789708438408704e-114, + -7.1210648776698686623e-050, + -9.6721262526706343301e+179, + -3.4583916571377395084e-106, + +4.7896094323214750793e-172, + -9.6926028040004137875e-056, + +7.0683848275381385483e-198, + -5.2970114182162961964e-007, + -4.4287021200905393271e-170, + +0.0728891155732808799e-189, + -9.1855462025879447465e+175, + +3.7294126234131007796e+015, + +2.6857421882792719241e+003, + -4.7070607333624685339e+039, + +7.2175820768279334274e+136, + -8.3678412534261163481e-115, + +2.2174844304241822163e+019, + +0.1949824588606861016e+112, + -9.7334052955672071912e+151, + -9.7793887766936999879e-142, + -5.1561164587416931561e+139, + -7.5048993577765174789e-022, + +7.3556076568687784568e+107, + -5.0681628575533599865e-144, + +1.5209705642027747811e+165, + -7.5989782535048296040e-101, + +1.3654137203389775871e-016, + -1.6441720554651372066e+087, + -4.9042433196141125923e+000, + -7.7063611961649130777e+118, + +0.1699427460930766201e+174, + +8.3374317849572216870e-145, + -5.2355330480469580072e+081, + -3.8510045942194147919e+141, + -6.3513622544326339887e-147, + +2.3869303484454428988e+049, + +3.8352715871620360268e-165, + -3.1263120493136887902e+035, + -5.5794797002556490823e+051, + -8.8109874479595604379e+142, + -4.3727360120203216922e+070, + -3.1109951189668539974e+170, + -9.4841878031704268232e+011, + -3.7398451668304407277e+067, + +4.8984042008915959963e-091, +}; +#define NN (sizeof(aVal)/sizeof(aVal[0])) + +#include "sqlite3.h" +#include +#include + +int main(int argc, char **argv){ + int i; + int cnt; + int fg; + char zBuf[1000]; + + if( argc!=3 ){ + fprintf(stderr, "Usage: %s FLAG COUNT\n", argv[0]); + return 1; + } + cnt = atoi(argv[2]); + fg = atoi(argv[1]); + + switch( fg % 3 ){ + case 0: { + printf("Doing %d calls to C-lib sprintf()\n", cnt); + for(i=0; i 10000} {error "n must be <= 10000"} + db eval "CREATE VIRTUAL TABLE t1 USING $opts(-module) (x, y)" + + set xwords [list zero one two three four five six seven eight nine ten] + set ywords [list alpha beta gamma delta epsilon zeta eta theta iota kappa] + + for {set i 0} {$i < $n} {incr i} { + set x "" + set y "" + + set x [list] + lappend x [lindex $xwords [expr ($i / 1000) % 10]] + lappend x [lindex $xwords [expr ($i / 100) % 10]] + lappend x [lindex $xwords [expr ($i / 10) % 10]] + lappend x [lindex $xwords [expr ($i / 1) % 10]] + + set y [list] + lappend y [lindex $ywords [expr ($i / 1000) % 10]] + lappend y [lindex $ywords [expr ($i / 100) % 10]] + lappend y [lindex $ywords [expr ($i / 10) % 10]] + lappend y [lindex $ywords [expr ($i / 1) % 10]] + + db eval { INSERT INTO t1(docid, x, y) VALUES($i, $x, $y) } + } +} + +#------------------------------------------------------------------------- +# USAGE: fts3_build_db_2 N ARGS +# +# Build a sample FTS table in the database opened by database connection +# [db]. The name of the new table is "t2". +# +proc fts3_build_db_2 {args} { + + set default(-module) fts4 + set default(-extra) "" + + set nArg [llength $args] + if {($nArg%2)==0} { + error "wrong # args: should be \"fts3_build_db_1 ?switches? n\"" + } + + set n [lindex $args [expr $nArg-1]] + array set opts [array get default] + array set opts [lrange $args 0 [expr $nArg-2]] + foreach k [array names opts] { + if {0==[info exists default($k)]} { error "unknown option: $k" } + } + + if {$n > 100000} {error "n must be <= 100000"} + + set sql "CREATE VIRTUAL TABLE t2 USING $opts(-module) (content" + if {$opts(-extra) != ""} { + append sql ", " $opts(-extra) + } + append sql ")" + db eval $sql + + set chars [list a b c d e f g h i j k l m n o p q r s t u v w x y z ""] + + for {set i 0} {$i < $n} {incr i} { + set word "" + set nChar [llength $chars] + append word [lindex $chars [expr {($i / 1) % $nChar}]] + append word [lindex $chars [expr {($i / $nChar) % $nChar}]] + append word [lindex $chars [expr {($i / ($nChar*$nChar)) % $nChar}]] + + db eval { INSERT INTO t2(docid, content) VALUES($i, $word) } + } +} + +#------------------------------------------------------------------------- +# USAGE: fts3_integrity_check TBL +# +# This proc is used to verify that the full-text index is consistent with +# the contents of the fts3 table. In other words, it checks that the +# data in the %_contents table matches that in the %_segdir and %_segments +# tables. +# +# This is not an efficient procedure. It uses a lot of memory and a lot +# of CPU. But it is better than not checking at all. +# +# The procedure is: +# +# 1) Read the entire full-text index from the %_segdir and %_segments +# tables into memory. For each entry in the index, the following is +# done: +# +# set C($iDocid,$iCol,$iPosition) $zTerm +# +# 2) Iterate through each column of each row of the %_content table. +# Tokenize all documents, and check that for each token there is +# a corresponding entry in the $C array. After checking a token, +# [unset] the $C array entry. +# +# 3) Check that array $C is now empty. +# +# +proc fts3_integrity_check {tbl} { + + fts3_read2 $tbl 1 A + + foreach zTerm [array names A] { + #puts $zTerm + foreach doclist $A($zTerm) { + set docid 0 + while {[string length $doclist]>0} { + set iCol 0 + set iPos 0 + set lPos [list] + set lCol [list] + + # First varint of a doclist-entry is the docid. Delta-compressed + # with respect to the docid of the previous entry. + # + incr docid [gobble_varint doclist] + if {[info exists D($zTerm,$docid)]} { + while {[set iDelta [gobble_varint doclist]] != 0} {} + continue + } + set D($zTerm,$docid) 1 + + # Gobble varints until the 0x00 that terminates the doclist-entry + # is found. + while {[set iDelta [gobble_varint doclist]] > 0} { + if {$iDelta == 1} { + set iCol [gobble_varint doclist] + set iPos 0 + } else { + incr iPos $iDelta + incr iPos -2 + set C($docid,$iCol,$iPos) $zTerm + } + } + } + } + } + + foreach key [array names C] { + #puts "$key -> $C($key)" + } + + + db eval "SELECT * FROM ${tbl}_content" E { + set iCol 0 + set iDoc $E(docid) + foreach col [lrange $E(*) 1 end] { + set c $E($col) + set sql {SELECT fts3_tokenizer_test('simple', $c)} + + foreach {pos term dummy} [db one $sql] { + if {![info exists C($iDoc,$iCol,$pos)]} { + set es "Error at docid=$iDoc col=$iCol pos=$pos. Index is missing" + lappend errors $es + } else { + if {[string compare $C($iDoc,$iCol,$pos) $term]} { + set es "Error at docid=$iDoc col=$iCol pos=$pos. Index " + append es "has \"$C($iDoc,$iCol,$pos)\", document has \"$term\"" + lappend errors $es + } + unset C($iDoc,$iCol,$pos) + } + } + incr iCol + } + } + + foreach c [array names C] { + lappend errors "Bad index entry: $c -> $C($c)" + } + + if {[info exists errors]} { return [join $errors "\n"] } + return "ok" +} + +# USAGE: fts3_terms TBL WHERE +# +# Argument TBL must be the name of an FTS3 table. Argument WHERE is an +# SQL expression that will be used as the WHERE clause when scanning +# the %_segdir table. As in the following query: +# +# "SELECT * FROM ${TBL}_segdir WHERE ${WHERE}" +# +# This function returns a list of all terms present in the segments +# selected by the statement above. +# +proc fts3_terms {tbl where} { + fts3_read $tbl $where a + return [lsort [array names a]] +} + + +# USAGE: fts3_doclist TBL TERM WHERE +# +# Argument TBL must be the name of an FTS3 table. TERM is a term that may +# or may not be present in the table. Argument WHERE is used to select a +# subset of the b-tree segments in the associated full-text index as +# described above for [fts3_terms]. +# +# This function returns the results of merging the doclists associated +# with TERM in the selected segments. Each doclist is an element of the +# returned list. Each doclist is formatted as follows: +# +# [$docid ?$col[$off1 $off2...]?...] +# +# The formatting is odd for a Tcl command in order to be compatible with +# the original C-language implementation. If argument WHERE is "1", then +# any empty doclists are omitted from the returned list. +# +proc fts3_doclist {tbl term where} { + fts3_read $tbl $where a + + + foreach doclist $a($term) { + set docid 0 + + while {[string length $doclist]>0} { + set iCol 0 + set iPos 0 + set lPos [list] + set lCol [list] + incr docid [gobble_varint doclist] + + while {[set iDelta [gobble_varint doclist]] > 0} { + if {$iDelta == 1} { + lappend lCol [list $iCol $lPos] + set iPos 0 + set lPos [list] + set iCol [gobble_varint doclist] + } else { + incr iPos $iDelta + incr iPos -2 + lappend lPos $iPos + } + } + + if {[llength $lPos]>0} { + lappend lCol [list $iCol $lPos] + } + + if {$where != "1" || [llength $lCol]>0} { + set ret($docid) $lCol + } else { + unset -nocomplain ret($docid) + } + } + } + + set lDoc [list] + foreach docid [lsort -integer [array names ret]] { + set lCol [list] + set cols "" + foreach col $ret($docid) { + foreach {iCol lPos} $col {} + append cols " $iCol\[[join $lPos { }]\]" + } + lappend lDoc "\[${docid}${cols}\]" + } + + join $lDoc " " +} + +########################################################################### + +proc gobble_varint {varname} { + upvar $varname blob + set n [read_fts3varint $blob ret] + set blob [string range $blob $n end] + return $ret +} +proc gobble_string {varname nLength} { + upvar $varname blob + set ret [string range $blob 0 [expr $nLength-1]] + set blob [string range $blob $nLength end] + return $ret +} + +# The argument is a blob of data representing an FTS3 segment leaf. +# Return a list consisting of alternating terms (strings) and doclists +# (blobs of data). +# +proc fts3_readleaf {blob} { + set zPrev "" + set terms [list] + + while {[string length $blob] > 0} { + set nPrefix [gobble_varint blob] + set nSuffix [gobble_varint blob] + + set zTerm [string range $zPrev 0 [expr $nPrefix-1]] + append zTerm [gobble_string blob $nSuffix] + set nDoclist [gobble_varint blob] + set doclist [gobble_string blob $nDoclist] + + lappend terms $zTerm $doclist + set zPrev $zTerm + } + + return $terms +} + +proc fts3_read2 {tbl where varname} { + upvar $varname a + array unset a + db eval " SELECT start_block, leaves_end_block, root + FROM ${tbl}_segdir WHERE $where + ORDER BY level ASC, idx DESC + " { + set c 0 + binary scan $root c c + if {$c==0} { + foreach {t d} [fts3_readleaf $root] { lappend a($t) $d } + } else { + db eval " SELECT block + FROM ${tbl}_segments + WHERE blockid>=$start_block AND blockid<=$leaves_end_block + ORDER BY blockid + " { + foreach {t d} [fts3_readleaf $block] { lappend a($t) $d } + } + } + } +} + +proc fts3_read {tbl where varname} { + upvar $varname a + array unset a + db eval " SELECT start_block, leaves_end_block, root + FROM ${tbl}_segdir WHERE $where + ORDER BY level DESC, idx ASC + " { + if {$start_block == 0} { + foreach {t d} [fts3_readleaf $root] { lappend a($t) $d } + } else { + db eval " SELECT block + FROM ${tbl}_segments + WHERE blockid>=$start_block AND blockid<$leaves_end_block + ORDER BY blockid + " { + foreach {t d} [fts3_readleaf $block] { lappend a($t) $d } + + } + } + } +} + +########################################################################## + diff --git a/test/fts3aa.test b/test/fts3aa.test new file mode 100644 index 0000000..cb1bde7 --- /dev/null +++ b/test/fts3aa.test @@ -0,0 +1,265 @@ +# 2006 September 9 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS3 module. +# +# $Id: fts3aa.test,v 1.1 2007/08/20 17:38:42 shess Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts3aa + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# Construct a full-text search table containing five keywords: +# one, two, three, four, and five, in various combinations. The +# rowid for each will be a bitmask for the elements it contains. +# +db eval { + CREATE VIRTUAL TABLE t1 USING fts3(content); + INSERT INTO t1(content) VALUES('one'); + INSERT INTO t1(content) VALUES('two'); + INSERT INTO t1(content) VALUES('one two'); + INSERT INTO t1(content) VALUES('three'); + INSERT INTO t1(content) VALUES('one three'); + INSERT INTO t1(content) VALUES('two three'); + INSERT INTO t1(content) VALUES('one two three'); + INSERT INTO t1(content) VALUES('four'); + INSERT INTO t1(content) VALUES('one four'); + INSERT INTO t1(content) VALUES('two four'); + INSERT INTO t1(content) VALUES('one two four'); + INSERT INTO t1(content) VALUES('three four'); + INSERT INTO t1(content) VALUES('one three four'); + INSERT INTO t1(content) VALUES('two three four'); + INSERT INTO t1(content) VALUES('one two three four'); + INSERT INTO t1(content) VALUES('five'); + INSERT INTO t1(content) VALUES('one five'); + INSERT INTO t1(content) VALUES('two five'); + INSERT INTO t1(content) VALUES('one two five'); + INSERT INTO t1(content) VALUES('three five'); + INSERT INTO t1(content) VALUES('one three five'); + INSERT INTO t1(content) VALUES('two three five'); + INSERT INTO t1(content) VALUES('one two three five'); + INSERT INTO t1(content) VALUES('four five'); + INSERT INTO t1(content) VALUES('one four five'); + INSERT INTO t1(content) VALUES('two four five'); + INSERT INTO t1(content) VALUES('one two four five'); + INSERT INTO t1(content) VALUES('three four five'); + INSERT INTO t1(content) VALUES('one three four five'); + INSERT INTO t1(content) VALUES('two three four five'); + INSERT INTO t1(content) VALUES('one two three four five'); +} + +do_test fts3aa-1.1 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'} +} {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31} +do_test fts3aa-1.2 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two'} +} {3 7 11 15 19 23 27 31} +do_test fts3aa-1.3 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'two one'} +} {3 7 11 15 19 23 27 31} +do_test fts3aa-1.4 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two three'} +} {7 15 23 31} +do_test fts3aa-1.5 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'one three two'} +} {7 15 23 31} +do_test fts3aa-1.6 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'two three one'} +} {7 15 23 31} +do_test fts3aa-1.7 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'two one three'} +} {7 15 23 31} +do_test fts3aa-1.8 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'three one two'} +} {7 15 23 31} +do_test fts3aa-1.9 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'three two one'} +} {7 15 23 31} +do_test fts3aa-1.10 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two THREE'} +} {7 15 23 31} +do_test fts3aa-1.11 { + execsql {SELECT rowid FROM t1 WHERE content MATCH ' ONE Two three '} +} {7 15 23 31} + +do_test fts3aa-2.1 { + execsql {SELECT rowid FROM t1 WHERE content MATCH '"one"'} +} {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31} +do_test fts3aa-2.2 { + execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two"'} +} {3 7 11 15 19 23 27 31} +do_test fts3aa-2.3 { + execsql {SELECT rowid FROM t1 WHERE content MATCH '"two one"'} +} {} +do_test fts3aa-2.4 { + execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two three"'} +} {7 15 23 31} +do_test fts3aa-2.5 { + execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three two"'} +} {} +do_test fts3aa-2.6 { + execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two three four"'} +} {15 31} +do_test fts3aa-2.7 { + execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three two four"'} +} {} +do_test fts3aa-2.8 { + execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three five"'} +} {21} +do_test fts3aa-2.9 { + execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three" five'} +} {21 29} +do_test fts3aa-2.10 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'five "one three"'} +} {21 29} +do_test fts3aa-2.11 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'five "one three" four'} +} {29} +do_test fts3aa-2.12 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'five four "one three"'} +} {29} +do_test fts3aa-2.13 { + execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three" four five'} +} {29} + +do_test fts3aa-3.1 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'} +} {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31} +do_test fts3aa-3.2 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'one -two'} +} {1 5 9 13 17 21 25 29} +do_test fts3aa-3.3 { + execsql {SELECT rowid FROM t1 WHERE content MATCH '-two one'} +} {1 5 9 13 17 21 25 29} + +do_test fts3aa-4.1 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'one OR two'} +} {1 2 3 5 6 7 9 10 11 13 14 15 17 18 19 21 22 23 25 26 27 29 30 31} +do_test fts3aa-4.2 { + execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two" OR three'} +} {3 4 5 6 7 11 12 13 14 15 19 20 21 22 23 27 28 29 30 31} +do_test fts3aa-4.3 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'three OR "one two"'} +} {3 4 5 6 7 11 12 13 14 15 19 20 21 22 23 27 28 29 30 31} +do_test fts3aa-4.4 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two OR three'} +} {3 5 7 11 13 15 19 21 23 27 29 31} +do_test fts3aa-4.5 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'three OR two one'} +} {3 5 7 11 13 15 19 21 23 27 29 31} +do_test fts3aa-4.6 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two OR three OR four'} +} {3 5 7 9 11 13 15 19 21 23 25 27 29 31} +do_test fts3aa-4.7 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'two OR three OR four one'} +} {3 5 7 9 11 13 15 19 21 23 25 27 29 31} + +# Test the ability to handle NULL content +# +do_test fts3aa-5.1 { + execsql {INSERT INTO t1(content) VALUES(NULL)} +} {} +do_test fts3aa-5.2 { + set rowid [db last_insert_rowid] + execsql {SELECT content FROM t1 WHERE rowid=$rowid} +} {{}} +do_test fts3aa-5.3 { + execsql {SELECT rowid FROM t1 WHERE content MATCH NULL} +} {} + +# Test the ability to handle non-positive rowids +# +do_test fts3aa-6.0 { + execsql {INSERT INTO t1(rowid, content) VALUES(0, 'four five')} +} {} +do_test fts3aa-6.1 { + execsql {SELECT content FROM t1 WHERE rowid = 0} +} {{four five}} +do_test fts3aa-6.2 { + execsql {INSERT INTO t1(rowid, content) VALUES(-1, 'three four')} +} {} +do_test fts3aa-6.3 { + execsql {SELECT content FROM t1 WHERE rowid = -1} +} {{three four}} +do_test fts3aa-6.4 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'four'} +} {-1 0 8 9 10 11 12 13 14 15 24 25 26 27 28 29 30 31} + +# Test creation of FTS3 and FTS4 tables with columns that contain +# an "=" character. +# +do_execsql_test fts3aa-7.1 { + CREATE VIRTUAL TABLE t2 USING fts3(xyz=abc); + SELECT xyz FROM t2; +} {} +do_catchsql_test fts3aa-7.2 { + CREATE VIRTUAL TABLE t3 USING fts4(xyz=abc); +} {1 {unrecognized parameter: xyz=abc}} +do_catchsql_test fts3aa-7.3 { + CREATE VIRTUAL TABLE t3 USING fts4(xyz = abc); +} {1 {unrecognized parameter: xyz = abc}} + +do_execsql_test fts3aa-7.4 { + CREATE VIRTUAL TABLE t3 USING fts3(tokenize=simple, tokenize=simple); + SELECT tokenize FROM t3; +} {} +do_catchsql_test fts3aa-7.5 { + CREATE VIRTUAL TABLE t4 USING fts4(tokenize=simple, tokenize=simple); +} {1 {unrecognized parameter: tokenize=simple}} + +do_execsql_test 8.0 { + CREATE VIRTUAL TABLE t0 USING fts4(order=desc); + BEGIN; + INSERT INTO t0(rowid, content) VALUES(1, 'abc'); + UPDATE t0 SET docid=5 WHERE docid=1; + INSERT INTO t0(rowid, content) VALUES(6, 'abc'); +} +do_execsql_test 8.1 { + SELECT docid FROM t0 WHERE t0 MATCH 'abc'; +} {6 5} +do_execsql_test 8.2 { + SELECT docid FROM t0 WHERE t0 MATCH '"abc abc"'; +} {} +do_execsql_test 8.3 { COMMIT } +do_execsql_test 8.4 { + SELECT docid FROM t0 WHERE t0 MATCH 'abc'; +} {6 5} +do_execsql_test 8.5 { + SELECT docid FROM t0 WHERE t0 MATCH '"abc abc"'; +} {} + +do_execsql_test 9.1 { + CREATE VIRTUAL TABLE t9 USING fts4(a, "", '---'); +} +do_execsql_test 9.2 { + CREATE VIRTUAL TABLE t10 USING fts3(<, b, c); +} + +do_execsql_test 10.0 { + CREATE VIRTUAL TABLE z1 USING fts3; + INSERT INTO z1 VALUES('one two three'),('four one five'),('six two five'); + CREATE TRIGGER z1r1 AFTER DELETE ON z1_content BEGIN + DELETE FROM z1; + END; +} +do_catchsql_test 10.1 { + DELETE FROM z1; +} {1 {SQL logic error}} + +expand_all_sql db +finish_test diff --git a/test/fts3ab.test b/test/fts3ab.test new file mode 100644 index 0000000..86124f7 --- /dev/null +++ b/test/fts3ab.test @@ -0,0 +1,147 @@ +# 2006 September 13 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS3 module. +# +# $Id: fts3ab.test,v 1.1 2007/08/20 17:38:42 shess Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# Fill the full-text index "t1" with phrases in english, spanish, +# and german. For the i-th row, fill in the names for the bits +# that are set in the value of i. The least significant bit is +# 1. For example, the value 5 is 101 in binary which will be +# converted to "one three" in english. +# +proc fill_multilanguage_fulltext_t1 {} { + set english {one two three four five} + set spanish {un dos tres cuatro cinco} + set german {eine zwei drei vier funf} + + for {set i 1} {$i<=31} {incr i} { + set cmd "INSERT INTO t1 VALUES" + set vset {} + foreach lang {english spanish german} { + set words {} + for {set j 0; set k 1} {$j<5} {incr j; incr k $k} { + if {$k&$i} {lappend words [lindex [set $lang] $j]} + } + lappend vset "'$words'" + } + set sql "INSERT INTO t1(english,spanish,german) VALUES([join $vset ,])" + # puts $sql + db eval $sql + } +} + +# Construct a full-text search table containing five keywords: +# one, two, three, four, and five, in various combinations. The +# rowid for each will be a bitmask for the elements it contains. +# +db eval { + CREATE VIRTUAL TABLE t1 USING fts3(english,spanish,german); +} +fill_multilanguage_fulltext_t1 + +do_test fts3ab-1.1 { + execsql {SELECT rowid FROM t1 WHERE english MATCH 'one'} +} {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31} +do_test fts3ab-1.2 { + execsql {SELECT rowid FROM t1 WHERE spanish MATCH 'one'} +} {} +do_test fts3ab-1.3 { + execsql {SELECT rowid FROM t1 WHERE german MATCH 'one'} +} {} +do_test fts3ab-1.4 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'one'} +} {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31} +do_test fts3ab-1.5 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'one dos drei'} +} {7 15 23 31} +do_test fts3ab-1.6 { + execsql {SELECT english, spanish, german FROM t1 WHERE rowid=1} +} {one un eine} +do_test fts3ab-1.7 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH '"one un"'} +} {} + +do_test fts3ab-2.1 { + execsql { + CREATE VIRTUAL TABLE t2 USING fts3(from,to); + INSERT INTO t2([from],[to]) VALUES ('one two three', 'four five six'); + SELECT [from], [to] FROM t2 + } +} {{one two three} {four five six}} + + +# Compute an SQL string that contains the words one, two, three,... to +# describe bits set in the value $i. Only the lower 5 bits are examined. +# +proc wordset {i} { + set x {} + for {set j 0; set k 1} {$j<5} {incr j; incr k $k} { + if {$k&$i} {lappend x [lindex {one two three four five} $j]} + } + return '$x' +} + +# Create a new FTS table with three columns: +# +# norm: words for the bits of rowid +# plusone: words for the bits of rowid+1 +# invert: words for the bits of ~rowid +# +db eval { + CREATE VIRTUAL TABLE t4 USING fts3([norm],'plusone',"invert"); +} +for {set i 1} {$i<=15} {incr i} { + set vset [list [wordset $i] [wordset [expr {$i+1}]] [wordset [expr {~$i}]]] + db eval "INSERT INTO t4(norm,plusone,invert) VALUES([join $vset ,]);" +} + +do_test fts3ab-4.1 { + execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'norm:one'} +} {1 3 5 7 9 11 13 15} +do_test fts3ab-4.2 { + execsql {SELECT rowid FROM t4 WHERE norm MATCH 'one'} +} {1 3 5 7 9 11 13 15} +do_test fts3ab-4.3 { + execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'one'} +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15} +do_test fts3ab-4.4 { + execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'plusone:one'} +} {2 4 6 8 10 12 14} +do_test fts3ab-4.5 { + execsql {SELECT rowid FROM t4 WHERE plusone MATCH 'one'} +} {2 4 6 8 10 12 14} +do_test fts3ab-4.6 { + execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'norm:one plusone:two'} +} {1 5 9 13} +do_test fts3ab-4.7 { + execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'norm:one two'} +} {1 3 5 7 9 11 13 15} +do_test fts3ab-4.8 { + execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'plusone:two norm:one'} +} {1 5 9 13} +do_test fts3ab-4.9 { + execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'two norm:one'} +} {1 3 5 7 9 11 13 15} + + +finish_test diff --git a/test/fts3ac.test b/test/fts3ac.test new file mode 100644 index 0000000..84da924 --- /dev/null +++ b/test/fts3ac.test @@ -0,0 +1,1219 @@ +# 2006 September 14 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS3 module. +# +# $Id: fts3ac.test,v 1.1 2007/08/20 17:38:42 shess Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# Create a table of sample email data. The data comes from email +# archives of Enron executives that was published as part of the +# litigation against that company. +# +do_test fts3ac-1.1 { + db eval { + CREATE VIRTUAL TABLE email USING fts3([from],[to],subject,body); + BEGIN TRANSACTION; +INSERT INTO email([from],[to],subject,body) VALUES('savita.puthigai@enron.com', 'traders.eol@enron.com, traders.eol@enron.com', 'EnronOnline- Change to Autohedge', 'Effective Monday, October 22, 2001 the following changes will be made to the Autohedge functionality on EnronOnline. + +The volume on the hedge will now respect the minimum volume and volume increment settings on the parent product. See rules below: + +? If the transaction volume on the child is less than half of the parent''s minimum volume no hedge will occur. +? If the transaction volume on the child is more than half the parent''s minimum volume but less than half the volume increment on the parent, the hedge will volume will be the parent''s minimum volume. +? For all other volumes, the same rounding rules will apply based on the volume increment on the parent product. + +Please see example below: + +Parent''s Settings: +Minimum: 5000 +Increment: 1000 + +Volume on Autohedge transaction Volume Hedged +1 - 2499 0 +2500 - 5499 5000 +5500 - 6499 6000'); +INSERT INTO email([from],[to],subject,body) VALUES('dana.davis@enron.com', 'laynie.east@enron.com, lisa.king@enron.com, lisa.best@enron.com,', 'Leaving Early', 'FYI: +If it''s ok with everyone''s needs, I would like to leave @4pm. If you think +you will need my assistance past the 4 o''clock hour just let me know; I''ll +be more than willing to stay.'); +INSERT INTO email([from],[to],subject,body) VALUES('enron_update@concureworkplace.com', 'louise.kitchen@enron.com', '<> - CC02.06.02', 'The following expense report is ready for approval: + +Employee Name: Christopher F. Calger +Status last changed by: Mollie E. Gustafson Ms +Expense Report Name: CC02.06.02 +Report Total: $3,972.93 +Amount Due Employee: $3,972.93 + + +To approve this expense report, click on the following link for Concur Expense. +http://expensexms.enron.com'); +INSERT INTO email([from],[to],subject,body) VALUES('jeff.duff@enron.com', 'julie.johnson@enron.com', 'Work request', 'Julie, + +Could you print off the current work request report by 1:30 today? + +Gentlemen, + +I''d like to review this today at 1:30 in our office. Also, could you provide +me with your activity reports so I can have Julie enter this information. + +JD'); +INSERT INTO email([from],[to],subject,body) VALUES('v.weldon@enron.com', 'gary.l.carrier@usa.dupont.com, scott.joyce@bankofamerica.com', 'Enron News', 'This could turn into something big.... +http://biz.yahoo.com/rf/010129/n29305829.html'); +INSERT INTO email([from],[to],subject,body) VALUES('mark.haedicke@enron.com', 'paul.simons@enron.com', 'Re: First Polish Deal!', 'Congrats! Things seem to be building rapidly now on the Continent. Mark'); +INSERT INTO email([from],[to],subject,body) VALUES('e..carter@enron.com', 't..robinson@enron.com', 'FW: Producers Newsletter 9-24-2001', ' +The producer lumber pricing sheet. + -----Original Message----- +From: Johnson, Jay +Sent: Tuesday, October 16, 2001 3:42 PM +To: Carter, Karen E. +Subject: FW: Producers Newsletter 9-24-2001 + + + + -----Original Message----- +From: Daigre, Sergai +Sent: Friday, September 21, 2001 8:33 PM +Subject: Producers Newsletter 9-24-2001 + + '); +INSERT INTO email([from],[to],subject,body) VALUES('david.delainey@enron.com', 'kenneth.lay@enron.com', 'Greater Houston Partnership', 'Ken, in response to the letter from Mr Miguel San Juan, my suggestion would +be to offer up the Falcon for their use; however, given the tight time frame +and your recent visit with Mr. Fox that it would be difficult for either you +or me to participate. + +I spoke to Max and he agrees with this approach. + +I hope this meets with your approval. + +Regards +Delainey'); +INSERT INTO email([from],[to],subject,body) VALUES('lachandra.fenceroy@enron.com', 'lindy.donoho@enron.com', 'FW: Bus Applications Meeting Follow Up', 'Lindy, + +Here is the original memo we discussed earlier. Please provide any information that you may have. + +Your cooperation is greatly appreciated. + +Thanks, + +lachandra.fenceroy@enron.com +713.853.3884 +877.498.3401 Pager + + -----Original Message----- +From: Bisbee, Joanne +Sent: Wednesday, September 26, 2001 7:50 AM +To: Fenceroy, LaChandra +Subject: FW: Bus Applications Meeting Follow Up + +Lachandra, Please get with David Duff today and see what this is about. Who are our TW accounting business users? + + -----Original Message----- +From: Koh, Wendy +Sent: Tuesday, September 25, 2001 2:41 PM +To: Bisbee, Joanne +Subject: Bus Applications Meeting Follow Up + +Lisa brought up a TW change effective Nov 1. It involves eliminating a turnback surcharge. I have no other information, but you might check with the business folks for any system changes required. + +Wendy'); +INSERT INTO email([from],[to],subject,body) VALUES('danny.mccarty@enron.com', 'fran.fagan@enron.com', 'RE: worksheets', 'Fran, + If Julie''s merit needs to be lump sum, just move it over to that column. Also, send me Eric Gadd''s sheets as well. Thanks. +Dan + + -----Original Message----- +From: Fagan, Fran +Sent: Thursday, December 20, 2001 11:10 AM +To: McCarty, Danny +Subject: worksheets + +As discussed, attached are your sheets for bonus and merit. + +Thanks, + +Fran Fagan +Sr. HR Rep +713.853.5219 + + + << File: McCartyMerit.xls >> << File: mccartyBonusCommercial_UnP.xls >> + +'); +INSERT INTO email([from],[to],subject,body) VALUES('bert.meyers@enron.com', 'shift.dl-portland@enron.com', 'OCTOBER SCHEDULE', 'TEAM, + +PLEASE SEND ME ANY REQUESTS THAT YOU HAVE FOR OCTOBER. SO FAR I HAVE THEM FOR LEAF. I WOULD LIKE TO HAVE IT DONE BY THE 15TH OF THE MONTH. ANY QUESTIONS PLEASE GIVE ME A CALL. + +BERT'); +INSERT INTO email([from],[to],subject,body) VALUES('errol.mclaughlin@enron.com', 'john.arnold@enron.com, bilal.bajwa@enron.com, john.griffith@enron.com,', 'TRV Notification: (NG - PROPT P/L - 09/27/2001)', 'The report named: NG - PROPT P/L , published as of 09/27/2001 is now available for viewing on the website.'); +INSERT INTO email([from],[to],subject,body) VALUES('patrice.mims@enron.com', 'calvin.eakins@enron.com', 'Re: Small business supply assistance', 'Hi Calvin + + +I spoke with Rickey (boy, is he long-winded!!). Gave him the name of our +credit guy, Russell Diamond. + +Thank for your help!'); +INSERT INTO email([from],[to],subject,body) VALUES('legal <.hall@enron.com>', 'stephanie.panus@enron.com', 'Termination update', 'City of Vernon and Salt River Project terminated their contracts. I will fax these notices to you.'); +INSERT INTO email([from],[to],subject,body) VALUES('d..steffes@enron.com', 'richard.shapiro@enron.com', 'EES / ENA Government Affairs Staffing & Outside Services', 'Rick -- + +Here is the information on staffing and outside services. Call if you need anything else. + +Jim + + '); +INSERT INTO email([from],[to],subject,body) VALUES('gelliott@industrialinfo.com', 'pcopello@industrialinfo.com', 'ECAAR (Gavin), WSCC (Diablo Canyon), & NPCC (Seabrook)', 'Dear Power Outage Database Customer, +Attached you will find an excel document. The outages contained within are forced or rescheduled outages. Your daily delivery will still contain these outages. +In addition to the two excel documents, there is a dbf file that is formatted like your daily deliveries you receive nightly. This will enable you to load the data into your regular database. Any questions please let me know. Thanks. +Greg Elliott +IIR, Inc. +713-783-5147 x 3481 +outages@industrialinfo.com +THE INFORMATION CONTAINED IN THIS E-MAIL IS LEGALLY PRIVILEGED AND CONFIDENTIAL INFORMATION INTENDED ONLY FOR THE USE OF THE INDIVIDUAL OR ENTITY NAMED ABOVE. YOU ARE HEREBY NOTIFIED THAT ANY DISSEMINATION, DISTRIBUTION, OR COPY OF THIS E-MAIL TO UNAUTHORIZED ENTITIES IS STRICTLY PROHIBITED. IF YOU HAVE RECEIVED THIS +E-MAIL IN ERROR, PLEASE DELETE IT. + - OUTAGE.dbf + - 111201R.xls + - 111201.xls '); +INSERT INTO email([from],[to],subject,body) VALUES('enron.announcements@enron.com', 'all_ena_egm_eim@enron.com', 'EWS Brown Bag', 'MARK YOUR LUNCH CALENDARS NOW ! + +You are invited to attend the EWS Brown Bag Lunch Series + +Featuring: RAY BOWEN, COO + +Topic: Enron Industrial Markets + +Thursday, March 15, 2001 +11:30 am - 12:30 pm +EB 5 C2 + + +You bring your lunch, Limited Seating +We provide drinks and dessert. RSVP x 3-9610'); +INSERT INTO email([from],[to],subject,body) VALUES('chris.germany@enron.com', 'ingrid.immer@williams.com', 'Re: About St Pauls', 'Sounds good to me. I bet this is next to the Warick?? Hotel. + + + + +"Immer, Ingrid" on 12/21/2000 11:48:47 AM +To: "''chris.germany@enron.com''" +cc: +Subject: About St Pauls + + + + + <> +? +?http://www.stpaulshouston.org/about.html + +Chris, + +I like the looks of this place.? What do you think about going here Christmas +eve?? They have an 11:00 a.m. service and a candlelight service at 5:00 p.m., +among others. + +Let me know.?? ii + + - About St Pauls.url + +'); +INSERT INTO email([from],[to],subject,body) VALUES('nas@cpuc.ca.gov', 'skatz@sempratrading.com, kmccrea@sablaw.com, thompson@wrightlaw.com,', 'Reply Brief filed July 31, 2000', ' - CPUC01-#76371-v1-Revised_Reply_Brief__Due_today_7_31_.doc'); +INSERT INTO email([from],[to],subject,body) VALUES('gascontrol@aglresources.com', 'dscott4@enron.com, lcampbel@enron.com', 'Alert Posted 10:00 AM November 20,2000: E-GAS Request Reminder', 'Alert Posted 10:00 AM November 20,2000: E-GAS Request Reminder +As discussed in the Winter Operations Meeting on Sept.29,2000, +E-Gas(Emergency Gas) will not be offered this winter as a service from AGLC. +Marketers and Poolers can receive gas via Peaking and IBSS nominations(daisy +chain) from other marketers up to the 6 p.m. Same Day 2 nomination cycle. +'); +INSERT INTO email([from],[to],subject,body) VALUES('dutch.quigley@enron.com', 'rwolkwitz@powermerchants.com', '', ' + +Here is a goody for you'); +INSERT INTO email([from],[to],subject,body) VALUES('ryan.o''rourke@enron.com', 'k..allen@enron.com, randy.bhatia@enron.com, frank.ermis@enron.com,', 'TRV Notification: (West VaR - 11/07/2001)', 'The report named: West VaR , published as of 11/07/2001 is now available for viewing on the website.'); +INSERT INTO email([from],[to],subject,body) VALUES('mjones7@txu.com', 'cstone1@txu.com, ggreen2@txu.com, timpowell@txu.com,', 'Enron / HPL Actuals for July 10, 2000', 'Teco Tap 10.000 / Enron ; 110.000 / HPL IFERC + +LS HPL LSK IC 30.000 / Enron +'); +INSERT INTO email([from],[to],subject,body) VALUES('susan.pereira@enron.com', 'kkw816@aol.com', 'soccer practice', 'Kathy- + +Is it safe to assume that practice is cancelled for tonight?? + +Susan Pereira'); +INSERT INTO email([from],[to],subject,body) VALUES('mark.whitt@enron.com', 'barry.tycholiz@enron.com', 'Huber Internal Memo', 'Please look at this. I didn''t know how deep to go with the desk. Do you think this works. + + '); +INSERT INTO email([from],[to],subject,body) VALUES('m..forney@enron.com', 'george.phillips@enron.com', '', 'George, +Give me a call and we will further discuss opportunities on the 13st floor. + +Thanks, +JMForney +3-7160'); +INSERT INTO email([from],[to],subject,body) VALUES('brad.mckay@enron.com', 'angusmcka@aol.com', 'Re: (no subject)', 'not yet'); +INSERT INTO email([from],[to],subject,body) VALUES('adam.bayer@enron.com', 'jonathan.mckay@enron.com', 'FW: Curve Fetch File', 'Here is the curve fetch file sent to me. It has plenty of points in it. If you give me a list of which ones you need we may be able to construct a secondary worksheet to vlookup the values. + +adam +35227 + + + -----Original Message----- +From: Royed, Jeff +Sent: Tuesday, September 25, 2001 11:37 AM +To: Bayer, Adam +Subject: Curve Fetch File + +Let me know if it works. It may be required to have a certain version of Oracle for it to work properly. + + + +Jeff Royed +Enron +Energy Operations +Phone: 713-853-5295'); +INSERT INTO email([from],[to],subject,body) VALUES('matt.smith@enron.com', 'yan.wang@enron.com', 'Report Formats', 'Yan, + +The merged reports look great. I believe the only orientation changes are to +"unmerge" the following six reports: + +31 Keystone Receipts +15 Questar Pipeline +40 Rockies Production +22 West_2 +23 West_3 +25 CIG_WIC + +The orientation of the individual reports should be correct. Thanks. + +Mat + +PS. Just a reminder to add the "*" by the title of calculated points.'); +INSERT INTO email([from],[to],subject,body) VALUES('michelle.lokay@enron.com', 'jimboman@bigfoot.com', 'Egyptian Festival', '---------------------- Forwarded by Michelle Lokay/ET&S/Enron on 09/07/2000 +10:08 AM --------------------------- + + +"Karkour, Randa" on 09/07/2000 09:01:04 AM +To: "''Agheb (E-mail)" , "Leila Mankarious (E-mail)" +, "''Marymankarious (E-mail)" +, "Michelle lokay (E-mail)" , "Ramy +Mankarious (E-mail)" +cc: + +Subject: Egyptian Festival + + + <> + + http://www.egyptianfestival.com/ + + - Egyptian Festival.url +'); +INSERT INTO email([from],[to],subject,body) VALUES('errol.mclaughlin@enron.com', 'sherry.dawson@enron.com', 'Urgent!!! --- New EAST books', 'This has to be done.................................. + +Thanks +---------------------- Forwarded by Errol McLaughlin/Corp/Enron on 12/20/2000 +08:39 AM --------------------------- + + + + From: William Kelly @ ECT 12/20/2000 08:31 AM + + +To: Kam Keiser/HOU/ECT@ECT, Darron C Giron/HOU/ECT@ECT, David +Baumbach/HOU/ECT@ECT, Errol McLaughlin/Corp/Enron@ENRON +cc: Kimat Singla/HOU/ECT@ECT, Kulvinder Fowler/NA/Enron@ENRON, Kyle R +Lilly/HOU/ECT@ECT, Jeff Royed/Corp/Enron@ENRON, Alejandra +Chavez/NA/Enron@ENRON, Crystal Hyde/HOU/ECT@ECT + +Subject: New EAST books + +We have new book names in TAGG for our intramonth portfolios and it is +extremely important that any deal booked to the East is communicated quickly +to someone on my team. I know it will take some time for the new names to +sink in and I do not want us to miss any positions or P&L. + +Thanks for your help on this. + +New: +Scott Neal : East Northeast +Dick Jenkins: East Marketeast + +WK +'); +INSERT INTO email([from],[to],subject,body) VALUES('david.forster@enron.com', 'eol.wide@enron.com', 'Change to Stack Manager', 'Effective immediately, there is a change to the Stack Manager which will +affect any Inactive Child. + +An inactive Child with links to Parent products will not have their +calculated prices updated until the Child product is Activated. + +When the Child Product is activated, the price will be recalculated and +updated BEFORE it is displayed on the web. + +This means that if you are inputting a basis price on a Child product, you +will not see the final, calculated price until you Activate the product, at +which time the customer will also see it. + +If you have any questions, please contact the Help Desk on: + +Americas: 713 853 4357 +Europe: + 44 (0) 20 7783 7783 +Asia/Australia: +61 2 9229 2300 + +Dave'); +INSERT INTO email([from],[to],subject,body) VALUES('vince.kaminski@enron.com', 'jhh1@email.msn.com', 'Re: Light reading - see pieces beginning on page 7', 'John, + +I saw it. Very interesting. + +Vince + + + + + +"John H Herbert" on 07/28/2000 08:38:08 AM +To: "Vince J Kaminski" +cc: +Subject: Light reading - see pieces beginning on page 7 + + +Cheers and have a nice weekend, + + +JHHerbert + + + + + - gd000728.pdf + + + +'); +INSERT INTO email([from],[to],subject,body) VALUES('matthew.lenhart@enron.com', 'mmmarcantel@equiva.com', 'RE:', 'i will try to line up a pig for you '); +INSERT INTO email([from],[to],subject,body) VALUES('jae.black@enron.com', 'claudette.harvey@enron.com, chaun.roberts@enron.com, judy.martinez@enron.com,', 'Disaster Recovery Equipment', 'As a reminder...there are several pieces of equipment that are set up on the 30th Floor, as well as on our floor, for the Disaster Recovery Team. PLEASE DO NOT TAKE, BORROW OR USE this equipment. Should you need to use another computer system, other than yours, or make conference calls please work with your Assistant to help find or set up equipment for you to use. + +Thanks for your understanding in this matter. + +T.Jae Black +East Power Trading +Assistant to Kevin Presto +off. 713-853-5800 +fax 713-646-8272 +cell 713-539-4760'); +INSERT INTO email([from],[to],subject,body) VALUES('eric.bass@enron.com', 'dale.neuner@enron.com', '5 X 24', 'Dale, + +Have you heard anything more on the 5 X 24s? We would like to get this +product out ASAP. + + +Thanks, + +Eric'); +INSERT INTO email([from],[to],subject,body) VALUES('messenger@smartreminders.com', 'm..tholt@enron.com', '10% Coupon - PrintPal Printer Cartridges - 100% Guaranteed', '[IMAGE] +[IMAGE][IMAGE][IMAGE] +Dear SmartReminders Member, + [IMAGE] [IMAGE] [IMAGE] [IMAGE] [IMAGE] [IMAGE] [IMAGE] [IMAGE] + + + + + + + + + + + + + + + + + + + + + +We respect your privacy and are a Certified Participant of the BBBOnLine + Privacy Program. To be removed from future offers,click here. +SmartReminders.com is a permission based service. To unsubscribe click here . '); +INSERT INTO email([from],[to],subject,body) VALUES('benjamin.rogers@enron.com', 'mark.bernstein@enron.com', '', 'The guy you are talking about left CIN under a "cloud of suspicion" sort of +speak. He was the one who got into several bad deals and PPA''s in California +for CIN, thus he left on a bad note. Let me know if you need more detail +than that, I felt this was the type of info you were looking for. Thanks! +Ben'); +INSERT INTO email([from],[to],subject,body) VALUES('enron_update@concureworkplace.com', 'michelle.cash@enron.com', 'Expense Report Receipts Not Received', 'Employee Name: Michelle Cash +Report Name: Houston Cellular 8-11-01 +Report Date: 12/13/01 +Report ID: 594D37C9ED2111D5B452 +Submitted On: 12/13/01 + +You are only allowed 2 reports with receipts outstanding. Your expense reports will not be paid until you meet this requirement.'); +INSERT INTO email([from],[to],subject,body) VALUES('susan.mara@enron.com', 'ray.alvarez@enron.com, mark.palmer@enron.com, karen.denne@enron.com,', 'CAISO Emergency Motion -- to discontinue market-based rates for', 'FYI. the latest broadside against the generators. + +Sue Mara +Enron Corp. +Tel: (415) 782-7802 +Fax:(415) 782-7854 +----- Forwarded by Susan J Mara/NA/Enron on 06/08/2001 12:24 PM ----- + + + "Milner, Marcie" 06/08/2001 11:13 AM To: "''smara@enron.com''" cc: Subject: CAISO Emergency Motion + + +Sue, did you see this emergency motion the CAISO filed today? Apparently +they are requesting that FERC discontinue market-based rates immediately and +grant refunds plus interest on the difference between cost-based rates and +market revenues received back to May 2000. They are requesting the +commission act within 14 days. Have you heard anything about what they are +doing? + +Marcie + +http://www.caiso.com/docs/2001/06/08/200106081005526469.pdf +'); +INSERT INTO email([from],[to],subject,body) VALUES('fletcher.sturm@enron.com', 'eloy.escobar@enron.com', 'Re: General Brinks Position Meeting', 'Eloy, + +Who is General Brinks? + +Fletch'); +INSERT INTO email([from],[to],subject,body) VALUES('nailia.dindarova@enron.com', 'richard.shapiro@enron.com', 'Documents for Mark Frevert (on EU developments and lessons from', 'Rick, + +Here are the documents that Peter has prepared for Mark Frevert. + +Nailia +---------------------- Forwarded by Nailia Dindarova/LON/ECT on 25/06/2001 +16:36 --------------------------- + + +Nailia Dindarova +25/06/2001 15:36 +To: Michael Brown/Enron@EUEnronXGate +cc: Ross Sankey/Enron@EUEnronXGate, Eric Shaw/ENRON@EUEnronXGate, Peter +Styles/LON/ECT@ECT + +Subject: Documents for Mark Frevert (on EU developments and lessons from +California) + +Michael, + + +These are the documents that Peter promised to give to you for Mark Frevert. +He has now handed them to him in person but asked me to transmit them +electronically to you, as well as Eric and Ross. + +Nailia + + + + + +'); +INSERT INTO email([from],[to],subject,body) VALUES('peggy.a.kostial@accenture.com', 'dave.samuels@enron.com', 'EOL-Accenture Deal Sheet', 'Dave - + +Attached are our comments and suggested changes. Please call to review. + +On the time line for completion, we have four critical steps to complete: + Finalize market analysis to refine business case, specifically + projected revenue stream + Complete counterparty surveying, including targeting 3 CPs for letters + of intent + Review Enron asset base for potential reuse/ licensing + Contract negotiations + +Joe will come back to us with an updated time line, but it is my +expectation that we are still on the same schedule (we just begun week +three) with possibly a week or so slippage.....contract negotiations will +probably be the critical path. + +We will send our cut at the actual time line here shortly. Thanks, + +Peggy + +(See attached file: accenture-dealpoints v2.doc) + - accenture-dealpoints v2.doc '); +INSERT INTO email([from],[to],subject,body) VALUES('thomas.martin@enron.com', 'thomas.martin@enron.com', 'Re: Guadalupe Power Partners LP', '---------------------- Forwarded by Thomas A Martin/HOU/ECT on 03/20/2001 +03:49 PM --------------------------- + + +Thomas A Martin +10/11/2000 03:55 PM +To: Patrick Wade/HOU/ECT@ECT +cc: +Subject: Re: Guadalupe Power Partners LP + +The deal is physically served at Oasis Waha or Oasis Katy and is priced at +either HSC, Waha or Katytailgate GD at buyers option three days prior to +NYMEX close. + +'); +INSERT INTO email([from],[to],subject,body) VALUES('judy.townsend@enron.com', 'dan.junek@enron.com, chris.germany@enron.com', 'Columbia Distribution''s Capacity Available for Release - Sum', '---------------------- Forwarded by Judy Townsend/HOU/ECT on 03/09/2001 11:04 +AM --------------------------- + + +agoddard@nisource.com on 03/08/2001 09:16:57 AM +To: " - *Koch, Kent" , " - +*Millar, Debra" , " - *Burke, Lynn" + +cc: " - *Heckathorn, Tom" +Subject: Columbia Distribution''s Capacity Available for Release - Sum + + +Attached is Columbia Distribution''s notice of capacity available for release +for +the summer of 2001 (Apr. 2001 through Oct. 2001). + +Please note that the deadline for bids is 3:00pm EST on March 20, 2001. + +If you have any questions, feel free to contact any of the representatives +listed +at the bottom of the attachment. + +Aaron Goddard + + + + + - 2001Summer.doc +'); +INSERT INTO email([from],[to],subject,body) VALUES('rhonda.denton@enron.com', 'tim.belden@enron.com, dana.davis@enron.com, genia.fitzgerald@enron.com,', 'Split Rock Energy LLC', 'We have received the executed EEI contract from this CP dated 12/12/2000. +Copies will be distributed to Legal and Credit.'); +INSERT INTO email([from],[to],subject,body) VALUES('kerrymcelroy@dwt.com', 'jack.speer@alcoa.com, crow@millernash.com, michaelearly@earthlink.net,', 'Oral Argument Request', ' - Oral Argument Request.doc'); +INSERT INTO email([from],[to],subject,body) VALUES('mike.carson@enron.com', 'rlmichaelis@hormel.com', '', 'Did you come in town this wk end..... My new number at our house is : +713-668-3712...... my cell # is 281-381-7332 + +the kid'); +INSERT INTO email([from],[to],subject,body) VALUES('cooper.richey@enron.com', 'trycooper@hotmail.com', 'FW: Contact Info', ' + +-----Original Message----- +From: Punja, Karim +Sent: Thursday, December 13, 2001 2:35 PM +To: Richey, Cooper +Subject: Contact Info + + +Cooper, + +Its been a real pleasure working with you (even though it was for only a small amount of time) +I hope we can stay in touch. + +Home# 234-0249 +email: kpunja@hotmail.com + +Take Care, + +Karim. + '); +INSERT INTO email([from],[to],subject,body) VALUES('bjm30@earthlink.net', 'mcguinn.k@enron.com, mcguinn.ian@enron.com, mcguinn.stephen@enron.com,', 'email address change', 'Hello all. + +I haven''t talked to many of you via email recently but I do want to give you +my new address for your email file: + + bjm30@earthlink.net + +I hope all is well. + +Brian McGuinn'); +INSERT INTO email([from],[to],subject,body) VALUES('shelley.corman@enron.com', 'steve.hotte@enron.com', 'Flat Panels', 'Can you please advise what is going on with the flat panels that we had planned to distribute to our gas logistics team. It was in the budget and we had the okay, but now I''m hearing there is some hold-up & the units are stored on 44. + +Shelley'); +INSERT INTO email([from],[to],subject,body) VALUES('sara.davidson@enron.com', 'john.schwartzenburg@enron.com, scott.dieball@enron.com, recipients@enron.com,', '2001 Enron Law Conference (Distribution List 2)', ' Enron Law Conference + +San Antonio, Texas May 2-4, 2001 Westin Riverwalk + + See attached memo for more details!! + + +? Registration for the law conference this year will be handled through an +Online RSVP Form on the Enron Law Conference Website at +http://lawconference.corp.enron.com. The website is still under construction +and will not be available until Thursday, March 15, 2001. + +? We will send you another e-mail to confirm when the Law Conference Website +is operational. + +? Please complete the Online RSVP Form as soon as it is available and submit +it no later than Friday, March 30th. + + + + +'); +INSERT INTO email([from],[to],subject,body) VALUES('tori.kuykendall@enron.com', 'heath.b.taylor@accenture.com', 'Re:', 'hey - thats funny about john - he definitely remembers him - i''ll call pat +and let him know - we are coming on saturday - i just havent had a chance to +call you guys back -- looking forward to it -- i probably need the +directions again though'); +INSERT INTO email([from],[to],subject,body) VALUES('darron.giron@enron.com', 'bryce.baxter@enron.com', 'Re: Feedback for Audrey Cook', 'Bryce, + +I''ll get it done today. + +DG 3-9573 + + + + + + From: Bryce Baxter 06/12/2000 07:15 PM + + +To: Darron C Giron/HOU/ECT@ECT +cc: +Subject: Feedback for Audrey Cook + +You were identified as a reviewer for Audrey Cook. If possible, could you +complete her feedback by end of business Wednesday? It will really help me +in the PRC process to have your input. Thanks. + +'); +INSERT INTO email([from],[to],subject,body) VALUES('casey.evans@enron.com', 'stephanie.sever@enron.com', 'Gas EOL ID', 'Stephanie, + +In conjunction with the recent movement of several power traders, they are changing the names of their gas books as well. The names of the new gas books and traders are as follows: + +PWR-NG-LT-SPP: Mike Carson +PWR-NG-LT-SERC: Jeff King + +If you need to know their power desk to map their ID to their gas books, those desks are as follows: + +EPMI-LT-SPP: Mike Carson +EPMI-LT-SERC: Jeff King + +I will be in training this afternoon, but will be back when class is over. Let me know if you have any questions. + +Thanks for your help! +Casey'); +INSERT INTO email([from],[to],subject,body) VALUES('darrell.schoolcraft@enron.com', 'david.roensch@enron.com, kimberly.watson@enron.com, michelle.lokay@enron.com,', 'Postings', 'Please see the attached. + + +ds + + + + + '); +INSERT INTO email([from],[to],subject,body) VALUES('mcominsky@aol.com', 'cpatman@bracepatt.com, james_derrick@enron.com', 'Jurisprudence Luncheon', 'Carrin & Jim -- + +It was an honor and a pleasure to meet both of you yesterday. I know we will +have fun working together on this very special event. + +Jeff left the jurisprudence luncheon lists for me before he left on vacation. + I wasn''t sure whether he transmitted them to you as well. Would you please +advise me if you would like them sent to you? I can email the MS Excel files +or I can fax the hard copies to you. Please advise what is most convenient. + +I plan to be in town through the holidays and can be reached by phone, email, +or cell phone at any time. My cell phone number is 713/705-4829. + +Thanks again for your interest in the ADL''s work. Martin. + +Martin B. Cominsky +Director, Southwest Region +Anti-Defamation League +713/627-3490, ext. 122 +713/627-2011 (fax) +MCominsky@aol.com'); +INSERT INTO email([from],[to],subject,body) VALUES('phillip.love@enron.com', 'todagost@utmb.edu, gbsonnta@utmb.edu', 'New President', 'I had a little bird put a word in my ear. Is there any possibility for Ben +Raimer to be Bush''s secretary of HHS? Just curious about that infamous UTMB +rumor mill. Hope things are well, happy holidays. +PL'); +INSERT INTO email([from],[to],subject,body) VALUES('marie.heard@enron.com', 'ehamilton@fna.com', 'ISDA Master Agreement', 'Erin: + +Pursuant to your request, attached are the Schedule to the ISDA Master Agreement, together with Paragraph 13 to the ISDA Credit Support Annex. Please let me know if you need anything else. We look forward to hearing your comments. + +Marie + +Marie Heard +Senior Legal Specialist +Enron North America Corp. +Phone: (713) 853-3907 +Fax: (713) 646-3490 +marie.heard@enron.com + + '); +INSERT INTO email([from],[to],subject,body) VALUES('andrea.ring@enron.com', 'beverly.beaty@enron.com', 'Re: Tennessee Buy - Louis Dreyfus', 'Beverly - once again thanks so much for your help on this. + + + + '); +INSERT INTO email([from],[to],subject,body) VALUES('karolyn.criado@enron.com', 'j..bonin@enron.com, felicia.case@enron.com, b..clapp@enron.com,', 'Price List week of Oct. 8-9, 2001', ' +Please contact me if you have any questions regarding last weeks prices. + +Thank you, +Karolyn Criado +3-9441 + + + + +'); +INSERT INTO email([from],[to],subject,body) VALUES('kevin.presto@enron.com', 'edward.baughman@enron.com, billy.braddock@enron.com', 'Associated', 'Please begin working on filling our Associated short position in 02. I would like to take this risk off the books. + +In addition, please find out what a buy-out of VEPCO would cost us. With Rogers transitioning to run our retail risk management, I would like to clean up our customer positions. + +We also need to continue to explore a JEA buy-out. + +Thanks.'); +INSERT INTO email([from],[to],subject,body) VALUES('stacy.dickson@enron.com', 'gregg.penman@enron.com', 'RE: Constellation TC 5-7-01', 'Gregg, + +I am at home with a sick baby. (Lots of fun!) I will call you about this +tomorrow. + +Stacy'); +INSERT INTO email([from],[to],subject,body) VALUES('joe.quenet@enron.com', 'dfincher@utilicorp.com', '', 'hey big guy.....check this out..... + + w ww.gorelieberman-2000.com/'); +INSERT INTO email([from],[to],subject,body) VALUES('k..allen@enron.com', 'jacqestc@aol.com', '', 'Jacques, + +I sent you a fax of Kevin Kolb''s comments on the release. The payoff on the note would be $36,248 ($36090(principal) + $158 (accrued interest)). +This is assuming we wrap this up on Tuesday. + +Please email to confirm that their changes are ok so I can set up a meeting on Tuesday to reach closure. + +Phillip'); +INSERT INTO email([from],[to],subject,body) VALUES('kourtney.nelson@enron.com', 'mike.swerzbin@enron.com', 'Adjusted L/R Balance', 'Mike, + +I placed the adjusted L/R Balance on the Enronwest site. It is under the "Staff/Kourtney Nelson". There are two links: + +1) "Adj L_R" is the same data/format from the weekly strategy meeting. +2) "New Gen 2001_2002" link has all of the supply side info that is used to calculate the L/R balance + -Please note the Data Flag column, a value of "3" indicates the project was cancelled, on hold, etc and is not included in the calc. + +Both of these sheets are interactive Excel spreadsheets and thus you can play around with the data as you please. Also, James Bruce is working to get his gen report on the web. That will help with your access to information on new gen. + +Please let me know if you have any questions or feedback, + +Kourtney + + + +Kourtney Nelson +Fundamental Analysis +Enron North America +(503) 464-8280 +kourtney.nelson@enron.com'); +INSERT INTO email([from],[to],subject,body) VALUES('d..thomas@enron.com', 'naveed.ahmed@enron.com', 'FW: Current Enron TCC Portfolio', ' + +-----Original Message----- +From: Grace, Rebecca M. +Sent: Monday, December 17, 2001 9:44 AM +To: Thomas, Paul D. +Cc: Cashion, Jim; Allen, Thresa A.; May, Tom +Subject: RE: Current Enron TCC Portfolio + + +Paul, + +I reviewed NY''s list. I agree with all of their contracts numbers and mw amounts. + +Call if you have any more questions. + +Rebecca + + + + -----Original Message----- +From: Thomas, Paul D. +Sent: Monday, December 17, 2001 9:08 AM +To: Grace, Rebecca M. +Subject: FW: Current Enron TCC Portfolio + + << File: enrontccs.xls >> +Rebecca, +Let me know if you see any differences. + +Paul +X 3-0403 +-----Original Message----- +From: Thomas, Paul D. +Sent: Monday, December 17, 2001 9:04 AM +To: Ahmed, Naveed +Subject: FW: Current Enron TCC Portfolio + + + + +-----Original Message----- +From: Thomas, Paul D. +Sent: Thursday, December 13, 2001 10:01 AM +To: Baughman, Edward D. +Subject: Current Enron TCC Portfolio + + +'); +INSERT INTO email([from],[to],subject,body) VALUES('stephanie.panus@enron.com', 'william.bradford@enron.com, debbie.brackett@enron.com,', 'Coastal Merchant Energy/El Paso Merchant Energy', 'Coastal Merchant Energy, L.P. merged with and into El Paso Merchant Energy, +L.P., effective February 1, 2001, with the surviving entity being El Paso +Merchant Energy, L.P. We currently have ISDA Master Agreements with both +counterparties. Please see the attached memo regarding the existing Masters +and let us know which agreement should be terminated. + +Thanks, +Stephanie +'); +INSERT INTO email([from],[to],subject,body) VALUES('kam.keiser@enron.com', 'c..kenne@enron.com', 'RE: What about this too???', ' + + -----Original Message----- +From: Kenne, Dawn C. +Sent: Wednesday, February 06, 2002 11:50 AM +To: Keiser, Kam +Subject: What about this too??? + + + << File: Netco Trader Matrix.xls >> + '); +INSERT INTO email([from],[to],subject,body) VALUES('chris.meyer@enron.com', 'joe.parks@enron.com', 'Centana', 'Talked to Chip. We do need Cash Committe approval given the netting feature of your deal, which means Batch Funding Request. Please update per my previous e-mail and forward. + +Thanks + +chris +x31666'); +INSERT INTO email([from],[to],subject,body) VALUES('debra.perlingiere@enron.com', 'jworman@academyofhealth.com', '', 'Have a great weekend! Happy Fathers Day! + + +Debra Perlingiere +Enron North America Corp. +1400 Smith Street, EB 3885 +Houston, Texas 77002 +dperlin@enron.com +Phone 713-853-7658 +Fax 713-646-3490'); +INSERT INTO email([from],[to],subject,body) VALUES('outlook.team@enron.com', '', 'Demo by Martha Janousek of Dashboard & Pipeline Profile / Julia &', 'CALENDAR ENTRY: APPOINTMENT + +Description: + Demo by Martha Janousek of Dashboard & Pipeline Profile / Julia & Dir Rpts. - 4102 + +Date: 1/5/2001 +Time: 9:00 AM - 10:00 AM (Central Standard Time) + +Chairperson: Outlook Migration Team + +Detailed Description:'); +INSERT INTO email([from],[to],subject,body) VALUES('diana.seifert@enron.com', 'mark.taylor@enron.com', 'Guest access Chile', 'Hello Mark, + +Justin Boyd told me that your can help me with questions regarding Chile. +We got a request for guest access through MG. +The company is called Escondida and is a subsidiary of BHP Australia. + +Please advise if I can set up a guest account or not. +F.Y.I.: MG is planning to put a "in w/h Chile" contract for Copper on-line as +soon as Enron has done the due diligence for this country. +Thanks ! + + +Best regards + +Diana Seifert +EOL PCG'); +INSERT INTO email([from],[to],subject,body) VALUES('enron_update@concureworkplace.com', 'mark.whitt@enron.com', '<> - 121001', 'The Approval status has changed on the following report: + +Status last changed by: Barry L. Tycholiz +Expense Report Name: 121001 +Report Total: $198.98 +Amount Due Employee: $198.98 +Amount Approved: $198.98 +Amount Paid: $0.00 +Approval Status: Approved +Payment Status: Pending + + +To review this expense report, click on the following link for Concur Expense. +http://expensexms.enron.com'); +INSERT INTO email([from],[to],subject,body) VALUES('kevin.hyatt@enron.com', '', 'Technical Support', 'Outside the U.S., please refer to the list below: + +Australia: +1800 678-515 +support@palm-au.com + +Canada: +1905 305-6530 +support@palm.com + +New Zealand: +0800 446-398 +support@palm-nz.com + +U.K.: +0171 867 0108 +eurosupport@palm.3com.com + +Please refer to the Worldwide Customer Support card for a complete technical support contact list.'); +INSERT INTO email([from],[to],subject,body) VALUES('geoff.storey@enron.com', 'dutch.quigley@enron.com', 'RE:', 'duke contact? + + -----Original Message----- +From: Quigley, Dutch +Sent: Wednesday, October 31, 2001 10:14 AM +To: Storey, Geoff +Subject: RE: + +bp corp Albert LaMore 281-366-4962 + +running the reports now + + + -----Original Message----- +From: Storey, Geoff +Sent: Wednesday, October 31, 2001 10:10 AM +To: Quigley, Dutch +Subject: RE: + +give me a contact over there too +BP + + + -----Original Message----- +From: Quigley, Dutch +Sent: Wednesday, October 31, 2001 9:42 AM +To: Storey, Geoff +Subject: + +Coral Jeff Whitnah 713-767-5374 +Relaint Steve McGinn 713-207-4000'); +INSERT INTO email([from],[to],subject,body) VALUES('pete.davis@enron.com', 'pete.davis@enron.com', 'Start Date: 4/22/01; HourAhead hour: 3; ', 'Start Date: 4/22/01; HourAhead hour: 3; No ancillary schedules awarded. +Variances detected. +Variances detected in Load schedule. + + LOG MESSAGES: + +PARSING FILE -->> O:\Portland\WestDesk\California Scheduling\ISO Final +Schedules\2001042203.txt + +---- Load Schedule ---- +$$$ Variance found in table tblLoads. + Details: (Hour: 3 / Preferred: 1.92 / Final: 1.89) + TRANS_TYPE: FINAL + LOAD_ID: PGE4 + MKT_TYPE: 2 + TRANS_DATE: 4/22/01 + SC_ID: EPMI + +'); +INSERT INTO email([from],[to],subject,body) VALUES('john.postlethwaite@enron.com', 'john.zufferli@enron.com', 'Reference', 'John, hope things are going well up there for you. The big day is almost here for you and Jessica. I was wondering if I could use your name as a job reference if need be. I am just trying to get everything in order just in case something happens. + +John'); +INSERT INTO email([from],[to],subject,body) VALUES('jeffrey.shankman@enron.com', 'lschiffm@jonesday.com', 'Re:', 'I saw you called on the cell this a.m. Sorry I missed you. (I was in the +shower). I have had a shitty week--I suspect my silence (not only to you, +but others) after our phone call is a result of the week. I''m seeing Glen at +11:15....talk to you'); +INSERT INTO email([from],[to],subject,body) VALUES('litebytz@enron.com', '', 'Lite Bytz RSVP', ' +This week''s Lite Bytz presentation will feature the following TOOLZ speaker: + +Richard McDougall +Solaris 8 +Thursday, June 7, 2001 + +If you have not already signed up, please RSVP via email to litebytz@enron.com by the end of the day Tuesday, June 5, 2001. + +*Remember: this is now a Brown Bag Event--so bring your lunch and we will provide cookies and drinks. + +Click below for more details. + +http://home.enron.com:84/messaging/litebytztoolzprint.jpg'); + COMMIT; + } +} {} + +############################################################################### +# Everything above just builds an interesting test database. The actual +# tests come after this comment. +############################################################################### + +do_test fts3ac-1.2 { + execsql { + SELECT rowid FROM email WHERE email MATCH 'mark' + } +} {6 17 25 38 40 42 73 74} +do_test fts3ac-1.3 { + execsql { + SELECT rowid FROM email WHERE email MATCH 'susan' + } +} {24 40} +do_test fts3ac-1.4 { + execsql { + SELECT rowid FROM email WHERE email MATCH 'mark susan' + } +} {40} +do_test fts3ac-1.5 { + execsql { + SELECT rowid FROM email WHERE email MATCH 'susan mark' + } +} {40} +do_test fts3ac-1.6 { + execsql { + SELECT rowid FROM email WHERE email MATCH '"mark susan"' + } +} {} +do_test fts3ac-1.7 { + execsql { + SELECT rowid FROM email WHERE email MATCH 'mark -susan' + } +} {6 17 25 38 42 73 74} +do_test fts3ac-1.8 { + execsql { + SELECT rowid FROM email WHERE email MATCH '-mark susan' + } +} {24} +do_test fts3ac-1.9 { + execsql { + SELECT rowid FROM email WHERE email MATCH 'mark OR susan' + } +} {6 17 24 25 38 40 42 73 74} + +# Some simple tests of the automatic "offsets(email)" column. In the sample +# data set above, only one message, number 20, contains the words +# "gas" and "reminder" in both body and subject. +# +do_test fts3ac-2.1 { + execsql { + SELECT rowid, offsets(email) FROM email + WHERE email MATCH 'gas reminder' + } +} {20 {2 0 42 3 2 1 54 8 3 0 42 3 3 1 54 8 3 0 129 3 3 0 143 3 3 0 240 3}} +do_test fts3ac-2.2 { + execsql { + SELECT rowid, offsets(email) FROM email + WHERE email MATCH 'subject:gas reminder' + } +} {20 {2 0 42 3 2 1 54 8 3 1 54 8}} +do_test fts3ac-2.3 { + execsql { + SELECT rowid, offsets(email) FROM email + WHERE email MATCH 'body:gas reminder' + } +} {20 {2 1 54 8 3 0 42 3 3 1 54 8 3 0 129 3 3 0 143 3 3 0 240 3}} +do_test fts3ac-2.4 { + execsql { + SELECT rowid, offsets(email) FROM email + WHERE subject MATCH 'gas reminder' + } +} {20 {2 0 42 3 2 1 54 8}} +do_test fts3ac-2.5 { + execsql { + SELECT rowid, offsets(email) FROM email + WHERE body MATCH 'gas reminder' + } +} {20 {3 0 42 3 3 1 54 8 3 0 129 3 3 0 143 3 3 0 240 3}} + +# Document 32 contains 5 instances of the world "child". But only +# 3 of them are paired with "product". Make sure only those instances +# that match the phrase appear in the offsets(email) list. +# +do_test fts3ac-3.1 { + execsql { + SELECT rowid, offsets(email) FROM email + WHERE body MATCH 'child product' AND +rowid=32 + } +} {32 {3 0 94 5 3 0 114 5 3 0 207 5 3 1 213 7 3 0 245 5 3 1 251 7 3 0 409 5 3 1 415 7 3 1 493 7}} +do_test fts3ac-3.2 { + execsql { + SELECT rowid, offsets(email) FROM email + WHERE body MATCH '"child product"' + } +} {32 {3 0 207 5 3 1 213 7 3 0 245 5 3 1 251 7 3 0 409 5 3 1 415 7}} + +# Snippet generator tests +# +do_test fts3ac-4.1 { + execsql { + SELECT snippet(email) FROM email + WHERE email MATCH 'subject:gas reminder' + } +} {{Alert Posted 10:00 AM November 20,2000: E-GAS Request Reminder}} +do_test fts3ac-4.2 { + execsql { + SELECT snippet(email) FROM email + WHERE email MATCH 'christmas candlelight' + } +} {{...here Christmas +eve?? They have an 11:00 a.m. service and a candlelight service...}} + +do_test fts3ac-4.3 { + execsql { + SELECT snippet(email) FROM email + WHERE email MATCH 'deal sheet potential reuse' + } +} {{EOL-Accenture Deal Sheet...asset base for potential reuse/ licensing + Contract negotiations...}} +do_test fts3ac-4.4 { + execsql { + SELECT snippet(email,'<<<','>>>',' ') FROM email + WHERE email MATCH 'deal sheet potential reuse' + } +} {{EOL-Accenture <<>> <<>> asset base for <<>> <<>>/ licensing + Contract negotiations }} +do_test fts3ac-4.5 { + execsql { + SELECT snippet(email,'<<<','>>>',' ') FROM email + WHERE email MATCH 'first things' + } +} {{Re: <<>> Polish Deal! Congrats! <<>> seem to be building rapidly now }} +do_test fts3ac-4.6 { + execsql { + SELECT snippet(email) FROM email + WHERE email MATCH 'chris is here' + } +} {{...chris.germany@enron.com'" <chris...bet this is next to...about going here Christmas +eve...}} +do_test fts3ac-4.7 { + execsql { + SELECT snippet(email) FROM email + WHERE email MATCH '"pursuant to"' + } +} {{Erin: + +Pursuant to your request, attached are the Schedule to the ISDA Master Agreement, together...}} +do_test fts3ac-4.8 { + execsql { + SELECT snippet(email) FROM email + WHERE email MATCH 'ancillary load davis' + } +} {{pete.davis@enron.com...3; No ancillary schedules awarded...detected in Load schedule. + + LOG...}} + +# Combinations of AND and OR operators: +# +do_test fts3ac-5.1 { + execsql { + SELECT snippet(email) FROM email + WHERE email MATCH 'questar enron OR com' + } +} {{matt.smith@enron.com...31 Keystone Receipts +15 Questar Pipeline +40 Rockies...}} + +do_test fts3ac-5.2 { + execsql { + SELECT snippet(email) FROM email + WHERE email MATCH 'enron OR com questar' + } +} {{matt.smith@enron.com...31 Keystone Receipts +15 Questar Pipeline +40 Rockies...}} + +#------------------------------------------------------------------------- +# Test a problem reported on the mailing list. +# +do_test fts3ac-6.1 { + execsql { + CREATE VIRTUAL TABLE ft USING fts3(one, two); + INSERT INTO ft VALUES('', 'foo'); + INSERT INTO ft VALUES('foo', 'foo'); + SELECT offsets(ft) FROM ft WHERE ft MATCH 'foo'; + } +} {{1 0 0 3} {0 0 0 3 1 0 0 3}} +do_test fts3ac-6.2 { + execsql { + DELETE FROM ft WHERE one = 'foo'; + SELECT offsets(ft) FROM ft WHERE ft MATCH 'foo'; + } +} {{1 0 0 3}} + +finish_test diff --git a/test/fts3ad.test b/test/fts3ad.test new file mode 100644 index 0000000..e373339 --- /dev/null +++ b/test/fts3ad.test @@ -0,0 +1,106 @@ +# 2006 October 1 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS3 module, and in particular +# the Porter stemmer. +# +# $Id: fts3ad.test,v 1.1 2007/08/20 17:38:42 shess Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +do_test fts3ad-1.1 { + execsql { + CREATE VIRTUAL TABLE t1 USING fts3(content, tokenize porter); + INSERT INTO t1(rowid, content) VALUES(1, 'running and jumping'); + SELECT rowid FROM t1 WHERE content MATCH 'run jump'; + } +} {1} +do_test fts3ad-1.2 { + execsql { + SELECT snippet(t1) FROM t1 WHERE t1 MATCH 'run jump'; + } +} {{running and jumping}} +do_test fts3ad-1.3 { + execsql { + INSERT INTO t1(rowid, content) + VALUES(2, 'abcdefghijklmnopqrstuvwyxz'); + SELECT rowid, snippet(t1) FROM t1 WHERE t1 MATCH 'abcdefghijqrstuvwyxz' + } +} {2 abcdefghijklmnopqrstuvwyxz} +do_test fts3ad-1.4 { + execsql { + SELECT rowid, snippet(t1) FROM t1 WHERE t1 MATCH 'abcdefghijXXXXqrstuvwyxz' + } +} {2 abcdefghijklmnopqrstuvwyxz} +do_test fts3ad-1.5 { + execsql { + INSERT INTO t1(rowid, content) + VALUES(3, 'The value is 123456789'); + SELECT rowid, snippet(t1) FROM t1 WHERE t1 MATCH '123789' + } +} {3 {The value is 123456789}} +do_test fts3ad-1.6 { + execsql { + SELECT rowid, snippet(t1) FROM t1 WHERE t1 MATCH '123000000789' + } +} {3 {The value is 123456789}} + +do_test fts3ad-2.1 { + execsql { + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING fts3(content, tokenize porter); + INSERT INTO t1(rowid, content) VALUES(1, 'running and jumping'); + SELECT rowid FROM t1 WHERE content MATCH 'run jump'; + } +} {1} +do_test fts3ad-2.2 { + execsql { + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING fts3(content, tokenize= porter); + INSERT INTO t1(rowid, content) VALUES(1, 'running and jumping'); + SELECT rowid FROM t1 WHERE content MATCH 'run jump'; + } +} {1} +do_test fts3ad-2.3 { + execsql { + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING fts3(content, tokenize= simple); + INSERT INTO t1(rowid, content) VALUES(1, 'running and jumping'); + SELECT rowid FROM t1 WHERE content MATCH 'run jump'; + } +} {} +do_test fts3ad-2.4 { + execsql { + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING fts3(content, tokenize= porter); + INSERT INTO t1(rowid, content) VALUES(1, 'running and jumping'); + SELECT rowid FROM t1 WHERE content MATCH 'run jump'; + } +} {1} +do_test fts3ad-2.5 { + execsql { + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING fts3(content, tokenize = porter); + INSERT INTO t1(rowid, content) VALUES(1, 'running and jumping'); + SELECT rowid FROM t1 WHERE content MATCH 'run jump'; + } +} {1} + + +finish_test diff --git a/test/fts3ae.test b/test/fts3ae.test new file mode 100644 index 0000000..b872688 --- /dev/null +++ b/test/fts3ae.test @@ -0,0 +1,85 @@ +# 2006 October 19 +# +# The author disclaims copyright to this source code. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing deletions in the FTS3 module. +# +# $Id: fts3ae.test,v 1.1 2007/08/20 17:38:42 shess Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# Construct a full-text search table containing keywords which are the +# ordinal numbers of the bit positions set for a sequence of integers, +# which are used for the rowid. There are a total of 30 INSERT and +# DELETE statements, so that we'll test both the segmentMerge() merge +# (over the first 16) and the termSelect() merge (over the level-1 +# segment and 14 level-0 segments). +db eval { + CREATE VIRTUAL TABLE t1 USING fts3(content); + INSERT INTO t1 (rowid, content) VALUES(1, 'one'); + INSERT INTO t1 (rowid, content) VALUES(2, 'two'); + INSERT INTO t1 (rowid, content) VALUES(3, 'one two'); + INSERT INTO t1 (rowid, content) VALUES(4, 'three'); + DELETE FROM t1 WHERE rowid = 1; + INSERT INTO t1 (rowid, content) VALUES(5, 'one three'); + INSERT INTO t1 (rowid, content) VALUES(6, 'two three'); + INSERT INTO t1 (rowid, content) VALUES(7, 'one two three'); + DELETE FROM t1 WHERE rowid = 4; + INSERT INTO t1 (rowid, content) VALUES(8, 'four'); + INSERT INTO t1 (rowid, content) VALUES(9, 'one four'); + INSERT INTO t1 (rowid, content) VALUES(10, 'two four'); + DELETE FROM t1 WHERE rowid = 7; + INSERT INTO t1 (rowid, content) VALUES(11, 'one two four'); + INSERT INTO t1 (rowid, content) VALUES(12, 'three four'); + INSERT INTO t1 (rowid, content) VALUES(13, 'one three four'); + DELETE FROM t1 WHERE rowid = 10; + INSERT INTO t1 (rowid, content) VALUES(14, 'two three four'); + INSERT INTO t1 (rowid, content) VALUES(15, 'one two three four'); + INSERT INTO t1 (rowid, content) VALUES(16, 'five'); + DELETE FROM t1 WHERE rowid = 13; + INSERT INTO t1 (rowid, content) VALUES(17, 'one five'); + INSERT INTO t1 (rowid, content) VALUES(18, 'two five'); + INSERT INTO t1 (rowid, content) VALUES(19, 'one two five'); + DELETE FROM t1 WHERE rowid = 16; + INSERT INTO t1 (rowid, content) VALUES(20, 'three five'); + INSERT INTO t1 (rowid, content) VALUES(21, 'one three five'); + INSERT INTO t1 (rowid, content) VALUES(22, 'two three five'); + DELETE FROM t1 WHERE rowid = 19; + DELETE FROM t1 WHERE rowid = 22; +} + +do_test fts3ae-1.1 { + execsql {SELECT COUNT(*) FROM t1} +} {14} + +do_test fts3ae-2.1 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'} +} {3 5 9 11 15 17 21} + +do_test fts3ae-2.2 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'two'} +} {2 3 6 11 14 15 18} + +do_test fts3ae-2.3 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'three'} +} {5 6 12 14 15 20 21} + +do_test fts3ae-2.4 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'four'} +} {8 9 11 12 14 15} + +do_test fts3ae-2.5 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'five'} +} {17 18 20 21} + +finish_test diff --git a/test/fts3af.test b/test/fts3af.test new file mode 100644 index 0000000..221ac4c --- /dev/null +++ b/test/fts3af.test @@ -0,0 +1,90 @@ +# 2006 October 19 +# +# The author disclaims copyright to this source code. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing updates in the FTS3 module. +# +# $Id: fts3af.test,v 1.1 2007/08/20 17:38:42 shess Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# Construct a full-text search table containing keywords which are the +# ordinal numbers of the bit positions set for a sequence of integers, +# which are used for the rowid. There are a total of 31 INSERT, +# UPDATE, and DELETE statements, so that we'll test both the +# segmentMerge() merge (over the first 16) and the termSelect() merge +# (over the level-1 segment and 15 level-0 segments). +db eval { + CREATE VIRTUAL TABLE t1 USING fts3(content); + INSERT INTO t1 (rowid, content) VALUES(1, 'one'); + INSERT INTO t1 (rowid, content) VALUES(2, 'two'); + INSERT INTO t1 (rowid, content) VALUES(3, 'one two'); + INSERT INTO t1 (rowid, content) VALUES(4, 'three'); + INSERT INTO t1 (rowid, content) VALUES(5, 'one three'); + INSERT INTO t1 (rowid, content) VALUES(6, 'two three'); + INSERT INTO t1 (rowid, content) VALUES(7, 'one two three'); + DELETE FROM t1 WHERE rowid = 4; + INSERT INTO t1 (rowid, content) VALUES(8, 'four'); + UPDATE t1 SET content = 'update one three' WHERE rowid = 1; + INSERT INTO t1 (rowid, content) VALUES(9, 'one four'); + INSERT INTO t1 (rowid, content) VALUES(10, 'two four'); + DELETE FROM t1 WHERE rowid = 7; + INSERT INTO t1 (rowid, content) VALUES(11, 'one two four'); + INSERT INTO t1 (rowid, content) VALUES(12, 'three four'); + INSERT INTO t1 (rowid, content) VALUES(13, 'one three four'); + DELETE FROM t1 WHERE rowid = 10; + INSERT INTO t1 (rowid, content) VALUES(14, 'two three four'); + INSERT INTO t1 (rowid, content) VALUES(15, 'one two three four'); + UPDATE t1 SET content = 'update two five' WHERE rowid = 8; + INSERT INTO t1 (rowid, content) VALUES(16, 'five'); + DELETE FROM t1 WHERE rowid = 13; + INSERT INTO t1 (rowid, content) VALUES(17, 'one five'); + INSERT INTO t1 (rowid, content) VALUES(18, 'two five'); + INSERT INTO t1 (rowid, content) VALUES(19, 'one two five'); + DELETE FROM t1 WHERE rowid = 16; + INSERT INTO t1 (rowid, content) VALUES(20, 'three five'); + INSERT INTO t1 (rowid, content) VALUES(21, 'one three five'); + INSERT INTO t1 (rowid, content) VALUES(22, 'two three five'); + DELETE FROM t1 WHERE rowid = 19; + UPDATE t1 SET content = 'update' WHERE rowid = 15; +} + +do_test fts3af-1.1 { + execsql {SELECT COUNT(*) FROM t1} +} {16} + +do_test fts3af-2.0 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'update'} +} {1 8 15} + +do_test fts3af-2.1 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'} +} {1 3 5 9 11 17 21} + +do_test fts3af-2.2 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'two'} +} {2 3 6 8 11 14 18 22} + +do_test fts3af-2.3 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'three'} +} {1 5 6 12 14 20 21 22} + +do_test fts3af-2.4 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'four'} +} {9 11 12 14} + +do_test fts3af-2.5 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'five'} +} {8 17 18 20 21 22} + +finish_test diff --git a/test/fts3ag.test b/test/fts3ag.test new file mode 100644 index 0000000..9b658d1 --- /dev/null +++ b/test/fts3ag.test @@ -0,0 +1,93 @@ +# 2006 October 19 +# +# The author disclaims copyright to this source code. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The focus +# of this script is testing handling of edge cases for various doclist +# merging functions in the FTS3 module query logic. +# +# $Id: fts3ag.test,v 1.2 2007/11/16 00:23:08 shess Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +db eval { + CREATE VIRTUAL TABLE t1 USING fts3(content); + INSERT INTO t1 (rowid, content) VALUES(1, 'this is a test'); + INSERT INTO t1 (rowid, content) VALUES(2, 'also a test'); +} + +# No hits at all. Returns empty doclists from termSelect(). +do_test fts3ag-1.1 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'something'} +} {} + +# Empty left in docListExceptMerge(). +do_test fts3ag-1.2 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH '-this something'} +} {} + +# Empty right in docListExceptMerge(). +do_test fts3ag-1.3 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'this -something'} +} {1} + +# Empty left in docListPhraseMerge(). +do_test fts3ag-1.4 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH '"this something"'} +} {} + +# Empty right in docListPhraseMerge(). +do_test fts3ag-1.5 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH '"something is"'} +} {} + +# Empty left in docListOrMerge(). +do_test fts3ag-1.6 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'something OR this'} +} {1} + +# Empty right in docListOrMerge(). +do_test fts3ag-1.7 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'this OR something'} +} {1} + +# Empty left in docListAndMerge(). +do_test fts3ag-1.8 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'something this'} +} {} + +# Empty right in docListAndMerge(). +do_test fts3ag-1.9 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'this something'} +} {} + +# No support for all-except queries. +do_test fts3ag-1.10 { + catchsql {SELECT rowid FROM t1 WHERE t1 MATCH '-this -something'} +} {1 {malformed MATCH expression: [-this -something]}} + +# Test that docListOrMerge() correctly handles reaching the end of one +# doclist before it reaches the end of the other. +do_test fts3ag-1.11 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'this OR also'} +} {1 2} +do_test fts3ag-1.12 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'also OR this'} +} {1 2} + +# Empty left and right in docListOrMerge(). Each term matches neither +# row, and when combined there was an assertion failure. +do_test fts3ag-1.13 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'something OR nothing'} +} {} + +finish_test diff --git a/test/fts3ah.test b/test/fts3ah.test new file mode 100644 index 0000000..3810ec3 --- /dev/null +++ b/test/fts3ah.test @@ -0,0 +1,71 @@ +# 2006 October 31 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The focus +# here is testing correct handling of very long terms. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is not defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# Generate a document of bigterms based on characters from the list +# chars. +proc bigtermdoc {chars len} { + set doc "" + foreach char $chars { + append doc " " [string repeat $char $len] + } + return $doc +} + +set len 5000 +set doc1 [bigtermdoc {a b c d} $len] +set doc2 [bigtermdoc {b d e f} $len] +set doc3 [bigtermdoc {a c e} $len] + +set aterm [string repeat a $len] +set bterm [string repeat b $len] +set xterm [string repeat x $len] + +db eval { + CREATE VIRTUAL TABLE t1 USING fts3(content); + INSERT INTO t1 (rowid, content) VALUES(1, $doc1); + INSERT INTO t1 (rowid, content) VALUES(2, $doc2); + INSERT INTO t1 (rowid, content) VALUES(3, $doc3); +} + +# No hits at all. Returns empty doclists from termSelect(). +do_test fts3ah-1.1 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'something'} +} {} + +do_test fts3ah-1.2 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH $aterm} +} {1 3} + +do_test fts3ah-1.3 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH $xterm} +} {} + +do_test fts3ah-1.4 { + execsql "SELECT rowid FROM t1 WHERE t1 MATCH '$aterm -$xterm'" +} {1 3} + +do_test fts3ah-1.5 { + execsql "SELECT rowid FROM t1 WHERE t1 MATCH '\"$aterm $bterm\"'" +} {1} + +finish_test diff --git a/test/fts3ai.test b/test/fts3ai.test new file mode 100644 index 0000000..b17b5bd --- /dev/null +++ b/test/fts3ai.test @@ -0,0 +1,92 @@ +# 2007 January 17 +# +# The author disclaims copyright to this source code. +# +#************************************************************************* +# This file implements regression tests for SQLite fts3 library. The +# focus here is testing handling of UPDATE when using UTF-16-encoded +# databases. +# +# $Id: fts3ai.test,v 1.1 2007/08/20 17:38:42 shess Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +ifcapable !utf16 { + finish_test + return +} + +# Return the UTF-16 representation of the supplied UTF-8 string $str. +# If $nt is true, append two 0x00 bytes as a nul terminator. +# NOTE(shess) Copied from capi3.test. +proc utf16 {str {nt 1}} { + set r [encoding convertto unicode $str] + if {$nt} { + append r "\x00\x00" + } + return $r +} + +db eval { + PRAGMA encoding = "UTF-16le"; + CREATE VIRTUAL TABLE t1 USING fts3(content); +} + +do_test fts3ai-1.0 { + execsql {PRAGMA encoding} +} {UTF-16le} + +do_test fts3ai-1.1 { + execsql {INSERT INTO t1 (rowid, content) VALUES(1, 'one')} + execsql {SELECT content FROM t1 WHERE rowid = 1} +} {one} + +do_test fts3ai-1.2 { + set sql "INSERT INTO t1 (rowid, content) VALUES(2, 'two')" + set STMT [sqlite3_prepare $DB $sql -1 TAIL] + sqlite3_step $STMT + sqlite3_finalize $STMT + execsql {SELECT content FROM t1 WHERE rowid = 2} +} {two} + +do_test fts3ai-1.3 { + set sql "INSERT INTO t1 (rowid, content) VALUES(3, 'three')" + set STMT [sqlite3_prepare $DB $sql -1 TAIL] + sqlite3_step $STMT + sqlite3_finalize $STMT + set sql "UPDATE t1 SET content = 'trois' WHERE rowid = 3" + set STMT [sqlite3_prepare $DB $sql -1 TAIL] + sqlite3_step $STMT + sqlite3_finalize $STMT + execsql {SELECT content FROM t1 WHERE rowid = 3} +} {trois} + +do_test fts3ai-1.4 { + set sql16 [utf16 {INSERT INTO t1 (rowid, content) VALUES(4, 'four')}] + set STMT [sqlite3_prepare16 $DB $sql16 -1 TAIL] + sqlite3_step $STMT + sqlite3_finalize $STMT + execsql {SELECT content FROM t1 WHERE rowid = 4} +} {four} + +do_test fts3ai-1.5 { + set sql16 [utf16 {INSERT INTO t1 (rowid, content) VALUES(5, 'five')}] + set STMT [sqlite3_prepare16 $DB $sql16 -1 TAIL] + sqlite3_step $STMT + sqlite3_finalize $STMT + set sql "UPDATE t1 SET content = 'cinq' WHERE rowid = 5" + set STMT [sqlite3_prepare $DB $sql -1 TAIL] + sqlite3_step $STMT + sqlite3_finalize $STMT + execsql {SELECT content FROM t1 WHERE rowid = 5} +} {cinq} + +finish_test diff --git a/test/fts3aj.test b/test/fts3aj.test new file mode 100644 index 0000000..0c89691 --- /dev/null +++ b/test/fts3aj.test @@ -0,0 +1,87 @@ +# 2007 February 6 +# +# The author disclaims copyright to this source code. +# +#************************************************************************* +# This file implements regression tests for SQLite library. This +# tests creating fts3 tables in an attached database. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# Clean up anything left over from a previous pass. +forcedelete test2.db +forcedelete test2.db-journal +sqlite3 db2 test2.db + +db eval { + CREATE VIRTUAL TABLE t3 USING fts3(content); + INSERT INTO t3 (rowid, content) VALUES(1, 'hello world'); +} + +db2 eval { + CREATE VIRTUAL TABLE t1 USING fts3(content); + INSERT INTO t1 (rowid, content) VALUES(1, 'hello world'); + INSERT INTO t1 (rowid, content) VALUES(2, 'hello there'); + INSERT INTO t1 (rowid, content) VALUES(3, 'cruel world'); +} + +# This has always worked because the t1_* tables used by fts3 will be +# the defaults. +do_test fts3aj-1.1 { + execsql { + ATTACH DATABASE 'test2.db' AS two; + SELECT rowid FROM t1 WHERE t1 MATCH 'hello'; + DETACH DATABASE two; + } +} {1 2} +# Make certain we're detached if there was an error. +catch {db eval {DETACH DATABASE two}} + +# In older code, this appears to work fine, but the t2_* tables used +# by fts3 will be created in database 'main' instead of database +# 'two'. It appears to work fine because the tables end up being the +# defaults, but obviously is badly broken if you hope to use things +# other than in the exact same ATTACH setup. +do_test fts3aj-1.2 { + execsql { + ATTACH DATABASE 'test2.db' AS two; + CREATE VIRTUAL TABLE two.t2 USING fts3(content); + INSERT INTO t2 (rowid, content) VALUES(1, 'hello world'); + INSERT INTO t2 (rowid, content) VALUES(2, 'hello there'); + INSERT INTO t2 (rowid, content) VALUES(3, 'cruel world'); + SELECT rowid FROM t2 WHERE t2 MATCH 'hello'; + DETACH DATABASE two; + } +} {1 2} +catch {db eval {DETACH DATABASE two}} + +# In older code, this broke because the fts3 code attempted to create +# t3_* tables in database 'main', but they already existed. Normally +# this wouldn't happen without t3 itself existing, in which case the +# fts3 code would never be called in the first place. +do_test fts3aj-1.3 { + execsql { + ATTACH DATABASE 'test2.db' AS two; + + CREATE VIRTUAL TABLE two.t3 USING fts3(content); + INSERT INTO two.t3 (rowid, content) VALUES(2, 'hello there'); + INSERT INTO two.t3 (rowid, content) VALUES(3, 'cruel world'); + SELECT rowid FROM two.t3 WHERE t3 MATCH 'hello'; + + DETACH DATABASE two; + } db2 +} {2} +catch {db eval {DETACH DATABASE two}} + +catch {db2 close} +forcedelete test2.db + +finish_test diff --git a/test/fts3ak.test b/test/fts3ak.test new file mode 100644 index 0000000..080efe5 --- /dev/null +++ b/test/fts3ak.test @@ -0,0 +1,105 @@ +# 2007 March 9 +# +# The author disclaims copyright to this source code. +# +#************************************************************************* +# This file implements regression tests for SQLite library. These +# make sure that fts3 insertion buffering is fully transparent when +# using transactions. +# +# $Id: fts3ak.test,v 1.1 2007/08/20 17:38:42 shess Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +db eval { + CREATE VIRTUAL TABLE t1 USING fts3(content); + INSERT INTO t1 (rowid, content) VALUES(1, 'hello world'); + INSERT INTO t1 (rowid, content) VALUES(2, 'hello there'); + INSERT INTO t1 (rowid, content) VALUES(3, 'cruel world'); +} + +# Test that possibly-buffered inserts went through after commit. +do_test fts3ak-1.1 { + execsql { + BEGIN TRANSACTION; + INSERT INTO t1 (rowid, content) VALUES(4, 'false world'); + INSERT INTO t1 (rowid, content) VALUES(5, 'false door'); + COMMIT TRANSACTION; + SELECT rowid FROM t1 WHERE t1 MATCH 'world'; + } +} {1 3 4} + +# Test that buffered inserts are seen by selects in the same +# transaction. +do_test fts3ak-1.2 { + execsql { + BEGIN TRANSACTION; + INSERT INTO t1 (rowid, content) VALUES(6, 'another world'); + INSERT INTO t1 (rowid, content) VALUES(7, 'another test'); + SELECT rowid FROM t1 WHERE t1 MATCH 'world'; + COMMIT TRANSACTION; + } +} {1 3 4 6} + +# Test that buffered inserts are seen within a transaction. This is +# really the same test as 1.2. +do_test fts3ak-1.3 { + execsql { + BEGIN TRANSACTION; + INSERT INTO t1 (rowid, content) VALUES(8, 'second world'); + INSERT INTO t1 (rowid, content) VALUES(9, 'second sight'); + SELECT rowid FROM t1 WHERE t1 MATCH 'world'; + ROLLBACK TRANSACTION; + } +} {1 3 4 6 8} + +# Double-check that the previous result doesn't persist past the +# rollback! +do_test fts3ak-1.4 { + execsql { + SELECT rowid FROM t1 WHERE t1 MATCH 'world'; + } +} {1 3 4 6} + +# Test it all together. +do_test fts3ak-1.5 { + execsql { + BEGIN TRANSACTION; + INSERT INTO t1 (rowid, content) VALUES(10, 'second world'); + INSERT INTO t1 (rowid, content) VALUES(11, 'second sight'); + ROLLBACK TRANSACTION; + SELECT rowid FROM t1 WHERE t1 MATCH 'world'; + } +} {1 3 4 6} + +# Test that the obvious case works. +do_test fts3ak-1.6 { + execsql { + BEGIN; + INSERT INTO t1 (rowid, content) VALUES(12, 'third world'); + COMMIT; + SELECT rowid FROM t1 WHERE t1 MATCH 'third'; + } +} {12} + +# This is exactly the same as the previous test, except that older +# code loses the INSERT due to an SQLITE_SCHEMA error. +do_test fts3ak-1.7 { + execsql { + BEGIN; + INSERT INTO t1 (rowid, content) VALUES(13, 'third dimension'); + CREATE TABLE x (c); + COMMIT; + SELECT rowid FROM t1 WHERE t1 MATCH 'dimension'; + } +} {13} + +finish_test diff --git a/test/fts3al.test b/test/fts3al.test new file mode 100644 index 0000000..02cc0d1 --- /dev/null +++ b/test/fts3al.test @@ -0,0 +1,73 @@ +# 2007 March 28 +# +# The author disclaims copyright to this source code. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The focus +# of this script is testing isspace/isalnum/tolower problems with the +# FTS3 module. Unfortunately, this code isn't a really principled set +# of tests, because it is impossible to know where new uses of these +# functions might appear. +# +# $Id: fts3al.test,v 1.2 2007/12/13 21:54:11 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# Tests that startsWith() (calls isspace, tolower, isalnum) can handle +# hi-bit chars. parseSpec() also calls isalnum here. +do_test fts3al-1.1 { + execsql "CREATE VIRTUAL TABLE t1 USING fts3(content, \x80)" +} {} + +# Additionally tests isspace() call in getToken(), and isalnum() call +# in tokenListToIdList(). +do_test fts3al-1.2 { + catch { + execsql "CREATE VIRTUAL TABLE t2 USING fts3(content, tokenize \x80)" + } + sqlite3_errmsg $DB +} "unknown tokenizer: \x80" + +# Additionally test final isalnum() in startsWith(). +do_test fts3al-1.3 { + execsql "CREATE VIRTUAL TABLE t3 USING fts3(content, tokenize\x80)" +} {} + +# The snippet-generation code has calls to isspace() which are sort of +# hard to get to. It finds convenient breakpoints by starting ~40 +# chars before and after the matched term, and scanning ~10 chars +# around that position for isspace() characters. The long word with +# embedded hi-bit chars causes one of these isspace() calls to be +# exercised. The version with a couple extra spaces should cause the +# other isspace() call to be exercised. [Both cases have been tested +# in the debugger, but I'm hoping to continue to catch it if simple +# constant changes change things slightly. +# +# The trailing and leading hi-bit chars help with code which tests for +# isspace() to coalesce multiple spaces. +# +# UPDATE: The above is no longer true; there is no such code in fts3. +# But leave the test in just the same. +# + +set word "\x80xxxxx\x80xxxxx\x80xxxxx\x80xxxxx\x80xxxxx\x80xxxxx\x80" +set phrase1 "$word $word $word target $word $word $word" +set phrase2 "$word $word $word target $word $word $word" + +db eval {CREATE VIRTUAL TABLE t4 USING fts3(content)} +db eval "INSERT INTO t4 (content) VALUES ('$phrase1')" +db eval "INSERT INTO t4 (content) VALUES ('$phrase2')" + +do_test fts3al-1.4 { + execsql {SELECT rowid, length(snippet(t4)) FROM t4 WHERE t4 MATCH 'target'} +} {1 241 2 247} + +finish_test diff --git a/test/fts3am.test b/test/fts3am.test new file mode 100644 index 0000000..4a09cd8 --- /dev/null +++ b/test/fts3am.test @@ -0,0 +1,65 @@ +# 2007 April 9 +# +# The author disclaims copyright to this source code. +# +#************************************************************************* +# This file implements regression tests for SQLite library. fts3 +# DELETE handling assumed all fields were non-null. This was not +# the intention at all. +# +# $Id: fts3am.test,v 1.1 2007/08/20 17:38:42 shess Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +db eval { + CREATE VIRTUAL TABLE t1 USING fts3(col_a, col_b); + + INSERT INTO t1(rowid, col_a, col_b) VALUES(1, 'testing', 'testing'); + INSERT INTO t1(rowid, col_a, col_b) VALUES(2, 'only a', null); + INSERT INTO t1(rowid, col_a, col_b) VALUES(3, null, 'only b'); + INSERT INTO t1(rowid, col_a, col_b) VALUES(4, null, null); +} + +do_test fts3am-1.0 { + execsql { + SELECT COUNT(col_a), COUNT(col_b), COUNT(*) FROM t1; + } +} {2 2 4} + +do_test fts3am-1.1 { + execsql { + DELETE FROM t1 WHERE rowid = 1; + SELECT COUNT(col_a), COUNT(col_b), COUNT(*) FROM t1; + } +} {1 1 3} + +do_test fts3am-1.2 { + execsql { + DELETE FROM t1 WHERE rowid = 2; + SELECT COUNT(col_a), COUNT(col_b), COUNT(*) FROM t1; + } +} {0 1 2} + +do_test fts3am-1.3 { + execsql { + DELETE FROM t1 WHERE rowid = 3; + SELECT COUNT(col_a), COUNT(col_b), COUNT(*) FROM t1; + } +} {0 0 1} + +do_test fts3am-1.4 { + execsql { + DELETE FROM t1 WHERE rowid = 4; + SELECT COUNT(col_a), COUNT(col_b), COUNT(*) FROM t1; + } +} {0 0 0} + +finish_test diff --git a/test/fts3an.test b/test/fts3an.test new file mode 100644 index 0000000..5211027 --- /dev/null +++ b/test/fts3an.test @@ -0,0 +1,218 @@ +# 2007 April 26 +# +# The author disclaims copyright to this source code. +# +#************************************************************************* +# This file implements tests for prefix-searching in the fts3 +# component of the SQLite library. +# +# $Id: fts3an.test,v 1.2 2007/12/13 21:54:11 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# A large string to prime the pump with. +set text { + Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas + iaculis mollis ipsum. Praesent rhoncus placerat justo. Duis non quam + sed turpis posuere placerat. Curabitur et lorem in lorem porttitor + aliquet. Pellentesque bibendum tincidunt diam. Vestibulum blandit + ante nec elit. In sapien diam, facilisis eget, dictum sed, viverra + at, felis. Vestibulum magna. Sed magna dolor, vestibulum rhoncus, + ornare vel, vulputate sit amet, felis. Integer malesuada, tellus at + luctus gravida, diam nunc porta nibh, nec imperdiet massa metus eu + lectus. Aliquam nisi. Nunc fringilla nulla at lectus. Suspendisse + potenti. Cum sociis natoque penatibus et magnis dis parturient + montes, nascetur ridiculus mus. Pellentesque odio nulla, feugiat eu, + suscipit nec, consequat quis, risus. +} + +db eval { + CREATE VIRTUAL TABLE t1 USING fts3(c); + + INSERT INTO t1(rowid, c) VALUES(1, $text); + INSERT INTO t1(rowid, c) VALUES(2, 'Another lovely row'); +} + +# Exact match +do_test fts3an-1.1 { + execsql "SELECT rowid FROM t1 WHERE t1 MATCH 'lorem'" +} {1} + +# And a prefix +do_test fts3an-1.2 { + execsql "SELECT rowid FROM t1 WHERE t1 MATCH 'lore*'" +} {1} + +# Prefix includes exact match +do_test fts3an-1.3 { + execsql "SELECT rowid FROM t1 WHERE t1 MATCH 'lorem*'" +} {1} + +# Make certain everything isn't considered a prefix! +do_test fts3an-1.4 { + execsql "SELECT rowid FROM t1 WHERE t1 MATCH 'lore'" +} {} + +# Prefix across multiple rows. +do_test fts3an-1.5 { + execsql "SELECT rowid FROM t1 WHERE t1 MATCH 'lo*'" +} {1 2} + +# Likewise, with multiple hits in one document. +do_test fts3an-1.6 { + execsql "SELECT rowid FROM t1 WHERE t1 MATCH 'l*'" +} {1 2} + +# Prefix which should only hit one document. +do_test fts3an-1.7 { + execsql "SELECT rowid FROM t1 WHERE t1 MATCH 'lov*'" +} {2} + +# * not at end is dropped. +do_test fts3an-1.8 { + execsql "SELECT rowid FROM t1 WHERE t1 MATCH 'lo *'" +} {} + +# Stand-alone * is dropped. +do_test fts3an-1.9 { + execsql "SELECT rowid FROM t1 WHERE t1 MATCH '*'" +} {} + +# Phrase-query prefix. +do_test fts3an-1.10 { + execsql "SELECT rowid FROM t1 WHERE t1 MATCH '\"lovely r*\"'" +} {2} +do_test fts3an-1.11 { + execsql "SELECT rowid FROM t1 WHERE t1 MATCH '\"lovely r\"'" +} {} + +# Phrase query with multiple prefix matches. +do_test fts3an-1.12 { + execsql "SELECT rowid FROM t1 WHERE t1 MATCH '\"a* l*\"'" +} {1 2} + +# Phrase query with multiple prefix matches. +do_test fts3an-1.13 { + execsql "SELECT rowid FROM t1 WHERE t1 MATCH '\"a* l* row\"'" +} {2} + + + + +# Test across updates (and, by implication, deletes). + +# Version of text without "lorem". +regsub -all {[Ll]orem} $text '' ntext + +db eval { + CREATE VIRTUAL TABLE t2 USING fts3(c); + + INSERT INTO t2(rowid, c) VALUES(1, $text); + INSERT INTO t2(rowid, c) VALUES(2, 'Another lovely row'); + UPDATE t2 SET c = $ntext WHERE rowid = 1; +} + +# Can't see lorem as an exact match. +do_test fts3an-2.1 { + execsql "SELECT rowid FROM t2 WHERE t2 MATCH 'lorem'" +} {} + +# Can't see a prefix of lorem, either. +do_test fts3an-2.2 { + execsql "SELECT rowid FROM t2 WHERE t2 MATCH 'lore*'" +} {} + +# Can see lovely in the other document. +do_test fts3an-2.3 { + execsql "SELECT rowid FROM t2 WHERE t2 MATCH 'lo*'" +} {2} + +# Can still see other hits. +do_test fts3an-2.4 { + execsql "SELECT rowid FROM t2 WHERE t2 MATCH 'l*'" +} {1 2} + +# Prefix which should only hit one document. +do_test fts3an-2.5 { + execsql "SELECT rowid FROM t2 WHERE t2 MATCH 'lov*'" +} {2} + + + +# Test with a segment which will have multiple levels in the tree. + +# Build a big document with lots of unique terms. +set bigtext $text +foreach c {a b c d e} { + regsub -all {[A-Za-z]+} $bigtext "&$c" t + append bigtext $t +} + +# Populate a table with many copies of the big document, so that we +# can test the number of hits found. Populate $ret with the expected +# hit counts for each row. offsets() returns 4 elements for every +# hit. We'll have 6 hits for row 1, 1 for row 2, and 6*(2^5)==192 for +# $bigtext. +set ret {6 1} +db eval { + BEGIN; + CREATE VIRTUAL TABLE t3 USING fts3(c); + + INSERT INTO t3(rowid, c) VALUES(1, $text); + INSERT INTO t3(rowid, c) VALUES(2, 'Another lovely row'); +} +for {set i 0} {$i<68} {incr i} { + db eval {INSERT INTO t3(rowid, c) VALUES(3+$i, $bigtext)} + lappend ret 192 +} +db eval {COMMIT;} + +# Test that we get the expected number of hits. +do_test fts3an-3.1 { + set t {} + db eval {SELECT offsets(t3) as o FROM t3 WHERE t3 MATCH 'l*'} { + set l [llength $o] + lappend t [expr {$l/4}] + } + set t +} $ret + +# Test a boundary condition: More than 2^16 terms that match a searched for +# prefix in a single segment. +# +puts "This next test can take a little while (~ 30 seconds)..." +do_test fts3an-4.1 { + execsql { CREATE VIRTUAL TABLE ft USING fts3(x) } + execsql BEGIN + execsql { INSERT INTO ft VALUES(NULL) } + execsql { INSERT INTO ft SELECT * FROM ft } ;# 2 + execsql { INSERT INTO ft SELECT * FROM ft } ;# 4 + execsql { INSERT INTO ft SELECT * FROM ft } ;# 8 + execsql { INSERT INTO ft SELECT * FROM ft } ;# 16 + execsql { INSERT INTO ft SELECT * FROM ft } ;# 32 + execsql { INSERT INTO ft SELECT * FROM ft } ;# 64 + execsql { INSERT INTO ft SELECT * FROM ft } ;# 128 + execsql { INSERT INTO ft SELECT * FROM ft } ;# 256 + execsql { INSERT INTO ft SELECT * FROM ft } ;# 512 + execsql { INSERT INTO ft SELECT * FROM ft } ;# 1024 + execsql { INSERT INTO ft SELECT * FROM ft } ;# 2048 + execsql { INSERT INTO ft SELECT * FROM ft } ;# 4096 + execsql { INSERT INTO ft SELECT * FROM ft } ;# 8192 + execsql { INSERT INTO ft SELECT * FROM ft } ;# 16384 + execsql { INSERT INTO ft SELECT * FROM ft } ;# 32768 + execsql { INSERT INTO ft SELECT * FROM ft } ;# 65536 + execsql { INSERT INTO ft SELECT * FROM ft } ;# 131072 + execsql COMMIT + execsql { UPDATE ft SET x = 'abc' || rowid } + execsql { SELECT count(*) FROM ft WHERE x MATCH 'abc*' } +} {131072} + +finish_test diff --git a/test/fts3ao.test b/test/fts3ao.test new file mode 100644 index 0000000..d9b2233 --- /dev/null +++ b/test/fts3ao.test @@ -0,0 +1,250 @@ +# 2007 June 20 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS3 module. +# +# $Id: fts3ao.test,v 1.1 2007/08/20 17:38:42 shess Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is not defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +set ::testprefix fts3ao + +#--------------------------------------------------------------------- +# These tests, fts3ao-1.*, test that ticket #2429 is fixed. +# +db eval { + CREATE VIRTUAL TABLE t1 USING fts3(a, b, c); + INSERT INTO t1(a, b, c) VALUES('one three four', 'one four', 'one four two'); +} +do_test fts3ao-1.1 { + execsql { + SELECT rowid, snippet(t1) FROM t1 WHERE c MATCH 'four'; + } +} {1 {one four two}} +do_test fts3ao-1.2 { + execsql { + SELECT rowid, snippet(t1) FROM t1 WHERE b MATCH 'four'; + } +} {1 {one four}} +do_test fts3ao-1.3 { + execsql { + SELECT rowid, snippet(t1) FROM t1 WHERE a MATCH 'four'; + } +} {1 {one three four}} + +#--------------------------------------------------------------------- +# Test that it is possible to rename an fts3 table. +# +do_test fts3ao-2.1 { + execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'} +} {t1 t1_content t1_segments t1_segdir} +do_test fts3ao-2.2 { + execsql { ALTER TABLE t1 RENAME to fts_t1; } +} {} +do_test fts3ao-2.3 { + execsql { SELECT rowid, snippet(fts_t1) FROM fts_t1 WHERE a MATCH 'four'; } +} {1 {one three four}} +do_test fts3ao-2.4 { + execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'} +} {fts_t1 fts_t1_content fts_t1_segments fts_t1_segdir} + +# See what happens when renaming the fts3 table fails. +# +do_test fts3ao-2.5 { + catchsql { + CREATE TABLE t1_segdir(a, b, c); + ALTER TABLE fts_t1 RENAME to t1; + } +} {1 {SQL logic error}} +do_test fts3ao-2.6 { + execsql { SELECT rowid, snippet(fts_t1) FROM fts_t1 WHERE a MATCH 'four'; } +} {1 {one three four}} +do_test fts3ao-2.7 { + execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'} +} {fts_t1 fts_t1_content fts_t1_segments fts_t1_segdir t1_segdir} + +# See what happens when renaming the fts3 table fails inside a transaction. +# +do_test fts3ao-2.8 { + execsql { + BEGIN; + INSERT INTO fts_t1(a, b, c) VALUES('one two three', 'one four', 'one two'); + } +} {} +do_test fts3ao-2.9 { + catchsql { + ALTER TABLE fts_t1 RENAME to t1; + } +} {1 {SQL logic error}} +do_test fts3ao-2.10 { + execsql { SELECT rowid, snippet( fts_t1 ) FROM fts_t1 WHERE a MATCH 'four'; } +} {1 {one three four}} +do_test fts3ao-2.11 { + execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'} +} {fts_t1 fts_t1_content fts_t1_segments fts_t1_segdir t1_segdir} +do_test fts3ao-2.12 { + execsql COMMIT + execsql {SELECT a FROM fts_t1} +} {{one three four} {one two three}} +do_test fts3ao-2.12 { + execsql { SELECT a, b, c FROM fts_t1 WHERE c MATCH 'four'; } +} {{one three four} {one four} {one four two}} + +#------------------------------------------------------------------- +# Close, delete and reopen the database. The following test should +# be run on an initially empty db. +# +db close +forcedelete test.db test.db-journal +sqlite3 db test.db + +do_test fts3ao-3.1 { + execsql { + CREATE VIRTUAL TABLE t1 USING fts3(a, b, c); + INSERT INTO t1(a, b, c) VALUES('one three four', 'one four', 'one two'); + SELECT a, b, c FROM t1 WHERE c MATCH 'two'; + } +} {{one three four} {one four} {one two}} + +# This test was crashing at one point. +# +do_test fts3ao-3.2 { + execsql { + SELECT a, b, c FROM t1 WHERE c MATCH 'two'; + CREATE TABLE t3(a, b, c); + SELECT a, b, c FROM t1 WHERE c MATCH 'two'; + } +} {{one three four} {one four} {one two} {one three four} {one four} {one two}} + +#--------------------------------------------------------------------- +# Test that it is possible to rename an fts3 table in an attached +# database. +# +forcedelete test2.db test2.db-journal + +do_test fts3ao-3.1 { + execsql { + ATTACH 'test2.db' AS aux; + CREATE VIRTUAL TABLE aux.t1 USING fts3(a, b, c); + INSERT INTO aux.t1(a, b, c) VALUES( + 'neung song sahm', 'neung see', 'neung see song' + ); + } +} {} + +do_test fts3ao-3.2 { + execsql { SELECT a, b, c FROM aux.t1 WHERE a MATCH 'song'; } +} {{neung song sahm} {neung see} {neung see song}} + +do_test fts3ao-3.3 { + execsql { SELECT a, b, c FROM t1 WHERE c MATCH 'two'; } +} {{one three four} {one four} {one two}} + +do_test fts3ao-3.4 { + execsql { ALTER TABLE aux.t1 RENAME TO t2 } +} {} + +do_test fts3ao-3.2 { + execsql { SELECT a, b, c FROM t2 WHERE a MATCH 'song'; } +} {{neung song sahm} {neung see} {neung see song}} + +do_test fts3ao-3.3 { + execsql { SELECT a, b, c FROM t1 WHERE c MATCH 'two'; } +} {{one three four} {one four} {one two}} + +#--------------------------------------------------------------------- +# Test that it is possible to rename an fts3 table within a +# transaction. +# +do_test fts3ao-4.1 { + execsql { + CREATE VIRTUAL TABLE t4 USING fts3; + INSERT INTO t4 VALUES('the quick brown fox'); + } +} {} +do_test fts3ao-4.2 { + execsql { + BEGIN; + INSERT INTO t4 VALUES('jumped over the'); + } +} {} +do_test fts3ao-4.3 { execsql { ALTER TABLE t4 RENAME TO t5; } } {} +do_test fts3ao-4.4 { execsql { INSERT INTO t5 VALUES('lazy dog'); } } {} +do_test fts3ao-4.5 { execsql COMMIT } {} +do_test fts3ao-4.6 { + execsql { SELECT * FROM t5 } +} {{the quick brown fox} {jumped over the} {lazy dog}} +do_test fts3ao-4.7 { + execsql { + BEGIN; + INSERT INTO t5 VALUES('Down came a jumbuck to drink at that billabong'); + ALTER TABLE t5 RENAME TO t6; + INSERT INTO t6 VALUES('Down came the troopers, one, two, three'); + ROLLBACK; + SELECT * FROM t5; + } +} {{the quick brown fox} {jumped over the} {lazy dog}} +do_execsql_test fts3ao-4.8 { + SELECT snippet(t5, '[', ']') FROM t5 WHERE t5 MATCH 'the' +} {{[the] quick brown fox} {jumped over [the]}} + +# Test that it is possible to rename an FTS4 table. Renaming an FTS4 table +# involves renaming the extra %_docsize and %_stat tables. +# +do_execsql_test 5.1 { + CREATE VIRTUAL TABLE t7 USING FTS4; + INSERT INTO t7 VALUES('coined by a German clinician'); + SELECT count(*) FROM sqlite_master WHERE name LIKE 't7%'; + SELECT count(*) FROM sqlite_master WHERE name LIKE 't8%'; +} {6 0} +do_execsql_test 5.2 { + ALTER TABLE t7 RENAME TO t8; + SELECT count(*) FROM sqlite_master WHERE name LIKE 't7%'; + SELECT count(*) FROM sqlite_master WHERE name LIKE 't8%'; +} {0 6} + +# At one point this was causing a memory leak. +# +foreach {tn sql} { + 1 {} + 2 { INSERT INTO ft(ft) VALUES('merge=2,2'); } +} { + reset_db + do_execsql_test 6.$tn.1 " + CREATE TABLE t1(x); + CREATE VIRTUAL TABLE ft USING fts3; + INSERT INTO ft VALUES('hello world'); + $sql + " + + db close + sqlite3 db test.db + do_execsql_test 6.$tn.2 { SELECT * FROM t1 } {} + + do_test 6.$tn.3 { + sqlite3 db2 test.db + db2 eval { DROP TABLE t1 } + db2 close + set stmt [sqlite3_prepare db { SELECT * FROM ft } -1 dummy] + sqlite3_finalize $stmt + } {SQLITE_OK} + db close +} + +finish_test diff --git a/test/fts3atoken.test b/test/fts3atoken.test new file mode 100644 index 0000000..4981480 --- /dev/null +++ b/test/fts3atoken.test @@ -0,0 +1,287 @@ +# 2007 June 21 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The focus +# of this script is testing the pluggable tokeniser feature of the +# FTS3 module. +# +# $Id: fts3atoken.test,v 1.1 2007/08/20 17:38:42 shess Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +set ::testprefix fts3atoken + +proc escape_string {str} { + set out "" + foreach char [split $str ""] { + scan $char %c i + if {$i<=127} { + append out $char + } else { + append out [format {\x%.4x} $i] + } + } + set out +} + +#-------------------------------------------------------------------------- +# Test cases fts3atoken-1.* are the warm-body test for the SQL scalar +# function fts3_tokenizer(). The procedure is as follows: +# +# 1: Verify that there is no such fts3 tokenizer as 'blah'. +# +# 2: Query for the built-in tokenizer 'simple'. Insert a copy of the +# retrieved value as tokenizer 'blah'. +# +# 3: Test that the value returned for tokenizer 'blah' is now the +# same as that retrieved for 'simple'. +# +# 4: Test that it is now possible to create an fts3 table using +# tokenizer 'blah' (it was not possible in step 1). +# +# 5: Test that the table created to use tokenizer 'blah' is usable. +# +sqlite3_db_config db SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1 +do_test fts3atoken-1.1 { + catchsql { + CREATE VIRTUAL TABLE t1 USING fts3(content, tokenize blah); + } +} {1 {unknown tokenizer: blah}} +do_test fts3atoken-1.2 { + execsql { + SELECT fts3_tokenizer('blah', fts3_tokenizer('simple')) IS NULL; + } +} {0} +do_test fts3atoken-1.3 { + execsql { + SELECT fts3_tokenizer('blah') == fts3_tokenizer('simple'); + } +} {1} +do_test fts3atoken-1.4 { + catchsql { + CREATE VIRTUAL TABLE t1 USING fts3(content, tokenize blah); + } +} {0 {}} +do_test fts3atoken-1.5 { + execsql { + INSERT INTO t1(content) VALUES('There was movement at the station'); + INSERT INTO t1(content) VALUES('For the word has passed around'); + INSERT INTO t1(content) VALUES('That the colt from ol regret had got'); + SELECT content FROM t1 WHERE content MATCH 'movement' + } +} {{There was movement at the station}} + +unset -nocomplain simple blah2name simplename +set simplename "simple" +set blah2name "blah2" +set simple [db one {SELECT fts3_tokenizer('simple')}] +sqlite3_db_config db SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 0 +do_catchsql_test 1.6 { + SELECT fts3_tokenizer('blah', fts3_tokenizer('simple')) IS NULL; +} {1 {fts3tokenize disabled}} +do_test fts3atoken-1.7 { + execsql { + SELECT fts3_tokenizer('blah2', $simple) IS NULL; + } +} {1} + +# With ENABLE_FTS3_TOKENIZER off, the fts3_tokenzer(1) function +# returns NULL unless the first parameter is a bound parameter. +# If the first parameter is a bound parameter, then fts3_tokenizer(1) +# returns the actual pointer value as a BLOB. +# +do_test fts3atoken-1.8 { + execsql { + SELECT fts3_tokenizer($blah2name) == fts3_tokenizer($simplename), + typeof(fts3_tokenizer($blah2name)), + typeof(fts3_tokenizer('blah2')), + typeof(fts3_tokenizer($simplename)), + typeof(fts3_tokenizer('simple')); + } +} {1 blob null blob null} + +# With ENABLE_FTS3_TOKENIZER on, fts3_tokenizer() always returns +# the BLOB pointer, regardless the parameter +# +sqlite3_db_config db SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1 +do_test fts3atoken-1.9 { + execsql { + SELECT fts3_tokenizer('blah2') == fts3_tokenizer('simple'), + typeof(fts3_tokenizer($blah2name)), + typeof(fts3_tokenizer('blah2')), + typeof(fts3_tokenizer($simplename)), + typeof(fts3_tokenizer('simple')); + } +} {1 blob blob blob blob} + +# 2019-12-31: The fts3_tokenizer() function can never be invoked from +# within a trigger or view. +# +do_catchsql_test fts3atoken-1.10 { + CREATE VIEW v110(x) AS + SELECT fts3_tokenizer('tok110', fts3_tokenizer('simple')) IS NULL; +} {0 {}} +do_catchsql_test fts3atoken-1.11 { + SELECT * FROM v110; +} {1 {unsafe use of fts3_tokenizer()}} +do_catchsql_test fts3atoken-1.12 { + CREATE TABLE t110(a,b); + CREATE TRIGGER r110 AFTER INSERT ON t110 BEGIN + SELECT fts3_tokenizer('tok110', fts3_tokenizer('simple')) IS NULL; + END; +} {0 {}} +do_catchsql_test fts3atoken-1.13 { + INSERT INTO t110(a,b) VALUES(1,2); +} {1 {unsafe use of fts3_tokenizer()}} +do_catchsql_test fts3atoken-1.14 { + SELECT * FROM t110; +} {0 {}} + +#-------------------------------------------------------------------------- +# Test cases fts3atoken-2.* test error cases in the scalar function based +# API for getting and setting tokenizers. +# +do_test fts3atoken-2.1 { + catchsql { + SELECT fts3_tokenizer('nosuchtokenizer'); + } +} {1 {unknown tokenizer: nosuchtokenizer}} + +#-------------------------------------------------------------------------- +# Test cases fts3atoken-3.* test the three built-in tokenizers with a +# simple input string via the built-in test function. This is as much +# to test the test function as the tokenizer implementations. +# +sqlite3_db_config db SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1 +do_test fts3atoken-3.1 { + execsql { + SELECT fts3_tokenizer_test('simple', 'I don''t see how'); + } +} {{0 i I 1 don don 2 t t 3 see see 4 how how}} +do_test fts3atoken-3.2 { + execsql { + SELECT fts3_tokenizer_test('porter', 'I don''t see how'); + } +} {{0 i I 1 don don 2 t t 3 see see 4 how how}} +ifcapable icu { + do_test fts3atoken-3.3 { + execsql { + SELECT fts3_tokenizer_test('icu', 'I don''t see how'); + } + } {{0 i I 1 don't don't 2 see see 3 how how}} +} + +#-------------------------------------------------------------------------- +# Test cases fts3atoken-4.* test the ICU tokenizer. In practice, this +# tokenizer only has two modes - "thai" and "everybody else". Some other +# Asian languages (Lao, Khmer etc.) require the same special treatment as +# Thai, but ICU doesn't support them yet. +# +ifcapable icu { + + proc do_icu_test {name locale input output} { + set ::out [db eval { SELECT fts3_tokenizer_test('icu', $locale, $input) }] + do_test $name { + lindex $::out 0 + } $output + } + + do_icu_test fts3atoken-4.1 en_US {} {} + do_icu_test fts3atoken-4.2 en_US {Test cases fts3} [list \ + 0 test Test 1 cases cases 2 fts3 fts3 + ] + + # The following test shows that ICU is smart enough to recognise + # Thai chararacters, even when the locale is set to English/United + # States. + # + set input "\u0e2d\u0e30\u0e44\u0e23\u0e19\u0e30\u0e04\u0e23\u0e31\u0e1a" + set output "0 \u0e2d\u0e30\u0e44\u0e23 \u0e2d\u0e30\u0e44\u0e23 " + append output "1 \u0e19\u0e30 \u0e19\u0e30 " + append output "2 \u0e04\u0e23\u0e31\u0e1a \u0e04\u0e23\u0e31\u0e1a" + + do_icu_test fts3atoken-4.3 th_TH $input $output + do_icu_test fts3atoken-4.4 en_US $input $output + + # ICU handles an unknown locale by falling back to the default. + # So this is not an error. + do_icu_test fts3atoken-4.5 MiddleOfTheOcean $input $output + + set longtoken "AReallyReallyLongTokenOneThatWillSurelyRequire" + append longtoken "AReallocInTheIcuTokenizerCode" + + set input "short tokens then " + append input $longtoken + set output "0 short short " + append output "1 tokens tokens " + append output "2 then then " + append output "3 [string tolower $longtoken] $longtoken" + + do_icu_test fts3atoken-4.6 MiddleOfTheOcean $input $output + do_icu_test fts3atoken-4.7 th_TH $input $output + do_icu_test fts3atoken-4.8 en_US $input $output + + do_execsql_test 5.1 { + CREATE VIRTUAL TABLE x1 USING fts3(name,TOKENIZE icu en_US); + insert into x1 (name) values (NULL); + insert into x1 (name) values (NULL); + delete from x1; + } + + proc cp_to_str {codepoint_list} { + set fmt [string repeat %c [llength $codepoint_list]] + eval [list format $fmt] $codepoint_list + } + + do_test 5.2 { + set str [cp_to_str {19968 26085 32822 32645 27874 23433 20986}] + execsql { INSERT INTO x1 VALUES($str) } + } {} +} + +do_test fts3atoken-internal { + execsql { SELECT fts3_tokenizer_internal_test() } +} {ok} + +#------------------------------------------------------------------------- +# Test empty tokenizer names. +# +do_catchsql_test 6.1.1 { + CREATE VIRTUAL TABLE t3 USING fts4(tokenize=""); +} {1 {unknown tokenizer: }} +do_catchsql_test 6.1.2 { + CREATE VIRTUAL TABLE t3 USING fts4(tokenize=); +} {1 {unknown tokenizer: }} +do_catchsql_test 6.1.3 { + CREATE VIRTUAL TABLE t3 USING fts4(tokenize=" "); +} {1 {unknown tokenizer: }} + +do_catchsql_test 6.2.1 { + SELECT fts3_tokenizer(NULL); +} {1 {unknown tokenizer: }} + +sqlite3_db_config db SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1 +do_catchsql_test 6.2.2 { + SELECT fts3_tokenizer(NULL, X'1234567812345678'); +} {1 {argument type mismatch}} +do_catchsql_test 6.2.3 { + SELECT fts3_tokenizer(NULL, X'12345678'); +} {1 {argument type mismatch}} + + +finish_test diff --git a/test/fts3auto.test b/test/fts3auto.test new file mode 100644 index 0000000..1919397 --- /dev/null +++ b/test/fts3auto.test @@ -0,0 +1,717 @@ +# 2011 June 10 +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If this build does not include FTS3, skip the tests in this file. +# +ifcapable !fts3 { finish_test ; return } +source $testdir/fts3_common.tcl +source $testdir/malloc_common.tcl + +set testprefix fts3auto +set sfep $sqlite_fts3_enable_parentheses +set sqlite_fts3_enable_parentheses 1 + +#-------------------------------------------------------------------------- +# Start of Tcl infrastructure used by tests. The entry points are: +# +# do_fts3query_test +# fts3_make_deferrable +# fts3_zero_long_segments +# + +# +# do_fts3query_test TESTNAME ?OPTIONS? TABLE MATCHEXPR +# +# This proc runs several test cases on FTS3/4 table $TABLE using match +# expression $MATCHEXPR. All documents in $TABLE must be formatted so that +# they can be "tokenized" using the Tcl list commands (llength, lindex etc.). +# The name and column names used by $TABLE must not require any quoting or +# escaping when used in SQL statements. +# +# $MATCHINFO may be any expression accepted by the FTS4 MATCH operator, +# except that the ":token" syntax is not supported. Tcl list +# commands are used to tokenize the expression. Any parenthesis must appear +# either as separate list elements, or as the first (for opening) or last +# (for closing) character of a list element. i.e. the expression "(a OR b)c" +# will not be parsed correctly, but "( a OR b) c" will. +# +# Available OPTIONS are: +# +# -deferred TOKENLIST +# +# If the "deferred" option is supplied, it is passed a list of tokens that +# are deferred by FTS and result in the relevant matchinfo() stats being an +# approximation. +# +set sqlite_fts3_enable_parentheses 1 +proc do_fts3query_test {tn args} { + + set nArg [llength $args] + if {$nArg < 2 || ($nArg % 2)} { + set cmd do_fts3query_test + error "wrong # args: should be \"$cmd ?-deferred LIST? TABLE MATCHEXPR\"" + } + set tbl [lindex $args [expr $nArg-2]] + set match [lindex $args [expr $nArg-1]] + set deferred [list] + + foreach {k v} [lrange $args 0 [expr $nArg-3]] { + switch -- $k { + -deferred { + ifcapable fts4_deferred { set deferred $v } + } + default { + error "bad option \"$k\": must be -deferred" + } + } + } + + get_near_results $tbl $match $deferred aHit + get_near_results $tbl [string map {AND OR} $match] $deferred aMatchinfo + + set matchinfo_asc [list] + foreach docid [lsort -integer -incr [array names aHit]] { + lappend matchinfo_asc $docid $aMatchinfo($docid) + } + set matchinfo_desc [list] + foreach docid [lsort -integer -decr [array names aHit]] { + lappend matchinfo_desc $docid $aMatchinfo($docid) + } + + set title "(\"$match\" -> [llength [array names aHit]] rows)" + + do_execsql_test $tn$title.1 " + SELECT docid FROM $tbl WHERE $tbl MATCH '$match' ORDER BY docid ASC + " [lsort -integer -incr [array names aHit]] + + do_execsql_test $tn$title.2 " + SELECT docid FROM $tbl WHERE $tbl MATCH '$match' ORDER BY docid DESC + " [lsort -integer -decr [array names aHit]] + + do_execsql_test $tn$title.3 " + SELECT docid, mit(matchinfo($tbl, 'x')) FROM $tbl + WHERE $tbl MATCH '$match' ORDER BY docid DESC + " $matchinfo_desc + + do_execsql_test $tn$title.4 " + SELECT docid, mit(matchinfo($tbl, 'x')) FROM $tbl + WHERE $tbl MATCH '$match' ORDER BY docid ASC + " $matchinfo_asc +} + +# fts3_make_deferrable TABLE TOKEN ?NROW? +# +proc fts3_make_deferrable {tbl token {nRow 0}} { + + set stmt [sqlite3_prepare db "SELECT * FROM $tbl" -1 dummy] + set name [sqlite3_column_name $stmt 0] + sqlite3_finalize $stmt + + if {$nRow==0} { + set nRow [db one "SELECT count(*) FROM $tbl"] + } + set pgsz [db one "PRAGMA page_size"] + execsql BEGIN + for {set i 0} {$i < ($nRow * $pgsz * 1.2)/100} {incr i} { + set doc [string repeat "$token " 100] + execsql "INSERT INTO $tbl ($name) VALUES(\$doc)" + } + execsql "INSERT INTO $tbl ($name) VALUES('aaaaaaa ${token}aaaaa')" + execsql COMMIT + + return [expr $nRow*$pgsz] +} + +# fts3_zero_long_segments TABLE ?LIMIT? +# +proc fts3_zero_long_segments {tbl limit} { + sqlite3_db_config db DEFENSIVE 0 + execsql " + UPDATE ${tbl}_segments + SET block = zeroblob(length(block)) + WHERE length(block)>$limit + " + return [db changes] +} + + +proc mit {blob} { + set scan(littleEndian) i* + set scan(bigEndian) I* + binary scan $blob $scan($::tcl_platform(byteOrder)) r + return $r +} +db func mit mit + +proc fix_phrase_expr {cols expr colfiltervar} { + upvar $colfiltervar iColFilter + + set out [list] + foreach t $expr { + if {[string match *:* $t]} { + set col [lindex [split $t :] 0] + set t [lindex [split $t :] 1] + set iCol [lsearch $cols $col] + if {$iCol<0} { error "unknown column: $col" } + if {$iColFilter < 0} { + set iColFilter $iCol + } elseif {$iColFilter != $iCol} { + set iColFilter [llength $cols] + } + } + lappend out $t + } + + return $out +} + +proc fix_near_expr {cols expr colfiltervar} { + upvar $colfiltervar iColFilter + + set iColFilter -1 + + set out [list] + lappend out [fix_phrase_expr $cols [lindex $expr 0] iColFilter] + foreach {a b} [lrange $expr 1 end] { + if {[string match -nocase near $a]} { set a 10 } + if {[string match -nocase near/* $a]} { set a [string range $a 5 end] } + lappend out $a + lappend out [fix_phrase_expr $cols $b iColFilter] + } + return $out +} + +proc get_single_near_results {tbl expr deferred arrayvar nullvar} { + upvar $arrayvar aMatchinfo + upvar $nullvar nullentry + catch {array unset aMatchinfo} + + set cols [list] + set miss [list] + db eval "PRAGMA table_info($tbl)" A { lappend cols $A(name) ; lappend miss 0 } + set expr [fix_near_expr $cols $expr iColFilter] + + # Calculate the expected results using [fts3_near_match]. The following + # loop populates the "hits" and "counts" arrays as follows: + # + # 1. For each document in the table that matches the NEAR expression, + # hits($docid) is set to 1. The set of docids that match the expression + # can therefore be found using [array names hits]. + # + # 2. For each column of each document in the table, counts($docid,$iCol) + # is set to the -phrasecountvar output. + # + set res [list] + catch { array unset hits } + db eval "SELECT docid, * FROM $tbl" d { + set iCol 0 + foreach col [lrange $d(*) 1 end] { + set docid $d(docid) + if {$iColFilter<0 || $iCol==$iColFilter} { + set hit [fts3_near_match $d($col) $expr -p counts($docid,$iCol)] + if {$hit} { set hits($docid) 1 } + } else { + set counts($docid,$iCol) $miss + } + incr iCol + } + } + set nPhrase [expr ([llength $expr]+1)/2] + set nCol $iCol + + # This block populates the nHit and nDoc arrays. For each phrase/column + # in the query/table, array elements are set as follows: + # + # nHit($iPhrase,$iCol) - Total number of hits for phrase $iPhrase in + # column $iCol. + # + # nDoc($iPhrase,$iCol) - Number of documents with at least one hit for + # phrase $iPhrase in column $iCol. + # + for {set iPhrase 0} {$iPhrase < $nPhrase} {incr iPhrase} { + for {set iCol 0} {$iCol < $nCol} {incr iCol} { + set nHit($iPhrase,$iCol) 0 + set nDoc($iPhrase,$iCol) 0 + } + } + foreach key [array names counts] { + set iCol [lindex [split $key ,] 1] + set iPhrase 0 + foreach c $counts($key) { + if {$c>0} { incr nDoc($iPhrase,$iCol) 1 } + incr nHit($iPhrase,$iCol) $c + incr iPhrase + } + } + + if {[llength $deferred] && [llength $expr]==1} { + set phrase [lindex $expr 0] + set rewritten [list] + set partial 0 + foreach tok $phrase { + if {[lsearch $deferred $tok]>=0} { + lappend rewritten * + } else { + lappend rewritten $tok + set partial 1 + } + } + if {$partial==0} { + set tblsize [db one "SELECT count(*) FROM $tbl"] + for {set iCol 0} {$iCol < $nCol} {incr iCol} { + set nHit(0,$iCol) $tblsize + set nDoc(0,$iCol) $tblsize + } + } elseif {$rewritten != $phrase} { + while {[lindex $rewritten end] == "*"} { + set rewritten [lrange $rewritten 0 end-1] + } + while {[lindex $rewritten 0] == "*"} { + set rewritten [lrange $rewritten 1 end] + } + get_single_near_results $tbl [list $rewritten] {} aRewrite nullentry + foreach docid [array names hits] { + set aMatchinfo($docid) $aRewrite($docid) + } + return + } + } + + # Set up the aMatchinfo array. For each document, set aMatchinfo($docid) to + # contain the output of matchinfo('x') for the document. + # + foreach docid [array names hits] { + set mi [list] + for {set iPhrase 0} {$iPhrase<$nPhrase} {incr iPhrase} { + for {set iCol 0} {$iCol<$nCol} {incr iCol} { + lappend mi [lindex $counts($docid,$iCol) $iPhrase] + lappend mi $nHit($iPhrase,$iCol) + lappend mi $nDoc($iPhrase,$iCol) + } + } + set aMatchinfo($docid) $mi + } + + # Set up the nullentry output. + # + set nullentry [list] + for {set iPhrase 0} {$iPhrase<$nPhrase} {incr iPhrase} { + for {set iCol 0} {$iCol<$nCol} {incr iCol} { + lappend nullentry 0 $nHit($iPhrase,$iCol) $nDoc($iPhrase,$iCol) + } + } +} + + +proc matching_brackets {expr} { + if {[string range $expr 0 0]!="(" || [string range $expr end end] !=")"} { + return 0 + } + + set iBracket 1 + set nExpr [string length $expr] + for {set i 1} {$iBracket && $i < $nExpr} {incr i} { + set c [string range $expr $i $i] + if {$c == "("} {incr iBracket} + if {$c == ")"} {incr iBracket -1} + } + + return [expr ($iBracket==0 && $i==$nExpr)] +} + +proc get_near_results {tbl expr deferred arrayvar {nullvar ""}} { + upvar $arrayvar aMatchinfo + if {$nullvar != ""} { upvar $nullvar nullentry } + + set expr [string trim $expr] + while { [matching_brackets $expr] } { + set expr [string trim [string range $expr 1 end-1]] + } + + set prec(NOT) 1 + set prec(AND) 2 + set prec(OR) 3 + + set currentprec 0 + set iBracket 0 + set expr_length [llength $expr] + for {set i 0} {$i < $expr_length} {incr i} { + set op [lindex $expr $i] + if {$iBracket==0 && [info exists prec($op)] && $prec($op)>=$currentprec } { + set opidx $i + set currentprec $prec($op) + } else { + for {set j 0} {$j < [string length $op]} {incr j} { + set c [string range $op $j $j] + if {$c == "("} { incr iBracket +1 } + if {$c == ")"} { incr iBracket -1 } + } + } + } + if {$iBracket!=0} { error "mismatched brackets in: $expr" } + + if {[info exists opidx]==0} { + get_single_near_results $tbl $expr $deferred aMatchinfo nullentry + } else { + set eLeft [lrange $expr 0 [expr $opidx-1]] + set eRight [lrange $expr [expr $opidx+1] end] + + get_near_results $tbl $eLeft $deferred aLeft nullleft + get_near_results $tbl $eRight $deferred aRight nullright + + switch -- [lindex $expr $opidx] { + "NOT" { + foreach hit [array names aLeft] { + if {0==[info exists aRight($hit)]} { + set aMatchinfo($hit) $aLeft($hit) + } + } + set nullentry $nullleft + } + + "AND" { + foreach hit [array names aLeft] { + if {[info exists aRight($hit)]} { + set aMatchinfo($hit) [concat $aLeft($hit) $aRight($hit)] + } + } + set nullentry [concat $nullleft $nullright] + } + + "OR" { + foreach hit [array names aLeft] { + if {[info exists aRight($hit)]} { + set aMatchinfo($hit) [concat $aLeft($hit) $aRight($hit)] + unset aRight($hit) + } else { + set aMatchinfo($hit) [concat $aLeft($hit) $nullright] + } + } + foreach hit [array names aRight] { + set aMatchinfo($hit) [concat $nullleft $aRight($hit)] + } + + set nullentry [concat $nullleft $nullright] + } + } + } +} + + +# End of test procs. Actual tests are below this line. +#-------------------------------------------------------------------------- + +#-------------------------------------------------------------------------- +# The following test cases - fts3auto-1.* - focus on testing the Tcl +# command [fts3_near_match], which is used by other tests in this file. +# +proc test_fts3_near_match {tn doc expr res} { + fts3_near_match $doc $expr -phrasecountvar p + uplevel do_test [list $tn] [list [list set {} $p]] [list $res] +} + +test_fts3_near_match 1.1.1 {a b c a b} a {2} +test_fts3_near_match 1.1.2 {a b c a b} {a 5 b 6 c} {2 2 1} +test_fts3_near_match 1.1.3 {a b c a b} {"a b"} {2} +test_fts3_near_match 1.1.4 {a b c a b} {"b c"} {1} +test_fts3_near_match 1.1.5 {a b c a b} {"c c"} {0} + +test_fts3_near_match 1.2.1 "a b c d e f g" {b 2 f} {0 0} +test_fts3_near_match 1.2.2 "a b c d e f g" {b 3 f} {1 1} +test_fts3_near_match 1.2.3 "a b c d e f g" {f 2 b} {0 0} +test_fts3_near_match 1.2.4 "a b c d e f g" {f 3 b} {1 1} +test_fts3_near_match 1.2.5 "a b c d e f g" {"a b" 2 "f g"} {0 0} +test_fts3_near_match 1.2.6 "a b c d e f g" {"a b" 3 "f g"} {1 1} + +set A "a b c d e f g h i j k l m n o p q r s t u v w x y z" +test_fts3_near_match 1.3.1 $A {"c d" 5 "i j" 1 "e f"} {0 0 0} +test_fts3_near_match 1.3.2 $A {"c d" 5 "i j" 2 "e f"} {1 1 1} + +#-------------------------------------------------------------------------- +# Test cases fts3auto-2.* run some simple tests using the +# [do_fts3query_test] proc. +# +foreach {tn create} { + 1 "fts4(a, b)" + 2 "fts4(a, b, order=DESC)" + 3 "fts4(a, b, order=ASC)" + 4 "fts4(a, b, prefix=1)" + 5 "fts4(a, b, order=DESC, prefix=1)" + 6 "fts4(a, b, order=ASC, prefix=1)" +} { + do_test 2.$tn.1 { + catchsql { DROP TABLE t1 } + execsql "CREATE VIRTUAL TABLE t1 USING $create" + for {set i 0} {$i<32} {incr i} { + set doc [list] + if {$i&0x01} {lappend doc one} + if {$i&0x02} {lappend doc two} + if {$i&0x04} {lappend doc three} + if {$i&0x08} {lappend doc four} + if {$i&0x10} {lappend doc five} + execsql { INSERT INTO t1 VALUES($doc, null) } + } + } {} + + foreach {tn2 expr} { + 1 {one} + 2 {one NEAR/1 five} + 3 {t*} + 4 {t* NEAR/0 five} + 5 {o* NEAR/1 f*} + 6 {one NEAR five NEAR two NEAR four NEAR three} + 7 {one NEAR xyz} + 8 {one OR two} + 9 {one AND two} + 10 {one NOT two} + 11 {one AND two OR three} + 12 {three OR one AND two} + 13 {(three OR one) AND two} + 14 {(three OR one) AND two NOT (five NOT four)} + 15 {"one two"} + 16 {"one two" NOT "three four"} + } { + do_fts3query_test 2.$tn.2.$tn2 t1 $expr + } +} + +#-------------------------------------------------------------------------- +# Some test cases involving deferred tokens. +# + +foreach {tn create} { + 1 "fts4(x)" + 2 "fts4(x, order=DESC)" +} { + catchsql { DROP TABLE t1 } + execsql "CREATE VIRTUAL TABLE t1 USING $create" + do_execsql_test 3.$tn.1 { + INSERT INTO t1(docid, x) VALUES(-2, 'a b c d e f g h i j k'); + INSERT INTO t1(docid, x) VALUES(-1, 'b c d e f g h i j k a'); + INSERT INTO t1(docid, x) VALUES(0, 'c d e f g h i j k a b'); + INSERT INTO t1(docid, x) VALUES(1, 'd e f g h i j k a b c'); + INSERT INTO t1(docid, x) VALUES(2, 'e f g h i j k a b c d'); + INSERT INTO t1(docid, x) VALUES(3, 'f g h i j k a b c d e'); + INSERT INTO t1(docid, x) VALUES(4, 'a c e g i k'); + INSERT INTO t1(docid, x) VALUES(5, 'a d g j'); + INSERT INTO t1(docid, x) VALUES(6, 'c a b'); + } + + set limit [fts3_make_deferrable t1 c] + + do_fts3query_test 3.$tn.2.1 t1 {a OR c} + + ifcapable fts4_deferred { + do_test 3.$tn.3 { fts3_zero_long_segments t1 $limit } {1} + } + + foreach {tn2 expr def} { + 1 {a NEAR c} {} + 2 {a AND c} c + 3 {"a c"} c + 4 {"c a"} c + 5 {"a c" NEAR/1 g} {} + 6 {"a c" NEAR/0 g} {} + } { + do_fts3query_test 3.$tn.4.$tn2 -deferred $def t1 $expr + } +} + +#-------------------------------------------------------------------------- +# +foreach {tn create} { + 1 "fts4(x, y)" + 2 "fts4(x, y, order=DESC)" + 3 "fts4(x, y, order=DESC, prefix=2)" +} { + + execsql [subst { + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING $create; + INSERT INTO t1 VALUES('one two five four five', ''); + INSERT INTO t1 VALUES('', 'one two five four five'); + INSERT INTO t1 VALUES('one two', 'five four five'); + }] + + do_fts3query_test 4.$tn.1.1 t1 {one AND five} + do_fts3query_test 4.$tn.1.2 t1 {one NEAR five} + do_fts3query_test 4.$tn.1.3 t1 {one NEAR/1 five} + do_fts3query_test 4.$tn.1.4 t1 {one NEAR/2 five} + do_fts3query_test 4.$tn.1.5 t1 {one NEAR/3 five} + + do_test 4.$tn.2 { + set limit [fts3_make_deferrable t1 five] + execsql { INSERT INTO t1(t1) VALUES('optimize') } + ifcapable fts4_deferred { + expr {[fts3_zero_long_segments t1 $limit]>0} + } else { + expr 1 + } + } {1} + + do_fts3query_test 4.$tn.3.1 -deferred five t1 {one AND five} + do_fts3query_test 4.$tn.3.2 -deferred five t1 {one NEAR five} + do_fts3query_test 4.$tn.3.3 -deferred five t1 {one NEAR/1 five} + do_fts3query_test 4.$tn.3.4 -deferred five t1 {one NEAR/2 five} + + do_fts3query_test 4.$tn.3.5 -deferred five t1 {one NEAR/3 five} + + do_fts3query_test 4.$tn.4.1 -deferred fi* t1 {on* AND fi*} + do_fts3query_test 4.$tn.4.2 -deferred fi* t1 {on* NEAR fi*} + do_fts3query_test 4.$tn.4.3 -deferred fi* t1 {on* NEAR/1 fi*} + do_fts3query_test 4.$tn.4.4 -deferred fi* t1 {on* NEAR/2 fi*} + do_fts3query_test 4.$tn.4.5 -deferred fi* t1 {on* NEAR/3 fi*} + + ifcapable fts4_deferred { + db eval {UPDATE t1_stat SET value=x'' WHERE id=0} + do_catchsql_test 4.$tn.4.6 { + SELECT docid FROM t1 WHERE t1 MATCH 'on* NEAR/3 fi*' + } {1 {database disk image is malformed}} + } +} + +#-------------------------------------------------------------------------- +# The following test cases - fts3auto-5.* - focus on using prefix indexes. +# +set chunkconfig [fts3_configure_incr_load 1 1] +foreach {tn create pending} { + 1 "fts4(a, b)" 1 + 2 "fts4(a, b, order=ASC, prefix=1)" 1 + 3 "fts4(a, b, order=ASC, prefix=\"1,3\")" 0 + 4 "fts4(a, b, order=DESC, prefix=\"2,4\")" 0 + 5 "fts4(a, b, order=DESC, prefix=\"1\")" 0 + 6 "fts4(a, b, order=ASC, prefix=\"1,3\")" 0 +} { + + execsql [subst { + DROP TABLE IF EXISTS t1; + CREATE VIRTUAL TABLE t1 USING $create; + }] + + if {$pending} {execsql BEGIN} + + foreach {a b} { + "the song of songs which is solomons" + "let him kiss me with the kisses of his mouth for thy love is better than wine" + "because of the savour of thy good ointments thy name is as ointment poured forth therefore do the virgins love thee" + "draw me we will run after thee the king hath brought me into his chambers we will be glad and rejoice in thee we will remember thy love more than wine the upright love thee" + "i am black but comely o ye daughters of jerusalem as the tents of kedar as the curtains of solomon" + "look not upon me because i am black because the sun hath looked upon me my mothers children were angry with me they made me the keeper of the vineyards but mine own vineyard have i not kept" + "tell me o thou whom my soul loveth where thou feedest where thou makest thy flock to rest at noon for why should i be as one that turneth aside by the flocks of thy companions?" + "if thou know not o thou fairest among women go thy way forth by the footsteps of the flock and feed thy kids beside the shepherds tents" + "i have compared thee o my love to a company of horses in pharaohs chariots" + "thy cheeks are comely with rows of jewels thy neck with chains of gold" + "we will make thee borders of gold with studs of silver" + "while the king sitteth at his table my spikenard sendeth forth the smell thereof" + "a bundle of myrrh is my wellbeloved unto me he shall lie all night betwixt my breasts" + "my beloved is unto me as a cluster of camphire in the vineyards of en gedi" + "behold thou art fair my love behold thou art fair thou hast doves eyes" + "behold thou art fair my beloved yea pleasant also our bed is green" + "the beams of our house are cedar and our rafters of fir" + } { + execsql {INSERT INTO t1(a, b) VALUES($a, $b)} + } + + + do_fts3query_test 5.$tn.1.1 t1 {s*} + do_fts3query_test 5.$tn.1.2 t1 {so*} + do_fts3query_test 5.$tn.1.3 t1 {"s* o*"} + do_fts3query_test 5.$tn.1.4 t1 {b* NEAR/3 a*} + do_fts3query_test 5.$tn.1.5 t1 {a*} + do_fts3query_test 5.$tn.1.6 t1 {th* NEAR/5 a* NEAR/5 w*} + do_fts3query_test 5.$tn.1.7 t1 {"b* th* art* fair*"} + + if {$pending} {execsql COMMIT} +} +eval fts3_configure_incr_load $chunkconfig + +foreach {tn pending create} { + 1 0 "fts4(a, b, c, d)" + 2 1 "fts4(a, b, c, d)" + 3 0 "fts4(a, b, c, d, order=DESC)" + 4 1 "fts4(a, b, c, d, order=DESC)" +} { + execsql [subst { + DROP TABLE IF EXISTS t1; + CREATE VIRTUAL TABLE t1 USING $create; + }] + + + if {$pending} { execsql BEGIN } + + foreach {a b c d} { + "A B C" "D E F" "G H I" "J K L" + "B C D" "E F G" "H I J" "K L A" + "C D E" "F G H" "I J K" "L A B" + "D E F" "G H I" "J K L" "A B C" + "E F G" "H I J" "K L A" "B C D" + "F G H" "I J K" "L A B" "C D E" + } { + execsql { INSERT INTO t1 VALUES($a, $b, $c, $d) } + } + + do_fts3query_test 6.$tn.1 t1 {b:G} + do_fts3query_test 6.$tn.2 t1 {b:G AND c:I} + do_fts3query_test 6.$tn.3 t1 {b:G NEAR c:I} + do_fts3query_test 6.$tn.4 t1 {a:C OR b:G OR c:K OR d:C} + + do_fts3query_test 6.$tn.5 t1 {a:G OR b:G} + + catchsql { COMMIT } +} + +foreach {tn create} { + 1 "fts4(x)" + 2 "fts4(x, order=DESC)" +} { + execsql [subst { + DROP TABLE IF EXISTS t1; + CREATE VIRTUAL TABLE t1 USING $create; + }] + + foreach {x} { + "F E N O T K X V A X I E X A P G Q V H U" + "R V A E T C V Q N I E L O N U G J K L U" + "U Y I G W M V F J L X I D C H F P J Q B" + "S G D Z X R P G S S Y B K A S G A I L L" + "L S I C H T Z S R Q P R N K J X L F M J" + "C C C D P X B Z C M A D A C X S B T X V" + "W Y J M D R G V R K B X S A W R I T N C" + "P K L W T M S P O Y Y V V O E H Q A I R" + "C D Y I C Z F H J C O Y A Q F L S B D K" + "P G S C Y C Y V I M B D S Z D D Y W I E" + "Z K Z U E E S F Y X T U A L W O U J C Q" + "P A T Z S W L P L Q V Y Y I P W U X S S" + "I U I H U O F Z F R H R F T N D X A G M" + "N A B M S H K X S O Y D T X S B R Y H Z" + "L U D A S K I L S V Z J P U B E B Y H M" + } { + execsql { INSERT INTO t1 VALUES($x) } + } + + # Add extra documents to the database such that token "B" will be considered + # deferrable if considering the other tokens means that 2 or fewer documents + # will be loaded into memory. + # + fts3_make_deferrable t1 B 2 + + # B is not deferred in either of the first two tests below, since filtering + # on "M" or "D" returns 10 documents or so. But filtering on "M * D" only + # returns 2, so B is deferred in this case. + # + do_fts3query_test 7.$tn.1 t1 {"M B"} + do_fts3query_test 7.$tn.2 t1 {"B D"} + do_fts3query_test 7.$tn.3 -deferred B t1 {"M B D"} +} + +set sqlite_fts3_enable_parentheses $sfep +finish_test diff --git a/test/fts3aux1.test b/test/fts3aux1.test new file mode 100644 index 0000000..1524d6d --- /dev/null +++ b/test/fts3aux1.test @@ -0,0 +1,531 @@ +# 2011 January 27 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS3 module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +ifcapable !fts3 { finish_test ; return } +set ::testprefix fts3aux1 + +do_execsql_test 1.1 { + CREATE VIRTUAL TABLE t1 USING fts4; + INSERT INTO t1 VALUES('one two three four'); + INSERT INTO t1 VALUES('three four five six'); + INSERT INTO t1 VALUES('one three five seven'); + + CREATE VIRTUAL TABLE terms USING fts4aux(t1); + SELECT term, documents, occurrences FROM terms WHERE col = '*'; +} { + five 2 2 four 2 2 one 2 2 seven 1 1 + six 1 1 three 3 3 two 1 1 +} + +do_execsql_test 1.2 { + INSERT INTO t1 VALUES('one one one three three three'); + SELECT term, documents, occurrences FROM terms WHERE col = '*'; +} { + five 2 2 four 2 2 one 3 5 seven 1 1 + six 1 1 three 4 6 two 1 1 +} + +do_execsql_test 1.3.1 { DELETE FROM t1; } +do_execsql_test 1.3.2 { + SELECT term, documents, occurrences FROM terms WHERE col = '*'; +} + +do_execsql_test 1.4 { + INSERT INTO t1 VALUES('a b a b a b a'); + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + SELECT term, documents, occurrences FROM terms WHERE col = '*'; +} {a 256 1024 b 256 768} + +#------------------------------------------------------------------------- +# The following tests verify that the fts4aux module uses the full-text +# index to reduce the number of rows scanned in the following circumstances: +# +# * when there is equality comparison against the term column using the +# BINARY collating sequence. +# +# * when there is a range constraint on the term column using the BINARY +# collating sequence. +# +# And also uses the full-text index to optimize ORDER BY clauses of the +# form "ORDER BY term ASC" or equivalent. +# +# Test organization is: +# +# fts3aux1-2.1.*: equality constraints. +# fts3aux1-2.2.*: range constraints. +# fts3aux1-2.3.*: ORDER BY optimization. +# + +do_execsql_test 2.0 { + DROP TABLE t1; + DROP TABLE terms; + + CREATE VIRTUAL TABLE x1 USING fts4(x); + INSERT INTO x1(x1) VALUES('nodesize=24'); + CREATE VIRTUAL TABLE terms USING fts4aux(x1); + + CREATE VIEW terms_v AS + SELECT term, documents, occurrences FROM terms WHERE col = '*'; + + INSERT INTO x1 VALUES('braes brag bragged bragger bragging'); + INSERT INTO x1 VALUES('brags braid braided braiding braids'); + INSERT INTO x1 VALUES('brain brainchild brained braining brains'); + INSERT INTO x1 VALUES('brainstem brainstems brainstorm brainstorms'); +} + +proc rec {varname x} { + global $varname + incr $varname + return 1 +} +db func rec rec + +# Use EQP to show that the WHERE expression "term='braid'" uses a different +# index number (1) than "+term='braid'" (0). +# +do_execsql_test 2.1.1.1 { + EXPLAIN QUERY PLAN SELECT * FROM terms WHERE term='braid' +} {/*SCAN terms VIRTUAL TABLE INDEX 1:*/} +do_execsql_test 2.1.1.2 { + EXPLAIN QUERY PLAN SELECT * FROM terms WHERE +term='braid' +} {/*SCAN terms VIRTUAL TABLE INDEX 0:*/} + +# Now show that using "term='braid'" means the virtual table returns +# only 1 row to SQLite, but "+term='braid'" means all 19 are returned. +# +do_test 2.1.2.1 { + set cnt 0 + execsql { SELECT * FROM terms_v WHERE rec('cnt', term) AND term='braid' } + set cnt +} {1} +do_test 2.1.2.2 { + set cnt 0 + execsql { SELECT * FROM terms_v WHERE rec('cnt', term) AND +term='braid' } + set cnt +} {19} + +# Similar to the test immediately above, but using a term ("breakfast") that +# is not featured in the dataset. +# +do_test 2.1.3.1 { + set cnt 0 + execsql { SELECT * FROM terms_v WHERE rec('cnt', term) AND term='breakfast' } + set cnt +} {0} +do_test 2.1.3.2 { + set cnt 0 + execsql { SELECT * FROM terms_v WHERE rec('cnt', term) AND +term='breakfast' } + set cnt +} {19} + +do_execsql_test 2.1.4.1 { SELECT * FROM terms_v WHERE term='braid' } {braid 1 1} +do_execsql_test 2.1.4.2 { SELECT * FROM terms_v WHERE +term='braid'} {braid 1 1} +do_execsql_test 2.1.4.3 { SELECT * FROM terms_v WHERE term='breakfast' } {} +do_execsql_test 2.1.4.4 { SELECT * FROM terms_v WHERE +term='breakfast' } {} + +do_execsql_test 2.1.4.5 { SELECT * FROM terms_v WHERE term='cba' } {} +do_execsql_test 2.1.4.6 { SELECT * FROM terms_v WHERE +term='cba' } {} +do_execsql_test 2.1.4.7 { SELECT * FROM terms_v WHERE term='abc' } {} +do_execsql_test 2.1.4.8 { SELECT * FROM terms_v WHERE +term='abc' } {} + +# Special case: term=NULL +# +do_execsql_test 2.1.5 { SELECT * FROM terms WHERE term=NULL } {} + +do_execsql_test 2.2.1.1 { + EXPLAIN QUERY PLAN SELECT * FROM terms WHERE term>'brain' +} {/*SCAN terms VIRTUAL TABLE INDEX 2:*/} +do_execsql_test 2.2.1.2 { + EXPLAIN QUERY PLAN SELECT * FROM terms WHERE +term>'brain' +} {/*SCAN terms VIRTUAL TABLE INDEX 0:*/} + +do_execsql_test 2.2.1.3 { + EXPLAIN QUERY PLAN SELECT * FROM terms WHERE term<'brain' +} {/*SCAN terms VIRTUAL TABLE INDEX 4:*/} +do_execsql_test 2.2.1.4 { + EXPLAIN QUERY PLAN SELECT * FROM terms WHERE +term<'brain' +} {/*SCAN terms VIRTUAL TABLE INDEX 0:*/} + +do_execsql_test 2.2.1.5 { + EXPLAIN QUERY PLAN SELECT * FROM terms WHERE term BETWEEN 'brags' AND 'brain' +} {/*SCAN terms VIRTUAL TABLE INDEX 6:*/} +do_execsql_test 2.2.1.6 { + EXPLAIN QUERY PLAN SELECT * FROM terms WHERE +term BETWEEN 'brags' AND 'brain' +} {/*SCAN terms VIRTUAL TABLE INDEX 0:*/} + +do_test 2.2.2.1 { + set cnt 0 + execsql { SELECT * FROM terms WHERE rec('cnt', term) AND term>'brain' } + set cnt +} {18} +do_test 2.2.2.2 { + set cnt 0 + execsql { SELECT * FROM terms WHERE rec('cnt', term) AND +term>'brain' } + set cnt +} {38} +do_execsql_test 2.2.2.3 { + SELECT term, documents, occurrences FROM terms_v WHERE term>'brain' +} { + brainchild 1 1 brained 1 1 braining 1 1 brains 1 1 + brainstem 1 1 brainstems 1 1 brainstorm 1 1 brainstorms 1 1 +} +do_execsql_test 2.2.2.4 { + SELECT term, documents, occurrences FROM terms_v WHERE +term>'brain' +} { + brainchild 1 1 brained 1 1 braining 1 1 brains 1 1 + brainstem 1 1 brainstems 1 1 brainstorm 1 1 brainstorms 1 1 +} +do_execsql_test 2.2.2.5 { + SELECT term, documents, occurrences FROM terms_v WHERE term>='brain' +} { + brain 1 1 + brainchild 1 1 brained 1 1 braining 1 1 brains 1 1 + brainstem 1 1 brainstems 1 1 brainstorm 1 1 brainstorms 1 1 +} +do_execsql_test 2.2.2.6 { + SELECT term, documents, occurrences FROM terms_v WHERE +term>='brain' +} { + brain 1 1 + brainchild 1 1 brained 1 1 braining 1 1 brains 1 1 + brainstem 1 1 brainstems 1 1 brainstorm 1 1 brainstorms 1 1 +} + +do_execsql_test 2.2.2.7 { + SELECT term, documents, occurrences FROM terms_v WHERE term>='abc' +} { + braes 1 1 brag 1 1 bragged 1 1 bragger 1 1 + bragging 1 1 brags 1 1 braid 1 1 braided 1 1 + braiding 1 1 braids 1 1 brain 1 1 brainchild 1 1 + brained 1 1 braining 1 1 brains 1 1 brainstem 1 1 + brainstems 1 1 brainstorm 1 1 brainstorms 1 1 +} +do_execsql_test 2.2.2.8 { + SELECT term, documents, occurrences FROM terms_v WHERE +term>='abc' +} { + braes 1 1 brag 1 1 bragged 1 1 bragger 1 1 + bragging 1 1 brags 1 1 braid 1 1 braided 1 1 + braiding 1 1 braids 1 1 brain 1 1 brainchild 1 1 + brained 1 1 braining 1 1 brains 1 1 brainstem 1 1 + brainstems 1 1 brainstorm 1 1 brainstorms 1 1 +} + +do_execsql_test 2.2.2.9 { + SELECT term, documents, occurrences FROM terms_v WHERE term>='brainstorms' +} {brainstorms 1 1} +do_execsql_test 2.2.2.10 { + SELECT term, documents, occurrences FROM terms_v WHERE term>='brainstorms' +} {brainstorms 1 1} +do_execsql_test 2.2.2.11 { SELECT * FROM terms_v WHERE term>'brainstorms' } {} +do_execsql_test 2.2.2.12 { SELECT * FROM terms_v WHERE term>'brainstorms' } {} + +do_execsql_test 2.2.2.13 { SELECT * FROM terms_v WHERE term>'cba' } {} +do_execsql_test 2.2.2.14 { SELECT * FROM terms_v WHERE term>'cba' } {} + +do_test 2.2.3.1 { + set cnt 0 + execsql { SELECT * FROM terms WHERE rec('cnt', term) AND term<'brain' } + set cnt +} {22} +do_test 2.2.3.2 { + set cnt 0 + execsql { SELECT * FROM terms WHERE rec('cnt', term) AND +term<'brain' } + set cnt +} {38} +do_execsql_test 2.2.3.3 { + SELECT term, documents, occurrences FROM terms_v WHERE term<'brain' +} { + braes 1 1 brag 1 1 bragged 1 1 bragger 1 1 bragging 1 1 + brags 1 1 braid 1 1 braided 1 1 braiding 1 1 braids 1 1 +} +do_execsql_test 2.2.3.4 { + SELECT term, documents, occurrences FROM terms_v WHERE +term<'brain' +} { + braes 1 1 brag 1 1 bragged 1 1 bragger 1 1 bragging 1 1 + brags 1 1 braid 1 1 braided 1 1 braiding 1 1 braids 1 1 +} +do_execsql_test 2.2.3.5 { + SELECT term, documents, occurrences FROM terms_v WHERE term<='brain' +} { + braes 1 1 brag 1 1 bragged 1 1 bragger 1 1 bragging 1 1 + brags 1 1 braid 1 1 braided 1 1 braiding 1 1 braids 1 1 + brain 1 1 +} +do_execsql_test 2.2.3.6 { + SELECT term, documents, occurrences FROM terms_v WHERE +term<='brain' +} { + braes 1 1 brag 1 1 bragged 1 1 bragger 1 1 bragging 1 1 + brags 1 1 braid 1 1 braided 1 1 braiding 1 1 braids 1 1 + brain 1 1 +} + +do_test 2.2.4.1 { + set cnt 0 + execsql { + SELECT term, documents, occurrences FROM terms + WHERE rec('cnt', term) AND term BETWEEN 'brags' AND 'brain' + } + set cnt +} {12} +do_test 2.2.4.2 { + set cnt 0 + execsql { + SELECT term, documents, occurrences FROM terms + WHERE rec('cnt', term) AND +term BETWEEN 'brags' AND 'brain' + } + set cnt +} {38} +do_execsql_test 2.2.4.3 { + SELECT term, documents, occurrences FROM terms_v + WHERE rec('cnt', term) AND term BETWEEN 'brags' AND 'brain' +} { + brags 1 1 braid 1 1 braided 1 1 braiding 1 1 braids 1 1 brain 1 1 +} +do_execsql_test 2.2.4.4 { + SELECT term, documents, occurrences FROM terms_v + WHERE rec('cnt', term) AND +term BETWEEN 'brags' AND 'brain' +} { + brags 1 1 braid 1 1 braided 1 1 braiding 1 1 braids 1 1 brain 1 1 +} +do_execsql_test 2.2.4.5 { + SELECT term, documents, occurrences FROM terms_v + WHERE rec('cnt', term) AND term > 'brags' AND term < 'brain' +} { + braid 1 1 braided 1 1 braiding 1 1 braids 1 1 +} +do_execsql_test 2.2.4.6 { + SELECT term, documents, occurrences FROM terms_v + WHERE rec('cnt', term) AND +term > 'brags' AND +term < 'brain' +} { + braid 1 1 braided 1 1 braiding 1 1 braids 1 1 +} + +# Check that "ORDER BY term ASC" and equivalents are sorted by the +# virtual table implementation. Any other ORDER BY clause requires +# SQLite to sort results using a temporary b-tree. +# +foreach {tn sort orderby} { + 1 0 "ORDER BY term ASC" + 2 0 "ORDER BY term" + 3 1 "ORDER BY term DESC" + 4 1 "ORDER BY documents ASC" + 5 1 "ORDER BY documents" + 6 1 "ORDER BY documents DESC" + 7 1 "ORDER BY occurrences ASC" + 8 1 "ORDER BY occurrences" + 9 1 "ORDER BY occurrences DESC" +} { + + set res {SCAN terms VIRTUAL TABLE INDEX 0:} + if {$sort} { append res {*USE TEMP B-TREE FOR ORDER BY} } + set res "/*$res*/" + + set sql "SELECT * FROM terms $orderby" + do_execsql_test 2.3.1.$tn "EXPLAIN QUERY PLAN $sql" $res +} + +#------------------------------------------------------------------------- +# The next set of tests, fts3aux1-3.*, test error conditions in the +# fts4aux module. Except, fault injection testing (OOM, IO error etc.) is +# done in fts3fault2.test +# + +do_execsql_test 3.1.1 { + CREATE VIRTUAL TABLE t2 USING fts4; +} + +do_catchsql_test 3.1.2 { + CREATE VIRTUAL TABLE terms2 USING fts4aux; +} {1 {invalid arguments to fts4aux constructor}} +do_catchsql_test 3.1.3 { + CREATE VIRTUAL TABLE terms2 USING fts4aux(t2, t2); +} {1 {invalid arguments to fts4aux constructor}} + +do_execsql_test 3.2.1 { + CREATE VIRTUAL TABLE terms3 USING fts4aux(does_not_exist) +} +do_catchsql_test 3.2.2 { + SELECT * FROM terms3 +} {1 {SQL logic error}} +do_catchsql_test 3.2.3 { + SELECT * FROM terms3 WHERE term = 'abc' +} {1 {SQL logic error}} + +do_catchsql_test 3.3.1 { + INSERT INTO terms VALUES(1,2,3); +} {1 {table terms may not be modified}} +do_catchsql_test 3.3.2 { + DELETE FROM terms +} {1 {table terms may not be modified}} +do_catchsql_test 3.3.3 { + UPDATE terms set documents = documents+1; +} {1 {table terms may not be modified}} + + +#------------------------------------------------------------------------- +# The following tests - fts4aux-4.* - test that joins work with fts4aux +# tables. And that fts4aux provides reasonably sane cost information via +# xBestIndex to the query planner. +# +db close +forcedelete test.db +sqlite3 db test.db +do_execsql_test 4.1 { + CREATE VIRTUAL TABLE x1 USING fts4(x); + CREATE VIRTUAL TABLE terms USING fts4aux(x1); + CREATE TABLE x2(y); + CREATE TABLE x3(y); + CREATE INDEX i1 ON x3(y); + + INSERT INTO x1 VALUES('a b c d e'); + INSERT INTO x1 VALUES('f g h i j'); + INSERT INTO x1 VALUES('k k l l a'); + + INSERT INTO x2 SELECT term FROM terms WHERE col = '*'; + INSERT INTO x3 SELECT term FROM terms WHERE col = '*'; +} + +proc do_plansql_test {tn sql r1 r2} { + do_eqp_test $tn.eqp $sql $r1 + do_execsql_test $tn $sql $r2 +} + +do_plansql_test 4.2 { + SELECT y FROM x2, terms WHERE y = term AND col = '*' +} { + QUERY PLAN + |--SCAN x2 + `--SCAN terms VIRTUAL TABLE INDEX 1: +} { + a b c d e f g h i j k l +} + +do_plansql_test 4.3 { + SELECT y FROM terms, x2 WHERE y = term AND col = '*' +} { + QUERY PLAN + |--SCAN x2 + `--SCAN terms VIRTUAL TABLE INDEX 1: +} { + a b c d e f g h i j k l +} + +do_plansql_test 4.4 { + SELECT y FROM x3, terms WHERE y = term AND col = '*' +} { + QUERY PLAN + |--SCAN terms VIRTUAL TABLE INDEX 0: + `--SEARCH x3 USING COVERING INDEX i1 (y=?) +} { + a b c d e f g h i j k l +} + +do_plansql_test 4.5 { + SELECT y FROM terms, x3 WHERE y = term AND occurrences>1 AND col = '*' +} { + QUERY PLAN + |--SCAN terms VIRTUAL TABLE INDEX 0: + `--SEARCH x3 USING COVERING INDEX i1 (y=?) +} { + a k l +} + +#------------------------------------------------------------------------- +# The following tests check that fts4aux can handle an fts table with an +# odd name (one that requires quoting for use in SQL statements). And that +# the argument to the fts4aux constructor is properly dequoted before use. +# +do_execsql_test 5.1 { + CREATE VIRTUAL TABLE "abc '!' def" USING fts4(x, y); + INSERT INTO "abc '!' def" VALUES('XX', 'YY'); + + CREATE VIRTUAL TABLE terms3 USING fts4aux("abc '!' def"); + SELECT * FROM terms3; +} {xx * 1 1 xx 0 1 1 yy * 1 1 yy 1 1 1} + +do_execsql_test 5.2 { + CREATE VIRTUAL TABLE "%%^^%%" USING fts4aux('abc ''!'' def'); + SELECT * FROM "%%^^%%"; +} {xx * 1 1 xx 0 1 1 yy * 1 1 yy 1 1 1} + +#------------------------------------------------------------------------- +# Test that we can create an fts4aux table in the temp database. +# +forcedelete test.db2 +do_execsql_test 6.1 { + CREATE VIRTUAL TABLE ft1 USING fts4(x, y); + INSERT INTO ft1 VALUES('a b', 'c d'); + INSERT INTO ft1 VALUES('e e', 'c d'); + INSERT INTO ft1 VALUES('a a', 'b b'); + CREATE VIRTUAL TABLE temp.aux1 USING fts4aux(main, ft1); + SELECT * FROM aux1; +} { + a * 2 3 a 0 2 3 + b * 2 3 b 0 1 1 b 1 1 2 + c * 2 2 c 1 2 2 + d * 2 2 d 1 2 2 + e * 1 2 e 0 1 2 +} + +do_execsql_test 6.2 { + ATTACH 'test.db2' AS att; + CREATE VIRTUAL TABLE att.ft1 USING fts4(x, y); + INSERT INTO att.ft1 VALUES('v w', 'x y'); + INSERT INTO att.ft1 VALUES('z z', 'x y'); + INSERT INTO att.ft1 VALUES('v v', 'w w'); + CREATE VIRTUAL TABLE temp.aux2 USING fts4aux(att, ft1); + SELECT * FROM aux2; +} { + v * 2 3 v 0 2 3 + w * 2 3 w 0 1 1 w 1 1 2 + x * 2 2 x 1 2 2 + y * 2 2 y 1 2 2 + z * 1 2 z 0 1 2 +} + +foreach {tn q res1 res2} { + 1 { SELECT * FROM %%% WHERE term = 'a' } {a * 2 3 a 0 2 3} {} + 2 { SELECT * FROM %%% WHERE term = 'x' } {} {x * 2 2 x 1 2 2} + + 3 { SELECT * FROM %%% WHERE term >= 'y' } + {} {y * 2 2 y 1 2 2 z * 1 2 z 0 1 2} + + 4 { SELECT * FROM %%% WHERE term <= 'c' } + {a * 2 3 a 0 2 3 b * 2 3 b 0 1 1 b 1 1 2 c * 2 2 c 1 2 2} {} +} { + set sql1 [string map {%%% aux1} $q] + set sql2 [string map {%%% aux2} $q] + + do_execsql_test 7.$tn.1 $sql1 $res1 + do_execsql_test 7.$tn.2 $sql2 $res2 +} + +do_test 8.1 { + catchsql { CREATE VIRTUAL TABLE att.aux3 USING fts4aux(main, ft1) } +} {1 {invalid arguments to fts4aux constructor}} + +do_test 8.2 { + execsql {DETACH att} + catchsql { SELECT * FROM aux2 } +} {1 {SQL logic error}} + +finish_test diff --git a/test/fts3aux2.test b/test/fts3aux2.test new file mode 100644 index 0000000..9554022 --- /dev/null +++ b/test/fts3aux2.test @@ -0,0 +1,168 @@ +# 2011 January 27 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS3 module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +ifcapable !fts3 { finish_test ; return } +set ::testprefix fts3aux2 + +do_execsql_test 1.1 { + CREATE VIRTUAL TABLE t1 USING fts4(a, b, languageid=l); + INSERT INTO t1(a, b, l) VALUES + ('zero zero', 'zero zero', 0), + ('one two', 'three four', 1), + ('five six', 'seven eight', 2) + ; + CREATE VIRTUAL TABLE terms USING fts4aux(t1); +} {} + +do_execsql_test 1.2.1 { + SELECT term, documents, occurrences, languageid FROM terms WHERE col = '*'; +} {zero 1 4 0} + +do_execsql_test 1.2.2 { + SELECT * FROM terms; +} {zero * 1 4 zero 0 1 2 zero 1 1 2} + +do_execsql_test 1.2.3 { + SELECT * FROM terms WHERE languageid=''; +} {} + +do_execsql_test 1.2.4 { + SELECT * FROM terms WHERE languageid=-1; +} {} + +do_execsql_test 1.2.5 { + SELECT * FROM terms WHERE languageid=9223372036854775807; +} {} + +do_execsql_test 1.2.6 { + SELECT * FROM terms WHERE languageid=-9223372036854775808; +} {} + +do_execsql_test 1.2.7 { + SELECT * FROM terms WHERE languageid=NULL; +} {} + +do_execsql_test 1.3.1 { + SELECT term, documents, occurrences, languageid + FROM terms WHERE col = '*' AND languageid=1; +} { + four 1 1 1 one 1 1 1 three 1 1 1 two 1 1 1 +} + +do_execsql_test 1.3.2 { + SELECT term, col, documents, occurrences, languageid + FROM terms WHERE languageid=1; +} { + four * 1 1 1 four 1 1 1 1 + one * 1 1 1 one 0 1 1 1 + three * 1 1 1 three 1 1 1 1 + two * 1 1 1 two 0 1 1 1 +} + +do_execsql_test 1.3.3 { + SELECT term, col, documents, occurrences, languageid + FROM terms WHERE languageid=1 AND term='zero' +} { +} + +do_execsql_test 1.3.4 { + SELECT term, col, documents, occurrences, languageid + FROM terms WHERE languageid='1' AND term='two' +} { + two * 1 1 1 two 0 1 1 1 +} + +do_execsql_test 1.3.5 { + SELECT term, col, documents, occurrences, languageid + FROM terms WHERE languageid='+1' AND term>'four' +} { + one * 1 1 1 one 0 1 1 1 + three * 1 1 1 three 1 1 1 1 + two * 1 1 1 two 0 1 1 1 +} + +do_execsql_test 1.4.1 { + SELECT term, documents, occurrences, languageid + FROM terms WHERE col = '*' AND languageid=2; +} { + eight 1 1 2 five 1 1 2 seven 1 1 2 six 1 1 2 +} + +do_execsql_test 1.4.2 { + SELECT term, col, documents, occurrences, languageid + FROM terms WHERE languageid=2; +} { + eight * 1 1 2 eight 1 1 1 2 + five * 1 1 2 five 0 1 1 2 + seven * 1 1 2 seven 1 1 1 2 + six * 1 1 2 six 0 1 1 2 +} + +do_execsql_test 1.4.3 { + SELECT term, col, documents, occurrences, languageid + FROM terms WHERE languageid=2 AND term='five'; +} { + five * 1 1 2 five 0 1 1 2 +} + +do_execsql_test 1.4.4 { + SELECT term, col, documents, occurrences, languageid + FROM terms WHERE term='five' AND languageid=2 +} { + five * 1 1 2 five 0 1 1 2 +} + +do_execsql_test 1.4.5 { + SELECT term, col, documents, occurrences, languageid + FROM terms WHERE term>='seven' AND languageid=2 +} { + seven * 1 1 2 seven 1 1 1 2 + six * 1 1 2 six 0 1 1 2 +} + +do_execsql_test 1.4.6 { + SELECT term, col, documents, occurrences, languageid + FROM terms WHERE term>='e' AND term<'seven' AND languageid=2 +} { + eight * 1 1 2 eight 1 1 1 2 + five * 1 1 2 five 0 1 1 2 +} + +#------------------------------------------------------------------------- +do_execsql_test 2.0 { + CREATE VIRTUAL TABLE ft USING fts3(); + INSERT INTO ft VALUES('a_234567890123456789'); + INSERT INTO ft VALUES('b_234567890123456789'); + INSERT INTO ft VALUES('c_234567890123456789'); + CREATE VIRTUAL TABLE t2 USING fts4aux(ft); +} + +do_execsql_test 2.1 { + SELECT term FROM t2 WHERE term=X'625f323334353637383930313233343536373839'; +} + +do_execsql_test 2.2 { + SELECT term FROM t2 WHERE term 16. +set text { + Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas + iaculis mollis ipsum. Praesent rhoncus placerat justo. Duis non quam + sed turpis posuere placerat. Curabitur et lorem in lorem porttitor + aliquet. Pellentesque bibendum tincidunt diam. Vestibulum blandit + ante nec elit. In sapien diam, facilisis eget, dictum sed, viverra + at, felis. Vestibulum magna. Sed magna dolor, vestibulum rhoncus, + ornare vel, vulputate sit amet, felis. Integer malesuada, tellus at + luctus gravida, diam nunc porta nibh, nec imperdiet massa metus eu + lectus. Aliquam nisi. Nunc fringilla nulla at lectus. Suspendisse + potenti. Cum sociis natoque penatibus et magnis dis parturient + montes, nascetur ridiculus mus. Pellentesque odio nulla, feugiat eu, + suscipit nec, consequat quis, risus. +} +append text $text + +db eval {CREATE VIRTUAL TABLE t2 USING fts3(c)} +set res {} +db eval {BEGIN} +for {set ii 0} {$ii<10000} {incr ii} { + db eval {INSERT INTO t2 (c) VALUES ($text)} + lappend res [expr {$ii+1}] + if {($ii%500)==0} { + db eval { + COMMIT; + BEGIN; + } + } +} +db eval {COMMIT} + +do_test fts3b-2.1 { + execsql { + SELECT rowid FROM t2 WHERE c MATCH 'lorem'; + } +} $res + +db eval {VACUUM} + +# The VACUUM renumbered the t2_segment table in fts2, which would +# break the following. +do_test fts3b-2.2 { + execsql { + SELECT rowid FROM t2 WHERE c MATCH 'lorem'; + } +} $res + +# Since fts3 is already an API break, I've marked the table-named +# column HIDDEN. + +db eval { + CREATE VIRTUAL TABLE t3 USING fts3(c); + INSERT INTO t3 (c) VALUES('this is a test'); + INSERT INTO t3 (c) VALUES('that was a test'); + INSERT INTO t3 (c) VALUES('this is fun'); + DELETE FROM t3 WHERE c = 'that was a test'; +} + +# Test that the table-named column still works. +do_test fts3b-3.1 { + execsql { + SELECT snippet(t3) FROM t3 WHERE t3 MATCH 'test'; + } +} {{this is a test}} + +# Test that the column doesn't appear when selecting all columns. +do_test fts3b-3.2 { + execsql { + SELECT * FROM t3 WHERE rowid = 1; + } +} {{this is a test}} + +# Test that the column doesn't conflict with inserts that don't name +# columns. +do_test fts3b-3.3 { + execsql { + INSERT INTO t3 VALUES ('another test'); + } +} {} + +# fts3 adds a new implicit column, docid, which acts as an alias for +# rowid. + +db eval { + CREATE VIRTUAL TABLE t4 USING fts3(c); + INSERT INTO t4 (c) VALUES('this is a test'); + INSERT INTO t4 (c) VALUES('that was a test'); + INSERT INTO t4 (c) VALUES('this is fun'); + DELETE FROM t4 WHERE c = 'that was a test'; +} + +# Test that docid is present and identical to rowid. +do_test fts3b-4.1 { + execsql { + SELECT rowid FROM t4 WHERE rowid <> docid; + } +} {} + +# Test that docid is hidden. +do_test fts3b-4.2 { + execsql { + SELECT * FROM t4 WHERE rowid = 1; + } +} {{this is a test}} + +# Test that docid can be selected. +do_test fts3b-4.3 { + execsql { + SELECT docid, * FROM t4 WHERE rowid = 1; + } +} {1 {this is a test}} + +# Test that docid can be used in WHERE. +do_test fts3b-4.4 { + execsql { + SELECT docid, * FROM t4 WHERE docid = 1; + } +} {1 {this is a test}} + +# Test that the column doesn't conflict with inserts that don't name +# columns. [Yes, this is the same as fts3b-3.3, here just in case the +# goals of that test change.] +do_test fts3b-4.5 { + execsql { + INSERT INTO t4 VALUES ('another test'); + } +} {} + +# Test that the docid can be forced on insert. +do_test fts3b-4.6 { + execsql { + INSERT INTO t4 (docid, c) VALUES (10, 'yet another test'); + SELECT * FROM t4 WHERE docid = 10; + } +} {{yet another test}} + +# Test that rowid can also be forced. +do_test fts3b-4.7 { + execsql { + INSERT INTO t4 (docid, c) VALUES (12, 'still testing'); + SELECT * FROM t4 WHERE docid = 12; + } +} {{still testing}} + +# If an insert tries to set both docid and rowid, require an error. +do_test fts3b-4.8 { + catchsql { + INSERT INTO t4 (rowid, docid, c) VALUES (14, 15, 'bad test'); + SELECT * FROM t4 WHERE docid = 14; + } +} {1 {SQL logic error}} + +do_test fts3b-4.9 { + execsql { SELECT docid FROM t4 WHERE t4 MATCH 'testing' } +} {12} +do_test fts3b-4.10 { + execsql { + UPDATE t4 SET docid = 14 WHERE docid = 12; + SELECT docid FROM t4 WHERE t4 MATCH 'testing'; + } +} {14} +do_test fts3b-4.11 { + execsql { SELECT * FROM t4 WHERE rowid = 14; } +} {{still testing}} +do_test fts3b-4.12 { + execsql { SELECT * FROM t4 WHERE rowid = 12; } +} {} +do_test fts3b-4.13 { + execsql { SELECT docid FROM t4 WHERE t4 MATCH 'still'; } +} {14} + +finish_test diff --git a/test/fts3c.test b/test/fts3c.test new file mode 100644 index 0000000..6b63264 --- /dev/null +++ b/test/fts3c.test @@ -0,0 +1,255 @@ +# 2008 June 26 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file exercises some new testing functions in the FTS3 module, +# and then uses them to do some basic tests that FTS3 is internally +# working as expected. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/fts3_common.tcl + +# If SQLITE_ENABLE_FTS3 is not defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +#************************************************************************* +# Utility function to check for the expected terms in the segment +# level/index. _all version does same but for entire index. +proc check_terms {test level index terms} { + set where "level = $level AND idx = $index" + do_test $test.terms [list fts3_terms t1 $where] $terms +} +proc check_terms_all {test terms} { + do_test $test.terms [list fts3_terms t1 1] $terms +} + +# Utility function to check for the expected doclist for the term in +# segment level/index. _all version does same for entire index. +proc check_doclist {test level index term doclist} { + set where "level = $level AND idx = $index" + do_test $test [list fts3_doclist t1 $term $where] $doclist +} +proc check_doclist_all {test term doclist} { + do_test $test [list fts3_doclist t1 $term 1] $doclist +} + +#************************************************************************* +# Test the segments resulting from straight-forward inserts. +db eval { + DROP TABLE IF EXISTS t1; + CREATE VIRTUAL TABLE t1 USING fts3(c); + INSERT INTO t1 (docid, c) VALUES (1, 'This is a test'); + INSERT INTO t1 (docid, c) VALUES (2, 'That was a test'); + INSERT INTO t1 (docid, c) VALUES (3, 'This is a test'); +} + +# Check for expected segments and expected matches. +do_test fts3c-1.0.segments { + execsql { + SELECT level, idx FROM t1_segdir ORDER BY level, idx; + } +} {0 0 0 1 0 2} +do_test fts3c-1.0.matches { + execsql { + SELECT OFFSETS(t1) FROM t1 + WHERE t1 MATCH 'this OR that OR was OR a OR is OR test' ORDER BY docid; + } +} [list {0 0 0 4 0 4 5 2 0 3 8 1 0 5 10 4} \ + {0 1 0 4 0 2 5 3 0 3 9 1 0 5 11 4} \ + {0 0 0 4 0 4 5 2 0 3 8 1 0 5 10 4}] + +# Check the specifics of the segments constructed. +# Logical view of entire index. +check_terms_all fts3c-1.0.1 {a is test that this was} +check_doclist_all fts3c-1.0.1.1 a {[1 0[2]] [2 0[2]] [3 0[2]]} +check_doclist_all fts3c-1.0.1.2 is {[1 0[1]] [3 0[1]]} +check_doclist_all fts3c-1.0.1.3 test {[1 0[3]] [2 0[3]] [3 0[3]]} +check_doclist_all fts3c-1.0.1.4 that {[2 0[0]]} +check_doclist_all fts3c-1.0.1.5 this {[1 0[0]] [3 0[0]]} +check_doclist_all fts3c-1.0.1.6 was {[2 0[1]]} + +# Segment 0,0 +check_terms fts3c-1.0.2 0 0 {a is test this} +check_doclist fts3c-1.0.2.1 0 0 a {[1 0[2]]} +check_doclist fts3c-1.0.2.2 0 0 is {[1 0[1]]} +check_doclist fts3c-1.0.2.3 0 0 test {[1 0[3]]} +check_doclist fts3c-1.0.2.4 0 0 this {[1 0[0]]} + +# Segment 0,1 +check_terms fts3c-1.0.3 0 1 {a test that was} +check_doclist fts3c-1.0.3.1 0 1 a {[2 0[2]]} +check_doclist fts3c-1.0.3.2 0 1 test {[2 0[3]]} +check_doclist fts3c-1.0.3.3 0 1 that {[2 0[0]]} +check_doclist fts3c-1.0.3.4 0 1 was {[2 0[1]]} + +# Segment 0,2 +check_terms fts3c-1.0.4 0 2 {a is test this} +check_doclist fts3c-1.0.4.1 0 2 a {[3 0[2]]} +check_doclist fts3c-1.0.4.2 0 2 is {[3 0[1]]} +check_doclist fts3c-1.0.4.3 0 2 test {[3 0[3]]} +check_doclist fts3c-1.0.4.4 0 2 this {[3 0[0]]} + +#************************************************************************* +# Test the segments resulting from inserts followed by a delete. +db eval { + DROP TABLE IF EXISTS t1; + CREATE VIRTUAL TABLE t1 USING fts3(c); + INSERT INTO t1 (docid, c) VALUES (1, 'This is a test'); + INSERT INTO t1 (docid, c) VALUES (2, 'That was a test'); + INSERT INTO t1 (docid, c) VALUES (3, 'This is a test'); + DELETE FROM t1 WHERE docid = 1; +} + +do_test fts3c-1.1.segments { + execsql { + SELECT level, idx FROM t1_segdir ORDER BY level, idx; + } +} {0 0 0 1 0 2 0 3} +do_test fts3c-1.1.matches { + execsql { + SELECT OFFSETS(t1) FROM t1 + WHERE t1 MATCH 'this OR that OR was OR a OR is OR test' ORDER BY docid; + } +} {{0 1 0 4 0 2 5 3 0 3 9 1 0 5 11 4} {0 0 0 4 0 4 5 2 0 3 8 1 0 5 10 4}} + +check_terms_all fts3c-1.1.1 {a is test that this was} +check_doclist_all fts3c-1.1.1.1 a {[2 0[2]] [3 0[2]]} +check_doclist_all fts3c-1.1.1.2 is {[3 0[1]]} +check_doclist_all fts3c-1.1.1.3 test {[2 0[3]] [3 0[3]]} +check_doclist_all fts3c-1.1.1.4 that {[2 0[0]]} +check_doclist_all fts3c-1.1.1.5 this {[3 0[0]]} +check_doclist_all fts3c-1.1.1.6 was {[2 0[1]]} + +check_terms fts3c-1.1.2 0 0 {a is test this} +check_doclist fts3c-1.1.2.1 0 0 a {[1 0[2]]} +check_doclist fts3c-1.1.2.2 0 0 is {[1 0[1]]} +check_doclist fts3c-1.1.2.3 0 0 test {[1 0[3]]} +check_doclist fts3c-1.1.2.4 0 0 this {[1 0[0]]} + +check_terms fts3c-1.1.3 0 1 {a test that was} +check_doclist fts3c-1.1.3.1 0 1 a {[2 0[2]]} +check_doclist fts3c-1.1.3.2 0 1 test {[2 0[3]]} +check_doclist fts3c-1.1.3.3 0 1 that {[2 0[0]]} +check_doclist fts3c-1.1.3.4 0 1 was {[2 0[1]]} + +check_terms fts3c-1.1.4 0 2 {a is test this} +check_doclist fts3c-1.1.4.1 0 2 a {[3 0[2]]} +check_doclist fts3c-1.1.4.2 0 2 is {[3 0[1]]} +check_doclist fts3c-1.1.4.3 0 2 test {[3 0[3]]} +check_doclist fts3c-1.1.4.4 0 2 this {[3 0[0]]} + +check_terms fts3c-1.1.5 0 3 {a is test this} +check_doclist fts3c-1.1.5.1 0 3 a {[1]} +check_doclist fts3c-1.1.5.2 0 3 is {[1]} +check_doclist fts3c-1.1.5.3 0 3 test {[1]} +check_doclist fts3c-1.1.5.4 0 3 this {[1]} + +#************************************************************************* +# Test results when all references to certain tokens are deleted. +db eval { + DROP TABLE IF EXISTS t1; + CREATE VIRTUAL TABLE t1 USING fts3(c); + INSERT INTO t1 (docid, c) VALUES (1, 'This is a test'); + INSERT INTO t1 (docid, c) VALUES (2, 'That was a test'); + INSERT INTO t1 (docid, c) VALUES (3, 'This is a test'); + DELETE FROM t1 WHERE docid IN (1,3); +} + +# Still 4 segments because 0,3 will contain deletes for docid 1 and 3. +do_test fts3c-1.2.segments { + execsql { + SELECT level, idx FROM t1_segdir ORDER BY level, idx; + } +} {0 0 0 1 0 2 0 3} +do_test fts3c-1.2.matches { + execsql { + SELECT OFFSETS(t1) FROM t1 + WHERE t1 MATCH 'this OR that OR was OR a OR is OR test' ORDER BY docid; + } +} {{0 1 0 4 0 2 5 3 0 3 9 1 0 5 11 4}} + +check_terms_all fts3c-1.2.1 {a is test that this was} +check_doclist_all fts3c-1.2.1.1 a {[2 0[2]]} +check_doclist_all fts3c-1.2.1.2 is {} +check_doclist_all fts3c-1.2.1.3 test {[2 0[3]]} +check_doclist_all fts3c-1.2.1.4 that {[2 0[0]]} +check_doclist_all fts3c-1.2.1.5 this {} +check_doclist_all fts3c-1.2.1.6 was {[2 0[1]]} + +check_terms fts3c-1.2.2 0 0 {a is test this} +check_doclist fts3c-1.2.2.1 0 0 a {[1 0[2]]} +check_doclist fts3c-1.2.2.2 0 0 is {[1 0[1]]} +check_doclist fts3c-1.2.2.3 0 0 test {[1 0[3]]} +check_doclist fts3c-1.2.2.4 0 0 this {[1 0[0]]} + +check_terms fts3c-1.2.3 0 1 {a test that was} +check_doclist fts3c-1.2.3.1 0 1 a {[2 0[2]]} +check_doclist fts3c-1.2.3.2 0 1 test {[2 0[3]]} +check_doclist fts3c-1.2.3.3 0 1 that {[2 0[0]]} +check_doclist fts3c-1.2.3.4 0 1 was {[2 0[1]]} + +check_terms fts3c-1.2.4 0 2 {a is test this} +check_doclist fts3c-1.2.4.1 0 2 a {[3 0[2]]} +check_doclist fts3c-1.2.4.2 0 2 is {[3 0[1]]} +check_doclist fts3c-1.2.4.3 0 2 test {[3 0[3]]} +check_doclist fts3c-1.2.4.4 0 2 this {[3 0[0]]} + +check_terms fts3c-1.2.5 0 3 {a is test this} +check_doclist fts3c-1.2.5.1 0 3 a {[1] [3]} +check_doclist fts3c-1.2.5.2 0 3 is {[1] [3]} +check_doclist fts3c-1.2.5.3 0 3 test {[1] [3]} +check_doclist fts3c-1.2.5.4 0 3 this {[1] [3]} + +#************************************************************************* +# Test results when everything is optimized manually. +db eval { + DROP TABLE IF EXISTS t1; + CREATE VIRTUAL TABLE t1 USING fts3(c); + INSERT INTO t1 (docid, c) VALUES (1, 'This is a test'); + INSERT INTO t1 (docid, c) VALUES (2, 'That was a test'); + INSERT INTO t1 (docid, c) VALUES (3, 'This is a test'); + DELETE FROM t1 WHERE docid IN (1,3); + DROP TABLE IF EXISTS t1old; + ALTER TABLE t1 RENAME TO t1old; + CREATE VIRTUAL TABLE t1 USING fts3(c); + INSERT INTO t1 (docid, c) SELECT docid, c FROM t1old; + DROP TABLE t1old; +} + +# Should be a single optimal segment with the same logical results. +do_test fts3c-1.3.segments { + execsql { + SELECT level, idx FROM t1_segdir ORDER BY level, idx; + } +} {0 0} +do_test fts3c-1.3.matches { + execsql { + SELECT OFFSETS(t1) FROM t1 + WHERE t1 MATCH 'this OR that OR was OR a OR is OR test' ORDER BY docid; + } +} {{0 1 0 4 0 2 5 3 0 3 9 1 0 5 11 4}} + +check_terms_all fts3c-1.3.1 {a test that was} +check_doclist_all fts3c-1.3.1.1 a {[2 0[2]]} +check_doclist_all fts3c-1.3.1.2 test {[2 0[3]]} +check_doclist_all fts3c-1.3.1.3 that {[2 0[0]]} +check_doclist_all fts3c-1.3.1.4 was {[2 0[1]]} + +check_terms fts3c-1.3.2 0 0 {a test that was} +check_doclist fts3c-1.3.2.1 0 0 a {[2 0[2]]} +check_doclist fts3c-1.3.2.2 0 0 test {[2 0[3]]} +check_doclist fts3c-1.3.2.3 0 0 that {[2 0[0]]} +check_doclist fts3c-1.3.2.4 0 0 was {[2 0[1]]} + +finish_test diff --git a/test/fts3comp1.test b/test/fts3comp1.test new file mode 100644 index 0000000..9f13aaa --- /dev/null +++ b/test/fts3comp1.test @@ -0,0 +1,115 @@ +# 2011 January 27 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS3 module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +ifcapable !fts3 { finish_test ; return } +set ::testprefix fts3comp1 + +# Create a pretend compression system. +# +# Each time the [zip] function is called, an entry is added to the ::strings +# array mapping from an integer key to the string argument to zip. The key +# is returned. Later on, when the key is passed to [unzip], the original +# string is retrieved from the ::strings array and returned. +# +set next_x 0 +proc zip {x} { + incr ::next_x + set ::strings($::next_x) $x + return $::next_x +} +proc unzip {x} { + return $::strings($x) +} + +foreach {tn zip unzip} { + 1 zip unzip + 2 {z.i.p!!} {un "zip"} +} { + + set next_x 0 + catch {db close} + forcedelete test.db + sqlite3 db test.db + db func $zip zip + db func $unzip unzip + + # Create a table that uses zip/unzip. Check that content inserted into + # the table can be read back (using a full-scan query). Check that the + # underlying %_content table contains the compressed (integer) values. + # + do_execsql_test 1.$tn.0 " + CREATE VIRTUAL TABLE t1 USING fts4( + a, b, + compress='$zip', uncompress='$unzip' + ); + " + do_execsql_test 1.$tn.1 { + INSERT INTO t1 VALUES('one two three', 'two four six'); + SELECT a, b FROM t1; + } {{one two three} {two four six}} + do_execsql_test 1.$tn.2 { + SELECT c0a, c1b FROM t1_content; + } {1 2} + + # Insert another row and check that it can be read back. Also that the + # %_content table still contains all compressed content. This time, try + # full-text index and by-docid queries too. + # + do_execsql_test 1.$tn.3 { + INSERT INTO t1 VALUES('three six nine', 'four eight twelve'); + SELECT a, b FROM t1; + } {{one two three} {two four six} {three six nine} {four eight twelve}} + do_execsql_test 1.$tn.4 { + SELECT c0a, c1b FROM t1_content; + } {1 2 3 4} + + do_execsql_test 1.$tn.5 { + SELECT a, b FROM t1 WHERE docid = 2 + } {{three six nine} {four eight twelve}} + do_execsql_test 1.$tn.6 { + SELECT a, b FROM t1 WHERE t1 MATCH 'two' + } {{one two three} {two four six}} + + # Delete a row and check that the full-text index is correctly updated. + # Inspect the full-text index using an fts4aux table. + # + do_execsql_test 1.$tn.7 { + CREATE VIRTUAL TABLE terms USING fts4aux(t1); + SELECT term, documents, occurrences FROM terms WHERE col = '*'; + } { + eight 1 1 four 2 2 nine 1 1 one 1 1 + six 2 2 three 2 2 twelve 1 1 two 1 2 + } + do_execsql_test 1.$tn.8 { + DELETE FROM t1 WHERE docid = 1; + SELECT term, documents, occurrences FROM terms WHERE col = '*'; + } { + eight 1 1 four 1 1 nine 1 1 + six 1 1 three 1 1 twelve 1 1 + } + do_execsql_test 1.$tn.9 { SELECT c0a, c1b FROM t1_content } {3 4} +} + +# Test that is an error to specify just one of compress and uncompress. +# +do_catchsql_test 2.1 { + CREATE VIRTUAL TABLE t2 USING fts4(x, compress=zip) +} {1 {missing uncompress parameter in fts4 constructor}} +do_catchsql_test 2.2 { + CREATE VIRTUAL TABLE t2 USING fts4(x, uncompress=unzip) +} {1 {missing compress parameter in fts4 constructor}} + +finish_test diff --git a/test/fts3conf.test b/test/fts3conf.test new file mode 100644 index 0000000..cd48290 --- /dev/null +++ b/test/fts3conf.test @@ -0,0 +1,256 @@ +# 2011 April 25 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS3 module. + + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts3conf + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + + +proc fts3_integrity {tn db tbl} { + + if {[sqlite3_get_autocommit $db]==0} { + error "fts3_integrity does not work with an open transaction" + } + + set sql [db one {SELECT sql FROM sqlite_master WHERE name = $tbl}] + regexp -nocase {[^(]* using (.*)} $sql -> tail + set cols [list] + $db eval "PRAGMA table_info($tbl)" { + lappend cols $name + } + set cols [join [concat docid $cols] ,] + + $db eval [subst { + CREATE VIRTUAL TABLE fts3check USING fts4term($tbl); + CREATE VIRTUAL TABLE temp.fts3check2 USING $tail; + INSERT INTO temp.fts3check2($cols) SELECT docid, * FROM $tbl; + CREATE VIRTUAL TABLE temp.fts3check3 USING fts4term(fts3check2); + }] + + set m1 [$db one {SELECT md5sum(term, docid, col, pos) FROM fts3check}] + set m2 [$db one {SELECT md5sum(term, docid, col, pos) FROM fts3check3}] + + $db eval { + DROP TABLE fts3check; + DROP TABLE temp.fts3check2; + DROP TABLE temp.fts3check3; + } + + uplevel [list do_test $tn [list set {} $m1] $m2] +} + +do_execsql_test 1.0.1 { + CREATE VIRTUAL TABLE t1 USING fts3(x); + INSERT INTO t1(rowid, x) VALUES(1, 'a b c d'); + INSERT INTO t1(rowid, x) VALUES(2, 'e f g h'); + + CREATE TABLE source(a, b); + INSERT INTO source VALUES(4, 'z'); + INSERT INTO source VALUES(2, 'y'); +} +db_save_and_close + +set T1 "INTO t1(rowid, x) VALUES(1, 'x')" +set T2 "INTO t1(rowid, x) SELECT * FROM source" + +set T3 "t1 SET docid = 2 WHERE docid = 1" +set T4 "t1 SET docid = CASE WHEN docid = 1 THEN 4 ELSE 3 END WHERE docid <=2" + +foreach {tn sql uses constraint data} [subst { + 1 "INSERT OR ROLLBACK $T1" 0 1 {{a b c d} {e f g h}} + 2 "INSERT OR ABORT $T1" 0 1 {{a b c d} {e f g h} {i j k l}} + 3 "INSERT OR FAIL $T1" 0 1 {{a b c d} {e f g h} {i j k l}} + 4 "INSERT OR IGNORE $T1" 0 0 {{a b c d} {e f g h} {i j k l}} + 5 "INSERT OR REPLACE $T1" 0 0 {x {e f g h} {i j k l}} + + 6 "INSERT OR ROLLBACK $T2" 1 1 {{a b c d} {e f g h}} + 7 "INSERT OR ABORT $T2" 1 1 {{a b c d} {e f g h} {i j k l}} + 8 "INSERT OR FAIL $T2" 1 1 {{a b c d} {e f g h} {i j k l} z} + 9 "INSERT OR IGNORE $T2" 1 0 {{a b c d} {e f g h} {i j k l} z} + 10 "INSERT OR REPLACE $T2" 1 0 {{a b c d} y {i j k l} z} + + 11 "UPDATE OR ROLLBACK $T3" 0 1 {{a b c d} {e f g h}} + 12 "UPDATE OR ABORT $T3" 0 1 {{a b c d} {e f g h} {i j k l}} + 13 "UPDATE OR FAIL $T3" 0 1 {{a b c d} {e f g h} {i j k l}} + 14 "UPDATE OR IGNORE $T3" 0 0 {{a b c d} {e f g h} {i j k l}} + 15 "UPDATE OR REPLACE $T3" 0 0 {{a b c d} {i j k l}} + + 16 "UPDATE OR ROLLBACK $T4" 1 1 {{a b c d} {e f g h}} + 17 "UPDATE OR ABORT $T4" 1 1 {{a b c d} {e f g h} {i j k l}} + 18 "UPDATE OR FAIL $T4" 1 1 {{e f g h} {i j k l} {a b c d}} + 19 "UPDATE OR IGNORE $T4" 1 0 {{e f g h} {i j k l} {a b c d}} + 20 "UPDATE OR REPLACE $T4" 1 0 {{e f g h} {a b c d}} +}] { + db_restore_and_reopen + execsql { + BEGIN; + INSERT INTO t1(rowid, x) VALUES(3, 'i j k l'); + } + set R(0) {0 {}} + set R(1) {1 {constraint failed}} + do_catchsql_test 1.$tn.1 $sql $R($constraint) + do_catchsql_test 1.$tn.2 { SELECT * FROM t1 } [list 0 $data] + catchsql COMMIT + + fts3_integrity 1.$tn.3 db t1 + + do_test 1.$tn.4 [list sql_uses_stmt db $sql] $uses +} + +do_execsql_test 2.1.1 { + DELETE FROM t1; + BEGIN; + INSERT INTO t1 VALUES('a b c'); + SAVEPOINT a; + INSERT INTO t1 VALUES('x y z'); + ROLLBACK TO a; + COMMIT; +} +fts3_integrity 2.1.2 db t1 + +do_catchsql_test 2.2.1 { + DELETE FROM t1; + BEGIN; + INSERT INTO t1(docid, x) VALUES(0, 'a b c'); + INSERT INTO t1(docid, x) VALUES(1, 'a b c'); + REPLACE INTO t1(docid, x) VALUES('zero', 'd e f'); +} {1 {datatype mismatch}} +do_execsql_test 2.2.2 { COMMIT } +do_execsql_test 2.2.3 { SELECT * FROM t1 } {{a b c} {a b c}} +fts3_integrity 2.2.4 db t1 + +if {$tcl_platform(byteOrder)=="littleEndian"} { + do_execsql_test 3.1 { + CREATE VIRTUAL TABLE t3 USING fts4; + REPLACE INTO t3(docid, content) VALUES (1, 'one two'); + SELECT quote(matchinfo(t3, 'na')) FROM t3 WHERE t3 MATCH 'one' + } {X'0100000002000000'} + + do_execsql_test 3.2 { + REPLACE INTO t3(docid, content) VALUES (2, 'one two three four'); + SELECT quote(matchinfo(t3, 'na')) FROM t3 WHERE t3 MATCH 'four' + } {X'0200000003000000'} + + do_execsql_test 3.3 { + REPLACE INTO t3(docid, content) VALUES (1, 'one two three four five six'); + SELECT quote(matchinfo(t3, 'na')) FROM t3 WHERE t3 MATCH 'six' + } {X'0200000005000000'} + + do_execsql_test 3.4 { + UPDATE OR REPLACE t3 SET docid = 2 WHERE docid=1; + SELECT quote(matchinfo(t3, 'na')) FROM t3 WHERE t3 MATCH 'six' + } {X'0100000006000000'} + + do_execsql_test 3.5 { + UPDATE OR REPLACE t3 SET docid = 3 WHERE docid=2; + SELECT quote(matchinfo(t3, 'na')) FROM t3 WHERE t3 MATCH 'six' + } {X'0100000006000000'} + + do_execsql_test 3.6 { + REPLACE INTO t3(docid, content) VALUES (3, 'one two'); + SELECT quote(matchinfo(t3, 'na')) FROM t3 WHERE t3 MATCH 'one' + } {X'0100000002000000'} + + do_execsql_test 3.7 { + REPLACE INTO t3(docid, content) VALUES(NULL,'one two three four'); + REPLACE INTO t3(docid, content) VALUES(NULL,'one two three four five six'); + SELECT docid FROM t3; + } {3 4 5} + + do_execsql_test 3.8 { + UPDATE OR REPLACE t3 SET docid = 5, content='three four' WHERE docid = 4; + SELECT quote(matchinfo(t3, 'na')) FROM t3 WHERE t3 MATCH 'one' + } {X'0200000002000000'} +} + +#------------------------------------------------------------------------- +# Test that the xSavepoint is invoked correctly if the first write +# operation within a transaction is to a virtual table. +# +do_catchsql_test 4.1.1 { + CREATE VIRTUAL TABLE t0 USING fts4; + BEGIN; + INSERT INTO t0(rowid, content) SELECT + 1, 'abc' UNION ALL SELECT + 2, 'def' UNION ALL SELECT + 1, 'ghi'; +} {1 {constraint failed}} +do_execsql_test 4.1.2 { + COMMIT; +} +do_execsql_test 4.1.3 { + SELECT * FROM t0 WHERE t0 MATCH 'abc'; + INSERT INTO t0(t0) VALUES('integrity-check'); + PRAGMA integrity_check; +} {ok} + +do_execsql_test 4.2.1 { + CREATE VIRTUAL TABLE t01 USING fts4; + BEGIN; + SAVEPOINT abc; + INSERT INTO t01 VALUES('a b c'); + ROLLBACK TO abc; + COMMIT; +} +do_execsql_test 4.2.2 { + SELECT * FROM t01 WHERE t01 MATCH 'b'; + INSERT INTO t01(t01) VALUES('integrity-check'); + PRAGMA integrity_check; +} {ok} + +do_execsql_test 4.3.1 { + CREATE VIRTUAL TABLE t02 USING fts4; + INSERT INTO t01 VALUES('1 1 1'); + INSERT INTO t02 VALUES('2 2 2'); + BEGIN; + SAVEPOINT abc; + INSERT INTO t01 VALUES('a b c'); + INSERT INTO t02 VALUES('a b c'); + ROLLBACK TO abc; + COMMIT; +} +do_execsql_test 4.3.2 { + SELECT * FROM t01 WHERE t01 MATCH 'b'; + INSERT INTO t01(t01) VALUES('integrity-check'); +} {} + +do_execsql_test 4.4.1 { + CREATE TABLE A(ID INTEGER PRIMARY KEY, AnotherID INTEGER, Notes TEXT); + CREATE VIRTUAL TABLE AFTS USING FTS4 (Notes); + CREATE TRIGGER A_DeleteTrigger AFTER DELETE ON A FOR EACH ROW BEGIN + DELETE FROM AFTS WHERE rowid=OLD.ID; + END; + CREATE TABLE B(ID INTEGER PRIMARY KEY,Notes TEXT); + CREATE VIRTUAL TABLE BFTS USING FTS3 (Notes); + CREATE TRIGGER B_DeleteTrigger AFTER DELETE ON B FOR EACH ROW BEGIN + DELETE FROM BFTS WHERE rowid=OLD.ID; + END; +} + +do_execsql_test 4.4.2 { + BEGIN TRANSACTION; + DELETE FROM A WHERE AnotherID=1; + DELETE FROM B WHERE ID=1; + COMMIT; +} + + + +finish_test diff --git a/test/fts3corrupt.test b/test/fts3corrupt.test new file mode 100644 index 0000000..69d5030 --- /dev/null +++ b/test/fts3corrupt.test @@ -0,0 +1,234 @@ +# 2010 October 27 +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# Test that the FTS3 extension does not crash when it encounters a +# corrupt data structure on disk. +# + + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is not defined, omit this file. +ifcapable !fts3 { finish_test ; return } + +set ::testprefix fts3corrupt + + +# Test that a doclist with a length field that indicates that the doclist +# extends past the end of the node on which it resides is correctly identified +# as database corruption. +# +sqlite3_db_config db DEFENSIVE 0 +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t1 USING fts3; + INSERT INTO t1 VALUES('hello'); +} {} +do_test fts3corrupt-1.1 { + set blob [db one {SELECT root from t1_segdir}] + set blob [binary format a7ca* $blob 24 [string range $blob 8 end]] + execsql { UPDATE t1_segdir SET root = $blob } +} {} +do_test fts3corrupt-1.2 { + foreach w {a b c d e f g h i j k l m n o} { + execsql { INSERT INTO t1 VALUES($w) } + } +} {} +do_catchsql_test 1.3 { + INSERT INTO t1 VALUES('world'); +} {1 {database disk image is malformed}} +do_test 1.3.1 { sqlite3_extended_errcode db } SQLITE_CORRUPT_VTAB +do_execsql_test 1.4 { + DROP TABLE t1; +} + +# This block of tests checks that corruption is correctly detected if the +# length field of a term on a leaf node indicates that the term extends past +# the end of the node on which it resides. There are two cases: +# +# 1. The first term on the node. +# 2. The second or subsequent term on the node (prefix compressed term). +# +do_execsql_test 2.0 { + CREATE VIRTUAL TABLE t1 USING fts3; + BEGIN; + INSERT INTO t1 VALUES('hello'); + INSERT INTO t1 VALUES('hello'); + INSERT INTO t1 VALUES('hello'); + INSERT INTO t1 VALUES('hello'); + INSERT INTO t1 VALUES('hello'); + COMMIT; +} {} +do_test fts3corrupt-2.1 { + set blob [db one {SELECT root from t1_segdir}] + set blob [binary format a*a* "\x00\x7F" [string range $blob 2 end]] + execsql { UPDATE t1_segdir SET root = $blob } +} {} +do_catchsql_test 2.2 { + SELECT rowid FROM t1 WHERE t1 MATCH 'hello' +} {1 {database disk image is malformed}} +do_test 2.2.1 { sqlite3_extended_errcode db } SQLITE_CORRUPT_VTAB + +do_execsql_test 3.0 { + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING fts3; + BEGIN; + INSERT INTO t1 VALUES('hello'); + INSERT INTO t1 VALUES('world'); + COMMIT; +} {} +do_test fts3corrupt-3.1 { + set blob [db one {SELECT quote(root) from t1_segdir}] + set blob [binary format a11a*a* $blob "\x7F" [string range $blob 12 end]] + execsql { UPDATE t1_segdir SET root = $blob } +} {} +do_catchsql_test 3.2 { + SELECT rowid FROM t1 WHERE t1 MATCH 'world' +} {1 {database disk image is malformed}} +do_test 3.2.1 { sqlite3_extended_errcode db } SQLITE_CORRUPT_VTAB + + +do_execsql_test 4.0 { + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING fts3; + INSERT INTO t1(t1) VALUES('nodesize=24'); +} +do_test fts3corrupt-4.1 { + execsql BEGIN + foreach s { + "amxtvoo adqwroyhz auq aithtir avniqnuynvf axp ahibayfynig agbicpm" + "ajdtebs anteaxr aieynenwmd awpl alo akxcrwow aoxftge aoqvgul" + "amcfvdr auz apu aebelm ahuxyz aqc asyafdb agulvhvqu" + "apepwfyz azkhdvkw aenyelxzbk aslnitbyet aycdsdcpgr aqzzdbc agfi axnypydou" + "aaqrzzcm apcxdxo atumltzj aevvivo aodknoft aqoyytoz alobx apldt" + } { + execsql { INSERT INTO t1 VALUES($s) } + } + execsql COMMIT +} {} + +do_catchsql_test 4.2 { + UPDATE t1_segdir SET root = X'FFFFFFFFFFFFFFFF'; + SELECT rowid FROM t1 WHERE t1 MATCH 'world'; +} {1 {database disk image is malformed}} +do_test 4.2.1 { sqlite3_extended_errcode db } SQLITE_CORRUPT_VTAB + +set blob [binary format cca*cca*cca*cca*cca*cca*cca*cca*cca*cca*a* \ + 22 120 [string repeat a 120] \ + 22 120 [string repeat b 120] \ + 22 120 [string repeat c 120] \ + 22 120 [string repeat d 120] \ + 22 120 [string repeat e 120] \ + 22 120 [string repeat f 120] \ + 22 120 [string repeat g 120] \ + 22 120 [string repeat h 120] \ + 22 120 [string repeat i 120] \ + 22 120 [string repeat j 120] \ + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" +] + +do_catchsql_test 4.3 { + UPDATE t1_segdir SET root = $blob; + SELECT rowid FROM t1 WHERE t1 MATCH 'world'; +} {1 {database disk image is malformed}} +do_test 4.3.1 { sqlite3_extended_errcode db } SQLITE_CORRUPT_VTAB + +# Test a special kind of corruption, where the %_stat table contains +# an invalid entry. At one point this could lead to a division-by-zero +# error in fts4. +# +do_execsql_test 5.0 { + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING fts4; +} +do_test 5.1 { + db func nn nn + execsql BEGIN + execsql { INSERT INTO t1 VALUES('one') } + execsql { INSERT INTO t1 VALUES('two') } + execsql { INSERT INTO t1 VALUES('three') } + execsql { INSERT INTO t1 VALUES('four') } + execsql COMMIT +} {} +do_catchsql_test 5.2 { + UPDATE t1_stat SET value = X'0000'; + SELECT matchinfo(t1, 'nxa') FROM t1 WHERE t1 MATCH 't*'; +} {1 {database disk image is malformed}} +do_test 5.2.1 { sqlite3_extended_errcode db } SQLITE_CORRUPT_VTAB +do_catchsql_test 5.3 { + UPDATE t1_stat SET value = NULL; + SELECT matchinfo(t1, 'nxa') FROM t1 WHERE t1 MATCH 't*'; +} {1 {database disk image is malformed}} +do_test 5.3.1 { sqlite3_extended_errcode db } SQLITE_CORRUPT_VTAB + +# 2019-11-18 https://bugs.chromium.org/p/chromium/issues/detail?id=1025467 +# bug1 +db close +sqlite3 db :memory: +do_catchsql_test 6.10 { + CREATE VIRTUAL TABLE f using fts3(a,b); + CREATE TABLE f_stat(id INTEGER PRIMARY KEY, value BLOB); + INSERT INTO f_segdir VALUES (2000, 0,0,0, '16', ''); + INSERT INTO f_segdir VALUES (1999, 0,0,0, '0 18', + x'000131030102000103323334050101010200'); + INSERT INTO f_segments (blockid) values (16); + INSERT INTO f_segments values (0, x''); + INSERT INTO f_stat VALUES (1,x'cf0f01'); + INSERT INTO f(f) VALUES ('merge=1'); +} {1 {database disk image is malformed}} + +# 2020-03-02 https://bugs.chromium.org/p/chromium/issues/detail?id=1057441 +# The ticket complains of use of an uninitialized value. That part is harmless. +# The only reason to fix this is the failure to detect a subtly corrupt +# inverted index. +# +reset_db +do_catchsql_test 7.10 { + CREATE VIRTUAL TABLE f USING fts3(a,b); + INSERT INTO f_segdir VALUES (0,0,1,0,'0 0',x'01010101020101'); + SELECT matchinfo( f , 'pcx') FROM f WHERE b MATCH x'c533'; +} {1 {database disk image is malformed}} + +reset_db +sqlite3_fts3_may_be_corrupt 1 +do_execsql_test 8.1 { + CREATE VIRTUAL TABLE f USING fts3(a); + INSERT INTO f(f) VALUES('nodesize=24'); + BEGIN; + INSERT INTO f VALUES('abcdefghijklmnopqrstuvwxyz0123456789'); + INSERT INTO f VALUES('abcdefghijklmnopqrstuvwxyz0123456789'); + INSERT INTO f VALUES('abcdefghijklmnopqrstuvwxyz0123456789'); + + INSERT INTO f VALUES('abcdefghijklmnopqrstuvwxyz012345678X'); + INSERT INTO f VALUES('abcdefghijklmnopqrstuvwxyz012345678X'); + INSERT INTO f VALUES('abcdefghijklmnopqrstuvwxyz012345678X'); + COMMIT; + BEGIN; + INSERT INTO f VALUES('abcdefghijklmnopqrstuvwxyz0123456789'); + INSERT INTO f VALUES('abcdefghijklmnopqrstuvwxyz0123456789'); + INSERT INTO f VALUES('abcdefghijklmnopqrstuvwxyz0123456789'); + + INSERT INTO f VALUES('abcdefghijklmnopqrstuvwxyz012345678X'); + INSERT INTO f VALUES('abcdefghijklmnopqrstuvwxyz012345678X'); + INSERT INTO f VALUES('abcdefghijklmnopqrstuvwxyz012345678X'); + COMMIT; + + SELECT count(*) FROM f_segments; +} {4} + +do_execsql_test 8.2 { + UPDATE f_segments SET block = ( + SELECT block FROM f_segments WHERE blockid=1 + ) WHERE blockid=2 +} + +do_catchsql_test 8.3 { + INSERT INTO f(f) VALUES('merge=2,2'); +} {1 {database disk image is malformed}} +sqlite3_fts3_may_be_corrupt 0 + +finish_test diff --git a/test/fts3corrupt2.test b/test/fts3corrupt2.test new file mode 100644 index 0000000..5864353 --- /dev/null +++ b/test/fts3corrupt2.test @@ -0,0 +1,111 @@ +# 2010 October 30 +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# Test that the FTS3 extension does not crash when it encounters a +# corrupt data structure on disk. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is not defined, omit this file. +ifcapable !fts3 { finish_test ; return } + +set ::testprefix fts3corrupt2 +sqlite3_fts3_may_be_corrupt 1 + +set data [list] +lappend data {*}{ + "amxtvoo adqwroyhz auq aithtir avniqnuynvf axp ahibayfynig agbicpm" + "ajdtebs anteaxr aieynenwmd awpl alo akxcrwow aoxftge aoqvgul" + "amcfvdr auz apu aebelm ahuxyz aqc asyafdb agulvhvqu" + "apepwfyz azkhdvkw aenyelxzbk aslnitbyet aycdsdcpgr aqzzdbc agfi axnypydou" + "aaqrzzcm apcxdxo atumltzj aevvivo aodknoft aqoyytoz alobx apldt" + "adjllxlhnmj aiuhvuj adwppceuht atvj azrsam ahkjqdhny audlqxr aotgcd" + "aira azflsceos awj auzbobfkc awmezplr aeh awec ahndxlmv" + "aydwnied alk auoap agihyqeix aymqxzajnl aydwnied aojkarx agbo" + "ahajsmcl anvx amdhjm aoptsj agugzjjm apkevm acnj acjg" + "amwtkw aogttbykvt aubwrfqnbjf ajow agsj aerkqzjdqst anenlvbalkn arfajzzgckx" + "adqqqofkmz amjpavjuhw aqgehgnb awvvxlbtqzn agstqko akmkzehyh atagzey agwja" + "amag ahe autkllywhr avnk atmt akn anvdh aixfrv" + "aqdyerbws avefykly awl azaduojgzo anxfsmw axpt abgbvk ati" + "attyqkwz aiweypiczul afy asitaqbczhh aitxisizpv auhviq aibql ajfqc" + "aylzprtmta aiuemihqrpi awluvgsw ampbuy axlifpzfqr aems aoaxwads apianfn" + "aodrkijelq acdb aaserrdxm aqyasgofqu aevvivo afi apmwu aeoqysl" + "amqnk ankaotm ayfy ajcupeeoc advcbukan aucahlwnyk adbfyo azqjpeant" + "afczpp asqrs ahslvda akhlf aiqgdp atyd aznuglxqbrg awirndrh" + "aqhiajp amxeazb asxuehg akod axvolvsp agcz asmovmohy acmqa" + "avvomv aafms ashuaec arevx audtq alrwqhjvao avgsgpg ajbrctpsel" + "atxoirr ayopboobqdu ajunntua arh aernimxid aipljda aglo aefk" + "aonxf acmnnkna abgviaswe aulvcbv axp apemgakpzo aibql acioaid" + "axo alrwqhjvao ayqounftdzl azmoakdyh apajze ajk artvy apxiamy" + "ayjafsraz addjj agsj asejtziqws acatvhegu aoxdjqblsvv aekdmmbs aaobe" + "abjjvzubkwt alczv ati awz auyxgcxeb aymjoym anqoukprtyt atwfhpmbooh" + "ajfqz aethlgir aclcx aowlyvetby aproqm afjlqtkv anebfy akzrcpfrrvw" + "aoledfotm aiwlfm aeejlaej anz abgbvk aktfn aayoh anpywgdvgz" + "acvmldguld asdvz aqb aeomsyzyu aggylhprbdz asrfkwz auipybpsn agsnszzfb" +} + +sqlite3_db_config db DEFENSIVE 0 +do_test fts3corrupt2-1.0 { + execsql BEGIN + execsql { CREATE VIRTUAL TABLE t2 USING FTS3(a, b); } + execsql { INSERT INTO t2(t2) VALUES('nodesize=32') } + foreach d $data { + execsql { INSERT INTO t2 VALUES($d, $d) } + } + execsql COMMIT + execsql { SELECT count(*) FROM t2_segments } +} {163} + +proc set_byte {blob byte val} { + binary format a*ca* \ + [string range $blob 0 [expr $byte-1]] \ + $val \ + [string range $blob [expr $byte+1] end] \ +} + +set tn 0 +set c 256 +foreach {rowid sz blob} [ + db eval {SELECT rowid, length(block), block FROM t2_segments} +] { + incr tn + set c [expr (($c+255)%256)] + for {set i 0} {$i < $sz} {incr i} { + set b2 [set_byte $blob $i $c] + execsql { UPDATE t2_segments SET block = $b2 WHERE rowid = $rowid } + do_test fts3corrupt2-1.$tn.$i { + catchsql { SELECT * FROM t2 WHERE t2 MATCH 'a*' } + set {} {} + } {} + } + execsql { UPDATE t2_segments SET block = $blob WHERE rowid = $rowid } +} + +foreach c {50 100 150 200 250} { + foreach {rowid sz blob} [ + db eval {SELECT rowid, length(root), root FROM t2_segdir} + ] { + incr tn + for {set i 0} {$i < $sz} {incr i} { + set b2 [set_byte $blob $i $c] + execsql { UPDATE t2_segdir SET root = $b2 WHERE rowid = $rowid } + do_test fts3corrupt2-2.$c.$tn.$i { + catchsql { SELECT * FROM t2 WHERE t2 MATCH 'a*' } + set {} {} + } {} + } + execsql { UPDATE t2_segdir SET root = $blob WHERE rowid = $rowid } + } +} + + + + + +finish_test diff --git a/test/fts3corrupt3.test b/test/fts3corrupt3.test new file mode 100644 index 0000000..eae13f2 --- /dev/null +++ b/test/fts3corrupt3.test @@ -0,0 +1,66 @@ +# 2010 October 27 +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# Test that the FTS3 extension does not crash when it encounters a +# corrupt data structure on disk. +# + + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is not defined, omit this file. +ifcapable !fts3 { finish_test ; return } + +set ::testprefix fts3corrupt3 + +#------------------------------------------------------------------------- +# Test that fts3 does not choke on an oversized varint. +# +do_execsql_test 1.0 { + PRAGMA page_size = 512; + CREATE VIRTUAL TABLE t1 USING fts3; + BEGIN; + INSERT INTO t1 VALUES('one'); + INSERT INTO t1 VALUES('one'); + INSERT INTO t1 VALUES('one'); + COMMIT; +} +do_execsql_test 1.1 { + SELECT quote(root) from t1_segdir; +} {X'00036F6E6509010200010200010200'} +sqlite3_db_config db DEFENSIVE 0 +do_execsql_test 1.2 { + UPDATE t1_segdir SET root = X'00036F6E650EFFFFFFFFFFFFFFFFFFFFFFFF0200'; +} +do_catchsql_test 1.3 { + SELECT rowid FROM t1 WHERE t1 MATCH 'one' +} {0 -1} + +#------------------------------------------------------------------------- +# Interior node with the prefix or suffix count of an entry set to a +# negative value. +# +set doc1 [string repeat "x " 600] +set doc2 [string repeat "y " 600] +set doc3 [string repeat "z " 600] + +do_execsql_test 2.0 { + CREATE VIRTUAL TABLE t2 USING fts3; + BEGIN; + INSERT INTO t2 VALUES($doc1); + INSERT INTO t2 VALUES($doc2); + INSERT INTO t2 VALUES($doc3); + COMMIT; +} +do_execsql_test 2.1 { + SELECT quote(root) from t2_segdir; +} {X'0101017900017A'} + + + +finish_test diff --git a/test/fts3corrupt4.test b/test/fts3corrupt4.test new file mode 100644 index 0000000..433a486 --- /dev/null +++ b/test/fts3corrupt4.test @@ -0,0 +1,7666 @@ +# 2006 September 9 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS3 module. +# +# $Id: fts3aa.test,v 1.1 2007/08/20 17:38:42 shess Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/fts3_common.tcl +set testprefix fts3corrupt4 + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +sqlite3_fts3_may_be_corrupt 1 +database_may_be_corrupt +extra_schema_checks 0 + +do_execsql_test 1.0 { + BEGIN; + CREATE VIRTUAL TABLE ft USING fts3; + INSERT INTO ft VALUES('aback'); + INSERT INTO ft VALUES('abaft'); + INSERT INTO ft VALUES('abandon'); + COMMIT; +} + +proc blob {a} { binary decode hex $a } +db func blob blob + +do_execsql_test 1.1 { + SELECT quote(root) FROM ft_segdir; +} {X'0005616261636B03010200030266740302020003046E646F6E03030200'} + +sqlite3_db_config db DEFENSIVE 0 +do_execsql_test 1.2 { + UPDATE ft_segdir SET root = blob( + '0005616261636B03010200 FFFFFFFF0702 66740302020003046E646F6E03030200' + ); +} + +do_catchsql_test 1.3 { + SELECT * FROM ft WHERE ft MATCH 'abandon'; +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 2.0.0 { + CREATE VIRTUAL TABLE ft USING fts3; + INSERT INTO ft(ft) VALUES('nodesize=32'); +} +do_test 2.0.1 { + for {set i 0} {$i < 12} {incr i} { + execsql { + BEGIN; + INSERT INTO ft VALUES('abc' || $i); + INSERT INTO ft VALUES('abc' || $i || 'x' ); + INSERT INTO ft VALUES('abc' || $i || 'xx' ); + COMMIT + } + } + execsql { + SELECT count(*) FROM ft_segdir; + SELECT count(*) FROM ft_segments; + } +} {12 0} + +do_execsql_test 2.1 { + INSERT INTO ft(ft) VALUES('merge=1,4'); + SELECT count(*) FROM ft_segdir; + SELECT count(*) FROM ft_segments; +} {12 3} + +do_execsql_test 2.2 { + SELECT quote(block) FROM ft_segments WHERE blockid=2 +} {X'00056162633130031F0200'} + +db func blob blob +sqlite3_db_config db DEFENSIVE 0 +do_execsql_test 2.3.1 { + UPDATE ft_segments SET block = + blob('00056162633130031F0200 FFFFFFFF07FF55 66740302020003046E646F6E03030200') + WHERE blockid=2; +} {} +do_catchsql_test 2.3.2 { + INSERT INTO ft(ft) VALUES('merge=1,4'); +} {1 {database disk image is malformed}} + +do_execsql_test 2.4.1 { + UPDATE ft_segments SET block = + blob('00056162633130031F0200 02FFFFFFFF07 66740302020003046E646F6E03030200') + WHERE blockid=2; +} {} +do_catchsql_test 2.4.2 { + INSERT INTO ft(ft) VALUES('merge=1,4'); +} {1 {database disk image is malformed}} + +do_execsql_test 2.5.1 { + UPDATE ft_segments SET block = + blob('00056162633130031F0200 0202 6674 FFFFFF070302020003046E646F6E030200') + WHERE blockid=2; +} {} +do_catchsql_test 2.5.2 { + INSERT INTO ft(ft) VALUES('merge=1,4'); +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 3.0.0 { + CREATE VIRTUAL TABLE ft USING fts3; + INSERT INTO ft(ft) VALUES('nodesize=32'); +} +do_test 3.0.1 { + execsql BEGIN + for {set i 0} {$i < 20} {incr i} { + execsql { INSERT INTO ft VALUES('abc' || $i) } + } + execsql { + COMMIT; + SELECT count(*) FROM ft_segdir; + SELECT count(*) FROM ft_segments; + } +} {1 5} + +do_execsql_test 3.1 { + SELECT quote(root) FROM ft_segdir +} {X'0101056162633132040136030132030136'} + +db func blob blob +sqlite3_db_config db DEFENSIVE 0 +do_execsql_test 3.2 { + UPDATE ft_segdir + SET root = blob('0101056162633132FFFFFFFF070236030132030136'); +} + +do_catchsql_test 3.1 { + SELECT * FROM ft WHERE ft MATCH 'abc20' +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 4.0 { + CREATE VIRTUAL TABLE t1 USING fts3(); + INSERT INTO t1 VALUES('one two three'); + UPDATE t1_segdir SET start_block = 1; +} + +do_catchsql_test 4.1 { + SELECT * FROM t1 WHERE t1 MATCH 'one'; +} {1 {database disk image is malformed}} +do_catchsql_test 4.2 { + SELECT * FROM t1 WHERE t1 MATCH 'two'; +} {1 {database disk image is malformed}} +do_catchsql_test 4.3 { + SELECT * FROM t1 WHERE t1 MATCH 'three'; +} {1 {database disk image is malformed}} +do_execsql_test 4.4 { + INSERT INTO t1(t1) VALUES('optimize'); +} + +#------------------------------------------------------------------------- +reset_db +do_test 5.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 24576 pagesize 4096 filename c15.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 04 .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ +| 96: 00 00 00 00 0d 0e f9 00 06 0d ec 00 0f cd 0f 69 ...............i +| 112: 0f 01 0e 10 0e c6 0d ec 00 00 00 00 00 00 00 00 ................ +| 3552: 00 00 00 00 00 00 00 00 00 00 00 00 22 06 06 17 ................ +| 3568: 11 11 01 31 74 61 62 6c 65 74 32 74 32 06 43 52 ...1tablet2t2.CR +| 3584: 45 41 54 45 20 54 41 42 4c 45 20 74 32 28 78 29 EATE TABLE t2(x) +| 3600: 81 33 04 07 17 1f 1f 01 82 35 74 61 62 6c 65 74 .3.......5tablet +| 3616: 31 5f 73 65 67 64 69 72 74 31 5f 73 65 67 64 69 1_segdirt1_segdi +| 3632: 72 04 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 r.CREATE TABLE ' +| 3648: 74 31 5f 73 65 67 64 69 72 27 28 6c 65 76 65 6c t1_segdir'(level +| 3664: 20 49 4e 54 45 47 45 52 2c 69 64 78 20 49 4e 54 INTEGER,idx INT +| 3680: 45 47 45 52 2c 73 74 61 72 74 5f 62 6c 6f 63 6b EGER,start_block +| 3696: 20 49 4e 54 45 47 45 52 2c 6c 65 61 76 65 73 5f INTEGER,leaves_ +| 3712: 65 6e 64 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 end_block INTEGE +| 3728: 52 2c 65 6e 64 5f 62 6c 6f 63 6b 20 49 4e 54 45 R,end_block INTE +| 3744: 47 45 52 2c 72 6f 6f 74 20 42 4c 4f 42 2c 50 52 GER,root BLOB,PR +| 3760: 49 4d 41 52 59 20 4b 45 59 28 6c 65 76 65 6c 2c IMARY KEY(level, +| 3776: 20 69 64 78 29 29 31 05 06 17 45 1f 01 00 69 6e idx))1...E...in +| 3792: 64 65 78 73 71 6c 69 74 65 5f 61 75 74 6f 69 6e dexsqlite_autoin +| 3808: 64 65 79 5f 74 31 5f 73 65 67 64 69 72 5f 31 74 dey_t1_segdir_1t +| 3824: 31 5f 73 65 67 64 69 72 05 00 00 00 08 00 00 00 1_segdir........ +| 3840: 00 66 03 07 17 23 23 01 81 13 74 61 62 6c 65 74 .f...##...tablet +| 3856: 31 5f 73 65 67 6d 65 6e 74 73 74 31 5f 73 65 67 1_segmentst1_seg +| 3872: 6d 65 6e 74 73 03 43 52 45 41 54 45 20 54 41 42 ments.CREATE TAB +| 3888: 4c 45 20 27 74 31 5f 73 65 67 6d 65 6e 74 73 27 LE 't1_segments' +| 3904: 28 62 6c 6f 63 6b 69 64 20 49 4e 54 45 47 45 52 (blockid INTEGER +| 3920: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 62 6c PRIMARY KEY, bl +| 3936: 6f 63 6b 20 42 4c 4f 42 29 62 02 07 17 21 21 01 ock BLOB)b...!!. +| 3952: 81 0f 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65 6e ..tablet1_conten +| 3968: 74 74 31 5f 63 6f 6e 74 65 6e 74 02 43 52 45 41 tt1_content.CREA +| 3984: 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f 6e TE TABLE 't1_con +| 4000: 74 65 6e 74 27 28 64 6f 63 69 64 20 49 4e 54 45 tent'(docid INTE +| 4016: 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c GER PRIMARY KEY, +| 4032: 20 27 63 30 63 6f 6e 74 65 6e 74 27 29 31 01 06 'c0content')1.. +| 4048: 17 11 11 08 51 74 61 62 6c 65 74 31 74 31 43 52 ....Qtablet1t1CR +| 4064: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB +| 4080: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33 LE t1 USING fts3 +| page 2 offset 4096 +| 0: 0d 00 00 00 03 0f e0 00 0f f6 0f ec 0f e0 00 00 ................ +| 4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00 .....abandon.... +| 4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b .abaft.....aback +| page 3 offset 8192 +| 0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................ +| page 4 offset 12288 +| 0: 0d 00 00 00 01 0f d6 00 0f d6 00 00 00 00 00 00 ................ +| 4048: 00 00 00 00 00 00 28 01 07 08 08 08 08 15 46 30 ......(.......F0 +| 4064: 20 32 39 00 05 61 62 61 63 6b 03 01 02 00 03 02 29..aback...... +| 4080: 66 74 03 02 02 00 03 04 6e 64 6f 60 30 30 20 00 ft......ndo`00 . +| page 5 offset 16384 +| 0: a0 00 00 00 10 ff b0 00 ff fb 00 00 00 00 00 00 ................ +| 4080: 00 00 00 00 00 00 00 00 00 00 00 04 04 08 08 09 ................ +| page 6 offset 20480 +| 0: 0d 00 00 00 05 0f b8 00 0f f4 0f e9 0f d6 0f c7 ................ +| 16: 0f b8 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 ..'t1_content'(d +| 32: 6f 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 ocid INTEGER PRI +| 48: 4d 41 52 59 20 4b 45 59 2c 20 27 63 30 63 6f 6e MARY KEY, 'c0con +| 64: 74 65 6e 74 27 29 31 01 06 17 11 11 08 51 74 61 tent')1......Qta +| 80: 62 6c 65 74 31 74 31 43 52 45 41 54 45 20 56 49 blet1t1CREATE VI +| 96: 52 54 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 RTUAL TABLE t1 U +| 112: 53 49 4e 47 20 66 74 73 33 0d 00 00 00 03 0f e0 SING fts3....... +| 128: 00 0f f6 0f ec 0f e0 00 00 00 00 00 00 00 00 00 ................ +| 4016: 00 00 00 00 00 00 00 00 0d 05 02 23 61 75 74 6f ...........#auto +| 4032: 6d 65 72 67 65 3d 35 0d 04 02 23 6d 65 72 67 65 merge=5...#merge +| 4048: 3d 31 30 30 2c 38 11 03 02 2b 69 6e 74 65 67 72 =100,8...+integr +| 4064: 69 74 79 2d 63 68 65 63 6b 09 02 02 1b 72 65 62 ity-check....reb +| 4080: 75 69 6c 64 0a 01 02 1d 6f 70 74 69 6d 69 7a 65 uild....optimize +| end c15.db +}]} {} + +do_catchsql_test 5.1 { + SELECT * FROM t1 WHERE t1 MATCH 'abandon'; +} {1 {malformed database schema (sqlite_autoindey_t1_segdir_1) - orphan index}} + + +#------------------------------------------------------------------------- +reset_db +database_may_be_corrupt +do_execsql_test 6.0 { + CREATE VIRTUAL TABLE Table0 USING fts3(); + INSERT INTO Table0_segdir VALUES(1,NULL,1,NULL,NULL,NULL); +} + +do_catchsql_test 6.1 { + SELECT * FROM Table0 WHERE Table0 MATCH 'a'; +} {0 {}} + +do_catchsql_test 6.2 { + INSERT INTO Table0(Table0) VALUES('optimize'); +} {0 {}} + +#------------------------------------------------------------------------- +reset_db +do_test 7.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 32768 pagesize 4096 filename crash-04bb6e7c811ce9.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07 .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ +| 96: 00 00 00 00 0d 0e ef 00 07 0d 4d 00 0f bd 0f 5f ..........M...._ +| 112: 0e f7 0e 06 0e bc 0d a4 0d 4d 00 00 00 00 00 00 .........M...... +| 3392: 00 00 00 00 00 00 00 00 00 00 00 00 00 55 07 07 .............U.. +| 3408: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 73 74 ......tablet1_st +| 3424: 61 74 74 31 5f 73 74 61 74 07 43 52 45 41 54 45 att1_stat.CREATE +| 3440: 20 54 41 42 4c 45 20 27 74 31 5f 73 74 61 74 27 TABLE 't1_stat' +| 3456: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d (id INTEGER PRIM +| 3472: 41 52 59 20 4b 45 59 2c 20 76 61 6c 75 65 20 42 ARY KEY, value B +| 3488: 4c 4f 42 29 60 06 07 17 21 21 01 81 0b 74 61 62 LOB)`...!!...tab +| 3504: 6c 65 74 31 5f 64 6f 63 73 69 7a 65 74 31 5f 64 let1_docsizet1_d +| 3520: 6f 63 73 69 7a 65 06 43 52 45 41 54 45 20 54 41 ocsize.CREATE TA +| 3536: 42 4c 45 20 27 74 31 5f 64 6f 63 73 69 7a 65 27 BLE 't1_docsize' +| 3552: 28 64 6f 63 69 64 20 49 4e 54 45 47 45 52 20 50 (docid INTEGER P +| 3568: 52 49 4d 41 52 59 20 4b 45 59 2c 20 73 69 7a 65 RIMARY KEY, size +| 3584: 20 42 4c 4f 42 29 81 33 04 07 17 1f 1f 01 82 35 BLOB).3.......5 +| 3600: 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72 74 31 tablet1_segdirt1 +| 3616: 5f 73 65 67 64 69 72 04 43 52 45 41 54 45 20 54 _segdir.CREATE T +| 3632: 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69 72 27 ABLE 't1_segdir' +| 3648: 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52 2c 69 (level INTEGER,i +| 3664: 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61 72 74 dx INTEGER,start +| 3680: 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52 2c 6c _block INTEGER,l +| 3696: 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 6b 20 eaves_end_block +| 3712: 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c 6f 63 INTEGER,end_bloc +| 3728: 6b 20 49 4e 54 45 47 45 52 2c 72 6f 6f 74 20 42 k INTEGER,root B +| 3744: 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45 59 28 LOB,PRIMARY KEY( +| 3760: 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 05 06 17 level, idx))1... +| 3776: 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74 65 5f E...indexsqlite_ +| 3792: 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73 65 67 autoindex_t1_seg +| 3808: 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72 05 00 dir_1t1_segdir.. +| 3824: 00 00 08 00 00 00 00 66 03 07 17 23 23 01 81 13 .......f...##... +| 3840: 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e 74 73 tablet1_segments +| 3856: 74 31 5f 73 65 67 6d 65 6e 74 73 03 43 52 45 41 t1_segments.CREA +| 3872: 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 TE TABLE 't1_seg +| 3888: 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64 20 49 ments'(blockid I +| 3904: 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b NTEGER PRIMARY K +| 3920: 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 29 5c EY, block BLOB). +| 3936: 02 07 17 21 21 01 81 03 74 61 62 6c 65 74 31 5f ...!!...tablet1_ +| 3952: 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 65 6e contentt1_conten +| 3968: 74 02 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 t.CREATE TABLE ' +| 3984: 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f 63 69 t1_content'(doci +| 4000: 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 d INTEGER PRIMAR +| 4016: 59 20 4b 45 59 2c 20 27 63 30 61 27 29 41 01 06 Y KEY, 'c0a')A.. +| 4032: 17 11 11 08 71 74 61 62 6c 65 74 31 74 31 43 52 ....qtablet1t1CR +| 4048: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB +| 4064: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 34 LE t1 USING fts4 +| 4080: 28 61 2c 70 72 65 66 69 78 3d 27 31 2c 32 27 29 (a,prefix='1,2') +| page 2 offset 4096 +| 0: 0d 00 00 00 08 0e 1f 00 0f c4 0f 7c 0f 34 0f 07 ...........|.4.. +| 16: 0e c3 0e 97 0e 63 0e 1f 00 00 00 00 00 00 00 00 .....c.......... +| 3600: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 42 ...............B +| 3616: 08 04 00 81 09 73 75 6e 74 20 69 6e 20 63 75 6c .....sunt in cul +| 3632: 70 61 20 71 75 69 20 6f 66 66 69 63 69 61 20 64 pa qui officia d +| 3648: 65 73 65 72 75 6e 74 20 6d 6f 6c 6c 69 74 20 61 eserunt mollit a +| 3664: 6e 69 6d 20 69 64 20 65 73 74 20 6c 61 62 6f 72 nim id est labor +| 3680: 75 6d 2e 32 07 03 00 6b 45 78 63 65 70 74 65 75 um.2...kExcepteu +| 3696: 72 20 73 69 6e 74 20 6f 63 63 61 65 63 67 42 06 r sint occaecgB. +| 3712: 37 57 06 96 46 17 46 17 42 06 e6 f6 e2 07 07 26 7W..F.F.B......& +| 3728: f6 96 46 56 e7 42 c2 a0 60 30 05 b6 36 96 c6 c7 ..FV.B..`0..6... +| 3744: 56 d2 06 46 f6 c6 f7 26 52 06 57 52 06 67 56 7c V..F...&R.WR.gV| +| 3760: 65 3f 04 20 6e 75 6c 6c 61 20 70 61 72 69 61 74 e?. nulla pariat +| 3776: 75 72 2e 42 05 04 00 81 09 44 75 69 73 20 61 75 ur.B.....Duis au +| 3792: 74 65 20 69 72 75 72 65 20 64 6f 6c 6f 72 20 69 te irure dolor i +| 3808: 6e 20 72 65 70 72 65 68 65 6e 64 65 72 69 74 20 n reprehenderit +| 3824: 69 6e 20 76 6f 6c 75 70 74 61 74 65 20 76 65 6c in voluptate vel +| 3840: 69 74 20 65 73 73 65 2b 04 03 00 5d 6e 69 73 69 it esse+...]nisi +| 3856: 20 75 74 20 61 6c 69 71 75 69 70 20 65 78 20 65 ut aliquip ex e +| 3872: 61 20 63 6f 6d 6d 6f 64 6f 20 63 6f 6e 73 65 71 a commodo conseq +| 3888: 75 61 74 2e 46 03 04 00 81 11 55 74 20 65 6e 69 uat.F.....Ut eni +| 3904: 6d 20 61 64 20 6d 69 6e 69 6d 20 76 65 6e 69 61 m ad minim venia +| 3920: 6d 2c 20 71 75 69 73 20 6e 6f 73 74 72 75 64 20 m, quis nostrud +| 3936: 65 78 65 72 63 69 74 61 74 69 6f 6e 20 75 6c 6c exercitation ull +| 3952: 61 6d 63 6f 20 6c 61 62 6f 72 69 73 46 02 04 00 amco laborisF... +| 3968: 81 11 73 65 64 20 64 6f 20 65 69 75 73 6d 6f 64 ..sed do eiusmod +| 3984: 20 74 65 6d 70 6f 72 20 69 6e 63 69 64 69 64 75 tempor incididu +| 4000: 6e 74 20 75 74 20 6c 61 62 6f 72 65 20 65 74 20 nt ut labore et +| 4016: 64 6f 6c 6f 72 65 20 6d 61 67 6e 61 20 61 6c 69 dolore magna ali +| 4032: 71 75 61 2e 3a 01 03 00 7b 4c 6f 72 65 6d 20 69 qua.:....Lorem i +| 4048: 70 73 75 6d 20 64 6f 6c 6f 72 20 73 69 72 12 29 psum dolor sir.) +| 4064: 0d 65 74 2c 20 63 6f 6e 73 65 63 74 65 74 75 72 .et, consectetur +| 4080: 20 61 64 69 70 69 73 63 69 6e 67 20 65 6c 69 74 adipiscing elit +| page 3 offset 8192 +| 0: 0d 00 00 00 00 10 30 00 10 17 50 30 80 20 00 00 ......0...P0. .. +| 16: 27 46 50 30 20 50 00 00 27 56 c0 30 30 a0 00 10 'FP0 P..'V.00... +| 32: 17 40 90 20 70 00 10 20 00 10 30 00 00 27 66 50 .@. p.. ..0..'fP +| 48: 60 30 60 00 20 a0 00 10 16 f0 30 50 90 08 20 a0 `0`. .....0P.. . +| 64: 20 80 20 80 80 81 78 40 20 40 03 02 03 23 53 10 . ...x@ @...#S. +| 80: 00 16 11 30 10 60 40 00 10 c0 00 10 40 00 00 00 ...0.`@.....@... +| 96: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 78 24 ..............x$ +| 112: 41 71 83 37 10 27 97 60 10 40 00 00 16 41 10 10 Aq.7.'.`.@...A.. +| 128: 40 00 10 30 90 00 30 20 50 00 10 30 00 20 70 00 @..0..0 P..0. p. +| 144: 00 16 51 b0 10 90 00 10 40 70 00 10 30 80 00 10 ..Q.....@p..0... +| 160: 50 30 00 10 b0 00 10 40 00 10 20 00 10 b0 00 00 P0.....@.. ..... +| 176: 16 60 30 60 50 00 00 16 90 f0 10 30 00 10 60 00 .`0`P......0..`. +| 192: 30 40 40 40 00 30 30 90 00 00 16 c0 c0 10 20 00 0@@@.00....... . +| 208: 10 80 00 10 b0 00 50 c0 00 00 16 d0 90 20 b0 00 ......P...... .. +| 224: 10 50 00 50 80 00 00 16 e0 c0 30 80 00 10 20 00 .P.P......0... . +| 240: 20 60 00 10 60 00 00 16 f0 60 70 40 00 10 60 00 `..`....`p@..`. +| 256: 00 17 00 60 60 70 00 10 70 00 00 17 10 60 30 70 ...``p..p....`0p +| 272: 00 50 50 00 00 17 20 30 50 70 00 00 17 30 c0 10 .PP... 0Pp...0.. +| 288: 50 00 10 20 00 50 30 00 10 20 00 00 17 40 30 20 P.. .P0.. ...@0 +| 304: 50 00 00 17 50 a0 20 70 00 10 20 a0 00 10 30 00 P...P. p.. ...0. +| 320: 00 17 60 70 30 60 00 20 90 30 08 52 60 10 80 80 ..`p0`. .0.R`... +| 336: 80 80 81 78 a3 e3 02 03 63 63 50 00 26 16 40 30 ...x....ccP.&.@0 +| 352: 30 40 00 20 86 97 06 97 36 36 96 e6 70 30 10 80 0@. ....66..p0.. +| 368: 00 10 56 c6 97 17 56 10 30 20 c0 00 50 26 97 00 ..V...V.0 ..P&.. +| 384: 30 40 40 00 10 36 d6 57 40 30 10 60 00 10 36 e6 0@@..6.W@0.`..6. +| 400: 96 d0 30 80 90 00 10 37 57 46 50 30 50 30 00 00 ..0....7WFP0P0.. +| 416: 66 36 96 c6 c7 56 d0 30 60 20 00 10 66 f6 d6 d6 f6...V.0` ..f... +| 432: f6 46 f0 30 40 70 00 20 96 e7 36 56 37 46 57 47 .F.0@p. ..6V7FWG +| 448: 57 20 30 10 70 00 50 47 17 56 17 40 30 40 80 00 W 0.p.PG.V.@0@.. +| 464: 10 47 56 c7 06 10 30 80 40 00 20 77 06 96 46 17 .GV...0.@. w..F. +| 480: 46 17 40 30 70 50 00 00 86 46 57 36 57 27 56 e7 F.@0pP...FW6W'V. +| 496: 40 30 80 70 00 10 16 f0 30 20 30 00 20 36 c6 f7 @0.p....0 0. 6.. +| 512: 20 60 10 40 00 40 50 00 50 16 50 60 20 a0 00 40 `.@.@P.P.P` ..@ +| 528: 30 00 10 37 56 97 30 30 50 20 00 00 26 56 10 30 0..7V.00P ..&V.0 +| 544: 40 60 00 10 66 97 57 36 d6 f6 40 30 20 40 00 10 @`..f.W6..@0 @.. +| 560: 36 c6 97 40 30 10 90 00 15 35 14 c6 97 46 52 06 6..@0....5...FR. +| 576: 66 f7 26 d6 17 42 03 30 01 00 00 10 10 04 02 02 f.&..B.0........ +| 592: 00 00 00 00 00 00 00 00 70 00 00 00 00 00 00 00 ........p....... +| 608: 00 00 00 00 60 00 00 00 40 00 00 00 00 00 00 00 ....`...@....... +| page 4 offset 12288 +| 0: 0d 00 00 00 03 0a a6 00 0d 57 0c 4a 0a a6 00 00 .........W.J.... +| 2720: 00 00 00 00 00 00 83 21 03 08 02 08 08 08 17 86 .......!........ +| 2736: 30 08 00 30 20 34 30 32 00 02 61 64 06 01 08 00 0..0 402..ad.... +| 2752: 02 04 00 01 01 6c 06 02 0c 00 02 04 00 01 01 6d .....l.........m +| 2768: 03 01 06 00 01 01 6e 03 08 00 00 91 01 75 03 05 ......n......u.. +| 2784: 03 00 00 02 63 69 03 06 02 00 01 01 6f 07 01 07 ....ci......o... +| 2800: 00 03 07 03 00 01 01 75 06 07 05 00 01 04 00 00 .......u........ +| 2816: 02 64 65 03 08 07 00 01 01 6f 0d 01 04 00 01 03 .de......o...... +| 2832: 09 00 03 05 00 01 03 00 01 01 75 03 05 02 00 00 ..........u..... +| 2848: 02 65 61 03 04 06 00 01 01 69 03 02 04 00 01 01 .ea......i...... +| 2864: 6c 03 01 09 00 01 01 6e 30 03 03 00 01 01 73 06 l......n0.....s. +| 2880: 05 0b 00 03 0b 00 01 01 74 03 02 09 00 01 01 75 ........t......u +| 2896: 03 06 04 00 01 01 78 09 03 09 00 01 05 00 03 02 ......x......... +| 2912: 00 00 02 66 75 03 06 05 00 00 02 69 64 03 08 0a ...fu......id... +| 2928: 00 01 01 6e 0a 02 06 00 03 06 04 00 03 03 00 01 ...n............ +| 2944: 01 70 03 01 03 00 01 01 72 03 05 04 00 00 02 6c .p......r......l +| 2960: 61 09 02 08 00 01 0b 00 05 0c 00 01 01 6f 03 01 a............o.. +| 2976: 02 00 00 02 6d 61 03 02 0b 00 01 01 69 03 03 05 ....ma......i... +| 2992: 00 01 01 6f 03 08 08 00 00 02 6e 69 03 04 02 00 ...o......ni.... +| 3008: 01 01 6f 06 03 08 00 04 06 00 01 01 75 03 06 06 ..o.........u... +| 3024: 00 00 02 6f 63 03 07 04 00 01 01 66 03 08 06 00 ...oc......f.... +| 3040: 00 02 70 61 03 06 07 00 01 01 72 03 07 07 00 00 ..pa......r..... +| 3056: 02 71 75 06 03 07 00 05 05 00 00 02 72 65 03 05 .qu.........re.. +| 3072: 07 00 00 02 73 65 03 02 02 00 01 01 69 06 01 05 ....se......i... +| 3088: 00 06 03 00 01 01 75 03 08 02 00 00 02 74 65 03 ......u......te. +| 3104: 02 05 00 00 02 75 6c 03 03 0a 00 01 01 74 09 02 .....ul......t.. +| 3120: 07 00 01 02 00 01 03 00 00 02 76 65 06 03 06 00 ..........ve.... +| 3136: 02 0a 00 01 01 6f 03 05 09 00 82 0a 02 08 02 08 .....o.......... +| 3152: 08 08 17 84 02 04 00 30 20 32 35 31 00 01 61 13 .......0 251..a. +| 3168: 01 06 04 00 01 0c 00 01 04 00 01 04 00 01 03 00 ................ +| 3184: 03 09 00 00 01 63 10 01 07 00 03 07 03 00 02 02 .....c.......... +| 3200: 00 01 05 00 01 04 00 00 01 64 11 01 04 00 01 03 .........d...... +| 3216: 09 00 03 02 05 00 01 03 00 02 07 00 00 01 65 1b ..............e. +| 3232: 01 09 00 01 04 01 70 00 03 01 80 00 05 03 00 01 ......p......... +| 3248: 0b 00 01 04 00 01 02 00 01 0b 00 00 01 66 03 06 .............f.. +| 3264: 05 00 00 01 69 0f 01 03 00 01 06 00 03 04 04 04 ....i........... +| 3280: 00 03 03 09 00 00 01 6c 0c 01 02 00 01 08 00 01 .......l........ +| 3296: 0b 00 05 0c 00 00 01 6d 09 02 0b 00 01 05 00 05 .......m........ +| 3312: 08 00 00 01 6e 0c 03 08 00 01 02 00 02 06 00 01 ....n........... +| 3328: 06 00 00 01 6f 06 07 04 00 01 06 00 00 01 70 06 ....o.........p. +| 3344: 06 07 00 01 07 00 00 01 71 06 03 07 00 05 05 00 ........q....... +| 3360: 00 01 72 03 05 07 00 00 01 73 0c 01 05 00 01 02 ..r......s...... +| 3376: 00 05 03 00 01 02 00 00 01 74 03 02 05 00 00 01 .........t...... +| 3392: 75 0a 02 07 00 01 02 0a 00 01 03 00 00 01 76 07 u.............v. +| 3408: 03 06 00 02 09 03 00 85 26 01 08 08 08 08 08 17 ........&....... +| 3424: 8a 3e 30 20 36 36 35 00 02 61 64 03 03 04 00 02 .>0 665..ad..... +| 3440: 08 69 70 69 73 63 69 6e 67 03 01 08 00 01 05 6c .ipiscing......l +| 3456: 69 71 75 61 03 02 0c 00 05 02 69 70 03 04 04 00 iqua......ip.... +| 3472: 01 03 6d 65 74 03 01 06 00 01 03 6e 69 6d 03 08 ..met......nim.. +| 3488: 09 00 01 03 75 74 65 03 05 03 00 00 06 63 69 6c ....ute......cil +| 3504: 6c 75 6d 03 06 02 00 01 06 6f 6d 6d 6f 64 6f 03 lum......ommodo. +| 3520: 04 07 00 02 09 6e 73 65 63 74 65 74 75 72 03 01 .....nsectetur.. +| 3536: 07 00 05 04 71 75 61 74 03 04 08 00 01 04 75 6c ....quat......ul +| 3552: 70 61 03 08 04 00 02 07 70 69 64 61 74 61 74 03 pa......pidatat. +| 3568: 07 05 00 00 08 64 65 73 65 72 75 6e 74 03 08 07 .....deserunt... +| 3584: 00 01 01 6f 03 02 03 00 02 03 6c 6f 72 06 01 04 ...o......lor... +| 3600: 00 04 05 00 05 01 65 06 02 0a 00 04 03 00 01 03 ......e......... +| 3616: 75 69 73 03 05 02 00 00 02 65 61 03 04 06 00 01 uis......ea..... +| 3632: 06 69 75 73 6d 6f 64 03 02 04 00 01 03 6c 69 74 .iusmod......lit +| 3648: 03 01 09 00 01 03 6e 69 6d 03 03 03 00 01 03 73 ......nim......s +| 3664: 73 65 03 05 0b 00 02 01 74 03 08 0b 00 01 01 74 se......t......t +| 3680: 03 02 09 00 01 01 75 03 06 04 00 01 01 78 03 04 ......u......x.. +| 3696: 05 00 02 07 63 65 70 74 65 75 72 03 07 02 00 02 ....cepteur..... +| 3712: 0a 65 72 63 69 74 61 74 69 6f 6e 03 03 09 00 00 .ercitation..... +| 3728: 06 66 75 67 69 61 74 03 06 05 00 00 02 69 64 03 .fugiat......id. +| 3744: 08 0a 00 01 01 6e 07 05 06 04 00 03 03 00 02 08 .....n.......... +| 3760: 63 69 64 69 64 75 6e 74 03 02 06 00 01 04 70 73 cididunt......ps +| 3776: 75 6d 03 01 03 00 01 04 72 75 72 65 03 05 04 00 um......rure.... +| 3792: 00 06 6c 61 62 6f 72 65 03 02 08 00 05 02 69 73 ..labore......is +| 3808: 03 03 0b 00 05 02 75 6d 03 08 0c 00 01 04 6f 72 ......um......or +| 3824: 65 6d 03 01 02 00 00 05 6d 61 67 6e 61 03 02 0b em......magna... +| 3840: 00 01 04 69 6e 69 6d 03 03 05 00 01 05 6f 6c 6c ...inim......oll +| 3856: 69 74 03 08 08 00 00 04 6e 69 73 69 03 04 02 00 it......nisi.... +| 3872: 01 02 6f 6e 03 07 06 00 02 05 73 74 72 75 64 03 ..on......strud. +| 3888: 03 08 00 01 04 75 6c 6c 61 03 06 06 00 00 08 6f .....ulla......o +| 3904: 63 63 61 65 63 61 74 03 07 04 00 01 06 66 66 69 ccaecat......ffi +| 3920: 63 69 61 03 08 06 00 00 08 70 61 72 69 61 74 75 cia......pariatu +| 3936: 72 03 06 07 00 01 07 72 6f 69 64 65 6e 74 03 07 r......roident.. +| 3952: 07 00 00 03 71 75 69 03 08 05 00 03 01 73 03 03 ....qui......s.. +| 3968: 07 00 00 0d 72 65 70 72 65 68 65 6e 64 65 72 69 ....reprehenderi +| 3984: 74 03 05 07 00 00 03 73 65 64 03 02 02 00 01 03 t......sed...... +| 4000: 69 6e 74 03 07 03 00 02 01 74 03 01 05 00 01 03 int......t...... +| 4016: 75 6e 74 03 08 02 00 00 06 74 65 6d 70 6f 72 03 unt......tempor. +| 4032: 02 05 00 00 07 75 6c 6c 61 6d 63 6f 03 03 0a 00 .....ullamco.... +| 4048: 01 01 74 09 02 07 00 01 02 00 01 03 00 00 05 76 ..t............v +| 4064: 65 6c 69 74 03 05 0a 00 02 04 6e 69 61 6d 03 03 elit......niam.. +| 4080: 06 00 01 08 6f 6c 75 70 74 61 74 65 03 05 09 00 ....oluptate.... +| page 5 offset 16384 +| 0: 0a 00 00 00 03 0f eb 00 0f fb 0f f3 0f eb 00 00 ................ +| 4064: 00 00 00 00 00 00 00 00 00 00 00 07 04 02 08 01 ................ +| 4080: 08 00 03 07 04 02 08 01 04 00 02 04 04 08 08 09 ................ +| page 6 offset 20480 +| 0: 0d 00 00 00 08 0f d0 00 0f fa 0f f4 0f ee 0f e8 ................ +| 16: 0f e2 0f dc 0f d6 0f d0 00 00 00 00 00 00 00 00 ................ +| 4048: 04 08 03 00 0e 0b 04 07 03 00 0e 06 04 06 03 00 ................ +| 4064: 0e 06 04 05 03 00 0e 0a 04 04 03 00 0e 07 04 03 ................ +| 4080: 03 00 0e 0a 04 02 03 00 0e 0b 04 01 03 00 0e 08 ................ +| page 7 offset 24576 +| 0: 0d 00 00 00 01 0f f7 00 0f f7 00 00 00 00 00 00 ................ +| 4080: 00 00 00 00 00 00 00 07 00 03 00 14 08 45 b5 03 .............E.. +| page 8 offset 28672 +| 0: 6f ee cd e1 f1 ee 1a ca be ed ee ec de ac f1 cb o............... +| 16: f1 ee 1a ce de ee f1 ee 0a cc de ed ae 90 87 88 ................ +| 32: ec 5e dc ec fc 11 72 32 75 0a da be ec ed eb de .^....r2u....... +| 48: ce c1 aa e0 ae ec 1f c1 ee 99 c2 aa e0 a9 ad 15 ................ +| 64: 0e ec ab ef 1e e0 48 ad 15 04 24 80 00 00 00 00 ......H...$..... +| 80: 00 00 00 00 e0 00 00 00 04 2c 80 00 10 42 4e c1 .........,...BN. +| 96: 20 4b 45 59 2c 6e 6f 64 65 6e 6f 2c 61 30 29 46 KEY,nodeno,a0)F +| 112: 02 06 17 11 11 08 7b 74 61 62 6c 65 74 31 74 31 .......tablet1t1 +| 128: 43 52 45 41 54 e1 ec eb ea eb eb ac ee ce be de CREAT........... +| 144: ee f1 ee 1a ca ba de 47 80 30 00 14 90 47 70 30 .......G.0...Gp0 +| 160: 00 11 60 47 60 30 00 15 f0 47 50 30 00 10 f0 47 ..`G`0...GP0...G +| 176: 40 30 00 11 f0 47 45 20 30 00 11 d0 45 10 30 00 @0...GE 0...E.0. +| 192: 12 10 45 00 30 00 14 e0 44 f0 30 00 11 e0 44 e0 ..E.0...D.0...D. +| 208: 30 00 12 a0 44 d0 30 00 15 e0 44 c0 30 00 10 40 0...D.0...D.0..@ +| 224: 44 b0 30 00 15 10 44 a0 30 00 14 c0 44 90 30 00 D.0...D.0...D.0. +| 240: 16 20 44 80 30 00 52 45 41 54 45 20 54 41 42 4c . D.0.REATE TABL +| 256: 45 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 69 E 't1_content'(i +| 272: 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 d INTEGER PRIMAR +| 288: 59 20 4b 45 59 2c 20 63 30 29 69 03 07 17 19 19 Y KEY, c0)i..... +| 304: 01 81 2d 74 61 62 6c 65 74 31 5f 69 64 78 74 31 ..-tablet1_idxt1 +| 320: 5f 69 64 78 03 43 52 45 41 54 45 20 54 41 42 4c _idx.CREATE TABL +| 336: 45 20 27 70 31 5f 69 64 78 03 6e 69 6d 03 03 03 E 'p1_idx.nim... +| 352: 00 01 03 73 73 65 03 05 0b 00 02 01 74 03 08 0b ...sse......t... +| 368: 00 01 01 74 03 02 09 00 01 01 75 03 06 04 00 01 ...t......u..... +| 384: 01 78 03 04 05 00 02 07 63 65 70 74 65 75 72 03 .x......cepteur. +| 400: 07 02 00 02 0a 65 72 63 69 74 61 74 69 6f 6e 03 .....ercitation. +| 416: 03 09 00 00 06 66 75 67 69 61 74 03 06 05 00 00 .....fugiat..... +| 432: 02 69 64 03 08 0a 00 01 01 6e 07 05 06 04 00 03 .id......n...... +| 448: 03 00 02 08 63 69 64 69 64 75 6e 74 03 02 06 00 ....cididunt.... +| 464: 01 04 70 73 75 6d 03 01 03 00 01 04 72 75 72 65 ..psum......rure +| 480: 03 05 04 00 00 06 6c 61 62 6f 72 65 03 02 08 00 ......labore.... +| 496: 05 02 69 73 03 03 0b 00 05 02 75 6d 03 08 0c 00 ..is......um.... +| 512: 01 04 6f 72 65 6d 03 01 02 00 00 05 6d 61 67 6e ..orem......magn +| 528: 61 03 02 0b 00 01 04 69 6e 69 6d 03 03 05 00 01 a......inim..... +| 544: 05 6f 6c 6c 69 74 03 08 08 00 00 04 6e 69 73 69 .ollit......nisi +| 560: 03 04 02 00 01 02 6f 6e 03 07 06 00 02 05 73 74 ......on......st +| 576: 72 75 64 03 03 08 00 01 04 75 6c 6c 61 03 06 06 rud......ulla... +| 592: 00 00 08 6f 63 63 61 65 63 61 74 03 07 04 00 01 ...occaecat..... +| 608: 06 66 66 69 63 69 61 03 08 06 00 00 08 70 61 72 .fficia......par +| 624: 69 61 74 75 72 03 06 07 00 01 07 72 6f ed ce de iatur......ro... +| 640: 69 64 65 6e 74 03 07 07 00 00 03 71 75 69 03 08 ident......qui.. +| 656: 05 00 03 01 73 03 03 07 00 00 0d 72 65 70 72 65 ....s......repre +| 672: 68 65 6e 64 65 72 69 74 03 05 07 00 00 03 73 65 henderit......se +| 688: 64 03 02 02 00 01 03 69 6e 74 03 07 03 00 02 01 d......int...... +| 704: 74 03 01 05 00 01 03 75 6e 74 03 08 02 00 00 06 t......unt...... +| 720: 74 65 6d 70 6f 72 03 02 05 00 00 07 75 6c 6c 61 tempor......ulla +| 736: 6d 63 6f 03 03 0a 00 01 01 74 09 02 07 00 01 02 mco......t...... +| 752: 00 01 03 00 00 05 76 65 6c 69 74 03 05 0a 00 02 ......velit..... +| 768: 04 6e 69 61 6d 03 03 06 00 01 08 6f 6c 75 70 74 .niam......olupt +| 784: 61 74 65 03 05 09 00 0a 00 00 00 03 0f eb 00 0f ate............. +| 800: fb 0f f3 0f eb 00 00 00 00 00 00 00 00 00 00 00 ................ +| end crash-04bb6e7c811ce9.db +}]} {} + +do_catchsql_test 7.1 { + SELECT matchinfo(t1,'y') FROM t1 WHERE t1 MATCH 'e*'; +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +reset_db +do_test 8.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 28672 pagesize 4096 filename crash-7948058d822acb.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07 .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ +| 96: 00 00 00 00 0d 0e ef 00 07 0d 4d 00 0f bd 0f 5f ..........M...._ +| 112: 0e f7 0e 06 0e bc 0d a4 0d 4d 00 00 00 00 00 00 .........M...... +| 3392: 00 00 00 00 00 00 00 00 00 00 00 00 00 55 07 07 .............U.. +| 3408: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 73 74 ......tablet1_st +| 3424: 61 74 74 31 5f 73 74 61 74 07 43 52 45 41 54 45 att1_stat.CREATE +| 3440: 20 54 41 42 4c 45 20 27 74 31 5f 73 74 61 74 27 TABLE 't1_stat' +| 3456: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d (id INTEGER PRIM +| 3472: 41 52 59 20 4b 45 59 2c 20 76 61 6c 75 65 20 42 ARY KEY, value B +| 3488: 4c 4f 42 29 60 06 07 17 21 21 01 81 0b 74 61 62 LOB)`...!!...tab +| 3504: 6c 65 74 31 5f 64 6f 63 73 69 7a 65 74 31 5f 64 let1_docsizet1_d +| 3520: 6f 63 73 69 7a 65 06 43 52 45 41 54 45 20 54 41 ocsize.CREATE TA +| 3536: 42 4c 45 20 27 74 31 5f 64 6f 63 73 69 7a 65 27 BLE 't1_docsize' +| 3552: 28 64 6f 63 69 64 20 49 4e 54 45 47 45 52 20 50 (docid INTEGER P +| 3568: 52 49 4d 41 52 59 20 4b 45 59 2c 20 73 69 7a 65 RIMARY KEY, size +| 3584: 20 42 4c 4f 42 29 81 33 04 07 17 1f 1f 01 82 35 BLOB).3.......5 +| 3600: 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72 74 31 tablet1_segdirt1 +| 3616: 5f 73 65 67 64 69 72 04 43 52 45 41 54 45 20 54 _segdir.CREATE T +| 3632: 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69 72 27 ABLE 't1_segdir' +| 3648: 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52 2c 69 (level INTEGER,i +| 3664: 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61 72 74 dx INTEGER,start +| 3680: 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52 2c 6c _block INTEGER,l +| 3696: 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 6b 20 eaves_end_block +| 3712: 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c 6f 63 INTEGER,end_bloc +| 3728: 6b 20 49 4e 54 45 47 45 52 2c 72 6f 6f 74 20 42 k INTEGER,root B +| 3744: 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45 59 28 LOB,PRIMARY KEY( +| 3760: 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 05 06 17 level, idx))1... +| 3776: 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74 65 5f E...indexsqlite_ +| 3792: 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73 65 67 autoindex_t1_seg +| 3808: 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72 05 00 dir_1t1_segdir.. +| 3824: 00 00 08 00 00 00 00 66 03 07 17 23 23 01 81 13 .......f...##... +| 3840: 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e 74 73 tablet1_segments +| 3856: 74 31 5f 73 65 67 6d 65 6e 74 73 03 43 52 45 41 t1_segments.CREA +| 3872: 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 TE TABLE 't1_seg +| 3888: 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64 20 49 ments'(blockid I +| 3904: 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b NTEGER PRIMARY K +| 3920: 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 29 5c EY, block BLOB). +| 3936: 02 07 17 21 21 01 81 03 74 61 62 6c 65 74 31 5f ...!!...tablet1_ +| 3952: 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 65 6e contentt1_conten +| 3968: 74 02 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 t.CREATE TABLE ' +| 3984: 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f 63 69 t1_content'(doci +| 4000: 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 d INTEGER PRIMAR +| 4016: 59 20 4b 45 59 2c 20 27 63 30 61 27 29 41 01 06 Y KEY, 'c0a')A.. +| 4032: 17 11 11 08 71 74 61 62 6c 65 74 31 74 31 43 52 ....qtablet1t1CR +| 4048: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB +| 4064: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 34 LE t1 USING fts4 +| 4080: 28 61 2c 70 72 65 66 69 78 3d 27 31 2c 32 27 29 (a,prefix='1,2') +| page 2 offset 4096 +| 0: 0d 00 00 00 08 0e 1f 00 0f c4 0f 7c 0f 34 0f 07 ...........|.4.. +| 16: 0e c3 0e 97 0e 63 0e 1f 00 00 00 00 00 00 00 00 .....c.......... +| 3600: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 42 ...............B +| 3616: 08 04 00 81 09 73 75 6e 74 20 69 6e 20 63 75 6c .....sunt in cul +| 3632: 70 61 20 71 75 69 20 6f 66 66 69 63 69 61 20 64 pa qui officia d +| 3648: 65 73 65 72 75 6e 74 20 6d 6f 6c 6c 69 74 20 61 eserunt mollit a +| 3664: 6e 69 6d 20 69 64 20 65 73 74 20 6c 61 62 6f 72 nim id est labor +| 3680: 75 6d 2e 32 07 03 00 6b 45 78 63 65 70 74 65 75 um.2...kExcepteu +| 3696: 72 20 73 69 6e 74 20 6f 63 63 61 65 63 67 42 06 r sint occaecgB. +| 3712: 37 57 06 96 46 17 46 17 42 06 e6 f6 e2 07 07 26 7W..F.F.B......& +| 3728: f6 96 46 56 e7 42 c2 a0 60 30 05 b6 36 96 c6 c7 ..FV.B..`0..6... +| 3744: 56 d2 06 46 f6 c6 f7 26 52 06 57 52 06 67 56 7c V..F...&R.WR.gV| +| 3760: 65 3f 04 20 6e 75 6c 6c 61 20 70 61 72 69 61 74 e?. nulla pariat +| 3776: 75 72 2e 42 05 04 00 81 09 44 75 69 73 20 61 75 ur.B.....Duis au +| 3792: 74 65 20 69 72 75 72 65 20 64 6f 6c 6f 72 20 69 te irure dolor i +| 3808: 6e 20 72 65 70 72 65 68 65 6e 64 65 72 69 74 20 n reprehenderit +| 3824: 69 6e 20 76 6f 6c 75 70 74 61 74 65 20 76 65 6c in voluptate vel +| 3840: 69 74 20 65 73 73 65 2b 04 03 00 5d 6e 69 73 69 it esse+...]nisi +| 3856: 20 75 74 20 61 7c 69 71 75 69 70 20 65 78 20 65 ut a|iquip ex e +| 3872: 61 20 63 6f 6d 6d 6f 64 6f 20 63 6f 6e 73 65 71 a commodo conseq +| 3888: 75 61 74 2e 46 03 04 00 81 11 55 74 20 65 6e 69 uat.F.....Ut eni +| 3904: 6d 20 61 64 20 6d 69 6e 69 6d 20 76 65 6e 69 61 m ad minim venia +| 3920: 6d 2c 20 71 75 69 73 20 6e 6f 73 74 72 75 64 20 m, quis nostrud +| 3936: 65 78 65 72 63 69 74 61 74 69 6f 6e 20 75 6c 6c exercitation ull +| 3952: 61 6d 63 6f 20 6c 61 62 6f 72 69 73 46 02 04 00 amco laborisF... +| 3968: 81 11 73 65 64 20 64 6f 20 65 69 75 73 6d 6f 64 ..sed do eiusmod +| 3984: 20 74 65 6d 70 6f 72 20 69 6e 63 69 64 69 64 75 tempor incididu +| 4000: 6e 74 20 75 74 20 6c 61 62 6f 72 65 20 65 74 20 nt ut labore et +| 4016: 64 6f 6c 6f 72 65 20 6d 61 67 6e 61 20 61 6c 69 dolore magna ali +| 4032: 71 75 61 2e 3a 01 03 00 7b 4c 6f 72 65 6d 20 69 qua.:....Lorem i +| 4048: 70 73 75 6d 20 64 6f 6c 6f 72 20 73 69 74 20 61 psum dolor sit a +| 4064: 6d 65 74 2c 20 63 6f 6e 73 65 63 74 65 74 75 72 met, consectetur +| 4080: 20 61 64 69 70 69 73 63 69 6e 67 20 65 6c 69 74 adipiscing elit +| page 3 offset 8192 +| 0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................ +| page 4 offset 12288 +| 0: 0d 00 00 00 03 0a a6 00 0d 57 0c 4a 0a a6 00 00 .........W.J.... +| 2720: 00 00 00 00 00 00 83 21 03 08 02 08 08 08 17 86 .......!........ +| 2736: 30 08 00 30 20 34 30 32 00 02 61 64 06 01 08 00 0..0 402..ad.... +| 2752: 02 04 00 01 01 6c 06 02 0c 00 02 04 00 01 01 6d .....l.........m +| 2768: 03 01 06 00 01 01 6e 03 08 00 00 91 01 75 03 05 ......n......u.. +| 2784: 03 00 00 02 63 69 03 06 02 00 01 01 6f 07 01 07 ....ci......o... +| 2800: 00 03 07 03 00 01 01 75 06 07 05 00 01 04 00 00 .......u........ +| 2816: 02 64 65 03 08 07 00 01 01 6f 0d 01 04 00 01 03 .de......o...... +| 2832: 09 00 03 05 00 01 03 00 01 01 75 03 05 02 00 00 ..........u..... +| 2848: 02 65 61 03 04 06 00 01 01 69 03 02 04 00 01 01 .ea......i...... +| 2864: 6c 03 01 09 00 01 01 6e 30 03 03 00 01 01 73 06 l......n0.....s. +| 2880: 05 0b 00 03 0b 00 01 01 74 03 02 09 00 01 01 75 ........t......u +| 2896: 03 06 04 00 01 01 78 09 03 09 00 01 05 00 03 02 ......x......... +| 2912: 00 00 02 66 75 03 06 05 00 00 02 69 64 03 08 0a ...fu......id... +| 2928: 00 01 01 6e 0a 02 06 00 03 06 04 00 03 03 00 01 ...n............ +| 2944: 01 70 03 01 03 00 01 01 72 03 05 04 00 00 02 6c .p......r......l +| 2960: 61 09 02 08 00 01 0b 00 05 0c 00 01 01 6f 03 01 a............o.. +| 2976: 02 00 00 02 6d 61 03 02 0b 00 01 01 69 03 03 05 ....ma......i... +| 2992: 00 01 01 6f 03 08 08 00 00 02 6e 69 03 04 02 00 ...o......ni.... +| 3008: 01 01 6f 06 03 08 00 04 06 00 01 01 75 03 06 06 ..o.........u... +| 3024: 00 00 02 6f 63 03 07 04 00 01 01 66 03 08 06 00 ...oc......f.... +| 3040: 00 02 70 61 03 06 07 00 01 01 72 03 07 07 00 00 ..pa......r..... +| 3056: 02 71 75 06 03 07 00 05 05 00 00 02 72 65 03 05 .qu.........re.. +| 3072: 07 00 00 02 73 65 03 02 02 00 01 01 69 06 01 05 ....se......i... +| 3088: 00 06 03 00 01 01 75 03 08 02 00 00 02 74 65 03 ......u......te. +| 3104: 02 05 00 00 02 75 6c 03 03 0a 00 01 01 74 09 02 .....ul......t.. +| 3120: 07 00 01 02 00 01 03 00 00 02 76 65 06 03 06 00 ..........ve.... +| 3136: 02 0a 00 01 01 6f 03 05 09 00 82 0a 02 08 02 08 .....o.......... +| 3152: 08 08 17 84 02 04 00 30 20 32 35 31 00 01 61 13 .......0 251..a. +| 3168: 01 06 04 00 01 0c 00 01 04 00 01 04 00 01 03 00 ................ +| 3184: 03 09 00 00 01 63 10 01 07 00 03 07 03 00 02 02 .....c.......... +| 3200: 00 01 05 00 01 04 00 00 01 64 11 01 04 00 01 03 .........d...... +| 3216: 09 00 03 02 05 00 01 03 00 02 07 00 00 01 65 1b ..............e. +| 3232: 01 09 00 01 04 07 00 01 03 00 80 00 15 03 00 01 ................ +| 3248: 0b 00 01 04 00 01 02 00 01 0b 00 00 01 66 03 06 .............f.. +| 3264: 05 00 00 01 69 0f 01 03 00 01 06 00 03 04 04 04 ....i........... +| 3280: 00 03 03 09 00 00 01 6c 0c 01 02 00 01 08 00 01 .......l........ +| 3296: 0b 00 05 0c 00 00 01 6d 09 02 0b 00 01 05 00 05 .......m........ +| 3312: 08 00 00 01 6e 0c 03 08 00 01 02 00 02 06 00 01 ....n........... +| 3328: 06 00 00 01 6f 06 07 04 00 01 06 00 00 01 70 06 ....o.........p. +| 3344: 06 07 00 01 07 00 00 01 71 06 03 07 00 05 05 00 ........q....... +| 3360: 00 01 72 03 05 07 00 00 01 73 0c 01 05 00 01 02 ..r......s...... +| 3376: 00 05 03 00 01 02 00 00 01 74 03 02 05 00 00 01 .........t...... +| 3392: 75 0a 02 07 00 01 02 0a 00 01 03 00 00 01 76 07 u.............v. +| 3408: 03 06 00 02 09 03 00 85 26 01 08 08 08 08 08 17 ........&....... +| 3424: 8a 3e 30 20 36 36 35 00 02 61 64 03 03 04 00 02 .>0 665..ad..... +| 3440: 08 69 70 69 73 63 69 6e 67 03 01 08 00 01 05 6c .ipiscing......l +| 3456: 69 71 75 61 03 02 0c 00 05 02 69 70 03 04 04 00 iqua......ip.... +| 3472: 01 03 6d 65 74 03 01 06 00 01 03 6e 69 6d 03 08 ..met......nim.. +| 3488: 09 00 01 03 75 74 65 03 05 03 00 00 06 63 69 6c ....ute......cil +| 3504: 6c 75 6d 03 06 02 00 01 06 6f 6d 6d 6f 64 6f 03 lum......ommodo. +| 3520: 04 07 00 02 09 6e 73 65 63 74 65 74 75 72 03 01 .....nsectetur.. +| 3536: 07 00 05 04 71 75 61 74 03 04 08 00 01 04 75 6c ....quat......ul +| 3552: 70 61 03 08 04 00 02 07 70 69 64 61 74 61 74 03 pa......pidatat. +| 3568: 07 05 00 00 08 64 65 73 65 72 75 6e 74 03 08 07 .....deserunt... +| 3584: 00 01 01 6f 03 02 03 00 02 03 6c 6f 72 06 01 04 ...o......lor... +| 3600: 00 40 05 00 05 01 65 06 02 0a 00 04 03 00 01 03 .@....e......... +| 3616: 75 69 73 03 05 02 00 00 02 65 61 03 04 06 00 01 uis......ea..... +| 3632: 06 69 75 73 6d 6f 64 03 02 04 00 01 03 6c 69 74 .iusmod......lit +| 3648: 03 01 09 00 01 03 6e 69 6d 03 03 03 00 01 03 73 ......nim......s +| 3664: 73 65 03 05 0b 00 02 01 74 03 08 0b 00 01 01 74 se......t......t +| 3680: 03 02 09 00 01 01 75 03 06 04 00 01 01 78 03 04 ......u......x.. +| 3696: 05 00 02 07 63 65 70 74 65 75 72 03 07 02 00 02 ....cepteur..... +| 3712: 0a 65 72 63 69 74 61 74 69 6f 6e 03 03 09 00 00 .ercitation..... +| 3728: 06 66 75 67 69 61 74 03 06 05 00 00 02 69 64 03 .fugiat......id. +| 3744: 08 0a 00 01 01 6e 07 05 06 04 00 03 03 00 02 08 .....n.......... +| 3760: 63 69 64 69 64 75 6e 74 03 02 06 00 01 04 70 73 cididunt......ps +| 3776: 75 6d 03 01 03 00 01 04 72 75 72 65 03 05 04 00 um......rure.... +| 3792: 00 06 6c 61 62 6f 72 65 03 02 08 00 05 02 69 73 ..labore......is +| 3808: 03 03 0b 00 05 02 75 6d 03 08 0c 00 01 04 6f 72 ......um......or +| 3824: 65 6d 03 01 02 00 00 05 6d 61 67 6e 61 03 02 0b em......magna... +| 3840: 00 01 04 69 6e 69 6d 03 03 05 00 01 05 6f 6c 6c ...inim......oll +| 3856: 69 74 03 08 08 00 00 04 6e 69 73 69 03 04 02 00 it......nisi.... +| 3872: 01 02 6f 6e 03 07 06 00 02 05 73 74 72 75 64 03 ..on......strud. +| 3888: 03 08 00 01 04 75 6c 6c 61 03 06 06 00 00 08 6f .....ulla......o +| 3904: 63 63 61 65 63 61 74 03 07 04 00 01 06 66 66 69 ccaecat......ffi +| 3920: 63 69 61 03 08 06 00 00 08 70 61 72 69 61 74 75 cia......pariatu +| 3936: 72 03 06 07 00 01 07 72 6f 69 64 65 6e 74 03 07 r......roident.. +| 3952: 07 00 00 03 71 75 69 03 08 05 00 03 01 73 03 03 ....qui......s.. +| 3968: 07 00 00 0d 72 65 70 72 65 68 65 6e 64 65 72 69 ....reprehenderi +| 3984: 74 03 05 07 00 00 03 73 65 64 03 02 02 00 01 03 t......sed...... +| 4000: 69 6e 74 03 07 03 00 02 01 74 03 01 05 00 01 03 int......t...... +| 4016: 75 6e 74 03 08 02 00 00 06 74 65 6d 70 6f 72 03 unt......tempor. +| 4032: 02 05 00 00 07 75 6c 6c 61 6d 63 6f 03 03 0a 00 .....ullamco.... +| 4048: 01 01 74 09 02 07 00 01 02 00 01 03 00 00 05 76 ..t............v +| 4064: 65 6c 69 74 03 05 0a 00 02 04 6e 69 61 6d 03 03 elit......niam.. +| 4080: 06 00 01 08 6f 6c 75 70 74 61 74 65 03 05 09 00 ....oluptate.... +| page 5 offset 16384 +| 0: 0a 00 00 00 03 0f eb 00 0f fb 0f f3 0f eb 00 00 ................ +| 4064: 00 00 00 00 00 00 00 00 00 00 00 07 04 02 08 01 ................ +| 4080: 08 00 03 07 04 02 08 01 04 00 02 04 04 08 08 09 ................ +| page 6 offset 20480 +| 0: 0d 00 00 00 08 0f d0 00 0f fa 0f f4 0f ee 0f e8 ................ +| 16: 0f e2 0f dc 0f d6 0f d0 00 00 00 00 00 00 00 00 ................ +| 4048: 04 08 03 00 0e 0b 04 07 03 00 0e 06 04 06 03 00 ................ +| 4064: 0e 06 04 05 03 00 0e 0a 04 04 03 00 0e 07 04 03 ................ +| 4080: 03 00 0e 0a 04 02 03 00 0e 0b 04 01 03 00 0e 08 ................ +| page 7 offset 24576 +| 0: 0d 00 00 00 01 0f f7 00 0f f7 00 00 00 00 00 00 ................ +| 4080: 00 00 00 00 00 00 00 07 00 03 00 14 08 45 b5 03 .............E.. +| end crash-7948058d822acb.db +}]} {} + +do_catchsql_test 8.1 { + SELECT matchinfo(t1,'x') FROM t1 WHERE t1 MATCH 'e*'; +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +reset_db +do_test 9.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 28672 pagesize 4096 filename crash-e1c6cbfdf643e9.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07 .....@ ........ +| 32: 00 00 00 02 00 00 00 01 00 00 00 07 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ +| 96: 00 00 00 00 0d 0e b1 00 06 0d a4 00 0f 8d 0f 21 ...............! +| 112: 0e b9 0d c8 0e 7e 0d a4 0d a4 00 00 00 00 00 00 .....~.......... +| 3488: 00 00 00 00 22 07 06 17 11 11 01 31 74 61 62 6c ...........1tabl +| 3504: 65 74 32 74 32 07 43 52 45 41 54 45 20 54 41 42 et2t2.CREATE TAB +| 3520: 4c 45 20 74 32 28 78 29 81 33 05 07 17 1f 1f 01 LE t2(x).3...... +| 3536: 82 35 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72 .5tablet1_segdir +| 3552: 74 31 5f 73 65 67 64 69 72 05 43 52 45 41 54 45 t1_segdir.CREATE +| 3568: 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69 TABLE 't1_segdi +| 3584: 72 27 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52 r'(level INTEGER +| 3600: 2c 69 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61 ,idx INTEGER,sta +| 3616: 72 74 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52 rt_block INTEGER +| 3632: 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 ,leaves_end_bloc +| 3648: 6b 20 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c k INTEGER,end_bl +| 3664: 6f 63 6b 20 49 4e 54 45 47 45 52 2c 72 6f 6f 74 ock INTEGER,root +| 3680: 20 42 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45 BLOB,PRIMARY KE +| 3696: 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 06 Y(level, idx))1. +| 3712: 06 17 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74 ..E...indexsqlit +| 3728: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73 e_autoindex_t1_s +| 3744: 65 67 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72 egdir_1t1_segdir +| 3760: 06 0f c7 00 08 00 00 00 00 66 04 07 17 23 23 01 .........f...##. +| 3776: 81 13 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e ..tablet1_segmen +| 3792: 74 73 74 31 5f 73 65 67 6d 65 6e 74 73 04 43 52 tst1_segments.CR +| 3808: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 EATE TABLE 't1_s +| 3824: 65 67 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64 egments'(blockid +| 3840: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 INTEGER PRIMARY +| 3856: 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 KEY, block BLOB +| 3872: 29 6a 03 07 17 21 21 01 81 1f 74 61 62 6c 65 74 )j...!!...tablet +| 3888: 31 5f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 1_contentt1_cont +| 3904: 65 6e 74 03 43 52 45 41 54 45 20 54 41 42 4c 45 ent.CREATE TABLE +| 3920: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f 't1_content'(do +| 3936: 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d cid INTEGER PRIM +| 3952: 41 52 59 20 4b 45 59 2c 20 27 63 30 61 27 2c 20 ARY KEY, 'c0a', +| 3968: 27 63 31 62 27 2c 20 27 63 32 63 27 29 38 02 06 'c1b', 'c2c')8.. +| 3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52 ...._tablet1t1CR +| 4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB +| 4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33 LE t1 USING fts3 +| 4032: 28 61 2c 62 2c 63 29 00 00 00 39 00 00 00 00 00 (a,b,c)...9..... +| page 3 offset 8192 +| 0: 0d 00 00 00 25 0b 48 00 0f d8 0f af 0f 86 0f 74 ....%.H........t +| 16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5 .a.N./.......... +| 32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 0d ef 0d d5 ...t.[.@.$...... +| 48: 0d bb 0d a0 0d 84 0d 68 0d 4f 0d 35 0d 1b 0c fb .......h.O.5.... +| 64: 0c da 0c b9 0c 99 0c 78 0c 57 0c 3e 0c 24 0c 0a .......x.W.>.$.. +| 80: 0b 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .H.............. +| 2880: 00 00 00 00 00 00 00 00 81 3f 25 06 00 82 7f 00 .........?%..... +| 2896: 00 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e .COMPILER=gcc-5. +| 2912: 34 2e 30 20 32 30 31 36 30 36 30 39 20 44 45 42 4.0 20160609 DEB +| 2928: 55 47 20 45 4e 41 42 4c 45 20 44 42 53 54 41 54 UG ENABLE DBSTAT +| 2944: 20 56 54 41 42 20 45 4e 41 42 4c 45 20 46 54 53 VTAB ENABLE FTS +| 2960: 34 20 45 4e 41 42 4c 45 20 46 54 53 35 20 45 4e 4 ENABLE FTS5 EN +| 2976: 41 42 4c 45 20 47 45 4f 50 4f 4c 59 20 45 4e 41 ABLE GEOPOLY ENA +| 2992: 42 4c 45 20 4a 53 4f 4e 31 20 45 4e 41 42 4c 45 BLE JSON1 ENABLE +| 3008: 20 4d 45 4d 53 59 53 35 20 45 4e 41 42 4c 45 20 MEMSYS5 ENABLE +| 3024: 52 54 52 45 45 20 4d 41 58 20 4d 45 4d 4f 52 59 RTREE MAX MEMORY +| 3040: 3d 35 30 30 30 30 30 30 30 20 4f 4d 49 54 20 4c =50000000 OMIT L +| 3056: 4f 41 44 20 45 58 54 45 4e 53 49 4f 4e 20 54 48 OAD EXTENSION TH +| 3072: 52 45 41 44 53 41 46 45 3d 30 18 24 05 00 25 0f READSAFE=0.$..%. +| 3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49 .THREADSAFE=0XBI +| 3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41 NARY.#..%..THREA +| 3120: 44 53 41 46 45 3d 30 58 4e 4f 43 41 53 45 17 22 DSAFE=0XNOCASE.. +| 3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 45 3d ..%..THREADSAFE= +| 3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d 0XRTRIM.!..3..OM +| 3168: 49 54 20 4c 4f 41 44 20 35 58 54 45 4e 53 49 4f IT LOAD 5XTENSIO +| 3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f NXBINARY. ..3..O +| 3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 MIT LOAD EXTENSI +| 3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17 ONXNOCASE....3.. +| 3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 OMIT LOAD EXTENS +| 3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f 19 IONXRTRIM....3.. +| 3264: 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 30 MAX MEMORY=50000 +| 3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f 000XBINARY....3. +| 3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 .MAX MEMORY=5000 +| 3312: 30 30 30 30 58 4e 4f 43 41 53 45 1e 1c 05 00 33 0000XNOCASE....3 +| 3328: 0f 17 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 ..MAX MEMORY=500 +| 3344: 30 30 30 30 30 58 52 54 52 49 4d 18 1b 05 00 25 00000XRTRIM....% +| 3360: 0f 19 45 4e 41 42 4c 45 20 52 54 52 45 45 58 42 ..ENABLE RTREEXB +| 3376: 49 4e 41 52 59 18 1a 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3392: 4c 45 20 52 54 52 45 45 58 4e 4f 43 41 53 45 17 LE RTREEXNOCASE. +| 3408: 19 05 00 25 0f 17 45 4e 41 42 4c 45 20 52 54 52 ...%..ENABLE RTR +| 3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45 EEXRTRIM....)..E +| 3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 58 42 49 NABLE MEMSYS5XBI +| 3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4e 41 42 4c NARY....)..ENABL +| 3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 53 45 E MEMSYS5XNOCASE +| 3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 4d 45 ....)..ENABLE ME +| 3504: 4d 53 59 53 35 58 52 54 52 49 4d 18 15 05 00 25 MSYS5XRTRIM....% +| 3520: 0f 19 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 58 42 ..ENABLE JSON1XB +| 3536: 49 4e 41 52 59 18 14 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3552: 4c 45 20 4a 53 4f 4e 31 58 4e 4f 43 41 53 45 17 LE JSON1XNOCASE. +| 3568: 13 05 00 25 1f 17 45 4e 41 42 4c 45 20 4a 53 4f ...%..ENABLE JSO +| 3584: 4e 31 58 52 54 52 49 4d 1a 12 05 00 29 0f 19 45 N1XRTRIM....)..E +| 3600: 4e 41 42 4c 45 20 47 45 4f 50 4f 4c 59 58 42 49 NABLE GEOPOLYXBI +| 3616: 4e 41 52 59 1a 11 05 00 29 0f 19 45 4e 41 42 4c NARY....)..ENABL +| 3632: 45 20 47 45 4f 50 4f 4c 59 58 4e 4f 43 41 53 45 E GEOPOLYXNOCASE +| 3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 45 ....)..ENABLE GE +| 3664: 4f 50 4f 4c 59 58 52 54 52 49 4d 17 0f 05 00 23 OPOLYXRTRIM....# +| 3680: 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 58 42 49 ..ENABLE FTS5XBI +| 3696: 4e 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 4c NARY....#..ENABL +| 3712: 45 20 46 54 53 35 58 4e 4f 43 41 53 45 16 0d 05 E FTS5XNOCASE... +| 3728: 00 23 0f 17 44 4e 41 42 4c 45 20 46 54 53 35 58 .#..DNABLE FTS5X +| 3744: 52 54 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42 RTRIM....#..ENAB +| 3760: 4c 45 20 46 54 53 34 58 42 49 4e 41 52 59 17 0b LE FTS4XBINARY.. +| 3776: 05 00 23 0f 19 45 4e 41 42 4c 45 20 46 54 53 34 ..#..ENABLE FTS4 +| 3792: 58 4e 4f 43 41 53 45 16 0a 05 00 23 0f 17 45 4e XNOCASE....#..EN +| 3808: 41 42 4c 45 20 46 54 53 34 58 52 54 52 49 4d 1e ABLE FTS4XRTRIM. +| 3824: 09 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 52 59 1e TAT VTABXBINARY. +| 3856: 08 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3872: 54 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d TAT VTABXNOCASE. +| 3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3904: 54 41 54 20 56 54 41 42 58 52 54 52 49 4d 11 06 TAT VTABXRTRIM.. +| 3920: 05 00 17 0f 19 44 45 42 55 47 58 42 49 4e 41 52 .....DEBUGXBINAR +| 3936: 59 11 05 05 00 17 0f 19 44 45 42 55 47 58 4e 4f Y.......DEBUGXNO +| 3952: 43 41 53 45 10 04 05 00 17 0f 17 44 45 42 55 47 CASE.......DEBUG +| 3968: 58 52 54 52 49 4d 27 03 05 00 43 0f 19 43 4f 4d XRTRIM'...C..COM +| 3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20 PILER=gcc-5.4.0 +| 4000: 32 30 31 36 30 36 30 39 58 42 49 4e 41 52 59 27 20160609XBINARY' +| 4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67 ...C..COMPILER=g +| 4032: 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36 30 cc-5.4.0 2016060 +| 4048: 39 58 4e 4f 43 41 53 45 26 01 05 00 43 0f 17 43 9XNOCASE&...C..C +| 4064: 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e OMPILER=gcc-5.4. +| 4080: 30 20 32 30 31 36 30 36 30 39 58 52 54 52 49 4d 0 20160609XRTRIM +| page 4 offset 12288 +| 0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................ +| page 5 offset 16384 +| 0: 0d 00 00 00 02 0b a0 00 0c ad 0b a0 00 00 00 00 ................ +| 2976: 82 0a 02 08 08 09 08 08 17 84 06 30 20 32 35 33 ...........0 253 +| 2992: 00 01 30 04 25 06 1b 00 00 08 32 30 31 36 30 36 ..0.%.....201606 +| 3008: 30 39 03 25 07 00 00 01 34 03 25 05 00 00 01 35 09.%....4.%....5 +| 3024: 03 25 04 00 01 07 30 30 30 30 30 30 30 03 25 1a .%....0000000.%. +| 3040: 00 00 08 63 6f 6d 70 69 6c 65 72 03 25 02 00 00 ...compiler.%... +| 3056: 06 64 62 73 74 61 74 03 25 0a 00 01 04 65 62 75 .dbstat.%....ebu +| 3072: 67 03 25 08 00 00 06 65 6e 61 62 6c 65 09 25 09 g.%....enable.%. +| 3088: 05 04 04 04 04 04 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3104: 6e 03 25 1d 00 00 04 66 74 73 34 03 25 0d 00 03 n.%....fts4.%... +| 3120: 01 35 03 25 0f 00 00 03 67 63 63 03 25 03 00 01 .5.%....gcc.%... +| 3136: 06 65 6f 70 6f 6c 79 03 25 11 00 00 05 6a 73 6f .eopoly.%....jso +| 3152: 6e 31 03 25 13 00 00 04 6c 6f 61 64 03 25 1c 00 n1.%....load.%.. +| 3168: 00 03 6d 61 78 03 25 18 00 01 05 65 6d 6f 72 79 ..max.%....emory +| 3184: 03 25 19 00 03 04 73 79 73 35 03 25 15 00 00 04 .%....sys5.%.... +| 3200: 6f 6d 69 74 03 25 1b 00 00 05 72 74 72 65 65 03 omit.%....rtree. +| 3216: 25 17 00 00 0a 74 68 72 65 61 64 73 61 66 65 03 %....threadsafe. +| 3232: 25 1e 00 00 04 76 74 61 62 03 25 0b 00 86 50 01 %....vtab.%...P. +| 3248: 08 08 08 08 08 17 8d 12 30 20 38 33 35 00 01 30 ........0 835..0 +| 3264: 12 01 06 00 01 06 00 01 06 00 1f 03 00 01 03 00 ................ +| 3280: 01 03 00 00 08 32 30 31 36 30 36 30 39 09 01 07 .....20160609... +| 3296: 00 01 07 00 01 07 00 00 01 34 09 01 05 00 01 05 .........4...... +| 3312: 00 01 05 00 00 01 35 09 01 04 00 01 04 00 01 04 ......5......... +| 3328: 00 01 07 30 30 30 30 30 30 30 09 1c 04 00 01 04 ...0000000...... +| 3344: 00 01 04 00 00 06 62 69 6e 61 72 79 3c 03 01 02 ......binary<... +| 3360: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3376: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3392: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 ................ +| 3408: 01 02 02 00 03 01 02 02 00 00 08 63 6f 6d 70 69 ...........compi +| 3424: 6c 65 72 09 01 02 00 01 02 00 01 02 00 00 06 64 ler............d +| 3440: 62 73 74 61 74 09 07 03 00 01 03 00 01 03 00 01 bstat........... +| 3456: 04 65 62 75 67 09 04 02 00 01 02 00 01 02 00 00 .ebug........... +| 3472: 06 65 6e 61 62 6c 65 3f 07 02 00 01 02 00 01 02 .enable?........ +| 3488: 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00 ................ +| 3504: 01 02 00 01 02 00 01 02 00 01 02 00 01 01 00 01 ................ +| 3520: 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 ................ +| 3536: 00 01 02 00 01 02 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3552: 6e 09 1f 04 00 01 04 00 01 04 00 00 04 66 74 73 n............fts +| 3568: 34 09 0a 03 00 01 03 00 01 03 00 03 01 35 09 0d 4............5.. +| 3584: 03 00 01 03 00 01 03 00 00 03 67 63 63 09 01 03 ..........gcc... +| 3600: 00 01 03 00 01 03 00 01 06 65 6f 70 6f 6c 79 09 .........eopoly. +| 3616: 10 03 00 01 03 00 01 03 00 00 05 6a 73 6f 6e 31 ...........json1 +| 3632: 09 13 03 00 01 03 00 01 03 00 00 04 6c 6f 61 64 ............load +| 3648: 09 1f 03 00 01 03 00 01 03 00 00 03 6d 61 78 09 ............max. +| 3664: 1c 02 00 01 02 00 01 02 00 01 05 65 6d 6f 72 79 ...........emory +| 3680: 09 1c 03 00 01 03 00 01 03 00 03 04 73 79 73 35 ............sys5 +| 3696: 09 16 03 00 01 03 00 01 03 00 00 06 6e 6f 63 61 ............noca +| 3712: 73 65 3c 02 01 02 02 00 03 01 02 02 00 03 01 02 se<............. +| 3728: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3744: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3760: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 00 ................ +| 3776: 04 6f 6d 69 74 09 1f 02 00 01 02 00 01 02 00 00 .omit........... +| 3792: 05 72 74 72 65 65 09 19 03 00 01 03 00 01 03 00 .rtree.......... +| 3808: 03 02 69 6d 3c 01 01 02 02 00 03 01 02 02 00 03 ..im<........... +| 3824: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 ................ +| 3840: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 ................ +| 3856: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3872: 00 00 0a 74 68 72 65 61 64 73 61 66 65 09 22 02 ...threadsafe... +| 3888: 00 01 02 00 0a 12 00 00 04 76 74 61 62 09 07 04 .........vtab... +| 3904: 00 01 04 00 01 04 00 00 01 78 b4 01 01 01 01 02 .........x...... +| 3920: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 3936: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 3952: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 3968: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 3984: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4000: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 4016: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 4032: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 4048: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 4064: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4080: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| page 6 offset 20480 +| 0: 0a 00 00 00 02 0f f5 00 0f fb 0f f5 00 00 00 00 ................ +| 4080: 00 00 00 00 00 05 04 08 09 01 02 04 04 08 08 09 ................ +| page 7 offset 24576 +| 0: 0d 00 00 00 05 0f b8 00 0f f4 0f e9 0f d6 0f c7 ................ +| 16: 0f b8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 4016: 00 00 00 00 00 00 00 00 0d 05 02 23 61 75 74 6f ...........#auto +| 4032: 6d 65 72 67 65 3d 35 0d 04 02 23 6d 65 72 67 65 merge=5...#merge +| 4048: 3d 31 30 30 2c 38 11 03 02 2b 69 6e 74 65 67 72 =100,8...+integr +| 4064: 69 74 79 2d 63 68 65 63 6b 09 02 02 1b 72 65 62 ity-check....reb +| 4080: 75 69 6c 64 0a 01 02 1d 6f 70 74 69 6d 69 7a 65 uild....optimize +| end crash-e1c6cbfdf643e9.db +}]} {} + +do_execsql_test 9.1 { + SELECT count(*) FROM t1 WHERE t1 MATCH '"json1 enable"'; +} {1} + +#------------------------------------------------------------------------- +reset_db +do_test 10.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 28672 pagesize 4096 filename crash-c3a971f0061039.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07 .....@ ........ +| 32: 00 00 00 02 00 00 00 01 00 00 00 07 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ +| 96: 00 00 00 00 0d 0e b1 00 06 0d a4 00 0f 8d 0f 21 ...............! +| 112: 0e b9 0d c8 0e 7e 0d a4 0d a4 00 00 00 00 00 00 .....~.......... +| 3488: 00 00 00 00 22 07 06 17 11 11 01 31 74 61 62 6c ...........1tabl +| 3504: 65 74 32 74 32 07 43 52 45 41 54 45 20 54 41 42 et2t2.CREATE TAB +| 3520: 4c 45 20 74 32 28 78 29 81 33 05 07 17 1f 1f 01 LE t2(x).3...... +| 3536: 82 35 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72 .5tablet1_segdir +| 3552: 74 31 5f 73 65 67 64 69 72 05 43 52 45 41 54 45 t1_segdir.CREATE +| 3568: 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69 TABLE 't1_segdi +| 3584: 72 27 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52 r'(level INTEGER +| 3600: 2c 69 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61 ,idx INTEGER,sta +| 3616: 72 74 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52 rt_block INTEGER +| 3632: 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 ,leaves_end_bloc +| 3648: 6b 20 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c k INTEGER,end_bl +| 3664: 6f 63 6b 20 49 4e 54 45 47 45 52 2c 72 6f 6f 74 ock INTEGER,root +| 3680: 20 42 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45 BLOB,PRIMARY KE +| 3696: 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 06 Y(level, idx))1. +| 3712: 06 17 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74 ..E...indexsqlit +| 3728: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73 e_autoindex_t1_s +| 3744: 65 67 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72 egdir_1t1_segdir +| 3760: 06 0f c7 00 08 00 00 00 00 66 04 07 17 23 23 01 .........f...##. +| 3776: 81 13 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e ..tablet1_segmen +| 3792: 74 73 74 31 5f 73 65 67 6d 65 6e 74 73 04 43 52 tst1_segments.CR +| 3808: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 EATE TABLE 't1_s +| 3824: 65 67 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64 egments'(blockid +| 3840: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 INTEGER PRIMARY +| 3856: 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 KEY, block BLOB +| 3872: 29 6a 03 07 17 21 21 01 81 1f 74 61 62 6c 65 74 )j...!!...tablet +| 3888: 31 5f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 1_contentt1_cont +| 3904: 65 6e 74 03 43 52 45 41 54 45 20 54 41 42 4c 45 ent.CREATE TABLE +| 3920: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f 't1_content'(do +| 3936: 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d cid INTEGER PRIM +| 3952: 41 52 59 30 4b 45 59 2c 20 27 63 30 61 27 2c 20 ARY0KEY, 'c0a', +| 3968: 27 63 31 62 27 2c 20 27 63 32 63 27 29 38 02 06 'c1b', 'c2c')8.. +| 3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52 ...._tablet1t1CR +| 4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB +| 4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33 LE t1 USING fts3 +| 4032: 28 61 2c 62 2c 63 29 00 00 00 39 00 00 00 00 00 (a,b,c)...9..... +| page 3 offset 8192 +| 0: 0d 00 00 00 25 0b 48 00 0f d8 0f af 0f 86 0f 74 ....%.H........t +| 16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5 .a.N./.......... +| 32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 0d ef 0d d5 ...t.[.@.$...... +| 48: 0d bb 0d a0 0d 84 0d 68 0d 4f 0d 35 0d 1b 0c fb .......h.O.5.... +| 64: 0c da 0c b9 0c 99 0c 78 0c 57 0c 3e 0c 24 0c 0a .......x.W.>.$.. +| 80: 0b 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .H.............. +| 2880: 00 00 00 00 00 00 00 00 81 3f 25 06 00 82 7f 00 .........?%..... +| 2896: 00 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e .COMPILER=gcc-5. +| 2912: 34 2e 30 20 32 30 31 36 30 36 30 39 20 44 45 42 4.0 20160609 DEB +| 2928: 55 47 20 45 4e 41 42 4c 45 20 44 42 53 54 41 54 UG ENABLE DBSTAT +| 2944: 20 56 54 41 42 20 45 4e 41 42 4c 45 20 46 54 53 VTAB ENABLE FTS +| 2960: 34 20 45 4e 41 42 4c 45 20 46 54 53 35 20 45 4e 4 ENABLE FTS5 EN +| 2976: 41 42 4c 45 20 47 45 4f 50 4f 4c 59 20 45 4e 41 ABLE GEOPOLY ENA +| 2992: 42 4c 45 20 4a 53 4f 4e 31 20 45 4e 41 42 4c 45 BLE JSON1 ENABLE +| 3008: 20 4d 45 4d 53 59 53 35 20 45 4e 41 42 4c 45 1f MEMSYS5 ENABLE. +| 3024: 52 54 52 45 45 20 4d 41 58 20 4d 45 4d 4f 52 59 RTREE MAX MEMORY +| 3040: 3d 35 30 30 30 30 30 30 30 20 4f 4d 49 54 20 4c =50000000 OMIT L +| 3056: 4f 41 44 20 45 58 54 45 4e 53 49 4f 4e 20 54 48 OAD EXTENSION TH +| 3072: 52 45 41 44 53 41 46 45 3d 30 18 24 05 00 25 0f READSAFE=0.$..%. +| 3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49 .THREADSAFE=0XBI +| 3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41 NARY.#..%..THREA +| 3120: 44 53 41 46 45 3d 30 58 4e 4f 43 41 53 45 17 22 DSAFE=0XNOCASE.. +| 3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 45 3d ..%..THREADSAFE= +| 3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d 0XRTRIM.!..3..OM +| 3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 4f IT LOAD EXTENSIO +| 3184: 4e 58 43 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f NXCINARY. ..3..O +| 3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 MIT LOAD EXTENSI +| 3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17 ONXNOCASE....3.. +| 3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 OMIT LOAD EXTENS +| 3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f 19 IONXRTRIM....3.. +| 3264: 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 30 MAX MEMORY=50000 +| 3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f 000XBINARY....3. +| 3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 .MAX MEMORY=5000 +| 3312: 30 30 30 30 58 4e 4f 43 41 53 45 1e 1c 05 00 33 0000XNOCASE....3 +| 3328: 0f 17 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 ..MAX MEMORY=500 +| 3344: 30 30 30 30 30 58 52 54 52 49 4d 18 1b 05 00 25 00000XRTRIM....% +| 3360: 0f 19 45 4e 41 42 4c 45 20 52 54 52 45 45 58 42 ..ENABLE RTREEXB +| 3376: 49 4e 41 52 59 18 1a 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3392: 4c 45 20 52 54 52 45 45 58 4e 4f 43 41 53 45 17 LE RTREEXNOCASE. +| 3408: 19 05 00 25 0f 17 45 4e 41 42 4c 45 20 52 54 52 ...%..ENABLE RTR +| 3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45 EEXRTRIM....)..E +| 3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 58 42 49 NABLE MEMSYS5XBI +| 3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4e 41 42 4c NARY....)..ENABL +| 3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 53 45 E MEMSYS5XNOCASE +| 3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 4d 45 ....)..ENABLE ME +| 3504: 4d 53 59 53 35 58 52 54 52 49 4d 18 15 09 00 25 MSYS5XRTRIM....% +| 3520: 0f 19 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 58 42 ..ENABLE JSON1XB +| 3536: 49 4e 41 52 59 18 14 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3552: 4c 45 20 4a 53 4f 4e 31 58 4e 4f 43 41 53 45 17 LE JSON1XNOCASE. +| 3568: 13 05 00 25 0f 17 45 4e 41 42 4c 45 20 4a 53 4f ...%..ENABLE JSO +| 3584: 4e 31 58 52 54 52 49 4d 1a 12 05 00 29 0f 19 45 N1XRTRIM....)..E +| 3600: 4e 41 42 4c 45 20 47 45 4f 50 4f 4c 59 58 42 49 NABLE GEOPOLYXBI +| 3616: 4e 41 52 59 1a 11 05 00 29 0f 19 45 4e 41 42 4c NARY....)..ENABL +| 3632: 45 20 47 45 4f 50 4f 4c 59 58 4e 4f 43 41 53 45 E GEOPOLYXNOCASE +| 3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 46 20 47 45 ....)..ENABLF GE +| 3664: 4f 50 4f 4c 59 58 52 54 52 49 4d 17 0f 05 00 23 OPOLYXRTRIM....# +| 3680: 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 58 42 49 ..ENABLE FTS5XBI +| 3696: 4e 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 4c NARY....#..ENABL +| 3712: 45 20 46 54 53 35 58 4e 4f 43 41 53 45 16 0d 05 E FTS5XNOCASE... +| 3728: 00 23 0f 17 45 4e 41 42 4c 45 20 46 54 53 35 58 .#..ENABLE FTS5X +| 3744: 52 54 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42 RTRIM....#..ENAB +| 3760: 4c 45 20 46 54 53 34 58 42 49 4e 41 52 59 17 0b LE FTS4XBINARY.. +| 3776: 05 00 23 0f 19 45 4e 41 42 4c 45 20 46 54 53 34 ..#..ENABLE FTS4 +| 3792: 58 4e 4f 43 41 53 45 16 0a 05 00 23 0f 17 45 4e XNOCASE....#..EN +| 3808: 41 42 4c 45 20 46 54 53 34 58 52 54 52 49 4d 1e ABLE FTS4XRTRIM. +| 3824: 09 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 52 59 1e TAT VTABXBINARY. +| 3856: 08 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3872: 54 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d TAT VTABXNOCASE. +| 3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3904: 54 41 54 20 56 54 41 42 58 52 54 52 49 4d 11 06 TAT VTABXRTRIM.. +| 3920: 05 00 17 0f 19 44 45 42 55 47 58 42 49 4e 41 52 .....DEBUGXBINAR +| 3936: 59 11 05 05 00 17 0f 19 44 45 42 55 47 58 4e 4f Y.......DEBUGXNO +| 3952: 43 41 53 45 10 04 05 00 17 0f 17 44 45 42 55 47 CASE.......DEBUG +| 3968: 58 52 54 52 49 4d 27 03 05 00 43 0f 19 43 4f 4d XRTRIM'...C..COM +| 3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20 PILER=gcc-5.4.0 +| 4000: 32 30 31 36 30 36 30 39 58 42 49 4e 41 52 59 27 20160609XBINARY' +| 4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67 ...C..COMPILER=g +| 4032: 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36 30 cc-5.4.0 2016060 +| 4048: 39 58 4e 4f 43 41 53 45 26 01 05 00 43 0f 17 43 9XNOCASE&...C..C +| 4064: 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e OMPILER=gcc-5.4. +| 4080: 30 20 32 30 31 36 30 36 30 39 58 52 54 52 49 4d 0 20160609XRTRIM +| page 4 offset 12288 +| 0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................ +| page 5 offset 16384 +| 0: 0d 00 00 00 02 0b a0 00 0c ad 0b a0 00 00 00 00 ................ +| 2976: 82 0a 02 08 08 09 08 08 17 84 06 30 20 32 35 33 ...........0 253 +| 2992: 00 01 30 04 25 06 1b 00 00 08 32 30 31 36 30 36 ..0.%.....201606 +| 3008: 30 39 03 25 07 00 00 01 34 03 25 05 00 00 01 35 09.%....4.%....5 +| 3024: 03 25 04 00 01 07 30 30 30 30 30 30 30 03 25 1a .%....0000000.%. +| 3040: 00 00 08 63 6f 6d 70 69 6c 65 72 03 25 02 00 00 ...compiler.%... +| 3056: 06 64 62 73 74 61 74 03 25 0a 00 01 04 65 62 75 .dbstat.%....ebu +| 3072: 67 03 25 08 00 00 06 65 6e 61 62 6c 65 09 25 09 g.%....enable.%. +| 3088: 05 04 04 04 04 04 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3104: 6e 03 25 1d 00 00 04 66 74 73 34 03 25 0d 00 03 n.%....fts4.%... +| 3120: 01 35 03 25 0f 00 00 03 67 63 63 03 25 03 00 01 .5.%....gcc.%... +| 3136: 06 65 6f 70 6f 6c 79 03 25 11 00 00 05 6a 73 6f .eopoly.%....jso +| 3152: 6e 31 03 25 13 00 00 04 6c 6f 61 64 03 25 1c 00 n1.%....load.%.. +| 3168: 00 03 6d 61 78 03 25 18 00 01 05 65 6d 6f 72 79 ..max.%....emory +| 3184: 03 25 19 00 03 04 73 79 73 35 03 25 15 00 00 04 .%....sys5.%.... +| 3200: 6f 6d 69 74 03 25 1b 00 00 05 72 74 72 65 65 03 omit.%....rtree. +| 3216: 25 17 00 00 0a 74 68 72 65 61 64 73 61 66 65 03 %....threadsafe. +| 3232: 25 1e 00 00 04 76 74 61 62 03 25 0b 00 86 50 01 %....vtab.%...P. +| 3248: 08 08 08 08 09 17 8d 12 30 20 38 33 35 00 01 30 ........0 835..0 +| 3264: 12 01 06 00 01 06 00 01 06 00 1f 03 00 01 03 00 ................ +| 3280: 01 03 00 00 08 32 30 31 36 30 36 30 39 09 01 07 .....20160609... +| 3296: 00 01 07 00 01 07 00 00 01 34 09 01 05 00 01 05 .........4...... +| 3312: 00 01 05 00 00 01 35 09 01 04 00 01 04 00 01 04 ......5......... +| 3328: 00 01 07 30 30 30 30 30 30 30 09 1c 04 00 01 04 ...0000000...... +| 3344: 00 01 04 00 00 06 62 69 6e 61 72 79 3c 03 01 02 ......binary<... +| 3360: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3376: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3392: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 ................ +| 3408: 01 02 02 00 03 01 02 02 00 00 08 63 6f 6d 70 69 ...........compi +| 3424: 6c 65 72 09 01 02 00 01 02 00 01 02 00 00 06 64 ler............d +| 3440: 62 73 74 61 74 09 07 03 00 01 03 00 01 03 00 01 bstat........... +| 3456: 04 65 62 75 67 09 04 02 00 01 02 00 01 02 00 00 .ebug........... +| 3472: 06 65 6e 61 62 6c 65 3f 07 02 00 01 02 00 01 02 .enable?........ +| 3488: 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00 ................ +| 3504: 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 ................ +| 3520: 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 ................ +| 3536: 00 01 02 00 01 02 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3552: 6e 09 1f 04 00 01 04 00 01 04 00 00 04 66 74 73 n............fts +| 3568: 34 09 0a 03 00 01 03 00 01 03 00 03 01 35 09 0d 4............5.. +| 3584: 03 00 01 03 00 01 03 00 00 03 67 63 63 09 01 03 ..........gcc... +| 3600: 00 01 03 00 01 03 00 01 06 65 6f 70 6f 6c 79 09 .........eopoly. +| 3616: 10 03 00 01 03 00 01 03 00 00 05 6a 73 6f 6e 31 ...........json1 +| 3632: 09 13 03 00 01 03 00 01 03 00 00 04 6c 6f 61 64 ............load +| 3648: 09 1f 03 00 01 03 00 01 03 00 00 03 6d 61 78 09 ............max. +| 3664: 1c 02 00 01 02 00 01 02 00 01 05 65 6d 6f 72 79 ...........emory +| 3680: 09 1c 03 00 01 03 00 01 03 00 03 04 73 79 73 35 ............sys5 +| 3696: 09 16 03 00 01 03 00 01 03 00 00 06 6e 6f 63 61 ............noca +| 3712: 73 65 3c 02 01 02 02 00 03 01 02 02 00 03 01 02 se<............. +| 3728: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3744: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3760: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 00 ................ +| 3776: 04 6f 6d 69 74 09 1f 02 00 01 02 00 01 02 00 00 .omit........... +| 3792: 05 72 74 72 65 65 09 19 03 00 01 03 00 01 03 00 .rtree.......... +| 3808: 03 02 69 6d 3c 01 01 02 02 00 03 01 02 02 00 03 ..im<........... +| 3824: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 ................ +| 3840: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 ................ +| 3856: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3872: 00 00 0a 74 68 72 65 61 64 73 61 66 65 09 22 02 ...threadsafe... +| 3888: 00 01 02 00 02 02 00 00 04 76 74 61 62 09 07 04 .........vtab... +| 3904: 00 01 04 00 01 04 00 00 01 78 b4 01 01 01 01 02 .........x...... +| 3920: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 3936: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 3952: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 3968: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 3984: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4000: 10 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 4016: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 4032: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 4048: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 4064: 02 00 01 01 02 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4080: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| page 6 offset 20480 +| 0: 0a 00 00 00 02 0f f5 00 0f fb 0f f5 00 00 00 00 ................ +| 4080: 00 00 00 00 00 05 04 08 09 01 02 04 04 08 08 09 ................ +| page 7 offset 24576 +| 0: 0d 00 00 00 05 0f b8 00 0f f4 0f e9 0f d6 0f c7 ................ +| 16: 0f b8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 4016: 00 00 00 00 00 00 00 00 0d 05 02 23 61 75 74 6f ...........#auto +| 4032: 6d 65 72 67 65 3d 35 0d 04 02 23 6d 65 72 67 65 merge=5...#merge +| 4048: 3d 31 30 30 2c 38 11 03 02 2b 69 6e 74 65 67 72 =100,8...+integr +| 4064: 69 74 79 2d 63 68 65 63 6b 09 02 02 1b 72 65 62 ity-check....reb +| 4080: 75 69 6c 64 0a 01 02 1d 6f 70 74 69 6d 69 7a 65 uild....optimize +| end crash-c3a971f0061039.db +}]} {} + +do_catchsql_test 10.1 { + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100) + INSERT OR IGNORE INTO t1(a,c) SELECT x,null FROM c + UNION ALL SELECT 180-x,printf('[%,d]',x*-5844627) FROM c; +} {0 {}} + +do_catchsql_test 10.3 { + INSERT INTO t1(t1) VALUES('optimize'); +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +reset_db +do_test 11.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 28672 pagesize 4096 filename crash-843cb8447eaf14.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07 .....@ ........ +| 32: 00 00 00 02 00 00 00 01 00 00 00 07 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ +| 96: 00 00 00 00 0d 0e b1 00 06 0d a4 00 0f 8d 0f 21 ...............! +| 112: 0e b9 0d c8 0e 7e 0d a4 0d a4 00 00 00 00 00 00 .....~.......... +| 3488: 00 00 00 00 22 07 06 17 11 11 01 31 74 61 62 6c ...........1tabl +| 3504: 65 74 32 74 32 07 43 52 45 41 54 45 20 54 41 42 et2t2.CREATE TAB +| 3520: 4c 45 20 74 32 28 78 29 81 33 05 07 17 1f 1f 01 LE t2(x).3...... +| 3536: 82 35 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72 .5tablet1_segdir +| 3552: 74 31 5f 73 65 67 64 69 72 05 43 52 45 41 54 45 t1_segdir.CREATE +| 3568: 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69 TABLE 't1_segdi +| 3584: 72 27 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52 r'(level INTEGER +| 3600: 2c 69 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61 ,idx INTEGER,sta +| 3616: 72 74 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52 rt_block INTEGER +| 3632: 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 ,leaves_end_bloc +| 3648: 6b 20 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c k INTEGER,end_bl +| 3664: 6f 63 6b 20 49 4e 54 45 47 45 52 2c 72 6f 6f 74 ock INTEGER,root +| 3680: 20 42 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45 BLOB,PRIMARY KE +| 3696: 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 06 Y(level, idx))1. +| 3712: 06 17 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74 ..E...indexsqlit +| 3728: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73 e_autoindex_t1_s +| 3744: 65 67 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72 egdir_1t1_segdir +| 3760: 06 0f c7 00 08 00 00 00 00 66 04 07 17 23 23 01 .........f...##. +| 3776: 81 13 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e ..tablet1_segmen +| 3792: 74 73 74 31 5f 73 65 67 6d 65 6e 74 73 04 43 52 tst1_segments.CR +| 3808: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 EATE TABLE 't1_s +| 3824: 65 67 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64 egments'(blockid +| 3840: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 INTEGER PRIMARY +| 3856: 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 KEY, block BLOB +| 3872: 29 6a 03 07 17 21 21 01 81 1f 74 61 62 6c 65 74 )j...!!...tablet +| 3888: 31 5f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 1_contentt1_cont +| 3904: 65 6e 74 03 43 52 45 41 54 45 20 54 41 42 4c 45 ent.CREATE TABLE +| 3920: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f 't1_content'(do +| 3936: 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d cid INTEGER PRIM +| 3952: 41 52 59 20 4b 45 59 2c 20 27 63 30 61 27 2c 20 ARY KEY, 'c0a', +| 3968: 27 63 31 62 27 2c 20 27 63 32 63 27 29 38 02 06 'c1b', 'c2c')8.. +| 3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52 ...._tablet1t1CR +| 4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB +| 4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33 LE t1 USING fts3 +| 4032: 28 61 2c 62 2c 63 29 00 00 00 39 00 00 00 00 00 (a,b,c)...9..... +| page 3 offset 8192 +| 0: 0d 00 00 00 25 0b 48 00 0f d8 0f af 0f 86 0f 74 ....%.H........t +| 16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5 .a.N./.......... +| 32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 0d ef 0d d4 ...t.[.@.$...... +| 48: dd bb 0d a0 0d 84 0d 68 0d 4f 0d 35 0d 1b 0c fb .......h.O.5.... +| 64: 0c da 0c b9 35 99 0c 78 0c 57 0c 3e 0c 24 0c 0a ....5..x.W.>.$.. +| 80: 0b 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .H.............. +| 2880: 00 00 00 00 00 00 00 00 81 3f 25 06 00 82 7f 00 .........?%..... +| 2896: 00 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e .COMPILER=gcc-5. +| 2912: 34 2e 30 20 32 30 31 36 30 36 30 39 20 44 45 42 4.0 20160609 DEB +| 2928: 55 47 20 45 4e 41 42 4c 45 20 44 42 53 54 41 54 UG ENABLE DBSTAT +| 2944: 20 56 54 41 42 20 45 4e 41 42 4c 45 20 46 54 53 VTAB ENABLE FTS +| 2960: 34 20 45 4e 41 42 4c 45 20 46 54 53 35 20 45 4e 4 ENABLE FTS5 EN +| 2976: 41 42 4c 45 20 47 45 4f 50 4f 4c 59 20 45 4e 41 ABLE GEOPOLY ENA +| 2992: 42 4c 45 20 4a 53 4f 4e 31 20 45 4e 41 42 4c 45 BLE JSON1 ENABLE +| 3008: 20 4d 45 4d 53 59 53 35 20 45 4e 41 42 4c 45 20 MEMSYS5 ENABLE +| 3024: 52 54 52 45 45 20 4d 41 58 20 4d 45 4d 4f 52 59 RTREE MAX MEMORY +| 3040: 3d 35 30 30 30 30 30 30 30 20 4f 4d 49 54 20 4c =50000000 OMIT L +| 3056: 4f 41 44 20 45 58 54 45 4e 53 49 4f 4e 20 54 48 OAD EXTENSION TH +| 3072: 52 45 41 44 53 41 46 45 3d 30 18 24 05 00 25 0f READSAFE=0.$..%. +| 3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49 .THREADSAFE=0XBI +| 3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41 NARY.#..%..THREA +| 3120: 44 53 41 46 45 3d 30 58 4e 4f 43 41 53 45 17 22 DSAFE=0XNOCASE.. +| 3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 45 3d ..%..THREADSAFE= +| 3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d 0XRTRIM.!..3..OM +| 3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 4f IT LOAD EXTENSIO +| 3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f NXBINARY. ..3..O +| 3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 MIT LOAD EXTENSI +| 3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17 ONXNOCASE....3.. +| 3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 OMIT LOAD EXTENS +| 3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f 19 IONXRTRIM....3.. +| 3264: 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 30 MAX MEMORY=50000 +| 3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f 000XBINARY....3. +| 3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 .MAX MEMORY=5000 +| 3312: 30 30 30 30 58 4e 4f 43 41 53 45 1e 1c 05 00 33 0000XNOCASE....3 +| 3328: 0f 17 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 ..MAX MEMORY=500 +| 3344: 30 30 30 30 30 58 52 54 52 49 4d 18 1b 05 00 25 00000XRTRIM....% +| 3360: 0f 19 45 4e 41 42 4c 45 20 52 54 52 45 45 58 42 ..ENABLE RTREEXB +| 3376: 49 4e 41 52 59 18 1a 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3392: 4c 45 20 52 54 52 45 45 58 4e 4f 43 41 53 45 17 LE RTREEXNOCASE. +| 3408: 19 05 00 25 0f 17 45 4e 41 42 4c 45 20 52 54 52 ...%..ENABLE RTR +| 3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45 EEXRTRIM....)..E +| 3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 58 42 49 NABLE MEMSYS5XBI +| 3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4e 41 42 4c NARY....)..ENABL +| 3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 53 45 E MEMSYS5XNOCASE +| 3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 4d 45 ....)..ENABLE ME +| 3504: 4d 53 59 53 35 58 52 54 52 49 4d 18 15 05 00 25 MSYS5XRTRIM....% +| 3520: 0f 19 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 58 42 ..ENABLE JSON1XB +| 3536: 49 4e 41 52 59 18 14 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3552: 4c 45 20 4a 53 4f 4e 31 58 4e 4f 43 41 53 45 17 LE JSON1XNOCASE. +| 3568: 13 05 00 25 0f 17 45 4e 41 42 4c 45 20 4a 53 4f ...%..ENABLE JSO +| 3584: 4e 31 58 52 54 52 49 4d 1a 12 05 00 29 0f 19 45 N1XRTRIM....)..E +| 3600: 4e 41 42 4c 45 20 47 45 4f 50 4f 4c 59 58 42 49 NABLE GEOPOLYXBI +| 3616: 4e 41 52 59 1a 11 05 00 29 0f 19 45 4e 41 42 4c NARY....)..ENABL +| 3632: 45 20 47 45 4f 50 4f 4c 59 58 4e 4f 43 41 53 45 E GEOPOLYXNOCASE +| 3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 45 ....)..ENABLE GE +| 3664: 4f 50 4f 4c 59 58 52 54 52 49 4d 17 0f 05 00 23 OPOLYXRTRIM....# +| 3680: 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 58 42 49 ..ENABLE FTS5XBI +| 3696: 4e 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 4c NARY....#..ENABL +| 3712: 45 20 46 54 53 35 58 4e 4f 43 41 53 45 16 0d 05 E FTS5XNOCASE... +| 3728: 00 23 0f 17 45 4e 41 42 4c 45 20 46 54 53 35 58 .#..ENABLE FTS5X +| 3744: 52 54 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42 RTRIM....#..ENAB +| 3760: 4c 45 20 46 54 53 34 58 42 49 4e 41 52 59 17 0b LE FTS4XBINARY.. +| 3776: 05 00 23 0f 19 45 4e 41 42 4c 45 20 46 54 53 34 ..#..ENABLE FTS4 +| 3792: 58 4e 4f 43 41 53 45 16 0a 05 00 23 0f 17 45 4e XNOCASE....#..EN +| 3808: 41 42 4c 45 20 46 54 53 34 58 52 54 52 49 4d 1e ABLE FTS4XRTRIM. +| 3824: 09 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 52 59 1e TAT VTABXBINARY. +| 3856: 08 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3872: 54 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d TAT VTABXNOCASE. +| 3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3904: 54 41 54 20 56 54 41 42 58 52 54 52 49 4d 11 06 TAT VTABXRTRIM.. +| 3920: 05 00 17 0f 19 44 45 42 55 47 58 42 49 4e 41 52 .....DEBUGXBINAR +| 3936: 59 11 05 05 00 17 0f 19 44 45 42 55 47 58 4e 4f Y.......DEBUGXNO +| 3952: 43 41 53 45 10 04 05 00 17 0f 17 44 45 42 55 47 CASE.......DEBUG +| 3968: 58 52 54 52 49 4d 27 03 05 00 43 0f 19 43 4f 4d XRTRIM'...C..COM +| 3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20 PILER=gcc-5.4.0 +| 4000: 32 30 31 36 30 36 30 39 58 42 49 4e 41 52 59 27 20160609XBINARY' +| 4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67 ...C..COMPILER=g +| 4032: 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36 30 cc-5.4.0 2016060 +| 4048: 39 58 4e 4f 43 41 53 45 26 01 05 00 43 0f 17 43 9XNOCASE&...C..C +| 4064: 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e OMPILER=gcc-5.4. +| 4080: 30 20 32 30 31 36 30 36 30 39 58 52 54 52 49 4d 0 20160609XRTRIM +| page 4 offset 12288 +| 0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................ +| page 5 offset 16384 +| 0: 0d 00 00 00 02 0b a0 00 0c ad 0b a0 00 00 00 00 ................ +| 2976: 82 0a 02 08 08 09 08 08 17 84 06 30 20 32 35 33 ...........0 253 +| 2992: 00 01 30 04 25 06 1b 00 00 08 32 30 31 36 30 36 ..0.%.....201606 +| 3008: 30 39 03 25 07 00 00 01 34 03 25 05 00 00 01 35 09.%....4.%....5 +| 3024: 03 25 04 00 01 07 30 30 30 30 30 30 30 03 25 1a .%....0000000.%. +| 3040: 00 00 08 63 6f 6d 70 69 6c 65 72 03 25 02 00 00 ...compiler.%... +| 3056: 06 64 62 73 74 61 74 03 25 0a 00 01 04 65 62 75 .dbstat.%....ebu +| 3072: 67 03 25 08 00 00 06 65 6e 61 62 6c 65 09 25 09 g.%....enable.%. +| 3088: 05 04 04 04 04 04 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3104: 6e 03 25 1d 00 00 04 66 74 73 34 03 25 0d 00 03 n.%....fts4.%... +| 3120: 01 35 03 25 0f 00 00 03 67 63 63 03 25 03 00 01 .5.%....gcc.%... +| 3136: 06 65 6f 70 6f 6c 79 03 25 11 00 00 05 6a 73 6f .eopoly.%....jso +| 3152: 6e 31 03 25 13 00 00 04 6c 6f 61 64 03 25 1c 00 n1.%....load.%.. +| 3168: 00 03 6d 61 78 03 25 18 00 01 05 65 6d 6f 72 79 ..max.%....emory +| 3184: 03 25 19 00 03 04 73 79 73 35 03 25 15 00 00 04 .%....sys5.%.... +| 3200: 6f 6d 69 74 03 25 1b 00 00 05 72 74 72 65 65 03 omit.%....rtree. +| 3216: 25 17 00 00 0a 74 68 72 65 61 64 73 61 66 65 03 %....threadsafe. +| 3232: 25 1e 00 00 04 76 74 61 62 03 25 0b 00 86 50 01 %....vtab.%...P. +| 3248: 08 08 08 08 08 17 8d 12 30 20 38 33 35 00 01 30 ........0 835..0 +| 3264: 12 01 06 00 01 06 00 01 06 00 1f 03 00 01 03 00 ................ +| 3280: 01 03 00 00 08 32 30 31 36 30 36 30 39 09 01 07 .....20160609... +| 3296: 00 01 07 00 01 07 00 00 01 34 09 01 05 00 01 05 .........4...... +| 3312: 00 01 05 00 00 01 35 09 01 04 00 01 04 00 01 04 ......5......... +| 3328: 00 01 07 30 30 30 30 30 30 30 09 1c 04 00 01 04 ...0000000...... +| 3344: 00 01 04 00 00 06 62 69 6e 61 72 79 3c 03 01 02 ......binary<... +| 3360: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3376: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3392: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 ................ +| 3408: 01 02 02 00 03 01 02 02 00 00 08 63 6f 6d 70 69 ...........compi +| 3424: 6c 65 72 09 01 02 00 01 02 00 01 02 00 00 06 64 ler............d +| 3440: 62 73 74 61 74 09 07 03 00 01 03 00 01 03 00 01 bstat........... +| 3456: 04 65 62 75 67 09 04 02 00 01 02 00 01 02 00 00 .ebug........... +| 3472: 06 65 6e 61 62 6c 65 3f 07 02 00 01 02 00 01 02 .enable?........ +| 3488: 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00 ................ +| 3504: 01 02 00 01 02 00 01 02 00 01 02 00 01 01 00 01 ................ +| 3520: 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 ................ +| 3536: 00 01 02 00 01 02 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3552: 6e 09 1f 04 00 01 04 00 01 04 00 00 04 66 74 73 n............fts +| 3568: 34 09 0a 03 00 01 03 00 01 03 00 03 01 35 09 0d 4............5.. +| 3584: 03 00 01 03 00 01 03 00 00 03 67 63 63 09 01 03 ..........gcc... +| 3600: 00 01 03 00 01 03 00 01 06 65 6f 70 6f 6c 79 09 .........eopoly. +| 3616: 10 03 00 01 03 00 01 03 00 00 05 6a 73 6f 6e 31 ...........json1 +| 3632: 09 13 03 00 01 03 00 01 03 00 00 04 6c 6f 61 64 ............load +| 3648: 09 1f 03 00 01 03 00 01 03 00 00 03 6d 61 78 09 ............max. +| 3664: 1c 02 00 01 02 00 01 02 00 01 05 65 6d 6f 72 79 ...........emory +| 3680: 09 1c 03 00 01 03 00 01 03 00 03 04 73 79 73 35 ............sys5 +| 3696: 09 16 03 00 01 03 00 01 03 00 00 06 6e 6f 63 61 ............noca +| 3712: 73 65 3c 02 01 02 02 00 03 01 02 02 00 03 01 02 se<............. +| 3728: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3744: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3760: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 00 ................ +| 3776: 04 6f 6d 69 74 09 1f 02 00 01 02 00 01 02 00 00 .omit........... +| 3792: 05 72 74 72 65 65 09 19 03 00 01 03 00 01 03 00 .rtree.......... +| 3808: 03 02 69 6d 3c 01 01 02 02 00 03 01 02 02 00 03 ..im<........... +| 3824: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 ................ +| 3840: 02 02 00 03 01 02 02 00 03 01 a2 02 00 03 01 02 ................ +| 3856: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3872: 00 00 0a 74 68 72 65 61 64 73 61 66 65 09 22 02 ...threadsafe... +| 3888: 00 01 02 00 01 02 00 00 04 76 74 61 62 09 07 04 .........vtab... +| 3904: 00 01 04 00 01 04 00 00 01 78 b4 01 01 01 01 02 .........x...... +| 3920: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 3936: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 3952: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 3968: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 3984: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4000: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 4016: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 4032: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 4048: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 4064: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4080: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| page 6 offset 20480 +| 0: 0a 00 00 00 02 0f f5 00 0f fb 0f f5 00 00 00 00 ................ +| 4080: 00 00 00 00 00 05 04 08 09 01 02 04 04 08 08 09 ................ +| page 7 offset 24576 +| 0: 0d 00 00 00 05 0f b8 00 0f f4 0f e9 0f d6 0f c7 ................ +| 16: 0f b8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 4016: 00 00 00 00 00 00 00 00 0d 05 02 23 61 75 74 6f ...........#auto +| 4032: 6d 65 72 67 65 3d 35 0d 04 02 23 6d 65 72 67 65 merge=5...#merge +| 4048: 3d 31 30 30 2c 38 11 03 02 2b 69 6e 74 65 67 72 =100,8...+integr +| 4064: 69 74 79 2d 63 68 65 63 6b 09 02 02 1b 72 65 62 ity-check....reb +| 4080: 75 69 6c 64 0a 01 02 1d 6f 70 74 69 6d 69 7a 65 uild....optimize +| end crash-843cb8447eaf14.db +}]} {} + +do_catchsql_test 11.1 { + SELECT rowid, quote(matchinfo(t1,'pcxybs')) FROM t1 WHERE t1 MATCH 'e*' +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +reset_db +do_test 12.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 28672 pagesize 4096 filename c81b.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 01 00 00 00 07 .....@ ........ +| 32: 00 00 00 02 00 00 00 01 00 00 00 01 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ +| 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 ................ +| 96: 00 2e 30 38 0d 0e b1 00 06 0d a4 00 0f 8d 0f 21 ..08...........! +| 112: 0e b9 0d c8 0e 7e 0d a4 0d a4 00 00 00 00 00 00 .....~.......... +| 3488: 00 00 00 00 22 07 06 17 11 11 01 31 74 61 62 6c ...........1tabl +| 3504: 65 74 32 74 32 07 43 52 45 41 54 45 20 54 41 42 et2t2.CREATE TAB +| 3520: 4c 45 20 74 32 28 78 29 81 33 05 07 17 1f 1f 01 LE t2(x).3...... +| 3536: 82 35 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72 .5tablet1_segdir +| 3552: 74 31 5f 73 65 67 64 69 72 05 43 52 45 41 54 45 t1_segdir.CREATE +| 3568: 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69 TABLE 't1_segdi +| 3584: 72 27 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52 r'(level INTEGER +| 3600: 2c 69 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61 ,idx INTEGER,sta +| 3616: 72 74 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52 rt_block INTEGER +| 3632: 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 ,leaves_end_bloc +| 3648: 6b 20 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c k INTEGER,end_bl +| 3664: 6f 63 6b 20 49 4e 54 45 47 45 62 2c 72 6f 6f 74 ock INTEGEb,root +| 3680: 20 42 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45 BLOB,PRIMARY KE +| 3696: 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 06 Y(level, idx))1. +| 3712: 06 17 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74 ..E...indexsqlit +| 3728: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73 e_autoindex_t1_s +| 3744: 65 67 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72 egdir_1t1_segdir +| 3760: 06 0f c7 00 08 00 00 00 00 66 04 07 17 23 23 01 .........f...##. +| 3776: 81 13 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e ..tablet1_segmen +| 3792: 74 73 74 31 5f 73 65 67 6d 65 6e 74 73 04 43 52 tst1_segments.CR +| 3808: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 EATE TABLE 't1_s +| 3824: 65 67 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64 egments'(blockid +| 3840: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 INTEGER PRIMARY +| 3856: 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 KEY, block BLOB +| 3872: 29 6a 03 07 17 21 21 01 81 1f 74 61 62 6c 65 74 )j...!!...tablet +| 3888: 31 5f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 1_contentt1_cont +| 3904: 65 6e 74 03 43 52 45 41 54 45 20 54 41 42 4c 45 ent.CREATE TABLE +| 3920: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f 't1_content'(do +| 3936: 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d cid INTEGER PRIM +| 3952: 41 52 59 20 4b 45 59 2c 20 27 63 30 61 27 2c 20 ARY KEY, 'c0a', +| 3968: 27 63 31 62 27 2c 20 27 63 32 63 27 29 38 02 06 'c1b', 'c2c')8.. +| 3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52 ...._tablet1t1CR +| 4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB +| 4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33 LE t1 USING fts3 +| 4032: 28 61 2c 62 2c 63 29 00 00 00 39 00 00 00 00 00 (a,b,c)...9..... +| page 3 offset 8192 +| 0: 0d 00 00 00 25 0b 48 00 0f d8 0f af 0f 86 0f 74 ....%.H........t +| 16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5 .a.N./.......... +| 32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 0d ef 0d d5 ...t.[.@.$...... +| 48: 0d bb 0d a0 0d 84 0d 68 0d 4f 0d 35 0d 1b 0c fb .......h.O.5.... +| 64: 0c da 0c b9 0c 99 0c 78 0c 57 0c 3e 0c 24 0c 0a .......x.W.>.$.. +| 80: 0b 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .H.............. +| 2880: 00 00 00 00 00 00 00 00 81 3f 25 06 00 82 7f 00 .........?%..... +| 2896: 00 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e .COMPILER=gcc-5. +| 2912: 34 2e 30 20 32 30 31 36 30 36 30 39 20 44 45 42 4.0 20160609 DEB +| 2928: 55 47 20 45 4e 41 42 4c 45 20 44 42 53 54 41 54 UG ENABLE DBSTAT +| 2944: 20 56 54 41 42 20 45 4e 41 42 4c 45 20 46 54 53 VTAB ENABLE FTS +| 2960: 34 20 45 4e 41 42 4c 45 20 46 54 53 35 20 45 4e 4 ENABLE FTS5 EN +| 2976: 41 42 4c 45 20 47 45 4f 50 4f 4c 59 20 46 4e 41 ABLE GEOPOLY FNA +| 2992: 42 4c 45 20 4a 53 4f 4e 31 20 45 4e 41 42 4c 45 BLE JSON1 ENABLE +| 3008: 20 4d 45 4d 53 59 53 35 20 45 4e 41 42 4c 45 20 MEMSYS5 ENABLE +| 3024: 52 54 52 45 45 20 4d 41 58 20 4d 45 4d 4f 52 59 RTREE MAX MEMORY +| 3040: 3d 35 30 30 30 30 30 30 30 20 4f 4d 49 54 20 4c =50000000 OMIT L +| 3056: 4f 41 44 20 45 58 54 45 4e 53 49 4f 4e 20 54 48 OAD EXTENSION TH +| 3072: 52 45 41 44 53 41 46 45 3d 30 18 24 05 00 0f 25 READSAFE=0.$...% +| 3088: 19 58 54 48 52 45 41 44 53 41 46 45 3d 30 42 49 .XTHREADSAFE=0BI +| 3104: 4e 41 52 59 18 23 05 00 0f 25 19 58 54 48 52 45 NARY.#...%.XTHRE +| 3120: 41 44 53 41 46 45 3d 30 4e 4f 43 41 53 45 17 22 ADSAFE=0NOCASE.. +| 3136: 05 00 0f 25 17 58 54 48 52 45 41 44 53 41 46 45 ...%.XTHREADSAFE +| 3152: 3d 30 52 54 52 49 4d 1f 21 05 00 0f 33 19 58 4f =0RTRIM.!...3.XO +| 3168: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 MIT LOAD EXTENSI +| 3184: 4f 4e 42 49 4e 41 52 59 1f 20 05 00 0f 33 19 58 ONBINARY. ...3.X +| 3200: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 OMIT LOAD EXTENS +| 3216: 49 4f 4e 4e 4f 43 41 53 45 1e 1f 05 00 0f 33 17 IONNOCASE.....3. +| 3232: 58 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e XOMIT LOAD EXTEN +| 3248: 53 49 4f 4e 52 54 52 49 4d 1f 1e 05 00 0f 33 19 SIONRTRIM.....3. +| 3264: 58 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 XMAX MEMORY=5000 +| 3280: 30 30 30 30 42 49 4e 41 52 59 1f 1d 05 00 0f 33 0000BINARY.....3 +| 3296: 19 58 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 .XMAX MEMORY=500 +| 3312: 30 30 30 30 30 4e 4f 43 41 53 45 1e 1c 05 00 0f 00000NOCASE..... +| 3328: 33 17 58 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 3.XMAX MEMORY=50 +| 3344: 30 30 30 30 30 30 52 54 52 49 4d 18 1b 05 00 0f 000000RTRIM..... +| 3360: 25 19 58 45 4e 41 42 4c 45 20 52 54 52 45 45 42 %.XENABLE RTREEB +| 3376: 49 4e 41 52 59 18 1a 05 00 0f 25 19 58 45 4e 41 INARY.....%.XENA +| 3392: 42 4c 45 20 52 54 52 45 45 4e 4f 43 41 53 45 17 BLE RTREENOCASE. +| 3408: 19 05 00 0f 25 17 58 45 4e 41 42 4c 45 20 52 54 ....%.XENABLE RT +| 3424: 52 45 45 52 54 52 49 4d 1a 18 05 00 0f 29 19 58 REERTRIM.....).X +| 3440: 45 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 42 49 ENABLE MEMSYS5BI +| 3456: 4e 41 52 59 1a 17 05 00 0f 29 19 58 45 4e 41 42 NARY.....).XENAB +| 3472: 4c 45 20 4d 45 4d 53 59 53 35 4e 4f 43 41 53 45 LE MEMSYS5NOCASE +| 3488: 19 16 05 00 0f 29 17 58 45 4e 41 42 4c 45 20 4d .....).XENABLE M +| 3504: 45 4d 53 59 53 35 52 54 52 49 4d 18 15 05 00 0f EMSYS5RTRIM..... +| 3520: 25 19 58 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 42 %.XENABLE JSON1B +| 3536: 49 4e 41 52 59 18 14 05 00 0f 25 19 58 45 4e 41 INARY.....%.XENA +| 3552: 42 4c 45 20 4a 53 4f 4e 31 4e 4f 43 41 53 45 17 BLE JSON1NOCASE. +| 3568: 13 05 00 0f 25 17 58 45 4e 41 42 4c 45 20 4a 53 ....%.XENABLE JS +| 3584: 4f 4e 31 52 54 52 49 4d 1a 12 05 00 0f 29 19 58 ON1RTRIM.....).X +| 3600: 45 4e 41 42 4c 45 20 47 45 4f 50 4f 4c 59 42 49 ENABLE GEOPOLYBI +| 3616: 4e 41 52 59 1a 11 05 00 0f 29 19 58 45 4e 41 1e NARY.....).XENA. +| 3632: 4c 45 20 47 45 4f 50 4f 4c 59 4e 4f 43 41 53 45 LE GEOPOLYNOCASE +| 3648: 19 10 05 00 0f 29 17 58 45 4e 41 42 4c 45 20 47 .....).XENABLE G +| 3664: 45 4f 50 4f 4c 59 52 54 52 49 4d 17 0f 05 00 0f EOPOLYRTRIM..... +| 3680: 23 19 58 45 4e 41 42 4c 45 20 46 54 53 35 42 49 #.XENABLE FTS5BI +| 3696: 4e 41 52 59 17 0e 05 00 0f 23 19 58 55 4e 41 42 NARY.....#.XUNAB +| 3712: 4c 45 20 46 54 53 35 4e 4f 43 41 53 45 16 0d 05 LE FTS5NOCASE... +| 3728: 00 0f 23 17 58 45 4e 41 42 4c 45 20 46 54 53 35 ..#.XENABLE FTS5 +| 3744: 52 54 52 49 4d 17 0c 05 00 0f 23 19 58 45 4e 41 RTRIM.....#.XENA +| 3760: 42 4c 45 20 46 54 53 34 42 49 4e 41 52 59 17 0b BLE FTS4BINARY.. +| 3776: 05 00 0f 23 19 58 45 4e 41 42 4c 45 20 46 54 53 ...#.XENABLE FTS +| 3792: 35 4e 4f 43 40 53 45 16 0a 05 00 0f 23 17 58 45 5NOC@SE.....#.XE +| 3808: 4e 41 42 4c 45 20 46 54 53 34 52 54 52 49 4d 1e NABLE FTS4RTRIM. +| 3824: 09 05 00 0f 31 19 58 45 4e 41 42 4c 35 20 44 42 ....1.XENABL5 DB +| 3840: 53 54 41 54 20 56 54 41 42 42 49 4e 41 52 59 1e STAT VTABBINARY. +| 3856: 08 05 00 0f 31 19 58 45 4e 41 42 4c 45 20 44 42 ....1.XENABLE DB +| 3872: 53 54 41 54 20 56 54 41 42 4e 4f 43 41 53 45 1d STAT VTABNOCASE. +| 3888: 07 05 00 0f 31 17 58 45 4e 41 42 4c 45 20 44 42 ....1.XENABLE DB +| 3904: 53 54 41 54 20 56 54 41 42 52 54 52 49 4d 11 06 STAT VTABRTRIM.. +| 3920: 05 00 0f 17 19 58 44 45 42 55 47 42 49 4e 41 52 .....XDEBUGBINAR +| 3936: 59 11 05 05 00 0f 17 19 58 44 45 42 55 47 4e 4f Y.......XDEBUGNO +| 3952: 43 41 53 45 10 04 05 00 0f 17 17 58 44 45 42 55 CASE.......XDEBU +| 3968: 47 52 54 52 49 4d 27 03 05 00 0f 43 19 58 43 4f GRTRIM'....C.XCO +| 3984: 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 MPILER=gcc-5.4.0 +| 4000: 20 32 30 31 36 30 36 30 39 42 49 4e 41 52 59 27 20160609BINARY' +| 4016: 02 05 00 0f 43 19 58 43 4f 4d 50 49 4c 45 52 3d ....C.XCOMPILER= +| 4032: 67 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36 gcc-5.4.0 201606 +| 4048: 30 39 4e 4f 43 41 53 45 26 01 05 00 0f 43 17 58 09NOCASE&....C.X +| 4064: 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 COMPILER=gcc-5.4 +| 4080: 2e 30 20 32 30 31 36 30 36 30 39 52 54 52 49 4d .0 20160609RTRIM +| page 4 offset 12288 +| 0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................ +| page 5 offset 16384 +| 0: 0d 00 00 00 03 07 bb 00 0c ad 0b a0 07 bb 00 00 ................ +| 1968: 00 00 00 00 00 00 00 00 00 00 00 87 62 03 08 08 ............b... +| 1984: 01 08 08 17 8f 34 02 30 20 39 38 30 00 01 30 1e .....4.0 980..0. +| 2000: 01 01 01 06 00 01 01 01 06 00 01 01 01 06 00 1f ................ +| 2016: 01 01 03 00 01 01 01 03 00 01 01 01 03 00 00 08 ................ +| 2032: 32 30 31 36 30 36 30 39 0f 01 01 01 07 00 01 01 20160609........ +| 2048: 01 07 00 01 01 01 07 00 00 01 34 0f 01 01 01 05 ..........4..... +| 2064: 00 01 01 01 05 00 01 01 01 05 00 00 01 35 0f 01 .............5.. +| 2080: 01 01 04 00 01 01 01 04 00 01 01 01 04 00 01 07 ................ +| 2096: 30 30 30 30 30 30 30 0f 1c 01 01 04 00 01 01 01 0000000......... +| 2112: 04 00 01 01 01 04 00 00 06 62 69 6e 61 72 79 3c .........binary< +| 2128: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 ................ +| 2144: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 ................ +| 2160: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 ................ +| 2176: 02 00 03 01 02 02 00 03 01 02 02 00 00 08 63 6f ..............co +| 2192: 6d 70 69 6c 65 72 0f 01 01 01 02 00 01 01 01 02 mpiler.......... +| 2208: 00 01 01 01 02 00 00 06 64 62 73 74 61 74 0f 07 ........dbstat.. +| 2224: 01 01 03 00 01 01 01 03 00 01 01 01 03 00 01 04 ................ +| 2240: 65 62 75 67 0f 04 01 01 02 00 01 01 01 02 00 01 ebug............ +| 2256: 01 01 02 00 00 03 65 6e 61 05 11 01 01 02 00 03 ......ena....... +| 2272: 03 62 6c 35 05 09 01 01 02 00 05 01 65 5a 07 01 .bl5........eZ.. +| 2288: 01 02 00 01 01 01 02 00 02 01 01 02 00 01 01 01 ................ +| 2304: 02 00 01 01 01 02 00 01 01 01 02 00 02 01 01 02 ................ +| 2320: 00 01 01 01 02 00 02 01 01 02 00 01 01 01 02 00 ................ +| 2336: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 2352: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 2368: 01 02 00 01 01 01 02 00 01 08 78 74 65 6e 73 69 ..........xtensi +| 2384: 6f 6e 0f 1f 01 01 04 00 01 01 01 04 00 01 01 01 on.............. +| 2400: 04 00 00 04 66 74 73 34 0a 0a 01 01 03 00 02 01 ....fts4........ +| 2416: 01 03 00 03 01 35 14 0b 01 01 03 00 02 01 01 03 .....5.......... +| 2432: 00 01 01 01 03 00 01 01 01 03 00 00 03 67 63 63 .............gcc +| 2448: 0f 01 01 01 03 00 01 01 01 03 00 01 01 01 03 00 ................ +| 2464: 01 06 65 6f 70 6f 6c 79 0f 10 01 01 03 00 01 01 ..eopoly........ +| 2480: 01 04 00 01 01 01 03 00 00 05 6a 73 6f 6e 31 0f ..........json1. +| 2496: 13 01 01 03 00 01 01 01 03 00 01 01 01 03 00 00 ................ +| 2512: 02 6c 65 05 11 01 01 03 00 01 03 6f 61 64 0f 1f .le........oad.. +| 2528: 01 01 03 00 01 01 01 03 00 01 01 01 03 00 00 03 ................ +| 2544: 6d 61 78 0f 1c 01 01 02 00 01 01 01 02 00 01 01 max............. +| 2560: 01 02 00 01 05 65 6d 6f 72 79 0f 1c 01 01 03 00 .....emory...... +| 2576: 01 01 01 03 00 01 01 01 03 00 03 04 73 79 73 35 ............sys5 +| 2592: 0f 16 01 01 03 00 01 01 01 03 00 01 01 01 03 00 ................ +| 2608: 00 03 6e 6f 63 05 0b 01 02 02 00 03 03 61 73 65 ..noc........ase +| 2624: 37 02 01 02 02 00 03 01 02 02 00 03 01 02 02 00 7............... +| 2640: 06 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 ................ +| 2656: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 ................ +| 2672: 02 02 00 03 01 02 02 00 00 04 6f 6d 69 74 0f 1f ..........omit.. +| 2688: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 00 05 ................ +| 2704: 72 74 72 65 65 0f 19 01 01 03 00 01 01 01 03 00 rtree........... +| 2720: 01 01 01 03 00 03 02 69 6d 3c 01 01 02 02 00 03 .......im<...... +| 2736: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 ................ +| 2752: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 ................ +| 2768: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 2784: 00 03 01 02 02 00 00 02 73 65 05 0b 01 02 03 00 ........se...... +| 2800: 00 0a 74 68 72 65 61 64 73 61 66 65 0f 22 01 01 ..threadsafe.... +| 2816: 02 00 01 01 01 02 00 01 01 01 02 00 00 06 75 6e ..............un +| 2832: 61 62 6c 65 05 0e 01 01 02 00 00 04 76 74 61 62 able........vtab +| 2848: 0f 07 01 01 04 00 01 01 01 04 00 01 01 01 04 00 ................ +| 2864: 00 01 78 6c 01 02 00 01 02 00 01 02 00 01 02 00 ..xl............ +| 2880: 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 ................ +| 2896: 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 ................ +| 2912: 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00 ................ +| 2928: 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 ................ +| 2944: 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 ................ +| 2960: 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00 ................ +| 2976: 82 0a 02 08 08 09 08 08 17 84 06 30 20 32 35 33 ...........0 253 +| 2992: 00 01 30 04 25 06 1b 00 00 08 32 30 31 36 30 36 ..0.%.....201606 +| 3008: 30 39 03 25 07 00 00 01 34 03 25 05 00 00 01 35 09.%....4.%....5 +| 3024: 03 25 04 00 01 07 30 30 30 30 30 30 30 03 25 1a .%....0000000.%. +| 3040: 00 00 08 63 6f 6d 70 69 6c 65 72 03 25 02 00 00 ...compiler.%... +| 3056: 06 64 62 73 74 61 74 03 25 0a 00 01 04 65 62 75 .dbstat.%....ebu +| 3072: 67 03 25 08 00 00 06 65 6e 61 62 6c 65 09 25 09 g.%....enable.%. +| 3088: 05 04 04 04 04 04 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3104: 6e 03 25 1d 00 00 04 66 74 73 34 03 25 0d 00 03 n.%....fts4.%... +| 3120: 11 35 03 25 0f 00 00 03 67 63 63 03 25 03 00 01 .5.%....gcc.%... +| 3136: 06 65 6f 70 6f 6c 79 03 25 11 00 00 05 6a 73 6f .eopoly.%....jso +| 3152: 6e 31 03 25 13 00 00 04 6c 6f 61 64 03 25 1c 00 n1.%....load.%.. +| 3168: 00 03 6d 61 78 03 25 18 00 01 05 65 6d 6f 72 79 ..max.%....emory +| 3184: 03 25 19 00 03 04 73 79 73 35 03 25 15 00 00 04 .%....sys5.%.... +| 3200: 6f 6d 69 74 03 25 1b 00 00 05 72 74 72 65 65 03 omit.%....rtree. +| 3216: 25 17 00 00 0a 74 68 72 65 61 64 73 61 66 65 03 %....threadsafe. +| 3232: 25 1e 00 00 04 76 74 61 62 03 25 0b 00 86 50 01 %....vtab.%...P. +| 3248: 08 08 08 08 08 17 8d 12 30 20 38 33 35 00 01 30 ........0 835..0 +| 3264: 12 00 f6 00 01 06 00 01 06 00 1f 03 00 01 03 00 ................ +| 3280: 01 03 00 00 08 32 30 31 36 30 36 30 39 09 01 07 .....20160609... +| 3296: 00 01 07 00 01 07 00 00 01 34 09 01 05 00 01 05 .........4...... +| 3312: 00 01 05 00 00 01 35 09 01 04 00 01 04 00 01 04 ......5......... +| 3328: 00 01 07 30 30 30 30 30 30 30 09 1c 04 00 01 04 ...0000000...... +| 3344: 00 01 04 00 00 06 62 69 6e 61 72 79 3c 03 01 02 ......binary<... +| 3360: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3376: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3392: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 ................ +| 3408: 01 02 02 00 03 01 02 02 00 00 08 63 6f 6d 70 69 ...........compi +| 3424: 6c 65 72 09 01 02 00 01 02 00 01 02 00 00 06 64 ler............d +| 3440: 62 73 74 61 74 09 07 03 00 01 03 00 01 03 00 01 bstat........... +| 3456: 04 65 62 75 67 09 04 02 00 01 02 00 01 02 00 00 .ebug........... +| 3472: 06 65 6e 61 62 6c 65 3f 07 02 00 01 02 00 01 01 .enable?........ +| 3488: 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00 ................ +| 3504: 01 02 00 01 02 00 01 02 00 01 02 00 01 02 10 01 ................ +| 3520: 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 ................ +| 3536: 00 01 02 00 01 02 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3552: 6e 09 1f 04 00 01 04 00 01 04 00 00 04 66 74 73 n............fts +| 3568: 34 09 0a 03 00 01 03 00 01 03 00 03 01 35 09 0d 4............5.. +| 3584: 03 00 01 03 00 01 03 00 00 03 67 63 63 09 01 03 ..........gcc... +| 3600: 00 01 03 00 01 03 00 01 06 65 6f 70 6f 6c 79 09 .........eopoly. +| 3616: 10 03 00 01 03 00 01 03 00 00 05 6a 73 6f 6e 31 ...........json1 +| 3632: 09 13 03 00 01 03 00 01 03 00 00 04 6c 6f 61 64 ............load +| 3648: 09 1f 03 00 01 03 00 01 03 00 00 03 6d 61 78 09 ............max. +| 3664: 1c 02 00 01 02 00 01 02 00 01 05 65 6d 6f 72 79 ...........emory +| 3680: 09 1c 03 00 01 03 00 01 03 00 03 04 73 79 73 35 ............sys5 +| 3696: 09 16 03 00 01 03 00 01 03 00 00 06 6e 6f 63 61 ............noca +| 3712: 73 65 3c 02 01 02 02 00 03 01 02 02 00 03 01 02 se<............. +| 3728: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3744: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3760: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 00 ................ +| 3776: 04 6f 6d 69 74 09 1f 02 00 01 02 00 01 02 00 00 .omit........... +| 3792: 05 72 74 72 65 65 09 19 03 00 01 03 00 01 03 00 .rtree.......... +| 3808: 03 02 69 6d 3c 01 01 02 02 00 03 01 02 02 00 03 ..im<........... +| 3824: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 ................ +| 3840: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 ................ +| 3856: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3872: 00 00 0a 74 68 72 65 61 64 73 61 66 65 09 22 02 ...threadsafe... +| 3888: 00 01 02 00 02 02 00 00 04 76 74 61 62 09 07 04 .........vtab... +| 3904: 00 01 04 00 01 04 00 00 01 78 b4 01 01 01 01 02 .........x...... +| 3920: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 3936: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 3952: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 3968: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 3984: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4000: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 4016: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 4032: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 4048: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 4064: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4080: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| page 6 offset 20480 +| 0: 0a 00 00 00 03 0f ee 00 0f fb 0f f5 0f ee 00 00 ................ +| 4064: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 06 04 ................ +| 4080: 08 01 01 02 03 05 04 08 09 01 02 04 04 08 08 09 ................ +| page 7 offset 24576 +| 0: 0d 00 00 00 05 0f b8 00 0f f4 0f e9 0f d6 0f c7 ................ +| 16: 0f b8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 4016: 00 00 00 00 00 00 00 00 0d 05 02 23 61 75 74 6f ...........#auto +| 4032: 6d 65 72 67 65 3d 35 0c f4 02 23 6d 65 72 67 65 merge=5...#merge +| 4048: 3d 31 30 30 2c 38 11 03 02 2b 69 6e 74 65 67 72 =100,8...+integr +| 4064: 69 74 79 2d 63 68 65 63 6b 09 02 02 1b 72 65 62 ity-check....reb +| 4080: 75 69 6c 64 0a 01 02 1d 6f 70 74 69 6d 69 7a 65 uild....optimize +| end c81b.db +}]} {} + +do_catchsql_test 12.1 { + SELECT rowid, quote(matchinfo(t1,'pcxybspcxybs')) + FROM t1 WHERE t1 MATCH 'e*e*' +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +reset_db +do_test 13.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 28672 pagesize 4096 filename crash-c666cfde112dee.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07 .....@ ........ +| 32: 00 00 00 02 00 00 00 01 00 00 00 07 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 07 00 00 00 01 00 00 00 00 ................ +| 96: 00 00 00 00 0d 0e b1 00 06 0d a4 00 0f 8d 0f 21 ...............! +| 112: 0e b9 0d c8 0e 7e 0d a4 0d a4 00 00 00 00 00 00 .....~.......... +| 3488: 00 00 00 00 22 07 06 17 11 11 01 31 74 61 62 6c ...........1tabl +| 3504: 65 74 32 74 32 07 43 52 45 41 54 45 20 54 41 42 et2t2.CREATE TAB +| 3520: 4c 45 20 74 32 28 78 29 81 33 05 07 17 1f 1f 01 LE t2(x).3...... +| 3536: 82 35 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72 .5tablet1_segdir +| 3552: 74 31 5f 73 65 67 64 69 72 05 43 52 45 41 54 45 t1_segdir.CREATE +| 3568: 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69 TABLE 't1_segdi +| 3584: 72 27 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52 r'(level INTEGER +| 3600: 2c 69 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61 ,idx INTEGER,sta +| 3616: 72 74 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52 rt_block INTEGER +| 3632: 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 ,leaves_end_bloc +| 3648: 6b 20 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c k INTEGER,end_bl +| 3664: 6f 63 6b 20 49 4e 54 45 47 45 62 2c 72 6f 6f 74 ock INTEGEb,root +| 3680: 20 42 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45 BLOB,PRIMARY KE +| 3696: 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 06 Y(level, idx))1. +| 3712: 06 17 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74 ..E...indexsqlit +| 3728: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73 e_autoindex_t1_s +| 3744: 65 67 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72 egdir_1t1_segdir +| 3760: 06 0f c7 00 08 00 00 00 00 66 04 07 17 23 23 01 .........f...##. +| 3776: 81 13 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e ..tablet1_segmen +| 3792: 74 73 74 31 5f 73 65 67 6d 65 6e 74 73 04 43 52 tst1_segments.CR +| 3808: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 EATE TABLE 't1_s +| 3824: 65 67 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64 egments'(blockid +| 3840: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 INTEGER PRIMARY +| 3856: 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 KEY, block BLOB +| 3872: 29 6a 03 07 17 21 21 01 81 1f 74 61 62 6c 65 74 )j...!!...tablet +| 3888: 31 5f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 1_contentt1_cont +| 3904: 65 6e 74 03 43 52 45 41 54 45 20 54 41 42 4c 45 ent.CREATE TABLE +| 3920: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f 't1_content'(do +| 3936: 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d cid INTEGER PRIM +| 3952: 41 52 59 20 4b 45 59 2c 20 27 63 30 61 27 2c 20 ARY KEY, 'c0a', +| 3968: 27 63 31 62 27 2c 20 27 63 32 63 27 29 38 02 06 'c1b', 'c2c')8.. +| 3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52 ...._tablet1t1CR +| 4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB +| 4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33 LE t1 USING fts3 +| 4032: 28 61 2c 62 2c 63 29 00 00 00 39 00 00 00 00 00 (a,b,c)...9..... +| page 3 offset 8192 +| 0: 0d 00 00 00 25 0b 48 00 0f d8 0f af 0f 86 0f 74 ....%.H........t +| 16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5 .a.N./.......... +| 32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 0d ef 0d d5 ...t.[.@.$...... +| 48: 0d bb 0d a0 0d 84 0d 68 0d 4f 0d 35 0d 1b 0c fb .......h.O.5.... +| 64: 0c da 0c b9 0c 99 0c 78 0c 57 0c 3e 0c 24 0c 0a .......x.W.>.$.. +| 80: 0b 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .H.............. +| 2880: 00 00 00 00 00 00 00 00 81 3f 25 06 00 82 7f 00 .........?%..... +| 2896: 00 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e .COMPILER=gcc-5. +| 2912: 34 23 00 20 32 30 31 36 30 36 30 39 20 44 45 42 4#. 20160609 DEB +| 2928: 55 47 20 45 4e 41 42 4c 45 20 44 42 53 54 41 54 UG ENABLE DBSTAT +| 2944: 20 56 54 41 42 20 45 4e 41 42 4c 45 20 46 54 53 VTAB ENABLE FTS +| 2960: 34 20 45 4e 41 42 4c 45 20 46 54 53 35 20 45 4e 4 ENABLE FTS5 EN +| 2976: 41 42 4c 45 20 47 45 4f 50 4f 4c 59 20 45 4e 41 ABLE GEOPOLY ENA +| 2992: 42 4c 45 20 4a 53 4f 4e 31 20 45 4e 41 42 4c 45 BLE JSON1 ENABLE +| 3008: 20 4d 45 4d 53 59 53 35 20 45 4e 41 42 4c 45 20 MEMSYS5 ENABLE +| 3024: 52 54 52 45 45 20 4d 41 58 20 4d 45 4d 4f 52 59 RTREE MAX MEMORY +| 3040: 3d 35 30 30 30 30 30 30 30 20 4f 4d 49 54 20 4c =50000000 OMIT L +| 3056: 4f 41 44 20 45 58 54 45 4e 53 49 4f 4e 20 54 48 OAD EXTENSION TH +| 3072: 52 45 41 44 53 41 46 45 3d 30 18 24 05 00 25 0f READSAFE=0.$..%. +| 3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49 .THREADSAFE=0XBI +| 3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41 NARY.#..%..THREA +| 3120: 44 53 41 46 45 3d 30 58 4e 4f 43 41 53 45 17 22 DSAFE=0XNOCASE.. +| 3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 45 3d ..%..THREADSAFE= +| 3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d 0XRTRIM.!..3..OM +| 3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 4f IT LOAD EXTENSIO +| 3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f NXBINARY. ..3..O +| 3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 MIT LOAD EXTENSI +| 3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17 ONXNOCASE....3.. +| 3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 OMIT LOAD EXTENS +| 3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f 19 IONXRTRIM....3.. +| 3264: 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 30 MAX MEMORY=50000 +| 3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f 000XBINARY....3. +| 3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 .MAX MEMORY=5000 +| 3312: 30 30 30 30 58 4e 4f 43 41 53 45 1e 1c 05 00 33 0000XNOCASE....3 +| 3328: 0f 17 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 ..MAX MEMORY=500 +| 3344: 30 30 30 30 30 58 52 54 53 49 4d 18 1b 05 00 25 00000XRTSIM....% +| 3360: 0f 19 45 4e 41 42 4c 45 20 52 54 52 45 45 58 42 ..ENABLE RTREEXB +| 3376: 49 4e 41 52 59 18 1a 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3392: 4c 45 20 52 54 52 45 45 58 4e 4f 43 41 53 45 17 LE RTREEXNOCASE. +| 3408: 19 05 00 25 0f 17 45 4e 41 42 4c 45 20 52 54 52 ...%..ENABLE RTR +| 3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45 EEXRTRIM....)..E +| 3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 58 42 49 NABLE MEMSYS5XBI +| 3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4e 41 42 4c NARY....)..ENABL +| 3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 53 45 E MEMSYS5XNOCASE +| 3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 4d 45 ....)..ENABLE ME +| 3504: 4d 53 59 53 35 58 52 54 52 49 4d 18 15 05 00 25 MSYS5XRTRIM....% +| 3520: 0f 19 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 58 42 ..ENABLE JSON1XB +| 3536: 49 4e 41 52 59 18 14 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3552: 4c 45 20 4a 53 4f 4e 31 58 4e 4f 43 41 53 45 17 LE JSON1XNOCASE. +| 3568: 13 05 00 25 0f 17 45 4e 41 52 4c 45 20 4a 53 4f ...%..ENARLE JSO +| 3584: 4e 31 58 52 54 52 49 4d 1a 12 05 00 29 0f 19 45 N1XRTRIM....)..E +| 3600: 4e 41 42 4c 45 20 47 45 4f 50 4f 4c 59 58 42 49 NABLE GEOPOLYXBI +| 3616: 4e 41 52 59 1a 11 05 00 29 0f 19 45 4e 41 1e 4c NARY....)..ENA.L +| 3632: 45 20 47 45 4f 50 4f 4c 59 58 4e 4f 43 41 53 45 E GEOPOLYXNOCASE +| 3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 45 ....)..ENABLE GE +| 3664: 4f 50 4f 4c 59 58 52 54 52 49 4d 17 0f 05 00 23 OPOLYXRTRIM....# +| 3680: 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 58 42 49 ..ENABLE FTS5XBI +| 3696: 4e 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 4c NARY....#..ENABL +| 3712: 45 20 46 54 53 35 58 4e 4f 43 41 53 45 16 0d 05 E FTS5XNOCASE... +| 3728: 00 23 0f 17 45 4e 41 42 4c 45 20 46 54 59 e5 58 .#..ENABLE FTY.X +| 3744: 52 54 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42 RTRIM....#..ENAB +| 3760: 4c 45 20 46 54 53 34 58 42 49 4e 41 52 59 17 0b LE FTS4XBINARY.. +| 3776: 05 00 23 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 ..#..ENABLE FTS5 +| 3792: 58 4e 4f 43 40 53 45 16 0a 05 00 23 0f 17 45 4e XNOC@SE....#..EN +| 3808: 41 42 4c 45 20 46 54 53 34 58 52 54 52 49 4d 1e ABLE FTS4XRTRIM. +| 3824: 09 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 52 59 1e TAT VTABXBINARY. +| 3856: 08 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3872: 54 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d TAT VTABXNOCASE. +| 3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3904: 54 41 54 20 56 54 41 42 58 52 54 52 49 4d 11 06 TAT VTABXRTRIM.. +| 3920: 05 00 17 0f 19 44 45 42 55 47 58 42 49 4e 41 52 .....DEBUGXBINAR +| 3936: 59 11 05 05 00 17 0f 19 44 45 42 55 47 58 4e 4f Y.......DEBUGXNO +| 3952: 43 41 53 45 10 04 05 00 17 0f 17 44 45 42 55 47 CASE.......DEBUG +| 3968: 58 52 54 52 49 4d 27 03 05 00 43 0f 19 43 4f 4d XRTRIM'...C..COM +| 3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20 PILER=gcc-5.4.0 +| 4000: 32 30 31 36 30 36 30 39 58 42 49 4e 41 52 59 27 20160609XBINARY' +| 4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67 ...C..COMPILER=g +| 4032: 63 63 2d 35 2e 34 2f 30 20 32 30 31 36 30 36 30 cc-5.4/0 2016060 +| 4048: 39 58 4e 4f 43 41 53 45 26 01 05 00 43 0f 17 43 9XNOCASE&...C..C +| 4064: 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e OMPILER=gcc-5.4. +| 4080: 30 20 32 30 31 36 30 36 30 39 58 52 54 52 49 4d 0 20160609XRTRIM +| page 4 offset 12288 +| 0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................ +| page 5 offset 16384 +| 0: 0d 00 00 00 02 0b a0 00 0c ad 0b a0 00 00 00 00 ................ +| 2976: 82 0a 02 08 08 09 08 08 17 84 06 30 20 32 35 33 ...........0 253 +| 2992: 00 01 30 04 25 06 1b 00 00 08 32 30 31 36 30 36 ..0.%.....201606 +| 3008: 30 39 03 25 07 00 00 01 34 03 25 05 00 00 01 35 09.%....4.%....5 +| 3024: 03 25 04 00 01 07 30 30 30 30 30 30 30 03 25 1a .%....0000000.%. +| 3040: 00 00 08 63 6f 6d 70 69 6c 65 72 03 25 02 00 00 ...compiler.%... +| 3056: 06 64 62 73 74 61 74 03 25 0a 00 01 04 65 62 75 .dbstat.%....ebu +| 3072: 67 03 25 08 00 00 06 65 6e 61 62 6c 65 09 25 09 g.%....enable.%. +| 3088: 05 04 04 04 04 04 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3104: 6e 03 25 1d 00 00 04 66 74 73 34 03 25 0d 00 03 n.%....fts4.%... +| 3120: 01 35 03 25 0f 00 00 03 67 63 63 03 25 03 00 01 .5.%....gcc.%... +| 3136: 06 65 6f 70 6f 6c 79 03 25 11 00 00 05 6a 73 6f .eopoly.%....jso +| 3152: 6e 31 03 25 13 41 00 04 6c 6f 61 64 03 25 1c 00 n1.%.A..load.%.. +| 3168: 00 03 6d 61 78 03 25 18 00 01 05 65 6d 6f 72 79 ..max.%....emory +| 3184: 03 25 19 00 03 04 73 79 73 35 03 25 15 00 00 04 .%....sys5.%.... +| 3200: 6f 6d 69 74 03 25 1b 00 00 05 72 74 72 65 65 03 omit.%....rtree. +| 3216: 25 17 00 00 0a 74 68 72 65 61 64 73 61 66 65 03 %....threadsafe. +| 3232: 25 1e 00 00 04 76 74 61 62 03 25 0b 00 86 50 01 %....vtab.%...P. +| 3248: 08 08 08 08 08 17 8d 12 30 20 38 33 35 00 01 30 ........0 835..0 +| 3264: 12 01 06 00 01 06 00 01 06 00 1f 03 00 01 03 00 ................ +| 3280: 01 03 00 00 08 32 30 31 36 30 36 30 39 09 01 07 .....20160609... +| 3296: 00 01 07 00 01 07 00 00 01 34 09 01 05 00 01 05 .........4...... +| 3312: 00 01 05 00 00 01 35 09 01 04 00 01 04 00 01 04 ......5......... +| 3328: 00 01 07 30 30 30 30 30 30 30 09 1c 04 00 01 04 ...0000000...... +| 3344: 00 01 04 00 00 06 62 69 6e 61 72 79 3c 03 02 02 ......binary<... +| 3360: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3376: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3392: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 ................ +| 3408: 01 02 02 00 03 01 02 02 00 00 08 63 6f 6d 70 69 ...........compi +| 3424: 6c 65 72 09 01 02 00 01 02 00 01 02 00 00 06 64 ler............d +| 3440: 62 73 74 61 74 09 f2 03 00 01 03 00 01 03 00 01 bstat........... +| 3456: 04 65 62 75 67 09 04 02 00 01 02 00 01 02 00 00 .ebug........... +| 3472: 06 65 6e 61 62 6c 65 3f 07 02 00 01 02 00 01 02 .enable?........ +| 3488: 00 01 02 00 01 02 00 01 02 00 01 02 00 57 02 00 .............W.. +| 3504: 01 02 00 01 01 00 01 02 00 01 02 00 01 02 10 01 ................ +| 3520: 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 ................ +| 3536: 00 01 02 00 01 02 00 01 08 78 74 64 6e 73 69 6f .........xtdnsio +| 3552: 6e 09 1f 04 00 01 04 00 01 03 00 00 04 66 74 73 n............fts +| 3568: 34 09 0a 03 00 01 03 00 01 03 00 03 01 35 09 0d 4............5.. +| 3584: 03 00 01 03 00 01 03 00 00 03 57 63 63 09 01 03 ..........Wcc... +| 3600: 00 01 03 00 01 03 00 01 06 65 6f 70 6f 6c 79 09 .........eopoly. +| 3616: 10 03 00 01 03 00 01 03 00 00 05 6a 73 6f 6e 31 ...........json1 +| 3632: 09 13 03 00 01 03 00 01 03 00 00 04 6c 6f 61 64 ............load +| 3648: 09 1f 03 00 01 03 00 01 03 00 00 03 6d 61 78 09 ............max. +| 3664: 1c 02 00 01 02 00 01 02 00 01 05 65 6d 6f 72 79 ...........emory +| 3680: 09 1c 03 00 01 03 00 01 03 00 03 04 73 79 73 35 ............sys5 +| 3696: 09 16 03 00 01 03 00 01 03 00 00 06 6e 6f 63 61 ............noca +| 3712: 73 65 3c 02 01 02 02 00 03 01 02 02 00 03 01 02 se<............. +| 3728: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3744: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3760: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 00 ................ +| 3776: 04 6f 6d 69 74 09 1f 02 00 01 02 00 01 02 00 00 .omit........... +| 3792: 05 72 74 72 65 65 09 19 03 00 01 03 00 01 03 00 .rtree.......... +| 3808: 03 02 69 6d 3c 01 01 02 02 00 03 01 02 02 00 03 ..im<........... +| 3824: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 ................ +| 3840: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 ................ +| 3856: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3872: 00 00 0a 74 68 72 65 61 64 73 61 66 65 09 22 02 ...threadsafe... +| 3888: 00 01 02 00 02 02 00 00 04 76 74 61 62 09 07 04 .........vtab... +| 3904: 00 01 04 00 01 04 00 00 01 78 b4 01 01 01 01 02 .........x...... +| 3920: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 3936: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 3952: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 3968: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 3984: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4000: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 4016: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 4032: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 4048: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 4064: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4080: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| page 6 offset 20480 +| 0: 0a 00 00 00 02 0f f5 00 0f fb 0f f5 00 00 00 00 ................ +| 4080: 00 00 00 00 00 05 04 08 09 01 02 04 04 08 08 09 ................ +| page 7 offset 24576 +| 0: 0d 00 00 00 05 0f b8 00 0f f4 0f e9 0f d6 0f c7 ................ +| 16: 0f b8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 4016: 00 00 00 00 00 00 00 00 0d 05 02 23 61 75 74 6f ...........#auto +| 4032: 6d 65 72 67 65 3d 35 0d 04 02 23 6d 65 72 67 65 merge=5...#merge +| 4048: 3d 31 30 30 2c 38 11 03 02 2b 69 6e 74 65 67 72 =100,8...+integr +| 4064: 69 74 79 2d 63 68 65 63 6b 09 02 02 1b 72 65 62 ity-check....reb +| 4080: 75 69 6c 64 0a 01 02 1d 6f 70 74 69 6d 69 7a 65 uild....optimize +| end crash-c666cfde112dee.db +}]} {} + +do_catchsql_test 13.1 { + SELECT quote(matchinfo(t1,'pcxybs'))==0 FROM t1 WHERE b MATCH 'e*'; +} {0 {}} + +#------------------------------------------------------------------------- +reset_db +do_test 14.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 28672 pagesize 4096 filename crash-f7b636a855e1d2.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07 .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ +| 96: 00 00 00 00 0d 0e ef 00 07 0d 4d 00 0f bd 0f 5f ..........M...._ +| 112: 0e f7 0e 06 0e bc 0d a4 0d 4d 00 00 00 00 00 00 .........M...... +| 3392: 00 00 00 00 00 00 00 00 00 00 00 00 00 55 07 07 .............U.. +| 3408: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 73 74 ......tablet1_st +| 3424: 61 74 74 31 5f 73 74 61 74 07 43 52 45 41 54 45 att1_stat.CREATE +| 3440: 20 54 41 42 4c 45 20 27 74 31 5f 73 74 61 74 27 TABLE 't1_stat' +| 3456: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d (id INTEGER PRIM +| 3472: 41 52 59 20 4b 45 59 2c 20 76 61 6c 75 65 20 42 ARY KEY, value B +| 3488: 4c 4f 42 29 60 06 07 17 21 21 01 81 0b 74 61 62 LOB)`...!!...tab +| 3504: 6c 65 74 31 5f 64 6f 63 73 69 7a 65 74 31 5f 64 let1_docsizet1_d +| 3520: 6f 63 73 69 7a 65 06 43 52 45 41 54 45 20 54 41 ocsize.CREATE TA +| 3536: 42 4c 45 20 27 74 31 5f 64 6f 63 73 69 7a 65 27 BLE 't1_docsize' +| 3552: 28 64 6f 63 69 64 20 49 4e 54 45 47 45 52 20 50 (docid INTEGER P +| 3568: 52 49 4d 41 52 59 20 4b 45 59 2c 20 73 69 7a 65 RIMARY KEY, size +| 3584: 20 42 4c 4f 42 29 81 33 04 07 17 1f 1f 01 82 35 BLOB).3.......5 +| 3600: 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72 74 31 tablet1_segdirt1 +| 3616: 5f 73 65 67 64 69 25 04 43 52 45 41 54 45 20 54 _segdi%.CREATE T +| 3632: 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69 72 27 ABLE 't1_segdir' +| 3648: 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52 2c 69 (level INTEGER,i +| 3664: 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61 72 74 dx INTEGER,start +| 3680: 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52 2c 6c _block INTEGER,l +| 3696: 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 6b 20 eaves_end_block +| 3712: 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c 6f 63 INTEGER,end_bloc +| 3728: 6b 20 49 4e 54 45 47 45 52 2c 72 6f 6f 74 20 42 k INTEGER,root B +| 3744: 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45 59 28 LOB,PRIMARY KEY( +| 3760: 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 05 06 17 level, idx))1... +| 3776: 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74 65 5f E...indexsqlite_ +| 3792: 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73 65 67 autoindex_t1_seg +| 3808: 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72 05 00 dir_1t1_segdir.. +| 3824: 00 00 08 00 00 00 00 66 03 07 17 23 23 01 81 13 .......f...##... +| 3840: 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e 74 73 tablet1_segments +| 3856: 74 31 5f 73 65 67 6d 65 6e 74 73 03 43 52 45 41 t1_segments.CREA +| 3872: 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 TE TABLE 't1_seg +| 3888: 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64 20 49 ments'(blockid I +| 3904: 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b NTEGER PRIMARY K +| 3920: 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 29 5c EY, block BLOB). +| 3936: 02 07 17 21 21 01 81 03 74 61 62 6c 65 74 31 5f ...!!...tablet1_ +| 3952: 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 65 6e contentt1_conten +| 3968: 74 02 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 t.CREATE TABLE ' +| 3984: 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f 63 69 t1_content'(doci +| 4000: 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 d INTEGER PRIMAR +| 4016: 59 20 4b 45 59 2c 20 27 63 30 61 27 29 41 01 06 Y KEY, 'c0a')A.. +| 4032: 17 11 11 08 71 74 61 62 6c 65 74 31 74 31 43 52 ....qtablet1t1CR +| 4048: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB +| 4064: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 34 LE t1 USING fts4 +| 4080: 28 61 2c 70 72 65 66 69 78 3d 27 31 2c 32 27 29 (a,prefix='1,2') +| page 2 offset 4096 +| 0: 0d 00 00 00 08 0e 1f 00 0f c4 0f 7c 0f 34 0f 07 ...........|.4.. +| 16: 0e c3 0e 97 0e 63 0e 1f 00 00 00 00 00 00 00 00 .....c.......... +| 3600: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 42 ...............B +| 3616: 08 04 00 81 09 73 75 6e 74 20 69 6e 20 63 75 6c .....sunt in cul +| 3632: 70 61 20 71 75 69 20 6f 66 66 69 63 69 61 20 64 pa qui officia d +| 3648: 65 73 65 72 75 6e 74 20 6d 6f 6c 6c 69 74 20 61 eserunt mollit a +| 3664: 6e 69 6d 20 69 64 20 65 73 74 20 6c 61 62 6f 72 nim id est labor +| 3680: 75 6d 2e 32 07 03 01 6b 45 78 63 65 70 74 65 75 um.2...kExcepteu +| 3696: 72 20 73 69 6e 74 20 6f 63 63 61 65 63 61 74 20 r sint occaecat +| 3712: 63 75 70 69 64 61 74 61 74 20 6e 6f 6e 20 70 72 cupidatat non pr +| 3728: 6f 69 64 65 6e 74 2c 2a 06 03 00 5b 63 69 6c 6c oident,*...[cill +| 3744: 75 6d 20 64 6f 6c 6f 72 65 20 65 75 20 66 75 67 um dolore eu fug +| 3760: 69 61 74 20 6e 75 6c 6c 61 20 70 61 72 69 61 74 iat nulla pariat +| 3776: 75 72 2e 43 05 04 00 81 09 44 75 69 73 20 61 75 ur.C.....Duis au +| 3792: 74 65 20 69 72 75 72 65 20 64 6f 6c 6f 72 20 69 te irure dolor i +| 3808: 6e 20 72 65 70 72 65 68 65 6e 64 65 72 69 74 20 n reprehenderit +| 3824: 69 6e 20 76 6f 6c 75 70 74 61 74 65 20 76 65 6c in voluptate vel +| 3840: 69 74 20 65 73 73 65 2b 14 03 00 5d 6e 69 73 69 it esse+...]nisi +| 3856: 20 75 74 20 61 6c 69 71 75 69 70 20 65 78 20 65 ut aliquip ex e +| 3872: 61 20 63 6f 6d 6d 6f 64 6f 20 63 6f 6e 73 65 71 a commodo conseq +| 3888: 75 61 74 2e 46 03 04 00 81 11 55 74 20 65 6e 69 uat.F.....Ut eni +| 3904: 6d 20 61 64 20 6d 69 6e 69 6d 20 76 65 6e 69 61 m ad minim venia +| 3920: 6d 2c 20 71 75 69 73 20 6e 6f 73 74 72 75 64 20 m, quis nostrud +| 3936: 65 78 65 72 63 69 74 61 74 69 6f 6e 20 75 6c 6c exercitation ull +| 3952: 61 6d 63 6f 20 6c 61 62 6f 72 69 73 46 02 04 00 amco laborisF... +| 3968: 81 11 73 65 64 20 64 6f 20 65 69 75 73 6d 6f 64 ..sed do eiusmod +| 3984: 20 74 65 6d 70 6f 72 20 69 6e 63 69 64 69 64 75 tempor incididu +| 4000: 6e 74 20 75 74 20 6c 61 62 6f 72 65 20 65 74 20 nt ut labore et +| 4016: 64 6f 6c 6f 72 65 20 6d 61 67 6e 61 20 61 6c 69 dolore magna ali +| 4032: 71 75 61 2e 3a 01 03 00 7b 4c 6f 72 65 6d 20 69 qua.:....Lorem i +| 4048: 70 73 75 6d 20 64 6f 6c 6f 72 20 73 69 74 20 61 psum dolor sit a +| 4064: 6d 65 74 2c 20 63 6f 6e 73 65 63 74 65 74 75 72 met, consectetur +| 4080: 20 61 64 69 70 69 73 63 69 6e 67 20 65 6c 69 74 adipiscing elit +| page 3 offset 8192 +| 0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................ +| page 4 offset 12288 +| 0: 0d 00 00 00 03 0a a6 00 0d 57 0c 4a 0a a6 00 00 .........W.J.... +| 2720: 00 00 00 00 00 00 83 21 03 08 02 08 08 08 17 86 .......!........ +| 2736: 30 08 00 30 20 34 30 32 00 02 61 64 06 01 08 00 0..0 402..ad.... +| 2752: 02 04 00 01 01 6c 06 02 0c 00 02 04 00 01 01 6d .....l.........m +| 2768: 03 01 06 00 01 01 6e 03 08 09 00 01 01 75 03 05 ......n......u.. +| 2784: 03 00 00 02 63 69 03 06 01 00 01 01 6f 07 01 07 ....ci......o... +| 2800: 00 03 07 03 00 01 01 75 06 07 05 00 01 04 00 00 .......u........ +| 2816: 02 64 65 03 08 07 00 01 01 6f 0d 01 04 00 01 03 .de......o...... +| 2832: 09 00 03 05 00 01 03 00 01 01 75 03 05 02 00 00 ..........u..... +| 2848: 02 65 61 03 04 06 00 01 01 69 03 02 04 00 01 01 .ea......i...... +| 2864: 6c 03 01 09 00 01 01 6e 03 03 03 00 01 01 73 06 l......n......s. +| 2880: 05 0b 00 03 0b 00 01 01 74 03 02 09 00 01 01 75 ........t......u +| 2896: 03 06 04 00 01 01 78 09 03 09 00 01 05 00 03 02 ......x......... +| 2912: 00 00 02 66 75 03 06 05 00 00 02 69 64 03 08 0a ...fu......id... +| 2928: 00 01 01 6e 0a 02 06 00 03 06 04 00 03 03 00 01 ...n............ +| 2944: 01 70 03 01 13 00 01 01 72 03 05 04 00 00 02 6c .p......r......l +| 2960: 61 09 02 08 00 01 0b 00 05 0c 00 01 01 6f 03 01 a............o.. +| 2976: 02 00 00 02 6d 61 03 02 0b 00 01 01 69 03 04 05 ....ma......i... +| 2992: 00 01 01 6f 03 08 08 00 00 02 6e 69 03 04 02 00 ...o......ni.... +| 3008: 01 01 6f 06 03 08 00 04 06 00 01 01 75 03 06 06 ..o.........u... +| 3024: 00 00 02 6f 63 03 07 04 00 01 01 66 03 08 06 00 ...oc......f.... +| 3040: 00 02 70 61 03 06 07 00 01 01 72 03 07 07 00 00 ..pa......r..... +| 3056: 02 71 75 06 03 07 00 05 05 00 00 02 72 65 03 05 .qu.........re.. +| 3072: 07 00 00 02 73 65 03 02 02 00 01 01 69 06 01 05 ....se......i... +| 3088: 00 06 03 00 01 01 75 03 08 02 00 00 02 74 65 03 ......u......te. +| 3104: 03 05 00 00 02 75 6c 03 03 0a 00 01 01 74 09 02 .....ul......t.. +| 3120: 07 00 01 02 00 01 03 00 00 02 76 65 06 03 06 00 ..........ve.... +| 3136: 02 0a 00 01 01 6f 03 05 09 00 82 0a 02 08 02 08 .....o.......... +| 3152: 08 08 17 84 02 04 00 30 20 32 35 31 00 01 61 13 .......0 251..a. +| 3168: 01 06 04 00 01 0c 00 01 04 00 01 04 00 01 03 00 ................ +| 3184: 03 09 00 00 01 63 10 01 07 00 03 07 03 00 02 02 .....c.......... +| 3200: 00 01 05 00 01 04 00 00 01 64 11 01 04 00 01 03 .........d...... +| 3216: 09 00 03 02 05 00 01 03 00 02 07 00 00 01 65 1b ..............e. +| 3232: 01 09 00 01 04 07 00 01 03 08 00 01 05 03 00 01 ................ +| 3248: 0b 00 01 04 00 01 02 00 01 0b 00 00 01 66 03 06 .............f.. +| 3264: 05 00 00 01 69 0f 01 03 00 01 06 00 03 04 04 04 ....i........... +| 3280: 00 03 03 09 00 00 01 6c 0c 01 02 00 01 08 00 01 .......l........ +| 3296: 0b 00 05 0c 00 00 01 6d 09 02 0b 00 01 05 00 05 .......m........ +| 3312: 08 00 00 01 6e 0c 03 08 00 01 02 00 02 06 00 01 ....n........... +| 3328: 06 00 00 01 6f 06 07 04 00 01 06 00 00 01 70 06 ....o.........p. +| 3344: 06 07 00 01 07 00 00 01 71 06 03 07 00 05 05 00 ........q....... +| 3360: 00 01 72 03 05 08 00 00 01 73 0c 01 05 00 01 02 ..r......s...... +| 3376: 00 05 03 00 01 02 00 00 01 74 03 02 05 00 00 01 .........t...... +| 3392: 75 0a 02 07 00 01 02 0a 00 01 03 00 00 01 76 07 u.............v. +| 3408: 03 06 00 02 09 03 00 85 26 01 08 08 08 08 08 17 ........&....... +| 3424: 8a 3e 30 20 36 36 35 00 02 61 64 03 03 04 00 02 .>0 665..ad..... +| 3440: 08 69 70 69 73 63 69 6e 67 03 01 08 00 01 05 6c .ipiscing......l +| 3456: 69 71 75 61 03 02 0c 00 05 02 69 70 03 04 04 00 iqua......ip.... +| 3472: 01 03 6d 65 74 03 01 06 00 01 03 6e 69 6d 03 08 ..met......nim.. +| 3488: 09 00 01 03 75 74 65 03 05 03 00 00 06 63 69 6c ....ute......cil +| 3504: 6c 75 6d 03 06 02 00 01 06 6f 6d 6d 6f 64 6f 03 lum......ommodo. +| 3520: 04 07 00 02 09 6e 73 65 63 74 65 74 75 72 03 01 .....nsectetur.. +| 3536: 07 00 05 04 71 75 61 74 03 04 08 00 01 04 75 6c ....quat......ul +| 3552: 70 61 03 08 04 00 02 07 70 69 64 61 74 61 74 03 pa......pidatat. +| 3568: 07 05 00 00 08 64 65 73 65 72 75 6e 74 03 08 07 .....deserunt... +| 3584: 00 01 01 6f 03 02 03 00 02 03 6c 6f 72 06 01 04 ...o......lor... +| 3600: 00 04 05 00 05 01 65 06 02 0a 00 04 03 00 01 03 ......e......... +| 3616: 75 69 73 03 05 02 00 00 02 65 61 03 04 06 00 01 uis......ea..... +| 3632: 06 69 75 73 6d 6f 64 03 02 04 00 01 03 6c 69 74 .iusmod......lit +| 3648: 03 01 09 00 01 03 6e 69 6d 03 03 03 00 01 03 73 ......nim......s +| 3664: 73 65 03 05 0b 00 02 01 73 03 08 0b 00 01 01 74 se......s......t +| 3680: 03 02 09 00 01 01 75 03 06 04 00 01 01 78 03 04 ......u......x.. +| 3696: 05 00 02 07 63 65 70 74 65 75 72 03 07 02 00 02 ....cepteur..... +| 3712: 0a 65 72 63 69 74 61 74 69 6f 6e 03 03 09 00 00 .ercitation..... +| 3728: 06 66 75 67 69 61 74 03 06 05 00 00 02 69 64 03 .fugiat......id. +| 3744: 08 0a 00 01 01 6e 07 05 06 04 00 03 03 00 02 08 .....n.......... +| 3760: 63 69 64 69 64 75 6e 74 03 02 06 00 01 04 70 73 cididunt......ps +| 3776: 75 6d 03 01 03 00 01 04 72 75 72 65 03 05 04 00 um......rure.... +| 3792: 00 06 6c 61 62 6f 72 65 03 02 08 00 05 02 69 73 ..labore......is +| 3808: 03 03 0b 00 05 02 75 6d 03 08 0c 00 01 04 6f 72 ......um......or +| 3824: 65 6d 03 01 02 00 00 05 6d 61 67 6e 61 03 02 0b em......magna... +| 3840: 00 01 04 69 6e 69 6d 03 03 05 00 01 05 6f 6c 6c ...inim......oll +| 3856: 69 74 03 08 08 00 00 04 6e 69 73 69 03 04 02 00 it......nisi.... +| 3872: 01 02 6f 6e 03 07 06 00 02 05 73 74 72 75 64 03 ..on......strud. +| 3888: 03 08 00 01 04 75 6c 6c 61 03 06 06 00 00 08 6f .....ulla......o +| 3904: 63 63 61 65 63 61 74 03 07 04 00 01 06 66 66 69 ccaecat......ffi +| 3920: 63 69 61 03 08 06 00 00 08 70 61 72 69 61 74 75 cia......pariatu +| 3936: 72 03 06 07 00 01 07 72 6f 69 64 65 6e 74 03 07 r......roident.. +| 3952: 07 00 00 03 71 75 69 03 08 05 00 03 01 73 03 03 ....qui......s.. +| 3968: 07 00 00 0d 72 65 70 72 65 68 65 6e 64 65 72 69 ....reprehenderi +| 3984: 74 03 05 07 00 00 03 73 65 64 03 02 02 00 01 03 t......sed...... +| 4000: 69 6e 74 03 07 03 00 02 01 74 03 01 05 00 01 03 int......t...... +| 4016: 75 6e 74 03 08 02 00 00 06 74 65 6d 70 6f 72 03 unt......tempor. +| 4032: 02 05 00 00 07 75 6c 6c 61 6d 63 6f 03 03 0a 00 .....ullamco.... +| 4048: 01 01 74 09 02 07 00 01 02 00 01 03 00 00 05 76 ..t............v +| 4064: 65 6c 69 74 03 05 0a 00 02 04 6e 69 61 6d 03 03 elit......niam.. +| 4080: 06 00 01 08 6f 6c 75 70 74 61 74 65 03 05 09 00 ....oluptate.... +| page 5 offset 16384 +| 0: 0a 00 00 00 03 0f eb 00 0f fb 0f f3 0f eb 00 00 ................ +| 4064: 00 00 00 00 00 00 00 00 00 00 00 07 04 02 08 01 ................ +| 4080: 08 00 03 07 04 02 08 01 04 00 02 04 04 08 08 09 ................ +| page 6 offset 20480 +| 0: 0d 00 00 00 08 0f d0 00 0f fa 0f f4 0f ee 0f e8 ................ +| 16: 0f e2 0f dc 0f d6 0f d0 00 00 00 00 00 00 00 00 ................ +| 4048: 04 08 03 00 0e 0b 04 07 03 00 0e 06 04 06 03 00 ................ +| 4064: 0e 06 04 05 03 00 0e 0a 04 04 03 00 0e 07 04 03 ................ +| 4080: 03 00 0e 0a 04 02 03 00 0e 0b 04 01 03 00 0e 08 ................ +| page 7 offset 24576 +| 0: 0d 00 00 00 01 0f f7 00 0f f7 00 00 00 00 00 00 ................ +| 4080: 00 00 00 00 00 00 00 07 00 03 00 14 08 45 b5 03 .............E.. +| end crash-f7b636a855e1d2.db +}]} {} + +do_execsql_test 14.1 { + PRAGMA writable_schema = 1; + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<10) + INSERT INTO t1(a) SELECT randomblob(3000) FROM c; +} + +do_catchsql_test 14.2 { + INSERT INTO t1(t1) VALUES('optimize'); +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 15.0 { + CREATE VIRTUAL TABLE t1 USING fts3(a, content=""); + INSERT INTO t1_segdir VALUES(0,0,0,0,'0 665',X'000261640303040002086970697363696e670301080001056c6971756103020c00050269700304040001036d65740301060001036e6a6d03080900010375746503050300000663696c6c756d0306020001066f6d6d6f646f0304070002096e736563746574757203010700050471756174030408000104756c7061030804000207706964617461740307050000086465736572756e740308070001016f0302030002036c6f720601040004050005016506020a00040300010375697303050200000265610304060001066975736d6f640302040001036c69740301090001036e696d13030300010373736503050b0002017403080b0001017403020900010175030604000101780304050002076365707465757203070100020a65726369746174696f6e030309000006667567696174030605000002696403080a0001016e070506040003030002086369646964756e740302060001047073756d030103000104727572650305040000066c61626f7265030208000502697303030b000502756d03080c0001046f72656d0301020000056d61676e6103020b000104696e696d0303050001056f6c6c69740308080000046e6973690304020001026f6e0307060002057374727564030308000104756c6c610306060000086f636361656361740307040001066666696369610308060000087061726961747572030607000107726f6964656e740307070000037175690308050003017303030700000d726570726568656e6465726974030507000003736564030202000103696e7403070300020174030105000103756e7403080200000674656d706f72030205000007756c6c616d636f03030a0001017409020700010200010300000576656c697403050a0002046e69616d0303060001086f6c75707461746503050900'); +} + +do_execsql_test 15.1 { + SELECT quote(matchinfo(t1, t1 ))==0 FROM t1 WHERE t1 MATCH 'e*'; +} {0 0 0 0 0 0} + +#------------------------------------------------------------------------- +reset_db +do_test 16.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 28672 pagesize 4096 filename crash-de7e8cb026385a.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07 .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ +| 96: 00 00 00 00 0d 0e ef 00 07 0d 4d 00 0f bd 0f 5f ..........M...._ +| 112: 0e f7 0e 06 0e bc 0d a4 0d 4d 00 00 00 00 00 00 .........M...... +| 3392: 00 00 00 00 00 00 00 00 00 00 00 00 00 55 07 07 .............U.. +| 3408: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 73 74 ......tablet1_st +| 3424: 61 74 74 31 5f 73 74 61 74 07 43 52 45 41 54 45 att1_stat.CREATE +| 3440: 20 54 41 42 4c 45 20 27 74 31 5f 73 74 61 74 27 TABLE 't1_stat' +| 3456: 28 69 64 20 49 af 54 45 47 45 52 20 50 52 49 4d (id I.TEGER PRIM +| 3472: 41 52 59 20 4b 45 59 2c 20 76 61 6c 75 65 20 42 ARY KEY, value B +| 3488: 4c 4f 42 29 60 06 07 17 21 21 01 81 0b 74 61 62 LOB)`...!!...tab +| 3504: 6c 65 74 31 5f 64 6f 63 73 69 7a 65 74 31 5f 64 let1_docsizet1_d +| 3520: 6f 63 73 69 7a 65 06 43 52 45 41 54 45 20 54 41 ocsize.CREATE TA +| 3536: 42 4c 45 20 27 74 31 5f 64 6f 63 73 69 7a 65 27 BLE 't1_docsize' +| 3552: 28 64 6f 63 69 64 20 49 4e 54 45 47 45 52 20 50 (docid INTEGER P +| 3568: 52 49 4d 41 52 59 20 4b 45 59 2c 20 73 69 7a 65 RIMARY KEY, size +| 3584: 20 42 4c 4f 42 29 81 33 04 07 17 1f 1f 01 82 35 BLOB).3.......5 +| 3600: 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72 74 31 tablet1_segdirt1 +| 3616: 5f 73 65 67 64 69 72 04 43 52 45 41 54 45 20 54 _segdir.CREATE T +| 3632: 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69 72 27 ABLE 't1_segdir' +| 3648: 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52 2c 69 (level INTEGER,i +| 3664: 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61 72 74 dx INTEGER,start +| 3680: 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52 2c 6c _block INTEGER,l +| 3696: 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 6b 20 eaves_end_block +| 3712: 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c 6f 63 INTEGER,end_bloc +| 3728: 6b 20 49 4e 54 45 47 45 52 2c 72 6f 6f 74 20 42 k INTEGER,root B +| 3744: 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45 59 28 LOB,PRIMARY KEY( +| 3760: 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 05 06 17 level, idx))1... +| 3776: 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74 65 5f E...indexsqlite_ +| 3792: 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73 65 67 autoindex_t1_seg +| 3808: 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72 05 00 dir_1t1_segdir.. +| 3824: 00 00 08 00 00 00 00 66 03 07 17 23 23 01 81 13 .......f...##... +| 3840: 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e 74 73 tablet1_segments +| 3856: 74 31 5f 73 65 67 6d 65 6e 74 73 03 43 52 45 41 t1_segments.CREA +| 3872: 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 TE TABLE 't1_seg +| 3888: 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64 20 49 ments'(blockid I +| 3904: 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b NTEGER PRIMARY K +| 3920: 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 29 5c EY, block BLOB). +| 3936: 02 07 17 21 21 01 81 03 74 61 62 6c 65 74 31 5f ...!!...tablet1_ +| 3952: 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 65 6e contentt1_conten +| 3968: 74 02 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 t.CREATE TABLE ' +| 3984: 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f 63 69 t1_content'(doci +| 4000: 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 d INTEGER PRIMAR +| 4016: 59 20 4b 45 59 2c 20 27 63 30 61 27 29 41 01 06 Y KEY, 'c0a')A.. +| 4032: 17 11 11 08 71 74 61 62 6c 65 74 31 74 31 43 52 ....qtablet1t1CR +| 4048: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB +| 4064: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 34 LE t1 USING fts4 +| 4080: 28 61 2c 70 72 65 66 69 78 3d 27 31 2c 32 27 29 (a,prefix='1,2') +| page 2 offset 4096 +| 0: 0d 00 00 00 08 0e 1f 00 0f c4 0f 7c 0f 34 0f 07 ...........|.4.. +| 16: 0e c3 0e 97 0e 63 0e 1f 00 00 00 00 00 00 00 00 .....c.......... +| 3600: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 42 ...............B +| 3616: 08 04 00 81 09 73 75 6e 74 20 69 6e 20 63 75 6c .....sunt in cul +| 3632: 70 61 20 71 75 69 20 6f 66 66 69 63 69 61 20 64 pa qui officia d +| 3648: 65 73 65 72 75 6e 74 20 6d 6f 6c 6c 69 74 20 61 eserunt mollit a +| 3664: 6e 69 6d 20 69 64 20 65 73 74 20 6c 61 62 6f 72 nim id est labor +| 3680: 75 6d 2e 32 07 03 00 6b 45 78 63 65 70 74 65 75 um.2...kExcepteu +| 3696: 72 20 73 69 6e 74 20 6f 63 63 61 65 63 61 74 20 r sint occaecat +| 3712: 63 75 70 69 64 61 74 61 74 20 6e 6f 6e 20 70 72 cupidatat non pr +| 3728: 6f 69 64 65 6e 74 2c 2a 06 03 00 5b 63 69 6c 6c oident,*...[cill +| 3744: 75 6d 20 64 6f 6c 6f 72 65 20 65 75 20 66 75 67 um dolore eu fug +| 3760: 69 61 74 20 6e 75 6c 6c 61 20 70 61 72 69 61 74 iat nulla pariat +| 3776: 75 72 2e 42 05 04 00 81 09 44 75 69 73 20 61 75 ur.B.....Duis au +| 3792: 74 65 20 69 72 75 72 65 21 64 6f 6c 6f 72 20 69 te irure!dolor i +| 3808: 6e 20 72 65 70 72 65 68 65 6e 64 65 72 69 74 20 n reprehenderit +| 3824: 69 6e 20 76 6f 6c 75 70 74 61 74 65 20 76 65 6c in voluptate vel +| 3840: 69 74 20 65 73 74 65 2b 04 03 00 5d 6e 69 73 69 it este+...]nisi +| 3856: 20 75 74 20 61 6c 69 71 75 69 70 20 65 78 20 65 ut aliquip ex e +| 3872: 61 20 63 6f 6d 6d 6f 64 6f 20 63 6f 6e 73 65 71 a commodo conseq +| 3888: 75 61 74 2e 46 03 04 00 81 11 55 74 20 65 6e 69 uat.F.....Ut eni +| 3904: 6d 20 61 64 20 6d 69 6e 69 6d 20 76 65 6e 69 61 m ad minim venia +| 3920: 6d 2c 20 71 75 69 73 20 6e 6f 73 74 72 75 64 20 m, quis nostrud +| 3936: 65 78 65 72 63 69 74 61 74 69 6f 6e 20 75 6c 6c exercitation ull +| 3952: 61 6d 63 6f 20 6c 61 62 6f 72 69 73 46 02 04 00 amco laborisF... +| 3968: 81 11 73 65 64 20 64 6f 20 65 69 75 73 6d 6f 64 ..sed do eiusmod +| 3984: 20 74 65 6d 70 6f 72 20 69 6e 63 69 64 69 64 75 tempor incididu +| 4000: 6e 74 20 75 74 20 6c 61 62 6f 72 65 20 65 74 20 nt ut labore et +| 4016: 64 6f 6c 6f 72 65 20 6d 61 67 6e 61 20 51 6c 69 dolore magna Qli +| 4032: 71 75 61 2e 3a 01 03 00 7b 4c 6f 72 65 6d 20 69 qua.:....Lorem i +| 4048: 70 73 75 6d 20 64 6f 6c 6f 72 20 73 69 74 e5 61 psum dolor sit.a +| 4064: 6d 65 74 2c 20 63 6f 6e 73 65 63 74 65 74 75 72 met, consectetur +| 4080: 20 61 64 69 70 69 73 63 69 6e 67 20 65 6c 69 74 adipiscing elit +| page 3 offset 8192 +| 0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................ +| page 4 offset 12288 +| 0: 0d 00 00 00 03 0a a6 00 0d 57 0c 4a 0a a6 00 00 .........W.J.... +| 2720: 00 00 00 00 00 00 83 21 03 08 02 08 08 08 17 86 .......!........ +| 2736: 30 08 00 30 20 34 30 32 00 02 61 64 06 01 08 00 0..0 402..ad.... +| 2752: 02 04 00 01 01 6c 06 02 0c 00 02 04 00 01 01 6d .....l.........m +| 2768: 03 01 06 00 01 01 6e 03 08 09 00 01 01 75 03 05 ......n......u.. +| 2784: 03 00 00 02 63 69 03 06 02 00 01 01 6f 07 01 07 ....ci......o... +| 2800: 00 03 07 03 00 01 01 75 06 07 05 00 01 04 00 00 .......u........ +| 2816: 02 64 65 03 08 07 00 01 01 6f 0d 01 04 00 01 03 .de......o...... +| 2832: 09 00 03 05 00 01 03 00 01 01 75 03 05 02 00 00 ..........u..... +| 2848: 02 65 61 03 04 06 00 01 01 69 03 02 04 00 01 01 .ea......i...... +| 2864: 6c 03 01 09 00 01 01 6e 03 03 03 00 01 01 73 06 l......n......s. +| 2880: 05 0b 00 03 0b 00 01 01 74 03 02 09 00 01 01 75 ........t......u +| 2896: 03 06 04 00 01 01 78 09 03 09 00 01 05 00 03 02 ......x......... +| 2912: 00 00 02 66 75 03 06 05 00 00 02 69 64 03 08 0a ...fu......id... +| 2928: 00 01 01 6e 0a 02 06 00 03 06 04 00 03 03 00 01 ...n............ +| 2944: 01 70 03 01 03 00 01 01 72 03 05 04 00 00 02 6c .p......r......l +| 2960: 61 09 02 08 00 01 0b 00 05 0c 00 01 01 6f 03 01 a............o.. +| 2976: 02 00 00 02 6d 61 03 02 0b 00 01 01 69 03 03 05 ....ma......i... +| 2992: 00 01 01 6f 03 08 08 00 00 02 6e 69 03 04 02 00 ...o......ni.... +| 3008: 01 01 6f 06 03 08 00 04 06 00 01 01 75 03 06 06 ..o.........u... +| 3024: 00 00 02 6f 63 03 07 04 00 01 01 66 03 08 06 00 ...oc......f.... +| 3040: 00 02 70 61 03 06 07 00 01 01 72 03 07 07 00 00 ..pa......r..... +| 3056: 02 71 75 06 03 07 00 05 05 00 00 02 72 65 03 05 .qu.........re.. +| 3072: 07 00 00 02 73 65 03 02 02 00 01 01 69 06 01 05 ....se......i... +| 3088: 00 06 03 00 01 01 75 03 08 02 00 00 02 74 65 03 ......u......te. +| 3104: 02 05 00 00 02 75 6c 03 03 0a 00 01 01 74 09 02 .....ul......t.. +| 3120: 07 00 01 02 00 01 03 00 00 02 76 65 06 03 06 00 ..........ve.... +| 3136: 02 0a 00 01 01 6f 03 05 09 00 82 0a 02 08 12 08 .....o.......... +| 3152: 08 08 17 84 02 04 00 30 20 32 35 31 00 01 61 23 .......0 251..a# +| 3168: 01 06 04 00 01 0c 00 01 04 00 01 04 00 01 03 00 ................ +| 3184: 03 09 00 00 01 63 10 01 07 00 03 07 03 00 02 02 .....c.......... +| 3200: 00 01 05 00 01 04 00 00 01 64 11 01 04 00 01 03 .........d...... +| 3216: 09 00 03 02 05 00 01 13 00 02 07 00 00 01 65 1b ..............e. +| 3232: 01 09 00 01 04 07 00 01 03 08 00 01 05 03 00 01 ................ +| 3248: 0b 00 01 04 00 01 02 00 01 0b 00 00 01 66 03 06 .............f.. +| 3264: 05 00 00 01 69 0f 01 03 00 01 06 00 03 04 04 04 ....i........... +| 3280: 00 03 03 09 00 00 01 6c 0c 01 02 00 01 08 00 01 .......l........ +| 3296: 0b 00 05 0c 00 10 01 6d 09 02 0b 00 01 05 00 05 .......m........ +| 3312: 08 00 00 01 6e 0c 03 08 00 01 02 00 02 06 00 01 ....n........... +| 3328: 06 00 00 01 6f 06 07 04 00 01 06 00 00 01 70 06 ....o.........p. +| 3344: 06 07 00 01 07 00 00 01 71 06 03 07 00 05 05 00 ........q....... +| 3360: 00 01 72 03 05 07 00 00 01 73 0c 01 05 00 01 02 ..r......s...... +| 3376: 00 05 03 00 01 02 00 00 01 74 03 02 05 00 00 01 .........t...... +| 3392: 75 0a 02 07 00 01 02 0a 00 01 03 00 00 01 76 07 u.............v. +| 3408: 03 06 00 02 09 03 00 85 26 01 08 08 08 08 08 17 ........&....... +| 3424: 8a 3e 30 20 36 36 35 00 02 61 64 03 03 04 00 02 .>0 665..ad..... +| 3440: 08 69 70 69 73 63 69 6e 67 03 01 08 00 01 05 6c .ipiscing......l +| 3456: 69 71 75 61 03 02 0c 00 05 02 69 70 03 04 04 00 iqua......ip.... +| 3472: 01 03 6d 65 74 03 01 06 00 01 03 6e 69 6d 03 08 ..met......nim.. +| 3488: 09 00 01 03 75 74 65 03 05 03 00 00 06 63 69 6c ....ute......cil +| 3504: 6c 75 6d 03 06 02 00 01 06 6f 6d 6d 6f 64 6f 03 lum......ommodo. +| 3520: 04 07 00 02 09 6e 73 65 63 74 65 74 75 72 03 01 .....nsectetur.. +| 3536: 07 00 05 04 71 75 61 74 03 04 08 00 01 04 75 6c ....quat......ul +| 3552: 70 61 03 08 04 00 02 07 70 69 64 61 74 61 74 03 pa......pidatat. +| 3568: 07 05 00 00 08 64 65 73 65 72 75 6e 74 03 08 07 .....deserunt... +| 3584: 00 01 01 6f 03 02 03 00 02 03 6c 6f 72 06 01 04 ...o......lor... +| 3600: 00 04 05 00 05 01 65 06 02 0a 00 04 03 00 01 03 ......e......... +| 3616: 75 69 73 03 05 02 00 00 02 65 61 03 04 06 00 01 uis......ea..... +| 3632: 06 69 75 73 6d 6f 64 03 02 04 00 01 03 6c 69 74 .iusmod......lit +| 3648: 03 01 09 00 01 03 6e 69 6d 03 03 03 00 01 03 73 ......nim......s +| 3664: 73 65 03 05 0b 00 02 01 74 03 08 0b 00 01 01 74 se......t......t +| 3680: 03 02 09 00 01 01 75 03 06 04 00 01 01 78 03 04 ......u......x.. +| 3696: 05 00 02 07 63 65 70 74 65 75 72 03 07 02 00 02 ....cepteur..... +| 3712: 0a 65 72 63 69 74 61 74 69 6f 6e 03 03 09 00 00 .ercitation..... +| 3728: 06 66 75 67 69 61 74 03 06 05 00 00 02 69 64 03 .fugiat......id. +| 3744: 08 0a 00 01 01 6e 07 05 06 04 00 03 03 00 02 08 .....n.......... +| 3760: 63 69 64 69 64 75 7e 74 03 02 06 00 01 04 70 73 cididu~t......ps +| 3776: 75 6d 03 01 03 00 01 03 72 75 72 65 03 05 04 00 um......rure.... +| 3792: 00 06 6c 61 62 6f 72 65 03 02 08 00 05 02 69 73 ..labore......is +| 3808: 03 03 0b 00 05 02 75 6d 03 08 0c 00 01 04 6f 72 ......um......or +| 3824: 65 6d 03 01 02 00 00 05 6d 61 67 6e 61 03 02 0b em......magna... +| 3840: 00 01 04 69 6e 69 6d 03 03 05 00 01 05 6f 6c 6c ...inim......oll +| 3856: 69 74 03 08 08 00 00 04 6e 69 73 69 03 04 02 00 it......nisi.... +| 3872: 01 02 6f 6e 03 07 06 00 02 05 73 74 72 75 64 03 ..on......strud. +| 3888: 03 08 00 01 04 75 6c 6c 61 03 06 06 00 00 08 6f .....ulla......o +| 3904: 63 63 61 65 63 61 74 03 07 04 00 01 06 66 66 69 ccaecat......ffi +| 3920: 63 69 61 03 08 06 00 00 08 70 61 72 69 61 74 75 cia......pariatu +| 3936: 72 03 06 07 00 01 07 72 6f 69 64 65 6e 74 03 07 r......roident.. +| 3952: 07 00 00 03 71 75 69 03 08 05 00 03 01 73 03 03 ....qui......s.. +| 3968: 07 00 00 0d 72 65 70 72 65 68 65 6e 64 65 72 69 ....reprehenderi +| 3984: 74 03 05 07 00 00 03 73 65 64 03 02 02 00 01 03 t......sed...... +| 4000: 69 6e 74 03 07 03 00 02 01 74 03 01 05 00 01 03 int......t...... +| 4016: 75 6e 74 03 08 02 00 00 06 74 65 6d 70 6f 72 03 unt......tempor. +| 4032: 02 05 00 00 07 75 6c 6c 61 6d 63 6f 03 03 0a 00 .....ullamco.... +| 4048: 01 01 74 09 02 07 00 01 02 00 01 03 00 00 05 76 ..t............v +| 4064: 65 6c 69 74 03 05 0a 00 02 04 6e 69 61 6d 03 03 elit......niam.. +| 4080: 06 00 01 08 6f 6c 75 70 74 61 74 65 03 05 09 00 ....oluptate.... +| page 5 offset 16384 +| 0: 0a 00 00 00 03 0f eb 00 0f fb 0f f3 0f eb 00 00 ................ +| 4064: 00 00 00 00 00 00 00 00 00 00 00 07 04 02 08 01 ................ +| 4080: 08 00 03 07 04 02 08 03 a4 00 02 04 04 08 08 09 ................ +| page 6 offset 20480 +| 0: 0d 00 00 00 08 0f d0 00 0f fa 0f f4 0f ee 0f e8 ................ +| 16: 0f e2 0f dc 0f d6 0f d0 00 00 00 00 00 00 00 00 ................ +| 4048: 04 08 03 00 0e 0b 04 07 03 00 0e 06 04 06 03 00 ................ +| 4064: 0e 06 04 05 03 00 0e 0a 04 04 03 00 0e 07 04 03 ................ +| 4080: 03 00 0e 0a 04 02 03 00 0e 0b 04 01 03 00 0e 08 ................ +| page 7 offset 24576 +| 0: 0d 00 00 00 01 0f f7 00 0f f7 00 00 00 00 00 00 ................ +| 4080: 00 00 00 00 00 00 00 07 00 03 00 14 08 45 b5 03 .............E.. +| end crash-de7e8cb026385a.db +}]} {} + +do_catchsql_test 16.1 { + INSERT INTO t1(t1) VALUES('optimize'); +} {0 {}} + +#------------------------------------------------------------------------- +reset_db +do_test 17.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +.open --hexdb +| size 28672 pagesize 4096 filename crash-f15972acf5bc1c.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07 .....@ ........ +| 32: 00 00 00 02 00 00 00 01 00 00 00 07 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ +| 96: 00 00 00 00 0d 0e b1 00 06 0d a4 00 0f 8d 0f 21 ...............! +| 112: 0e b9 0d c8 0e 7e 0d a4 0d a4 00 00 00 00 00 00 .....~.......... +| 3488: 00 00 00 00 22 07 06 17 11 11 01 31 74 61 62 6c ...........1tabl +| 3504: 65 74 32 74 32 07 43 52 45 41 54 45 20 54 41 42 et2t2.CREATE TAB +| 3520: 4c 45 20 74 32 28 78 29 81 33 05 07 17 1f 1f 01 LE t2(x).3...... +| 3536: 82 35 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72 .5tablet1_segdir +| 3552: 74 31 5f 73 65 67 64 69 72 05 43 52 45 41 54 45 t1_segdir.CREATE +| 3568: 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69 TABLE 't1_segdi +| 3584: 72 27 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52 r'(level INTEGER +| 3600: 2c 69 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61 ,idx INTEGER,sta +| 3616: 72 74 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52 rt_block INTEGER +| 3632: 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 ,leaves_end_bloc +| 3648: 6b 20 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c k INTEGER,end_bl +| 3664: 6f 63 6b 20 49 4e 54 45 47 45 52 2c 72 6f 6f 74 ock INTEGER,root +| 3680: 20 42 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45 BLOB,PRIMARY KE +| 3696: 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 06 Y(level, idx))1. +| 3712: 06 17 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74 ..E...indexsqlit +| 3728: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73 e_autoindex_t1_s +| 3744: 65 67 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72 egdir_1t1_segdir +| 3760: 06 0f c7 00 08 00 00 00 00 66 04 07 17 23 23 01 .........f...##. +| 3776: 81 13 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e ..tablet1_segmen +| 3792: 74 73 74 31 5f 73 65 67 6d 65 6e 74 73 04 43 52 tst1_segments.CR +| 3808: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 EATE TABLE 't1_s +| 3824: 65 67 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64 egments'(blockid +| 3840: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 INTEGER PRIMARY +| 3856: 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 KEY, block BLOB +| 3872: 29 6a 03 07 17 21 21 01 81 1f 74 61 62 6c 65 74 )j...!!...tablet +| 3888: 31 5f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 1_contentt1_cont +| 3904: 65 6e 74 03 43 52 45 41 54 45 20 54 41 42 4c 45 ent.CREATE TABLE +| 3920: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f 't1_content'(do +| 3936: 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d cid INTEGER PRIM +| 3952: 41 52 59 20 4b 45 59 2c 20 27 63 30 61 27 2c 20 ARY KEY, 'c0a', +| 3968: 27 63 31 62 27 2c 20 27 63 32 63 27 29 38 02 06 'c1b', 'c2c')8.. +| 3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52 ...._tablet1t1CR +| 4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB +| 4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33 LE t1 USING fts3 +| 4032: 28 61 2c 62 2c 63 29 00 00 00 39 00 00 00 00 00 (a,b,c)...9..... +| page 3 offset 8192 +| 0: 0d 00 00 00 25 0b 48 00 0f d8 0f af 0f 86 0f 74 ....%.H........t +| 16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5 .a.N./.......... +| 32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 0d ef 0d d5 ...t.[.@.$...... +| 48: 0d bb 0d a0 0d 84 03 28 0d 4f 0d 35 0d 1b 0c fb .......(.O.5.... +| 64: 0c da 0c b9 0c 99 0c 78 0c 57 0c 3e 0c 24 0c 0a .......x.W.>.$.. +| 80: 0b 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .H.............. +| 2880: 00 00 00 00 00 00 00 00 81 3f 25 06 00 72 7f 00 .........?%..r.. +| 2896: 00 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e .COMPILER=gcc-5. +| 2912: 34 2e 30 20 32 30 31 36 30 36 30 39 20 44 45 42 4.0 20160609 DEB +| 2928: 55 47 20 45 4e 41 42 4c 45 20 44 42 53 54 41 54 UG ENABLE DBSTAT +| 2944: 20 56 54 41 42 20 45 4e 41 42 4c 45 20 46 54 53 VTAB ENABLE FTS +| 2960: 34 20 45 4e 41 42 4c 45 20 46 54 53 35 20 45 4e 4 ENABLE FTS5 EN +| 2976: 41 42 4c 45 20 47 45 4f 50 4f 4c 59 20 45 4e 41 ABLE GEOPOLY ENA +| 2992: 42 4c 45 20 4a 53 4f 4e 31 20 45 4e 41 42 4c 45 BLE JSON1 ENABLE +| 3008: 20 4d 45 4d 53 59 53 35 20 45 4e 41 42 4c 45 20 MEMSYS5 ENABLE +| 3024: 52 54 52 45 45 20 4d 41 58 20 4d 45 4d 4f 52 59 RTREE MAX MEMORY +| 3040: 3d 35 30 30 30 30 30 30 30 20 4f 4d 49 54 20 4c =50000000 OMIT L +| 3056: 4f 41 43 20 45 58 54 45 4e 53 49 4f 4e 20 54 48 OAC EXTENSION TH +| 3072: 52 45 41 44 53 41 46 45 3d 30 18 24 05 00 25 0f READSAFE=0.$..%. +| 3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49 .THREADSAFE=0XBI +| 3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41 NARY.#..%..THREA +| 3120: 44 53 41 46 45 3d 30 58 4e 4f 43 41 53 45 17 22 DSAFE=0XNOCASE.. +| 3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 45 3d ..%..THREADSAFE= +| 3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d 0XRTRIM.!..3..OM +| 3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 4f IT LOAD EXTENSIO +| 3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f NXBINARY. ..3..O +| 3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 MIT LOAD EXTENSI +| 3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17 ONXNOCASE....3.. +| 3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 OMIT LOAD EXTENS +| 3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f 19 IONXRTRIM....3.. +| 3264: 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 30 MAX MEMORY=50000 +| 3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f 000XBINARY....3. +| 3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 .MAX MEMORY=5000 +| 3312: 30 30 30 30 58 4e 4f 43 41 53 45 1e 1c 05 00 33 0000XNOCASE....3 +| 3328: 0f 17 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 ..MAX MEMORY=500 +| 3344: 30 30 30 30 30 58 52 54 52 49 4d 18 1b 05 00 25 00000XRTRIM....% +| 3360: 0f 19 45 4e 41 42 4c 45 20 52 54 52 45 45 58 42 ..ENABLE RTREEXB +| 3376: 49 4e 41 52 59 18 1a 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3392: 4c 45 20 52 54 52 45 45 58 4e 4f 43 41 53 45 17 LE RTREEXNOCASE. +| 3408: 19 05 00 25 0f 17 45 4e 41 42 4c 45 20 52 54 52 ...%..ENABLE RTR +| 3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45 EEXRTRIM....)..E +| 3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 58 42 49 NABLE MEMSYS5XBI +| 3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4e 41 42 4c NARY....)..ENABL +| 3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 53 45 E MEMSYS5XNOCASE +| 3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 4d 45 ....)..ENABLE ME +| 3504: 4d 53 59 53 35 58 52 54 52 49 4d 18 14 05 00 25 MSYS5XRTRIM....% +| 3520: 0f 19 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 58 42 ..ENABLE JSON1XB +| 3536: 49 4e 41 52 59 18 14 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3552: 4c 45 20 4a 53 4f 4e 31 58 4e 4f 43 41 53 45 17 LE JSON1XNOCASE. +| 3568: 13 05 00 25 0f 17 45 4e 41 42 4c 45 20 4a 53 4f ...%..ENABLE JSO +| 3584: 4e 31 58 52 54 52 49 4d 1a 12 05 00 29 0f 19 45 N1XRTRIM....)..E +| 3600: 4e 41 42 4c 45 20 47 45 4f 50 4f 4c 59 58 42 49 NABLE GEOPOLYXBI +| 3616: 4e 41 52 59 1a 11 05 00 29 0f 19 45 4e 41 42 4c NARY....)..ENABL +| 3632: 45 20 47 45 4f 50 4f 4c 59 58 4e 4f 43 41 53 45 E GEOPOLYXNOCASE +| 3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 45 ....)..ENABLE GE +| 3664: 4f 50 4f 4c 59 58 52 54 52 49 4d 17 0f 05 00 23 OPOLYXRTRIM....# +| 3680: 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 58 42 49 ..ENABLE FTS5XBI +| 3696: 4e 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 4c NARY....#..ENABL +| 3712: 45 20 46 54 53 35 58 4e 4f 43 41 53 45 16 0d 05 E FTS5XNOCASE... +| 3728: 00 23 0f 17 45 4e 41 42 4c 45 20 46 54 53 35 58 .#..ENABLE FTS5X +| 3744: 52 54 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42 RTRIM....#..ENAB +| 3760: 4c 45 20 46 54 53 34 58 42 49 4e 41 52 59 17 0b LE FTS4XBINARY.. +| 3776: 05 00 23 0f 19 45 4e 41 42 4c 45 20 46 54 53 34 ..#..ENABLE FTS4 +| 3792: 58 4e 4f 43 41 53 45 16 0a 05 00 23 0f 17 45 4e XNOCASE....#..EN +| 3808: 41 42 4c 45 20 46 54 53 34 58 52 54 52 49 4d 1e ABLE FTS4XRTRIM. +| 3824: 09 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 52 59 1e TAT VTABXBINARY. +| 3856: 08 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3872: 54 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d TAT VTABXNOCASE. +| 3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3904: 54 41 54 20 56 54 41 42 58 52 54 52 49 4d 11 06 TAT VTABXRTRIM.. +| 3920: 05 00 17 0f 19 44 45 42 55 47 58 42 49 4e 41 52 .....DEBUGXBINAR +| 3936: 59 11 05 05 00 17 0e 19 44 45 42 55 47 58 4e 4f Y.......DEBUGXNO +| 3952: 43 41 53 45 10 04 05 00 17 0f 17 44 45 42 55 47 CASE.......DEBUG +| 3968: 58 52 54 52 49 4d 27 03 05 00 43 0f 19 43 4f 4d XRTRIM'...C..COM +| 3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20 PILER=gcc-5.4.0 +| 4000: 32 30 31 36 30 36 30 39 58 42 49 4e 41 52 59 27 20160609XBINARY' +| 4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67 ...C..COMPILER=g +| 4032: 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36 30 cc-5.4.0 2016060 +| 4048: 39 58 4e 4f 43 41 53 45 26 01 05 00 43 0f 17 43 9XNOCASE&...C..C +| 4064: 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e OMPILER=gcc-5.4. +| 4080: 30 20 32 30 31 36 30 36 30 39 58 52 54 52 49 4d 0 20160609XRTRIM +| page 4 offset 12288 +| 0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................ +| page 5 offset 16384 +| 0: 0d 00 00 00 02 0b a0 00 0c ad 0b a0 00 00 00 00 ................ +| 2976: 82 0a 02 08 08 09 08 08 17 84 06 30 20 32 35 33 ...........0 253 +| 2992: 00 01 30 04 25 06 1b 00 00 08 32 30 31 36 30 36 ..0.%.....201606 +| 3008: 30 39 03 25 07 00 00 01 34 03 25 05 00 00 01 35 09.%....4.%....5 +| 3024: 03 25 04 00 01 07 30 30 30 30 30 30 30 03 25 1a .%....0000000.%. +| 3040: 00 00 08 63 6f 6d 70 69 6c 65 72 03 25 02 00 00 ...compiler.%... +| 3056: 06 64 62 73 74 61 74 03 25 0a 00 01 04 65 62 75 .dbstat.%....ebu +| 3072: 67 03 25 08 00 00 06 65 6e 61 62 6c 65 09 25 09 g.%....enable.%. +| 3088: 05 04 04 04 04 04 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3104: 6e 03 25 1d 00 00 04 66 74 73 34 03 25 0d 00 03 n.%....fts4.%... +| 3120: 01 35 03 25 0f 00 00 03 67 63 63 03 25 03 00 01 .5.%....gcc.%... +| 3136: 06 65 6f 70 6f 6c 79 03 25 11 00 00 05 6a 73 6f .eopoly.%....jso +| 3152: 6e 31 03 25 13 00 00 04 6c 6f 61 64 03 25 1c 00 n1.%....load.%.. +| 3168: 00 03 6d 61 78 03 25 18 00 01 05 65 6d 6f 72 79 ..max.%....emory +| 3184: 03 25 19 00 03 04 73 79 73 4d 03 25 15 00 00 04 .%....sysM.%.... +| 3200: 6f 6d 69 74 03 25 1b 00 00 05 72 74 72 65 65 03 omit.%....rtree. +| 3216: 25 17 00 00 0a 74 68 72 65 61 64 73 61 66 65 03 %....threadsafe. +| 3232: 25 0e 00 00 04 76 74 61 62 03 25 0b 00 86 50 01 %....vtab.%...P. +| 3248: 08 08 08 08 08 17 8d 12 30 20 38 33 35 00 01 30 ........0 835..0 +| 3264: 12 01 06 00 01 06 00 01 06 00 1f 03 00 01 03 00 ................ +| 3280: 01 03 00 00 08 32 30 31 36 30 36 30 39 09 01 07 .....20160609... +| 3296: 00 01 07 00 01 07 00 00 01 34 09 01 05 00 01 05 .........4...... +| 3312: 00 01 05 00 00 01 35 09 01 04 00 01 04 00 01 04 ......5......... +| 3328: 00 01 07 30 30 30 30 30 30 30 09 1c 04 00 01 04 ...0000000...... +| 3344: 00 01 04 00 00 06 62 69 6e 61 72 79 3c 03 01 02 ......binary<... +| 3360: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3376: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3392: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 ................ +| 3408: 01 02 02 00 03 01 02 02 00 00 08 63 6f 6d 70 69 ...........compi +| 3424: 6c 65 72 09 01 02 00 01 02 00 01 02 00 00 06 64 ler............d +| 3440: 62 73 74 61 74 09 07 03 00 01 03 00 01 03 00 01 bstat........... +| 3456: 04 65 62 75 67 09 04 02 00 01 02 00 01 02 00 00 .ebug........... +| 3472: 06 65 6e 61 62 6c 65 3f 07 02 00 01 02 00 01 02 .enable?........ +| 3488: 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00 ................ +| 3504: 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 ................ +| 3520: 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 ................ +| 3536: 00 01 02 00 01 02 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3552: 6e 09 1f 04 00 01 04 00 01 04 00 00 04 66 74 73 n............fts +| 3568: 34 09 0a 03 00 01 03 00 01 03 00 03 01 35 09 0d 4............5.. +| 3584: 03 00 01 03 00 01 03 00 00 03 67 63 63 09 01 03 ..........gcc... +| 3600: 00 01 03 00 01 03 00 01 06 65 6f 70 6f 6c 79 09 .........eopoly. +| 3616: 10 03 00 01 03 00 01 03 00 00 05 6a 73 6f 6e 31 ...........json1 +| 3632: 09 13 03 00 01 03 00 01 03 00 00 04 6c 6f 61 64 ............load +| 3648: 09 1f 03 00 01 03 00 01 03 00 00 03 6d 61 78 09 ............max. +| 3664: 1c 02 00 01 02 00 01 02 00 01 05 65 6d 6f 72 79 ...........emory +| 3680: 09 1c 03 00 01 03 00 01 03 00 03 04 73 79 73 35 ............sys5 +| 3696: 09 16 03 00 01 03 00 01 03 00 00 06 6e 6f 63 61 ............noca +| 3712: 73 65 3c 02 01 02 02 00 03 01 02 02 00 03 01 02 se<............. +| 3728: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3744: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3760: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 00 ................ +| 3776: 04 6f 6d 69 74 09 1f 02 00 01 02 00 01 02 00 00 .omit........... +| 3792: 05 72 74 72 65 65 09 19 03 00 01 03 00 01 03 00 .rtree.......... +| 3808: 03 02 69 6d 3c 01 01 02 02 00 03 01 02 02 00 03 ..im<........... +| 3824: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 ................ +| 3840: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 ................ +| 3856: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3872: 00 00 0a 74 68 72 65 61 64 73 61 66 65 09 22 02 ...threadsafe... +| 3888: 00 01 02 00 01 02 00 00 04 76 74 61 62 09 07 04 .........vtab... +| 3904: 00 01 04 00 01 04 00 00 01 78 b4 01 01 01 01 02 .........x...... +| 3920: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 3936: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 3952: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 3968: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 3984: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4000: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 4016: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 4032: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 4048: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 4064: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4080: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| page 6 offset 20480 +| 0: 0a 00 00 00 02 0f f5 00 0f fb 0f f5 00 00 00 00 ................ +| 4080: 00 00 00 00 00 05 04 08 09 01 02 04 04 08 08 09 ................ +| page 7 offset 24576 +| 0: 0d 00 00 00 05 0f b8 00 0f f4 0f e9 10 d6 0f c7 ................ +| 16: 0f b8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 4016: 00 00 00 00 00 00 00 00 0d 05 02 23 61 75 74 6f ...........#auto +| 4032: 6d 65 72 67 65 3d 35 0d 04 02 23 6d 65 72 67 65 merge=5...#merge +| 4048: 3d 31 30 30 2c 38 11 03 02 2b 69 6e 74 65 67 72 =100,8...+integr +| 4064: 69 74 79 2d 63 68 65 63 6b 09 02 02 1b 72 65 62 ity-check....reb +| 4080: 75 69 6c 64 0a 01 02 1d 6f 70 74 69 6d 69 7a 65 uild....optimize +| end crash-f15972acf5bc1c.db +}]} {} + +do_execsql_test 17.1 { + BEGIN; + INSERT INTO t1(t1) SELECT x FROM t2; + UPDATE t1 SET b=quote(zeroblob(200)) WHERE a MATCH 'thread*'; +} + +do_execsql_test 17.2 { + INSERT INTO t1(t1) VALUES('optimize'); +} + +do_catchsql_test 17.3 { + DROP TABLE IF EXISTS t1; +} {0 {}} + +#------------------------------------------------------------------------- +reset_db +do_test 18.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 32768 pagesize 4096 filename crash-4ce32d0608aff1.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07 .....@ ........ +| 32: 00 00 00 02 00 00 00 01 00 00 00 07 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 07 00 00 00 01 00 00 00 00 ................ +| 96: 00 00 00 00 0d 0e b1 00 06 0d a4 00 0f 8d 0f 21 ...............! +| 112: 0e b9 0d c8 0e 7e 0d a4 0d a4 00 00 00 00 00 00 .....~.......... +| 3488: 00 00 00 00 22 07 06 17 11 11 01 31 74 61 62 6c ...........1tabl +| 3504: 65 74 32 74 32 07 43 52 45 41 54 45 20 54 41 42 et2t2.CREATE TAB +| 3520: 4c 45 20 74 32 28 78 29 81 33 05 07 17 1f 1f 01 LE t2(x).3...... +| 3536: 82 35 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72 .5tablet1_segdir +| 3552: 74 31 5f 73 65 67 64 69 72 05 43 52 45 41 54 45 t1_segdir.CREATE +| 3568: 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69 TABLE 't1_segdi +| 3584: 72 27 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52 r'(level INTEGER +| 3600: 2c 69 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61 ,idx INTEGER,sta +| 3616: 72 74 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52 rt_block INTEGER +| 3632: 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 ,leaves_end_bloc +| 3648: 6b 20 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c k INTEGER,end_bl +| 3664: 6f 63 6b 20 49 4e 54 45 47 45 62 2c 72 6f 6f 74 ock INTEGEb,root +| 3680: 20 42 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45 BLOB,PRIMARY KE +| 3696: 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 06 Y(level, idx))1. +| 3712: 06 17 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74 ..E...indexsqlit +| 3728: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73 e_autoindex_t1_s +| 3744: 65 67 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72 egdir_1t1_segdir +| 3760: 06 0f c7 00 08 00 00 00 00 66 04 07 17 23 23 01 .........f...##. +| 3776: 81 13 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e ..tablet1_segmen +| 3792: 74 73 74 31 5f 73 65 67 6d 65 6e 74 73 04 43 52 tst1_segments.CR +| 3808: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 EATE TABLE 't1_s +| 3824: 65 67 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64 egments'(blockid +| 3840: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 INTEGER PRIMARY +| 3856: 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 KEY, block BLOB +| 3872: 29 6a 03 07 17 21 21 01 81 1f 74 61 62 6c 65 74 )j...!!...tablet +| 3888: 31 5f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 1_contentt1_cont +| 3904: 65 6e 74 03 43 52 45 41 54 45 20 54 41 42 4c 45 ent.CREATE TABLE +| 3920: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f 't1_content'(do +| 3936: 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d cid INTEGER PRIM +| 3952: 41 52 59 20 4b 45 59 2c 20 27 63 30 61 27 2c 20 ARY KEY, 'c0a', +| 3968: 27 63 31 62 27 2c 20 27 63 32 63 27 29 38 02 06 'c1b', 'c2c')8.. +| 3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52 ...._tablet1t1CR +| 4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB +| 4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33 LE t1 USING fts3 +| 4032: 28 61 2c 62 2c 63 29 00 00 00 39 00 00 00 00 00 (a,b,c)...9..... +| page 3 offset 8192 +| 0: 0d 00 00 00 25 0b 48 00 0f d8 0f af 0f 86 0f 74 ....%.H........t +| 16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5 .a.N./.......... +| 32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 0d ef 0d d5 ...t.[.@.$...... +| 48: 0d bb 0d a0 0d 84 0d 68 0d 4f 0d 35 0d 1b 0c fb .......h.O.5.... +| 64: 0c da 0c b9 0c 99 0c 78 0c 57 0c 3e 0c 24 0c 0a .......x.W.>.$.. +| 80: 0b 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .H.............. +| 2880: 00 00 00 00 00 00 00 00 81 3f 25 06 00 82 7f 00 .........?%..... +| 2896: 00 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e .COMPILER=gcc-5. +| 2912: 34 23 00 20 32 30 31 36 30 36 30 39 20 44 45 42 4#. 20160609 DEB +| 2928: 55 47 20 45 4e 41 42 4c 45 20 44 42 53 54 41 54 UG ENABLE DBSTAT +| 2944: 20 56 54 41 42 20 45 4e 41 42 4c 45 20 46 54 53 VTAB ENABLE FTS +| 2960: 34 20 45 4e 41 42 4c 45 20 46 54 53 35 20 45 4e 4 ENABLE FTS5 EN +| 2976: 41 42 4c 45 20 47 45 4f 50 4f 4c 59 20 45 4e 41 ABLE GEOPOLY ENA +| 2992: 42 4c 45 20 4a 53 4f 4e 31 20 45 4e 41 42 4c 45 BLE JSON1 ENABLE +| 3008: 20 4d 45 4d 53 59 53 35 20 45 4e 41 42 4c 45 20 MEMSYS5 ENABLE +| 3024: 52 54 52 45 45 20 4d 41 58 20 4d 45 4d 4f 52 59 RTREE MAX MEMORY +| 3040: 3d 35 30 30 30 30 30 30 30 20 4f 4d 49 54 20 4c =50000000 OMIT L +| 3056: 4f 41 44 20 45 58 54 45 4e 53 49 4f 4e 20 54 48 OAD EXTENSION TH +| 3072: 52 45 41 44 53 41 46 45 3d 30 18 24 05 00 25 0f READSAFE=0.$..%. +| 3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49 .THREADSAFE=0XBI +| 3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41 NARY.#..%..THREA +| 3120: 44 53 41 46 45 3d 30 58 4e 4f 43 41 53 45 17 22 DSAFE=0XNOCASE.. +| 3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 45 3d ..%..THREADSAFE= +| 3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d 0XRTRIM.!..3..OM +| 3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 4f IT LOAD EXTENSIO +| 3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f NXBINARY. ..3..O +| 3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 MIT LOAD EXTENSI +| 3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17 ONXNOCASE....3.. +| 3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 OMIT LOAD EXTENS +| 3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f 19 IONXRTRIM....3.. +| 3264: 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 30 MAX MEMORY=50000 +| 3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f 000XBINARY....3. +| 3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 .MAX MEMORY=5000 +| 3312: 30 30 30 30 58 4e 4f 43 41 53 45 1e 1c 05 00 33 0000XNOCASE....3 +| 3328: 0f 17 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 ..MAX MEMORY=500 +| 3344: 30 30 30 30 30 58 52 54 53 49 4d 18 1b 05 00 25 00000XRTSIM....% +| 3360: 0f 19 45 4e 41 42 4c 45 20 52 54 52 45 45 58 42 ..ENABLE RTREEXB +| 3376: 49 4e 41 52 59 18 1a 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3392: 4c 45 20 52 54 52 45 45 58 4e 4f 43 41 53 45 17 LE RTREEXNOCASE. +| 3408: 19 05 00 25 0f 17 45 4e 41 42 4c 45 20 52 54 52 ...%..ENABLE RTR +| 3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45 EEXRTRIM....)..E +| 3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 58 42 49 NABLE MEMSYS5XBI +| 3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4e 41 42 4c NARY....)..ENABL +| 3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 53 45 E MEMSYS5XNOCASE +| 3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 4d 45 ....)..ENABLE ME +| 3504: 4d 53 59 53 35 58 52 54 52 49 4d 18 15 05 00 25 MSYS5XRTRIM....% +| 3520: 0f 19 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 58 42 ..ENABLE JSON1XB +| 3536: 49 4e 41 52 59 18 14 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3552: 4c 45 20 4a 53 4f 4e 31 58 4e 4f 43 41 53 45 17 LE JSON1XNOCASE. +| 3568: 13 05 00 25 0f 17 45 4e 41 52 4c 45 20 4a 53 4f ...%..ENARLE JSO +| 3584: 4e 31 58 52 54 52 49 4d 1a 12 05 00 29 0f 19 45 N1XRTRIM....)..E +| 3600: 4e 41 42 4c 45 20 47 45 4f 50 4f 4c 59 58 42 49 NABLE GEOPOLYXBI +| 3616: 4e 41 52 59 1a 11 05 00 29 0f 19 45 4e 41 1e 4c NARY....)..ENA.L +| 3632: 45 20 47 45 4f 50 4f 4c 59 58 4e 4f 43 41 53 45 E GEOPOLYXNOCASE +| 3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 55 ....)..ENABLE GU +| 3664: 4f 50 4f 4c 59 58 52 54 52 49 4d 17 0f 05 00 23 OPOLYXRTRIM....# +| 3680: 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 58 42 49 ..ENABLE FTS5XBI +| 3696: 4e 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 4c NARY....#..ENABL +| 3712: 45 20 46 54 53 35 58 4e 4f 43 41 53 45 16 0d 05 E FTS5XNOCASE... +| 3728: 00 23 0f 17 45 4e 41 42 4c 45 20 46 54 59 e5 58 .#..ENABLE FTY.X +| 3744: 52 54 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42 RTRIM....#..ENAB +| 3760: 4c 45 20 46 54 53 34 58 42 49 4e 41 52 59 17 0b LE FTS4XBINARY.. +| 3776: 05 00 23 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 ..#..ENABLE FTS5 +| 3792: 58 4e 4f 43 40 53 45 16 0a 05 00 23 0f 17 45 4e XNOC@SE....#..EN +| 3808: 41 42 4c 45 20 46 54 53 34 58 52 54 52 49 4d 1e ABLE FTS4XRTRIM. +| 3824: 09 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 52 59 1e TAT VTABXBINARY. +| 3856: 08 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3872: 54 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d TAT VTABXNOCASE. +| 3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3904: 54 41 54 20 56 54 41 42 58 52 54 52 49 4d 11 06 TAT VTABXRTRIM.. +| 3920: 05 00 17 0f 19 44 45 42 55 47 58 42 49 4e 41 52 .....DEBUGXBINAR +| 3936: 59 11 05 05 00 17 0f 19 44 45 42 55 47 58 4e 4f Y.......DEBUGXNO +| 3952: 43 41 53 45 10 04 05 00 17 0f 17 44 45 42 55 47 CASE.......DEBUG +| 3968: 58 52 54 52 49 4d 27 03 05 00 43 0f 19 43 4f 4d XRTRIM'...C..COM +| 3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20 PILER=gcc-5.4.0 +| 4000: 32 30 31 36 30 36 30 39 58 42 49 4e 41 52 59 27 20160609XBINARY' +| 4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67 ...C..COMPILER=g +| 4032: 63 63 25 75 2e 34 2f 30 20 32 30 31 36 30 36 30 cc%u.4/0 2016060 +| 4048: 39 58 4e 4f 43 41 53 45 26 01 05 00 43 0f 17 43 9XNOCASE&...C..C +| 4064: 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e OMPILER=gcc-5.4. +| 4080: 30 20 32 30 31 36 30 36 30 39 58 52 54 52 49 4d 0 20160609XRTRIM +| page 4 offset 12288 +| 0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................ +| page 5 offset 16384 +| 0: 0d 00 00 00 02 0b a0 00 0c ad 0b a0 00 00 00 00 ................ +| 2976: 82 0a 02 08 08 09 08 08 17 84 06 30 20 32 35 33 ...........0 253 +| 2992: 00 01 30 04 25 06 1b 00 00 08 32 30 31 36 30 36 ..0.%.....201606 +| 3008: 30 39 03 25 07 00 00 01 34 03 25 05 00 00 01 35 09.%....4.%....5 +| 3024: 03 25 04 00 01 07 30 30 30 30 30 30 30 03 25 1a .%....0000000.%. +| 3040: 00 00 08 63 6f 6d 70 69 6c 65 72 03 25 02 00 00 ...compiler.%... +| 3056: 06 64 62 73 74 61 74 03 25 0a 00 01 04 65 62 75 .dbstat.%....ebu +| 3072: 67 03 25 08 00 00 06 65 6e 61 62 6c 65 09 25 09 g.%....enable.%. +| 3088: 05 04 04 04 04 04 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3104: 6e 03 25 1d 00 00 04 66 74 73 34 03 25 0d 00 03 n.%....fts4.%... +| 3120: 01 35 03 25 0f 00 00 03 67 63 63 03 25 03 00 01 .5.%....gcc.%... +| 3136: 06 65 6f 70 6f 6c 79 03 25 11 00 00 05 6a 73 6f .eopoly.%....jso +| 3152: 6e 31 03 25 13 41 00 04 6c 6f 61 64 03 25 1c 00 n1.%.A..load.%.. +| 3168: 00 03 6d 61 78 03 25 18 00 01 05 65 6d 6f 72 79 ..max.%....emory +| 3184: 03 25 19 00 03 04 73 79 73 35 03 25 15 00 00 04 .%....sys5.%.... +| 3200: 6f 6d 69 74 03 25 1b 00 00 05 72 74 72 65 65 03 omit.%....rtree. +| 3216: 25 17 00 00 0a 74 68 72 65 61 64 73 61 56 65 03 %....threadsaVe. +| 3232: 25 1e 00 00 04 76 74 61 62 03 25 0b 00 86 50 01 %....vtab.%...P. +| 3248: 08 08 08 08 08 17 8d 12 30 20 38 33 35 00 01 30 ........0 835..0 +| 3264: 12 01 06 00 01 06 00 01 06 00 1f 03 00 01 03 00 ................ +| 3280: 01 03 00 00 08 32 30 31 36 30 36 30 39 09 01 07 .....20160609... +| 3296: 00 01 07 00 01 07 00 00 01 34 09 01 05 00 01 05 .........4...... +| 3312: 00 01 05 00 00 01 35 09 01 04 00 01 04 00 01 04 ......5......... +| 3328: 00 01 07 30 30 30 30 30 30 30 09 1c 04 00 01 04 ...0000000...... +| 3344: 00 01 04 00 00 06 62 69 6e 61 72 79 3c 03 02 02 ......binary<... +| 3360: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3376: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3392: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 ................ +| 3408: 01 02 02 00 03 01 02 02 00 00 08 63 6f 6d 70 69 ...........compi +| 3424: 6c 65 72 09 01 02 00 01 02 00 01 02 00 00 06 64 ler............d +| 3440: 62 73 74 61 74 09 f2 03 00 01 03 00 01 03 00 01 bstat........... +| 3456: 04 65 62 75 67 09 04 02 00 01 02 00 01 02 00 00 .ebug........... +| 3472: 06 65 6e 61 62 6c 65 3f 07 02 00 01 02 00 01 02 .enable?........ +| 3488: 00 01 02 00 01 02 00 01 02 00 01 02 00 57 02 00 .............W.. +| 3504: 01 02 00 01 01 00 01 02 00 11 02 00 01 02 10 01 ................ +| 3520: 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 ................ +| 3536: 00 01 02 00 01 02 00 01 08 78 74 64 6e 73 69 6f .........xtdnsio +| 3552: 6e 09 1f 04 00 01 04 00 01 03 00 00 04 66 74 73 n............fts +| 3568: 34 09 0a 03 00 01 03 00 01 03 00 03 01 35 09 0d 4............5.. +| 3584: 03 00 01 03 00 01 03 00 00 03 57 63 63 09 01 03 ..........Wcc... +| 3600: 00 01 03 00 01 03 00 01 06 65 6f 70 6f 6c 79 09 .........eopoly. +| 3616: 10 03 00 01 03 00 01 03 00 00 05 6a 73 6f 6e 31 ...........json1 +| 3632: 09 13 03 00 01 03 00 01 03 00 00 04 6c 6f 61 64 ............load +| 3648: 09 1f 03 00 01 03 00 01 03 00 00 03 6d 61 78 09 ............max. +| 3664: 1c 02 00 01 02 00 01 02 00 01 05 65 6d 6f 72 79 ...........emory +| 3680: 09 1c 03 00 01 03 00 01 03 00 03 04 73 79 73 35 ............sys5 +| 3696: 09 16 03 00 01 03 00 01 03 00 00 06 6e 6f 63 61 ............noca +| 3712: 73 65 3c 02 01 02 02 00 03 01 02 02 00 03 01 02 se<............. +| 3728: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3744: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3760: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 00 ................ +| 3776: 04 6f 6d 69 74 09 1f 02 00 01 02 00 01 02 00 00 .omit........... +| 3792: 05 72 74 72 65 65 09 19 03 00 01 03 00 01 03 00 .rtree.......... +| 3808: 03 02 69 6d 3c 01 01 02 02 00 03 01 02 02 00 03 ..im<........... +| 3824: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 ................ +| 3840: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 ................ +| 3856: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3872: 00 00 0a 74 68 72 65 61 64 73 61 66 65 09 22 02 ...threadsafe... +| 3888: 00 01 02 00 02 02 00 00 04 76 74 61 62 09 07 04 .........vtab... +| 3904: 00 01 04 00 01 04 00 00 01 78 b4 01 01 01 01 02 .........x...... +| 3920: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 3936: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 3952: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 3968: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 3984: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4000: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 4016: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 4032: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 4048: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 4064: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4080: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| page 6 offset 20480 +| 0: 0a 00 00 00 02 0f f5 00 0f fb 0f f5 00 00 00 00 ................ +| 4080: 00 00 00 00 00 05 04 08 09 01 02 04 04 08 08 09 ................ +| page 7 offset 24576 +| 0: 0d 00 00 00 05 0f b8 00 0f f4 0f e9 0f d6 0f c7 ................ +| 16: 0f b8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 4064: 00 00 00 00 00 0d 05 02 23 61 75 74 6f 6d 65 72 ........#automer +| 4080: 67 65 3d 35 0d 04 02 23 6d 65 72 67 65 3d 31 30 ge=5...#merge=10 +| page 8 offset 28672 +| 0: 30 2c 38 11 03 02 2b 69 6e 74 65 67 72 69 74 79 0,8...+integrity +| 16: 2d 63 68 65 63 6b 09 02 02 1b 72 65 62 75 69 6c -check....rebuil +| 32: 64 0a 01 02 1d 6f 70 74 69 6d 69 7a 65 00 00 00 d....optimize... +| end crash-4ce32d0608aff1.db +}]} {} + +do_catchsql_test 18.1 { + SELECT quote(matchinfo(t1,'pcxybs'))==0 FROM t1 WHERE b MATCH 'e*'; +} {0 {}} + +#------------------------------------------------------------------------- +reset_db +do_test 19.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 28672 pagesize 4096 filename crash-526ea445f41c02.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07 .....@ ........ +| 32: 00 00 00 02 00 00 00 01 00 00 00 07 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ +| 96: 00 00 00 00 0d 0e b1 00 06 0d a4 00 0f 8d 0f 21 ...............! +| 112: 0e b9 0d c8 0e 7e 0d a4 00 00 00 00 00 00 00 00 .....~.......... +| 3488: 00 00 00 00 22 07 06 17 11 11 01 31 74 61 62 6c ...........1tabl +| 3504: 65 74 32 74 32 07 43 52 45 41 54 45 20 54 41 42 et2t2.CREATE TAB +| 3520: 4c 45 20 74 32 28 78 29 81 33 05 07 17 1f 1f 01 LE t2(x).3...... +| 3536: 82 35 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72 .5tablet1_segdir +| 3552: 74 31 5f 73 65 67 64 69 72 05 43 52 45 41 54 45 t1_segdir.CREATE +| 3568: 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69 TABLE 't1_segdi +| 3584: 72 27 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52 r'(level INTEGER +| 3600: 2c 69 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61 ,idx INTEGER,sta +| 3616: 72 74 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52 rt_block INTEGER +| 3632: 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 ,leaves_end_bloc +| 3648: 6b 20 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c k INTEGER,end_bl +| 3664: 6f 63 6b 20 49 4e 54 45 47 45 52 2c 72 6f 6f 74 ock INTEGER,root +| 3680: 20 42 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45 BLOB,PRIMARY KE +| 3696: 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 06 Y(level, idx))1. +| 3712: 06 17 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74 ..E...indexsqlit +| 3728: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73 e_autoindex_t1_s +| 3744: 65 67 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72 egdir_1t1_segdir +| 3760: 06 0f c7 00 08 00 00 00 00 66 04 07 17 23 23 01 .........f...##. +| 3776: 81 13 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e ..tablet1_segmen +| 3792: 74 73 74 31 5f 73 65 67 6d 65 6e 74 73 04 43 52 tst1_segments.CR +| 3808: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 EATE TABLE 't1_s +| 3824: 65 67 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64 egments'(blockid +| 3840: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 INTEGER PRIMARY +| 3856: 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 KEY, block BLOB +| 3872: 29 6a 03 07 17 21 21 01 81 1f 74 61 62 6c 65 74 )j...!!...tablet +| 3888: 31 5f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 1_contentt1_cont +| 3904: 65 6e 74 03 43 52 45 41 54 45 20 54 41 42 4c 45 ent.CREATE TABLE +| 3920: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f 't1_content'(do +| 3936: 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d cid INTEGER PRIM +| 3952: 41 52 59 20 4b 45 59 2c 20 27 63 30 61 27 2c 20 ARY KEY, 'c0a', +| 3968: 27 63 31 62 27 2c 20 27 63 32 63 27 29 38 02 06 'c1b', 'c2c')8.. +| 3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 41 43 52 ...._tablet1tACR +| 4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB +| 4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33 LE t1 USING fts3 +| 4032: 28 61 2c 62 2c 63 29 00 00 00 39 00 00 00 00 00 (a,b,c)...9..... +| page 3 offset 8192 +| 0: 0d 00 00 00 25 0b 48 00 0f d8 0f af 0f 86 0f 74 ....%.H........t +| 16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5 .a.N./.......... +| 32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 0d ef 0d d5 ...t.[.@.$...... +| 48: 0d bb 0d a0 0d 84 0d 68 0d 4f 0d 35 0d 1b 0c fb .......h.O.5.... +| 64: 0c da 0c b9 0c 99 0c 78 0c 57 0c 3e 0c 24 0c 0a .......x.W.>.$.. +| 80: 0b 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .H.............. +| 2880: 00 00 00 00 00 00 00 00 81 3f 25 06 00 82 7f 00 .........?%..... +| 2896: 00 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2f .COMPILER=gcc-5/ +| 2912: 34 2e 30 20 32 30 31 36 30 36 30 39 20 44 45 42 4.0 20160609 DEB +| 2928: 55 47 20 45 4e 41 42 4c 45 20 44 42 53 54 41 54 UG ENABLE DBSTAT +| 2944: 20 56 54 41 42 20 45 4e 41 42 4c 45 20 46 54 53 VTAB ENABLE FTS +| 2960: 34 20 45 4e 41 42 4c 45 20 46 54 53 35 20 45 4e 4 ENABLE FTS5 EN +| 2976: 41 42 4c 45 20 47 45 4f 50 4f 4c 59 20 45 4e 41 ABLE GEOPOLY ENA +| 2992: 42 4c 45 20 4a 53 4f 4e 31 20 45 4e 41 42 4c 45 BLE JSON1 ENABLE +| 3008: 20 4d 45 4d 53 59 53 35 20 45 4e 41 42 4c 45 20 MEMSYS5 ENABLE +| 3024: 52 54 52 45 45 20 4d 41 58 20 4d 45 4d 4f 52 59 RTREE MAX MEMORY +| 3040: 3d 35 30 30 30 30 30 30 30 20 4f 4d 49 54 20 4c =50000000 OMIT L +| 3056: 4f 41 44 20 45 58 54 45 4e 53 49 4f 4e 20 54 48 OAD EXTENSION TH +| 3072: 52 45 41 44 53 41 46 45 3d 30 18 24 05 00 25 0f READSAFE=0.$..%. +| 3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49 .THREADSAFE=0XBI +| 3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41 NARY.#..%..THREA +| 3120: 44 53 41 46 45 3d 30 58 4e 4f 43 41 53 45 17 22 DSAFE=0XNOCASE.. +| 3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 45 3d ..%..THREADSAFE= +| 3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d 0XRTRIM.!..3..OM +| 3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 4f IT LOAD EXTENSIO +| 3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f NXBINARY. ..3..O +| 3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 MIT LOAD EXTENSI +| 3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17 ONXNOCASE....3.. +| 3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 OMIT LOAD EXTENS +| 3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f 19 IONXRTRIM....3.. +| 3264: 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 30 MAX MEMORY=50000 +| 3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f 000XBINARY....3. +| 3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 .MAX MEMORY=5000 +| 3312: 30 30 30 30 58 4e 4f 43 41 53 45 1e 1c 05 00 33 0000XNOCASE....3 +| 3328: 0f 17 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 ..MAX MEMORY=500 +| 3344: 30 30 30 30 30 58 52 54 52 49 4d 18 1b 05 00 25 00000XRTRIM....% +| 3360: 0f 19 45 4e 41 42 4c 45 20 52 54 52 45 45 58 42 ..ENABLE RTREEXB +| 3376: 49 4e 41 52 59 18 1a 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3392: 4c 45 20 52 54 52 45 45 58 4e 4f 43 41 53 45 17 LE RTREEXNOCASE. +| 3408: 19 05 00 25 0f 17 45 4e 41 42 4c 45 20 52 54 52 ...%..ENABLE RTR +| 3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45 EEXRTRIM....)..E +| 3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 58 42 49 NABLE MEMSYS5XBI +| 3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4e 41 42 4c NARY....)..ENABL +| 3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 53 45 E MEMSYS5XNOCASE +| 3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 4d 45 ....)..ENABLE ME +| 3504: 4d 53 59 53 35 58 52 54 52 49 4d 18 15 05 00 25 MSYS5XRTRIM....% +| 3520: 0f 19 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 58 42 ..ENABLE JSON1XB +| 3536: 49 4e 41 52 59 18 14 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3552: 4c 45 20 4a 53 4f 4e 31 58 4e 4f 43 41 53 45 17 LE JSON1XNOCASE. +| 3568: 13 05 00 25 0f 17 45 4e 41 42 4c 45 20 4a 53 4f ...%..ENABLE JSO +| 3584: 4e 31 58 52 54 52 49 4d 1a 12 05 00 29 0f 19 45 N1XRTRIM....)..E +| 3600: 4e 41 42 4c 45 20 47 45 4f 50 4f 4c 59 58 42 49 NABLE GEOPOLYXBI +| 3616: 4e 41 52 59 1a 11 05 00 29 0f 19 45 4e 41 42 4c NARY....)..ENABL +| 3632: 45 20 47 45 4f 50 4f 4c 59 58 4e 4f 43 41 53 45 E GEOPOLYXNOCASE +| 3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 45 ....)..ENABLE GE +| 3664: 4f 50 4f 4c 59 58 52 54 52 49 4d 17 0f 05 00 23 OPOLYXRTRIM....# +| 3680: 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 58 42 49 ..ENABLE FTS5XBI +| 3696: 4f 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 4c OARY....#..ENABL +| 3712: 45 20 46 54 53 35 58 4e 4f 43 41 53 45 16 0d 05 E FTS5XNOCASE... +| 3728: 00 23 0f 17 45 4e 41 42 4c 45 20 46 54 53 35 58 .#..ENABLE FTS5X +| 3744: 52 54 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42 RTRIM....#..ENAB +| 3760: 4c 45 20 46 54 53 34 58 42 49 4e 41 52 59 17 0b LE FTS4XBINARY.. +| 3776: 05 00 23 0f 19 45 4e 41 42 4d f5 20 46 54 53 34 ..#..ENABM. FTS4 +| 3792: 58 4e 4f 43 41 53 45 16 0a 05 00 23 0f 17 45 4e XNOCASE....#..EN +| 3808: 41 52 4c 45 20 46 54 53 34 58 52 54 52 49 4d 1e ARLE FTS4XRTRIM. +| 3824: 09 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 52 59 1e TAT VTABXBINARY. +| 3856: 08 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3872: 54 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d TAT VTABXNOCASE. +| 3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3904: 54 41 54 20 56 54 41 42 58 52 54 52 49 4d 11 06 TAT VTABXRTRIM.. +| 3920: 05 00 17 0f 19 44 45 42 55 47 58 42 49 4e 41 52 .....DEBUGXBINAR +| 3936: 59 11 05 05 00 17 0f 19 44 45 42 55 47 58 4e 4f Y.......DEBUGXNO +| 3952: 43 41 53 45 10 04 05 00 17 0f 17 44 45 42 55 47 CASE.......DEBUG +| 3968: 58 52 54 52 49 4d 27 03 05 00 43 0f 19 43 4f 4d XRTRIM'...C..COM +| 3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20 PILER=gcc-5.4.0 +| 4000: 32 30 31 36 30 36 30 39 58 42 49 4e 41 52 59 27 20160609XBINARY' +| 4016: 02 04 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67 ...C..COMPILER=g +| 4032: 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36 30 cc-5.4.0 2016060 +| 4048: 39 58 4e 4f 43 41 53 45 26 01 05 00 43 0f 17 43 9XNOCASE&...C..C +| 4064: 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e OMPILER=gcc-5.4. +| 4080: 30 20 32 30 31 36 30 36 30 39 58 52 54 52 49 4d 0 20160609XRTRIM +| page 4 offset 12288 +| 0: 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| page 5 offset 16384 +| 0: 0d 00 00 00 02 0b a0 00 0c ad 0b a0 00 00 00 00 ................ +| 2976: 82 0a 02 08 08 09 08 08 17 84 06 30 20 32 35 33 ...........0 253 +| 2992: 00 01 30 04 25 06 1b 00 00 08 32 30 31 36 30 36 ..0.%.....201606 +| 3008: 30 39 03 25 07 00 00 01 34 03 25 05 00 00 01 35 09.%....4.%....5 +| 3024: 03 25 04 00 01 07 30 30 30 30 30 30 30 03 25 1a .%....0000000.%. +| 3040: 00 00 08 63 6f 6d 70 69 6c 65 72 03 25 02 00 00 ...compiler.%... +| 3056: 06 64 62 73 74 61 74 03 25 0a 00 01 04 65 62 75 .dbstat.%....ebu +| 3072: 67 03 25 08 00 00 06 65 6e 61 62 6c 65 09 25 09 g.%....enable.%. +| 3088: 05 04 04 04 04 04 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3104: 6e 03 25 1d 00 00 04 66 74 73 34 03 25 0d 00 03 n.%....fts4.%... +| 3120: 01 35 03 25 0f 00 00 03 67 63 63 03 25 03 00 01 .5.%....gcc.%... +| 3136: 06 65 6f 70 6f 6c 79 03 25 11 00 00 05 6a 73 6f .eopoly.%....jso +| 3152: 6e 31 03 25 13 00 00 04 6c 6f 61 64 03 25 1c 00 n1.%....load.%.. +| 3168: 00 03 6d 61 78 03 25 18 00 01 05 65 6d 6f 72 79 ..max.%....emory +| 3184: 03 25 19 00 03 04 73 79 73 35 03 25 15 00 00 04 .%....sys5.%.... +| 3200: 6f 6d 69 74 03 25 1b 00 00 05 72 74 72 65 65 03 omit.%....rtree. +| 3216: 25 17 00 00 0a 74 68 72 65 61 64 73 61 66 65 03 %....threadsafe. +| 3232: 25 1e 00 00 04 76 74 61 62 03 25 0b 00 86 50 01 %....vtab.%...P. +| 3248: 08 08 08 08 08 17 8d 12 30 20 38 33 35 00 01 30 ........0 835..0 +| 3264: 12 01 06 00 01 06 00 01 06 00 1f 03 00 01 03 00 ................ +| 3280: 01 03 00 00 08 32 30 31 36 30 36 30 39 09 01 07 .....20160609... +| 3296: 00 01 07 00 01 07 00 00 01 34 09 01 05 00 01 05 .........4...... +| 3312: 00 01 05 00 00 01 35 09 01 04 00 01 04 00 01 04 ......5......... +| 3328: 00 01 07 30 30 30 30 30 30 30 09 1c 04 00 01 04 ...0000000...... +| 3344: 00 01 04 00 00 06 62 69 6e 61 72 79 3c 03 01 02 ......binary<... +| 3360: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3376: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3392: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 ................ +| 3408: 01 02 02 00 03 01 02 02 00 00 08 63 6f 6d 70 69 ...........compi +| 3424: 6c 65 72 09 01 02 00 01 02 00 01 02 00 00 06 64 ler............d +| 3440: 62 73 74 61 74 09 07 03 00 01 03 00 01 03 00 01 bstat........... +| 3456: 04 65 62 75 67 09 04 02 00 01 02 00 01 02 00 00 .ebug........... +| 3472: 06 65 6e 61 62 6c 65 3f 07 02 00 01 02 00 01 02 .enable?........ +| 3488: 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00 ................ +| 3504: 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 ................ +| 3520: 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 ................ +| 3536: 00 01 02 00 01 02 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3552: 6e 09 1f 04 00 01 04 00 01 04 00 00 04 66 74 73 n............fts +| 3568: 34 09 0a 03 00 01 03 00 01 03 00 03 01 35 09 0d 4............5.. +| 3584: 03 00 01 03 00 01 03 00 00 03 67 63 63 09 01 03 ..........gcc... +| 3600: 00 01 03 00 01 03 00 01 06 65 6f 70 6f 6c 79 09 .........eopoly. +| 3616: 10 03 00 01 03 00 01 03 00 00 05 6a 73 6f 6e 31 ...........json1 +| 3632: 09 13 03 00 01 03 00 01 03 00 00 04 6c 6f 61 64 ............load +| 3648: 09 1f 03 00 01 03 00 01 03 00 00 03 6d 61 78 09 ............max. +| 3664: 1c 02 00 01 02 00 01 02 00 01 05 65 6d 6f 72 79 ...........emory +| 3680: 09 1c 03 00 01 03 00 01 03 00 03 04 73 79 73 35 ............sys5 +| 3696: 09 16 03 00 01 03 00 01 03 00 00 06 6e 6f 63 61 ............noca +| 3712: 73 65 3c 02 01 02 02 00 03 01 02 02 00 03 01 02 se<............. +| 3728: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3744: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3760: 03 01 02 02 00 13 01 02 02 00 03 01 02 02 00 00 ................ +| 3776: 04 6f 6d 69 74 09 1f 02 00 01 12 00 01 02 00 00 .omit........... +| 3792: 05 72 74 72 65 65 09 19 03 00 01 81 00 01 03 00 .rtree.......... +| 3808: 03 02 69 6d 3c 01 01 02 02 00 03 01 02 02 00 03 ..im<........... +| 3824: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 ................ +| 3840: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 ................ +| 3856: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3872: 00 00 0a 74 68 72 65 61 64 73 61 66 65 09 22 02 ...threadsafe... +| 3888: 00 01 02 00 01 02 00 00 04 76 74 61 62 09 07 04 .........vtab... +| 3904: 00 01 04 00 01 04 00 00 01 78 b4 01 01 01 01 02 .........x...... +| 3920: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 3936: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 3952: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 3968: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 3984: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4000: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 4016: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 4032: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 4048: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 4064: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4080: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| page 6 offset 20480 +| 0: 0a 00 00 00 02 0f f5 00 0f fb 0f f5 00 00 00 00 ................ +| 4080: 00 00 00 00 00 05 04 08 09 01 02 04 04 08 08 09 ................ +| page 7 offset 24576 +| 0: 0d 00 00 00 05 0f b8 00 0f f4 0f e9 0f d6 0f c7 ................ +| 16: 0f b8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 4016: 00 00 00 00 00 00 00 00 0d 05 02 23 61 75 74 6f ...........#auto +| 4032: 6d 65 72 67 65 3d 35 0d 04 02 23 6d 65 72 67 65 merge=5...#merge +| 4048: 3d 31 30 30 2c 38 11 03 02 2b 69 6e 74 65 67 72 =100,8...+integr +| 4064: 69 74 79 2d 63 68 65 63 6b 09 02 02 1b 72 65 62 ity-check....reb +| 4080: 75 69 6c 64 0a 01 02 1d 6f 70 74 69 6d 69 7a 65 uild....optimize +| end crash-526ea445f41c02.db +}]} {} + +do_catchsql_test 19.1 { + PRAGMA writable_schema = 1; + SELECT rowid,a,c,snippet(t1,85101090932165,-1,10) FROM t1 WHERE a MATCH 'rtree'; +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +reset_db +do_test 20.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +.open --hexdb +| size 28672 pagesize 4096 filename crash-afecd03c862e58.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07 .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 04 ................ +| 96: 00 00 00 00 0d 0e ef 00 07 0d 4d 00 0f bd 0f 5f ..........M...._ +| 112: 0e f7 0e 06 0e bc 0d a4 0d 4d 00 00 01 00 00 00 .........M...... +| 3392: 00 00 00 00 00 00 00 00 00 00 00 00 00 55 07 07 .............U.. +| 3408: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 73 74 ......tablet1_st +| 3424: 61 74 74 31 5f 73 74 61 74 07 43 52 45 41 54 45 att1_stat.CREATE +| 3440: 20 54 41 42 4c 45 20 27 74 31 5f 73 74 61 74 27 TABLE 't1_stat' +| 3456: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d (id INTEGER PRIM +| 3472: 41 52 59 20 4b 45 59 2c 20 76 61 6c 75 65 20 42 ARY KEY, value B +| 3488: 4c 4f 42 29 60 06 07 17 21 21 01 81 0b 74 61 62 LOB)`...!!...tab +| 3504: 6c 65 74 31 5f 64 6f 63 73 69 7a 65 74 31 5f 64 let1_docsizet1_d +| 3520: 6f 63 73 69 7a 65 06 43 52 45 41 54 45 20 54 41 ocsize.CREATE TA +| 3536: 42 4c 45 20 27 74 31 5f 64 6f 63 73 69 7a 65 27 BLE 't1_docsize' +| 3552: 28 64 6f 63 69 64 20 49 4e 54 45 47 45 52 20 50 (docid INTEGER P +| 3568: 52 49 4d 41 52 59 30 4b 45 59 2c 20 73 69 7a 65 RIMARY0KEY, size +| 3584: 20 42 4c 4f 42 29 81 33 04 07 17 1f 1f 01 82 35 BLOB).3.......5 +| 3600: 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72 74 31 tablet1_segdirt1 +| 3616: 5f 73 65 67 64 69 25 04 43 52 45 41 54 45 20 54 _segdi%.CREATE T +| 3632: 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69 72 27 ABLE 't1_segdir' +| 3648: 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52 2c 69 (level INTEGER,i +| 3664: 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61 72 74 dx INTEGER,start +| 3680: 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52 2c 6c _block INTEGER,l +| 3696: 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 6b 20 eaves_end_block +| 3712: 49 4d 54 45 47 45 52 2c 65 6e 64 5f 62 6c 6f 63 IMTEGER,end_bloc +| 3728: 6b 20 49 4e 54 45 47 45 52 2c 72 6f 6f 74 20 42 k INTEGER,root B +| 3744: 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45 59 28 LOB,PRIMARY KEY( +| 3760: 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 05 06 17 level, idx))1... +| 3776: 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74 65 5f E...indexsqlite_ +| 3792: 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73 65 67 autoindex_t1_seg +| 3808: 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72 05 00 dir_1t1_segdir.. +| 3824: 00 00 08 00 00 00 00 66 03 07 17 23 23 01 81 13 .......f...##... +| 3840: 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e 74 73 tablet1_segments +| 3856: 74 31 5f 73 65 67 6d 65 6e 74 73 03 43 52 45 41 t1_segments.CREA +| 3872: 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 TE TABLE 't1_seg +| 3888: 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64 20 49 ments'(blockid I +| 3904: 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b NTEGER PRIMARY K +| 3920: 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 29 5c EY, block BLOB). +| 3936: 02 07 17 21 21 01 81 03 74 61 62 6c 65 74 31 5f ...!!...tablet1_ +| 3952: 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 65 6e contentt1_conten +| 3968: 74 02 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 t.CREATE TABLE ' +| 3984: 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f 63 69 t1_content'(doci +| 4000: 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 d INTEGER PRIMAR +| 4016: 59 20 4b 45 59 2c 20 27 63 30 61 27 29 41 01 06 Y KEY, 'c0a')A.. +| 4032: 17 11 11 08 71 74 61 62 6c 65 74 31 74 31 43 52 ....qtablet1t1CR +| 4048: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB +| 4064: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 34 LE t1 USING fts4 +| 4080: 28 61 2c 70 72 65 66 69 78 3d 27 31 2c 32 27 29 (a,prefix='1,2') +| page 2 offset 4096 +| 0: 0d 00 00 00 08 0e 1f 00 0f c4 0f 7c 0f 34 0f 07 ...........|.4.. +| 16: 0e c3 0e 97 0e 63 0e 1f 00 00 00 00 00 00 00 00 .....c.......... +| 3600: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 42 ...............B +| 3616: 08 04 00 81 09 73 75 6e 74 20 69 6e 20 63 75 6c .....sunt in cul +| 3632: 70 61 20 71 75 68 20 6f 66 66 69 63 69 61 20 64 pa quh officia d +| 3648: 65 73 65 72 75 6e 74 20 6d 6f 6c 6c 69 74 20 61 eserunt mollit a +| 3664: 6e 69 6d 20 69 64 20 65 73 74 20 6c 61 62 6f 72 nim id est labor +| 3680: 75 6d 2e 32 07 03 01 6b 45 78 63 65 70 74 65 75 um.2...kExcepteu +| 3696: 72 20 73 69 6e 74 20 6f 63 63 61 65 63 61 74 20 r sint occaecat +| 3712: 63 75 70 69 64 61 74 61 74 20 6e 6f 6e 20 70 72 cupidatat non pr +| 3728: 6f 69 64 65 6e 74 2c 2a 06 03 00 5b 63 69 6c 6c oident,*...[cill +| 3744: 75 6d 20 64 6f 6c 6f 72 65 20 65 75 20 66 75 67 um dolore eu fug +| 3760: 69 61 74 20 6e 75 6c 6c 61 20 70 61 72 69 61 74 iat nulla pariat +| 3776: 75 72 2e 43 05 04 00 81 09 44 75 69 73 20 61 75 ur.C.....Duis au +| 3792: 74 65 20 69 72 75 72 65 20 64 6f 6c 6f 72 20 69 te irure dolor i +| 3808: 6e 20 72 65 70 72 65 68 65 6e 64 65 72 69 74 20 n reprehenderit +| 3824: 69 6e 20 76 6f 6c 75 70 74 61 74 65 20 76 65 6c in voluptate vel +| 3840: 69 74 20 65 73 73 65 2b 14 03 00 5d 6e 69 73 69 it esse+...]nisi +| 3856: 20 75 74 20 61 6c 69 71 75 69 70 20 65 78 20 65 ut aliquip ex e +| 3872: 61 20 63 6f 6d 6d 6f 64 6f 20 63 6f 6e 73 65 71 a commodo conseq +| 3888: 75 61 74 2e 46 03 04 00 81 11 55 74 20 65 6e 69 uat.F.....Ut eni +| 3904: 6d 20 61 63 20 6d 69 6e 69 6d 20 76 65 6e 69 61 m ac minim venia +| 3920: 6d 2c 20 71 75 69 73 20 6e 6f 73 74 72 75 64 20 m, quis nostrud +| 3936: 65 78 65 72 63 69 74 61 74 69 6f 6e 20 75 6c 6c exercitation ull +| 3952: 61 6d 63 6f 20 6c 61 62 6f 72 69 73 46 02 04 00 amco laborisF... +| 3968: 81 11 73 65 64 20 64 6f 20 65 69 75 73 6d 6f 64 ..sed do eiusmod +| 3984: 20 74 65 6d 70 6f 72 20 69 6e 63 69 64 69 64 75 tempor incididu +| 4000: 6e 74 20 75 74 20 6c 61 62 6f 72 65 20 65 74 20 nt ut labore et +| 4016: 64 6f 6c 6f 72 65 20 6d 61 67 6e 61 20 61 6c 69 dolore magna ali +| 4032: 71 75 61 2e 3a 01 03 00 7b 4c 6f 72 65 6d 20 69 qua.:....Lorem i +| 4048: 70 73 75 6d 20 64 6f 6c 6f 72 20 73 69 74 20 61 psum dolor sit a +| 4064: 6d 65 74 2c 20 63 6f 6e 73 65 63 74 65 74 75 72 met, consectetur +| 4080: 20 61 64 69 70 69 73 63 69 6e 67 20 65 6c 69 74 adipiscing elit +| page 3 offset 8192 +| 0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................ +| page 4 offset 12288 +| 0: 0d 00 00 00 03 0a a6 00 0d 57 0c 4a 0a a6 00 00 .........W.J.... +| 2720: 00 00 00 00 00 00 83 21 03 08 02 08 08 08 17 86 .......!........ +| 2736: 30 08 00 30 20 34 30 32 00 02 61 64 06 01 08 00 0..0 402..ad.... +| 2752: 02 04 00 01 01 6c 06 02 0c 00 02 04 00 01 01 6d .....l.........m +| 2768: 03 01 06 00 01 01 6e 03 08 09 00 01 01 75 03 05 ......n......u.. +| 2784: 03 00 00 02 63 69 03 06 01 00 01 01 6f 07 01 07 ....ci......o... +| 2800: 00 03 07 03 00 01 01 75 06 07 05 00 01 04 00 00 .......u........ +| 2816: 02 64 65 03 08 07 00 01 01 6f 0d 01 04 00 01 03 .de......o...... +| 2832: 09 00 03 05 00 01 03 00 01 01 75 03 05 02 00 00 ..........u..... +| 2848: 02 65 61 03 04 06 00 01 01 69 03 02 04 00 01 01 .ea......i...... +| 2864: 6c 03 01 09 00 01 01 6e 03 03 03 00 01 01 73 06 l......n......s. +| 2880: 05 0b 00 03 0b 00 01 01 74 03 02 09 00 01 01 75 ........t......u +| 2896: 03 06 04 00 01 01 78 09 03 09 00 01 05 00 03 02 ......x......... +| 2912: 00 00 02 66 75 03 06 05 00 00 02 69 64 03 08 0a ...fu......id... +| 2928: 00 01 01 6e 0a 02 06 00 03 06 04 00 03 03 00 01 ...n............ +| 2944: 01 70 03 01 13 00 01 01 72 03 05 04 00 00 02 6c .p......r......l +| 2960: 61 09 02 08 00 01 0b 00 05 0c 00 01 01 6f 03 01 a............o.. +| 2976: 02 00 00 02 6d 61 03 02 0b 00 01 01 69 03 03 05 ....ma......i... +| 2992: 00 01 01 6f 03 08 08 00 00 02 6e 69 03 04 02 00 ...o......ni.... +| 3008: 01 01 6f 06 03 08 00 04 06 00 01 01 75 03 06 06 ..o.........u... +| 3024: 00 00 02 6f 63 03 07 04 00 01 01 66 03 08 06 00 ...oc......f.... +| 3040: 00 02 70 61 03 06 07 00 01 01 72 03 07 07 00 00 ..pa......r..... +| 3056: 02 71 75 06 03 07 00 05 05 00 00 02 72 65 03 05 .qu.........re.. +| 3072: 07 00 00 02 73 65 03 02 02 00 01 01 69 06 01 05 ....se......i... +| 3088: 00 06 03 00 01 01 75 03 08 02 00 00 02 74 65 03 ......u......te. +| 3104: 03 05 00 00 02 72 bc 03 03 0a 00 01 01 74 09 02 .....r.......t.. +| 3120: 07 00 01 02 00 01 03 00 00 02 76 65 06 03 06 00 ..........ve.... +| 3136: 02 0a 00 01 01 6f 03 05 09 00 82 0a 02 08 02 08 .....o.......... +| 3152: 08 08 17 84 02 04 00 30 20 32 35 31 00 01 61 13 .......0 251..a. +| 3168: 01 06 04 00 01 0c 00 01 04 00 01 04 00 01 03 00 ................ +| 3184: 03 09 00 00 01 63 10 01 07 00 03 07 03 00 02 02 .....c.......... +| 3200: 00 01 05 00 01 04 00 00 01 64 11 01 04 00 01 03 .........d...... +| 3216: 09 00 03 02 05 00 01 03 00 02 07 00 00 01 65 1b ..............e. +| 3232: 01 09 00 01 04 07 00 01 03 08 00 01 05 03 00 01 ................ +| 3248: 0b 00 01 04 00 01 02 00 01 0b 00 00 01 66 03 06 .............f.. +| 3264: 05 00 00 01 69 0f 01 03 00 01 06 00 02 04 04 04 ....i........... +| 3280: 00 03 03 09 00 00 01 6c 0c 01 02 00 01 08 00 01 .......l........ +| 3296: 0b 00 05 0c 00 00 01 6d 09 02 0b 00 01 05 00 05 .......m........ +| 3312: 08 00 00 01 6e 0c 03 08 00 01 02 00 02 06 00 01 ....n........... +| 3328: 06 00 f0 01 6f 06 07 04 00 01 06 00 00 01 70 06 ....o.........p. +| 3344: 06 07 00 01 07 00 00 01 71 06 03 07 00 05 05 00 ........q....... +| 3360: 00 01 72 03 05 08 00 00 01 73 0c 01 05 00 01 02 ..r......s...... +| 3376: 00 05 03 00 01 02 00 00 01 74 03 02 05 00 00 01 .........t...... +| 3392: 75 0a 02 07 00 01 02 0a 00 01 03 00 00 01 76 07 u.............v. +| 3408: 03 06 00 02 09 03 00 85 26 01 08 08 08 08 08 17 ........&....... +| 3424: 8a 3e 30 21 36 36 35 00 02 61 64 03 03 04 00 02 .>0!665..ad..... +| 3440: 08 69 70 69 73 63 69 6e 67 03 01 08 00 01 05 6c .ipiscing......l +| 3456: 69 71 75 61 03 02 0c 00 05 02 69 70 03 04 04 00 iqua......ip.... +| 3472: 01 03 6d 65 74 03 01 06 00 01 03 6e 69 6d 03 08 ..met......nim.. +| 3488: 09 00 01 03 75 74 65 03 05 03 00 00 06 63 69 6c ....ute......cil +| 3504: 6c 75 6d 03 06 02 00 01 06 6f 6d 6d 6f 64 6f 03 lum......ommodo. +| 3520: 04 07 00 02 09 6e 73 65 63 74 65 74 75 72 03 01 .....nsectetur.. +| 3536: 07 00 05 04 71 75 61 74 03 04 08 00 01 04 75 6c ....quat......ul +| 3552: 70 61 03 08 04 00 02 07 70 69 64 61 74 61 74 03 pa......pidatat. +| 3568: 07 05 00 00 08 64 65 73 65 72 75 6e 74 03 08 07 .....deserunt... +| 3584: 00 01 01 6f 03 02 03 00 02 03 6c 6f 72 06 01 04 ...o......lor... +| 3600: 00 04 05 00 05 01 65 06 02 0a 00 04 03 00 01 03 ......e......... +| 3616: 75 69 73 03 05 02 00 00 02 65 61 03 04 06 00 01 uis......ea..... +| 3632: 06 69 75 73 6d 6f 64 03 02 04 00 01 03 6c 69 74 .iusmod......lit +| 3648: 03 01 09 00 01 03 6e 69 6d 03 03 03 00 01 03 73 ......nim......s +| 3664: 73 65 03 05 0b 00 02 01 74 03 08 0b 00 01 01 74 se......t......t +| 3680: 03 02 09 00 01 01 75 03 06 04 00 01 01 78 03 04 ......u......x.. +| 3696: 05 00 02 07 63 65 70 74 65 75 72 03 07 02 00 02 ....cepteur..... +| 3712: 0a 65 72 63 69 74 61 74 69 6f 6e 03 03 09 00 00 .ercitation..... +| 3728: 06 66 75 67 69 61 74 03 06 05 00 00 02 69 64 03 .fugiat......id. +| 3744: 08 0a 00 01 01 6e 07 05 06 04 00 03 03 00 02 08 .....n.......... +| 3760: 63 69 64 69 64 75 6e 74 03 02 06 00 01 04 70 73 cididunt......ps +| 3776: 75 6d 03 01 03 00 01 04 72 75 72 65 03 05 04 00 um......rure.... +| 3792: 00 06 6c 61 62 6f 72 65 03 02 08 00 05 02 69 73 ..labore......is +| 3808: 03 03 0b 00 05 02 75 6d 03 08 0c 00 01 04 6f 72 ......um......or +| 3824: 65 6d 03 01 02 00 00 05 6d 61 67 6e 61 03 02 0b em......magna... +| 3840: 00 01 04 69 6e 69 6d 03 03 05 00 01 05 6f 6c 6c ...inim......oll +| 3856: 69 74 03 08 08 00 00 04 6e 69 73 69 03 04 02 00 it......nisi.... +| 3872: 01 02 6f 6e 03 07 06 00 02 05 73 74 72 75 64 03 ..on......strud. +| 3888: 03 08 00 01 04 75 6c 6c 61 03 06 06 00 00 08 6f .....ulla......o +| 3904: 63 63 61 65 63 61 74 03 07 04 00 01 06 66 66 69 ccaecat......ffi +| 3920: 63 69 61 03 08 06 00 00 08 70 61 72 69 61 74 75 cia......pariatu +| 3936: 72 03 06 07 00 01 07 72 6f 69 64 65 6e 74 03 07 r......roident.. +| 3952: 07 00 00 03 71 75 69 03 08 05 00 03 01 73 03 03 ....qui......s.. +| 3968: 07 00 00 0d 72 65 41 72 65 68 65 6e 64 65 72 69 ....reArehenderi +| 3984: 74 03 05 07 00 00 03 73 65 64 03 02 02 00 01 03 t......sed...... +| 4000: 69 6e 74 03 07 03 00 02 01 74 03 01 05 00 01 03 int......t...... +| 4016: 75 6e 74 03 08 02 00 00 06 74 65 6d 70 6f 72 03 unt......tempor. +| 4032: 02 05 00 00 07 75 6c 6c 61 6d 63 6f 03 03 0a 00 .....ullamco.... +| 4048: 01 01 74 09 02 07 00 01 02 00 01 03 00 00 05 76 ..t............v +| 4064: 65 6c 69 74 03 05 0a 00 02 04 6e 69 61 6d 03 03 elit......niam.. +| 4080: 06 00 01 08 70 6c 75 70 74 61 74 65 03 05 09 00 ....pluptate.... +| page 5 offset 16384 +| 0: 0a 00 00 00 03 0f eb 00 0f fb 0f f3 0f eb 00 00 ................ +| 4064: 00 00 00 00 00 00 00 00 00 00 00 07 04 02 08 01 ................ +| 4080: 08 00 03 07 04 0a 98 01 04 00 02 04 04 08 08 09 ................ +| page 6 offset 20480 +| 0: 0d 00 00 00 08 0f d0 00 0f fa 0f f4 0f ee 0f e8 ................ +| 16: 0f e2 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 4048: 04 08 03 00 0e 0b 04 07 03 00 0e 06 04 06 03 00 ................ +| 4064: 0e 06 04 05 03 00 0e 0a 04 04 03 00 0e 07 04 03 ................ +| 4080: 03 00 0e 0a 04 02 03 00 0e 0b 04 01 03 00 0e 08 ................ +| page 7 offset 24576 +| 0: 0d 00 00 00 01 0f f7 00 0f f7 00 00 00 00 00 00 ................ +| 4080: 00 00 00 00 00 00 00 07 00 03 00 14 08 45 b5 03 .............E.. +| end crash-afecd03c862e58.db +}]} {} + +do_execsql_test 20.1 { + PRAGMA writable_schema = 1; + BEGIN; + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<10) + INSERT INTO t1(a) SELECT randomblob(3000) FROM c; +} + +do_execsql_test 20.2 { + INSERT INTO t1(t1) VALUES('optimize'); +} + +#------------------------------------------------------------------------- +reset_db +do_test 21.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 28672 pagesize 4096 filename crash-18cc014e42e828.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07 .....@ ........ +| 32: 00 00 00 02 00 00 00 01 00 00 00 07 00 00 00 04 ................ +| 96: 00 00 00 00 0d 0e b1 00 06 0d a4 00 0f 8d 0f 21 ...............! +| 112: 0e b9 0d c8 0e 7e 0d a4 00 00 00 00 00 00 00 00 .....~.......... +| 3488: 00 00 00 00 22 07 06 17 11 11 01 31 74 61 62 6c ...........1tabl +| 3504: 66 74 32 74 32 07 43 52 45 41 54 45 20 54 41 42 ft2t2.CREATE TAB +| 3520: 4c 45 20 74 32 28 78 29 81 33 05 07 17 1f 1f 01 LE t2(x).3...... +| 3536: 82 35 74 61 62 6c 65 74 31 5f 73 75 67 64 69 72 .5tablet1_sugdir +| 3552: 74 31 5f 73 65 67 64 69 72 05 43 52 45 41 54 45 t1_segdir.CREATE +| 3568: 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69 TABLE 't1_segdi +| 3584: 72 27 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52 r'(level INTEGER +| 3600: 2c 69 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61 ,idx INTEGER,sta +| 3616: 72 74 5f 62 6c 6f 63 6b 20 49 4e 54 46 47 45 52 rt_block INTFGER +| 3632: 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 ,leaves_end_bloc +| 3648: 6b 20 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c k INTEGER,end_bl +| 3664: 6f 63 6b 20 49 4e 54 45 47 45 62 2c 72 6f 6f 74 ock INTEGEb,root +| 3680: 20 42 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45 BLOB,PRIMARY KE +| 3696: 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 06 Y(level, idx))1. +| 3712: 06 17 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74 ..E...indexsqlit +| 3728: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73 e_autoindex_t1_s +| 3744: 65 67 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72 egdir_1t1_segdir +| 3760: 06 0f c7 00 08 00 00 00 00 66 04 07 17 23 23 01 .........f...##. +| 3776: 81 13 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e ..tablet1_segmen +| 3792: 74 73 74 31 5f 73 65 67 6d 65 6e 74 73 04 43 52 tst1_segments.CR +| 3808: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 EATE TABLE 't1_s +| 3824: 65 67 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64 egments'(blockid +| 3840: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 INTEGER PRIMARY +| 3856: 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 KEY, block BLOB +| 3872: 29 6a 03 07 17 21 21 01 81 1f 74 61 62 6c 65 74 )j...!!...tablet +| 3888: 31 5f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 1_contentt1_cont +| 3904: 65 6e 74 03 43 52 45 41 54 45 20 54 41 42 4c 45 ent.CREATE TABLE +| 3920: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f 't1_content'(do +| 3936: 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d cid INTEGER PRIM +| 3952: 41 52 59 20 4b 45 59 2c 20 27 63 30 61 27 2c 20 ARY KEY, 'c0a', +| 3968: 27 63 31 62 27 2c 20 27 63 32 63 27 29 38 02 06 'c1b', 'c2c')8.. +| 3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52 ...._tablet1t1CR +| 4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB +| 4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33 LE t1 USING fts3 +| 4032: 28 61 2c 62 2c 63 29 00 00 00 00 00 00 00 00 00 (a,b,c)......... +| page 3 offset 8192 +| 0: 0d 00 00 00 25 0b 48 00 0f d8 0f af 0f 86 0f 74 ....%.H........t +| 16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5 .a.N./.......... +| 32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 0d ef 0d d5 ...t.[.@.$...... +| 48: 0d bb 0d a0 0d 84 0d 68 0d 4e 0d 35 0d 1b 0c fb .......h.N.5.... +| 64: 0c da 0c b9 0c 99 0c 78 0c 57 0c 3e 0c 24 00 00 .......x.W.>.$.. +| 2880: 00 00 00 00 00 00 00 00 81 3f 25 06 00 82 7f 00 .........?%..... +| 2896: 00 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e .COMPILER=gcc-5. +| 2912: 34 23 00 20 32 30 31 36 30 36 30 39 20 44 45 42 4#. 20160609 DEB +| 2928: 55 47 20 45 4e 41 42 4c 45 20 44 42 53 54 41 54 UG ENABLE DBSTAT +| 2944: 20 56 54 41 42 20 45 4e 41 42 4c 45 20 46 43 53 VTAB ENABLE FCS +| 2960: 34 20 45 4e 41 42 4c 45 20 46 54 53 35 20 45 4e 4 ENABLE FTS5 EN +| 2976: 41 42 4c 45 20 47 45 4f 50 4f 4c 59 20 45 4e 41 ABLE GEOPOLY ENA +| 2992: 42 4c 45 20 4a 53 4f 4e 31 20 45 4e 41 42 4c 45 BLE JSON1 ENABLE +| 3008: 20 4d 45 4d 53 59 53 35 20 45 4e 41 42 4c 45 20 MEMSYS5 ENABLE +| 3024: 52 54 52 45 45 20 4d 41 58 20 4d 45 4d 4f 52 59 RTREE MAX MEMORY +| 3040: 3d 35 30 30 30 30 30 30 30 20 4f 4d 49 54 20 4c =50000000 OMIT L +| 3056: 4f 41 44 20 45 58 54 45 4e 53 49 4f 4e 20 54 48 OAD EXTENSION TH +| 3072: 52 45 41 44 53 41 46 45 3d 30 18 24 05 00 25 0f READSAFE=0.$..%. +| 3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49 .THREADSAFE=0XBI +| 3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41 NARY.#..%..THREA +| 3120: 44 53 41 46 45 3d 30 58 4e 4f 43 41 53 45 17 22 DSAFE=0XNOCASE.. +| 3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 45 3d ..%..THREADSAFE= +| 3152: 30 58 52 54 52 49 4d 20 21 05 00 33 0f 19 4f 4d 0XRTRIM !..3..OM +| 3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 4f IT LOAD EXTENSIO +| 3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f NXBINARY. ..3..O +| 3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 MIT LOAD EXTENSI +| 3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17 ONXNOCASE....3.. +| 3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 OMIT LOAD EXTENS +| 3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f 19 IONXRTRIM....3.. +| 3264: 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 30 MAX MEMORY=50000 +| 3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f 000XBINARY....3. +| 3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 .MAX MEMORY=5000 +| 3312: 30 30 30 30 58 4e 4f 43 41 53 45 1e 1c 05 00 33 0000XNOCASE....3 +| 3328: 0f 17 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 ..MAX MEMORY=500 +| 3344: 30 30 30 30 30 58 52 54 52 49 4d 18 1b 05 00 25 00000XRTRIM....% +| 3360: 0f 19 45 4e 41 42 4c 45 20 52 54 52 45 45 58 42 ..ENABLE RTREEXB +| 3376: 49 4e 41 52 59 18 1a 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3392: 4c 45 20 52 54 52 45 45 58 4e 4f 43 41 53 45 17 LE RTREEXNOCASE. +| 3408: 19 05 00 25 0f 17 45 4e 41 42 4c 45 20 52 54 52 ...%..ENABLE RTR +| 3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45 EEXRTRIM....)..E +| 3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 58 42 49 NABLE MEMSYS5XBI +| 3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4e 41 42 4c NARY....)..ENABL +| 3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 53 45 E MEMSYS5XNOCASE +| 3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 4d 45 ....)..ENABLE ME +| 3504: 4d 53 59 53 35 58 52 54 52 49 4d 18 15 05 00 25 MSYS5XRTRIM....% +| 3520: 0f 19 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 58 42 ..ENABLE JSON1XB +| 3536: 49 4e 41 52 59 18 14 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3552: 4c 45 20 4a 53 4f 4e 31 58 4e 4f 43 41 53 45 17 LE JSON1XNOCASE. +| 3568: 13 05 00 25 0f 17 45 4e 41 42 4c 45 20 4a 53 4f ...%..ENABLE JSO +| 3584: 4e 31 58 52 54 52 49 4d 1a 12 05 00 29 0f 19 45 N1XRTRIM....)..E +| 3600: 4e 41 42 4c 45 20 47 45 4f 50 4f 4c 59 58 42 39 NABLE GEOPOLYXB9 +| 3616: 4e 41 52 59 1a 11 05 00 29 0f 19 45 4e 41 1e 4c NARY....)..ENA.L +| 3632: 45 20 47 45 4f 50 4f 4c 59 58 4e 4f 43 41 53 45 E GEOPOLYXNOCASE +| 3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 45 ....)..ENABLE GE +| 3664: 4f 50 4f 4c 59 58 52 54 52 49 4d 17 0f 05 00 23 OPOLYXRTRIM....# +| 3680: 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 58 42 49 ..ENABLE FTS5XBI +| 3696: 4e 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 4c NARY....#..ENABL +| 3712: 45 20 46 54 53 35 58 4e 4f 43 41 53 45 16 0d 05 E FTS5XNOCASE... +| 3728: 00 23 0f 16 45 4e 41 42 4c 45 20 46 54 53 35 58 .#..ENABLE FTS5X +| 3744: 52 54 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42 RTRIM....#..ENAB +| 3760: 4c 45 20 46 54 53 34 58 42 48 4e 41 52 59 17 0b LE FTS4XBHNARY.. +| 3776: 05 00 23 0e 19 45 4e 41 42 4c 45 20 46 54 53 35 ..#..ENABLE FTS5 +| 3792: 58 4e 4f 43 40 53 45 16 0a 05 00 23 0f 17 45 4e XNOC@SE....#..EN +| 3808: 41 42 4c 45 20 46 54 53 34 58 52 2e 52 49 4d 1e ABLE FTS4XR.RIM. +| 3824: 09 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 52 59 1e TAT VTABXBINARY. +| 3856: 08 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3872: 54 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d TAT VTABXNOCASE. +| 3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3904: 54 41 54 20 56 54 41 42 58 52 54 52 49 4d 11 06 TAT VTABXRTRIM.. +| 3920: 05 00 17 0f 19 44 45 42 55 47 58 42 49 4e 41 52 .....DEBUGXBINAR +| 3936: 59 11 05 05 00 17 0f 19 44 45 42 55 47 58 4e 4f Y.......DEBUGXNO +| 3952: 43 41 53 45 10 04 05 00 17 0f 17 44 45 42 55 47 CASE.......DEBUG +| 3968: 58 52 54 52 49 4d 27 03 05 00 43 0f 19 43 4f 4d XRTRIM'...C..COM +| 3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20 PILER=gcc-5.4.0 +| 4000: 32 30 31 36 30 36 30 39 58 42 49 da 41 52 59 27 20160609XBI.ARY' +| 4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67 ...C..COMPILER=g +| 4032: 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36 30 cc-5.4.0 2016060 +| 4048: 39 58 4e 4f 43 41 53 45 26 01 05 00 43 0f 17 43 9XNOCASE&...C..C +| 4064: 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 00 00 00 00 OMPILER=gcc-.... +| page 5 offset 16384 +| 0: 0d 00 00 00 02 0b a0 00 0c ad 0b a0 00 00 00 00 ................ +| 2976: 82 0a 02 08 08 09 08 08 17 84 06 30 20 32 35 33 ...........0 253 +| 2992: 00 01 30 04 25 06 1b 00 00 08 32 30 31 36 30 36 ..0.%.....201606 +| 3008: 30 3a 03 25 07 00 00 01 34 03 25 05 00 00 01 35 0:.%....4.%....5 +| 3024: 03 25 04 00 01 07 30 30 30 30 30 30 30 03 25 1a .%....0000000.%. +| 3040: 00 00 08 63 6f 6d 70 69 6c 65 72 03 25 02 00 00 ...compiler.%... +| 3056: 06 64 62 73 74 61 74 03 25 0a 00 01 04 65 62 75 .dbstat.%....ebu +| 3072: 67 03 25 08 00 00 06 65 6e 61 62 6c 65 09 25 09 g.%....enable.%. +| 3088: 05 04 04 04 04 04 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3104: 6e 03 25 1d 00 00 04 66 74 73 34 03 25 0d 00 03 n.%....fts4.%... +| 3120: 01 35 03 25 0f 00 00 03 57 63 63 03 25 03 00 01 .5.%....Wcc.%... +| 3136: 06 65 6f 70 6f 6c 79 03 25 11 00 00 05 6a 73 6f .eopoly.%....jso +| 3152: 6e 31 03 25 13 00 00 04 6c 6f 61 64 03 25 1c 00 n1.%....load.%.. +| 3168: 00 03 6d 61 78 03 25 18 00 01 05 65 6d 6f 72 79 ..max.%....emory +| 3184: 03 25 19 00 03 04 73 79 73 35 03 25 15 00 00 04 .%....sys5.%.... +| 3200: 6f 6d 69 74 03 25 1b 00 00 05 72 74 72 65 65 03 omit.%....rtree. +| 3216: 25 17 00 00 0a 74 68 72 65 64 64 73 61 66 65 03 %....threddsafe. +| 3232: 25 1e 00 00 04 76 74 61 62 03 25 0b 00 86 50 01 %....vtab.%...P. +| 3248: 08 08 08 08 08 17 8d 12 30 20 38 33 35 00 01 30 ........0 835..0 +| 3264: 12 01 06 00 01 06 00 01 06 00 1f 03 00 01 03 00 ................ +| 3280: 01 03 00 00 08 32 30 31 36 30 36 30 39 09 01 07 .....20160609... +| 3296: 00 01 07 00 01 07 00 00 01 34 09 01 05 00 01 05 .........4...... +| 3312: 00 01 05 00 00 01 35 09 01 04 00 01 04 00 01 04 ......5......... +| 3328: 00 01 07 30 30 30 30 30 30 30 09 1c 04 00 01 04 ...0000000...... +| 3344: 00 01 04 00 00 06 62 69 6e 61 72 79 3c 03 01 02 ......binary<... +| 3360: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3376: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3392: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 ................ +| 3408: 01 02 02 00 03 01 02 02 00 00 08 63 6f 6d 70 69 ...........compi +| 3424: 6c 65 72 09 01 02 00 01 02 00 01 02 00 00 06 64 ler............d +| 3440: 62 73 74 61 74 09 07 03 00 01 03 00 01 03 00 01 bstat........... +| 3456: 04 65 62 75 67 09 04 02 00 01 02 00 01 02 00 00 .ebug........... +| 3472: 06 65 6e 61 62 6c 65 3f 07 02 00 01 02 00 01 12 .enable?........ +| 3488: 00 01 02 00 01 02 00 01 02 00 01 02 0e 97 02 00 ................ +| 3504: 01 02 00 01 cb 00 01 02 00 01 02 00 01 02 10 01 ................ +| 3520: 02 00 01 02 00 01 02 01 01 02 00 01 02 00 01 02 ................ +| 3536: 00 01 02 00 01 02 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3552: 6e 09 1f 04 00 01 04 00 01 04 00 00 04 66 74 73 n............fts +| 3568: 34 09 0a 03 00 01 03 00 01 03 00 03 01 35 09 0d 4............5.. +| 3584: 03 00 01 03 00 01 03 00 00 03 67 63 63 09 01 03 ..........gcc... +| 3600: 00 01 03 00 01 03 00 01 06 65 6f 70 6f 6c 79 09 .........eopoly. +| 3616: 10 03 00 01 03 00 01 03 00 00 05 6a 73 6f 6e 31 ...........json1 +| 3632: 09 13 03 00 01 03 00 01 03 00 00 04 6c 6f 61 64 ............load +| 3648: 09 1f 03 00 01 03 00 01 03 00 00 03 6d 61 78 09 ............max. +| 3664: 1c 02 00 01 02 00 01 02 00 01 05 65 6d 6f 72 79 ...........emory +| 3680: 09 1c 03 00 01 03 00 01 03 00 03 04 73 79 73 35 ............sys5 +| 3696: 09 16 03 00 01 03 00 01 03 00 00 06 6e 6f 63 61 ............noca +| 3712: 73 65 3c 02 01 02 02 00 03 01 02 02 00 03 01 02 se<............. +| 3728: 02 00 03 01 02 02 00 03 01 02 02 00 ab 01 02 02 ................ +| 3744: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3760: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 00 ................ +| 3776: 04 6f 6d 69 74 09 1f 12 00 01 02 00 01 02 00 00 .omit........... +| 3792: 05 72 74 72 65 65 09 19 03 00 01 03 00 01 03 00 .rtree.......... +| 3808: 03 02 69 6d 3c 01 01 02 02 00 03 01 02 02 00 03 ..im<........... +| 3824: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 ................ +| 3840: 02 02 00 03 01 02 01 f0 03 01 02 02 00 03 01 02 ................ +| 3856: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3872: 00 00 0a 74 68 72 65 61 64 73 61 66 65 09 22 02 ...threadsafe... +| 3888: 00 01 02 00 02 02 00 00 04 76 74 61 62 09 07 04 .........vtab... +| 3904: 00 01 04 00 01 04 00 00 01 78 b4 01 01 01 08 a2 .........x...... +| 3920: 00 01 01 01 02 00 01 01 01 02 00 02 01 01 02 00 ................ +| 3936: 01 01 01 01 ff f1 01 01 02 00 01 01 01 02 00 01 ................ +| 3952: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 3968: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 3984: 02 00 01 01 01 02 00 01 01 01 02 01 01 01 01 02 ................ +| 4000: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 4016: 01 01 01 02 00 01 01 01 02 00 01 01 01 03 00 01 ................ +| 4032: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 4048: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 4064: 02 00 01 01 01 02 00 01 02 01 02 00 01 01 01 02 ................ +| 4080: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| page 6 offset 20480 +| 0: 0a 00 00 00 02 0f f5 00 0f fb 0f f5 00 00 00 00 ................ +| 4080: 00 00 00 00 00 05 04 08 09 01 02 04 04 08 08 09 ................ +| page 7 offset 24576 +| 0: 0d 00 00 00 05 0f b8 00 00 00 00 00 00 00 00 00 ................ +| 4016: 00 00 00 00 00 00 00 00 0d 05 02 23 61 75 74 6f ...........#auto +| 4032: 6d 65 72 67 65 3d 35 0d 04 02 23 6d 65 72 67 65 merge=5...#merge +| 4048: 3d 31 30 30 2c 38 11 03 02 2b 69 6e 74 65 67 72 =100,8...+integr +| 4064: 69 74 79 2d 63 68 65 63 6b 09 02 02 1b 72 65 62 ity-check....reb +| 4080: 75 69 6c 64 0a 01 02 1d 00 00 00 00 00 00 00 00 uild............ +| end crash-18cc014e42e828.db +}]} {} + +do_catchsql_test 21.1 { + PRAGMA writable_schema = 1; + SELECT offsets(t1) FROM t1 WHERE t1 MATCH 'R*'; +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +reset_db +do_test 22.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 28672 pagesize 4096 filename crash-b794c89d922ac9.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07 .....@ ........ +| 32: 00 00 00 02 00 00 00 01 00 00 00 07 00 00 00 00 ................ +| 96: 00 00 00 00 0d 0e b1 00 06 0d a4 00 0f 8d 0f 21 ...............! +| 112: 0e b9 0d c8 0e 7e 0d a4 00 00 00 00 00 00 00 00 .....~.......... +| 3488: 00 00 00 00 22 07 06 17 11 11 01 31 74 61 62 6c ...........1tabl +| 3504: 65 74 32 74 32 07 43 52 45 41 54 45 20 54 41 42 et2t2.CREATE TAB +| 3520: 4c 45 20 74 32 28 78 29 81 33 05 07 17 1f 1f 01 LE t2(x).3...... +| 3536: 82 35 74 61 61 6c 65 74 31 5f 73 65 67 64 69 72 .5taalet1_segdir +| 3552: 74 31 5f 73 65 67 64 69 72 05 43 52 45 41 54 45 t1_segdir.CREATE +| 3568: 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69 TABLE 't1_segdi +| 3584: 72 27 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52 r'(level INTEGER +| 3600: 2c 69 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61 ,idx INTEGER,sta +| 3616: 72 74 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52 rt_block INTEGER +| 3632: 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 ,leaves_end_bloc +| 3648: 6b 20 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c k INTEGER,end_bl +| 3664: 6f 63 6b 20 49 4e 54 45 47 45 52 2c 72 6f 6f 74 ock INTEGER,root +| 3680: 20 42 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45 BLOB,PRIMARY KE +| 3696: 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 06 Y(level, idx))1. +| 3712: 06 17 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74 ..E...indexsqlit +| 3728: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73 e_autoindex_t1_s +| 3744: 65 67 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72 egdir_1t1_segdir +| 3760: 06 0f c7 00 08 00 00 00 00 66 04 07 17 23 23 01 .........f...##. +| 3776: 81 13 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e ..tablet1_segmen +| 3792: 74 73 74 31 5f 73 65 67 6d 65 6e 74 73 04 43 52 tst1_segments.CR +| 3808: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 EATE TABLE 't1_s +| 3824: 65 67 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64 egments'(blockid +| 3840: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 INTEGER PRIMARY +| 3856: 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 KEY, block BLOB +| 3872: 29 6a 03 07 17 21 21 01 81 1f 74 61 62 6c 65 74 )j...!!...tablet +| 3888: 31 5f 63 6f 6e 84 65 6e 74 74 31 5f 63 6f 6e 74 1_con.entt1_cont +| 3904: 65 6e 74 03 43 52 45 41 54 45 20 54 41 42 4c 45 ent.CREATE TABLE +| 3920: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f 't1_content'(do +| 3936: 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d cid INTEGER PRIM +| 3952: 41 52 59 20 4b 45 59 2c 20 27 63 30 61 27 2c 20 ARY KEY, 'c0a', +| 3968: 27 63 31 62 27 2c 20 27 63 32 63 27 29 38 02 06 'c1b', 'c2c')8.. +| 3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52 ...._tablet1t1CR +| 4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB +| 4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33 LE t1 USING fts3 +| 4032: 28 61 2c 62 2c 63 29 00 00 00 00 00 00 00 00 00 (a,b,c)......... +| page 3 offset 8192 +| 0: 0d 00 00 00 25 0b 48 00 0f d8 0f af 0f 86 0f 74 ....%.H........t +| 16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5 .a.N./.......... +| 32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 0d ef 0d d5 ...t.[.@.$...... +| 48: 0d bb 0d a0 0d 84 0d 68 0d 4f 0d 35 0d 1b 0c fb .......h.O.5.... +| 64: 0c da 0c b9 0c 99 0c 78 0c 57 0c 3e 0c 24 0c 0a .......x.W.>.$.. +| 80: 0b 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .H.............. +| 2880: 00 00 00 00 00 00 00 00 81 3f 25 06 00 82 7f 00 .........?%..... +| 2896: 00 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e .COMPILER=gcc-5. +| 2912: 34 2e 30 20 32 30 31 36 30 36 30 39 20 44 45 42 4.0 20160609 DEB +| 2928: 55 47 20 45 4e 41 42 4c 45 20 44 42 53 54 41 54 UG ENABLE DBSTAT +| 2944: 20 56 54 41 42 20 45 4e 41 42 4c 45 20 46 54 53 VTAB ENABLE FTS +| 2960: 34 20 45 4e 41 42 4c 45 20 46 54 53 35 20 45 4e 4 ENABLE FTS5 EN +| 2976: 41 42 4c 45 20 47 45 4f 50 4f 4c 59 20 45 4e 41 ABLE GEOPOLY ENA +| 2992: 42 4c 45 20 4a 53 4f 4e 31 20 45 4e 41 42 4c 45 BLE JSON1 ENABLE +| 3008: 20 4d 45 4d 53 49 53 35 20 45 4e 41 42 4c 45 20 MEMSIS5 ENABLE +| 3024: 52 54 52 45 45 20 4d 41 58 20 4d 45 4d 4f 52 59 RTREE MAX MEMORY +| 3040: 3d 35 30 30 30 30 30 30 30 20 4f 4d 49 54 20 4c =50000000 OMIT L +| 3056: 4f 41 44 20 45 58 54 45 4e 53 49 4f 4e 20 54 48 OAD EXTENSION TH +| 3072: 52 45 41 44 53 41 46 45 3d 30 18 24 05 00 26 0f READSAFE=0.$..&. +| 3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49 .THREADSAFE=0XBI +| 3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41 NARY.#..%..THREA +| 3120: 44 53 41 46 45 3d 30 58 4e 4f 43 41 53 45 17 22 DSAFE=0XNOCASE.. +| 3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 45 3d ..%..THREADSAFE= +| 3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d 0XRTRIM.!..3..OM +| 3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 4f IT LOAD EXTENSIO +| 3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f NXBINARY. ..3..O +| 3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 MIT LOAD EXTENSI +| 3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17 ONXNOCASE....3.. +| 3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 OMIT LOAD EXTENS +| 3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f 19 IONXRTRIM....3.. +| 3264: 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 30 MAX MEMORY=50000 +| 3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f 000XBINARY....3. +| 3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 .MAX MEMORY=5000 +| 3312: 30 30 30 30 58 4e 4f 43 41 53 45 1e 1c 05 00 33 0000XNOCASE....3 +| 3328: 0f 17 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 ..MAX MEMORY=500 +| 3344: 30 30 30 30 30 58 52 54 52 49 4d 18 1b 05 00 25 00000XRTRIM....% +| 3360: 0f 19 45 4e 41 42 4c 45 20 52 54 52 45 45 58 42 ..ENABLE RTREEXB +| 3376: 49 4e 41 52 59 18 1a 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3392: 4c 55 20 52 54 52 45 45 58 4e 4f 43 41 53 45 17 LU RTREEXNOCASE. +| 3408: 19 05 00 25 0f 17 45 4e 41 42 4c 45 20 52 54 52 ...%..ENABLE RTR +| 3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45 EEXRTRIM....)..E +| 3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 58 42 49 NABLE MEMSYS5XBI +| 3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4e 41 42 4c NARY....)..ENABL +| 3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 53 45 E MEMSYS5XNOCASE +| 3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 4d 45 ....)..ENABLE ME +| 3504: 4d 53 59 53 35 58 52 54 52 49 4d 18 15 05 00 25 MSYS5XRTRIM....% +| 3520: 0f 19 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 58 42 ..ENABLE JSON1XB +| 3536: 49 4e 41 52 59 18 14 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3552: 4c 45 20 4a 53 4f 4e 31 58 4e 4f 43 41 53 45 17 LE JSON1XNOCASE. +| 3568: 13 05 00 25 0f 17 45 4e 41 42 4c 45 20 4a 53 4f ...%..ENABLE JSO +| 3584: 4e 31 58 52 54 52 49 4d 1a 12 05 00 29 0f 19 45 N1XRTRIM....)..E +| 3600: 4e 41 42 4c 45 20 47 45 4f 50 4f 4c 59 58 42 49 NABLE GEOPOLYXBI +| 3616: 4e 41 52 59 1a 11 05 00 29 0f 19 45 4e 41 42 4c NARY....)..ENABL +| 3632: 45 20 47 45 4f 50 4f 4c 59 58 4e 4f 43 41 53 45 E GEOPOLYXNOCASE +| 3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 45 ....)..ENABLE GE +| 3664: 4f 50 4f 4c 59 58 52 54 52 49 4d 17 0f 05 00 23 OPOLYXRTRIM....# +| 3680: 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 58 42 49 ..ENABLE FTS5XBI +| 3696: 4e 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 4c NARY....#..ENABL +| 3712: 45 20 46 54 53 35 58 4e 4f 43 41 53 45 16 0d 05 E FTS5XNOCASE... +| 3728: 00 23 0f 17 45 4e 41 42 4c 45 20 46 54 53 35 58 .#..ENABLE FTS5X +| 3744: 52 54 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42 RTRIM....#..ENAB +| 3760: 4c 45 19 46 54 53 34 58 42 49 4e 41 52 59 17 0b LE.FTS4XBINARY.. +| 3776: 05 00 23 0f 19 45 4e 41 42 4e f5 20 46 54 53 34 ..#..ENABN. FTS4 +| 3792: 58 4e 4f 43 41 53 45 16 0a 05 00 23 0f 17 45 4e XNOCASE....#..EN +| 3808: 41 42 4c 45 20 46 54 53 34 58 52 54 52 49 4d 1e ABLE FTS4XRTRIM. +| 3824: 09 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 52 59 1e TAT VTABXBINARY. +| 3856: 08 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3872: 54 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d TAT VTABXNOCASE. +| 3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 44 41 53 ...1..ENABLE DAS +| 3904: 54 41 54 20 56 54 41 42 58 52 54 52 49 4d 11 06 TAT VTABXRTRIM.. +| 3920: 05 00 17 0f 19 44 45 42 55 47 58 42 49 4e 41 52 .....DEBUGXBINAR +| 3936: 59 11 05 05 00 17 0f 19 44 45 42 55 47 58 4e 4f Y.......DEBUGXNO +| 3952: 43 41 53 45 10 04 05 00 17 ab 17 44 45 42 55 47 CASE.......DEBUG +| 3968: 48 52 54 52 49 4d 27 03 05 00 43 0f 19 43 4f 4d HRTRIM'...C..COM +| 3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20 PILER=gcc-5.4.0 +| 4000: 32 30 31 36 30 36 30 39 58 43 49 4e 41 52 59 27 20160609XCINARY' +| 4016: 02 04 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67 ...C..COMPILER=g +| 4032: 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36 30 cc-5.4.0 2016060 +| 4048: 39 58 4e 4f 43 41 53 45 26 01 05 00 43 0f 17 43 9XNOCASE&...C..C +| 4064: 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e OMPILER=gcc-5.4. +| 4080: 30 20 32 30 31 36 30 36 30 39 58 52 54 52 49 4d 0 20160609XRTRIM +| page 4 offset 12288 +| 0: 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| page 5 offset 16384 +| 0: 0d 00 00 00 02 0b a0 00 0c ad 0b a0 00 00 00 00 ................ +| 2976: 82 0a 02 08 08 09 08 08 17 84 06 30 20 32 35 33 ...........0 253 +| 2992: 00 01 30 04 25 06 1b 00 00 08 32 30 31 36 30 36 ..0.%.....201606 +| 3008: 30 39 03 25 07 00 00 01 34 03 25 05 00 00 01 35 09.%....4.%....5 +| 3024: 03 25 04 00 01 07 30 30 30 30 30 30 30 03 25 1a .%....0000000.%. +| 3040: 00 00 08 63 6f 6d 70 69 6c 65 72 03 25 02 00 00 ...compiler.%... +| 3056: 06 64 62 73 74 61 74 03 25 0a 00 01 04 65 62 75 .dbstat.%....ebu +| 3072: 67 03 25 08 00 00 06 65 6e 61 62 6c 65 09 25 09 g.%....enable.%. +| 3088: 05 04 04 04 04 04 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3104: 6e 03 25 1d 00 00 04 66 74 73 34 03 25 0d 00 03 n.%....fts4.%... +| 3120: 01 35 03 25 0f 00 00 03 67 63 63 03 25 03 00 01 .5.%....gcc.%... +| 3136: 06 65 6f 70 6f 6c 79 03 25 11 00 00 05 6a 73 6f .eopoly.%....jso +| 3152: 6e 31 03 25 13 00 00 04 6c 6f 61 64 03 25 1c 00 n1.%....load.%.. +| 3168: 00 03 6d 61 78 03 25 18 00 01 05 65 6d 6f 72 79 ..max.%....emory +| 3184: 03 25 19 00 03 04 73 79 73 35 03 25 15 00 00 04 .%....sys5.%.... +| 3200: 6f 6d 69 74 03 25 1b 00 00 05 72 74 72 65 65 03 omit.%....rtree. +| 3216: 25 17 00 00 0a 74 68 72 65 61 64 73 61 66 65 03 %....threadsafe. +| 3232: 25 1e 00 00 04 76 74 61 62 03 25 0b 00 86 50 01 %....vtab.%...P. +| 3248: 08 08 08 08 08 17 8d 12 30 20 38 33 35 00 01 30 ........0 835..0 +| 3264: 12 01 06 00 01 06 00 01 06 00 1f 03 00 01 03 00 ................ +| 3280: 01 03 00 00 08 32 30 31 36 30 36 30 39 09 01 07 .....20160609... +| 3296: 00 01 07 00 01 07 00 00 01 34 09 01 05 00 01 05 .........4...... +| 3312: 00 01 05 00 00 01 35 09 01 04 00 01 04 00 01 04 ......5......... +| 3328: 00 01 07 30 30 30 30 30 30 30 09 1c 04 00 01 04 ...0000000...... +| 3344: 00 01 04 00 00 06 62 69 6e 61 72 79 3c 03 01 02 ......binary<... +| 3360: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3376: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3392: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 ................ +| 3408: 01 02 02 00 03 01 02 02 00 00 08 63 6f 6d 70 69 ...........compi +| 3424: 6c 65 72 09 01 02 00 01 02 00 01 02 00 00 06 64 ler............d +| 3440: 62 73 74 61 74 09 07 03 00 01 03 00 01 03 00 01 bstat........... +| 3456: 04 65 62 75 67 09 04 02 00 01 02 00 01 02 00 00 .ebug........... +| 3472: 06 65 6e 61 62 6c 65 3f 07 02 00 01 02 00 01 02 .enable?........ +| 3488: 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00 ................ +| 3504: 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 ................ +| 3520: 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 ................ +| 3536: 00 01 02 00 01 02 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3552: 6e 09 1f 04 00 01 04 00 01 04 00 00 04 66 74 73 n............fts +| 3568: 34 09 0a 03 d4 01 02 ff 01 03 00 03 01 35 09 0d 4............5.. +| 3584: 03 00 01 03 00 01 03 00 00 03 67 64 d3 09 01 03 ..........gd.... +| 3600: 00 01 03 00 01 03 00 01 06 65 6f 70 6f 6c 79 09 .........eopoly. +| 3616: 10 03 00 01 03 00 01 03 00 00 05 6a 73 6f 6e 31 ...........json1 +| 3632: 19 13 03 00 01 03 00 01 03 00 00 04 6c 6f 61 64 ............load +| 3648: 09 1f 03 00 01 03 00 01 03 00 00 03 6d 61 78 09 ............max. +| 3664: 1c 02 00 01 02 00 01 02 00 01 05 65 6d 6f 72 79 ...........emory +| 3680: 09 1c 03 00 01 03 00 01 03 00 03 04 73 79 73 35 ............sys5 +| 3696: 09 16 03 00 01 03 00 01 03 00 00 06 6e 6f 63 61 ............noca +| 3712: 73 65 3c 02 01 02 02 00 03 01 02 02 00 03 01 02 se<............. +| 3728: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3744: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3760: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 00 ................ +| 3776: 04 6f 6d 69 74 09 1f 02 00 01 12 00 01 02 00 00 .omit........... +| 3792: 05 72 74 72 65 65 09 19 03 00 01 07 80 00 f3 00 .rtree.......... +| 3808: 03 02 69 6d 3c 01 01 02 02 00 03 01 02 02 00 03 ..im<........... +| 3824: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 ................ +| 3840: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 ................ +| 3856: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3872: 00 00 0a 74 68 72 65 61 64 73 61 66 65 09 22 02 ...threadsafe... +| 3888: 00 01 02 00 01 02 00 00 04 76 74 61 62 09 07 04 .........vtab... +| 3904: 00 01 04 00 01 04 00 00 01 78 b4 01 01 01 01 02 .........x...... +| 3920: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 3936: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 3952: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 3968: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 3984: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4000: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 4016: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 4032: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 4048: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 4064: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4080: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| page 6 offset 20480 +| 0: 0a 00 00 00 02 0f f5 00 0f fb 0f f5 00 00 00 00 ................ +| 4080: 00 00 00 00 00 05 04 08 09 01 02 04 04 08 08 09 ................ +| page 7 offset 24576 +| 0: 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 4016: 00 00 00 00 00 00 00 00 0d 05 02 23 61 75 74 6f ...........#auto +| 4032: 6d 65 72 67 65 3d 35 0d 04 02 23 6d 65 72 67 65 merge=5...#merge +| 4048: 3d 31 30 30 2c 38 11 03 02 2b 69 6e 74 65 67 72 =100,8...+integr +| 4064: 69 74 79 2d 63 68 65 63 6b 09 02 02 1b 72 65 62 ity-check....reb +| end crash-b794c89d922ac9.db +}]} {} + +do_catchsql_test 22.1 { + PRAGMA writable_schema = 1; + SELECT snippet(t1,'', '', '--',-1,01)==0 + FROM t1 WHERE a MATCH 'rtree OR json1rtree OR json1'; +} {0 {0 0 0 0 0 0 0}} + +#------------------------------------------------------------------------- +reset_db +do_test 23.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +.open --hexdb +| size 28672 pagesize 4096 filename crash-670b15f2955a36.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07 .....@ ........ +| 32: 00 00 00 02 10 00 00 01 00 00 00 07 00 00 00 00 ................ +| 96: 00 00 00 00 0d 0e b1 00 06 0d a4 00 0f 8d 0f 21 ...............! +| 112: 0e b9 0d c8 0e 7e 0d a4 00 00 00 00 00 00 00 00 .....~.......... +| 3488: 00 00 00 00 22 07 06 17 11 11 01 31 74 61 62 6c ...........1tabl +| 3504: 65 74 32 74 32 07 43 52 45 41 54 45 20 54 41 42 et2t2.CREATE TAB +| 3520: 4c 45 20 74 32 28 78 29 81 33 05 07 17 1f 1f 01 LE t2(x).3...... +| 3536: 82 35 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72 .5tablet1_segdir +| 3552: 74 31 5f 73 65 67 64 69 72 05 43 52 45 41 54 45 t1_segdir.CREATE +| 3568: 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69 TABLE 't1_segdi +| 3584: 72 27 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52 r'(level INTEGER +| 3600: 2c 69 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61 ,idx INTEGER,sta +| 3616: 72 74 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52 rt_block INTEGER +| 3632: 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 ,leaves_end_bloc +| 3648: 6b 20 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c k INTEGER,end_bl +| 3664: 6f 63 6b 20 49 4e 54 45 47 45 52 2c 72 6f 6f 74 ock INTEGER,root +| 3680: 20 42 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45 BLOB,PRIMARY KE +| 3696: 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 06 Y(level, idx))1. +| 3712: 06 17 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74 ..E...indexsqlit +| 3728: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73 e_autoindex_t1_s +| 3744: 65 67 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72 egdir_1t1_segdir +| 3760: 06 0f c7 00 08 00 00 00 00 66 04 07 17 23 23 01 .........f...##. +| 3776: 81 13 74 61 62 6c 75 74 31 5f 73 65 67 6d 65 6e ..tablut1_segmen +| 3792: 74 73 74 31 5f 73 65 67 6d 65 6e 74 73 04 43 52 tst1_segments.CR +| 3808: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 EATE TABLE 't1_s +| 3824: 65 67 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64 egments'(blockid +| 3840: 20 49 4e 54 45 47 45 42 20 50 52 49 4d 41 52 59 INTEGEB PRIMARY +| 3856: 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 KEY, block BLOB +| 3872: 29 6a 03 07 17 21 21 01 81 1f 74 61 62 6c 65 74 )j...!!...tablet +| 3888: 31 5f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 1_contentt1_cont +| 3904: 65 6e 74 03 43 52 45 41 54 45 20 54 41 42 4c 45 ent.CREATE TABLE +| 3920: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f 't1_content'(do +| 3936: 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d cid INTEGER PRIM +| 3952: 41 52 59 20 4b 45 59 2c 20 27 63 30 61 27 2c 20 ARY KEY, 'c0a', +| 3968: 27 63 31 62 27 2c 20 27 63 32 63 27 29 38 02 06 'c1b', 'c2c')8.. +| 3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52 ...._tablet1t1CR +| 4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB +| 4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33 LE t1 USING fts3 +| 4032: 28 61 2c 62 2c 63 29 00 00 00 00 00 00 00 00 00 (a,b,c)......... +| page 3 offset 8192 +| 0: 0d 00 00 00 25 0b 48 01 0f d8 00 2f 0f 86 0f 74 ....%.H..../...t +| 16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5 .a.N./.......... +| 32: 0e 8d 0e 74 0e 5a fe 40 0e 24 0e 08 0d ef 0d d5 ...t.Z.@.$...... +| 48: 0d bb 0d a0 0d 84 0d 68 0d 4f 81 35 0d 1b 0c fb .......h.O.5.... +| 64: 0c da 0c b9 0c 99 0c 78 0c 57 0c 3e 00 00 00 00 .......x.W.>.... +| 2880: 00 00 00 00 00 00 00 00 81 3f 25 06 00 82 7f 10 .........?%..... +| 2896: 00 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e .COMPILER=gcc-5. +| 2912: 34 2e 30 20 32 30 31 36 30 36 30 39 20 44 45 42 4.0 20160609 DEB +| 2928: 55 47 20 45 4e 41 42 4c 45 20 44 42 53 54 41 54 UG ENABLE DBSTAT +| 2944: 20 56 54 41 42 20 45 4e 41 42 4c 45 20 46 54 53 VTAB ENABLE FTS +| 2960: 34 20 45 4e 41 42 4c 45 20 46 54 53 35 20 45 4e 4 ENABLE FTS5 EN +| 2976: 41 42 4c 45 20 47 45 4f 50 4f 4c 59 20 45 4e 41 ABLE GEOPOLY ENA +| 2992: 42 4c 45 20 4a 53 4f 4e 31 20 45 4e 41 42 4c 45 BLE JSON1 ENABLE +| 3008: 20 4d 45 4d 53 59 53 35 20 45 4e 41 42 4c 45 20 MEMSYS5 ENABLE +| 3024: 52 54 52 45 45 20 4d 41 58 20 4d 45 4d 4f 52 59 RTREE MAX MEMORY +| 3040: 3d 35 30 30 30 30 30 30 30 20 4f 4d 49 54 20 4c =50000000 OMIT L +| 3056: 4f 41 44 20 45 58 54 45 4e 53 49 4f 4e 20 54 48 OAD EXTENSION TH +| 3072: 52 45 41 44 53 41 46 45 3d 30 18 24 05 00 35 0f READSAFE=0.$..5. +| 3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49 .THREADSAFE=0XBI +| 3104: 4e 41 52 59 18 23 55 00 25 0f 19 54 48 52 45 41 NARY.#U.%..THREA +| 3120: 44 53 41 46 45 3d 30 58 4e 4f 43 41 53 45 17 22 DSAFE=0XNOCASE.. +| 3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 45 3d ..%..THREADSAFE= +| 3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d 0XRTRIM.!..3..OM +| 3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 4f IT LOAD EXTENSIO +| 3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f NXBINARY. ..3..O +| 3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 MIT LOAD EXTENSI +| 3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17 ONXNOCASE....3.. +| 3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 OMIT LOAD EXTENS +| 3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f 19 IONXRTRIM....3.. +| 3264: 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 30 MAX MEMORY=50000 +| 3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f 000XBINARY....3. +| 3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 .MAX MEMORY=5000 +| 3312: 30 30 30 30 58 4e 4f 43 41 53 45 1e 1c 05 00 33 0000XNOCASE....3 +| 3328: 0f 17 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 ..MAX MEMORY=500 +| 3344: 30 30 30 30 30 58 52 54 52 49 4d 18 1b 05 00 25 00000XRTRIM....% +| 3360: 0f 19 45 4e 41 42 4c 44 20 52 54 52 45 45 58 42 ..ENABLD RTREEXB +| 3376: 49 4e 41 52 59 18 1a 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3392: 4c 45 20 52 54 52 45 45 58 4e 4f 43 41 53 45 17 LE RTREEXNOCASE. +| 3408: 19 05 00 24 0f 17 45 4e 40 42 4c 45 20 52 54 52 ...$..EN@BLE RTR +| 3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45 EEXRTRIM....)..E +| 3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 58 42 49 NABLE MEMSYS5XBI +| 3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4d 41 42 4c NARY....)..EMABL +| 3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 4c 45 E MEMSYS5XNOCALE +| 3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 4d 45 ....)..ENABLE ME +| 3504: 4e 53 59 53 35 58 52 54 52 49 4d 18 15 05 00 25 NSYS5XRTRIM....% +| 3520: 0f 19 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 58 42 ..ENABLE JSON1XB +| 3536: 49 4e 41 52 59 18 14 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3552: 4c 45 20 4a 53 4f 4e 31 58 4e 4f 43 41 53 45 17 LE JSON1XNOCASE. +| 3568: 13 05 00 25 0f 17 45 4e 41 42 4c 45 20 4a 53 4f ...%..ENABLE JSO +| 3584: 4e 31 58 52 54 5f b9 4d 1a 12 05 00 29 0f 19 45 N1XRT_.M....)..E +| 3600: 4e 41 42 4c 45 20 47 45 4f 50 31 4c 59 58 42 49 NABLE GEOP1LYXBI +| 3616: 4e 41 52 58 1a 11 05 00 29 0f 19 45 4e 41 42 4c NARX....)..ENABL +| 3632: 45 20 47 45 4f 50 4f 4c 59 58 4e 4f 43 41 53 45 E GEOPOLYXNOCASE +| 3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 57 45 ....)..ENABLE WE +| 3664: 4f 50 4f 4c 59 48 52 54 52 49 4d 17 0f 05 00 23 OPOLYHRTRIM....# +| 3680: 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 58 42 49 ..ENABLE FTS5XBI +| 3696: 4e 41 53 59 17 0e 05 00 23 0f 19 45 4e 40 42 4b NASY....#..EN@BK +| 3712: 45 20 46 54 53 35 58 4e 4f 43 41 53 45 16 0d 05 E FTS5XNOCASE... +| 3728: 00 23 0f 17 45 4e 41 42 4c 45 20 46 54 53 35 58 .#..ENABLE FTS5X +| 3744: 52 54 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42 RTRIM....#..ENAB +| 3760: 4c 45 20 46 54 94 34 58 42 49 4e 41 52 59 17 0b LE FT.4XBINARY.. +| 3776: 05 00 23 0f 19 45 4e 41 42 4c 43 70 46 54 53 34 ..#..ENABLCpFTS4 +| 3792: 58 4e 4f 43 41 53 45 16 0a 05 00 23 0f 17 45 4e XNOCASE....#..EN +| 3808: 41 42 4c 45 20 46 54 53 34 58 52 54 52 49 4d 1e ABLE FTS4XRTRIM. +| 3824: 09 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 52 59 1e TAT VTABXBINARY. +| 3856: 08 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 32 53 ...1..ENABLE D2S +| 3872: 54 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d TAT VTABXNOCASE. +| 3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3904: 54 41 54 20 56 54 41 42 58 52 54 52 49 4d 11 06 TAT VTABXRTRIM.. +| 3920: 05 0b 27 0f 19 44 45 42 55 47 58 42 49 4e 41 52 ..'..DEBUGXBINAR +| 3936: 59 11 05 05 00 17 0f 19 44 45 42 55 47 58 4e 4f Y.......DEBUGXNO +| 3952: 43 41 53 45 10 03 05 00 17 0f 17 44 45 42 55 47 CASE.......DEBUG +| 3968: 58 52 54 52 49 4d 27 03 05 00 43 0f 19 43 4f 4d XRTRIM'...C..COM +| 3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20 PILER=gcc-5.4.0 +| 4000: 32 30 31 36 30 36 30 39 58 42 49 4e 41 52 59 27 20160609XBINARY' +| 4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 35 52 3d 67 ...C..COMPIL5R=g +| 4032: 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36 30 cc-5.4.0 2016060 +| 4048: 39 58 4e 4f 43 41 53 45 26 01 05 00 43 0f 02 43 9XNOCASE&...C..C +| 4064: 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e OMPILER=gcc-5.4. +| 4080: 30 20 32 30 31 36 30 36 30 39 58 00 00 00 00 00 0 20160609X..... +| page 5 offset 16384 +| 0: 0d 00 00 00 02 0b a0 00 0c ad 0b a0 00 00 00 00 ................ +| 2976: 82 0a 02 08 08 09 08 08 17 84 06 30 20 32 35 33 ...........0 253 +| 2992: 00 01 30 04 25 06 1b 00 00 08 32 30 31 36 30 36 ..0.%.....201606 +| 3008: 30 39 03 25 07 00 00 01 34 03 25 05 00 00 01 35 09.%....4.%....5 +| 3024: 03 25 04 00 01 07 30 30 30 30 30 30 30 08 55 1a .%....0000000.U. +| 3040: 00 00 08 63 6f 6d 70 69 6c 65 72 03 25 02 00 00 ...compiler.%... +| 3056: 06 64 62 73 74 61 74 03 25 0a 00 01 04 65 61 75 .dbstat.%....eau +| 3072: 67 03 25 08 00 00 06 65 6e 61 62 6c 65 09 25 09 g.%....enable.%. +| 3088: 05 04 04 04 04 04 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3104: 6e 03 25 1d 00 00 04 66 74 73 34 03 25 0d 00 03 n.%....fts4.%... +| 3120: 01 35 03 25 0f 00 00 0c 97 63 63 03 25 03 00 01 .5.%.....cc.%... +| 3136: 06 65 6f 70 6f 6c 7a 03 25 11 00 00 05 6a 73 6f .eopolz.%....jso +| 3152: 6e 31 03 25 13 00 00 04 6c 6f 61 64 03 25 1c 00 n1.%....load.%.. +| 3168: 00 03 6d 61 78 03 25 18 00 01 05 65 6d 6f 72 79 ..max.%....emory +| 3184: 03 25 3d f0 03 04 73 79 73 35 03 25 15 00 00 04 .%=...sys5.%.... +| 3200: 6f 6d 69 74 03 25 1b 00 00 05 72 74 72 65 65 03 omit.%....rtree. +| 3216: 25 17 00 00 0a 74 68 72 65 61 64 73 61 66 65 03 %....threadsafe. +| 3232: 25 1e 00 00 04 76 74 61 62 03 25 0b 00 86 50 01 %....vtab.%...P. +| 3248: 08 08 08 09 08 17 8d 12 30 20 38 33 37 e3 aa e0 ........0 837... +| 3264: 12 d1 06 00 01 06 00 01 06 00 1f 03 00 01 03 00 ................ +| 3280: 01 03 00 00 08 32 30 31 36 30 36 30 49 09 01 07 .....2016060I... +| 3296: 00 01 07 00 01 07 00 00 01 34 09 01 05 00 01 05 .........4...... +| 3312: 00 01 05 00 00 01 35 09 01 04 00 01 04 00 01 04 ......5......... +| 3328: 00 01 07 30 30 30 30 30 30 30 09 1c 04 00 01 04 ...0000000...... +| 3344: 00 01 04 00 00 06 62 69 6e 61 72 79 3c 03 01 02 ......binary<... +| 3360: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3376: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3392: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 ................ +| 3408: 01 02 02 00 03 01 02 02 00 00 08 63 6f 6d 70 69 ...........compi +| 3424: 6c 65 72 09 01 02 00 01 02 00 01 02 00 00 06 64 ler............d +| 3440: 62 73 74 61 74 09 07 03 00 01 03 00 01 03 00 01 bstat........... +| 3456: 04 65 62 75 67 09 04 01 f0 01 02 00 01 02 00 00 .ebug........... +| 3472: 06 65 6e 61 62 6c 65 3f 07 02 00 01 02 00 01 02 .enable?........ +| 3488: 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00 ................ +| 3504: 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 ................ +| 3520: 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 ................ +| 3536: 00 01 02 00 01 02 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3552: 6e 09 1f 04 00 01 04 00 01 04 00 00 04 66 74 73 n............fts +| 3568: 34 09 0a 03 f3 01 03 00 01 03 00 19 01 35 09 0d 4............5.. +| 3584: 03 00 01 03 00 01 03 00 00 03 67 63 63 09 01 03 ..........gcc... +| 3600: 00 01 03 00 01 03 00 01 06 65 6f 70 6f 6c 79 09 .........eopoly. +| 3616: 10 03 00 01 03 00 01 03 00 00 05 6a 73 6f 6e 31 ...........json1 +| 3632: 09 13 03 00 01 03 00 00 f3 00 00 04 6c 6f 61 64 ............load +| 3648: 09 1f 03 00 01 03 00 01 03 00 00 03 6d 61 78 09 ............max. +| 3664: 1c 02 00 01 02 00 01 02 00 01 05 65 6d 6f 72 79 ...........emory +| 3680: 09 1c 03 00 01 03 00 01 03 00 03 04 73 79 73 35 ............sys5 +| 3696: 09 16 03 00 01 03 00 01 03 00 00 06 6e 6f 63 61 ............noca +| 3712: 73 65 3c 02 01 02 02 00 03 01 02 02 00 03 01 02 se<............. +| 3728: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3744: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3760: 03 01 02 02 00 03 01 02 02 00 46 01 02 02 00 00 ..........F..... +| 3776: 04 6f 6d 69 74 09 1f 02 00 01 02 00 01 02 00 00 .omit........... +| 3792: 05 72 74 72 64 65 09 19 03 00 01 03 00 01 03 00 .rtrde.......... +| 3808: 03 02 69 6d 3c 01 01 02 02 00 03 01 02 02 00 03 ..im<........... +| 3824: 01 02 02 00 03 01 02 01 ff 03 01 02 02 00 03 01 ................ +| 3840: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 ................ +| 3856: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3872: 00 00 0a 74 68 72 65 61 64 73 61 66 65 09 22 02 ...threadsafe... +| 3888: 00 01 02 00 01 02 00 00 04 76 74 61 62 09 07 04 .........vtab... +| 3904: 00 01 04 00 01 04 00 00 01 78 b4 01 01 01 01 02 .........x...... +| 3920: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 3936: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 3952: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 3968: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 3984: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4000: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 4016: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 4032: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 4048: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 4064: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 02 02 ................ +| 4080: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| page 6 offset 20480 +| 0: 0a 00 00 00 02 0f f5 00 0f fb 0f f5 00 00 00 00 ................ +| 4080: 00 00 00 00 00 05 04 08 09 01 02 04 04 08 09 09 ................ +| page 7 offset 24576 +| 0: 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 4016: 00 00 00 00 00 00 00 00 0d 05 02 23 61 75 74 6f ...........#auto +| 4032: 6d 65 71 97 65 3d 35 0d 04 02 23 6d 65 72 67 65 meq.e=5...#merge +| 4048: 3d 31 30 30 2c 38 11 03 02 2b 69 6e 74 65 67 72 =100,8...+integr +| 4064: 69 74 79 00 00 00 00 00 00 00 00 00 00 00 00 00 ity............. +| end crash-670b15f2955a36.db +}]} {} + +do_catchsql_test 23.1 { + PRAGMA writable_schema = 1; + SELECT 'FyzLy'FROM t1 WHERE t1 MATCH 'j'; +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +reset_db +do_test 24.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +.open --hexdb +| size 28672 pagesize 4096 filename crash-369d042958c29b.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 03 10 00 00 00 00 .....@ ........ +| 96: 00 00 00 00 0d 0e b1 00 06 0d a4 00 0f 8d 0f 21 ...............! +| 112: 0e b9 0d c8 0e 7e 0d a4 00 00 00 00 00 00 00 00 .....~.......... +| 3488: 00 00 00 00 22 07 06 17 11 11 01 31 74 61 62 6c ...........1tabl +| 3504: 65 74 32 74 32 07 43 52 45 41 54 45 20 54 41 42 et2t2.CREATE TAB +| 3520: 4c 45 20 74 32 28 78 29 81 33 05 07 17 1f 1f 01 LE t2(x).3...... +| 3536: 82 35 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72 .5tablet1_segdir +| 3552: 74 31 5f 73 65 67 64 69 72 05 43 52 45 41 54 45 t1_segdir.CREATE +| 3568: 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69 TABLE 't1_segdi +| 3584: 72 27 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52 r'(level INTEGER +| 3600: 2c 69 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61 ,idx INTEGER,sta +| 3616: 72 74 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52 rt_block INTEGER +| 3632: 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 ,leaves_end_bloc +| 3648: 6b 20 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c k INTEGER,end_bl +| 3664: 6f 63 6b 20 49 4e 54 45 47 45 52 2c 72 6f 6f 74 ock INTEGER,root +| 3680: 20 42 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45 BLOB,PRIMARY KE +| 3696: 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 06 Y(level, idx))1. +| 3712: 06 17 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74 ..E...indexsqlit +| 3728: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73 e_autoindex_t1_s +| 3744: 65 67 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72 egdir_1t1_segdir +| 3760: 06 0f c7 00 08 00 10 00 00 66 04 07 17 23 23 01 .........f...##. +| 3776: 81 13 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e ..tablet1_segmen +| 3792: 64 73 74 31 5f 73 65 67 6d 65 6e 74 73 04 43 52 dst1_segments.CR +| 3808: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 EATE TABLE 't1_s +| 3824: 65 67 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64 egments'(blockid +| 3840: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 INTEGER PRIMARY +| 3856: 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 KEY, block BLOB +| 3872: 29 6a 03 07 17 21 21 01 81 1f 74 61 62 6c 65 74 )j...!!...tablet +| 3888: 31 4f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 1Ocontentt1_cont +| 3904: 65 6e 74 03 43 52 45 41 54 45 20 54 41 42 4c 45 ent.CREATE TABLE +| 3920: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f 't1_content'(do +| 3936: 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 39 4d cid INTEGER PR9M +| 3952: 41 52 59 20 4b 45 59 2c 20 27 63 30 61 27 2c 20 ARY KEY, 'c0a', +| 3968: 27 63 31 62 27 2c 20 27 63 32 63 27 29 38 02 06 'c1b', 'c2c')8.. +| 3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52 ...._tablet1t1CR +| 4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB +| 4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33 LE t1 USING fts3 +| 4032: 28 61 2c 62 2c 63 29 00 00 00 00 00 00 00 00 00 (a,b,c)......... +| page 3 offset 8192 +| 0: 0d 00 00 00 26 0b 48 0e 0f d8 0f af 0f 86 0f 74 ....&.H........t +| 16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5 .a.N./.......... +| 32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 0d ef 0d d5 ...t.[.@.$...... +| 48: 0d bb 0d a0 0e 94 03 28 0d 4f 0d 35 0d 1b 05 0b .......(.O.5.... +| 64: 0c da 0c b9 0c 99 0c 78 0c 57 0c 3e 0c 24 0c 0a .......x.W.>.$.. +| 2880: 00 00 00 00 00 00 00 00 81 3f 25 06 00 72 7f 00 .........?%..r.. +| 2896: 00 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e .COMPILER=gcc-5. +| 2912: 34 2e 30 20 32 30 31 36 30 36 30 39 20 44 55 42 4.0 20160609 DUB +| 2928: 55 47 20 45 4e 41 e4 7c 45 20 44 42 53 54 41 54 UG ENA.|E DBSTAT +| 2944: e4 d1 54 41 42 20 45 4e 41 42 4c 45 20 46 54 53 ..TAB ENABLE FTS +| 2960: 34 20 45 4e 41 42 4c 45 20 46 54 53 35 20 45 4e 4 ENABLE FTS5 EN +| 2976: 41 42 4c 45 20 47 45 4f 50 4f 4c 59 20 45 4e 41 ABLE GEOPOLY ENA +| 2992: 42 4c 45 20 4a 53 4f 4e 31 20 45 4e 41 42 4c 45 BLE JSON1 ENABLE +| 3008: 20 4d 45 4d 53 59 53 35 20 45 4e 41 42 4c 45 20 MEMSYS5 ENABLE +| 3024: 42 54 52 45 45 20 4d 41 58 20 4d 45 4d 4f 52 59 BTREE MAX MEMORY +| 3040: 3d 35 30 30 30 30 30 30 30 20 4f 4c 49 54 20 4c =50000000 OLIT L +| 3056: 4f 41 43 20 45 58 54 45 4e 53 49 4f 4e 21 54 48 OAC EXTENSION!TH +| 3072: 52 45 41 44 53 41 46 45 3d 30 18 24 05 00 25 0f READSAFE=0.$..%. +| 3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49 .THREADSAFE=0XBI +| 3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41 NARY.#..%..THREA +| 3120: 44 53 41 4b 75 3d 30 58 4d 4f 43 41 53 45 17 22 DSAKu=0XMOCASE.. +| 3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 46 3d ..%..THREADSAFF= +| 3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d 0XRTRIM.!..3..OM +| 3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 52 49 4f IT LOAD EXTENRIO +| 3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f NXBINARY. ..3..O +| 3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 MIT LOAD EXTENSI +| 3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17 ONXNOCASE....3.. +| 3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 OMIT LOAD EXTENS +| 3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f 19 IONXRTRIM....3.. +| 3264: 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 30 MAX MEMORY=50000 +| 3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f 000XBINARY....3. +| 3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 .MAX MEMORY=5000 +| 3312: 30 30 30 30 58 4e 4f 43 41 53 45 1e 1c 05 00 33 0000XNOCASE....3 +| 3328: 0f 17 4d 42 b8 20 4d 45 4d 4f 52 59 3d 35 30 30 ..MB. MEMORY=500 +| 3344: 30 30 30 30 30 58 52 54 52 49 4d 18 1b 05 00 25 00000XRTRIM....% +| 3360: 0f 19 45 4e 41 42 4c 45 20 52 54 52 45 45 58 42 ..ENABLE RTREEXB +| 3376: 49 4e 41 52 59 18 1a 05 0d a5 0f 19 45 4e 41 42 INARY.......ENAB +| 3392: 4c 45 20 52 54 52 45 45 58 4e 4f 43 41 53 45 17 LE RTREEXNOCASE. +| 3408: 19 1c 00 25 0f 17 45 4e 41 42 4c 45 20 52 54 52 ...%..ENABLE RTR +| 3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45 EEXRTRIM....)..E +| 3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 58 42 49 NABLE MEMSYS5XBI +| 3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4e 41 42 4c NARY....)..ENABL +| 3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 53 45 E MEMSYS5XNOCASE +| 3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 4d 45 ....)..ENABLE ME +| 3504: 4d 53 59 53 35 58 52 54 52 49 4d 18 14 05 01 25 MSYS5XRTRIM....% +| 3520: 0f 19 45 4e 12 42 4c 45 20 4a 53 4f 4e 31 58 42 ..EN.BLE JSON1XB +| 3536: 49 4e 41 52 59 18 14 05 00 25 09 d9 45 4e 41 42 INARY....%..ENAB +| 3552: 4c 45 20 4a 53 4f 3e 31 58 4e 4f 43 41 53 45 17 LE JSO>1XNOCASE. +| 3568: 13 05 00 25 0f 17 45 4e 40 42 4c 45 20 4a 53 4f ...%..EN@BLE JSO +| 3584: 4e 31 58 52 54 52 49 4d 1a 12 05 82 29 0f 19 45 N1XRTRIM....)..E +| 3600: 4e 41 42 4c 45 20 47 45 4f 50 4f 4c 59 58 42 49 NABLE GEOPOLYXBI +| 3616: 4e 41 52 59 1a 11 05 c9 29 e8 19 46 4e 41 42 4c NARY....)..FNABL +| 3632: 48 c0 47 45 4f 50 4f 4c 59 58 4e 74 43 41 53 45 H.GEOPOLYXNtCASE +| 3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 45 ....)..ENABLE GE +| 3664: 4f 50 4f 4c 59 58 52 54 52 49 4d 17 0f 05 00 23 OPOLYXRTRIM....# +| 3680: 0f 19 45 4e 41 42 4c 45 30 46 54 53 35 58 42 49 ..ENABLE0FTS5XBI +| 3696: 4e 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 4c NARY....#..ENABL +| 3712: 45 20 46 54 53 35 58 4e 4f 43 41 53 45 16 0e 05 E FTS5XNOCASE... +| 3728: 00 23 0f 17 45 4e 41 42 4c 45 20 46 54 53 35 58 .#..ENABLE FTS5X +| 3744: 52 54 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42 RTRIM....#..ENAB +| 3760: 4c 45 20 46 54 53 34 58 42 49 4e 41 52 59 17 0b LE FTS4XBINARY.. +| 3776: 05 00 23 0f 19 45 4e 41 42 4c 45 20 46 54 53 34 ..#..ENABLE FTS4 +| 3792: 58 4e 4f 43 41 53 45 16 0a 05 00 23 0f 17 45 4e XNOCASE....#..EN +| 3808: 41 42 4c 45 20 46 54 53 34 58 52 54 52 49 4d 1e ABLE FTS4XRTRIM. +| 3824: 09 05 00 31 0f 19 45 4e 42 42 4c 45 20 44 42 53 ...1..ENBBLE DBS +| 3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 52 59 1e TAT VTABXBINARY. +| 3856: 08 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3872: 54 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d TAT VTABXNOCASE. +| 3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3904: 54 41 54 20 56 54 41 42 58 52 54 52 4a 4d 11 06 TAT VTABXRTRJM.. +| 3920: 05 f0 17 0f 19 44 45 42 55 47 58 42 49 4e 41 52 .....DEBUGXBINAR +| 3936: 59 11 05 05 00 17 0e 19 44 45 42 55 47 58 4e 4f Y.......DEBUGXNO +| 3952: 43 41 53 45 10 04 05 00 17 0f 16 44 45 42 55 47 CASE.......DEBUG +| 3968: 58 52 54 52 49 4d 27 03 05 00 43 0f 19 43 4f 4d XRTRIM'...C..COM +| 3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20 PILER=gcc-5.4.0 +| 4000: 32 30 31 36 30 36 30 39 58 42 49 4e 41 52 59 27 20160609XBINARY' +| 4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67 ...C..COMPILER=g +| 4032: 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36 30 cc-5.4.0 2016060 +| 4048: 39 58 4e 4f 43 41 53 45 26 01 06 00 43 0f 17 43 9XNOCASE&...C..C +| 4064: 4f 4d 50 49 4b 45 52 3d 67 63 63 2d 35 2e 34 2e OMPIKER=gcc-5.4. +| 4080: 30 20 32 30 31 36 30 36 40 39 58 29 54 52 49 4d 0 201606@9X)TRIM +| page 4 offset 12288 +| 0: 0d 00 10 00 00 10 00 00 00 00 00 00 00 01 00 00 ................ +| page 5 offset 16384 +| 0: 0d 00 00 00 02 0b a0 00 0c ad 0b a0 00 00 00 00 ................ +| 2976: 82 0a 02 08 08 09 08 08 17 84 06 30 20 32 35 33 ...........0 253 +| 2992: 00 01 30 04 25 06 1b 00 00 08 32 30 31 36 30 36 ..0.%.....201606 +| 3008: 30 39 03 25 07 00 00 01 34 03 25 05 00 00 01 35 09.%....4.%....5 +| 3024: 03 25 04 00 01 07 30 30 30 30 30 30 30 03 25 1a .%....0000000.%. +| 3040: 00 00 08 63 6f 6d 70 69 6c 65 72 03 25 02 00 00 ...compiler.%... +| 3056: 06 64 62 73 74 61 74 03 25 0a 00 01 04 65 62 75 .dbstat.%....ebu +| 3072: 67 03 25 08 00 00 06 65 6e 61 62 6c 65 09 25 09 g.%....enable.%. +| 3088: 05 04 04 04 04 04 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3104: 6e 03 25 1d 00 00 04 66 74 73 34 03 25 0d 00 03 n.%....fts4.%... +| 3120: 01 35 03 25 0f 00 00 03 67 63 63 03 25 03 00 01 .5.%....gcc.%... +| 3136: 06 65 6f 70 6f 6c 79 03 25 11 00 00 05 6a 73 6f .eopoly.%....jso +| 3152: 6e 31 03 25 13 00 00 04 6c 6f 61 64 03 25 1c 00 n1.%....load.%.. +| 3168: 00 03 6d 61 78 03 25 18 00 01 05 65 6e 6f 72 79 ..max.%....enory +| 3184: 03 25 19 00 03 04 ce 79 73 4d 03 25 15 00 00 04 .%.....ysM.%.... +| 3200: 6f 6d 69 74 03 25 1b 00 00 05 72 74 72 65 65 03 omit.%....rtree. +| 3216: 25 17 00 00 0a 74 68 72 65 61 64 73 61 66 65 03 %....threadsafe. +| 3232: 25 0e 00 00 04 76 74 61 62 03 25 0b 00 86 50 01 %....vtab.%...P. +| 3248: 08 08 08 08 08 17 8d 12 30 20 38 33 35 00 01 30 ........0 835..0 +| 3264: 12 01 06 00 01 06 00 01 06 00 1f 03 00 01 03 09 ................ +| 3280: 51 03 00 00 08 32 30 31 36 30 36 30 39 09 01 07 Q....20160609... +| 3296: 00 01 07 00 01 07 00 00 01 34 09 01 05 00 01 05 .........4...... +| 3312: 00 01 05 00 00 01 35 09 01 04 00 01 04 00 01 04 ......5......... +| 3328: 00 01 07 30 30 30 30 30 30 30 09 1c 04 00 01 04 ...0000000...... +| 3344: 00 01 04 00 00 06 62 69 6e 61 72 79 3c 03 01 02 ......binary<... +| 3360: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3376: 00 03 01 02 02 00 02 f1 02 02 00 03 01 02 02 00 ................ +| 3392: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 ................ +| 3408: 01 02 02 00 03 01 02 02 00 00 08 63 6f 6d 70 69 ...........compi +| 3424: 6c 65 72 09 01 02 00 01 02 00 01 02 00 00 06 67 ler............g +| 3440: d2 73 74 61 74 09 07 03 00 01 03 00 01 03 00 01 .stat........... +| 3456: 04 65 62 75 67 09 04 02 00 01 02 00 01 02 00 00 .ebug........... +| 3472: 06 65 6e 6f 82 6c 65 3f 07 02 00 01 02 00 01 02 .eno.le?........ +| 3488: b0 01 02 00 01 02 00 11 02 00 01 02 00 01 02 00 ................ +| 3504: 01 02 00 01 02 00 01 02 00 01 a6 00 01 02 00 01 ................ +| 3520: 02 05 51 02 00 01 02 00 01 02 00 01 02 00 01 02 ..Q............. +| 3536: 00 01 02 00 01 02 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3552: 6e 09 1f 04 00 01 04 00 00 04 00 00 04 66 74 73 n............fts +| 3568: 34 09 0a 03 00 01 03 00 01 03 00 03 01 35 09 0d 4............5.. +| 3584: 03 00 01 03 00 01 03 00 00 03 67 63 63 09 01 03 ..........gcc... +| 3600: 00 01 03 00 01 03 00 01 06 65 6f 70 73 6c 79 09 .........eopsly. +| 3616: 10 03 00 01 03 00 01 03 00 00 05 6a 73 6f 6e 31 ...........json1 +| 3632: 09 13 03 00 01 03 00 01 03 00 00 04 6c 6f 61 64 ............load +| 3648: 09 1f 03 00 01 03 00 01 03 00 00 03 6d 61 78 09 ............max. +| 3664: 1c 02 00 01 02 00 01 02 00 01 05 65 6d 6f 72 79 ...........emory +| 3680: 09 1c 03 00 01 03 00 01 03 00 03 04 73 79 73 35 ............sys5 +| 3696: 09 16 03 00 01 03 00 01 03 00 00 06 6e 6f 63 61 ............noca +| 3712: 73 65 3c 02 01 02 02 00 03 01 12 02 00 03 01 02 se<............. +| 3728: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3744: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3760: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 00 ................ +| 3776: 04 6f 6d 69 74 09 1f 02 00 01 02 00 01 02 00 00 .omit........... +| 3792: 05 72 74 72 65 65 09 19 03 00 01 03 00 01 03 00 .rtree.......... +| 3808: 03 02 69 6d 3c 01 01 02 02 00 03 01 02 02 00 03 ..im<........... +| 3824: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 ................ +| 3840: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 ................ +| 3856: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3872: 00 00 0a 74 68 72 65 61 64 73 61 66 65 09 22 02 ...threadsafe... +| 3888: 00 01 02 00 01 02 00 00 04 76 74 61 62 09 07 04 .........vtab... +| 3904: 00 01 04 00 01 03 ff ff 01 78 b4 01 01 01 01 02 .........x...... +| 3920: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 3936: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 3952: 01 01 02 00 01 01 01 07 30 01 01 01 02 00 01 01 ........0....... +| 3968: 01 02 00 11 01 01 02 00 01 01 01 02 00 11 01 01 ................ +| 3984: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4000: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 4016: 01 01 01 01 ff 01 01 01 02 00 01 01 01 02 00 01 ................ +| 4032: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 4048: 01 02 00 01 01 09 c2 00 01 01 01 02 00 01 01 01 ................ +| 4064: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4080: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| page 6 offset 20480 +| 0: 0a 00 00 00 02 0f f5 00 0f fb 0f f5 00 00 00 00 ................ +| 4080: 00 00 00 00 00 05 04 08 09 01 02 04 04 08 08 09 ................ +| page 7 offset 24576 +| 0: 0d 00 00 00 05 0f b8 00 0e f4 0f e9 10 d6 0f c7 ................ +| 4016: 00 00 00 00 00 00 00 00 0d 05 02 23 61 75 74 6f ...........#auto +| 4032: 6d 65 72 67 65 3d 35 0d 04 02 23 6d 65 72 67 65 merge=5...#merge +| 4048: 3d 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 =1.............. +| end crash-369d042958c29b.db +}]} {} + +do_catchsql_test 24.1 { + PRAGMA writable_schema = 1; + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT '4hE'+x FROM c WHERE x<72) + INSERT INTO t1(a) SELECT randomblob(2829) FROM c; +} {1 {database disk image is malformed}} + +do_catchsql_test 24.2 { + UPDATE t1 SET b=quote((true) ) WHERE t1 MATCH 'h'; +} {0 {}} + +do_catchsql_test 24.3 { + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT 3+x FROM c WHERE x<72) + INSERT INTO t1(a) SELECT randomblob(2829) FROM c; +} {1 {database disk image is malformed}} + +do_catchsql_test 24.4 { + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT null<.$.. +| 2880: 00 00 00 00 00 00 00 00 81 3f 25 06 00 72 7f 00 .........?%..r.. +| 2896: 00 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e .COMPILER=gcc-5. +| 2912: 34 2e 30 20 32 30 31 36 30 36 30 39 20 44 55 42 4.0 20160609 DUB +| 2928: 55 47 20 45 4e 41 e4 7c 45 20 44 42 53 54 41 54 UG ENA.|E DBSTAT +| 2944: e4 46 54 41 42 20 45 4e 41 42 4c 45 20 46 54 53 .FTAB ENABLE FTS +| 2960: 34 20 45 4e 41 42 4c 45 20 46 54 53 35 20 45 4e 4 ENABLE FTS5 EN +| 2976: 41 42 4c 45 20 47 45 4f 50 4f 4c 59 20 45 4e 41 ABLE GEOPOLY ENA +| 2992: 42 4c 45 20 4a 53 4f 4e 31 20 45 4e 41 42 4c 45 BLE JSON1 ENABLE +| 3008: 20 4d 45 4d 53 59 53 35 20 45 4e 41 42 4c 45 20 MEMSYS5 ENABLE +| 3024: 42 54 52 45 45 20 4d 41 58 20 4d 45 4d 4f 52 59 BTREE MAX MEMORY +| 3040: 3d 35 30 30 30 30 30 30 30 20 4f 4c 49 54 20 4c =50000000 OLIT L +| 3056: 4f 41 43 20 45 58 54 45 4e 53 49 4f 4e 21 54 48 OAC EXTENSION!TH +| 3072: 52 45 41 44 53 41 46 45 3d 30 18 24 05 00 25 0f READSAFE=0.$..%. +| 3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49 .THREADSAFE=0XBI +| 3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41 NARY.#..%..THREA +| 3120: 44 53 41 4b 75 3d 30 58 4d 4f 43 41 53 45 17 22 DSAKu=0XMOCASE.. +| 3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 46 3d ..%..THREADSAFF= +| 3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d 0XRTRIM.!..3..OM +| 3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 52 49 4f IT LOAD EXTENRIO +| 3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f NXBINARY. ..3..O +| 3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 MIT LOAD EXTENSI +| 3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17 ONXNOCASE....3.. +| 3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 OMIT LOAD EXTENS +| 3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f 19 IONXRTRIM....3.. +| 3264: 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 30 MAX MEMORY=50000 +| 3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f 000XBINARY....3. +| 3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 .MAX MEMORY=5000 +| 3312: 30 30 30 30 58 4e 4f 43 41 53 45 1e 1c 05 00 33 0000XNOCASE....3 +| 3328: 0f 17 4d 42 b8 20 4d 45 4d 4f 52 59 3d 35 30 30 ..MB. MEMORY=500 +| 3344: 30 30 30 30 30 58 52 54 52 49 4d 18 1b 05 00 25 00000XRTRIM....% +| 3360: 0f 19 45 4e 41 42 4c 45 20 52 54 52 45 45 58 42 ..ENABLE RTREEXB +| 3376: 49 4e 41 52 59 18 1a 05 0d a5 0f 19 45 4e 41 42 INARY.......ENAB +| 3392: 4c 45 20 52 54 52 45 45 58 4e 4f 43 41 53 45 17 LE RTREEXNOCASE. +| 3408: 19 1c 00 25 0f 17 45 4e 41 42 4c 45 20 52 54 52 ...%..ENABLE RTR +| 3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45 EEXRTRIM....)..E +| 3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 58 42 49 NABLE MEMSYS5XBI +| 3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4e 41 42 4c NARY....)..ENABL +| 3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 53 45 E MEMSYS5XNOCASE +| 3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 4d 45 ....)..ENABLE ME +| 3504: 4d 53 59 53 35 58 52 54 52 49 4d 18 14 05 01 25 MSYS5XRTRIM....% +| 3520: 0f 19 45 4e 12 42 4c 45 20 4a 53 4f 4e 31 58 42 ..EN.BLE JSON1XB +| 3536: 49 4e 41 52 59 18 14 05 00 25 09 d9 45 4e 41 42 INARY....%..ENAB +| 3552: 4c 45 20 4a 53 4f 3e 31 58 4e 4f 43 41 53 45 17 LE JSO>1XNOCASE. +| 3568: 13 05 00 25 0f 17 45 4e 40 42 4c 45 20 4a 53 4f ...%..EN@BLE JSO +| 3584: 4e 31 58 52 54 52 49 4d 1a 12 05 82 29 0f 19 45 N1XRTRIM....)..E +| 3600: 4e 41 42 4c 45 20 47 45 4f 50 4f 4c 59 58 42 49 NABLE GEOPOLYXBI +| 3616: 4e 41 52 59 1a 11 05 c9 29 e8 19 46 4e 41 42 4c NARY....)..FNABL +| 3632: 48 c0 47 45 4f 50 4f 4c 59 58 4e 74 43 41 53 45 H.GEOPOLYXNtCASE +| 3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 45 ....)..ENABLE GE +| 3664: 4f 50 4f 4c 59 58 52 54 52 49 4d 17 0f 05 00 23 OPOLYXRTRIM....# +| 3680: 0f 19 45 4e 41 42 4c 45 30 46 54 53 35 58 42 49 ..ENABLE0FTS5XBI +| 3696: 4e 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 4c NARY....#..ENABL +| 3712: 45 20 46 54 53 35 58 4e 4f 43 41 53 45 16 0e 05 E FTS5XNOCASE... +| 3728: 00 23 0f 17 45 4e 41 42 4c 45 20 46 54 53 35 58 .#..ENABLE FTS5X +| 3744: 52 54 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42 RTRIM....#..ENAB +| 3760: 4c 45 20 46 54 53 34 58 42 49 4e 41 52 59 17 0b LE FTS4XBINARY.. +| 3776: 05 00 23 0f 19 45 4e 41 42 4c 45 20 46 54 53 34 ..#..ENABLE FTS4 +| 3792: 58 4e 4f 43 41 53 45 16 0a 05 00 23 0f 17 45 4e XNOCASE....#..EN +| 3808: 41 42 4c 45 20 46 54 53 34 58 52 54 52 49 4d 1e ABLE FTS4XRTRIM. +| 3824: 09 05 00 31 0f 19 45 4e 42 42 4c 45 20 44 42 53 ...1..ENBBLE DBS +| 3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 52 59 1e TAT VTABXBINARY. +| 3856: 08 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3872: 54 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d TAT VTABXNOCASE. +| 3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3904: 54 41 54 20 56 54 41 42 58 52 54 52 4a 4d 11 06 TAT VTABXRTRJM.. +| 3920: 05 f0 17 0f 19 44 45 42 55 47 58 42 49 4e 41 52 .....DEBUGXBINAR +| 3936: 59 11 05 05 00 17 0e 19 44 45 42 55 47 58 4e 4f Y.......DEBUGXNO +| 3952: 43 41 53 45 10 04 05 00 17 0f 16 44 45 42 55 47 CASE.......DEBUG +| 3968: 58 52 54 52 49 4d 27 03 05 00 43 0f 19 43 4f 4d XRTRIM'...C..COM +| 3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20 PILER=gcc-5.4.0 +| 4000: 32 30 31 36 30 36 30 39 58 42 49 4e 41 52 59 27 20160609XBINARY' +| 4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67 ...C..COMPILER=g +| 4032: 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36 30 cc-5.4.0 2016060 +| 4048: 39 58 4e 4f 43 41 53 45 26 01 06 00 43 0f 17 43 9XNOCASE&...C..C +| 4064: 4f 4d 50 49 4b 45 52 3d 67 63 63 2d 35 2e 34 2e OMPIKER=gcc-5.4. +| 4080: 30 20 32 30 31 36 30 36 40 39 58 29 54 52 49 4d 0 201606@9X)TRIM +| page 4 offset 12288 +| 0: 0d 00 10 00 00 10 00 00 00 00 00 00 00 01 00 00 ................ +| page 5 offset 16384 +| 0: 0d 00 00 00 02 0b a0 00 0c ad 0b a0 00 00 00 00 ................ +| 2976: 82 0a 02 08 08 09 08 08 17 84 06 30 20 32 35 33 ...........0 253 +| 2992: 00 01 30 04 25 06 1b 00 00 08 32 30 31 36 30 36 ..0.%.....201606 +| 3008: 30 39 03 25 07 00 00 01 34 03 25 05 00 00 01 35 09.%....4.%....5 +| 3024: 03 25 04 00 01 07 30 30 30 30 30 30 30 03 25 1a .%....0000000.%. +| 3040: 00 00 08 63 6f 6d 70 69 6c 65 72 03 25 02 00 00 ...compiler.%... +| 3056: 06 64 62 73 74 61 74 03 25 0a 00 01 04 65 62 75 .dbstat.%....ebu +| 3072: 67 03 25 08 00 00 06 65 6e 61 62 6c 65 09 25 09 g.%....enable.%. +| 3088: 05 04 04 04 04 04 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3104: 6e 03 25 1d 00 00 04 66 74 73 34 03 25 0d 00 03 n.%....fts4.%... +| 3120: 01 35 03 25 0f 00 00 03 67 63 63 03 25 03 00 01 .5.%....gcc.%... +| 3136: 06 65 6f 70 6f 6c 79 03 25 11 00 00 05 6a 73 6f .eopoly.%....jso +| 3152: 6e 31 03 25 13 00 00 04 6c 6f 61 64 03 25 1c 00 n1.%....load.%.. +| 3168: 00 03 6d 61 78 03 25 18 00 01 05 65 6e 6f 72 79 ..max.%....enory +| 3184: 03 25 19 00 03 04 ce 79 73 4d 03 25 15 00 00 04 .%.....ysM.%.... +| 3200: 6f 6d 69 74 03 25 1b 00 00 05 72 74 72 65 65 03 omit.%....rtree. +| 3216: 25 17 00 00 0a 74 68 72 65 61 64 73 61 66 65 03 %....threadsafe. +| 3232: 25 0e 00 00 04 76 74 61 62 03 25 0b 00 86 50 01 %....vtab.%...P. +| 3248: 08 08 08 08 08 17 8d 12 30 20 38 33 35 00 01 30 ........0 835..0 +| 3264: 12 01 06 00 01 06 00 01 06 00 1f 03 00 01 03 09 ................ +| 3280: 51 03 00 00 08 32 30 31 36 30 36 30 39 09 01 07 Q....20160609... +| 3296: 00 01 07 00 01 07 00 00 01 34 09 01 05 00 01 05 .........4...... +| 3312: 00 01 05 00 00 01 35 09 01 04 00 01 04 00 01 04 ......5......... +| 3328: 00 01 07 30 30 30 30 30 30 30 09 1c 04 00 01 04 ...0000000...... +| 3344: 00 01 04 00 00 06 62 69 6e 61 72 79 3c 03 01 02 ......binary<... +| 3360: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3376: 00 03 01 02 02 00 02 f1 02 02 00 03 01 02 02 00 ................ +| 3392: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 ................ +| 3408: 01 02 02 00 03 01 02 02 00 00 08 63 6f 6d 70 69 ...........compi +| 3424: 6c 65 72 09 01 02 00 01 02 00 01 02 00 00 06 67 ler............g +| 3440: d2 73 74 61 74 09 07 03 00 01 03 00 01 03 00 01 .stat........... +| 3456: 04 65 62 75 67 09 04 02 00 01 02 00 01 02 00 00 .ebug........... +| 3472: 06 65 6e 6f 82 6c 65 3f 07 02 00 01 02 00 01 02 .eno.le?........ +| 3488: b0 01 02 00 01 02 00 11 02 00 01 02 00 01 02 00 ................ +| 3504: 01 02 00 01 02 00 01 02 00 01 a6 00 01 02 00 01 ................ +| 3520: 02 05 51 02 00 01 02 00 01 02 00 01 02 00 01 02 ..Q............. +| 3536: 00 01 02 00 01 02 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3552: 6e 09 1f 04 00 01 04 00 00 04 00 00 04 66 74 73 n............fts +| 3568: 34 09 0a 03 00 01 03 00 01 03 00 03 01 35 09 0d 4............5.. +| 3584: 03 00 01 03 00 01 03 00 00 03 67 63 63 09 01 03 ..........gcc... +| 3600: 00 01 03 00 01 03 00 01 06 65 6f 70 73 6c 79 09 .........eopsly. +| 3616: 10 03 00 01 03 00 01 03 00 00 05 6a 73 6f 6e 31 ...........json1 +| 3632: 09 13 03 00 01 03 00 01 03 00 00 04 6c 6f 61 64 ............load +| 3648: 09 1f 03 00 01 03 00 01 03 00 00 03 6d 61 78 09 ............max. +| 3664: 1c 02 00 01 02 00 01 02 00 01 05 65 6d 6f 72 79 ...........emory +| 3680: 09 1c 03 00 01 03 00 01 03 00 03 04 73 79 73 35 ............sys5 +| 3696: 09 16 03 00 01 03 00 01 03 00 00 06 6e 6f 63 61 ............noca +| 3712: 73 65 3c 02 01 02 02 00 03 01 12 02 00 03 01 02 se<............. +| 3728: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3744: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3760: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 00 ................ +| 3776: 0e 9f 6d 69 74 09 1f 02 00 01 02 00 01 02 00 00 ..mit........... +| 3792: 05 72 74 72 65 65 09 19 03 00 01 03 00 01 03 00 .rtree.......... +| 3808: 03 02 69 6d 3c 01 01 02 02 00 03 01 02 02 00 03 ..im<........... +| 3824: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 ................ +| 3840: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 ................ +| 3856: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3872: 00 00 0a 74 68 72 65 61 64 73 61 66 65 09 22 02 ...threadsafe... +| 3888: 00 01 02 00 01 02 00 00 04 76 74 61 62 09 07 04 .........vtab... +| 3904: 00 01 04 00 01 04 00 00 01 78 b4 01 01 01 01 02 .........x...... +| 3920: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 3936: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 3952: 01 01 02 00 01 01 01 07 30 01 01 01 02 00 01 01 ........0....... +| 3968: 01 02 00 11 01 01 02 00 01 01 01 02 00 11 01 01 ................ +| 3984: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4000: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 4016: 01 01 01 01 ff 01 01 01 02 00 01 01 01 02 00 01 ................ +| 4032: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 4048: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 4064: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4080: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| page 6 offset 20480 +| 0: 0a 00 00 00 02 0f f5 00 0f fb 0f f5 00 00 00 00 ................ +| 4080: 00 00 00 00 00 05 04 08 09 01 02 04 04 08 08 09 ................ +| page 7 offset 24576 +| 0: 0d 00 00 00 05 0f b8 00 0e f4 0f e9 10 d6 0f c7 ................ +| 4016: 00 00 00 00 00 00 00 00 0d 05 02 23 61 75 74 6f ...........#auto +| 4032: 6d 65 72 67 65 3d 35 0d 04 02 23 6d 65 72 67 65 merge=5...#merge +| 4048: 3d 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 =1.............. +| end crash-dde9e76ed8ab2d.db +}]} {} + +do_catchsql_test 25.1 { + PRAGMA writable_schema = 1; + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x%1 FROM c WHERE x<599237) + INSERT INTO t1( a ) SELECT randomblob(3000) FROM t2 ; +} {0 {}} + +do_catchsql_test 25.2 { + UPDATE t1 SET b=quote((true) ) WHERE t1 MATCH 'h*'; +} {0 {}} + +do_catchsql_test 25.3 { + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x +x FROM c WHERE 721XNOCASE. +| 3568: 13 05 00 25 0f 17 45 4e 40 42 4c 45 20 4a 53 4f ...%..EN@BLE JSO +| 3584: 4e 31 58 52 54 52 49 4d 1a 12 05 82 29 0f 19 45 N1XRTRIM....)..E +| 3600: 4e 41 42 4c 45 20 47 45 4f 50 4f 4d 59 58 42 49 NABLE GEOPOMYXBI +| 3616: 4e 41 52 59 1a 11 05 c9 29 e8 19 46 4e 41 42 4c NARY....)..FNABL +| 3632: 48 c0 47 45 4f 50 4f 4c 59 58 4e 74 43 41 53 45 H.GEOPOLYXNtCASE +| 3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 45 ....)..ENABLE GE +| 3664: 4f 50 4f 4c 59 58 52 54 52 49 4d 17 0f 05 00 23 OPOLYXRTRIM....# +| 3680: 0f 19 45 4e 41 42 4c 45 30 46 54 53 35 58 42 49 ..ENABLE0FTS5XBI +| 3696: 4e 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 4c NARY....#..ENABL +| 3712: 45 20 46 54 53 35 58 4e 4f 4a e1 53 45 16 0e 05 E FTS5XNOJ.SE... +| 3728: 00 23 0f 17 45 4e 41 42 4c 45 20 46 54 53 35 58 .#..ENABLE FTS5X +| 3744: 52 54 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42 RTRIM....#..ENAB +| 3760: 4c 45 20 46 54 53 34 58 42 49 4e 41 52 59 17 0b LE FTS4XBINARY.. +| 3776: 05 00 23 0f 19 45 4e 41 42 4c 45 20 46 54 53 34 ..#..ENABLE FTS4 +| 3792: 58 4e 4f 43 41 53 45 16 0a 05 00 23 0f 17 55 4e XNOCASE....#..UN +| 3808: 41 42 4c 45 20 46 54 53 34 58 52 54 52 49 4d 1e ABLE FTS4XRTRIM. +| 3824: 09 05 00 31 0f 19 45 4e 42 42 4c 45 20 44 42 53 ...1..ENBBLE DBS +| 3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 52 59 1e TAT VTABXBINARY. +| 3856: 08 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3872: 54 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d TAT VTABXNOCASE. +| 3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3904: 54 41 54 20 56 54 41 42 58 52 54 52 4a 4d 11 06 TAT VTABXRTRJM.. +| 3920: 05 f0 17 0f 29 44 45 42 55 47 58 42 49 4e 41 52 ....)DEBUGXBINAR +| 3936: 59 11 05 05 00 17 0e 19 44 45 42 55 47 58 4e 4f Y.......DEBUGXNO +| 3952: 43 41 53 45 10 04 05 00 17 0f 16 44 45 42 55 47 CASE.......DEBUG +| 3968: 58 52 54 52 49 4d 27 03 05 00 43 0f 19 43 4f 4d XRTRIM'...C..COM +| 3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20 PILER=gcc-5.4.0 +| 4000: 32 30 31 36 30 36 30 39 58 42 49 4e 41 52 59 27 20160609XBINARY' +| 4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67 ...C..COMPILER=g +| 4032: 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36 30 cc-5.4.0 2016060 +| 4048: 39 58 4e 4f 43 41 53 45 26 01 06 00 43 0f 17 43 9XNOCASE&...C..C +| 4064: 4f 4d 50 49 4b 45 52 3d 67 63 63 2d 35 2e 34 2e OMPIKER=gcc-5.4. +| 4080: 30 20 32 30 31 36 30 36 40 39 58 29 54 52 49 4d 0 201606@9X)TRIM +| page 4 offset 12288 +| 0: 0d 00 10 00 00 10 00 00 00 00 00 00 00 00 00 00 ................ +| 16: 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| page 5 offset 16384 +| 0: 0d 00 00 00 02 0b a0 00 0c ad 0b a0 00 00 00 00 ................ +| 2976: 82 0a 02 08 08 09 08 08 17 84 06 30 20 32 35 33 ...........0 253 +| 2992: 00 01 30 04 25 06 1b 00 00 08 32 30 31 36 30 36 ..0.%.....201606 +| 3008: 30 39 03 25 07 00 00 01 34 03 25 05 00 00 01 35 09.%....4.%....5 +| 3024: 03 25 04 00 01 07 30 30 30 30 30 30 30 03 25 1a .%....0000000.%. +| 3040: 00 00 08 63 6f 6d 70 69 6c 65 72 03 25 02 00 00 ...compiler.%... +| 3056: 06 64 62 73 74 61 74 03 25 0a 00 01 04 65 62 75 .dbstat.%....ebu +| 3072: 67 03 25 08 00 00 06 65 6e 61 62 7c 65 09 25 09 g.%....enab|e.%. +| 3088: 05 04 04 04 04 04 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3104: 6e 03 25 1d 00 00 04 66 74 73 34 03 25 0d 00 03 n.%....fts4.%... +| 3120: 01 35 03 25 0f 00 00 03 67 63 63 03 25 03 00 01 .5.%....gcc.%... +| 3136: 06 65 6f 70 6f 6c 79 03 25 11 00 00 05 6a 73 6f .eopoly.%....jso +| 3152: 6e 31 03 25 13 00 00 04 6c 6f 61 64 03 25 1c 00 n1.%....load.%.. +| 3168: 00 03 6d 61 78 03 25 18 00 01 05 65 6e 6f 72 79 ..max.%....enory +| 3184: 03 25 19 00 03 04 ce 79 73 4d 03 25 15 00 00 04 .%.....ysM.%.... +| 3200: 6f 6d 69 74 03 25 1b 00 00 05 72 74 72 65 65 03 omit.%....rtree. +| 3216: 25 17 00 00 0a 74 68 72 65 61 64 73 61 66 65 03 %....threadsafe. +| 3232: 25 0e 00 00 04 76 74 61 62 03 25 0b 00 86 50 01 %....vtab.%...P. +| 3248: 08 08 08 08 08 17 8d 12 30 20 38 33 35 00 01 30 ........0 835..0 +| 3264: 12 01 06 00 01 06 00 01 06 00 1f 03 00 01 03 00 ................ +| 3280: 01 03 00 00 08 32 30 31 36 30 36 30 39 09 01 07 .....20160609... +| 3296: 00 01 07 00 01 07 00 00 01 34 09 01 05 00 01 05 .........4...... +| 3312: 00 01 05 00 00 01 35 09 01 04 00 01 04 00 01 04 ......5......... +| 3328: 00 01 07 30 30 30 30 30 30 30 09 1c 04 00 01 04 ...0000000...... +| 3344: 00 01 04 00 00 06 62 69 6e 61 72 79 3c 03 01 02 ......binary<... +| 3360: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3376: 00 03 01 02 02 00 02 f1 02 02 00 03 01 02 02 00 ................ +| 3392: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 ................ +| 3408: 01 01 f2 00 03 01 02 02 00 00 08 63 6f 6d 70 69 ...........compi +| 3424: 6c 65 72 09 01 02 00 01 02 00 01 02 00 00 06 67 ler............g +| 3440: d2 73 74 61 74 09 07 03 00 01 03 00 01 03 00 01 .stat........... +| 3456: 04 65 62 75 67 09 04 02 00 01 02 00 01 02 00 00 .ebug........... +| 3472: 06 65 6e 6f 82 6c 65 3f 07 02 00 01 02 00 01 02 .eno.le?........ +| 3488: b0 01 02 00 01 02 00 11 0a f0 01 02 00 01 02 00 ................ +| 3504: 01 02 00 01 02 00 01 02 00 01 a6 00 01 02 00 02 ................ +| 3520: 02 05 51 02 00 01 02 00 01 02 00 01 02 00 01 02 ..Q............. +| 3536: 00 01 02 00 01 02 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3552: 6e 09 1f 04 00 01 04 00 00 04 00 00 04 66 74 73 n............fts +| 3568: 34 09 0a 03 00 01 03 00 01 03 00 03 01 35 09 0d 4............5.. +| 3584: 03 00 01 03 00 01 03 00 00 03 67 63 63 09 01 03 ..........gcc... +| 3600: 00 01 03 00 01 03 00 01 06 65 6f 70 73 6c 79 09 .........eopsly. +| 3616: 10 03 00 01 03 00 01 03 00 00 05 6a 73 6f 6e 31 ...........json1 +| 3632: 09 13 03 00 01 03 00 01 03 00 00 04 6c 6f 61 64 ............load +| 3648: 09 1f 03 00 01 03 00 01 03 00 00 03 6d 61 78 09 ............max. +| 3664: 1c 02 00 01 02 00 01 02 00 01 05 65 6d 6f 72 79 ...........emory +| 3680: 09 1c 03 00 01 03 00 01 03 00 03 04 73 79 73 35 ............sys5 +| 3696: 09 16 03 00 01 03 00 01 03 00 00 06 6e 6f 63 61 ............noca +| 3712: 73 65 3c 02 01 02 02 00 03 01 12 02 00 03 01 02 se<............. +| 3728: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3744: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3760: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 00 ................ +| 3776: 04 6f 6d 69 74 09 1f 02 00 01 02 00 01 02 00 00 .omit........... +| 3792: 05 72 74 72 65 65 09 19 03 00 01 03 00 01 03 00 .rtree.......... +| 3808: 03 02 69 6d 3c 01 01 02 02 00 03 01 02 02 00 03 ..im<........... +| 3824: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 ................ +| 3840: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 ................ +| 3856: 02 00 03 01 02 02 01 e3 01 02 02 00 03 01 02 02 ................ +| 3872: 00 00 0a 74 68 72 65 61 64 73 61 66 65 09 22 02 ...threadsafe... +| 3888: 00 01 02 00 01 02 00 00 04 76 74 61 62 09 07 04 .........vtab... +| 3904: 00 01 04 00 01 04 00 00 01 78 b4 01 01 01 01 02 .........x...... +| 3920: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 3936: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 3952: 01 01 01 f0 01 01 01 07 30 01 01 01 02 00 01 01 ........0....... +| 3968: 01 02 00 ea 01 01 02 00 01 01 01 02 00 11 01 01 ................ +| 3984: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4000: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 4016: 01 01 01 01 ff 01 01 01 02 00 01 01 01 02 00 01 ................ +| 4032: 01 01 02 00 01 11 01 02 00 01 01 01 02 00 01 01 ................ +| 4048: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 4064: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4080: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| page 6 offset 20480 +| 0: 0a 00 00 00 02 0f f5 00 0f fb 0f f5 01 00 00 00 ................ +| 4080: 00 00 00 00 00 05 04 08 09 01 02 04 04 08 08 09 ................ +| page 7 offset 24576 +| 0: 0d 00 00 00 05 0f b8 00 0e f4 0f e9 10 d6 0f c7 ................ +| 4016: 00 00 00 00 00 00 00 00 0f 85 02 23 61 75 74 6f ...........#auto +| 4032: 6d 65 72 67 65 3d 35 0d 04 02 23 6d 65 72 67 65 merge=5...#merge +| 4048: 3d 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 =1.............. +| end crash-23ddd777a03bfd.db +}]} {} + +do_catchsql_test 27.2 { + PRAGMA writable_schema = 1; + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x GLOB 2.16770 FROM x) + INSERT INTO t1(a) SELECT randomblob(3000) FROM t2 ; +} {1 {database disk image is malformed}} +do_catchsql_test 27.3 { + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT 3+x FROM c WHERE x<2.653) + INSERT INTO t1(a) SELECT randomblob(-current_time) FROM c; +} {1 {database disk image is malformed}} +do_catchsql_test 27.4 { + UPDATE t1 SET b=quote((true) ) WHERE t1 MATCH 'h*h*'; +} {0 {}} +do_catchsql_test 27.5 { + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT 3+x FROM c WHERE x<2.653) + INSERT INTO t1(a) SELECT randomblob(-current_time) FROM c; +} {1 {database disk image is malformed}} +do_catchsql_test 27.5 { + INSERT INTO t1(t1) SELECT x FROM t2; +} {1 {database disk image is malformed}} +do_catchsql_test 27.6 { + INSERT INTO t1(t1) SELECT x FROM t2; +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +reset_db +do_test 28.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +.open --hexdb +| size 28672 pagesize 4096 filename crash-159ac1ca51ed55.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 00 .....@ ........ +| 96: 00 00 00 00 0d 0e b1 00 06 0d a4 00 0f 8d 0f 21 ...............! +| 112: 0e b9 0d c8 0e 7e 0d a4 00 00 00 00 00 00 00 00 .....~.......... +| 3488: 00 00 00 00 22 07 06 17 11 11 01 31 74 61 62 6c ...........1tabl +| 3504: 65 74 32 74 32 07 43 52 45 41 54 45 20 54 41 42 et2t2.CREATE TAB +| 3520: 4c 45 20 74 32 28 78 29 81 33 05 07 17 1f 1f 01 LE t2(x).3...... +| 3536: 82 35 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72 .5tablet1_segdir +| 3552: 74 31 5f 73 65 67 64 69 72 05 43 52 45 41 54 45 t1_segdir.CREATE +| 3568: 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69 TABLE 't1_segdi +| 3584: 72 27 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52 r'(level INTEGER +| 3600: 2c 69 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61 ,idx INTEGER,sta +| 3616: 72 74 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52 rt_block INTEGER +| 3632: 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 ,leaves_end_bloc +| 3648: 6b 20 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c k INTEGER,end_bl +| 3664: 6f 63 6b 20 49 4e 54 45 47 45 52 2c 72 6f 6f 74 ock INTEGER,root +| 3680: 20 42 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45 BLOB,PRIMARY KE +| 3696: 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 06 Y(level, idx))1. +| 3712: 06 17 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74 ..E...indexsqlit +| 3728: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73 e_autoindex_t1_s +| 3744: 65 67 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72 egdir_1t1_segdir +| 3760: 06 0f c7 00 08 00 10 00 00 66 04 07 17 23 23 01 .........f...##. +| 3776: 81 13 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e ..tablet1_segmen +| 3792: 64 73 74 31 5f 73 65 67 6d 65 6e 74 73 04 43 52 dst1_segments.CR +| 3808: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 EATE TABLE 't1_s +| 3824: 65 67 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64 egments'(blockid +| 3840: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 INTEGER PRIMARY +| 3856: 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 KEY, block BLOB +| 3872: 29 6a 03 07 17 21 21 01 81 1f 74 61 62 6c 65 74 )j...!!...tablet +| 3888: 31 4f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 1Ocontentt1_cont +| 3904: 65 6e 74 03 43 52 45 41 54 45 20 54 41 42 4c 45 ent.CREATE TABLE +| 3920: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f 't1_content'(do +| 3936: 63 69 64 20 49 4e 54 45 43 a5 52 20 50 52 39 4d cid INTEC.R PR9M +| 3952: 41 52 59 20 4b 45 59 2c 20 27 63 30 61 27 2c 20 ARY KEY, 'c0a', +| 3968: 27 63 31 62 27 2c 20 27 63 32 63 27 29 38 02 06 'c1b', 'c2c')8.. +| 3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52 ...._tablet1t1CR +| 4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB +| 4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33 LE t1 USING fts3 +| 4032: 28 61 2c 62 2c 63 29 00 00 00 00 00 00 00 00 00 (a,b,c)......... +| page 3 offset 8192 +| 0: 0d 00 00 00 26 0b 48 00 00 00 00 00 00 00 00 00 ....&.H......... +| 2880: 00 00 00 00 00 00 00 00 81 3f 25 06 00 72 7f 00 .........?%..r.. +| 2896: 00 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e .COMPILER=gcc-5. +| 2912: 34 2e 30 20 32 30 31 36 30 36 30 39 20 44 55 42 4.0 20160609 DUB +| 2928: 55 47 20 45 4e 41 e4 7c 45 20 44 42 53 54 41 54 UG ENA.|E DBSTAT +| 2944: e4 46 54 41 42 20 45 4e 41 42 4c 45 20 46 54 53 .FTAB ENABLE FTS +| 2960: 34 20 45 4e 41 42 4c 45 20 46 54 53 35 20 45 4e 4 ENABLE FTS5 EN +| 2976: 41 42 1f 45 20 47 45 4f 50 4f 4c 59 20 45 4e 41 AB.E GEOPOLY ENA +| 2992: 42 4c 45 20 4a 53 4f 4e 31 20 45 4e 41 42 4c 45 BLE JSON1 ENABLE +| 3008: 20 4d 45 4d 53 59 53 35 20 45 4e 41 42 4c 45 20 MEMSYS5 ENABLE +| 3024: 42 54 52 45 45 20 4d 41 58 20 4d 45 4d 4f 52 59 BTREE MAX MEMORY +| 3040: 3d 35 30 30 30 30 30 30 30 20 4f 4c 49 54 20 4c =50000000 OLIT L +| 3056: 4f 41 43 20 45 58 54 45 4e 53 49 4f 4e 21 54 48 OAC EXTENSION!TH +| 3072: 52 45 41 44 53 41 46 45 3d 2f 18 24 05 00 25 0f READSAFE=/.$..%. +| 3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49 .THREADSAFE=0XBI +| 3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41 NARY.#..%..THREA +| 3120: 44 53 41 4b 75 3d 30 58 4d 4f 43 41 53 45 17 22 DSAKu=0XMOCASE.. +| 3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 46 3d ..%..THREADSAFF= +| 3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d 0XRTRIM.!..3..OM +| 3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 52 49 4f IT LOAD EXTENRIO +| 3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f NXBINARY. ..3..O +| 3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 MIT LOAD EXTENSI +| 3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17 ONXNOCASE....3.. +| 3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 OMIT LOAD EXTENS +| 3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f 19 IONXRTRIM....3.. +| 3264: 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 30 MAX MEMORY=50000 +| 3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f 000XBINARY....3. +| 3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 .MAX MEMORY=5000 +| 3312: 30 30 30 30 58 4e 4f 43 41 53 45 1e 1c 05 00 33 0000XNOCASE....3 +| 3328: 0f 17 4d 42 b8 20 4d 45 4d 4f 52 59 3d 35 30 30 ..MB. MEMORY=500 +| 3344: 30 30 30 30 30 58 52 54 52 4a 4d 18 1b 05 00 25 00000XRTRJM....% +| 3360: 0f 19 45 4e 41 42 4c 45 20 52 54 52 45 45 58 42 ..ENABLE RTREEXB +| 3376: 49 4e 41 52 59 18 1a 05 0d a5 0f 19 45 4e 41 42 INARY.......ENAB +| 3392: 4c 45 20 52 54 52 45 45 58 4e 4f 43 41 53 45 17 LE RTREEXNOCASE. +| 3408: 19 1c 00 25 0f 17 45 4e 41 42 4c 45 20 52 54 52 ...%..ENABLE RTR +| 3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45 EEXRTRIM....)..E +| 3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 58 42 49 NABLE MEMSYS5XBI +| 3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4e 41 42 4c NARY....)..ENABL +| 3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 53 45 E MEMSYS5XNOCASE +| 3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 4d 45 ....)..ENABLE ME +| 3504: 4d 53 59 53 35 58 52 54 52 49 4d 18 14 05 01 25 MSYS5XRTRIM....% +| 3520: 0f 19 45 4e 12 42 4c 45 20 4a 53 4f 4e 31 58 42 ..EN.BLE JSON1XB +| 3536: 49 4e 41 52 59 18 14 05 00 25 09 d9 45 4e 41 42 INARY....%..ENAB +| 3552: 4c 45 20 4a 53 4f 3e 31 58 4e 4f 43 41 53 45 17 LE JSO>1XNOCASE. +| 3568: 13 05 00 25 0f 17 44 4e 40 42 4c 45 20 4a 53 4f ...%..DN@BLE JSO +| 3584: 4e 31 58 52 54 52 49 4d 1a 12 05 82 29 0f 19 45 N1XRTRIM....)..E +| 3600: 4e 41 42 4c 45 20 47 45 4f 50 4f 4c 59 58 42 49 NABLE GEOPOLYXBI +| 3616: 4e 41 52 59 1a 11 05 c9 29 e8 19 46 4e 41 42 4c NARY....)..FNABL +| 3632: 48 c0 47 45 4f 50 4f 4c 59 58 4e 74 43 41 53 45 H.GEOPOLYXNtCASE +| 3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 45 ....)..ENABLE GE +| 3664: 4f 50 4f 4c 59 58 52 54 52 49 4d 17 0f 05 00 23 OPOLYXRTRIM....# +| 3680: 0f 19 45 4e 41 42 4c 45 30 46 54 53 35 58 42 49 ..ENABLE0FTS5XBI +| 3696: 4e 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 4c NARY....#..ENABL +| 3712: 45 20 46 54 53 35 58 4e 4f 43 41 53 45 16 0e 05 E FTS5XNOCASE... +| 3728: 00 23 0f 17 45 4e 41 42 4c 45 20 46 54 53 35 58 .#..ENABLE FTS5X +| 3744: 52 54 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42 RTRIM....#..ENAB +| 3760: 4c 45 20 46 54 53 34 58 42 49 4e 41 52 59 17 0b LE FTS4XBINARY.. +| 3776: 04 ff 23 0f 19 45 4e 41 42 4c 45 20 46 54 53 34 ..#..ENABLE FTS4 +| 3792: 58 4e 4f 43 41 53 45 16 0a 05 00 23 0f 17 45 4e XNOCASE....#..EN +| 3808: 41 42 4c 45 20 46 54 53 34 58 52 54 52 49 4d 1e ABLE FTS4XRTRIM. +| 3824: 09 05 00 31 0f 19 45 4e 42 42 4c 45 20 44 42 53 ...1..ENBBLE DBS +| 3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 52 59 1e TAT VTABXBINARY. +| 3856: 08 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3872: 54 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d TAT VTABXNOCASE. +| 3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3904: 54 41 54 20 56 54 41 42 58 52 54 52 4a 4d 11 06 TAT VTABXRTRJM.. +| 3920: 05 f0 17 0f 19 44 45 42 55 47 58 42 49 4e 41 52 .....DEBUGXBINAR +| 3936: 59 11 05 09 b0 17 0e 19 44 45 42 55 47 58 4e 4f Y.......DEBUGXNO +| 3952: 43 41 53 45 10 04 05 00 17 0f 16 44 45 42 55 47 CASE.......DEBUG +| 3968: 58 52 54 52 49 4d 27 03 05 00 43 0f 19 43 4f 4d XRTRIM'...C..COM +| 3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20 PILER=gcc-5.4.0 +| 4000: 32 30 31 36 30 36 30 39 58 42 49 4e 41 52 59 27 20160609XBINARY' +| 4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 45 52 4d 67 ...C..COMPILERMg +| 4032: 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36 30 cc-5.4.0 2016060 +| 4048: 39 58 4e 4f 43 41 53 45 26 01 06 00 43 0f 17 43 9XNOCASE&...C..C +| 4064: 4f 4d 50 49 4b 45 52 3d 67 63 63 2d 35 2e 34 2e OMPIKER=gcc-5.4. +| 4080: 30 20 32 30 31 36 30 36 40 39 58 29 54 52 49 4d 0 201606@9X)TRIM +| page 4 offset 12288 +| 0: 0d 00 10 00 00 10 00 00 00 00 00 00 00 00 00 00 ................ +| page 5 offset 16384 +| 0: 0d 00 00 00 02 0b a0 00 00 00 00 00 00 00 00 00 ................ +| 2976: 82 0a 02 08 08 09 08 08 17 84 06 30 20 32 35 33 ...........0 253 +| 2992: 00 01 30 04 25 06 1b 00 00 08 32 30 31 36 30 36 ..0.%.....201606 +| 3008: 30 39 03 25 07 00 00 01 34 03 25 05 00 00 01 35 09.%....4.%....5 +| 3024: 03 25 04 00 4d 07 30 30 30 30 30 30 30 03 25 1a .%..M.0000000.%. +| 3040: 00 00 08 63 6f 6d 70 69 6c 65 72 03 25 02 00 00 ...compiler.%... +| 3056: 06 64 62 73 74 61 74 03 25 0a 00 01 04 65 62 75 .dbstat.%....ebu +| 3072: 67 03 25 08 00 00 06 65 6e 61 62 6c 65 09 25 09 g.%....enable.%. +| 3088: 05 04 04 04 04 04 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3104: 6e 03 25 1d 00 00 04 66 74 73 34 03 25 0d 00 03 n.%....fts4.%... +| 3120: 01 35 03 25 0f 00 00 03 67 63 63 03 25 03 00 01 .5.%....gcc.%... +| 3136: 06 65 6f 70 6f 6c 79 03 25 10 ff ff f5 6a 73 6f .eopoly.%....jso +| 3152: 6e 31 03 25 13 00 00 04 6c 6f 61 64 03 25 1c 00 n1.%....load.%.. +| 3168: 00 03 6d 71 78 03 25 18 00 01 05 65 6e 6f 72 79 ..mqx.%....enory +| 3184: 03 25 19 00 03 04 ce 79 73 4d 03 25 15 00 00 04 .%.....ysM.%.... +| 3200: 6f 6d 69 74 03 25 1b 00 00 05 72 74 72 65 65 03 omit.%....rtree. +| 3216: 25 17 00 00 0a 7f 08 72 65 61 64 73 61 66 65 03 %......readsafe. +| 3232: 25 0e 00 00 04 76 75 61 62 03 25 0b 00 86 50 01 %....vuab.%...P. +| 3248: 08 08 08 08 08 17 8d 12 30 20 38 33 35 00 01 30 ........0 835..0 +| 3264: 12 01 06 00 01 06 00 01 06 00 1f 03 00 01 03 09 ................ +| 3280: 51 03 00 00 09 32 30 31 36 30 36 30 39 09 01 07 Q....20160609... +| 3296: 00 01 07 00 01 07 00 00 01 34 09 01 05 00 01 05 .........4...... +| 3312: 00 01 05 00 00 01 35 09 01 04 00 01 03 ff 01 04 ......5......... +| 3328: 00 01 07 30 30 30 30 30 30 30 09 1c 04 00 01 04 ...0000000...... +| 3344: 00 01 04 00 00 06 62 69 6e 61 72 79 3c 03 01 02 ......binary<... +| 3360: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3376: 00 03 01 02 02 00 02 f1 02 02 00 03 01 02 02 00 ................ +| 3392: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 ................ +| 3408: 01 02 02 00 03 01 02 02 00 00 08 63 6f 6d 70 69 ...........compi +| 3424: 6c 65 72 09 01 02 00 01 02 00 01 02 00 00 06 67 ler............g +| 3440: d2 73 74 61 74 09 07 03 00 01 03 00 01 03 00 01 .stat........... +| 3456: 04 65 62 75 67 09 04 02 00 01 02 00 01 02 00 00 .ebug........... +| 3472: 06 65 6e 6f 82 6c 65 3f 07 02 00 01 02 00 01 02 .eno.le?........ +| 3488: b0 01 02 00 00 f2 00 11 02 00 01 02 00 01 02 00 ................ +| 3504: 01 02 00 01 02 00 01 02 00 01 a6 00 01 02 00 01 ................ +| 3520: 02 05 51 02 00 01 02 00 01 02 00 01 02 00 01 02 ..Q............. +| 3536: 00 01 02 00 01 02 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3552: 6e 09 1f 04 00 01 04 00 00 04 00 00 04 66 74 73 n............fts +| 3568: 34 09 0a 03 00 01 03 00 01 03 00 03 01 35 09 0d 4............5.. +| 3584: 03 00 01 03 00 01 03 00 00 03 67 63 63 09 01 03 ..........gcc... +| 3600: 00 01 03 00 01 03 00 01 06 65 6f 70 73 6c 79 09 .........eopsly. +| 3616: 10 03 00 01 03 00 01 03 00 00 05 6a 73 6f 6e 31 ...........json1 +| 3632: 09 13 03 00 01 03 00 01 03 00 00 04 6c 6f 61 64 ............load +| 3648: 09 1f 03 00 01 03 00 01 03 00 00 03 6d 61 78 09 ............max. +| 3664: 1c 02 00 01 02 00 01 02 00 01 05 65 6d 6f 72 79 ...........emory +| 3680: 09 1c 03 00 01 03 00 01 03 00 03 04 73 79 73 35 ............sys5 +| 3696: 09 16 03 00 01 03 00 01 03 00 00 06 6e 6f 63 61 ............noca +| 3712: 73 65 3c 02 01 02 02 00 03 01 12 02 00 03 01 02 se<............. +| 3728: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3744: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3760: 0f 71 02 02 00 03 01 02 02 00 03 6f 02 02 00 00 .q.........o.... +| 3776: 04 6f 6d 69 74 09 1f 02 00 01 02 00 01 02 00 00 .omit........... +| 3792: 05 72 74 72 65 65 09 19 03 00 01 03 00 01 03 00 .rtree.......... +| 3808: 03 02 69 6d 3c 01 01 02 02 00 03 01 02 02 00 03 ..im<........... +| 3824: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 ................ +| 3840: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 ................ +| 3856: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3872: 00 00 0a 74 68 72 65 61 64 73 61 66 65 09 22 02 ...threadsafe... +| 3888: 00 01 02 00 01 02 00 00 04 76 74 61 62 09 07 04 .........vtab... +| 3904: 00 01 04 00 01 04 00 00 01 78 b4 01 01 01 01 02 .........x...... +| 3920: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 3936: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 3952: 01 01 02 00 01 01 01 07 30 01 01 01 02 00 01 01 ........0....... +| 3968: 01 02 00 11 01 01 02 00 01 01 01 02 00 11 01 01 ................ +| 3984: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4000: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 4016: 01 01 01 01 ff 01 01 01 02 00 01 01 01 02 00 01 ................ +| 4032: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 4048: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 4064: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4080: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| page 6 offset 20480 +| 0: 0a 00 00 00 02 0f f5 00 00 00 00 00 00 00 00 00 ................ +| 4080: 00 00 00 00 00 05 04 08 09 01 02 04 04 08 08 09 ................ +| page 7 offset 24576 +| 0: 0d 00 00 00 05 0f b8 00 0e f4 0f e9 10 d6 0f c7 ................ +| 4016: 00 00 00 00 00 00 00 00 0d 05 02 23 61 75 74 6f ...........#auto +| 4032: 6d 65 72 67 65 3d 35 0d 04 02 23 6d 65 72 67 65 merge=5...#merge +| 4048: 3d 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 =1.............. +| end crash-159ac1ca51ed55.db +}]} {} + +do_catchsql_test 28.1 { + PRAGMA writable_schema = 1; + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT 3+x FROM c WHERE x<72) + INSERT INTO t1(a) SELECT randomblob(2829) FROM c; +} {1 {database disk image is malformed}} + +do_catchsql_test 28.2 { + UPDATE t1 SET b=quote((true) ) WHERE t1 MATCH 'h'; +} {0 {}} + +do_catchsql_test 28.3 { + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT 3+x FROM c WHERE x<72) + INSERT INTO t1(a) SELECT randomblob(2829) FROM c; +} {1 {database disk image is malformed}} + +do_catchsql_test 28.4 { + WITH c(x) AS (VALUES(1) UNION ALL SELECT 3<.$.. +| 80: 0b 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .H.............. +| 2880: 00 00 00 00 00 00 00 00 81 3f 25 06 00 72 7f 00 .........?%..r.. +| 2896: 00 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e .COMPILER=gcc-5. +| 2912: 34 2e 30 20 32 30 31 36 30 36 30 39 21 44 45 42 4.0 20160609!DEB +| 2928: 55 47 20 45 4e 41 42 4c 45 20 44 42 53 54 41 54 UG ENABLE DBSTAT +| 2944: 20 56 54 41 42 20 45 4e 41 42 4c 46 20 46 54 53 VTAB ENABLF FTS +| 2960: 34 20 45 4e 41 42 4c 45 20 46 54 53 35 20 45 4e 4 ENABLE FTS5 EN +| 2976: 41 42 4c 45 20 47 45 4f 50 4f 4c 59 20 45 4e 41 ABLE GEOPOLY ENA +| 2992: 42 4c 55 20 4a 53 4f 4e 31 20 45 4e 41 42 4c 45 BLU JSON1 ENABLE +| 3008: 20 4d 45 4d 53 59 53 35 20 45 4e 41 42 4c 45 20 MEMSYS5 ENABLE +| 3024: 52 54 52 45 45 56 4d 41 58 20 4d 45 4d 4f 52 59 RTREEVMAX MEMORY +| 3040: 3d 35 30 30 30 30 30 30 30 20 4f 4d 49 54 20 4c =50000000 OMIT L +| 3056: 4f 42 43 20 45 58 54 45 4e 53 49 4f 4e 20 54 48 OBC EXTENSION TH +| 3072: 52 45 41 44 53 41 46 45 3d 40 18 24 05 00 25 0f READSAFE=@.$..%. +| 3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49 .THREADSAFE=0XBI +| 3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41 NARY.#..%..THREA +| 3120: 44 53 41 46 45 3d 31 58 4e 4f 43 41 53 45 17 22 DSAFE=1XNOCASE.. +| 3136: 05 00 25 0f 17 54 48 52 45 41 44 43 41 46 45 3d ..%..THREADCAFE= +| 3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d 0XRTRIM.!..3..OM +| 3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 4f IT LOAD EXTENSIO +| 3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f NXBINARY. ..3..O +| 3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 48 MIT LOAD EXTENSH +| 3216: cf 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17 .NXNOCASE....3.. +| 3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 OMIT LOAD EXTENS +| 3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f 19 IONXRTRIM....3.. +| 3264: 4d 41 58 20 4d 45 4d 4f 52 59 2d 35 30 30 30 30 MAX MEMORY-50000 +| 3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f 000XBINARY....3. +| 3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 .MAX MEMORY=5000 +| 3312: 30 30 30 30 58 4e 4f 43 41 53 45 1e 1c 05 00 33 0000XNOCASE....3 +| 3328: 0f 17 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 ..MAX MEMORY=500 +| 3344: 30 30 30 30 30 58 52 54 52 49 4d 18 1b 05 00 25 00000XRTRIM....% +| 3360: 0f 19 45 4e 41 42 4c 45 20 52 54 52 45 45 58 42 ..ENABLE RTREEXB +| 3376: 49 4e 41 52 49 18 1a 05 0d a5 0f 19 45 4e 41 42 INARI.......ENAB +| 3392: 4c 45 20 52 54 52 45 45 58 4e 4f be 31 53 45 17 LE RTREEXNO.1SE. +| 3408: 19 05 00 25 0f 17 45 4e 41 42 4c 45 20 52 54 51 ...%..ENABLE RTQ +| 3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45 EEXRTRIM....)..E +| 3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 58 42 49 NABLE MEMSYS5XBI +| 3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4e 41 42 4c NARY....)..ENABL +| 3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 53 45 E MEMSYS5XNOCASE +| 3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 4d 45 ....)..ENABLE ME +| 3504: 4d 53 59 53 37 f8 52 54 52 49 4d 18 14 05 00 25 MSYS7.RTRIM....% +| 3520: 0f 19 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 58 42 ..ENABLE JSON1XB +| 3536: 49 4e 41 52 59 18 14 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3552: 4c 45 20 4a 53 4f 3e 31 58 4e 4f 43 41 53 45 17 LE JSO>1XNOCASE. +| 3568: 13 05 00 25 0f 17 45 4e 41 42 4c 45 20 4a 53 4f ...%..ENABLE JSO +| 3584: 4e 31 58 52 54 52 49 4d 1a 12 05 00 29 0f 19 45 N1XRTRIM....)..E +| 3600: 4e 41 42 4c 45 20 47 45 4f 50 4f 4c 59 58 42 49 NABLE GEOPOLYXBI +| 3616: 4e 41 52 59 1a 11 05 00 29 0f 19 45 4e 41 42 4c NARY....)..ENABL +| 3632: 48 c0 47 45 4f 50 4f 4c 40 58 4e 4f 43 41 53 45 H.GEOPOL@XNOCASE +| 3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 45 ....)..ENABLE GE +| 3664: 4f 50 4f 4c 59 58 52 54 51 49 4d 17 0f 05 00 23 OPOLYXRTQIM....# +| 3680: 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 58 42 49 ..ENABLE FTS5XBI +| 3696: 4e 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 4c NARY....#..ENABL +| 3712: 45 20 46 54 53 35 58 4e 4f 43 41 53 45 16 0d 05 E FTS5XNOCASE... +| 3728: 00 23 0f 17 45 4e 41 42 4c 45 20 46 54 53 35 58 .#..ENABLE FTS5X +| 3744: 52 54 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42 RTRIM....#..ENAB +| 3760: 4c 45 20 46 54 53 34 58 42 49 4d 41 52 59 17 0b LE FTS4XBIMARY.. +| 3776: 05 00 23 0f 19 45 4e 31 42 4c 45 20 46 1a 53 34 ..#..EN1BLE F.S4 +| 3792: 58 4e 4f 43 41 53 45 16 0a 05 00 23 0f 17 45 4e XNOCASE....#..EN +| 3808: 41 42 4c 45 20 46 54 53 34 58 52 54 52 49 4d 1e ABLE FTS4XRTRIM. +| 3824: 09 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 52 59 1e TAT VTABXBINARY. +| 3856: 08 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3872: 54 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d TAT VTABXNOCASE. +| 3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3904: 54 96 54 20 56 54 41 42 58 52 54 52 49 4d 11 06 T.T VTABXRTRIM.. +| 3920: 05 00 17 0f 1e e4 45 42 55 47 58 42 49 4e 41 52 ......EBUGXBINAR +| 3936: 59 11 05 05 00 17 0e 19 44 45 42 55 47 58 4e 4f Y.......DEBUGXNO +| 3952: 43 41 53 45 10 04 05 00 17 0f 17 44 45 42 55 47 CASE.......DEBUG +| 3968: 58 52 54 52 49 4d 27 03 05 01 43 0f 19 43 4f 4d XRTRIM'...C..COM +| 3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20 PILER=gcc-5.4.0 +| 4000: 32 30 31 36 30 36 30 39 58 42 49 4e 41 52 59 27 20160609XBINARY' +| 4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67 ...C..COMPILER=g +| 4032: 63 63 2d 35 2e 34 2e 30 40 32 30 31 36 30 36 30 cc-5.4.0@2016060 +| 4048: 39 58 4e 4f 43 41 53 45 26 01 05 00 43 0f 17 43 9XNOCASE&...C..C +| 4064: 4f 4d 4f 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e OMOILER=gcc-5.4. +| 4080: 30 20 32 30 31 36 30 36 30 39 58 52 54 52 49 4d 0 20160609XRTRIM +| page 4 offset 12288 +| 0: 0d 00 00 01 00 10 00 00 00 00 00 00 00 00 00 00 ................ +| page 5 offset 16384 +| 0: 0d 00 00 00 02 0b a0 00 0c ad 0b a0 00 00 00 00 ................ +| 2976: 82 0a 02 08 08 09 08 08 17 84 06 30 20 32 35 33 ...........0 253 +| 2992: 00 01 30 04 25 06 1b 00 00 08 32 30 31 36 30 36 ..0.%.....201606 +| 3008: 30 39 03 25 07 00 00 01 34 03 25 05 00 00 01 35 09.%....4.%....5 +| 3024: 03 25 04 00 01 07 30 30 30 30 30 30 30 03 25 1a .%....0000000.%. +| 3040: 00 00 08 63 6f 6d 70 69 6c 65 72 03 25 02 00 00 ...compiler.%... +| 3056: 06 64 62 73 74 61 74 03 25 0a 00 01 04 65 62 75 .dbstat.%....ebu +| 3072: 67 03 25 08 00 00 06 65 6e 61 62 6c 65 09 25 09 g.%....enable.%. +| 3088: 05 04 04 04 04 04 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3104: 6e 03 25 1d 00 00 04 66 74 73 34 03 25 0d 00 03 n.%....fts4.%... +| 3120: 01 35 03 25 0f 00 00 03 67 63 63 03 25 03 00 01 .5.%....gcc.%... +| 3136: 06 65 6f 70 6f 6c 79 03 25 11 00 00 05 6a 73 6f .eopoly.%....jso +| 3152: 6e 31 03 25 13 00 00 04 6c 6f 61 64 03 25 1c 00 n1.%....load.%.. +| 3168: 00 03 6d 61 78 03 25 18 00 01 05 65 6d 6f 72 79 ..max.%....emory +| 3184: 03 25 19 00 03 04 73 79 73 4d 03 25 15 00 00 04 .%....sysM.%.... +| 3200: 6e 6d 69 74 03 25 1b 00 00 05 72 74 72 65 65 03 nmit.%....rtree. +| 3216: 25 17 00 00 0a 74 68 72 65 61 64 73 61 66 65 03 %....threadsafe. +| 3232: 25 0e 00 00 04 76 74 61 62 03 25 0b 00 86 50 01 %....vtab.%...P. +| 3248: 08 08 08 08 08 17 8d 12 30 20 38 33 35 00 01 30 ........0 835..0 +| 3264: 12 01 06 00 01 06 00 01 06 00 1f 03 00 01 03 00 ................ +| 3280: 01 03 00 00 08 32 30 31 36 30 36 30 39 09 01 bd .....20160609... +| 3296: 00 01 07 00 01 07 00 00 01 34 09 01 05 00 01 05 .........4...... +| 3312: 00 01 06 00 00 01 35 09 01 04 00 01 04 00 02 04 ......5......... +| 3328: 00 01 07 30 30 e6 30 30 30 30 09 1c 04 00 01 04 ...00.0000...... +| 3344: 00 01 04 00 00 06 62 69 6e 61 72 79 3c 03 01 02 ......binary<... +| 3360: 02 00 03 01 02 02 00 04 01 02 02 10 03 01 02 02 ................ +| 3376: 00 0f 71 02 12 00 03 01 02 02 00 03 01 65 02 00 ..q..........e.. +| 3392: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 ................ +| 3408: 01 0d a2 00 03 01 02 02 00 00 08 63 3b 6d 70 69 ...........c;mpi +| 3424: 6c 65 72 09 01 02 00 01 02 00 01 02 00 00 06 64 ler............d +| 3440: 62 73 74 61 74 09 07 03 00 01 03 00 01 03 00 01 bstat........... +| 3456: 04 65 62 75 67 09 04 02 00 01 02 00 01 02 00 00 .ebug........... +| 3472: 06 65 6e 61 62 6c 65 3f 07 02 00 01 02 00 01 02 .enable?........ +| 3488: 00 01 02 00 01 02 00 01 01 f0 01 02 00 01 02 00 ................ +| 3504: 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 ................ +| 3520: 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 ................ +| 3536: 00 01 02 00 01 02 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3552: 6e 09 1f 04 00 01 04 00 01 04 00 00 04 66 74 73 n............fts +| 3568: 34 09 0a 03 00 01 03 00 01 03 00 03 01 35 09 0d 4............5.. +| 3584: 03 00 01 03 00 01 03 00 00 03 67 63 63 09 01 03 ..........gcc... +| 3600: 00 01 03 00 01 03 00 01 06 65 6f 70 6f 6c 79 09 .........eopoly. +| 3616: 10 03 00 01 03 00 01 03 00 00 05 6a 73 6f 6e 31 ...........json1 +| 3632: 09 13 03 00 01 03 00 01 03 00 00 04 6c 6f 61 64 ............load +| 3648: 09 1f 03 00 01 03 00 01 03 00 00 03 6d 61 78 09 ............max. +| 3664: 1c 02 00 01 02 00 01 02 00 01 05 65 6d 6f 72 79 ...........emory +| 3680: 09 1c 03 00 01 03 00 01 03 00 03 04 73 79 73 35 ............sys5 +| 3696: 09 16 03 00 01 03 00 01 03 00 00 06 6e 6f 63 61 ............noca +| 3712: 73 65 3c 02 01 02 02 00 03 01 02 02 00 03 01 02 se<............. +| 3728: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3744: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 01 f0 ................ +| 3760: 03 01 02 02 05 93 01 02 02 00 03 01 02 02 00 00 ................ +| 3776: 04 6f 6d 69 74 09 1f 02 00 01 02 00 01 02 00 00 .omit........... +| 3792: 05 72 8a 72 65 65 09 19 03 00 01 03 00 11 03 00 .r.ree.......... +| 3808: 03 02 69 6d 3c 01 01 02 02 00 03 01 02 02 00 03 ..im<........... +| 3824: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 ................ +| 3840: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 ................ +| 3856: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3872: 00 00 0a 74 68 72 65 61 64 73 61 66 65 09 22 02 ...threadsafe... +| 3888: 00 01 02 00 01 02 00 00 04 76 75 61 62 09 07 04 .........vuab... +| 3904: 00 01 04 00 01 04 00 00 61 78 b4 01 01 01 01 02 ........ax...... +| 3920: 00 01 01 01 02 00 00 f1 01 02 00 01 01 01 02 00 ................ +| 3936: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 3952: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 3968: 01 02 00 01 01 01 01 ff 01 01 01 02 00 01 01 01 ................ +| 3984: 02 00 01 01 01 02 00 01 01 01 02 09 01 01 01 02 ................ +| 4000: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 4016: 01 01 01 02 00 01 02 01 02 00 01 01 01 02 00 01 ................ +| 4032: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 4048: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 4064: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4080: 00 01 01 11 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| page 6 offset 20480 +| 0: 0a 00 00 00 02 0f f5 00 0f fb 1f f5 00 00 00 00 ................ +| 4080: 00 00 00 00 00 05 04 08 09 01 02 04 04 08 08 09 ................ +| page 7 offset 24576 +| 0: 0d 00 00 00 05 0f b8 00 0f f4 0f e9 10 d6 0f c7 ................ +| 4016: 00 00 00 00 00 00 00 00 0d 05 02 23 61 75 74 6f ...........#auto +| 4032: 6d 65 72 67 65 3d 35 0d 04 02 23 6d 65 72 67 65 merge=5...#merge +| 4048: 3d 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 =1.............. +| end crash-53f41622dd3bf6.db +}]} {} + +do_catchsql_test 29.1 { + PRAGMA writable_schema = 1; + INSERT INTO t1(a) SELECT X'819192E578DE3F'; + UPDATE t1 SET b=quote(zeroblob(current_date)) WHERE t1 MATCH 't*'; + INSERT INTO t1(b) VALUES(x'78'); + INSERT INTO t1(t1) SELECT x FROM t2; +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +# +reset_db +do_test 30.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 28672 pagesize 4096 filename crash-e6e3857edf9b26.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 00 .....@ ........ +| 96: 00 00 00 00 0d 0e b1 00 06 0d a4 00 0f 8d 0f 21 ...............! +| 112: 0e b9 0d c8 0e 7e 0d a4 00 00 00 00 00 00 00 00 .....~.......... +| 3488: 00 00 00 00 22 07 06 17 11 11 01 31 74 61 62 6c ...........1tabl +| 3504: 65 74 32 74 32 07 43 52 45 41 54 45 20 54 41 42 et2t2.CREATE TAB +| 3520: 4c 45 20 74 32 28 78 29 81 33 05 07 17 1f 1f 01 LE t2(x).3...... +| 3536: 82 35 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72 .5tablet1_segdir +| 3552: 74 31 5f 73 65 67 64 69 72 05 43 52 45 41 54 45 t1_segdir.CREATE +| 3568: 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69 TABLE 't1_segdi +| 3584: 72 27 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52 r'(level INTEGER +| 3600: 2c 69 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61 ,idx INTEGER,sta +| 3616: 72 74 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52 rt_block INTEGER +| 3632: 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 ,leaves_end_bloc +| 3648: 6b 20 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c k INTEGER,end_bl +| 3664: 6f 63 6b 20 49 4e 54 45 47 45 62 2c 72 6f 6f 74 ock INTEGEb,root +| 3680: 20 42 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45 BLOB,PRIMARY KE +| 3696: 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 06 Y(level, idx))1. +| 3712: 06 17 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74 ..E...indexsqlit +| 3728: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73 e_autoindex_t1_s +| 3744: 65 67 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72 egdir_1t1_segdir +| 3760: 06 0f c7 00 08 00 00 00 00 66 04 07 17 23 23 01 .........f...##. +| 3776: 81 13 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e ..tablet1_segmen +| 3792: 74 73 74 31 5f 73 65 67 6d 65 6e 74 73 04 43 52 tst1_segments.CR +| 3808: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 EATE TABLE 't1_s +| 3824: 65 67 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64 egments'(blockid +| 3840: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 INTEGER PRIMARY +| 3856: 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 KEY, block BLOB +| 3872: 29 6a 03 07 17 21 21 01 81 1f 74 61 62 6c 65 74 )j...!!...tablet +| 3888: 31 5f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 1_contentt1_cont +| 3904: 65 6e 74 03 43 52 45 41 54 45 20 54 41 42 4c 45 ent.CREATE TABLE +| 3920: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f 't1_content'(do +| 3936: 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d cid INTEGER PRIM +| 3952: 41 52 59 20 4b 45 59 2c 20 27 63 30 61 27 2c 20 ARY KEY, 'c0a', +| 3968: 27 63 31 62 27 2c 20 27 63 32 63 27 29 38 02 06 'c1b', 'c2c')8.. +| 3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52 ...._tablet1t1CR +| 4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB +| 4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33 LE t1 USING fts3 +| 4032: 28 61 2c 62 2c 63 29 00 00 00 00 00 00 00 00 00 (a,b,c)......... +| page 3 offset 8192 +| 0: 0d 00 00 00 25 0b 48 00 0f d8 0f af 0f 86 0f 74 ....%.H........t +| 16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5 .a.N./.......... +| 32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 0d ef 00 00 ...t.[.@.$...... +| 2880: 00 00 00 00 00 00 00 00 81 3f 25 06 00 82 7e f0 .........?%...~. +| 2896: 00 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e .COMPILER=gcc-5. +| 2912: 34 23 00 20 32 30 31 36 30 36 30 39 20 44 45 42 4#. 20160609 DEB +| 2928: 55 47 20 45 4e 41 42 4c 45 20 44 42 53 54 41 54 UG ENABLE DBSTAT +| 2944: 20 56 54 41 42 20 45 4e 42 92 4c 45 20 46 54 53 VTAB ENB.LE FTS +| 2960: 34 20 45 4e 41 42 4c 45 20 46 54 53 35 20 45 4e 4 ENABLE FTS5 EN +| 2976: 41 42 4c 45 20 47 45 4f 50 4f 4c 59 20 45 4e 41 ABLE GEOPOLY ENA +| 2992: 42 4c 45 1f 4a 53 4f 4e 31 20 45 4e 41 42 4c 49 BLE.JSON1 ENABLI +| 3008: 00 4d 45 4d 53 59 53 35 20 45 4e 41 42 4c 45 20 .MEMSYS5 ENABLE +| 3024: 52 54 52 45 45 20 4d 41 58 20 4d 45 4d 4f 52 59 RTREE MAX MEMORY +| 3040: 3d 35 30 30 30 30 30 30 30 20 4f 4d 49 54 20 4c =50000000 OMIT L +| 3056: 4f 41 44 20 45 58 54 45 4e 53 49 4f 4e 20 54 48 OAD EXTENSION TH +| 3072: 52 45 41 44 53 41 46 45 3d 30 18 24 05 00 25 0f READSAFE=0.$..%. +| 3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49 .THREADSAFE=0XBI +| 3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41 NARY.#..%..THREA +| 3120: 44 53 41 46 45 3d 30 88 4e 4f 43 41 53 45 17 22 DSAFE=0.NOCASE.. +| 3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 45 3d ..%..THREADSAFE= +| 3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d 0XRTRIM.!..3..OM +| 3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 4f IT LOAD EXTENSIO +| 3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f NXBINARY. ..3..O +| 3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 MIT LOAD EXTENSI +| 3216: 4f 4e 58 4e 4f 43 41 53 45 1e 20 05 00 33 0f 17 ONXNOCASE. ..3.. +| 3232: 4f 4d 49 54 20 4c 4f 41 54 20 45 58 54 45 4e 53 OMIT LOAT EXTENS +| 3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 04 00 33 0f 19 IONXRTRIM....3.. +| 3264: 82 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 30 .AX MEMORY=50000 +| 3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f 000XBINARY....3. +| 3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 .MAX MEMORY=5000 +| 3312: 30 30 30 30 58 4e 4f 43 41 53 45 1e 1c 05 00 33 0000XNOCASE....3 +| 3328: 0f 17 4d 41 58 20 4d 45 4d fa 52 59 3d 35 30 20 ..MAX MEM.RY=50 +| 3344: 30 30 30 30 30 58 52 54 52 49 4d 18 1b 05 00 25 00000XRTRIM....% +| 3360: 0f 19 45 4e 41 42 4c 45 20 52 53 52 45 45 58 42 ..ENABLE RSREEXB +| 3376: 49 4e 41 52 59 18 1a 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3392: 4c 45 20 52 54 52 45 45 58 4e 4f 53 41 53 45 17 LE RTREEXNOSASE. +| 3408: 19 05 00 25 0f 17 45 4e 42 42 4c 45 20 52 54 52 ...%..ENBBLE RTR +| 3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45 EEXRTRIM....)..E +| 3440: 4e 41 42 4c 45 20 4d 45 4d 53 5a 53 35 58 42 49 NABLE MEMSZS5XBI +| 3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4e 41 42 3c NARY....)..ENAB< +| 3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 53 45 E MEMSYS5XNOCASE +| 3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 4d 45 ....)..ENABLE ME +| 3504: 4d 53 59 53 35 58 52 54 52 49 4d 18 15 05 00 25 MSYS5XRTRIM....% +| 3520: 0f 19 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 58 42 ..ENABLE JSON1XB +| 3536: 49 4e 41 52 59 18 14 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3552: 4c 45 20 4a 53 4f 4e 31 58 4e 4f 43 41 53 45 17 LE JSON1XNOCASE. +| 3568: 13 05 00 25 0f 17 45 4e 41 42 4c 45 20 4a 53 4f ...%..ENABLE JSO +| 3584: 4e 31 58 52 54 52 49 4d 1a 12 05 00 29 0f 19 45 N1XRTRIM....)..E +| 3600: 4e 31 42 4c 45 20 47 45 4e 50 4f 4c 59 58 42 49 N1BLE GENPOLYXBI +| 3616: 4e 41 52 59 1a 11 05 00 29 0f 19 45 4e f2 1e 4c NARY....)..EN..L +| 3632: 45 20 47 45 4f 50 4f 4c 59 58 4e 4f 43 41 53 45 E GEOPOLYXNOCASE +| 3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 45 ....)..ENABLE GE +| 3664: 4f 50 4f 4c 59 58 52 54 52 49 4d 17 0f 05 00 23 OPOLYXRTRIM....# +| 3680: 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 58 42 49 ..ENABLE FTS5XBI +| 3696: 4e 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 3c NARY....#..ENAB< +| 3712: 45 20 46 54 53 35 58 4e 4f 43 41 53 45 16 0d 05 E FTS5XNOCASE... +| 3728: 00 23 0f 17 45 4e 41 42 4c 45 20 46 54 53 35 58 .#..ENABLE FTS5X +| 3744: 52 54 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42 RTRIM....#..ENAB +| 3760: 4c 45 20 46 54 53 34 58 42 49 4e 41 52 59 17 0b LE FTS4XBINARY.. +| 3776: 05 00 23 0f 19 45 4e 41 43 4c 45 20 46 54 53 35 ..#..ENACLE FTS5 +| 3792: 58 4e 4f 43 40 53 45 16 0a 05 00 23 0f 17 45 4e XNOC@SE....#..EN +| 3808: 41 42 4c 45 20 46 54 53 34 58 52 54 52 49 4d 1e ABLE FTS4XRTRIM. +| 3824: 09 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3840: 54 41 55 20 56 54 41 42 58 42 49 4e 41 52 59 1e TAU VTABXBINARY. +| 3856: 08 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3872: 54 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d TAT VTABXNOCASE. +| 3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3904: 54 41 54 20 56 54 41 42 58 52 54 62 49 4d 11 06 TAT VTABXRTbIM.. +| 3920: 05 00 17 0f 19 44 45 42 54 47 58 42 49 4e 41 52 .....DEBTGXBINAR +| 3936: 59 11 05 05 00 17 0f 19 54 45 42 55 47 58 4e 4f Y.......TEBUGXNO +| 3952: 43 41 53 45 10 04 05 00 17 0f 17 44 45 42 55 47 CASE.......DEBUG +| 3968: 68 52 54 52 49 4d 27 03 05 00 43 0f 19 43 4f 4d hRTRIM'...C..COM +| 3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20 PILER=gcc-5.4.0 +| 4000: 32 30 31 36 30 36 30 39 58 42 49 4e 41 52 59 27 20160609XBINARY' +| 4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67 ...C..COMPILER=g +| 4032: 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36 30 cc-5.4.0 2016060 +| 4048: 39 58 4f 4f 43 41 53 45 26 01 05 00 43 0f 17 43 9XOOCASE&...C..C +| 4064: 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e OMPILER=gcc-5.4. +| 4080: 30 20 32 30 31 36 30 36 30 39 58 52 54 52 49 4d 0 20160609XRTRIM +| page 4 offset 12288 +| 0: 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| page 5 offset 16384 +| 0: 0d 00 00 00 02 0b a0 00 0c ad 0b a0 00 00 00 00 ................ +| 2976: 82 0a 02 08 08 09 08 08 17 84 06 30 20 32 35 33 ...........0 253 +| 2992: 00 01 30 04 25 06 1b 00 00 08 32 30 31 36 30 36 ..0.%.....201606 +| 3008: 30 39 03 25 07 00 00 01 34 03 25 05 00 00 01 35 09.%....4.%....5 +| 3024: 03 25 04 00 01 07 30 30 30 30 30 30 30 03 25 1a .%....0000000.%. +| 3040: 00 00 08 63 6f 6d 70 69 6c 65 72 03 25 02 00 00 ...compiler.%... +| 3056: 06 64 62 73 74 61 74 03 25 0a 00 01 04 65 62 75 .dbstat.%....ebu +| 3072: 67 03 25 08 00 00 06 65 6e 61 62 6c 65 09 25 09 g.%....enable.%. +| 3088: 05 04 04 04 04 04 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3104: 6e 03 25 1d 00 00 04 66 74 73 34 03 25 0d 00 03 n.%....fts4.%... +| 3120: 01 35 03 25 0f 00 00 03 67 63 63 03 25 03 00 01 .5.%....gcc.%... +| 3136: 06 65 6f 70 6f 6c 79 03 25 11 00 00 05 6a 73 6f .eopoly.%....jso +| 3152: 6e 31 03 25 14 00 e8 04 6c 6f 61 64 03 25 1c 00 n1.%....load.%.. +| 3168: 00 03 6d 61 78 03 25 18 00 01 05 65 6d 6f 72 79 ..max.%....emory +| 3184: 03 25 19 00 03 04 73 79 73 35 03 25 15 00 00 04 .%....sys5.%.... +| 3200: 6f 6d 69 74 03 25 1b 00 00 05 72 74 72 65 65 03 omit.%....rtree. +| 3216: 25 17 00 00 0a 74 68 72 65 61 64 73 61 66 65 03 %....threadsafe. +| 3232: 25 1e 00 00 04 76 74 61 62 03 25 0b 00 86 50 01 %....vtab.%...P. +| 3248: 08 08 08 08 08 17 8d 12 30 20 38 33 35 00 01 30 ........0 835..0 +| 3264: 12 01 06 00 01 06 00 01 06 00 1f 03 00 01 03 00 ................ +| 3280: 01 03 00 00 08 32 30 31 36 30 36 30 39 09 01 07 .....20160609... +| 3296: 00 01 07 00 01 07 00 00 01 34 09 01 05 00 01 05 .........4...... +| 3312: 00 01 05 00 00 01 35 09 01 04 00 01 04 00 01 04 ......5......... +| 3328: 00 01 07 30 30 30 30 30 30 30 09 1c 04 00 01 04 ...0000000...... +| 3344: 00 01 04 00 00 06 62 69 6e 61 72 79 3c 03 01 02 ......binary<... +| 3360: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3376: 00 03 01 02 f2 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3392: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 ................ +| 3408: 01 02 02 00 03 01 02 02 00 00 08 63 6f 6d 70 69 ...........compi +| 3424: 6c 65 72 09 01 02 00 01 02 00 01 02 00 00 06 64 ler............d +| 3440: 62 73 74 61 74 09 07 03 00 01 03 00 01 03 00 01 bstat........... +| 3456: 04 65 62 75 67 09 04 02 00 01 02 00 01 02 00 00 .ebug........... +| 3472: 06 65 6e 60 62 6c 65 3f 07 02 00 01 02 00 01 01 .en`ble?........ +| 3488: ff f1 b1 00 00 02 3f 01 01 f0 f1 02 00 57 02 00 ......?......W.. +| 3504: 01 02 00 01 02 00 01 02 00 01 02 00 01 02 10 01 ................ +| 3520: 02 00 01 02 00 01 02 00 01 02 01 01 02 00 01 02 ................ +| 3536: 00 01 02 00 00 f2 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3552: 6e 09 1f 04 00 01 04 00 01 04 00 00 04 66 74 73 n............fts +| 3568: 34 09 0a 03 00 01 03 00 01 03 00 03 01 35 09 0d 4............5.. +| 3584: 03 00 01 03 00 01 03 00 00 03 67 63 63 09 01 03 ..........gcc... +| 3600: 00 01 03 00 01 03 00 01 06 65 6f 70 6f 6c 79 09 .........eopoly. +| 3616: 10 03 00 01 03 00 01 03 00 00 b3 6a 73 6f 6e 31 ...........json1 +| 3632: 09 13 03 00 01 03 00 01 03 00 00 04 6c 6f 61 64 ............load +| 3648: 09 1f 03 00 01 03 00 01 03 00 00 03 6d 61 78 09 ............max. +| 3664: 1c 02 00 01 02 00 01 02 00 01 05 65 6d 6f 72 79 ...........emory +| 3680: 09 1c 03 00 01 03 00 01 03 00 03 04 73 79 73 35 ............sys5 +| 3696: 09 16 03 00 01 03 00 01 03 cc 00 06 6e 6f 63 61 ............noca +| 3712: 73 65 3c 02 01 02 02 00 03 01 02 02 00 03 01 02 se<............. +| 3728: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3744: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3760: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 00 ................ +| 3776: 04 6f 6d 69 74 09 1f 02 00 01 02 00 01 02 00 00 .omit........... +| 3792: 05 72 74 62 65 65 09 19 03 00 01 03 00 01 03 00 .rtbee.......... +| 3808: 03 02 69 6d 3c 01 01 02 02 00 03 01 02 02 00 03 ..im<........... +| 3824: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 ................ +| 3840: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 ................ +| 3856: 02 00 03 01 02 02 00 03 01 02 01 00 03 01 02 02 ................ +| 3872: 00 00 0a 74 68 72 65 61 64 73 61 66 65 09 22 02 ...threadsafe... +| 3888: 00 01 02 00 02 02 00 00 04 76 74 61 62 09 07 04 .........vtab... +| 3904: 00 01 03 00 01 04 00 00 01 78 b4 01 01 01 01 02 .........x...... +| 3920: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 3936: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 3952: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 3968: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 3984: 02 01 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4000: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 4016: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 4032: 01 01 02 00 01 01 01 da 00 01 01 01 02 00 01 01 ................ +| 4048: 01 02 00 01 01 01 01 ff ff 01 01 02 00 01 01 01 ................ +| 4064: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4080: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| page 6 offset 20480 +| 0: 0a 00 00 00 02 0f f5 00 0f fb 0f f5 01 00 00 00 ................ +| 4080: 00 00 00 00 00 05 04 08 09 01 02 04 04 08 08 09 ................ +| page 7 offset 24576 +| 0: 01 6f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .o.............. +| end crash-e6e3857edf9b26.db +}]} {} + +do_execsql_test 30.1 { + UPDATE t1 SET b=a; +} + +do_catchsql_test 30.2 { + SELECT (matchinfo(null)) FROM t1 WHERE t1 MATCH 'ee*e*e*e*e*e*e*Re*e*e*e**' +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 31.0 { +CREATE VIRTUAL TABLE t1 USING fts3(a,b,c); +INSERT INTO t1_segdir VALUES(0,0,0,0,'0 592',X'00016dcb048ce6fbd3b2d68bfebf0101020200808080808080808020010202008080808080808080100102020080808080808080800801020200808080808080808004010202008080808080808080020102020080808080808080800101020200808080808080804001020200808080808080802001020200808080808080801001020200808080808080800801020200808080808080800401020200808080808080800201020200808080808080800101020200808080808080400102020080808080808020010202008080808080801001020200808080808080080102020080808080808004010202008080808080800201020200808080808080010102020080808080804001020200808080808020010202008080808080100102020080808080800801020200808080808004010202008080808080020102020080808080800101020200808080804001020200808080802001020200808080801001020200808080800801020200808080800401020200808080800201020200808080800101020200808080400102020080808020010202008080801001020200808080080102020080808004010202008080800201020200808080010102020080804001020200808020010202008080100102020080800801020200808004010202008080020102020080800101020200804001020200802001020200801001020200800801020200800401020200800201020200800101020200400102020020010202001001020200080102020004010202000201020200010102020001010202008080808080808080800101020200'); +INSERT INTO t1_segdir VALUES(0,1,0,0,'0 18',X'00026d6d0d8ee6fbd3b2d68bfe7f01020200'); +} + +do_catchsql_test 31.1 { + SELECT (matchinfo(t1, c ) ) FROM t1 WHERE t1 MATCH 'M*M*M*M*'; +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +# +reset_db +do_test 32.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +.open --hexdb +| size 24576 pagesize 4096 filename crash-74fdbc96edbc04.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 00 .....@ ........ +| 96: 00 00 00 00 0d 0e b1 00 06 0d a4 00 0f 8d 0f 21 ...............! +| 112: 0e b9 0d c8 0e 7e 0d a4 00 00 00 00 00 00 00 00 .....~.......... +| 3488: 00 00 00 00 22 07 06 17 11 11 01 31 74 61 62 6c ...........1tabl +| 3504: 65 74 32 74 32 07 43 52 45 41 54 45 20 54 41 42 et2t2.CREATE TAB +| 3520: 4c 45 20 74 32 28 78 29 81 33 05 07 17 1f 1f 01 LE t2(x).3...... +| 3536: 82 35 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72 .5tablet1_segdir +| 3552: 74 31 5f 73 65 67 64 69 72 05 43 52 45 41 54 45 t1_segdir.CREATE +| 3568: 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69 TABLE 't1_segdi +| 3584: 72 27 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52 r'(level INTEGER +| 3600: 2c 69 64 78 20 49 4e 54 45 47 44 52 2c 73 74 61 ,idx INTEGDR,sta +| 3616: 72 74 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52 rt_block INTEGER +| 3632: 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 ,leaves_end_bloc +| 3648: 6b 20 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c k INTEGER,end_bl +| 3664: 6f 63 6b 20 49 4e 54 45 47 45 52 2c 72 6f 6f 74 ock INTEGER,root +| 3680: 20 42 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45 BLOB,PRIMARY KE +| 3696: 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 06 Y(level, idx))1. +| 3712: 06 17 45 1f 01 00 6a 6e 64 65 78 73 71 6c 69 74 ..E...jndexsqlit +| 3728: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73 e_autoindex_t1_s +| 3744: 65 67 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72 egdir_1t1_segdir +| 3760: 06 0f c7 00 08 00 00 00 00 66 04 07 17 23 23 01 .........f...##. +| 3776: 81 13 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e ..tablet1_segmen +| 3792: 74 73 74 31 5f 73 65 67 6d 65 6e 74 73 03 43 52 tst1_segments.CR +| 3808: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 EATE TABLE 't1_s +| 3824: 65 67 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64 egments'(blockid +| 3840: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 5a INTEGER PRIMARZ +| 3856: 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 KEY, block BLOB +| 3872: 29 6a 03 07 17 21 21 01 81 1f 74 61 62 6c 65 74 )j...!!...tablet +| 3888: 31 5f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 1_contentt1_cont +| 3904: 65 6e 74 03 43 52 45 41 54 45 20 54 41 42 4c 45 ent.CREATE TABLE +| 3920: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f 't1_content'(do +| 3936: 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d cid INTEGER PRIM +| 3952: 41 52 59 20 4b 45 59 2c 20 27 63 30 61 27 2c 20 ARY KEY, 'c0a', +| 3968: 27 63 31 62 27 2c 20 27 63 32 63 27 29 38 02 06 'c1b', 'c2c')8.. +| 3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52 ...._tablet1t1CR +| 4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB +| 4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33 LE t1 USING fts3 +| 4032: 28 61 2c 62 2c 63 29 00 00 00 00 00 00 00 00 00 (a,b,c)......... +| page 3 offset 8192 +| 0: 0d 00 00 00 25 0b 48 00 0f d8 0f af 0f 86 0f 74 ....%.H........t +| 16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5 .a.N./.......... +| 32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 0d ef 0d d5 ...t.[.@.$...... +| 48: 0d bb 0d a0 0d 84 0d 68 0d 50 0d 35 0d 1b 0c fb .......h.P.5.... +| 64: 0c da 0c b8 fc 99 0c 78 0c 57 0c 3e 0c 24 0c 0a .......x.W.>.$.. +| 80: 0b 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .H.............. +| 2880: 00 00 00 00 00 00 00 00 81 3f 25 06 00 82 7f 00 .........?%..... +| 2896: 00 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e .COMPILER=gcc-5. +| 2912: 34 2e 30 20 32 30 31 36 30 36 30 39 20 44 45 42 4.0 20160609 DEB +| 2928: 55 47 20 45 4e 41 42 4c 45 20 44 42 53 54 7e 54 UG ENABLE DBST~T +| 2944: 20 56 54 41 42 20 45 4e 41 42 4c 45 20 46 54 53 VTAB ENABLE FTS +| 2960: 44 20 45 4e 41 42 4c 45 20 46 54 53 35 20 45 4e D ENABLE FTS5 EN +| 2976: 41 42 4c 45 20 47 45 4f 50 4f 4c 59 20 45 4e 41 ABLE GEOPOLY ENA +| 2992: 42 4c 45 20 4a 53 4f 4e 31 20 45 4e 41 42 4c 45 BLE JSON1 ENABLE +| 3008: 20 4d 45 4d 53 59 53 35 20 45 4e 41 42 4c 45 20 MEMSYS5 ENABLE +| 3024: 52 54 52 45 45 20 4d 41 58 20 4d 45 4d 4f 52 59 RTREE MAX MEMORY +| 3040: 3d 35 30 30 30 30 30 30 30 20 4f 4d 49 54 20 4c =50000000 OMIT L +| 3056: 4f 41 44 20 45 58 54 45 4e 53 49 4f 4e 20 54 48 OAD EXTENSION TH +| 3072: 52 45 41 44 53 41 46 45 3d 30 18 24 05 00 25 0f READSAFE=0.$..%. +| 3088: 19 54 48 52 45 41 44 54 41 46 45 3d 30 58 42 49 .THREADTAFE=0XBI +| 3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41 NARY.#..%..THREA +| 3120: 44 53 41 46 45 3d 30 bd 4e 4f 43 41 53 45 17 22 DSAFE=0.NOCASE.. +| 3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 45 3d ..%..THREADSAFE= +| 3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d 0XRTRIM.!..3..OM +| 3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 4e IT LOAD EXTENSIN +| 3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f NXBINARY. ..3..O +| 3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 MIT LOAD EXTENSI +| 3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17 ONXNOCASE....3.. +| 3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 OMIT LOAD EXTENS +| 3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f 19 IONXRTRIM....3.. +| 3264: 4d 41 58 1f 4d 45 4d 4f 52 59 3d 35 30 30 30 30 MAX.MEMORY=50000 +| 3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f 000XBINARY....3. +| 3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 .MAX MEMORY=5000 +| 3312: 30 30 30 30 58 4e 4f 43 41 53 45 1e 1c 05 00 33 0000XNOCASE....3 +| 3328: 0f 17 4d 41 58 20 4d 44 4d 4f 52 59 3d 35 30 30 ..MAX MDMORY=500 +| 3344: 30 30 30 30 30 58 52 54 52 49 4d 18 1b 05 00 25 00000XRTRIM....% +| 3360: 0f 19 45 4e 41 42 4c 45 20 52 54 52 45 45 58 42 ..ENABLE RTREEXB +| 3376: 49 4e 41 52 59 18 1a 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3392: 4c 55 20 52 54 52 45 45 58 4e 4f 43 41 53 45 17 LU RTREEXNOCASE. +| 3408: 19 05 00 25 0f 17 45 4e 41 42 4c 45 20 52 54 52 ...%..ENABLE RTR +| 3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45 EEXRTRIM....)..E +| 3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 58 42 49 NABLE MEMSYS5XBI +| 3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4e 41 42 4c NARY....)..ENABL +| 3472: 45 20 4d 45 4d 53 59 53 35 58 4e 3f 43 41 53 45 E MEMSYS5XN?CASE +| 3488: 19 16 05 00 29 0f 17 45 4e a1 42 4c 45 20 4d 45 ....)..EN.BLE ME +| 3504: 4d 53 59 53 35 58 52 54 52 49 4d 18 15 05 00 25 MSYS5XRTRIM....% +| 3520: 0f 19 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 58 42 ..ENABLE JSON1XB +| 3536: 49 4e 41 52 59 18 14 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3552: 4c 45 20 4a 53 4f 4e 31 58 4e 4f 43 41 53 45 17 LE JSON1XNOCASE. +| 3568: 13 05 00 25 0f 17 45 4e 41 42 4c 45 20 4a 53 4f ...%..ENABLE JSO +| 3584: 4e 31 58 52 54 52 49 4d 1a 12 05 00 29 0f 19 45 N1XRTRIM....)..E +| 3600: 4e 41 42 4c 45 20 47 45 4f 50 5f 4c 59 58 42 49 NABLE GEOP_LYXBI +| 3616: 4e 41 52 59 1a 11 05 00 29 0f 19 45 4e 41 42 4c NARY....)..ENABL +| 3632: 45 20 47 45 4f 50 4f 4c 59 58 4b bf 43 41 53 45 E GEOPOLYXK.CASE +| 3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 45 ....)..ENABLE GE +| 3664: 4f 50 4f 4c 59 58 52 54 52 49 4d 17 0f 05 00 23 OPOLYXRTRIM....# +| 3680: 0f 19 45 4e 41 42 4c 55 20 46 54 53 35 58 42 49 ..ENABLU FTS5XBI +| 3696: 4e 4b a2 59 17 0e 05 00 23 0f 19 45 4e 41 42 4c NK.Y....#..ENABL +| 3712: 45 20 46 54 52 35 58 4e 4f 43 41 53 45 16 0d 05 E FTR5XNOCASE... +| 3728: 00 23 0f 17 45 4e 41 42 4c 45 20 46 54 53 35 58 .#..ENABLE FTS5X +| 3744: 52 54 52 49 4d 17 0b 05 00 23 0f 19 45 4e 41 42 RTRIM....#..ENAB +| 3760: 4c 45 20 46 54 53 34 58 42 49 4e 41 52 59 17 0b LE FTS4XBINARY.. +| 3776: 05 00 23 0f 19 45 4e 41 42 4c 45 20 46 54 53 34 ..#..ENABLE FTS4 +| 3792: 58 4e 4f 43 41 53 45 16 0a 05 00 23 0f 17 45 4e XNOCASE....#..EN +| 3808: 41 42 4c 45 20 46 54 53 34 58 52 54 52 49 4d 1e ABLE FTS4XRTRIM. +| 3824: 09 05 07 e1 0f 19 45 4e 41 42 4c 45 20 44 42 53 ......ENABLE DBS +| 3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 52 59 1e TAT VTABXBINARY. +| 3856: 18 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3872: 54 41 54 20 56 54 41 41 18 4e 4f 43 41 53 45 1d TAT VTAA.NOCASE. +| 3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 44 32 53 ...1..ENABLE D2S +| 3904: 54 41 54 20 56 54 41 42 58 52 54 52 49 4d 11 06 TAT VTABXRTRIM.. +| 3920: 05 00 17 0f 19 44 45 42 55 47 58 42 49 4e 41 52 .....DEBUGXBINAR +| 3936: 59 11 05 05 00 17 0f 19 44 45 00 00 00 00 00 00 Y.......DE...... +| page 5 offset 16384 +| 0: 0d 00 00 00 02 0b a0 00 0c ad 0b a0 01 00 00 00 ................ +| 2976: 82 0a 02 08 08 09 08 08 17 84 06 30 20 32 35 33 ...........0 253 +| 2992: 00 01 30 04 25 06 1b 00 00 08 32 30 31 36 30 36 ..0.%.....201606 +| 3008: 30 38 03 25 07 00 00 01 34 03 25 05 00 00 01 35 08.%....4.%....5 +| 3024: 03 25 13 00 01 07 30 30 30 30 30 30 30 03 25 1a .%....0000000.%. +| 3040: 00 00 08 63 6f 6d 70 69 6c 65 72 03 25 02 00 00 ...compiler.%... +| 3056: 06 64 62 73 74 61 74 03 25 0a 00 01 04 65 62 75 .dbstat.%....ebu +| 3072: 67 03 25 08 00 00 06 65 6e 61 62 6c 65 09 25 09 g.%....enable.%. +| 3088: 05 04 04 04 04 04 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3104: 6e 03 25 1d 00 00 04 66 74 73 34 03 25 0d 00 03 n.%....fts4.%... +| 3120: 01 35 03 25 0f 00 00 03 67 63 63 03 25 03 00 01 .5.%....gcc.%... +| 3136: 06 65 6f 70 6f 6c 79 03 25 11 00 00 05 6a 73 6f .eopoly.%....jso +| 3152: 6e 31 03 25 13 00 00 04 6c 6f 61 64 03 25 1c 00 n1.%....load.%.. +| 3168: 00 03 6d 62 78 03 25 18 00 01 05 65 6d 6f 72 79 ..mbx.%....emory +| 3184: 03 25 19 00 03 04 73 c8 73 35 03 25 15 00 00 04 .%....s.s5.%.... +| 3200: 6f 6d 69 74 03 25 1b 00 00 05 72 74 72 65 65 03 omit.%....rtree. +| 3216: 25 17 00 00 0a 74 68 72 65 61 64 73 61 66 65 03 %....threadsafe. +| 3232: 25 1e 00 00 04 76 74 61 62 03 25 0b 00 86 50 01 %....vtab.%...P. +| 3248: 08 08 08 08 08 17 8d 12 30 20 38 33 35 00 01 30 ........0 835..0 +| 3264: 12 01 06 00 01 06 00 01 06 00 1f 03 00 01 03 00 ................ +| 3280: 01 03 00 00 08 32 30 31 36 30 36 30 39 09 01 07 .....20160609... +| 3296: 00 01 07 00 01 07 00 00 01 34 09 01 05 00 01 05 .........4...... +| 3312: 00 01 05 00 00 01 35 09 01 04 00 01 04 00 02 04 ......5......... +| 3328: 00 01 07 30 2f 30 30 30 30 30 09 1c 04 00 01 04 ...0/00000...... +| 3344: 00 01 04 00 00 06 62 69 6e 61 72 79 3c 03 01 02 ......binary<... +| 3360: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3376: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3392: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 ................ +| 3408: 01 02 02 00 03 01 02 02 00 00 08 63 6f 6d 70 69 ...........compi +| 3424: 6c 65 72 09 01 02 00 01 02 00 01 02 00 00 06 64 ler............d +| 3440: 62 73 74 61 74 09 07 03 00 01 03 00 01 03 00 01 bstat........... +| 3456: 04 65 62 75 67 09 04 02 00 01 02 00 01 02 00 00 .ebug........... +| 3472: 06 65 6e 61 6c 2c 65 3f 07 02 00 01 02 00 01 02 .enal,e?........ +| 3488: 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00 ................ +| 3504: 01 02 00 01 02 00 01 02 00 01 01 ff f1 02 00 01 ................ +| 3520: 02 00 01 02 00 01 02 00 f1 02 00 01 02 00 01 4f ...............O +| 3536: 00 01 02 00 01 02 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3552: 6e 09 1f 04 00 01 04 00 01 04 00 00 04 66 74 73 n............fts +| 3568: 34 09 0a 03 00 01 03 00 00 f3 00 03 01 35 09 0d 4............5.. +| 3584: 03 00 01 04 00 01 03 00 00 03 67 63 63 09 01 03 ..........gcc... +| 3600: 00 01 03 00 01 03 00 01 06 65 6f 70 6f 6c 79 09 .........eopoly. +| 3616: 10 03 00 01 03 00 01 03 00 00 05 6a 73 6f 6e 31 ...........json1 +| 3632: 09 13 03 00 01 02 ff 01 03 00 00 04 6c 6f 61 63 ............loac +| 3648: 09 1f 03 00 01 03 00 01 03 00 00 03 6d 61 78 09 ............max. +| 3664: 1c 02 00 01 02 00 01 02 00 01 05 64 6d 6f 72 79 ...........dmory +| 3680: 09 1c 03 00 01 03 00 01 03 00 03 04 73 79 73 35 ............sys5 +| 3696: 09 16 02 f0 01 03 00 01 03 00 00 06 6e 6f 63 61 ............noca +| 3712: 73 65 3c 02 01 02 02 00 03 01 02 02 00 03 01 02 se<............. +| 3728: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3744: 00 03 01 02 02 00 03 01 02 02 00 4b 01 02 02 00 ...........K.... +| 3760: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 00 ................ +| 3776: 04 6f 6d 69 74 09 1f 02 00 01 02 00 01 02 00 00 .omit........... +| 3792: 05 72 74 72 65 65 09 19 03 00 01 03 00 01 03 00 .rtree.......... +| 3808: 03 02 69 6d 3c 01 01 02 02 00 03 01 02 02 00 03 ..im<........... +| 3824: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 ................ +| 3840: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 ................ +| 3856: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3872: 00 00 0a 74 68 72 65 61 64 73 61 66 65 09 22 02 ...threadsafe... +| 3888: 00 01 02 00 01 02 00 00 04 76 74 61 62 09 07 04 .........vtab... +| 3904: 00 01 04 00 01 04 00 00 01 78 b4 01 01 01 01 02 .........x...... +| 3920: 00 01 f4 01 02 00 01 02 01 02 00 01 01 01 02 ff ................ +| 3936: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 3952: 01 01 02 ae 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 3968: 01 12 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 3984: 12 00 01 01 01 02 01 01 01 01 02 00 01 01 01 02 ................ +| 4000: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 4016: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 4032: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 4048: 01 02 00 01 01 01 02 00 01 76 01 02 00 01 01 01 .........v...... +| 4064: 02 00 01 01 01 02 01 01 01 01 02 00 01 01 01 02 ................ +| 4080: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| page 6 offset 20480 +| 0: 0a 00 00 00 02 0f f5 00 0f fb 0f f5 00 00 00 00 ................ +| 4080: 00 00 00 00 00 05 04 08 09 01 02 04 04 08 08 09 ................ +| end crash-74fdbc96edbc04.db +}]} {} + +do_catchsql_test 32.1 { + UPDATE t1 SET b=quote(zeroblob(6.51158946e+5)) WHERE a MATCH '*t*'; +} {1 {database disk image is malformed}} + +#do_catchsql_test 32.2 { +# UPDATE t1 SET b=((- '' )) WHERE a MATCH '0*t'; +#} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +# +ifcapable icu { + reset_db + do_catchsql_test 33.0 { + CREATE VIRTUAL TABLE f USING fts3(a,b,tokenize=icu); + CREATE TABLE 'f_docsize'(docid INTEGER PRIMARY KEY, size BLOB); + CREATE TABLE 'f_stat'(id INTEGER PRIMARY KEY, value BLOB); + INSERT INTO f VALUES (1, '1234'); + INSERT INTO f_stat VALUES (1,x'0000000165656565db6569746565c5c52bc5c5c53e3a003bc502ffffffffc5c5c53e3a003bc502fffffffffb8b2afbfb6565f0740100650000000165656565db6569746565c5c52bc5c5c53e3a003bc502ffffffffc5c5c53e3a003b8b00c5c5c5c5c5bfc5'); + INSERT INTO f(f) VALUES ('merge=198,49'); + } {1 {database disk image is malformed}} +} + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 34.0 { + CREATE VIRTUAL TABLE f USING fts3(a,b); + INSERT INTO f VALUES (1, '1234'); + INSERT INTO f_segdir VALUES (1,255,0,0,'1 255',x'00'); + UPDATE f_segdir SET level = 0 WHERE level IN ( + SELECT level FROM f_segdir LIMIT 1 OFFSET 1 + ); + INSERT INTO f_segdir VALUES (255,249,0,121,'0 0',x'00'); + INSERT INTO f_content VALUES (255,0,x'ff'); + INSERT INTO f_segdir VALUES (1,255,16,0,'1 255',x'00'); +} + +do_catchsql_test 34.1 { + UPDATE f SET b = x'00' WHERE b IN (SELECT b FROM f LIMIT 1 OFFSET 0); +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 35.0 { + CREATE VIRTUAL TABLE f USING fts3(a,b); + INSERT INTO f_segdir VALUES (1,255,0,0,'1 255',x'0001ff000001ff000001ff000001ff000001ff00c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5bec5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5'); +} + +do_catchsql_test 35.1 { + INSERT INTO f(f) VALUES ('integrity-check'); +} {1 {database disk image is malformed}} +do_execsql_test 35.2 { + PRAGMA integrity_check; +} {{malformed inverted index for FTS3 table main.f}} + +reset_db +do_catchsql_test 36.0 { + CREATE VIRTUAL TABLE f USING fts3(a,tokenize=porter); + CREATE TABLE 'f_stat'(id INTEGER PRIMARY KEY, value BLOB); + INSERT INTO f VALUES (1); + INSERT INTO f_stat VALUES (1,x'00000000000101010119013d00ffff0400fa83717b71a69297979701f63d010101010101010101010101190000000000000000fa83717b71a601f63d01010101010101010101010119013d00ffffff0400fa83717b71a69297979701f63d010101010101010101010101190000000000000000fa83717b71a69201f63d010101f63d01010101010101010101010119013d00ffffff0400fa83717b71a6929797010101010101010101010119013d00ffff01f63d01010101010101010101010119013d00ffffff0400fa83717b71a69297979701f63d00fa03ffffffa69297979701f63d010101000000000101010101197e9797976567656565ffa63535354e'); + INSERT INTO f(f) VALUES ('merge=53,216'); +} {0 {}} + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 36.0 { + CREATE VIRTUAL TABLE f USING fts3(a,b); + CREATE TABLE 'f_stat'(id INTEGER PRIMARY KEY, value BLOB); + INSERT INTO f_stat VALUES (1,x'11014101000101c5c5014b010164c5014b010101c50101c5c5010201010101014101000101c5c5014b010101c5014b010101c50101c5c501010100c50101c5c5010101010101e40201010101014101000201010101014101000101010201010101014101000101c5c503b5fefefe3afeffffc5c5c5c50101010101010201010101014101adadadadadadadadadadadad91adadadadadadadad0101c50101c5c501f9ffffffffffffffff0001010102010101010140f5000101c5c5014b010101c50101c5c501010101e6010201010101014101000101c5c5014b010101c50101c5c5010101114b0101c5c50101010a0101020101e60101'); +} + +do_catchsql_test 36.1 { + INSERT INTO f(f) VALUES ('merge=59,59'); +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 37.0 { + CREATE VIRTUAL TABLE f USING fts3(a,b); + INSERT INTO f_segdir VALUES (28,0,0,0,'0 0',x'00'); + INSERT INTO f_segdir VALUES (0,241,0,0,'0 0',x'0001000030310000f1'); +} + +do_catchsql_test 37.1 { + INSERT INTO f VALUES (0,x'00'); +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +# +reset_db +do_test 38.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +.open --hexdb +| size 24576 pagesize 4096 filename crash-1cc4f8a70485ce.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 00 .....@ ........ +| 96: 00 00 00 00 0d 0e b1 00 06 0d a4 00 0f 8d 0f 21 ...............! +| 112: 0e b9 0d c8 0e 7e 0d a4 00 00 00 00 00 00 00 00 .....~.......... +| 3488: 00 00 00 00 22 07 06 17 11 11 01 31 74 61 62 6c ...........1tabl +| 3504: 65 74 32 74 32 07 43 52 45 41 54 45 20 54 41 42 et2t2.CREATE TAB +| 3520: 4c 45 20 74 32 28 78 29 81 33 05 07 17 1f 1f 01 LE t2(x).3...... +| 3536: 82 35 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72 .5tablet1_segdir +| 3552: 74 31 5f 73 65 67 64 69 72 05 43 52 45 41 54 45 t1_segdir.CREATE +| 3568: 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69 TABLE 't1_segdi +| 3584: 72 27 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52 r'(level INTEGER +| 3600: 2c 69 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61 ,idx INTEGER,sta +| 3616: 72 74 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52 rt_block INTEGER +| 3632: 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 ,leaves_end_bloc +| 3648: 6b 20 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c k INTEGER,end_bl +| 3664: 6f 63 6b 20 49 4e 54 45 47 45 62 2c 72 6f 6f 74 ock INTEGEb,root +| 3680: 20 42 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45 BLOB,PRIMARY KE +| 3696: 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 06 Y(level, idx))1. +| 3712: 06 17 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74 ..E...indexsqlit +| 3728: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73 e_autoindex_t1_s +| 3744: 65 67 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72 egdir_1t1_segdir +| 3760: 06 0f c7 00 08 00 00 00 00 66 04 07 17 23 23 01 .........f...##. +| 3776: 81 13 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e ..tablet1_segmen +| 3792: 74 73 74 31 5f 73 65 67 6d 65 6e 74 73 04 43 52 tst1_segments.CR +| 3808: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 EATE TABLE 't1_s +| 3824: 65 67 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64 egments'(blockid +| 3840: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 INTEGER PRIMARY +| 3856: 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 KEY, block BLOB +| 3872: 29 6a 03 07 17 21 21 01 81 1f 74 61 62 6c 65 74 )j...!!...tablet +| 3888: 31 5f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 1_contentt1_cont +| 3904: 65 6e 74 03 43 52 45 41 54 45 20 54 41 42 4c 45 ent.CREATE TABLE +| 3920: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f 't1_content'(do +| 3936: 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d cid INTEGER PRIM +| 3952: 41 52 59 20 4b 45 59 2c 20 27 63 30 61 27 2c 20 ARY KEY, 'c0a', +| 3968: 27 63 31 62 27 2c 20 27 63 32 63 27 29 38 02 06 'c1b', 'c2c')8.. +| 3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52 ...._tablet1t1CR +| 4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB +| 4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33 LE t1 USING fts3 +| 4032: 28 61 2c 62 2c 63 29 00 00 00 00 00 00 00 00 00 (a,b,c)......... +| page 3 offset 8192 +| 0: 0d 00 00 00 25 0b 48 00 0f d8 0f af 0f 86 0f 74 ....%.H........t +| 16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5 .a.N./.......... +| 32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 0d ef 00 00 ...t.[.@.$...... +| 2880: 00 00 00 00 00 00 00 00 81 3f 25 06 00 82 7e f0 .........?%...~. +| 2896: 00 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e .COMPILER=gcc-5. +| 2912: 34 23 00 20 42 30 31 36 2f 36 30 39 20 44 45 42 4#. B016/609 DEB +| 2928: 55 47 20 45 4e 41 42 4c 45 20 44 42 53 54 41 54 UG ENABLE DBSTAT +| 2944: 20 56 54 41 42 20 45 4e 42 92 4c 45 20 46 54 53 VTAB ENB.LE FTS +| 2960: 34 20 45 4e 41 42 4c 45 20 46 54 53 35 20 45 4e 4 ENABLE FTS5 EN +| 2976: 41 42 4c 45 20 47 45 4f 50 4f 4c 59 20 45 4e 41 ABLE GEOPOLY ENA +| 2992: 42 5c 45 1f 4a 53 4f 4e 31 20 45 4e 41 42 4c 45 B.E.JSON1 ENABLE +| 3008: 20 4d 45 4d 53 59 53 35 20 45 4e 41 42 4c 45 20 MEMSYS5 ENABLE +| 3024: 52 54 52 45 45 20 4d 41 58 20 4d 45 4d 4f 52 59 RTREE MAX MEMORY +| 3040: 3d 35 30 30 30 30 30 30 30 20 4f 4d 49 54 20 4c =50000000 OMIT L +| 3056: 4f 41 44 20 45 58 54 45 4e 53 49 4f 4e 20 54 48 OAD EXTENSION TH +| 3072: 52 45 41 44 53 41 46 45 3d 30 18 24 05 00 25 0f READSAFE=0.$..%. +| 3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49 .THREADSAFE=0XBI +| 3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41 NARY.#..%..THREA +| 3120: 44 53 41 46 45 3d 30 88 4e 4f 43 41 53 45 17 22 DSAFE=0.NOCASE.. +| 3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 45 3d ..%..THREADSAFE= +| 3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d 0XRTRIM.!..3..OM +| 3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 4f IT LOAD EXTENSIO +| 3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f NXBINARY. ..3..O +| 3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 MIT LOAD EXTENSI +| 3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17 ONXNOCASE....3.. +| 3232: 4f 4d 49 54 20 4c 4f 41 54 20 45 58 54 45 4e 53 OMIT LOAT EXTENS +| 3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 04 00 33 0f 19 IONXRTRIM....3.. +| 3264: 82 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 30 .AX MEMORY=50000 +| 3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f 000XBINARY....3. +| 3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 .MAX MEMORY=5000 +| 3312: 30 30 30 30 58 4e 4f 43 41 53 45 1e 1c 05 00 33 0000XNOCASE....3 +| 3328: 0f 17 4d 41 58 20 4d 45 4d fa 52 59 3d 35 30 20 ..MAX MEM.RY=50 +| 3344: 30 30 30 30 30 58 52 54 52 49 4d 18 1b 05 00 25 00000XRTRIM....% +| 3360: 0f 19 45 4e 41 42 4c 45 20 52 54 52 45 45 58 42 ..ENABLE RTREEXB +| 3376: 49 4e 41 52 59 18 1a 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3392: 4c 45 20 52 54 52 45 45 58 4e 4f 43 41 53 45 17 LE RTREEXNOCASE. +| 3408: 19 05 00 25 0f 17 45 4e 42 42 4c 45 20 52 54 52 ...%..ENBBLE RTR +| 3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45 EEXRTRIM....)..E +| 3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 58 42 49 NABLE MEMSYS5XBI +| 3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4e 41 42 3c NARY....)..ENAB< +| 3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 53 45 E MEMSYS5XNOCASE +| 3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 4d 45 ....)..ENABLE ME +| 3504: 4d 53 59 53 35 58 52 54 52 49 4d 18 15 05 00 25 MSYS5XRTRIM....% +| 3520: 0f 19 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 58 42 ..ENABLE JSON1XB +| 3536: 49 4e 41 52 59 18 14 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3552: 4c 45 20 4a 53 4f 4e 31 58 4e 4f 43 41 53 45 17 LE JSON1XNOCASE. +| 3568: 13 05 00 25 0f 17 45 4e 41 42 4c 45 20 4a 53 4f ...%..ENABLE JSO +| 3584: 4e 31 58 52 54 52 49 4d 95 12 05 00 29 0f 19 45 N1XRTRIM....)..E +| 3600: 4e 31 42 4c 45 20 47 45 4e 50 4f 4c 59 58 42 49 N1BLE GENPOLYXBI +| 3616: 4e 41 52 59 1a 11 05 00 29 0f 19 45 3e f2 1e 4c NARY....)..E>..L +| 3632: 45 20 47 45 4f 50 4f 4c 59 58 4e 4f 43 41 53 45 E GEOPOLYXNOCASE +| 3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 45 ....)..ENABLE GE +| 3664: 4f 50 4f 4c 59 58 52 54 52 49 4d 17 0f 05 00 23 OPOLYXRTRIM....# +| 3680: 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 58 42 49 ..ENABLE FTS5XBI +| 3696: 4e 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 3c NARY....#..ENAB< +| 3712: 45 20 46 54 53 35 58 4e 4f 43 41 53 45 16 0d 05 E FTS5XNOCASE... +| 3728: 00 23 0f 17 45 4e 41 42 4c 45 20 46 54 53 35 58 .#..ENABLE FTS5X +| 3744: 5d 24 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42 ]$RIM....#..ENAB +| 3760: 4c 45 20 46 54 53 34 58 42 49 4e 41 52 59 17 0b LE FTS4XBINARY.. +| 3776: 05 00 23 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 ..#..ENABLE FTS5 +| 3792: 58 4e 4f 43 40 53 45 16 0a 05 00 23 0f 17 45 4e XNOC@SE....#..EN +| 3808: 41 42 4c 45 20 46 54 53 34 58 52 54 52 49 4d 1e ABLE FTS4XRTRIM. +| 3824: 09 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 52 59 1e TAT VTABXBINARY. +| 3856: 08 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3872: 54 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d TAT VTABXNOCASE. +| 3888: 07 05 00 31 0f 17 45 4e 41 42 4b 45 20 44 42 53 ...1..ENABKE DBS +| 3904: 54 41 54 20 56 53 41 42 58 52 54 62 49 4d 11 06 TAT VSABXRTbIM.. +| 3920: 05 00 17 0f 19 44 45 42 54 47 58 42 49 4e 41 52 .....DEBTGXBINAR +| 3936: 59 11 05 05 00 17 0f 19 44 45 42 55 47 58 4e 4f Y.......DEBUGXNO +| 3952: 43 41 53 45 10 04 05 00 17 0f 17 44 45 42 55 47 CASE.......DEBUG +| 3968: 68 52 54 52 49 4d 27 03 05 00 43 0f 19 43 4f 4d hRTRIM'...C..COM +| 3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20 PILER=gcc-5.4.0 +| 4000: 32 30 31 36 30 36 30 39 58 42 49 4e 41 52 59 27 20160609XBINARY' +| 4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67 ...C..COMPILER=g +| 4032: 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36 30 cc-5.4.0 2016060 +| 4048: 39 58 4f 4f 43 41 53 45 26 01 05 00 43 0f 17 43 9XOOCASE&...C..C +| 4064: 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e OMPILER=gcc-5.4. +| 4080: 30 20 32 30 31 36 30 36 30 39 58 52 54 52 49 4d 0 20160609XRTRIM +| page 4 offset 12288 +| 0: 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| page 5 offset 16384 +| 0: 0d 00 00 00 02 0b a0 00 0c ad 0b a0 00 00 00 00 ................ +| 2976: 82 0a 02 08 08 09 08 08 17 84 06 30 20 32 35 33 ...........0 253 +| 2992: 00 01 30 04 25 06 1b 00 00 08 32 30 31 36 8c 36 ..0.%.....2016.6 +| 3008: 30 39 03 25 07 00 00 01 34 03 25 05 00 00 01 35 09.%....4.%....5 +| 3024: 03 25 04 00 01 07 30 30 30 30 30 30 30 03 25 1a .%....0000000.%. +| 3040: 00 00 08 63 6f 5d 70 69 6c 65 72 03 25 02 00 00 ...co]piler.%... +| 3056: 06 64 62 73 74 61 74 03 25 0a 00 01 04 65 62 75 .dbstat.%....ebu +| 3072: 67 03 25 08 00 00 06 65 6e 61 62 6c 65 09 25 09 g.%....enable.%. +| 3088: 05 04 04 04 04 04 00 01 08 78 74 65 7e 73 69 6f .........xte~sio +| 3104: 6e 03 25 1d 00 00 04 66 74 73 34 03 25 0d 00 03 n.%....fts4.%... +| 3120: 01 35 03 25 0f 00 00 03 67 63 63 03 25 03 00 01 .5.%....gcc.%... +| 3136: 06 65 6f 70 7f 6c 79 03 25 11 00 00 05 6a 73 6f .eop.ly.%....jso +| 3152: 6e 31 03 25 14 00 e8 04 6c 6f 61 64 03 25 1c 00 n1.%....load.%.. +| 3168: 00 03 6d 61 78 03 25 18 00 01 05 65 6d 6f 72 79 ..max.%....emory +| 3184: 03 25 19 00 03 04 73 79 73 35 03 25 15 00 00 04 .%....sys5.%.... +| 3200: 6f 6d 69 74 03 25 1b 00 00 05 72 74 72 65 65 03 omit.%....rtree. +| 3216: 25 17 00 00 0a 74 68 72 65 61 64 73 61 66 65 03 %....threadsafe. +| 3232: 25 1e 00 00 04 76 74 61 62 03 25 0b 00 86 50 01 %....vtab.%...P. +| 3248: 08 08 08 08 08 17 8d 12 30 20 38 33 35 00 01 30 ........0 835..0 +| 3264: 12 01 06 00 01 06 00 01 06 00 1f 03 00 01 03 00 ................ +| 3280: 01 03 00 00 08 32 30 31 36 30 36 30 39 09 01 07 .....20160609... +| 3296: 00 01 07 00 01 07 00 00 01 34 09 01 05 00 01 05 .........4...... +| 3312: 00 01 05 00 00 01 35 09 01 04 00 01 04 00 01 04 ......5......... +| 3328: 00 01 07 30 30 30 30 30 30 30 09 1c 04 00 01 04 ...0000000...... +| 3344: 00 01 04 00 00 06 62 69 6e 61 72 79 3c 03 01 02 ......binary<... +| 3360: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3376: 00 03 01 02 c2 00 03 01 02 02 00 03 01 04 82 00 ................ +| 3392: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 ................ +| 3408: 01 02 02 00 03 01 02 02 00 00 08 63 6f 6d 70 69 ...........compi +| 3424: 6c 65 72 09 01 02 00 01 02 00 01 02 00 00 06 64 ler............d +| 3440: 62 73 74 61 74 09 07 03 00 01 03 00 01 03 00 01 bstat........... +| 3456: 04 65 62 75 67 09 04 02 00 01 02 00 01 02 00 00 .ebug........... +| 3472: 06 65 6e 60 62 6c 65 3f 07 02 00 01 02 92 e1 a4 .en`ble?........ +| 3488: ff fc a2 8c 95 b2 3f 01 01 f0 f1 02 00 57 02 00 ......?......W.. +| 3504: 01 02 00 01 02 00 01 02 00 01 02 00 01 02 10 01 ................ +| 3520: 02 00 01 02 00 01 02 00 01 02 01 01 02 00 01 02 ................ +| 3536: 00 01 02 00 00 f2 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3552: 6e 09 1f 04 00 01 04 00 01 04 00 00 04 66 74 73 n............fts +| 3568: 34 09 0a 03 00 01 03 00 01 03 00 03 01 35 09 0d 4............5.. +| 3584: 03 00 01 03 00 01 03 00 00 03 67 63 63 09 01 03 ..........gcc... +| 3600: 00 01 03 00 01 03 00 01 06 65 5f 70 6f 6c 79 09 .........e_poly. +| 3616: 10 03 00 01 03 00 01 03 00 00 b3 6a 73 6f 6e 31 ...........json1 +| 3632: 09 13 03 00 01 03 00 01 03 00 00 04 6c 6f 61 64 ............load +| 3648: 09 1f 03 00 01 03 00 01 03 00 00 03 6d 61 78 09 ............max. +| 3664: 1c 02 00 01 02 00 01 02 00 01 05 65 6d 6f 72 79 ...........emory +| 3680: 09 1c 03 00 01 03 00 01 03 00 03 04 73 79 73 35 ............sys5 +| 3696: 09 16 03 00 01 03 00 01 03 cc 00 06 6e 6f 63 61 ............noca +| 3712: 73 65 3c 02 01 02 02 00 03 01 02 02 00 03 01 02 se<............. +| 3728: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3744: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3760: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 00 ................ +| 3776: 04 6f 6d 69 74 09 1f 02 00 01 02 00 01 02 00 00 .omit........... +| 3792: 05 72 74 62 65 65 09 19 03 00 01 03 00 01 03 00 .rtbee.......... +| 3808: 03 02 69 6d 3c 01 01 02 02 00 03 01 02 02 00 03 ..im<........... +| 3824: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 ................ +| 3840: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 ................ +| 3856: 02 00 03 01 02 02 00 03 01 02 01 00 03 01 02 02 ................ +| 3872: 00 00 0a 74 68 72 65 61 64 73 61 66 65 09 22 02 ...threadsafe... +| 3888: 00 01 02 00 02 02 00 00 04 76 74 61 62 09 07 04 .........vtab... +| 3904: 00 01 03 00 01 04 00 00 01 78 b4 01 01 01 01 02 .........x...... +| 3920: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 3936: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 3952: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 3968: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 3984: 02 01 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4000: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 4016: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 4032: 01 01 02 00 01 01 01 da 00 00 f1 01 02 00 01 01 ................ +| 4048: 01 02 00 01 01 01 01 ff ff 01 01 02 00 01 01 01 ................ +| 4064: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4080: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| page 6 offset 20480 +| 0: 0a 00 00 00 02 0f f5 00 0f fb 0f f5 01 00 00 00 ................ +| 4080: 00 00 00 00 00 05 04 08 09 01 02 04 04 08 08 09 ................ +| end crash-1cc4f8a70485ce.db +}]} {} + +do_execsql_test 38.1 { + UPDATE t1 SET b=a; +} + +do_catchsql_test 38.2 { + SELECT b FROM t1 WHERE a MATCH 'e*e*e*e*e*e*e*e*e*e*e*e*e*e*e*e*' +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +reset_db +set saved $sqlite_fts3_enable_parentheses +set sqlite_fts3_enable_parentheses 1 +do_execsql_test 39.0 { + CREATE VIRTUAL TABLE t0 USING fts3( + col0 INTEGER PRIMARY KEY, + col1 VARCHAR(8), + col2 BINARY, + col3 BINARY + ); + INSERT INTO t0_content VALUES(1,1,'1234','aaaa','bbbb'); + INSERT INTO t0_segdir VALUES(0,0,0,0,'0 42',X'000131030782000103323334050101010200000461616161050101020200000462626262050101030200'); +} + +do_test 39.1 { + catch { + db eval { SELECT rowid FROM t0 WHERE t0 MATCH '1 NEAR 1' } + } +} 0 + +do_test 39.2 { + catch { + db eval { + SELECT matchinfo(t0,'yxy') FROM t0 WHERE t0 MATCH x'2b0a312b0a312a312a2a0b5d0a0b0b0a312a0a0b0b0a312a0b310a392a0b0a27312a2a0b5d0a312a0b310a31315d0b310a312a316d2a0b313b15bceaa50a312a0b0a27312a2a0b5d0a312a0b310a312b0b2a310a312a0b2a0b2a0b2e5d0a0bff313336e34a2a312a0b0a3c310b0a0b4b4b0b4b2a4bec40322b2a0b310a0a312a0a0a0a0a0a0a0a0a0b310a312a2a2a0b5d0a0b0b0a312a0b310a312a0b0a4e4541530b310a5df5ced70a0a0a0a0a4f520a0a0a0a0a0a0a312a0b0a4e4541520b310a5d616161610a0a0a0a4f520a0a0a0a0a0a312b0a312a312a0a0a0a0a0a0a004a0b0a310b220a0b0a310a4a22310a0b0a7e6fe0e0e030e0e0e0e0e01176e02000e0e0e0e0e01131320226310a0b0a310a4a22310a0b0a310a766f8b8b4ee0e0300ae0090909090909090909090909090909090909090909090909090909090909090947aaaa540b09090909090909090909090909090909090909090909090909090909090909fae0e0f2f22164e0e0f273e07fefefef7d6dfafafafa6d6d6d6d'; + } + } +} 0 +set sqlite_fts3_enable_parentheses $saved + +#------------------------------------------------------------------------- +reset_db +set saved $sqlite_fts3_enable_parentheses +set sqlite_fts3_enable_parentheses 1 + +do_execsql_test 40.1 { + + CREATE VIRTUAL TABLE t0 USING fts3(col0 INTEGER PRIMARY KEY, col1, col2 ,col3 ); + INSERT INTO t0_segdir VALUES(0,0,0,0,'0 42', + X'0001310301020001033233340500010102000004616161bc050101020200000462626262050101030200' + ); +} + +do_execsql_test 40.2 { + SELECT 0==matchinfo(t0,'sx') FROM t0 WHERE t0 MATCH '1* 2 3 4 5 6 OR 1'; +} 0 + +set sqlite_fts3_enable_parentheses $saved + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 41.1 { + CREATE VIRTUAL TABLE t1 USING fts3(a,b,c); + INSERT INTO t1_segdir VALUES(0,0,0,0,'0 835',X'000130120106000106000106001f030001030001030000083230313630363039090107000107000107000001340901050001050001050000013509010400010400010400010730303030303030091c0400010400010400000662696e6172793c0301020200030102020003010202000301020200030102020003010202000301020200030102020003010202000301020200030102020003010202000008636f3870696c657209010200010200010200000664627374617409070300010300010300010465627567090402000102000102000006656e61626c653f07020001020001020001020001020001020001020001020001020001030001010002020001020001020001020001120001020001020001020001020001020001087874656e73696f6e091f0400010400010400000466747334090a0300010300010400030135090d03000103000103000003676363090103000103000103000106656f706f6c790910030001030001030000056a736f6e310913030001030001030000046c6f6164091f030001030001030000036d6178091c02000102000102000105656d6f7279091c03000103000103000304737973350916030001030001030000066e6f636173653c02010202000301020200030102020003010202000301020200030102020003010202000301020200030102020003010202000301020200030102020000046f6d6974091f020001020001020000057274726565091903000103000103000302696d3c010102020003010202000301020200030102020003010202000301020200030102020003010202000301020200030102020003010202000301020200000a746872656164736166650922020001020001020000047674616209070400010400010400000178b401010101020001010102000101010200010101020001010102000101010200010101020001010102000101010200010101020001010102000101010200010101020001010102000101010200010101020001010102000101010200010101020001010102000101010200010101020001010102000101010200010101020001010102000101010200010101020001010102000101010200010101020001010102000101010200010101020001010102000101010200'); +} + +do_execsql_test 41.2 { + SELECT offsets(t1) FROM t1 WHERE t1 MATCH 'rtree ner "json1^enable"'; +} + +#------------------------------------------------------------------------- +do_execsql_test 42.1 { + CREATE VIRTUAL TABLE f USING fts3(a, b); +} +do_execsql_test 42.2 { + INSERT INTO f_segdir VALUES(0,2,1111,0,0,X'00'); + INSERT INTO f_segdir VALUES(0,3,0 ,0,0,X'00013003010200'); +} +do_execsql_test 42.3 { + INSERT INTO f(f) VALUES ('merge=107,2'); +} + +#------------------------------------------------------------------------- +reset_db +set saved $sqlite_fts3_enable_parentheses +set sqlite_fts3_enable_parentheses 1 +do_execsql_test 43.1 { + CREATE VIRTUAL TABLE def USING fts3(xyz); + INSERT INTO def_segdir VALUES(0,0,0,0,0, X'0001310301c9000103323334050d81'); +} {} + +do_execsql_test 43.2 { + SELECT rowid FROM def WHERE def MATCH '1 NEAR 1' +} {1} + +set sqlite_fts3_enable_parentheses $saved + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 44.1 { + CREATE VIRTUAL TABLE t0 USING fts3(col0 INTEGER PRIMARY KEY,col1 VARCHAR(8),col2 BINARY,col3 BINARY); + INSERT INTO t0_content VALUES(0,NULL,NULL,NULL,NULL); + INSERT INTO t0_segdir VALUES(0,0,0,0,'0 42',X'00013103010200010332333405010201ba00000461616161050101020200000462626262050101030200'); +} + +do_execsql_test 44.2 { + SELECT matchinfo(t0, t0) IS NULL FROM t0 WHERE t0 MATCH '1*' +} {0} + +#------------------------------------------------------------------------- +# +reset_db +do_test 45.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +.open --hexdb +| size 24576 pagesize 4096 filename crash-65c98512cc9e49.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 06 .....@ ........ +| 96: 00 00 00 00 0d 0e fc 00 06 0d bc 00 0f ca 0f 6c ...............l +| 112: 0f 04 0e 13 0e c9 0d bc 00 00 00 00 00 00 00 00 ................ +| 3504: 00 00 00 00 00 00 00 00 00 00 00 00 55 06 07 17 ............U... +| 3520: 1b 1b 01 81 01 74 61 62 6c 65 78 31 5f 73 74 61 .....tablex1_sta +| 3536: 74 78 31 5f 73 74 61 74 06 43 52 45 41 54 45 20 tx1_stat.CREATE +| 3552: 54 41 42 4c 45 20 27 78 31 5f 73 74 61 74 27 28 TABLE 'x1_stat'( +| 3568: 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 id INTEGER PRIMA +| 3584: 52 59 20 4b 45 59 2c 20 76 61 6c 75 65 20 42 4c RY KEY, value BL +| 3600: 41 82 29 81 33 04 07 17 1f 1f 01 82 35 74 61 62 A.).3.......5tab +| 3616: 6c 65 78 31 5f 73 65 67 64 69 72 78 31 5f 73 65 lex1_segdirx1_se +| 3632: 67 64 69 72 04 43 52 45 41 54 45 20 54 41 42 4c gdir.CREATE TABL +| 3648: 45 20 27 78 31 5f 73 65 67 64 69 72 27 28 6c 65 E 'x1_segdir'(le +| 3664: 76 65 6c 20 49 4e 54 45 47 45 52 2c 69 64 78 20 vel INTEGER,idx +| 3680: 49 4e 54 45 47 45 52 2c 73 74 61 72 74 5f 62 6c INTEGER,start_bl +| 3696: 6f 63 6b 20 49 4e 54 45 47 45 52 2c 6c 65 61 76 ock INTEGER,leav +| 3712: 65 73 5f 65 6e 64 5f 62 6c 6f 63 6b 20 49 4e 54 es_end_block INT +| 3728: 45 47 45 52 2c 65 6e 64 5f 62 6c 6f 63 6b 20 49 EGER,end_block I +| 3744: 4e 54 45 47 45 52 2c 72 6f 6f 74 20 42 4c 4f 42 NTEGER,root BLOB +| 3760: 2c 50 52 49 4d 41 52 59 20 4b 45 59 28 6c 65 76 ,PRIMARY KEY(lev +| 3776: 65 6c 2c 20 69 64 78 29 29 31 05 06 17 45 1f 01 el, idx))1...E.. +| 3792: 00 69 6e 64 65 78 73 71 6c 69 74 65 5f 61 75 74 .indexsqlite_aut +| 3808: 6f 69 6e 64 65 78 5f 78 31 5f 73 65 67 64 69 72 oindex_x1_segdir +| 3824: 5f 31 78 31 5f 73 65 67 64 69 72 05 00 00 00 08 _1x1_segdir..... +| 3840: 60 00 00 00 66 03 07 17 23 23 01 81 13 74 61 62 `...f...##...tab +| 3856: 6c 65 78 31 5f 73 65 67 6d 65 6e 74 73 78 31 5f lex1_segmentsx1_ +| 3872: 73 65 67 6d 65 6e 74 73 03 43 52 45 41 54 45 20 segments.CREATE +| 3888: 54 41 42 4c 45 20 27 78 31 5f 73 65 67 6d 65 6e TABLE 'x1_segmen +| 3904: 74 73 27 28 62 6c 6f 63 6b 69 64 20 49 4e 54 45 ts'(blockid INTE +| 3920: 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c GER PRIMARY KEY, +| 3936: 20 62 6c 6f 63 6b 20 42 4c 4f 42 29 5c 02 07 17 block BLOB).... +| 3952: 21 21 01 81 03 74 61 62 6c 65 78 31 5f 63 6f 6e !!...tablex1_con +| 3968: 74 65 6e 74 78 31 5f 63 6f 6e 74 65 6e 74 02 43 tentx1_content.C +| 3984: 52 45 41 54 45 20 54 41 42 4c 45 20 27 78 31 5f REATE TABLE 'x1_ +| 4000: 63 6f 6e 74 65 6e 74 27 28 64 6f 63 69 64 20 49 content'(docid I +| 4016: 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b NTEGER PRIMARY K +| 4032: 45 59 2c 20 27 63 30 78 27 29 34 01 06 17 11 11 EY, 'c0x')4..... +| 4048: 08 57 74 61 62 6c 65 78 31 78 31 43 52 45 41 54 .Wtablex1x1CREAT +| 4064: 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 E VIRTUAL TABLE +| 4080: 78 31 20 55 53 49 4e 47 20 66 74 73 33 28 78 29 x1 USING fts3(x) +| page 2 offset 4096 +| 0: 0d 00 00 00 11 0f 77 f0 0f f8 0f f0 0f e8 0f e0 ......w......... +| 16: 0f d8 0f d0 0f c8 0f c0 00 00 00 00 00 00 00 00 ................ +| 3952: 00 00 00 00 00 00 00 00 06 11 03 00 13 77 78 79 .............wxy +| 3968: 06 10 03 00 13 74 75 76 06 0f 03 00 13 71 33 73 .....tuv.....q3s +| 3984: 06 0e 03 00 13 6e 6f 70 06 0d 03 00 13 6b 6c 6d .....nop.....klm +| 4000: 06 0c 03 04 c3 68 69 6a 06 0b 03 00 13 65 66 67 .....hij.....efg +| 4016: 06 0a 03 00 13 62 63 64 06 09 03 00 13 79 7a 61 .....bcd.....yza +| 4032: 06 08 03 00 13 76 77 78 06 07 03 00 13 73 74 75 .....vwx.....stu +| 4048: 06 06 03 00 13 70 71 72 06 05 03 00 13 6d 6e 6f .....pqr.....mno +| 4064: 06 03 03 00 13 6a 6b 6c 06 03 03 00 13 67 68 69 .....jkl.....ghi +| 4080: 06 02 02 00 03 64 65 66 06 01 03 00 13 61 52 63 .....def.....aRc +| page 3 offset 8192 +| 0: 0d 00 00 00 03 0f a7 00 0f b5 0f a7 0f fa 01 00 ................ +| 4000: 00 00 00 00 00 00 00 0c 02 03 00 1e 00 03 6b 6c ..............kl +| 4016: 6d 03 0d 02 00 43 01 04 00 81 0a 00 03 61 62 63 m....C.......abc +| 4032: 03 0b 32 00 00 03 62 63 64 03 0a 02 00 00 03 64 ..2...bcd......d +| 4048: 69 26 03 02 02 00 00 03 65 66 67 03 0b 02 00 00 i&......efg..... +| 4064: 03 67 68 69 03 03 02 00 00 03 68 69 6a 03 0c 02 .ghi......hij... +| 4080: 00 00 03 6a 6a 2c 03 04 02 00 03 81 00 03 00 00 ...jj,.......... +| page 4 offset 12288 +| 0: 0d 0f 3a 00 05 0f 25 00 0f 9e 0f 88 0f 43 0f 25 ..:...%......C.% +| 16: 0f 72 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .r.............. +| 3856: 00 00 00 00 00 00 00 00 00 56 01 08 08 13 1e 03 .........V...... +| 3872: 30 20 39 00 03 13 05 07 08 08 18 08 13 1e 30 20 0 9...........0 +| 3888: 39 00 03 77 78 79 03 11 02 00 0f 6c 00 09 01 08 9..wxy.....l.... +| 3904: 08 15 54 27 04 07 09 01 08 08 15 42 02 30 20 33 ..T'.......B.0 3 +| 3920: 36 00 03 6e 6f 70 03 0e 02 00 00 03 71 72 73 03 6..nop......qrs. +| 3936: 0f 02 00 00 03 74 75 76 03 10 02 00 0f cf b1 06 .....tuv........ +| 3952: 01 08 14 06 07 01 08 09 01 1b 14 02 02 31 32 38 .............128 +| 3968: 20 2d 37 32 10 01 01 6b 14 03 07 09 09 08 08 15 -72...k........ +| 3984: 1e 30 20 33 36 00 03 79 7a 61 03 09 02 00 2f 02 .0 36..yza..../. +| 4000: 07 09 08 08 08 15 54 30 20 33 36 00 03 6d 6e 6f ......T0 36..mno +| 4016: 03 05 02 00 00 03 70 71 72 03 06 02 00 00 03 73 ......pqr......s +| 4032: 74 75 03 07 02 00 00 03 76 77 78 03 08 02 00 00 tu......vwx..... +| 4048: 00 00 4a 08 08 08 15 54 30 20 33 36 00 03 61 62 ..J....T0 36..ab +| 4064: 63 03 01 02 00 00 03 64 65 66 03 02 02 00 00 03 c......def...... +| 4080: 67 68 69 03 03 67 00 00 03 6a 6b 6c 03 04 02 00 ghi..g...jkl.... +| page 5 offset 16384 +| 0: 0a 0f e7 00 05 0f da 00 0f e1 0f fa 0f f4 0f ed ................ +| 16: 0f da 0f 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 4048: 00 00 00 00 00 00 00 1a 01 03 06 04 01 08 01 02 ................ +| 4064: 06 05 04 08 08 01 05 00 00 00 06 01 03 06 04 09 ................ +| 4080: 02 01 02 04 05 04 09 09 01 03 05 04 09 08 01 02 ................ +| page 6 offset 20480 +| 0: 0d 00 10 00 01 0f f9 00 0f f9 00 00 00 00 00 00 ................ +| 4080: 00 00 00 00 00 00 00 00 00 05 01 03 00 10 01 03 ................ +| end crash-65c98512cc9e49.db +}]} {} + +do_catchsql_test 45.2 { + INSERT INTO x1(x1) VALUES( 'merge=1' ) +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +reset_db +set saved $sqlite_fts3_enable_parentheses +set sqlite_fts3_enable_parentheses 1 +do_execsql_test 46.1 { + CREATE VIRTUAL TABLE t0 USING fts3(a INTEGER PRIMARY KEY,b,c,d); + INSERT INTO t0_segdir VALUES(0,0,0,0,'0 42',X'0001310301c9000103323334050d8000f200000461616161050101020200000462626262050101030200'); +} {} + +do_catchsql_test 46.2 { + SELECT * FROM t0 + WHERE t0 MATCH x'2b0a312b0a312a312a2a0b5d0a0b0b0a312a0a0b0b0a312a0b310a392a0b0a27312a2a0b5d0a312a0b310a31315d0b310a312a316d2a0b313b15bceaa50a312a0b0a27312a2a0b5d0a312a0b310a312b0b2a310a312a0b2a0b2a0b2e5d0a0bff313336e34a2a312a0b0a3c310b0a0b4b4b0b4b2a4bec40322b2a0b310a0a312a0a0a0a0a0a0a0a0a0b310a312a2a2a0b5d0a0b0b0a312a0b310a312a0b0a4e4541530b310a5df5ced70a0a0a0a0a4f520a0a0a0a0a0a0a312a0b0a4e4541520b310a5d616161610a0a0a0a4f520a0a0a0a0a0a312b0a312a312a0a0a0a0a0a0a004a0b0a310b220a0b0a310a4a22310a0b0a7e6fe0e0e030e0e0e0e0e01176e02000e0e0e0e0e01131320226310a0b0a310a4a22310a0b0a310a766f8b8b4ee0e0300ae0090909090909090909090909090909090909090909090909090909090909090947aaaa540b09090909090909090909090909090909090909090909090909090909090909fae0e0f2f22164e0e0f273e07fefefef7d6dfafafafa6d6d6d6d'; +} {1 {database disk image is malformed}} + +set sqlite_fts3_enable_parentheses $saved +extra_schema_checks 1 + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 47.1 { + CREATE VIRTUAL TABLE t1 USING fts3(a,b,c); +} +do_execsql_test 47.2 { + INSERT INTO t1_segdir VALUES(0,0,0,0,0,X'000130120106000106000106001f030001030001030000083230313630363039090107000107000107000001340901050001050001050000013509010400010400010400010730303030303030091c0400010400010400000662696e6172793c0301020200030102020003010202000301020200030102020003010202000301020200030102020003010202000301020200030102020003010202000008636f6d70696c657209010200010200010200000664627374617409070300010300010300010465627567090402000102000102000006656e61626c653f07020001020001020001020001020001020001020001020001020001020001020001020001010001020001020001020001020001020001020001020001020001087874656e73696f6e091f0400010400010400000466747334090a0300010300010300030135090d03000103000103000003676363090103000103000103000106656f706f6c790910030001030001030000056a736f6e310913030001030001030000046c6f6164091f030001030001030000036d6178091c02000102000102000105656d6f7279091c03000103000103000304737973350916030001030001030000066e6f636173653c02010202000301020200030102020003010202000301020200030102020003010202000301020200030102020003010202000301020200030102020000046f6d6974091f020001020001020000057274726565091903000103000103000302696d3c01010202000301020200030102020003010202000301020200030102020003010202000301a202000301020200030102020003010202000301020200000a746872656164736166650922020001020001020000047674616209070400010400010400000178b401010101020001010102000101010200010101020001010102000101010200010101020001010102000101010200010101020001010102000101010200010101020001010102000101010200010101020001010102000101010200010101020001010102000101010200010101020001010102000101010200010101020001010102000101010200010101020001010102000101010200010101020001010102000101010200010101020001010102000101010200'); + INSERT INTO t1_segdir VALUES(0,1,0,0,0,X'0001300425061b000008323031363036303903250700000134032505000001350325040001073030303030303003251a000008636f6d70696c657203250200000664627374617403250a00010465627567032508000006656e61626c650925090504040404040001087874656e73696f6e03251d0000046674733403250d0003013503250f000003676363032503000106656f706f6c790325110000056a736f6e310325130000046c6f616403251c0000036d6178032518000105656d6f7279032519000304737973350325150000046f6d697403251b000005727472656503251700000a7468726561647361666503251e0000047674616333250b00'); +} + +do_catchsql_test 47.3 { + SELECT matchinfo(t1) FROM t1 WHERE t1 MATCH '"json1 enable"'; +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +# +reset_db +do_test 48.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +.open --hexdb +| size 20480 pagesize 4096 filename sql038051.txt.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 00 .....@ ........ +| 96: 00 00 00 00 0d 0e fc 00 05 0e 13 00 0f ca 0f 6c ...............l +| 112: 0f 04 0e 13 0e c9 00 00 00 00 00 00 00 00 00 00 ................ +| 3600: 00 00 00 81 33 04 07 17 1f 1f 01 82 35 74 61 62 ....3.......5tab +| 3616: 6c 65 78 31 5f 73 65 67 64 69 72 78 31 5f 73 65 lex1_segdirx1_se +| 3632: 67 64 69 72 04 43 52 45 41 54 45 20 54 41 42 4c gdir.CREATE TABL +| 3648: 45 20 27 78 31 5f 73 65 67 64 69 72 27 28 6c 65 E 'x1_segdir'(le +| 3664: 76 65 6c 20 49 4e 54 45 47 45 52 2c 69 64 78 20 vel INTEGER,idx +| 3680: 49 4e 54 45 47 45 52 2c 73 74 61 72 74 5f 62 6c INTEGER,start_bl +| 3696: 6f 63 6b 20 49 4e 54 45 47 45 52 2c 6c 65 61 76 ock INTEGER,leav +| 3712: 65 73 5f 65 6e 64 5f 62 6c 6f 63 6b 20 49 4e 54 es_end_block INT +| 3728: 45 47 45 52 2c 65 6e 64 5f 62 6c 6f 63 6b 20 49 EGER,end_block I +| 3744: 4e 54 45 47 45 52 2c 72 6f 6f 74 20 42 4c 4f 42 NTEGER,root BLOB +| 3760: 2c 50 52 49 4d 41 52 59 20 4b 45 59 28 6c 65 76 ,PRIMARY KEY(lev +| 3776: 65 6c 2c 20 69 64 78 29 29 31 05 06 17 45 1f 01 el, idx))1...E.. +| 3792: 00 69 6e 64 65 78 73 71 6c 69 74 65 5f 61 75 74 .indexsqlite_aut +| 3808: 6f 69 6e 64 65 78 5f 78 31 5f 73 65 67 64 69 72 oindex_x1_segdir +| 3824: 5f 31 78 31 5f 73 65 67 64 69 72 05 00 00 00 08 _1x1_segdir..... +| 3840: 00 00 00 00 66 03 07 17 23 23 01 81 13 74 61 62 ....f...##...tab +| 3856: 6c 65 78 31 5f 73 65 67 6d 65 6e 74 73 78 31 5f lex1_segmentsx1_ +| 3872: 73 65 67 6d 65 6e 74 73 03 43 52 45 41 54 45 20 segments.CREATE +| 3888: 54 41 42 4c 45 20 27 78 31 5f 73 65 67 6d 65 6e TABLE 'x1_segmen +| 3904: 74 73 27 28 62 6c 6f 63 6b 69 64 20 49 4e 54 45 ts'(blockid INTE +| 3920: 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c GER PRIMARY KEY, +| 3936: 20 62 6c 6f 63 6b 20 42 4c 4f 42 29 5c 02 07 17 block BLOB).... +| 3952: 21 21 01 81 03 74 61 62 6c 65 78 31 5f 63 6f 6e !!...tablex1_con +| 3968: 74 65 6e 74 78 31 5f 63 6f 6e 74 65 6e 74 02 43 tentx1_content.C +| 3984: 52 45 41 54 45 20 54 41 42 4c 45 20 27 78 31 5f REATE TABLE 'x1_ +| 4000: 63 6f 6e 74 65 6e 74 27 28 64 6f 63 69 64 20 49 content'(docid I +| 4016: 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b NTEGER PRIMARY K +| 4032: 45 59 2c 20 27 63 30 78 27 29 34 01 06 17 11 11 EY, 'c0x')4..... +| 4048: 08 57 74 61 62 6c 65 78 31 78 31 43 52 45 41 54 .Wtablex1x1CREAT +| 4064: 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 E VIRTUAL TABLE +| 4080: 78 31 20 55 53 49 4e 47 20 66 74 73 33 28 78 29 x1 USING fts3(x) +| page 2 offset 4096 +| 0: 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 3920: 00 00 00 2e 04 03 00 63 62 72 61 69 6e 73 74 65 .......cbrainste +| 3936: 6d 20 62 72 61 69 6e 73 74 65 6d 73 20 62 72 61 m brainstems bra +| 3952: 69 6e 73 74 6f 72 6d 20 62 72 61 69 6e 73 74 6f instorm brainsto +| 3968: 72 6d 73 2b 03 03 00 5d 62 72 61 69 6e 20 62 72 rms+...]brain br +| 3984: 61 69 6e 63 68 69 6c 64 20 62 72 61 69 6e 65 64 ainchild brained +| 4000: 20 62 72 61 69 6e 69 6e 67 20 62 72 61 69 6e 73 braining brains +| 4016: 26 02 03 00 53 62 72 61 67 73 20 62 72 61 69 64 &...Sbrags braid +| 4032: 20 62 72 61 69 64 65 64 20 62 72 61 69 64 69 6e braided braidin +| 4048: 67 20 62 72 61 69 64 73 26 01 03 00 53 62 72 61 g braids&...Sbra +| 4064: 65 73 20 62 72 61 67 20 62 72 61 67 67 65 64 20 es brag bragged +| 4080: 62 72 61 c3 67 65 72 20 62 72 61 67 67 69 6e 67 bra.ger bragging +| page 3 offset 8192 +| 0: 0d 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 ................ +| page 4 offset 12288 +| 0: 0d 00 00 00 04 0f 20 00 0f c8 0f 90 0f 54 0f 20 ...... ......T. +| 3872: 32 04 07 08 01 08 08 15 58 03 30 20 33 38 00 09 2.......X.0 38.. +| 3888: 62 72 61 69 6e 73 74 65 6d 03 04 02 00 09 01 73 brainstem......s +| 3904: 03 04 03 00 07 03 6f 72 6d 03 04 04 00 0a 01 73 ......orm......s +| 3920: 03 04 05 00 3a 03 07 08 01 08 08 15 68 02 30 20 ....:.......h.0 +| 3936: 34 36 00 05 62 72 61 69 6e 03 03 02 00 05 05 63 46..brain......c +| 3952: 68 69 6c 64 03 03 03 00 05 02 65 64 03 03 04 00 hild......ed.... +| 3968: 05 03 69 6e 67 03 03 05 00 05 01 73 03 03 06 00 ..ing......s.... +| 3984: 36 02 07 08 09 08 08 15 62 30 20 34 33 00 05 62 6.......b0 43..b +| 4000: 72 61 67 73 03 02 02 00 03 02 69 64 03 02 03 00 rags......id.... +| 4016: 05 02 65 64 03 02 04 00 05 03 69 6e 67 03 02 05 ..ed......ing... +| 4032: 00 05 01 73 03 02 06 00 36 01 07 08 08 08 08 15 ...s....6....... +| 4048: 62 30 20 34 33 00 05 62 72 61 65 73 03 01 02 00 b0 43..braes.... +| 4064: 03 01 68 03 01 03 00 04 03 67 65 74 03 01 04 00 ..h......get.... +| 4080: 06 01 72 03 01 05 00 05 03 69 6e 67 03 01 06 00 ..r......ing.... +| page 5 offset 16384 +| 0: 0a 00 00 00 04 0f e7 00 0f fb 0f f5 0f ee 0f e7 ................ +| 4064: 00 00 00 00 00 00 00 06 04 08 01 01 03 04 06 04 ................ +| 4080: 08 01 01 02 03 05 04 08 09 01 02 04 04 08 08 09 ................ +| end sql038051.txt.db +}]} {} + +do_catchsql_test 48.1 { + INSERT INTO x1(x1) VALUES('nodesize=24'),('merge=3,4'); + INSERT INTO x1(x1) VALUES( 'merge=3,4' ),('merge=3,4'); +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +# +reset_db +do_test 49.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +.open --hexdb +| size 28672 pagesize 4096 filename crash-58821b8eae6883.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07 .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 04 ................ +| 96: 00 00 00 00 0d 0e ef 00 07 0d 4d 00 0f bd 0f 5f ..........M...._ +| 112: 0e f7 0e 06 0e bc 0d a4 0d 4d 00 00 00 00 00 00 .........M...... +| 3392: 00 00 00 00 00 00 00 00 00 00 00 00 00 55 07 07 .............U.. +| 3408: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 73 74 ......tablet1_st +| 3424: 61 74 74 31 5f 73 74 61 74 07 43 52 45 41 54 45 att1_stat.CREATE +| 3440: 20 54 41 42 4c 45 20 27 74 31 5f 73 74 61 74 27 TABLE 't1_stat' +| 3456: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d (id INTEGER PRIM +| 3472: 41 52 59 20 4b 45 59 2c 20 76 61 6c 75 65 20 42 ARY KEY, value B +| 3488: 4c 4f 42 29 60 06 07 17 21 21 01 81 0b 74 61 62 LOB)`...!!...tab +| 3504: 6c 65 74 31 5f 64 6f 63 73 69 7a 65 74 31 5f 64 let1_docsizet1_d +| 3520: 6f 63 73 69 7a 65 06 43 52 45 41 54 45 20 54 41 ocsize.CREATE TA +| 3536: 42 4c 45 20 27 74 31 5f 64 6f 63 73 69 7a 65 27 BLE 't1_docsize' +| 3552: 28 64 6f 63 69 64 20 49 4e 54 45 47 45 52 20 50 (docid INTEGER P +| 3568: 52 49 4d 41 52 59 20 4b 45 59 2c 20 73 69 7a 65 RIMARY KEY, size +| 3584: 20 42 4c 4f 42 29 81 33 04 07 17 1f 1f 01 82 35 BLOB).3.......5 +| 3600: 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72 74 31 tablet1_segdirt1 +| 3616: 5f 73 65 67 64 69 72 04 43 52 45 41 54 45 20 54 _segdir.CREATE T +| 3632: 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69 72 27 ABLE 't1_segdir' +| 3648: 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52 2c 69 (level INTEGER,i +| 3664: 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61 72 74 dx INTEGER,start +| 3680: 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52 2c 6c _block INTEGER,l +| 3696: 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 6b 20 eaves_end_block +| 3712: 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c 6f 63 INTEGER,end_bloc +| 3728: 6b 20 49 4e 54 45 47 45 52 2c 72 6f 6f 74 20 42 k INTEGER,root B +| 3744: 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45 59 28 LOB,PRIMARY KEY( +| 3760: 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 05 06 17 level, idx))1... +| 3776: 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74 65 5f E...indexsqlite_ +| 3792: 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73 65 67 autoindex_t1_seg +| 3808: 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72 05 00 dir_1t1_segdir.. +| 3824: 00 00 08 00 00 00 00 66 03 07 17 23 23 01 81 13 .......f...##... +| 3840: 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e 74 73 tablet1_segments +| 3856: 74 31 5f 73 65 67 6d 65 6e 74 73 03 43 52 45 41 t1_segments.CREA +| 3872: 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 TE TABLE 't1_seg +| 3888: 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64 20 49 ments'(blockid I +| 3904: 4e 54 45 47 45 52 20 f9 52 49 4d 41 52 59 20 4b NTEGER .RIMARY K +| 3920: 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 29 5c EY, block BLOB). +| 3936: 02 07 17 21 21 01 81 03 74 61 62 6c 65 74 31 5f ...!!...tablet1_ +| 3952: 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 65 6e contentt1_conten +| 3968: 74 02 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 t.CREATE TABLE ' +| 3984: 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f 63 69 t1_content'(doci +| 4000: 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 d INTEGER PRIMAR +| 4016: 59 20 4b 45 59 2c 20 27 63 30 61 27 29 41 01 06 Y KEY, 'c0a')A.. +| 4032: 17 11 11 08 71 74 61 62 6c 65 74 31 74 31 43 52 ....qtablet1t1CR +| 4048: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB +| 4064: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 34 LE t1 USING fts4 +| 4080: 28 61 2c 70 72 65 66 69 78 3d 27 32 2c 32 27 29 (a,prefix='2,2') +| page 2 offset 4096 +| 0: 0d 00 00 00 08 0e 1f 00 0f c4 0f 7c 0f 34 0f 07 ...........|.4.. +| 16: 0e c3 0e 97 0e 00 00 00 00 00 00 00 00 00 00 00 ................ +| 3600: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 42 ...............B +| 3616: 08 04 00 81 09 73 75 6e 74 20 69 6e 20 63 75 6c .....sunt in cul +| 3632: 70 61 20 71 75 69 20 6f 66 66 69 63 69 61 20 64 pa qui officia d +| 3648: 65 73 65 72 75 6e 74 20 6d 6f 6c 6c 69 74 20 61 eserunt mollit a +| 3664: 6e 69 6d 20 69 64 20 65 73 74 20 6c 61 62 6f 72 nim id est labor +| 3680: 75 6d 2e 32 07 03 00 6b 45 78 63 65 70 74 65 75 um.2...kExcepteu +| 3696: 72 20 73 69 6e 74 20 6f 63 63 61 65 63 61 74 20 r sint occaecat +| 3712: 63 75 70 69 64 61 74 61 74 20 6e 6f 6e 20 70 72 cupidatat non pr +| 3728: 6f 69 64 65 6e 74 2c 2a 06 03 00 5b 63 69 6c 6c oident,*...[cill +| 3744: 75 6d 20 64 6f 6c 6f 72 65 20 65 75 20 66 75 67 um dolore eu fug +| 3760: 69 61 74 20 6e 75 6c 6c 61 20 70 61 72 69 61 74 iat nulla pariat +| 3776: 75 72 2e 42 05 04 00 81 09 44 75 69 73 20 61 75 ur.B.....Duis au +| 3792: 74 65 20 69 72 75 72 65 20 64 6f 6c 6f 72 20 69 te irure dolor i +| 3808: 6e 20 72 65 70 72 65 68 65 6e 64 65 72 69 74 20 n reprehenderit +| 3824: 69 6e 20 76 6f 6c 75 70 74 61 74 65 20 76 65 6c in voluptate vel +| 3840: 69 74 20 65 73 73 65 2b 04 03 00 5d 6e 69 73 69 it esse+...]nisi +| 3856: 20 75 74 20 61 6c 69 71 75 69 70 20 65 78 20 65 ut aliquip ex e +| 3872: 61 20 63 6f 6d 6d 6f 64 6f 20 63 6f 6e 73 65 71 a commodo conseq +| 3888: 75 61 74 2e 46 03 04 00 81 11 55 74 20 65 6e 69 uat.F.....Ut eni +| 3904: 6d 20 61 64 20 6d 69 6e 69 6d 20 76 65 6e 69 61 m ad minim venia +| 3920: 6d 2c 20 71 75 69 73 20 6e 6f 73 74 72 75 64 20 m, quis nostrud +| 3936: 65 78 65 72 63 69 74 61 74 69 6f 6e 20 75 6c 6c exercitation ull +| 3952: 61 6d 63 6f 20 6c 61 62 6f 72 69 73 46 02 04 00 amco laborisF... +| 3968: 81 11 73 65 64 20 64 6f 20 65 69 75 73 6d 6f 64 ..sed do eiusmod +| 3984: 20 74 65 6d 70 6f 72 20 69 6e 63 69 64 69 64 75 tempor incididu +| 4000: 6e 74 20 75 74 20 6c 61 62 6f 72 65 20 65 74 20 nt ut labore et +| 4016: 64 6f 6c 6f 72 65 20 6d 61 67 6e 61 20 61 6c 69 dolore magna ali +| 4032: 71 75 61 2e 3a 01 03 00 7b 4c 6f 72 65 6d 20 69 qua.:....Lorem i +| 4048: 70 73 75 6d 20 64 6f 6c 6f 72 20 73 69 74 20 61 psum dolor sit a +| 4064: 6d 65 74 2c 20 63 6f 6e 73 65 63 74 65 74 75 72 met, consectetur +| 4080: 20 61 64 69 70 69 73 63 69 6e 67 20 65 00 01 00 adipiscing e... +| page 4 offset 12288 +| 0: 0d 00 00 00 03 0a a6 00 0d 57 0c 4a 0a a6 00 00 .........W.J.... +| 2720: 00 00 00 00 00 00 83 21 03 08 02 08 08 08 17 86 .......!........ +| 2736: 30 08 00 30 20 34 30 32 00 02 61 64 06 01 08 00 0..0 402..ad.... +| 2752: 02 04 00 01 01 6c 06 02 0c 00 02 04 00 01 01 6d .....l.........m +| 2768: 03 01 06 00 01 01 6e 03 08 09 00 01 01 75 03 05 ......n......u.. +| 2784: 03 00 00 02 63 69 03 06 02 00 01 01 6f 07 01 07 ....ci......o... +| 2800: 00 03 07 03 00 01 01 75 06 07 05 00 01 04 00 00 .......u........ +| 2816: 02 64 65 03 08 07 00 01 01 6f 0d 01 04 00 01 03 .de......o...... +| 2832: 09 00 03 05 00 01 03 00 01 01 75 03 05 02 00 00 ..........u..... +| 2848: 02 65 61 03 04 06 00 01 01 69 03 02 04 00 01 01 .ea......i...... +| 2864: 6c 03 01 09 00 01 01 6e 03 03 03 00 01 01 73 06 l......n......s. +| 2880: 05 0b 00 03 0b 00 01 01 74 03 02 09 00 01 01 75 ........t......u +| 2896: 03 06 04 00 01 01 78 09 03 09 00 01 05 00 03 02 ......x......... +| 2912: 00 00 02 66 75 03 06 05 00 00 02 69 64 03 08 0a ...fu......id... +| 2928: 00 01 01 6e 0a 02 06 00 03 06 04 00 03 03 00 01 ...n............ +| 2944: 01 70 03 01 03 00 01 01 72 03 05 04 00 00 02 6c .p......r......l +| 2960: 61 09 02 08 00 01 0b 00 05 0c 00 01 01 6f 03 01 a............o.. +| 2976: 02 00 00 02 6d 61 03 02 0b 00 01 01 69 03 03 05 ....ma......i... +| 2992: 00 01 01 6f 03 08 08 00 00 02 6e 69 03 04 02 00 ...o......ni.... +| 3008: 01 01 6f 06 03 08 00 04 06 00 01 01 75 03 06 06 ..o.........u... +| 3024: 00 00 02 6f 63 03 07 04 00 01 01 66 03 08 06 00 ...oc......f.... +| 3040: 00 02 70 61 03 06 07 00 01 01 72 03 07 07 00 00 ..pa......r..... +| 3056: 02 71 75 06 03 07 00 05 05 00 00 02 72 65 03 05 .qu.........re.. +| 3072: 07 00 00 02 73 65 03 02 02 00 01 01 69 06 01 05 ....se......i... +| 3088: 00 06 03 00 01 01 75 03 08 02 00 00 02 74 65 03 ......u......te. +| 3104: 02 05 00 00 02 75 6c 03 03 0a 00 01 01 74 09 02 .....ul......t.. +| 3120: 07 00 01 02 00 01 03 00 00 02 76 65 06 03 06 00 ..........ve.... +| 3136: 02 0a 00 01 01 6f 03 05 09 00 82 0a 02 08 02 08 .....o.......... +| 3152: 08 08 17 84 02 04 00 30 20 32 35 31 00 01 61 13 .......0 251..a. +| 3168: 01 06 04 00 01 0c 00 01 04 00 01 04 00 01 03 00 ................ +| 3184: 03 09 00 00 01 63 10 01 07 00 03 07 03 00 02 02 .....c.......... +| 3200: 00 01 05 00 01 04 00 00 01 64 11 01 04 00 01 03 .........d...... +| 3216: 09 00 03 02 05 00 01 03 00 02 07 00 00 01 65 1b ..............e. +| 3232: 01 09 00 01 04 07 00 01 03 08 00 01 05 03 00 01 ................ +| 3248: 0b 00 01 04 00 01 02 00 01 0b 00 00 01 66 03 06 .............f.. +| 3264: 05 00 00 01 69 0f 01 03 00 01 06 00 03 04 04 04 ....i........... +| 3280: 00 03 03 09 00 00 01 6c 0c 01 02 00 01 08 00 01 .......l........ +| 3296: 0b 00 05 0c 00 00 01 6d 09 02 0b 00 01 05 00 05 .......m........ +| 3312: 08 00 00 01 6e 0c 03 08 00 01 02 00 02 06 00 01 ....n........... +| 3328: 06 00 00 01 6f 06 07 04 00 01 06 00 00 01 70 06 ....o.........p. +| 3344: 06 07 00 01 07 00 00 01 71 06 03 07 00 05 05 00 ........q....... +| 3360: 00 01 72 03 05 07 00 00 01 73 0c 01 05 00 01 02 ..r......s...... +| 3376: 00 05 03 00 01 02 00 00 01 74 03 02 05 00 00 01 .........t...... +| 3392: 75 0a 02 07 00 01 02 0a 00 01 03 00 00 01 76 07 u.............v. +| 3408: 03 06 00 02 09 03 00 85 26 01 08 08 08 08 08 17 ........&....... +| 3424: 8a 3e 30 20 36 36 35 00 02 61 65 03 03 04 00 02 .>0 665..ae..... +| 3440: 08 69 70 69 73 63 69 6e 67 03 01 08 00 01 05 6c .ipiscing......l +| 3456: 69 71 75 61 03 02 0c 00 05 02 69 70 03 04 04 00 iqua......ip.... +| 3472: 01 03 6d 65 74 03 01 06 00 01 03 6e 69 6d 03 08 ..met......nim.. +| 3488: 09 00 01 03 75 74 65 03 05 03 00 00 06 63 69 6c ....ute......cil +| 3504: 6c 75 6d 03 06 02 00 01 06 6f 6d 6d 6f 64 6f 03 lum......ommodo. +| 3520: 04 07 00 02 09 6e 73 65 63 74 65 74 b5 72 03 01 .....nsectet.r.. +| 3536: 07 00 05 04 71 75 61 74 03 04 08 00 01 04 75 6c ....quat......ul +| 3552: 70 61 03 08 04 00 02 07 70 69 64 61 74 61 74 03 pa......pidatat. +| 3568: 07 05 00 00 08 64 65 73 65 72 75 6e 74 03 08 07 .....deserunt... +| 3584: 00 01 01 6f 03 02 03 00 02 03 6c 6f 72 06 01 04 ...o......lor... +| 3600: 00 04 05 00 05 01 65 06 02 0a 00 04 03 00 01 03 ......e......... +| 3616: 75 69 73 03 05 02 00 00 02 65 61 03 04 06 00 01 uis......ea..... +| 3632: 06 69 75 73 6d 6f 64 03 02 04 00 01 03 6c 69 74 .iusmod......lit +| 3648: 03 01 09 00 01 03 6e 69 6d 03 03 03 00 01 03 73 ......nim......s +| 3664: 73 65 03 05 0b 00 02 01 74 03 08 0b 00 01 01 74 se......t......t +| 3680: 03 02 09 00 01 01 75 03 06 04 00 01 01 78 03 04 ......u......x.. +| 3696: 05 00 02 07 63 65 70 74 65 75 72 03 07 02 00 02 ....cepteur..... +| 3712: 0a 65 72 63 69 74 61 74 69 6f 6e 03 03 09 00 00 .ercitation..... +| 3728: 06 66 75 67 69 61 74 03 06 05 00 00 02 69 64 03 .fugiat......id. +| 3744: 08 0a 00 01 01 6e 07 05 06 04 00 03 03 00 02 08 .....n.......... +| 3760: 63 69 64 69 64 75 6e 74 03 02 06 00 01 04 70 73 cididunt......ps +| 3776: 75 6d 03 01 03 00 01 04 72 75 72 65 03 05 04 00 um......rure.... +| 3792: 00 06 6c 61 62 6f 72 65 03 02 08 00 05 02 69 73 ..labore......is +| 3808: 03 03 0b 00 05 02 75 6d 03 08 0c 00 01 04 6f 72 ......um......or +| 3824: 65 6d 03 01 02 00 00 05 6d 61 67 6e 61 03 02 0b em......magna... +| 3840: 00 01 04 69 6e 69 6d 03 03 05 00 01 05 6f 6c 6c ...inim......oll +| 3856: 69 74 03 08 08 00 00 04 6e 69 73 69 03 04 02 00 it......nisi.... +| 3872: 01 02 6f 6e 03 07 06 00 02 05 73 74 72 75 64 03 ..on......strud. +| 3888: 03 08 00 01 04 75 6c 6c 61 03 06 06 00 00 08 6f .....ulla......o +| 3904: 63 63 61 65 63 61 74 03 07 04 00 01 06 66 66 69 ccaecat......ffi +| 3920: 63 69 61 03 08 06 00 00 08 70 61 72 69 61 74 75 cia......pariatu +| 3936: 72 03 06 07 00 01 07 72 6f 69 64 65 6e 74 03 07 r......roident.. +| 3952: 07 00 00 03 71 75 69 03 08 05 00 03 01 73 03 03 ....qui......s.. +| 3968: 07 00 00 0d 72 65 70 72 65 68 65 6e 64 65 72 69 ....reprehenderi +| 3984: 74 03 05 07 00 00 03 73 65 64 03 02 02 00 01 03 t......sed...... +| 4000: 69 6e 74 03 07 03 00 02 01 74 03 01 05 00 01 03 int......t...... +| 4016: 75 6e 74 03 08 02 00 00 06 74 65 6d 70 6f 72 03 unt......tempor. +| 4032: 02 05 00 00 07 75 6c 6c 61 6d 63 6f 03 03 0a 00 .....ullamco.... +| 4048: 01 01 74 09 02 07 00 01 02 00 01 03 00 00 05 76 ..t............v +| 4064: 65 6c 69 74 03 05 0a 00 02 04 6e 69 61 6d 03 03 elit......niam.. +| 4080: 06 00 01 08 6f 6c 75 70 74 61 74 65 03 05 09 00 ....oluptate.... +| page 5 offset 16384 +| 0: 0a 00 00 00 03 0f eb 00 0f fb 0f f3 0f eb 00 00 ................ +| 4064: 00 00 00 00 00 00 00 00 00 00 00 07 04 02 08 01 ................ +| 4080: 08 00 03 07 04 02 08 01 04 00 02 04 04 08 08 09 ................ +| page 6 offset 20480 +| 0: 0d 00 00 00 08 0f d0 00 0f fa 0f f4 0f ee 0f e8 ................ +| 16: 0f e2 0f dc 0f d6 0f d0 00 00 00 00 00 00 00 00 ................ +| 4048: 04 08 03 00 0e 0b 04 07 03 00 0e 06 04 06 03 00 ................ +| 4064: 0e 06 04 05 03 00 0e 0a 04 04 03 00 0e 07 04 03 ................ +| 4080: 03 00 0e 0a 04 02 03 00 0e 0b 04 01 03 00 0e 08 ................ +| page 7 offset 24576 +| 0: 0d 00 00 00 01 0f f7 00 0f f7 00 00 00 00 01 00 ................ +| 4080: 00 00 00 00 00 00 00 07 00 03 00 14 08 45 b5 03 .............E.. +| end crash-58821b8eae6883.db +}]} {} + +do_catchsql_test 49.1 { + SAVEPOINT one; + DELETE FROM t1 WHERE t1 MATCH 'c*'; + SELECT matchinfo(t1,'pcx') IS NULL FROM t1 WHERE t1 MATCH 'f*e*'; +} {0 0} + +#------------------------------------------------------------------------- +# +reset_db +do_test 50.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +.open --hexdb +| size 28672 pagesize 4096 filename crash-14ab65782c9c45.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07 .....@ ........ +| 32: 00 00 00 02 00 00 00 01 00 00 00 00 00 00 00 00 ................ +| 96: 00 00 00 00 0d 0e b1 00 06 0d a4 00 0f 8d 0f 21 ...............! +| 112: 0e b9 0d c8 0e 7e 0d a4 00 00 00 00 00 00 00 00 .....~.......... +| 3488: 00 00 00 00 22 07 06 17 11 11 01 31 74 61 62 6c ...........1tabl +| 3504: 65 74 32 74 32 07 43 52 45 41 54 45 20 54 41 42 et2t2.CREATE TAB +| 3520: 4c 45 20 74 32 28 78 29 81 33 05 07 17 1f 1f 01 LE t2(x).3...... +| 3536: 82 35 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72 .5tablet1_segdir +| 3552: 74 31 5f 73 65 67 64 69 72 05 43 52 45 41 54 45 t1_segdir.CREATE +| 3568: 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69 TABLE 't1_segdi +| 3584: 72 27 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52 r'(level INTEGER +| 3600: 2c 69 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61 ,idx INTEGER,sta +| 3616: 72 74 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52 rt_block INTEGER +| 3632: 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 ,leaves_end_bloc +| 3648: 6b 20 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c k INTEGER,end_bl +| 3664: 6f 63 6b 20 49 4e 54 45 47 45 52 2c 72 6f 6f 74 ock INTEGER,root +| 3680: 20 42 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45 BLOB,PRIMARY KE +| 3696: 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 06 Y(level, idx))1. +| 3712: 06 17 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74 ..E...indexsqlit +| 3728: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73 e_autoindex_t1_s +| 3744: 65 67 64 69 72 5f 31 74 31 5f 73 65 68 64 69 72 egdir_1t1_sehdir +| 3760: 06 0f c7 00 08 00 00 00 00 66 04 07 17 23 23 01 .........f...##. +| 3776: 81 13 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e ..tablet1_segmen +| 3792: 74 73 74 31 5f 73 65 67 6d 65 6e 74 73 04 43 52 tst1_segments.CR +| 3808: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 EATE TABLE 't1_s +| 3824: 65 67 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64 egments'(blockid +| 3840: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 INTEGER PRIMARY +| 3856: 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 KEY, block BLOB +| 3872: 29 6a 03 07 17 21 21 01 81 1f 74 61 62 6c 65 74 )j...!!...tablet +| 3888: 31 5f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 1_contentt1_cont +| 3904: 65 6e 74 03 43 52 45 41 54 45 20 54 41 42 4c 45 ent.CREATE TABLE +| 3920: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f 't1_content'(do +| 3936: 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d cid INTEGER PRIM +| 3952: 41 52 59 20 4b 45 59 2c 20 27 63 30 61 27 2c 20 ARY KEY, 'c0a', +| 3968: 27 62 31 62 27 2c 20 27 63 32 63 27 29 38 02 06 'b1b', 'c2c')8.. +| 3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52 ...._tablet1t1CR +| 4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB +| 4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33 LE t1 USING fts3 +| 4032: 28 61 2c 62 2c 63 29 00 00 00 00 00 00 00 00 00 (a,b,c)......... +| page 3 offset 8192 +| 0: 0d 00 00 00 25 0b 48 00 0f d8 0f af 0f 86 0f 74 ....%.H........t +| 16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5 .a.N./.......... +| 32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 0d ef 0d d5 ...t.[.@.$...... +| 48: 0d bb 0d a0 0d 84 0d 00 00 00 00 00 00 00 00 00 ................ +| 2880: 00 00 00 00 00 00 00 00 81 f9 25 06 00 82 7f 00 ..........%..... +| 2896: 00 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e .COMPILER=gcc-5. +| 2912: 34 2e 30 20 32 30 31 36 30 36 30 39 20 44 45 42 4.0 20160609 DEB +| 2928: 55 47 20 45 4e 41 42 4c 45 20 44 42 53 54 41 54 UG ENABLE DBSTAT +| 2944: 20 56 54 41 42 20 45 4e 41 42 4c 45 20 46 54 53 VTAB ENABLE FTS +| 2960: 34 20 45 4e 41 42 4c 45 20 46 54 53 35 20 45 4e 4 ENABLE FTS5 EN +| 2976: 41 42 4c 45 20 47 45 4f 50 4f 4c 59 20 45 4e 41 ABLE GEOPOLY ENA +| 2992: 42 4c 45 20 4a 53 4f 4e 31 20 45 4e 41 42 4c 45 BLE JSON1 ENABLE +| 3008: 20 4d 45 4d 53 59 53 35 20 45 4e 41 42 4c 45 20 MEMSYS5 ENABLE +| 3024: 52 54 52 45 45 20 4d 41 58 20 4d 45 4d 4f 52 59 RTREE MAX MEMORY +| 3040: 3d 37 a0 30 30 30 30 f2 30 20 4f 4d 49 54 20 4c =7.0000.0 OMIT L +| 3056: 4f 41 44 20 45 58 54 45 4e 53 49 4f 4e 20 54 48 OAD EXTENSION TH +| 3072: 52 45 41 44 53 41 46 45 3d 30 18 24 05 00 25 0f READSAFE=0.$..%. +| 3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49 .THREADSAFE=0XBI +| 3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41 NARY.#..%..THREA +| 3120: 44 53 41 46 45 3d 30 58 4e 4f 43 41 53 45 17 22 DSAFE=0XNOCASE.. +| 3136: 05 00 25 0f 17 54 48 52 45 41 54 53 41 46 45 3d ..%..THREATSAFE= +| 3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d 0XRTRIM.!..3..OM +| 3168: 49 54 20 5c 4f 41 44 20 45 58 54 45 4e 53 49 4f IT .OAD EXTENSIO +| 3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f NXBINARY. ..3..O +| 3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 MIT LOAD EXTENSI +| 3216: 4f 4e 58 4e 4f 43 41 53 46 1e 1f 05 00 33 0f 17 ONXNOCASF....3.. +| 3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 OMIT LOAD EXTENS +| 3248: 49 4f 4e 58 52 44 52 49 4d 1f 1e 05 00 33 0f 19 IONXRDRIM....3.. +| 3264: 4d 41 68 20 4d 45 4d 4f 52 59 3d 35 30 30 30 30 MAh MEMORY=50000 +| 3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f 000XBINARY....3. +| 3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 .MAX MEMORY=5000 +| 3312: 30 30 30 30 58 4e 4f 43 41 53 45 1e 1c 05 00 33 0000XNOCASE....3 +| 3328: 0f 16 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 ..MAX MEMORY=500 +| 3344: 30 30 30 30 30 58 52 54 52 49 4d 18 1b 05 00 25 00000XRTRIM....% +| 3360: 0f 19 45 4e 41 42 4c 45 20 52 54 52 45 45 58 42 ..ENABLE RTREEXB +| 3376: 49 4e 41 52 59 18 1a 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3392: 4c 45 20 52 54 52 45 45 58 4e 4f 43 41 53 45 17 LE RTREEXNOCASE. +| 3408: 19 05 00 25 0f 17 45 4e 41 42 4c 45 20 52 54 52 ...%..ENABLE RTR +| 3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45 EEXRTRIM....)..E +| 3440: 4e 41 42 4c 45 20 4d 45 43 53 59 53 35 58 42 49 NABLE MECSYS5XBI +| 3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4e 41 42 4c NARY....)..ENABL +| 3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 53 45 E MEMSYS5XNOCASE +| 3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 4d 45 ....)..ENABLE ME +| 3504: 4d 53 59 53 35 58 52 54 52 49 4d 18 15 05 00 25 MSYS5XRTRIM....% +| 3520: 0f 19 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 58 42 ..ENABLE JSON1XB +| 3536: 49 4e 41 52 59 18 14 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3552: 4c 45 20 4a 53 4f 4e 31 58 4e 4f 43 41 53 45 17 LE JSON1XNOCASE. +| 3568: 13 05 00 25 0f 17 45 4e 41 42 4c 45 20 4a 53 4f ...%..ENABLE JSO +| 3584: 4e 31 58 52 54 52 49 4d 1a 12 05 00 29 0f 19 45 N1XRTRIM....)..E +| 3600: 4e 41 42 4c 45 20 47 45 4f 50 4f 4c 59 58 42 49 NABLE GEOPOLYXBI +| 3616: 4e 41 52 59 1a 11 05 00 29 0f 19 45 4e 41 42 4c NARY....)..ENABL +| 3632: 45 20 47 45 4f 50 4f 4c 59 58 4e 4f 43 41 53 45 E GEOPOLYXNOCASE +| 3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 45 ....)..ENABLE GE +| 3664: 4f 50 4f 4c 59 58 52 54 52 49 4d 17 0f 05 00 23 OPOLYXRTRIM....# +| 3680: 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 58 42 49 ..ENABLE FTS5XBI +| 3696: 4e 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 4c NARY....#..ENABL +| 3712: 45 20 46 54 53 35 58 4e 4f 43 41 53 45 16 0d 05 E FTS5XNOCASE... +| 3728: 00 23 0f 17 45 4e 41 42 4c 45 20 46 54 53 35 58 .#..ENABLE FTS5X +| 3744: 52 54 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42 RTRIM....#..ENAB +| 3760: 4c 45 20 46 54 53 34 58 42 49 4e 41 52 59 17 0b LE FTS4XBINARY.. +| 3776: 05 00 23 0f 19 45 4e 41 42 4c 45 20 46 54 53 34 ..#..ENABLE FTS4 +| 3792: 58 4e 4f 43 41 53 45 16 0a 05 00 23 0f 17 45 4e XNOCASE....#..EN +| 3808: 41 42 4c 46 20 46 54 53 34 58 52 54 52 49 4d 1e ABLF FTS4XRTRIM. +| 3824: 09 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 52 59 1e TAT VTABXBINARY. +| 3856: 08 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3872: 55 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d UAT VTABXNOCASE. +| 3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3904: 54 41 54 20 56 54 41 42 58 52 54 52 49 4d 11 06 TAT VTABXRTRIM.. +| 3920: 05 00 17 0f 19 44 45 42 55 47 58 42 49 4e 41 52 .....DEBUGXBINAR +| 3936: 59 11 05 05 00 17 0f 19 44 45 42 55 47 58 4e 4f Y.......DEBUGXNO +| 3952: 43 41 53 45 10 04 05 00 17 0f 17 44 45 42 55 47 CASE.......DEBUG +| 3968: 58 52 54 52 49 4d 27 03 05 00 43 0f 19 43 4f 4d XRTRIM'...C..COM +| 3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20 PILER=gcc-5.4.0 +| 4000: 32 30 31 36 30 36 30 39 58 42 49 4e 41 52 59 27 20160609XBINARY' +| 4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67 ...C..COMPILER=g +| 4032: 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36 30 cc-5.4.0 2016060 +| 4048: 39 58 4e 4f 43 41 53 45 00 00 00 00 00 00 00 00 9XNOCASE........ +| page 5 offset 16384 +| 0: 0d 00 00 00 02 0b a0 00 0c ad 0b a0 00 00 00 00 ................ +| 2976: 82 0a 02 08 08 09 08 08 17 84 06 30 20 32 35 33 ...........0 253 +| 2992: 00 01 30 04 25 06 1b 00 00 08 32 30 31 36 30 36 ..0.%.....201606 +| 3008: 30 39 03 25 07 00 00 01 34 03 25 05 00 00 01 35 09.%....4.%....5 +| 3024: 03 25 04 00 01 07 30 30 30 30 30 30 30 03 25 1a .%....0000000.%. +| 3040: 00 00 08 63 6f 6d 70 69 6c 65 72 03 25 02 00 00 ...compiler.%... +| 3056: 06 64 62 73 74 61 74 03 25 0a 00 01 04 65 62 75 .dbstat.%....ebu +| 3072: 67 03 25 08 00 00 06 65 6e 61 62 6c 65 09 25 09 g.%....enable.%. +| 3088: 05 04 04 04 04 04 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3104: 6e 03 25 1d 00 00 04 66 74 73 34 03 25 0d 00 03 n.%....fts4.%... +| 3120: 01 35 03 25 0f 00 00 03 67 63 63 03 25 03 00 01 .5.%....gcc.%... +| 3136: 06 65 6f 70 6f 6c 79 03 25 11 00 00 05 6a 73 6f .eopoly.%....jso +| 3152: 6e 31 03 25 13 00 00 04 6c 6f 61 64 03 25 1c 00 n1.%....load.%.. +| 3168: 00 03 6d 61 78 03 25 18 00 01 05 65 6d 6f 72 79 ..max.%....emory +| 3184: 03 25 19 00 03 04 73 79 73 35 03 25 15 00 00 04 .%....sys5.%.... +| 3200: 6f 6d 69 74 03 25 1b 00 00 05 72 74 72 65 65 03 omit.%....rtree. +| 3216: 25 17 00 00 0a 74 68 72 65 61 64 73 61 66 65 03 %....threadsafe. +| 3232: 25 1e 00 00 04 76 74 61 62 03 25 0b 00 86 50 01 %....vtab.%...P. +| 3248: 08 08 08 08 08 17 8d 12 30 20 38 33 35 00 01 30 ........0 835..0 +| 3264: 12 01 06 00 01 06 00 01 06 00 1f 03 00 01 03 00 ................ +| 3280: 01 03 00 00 08 32 30 31 36 30 36 30 39 09 01 07 .....20160609... +| 3296: 00 01 07 00 01 07 00 00 01 34 09 01 05 00 01 05 .........4...... +| 3312: 00 01 05 00 00 01 35 09 01 04 00 01 04 00 01 04 ......5......... +| 3328: 00 01 07 30 30 30 30 30 30 30 09 1c 04 00 01 04 ...0000000...... +| 3344: 00 01 04 00 00 06 62 69 6e 61 72 79 3c 03 01 02 ......binary<... +| 3360: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3376: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3392: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 ................ +| 3408: 01 02 02 00 03 01 02 02 00 00 08 63 6f 38 70 69 ...........co8pi +| 3424: 6c 65 72 09 01 02 00 01 02 00 01 02 00 00 06 64 ler............d +| 3440: 52 73 74 61 74 09 07 03 00 01 03 00 01 03 00 01 Rstat........... +| 3456: 04 65 62 75 67 09 04 02 00 01 02 00 01 02 00 00 .ebug........... +| 3472: 06 65 6e 61 62 6c 65 3f 07 02 00 01 02 00 01 01 .enable?........ +| 3488: ff f1 02 00 01 02 00 01 02 00 01 02 00 01 02 00 ................ +| 3504: 01 02 00 01 03 00 01 01 00 02 02 00 01 02 00 01 ................ +| 3520: 02 00 01 02 00 01 12 00 01 02 00 01 02 00 01 02 ................ +| 3536: 00 01 02 00 01 02 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3552: 6e 09 1f 04 00 01 04 00 01 04 00 00 04 66 74 73 n............fts +| 3568: 34 09 0a 03 00 01 03 00 01 04 00 03 01 35 09 0d 4............5.. +| 3584: 03 00 01 03 00 01 03 00 00 03 67 63 63 09 01 03 ..........gcc... +| 3600: 00 01 03 0b 01 13 00 01 06 65 6f 70 6f 6c 79 09 .........eopoly. +| 3616: 10 03 00 01 03 00 01 03 00 00 05 6a 83 6f 6e 31 ...........j.on1 +| 3632: 09 13 03 00 01 03 00 01 03 00 00 04 6c 6f 61 64 ............load +| 3648: 09 1f 03 00 01 03 00 01 03 00 00 03 6d 61 78 09 ............max. +| 3664: 1c 02 00 01 02 00 01 02 00 01 05 65 6d 6f 72 79 ...........emory +| 3680: 09 1c 03 00 01 03 00 01 03 00 03 04 73 79 73 35 ............sys5 +| 3696: 09 16 03 00 01 03 00 01 03 00 00 06 6e 6f 63 61 ............noca +| 3712: 73 65 3c 02 01 02 02 00 03 01 02 02 00 03 01 02 se<............. +| 3728: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3744: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3760: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 00 ................ +| 3776: 04 6f 6d 69 74 09 1f 02 00 01 02 00 01 02 00 00 .omit........... +| 3792: 05 72 74 72 65 65 09 19 03 00 01 03 00 01 03 00 .rtree.......... +| 3808: 03 02 69 6d 3c 01 01 02 02 00 03 01 02 02 00 03 ..im<........... +| 3824: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 ................ +| 3840: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 ................ +| 3856: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3872: 00 00 0a 74 68 72 65 61 64 73 61 66 65 09 22 02 ...threadsafe... +| 3888: 00 01 02 00 01 02 00 00 04 76 74 61 62 09 07 04 .........vtab... +| 3904: 00 01 04 00 01 04 00 00 01 78 b4 01 01 01 01 02 .........x...... +| 3920: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 3936: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 3952: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 3968: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 3984: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4000: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 4016: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 4032: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 4048: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 4064: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4080: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| page 6 offset 20480 +| 0: 0a 00 00 00 02 0f f5 00 0f fb 0f f5 00 00 00 00 ................ +| 4080: 00 00 00 00 00 05 04 08 09 01 02 04 04 08 08 09 ................ +| page 7 offset 24576 +| 0: 0d 00 00 00 05 0f b8 00 0f f4 0f 00 00 00 00 00 ................ +| 4016: 00 00 00 00 00 00 00 00 0d 05 02 23 61 75 74 6f ...........#auto +| 4032: 6d 65 72 67 65 3d 35 0d 04 02 23 6d 65 72 67 65 merge=5...#merge +| 4048: 3d 31 30 30 2c 38 11 03 02 2b 69 6e 74 65 67 72 =100,8...+integr +| 4064: 69 74 79 2d 63 68 65 63 6b 09 02 02 00 00 00 00 ity-check....... +| end crash-14ab65782c9c45.db +}]} {} + +do_execsql_test 50.1 { + SELECT NULL FROM t1 WHERE t1 MATCH '"^enable"' +} { + {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} +} + +#------------------------------------------------------------------------- +# +reset_db +do_test 51.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +.open --hexdb +| size 28672 pagesize 4096 filename crash-11cf359576eb28.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07 .....@ ........ +| 32: 00 00 00 02 00 00 00 01 00 00 00 07 00 00 00 04 ................ +| 96: 00 00 00 00 0d 0e b1 00 06 0d a4 00 0f 8d 0f 21 ...............! +| 112: 0e b9 0d c8 0e 7e 0d a4 0d a4 00 00 00 00 00 00 .....~.......... +| 3488: 00 00 00 00 22 07 06 17 11 11 01 31 74 61 62 6c ...........1tabl +| 3504: 65 74 32 74 32 07 43 52 45 41 54 45 20 54 41 42 et2t2.CREATE TAB +| 3520: 4c 45 20 74 32 28 78 29 81 33 05 07 17 1f 1f 01 LE t2(x).3...... +| 3536: 82 35 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72 .5tablet1_segdir +| 3552: 74 31 5f 73 65 67 64 69 72 05 43 52 45 41 54 45 t1_segdir.CREATE +| 3568: 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69 TABLE 't1_segdi +| 3584: 72 27 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52 r'(level INTEGER +| 3600: 2c 69 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61 ,idx INTEGER,sta +| 3616: 72 74 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52 rt_block INTEGER +| 3632: 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 ,leaves_end_bloc +| 3648: 6b 20 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c k INTEGER,end_bl +| 3664: 6f 63 6b 20 49 4e 54 45 47 45 52 2c 72 6f 6f 74 ock INTEGER,root +| 3680: 20 42 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45 BLOB,PRIMARY KE +| 3696: 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 06 Y(level, idx))1. +| 3712: 06 17 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74 ..E...indexsqlit +| 3728: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73 e_autoindex_t1_s +| 3744: 65 67 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72 egdir_1t1_segdir +| 3760: 06 0f c7 00 08 00 00 00 00 66 04 07 17 23 23 01 .........f...##. +| 3776: 81 13 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e ..tablet1_segmen +| 3792: 74 73 74 31 5f 73 65 67 6d 65 6e 74 73 04 43 52 tst1_segments.CR +| 3808: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 EATE TABLE 't1_s +| 3824: 65 67 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64 egments'(blockid +| 3840: 20 49 4e 54 45 47 45 52 20 50 51 49 4d 41 52 59 INTEGER PQIMARY +| 3856: 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 KEY, block BLOB +| 3872: 29 6a 03 07 17 21 21 01 81 1f 74 61 62 6c 65 74 )j...!!...tablet +| 3888: 31 5f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 1_contentt1_cont +| 3904: 65 6e 74 03 43 52 45 41 54 45 20 54 41 42 4c 45 ent.CREATE TABLE +| 3920: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f 't1_content'(do +| 3936: 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d cid INTEGER PRIM +| 3952: 41 52 59 20 4b 45 59 2c 20 27 63 30 61 27 2c 20 ARY KEY, 'c0a', +| 3968: 27 63 31 62 27 2c 20 27 63 32 63 27 29 38 02 06 'c1b', 'c2c')8.. +| 3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52 ...._tablet1t1CR +| 4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB +| 4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33 LE t1 USING fts3 +| 4032: 28 61 2c 62 2c 63 29 00 00 00 00 00 00 00 00 00 (a,b,c)......... +| page 3 offset 8192 +| 0: 0d 00 00 00 25 0b 48 00 0f d8 0f af 0f 86 0f 74 ....%.H........t +| 16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5 .a.N./.......... +| 32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 0d ef 0d d5 ...t.[.@.$...... +| 48: 0d bb 0d a0 0d 84 0d 68 0d 4f 0d 35 0d 1b 0c fb .......h.O.5.... +| 64: 0c da 0c b9 0c 99 0c 78 0c 57 0c 3e 0c 24 0c 0a .......x.W.>.$.. +| 80: 0b 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .H.............. +| 2880: 00 00 00 00 00 00 00 00 81 3f 25 06 00 82 7f 00 .........?%..... +| 2896: 00 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e .COMPILER=gcc-5. +| 2912: 34 2e 30 20 32 30 31 36 30 36 30 39 20 44 45 42 4.0 20160609 DEB +| 2928: 55 47 20 45 4e 41 42 4c 45 20 44 42 53 54 41 54 UG ENABLE DBSTAT +| 2944: 20 56 54 41 42 20 45 4e 41 42 4c 45 20 46 54 53 VTAB ENABLE FTS +| 2960: 34 20 45 4e 41 42 4c 45 20 46 54 53 35 20 45 4e 4 ENABLE FTS5 EN +| 2976: 41 42 4c 45 20 47 45 4f 59 0f 4c 59 20 45 4e 41 ABLE GEOY.LY ENA +| 2992: 42 4c 45 20 4a 53 4f 4e 31 20 45 4e 41 42 4c 45 BLE JSON1 ENABLE +| 3008: 20 4d 45 4d 53 59 53 35 20 45 4e 41 42 4c 45 20 MEMSYS5 ENABLE +| 3024: 52 54 52 45 45 20 4d 41 58 20 4d 45 4d 4f 52 59 RTREE MAX MEMORY +| 3040: 3d 35 30 30 30 30 30 30 30 20 4f 4d 49 54 20 4d =50000000 OMIT M +| 3056: 4f 41 44 20 45 58 54 45 4e 53 49 4f 4e 20 54 48 OAD EXTENSION TH +| 3072: 52 45 41 44 53 41 46 45 3d 30 18 24 05 00 25 0f READSAFE=0.$..%. +| 3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49 .THREADSAFE=0XBI +| 3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41 NARY.#..%..THREA +| 3120: 44 53 41 46 45 3d 30 58 4e 4f 43 41 53 45 17 22 DSAFE=0XNOCASE.. +| 3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 45 3d ..%..THREADSAFE= +| 3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d 0XRTRIM.!..3..OM +| 3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 4f IT LOAD EXTENSIO +| 3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f NXBINARY. ..3..O +| 3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 MIT LOAD EXTENSI +| 3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17 ONXNOCASE....3.. +| 3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 OMIT LOAD EXTENS +| 3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f 19 IONXRTRIM....3.. +| 3264: 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 30 MAX MEMORY=50000 +| 3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f 000XBINARY....3. +| 3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 .MAX MEMORY=5000 +| 3312: 30 30 30 30 58 4e 4f 43 41 53 45 1e 1c 05 00 33 0000XNOCASE....3 +| 3328: 0f 17 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 ..MAX MEMORY=500 +| 3344: 30 30 30 30 30 58 52 54 52 49 4d 18 1b 05 00 25 00000XRTRIM....% +| 3360: 0f 19 45 4e 41 42 4c 45 20 52 54 52 45 45 58 42 ..ENABLE RTREEXB +| 3376: 49 4e 41 52 59 18 1a 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3392: 4c 45 20 52 54 52 45 45 58 4e 4f 43 41 53 45 17 LE RTREEXNOCASE. +| 3408: 19 05 00 25 0f 17 45 4e 41 42 4c 45 20 52 54 52 ...%..ENABLE RTR +| 3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45 EEXRTRIM....)..E +| 3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 58 42 49 NABLE MEMSYS5XBI +| 3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4e 41 42 4c NARY....)..ENABL +| 3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 53 45 E MEMSYS5XNOCASE +| 3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 4d 45 ....)..ENABLE ME +| 3504: 4d 53 59 53 35 58 52 54 52 49 4d 18 15 05 00 25 MSYS5XRTRIM....% +| 3520: 0f 19 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 58 42 ..ENABLE JSON1XB +| 3536: 49 4e 41 52 59 18 14 05 00 25 0f 19 45 4e 41 42 INARY....%..ENAB +| 3552: 4c 45 20 4a 53 4f 4e 31 58 4e 4f 43 41 53 45 17 LE JSON1XNOCASE. +| 3568: 13 05 00 25 0f 17 45 4e 41 42 4c 45 20 4a 53 4f ...%..ENABLE JSO +| 3584: 4e 31 58 52 54 52 49 4d 1a 12 05 00 29 0f 19 45 N1XRTRIM....)..E +| 3600: 4e 41 42 4c 45 20 47 45 4f 50 4f 4c 59 58 42 49 NABLE GEOPOLYXBI +| 3616: 4e 41 52 59 1a 11 05 00 29 0f 19 45 4e 41 42 4c NARY....)..ENABL +| 3632: 45 20 47 45 4f 50 4f 4c 59 58 4e 4f 43 41 53 45 E GEOPOLYXNOCASE +| 3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 45 ....)..ENABLE GE +| 3664: 4f 50 4f 4c 59 58 52 54 52 49 4d 17 0f 05 00 23 OPOLYXRTRIM....# +| 3680: 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 58 42 49 ..ENABLE FTS5XBI +| 3696: 4e 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 4c NARY....#..ENABL +| 3712: 45 20 46 54 53 35 58 4e 4f 43 41 53 45 16 0d 05 E FTS5XNOCASE... +| 3728: 00 23 0f 17 45 4e 41 42 4c 45 20 46 54 53 35 58 .#..ENABLE FTS5X +| 3744: 52 54 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42 RTRIM....#..ENAB +| 3760: 4c 45 20 46 54 53 34 58 42 49 4e 41 52 59 17 0b LE FTS4XBINARY.. +| 3776: 05 00 23 0f 19 45 4e 41 42 4c 45 20 46 54 53 34 ..#..ENABLE FTS4 +| 3792: 58 4e 4f 43 41 53 45 16 0a 05 00 23 0f 17 45 4e XNOCASE....#..EN +| 3808: 41 42 4c 45 20 46 54 53 34 58 52 54 52 49 4d 1e ABLE FTS4XRTRIM. +| 3824: 09 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 52 59 1e TAT VTABXBINARY. +| 3856: 08 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3872: 54 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d TAT VTABXNOCASE. +| 3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 44 42 53 ...1..ENABLE DBS +| 3904: 54 41 54 20 56 54 41 42 58 52 54 52 49 4d 11 06 TAT VTABXRTRIM.. +| 3920: 05 00 17 0f 19 44 45 42 55 47 58 42 49 4e 41 52 .....DEBUGXBINAR +| 3936: 59 11 05 05 00 17 0f 19 44 45 42 55 47 58 4e 4f Y.......DEBUGXNO +| 3952: 43 41 53 45 10 04 05 00 17 0f 17 44 45 42 55 47 CASE.......DEBUG +| 3968: 58 52 54 52 49 4d 27 03 05 00 43 10 19 43 4f 4d XRTRIM'...C..COM +| 3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20 PILER=gcc-5.4.0 +| 4000: 32 30 31 36 30 36 30 39 58 42 49 4e 41 52 59 27 20160609XBINARY' +| 4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67 ...C..COMPILER=g +| 4032: 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36 30 cc-5.4.0 2016060 +| 4048: 39 58 4e 4f 43 41 53 45 26 01 05 00 43 0f 17 43 9XNOCASE&...C..C +| 4064: 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e OMPILER=gcc-5.4. +| 4080: 30 20 32 30 31 36 30 36 30 39 58 52 54 52 49 4d 0 20160609XRTRIM +| page 4 offset 12288 +| 0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................ +| page 5 offset 16384 +| 0: 0d 00 00 00 02 0b a0 00 0c ad 0b a0 00 00 00 00 ................ +| 2976: 82 0a 02 08 08 09 08 08 17 84 06 30 20 32 35 33 ...........0 253 +| 2992: 00 01 30 04 25 06 1b 00 00 08 32 30 31 36 30 36 ..0.%.....201606 +| 3008: 30 39 03 25 07 00 00 01 34 03 25 05 00 00 01 35 09.%....4.%....5 +| 3024: 03 25 04 00 01 07 30 30 30 30 30 30 30 03 25 1a .%....0000000.%. +| 3040: 00 00 08 63 6f 6d 70 69 6c 65 72 03 25 02 00 00 ...compiler.%... +| 3056: 06 64 62 73 74 61 74 03 25 0a 00 01 04 65 62 75 .dbstat.%....ebu +| 3072: 67 03 25 08 00 00 06 65 6e 61 62 6c 65 09 25 09 g.%....enable.%. +| 3088: 05 04 04 04 04 04 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3104: 6e 03 25 1d 00 00 04 66 74 73 34 03 25 0d 00 03 n.%....fts4.%... +| 3120: 01 35 03 25 0f 00 00 03 67 63 63 03 25 03 00 01 .5.%....gcc.%... +| 3136: 06 65 6f 70 6f 6c 79 03 25 11 00 00 05 6a 73 6f .eopoly.%....jso +| 3152: 6e 31 03 25 13 00 00 04 6c 6f 61 64 03 25 1c 00 n1.%....load.%.. +| 3168: 00 03 6d 61 78 03 25 18 00 01 05 65 6d 6f 72 79 ..max.%....emory +| 3184: 03 25 19 00 03 04 73 79 73 35 03 25 15 00 00 04 .%....sys5.%.... +| 3200: 6f 6d 69 74 03 25 1b 00 00 05 72 74 72 65 65 03 omit.%....rtree. +| 3216: 25 17 00 00 0a 74 68 72 65 61 64 73 61 66 65 03 %....threadsafe. +| 3232: 25 1e 00 00 04 76 74 61 62 03 25 0b 00 86 50 01 %....vtab.%...P. +| 3248: 08 08 08 08 08 17 8d 12 30 20 38 33 35 00 01 30 ........0 835..0 +| 3264: 12 01 06 00 01 06 00 01 06 00 1f 03 00 01 03 00 ................ +| 3280: 01 03 00 00 08 32 30 31 36 30 36 30 39 09 01 07 .....20160609... +| 3296: 00 01 07 00 01 07 00 00 01 34 09 01 05 00 01 05 .........4...... +| 3312: 00 01 05 00 00 01 35 09 01 04 00 01 04 00 01 04 ......5......... +| 3328: 00 01 07 30 30 30 30 30 30 30 09 1c 04 00 01 04 ...0000000...... +| 3344: 00 01 04 00 00 06 62 69 6e 61 72 79 3c 03 01 02 ......binary<... +| 3360: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3376: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 5f ..............._ +| 3392: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 ................ +| 3408: 01 02 02 00 03 01 02 02 00 00 08 63 6f 6d 70 69 ...........compi +| 3424: 6c 65 72 09 01 02 00 01 02 00 01 02 00 00 06 64 ler............d +| 3440: 62 73 74 61 74 09 07 03 00 01 03 00 01 03 00 01 bstat........... +| 3456: 04 65 62 75 67 09 04 02 00 01 02 00 01 02 00 00 .ebug........... +| 3472: 06 65 6e 61 62 6c 65 3f 07 02 00 01 02 00 01 02 .enable?........ +| 3488: 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00 ................ +| 3504: 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 ................ +| 3520: 02 00 01 01 00 01 02 00 01 02 00 01 02 00 01 02 ................ +| 3536: 00 01 02 00 01 02 00 01 08 78 74 65 6e 73 69 6f .........xtensio +| 3552: 6e 09 1f 04 00 01 04 00 01 04 00 00 04 66 74 73 n............fts +| 3568: 34 09 0a 03 00 01 03 00 01 03 00 03 01 35 09 0d 4............5.. +| 3584: 03 00 01 03 00 01 03 00 00 03 67 63 63 09 01 03 ..........gcc... +| 3600: 00 01 03 00 01 03 00 01 06 65 6f 70 6f 6c 79 09 .........eopoly. +| 3616: 10 03 00 01 03 00 01 03 00 00 05 6a 73 6f 6e 31 ...........json1 +| 3632: 09 13 03 00 01 03 00 01 03 00 00 04 6c 6f 61 64 ............load +| 3648: 09 1f 03 00 01 03 00 01 03 00 00 03 6d 61 78 09 ............max. +| 3664: 1c 02 00 01 02 00 01 02 00 01 05 65 6d 6f 72 79 ...........emory +| 3680: 09 1c 03 00 01 03 00 01 03 00 03 04 73 79 73 35 ............sys5 +| 3696: 09 16 03 00 01 03 00 01 03 00 00 06 6e 6f 63 61 ............noca +| 3712: 73 65 3c 02 01 02 02 00 03 01 02 02 00 03 01 02 se<............. +| 3728: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3744: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................ +| 3760: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 00 ................ +| 3776: 04 6f 6d 69 74 09 1f 02 00 01 02 00 01 02 00 00 .omit........... +| 3792: 05 72 74 72 65 65 09 19 03 00 01 03 00 01 03 00 .rtree.......... +| 3808: 03 02 69 6d 3c 01 01 02 02 00 03 01 02 02 00 03 ..im<........... +| 3824: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 ................ +| 3840: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 ................ +| 3856: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................ +| 3872: 00 00 0a 74 68 72 65 61 64 73 61 66 65 09 22 02 ...threadsafe... +| 3888: 00 01 02 00 01 02 00 00 04 76 74 61 62 09 07 04 .........vtab... +| 3904: 00 01 04 00 01 04 00 00 01 78 b4 01 01 01 01 02 .........x...... +| 3920: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 3936: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 3952: 01 01 03 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 3968: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 3984: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4000: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| 4016: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 ................ +| 4032: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................ +| 4048: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................ +| 4064: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................ +| 4080: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................ +| page 6 offset 20480 +| 0: 0a 00 00 00 02 0f f5 00 0f fb 0f f5 00 00 00 00 ................ +| 4080: 00 00 00 00 00 05 04 08 09 01 02 04 04 08 08 09 ................ +| page 7 offset 24576 +| 0: 0d 00 00 00 05 0f b8 00 0f f4 0f e9 0f d6 00 00 ................ +| 4016: 00 00 00 00 00 00 00 00 0d 05 02 23 61 75 74 6f ...........#auto +| 4032: 6d 65 72 67 65 3d 35 0d 04 02 23 6d 65 72 67 65 merge=5...#merge +| 4048: 3d 31 30 30 2c 38 11 03 02 2b 69 6e 74 65 67 72 =100,8...+integr +| 4064: 69 74 79 2d 63 68 65 63 6b 09 02 02 1b 72 65 62 ity-check....reb +| 4080: 75 69 6c 64 0a 01 02 1d 6f 70 74 69 6d 69 7a 65 uild....optimize +| end crash-11cf359576eb28.db +}]} {} + +set saved $sqlite_fts3_enable_parentheses +set sqlite_fts3_enable_parentheses 1 +do_catchsql_test 51.1 { + SELECT 'xyzzy',offsets(t1) FROM t1 WHERE t1 MATCH 'rtree OR json1''rtree NEAR "json1 enable"'; +} {1 {database disk image is malformed}} +set sqlite_fts3_enable_parentheses $saved + +#------------------------------------------------------------------------- +# +set saved $sqlite_fts3_enable_parentheses +set sqlite_fts3_enable_parentheses 1 +reset_db +do_test 52.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +.open --hexdb +| size 28672 pagesize 4096 filename crash-fd33f4b1c8348b.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 92 00 00 00 07 .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 07 00 00 00 04 ................ +| 96: 00 00 00 00 0d 0e ef 00 08 0d 13 00 0f bd 0f 5f ..............._ +| 112: 0e f7 0e 06 0e bc 0d a4 0d 4d 0d 13 00 00 00 00 .........M...... +| 3344: 00 00 00 38 08 06 17 11 11 08 5f 74 61 62 6c 65 ...8......_table +| 3360: 74 32 74 32 43 52 45 41 54 45 20 56 49 52 54 55 t2t2CREATE VIRTU +| 3376: 41 4c 20 54 41 42 4c 45 20 74 32 20 55 53 49 4e AL TABLE t2 USIN +| 3392: 47 20 66 74 73 34 61 75 78 28 74 31 29 55 07 07 G fts4aux(t1)U.. +| 3408: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 73 74 ......tablet1_st +| 3424: 61 74 74 31 5f 73 74 61 74 07 43 52 45 41 54 45 att1_stat.CREATE +| 3440: 20 54 41 42 4c 45 20 27 74 31 5f 73 74 61 74 27 TABLE 't1_stat' +| 3456: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d (id INTEGER PRIM +| 3472: 41 52 59 20 4b 45 59 2c 20 76 61 6c 75 65 20 42 ARY KEY, value B +| 3488: 4c 4f 42 29 60 06 07 17 21 21 01 81 0b 74 61 62 LOB)`...!!...tab +| 3504: 6c 65 74 31 5f 64 6f 63 73 69 7a 65 74 31 5f 64 let1_docsizet1_d +| 3520: 6f 63 73 69 7a 65 06 43 52 45 41 54 45 20 54 41 ocsize.CREATE TA +| 3536: 42 4c 45 20 27 74 31 5f 64 6f 63 73 69 7a 65 27 BLE 't1_docsize' +| 3552: 28 64 6f 63 69 64 20 49 4e 54 45 47 45 52 20 50 (docid INTEGER P +| 3568: 52 49 4d 41 52 59 20 4b 45 59 2c 20 73 69 7a 65 RIMARY KEY, size +| 3584: 20 42 4c 4f 42 29 81 33 04 07 17 1f 1f 01 82 35 BLOB).3.......5 +| 3600: 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72 74 31 tablet1_segdirt1 +| 3616: 5f 73 65 67 64 69 72 04 43 52 45 41 54 45 20 54 _segdir.CREATE T +| 3632: 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69 72 27 ABLE 't1_segdir' +| 3648: 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52 2c 69 (level INTEGER,i +| 3664: 64 78 20 49 4e 64 45 47 45 52 2c 73 74 61 72 74 dx INdEGER,start +| 3680: 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52 2c 6c _block INTEGER,l +| 3696: 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 6b 20 eaves_end_block +| 3712: 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c 6f 63 INTEGER,end_bloc +| 3728: 6b 20 49 4e 54 45 47 45 52 2c 72 6f 6f 74 20 42 k INTEGER,root B +| 3744: 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45 59 28 LOB,PRIMARY KEY( +| 3760: 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 05 06 17 level, idx))1... +| 3776: 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74 65 5f E...indexsqlite_ +| 3792: 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73 65 67 autoindex_t1_seg +| 3808: 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72 05 00 dir_1t1_segdir.. +| 3824: 00 00 08 00 00 00 00 66 03 07 17 23 23 01 81 13 .......f...##... +| 3840: 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e 74 73 tablet1_segments +| 3856: 74 31 5f 73 65 67 6d 65 6e 74 73 03 43 52 45 41 t1_segments.CREA +| 3872: 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 TE TABLE 't1_seg +| 3888: 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64 20 49 ments'(blockid I +| 3904: 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b NTEGER PRIMARY K +| 3920: 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 29 5c EY, block BLOB). +| 3936: 02 07 17 21 21 01 81 03 74 61 62 6c 65 74 31 5f ...!!...tablet1_ +| 3952: 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 65 6e contentt1_conten +| 3968: 74 02 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 t.CREATE TABLE ' +| 3984: 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f 63 69 t1_content'(doci +| 4000: 64 20 49 4e 54 45 47 45 52 e6 50 52 49 4d 41 52 d INTEGER.PRIMAR +| 4016: 59 20 4b 45 59 2c 20 27 63 30 61 27 29 41 01 06 Y KEY, 'c0a')A.. +| 4032: 17 11 11 08 71 74 61 62 6c 65 74 31 74 31 43 52 ....qtablet1t1CR +| 4048: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB +| 4064: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 34 LE t1 USING fts4 +| 4080: 28 61 2c 70 72 65 66 69 78 3d 27 31 2c 32 27 29 (a,prefix='1,2') +| page 2 offset 4096 +| 0: 0d 00 00 00 08 0e 22 00 0f c4 0f 00 00 00 00 00 ................ +| 3616: 00 00 42 08 04 00 81 09 73 75 6e 74 20 69 6e 20 ..B.....sunt in +| 3632: 63 75 6c 70 61 20 71 75 69 20 6f 66 66 69 63 69 culpa qui offici +| 3648: 61 20 64 65 73 65 72 75 6e 74 20 6d 6f 6c 6c 69 a deserunt molli +| 3664: 74 20 61 6e 69 6d 20 69 64 20 65 73 74 20 7c 61 t anim id est |a +| 3680: 62 6f 72 75 6d 2e 32 07 03 00 6b 45 78 63 65 70 borum.2...kExcep +| 3696: 74 65 75 72 20 73 69 6e 74 20 6f 63 63 61 65 63 teur sint occaec +| 3712: 61 74 20 63 75 70 69 64 61 74 61 74 20 6e 6f 6e at cupidatat non +| 3728: 20 70 72 6f 69 64 65 6e 74 2c 29 06 03 00 59 63 proident,)...Yc +| 3744: 69 6c 6c 75 6d 20 64 6f 6c 6f 72 65 20 65 20 66 illum dolore e f +| 3760: 75 67 69 61 74 20 6e 75 6c 6c 61 20 70 61 72 69 ugiat nulla pari +| 3776: 61 74 75 72 2e 42 05 04 00 81 09 44 75 69 73 20 atur.B.....Duis +| 3792: 61 75 74 65 20 69 72 75 72 65 20 64 6f 6c 6f 72 aute irure dolor +| 3808: 20 69 6e 20 72 65 60 72 65 68 65 6e 64 65 72 69 in re`rehenderi +| 3824: 74 20 69 6e 20 76 70 6c 75 70 74 61 74 65 20 76 t in vpluptate v +| 3840: 65 6c 69 72 c0 65 73 73 65 29 04 03 00 59 6e 69 elir.esse)...Yni +| 3856: 73 6a 20 75 74 20 61 6c 69 71 75 69 70 20 65 20 sj ut aliquip e +| 3872: 65 20 63 6f 6d 6d 6f 64 6f 20 63 6f 6e 73 65 71 e commodo conseq +| 3888: 75 61 74 2e 46 03 04 00 29 11 55 74 20 65 6e 69 uat.F...).Ut eni +| 3904: 6d 20 61 64 20 6d 69 6e 69 6d 20 76 65 6e 69 61 m ad minim venia +| 3920: 6d 2c 20 71 75 69 73 20 6e 6f 73 74 72 75 64 20 m, quis nostrud +| 3936: 65 78 65 72 63 69 7a 71 74 69 6f 6e 20 75 6c 6c exercizqtion ull +| 3952: 61 6d 63 6f 20 6c 61 62 6f 72 69 73 46 02 04 00 amco laborisF... +| 3968: 81 11 73 65 64 20 64 6f 20 65 69 75 73 6d 6f 64 ..sed do eiusmod +| 3984: 20 74 65 6d 70 6f 72 20 69 6e 63 69 64 69 64 75 tempor incididu +| 4000: 6e 74 20 75 74 20 6c 61 62 6f 72 65 20 65 74 20 nt ut labore et +| 4016: 64 6f 6c 6f 72 65 20 6d 61 67 6e 61 20 61 6c 69 dolore magna ali +| 4032: 71 75 61 2e 3a 01 03 00 7b 4c 6f 72 65 6d 20 69 qua.:....Lorem i +| 4048: 72 63 75 6d 20 64 6f 6c 6f 72 20 73 69 74 20 61 rcum dolor sit a +| 4064: 6d 65 74 2c 20 63 6f 6e 78 65 63 74 65 64 75 72 met, conxectedur +| 4080: 20 61 64 69 70 69 73 00 00 00 00 00 00 00 00 00 adipis......... +| page 4 offset 12288 +| 0: 0d 00 00 00 03 0a c1 00 0d 61 0c 54 0a c1 00 00 .........a.T.... +| 2752: 00 83 10 03 08 02 08 08 08 17 86 0e 08 00 30 20 ..............0 +| 2768: 33 38 35 00 02 61 64 06 01 08 00 02 04 00 01 01 385..ad......... +| 2784: 6c 06 02 0c 00 02 04 00 01 01 6d 03 01 06 10 01 l.........m..... +| 2800: 01 6e 03 08 09 00 01 01 75 03 05 03 00 00 02 63 .n......u......c +| 2816: 69 03 06 02 00 01 01 6f 07 01 07 00 03 07 03 00 i......o........ +| 2832: 01 01 75 06 75 05 00 01 04 00 00 02 64 65 03 08 ..u.u.......de.. +| 2848: 07 00 01 01 6f 0d 01 04 00 01 03 09 00 03 05 00 ....o........... +| 2864: 01 03 00 01 01 75 03 05 02 00 00 02 65 69 03 02 .....u......ei.. +| 2880: 04 00 01 01 6c 03 01 44 00 01 01 6e 03 03 03 00 ....l..D...n.... +| 2896: 01 01 73 06 05 0b 00 03 0b 00 01 01 74 03 02 09 ..s.........t... +| 2912: 00 01 01 78 06 03 09 00 04 02 00 00 02 66 75 03 ...x.........fu. +| 2928: 06 05 00 00 02 69 64 03 08 0a 00 01 01 6e 0a 02 .....id......n.. +| 2944: 06 00 03 06 04 00 03 03 00 01 01 70 03 01 03 00 ...........p.... +| 2960: 01 01 72 03 05 04 00 00 02 6c 61 09 02 08 00 01 ..r......la..... +| 2976: 0b 00 05 0c 00 01 01 6f 03 01 02 00 00 02 6d 61 .......o......ma +| 2992: 03 02 0b 00 01 01 69 03 03 05 00 01 01 6f 03 08 ......i......o.. +| 3008: 08 00 00 02 6e 69 03 04 02 00 01 01 6f 06 03 08 ....ni......o... +| 3024: 00 04 06 00 01 01 75 03 06 06 00 00 02 6f 63 03 ......u......oc. +| 3040: 07 04 00 01 01 66 03 08 06 00 00 02 70 61 03 06 .....f......pa.. +| 3056: 07 00 01 11 72 03 07 07 00 00 02 71 75 06 03 07 ....r......qu... +| 3072: 00 05 05 00 00 02 72 65 03 05 07 00 00 02 73 65 ......re......se +| 3088: 03 02 02 00 01 01 69 06 01 05 00 06 03 00 01 01 ......i......... +| 3104: 75 03 08 02 00 00 02 74 65 03 02 05 00 00 02 75 u......te......u +| 3120: 6c 13 03 0a 00 01 01 74 09 02 07 00 01 02 00 01 l......t........ +| 3136: 02 ff ff 02 76 65 06 03 06 00 02 0a 00 01 01 6f ....ve.........o +| 3152: 03 05 09 00 82 0a 02 08 02 08 08 08 17 84 02 04 ................ +| 3168: 00 30 20 32 35 31 00 01 61 13 01 06 04 00 01 0c .0 251..a....... +| 3184: 00 01 04 00 01 04 00 01 03 00 03 09 00 00 01 63 ...............c +| 3200: 10 01 07 00 03 07 03 00 02 02 00 01 05 00 01 04 ................ +| 3216: 00 00 01 64 11 01 04 00 01 03 09 00 03 02 05 00 ...d............ +| 3232: 01 03 00 02 07 00 00 01 65 1b 01 09 00 01 04 07 ........e....... +| 3248: 00 01 03 08 00 01 05 03 00 01 1c eb 01 04 00 01 ................ +| 3264: 0e 80 01 0b 00 00 01 66 03 06 05 00 00 01 69 0f .......f......i. +| 3280: 01 03 00 01 06 0b 23 04 04 04 00 03 03 09 00 00 ......#......... +| 3296: 01 6c 0c 01 02 00 01 08 00 01 0b 00 05 0c 00 00 .l.............. +| 3312: 01 6d 09 02 0b 00 01 05 00 05 08 00 00 01 6e 0c .m............n. +| 3328: 03 08 00 01 02 00 02 06 00 01 06 00 00 01 6f 06 ..............o. +| 3344: 07 04 00 01 06 00 00 01 70 06 06 07 00 01 07 00 ........p....... +| 3360: 00 01 71 06 03 07 00 05 05 00 00 01 72 03 05 07 ..q.........r... +| 3376: 00 00 02 73 0c 01 05 00 01 02 00 05 03 00 01 02 ...s............ +| 3392: 00 00 01 74 03 02 05 00 00 01 75 0a 02 07 00 01 ...t......u..... +| 3408: 02 0a 00 01 03 00 00 01 76 07 03 06 00 02 09 03 ........v....... +| 3424: 00 85 1c 01 08 08 08 08 08 17 8a 2a 30 20 36 35 ...........*0 65 +| 3440: 35 00 02 61 64 03 03 04 00 02 08 69 70 69 73 63 5..ad......ipisc +| 3456: 69 6e 67 03 01 08 00 01 05 6c 69 71 75 61 03 02 ing......liqua.. +| 3472: 0c 00 05 02 69 70 03 04 04 00 01 03 6d 65 74 03 ....ip......met. +| 3488: 01 06 00 01 03 6e 69 6d 03 08 09 00 01 03 75 74 .....nim......ut +| 3504: 65 03 05 03 00 00 06 63 69 6c 6c 75 6d 03 06 02 e......cillum... +| 3520: 00 01 06 6f 6d 6d 6f 64 6f 03 04 07 00 02 09 6e ...ommodo......n +| 3536: 73 65 63 74 65 74 75 72 03 01 07 00 05 04 71 75 sectetur......qu +| 3552: 61 73 03 04 08 00 01 04 75 6c 70 61 03 08 04 00 as......ulpa.... +| 3568: 02 07 70 69 64 61 74 61 74 03 07 05 00 00 08 64 ..pidatat......d +| 3584: 65 73 65 72 75 6e 74 03 08 07 00 01 01 6f 03 09 eserunt......o.. +| 3600: b3 00 02 03 6c 6f 72 06 01 04 00 04 05 00 05 01 ....lor......... +| 3616: 65 06 02 0a 00 04 03 00 01 03 75 69 73 03 05 02 e.........uis... +| 3632: 00 00 01 65 07 04 05 03 00 02 04 00 01 06 69 75 ...e..........iu +| 3648: 73 6d 6f 64 03 02 04 00 01 03 6c 69 74 03 01 09 smod......lit... +| 3664: 00 01 03 6e 69 6d 03 03 03 00 01 03 73 73 65 03 ...nim......sse. +| 3680: 05 0b 00 02 01 74 03 08 0b 00 01 01 74 03 02 09 .....t......t... +| 3696: 00 01 08 78 63 65 70 64 65 75 72 03 07 02 00 02 ...xcepdeur..... +| 3712: 0a 65 72 63 69 74 61 74 69 6f 6e 03 03 09 00 00 .ercitation..... +| 3728: 06 66 75 67 69 61 74 03 06 05 00 00 02 69 64 03 .fugiat......id. +| 3744: 08 0a 00 01 01 6e 07 05 06 04 00 03 03 00 02 08 .....n.......... +| 3760: 63 69 64 69 64 75 6e 74 03 02 06 00 01 04 70 73 cididunt......ps +| 3776: 75 6c f3 01 03 00 01 04 72 75 72 65 03 05 04 00 ul......rure.... +| 3792: 00 06 6c 61 62 6f 72 65 03 02 08 00 05 02 69 73 ..labore......is +| 3808: 03 03 0b 00 05 02 75 6d 03 08 0c 00 01 04 6f 72 ......um......or +| 3824: 65 6d 03 01 02 00 00 05 6d 61 67 6e 61 03 02 0b em......magna... +| 3840: 00 01 04 69 6e 69 6d 03 03 05 00 01 05 6f 6c 6c ...inim......oll +| 3856: 69 74 03 08 08 00 00 04 6e 69 73 69 03 04 02 00 it......nisi.... +| 3872: 01 02 6f 6e 03 07 06 00 02 05 73 74 72 75 64 03 ..on......strud. +| 3888: 03 08 00 01 04 75 6c 6c 61 03 06 06 00 00 08 6f .....ulla......o +| 3904: 63 63 61 65 63 61 74 03 07 04 00 01 06 66 66 69 ccaecat......ffi +| 3920: 63 69 61 03 08 06 00 00 08 70 61 72 69 61 74 75 cia......pariatu +| 3936: 72 03 06 07 00 01 07 72 6f 69 64 65 6e 74 03 07 r......roident.. +| 3952: 07 00 00 03 71 75 69 03 08 15 00 03 01 73 03 03 ....qui......s.. +| 3968: 07 00 00 0d 72 65 70 72 65 68 65 6e 64 65 72 69 ....reprehenderi +| 3984: 74 03 05 07 00 00 03 73 65 64 03 02 01 ff ff f0 t......sed...... +| 4000: b9 6e 74 03 07 03 00 02 01 74 03 01 05 00 01 03 .nt......t...... +| 4016: 75 6e 74 03 08 02 00 00 06 74 65 6d 70 6f 72 03 unt......tempor. +| 4032: 02 05 00 00 07 75 6c 6c 61 6d 63 6f 03 03 0a 00 .....ullamco.... +| 4048: 01 01 74 09 02 07 00 01 02 00 01 03 00 00 05 76 ..t............v +| 4064: 65 6c 69 74 03 05 0a 00 02 04 6e 69 61 6d 03 03 elit......niam.. +| 4080: 06 00 01 08 6f 6c 75 70 74 61 74 65 03 05 09 00 ....oluptate.... +| page 5 offset 16384 +| 0: 0a 00 00 00 03 0f eb 00 0f fb 0f f3 00 00 00 00 ................ +| 4064: 00 00 00 00 00 00 00 00 00 00 00 07 04 02 08 01 ................ +| 4080: 08 00 03 07 04 02 08 01 04 00 02 04 04 08 08 09 ................ +| page 6 offset 20480 +| 0: 0d 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 ................ +| 4048: 04 08 03 00 0e 0b 04 07 03 00 0e 06 04 06 03 00 ................ +| 4064: 0e 06 04 05 03 00 0e 0a 04 04 03 00 0e 07 04 03 ................ +| 4080: 03 00 0d fa 04 02 03 00 0e 0b 04 00 00 00 00 00 ................ +| page 7 offset 24576 +| 4080: 00 00 00 00 00 00 00 07 00 03 00 00 00 00 00 00 ................ +| end crash-fd33f4b1c8348b.db +}]} {} + +do_catchsql_test 52.1 { + SELECT * FROM t1, t2; +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +# +reset_db +do_test 53.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +.open --hexdb +| size 8192 pagesize 1024 filename crash-7bc.txt.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 04 00 01 01 00 40 20 20 00 00 00 00 00 00 00 08 .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ +| 96: 00 00 00 00 0d 02 f3 00 07 01 51 00 03 c8 03 63 ..........Q....c +| 112: 02 fb 02 0a 02 c0 01 a8 01 51 00 00 00 00 00 00 .........Q...... +| 336: 00 55 07 07 17 1b 1b 01 81 01 74 61 62 6c 65 74 .U........tablet +| 352: 31 5f 73 74 61 74 74 31 5f 73 74 61 74 07 43 52 1_statt1_stat.CR +| 368: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 EATE TABLE 't1_s +| 384: 74 61 74 27 28 69 64 20 49 4e 54 45 47 45 52 20 tat'(id INTEGER +| 400: 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 61 6c PRIMARY KEY, val +| 416: 75 65 20 42 4c 4f 42 29 60 06 07 17 21 21 01 81 ue BLOB)`...!!.. +| 432: 0b 74 61 62 6c 65 74 31 5f 64 6f 63 73 69 7a 65 .tablet1_docsize +| 448: 74 31 5f 64 6f 63 73 69 7a 65 06 43 52 45 41 54 t1_docsize.CREAT +| 464: 45 20 54 41 42 4c 45 20 27 74 31 5f 64 6f 63 73 E TABLE 't1_docs +| 480: 69 7a 65 27 28 64 6f 63 69 64 20 49 4e 54 45 47 ize'(docid INTEG +| 496: 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 ER PRIMARY KEY, +| 512: 73 69 7a 65 20 42 4c 4f 42 29 81 33 04 07 17 1f size BLOB).3.... +| 528: 1f 01 82 35 74 61 62 6c 65 74 31 5f 73 65 67 64 ...5tablet1_segd +| 544: 69 72 74 31 5f 73 65 67 64 69 72 04 43 52 45 41 irt1_segdir.CREA +| 560: 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 TE TABLE 't1_seg +| 576: 64 69 72 27 28 6c 65 76 65 6c 20 49 4e 54 45 47 dir'(level INTEG +| 592: 45 52 2c 69 64 78 20 49 4e 54 45 47 45 52 2c 73 ER,idx INTEGER,s +| 608: 74 61 72 74 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 tart_block INTEG +| 624: 45 52 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c ER,leaves_end_bl +| 640: 6f 63 6b 20 49 4e 54 45 47 45 52 2c 65 6e 64 5f ock INTEGER,end_ +| 656: 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52 2c 72 6f block INTEGER,ro +| 672: 6f 74 20 42 4c 4f 42 2c 50 52 49 4d 41 52 59 20 ot BLOB,PRIMARY +| 688: 4b 45 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 KEY(level, idx)) +| 704: 31 05 06 17 45 1f 01 00 69 6e 64 65 78 73 71 6c 1...E...indexsql +| 720: 69 74 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 ite_autoindex_t1 +| 736: 5f 73 65 67 64 69 72 5f 31 74 31 5f 73 65 67 64 _segdir_1t1_segd +| 752: 69 72 05 00 00 00 08 00 00 00 00 66 03 07 17 23 ir.........f...# +| 768: 23 01 81 13 74 61 62 6c 65 74 31 5f 73 65 67 6d #...tablet1_segm +| 784: 65 6e 74 73 74 31 5f 73 65 67 6d 65 6e 74 73 03 entst1_segments. +| 800: 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 CREATE TABLE 't1 +| 816: 5f 73 65 67 6d 65 6e 74 73 27 28 62 6c 6f 63 6b _segments'(block +| 832: 69 64 20 49 4e 53 45 47 45 52 20 50 52 49 4d 41 id INSEGER PRIMA +| 848: 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c RY KEY, block BL +| 864: 4f 42 29 63 02 07 17 21 21 01 81 11 74 61 62 6c OB)c...!!...tabl +| 880: 65 74 31 5f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f et1_contentt1_co +| 896: 6e 74 65 6e 74 02 43 52 45 41 54 45 20 54 41 42 ntent.CREATE TAB +| 912: 4c 45 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 LE 't1_content'( +| 928: 64 6f 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 docid INTEGER PR +| 944: 49 4d 41 52 59 20 4b 45 59 2c 20 27 63 30 30 27 IMARY KEY, 'c00' +| 960: 2c 20 27 63 31 62 27 29 36 01 06 17 11 11 08 5b , 'c1b')6......[ +| 976: 74 61 62 6c 65 74 31 74 31 43 52 45 41 54 45 20 tablet1t1CREATE +| 992: 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 74 31 VIRTUAL TABLE t1 +| 1008: 20 55 53 49 4e 47 20 66 74 73 34 28 30 2c 62 29 USING fts4(0,b) +| page 2 offset 1024 +| 0: 0d 00 00 00 03 00 0f 00 00 23 00 16 00 0f 00 05 .........#...... +| 16: 03 04 00 08 0f 61 0b 02 04 00 08 1b 41 54 45 20 .....a......ATE +| 32: 32 3a 50 87 5a 01 05 00 08 8f 37 66 30 30 30 30 2:P.Z.....7f0000 +| 48: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 64: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 80: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 96: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 112: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 128: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 144: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 160: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 176: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 192: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 208: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 224: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 240: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 256: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 272: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 288: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 304: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 320: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 336: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 352: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 368: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 384: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 400: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 416: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 432: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 448: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 464: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 480: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 496: 30 40 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0@00000000000000 +| 512: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 528: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 544: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 560: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 576: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 592: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 608: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 624: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 640: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 656: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 672: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 688: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 704: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 720: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 736: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 752: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 768: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 784: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 800: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 816: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 832: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 848: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 864: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 880: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 896: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 912: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 928: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 944: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 960: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 976: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 992: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 1008: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| page 3 offset 2048 +| 0: 0d 00 00 00 02 03 86 00 03 f4 03 86 00 00 00 00 ................ +| 896: 00 00 00 00 00 00 87 62 02 04 00 8f 48 00 d5 07 .......b....H... +| 912: 66 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 f000000000000000 +| 928: 30 30 30 30 3a 30 30 30 30 30 30 30 30 30 30 30 0000:00000000000 +| 944: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 960: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 976: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 992: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 1008: 00 00 00 08 0a 01 03 00 1a 00 01 30 03 01 02 00 ...........0.... +| page 4 offset 3072 +| 0: 0d 00 00 00 03 03 9e 00 03 ed 03 bc 03 9e 00 00 ................ +| 912: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1c 03 ................ +| 928: 07 08 01 08 08 15 2c 02 30 20 31 36 00 01 30 03 ......,.0 16..0. +| 944: 03 02 00 00 01 61 05 03 01 01 02 00 2f 02 07 08 .....a....../... +| 960: 09 08 08 15 54 30 20 33 36 00 01 30 03 02 02 00 ....T0 36..0.... +| 976: 00 01 32 05 02 01 01 03 00 00 03 61 74 65 05 02 ..2........ate.. +| 992: 01 01 02 00 00 01 70 05 02 01 01 04 00 11 01 07 ......p......... +| 1008: 08 08 09 01 17 14 02 32 20 39 39 37 01 01 01 66 .......2 997...f +| page 5 offset 4096 +| 0: 0a 00 00 00 03 03 ee 00 03 fb 03 f5 03 ee 00 00 ................ +| 992: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 06 04 ................ +| 1008: 08 01 01 02 03 05 04 08 09 01 02 04 04 08 08 09 ................ +| page 6 offset 5120 +| 0: 0d 00 00 00 03 03 eb 00 00 00 00 00 00 00 00 00 ................ +| 992: 00 00 00 00 00 00 00 00 00 00 00 05 03 03 00 10 ................ +| 1008: 01 01 05 02 03 00 10 01 03 05 01 03 00 10 01 01 ................ +| page 7 offset 6144 +| 0: 0d 00 00 00 01 03 f6 00 03 f6 00 00 00 00 00 00 ................ +| 1008: 00 00 00 00 00 00 08 00 03 00 16 03 08 c5 e0 07 ................ +| page 8 offset 7168 +| 0: 00 00 00 00 30 30 30 30 30 30 30 30 30 30 30 30 ....000000000000 +| 16: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 32: 30 30 30 30 30 30 30 30 30 30 30 30 30 bc 30 30 0000000000000.00 +| 48: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 64: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 80: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 96: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 112: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 128: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 144: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 160: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 176: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 192: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 c0 30 00000000000000.0 +| 208: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 224: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 240: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 256: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 272: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 288: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 304: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 320: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 336: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 352: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 368: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 384: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 400: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 416: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 432: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 448: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 464: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 480: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 496: 30 30 30 30 30 30 30 30 30 30 30 40 30 30 30 30 00000000000@0000 +| 512: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 528: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 544: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 560: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 576: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 592: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 608: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 624: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 640: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 656: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 672: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 688: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 704: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 720: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 736: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 752: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 768: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 784: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 800: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 816: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 832: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 848: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 864: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 880: 30 30 30 30 30 30 30 30 30 05 01 00 00 00 00 00 000000000....... +| end crash-7bc.txt.db +}]} {} + +do_execsql_test 53.1 { + SELECT*FROM t1 WHERE t1 MATCH'ATE"0"OR"2D:P"""ATE"0"OR"2:P"""'; +} {0 {ATE 2:P}} +set sqlite_fts3_enable_parentheses $saved + +#------------------------------------------------------------------------- +# +reset_db +do_test 54.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +.open --hexdb +| size 8192 pagesize 1024 filename crash-365.txt.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 04 00 01 01 00 40 20 20 00 00 00 00 00 00 00 08 .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 04 ................ +| 96: 00 00 00 00 0d 02 f3 00 07 01 51 00 03 c8 03 63 ..........Q....c +| 112: 02 fb 02 0a 02 c0 01 a8 01 51 00 00 00 00 00 00 .........Q...... +| 336: 00 55 07 07 17 1b 1b 01 81 01 74 61 62 6c 65 74 .U........tablet +| 352: 31 5f 73 74 61 74 74 31 5f 73 74 61 74 07 43 52 1_statt1_stat.CR +| 368: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 EATE TABLE 't1_s +| 384: 74 61 74 27 28 69 64 20 49 4e 54 45 47 45 52 20 tat'(id INTEGER +| 400: 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 61 6c PRIMARY KEY, val +| 416: 75 65 20 42 4c 4f 42 29 60 06 07 17 21 21 01 81 ue BLOB)`...!!.. +| 432: 0b 74 61 62 6c 65 74 31 5f 64 6f 63 73 69 7a 65 .tablet1_docsize +| 448: 74 31 5f 64 6f 63 73 69 7a 65 06 43 52 45 41 54 t1_docsize.CREAT +| 464: 45 20 54 41 42 4c 45 20 27 74 31 5f 64 6f 63 73 E TABLE 't1_docs +| 480: 69 7a 65 27 28 64 6f 63 69 64 20 49 4e 54 45 47 ize'(docid INTEG +| 496: 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 ER PRIMARY KEY, +| 512: 73 69 7a 65 20 42 4c 4f 42 29 81 33 04 07 17 1f size BLOB).3.... +| 528: 1f 01 82 35 74 61 62 6c 65 74 31 5f 73 65 67 64 ...5tablet1_segd +| 544: 69 72 74 31 5f 73 65 67 64 69 72 04 43 52 45 41 irt1_segdir.CREA +| 560: 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 TE TABLE 't1_seg +| 576: 64 69 72 27 28 6c 65 76 65 6c 20 49 4e 54 45 47 dir'(level INTEG +| 592: 45 52 2c 69 64 78 20 49 4e 54 45 47 45 52 2c 73 ER,idx INTEGER,s +| 608: 74 61 72 74 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 tart_block INTEG +| 624: 45 52 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c ER,leaves_end_bl +| 640: 6f 63 6b 20 49 4e 54 45 47 45 52 2c 65 6e 64 5f ock INTEGER,end_ +| 656: 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52 2c 72 6f block INTEGER,ro +| 672: 6f 74 20 42 4c 4f 42 2c 50 52 49 4d 41 52 59 20 ot BLOB,PRIMARY +| 688: 4b 45 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 KEY(level, idx)) +| 704: 31 05 06 17 45 1f 01 00 69 6e 64 65 78 73 71 6c 1...E...indexsql +| 720: 69 74 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 ite_autoindex_t1 +| 736: 5f 73 65 67 64 69 72 5f 31 74 31 5f 73 65 67 64 _segdir_1t1_segd +| 752: 69 72 05 00 00 00 08 00 00 00 00 66 03 07 17 23 ir.........f...# +| 768: 23 01 81 13 74 61 62 6c 65 74 31 5f 73 65 67 6d #...tablet1_segm +| 784: 65 6e 74 73 74 31 5f 73 65 67 6d 65 6e 74 73 03 entst1_segments. +| 800: 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 CREATE TABLE 't1 +| 816: 5f 73 65 67 6d 65 6e 74 73 27 28 62 6c 6f 63 6b _segments'(block +| 832: 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 id INTEGER PRIMA +| 848: 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c RY KEY, block BL +| 864: 4f 42 29 63 02 07 17 21 21 01 81 11 74 61 62 6c OB)c...!!...tabl +| 880: 65 74 31 5f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f et1_contentt1_co +| 896: 6e 74 65 6e 74 02 43 52 45 41 54 45 20 54 41 42 ntent.CREATE TAB +| 912: 4c 45 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 LE 't1_content'( +| 928: 64 6f 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 docid INTEGER PR +| 944: 49 4d 41 52 59 20 4b 45 59 2c 20 27 63 30 30 27 IMARY KEY, 'c00' +| 960: 2c 20 27 63 31 62 27 29 36 01 06 17 11 11 08 5b , 'c1b')6......[ +| 976: 74 61 62 6c 65 74 31 74 31 43 52 45 41 54 45 20 tablet1t1CREATE +| 992: 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 74 31 VIRTUAL TABLE t1 +| 1008: 20 55 53 49 4e 47 20 66 74 73 34 28 30 2c 62 29 USING fts4(0,b) +| page 2 offset 1024 +| 0: 0d 00 00 00 03 00 0f 00 00 23 00 16 00 0f 00 05 .........#...... +| 16: 03 04 00 08 0f 61 0b 02 04 00 08 1b 41 54 45 20 .....a......ATE +| 32: 32 3a 50 87 5a 01 05 00 08 8f 37 66 30 30 30 30 2:P.Z.....7f0000 +| 48: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 64: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 80: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 96: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 112: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 128: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 144: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 160: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 176: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 192: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 208: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 224: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 240: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 256: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 272: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 288: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 304: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 320: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 336: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 352: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 368: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 384: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 400: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 416: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 432: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 448: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 464: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 480: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 496: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 512: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 528: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 544: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 560: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 576: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 592: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 608: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 624: 30 30 30 30 30 30 30 30 30 30 1b 30 30 30 30 30 0000000000.00000 +| 640: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 656: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 672: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 688: 30 30 30 30 30 30 30 30 2f 30 30 30 30 30 30 30 00000000/0000000 +| 704: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 720: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 736: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 752: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 768: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 784: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 800: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 816: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 832: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 848: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 864: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 880: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 896: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 912: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 928: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 944: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 960: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 976: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 992: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 1008: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| page 3 offset 2048 +| 0: 0d 00 00 00 02 03 86 00 03 f4 03 86 00 00 00 00 ................ +| 896: 00 00 00 00 00 00 87 62 02 04 00 8f 48 00 d5 07 .......b....H... +| 912: 66 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 f000000000000000 +| 928: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 944: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 960: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 976: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 992: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 1008: 00 00 00 08 0a 01 03 00 1a 00 01 30 03 01 02 00 ...........0.... +| page 4 offset 3072 +| 0: 0d 00 00 00 03 03 9e 00 03 ed 03 bc 03 9e 00 01 ................ +| 912: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1c 03 ................ +| 928: 07 08 01 08 08 15 2c 02 30 20 31 36 00 01 30 03 ......,.0 16..0. +| 944: 03 02 00 00 01 61 05 03 01 01 02 00 2f 02 07 08 .....a....../... +| 960: 09 08 08 15 54 30 20 33 36 00 01 30 03 02 02 00 ....T0 36..0.... +| 976: 00 01 32 05 02 01 01 03 00 00 03 61 74 65 05 02 ..2........ate.. +| 992: 01 01 02 00 00 01 70 05 02 01 01 04 00 11 01 07 ......p......... +| 1008: 08 08 09 01 17 14 02 32 20 39 39 37 01 01 01 66 .......2 997...f +| page 5 offset 4096 +| 0: 0a 00 00 00 03 03 ee 00 03 fb 03 f5 03 ee 00 00 ................ +| 992: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 06 04 ................ +| 1008: 08 01 01 02 03 05 04 08 09 01 02 04 04 08 08 09 ................ +| page 6 offset 5120 +| 0: 0d 00 00 00 03 03 eb 00 03 f9 03 f2 00 00 00 00 ................ +| 992: 00 00 00 00 00 00 00 00 00 00 00 05 03 03 00 10 ................ +| 1008: 01 01 05 02 03 00 10 01 03 05 01 03 00 10 01 01 ................ +| page 7 offset 6144 +| 0: 0d 00 00 00 01 03 f6 00 03 f6 00 00 00 00 00 00 ................ +| 1008: 00 00 00 00 00 00 08 00 03 00 16 03 03 05 e0 07 ................ +| page 8 offset 7168 +| 0: 00 00 00 00 30 30 30 30 30 30 30 30 30 30 30 30 ....000000000000 +| 16: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 32: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 48: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 64: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 80: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 96: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 112: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 128: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 144: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 160: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 176: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 192: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 208: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 224: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 240: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 256: 30 30 30 30 30 2f 30 30 30 30 30 30 30 30 30 30 00000/0000000000 +| 272: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 288: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 304: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 320: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 336: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 352: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 368: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 384: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 400: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 416: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 432: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 448: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 464: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 480: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 496: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 512: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 528: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 544: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 560: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 576: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 592: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 608: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 624: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 640: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 656: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 672: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 688: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 704: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 720: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 736: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 752: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 768: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 784: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 800: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 816: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 832: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 848: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 864: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000 +| 880: 30 30 30 30 30 30 30 30 30 05 01 01 01 02 00 00 000000000....... +| end crash-365.txt.db +}]} {} + +do_execsql_test 54.1 { + SELECT rowid, quote(matchinfo(t1,'pcxybspcxybs')) FROM t1 WHERE t1 MATCH'ATE"0"OR"2:P"""'; +} + +finish_test diff --git a/test/fts3corrupt5.test b/test/fts3corrupt5.test new file mode 100644 index 0000000..a8a3b01 --- /dev/null +++ b/test/fts3corrupt5.test @@ -0,0 +1,59 @@ +# 2019 May 22 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/fts3_common.tcl +set testprefix fts3corrupt5 + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +sqlite3_fts3_may_be_corrupt 1 + +do_execsql_test 1.0 { + BEGIN; + CREATE VIRTUAL TABLE ft USING fts3(a, b, c); + INSERT INTO ft VALUES('one', 'one', 'one'); + COMMIT; +} + +do_execsql_test 1.1 { + SELECT * FROM ft WHERE ft MATCH 'b:one' +} {one one one} + +do_execsql_test 1.2 { + SELECT quote(root) FROM ft_segdir; +} {X'00036F6E6509010201010201020200'} + +breakpoint +foreach {tn val q bCorrupt} { + 1 X'00036F6E650901' 'b:one' 1 + 2 X'00036F6E6509010201010201FFFFFF' 'c:one' 1 + 3 X'00036F6E6501' 'b:one' 1 + 4 X'00036F6E650101' 'b:one' 1 + 5 X'00036F6E650100' 'b:one' 0 +} { + do_execsql_test 1.3.$tn.1 "UPDATE ft_segdir SET root = $val" + + set res {0 {}} + if {$bCorrupt} { set res {1 {database disk image is malformed}}} + do_catchsql_test 1.3.$tn.2 { + SELECT * FROM ft WHERE ft MATCH $q + } $res +} + +finish_test diff --git a/test/fts3corrupt6.test b/test/fts3corrupt6.test new file mode 100644 index 0000000..a3c5fd8 --- /dev/null +++ b/test/fts3corrupt6.test @@ -0,0 +1,79 @@ +# 2020 June 8 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS3 module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/fts3_common.tcl +set testprefix fts3corrupt6 + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +set ::saved_sqlite_fts3_enable_parentheses $::sqlite_fts3_enable_parentheses +set sqlite_fts3_enable_parentheses 1 +sqlite3_fts3_may_be_corrupt 1 +database_may_be_corrupt + +do_execsql_test 1.0 { + BEGIN TRANSACTION; + CREATE TABLE t_content(col0 INTEGER); + PRAGMA writable_schema=ON; + CREATE VIRTUAL TABLE t0 USING fts3(col0 INTEGER PRIMARY KEY,col1 VARCHAR(8),col2 BINARY,col3 BINARY); + INSERT INTO t0_content VALUES(0,NULL,NULL,NULL,NULL); + INSERT INTO t0_segdir VALUES(0,0,0,0,'0 42',X'000131030102000103323334050101010200000461616161050101020200000462626262050101030200'); + COMMIT; +} + +do_execsql_test 1.1 { + SELECT 0+matchinfo(t0,'yxyyxy') FROM t0 WHERE t0 MATCH CAST( x'2b0a312b0a312a312a2a0b5d0a0b0b0a312a0a0b0b0a312a0b310a392a0b0a27312a2a0b5d0a312a0b310a31315d0b310a312a316d2a0b313b15bceaa50a312a0b0a27312a2a0b5d0a312a0b310a312b0b2a310a312a0b2a0b2a0b2e5d0a0bff313336e34a2a312a0b0a3c310b0a0b4b4b0b4b2a4bec40322b2a0b310a0a312a0a0a0a0a0a0a0a0a0b310a312a2a2a0b5d0a0b0b0a312a0b310a312a0b0a4e4541530b310a5df5ced70a0a0a0a0a4f520a0a0a0a0a0a0a312a0b0a4e4541520b310a5d616161610a0a0a0a4f520a0a0a0a0a0a312b0a312a312a0a0a0a0a0a0a004a0b0a310b220a0b0a310a4a22310a0b0a7e6fe0e0e030e0e0e0e0e01176e02000e0e0e0e0e01131320226310a0b0a310a4a22310a0b0a310a766f8b8b4ee0e0300ae0090909090909090909090909090909090909090909090909090909090909090947aaaa540b09090909090909090909090909090909090909090909090909090909090909fae0e0f2f22164e0e0f273e07fefefef7d6dfafafafa6d6d6d6d' AS TEXT); +} {0} + +do_execsql_test 1.2 { + CREATE VIRTUAL TABLE t1 USING fts3(col0 INTEGER PRIMARY KEY,col1 VARCHAR(8),col2 BINARY,col3 BINARY); + INSERT INTO t1_content VALUES(0,NULL,NULL,NULL,NULL); + INSERT INTO t1_segdir VALUES(0,0,0,0,'0 42',X'000131030102000103323334050101010200000461616161050101020200000462626262050101030200'); +} + +do_execsql_test 1.3 { + SELECT 42+matchinfo(t1,'yxyyxy') FROM t1 WHERE t1 MATCH x'2b0a312b0a312a312a2a0b5d0a0b0b0a312a0a0b0b0a312a0b310a392a0b0a27312a2a0b5d0a312a0b310a31315d0b310a312a316d2a0b313b15bceaa50a312a0b0a27312a2a0b5d0a312a0b310a312b0b2a310a312a0b2a0b2a0b2e5d0a0bff313336e34a2a312a0b0a3c310b0a0b4b4b0b4b2a4bec40322b2a0b310a0a312a0a0a0a0a0a0a0a0a0b310a312a2a2a0b5d0a0b0b0a312a0b310a312a0b0a4e4541530b310a5df5ced70a0a0a0a0a4f520a0a0a0a0a0a0a312a0b0a4e4541520b310a5d616161610a0a0a0a4f520a0a0a0a0a0a312b0a312a312a0a0a0a0a0a0a004a0b0a310b220a0b0a310a4a22310a0b0a7e6fe0e0e030e0e0e0e0e01176e02000e0e0e0e0e01131320226310a0b0a310a4a22310a0b0a310a766f8b8b4ee0e0300ae0090909090909090909090909090909090909090909090909090909090909090947aaaa540b09090909090909090909090909090909090909090909090909090909090909fae0e0f2f22164e0e0f273e07fefefef7d6dfafafafa6d6d6d6d'; +} {42} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 2.0 { + CREATE VIRTUAL TABLE t0 USING fts3(a); + INSERT INTO t0_segdir VALUES(0,0,0,0,'0 42',X'000131030782000103323334050100fff200010461616161050101020200000462626262050101030200'); +} +do_execsql_test 2.1 { + SELECT count(*) FROM t0 WHERE t0 MATCH '(1 NEAR 1) AND (aaaa OR 1)'; +} 1 + +#------------------------------------------------------------------------- +reset_db +breakpoint +do_catchsql_test 3.0 { + CREATE VIRTUAL TABLE main.Table0 USING fts3(); + INSERT INTO Table0 VALUES (1), (printf('%8.1280000X') ), (1), (printf('%8.1280000X') ), (1) ; + INSERT INTO Table0 VALUES (0), (printf('%8.1280000X%8.1280000X') ), (1), (printf('%1280000.1280000X%#1280000.1280000E%8.1280000X') ), (1) ; + INSERT INTO Table0 VALUES (1) ; + UPDATE Table0_segdir SET start_block = 1; + INSERT INTO Table0 VALUES (1) ; + INSERT INTO Table0(Table0) VALUES('merge=6,8'); +} {1 {database disk image is malformed}} + +set sqlite_fts3_enable_parentheses $saved_sqlite_fts3_enable_parentheses +finish_test diff --git a/test/fts3cov.test b/test/fts3cov.test new file mode 100644 index 0000000..5d83836 --- /dev/null +++ b/test/fts3cov.test @@ -0,0 +1,434 @@ +# 2009 December 03 +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# The tests in this file are structural coverage tests for FTS3. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If this build does not include FTS3, skip the tests in this file. +# +ifcapable !fts3 { finish_test ; return } +source $testdir/fts3_common.tcl +source $testdir/malloc_common.tcl + +set DO_MALLOC_TEST 0 +set testprefix fts3cov + +#-------------------------------------------------------------------------- +# When it first needs to read a block from the %_segments table, the FTS3 +# module compiles an SQL statement for that purpose. The statement is +# stored and reused each subsequent time a block is read. This test case +# tests the effects of an OOM error occuring while compiling the statement. +# +# Similarly, when FTS3 first needs to scan through a set of segment leaves +# to find a set of documents that matches a term, it allocates a string +# containing the text of the required SQL, and compiles one or more +# statements to traverse the leaves. This test case tests that OOM errors +# that occur while allocating this string and statement are handled correctly +# also. +# +do_test fts3cov-1.1 { + execsql { + CREATE VIRTUAL TABLE t1 USING fts3(x); + INSERT INTO t1(t1) VALUES('nodesize=24'); + BEGIN; + INSERT INTO t1 VALUES('Is the night chilly and dark?'); + INSERT INTO t1 VALUES('The night is chilly, but not dark.'); + INSERT INTO t1 VALUES('The thin gray cloud is spread on high,'); + INSERT INTO t1 VALUES('It covers but not hides the sky.'); + COMMIT; + SELECT count(*)>0 FROM t1_segments; + } +} {1} + +set DO_MALLOC_TEST 1 +do_restart_select_test fts3cov-1.2 { + SELECT docid FROM t1 WHERE t1 MATCH 'chilly'; +} {1 2} +set DO_MALLOC_TEST 0 + +#-------------------------------------------------------------------------- +# When querying the full-text index, if an expected internal node block is +# missing from the %_segments table, or if a NULL value is stored in the +# %_segments table instead of a binary blob, database corruption should be +# reported. +# +# Even with tiny 24 byte nodes, it takes a fair bit of data to produce a +# segment b-tree that uses the %_segments table to store internal nodes. +# +do_test fts3cov-2.1 { + execsql { + INSERT INTO t1(t1) VALUES('nodesize=24'); + BEGIN; + INSERT INTO t1 VALUES('The moon is behind, and at the full;'); + INSERT INTO t1 VALUES('And yet she looks both small and dull.'); + INSERT INTO t1 VALUES('The night is chill, the cloud is gray:'); + INSERT INTO t1 VALUES('''T is a month before the month of May,'); + INSERT INTO t1 VALUES('And the Spring comes slowly up this way.'); + INSERT INTO t1 VALUES('The lovely lady, Christabel,'); + INSERT INTO t1 VALUES('Whom her father loves so well,'); + INSERT INTO t1 VALUES('What makes her in the wood so late,'); + INSERT INTO t1 VALUES('A furlong from the castle gate?'); + INSERT INTO t1 VALUES('She had dreams all yesternight'); + INSERT INTO t1 VALUES('Of her own betrothed knight;'); + INSERT INTO t1 VALUES('And she in the midnight wood will pray'); + INSERT INTO t1 VALUES('For the weal of her lover that''s far away.'); + COMMIT; + } + execsql { + INSERT INTO t1(t1) VALUES('optimize'); + SELECT substr(hex(root), 1, 2) FROM t1_segdir; + } +} {03} + +# Test the "missing entry" case: +sqlite3_db_config db DEFENSIVE 0 +do_test fts3cov-2.2 { + set root [db one {SELECT root FROM t1_segdir}] + read_fts3varint [string range $root 1 end] left_child + execsql { DELETE FROM t1_segments WHERE blockid = $left_child } +} {} +do_error_test fts3cov-2.3 { + SELECT * FROM t1 WHERE t1 MATCH 'c*' +} {database disk image is malformed} + +# Test the "replaced with NULL" case: +do_test fts3cov-2.4 { + execsql { INSERT INTO t1_segments VALUES($left_child, NULL) } +} {} +do_error_test fts3cov-2.5 { + SELECT * FROM t1 WHERE t1 MATCH 'cloud' +} {database disk image is malformed} + +#-------------------------------------------------------------------------- +# The following tests are to test the effects of OOM errors while storing +# terms in the pending-hash table. Specifically, while creating doclist +# blobs to store in the table. More specifically, to test OOM errors while +# appending column numbers to doclists. For example, if a doclist consists +# of: +# +# 0x01 +# +# The following tests check that malloc errors encountered while appending +# the "0x01 " data to the dynamically growable blob used to +# accumulate the doclist in memory are handled correctly. +# +do_test fts3cov-3.1 { + set cols [list] + set vals [list] + for {set i 0} {$i < 120} {incr i} { + lappend cols "col$i" + lappend vals "'word'" + } + execsql "CREATE VIRTUAL TABLE t2 USING fts3([join $cols ,])" +} {} +set DO_MALLOC_TEST 1 +do_write_test fts3cov-3.2 t2_content " + INSERT INTO t2(docid, [join $cols ,]) VALUES(1, [join $vals ,]) +" +do_write_test fts3cov-3.3 t2_content " + INSERT INTO t2(docid, [join $cols ,]) VALUES(200, [join $vals ,]) +" +do_write_test fts3cov-3.4 t2_content " + INSERT INTO t2(docid, [join $cols ,]) VALUES(60000, [join $vals ,]) +" + +#------------------------------------------------------------------------- +# If too much data accumulates in the pending-terms hash table, it is +# flushed to the database automatically, even if the transaction has not +# finished. The following tests check the effects of encountering an OOM +# while doing this. +# +do_test fts3cov-4.1 { + execsql { + CREATE VIRTUAL TABLE t3 USING fts3(x); + INSERT INTO t3(t3) VALUES('nodesize=24'); + INSERT INTO t3(t3) VALUES('maxpending=100'); + } +} {} +set DO_MALLOC_TEST 1 +do_write_test fts3cov-4.2 t3_content { + INSERT INTO t3(docid, x) + SELECT 1, 'Then Christabel stretched forth her hand,' UNION ALL + SELECT 3, 'And comforted fair Geraldine:' UNION ALL + SELECT 4, '''O well, bright dame, may you command' UNION ALL + SELECT 5, 'The service of Sir Leoline;' UNION ALL + SELECT 2, 'And gladly our stout chivalry' UNION ALL + SELECT 7, 'Will he send forth, and friends withal,' UNION ALL + SELECT 8, 'To guide and guard you safe and free' UNION ALL + SELECT 6, 'Home to your noble father''s hall.''' +} + +#------------------------------------------------------------------------- +# When building the internal tree structure for each segment b-tree, FTS3 +# assumes that the content of each internal node will be less than +# $nodesize bytes, where $nodesize is the advisory node size. If this turns +# out to be untrue, then an extra buffer must be malloc'd for each term. +# This test case tests these paths and the effects of said mallocs failing +# by inserting insert a document with some fairly large terms into a +# full-text table with a very small node-size. +# +# Test this handling of large terms in three contexts: +# +# 1. When flushing the pending-terms table. +# 2. When optimizing the data structures using the INSERT syntax. +# 2. When optimizing the data structures using the deprecated SELECT syntax. +# +do_test fts3cov-5.1 { + execsql { + CREATE VIRTUAL TABLE t4 USING fts3(x); + INSERT INTO t4(t4) VALUES('nodesize=24'); + } +} {} +set DO_MALLOC_TEST 1 + +# Test when flushing pending-terms table. +do_write_test fts3cov-5.2 t4_content { + INSERT INTO t4 + SELECT 'ItisanancientMarinerAndhestoppethoneofthreeAA' UNION ALL + SELECT 'ItisanancientMarinerAndhestoppethoneofthreeBB' UNION ALL + SELECT 'ItisanancientMarinerAndhestoppethoneofthreeCC' UNION ALL + SELECT 'BythylonggreybeardandglitteringeyeNowwhereforestoppstAA' UNION ALL + SELECT 'BythylonggreybeardandglitteringeyeNowwhereforestoppstBB' UNION ALL + SELECT 'BythylonggreybeardandglitteringeyeNowwhereforestoppstCC' +} + +# Test when optimizing via INSERT. +do_test fts3cov-5.3 { execsql { INSERT INTO t4 VALUES('extra!') } } {} +do_write_test fts3cov-5.2 t4_segments { INSERT INTO t4(t4) VALUES('optimize') } + +# Test when optimizing via SELECT. +do_test fts3cov-5.5 { execsql { INSERT INTO t4 VALUES('more extra!') } } {} +do_write_test fts3cov-5.6 t4_segments { + SELECT * FROM (SELECT optimize(t4) FROM t4 LIMIT 1) + EXCEPT SELECT 'Index optimized' +} + +#------------------------------------------------------------------------- +# When merging all segments at a given level to create a single segment +# at level+1, FTS3 runs a query of the form: +# +# SELECT count(*) FROM %_segdir WHERE level = ? +# +# The query is compiled the first time this operation is required and +# reused thereafter. This test aims to test the effects of an OOM while +# preparing and executing this query for the first time. +# +# Then, keep inserting rows into the table so that the effects of an OOM +# while re-executing the same query can also be tested. +# +do_test fts3cov-6.1 { + execsql { CREATE VIRTUAL TABLE t5 USING fts3(x) } + for {set i 0} {$i<16} {incr i} { execsql "INSERT INTO t5 VALUES('term$i')" } + execsql { SELECT count(*) FROM t5_segdir } +} {16} + +# First time. +db close +sqlite3 db test.db +do_write_test fts3cov-6.2 t5_content { + INSERT INTO t5 VALUES('segment number 16!'); +} + +# Second time. +do_test fts3cov-6.3 { + for {set i 1} {$i<16} {incr i} { execsql "INSERT INTO t5 VALUES('term$i')" } + execsql { SELECT count(*) FROM t5_segdir } +} {17} +do_write_test fts3cov-6.4 t5_content { + INSERT INTO t5 VALUES('segment number 16!'); +} + +#------------------------------------------------------------------------- +# Update the docid of a row. Test this in two scenarios: +# +# 1. When the row being updated is the only row in the table. +# 2. When it is not. +# +# The two cases above take different paths because in case 1 all data +# structures can simply be emptied before inserting the new row record. +# In case 2, the data structures actually have to be updated. +# +do_test fts3cov-7.1 { + execsql { + CREATE VIRTUAL TABLE t7 USING fts3(a, b, c); + INSERT INTO t7 VALUES('A', 'B', 'C'); + UPDATE t7 SET docid = 5; + SELECT docid, * FROM t7; + } +} {5 A B C} +do_test fts3cov-7.2 { + execsql { + INSERT INTO t7 VALUES('D', 'E', 'F'); + UPDATE t7 SET docid = 1 WHERE docid = 6; + SELECT docid, * FROM t7; + } +} {1 D E F 5 A B C} + +#------------------------------------------------------------------------- +# If a set of documents are modified within a transaction, the +# pending-terms table must be flushed each time a document with a docid +# less than or equal to the previous docid is modified. +# +# This test checks the effects of an OOM error occuring when the +# pending-terms table is flushed for this reason as part of a DELETE +# statement. +# +do_malloc_test fts3cov-8 -sqlprep { + BEGIN; + CREATE VIRTUAL TABLE t8 USING fts3; + INSERT INTO t8 VALUES('the output of each batch run'); + INSERT INTO t8 VALUES('(possibly a day''s work)'); + INSERT INTO t8 VALUES('was written to two separate disks'); + COMMIT; +} -sqlbody { + BEGIN; + DELETE FROM t8 WHERE rowid = 3; + DELETE FROM t8 WHERE rowid = 2; + DELETE FROM t8 WHERE rowid = 1; + COMMIT; +} + +#------------------------------------------------------------------------- +# Test some branches in the code that handles "special" inserts like: +# +# INSERT INTO t1(t1) VALUES('optimize'); +# +# Also test that an optimize (INSERT method) works on an empty table. +# +set DO_MALLOC_TEST 0 +do_test fts3cov-9.1 { + execsql { CREATE VIRTUAL TABLE xx USING fts3 } +} {} +do_error_test fts3cov-9.2 { + INSERT INTO xx(xx) VALUES('optimise'); -- British spelling +} {SQL logic error} +do_error_test fts3cov-9.3 { + INSERT INTO xx(xx) VALUES('short'); +} {SQL logic error} +do_error_test fts3cov-9.4 { + INSERT INTO xx(xx) VALUES('waytoolongtobecorrect'); +} {SQL logic error} +do_test fts3cov-9.5 { + execsql { INSERT INTO xx(xx) VALUES('optimize') } +} {} + +#------------------------------------------------------------------------- +# Test that a table can be optimized in the middle of a transaction when +# the pending-terms table is non-empty. This case involves some extra +# branches because data must be read not only from the database, but +# also from the pending-terms table. +# +do_malloc_test fts3cov-10 -sqlprep { + CREATE VIRTUAL TABLE t10 USING fts3; + INSERT INTO t10 VALUES('Optimising images for the web is a tricky business'); + BEGIN; + INSERT INTO t10 VALUES('You have to get the right balance between'); +} -sqlbody { + INSERT INTO t10(t10) VALUES('optimize'); +} + +#------------------------------------------------------------------------- +# Test a full-text query for a term that was once in the index, but is +# no longer. +# +do_test fts3cov-11.1 { + execsql { + CREATE VIRTUAL TABLE xx USING fts3; + INSERT INTO xx VALUES('one two three'); + INSERT INTO xx VALUES('four five six'); + DELETE FROM xx WHERE docid = 1; + } + execsql { SELECT * FROM xx WHERE xx MATCH 'two' } +} {} + + +do_malloc_test fts3cov-12 -sqlprep { + CREATE VIRTUAL TABLE t12 USING fts3; + INSERT INTO t12 VALUES('is one of the two togther'); + BEGIN; + INSERT INTO t12 VALUES('one which was appropriate at the time'); +} -sqlbody { + SELECT * FROM t12 WHERE t12 MATCH 'one' +} + +do_malloc_test fts3cov-13 -sqlprep { + PRAGMA encoding = 'UTF-16'; + CREATE VIRTUAL TABLE t13 USING fts3; + INSERT INTO t13 VALUES('two scalar functions'); + INSERT INTO t13 VALUES('scalar two functions'); + INSERT INTO t13 VALUES('functions scalar two'); +} -sqlbody { + SELECT snippet(t13, '%%', '%%', '#') FROM t13 WHERE t13 MATCH 'two'; + SELECT snippet(t13, '%%', '%%') FROM t13 WHERE t13 MATCH 'two'; + SELECT snippet(t13, '%%') FROM t13 WHERE t13 MATCH 'two'; +} + +do_execsql_test 14.0 { + CREATE VIRTUAL TABLE t14 USING fts4(a, b); + INSERT INTO t14 VALUES('one two three', 'one three four'); + INSERT INTO t14 VALUES('a b c', 'd e a'); +} +do_execsql_test 14.1 { + SELECT rowid FROM t14 WHERE t14 MATCH '"one two three"' +} {1} +do_execsql_test 14.2 { + SELECT rowid FROM t14 WHERE t14 MATCH '"one four"' +} {} +do_execsql_test 14.3 { + SELECT rowid FROM t14 WHERE t14 MATCH '"e a"' +} {2} +do_execsql_test 14.5 { + SELECT rowid FROM t14 WHERE t14 MATCH '"e b"' +} {} +do_catchsql_test 14.6 { + SELECT rowid FROM t14 WHERE rowid MATCH 'one' +} {1 {unable to use function MATCH in the requested context}} +do_catchsql_test 14.7 { + SELECT rowid FROM t14 WHERE docid MATCH 'one' +} {1 {unable to use function MATCH in the requested context}} + +do_execsql_test 15.0 { + CREATE VIRTUAL TABLE t15 USING fts4(a, b, c); + INSERT INTO t15 VALUES('abc def ghi', 'abc2 def2 ghi2', 'abc3 def3 ghi3'); + INSERT INTO t15 VALUES('abc2 def2 ghi2', 'abc2 def2 ghi2', 'abc def3 ghi3'); +} +do_execsql_test 15.1 { + SELECT rowid FROM t15 WHERE t15 MATCH '"abc* def2"' +} {1 2} + +# Test a corruption case. +# +sqlite3_db_config db DEFENSIVE 0 +do_execsql_test 16.1 { + CREATE VIRTUAL TABLE t16 USING fts4; + INSERT INTO t16 VALUES('theoretical work to examine the relationship'); + INSERT INTO t16 VALUES('solution of our problems on the invisible'); + DELETE FROM t16_content WHERE rowid = 2; +} +do_catchsql_test 16.2 { + SELECT * FROM t16 WHERE t16 MATCH 'invisible' +} {1 {database disk image is malformed}} + +# And another corruption test case. +# +do_execsql_test 17.1 { + CREATE VIRTUAL TABLE t17 USING fts4; + INSERT INTO t17(content) VALUES('one one one'); + UPDATE t17_segdir SET root = X'00036F6E65FFFFFFFFFFFFFFFFFFFFFF02030300' +} {} +do_catchsql_test 17.2 { + SELECT * FROM t17 WHERE t17 MATCH 'one' +} {1 {database disk image is malformed}} + + + + +finish_test diff --git a/test/fts3d.test b/test/fts3d.test new file mode 100644 index 0000000..b0547ce --- /dev/null +++ b/test/fts3d.test @@ -0,0 +1,372 @@ +# 2008 June 26 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The focus +# of this script is testing the FTS3 module's optimize() function. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/fts3_common.tcl + +# If SQLITE_ENABLE_FTS3 is not defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +#************************************************************************* +# Utility function to check for the expected terms in the segment +# level/index. _all version does same but for entire index. +proc check_terms {test level index terms} { + set where "level = $level AND idx = $index" + do_test $test.terms [list fts3_terms t1 $where] $terms +} +proc check_terms_all {test terms} { + do_test $test.terms [list fts3_terms t1 1] $terms +} + +# Utility function to check for the expected doclist for the term in +# segment level/index. _all version does same for entire index. +proc check_doclist {test level index term doclist} { + set where "level = $level AND idx = $index" + do_test $test.doclist [list fts3_doclist t1 $term $where] $doclist +} +proc check_doclist_all {test term doclist} { + do_test $test.doclist [list fts3_doclist t1 $term 1] $doclist +} + +#************************************************************************* +# Test results when all rows are deleted and one is added back. +# Previously older segments would continue to exist, but now the index +# should be dropped when the table is empty. The results should look +# exactly like we never added the earlier rows in the first place. +db eval { + DROP TABLE IF EXISTS t1; + CREATE VIRTUAL TABLE t1 USING fts3(c); + INSERT INTO t1 (docid, c) VALUES (1, 'This is a test'); + INSERT INTO t1 (docid, c) VALUES (2, 'That was a test'); + INSERT INTO t1 (docid, c) VALUES (3, 'This is a test'); + DELETE FROM t1 WHERE 1=1; -- Delete each row rather than dropping table. + INSERT INTO t1 (docid, c) VALUES (1, 'This is a test'); +} + +# Should be a single initial segment. +do_test fts3d-1.segments { + execsql { + SELECT level, idx FROM t1_segdir ORDER BY level, idx; + } +} {0 0} +do_test fts3d-1.matches { + execsql { + SELECT OFFSETS(t1) FROM t1 + WHERE t1 MATCH 'this OR that OR was OR a OR is OR test' ORDER BY docid; + } +} {{0 0 0 4 0 4 5 2 0 3 8 1 0 5 10 4}} + +check_terms_all fts3d-1.1 {a is test this} +check_doclist_all fts3d-1.1.1 a {[1 0[2]]} +check_doclist_all fts3d-1.1.2 is {[1 0[1]]} +check_doclist_all fts3d-1.1.3 test {[1 0[3]]} +check_doclist_all fts3d-1.1.4 this {[1 0[0]]} + +check_terms fts3d-1.2 0 0 {a is test this} +check_doclist fts3d-1.2.1 0 0 a {[1 0[2]]} +check_doclist fts3d-1.2.2 0 0 is {[1 0[1]]} +check_doclist fts3d-1.2.3 0 0 test {[1 0[3]]} +check_doclist fts3d-1.2.4 0 0 this {[1 0[0]]} + +#************************************************************************* +# Test results when everything is optimized manually. +# NOTE(shess): This is a copy of fts3c-1.3. I've pulled a copy here +# because fts3d-2 and fts3d-3 should have identical results. +db eval { + DROP TABLE IF EXISTS t1; + CREATE VIRTUAL TABLE t1 USING fts3(c); + INSERT INTO t1 (docid, c) VALUES (1, 'This is a test'); + INSERT INTO t1 (docid, c) VALUES (2, 'That was a test'); + INSERT INTO t1 (docid, c) VALUES (3, 'This is a test'); + DELETE FROM t1 WHERE docid IN (1,3); + DROP TABLE IF EXISTS t1old; + ALTER TABLE t1 RENAME TO t1old; + CREATE VIRTUAL TABLE t1 USING fts3(c); + INSERT INTO t1 (docid, c) SELECT docid, c FROM t1old; + DROP TABLE t1old; +} + +# Should be a single optimal segment with the same logical results. +do_test fts3d-2.segments { + execsql { + SELECT level, idx FROM t1_segdir ORDER BY level, idx; + } +} {0 0} +do_test fts3d-2.matches { + execsql { + SELECT OFFSETS(t1) FROM t1 + WHERE t1 MATCH 'this OR that OR was OR a OR is OR test' ORDER BY docid; + } +} {{0 1 0 4 0 2 5 3 0 3 9 1 0 5 11 4}} + +check_terms_all fts3d-2.1 {a test that was} +check_doclist_all fts3d-2.1.1 a {[2 0[2]]} +check_doclist_all fts3d-2.1.2 test {[2 0[3]]} +check_doclist_all fts3d-2.1.3 that {[2 0[0]]} +check_doclist_all fts3d-2.1.4 was {[2 0[1]]} + +check_terms fts3d-2.2 0 0 {a test that was} +check_doclist fts3d-2.2.1 0 0 a {[2 0[2]]} +check_doclist fts3d-2.2.2 0 0 test {[2 0[3]]} +check_doclist fts3d-2.2.3 0 0 that {[2 0[0]]} +check_doclist fts3d-2.2.4 0 0 was {[2 0[1]]} + +#************************************************************************* +# Test results when everything is optimized via optimize(). +db eval { + DROP TABLE IF EXISTS t1; + CREATE VIRTUAL TABLE t1 USING fts3(c); + INSERT INTO t1 (docid, c) VALUES (1, 'This is a test'); + INSERT INTO t1 (docid, c) VALUES (2, 'That was a test'); + INSERT INTO t1 (docid, c) VALUES (3, 'This is a test'); + DELETE FROM t1 WHERE docid IN (1,3); + SELECT OPTIMIZE(t1) FROM t1 LIMIT 1; +} + +# Should be a single optimal segment with the same logical results. +do_test fts3d-3.segments { + execsql { + SELECT level, idx FROM t1_segdir ORDER BY level, idx; + } +} {0 0} +do_test fts3d-3.matches { + execsql { + SELECT OFFSETS(t1) FROM t1 + WHERE t1 MATCH 'this OR that OR was OR a OR is OR test' ORDER BY docid; + } +} {{0 1 0 4 0 2 5 3 0 3 9 1 0 5 11 4}} + +check_terms_all fts3d-3.1 {a test that was} +check_doclist_all fts3d-3.1.1 a {[2 0[2]]} +check_doclist_all fts3d-3.1.2 test {[2 0[3]]} +check_doclist_all fts3d-3.1.3 that {[2 0[0]]} +check_doclist_all fts3d-3.1.4 was {[2 0[1]]} + +check_terms fts3d-3.2 0 0 {a test that was} +check_doclist fts3d-3.2.1 0 0 a {[2 0[2]]} +check_doclist fts3d-3.2.2 0 0 test {[2 0[3]]} +check_doclist fts3d-3.2.3 0 0 that {[2 0[0]]} +check_doclist fts3d-3.2.4 0 0 was {[2 0[1]]} + +#************************************************************************* +# Test optimize() against a table involving segment merges. +# NOTE(shess): Since there's no transaction, each of the INSERT/UPDATE +# statements generates a segment. +db eval { + DROP TABLE IF EXISTS t1; + CREATE VIRTUAL TABLE t1 USING fts3(c); + + INSERT INTO t1 (rowid, c) VALUES (1, 'This is a test'); + INSERT INTO t1 (rowid, c) VALUES (2, 'That was a test'); + INSERT INTO t1 (rowid, c) VALUES (3, 'This is a test'); + + UPDATE t1 SET c = 'This is a test one' WHERE rowid = 1; + UPDATE t1 SET c = 'That was a test one' WHERE rowid = 2; + UPDATE t1 SET c = 'This is a test one' WHERE rowid = 3; + + UPDATE t1 SET c = 'This is a test two' WHERE rowid = 1; + UPDATE t1 SET c = 'That was a test two' WHERE rowid = 2; + UPDATE t1 SET c = 'This is a test two' WHERE rowid = 3; + + UPDATE t1 SET c = 'This is a test three' WHERE rowid = 1; + UPDATE t1 SET c = 'That was a test three' WHERE rowid = 2; + UPDATE t1 SET c = 'This is a test three' WHERE rowid = 3; + + UPDATE t1 SET c = 'This is a test four' WHERE rowid = 1; + UPDATE t1 SET c = 'That was a test four' WHERE rowid = 2; + UPDATE t1 SET c = 'This is a test four' WHERE rowid = 3; + + UPDATE t1 SET c = 'This is a test' WHERE rowid = 1; + UPDATE t1 SET c = 'That was a test' WHERE rowid = 2; + UPDATE t1 SET c = 'This is a test' WHERE rowid = 3; +} + +# 2 segments in level 0, 1 in level 1 (18 segments created, 16 +# merged). +do_test fts3d-4.segments { + execsql { + SELECT level, idx FROM t1_segdir ORDER BY level, idx; + } +} {0 0 0 1 1 0} + +do_test fts3d-4.matches { + execsql { + SELECT OFFSETS(t1) FROM t1 + WHERE t1 MATCH 'this OR that OR was OR a OR is OR test' ORDER BY docid; + } +} [list {0 0 0 4 0 4 5 2 0 3 8 1 0 5 10 4} \ + {0 1 0 4 0 2 5 3 0 3 9 1 0 5 11 4} \ + {0 0 0 4 0 4 5 2 0 3 8 1 0 5 10 4}] + +db eval {SELECT c FROM t1 } +check_terms_all fts3d-4.1 {a four is test that this was} +check_doclist_all fts3d-4.1.1 a {[1 0[2]] [2 0[2]] [3 0[2]]} +check_doclist_all fts3d-4.1.2 four {} +check_doclist_all fts3d-4.1.3 is {[1 0[1]] [3 0[1]]} +#check_doclist_all fts3d-4.1.4 one {} +check_doclist_all fts3d-4.1.5 test {[1 0[3]] [2 0[3]] [3 0[3]]} +check_doclist_all fts3d-4.1.6 that {[2 0[0]]} +check_doclist_all fts3d-4.1.7 this {[1 0[0]] [3 0[0]]} +#check_doclist_all fts3d-4.1.8 three {} +#check_doclist_all fts3d-4.1.9 two {} +check_doclist_all fts3d-4.1.10 was {[2 0[1]]} + +check_terms fts3d-4.2 0 0 {a four test that was} +check_doclist fts3d-4.2.1 0 0 a {[2 0[2]]} +check_doclist fts3d-4.2.2 0 0 four {[2]} +check_doclist fts3d-4.2.3 0 0 test {[2 0[3]]} +check_doclist fts3d-4.2.4 0 0 that {[2 0[0]]} +check_doclist fts3d-4.2.5 0 0 was {[2 0[1]]} + +check_terms fts3d-4.3 0 1 {a four is test this} +check_doclist fts3d-4.3.1 0 1 a {[3 0[2]]} +check_doclist fts3d-4.3.2 0 1 four {[3]} +check_doclist fts3d-4.3.3 0 1 is {[3 0[1]]} +check_doclist fts3d-4.3.4 0 1 test {[3 0[3]]} +check_doclist fts3d-4.3.5 0 1 this {[3 0[0]]} + +check_terms fts3d-4.4 1 0 {a four is test that this was} +check_doclist fts3d-4.4.1 1 0 a {[1 0[2]] [2 0[2]] [3 0[2]]} +check_doclist fts3d-4.4.2 1 0 four {[2 0[4]] [3 0[4]]} +check_doclist fts3d-4.4.3 1 0 is {[1 0[1]] [3 0[1]]} +#check_doclist fts3d-4.4.4 1 0 one {[1] [2] [3]} +check_doclist fts3d-4.4.5 1 0 test {[1 0[3]] [2 0[3]] [3 0[3]]} +check_doclist fts3d-4.4.6 1 0 that {[2 0[0]]} +check_doclist fts3d-4.4.7 1 0 this {[1 0[0]] [3 0[0]]} +#check_doclist fts3d-4.4.8 1 0 three {[1] [2] [3]} +#check_doclist fts3d-4.4.9 1 0 two {[1] [2] [3]} +check_doclist fts3d-4.4.10 1 0 was {[2 0[1]]} + +# Optimize should leave the result in the level of the highest-level +# prior segment. +do_test fts3d-4.5 { + execsql { + SELECT OPTIMIZE(t1) FROM t1 LIMIT 1; + SELECT level, idx FROM t1_segdir ORDER BY level, idx; + } +} {{Index optimized} 1 0} + +# Identical to fts3d-4.matches. +do_test fts3d-4.5.matches { + execsql { + SELECT OFFSETS(t1) FROM t1 + WHERE t1 MATCH 'this OR that OR was OR a OR is OR test' ORDER BY docid; + } +} [list {0 0 0 4 0 4 5 2 0 3 8 1 0 5 10 4} \ + {0 1 0 4 0 2 5 3 0 3 9 1 0 5 11 4} \ + {0 0 0 4 0 4 5 2 0 3 8 1 0 5 10 4}] + +check_terms_all fts3d-4.5.1 {a is test that this was} +check_doclist_all fts3d-4.5.1.1 a {[1 0[2]] [2 0[2]] [3 0[2]]} +check_doclist_all fts3d-4.5.1.2 is {[1 0[1]] [3 0[1]]} +check_doclist_all fts3d-4.5.1.3 test {[1 0[3]] [2 0[3]] [3 0[3]]} +check_doclist_all fts3d-4.5.1.4 that {[2 0[0]]} +check_doclist_all fts3d-4.5.1.5 this {[1 0[0]] [3 0[0]]} +check_doclist_all fts3d-4.5.1.6 was {[2 0[1]]} + +check_terms fts3d-4.5.2 1 0 {a is test that this was} +check_doclist fts3d-4.5.2.1 1 0 a {[1 0[2]] [2 0[2]] [3 0[2]]} +check_doclist fts3d-4.5.2.2 1 0 is {[1 0[1]] [3 0[1]]} +check_doclist fts3d-4.5.2.3 1 0 test {[1 0[3]] [2 0[3]] [3 0[3]]} +check_doclist fts3d-4.5.2.4 1 0 that {[2 0[0]]} +check_doclist fts3d-4.5.2.5 1 0 this {[1 0[0]] [3 0[0]]} +check_doclist fts3d-4.5.2.6 1 0 was {[2 0[1]]} + +# Re-optimizing does nothing. +do_test fts3d-5.0 { + execsql { + SELECT OPTIMIZE(t1) FROM t1 LIMIT 1; + SELECT level, idx FROM t1_segdir ORDER BY level, idx; + } +} {{Index already optimal} 1 0} + +# Even if we move things around, still does nothing. +sqlite3_db_config db DEFENSIVE 0 +do_test fts3d-5.1 { + execsql { + UPDATE t1_segdir SET level = 2 WHERE level = 1 AND idx = 0; + SELECT OPTIMIZE(t1) FROM t1 LIMIT 1; + SELECT level, idx FROM t1_segdir ORDER BY level, idx; + } +} {{Index already optimal} 2 0} + + +# ALTER TABLE RENAME should work regardless of the database encoding. +# +do_test fts3d-6.0 { + db close + forcedelete test.db + sqlite3 db test.db + db eval { + PRAGMA encoding=UTF8; + CREATE VIRTUAL TABLE fts USING fts3(a,b,c); + SELECT name FROM sqlite_master WHERE name GLOB '???_*' ORDER BY 1; + } +} {fts_content fts_segdir fts_segments} +do_test fts3d-6.1 { + db eval { + ALTER TABLE fts RENAME TO xyz; + SELECT name FROM sqlite_master WHERE name GLOB '???_*' ORDER BY 1; + } +} {xyz_content xyz_segdir xyz_segments} +do_test fts3d-6.2 { + db close + forcedelete test.db + sqlite3 db test.db + db eval { + PRAGMA encoding=UTF16le; + CREATE VIRTUAL TABLE fts USING fts3(a,b,c); + SELECT name FROM sqlite_master WHERE name GLOB '???_*' ORDER BY 1; + } +} {fts_content fts_segdir fts_segments} +do_test fts3d-6.3 { + db eval { + ALTER TABLE fts RENAME TO xyz; + SELECT name FROM sqlite_master WHERE name GLOB '???_*' ORDER BY 1; + } +} {xyz_content xyz_segdir xyz_segments} +do_test fts3d-6.4 { + db close + forcedelete test.db + sqlite3 db test.db + db eval { + PRAGMA encoding=UTF16be; + CREATE VIRTUAL TABLE fts USING fts3(a,b,c); + SELECT name FROM sqlite_master WHERE name GLOB '???_*' ORDER BY 1; + } +} {fts_content fts_segdir fts_segments} +do_test fts3d-6.5 { + db eval { + ALTER TABLE fts RENAME TO xyz; + SELECT name FROM sqlite_master WHERE name GLOB '???_*' ORDER BY 1; + } +} {xyz_content xyz_segdir xyz_segments} + +# ALTER TABLE RENAME on an FTS3 table following an incr-merge op. +# +do_test fts3d-6.6 { + execsql { INSERT INTO xyz(xyz) VALUES('merge=2,2') } + sqlite3 db test.db + execsql { + ALTER TABLE xyz RENAME TO ott; + SELECT name FROM sqlite_master WHERE name GLOB '???_*' ORDER BY 1; + } +} {ott_content ott_segdir ott_segments ott_stat} + + +finish_test diff --git a/test/fts3defer.test b/test/fts3defer.test new file mode 100644 index 0000000..5d8395a --- /dev/null +++ b/test/fts3defer.test @@ -0,0 +1,531 @@ +# 2010 October 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/malloc_common.tcl + +ifcapable !fts3||!fts4_deferred { + finish_test + return +} + +set sqlite_fts3_enable_parentheses 1 + +set fts3_simple_deferred_tokens_only 1 + +set ::testprefix fts3defer + +#-------------------------------------------------------------------------- +# Test cases fts3defer-1.* are the "warm body" cases. The database contains +# one row with 15000 instances of the token "a". This makes the doclist for +# "a" so large that FTS3 will avoid loading it in most cases. +# +# To show this, test cases fts3defer-1.2.* execute a bunch of FTS3 queries +# involving token "a". Then, fts3defer-1.3.* replaces the doclist for token +# "a" with all zeroes and fts3defer-1.4.* repeats the tests from 1.2. If +# the tests still work, we can conclude that the doclist for "a" was not +# used. +# + +set aaa [string repeat "a " 15000] + +do_execsql_test 1.1 { + CREATE VIRTUAL TABLE t1 USING fts4; + BEGIN; + INSERT INTO t1 VALUES('this is a dog'); + INSERT INTO t1 VALUES('an instance of a phrase'); + INSERT INTO t1 VALUES('an instance of a longer phrase'); + INSERT INTO t1 VALUES($aaa); + COMMIT; +} {} + +set tests { + 1 {SELECT rowid FROM t1 WHERE t1 MATCH '"a dog"'} {1} + 2 {SELECT rowid FROM t1 WHERE t1 MATCH '"is a dog"'} {1} + 3 {SELECT rowid FROM t1 WHERE t1 MATCH '"a longer phrase"'} {3} + 4 {SELECT snippet(t1) FROM t1 WHERE t1 MATCH '"a longer phrase"'} + {"an instance of a longer phrase"} + 5 {SELECT rowid FROM t1 WHERE t1 MATCH 'a dog'} {1} +} + +do_select_tests 1.2 $tests + +sqlite3_db_config db DEFENSIVE 0 +do_execsql_test 1.3 { + SELECT count(*) FROM t1_segments WHERE length(block)>10000; + UPDATE t1_segments + SET block = zeroblob(length(block)) + WHERE length(block)>10000; +} {1} + +do_select_tests 1.4 $tests + +# Drop the table. It is corrupt now anyhow, so not useful for subsequent tests. +# +do_execsql_test 1.5 { DROP TABLE t1 } + +#-------------------------------------------------------------------------- +# These tests - fts3defer-2.* - are more rigorous. They test that for a +# variety of queries, FTS3 and FTS4 return the same results. And that +# zeroing the very large doclists that FTS4 does not load does not change +# the results. +# +# They use the following pseudo-randomly generated document data. The +# tokens "zm" and "jk" are especially common in this dataset. Additionally, +# two documents are added to the pseudo-random data before it is loaded +# into FTS4 containing 100,000 instances of the "zm" and "jk" tokens. This +# makes the doclists for those tokens so large that FTS4 avoids loading them +# into memory if possible. +# +set data [list] +lappend data [string repeat "zm " 100000] +lappend data [string repeat "jk " 100000] +lappend data {*}{ + "zm zm agmckuiu uhzq nsab jk rrkx duszemmzl hyq jk" + "jk uhzq zm zm rgpzmlnmd zm zk jk jk zm" + "duszemmzl zm jk xldlpy zm jk sbptoa xh jk xldlpy" + "zm xh zm xqf azavwm jk jk trqd rgpzmlnmd jk" + "zm vwq urvysbnykk ubwrfqnbjf zk lsz jk doiwavhwwo jk jk" + "jk xduvfhk orpfawpx zkhdvkw jk mjpavjuhw zm jk duszemmzl zm" + "jk igju jk jk zm hmjf xh zm gwdfhwurx zk" + "vgsld jk jk zm hrlipdm jn zm zsmhnf vgsld duszemmzl" + "gtuiexzsu aayxpmve zm zm zm drir scpgna xh azavwm uhzq" + "farlehdhq hkfoudzftq igju duszemmzl xnxhf ewle zm hrlipdm urvysbnykk kn" + "xnxhf jk jk agmckuiu duszemmzl jk zm zm jk vgsld" + "zm zm zm jk jk urvysbnykk ogttbykvt zm zm jk" + "iasrqgqv zm azavwm zidhxhbtv jk jk mjpavjuhw zm zm ajmvcydy" + "rgpzmlnmd tmt mjpavjuhw xh igju jk azavwm fibokdry vgsld ofm" + "zm jk vgsld jk xh jk csjqxhgj drir jk pmrb" + "xh jk jk zm rrkx duszemmzl mjpavjuhw xldlpy igju zm" + "jk hkfoudzftq zf rrkx wdmy jupk jk zm urvysbnykk npywgdvgz" + "zm jk zm zm zhbrzadb uenvbm aayxpmve urvysbnykk duszemmzl jk" + "uenvbm jk zm fxw xh bdilwmjw mjpavjuhw uv jk zm" + "nk jk bnhc pahlds jk igju dzadnqzprr jk jk jk" + "uhzq uv zm duszemmzl tlqix jk jk xh jk zm" + "jk zm agmckuiu urvysbnykk jk jk zm zm jk jk" + "azavwm mjpavjuhw lsgshn trqd xldlpy ogyavjvv agmckuiu ryvwwhlbc jk jk" + "tmt jk zk zm azavwm ofm acpgim bvgimjik iasrqgqv wuvajhwqz" + "igju ogyavjvv xrbdak rrkx fibokdry zf ujfhmrllq jk zm hxgwvib" + "zm pahlds jk uenvbm aayxpmve iaf hmjf xph vnlyvtkgx zm" + "jk xnxhf igju jk xh jk nvfasfh zm js jk" + "zm zm rwaj igju xr rrkx xnxhf nvfasfh skxbsqzvmt xatbxeqq" + "vgsld zm ujfhmrllq uhzq ogyavjvv nsab azavwm zm vgsld jmfiqhwnjg" + "ymjoym duszemmzl urvysbnykk azavwm jk jmfiqhwnjg bu qcdziqomqk vnlyvtkgx" + "zm nbilqcnz dzadnqzprr xh bkfgzsxn urvysbnykk xrujfzxqf zm zf agmckuiu" + "jk urvysbnykk nvfasfh zf xh zm zm qcdziqomqk qvxtclg wdmy" + "fibokdry jk urvysbnykk jk xr osff zm cvnnsl zm vgsld" + "jk mjpavjuhw hkfoudzftq jk zm xh xqf urvysbnykk jk iasrqgqv" + "jk csjqxhgj duszemmzl iasrqgqv aayxpmve zm brsuoqww jk qpmhtvl wluvgsw" + "jk mj azavwm jk zm jn dzadnqzprr zm jk uhzq" + "zk xqf jupk fxw nbilqcnz zm jk jcpiwj tznlvbfcv nvfasfh" + "jk jcpiwj zm xnxhf zm mjpavjuhw mj drir pa pvjrjlas" + "duszemmzl dzadnqzprr jk swc duszemmzl tmt jk jk pahlds jk" + "zk zm jk zm zm eczkjblu zm hi pmrb jk" + "azavwm zm iz agmckuiu jk sntk jk duszemmzl duszemmzl zm" + "jk zm jk eczkjblu urvysbnykk sk gnl jk ttvgf hmjf" + "jk bnhc jjrxpjkb mjpavjuhw fibokdry igju jk zm zm xh" + "wxe ogttbykvt uhzq xr iaf zf urvysbnykk aayxpmve oacaxgjoo mjpavjuhw" + "gazrt jk ephknonq myjp uenvbm wuvajhwqz jk zm xnxhf nvfasfh" + "zm aayxpmve csjqxhgj xnxhf xr jk aayxpmve xnxhf zm zm" + "sokcyf zm ogyavjvv jk zm fibokdry zm jk igju igju" + "vgsld bvgimjik xuprtlyle jk akmikrqyt jk aayxpmve hkfoudzftq ddjj ithtir" + "zm uhzq ovkyevlgv zk uenvbm csjqxhgj jk vgsld pgybs jk" + "zm agmckuiu zexh fibokdry jk uhzq bu tugflixoex xnxhf sk" + "zm zf uenvbm jk azavwm zm zm agmckuiu zm jk" + "rrkx jk zf jt zm oacaxgjoo fibokdry wdmy igju csjqxhgj" + "hi igju zm jk zidhxhbtv dzadnqzprr jk jk trqd duszemmzl" + "zm zm mjpavjuhw xrbdak qrvbjruc jk qzzqdxq guwq cvnnsl zm" + "ithtir jk jk qcdziqomqk zm farlehdhq zm zm xrbdak jk" + "ixfipk csjqxhgj azavwm sokcyf ttvgf vgsld jk sk xh zk" + "nvfasfh azavwm zm zm zm fxw nvfasfh zk gnl trqd" + "zm fibokdry csjqxhgj ofm dzadnqzprr jk akmikrqyt orpfawpx duszemmzl vwq" + "csjqxhgj jk jk vgsld urvysbnykk jk nxum jk jk nxum" + "zm hkfoudzftq jk ryvwwhlbc mjpavjuhw ephknonq jk zm ogyavjvv zm" + "lwa hi xnxhf qdyerbws zk njtc jk uhzq zm jk" + "trqd zm dzadnqzprr zm urvysbnykk jk lsz jk mjpavjuhw cmnnkna" + "duszemmzl zk jk jk fibokdry jseuhjnzo zm aayxpmve zk jk" + "fibokdry jk sviq qvxtclg wdmy jk doiwavhwwo zexh jk zm" + "jupk zm xh jk mjpavjuhw zm jk nsab npywgdvgz duszemmzl" + "zm igju zm zm nvfasfh eh hkfoudzftq fibokdry fxw xkblf" + "jk zm jk jk zm xh zk abthnzcv zf csjqxhgj" + "zm zm jk nkaotm urvysbnykk sbptoa bq jk ktxdty ubwrfqnbjf" + "nvfasfh aayxpmve xdcuz zm tugflixoex jcpiwj zm mjpavjuhw fibokdry doiwavhwwo" + "iaf jk mjpavjuhw zm duszemmzl jk jk uhzq pahlds fibokdry" + "ddjj zk azavwm jk swc zm gjtexkv jk xh jk" + "igju jk csjqxhgj zm jk dzadnqzprr duszemmzl ulvcbv jk jk" + "jk fibokdry zm csjqxhgj jn zm zm zm zf uhzq" + "duszemmzl jk xkblf zk hrlipdm aayxpmve uenvbm uhzq jk zf" + "dzadnqzprr jk zm zdu nvfasfh zm jk urvysbnykk hmjf jk" + "jk aayxpmve aserrdxm acpgim fibokdry jk drir wxe brsuoqww rrkx" + "uhzq csjqxhgj nvfasfh jk rrkx qbamok trqd uenvbm sntk zm" + "ps azavwm zkhdvkw jk zm jk jk zm csjqxhgj xedlrcfo" + "jk jk ogyavjvv jk zm farlehdhq duszemmzl jk agitgxamxe jk" + "qzzqdxq rwaj jk jk zm xqf jk uenvbm jk zk" + "zm hxgwvib akmikrqyt zf agmckuiu uenvbm bq npywgdvgz azavwm jk" + "zf jmfiqhwnjg js igju zm aayxpmve zm mbxnljomiv csjqxhgj nvfasfh" + "zm jk jk gazrt jk jk lkc jk nvfasfh jk" + "xldlpy orpfawpx zkhdvkw jk zm igju zm urvysbnykk dzadnqzprr mbxnljomiv" + "urvysbnykk jk zk igju zm uenvbm jk zm ithtir jk" + "zm zk zm zf ofm zm xdcuz dzadnqzprr zm vgsld" + "sbptoa jk tugflixoex jk zm zm vgsld zm xh zm" + "uhzq jk zk evvivo vgsld vniqnuynvf agmckuiu jk zm zm" + "zm nvfasfh zm zm zm abthnzcv uenvbm jk zk dzadnqzprr" + "zm azavwm igju qzzqdxq jk xnxhf abthnzcv jk nvfasfh zm" + "qbamok fxw vgsld igju cmnnkna xnxhf vniqnuynvf zk xh zm" + "nvfasfh zk zm mjpavjuhw dzadnqzprr jk jk duszemmzl xldlpy nvfasfh" + "xnxhf sviq nsab npywgdvgz osff vgsld farlehdhq fibokdry wjbkhzsa hhac" + "zm azavwm scpgna jk jk bq jk duszemmzl fibokdry ovkyevlgv" + "csjqxhgj zm jk jk duszemmzl zk xh zm jk zf" + "urvysbnykk dzadnqzprr csjqxhgj mjpavjuhw ubwrfqnbjf nkaotm jk jk zm drir" + "nvfasfh xh igju zm wluvgsw jk zm srwwnezqk ewle ovnq" + "jk nvfasfh eh ktxdty urvysbnykk vgsld zm jk eh uenvbm" + "orpfawpx pahlds jk uhzq hi zm zm zf jk dzadnqzprr" + "srwwnezqk csjqxhgj rbwzuf nvfasfh jcpiwj xldlpy nvfasfh jk vgsld wjybxmieki" +} + +proc add_empty_records {n} { + execsql BEGIN + for {set i 0} {$i < $n} {incr i} { + execsql { INSERT INTO t1 VALUES('') } + } + execsql COMMIT +} + + +#set e [list] +#foreach d $data {set e [concat $e $d]} +#puts [lsort -unique $e] +#exit + +set zero_long_doclists { + UPDATE t1_segments SET block=zeroblob(length(block)) WHERE length(block)>10000 +} + +foreach {tn setup} { + 1 { + set dmt_modes 0 + execsql { CREATE VIRTUAL TABLE t1 USING FTS3 } + foreach doc $data { execsql { INSERT INTO t1 VALUES($doc) } } + } + 2 { + set dmt_modes 0 + execsql { CREATE VIRTUAL TABLE t1 USING FTS4 } + foreach doc $data { execsql { INSERT INTO t1 VALUES($doc) } } + } + 3 { + set dmt_modes {0 1 2} + execsql { CREATE VIRTUAL TABLE t1 USING FTS4 } + foreach doc $data { execsql { INSERT INTO t1 VALUES($doc) } } + add_empty_records 1000 + sqlite3_db_config db DEFENSIVE 0 + execsql $zero_long_doclists + } + 4 { + set dmt_modes 0 + execsql { CREATE VIRTUAL TABLE t1 USING FTS4 } + foreach doc $data { execsql { INSERT INTO t1 VALUES($doc) } } + add_empty_records 1000 + execsql "INSERT INTO t1(t1) VALUES('optimize')" + sqlite3_db_config db DEFENSIVE 0 + execsql $zero_long_doclists + } + 5 { + set dmt_modes 0 + execsql { CREATE VIRTUAL TABLE t1 USING FTS4(matchinfo=fts3) } + foreach doc $data { execsql { INSERT INTO t1 VALUES($doc) } } + add_empty_records 1000 + sqlite3_db_config db DEFENSIVE 0 + execsql $zero_long_doclists + } +} { + + execsql { DROP TABLE IF EXISTS t1 } + eval $setup + set ::testprefix fts3defer-2.$tn + set DO_MALLOC_TEST 0 + + do_execsql_test 0 { + SELECT count(*) FROM t1_segments WHERE length(block)>10000 + } {2} + + do_select_test 1.1 { + SELECT rowid FROM t1 WHERE t1 MATCH 'jk xnxhf' + } {13 29 40 47 48 52 63 92} + do_select_test 1.2 { + SELECT rowid FROM t1 WHERE t1 MATCH 'jk eh' + } {100} + do_select_test 1.3 { + SELECT rowid FROM t1 WHERE t1 MATCH 'jk ubwrfqnbjf' + } {7 70 98} + do_select_test 1.4 { + SELECT rowid FROM t1 WHERE t1 MATCH 'duszemmzl jk' + } {3 5 8 10 13 18 20 23 32 37 41 43 55 60 65 67 72 74 76 81 94 96 97} + do_select_test 1.5 { + SELECT rowid FROM t1 WHERE t1 MATCH 'ubwrfqnbjf jk' + } {7 70 98} + do_select_test 1.6 { + SELECT rowid FROM t1 WHERE t1 MATCH 'jk ubwrfqnbjf jk jk jk jk' + } {7 70 98} + do_select_test 1.7 { + SELECT rowid FROM t1 WHERE t1 MATCH 'zm xnxhf' + } {12 13 29 30 40 47 48 52 63 92 93} + do_select_test 1.8 { + SELECT rowid FROM t1 WHERE t1 MATCH 'zm eh' + } {68 100} + do_select_test 1.9 { + SELECT rowid FROM t1 WHERE t1 MATCH 'zm ubwrfqnbjf' + } {7 70 98} + do_select_test 1.10 { + SELECT rowid FROM t1 WHERE t1 MATCH 'z* vgsld' + } {10 13 17 31 35 51 58 88 89 90 93 100} + + if { $fts3_simple_deferred_tokens_only==0 } { + do_select_test 1.11 { + SELECT rowid FROM t1 + WHERE t1 MATCH '( + zdu OR zexh OR zf OR zhbrzadb OR zidhxhbtv OR + zk OR zkhdvkw OR zm OR zsmhnf + ) vgsld' + } {10 13 17 31 35 51 58 88 89 90 93 100} + } + + do_select_test 2.1 { + SELECT rowid FROM t1 WHERE t1 MATCH '"zm agmckuiu"' + } {3 24 52 53} + do_select_test 2.2 { + SELECT rowid FROM t1 WHERE t1 MATCH '"zm zf"' + } {33 53 75 88 101} + do_select_test 2.3 { + SELECT rowid FROM t1 WHERE t1 MATCH '"zm aayxpmve"' + } {48 65 84} + do_select_test 2.4 { + SELECT rowid FROM t1 WHERE t1 MATCH '"aayxpmve zm"' + } {11 37 84} + do_select_test 2.5 { + SELECT rowid FROM t1 WHERE t1 MATCH '"jk azavwm"' + } {16 53} + do_select_test 2.6 { + SELECT rowid FROM t1 WHERE t1 MATCH '"xh jk jk"' + } {18} + do_select_test 2.7 { + SELECT rowid FROM t1 WHERE t1 MATCH '"zm jk vgsld"' + } {13 17} + do_select_test 2.8 { + SELECT rowid FROM t1 WHERE t1 MATCH '"zm jk vgsld lkjlkjlkj"' + } {} + + do_select_test 3.1 { + SELECT snippet(t1, '[', ']') FROM t1 WHERE t1 MATCH '"zm agmckuiu"' + } { + {zm [zm] [agmckuiu] uhzq nsab jk rrkx duszemmzl hyq jk} + {jk [zm] [agmckuiu] urvysbnykk jk jk zm zm jk jk} + {[zm] [agmckuiu] zexh fibokdry jk uhzq bu tugflixoex xnxhf sk} + {zm zf uenvbm jk azavwm zm [zm] [agmckuiu] zm jk} + } + + do_select_test 3.2 { + SELECT snippet(t1, '[', ']') FROM t1 WHERE t1 MATCH 'xnxhf jk' + } { + {[xnxhf] [jk] [jk] agmckuiu duszemmzl [jk] zm zm [jk] vgsld} + {[jk] [xnxhf] igju [jk] xh [jk] nvfasfh zm js [jk]} + {[jk] jcpiwj zm [xnxhf] zm mjpavjuhw mj drir pa pvjrjlas} + {gazrt [jk] ephknonq myjp uenvbm wuvajhwqz [jk] zm [xnxhf] nvfasfh} + {zm aayxpmve csjqxhgj [xnxhf] xr [jk] aayxpmve [xnxhf] zm zm} + {zm agmckuiu zexh fibokdry [jk] uhzq bu tugflixoex [xnxhf] sk} + {lwa hi [xnxhf] qdyerbws zk njtc [jk] uhzq zm [jk]} + {zm azavwm igju qzzqdxq [jk] [xnxhf] abthnzcv [jk] nvfasfh zm} + } + + do_select_test 4.1 { + SELECT offsets(t1) FROM t1 WHERE t1 MATCH '"jk uenvbm"' + } { + {0 0 10 2 0 1 13 6} {0 0 26 2 0 1 29 6} + } + + do_select_test 4.2 { + SELECT offsets(t1) FROM t1 WHERE t1 MATCH 'duszemmzl jk fibokdry' + } { + {0 2 3 8 0 1 36 2 0 0 58 9} + {0 0 0 9 0 1 13 2 0 1 16 2 0 2 19 8 0 1 53 2} + {0 1 4 2 0 0 20 9 0 1 30 2 0 1 33 2 0 2 48 8} + {0 1 17 2 0 1 20 2 0 1 26 2 0 0 29 9 0 2 39 8} + } + + do_select_test 4.3 { + SELECT offsets(t1) FROM t1 + WHERE t1 MATCH 'vgsld (hrlipdm OR (aapmve NEAR duszemmzl))' + } {{0 0 0 5 0 1 15 7 0 0 36 5}} + + # The following block of tests runs normally with FTS3 or FTS4 without the + # long doclists zeroed. And with OOM-injection for FTS4 with long doclists + # zeroed. Change this by messing with the [set dmt_modes] commands above. + # + foreach DO_MALLOC_TEST $dmt_modes { + + # Phrase search. + # + do_select_test 5.$DO_MALLOC_TEST.1 { + SELECT rowid FROM t1 WHERE t1 MATCH '"jk mjpavjuhw"' + } {8 15 36 64 67 72} + + # Multiple tokens search. + do_select_test 5.$DO_MALLOC_TEST.2 { + SELECT rowid FROM t1 WHERE t1 MATCH 'duszemmzl zm' + } {3 5 8 10 12 13 18 20 23 37 43 55 60 65 67 72 74 81 94 96 97} + + # snippet() function with phrase. + do_select_test 5.$DO_MALLOC_TEST.3 { + SELECT snippet(t1, '[', ']') FROM t1 WHERE t1 MATCH '"zm aayxpmve"' + } { + {[zm] [aayxpmve] csjqxhgj xnxhf xr jk aayxpmve xnxhf zm zm} + {duszemmzl zk jk jk fibokdry jseuhjnzo [zm] [aayxpmve] zk jk} + {zf jmfiqhwnjg js igju [zm] [aayxpmve] zm mbxnljomiv csjqxhgj nvfasfh} + } + + # snippet() function with multiple tokens. + do_select_test 5.$DO_MALLOC_TEST.4 { + SELECT snippet(t1, '[', ']') FROM t1 WHERE t1 MATCH 'zm zhbrzadb' + } { + {[zm] jk [zm] [zm] [zhbrzadb] uenvbm aayxpmve urvysbnykk duszemmzl jk} + } + + # snippet() function with phrase. + do_select_test 5.$DO_MALLOC_TEST.5 { + SELECT offsets(t1) FROM t1 WHERE t1 MATCH '"zm aayxpmve"' + } { + {0 0 0 2 0 1 3 8} {0 0 38 2 0 1 41 8} {0 0 22 2 0 1 25 8} + } + + # snippet() function with multiple tokens. + do_select_test 5.$DO_MALLOC_TEST.6 { + SELECT offsets(t1) FROM t1 WHERE t1 MATCH 'zm zhbrzadb' + } { + {0 0 0 2 0 0 6 2 0 0 9 2 0 1 12 8} + } + + set DO_MALLOC_TEST 0 + } + + do_select_test 6.1 { + SELECT rowid FROM t1 + WHERE t1 MATCH 'vgsld (hrlipdm OR (aayxpmve duszemmzl))' + } {10} + do_select_test 6.2.1 { + SELECT rowid FROM t1 WHERE t1 MATCH '"jk xduvfhk"' + } {8} + do_select_test 6.2.2 { + SELECT rowid FROM t1 WHERE t1 MATCH '"zm azavwm"' + } {15 26 92 96} + if {$fts3_simple_deferred_tokens_only==0} { + do_select_test 6.2.3 { + SELECT rowid FROM t1 WHERE t1 MATCH '"jk xduvfhk" OR "zm azavwm"' + } {8 15 26 92 96} + } + + if {$tn>1} { + # These tests will not work with $tn==1, as in this case table t1 is + # created using FTS3. The ^ syntax is only available with FTS4 tables. + # + do_select_test 7.1 { + SELECT rowid FROM t1 WHERE t1 MATCH '^zm mjpavjuhw' + } {56 62} + do_select_test 7.2 { + SELECT rowid FROM t1 WHERE t1 MATCH '^azavwm zm' + } {43} + } +} + +set testprefix fts3defer + +do_execsql_test 3.1 { + CREATE VIRTUAL TABLE x1 USING fts4(a, b); + INSERT INTO x1 VALUES('a b c', 'd e f'); + INSERT INTO x1 SELECT * FROM x1; + INSERT INTO x1 SELECT * FROM x1; + INSERT INTO x1 SELECT * FROM x1; + INSERT INTO x1 SELECT * FROM x1; +} +do_execsql_test 3.2 " + INSERT INTO x1 VALUES( + '[string repeat {d } 3000]', '[string repeat {f } 30000]' + ); + INSERT INTO x1(x1) VALUES('optimize'); +" + +do_execsql_test 3.3 { + SELECT count(*) FROM x1 WHERE x1 MATCH '"d e f"' +} {16} + +# At one point the following was causing a floating-point exception. +# +do_execsql_test 4.1 { + CREATE VIRTUAL TABLE x2 USING FTS4(x); + BEGIN; + INSERT INTO x2 VALUES('m m m m m m m m m m m m m m m m m m m m m m m m m m'); + INSERT INTO x2 SELECT * FROM x2; + INSERT INTO x2 SELECT * FROM x2; + INSERT INTO x2 SELECT * FROM x2; + INSERT INTO x2 SELECT * FROM x2; + INSERT INTO x2 SELECT * FROM x2; + INSERT INTO x2 SELECT * FROM x2; + INSERT INTO x2 SELECT * FROM x2; + INSERT INTO x2 SELECT * FROM x2; + INSERT INTO x2 SELECT * FROM x2; + INSERT INTO x2 SELECT * FROM x2; + INSERT INTO x2 SELECT * FROM x2; + INSERT INTO x2 SELECT * FROM x2; + INSERT INTO x2 SELECT * FROM x2; + INSERT INTO x2 SELECT * FROM x2; + INSERT INTO x2 SELECT * FROM x2; + INSERT INTO x2 VALUES('a b c d e f g h i j k l m n o p q r s t u v w x y m'); + COMMIT; +} +do_execsql_test 4.2 { + SELECT * FROM x2 WHERE x2 MATCH 'a b c d e f g h i j k l m n o p q r s'; +} {{a b c d e f g h i j k l m n o p q r s t u v w x y m}} + +set tokenizers {1 simple} +ifcapable icu { lappend tokenizers 2 {icu en_US} } +foreach {tn tokenizer} $tokenizers { + do_execsql_test 5.$tn.1 " + CREATE VIRTUAL TABLE x3 USING FTS4(a, b, TOKENIZE $tokenizer) + " + do_execsql_test 5.$tn.2 { + BEGIN; + INSERT INTO x3 VALUES('b b b b b b b b b b b', 'b b b b b b b b b b b b b'); + INSERT INTO x3 SELECT * FROM x3; + INSERT INTO x3 SELECT * FROM x3; + INSERT INTO x3 SELECT * FROM x3; + INSERT INTO x3 SELECT * FROM x3; + INSERT INTO x3 SELECT * FROM x3; + INSERT INTO x3 SELECT * FROM x3; + INSERT INTO x3 SELECT * FROM x3; + INSERT INTO x3 SELECT * FROM x3; + INSERT INTO x3 SELECT * FROM x3; + INSERT INTO x3 SELECT * FROM x3; + INSERT INTO x3 SELECT * FROM x3; + INSERT INTO x3 SELECT * FROM x3; + INSERT INTO x3 SELECT * FROM x3; + INSERT INTO x3 SELECT * FROM x3; + INSERT INTO x3 SELECT * FROM x3; + INSERT INTO x3 SELECT * FROM x3; + INSERT INTO x3 VALUES('a b c', NULL); + INSERT INTO x3 VALUES('a x c', NULL); + COMMIT; + + SELECT * FROM x3 WHERE x3 MATCH 'a b'; + } {{a b c} {}} + + do_execsql_test 5.$tn.3 { DROP TABLE x3 } +} + +finish_test diff --git a/test/fts3defer2.test b/test/fts3defer2.test new file mode 100644 index 0000000..51d2afc --- /dev/null +++ b/test/fts3defer2.test @@ -0,0 +1,193 @@ +# 2010 October 23 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/malloc_common.tcl +ifcapable !fts3||!fts4_deferred { + finish_test + return +} + +set testprefix fts3defer2 + +proc mit {blob} { + set scan(littleEndian) i* + set scan(bigEndian) I* + binary scan $blob $scan($::tcl_platform(byteOrder)) r + return $r +} +db func mit mit + +#----------------------------------------------------------------------------- +# This block of tests - fts3defer2-1.* - test the interaction of deferred NEAR +# expressions and the snippet, offsets and matchinfo functions. +# +do_execsql_test 1.1.1 { + CREATE VIRTUAL TABLE t1 USING fts4; +} +do_execsql_test 1.1.2 "INSERT INTO t1 VALUES('[string repeat {a } 20000]')" +do_execsql_test 1.1.3 "INSERT INTO t1 VALUES('[string repeat {z } 20000]')" +do_execsql_test 1.1.4 { + INSERT INTO t1 VALUES('a b c d e f a x y'); + INSERT INTO t1 VALUES(''); + INSERT INTO t1 VALUES(''); + INSERT INTO t1 VALUES(''); + INSERT INTO t1 VALUES(''); + INSERT INTO t1 VALUES(''); + INSERT INTO t1(t1) VALUES('optimize'); +} +sqlite3_db_config db DEFENSIVE 0 +do_execsql_test 1.1.4 { + SELECT count(*) FROM t1_segments WHERE length(block)>10000; + UPDATE t1_segments SET block = zeroblob(length(block)) WHERE length(block)>10000; +} {2} + +do_execsql_test 1.2.0 { + SELECT content FROM t1 WHERE t1 MATCH 'f (e a)'; +} {{a b c d e f a x y}} + +do_execsql_test 1.2.1 { + SELECT content FROM t1 WHERE t1 MATCH 'f (e NEAR/2 a)'; +} {{a b c d e f a x y}} + + +do_execsql_test 1.2.2 { + SELECT snippet(t1, '[', ']'), offsets(t1), mit(matchinfo(t1, 'pcxnal')) + FROM t1 WHERE t1 MATCH 'f (e NEAR/2 a)'; +} [list \ + {a b c d [e] [f] [a] x y} \ + {0 1 8 1 0 0 10 1 0 2 12 1} \ + [list 3 1 1 1 1 1 1 1 1 1 1 8 5001 9] +] + +do_execsql_test 1.2.3 { + SELECT snippet(t1, '[', ']'), offsets(t1), mit(matchinfo(t1, 'pcxnal')) + FROM t1 WHERE t1 MATCH 'f (e NEAR/3 a)'; +} [list \ + {[a] b c d [e] [f] [a] x y} \ + {0 2 0 1 0 1 8 1 0 0 10 1 0 2 12 1} \ + [list 3 1 1 1 1 1 1 1 2 2 1 8 5001 9] +] + +do_execsql_test 1.3.1 { DROP TABLE t1 } + +#----------------------------------------------------------------------------- +# Test cases fts3defer2-2.* focus specifically on the matchinfo function. +# +do_execsql_test 2.1.1 "CREATE VIRTUAL TABLE t2 USING fts4" +do_execsql_test 2.1.2 "INSERT INTO t2 VALUES('[string repeat {a } 10000]')" +do_execsql_test 2.1.3 "INSERT INTO t2 VALUES('b [string repeat {z } 10000]')" +do_execsql_test 2.1.4 [string repeat "INSERT INTO t2 VALUES('x');" 50] +do_execsql_test 2.1.5 { + INSERT INTO t2 VALUES('a b c d e f g z'); + INSERT INTO t2 VALUES('a b c d e f g'); +} +foreach {tn sql} { + 1 {} + 2 { INSERT INTO t2(t2) VALUES('optimize') } + 3 { UPDATE t2_segments SET block = zeroblob(length(block)) + WHERE length(block)>10000; + } +} { + sqlite3_db_config db DEFENSIVE 0 + execsql $sql + + do_execsql_test 2.2.$tn.1 { + SELECT mit(matchinfo(t2, 'pcxnal')) FROM t2 WHERE t2 MATCH 'a b'; + } [list \ + [list 2 1 1 54 54 1 3 3 54 372 8] \ + [list 2 1 1 54 54 1 3 3 54 372 7] \ + ] + + do_execsql_test 2.2.$tn.2 { + SELECT mit(matchinfo(t2, 'x')) FROM t2 WHERE t2 MATCH 'g z'; + } [list \ + [list 1 2 2 1 54 54] \ + ] + + set sqlite_fts3_enable_parentheses 1 + do_execsql_test 2.2.$tn.3 { + SELECT mit(matchinfo(t2, 'x')) FROM t2 WHERE t2 MATCH 'g OR (g z)'; + } [list \ + [list 1 2 2 1 2 2 1 54 54] \ + [list 1 2 2 1 2 2 0 54 54] \ + ] + set sqlite_fts3_enable_parentheses 0 + + do_execsql_test 2.2.$tn.4 { + SELECT mit(matchinfo(t2, 'x')) FROM t2 WHERE t2 MATCH 'e "g z"'; + } [list \ + [list 1 2 2 1 2 2] \ + ] +} + +do_execsql_test 2.3.1 { + CREATE VIRTUAL TABLE t3 USING fts4; + INSERT INTO t3 VALUES('a b c d e f'); + INSERT INTO t3 VALUES('x b c d e f'); + INSERT INTO t3 VALUES('d e f a b c'); + INSERT INTO t3 VALUES('b c d e f'); + INSERT INTO t3 VALUES(''); + INSERT INTO t3 VALUES(''); + INSERT INTO t3 VALUES(''); + INSERT INTO t3 VALUES(''); + INSERT INTO t3 VALUES(''); + INSERT INTO t3 VALUES(''); +} +do_execsql_test 2.3.2 " + INSERT INTO t3 VALUES('f e d c b [string repeat {a } 10000]') +" +foreach {tn sql} { + 1 {} + 2 { INSERT INTO t3(t3) VALUES('optimize') } + 3 { UPDATE t3_segments SET block = zeroblob(length(block)) + WHERE length(block)>10000; + } +} { + sqlite3_db_config db DEFENSIVE 0 + execsql $sql + do_execsql_test 2.4.$tn { + SELECT docid, mit(matchinfo(t3, 'pcxnal')) FROM t3 WHERE t3 MATCH '"a b c"'; + } {1 {1 1 1 4 4 11 912 6} 3 {1 1 1 4 4 11 912 6}} +} + +do_execsql_test 2.5 { + INSERT INTO t3(t3) VALUES('rebuild'); +} +do_execsql_test 2.6 { + SELECT rowid, length(offsets(t3)) FROM t3 WHERE t3 MATCH '(a NEAR a)'; +} {11 228929} +do_execsql_test 2.7 { + SELECT rowid, length(offsets(t3)) FROM t3 WHERE t3 MATCH '(a NEAR b NEAR a)'; +} {1 23 3 23 11 205} +do_execsql_test 2.8 { + SELECT rowid, length(offsets(t3)) FROM t3 WHERE t3 MATCH '(a NEAR b)'; +} {1 15 3 15 11 106} + +do_execsql_test 2.9 { + SELECT rowid, length(matchinfo(t3)) FROM t3 WHERE t3 MATCH '(a NEAR a)'; +} {11 32} +do_execsql_test 2.10 { + SELECT rowid, length(matchinfo(t3)) FROM t3 WHERE t3 MATCH '(a NEAR b NEAR a)' +} {1 44 3 44 11 44} +do_execsql_test 2.11 { + SELECT rowid, length(matchinfo(t3)) FROM t3 WHERE t3 MATCH '(a NEAR b)'; +} {1 32 3 32 11 32} + +do_execsql_test 2.12 { + SELECT rowid, length(matchinfo(t3)) FROM t3 + WHERE t3 MATCH '(a NEAR b NEAR a NEAR b NEAR a)' +} {1 68 3 68 11 68} + + +finish_test diff --git a/test/fts3defer3.test b/test/fts3defer3.test new file mode 100644 index 0000000..a795e92 --- /dev/null +++ b/test/fts3defer3.test @@ -0,0 +1,84 @@ +# 2010 October 23 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file contains a very simple test to show that the deferred tokens +# optimization is doing something. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/malloc_common.tcl +ifcapable !fts3||!fts4_deferred { + finish_test + return +} +set testprefix fts3defer3 + +set nDoclist 3204 +set nDoc 800 + +# Set up a database that contains 800 rows. Each row contains the document +# "b b", except for the row with docid=200, which contains "a b". Hence +# token "b" is extremely common and token "a" is not. +# +do_test 1.1 { + execsql { + CREATE VIRTUAL TABLE t1 USING fts4; + BEGIN; + } + for {set i 1} {$i <= $nDoc} {incr i} { + set document "b b" + if {$i==200} { set document "a b" } + execsql { INSERT INTO t1 (docid, content) VALUES($i, $document) } + } + execsql COMMIT +} {} + +# Check that the db contains two doclists. A small one for "a" and a +# larger one for "b". +# +do_execsql_test 1.2 { + SELECT blockid, length(block) FROM t1_segments; +} [list 1 8 2 $nDoclist] + +# Query for 'a b'. Although this test doesn't prove so, token "b" will +# be deferred because of the very large associated doclist. +# +do_execsql_test 1.3 { + SELECT docid, content FROM t1 WHERE t1 MATCH 'a b'; +} {200 {a b}} + +# Zero out the doclist for token "b" within the database file. Now the +# only queries that use token "b" that will work are those that defer +# it. Any query that tries to use the doclist belonging to token "b" +# will fail. +# +do_test 1.4 { + set fd [db incrblob t1_segments block 2] + puts -nonewline $fd [string repeat "\00" $nDoclist] + close $fd +} {} + +# The first two queries succeed, as they defer token "b". The last one +# fails, as it tries to load the corrupt doclist. +# +do_execsql_test 1.5 { + SELECT docid, content FROM t1 WHERE t1 MATCH 'a b'; +} {200 {a b}} +do_execsql_test 1.6 { + SELECT count(*) FROM t1 WHERE t1 MATCH 'a b'; +} {1} +do_catchsql_test 1.7 { + SELECT count(*) FROM t1 WHERE t1 MATCH 'b'; +} {1 {database disk image is malformed}} + + +finish_test diff --git a/test/fts3drop.test b/test/fts3drop.test new file mode 100644 index 0000000..8b76eaf --- /dev/null +++ b/test/fts3drop.test @@ -0,0 +1,61 @@ +# 2011 October 29 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS3 module. More specifically, +# that DROP TABLE commands can co-exist with savepoints inside transactions. +# See ticket [48f299634a] for details. +# + + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts3drop + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +do_execsql_test 1.1 { + CREATE VIRTUAL TABLE f1 USING fts3; + INSERT INTO f1 VALUES('a b c'); +} + +do_execsql_test 1.2 { + BEGIN; + INSERT INTO f1 VALUES('d e f'); + SAVEPOINT one; + INSERT INTO f1 VALUES('g h i'); + DROP TABLE f1; + ROLLBACK TO one; + COMMIT; +} + +do_execsql_test 1.3 { + SELECT * FROM f1; +} {{a b c} {d e f}} + +do_execsql_test 1.4 { + BEGIN; + INSERT INTO f1 VALUES('g h i'); + SAVEPOINT one; + INSERT INTO f1 VALUES('j k l'); + DROP TABLE f1; + RELEASE one; + ROLLBACK; +} + +do_execsql_test 1.5 { + SELECT * FROM f1; +} {{a b c} {d e f}} + +finish_test diff --git a/test/fts3dropmod.test b/test/fts3dropmod.test new file mode 100644 index 0000000..d6b1677 --- /dev/null +++ b/test/fts3dropmod.test @@ -0,0 +1,44 @@ +# 2021 December 16 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS3 module. +# +# $Id: fts3aa.test,v 1.1 2007/08/20 17:38:42 shess Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts3dropmod + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +sqlite3_drop_modules db fts3 +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t1 USING fts3(x); +} +do_catchsql_test 1.1 { + CREATE VIRTUAL TABLE t2 USING fts4(x); +} {1 {no such module: fts4}} + +reset_db +sqlite3_drop_modules db fts4 +do_execsql_test 2.0 { + CREATE VIRTUAL TABLE t1 USING fts4(x); +} +do_catchsql_test 2.1 { + CREATE VIRTUAL TABLE t2 USING fts3(x); +} {1 {no such module: fts3}} + +finish_test diff --git a/test/fts3e.test b/test/fts3e.test new file mode 100644 index 0000000..03caaf8 --- /dev/null +++ b/test/fts3e.test @@ -0,0 +1,125 @@ +# 2008 July 29 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# These tests exercise the various types of fts3 cursors. +# +# $Id: fts3e.test,v 1.1 2008/07/29 20:24:46 shess Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is not defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +#************************************************************************* +# Test table scan (QUERY_GENERIC). This kind of query happens for +# queries with no WHERE clause, or for WHERE clauses which cannot be +# satisfied by an index. +db eval { + DROP TABLE IF EXISTS t1; + CREATE VIRTUAL TABLE t1 USING fts3(c); + INSERT INTO t1 (docid, c) VALUES (1, 'This is a test'); + INSERT INTO t1 (docid, c) VALUES (2, 'That was a test'); + INSERT INTO t1 (docid, c) VALUES (3, 'This is a test'); +} + +do_test fts3e-1.1 { + execsql { + SELECT docid FROM t1 ORDER BY docid; + } +} {1 2 3} + +do_test fts3e-1.2 { + execsql { + SELECT docid FROM t1 WHERE c LIKE '%test' ORDER BY docid; + } +} {1 2 3} + +do_test fts3e-1.3 { + execsql { + SELECT docid FROM t1 WHERE c LIKE 'That%' ORDER BY docid; + } +} {2} + +#************************************************************************* +# Test lookup by docid (QUERY_DOCID). This kind of query happens for +# queries which select by the docid/rowid implicit index. +db eval { + DROP TABLE IF EXISTS t1; + DROP TABLE IF EXISTS t2; + CREATE VIRTUAL TABLE t1 USING fts3(c); + CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT, weight INTEGER UNIQUE); + INSERT INTO t2 VALUES (null, 10); + INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'This is a test'); + INSERT INTO t2 VALUES (null, 5); + INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'That was a test'); + INSERT INTO t2 VALUES (null, 20); + INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'This is a test'); +} + +# TODO(shess): This actually is doing QUERY_GENERIC? I'd have +# expected QUERY_DOCID in this case, as for a very large table the +# full scan is less efficient. +do_test fts3e-2.1 { + execsql { + SELECT docid FROM t1 WHERE docid in (1, 2, 10); + SELECT rowid FROM t1 WHERE rowid in (1, 2, 10); + } +} {1 2 1 2} + +do_test fts3e-2.2 { + execsql { + SELECT docid, weight FROM t1, t2 WHERE t2.id = t1.docid ORDER BY weight; + SELECT t1.rowid, weight FROM t1, t2 WHERE t2.id = t1.rowid ORDER BY weight; + } +} {2 5 1 10 3 20 2 5 1 10 3 20} + +do_test fts3e-2.3 { + execsql { + SELECT docid, weight FROM t1, t2 + WHERE t2.weight>5 AND t2.id = t1.docid ORDER BY weight; + SELECT t1.rowid, weight FROM t1, t2 + WHERE t2.weight>5 AND t2.id = t1.rowid ORDER BY weight; + } +} {1 10 3 20 1 10 3 20} + +#************************************************************************* +# Test lookup by MATCH (QUERY_FULLTEXT). This is the fulltext index. +db eval { + DROP TABLE IF EXISTS t1; + DROP TABLE IF EXISTS t2; + CREATE VIRTUAL TABLE t1 USING fts3(c); + CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT, weight INTEGER UNIQUE); + INSERT INTO t2 VALUES (null, 10); + INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'This is a test'); + INSERT INTO t2 VALUES (null, 5); + INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'That was a test'); + INSERT INTO t2 VALUES (null, 20); + INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'This is a test'); +} + +do_test fts3e-3.1 { + execsql { + SELECT docid FROM t1 WHERE t1 MATCH 'this' ORDER BY docid; + } +} {1 3} + +do_test fts3e-3.2 { + execsql { + SELECT docid, weight FROM t1, t2 + WHERE t1 MATCH 'this' AND t1.docid = t2.id ORDER BY weight; + } +} {1 10 3 20} + +finish_test diff --git a/test/fts3expr.test b/test/fts3expr.test new file mode 100644 index 0000000..2fd1920 --- /dev/null +++ b/test/fts3expr.test @@ -0,0 +1,521 @@ +# 2006 September 9 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS3 module. +# +# $Id: fts3expr.test,v 1.9 2009/07/28 16:44:26 danielk1977 Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +set sqlite_fts3_enable_parentheses 1 + +proc test_fts3expr {expr} { + db one {SELECT fts3_exprtest('simple', $expr, 'a', 'b', 'c')} +} + +do_test fts3expr-1.0 { + test_fts3expr "abcd" +} {PHRASE 3 0 abcd} +do_test fts3expr-1.1 { + test_fts3expr " tag " +} {PHRASE 3 0 tag} + +do_test fts3expr-1.2 { + test_fts3expr "ab AND cd" +} {AND {PHRASE 3 0 ab} {PHRASE 3 0 cd}} +do_test fts3expr-1.2.1 { + test_fts3expr "ab cd" +} {AND {PHRASE 3 0 ab} {PHRASE 3 0 cd}} +do_test fts3expr-1.3 { + test_fts3expr "ab OR cd" +} {OR {PHRASE 3 0 ab} {PHRASE 3 0 cd}} +do_test fts3expr-1.4 { + test_fts3expr "ab NOT cd" +} {NOT {PHRASE 3 0 ab} {PHRASE 3 0 cd}} +do_test fts3expr-1.5 { + test_fts3expr "ab NEAR cd" +} {NEAR/10 {PHRASE 3 0 ab} {PHRASE 3 0 cd}} +do_test fts3expr-1.6.1 { + test_fts3expr "ab NEAR/5 cd" +} {NEAR/5 {PHRASE 3 0 ab} {PHRASE 3 0 cd}} +do_test fts3expr-1.6.2 { + test_fts3expr "ab NEAR/87654321 cd" +} {NEAR/87654321 {PHRASE 3 0 ab} {PHRASE 3 0 cd}} +do_test fts3expr-1.6.3 { + test_fts3expr "ab NEAR/7654321 cd" +} {NEAR/7654321 {PHRASE 3 0 ab} {PHRASE 3 0 cd}} +do_test fts3expr-1.6.4 { + test_fts3expr "ab NEAR/654321 cd" +} {NEAR/654321 {PHRASE 3 0 ab} {PHRASE 3 0 cd}} +do_test fts3expr-1.6.5 { + test_fts3expr "ab NEAR/54321 cd" +} {NEAR/54321 {PHRASE 3 0 ab} {PHRASE 3 0 cd}} +do_test fts3expr-1.6.6 { + test_fts3expr "ab NEAR/4321 cd" +} {NEAR/4321 {PHRASE 3 0 ab} {PHRASE 3 0 cd}} +do_test fts3expr-1.6.7 { + test_fts3expr "ab NEAR/321 cd" +} {NEAR/321 {PHRASE 3 0 ab} {PHRASE 3 0 cd}} +do_test fts3expr-1.6.8 { + test_fts3expr "ab NEAR/21 cd" +} {NEAR/21 {PHRASE 3 0 ab} {PHRASE 3 0 cd}} + +do_test fts3expr-1.7 { + test_fts3expr {"one two three"} +} {PHRASE 3 0 one two three} +do_test fts3expr-1.8.1 { + test_fts3expr {zero "one two three" four} +} {AND {AND {PHRASE 3 0 zero} {PHRASE 3 0 one two three}} {PHRASE 3 0 four}} +do_test fts3expr-1.8.2 { + test_fts3expr {zero AND "one two three" four} +} {AND {AND {PHRASE 3 0 zero} {PHRASE 3 0 one two three}} {PHRASE 3 0 four}} +do_test fts3expr-1.8.3 { + test_fts3expr {zero "one two three" AND four} +} {AND {AND {PHRASE 3 0 zero} {PHRASE 3 0 one two three}} {PHRASE 3 0 four}} +do_test fts3expr-1.8.4 { + test_fts3expr {zero AND "one two three" AND four} +} {AND {AND {PHRASE 3 0 zero} {PHRASE 3 0 one two three}} {PHRASE 3 0 four}} +do_test fts3expr-1.9.1 { + test_fts3expr {"one* two three"} +} {PHRASE 3 0 one+ two three} +do_test fts3expr-1.9.2 { + test_fts3expr {"one two* three"} +} {PHRASE 3 0 one two+ three} +do_test fts3expr-1.9.3 { + test_fts3expr {"one* two* three"} +} {PHRASE 3 0 one+ two+ three} +do_test fts3expr-1.9.4 { + test_fts3expr {"one two three*"} +} {PHRASE 3 0 one two three+} +do_test fts3expr-1.9.5 { + test_fts3expr {"one* two three*"} +} {PHRASE 3 0 one+ two three+} +do_test fts3expr-1.9.6 { + test_fts3expr {"one two* three*"} +} {PHRASE 3 0 one two+ three+} +do_test fts3expr-1.9.7 { + test_fts3expr {"one* two* three*"} +} {PHRASE 3 0 one+ two+ three+} + +do_test fts3expr-1.10 { + test_fts3expr {one* two} +} {AND {PHRASE 3 0 one+} {PHRASE 3 0 two}} +do_test fts3expr-1.11 { + test_fts3expr {one two*} +} {AND {PHRASE 3 0 one} {PHRASE 3 0 two+}} + +do_test fts3expr-1.14 { + test_fts3expr {a:one two} +} {AND {PHRASE 0 0 one} {PHRASE 3 0 two}} +do_test fts3expr-1.15.1 { + test_fts3expr {one b:two} +} {AND {PHRASE 3 0 one} {PHRASE 1 0 two}} +do_test fts3expr-1.15.2 { + test_fts3expr {one B:two} +} {AND {PHRASE 3 0 one} {PHRASE 1 0 two}} + +do_test fts3expr-1.16 { + test_fts3expr {one AND two AND three AND four AND five} +} [list AND \ + [list AND \ + [list AND \ + [list AND {PHRASE 3 0 one} {PHRASE 3 0 two}] \ + {PHRASE 3 0 three} \ + ] \ + {PHRASE 3 0 four} \ + ] \ + {PHRASE 3 0 five} \ + ] +do_test fts3expr-1.17 { + test_fts3expr {(one AND two) AND ((three AND four) AND five)} +} [list AND \ + [list AND {PHRASE 3 0 one} {PHRASE 3 0 two}] \ + [list AND \ + [list AND {PHRASE 3 0 three} {PHRASE 3 0 four}] \ + {PHRASE 3 0 five} \ + ] \ + ] +do_test fts3expr-1.18 { + test_fts3expr {(one AND two) OR ((three AND four) AND five)} +} [list OR \ + [list AND {PHRASE 3 0 one} {PHRASE 3 0 two}] \ + [list AND \ + [list AND {PHRASE 3 0 three} {PHRASE 3 0 four}] \ + {PHRASE 3 0 five} \ + ] \ + ] +do_test fts3expr-1.19 { + test_fts3expr {(one AND two) AND ((three AND four) OR five)} +} [list AND \ + [list AND {PHRASE 3 0 one} {PHRASE 3 0 two}] \ + [list OR \ + [list AND {PHRASE 3 0 three} {PHRASE 3 0 four}] \ + {PHRASE 3 0 five} \ + ] \ + ] +do_test fts3expr-1.20 { + test_fts3expr {(one OR two) AND ((three OR four) AND five)} +} [list AND \ + [list OR {PHRASE 3 0 one} {PHRASE 3 0 two}] \ + [list AND \ + [list OR {PHRASE 3 0 three} {PHRASE 3 0 four}] \ + {PHRASE 3 0 five} \ + ] \ + ] +do_test fts3expr-1.21 { + test_fts3expr {(one OR two) AND ((three NOT four) AND five)} +} [list AND \ + [list OR {PHRASE 3 0 one} {PHRASE 3 0 two}] \ + [list AND \ + [list NOT {PHRASE 3 0 three} {PHRASE 3 0 four}] \ + {PHRASE 3 0 five} \ + ] \ + ] +do_test fts3expr-1.22 { + test_fts3expr {(one OR two) NOT ((three OR four) AND five)} +} [list NOT \ + [list OR {PHRASE 3 0 one} {PHRASE 3 0 two}] \ + [list AND \ + [list OR {PHRASE 3 0 three} {PHRASE 3 0 four}] \ + {PHRASE 3 0 five} \ + ] \ + ] +do_test fts3expr-1.23 { + test_fts3expr {(((((one OR two))))) NOT (((((three OR four))) AND five))} +} [list NOT \ + [list OR {PHRASE 3 0 one} {PHRASE 3 0 two}] \ + [list AND \ + [list OR {PHRASE 3 0 three} {PHRASE 3 0 four}] \ + {PHRASE 3 0 five} \ + ] \ + ] +do_test fts3expr-1.24 { + test_fts3expr {one NEAR two} +} [list NEAR/10 {PHRASE 3 0 one} {PHRASE 3 0 two}] +do_test fts3expr-1.25 { + test_fts3expr {(one NEAR two)} +} [list NEAR/10 {PHRASE 3 0 one} {PHRASE 3 0 two}] +do_test fts3expr-1.26 { + test_fts3expr {((((((one NEAR two))))))} +} [list NEAR/10 {PHRASE 3 0 one} {PHRASE 3 0 two}] +do_test fts3expr-1.27 { + test_fts3expr {(one NEAR two) OR ((three OR four) AND five)} +} [list OR \ + [list NEAR/10 {PHRASE 3 0 one} {PHRASE 3 0 two}] \ + [list AND \ + [list OR {PHRASE 3 0 three} {PHRASE 3 0 four}] \ + {PHRASE 3 0 five} \ + ] \ + ] +do_test fts3expr-1.28 { + test_fts3expr {(one NEAR/321 two) OR ((three OR four) AND five)} +} [list OR \ + [list NEAR/321 {PHRASE 3 0 one} {PHRASE 3 0 two}] \ + [list AND \ + [list OR {PHRASE 3 0 three} {PHRASE 3 0 four}] \ + {PHRASE 3 0 five} \ + ] \ + ] + +proc strip_phrase_data {L} { + if {[lindex $L 0] eq "PHRASE"} { + return [lrange $L 3 end] + } + return [list \ + [lindex $L 0] \ + [strip_phrase_data [lindex $L 1]] \ + [strip_phrase_data [lindex $L 2]] \ + ] +} +proc test_fts3expr2 {expr} { + strip_phrase_data [ + db one {SELECT fts3_exprtest('simple', $expr, 'a', 'b', 'c')} + ] +} +do_test fts3expr-2.1 { + test_fts3expr2 "ab OR cd AND ef" +} {OR ab {AND cd ef}} +do_test fts3expr-2.2 { + test_fts3expr2 "cd AND ef OR ab" +} {OR {AND cd ef} ab} +do_test fts3expr-2.3 { + test_fts3expr2 "ab AND cd AND ef OR gh" +} {OR {AND {AND ab cd} ef} gh} +do_test fts3expr-2.4 { + test_fts3expr2 "ab AND cd OR ef AND gh" +} {OR {AND ab cd} {AND ef gh}} +do_test fts3expr-2.5 { + test_fts3expr2 "ab cd" +} {AND ab cd} + +do_test fts3expr-3.1 { + test_fts3expr2 "(ab OR cd) AND ef" +} {AND {OR ab cd} ef} +do_test fts3expr-3.2 { + test_fts3expr2 "ef AND (ab OR cd)" +} {AND ef {OR ab cd}} +do_test fts3expr-3.3 { + test_fts3expr2 "(ab OR cd)" +} {OR ab cd} +do_test fts3expr-3.4 { + test_fts3expr2 "(((ab OR cd)))" +} {OR ab cd} + +do_test fts3expr-3.5 { + test_fts3expr2 "one AND (two NEAR three)" +} {AND one {NEAR/10 two three}} +do_test fts3expr-3.6 { + test_fts3expr2 "one (two NEAR three)" +} {AND one {NEAR/10 two three}} +do_test fts3expr-3.7 { + test_fts3expr2 "(two NEAR three) one" +} {AND {NEAR/10 two three} one} +do_test fts3expr-3.8 { + test_fts3expr2 "(two NEAR three) AND one" +} {AND {NEAR/10 two three} one} +do_test fts3expr-3.9 { + test_fts3expr2 "(two NEAR three) (four five)" +} {AND {NEAR/10 two three} {AND four five}} +do_test fts3expr-3.10 { + test_fts3expr2 "(two NEAR three) AND (four five)" +} {AND {NEAR/10 two three} {AND four five}} +do_test fts3expr-3.11 { + test_fts3expr2 "(two NEAR three) (four NEAR five)" +} {AND {NEAR/10 two three} {NEAR/10 four five}} +do_test fts3expr-3.12 { + test_fts3expr2 "(two NEAR three) OR (four NEAR five)" +} {OR {NEAR/10 two three} {NEAR/10 four five}} + +do_test fts3expr-3.13 { + test_fts3expr2 "(two NEAR/1a three)" +} {AND {AND {AND two near} 1a} three} + +do_test fts3expr-3.14 { + test_fts3expr2 "(two NEAR// three)" +} {AND {AND two near} three} +do_test fts3expr-3.15 { + test_fts3expr2 "(two NEAR/: three)" +} {AND {AND two near} three} + +do_test fts3expr-3.16 { + test_fts3expr2 "(two NEAR three)OR(four NEAR five)" +} {OR {NEAR/10 two three} {NEAR/10 four five}} +do_test fts3expr-3.17 { + test_fts3expr2 "(two NEAR three)OR\"four five\"" +} {OR {NEAR/10 two three} {four five}} +do_test fts3expr-3.18 { + test_fts3expr2 "one \u0080wo" +} "AND one \u0080wo" + + + +#------------------------------------------------------------------------ +# The following tests, fts3expr-4.*, test the parsers response to syntax +# errors in query expressions. This is done using a real fts3 table and +# MATCH clauses, not the parser test interface. +# +do_test fts3expr-4.1 { + execsql { CREATE VIRTUAL TABLE t1 USING fts3(a, b, c) } +} {} + +# Mismatched parenthesis: +do_test fts3expr-4.2.1 { + catchsql { SELECT * FROM t1 WHERE t1 MATCH 'example AND (hello OR world))' } +} {1 {malformed MATCH expression: [example AND (hello OR world))]}} +do_test fts3expr-4.2.2 { + catchsql { SELECT * FROM t1 WHERE t1 MATCH 'example AND (hello OR world' } +} {1 {malformed MATCH expression: [example AND (hello OR world]}} +do_test fts3expr-4.2.3 { + catchsql { SELECT * FROM t1 WHERE t1 MATCH '(hello' } +} {1 {malformed MATCH expression: [(hello]}} +do_test fts3expr-4.2.4 { + catchsql { SELECT * FROM t1 WHERE t1 MATCH '(' } +} {1 {malformed MATCH expression: [(]}} +do_test fts3expr-4.2.5 { + catchsql { SELECT * FROM t1 WHERE t1 MATCH ')' } +} {1 {malformed MATCH expression: [)]}} + +do_test fts3expr-4.2.6 { + catchsql { SELECT * FROM t1 WHERE t1 MATCH 'example (hello world' } +} {1 {malformed MATCH expression: [example (hello world]}} + +# Unterminated quotation marks: +do_test fts3expr-4.3.1 { + catchsql { SELECT * FROM t1 WHERE t1 MATCH 'example OR "hello world' } +} {1 {malformed MATCH expression: [example OR "hello world]}} +do_test fts3expr-4.3.2 { + catchsql { SELECT * FROM t1 WHERE t1 MATCH 'example OR hello world"' } +} {1 {malformed MATCH expression: [example OR hello world"]}} + +# Binary operators without the required operands. +do_test fts3expr-4.4.1 { + catchsql { SELECT * FROM t1 WHERE t1 MATCH 'OR hello world' } +} {1 {malformed MATCH expression: [OR hello world]}} +do_test fts3expr-4.4.2 { + catchsql { SELECT * FROM t1 WHERE t1 MATCH 'hello world OR' } +} {1 {malformed MATCH expression: [hello world OR]}} +do_test fts3expr-4.4.3 { + catchsql { SELECT * FROM t1 WHERE t1 MATCH 'one (hello world OR) two' } +} {1 {malformed MATCH expression: [one (hello world OR) two]}} +do_test fts3expr-4.4.4 { + catchsql { SELECT * FROM t1 WHERE t1 MATCH 'one (OR hello world) two' } +} {1 {malformed MATCH expression: [one (OR hello world) two]}} + +# NEAR operators with something other than phrases as arguments. +do_test fts3expr-4.5.1 { + catchsql { SELECT * FROM t1 WHERE t1 MATCH '(hello OR world) NEAR one' } +} {1 {malformed MATCH expression: [(hello OR world) NEAR one]}} +do_test fts3expr-4.5.2 { + catchsql { SELECT * FROM t1 WHERE t1 MATCH 'one NEAR (hello OR world)' } +} {1 {malformed MATCH expression: [one NEAR (hello OR world)]}} + +#------------------------------------------------------------------------ +# The following OOM tests are designed to cover cases in fts3_expr.c. +# +source $testdir/malloc_common.tcl +do_malloc_test fts3expr-malloc-1 -sqlbody { + SELECT fts3_exprtest('simple', 'a b c "d e f"', 'a', 'b', 'c') +} +do_malloc_test fts3expr-malloc-2 -tclprep { + set sqlite_fts3_enable_parentheses 0 +} -sqlbody { + SELECT fts3_exprtest('simple', 'a -b', 'a', 'b', 'c') +} -cleanup { + set sqlite_fts3_enable_parentheses 1 +} + +#------------------------------------------------------------------------ +# The following tests are not very important. They cover error handling +# cases in the test code, which makes test coverage easier to measure. +# +do_test fts3expr-5.1 { + catchsql { SELECT fts3_exprtest('simple', 'a b') } +} {1 {Usage: fts3_exprtest(tokenizer, expr, col1, ...}} +do_test fts3expr-5.2 { + catchsql { SELECT fts3_exprtest('doesnotexist', 'a b', 'c') } +} {1 {unknown tokenizer: doesnotexist}} +do_test fts3expr-5.3 { + catchsql { SELECT fts3_exprtest('simple', 'a b OR', 'c') } +} {1 {Error parsing expression}} + +#------------------------------------------------------------------------ +# The next set of tests verifies that things actually work as they are +# supposed to when using the new syntax. +# +do_test fts3expr-6.1 { + execsql { + CREATE VIRTUAL TABLE t1 USING fts3(a); + } + for {set ii 1} {$ii < 32} {incr ii} { + set v [list] + if {$ii & 1} { lappend v one } + if {$ii & 2} { lappend v two } + if {$ii & 4} { lappend v three } + if {$ii & 8} { lappend v four } + if {$ii & 16} { lappend v five } + execsql { INSERT INTO t1 VALUES($v) } + } + + execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'five four one' ORDER BY rowid} +} {25 27 29 31} + +foreach {id expr res} { + + 2 "five four NOT one" {24 26 28 30} + + 3 "five AND four OR one" + {1 3 5 7 9 11 13 15 17 19 21 23 24 25 26 27 28 29 30 31} + + 4 "five AND (four OR one)" {17 19 21 23 24 25 26 27 28 29 30 31} + + 5 "five NOT (four OR one)" {16 18 20 22} + + 6 "(five NOT (four OR one)) OR (five AND (four OR one))" + {16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31} + + 7 "(five OR one) AND two AND three" {7 15 22 23 30 31} + + 8 "five OR one AND two AND three" + {7 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31} + + 9 "five OR one two three" + {7 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31} + + 10 "five OR \"one two three\"" + {7 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31} + + 11 "one two OR four five NOT three" {3 7 11 15 19 23 24 25 26 27 31} + + 12 "(one two OR four five) NOT three" {3 11 19 24 25 26 27} + + 13 "((((((one two OR four five)))))) NOT three" {3 11 19 24 25 26 27} + +} { + do_test fts3expr-6.1.$id { + execsql { SELECT rowid FROM t1 WHERE t1 MATCH $expr ORDER BY rowid } + } $res +} + +set sqlite_fts3_enable_parentheses 0 +foreach {id expr res} { + 1 "one -two three" {5 13 21 29} + 2 "-two one three" {5 13 21 29} + 3 "one three -two" {5 13 21 29} + 4 "-one -two three" {4 12 20 28} + 5 "three -one -two" {4 12 20 28} + 6 "-one three -two" {4 12 20 28} +} { + do_test fts3expr-6.2.$id { + execsql { SELECT rowid FROM t1 WHERE t1 MATCH $expr ORDER BY rowid } + } $res +} +set sqlite_fts3_enable_parentheses 1 + +do_test fts3expr-7.1 { + execsql { + CREATE VIRTUAL TABLE test USING fts3 (keyword); + INSERT INTO test VALUES ('abc'); + SELECT * FROM test WHERE keyword MATCH '""'; + } +} {} + + +do_test fts3expr-8.0 { test_fts3expr "(blah)" } {PHRASE 3 0 blah} +do_test fts3expr-8.1 { test_fts3expr "(blah.)" } {PHRASE 3 0 blah} +do_test fts3expr-8.2 { test_fts3expr "(blah,)" } {PHRASE 3 0 blah} +do_test fts3expr-8.3 { test_fts3expr "(blah!)" } {PHRASE 3 0 blah} +do_test fts3expr-8.4 { test_fts3expr "(blah-)" } {PHRASE 3 0 blah} + +do_test fts3expr-8.5 { test_fts3expr "((blah.))" } {PHRASE 3 0 blah} +do_test fts3expr-8.6 { test_fts3expr "(((blah,)))" } {PHRASE 3 0 blah} +do_test fts3expr-8.7 { test_fts3expr "((((blah!))))" } {PHRASE 3 0 blah} + +do_test fts3expr-8.8 { test_fts3expr "(,(blah-),)" } {PHRASE 3 0 blah} + +set sqlite_fts3_enable_parentheses 0 + +do_test fts3expr-9.1 { + test_fts3expr "f (e NEAR/2 a)" +} {AND {PHRASE 3 0 f} {NEAR/2 {PHRASE 3 0 e} {PHRASE 3 0 a}}} + +do_test fts3expr-10.1 { test_fts3expr "abc *" } {PHRASE 3 0 abc} +do_test fts3expr-10.2 { test_fts3expr "*" } {} +do_test fts3expr-10.3 { test_fts3expr "abc*" } {PHRASE 3 0 abc+} + +finish_test diff --git a/test/fts3expr2.test b/test/fts3expr2.test new file mode 100644 index 0000000..c3d1617 --- /dev/null +++ b/test/fts3expr2.test @@ -0,0 +1,166 @@ +# 2009 January 1 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS3 module syntax parser. +# +# $Id: fts3expr2.test,v 1.2 2009/06/05 17:09:12 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# Test overview: +# +# The tests in this file are pseudo-randomly generated. They test +# the fts3 match expression parser via the test interface +# SQL function "fts3_exprtest" (see comments in fts3_expr.c). +# +# Each test case works as follows: +# +# 1. A random expression tree is generated using proc [random_expr_tree]. +# 2. The expression tree is converted to the text of an equivalent +# fts3 expression using proc [tree_to_expr]. +# 3. The test SQL function "fts3_exprtest" is used to parse the +# expression text generated in step (2), returning a parsed expression +# tree. +# 4. Test that the tree returned in step (3) matches that generated in +# step (1). +# +# In step (2), 4 different fts3 expressions are created from each +# expression tree by varying the following boolean properties: +# +# * Whether or not superflous parenthesis are included. i.e. if +# "a OR b AND (c OR d)" or "a OR (b AND (c OR d))" is generated. +# +# * Whether or not explict AND operators are used. i.e. if +# "a OR b AND c" or "a OR b c" is generated. +# + +set sqlite_fts3_enable_parentheses 1 + +proc strip_phrase_data {L} { + if {[lindex $L 0] eq "PHRASE"} { + return [list P [lrange $L 3 end]] + } + return [list \ + [lindex $L 0] \ + [strip_phrase_data [lindex $L 1]] \ + [strip_phrase_data [lindex $L 2]] \ + ] +} +proc test_fts3expr2 {expr} { + strip_phrase_data [ + db one {SELECT fts3_exprtest('simple', $expr, 'a', 'b', 'c')} + ] +} + +proc rnd {nMax} { expr {int(rand()*$nMax)} } + +proc random_phrase {} { + set phrases [list one two three four "one two" "three four"] + list P [lindex $phrases [rnd [llength $phrases]]] +} + +# Generate and return a pseudo-random expression tree. Using the same +# format returned by the [test_fts3expr2] proc. +# +proc random_expr_tree {iHeight} { + if {$iHeight==0 || [rnd 3]==0} { + return [random_phrase] + } + + set operators [list NEAR NOT AND OR] + set op [lindex $operators [rnd 4]] + + if {$op eq "NEAR"} { + set iDistance [rnd 15] + return [list $op/$iDistance [random_phrase] [random_phrase]] + } + + set iNH [expr {$iHeight - 1}] + return [list $op [random_expr_tree $iNH] [random_expr_tree $iNH]] +} + +# Given an expression tree, generate a corresponding expression. +# +proc tree_to_expr {tree all_brackets implicit_and} { + set prec(NOT) 2 + set prec(AND) 3 + set prec() 3 + set prec(OR) 4 + + set op [lindex $tree 0] + + if {$op eq "P"} { + set phrase [lindex $tree 1] + if {[llength $phrase]>1} { + return "\"$phrase\"" + } else { + return $phrase + } + } + + if {$op eq "NEAR/10"} { + set op "NEAR" + } + if {$op eq "AND" && $implicit_and} { + set op "" + } + + set lhs [lindex $tree 1] + set rhs [lindex $tree 2] + set zLeft [tree_to_expr $lhs $all_brackets $implicit_and] + set zRight [tree_to_expr $rhs $all_brackets $implicit_and] + + set iPrec 5 + set iLeftPrec 0 + set iRightPrec 0 + + catch {set iPrec $prec($op)} + catch {set iLeftPrec $prec([lindex $lhs 0])} + catch {set iRightPrec $prec([lindex $rhs 0])} + + if {$iLeftPrec > $iPrec || $all_brackets} { + set zLeft "($zLeft)" + } + if {$iRightPrec >= $iPrec || $all_brackets} { + set zRight "($zRight)" + } + + return "$zLeft $op $zRight" +} + +proc do_exprparse_test {name expr tree} { + uplevel do_test $name [list "test_fts3expr2 {$expr}"] [list $tree] +} + +for {set iTest 1} {$iTest<500} {incr iTest} { + set t [random_expr_tree 4] + + set e1 [tree_to_expr $t 0 0] + set e2 [tree_to_expr $t 0 1] + set e3 [tree_to_expr $t 1 0] + set e4 [tree_to_expr $t 1 1] + + do_exprparse_test fts3expr2-$iTest.1 $e1 $t + do_exprparse_test fts3expr2-$iTest.2 $e2 $t + do_exprparse_test fts3expr2-$iTest.3 $e3 $t + do_exprparse_test fts3expr2-$iTest.4 $e4 $t +} + +set sqlite_fts3_enable_parentheses 0 +finish_test diff --git a/test/fts3expr3.test b/test/fts3expr3.test new file mode 100644 index 0000000..83c1532 --- /dev/null +++ b/test/fts3expr3.test @@ -0,0 +1,238 @@ +# 2009 January 1 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the part of the FTS3 expression +# parser that rebalances large expressions. +# +# $Id: fts3expr2.test,v 1.2 2009/06/05 17:09:12 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/malloc_common.tcl +set ::testprefix fts3expr3 + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +set sqlite_fts3_enable_parentheses 1 + +proc strip_phrase_data {L} { + if {[lindex $L 0] eq "PHRASE"} { + return [list P [lrange $L 3 end]] + } + return [list \ + [lindex $L 0] \ + [strip_phrase_data [lindex $L 1]] \ + [strip_phrase_data [lindex $L 2]] \ + ] +} +proc test_fts3expr2 {expr} { + strip_phrase_data [ + db one {SELECT fts3_exprtest_rebalance('simple', $expr, 'a', 'b', 'c')} + ] +} + +proc balanced_exprtree_structure {nEntry} { + set L [list] + for {set i 1} {$i <= $nEntry} {incr i} { + lappend L xxx + } + while {[llength $L] > 1} { + set N [list] + if {[llength $L] % 2} { + foreach {a b} [lrange $L 0 end-1] { lappend N [list AND $a $b] } + lappend N [lindex $L end] + } else { + foreach {a b} $L { lappend N [list AND $a $b] } + } + set L $N + } + return [lindex $L 0] +} + +proc balanced_and_tree {nEntry} { + set query [balanced_exprtree_structure $nEntry] + if {$query == "xxx"} { + return "P 1" + } + for {set i 1} {$i <= $nEntry} {incr i} { + regsub xxx $query "{P $i}" query + } + return $query +} + +proc random_tree_structure {nEntry bParen op} { + set query xxx + for {set i 1} {$i < $nEntry} {incr i} { + set x1 [expr int(rand()*4.0)] + set x2 [expr int(rand()*2.0)] + if {$x1==0 && $bParen} { + set query "($query)" + } + if {$x2} { + set query "xxx $op $query" + } else { + set query "$query $op xxx" + } + } + return $query +} + +proc random_and_query {nEntry {bParen 0}} { + set query [random_tree_structure $nEntry $bParen AND] + for {set i 1} {$i <= $nEntry} {incr i} { + regsub xxx $query $i query + } + return $query +} + +proc random_or_query {nEntry} { + set query [random_tree_structure $nEntry 1 OR] + for {set i 1} {$i <= $nEntry} {incr i} { + regsub xxx $query $i query + } + return $query +} + +proc random_andor_query {nEntry} { + set query [random_tree_structure $nEntry 1 AND] + for {set i 1} {$i <= $nEntry} {incr i} { + regsub xxx $query "([random_or_query $nEntry])" query + } + return $query +} + +proc balanced_andor_tree {nEntry} { + set tree [balanced_exprtree_structure $nEntry] + set node "{[balanced_and_tree $nEntry]}" + regsub -all AND $node OR node + regsub -all xxx $tree $node tree + return $tree +} + +if 1 { + +# Test that queries like "1 AND 2 AND 3 AND 4..." are transformed to +# balanced trees by FTS. +# +for {set i 1} {$i < 100} {incr i} { + do_test 1.$i { + test_fts3expr2 [random_and_query $i] + } [balanced_and_tree $i] +} + +# Same again, except with parenthesis inserted at arbitrary points. +# +for {set i 1} {$i < 100} {incr i} { + do_test 2.$i { + test_fts3expr2 [random_and_query $i 1] + } [balanced_and_tree $i] +} + +# Now attempt to balance two AND trees joined by an OR. +# +for {set i 1} {$i < 100} {incr i} { + do_test 3.$i { + test_fts3expr2 "[random_and_query $i 1] OR [random_and_query $i 1]" + } [list OR [balanced_and_tree $i] [balanced_and_tree $i]] +} + +# Try trees of AND nodes with leaves that are themselves trees of OR nodes. +# +for {set i 2} {$i < 64} {incr i 4} { + do_test 3.$i { + test_fts3expr2 [random_andor_query $i] + } [balanced_andor_tree $i] +} + +# These exceed the depth limit. +# +for {set i 65} {$i < 70} {incr i} { + do_test 3.$i { + list [catch {test_fts3expr2 [random_andor_query $i]} msg] $msg + } {1 {Error parsing expression}} +} + +# This also exceeds the depth limit. +# + +do_test 4.1.1 { + set q "1" + for {set i 2} {$i < 5000} {incr i} { + append q " AND $i" + } + list [catch {test_fts3expr2 $q} msg] $msg +} {1 {Error parsing expression}} +do_test 4.1.2 { + set q "1" + for {set i 2} {$i < 4000} {incr i} { + append q " AND $i" + } + catch {test_fts3expr2 $q} +} {0} + +proc create_toggle_tree {nDepth} { + if {$nDepth == 0} { return xxx } + set nNew [expr $nDepth-1] + if {$nDepth % 2} { + return "([create_toggle_tree $nNew]) OR ([create_toggle_tree $nNew])" + } + return "([create_toggle_tree $nNew]) AND ([create_toggle_tree $nNew])" +} + +do_test 4.2 { + list [catch {test_fts3expr2 [create_toggle_tree 17]} msg] $msg +} {1 {Error parsing expression}} + +set query [random_andor_query 12] +set result [balanced_andor_tree 12] +do_faultsim_test fts3expr3-fault-1 -faults oom-* -body { + test_fts3expr2 $::query +} -test { + faultsim_test_result [list 0 $::result] +} + +} + +#------------------------------------------------------------------- + +foreach {tn expr res} { + 1 {1 OR 2 OR 3 OR 4} {OR {OR {P 1} {P 2}} {OR {P 3} {P 4}}} + 2 {1 OR (2 AND 3 AND 4 AND 5)} + {OR {P 1} {AND {AND {P 2} {P 3}} {AND {P 4} {P 5}}}} + 3 {(2 AND 3 AND 4 AND 5) OR 1} + {OR {AND {AND {P 2} {P 3}} {AND {P 4} {P 5}}} {P 1}} + + 4 {1 AND (2 OR 3 OR 4 OR 5)} + {AND {P 1} {OR {OR {P 2} {P 3}} {OR {P 4} {P 5}}}} + 5 {(2 OR 3 OR 4 OR 5) AND 1} + {AND {OR {OR {P 2} {P 3}} {OR {P 4} {P 5}}} {P 1}} + + 6 {(2 OR 3 OR 4 OR 5) NOT 1} + {NOT {OR {OR {P 2} {P 3}} {OR {P 4} {P 5}}} {P 1}} + + 7 {1 NOT (2 OR 3 OR 4 OR 5)} + {NOT {P 1} {OR {OR {P 2} {P 3}} {OR {P 4} {P 5}}}} + + 8 {(1 OR 2 OR 3 OR 4) NOT (5 AND 6 AND 7 AND 8)} + {NOT {OR {OR {P 1} {P 2}} {OR {P 3} {P 4}}} {AND {AND {P 5} {P 6}} {AND {P 7} {P 8}}}} +} { + do_test 5.1.$tn { + test_fts3expr2 $expr + } $res +} + +set sqlite_fts3_enable_parentheses 0 +finish_test diff --git a/test/fts3expr4.test b/test/fts3expr4.test new file mode 100644 index 0000000..b9227ae --- /dev/null +++ b/test/fts3expr4.test @@ -0,0 +1,91 @@ +# 2014 May 7 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS3 module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts3expr4 + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3||!icu { + finish_test + return +} + +set sqlite_fts3_enable_parentheses 1 + +proc test_fts3expr {tokenizer expr} { + db one {SELECT fts3_exprtest($tokenizer, $expr, 'a', 'b', 'c')} +} + +proc do_icu_expr_test {tn expr res} { + set res2 [list {*}$res] + uplevel [list do_test $tn [list test_fts3expr "icu en_US" $expr] $res2] +} + +proc do_simple_expr_test {tn expr res} { + uplevel [list do_test $tn [list test_fts3expr simple $expr] [list {*}$res]] +} + +#------------------------------------------------------------------------- +# +do_icu_expr_test 1.1 "abcd" {PHRASE 3 0 abcd} +do_icu_expr_test 1.2 " tag " {PHRASE 3 0 tag} +do_icu_expr_test 1.3 {"x y z"} {PHRASE 3 0 x y z} +do_icu_expr_test 1.4 {x OR y} {OR {PHRASE 3 0 x} {PHRASE 3 0 y}} +do_icu_expr_test 1.5 {(x OR y)} {OR {PHRASE 3 0 x} {PHRASE 3 0 y}} +do_icu_expr_test 1.6 { "(x OR y)" } {PHRASE 3 0 ( x or y )} + +# In "col:word", if "col" is not the name of a column, the entire thing +# is passed to the tokenizer. +# +do_icu_expr_test 1.7 {a:word} {PHRASE 0 0 word} +# do_icu_expr_test 1.8 {d:word} {PHRASE 3 0 d:word} +do_test 1.8 { + set res [ + db one {SELECT fts3_exprtest('icu en_US', 'd:word', 'a', 'b', 'c')} + ] + expr { + $res=="PHRASE 3 0 d:word" || + $res=="AND {AND {PHRASE 3 0 d} {PHRASE 3 0 :}} {PHRASE 3 0 word}" + } +} 1 + +set sqlite_fts3_enable_parentheses 0 + +do_icu_expr_test 2.1 { + f (e NEAR/2 a) +} {AND {AND {AND {PHRASE 3 0 f} {PHRASE 3 0 (}} {NEAR/2 {PHRASE 3 0 e} {PHRASE 3 0 a}}} {PHRASE 3 0 )}} + +#------------------------------------------------------------------------- +# +do_simple_expr_test 3.1 {*lOl* *h4h*} { + AND {PHRASE 3 0 lol+} {PHRASE 3 0 h4h+} +} + +do_icu_expr_test 3.2 {*lOl* *h4h*} { + AND {AND {AND {PHRASE 3 0 *} {PHRASE 3 0 lol+}} {PHRASE 3 0 *}} {PHRASE 3 0 h4h+} +} + +do_simple_expr_test 3.3 { * } {} +do_simple_expr_test 3.4 { *a } { PHRASE 3 0 a } +do_simple_expr_test 3.5 { a*b } { AND {PHRASE 3 0 a+} {PHRASE 3 0 b} } +do_simple_expr_test 3.6 { *a*b } { AND {PHRASE 3 0 a+} {PHRASE 3 0 b} } +do_simple_expr_test 3.7 { *"abc" } { PHRASE 3 0 abc } +do_simple_expr_test 3.8 { "abc"* } { PHRASE 3 0 abc } +do_simple_expr_test 3.8 { "ab*c" } { PHRASE 3 0 ab+ c } + +do_icu_expr_test 3.9 { "ab*c" } { PHRASE 3 0 ab+ * c } +do_icu_expr_test 3.10 { ab*c } { AND {PHRASE 3 0 ab+} {PHRASE 3 0 c}} + +finish_test diff --git a/test/fts3expr5.test b/test/fts3expr5.test new file mode 100644 index 0000000..1317bef --- /dev/null +++ b/test/fts3expr5.test @@ -0,0 +1,66 @@ +# 2006 September 9 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS3 module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts3expr5 + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +proc test_fts3expr {expr} { + db one {SELECT fts3_exprtest('simple', $expr, 'a', 'b', 'c')} +} + +#------------------------------------------------------------------------- +# Various forms of empty phrase expressions. +# +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t0 USING fts3(x); + SELECT rowid FROM t0 WHERE x MATCH ''; +} {} +do_execsql_test 1.1 { + SELECT rowid FROM t0 WHERE x MATCH '""'; +} {} +do_execsql_test 1.2 { + SELECT rowid FROM t0 WHERE x MATCH '"" ""'; +} {} +do_execsql_test 1.3 { + SELECT rowid FROM t0 WHERE x MATCH '"" OR ""'; +} {} +do_execsql_test 1.4 { + SELECT rowid FROM t0 WHERE x MATCH '"" NOT ""'; +} {} +do_execsql_test 1.5 { + SELECT rowid FROM t0 WHERE x MATCH '""""'; +} {} + +#------------------------------------------------------------------------- +# Various forms of empty phrase expressions. +# +set sqlite_fts3_enable_parentheses 1 +do_test 2.0 { + test_fts3expr {(a:123)(b:234)()(c:456)} +} {AND {AND {PHRASE 0 0 123} {PHRASE 1 0 234}} {PHRASE 2 0 456}} +do_test 2.1 { + test_fts3expr {(a:123)(b:234)(c:456)} +} {AND {AND {PHRASE 0 0 123} {PHRASE 1 0 234}} {PHRASE 2 0 456}} +do_test 2.2 { + list [catch { test_fts3expr {"123" AND ( )} } msg] $msg +} {1 {Error parsing expression}} + +finish_test diff --git a/test/fts3f.test b/test/fts3f.test new file mode 100644 index 0000000..d9a57cb --- /dev/null +++ b/test/fts3f.test @@ -0,0 +1,57 @@ +# 2006 September 9 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS3 module. +# +# $Id: fts3aa.test,v 1.1 2007/08/20 17:38:42 shess Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts3f + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE ft USING fts3(x); + BEGIN; + INSERT INTO ft VALUES('a one'), ('b one'), ('c one'); +} + +do_test 1.1 { + set ret [list] + db eval { SELECT docid FROM ft WHERE ft MATCH 'one' } { + if { $docid==2 } { + db eval COMMIT + } + lappend ret $docid + } + set ret +} {1 2 3} + +do_execsql_test 1.2 { + BEGIN; + INSERT INTO ft VALUES('a one'), ('b one'), ('c one'); +} + +do_execsql_test 1.3 { + SELECT docid, optimize(ft) FROM ft WHERE ft MATCH 'one' +} { + 1 {Index optimized} 2 {Index already optimal} 3 {Index already optimal} + 4 {Index already optimal} + 5 {Index already optimal} 6 {Index already optimal} +} + +finish_test diff --git a/test/fts3fault.test b/test/fts3fault.test new file mode 100644 index 0000000..21defd2 --- /dev/null +++ b/test/fts3fault.test @@ -0,0 +1,263 @@ +# 2010 June 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +set ::testprefix fts3fault + +# If SQLITE_ENABLE_FTS3 is not defined, omit this file. +ifcapable !fts3 { finish_test ; return } + +set ::TMPDBERROR [list 1 \ + {unable to open a temporary database file for storing temporary tables} +] + +# Test error handling in the sqlite3Fts3Init() function. This is the +# function that registers the FTS3 module and various support functions +# with SQLite. +# +do_faultsim_test 1 -body { + sqlite3 db test.db + expr 0 +} -test { + catch { db close } +} + +# Test error handling in an "ALTER TABLE ... RENAME TO" statement on an +# FTS3 table. Specifically, test renaming the table within a transaction +# after it has been written to. +# +faultsim_delete_and_reopen +do_execsql_test 2.0 { + CREATE VIRTUAL TABLE t1 USING fts3; + INSERT INTO t1 VALUES('test renaming the table'); + INSERT INTO t1 VALUES(' after it has been written'); +} +do_faultsim_test 2 -prep { + sqlite3 db test.db + execsql { + BEGIN; + INSERT INTO t1 VALUES('registers the FTS3 module'); + INSERT INTO t1 VALUES('various support functions'); + } +} -body { + execsql { ALTER TABLE t1 RENAME TO t2 } +} -test { + faultsim_test_result {0 {}} $::TMPDBERROR +} + +# Test error handling in the special case where a single prefix query +# matches terms that reside on a large range of leaf nodes. +# +do_test fts3fault-3.0 { + sqlite3 db test.db + execsql { CREATE VIRTUAL TABLE t3 USING fts4; } + execsql { INSERT INTO t3(t3) VALUES('nodesize=50') } + execsql { BEGIN } + for {set i 0} {$i < 1000} {incr i} { + execsql { INSERT INTO t3 VALUES('aaa' || $i) } + } + execsql { COMMIT } +} {} + +do_faultsim_test 3 -faults oom-transient -prep { + sqlite3 db test.db + execsql { SELECT * FROM t3 WHERE t3 MATCH 'x' } +} -body { + execsql { SELECT count(rowid) FROM t3 WHERE t3 MATCH 'aa*' } +} -test { + faultsim_test_result {0 1000} +} + +do_test fts3fault-4.0 { + faultsim_delete_and_reopen + execsql { + CREATE VIRTUAL TABLE t4 USING fts4; + INSERT INTO t4 VALUES('The British Government called on'); + INSERT INTO t4 VALUES('as pesetas then became much'); + } +} {} +faultsim_save_and_close +do_faultsim_test 4 -prep { + faultsim_restore_and_reopen + execsql { SELECT content FROM t4 } +} -body { + execsql { SELECT optimize(t4) FROM t4 LIMIT 1 } +} -test { + faultsim_test_result {0 {{Index optimized}}} +} + +do_test fts3fault-5.0 { + faultsim_delete_and_reopen + execsql { + CREATE VIRTUAL TABLE t5 USING fts4; + INSERT INTO t5 VALUES('The British Government called on'); + INSERT INTO t5 VALUES('as pesetas then became much'); + } +} {} +faultsim_save_and_close +do_faultsim_test 5 -prep { + faultsim_restore_and_reopen + execsql { + BEGIN; + INSERT INTO t5 VALUES('influential in shaping his future outlook'); + INSERT INTO t5 VALUES('might be acceptable to the British electorate'); + } +} -body { + execsql { SELECT rowid FROM t5 WHERE t5 MATCH 'british' } +} -test { + faultsim_test_result {0 {1 4}} +} + +do_test fts3fault-6.0 { + faultsim_delete_and_reopen + execsql { CREATE VIRTUAL TABLE t6 USING fts4 } +} {} +faultsim_save_and_close +do_faultsim_test 6 -prep { + faultsim_restore_and_reopen + execsql { SELECT rowid FROM t6 } +} -body { + execsql { DROP TABLE t6 } +} -test { + faultsim_test_result {0 {}} +} + +# Test various malloc failures while processing FTS4 parameters. +# +do_faultsim_test 7.1 -prep { + faultsim_delete_and_reopen +} -body { + execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, matchinfo=fts3) } +} -test { + faultsim_test_result {0 {}} +} +do_faultsim_test 7.2 -prep { + faultsim_delete_and_reopen +} -body { + execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, matchinfo=fs3) } +} -test { + faultsim_test_result {1 {unrecognized matchinfo: fs3}} \ + {1 {vtable constructor failed: t1}} \ + {1 {SQL logic error}} +} +do_faultsim_test 7.3 -prep { + faultsim_delete_and_reopen +} -body { + execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, matchnfo=fts3) } +} -test { + faultsim_test_result {1 {unrecognized parameter: matchnfo=fts3}} \ + {1 {vtable constructor failed: t1}} \ + {1 {SQL logic error}} +} + + +proc mit {blob} { + set scan(littleEndian) i* + set scan(bigEndian) I* + binary scan $blob $scan($::tcl_platform(byteOrder)) r + return $r +} + +do_test 8.0 { + faultsim_delete_and_reopen + execsql { CREATE VIRTUAL TABLE t8 USING fts4 } + execsql "INSERT INTO t8 VALUES('a b c')" + execsql "INSERT INTO t8 VALUES('b b b')" + execsql "INSERT INTO t8 VALUES('[string repeat {c } 50000]')" + execsql "INSERT INTO t8 VALUES('d d d')" + execsql "INSERT INTO t8 VALUES('e e e')" + execsql "INSERT INTO t8(t8) VALUES('optimize')" + faultsim_save_and_close +} {} + +ifcapable fts4_deferred { + do_faultsim_test 8.1 -faults oom-t* -prep { + faultsim_restore_and_reopen + db func mit mit + } -body { + execsql { SELECT mit(matchinfo(t8, 'x')) FROM t8 WHERE t8 MATCH 'a b c' } + } -test { + faultsim_test_result {0 {{1 1 1 1 4 2 1 5 5}}} + } +} + +do_faultsim_test 8.2 -faults oom-t* -prep { + faultsim_restore_and_reopen + db func mit mit +} -body { + execsql { SELECT mit(matchinfo(t8, 's')) FROM t8 WHERE t8 MATCH 'a b c' } +} -test { + faultsim_test_result {0 3} $::TMPDBERROR +} +do_faultsim_test 8.3 -prep { + faultsim_restore_and_reopen + db func mit mit +} -body { + execsql { SELECT mit(matchinfo(t8, 'a')) FROM t8 WHERE t8 MATCH 'a b c' } +} -test { + faultsim_test_result {0 10002} +} +do_faultsim_test 8.4 -prep { + faultsim_restore_and_reopen + db func mit mit +} -body { + execsql { SELECT mit(matchinfo(t8, 'l')) FROM t8 WHERE t8 MATCH 'a b c' } +} -test { + faultsim_test_result {0 3} +} + +do_test 9.0 { + faultsim_delete_and_reopen + execsql { + CREATE VIRTUAL TABLE t9 USING fts4(tokenize=porter); + INSERT INTO t9 VALUES( + 'this record is used toooooooooooooooooooooooooooooooooooooo try to' + ); + SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to*'; + } + faultsim_save_and_close +} {} +do_faultsim_test 9.1 -prep { + faultsim_restore_and_reopen +} -body { + execsql { SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to*' } +} -test { + faultsim_test_result {0 {{0 0 20 39 0 0 64 2}}} +} + +do_faultsim_test 10.1 -prep { + faultsim_delete_and_reopen +} -body { + execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, languageid=d) } +} -test { + faultsim_test_result {0 {}} +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 11.0 { + CREATE VIRTUAL TABLE t1 USING fts3(a, b); +} +faultsim_save_and_close + +do_faultsim_test 11 -faults oom* -prep { + faultsim_restore_and_reopen +} -body { + execsql { DROP TABLE t1 } +} -test { + faultsim_test_result {0 {}} +} + + +finish_test diff --git a/test/fts3fault2.test b/test/fts3fault2.test new file mode 100644 index 0000000..913f9ba --- /dev/null +++ b/test/fts3fault2.test @@ -0,0 +1,250 @@ +# 2011 February 3 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix fts3fault2 + +# If SQLITE_ENABLE_FTS3 is not defined, omit this file. +ifcapable !fts3 { finish_test ; return } + +do_test 1.0 { + execsql { + CREATE VIRTUAL TABLE t1 USING fts4(x); + INSERT INTO t1 VALUES('a b c'); + INSERT INTO t1 VALUES('c d e'); + CREATE VIRTUAL TABLE terms USING fts4aux(t1); + } + faultsim_save_and_close +} {} + +do_faultsim_test 1.1 -prep { + faultsim_restore_and_reopen + db eval {SELECT * FROM sqlite_master} +} -body { + execsql "CREATE VIRTUAL TABLE terms2 USING fts4aux(t1)" +} -test { + faultsim_test_result {0 {}} +} + +do_faultsim_test 1.2 -prep { + faultsim_restore_and_reopen + db eval {SELECT * FROM sqlite_master} +} -body { + execsql "SELECT * FROM terms" +} -test { + faultsim_test_result {0 {a * 1 1 a 0 1 1 b * 1 1 b 0 1 1 c * 2 2 c 0 2 2 d * 1 1 d 0 1 1 e * 1 1 e 0 1 1}} +} + +do_faultsim_test 1.3 -prep { + faultsim_restore_and_reopen + db eval {SELECT * FROM sqlite_master} +} -body { + execsql "SELECT * FROM terms WHERE term>'a' AND TERM < 'd'" +} -test { + faultsim_test_result {0 {b * 1 1 b 0 1 1 c * 2 2 c 0 2 2}} +} + +do_faultsim_test 1.4 -prep { + faultsim_restore_and_reopen + db eval {SELECT * FROM sqlite_master} +} -body { + execsql "SELECT * FROM terms WHERE term='c'" +} -test { + faultsim_test_result {0 {c * 2 2 c 0 2 2}} +} + +do_test 2.0 { + faultsim_delete_and_reopen + execsql { + CREATE VIRTUAL TABLE tx USING fts4(a, b); + INSERT INTO tx VALUES('a b c', 'x y z'); + CREATE VIRTUAL TABLE terms2 USING fts4aux(tx); + } + faultsim_save_and_close +} {} + +do_faultsim_test 2.1 -prep { + faultsim_restore_and_reopen + db eval {SELECT * FROM sqlite_master} +} -body { + execsql "SELECT * FROM terms2" +} -test { + faultsim_test_result {0 {a * 1 1 a 0 1 1 b * 1 1 b 0 1 1 c * 1 1 c 0 1 1 x * 1 1 x 1 1 1 y * 1 1 y 1 1 1 z * 1 1 z 1 1 1}} +} + +do_faultsim_test 3.0 -faults oom* -prep { + faultsim_delete_and_reopen + db eval { CREATE TABLE 'xx yy'(a, b); } +} -body { + execsql { + CREATE VIRTUAL TABLE tt USING fts4(content="xx yy"); + } +} -test { + faultsim_test_result {0 {}} +} + +do_faultsim_test 3.1 -faults oom* -prep { + faultsim_delete_and_reopen + db func zip zip + db func unzip unzip +} -body { + execsql { + CREATE VIRTUAL TABLE tt USING fts4(compress=zip, uncompress=unzip); + } +} -test { + faultsim_test_result {0 {}} +} + +do_test 4.0 { + faultsim_delete_and_reopen + execsql { + CREATE VIRTUAL TABLE ft USING fts4(a, b); + INSERT INTO ft VALUES('U U T C O', 'F N D E S'); + INSERT INTO ft VALUES('P H X G B', 'I D M R U'); + INSERT INTO ft VALUES('P P X D M', 'Y V N T C'); + INSERT INTO ft VALUES('Z L Q O W', 'D F U N Q'); + INSERT INTO ft VALUES('A J D U P', 'C H M Q E'); + INSERT INTO ft VALUES('P S A O H', 'S Z C W D'); + INSERT INTO ft VALUES('T B N L W', 'C A K T I'); + INSERT INTO ft VALUES('K E Z L O', 'L L Y C E'); + INSERT INTO ft VALUES('C R E S V', 'Q V F W P'); + INSERT INTO ft VALUES('S K H G W', 'R W Q F G'); + } + faultsim_save_and_close +} {} +do_faultsim_test 4.1 -prep { + faultsim_restore_and_reopen + db eval {SELECT * FROM sqlite_master} +} -body { + execsql { INSERT INTO ft(ft) VALUES('rebuild') } +} -test { + faultsim_test_result {0 {}} +} + +ifcapable fts3_unicode { + do_test 5.0 { + faultsim_delete_and_reopen + execsql { + CREATE VIRTUAL TABLE ft USING fts4(a, tokenize=unicode61); + } + faultsim_save_and_close + } {} + + do_faultsim_test 5.1 -faults oom* -prep { + faultsim_restore_and_reopen + db eval {SELECT * FROM sqlite_master} + } -body { + execsql { INSERT INTO ft VALUES('the quick brown fox'); } + execsql { INSERT INTO ft VALUES( + 'theunusuallylongtokenthatjustdragsonandonandonandthendragsonsomemoreeof' + ); + } + execsql { SELECT docid FROM ft WHERE ft MATCH 'th*' } + } -test { + faultsim_test_result {0 {1 2}} + } +} + +reset_db +do_test 6.0 { + execsql { + CREATE VIRTUAL TABLE t6 USING fts4(x,order=DESC); + INSERT INTO t6(docid, x) VALUES(-1,'a b'); + INSERT INTO t6(docid, x) VALUES(1, 'b'); + } + faultsim_save_and_close +} {} + +do_faultsim_test 6.1 -faults oom* -prep { + faultsim_restore_and_reopen + db eval {SELECT * FROM sqlite_master} +} -body { + execsql { SELECT docid FROM t6 WHERE t6 MATCH '"a* b"' } +} -test { + faultsim_test_result {0 -1} +} + +#------------------------------------------------------------------------- +# Inject faults into a query for an N-byte prefix that uses a prefix=N+1 +# index. +reset_db +do_execsql_test 7.0 { + CREATE VIRTUAL TABLE t7 USING fts4(x,prefix=2); + INSERT INTO t7 VALUES('the quick brown fox'); + INSERT INTO t7 VALUES('jumped over the'); + INSERT INTO t7 VALUES('lazy dog'); +} +do_faultsim_test 7.1 -faults oom* -body { + execsql { SELECT docid FROM t7 WHERE t7 MATCH 't*' } +} -test { + faultsim_test_result {0 {1 2}} +} + +#------------------------------------------------------------------------- +# Inject faults into a opening an existing fts3 table that has been +# upgraded to add an %_stat table. +# +reset_db +do_execsql_test 8.0 { + CREATE VIRTUAL TABLE t8 USING fts3; + INSERT INTO t8 VALUES('the quick brown fox'); + INSERT INTO t8 VALUES('jumped over the'); + INSERT INTO t8 VALUES('lazy dog'); + INSERT INTO t8(t8) VALUES('automerge=8'); + SELECT name FROM sqlite_master WHERE name LIKE 't8%'; +} { + t8 t8_content t8_segments t8_segdir t8_stat +} +faultsim_save_and_close + +do_faultsim_test 8.1 -faults oom* -prep { + faultsim_restore_and_reopen +} -body { + execsql { INSERT INTO t8 VALUES('one two three') } +} -test { + faultsim_test_result {0 {}} +} + +set ::TMPDBERROR [list 1 \ + {unable to open a temporary database file for storing temporary tables} +] +do_faultsim_test 8.2 -faults oom* -prep { + faultsim_restore_and_reopen +} -body { + execsql { ALTER TABLE t8 RENAME TO t8ii } +} -test { + faultsim_test_result {0 {}} $::TMPDBERROR +} + +#------------------------------------------------------------------------- +reset_db +set chunkconfig [fts3_configure_incr_load 1 1] +do_execsql_test 9.0 { + PRAGMA page_size = 512; + CREATE VIRTUAL TABLE t9 USING fts3; + WITH s(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<50 + ) + INSERT INTO t9 SELECT 'one two three' FROM s; +} + +do_faultsim_test 8.2 -faults io* -body { + execsql { SELECT count(*) FROM t9 WHERE t9 MATCH '"one two three"' } +} -test { + faultsim_test_result {0 50} +} + +eval fts3_configure_incr_load $chunkconfig + + +finish_test diff --git a/test/fts3fault3.test b/test/fts3fault3.test new file mode 100644 index 0000000..6e1c0cd --- /dev/null +++ b/test/fts3fault3.test @@ -0,0 +1,54 @@ +# 2023 October 23 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +set ::testprefix fts3fault + +# If SQLITE_ENABLE_FTS3 is not defined, omit this file. +ifcapable !fts3 { finish_test ; return } + +set ::TMPDBERROR [list 1 \ + {unable to open a temporary database file for storing temporary tables} +] + + +# Test error handling in an "ALTER TABLE ... RENAME TO" statement on an +# FTS3 table. Specifically, test renaming the table within a transaction +# after it has been written to. +# +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t1 USING fts3(a); + INSERT INTO t1 VALUES('test renaming the table'); + INSERT INTO t1 VALUES(' after it has been written'); + INSERT INTO t1 VALUES(' actually other stuff instead'); +} +faultsim_save_and_close +do_faultsim_test 1 -faults oom* -prep { + faultsim_restore_and_reopen + execsql { + BEGIN; + DELETE FROM t1 WHERE rowid=2; + } +} -body { + execsql { + DELETE FROM t1; + } +} -test { + catchsql { COMMIT } + faultsim_integrity_check + faultsim_test_result {0 {}} +} + + +finish_test diff --git a/test/fts3first.test b/test/fts3first.test new file mode 100644 index 0000000..673f818 --- /dev/null +++ b/test/fts3first.test @@ -0,0 +1,163 @@ +# 2011 October 18 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/malloc_common.tcl + +ifcapable !fts3 { + finish_test + return +} + +set testprefix fts3first + +proc lreverse {L} { + set res [list] + for {set ii [expr [llength $L]-1]} {$ii>=0} {incr ii -1} { + lappend res [lindex $L $ii] + } + set res +} + +proc mit {blob} { + set scan(littleEndian) i* + set scan(bigEndian) I* + binary scan $blob $scan($::tcl_platform(byteOrder)) r + return $r +} +db func mit mit + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE x1 USING FTS4(a, b, c); + INSERT INTO x1(docid,a,b,c) VALUES(0, 'K H D S T', 'V M N Y K', 'S Z N Q S'); + INSERT INTO x1(docid,a,b,c) VALUES(1, 'K N J L W', 'S Z W J Q', 'D U W S E'); + INSERT INTO x1(docid,a,b,c) VALUES(2, 'B P M O I', 'R P H W S', 'R J L L E'); + INSERT INTO x1(docid,a,b,c) VALUES(3, 'U R Q M L', 'M J K A V', 'Q W J T J'); + INSERT INTO x1(docid,a,b,c) VALUES(4, 'N J C Y N', 'R U D X V', 'B O U A Q'); + INSERT INTO x1(docid,a,b,c) VALUES(5, 'Q L X L U', 'I F N X S', 'U Q A N Y'); + INSERT INTO x1(docid,a,b,c) VALUES(6, 'M R G U T', 'U V I Q P', 'X Y D L S'); + INSERT INTO x1(docid,a,b,c) VALUES(7, 'D Y P O I', 'X J P K R', 'V O T H V'); + INSERT INTO x1(docid,a,b,c) VALUES(8, 'R Y D L R', 'U U E S J', 'N W L M R'); + INSERT INTO x1(docid,a,b,c) VALUES(9, 'Z P F N P', 'W A X D U', 'V A E Q A'); + INSERT INTO x1(docid,a,b,c) VALUES(10, 'Q I A Q M', 'N D K H C', 'A H T Q Z'); + INSERT INTO x1(docid,a,b,c) VALUES(11, 'T E R Q B', 'C I B C B', 'F Z U W R'); + INSERT INTO x1(docid,a,b,c) VALUES(12, 'E S V U W', 'T P F W H', 'A M D J Q'); + INSERT INTO x1(docid,a,b,c) VALUES(13, 'X S B X Y', 'U D N D P', 'X Z Y G F'); + INSERT INTO x1(docid,a,b,c) VALUES(14, 'K H A B L', 'S R C C Z', 'D W E H J'); + INSERT INTO x1(docid,a,b,c) VALUES(15, 'C E U C C', 'W F M N M', 'T Z U X T'); + INSERT INTO x1(docid,a,b,c) VALUES(16, 'Q G C G H', 'H N N B H', 'B Q I H Y'); + INSERT INTO x1(docid,a,b,c) VALUES(17, 'Q T S K B', 'W B D Y N', 'V J P E C'); + INSERT INTO x1(docid,a,b,c) VALUES(18, 'A J M O Q', 'L G Y Y A', 'G N M R N'); + INSERT INTO x1(docid,a,b,c) VALUES(19, 'T R Y P Y', 'N V Y B X', 'L Z T N T'); + + CREATE VIRTUAL TABLE x2 USING FTS4(a, b, c, order=DESC); + INSERT INTO x2(docid, a, b, c) SELECT docid, a, b, c FROM x1; +} + + +# Test queries. +# +foreach x {1 2} { + foreach {tn match res} { + 1 "^K" {0 1 14} + 2 "^S" {0 1 14} + 3 "^W" {9 15 17} + 4 "^J" {} + 5 "^E" {12} + 6 "V ^-E" {0 3 4 6 7 9 17 19} + 7 "V -^E" {0 3 4 6 7 9 17 19} + 8 "^-E V" {0 3 4 6 7 9 17 19} + 9 "-^E V" {0 3 4 6 7 9 17 19} + 10 "V" {0 3 4 6 7 9 12 17 19} + + 11 {"^K H"} {0 14} + 12 {"K H"} {0 10 14} + 13 {"K ^H"} {} + } { + set rev [lreverse $res] + do_execsql_test 1.$x.$tn.1 {SELECT docid FROM x1 WHERE x1 MATCH $match} $res + do_execsql_test 1.$x.$tn.2 {SELECT docid FROM x2 WHERE x2 MATCH $match} $rev + } + + do_execsql_test 1.$x.[expr $tn+1] { + INSERT INTO x1(x1) VALUES('optimize'); + INSERT INTO x2(x2) VALUES('optimize'); + } {} +} + +# Test the snippet() function. +# +foreach {tn match res} { + 1 {^K} {{[K] H D S T} {[K] N J L W} {[K] H A B L}} + 2 {^X} {{[X] Y D L S} {[X] J P K R} {[X] S B X Y}} + 3 {^X Y} {{[X] [Y] D L S} {D [Y] P O I...[X] J P K R} {[X] S B X [Y]}} +} { + set rev [lreverse $res] + + do_execsql_test 1.3.$tn.1 { + SELECT snippet(x1, '[', ']', '...') FROM x1 WHERE x1 MATCH $match + } $res + + do_execsql_test 1.3.$tn.2 { + SELECT snippet(x2, '[', ']', '...') FROM x2 WHERE x2 MATCH $match + } $rev +} + +# Test matchinfo(). +# +foreach {tn match res} { + 1 {^K} { + {1 3 3 0 0 0 0 0 0} + {1 3 3 0 0 0 0 0 0} + {1 3 3 0 0 0 0 0 0} + } + 2 {^X} { + {0 1 1 0 1 1 1 2 2} + {0 1 1 1 1 1 0 2 2} + {1 1 1 0 1 1 1 2 2} + } + 3 {^X Y} { + {0 1 1 0 1 1 1 2 2 0 6 5 0 5 4 1 4 4} + {0 1 1 1 1 1 0 2 2 1 6 5 0 5 4 0 4 4} + {1 1 1 0 1 1 1 2 2 1 6 5 0 5 4 1 4 4} + } +} { + set rev [lreverse $res] + + do_execsql_test 1.3.$tn.1 { + SELECT mit(matchinfo(x1, 'x')) FROM x1 WHERE x1 MATCH $match + } $res + do_execsql_test 1.3.$tn.2 { + SELECT mit(matchinfo(x2, 'x')) FROM x2 WHERE x2 MATCH $match + } $rev +} + +# Test that ^ is ignored for FTS3 tables. +# +do_execsql_test 2.1 { + CREATE VIRTUAL TABLE x3 USING fts3; + INSERT INTO x3 VALUES('A B C'); + INSERT INTO x3 VALUES('B A C'); + + CREATE VIRTUAL TABLE x4 USING fts4; + INSERT INTO x4 VALUES('A B C'); + INSERT INTO x4 VALUES('B A C'); +} + +do_execsql_test 2.2.1 { + SELECT * FROM x3 WHERE x3 MATCH '^A'; +} {{A B C} {B A C}} +do_execsql_test 2.2.2 { + SELECT * FROM x4 WHERE x4 MATCH '^A'; +} {{A B C}} + +finish_test diff --git a/test/fts3fuzz001.test b/test/fts3fuzz001.test new file mode 100644 index 0000000..6b1ae90 --- /dev/null +++ b/test/fts3fuzz001.test @@ -0,0 +1,141 @@ +# 2012-12-21 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Test cases for corrupt database files. + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts3fuzz001 + +ifcapable !deserialize||!fts3 { + finish_test + return +} +database_may_be_corrupt + +do_test fts3fuzz001-100 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 24576 pagesize 4096 filename c6.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 06 .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ +| 96: 00 00 00 00 0d 0e f9 00 06 0d ec 00 0f cd 0f 69 ...............i +| 112: 0f 01 0e 10 0e c6 0d ec 00 00 00 00 00 00 00 00 ................ +| 3552: 00 00 00 00 00 00 00 00 00 00 00 00 22 06 06 17 ............"... +| 3568: 11 11 01 31 74 61 62 6c 65 74 32 74 32 06 43 52 ...1tablet2t2.CR +| 3584: 45 41 54 45 20 54 41 42 4c 45 20 74 32 28 78 29 EATE TABLE t2(x) +| 3600: 81 33 04 07 17 1f 1f 01 82 35 74 61 62 6c 65 74 .3.......5tablet +| 3616: 31 5f 73 65 67 64 69 72 74 31 5f 73 65 67 64 69 1_segdirt1_segdi +| 3632: 72 04 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 r.CREATE TABLE ' +| 3648: 74 31 5f 73 65 67 64 69 72 27 28 6c 65 76 65 6c t1_segdir'(level +| 3664: 20 49 4e 54 45 47 45 52 2c 69 64 78 20 49 4e 54 INTEGER,idx INT +| 3680: 45 47 45 52 2c 73 74 61 72 74 5f 62 6c 6f 63 6b EGER,start_block +| 3696: 20 49 4e 54 45 47 45 52 2c 6c 65 61 76 65 73 5f INTEGER,leaves_ +| 3712: 65 6e 64 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 end_block INTEGE +| 3728: 52 2c 65 6e 64 5f 62 6c 6f 63 6b 20 49 4e 54 45 R,end_block INTE +| 3744: 47 45 52 2c 72 6f 6f 74 20 42 4c 4f 42 2c 50 52 GER,root BLOB,PR +| 3760: 49 4d 41 52 59 20 4b 45 59 28 6c 65 76 65 6c 2c IMARY KEY(level, +| 3776: 20 69 64 78 29 29 31 05 06 17 45 1f 01 00 69 6e idx))1...E...in +| 3792: 64 65 78 73 71 6c 69 74 65 5f 61 75 74 6f 69 6e dexsqlite_autoin +| 3808: 64 65 78 5f 74 15 f7 36 56 76 46 97 25 f3 17 43 dex_t..6VvF.%..C +| 3824: 15 5f 73 65 67 64 69 72 05 00 00 00 08 00 00 00 ._segdir........ +| 3840: 00 66 03 07 17 23 23 01 81 13 74 61 62 6c 65 74 .f...##...tablet +| 3856: 31 5f 73 65 67 6d 65 6e 74 73 74 31 5f 73 65 67 1_segmentst1_seg +| 3872: 6d 65 6e 74 73 03 43 52 45 41 54 45 20 54 41 42 ments.CREATE TAB +| 3888: 4c 45 20 27 74 31 5f 73 65 67 6d 65 6e 74 73 27 LE 't1_segments' +| 3904: 28 62 6c 6f 63 6b 69 64 20 49 4e 54 45 47 45 52 (blockid INTEGER +| 3920: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 62 6c PRIMARY KEY, bl +| 3936: 6f 63 6b 20 42 4c 4f 42 29 62 02 07 17 21 21 01 ock BLOB)b...!!. +| 3952: 81 0f 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65 6e ..tablet1_conten +| 3968: 74 74 31 5f 63 6f 6e 74 65 6e 74 02 43 52 45 41 tt1_content.CREA +| 3984: 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f 6e TE TABLE 't1_con +| 4000: 74 65 6e 74 27 28 64 6f 63 69 64 20 49 4e 54 45 tent'(docid INTE +| 4016: 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c GER PRIMARY KEY, +| 4032: 20 27 63 30 63 6f 6e 74 65 6e 74 27 29 31 01 06 'c0content')1.. +| 4048: 17 11 11 08 51 74 61 62 6c 65 74 31 74 31 43 52 ....Qtablet1t1CR +| 4064: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB +| 4080: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33 LE t1 USING fts3 +| page 2 offset 4096 +| 0: 0d 00 00 00 03 0f e0 00 0f f6 0f ec 0f e0 00 00 ................ +| 4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00 .....abandon.... +| 4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b .abaft.....aback +| page 3 offset 8192 +| 0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................ +| page 4 offset 12288 +| 0: 0d 00 00 00 01 0f d6 00 0f 00 00 00 00 00 00 00 ................ +| 4048: 00 00 00 00 00 00 28 01 07 08 08 08 08 15 46 30 ......(.......F0 +| 4064: 20 32 39 00 05 61 62 61 63 6b 03 01 02 00 03 02 29..aback...... +| 4080: 66 74 03 02 02 00 03 04 6e 64 6f 6e 03 03 02 00 ft......ndon.... +| page 5 offset 16384 +| 0: 0a 00 00 00 01 0f fb 00 0f fb 00 00 00 00 00 00 ................ +| 4080: 00 00 00 00 00 00 00 00 00 00 00 04 04 08 08 09 ................ +| page 6 offset 20480 +| 0: 0d 00 00 00 05 0f b8 00 0f f4 0f e9 0f d6 0f c7 ................ +| 16: 0f b8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 4016: 00 00 00 00 00 00 00 00 0d 05 02 23 61 75 74 6f ...........#auto +| 4032: 6d 65 72 67 65 3d 35 0d 04 02 23 6d 65 72 67 65 merge=5...#merge +| 4048: 3d 31 30 30 2c 38 11 03 02 2b 69 6e 74 65 67 72 =100,8...+integr +| 4064: 69 74 79 3d 63 68 65 63 6b 09 02 02 1b 72 65 62 ity=check....reb +| 4080: 75 69 6c 64 0a 01 02 1d 6f 70 74 69 6d 69 7a 65 uild....optimize +| end c6.db + }] + catchsql { + PRAGMA writable_schema=on; -- disable schema corruption detection + INSERT INTO t1(t1) SELECT x FROM t2; + } +} {1 {database disk image is malformed}} +do_test fts3fuzz001-110 { + catchsql { + INSERT INTO t1(t1) VALUES('integrity-check'); + } +} {1 {database disk image is malformed}} +do_test fts3fuzz001-120 { + catchsql { + INSERT INTO t1(t1) VALUES('optimize'); + } +} {1 {database disk image is malformed}} +do_test fts3fuzz001-121 { + catchsql { + INSERT INTO t1(t1) VALUES('integrity-check'); + } +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 200 { + CREATE VIRTUAL TABLE x1 USING fts3(x); + + INSERT INTO x1 VALUES('braes brag bragged bragger bragging'); + INSERT INTO x1 VALUES('brags braid braided braiding braids'); + INSERT INTO x1 VALUES('brain brainchild brained braining brains'); + INSERT INTO x1 VALUES('brainstem brainstems brainstorm brainstorms'); + INSERT INTO x1(x1) VALUES('nodesize=24'); +} + +do_execsql_test 210 { + PRAGMA integrity_check; +} {ok} + +do_execsql_test 220 { + INSERT INTO x1(x1) VALUES('merge=10,2') +} + +do_execsql_test 220 { + PRAGMA integrity_check; +} {ok} + + + + +finish_test diff --git a/test/fts3integrity.test b/test/fts3integrity.test new file mode 100644 index 0000000..bcbc49d --- /dev/null +++ b/test/fts3integrity.test @@ -0,0 +1,42 @@ +# 2023 December 16 +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file runs all tests. +# +# $Id: fts3.test,v 1.2 2008/07/23 18:17:32 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix fts3integrity + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t1 USING fts3(x); + INSERT INTO t1 VALUES('first row'); + INSERT INTO t1 VALUES('second row'); + + CREATE TABLE t2(x PRIMARY KEY); + INSERT INTO t2 VALUES('first row'); + INSERT INTO t2 VALUES('second row'); +} + +sqlite3 db2 test.db + +do_execsql_test -db db2 1.1 { + CREATE TABLE t3(x, y); +} + +do_execsql_test 1.2 { + PRAGMA integrity_check; +} {ok} + +finish_test diff --git a/test/fts3join.test b/test/fts3join.test new file mode 100644 index 0000000..cbd08b6 --- /dev/null +++ b/test/fts3join.test @@ -0,0 +1,107 @@ +# 2014 January 4 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS3 module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix fts3join + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE ft1 USING fts4(x); + INSERT INTO ft1 VALUES('aaa aaa'); + INSERT INTO ft1 VALUES('aaa bbb'); + INSERT INTO ft1 VALUES('bbb aaa'); + INSERT INTO ft1 VALUES('bbb bbb'); + + CREATE TABLE t1(id, y); + INSERT INTO t1 VALUES(1, 'aaa'); + INSERT INTO t1 VALUES(2, 'bbb'); +} + +do_execsql_test 1.1 { + SELECT docid FROM ft1, t1 WHERE ft1 MATCH y AND id=1; +} {1 2 3} + +do_execsql_test 1.2 { + SELECT docid FROM ft1, t1 WHERE ft1 MATCH y AND id=1 ORDER BY docid; +} {1 2 3} + +do_execsql_test 2.0 { + CREATE VIRTUAL TABLE ft2 USING fts4(x); + CREATE VIRTUAL TABLE ft3 USING fts4(y); + + INSERT INTO ft2 VALUES('abc'); + INSERT INTO ft2 VALUES('def'); + INSERT INTO ft3 VALUES('ghi'); + INSERT INTO ft3 VALUES('abc'); +} + +do_execsql_test 2.1 { SELECT * FROM ft2, ft3 WHERE x MATCH y; } {abc abc} +do_execsql_test 2.2 { SELECT * FROM ft2, ft3 WHERE y MATCH x; } {abc abc} +do_execsql_test 2.3 { SELECT * FROM ft3, ft2 WHERE x MATCH y; } {abc abc} +do_execsql_test 2.4 { SELECT * FROM ft3, ft2 WHERE y MATCH x; } {abc abc} + +do_catchsql_test 2.5 { + SELECT * FROM ft3, ft2 WHERE y MATCH x AND x MATCH y; +} {1 {unable to use function MATCH in the requested context}} + +do_execsql_test 3.0 { + CREATE VIRTUAL TABLE vt USING fts3(x); + INSERT INTO vt VALUES('abc'); + INSERT INTO vt VALUES('xyz'); + + CREATE TABLE tt(a INTEGER PRIMARY KEY); + INSERT INTO tt VALUES(1), (2); +} + +do_execsql_test 3.1 { + SELECT * FROM tt LEFT JOIN ( + SELECT rowid AS rrr, * FROM vt WHERE vt MATCH 'abc' + ) ON tt.a = rrr +} {1 1 abc 2 {} {}} + +do_execsql_test 3.2 { + SELECT * FROM tt LEFT JOIN vt ON (vt MATCH 'abc') +} {1 abc 2 abc} + +#------------------------------------------------------------------------- +# Test that queries of the form found in test case 4.2 use an automatic +# index to avoid running multiple fts queries. +# +do_execsql_test 4.1 { + CREATE VIRTUAL TABLE ft4 USING fts3(x); + CREATE TABLE t4(y, z); + CREATE INDEX t4y ON t1(y); +} + +do_eqp_test 4.2 { + SELECT * FROM t4 LEFT JOIN ( + SELECT docid, * FROM ft4 WHERE ft4 MATCH ? + ) AS rr ON t4.rowid=rr.docid + WHERE t4.y = ?; +} { + QUERY PLAN + |--MATERIALIZE rr + | `--SCAN ft4 VIRTUAL TABLE INDEX 3: + |--SCAN t4 + |--BLOOM FILTER ON rr (docid=?) + `--SEARCH rr USING AUTOMATIC COVERING INDEX (docid=?) LEFT-JOIN +} + +finish_test diff --git a/test/fts3malloc.test b/test/fts3malloc.test new file mode 100644 index 0000000..ed30fe2 --- /dev/null +++ b/test/fts3malloc.test @@ -0,0 +1,307 @@ +# 2009 October 22 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file contains tests to verify that malloc() errors that occur +# within the FTS3 module code are handled correctly. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +ifcapable !fts3 { finish_test ; return } +source $testdir/malloc_common.tcl +source $testdir/fts3_common.tcl + +# Ensure the lookaside buffer is disabled for these tests. +# +sqlite3 db test.db +sqlite3_db_config_lookaside db 0 0 0 + +set sqlite_fts3_enable_parentheses 1 +set DO_MALLOC_TEST 1 + +# Test organization: +# +# fts3_malloc-1.*: Test OOM during CREATE and DROP table statements. +# fts3_malloc-2.*: Test OOM during SELECT operations. +# fts3_malloc-3.*: Test OOM during SELECT operations with a larger database. +# fts3_malloc-4.*: Test OOM during database write operations. +# fts3_malloc-5.*: Test that a couple of memory leaks that could follow +# OOM in tokenizer code have been fixed. +# + + +proc normal_list {l} { + set ret [list] + foreach elem $l {lappend ret $elem} + set ret +} + +do_write_test fts3_malloc-1.1 sqlite_master { + CREATE VIRTUAL TABLE ft1 USING fts3(a, b) +} +do_write_test fts3_malloc-1.2 sqlite_master { + CREATE VIRTUAL TABLE ft2 USING fts3([a], [b]); +} +do_write_test fts3_malloc-1.3 sqlite_master { + CREATE VIRTUAL TABLE ft3 USING fts3('a', "b"); +} +do_write_test fts3_malloc-1.4 sqlite_master { + CREATE VIRTUAL TABLE ft4 USING fts3(`a`, 'fred''s column'); +} +do_error_test fts3_malloc-1.5 { + CREATE VIRTUAL TABLE ft5 USING fts3(a, b, tokenize unknown) +} {unknown tokenizer: unknown} +do_write_test fts3_malloc-1.6 sqlite_master { + CREATE VIRTUAL TABLE ft6 USING fts3(a, b, tokenize porter) +} +do_write_test fts3_malloc-1.7 sqlite_master { + CREATE VIRTUAL TABLE ft7 USING fts4(a, b, notindexed=b) +} + +# Test the xConnect/xDisconnect methods: +#db eval { ATTACH 'test2.db' AS aux } +#do_write_test fts3_malloc-1.6 aux.sqlite_master { +# CREATE VIRTUAL TABLE aux.ft7 USING fts3(a, b, c); +#} +#do_write_test fts3_malloc-1.6 aux.sqlite_master { +# CREATE VIRTUAL TABLE aux.ft7 USING fts3(a, b, c); +#} + + + +do_test fts3_malloc-2.0 { + execsql { + DROP TABLE ft1; + DROP TABLE ft2; + DROP TABLE ft3; + DROP TABLE ft4; + DROP TABLE ft6; + DROP TABLE ft7; + } + execsql { CREATE VIRTUAL TABLE ft USING fts3(a, b) } + for {set ii 1} {$ii < 32} {incr ii} { + set a [list] + set b [list] + if {$ii & 0x01} {lappend a one ; lappend b neung} + if {$ii & 0x02} {lappend a two ; lappend b song } + if {$ii & 0x04} {lappend a three ; lappend b sahm } + if {$ii & 0x08} {lappend a four ; lappend b see } + if {$ii & 0x10} {lappend a five ; lappend b hah } + execsql { INSERT INTO ft VALUES($a, $b) } + } +} {} + +foreach {tn sql result} { + 1 "SELECT count(*) FROM sqlite_master" {5} + 2 "SELECT * FROM ft WHERE docid = 1" {one neung} + 3 "SELECT * FROM ft WHERE docid = 2" {two song} + 4 "SELECT * FROM ft WHERE docid = 3" {{one two} {neung song}} + + 5 "SELECT a FROM ft" { + {one} {two} {one two} + {three} {one three} {two three} + {one two three} {four} {one four} + {two four} {one two four} {three four} + {one three four} {two three four} {one two three four} + {five} {one five} {two five} + {one two five} {three five} {one three five} + {two three five} {one two three five} {four five} + {one four five} {two four five} {one two four five} + {three four five} {one three four five} {two three four five} + {one two three four five} + } + + 6 "SELECT a FROM ft WHERE a MATCH 'one'" { + {one} {one two} {one three} {one two three} + {one four} {one two four} {one three four} {one two three four} + {one five} {one two five} {one three five} {one two three five} + {one four five} {one two four five} + {one three four five} {one two three four five} + } + + 7 "SELECT a FROM ft WHERE a MATCH 'o*'" { + {one} {one two} {one three} {one two three} + {one four} {one two four} {one three four} {one two three four} + {one five} {one two five} {one three five} {one two three five} + {one four five} {one two four five} + {one three four five} {one two three four five} + } + + 8 "SELECT a FROM ft WHERE a MATCH 'o* t*'" { + {one two} {one three} {one two three} + {one two four} {one three four} {one two three four} + {one two five} {one three five} {one two three five} + {one two four five} {one three four five} {one two three four five} + } + + 9 "SELECT a FROM ft WHERE a MATCH '\"o* t*\"'" { + {one two} {one three} {one two three} + {one two four} {one three four} {one two three four} + {one two five} {one three five} {one two three five} + {one two four five} {one three four five} {one two three four five} + } + + 10 {SELECT a FROM ft WHERE a MATCH '"o* f*"'} { + {one four} {one five} {one four five} + } + + 11 {SELECT a FROM ft WHERE a MATCH '"one two three"'} { + {one two three} + {one two three four} + {one two three five} + {one two three four five} + } + + 12 {SELECT a FROM ft WHERE a MATCH '"two three four"'} { + {two three four} + {one two three four} + {two three four five} + {one two three four five} + } + + 12 {SELECT a FROM ft WHERE a MATCH '"two three" five'} { + {two three five} {one two three five} + {two three four five} {one two three four five} + } + + 13 {SELECT a FROM ft WHERE ft MATCH '"song sahm" hah'} { + {two three five} {one two three five} + {two three four five} {one two three four five} + } + + 14 {SELECT a FROM ft WHERE b MATCH 'neung'} { + {one} {one two} + {one three} {one two three} + {one four} {one two four} + {one three four} {one two three four} + {one five} {one two five} + {one three five} {one two three five} + {one four five} {one two four five} + {one three four five} {one two three four five} + } + + 15 {SELECT a FROM ft WHERE b MATCH '"neung song sahm"'} { + {one two three} {one two three four} + {one two three five} {one two three four five} + } + + 16 {SELECT a FROM ft WHERE b MATCH 'hah "song sahm"'} { + {two three five} {one two three five} + {two three four five} {one two three four five} + } + + 17 {SELECT a FROM ft WHERE b MATCH 'song OR sahm'} { + {two} {one two} {three} + {one three} {two three} {one two three} + {two four} {one two four} {three four} + {one three four} {two three four} {one two three four} + {two five} {one two five} {three five} + {one three five} {two three five} {one two three five} + {two four five} {one two four five} {three four five} + {one three four five} {two three four five} {one two three four five} + } + + 18 {SELECT a FROM ft WHERE a MATCH 'three NOT two'} { + {three} {one three} {three four} + {one three four} {three five} {one three five} + {three four five} {one three four five} + } + + 19 {SELECT a FROM ft WHERE b MATCH 'sahm NOT song'} { + {three} {one three} {three four} + {one three four} {three five} {one three five} + {three four five} {one three four five} + } + + 20 {SELECT a FROM ft WHERE ft MATCH 'sahm NOT song'} { + {three} {one three} {three four} + {one three four} {three five} {one three five} + {three four five} {one three four five} + } + + 21 {SELECT a FROM ft WHERE b MATCH 'neung NEAR song NEAR sahm'} { + {one two three} {one two three four} + {one two three five} {one two three four five} + } + +} { + set result [normal_list $result] + do_select_test fts3_malloc-2.$tn $sql $result +} + +do_test fts3_malloc-3.0 { + execsql BEGIN + for {set ii 32} {$ii < 1024} {incr ii} { + set a [list] + set b [list] + if {$ii & 0x0001} {lappend a one ; lappend b neung } + if {$ii & 0x0002} {lappend a two ; lappend b song } + if {$ii & 0x0004} {lappend a three ; lappend b sahm } + if {$ii & 0x0008} {lappend a four ; lappend b see } + if {$ii & 0x0010} {lappend a five ; lappend b hah } + if {$ii & 0x0020} {lappend a six ; lappend b hok } + if {$ii & 0x0040} {lappend a seven ; lappend b jet } + if {$ii & 0x0080} {lappend a eight ; lappend b bairt } + if {$ii & 0x0100} {lappend a nine ; lappend b gow } + if {$ii & 0x0200} {lappend a ten ; lappend b sip } + execsql { INSERT INTO ft VALUES($a, $b) } + } + execsql COMMIT +} {} +foreach {tn sql result} { + 1 "SELECT count(*) FROM ft" {1023} + + 2 "SELECT a FROM ft WHERE a MATCH 'one two three four five six seven eight'" { + {one two three four five six seven eight} + {one two three four five six seven eight nine} + {one two three four five six seven eight ten} + {one two three four five six seven eight nine ten} + } + + 3 {SELECT count(*), sum(docid) FROM ft WHERE a MATCH 'o*'} { + 512 262144 + } + + 4 {SELECT count(*), sum(docid) FROM ft WHERE a MATCH '"two three four"'} { + 128 66368 + } +} { + set result [normal_list $result] + do_select_test fts3_malloc-3.$tn $sql $result +} + +do_test fts3_malloc-4.0 { + execsql { DELETE FROM ft WHERE docid>=32 } +} {} +foreach {tn sql} { + 1 "DELETE FROM ft WHERE ft MATCH 'one'" + 2 "DELETE FROM ft WHERE ft MATCH 'three'" + 3 "DELETE FROM ft WHERE ft MATCH 'five'" +} { + do_write_test fts3_malloc-4.1.$tn ft_content $sql +} +do_test fts3_malloc-4.2 { + execsql { SELECT a FROM ft } +} {two four {two four}} + +do_write_test fts3_malloc-5.1 ft_content { + INSERT INTO ft VALUES('short alongertoken reallyquitealotlongerimeanit andthistokenisjustsolongthatonemightbeforgivenforimaginingthatitwasmerelyacontrivedexampleandnotarealtoken', 'cynics!') +} +do_test fts3_malloc-5.2 { + execsql { CREATE VIRTUAL TABLE ft8 USING fts3(x, tokenize porter) } +} {} + +do_write_test fts3_malloc-5.3 ft_content { + INSERT INTO ft8 VALUES('short alongertoken reallyquitealotlongerimeanit andthistokenisjustsolongthatonemightbeforgivenforimaginingthatitwasmerelyacontrivedexampleandnotarealtoken') +} + + +finish_test diff --git a/test/fts3matchinfo.test b/test/fts3matchinfo.test new file mode 100644 index 0000000..af0b1cd --- /dev/null +++ b/test/fts3matchinfo.test @@ -0,0 +1,556 @@ +# 2010 November 02 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for the FTS3 module. The focus +# of this file is tables created with the "matchinfo=fts3" option. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is not defined, omit this file. +ifcapable !fts3 { finish_test ; return } + +set testprefix fts3matchinfo +set sqlite_fts3_enable_parentheses 0 + +proc mit {blob} { + set scan(littleEndian) i* + set scan(bigEndian) I* + binary scan $blob $scan($::tcl_platform(byteOrder)) r + return $r +} +db func mit mit + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t1 USING fts4(matchinfo=fts3); + SELECT name FROM sqlite_master WHERE type = 'table'; +} {t1 t1_content t1_segments t1_segdir t1_stat} + +do_execsql_test 1.1 { + INSERT INTO t1(content) VALUES('I wandered lonely as a cloud'); + INSERT INTO t1(content) VALUES('That floats on high o''er vales and hills,'); + INSERT INTO t1(content) VALUES('When all at once I saw a crowd,'); + INSERT INTO t1(content) VALUES('A host, of golden daffodils,'); + SELECT mit(matchinfo(t1)) FROM t1 WHERE t1 MATCH 'I'; +} {{1 1 1 2 2} {1 1 1 2 2}} + +# Now create an FTS4 table that does not specify matchinfo=fts3. +# +do_execsql_test 1.2 { + CREATE VIRTUAL TABLE t2 USING fts4; + INSERT INTO t2 SELECT * FROM t1; + SELECT mit(matchinfo(t2)) FROM t2 WHERE t2 MATCH 'I'; +} {{1 1 1 2 2} {1 1 1 2 2}} + +# Test some syntax-error handling. +# +do_catchsql_test 2.0 { + CREATE VIRTUAL TABLE x1 USING fts4(matchinfo=fs3); +} {1 {unrecognized matchinfo: fs3}} +do_catchsql_test 2.1 { + CREATE VIRTUAL TABLE x2 USING fts4(mtchinfo=fts3); +} {1 {unrecognized parameter: mtchinfo=fts3}} +do_catchsql_test 2.2 { + CREATE VIRTUAL TABLE x2 USING fts4(matchinfo=fts5); +} {1 {unrecognized matchinfo: fts5}} + +# Check that with fts3, the "=" character is permitted in column definitions. +# +do_execsql_test 3.1 { + CREATE VIRTUAL TABLE t3 USING fts3(mtchinfo=fts3); + INSERT INTO t3(mtchinfo) VALUES('Beside the lake, beneath the trees'); + SELECT mtchinfo FROM t3; +} {{Beside the lake, beneath the trees}} + +do_execsql_test 3.2 { + CREATE VIRTUAL TABLE xx USING FTS4; +} +do_execsql_test 3.3 { + SELECT * FROM xx WHERE xx MATCH 'abc'; +} +do_execsql_test 3.4 { + SELECT * FROM xx WHERE xx MATCH 'a b c'; +} + + +#-------------------------------------------------------------------------- +# Proc [do_matchinfo_test] is used to test the FTSX matchinfo() function. +# +# The first argument - $tn - is a test identifier. This may be either a +# full identifier (i.e. "fts3matchinfo-1.1") or, if global var $testprefix +# is set, just the numeric component (i.e. "1.1"). +# +# The second argument is the name of an FTSX table. The third is the +# full text of a WHERE/MATCH expression to query the table for +# (i.e. "t1 MATCH 'abc'"). The final argument - $results - should be a +# key-value list (serialized array) with matchinfo() format specifiers +# as keys, and the results of executing the statement: +# +# SELECT matchinfo($tbl, '$key') FROM $tbl WHERE $expr +# +# For example: +# +# CREATE VIRTUAL TABLE t1 USING fts4; +# INSERT INTO t1 VALUES('abc'); +# INSERT INTO t1 VALUES('def'); +# INSERT INTO t1 VALUES('abc abc'); +# +# do_matchinfo_test 1.1 t1 "t1 MATCH 'abc'" { +# n {3 3} +# p {1 1} +# c {1 1} +# x {{1 3 2} {2 3 2}} +# } +# +# If the $results list contains keys mapped to "-" instead of a matchinfo() +# result, then this command computes the expected results based on other +# mappings to test the matchinfo() function. For example, the command above +# could be changed to: +# +# do_matchinfo_test 1.1 t1 "t1 MATCH 'abc'" { +# n {3 3} p {1 1} c {1 1} x {{1 3 2} {2 3 2}} +# pcx - +# } +# +# And this command would compute the expected results for matchinfo(t1, 'pcx') +# based on the results of matchinfo(t1, 'p'), matchinfo(t1, 'c') and +# matchinfo(t1, 'x') in order to test 'pcx'. +# +proc do_matchinfo_test {tn tbl expr results} { + + foreach {fmt res} $results { + if {$res == "-"} continue + set resarray($fmt) $res + } + + set nRow 0 + foreach {fmt res} [array get resarray] { + if {[llength $res]>$nRow} { set nRow [llength $res] } + } + + # Construct expected results for any formats for which the caller + # supplied result is "-". + # + foreach {fmt res} $results { + if {$res == "-"} { + set res [list] + for {set iRow 0} {$iRow<$nRow} {incr iRow} { + set rowres [list] + foreach c [split $fmt ""] { + set rowres [concat $rowres [lindex $resarray($c) $iRow]] + } + lappend res $rowres + } + set resarray($fmt) $res + } + } + + # Test each matchinfo() request individually. + # + foreach {fmt res} [array get resarray] { + set sql "SELECT mit(matchinfo($tbl, '$fmt')) FROM $tbl WHERE $expr" + do_execsql_test $tn.$fmt $sql [normalize2 $res] + } + + # Test them all executed together (multiple invocations of matchinfo()). + # + set exprlist [list] + foreach {format res} [array get resarray] { + lappend exprlist "mit(matchinfo($tbl, '$format'))" + } + set allres [list] + for {set iRow 0} {$iRow<$nRow} {incr iRow} { + foreach {format res} [array get resarray] { + lappend allres [lindex $res $iRow] + } + } + set sql "SELECT [join $exprlist ,] FROM $tbl WHERE $expr" + do_execsql_test $tn.multi $sql [normalize2 $allres] +} +proc normalize2 {list_of_lists} { + set res [list] + foreach elem $list_of_lists { + lappend res [list {*}$elem] + } + return $res +} + + +do_execsql_test 4.1.0 { + CREATE VIRTUAL TABLE t4 USING fts4(x, y); + INSERT INTO t4 VALUES('a b c d e', 'f g h i j'); + INSERT INTO t4 VALUES('f g h i j', 'a b c d e'); +} + +do_matchinfo_test 4.1.1 t4 {t4 MATCH 'a b c'} { + p {3 3} + c {2 2} + x { + {1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1} + {0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1} + } + n {2 2} + l {{5 5} {5 5}} + a {{5 5} {5 5}} + + s {{3 0} {0 3}} + + xxxxxxxxxxxxxxxxxx - pcx - xpc - ccc - pppxpcpcx - laxnpc - + xpxsscplax - +} + +do_matchinfo_test 4.1.2 t4 {t4 MATCH '"g h i"'} { + p {1 1} + c {2 2} + x { + {0 1 1 1 1 1} + {1 1 1 0 1 1} + } + n {2 2} + l {{5 5} {5 5}} + a {{5 5} {5 5}} + + s {{0 1} {1 0}} + + xxxxxxxxxxxxxxxxxx - pcx - xpc - ccc - pppxpcpcx - laxnpc - + sxsxs - +} + +do_matchinfo_test 4.1.3 t4 {t4 MATCH 'a b'} { s {{2 0} {0 2}} } +do_matchinfo_test 4.1.4 t4 {t4 MATCH '"a b" c'} { s {{2 0} {0 2}} } +do_matchinfo_test 4.1.5 t4 {t4 MATCH 'a "b c"'} { s {{2 0} {0 2}} } +do_matchinfo_test 4.1.6 t4 {t4 MATCH 'd d'} { s {{1 0} {0 1}} } +do_matchinfo_test 4.1.7 t4 {t4 MATCH 'f OR abcd'} { + x { + {0 1 1 1 1 1 0 0 0 0 0 0} + {1 1 1 0 1 1 0 0 0 0 0 0} + } +} +do_matchinfo_test 4.1.8 t4 {t4 MATCH 'f -abcd'} { + x { + {0 1 1 1 1 1} + {1 1 1 0 1 1} + } +} + +do_execsql_test 4.2.0 { + CREATE VIRTUAL TABLE t5 USING fts4; + INSERT INTO t5 VALUES('a a a a a'); + INSERT INTO t5 VALUES('a b a b a'); + INSERT INTO t5 VALUES('c b c b c'); + INSERT INTO t5 VALUES('x x x x x'); +} +do_matchinfo_test 4.2.1 t5 {t5 MATCH 'a a'} { + x {{5 8 2 5 8 2} {3 8 2 3 8 2}} + s {2 1} +} +do_matchinfo_test 4.2.2 t5 {t5 MATCH 'a b'} { s {2} } +do_matchinfo_test 4.2.3 t5 {t5 MATCH 'a b a'} { s {3} } +do_matchinfo_test 4.2.4 t5 {t5 MATCH 'a a a'} { s {3 1} } +do_matchinfo_test 4.2.5 t5 {t5 MATCH '"a b" "a b"'} { s {2} } +do_matchinfo_test 4.2.6 t5 {t5 MATCH 'a OR b'} { s {1 2 1} } + +do_execsql_test 4.3.0 "INSERT INTO t5 VALUES('x y [string repeat {b } 50000]')"; + +# It used to be that the second 'a' token would be deferred. That doesn't +# work any longer. +if 0 { + do_matchinfo_test 4.3.1 t5 {t5 MATCH 'a a'} { + x {{5 8 2 5 5 5} {3 8 2 3 5 5}} + s {2 1} + } +} + +do_matchinfo_test 4.3.2 t5 {t5 MATCH 'a b'} { s {2} } +do_matchinfo_test 4.3.3 t5 {t5 MATCH 'a b a'} { s {3} } +do_matchinfo_test 4.3.4 t5 {t5 MATCH 'a a a'} { s {3 1} } +do_matchinfo_test 4.3.5 t5 {t5 MATCH '"a b" "a b"'} { s {2} } +do_matchinfo_test 4.3.6 t5 {t5 MATCH 'a OR b'} { s {1 2 1 1} } + +do_execsql_test 4.4.0.1 { INSERT INTO t5(t5) VALUES('optimize') } + +ifcapable fts4_deferred { + sqlite3_db_config db DEFENSIVE 0 + do_execsql_test 4.4.0.2 { + UPDATE t5_segments + SET block = zeroblob(length(block)) + WHERE length(block)>10000; + } +} + +do_matchinfo_test 4.4.2 t5 {t5 MATCH 'a b'} { s {2} } +do_matchinfo_test 4.4.1 t5 {t5 MATCH 'a a'} { s {2 1} } +do_matchinfo_test 4.4.2 t5 {t5 MATCH 'a b'} { s {2} } +do_matchinfo_test 4.4.3 t5 {t5 MATCH 'a b a'} { s {3} } +do_matchinfo_test 4.4.4 t5 {t5 MATCH 'a a a'} { s {3 1} } +do_matchinfo_test 4.4.5 t5 {t5 MATCH '"a b" "a b"'} { s {2} } + +do_execsql_test 4.5.0 { + CREATE VIRTUAL TABLE t6 USING fts4(a, b, c); + INSERT INTO t6 VALUES('a', 'b', 'c'); +} +do_matchinfo_test 4.5.1 t6 {t6 MATCH 'a b c'} { s {{1 1 1}} } + + +#------------------------------------------------------------------------- +# Check the following restrictions: +# +# + Matchinfo flags 'a', 'l' and 'n' can only be used with fts4, not fts3. +# + Matchinfo flag 'l' cannot be used with matchinfo=fts3. +# +do_execsql_test 5.1 { + CREATE VIRTUAL TABLE t7 USING fts3(a, b); + INSERT INTO t7 VALUES('u v w', 'x y z'); + + CREATE VIRTUAL TABLE t8 USING fts4(a, b, matchinfo=fts3); + INSERT INTO t8 VALUES('u v w', 'x y z'); +} + +do_catchsql_test 5.2.1 { + SELECT matchinfo(t7, 'a') FROM t7 WHERE t7 MATCH 'x y' +} {1 {unrecognized matchinfo request: a}} +do_catchsql_test 5.2.2 { + SELECT matchinfo(t7, 'l') FROM t7 WHERE t7 MATCH 'x y' +} {1 {unrecognized matchinfo request: l}} +do_catchsql_test 5.2.3 { + SELECT matchinfo(t7, 'n') FROM t7 WHERE t7 MATCH 'x y' +} {1 {unrecognized matchinfo request: n}} + +do_catchsql_test 5.3.1 { + SELECT matchinfo(t8, 'l') FROM t8 WHERE t8 MATCH 'x y' +} {1 {unrecognized matchinfo request: l}} + +#------------------------------------------------------------------------- +# Test that the offsets() function handles corruption in the %_content +# table correctly. +# +do_execsql_test 6.1 { + CREATE VIRTUAL TABLE t9 USING fts4; + INSERT INTO t9 VALUES( + 'this record is used to try to dectect corruption' + ); + SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to'; +} {{0 0 20 2 0 0 27 2}} + +sqlite3_db_config db DEFENSIVE 0 +do_catchsql_test 6.2 { + UPDATE t9_content SET c0content = 'this record is used to'; + SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to'; +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +# Test the outcome of matchinfo() when used within a query that does not +# use the full-text index (i.e. lookup by rowid or full-table scan). +# +do_execsql_test 7.1 { + CREATE VIRTUAL TABLE t10 USING fts4; + INSERT INTO t10 VALUES('first record'); + INSERT INTO t10 VALUES('second record'); +} +do_execsql_test 7.2 { + SELECT typeof(matchinfo(t10)), length(matchinfo(t10)) FROM t10; +} {blob 0 blob 0} +do_execsql_test 7.3 { + SELECT typeof(matchinfo(t10)), length(matchinfo(t10)) FROM t10 WHERE docid=1; +} {blob 0} +do_execsql_test 7.4 { + SELECT typeof(matchinfo(t10)), length(matchinfo(t10)) + FROM t10 WHERE t10 MATCH 'record' +} {blob 20 blob 20} + +#------------------------------------------------------------------------- +# Test a special case - matchinfo('nxa') with many zero length documents. +# Special because "x" internally uses a statement used by both "n" and "a". +# This was causing a problem at one point in the obscure case where the +# total number of bytes of data stored in an fts3 table was greater than +# the number of rows. i.e. when the following query returns true: +# +# SELECT sum(length(content)) < count(*) FROM fts4table; +# +do_execsql_test 8.1 { + CREATE VIRTUAL TABLE t11 USING fts4; + INSERT INTO t11(t11) VALUES('nodesize=24'); + INSERT INTO t11 VALUES('quitealongstringoftext'); + INSERT INTO t11 VALUES('anotherquitealongstringoftext'); + INSERT INTO t11 VALUES('athirdlongstringoftext'); + INSERT INTO t11 VALUES('andonemoreforgoodluck'); +} +do_test 8.2 { + for {set i 0} {$i < 200} {incr i} { + execsql { INSERT INTO t11 VALUES('') } + } + execsql { INSERT INTO t11(t11) VALUES('optimize') } +} {} +do_execsql_test 8.3 { + SELECT mit(matchinfo(t11, 'nxa')) FROM t11 WHERE t11 MATCH 'a*' +} {{204 1 3 3 0} {204 1 3 3 0} {204 1 3 3 0}} + +# Corruption related tests. +sqlite3_db_config db DEFENSIVE 0 +do_execsql_test 8.4.1.1 { UPDATE t11_stat SET value = X'0000'; } +do_catchsql_test 8.5.1.2 { + SELECT mit(matchinfo(t11, 'nxa')) FROM t11 WHERE t11 MATCH 'a*' +} {1 {database disk image is malformed}} + +do_execsql_test 8.4.2.1 { UPDATE t11_stat SET value = X'00'; } +do_catchsql_test 8.5.2.2 { + SELECT mit(matchinfo(t11, 'nxa')) FROM t11 WHERE t11 MATCH 'a*' +} {1 {database disk image is malformed}} + +do_execsql_test 8.4.3.1 { UPDATE t11_stat SET value = NULL; } +do_catchsql_test 8.5.3.2 { + SELECT mit(matchinfo(t11, 'nxa')) FROM t11 WHERE t11 MATCH 'a*' +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +do_execsql_test 8.1 { + CREATE VIRTUAL TABLE t12 USING fts4; + INSERT INTO t12 VALUES('a b c d'); + SELECT mit(matchinfo(t12, 'x')) FROM t12 WHERE t12 MATCH 'a NEAR/1 d OR a'; +} {{0 0 0 0 0 0 1 1 1}} +do_execsql_test 8.2 { + INSERT INTO t12 VALUES('a d c d'); + SELECT mit(matchinfo(t12, 'x')) FROM t12 WHERE t12 MATCH 'a NEAR/1 d OR a'; +} { + {0 1 1 0 1 1 1 2 2} {1 1 1 1 1 1 1 2 2} +} +do_execsql_test 8.3 { + INSERT INTO t12 VALUES('a d d a'); + SELECT mit(matchinfo(t12, 'x')) FROM t12 WHERE t12 MATCH 'a NEAR/1 d OR a'; +} { + {0 3 2 0 3 2 1 4 3} {1 3 2 1 3 2 1 4 3} {2 3 2 2 3 2 2 4 3} +} + +do_execsql_test 9.1 { + CREATE VIRTUAL TABLE ft2 USING fts4; + INSERT INTO ft2 VALUES('a b c d e'); + INSERT INTO ft2 VALUES('f a b c d'); + SELECT snippet(ft2, '[', ']', '', -1, 1) FROM ft2 WHERE ft2 MATCH 'c'; +} {{[c]} {[c]}} + +#--------------------------------------------------------------------------- +# Test for a memory leak +# +do_execsql_test 10.1 { + DROP TABLE t10; + CREATE VIRTUAL TABLE t10 USING fts4(idx, value); + INSERT INTO t10 values (1, 'one'),(2, 'two'),(3, 'three'); + SELECT docId, t10.* + FROM t10 + JOIN (SELECT 1 AS idx UNION SELECT 2 UNION SELECT 3) AS x + WHERE t10 MATCH x.idx + AND matchinfo(t10) not null + GROUP BY docId + ORDER BY 1; +} {1 1 one 2 2 two 3 3 three} + +#--------------------------------------------------------------------------- +# Test the 'y' matchinfo flag +# +set sqlite_fts3_enable_parentheses 1 +reset_db +do_execsql_test 11.0 { + CREATE VIRTUAL TABLE tt USING fts3(x, y); + INSERT INTO tt VALUES('c d a c d d', 'e a g b d a'); -- 1 + INSERT INTO tt VALUES('c c g a e b', 'c g d g e c'); -- 2 + INSERT INTO tt VALUES('b e f d e g', 'b a c b c g'); -- 3 + INSERT INTO tt VALUES('a c f f g d', 'd b f d e g'); -- 4 + INSERT INTO tt VALUES('g a c f c f', 'd g g b c c'); -- 5 + INSERT INTO tt VALUES('g a c e b b', 'd b f b g g'); -- 6 + INSERT INTO tt VALUES('f d a a f c', 'e e a d c f'); -- 7 + INSERT INTO tt VALUES('a c b b g f', 'a b a e d f'); -- 8 + INSERT INTO tt VALUES('b a f e c c', 'f d b b a b'); -- 9 + INSERT INTO tt VALUES('f d c e a c', 'f a f a a f'); -- 10 +} + +db func mit mit +foreach {tn expr res} { + 1 "a" { + 1 {1 2} 2 {1 0} 3 {0 1} 4 {1 0} 5 {1 0} + 6 {1 0} 7 {2 1} 8 {1 2} 9 {1 1} 10 {1 3} + } + + 2 "b" { + 1 {0 1} 2 {1 0} 3 {1 2} 4 {0 1} 5 {0 1} + 6 {2 2} 8 {2 1} 9 {1 3} + } + + 3 "y:a" { + 1 {0 2} 3 {0 1} + 7 {0 1} 8 {0 2} 9 {0 1} 10 {0 3} + } + + 4 "x:a" { + 1 {1 0} 2 {1 0} 4 {1 0} 5 {1 0} + 6 {1 0} 7 {2 0} 8 {1 0} 9 {1 0} 10 {1 0} + } + + 5 "a OR b" { + 1 {1 2 0 1} 2 {1 0 1 0} 3 {0 1 1 2} 4 {1 0 0 1} 5 {1 0 0 1} + 6 {1 0 2 2} 7 {2 1 0 0} 8 {1 2 2 1} 9 {1 1 1 3} 10 {1 3 0 0} + } + + 6 "a AND b" { + 1 {1 2 0 1} 2 {1 0 1 0} 3 {0 1 1 2} 4 {1 0 0 1} 5 {1 0 0 1} + 6 {1 0 2 2} 8 {1 2 2 1} 9 {1 1 1 3} + } + + 7 "a OR (a AND b)" { + 1 {1 2 1 2 0 1} 2 {1 0 1 0 1 0} 3 {0 1 0 1 1 2} 4 {1 0 1 0 0 1} + 5 {1 0 1 0 0 1} 6 {1 0 1 0 2 2} 7 {2 1 0 0 0 0} 8 {1 2 1 2 2 1} + 9 {1 1 1 1 1 3} 10 {1 3 0 0 0 0} + } + +} { + do_execsql_test 11.1.$tn.1 { + SELECT rowid, mit(matchinfo(tt, 'y')) FROM tt WHERE tt MATCH $expr + } $res + + set r2 [list] + foreach {rowid L} $res { + lappend r2 $rowid + set M [list] + foreach {a b} $L { + lappend M [expr ($a ? 1 : 0) + ($b ? 2 : 0)] + } + lappend r2 $M + } + + do_execsql_test 11.1.$tn.2 { + SELECT rowid, mit(matchinfo(tt, 'b')) FROM tt WHERE tt MATCH $expr + } $r2 + + do_execsql_test 11.1.$tn.2 { + SELECT rowid, mit(matchinfo(tt, 'b')) FROM tt WHERE tt MATCH $expr + } $r2 +} +set sqlite_fts3_enable_parentheses 0 + +#--------------------------------------------------------------------------- +# Test the 'b' matchinfo flag +# +set sqlite_fts3_enable_parentheses 1 +reset_db +db func mit mit + +do_test 12.0 { + set cols [list] + for {set i 0} {$i < 50} {incr i} { lappend cols "c$i" } + execsql "CREATE VIRTUAL TABLE tt USING fts3([join $cols ,])" +} {} + +do_execsql_test 12.1 { + INSERT INTO tt (rowid, c4, c45) VALUES(1, 'abc', 'abc'); + SELECT mit(matchinfo(tt, 'b')) FROM tt WHERE tt MATCH 'abc'; +} [list [list [expr 1<<4] [expr 1<<(45-32)]]] + +set sqlite_fts3_enable_parentheses 0 +finish_test diff --git a/test/fts3matchinfo2.test b/test/fts3matchinfo2.test new file mode 100644 index 0000000..670e107 --- /dev/null +++ b/test/fts3matchinfo2.test @@ -0,0 +1,35 @@ +# 2020-05-14 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for the FTS3 module. The focus +# of this file is tables created with the "matchinfo=fts3" option. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is not defined, omit this file. +ifcapable !fts3 { finish_test ; return } + +set sqlite_fts3_enable_parentheses 1 + +# Crash case found by cyg0810 at gmail.com 2020-05-14. Reported to +# chromium (which is not vulnerable) who kindly referred it to us. +# +do_execsql_test 1.0 { + CREATE TABLE t_content(col0 INTEGER); + CREATE VIRTUAL TABLE t0 USING fts3(col0 INTEGER PRIMARY KEY,col1 VARCHAR(8),col2 BINARY,col3 BINARY); + INSERT INTO t0 VALUES (1, '1234','aaaa','bbbb'); + SELECT hex(matchinfo(t0,'yxy')) FROM t0 WHERE t0 MATCH x'2b0a312b0a312a312a2a0b5d0a0b0b0a312a0a0b0b0a312a0b310a392a0b0a27312a2a0b5d0a312a0b310a31315d0b310a312a316d2a0b313b15bceaa50a312a0b0a27312a2a0b5d0a312a0b310a312b0b2a310a312a0b2a0b2a0b2e5d0a0bff313336e34a2a312a0b0a3c310b0a0b4b4b0b4b2a4bec40322b2a0b310a0a312a0a0a0a0a0a0a0a0a0b310a312a2a2a0b5d0a0b0b0a312a0b310a312a0b0a4e4541530b310a5df5ced70a0a0a0a0a4f520a0a0a0a0a0a0a312a0b0a4e4541520b310a5d616161610a0a0a0a4f520a0a0a0a0a0a312b0a312a312a0a0a0a0a0a0a004a0b0a310b220a0b0a310a4a22310a0b0a7e6fe0e0e030e0e0e0e0e01176e02000e0e0e0e0e01131320226310a0b0a310a4a22310a0b0a310a766f8b8b4ee0e0300ae0090909090909090909090909090909090909090909090909090909090909090947aaaa540b09090909090909090909090909090909090909090909090909090909090909fae0e0f2f22164e0e0f273e07fefefef7d6dfafafafa6d6d6d6d'; +} {/000000.*0000000/} + + +set sqlite_fts3_enable_parentheses 0 +finish_test diff --git a/test/fts3misc.test b/test/fts3misc.test new file mode 100644 index 0000000..a1bec42 --- /dev/null +++ b/test/fts3misc.test @@ -0,0 +1,326 @@ +# 2017 March 22 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS3 module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts3misc + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +#------------------------------------------------------------------------- +# A self-join. +# +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t1 USING fts3(a, b); + INSERT INTO t1 VALUES('one', 'i'); + INSERT INTO t1 VALUES('one', 'ii'); + INSERT INTO t1 VALUES('two', 'i'); + INSERT INTO t1 VALUES('two', 'ii'); +} + +do_execsql_test 1.1 { + SELECT a.a, b.b FROM t1 a, t1 b WHERE a.t1 MATCH 'two' AND b.t1 MATCH 'i' +} {two i two i two i two i} + +#------------------------------------------------------------------------- +# FTS tables with 128 or more columns. +# +proc v1 {v} { + set vector [list a b c d e f g h] + set res [list] + for {set i 0} {$i<8} {incr i} { + if {$v & (1 << $i)} { lappend res [lindex $vector $i] } + } + set res +} +proc v2 {v} { + set vector [list d e f g h i j k] + set res [list] + for {set i 0} {$i<8} {incr i} { + if {$v & (1 << $i)} { lappend res [lindex $vector $i] } + } + set res +} +db func v1 v1 +db func v2 v2 + +do_test 2.0 { + set cols [list] + for {set i 0} {$i<200} {incr i} { + lappend cols "c$i" + } + execsql "CREATE VIRTUAL TABLE t2 USING fts3([join $cols ,])" + execsql { + WITH data(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM data WHERE i<200 + ) + INSERT INTO t2(c198, c199) SELECT v1(i), v2(i) FROM data; + } +} {} +do_execsql_test 2.1 { + SELECT rowid FROM t2 WHERE t2 MATCH '"a b c"' +} { + 7 15 23 31 39 47 55 63 71 79 87 95 103 111 + 119 127 135 143 151 159 167 175 183 191 199 +} +do_execsql_test 2.2 { + SELECT rowid FROM t2 WHERE t2 MATCH '"g h i"' +} { + 56 57 58 59 60 61 62 63 120 121 122 123 124 + 125 126 127 184 185 186 187 188 189 190 191 +} +do_execsql_test 2.3 { + SELECT rowid FROM t2 WHERE t2 MATCH '"i h"' +} { +} +do_execsql_test 2.4 { + SELECT rowid FROM t2 WHERE t2 MATCH '"f e"' +} { +} +do_execsql_test 2.5 { + SELECT rowid FROM t2 WHERE t2 MATCH '"e f"' +} { + 6 7 14 15 22 23 30 31 38 39 46 47 48 49 50 51 52 53 54 55 56 + 57 58 59 60 61 62 63 70 71 78 79 86 87 94 95 102 103 110 + 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 + 134 135 142 143 150 151 158 159 166 167 174 175 176 177 178 179 180 + 181 182 183 184 185 186 187 188 189 190 191 198 199 +} + +#------------------------------------------------------------------------- +# Range constraints on the docid using non-integer values. +# +do_execsql_test 2.6 { + SELECT rowid FROM t2 WHERE t2 MATCH 'e' AND rowid BETWEEN NULL AND 45; +} {} +do_execsql_test 2.7 { + SELECT rowid FROM t2 WHERE t2 MATCH 'e' AND rowid BETWEEN 11.5 AND 48.2; +} { + 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 + 29 30 31 34 35 38 39 42 43 46 47 48 +} +do_execsql_test 2.8 { + SELECT rowid FROM t2 WHERE t2 MATCH 'e' AND rowid BETWEEN '11.5' AND '48.2'; +} { + 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 + 29 30 31 34 35 38 39 42 43 46 47 48 +} + +#------------------------------------------------------------------------- +# Phrase query tests. +# +do_execsql_test 3.1.1 { + CREATE VIRTUAL TABLE t3 USING fts3; + INSERT INTO t3 VALUES('a b c'); + INSERT INTO t3 VALUES('d e f'); + INSERT INTO t3 VALUES('a b d'); + INSERT INTO t3 VALUES('1 2 3 4 5 6 7 8 9 10 11'); +} +do_execsql_test 3.1.2 { + SELECT * FROM t3 WHERE t3 MATCH '"a b x y"' ORDER BY docid DESC +} +do_execsql_test 3.1.3 { + SELECT * FROM t3 WHERE t3 MATCH '"a b c" OR "a b x y"' ORDER BY docid DESC +} {{a b c}} +do_execsql_test 3.1.4 { + SELECT * FROM t3 WHERE t3 MATCH '"a* b* x* a*"' +} +do_execsql_test 3.1.5 { + SELECT rowid FROM t3 WHERE t3 MATCH '"2 3 4 5 6 7 8 9"' +} {4} + +#------------------------------------------------------------------------- +# +reset_db +ifcapable fts4_deferred { + do_execsql_test 4.0 { + PRAGMA page_size = 512; + CREATE VIRTUAL TABLE t4 USING fts4; + WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<8000 ) + INSERT INTO t4 SELECT 'a b c a b c a b c' FROM s; + } + do_execsql_test 4.1 { + SELECT count(*) FROM t4 WHERE t4 MATCH '"a b c" OR "c a b"' + } {8000} + do_execsql_test 4.2 { + SELECT quote(value) from t4_stat where id=0 + } {X'C03EC0B204C0A608'} + sqlite3_db_config db DEFENSIVE 0 + do_execsql_test 4.3 { + UPDATE t4_stat SET value = X'C03EC0B204C0A60800' WHERE id=0; + } + do_catchsql_test 4.4 { + SELECT count(*) FROM t4 WHERE t4 MATCH '"a b c" OR "c a b"' + } {1 {database disk image is malformed}} + do_execsql_test 4.5 { + UPDATE t4_stat SET value = X'00C03EC0B204C0A608' WHERE id=0; + } + do_catchsql_test 4.6 { + SELECT count(*) FROM t4 WHERE t4 MATCH '"a b c" OR "c a b"' + } {1 {database disk image is malformed}} +} + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 5.0 { + CREATE VIRTUAL TABLE t5 USING fts4; + INSERT INTO t5 VALUES('a x x x x b x x x x c'); + INSERT INTO t5 VALUES('a x x x x b x x x x c'); + INSERT INTO t5 VALUES('a x x x x b x x x x c'); +} +do_execsql_test 5.1 { + SELECT rowid FROM t5 WHERE t5 MATCH 'a NEAR/4 b NEAR/4 c' +} {1 2 3} +do_execsql_test 5.2 { + SELECT rowid FROM t5 WHERE t5 MATCH 'a NEAR/3 b NEAR/4 c' +} {} +do_execsql_test 5.3 { + SELECT rowid FROM t5 WHERE t5 MATCH 'a NEAR/4 b NEAR/3 c' +} {} +do_execsql_test 5.4 { + SELECT rowid FROM t5 WHERE t5 MATCH 'y NEAR/4 b NEAR/4 c' +} {} +do_execsql_test 5.5 { + SELECT rowid FROM t5 WHERE t5 MATCH 'x OR a NEAR/3 b NEAR/3 c' +} {1 2 3} +do_execsql_test 5.5 { + SELECT rowid FROM t5 WHERE t5 MATCH 'x OR y NEAR/3 b NEAR/3 c' +} {1 2 3} + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 6.0 { + CREATE VIRTUAL TABLE t6 USING fts4; + + BEGIN; + WITH s(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<50000) + INSERT INTO t6 SELECT 'x x x x x x x x x x x' FROM s; + + INSERT INTO t6 VALUES('x x x x x x x x x x x A'); + INSERT INTO t6 VALUES('x x x x x x x x x x x B'); + INSERT INTO t6 VALUES('x x x x x x x x x x x A'); + INSERT INTO t6 VALUES('x x x x x x x x x x x B'); + + WITH s(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<50000) + INSERT INTO t6 SELECT 'x x x x x x x x x x x' FROM s; + COMMIT; +} +do_execsql_test 6.1 { + SELECT rowid FROM t6 WHERE t6 MATCH 'b OR "x a"' +} {50001 50002 50003 50004} + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 7.0 { + CREATE VIRTUAL TABLE vt0 USING fts3(c0); + INSERT INTO vt0 VALUES (x'00'); +} +do_execsql_test 7.1 { + INSERT INTO vt0(vt0) VALUES('integrity-check'); +} + +#------------------------------------------------------------------------- +# Ticket [8a6fa2bb]. +# +reset_db +do_execsql_test 7.0.1 { + CREATE VIRTUAL TABLE vt0 USING fts4(c0, order=DESC); + INSERT INTO vt0(c0) VALUES (0), (0); +} +do_execsql_test 7.0.2 { + INSERT INTO vt0(vt0) VALUES('integrity-check'); +} +reset_db +do_execsql_test 7.1.1 { + CREATE VIRTUAL TABLE vt0 USING fts4(c0, order=ASC); + INSERT INTO vt0(c0) VALUES (0), (0); +} +do_execsql_test 7.1.2 { + INSERT INTO vt0(vt0) VALUES('integrity-check'); +} +do_execsql_test 7.2.1 { + CREATE VIRTUAL TABLE ft USING fts4(c0, c1, order=DESC, prefix=1); + INSERT INTO ft VALUES('a b c d', 'hello world'); + INSERT INTO ft VALUES('negative', 'positive'); + INSERT INTO ft VALUES('hello world', 'a b c d'); +} +do_execsql_test 7.2.2 { + INSERT INTO vt0(vt0) VALUES('integrity-check'); +} + +#------------------------------------------------------------------------- +# Ticket [745f1abc]. +# +reset_db +do_execsql_test 8.1 { + CREATE VIRTUAL TABLE vt0 USING fts4(c0, prefix=1); +} +do_execsql_test 8.2 { + BEGIN; + INSERT INTO vt0 VALUES (0); + INSERT INTO vt0(vt0) VALUES('optimize'); + COMMIT; +} +do_execsql_test 8.3 { + INSERT INTO vt0(vt0) VALUES('integrity-check'); +} + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 9.0 { + CREATE VIRTUAL TABLE t1 using fts4(mailcontent); + insert into t1(rowid, mailcontent) values + (-4764623217061966105, 'we are going to upgrade'), + (8324454597464624651, 'we are going to upgrade'); +} + +do_execsql_test 9.1 { + INSERT INTO t1(t1) VALUES('integrity-check'); +} + +do_execsql_test 9.2 { + SELECT rowid FROM t1 WHERE t1 MATCH 'upgrade'; +} { + -4764623217061966105 8324454597464624651 +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 10.0 { + CREATE VIRTUAL TABLE f USING fts3(a,b); + CREATE TABLE 'f_stat'(id INTEGER PRIMARY KEY, value BLOB); + INSERT INTO f_stat VALUES (1,x'3b3b3b3b3b3b3b28ffffffffffffffffff1807f9073481f1d43bc93b3b3b3b3b3b3b3b3b3b18073b3b3b3b3b3b3b9b003b'); +} {} + +do_catchsql_test 10.1 { + INSERT INTO f(f) VALUES ('merge=69,59'); +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +do_execsql_test 11.0 { + CREATE VIRTUAL TABLE xyz USING fts3(); +} +do_execsql_test 11.1 { + SELECT * FROM xyz WHERE xyz MATCH 'a NEAR/4294836224 a'; +} + +finish_test diff --git a/test/fts3near.test b/test/fts3near.test new file mode 100644 index 0000000..2d9981e --- /dev/null +++ b/test/fts3near.test @@ -0,0 +1,597 @@ + +# 2007 October 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# +# $Id: fts3near.test,v 1.3 2009/01/02 17:33:46 danielk1977 Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +db eval { + CREATE VIRTUAL TABLE t1 USING fts3(content); + INSERT INTO t1(content) VALUES('one three four five'); + INSERT INTO t1(content) VALUES('two three four five'); + INSERT INTO t1(content) VALUES('one two three four five'); +} + +do_test fts3near-1.1 { + execsql {SELECT docid FROM t1 WHERE content MATCH 'one NEAR/0 three'} +} {1} +do_test fts3near-1.2 { + execsql {SELECT docid FROM t1 WHERE content MATCH 'one NEAR/1 two'} +} {3} +do_test fts3near-1.3 { + execsql {SELECT docid FROM t1 WHERE content MATCH 'one NEAR/1 three'} +} {1 3} +do_test fts3near-1.4 { + execsql {SELECT docid FROM t1 WHERE content MATCH 'three NEAR/1 one'} +} {1 3} +do_test fts3near-1.5 { + execsql {SELECT docid FROM t1 WHERE content MATCH '"one two" NEAR/1 five'} +} {} +do_test fts3near-1.6 { + execsql {SELECT docid FROM t1 WHERE content MATCH '"one two" NEAR/2 five'} +} {3} +do_test fts3near-1.7 { + execsql {SELECT docid FROM t1 WHERE content MATCH 'one NEAR four'} +} {1 3} +do_test fts3near-1.8 { + execsql {SELECT docid FROM t1 WHERE content MATCH 'four NEAR three'} +} {1 2 3} +do_test fts3near-1.9 { + execsql {SELECT docid FROM t1 WHERE content MATCH '"four five" NEAR/0 three'} +} {1 2 3} +do_test fts3near-1.10 { + execsql {SELECT docid FROM t1 WHERE content MATCH '"four five" NEAR/2 one'} +} {1 3} +do_test fts3near-1.11 { + execsql {SELECT docid FROM t1 WHERE content MATCH '"four five" NEAR/1 one'} +} {1} +do_test fts3near-1.12 { + execsql {SELECT docid FROM t1 WHERE content MATCH 'five NEAR/1 "two three"'} +} {2 3} +do_test fts3near-1.13 { + execsql {SELECT docid FROM t1 WHERE content MATCH 'one NEAR five'} +} {1 3} + +do_test fts3near-1.14 { + execsql {SELECT docid FROM t1 WHERE content MATCH 'four NEAR four'} +} {} +do_test fts3near-1.15 { + execsql {SELECT docid FROM t1 WHERE content MATCH 'one NEAR two NEAR one'} +} {3} + +do_test fts3near-1.16 { + execsql { + SELECT docid FROM t1 WHERE content MATCH '"one three" NEAR/0 "four five"' + } +} {1} +do_test fts3near-1.17 { + execsql { + SELECT docid FROM t1 WHERE content MATCH '"four five" NEAR/0 "one three"' + } +} {1} + + +# Output format of the offsets() function: +# +# +# +db eval { + INSERT INTO t1(content) VALUES('A X B C D A B'); +} +do_test fts3near-2.1 { + execsql { + SELECT offsets(t1) FROM t1 WHERE content MATCH 'A NEAR/0 B' + } +} {{0 0 10 1 0 1 12 1}} +do_test fts3near-2.2 { + execsql { + SELECT offsets(t1) FROM t1 WHERE content MATCH 'B NEAR/0 A' + } +} {{0 1 10 1 0 0 12 1}} +do_test fts3near-2.3 { + execsql { + SELECT offsets(t1) FROM t1 WHERE content MATCH '"C D" NEAR/0 A' + } +} {{0 0 6 1 0 1 8 1 0 2 10 1}} +do_test fts3near-2.4 { + execsql { + SELECT offsets(t1) FROM t1 WHERE content MATCH 'A NEAR/0 "C D"' + } +} {{0 1 6 1 0 2 8 1 0 0 10 1}} +do_test fts3near-2.5 { + execsql { + SELECT offsets(t1) FROM t1 WHERE content MATCH 'A NEAR A' + } +} {{0 0 0 1 0 1 0 1 0 0 10 1 0 1 10 1}} +do_test fts3near-2.6 { + execsql { + INSERT INTO t1 VALUES('A A A'); + SELECT offsets(t1) FROM t1 WHERE content MATCH 'A NEAR/2 A'; + } +} [list [list 0 0 0 1 0 1 0 1 0 0 2 1 0 1 2 1 0 0 4 1 0 1 4 1]] +do_test fts3near-2.7 { + execsql { + DELETE FROM t1; + INSERT INTO t1 VALUES('A A A A'); + SELECT offsets(t1) FROM t1 WHERE content MATCH 'A NEAR A NEAR A'; + } +} [list [list \ + 0 0 0 1 0 1 0 1 0 2 0 1 0 0 2 1 \ + 0 1 2 1 0 2 2 1 0 0 4 1 0 1 4 1 \ + 0 2 4 1 0 0 6 1 0 1 6 1 0 2 6 1 \ +]] + +db eval { + DELETE FROM t1; + INSERT INTO t1(content) VALUES( + 'one two three two four six three six nine four eight twelve' + ); +} + +do_test fts3near-3.1 { + execsql {SELECT offsets(t1) FROM t1 WHERE content MATCH 'three NEAR/1 one'} +} {{0 1 0 3 0 0 8 5}} +do_test fts3near-3.2 { + execsql {SELECT offsets(t1) FROM t1 WHERE content MATCH 'one NEAR/1 three'} +} {{0 0 0 3 0 1 8 5}} +do_test fts3near-3.3 { + execsql {SELECT offsets(t1) FROM t1 WHERE content MATCH 'three NEAR/1 two'} +} {{0 1 4 3 0 0 8 5 0 1 14 3}} +do_test fts3near-3.4 { + execsql {SELECT offsets(t1) FROM t1 WHERE content MATCH 'three NEAR/2 two'} +} {{0 1 4 3 0 0 8 5 0 1 14 3 0 0 27 5}} +do_test fts3near-3.5 { + execsql {SELECT offsets(t1) FROM t1 WHERE content MATCH 'two NEAR/2 three'} +} {{0 0 4 3 0 1 8 5 0 0 14 3 0 1 27 5}} +do_test fts3near-3.6 { + execsql { + SELECT offsets(t1) FROM t1 WHERE content MATCH 'three NEAR/0 "two four"' + } +} {{0 0 8 5 0 1 14 3 0 2 18 4}} +do_test fts3near-3.7 { + execsql { + SELECT offsets(t1) FROM t1 WHERE content MATCH '"two four" NEAR/0 three'} +} {{0 2 8 5 0 0 14 3 0 1 18 4}} + +db eval { + INSERT INTO t1(content) VALUES(' + This specification defines Cascading Style Sheets, level 2 (CSS2). CSS2 is a style sheet language that allows authors and users to attach style (e.g., fonts, spacing, and aural cues) to structured documents (e.g., HTML documents and XML applications). By separating the presentation style of documents from the content of documents, CSS2 simplifies Web authoring and site maintenance. + + CSS2 builds on CSS1 (see [CSS1]) and, with very few exceptions, all valid CSS1 style sheets are valid CSS2 style sheets. CSS2 supports media-specific style sheets so that authors may tailor the presentation of their documents to visual browsers, aural devices, printers, braille devices, handheld devices, etc. This specification also supports content positioning, downloadable fonts, table layout, features for internationalization, automatic counters and numbering, and some properties related to user interface. + ') +} +do_test fts3near-4.1 { + execsql { + SELECT snippet(t1) FROM t1 WHERE content MATCH 'specification NEAR supports' + } +} {{...braille devices, handheld devices, etc. This specification also supports content positioning, downloadable fonts, table layout...}} + +do_test fts3near-5.1 { + execsql { + SELECT docid FROM t1 WHERE content MATCH 'specification attach' + } +} {2} +do_test fts3near-5.2 { + execsql { + SELECT docid FROM t1 WHERE content MATCH 'specification NEAR attach' + } +} {} +do_test fts3near-5.3 { + execsql { + SELECT docid FROM t1 WHERE content MATCH 'specification NEAR/18 attach' + } +} {} +do_test fts3near-5.4 { + execsql { + SELECT docid FROM t1 WHERE content MATCH 'specification NEAR/19 attach' + } +} {2} +do_test fts3near-5.5 { + execsql { + SELECT docid FROM t1 WHERE content MATCH 'specification NEAR/000018 attach' + } +} {} +do_test fts3near-5.6 { + execsql { + SELECT docid FROM t1 WHERE content MATCH 'specification NEAR/000019 attach' + } +} {2} + +db eval { + INSERT INTO t1 VALUES(' + abbrev aberrations abjurations aboding abr abscesses absolutistic + abstention abuses acanthuses acceptance acclaimers accomplish + accoutring accusation acetonic acid acolytes acquitting acrylonitrile + actives acyclic addicted adenoid adjacently adjusting admissible + adoption adulated advantaging advertisers aedes aerogramme aetiology + affiliative afforest afterclap agamogenesis aggrade agings agonize + agron ailurophile airfreight airspeed alarmists alchemizing + alexandrines alien aliped all allergenic allocator allowances almost + alphabetizes altho alvine amaurosis ambles ameliorate amicability amnio + amour ampicillin amusement anadromous analogues anarchy anchormen + anecdota aneurin angst animating anlage announcements anodized + answerable antemeridian anthracene antiabortionist anticlimaxes + antifriction antimitotic antiphon antiques antithetic anviled + apatosaurus aphrodisia apodal aposiopesis apparatus appendectomies + applications appraisingly appropriate apteryx arabinose + arboricultural archdeaconates archipelago ardently arguers armadillo + arnicas arrayed arrowy arthroscope artisans ascensive ashier + aspersorium assail assentor assignees assonants astereognosis + astringency astutest atheistical atomize attachment attenuates + attrahent audibility augite auricle auteurists autobus autolysis + autosome avenge avidest aw awl ayes babirusa backbeats backgrounder + backseat backswings baddie bagnios baked balefuller ballista balmily + bandbox bandylegged bankruptcy baptism barbering bargain barneys + barracuda barterer bashes bassists bathers batterer bavardage + beachfront beanstalk beauteous become bedim bedtimes beermats begat + begun belabors bellarmine belongings bending benthos bereavements + besieger bestialized betide bevels biases bicarbonates bidentate bigger + bile billow bine biodynamics biomedicine biotites birding bisection + bitingly bkg blackheads blaeberry blanking blatherer bleeper blindage + blithefulness blockish bloodstreams bloused blubbing bluestocking + blurted boatbill bobtailed boffo bold boltrope bondservant bonks + bookbinding bookworm booting borating boscages botchers bougainvillea + bounty bowlegged boyhood bracketed brainstorm brandishes + braunschweigers brazilin breakneck breathlessness brewage bridesmaids + brighter brisker broader brokerages bronziest browband brunets bryology + bucking budlike bugleweed bulkily bulling bummer bunglers bureau burgs + burrito bushfire buss butlery buttressing bylines cabdriver cached + cadaverousnesses cafeterias cakewalk calcifies calendula callboy calms + calyptra camisoles camps candelabrum caned cannolis canoodling cantors + cape caponize capsuling caracoled carbolics carcase carditis caretakers + carnallite carousel carrageenan cartels carves cashbook castanets + casuistry catalyzer catchers categorizations cathexis caucuses + causeway cavetto cede cella cementite centenary centrals ceramics ceria + cervixes chafferer chalcopyrites chamfers change chaotically + characteristically charivari chases chatterer cheats cheeks chef + chemurgy chetah chickaree chigoes chillies chinning chirp chive + chloroforms chokebore choplogic chorioids chromatic chronically + chubbiest chunder chutzpah cimetidine cinque circulated circumscribe + cirrose citrin claddagh clamorousness clapperboards classicalism + clauses cleanse clemency clicker clinchers cliquiest clods closeting + cloudscape clucking cnidarian coalfish coatrack coca cockfights coddled + coeducation coexistence cognitively coiffed colatitude collage + collections collinear colonelcy colorimetric columelliform combos + comforters commence commercialist commit commorancy communized compar + compendiously complainers compliance composition comprised comradery + concelebrants concerted conciliation concourses condensate + condonations confab confessionals confirmed conforming congeal + congregant conjectured conjurers connoisseurs conscripting + conservator consolable conspired constricting consuls contagious + contemporaneity contesters continuities contractors contrarian + contrive convalescents convents convexly convulsed cooncan coparcenary + coprolite copyreader cordially corklike cornflour coroner corralling + corrigible corsages cosies cosmonauts costumer cottontails counselings + counterclaim counterpane countertenors courageously couth coveting + coworker cozier cracklings crampon crappies craved cream credenzas + crematoriums cresol cricoid crinkle criterion crocodile crore crossover + crowded cruelest crunch cruzeiros cryptomeria cubism cuesta culprit + cumquat cupped curdle curly cursoring curvy customized cutting cyclamens + cylindrical cytaster dachshund daikon damages damselfly dangling + darkest databanks dauphine dazzling deadpanned deathday debauchers + debunking decameter decedents decibel decisions declinations + decomposition decoratively decretive deduct deescalated defecating + deferentially definiendum defluxion defrocks degrade deice dekaliters + deli delinquencies deludedly demarcates demineralizers demodulating + demonstrabilities demurred deniabilities denouncement denudation + departure deplorable deposing depredatory deputizes derivational + desalinization descriptors desexes desisted despising destitute + detectability determiner detoxifying devalued devilries devotions + dextrous diagenesis dialling diaphoresis diazonium dickeys diddums + differencing dig dignified dildo dimetric dineric dinosaurs diplodocus + directer dirty disagrees disassembler disburses disclosures + disconcerts discountability discrete disembarrass disenthrone + disgruntled dishpans disintegrators dislodged disobedient + dispassionate dispiritednesses dispraised disqualifying + dissatisfying dissidence dissolvers distich distracting distrusts + ditto diverse divineness dizzily dockyard dodgers doggish doited dom + dominium doohickey doozie dorsum doubleheaders dourer downbeats + downshifted doyennes draftsman dramatic drawling dredge drifter + drivelines droopier drowsed drunkards dubiosities duding dulcifying + dumpcart duodecillion durable duteous dyed dysgenic eagles earplugs + earwitness ebonite echoers economical ectothermous edibility educates + effected effigies eggbeaters egresses ejaculates elasticize elector + electrodynamometer electrophorus elem eligibly eloped emaciating + embarcaderos embezzlers embosses embryectomy emfs emotionalizing + empiricist emu enamels enchained encoded encrusts endeavored endogamous + endothelioma energizes engager engrosses enl enologist enrolls ensphere + enters entirety entrap entryways envies eosinophil epicentral + epigrammatized episodic epochs equestrian equitably erect ernes + errorless escalated eschatology espaliers essonite estop eternity + ethnologically eudemonics euphonious euthenist evangelizations + eventuality evilest evulsion examinee exceptionably exciter + excremental execrably exemplars exhalant exhorter exocrine exothermic + expected expends explainable exploratory expostulatory expunges + extends externals extorts extrapolative extrorse eyebolt eyra + facetiously factor faeries fairings fallacies falsities fancifulness + fantasticalness farmhouse fascinate fatalistically fattener fave + fearlessly featly federates feints fellowman fencers ferny + fertilenesses feta feudality fibers fictionalize fiefs fightback + filefish filmier finaglers fingerboards finochio firefly firmament + fishmeal fitted fjords flagitiousnesses flamen flaps flatfooting + flauntier fleapit fleshes flickertail flints floaty floorboards + floristic flow fluffily fluorescein flutes flyspecks foetal folderols + followable foolhardier footlockers foppish forceless foredo foreknows + foreseeing foretaste forgather forlorn formidableness fortalice + forwarding founding foxhunting fragmentarily frangipani fray freeform + freezable freshening fridges frilliest frizzed frontbench frottages + fruitcake fryable fugleman fulminated functionalists fungoid furfuran + furtive fussy fwd gadolinium galabias gallinaceous galvanism gamers + gangland gaoling garganey garrisoning gasp gate gauger gayety geed + geminately generalissimos genii gentled geochronology geomorphic + geriatricians gesellschaft ghat gibbeting giggles gimps girdlers + glabella glaive glassfuls gleefully glistered globetrotted glorifier + gloving glutathione glyptodont goaled gobsmacked goggliest golliwog + goobers gooseberries gormandizer gouramis grabbier gradually grampuses + grandmothers granulated graptolite gratuitously gravitates greaten + greenmailer greys grills grippers groan gropingly grounding groveling + grueled grunter guardroom guggle guineas gummed gunnysacks gushingly + gutturals gynecoid gyrostabilizer habitudes haemophilia hailer hairs + halest hallow halters hamsters handhelds handsaw hangup haranguer + hardheartedness harlotry harps hashing hated hauntingly hayrack + headcases headphone headword heartbreakers heaters hebephrenia + hedonist heightening heliozoan helots hemelytron hemorrhagic hent + herbicides hereunto heroines heteroclitics heterotrophs hexers + hidebound hies hightails hindmost hippopotomonstrosesquipedalian + histologist hittable hobbledehoys hogans holdings holocrine homegirls + homesteader homogeneousness homopolar honeys hoodwinks hoovered + horizontally horridness horseshoers hospitalization hotdogging houri + housemate howitzers huffier humanist humid humors huntress husbandmen + hyaenas hydride hydrokinetics hydroponically hygrothermograph + hyperbolically hypersensitiveness hypnogogic hypodermically + hypothermia iatrochemistry ichthyological idealist ideograms idling + igniting illegal illuminatingly ilmenite imbibing immateriality + immigrating immortalizes immures imparts impeder imperfection + impersonated implant implying imposition imprecating imprimis + improvising impv inanenesses inaugurate incapably incentivize + incineration incloses incomparableness inconsequential incorporate + incrementing incumbered indecorous indentation indicative indignities + indistinguishably indoors indulges ineducation inerrable + inexperienced infants infestations infirmnesses inflicting + infracostal ingathered ingressions inheritances iniquity + injuriousnesses innervated inoculates inquisitionist insectile + insiders insolate inspirers instatement instr insulates intactness + intellects intensifies intercalations intercontinental interferon + interlarded intermarrying internalizing interpersonally + interrelatednesses intersperse interviewees intolerance + intransigents introducing intubates invades inventing inveterate + invocate iodides irenicism ironsmith irreducibly irresistibility + irriguous isobarisms isometrically issuable itineracies jackdaws + jaggery jangling javelins jeeringly jeremiad jeweler jigsawing jitter + jocosity jokester jot jowls judicative juicy jungly jurists juxtaposed + kalpa karstify keddah kendo kermesses keynote kibbutznik kidnaper + kilogram kindred kingpins kissers klatch kneads knobbed knowingest + kookaburras kruller labefaction labyrinths lacquer laddered lagoons + lambency laminates lancinate landscapist lankiness lapse larked lasso + laterite laudableness laundrywomen lawgiver laypersons leafhoppers + leapfrogs leaven leeches legated legislature leitmotifs lenients + leprous letterheads levelling lexicographically liberalists + librettist licorice lifesaving lightheadedly likelier limekiln limped + lines linkers lipoma liquidator listeners litharge litmus + liverishnesses loamier lobeline locative locutionary loggier loiterer + longevity loomed loping lotion louts lowboys luaus lucrativeness lulus + lumpier lungi lush luthern lymphangial lythraceous machinists maculate + maggot magnetochemistry maharani maimers majored malaprops malignants + maloti mammary manchineel manfully manicotti manipulativenesses + mansards manufactories maraschino margin markdown marooning marshland + mascaraing massaging masticate matchmark matings mattes mausoleum + mayflies mealworm meataxe medevaced medievalist meetings megavitamin + melded melodramatic memorableness mendaciousnesses mensurable + mercenaries mere meronymous mesmerizes mestee metallurgical + metastasize meterages meticulosity mewed microbe microcrystalline + micromanager microsporophyll midiron miffed milder militiamen + millesimal milometer mincing mingily minims minstrelsy mires + misanthropic miscalculate miscomprehended misdefines misery mishears + misled mispickel misrepresent misspending mistranslate miswriting + mixologists mobilizers moderators modulate mojo mollies momentum monde + monied monocles monographs monophyletic monotonousness moocher + moorages morality morion mortally moseyed motherly motorboat mouldering + mousers moveables mucky mudslides mulatto multicellularity + multipartite multivalences mundanities murkiest mushed muskiness + mutability mutisms mycelia myosotis mythicist nacred namable napkin + narghile nastiness nattering nauseations nearliest necessitate + necrophobia neg negotiators neologizes nephrotomy netiquette + neurophysiology newbie newspaper niccolite nielsbohriums nightlong + nincompoops nitpicked nix noddling nomadize nonadhesive noncandidates + nonconducting nondigestible nones nongreasy nonjoinder nonoccurrence + nonporousness nonrestrictive nonstaining nonuniform nooses northwards + nostalgic notepaper nourishment noyades nuclides numberless numskulls + nutmegged nymphaea oatmeal obis objurgators oblivious obsequiousness + obsoletism obtruding occlusions ocher octettes odeums offcuts + officiation ogival oilstone olestras omikron oncogenesis onsetting + oomphs openly ophthalmoscope opposites optimum orangutans + orchestrations ordn organophosphates origin ornithosis orthognathous + oscillatory ossuaries ostracized ounce outbreaks outearning outgrows + outlived outpoints outrunning outspends outwearing overabound + overbalance overcautious overcrowds overdubbing overexpanding + overgraze overindustrialize overlearning overoptimism overproducing + overripe overshadowing overspreading overstuff overtones overwind ow + oxidizing pacer packs paganish painstakingly palate palette pally + palsying pandemic panhandled pantheism papaws papped parading + parallelize paranoia parasitically pardners parietal parodied pars + participator partridgeberry passerines password pastors + paterfamiliases patination patrolman paunch pawnshops peacekeeper + peatbog peculator pedestrianism peduncles pegboard pellucidnesses + pendency penitentiary penstock pentylenetetrazol peptidase perched + perennial performing perigynous peripheralize perjurer permissively + perpetuals persistency perspicuously perturbingly pesky petcock + petrologists pfennige pharmacies phenformin philanderers + philosophically phonecards phosgenes photocomposer photogenic photons + phototype phylloid physiotherapeutics picadores pickup pieces pigging + pilaster pillion pimples pinioned pinpricks pipers pirogi pit + pitifullest pizza placental plainly planing plasmin platforming + playacts playwrights plectra pleurisy plopped plug plumule plussed + poaches poetasters pointless polarize policyholder polkaed + polyadelphous polygraphing polyphonous pomace ponderers pooch poplar + porcelains portableness portly positioning postage posthumously + postponed potages potholed poulard powdering practised pranksters + preadapt preassigning precentors precipitous preconditions predefined + predictors preengage prefers prehumans premedical prenotification + preplanning prepuberty presbytery presentation presidia prestissimo + preterites prevailer prewarmed priding primitively principalships + prisage privileged probed prochurch proctoscope products proficients + prognathism prohibiting proletarianisms prominence promulgates + proofreading property proportions prorate proselytize prosthesis + proteins prototypic provenances provitamin prudish pseudonymities + psychoanalysts psychoneuroses psychrometer publishable pufferies + pullet pulses punchy punkins purchased purities pursers pushover + putridity pylons pyrogenous pzazz quadricepses quaff qualmish quarriers + quasilinear queerness questionnaires quieten quintals quislings quoits + rabidness racketeers radiative radioisotope radiotherapists ragingly + rainband rakishness rampagers rands raped rare raspy ratiocinator + rattlebrain ravening razz reactivation readoption realm reapportioning + reasoning reattempts rebidding rebuts recapitulatory receptiveness + recipes reckonings recognizee recommendatory reconciled reconnoiters + recontaminated recoupments recruits recumbently redact redefine + redheaded redistributable redraw redwing reeled reenlistment reexports + refiles reflate reflowing refortified refried refuses regelate + registrant regretting rehabilitative reigning reinduced reinstalled + reinvesting rejoining relations relegates religiosities reluctivity + remastered reminisce remodifying remounted rends renovate reordered + repartee repel rephrase replicate repossessing reprint reprogramed + repugnantly requiter rescheduling resegregate resettled residually + resold resourcefulness respondent restating restrainedly resubmission + resurveyed retaliating retiarius retorsion retreated retrofitting + returning revanchism reverberated reverted revitalization + revolutionize rewind rhapsodizing rhizogenic rhythms ricketinesses + ridicule righteous rilles rinks rippliest ritualize riyals roast rockery + roguish romanizations rookiest roquelaure rotation rotundity rounder + routinizing rubberize rubricated ruefully ruining rummaged runic + russets ruttish sackers sacrosanctly safeguarding said salaciousness + salinity salsas salutatorians sampan sandbag saned santonin + saprophagous sarnies satem saturant savaged sawbucks scablike scalp + scant scared scatter schedulers schizophrenics schnauzers schoolmarms + scintillae scleroses scoped scotched scram scratchiness screwball + scripting scrubwomen scrutinizing scumbled scuttled seals seasickness + seccos secretions secularizing seditiousnesses seeking segregators + seize selfish semeiology seminarian semitropical sensate sensors + sentimo septicemic sequentially serener serine serums + sesquicentennials seventeen sexiest sforzandos shadowing shallot + shampooing sharking shearer sheered shelters shifter shiner shipper + shitted shoaled shofroth shorebirds shortsightedly showboated shrank + shrines shucking shuttlecocks sickeningly sideling sidewise sigil + signifiers siliceous silty simony simulative singled sinkings sirrah + situps skateboarder sketchpad skim skirmished skulkers skywalk slander + slating sleaziest sleepyheads slicking slink slitting slot slub + slumlords smallest smattered smilier smokers smriti snailfish snatch + snides snitching snooze snowblowers snub soapboxing socialite sockeyes + softest sold solicitings solleret sombreros somnolencies sons sopor + sorites soubrette soupspoon southpaw spaces spandex sparkers spatially + speccing specking spectroscopists speedsters spermatics sphincter + spiffied spindlings spirals spitball splayfeet splitter spokeswomen + spooled sportily spousals sprightliness sprogs spurner squalene + squattered squelches squirms stablish staggerings stalactitic stamp + stands starflower starwort stations stayed steamroll steeplebush + stemmatics stepfathers stereos steroid sticks stillage stinker + stirringly stockpiling stomaching stopcock stormers strabismuses + strainer strappado strawberries streetwise striae strikeouts strives + stroppiest stubbed study stunting style suavity subchloride subdeb + subfields subjoin sublittoral subnotebooks subprograms subside + substantial subtenants subtreasuries succeeding sucked sufferers + sugarier sulfaguanidine sulphating summerhouse sunbonnets sunned + superagency supercontinent superheroes supernatural superscribing + superthin supplest suppositive surcease surfs surprise survey + suspiration svelte swamplands swashes sweatshop swellhead swindling + switching sworn syllabuses sympathetics synchrocyclotron syndic + synonymously syringed tablatures tabulation tackling taiga takas talker + tamarisks tangential tans taproom tarpapers taskmaster tattiest + tautologically taxied teacup tearjerkers technocracies teepee + telegenic telephony telexed temperaments temptress tenderizing tensed + tenuring tergal terned terror testatrices tetherball textile thatched + their theorem thereof thermometers thewy thimerosal thirsty + thoroughwort threateningly thrived through thumbnails thwacks + ticketing tie til timekeepers timorousness tinkers tippers tisane + titrating toastmaster toff toking tomb tongs toolmakings topes topple + torose tortilla totalizing touchlines tousling townsmen trachea + tradeable tragedienne traitorous trances transcendentalists + transferrable tranship translating transmogrifying transportable + transvestism traumatize treachery treed trenail tressing tribeswoman + trichromatism triennials trikes trims triplicate tristich trivializes + trombonist trots trouts trued trunnion tryster tubes tulle tundras turban + turgescence turnround tutelar tweedinesses twill twit tympanum typists + tzarists ulcered ultramodern umbles unaccountability unamended + unassertivenesses unbanned unblocked unbundled uncertified unclaimed + uncoated unconcerns unconvinced uncrossing undefined underbodice + underemphasize undergrowth underpayment undershirts understudy + underwritten undissolved unearthed unentered unexpended unfeeling + unforeseen unfussy unhair unhinges unifilar unimproved uninvitingly + universalization unknowns unlimbering unman unmet unnaturalness + unornament unperturbed unprecedentedly unproportionate unread + unreflecting unreproducible unripe unsatisfying unseaworthiness + unsharable unsociable unstacking unsubtly untactfully untied untruest + unveils unwilled unyokes upheave upraised upstart upwind urethrae + urtexts usurers uvula vacillators vailed validation valvule vanities + varia variously vassaled vav veggies velours venerator ventrals + verbalizes verification vernacularized verticality vestigially via + vicariously victoriousness viewpoint villainies vines violoncellist + virtual viscus vital vitrify viviparous vocalizers voidable volleys + volutes vouches vulcanology wackos waggery wainwrights waling wallowing + wanking wardroom warmup wartiest washwoman watchman watermarks waverer + wayzgoose weariest weatherstripped weediness weevil welcomed + wentletrap whackers wheatworm whelp whf whinged whirl whistles whithers + wholesomeness whosoever widows wikiup willowier windburned windsail + wingspread winterkilled wisecracking witchgrass witling wobbliest + womanliness woodcut woodworking woozy working worldwide worthiest + wrappings wretched writhe wynd xylophone yardarm yea yelped yippee yoni + yuks zealotry zigzagger zitherists zoologists zygosis'); +} + +do_test fts3near-6.1 { + execsql { + SELECT docid FROM t1 WHERE content MATCH 'abbrev zygosis' + } +} {3} +do_test fts3near-6.2 { + execsql { + SELECT docid FROM t1 WHERE content MATCH 'abbrev NEAR zygosis' + } +} {} +do_test fts3near-6.3 { + execsql { + SELECT docid FROM t1 WHERE content MATCH 'abbrev NEAR/100 zygosis' + } +} {} +do_test fts3near-6.4 { + execsql { + SELECT docid FROM t1 WHERE content MATCH 'abbrev NEAR/1000 zygosis' + } +} {} +do_test fts3near-6.5 { + execsql { + SELECT docid FROM t1 WHERE content MATCH 'abbrev NEAR/10000 zygosis' + } +} {3} + +# Ticket 38b1ae018f. +# +do_execsql_test fts3near-7.1 { + CREATE VIRTUAL TABLE x USING fts4(y,z); + INSERT INTO x VALUES('aaa bbb ccc ddd', 'bbb ddd aaa ccc'); + SELECT * FROM x where y MATCH 'bbb NEAR/6 aaa'; +} {{aaa bbb ccc ddd} {bbb ddd aaa ccc}} + +do_execsql_test fts3near-7.2 { + CREATE VIRTUAL TABLE t2 USING fts4(a, b); + INSERT INTO t2 VALUES('A B C', 'A D E'); + SELECT * FROM t2 where t2 MATCH 'a:A NEAR E' +} {} + + +finish_test diff --git a/test/fts3offsets.test b/test/fts3offsets.test new file mode 100644 index 0000000..24c339d --- /dev/null +++ b/test/fts3offsets.test @@ -0,0 +1,135 @@ +# 2010 November 02 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is not defined, omit this file. +ifcapable !fts3 { finish_test ; return } + +set testprefix fts3offsets +set sqlite_fts3_enable_parentheses 1 + +proc extract {offsets text} { + set res "" + + set off [list] + foreach {t i s n} $offsets { + lappend off [list $s $n] + } + set off [lsort -integer -index 0 $off] + + set iOff 0 + foreach e $off { + foreach {s n} $e {} + append res [string range $text $iOff $s-1] + append res "(" + append res [string range $text $s [expr $s+$n-1]] + append res ")" + set iOff [expr $s+$n] + } + append res [string range $text $iOff end] + + set res +} +db func extract extract + + +do_execsql_test 1.1.0 { + CREATE VIRTUAL TABLE xx USING fts3(x); + INSERT INTO xx VALUES('A x x x B C x x'); + INSERT INTO xx VALUES('A B C x B x x C'); + INSERT INTO xx VALUES('A x x B C x x x'); +} +do_execsql_test 1.1.1 { + SELECT oid,extract(offsets(xx), x) FROM xx WHERE xx MATCH 'a OR (b NEAR/1 c)'; +} { + 1 {(A) x x x (B) (C) x x} + 2 {(A) (B) (C) x (B) x x C} + 3 {(A) x x (B) (C) x x x} +} + +do_execsql_test 1.2 { + DELETE FROM xx; + INSERT INTO xx VALUES('A x x x B C x x'); + INSERT INTO xx VALUES('A x x C x x x C'); + INSERT INTO xx VALUES('A x x B C x x x'); +} +do_execsql_test 1.2.1 { + SELECT oid,extract(offsets(xx), x) FROM xx WHERE xx MATCH 'a OR (b NEAR/1 c)'; +} { + 1 {(A) x x x (B) (C) x x} + 2 {(A) x x C x x x C} + 3 {(A) x x (B) (C) x x x} +} + +do_execsql_test 1.3 { + DELETE FROM xx; + INSERT INTO xx(rowid, x) VALUES(1, 'A B C'); + INSERT INTO xx(rowid, x) VALUES(2, 'A x'); + INSERT INTO xx(rowid, x) VALUES(3, 'A B C'); + INSERT INTO xx(rowid, x) VALUES(4, 'A B C x x x x x x x B'); + INSERT INTO xx(rowid, x) VALUES(5, 'A x x x x x x x x x C'); + INSERT INTO xx(rowid, x) VALUES(6, 'A x x x x x x x x x x x B'); + INSERT INTO xx(rowid, x) VALUES(7, 'A B C'); +} +do_execsql_test 1.3.1 { + SELECT oid,extract(offsets(xx), x) FROM xx WHERE xx MATCH 'a OR (b NEAR/1 c)'; +} { + 1 {(A) (B) (C)} + 2 {(A) x} + 3 {(A) (B) (C)} + 4 {(A) (B) (C) x x x x x x x B} + 5 {(A) x x x x x x x x x C} + 6 {(A) x x x x x x x x x x x B} + 7 {(A) (B) (C)} +} + + +do_execsql_test 1.4 { + DELETE FROM xx; + INSERT INTO xx(rowid, x) VALUES(7, 'A B C'); + INSERT INTO xx(rowid, x) VALUES(6, 'A x'); + INSERT INTO xx(rowid, x) VALUES(5, 'A B C'); + INSERT INTO xx(rowid, x) VALUES(4, 'A B C x x x x x x x B'); + INSERT INTO xx(rowid, x) VALUES(3, 'A x x x x x x x x x C'); + INSERT INTO xx(rowid, x) VALUES(2, 'A x x x x x x x x x x x B'); + INSERT INTO xx(rowid, x) VALUES(1, 'A B C'); +} +do_execsql_test 1.4.1 { + SELECT oid,extract(offsets(xx), x) FROM xx WHERE xx MATCH 'a OR (b NEAR/1 c)' + ORDER BY docid DESC; +} { + 7 {(A) (B) (C)} + 6 {(A) x} + 5 {(A) (B) (C)} + 4 {(A) (B) (C) x x x x x x x B} + 3 {(A) x x x x x x x x x C} + 2 {(A) x x x x x x x x x x x B} + 1 {(A) (B) (C)} +} + +do_execsql_test 1.5.0 { + CREATE VIRTUAL TABLE x1 USING fts3(x); + INSERT INTO x1 VALUES('A A A'); + INSERT INTO x1 VALUES('A A A'); +} +do_execsql_test 1.5.1 { + SELECT offsets(x1) FROM x1 WHERE x1 MATCH 'a OR b AND c NEAR d' +} { + {0 0 0 1 0 0 2 1 0 0 4 1} + {0 0 0 1 0 0 2 1 0 0 4 1} +} + + +set sqlite_fts3_enable_parentheses 0 +finish_test diff --git a/test/fts3prefix.test b/test/fts3prefix.test new file mode 100644 index 0000000..e8d2b2b --- /dev/null +++ b/test/fts3prefix.test @@ -0,0 +1,295 @@ +# 2011 May 04 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS3 module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts3prefix + +ifcapable !fts3 { + finish_test + return +} + +# This proc tests that the prefixes index appears to represent the same content +# as the terms index. +# +proc fts3_terms_and_prefixes {db tbl prefixlengths} { + + set iIndex 0 + foreach len $prefixlengths { + incr iIndex + $db eval { + DROP TABLE IF EXISTS fts3check1; + DROP TABLE IF EXISTS fts3check2; + } + $db eval "CREATE VIRTUAL TABLE fts3check1 USING fts4term($tbl, 0);" + $db eval "CREATE VIRTUAL TABLE fts3check2 USING fts4term($tbl, $iIndex);" + + $db eval { + DROP TABLE IF EXISTS temp.terms; + DROP TABLE IF EXISTS temp.prefixes; + CREATE TEMP TABLE terms AS SELECT * FROM fts3check1; + CREATE TEMP TABLE prefixes AS SELECT * FROM fts3check2; + CREATE INDEX temp.idx ON prefixes(term); + DROP TABLE fts3check1; + DROP TABLE fts3check2; + } + + set nExpect 0 + $db eval { SELECT term, docid, col, pos FROM temp.terms } a { + if {[string length $a(term)]<$len} continue + incr nExpect + set prefix [string range $a(term) 0 [expr $len-1]] + set r [$db one { + SELECT count(*) FROM temp.prefixes WHERE + term = $prefix AND docid = $a(docid) AND col = $a(col) AND pos = $a(pos) + }] + if {$r != 1} { + error "$t, $a(docid), $a(col), $a(pos)" + } + } + + set nCount [$db one {SELECT count(*) FROM temp.prefixes}] + if {$nCount != $nExpect} { + error "prefixes.count(*) is $nCount expected $nExpect" + } + + execsql { DROP TABLE temp.prefixes } + execsql { DROP TABLE temp.terms } + + set list [list] + $db eval " + SELECT sum( 1 << (16*(level%1024)) ) AS total, (level/1024) AS tree + FROM ${tbl}_segdir GROUP BY tree + " { + lappend list [list $total $tree] + } + + if { [lsort -integer -index 0 $list] != [lsort -integer -index 1 $list] } { + error "inconsistent tree structures: $list" + } + } + + return "" +} +proc fts3_tap_test {tn db tbl lens} { + uplevel [list do_test $tn [list fts3_terms_and_prefixes $db $tbl $lens] ""] +} + +#------------------------------------------------------------------------- +# Test cases 1.* are a sanity check. They test that the prefixes index is +# being constructed correctly for the simplest possible case. +# +do_execsql_test 1.1 { + CREATE VIRTUAL TABLE t1 USING fts4(prefix='1,3,6'); + + CREATE VIRTUAL TABLE p1 USING fts4term(t1, 1); + CREATE VIRTUAL TABLE p2 USING fts4term(t1, 2); + CREATE VIRTUAL TABLE p3 USING fts4term(t1, 3); + CREATE VIRTUAL TABLE terms USING fts4term(t1); +} +do_execsql_test 1.2 { + INSERT INTO t1 VALUES('sqlite mysql firebird'); +} +do_execsql_test 1.3.1 { SELECT term FROM p1 } {f m s} +do_execsql_test 1.3.2 { SELECT term FROM p2 } {fir mys sql} +do_execsql_test 1.3.3 { SELECT term FROM p3 } {firebi sqlite} +do_execsql_test 1.4 { + SELECT term FROM terms; +} {firebird mysql sqlite} + +fts3_tap_test 1.5 db t1 {1 3 6} + +#------------------------------------------------------------------------- +# A slightly more complicated dataset. This test also verifies that DELETE +# operations do not corrupt the prefixes index. +# +do_execsql_test 2.1 { + INSERT INTO t1 VALUES('FTS3 and FTS4 are an SQLite virtual table modules'); + INSERT INTO t1 VALUES('that allows users to perform full-text searches on'); + INSERT INTO t1 VALUES('a set of documents. The most common (and'); + INSERT INTO t1 VALUES('effective) way to describe full-text searches is'); + INSERT INTO t1 VALUES('"what Google, Yahoo and Altavista do with'); + INSERT INTO t1 VALUES('documents placed on the World Wide Web". Users'); + INSERT INTO t1 VALUES('input a term, or series of terms, perhaps'); + INSERT INTO t1 VALUES('connected by a binary operator or grouped together'); + INSERT INTO t1 VALUES('into a phrase, and the full-text query system'); + INSERT INTO t1 VALUES('finds the set of documents that best matches those'); + INSERT INTO t1 VALUES('terms considering the operators and groupings the'); + INSERT INTO t1 VALUES('user has specified. This article describes the'); + INSERT INTO t1 VALUES('deployment and usage of FTS3 and FTS4.'); + INSERT INTO t1 VALUES('FTS1 and FTS2 are obsolete full-text search'); + INSERT INTO t1 VALUES('modules for SQLite. There are known issues with'); + INSERT INTO t1 VALUES('these older modules and their use should be'); + INSERT INTO t1 VALUES('avoided. Portions of the original FTS3 code were'); + INSERT INTO t1 VALUES('contributed to the SQLite project by Scott Hess of'); + INSERT INTO t1 VALUES('Google. It is now developed and maintained as part'); + INSERT INTO t1 VALUES('of SQLite. '); +} +fts3_tap_test 2.2 db t1 {1 3 6} +do_execsql_test 2.3 { DELETE FROM t1 WHERE docid%2; } +fts3_tap_test 2.4 db t1 {1 3 6} + +do_execsql_test 2.5 { INSERT INTO t1(t1) VALUES('optimize') } +fts3_tap_test 2.6 db t1 {1 3 6} + +do_execsql_test 3.1 { + CREATE VIRTUAL TABLE t2 USING fts4(prefix='1,2,3'); + INSERT INTO t2 VALUES('On 12 September the wind direction turned and'); + INSERT INTO t2 VALUES('William''s fleet sailed. A storm blew up and the'); + INSERT INTO t2 VALUES('fleet was forced to take shelter at'); + INSERT INTO t2 VALUES('Saint-Valery-sur-Somme and again wait for the wind'); + INSERT INTO t2 VALUES('to change. On 27 September the Norman fleet'); + INSERT INTO t2 VALUES('finally set sail, landing in England at Pevensey'); + INSERT INTO t2 VALUES('Bay (Sussex) on 28 September. William then moved'); + INSERT INTO t2 VALUES('to Hastings, a few miles to the east, where he'); + INSERT INTO t2 VALUES('built a prefabricated wooden castle for a base of'); + INSERT INTO t2 VALUES('operations. From there, he ravaged the hinterland'); + INSERT INTO t2 VALUES('and waited for Harold''s return from the north.'); + INSERT INTO t2 VALUES('On 12 September the wind direction turned and'); + INSERT INTO t2 VALUES('William''s fleet sailed. A storm blew up and the'); + INSERT INTO t2 VALUES('fleet was forced to take shelter at'); + INSERT INTO t2 VALUES('Saint-Valery-sur-Somme and again wait for the wind'); + INSERT INTO t2 VALUES('to change. On 27 September the Norman fleet'); + INSERT INTO t2 VALUES('finally set sail, landing in England at Pevensey'); + INSERT INTO t2 VALUES('Bay (Sussex) on 28 September. William then moved'); + INSERT INTO t2 VALUES('to Hastings, a few miles to the east, where he'); + INSERT INTO t2 VALUES('built a prefabricated wooden castle for a base of'); + INSERT INTO t2 VALUES('operations. From there, he ravaged the hinterland'); + INSERT INTO t2 VALUES('and waited for Harold''s return from the north.'); +} + +fts3_tap_test 3.2 db t2 {1 2 3} +do_execsql_test 3.3 { SELECT optimize(t2) FROM t2 LIMIT 1 } {{Index optimized}} +fts3_tap_test 3.4 db t2 {1 2 3} + + +#------------------------------------------------------------------------- +# Simple tests for reading the prefix-index. +# +do_execsql_test 4.1 { + CREATE VIRTUAL TABLE t3 USING fts4(prefix="1,4"); + INSERT INTO t3 VALUES('one two three'); + INSERT INTO t3 VALUES('four five six'); + INSERT INTO t3 VALUES('seven eight nine'); +} +do_execsql_test 4.2 { + SELECT * FROM t3 WHERE t3 MATCH 'f*' +} {{four five six}} +do_execsql_test 4.3 { + SELECT * FROM t3 WHERE t3 MATCH 'four*' +} {{four five six}} +do_execsql_test 4.4 { + SELECT * FROM t3 WHERE t3 MATCH 's*' +} {{four five six} {seven eight nine}} +do_execsql_test 4.5 { + SELECT * FROM t3 WHERE t3 MATCH 'sev*' +} {{seven eight nine}} +do_execsql_test 4.6 { + SELECT * FROM t3 WHERE t3 MATCH 'one*' +} {{one two three}} + +#------------------------------------------------------------------------- +# Syntax tests. +# +do_catchsql_test 5.1 { + CREATE VIRTUAL TABLE t4 USING fts4(prefix="abc"); +} {1 {error parsing prefix parameter: abc}} +do_catchsql_test 5.2 { + CREATE VIRTUAL TABLE t4 USING fts4(prefix=""); +} {0 {}} +do_catchsql_test 5.3 { + CREATE VIRTUAL TABLE t5 USING fts4(prefix="-1"); +} {1 {error parsing prefix parameter: -1}} + +#------------------------------------------------------------------------- +# Prefix indexes of size 0 are ignored. Demonstrate this by showing that +# adding prefix=0 does not change the contents of the %_segdir table. +# +reset_db +do_execsql_test 6.1.1 { + CREATE VIRTUAL TABLE t1 USING fts4(prefix=0); + CREATE VIRTUAL TABLE t2 USING fts4; + INSERT INTO t1 VALUES('Twas Mulga Bill, from Eaglehawk, '); + INSERT INTO t2 VALUES('Twas Mulga Bill, from Eaglehawk, '); +} {} +do_execsql_test 6.1.2 { + SELECT md5sum(quote(root)) FROM t1_segdir; +} [db eval {SELECT md5sum(quote(root)) FROM t2_segdir}] + +reset_db +do_execsql_test 6.2.1 { + CREATE VIRTUAL TABLE t1 USING fts4(prefix="1,0,2"); + CREATE VIRTUAL TABLE t2 USING fts4(prefix="1,2"); + INSERT INTO t1 VALUES('that caught the cycling craze;'); + INSERT INTO t2 VALUES('that caught the cycling craze;'); +} {} +do_execsql_test 6.2.2 { + SELECT md5sum(quote(root)) FROM t1_segdir; +} [db eval {SELECT md5sum(quote(root)) FROM t2_segdir}] + +reset_db +do_execsql_test 6.3.1 { + CREATE VIRTUAL TABLE t1 USING fts4(prefix="1,3,2"); + CREATE VIRTUAL TABLE t2 USING fts4(prefix="1,2"); + INSERT INTO t1 VALUES('He turned away the good old horse'); + INSERT INTO t2 VALUES('He turned away the good old horse'); +} {} +do_test 6.3.2 { + set one [db eval {SELECT md5sum(quote(root)) FROM t1_segdir}] + set two [db eval {SELECT md5sum(quote(root)) FROM t2_segdir}] + expr {$one == $two} +} 0 + +reset_db +do_execsql_test 6.4.1 { + CREATE VIRTUAL TABLE t1 USING fts4(prefix="1,600,2"); + CREATE VIRTUAL TABLE t2 USING fts4(prefix="1,2"); + INSERT INTO t1 VALUES('that served him many days;'); + INSERT INTO t2 VALUES('that served him many days;'); +} {} +do_execsql_test 6.4.2 { + SELECT md5sum(quote(root)) FROM t1_segdir; +} [db eval {SELECT md5sum(quote(root)) FROM t2_segdir}] + +reset_db +do_execsql_test 6.5.1 { + CREATE VIRTUAL TABLE t1 USING fts4(prefix="2147483647,2147483648,2147483649"); + CREATE VIRTUAL TABLE t2 USING fts4(prefix=); + INSERT INTO t1 VALUES('He dressed himself in cycling clothes'); + INSERT INTO t2 VALUES('He dressed himself in cycling clothes'); +} {} +do_execsql_test 6.5.2 { + SELECT md5sum(quote(root)) FROM t1_segdir; +} [db eval {SELECT md5sum(quote(root)) FROM t2_segdir}] + + +do_execsql_test 7.0 { + CREATE VIRTUAL TABLE t6 USING fts4(x,order=DESC); + INSERT INTO t6(docid, x) VALUES(-1,'a b'); + INSERT INTO t6(docid, x) VALUES(1, 'b'); +} +do_execsql_test 7.1 { + SELECT docid FROM t6 WHERE t6 MATCH '"a* b"'; +} {-1} +do_execsql_test 7.2 { + SELECT docid FROM t6 WHERE t6 MATCH 'a*'; +} {-1} +do_execsql_test 7.3 { + SELECT docid FROM t6 WHERE t6 MATCH 'a* b'; +} {-1} + + + +finish_test diff --git a/test/fts3prefix2.test b/test/fts3prefix2.test new file mode 100644 index 0000000..e033fb6 --- /dev/null +++ b/test/fts3prefix2.test @@ -0,0 +1,61 @@ +# 2012 January 25 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS3 module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts3prefix2 + +ifcapable !fts3 { + finish_test + return +} + +do_execsql_test 1.0 { PRAGMA page_size = 512 } +do_execsql_test 1.1 { + CREATE VIRTUAL TABLE t1 USING fts4(x, prefix="2,3"); + + BEGIN; + INSERT INTO t1 VALUES('T TX T TX T TX T TX T TX'); + INSERT INTO t1 SELECT * FROM t1; -- 2 + INSERT INTO t1 SELECT * FROM t1; -- 4 + INSERT INTO t1 SELECT * FROM t1; -- 8 + INSERT INTO t1 SELECT * FROM t1; -- 16 + INSERT INTO t1 SELECT * FROM t1; -- 32 + INSERT INTO t1 SELECT * FROM t1; -- 64 + INSERT INTO t1 SELECT * FROM t1; -- 128 + INSERT INTO t1 SELECT * FROM t1; -- 256 + INSERT INTO t1 SELECT * FROM t1; -- 512 + INSERT INTO t1 SELECT * FROM t1; -- 1024 + INSERT INTO t1 SELECT * FROM t1; -- 2048 + COMMIT; +} + +do_execsql_test 1.2 { + INSERT INTO t1 SELECT * FROM t1 LIMIT 10; + INSERT INTO t1 SELECT * FROM t1 LIMIT 10; + INSERT INTO t1 SELECT * FROM t1 LIMIT 10; + DELETE FROM t1 WHERE docid > 5; +} + +do_execsql_test 1.3 { + SELECT * FROM t1 WHERE t1 MATCH 'T*'; +} { + {T TX T TX T TX T TX T TX} + {T TX T TX T TX T TX T TX} + {T TX T TX T TX T TX T TX} + {T TX T TX T TX T TX T TX} + {T TX T TX T TX T TX T TX} +} + +finish_test diff --git a/test/fts3query.test b/test/fts3query.test new file mode 100644 index 0000000..70ee005 --- /dev/null +++ b/test/fts3query.test @@ -0,0 +1,293 @@ +# 2009 December 20 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file contains tests of fts3 queries that have been useful during +# the development process as well as some that have been useful in tracking +# down bugs. They are not focused on any particular functionality. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If this build does not include FTS3, skip the tests in this file. +# +ifcapable !fts3 { finish_test ; return } +source $testdir/malloc_common.tcl +source $testdir/fts3_common.tcl +set DO_MALLOC_TEST 0 + +set testprefix fts3query + +do_test fts3query-1.1 { + execsql { + CREATE VIRTUAL TABLE t1 USING fts3(x); + BEGIN; + INSERT INTO t1 VALUES('The source code for SQLite is in the public'); + } +} {} + +do_select_test fts3query-1.2 { + SELECT * FROM t1; +} {{The source code for SQLite is in the public}} +do_select_test fts3query-1.3 { + SELECT * FROM t1 WHERE t1 MATCH 'sqlite' +} {{The source code for SQLite is in the public}} + +do_test fts3query-1.4 { execsql {COMMIT} } {} + +do_select_test fts3query-1.5 { + SELECT * FROM t1; +} {{The source code for SQLite is in the public}} +do_select_test fts3query-1.6 { + SELECT * FROM t1 WHERE t1 MATCH 'sqlite' +} {{The source code for SQLite is in the public}} + + +set sqlite_fts3_enable_parentheses 1 +do_test fts3query-2.1 { + execsql { + CREATE VIRTUAL TABLE zoink USING fts3; + INSERT INTO zoink VALUES('The apple falls far from the tree'); + } +} {} +do_test fts3query-2.2 { + execsql { + SELECT docid FROM zoink WHERE zoink MATCH '(apple oranges) AND apple' + } +} {} +do_test fts3query-2.3 { + execsql { + SELECT docid FROM zoink WHERE zoink MATCH 'apple AND (oranges apple)' + } +} {} +set sqlite_fts3_enable_parentheses 0 + +do_test fts3query-3.1 { + execsql { + CREATE VIRTUAL TABLE foobar using FTS3(description, tokenize porter); + INSERT INTO foobar (description) values (' + Filed under: Emerging Technologies, EV/Plug-in, Hybrid, Chevrolet, GM, + ZENN 2011 Chevy Volt - Click above for high-res image gallery There are + 16 days left in the month of December. Besides being time for most + Americans to kick their Christmas shopping sessions into high gear and + start planning their resolutions for 2010, it also means that there''s + precious little time for EEStor to "deliver functional technology" to + Zenn Motors as promised. Still, the promises held out by the secretive + company are too great for us to forget about entirely. We''d love for + EEStor''s claims to be independently verified and proven accurate, as + would just about anyone else looking to break free of petroleum in fav + '); + } +} {} + +do_test fts3query-3.2 { + execsql { SELECT docid FROM foobar WHERE description MATCH '"high sp d"' } +} {} + +proc mit {blob} { + set scan(littleEndian) i* + set scan(bigEndian) I* + binary scan $blob $scan($::tcl_platform(byteOrder)) r + return $r +} +db func mit mit + +do_test fts3query-3.3 { + execsql { SELECT mit(matchinfo(foobar)) FROM foobar WHERE foobar MATCH 'the' } +} {{1 1 3 3 1}} + +# The following tests check that ticket 775b39dd3c has been fixed. +# +do_test fts3query-4.1 { + execsql { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(number INTEGER PRIMARY KEY, date); + CREATE INDEX i1 ON t1(date); + CREATE VIRTUAL TABLE ft USING fts3(title); + CREATE TABLE bt(title); + } +} {} +do_eqp_test fts3query-4.2 { + SELECT t1.number FROM t1, ft WHERE t1.number=ft.rowid ORDER BY t1.date +} { + QUERY PLAN + |--SCAN t1 USING COVERING INDEX i1 + `--SCAN ft VIRTUAL TABLE INDEX 1: +} +do_eqp_test fts3query-4.3 { + SELECT t1.number FROM ft, t1 WHERE t1.number=ft.rowid ORDER BY t1.date +} { + QUERY PLAN + |--SCAN t1 USING COVERING INDEX i1 + `--SCAN ft VIRTUAL TABLE INDEX 1: +} +do_eqp_test fts3query-4.4 { + SELECT t1.number FROM t1, bt WHERE t1.number=bt.rowid ORDER BY t1.date +} { + QUERY PLAN + |--SCAN t1 USING COVERING INDEX i1 + `--SEARCH bt USING INTEGER PRIMARY KEY (rowid=?) +} +do_eqp_test fts3query-4.5 { + SELECT t1.number FROM bt, t1 WHERE t1.number=bt.rowid ORDER BY t1.date +} { + QUERY PLAN + |--SCAN t1 USING COVERING INDEX i1 + `--SEARCH bt USING INTEGER PRIMARY KEY (rowid=?) +} + + +# Test that calling matchinfo() with the wrong number of arguments, or with +# an invalid argument returns an error. +# +do_execsql_test 5.1 { + CREATE VIRTUAL TABLE t2 USING FTS4; + INSERT INTO t2 VALUES('it was the first time in history'); +} +do_select_tests 5.2 -errorformat { + wrong number of arguments to function %s() +} { + 1 "SELECT matchinfo() FROM t2 WHERE t2 MATCH 'history'" matchinfo + 3 "SELECT snippet(t2, 1, 2, 3, 4, 5, 6) FROM t2 WHERE t2 MATCH 'history'" + snippet +} +do_select_tests 5.3 -errorformat { + illegal first argument to %s +} { + 1 "SELECT matchinfo(content) FROM t2 WHERE t2 MATCH 'history'" matchinfo + 2 "SELECT offsets(content) FROM t2 WHERE t2 MATCH 'history'" offsets + 3 "SELECT snippet(content) FROM t2 WHERE t2 MATCH 'history'" snippet + 4 "SELECT optimize(content) FROM t2 WHERE t2 MATCH 'history'" optimize +} +sqlite3_db_config db DEFENSIVE 0 +do_execsql_test 5.4.0 { UPDATE t2_content SET c0content = X'1234' } +do_select_tests 5.4 -errorformat { + illegal first argument to %s +} { + 1 "SELECT matchinfo(content) FROM t2 WHERE t2 MATCH 'history'" matchinfo + 2 "SELECT offsets(content) FROM t2 WHERE t2 MATCH 'history'" offsets + 3 "SELECT snippet(content) FROM t2 WHERE t2 MATCH 'history'" snippet + 4 "SELECT optimize(content) FROM t2 WHERE t2 MATCH 'history'" optimize +} +do_catchsql_test 5.5.1 { + SELECT matchinfo(t2, 'abcd') FROM t2 WHERE t2 MATCH 'history' +} {1 {unrecognized matchinfo request: d}} + +do_execsql_test 5.5 { DROP TABLE t2 } + + +# Test the snippet() function with 1 to 6 arguments. +# +do_execsql_test 6.1 { + CREATE VIRTUAL TABLE t3 USING FTS4(a, b); + INSERT INTO t3 VALUES('no gestures', 'another intriguing discovery by observing the hand gestures (called beats) people make while speaking. Research has shown that such gestures do more than add visual emphasis to our words (many people gesture while they''re on the telephone, for example); it seems they actually help our brains find words'); +} +do_select_tests 6.2 { + 1 "SELECT snippet(t3) FROM t3 WHERE t3 MATCH 'gestures'" + {{...hand gestures (called beats) people make while speaking. Research has shown that such gestures do...}} + + 2 "SELECT snippet(t3, 'XXX') FROM t3 WHERE t3 MATCH 'gestures'" + {{...hand XXXgestures (called beats) people make while speaking. Research has shown that such XXXgestures do...}} + + 3 "SELECT snippet(t3, 'XXX', 'YYY') FROM t3 WHERE t3 MATCH 'gestures'" + {{...hand XXXgesturesYYY (called beats) people make while speaking. Research has shown that such XXXgesturesYYY do...}} + + 4 "SELECT snippet(t3, 'XXX', 'YYY', 'ZZZ') FROM t3 WHERE t3 MATCH 'gestures'" + {{ZZZhand XXXgesturesYYY (called beats) people make while speaking. Research has shown that such XXXgesturesYYY doZZZ}} + + 5 "SELECT snippet(t3, 'XXX', 'YYY', 'ZZZ', 1) FROM t3 WHERE t3 MATCH 'gestures'" + {{ZZZhand XXXgesturesYYY (called beats) people make while speaking. Research has shown that such XXXgesturesYYY doZZZ}} + + 6 "SELECT snippet(t3, 'XXX', 'YYY', 'ZZZ', 0) FROM t3 WHERE t3 MATCH 'gestures'" + {{no XXXgesturesYYY}} + + 7 "SELECT snippet(t3, 'XXX', 'YYY', 'ZZZ', 1, 5) FROM t3 WHERE t3 MATCH 'gestures'" + {{ZZZthe hand XXXgesturesYYY (called beatsZZZ}} +} + +# Test some range queries on the rowid field. +# +do_execsql_test 7.1 { + CREATE VIRTUAL TABLE ft4 USING fts4(x); + CREATE TABLE t4(x); +} + +set SMALLINT -9223372036854775808 +set LARGEINT 9223372036854775807 +do_test 7.2 { + db transaction { + foreach {iFirst nEntry} [subst { + 0 100 + $SMALLINT 100 + [expr $LARGEINT - 99] 100 + }] { + for {set i 0} {$i < $nEntry} {incr i} { + set iRowid [expr $i + $iFirst] + execsql { + INSERT INTO ft4(rowid, x) VALUES($iRowid, 'x y z'); + INSERT INTO t4(rowid, x) VALUES($iRowid, 'x y z'); + } + } + } + } +} {} + +foreach {tn iFirst iLast} [subst { + 1 5 10 + 2 $SMALLINT [expr $SMALLINT+5] + 3 $SMALLINT [expr $SMALLINT+50] + 4 [expr $LARGEINT-5] $LARGEINT + 5 $LARGEINT $LARGEINT + 6 $SMALLINT $LARGEINT + 7 $SMALLINT $SMALLINT + 8 $LARGEINT $SMALLINT +}] { + set res [db eval { + SELECT rowid FROM t4 WHERE rowid BETWEEN $iFirst AND $iLast + } ] + + do_execsql_test 7.2.$tn.1.[llength $res] { + SELECT rowid FROM ft4 WHERE rowid BETWEEN $iFirst AND $iLast + } $res + set res [db eval { + SELECT rowid FROM t4 WHERE rowid BETWEEN $iFirst AND $iLast + ORDER BY +rowid DESC + } ] + do_execsql_test 7.2.$tn.2.[llength $res] { + SELECT rowid FROM ft4 WHERE rowid BETWEEN $iFirst AND $iLast + ORDER BY rowid DESC + } $res +} + +foreach ii [db eval {SELECT rowid FROM t4}] { + set res1 [db eval {SELECT rowid FROM t4 WHERE rowid > $ii}] + set res2 [db eval {SELECT rowid FROM t4 WHERE rowid < $ii}] + set res1s [db eval {SELECT rowid FROM t4 WHERE rowid > $ii ORDER BY +rowid DESC}] + set res2s [db eval {SELECT rowid FROM t4 WHERE rowid < $ii ORDER BY +rowid DESC}] + + do_execsql_test 7.3.$ii.1 { + SELECT rowid FROM ft4 WHERE rowid > $ii + } $res1 + + do_execsql_test 7.3.$ii.2 { + SELECT rowid FROM ft4 WHERE rowid < $ii + } $res2 + + do_execsql_test 7.3.$ii.3 { + SELECT rowid FROM ft4 WHERE rowid > $ii ORDER BY rowid DESC + } $res1s + + do_execsql_test 7.3.$ii.4 { + SELECT rowid FROM ft4 WHERE rowid < $ii ORDER BY rowid DESC + } $res2s +} + +finish_test diff --git a/test/fts3rank.test b/test/fts3rank.test new file mode 100644 index 0000000..fd1a1c8 --- /dev/null +++ b/test/fts3rank.test @@ -0,0 +1,69 @@ +# 2017 October 7 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS3 module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts3rank + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +install_fts3_rank_function db +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t1 USING fts3(a, b); + INSERT INTO t1 VALUES('one two', 'one'); + INSERT INTO t1 VALUES('one two', 'three'); + INSERT INTO t1 VALUES('one two', 'two'); +} + +do_execsql_test 1.1 { + SELECT * FROM t1 WHERE t1 MATCH 'one' + ORDER BY rank(matchinfo(t1), 1.0, 1.0) DESC, rowid +} { + {one two} one + {one two} three + {one two} two +} + +do_execsql_test 1.2 { + SELECT * FROM t1 WHERE t1 MATCH 'two' + ORDER BY rank(matchinfo(t1), 1.0, 1.0) DESC, rowid +} { + {one two} two + {one two} one + {one two} three +} + +do_catchsql_test 1.3 { + SELECT * FROM t1 ORDER BY rank(matchinfo(t1), 1.0, 1.0) DESC, rowid +} {1 {invalid matchinfo blob passed to function rank()}} + +do_catchsql_test 1.4 { + SELECT * FROM t1 ORDER BY rank(x'0000000000000000') DESC, rowid +} {0 {{one two} one {one two} three {one two} two}} + +if {$tcl_platform(byteOrder)=="littleEndian"} { + do_catchsql_test 1.5le { + SELECT * FROM t1 ORDER BY rank(x'0100000001000000') DESC, rowid + } {1 {invalid matchinfo blob passed to function rank()}} +} else { + do_catchsql_test 1.5be { + SELECT * FROM t1 ORDER BY rank(x'0000000100000001') DESC, rowid + } {1 {invalid matchinfo blob passed to function rank()}} +} + +finish_test diff --git a/test/fts3rnd.test b/test/fts3rnd.test new file mode 100644 index 0000000..97af549 --- /dev/null +++ b/test/fts3rnd.test @@ -0,0 +1,460 @@ +# 2009 December 03 +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Brute force (random data) tests for FTS3. +# + +#------------------------------------------------------------------------- +# +# The FTS3 tests implemented in this file focus on testing that FTS3 +# returns the correct set of documents for various types of full-text +# query. This is done using pseudo-randomly generated data and queries. +# The expected result of each query is calculated using Tcl code. +# +# 1. The database is initialized to contain a single table with three +# columns. 100 rows are inserted into the table. Each of the three +# values in each row is a document consisting of between 0 and 100 +# terms. Terms are selected from a vocabulary of $G(nVocab) terms. +# +# 2. The following is performed 100 times: +# +# a. A row is inserted into the database. The row contents are +# generated as in step 1. The docid is a pseudo-randomly selected +# value between 0 and 1000000. +# +# b. A psuedo-randomly selected row is updated. One of its columns is +# set to contain a new document generated in the same way as the +# documents in step 1. +# +# c. A psuedo-randomly selected row is deleted. +# +# d. For each of several types of fts3 queries, 10 SELECT queries +# of the form: +# +# SELECT docid FROM WHERE MATCH '' +# +# are evaluated. The results are compared to those calculated by +# Tcl code in this file. The patterns used for the different query +# types are: +# +# 1. query = +# 2. query = +# 3. query = " " +# 4. query = " " +# 5. query = " " +# 6. query = NEAR +# 7. query = NEAR/11 NEAR/11 +# 8. query = OR +# 9. query = NOT +# 10. query = AND +# 11. query = NEAR OR NEAR +# 12. query = NEAR NOT NEAR +# 13. query = NEAR AND NEAR +# +# where is a term psuedo-randomly selected from the vocabulary +# and prefix is the first 2 characters of such a term followed by +# a "*" character. +# +# Every second iteration, steps (a) through (d) above are performed +# within a single transaction. This forces the queries in (d) to +# read data from both the database and the in-memory hash table +# that caches the full-text index entries created by steps (a), (b) +# and (c) until the transaction is committed. +# +# The procedure above is run 5 times, using advisory fts3 node sizes of 50, +# 500, 1000 and 2000 bytes. +# +# After the test using an advisory node-size of 50, an OOM test is run using +# the database. This test is similar to step (d) above, except that it tests +# the effects of transient and persistent OOM conditions encountered while +# executing each query. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If this build does not include FTS3, skip the tests in this file. +# +ifcapable !fts3 { finish_test ; return } +source $testdir/fts3_common.tcl +source $testdir/malloc_common.tcl + +set G(nVocab) 100 + +set nVocab 100 +set lVocab [list] + +expr srand(0) + +# Generate a vocabulary of nVocab words. Each word is 3 characters long. +# +set lChar {a b c d e f g h i j k l m n o p q r s t u v w x y z} +for {set i 0} {$i < $nVocab} {incr i} { + set len [expr int(rand()*3)+2] + set word [lindex $lChar [expr int(rand()*26)]] + append word [lindex $lChar [expr int(rand()*26)]] + if {$len>2} { append word [lindex $lChar [expr int(rand()*26)]] } + if {$len>3} { append word [lindex $lChar [expr int(rand()*26)]] } + lappend lVocab $word +} + +proc random_term {} { + lindex $::lVocab [expr {int(rand()*$::nVocab)}] +} + +# Return a document consisting of $nWord arbitrarily selected terms +# from the $::lVocab list. +# +proc generate_doc {nWord} { + set doc [list] + for {set i 0} {$i < $nWord} {incr i} { + lappend doc [random_term] + } + return $doc +} + + + +# Primitives to update the table. +# +unset -nocomplain t1 +proc insert_row {rowid} { + set a [generate_doc [expr int((rand()*100))]] + set b [generate_doc [expr int((rand()*100))]] + set c [generate_doc [expr int((rand()*100))]] + execsql { INSERT INTO t1(docid, a, b, c) VALUES($rowid, $a, $b, $c) } + set ::t1($rowid) [list $a $b $c] +} +proc delete_row {rowid} { + execsql { DELETE FROM t1 WHERE rowid = $rowid } + catch {unset ::t1($rowid)} +} +proc update_row {rowid} { + set cols {a b c} + set iCol [expr int(rand()*3)] + set doc [generate_doc [expr int((rand()*100))]] + lset ::t1($rowid) $iCol $doc + execsql "UPDATE t1 SET [lindex $cols $iCol] = \$doc WHERE rowid = \$rowid" +} + +proc simple_phrase {zPrefix} { + set ret [list] + + set reg [string map {* {[^ ]*}} $zPrefix] + set reg " $reg " + + foreach key [lsort -integer [array names ::t1]] { + set value $::t1($key) + set cnt [list] + foreach col $value { + if {[regexp $reg " $col "]} { lappend ret $key ; break } + } + } + + #lsort -uniq -integer $ret + set ret +} + +# This [proc] is used to test the FTS3 matchinfo() function. +# +proc simple_token_matchinfo {zToken bDesc} { + + set nDoc(0) 0 + set nDoc(1) 0 + set nDoc(2) 0 + set nHit(0) 0 + set nHit(1) 0 + set nHit(2) 0 + + set dir -inc + if {$bDesc} { set dir -dec } + + foreach key [array names ::t1] { + set value $::t1($key) + set a($key) [list] + foreach i {0 1 2} col $value { + set hit [llength [lsearch -all $col $zToken]] + lappend a($key) $hit + incr nHit($i) $hit + if {$hit>0} { incr nDoc($i) } + } + } + + set ret [list] + foreach docid [lsort -integer $dir [array names a]] { + if { [lindex [lsort -integer $a($docid)] end] } { + set matchinfo [list 1 3] + foreach i {0 1 2} hit $a($docid) { + lappend matchinfo $hit $nHit($i) $nDoc($i) + } + lappend ret $docid $matchinfo + } + } + + set ret +} + +proc simple_near {termlist nNear} { + set ret [list] + + foreach {key value} [array get ::t1] { + foreach v $value { + + set l [lsearch -exact -all $v [lindex $termlist 0]] + foreach T [lrange $termlist 1 end] { + set l2 [list] + foreach i $l { + set iStart [expr $i - $nNear - 1] + set iEnd [expr $i + $nNear + 1] + if {$iStart < 0} {set iStart 0} + foreach i2 [lsearch -exact -all [lrange $v $iStart $iEnd] $T] { + incr i2 $iStart + if {$i2 != $i} { lappend l2 $i2 } + } + } + set l [lsort -uniq -integer $l2] + } + + if {[llength $l]} { +#puts "MATCH($key): $v" + lappend ret $key + } + } + } + + lsort -unique -integer $ret +} + +# The following three procs: +# +# setup_not A B +# setup_or A B +# setup_and A B +# +# each take two arguments. Both arguments must be lists of integer values +# sorted by value. The return value is the list produced by evaluating +# the equivalent of "A op B", where op is the FTS3 operator NOT, OR or +# AND. +# +proc setop_not {A B} { + foreach b $B { set n($b) {} } + set ret [list] + foreach a $A { if {![info exists n($a)]} {lappend ret $a} } + return $ret +} +proc setop_or {A B} { + lsort -integer -uniq [concat $A $B] +} +proc setop_and {A B} { + foreach b $B { set n($b) {} } + set ret [list] + foreach a $A { if {[info exists n($a)]} {lappend ret $a} } + return $ret +} + +proc mit {blob} { + set scan(littleEndian) i* + set scan(bigEndian) I* + binary scan $blob $scan($::tcl_platform(byteOrder)) r + return $r +} +db func mit mit +set sqlite_fts3_enable_parentheses 1 + +proc do_orderbydocid_test {tn sql res} { + uplevel [list do_select_test $tn.asc "$sql ORDER BY docid ASC" $res] + uplevel [list do_select_test $tn.desc "$sql ORDER BY docid DESC" \ + [lsort -int -dec $res] + ] +} + +set NUM_TRIALS 100 + +foreach {nodesize order} { + 50 DESC + 50 ASC + 500 ASC + 1000 DESC + 2000 ASC +} { + catch { array unset ::t1 } + set testname "$nodesize/$order" + + # Create the FTS3 table. Populate it (and the Tcl array) with 100 rows. + # + db transaction { + catchsql { DROP TABLE t1 } + execsql "CREATE VIRTUAL TABLE t1 USING fts4(a, b, c, order=$order)" + execsql "INSERT INTO t1(t1) VALUES('nodesize=$nodesize')" + for {set i 0} {$i < 100} {incr i} { insert_row $i } + } + + for {set iTest 1} {$iTest <= $NUM_TRIALS} {incr iTest} { + catchsql COMMIT + + set DO_MALLOC_TEST 0 + set nRep 10 + if {$iTest==100 && $nodesize==50} { + set DO_MALLOC_TEST 1 + set nRep 2 + } + + set ::testprefix fts3rnd-1.$testname.$iTest + + # Delete one row, update one row and insert one row. + # + set rows [array names ::t1] + set nRow [llength $rows] + set iUpdate [lindex $rows [expr {int(rand()*$nRow)}]] + set iDelete $iUpdate + while {$iDelete == $iUpdate} { + set iDelete [lindex $rows [expr {int(rand()*$nRow)}]] + } + set iInsert $iUpdate + while {[info exists ::t1($iInsert)]} { + set iInsert [expr {int(rand()*1000000)}] + } + execsql BEGIN + insert_row $iInsert + update_row $iUpdate + delete_row $iDelete + if {0==($iTest%2)} { execsql COMMIT } + + if {0==($iTest%2)} { + #do_test 0 { fts3_integrity_check t1 } ok + } + + # Pick 10 terms from the vocabulary. Check that the results of querying + # the database for the set of documents containing each of these terms + # is the same as the result obtained by scanning the contents of the Tcl + # array for each term. + # + for {set i 0} {$i < 10} {incr i} { + set term [random_term] + do_select_test 1.$i.asc { + SELECT docid, mit(matchinfo(t1)) FROM t1 WHERE t1 MATCH $term + ORDER BY docid ASC + } [simple_token_matchinfo $term 0] + do_select_test 1.$i.desc { + SELECT docid, mit(matchinfo(t1)) FROM t1 WHERE t1 MATCH $term + ORDER BY docid DESC + } [simple_token_matchinfo $term 1] + } + + # This time, use the first two characters of each term as a term prefix + # to query for. Test that querying the Tcl array produces the same results + # as querying the FTS3 table for the prefix. + # + for {set i 0} {$i < $nRep} {incr i} { + set prefix [string range [random_term] 0 end-1] + set match "${prefix}*" + do_orderbydocid_test 2.$i { + SELECT docid FROM t1 WHERE t1 MATCH $match + } [simple_phrase $match] + } + + # Similar to the above, except for phrase queries. + # + for {set i 0} {$i < $nRep} {incr i} { + set term [list [random_term] [random_term]] + set match "\"$term\"" + do_orderbydocid_test 3.$i { + SELECT docid FROM t1 WHERE t1 MATCH $match + } [simple_phrase $term] + } + + # Three word phrases. + # + for {set i 0} {$i < $nRep} {incr i} { + set term [list [random_term] [random_term] [random_term]] + set match "\"$term\"" + do_orderbydocid_test 4.$i { + SELECT docid FROM t1 WHERE t1 MATCH $match + } [simple_phrase $term] + } + + # Three word phrases made up of term-prefixes. + # + for {set i 0} {$i < $nRep} {incr i} { + set query "[string range [random_term] 0 end-1]* " + append query "[string range [random_term] 0 end-1]* " + append query "[string range [random_term] 0 end-1]*" + + set match "\"$query\"" + do_orderbydocid_test 5.$i { + SELECT docid FROM t1 WHERE t1 MATCH $match + } [simple_phrase $query] + } + + # A NEAR query with terms as the arguments: + # + # ... MATCH '$term1 NEAR $term2' ... + # + for {set i 0} {$i < $nRep} {incr i} { + set terms [list [random_term] [random_term]] + set match [join $terms " NEAR "] + do_orderbydocid_test 6.$i { + SELECT docid FROM t1 WHERE t1 MATCH $match + } [simple_near $terms 10] + } + + # A 3-way NEAR query with terms as the arguments. + # + for {set i 0} {$i < $nRep} {incr i} { + set terms [list [random_term] [random_term] [random_term]] + set nNear 11 + set match [join $terms " NEAR/$nNear "] + do_orderbydocid_test 7.$i { + SELECT docid FROM t1 WHERE t1 MATCH $match + } [simple_near $terms $nNear] + } + + # Set operations on simple term queries. + # + foreach {tn op proc} { + 8 OR setop_or + 9 NOT setop_not + 10 AND setop_and + } { + for {set i 0} {$i < $nRep} {incr i} { + set term1 [random_term] + set term2 [random_term] + set match "$term1 $op $term2" + do_orderbydocid_test $tn.$i { + SELECT docid FROM t1 WHERE t1 MATCH $match + } [$proc [simple_phrase $term1] [simple_phrase $term2]] + } + } + + # Set operations on NEAR queries. + # + foreach {tn op proc} { + 11 OR setop_or + 12 NOT setop_not + 13 AND setop_and + } { + for {set i 0} {$i < $nRep} {incr i} { + set term1 [random_term] + set term2 [random_term] + set term3 [random_term] + set term4 [random_term] + set match "$term1 NEAR $term2 $op $term3 NEAR $term4" + do_orderbydocid_test $tn.$i { + SELECT docid FROM t1 WHERE t1 MATCH $match + } [$proc \ + [simple_near [list $term1 $term2] 10] \ + [simple_near [list $term3 $term4] 10] + ] + } + } + + catchsql COMMIT + } +} + +finish_test diff --git a/test/fts3shared.test b/test/fts3shared.test new file mode 100644 index 0000000..0943c05 --- /dev/null +++ b/test/fts3shared.test @@ -0,0 +1,176 @@ +# +# 2010 September 17 +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is the interactions between the FTS3/4 module +# and shared-cache mode. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !fts3||!shared_cache { + finish_test + return +} +set ::testprefix fts3shared + +db close +set ::enable_shared_cache [sqlite3_enable_shared_cache 1] + +# Open two connections to the database in shared-cache mode. +# +sqlite3 db test.db +sqlite3 db2 test.db + +# Create a virtual FTS3 table. Populate it with some initial data. +# +do_execsql_test fts3shared-1.1 { + CREATE VIRTUAL TABLE t1 USING fts3(x); + BEGIN; + INSERT INTO t1 VALUES('We listened and looked sideways up!'); + INSERT INTO t1 VALUES('Fear at my heart, as at a cup,'); + INSERT INTO t1 VALUES('My life-blood seemed to sip!'); + INSERT INTO t1 VALUES('The stars were dim, and thick the night'); + COMMIT; +} {} + +# Open a write transaction and insert rows into the FTS3 table. This takes +# a write-lock on the underlying t1_content table. +# +do_execsql_test fts3shared-1.2 { + BEGIN; + INSERT INTO t1 VALUES('The steersman''s face by his lamp gleamed white;'); +} {} + +# Now try a SELECT on the full-text table. This particular SELECT does not +# read data from the %_content table. But it still attempts to obtain a lock +# on that table and so the SELECT fails. +# +do_test fts3shared-1.3 { + catchsql { + BEGIN; + SELECT rowid FROM t1 WHERE t1 MATCH 'stars' + } db2 +} {1 {database table is locked}} + +# Verify that the first connection can commit its transaction. +# +do_test fts3shared-1.4 { sqlite3_get_autocommit db } 0 +do_execsql_test fts3shared-1.5 { COMMIT } {} +do_test fts3shared-1.6 { sqlite3_get_autocommit db } 1 + +# Verify that the second connection still has an open transaction. +# +do_test fts3shared-1.6 { sqlite3_get_autocommit db2 } 0 + +db close +db2 close + +#------------------------------------------------------------------------- +# The following tests - fts3shared-2.* - test that unless FTS is bypassed +# and the underlying tables accessed directly, it is not possible for an +# SQLITE_LOCKED error to be enountered when committing an FTS transaction. +# +# Any SQLITE_LOCKED error should be returned when the fts4 (or fts4aux) +# table is first read/written within a transaction, not later on. +# +set LOCKED {1 {database table is locked}} +forcedelete test.db +sqlite3 dbR test.db +sqlite3 dbW test.db +do_test 2.1 { + execsql { + CREATE VIRTUAL TABLE t1 USING fts4; + CREATE TABLE t2ext(a, b); + CREATE VIRTUAL TABLE t2 USING fts4(content=t2ext); + CREATE VIRTUAL TABLE t1aux USING fts4aux(t1); + CREATE VIRTUAL TABLE t2aux USING fts4aux(t2); + + INSERT INTO t1 VALUES('a b c'); + INSERT INTO t2(rowid, a, b) VALUES(1, 'd e f', 'g h i'); + } dbW +} {} + +# Test that once [dbW] has written to the FTS table, no client may read +# from the FTS or fts4aux table. +do_test 2.2.1 { + execsql { + BEGIN; + INSERT INTO t1 VALUES('j k l'); + } dbW + execsql BEGIN dbR +} {} +do_test 2.2.2 { catchsql "SELECT * FROM t1 WHERE rowid=1" dbR } $LOCKED +do_test 2.2.3 { catchsql "SELECT * FROM t1 WHERE t1 MATCH 'a'" dbR } $LOCKED +do_test 2.2.4 { catchsql "SELECT rowid FROM t1 WHERE t1 MATCH 'a'" dbR } $LOCKED +do_test 2.2.5 { catchsql "SELECT * FROM t1" dbR } $LOCKED +do_test 2.2.6 { catchsql "SELECT * FROM t1aux" dbR } $LOCKED +do_test 2.2.7 { execsql COMMIT dbW } {} +do_test 2.2.8 { execsql COMMIT dbR } {} + +# Same test as 2.2.*, except with a content= table. +# +do_test 2.3.1 { + execsql { + BEGIN; + INSERT INTO t2(rowid, a, b) VALUES(2, 'j k l', 'm n o'); + } dbW + execsql BEGIN dbR +} {} +do_test 2.3.3 { catchsql "SELECT * FROM t2 WHERE t2 MATCH 'a'" dbR } $LOCKED +do_test 2.3.4 { catchsql "SELECT rowid FROM t2 WHERE t2 MATCH 'a'" dbR } $LOCKED +do_test 2.3.6 { catchsql "SELECT * FROM t2aux" dbR } $LOCKED +do_test 2.3.7 { execsql COMMIT dbW } {} +do_test 2.3.8 { execsql COMMIT dbR } {} + +# Test that once a connection has read from the FTS or fts4aux table, +# another connection may not write to the FTS table. +# +foreach {tn sql} { + 1 "SELECT * FROM t1 WHERE rowid=1" + 2 "SELECT * FROM t1 WHERE t1 MATCH 'a'" + 3 "SELECT rowid FROM t1 WHERE t1 MATCH 'a'" + 4 "SELECT * FROM t1" + 5 "SELECT * FROM t1aux" +} { + + do_test 2.4.$tn { + execsql BEGIN dbR + execsql $::sql dbR + execsql BEGIN dbW + catchsql "INSERT INTO t1 VALUES('p q r')" dbW + } $LOCKED + + execsql ROLLBACK dbR + execsql ROLLBACK dbW +} + +# Same test as 2.4.*, except with a content= table. +# +foreach {tn sql} { + 2 "SELECT * FROM t2 WHERE t2 MATCH 'a'" + 3 "SELECT rowid FROM t2 WHERE t2 MATCH 'a'" + 5 "SELECT * FROM t2aux" +} { + + do_test 2.5.$tn { + execsql BEGIN dbR + execsql $::sql dbR + execsql BEGIN dbW + catchsql "INSERT INTO t2(rowid, a, b) VALUES(3, 's t u', 'v w x')" dbW + } $LOCKED + + execsql ROLLBACK dbR + execsql ROLLBACK dbW +} + +dbW close +dbR close +sqlite3_enable_shared_cache $::enable_shared_cache +finish_test diff --git a/test/fts3snippet.test b/test/fts3snippet.test new file mode 100644 index 0000000..ae022b6 --- /dev/null +++ b/test/fts3snippet.test @@ -0,0 +1,592 @@ +# 2010 January 07 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# +# The tests in this file test the FTS3 auxillary functions offsets(), +# snippet() and matchinfo() work. At time of writing, running this file +# provides full coverage of fts3_snippet.c. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts3snippet + +# If SQLITE_ENABLE_FTS3 is not defined, omit this file. +ifcapable !fts3 { finish_test ; return } +source $testdir/fts3_common.tcl + +set sqlite_fts3_enable_parentheses 1 +set DO_MALLOC_TEST 0 + +# Transform the list $L to its "normal" form. So that it can be compared to +# another list with the same set of elements using [string compare]. +# +proc normalize {L} { + set ret [list] + foreach l $L {lappend ret $l} + return $ret +} + +proc do_offsets_test {name expr args} { + set result [list] + foreach a $args { + lappend result [normalize $a] + } + do_select_test $name { + SELECT offsets(ft) FROM ft WHERE ft MATCH $expr + } $result +} + +# Document text used by a few tests. Contains the English names of all +# integers between 1 and 300. +# +set numbers [normalize { + one two three four five six seven eight nine ten eleven twelve thirteen + fourteen fifteen sixteen seventeen eighteen nineteen twenty twentyone + twentytwo twentythree twentyfour twentyfive twentysix twentyseven + twentyeight twentynine thirty thirtyone thirtytwo thirtythree thirtyfour + thirtyfive thirtysix thirtyseven thirtyeight thirtynine forty fortyone + fortytwo fortythree fortyfour fortyfive fortysix fortyseven fortyeight + fortynine fifty fiftyone fiftytwo fiftythree fiftyfour fiftyfive fiftysix + fiftyseven fiftyeight fiftynine sixty sixtyone sixtytwo sixtythree sixtyfour + sixtyfive sixtysix sixtyseven sixtyeight sixtynine seventy seventyone + seventytwo seventythree seventyfour seventyfive seventysix seventyseven + seventyeight seventynine eighty eightyone eightytwo eightythree eightyfour + eightyfive eightysix eightyseven eightyeight eightynine ninety ninetyone + ninetytwo ninetythree ninetyfour ninetyfive ninetysix ninetyseven + ninetyeight ninetynine onehundred onehundredone onehundredtwo + onehundredthree onehundredfour onehundredfive onehundredsix onehundredseven + onehundredeight onehundrednine onehundredten onehundredeleven + onehundredtwelve onehundredthirteen onehundredfourteen onehundredfifteen + onehundredsixteen onehundredseventeen onehundredeighteen onehundrednineteen + onehundredtwenty onehundredtwentyone onehundredtwentytwo + onehundredtwentythree onehundredtwentyfour onehundredtwentyfive + onehundredtwentysix onehundredtwentyseven onehundredtwentyeight + onehundredtwentynine onehundredthirty onehundredthirtyone + onehundredthirtytwo onehundredthirtythree onehundredthirtyfour + onehundredthirtyfive onehundredthirtysix onehundredthirtyseven + onehundredthirtyeight onehundredthirtynine onehundredforty + onehundredfortyone onehundredfortytwo onehundredfortythree + onehundredfortyfour onehundredfortyfive onehundredfortysix + onehundredfortyseven onehundredfortyeight onehundredfortynine + onehundredfifty onehundredfiftyone onehundredfiftytwo onehundredfiftythree + onehundredfiftyfour onehundredfiftyfive onehundredfiftysix + onehundredfiftyseven onehundredfiftyeight onehundredfiftynine + onehundredsixty onehundredsixtyone onehundredsixtytwo onehundredsixtythree + onehundredsixtyfour onehundredsixtyfive onehundredsixtysix + onehundredsixtyseven onehundredsixtyeight onehundredsixtynine + onehundredseventy onehundredseventyone onehundredseventytwo + onehundredseventythree onehundredseventyfour onehundredseventyfive + onehundredseventysix onehundredseventyseven onehundredseventyeight + onehundredseventynine onehundredeighty onehundredeightyone + onehundredeightytwo onehundredeightythree onehundredeightyfour + onehundredeightyfive onehundredeightysix onehundredeightyseven + onehundredeightyeight onehundredeightynine onehundredninety + onehundredninetyone onehundredninetytwo onehundredninetythree + onehundredninetyfour onehundredninetyfive onehundredninetysix + onehundredninetyseven onehundredninetyeight onehundredninetynine twohundred + twohundredone twohundredtwo twohundredthree twohundredfour twohundredfive + twohundredsix twohundredseven twohundredeight twohundrednine twohundredten + twohundredeleven twohundredtwelve twohundredthirteen twohundredfourteen + twohundredfifteen twohundredsixteen twohundredseventeen twohundredeighteen + twohundrednineteen twohundredtwenty twohundredtwentyone twohundredtwentytwo + twohundredtwentythree twohundredtwentyfour twohundredtwentyfive + twohundredtwentysix twohundredtwentyseven twohundredtwentyeight + twohundredtwentynine twohundredthirty twohundredthirtyone + twohundredthirtytwo twohundredthirtythree twohundredthirtyfour + twohundredthirtyfive twohundredthirtysix twohundredthirtyseven + twohundredthirtyeight twohundredthirtynine twohundredforty + twohundredfortyone twohundredfortytwo twohundredfortythree + twohundredfortyfour twohundredfortyfive twohundredfortysix + twohundredfortyseven twohundredfortyeight twohundredfortynine + twohundredfifty twohundredfiftyone twohundredfiftytwo twohundredfiftythree + twohundredfiftyfour twohundredfiftyfive twohundredfiftysix + twohundredfiftyseven twohundredfiftyeight twohundredfiftynine + twohundredsixty twohundredsixtyone twohundredsixtytwo twohundredsixtythree + twohundredsixtyfour twohundredsixtyfive twohundredsixtysix + twohundredsixtyseven twohundredsixtyeight twohundredsixtynine + twohundredseventy twohundredseventyone twohundredseventytwo + twohundredseventythree twohundredseventyfour twohundredseventyfive + twohundredseventysix twohundredseventyseven twohundredseventyeight + twohundredseventynine twohundredeighty twohundredeightyone + twohundredeightytwo twohundredeightythree twohundredeightyfour + twohundredeightyfive twohundredeightysix twohundredeightyseven + twohundredeightyeight twohundredeightynine twohundredninety + twohundredninetyone twohundredninetytwo twohundredninetythree + twohundredninetyfour twohundredninetyfive twohundredninetysix + twohundredninetyseven twohundredninetyeight twohundredninetynine + threehundred +}] + +foreach {DO_MALLOC_TEST enc} { + 0 utf8 + 1 utf8 + 1 utf16 +} { + + db close + forcedelete test.db + sqlite3 db test.db + sqlite3_db_config_lookaside db 0 0 0 + db eval "PRAGMA encoding = \"$enc\"" + + # Set variable $T to the test name prefix for this iteration of the loop. + # + set T "fts3snippet-1.$enc" + + ########################################################################## + # Test the offset function. + # + do_test $T.1.1 { + execsql { + CREATE VIRTUAL TABLE ft USING fts3; + INSERT INTO ft VALUES('xxx xxx xxx xxx'); + } + } {} + do_offsets_test $T.1.2 {xxx} {0 0 0 3 0 0 4 3 0 0 8 3 0 0 12 3} + do_offsets_test $T.1.3 {"xxx xxx"} { + 0 0 0 3 0 0 4 3 0 1 4 3 0 0 8 3 + 0 1 8 3 0 1 12 3 + } + do_offsets_test $T.1.4 {"xxx xxx" xxx} { + 0 0 0 3 0 2 0 3 0 0 4 3 0 1 4 3 + 0 2 4 3 0 0 8 3 0 1 8 3 0 2 8 3 + 0 1 12 3 0 2 12 3 + } + do_offsets_test $T.1.5 {xxx "xxx xxx"} { + 0 0 0 3 0 1 0 3 0 0 4 3 0 1 4 3 + 0 2 4 3 0 0 8 3 0 1 8 3 0 2 8 3 + 0 0 12 3 0 2 12 3 + } + + do_test $T.2.1 { + set v1 [lrange $numbers 0 99] + execsql { + DROP TABLE IF EXISTS ft; + CREATE VIRTUAL TABLE ft USING fts3(a, b); + INSERT INTO ft VALUES($v1, $numbers); + INSERT INTO ft VALUES($v1, NULL); + } + } {} + + set off [string first "twohundred " $numbers] + do_offsets_test $T.2.1 {twohundred} [list 1 0 $off 10] + + set off [string first "onehundred " $numbers] + do_offsets_test $T.2.2 {onehundred} \ + [list 0 0 $off 10 1 0 $off 10] [list 0 0 $off 10] + + # Test a corruption case: + sqlite3_db_config db DEFENSIVE 0 + execsql { UPDATE ft_content SET c1b = 'hello world' WHERE c1b = $numbers } + do_error_test $T.2.3 { + SELECT offsets(ft) FROM ft WHERE ft MATCH 'onehundred' + } {database disk image is malformed} + + ########################################################################## + # Test the snippet function. + # + proc do_snippet_test {name expr iCol nTok args} { + set res [list] + foreach a $args { lappend res [string trim $a] } + do_select_test $name { + SELECT snippet(ft,'{','}','...',$iCol,$nTok) FROM ft WHERE ft MATCH $expr + } $res + } + do_test $T.3.1 { + execsql { + DROP TABLE IF EXISTS ft; + CREATE VIRTUAL TABLE ft USING fts3; + INSERT INTO ft VALUES('one two three four five six seven eight nine ten'); + } + } {} + do_snippet_test $T.3.2 one 0 5 "{one} two three four five..." + do_snippet_test $T.3.3 two 0 5 "one {two} three four five..." + do_snippet_test $T.3.4 three 0 5 "one two {three} four five..." + do_snippet_test $T.3.5 four 0 5 "...two three {four} five six..." + do_snippet_test $T.3.6 five 0 5 "...three four {five} six seven..." + do_snippet_test $T.3.7 six 0 5 "...four five {six} seven eight..." + do_snippet_test $T.3.8 seven 0 5 "...five six {seven} eight nine..." + do_snippet_test $T.3.9 eight 0 5 "...six seven {eight} nine ten" + do_snippet_test $T.3.10 nine 0 5 "...six seven eight {nine} ten" + do_snippet_test $T.3.11 ten 0 5 "...six seven eight nine {ten}" + + do_test $T.4.1 { + execsql { + INSERT INTO ft VALUES( + 'one two three four five ' + || 'six seven eight nine ten ' + || 'eleven twelve thirteen fourteen fifteen ' + || 'sixteen seventeen eighteen nineteen twenty ' + || 'one two three four five ' + || 'six seven eight nine ten ' + || 'eleven twelve thirteen fourteen fifteen ' + || 'sixteen seventeen eighteen nineteen twenty' + ); + } + } {} + + do_snippet_test $T.4.2 {one nine} 0 5 { + {one} two three...eight {nine} ten + } { + {one} two three...eight {nine} ten... + } + + do_snippet_test $T.4.3 {one nine} 0 -5 { + {one} two three four five...six seven eight {nine} ten + } { + {one} two three four five...seven eight {nine} ten eleven... + } + do_snippet_test $T.4.3 {one nineteen} 0 -5 { + ...eighteen {nineteen} twenty {one} two... + } + do_snippet_test $T.4.4 {two nineteen} 0 -5 { + ...eighteen {nineteen} twenty one {two}... + } + do_snippet_test $T.4.5 {three nineteen} 0 -5 { + ...{nineteen} twenty one two {three}... + } + + do_snippet_test $T.4.6 {four nineteen} 0 -5 { + ...two three {four} five six...seventeen eighteen {nineteen} twenty one... + } + do_snippet_test $T.4.7 {four NEAR nineteen} 0 -5 { + ...seventeen eighteen {nineteen} twenty one...two three {four} five six... + } + + do_snippet_test $T.4.8 {four nineteen} 0 5 { + ...three {four} five...eighteen {nineteen} twenty... + } + do_snippet_test $T.4.9 {four NEAR nineteen} 0 5 { + ...eighteen {nineteen} twenty...three {four} five... + } + do_snippet_test $T.4.10 {four NEAR nineteen} 0 -5 { + ...seventeen eighteen {nineteen} twenty one...two three {four} five six... + } + do_snippet_test $T.4.11 {four NOT (nineteen twentyone)} 0 5 { + ...two three {four} five six... + } { + ...two three {four} five six... + } + do_snippet_test $T.4.12 {four OR nineteen NEAR twentyone} 0 5 { + ...two three {four} five six... + } { + ...two three {four} five six... + } + + do_test $T.5.1 { + execsql { + DROP TABLE IF EXISTS ft; + CREATE VIRTUAL TABLE ft USING fts3(a, b, c); + INSERT INTO ft VALUES( + 'one two three four five', + 'four five six seven eight', + 'seven eight nine ten eleven' + ); + } + } {} + + do_snippet_test $T.5.2 {five} -1 3 {...three four {five}} + do_snippet_test $T.5.3 {five} 0 3 {...three four {five}} + do_snippet_test $T.5.4 {five} 1 3 {four {five} six...} + do_snippet_test $T.5.5 {five} 2 3 {seven eight nine...} + + do_test $T.5.6 { + execsql { UPDATE ft SET b = NULL } + } {} + + do_snippet_test $T.5.7 {five} -1 3 {...three four {five}} + do_snippet_test $T.5.8 {five} 0 3 {...three four {five}} + do_snippet_test $T.5.9 {five} 1 3 {} + do_snippet_test $T.5.10 {five} 2 3 {seven eight nine...} + + do_snippet_test $T.5.11 {one "seven eight nine"} -1 -3 { + {one} two three...{seven} {eight} {nine}... + } + + do_test $T.6.1 { + execsql { + DROP TABLE IF EXISTS ft; + CREATE VIRTUAL TABLE ft USING fts3(x); + INSERT INTO ft VALUES($numbers); + } + } {} + do_snippet_test $T.6.2 { + one fifty onehundred onehundredfifty twohundredfifty threehundred + } -1 4 { + {one}...{fifty}...{onehundred}...{onehundredfifty}... + } + do_snippet_test $T.6.3 { + one fifty onehundred onehundredfifty twohundredfifty threehundred + } -1 -4 { + {one} two three four...fortyeight fortynine {fifty} fiftyone...ninetyeight ninetynine {onehundred} onehundredone...onehundredfortyeight onehundredfortynine {onehundredfifty} onehundredfiftyone... + } + + do_test $T.7.1 { + execsql { + BEGIN; + DROP TABLE IF EXISTS ft; + CREATE VIRTUAL TABLE ft USING fts3(x); + } + set testresults [list] + for {set i 1} {$i < 150} {incr i} { + set commas [string repeat , $i] + execsql {INSERT INTO ft VALUES('one' || $commas || 'two')} + lappend testresults "{one}$commas{two}" + } + execsql COMMIT + } {} + eval [list do_snippet_test $T.7.2 {one two} -1 3] $testresults + + ########################################################################## + # Test the matchinfo function. + # + proc mit {blob} { + set scan(littleEndian) i* + set scan(bigEndian) I* + binary scan $blob $scan($::tcl_platform(byteOrder)) r + return $r + } + db func mit mit + proc do_matchinfo_test {name expr args} { + set res [list] + foreach a $args { lappend res [normalize $a] } + do_select_test $name { + SELECT mit(matchinfo(ft)) FROM ft WHERE ft MATCH $expr + } $res + } + do_test $T.8.1 { + set ten {one two three four five six seven eight nine ten} + execsql { + DROP TABLE IF EXISTS ft; + CREATE VIRTUAL TABLE ft USING fts3; + INSERT INTO ft VALUES($ten); + INSERT INTO ft VALUES($ten || ' ' || $ten); + } + } {} + + do_matchinfo_test $T.8.2 "one" {1 1 1 3 2} {1 1 2 3 2} + do_matchinfo_test $T.8.3 "one NEAR/3 ten" {2 1 1 1 1 1 1 1} + do_matchinfo_test $T.8.4 "five NEAR/4 ten" \ + {2 1 1 3 2 1 3 2} {2 1 2 3 2 2 3 2} + do_matchinfo_test $T.8.5 "six NEAR/3 ten NEAR/3 two" \ + {3 1 1 1 1 1 1 1 1 1 1} + do_matchinfo_test $T.8.6 "five NEAR/4 ten NEAR/3 two" \ + {3 1 2 2 1 1 1 1 1 1 1} + + do_test $T.9.1 { + execsql { + DROP TABLE IF EXISTS ft; + CREATE VIRTUAL TABLE ft USING fts3(x, y); + } + foreach n {1 2 3} { + set v1 [lrange $numbers 0 [expr $n*100]] + set v2 [string trim [string repeat "$numbers " $n]] + set docid [expr $n * 1000000] + execsql { INSERT INTO ft(docid, x, y) VALUES($docid, $v1, $v2) } + } + } {} + do_matchinfo_test $T.9.2 {two*} \ + { 1 2 1 105 3 101 606 3} \ + { 1 2 3 105 3 202 606 3} \ + { 1 2 101 105 3 303 606 3} + + do_matchinfo_test $T.9.4 {"one* two*"} \ + { 1 2 1 5 3 2 12 3} \ + { 1 2 2 5 3 4 12 3} \ + { 1 2 2 5 3 6 12 3} + + do_matchinfo_test $T.9.5 {twohundredfifty} \ + { 1 2 0 1 1 1 6 3} \ + { 1 2 0 1 1 2 6 3} \ + { 1 2 1 1 1 3 6 3} + + do_matchinfo_test $T.9.6 {"threehundred one"} \ + { 1 2 0 0 0 1 3 2} \ + { 1 2 0 0 0 2 3 2} + + do_matchinfo_test $T.9.7 {one OR fivehundred} \ + { 2 2 1 3 3 1 6 3 0 0 0 0 0 0 } \ + { 2 2 1 3 3 2 6 3 0 0 0 0 0 0 } \ + { 2 2 1 3 3 3 6 3 0 0 0 0 0 0 } + + do_matchinfo_test $T.9.8 {two OR "threehundred one"} \ + { 2 2 1 3 3 1 6 3 0 0 0 0 3 2 } \ + { 2 2 1 3 3 2 6 3 0 0 0 1 3 2 } \ + { 2 2 1 3 3 3 6 3 0 0 0 2 3 2 } + + do_select_test $T.9.9 { + SELECT mit(matchinfo(ft)), mit(matchinfo(ft)) + FROM ft WHERE ft MATCH 'two OR "threehundred one"' + } [normalize { + {2 2 1 3 3 1 6 3 0 0 0 0 3 2} + {2 2 1 3 3 1 6 3 0 0 0 0 3 2} + {2 2 1 3 3 2 6 3 0 0 0 1 3 2} + {2 2 1 3 3 2 6 3 0 0 0 1 3 2} + {2 2 1 3 3 3 6 3 0 0 0 2 3 2} + {2 2 1 3 3 3 6 3 0 0 0 2 3 2} + }] + + # EVIDENCE-OF: R-40630-02268 If used within a SELECT that uses the + # "query by rowid" or "linear scan" strategies, then the snippet and + # offsets both return an empty string, and the matchinfo function + # returns a blob value zero bytes in size. + # + set r 1000000 ;# A rowid that exists in table ft + do_select_test $T.10.0 { SELECT rowid FROM ft WHERE rowid = $r } $r + do_select_test $T.10.1 { + SELECT length(offsets(ft)), typeof(offsets(ft)) FROM ft; + } {0 text 0 text 0 text} + do_select_test $T.10.2 { + SELECT length(offsets(ft)), typeof(offsets(ft)) FROM ft WHERE rowid = $r + } {0 text} + do_select_test $T.10.3 { + SELECT length(snippet(ft)), typeof(snippet(ft)) FROM ft; + } {0 text 0 text 0 text} + do_select_test $T.10.4 { + SELECT length(snippet(ft)), typeof(snippet(ft)) FROM ft WHERE rowid = $r; + } {0 text} + do_select_test $T.10.5 { + SELECT length(matchinfo(ft)), typeof(matchinfo(ft)) FROM ft; + } {0 blob 0 blob 0 blob} + do_select_test $T.10.6 { + SELECT length(matchinfo(ft)), typeof(matchinfo(ft)) FROM ft WHERE rowid = $r + } {0 blob} +} + +#------------------------------------------------------------------------- +# Test an interaction between the snippet() function and OR clauses. +# +do_execsql_test 2.1 { + CREATE VIRTUAL TABLE t2 USING fts4; + INSERT INTO t2 VALUES('one two three four five'); + INSERT INTO t2 VALUES('two three four five one'); + INSERT INTO t2 VALUES('three four five one two'); + INSERT INTO t2 VALUES('four five one two three'); + INSERT INTO t2 VALUES('five one two three four'); +} + +do_execsql_test 2.2 { + SELECT snippet(t2, '[', ']') FROM t2 WHERE t2 MATCH 'one OR (four AND six)' +} { + {[one] two three [four] five} + {two three [four] five [one]} + {three [four] five [one] two} + {[four] five [one] two three} + {five [one] two three [four]} +} + +do_execsql_test 2.3 { + SELECT snippet(t2, '[', ']') FROM t2 + WHERE t2 MATCH 'one OR (four AND six)' + ORDER BY docid DESC +} { + {five [one] two three [four]} + {[four] five [one] two three} + {three [four] five [one] two} + {two three [four] five [one]} + {[one] two three [four] five} +} + +do_execsql_test 2.4 { + INSERT INTO t2 VALUES('six'); +} + +do_execsql_test 2.5 { + SELECT snippet(t2, '[', ']') FROM t2 WHERE t2 MATCH 'one OR (four AND six)' +} { + {[one] two three [four] five} + {two three [four] five [one]} + {three [four] five [one] two} + {[four] five [one] two three} + {five [one] two three [four]} +} + +do_execsql_test 2.6 { + SELECT snippet(t2, '[', ']') FROM t2 + WHERE t2 MATCH 'one OR (four AND six)' + ORDER BY docid DESC +} { + {five [one] two three [four]} + {[four] five [one] two three} + {three [four] five [one] two} + {two three [four] five [one]} + {[one] two three [four] five} +} + +#------------------------------------------------------------------------- +do_execsql_test 3 { + CREATE VIRTUAL TABLE t3 USING fts4; + INSERT INTO t3 VALUES('[one two three]'); +} +do_execsql_test 3.1 { + SELECT snippet(t3) FROM t3 WHERE t3 MATCH 'one'; +} {{[one two three]}} +do_execsql_test 3.2 { + SELECT snippet(t3) FROM t3 WHERE t3 MATCH 'two'; +} {{[one two three]}} +do_execsql_test 3.3 { + SELECT snippet(t3) FROM t3 WHERE t3 MATCH 'three'; +} {{[one two three]}} +do_execsql_test 3.4 { + SELECT snippet(t3) FROM t3 WHERE t3 MATCH 'one OR two OR three'; +} {{[one two three]}} + +#------------------------------------------------------------------------- +# Request a snippet 0 tokens in size. This is always an empty string. +do_execsql_test 4.1 { + CREATE VIRTUAL TABLE t4 USING fts4; + INSERT INTO t4 VALUES('a b c d'); + SELECT snippet(t4, '[', ']', '...', 0, 0) FROM t4 WHERE t4 MATCH 'b'; +} {{}} + +do_test 4.2 { + set x35 [string trim [string repeat "x " 35]] + execsql "INSERT INTO t4 VALUES('$x35 E $x35 F $x35 G $x35');" + llength [db one { + SELECT snippet(t4, '', '', '', 0, 64) FROM t4 WHERE t4 MATCH 'E' + }] +} {64} + +do_test 4.3 { + llength [db one { + SELECT snippet(t4, '', '', '', 0, 150) FROM t4 WHERE t4 MATCH 'E' + }] +} {64} + + +#------------------------------------------------------------------------- +# Request a snippet from a query with more than 64 phrases. +# +do_execsql_test 5.0 { + CREATE VIRTUAL TABLE t5 USING fts3(x); + INSERT INTO t5 VALUES('a1 a2 a3'); + INSERT INTO t5 VALUES('a4 a5 a6'); + INSERT INTO t5 VALUES('a70 a71 a72'); +} + +do_execsql_test 5.1 { + SELECT snippet(t5, '[', ']') FROM t5 WHERE t5 MATCH + 'a1 OR a2 OR a3 OR a4 OR a5 OR a6 OR a7 OR a8 OR a9 OR a10 OR ' || + 'a11 OR a12 OR a13 OR a14 OR a15 OR a16 OR a17 OR a18 OR a19 OR a10 OR ' || + 'a21 OR a22 OR a23 OR a24 OR a25 OR a26 OR a27 OR a28 OR a29 OR a20 OR ' || + 'a31 OR a32 OR a33 OR a34 OR a35 OR a36 OR a37 OR a38 OR a39 OR a30 OR ' || + 'a41 OR a42 OR a43 OR a44 OR a45 OR a46 OR a47 OR a48 OR a49 OR a40 OR ' || + 'a51 OR a52 OR a53 OR a54 OR a55 OR a56 OR a57 OR a58 OR a59 OR a50 OR ' || + 'a61 OR a62 OR a63 OR a64 OR a65 OR a66 OR a67 OR a68 OR a69 OR a60 OR ' || + 'a71 OR a72 OR a73 OR a74 OR a75 OR a76 OR a77 OR a78 OR a79 OR a70' +} { + {[a1] [a2] [a3]} + {[a4] [a5] [a6]} + {[a70] [a71] [a72]} +} + +set sqlite_fts3_enable_parentheses 0 +finish_test diff --git a/test/fts3snippet2.test b/test/fts3snippet2.test new file mode 100644 index 0000000..607b01e --- /dev/null +++ b/test/fts3snippet2.test @@ -0,0 +1,59 @@ +# 2020-05-14 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# +# The tests in this file test the FTS3 auxillary functions offsets(), +# snippet() and matchinfo() work. At time of writing, running this file +# provides full coverage of fts3_snippet.c. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts3snippet + +# If SQLITE_ENABLE_FTS3 is not defined, omit this file. +ifcapable !fts3 { finish_test ; return } +source $testdir/fts3_common.tcl + +set sqlite_fts3_enable_parentheses 1 +#------------------------------------------------------------------------- +# Request a snippet from a query with more than 64 phrases. +# +reset_db +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE f USING fts3(b); + INSERT INTO f VALUES ( x'746e6e6d64612e082a011065616e656d655a616c702a2f65732e0f42014001380230018218'); +} + +do_execsql_test 1.1 { + SELECT length(snippet(f))>0 FROM f WHERE b MATCH x'1065616e656d655a616c702a2f65732e0f42014001380230018218021001081e0a3d746e6e6d64612e082a010f42014001380230018218021001081e0a3d746e6e6d64612e082a011065616e656d655a616c702a2f65732e0f42014001380230018218021001081e0a3d746e6e6d64612e082a011065616e656d655a616c702a2f65732e0f42014001380230018218021001081e0a3d746e6e6d64612e082a011065616e656d655a616c702a2f0a3d746e6e6d64612e082a011065616e656d655a616c702a2f65732e0f42014001018218021001081e0a3d746e6e6d64612e082a011065616e656d655a616c702a018218021001081e0a3d746e6e6d64612e082a011065616e656d655a616c2a2f65732e0f42014001380230018218021001081e0a3d746e6e6d64612e082a011065616e656d655a616c702a2f65732e0f42014001380230018218021001081e0a3d746e6e6d64612e082a011065616e656d655a616c702a2f65732e0f42014001380230018218021001081e0a3d746e6e6d64612e082a011065616e656d655a616c702a2f65732e0f42014001380230018218021001081e0a3d746e6e6d64612e0f42'; +} {1} + +reset_db +do_execsql_test 2.0 { + CREATE VIRTUAL TABLE t0 USING fts3(col0 INTEGER PRIMARY KEY,col1 VARCHAR(8),col2 BINARY,col3 BINARY); + INSERT INTO t0 VALUES (1, '1234','aaaa','bbbb'); + SELECT snippet(t0) FROM t0 WHERE t0 MATCH x'0a4d4d4d4d320a4f52d70a310a310a4e4541520a0a31f6ce0a4f520a0a310a310a310a4f520a75fc2a242424' ; +} {1} + +reset_db +do_execsql_test 2.1 { + CREATE VIRTUAL TABLE t0 USING fts3( + col0 INTEGER PRIMARY KEY,col1 VARCHAR(8),col2 BINARY,col3 BINARY + ); + INSERT INTO t0 VALUES ('one', '1234','aaaa','bbbb'); +} +do_execsql_test 2.2 { + SELECT snippet(t0) FROM t0 WHERE t0 MATCH + '(def AND (one NEAR abc)) OR one' +} {one} + +set sqlite_fts3_enable_parentheses 0 +finish_test diff --git a/test/fts3sort.test b/test/fts3sort.test new file mode 100644 index 0000000..218bf3e --- /dev/null +++ b/test/fts3sort.test @@ -0,0 +1,184 @@ +# 2011 May 04 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS3 module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + + +proc build_database {nRow param} { + db close + forcedelete test.db + sqlite3 db test.db + + set vocab [list aa ab ac ba bb bc ca cb cc da] + expr srand(0) + + execsql "CREATE VIRTUAL TABLE t1 USING fts4($param)" + for {set i 0} {$i < $nRow} {incr i} { + set v [expr int(rand()*1000000)] + set doc [list] + for {set div 1} {$div < 1000000} {set div [expr $div*10]} { + lappend doc [lindex $vocab [expr ($v/$div) % 10]] + } + execsql { INSERT INTO t1 VALUES($doc) } + } +} + +set testprefix fts3sort + +unset -nocomplain CONTROL +foreach {t param} { + 1 "" + 2 "order=asc" + 3 "order=desc" +} { + + set testprefix fts3sort-1.$t + + set nRow 1000 + do_test 1.0 { + build_database $nRow $param + execsql { SELECT count(*) FROM t1 } + } $nRow + + foreach {tn query} { + 1 "SELECT docid, * FROM t1" + 2 "SELECT docid, * FROM t1 WHERE t1 MATCH 'aa'" + 3 "SELECT docid, * FROM t1 WHERE t1 MATCH 'a*'" + 4 "SELECT docid, quote(matchinfo(t1)) FROM t1 WHERE t1 MATCH 'a*'" + 5 "SELECT docid, quote(matchinfo(t1,'pcnxals')) FROM t1 WHERE t1 MATCH 'b*'" + 6 "SELECT docid, * FROM t1 WHERE t1 MATCH 'a* b* c*'" + 7 "SELECT docid, * FROM t1 WHERE t1 MATCH 'aa OR da'" + 8 "SELECT docid, * FROM t1 WHERE t1 MATCH 'nosuchtoken'" + 9 "SELECT docid, snippet(t1) FROM t1 WHERE t1 MATCH 'aa OR da'" + 10 "SELECT docid, snippet(t1) FROM t1 WHERE t1 MATCH 'aa OR nosuchtoken'" + 11 "SELECT docid, snippet(t1) FROM t1 WHERE t1 MATCH 'aa NEAR bb'" + 12 "SELECT docid, snippet(t1) FROM t1 WHERE t1 MATCH '\"aa bb\"'" + 13 "SELECT docid, content FROM t1 WHERE t1 MATCH 'aa NEAR/2 bb NEAR/3 cc'" + 14 "SELECT docid, content FROM t1 WHERE t1 MATCH '\"aa bb cc\"'" + } { + + unset -nocomplain A B C D + set A_list [list] + set B_list [list] + set C_list [list] + set D_list [list] + + unset -nocomplain X + db eval "$query ORDER BY rowid ASC" X { + set A($X(docid)) [array get X] + lappend A_list $X(docid) + } + unset -nocomplain X + db eval "$query ORDER BY rowid DESC" X { + set B($X(docid)) [array get X] + lappend B_list $X(docid) + } + unset -nocomplain X + db eval "$query ORDER BY docid ASC" X { + set C($X(docid)) [array get X] + lappend C_list $X(docid) + } + unset -nocomplain X + db eval "$query ORDER BY docid DESC" X { + set D($X(docid)) [array get X] + lappend D_list $X(docid) + } + + do_test $tn.1 { set A_list } [lsort -integer -increasing $A_list] + do_test $tn.2 { set B_list } [lsort -integer -decreasing $B_list] + do_test $tn.3 { set C_list } [lsort -integer -increasing $C_list] + do_test $tn.4 { set D_list } [lsort -integer -decreasing $D_list] + + unset -nocomplain DATA + unset -nocomplain X + db eval "$query" X { + set DATA($X(docid)) [array get X] + } + + do_test $tn.5 { lsort [array get A] } [lsort [array get DATA]] + do_test $tn.6 { lsort [array get B] } [lsort [array get DATA]] + do_test $tn.7 { lsort [array get C] } [lsort [array get DATA]] + do_test $tn.8 { lsort [array get D] } [lsort [array get DATA]] + + if {[info exists CONTROL($tn)]} { + do_test $tn.9 { set CONTROL($tn) } [lsort [array get DATA]] + } else { + set CONTROL($tn) [lsort [array get DATA]] + } + } +} +unset -nocomplain CONTROL + +set testprefix fts3sort + +#------------------------------------------------------------------------- +# Tests for parsing the "order=asc" and "order=desc" directives. +# +foreach {tn param res} { + 1 "order=asc" {0 {}} + 2 "order=desc" {0 {}} + 3 "order=dec" {1 {unrecognized order: dec}} + 4 "order=xxx, order=asc" {1 {unrecognized order: xxx}} + 5 "order=desc, order=asc" {0 {}} + 6 "order=xxxx, order=asc" {1 {unrecognized order: xxxx}} + 7 "order=desk" {1 {unrecognized order: desk}} +} { + execsql { DROP TABLE IF EXISTS t1 } + do_catchsql_test 2.1.$tn " + CREATE VIRTUAL TABLE t1 USING fts4(a, b, $param) + " $res +} + +do_execsql_test 2.2 { + BEGIN; + CREATE VIRTUAL TABLE t2 USING fts4(order=desc); + INSERT INTO t2 VALUES('aa bb'); + INSERT INTO t2 VALUES('bb cc'); + INSERT INTO t2 VALUES('cc aa'); + SELECT docid FROM t2 WHERE t2 MATCH 'aa'; + END; +} {3 1} +do_execsql_test 2.3 { + SELECT docid FROM t2 WHERE t2 MATCH 'aa'; +} {3 1} +do_execsql_test 2.4 { + SELECT docid FROM t2 WHERE t2 MATCH 'aa' ORDER BY content; +} {1 3} + +#------------------------------------------------------------------------- +# Test that ticket [56be976859] has been fixed. +# +do_execsql_test 3.1 { + CREATE VIRTUAL TABLE t3 USING fts4(x, order=DESC); + INSERT INTO t3(docid, x) VALUES(113382409004785664, 'aa'); + INSERT INTO t3(docid, x) VALUES(1, 'ab'); + SELECT rowid FROM t3 WHERE x MATCH 'a*' ORDER BY docid DESC; +} {113382409004785664 1} +do_execsql_test 3.2 { + CREATE VIRTUAL TABLE t4 USING fts4(x); + INSERT INTO t4(docid, x) VALUES(-113382409004785664, 'aa'); + INSERT INTO t4(docid, x) VALUES(1, 'ab'); + SELECT rowid FROM t4 WHERE x MATCH 'a*'; +} {-113382409004785664 1} + + + +finish_test diff --git a/test/fts3tok1.test b/test/fts3tok1.test new file mode 100644 index 0000000..139fae8 --- /dev/null +++ b/test/fts3tok1.test @@ -0,0 +1,124 @@ +# 2013 April 22 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the "fts3tokenize" virtual table +# that is part of the FTS3 module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +ifcapable !fts3 { finish_test ; return } +set ::testprefix fts3tok1 + +#------------------------------------------------------------------------- +# Simple test cases. Using the default (simple) tokenizer. +# +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t1 USING fts3tokenize(simple); + CREATE VIRTUAL TABLE t2 USING fts3tokenize(); + CREATE VIRTUAL TABLE t3 USING fts3tokenize(simple, '', 'xyz '); +} + +foreach {tn tbl} {1 t1 2 t2 3 t3} { + do_execsql_test 1.$tn.1 "SELECT * FROM $tbl WHERE input = 'one two three'" { + {one two three} one 0 3 0 + {one two three} two 4 7 1 + {one two three} three 8 13 2 + } + + do_execsql_test 1.$tn.2 " + SELECT token FROM $tbl WHERE input = 'OnE tWo tHrEe' + " { + one two three + } +} + +do_execsql_test 1.4 { + SELECT token FROM t3 WHERE input = '1x2x3x' +} {1 2 3} + +do_execsql_test 1.5 { + SELECT token FROM t1 WHERE input = '1x2x3x' +} {1x2x3x} + +do_execsql_test 1.6 { + SELECT token FROM t3 WHERE input = '1''2x3x' +} {1'2 3} + +do_execsql_test 1.7 { + SELECT token FROM t3 WHERE input = '' +} {} + +do_execsql_test 1.8 { + SELECT token FROM t3 WHERE input = NULL +} {} + +do_execsql_test 1.9 { + SELECT * FROM t3 WHERE input = 123 +} {123 123 0 3 0} + +do_execsql_test 1.10 { + SELECT * FROM t1 WHERE input = 'a b c' AND token = 'b'; +} { + {a b c} b 2 3 1 +} + +do_execsql_test 1.11 { + SELECT * FROM t1 WHERE token = 'b' AND input = 'a b c'; +} { + {a b c} b 2 3 1 +} + +do_execsql_test 1.12 { + SELECT * FROM t1 WHERE input < 'b' AND input = 'a b c'; +} { + {a b c} a 0 1 0 + {a b c} b 2 3 1 + {a b c} c 4 5 2 +} + +do_execsql_test 1.13.1 { + CREATE TABLE c1(x); + INSERT INTO c1(x) VALUES('a b c'); + INSERT INTO c1(x) VALUES('d e f'); +} +do_execsql_test 1.13.2 { + SELECT * FROM c1, t1 WHERE input = x AND c1.rowid=t1.rowid; +} { + {a b c} {a b c} a 0 1 0 + {d e f} {d e f} e 2 3 1 +} + + +#------------------------------------------------------------------------- +# Error cases. +# +do_catchsql_test 2.0 { + CREATE VIRTUAL TABLE tX USING fts3tokenize(nosuchtokenizer); +} {1 {unknown tokenizer: nosuchtokenizer}} + +do_catchsql_test 2.1 { + CREATE VIRTUAL TABLE t4 USING fts3tokenize; + SELECT * FROM t4; +} {1 {SQL logic error}} + +do_catchsql_test 2.2 { + CREATE VIRTUAL TABLE t USING fts4(tokenize=simple""); +} {0 {}} + +ifcapable fts3_unicode { + do_catchsql_test 2.3 { + CREATE VIRTUAL TABLE u USING fts4(tokenize=unicode61""); + } {1 {unknown tokenizer}} +} + + +finish_test diff --git a/test/fts3tok_err.test b/test/fts3tok_err.test new file mode 100644 index 0000000..df0d4be --- /dev/null +++ b/test/fts3tok_err.test @@ -0,0 +1,47 @@ +# 2013 April 22 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the "fts3tokenize" virtual table +# that is part of the FTS3 module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/malloc_common.tcl +ifcapable !fts3 { finish_test ; return } +set ::testprefix fts3tok_err + + +faultsim_save_and_close +do_faultsim_test fts3tok_err-1 -faults oom* -prep { + faultsim_restore_and_reopen +} -body { + execsql { CREATE VIRTUAL TABLE t1 USING fts3tokenize("simple"); } +} -test { + faultsim_test_result {0 {}} +} + +do_test fts3tok_err-2.prep { + faultsim_delete_and_reopen + execsql { CREATE VIRTUAL TABLE t1 USING fts3tokenize("simple"); } + faultsim_save_and_close +} {} + +do_faultsim_test fts3tok_err-2 -faults oom* -prep { + faultsim_restore_and_reopen +} -body { + execsql { SELECT token FROM t1 WHERE input = 'A galaxy far, far away' } +} -test { + faultsim_test_result {0 {a galaxy far far away}} +} + + +finish_test diff --git a/test/fts3varint.test b/test/fts3varint.test new file mode 100644 index 0000000..9f797ed --- /dev/null +++ b/test/fts3varint.test @@ -0,0 +1,121 @@ +# 2007 November 23 +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file runs all tests. +# +# $Id: fts3.test,v 1.2 2008/07/23 18:17:32 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts3varint + +ifcapable !fts3 { + finish_test + return +} + +proc test_list {list} { + foreach n $list { fts3_test_varint $n } +} + +proc do_fts3_varint_test {tn list} { + uplevel [list do_test $tn [list test_list $list] {}] +} + +do_fts3_varint_test 1.0 { + 1 10 100 1000 10000 100000 1000000 + 10000000 100000000 1000000000 10000000000 + 100000000000 1000000000000 10000000000000 +} + +do_fts3_varint_test 1.1 { + -1 -10 -100 -1000 -10000 -100000 -1000000 + -10000000 -100000000 -1000000000 -10000000000 + -100000000000 -1000000000000 -10000000000000 +} + +do_fts3_varint_test 2.0 { 0 1 2 } +do_fts3_varint_test 2.1 { 1 2 3 } +do_fts3_varint_test 2.2 { 3 4 5 } +do_fts3_varint_test 2.3 { 7 8 9 } +do_fts3_varint_test 2.4 { 15 16 17 } +do_fts3_varint_test 2.5 { 31 32 33 } +do_fts3_varint_test 2.6 { 63 64 65 } +do_fts3_varint_test 2.7 { 127 128 129 } +do_fts3_varint_test 2.8 { 255 256 257 } +do_fts3_varint_test 2.9 { 511 512 513 } +do_fts3_varint_test 2.10 { 1023 1024 1025 } +do_fts3_varint_test 2.11 { 2047 2048 2049 } +do_fts3_varint_test 2.12 { 4095 4096 4097 } +do_fts3_varint_test 2.13 { 8191 8192 8193 } +do_fts3_varint_test 2.14 { 16383 16384 16385 } +do_fts3_varint_test 2.15 { 32767 32768 32769 } +do_fts3_varint_test 2.16 { 65535 65536 65537 } +do_fts3_varint_test 2.17 { 131071 131072 131073 } +do_fts3_varint_test 2.18 { 262143 262144 262145 } +do_fts3_varint_test 2.19 { 524287 524288 524289 } +do_fts3_varint_test 2.20 { 1048575 1048576 1048577 } +do_fts3_varint_test 2.21 { 2097151 2097152 2097153 } +do_fts3_varint_test 2.22 { 4194303 4194304 4194305 } +do_fts3_varint_test 2.23 { 8388607 8388608 8388609 } +do_fts3_varint_test 2.24 { 16777215 16777216 16777217 } +do_fts3_varint_test 2.25 { 33554431 33554432 33554433 } +do_fts3_varint_test 2.26 { 67108863 67108864 67108865 } +do_fts3_varint_test 2.27 { 134217727 134217728 134217729 } +do_fts3_varint_test 2.28 { 268435455 268435456 268435457 } +do_fts3_varint_test 2.29 { 536870911 536870912 536870913 } +do_fts3_varint_test 2.30 { 1073741823 1073741824 1073741825 } +do_fts3_varint_test 2.31 { 2147483647 2147483648 2147483649 } +do_fts3_varint_test 2.32 { 4294967295 4294967296 4294967297 } +do_fts3_varint_test 2.33 { 8589934591 8589934592 8589934593 } +do_fts3_varint_test 2.34 { 17179869183 17179869184 17179869185 } +do_fts3_varint_test 2.35 { 34359738367 34359738368 34359738369 } +do_fts3_varint_test 2.36 { 68719476735 68719476736 68719476737 } +do_fts3_varint_test 2.37 { 137438953471 137438953472 137438953473 } +do_fts3_varint_test 2.38 { 274877906943 274877906944 274877906945 } +do_fts3_varint_test 2.39 { 549755813887 549755813888 549755813889 } +do_fts3_varint_test 2.40 { 1099511627775 1099511627776 1099511627777 } +do_fts3_varint_test 2.41 { 2199023255551 2199023255552 2199023255553 } +do_fts3_varint_test 2.42 { 4398046511103 4398046511104 4398046511105 } +do_fts3_varint_test 2.43 { 8796093022207 8796093022208 8796093022209 } +do_fts3_varint_test 2.44 { 17592186044415 17592186044416 17592186044417 } +do_fts3_varint_test 2.45 { 35184372088831 35184372088832 35184372088833 } +do_fts3_varint_test 2.46 { 70368744177663 70368744177664 70368744177665 } +do_fts3_varint_test 2.47 { 140737488355327 140737488355328 140737488355329 } +do_fts3_varint_test 2.48 { 281474976710655 281474976710656 281474976710657 } +do_fts3_varint_test 2.49 { 562949953421311 562949953421312 562949953421313 } +do_fts3_varint_test 2.50 { 1125899906842623 1125899906842624 1125899906842625 } +do_fts3_varint_test 2.51 { 2251799813685247 2251799813685248 2251799813685249 } +do_fts3_varint_test 2.52 { 4503599627370495 4503599627370496 4503599627370497 } +do_fts3_varint_test 2.53 { 9007199254740991 9007199254740992 9007199254740993 } +do_fts3_varint_test 2.54 { + 18014398509481983 18014398509481984 18014398509481985 } +do_fts3_varint_test 2.55 { + 36028797018963967 36028797018963968 36028797018963969 } +do_fts3_varint_test 2.56 { + 72057594037927935 72057594037927936 72057594037927937 } +do_fts3_varint_test 2.57 { + 144115188075855871 144115188075855872 144115188075855873 } +do_fts3_varint_test 2.58 { + 288230376151711743 288230376151711744 288230376151711745 } +do_fts3_varint_test 2.59 { + 576460752303423487 576460752303423488 576460752303423489 } +do_fts3_varint_test 2.60 { + 1152921504606846975 1152921504606846976 1152921504606846977 } +do_fts3_varint_test 2.61 { + 2305843009213693951 2305843009213693952 2305843009213693953 } +do_fts3_varint_test 2.62 { + 4611686018427387903 4611686018427387904 4611686018427387905 } + +if {![catch {fts3_test_varint 18446744073709551615}]} { + do_fts3_varint_test 2.63 { + 9223372036854775807 9223372036854775808 9223372036854775809 } + + do_fts3_varint_test 3.0 { 18446744073709551615 -18446744073709551615 } +} + +finish_test diff --git a/test/fts4aa.test b/test/fts4aa.test new file mode 100644 index 0000000..0c6c0b9 --- /dev/null +++ b/test/fts4aa.test @@ -0,0 +1,256 @@ +# 2010 February 02 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS4 module. +# +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# Create the fts_kjv_genesis procedure which fills and FTS3/4 table with +# the complete text of the Book of Genesis. +# +source $testdir/genesis.tcl + +# The following is a list of queries to perform against the above +# FTS3/FTS4 database. We will be trying these queries in various +# configurations to ensure that they always return the same answers. +# +set fts4aa_queries { + {abraham} + {the king} + {"the king"} + {abraham OR joseph} + {ab* OR jos*} + {lived t*} + {spake hebrew} + {melchizedek} + {t* melchizedek} + {melchizedek t*} +} +unset -nocomplain fts4aa_res + +# Set up the baseline results +# +do_test fts4aa-1.0 { + db eval { + CREATE VIRTUAL TABLE t1 USING fts4(words, tokenize porter); + } + fts_kjv_genesis + foreach q $::fts4aa_queries { + set r [db eval {SELECT docid FROM t1 WHERE words MATCH $q ORDER BY docid}] + set ::fts4aa_res($q) $r + } +} {} + +# Legacy test cases +# +do_test fts4aa-1.1 { + db eval { + SELECT docid FROM t1 EXCEPT SELECT docid FROM t1_docsize + } +} {} +do_test fts4aa-1.2 { + db eval { + SELECT docid FROM t1_docsize EXCEPT SELECT docid FROM t1 + } +} {} + +proc mit {blob} { + set scan(littleEndian) i* + set scan(bigEndian) I* + binary scan $blob $scan($::tcl_platform(byteOrder)) r + return $r +} +db func mit mit + +do_test fts4aa-1.3 { + db eval { + SELECT docid, mit(matchinfo(t1, 'pcxnal')) FROM t1 WHERE t1 MATCH 'melchizedek'; + } +} {1014018 {1 1 1 1 1 1533 25 20}} +do_test fts4aa-1.4 { + db eval { + SELECT docid, mit(matchinfo(t1, 'pcxnal')) FROM t1 + WHERE t1 MATCH 'spake hebrew' + ORDER BY docid; + } +} {1039014 {2 1 1 40 40 1 6 6 1533 25 42} 1039017 {2 1 1 40 40 1 6 6 1533 25 26}} +do_test fts4aa-1.5 { + db eval { + SELECT docid, mit(matchinfo(t1, 'pcxnal')) FROM t1 + WHERE t1 MATCH 'laban overtook jacob' + ORDER BY docid; + } +} {1031025 {3 1 2 54 46 1 3 3 2 181 160 1533 25 24}} + +do_test fts4aa-1.6 { + db eval { + DELETE FROM t1 WHERE docid!=1050026; + SELECT hex(size) FROM t1_docsize; + SELECT hex(value) FROM t1_stat; + } +} {17 01176F} + +do_test fts4aa-1.7 { + db eval { + SELECT docid FROM t1 EXCEPT SELECT docid FROM t1_docsize + } +} {} +do_test fts4aa-1.8 { + db eval { + SELECT docid FROM t1_docsize EXCEPT SELECT docid FROM t1 + } +} {} +ifcapable fts4_deferred { + do_test fts4aa-1.9 { + # Note: Token 'in' is being deferred in the following query. + db eval { + SELECT docid, mit(matchinfo(t1, 'pcxnal')) FROM t1 + WHERE t1 MATCH 'joseph died in egypt' + ORDER BY docid; + } + } {1050026 {4 1 1 1 1 1 1 1 2 1 1 1 1 1 1 23 23}} +} + +# Should get the same search results from FTS3 +# +do_test fts4aa-2.0 { + db eval { + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING fts3(words, tokenize porter); + } + fts_kjv_genesis +} {} +unset -nocomplain ii +set ii 0 +foreach {q r} [array get fts4aa_res] { + incr ii + do_test fts4aa-2.$ii { + db eval {SELECT docid FROM t1 WHERE words MATCH $::q ORDER BY docid} + } $r +} + +# Should get the same search results when the page size is very large +# +do_test fts4aa-3.0 { + db close + forcedelete test.db + sqlite3 db test.db + db eval { + PRAGMA page_size=65536; + CREATE VIRTUAL TABLE t1 USING fts4(words, tokenize porter); + } + fts_kjv_genesis +} {} +unset -nocomplain ii +set ii 0 +foreach {q r} [array get fts4aa_res] { + incr ii + do_test fts4aa-3.$ii { + db eval {SELECT docid FROM t1 WHERE words MATCH $::q ORDER BY docid} + } $r +} + +# Should get the same search results when an authorizer prevents +# all PRAGMA statements. +# +proc no_pragma_auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_PRAGMA"} {return SQLITE_DENY} + return SQLITE_OK; +} +do_test fts4aa-4.0 { + db auth ::no_pragma_auth + db eval { + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING fts4(words, tokenize porter); + } + fts_kjv_genesis +} {} +unset -nocomplain ii +set ii 0 +foreach {q r} [array get fts4aa_res] { + incr ii + do_test fts4aa-4.$ii { + db eval {SELECT docid FROM t1 WHERE words MATCH $::q ORDER BY docid} + } $r +} + +# 2019-11-16 https://bugs.chromium.org/p/chromium/issues/detail?id=1025472 +# +db close +sqlite3 db :memory: +do_execsql_test fts4aa-5.10 { + CREATE VIRTUAL TABLE t1 USING fts4(a, b, c, d, e,f,g,h,i,j,k,l,m,n,o,p,q,r); + INSERT INTO t1 VALUES('X Y', '2', '3', '4', '5', '6', '7', '8', '9', '0', + 'a','b','c','d','e','f','g','h'); + UPDATE t1_docsize SET size=x'88' WHERE docid=1; +} {} +do_catchsql_test fts4aa-5.20 { + SELECT quote(matchinfo(t1, 'l')) FROM t1 WHERE t1 MATCH 'X Y'; +} {1 {database disk image is malformed}} +do_execsql_test fts4aa-5.30 { + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING fts4(a,b,c,d); + INSERT INTO t1 VALUES('one two','three four','five six','seven eight'); +} {} +do_catchsql_test fts4aa-5.40 { + UPDATE t1_stat SET value=x'01010101' WHERE id=0; + SELECT quote(matchinfo(t1,'a')) FROM t1 WHERE t1 MATCH 'one two'; +} {1 {database disk image is malformed}} +do_catchsql_test fts4aa-5.50 { + UPDATE t1_stat SET value=x'010101' WHERE id=0; + SELECT quote(matchinfo(t1,'a')) FROM t1 WHERE t1 MATCH 'one two'; +} {1 {database disk image is malformed}} +do_catchsql_test fts4aa-5.60 { + UPDATE t1_stat SET value=x'01' WHERE id=0; + SELECT quote(matchinfo(t1,'a')) FROM t1 WHERE t1 MATCH 'one two'; +} {1 {database disk image is malformed}} +do_catchsql_test fts4aa-5.70 { + UPDATE t1_stat SET value=x'' WHERE id=0; + SELECT quote(matchinfo(t1,'a')) FROM t1 WHERE t1 MATCH 'one two'; +} {1 {database disk image is malformed}} + +# 2019-11-18 https://bugs.chromium.org/p/chromium/issues/detail?id=1025467 +db close +sqlite3 db :memory: +if {$tcl_platform(byteOrder)=="littleEndian"} { + set res {X'0200000000000000000000000E0000000E00000001000000010000000100000001000000'} +} else { + set res {X'0000000200000000000000000000000E0000000E00000001000000010000000100000001'} +} +do_catchsql_test fts4aa-6.10 { + CREATE VIRTUAL TABLE f USING fts4(); + INSERT INTO f_segdir VALUES (77,91,0,0,'255 77',x'0001308000004d5c4ddddddd4d4d7b4d4d4d614d8019ff4d05000001204d4d2e4d6e4d4d4d4b4d6c4d004d4d4d4d4d4d3d000000004d5d4d4d645d4d004d4d4d4d4d4d4d4d4d454d6910004d05ffff054d646c4d004d5d4d4d4d4d3d000000004d4d4d4d4d4d4d4d4d4d4d69624d4d4d04004d4d4d4d4d604d4ce1404d554d45'); + INSERT INTO f_segdir VALUES (77,108,0,0,'255 77',x'0001310000fa64004d4d4d3c5d4d654d4d4d614d8000ff4d05000001204d4d2e4d6e4d4d4dff4d4d4d4d4d4d00104d4d4d4d000000004d4d4d0400311d4d4d4d4d4d4d4d4d4d684d6910004d05ffff054d4d6c4d004d4d4d4d4d4d3d000000004d4d4d4d644d4d4d4d4d4d69624d4d4d03ed4d4d4d4d4d604d4ce1404d550080'); + INSERT INTO f_stat VALUES (0,x'80808080100000000064004d4d4d3c4d4d654d4d4d614d8000ff4df6ff1a00204d4d2e4d6e4d4d4d104d4d4d4d4d4d00104d4d4d4d4d4d69574d4d4d000031044d4d4d3e4d4d4c4d05004d6910'); + SELECT quote(matchinfo(f,'pnax')) from f where f match '0 1'; +} {1 {database disk image is malformed}} + +# 2019-11-18 Detect infinite loop in fts3SelectLeaf() +db close +sqlite3 db :memory: +do_catchsql_test fts4aa-7.10 { + CREATE VIRTUAL TABLE f USING fts4(); + INSERT INTO f_segdir VALUES (63,60,60,60,'60 60',x'3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c483c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c20003c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c283c3c3c3c3c3c3c3c3c3c3c223c3c3c3c3c3c3c3c3c'); + INSERT INTO f_segments VALUES (60,x'3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c5a3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c2a3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c5e3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c803c3c3c3c3c3c233c3c3c3c1c3c3c3c3c3c3c3c3c3c3c3c1b3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c273c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c1a3c3c3c3c3c3c000200003c3c3c3c3c3c3c3c3c3c3c3c3c383c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d898d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d3c3c3c3c3c3c3c3c3c3cba3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c1c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c00023c3c3c3c3c3c383c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3cbc3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c2c3c3c3c403c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c16161616161616163c3c3c3c3c3c3c3c3c3c3c3c3c583c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c2b3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c1c013c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c20003c3c3c3c3c3c3c3c3c3c3c800000003c3c3c3c3c3c3c2c3c3c3c3c3c3c353c08080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808f4080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808083c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c323c3c3c3c3c3c3c3c3c3c3c4f3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3cfcfcfcfcfcfcfcfcfcfcfc10fcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfd02fcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfc03e8fcfcfcfc3c3c3c3c3c3c8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c553c3c3c3c3c3c3c3c3c3c3c3c3c573c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c000000803c3c4dd5d5a6d52cf3d5d5d5d5d5d5d5d5d5d5d5d5d5d53c3c3c3c3f3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c2d3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c013c3c3c3c00643c3c3c3ce93c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c263c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c363c3c3c3c3c3c3c3c3c3c3c3c3c3c543c3c3c3c3c3c3c3c3c3c273c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c330000003c3c3c3c3c3c3c3c3c3c3c3c3c3c4d3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c000010003c3c3c3c3c3c413c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c1c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c403c3c3c3c3c3c3c3c3c3c3c3cec0000fa3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c2d3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c4c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c5e3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c1b3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c593c3c3c3c3c3c243c3c373c3c3c3c3cff3c3c3c3c3c3c3c3c3c3c3c3c3c000080003c3c3c3c3c3c3c3c3c3c353c3c3c3c3c3d3c3c3c3c3c3c3c3c3c3c3c3c4d3c3c3c3c3c3c3c3c3c3c3c3c3c40003c3c3c3c3c293c3c3c3c3c3c3c3c3c3d3c3c3c3c3c3c3c3c353c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c4f3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3f3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3cff7f3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c2d3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3ca43c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3cbf3c3c3c3c3c3c3c3c3c008000003c3c3c3c3c3c3c3c343c3c373c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c593c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c'); + SELECT * from f where f match '0'; +} {1 {database disk image is malformed}} + + +finish_test diff --git a/test/fts4check.test b/test/fts4check.test new file mode 100644 index 0000000..7f1004d --- /dev/null +++ b/test/fts4check.test @@ -0,0 +1,223 @@ +# 2012 March 26 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS 'integrity-check' function, +# used to check if the current FTS index accurately reflects the content +# of the table. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/fts3_common.tcl +set ::testprefix fts4check + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# Run the integrity-check on FTS table $tbl using database handle $db. If +# the integrity-check passes, return "ok". Otherwise, throw an exception. +# +proc fts_integrity {db tbl} { + $db eval "INSERT INTO $tbl ($tbl) VALUES('integrity-check')" + return "ok" +} + +#------------------------------------------------------------------------- +# Test cases 1.* +# +# 1.0: Build a reasonably sized FTS table (5000 rows). +# +# 1.1: Run the integrity check code to check it passes. +# +# 1.2: Make a series of minor changes to the underlying FTS data structures +# (e.g. delete or insert a row from the %_content table). Check that +# this causes the integrity-check code to fail. +# + +# Build an FTS table and check the integrity-check passes. +# +do_test 1.0 { fts3_build_db_1 5000 } {} +do_test 1.1 { fts_integrity db t1 } {ok} + +# Mess around with the underlying tables. Check that this causes the +# integrity-check test to fail. +# +foreach {tn disruption} { + 1 { + INSERT INTO t1_content(docid, c0x, c1y) VALUES(NULL, 'a', 'b'); + } + 2 { + DELETE FROM t1_content WHERE docid = (SELECT max(docid) FROM t1_content); + } + 3 { + DELETE FROM t1_segdir WHERE level=0 AND idx=( + SELECT max(idx) FROM t1_segdir WHERE level=0 + ); + } +} { + sqlite3_db_config db DEFENSIVE 0 + do_execsql_test 1.2.1.$tn "BEGIN; $disruption" + do_catchsql_test 1.2.2.$tn { + INSERT INTO t1 (t1) VALUES('integrity-check') + } {1 {database disk image is malformed}} + do_execsql_test 1.2.3.$tn { + PRAGMA integrity_check; + } {{malformed inverted index for FTS4 table main.t1}} + do_execsql_test 1.2.4.$tn "ROLLBACK" +} + +do_test 1.3 { fts_integrity db t1 } {ok} + +#------------------------------------------------------------------------- +# Test cases 2.* +# +# 2.0: Build a reasonably sized FTS table (20000 rows) that includes +# prefix indexes. +# +# 2.1: Run the integrity check code to check it passes. +# +# 2.2: Make a series of minor changes to the underlying FTS data structures +# (e.g. delete or insert a row from the %_content table). Check that +# this causes the integrity-check code to fail. +# + +do_test 2.0 { fts3_build_db_2 -extra {prefix="3,1"} 20000 } {} +do_test 2.1 { fts_integrity db t2 } {ok} +foreach {tn disruption} { + 1 { + INSERT INTO t2_content VALUES(NULL, 'xyz') + } + 3 { + DELETE FROM t2_segdir WHERE level=0 AND idx=( + SELECT max(idx) FROM t2_segdir WHERE level=1024 + ); + } +} { + sqlite3_db_config db DEFENSIVE 0 + do_execsql_test 2.2.1.$tn "BEGIN; $disruption" + do_catchsql_test 2.2.2.$tn { + INSERT INTO t2 (t2) VALUES('integrity-check') + } {1 {database disk image is malformed}} + do_test 2.2.3.$tn { + db eval {PRAGMA integrity_check(t2);} + } {{malformed inverted index for FTS4 table main.t2}} + do_execsql_test 2.2.4.$tn "ROLLBACK" +} + + +#------------------------------------------------------------------------- +# Test cases 3.* +# +# 3.0: Build a reasonably sized FTS table (5000 rows) that includes +# prefix indexes and uses the languageid= feature. +# +# 3.1: Run the integrity check code to check it passes. +# +# 3.2: Make a series of minor changes to the underlying FTS data structures +# (e.g. delete or insert a row from the %_content table). Check that +# this causes the integrity-check code to fail. +# +do_test 3.0 { + reset_db + fts3_build_db_1 5000 + execsql { + CREATE VIRTUAL TABLE t3 USING fts4(x, y, prefix="2,3", languageid=langid); + } + foreach docid [execsql {SELECT docid FROM t1 ORDER BY 1 ASC}] { + execsql { + INSERT INTO t3(x, y, langid) + SELECT x, y, (docid%9)*4 FROM t1 WHERE docid=$docid; + } + } +} {} +do_test 3.1 { fts_integrity db t3 } {ok} + +foreach {tn disruption} { + 1 { + INSERT INTO t3_content(c0x, c1y, langid) VALUES(NULL, 'a', 0); + } + 2 { + UPDATE t3_content SET langid=langid+1 WHERE rowid = ( + SELECT max(rowid) FROM t3_content + ) + } +} { + sqlite3_db_config db DEFENSIVE 0 + do_execsql_test 3.2.1.$tn "BEGIN; $disruption" + do_catchsql_test 3.2.2.$tn { + INSERT INTO t3 (t3) VALUES('integrity-check') + } {1 {database disk image is malformed}} + do_execsql_test 3.2.3.$tn "ROLLBACK" +} + +#-------------------------------------------------------------------------- +# Test case 4.* +# +# Test that the integrity-check works if there are "notindexed" columns. +# +do_execsql_test 4.0 { + CREATE VIRTUAL TABLE t4 USING fts4(a, b, c, notindexed=b); + INSERT INTO t4 VALUES('text one', 'text two', 'text three'); + INSERT INTO t4(t4) VALUES('integrity-check'); +} + +sqlite3_db_config db DEFENSIVE 0 +do_execsql_test 4.1 { + PRAGMA writable_schema = 1; + UPDATE sqlite_master + SET sql = 'CREATE VIRTUAL TABLE t4 USING fts4(a, b, c)' + WHERE name = 't4'; +} + +do_test 4.2 { + db close + sqlite3 db test.db + catchsql { + INSERT INTO t4(t4) VALUES('integrity-check'); + } +} {1 {database disk image is malformed}} +reset_db + +#-------------------------------------------------------------------------- +# Test case 5.* +# +# Test that the integrity-check works if there is uncommitted data. +# +do_execsql_test 5.0 { + BEGIN; + CREATE VIRTUAL TABLE t5 USING fts4(a, prefix="1,2,3"); + INSERT INTO t5 VALUES('And down by Kosiosko, where the reed-banks sweep'); + INSERT INTO t5 VALUES('and sway, and the rolling plains are wide, the'); + INSERT INTO t5 VALUES('man from snowy river is a household name today,'); + INSERT INTO t5 VALUES('and the stockmen tell the story of his ride'); +} + +do_execsql_test 5.1 { + INSERT INTO t5(t5) VALUES('integrity-check'); +} {} + +sqlite3_db_config db DEFENSIVE 0 +do_catchsql_test 5.2 { + INSERT INTO t5_content VALUES(5, 'his hardy mountain pony'); + INSERT INTO t5(t5) VALUES('integrity-check'); +} {1 {database disk image is malformed}} + +do_execsql_test 5.3 ROLLBACK + +do_execsql_test 5.4 { + CREATE VIRTUAL TABLE t5 USING fts4(a, prefix="1,2,3"); + INSERT INTO t5(t5) VALUES('integrity-check'); +} {} + +finish_test diff --git a/test/fts4content.test b/test/fts4content.test new file mode 100644 index 0000000..980586e --- /dev/null +++ b/test/fts4content.test @@ -0,0 +1,674 @@ +# 2011 October 03 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the content=xxx FTS4 option. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix fts4content + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +#------------------------------------------------------------------------- +# Test organization: +# +# 1.* - Warm-body tests. +# +# 2.* - Querying a content=xxx FTS table. +# +# 3.* - Writing to a content=xxx FTS table. +# +# 4.* - The "INSERT INTO fts(fts) VALUES('rebuild')" command. +# +# 5.* - Check that CREATE TABLE, DROP TABLE and ALTER TABLE correctly +# ignore any %_content table when used with the content=xxx option. +# +# 6.* - Test the effects of messing with the schema of table xxx after +# creating a content=xxx FTS index. +# +# 7.* - Test that if content=xxx is specified and table xxx does not +# exist, the FTS table can still be used for INSERT and some +# SELECT statements. +# +# 8.* - Test that if the content=xxx and prefix options are used together, +# the 'rebuild' command still works. +# +# 9.* - Test using content=xxx where xxx is a virtual table. +# +# 11.* - Test that circular references (e.g. "t1(content=t1)") are +# detected. +# + +do_execsql_test 1.1.1 { + CREATE TABLE t1(a, b, c); + INSERT INTO t1 VALUES('w x', 'x y', 'y z'); + CREATE VIRTUAL TABLE ft1 USING fts4(content=t1); +} + +do_execsql_test 1.1.2 { + PRAGMA table_info(ft1); +} { + 0 a {} 0 {} 0 + 1 b {} 0 {} 0 + 2 c {} 0 {} 0 +} + +do_execsql_test 1.1.3 { SELECT *, rowid FROM ft1 } {{w x} {x y} {y z} 1} +do_execsql_test 1.1.4 { SELECT a, c FROM ft1 WHERE rowid=1 } {{w x} {y z}} + +do_execsql_test 1.1.5 { INSERT INTO ft1(ft1) VALUES('rebuild') } {} +do_execsql_test 1.1.6 { SELECT rowid FROM ft1 WHERE ft1 MATCH 'x' } {1} +do_execsql_test 1.1.7 { SELECT rowid FROM ft1 WHERE ft1 MATCH 'a' } {} + +do_execsql_test 1.2.1 { + DROP TABLE ft1; + CREATE VIRTUAL TABLE ft1 USING fts4(content=t1, b); + PRAGMA table_info(ft1); +} { + 0 b {} 0 {} 0 +} +do_execsql_test 1.2.2 { + SELECT *, rowid FROM ft1 +} {{x y} 1} + +#------------------------------------------------------------------------- +# The following block of tests - 2.* - test that a content=xxx FTS table +# can be queried. Also tested are cases where rows identified in the FTS +# are missing from the content table, and cases where the index is +# inconsistent with the content table. +# +do_execsql_test 2.0 { + CREATE TABLE t2(x); + INSERT INTO t2 VALUES('O S W W F U C R Q I C N P Z Y Y E Y Y E'); -- 1 + INSERT INTO t2 VALUES('Y X U V L B E H Y J C Y A I A P V F V K'); -- 2 + INSERT INTO t2 VALUES('P W I N J H I I N I F B K D U Q B Z S F'); -- 3 + INSERT INTO t2 VALUES('N R O R H J R H G M D I U U B O M P A U'); -- 4 + INSERT INTO t2 VALUES('Y O V O G T P N G T N F I V B U M J M G'); -- 5 + INSERT INTO t2 VALUES('J O B N K N E C H Z R K J O U G M K L S'); -- 6 + INSERT INTO t2 VALUES('S Z S R I Q U A P W R X H K C Z U L S P'); -- 7 + INSERT INTO t2 VALUES('J C H N R C K R V N M O F Z M Z A I H W'); -- 8 + INSERT INTO t2 VALUES('O Y G I S J U U W O D Z F J K N R P R L'); -- 9 + INSERT INTO t2 VALUES('B G L K U R U P V X Z I H V R W C Q A S'); -- 10 + INSERT INTO t2 VALUES('T F T J F F Y V F W N X K Q A Y L X W G'); -- 11 + INSERT INTO t2 VALUES('C J U H B Q X L C M M Y E G V F W V Z C'); -- 12 + INSERT INTO t2 VALUES('B W L T F S G X D P H N G M R I O A X I'); -- 13 + INSERT INTO t2 VALUES('N G Y O K Q K Z N M H U J E D H U W R K'); -- 14 + INSERT INTO t2 VALUES('U D T R U Y F J D S J X E H Q G V A S Z'); -- 15 + INSERT INTO t2 VALUES('M I W P J S H R J D Q I C G P C T P H R'); -- 16 + INSERT INTO t2 VALUES('J M N I S L X Q C A B F C B Y D H V R J'); -- 17 + INSERT INTO t2 VALUES('F V Z W J Q L P X Y E W B U Q N H X K T'); -- 18 + INSERT INTO t2 VALUES('R F S R Y O F Q E I E G H C B H R X Y N'); -- 19 + INSERT INTO t2 VALUES('U Q Q Q T E P D M F X P J G H X C Q D L'); -- 20 +} + +do_execsql_test 2.1 { + CREATE VIRTUAL TABLE ft2 USING fts4(content=t2); + INSERT INTO ft2(ft2) VALUES('rebuild'); + + -- Modify the backing table a bit: Row 17 is missing and the contents + -- of row 20 do not match the FTS index contents. + DELETE FROM t2 WHERE rowid = 17; + UPDATE t2 SET x = 'a b c d e f g h i j' WHERE rowid = 20; +} + +foreach {tn match rowidlist} { + 1 {S} {1 3 6 7 9 10 13 15 16 17 19} + 2 {"S R"} {7 19} + 3 {"N K N"} {6} + 4 {"Q Q"} {20} + 5 {"B Y D"} {17} +} { + do_execsql_test 2.2.1.$tn { + SELECT rowid FROM ft2 WHERE ft2 MATCH $match + } $rowidlist + + do_execsql_test 2.2.2.$tn { + SELECT docid FROM ft2 WHERE ft2 MATCH $match + } $rowidlist +} + +foreach {tn match result} { + 1 {"N K N"} {{J O B N K N E C H Z R K J O U G M K L S}} + 2 {"Q Q"} {{a b c d e f g h i j}} + 3 {"B Y D"} {{}} +} { + do_execsql_test 2.3.$tn { + SELECT * FROM ft2 WHERE ft2 MATCH $match + } $result +} + +foreach {tn match result} { + 1 {"N K N"} {{..O B [N] [K] [N] E..}} + 2 {"B Y D"} {{}} + 3 {"Q Q"} {{a [b] [c] [d] e f..}} +} { + do_execsql_test 2.4.$tn { + SELECT snippet(ft2, '[', ']', '..', -1, 6) FROM ft2 WHERE ft2 MATCH $match + } $result +} + +foreach {tn match result} { + 1 {"N K N"} {{0 0 6 1 0 1 8 1 0 2 10 1}} + 2 {"B Y D"} {{}} + 3 {"Q Q"} {{0 0 2 1 0 0 4 1 0 1 4 1 0 1 6 1}} + 4 {"Q D L"} {{}} +} { + do_execsql_test 2.5.$tn { + SELECT offsets(ft2) FROM ft2 WHERE ft2 MATCH $match + } $result +} + +#------------------------------------------------------------------------- +# The following block of tests - 3.* - test that the FTS index can be +# modified by writing to the table. But that this has no effect on the +# content table. +# + +do_execsql_test 3.1 { + CREATE TABLE t3(x, y); + CREATE VIRTUAL TABLE ft3 USING fts4(content=t3); +} + +do_catchsql_test 3.1.1 { + INSERT INTO ft3 VALUES('a b c', 'd e f'); +} {1 {constraint failed}} +do_execsql_test 3.1.2 { + INSERT INTO ft3(docid, x, y) VALUES(21, 'a b c', 'd e f'); + SELECT rowid FROM ft3 WHERE ft3 MATCH '"a b c"'; +} {21} +do_execsql_test 3.1.3 { SELECT * FROM t3 } {} + +# This DELETE does not work, since there is no row in [t3] to base the +# DELETE on. So the SELECT on [ft3] still returns rowid 21. +do_execsql_test 3.1.4 { + DELETE FROM ft3; + SELECT rowid FROM ft3 WHERE ft3 MATCH '"a b c"'; +} {21} + +# If the row is added to [t3] before the DELETE on [ft3], it works. +do_execsql_test 3.1.5 { + INSERT INTO t3(rowid, x, y) VALUES(21, 'a b c', 'd e f'); + DELETE FROM ft3; + SELECT rowid FROM ft3 WHERE ft3 MATCH '"a b c"'; +} {} +do_execsql_test 3.1.6 { SELECT rowid FROM t3 } {21} + +do_execsql_test 3.2.1 { + INSERT INTO ft3(rowid, x, y) VALUES(0, 'R T M S M', 'A F O K H'); + INSERT INTO ft3(rowid, x, y) VALUES(1, 'C Z J O X', 'U S Q D K'); + INSERT INTO ft3(rowid, x, y) VALUES(2, 'N G H P O', 'N O P O C'); + INSERT INTO ft3(rowid, x, y) VALUES(3, 'V H S D R', 'K N G E C'); + INSERT INTO ft3(rowid, x, y) VALUES(4, 'J T R V U', 'U X S L C'); + INSERT INTO ft3(rowid, x, y) VALUES(5, 'N A Y N G', 'X D G P Y'); + INSERT INTO ft3(rowid, x, y) VALUES(6, 'I Q I S P', 'D R O Q B'); + INSERT INTO ft3(rowid, x, y) VALUES(7, 'T K T Z J', 'B W D G O'); + INSERT INTO ft3(rowid, x, y) VALUES(8, 'Y K F X T', 'D F G V G'); + INSERT INTO ft3(rowid, x, y) VALUES(9, 'E L E T L', 'P W N F Z'); + INSERT INTO ft3(rowid, x, y) VALUES(10, 'O G J G X', 'G J F E P'); + INSERT INTO ft3(rowid, x, y) VALUES(11, 'O L N N Z', 'K E Z F D'); + INSERT INTO ft3(rowid, x, y) VALUES(12, 'R Z M R J', 'X G I M Z'); + INSERT INTO ft3(rowid, x, y) VALUES(13, 'L X N N X', 'R R N S T'); + INSERT INTO ft3(rowid, x, y) VALUES(14, 'F L B J H', 'K W F L C'); + INSERT INTO ft3(rowid, x, y) VALUES(15, 'P E B M V', 'E A A B U'); + INSERT INTO ft3(rowid, x, y) VALUES(16, 'V E C F P', 'L U T V K'); + INSERT INTO ft3(rowid, x, y) VALUES(17, 'T N O Z N', 'T P Q X N'); + INSERT INTO ft3(rowid, x, y) VALUES(18, 'V W U W R', 'H O A A V'); + INSERT INTO ft3(rowid, x, y) VALUES(19, 'A H N L F', 'I G H B O'); +} + +foreach {tn match rowidlist} { + 1 "N A" {5 19} + 2 "x:O" {1 2 10 11 17} + 3 "y:O" {0 2 6 7 18 19} +} { + set res [list] + foreach rowid $rowidlist { lappend res $rowid {} {} } + + do_execsql_test 3.2.2.$tn { + SELECT rowid, * FROM ft3 WHERE ft3 MATCH $match + } $res + do_execsql_test 3.2.3.$tn { + SELECT docid, * FROM ft3 WHERE ft3 MATCH $match + } $res +} + +do_execsql_test 3.3.1 { + INSERT INTO t3(rowid, x, y) VALUES(0, 'R T M S M', 'A F O K H'); + INSERT INTO t3(rowid, x, y) VALUES(1, 'C Z J O X', 'U S Q D K'); + INSERT INTO t3(rowid, x, y) VALUES(2, 'N G H P O', 'N O P O C'); + INSERT INTO t3(rowid, x, y) VALUES(3, 'V H S D R', 'K N G E C'); + INSERT INTO t3(rowid, x, y) VALUES(4, 'J T R V U', 'U X S L C'); + INSERT INTO t3(rowid, x, y) VALUES(5, 'N A Y N G', 'X D G P Y'); + UPDATE ft3 SET x = y, y = x; + DELETE FROM t3; +} + +foreach {tn match rowidlist} { + 1 "N A" {5 19} + 2 "x:O" {0 2 10 11 17} + 3 "y:O" {1 2 6 7 18 19} +} { + set res [list] + foreach rowid $rowidlist { lappend res $rowid {} {} } + + do_execsql_test 3.3.2.$tn { + SELECT rowid, * FROM ft3 WHERE ft3 MATCH $match + } $res + do_execsql_test 3.3.3.$tn { + SELECT docid, * FROM ft3 WHERE ft3 MATCH $match + } $res +} + +do_execsql_test 3.3.1 { + INSERT INTO t3(rowid, x, y) VALUES(15, 'P E B M V', 'E A A B U'); + INSERT INTO t3(rowid, x, y) VALUES(16, 'V E C F P', 'L U T V K'); + INSERT INTO t3(rowid, x, y) VALUES(17, 'T N O Z N', 'T P Q X N'); + INSERT INTO t3(rowid, x, y) VALUES(18, 'V W U W R', 'H O A A V'); + INSERT INTO t3(rowid, x, y) VALUES(19, 'A H N L F', 'I G H B O'); + DELETE FROM ft3; +} + +foreach {tn match rowidlist} { + 1 "N A" {5} + 2 "x:O" {0 2 10 11} + 3 "y:O" {1 2 6 7} +} { + set res [list] + foreach rowid $rowidlist { lappend res $rowid {} {} } + + do_execsql_test 3.3.2.$tn { + SELECT rowid, * FROM ft3 WHERE ft3 MATCH $match + } $res + do_execsql_test 3.3.3.$tn { + SELECT docid, * FROM ft3 WHERE ft3 MATCH $match + } $res +} + + +#------------------------------------------------------------------------- +# Test cases 4.* test the 'rebuild' command. On content=xxx and regular +# FTS tables. +# +do_execsql_test 4.0 { + CREATE TABLE t4(x); + CREATE VIRTUAL TABLE ft4 USING fts4(content=t4); + CREATE VIRTUAL TABLE ft4x USING fts4(x); +} + +do_execsql_test 4.1.1 { + INSERT INTO ft4x(ft4x) VALUES('rebuild'); + INSERT INTO ft4(ft4) VALUES('rebuild'); +} {} +do_execsql_test 4.1.2 { + SELECT id, quote(value) FROM ft4_stat +} {0 X'000000'} +do_execsql_test 4.1.3 { + SELECT id, quote(value) FROM ft4x_stat +} {0 X'000000'} + +do_execsql_test 4.2.1 { + INSERT INTO ft4x VALUES('M G M F T'); + INSERT INTO ft4x VALUES('Z Q C A U'); + INSERT INTO ft4x VALUES('N L L V'); + INSERT INTO ft4x VALUES('T F D X D'); + INSERT INTO ft4x VALUES('Z H I S D'); + + SELECT id, quote(value) FROM ft4x_stat +} {0 X'05182B'} + +do_execsql_test 4.2.2 { + INSERT INTO ft4(rowid, x) SELECT rowid, * FROM ft4x; + SELECT id, quote(value) FROM ft4_stat +} {0 X'05182B'} + +do_execsql_test 4.2.3 { + SELECT docid, quote(size) FROM ft4_docsize +} {1 X'05' 2 X'05' 3 X'04' 4 X'05' 5 X'05'} + +do_execsql_test 4.2.4 { + INSERT INTO ft4x(ft4x) VALUES('rebuild'); + SELECT id, quote(value) FROM ft4x_stat; + SELECT docid, quote(size) FROM ft4x_docsize +} {0 X'05182B' 1 X'05' 2 X'05' 3 X'04' 4 X'05' 5 X'05'} + +do_execsql_test 4.2.5 { + INSERT INTO ft4(ft4) VALUES('rebuild'); + SELECT id, quote(value) FROM ft4_stat; + SELECT docid, quote(size) FROM ft4_docsize +} {0 X'000000'} + +do_execsql_test 4.2.6 { + INSERT INTO t4(rowid, x) SELECT rowid, x FROM ft4x; + INSERT INTO ft4(ft4) VALUES('rebuild'); + SELECT id, quote(value) FROM ft4_stat; + SELECT docid, quote(size) FROM ft4_docsize +} {0 X'05182B' 1 X'05' 2 X'05' 3 X'04' 4 X'05' 5 X'05'} + + +#------------------------------------------------------------------------- +# Test cases 5.* test that the following commands do not create/move or +# delete a %_content table when used with a content=xxx FTS table. +# +do_execsql_test 5.1.1 { + CREATE TABLE t5(a, b, c, d); + CREATE VIRTUAL TABLE ft5 USING fts4(content=t5); + SELECT name FROM sqlite_master WHERE name LIKE '%t5%'; +} { + t5 ft5 ft5_segments ft5_segdir + sqlite_autoindex_ft5_segdir_1 ft5_docsize ft5_stat +} +do_execsql_test 5.1.2 { + ALTER TABLE ft5 RENAME TO ft6; + SELECT name FROM sqlite_master WHERE name LIKE '%t5%'; +} { + t5 +} +do_execsql_test 5.1.3 { + SELECT name FROM sqlite_master WHERE name LIKE '%t6%'; +} { + ft6 ft6_segments ft6_segdir + sqlite_autoindex_ft6_segdir_1 ft6_docsize ft6_stat +} +do_execsql_test 5.1.4 { + INSERT INTO t5 VALUES('a', 'b', 'c', 'd'); + INSERT INTO ft6(ft6) VALUES('rebuild'); + SELECT rowid FROM ft6 WHERE ft6 MATCH 'b'; +} {1} +do_execsql_test 5.1.5 { + DROP TABLE ft6; + SELECT * FROM t5; +} {a b c d} +do_execsql_test 5.1.6 { + SELECT name FROM sqlite_master WHERE name LIKE '%t6%'; +} { +} +do_execsql_test 5.1.7 { + CREATE VIRTUAL TABLE ft5 USING fts4(content=t5); + CREATE TABLE t5_content(a, b); + DROP TABLE ft5; + SELECT name FROM sqlite_master WHERE name LIKE '%t5%'; +} { + t5 t5_content +} + +#------------------------------------------------------------------------- +# Test cases 6.* test +# +do_catchsql_test 6.1.1 { + CREATE VIRTUAL TABLE ft7 USING fts4(content=t7); +} {1 {no such table: main.t7}} + +do_execsql_test 6.2.1 { + CREATE TABLE t7(one, two); + CREATE VIRTUAL TABLE ft7 USING fts4(content=t7); + INSERT INTO t7 VALUES('A B', 'B A'); + INSERT INTO t7 VALUES('C D', 'A A'); + SELECT * FROM ft7; +} { + {A B} {B A} {C D} {A A} +} + +do_catchsql_test 6.2.2 { + DROP TABLE t7; + SELECT * FROM ft7; +} {1 {SQL logic error}} + +db close +sqlite3 db test.db +do_execsql_test 6.2.3 { + SELECT name FROM sqlite_master WHERE name LIKE '%t7%' +} { + ft7 ft7_segments ft7_segdir sqlite_autoindex_ft7_segdir_1 + ft7_docsize ft7_stat +} +do_catchsql_test 6.2.4 { + SELECT * FROM ft7; +} {1 {no such table: main.t7}} +do_execsql_test 6.2.5 { + CREATE TABLE t7(x, y); + INSERT INTO t7 VALUES('A B', 'B A'); + INSERT INTO t7 VALUES('C D', 'A A'); + SELECT * FROM ft7; +} { + {A B} {B A} {C D} {A A} +} + +do_execsql_test 6.2.6 { + INSERT INTO ft7(ft7) VALUES('rebuild'); + SELECT rowid FROM ft7 WHERE ft7 MATCH '"A A"'; +} {2} + +do_execsql_test 6.2.7 { + DROP TABLE t7; + CREATE TABLE t7(x); +} +do_catchsql_test 6.2.8 { + SELECT * FROM ft7 WHERE ft7 MATCH '"A A"'; +} {1 {SQL logic error}} +do_catchsql_test 6.2.9 { + SELECT * FROM ft7 WHERE ft7 MATCH '"A A"'; +} {1 {SQL logic error}} + +db close +sqlite3 db test.db +do_catchsql_test 6.2.10 { + SELECT rowid FROM ft7 WHERE ft7 MATCH '"A A"'; +} {0 2} +do_catchsql_test 6.2.11 { + SELECT rowid, * FROM ft7 WHERE ft7 MATCH '"A A"'; +} {0 {2 {}}} + +#------------------------------------------------------------------------- +# Test cases 7.* +# +do_execsql_test 7.1.1 { + CREATE VIRTUAL TABLE ft8 USING fts4(content=nosuchtable, x); + INSERT INTO ft8(docid, x) VALUES(13, 'U O N X G'); + INSERT INTO ft8(docid, x) VALUES(14, 'C J J U B'); + INSERT INTO ft8(docid, x) VALUES(15, 'N J Y G X'); + INSERT INTO ft8(docid, x) VALUES(16, 'R Y D O R'); + INSERT INTO ft8(docid, x) VALUES(17, 'I Y T Q O'); +} + +do_execsql_test 7.1.2 { + SELECT docid FROM ft8 WHERE ft8 MATCH 'N'; +} {13 15} + +do_execsql_test 7.2.1 { + CREATE VIRTUAL TABLE ft9 USING fts4(content=, x); + INSERT INTO ft9(docid, x) VALUES(13, 'U O N X G'); + INSERT INTO ft9(docid, x) VALUES(14, 'C J J U B'); + INSERT INTO ft9(docid, x) VALUES(15, 'N J Y G X'); + INSERT INTO ft9(docid, x) VALUES(16, 'R Y D O R'); + INSERT INTO ft9(docid, x) VALUES(17, 'I Y T Q O'); +} +do_execsql_test 7.2.2 { + SELECT docid FROM ft9 WHERE ft9 MATCH 'N'; +} {13 15} +do_execsql_test 7.2.3 { + SELECT name FROM sqlite_master WHERE name LIKE 'ft9_%'; +} {ft9_segments ft9_segdir ft9_docsize ft9_stat} + +do_catchsql_test 7.2.4 { + SELECT * FROM ft9 WHERE ft9 MATCH 'N'; +} {1 {SQL logic error}} + +#------------------------------------------------------------------------- +# Test cases 8.* +# +do_execsql_test 8.1 { + CREATE TABLE t10(a, b); + INSERT INTO t10 VALUES( + 'abasia abasic abask', 'Abassin abastardize abatable'); + INSERT INTO t10 VALUES( + 'abate abatement abater', 'abatis abatised abaton'); + INSERT INTO t10 VALUES( + 'abator abattoir Abatua', 'abature abave abaxial'); + + CREATE VIRTUAL TABLE ft10 USING fts4(content=t10, prefix="2,4", a, b); +} + +do_execsql_test 8.2 { SELECT * FROM ft10 WHERE a MATCH 'ab*'; } +do_execsql_test 8.3 { INSERT INTO ft10(ft10) VALUES('rebuild'); } +do_execsql_test 8.4 { SELECT rowid FROM ft10 WHERE a MATCH 'ab*'; } {1 2 3} +do_execsql_test 8.5 { SELECT rowid FROM ft10 WHERE b MATCH 'abav*'; } {3} +do_execsql_test 8.6 { SELECT rowid FROM ft10 WHERE ft10 MATCH 'abas*'; } {1} + +#------------------------------------------------------------------------- +# Test cases 9.* +# +reset_db +register_echo_module [sqlite3_connection_pointer db] + +do_execsql_test 9.1 { + CREATE TABLE tbl1(a, b); + INSERT INTO tbl1 VALUES('a b', 'c d'); + INSERT INTO tbl1 VALUES('e f', 'a b'); + CREATE VIRTUAL TABLE e1 USING echo(tbl1); + CREATE VIRTUAL TABLE ft1 USING fts4(content=e1); + INSERT INTO ft1(ft1) VALUES('rebuild'); +} + +do_execsql_test 9.2 { + SELECT rowid, * FROM ft1 WHERE ft1 MATCH 'e' +} {2 {e f} {a b}} + +do_execsql_test 9.3 { + SELECT rowid, * FROM ft1 WHERE ft1 MATCH 'a' +} {1 {a b} {c d} 2 {e f} {a b}} + +do_execsql_test 9.4 { + DELETE FROM ft1 WHERE docid=1; +} + +do_execsql_test 9.5 { + SELECT rowid, * FROM ft1 WHERE ft1 MATCH 'a' +} {2 {e f} {a b}} + +do_execsql_test 9.6 { + INSERT INTO ft1(ft1) VALUES('rebuild'); + SELECT rowid, * FROM ft1 WHERE ft1 MATCH 'a' +} {1 {a b} {c d} 2 {e f} {a b}} + + +#------------------------------------------------------------------------- +# Test cases 10.* +# +reset_db +register_fs_module [sqlite3_connection_pointer db] + +proc write_file {path text} { + set fd [open $path w] + puts -nonewline $fd $text + close $fd +} + +write_file t1.txt {a b c d e f g h i j k l m n o p q r s t u v w x y z} +write_file t2.txt {a b c d e f g h i j k l m a b c d e f g h i j k l m} +write_file t3.txt {n o p q r s t u v w x y z n o p q r s t u v w x y z} + +do_execsql_test 10.1 { + CREATE TABLE idx(id INTEGER PRIMARY KEY, path TEXT); + INSERT INTO idx VALUES (1, 't1.txt'); + INSERT INTO idx VALUES (2, 't2.txt'); + INSERT INTO idx VALUES (3, 't3.txt'); + + CREATE VIRTUAL TABLE vt USING fs(idx); + SELECT path, data FROM vt; +} { + 1 {a b c d e f g h i j k l m n o p q r s t u v w x y z} + 2 {a b c d e f g h i j k l m a b c d e f g h i j k l m} + 3 {n o p q r s t u v w x y z n o p q r s t u v w x y z} +} + +do_execsql_test 10.2 { + SELECT path, data FROM vt WHERE rowid = 2; +} { + 2 {a b c d e f g h i j k l m a b c d e f g h i j k l m} +} + +do_execsql_test 10.3 { + CREATE VIRTUAL TABLE ft USING fts4(content=vt); + INSERT INTO ft(ft) VALUES('rebuild'); +} + +do_execsql_test 10.4 { + SELECT snippet(ft, '[', ']', '...', -1, 5) FROM ft WHERE ft MATCH 'e' +} { + {...c d [e] f g...} {...c d [e] f g...} +} + +do_execsql_test 10.5 { + SELECT snippet(ft, '[', ']', '...', -1, 5) FROM ft WHERE ft MATCH 't' +} { + {...r s [t] u v...} {...r s [t] u v...} +} + +do_execsql_test 10.6 { DELETE FROM ft WHERE docid=2 } + +do_execsql_test 10.7 { + SELECT snippet(ft, '[', ']', '...', -1, 5) FROM ft WHERE ft MATCH 'e' +} { + {...c d [e] f g...} +} + +#------------------------------------------------------------------------- +# Test cases 11.* +# +reset_db + +do_catchsql_test 11.1 { + CREATE VIRTUAL TABLE x1 USING fts4(content=x1); +} {1 {vtable constructor called recursively: x1}} + +#--------------------------------------------------------------------------- +# Check that an fts4 table cannot be its own content table. +# +reset_db +breakpoint +do_execsql_test 12.1.1 { + CREATE VIRTUAL TABLE t1 USING fts4(a, content=t1 ); + INSERT INTO t1(rowid, a) VALUES(1, 'abc'); +} +do_catchsql_test 12.1.2 { + SELECT * FROM t1; +} {1 {SQL logic error}} +do_catchsql_test 12.1.3 { + SELECT * FROM t1('abc'); +} {1 {SQL logic error}} +do_catchsql_test 12.1.4 { + SELECT count(*) FROM t1; +} {1 {SQL logic error}} + +reset_db +do_execsql_test 12.2.1 { + CREATE VIRTUAL TABLE t1 USING fts4(a, content=t2 ); + CREATE VIRTUAL TABLE t2 USING fts4(a, content=t1 ); + INSERT INTO t1(rowid, a) VALUES(1, 'abc'); +} +do_catchsql_test 12.2.2 { + SELECT * FROM t1; +} {1 {SQL logic error}} +do_catchsql_test 12.2.3 { + SELECT * FROM t1('abc'); +} {1 {SQL logic error}} +do_catchsql_test 12.2.4 { + SELECT count(*) FROM t1; +} {1 {SQL logic error}} + + + +finish_test diff --git a/test/fts4docid.test b/test/fts4docid.test new file mode 100644 index 0000000..2328b6e --- /dev/null +++ b/test/fts4docid.test @@ -0,0 +1,116 @@ +# 2012 March 26 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/fts3_common.tcl +set ::testprefix fts4docid + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# Initialize a table with pseudo-randomly generated data. +# +do_execsql_test 1.0 { CREATE VIRTUAL TABLE t1 USING fts4; } +do_test 1.1 { + foreach {docid content} { + 0 {F N K B T I K V B A} 1 {D M J E S P H E L O} + 2 {W U T Q T Q T L H G} 3 {D W H M B R S Z B K} + 4 {F Q I N P Q J L Z D} 5 {J O Q E Y A O E L B} + 6 {O V R A C R K C Y H} 7 {Z J H T Q Q O R A G} + 8 {L K J W G D Y W B M} 9 {K E Y I A Q R Q T S} + 10 {N P H Y Z M R T I C} 11 {E X H O I S E S Z F} + 12 {B Y Q T J X C L L J} 13 {Q D C U U A Q E Z U} + 14 {S I T C J R X S J M} 15 {M X M K E X L H Q Y} + 16 {O W E I C H U Y S Y} 17 {P V V E M T H C C S} + 18 {L Y A M I E N M X O} 19 {S Y R U L S Q Y F P} + 20 {U J S T T J J S V X} 21 {T E I W P O V A A P} + 22 {W D K H D H F G O J} 23 {T X Y P G M J U I L} + 24 {F V X E B C N B K W} 25 {E B A Y N N T Z I C} + 26 {G E E B C P U D H G} 27 {J D J K N S B Q T M} + 28 {Q T G M D O D Y V G} 29 {P X W I W V P W Z G} + } { + execsql { INSERT INTO t1(docid, content) VALUES($docid, $content) } + } +} {} + +# Quick test regarding affinites and the docid/rowid column. +do_execsql_test 2.1.1 { SELECT docid FROM t1 WHERE docid = 5 } {5} +do_execsql_test 2.1.2 { SELECT docid FROM t1 WHERE docid = '5' } {5} +do_execsql_test 2.1.3 { SELECT docid FROM t1 WHERE docid = +5 } {5} +do_execsql_test 2.1.4 { SELECT docid FROM t1 WHERE docid = +'5' } {5} +do_execsql_test 2.1.5 { SELECT docid FROM t1 WHERE docid < 5 } {0 1 2 3 4} +do_execsql_test 2.1.6 { SELECT docid FROM t1 WHERE docid < '5' } {0 1 2 3 4} + +do_execsql_test 2.2.1 { SELECT rowid FROM t1 WHERE rowid = 5 } {5} +do_execsql_test 2.2.2 { SELECT rowid FROM t1 WHERE rowid = '5' } {5} +do_execsql_test 2.2.3 { SELECT rowid FROM t1 WHERE rowid = +5 } {5} +do_execsql_test 2.2.4 { SELECT rowid FROM t1 WHERE rowid = +'5' } {5} +do_execsql_test 2.2.5 { SELECT rowid FROM t1 WHERE rowid < 5 } {0 1 2 3 4} +do_execsql_test 2.2.6 { SELECT rowid FROM t1 WHERE rowid < '5' } {0 1 2 3 4} + +#------------------------------------------------------------------------- +# Now test a bunch of full-text queries featuring range constraints on +# the docid field. Each query is run so that the range constraint: +# +# * is on the docid field, +# * is on the docid field with a unary +, +# * is on the rowid field, +# * is on the rowid field with a unary +. +# +# Queries are run with both "ORDER BY docid DESC" and "ORDER BY docid ASC" +# clauses. +# +foreach {tn where result} { + 1 {WHERE t1 MATCH 'O' AND xxx < 17} {1 5 6 7 11 16} + 2 {WHERE t1 MATCH 'O' AND xxx < 4123456789123456} {1 5 6 7 11 16 18 21 22 28} + 3 {WHERE t1 MATCH 'O' AND xxx < 1} {} + 4 {WHERE t1 MATCH 'O' AND xxx < -4123456789123456} {} + + 5 {WHERE t1 MATCH 'O' AND xxx > 17} {18 21 22 28} + 6 {WHERE t1 MATCH 'O' AND xxx > 4123456789123456} {} + 7 {WHERE t1 MATCH 'O' AND xxx > 1} {5 6 7 11 16 18 21 22 28} + 8 {WHERE t1 MATCH 'O' AND xxx > -4123456789123456} {1 5 6 7 11 16 18 21 22 28} + + 9 {WHERE t1 MATCH '"Q T"' AND xxx < 27} {2 9 12} + 10 {WHERE t1 MATCH '"Q T"' AND xxx <= 27} {2 9 12 27} + 11 {WHERE t1 MATCH '"Q T"' AND xxx > 27} {28} + 12 {WHERE t1 MATCH '"Q T"' AND xxx >= 27} {27 28} +} { + foreach {tn2 ref order} { + 1 docid "ORDER BY docid ASC" + 2 +docid "ORDER BY docid ASC" + 3 rowid "ORDER BY docid ASC" + 4 +rowid "ORDER BY docid ASC" + + 5 docid "ORDER BY docid DESC" + 6 +docid "ORDER BY docid DESC" + 7 rowid "ORDER BY docid DESC" + 8 +rowid "ORDER BY docid DESC" + } { + set w [string map "xxx $ref" $where] + set q "SELECT docid FROM t1 $w $order" + + if {$tn2<5} { + set r [lsort -integer -increasing $result] + } else { + set r [lsort -integer -decreasing $result] + } + + do_execsql_test 3.$tn.$tn2 $q $r + } +} + +finish_test diff --git a/test/fts4growth.test b/test/fts4growth.test new file mode 100644 index 0000000..5cf8777 --- /dev/null +++ b/test/fts4growth.test @@ -0,0 +1,441 @@ +# 2014 May 12 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS4 module. +# +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts4growth + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +source $testdir/genesis.tcl + +sqlite3_db_config db DEFENSIVE 0 +do_execsql_test 1.1 { CREATE VIRTUAL TABLE x1 USING fts3; } + +do_test 1.2 { + foreach L { + {"See here, young man," said Mulga Bill, "from Walgett to the sea,} + {From Conroy's Gap to Castlereagh, there's none can ride like me.} + {I'm good all round at everything as everybody knows,} + {Although I'm not the one to talk -- I hate a man that blows.} + } { + execsql { INSERT INTO x1 VALUES($L) } + } + execsql { SELECT end_block, length(root) FROM x1_segdir } +} {{0 114} 114 {0 118} 118 {0 95} 95 {0 115} 115} + +do_execsql_test 1.3 { + INSERT INTO x1(x1) VALUES('optimize'); + SELECT level, end_block, length(root) FROM x1_segdir; +} {0 {0 394} 394} + +do_test 1.4 { + foreach L { + {But riding is my special gift, my chiefest, sole delight;} + {Just ask a wild duck can it swim, a wildcat can it fight.} + {There's nothing clothed in hair or hide, or built of flesh or steel,} + {There's nothing walks or jumps, or runs, on axle, hoof, or wheel,} + {But what I'll sit, while hide will hold and girths and straps are tight:} + {I'll ride this here two-wheeled concern right straight away at sight."} + } { + execsql { INSERT INTO x1 VALUES($L) } + } + execsql { + INSERT INTO x1(x1) VALUES('merge=4,4'); + SELECT level, end_block, length(root) FROM x1_segdir; + } +} {1 {224 921} 2} + +do_execsql_test 1.5 { + SELECT length(block) FROM x1_segments; +} {921 {}} + +do_test 1.6 { + foreach L { + {'Twas Mulga Bill, from Eaglehawk, that sought his own abode,} + {That perched above Dead Man's Creek, beside the mountain road.} + {He turned the cycle down the hill and mounted for the fray,} + {But 'ere he'd gone a dozen yards it bolted clean away.} + + {It left the track, and through the trees, just like a silver steak,} + {It whistled down the awful slope towards the Dead Man's Creek.} + {It shaved a stump by half an inch, it dodged a big white-box:} + {The very wallaroos in fright went scrambling up the rocks,} + + {The wombats hiding in their caves dug deeper underground,} + {As Mulga Bill, as white as chalk, sat tight to every bound.} + {It struck a stone and gave a spring that cleared a fallen tree,} + {It raced beside a precipice as close as close could be;} + + {And then as Mulga Bill let out one last despairing shriek} + {It made a leap of twenty feet into the Dead Man's Creek.} + {It shaved a stump by half an inch, it dodged a big white-box:} + {The very wallaroos in fright went scrambling up the rocks,} + {The wombats hiding in their caves dug deeper underground,} + } { + execsql { INSERT INTO x1 VALUES($L) } + } + execsql { + SELECT level, end_block, length(root) FROM x1_segdir; + } +} {1 {224 921} 2 1 {226 1230} 7 0 {0 98} 98} + +do_execsql_test 1.7 { + SELECT sum(length(block)) FROM x1_segments WHERE blockid IN (224,225,226) +} {1230} + +#------------------------------------------------------------------------- +# +do_execsql_test 2.1 { + CREATE TABLE t1(docid, words); + CREATE VIRTUAL TABLE x2 USING fts4; +} +fts_kjv_genesis +do_test 2.2 { + foreach id [db eval {SELECT docid FROM t1}] { + execsql { + INSERT INTO x2(docid, content) SELECT $id, words FROM t1 WHERE docid=$id + } + } + foreach id [db eval {SELECT docid FROM t1}] { + execsql { + INSERT INTO x2(docid, content) SELECT NULL, words FROM t1 WHERE docid=$id + } + if {[db one {SELECT count(*) FROM x2_segdir WHERE level<2}]==2} break + } +} {} + +do_execsql_test 2.3 { + SELECT count(*) FROM x2_segdir WHERE level=2; + SELECT count(*) FROM x2_segdir WHERE level=3; +} {6 0} + +do_execsql_test 2.4 { + INSERT INTO x2(x2) VALUES('merge=4,4'); + SELECT count(*) FROM x2_segdir WHERE level=2; + SELECT count(*) FROM x2_segdir WHERE level=3; +} {6 1} + +do_execsql_test 2.5 { + SELECT end_block FROM x2_segdir WHERE level=3; + INSERT INTO x2(x2) VALUES('merge=4,4'); + SELECT end_block FROM x2_segdir WHERE level=3; + INSERT INTO x2(x2) VALUES('merge=4,4'); + SELECT end_block FROM x2_segdir WHERE level=3; +} {{5588 -3950} {5588 -11766} {5588 -15541}} + +do_execsql_test 2.6 { + SELECT sum(length(block)) FROM x2_segdir, x2_segments WHERE + blockid BETWEEN start_block AND leaves_end_block + AND level=3 +} {15541} + +do_execsql_test 2.7 { + INSERT INTO x2(x2) VALUES('merge=1000,4'); + SELECT end_block FROM x2_segdir WHERE level=3; +} {{5588 127563}} + +do_execsql_test 2.8 { + SELECT sum(length(block)) FROM x2_segdir, x2_segments WHERE + blockid BETWEEN start_block AND leaves_end_block + AND level=3 +} {127563} + +#-------------------------------------------------------------------------- +# Test that delete markers are removed from FTS segments when possible. +# It is only possible to remove delete markers when the output of the +# merge operation will become the oldest segment in the index. +# +# 3.1 - when the oldest segment is created by an 'optimize'. +# 3.2 - when the oldest segment is created by an incremental merge. +# 3.3 - by a crisis merge. +# + +proc insert_doc {args} { + foreach iDoc $args { + set L [lindex { + {In your eagerness to engage the Trojans,} + {don’t any of you charge ahead of others,} + {trusting in your strength and horsemanship.} + {And don’t lag behind. That will hurt our charge.} + {Any man whose chariot confronts an enemy’s} + {should thrust with his spear at him from there.} + {That’s the most effective tactic, the way} + {men wiped out city strongholds long ago —} + {their chests full of that style and spirit.} + } [expr $iDoc%9]] + execsql { REPLACE INTO x3(docid, content) VALUES($iDoc, $L) } + } +} + +proc delete_doc {args} { + foreach iDoc $args { + execsql { DELETE FROM x3 WHERE docid = $iDoc } + } +} + +proc second {x} { lindex $x 1 } +db func second second + +do_execsql_test 3.0 { CREATE VIRTUAL TABLE x3 USING fts4 } + +do_test 3.1.1 { + db transaction { insert_doc 1 2 3 4 5 6 } + execsql { SELECT level, idx, second(end_block) FROM x3_segdir } +} {0 0 412} +do_test 3.1.2 { + delete_doc 1 2 3 4 5 6 + execsql { SELECT count(*) FROM x3_segdir } +} {0} +do_test 3.1.3 { + db transaction { + insert_doc 1 2 3 4 5 6 7 8 9 + delete_doc 9 8 7 + } + execsql { SELECT level, idx, second(end_block) FROM x3_segdir } +} {0 0 591 0 1 65 0 2 72 0 3 76} +do_test 3.1.4 { + execsql { INSERT INTO x3(x3) VALUES('optimize') } + execsql { SELECT level, idx, second(end_block) FROM x3_segdir } +} {0 0 412} + +do_test 3.2.1 { + execsql { DELETE FROM x3 } + insert_doc 8 7 6 5 4 3 2 1 + delete_doc 7 8 + execsql { SELECT count(*) FROM x3_segdir } +} {10} +do_test 3.2.2 { + execsql { INSERT INTO x3(x3) VALUES('merge=500,10') } + execsql { SELECT level, idx, second(end_block) FROM x3_segdir } +} {1 0 412} + +# This assumes the crisis merge happens when there are already 16 +# segments and one more is added. +# +do_test 3.3.1 { + execsql { DELETE FROM x3 } + insert_doc 1 2 3 4 5 6 7 8 9 10 11 + delete_doc 11 10 9 8 7 + execsql { SELECT count(*) FROM x3_segdir } +} {16} + +do_test 3.3.2 { + insert_doc 12 + execsql { SELECT level, idx, second(end_block) FROM x3_segdir WHERE level=1 } +} {1 0 412} + +#-------------------------------------------------------------------------- +# Check a theory on a bug in fts4 - that segments with idx==0 were not +# being incrementally merged correctly. Theory turned out to be false. +# +do_execsql_test 4.1 { + DROP TABLE IF EXISTS x4; + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(docid, words); + CREATE VIRTUAL TABLE x4 USING fts4(words); +} +do_test 4.2 { + fts_kjv_genesis + execsql { INSERT INTO x4 SELECT words FROM t1 } + execsql { INSERT INTO x4 SELECT words FROM t1 } +} {} + +do_execsql_test 4.3 { + SELECT level, idx, second(end_block) FROM x4_segdir +} {0 0 117483 0 1 118006} + +do_execsql_test 4.4 { + INSERT INTO x4(x4) VALUES('merge=10,2'); + SELECT count(*) FROM x4_segdir; +} {3} + +do_execsql_test 4.5 { + INSERT INTO x4(x4) VALUES('merge=10,2'); + SELECT count(*) FROM x4_segdir; +} {3} + +do_execsql_test 4.6 { + INSERT INTO x4(x4) VALUES('merge=1000,2'); + SELECT count(*) FROM x4_segdir; +} {1} + + + +#-------------------------------------------------------------------------- +# Check that segments are not promoted if the "end_block" field does not +# contain a size. +# +do_execsql_test 5.1 { + DROP TABLE IF EXISTS x2; + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(docid, words); + CREATE VIRTUAL TABLE x2 USING fts4; +} +fts_kjv_genesis + +proc first {L} {lindex $L 0} +db func first first + +do_test 5.2 { + foreach r [db eval { SELECT rowid FROM t1 }] { + execsql { + INSERT INTO x2(docid, content) SELECT docid, words FROM t1 WHERE rowid=$r + } + } + foreach d [db eval { SELECT docid FROM t1 LIMIT -1 OFFSET 20 }] { + execsql { DELETE FROM x2 WHERE docid = $d } + } + + execsql { + INSERT INTO x2(x2) VALUES('optimize'); + SELECT level, idx, end_block FROM x2_segdir + } +} {2 0 {752 1926}} + +do_execsql_test 5.3 { + UPDATE x2_segdir SET end_block = CAST( first(end_block) AS INTEGER ); + SELECT end_block, typeof(end_block) FROM x2_segdir; +} {752 integer} + +do_execsql_test 5.4 { + INSERT INTO x2 SELECT words FROM t1 LIMIT 50; + SELECT level, idx, end_block FROM x2_segdir +} {2 0 752 0 0 {758 5174}} + +do_execsql_test 5.5 { + UPDATE x2_segdir SET end_block = end_block || ' 1926' WHERE level=2; + INSERT INTO x2 SELECT words FROM t1 LIMIT 40; + SELECT level, idx, end_block FROM x2_segdir +} {0 0 {752 1926} 0 1 {758 5174} 0 2 {763 4170}} + +proc t1_to_x2 {} { + foreach id [db eval {SELECT docid FROM t1 LIMIT 2}] { + execsql { + DELETE FROM x2 WHERE docid=$id; + INSERT INTO x2(docid, content) SELECT $id, words FROM t1 WHERE docid=$id; + } + } +} + +#-------------------------------------------------------------------------- +# Check that segments created by auto-merge are not promoted until they +# are completed. +# + +do_execsql_test 6.1 { + CREATE VIRTUAL TABLE x5 USING fts4; + INSERT INTO x5 SELECT words FROM t1 LIMIT 100 OFFSET 0; + INSERT INTO x5 SELECT words FROM t1 LIMIT 100 OFFSET 25; + INSERT INTO x5 SELECT words FROM t1 LIMIT 100 OFFSET 50; + INSERT INTO x5 SELECT words FROM t1 LIMIT 100 OFFSET 75; + SELECT count(*) FROM x5_segdir +} {4} + +do_execsql_test 6.2 { + INSERT INTO x5(x5) VALUES('merge=2,4'); + SELECT level, idx, end_block FROM x5_segdir; +} {0 0 {10 9216} 0 1 {21 9330} 0 2 {31 8850} 0 3 {40 8689} 1 0 {1320 -3117}} + +do_execsql_test 6.3 { + INSERT INTO x5 SELECT words FROM t1 LIMIT 100 OFFSET 100; + SELECT level, idx, end_block FROM x5_segdir; +} { + 0 0 {10 9216} 0 1 {21 9330} 0 2 {31 8850} + 0 3 {40 8689} 1 0 {1320 -3117} 0 4 {1329 8297} +} + +do_execsql_test 6.4 { + INSERT INTO x5(x5) VALUES('merge=200,4'); + SELECT level, idx, end_block FROM x5_segdir; +} {0 0 {1329 8297} 1 0 {1320 28009}} + +do_execsql_test 6.5 { + INSERT INTO x5 SELECT words FROM t1; + SELECT level, idx, end_block FROM x5_segdir; +} { + 0 1 {1329 8297} 0 0 {1320 28009} 0 2 {1449 118006} +} + +#-------------------------------------------------------------------------- +# Ensure that if part of an incremental merge is performed by an old +# version that does not support storing segment sizes in the end_block +# field, no size is stored in the final segment (as it would be incorrect). +# +do_execsql_test 7.1 { + CREATE VIRTUAL TABLE x6 USING fts4; + INSERT INTO x6 SELECT words FROM t1; + INSERT INTO x6 SELECT words FROM t1; + INSERT INTO x6 SELECT words FROM t1; + INSERT INTO x6 SELECT words FROM t1; + INSERT INTO x6 SELECT words FROM t1; + INSERT INTO x6 SELECT words FROM t1; + SELECT level, idx, end_block FROM x6_segdir; +} { + 0 0 {118 117483} 0 1 {238 118006} 0 2 {358 118006} + 0 3 {478 118006} 0 4 {598 118006} 0 5 {718 118006} +} + +do_execsql_test 7.2 { + INSERT INTO x6(x6) VALUES('merge=25,4'); + SELECT level, idx, end_block FROM x6_segdir; +} { + 0 0 {118 117483} 0 1 {238 118006} 0 2 {358 118006} + 0 3 {478 118006} 0 4 {598 118006} 0 5 {718 118006} + 1 0 {23694 -69477} +} + +do_execsql_test 7.3 { + UPDATE x6_segdir SET end_block = first(end_block) WHERE level=1; + SELECT level, idx, end_block FROM x6_segdir; +} { + 0 0 {118 117483} 0 1 {238 118006} 0 2 {358 118006} + 0 3 {478 118006} 0 4 {598 118006} 0 5 {718 118006} + 1 0 23694 +} + +do_execsql_test 7.4 { + INSERT INTO x6(x6) VALUES('merge=25,4'); + SELECT level, idx, end_block FROM x6_segdir; +} { + 0 0 {118 117483} 0 1 {238 118006} 0 2 {358 118006} + 0 3 {478 118006} 0 4 {598 118006} 0 5 {718 118006} + 1 0 23694 +} + +do_execsql_test 7.5 { + INSERT INTO x6(x6) VALUES('merge=2500,4'); + SELECT level, idx, start_block, leaves_end_block, end_block FROM x6_segdir; +} { + 1 0 719 1171 23694 +} + +do_execsql_test 7.6 { + INSERT INTO x6(x6) VALUES('merge=2500,2'); + SELECT level, idx, start_block, leaves_end_block, end_block FROM x6_segdir; +} { + 1 0 719 1171 23694 +} + +do_execsql_test 7.7 { + SELECT sum(length(block)) FROM x6_segments +} {635247} + + +finish_test diff --git a/test/fts4growth2.test b/test/fts4growth2.test new file mode 100644 index 0000000..bcccf89 --- /dev/null +++ b/test/fts4growth2.test @@ -0,0 +1,92 @@ +# 2014 May 12 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS4 module. +# +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts4growth2 + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +source $testdir/genesis.tcl + +do_execsql_test 1.0 { CREATE TABLE t1(docid, words); } +fts_kjv_genesis + +proc structure {} { + puts [ db eval {SELECT level, count(*) FROM x1_segdir GROUP BY level} ] +} + +proc tt {val} { + execsql { + DELETE FROM x1 + WHERE docid IN (SELECT docid FROM t1 WHERE (rowid-1)%4==$val+0); + } + execsql { + INSERT INTO x1(docid, content) + SELECT docid, words FROM t1 WHERE (rowid%4)==$val+0; + } +} + +do_execsql_test 1.1 { + CREATE VIRTUAL TABLE x1 USING fts4; + INSERT INTO x1(x1) VALUES('automerge=2'); +} + +do_test 1.2 { + for {set i 0} {$i < 40} {incr i} { + tt 0 ; tt 1 ; tt 2 ; tt 3 + } + execsql { + SELECT max(level) FROM x1_segdir; + SELECT count(*) FROM x1_segdir WHERE level=2; + } +} {2 1} + +do_test 1.3 { + for {set i 0} {$i < 40} {incr i} { + tt 0 ; tt 1 ; tt 2 ; tt 3 + } + execsql { + SELECT max(level) FROM x1_segdir; + SELECT count(*) FROM x1_segdir WHERE level=2; + } +} {2 1} + +#------------------------------------------------------------------------- +# +do_execsql_test 2.1 { + DELETE FROM t1 WHERE rowid>16; + DROP TABLE IF EXISTS x1; + CREATE VIRTUAL TABLE x1 USING fts4; +} + +db func second second +proc second {L} {lindex $L 1} + +for {set tn 0} {$tn < 40} {incr tn} { + do_test 2.2.$tn { + for {set i 0} {$i < 100} {incr i} { + tt 0 ; tt 1 ; tt 2 ; tt 3 + } + execsql { SELECT max(level) FROM x1_segdir } + } {1} +} + + +finish_test diff --git a/test/fts4incr.test b/test/fts4incr.test new file mode 100644 index 0000000..9210488 --- /dev/null +++ b/test/fts4incr.test @@ -0,0 +1,77 @@ +# 2012 March 26 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/fts3_common.tcl +set ::testprefix fts4incr + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# Create the fts_kjv_genesis procedure which fills and FTS3/4 table +# with the complete text of the Book of Genesis. +# +source $testdir/genesis.tcl + +do_test 1.0 { + execsql { CREATE VIRTUAL TABLE t1 USING fts4(words) } + fts_kjv_genesis +} {} + +do_execsql_test 1.1 { + SELECT min(docid), max(docid) FROM t1; +} {1001001 1050026} + +foreach {tn q res} { + 1 { SELECT count(*) FROM t1 WHERE t1 MATCH 'and' AND docid < 1010000} 224 + 2 { SELECT count(*) FROM t1 WHERE t1 MATCH '"in the"' AND docid < 1010000} 47 + 3 { SELECT count(*) FROM t1 WHERE t1 MATCH '"And God"' AND docid < 1010000} 33 + 4 { SELECT count(*) FROM t1 WHERE t1 + MATCH '"land of canaan"' AND docid < 1030000 } 7 +} { + foreach s {0 1} { + execsql "INSERT INTO t1(t1) VALUES('test-no-incr-doclist=$s')" + do_execsql_test 2.$tn.$s $q $res + set t($s) [lindex [time [list execsql $q] 100] 0] + } + if {0} { + puts "with optimization: $t(0) without: $t(1)" + } +} + +do_test 2.1 { + execsql { + CREATE VIRTUAL TABLE t2 USING fts4(order=DESC); + } + set num [list one two three four five six seven eight nine ten] + execsql BEGIN + for {set i 0} {$i < 10000} {incr i} { + set x "[lindex $num [expr $i%10]] zero" + execsql { INSERT INTO t2(docid, content) VALUES($i, $x) } + } + execsql COMMIT + execsql { INSERT INTO t2(t2) VALUES('optimize') } +} {} + +do_execsql_test 2.2 { + SELECT count(*) FROM t2 WHERE t2 MATCH '"never zero"' +} {0} + +do_execsql_test 2.3 { + SELECT count(*) FROM t2 WHERE t2 MATCH '"two zero"' +} {1000} + +finish_test diff --git a/test/fts4intck1.test b/test/fts4intck1.test new file mode 100644 index 0000000..6596b2f --- /dev/null +++ b/test/fts4intck1.test @@ -0,0 +1,75 @@ +# 2023-10-23 +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Test PRAGMA integrity_check against and FTS3/FTS4 table. +# + + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !fts3 { finish_test ; return } + +set ::testprefix fts4intck1 + +proc slang {in} { + return [string map {th d e eh} $in] +} + +db function slang -deterministic -innocuous slang +do_execsql_test 1.0 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c TEXT AS (slang(b))); + INSERT INTO t1(b) VALUES('the quick fox jumps over the lazy brown dog'); + SELECT c FROM t1; +} {{deh quick fox jumps ovehr deh lazy brown dog}} + +do_execsql_test 1.1 { + CREATE VIRTUAL TABLE t2 USING fts4(content="t1", c); + INSERT INTO t2(t2) VALUES('rebuild'); + SELECT docid FROM t2 WHERE t2 MATCH 'deh'; +} {1} + +do_execsql_test 1.2 { + PRAGMA integrity_check(t2); +} {ok} + +db close +sqlite3 db test.db +do_execsql_test 2.1 { + PRAGMA integrity_check(t2); +} {{unable to validate the inverted index for FTS4 table main.t2: SQL logic error}} + +db function slang -deterministic -innocuous slang +do_execsql_test 2.2 { + PRAGMA integrity_check(t2); +} {ok} + +proc slang {in} {return $in} +do_execsql_test 2.3 { + PRAGMA integrity_check(t2); +} {{malformed inverted index for FTS4 table main.t2}} + +#------------------------------------------------------------------------- +# Test that integrity-check works on a read-only database. +# +reset_db +do_execsql_test 3.0 { + CREATE VIRTUAL TABLE x1 USING fts4(a, b); + INSERT INTO x1 VALUES('one', 'two'); + INSERT INTO x1 VALUES('three', 'four'); +} +db close +sqlite3 db test.db -readonly 1 + +do_execsql_test 3.1 { + PRAGMA integrity_check; +} {ok} + + + +finish_test diff --git a/test/fts4langid.test b/test/fts4langid.test new file mode 100644 index 0000000..7be594b --- /dev/null +++ b/test/fts4langid.test @@ -0,0 +1,508 @@ +# 2012 March 01 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the languageid=xxx FTS4 option. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +set ::testprefix fts4langid + +#--------------------------------------------------------------------------- +# Test plan: +# +# 1.* - Warm-body tests created for specific purposes during development. +# Passing these doesn't really prove much. +# +# 2.1.* - Test that FTS queries only ever return rows associated with +# the requested language. +# +# 2.2.* - Same as 2.1.*, after an 'optimize' command. +# +# 2.3.* - Same as 2.1.*, after a 'rebuild' command. +# +# 3.* - Tests with content= tables. Both where there is a real +# underlying content table and where there is not. +# +# 4.* - Test that if one is provided, the tokenizer xLanguage method +# is called to configure the tokenizer before tokenizing query +# or document text. +# +# 5.* - Test the fts4aux table when the associated FTS4 table contains +# multiple languages. +# + +do_execsql_test 1.1 { + CREATE VIRTUAL TABLE t1 USING fts4(a, b, languageid=lang_id); +} + +do_execsql_test 1.2 { + SELECT sql FROM sqlite_master WHERE name = 't1_content'; +} {{CREATE TABLE 't1_content'(docid INTEGER PRIMARY KEY, 'c0a', 'c1b', langid)}} + +do_execsql_test 1.3 {SELECT docid FROM t1} {} +do_execsql_test 1.4 {SELECT lang_id FROM t1} {} + +do_execsql_test 1.5 {INSERT INTO t1(a, b) VALUES('aaa', 'bbb')} +do_execsql_test 1.6 {SELECT lang_id FROM t1 } {0} + +do_execsql_test 1.7 {INSERT INTO t1(a, b, lang_id) VALUES('aaa', 'bbb', 4)} +do_execsql_test 1.8 {SELECT lang_id FROM t1 } {0 4} + +do_execsql_test 1.9 {INSERT INTO t1(a, b, lang_id) VALUES('aaa', 'bbb', 'xyz')} +do_execsql_test 1.10 {SELECT lang_id FROM t1} {0 4 0} + +do_execsql_test 1.11 { + CREATE VIRTUAL TABLE t2 USING fts4; + INSERT INTO t2 VALUES('abc'); +} +do_execsql_test 1.12 { SELECT rowid FROM t2 WHERE content MATCH 'abc' } 1 + +do_execsql_test 1.13 { + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING fts4(languageid=lang_id); + INSERT INTO t1(content) VALUES('a b c'); + INSERT INTO t1(content, lang_id) VALUES('a b c', 1); +} + +do_execsql_test 1.14 { + SELECT rowid FROM t1 WHERE t1 MATCH 'b'; +} {1} +do_execsql_test 1.15 { + SELECT rowid FROM t1 WHERE t1 MATCH 'b' AND lang_id = 0; +} {1} + +do_execsql_test 1.16 { + SELECT rowid FROM t1 WHERE t1 MATCH 'b' AND lang_id = 1; +} {2} + +do_catchsql_test 1.17 { + INSERT INTO t1(content, lang_id) VALUES('123', -1); +} {1 {constraint failed}} + +do_execsql_test 1.18 { + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING fts4(languageid=lang_id); + INSERT INTO t1(content, lang_id) VALUES('A', 13); + INSERT INTO t1(content, lang_id) VALUES('B', 13); + INSERT INTO t1(content, lang_id) VALUES('C', 13); + INSERT INTO t1(content, lang_id) VALUES('D', 13); + INSERT INTO t1(content, lang_id) VALUES('E', 13); + INSERT INTO t1(content, lang_id) VALUES('F', 13); + INSERT INTO t1(content, lang_id) VALUES('G', 13); + INSERT INTO t1(content, lang_id) VALUES('H', 13); + INSERT INTO t1(content, lang_id) VALUES('I', 13); + INSERT INTO t1(content, lang_id) VALUES('J', 13); + INSERT INTO t1(content, lang_id) VALUES('K', 13); + INSERT INTO t1(content, lang_id) VALUES('L', 13); + INSERT INTO t1(content, lang_id) VALUES('M', 13); + INSERT INTO t1(content, lang_id) VALUES('N', 13); + INSERT INTO t1(content, lang_id) VALUES('O', 13); + INSERT INTO t1(content, lang_id) VALUES('P', 13); + INSERT INTO t1(content, lang_id) VALUES('Q', 13); + INSERT INTO t1(content, lang_id) VALUES('R', 13); + INSERT INTO t1(content, lang_id) VALUES('S', 13); + SELECT rowid FROM t1 WHERE t1 MATCH 'A'; +} {} + + +#------------------------------------------------------------------------- +# Test cases 2.* +# +proc build_multilingual_db_1 {db} { + $db eval { CREATE VIRTUAL TABLE t2 USING fts4(x, y, languageid=l) } + + set xwords [list zero one two three four five six seven eight nine ten] + set ywords [list alpha beta gamma delta epsilon zeta eta theta iota kappa] + + for {set i 0} {$i < 1000} {incr i} { + set iLangid [expr $i%9] + set x "" + set y "" + + set x [list] + lappend x [lindex $xwords [expr ($i / 1000) % 10]] + lappend x [lindex $xwords [expr ($i / 100) % 10]] + lappend x [lindex $xwords [expr ($i / 10) % 10]] + lappend x [lindex $xwords [expr ($i / 1) % 10]] + + set y [list] + lappend y [lindex $ywords [expr ($i / 1000) % 10]] + lappend y [lindex $ywords [expr ($i / 100) % 10]] + lappend y [lindex $ywords [expr ($i / 10) % 10]] + lappend y [lindex $ywords [expr ($i / 1) % 10]] + + $db eval { INSERT INTO t2(docid, x, y, l) VALUES($i, $x, $y, $iLangid) } + } + + $db eval { + CREATE TABLE data(x, y, l); + INSERT INTO data(rowid, x, y, l) SELECT docid, x, y, l FROM t2; + } +} + +proc rowid_list_set_langid {langid} { + set ::rowid_list_langid $langid +} +proc rowid_list {pattern} { + set langid $::rowid_list_langid + set res [list] + db eval {SELECT rowid, x, y FROM data WHERE l = $langid ORDER BY rowid ASC} { + if {[string match "*$pattern*" $x] || [string match "*$pattern*" $y]} { + lappend res $rowid + } + } + return $res +} + +proc or_merge_list {list1 list2} { + set res [list] + + set i1 0 + set i2 0 + + set n1 [llength $list1] + set n2 [llength $list2] + + while {$i1 < $n1 && $i2 < $n2} { + set e1 [lindex $list1 $i1] + set e2 [lindex $list2 $i2] + + if {$e1==$e2} { + lappend res $e1 + incr i1 + incr i2 + } elseif {$e1 < $e2} { + lappend res $e1 + incr i1 + } else { + lappend res $e2 + incr i2 + } + } + + concat $res [lrange $list1 $i1 end] [lrange $list2 $i2 end] +} + +proc or_merge_lists {args} { + set res [lindex $args 0] + for {set i 1} {$i < [llength $args]} {incr i} { + set res [or_merge_list $res [lindex $args $i]] + } + set res +} + +proc and_merge_list {list1 list2} { + foreach i $list2 { set a($i) 1 } + set res [list] + foreach i $list1 { + if {[info exists a($i)]} {lappend res $i} + } + set res +} + + +proc and_merge_lists {args} { + set res [lindex $args 0] + for {set i 1} {$i < [llength $args]} {incr i} { + set res [and_merge_list $res [lindex $args $i]] + } + set res +} + +proc filter_list {list langid} { + set res [list] + foreach i $list { + if {($i % 9) == $langid} {lappend res $i} + } + set res +} + +do_test 2.0 { + reset_db + build_multilingual_db_1 db +} {} + +proc do_test_query1 {tn query res_script} { + for {set langid 0} {$langid < 10} {incr langid} { + rowid_list_set_langid $langid + set res [eval $res_script] + + set actual [ + execsql {SELECT docid FROM t2 WHERE t2 MATCH $query AND l = $langid} + ] + do_test $tn.$langid [list set {} $actual] $res + } +} + +# Run some queries. +do_test_query1 2.1.1 {delta} { rowid_list delta } +do_test_query1 2.1.2 {"zero one two"} { rowid_list "zero one two" } +do_test_query1 2.1.3 {zero one two} { + and_merge_lists [rowid_list zero] [rowid_list one] [rowid_list two] +} +do_test_query1 2.1.4 {"zero one" OR "one two"} { + or_merge_lists [rowid_list "zero one"] [rowid_list "one two"] +} + +# Now try the same tests as above, but after running the 'optimize' +# command on the FTS table. +# +do_execsql_test 2.2 { + INSERT INTO t2(t2) VALUES('optimize'); + SELECT count(*) FROM t2_segdir; +} {9} +do_test_query1 2.2.1 {delta} { rowid_list delta } +do_test_query1 2.2.2 {"zero one two"} { rowid_list "zero one two" } +do_test_query1 2.2.3 {zero one two} { + and_merge_lists [rowid_list zero] [rowid_list one] [rowid_list two] +} +do_test_query1 2.2.4 {"zero one" OR "one two"} { + or_merge_lists [rowid_list "zero one"] [rowid_list "one two"] +} + +# And rebuild. +# +do_test 2.3 { + reset_db + build_multilingual_db_1 db + execsql { INSERT INTO t2(t2) VALUES('rebuild') } +} {} +do_test_query1 2.3.1 {delta} { rowid_list delta } +do_test_query1 2.3.2 {"zero one two"} { rowid_list "zero one two" } +do_test_query1 2.3.3 {zero one two} { + and_merge_lists [rowid_list zero] [rowid_list one] [rowid_list two] +} +do_test_query1 2.3.4 {"zero one" OR "one two"} { + or_merge_lists [rowid_list "zero one"] [rowid_list "one two"] +} + +#------------------------------------------------------------------------- +# Test cases 3.* +# +do_test 3.0 { + reset_db + build_multilingual_db_1 db + execsql { + CREATE TABLE t3_data(l, x, y); + INSERT INTO t3_data(rowid, l, x, y) SELECT docid, l, x, y FROM t2; + DROP TABLE t2; + } +} {} +do_execsql_test 3.1 { + CREATE VIRTUAL TABLE t2 USING fts4(content=t3_data, languageid=l); + INSERT INTO t2(t2) VALUES('rebuild'); +} + +do_test_query1 3.1.1 {delta} { rowid_list delta } +do_test_query1 3.1.2 {"zero one two"} { rowid_list "zero one two" } +do_test_query1 3.1.3 {zero one two} { + and_merge_lists [rowid_list zero] [rowid_list one] [rowid_list two] +} +do_test_query1 3.1.4 {"zero one" OR "one two"} { + or_merge_lists [rowid_list "zero one"] [rowid_list "one two"] +} + +do_execsql_test 3.2.1 { + DROP TABLE t2; + CREATE VIRTUAL TABLE t2 USING fts4(x, y, languageid=l, content=nosuchtable); +} + +do_execsql_test 3.2.2 { + INSERT INTO t2(docid, x, y, l) SELECT rowid, x, y, l FROM t3_data; +} + +do_execsql_test 3.2.3 { + DROP TABLE t3_data; +} + +do_test_query1 3.3.1 {delta} { rowid_list delta } +do_test_query1 3.3.2 {"zero one two"} { rowid_list "zero one two" } +do_test_query1 3.3.3 {zero one two} { + and_merge_lists [rowid_list zero] [rowid_list one] [rowid_list two] +} +do_test_query1 3.3.4 {"zero one" OR "one two"} { + or_merge_lists [rowid_list "zero one"] [rowid_list "one two"] +} + +do_execsql_test 3.4 { + CREATE TABLE t8c(a, b); + CREATE VIRTUAL TABLE t8 USING fts4(content=t8c, languageid=langid); + INSERT INTO t8(docid, a, b) VALUES(-1, 'one two three', 'x y z'); + SELECT docid FROM t8 WHERE t8 MATCH 'one x' AND langid=0 +} {-1} + +#------------------------------------------------------------------------- +# Test cases 4.* +# +proc build_multilingual_db_2 {db} { + $db eval { + CREATE VIRTUAL TABLE t4 USING fts4( + tokenize=testtokenizer, + languageid=lid + ); + } + for {set i 0} {$i < 50} {incr i} { + execsql { + INSERT INTO t4(docid, content, lid) VALUES($i, 'The Quick Brown Fox', $i) + } + } +} + +do_test 4.1.0 { + reset_db + set ptr [fts3_test_tokenizer] + sqlite3_db_config db SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1 + execsql { SELECT fts3_tokenizer('testtokenizer', $ptr) } + build_multilingual_db_2 db +} {} +do_execsql_test 4.1.1 { + SELECT docid FROM t4 WHERE t4 MATCH 'quick'; +} {0} +do_execsql_test 4.1.2 { + SELECT docid FROM t4 WHERE t4 MATCH 'quick' AND lid=1; +} {} +do_execsql_test 4.1.3 { + SELECT docid FROM t4 WHERE t4 MATCH 'Quick' AND lid=1; +} {1} +for {set i 0} {$i < 50} {incr i} { + do_execsql_test 4.1.4.$i { + SELECT count(*) FROM t4 WHERE t4 MATCH 'fox' AND lid=$i; + } [expr 0==($i%2)] +} +do_catchsql_test 4.1.5 { + INSERT INTO t4(content, lid) VALUES('hello world', 101) +} {1 {SQL logic error}} + +#------------------------------------------------------------------------- +# Test cases 5.* +# +# The following test cases are designed to detect a 32-bit overflow bug +# that existed at one point. +# +proc build_multilingual_db_3 {db} { + $db eval { + CREATE VIRTUAL TABLE t5 USING fts4(languageid=lid); + } + set languages [list 0 1 2 [expr 1<<30]] + + foreach lid $languages { + execsql { + INSERT INTO t5(docid, content, lid) VALUES( + $lid, 'My language is ' || $lid, $lid + ) + } + } +} + +do_test 5.1.0 { + reset_db + build_multilingual_db_3 db +} {} + +do_execsql_test 5.1.1 { + SELECT level FROM t5_segdir; +} [list 0 1024 2048 [expr 1<<40]] + +do_execsql_test 5.1.2 {SELECT docid FROM t5 WHERE t5 MATCH 'language'} 0 +foreach langid [list 0 1 2 [expr 1<<30]] { + do_execsql_test 5.2.$langid { + SELECT docid FROM t5 WHERE t5 MATCH 'language' AND lid = $langid + } $langid +} + +set lid [expr 1<<30] +do_execsql_test 5.3.1 { + CREATE VIRTUAL TABLE t6 USING fts4(languageid=lid); + INSERT INTO t6 VALUES('I belong to language 0!'); +} +do_test 5.3.2 { + for {set i 0} {$i < 20} {incr i} { + execsql { + INSERT INTO t6(content, lid) VALUES( + 'I (row '||$i||') belong to langauge N!', $lid + ); + } + } + execsql { SELECT docid FROM t6 WHERE t6 MATCH 'belong' } +} {1} + +do_test 5.3.3 { + execsql { SELECT docid FROM t6 WHERE t6 MATCH 'belong' AND lid=$lid} +} {2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21} + +do_execsql_test 5.3.4 { INSERT INTO t6(t6) VALUES('optimize') } {} +do_execsql_test 5.3.5 { SELECT docid FROM t6 WHERE t6 MATCH 'belong' } {1} +do_execsql_test 5.3.6 { + SELECT docid FROM t6 WHERE t6 MATCH 'belong' AND lid=$lid +} {2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21} + + +set lid [expr 1<<30] +foreach lid [list 4 [expr 1<<30]] { + do_execsql_test 5.4.$lid.1 { + DELETE FROM t6; + SELECT count(*) FROM t6_segdir; + SELECT count(*) FROM t6_segments; + } {0 0} + do_execsql_test 5.4.$lid.2 { + INSERT INTO t6(content, lid) VALUES('zero zero zero', $lid); + INSERT INTO t6(content, lid) VALUES('zero zero one', $lid); + INSERT INTO t6(content, lid) VALUES('zero one zero', $lid); + INSERT INTO t6(content, lid) VALUES('zero one one', $lid); + INSERT INTO t6(content, lid) VALUES('one zero zero', $lid); + INSERT INTO t6(content, lid) VALUES('one zero one', $lid); + INSERT INTO t6(content, lid) VALUES('one one zero', $lid); + INSERT INTO t6(content, lid) VALUES('one one one', $lid); + + SELECT docid FROM t6 WHERE t6 MATCH '"zero zero"' AND lid=$lid; + } {1 2 5} + + do_execsql_test 5.4.$lid.3 { + SELECT count(*) FROM t6_segdir; + SELECT count(*) FROM t6_segments; + } {8 0} + + do_execsql_test 5.4.$lid.4 { + INSERT INTO t6(t6) VALUES('merge=100,3'); + INSERT INTO t6(t6) VALUES('merge=100,3'); + SELECT docid FROM t6 WHERE t6 MATCH '"zero zero"' AND lid=$lid; + } {1 2 5} + + do_execsql_test 5.4.$lid.5 { + SELECT count(*) FROM t6_segdir; + SELECT count(*) FROM t6_segments; + } {1 2} +} + +reset_db +do_execsql_test 6.0 { + CREATE VIRTUAL TABLE vt0 USING fts4(c0, languageid="lid"); + INSERT INTO vt0 VALUES ('a'), ('b'); + BEGIN; + UPDATE vt0 SET lid = 1 WHERE lid=0; +} +do_execsql_test 6.1 { + INSERT INTO vt0(vt0) VALUES('integrity-check'); + PRAGMA integrity_check; +} {ok} +do_execsql_test 6.2 { + COMMIT; + INSERT INTO vt0(vt0) VALUES('integrity-check'); +} +finish_test diff --git a/test/fts4lastrowid.test b/test/fts4lastrowid.test new file mode 100644 index 0000000..7b35e3c --- /dev/null +++ b/test/fts4lastrowid.test @@ -0,0 +1,72 @@ +# 2017 Feb 27 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Tests of the last_insert_rowid functionality with fts4. +# + +set testdir [file dirname $argv0] +source [file join [file dirname [info script]] tester.tcl] +set testprefix fts4lastrowid + +ifcapable !fts3 { + finish_test + return +} + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t1 USING fts4(str); +} + +do_execsql_test 1.1 { + INSERT INTO t1 VALUES('one string'); + INSERT INTO t1 VALUES('two string'); + INSERT INTO t1 VALUES('three string'); + SELECT last_insert_rowid(); +} {3} + +do_execsql_test 1.2 { + BEGIN; + INSERT INTO t1 VALUES('one string'); + INSERT INTO t1 VALUES('two string'); + INSERT INTO t1 VALUES('three string'); + COMMIT; + SELECT last_insert_rowid(); +} {6} + +do_execsql_test 1.3 { + INSERT INTO t1(rowid, str) VALUES(-22, 'some more text'); + SELECT last_insert_rowid(); +} {-22} + +do_execsql_test 1.4 { + BEGIN; + INSERT INTO t1(rowid, str) VALUES(45, 'some more text'); + INSERT INTO t1(rowid, str) VALUES(46, 'some more text'); + INSERT INTO t1(rowid, str) VALUES(222, 'some more text'); + SELECT last_insert_rowid(); + COMMIT; + SELECT last_insert_rowid(); +} {222 222} + +do_execsql_test 1.5 { + CREATE TABLE x1(x); + INSERT INTO x1 VALUES('john'), ('paul'), ('george'), ('ringo'); + INSERT INTO t1 SELECT x FROM x1; + SELECT last_insert_rowid(); +} {226} + +do_execsql_test 1.6 { + INSERT INTO t1(rowid, str) SELECT rowid+10, x FROM x1; + SELECT last_insert_rowid(); +} {14} + + +finish_test diff --git a/test/fts4merge.test b/test/fts4merge.test new file mode 100644 index 0000000..ffef0e9 --- /dev/null +++ b/test/fts4merge.test @@ -0,0 +1,347 @@ +# 2012 March 06 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the incremental merge function. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/fts3_common.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +proc fts3_integrity_check {tbl} { + db eval "INSERT INTO $tbl ($tbl) VALUES('integrity-check')" + return "ok" +} + +foreach mod {fts3 fts4} { + set ::testprefix fts4merge-$mod + reset_db + + #------------------------------------------------------------------------- + # Test cases 1.* + # + do_test 1.0 { fts3_build_db_1 -module $mod 1004 } {} + do_test 1.1 { fts3_integrity_check t1 } {ok} + do_execsql_test 1.1 { + SELECT level, string_agg(idx, ' ') FROM t1_segdir GROUP BY level + } { + 0 {0 1 2 3 4 5 6 7 8 9 10 11} + 1 {0 1 2 3 4 5 6 7 8 9 10 11 12 13} + 2 {0 1 2} + } + + for {set i 0} {$i<20} {incr i} { + do_execsql_test 1.2.$i.1 { INSERT INTO t1(t1) VALUES('merge=1') } + do_test 1.2.$i.2 { fts3_integrity_check t1 } ok + do_execsql_test 1.2.$i.3 { + SELECT docid FROM t1 WHERE t1 MATCH 'zero one two three' + } {123 132 213 231 312 321} + } + + do_execsql_test 1.3 { + SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level + } { + 2 {0 1 2 3} + } + + for {set i 0} {$i<100} {incr i} { + do_execsql_test 1.4.$i { INSERT INTO t1(t1) VALUES('merge=1,4') } + do_test 1.4.$i.2 { fts3_integrity_check t1 } ok + do_execsql_test 1.4.$i.3 { + SELECT docid FROM t1 WHERE t1 MATCH 'zero one two three' + } {123 132 213 231 312 321} + } + + do_execsql_test 1.5 { + SELECT level, string_agg(idx, ' ') FROM t1_segdir GROUP BY level + } { + 3 0 + } + + #------------------------------------------------------------------------- + # Test cases 2.* test that errors in the xxx part of the 'merge=xxx' are + # handled correctly. + # + do_execsql_test 2.0 "CREATE VIRTUAL TABLE t2 USING $mod" + + foreach {tn arg} { + 1 {merge=abc} + 2 {merge=%%%} + 3 {merge=,} + 4 {merge=5,} + 5 {merge=6,%} + 6 {merge=6,six} + 7 {merge=6,1} + } { + do_catchsql_test 2.$tn { + INSERT INTO t2(t2) VALUES($arg); + } {1 {SQL logic error}} + } + + #------------------------------------------------------------------------- + # Test cases 3.* + # + do_test 3.0 { + reset_db + execsql { PRAGMA page_size = 512 } + fts3_build_db_2 -module $mod 30040 + } {} + do_test 3.1 { fts3_integrity_check t2 } {ok} + + do_execsql_test 3.2 { + SELECT level, string_agg(idx, ' ') FROM t2_segdir GROUP BY level + } { + 0 {0 1 2 3 4 5 6} + 1 {0 1 2 3 4} + 2 {0 1 2 3 4} + 3 {0 1 2 3 4 5 6} + } + + do_execsql_test 3.3 { + INSERT INTO t2(t2) VALUES('merge=1000000,2'); + SELECT level, group_concat(idx, ' ') FROM t2_segdir GROUP BY level + } { + 4 0 + } + + #------------------------------------------------------------------------- + # Test cases 4.* + # + reset_db + do_execsql_test 4.1 " + PRAGMA page_size = 512; + CREATE VIRTUAL TABLE t4 USING $mod; + PRAGMA main.page_size; + " {512} + + do_test 4.2 { + foreach x {a c b d e f g h i j k l m n o p} { + execsql "INSERT INTO t4 VALUES('[string repeat $x 600]')" + } + execsql {SELECT level, string_agg(idx, ' ') FROM t4_segdir GROUP BY level} + } {0 {0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15}} + + foreach {tn expect} { + 1 "0 {0 1 2 3 4 5 6 7 8 9 10 11 12 13} 1 0" + 2 "0 {0 1 2 3 4 5 6 7 8 9 10 11 12} 1 0" + 3 "0 {0 1 2 3 4 5 6 7 8 9 10 11} 1 0" + 4 "0 {0 1 2 3 4 5 6 7 8 9 10} 1 0" + 5 "0 {0 1 2 3 4 5 6 7 8 9} 1 0" + 6 "0 {0 1 2 3 4 5 6 7 8} 1 0" + 7 "0 {0 1 2 3 4 5 6 7} 1 0" + 8 "0 {0 1 2 3 4 5 6} 1 0" + 9 "0 {0 1 2 3 4 5} 1 0" + } { + do_execsql_test 4.3.$tn { + INSERT INTO t4(t4) VALUES('merge=1,16'); + SELECT level, group_concat(idx, ' ') FROM t4_segdir GROUP BY level; + } $expect + } + + do_execsql_test 4.4.1 { + SELECT quote(value) FROM t4_stat WHERE rowid=1 + } {X'0006'} + + sqlite3_db_config db DEFENSIVE 0 + do_execsql_test 4.4.2 { + DELETE FROM t4_stat WHERE rowid=1; + INSERT INTO t4(t4) VALUES('merge=1,12'); + SELECT level, string_agg(idx, ' ') FROM t4_segdir GROUP BY level; + } "0 {0 1 2 3 4 5} 1 0" + + + #------------------------------------------------------------------------- + # Test cases 5.* + # + # Test that if a crisis-merge occurs that disrupts an ongoing incremental + # merge, the next call to "merge=A,B" identifies this and starts a new + # incremental merge. There are two scenarios: + # + # * There are less segments on the input level that the disrupted + # incremental merge operated on, or + # + # * Sufficient segments exist on the input level but the segments + # contain keys smaller than the largest key in the potential output + # segment. + # + do_test 5.1 { + reset_db + fts3_build_db_1 -module $mod 1000 + } {} + + do_execsql_test 5.2 { + SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level; + } { + 0 {0 1 2 3 4 5 6 7} + 1 {0 1 2 3 4 5 6 7 8 9 10 11 12 13} + 2 {0 1 2} + } + + do_execsql_test 5.3 { + INSERT INTO t1(t1) VALUES('merge=1,5'); + INSERT INTO t1(t1) VALUES('merge=1,5'); + SELECT level, string_agg(idx, ' ') FROM t1_segdir GROUP BY level; + } { + 1 {0 1 2 3 4 5 6 7 8 9 10 11 12 13 14} + 2 {0 1 2 3} + } + + do_execsql_test 5.4 {SELECT quote(value) from t1_stat WHERE rowid=1} {X'010F'} + do_test 5.5 { + foreach docid [execsql {SELECT docid FROM t1}] { + execsql {INSERT INTO t1 SELECT * FROM t1 WHERE docid=$docid} + } + } {} + + do_execsql_test 5.6 {SELECT quote(value) from t1_stat WHERE rowid=1} {X'010F'} + + do_execsql_test 5.7 { + SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level; + SELECT quote(value) from t1_stat WHERE rowid=1; + } { + 0 {0 1 2 3 4 5 6 7} + 1 {0 1 2 3 4 5 6 7 8 9 10 11 12} + 2 {0 1 2 3 4 5 6 7} + X'010F' + } + + do_execsql_test 5.8 { + INSERT INTO t1(t1) VALUES('merge=1,6'); + INSERT INTO t1(t1) VALUES('merge=1,6'); + SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level; + SELECT quote(value) from t1_stat WHERE rowid=1; + } { + 1 {0 1 2 3 4 5 6 7 8 9 10 11 12 13} + 2 {0 1 2 3 4 5 6 7 8} X'010E' + } + + do_test 5.8.1 { fts3_integrity_check t1 } ok + + do_test 5.9 { + set L [expr 16*16*7 + 16*3 + 12] + foreach docid [execsql { + SELECT docid FROM t1 UNION ALL SELECT docid FROM t1 LIMIT $L + }] { + execsql {INSERT INTO t1 SELECT * FROM t1 WHERE docid=$docid} + } + } {} + + do_execsql_test 5.10 { + SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level; + SELECT quote(value) from t1_stat WHERE rowid=1; + } { + 0 {0 1 2 3 4 5 6 7 8 9 10 11} 1 0 2 0 3 0 X'010E' + } + + do_execsql_test 5.11 { + INSERT INTO t1(t1) VALUES('merge=1,6'); + SELECT level, string_agg(idx, ' ') FROM t1_segdir GROUP BY level; + SELECT quote(value) from t1_stat WHERE rowid=1; + } { + 1 {0 1} 2 0 3 0 X'010E' + } + + #------------------------------------------------------------------------- + # Test cases 6.* + # + # At one point the following test caused an assert() to fail (because the + # second 'merge=1,2' operation below actually "merges" a single input + # segment, which was unexpected). + # + do_test 6.1 { + reset_db + set a [string repeat a 900] + set b [string repeat b 900] + set c [string repeat c 900] + set d [string repeat d 900] + + execsql "CREATE VIRTUAL TABLE t1 USING $mod" + execsql { + BEGIN; + INSERT INTO t1 VALUES($a); + INSERT INTO t1 VALUES($b); + COMMIT; + BEGIN; + INSERT INTO t1 VALUES($c); + INSERT INTO t1 VALUES($d); + COMMIT; + } + + execsql { + INSERT INTO t1(t1) VALUES('merge=1,2'); + INSERT INTO t1(t1) VALUES('merge=1,2'); + } + } {} + + #------------------------------------------------------------------------- + # Test cases 7.* + # + # Test that the value returned by sqlite3_total_changes() increases by + # 1 following a no-op "merge=A,B", or by more than 1 if actual work is + # performed. + # + do_test 7.0 { + reset_db + fts3_build_db_1 -module $mod 1000 + } {} + + do_execsql_test 7.1 { + SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level + } { + 0 {0 1 2 3 4 5 6 7} + 1 {0 1 2 3 4 5 6 7 8 9 10 11 12 13} + 2 {0 1 2} + } + do_test 7.2 { + set x [db total_changes] + execsql { INSERT INTO t1(t1) VALUES('merge=2,10') } + expr { ([db total_changes] - $x)>1 } + } {1} + do_test 7.3 { + set x [db total_changes] + execsql { INSERT INTO t1(t1) VALUES('merge=200,10') } + expr { ([db total_changes] - $x)>1 } + } {1} + do_test 7.4 { + set x [db total_changes] + execsql { INSERT INTO t1(t1) VALUES('merge=200,10') } + expr { ([db total_changes] - $x)>1 } + } {0} + do_test 7.5 { + set x [db total_changes] + execsql { INSERT INTO t1(t1) VALUES('merge=200,10') } + expr { ([db total_changes] - $x)>1 } + } {0} +} + +#------------------------------------------------------------------------- +# Test cases 8.* - ticket [bf1aab89]. +# +set testprefix fts4merge +reset_db +do_execsql_test 8.0 { + CREATE VIRTUAL TABLE t1 USING fts4(a, order=DESC); + INSERT INTO t1(a) VALUES (0); + INSERT INTO t1(a) VALUES (0); + UPDATE t1 SET a = NULL; +} + +do_execsql_test 8.1 { + INSERT INTO t1(t1) VALUES('merge=1,4'); +} + +finish_test diff --git a/test/fts4merge2.test b/test/fts4merge2.test new file mode 100644 index 0000000..308b692 --- /dev/null +++ b/test/fts4merge2.test @@ -0,0 +1,38 @@ + + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/fts3_common.tcl +source $testdir/malloc_common.tcl +set ::testprefix fts4merge2 + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +do_test 1.0 { + fts3_build_db_1 1000 + faultsim_save_and_close +} {} + +do_faultsim_test 1.1 -faults oom-* -prep { + faultsim_restore_and_reopen +} -body { + execsql { INSERT INTO t1(t1) VALUES('merge=32,4') } +} -test { + faultsim_test_result {0 {}} +} + +do_faultsim_test 1.2 -faults oom-t* -prep { + if {$iFail<100} {set iFail 803} + faultsim_restore_and_reopen +} -body { + execsql { INSERT INTO t1(t1) VALUES('merge=1,2') } + execsql { INSERT INTO t1(t1) VALUES('merge=1,2') } +} -test { + faultsim_test_result {0 {}} +} + +finish_test diff --git a/test/fts4merge3.test b/test/fts4merge3.test new file mode 100644 index 0000000..08b68b9 --- /dev/null +++ b/test/fts4merge3.test @@ -0,0 +1,105 @@ +# 2012 March 06 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the incremental merge function. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/fts3_common.tcl +source $testdir/lock_common.tcl +source $testdir/bc_common.tcl + +set ::testprefix fts4merge3 + +ifcapable !fts3 { + finish_test + return +} + +if {"" == [bc_find_binaries backcompat.test]} { + finish_test + return +} + +db close +do_all_bc_test { + + sql2 { PRAGMA page_size = 512 } + if { 0==[catch { sql2 { CREATE VIRTUAL TABLE x USING fts4 } } ] } { + + # Build a large database. + set msg "this takes around 12 seconds" + do_test "1.1 ($msg)" { fts3_build_db_2 20000 } {} + + # Run some queries on it, using the old and new versions. + do_test 1.2 { sql1 "SELECT docid FROM t2 WHERE t2 MATCH 'abc'" } {1485} + do_test 1.3 { sql2 "SELECT docid FROM t2 WHERE t2 MATCH 'abc'" } {1485} + + do_test 1.4 { + set x [sql2 "PRAGMA page_count"] + expr {$x>=1284 && $x<=1286} + } {1} + do_test 1.5 { sql2 { + SELECT level, count(*) FROM t2_segdir GROUP BY level ORDER BY 1 + } } [list 0 15 1 1 2 14 3 4] + + # Run some incr-merge operations on the db. + for {set i 0} {$i<10} {incr i} { + do_test 1.6.$i.1 { sql1 { INSERT INTO t2(t2) VALUES('merge=2,2') } } {} + do_test 1.6.$i.2 { + sql2 "SELECT docid FROM t2 WHERE t2 MATCH 'abc'" + } {1485} + } + + do_test 1.7 { sql2 { + SELECT level, count(*) FROM t2_segdir GROUP BY level ORDER BY 1 + } } {2 15 3 5} + + # Using the old connection, insert many rows. + do_test 1.8 { + for {set i 0} {$i < 1500} {incr i} { + sql2 "INSERT INTO t2 SELECT content FROM t2 WHERE docid = $i" + } + } {} + + do_test 1.9 { sql2 { + SELECT level, count(*) FROM t2_segdir GROUP BY level ORDER BY 1 + } } [list 0 12 1 13 2 4 3 6] + + # Run a big incr-merge operation on the db. + do_test 1.10 { sql1 { INSERT INTO t2(t2) VALUES('merge=2000,2') } } {} + do_test 1.11 { + sql2 "SELECT docid FROM t2 WHERE t2 MATCH 'abc'" + } {1485 21485} + + do_test 1.12 { + for {set i 0} {$i < 1500} {incr i} { + sql2 "INSERT INTO t2 SELECT content FROM t2 WHERE docid = $i" + } + } {} + do_test 1.13 { + sql2 "SELECT docid FROM t2 WHERE t2 MATCH 'abc'" + } {1485 21485 22985} + + do_test 1.14 { + sql2 "INSERT INTO t2(t2) VALUES('optimize')" + sql2 "SELECT docid FROM t2 WHERE t2 MATCH 'abc'" + } {1485 21485 22985} + + do_test 1.15 { sql2 { + SELECT level, count(*) FROM t2_segdir GROUP BY level ORDER BY 1 + } } {4 1} + } +} + + +finish_test diff --git a/test/fts4merge4.test b/test/fts4merge4.test new file mode 100644 index 0000000..12328c2 --- /dev/null +++ b/test/fts4merge4.test @@ -0,0 +1,102 @@ +# 2013 May 29 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/fts3_common.tcl +set ::testprefix fts4merge4 + +ifcapable !fts3||!shared_cache { + finish_test + return +} + +set ::enable_shared_cache [sqlite3_enable_shared_cache 1] + +do_execsql_test 1.1 { CREATE VIRTUAL TABLE t1 USING fts4 } + +do_test 1.2 { + for {set i 0} {$i < 2000} {incr i} { + execsql {INSERT INTO t1 VALUES('a b c d e f g h i j k l');} + } +} {} + +do_test 1.3 { + execsql BEGIN + for {set i 0} {$i < 2000} {incr i} { + execsql {INSERT INTO t1 VALUES('a b c d e f g h i j k l');} + } + execsql { + INSERT INTO t1(t1) VALUES('merge=8,50'); + COMMIT + } +} {} + +reset_db +do_execsql_test 2.0 { CREATE VIRTUAL TABLE t1 USING fts4 } +do_test 2.1 { + for {set i 0} {$i < 2000} {incr i} { + execsql {INSERT INTO t1 VALUES('a b c d e f g h i j k l');} + } +} {} +do_execsql_test 2.2 { SELECT count(*) FROM t1_segdir; } 35 +do_execsql_test 2.3 { INSERT INTO t1(t1) VALUES('optimize') } {} +do_execsql_test 2.4 { SELECT count(*) FROM t1_segdir; } 1 + +#------------------------------------------------------------------------- +# Now test that the automerge=? option appears to work. +# +do_execsql_test 2.1 { CREATE VIRTUAL TABLE t2 USING fts4; } + +set doc "" +foreach c1 "a b c d e f g h i j" { + foreach c2 "a b c d e f g h i j" { + foreach c3 "a b c d e f g h i j" { + lappend doc "$c1$c2$c3" + } + } +} +set doc [string repeat $doc 10] + +foreach {tn am expected} { + 1 {automerge=2} {1 1 2 1 4 1 6 1} + 2 {automerge=4} {1 2 2 1 3 1} + 3 {automerge=8} {0 4 1 3 2 1} + 4 {automerge=1} {0 4 1 3 2 1} +} { + foreach {tn2 openclose} {1 {} 2 { db close ; sqlite3 db test.db }} { + do_test 2.2.$tn.$tn2 { + execsql { DELETE FROM t2 } + execsql { INSERT INTO t2(t2) VALUES($am) }; + + eval $openclose + + for {set i 0} {$i < 100} {incr i} { + execsql { + BEGIN; + INSERT INTO t2 VALUES($doc); + INSERT INTO t2 VALUES($doc); + INSERT INTO t2 VALUES($doc); + INSERT INTO t2 VALUES($doc); + INSERT INTO t2 VALUES($doc); + COMMIT; + } + } + + execsql { SELECT level, count(*) FROM t2_segdir GROUP BY level } + } [list {*}$expected] + } +} + +sqlite3_enable_shared_cache $::enable_shared_cache +finish_test diff --git a/test/fts4merge5.test b/test/fts4merge5.test new file mode 100644 index 0000000..1fad778 --- /dev/null +++ b/test/fts4merge5.test @@ -0,0 +1,58 @@ +# 2019 October 02 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS4 module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts4merge5 + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +source $testdir/genesis.tcl + +do_execsql_test 1.1 { + CREATE TABLE t1(docid, words); +} +fts_kjv_genesis + +do_execsql_test 1.2 { + CREATE VIRTUAL TABLE x1 USING fts3; + INSERT INTO x1(x1) VALUES('nodesize=64'); + INSERT INTO x1(x1) VALUES('maxpending=64'); +} + +do_execsql_test 1.3 { + INSERT INTO x1(docid, content) SELECT * FROM t1; +} + +for {set tn 1} {1} {incr tn} { + set tc1 [db total_changes] + do_execsql_test 1.4.$tn.1 { + INSERT INTO x1(x1) VALUES('merge=1,2'); + } + set tc2 [db total_changes] + + if {($tc2 - $tc1)<2} break + + do_execsql_test 1.4.$tn.1 { + INSERT INTO x1(x1) VALUES('integrity-check'); + } +} + + + +finish_test diff --git a/test/fts4min.test b/test/fts4min.test new file mode 100644 index 0000000..ca63b39 --- /dev/null +++ b/test/fts4min.test @@ -0,0 +1,53 @@ +# 2020 February 27 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/fts3_common.tcl +set ::testprefix fts4min + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +#------------------------------------------------------------------ +do_execsql_test 0.0 { + CREATE TABLE t1(a NOT NULL, b); + CREATE INDEX i1 ON t1(a); +} + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE ft USING fts3(c); + INSERT INTO ft(docid, c) VALUES(22, 'hello world'); + INSERT INTO ft(docid, c) VALUES(44, 'hello world'); + INSERT INTO ft(docid, c) VALUES(11, 'hello world'); +} + +do_eqp_test 1.1.1 { + SELECT max(rowid) FROM ft +} {VIRTUAL TABLE INDEX 0:DESC} + +do_eqp_test 1.1.2 { + SELECT min(rowid) FROM ft +} {VIRTUAL TABLE INDEX 0:ASC} + +do_execsql_test 1.2.1 { + SELECT max(rowid) FROM ft +} {44} + +do_execsql_test 1.2.2 { + SELECT min(rowid) FROM ft +} {11} + +finish_test diff --git a/test/fts4noti.test b/test/fts4noti.test new file mode 100644 index 0000000..87a0571 --- /dev/null +++ b/test/fts4noti.test @@ -0,0 +1,230 @@ +# 2013 June 21 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the notindexed=xxx FTS4 option. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix fts4noti + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + + +#------------------------------------------------------------------------- +# Test that typos in "notindexed=" column names are detected. +# +do_execsql_test 1.0 { + CREATE TABLE cc(a, b, c); +} +foreach {tn arg res} { + 1 "(b, c, notindexed=a)" {1 {no such column: a}} + 2 "(a, b, notindexed=a)" {0 {}} + 3 "(a, b, notindexed=a, notindexed=a)" {0 {}} + 4 "(notindexed=a, a, b)" {0 {}} + 5 "(notindexed=a, notindexed=b, notindexed=c, a, b, c, d)" {0 {}} + 6 "(notindexed=a, notindexed=B, notindexed=c, a, b, c, d)" {0 {}} + 7 "(notindexed=a, notindexed=b, notindexed=c, a, B, c, d)" {0 {}} + 8 "(notindexed=d, content=cc)" {1 {no such column: d}} + 9 "(notindexed=a, content=cc)" {0 {}} + 10 "(notindexed=a, notindexed=b, a)" {1 {no such column: b}} + 11 "(notindexed=a, notindexed=b, b)" {1 {no such column: a}} +} { + do_catchsql_test 1.$tn "CREATE VIRTUAL TABLE t1 USING fts4 $arg" $res + if {[lindex $res 0]==0} { execsql "DROP TABLE t1" } +} + +do_execsql_test 1.x { SELECT name FROM sqlite_master } {cc} + + +#------------------------------------------------------------------------- +# Test that notindexed columns are not indexed. +# +foreach {tn schema} { + 1 { + CREATE VIRTUAL TABLE t1 USING fts4(a, b, c, notindexed=b); + } + 2 { + CREATE TABLE c1(a, b, c); + INSERT INTO c1 VALUES('one two', 'three four', 'five six'); + INSERT INTO c1 VALUES('three four', 'five six', 'one two'); + CREATE VIRTUAL TABLE t1 USING fts4(content=c1, notindexed=b); + } + 3 { + CREATE VIRTUAL TABLE t1 USING fts4(content="", a, b, c, notindexed=b); + } +} { + execsql $schema + + do_execsql_test 2.$tn.1 { + INSERT INTO t1(docid,a,b,c) VALUES(1, 'one two', 'three four', 'five six'); + INSERT INTO t1(docid,a,b,c) VALUES(2, 'three four', 'five six', 'one two'); + } + + do_execsql_test 2.$tn.2 { SELECT docid FROM t1 WHERE t1 MATCH 'one' } {1 2} + do_execsql_test 2.$tn.3 { SELECT docid FROM t1 WHERE t1 MATCH 'three' } {2} + do_execsql_test 2.$tn.4 { SELECT docid FROM t1 WHERE t1 MATCH 'five' } {1} + + do_execsql_test 2.$tn.5 { INSERT INTO t1(t1) VALUES('optimize') } + + do_execsql_test 2.$tn.6 { SELECT docid FROM t1 WHERE t1 MATCH 'one' } {1 2} + do_execsql_test 2.$tn.7 { SELECT docid FROM t1 WHERE t1 MATCH 'three' } {2} + do_execsql_test 2.$tn.8 { SELECT docid FROM t1 WHERE t1 MATCH 'five' } {1} + + if {$tn!=3} { + do_execsql_test 2.$tn.9 { INSERT INTO t1(t1) VALUES('rebuild') } + + do_execsql_test 2.$tn.10 { SELECT docid FROM t1 WHERE t1 MATCH 'one' } {1 2} + do_execsql_test 2.$tn.11 { SELECT docid FROM t1 WHERE t1 MATCH 'three' } {2} + do_execsql_test 2.$tn.12 { SELECT docid FROM t1 WHERE t1 MATCH 'five' } {1} + + do_execsql_test 2.$tn.13 { + SELECT a,b,c FROM t1 WHERE docid=1 + } {{one two} {three four} {five six}} + do_execsql_test 2.$tn.14 { + SELECT a,b,c FROM t1 WHERE docid=2 + } {{three four} {five six} {one two}} + } + + do_execsql_test 2.x { DROP TABLE t1 } +} + +#------------------------------------------------------------------------- +# Test that notindexed columns are not scanned for deferred tokens. +# + +do_execsql_test 3.1 { + CREATE VIRTUAL TABLE t2 USING fts4(x, y, notindexed=x); +} +do_test 3.2 { + set v [string repeat " 1" 50000] + set v1 "x $v" + set v2 "y $v" + execsql { + INSERT INTO t2 VALUES(1, 'x y z'); + INSERT INTO t2 VALUES(2, $v1); + INSERT INTO t2 VALUES(3, $v2); + INSERT INTO t2 VALUES(4, $v2); + INSERT INTO t2 VALUES(5, $v2); + INSERT INTO t2 VALUES(6, $v2); + } +} {} + +do_execsql_test 3.3 { SELECT x FROM t2 WHERE t2 MATCH '2' } {} +do_execsql_test 3.4 { SELECT x FROM t2 WHERE t2 MATCH '1' } {2 3 4 5 6} +do_execsql_test 3.5 { SELECT x FROM t2 WHERE t2 MATCH 'x' } {1 2} +do_execsql_test 3.6 { SELECT x FROM t2 WHERE t2 MATCH 'x 1' } {2} + +do_execsql_test 3.x { DROP TABLE t2 } + +#------------------------------------------------------------------------- +# Test that the types of notindexed columns are not modified. +# +do_execsql_test 4.1 { + CREATE VIRTUAL TABLE t2 USING fts4(poi, addr, notindexed=poi); + INSERT INTO t2 VALUES(114, 'x x x'); + INSERT INTO t2 VALUES(X'1234', 'y y y'); + INSERT INTO t2 VALUES(NULL, 'z z z'); + INSERT INTO t2 VALUES(113.2, 'w w w'); + INSERT INTO t2 VALUES('poi', 'v v v'); +} +do_execsql_test 4.2 { SELECT typeof(poi) FROM t2 WHERE t2 MATCH 'x' } {integer} +do_execsql_test 4.3 { SELECT typeof(poi) FROM t2 WHERE t2 MATCH 'y' } {blob} +do_execsql_test 4.4 { SELECT typeof(poi) FROM t2 WHERE t2 MATCH 'z' } {null} +do_execsql_test 4.5 { SELECT typeof(poi) FROM t2 WHERE t2 MATCH 'w' } {real} +do_execsql_test 4.6 { SELECT typeof(poi) FROM t2 WHERE t2 MATCH 'v' } {text} + +do_execsql_test 4.x { DROP TABLE t2 } + +#------------------------------------------------------------------------- +# Test that multiple notindexed options on a single table work as expected. +# +do_execsql_test 5.1 { + CREATE VIRTUAL TABLE t2 USING fts4( + notindexed="three", one, two, three, notindexed="one", + ); + INSERT INTO t2 VALUES('a', 'b', 'c'); + INSERT INTO t2 VALUES('c', 'a', 'b'); + INSERT INTO t2 VALUES('b', 'c', 'a'); +} +do_execsql_test 5.2 { SELECT docid FROM t2 WHERE t2 MATCH 'a' } {2} +do_execsql_test 5.3 { SELECT docid FROM t2 WHERE t2 MATCH 'b' } {1} +do_execsql_test 5.4 { SELECT docid FROM t2 WHERE t2 MATCH 'c' } {3} + +do_execsql_test 5.x { DROP TABLE t2 } + +#------------------------------------------------------------------------- +# Check that if an indexed column name is a prefix of a notindexed column +# name, the column is still correctly tokenized. This was a problem at one +# point. +do_execsql_test 6.1.1 { + CREATE VIRTUAL TABLE t1 USING fts4( + poiCategory, poiCategoryId, notindexed=poiCategoryId + ); + INSERT INTO t1(poiCategory, poiCategoryId) values ('Restaurant', 6021); +} + +do_execsql_test 6.1.2 { + SELECT * FROM t1 WHERE t1 MATCH 'restaurant'; +} { Restaurant 6021 } +do_execsql_test 6.1.3 { + SELECT * FROM t1 WHERE t1 MATCH 're*'; +} { Restaurant 6021 } +do_execsql_test 6.1.4 { + SELECT * FROM t1 WHERE t1 MATCH '6021'; +} {} +do_execsql_test 6.1.5 { + SELECT * FROM t1 WHERE t1 MATCH '60*'; +} {} + +do_execsql_test 6.2.1 { + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING fts4( + poiCategory, poiCategoryId, notindexed=poiCategory + ); + INSERT INTO t1(poiCategory, poiCategoryId) values ('Restaurant', 6021); +} + +do_execsql_test 6.2.2 { + SELECT * FROM t1 WHERE t1 MATCH 'restaurant'; +} {} +do_execsql_test 6.2.3 { + SELECT * FROM t1 WHERE t1 MATCH 're*'; +} {} +do_execsql_test 6.2.4 { + SELECT * FROM t1 WHERE t1 MATCH '6021'; +} { Restaurant 6021 } +do_execsql_test 6.2.5 { + SELECT * FROM t1 WHERE t1 MATCH '60*'; +} { Restaurant 6021 } + +do_execsql_test 6.3.1 { + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING fts4(abc, ab, a, notindexed=abc); + CREATE VIRTUAL TABLE t2 USING fts4(a, ab, abc, notindexed=abc); + + INSERT INTO t1 VALUES('no', 'yes', 'yep'); + INSERT INTO t2 VALUES('yep', 'yes', 'no'); + + SELECT count(*) FROM t1 WHERE t1 MATCH 'no'; + SELECT count(*) FROM t1 WHERE t1 MATCH 'yes'; + SELECT count(*) FROM t1 WHERE t1 MATCH 'yep'; + + SELECT count(*) FROM t2 WHERE t2 MATCH 'no'; + SELECT count(*) FROM t2 WHERE t2 MATCH 'yes'; + SELECT count(*) FROM t2 WHERE t2 MATCH 'yep'; +} {0 1 1 0 1 1} + +finish_test diff --git a/test/fts4onepass.test b/test/fts4onepass.test new file mode 100644 index 0000000..344be4b --- /dev/null +++ b/test/fts4onepass.test @@ -0,0 +1,160 @@ +# 2015 Sep 27 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/fts3_common.tcl +set ::testprefix fts4onepass + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE ft USING fts3; + INSERT INTO ft(rowid, content) VALUES(1, '1 2 3'); + INSERT INTO ft(rowid, content) VALUES(2, '4 5 6'); + INSERT INTO ft(rowid, content) VALUES(3, '7 8 9'); +} + +#------------------------------------------------------------------------- +# Check that UPDATE and DELETE statements that feature "WHERE rowid=?" or +# or "WHERE docid=?" clauses do not use statement journals. But that other +# DELETE and UPDATE statements do. +# +# Note: "MATCH ? AND docid=?" does use a statement journal. +# +foreach {tn sql uses} { + 1.1 { DELETE FROM ft } 1 + 1.2 { DELETE FROM ft WHERE docid=? } 0 + 1.3 { DELETE FROM ft WHERE rowid=? } 0 + 1.4 { DELETE FROM ft WHERE ft MATCH '1' } 1 + 1.5 { DELETE FROM ft WHERE ft MATCH '1' AND docid=? } 1 + 1.6 { DELETE FROM ft WHERE ft MATCH '1' AND rowid=? } 1 + + 2.1 { UPDATE ft SET content='a b c' } 1 + 2.2 { UPDATE ft SET content='a b c' WHERE docid=? } 0 + 2.3 { UPDATE ft SET content='a b c' WHERE rowid=? } 0 + 2.4 { UPDATE ft SET content='a b c' WHERE ft MATCH '1' } 1 + 2.5 { UPDATE ft SET content='a b c' WHERE ft MATCH '1' AND docid=? } 1 + 2.6 { UPDATE ft SET content='a b c' WHERE ft MATCH '1' AND rowid=? } 1 +} { + do_test 1.$tn { sql_uses_stmt db $sql } $uses +} + +#------------------------------------------------------------------------- +# Check that putting a "DELETE/UPDATE ... WHERE rowid=?" statement in a +# trigger program does not prevent the VM from using a statement +# transaction. Even if the calling statement cannot hit a constraint. +# +do_execsql_test 2.0 { + CREATE TABLE t1(x); + + CREATE TRIGGER t1_ai AFTER INSERT ON t1 BEGIN + DELETE FROM ft WHERE rowid=new.x; + END; + + CREATE TRIGGER t1_ad AFTER DELETE ON t1 BEGIN + UPDATE ft SET content = 'a b c' WHERE rowid=old.x; + END; + + CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 BEGIN + DELETE FROM ft WHERE rowid=old.x; + END; +} + +foreach {tn sql uses} { + 1 { INSERT INTO t1 VALUES(1) } 1 + 2 { DELETE FROM t1 WHERE x=4 } 1 + 3 { UPDATE t1 SET x=10 WHERE x=11 } 1 +} { + do_test 2.$tn { sql_uses_stmt db $sql } $uses +} + +#------------------------------------------------------------------------- +# Test that an "UPDATE ... WHERE rowid=?" works and does not corrupt the +# index when it strikes a constraint. Both inside and outside a +# transaction. +# +foreach {tn tcl1 tcl2} { + 1 {} {} + + 2 { + execsql BEGIN + } { + if {[sqlite3_get_autocommit db]==1} { error "transaction rolled back!" } + execsql COMMIT + } +} { + + do_execsql_test 3.$tn.0 { + DROP TABLE IF EXISTS ft2; + CREATE VIRTUAL TABLE ft2 USING fts4; + INSERT INTO ft2(rowid, content) VALUES(1, 'a b c'); + INSERT INTO ft2(rowid, content) VALUES(2, 'a b d'); + INSERT INTO ft2(rowid, content) VALUES(3, 'a b e'); + } + + eval $tcl1 + foreach {tn2 sql content} { + 1 { UPDATE ft2 SET docid=2 WHERE docid=1 } + { 1 {a b c} 2 {a b d} 3 {a b e} } + + 2 { + INSERT INTO ft2(rowid, content) VALUES(4, 'a b f'); + UPDATE ft2 SET docid=5 WHERE docid=4; + UPDATE ft2 SET docid=3 WHERE docid=5; + } { 1 {a b c} 2 {a b d} 3 {a b e} 5 {a b f} } + + 3 { + UPDATE ft2 SET docid=3 WHERE docid=4; -- matches 0 rows + UPDATE ft2 SET docid=2 WHERE docid=3; + } { 1 {a b c} 2 {a b d} 3 {a b e} 5 {a b f} } + + 4 { + INSERT INTO ft2(rowid, content) VALUES(4, 'a b g'); + UPDATE ft2 SET docid=-1 WHERE docid=4; + UPDATE ft2 SET docid=3 WHERE docid=-1; + } {-1 {a b g} 1 {a b c} 2 {a b d} 3 {a b e} 5 {a b f} } + + 5 { + DELETE FROM ft2 WHERE rowid=451; + DELETE FROM ft2 WHERE rowid=-1; + UPDATE ft2 SET docid = 2 WHERE docid = 1; + } {1 {a b c} 2 {a b d} 3 {a b e} 5 {a b f} } + } { + do_catchsql_test 3.$tn.$tn2.a $sql {1 {constraint failed}} + do_execsql_test 3.$tn.$tn2.b { SELECT rowid, content FROM ft2 } $content + do_execsql_test 3.$tn.$tn2.c { + INSERT INTO ft2(ft2) VALUES('integrity-check'); + } + } + eval $tcl2 +} + +do_execsql_test 4.0 { + CREATE VIRTUAL TABLE zt USING fts4(a, b); + INSERT INTO zt(rowid, a, b) VALUES(1, 'unus duo', NULL); + INSERT INTO zt(rowid, a, b) VALUES(2, NULL, NULL); + + BEGIN; + UPDATE zt SET b='septum' WHERE rowid = 1; + UPDATE zt SET b='octo' WHERE rowid = 1; + COMMIT; + + SELECT count(*) FROM zt_segdir; +} {3} + + +finish_test diff --git a/test/fts4opt.test b/test/fts4opt.test new file mode 100644 index 0000000..4b3d003 --- /dev/null +++ b/test/fts4opt.test @@ -0,0 +1,214 @@ +# 2016 March 8 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/fts3_common.tcl +set ::testprefix fts4opt + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# Create the fts_kjv_genesis procedure which fills and FTS3/4 table +# with the complete text of the Book of Genesis. +# +source $testdir/genesis.tcl + +do_execsql_test 1.0 { CREATE TABLE t1(docid, words) } +fts_kjv_genesis + +#------------------------------------------------------------------------- +# Argument $db is an open database handle. $tbl is the name of an FTS3/4 +# table with the database. This command rearranges the contents of the +# %_segdir table so that all segments within each index are on the same +# level. This means that the 'merge' command can then be used for an +# incremental optimize routine. +# +proc prepare_for_optimize {db tbl} { + sqlite3_db_config $db DEFENSIVE 0 + $db eval [string map [list % $tbl] { + BEGIN; + CREATE TEMP TABLE tmp_segdir( + level, idx, start_block, leaves_end_block, end_block, root + ); + + INSERT INTO temp.tmp_segdir + SELECT + 1024*(o.level / 1024) + 32, -- level + sum(o.leveli.idx)), -- idx + o.start_block, o.leaves_end_block, o.end_block, o.root -- other + FROM %_segdir o, %_segdir i + WHERE (o.level / 1024) = (i.level / 1024) + GROUP BY o.level, o.idx; + + DELETE FROM %_segdir; + INSERT INTO %_segdir SELECT * FROM temp.tmp_segdir; + DROP TABLE temp.tmp_segdir; + + COMMIT; + }] +} + +do_test 1.1 { + execsql { CREATE VIRTUAL TABLE t2 USING fts4(words, prefix="1,2,3") } + foreach {docid words} [db eval { SELECT * FROM t1 }] { + execsql { INSERT INTO t2(docid, words) VALUES($docid, $words) } + } +} {} + +do_execsql_test 1.2 { + SELECT level, count(*) FROM t2_segdir GROUP BY level +} { + 0 13 1 15 2 5 + 1024 13 1025 15 1026 5 + 2048 13 2049 15 2050 5 + 3072 13 3073 15 3074 5 +} + +do_execsql_test 1.3 { INSERT INTO t2(t2) VALUES('integrity-check') } +prepare_for_optimize db t2 +do_execsql_test 1.4 { INSERT INTO t2(t2) VALUES('integrity-check') } + +do_execsql_test 1.5 { + SELECT level, count(*) FROM t2_segdir GROUP BY level +} { + 32 33 + 1056 33 + 2080 33 + 3104 33 +} + +do_test 1.6 { + while 1 { + set tc1 [db total_changes] + execsql { INSERT INTO t2(t2) VALUES('merge=5,2') } + set tc2 [db total_changes] + if {($tc2 - $tc1) < 2} break + } + execsql { SELECT level, count(*) FROM t2_segdir GROUP BY level } +} {33 1 1057 1 2081 1 3105 1} +do_execsql_test 1.7 { INSERT INTO t2(t2) VALUES('integrity-check') } + +do_execsql_test 1.8 { + INSERT INTO t2(words) SELECT words FROM t1; + SELECT level, count(*) FROM t2_segdir GROUP BY level; +} {0 2 1024 2 2048 2 3072 2} + +#------------------------------------------------------------------------- + +do_execsql_test 2.0 { + DELETE FROM t2; +} +do_test 2.1 { + foreach {docid words} [db eval { SELECT * FROM t1 }] { + execsql { INSERT INTO t2(docid, words) VALUES($docid, $words) } + } + + set i 0 + foreach {docid words} [db eval { SELECT * FROM t1 }] { + if {[incr i] % 2} { execsql { DELETE FROM t2 WHERE docid = $docid } } + } + + set i 0 + foreach {docid words} [db eval { SELECT * FROM t1 }] { + if {[incr i] % 3} { + execsql { INSERT OR REPLACE INTO t2(docid, words) VALUES($docid, $words) } + } + } +} {} + +do_execsql_test 2.2 { + SELECT level, count(*) FROM t2_segdir GROUP BY level +} { + 0 10 1 15 2 12 + 1024 10 1025 15 1026 12 + 2048 10 2049 15 2050 12 + 3072 10 3073 15 3074 12 +} + +do_execsql_test 2.3 { INSERT INTO t2(t2) VALUES('integrity-check') } +prepare_for_optimize db t2 +do_execsql_test 2.4 { INSERT INTO t2(t2) VALUES('integrity-check') } + +do_execsql_test 2.5 { + SELECT level, count(*) FROM t2_segdir GROUP BY level +} { + 32 37 + 1056 37 + 2080 37 + 3104 37 +} + +do_test 2.6 { + while 1 { + set tc1 [db total_changes] + execsql { INSERT INTO t2(t2) VALUES('merge=5,2') } + set tc2 [db total_changes] + if {($tc2 - $tc1) < 2} break + } + execsql { SELECT level, count(*) FROM t2_segdir GROUP BY level } +} {33 1 1057 1 2081 1 3105 1} +do_execsql_test 2.7 { INSERT INTO t2(t2) VALUES('integrity-check') } + +do_execsql_test 2.8 { + INSERT INTO t2(words) SELECT words FROM t1; + SELECT level, count(*) FROM t2_segdir GROUP BY level; +} {0 2 1024 2 2048 2 3072 2} + +#------------------------------------------------------------------------- +# Check that 'optimize' works when there is data in the in-memory hash +# table, but no segments at all on disk. +# +do_execsql_test 3.1 { + CREATE VIRTUAL TABLE fts USING fts4 (t); + INSERT INTO fts (fts) VALUES ('optimize'); +} +do_execsql_test 3.2 { + INSERT INTO fts(fts) VALUES('integrity-check'); + SELECT count(*) FROM fts_segdir; +} {0} +do_execsql_test 3.3 { + BEGIN; + INSERT INTO fts (rowid, t) VALUES (2, 'test'); + INSERT INTO fts (fts) VALUES ('optimize'); + COMMIT; + SELECT level, idx FROM fts_segdir; +} {0 0} +do_execsql_test 3.4 { + INSERT INTO fts(fts) VALUES('integrity-check'); + SELECT rowid FROM fts WHERE fts MATCH 'test'; +} {2} +do_execsql_test 3.5 { + INSERT INTO fts (fts) VALUES ('optimize'); + INSERT INTO fts(fts) VALUES('integrity-check'); +} +do_test 3.6 { + set c1 [db total_changes] + execsql { INSERT INTO fts (fts) VALUES ('optimize') } + expr {[db total_changes] - $c1} +} {1} +do_test 3.7 { + execsql { INSERT INTO fts (rowid, t) VALUES (3, 'xyz') } + set c1 [db total_changes] + execsql { INSERT INTO fts (fts) VALUES ('optimize') } + expr {([db total_changes] - $c1) > 1} +} {1} +do_test 3.8 { + set c1 [db total_changes] + execsql { INSERT INTO fts (fts) VALUES ('optimize') } + expr {[db total_changes] - $c1} +} {1} + +finish_test diff --git a/test/fts4record.test b/test/fts4record.test new file mode 100644 index 0000000..f1a3eaf --- /dev/null +++ b/test/fts4record.test @@ -0,0 +1,120 @@ +# 2019 September 18 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS4 module. +# +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/fts3_common.tcl +set testprefix fts4record + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +sqlite3_fts3_may_be_corrupt 1 + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t1 USING fts4(x); + INSERT INTO t1 VALUES('terma terma terma termb'); +} + +do_execsql_test 1.1 { + SELECT quote(root) FROM t1_segdir +} { + X'00057465726D6105010203030004016203010500' +} + +proc make_record_wrapper {args} { make_fts3record $args } +db func record make_record_wrapper + +do_execsql_test 1.2 { + select quote( + record(0, 5, 'terma', 5, 1, 2, 3, 3, 0, + 4, 1, 'b' , 3, 1, 5, 0 + ) ); +} { + X'00057465726D6105010203030004016203010500' +} + +do_execsql_test 1.3.1 { + UPDATE t1_segdir SET root = + record(0, 5, 'terma', 5, 1, 2, 3, 3, 0, + 4, 1, 'b' , 3, 1, 5, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 + ); +} + +do_catchsql_test 1.3.2 { + SELECT snippet(t1) FROM t1 WHERE t1 MATCH 'term*' +} {1 {database disk image is malformed}} + +do_execsql_test 1.4.1 { + UPDATE t1_segdir SET root = + record(0, 5, 'terma', 5, 1, 2, 3, 3, 0, + 4, 1, 'b' , 4, 1, 5, + 256, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 + ); +} + +do_catchsql_test 1.4.2 { + SELECT snippet(t1) FROM t1 WHERE t1 MATCH 'term*' +} {1 {database disk image is malformed}} + +do_execsql_test 1.4.3 { + SELECT quote(root) FROM t1_segdir +} { + X'00057465726D610501020303000401620401058002010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010100' +} + +do_execsql_test 1.5.1 { + UPDATE t1_segdir SET root = + record(0, 5, 'terma', 5, 1, 2, 3, 3, 0, + 4, 1, 'b' , 4, 1, 5, + 256, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 + ); +} + +do_catchsql_test 1.4.2 { + SELECT snippet(t1) FROM t1 WHERE t1 MATCH 'term*' +} {1 {database disk image is malformed}} + +do_execsql_test 1.4.3 { + SELECT quote(root) FROM t1_segdir +} { + X'00057465726D610501020303000401620401058002010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010100' +} + + +do_execsql_test 1.5.1 { + UPDATE t1_segdir SET root = + X'00057465726D61050102030300040162040105FF00010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010100' +} + +do_catchsql_test 1.5.2 { + SELECT snippet(t1) FROM t1 WHERE t1 MATCH 'term*' +} {1 {database disk image is malformed}} + +do_catchsql_test 1.5.3 { + INSERT INTO t1(t1) VALUES('integrity-check'); +} {1 {database disk image is malformed}} + +finish_test diff --git a/test/fts4rename.test b/test/fts4rename.test new file mode 100644 index 0000000..5571ea7 --- /dev/null +++ b/test/fts4rename.test @@ -0,0 +1,43 @@ +# 2019 April 30 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/fts3_common.tcl +set ::testprefix fts4rename + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE temp.t1 USING fts3(a); + BEGIN; + CREATE TABLE t2(x); +} {} + +do_catchsql_test 1.1 { + ALTER TABLE t1_content RENAME c0a TO docid; +} {1 {error in table t1_content after rename: duplicate column name: docid}} + +do_catchsql_test 1.2 { + UPDATE t1 SET Col0 = 1 ; +} {1 {no such column: Col0}} + +do_catchsql_test 1.3 { + ROLLBACK; + DROP TABLE t1; +} {0 {}} + +finish_test diff --git a/test/fts4umlaut.test b/test/fts4umlaut.test new file mode 100644 index 0000000..a5a652f --- /dev/null +++ b/test/fts4umlaut.test @@ -0,0 +1,64 @@ +# 2018 December 3 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS5 module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts4umlaut + +ifcapable !fts3 { + finish_test + return +} + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t1 USING fts4(x, tokenize=unicode61); + CREATE VIRTUAL TABLE t2 USING fts4( + x, + tokenize=unicode61 "remove_diacritics=2" + ); +} + +foreach {tn q res1 res2} { + 1 "Hà Nội" 0 1 + 2 "Hà Noi" 1 1 + 3 "Ha Noi" 1 1 + 4 "Ha N\u1ed9i" 0 1 + 5 "Ha N\u006fi" 1 1 + 6 "Ha N\u006f\u0302i" 1 1 + 7 "Ha N\u006f\u0323\u0302i" 1 1 +} { + do_execsql_test 1.$tn.1 { + DELETE FROM t1; + INSERT INTO t1(rowid, x) VALUES (1, 'Ha Noi'); + SELECT count(*) FROM t1 WHERE t1 MATCH $q + } $res1 + do_execsql_test 1.$tn.2 { + DELETE FROM t1; + INSERT INTO t1(rowid, x) VALUES (1, $q); + SELECT count(*) FROM t1 WHERE t1 MATCH 'Ha Noi' + } $res1 + + do_execsql_test 1.$tn.3 { + DELETE FROM t2; + INSERT INTO t2(rowid, x) VALUES (1, 'Ha Noi'); + SELECT count(*) FROM t2 WHERE t2 MATCH $q + } $res2 + do_execsql_test 1.$tn.4 { + DELETE FROM t2; + INSERT INTO t2(rowid, x) VALUES (1, $q); + SELECT count(*) FROM t2 WHERE t2 MATCH 'Ha Noi' + } $res2 +} + +finish_test diff --git a/test/fts4unicode.test b/test/fts4unicode.test new file mode 100644 index 0000000..facf2bf --- /dev/null +++ b/test/fts4unicode.test @@ -0,0 +1,588 @@ +# 2012 May 25 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# +# The tests in this file focus on testing the "unicode" FTS tokenizer. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +ifcapable !fts3_unicode { finish_test ; return } +set ::testprefix fts4unicode + +proc do_unicode_token_test {tn input res} { + set input [string map {' ''} $input] + uplevel [list do_execsql_test $tn " + SELECT fts3_tokenizer_test('unicode61', 'remove_diacritics=0', '$input'); + " [list [list {*}$res]]] +} + +proc do_unicode_token_test2 {tn input res} { + set input [string map {' ''} $input] + uplevel [list do_execsql_test $tn " + SELECT fts3_tokenizer_test('unicode61', '$input'); + " [list [list {*}$res]]] +} + +proc do_unicode_token_test3 {tn args} { + set res [lindex $args end] + set sql "SELECT fts3_tokenizer_test('unicode61'" + foreach a [lrange $args 0 end-1] { + append sql ", '" + append sql [string map {' ''} $a] + append sql "'" + } + append sql ")" + uplevel [list do_execsql_test $tn $sql [list [list {*}$res]]] +} + +do_unicode_token_test 1.0 {a B c D} {0 a a 1 b B 2 c c 3 d D} + +do_unicode_token_test 1.1 "\uC4 \uD6 \uDC" \ + "0 \uE4 \uC4 1 \uF6 \uD6 2 \uFC \uDC" + +do_unicode_token_test 1.2 "x\uC4x x\uD6x x\uDCx" \ + "0 x\uE4x x\uC4x 1 x\uF6x x\uD6x 2 x\uFCx x\uDCx" + +# 0x00DF is a small "sharp s". 0x1E9E is a capital sharp s. +do_unicode_token_test 1.3 "\uDF" "0 \uDF \uDF" +do_unicode_token_test 1.4 "\u1E9E" "0 \uDF \u1E9E" + +do_unicode_token_test 1.5 "The quick brown fox" { + 0 the The 1 quick quick 2 brown brown 3 fox fox +} +do_unicode_token_test 1.6 "The\u00bfquick\u224ebrown\u2263fox" { + 0 the The 1 quick quick 2 brown brown 3 fox fox +} + +do_unicode_token_test2 1.7 {a B c D} {0 a a 1 b B 2 c c 3 d D} +do_unicode_token_test2 1.8 "\uC4 \uD6 \uDC" "0 a \uC4 1 o \uD6 2 u \uDC" + +do_unicode_token_test2 1.9 "x\uC4x x\uD6x x\uDCx" \ + "0 xax x\uC4x 1 xox x\uD6x 2 xux x\uDCx" + +# Check that diacritics are removed if remove_diacritics=1 is specified. +# And that they do not break tokens. +do_unicode_token_test2 1.10 "xx\u0301xx" "0 xxxx xx\u301xx" + +# Title-case mappings work +do_unicode_token_test 1.11 "\u01c5" "0 \u01c6 \u01c5" + +#------------------------------------------------------------------------- +# +set docs [list { + Enhance the INSERT syntax to allow multiple rows to be inserted via the + VALUES clause. +} { + Enhance the CREATE VIRTUAL TABLE command to support the IF NOT EXISTS clause. +} { + Added the sqlite3_stricmp() interface as a counterpart to sqlite3_strnicmp(). +} { + Added the sqlite3_db_readonly() interface. +} { + Added the SQLITE_FCNTL_PRAGMA file control, giving VFS implementations the + ability to add new PRAGMA statements or to override built-in PRAGMAs. +} { + Queries of the form: "SELECT max(x), y FROM table" returns the value of y on + the same row that contains the maximum x value. +} { + Added support for the FTS4 languageid option. +} { + Documented support for the FTS4 content option. This feature has actually + been in the code since version 3.7.9 but is only now considered to be + officially supported. +} { + Pending statements no longer block ROLLBACK. Instead, the pending statement + will return SQLITE_ABORT upon next access after the ROLLBACK. +} { + Improvements to the handling of CSV inputs in the command-line shell +} { + Fix a bug introduced in version 3.7.10 that might cause a LEFT JOIN to be + incorrectly converted into an INNER JOIN if the WHERE clause indexable terms + connected by OR. +}] + +set map(a) [list "\u00C4" "\u00E4"] ; # LATIN LETTER A WITH DIAERESIS +set map(e) [list "\u00CB" "\u00EB"] ; # LATIN LETTER E WITH DIAERESIS +set map(i) [list "\u00CF" "\u00EF"] ; # LATIN LETTER I WITH DIAERESIS +set map(o) [list "\u00D6" "\u00F6"] ; # LATIN LETTER O WITH DIAERESIS +set map(u) [list "\u00DC" "\u00FC"] ; # LATIN LETTER U WITH DIAERESIS +set map(y) [list "\u0178" "\u00FF"] ; # LATIN LETTER Y WITH DIAERESIS +set map(h) [list "\u1E26" "\u1E27"] ; # LATIN LETTER H WITH DIAERESIS +set map(w) [list "\u1E84" "\u1E85"] ; # LATIN LETTER W WITH DIAERESIS +set map(x) [list "\u1E8C" "\u1E8D"] ; # LATIN LETTER X WITH DIAERESIS +foreach k [array names map] { + lappend mappings [string toupper $k] [lindex $map($k) 0] + lappend mappings $k [lindex $map($k) 1] +} +proc mapdoc {doc} { + set doc [regsub -all {[[:space:]]+} $doc " "] + string map $::mappings [string trim $doc] +} + +do_test 2.0 { + execsql { CREATE VIRTUAL TABLE t2 USING fts4(tokenize=unicode61, x); } + foreach doc $docs { + set d [mapdoc $doc] + execsql { INSERT INTO t2 VALUES($d) } + } +} {} + +do_test 2.1 { + set q [mapdoc "row"] + execsql { SELECT * FROM t2 WHERE t2 MATCH $q } +} [list [mapdoc { + Queries of the form: "SELECT max(x), y FROM table" returns the value of y on + the same row that contains the maximum x value. +}]] + +foreach {tn query snippet} { + 2 "row" { + ...returns the value of y on the same [row] that contains + the maximum x value. + } + 3 "ROW" { + ...returns the value of y on the same [row] that contains + the maximum x value. + } + 4 "rollback" { + ...[ROLLBACK]. Instead, the pending statement + will return SQLITE_ABORT upon next access after the [ROLLBACK]. + } + 5 "rOllback" { + ...[ROLLBACK]. Instead, the pending statement + will return SQLITE_ABORT upon next access after the [ROLLBACK]. + } + 6 "lang*" { + Added support for the FTS4 [languageid] option. + } +} { + do_test 2.$tn { + set q [mapdoc $query] + execsql { SELECT snippet(t2, '[', ']', '...') FROM t2 WHERE t2 MATCH $q } + } [list [mapdoc $snippet]] +} + +#------------------------------------------------------------------------- +# Make sure the unicode61 tokenizer does not crash if it is passed a +# NULL pointer. +reset_db +do_execsql_test 3.1 { + CREATE VIRTUAL TABLE t1 USING fts4(tokenize=unicode61, x, y); + INSERT INTO t1 VALUES(NULL, 'a b c'); +} + +do_execsql_test 3.2 { + SELECT snippet(t1, '[', ']') FROM t1 WHERE t1 MATCH 'b' +} {{a [b] c}} + +do_execsql_test 3.3 { + BEGIN; + DELETE FROM t1; + INSERT INTO t1 VALUES('b b b b b b b b b b b', 'b b b b b b b b b b b b b'); + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 VALUES('a b c', NULL); + INSERT INTO t1 VALUES('a x c', NULL); + COMMIT; +} + +do_execsql_test 3.4 { + SELECT * FROM t1 WHERE t1 MATCH 'a b'; +} {{a b c} {}} + +#------------------------------------------------------------------------- +# +reset_db + +do_test 4.1 { + set a "abc\uFFFEdef" + set b "abc\uD800def" + set c "\uFFFEdef" + set d "\uD800def" + execsql { + CREATE VIRTUAL TABLE t1 USING fts4(tokenize=unicode61, x); + INSERT INTO t1 VALUES($a); + INSERT INTO t1 VALUES($b); + INSERT INTO t1 VALUES($c); + INSERT INTO t1 VALUES($d); + } +} {} + +do_test 4.2 { + set a [binary format c* {0x61 0xF7 0xBF 0xBF 0xBF 0x62}] + set b [binary format c* {0x61 0xF7 0xBF 0xBF 0xBF 0xBF 0x62}] + set c [binary format c* {0x61 0xF7 0xBF 0xBF 0xBF 0xBF 0xBF 0x62}] + set d [binary format c* {0x61 0xF7 0xBF 0xBF 0xBF 0xBF 0xBF 0xBF 0x62}] + execsql { + INSERT INTO t1 VALUES($a); + INSERT INTO t1 VALUES($b); + INSERT INTO t1 VALUES($c); + INSERT INTO t1 VALUES($d); + } +} {} + +do_test 4.3 { + set a [binary format c* {0xF7 0xBF 0xBF 0xBF}] + set b [binary format c* {0xF7 0xBF 0xBF 0xBF 0xBF}] + set c [binary format c* {0xF7 0xBF 0xBF 0xBF 0xBF 0xBF}] + set d [binary format c* {0xF7 0xBF 0xBF 0xBF 0xBF 0xBF 0xBF}] + execsql { + INSERT INTO t1 VALUES($a); + INSERT INTO t1 VALUES($b); + INSERT INTO t1 VALUES($c); + INSERT INTO t1 VALUES($d); + } +} {} + +#------------------------------------------------------------------------- + +do_unicode_token_test3 5.1 {tokenchars=} { + sqlite3_reset sqlite3_column_int +} { + 0 sqlite3 sqlite3 + 1 reset reset + 2 sqlite3 sqlite3 + 3 column column + 4 int int +} + +do_unicode_token_test3 5.2 {tokenchars=_} { + sqlite3_reset sqlite3_column_int +} { + 0 sqlite3_reset sqlite3_reset + 1 sqlite3_column_int sqlite3_column_int +} + +do_unicode_token_test3 5.3 {separators=xyz} { + Laotianxhorseyrunszfast +} { + 0 laotian Laotian + 1 horse horse + 2 runs runs + 3 fast fast +} + +do_unicode_token_test3 5.4 {tokenchars=xyz} { + Laotianxhorseyrunszfast +} { + 0 laotianxhorseyrunszfast Laotianxhorseyrunszfast +} + +do_unicode_token_test3 5.5 {tokenchars=_} {separators=zyx} { + sqlite3_resetxsqlite3_column_intyhonda_phantom +} { + 0 sqlite3_reset sqlite3_reset + 1 sqlite3_column_int sqlite3_column_int + 2 honda_phantom honda_phantom +} + +do_unicode_token_test3 5.6 "separators=\u05D1" "abc\u05D1def" { + 0 abc abc 1 def def +} + +do_unicode_token_test3 5.7 \ + "tokenchars=\u2444\u2445" \ + "separators=\u05D0\u05D1\u05D2" \ + "\u2444fre\u2445sh\u05D0water\u05D2fish.\u2445timer" \ + [list \ + 0 \u2444fre\u2445sh \u2444fre\u2445sh \ + 1 water water \ + 2 fish fish \ + 3 \u2445timer \u2445timer \ + ] + +# Check that it is not possible to add a standalone diacritic codepoint +# to either separators or tokenchars. +do_unicode_token_test3 5.8 "separators=\u0301" \ + "hello\u0301world \u0301helloworld" \ + "0 helloworld hello\u0301world 1 helloworld helloworld" + +do_unicode_token_test3 5.9 "tokenchars=\u0301" \ + "hello\u0301world \u0301helloworld" \ + "0 helloworld hello\u0301world 1 helloworld helloworld" + +do_unicode_token_test3 5.10 "separators=\u0301" \ + "remove_diacritics=0" \ + "hello\u0301world \u0301helloworld" \ + "0 hello\u0301world hello\u0301world 1 helloworld helloworld" + +do_unicode_token_test3 5.11 "tokenchars=\u0301" \ + "remove_diacritics=0" \ + "hello\u0301world \u0301helloworld" \ + "0 hello\u0301world hello\u0301world 1 helloworld helloworld" + + +#------------------------------------------------------------------------- + +proc do_tokenize {tokenizer txt} { + set res [list] + foreach {a b c} [db one {SELECT fts3_tokenizer_test($tokenizer, $txt)}] { + lappend res $b + } + set res +} + +# Argument $lCodepoint must be a list of codepoints (integers) that +# correspond to whitespace characters. This command creates a string +# $W from the codepoints, then tokenizes "${W}hello{$W}world${W}" +# using tokenizer $tokenizer. The test passes if the tokenizer successfully +# extracts the two 5 character tokens. +# +proc do_isspace_test {tn tokenizer lCp} { + set whitespace [format [string repeat %c [llength $lCp]] {*}$lCp] + set txt "${whitespace}hello${whitespace}world${whitespace}" + uplevel [list do_test $tn [list do_tokenize $tokenizer $txt] {hello world}] +} + +set tokenizers [list unicode61] +ifcapable icu { lappend tokenizers icu } + +# Some tests to check that the tokenizers can both identify white-space +# codepoints. All codepoints tested below are of type "Zs" in the +# UnicodeData.txt file. +# +# Note that codepoint 6158 has changed from Zs to Cf in recent versions +# of UnicodeData.txt. So take that into account for the "icu" tests. +# +foreach T $tokenizers { + do_isspace_test 6.$T.1 $T 32 + do_isspace_test 6.$T.2 $T 160 + do_isspace_test 6.$T.3 $T 5760 + if {$T!="icu"} { + do_isspace_test 6.$T.4 $T 6158 + } + do_isspace_test 6.$T.5 $T 8192 + do_isspace_test 6.$T.6 $T 8193 + do_isspace_test 6.$T.7 $T 8194 + do_isspace_test 6.$T.8 $T 8195 + do_isspace_test 6.$T.9 $T 8196 + do_isspace_test 6.$T.10 $T 8197 + do_isspace_test 6.$T.11 $T 8198 + do_isspace_test 6.$T.12 $T 8199 + do_isspace_test 6.$T.13 $T 8200 + do_isspace_test 6.$T.14 $T 8201 + do_isspace_test 6.$T.15 $T 8202 + if {$T!="icu"} { + do_isspace_test 6.$T.16 $T 8239 + } + do_isspace_test 6.$T.17 $T 8287 + do_isspace_test 6.$T.18 $T 12288 + + if {$T!="icu"} { + do_isspace_test 6.$T.19 $T {32 160 5760 6158} + } else { + do_isspace_test 6.$T.19 $T {32 160 5760 8192} + } + do_isspace_test 6.$T.20 $T {8192 8193 8194 8195} + do_isspace_test 6.$T.21 $T {8196 8197 8198 8199} + do_isspace_test 6.$T.22 $T {8200 8201 8202 8239} + do_isspace_test 6.$T.23 $T {8287 12288} +} + +#------------------------------------------------------------------------- +# Test that the private use ranges are treated as alphanumeric. +# +foreach {tn1 c} { + 1 \ue000 2 \ue001 3 \uf000 4 \uf8fe 5 \uf8ff +} { + foreach {tn2 config res} { + 1 "" "0 hello*world hello*world" + 2 "separators=*" "0 hello hello 1 world world" + } { + set config [string map [list * $c] $config] + set input [string map [list * $c] "hello*world"] + set output [string map [list * $c] $res] + do_unicode_token_test3 7.$tn1.$tn2 {*}$config $input $output + } +} + +#------------------------------------------------------------------------- +# Cursory test of remove_diacritics=0. +# +# 00C4;LATIN CAPITAL LETTER A WITH DIAERESIS +# 00D6;LATIN CAPITAL LETTER O WITH DIAERESIS +# 00E4;LATIN SMALL LETTER A WITH DIAERESIS +# 00F6;LATIN SMALL LETTER O WITH DIAERESIS +# +do_execsql_test 8.1.1 " + CREATE VIRTUAL TABLE t3 USING fts4(tokenize=unicode61 'remove_diacritics=1'); + INSERT INTO t3 VALUES('o'); + INSERT INTO t3 VALUES('a'); + INSERT INTO t3 VALUES('O'); + INSERT INTO t3 VALUES('A'); + INSERT INTO t3 VALUES('\xD6'); + INSERT INTO t3 VALUES('\xC4'); + INSERT INTO t3 VALUES('\xF6'); + INSERT INTO t3 VALUES('\xE4'); +" +do_execsql_test 8.1.2 { + SELECT rowid FROM t3 WHERE t3 MATCH 'o'; +} {1 3 5 7} +do_execsql_test 8.1.3 { + SELECT rowid FROM t3 WHERE t3 MATCH 'a'; +} {2 4 6 8} +do_execsql_test 8.2.1 { + CREATE VIRTUAL TABLE t4 USING fts4(tokenize=unicode61 "remove_diacritics=0"); + INSERT INTO t4 SELECT * FROM t3; +} +do_execsql_test 8.2.2 { + SELECT rowid FROM t4 WHERE t4 MATCH 'o'; +} {1 3} +do_execsql_test 8.2.3 { + SELECT rowid FROM t4 WHERE t4 MATCH 'a'; +} {2 4} + +#------------------------------------------------------------------------- +# +foreach {tn sql} { + 1 { + CREATE VIRTUAL TABLE t5 USING fts4(tokenize=unicode61 [tokenchars= .]); + CREATE VIRTUAL TABLE t6 USING fts4( + tokenize=unicode61 [tokenchars=="] "tokenchars=[]"); + CREATE VIRTUAL TABLE t7 USING fts4(tokenize=unicode61 [separators=x\xC4]); + } + 2 { + CREATE VIRTUAL TABLE t5 USING fts4(tokenize=unicode61 "tokenchars= ."); + CREATE VIRTUAL TABLE t6 USING fts4(tokenize=unicode61 "tokenchars=[=""]"); + CREATE VIRTUAL TABLE t7 USING fts4(tokenize=unicode61 "separators=x\xC4"); + } + 3 { + CREATE VIRTUAL TABLE t5 USING fts4(tokenize=unicode61 'tokenchars= .'); + CREATE VIRTUAL TABLE t6 USING fts4(tokenize=unicode61 'tokenchars=="[]'); + CREATE VIRTUAL TABLE t7 USING fts4(tokenize=unicode61 'separators=x\xC4'); + } + 4 { + CREATE VIRTUAL TABLE t5 USING fts4(tokenize=unicode61 `tokenchars= .`); + CREATE VIRTUAL TABLE t6 USING fts4(tokenize=unicode61 `tokenchars=[="]`); + CREATE VIRTUAL TABLE t7 USING fts4(tokenize=unicode61 `separators=x\xC4`); + } +} { + do_execsql_test 9.$tn.0 { + DROP TABLE IF EXISTS t5; + DROP TABLE IF EXISTS t5aux; + DROP TABLE IF EXISTS t6; + DROP TABLE IF EXISTS t6aux; + DROP TABLE IF EXISTS t7; + DROP TABLE IF EXISTS t7aux; + } + do_execsql_test 9.$tn.1 $sql + + do_execsql_test 9.$tn.2 { + CREATE VIRTUAL TABLE t5aux USING fts4aux(t5); + INSERT INTO t5 VALUES('one two three/four.five.six'); + SELECT * FROM t5aux; + } { + four.five.six * 1 1 four.five.six 0 1 1 + {one two three} * 1 1 {one two three} 0 1 1 + } + + do_execsql_test 9.$tn.3 { + CREATE VIRTUAL TABLE t6aux USING fts4aux(t6); + INSERT INTO t6 VALUES('alpha=beta"gamma/delta[epsilon]zeta'); + SELECT * FROM t6aux; + } { + {alpha=beta"gamma} * 1 1 {alpha=beta"gamma} 0 1 1 + {delta[epsilon]zeta} * 1 1 {delta[epsilon]zeta} 0 1 1 + } + + do_execsql_test 9.$tn.4 { + CREATE VIRTUAL TABLE t7aux USING fts4aux(t7); + INSERT INTO t7 VALUES('alephxbeth\xC4gimel'); + SELECT * FROM t7aux; + } { + aleph * 1 1 aleph 0 1 1 + beth * 1 1 beth 0 1 1 + gimel * 1 1 gimel 0 1 1 + } +} + +# Check that multiple options are handled correctly. +# +do_execsql_test 10.1 { + DROP TABLE IF EXISTS t1; + CREATE VIRTUAL TABLE t1 USING fts4(tokenize=unicode61 + "tokenchars=xyz" "tokenchars=.=" "separators=.=" "separators=xy" + "separators=a" "separators=a" "tokenchars=a" "tokenchars=a" + ); + + INSERT INTO t1 VALUES('oneatwoxthreeyfour'); + INSERT INTO t1 VALUES('a.single=word'); + CREATE VIRTUAL TABLE t1aux USING fts4aux(t1); + SELECT * FROM t1aux; +} { + .single=word * 1 1 .single=word 0 1 1 + four * 1 1 four 0 1 1 + one * 1 1 one 0 1 1 + three * 1 1 three 0 1 1 + two * 1 1 two 0 1 1 +} + +# Test that case folding happens after tokenization, not before. +# +do_execsql_test 10.2 { + DROP TABLE IF EXISTS t2; + CREATE VIRTUAL TABLE t2 USING fts4(tokenize=unicode61 "separators=aB"); + INSERT INTO t2 VALUES('oneatwoBthree'); + INSERT INTO t2 VALUES('onebtwoAthree'); + CREATE VIRTUAL TABLE t2aux USING fts4aux(t2); + SELECT * FROM t2aux; +} { + one * 1 1 one 0 1 1 + onebtwoathree * 1 1 onebtwoathree 0 1 1 + three * 1 1 three 0 1 1 + two * 1 1 two 0 1 1 +} + +# Test that the tokenchars and separators options work with the +# fts3tokenize table. +# +do_execsql_test 11.1 { + CREATE VIRTUAL TABLE ft1 USING fts3tokenize( + "unicode61", "tokenchars=@.", "separators=1234567890" + ); + SELECT token FROM ft1 WHERE input = 'berlin@street123sydney.road'; +} { + berlin@street sydney.road +} + +# Test for embedded nul characters in fts4 unicode index. +# +do_execsql_test 12.0 { + CREATE VIRTUAL TABLE t12 USING fts4(tokenize=unicode61); + INSERT INTO t12 VALUES('abc' || char(0) || 'def'); + SELECT hex(CAST(content AS blob)) FROM t12; +} {61626300646566} +do_execsql_test 12.1 { + INSERT INTO t12(t12) VALUES('integrity-check'); +} {} +do_execsql_test 12.2 { + CREATE VIRTUAL TABLE t12aux USING fts4aux(t12); + SELECT * FROM t12aux; +} {abc * 1 1 abc 0 1 1} +do_execsql_test 12.3 { + SELECT hex(CAST(content AS blob)) FROM t12 WHERE t12 MATCH 'abc' +} {61626300646566} + +finish_test diff --git a/test/fts4upfrom.test b/test/fts4upfrom.test new file mode 100644 index 0000000..889b64a --- /dev/null +++ b/test/fts4upfrom.test @@ -0,0 +1,139 @@ +# 2020 February 24 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing UPDATE statements with FROM clauses +# against FTS4 tables. +# +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts4upfrom + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +foreach {tn create_table} { + 0 { CREATE VIRTUAL TABLE ft USING fts5(a, b, c) } + 1 { CREATE VIRTUAL TABLE ft USING fts3(a, b, c) } + 2 { CREATE TABLE ft(a, b, c) } + 3 { + CREATE TABLE real(a, b, c); + CREATE INDEX i1 ON real(a); + CREATE VIEW ft AS SELECT rowid, a, b, c FROM real; + CREATE TRIGGER tr1 INSTEAD OF INSERT ON ft BEGIN + INSERT INTO real(rowid, a, b, c) VALUES(new.rowid, new.a, new.b, new.c); + END; + CREATE TRIGGER tr2 INSTEAD OF UPDATE ON ft BEGIN + UPDATE real SET rowid=new.rowid, a=new.a, b=new.b, c=new.c + WHERE rowid=old.rowid; + END; + } +} { + if {$tn==0} { ifcapable !fts5 { continue } } + catchsql { DROP VIEW IF EXISTS changes } + catchsql { DROP TABLE IF EXISTS ft } + catchsql { DROP VIEW IF EXISTS ft } + execsql $create_table + + do_execsql_test 1.$tn.0 { + INSERT INTO ft(a, b, c) VALUES('a', NULL, 'apple'); + INSERT INTO ft(a, b, c) VALUES('b', NULL, 'banana'); + INSERT INTO ft(a, b, c) VALUES('c', NULL, 'cherry'); + INSERT INTO ft(a, b, c) VALUES('d', NULL, 'damson plum'); + } + + do_execsql_test 1.$tn.1 { + SELECT a, b, c FROM ft ORDER BY rowid; + } { + a {} apple + b {} banana + c {} cherry + d {} {damson plum} + } + + do_execsql_test 1.$tn.2 { + UPDATE ft SET b=o.c FROM ft AS o WHERE (ft.a == char(unicode(o.a)+1)) + } + + do_execsql_test 1.$tn.3 { + SELECT a, b, c FROM ft ORDER BY rowid; + } { + a {} apple + b apple banana + c banana cherry + d cherry {damson plum} + } + + do_catchsql_test 1.$tn.4 { + UPDATE ft SET c=v FROM changes WHERE a=k; + } {1 {no such table: changes}} + + do_execsql_test 1.$tn.5 { + create view changes(k, v) AS + VALUES( 'd', 'dewberry' ) UNION ALL + VALUES( 'c', 'clementine' ) UNION ALL + VALUES( 'b', 'blueberry' ) UNION ALL + VALUES( 'a', 'apricot' ) + ; + } + + do_execsql_test 1.$tn.6 { + UPDATE ft SET c=v FROM changes WHERE a=k; + } + + do_execsql_test 1.$tn.7 { + SELECT rowid, a, b, c FROM ft ORDER BY rowid; + } { + 1 a {} apricot + 2 b apple blueberry + 3 c banana clementine + 4 d cherry dewberry + } + + do_execsql_test 1.$tn.8 " + WITH x1(o, n) AS ( + VALUES(1, 11) UNION ALL + VALUES(2, 12) UNION ALL + VALUES(3, 13) UNION ALL + VALUES(4, 14) + ) + SELECT ft.rowid, a, b, c, o, n FROM ft, x1 WHERE ft.rowid = o; + " { + 1 a {} apricot 1 11 + 2 b apple blueberry 2 12 + 3 c banana clementine 3 13 + 4 d cherry dewberry 4 14 + } + + set ROWID rowid + if {$tn==1} { set ROWID docid } + do_execsql_test 1.$tn.9 " + WITH x1(o, n) AS ( + VALUES(1, 11) UNION ALL + VALUES(2, 12) UNION ALL + VALUES(3, 13) UNION ALL + VALUES(4, 14) + ) + UPDATE ft SET $ROWID = n FROM x1 WHERE ft.rowid = o; + SELECT rowid, a, b, c FROM ft ORDER BY rowid; + " { + 11 a {} apricot + 12 b apple blueberry + 13 c banana clementine + 14 d cherry dewberry + } +} + +finish_test diff --git a/test/full.test b/test/full.test new file mode 100644 index 0000000..a8fe371 --- /dev/null +++ b/test/full.test @@ -0,0 +1,20 @@ +# 2012 September 12 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file runs the "full" test suite. It is a peer of the quick.test +# and all.test scripts. +# + +set testdir [file dirname $argv0] +source $testdir/permutations.test + +run_test_suite full + +finish_test diff --git a/test/func.test b/test/func.test new file mode 100644 index 0000000..883950a --- /dev/null +++ b/test/func.test @@ -0,0 +1,1556 @@ +# 2001 September 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing built-in functions. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix func + +# Create a table to work with. +# +do_test func-0.0 { + execsql {CREATE TABLE tbl1(t1 text)} + foreach word {this program is free software} { + execsql "INSERT INTO tbl1 VALUES('$word')" + } + execsql {SELECT t1 FROM tbl1 ORDER BY t1} +} {free is program software this} +do_test func-0.1 { + execsql { + CREATE TABLE t2(a); + INSERT INTO t2 VALUES(1); + INSERT INTO t2 VALUES(NULL); + INSERT INTO t2 VALUES(345); + INSERT INTO t2 VALUES(NULL); + INSERT INTO t2 VALUES(67890); + SELECT * FROM t2; + } +} {1 {} 345 {} 67890} + +# Check out the length() function +# +do_test func-1.0 { + execsql {SELECT length(t1) FROM tbl1 ORDER BY t1} +} {4 2 7 8 4} +set isutf16 [regexp 16 [db one {PRAGMA encoding}]] +do_execsql_test func-1.0b { + SELECT octet_length(t1) FROM tbl1 ORDER BY t1; +} [expr {$isutf16?"8 4 14 16 8":"4 2 7 8 4"}] +do_test func-1.1 { + set r [catch {execsql {SELECT length(*) FROM tbl1 ORDER BY t1}} msg] + lappend r $msg +} {1 {wrong number of arguments to function length()}} +do_test func-1.2 { + set r [catch {execsql {SELECT length(t1,5) FROM tbl1 ORDER BY t1}} msg] + lappend r $msg +} {1 {wrong number of arguments to function length()}} +do_test func-1.3 { + execsql {SELECT length(t1), count(*) FROM tbl1 GROUP BY length(t1) + ORDER BY length(t1)} +} {2 1 4 2 7 1 8 1} +do_test func-1.4 { + execsql {SELECT coalesce(length(a),-1) FROM t2} +} {1 -1 3 -1 5} +do_execsql_test func-1.5 { + SELECT octet_length(12345); +} [expr {(1+($isutf16!=0))*5}] +db null NULL +do_execsql_test func-1.6 { + SELECT octet_length(NULL); +} {NULL} +do_execsql_test func-1.7 { + SELECT octet_length(7.5); +} [expr {(1+($isutf16!=0))*3}] +do_execsql_test func-1.8 { + SELECT octet_length(x'30313233'); +} {4} +do_execsql_test func-1.9 { + WITH c(x) AS (VALUES(char(350,351,352,353,354))) + SELECT length(x), octet_length(x) FROM c; +} {5 10} + + + +# Check out the substr() function +# +db null {} +do_test func-2.0 { + execsql {SELECT substr(t1,1,2) FROM tbl1 ORDER BY t1} +} {fr is pr so th} +do_test func-2.1 { + execsql {SELECT substr(t1,2,1) FROM tbl1 ORDER BY t1} +} {r s r o h} +do_test func-2.2 { + execsql {SELECT substr(t1,3,3) FROM tbl1 ORDER BY t1} +} {ee {} ogr ftw is} +do_test func-2.3 { + execsql {SELECT substr(t1,-1,1) FROM tbl1 ORDER BY t1} +} {e s m e s} +do_test func-2.4 { + execsql {SELECT substr(t1,-1,2) FROM tbl1 ORDER BY t1} +} {e s m e s} +do_test func-2.5 { + execsql {SELECT substr(t1,-2,1) FROM tbl1 ORDER BY t1} +} {e i a r i} +do_test func-2.6 { + execsql {SELECT substr(t1,-2,2) FROM tbl1 ORDER BY t1} +} {ee is am re is} +do_test func-2.7 { + execsql {SELECT substr(t1,-4,2) FROM tbl1 ORDER BY t1} +} {fr {} gr wa th} +do_test func-2.8 { + execsql {SELECT t1 FROM tbl1 ORDER BY substr(t1,2,20)} +} {this software free program is} +do_test func-2.9 { + execsql {SELECT substr(a,1,1) FROM t2} +} {1 {} 3 {} 6} +do_test func-2.10 { + execsql {SELECT substr(a,2,2) FROM t2} +} {{} {} 45 {} 78} + +# Only do the following tests if TCL has UTF-8 capabilities +# +if {"\u1234"!="u1234"} { + +# Put some UTF-8 characters in the database +# +do_test func-3.0 { + execsql {DELETE FROM tbl1} + foreach word "contains UTF-8 characters hi\u1234ho" { + execsql "INSERT INTO tbl1 VALUES('$word')" + } + execsql {SELECT t1 FROM tbl1 ORDER BY t1} +} "UTF-8 characters contains hi\u1234ho" +do_test func-3.1 { + execsql {SELECT length(t1) FROM tbl1 ORDER BY t1} +} {5 10 8 5} +do_test func-3.2 { + execsql {SELECT substr(t1,1,2) FROM tbl1 ORDER BY t1} +} {UT ch co hi} +do_test func-3.3 { + execsql {SELECT substr(t1,1,3) FROM tbl1 ORDER BY t1} +} "UTF cha con hi\u1234" +do_test func-3.4 { + execsql {SELECT substr(t1,2,2) FROM tbl1 ORDER BY t1} +} "TF ha on i\u1234" +do_test func-3.5 { + execsql {SELECT substr(t1,2,3) FROM tbl1 ORDER BY t1} +} "TF- har ont i\u1234h" +do_test func-3.6 { + execsql {SELECT substr(t1,3,2) FROM tbl1 ORDER BY t1} +} "F- ar nt \u1234h" +do_test func-3.7 { + execsql {SELECT substr(t1,4,2) FROM tbl1 ORDER BY t1} +} "-8 ra ta ho" +do_test func-3.8 { + execsql {SELECT substr(t1,-1,1) FROM tbl1 ORDER BY t1} +} "8 s s o" +do_test func-3.9 { + execsql {SELECT substr(t1,-3,2) FROM tbl1 ORDER BY t1} +} "F- er in \u1234h" +do_test func-3.10 { + execsql {SELECT substr(t1,-4,3) FROM tbl1 ORDER BY t1} +} "TF- ter ain i\u1234h" +do_test func-3.99 { + execsql {DELETE FROM tbl1} + foreach word {this program is free software} { + execsql "INSERT INTO tbl1 VALUES('$word')" + } + execsql {SELECT t1 FROM tbl1} +} {this program is free software} + +} ;# End \u1234!=u1234 + +# Test the abs() and round() functions. +# +ifcapable !floatingpoint { + do_test func-4.1 { + execsql { + CREATE TABLE t1(a,b,c); + INSERT INTO t1 VALUES(1,2,3); + INSERT INTO t1 VALUES(2,12345678901234,-1234567890); + INSERT INTO t1 VALUES(3,-2,-5); + } + catchsql {SELECT abs(a,b) FROM t1} + } {1 {wrong number of arguments to function abs()}} +} +ifcapable floatingpoint { + do_test func-4.1 { + execsql { + CREATE TABLE t1(a,b,c); + INSERT INTO t1 VALUES(1,2,3); + INSERT INTO t1 VALUES(2,1.2345678901234,-12345.67890); + INSERT INTO t1 VALUES(3,-2,-5); + } + catchsql {SELECT abs(a,b) FROM t1} + } {1 {wrong number of arguments to function abs()}} +} +do_test func-4.2 { + catchsql {SELECT abs() FROM t1} +} {1 {wrong number of arguments to function abs()}} +ifcapable floatingpoint { + do_test func-4.3 { + catchsql {SELECT abs(b) FROM t1 ORDER BY a} + } {0 {2 1.2345678901234 2}} + do_test func-4.4 { + catchsql {SELECT abs(c) FROM t1 ORDER BY a} + } {0 {3 12345.6789 5}} +} +ifcapable !floatingpoint { + if {[working_64bit_int]} { + do_test func-4.3 { + catchsql {SELECT abs(b) FROM t1 ORDER BY a} + } {0 {2 12345678901234 2}} + } + do_test func-4.4 { + catchsql {SELECT abs(c) FROM t1 ORDER BY a} + } {0 {3 1234567890 5}} +} +do_test func-4.4.1 { + execsql {SELECT abs(a) FROM t2} +} {1 {} 345 {} 67890} +do_test func-4.4.2 { + execsql {SELECT abs(t1) FROM tbl1} +} {0.0 0.0 0.0 0.0 0.0} + +ifcapable floatingpoint { + do_test func-4.5 { + catchsql {SELECT round(a,b,c) FROM t1} + } {1 {wrong number of arguments to function round()}} + do_test func-4.6 { + catchsql {SELECT round(b,2) FROM t1 ORDER BY b} + } {0 {-2.0 1.23 2.0}} + do_test func-4.7 { + catchsql {SELECT round(b,0) FROM t1 ORDER BY a} + } {0 {2.0 1.0 -2.0}} + do_test func-4.8 { + catchsql {SELECT round(c) FROM t1 ORDER BY a} + } {0 {3.0 -12346.0 -5.0}} + do_test func-4.9 { + catchsql {SELECT round(c,a) FROM t1 ORDER BY a} + } {0 {3.0 -12345.68 -5.0}} + do_test func-4.10 { + catchsql {SELECT 'x' || round(c,a) || 'y' FROM t1 ORDER BY a} + } {0 {x3.0y x-12345.68y x-5.0y}} + do_test func-4.11 { + catchsql {SELECT round() FROM t1 ORDER BY a} + } {1 {wrong number of arguments to function round()}} + do_test func-4.12 { + execsql {SELECT coalesce(round(a,2),'nil') FROM t2} + } {1.0 nil 345.0 nil 67890.0} + do_test func-4.13 { + execsql {SELECT round(t1,2) FROM tbl1} + } {0.0 0.0 0.0 0.0 0.0} + do_test func-4.14 { + execsql {SELECT typeof(round(5.1,1));} + } {real} + do_test func-4.15 { + execsql {SELECT typeof(round(5.1));} + } {real} + do_test func-4.16 { + catchsql {SELECT round(b,2.0) FROM t1 ORDER BY b} + } {0 {-2.0 1.23 2.0}} + # Verify some values reported on the mailing list. + # Some of these fail on MSVC builds with 64-bit + # long doubles, but not on GCC builds with 80-bit + # long doubles. + for {set i 1} {$i<999} {incr i} { + set x1 [expr 40222.5 + $i] + set x2 [expr 40223.0 + $i] + do_test func-4.17.$i { + execsql {SELECT round($x1);} + } $x2 + } + for {set i 1} {$i<999} {incr i} { + set x1 [expr 40222.05 + $i] + set x2 [expr 40222.10 + $i] + do_test func-4.18.$i { + execsql {SELECT round($x1,1);} + } $x2 + } + do_test func-4.20 { + execsql {SELECT round(40223.4999999999);} + } {40223.0} + do_test func-4.21 { + execsql {SELECT round(40224.4999999999);} + } {40224.0} + do_test func-4.22 { + execsql {SELECT round(40225.4999999999);} + } {40225.0} + for {set i 1} {$i<10} {incr i} { + do_test func-4.23.$i { + execsql {SELECT round(40223.4999999999,$i);} + } {40223.5} + do_test func-4.24.$i { + execsql {SELECT round(40224.4999999999,$i);} + } {40224.5} + do_test func-4.25.$i { + execsql {SELECT round(40225.4999999999,$i);} + } {40225.5} + } + for {set i 10} {$i<32} {incr i} { + do_test func-4.26.$i { + execsql {SELECT round(40223.4999999999,$i);} + } {40223.4999999999} + do_test func-4.27.$i { + execsql {SELECT round(40224.4999999999,$i);} + } {40224.4999999999} + do_test func-4.28.$i { + execsql {SELECT round(40225.4999999999,$i);} + } {40225.4999999999} + } + do_test func-4.29 { + execsql {SELECT round(1234567890.5);} + } {1234567891.0} + do_test func-4.30 { + execsql {SELECT round(12345678901.5);} + } {12345678902.0} + do_test func-4.31 { + execsql {SELECT round(123456789012.5);} + } {123456789013.0} + do_test func-4.32 { + execsql {SELECT round(1234567890123.5);} + } {1234567890124.0} + do_test func-4.33 { + execsql {SELECT round(12345678901234.5);} + } {12345678901235.0} + do_test func-4.34 { + execsql {SELECT round(1234567890123.35,1);} + } {1234567890123.4} + do_test func-4.35 { + execsql {SELECT round(1234567890123.445,2);} + } {1234567890123.45} + do_test func-4.36 { + execsql {SELECT round(99999999999994.5);} + } {99999999999995.0} + do_test func-4.37 { + execsql {SELECT round(9999999999999.55,1);} + } {9999999999999.6} + do_test func-4.38 { + execsql {SELECT round(9999999999999.556,2);} + } {9999999999999.56} + do_test func-4.39 { + string tolower [db eval {SELECT round(1e500), round(-1e500);}] + } {inf -inf} +} + +# Test the upper() and lower() functions +# +do_test func-5.1 { + execsql {SELECT upper(t1) FROM tbl1} +} {THIS PROGRAM IS FREE SOFTWARE} +do_test func-5.2 { + execsql {SELECT lower(upper(t1)) FROM tbl1} +} {this program is free software} +do_test func-5.3 { + execsql {SELECT upper(a), lower(a) FROM t2} +} {1 1 {} {} 345 345 {} {} 67890 67890} +ifcapable !icu { + do_test func-5.4 { + catchsql {SELECT upper(a,5) FROM t2} + } {1 {wrong number of arguments to function upper()}} +} +do_test func-5.5 { + catchsql {SELECT upper(*) FROM t2} +} {1 {wrong number of arguments to function upper()}} + +# Test the coalesce() and nullif() functions +# +do_test func-6.1 { + execsql {SELECT coalesce(a,'xyz') FROM t2} +} {1 xyz 345 xyz 67890} +do_test func-6.2 { + execsql {SELECT coalesce(upper(a),'nil') FROM t2} +} {1 nil 345 nil 67890} +do_test func-6.3 { + execsql {SELECT coalesce(nullif(1,1),'nil')} +} {nil} +do_test func-6.4 { + execsql {SELECT coalesce(nullif(1,2),'nil')} +} {1} +do_test func-6.5 { + execsql {SELECT coalesce(nullif(1,NULL),'nil')} +} {1} + + +# Test the last_insert_rowid() function +# +do_test func-7.1 { + execsql {SELECT last_insert_rowid()} +} [db last_insert_rowid] + +# Tests for aggregate functions and how they handle NULLs. +# +ifcapable floatingpoint { + do_test func-8.1 { + ifcapable explain { + execsql {EXPLAIN SELECT sum(a) FROM t2;} + } + execsql { + SELECT sum(a), count(a), round(avg(a),2), min(a), max(a), count(*) FROM t2; + } + } {68236 3 22745.33 1 67890 5} +} +ifcapable !floatingpoint { + do_test func-8.1 { + ifcapable explain { + execsql {EXPLAIN SELECT sum(a) FROM t2;} + } + execsql { + SELECT sum(a), count(a), avg(a), min(a), max(a), count(*) FROM t2; + } + } {68236 3 22745.0 1 67890 5} +} +do_test func-8.2 { + execsql { + SELECT max('z+'||a||'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP') FROM t2; + } +} {z+67890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP} + +ifcapable tempdb { + do_test func-8.3 { + execsql { + CREATE TEMP TABLE t3 AS SELECT a FROM t2 ORDER BY a DESC; + SELECT min('z+'||a||'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP') FROM t3; + } + } {z+1abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP} +} else { + do_test func-8.3 { + execsql { + CREATE TABLE t3 AS SELECT a FROM t2 ORDER BY a DESC; + SELECT min('z+'||a||'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP') FROM t3; + } + } {z+1abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP} +} +do_test func-8.4 { + execsql { + SELECT max('z+'||a||'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP') FROM t3; + } +} {z+67890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP} +ifcapable compound { + do_test func-8.5 { + execsql { + SELECT sum(x) FROM (SELECT '9223372036' || '854775807' AS x + UNION ALL SELECT -9223372036854775807) + } + } {0} + do_test func-8.6 { + execsql { + SELECT typeof(sum(x)) FROM (SELECT '9223372036' || '854775807' AS x + UNION ALL SELECT -9223372036854775807) + } + } {integer} + do_test func-8.7 { + execsql { + SELECT typeof(sum(x)) FROM (SELECT '9223372036' || '854775808' AS x + UNION ALL SELECT -9223372036854775807) + } + } {real} +ifcapable floatingpoint { + do_test func-8.8 { + execsql { + SELECT sum(x)>0.0 FROM (SELECT '9223372036' || '854775808' AS x + UNION ALL SELECT -9223372036850000000) + } + } {1} +} +ifcapable !floatingpoint { + do_test func-8.8 { + execsql { + SELECT sum(x)>0 FROM (SELECT '9223372036' || '854775808' AS x + UNION ALL SELECT -9223372036850000000) + } + } {1} +} +} + +# How do you test the random() function in a meaningful, deterministic way? +# +do_test func-9.1 { + execsql { + SELECT random() is not null; + } +} {1} +do_test func-9.2 { + execsql { + SELECT typeof(random()); + } +} {integer} +do_test func-9.3 { + execsql { + SELECT randomblob(32) is not null; + } +} {1} +do_test func-9.4 { + execsql { + SELECT typeof(randomblob(32)); + } +} {blob} +do_test func-9.5 { + execsql { + SELECT length(randomblob(32)), length(randomblob(-5)), + length(randomblob(2000)) + } +} {32 1 2000} + +# The "hex()" function was added in order to be able to render blobs +# generated by randomblob(). So this seems like a good place to test +# hex(). +# +ifcapable bloblit { + do_test func-9.10 { + execsql {SELECT hex(x'00112233445566778899aAbBcCdDeEfF')} + } {00112233445566778899AABBCCDDEEFF} +} +set encoding [db one {PRAGMA encoding}] +if {$encoding=="UTF-16le"} { + do_test func-9.11-utf16le { + execsql {SELECT hex(replace('abcdefg','ef','12'))} + } {6100620063006400310032006700} + do_test func-9.12-utf16le { + execsql {SELECT hex(replace('abcdefg','','12'))} + } {6100620063006400650066006700} + do_test func-9.13-utf16le { + execsql {SELECT hex(replace('aabcdefg','a','aaa'))} + } {610061006100610061006100620063006400650066006700} +} elseif {$encoding=="UTF-8"} { + do_test func-9.11-utf8 { + execsql {SELECT hex(replace('abcdefg','ef','12'))} + } {61626364313267} + do_test func-9.12-utf8 { + execsql {SELECT hex(replace('abcdefg','','12'))} + } {61626364656667} + do_test func-9.13-utf8 { + execsql {SELECT hex(replace('aabcdefg','a','aaa'))} + } {616161616161626364656667} +} +do_execsql_test func-9.14 { + WITH RECURSIVE c(x) AS ( + VALUES(1) + UNION ALL + SELECT x+1 FROM c WHERE x<1040 + ) + SELECT + count(*), + sum(length(replace(printf('abc%.*cxyz',x,'m'),'m','nnnn'))-(6+x*4)) + FROM c; +} {1040 0} + +# Use the "sqlite_register_test_function" TCL command which is part of +# the text fixture in order to verify correct operation of some of +# the user-defined SQL function APIs that are not used by the built-in +# functions. +# +set ::DB [sqlite3_connection_pointer db] +sqlite_register_test_function $::DB testfunc +do_test func-10.1 { + catchsql { + SELECT testfunc(NULL,NULL); + } +} {1 {first argument should be one of: int int64 string double null value}} +do_test func-10.2 { + execsql { + SELECT testfunc( + 'string', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', + 'int', 1234 + ); + } +} {1234} +do_test func-10.3 { + execsql { + SELECT testfunc( + 'string', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', + 'string', NULL + ); + } +} {{}} + +ifcapable floatingpoint { + do_test func-10.4 { + execsql { + SELECT testfunc( + 'string', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', + 'double', 1.234 + ); + } + } {1.234} + do_test func-10.5 { + execsql { + SELECT testfunc( + 'string', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', + 'int', 1234, + 'string', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', + 'string', NULL, + 'string', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', + 'double', 1.234, + 'string', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', + 'int', 1234, + 'string', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', + 'string', NULL, + 'string', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', + 'double', 1.234 + ); + } + } {1.234} +} + +# Test the built-in sqlite_version(*) SQL function. +# +do_test func-11.1 { + execsql { + SELECT sqlite_version(*); + } +} [sqlite3 -version] + +# Test that destructors passed to sqlite3 by calls to sqlite3_result_text() +# etc. are called. These tests use two special user-defined functions +# (implemented in func.c) only available in test builds. +# +# Function test_destructor() takes one argument and returns a copy of the +# text form of that argument. A destructor is associated with the return +# value. Function test_destructor_count() returns the number of outstanding +# destructor calls for values returned by test_destructor(). +# +if {[db eval {PRAGMA encoding}]=="UTF-8"} { + do_test func-12.1-utf8 { + execsql { + SELECT test_destructor('hello world'), test_destructor_count(); + } + } {{hello world} 1} +} else { + ifcapable {utf16} { + do_test func-12.1-utf16 { + execsql { + SELECT test_destructor16('hello world'), test_destructor_count(); + } + } {{hello world} 1} + } +} +do_test func-12.2 { + execsql { + SELECT test_destructor_count(); + } +} {0} +do_test func-12.3 { + execsql { + SELECT test_destructor('hello')||' world' + } +} {{hello world}} +do_test func-12.4 { + execsql { + SELECT test_destructor_count(); + } +} {0} +do_test func-12.5 { + execsql { + CREATE TABLE t4(x); + INSERT INTO t4 VALUES(test_destructor('hello')); + INSERT INTO t4 VALUES(test_destructor('world')); + SELECT min(test_destructor(x)), max(test_destructor(x)) FROM t4; + } +} {hello world} +do_test func-12.6 { + execsql { + SELECT test_destructor_count(); + } +} {0} +do_test func-12.7 { + execsql { + DROP TABLE t4; + } +} {} + + +# Test that the auxdata API for scalar functions works. This test uses +# a special user-defined function only available in test builds, +# test_auxdata(). Function test_auxdata() takes any number of arguments. +do_test func-13.1 { + execsql { + SELECT test_auxdata('hello world'); + } +} {0} + +do_test func-13.2 { + execsql { + CREATE TABLE t4(a, b); + INSERT INTO t4 VALUES('abc', 'def'); + INSERT INTO t4 VALUES('ghi', 'jkl'); + } +} {} +do_test func-13.3 { + execsql { + SELECT test_auxdata('hello world') FROM t4; + } +} {0 1} +do_test func-13.4 { + execsql { + SELECT test_auxdata('hello world', 123) FROM t4; + } +} {{0 0} {1 1}} +do_test func-13.5 { + execsql { + SELECT test_auxdata('hello world', a) FROM t4; + } +} {{0 0} {1 0}} +do_test func-13.6 { + execsql { + SELECT test_auxdata('hello'||'world', a) FROM t4; + } +} {{0 0} {1 0}} + +# Test that auxilary data is preserved between calls for SQL variables. +do_test func-13.7 { + set DB [sqlite3_connection_pointer db] + set sql "SELECT test_auxdata( ? , a ) FROM t4;" + set STMT [sqlite3_prepare $DB $sql -1 TAIL] + sqlite3_bind_text $STMT 1 hello\000 -1 + set res [list] + while { "SQLITE_ROW"==[sqlite3_step $STMT] } { + lappend res [sqlite3_column_text $STMT 0] + } + lappend res [sqlite3_finalize $STMT] +} {{0 0} {1 0} SQLITE_OK} + +# Test that auxiliary data is discarded when a statement is reset. +do_execsql_test 13.8.1 { + SELECT test_auxdata('constant') FROM t4; +} {0 1} +do_execsql_test 13.8.2 { + SELECT test_auxdata('constant') FROM t4; +} {0 1} +db cache flush +do_execsql_test 13.8.3 { + SELECT test_auxdata('constant') FROM t4; +} {0 1} +set V "one" +do_execsql_test 13.8.4 { + SELECT test_auxdata($V), $V FROM t4; +} {0 one 1 one} +set V "two" +do_execsql_test 13.8.5 { + SELECT test_auxdata($V), $V FROM t4; +} {0 two 1 two} +db cache flush +set V "three" +do_execsql_test 13.8.6 { + SELECT test_auxdata($V), $V FROM t4; +} {0 three 1 three} + + +# Make sure that a function with a very long name is rejected +do_test func-14.1 { + catch { + db function [string repeat X 254] {return "hello"} + } +} {0} +do_test func-14.2 { + catch { + db function [string repeat X 256] {return "hello"} + } +} {1} + +do_test func-15.1 { + catchsql {select test_error(NULL)} +} {1 {}} +do_test func-15.2 { + catchsql {select test_error('this is the error message')} +} {1 {this is the error message}} +do_test func-15.3 { + catchsql {select test_error('this is the error message',12)} +} {1 {this is the error message}} +do_test func-15.4 { + db errorcode +} {12} + +# Test the quote function for BLOB and NULL values. +do_test func-16.1 { + execsql { + CREATE TABLE tbl2(a, b); + } + set STMT [sqlite3_prepare $::DB "INSERT INTO tbl2 VALUES(?, ?)" -1 TAIL] + sqlite3_bind_blob $::STMT 1 abc 3 + sqlite3_step $::STMT + sqlite3_finalize $::STMT + execsql { + SELECT quote(a), quote(b) FROM tbl2; + } +} {X'616263' NULL} + +# Correctly handle function error messages that include %. Ticket #1354 +# +do_test func-17.1 { + proc testfunc1 args {error "Error %d with %s percents %p"} + db function testfunc1 ::testfunc1 + catchsql { + SELECT testfunc1(1,2,3); + } +} {1 {Error %d with %s percents %p}} + +# The SUM function should return integer results when all inputs are integer. +# +do_test func-18.1 { + execsql { + CREATE TABLE t5(x); + INSERT INTO t5 VALUES(1); + INSERT INTO t5 VALUES(-99); + INSERT INTO t5 VALUES(10000); + SELECT sum(x) FROM t5; + } +} {9902} +ifcapable floatingpoint { + do_test func-18.2 { + execsql { + INSERT INTO t5 VALUES(0.0); + SELECT sum(x) FROM t5; + } + } {9902.0} +} + +# The sum of nothing is NULL. But the sum of all NULLs is NULL. +# +# The TOTAL of nothing is 0.0. +# +do_test func-18.3 { + execsql { + DELETE FROM t5; + SELECT sum(x), total(x) FROM t5; + } +} {{} 0.0} +do_test func-18.4 { + execsql { + INSERT INTO t5 VALUES(NULL); + SELECT sum(x), total(x) FROM t5 + } +} {{} 0.0} +do_test func-18.5 { + execsql { + INSERT INTO t5 VALUES(NULL); + SELECT sum(x), total(x) FROM t5 + } +} {{} 0.0} +do_test func-18.6 { + execsql { + INSERT INTO t5 VALUES(123); + SELECT sum(x), total(x) FROM t5 + } +} {123 123.0} + +# Ticket #1664, #1669, #1670, #1674: An integer overflow on SUM causes +# an error. The non-standard TOTAL() function continues to give a helpful +# result. +# +do_test func-18.10 { + execsql { + CREATE TABLE t6(x INTEGER); + INSERT INTO t6 VALUES(1); + INSERT INTO t6 VALUES(1<<62); + SELECT sum(x) - ((1<<62)+1) from t6; + } +} 0 +do_test func-18.11 { + execsql { + SELECT typeof(sum(x)) FROM t6 + } +} integer +ifcapable floatingpoint { + do_catchsql_test func-18.12 { + INSERT INTO t6 VALUES(1<<62); + SELECT sum(x) - ((1<<62)*2.0+1) from t6; + } {1 {integer overflow}} + do_catchsql_test func-18.13 { + SELECT total(x) - ((1<<62)*2.0+1) FROM t6 + } {0 0.0} +} +if {[working_64bit_int]} { + do_test func-18.14 { + execsql { + SELECT sum(-9223372036854775805); + } + } -9223372036854775805 +} +ifcapable compound&&subquery { + +do_test func-18.15 { + catchsql { + SELECT sum(x) FROM + (SELECT 9223372036854775807 AS x UNION ALL + SELECT 10 AS x); + } +} {1 {integer overflow}} +if {[working_64bit_int]} { + do_test func-18.16 { + catchsql { + SELECT sum(x) FROM + (SELECT 9223372036854775807 AS x UNION ALL + SELECT -10 AS x); + } + } {0 9223372036854775797} + do_test func-18.17 { + catchsql { + SELECT sum(x) FROM + (SELECT -9223372036854775807 AS x UNION ALL + SELECT 10 AS x); + } + } {0 -9223372036854775797} +} +do_test func-18.18 { + catchsql { + SELECT sum(x) FROM + (SELECT -9223372036854775807 AS x UNION ALL + SELECT -10 AS x); + } +} {1 {integer overflow}} +do_test func-18.19 { + catchsql { + SELECT sum(x) FROM (SELECT 9 AS x UNION ALL SELECT -10 AS x); + } +} {0 -1} +do_test func-18.20 { + catchsql { + SELECT sum(x) FROM (SELECT -9 AS x UNION ALL SELECT 10 AS x); + } +} {0 1} +do_test func-18.21 { + catchsql { + SELECT sum(x) FROM (SELECT -10 AS x UNION ALL SELECT 9 AS x); + } +} {0 -1} +do_test func-18.22 { + catchsql { + SELECT sum(x) FROM (SELECT 10 AS x UNION ALL SELECT -9 AS x); + } +} {0 1} + +} ;# ifcapable compound&&subquery + +# Integer overflow on abs() +# +if {[working_64bit_int]} { + do_test func-18.31 { + catchsql { + SELECT abs(-9223372036854775807); + } + } {0 9223372036854775807} +} +do_test func-18.32 { + catchsql { + SELECT abs(-9223372036854775807-1); + } +} {1 {integer overflow}} + +# The MATCH function exists but is only a stub and always throws an error. +# +do_test func-19.1 { + execsql { + SELECT match(a,b) FROM t1 WHERE 0; + } +} {} +do_test func-19.2 { + catchsql { + SELECT 'abc' MATCH 'xyz'; + } +} {1 {unable to use function MATCH in the requested context}} +do_test func-19.3 { + catchsql { + SELECT 'abc' NOT MATCH 'xyz'; + } +} {1 {unable to use function MATCH in the requested context}} +do_test func-19.4 { + catchsql { + SELECT match(1,2,3); + } +} {1 {wrong number of arguments to function match()}} + +# Soundex tests. +# +if {![catch {db eval {SELECT soundex('hello')}}]} { + set i 0 + foreach {name sdx} { + euler E460 + EULER E460 + Euler E460 + ellery E460 + gauss G200 + ghosh G200 + hilbert H416 + Heilbronn H416 + knuth K530 + kant K530 + Lloyd L300 + LADD L300 + Lukasiewicz L222 + Lissajous L222 + A A000 + 12345 ?000 + } { + incr i + do_test func-20.$i { + execsql {SELECT soundex($name)} + } $sdx + } +} + +# Tests of the REPLACE function. +# +do_test func-21.1 { + catchsql { + SELECT replace(1,2); + } +} {1 {wrong number of arguments to function replace()}} +do_test func-21.2 { + catchsql { + SELECT replace(1,2,3,4); + } +} {1 {wrong number of arguments to function replace()}} +do_test func-21.3 { + execsql { + SELECT typeof(replace('This is the main test string', NULL, 'ALT')); + } +} {null} +do_test func-21.4 { + execsql { + SELECT typeof(replace(NULL, 'main', 'ALT')); + } +} {null} +do_test func-21.5 { + execsql { + SELECT typeof(replace('This is the main test string', 'main', NULL)); + } +} {null} +do_test func-21.6 { + execsql { + SELECT replace('This is the main test string', 'main', 'ALT'); + } +} {{This is the ALT test string}} +do_test func-21.7 { + execsql { + SELECT replace('This is the main test string', 'main', 'larger-main'); + } +} {{This is the larger-main test string}} +do_test func-21.8 { + execsql { + SELECT replace('aaaaaaa', 'a', '0123456789'); + } +} {0123456789012345678901234567890123456789012345678901234567890123456789} + +ifcapable tclvar { + do_test func-21.9 { + # Attempt to exploit a buffer-overflow that at one time existed + # in the REPLACE function. + set ::str "[string repeat A 29998]CC[string repeat A 35537]" + set ::rep [string repeat B 65536] + execsql { + SELECT LENGTH(REPLACE($::str, 'C', $::rep)); + } + } [expr 29998 + 2*65536 + 35537] +} + +# Tests for the TRIM, LTRIM and RTRIM functions. +# +do_test func-22.1 { + catchsql {SELECT trim(1,2,3)} +} {1 {wrong number of arguments to function trim()}} +do_test func-22.2 { + catchsql {SELECT ltrim(1,2,3)} +} {1 {wrong number of arguments to function ltrim()}} +do_test func-22.3 { + catchsql {SELECT rtrim(1,2,3)} +} {1 {wrong number of arguments to function rtrim()}} +do_test func-22.4 { + execsql {SELECT trim(' hi ');} +} {hi} +do_test func-22.5 { + execsql {SELECT ltrim(' hi ');} +} {{hi }} +do_test func-22.6 { + execsql {SELECT rtrim(' hi ');} +} {{ hi}} +do_test func-22.7 { + execsql {SELECT trim(' hi ','xyz');} +} {{ hi }} +do_test func-22.8 { + execsql {SELECT ltrim(' hi ','xyz');} +} {{ hi }} +do_test func-22.9 { + execsql {SELECT rtrim(' hi ','xyz');} +} {{ hi }} +do_test func-22.10 { + execsql {SELECT trim('xyxzy hi zzzy','xyz');} +} {{ hi }} +do_test func-22.11 { + execsql {SELECT ltrim('xyxzy hi zzzy','xyz');} +} {{ hi zzzy}} +do_test func-22.12 { + execsql {SELECT rtrim('xyxzy hi zzzy','xyz');} +} {{xyxzy hi }} +do_test func-22.13 { + execsql {SELECT trim(' hi ','');} +} {{ hi }} +if {[db one {PRAGMA encoding}]=="UTF-8"} { + do_test func-22.14 { + execsql {SELECT hex(trim(x'c280e1bfbff48fbfbf6869',x'6162e1bfbfc280'))} + } {F48FBFBF6869} + do_test func-22.15 { + execsql {SELECT hex(trim(x'6869c280e1bfbff48fbfbf61', + x'6162e1bfbfc280f48fbfbf'))} + } {6869} + do_test func-22.16 { + execsql {SELECT hex(trim(x'ceb1ceb2ceb3',x'ceb1'));} + } {CEB2CEB3} +} +do_test func-22.20 { + execsql {SELECT typeof(trim(NULL));} +} {null} +do_test func-22.21 { + execsql {SELECT typeof(trim(NULL,'xyz'));} +} {null} +do_test func-22.22 { + execsql {SELECT typeof(trim('hello',NULL));} +} {null} + +# 2021-06-15 - infinite loop due to unsigned character counter +# overflow, reported by Zimuzo Ezeozue +# +do_execsql_test func-22.23 { + SELECT trim('xyzzy',x'c0808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080'); +} {xyzzy} + +# This is to test the deprecated sqlite3_aggregate_count() API. +# +ifcapable deprecated { + do_test func-23.1 { + sqlite3_create_aggregate db + execsql { + SELECT legacy_count() FROM t6; + } + } {3} +} + +# The group_concat() and string_agg() functions. +# +do_test func-24.1 { + execsql { + SELECT group_concat(t1), string_agg(t1,',') FROM tbl1 + } +} {this,program,is,free,software this,program,is,free,software} +do_test func-24.2 { + execsql { + SELECT group_concat(t1,' '), string_agg(t1,' ') FROM tbl1 + } +} {{this program is free software} {this program is free software}} +do_test func-24.3 { + execsql { + SELECT group_concat(t1,' ' || rowid || ' ') FROM tbl1 + } +} {{this 2 program 3 is 4 free 5 software}} +do_test func-24.4 { + execsql { + SELECT group_concat(NULL,t1) FROM tbl1 + } +} {{}} +do_test func-24.5 { + execsql { + SELECT group_concat(t1,NULL), string_agg(t1,NULL) FROM tbl1 + } +} {thisprogramisfreesoftware thisprogramisfreesoftware} +do_test func-24.6 { + execsql { + SELECT 'BEGIN-'||group_concat(t1) FROM tbl1 + } +} {BEGIN-this,program,is,free,software} + +# Ticket #3179: Make sure aggregate functions can take many arguments. +# None of the built-in aggregates do this, so use the md5sum() from the +# test extensions. +# +unset -nocomplain midargs +set midargs {} +unset -nocomplain midres +set midres {} +unset -nocomplain result +for {set i 1} {$i<[sqlite3_limit db SQLITE_LIMIT_FUNCTION_ARG -1]} {incr i} { + append midargs ,'/$i' + append midres /$i + set result [md5 \ + "this${midres}program${midres}is${midres}free${midres}software${midres}"] + set sql "SELECT md5sum(t1$midargs) FROM tbl1" + do_test func-24.7.$i { + db eval $::sql + } $result +} + +# Ticket #3806. If the initial string in a group_concat is an empty +# string, the separator that follows should still be present. +# +do_test func-24.8 { + execsql { + SELECT group_concat(CASE t1 WHEN 'this' THEN '' ELSE t1 END) FROM tbl1 + } +} {,program,is,free,software} +do_test func-24.9 { + execsql { + SELECT group_concat(CASE WHEN t1!='software' THEN '' ELSE t1 END) FROM tbl1 + } +} {,,,,software} + +# Ticket #3923. Initial empty strings have a separator. But initial +# NULLs do not. +# +do_test func-24.10 { + execsql { + SELECT group_concat(CASE t1 WHEN 'this' THEN null ELSE t1 END) FROM tbl1 + } +} {program,is,free,software} +do_test func-24.11 { + execsql { + SELECT group_concat(CASE WHEN t1!='software' THEN null ELSE t1 END) FROM tbl1 + } +} {software} +do_test func-24.12 { + execsql { + SELECT group_concat(CASE t1 WHEN 'this' THEN '' + WHEN 'program' THEN null ELSE t1 END) FROM tbl1 + } +} {,is,free,software} +# Tests to verify ticket http://www.sqlite.org/src/tktview/55746f9e65f8587c0 +do_test func-24.13 { + execsql { + SELECT typeof(group_concat(x)) FROM (SELECT '' AS x); + } +} {text} +do_test func-24.14 { + execsql { + SELECT typeof(group_concat(x,'')) + FROM (SELECT '' AS x UNION ALL SELECT ''); + } +} {text} + + +# Use the test_isolation function to make sure that type conversions +# on function arguments do not effect subsequent arguments. +# +do_test func-25.1 { + execsql {SELECT test_isolation(t1,t1) FROM tbl1} +} {this program is free software} + +# Try to misuse the sqlite3_create_function() interface. Verify that +# errors are returned. +# +do_test func-26.1 { + abuse_create_function db +} {} + +# The previous test (func-26.1) registered a function with a very long +# function name that takes many arguments and always returns NULL. Verify +# that this function works correctly. +# +do_test func-26.2 { + set a {} + for {set i 1} {$i<=$::SQLITE_MAX_FUNCTION_ARG} {incr i} { + lappend a $i + } + db eval " + SELECT nullx_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789([join $a ,]); + " +} {{}} +do_test func-26.3 { + set a {} + for {set i 1} {$i<=$::SQLITE_MAX_FUNCTION_ARG+1} {incr i} { + lappend a $i + } + catchsql " + SELECT nullx_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789([join $a ,]); + " +} {1 {too many arguments on function nullx_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789}} +do_test func-26.4 { + set a {} + for {set i 1} {$i<=$::SQLITE_MAX_FUNCTION_ARG-1} {incr i} { + lappend a $i + } + catchsql " + SELECT nullx_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789([join $a ,]); + " +} {1 {wrong number of arguments to function nullx_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789()}} +do_test func-26.5 { + catchsql " + SELECT nullx_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_12345678a(0); + " +} {1 {no such function: nullx_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_12345678a}} +do_test func-26.6 { + catchsql " + SELECT nullx_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789a(0); + " +} {1 {no such function: nullx_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789a}} + +do_test func-27.1 { + catchsql {SELECT coalesce()} +} {1 {wrong number of arguments to function coalesce()}} +do_test func-27.2 { + catchsql {SELECT coalesce(1)} +} {1 {wrong number of arguments to function coalesce()}} +do_test func-27.3 { + catchsql {SELECT coalesce(1,2)} +} {0 1} + +# Ticket 2d401a94287b5 +# Unknown function in a DEFAULT expression causes a segfault. +# +do_test func-28.1 { + db eval { + CREATE TABLE t28(x, y DEFAULT(nosuchfunc(1))); + } + catchsql { + INSERT INTO t28(x) VALUES(1); + } +} {1 {unknown function: nosuchfunc()}} + +# Verify that the length() and typeof() functions do not actually load +# the content of their argument. +# +do_test func-29.1 { + db eval { + CREATE TABLE t29(id INTEGER PRIMARY KEY, x, y); + INSERT INTO t29 VALUES(1, 2, 3), (2, NULL, 4), (3, 4.5, 5); + INSERT INTO t29 VALUES(4, randomblob(1000000), 6); + INSERT INTO t29 VALUES(5, 'hello', 7); + } + db close + sqlite3 db test.db + sqlite3_db_status db CACHE_MISS 1 + db eval {SELECT typeof(x), length(x), typeof(y) FROM t29 ORDER BY id} +} {integer 1 integer null {} integer real 3 integer blob 1000000 integer text 5 integer} +do_test func-29.2 { + set x [lindex [sqlite3_db_status db CACHE_MISS 1] 1] + if {$x<5} {set x 1} + set x +} {1} +do_test func-29.3 { + db close + sqlite3 db test.db + sqlite3_db_status db CACHE_MISS 1 + db eval {SELECT typeof(+x) FROM t29 ORDER BY id} +} {integer null real blob text} +if {[permutation] != "mmap"} { + ifcapable !direct_read { + do_test func-29.4 { + set x [lindex [sqlite3_db_status db CACHE_MISS 1] 1] + if {$x>100} {set x many} + set x + } {many} + } +} +do_test func-29.5 { + db close + sqlite3 db test.db + sqlite3_db_status db CACHE_MISS 1 + db eval {SELECT sum(length(x)) FROM t29} +} {1000009} +do_test func-29.6 { + set x [lindex [sqlite3_db_status db CACHE_MISS 1] 1] + if {$x<5} {set x 1} + set x +} {1} + +# The OP_Column opcode has an optimization that avoids loading content +# for fields with content-length=0 when the content offset is on an overflow +# page. Make sure the optimization works. +# +do_execsql_test func-29.10 { + CREATE TABLE t29b(a,b,c,d,e,f,g,h,i); + INSERT INTO t29b + VALUES(1, hex(randomblob(2000)), null, 0, 1, '', zeroblob(0),'x',x'01'); + SELECT typeof(c), typeof(d), typeof(e), typeof(f), + typeof(g), typeof(h), typeof(i) FROM t29b; +} {null integer integer text blob text blob} +do_execsql_test func-29.11 { + SELECT length(f), length(g), length(h), length(i) FROM t29b; +} {0 0 1 1} +do_execsql_test func-29.12 { + SELECT quote(f), quote(g), quote(h), quote(i) FROM t29b; +} {'' X'' 'x' X'01'} + +# EVIDENCE-OF: R-29701-50711 The unicode(X) function returns the numeric +# unicode code point corresponding to the first character of the string +# X. +# +# EVIDENCE-OF: R-55469-62130 The char(X1,X2,...,XN) function returns a +# string composed of characters having the unicode code point values of +# integers X1 through XN, respectively. +# +do_execsql_test func-30.1 {SELECT unicode('$');} 36 +do_execsql_test func-30.2 [subst {SELECT unicode('\u00A2');}] 162 +do_execsql_test func-30.3 [subst {SELECT unicode('\u20AC');}] 8364 +do_execsql_test func-30.4 {SELECT char(36,162,8364);} [subst {$\u00A2\u20AC}] + +for {set i 1} {$i<0xd800} {incr i 13} { + do_execsql_test func-30.5.$i {SELECT unicode(char($i))} $i +} +for {set i 57344} {$i<=0xfffd} {incr i 17} { + if {$i==0xfeff} continue + do_execsql_test func-30.5.$i {SELECT unicode(char($i))} $i +} +for {set i 65536} {$i<=0x10ffff} {incr i 139} { + do_execsql_test func-30.5.$i {SELECT unicode(char($i))} $i +} + +# Test char(). +# +do_execsql_test func-31.1 { + SELECT char(), length(char()), typeof(char()) +} {{} 0 text} + +# sqlite3_value_frombind() +# +do_execsql_test func-32.100 { + SELECT test_frombind(1,2,3,4); +} {0} +do_execsql_test func-32.110 { + SELECT test_frombind(1,2,?,4); +} {4} +do_execsql_test func-32.120 { + SELECT test_frombind(1,(?),4,?+7); +} {2} +do_execsql_test func-32.130 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(a,b,c,e,f); + INSERT INTO t1 VALUES(1,2.5,'xyz',x'e0c1b2a3',null); + SELECT test_frombind(a,b,c,e,f,$xyz) FROM t1; +} {32} +do_execsql_test func-32.140 { + SELECT test_frombind(a,b,c,e,f,$xyz+f) FROM t1; +} {0} +do_execsql_test func-32.150 { + SELECT test_frombind(x.a,y.b,x.c,:123,y.e,x.f,$xyz+y.f) FROM t1 x, t1 y; +} {8} + +# 2019-08-15 +# Direct-only functions. +# +proc testdirectonly {x} {return [expr {$x*2}]} +do_test func-33.1 { + db func testdirectonly -directonly testdirectonly + db eval {SELECT testdirectonly(15)} +} {30} +do_catchsql_test func-33.2 { + CREATE VIEW v33(y) AS SELECT testdirectonly(15); + SELECT * FROM v33; +} {1 {unsafe use of testdirectonly()}} +do_execsql_test func-33.3 { + SELECT * FROM (SELECT testdirectonly(15)) AS v33; +} {30} +do_execsql_test func-33.4 { + WITH c(x) AS (SELECT testdirectonly(15)) + SELECT * FROM c; +} {30} +do_catchsql_test func-33.5 { + WITH c(x) AS (SELECT * FROM v33) + SELECT * FROM c; +} {1 {unsafe use of testdirectonly()}} +do_execsql_test func-33.10 { + CREATE TABLE t33a(a,b); + CREATE TABLE t33b(x,y); + CREATE TRIGGER r1 AFTER INSERT ON t33a BEGIN + INSERT INTO t33b(x,y) VALUES(testdirectonly(new.a),new.b); + END; +} {} +do_catchsql_test func-33.11 { + INSERT INTO t33a VALUES(1,2); +} {1 {unsafe use of testdirectonly()}} + +ifcapable altertable { +do_execsql_test func-33.20 { + ALTER TABLE t33a RENAME COLUMN a TO aaa; + SELECT sql FROM sqlite_master WHERE name='r1'; +} {{CREATE TRIGGER r1 AFTER INSERT ON t33a BEGIN + INSERT INTO t33b(x,y) VALUES(testdirectonly(new.aaa),new.b); + END}} +} + +# 2020-01-09 Yongheng fuzzer find +# The bug is in the register-validity debug logic, not in the SQLite core +# and as such it only impacts debug builds. Release builds work fine. +# +reset_db +do_execsql_test func-34.10 { + CREATE TABLE t1(a INT CHECK( + datetime( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10,11,12,13,14,15,16,17,18,19, + 20,21,22,23,24,25,26,27,28,29, + 30,31,32,33,34,35,36,37,38,39, + 40,41,42,43,44,45,46,47,48,a) + ) + ); + INSERT INTO t1(a) VALUES(1),(2); + SELECT * FROM t1; +} {1 2} + +# 2020-03-11 COALESCE() should short-circuit +# See also ticket 3c9eadd2a6ba0aa5 +# Both issues stem from the fact that functions that could +# throw exceptions were being factored out into initialization +# code. The fix was to put those function calls inside of +# OP_Once instead. +# +reset_db +do_execsql_test func-35.100 { + CREATE TABLE t1(x); + SELECT coalesce(x, abs(-9223372036854775808)) FROM t1; +} {} +do_execsql_test func-35.110 { + SELECT coalesce(x, 'xyz' LIKE printf('%.1000000c','y')) FROM t1; +} {} +do_execsql_test func-35.200 { + CREATE TABLE t0(c0 CHECK(ABS(-9223372036854775808))); + PRAGMA integrity_check; +} {ok} + +# 2021-01-07: The -> and ->> operators. +# +proc ptr1 {a b} { return "$a->$b" } +db func -> ptr1 +proc ptr2 {a b} { return "$a->>$b" } +db func ->> ptr2 +do_execsql_test func-36.100 { + SELECT 123 -> 456 +} {123->456} +do_execsql_test func-36.110 { + SELECT 123 ->> 456 +} {123->>456} + +# 2023-06-26 +# Enhanced precision of SUM(). +# +reset_db +do_catchsql_test func-37.100 { + WITH c(x) AS (VALUES(9223372036854775807),(9223372036854775807), + (123),(-9223372036854775807),(-9223372036854775807)) + SELECT sum(x) FROM c; +} {1 {integer overflow}} +do_catchsql_test func-37.110 { + WITH c(x) AS (VALUES(9223372036854775807),(1)) + SELECT sum(x) FROM c; +} {1 {integer overflow}} +do_catchsql_test func-37.120 { + WITH c(x) AS (VALUES(9223372036854775807),(10000),(-10010)) + SELECT sum(x) FROM c; +} {1 {integer overflow}} + +# 2023-08-28 forum post https://sqlite.org/forum/forumpost/1c06ddcacc86032a +# Incorrect handling of infinity by SUM(). +# +do_execsql_test func-38.100 { + WITH t1(x) AS (VALUES(9e+999)) SELECT sum(x), avg(x), total(x) FROM t1; + WITH t1(x) AS (VALUES(-9e+999)) SELECT sum(x), avg(x), total(x) FROM t1; +} {Inf Inf Inf -Inf -Inf -Inf} + +finish_test diff --git a/test/func2.test b/test/func2.test new file mode 100644 index 0000000..08ad857 --- /dev/null +++ b/test/func2.test @@ -0,0 +1,511 @@ +# 2009 November 11 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing built-in functions. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Test plan: +# +# func2-1.*: substr implementation (ascii) +# func2-2.*: substr implementation (utf8) +# func2-3.*: substr implementation (blob) +# + +proc bin_to_hex {blob} { + set bytes {} + binary scan $blob \c* bytes + set bytes2 [list] + foreach b $bytes {lappend bytes2 [format %02X [expr $b & 0xFF]]} + join $bytes2 {} +} + +#---------------------------------------------------------------------------- +# Test cases func2-1.*: substr implementation (ascii) +# + +do_test func2-1.1 { + execsql {SELECT 'Supercalifragilisticexpialidocious'} +} {Supercalifragilisticexpialidocious} + +# substr(x,y), substr(x,y,z) +do_test func2-1.2.1 { + catchsql {SELECT SUBSTR()} +} {1 {wrong number of arguments to function SUBSTR()}} +do_test func2-1.2.2 { + catchsql {SELECT SUBSTR('Supercalifragilisticexpialidocious')} +} {1 {wrong number of arguments to function SUBSTR()}} +do_test func2-1.2.3 { + catchsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 1,1,1)} +} {1 {wrong number of arguments to function SUBSTR()}} + +# p1 is 1-indexed +do_test func2-1.3 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 0)} +} {Supercalifragilisticexpialidocious} +do_test func2-1.4 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 1)} +} {Supercalifragilisticexpialidocious} +do_test func2-1.5 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 2)} +} {upercalifragilisticexpialidocious} +do_test func2-1.6 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 30)} +} {cious} +do_test func2-1.7 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 34)} +} {s} +do_test func2-1.8 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 35)} +} {{}} +do_test func2-1.9 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 36)} +} {{}} + +# if p1<0, start from right +do_test func2-1.10 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -0)} +} {Supercalifragilisticexpialidocious} +do_test func2-1.11 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -1)} +} {s} +do_test func2-1.12 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -2)} +} {us} +do_test func2-1.13 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -30)} +} {rcalifragilisticexpialidocious} +do_test func2-1.14 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -34)} +} {Supercalifragilisticexpialidocious} +do_test func2-1.15 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -35)} +} {Supercalifragilisticexpialidocious} +do_test func2-1.16 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -36)} +} {Supercalifragilisticexpialidocious} + +# p1 is 1-indexed, p2 length to return +do_test func2-1.17.1 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 0, 1)} +} {{}} +do_test func2-1.17.2 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 0, 2)} +} {S} +do_test func2-1.18 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 1, 1)} +} {S} +do_test func2-1.19.0 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 2, 0)} +} {{}} +do_test func2-1.19.1 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 2, 1)} +} {u} +do_test func2-1.19.2 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 2, 2)} +} {up} +do_test func2-1.20 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 30, 1)} +} {c} +do_test func2-1.21 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 34, 1)} +} {s} +do_test func2-1.22 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 35, 1)} +} {{}} +do_test func2-1.23 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 36, 1)} +} {{}} + +# if p1<0, start from right, p2 length to return +do_test func2-1.24 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -0, 1)} +} {{}} +do_test func2-1.25.0 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -1, 0)} +} {{}} +do_test func2-1.25.1 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -1, 1)} +} {s} +do_test func2-1.25.2 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -1, 2)} +} {s} +do_test func2-1.26 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -2, 1)} +} {u} +do_test func2-1.27 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -30, 1)} +} {r} +do_test func2-1.28.0 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -34, 0)} +} {{}} +do_test func2-1.28.1 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -34, 1)} +} {S} +do_test func2-1.28.2 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -34, 2)} +} {Su} +do_test func2-1.29.1 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -35, 1)} +} {{}} +do_test func2-1.29.2 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -35, 2)} +} {S} +do_test func2-1.30.0 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -36, 0)} +} {{}} +do_test func2-1.30.1 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -36, 1)} +} {{}} +do_test func2-1.30.2 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -36, 2)} +} {{}} +do_test func2-1.30.3 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -36, 3)} +} {S} + +# p1 is 1-indexed, p2 length to return, p2<0 return p2 chars before p1 +do_test func2-1.31.0 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 0, 0)} +} {{}} +do_test func2-1.31.1 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 0, -1)} +} {{}} +do_test func2-1.31.2 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 0, -2)} +} {{}} +do_test func2-1.32.0 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 1, 0)} +} {{}} +do_test func2-1.32.1 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 1, -1)} +} {{}} +do_test func2-1.33.0 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 2, 0)} +} {{}} +do_test func2-1.33.1 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 2, -1)} +} {S} +do_test func2-1.33.2 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 2, -2)} +} {S} +do_test func2-1.34.0 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 3, 0)} +} {{}} +do_test func2-1.34.1 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 3, -1)} +} {u} +do_test func2-1.34.2 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 3, -2)} +} {Su} +do_test func2-1.35.1 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 30, -1)} +} {o} +do_test func2-1.35.2 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 30, -2)} +} {do} +do_test func2-1.36 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 34, -1)} +} {u} +do_test func2-1.37 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 35, -1)} +} {s} +do_test func2-1.38.0 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 36, 0)} +} {{}} +do_test func2-1.38.1 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 36, -1)} +} {{}} +do_test func2-1.38.2 { + execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 36, -2)} +} {s} + + +#---------------------------------------------------------------------------- +# Test cases func2-2.*: substr implementation (utf8) +# + +# Only do the following tests if TCL has UTF-8 capabilities +# +if {"\u1234"!="u1234"} { + +do_test func2-2.1.1 { + execsql "SELECT 'hi\u1234ho'" +} "hi\u1234ho" + +# substr(x,y), substr(x,y,z) +do_test func2-2.1.2 { + catchsql "SELECT SUBSTR()" +} {1 {wrong number of arguments to function SUBSTR()}} +do_test func2-2.1.3 { + catchsql "SELECT SUBSTR('hi\u1234ho')" +} {1 {wrong number of arguments to function SUBSTR()}} +do_test func2-2.1.4 { + catchsql "SELECT SUBSTR('hi\u1234ho', 1,1,1)" +} {1 {wrong number of arguments to function SUBSTR()}} + +do_test func2-2.2.0 { + execsql "SELECT SUBSTR('hi\u1234ho', 0, 0)" +} {{}} +do_test func2-2.2.1 { + execsql "SELECT SUBSTR('hi\u1234ho', 0, 1)" +} {{}} +do_test func2-2.2.2 { + execsql "SELECT SUBSTR('hi\u1234ho', 0, 2)" +} "h" +do_test func2-2.2.3 { + execsql "SELECT SUBSTR('hi\u1234ho', 0, 3)" +} "hi" +do_test func2-2.2.4 { + execsql "SELECT SUBSTR('hi\u1234ho', 0, 4)" +} "hi\u1234" +do_test func2-2.2.5 { + execsql "SELECT SUBSTR('hi\u1234ho', 0, 5)" +} "hi\u1234h" +do_test func2-2.2.6 { + execsql "SELECT SUBSTR('hi\u1234ho', 0, 6)" +} "hi\u1234ho" + +do_test func2-2.3.0 { + execsql "SELECT SUBSTR('hi\u1234ho', 1, 0)" +} {{}} +do_test func2-2.3.1 { + execsql "SELECT SUBSTR('hi\u1234ho', 1, 1)" +} "h" +do_test func2-2.3.2 { + execsql "SELECT SUBSTR('hi\u1234ho', 1, 2)" +} "hi" +do_test func2-2.3.3 { + execsql "SELECT SUBSTR('hi\u1234ho', 1, 3)" +} "hi\u1234" +do_test func2-2.3.4 { + execsql "SELECT SUBSTR('hi\u1234ho', 1, 4)" +} "hi\u1234h" +do_test func2-2.3.5 { + execsql "SELECT SUBSTR('hi\u1234ho', 1, 5)" +} "hi\u1234ho" +do_test func2-2.3.6 { + execsql "SELECT SUBSTR('hi\u1234ho', 1, 6)" +} "hi\u1234ho" + +do_test func2-2.4.0 { + execsql "SELECT SUBSTR('hi\u1234ho', 3, 0)" +} {{}} +do_test func2-2.4.1 { + execsql "SELECT SUBSTR('hi\u1234ho', 3, 1)" +} "\u1234" +do_test func2-2.4.2 { + execsql "SELECT SUBSTR('hi\u1234ho', 3, 2)" +} "\u1234h" + +do_test func2-2.5.0 { + execsql "SELECT SUBSTR('\u1234', 0, 0)" +} {{}} +do_test func2-2.5.1 { + execsql "SELECT SUBSTR('\u1234', 0, 1)" +} {{}} +do_test func2-2.5.2 { + execsql "SELECT SUBSTR('\u1234', 0, 2)" +} "\u1234" +do_test func2-2.5.3 { + execsql "SELECT SUBSTR('\u1234', 0, 3)" +} "\u1234" + +do_test func2-2.6.0 { + execsql "SELECT SUBSTR('\u1234', 1, 0)" +} {{}} +do_test func2-2.6.1 { + execsql "SELECT SUBSTR('\u1234', 1, 1)" +} "\u1234" +do_test func2-2.6.2 { + execsql "SELECT SUBSTR('\u1234', 1, 2)" +} "\u1234" +do_test func2-2.6.3 { + execsql "SELECT SUBSTR('\u1234', 1, 3)" +} "\u1234" + +do_test func2-2.7.0 { + execsql "SELECT SUBSTR('\u1234', 2, 0)" +} {{}} +do_test func2-2.7.1 { + execsql "SELECT SUBSTR('\u1234', 2, 1)" +} {{}} +do_test func2-2.7.2 { + execsql "SELECT SUBSTR('\u1234', 2, 2)" +} {{}} + +do_test func2-2.8.0 { + execsql "SELECT SUBSTR('\u1234', -1, 0)" +} {{}} +do_test func2-2.8.1 { + execsql "SELECT SUBSTR('\u1234', -1, 1)" +} "\u1234" +do_test func2-2.8.2 { + execsql "SELECT SUBSTR('\u1234', -1, 2)" +} "\u1234" +do_test func2-2.8.3 { + execsql "SELECT SUBSTR('\u1234', -1, 3)" +} "\u1234" + +} ;# End \u1234!=u1234 + +#---------------------------------------------------------------------------- +# Test cases func2-3.*: substr implementation (blob) +# + +ifcapable {!bloblit} { + finish_test + return +} + +do_test func2-3.1.1 { + set blob [execsql "SELECT x'1234'"] + bin_to_hex [lindex $blob 0] +} "1234" + +# substr(x,y), substr(x,y,z) +do_test func2-3.1.2 { + catchsql {SELECT SUBSTR()} +} {1 {wrong number of arguments to function SUBSTR()}} +do_test func2-3.1.3 { + catchsql {SELECT SUBSTR(x'1234')} +} {1 {wrong number of arguments to function SUBSTR()}} +do_test func2-3.1.4 { + catchsql {SELECT SUBSTR(x'1234', 1,1,1)} +} {1 {wrong number of arguments to function SUBSTR()}} + +do_test func2-3.2.0 { + set blob [execsql "SELECT SUBSTR(x'1234', 0, 0)"] + bin_to_hex [lindex $blob 0] +} {} +do_test func2-3.2.1 { + set blob [execsql "SELECT SUBSTR(x'1234', 0, 1)"] + bin_to_hex [lindex $blob 0] +} {} +do_test func2-3.2.2 { + set blob [execsql "SELECT SUBSTR(x'1234', 0, 2)"] + bin_to_hex [lindex $blob 0] +} "12" +do_test func2-3.2.3 { + set blob [execsql "SELECT SUBSTR(x'1234', 0, 3)"] + bin_to_hex [lindex $blob 0] +} "1234" + +do_test func2-3.3.0 { + set blob [execsql "SELECT SUBSTR(x'1234', 1, 0)"] + bin_to_hex [lindex $blob 0] +} {} +do_test func2-3.3.1 { + set blob [execsql "SELECT SUBSTR(x'1234', 1, 1)"] + bin_to_hex [lindex $blob 0] +} "12" +do_test func2-3.3.2 { + set blob [execsql "SELECT SUBSTR(x'1234', 1, 2)"] + bin_to_hex [lindex $blob 0] +} "1234" +do_test func2-3.3.3 { + set blob [execsql "SELECT SUBSTR(x'1234', 1, 3)"] + bin_to_hex [lindex $blob 0] +} "1234" + +do_test func2-3.4.0 { + set blob [execsql "SELECT SUBSTR(x'1234', -1, 0)"] + bin_to_hex [lindex $blob 0] +} {} +do_test func2-3.4.1 { + set blob [execsql "SELECT SUBSTR(x'1234', -1, 1)"] + bin_to_hex [lindex $blob 0] +} "34" +do_test func2-3.4.2 { + set blob [execsql "SELECT SUBSTR(x'1234', -1, 2)"] + bin_to_hex [lindex $blob 0] +} "34" +do_test func2-3.4.3 { + set blob [execsql "SELECT SUBSTR(x'1234', -1, 3)"] + bin_to_hex [lindex $blob 0] +} "34" + +do_test func2-3.5.0 { + set blob [execsql "SELECT SUBSTR(x'1234', -2, 0)"] + bin_to_hex [lindex $blob 0] +} {} +do_test func2-3.5.1 { + set blob [execsql "SELECT SUBSTR(x'1234', -2, 1)"] + bin_to_hex [lindex $blob 0] +} "12" +do_test func2-3.5.2 { + set blob [execsql "SELECT SUBSTR(x'1234', -2, 2)"] + bin_to_hex [lindex $blob 0] +} "1234" +do_test func2-3.5.3 { + set blob [execsql "SELECT SUBSTR(x'1234', -2, 3)"] + bin_to_hex [lindex $blob 0] +} "1234" + +do_test func2-3.6.0 { + set blob [execsql "SELECT SUBSTR(x'1234', -1, 0)"] + bin_to_hex [lindex $blob 0] +} {} +do_test func2-3.6.1 { + set blob [execsql "SELECT SUBSTR(x'1234', -1, -1)"] + bin_to_hex [lindex $blob 0] +} "12" +do_test func2-3.6.2 { + set blob [execsql "SELECT SUBSTR(x'1234', -1, -2)"] + bin_to_hex [lindex $blob 0] +} "12" +do_test func2-3.6.3 { + set blob [execsql "SELECT SUBSTR(x'1234', -1, -3)"] + bin_to_hex [lindex $blob 0] +} "12" + +do_test func2-3.7.0 { + set blob [execsql "SELECT SUBSTR(x'1234', -2, 0)"] + bin_to_hex [lindex $blob 0] +} {} +do_test func2-3.7.1 { + set blob [execsql "SELECT SUBSTR(x'1234', -2, -1)"] + bin_to_hex [lindex $blob 0] +} {} +do_test func2-3.7.2 { + set blob [execsql "SELECT SUBSTR(x'1234', -2, -2)"] + bin_to_hex [lindex $blob 0] +} {} + +do_test func2-3.8.0 { + set blob [execsql "SELECT SUBSTR(x'1234', 1, 0)"] + bin_to_hex [lindex $blob 0] +} {} +do_test func2-3.8.1 { + set blob [execsql "SELECT SUBSTR(x'1234', 1, -1)"] + bin_to_hex [lindex $blob 0] +} {} +do_test func2-3.8.2 { + set blob [execsql "SELECT SUBSTR(x'1234', 1, -2)"] + bin_to_hex [lindex $blob 0] +} {} + +do_test func2-3.9.0 { + set blob [execsql "SELECT SUBSTR(x'1234', 2, 0)"] + bin_to_hex [lindex $blob 0] +} {} +do_test func2-3.9.1 { + set blob [execsql "SELECT SUBSTR(x'1234', 2, -1)"] + bin_to_hex [lindex $blob 0] +} "12" +do_test func2-3.9.2 { + set blob [execsql "SELECT SUBSTR(x'1234', 2, -2)"] + bin_to_hex [lindex $blob 0] +} "12" + +finish_test diff --git a/test/func3.test b/test/func3.test new file mode 100644 index 0000000..0221a0d --- /dev/null +++ b/test/func3.test @@ -0,0 +1,211 @@ +# 2010 August 27 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing that destructor functions associated +# with functions created using sqlite3_create_function_v2() is +# correctly invoked. +# +set testdir [file dirname $argv0] +source $testdir/tester.tcl + + +ifcapable utf16 { + do_test func3-1.1 { + set destroyed 0 + proc destroy {} { set ::destroyed 1 } + sqlite3_create_function_v2 db f2 -1 any -func f2 -destroy destroy + set destroyed + } 0 + do_test func3-1.2 { + sqlite3_create_function_v2 db f2 -1 utf8 -func f2 + set destroyed + } 0 + do_test func3-1.3 { + sqlite3_create_function_v2 db f2 -1 utf16le -func f2 + set destroyed + } 0 + do_test func3-1.4 { + sqlite3_create_function_v2 db f2 -1 utf16be -func f2 + set destroyed + } 1 +} + +do_test func3-2.1 { + set destroyed 0 + proc destroy {} { set ::destroyed 1 } + sqlite3_create_function_v2 db f3 -1 utf8 -func f3 -destroy destroy + set destroyed +} 0 +do_test func3-2.2 { + sqlite3_create_function_v2 db f3 -1 utf8 -func f3 + set destroyed +} 1 + +do_test func3-3.1 { + set destroyed 0 + proc destroy {} { set ::destroyed 1 } + sqlite3_create_function_v2 db f3 -1 any -func f3 -destroy destroy + set destroyed +} 0 +do_test func3-3.2 { + db close + set destroyed +} 1 + +sqlite3 db test.db +do_test func3-4.1 { + set destroyed 0 + set rc [catch { + sqlite3_create_function_v2 db f3 -1 any -func f3 -step f3 -destroy destroy + } msg] + list $rc $msg +} {1 SQLITE_MISUSE} +do_test func3-4.2 { set destroyed } 1 + +# EVIDENCE-OF: R-41921-05214 The likelihood(X,Y) function returns +# argument X unchanged. +# +do_execsql_test func3-5.1 { + SELECT likelihood(9223372036854775807, 0.5); +} {9223372036854775807} +do_execsql_test func3-5.2 { + SELECT likelihood(-9223372036854775808, 0.5); +} {-9223372036854775808} +do_execsql_test func3-5.3 { + SELECT likelihood(14.125, 0.5); +} {14.125} +do_execsql_test func3-5.4 { + SELECT likelihood(NULL, 0.5); +} {{}} +do_execsql_test func3-5.5 { + SELECT likelihood('test-string', 0.5); +} {test-string} +do_execsql_test func3-5.6 { + SELECT quote(likelihood(x'010203000405', 0.5)); +} {X'010203000405'} + +# EVIDENCE-OF: R-44133-61651 The value Y in likelihood(X,Y) must be a +# floating point constant between 0.0 and 1.0, inclusive. +# +do_execsql_test func3-5.7 { + SELECT likelihood(123, 1.0), likelihood(456, 0.0); +} {123 456} +do_test func3-5.8 { + catchsql { + SELECT likelihood(123, 1.000001); + } +} {1 {second argument to likelihood() must be a constant between 0.0 and 1.0}} +do_test func3-5.9 { + catchsql { + SELECT likelihood(123, -0.000001); + } +} {1 {second argument to likelihood() must be a constant between 0.0 and 1.0}} +do_test func3-5.10 { + catchsql { + SELECT likelihood(123, 0.5+0.3); + } +} {1 {second argument to likelihood() must be a constant between 0.0 and 1.0}} + +# EVIDENCE-OF: R-28535-44631 The likelihood(X) function is a no-op that +# the code generator optimizes away so that it consumes no CPU cycles +# during run-time (that is, during calls to sqlite3_step()). +# +do_test func3-5.20 { + db eval {EXPLAIN SELECT likelihood(min(1.0+'2.0',4*11), 0.5)} +} [db eval {EXPLAIN SELECT min(1.0+'2.0',4*11)}] + + +# EVIDENCE-OF: R-11152-23456 The unlikely(X) function returns the +# argument X unchanged. +# +do_execsql_test func3-5.30 { + SELECT unlikely(9223372036854775807); +} {9223372036854775807} +do_execsql_test func3-5.31 { + SELECT unlikely(-9223372036854775808); +} {-9223372036854775808} +do_execsql_test func3-5.32 { + SELECT unlikely(14.125); +} {14.125} +do_execsql_test func3-5.33 { + SELECT unlikely(NULL); +} {{}} +do_execsql_test func3-5.34 { + SELECT unlikely('test-string'); +} {test-string} +do_execsql_test func3-5.35 { + SELECT quote(unlikely(x'010203000405')); +} {X'010203000405'} + +# EVIDENCE-OF: R-22887-63324 The unlikely(X) function is a no-op that +# the code generator optimizes away so that it consumes no CPU cycles at +# run-time (that is, during calls to sqlite3_step()). +# +do_test func3-5.39 { + db eval {EXPLAIN SELECT unlikely(min(1.0+'2.0',4*11))} +} [db eval {EXPLAIN SELECT min(1.0+'2.0',4*11)}] + +# Unlikely() does not preserve the affinity of X. +# ticket https://www.sqlite.org/src/tktview/0c620df60b +# +do_execsql_test func3-5.40 { + SELECT likely(CAST(1 AS INT))=='1'; +} 0 +do_execsql_test func3-5.41 { + SELECT unlikely(CAST(1 AS INT))=='1'; +} 0 +do_execsql_test func3-5.41 { + SELECT likelihood(CAST(1 AS INT),0.5)=='1'; +} 0 + + +# EVIDENCE-OF: R-23735-03107 The likely(X) function returns the argument +# X unchanged. +# +do_execsql_test func3-5.50 { + SELECT likely(9223372036854775807); +} {9223372036854775807} +do_execsql_test func3-5.51 { + SELECT likely(-9223372036854775808); +} {-9223372036854775808} +do_execsql_test func3-5.52 { + SELECT likely(14.125); +} {14.125} +do_execsql_test func3-5.53 { + SELECT likely(NULL); +} {{}} +do_execsql_test func3-5.54 { + SELECT likely('test-string'); +} {test-string} +do_execsql_test func3-5.55 { + SELECT quote(likely(x'010203000405')); +} {X'010203000405'} + +# EVIDENCE-OF: R-43464-09689 The likely(X) function is a no-op that the +# code generator optimizes away so that it consumes no CPU cycles at +# run-time (that is, during calls to sqlite3_step()). +# +do_test func3-5.59 { + db eval {EXPLAIN SELECT likely(min(1.0+'2.0',4*11))} +} [db eval {EXPLAIN SELECT min(1.0+'2.0',4*11)}] + + +# Test the outcome of specifying NULL xStep and xFinal pointers (normally +# used to delete any existing function) and a non-NULL xDestroy when there +# is no existing function to destroy. +# +do_test func3-6.0 { + sqlite3_create_function_v2 db nofunc 1 utf8 +} {} + + + +finish_test diff --git a/test/func4.test b/test/func4.test new file mode 100644 index 0000000..64c7a11 --- /dev/null +++ b/test/func4.test @@ -0,0 +1,758 @@ +# 2013 March 10 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The focus of +# this file is testing the tointeger() and toreal() functions. +# +# Several of the toreal() tests are disabled on platforms where floating +# point precision is not high enough to represent their constant integer +# expression arguments as double precision floating point values. +# +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set saved_tcl_precision $tcl_precision +set tcl_precision 0 +load_static_extension db totype + +set highPrecision(1) [expr \ + {[db eval {SELECT tointeger(9223372036854775807 + 1);}] eq {{}}}] + +do_execsql_test func4-1.1 { + SELECT tointeger(NULL); +} {{}} +do_execsql_test func4-1.2 { + SELECT tointeger(''); +} {{}} +do_execsql_test func4-1.3 { + SELECT tointeger(' '); +} {{}} +do_execsql_test func4-1.4 { + SELECT tointeger('1234'); +} {1234} +do_execsql_test func4-1.5 { + SELECT tointeger(' 1234'); +} {{}} +do_execsql_test func4-1.6 { + SELECT tointeger('bad'); +} {{}} +do_execsql_test func4-1.7 { + SELECT tointeger('0xBAD'); +} {{}} +do_execsql_test func4-1.8 { + SELECT tointeger('123BAD'); +} {{}} +do_execsql_test func4-1.9 { + SELECT tointeger('0x123BAD'); +} {{}} +do_execsql_test func4-1.10 { + SELECT tointeger('123NO'); +} {{}} +do_execsql_test func4-1.11 { + SELECT tointeger('0x123NO'); +} {{}} +do_execsql_test func4-1.12 { + SELECT tointeger('-0x1'); +} {{}} +do_execsql_test func4-1.13 { + SELECT tointeger('-0x0'); +} {{}} +do_execsql_test func4-1.14 { + SELECT tointeger('0x0'); +} {{}} +do_execsql_test func4-1.15 { + SELECT tointeger('0x1'); +} {{}} +do_execsql_test func4-1.16 { + SELECT tointeger(-1); +} {-1} +do_execsql_test func4-1.17 { + SELECT tointeger(-0); +} {0} +do_execsql_test func4-1.18 { + SELECT tointeger(0); +} {0} +do_execsql_test func4-1.19 { + SELECT tointeger(1); +} {1} +do_execsql_test func4-1.20 { + SELECT tointeger(-1.79769313486232e308 - 1); +} {{}} +do_execsql_test func4-1.21 { + SELECT tointeger(-1.79769313486232e308); +} {{}} +do_execsql_test func4-1.22 { + SELECT tointeger(-1.79769313486232e308 + 1); +} {{}} +do_execsql_test func4-1.23 { + SELECT tointeger(-9223372036854775808 - 1); +} {{}} +do_execsql_test func4-1.24 { + SELECT tointeger(-9223372036854775808); +} {-9223372036854775808} +do_execsql_test func4-1.25 { + SELECT tointeger(-9223372036854775808 + 1); +} {-9223372036854775807} +do_execsql_test func4-1.26 { + SELECT tointeger(-9223372036854775807 - 1); +} {-9223372036854775808} +do_execsql_test func4-1.27 { + SELECT tointeger(-9223372036854775807); +} {-9223372036854775807} +do_execsql_test func4-1.28 { + SELECT tointeger(-9223372036854775807 + 1); +} {-9223372036854775806} +do_execsql_test func4-1.29 { + SELECT tointeger(-2147483648 - 1); +} {-2147483649} +do_execsql_test func4-1.30 { + SELECT tointeger(-2147483648); +} {-2147483648} +do_execsql_test func4-1.31 { + SELECT tointeger(-2147483648 + 1); +} {-2147483647} +do_execsql_test func4-1.32 { + SELECT tointeger(2147483647 - 1); +} {2147483646} +do_execsql_test func4-1.33 { + SELECT tointeger(2147483647); +} {2147483647} +do_execsql_test func4-1.34 { + SELECT tointeger(2147483647 + 1); +} {2147483648} +do_execsql_test func4-1.35 { + SELECT tointeger(9223372036854775807 - 1); +} {9223372036854775806} +do_execsql_test func4-1.36 { + SELECT tointeger(9223372036854775807); +} {9223372036854775807} +if {$highPrecision(1)} { + do_execsql_test func4-1.37 { + SELECT tointeger(9223372036854775807 + 1); + } {{}} +} +do_execsql_test func4-1.38 { + SELECT tointeger(1.79769313486232e308 - 1); +} {{}} +do_execsql_test func4-1.39 { + SELECT tointeger(1.79769313486232e308); +} {{}} +do_execsql_test func4-1.40 { + SELECT tointeger(1.79769313486232e308 + 1); +} {{}} +do_execsql_test func4-1.41 { + SELECT tointeger(4503599627370496 - 1); +} {4503599627370495} +do_execsql_test func4-1.42 { + SELECT tointeger(4503599627370496); +} {4503599627370496} +do_execsql_test func4-1.43 { + SELECT tointeger(4503599627370496 + 1); +} {4503599627370497} +do_execsql_test func4-1.44 { + SELECT tointeger(9007199254740992 - 1); +} {9007199254740991} +do_execsql_test func4-1.45 { + SELECT tointeger(9007199254740992); +} {9007199254740992} +do_execsql_test func4-1.46 { + SELECT tointeger(9007199254740992 + 1); +} {9007199254740993} +do_execsql_test func4-1.47 { + SELECT tointeger(9223372036854775807 - 1); +} {9223372036854775806} +do_execsql_test func4-1.48 { + SELECT tointeger(9223372036854775807); +} {9223372036854775807} +if {$highPrecision(1)} { + do_execsql_test func4-1.49 { + SELECT tointeger(9223372036854775807 + 1); + } {{}} + do_execsql_test func4-1.50 { + SELECT tointeger(9223372036854775808 - 1); + } {{}} + do_execsql_test func4-1.51 { + SELECT tointeger(9223372036854775808); + } {{}} + do_execsql_test func4-1.52 { + SELECT tointeger(9223372036854775808 + 1); + } {{}} +} +do_execsql_test func4-1.53 { + SELECT tointeger(18446744073709551616 - 1); +} {{}} +do_execsql_test func4-1.54 { + SELECT tointeger(18446744073709551616); +} {{}} +do_execsql_test func4-1.55 { + SELECT tointeger(18446744073709551616 + 1); +} {{}} + +ifcapable floatingpoint { + set highPrecision(2) [expr \ + {[db eval {SELECT toreal(-9223372036854775808 + 1);}] eq {{}}}] + + do_execsql_test func4-2.1 { + SELECT toreal(NULL); + } {{}} + do_execsql_test func4-2.2 { + SELECT toreal(''); + } {{}} + do_execsql_test func4-2.3 { + SELECT toreal(' '); + } {{}} + do_execsql_test func4-2.4 { + SELECT toreal('1234'); + } {1234.0} + do_execsql_test func4-2.5 { + SELECT toreal(' 1234'); + } {{}} + do_execsql_test func4-2.6 { + SELECT toreal('bad'); + } {{}} + do_execsql_test func4-2.7 { + SELECT toreal('0xBAD'); + } {{}} + do_execsql_test func4-2.8 { + SELECT toreal('123BAD'); + } {{}} + do_execsql_test func4-2.9 { + SELECT toreal('0x123BAD'); + } {{}} + do_execsql_test func4-2.10 { + SELECT toreal('123NO'); + } {{}} + do_execsql_test func4-2.11 { + SELECT toreal('0x123NO'); + } {{}} + do_execsql_test func4-2.12 { + SELECT toreal('-0x1'); + } {{}} + do_execsql_test func4-2.13 { + SELECT toreal('-0x0'); + } {{}} + do_execsql_test func4-2.14 { + SELECT toreal('0x0'); + } {{}} + do_execsql_test func4-2.15 { + SELECT toreal('0x1'); + } {{}} + do_execsql_test func4-2.16 { + SELECT toreal(-1); + } {-1.0} + do_execsql_test func4-2.17 { + SELECT toreal(-0); + } {0.0} + do_execsql_test func4-2.18 { + SELECT toreal(0); + } {0.0} + do_execsql_test func4-2.19 { + SELECT toreal(1); + } {1.0} + do_execsql_test func4-2.20 { + SELECT toreal(-1.79769313486232e308 - 1); + } {-Inf} + do_execsql_test func4-2.21 { + SELECT toreal(-1.79769313486232e308); + } {-Inf} + do_execsql_test func4-2.22 { + SELECT toreal(-1.79769313486232e308 + 1); + } {-Inf} + do_execsql_test func4-2.23 { + SELECT toreal(-9223372036854775808 - 1); + } {-9.223372036854776e+18} + do_execsql_test func4-2.24 { + SELECT toreal(-9223372036854775808); + } {{}} + if {$highPrecision(2)} { + do_execsql_test func4-2.25 { + SELECT toreal(-9223372036854775808 + 1); + } {{}} + } + do_execsql_test func4-2.26 { + SELECT toreal(-9223372036854775807 - 1); + } {{}} + if {$highPrecision(2)} { + do_execsql_test func4-2.27 { + SELECT toreal(-9223372036854775807); + } {{}} + do_execsql_test func4-2.28 { + SELECT toreal(-9223372036854775807 + 1); + } {{}} + } + do_execsql_test func4-2.29 { + SELECT toreal(-2147483648 - 1); + } {-2147483649.0} + do_execsql_test func4-2.30 { + SELECT toreal(-2147483648); + } {-2147483648.0} + do_execsql_test func4-2.31 { + SELECT toreal(-2147483648 + 1); + } {-2147483647.0} + do_execsql_test func4-2.32 { + SELECT toreal(2147483647 - 1); + } {2147483646.0} + do_execsql_test func4-2.33 { + SELECT toreal(2147483647); + } {2147483647.0} + do_execsql_test func4-2.34 { + SELECT toreal(2147483647 + 1); + } {2147483648.0} + if {$highPrecision(2)} { + do_execsql_test func4-2.35 { + SELECT toreal(9223372036854775807 - 1); + } {{}} + if {$highPrecision(1)} { + do_execsql_test func4-2.36 { + SELECT toreal(9223372036854775807); + } {{}} + } + } + do_execsql_test func4-2.37 { + SELECT toreal(9223372036854775807 + 1); + } {9.223372036854776e+18} + do_execsql_test func4-2.38 { + SELECT toreal(1.79769313486232e308 - 1); + } {Inf} + do_execsql_test func4-2.39 { + SELECT toreal(1.79769313486232e308); + } {Inf} + do_execsql_test func4-2.40 { + SELECT toreal(1.79769313486232e308 + 1); + } {Inf} + do_execsql_test func4-2.41 { + SELECT toreal(4503599627370496 - 1); + } {4503599627370495.0} + do_execsql_test func4-2.42 { + SELECT toreal(4503599627370496); + } {4503599627370496.0} + do_execsql_test func4-2.43 { + SELECT toreal(4503599627370496 + 1); + } {4503599627370497.0} + do_execsql_test func4-2.44 { + SELECT toreal(9007199254740992 - 1); + } {9007199254740991.0} + do_execsql_test func4-2.45 { + SELECT toreal(9007199254740992); + } {9007199254740992.0} + if {$highPrecision(2)} { + do_execsql_test func4-2.46 { + SELECT toreal(9007199254740992 + 1); + } {{}} + } + do_execsql_test func4-2.47 { + SELECT toreal(9007199254740992 + 2); + } {9007199254740994.0} + do_execsql_test func4-2.48 { + SELECT toreal(tointeger(9223372036854775808) - 1); + } {{}} + if {$highPrecision(1)} { + do_execsql_test func4-2.49 { + SELECT toreal(tointeger(9223372036854775808)); + } {{}} + do_execsql_test func4-2.50 { + SELECT toreal(tointeger(9223372036854775808) + 1); + } {{}} + } + do_execsql_test func4-2.51 { + SELECT toreal(tointeger(18446744073709551616) - 1); + } {{}} + do_execsql_test func4-2.52 { + SELECT toreal(tointeger(18446744073709551616)); + } {{}} + do_execsql_test func4-2.53 { + SELECT toreal(tointeger(18446744073709551616) + 1); + } {{}} +} + +ifcapable check { + do_execsql_test func4-3.1 { + CREATE TABLE t1( + x INTEGER CHECK(tointeger(x) IS NOT NULL) + ); + } {} + do_test func4-3.2 { + catchsql { + INSERT INTO t1 (x) VALUES (NULL); + } + } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} + do_test func4-3.3 { + catchsql { + INSERT INTO t1 (x) VALUES (NULL); + } + } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} + do_test func4-3.4 { + catchsql { + INSERT INTO t1 (x) VALUES (''); + } + } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} + do_test func4-3.5 { + catchsql { + INSERT INTO t1 (x) VALUES ('bad'); + } + } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} + do_test func4-3.6 { + catchsql { + INSERT INTO t1 (x) VALUES ('1234bad'); + } + } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} + do_test func4-3.7 { + catchsql { + INSERT INTO t1 (x) VALUES ('1234.56bad'); + } + } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} + do_test func4-3.8 { + catchsql { + INSERT INTO t1 (x) VALUES (1234); + } + } {0 {}} + do_test func4-3.9 { + catchsql { + INSERT INTO t1 (x) VALUES (1234.56); + } + } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} + do_test func4-3.10 { + catchsql { + INSERT INTO t1 (x) VALUES ('1234'); + } + } {0 {}} + do_test func4-3.11 { + catchsql { + INSERT INTO t1 (x) VALUES ('1234.56'); + } + } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} + do_test func4-3.12 { + catchsql { + INSERT INTO t1 (x) VALUES (ZEROBLOB(4)); + } + } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} + do_test func4-3.13 { + catchsql { + INSERT INTO t1 (x) VALUES (X''); + } + } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} + do_test func4-3.14 { + catchsql { + INSERT INTO t1 (x) VALUES (X'1234'); + } + } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} + do_test func4-3.15 { + catchsql { + INSERT INTO t1 (x) VALUES (X'12345678'); + } + } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} + do_test func4-3.16 { + catchsql { + INSERT INTO t1 (x) VALUES ('1234.00'); + } + } {0 {}} + do_test func4-3.17 { + catchsql { + INSERT INTO t1 (x) VALUES (1234.00); + } + } {0 {}} + do_test func4-3.18 { + catchsql { + INSERT INTO t1 (x) VALUES ('-9223372036854775809'); + } + } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} + if {$highPrecision(1)} { + do_test func4-3.19 { + catchsql { + INSERT INTO t1 (x) VALUES (9223372036854775808); + } + } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} + } + do_execsql_test func4-3.20 { + SELECT x FROM t1 WHERE x>0 ORDER BY x; + } {1234 1234 1234 1234} + + ifcapable floatingpoint { + do_execsql_test func4-4.1 { + CREATE TABLE t2( + x REAL CHECK(toreal(x) IS NOT NULL) + ); + } {} + do_test func4-4.2 { + catchsql { + INSERT INTO t2 (x) VALUES (NULL); + } + } {1 {CHECK constraint failed: toreal(x) IS NOT NULL}} + do_test func4-4.3 { + catchsql { + INSERT INTO t2 (x) VALUES (NULL); + } + } {1 {CHECK constraint failed: toreal(x) IS NOT NULL}} + do_test func4-4.4 { + catchsql { + INSERT INTO t2 (x) VALUES (''); + } + } {1 {CHECK constraint failed: toreal(x) IS NOT NULL}} + do_test func4-4.5 { + catchsql { + INSERT INTO t2 (x) VALUES ('bad'); + } + } {1 {CHECK constraint failed: toreal(x) IS NOT NULL}} + do_test func4-4.6 { + catchsql { + INSERT INTO t2 (x) VALUES ('1234bad'); + } + } {1 {CHECK constraint failed: toreal(x) IS NOT NULL}} + do_test func4-4.7 { + catchsql { + INSERT INTO t2 (x) VALUES ('1234.56bad'); + } + } {1 {CHECK constraint failed: toreal(x) IS NOT NULL}} + do_test func4-4.8 { + catchsql { + INSERT INTO t2 (x) VALUES (1234); + } + } {0 {}} + do_test func4-4.9 { + catchsql { + INSERT INTO t2 (x) VALUES (1234.56); + } + } {0 {}} + do_test func4-4.10 { + catchsql { + INSERT INTO t2 (x) VALUES ('1234'); + } + } {0 {}} + do_test func4-4.11 { + catchsql { + INSERT INTO t2 (x) VALUES ('1234.56'); + } + } {0 {}} + do_test func4-4.12 { + catchsql { + INSERT INTO t2 (x) VALUES (ZEROBLOB(4)); + } + } {1 {CHECK constraint failed: toreal(x) IS NOT NULL}} + do_test func4-4.13 { + catchsql { + INSERT INTO t2 (x) VALUES (X''); + } + } {1 {CHECK constraint failed: toreal(x) IS NOT NULL}} + do_test func4-4.14 { + catchsql { + INSERT INTO t2 (x) VALUES (X'1234'); + } + } {1 {CHECK constraint failed: toreal(x) IS NOT NULL}} + do_test func4-4.15 { + catchsql { + INSERT INTO t2 (x) VALUES (X'12345678'); + } + } {1 {CHECK constraint failed: toreal(x) IS NOT NULL}} + do_execsql_test func4-4.16 { + SELECT x FROM t2 ORDER BY x; + } {1234.0 1234.0 1234.56 1234.56} + } +} + +ifcapable floatingpoint { + do_execsql_test func4-5.1 { + SELECT tointeger(toreal('1234')); + } {1234} + do_execsql_test func4-5.2 { + SELECT tointeger(toreal(-1)); + } {-1} + do_execsql_test func4-5.3 { + SELECT tointeger(toreal(-0)); + } {0} + do_execsql_test func4-5.4 { + SELECT tointeger(toreal(0)); + } {0} + do_execsql_test func4-5.5 { + SELECT tointeger(toreal(1)); + } {1} + do_execsql_test func4-5.6 { + SELECT tointeger(toreal(-9223372036854775808 - 1)); + } {{}} + do_execsql_test func4-5.7 { + SELECT tointeger(toreal(-9223372036854775808)); + } {{}} + if {$highPrecision(2)} { + do_execsql_test func4-5.8 { + SELECT tointeger(toreal(-9223372036854775808 + 1)); + } {{}} + } + do_execsql_test func4-5.9 { + SELECT tointeger(toreal(-2147483648 - 1)); + } {-2147483649} + do_execsql_test func4-5.10 { + SELECT tointeger(toreal(-2147483648)); + } {-2147483648} + do_execsql_test func4-5.11 { + SELECT tointeger(toreal(-2147483648 + 1)); + } {-2147483647} + do_execsql_test func4-5.12 { + SELECT tointeger(toreal(2147483647 - 1)); + } {2147483646} + do_execsql_test func4-5.13 { + SELECT tointeger(toreal(2147483647)); + } {2147483647} + do_execsql_test func4-5.14 { + SELECT tointeger(toreal(2147483647 + 1)); + } {2147483648} + do_execsql_test func4-5.15 { + SELECT tointeger(toreal(9223372036854775807 - 1)); + } {{}} + if {$highPrecision(1)} { + do_execsql_test func4-5.16 { + SELECT tointeger(toreal(9223372036854775807)); + } {{}} + do_execsql_test func4-5.17 { + SELECT tointeger(toreal(9223372036854775807 + 1)); + } {{}} + } + do_execsql_test func4-5.18 { + SELECT tointeger(toreal(4503599627370496 - 1)); + } {4503599627370495} + do_execsql_test func4-5.19 { + SELECT tointeger(toreal(4503599627370496)); + } {4503599627370496} + do_execsql_test func4-5.20 { + SELECT tointeger(toreal(4503599627370496 + 1)); + } {4503599627370497} + do_execsql_test func4-5.21 { + SELECT tointeger(toreal(9007199254740992 - 1)); + } {9007199254740991} + do_execsql_test func4-5.22 { + SELECT tointeger(toreal(9007199254740992)); + } {9007199254740992} + if {$highPrecision(2)} { + do_execsql_test func4-5.23 { + SELECT tointeger(toreal(9007199254740992 + 1)); + } {{}} + } + do_execsql_test func4-5.24 { + SELECT tointeger(toreal(9007199254740992 + 2)); + } {9007199254740994} + if {$highPrecision(1)} { + do_execsql_test func4-5.25 { + SELECT tointeger(toreal(9223372036854775808 - 1)); + } {{}} + do_execsql_test func4-5.26 { + SELECT tointeger(toreal(9223372036854775808)); + } {{}} + do_execsql_test func4-5.27 { + SELECT tointeger(toreal(9223372036854775808 + 1)); + } {{}} + } + do_execsql_test func4-5.28 { + SELECT tointeger(toreal(18446744073709551616 - 1)); + } {{}} + do_execsql_test func4-5.29 { + SELECT tointeger(toreal(18446744073709551616)); + } {{}} + do_execsql_test func4-5.30 { + SELECT tointeger(toreal(18446744073709551616 + 1)); + } {{}} +} + +for {set i 0} {$i < 10} {incr i} { + if {$i == 8} continue + do_execsql_test func4-6.1.$i.1 [subst { + SELECT tointeger(x'[string repeat 01 $i]'); + }] {{}} + ifcapable floatingpoint { + do_execsql_test func4-6.1.$i.2 [subst { + SELECT toreal(x'[string repeat 01 $i]'); + }] {{}} + } +} + +do_execsql_test func4-6.2.1 { + SELECT tointeger(x'0102030405060708'); +} {578437695752307201} +do_execsql_test func4-6.2.2 { + SELECT tointeger(x'0807060504030201'); +} {72623859790382856} + +ifcapable floatingpoint { + do_execsql_test func4-6.3.1 { + SELECT toreal(x'ffefffffffffffff'); + } {-1.7976931348623157e+308} + do_execsql_test func4-6.3.2 { + SELECT toreal(x'8010000000000000'); + } {-2.2250738585072014e-308} + do_execsql_test func4-6.3.3 { + SELECT toreal(x'c000000000000000'); + } {-2.0} + do_execsql_test func4-6.3.4 { + SELECT toreal(x'bff0000000000000'); + } {-1.0} + do_execsql_test func4-6.3.5 { + SELECT toreal(x'8000000000000000'); + } {-0.0} + do_execsql_test func4-6.3.6 { + SELECT toreal(x'0000000000000000'); + } {0.0} + do_execsql_test func4-6.3.7 { + SELECT toreal(x'3ff0000000000000'); + } {1.0} + do_execsql_test func4-6.3.8 { + SELECT toreal(x'4000000000000000'); + } {2.0} + do_execsql_test func4-6.3.9 { + SELECT toreal(x'0010000000000000'); + } {2.2250738585072014e-308} + do_execsql_test func4-6.3.10 { + SELECT toreal(x'7fefffffffffffff'); + } {1.7976931348623157e+308} + do_execsql_test func4-6.3.11 { + SELECT toreal(x'8000000000000001'); + } {-5e-324} + do_execsql_test func4-6.3.12 { + SELECT toreal(x'800fffffffffffff'); + } {-2.225073858507201e-308} + do_execsql_test func4-6.3.13 { + SELECT toreal(x'0000000000000001'); + } {5e-324} + do_execsql_test func4-6.3.14 { + SELECT toreal(x'000fffffffffffff'); + } {2.225073858507201e-308} + do_execsql_test func4-6.3.15 { + SELECT toreal(x'fff0000000000000'); + } {-Inf} + do_execsql_test func4-6.3.16 { + SELECT toreal(x'7ff0000000000000'); + } {Inf} + do_execsql_test func4-6.3.17 { + SELECT toreal(x'fff8000000000000'); + } {{}} + do_execsql_test func4-6.3.18 { + SELECT toreal(x'fff0000000000001'); + } {{}} + do_execsql_test func4-6.3.19 { + SELECT toreal(x'fff7ffffffffffff'); + } {{}} + do_execsql_test func4-6.3.20 { + SELECT toreal(x'7ff0000000000001'); + } {{}} + do_execsql_test func4-6.3.21 { + SELECT toreal(x'7ff7ffffffffffff'); + } {{}} + do_execsql_test func4-6.3.22 { + SELECT toreal(x'fff8000000000001'); + } {{}} + do_execsql_test func4-6.3.23 { + SELECT toreal(x'ffffffffffffffff'); + } {{}} + do_execsql_test func4-6.3.24 { + SELECT toreal(x'7ff8000000000000'); + } {{}} + do_execsql_test func4-6.3.25 { + SELECT toreal(x'7fffffffffffffff'); + } {{}} +} + +set tcl_precision $saved_tcl_precision +unset saved_tcl_precision +finish_test diff --git a/test/func5.test b/test/func5.test new file mode 100644 index 0000000..8c3dd05 --- /dev/null +++ b/test/func5.test @@ -0,0 +1,64 @@ +# 2013-11-21 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# +# Testing of function factoring and the SQLITE_DETERMINISTIC flag. +# +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Verify that constant string expressions that get factored into initializing +# code are not reused between function parameters and other values in the +# VDBE program, as the function might have changed the encoding. +# +do_execsql_test func5-1.1 { + PRAGMA encoding=UTF16le; + CREATE TABLE t1(x,a,b,c); + INSERT INTO t1 VALUES(1,'ab','cd',1); + INSERT INTO t1 VALUES(2,'gh','ef',5); + INSERT INTO t1 VALUES(3,'pqr','fuzzy',99); + INSERT INTO t1 VALUES(4,'abcdefg','xy',22); + INSERT INTO t1 VALUES(5,'shoe','mayer',2953); + SELECT x FROM t1 WHERE c=instr('abcdefg',b) OR a='abcdefg' ORDER BY +x; +} {2 4} +do_execsql_test func5-1.2 { + SELECT x FROM t1 WHERE a='abcdefg' OR c=instr('abcdefg',b) ORDER BY +x; +} {2 4} + +# Verify that SQLITE_DETERMINISTIC functions get factored out of the +# evaluation loop whereas non-deterministic functions do not. counter1() +# is marked as non-deterministic and so is not factored out of the loop, +# and it really is non-deterministic, returning a different result each +# time. But counter2() is marked as deterministic, so it does get factored +# out of the loop. counter2() has the same implementation as counter1(), +# returning a different result on each invocation, but because it is +# only invoked once outside of the loop, it appears to return the same +# result multiple times. +# +do_execsql_test func5-2.1 { + CREATE TABLE t2(x,y); + INSERT INTO t2 VALUES(1,2),(3,4),(5,6),(7,8); + SELECT x, y FROM t2 WHERE x+5=5+x ORDER BY +x; +} {1 2 3 4 5 6 7 8} +sqlite3_create_function db +do_execsql_test func5-2.2 { + SELECT x, y FROM t2 + WHERE x+counter1('hello')=counter1('hello')+x + ORDER BY +x; +} {} +set cvalue [db one {SELECT counter2('hello')+1}] +do_execsql_test func5-2.3 { + SELECT x, y FROM t2 + WHERE x+counter2('hello')=$cvalue+x + ORDER BY +x; +} {1 2 3 4 5 6 7 8} + + +finish_test diff --git a/test/func6.test b/test/func6.test new file mode 100644 index 0000000..fe90a75 --- /dev/null +++ b/test/func6.test @@ -0,0 +1,183 @@ +# 2017-12-16 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# +# Test cases for the sqlite_offset() function. +# +# Some of the tests in this file depend on the exact placement of content +# within b-tree pages. Such placement is at the implementations discretion, +# and so it is possible for results to change from one release to the next. +# +set testdir [file dirname $argv0] +source $testdir/tester.tcl +ifcapable !offset_sql_func { + finish_test + return +} + +set bNullTrim 0 +ifcapable null_trim { + set bNullTrim 1 +} + +do_execsql_test func6-100 { + PRAGMA page_size=4096; + PRAGMA auto_vacuum=NONE; + CREATE TABLE t1(a,b,c,d); + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100) + INSERT INTO t1(a,b,c,d) SELECT printf('abc%03x',x), x, 1000-x, NULL FROM c; + CREATE INDEX t1a ON t1(a); + CREATE INDEX t1bc ON t1(b,c); + CREATE TABLE t2(x TEXT PRIMARY KEY, y) WITHOUT ROWID; + INSERT INTO t2(x,y) SELECT a, b FROM t1; +} + +# Load the contents of $file from disk and return it encoded as a hex +# string. +proc loadhex {file} { + set fd [open $file] + fconfigure $fd -translation binary -encoding binary + set data [read $fd] + close $fd + binary encode hex $data +} + +# Each argument is either an integer between 0 and 65535, a text value, or +# an empty string representing an SQL NULL. This command builds an SQLite +# record containing the values passed as arguments and returns it encoded +# as a hex string. +proc hexrecord {args} { + set hdr "" + set body "" + + if {$::bNullTrim} { + while {[llength $args] && [lindex $args end]=={}} { + set args [lrange $args 0 end-1] + } + } + + foreach x $args { + if {$x==""} { + append hdr 00 + } elseif {[string is integer $x]==0} { + set n [string length $x] + append hdr [format %02x [expr $n*2 + 13]] + append body [binary encode hex $x] + } elseif {$x == 0} { + append hdr 08 + } elseif {$x == 1} { + append hdr 09 + } elseif {$x <= 127} { + append hdr 01 + append body [format %02x $x] + } else { + append hdr 02 + append body [format %04x $x] + } + } + set res [format %02x [expr 1 + [string length $hdr]/2]] + append res $hdr + append res $body +} + +# Argument $off is an offset into the database image encoded as a hex string +# in argument $hexdb. This command returns 0 if the offset contains the hex +# $hexrec, or throws an exception otherwise. +# +proc offset_contains_record {off hexdb hexrec} { + set n [string length $hexrec] + set off [expr $off*2] + if { [string compare $hexrec [string range $hexdb $off [expr $off+$n-1]]] } { + error "record not found!" + } + return 0 +} + +# This command is the implementation of SQL function "offrec()". The first +# argument to this is an offset value. The remaining values are used to +# formulate an SQLite record. If database file test.db does not contain +# an equivalent record at the specified offset, an exception is thrown. +# Otherwise, 0 is returned. +# +proc offrec {args} { + set offset [lindex $args 0] + set rec [hexrecord {*}[lrange $args 1 end]] + offset_contains_record $offset $::F $rec +} +set F [loadhex test.db] +db func offrec offrec + +# Test the sanity of the tests. +if {$bNullTrim} { + set offset 8180 +} else { + set offset 8179 +} +do_execsql_test func6-105 { + SELECT sqlite_offset(d) FROM t1 ORDER BY rowid LIMIT 1; +} $offset +do_test func6-106 { + set r [hexrecord abc001 1 999 {}] + offset_contains_record $offset $F $r +} 0 + +set z100 [string trim [string repeat "0 " 100]] + +# Test offsets within table b-tree t1. +do_execsql_test func6-110 { + SELECT offrec(sqlite_offset(d), a, b, c, d) FROM t1 ORDER BY rowid +} $z100 + +do_execsql_test func6-120 { + SELECT a, typeof(sqlite_offset(+a)) FROM t1 + ORDER BY rowid LIMIT 2; +} {abc001 null abc002 null} + +# Test offsets within index b-tree t1a. +do_execsql_test func6-130 { + SELECT offrec(sqlite_offset(a), a, rowid) FROM t1 ORDER BY a +} $z100 + +# Test offsets within table b-tree t1 with a temp b-tree ORDER BY. +do_execsql_test func6-140 { + SELECT offrec(sqlite_offset(d), a, b, c, d) FROM t1 ORDER BY a +} $z100 + +# Test offsets from both index t1a and table t1 in the same query. +do_execsql_test func6-150 { + SELECT offrec(sqlite_offset(a), a, rowid), + offrec(sqlite_offset(d), a, b, c, d) + FROM t1 ORDER BY a +} [concat $z100 $z100] + +# Test offsets from both index t1bc and table t1 in the same query. +do_execsql_test func6-160 { + SELECT offrec(sqlite_offset(b), b, c, rowid), + offrec(sqlite_offset(c), b, c, rowid), + offrec(sqlite_offset(d), a, b, c, d) + FROM t1 + ORDER BY b +} [concat $z100 $z100 $z100] + +# Test offsets in WITHOUT ROWID table t2. +do_execsql_test func6-200 { + SELECT offrec( sqlite_offset(y), x, y ) FROM t2 ORDER BY x +} $z100 + +# 2022-03-14 dbsqlfuzz 474499f3977d95fdf2dbcd99c50be1d0082e4c92 +reset_db +do_execsql_test func6-300 { + CREATE TABLE t2(a INT, b INT PRIMARY KEY) WITHOUT ROWID; + CREATE INDEX x3 ON t2(b); + CREATE TABLE t1(a INT PRIMARY KEY, b TEXT); + SELECT * FROM t1 WHERE a IN (SELECT sqlite_offset(b) FROM t2); +} {} + +finish_test diff --git a/test/func7.test b/test/func7.test new file mode 100644 index 0000000..bb4f80b --- /dev/null +++ b/test/func7.test @@ -0,0 +1,251 @@ +# 2020-12-07 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# +# Test cases for SQL functions based off the standard math library +# +set testdir [file dirname $argv0] +source $testdir/tester.tcl +ifcapable !mathlib { + finish_test + return +} + +do_execsql_test func7-100 { + SELECT ceil(99.9), ceiling(-99.01), floor(17), floor(-17.99); +} {100.0 -99.0 17 -18.0} +do_execsql_test func7-110 { + SELECT quote(ceil(NULL)), ceil('-99.99'); +} {NULL -99.0} +do_execsql_test func7-200 { + SELECT round(ln(5),2), log(100.0), log(100), log(2,'256'); +} {1.61 2.0 2.0 8.0} +do_execsql_test func7-210 { + SELECT ln(-5), log(-5,100.0); +} {{} {}} + +# Test cases derived from PostgreSQL documentation +# +do_execsql_test func7-pg-100 { + SELECT abs(-17.4) +} {17.4} +do_execsql_test func7-pg-110 { + SELECT ceil(42.2) +} {43.0} +do_execsql_test func7-pg-120 { + SELECT ceil(-42.2) +} {-42.0} +do_execsql_test func7-pg-130 { + SELECT round(exp(1.0),7) +} {2.7182818} +do_execsql_test func7-pg-140 { + SELECT floor(42.8) +} {42.0} +do_execsql_test func7-pg-150 { + SELECT floor(-42.8) +} {-43.0} +do_execsql_test func7-pg-160 { + SELECT round(ln(2.0),7) +} {0.6931472} +do_execsql_test func7-pg-170 { + SELECT log(100.0) +} {2.0} +do_execsql_test func7-pg-180 { + SELECT log10(1000.0) +} {3.0} +do_execsql_test func7-pg-181 { + SELECT format('%.30f', log10(100.0) ); +} {2.000000000000000000000000000000} +do_execsql_test func7-pg-182 { + SELECT format('%.30f', ln(exp(2.0)) ); +} {2.000000000000000000000000000000} +do_execsql_test func7-pg-190 { + SELECT log(2.0, 64.0) +} {6.0} +do_execsql_test func7-pg-200 { + SELECT mod(9,4); +} {1.0} +do_execsql_test func7-pg-210 { + SELECT round(pi(),7); +} {3.1415927} +do_execsql_test func7-pg-220 { + SELECT power(9,3); +} {729.0} +do_execsql_test func7-pg-230 { + SELECT round(radians(45.0),7); +} {0.7853982} +do_execsql_test func7-pg-240 { + SELECT round(42.4); +} {42.0} +do_execsql_test func7-pg-250 { + SELECT round(42.4382,2); +} {42.44} +do_execsql_test func7-pg-260 { + SELECT sign(-8.4); +} {-1} +do_execsql_test func7-pg-270 { + SELECT round( sqrt(2), 7); +} {1.4142136} +do_execsql_test func7-pg-280 { + SELECT trunc(42.8), trunc(-42.8); +} {42.0 -42.0} +do_execsql_test func7-pg-300 { + SELECT acos(1); +} {0.0} +do_execsql_test func7-pg-301 { + SELECT degrees(acos(0.5)); +} {60.0} +do_execsql_test func7-pg-310 { + SELECT round( asin(1), 7); +} {1.5707963} +do_execsql_test func7-pg-311 { + SELECT degrees( asin(0.5) ); +} {30.0} +do_execsql_test func7-pg-320 { + SELECT round( atan(1), 7); +} {0.7853982} +do_execsql_test func7-pg-321 { + SELECT degrees( atan(1) ); +} {45.0} +do_execsql_test func7-pg-330 { + SELECT round( atan2(1,0), 7); +} {1.5707963} +do_execsql_test func7-pg-331 { + SELECT degrees( atan2(1,0) ); +} {90.0} +do_execsql_test func7-pg-400 { + SELECT cos(0); +} {1.0} +do_execsql_test func7-pg-401 { + SELECT cos( radians(60.0) ); +} {0.5} +do_execsql_test func7-pg-400 { + SELECT cos(0); +} {1.0} +do_execsql_test func7-pg-410 { + SELECT round( sin(1), 7); +} {0.841471} +do_execsql_test func7-pg-411 { + SELECT sin( radians(30) ); +} {0.5} +do_execsql_test func7-pg-420 { + SELECT round( tan(1), 7); +} {1.5574077} +do_execsql_test func7-pg-421 { + SELECT tan( radians(45) ); +} {1.0} +do_execsql_test func7-pg-500 { + SELECT round( sinh(1), 7); +} {1.1752012} +do_execsql_test func7-pg-510 { + SELECT round( cosh(0), 7); +} {1.0} +do_execsql_test func7-pg-520 { + SELECT round( tanh(1), 7); +} {0.7615942} +do_execsql_test func7-pg-530 { + SELECT round( asinh(1), 7); +} {0.8813736} +do_execsql_test func7-pg-540 { + SELECT round( acosh(1), 7); +} {0.0} +do_execsql_test func7-pg-550 { + SELECT round( atanh(0.5), 7); +} {0.5493061} + +# Test cases derived from MySQL documentation +# +do_execsql_test func7-mysql-100 { + SELECT acos(1); +} {0.0} +do_execsql_test func7-mysql-110 { + SELECT acos(1.0001); +} {{}} +do_execsql_test func7-mysql-120 { + SELECT round( acos(0.0), 7); +} {1.5707963} +do_execsql_test func7-mysql-130 { + SELECT round( asin(0.2), 7); +} {0.2013579} +do_execsql_test func7-mysql-140 { + SELECT asin('foo'); +} {{}} ;# Note: MySQL returns 0 here, not NULL. + # SQLite deliberately returns NULL. + # SQLServer and Oracle throw an error. +do_execsql_test func7-mysql-150 { + SELECT round( atan(2), 7), round( atan(-2), 7); +} {1.1071487 -1.1071487} +do_execsql_test func7-mysql-160 { + SELECT round( atan2(-2,2), 7), round( atan2(pi(),0), 7); +} {-0.7853982 1.5707963} +do_execsql_test func7-mysql-170 { + SELECT ceiling(1.23), ceiling(-1.23); +} {2.0 -1.0} +do_execsql_test func7-mysql-180 { + SELECT cos(pi()); +} {-1.0} +do_execsql_test func7-mysql-190 { + SELECT degrees(pi()), degrees(pi()/2); +} {180.0 90.0} +do_execsql_test func7-mysql-190 { + SELECT round( exp(2), 7), round( exp(-2), 7), exp(0); +} {7.3890561 0.1353353 1.0} +do_execsql_test func7-mysql-200 { + SELECT floor(1.23), floor(-1.23); +} {1.0 -2.0} +do_execsql_test func7-mysql-210 { + SELECT round(ln(2),7), quote(ln(-2)); +} {0.6931472 NULL} +#do_execsql_test func7-mysql-220 { +# SELECT round(log(2),7), log(-2); +#} {0.6931472 NULL} +# log() means natural logarithm in MySQL +do_execsql_test func7-mysql-230 { + SELECT log(2,65536), log(10,100), quote(log(1,100)), quote(log(0,100)); +} {16.0 2.0 NULL NULL} +do_execsql_test func7-mysql-240 { + SELECT log2(65536), quote(log2(-100)), quote(log2(0)); +} {16.0 NULL NULL} +do_execsql_test func7-mysql-250 { + SELECT round(log10(2),7), log10(100), quote(log10(-100)); +} {0.30103 2.0 NULL} +do_execsql_test func7-mysql-260 { + SELECT mod(234,10), 253%7, mod(29,9), 29%9; +} {4.0 1 2.0 2} +do_execsql_test func7-mysql-270 { + SELECT mod(34.5,3); +} {1.5} +do_execsql_test func7-mysql-280 { + SELECT pow(2,2), pow(2,-2); +} {4.0 0.25} +do_execsql_test func7-mysql-281 { + SELECT power(2,2), power(2,-2); +} {4.0 0.25} +do_execsql_test func7-mysql-290 { + SELECT round(radians(90),7); +} {1.5707963} +do_execsql_test func7-mysql-300 { + SELECT sign(-32), sign(0), sign(234); +} {-1 0 1} +do_execsql_test func7-mysql-310 { + SELECT sin(pi()) BETWEEN -1.0e-15 AND 1.0e-15; +} {1} +do_execsql_test func7-mysql-320 { + SELECT sqrt(4), round(sqrt(20),7), quote(sqrt(-16)); +} {2.0 4.472136 NULL} +do_execsql_test func7-mysql-330 { + SELECT tan(pi()) BETWEEN -1.0e-15 AND 1.0e-15; +} {1} +do_execsql_test func7-mysql-331 { + SELECT round(tan(pi()+1),7); +} {1.5574077} + + +finish_test diff --git a/test/func8.test b/test/func8.test new file mode 100644 index 0000000..348dfb7 --- /dev/null +++ b/test/func8.test @@ -0,0 +1,64 @@ +# 2023-03-17 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# +# Test cases for SQL functions with names that are the same as join +# keywords: CROSS FULL INNER LEFT NATURAL OUTER RIGHT +# +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +proc joinx {args} {return [join $args -]} +db func cross {joinx cross} +db func full {joinx full} +db func inner {joinx inner} +db func left {joinx left} +db func natural {joinx natural} +db func outer {joinx outer} +db func right {joinx right} +do_execsql_test func8-100 { + CREATE TABLE cross(cross,full,inner,left,natural,outer,right); + CREATE TABLE full(cross,full,inner,left,natural,outer,right); + CREATE TABLE inner(cross,full,inner,left,natural,outer,right); + CREATE TABLE left(cross,full,inner,left,natural,outer,right); + CREATE TABLE natural(cross,full,inner,left,natural,outer,right); + CREATE TABLE outer(cross,full,inner,left,natural,outer,right); + CREATE TABLE right(cross,full,inner,left,natural,outer,right); + INSERT INTO cross VALUES(1,2,3,4,5,6,7); + INSERT INTO full VALUES(1,2,3,4,5,6,7); + INSERT INTO inner VALUES(1,2,3,4,5,6,7); + INSERT INTO left VALUES(1,2,3,4,5,6,7); + INSERT INTO natural VALUES(1,2,3,4,5,6,7); + INSERT INTO outer VALUES(1,2,3,4,5,6,7); + INSERT INTO right VALUES(1,2,3,4,5,6,7); +} +do_execsql_test func8-110 { + SELECT cross(cross,full,inner,left,natural,outer,right) FROM cross; +} cross-1-2-3-4-5-6-7 +do_execsql_test func8-120 { + SELECT full(cross,full,inner,left,natural,outer,right) FROM full; +} full-1-2-3-4-5-6-7 +do_execsql_test func8-130 { + SELECT inner(cross,full,inner,left,natural,outer,right) FROM inner; +} inner-1-2-3-4-5-6-7 +do_execsql_test func8-140 { + SELECT left(cross,full,inner,left,natural,outer,right) FROM left; +} left-1-2-3-4-5-6-7 +do_execsql_test func8-150 { + SELECT natural(cross,full,inner,left,natural,outer,right) FROM natural; +} natural-1-2-3-4-5-6-7 +do_execsql_test func8-160 { + SELECT outer(cross,full,inner,left,natural,outer,right) FROM outer; +} outer-1-2-3-4-5-6-7 +do_execsql_test func8-170 { + SELECT right(cross,full,inner,left,natural,outer,right) FROM right; +} right-1-2-3-4-5-6-7 + +finish_test diff --git a/test/func9.test b/test/func9.test new file mode 100644 index 0000000..6cf9fc3 --- /dev/null +++ b/test/func9.test @@ -0,0 +1,40 @@ +# 2023-08-29 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# +# Test cases for SQL newer functions +# +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +do_execsql_test func9-100 { + SELECT concat('abc',123,null,'xyz'); +} {abc123xyz} +do_execsql_test func9-110 { + SELECT typeof(concat(null)); +} {text} +do_catchsql_test func9-120 { + SELECT concat(); +} {1 {wrong number of arguments to function concat()}} +do_execsql_test func9-130 { + SELECT concat_ws(',',1,2,3,4,5,6,7,8,NULL,9,10,11,12); +} {1,2,3,4,5,6,7,8,9,10,11,12} +do_execsql_test func9-140 { + SELECT concat_ws(NULL,1,2,3,4,5,6,7,8,NULL,9,10,11,12); +} {{}} +do_catchsql_test func9-150 { + SELECT concat_ws(); +} {1 {wrong number of arguments to function concat_ws()}} +do_catchsql_test func9-160 { + SELECT concat_ws(','); +} {1 {wrong number of arguments to function concat_ws()}} + + +finish_test diff --git a/test/fuzz-oss1.test b/test/fuzz-oss1.test new file mode 100644 index 0000000..46feeb6 --- /dev/null +++ b/test/fuzz-oss1.test @@ -0,0 +1,2007 @@ +# 2012 May 21 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +# NB: Portions of this file are extracted from open-source projects +# covered by permissive licenses. Use of this file for testing is clearly +# allowed. However, do not incorporate the text of this one file into +# end-products without checking the licenses on the open-source projects +# from which this code was extracted. This warning applies to this one +# file only - not the bulk of the SQLite source code and tests. +# +#*********************************************************************** +# +# This file contains large and complex schemas obtained from open-source +# software projects. The schemas are parsed just to make sure that nothing +# breaks in the parser logic. +# +# These tests merely verify that the parse occurs without error. +# No attempt is made to verify correct operation of the resulting schema +# and statements. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Schema and query extracted from Skrooge.org. +# +do_test fuzz-oss1-skrooge { + db eval { +CREATE TABLE parameters (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,t_uuid_parent TEXT NOT NULL DEFAULT '',t_name TEXT NOT NULL,t_value TEXT NOT NULL DEFAULT '',b_blob BLOB,d_lastmodifdate DATE NOT NULL DEFAULT CURRENT_TIMESTAMP,i_tmp INTEGER NOT NULL DEFAULT 0); +CREATE TABLE doctransaction (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,t_name TEXT NOT NULL,t_mode VARCHAR(1) DEFAULT 'U' CHECK (t_mode IN ('U', 'R')),d_date DATE NOT NULL,t_savestep VARCHAR(1) DEFAULT 'N' CHECK (t_savestep IN ('Y', 'N')),i_parent INTEGER, t_refreshviews VARCHAR(1) DEFAULT 'Y' CHECK (t_refreshviews IN ('Y', 'N'))); +CREATE TABLE doctransactionitem (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, rd_doctransaction_id INTEGER NOT NULL,i_object_id INTEGER NOT NULL,t_object_table TEXT NOT NULL,t_action VARCHAR(1) DEFAULT 'I' CHECK (t_action IN ('I', 'U', 'D')),t_sqlorder TEXT NOT NULL DEFAULT ''); +CREATE TABLE doctransactionmsg (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, rd_doctransaction_id INTEGER NOT NULL,t_message TEXT NOT NULL DEFAULT '',t_popup VARCHAR(1) DEFAULT 'Y' CHECK (t_popup IN ('Y', 'N'))); +CREATE TABLE unit(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,t_name TEXT NOT NULL,t_symbol TEXT NOT NULL DEFAULT '',t_country TEXT NOT NULL DEFAULT '',t_type VARCHAR(1) NOT NULL DEFAULT 'C' CHECK (t_type IN ('1', '2', 'C', 'S', 'I', 'O')),t_internet_code TEXT NOT NULL DEFAULT '',i_nbdecimal INT NOT NULL DEFAULT 2,rd_unit_id INTEGER NOT NULL DEFAULT 0, t_source TEXT NOT NULL DEFAULT ''); +CREATE TABLE unitvalue(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,rd_unit_id INTEGER NOT NULL,d_date DATE NOT NULL,f_quantity FLOAT NOT NULL CHECK (f_quantity>=0)); +CREATE TABLE bank (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,t_name TEXT NOT NULL DEFAULT '',t_bank_number TEXT NOT NULL DEFAULT '',t_icon TEXT NOT NULL DEFAULT ''); +CREATE TABLE interest(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,rd_account_id INTEGER NOT NULL,d_date DATE NOT NULL,f_rate FLOAT NOT NULL CHECK (f_rate>=0),t_income_value_date_mode VARCHAR(1) NOT NULL DEFAULT 'F' CHECK (t_income_value_date_mode IN ('F', '0', '1', '2', '3', '4', '5')),t_expenditure_value_date_mode VARCHAR(1) NOT NULL DEFAULT 'F' CHECK (t_expenditure_value_date_mode IN ('F', '0', '1', '2', '3', '4', '5')),t_base VARCHAR(3) NOT NULL DEFAULT '24' CHECK (t_base IN ('24', '360', '365'))); +CREATE TABLE operation(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,i_group_id INTEGER NOT NULL DEFAULT 0,i_number INTEGER DEFAULT 0 CHECK (i_number>=0),d_date DATE NOT NULL DEFAULT '0000-00-00',rd_account_id INTEGER NOT NULL,t_mode TEXT NOT NULL DEFAULT '',r_payee_id INTEGER NOT NULL DEFAULT 0,t_comment TEXT NOT NULL DEFAULT '',rc_unit_id INTEGER NOT NULL,t_status VARCHAR(1) NOT NULL DEFAULT 'N' CHECK (t_status IN ('N', 'P', 'Y')),t_bookmarked VARCHAR(1) NOT NULL DEFAULT 'N' CHECK (t_bookmarked IN ('Y', 'N')),t_imported VARCHAR(1) NOT NULL DEFAULT 'N' CHECK (t_imported IN ('Y', 'N', 'P', 'T')),t_template VARCHAR(1) NOT NULL DEFAULT 'N' CHECK (t_template IN ('Y', 'N')),t_import_id TEXT NOT NULL DEFAULT '',i_tmp INTEGER NOT NULL DEFAULT 0,r_recurrentoperation_id INTEGER NOT NULL DEFAULT 0); +CREATE TABLE operationbalance(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,f_balance FLOAT NOT NULL DEFAULT 0,r_operation_id INTEGER NOT NULL); +CREATE TABLE refund (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,t_name TEXT NOT NULL DEFAULT '',t_comment TEXT NOT NULL DEFAULT '',t_close VARCHAR(1) DEFAULT 'N' CHECK (t_close IN ('Y', 'N'))); +CREATE TABLE payee (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,t_name TEXT NOT NULL DEFAULT '',t_address TEXT NOT NULL DEFAULT '', t_bookmarked VARCHAR(1) NOT NULL DEFAULT 'N' CHECK (t_bookmarked IN ('Y', 'N'))); +CREATE TABLE suboperation(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,t_comment TEXT NOT NULL DEFAULT '',rd_operation_id INTEGER NOT NULL,r_category_id INTEGER NOT NULL DEFAULT 0,f_value FLOAT NOT NULL DEFAULT 0.0,i_tmp INTEGER NOT NULL DEFAULT 0,r_refund_id INTEGER NOT NULL DEFAULT 0, t_formula TEXT NOT NULL DEFAULT ''); +CREATE TABLE rule (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,t_description TEXT NOT NULL DEFAULT '',t_definition TEXT NOT NULL DEFAULT '',t_action_description TEXT NOT NULL DEFAULT '',t_action_definition TEXT NOT NULL DEFAULT '',t_action_type VARCHAR(1) DEFAULT 'S' CHECK (t_action_type IN ('S', 'U', 'A')),t_bookmarked VARCHAR(1) NOT NULL DEFAULT 'N' CHECK (t_bookmarked IN ('Y', 'N')),f_sortorder FLOAT); +CREATE TABLE budget (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,rc_category_id INTEGER NOT NULL DEFAULT 0,t_including_subcategories TEXT NOT NULL DEFAULT 'N' CHECK (t_including_subcategories IN ('Y', 'N')),f_budgeted FLOAT NOT NULL DEFAULT 0.0,f_budgeted_modified FLOAT NOT NULL DEFAULT 0.0,f_transferred FLOAT NOT NULL DEFAULT 0.0,i_year INTEGER NOT NULL DEFAULT 2010,i_month INTEGER NOT NULL DEFAULT 0 CHECK (i_month>=0 AND i_month<=12)); +CREATE TABLE budgetcategory(id INTEGER NOT NULL DEFAULT 0,id_category INTEGER NOT NULL DEFAULT 0); +CREATE TABLE budgetrule (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,rc_category_id INTEGER NOT NULL DEFAULT 0,t_category_condition TEXT NOT NULL DEFAULT 'Y' CHECK (t_category_condition IN ('Y', 'N')),t_year_condition TEXT NOT NULL DEFAULT 'Y' CHECK (t_year_condition IN ('Y', 'N')),i_year INTEGER NOT NULL DEFAULT 2010,i_month INTEGER NOT NULL DEFAULT 0 CHECK (i_month>=0 AND i_month<=12),t_month_condition TEXT NOT NULL DEFAULT 'Y' CHECK (t_month_condition IN ('Y', 'N')),i_condition INTEGER NOT NULL DEFAULT 0 CHECK (i_condition IN (-1,0,1)),f_quantity FLOAT NOT NULL DEFAULT 0.0,t_absolute TEXT NOT NULL DEFAULT 'Y' CHECK (t_absolute IN ('Y', 'N')),rc_category_id_target INTEGER NOT NULL DEFAULT 0,t_category_target TEXT NOT NULL DEFAULT 'Y' CHECK (t_category_target IN ('Y', 'N')),t_rule TEXT NOT NULL DEFAULT 'N' CHECK (t_rule IN ('N', 'C', 'Y'))); +CREATE TABLE "recurrentoperation" (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,d_date DATE NOT NULL DEFAULT '0000-00-00',rd_operation_id INTEGER NOT NULL,i_period_increment INTEGER NOT NULL DEFAULT 1 CHECK (i_period_increment>=0),t_period_unit TEXT NOT NULL DEFAULT 'M' CHECK (t_period_unit IN ('D', 'W', 'M', 'Y')),t_auto_write VARCHAR(1) DEFAULT 'Y' CHECK (t_auto_write IN ('Y', 'N')),i_auto_write_days INTEGER NOT NULL DEFAULT 5 CHECK (i_auto_write_days>=0),t_warn VARCHAR(1) DEFAULT 'Y' CHECK (t_warn IN ('Y', 'N')),i_warn_days INTEGER NOT NULL DEFAULT 5 CHECK (i_warn_days>=0),t_times VARCHAR(1) DEFAULT 'N' CHECK (t_times IN ('Y', 'N')),i_nb_times INTEGER NOT NULL DEFAULT 1 CHECK (i_nb_times>=0)); +CREATE TABLE "category" (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,t_name TEXT NOT NULL DEFAULT '' CHECK (t_name NOT LIKE '% > %'),t_fullname TEXT,rd_category_id INT,t_bookmarked VARCHAR(1) NOT NULL DEFAULT 'N' CHECK (t_bookmarked IN ('Y', 'N'))); +CREATE TABLE "account"(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,t_name TEXT NOT NULL,t_number TEXT NOT NULL DEFAULT '',t_agency_number TEXT NOT NULL DEFAULT '',t_agency_address TEXT NOT NULL DEFAULT '',t_comment TEXT NOT NULL DEFAULT '',t_close VARCHAR(1) DEFAULT 'N' CHECK (t_close IN ('Y', 'N')),t_type VARCHAR(1) NOT NULL DEFAULT 'C' CHECK (t_type IN ('C', 'D', 'A', 'I', 'L', 'W', 'O')),t_bookmarked VARCHAR(1) NOT NULL DEFAULT 'N' CHECK (t_bookmarked IN ('Y', 'N')),rd_bank_id INTEGER NOT NULL); +CREATE TABLE "node" (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,t_name TEXT NOT NULL DEFAULT '' CHECK (t_name NOT LIKE '% > %'),t_fullname TEXT,t_icon TEXT DEFAULT '',f_sortorder FLOAT,t_autostart VARCHAR(1) DEFAULT 'N' CHECK (t_autostart IN ('Y', 'N')),t_data TEXT,rd_node_id INT CONSTRAINT fk_id REFERENCES node(id) ON DELETE CASCADE); +CREATE TABLE vm_category_display_tmp( + id INT, + t_name TEXT, + t_fullname TEXT, + rd_category_id INT, + t_bookmarked TEXT, + i_NBOPERATIONS, + f_REALCURRENTAMOUNT +); +CREATE TABLE vm_budget_tmp( + id INT, + rc_category_id INT, + t_including_subcategories TEXT, + f_budgeted REAL, + f_budgeted_modified REAL, + f_transferred REAL, + i_year INT, + i_month INT, + t_CATEGORY, + t_PERIOD, + f_CURRENTAMOUNT, + t_RULES +); +CREATE INDEX idx_doctransaction_parent ON doctransaction (i_parent); +CREATE INDEX idx_doctransactionitem_i_object_id ON doctransactionitem (i_object_id); +CREATE INDEX idx_doctransactionitem_t_object_table ON doctransactionitem (t_object_table); +CREATE INDEX idx_doctransactionitem_t_action ON doctransactionitem (t_action); +CREATE INDEX idx_doctransactionitem_rd_doctransaction_id ON doctransactionitem (rd_doctransaction_id); +CREATE INDEX idx_doctransactionitem_optimization ON doctransactionitem (rd_doctransaction_id, i_object_id, t_object_table, t_action, id); +CREATE INDEX idx_unit_unit_id ON unitvalue(rd_unit_id); +CREATE INDEX idx_account_bank_id ON account(rd_bank_id); +CREATE INDEX idx_account_type ON account(t_type); +CREATE INDEX idx_category_category_id ON category(rd_category_id); +CREATE INDEX idx_category_t_fullname ON category(t_fullname); +CREATE INDEX idx_operation_account_id ON operation (rd_account_id); +CREATE INDEX idx_operation_tmp1_found_transfert ON operation (rc_unit_id, d_date); +CREATE INDEX idx_operation_grouped_operation_id ON operation (i_group_id); +CREATE INDEX idx_operation_i_number ON operation (i_number); +CREATE INDEX idx_operation_i_tmp ON operation (i_tmp); +CREATE INDEX idx_operation_rd_account_id ON operation (rd_account_id); +CREATE INDEX idx_operation_rc_unit_id ON operation (rc_unit_id); +CREATE INDEX idx_operation_t_status ON operation (t_status); +CREATE INDEX idx_operation_t_import_id ON operation (t_import_id); +CREATE INDEX idx_operation_t_template ON operation (t_template); +CREATE INDEX idx_operation_d_date ON operation (d_date); +CREATE INDEX idx_operationbalance_operation_id ON operationbalance (r_operation_id); +CREATE INDEX idx_suboperation_operation_id ON suboperation (rd_operation_id); +CREATE INDEX idx_suboperation_i_tmp ON suboperation (i_tmp); +CREATE INDEX idx_suboperation_category_id ON suboperation (r_category_id); +CREATE INDEX idx_suboperation_refund_id_id ON suboperation (r_refund_id); +CREATE INDEX idx_recurrentoperation_rd_operation_id ON recurrentoperation (rd_operation_id); +CREATE INDEX idx_refund_close ON refund(t_close); +CREATE INDEX idx_interest_account_id ON interest (rd_account_id); +CREATE INDEX idx_rule_action_type ON rule(t_action_type); +CREATE INDEX idx_budget_category_id ON budget(rc_category_id); +CREATE INDEX idx_budgetcategory_id ON budgetcategory (id); +CREATE INDEX idx_budgetcategory_id_category ON budgetcategory (id_category); +CREATE UNIQUE INDEX uidx_parameters_uuid_parent_name ON parameters (t_uuid_parent, t_name); +CREATE UNIQUE INDEX uidx_node_parent_id_name ON node(t_name,rd_node_id); +CREATE UNIQUE INDEX uidx_node_fullname ON node(t_fullname); +CREATE UNIQUE INDEX uidx_unit_name ON unit(t_name); +CREATE UNIQUE INDEX uidx_unit_symbol ON unit(t_symbol); +CREATE UNIQUE INDEX uidx_unitvalue ON unitvalue(d_date,rd_unit_id); +CREATE UNIQUE INDEX uidx_bank_name ON bank(t_name); +CREATE UNIQUE INDEX uidx_account_name ON account(t_name); +CREATE UNIQUE INDEX uidx_category_parent_id_name ON category(t_name,rd_category_id); +CREATE UNIQUE INDEX uidx_category_fullname ON category(t_fullname); +CREATE UNIQUE INDEX uidx_refund_name ON refund(t_name); +CREATE UNIQUE INDEX uidx_payee_name ON payee(t_name); +CREATE UNIQUE INDEX uidx_interest ON interest(d_date,rd_account_id); +CREATE UNIQUE INDEX uidx_budget ON budget(i_year,i_month, rc_category_id); +CREATE VIEW v_node AS SELECT * from node; +CREATE VIEW v_node_displayname AS SELECT *, t_fullname AS t_displayname from node; +CREATE VIEW v_parameters_displayname AS SELECT *, t_name AS t_displayname from parameters; +CREATE TRIGGER fkdc_parameters_parameters_uuid BEFORE DELETE ON parameters FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'parameters'; END; +CREATE TRIGGER fkdc_node_parameters_uuid BEFORE DELETE ON node FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'node'; END; +CREATE TRIGGER cpt_node_fullname1 AFTER INSERT ON node BEGIN UPDATE node SET t_fullname=CASE WHEN new.rd_node_id IS NULL OR new.rd_node_id='' OR new.rd_node_id=0 THEN new.t_name ELSE (SELECT c.t_fullname from node c where c.id=new.rd_node_id)||' > '||new.t_name END WHERE id=new.id;END; +CREATE TRIGGER cpt_node_fullname2 AFTER UPDATE OF t_name, rd_node_id ON node BEGIN UPDATE node SET t_fullname=CASE WHEN new.rd_node_id IS NULL OR new.rd_node_id='' OR new.rd_node_id=0 THEN new.t_name ELSE (SELECT c.t_fullname from node c where c.id=new.rd_node_id)||' > '||new.t_name END WHERE id=new.id;UPDATE node SET t_name=t_name WHERE rd_node_id=new.id;END; +CREATE TRIGGER fki_account_bank_rd_bank_id_id BEFORE INSERT ON account FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (bank est utilisé par account) +Nom de la contrainte : fki_account_bank_rd_bank_id_id') WHERE NEW.rd_bank_id!=0 AND NEW.rd_bank_id!='' AND (SELECT id FROM bank WHERE id = NEW.rd_bank_id) IS NULL; END; +CREATE TRIGGER fku_account_bank_rd_bank_id_id BEFORE UPDATE ON account FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (bank est utilisé par account) +Nom de la contrainte : fku_account_bank_rd_bank_id_id') WHERE NEW.rd_bank_id!=0 AND NEW.rd_bank_id!='' AND (SELECT id FROM bank WHERE id = NEW.rd_bank_id) IS NULL; END; +CREATE TRIGGER fkdc_bank_account_id_rd_bank_id BEFORE DELETE ON bank FOR EACH ROW BEGIN DELETE FROM account WHERE account.rd_bank_id = OLD.id; END; +CREATE TRIGGER fki_budget_category_rc_category_id_id BEFORE INSERT ON budget FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (category est utilisé par budget) +Nom de la contrainte : fki_budget_category_rc_category_id_id') WHERE NEW.rc_category_id!=0 AND NEW.rc_category_id!='' AND (SELECT id FROM category WHERE id = NEW.rc_category_id) IS NULL; END; +CREATE TRIGGER fku_budget_category_rc_category_id_id BEFORE UPDATE ON budget FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (category est utilisé par budget) +Nom de la contrainte : fku_budget_category_rc_category_id_id') WHERE NEW.rc_category_id!=0 AND NEW.rc_category_id!='' AND (SELECT id FROM category WHERE id = NEW.rc_category_id) IS NULL; END; +CREATE TRIGGER fkd_budget_category_rc_category_id_id BEFORE DELETE ON category FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de détruire un objet (category est utilisé par budget) +Nom de la contrainte : fkd_budget_category_rc_category_id_id') WHERE (SELECT rc_category_id FROM budget WHERE rc_category_id = OLD.id) IS NOT NULL; END; +CREATE TRIGGER fki_budgetrule_category_rc_category_id_id BEFORE INSERT ON budgetrule FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (category est utilisé par budgetrule) +Nom de la contrainte : fki_budgetrule_category_rc_category_id_id') WHERE NEW.rc_category_id!=0 AND NEW.rc_category_id!='' AND (SELECT id FROM category WHERE id = NEW.rc_category_id) IS NULL; END; +CREATE TRIGGER fku_budgetrule_category_rc_category_id_id BEFORE UPDATE ON budgetrule FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (category est utilisé par budgetrule) +Nom de la contrainte : fku_budgetrule_category_rc_category_id_id') WHERE NEW.rc_category_id!=0 AND NEW.rc_category_id!='' AND (SELECT id FROM category WHERE id = NEW.rc_category_id) IS NULL; END; +CREATE TRIGGER fkd_budgetrule_category_rc_category_id_id BEFORE DELETE ON category FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de détruire un objet (category est utilisé par budgetrule) +Nom de la contrainte : fkd_budgetrule_category_rc_category_id_id') WHERE (SELECT rc_category_id FROM budgetrule WHERE rc_category_id = OLD.id) IS NOT NULL; END; +CREATE TRIGGER fki_budgetrule_category_rc_category_id_target_id BEFORE INSERT ON budgetrule FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (category est utilisé par budgetrule) +Nom de la contrainte : fki_budgetrule_category_rc_category_id_target_id') WHERE NEW.rc_category_id_target!=0 AND NEW.rc_category_id_target!='' AND (SELECT id FROM category WHERE id = NEW.rc_category_id_target) IS NULL; END; +CREATE TRIGGER fku_budgetrule_category_rc_category_id_target_id BEFORE UPDATE ON budgetrule FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (category est utilisé par budgetrule) +Nom de la contrainte : fku_budgetrule_category_rc_category_id_target_id') WHERE NEW.rc_category_id_target!=0 AND NEW.rc_category_id_target!='' AND (SELECT id FROM category WHERE id = NEW.rc_category_id_target) IS NULL; END; +CREATE TRIGGER fkd_budgetrule_category_rc_category_id_target_id BEFORE DELETE ON category FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de détruire un objet (category est utilisé par budgetrule) +Nom de la contrainte : fkd_budgetrule_category_rc_category_id_target_id') WHERE (SELECT rc_category_id_target FROM budgetrule WHERE rc_category_id_target = OLD.id) IS NOT NULL; END; +CREATE TRIGGER fki_category_category_rd_category_id_id BEFORE INSERT ON category FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (category est utilisé par category) +Nom de la contrainte : fki_category_category_rd_category_id_id') WHERE NEW.rd_category_id!=0 AND NEW.rd_category_id!='' AND (SELECT id FROM category WHERE id = NEW.rd_category_id) IS NULL; END; +CREATE TRIGGER fku_category_category_rd_category_id_id BEFORE UPDATE ON category FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (category est utilisé par category) +Nom de la contrainte : fku_category_category_rd_category_id_id') WHERE NEW.rd_category_id!=0 AND NEW.rd_category_id!='' AND (SELECT id FROM category WHERE id = NEW.rd_category_id) IS NULL; END; +CREATE TRIGGER fkdc_category_category_id_rd_category_id BEFORE DELETE ON category FOR EACH ROW BEGIN DELETE FROM category WHERE category.rd_category_id = OLD.id; END; +CREATE TRIGGER fki_doctransactionitem_doctransaction_rd_doctransaction_id_id BEFORE INSERT ON doctransactionitem FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (doctransaction est utilisé par doctransactionitem) +Nom de la contrainte : fki_doctransactionitem_doctransaction_rd_doctransaction_id_id') WHERE NEW.rd_doctransaction_id!=0 AND NEW.rd_doctransaction_id!='' AND (SELECT id FROM doctransaction WHERE id = NEW.rd_doctransaction_id) IS NULL; END; +CREATE TRIGGER fku_doctransactionitem_doctransaction_rd_doctransaction_id_id BEFORE UPDATE ON doctransactionitem FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (doctransaction est utilisé par doctransactionitem) +Nom de la contrainte : fku_doctransactionitem_doctransaction_rd_doctransaction_id_id') WHERE NEW.rd_doctransaction_id!=0 AND NEW.rd_doctransaction_id!='' AND (SELECT id FROM doctransaction WHERE id = NEW.rd_doctransaction_id) IS NULL; END; +CREATE TRIGGER fkdc_doctransaction_doctransactionitem_id_rd_doctransaction_id BEFORE DELETE ON doctransaction FOR EACH ROW BEGIN DELETE FROM doctransactionitem WHERE doctransactionitem.rd_doctransaction_id = OLD.id; END; +CREATE TRIGGER fki_doctransactionmsg_doctransaction_rd_doctransaction_id_id BEFORE INSERT ON doctransactionmsg FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (doctransaction est utilisé par doctransactionmsg) +Nom de la contrainte : fki_doctransactionmsg_doctransaction_rd_doctransaction_id_id') WHERE NEW.rd_doctransaction_id!=0 AND NEW.rd_doctransaction_id!='' AND (SELECT id FROM doctransaction WHERE id = NEW.rd_doctransaction_id) IS NULL; END; +CREATE TRIGGER fku_doctransactionmsg_doctransaction_rd_doctransaction_id_id BEFORE UPDATE ON doctransactionmsg FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (doctransaction est utilisé par doctransactionmsg) +Nom de la contrainte : fku_doctransactionmsg_doctransaction_rd_doctransaction_id_id') WHERE NEW.rd_doctransaction_id!=0 AND NEW.rd_doctransaction_id!='' AND (SELECT id FROM doctransaction WHERE id = NEW.rd_doctransaction_id) IS NULL; END; +CREATE TRIGGER fkdc_doctransaction_doctransactionmsg_id_rd_doctransaction_id BEFORE DELETE ON doctransaction FOR EACH ROW BEGIN DELETE FROM doctransactionmsg WHERE doctransactionmsg.rd_doctransaction_id = OLD.id; END; +CREATE TRIGGER fki_interest_account_rd_account_id_id BEFORE INSERT ON interest FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (account est utilisé par interest) +Nom de la contrainte : fki_interest_account_rd_account_id_id') WHERE NEW.rd_account_id!=0 AND NEW.rd_account_id!='' AND (SELECT id FROM account WHERE id = NEW.rd_account_id) IS NULL; END; +CREATE TRIGGER fku_interest_account_rd_account_id_id BEFORE UPDATE ON interest FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (account est utilisé par interest) +Nom de la contrainte : fku_interest_account_rd_account_id_id') WHERE NEW.rd_account_id!=0 AND NEW.rd_account_id!='' AND (SELECT id FROM account WHERE id = NEW.rd_account_id) IS NULL; END; +CREATE TRIGGER fkdc_account_interest_id_rd_account_id BEFORE DELETE ON account FOR EACH ROW BEGIN DELETE FROM interest WHERE interest.rd_account_id = OLD.id; END; +CREATE TRIGGER fki_node_node_rd_node_id_id BEFORE INSERT ON node FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (node est utilisé par node) +Nom de la contrainte : fki_node_node_rd_node_id_id') WHERE NEW.rd_node_id!=0 AND NEW.rd_node_id!='' AND (SELECT id FROM node WHERE id = NEW.rd_node_id) IS NULL; END; +CREATE TRIGGER fku_node_node_rd_node_id_id BEFORE UPDATE ON node FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (node est utilisé par node) +Nom de la contrainte : fku_node_node_rd_node_id_id') WHERE NEW.rd_node_id!=0 AND NEW.rd_node_id!='' AND (SELECT id FROM node WHERE id = NEW.rd_node_id) IS NULL; END; +CREATE TRIGGER fkdc_node_node_id_rd_node_id BEFORE DELETE ON node FOR EACH ROW BEGIN DELETE FROM node WHERE node.rd_node_id = OLD.id; END; +CREATE TRIGGER fki_operation_account_rd_account_id_id BEFORE INSERT ON operation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (account est utilisé par operation) +Nom de la contrainte : fki_operation_account_rd_account_id_id') WHERE NEW.rd_account_id!=0 AND NEW.rd_account_id!='' AND (SELECT id FROM account WHERE id = NEW.rd_account_id) IS NULL; END; +CREATE TRIGGER fku_operation_account_rd_account_id_id BEFORE UPDATE ON operation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (account est utilisé par operation) +Nom de la contrainte : fku_operation_account_rd_account_id_id') WHERE NEW.rd_account_id!=0 AND NEW.rd_account_id!='' AND (SELECT id FROM account WHERE id = NEW.rd_account_id) IS NULL; END; +CREATE TRIGGER fkdc_account_operation_id_rd_account_id BEFORE DELETE ON account FOR EACH ROW BEGIN DELETE FROM operation WHERE operation.rd_account_id = OLD.id; END; +CREATE TRIGGER fki_operation_payee_r_payee_id_id BEFORE INSERT ON operation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (payee est utilisé par operation) +Nom de la contrainte : fki_operation_payee_r_payee_id_id') WHERE NEW.r_payee_id!=0 AND NEW.r_payee_id!='' AND (SELECT id FROM payee WHERE id = NEW.r_payee_id) IS NULL; END; +CREATE TRIGGER fku_operation_payee_r_payee_id_id BEFORE UPDATE ON operation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (payee est utilisé par operation) +Nom de la contrainte : fku_operation_payee_r_payee_id_id') WHERE NEW.r_payee_id!=0 AND NEW.r_payee_id!='' AND (SELECT id FROM payee WHERE id = NEW.r_payee_id) IS NULL; END; +CREATE TRIGGER fkd_operation_payee_r_payee_id_id BEFORE DELETE ON payee FOR EACH ROW BEGIN UPDATE operation SET r_payee_id=0 WHERE r_payee_id=OLD.id; END; +CREATE TRIGGER fki_operation_unit_rc_unit_id_id BEFORE INSERT ON operation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (unit est utilisé par operation) +Nom de la contrainte : fki_operation_unit_rc_unit_id_id') WHERE NEW.rc_unit_id!=0 AND NEW.rc_unit_id!='' AND (SELECT id FROM unit WHERE id = NEW.rc_unit_id) IS NULL; END; +CREATE TRIGGER fku_operation_unit_rc_unit_id_id BEFORE UPDATE ON operation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (unit est utilisé par operation) +Nom de la contrainte : fku_operation_unit_rc_unit_id_id') WHERE NEW.rc_unit_id!=0 AND NEW.rc_unit_id!='' AND (SELECT id FROM unit WHERE id = NEW.rc_unit_id) IS NULL; END; +CREATE TRIGGER fkd_operation_unit_rc_unit_id_id BEFORE DELETE ON unit FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de détruire un objet (unit est utilisé par operation) +Nom de la contrainte : fkd_operation_unit_rc_unit_id_id') WHERE (SELECT rc_unit_id FROM operation WHERE rc_unit_id = OLD.id) IS NOT NULL; END; +CREATE TRIGGER fki_operation_recurrentoperation_r_recurrentoperation_id_id BEFORE INSERT ON operation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (recurrentoperation est utilisé par operation) +Nom de la contrainte : fki_operation_recurrentoperation_r_recurrentoperation_id_id') WHERE NEW.r_recurrentoperation_id!=0 AND NEW.r_recurrentoperation_id!='' AND (SELECT id FROM recurrentoperation WHERE id = NEW.r_recurrentoperation_id) IS NULL; END; +CREATE TRIGGER fku_operation_recurrentoperation_r_recurrentoperation_id_id BEFORE UPDATE ON operation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (recurrentoperation est utilisé par operation) +Nom de la contrainte : fku_operation_recurrentoperation_r_recurrentoperation_id_id') WHERE NEW.r_recurrentoperation_id!=0 AND NEW.r_recurrentoperation_id!='' AND (SELECT id FROM recurrentoperation WHERE id = NEW.r_recurrentoperation_id) IS NULL; END; +CREATE TRIGGER fkd_operation_recurrentoperation_r_recurrentoperation_id_id BEFORE DELETE ON recurrentoperation FOR EACH ROW BEGIN UPDATE operation SET r_recurrentoperation_id=0 WHERE r_recurrentoperation_id=OLD.id; END; +CREATE TRIGGER fki_operationbalance_operation_r_operation_id_id BEFORE INSERT ON operationbalance FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (operation est utilisé par operationbalance) +Nom de la contrainte : fki_operationbalance_operation_r_operation_id_id') WHERE NEW.r_operation_id!=0 AND NEW.r_operation_id!='' AND (SELECT id FROM operation WHERE id = NEW.r_operation_id) IS NULL; END; +CREATE TRIGGER fku_operationbalance_operation_r_operation_id_id BEFORE UPDATE ON operationbalance FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (operation est utilisé par operationbalance) +Nom de la contrainte : fku_operationbalance_operation_r_operation_id_id') WHERE NEW.r_operation_id!=0 AND NEW.r_operation_id!='' AND (SELECT id FROM operation WHERE id = NEW.r_operation_id) IS NULL; END; +CREATE TRIGGER fkd_operationbalance_operation_r_operation_id_id BEFORE DELETE ON operation FOR EACH ROW BEGIN UPDATE operationbalance SET r_operation_id=0 WHERE r_operation_id=OLD.id; END; +CREATE TRIGGER fki_recurrentoperation_operation_rd_operation_id_id BEFORE INSERT ON recurrentoperation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (operation est utilisé par recurrentoperation) +Nom de la contrainte : fki_recurrentoperation_operation_rd_operation_id_id') WHERE NEW.rd_operation_id!=0 AND NEW.rd_operation_id!='' AND (SELECT id FROM operation WHERE id = NEW.rd_operation_id) IS NULL; END; +CREATE TRIGGER fku_recurrentoperation_operation_rd_operation_id_id BEFORE UPDATE ON recurrentoperation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (operation est utilisé par recurrentoperation) +Nom de la contrainte : fku_recurrentoperation_operation_rd_operation_id_id') WHERE NEW.rd_operation_id!=0 AND NEW.rd_operation_id!='' AND (SELECT id FROM operation WHERE id = NEW.rd_operation_id) IS NULL; END; +CREATE TRIGGER fkdc_operation_recurrentoperation_id_rd_operation_id BEFORE DELETE ON operation FOR EACH ROW BEGIN DELETE FROM recurrentoperation WHERE recurrentoperation.rd_operation_id = OLD.id; END; +CREATE TRIGGER fki_suboperation_operation_rd_operation_id_id BEFORE INSERT ON suboperation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (operation est utilisé par suboperation) +Nom de la contrainte : fki_suboperation_operation_rd_operation_id_id') WHERE NEW.rd_operation_id!=0 AND NEW.rd_operation_id!='' AND (SELECT id FROM operation WHERE id = NEW.rd_operation_id) IS NULL; END; +CREATE TRIGGER fku_suboperation_operation_rd_operation_id_id BEFORE UPDATE ON suboperation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (operation est utilisé par suboperation) +Nom de la contrainte : fku_suboperation_operation_rd_operation_id_id') WHERE NEW.rd_operation_id!=0 AND NEW.rd_operation_id!='' AND (SELECT id FROM operation WHERE id = NEW.rd_operation_id) IS NULL; END; +CREATE TRIGGER fkdc_operation_suboperation_id_rd_operation_id BEFORE DELETE ON operation FOR EACH ROW BEGIN DELETE FROM suboperation WHERE suboperation.rd_operation_id = OLD.id; END; +CREATE TRIGGER fki_suboperation_category_r_category_id_id BEFORE INSERT ON suboperation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (category est utilisé par suboperation) +Nom de la contrainte : fki_suboperation_category_r_category_id_id') WHERE NEW.r_category_id!=0 AND NEW.r_category_id!='' AND (SELECT id FROM category WHERE id = NEW.r_category_id) IS NULL; END; +CREATE TRIGGER fku_suboperation_category_r_category_id_id BEFORE UPDATE ON suboperation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (category est utilisé par suboperation) +Nom de la contrainte : fku_suboperation_category_r_category_id_id') WHERE NEW.r_category_id!=0 AND NEW.r_category_id!='' AND (SELECT id FROM category WHERE id = NEW.r_category_id) IS NULL; END; +CREATE TRIGGER fkd_suboperation_category_r_category_id_id BEFORE DELETE ON category FOR EACH ROW BEGIN UPDATE suboperation SET r_category_id=0 WHERE r_category_id=OLD.id; END; +CREATE TRIGGER fki_suboperation_refund_r_refund_id_id BEFORE INSERT ON suboperation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (refund est utilisé par suboperation) +Nom de la contrainte : fki_suboperation_refund_r_refund_id_id') WHERE NEW.r_refund_id!=0 AND NEW.r_refund_id!='' AND (SELECT id FROM refund WHERE id = NEW.r_refund_id) IS NULL; END; +CREATE TRIGGER fku_suboperation_refund_r_refund_id_id BEFORE UPDATE ON suboperation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (refund est utilisé par suboperation) +Nom de la contrainte : fku_suboperation_refund_r_refund_id_id') WHERE NEW.r_refund_id!=0 AND NEW.r_refund_id!='' AND (SELECT id FROM refund WHERE id = NEW.r_refund_id) IS NULL; END; +CREATE TRIGGER fkd_suboperation_refund_r_refund_id_id BEFORE DELETE ON refund FOR EACH ROW BEGIN UPDATE suboperation SET r_refund_id=0 WHERE r_refund_id=OLD.id; END; +CREATE TRIGGER fki_unit_unit_rd_unit_id_id BEFORE INSERT ON unit FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (unit est utilisé par unit) +Nom de la contrainte : fki_unit_unit_rd_unit_id_id') WHERE NEW.rd_unit_id!=0 AND NEW.rd_unit_id!='' AND (SELECT id FROM unit WHERE id = NEW.rd_unit_id) IS NULL; END; +CREATE TRIGGER fku_unit_unit_rd_unit_id_id BEFORE UPDATE ON unit FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (unit est utilisé par unit) +Nom de la contrainte : fku_unit_unit_rd_unit_id_id') WHERE NEW.rd_unit_id!=0 AND NEW.rd_unit_id!='' AND (SELECT id FROM unit WHERE id = NEW.rd_unit_id) IS NULL; END; +CREATE TRIGGER fkdc_unit_unit_id_rd_unit_id BEFORE DELETE ON unit FOR EACH ROW BEGIN DELETE FROM unit WHERE unit.rd_unit_id = OLD.id; END; +CREATE TRIGGER fki_unitvalue_unit_rd_unit_id_id BEFORE INSERT ON unitvalue FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (unit est utilisé par unitvalue) +Nom de la contrainte : fki_unitvalue_unit_rd_unit_id_id') WHERE NEW.rd_unit_id!=0 AND NEW.rd_unit_id!='' AND (SELECT id FROM unit WHERE id = NEW.rd_unit_id) IS NULL; END; +CREATE TRIGGER fku_unitvalue_unit_rd_unit_id_id BEFORE UPDATE ON unitvalue FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (unit est utilisé par unitvalue) +Nom de la contrainte : fku_unitvalue_unit_rd_unit_id_id') WHERE NEW.rd_unit_id!=0 AND NEW.rd_unit_id!='' AND (SELECT id FROM unit WHERE id = NEW.rd_unit_id) IS NULL; END; +CREATE TRIGGER fkdc_unit_unitvalue_id_rd_unit_id BEFORE DELETE ON unit FOR EACH ROW BEGIN DELETE FROM unitvalue WHERE unitvalue.rd_unit_id = OLD.id; END; +CREATE TRIGGER fkd_vm_budget_tmp_category_rc_category_id_id BEFORE DELETE ON category FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de détruire un objet (category est utilisé par vm_budget_tmp) +Nom de la contrainte : fkd_vm_budget_tmp_category_rc_category_id_id') WHERE (SELECT rc_category_id FROM vm_budget_tmp WHERE rc_category_id = OLD.id) IS NOT NULL; END; +CREATE TRIGGER fkdc_category_vm_category_display_tmp_id_rd_category_id BEFORE DELETE ON category FOR EACH ROW BEGIN DELETE FROM vm_category_display_tmp WHERE vm_category_display_tmp.rd_category_id = OLD.id; END; +CREATE VIEW v_unit_displayname AS SELECT *, t_name||' ('||t_symbol||')' AS t_displayname FROM unit; +CREATE VIEW v_unit_tmp1 AS SELECT *,(SELECT count(*) FROM unitvalue s WHERE s.rd_unit_id=unit.id) AS i_NBVALUES, (CASE WHEN unit.rd_unit_id=0 THEN '' ELSE (SELECT (CASE WHEN s.t_symbol!='' THEN s.t_symbol ELSE s.t_name END) FROM unit s WHERE s.id=unit.rd_unit_id) END) AS t_UNIT,(CASE unit.t_type WHEN '1' THEN 'Monnaie principale' WHEN '2' THEN 'Monnaie secondaire' WHEN 'C' THEN 'Monnaie' WHEN 'S' THEN 'Action' WHEN 'I' THEN 'Indice' ELSE 'Objet' END) AS t_TYPENLS, (SELECT MIN(s.d_date) FROM unitvalue s WHERE s.rd_unit_id=unit.id) AS d_MINDATE, (SELECT MAX(s.d_date) FROM unitvalue s WHERE s.rd_unit_id=unit.id) AS d_MAXDATE from unit; +CREATE VIEW v_unit_tmp2 AS SELECT *,CASE WHEN v_unit_tmp1.t_type='1' THEN 1 ELSE IFNULL((SELECT s.f_quantity FROM unitvalue s WHERE s.rd_unit_id=v_unit_tmp1.id AND s.d_date=v_unit_tmp1.d_MAXDATE),1) END AS f_LASTVALUE from v_unit_tmp1; +CREATE VIEW v_unit AS SELECT *,v_unit_tmp2.f_LASTVALUE*IFNULL((SELECT s2.f_LASTVALUE FROM v_unit_tmp2 s2 WHERE s2.id=v_unit_tmp2.rd_unit_id) , 1) AS f_CURRENTAMOUNT from v_unit_tmp2; +CREATE VIEW v_unitvalue_displayname AS SELECT *, (SELECT t_displayname FROM v_unit_displayname WHERE unitvalue.rd_unit_id=v_unit_displayname.id)||' '||STRFTIME('%d/%m/%Y',d_date) AS t_displayname FROM unitvalue; +CREATE VIEW v_unitvalue AS SELECT * FROM unitvalue; +CREATE VIEW v_suboperation AS SELECT * FROM suboperation; +CREATE VIEW v_operation_numbers AS SELECT DISTINCT i_number, rd_account_id FROM operation; +CREATE VIEW v_operation_next_numbers AS SELECT T1.i_number+1 AS i_number FROM v_operation_numbers AS T1 LEFT OUTER JOIN v_operation_numbers T2 ON T2.rd_account_id=T1.rd_account_id AND T2.i_number=T1.i_number+1 WHERE T1.i_number!=0 AND (T2.i_number IS NULL) ORDER BY T1.i_number; +CREATE VIEW v_operation_tmp1 AS SELECT *,(SELECT t_name FROM payee s WHERE s.id=operation.r_payee_id) AS t_PAYEE,(SELECT TOTAL(s.f_value) FROM suboperation s WHERE s.rd_operation_id=operation.ID) AS f_QUANTITY,(SELECT count(*) FROM suboperation s WHERE s.rd_operation_id=operation.ID) AS i_NBSUBCATEGORY FROM operation; +CREATE VIEW v_operation AS SELECT *,(SELECT s.id FROM suboperation s WHERE s.rd_operation_id=v_operation_tmp1.id AND ABS(s.f_value)=(SELECT MAX(ABS(s2.f_value)) FROM suboperation s2 WHERE s2.rd_operation_id=v_operation_tmp1.id)) AS i_MOSTIMPSUBOP,((SELECT s.f_CURRENTAMOUNT FROM v_unit s WHERE s.id=v_operation_tmp1.rc_unit_id)*v_operation_tmp1.f_QUANTITY) AS f_CURRENTAMOUNT, (CASE WHEN v_operation_tmp1.i_group_id<>0 AND EXISTS (SELECT 1 FROM account a WHERE v_operation_tmp1.rd_account_id=a.id AND a.t_type<>'L') AND EXISTS (SELECT 1 FROM v_operation_tmp1 op2, account a WHERE op2.i_group_id=v_operation_tmp1.i_group_id AND op2.rd_account_id=a.id AND a.t_type<>'L' AND op2.rc_unit_id=v_operation_tmp1.rc_unit_id AND op2.f_QUANTITY=-v_operation_tmp1.f_QUANTITY) THEN 'Y' ELSE 'N' END) AS t_TRANSFER FROM v_operation_tmp1; +CREATE VIEW v_operation_displayname AS SELECT *, STRFTIME('%d/%m/%Y',d_date)||' '||IFNULL(t_PAYEE,'')||' '||v_operation.f_CURRENTAMOUNT||' '||(SELECT (CASE WHEN s.t_symbol!='' THEN s.t_symbol ELSE s.t_name END) FROM unit s WHERE s.id=v_operation.rc_unit_id) AS t_displayname FROM v_operation; +CREATE VIEW v_operation_delete AS SELECT *, (CASE WHEN t_status='Y' THEN 'Vous n''êtes pas autorisé à détruire cette opération car en état « rapproché »' END) t_delete_message FROM operation; +CREATE VIEW v_account AS SELECT *,(SELECT MAX(s.d_date) FROM interest s WHERE s.rd_account_id=account.id) AS d_MAXDATE, (SELECT TOTAL(s.f_CURRENTAMOUNT) FROM v_operation s WHERE s.rd_account_id=account.id AND s.t_template='N') AS f_CURRENTAMOUNT FROM account; +CREATE VIEW v_account_delete AS SELECT *, (CASE WHEN EXISTS(SELECT 1 FROM operation WHERE rd_account_id=account.id AND d_date<>'0000-00-00' AND t_template='N' AND t_status='Y') THEN 'Vous n''êtes pas autorisé à détruire ce compte car il contient des opérations rapprochées' END) t_delete_message FROM account; +CREATE VIEW v_bank_displayname AS SELECT *, t_name AS t_displayname FROM bank; +CREATE VIEW v_account_displayname AS SELECT *, (SELECT t_displayname FROM v_bank_displayname WHERE account.rd_bank_id=v_bank_displayname.id)||'-'||t_name AS t_displayname FROM account; +CREATE VIEW v_bank AS SELECT *,(SELECT TOTAL(s.f_CURRENTAMOUNT) FROM v_account s WHERE s.rd_bank_id=bank.id) AS f_CURRENTAMOUNT FROM bank; +CREATE VIEW v_category_displayname AS SELECT *, t_fullname AS t_displayname FROM category; +CREATE VIEW v_category AS SELECT * FROM category; +CREATE VIEW v_recurrentoperation AS SELECT *,i_period_increment||' '||(CASE t_period_unit WHEN 'Y' THEN 'année(s)' WHEN 'M' THEN 'mois' WHEN 'W' THEN 'semaine(s)' ELSE 'jour(s)' END) AS t_PERIODNLS FROM recurrentoperation; +CREATE VIEW v_recurrentoperation_displayname AS SELECT *, STRFTIME('%d/%m/%Y',d_date)||' '||SUBSTR((SELECT t_displayname FROM v_operation_displayname WHERE v_operation_displayname.id=v_recurrentoperation.rd_operation_id), 11) AS t_displayname FROM v_recurrentoperation; +CREATE VIEW v_unitvalue_display AS SELECT *,IFNULL((SELECT (CASE WHEN s.t_symbol!='' THEN s.t_symbol ELSE s.t_name END) FROM unit s WHERE s.id=(SELECT s2.rd_unit_id FROM unit s2 WHERE s2.id=unitvalue.rd_unit_id)),'') AS t_UNIT,STRFTIME('%Y-%m',unitvalue.d_date) AS d_DATEMONTH,STRFTIME('%Y',unitvalue.d_date) AS d_DATEYEAR FROM unitvalue; +CREATE VIEW v_suboperation_display AS SELECT *,IFNULL((SELECT s.t_fullname FROM category s WHERE s.id=v_suboperation.r_category_id),'') AS t_CATEGORY, IFNULL((SELECT s.t_name FROM refund s WHERE s.id=v_suboperation.r_refund_id),'') AS t_REFUND, (CASE WHEN v_suboperation.f_value>=0 THEN v_suboperation.f_value ELSE 0 END) AS f_VALUE_INCOME, (CASE WHEN v_suboperation.f_value<=0 THEN v_suboperation.f_value ELSE 0 END) AS f_VALUE_EXPENSE FROM v_suboperation; +CREATE VIEW v_suboperation_displayname AS SELECT *, t_CATEGORY||' : '||f_value AS t_displayname FROM v_suboperation_display; +CREATE VIEW v_operation_display_all AS SELECT *,(SELECT s.t_name FROM account s WHERE s.id=v_operation.rd_account_id) AS t_ACCOUNT,(SELECT (CASE WHEN s.t_symbol!='' THEN s.t_symbol ELSE s.t_name END) FROM unit s WHERE s.id=v_operation.rc_unit_id) AS t_UNIT,(SELECT s.t_CATEGORY FROM v_suboperation_display s WHERE s.id=v_operation.i_MOSTIMPSUBOP) AS t_CATEGORY,(SELECT s.t_REFUND FROM v_suboperation_display s WHERE s.id=v_operation.i_MOSTIMPSUBOP) AS t_REFUND,(CASE WHEN v_operation.f_QUANTITY<0 THEN '-' WHEN v_operation.f_QUANTITY=0 THEN '' ELSE '+' END) AS t_TYPEEXPENSE, (CASE WHEN v_operation.f_QUANTITY<=0 THEN 'Dépense' ELSE 'Revenu' END) AS t_TYPEEXPENSENLS, STRFTIME('%Y-W%W',v_operation.d_date) AS d_DATEWEEK,STRFTIME('%Y-%m',v_operation.d_date) AS d_DATEMONTH,STRFTIME('%Y',v_operation.d_date)||'-Q'||(CASE WHEN STRFTIME('%m',v_operation.d_date)<='03' THEN '1' WHEN STRFTIME('%m',v_operation.d_date)<='06' THEN '2' WHEN STRFTIME('%m',v_operation.d_date)<='09' THEN '3' ELSE '4' END) AS d_DATEQUARTER, STRFTIME('%Y',v_operation.d_date)||'-S'||(CASE WHEN STRFTIME('%m',v_operation.d_date)<='06' THEN '1' ELSE '2' END) AS d_DATESEMESTER, STRFTIME('%Y',v_operation.d_date) AS d_DATEYEAR, (SELECT count(*) FROM v_recurrentoperation s WHERE s.rd_operation_id=v_operation.id) AS i_NBRECURRENT, (CASE WHEN v_operation.f_QUANTITY>=0 THEN v_operation.f_QUANTITY ELSE 0 END) AS f_QUANTITY_INCOME, (CASE WHEN v_operation.f_QUANTITY<=0 THEN v_operation.f_QUANTITY ELSE 0 END) AS f_QUANTITY_EXPENSE, (SELECT o2.f_balance FROM operationbalance o2 WHERE o2.r_operation_id=v_operation.id ) AS f_BALANCE, (CASE WHEN v_operation.f_QUANTITY>=0 THEN v_operation.f_CURRENTAMOUNT ELSE 0 END) AS f_CURRENTAMOUNT_INCOME, (CASE WHEN v_operation.f_QUANTITY<=0 THEN v_operation.f_CURRENTAMOUNT ELSE 0 END) AS f_CURRENTAMOUNT_EXPENSE FROM v_operation; +CREATE VIEW v_operation_template_display AS SELECT * FROM v_operation_display_all WHERE t_template='Y'; +CREATE VIEW v_operation_display AS SELECT * FROM v_operation_display_all WHERE d_date!='0000-00-00' AND t_template='N'; +CREATE VIEW v_unit_display AS SELECT *,(SELECT TOTAL(o.f_QUANTITY) FROM v_operation_display o WHERE o.rc_unit_id=v_unit.id) AS f_QUANTITYOWNED FROM v_unit; +CREATE VIEW v_account_display AS SELECT (CASE t_type WHEN 'C' THEN 'Courant' WHEN 'D' THEN 'Carte de crédit' WHEN 'A' THEN 'Actif' WHEN 'I' THEN 'Investissement' WHEN 'W' THEN 'Portefeuille' WHEN 'L' THEN 'Prêt' WHEN 'O' THEN 'Autre' END) AS t_TYPENLS,bank.t_name AS t_BANK,bank.t_bank_number AS t_BANK_NUMBER,bank.t_icon AS t_ICON,v_account.*,(v_account.f_CURRENTAMOUNT/(SELECT u.f_CURRENTAMOUNT FROM v_unit u, operation s WHERE u.id=s.rc_unit_id AND s.rd_account_id=v_account.id AND s.d_date='0000-00-00')) AS f_QUANTITY, (SELECT (CASE WHEN u.t_symbol!='' THEN u.t_symbol ELSE u.t_name END) FROM unit u, operation s WHERE u.id=s.rc_unit_id AND s.rd_account_id=v_account.id AND s.d_date='0000-00-00') AS t_UNIT, (SELECT TOTAL(s.f_CURRENTAMOUNT) FROM v_operation s WHERE s.rd_account_id=v_account.id AND s.t_status!='N' AND s.t_template='N') AS f_CHECKED, (SELECT TOTAL(s.f_CURRENTAMOUNT) FROM v_operation s WHERE s.rd_account_id=v_account.id AND s.t_status='N' AND s.t_template='N') AS f_COMING_SOON, (SELECT TOTAL(s.f_CURRENTAMOUNT) FROM v_operation s WHERE s.rd_account_id=v_account.id AND s.d_date<=date('now') AND s.t_template='N') AS f_TODAYAMOUNT, (SELECT count(*) FROM v_operation_display s WHERE s.rd_account_id=v_account.id) AS i_NBOPERATIONS, IFNULL((SELECT s.f_rate FROM interest s WHERE s.rd_account_id=v_account.id AND s.d_date=v_account.d_MAXDATE),0) AS f_RATE FROM v_account, bank WHERE bank.id=v_account.rd_bank_id; +CREATE VIEW v_operation_consolidated AS SELECT (SELECT s.t_TYPENLS FROM v_account_display s WHERE s.id=op.rd_account_id) AS t_ACCOUNTTYPE,(SELECT u.t_TYPENLS FROM v_unit u WHERE u.id=op.rc_unit_id) AS t_UNITTYPE,sop.id AS i_SUBOPID, sop.r_refund_id AS r_refund_id, (CASE WHEN sop.t_comment='' THEN op.t_comment ELSE sop.t_comment END) AS t_REALCOMMENT, sop.t_CATEGORY AS t_REALCATEGORY, sop.t_REFUND AS t_REALREFUND, sop.r_category_id AS i_IDCATEGORY, (CASE WHEN sop.f_value<0 THEN '-' WHEN sop.f_value=0 THEN '' ELSE '+' END) AS t_TYPEEXPENSE, (CASE WHEN sop.f_value<0 THEN 'Dépense' WHEN sop.f_value=0 THEN '' ELSE 'Revenu' END) AS t_TYPEEXPENSENLS, sop.f_value AS f_REALQUANTITY, sop.f_VALUE_INCOME AS f_REALQUANTITY_INCOME, sop.f_VALUE_EXPENSE AS f_REALQUANTITY_EXPENSE, ((SELECT u.f_CURRENTAMOUNT FROM v_unit u WHERE u.id=op.rc_unit_id)*sop.f_value) AS f_REALCURRENTAMOUNT, ((SELECT u.f_CURRENTAMOUNT FROM v_unit u WHERE u.id=op.rc_unit_id)*sop.f_VALUE_INCOME) AS f_REALCURRENTAMOUNT_INCOME, ((SELECT u.f_CURRENTAMOUNT FROM v_unit u WHERE u.id=op.rc_unit_id)*sop.f_VALUE_EXPENSE) AS f_REALCURRENTAMOUNT_EXPENSE, op.* FROM v_operation_display_all AS op, v_suboperation_display AS sop WHERE op.t_template='N' AND sop.rd_operation_id=op.ID; +CREATE VIEW v_operation_prop AS SELECT p.id AS i_PROPPID, p.t_name AS i_PROPPNAME, p.t_value AS i_PROPVALUE, op.* FROM v_operation_consolidated AS op LEFT OUTER JOIN parameters AS p ON p.t_uuid_parent=op.id||'-operation'; +CREATE VIEW v_refund_delete AS SELECT *, (CASE WHEN EXISTS(SELECT 1 FROM v_operation_consolidated WHERE r_refund_id=refund.id AND t_status='Y') THEN 'Vous n''êtes pas autorisé à détruire ce suiveur car utilisé par des opérations rapprochées' END) t_delete_message FROM refund; +CREATE VIEW v_refund AS SELECT *, (SELECT TOTAL(o.f_REALCURRENTAMOUNT) FROM v_operation_consolidated o WHERE o.r_refund_id=refund.id) AS f_CURRENTAMOUNT FROM refund; +CREATE VIEW v_refund_display AS SELECT *,(SELECT MIN(o.d_date) FROM v_operation_consolidated o WHERE o.r_refund_id=v_refund.id) AS d_FIRSTDATE, (SELECT MAX(o.d_date) FROM v_operation_consolidated o WHERE o.r_refund_id=v_refund.id) AS d_LASTDATE FROM v_refund; +CREATE VIEW v_refund_displayname AS SELECT *, t_name AS t_displayname FROM refund; +CREATE VIEW v_payee_delete AS SELECT *, (CASE WHEN EXISTS(SELECT 1 FROM operation WHERE r_payee_id=payee.id AND t_status='Y') THEN 'Vous n''êtes pas autorisé à détruire ce tiers car utilisé par des opérations rapprochées' END) t_delete_message FROM payee; +CREATE VIEW v_payee AS SELECT *, (SELECT TOTAL(o.f_CURRENTAMOUNT) FROM v_operation o WHERE o.r_payee_id=payee.id AND o.t_template='N') AS f_CURRENTAMOUNT FROM payee; +CREATE VIEW v_payee_display AS SELECT * FROM v_payee; +CREATE VIEW v_payee_displayname AS SELECT *, t_name AS t_displayname FROM payee; +CREATE VIEW v_category_delete AS SELECT *, (CASE WHEN EXISTS(SELECT 1 FROM v_operation_consolidated WHERE (t_REALCATEGORY=category.t_fullname OR t_REALCATEGORY like category.t_fullname||'%') AND t_status='Y') THEN 'Vous n''êtes pas autorisé à détruire cette catégorie car utilisée par des opérations rapprochées' END) t_delete_message FROM category; +CREATE VIEW v_category_display_tmp AS SELECT *,(SELECT count(distinct(so.rd_operation_id)) FROM operation o, suboperation so WHERE so.rd_operation_id=o.id AND so.r_category_id=v_category.ID AND o.t_template='N') AS i_NBOPERATIONS, (SELECT TOTAL(o.f_REALCURRENTAMOUNT) FROM v_operation_consolidated o WHERE o.i_IDCATEGORY=v_category.ID) AS f_REALCURRENTAMOUNT FROM v_category; +CREATE VIEW v_category_display AS SELECT *,f_REALCURRENTAMOUNT+(SELECT TOTAL(c.f_REALCURRENTAMOUNT) FROM vm_category_display_tmp c WHERE c.t_fullname LIKE vm_category_display_tmp.t_fullname||' > %') AS f_SUMCURRENTAMOUNT, i_NBOPERATIONS+(SELECT CAST(TOTAL(c.i_NBOPERATIONS) AS INTEGER) FROM vm_category_display_tmp c WHERE c.t_fullname like vm_category_display_tmp.t_fullname||' > %') AS i_SUMNBOPERATIONS, (CASE WHEN t_bookmarked='Y' THEN 'Y' WHEN EXISTS(SELECT 1 FROM category c WHERE c.t_bookmarked='Y' AND c.t_fullname like vm_category_display_tmp.t_fullname||' > %') THEN 'C' ELSE 'N' END) AS t_HASBOOKMARKEDCHILD, (CASE WHEN vm_category_display_tmp.f_REALCURRENTAMOUNT<0 THEN '-' WHEN vm_category_display_tmp.f_REALCURRENTAMOUNT=0 THEN '' ELSE '+' END) AS t_TYPEEXPENSE,(CASE WHEN vm_category_display_tmp.f_REALCURRENTAMOUNT<0 THEN 'Dépense' WHEN vm_category_display_tmp.f_REALCURRENTAMOUNT=0 THEN '' ELSE 'Revenu' END) AS t_TYPEEXPENSENLS FROM vm_category_display_tmp; +CREATE VIEW v_recurrentoperation_display AS SELECT rop.*, op.t_ACCOUNT, op.i_number, op.t_mode, op.i_group_id, op.t_TRANSFER, op.t_PAYEE, op.t_comment, op.t_CATEGORY, op.t_status, op.f_CURRENTAMOUNT FROM v_recurrentoperation rop, v_operation_display_all AS op WHERE rop.rd_operation_id=op.ID; +CREATE VIEW v_rule AS SELECT *,(SELECT COUNT(1) FROM rule r WHERE r.f_sortorder<=rule.f_sortorder) AS i_ORDER FROM rule; +CREATE VIEW v_rule_displayname AS SELECT *, t_definition AS t_displayname FROM rule; +CREATE VIEW v_interest AS SELECT *,(SELECT s.t_name FROM account s WHERE s.id=interest.rd_account_id) AS t_ACCOUNT FROM interest; +CREATE VIEW v_interest_displayname AS SELECT *, STRFTIME('%d/%m/%Y',d_date)||' '||f_rate||'%' AS t_displayname FROM interest; +CREATE VIEW v_budgetrule AS SELECT *, IFNULL((SELECT s.t_fullname FROM category s WHERE s.id=budgetrule.rc_category_id),'') AS t_CATEGORYCONDITION, IFNULL((SELECT s.t_fullname FROM category s WHERE s.id=budgetrule.rc_category_id_target),'') AS t_CATEGORY, (CASE WHEN budgetrule.i_condition=-1 THEN 'Négatif' WHEN budgetrule.i_condition=1 THEN 'Positif' WHEN budgetrule.i_condition=0 THEN 'Tous' END) AS t_WHENNLS, f_quantity||(CASE WHEN budgetrule.t_absolute='N' THEN '%' ELSE (SELECT t_symbol FROM unit WHERE t_type='1') END) AS t_WHATNLS,(CASE WHEN budgetrule.t_rule='N' THEN 'Suivant' WHEN budgetrule.t_rule='C' THEN 'Courant' WHEN budgetrule.t_rule='Y' THEN 'Année' END) AS t_RULENLS FROM budgetrule; +CREATE VIEW v_budgetrule_display AS SELECT * FROM v_budgetrule; +CREATE VIEW v_budgetrule_displayname AS SELECT *, t_WHENNLS||' '||t_WHATNLS||' '||t_RULENLS||' '||t_CATEGORY AS t_displayname FROM v_budgetrule; +CREATE VIEW v_budget_tmp AS SELECT *, IFNULL((SELECT s.t_fullname FROM category s WHERE s.id=budget.rc_category_id),'') AS t_CATEGORY, (i_year||(CASE WHEN i_month=0 THEN '' WHEN i_month<10 THEN '-0'||i_month ELSE '-'||i_month END)) AS t_PERIOD, (SELECT TOTAL(o.f_REALCURRENTAMOUNT) FROM v_operation_consolidated o WHERE STRFTIME('%Y', o.d_date)=i_year AND (i_month=0 OR STRFTIME('%m', o.d_date)=i_month) AND o.i_IDCATEGORY IN (SELECT b2.id_category FROM budgetcategory b2 WHERE b2.id=budget.id)) AS f_CURRENTAMOUNT, (SELECT GROUP_CONCAT(v_budgetrule_displayname.t_displayname,',') FROM v_budgetrule_displayname WHERE (v_budgetrule_displayname.t_year_condition='N' OR budget.i_year=v_budgetrule_displayname.i_year) AND (v_budgetrule_displayname.t_month_condition='N' OR budget.i_month=v_budgetrule_displayname.i_month) AND (v_budgetrule_displayname.t_category_condition='N' OR budget.rc_category_id=v_budgetrule_displayname.rc_category_id) ORDER BY v_budgetrule_displayname.t_absolute DESC, v_budgetrule_displayname.id) AS t_RULES FROM budget; +CREATE VIEW v_budget AS SELECT *, (f_CURRENTAMOUNT-f_budgeted_modified) AS f_DELTABEFORETRANSFER, (f_CURRENTAMOUNT-f_budgeted_modified-f_transferred) AS f_DELTA FROM v_budget_tmp; +CREATE VIEW v_budget_display AS SELECT *, (f_CURRENTAMOUNT-f_budgeted_modified) AS f_DELTABEFORETRANSFER, (f_CURRENTAMOUNT-f_budgeted_modified-f_transferred) AS f_DELTA FROM vm_budget_tmp; +CREATE VIEW v_budget_displayname AS SELECT *, t_CATEGORY||' '||t_PERIOD||' '||f_budgeted_modified AS t_displayname FROM v_budget; +CREATE TRIGGER fkdc_bank_parameters_uuid BEFORE DELETE ON bank FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'bank'; END; +CREATE TRIGGER fkdc_account_parameters_uuid BEFORE DELETE ON account FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'account'; END; +CREATE TRIGGER fkdc_unit_parameters_uuid BEFORE DELETE ON unit FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'unit'; END; +CREATE TRIGGER fkdc_unitvalue_parameters_uuid BEFORE DELETE ON unitvalue FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'unitvalue'; END; +CREATE TRIGGER fkdc_category_parameters_uuid BEFORE DELETE ON category FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'category'; END; +CREATE TRIGGER fkdc_operation_parameters_uuid BEFORE DELETE ON operation FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'operation'; END; +CREATE TRIGGER fkdc_interest_parameters_uuid BEFORE DELETE ON interest FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'interest'; END; +CREATE TRIGGER fkdc_suboperation_parameters_uuid BEFORE DELETE ON suboperation FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'suboperation'; END; +CREATE TRIGGER fkdc_refund_parameters_uuid BEFORE DELETE ON refund FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'refund'; END; +CREATE TRIGGER fkdc_payee_parameters_uuid BEFORE DELETE ON payee FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'payee'; END; +CREATE TRIGGER fkdc_recurrentoperation_parameters_uuid BEFORE DELETE ON recurrentoperation FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'recurrentoperation'; END; +CREATE TRIGGER fkdc_rule_parameters_uuid BEFORE DELETE ON rule FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'rule'; END; +CREATE TRIGGER fkdc_budget_parameters_uuid BEFORE DELETE ON budget FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'budget'; END; +CREATE TRIGGER fkdc_budgetrule_parameters_uuid BEFORE DELETE ON budgetrule FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'budgetrule'; END; +CREATE TRIGGER cpt_category_fullname1 AFTER INSERT ON category BEGIN UPDATE category SET t_fullname=CASE WHEN rd_category_id IS NULL OR rd_category_id='' OR rd_category_id=0 THEN new.t_name ELSE (SELECT c.t_fullname FROM category c WHERE c.id=new.rd_category_id)||' > '||new.t_name END WHERE id=new.id;END; +CREATE TRIGGER cpt_category_fullname2 AFTER UPDATE OF t_name, rd_category_id ON category BEGIN UPDATE category SET t_fullname=CASE WHEN rd_category_id IS NULL OR rd_category_id='' OR rd_category_id=0 THEN new.t_name ELSE (SELECT c.t_fullname FROM category c WHERE c.id=new.rd_category_id)||' > '||new.t_name END WHERE id=new.id;UPDATE category SET t_name=t_name WHERE rd_category_id=new.id;END; +CREATE TRIGGER fkdc_category_delete BEFORE DELETE ON category FOR EACH ROW BEGIN UPDATE suboperation SET r_category_id=OLD.rd_category_id WHERE r_category_id=OLD.id; END; +explain + SELECT TOTAL(f_CURRENTAMOUNT), d_DATEMONTH + from v_operation_display + WHERE d_DATEMONTH IN ('2012-05', '2012-04') + group by d_DATEMONTH, t_TYPEEXPENSE; + } +} {/.* Goto .*/} + +# The next test requires FTS4 +ifcapable !fts3 { + finish_test + return +} + +# Taken from the gnome-shell project +# +db close +forcedelete test.db +sqlite3 db test.db +sqlite3_db_config db SQLITE_DBCONFIG_DQS_DDL 1 +sqlite3_db_config db SQLITE_DBCONFIG_DQS_DML 1 +do_test fuzz-oss1-gnomeshell { + db eval { +CREATE TABLE Resource (ID INTEGER NOT NULL PRIMARY KEY, Uri TEXT NOT +NULL, UNIQUE (Uri)); +CREATE VIRTUAL TABLE fts USING fts4; +CREATE TABLE "mfo:Action" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "mfo:Enclosure" (ID INTEGER NOT NULL PRIMARY KEY, +"mfo:remoteLink" INTEGER, "mfo:remoteLink:graph" INTEGER, +"mfo:groupDefault" INTEGER, "mfo:groupDefault:graph" INTEGER, +"mfo:localLink" INTEGER, "mfo:localLink:graph" INTEGER, "mfo:optional" +INTEGER, "mfo:optional:graph" INTEGER); +CREATE TABLE "mfo:FeedChannel" (ID INTEGER NOT NULL PRIMARY KEY, +"mfo:updatedTime" INTEGER, "mfo:updatedTime:graph" INTEGER, +"mfo:updatedTime:localDate" INTEGER, "mfo:updatedTime:localTime" +INTEGER, "mfo:unreadCount" INTEGER, "mfo:unreadCount:graph" INTEGER, +"mfo:totalCount" INTEGER, "mfo:totalCount:graph" INTEGER, "mfo:action" +INTEGER, "mfo:action:graph" INTEGER, "mfo:type" INTEGER, +"mfo:type:graph" INTEGER); +CREATE TABLE "mfo:FeedElement" (ID INTEGER NOT NULL PRIMARY KEY, +"mfo:image" TEXT COLLATE NOCASE, "mfo:image:graph" INTEGER, +"mfo:feedSettings" INTEGER, "mfo:feedSettings:graph" INTEGER); +CREATE TABLE "mfo:FeedMessage" (ID INTEGER NOT NULL PRIMARY KEY, +"mfo:downloadedTime" INTEGER, "mfo:downloadedTime:graph" INTEGER, +"mfo:downloadedTime:localDate" INTEGER, "mfo:downloadedTime:localTime" +INTEGER); +CREATE TABLE "mfo:FeedMessage_mfo:enclosureList" (ID INTEGER NOT NULL, +"mfo:enclosureList" INTEGER NOT NULL, "mfo:enclosureList:graph" +INTEGER); +CREATE TABLE "mfo:FeedSettings" (ID INTEGER NOT NULL PRIMARY KEY, +"mfo:updateInterval" INTEGER, "mfo:updateInterval:graph" INTEGER, +"mfo:expiryInterval" INTEGER, "mfo:expiryInterval:graph" INTEGER, +"mfo:downloadPath" TEXT COLLATE NOCASE, "mfo:downloadPath:graph" +INTEGER, "mfo:downloadFlag" INTEGER, "mfo:downloadFlag:graph" INTEGER, +"mfo:maxSize" INTEGER, "mfo:maxSize:graph" INTEGER); +CREATE TABLE "mfo:FeedType" (ID INTEGER NOT NULL PRIMARY KEY, +"mfo:name" TEXT COLLATE NOCASE, "mfo:name:graph" INTEGER); +CREATE TABLE "mlo:GeoBoundingBox" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "mlo:GeoBoundingBox_mlo:bbNorthWest" (ID INTEGER NOT +NULL, "mlo:bbNorthWest" INTEGER NOT NULL, "mlo:bbNorthWest:graph" +INTEGER); +CREATE TABLE "mlo:GeoBoundingBox_mlo:bbSouthEast" (ID INTEGER NOT +NULL, "mlo:bbSouthEast" INTEGER NOT NULL, "mlo:bbSouthEast:graph" +INTEGER); +CREATE TABLE "mlo:GeoLocation" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "mlo:GeoLocation_mlo:asBoundingBox" (ID INTEGER NOT NULL, +"mlo:asBoundingBox" INTEGER NOT NULL, "mlo:asBoundingBox:graph" +INTEGER); +CREATE TABLE "mlo:GeoLocation_mlo:asGeoPoint" (ID INTEGER NOT NULL, +"mlo:asGeoPoint" INTEGER NOT NULL, "mlo:asGeoPoint:graph" INTEGER); +CREATE TABLE "mlo:GeoLocation_mlo:asPostalAddress" (ID INTEGER NOT +NULL, "mlo:asPostalAddress" INTEGER NOT NULL, +"mlo:asPostalAddress:graph" INTEGER); +CREATE TABLE "mlo:GeoPoint" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "mlo:GeoPoint_mlo:address" (ID INTEGER NOT NULL, +"mlo:address" TEXT NOT NULL, "mlo:address:graph" INTEGER); +CREATE TABLE "mlo:GeoPoint_mlo:altitude" (ID INTEGER NOT NULL, +"mlo:altitude" REAL NOT NULL, "mlo:altitude:graph" INTEGER); +CREATE TABLE "mlo:GeoPoint_mlo:city" (ID INTEGER NOT NULL, "mlo:city" +TEXT NOT NULL, "mlo:city:graph" INTEGER); +CREATE TABLE "mlo:GeoPoint_mlo:country" (ID INTEGER NOT NULL, +"mlo:country" TEXT NOT NULL, "mlo:country:graph" INTEGER); +CREATE TABLE "mlo:GeoPoint_mlo:latitude" (ID INTEGER NOT NULL, +"mlo:latitude" REAL NOT NULL, "mlo:latitude:graph" INTEGER); +CREATE TABLE "mlo:GeoPoint_mlo:longitude" (ID INTEGER NOT NULL, +"mlo:longitude" REAL NOT NULL, "mlo:longitude:graph" INTEGER); +CREATE TABLE "mlo:GeoPoint_mlo:state" (ID INTEGER NOT NULL, +"mlo:state" TEXT NOT NULL, "mlo:state:graph" INTEGER); +CREATE TABLE "mlo:GeoPoint_mlo:timestamp" (ID INTEGER NOT NULL, +"mlo:timestamp" INTEGER NOT NULL, "mlo:timestamp:graph" INTEGER, +"mlo:timestamp:localDate" INTEGER NOT NULL, "mlo:timestamp:localTime" +INTEGER NOT NULL); +CREATE TABLE "mlo:GeoSphere" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "mlo:GeoSphere_mlo:radius" (ID INTEGER NOT NULL, +"mlo:radius" REAL NOT NULL, "mlo:radius:graph" INTEGER); +CREATE TABLE "mlo:Landmark" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "mlo:LandmarkCategory" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "mlo:LandmarkCategory_mlo:isRemovable" (ID INTEGER NOT +NULL, "mlo:isRemovable" INTEGER NOT NULL, "mlo:isRemovable:graph" +INTEGER); +CREATE TABLE "mlo:Landmark_mlo:belongsToCategory" (ID INTEGER NOT +NULL, "mlo:belongsToCategory" INTEGER NOT NULL, +"mlo:belongsToCategory:graph" INTEGER); +CREATE TABLE "mlo:Landmark_mlo:poiLocation" (ID INTEGER NOT NULL, +"mlo:poiLocation" INTEGER NOT NULL, "mlo:poiLocation:graph" INTEGER); +CREATE TABLE "mlo:LocationBoundingBox" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "mlo:LocationBoundingBox_mlo:boxEastLimit" (ID INTEGER +NOT NULL, "mlo:boxEastLimit" INTEGER NOT NULL, +"mlo:boxEastLimit:graph" INTEGER); +CREATE TABLE "mlo:LocationBoundingBox_mlo:boxNorthLimit" (ID INTEGER +NOT NULL, "mlo:boxNorthLimit" INTEGER NOT NULL, +"mlo:boxNorthLimit:graph" INTEGER); +CREATE TABLE "mlo:LocationBoundingBox_mlo:boxSouthWestCorner" (ID +INTEGER NOT NULL, "mlo:boxSouthWestCorner" INTEGER NOT NULL, +"mlo:boxSouthWestCorner:graph" INTEGER); +CREATE TABLE "mlo:LocationBoundingBox_mlo:boxVerticalLimit" (ID +INTEGER NOT NULL, "mlo:boxVerticalLimit" INTEGER NOT NULL, +"mlo:boxVerticalLimit:graph" INTEGER); +CREATE TABLE "mlo:PointOfInterest" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "mlo:Route" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "mlo:Route_mlo:endTime" (ID INTEGER NOT NULL, +"mlo:endTime" INTEGER NOT NULL, "mlo:endTime:graph" INTEGER, +"mlo:endTime:localDate" INTEGER NOT NULL, "mlo:endTime:localTime" +INTEGER NOT NULL); +CREATE TABLE "mlo:Route_mlo:routeDetails" (ID INTEGER NOT NULL, +"mlo:routeDetails" TEXT NOT NULL, "mlo:routeDetails:graph" INTEGER); +CREATE TABLE "mlo:Route_mlo:startTime" (ID INTEGER NOT NULL, +"mlo:startTime" INTEGER NOT NULL, "mlo:startTime:graph" INTEGER, +"mlo:startTime:localDate" INTEGER NOT NULL, "mlo:startTime:localTime" +INTEGER NOT NULL); +CREATE TABLE "mto:DownloadTransfer" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "mto:State" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "mto:SyncTransfer" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "mto:Transfer" (ID INTEGER NOT NULL PRIMARY KEY, +"mto:transferState" INTEGER, "mto:transferState:graph" INTEGER, +"mto:method" INTEGER, "mto:method:graph" INTEGER, "mto:created" +INTEGER, "mto:created:graph" INTEGER, "mto:created:localDate" INTEGER, +"mto:created:localTime" INTEGER, "mto:account" TEXT COLLATE NOCASE, +"mto:account:graph" INTEGER, "mto:starter" INTEGER, +"mto:starter:graph" INTEGER, "mto:agent" INTEGER, "mto:agent:graph" +INTEGER); +CREATE TABLE "mto:TransferElement" (ID INTEGER NOT NULL PRIMARY KEY, +"mto:source" INTEGER, "mto:source:graph" INTEGER, "mto:destination" +INTEGER, "mto:destination:graph" INTEGER, "mto:startedTime" INTEGER, +"mto:startedTime:graph" INTEGER, "mto:startedTime:localDate" INTEGER, +"mto:startedTime:localTime" INTEGER, "mto:completedTime" INTEGER, +"mto:completedTime:graph" INTEGER, "mto:completedTime:localDate" +INTEGER, "mto:completedTime:localTime" INTEGER, "mto:state" INTEGER, +"mto:state:graph" INTEGER); +CREATE TABLE "mto:TransferMethod" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "mto:Transfer_mto:transferList" (ID INTEGER NOT NULL, +"mto:transferList" INTEGER NOT NULL, "mto:transferList:graph" +INTEGER); +CREATE TABLE "mto:Transfer_mto:transferPrivacyLevel" (ID INTEGER NOT +NULL, "mto:transferPrivacyLevel" TEXT NOT NULL, +"mto:transferPrivacyLevel:graph" INTEGER); +CREATE TABLE "mto:UploadTransfer" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "mto:UploadTransfer_mto:transferCategory" (ID INTEGER NOT +NULL, "mto:transferCategory" TEXT NOT NULL, +"mto:transferCategory:graph" INTEGER); +CREATE TABLE "mtp:ScanType" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nao:Property" (ID INTEGER NOT NULL PRIMARY KEY, +"nao:propertyName" TEXT COLLATE NOCASE, "nao:propertyName:graph" +INTEGER, "nao:propertyValue" TEXT COLLATE NOCASE, +"nao:propertyValue:graph" INTEGER); +CREATE TABLE "nao:Tag" (ID INTEGER NOT NULL PRIMARY KEY, +"nao:prefLabel" TEXT COLLATE NOCASE, "nao:prefLabel:graph" INTEGER, +"nao:description" TEXT COLLATE NOCASE, "nao:description:graph" +INTEGER); +CREATE TABLE "nao:Tag_tracker:isDefaultTag" (ID INTEGER NOT NULL, +"tracker:isDefaultTag" INTEGER NOT NULL, "tracker:isDefaultTag:graph" +INTEGER); +CREATE TABLE "nao:Tag_tracker:tagRelatedTo" (ID INTEGER NOT NULL, +"tracker:tagRelatedTo" INTEGER NOT NULL, "tracker:tagRelatedTo:graph" +INTEGER); +CREATE TABLE "ncal:AccessClassification" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:Alarm" (ID INTEGER NOT NULL PRIMARY KEY, +"ncal:repeat" INTEGER, "ncal:repeat:graph" INTEGER); +CREATE TABLE "ncal:AlarmAction" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:Alarm_ncal:action" (ID INTEGER NOT NULL, +"ncal:action" INTEGER NOT NULL, "ncal:action:graph" INTEGER); +CREATE TABLE "ncal:Attachment" (ID INTEGER NOT NULL PRIMARY KEY, +"ncal:attachmentUri" INTEGER, "ncal:attachmentUri:graph" INTEGER, +"ncal:fmttype" TEXT COLLATE NOCASE, "ncal:fmttype:graph" INTEGER, +"ncal:encoding" INTEGER, "ncal:encoding:graph" INTEGER, +"ncal:attachmentContent" TEXT COLLATE NOCASE, +"ncal:attachmentContent:graph" INTEGER); +CREATE TABLE "ncal:AttachmentEncoding" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:Attendee" (ID INTEGER NOT NULL PRIMARY KEY, +"ncal:delegatedTo" INTEGER, "ncal:delegatedTo:graph" INTEGER, +"ncal:delegatedFrom" INTEGER, "ncal:delegatedFrom:graph" INTEGER, +"ncal:cutype" INTEGER, "ncal:cutype:graph" INTEGER, "ncal:member" +INTEGER, "ncal:member:graph" INTEGER, "ncal:role" INTEGER, +"ncal:role:graph" INTEGER, "ncal:rsvp" INTEGER, "ncal:rsvp:graph" +INTEGER, "ncal:partstat" INTEGER, "ncal:partstat:graph" INTEGER); +CREATE TABLE "ncal:AttendeeOrOrganizer" (ID INTEGER NOT NULL PRIMARY +KEY, "ncal:dir" INTEGER, "ncal:dir:graph" INTEGER, +"ncal:involvedContact" INTEGER, "ncal:involvedContact:graph" INTEGER, +"ncal:sentBy" INTEGER, "ncal:sentBy:graph" INTEGER); +CREATE TABLE "ncal:AttendeeRole" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:BydayRulePart" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:BydayRulePart_ncal:bydayModifier" (ID INTEGER NOT +NULL, "ncal:bydayModifier" INTEGER NOT NULL, +"ncal:bydayModifier:graph" INTEGER); +CREATE TABLE "ncal:BydayRulePart_ncal:bydayWeekday" (ID INTEGER NOT +NULL, "ncal:bydayWeekday" INTEGER NOT NULL, "ncal:bydayWeekday:graph" +INTEGER); +CREATE TABLE "ncal:Calendar" (ID INTEGER NOT NULL PRIMARY KEY, +"ncal:method" TEXT COLLATE NOCASE, "ncal:method:graph" INTEGER, +"ncal:calscale" INTEGER, "ncal:calscale:graph" INTEGER, "ncal:prodid" +TEXT COLLATE NOCASE, "ncal:prodid:graph" INTEGER, "ncal:version" TEXT +COLLATE NOCASE, "ncal:version:graph" INTEGER); +CREATE TABLE "ncal:CalendarDataObject" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:CalendarScale" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:CalendarUserType" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:Calendar_ncal:component" (ID INTEGER NOT NULL, +"ncal:component" INTEGER NOT NULL, "ncal:component:graph" INTEGER); +CREATE TABLE "ncal:Event" (ID INTEGER NOT NULL PRIMARY KEY, +"ncal:eventStatus" INTEGER, "ncal:eventStatus:graph" INTEGER, +"ncal:transp" INTEGER, "ncal:transp:graph" INTEGER); +CREATE TABLE "ncal:EventStatus" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:Freebusy" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:FreebusyPeriod" (ID INTEGER NOT NULL PRIMARY KEY, +"ncal:fbtype" INTEGER, "ncal:fbtype:graph" INTEGER); +CREATE TABLE "ncal:FreebusyType" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:Freebusy_ncal:freebusy" (ID INTEGER NOT NULL, +"ncal:freebusy" INTEGER NOT NULL, "ncal:freebusy:graph" INTEGER); +CREATE TABLE "ncal:Journal" (ID INTEGER NOT NULL PRIMARY KEY, +"ncal:journalStatus" INTEGER, "ncal:journalStatus:graph" INTEGER); +CREATE TABLE "ncal:JournalStatus" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:NcalDateTime" (ID INTEGER NOT NULL PRIMARY KEY, +"ncal:ncalTimezone" INTEGER, "ncal:ncalTimezone:graph" INTEGER, +"ncal:date" INTEGER, "ncal:date:graph" INTEGER, "ncal:date:localDate" +INTEGER, "ncal:date:localTime" INTEGER, "ncal:dateTime" INTEGER, +"ncal:dateTime:graph" INTEGER, "ncal:dateTime:localDate" INTEGER, +"ncal:dateTime:localTime" INTEGER); +CREATE TABLE "ncal:NcalPeriod" (ID INTEGER NOT NULL PRIMARY KEY, +"ncal:periodBegin" INTEGER, "ncal:periodBegin:graph" INTEGER, +"ncal:periodBegin:localDate" INTEGER, "ncal:periodBegin:localTime" +INTEGER, "ncal:periodDuration" INTEGER, "ncal:periodDuration:graph" +INTEGER, "ncal:periodEnd" INTEGER, "ncal:periodEnd:graph" INTEGER, +"ncal:periodEnd:localDate" INTEGER, "ncal:periodEnd:localTime" +INTEGER); +CREATE TABLE "ncal:NcalTimeEntity" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:Organizer" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:ParticipationStatus" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:RecurrenceFrequency" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:RecurrenceIdentifier" (ID INTEGER NOT NULL PRIMARY +KEY, "ncal:range" INTEGER, "ncal:range:graph" INTEGER, +"ncal:recurrenceIdDateTime" INTEGER, "ncal:recurrenceIdDateTime:graph" +INTEGER); +CREATE TABLE "ncal:RecurrenceIdentifierRange" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:RecurrenceRule" (ID INTEGER NOT NULL PRIMARY KEY, +"ncal:until" INTEGER, "ncal:until:graph" INTEGER, +"ncal:until:localDate" INTEGER, "ncal:until:localTime" INTEGER, +"ncal:wkst" INTEGER, "ncal:wkst:graph" INTEGER, "ncal:interval" +INTEGER, "ncal:interval:graph" INTEGER, "ncal:count" INTEGER, +"ncal:count:graph" INTEGER, "ncal:freq" INTEGER, "ncal:freq:graph" +INTEGER); +CREATE TABLE "ncal:RecurrenceRule_ncal:byday" (ID INTEGER NOT NULL, +"ncal:byday" INTEGER NOT NULL, "ncal:byday:graph" INTEGER); +CREATE TABLE "ncal:RecurrenceRule_ncal:byhour" (ID INTEGER NOT NULL, +"ncal:byhour" INTEGER NOT NULL, "ncal:byhour:graph" INTEGER); +CREATE TABLE "ncal:RecurrenceRule_ncal:byminute" (ID INTEGER NOT NULL, +"ncal:byminute" INTEGER NOT NULL, "ncal:byminute:graph" INTEGER); +CREATE TABLE "ncal:RecurrenceRule_ncal:bymonth" (ID INTEGER NOT NULL, +"ncal:bymonth" INTEGER NOT NULL, "ncal:bymonth:graph" INTEGER); +CREATE TABLE "ncal:RecurrenceRule_ncal:bymonthday" (ID INTEGER NOT +NULL, "ncal:bymonthday" INTEGER NOT NULL, "ncal:bymonthday:graph" +INTEGER); +CREATE TABLE "ncal:RecurrenceRule_ncal:bysecond" (ID INTEGER NOT NULL, +"ncal:bysecond" INTEGER NOT NULL, "ncal:bysecond:graph" INTEGER); +CREATE TABLE "ncal:RecurrenceRule_ncal:bysetpos" (ID INTEGER NOT NULL, +"ncal:bysetpos" INTEGER NOT NULL, "ncal:bysetpos:graph" INTEGER); +CREATE TABLE "ncal:RecurrenceRule_ncal:byweekno" (ID INTEGER NOT NULL, +"ncal:byweekno" INTEGER NOT NULL, "ncal:byweekno:graph" INTEGER); +CREATE TABLE "ncal:RecurrenceRule_ncal:byyearday" (ID INTEGER NOT +NULL, "ncal:byyearday" INTEGER NOT NULL, "ncal:byyearday:graph" +INTEGER); +CREATE TABLE "ncal:RequestStatus" (ID INTEGER NOT NULL PRIMARY KEY, +"ncal:statusDescription" TEXT COLLATE NOCASE, +"ncal:statusDescription:graph" INTEGER, "ncal:returnStatus" TEXT +COLLATE NOCASE, "ncal:returnStatus:graph" INTEGER, +"ncal:requestStatusData" TEXT COLLATE NOCASE, +"ncal:requestStatusData:graph" INTEGER); +CREATE TABLE "ncal:TimeTransparency" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:Timezone" (ID INTEGER NOT NULL PRIMARY KEY, +"ncal:tzurl" INTEGER, "ncal:tzurl:graph" INTEGER, "ncal:standard" +INTEGER, "ncal:standard:graph" INTEGER, "ncal:daylight" INTEGER, +"ncal:daylight:graph" INTEGER, "ncal:tzid" TEXT COLLATE NOCASE, +"ncal:tzid:graph" INTEGER); +CREATE TABLE "ncal:TimezoneObservance" (ID INTEGER NOT NULL PRIMARY +KEY, "ncal:tzoffsetfrom" TEXT COLLATE NOCASE, +"ncal:tzoffsetfrom:graph" INTEGER, "ncal:tzoffsetto" TEXT COLLATE +NOCASE, "ncal:tzoffsetto:graph" INTEGER, "ncal:tzname" TEXT COLLATE +NOCASE, "ncal:tzname:graph" INTEGER); +CREATE TABLE "ncal:Todo" (ID INTEGER NOT NULL PRIMARY KEY, +"ncal:percentComplete" INTEGER, "ncal:percentComplete:graph" INTEGER, +"ncal:completed" INTEGER, "ncal:completed:graph" INTEGER, +"ncal:completed:localDate" INTEGER, "ncal:completed:localTime" +INTEGER, "ncal:todoStatus" INTEGER, "ncal:todoStatus:graph" INTEGER, +"ncal:due" INTEGER, "ncal:due:graph" INTEGER); +CREATE TABLE "ncal:TodoStatus" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:Trigger" (ID INTEGER NOT NULL PRIMARY KEY, +"ncal:related" INTEGER, "ncal:related:graph" INTEGER, +"ncal:triggerDateTime" INTEGER, "ncal:triggerDateTime:graph" INTEGER, +"ncal:triggerDateTime:localDate" INTEGER, +"ncal:triggerDateTime:localTime" INTEGER, "ncal:triggerDuration" +INTEGER, "ncal:triggerDuration:graph" INTEGER); +CREATE TABLE "ncal:TriggerRelation" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:UnionParentClass" (ID INTEGER NOT NULL PRIMARY KEY, +"ncal:lastModified" INTEGER, "ncal:lastModified:graph" INTEGER, +"ncal:lastModified:localDate" INTEGER, "ncal:lastModified:localTime" +INTEGER, "ncal:trigger" INTEGER, "ncal:trigger:graph" INTEGER, +"ncal:created" INTEGER, "ncal:created:graph" INTEGER, +"ncal:created:localDate" INTEGER, "ncal:created:localTime" INTEGER, +"ncal:url" INTEGER, "ncal:url:graph" INTEGER, "ncal:comment" TEXT +COLLATE NOCASE, "ncal:comment:graph" INTEGER, "ncal:summaryAltRep" +INTEGER, "ncal:summaryAltRep:graph" INTEGER, "ncal:priority" INTEGER, +"ncal:priority:graph" INTEGER, "ncal:location" TEXT COLLATE NOCASE, +"ncal:location:graph" INTEGER, "ncal:uid" TEXT COLLATE NOCASE, +"ncal:uid:graph" INTEGER, "ncal:requestStatus" INTEGER, +"ncal:requestStatus:graph" INTEGER, "ncal:recurrenceId" INTEGER, +"ncal:recurrenceId:graph" INTEGER, "ncal:dtstamp" INTEGER, +"ncal:dtstamp:graph" INTEGER, "ncal:dtstamp:localDate" INTEGER, +"ncal:dtstamp:localTime" INTEGER, "ncal:class" INTEGER, +"ncal:class:graph" INTEGER, "ncal:organizer" INTEGER, +"ncal:organizer:graph" INTEGER, "ncal:dtend" INTEGER, +"ncal:dtend:graph" INTEGER, "ncal:summary" TEXT COLLATE NOCASE, +"ncal:summary:graph" INTEGER, "ncal:descriptionAltRep" INTEGER, +"ncal:descriptionAltRep:graph" INTEGER, "ncal:commentAltRep" INTEGER, +"ncal:commentAltRep:graph" INTEGER, "ncal:sequence" INTEGER, +"ncal:sequence:graph" INTEGER, "ncal:contact" TEXT COLLATE NOCASE, +"ncal:contact:graph" INTEGER, "ncal:contactAltRep" INTEGER, +"ncal:contactAltRep:graph" INTEGER, "ncal:locationAltRep" INTEGER, +"ncal:locationAltRep:graph" INTEGER, "ncal:geo" INTEGER, +"ncal:geo:graph" INTEGER, "ncal:resourcesAltRep" INTEGER, +"ncal:resourcesAltRep:graph" INTEGER, "ncal:dtstart" INTEGER, +"ncal:dtstart:graph" INTEGER, "ncal:description" TEXT COLLATE NOCASE, +"ncal:description:graph" INTEGER, "ncal:relatedToSibling" TEXT COLLATE +NOCASE, "ncal:relatedToSibling:graph" INTEGER, "ncal:duration" +INTEGER, "ncal:duration:graph" INTEGER); +CREATE TABLE "ncal:UnionParentClass_ncal:attach" (ID INTEGER NOT NULL, +"ncal:attach" INTEGER NOT NULL, "ncal:attach:graph" INTEGER); +CREATE TABLE "ncal:UnionParentClass_ncal:attendee" (ID INTEGER NOT +NULL, "ncal:attendee" INTEGER NOT NULL, "ncal:attendee:graph" +INTEGER); +CREATE TABLE "ncal:UnionParentClass_ncal:categories" (ID INTEGER NOT +NULL, "ncal:categories" TEXT NOT NULL, "ncal:categories:graph" +INTEGER); +CREATE TABLE "ncal:UnionParentClass_ncal:exdate" (ID INTEGER NOT NULL, +"ncal:exdate" INTEGER NOT NULL, "ncal:exdate:graph" INTEGER); +CREATE TABLE "ncal:UnionParentClass_ncal:exrule" (ID INTEGER NOT NULL, +"ncal:exrule" INTEGER NOT NULL, "ncal:exrule:graph" INTEGER); +CREATE TABLE "ncal:UnionParentClass_ncal:hasAlarm" (ID INTEGER NOT +NULL, "ncal:hasAlarm" INTEGER NOT NULL, "ncal:hasAlarm:graph" +INTEGER); +CREATE TABLE "ncal:UnionParentClass_ncal:ncalRelation" (ID INTEGER NOT +NULL, "ncal:ncalRelation" TEXT NOT NULL, "ncal:ncalRelation:graph" +INTEGER); +CREATE TABLE "ncal:UnionParentClass_ncal:rdate" (ID INTEGER NOT NULL, +"ncal:rdate" INTEGER NOT NULL, "ncal:rdate:graph" INTEGER); +CREATE TABLE "ncal:UnionParentClass_ncal:relatedToChild" (ID INTEGER +NOT NULL, "ncal:relatedToChild" TEXT NOT NULL, +"ncal:relatedToChild:graph" INTEGER); +CREATE TABLE "ncal:UnionParentClass_ncal:relatedToParent" (ID INTEGER +NOT NULL, "ncal:relatedToParent" TEXT NOT NULL, +"ncal:relatedToParent:graph" INTEGER); +CREATE TABLE "ncal:UnionParentClass_ncal:resources" (ID INTEGER NOT +NULL, "ncal:resources" TEXT NOT NULL, "ncal:resources:graph" INTEGER); +CREATE TABLE "ncal:UnionParentClass_ncal:rrule" (ID INTEGER NOT NULL, +"ncal:rrule" INTEGER NOT NULL, "ncal:rrule:graph" INTEGER); +CREATE TABLE "ncal:Weekday" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:Affiliation" (ID INTEGER NOT NULL PRIMARY KEY, +"nco:department" TEXT COLLATE NOCASE, "nco:department:graph" INTEGER, +"nco:org" INTEGER, "nco:org:graph" INTEGER, "nco:role" TEXT COLLATE +NOCASE, "nco:role:graph" INTEGER); +CREATE TABLE "nco:Affiliation_nco:title" (ID INTEGER NOT NULL, +"nco:title" TEXT NOT NULL, "nco:title:graph" INTEGER); +CREATE TABLE "nco:AuthorizationStatus" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:BbsNumber" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:CarPhoneNumber" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:CellPhoneNumber" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:Contact" (ID INTEGER NOT NULL PRIMARY KEY, +"nco:fullname" TEXT COLLATE NOCASE, "nco:fullname:graph" INTEGER, +"nco:key" INTEGER, "nco:key:graph" INTEGER, "nco:contactUID" TEXT +COLLATE NOCASE, "nco:contactUID:graph" INTEGER, "nco:contactLocalUID" +TEXT COLLATE NOCASE, "nco:contactLocalUID:graph" INTEGER, +"nco:hasLocation" INTEGER, "nco:hasLocation:graph" INTEGER, +"nco:nickname" TEXT COLLATE NOCASE, "nco:nickname:graph" INTEGER, +"nco:representative" INTEGER, "nco:representative:graph" INTEGER, +"nco:photo" INTEGER, "nco:photo:graph" INTEGER, "nco:birthDate" +INTEGER, "nco:birthDate:graph" INTEGER, "nco:birthDate:localDate" +INTEGER, "nco:birthDate:localTime" INTEGER, "nco:sound" INTEGER, +"nco:sound:graph" INTEGER); +CREATE TABLE "nco:ContactGroup" (ID INTEGER NOT NULL PRIMARY KEY, +"nco:contactGroupName" TEXT COLLATE NOCASE, +"nco:contactGroupName:graph" INTEGER); +CREATE TABLE "nco:ContactList" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:ContactListDataObject" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:ContactList_nco:containsContact" (ID INTEGER NOT +NULL, "nco:containsContact" INTEGER NOT NULL, +"nco:containsContact:graph" INTEGER); +CREATE TABLE "nco:ContactMedium" (ID INTEGER NOT NULL PRIMARY KEY, +"nco:contactMediumComment" TEXT COLLATE NOCASE, +"nco:contactMediumComment:graph" INTEGER); +CREATE TABLE "nco:Contact_ncal:anniversary" (ID INTEGER NOT NULL, +"ncal:anniversary" INTEGER NOT NULL, "ncal:anniversary:graph" +INTEGER); +CREATE TABLE "nco:Contact_ncal:birthday" (ID INTEGER NOT NULL, +"ncal:birthday" INTEGER NOT NULL, "ncal:birthday:graph" INTEGER); +CREATE TABLE "nco:Contact_nco:belongsToGroup" (ID INTEGER NOT NULL, +"nco:belongsToGroup" INTEGER NOT NULL, "nco:belongsToGroup:graph" +INTEGER); +CREATE TABLE "nco:Contact_nco:note" (ID INTEGER NOT NULL, "nco:note" +TEXT NOT NULL, "nco:note:graph" INTEGER); +CREATE TABLE "nco:Contact_scal:anniversary" (ID INTEGER NOT NULL, +"scal:anniversary" INTEGER NOT NULL, "scal:anniversary:graph" +INTEGER); +CREATE TABLE "nco:Contact_scal:birthday" (ID INTEGER NOT NULL, +"scal:birthday" INTEGER NOT NULL, "scal:birthday:graph" INTEGER); +CREATE TABLE "nco:DomesticDeliveryAddress" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:EmailAddress" (ID INTEGER NOT NULL PRIMARY KEY, +"nco:emailAddress" TEXT COLLATE NOCASE UNIQUE, +"nco:emailAddress:graph" INTEGER); +CREATE TABLE "nco:FaxNumber" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:Gender" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:IMAccount" (ID INTEGER NOT NULL PRIMARY KEY, +"nco:imAccountAddress" INTEGER UNIQUE, "nco:imAccountAddress:graph" +INTEGER, "nco:imAccountType" TEXT COLLATE NOCASE, +"nco:imAccountType:graph" INTEGER, "nco:imDisplayName" TEXT COLLATE +NOCASE, "nco:imDisplayName:graph" INTEGER, "nco:imEnabled" INTEGER, +"nco:imEnabled:graph" INTEGER); +CREATE TABLE "nco:IMAccount_nco:hasIMContact" (ID INTEGER NOT NULL, +"nco:hasIMContact" INTEGER NOT NULL, "nco:hasIMContact:graph" +INTEGER); +CREATE TABLE "nco:IMAddress" (ID INTEGER NOT NULL PRIMARY KEY, +"nco:imID" TEXT COLLATE NOCASE, "nco:imID:graph" INTEGER, +"nco:imNickname" TEXT COLLATE NOCASE, "nco:imNickname:graph" INTEGER, +"nco:imAvatar" INTEGER, "nco:imAvatar:graph" INTEGER, "nco:imProtocol" +TEXT COLLATE NOCASE, "nco:imProtocol:graph" INTEGER, +"nco:imStatusMessage" TEXT COLLATE NOCASE, +"nco:imStatusMessage:graph" INTEGER, "nco:imPresence" INTEGER, +"nco:imPresence:graph" INTEGER, "nco:presenceLastModified" INTEGER, +"nco:presenceLastModified:graph" INTEGER, +"nco:presenceLastModified:localDate" INTEGER, +"nco:presenceLastModified:localTime" INTEGER, +"nco:imAddressAuthStatusFrom" INTEGER, +"nco:imAddressAuthStatusFrom:graph" INTEGER, +"nco:imAddressAuthStatusTo" INTEGER, "nco:imAddressAuthStatusTo:graph" +INTEGER); +CREATE TABLE "nco:IMAddress_nco:imCapability" (ID INTEGER NOT NULL, +"nco:imCapability" INTEGER NOT NULL, "nco:imCapability:graph" +INTEGER); +CREATE TABLE "nco:IMCapability" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:InternationalDeliveryAddress" (ID INTEGER NOT NULL +PRIMARY KEY); +CREATE TABLE "nco:IsdnNumber" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:MessagingNumber" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:ModemNumber" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:OrganizationContact" (ID INTEGER NOT NULL PRIMARY +KEY, "nco:logo" INTEGER, "nco:logo:graph" INTEGER); +CREATE TABLE "nco:PagerNumber" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:ParcelDeliveryAddress" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:PcsNumber" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:PersonContact" (ID INTEGER NOT NULL PRIMARY KEY, +"nco:nameFamily" TEXT COLLATE NOCASE, "nco:nameFamily:graph" INTEGER, +"nco:nameGiven" TEXT COLLATE NOCASE, "nco:nameGiven:graph" INTEGER, +"nco:nameAdditional" TEXT COLLATE NOCASE, "nco:nameAdditional:graph" +INTEGER, "nco:nameHonorificSuffix" TEXT COLLATE NOCASE, +"nco:nameHonorificSuffix:graph" INTEGER, "nco:nameHonorificPrefix" +TEXT COLLATE NOCASE, "nco:nameHonorificPrefix:graph" INTEGER, +"nco:hobby" TEXT COLLATE NOCASE, "nco:hobby:graph" INTEGER, +"nco:gender" INTEGER, "nco:gender:graph" INTEGER); +CREATE TABLE "nco:PersonContact_nco:hasAffiliation" (ID INTEGER NOT +NULL, "nco:hasAffiliation" INTEGER NOT NULL, +"nco:hasAffiliation:graph" INTEGER); +CREATE TABLE "nco:PhoneNumber" (ID INTEGER NOT NULL PRIMARY KEY, +"nco:phoneNumber" TEXT COLLATE NOCASE, "nco:phoneNumber:graph" +INTEGER); +CREATE TABLE "nco:PostalAddress" (ID INTEGER NOT NULL PRIMARY KEY, +"nco:region" TEXT COLLATE NOCASE, "nco:region:graph" INTEGER, +"nco:country" TEXT COLLATE NOCASE, "nco:country:graph" INTEGER, +"nco:extendedAddress" TEXT COLLATE NOCASE, +"nco:extendedAddress:graph" INTEGER, "nco:addressLocation" INTEGER, +"nco:addressLocation:graph" INTEGER, "nco:streetAddress" TEXT COLLATE +NOCASE, "nco:streetAddress:graph" INTEGER, "nco:postalcode" TEXT +COLLATE NOCASE, "nco:postalcode:graph" INTEGER, "nco:locality" TEXT +COLLATE NOCASE, "nco:locality:graph" INTEGER, "nco:county" TEXT +COLLATE NOCASE, "nco:county:graph" INTEGER, "nco:district" TEXT +COLLATE NOCASE, "nco:district:graph" INTEGER, "nco:pobox" TEXT +COLLATE NOCASE, "nco:pobox:graph" INTEGER); +CREATE TABLE "nco:PresenceStatus" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:Role" (ID INTEGER NOT NULL PRIMARY KEY, "nco:video" +INTEGER, "nco:video:graph" INTEGER); +CREATE TABLE "nco:Role_nco:blogUrl" (ID INTEGER NOT NULL, +"nco:blogUrl" INTEGER NOT NULL, "nco:blogUrl:graph" INTEGER); +CREATE TABLE "nco:Role_nco:foafUrl" (ID INTEGER NOT NULL, +"nco:foafUrl" INTEGER NOT NULL, "nco:foafUrl:graph" INTEGER); +CREATE TABLE "nco:Role_nco:hasContactMedium" (ID INTEGER NOT NULL, +"nco:hasContactMedium" INTEGER NOT NULL, "nco:hasContactMedium:graph" +INTEGER); +CREATE TABLE "nco:Role_nco:hasEmailAddress" (ID INTEGER NOT NULL, +"nco:hasEmailAddress" INTEGER NOT NULL, "nco:hasEmailAddress:graph" +INTEGER); +CREATE TABLE "nco:Role_nco:hasIMAddress" (ID INTEGER NOT NULL, +"nco:hasIMAddress" INTEGER NOT NULL, "nco:hasIMAddress:graph" +INTEGER); +CREATE TABLE "nco:Role_nco:hasPhoneNumber" (ID INTEGER NOT NULL, +"nco:hasPhoneNumber" INTEGER NOT NULL, "nco:hasPhoneNumber:graph" +INTEGER); +CREATE TABLE "nco:Role_nco:hasPostalAddress" (ID INTEGER NOT NULL, +"nco:hasPostalAddress" INTEGER NOT NULL, "nco:hasPostalAddress:graph" +INTEGER); +CREATE TABLE "nco:Role_nco:url" (ID INTEGER NOT NULL, "nco:url" +INTEGER NOT NULL, "nco:url:graph" INTEGER); +CREATE TABLE "nco:Role_nco:websiteUrl" (ID INTEGER NOT NULL, +"nco:websiteUrl" INTEGER NOT NULL, "nco:websiteUrl:graph" INTEGER); +CREATE TABLE "nco:VideoTelephoneNumber" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:VoicePhoneNumber" (ID INTEGER NOT NULL PRIMARY KEY, +"nco:voiceMail" INTEGER, "nco:voiceMail:graph" INTEGER); +CREATE TABLE "nfo:Application" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:Archive" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:uncompressedSize" INTEGER, "nfo:uncompressedSize:graph" INTEGER); +CREATE TABLE "nfo:ArchiveItem" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:isPasswordProtected" INTEGER, "nfo:isPasswordProtected:graph" +INTEGER); +CREATE TABLE "nfo:Attachment" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:Audio" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:channels" INTEGER, "nfo:channels:graph" INTEGER, +"nfo:sideChannels" INTEGER, "nfo:sideChannels:graph" INTEGER, +"nfo:lfeChannels" INTEGER, "nfo:lfeChannels:graph" INTEGER, +"nfo:sampleCount" INTEGER, "nfo:sampleCount:graph" INTEGER, +"nfo:bitsPerSample" INTEGER, "nfo:bitsPerSample:graph" INTEGER, +"nfo:frontChannels" INTEGER, "nfo:frontChannels:graph" INTEGER, +"nfo:sampleRate" REAL, "nfo:sampleRate:graph" INTEGER, +"nfo:averageAudioBitrate" REAL, "nfo:averageAudioBitrate:graph" +INTEGER, "nfo:rearChannels" INTEGER, "nfo:rearChannels:graph" INTEGER, +"nfo:gain" INTEGER, "nfo:gain:graph" INTEGER, "nfo:peakGain" INTEGER, +"nfo:peakGain:graph" INTEGER, "nfo:audioOffset" REAL, +"nfo:audioOffset:graph" INTEGER); +CREATE TABLE "nfo:Bookmark" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:bookmarks" INTEGER, "nfo:bookmarks:graph" INTEGER, +"nfo:characterPosition" INTEGER, "nfo:characterPosition:graph" +INTEGER, "nfo:pageNumber" INTEGER, "nfo:pageNumber:graph" INTEGER, +"nfo:streamPosition" INTEGER, "nfo:streamPosition:graph" INTEGER, +"nfo:streamDuration" INTEGER, "nfo:streamDuration:graph" INTEGER); +CREATE TABLE "nfo:BookmarkFolder" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:BookmarkFolder_nfo:containsBookmark" (ID INTEGER NOT +NULL, "nfo:containsBookmark" INTEGER NOT NULL, +"nfo:containsBookmark:graph" INTEGER); +CREATE TABLE "nfo:BookmarkFolder_nfo:containsBookmarkFolder" (ID +INTEGER NOT NULL, "nfo:containsBookmarkFolder" INTEGER NOT NULL, +"nfo:containsBookmarkFolder:graph" INTEGER); +CREATE TABLE "nfo:CompressionType" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:Cursor" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:DataContainer" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:DeletedResource" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:originalLocation" TEXT COLLATE NOCASE, +"nfo:originalLocation:graph" INTEGER, "nfo:deletionDate" INTEGER, +"nfo:deletionDate:graph" INTEGER, "nfo:deletionDate:localDate" +INTEGER, "nfo:deletionDate:localTime" INTEGER); +CREATE TABLE "nfo:Document" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:tableOfContents" TEXT COLLATE NOCASE, +"nfo:tableOfContents:graph" INTEGER); +CREATE TABLE "nfo:EmbeddedFileDataObject" (ID INTEGER NOT NULL PRIMARY +KEY, "nfo:encoding" TEXT COLLATE NOCASE, "nfo:encoding:graph" +INTEGER); +CREATE TABLE "nfo:Equipment" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:manufacturer" TEXT COLLATE NOCASE, "nfo:manufacturer:graph" +INTEGER, "nfo:model" TEXT COLLATE NOCASE, "nfo:model:graph" INTEGER, +"nfo:equipmentSoftware" TEXT COLLATE NOCASE, +"nfo:equipmentSoftware:graph" INTEGER); +CREATE TABLE "nfo:Executable" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:FileDataObject" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:fileLastAccessed" INTEGER, "nfo:fileLastAccessed:graph" INTEGER, +"nfo:fileLastAccessed:localDate" INTEGER, +"nfo:fileLastAccessed:localTime" INTEGER, "nfo:fileCreated" INTEGER, +"nfo:fileCreated:graph" INTEGER, "nfo:fileCreated:localDate" INTEGER, +"nfo:fileCreated:localTime" INTEGER, "nfo:fileSize" INTEGER, +"nfo:fileSize:graph" INTEGER, "nfo:permissions" TEXT COLLATE NOCASE, +"nfo:permissions:graph" INTEGER, "nfo:fileName" TEXT COLLATE NOCASE, +"nfo:fileName:graph" INTEGER, "nfo:hasHash" INTEGER, +"nfo:hasHash:graph" INTEGER, "nfo:fileOwner" INTEGER, +"nfo:fileOwner:graph" INTEGER, "nfo:fileLastModified" INTEGER, +"nfo:fileLastModified:graph" INTEGER, "nfo:fileLastModified:localDate" +INTEGER, "nfo:fileLastModified:localTime" INTEGER); +CREATE TABLE "nfo:FileHash" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:hashValue" TEXT COLLATE NOCASE, "nfo:hashValue:graph" INTEGER, +"nfo:hashAlgorithm" TEXT COLLATE NOCASE, "nfo:hashAlgorithm:graph" +INTEGER); +CREATE TABLE "nfo:Filesystem" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:FilesystemImage" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:Folder" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:Font" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:fontFamily" TEXT COLLATE NOCASE, "nfo:fontFamily:graph" INTEGER, +"nfo:foundry" INTEGER, "nfo:foundry:graph" INTEGER); +CREATE TABLE "nfo:HardDiskPartition" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:HelpDocument" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:HtmlDocument" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:Icon" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:Image" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:verticalResolution" INTEGER, "nfo:verticalResolution:graph" +INTEGER, "nfo:horizontalResolution" INTEGER, +"nfo:horizontalResolution:graph" INTEGER, "nfo:orientation" INTEGER, +"nfo:orientation:graph" INTEGER); +CREATE TABLE "nfo:Image_nfo:depicts" (ID INTEGER NOT NULL, +"nfo:depicts" INTEGER NOT NULL, "nfo:depicts:graph" INTEGER); +CREATE TABLE "nfo:Image_nfo:hasRegionOfInterest" (ID INTEGER NOT NULL, +"nfo:hasRegionOfInterest" INTEGER NOT NULL, +"nfo:hasRegionOfInterest:graph" INTEGER); +CREATE TABLE "nfo:Media" (ID INTEGER NOT NULL PRIMARY KEY, "nfo:count" +INTEGER, "nfo:count:graph" INTEGER, "nfo:duration" INTEGER, +"nfo:duration:graph" INTEGER, "nfo:compressionType" INTEGER, +"nfo:compressionType:graph" INTEGER, "nfo:hasMediaStream" INTEGER, +"nfo:hasMediaStream:graph" INTEGER, "nfo:bitDepth" INTEGER, +"nfo:bitDepth:graph" INTEGER, "nfo:codec" TEXT COLLATE NOCASE, +"nfo:codec:graph" INTEGER, "nfo:encodedBy" TEXT COLLATE NOCASE, +"nfo:encodedBy:graph" INTEGER, "nfo:bitrateType" TEXT COLLATE NOCASE, +"nfo:bitrateType:graph" INTEGER, "nfo:averageBitrate" REAL, +"nfo:averageBitrate:graph" INTEGER, "nfo:genre" TEXT COLLATE NOCASE, +"nfo:genre:graph" INTEGER, "nfo:equipment" INTEGER, +"nfo:equipment:graph" INTEGER, "nfo:lastPlayedPosition" INTEGER, +"nfo:lastPlayedPosition:graph" INTEGER, "nmm:genre" TEXT COLLATE +NOCASE, "nmm:genre:graph" INTEGER, "nmm:skipCounter" INTEGER, +"nmm:skipCounter:graph" INTEGER, "nmm:dlnaProfile" TEXT COLLATE +NOCASE, "nmm:dlnaProfile:graph" INTEGER, "nmm:dlnaMime" TEXT COLLATE +NOCASE, "nmm:dlnaMime:graph" INTEGER, "nmm:uPnPShared" INTEGER, +"nmm:uPnPShared:graph" INTEGER, "mtp:credits" TEXT COLLATE NOCASE, +"mtp:credits:graph" INTEGER, "mtp:creator" TEXT COLLATE NOCASE, +"mtp:creator:graph" INTEGER); +CREATE TABLE "nfo:MediaFileListEntry" (ID INTEGER NOT NULL PRIMARY +KEY, "nfo:listPosition" REAL, "nfo:listPosition:graph" INTEGER, +"nfo:entryUrl" TEXT COLLATE NOCASE, "nfo:entryUrl:graph" INTEGER); +CREATE TABLE "nfo:MediaList" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:entryCounter" INTEGER, "nfo:entryCounter:graph" INTEGER, +"nfo:listDuration" INTEGER, "nfo:listDuration:graph" INTEGER); +CREATE TABLE "nfo:MediaList_nfo:hasMediaFileListEntry" (ID INTEGER NOT +NULL, "nfo:hasMediaFileListEntry" INTEGER NOT NULL, +"nfo:hasMediaFileListEntry:graph" INTEGER); +CREATE TABLE "nfo:MediaList_nfo:mediaListEntry" (ID INTEGER NOT NULL, +"nfo:mediaListEntry" INTEGER NOT NULL, "nfo:mediaListEntry:graph" +INTEGER); +CREATE TABLE "nfo:MediaStream" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:Media_mtp:hidden" (ID INTEGER NOT NULL, "mtp:hidden" +INTEGER NOT NULL, "mtp:hidden:graph" INTEGER); +CREATE TABLE "nfo:Media_nmm:alternativeMedia" (ID INTEGER NOT NULL, +"nmm:alternativeMedia" INTEGER NOT NULL, "nmm:alternativeMedia:graph" +INTEGER); +CREATE TABLE "nfo:MindMap" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:Note" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:OperatingSystem" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:Orientation" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:PaginatedTextDocument" (ID INTEGER NOT NULL PRIMARY +KEY, "nfo:pageCount" INTEGER, "nfo:pageCount:graph" INTEGER); +CREATE TABLE "nfo:PlainTextDocument" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:Presentation" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:RasterImage" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:RegionOfInterest" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:regionOfInterestX" REAL, "nfo:regionOfInterestX:graph" INTEGER, +"nfo:regionOfInterestY" REAL, "nfo:regionOfInterestY:graph" INTEGER, +"nfo:regionOfInterestWidth" REAL, "nfo:regionOfInterestWidth:graph" +INTEGER, "nfo:regionOfInterestHeight" REAL, +"nfo:regionOfInterestHeight:graph" INTEGER, "nfo:regionOfInterestType" +INTEGER, "nfo:regionOfInterestType:graph" INTEGER, "nfo:roiRefersTo" +INTEGER, "nfo:roiRefersTo:graph" INTEGER); +CREATE TABLE "nfo:RegionOfInterestContent" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:RemoteDataObject" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:RemotePortAddress" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:Software" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:conflicts" INTEGER, "nfo:conflicts:graph" INTEGER, +"nfo:supercedes" INTEGER, "nfo:supercedes:graph" INTEGER, +"nfo:softwareIcon" INTEGER, "nfo:softwareIcon:graph" INTEGER, +"nfo:softwareCmdLine" TEXT COLLATE NOCASE, +"nfo:softwareCmdLine:graph" INTEGER); +CREATE TABLE "nfo:SoftwareApplication" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:SoftwareCategory" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:softwareCategoryIcon" INTEGER, "nfo:softwareCategoryIcon:graph" +INTEGER); +CREATE TABLE "nfo:SoftwareItem" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:SoftwareService" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:SourceCode" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:commentCharacterCount" INTEGER, "nfo:commentCharacterCount:graph" +INTEGER, "nfo:programmingLanguage" TEXT COLLATE NOCASE, +"nfo:programmingLanguage:graph" INTEGER, "nfo:definesClass" TEXT +COLLATE NOCASE, "nfo:definesClass:graph" INTEGER, +"nfo:definesFunction" TEXT COLLATE NOCASE, +"nfo:definesFunction:graph" INTEGER, "nfo:definesGlobalVariable" TEXT +COLLATE NOCASE, "nfo:definesGlobalVariable:graph" INTEGER); +CREATE TABLE "nfo:Spreadsheet" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:TextDocument" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:wordCount" INTEGER, "nfo:wordCount:graph" INTEGER, +"nfo:lineCount" INTEGER, "nfo:lineCount:graph" INTEGER, +"nfo:characterCount" INTEGER, "nfo:characterCount:graph" INTEGER); +CREATE TABLE "nfo:Trash" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:VectorImage" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:Video" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:frameRate" REAL, "nfo:frameRate:graph" INTEGER, "nfo:frameCount" +INTEGER, "nfo:frameCount:graph" INTEGER, "nfo:averageVideoBitrate" +REAL, "nfo:averageVideoBitrate:graph" INTEGER); +CREATE TABLE "nfo:Visual" (ID INTEGER NOT NULL PRIMARY KEY, +"nie:contentCreated" INTEGER, "nie:contentCreated:graph" INTEGER, +"nie:contentCreated:localDate" INTEGER, "nie:contentCreated:localTime" +INTEGER, "nfo:aspectRatio" REAL, "nfo:aspectRatio:graph" INTEGER, +"nfo:heading" REAL, "nfo:heading:graph" INTEGER, "nfo:tilt" REAL, +"nfo:tilt:graph" INTEGER, "nfo:interlaceMode" INTEGER, +"nfo:interlaceMode:graph" INTEGER, "nfo:height" INTEGER, +"nfo:height:graph" INTEGER, "nfo:width" INTEGER, "nfo:width:graph" +INTEGER, "nfo:colorDepth" INTEGER, "nfo:colorDepth:graph" INTEGER); +CREATE TABLE "nfo:WebHistory" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:domain" TEXT COLLATE NOCASE, "nfo:domain:graph" INTEGER, +"nfo:uri" TEXT COLLATE NOCASE, "nfo:uri:graph" INTEGER); +CREATE TABLE "nfo:Website" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nid3:ID3Audio" (ID INTEGER NOT NULL PRIMARY KEY, +"nid3:title" TEXT COLLATE NOCASE, "nid3:title:graph" INTEGER, +"nid3:albumTitle" TEXT COLLATE NOCASE, "nid3:albumTitle:graph" +INTEGER, "nid3:contentType" TEXT COLLATE NOCASE, +"nid3:contentType:graph" INTEGER, "nid3:length" INTEGER, +"nid3:length:graph" INTEGER, "nid3:recordingYear" INTEGER, +"nid3:recordingYear:graph" INTEGER, "nid3:trackNumber" TEXT COLLATE +NOCASE, "nid3:trackNumber:graph" INTEGER, "nid3:partOfSet" TEXT +COLLATE NOCASE, "nid3:partOfSet:graph" INTEGER, "nid3:comments" TEXT +COLLATE NOCASE, "nid3:comments:graph" INTEGER); +CREATE TABLE "nid3:ID3Audio_nid3:leadArtist" (ID INTEGER NOT NULL, +"nid3:leadArtist" INTEGER NOT NULL, "nid3:leadArtist:graph" INTEGER); +CREATE TABLE "nie:DataObject" (ID INTEGER NOT NULL PRIMARY KEY, +"nie:url" TEXT COLLATE NOCASE UNIQUE, "nie:url:graph" INTEGER, +"nie:byteSize" INTEGER, "nie:byteSize:graph" INTEGER, +"nie:interpretedAs" INTEGER, "nie:interpretedAs:graph" INTEGER, +"nie:lastRefreshed" INTEGER, "nie:lastRefreshed:graph" INTEGER, +"nie:lastRefreshed:localDate" INTEGER, "nie:lastRefreshed:localTime" +INTEGER, "nie:created" INTEGER, "nie:created:graph" INTEGER, +"nie:created:localDate" INTEGER, "nie:created:localTime" INTEGER, +"nfo:belongsToContainer" INTEGER, "nfo:belongsToContainer:graph" +INTEGER, "tracker:available" INTEGER, "tracker:available:graph" +INTEGER); +CREATE TABLE "nie:DataObject_nie:dataSource" (ID INTEGER NOT NULL, +"nie:dataSource" INTEGER NOT NULL, "nie:dataSource:graph" INTEGER); +CREATE TABLE "nie:DataObject_nie:isPartOf" (ID INTEGER NOT NULL, +"nie:isPartOf" INTEGER NOT NULL, "nie:isPartOf:graph" INTEGER); +CREATE TABLE "nie:DataSource" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nie:InformationElement" (ID INTEGER NOT NULL PRIMARY +KEY, "nie:title" TEXT COLLATE NOCASE, "nie:title:graph" INTEGER, +"nie:contentLastModified" INTEGER, "nie:contentLastModified:graph" +INTEGER, "nie:contentLastModified:localDate" INTEGER, +"nie:contentLastModified:localTime" INTEGER, "nie:subject" TEXT +COLLATE NOCASE, "nie:subject:graph" INTEGER, "nie:mimeType" TEXT +COLLATE NOCASE, "nie:mimeType:graph" INTEGER, "nie:language" TEXT +COLLATE NOCASE, "nie:language:graph" INTEGER, "nie:plainTextContent" +TEXT COLLATE NOCASE, "nie:plainTextContent:graph" INTEGER, +"nie:legal" TEXT COLLATE NOCASE, "nie:legal:graph" INTEGER, +"nie:generator" TEXT COLLATE NOCASE, "nie:generator:graph" INTEGER, +"nie:description" TEXT COLLATE NOCASE, "nie:description:graph" +INTEGER, "nie:disclaimer" TEXT COLLATE NOCASE, "nie:disclaimer:graph" +INTEGER, "nie:depends" INTEGER, "nie:depends:graph" INTEGER, +"nie:links" INTEGER, "nie:links:graph" INTEGER, "nie:copyright" TEXT +COLLATE NOCASE, "nie:copyright:graph" INTEGER, "nie:comment" TEXT +COLLATE NOCASE, "nie:comment:graph" INTEGER, "nie:isStoredAs" +INTEGER, "nie:isStoredAs:graph" INTEGER, "nie:version" TEXT COLLATE +NOCASE, "nie:version:graph" INTEGER, "nie:contentCreated" INTEGER, +"nie:contentCreated:graph" INTEGER, "nie:contentCreated:localDate" +INTEGER, "nie:contentCreated:localTime" INTEGER, "nie:contentAccessed" +INTEGER, "nie:contentAccessed:graph" INTEGER, +"nie:contentAccessed:localDate" INTEGER, +"nie:contentAccessed:localTime" INTEGER, "nie:license" TEXT COLLATE +NOCASE, "nie:license:graph" INTEGER, "nie:identifier" TEXT COLLATE +NOCASE, "nie:identifier:graph" INTEGER, "nie:licenseType" TEXT +COLLATE NOCASE, "nie:licenseType:graph" INTEGER, "nie:characterSet" +TEXT COLLATE NOCASE, "nie:characterSet:graph" INTEGER, +"nie:contentSize" INTEGER, "nie:contentSize:graph" INTEGER, +"nie:rootElementOf" INTEGER, "nie:rootElementOf:graph" INTEGER, +"nie:usageCounter" INTEGER, "nie:usageCounter:graph" INTEGER, +"nco:publisher" INTEGER, "nco:publisher:graph" INTEGER, +"nfo:isContentEncrypted" INTEGER, "nfo:isContentEncrypted:graph" +INTEGER, "slo:location" INTEGER, "slo:location:graph" INTEGER, +"nfo:isBootable" INTEGER, "nfo:isBootable:graph" INTEGER, "osinfo:id" +TEXT COLLATE NOCASE, "osinfo:id:graph" INTEGER, "osinfo:mediaId" TEXT +COLLATE NOCASE, "osinfo:mediaId:graph" INTEGER); +CREATE TABLE "nie:InformationElement_mlo:location" (ID INTEGER NOT +NULL, "mlo:location" INTEGER NOT NULL, "mlo:location:graph" INTEGER); +CREATE TABLE "nie:InformationElement_nao:hasProperty" (ID INTEGER NOT +NULL, "nao:hasProperty" INTEGER NOT NULL, "nao:hasProperty:graph" +INTEGER); +CREATE TABLE "nie:InformationElement_nco:contributor" (ID INTEGER NOT +NULL, "nco:contributor" INTEGER NOT NULL, "nco:contributor:graph" +INTEGER); +CREATE TABLE "nie:InformationElement_nco:creator" (ID INTEGER NOT +NULL, "nco:creator" INTEGER NOT NULL, "nco:creator:graph" INTEGER); +CREATE TABLE "nie:InformationElement_nie:hasLogicalPart" (ID INTEGER +NOT NULL, "nie:hasLogicalPart" INTEGER NOT NULL, +"nie:hasLogicalPart:graph" INTEGER); +CREATE TABLE "nie:InformationElement_nie:hasPart" (ID INTEGER NOT +NULL, "nie:hasPart" INTEGER NOT NULL, "nie:hasPart:graph" INTEGER); +CREATE TABLE "nie:InformationElement_nie:informationElementDate" (ID +INTEGER NOT NULL, "nie:informationElementDate" INTEGER NOT NULL, +"nie:informationElementDate:graph" INTEGER, +"nie:informationElementDate:localDate" INTEGER NOT NULL, +"nie:informationElementDate:localTime" INTEGER NOT NULL); +CREATE TABLE "nie:InformationElement_nie:isLogicalPartOf" (ID INTEGER +NOT NULL, "nie:isLogicalPartOf" INTEGER NOT NULL, +"nie:isLogicalPartOf:graph" INTEGER); +CREATE TABLE "nie:InformationElement_nie:keyword" (ID INTEGER NOT +NULL, "nie:keyword" TEXT NOT NULL, "nie:keyword:graph" INTEGER); +CREATE TABLE "nie:InformationElement_nie:relatedTo" (ID INTEGER NOT +NULL, "nie:relatedTo" INTEGER NOT NULL, "nie:relatedTo:graph" +INTEGER); +CREATE TABLE "nmm:AnalogRadio" (ID INTEGER NOT NULL PRIMARY KEY, +"nmm:modulation" INTEGER, "nmm:modulation:graph" INTEGER, +"nmm:frequency" INTEGER, "nmm:frequency:graph" INTEGER); +CREATE TABLE "nmm:Artist" (ID INTEGER NOT NULL PRIMARY KEY, +"nmm:artistName" TEXT COLLATE NOCASE, "nmm:artistName:graph" +INTEGER); +CREATE TABLE "nmm:DigitalRadio" (ID INTEGER NOT NULL PRIMARY KEY, +"nmm:streamingBitrate" INTEGER, "nmm:streamingBitrate:graph" INTEGER, +"nmm:encoding" TEXT COLLATE NOCASE, "nmm:encoding:graph" INTEGER, +"nmm:protocol" TEXT COLLATE NOCASE, "nmm:protocol:graph" INTEGER); +CREATE TABLE "nmm:Flash" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmm:ImageList" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmm:MeteringMode" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmm:MusicAlbum" (ID INTEGER NOT NULL PRIMARY KEY, +"nie:title" TEXT COLLATE NOCASE, "nie:title:graph" INTEGER, +"nmm:albumTrackCount" INTEGER, "nmm:albumTrackCount:graph" INTEGER, +"nmm:albumTitle" TEXT COLLATE NOCASE, "nmm:albumTitle:graph" INTEGER, +"nmm:albumDuration" INTEGER, "nmm:albumDuration:graph" INTEGER, +"nmm:albumGain" INTEGER, "nmm:albumGain:graph" INTEGER, +"nmm:albumPeakGain" INTEGER, "nmm:albumPeakGain:graph" INTEGER); +CREATE TABLE "nmm:MusicAlbumDisc" (ID INTEGER NOT NULL PRIMARY KEY, +"nmm:albumDiscAlbum" INTEGER, "nmm:albumDiscAlbum:graph" INTEGER, +"nmm:musicCDIdentifier" TEXT COLLATE NOCASE, +"nmm:musicCDIdentifier:graph" INTEGER, "nmm:setNumber" INTEGER, +"nmm:setNumber:graph" INTEGER); +CREATE TABLE "nmm:MusicAlbum_nmm:albumArtist" (ID INTEGER NOT NULL, +"nmm:albumArtist" INTEGER NOT NULL, "nmm:albumArtist:graph" INTEGER); +CREATE TABLE "nmm:MusicPiece" (ID INTEGER NOT NULL PRIMARY KEY, +"nie:title" TEXT COLLATE NOCASE, "nie:title:graph" INTEGER, +"nmm:musicAlbum" INTEGER, "nmm:musicAlbum:graph" INTEGER, +"nmm:musicAlbumDisc" INTEGER, "nmm:musicAlbumDisc:graph" INTEGER, +"nmm:beatsPerMinute" INTEGER, "nmm:beatsPerMinute:graph" INTEGER, +"nmm:performer" INTEGER, "nmm:performer:graph" INTEGER, "nmm:composer" +INTEGER, "nmm:composer:graph" INTEGER, "nmm:lyricist" INTEGER, +"nmm:lyricist:graph" INTEGER, "nmm:trackNumber" INTEGER, +"nmm:trackNumber:graph" INTEGER, +"nmm:internationalStandardRecordingCode" TEXT COLLATE NOCASE, +"nmm:internationalStandardRecordingCode:graph" INTEGER); +CREATE TABLE "nmm:MusicPiece_nmm:lyrics" (ID INTEGER NOT NULL, +"nmm:lyrics" INTEGER NOT NULL, "nmm:lyrics:graph" INTEGER); +CREATE TABLE "nmm:Photo" (ID INTEGER NOT NULL PRIMARY KEY, +"nmm:exposureTime" REAL, "nmm:exposureTime:graph" INTEGER, "nmm:flash" +INTEGER, "nmm:flash:graph" INTEGER, "nmm:fnumber" REAL, +"nmm:fnumber:graph" INTEGER, "nmm:focalLength" REAL, +"nmm:focalLength:graph" INTEGER, "nmm:isoSpeed" REAL, +"nmm:isoSpeed:graph" INTEGER, "nmm:meteringMode" INTEGER, +"nmm:meteringMode:graph" INTEGER, "nmm:whiteBalance" INTEGER, +"nmm:whiteBalance:graph" INTEGER, "nmm:isCropped" INTEGER, +"nmm:isCropped:graph" INTEGER, "nmm:isColorCorrected" INTEGER, +"nmm:isColorCorrected:graph" INTEGER); +CREATE TABLE "nmm:Playlist" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmm:RadioModulation" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmm:RadioStation" (ID INTEGER NOT NULL PRIMARY KEY, +"nmm:radioIcon" INTEGER, "nmm:radioIcon:graph" INTEGER, "nmm:radioPTY" +INTEGER, "nmm:radioPTY:graph" INTEGER); +CREATE TABLE "nmm:RadioStation_nmm:carrier" (ID INTEGER NOT NULL, +"nmm:carrier" INTEGER NOT NULL, "nmm:carrier:graph" INTEGER); +CREATE TABLE "nmm:SynchronizedText" (ID INTEGER NOT NULL PRIMARY KEY, +"nmm:isForHearingImpaired" INTEGER, "nmm:isForHearingImpaired:graph" +INTEGER); +CREATE TABLE "nmm:Video" (ID INTEGER NOT NULL PRIMARY KEY, +"nmm:videoAlbum" INTEGER, "nmm:videoAlbum:graph" INTEGER, +"nmm:isSeries" INTEGER, "nmm:isSeries:graph" INTEGER, "nmm:season" +INTEGER, "nmm:season:graph" INTEGER, "nmm:episodeNumber" INTEGER, +"nmm:episodeNumber:graph" INTEGER, "nmm:runTime" INTEGER, +"nmm:runTime:graph" INTEGER, "nmm:synopsis" TEXT COLLATE NOCASE, +"nmm:synopsis:graph" INTEGER, "nmm:MPAARating" TEXT COLLATE NOCASE, +"nmm:MPAARating:graph" INTEGER, "nmm:category" TEXT COLLATE NOCASE, +"nmm:category:graph" INTEGER, "nmm:producedBy" INTEGER, +"nmm:producedBy:graph" INTEGER, "nmm:hasSubtitle" INTEGER, +"nmm:hasSubtitle:graph" INTEGER, "nmm:isContentEncrypted" INTEGER, +"nmm:isContentEncrypted:graph" INTEGER, "mtp:fourCC" TEXT COLLATE +NOCASE, "mtp:fourCC:graph" INTEGER, "mtp:waveformat" TEXT COLLATE +NOCASE, "mtp:waveformat:graph" INTEGER); +CREATE TABLE "nmm:Video_mtp:scantype" (ID INTEGER NOT NULL, +"mtp:scantype" INTEGER NOT NULL, "mtp:scantype:graph" INTEGER); +CREATE TABLE "nmm:Video_nmm:director" (ID INTEGER NOT NULL, +"nmm:director" INTEGER NOT NULL, "nmm:director:graph" INTEGER); +CREATE TABLE "nmm:Video_nmm:leadActor" (ID INTEGER NOT NULL, +"nmm:leadActor" INTEGER NOT NULL, "nmm:leadActor:graph" INTEGER); +CREATE TABLE "nmm:Video_nmm:subtitle" (ID INTEGER NOT NULL, +"nmm:subtitle" INTEGER NOT NULL, "nmm:subtitle:graph" INTEGER); +CREATE TABLE "nmm:WhiteBalance" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmo:Attachment" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmo:Call" (ID INTEGER NOT NULL PRIMARY KEY, +"nmo:sentDate" INTEGER, "nmo:sentDate:graph" INTEGER, +"nmo:sentDate:localDate" INTEGER, "nmo:sentDate:localTime" INTEGER, +"nmo:duration" INTEGER, "nmo:duration:graph" INTEGER); +CREATE TABLE "nmo:CommunicationChannel" (ID INTEGER NOT NULL PRIMARY +KEY, "nmo:lastMessageDate" INTEGER, "nmo:lastMessageDate:graph" +INTEGER, "nmo:lastMessageDate:localDate" INTEGER, +"nmo:lastMessageDate:localTime" INTEGER, +"nmo:lastSuccessfulMessageDate" INTEGER, +"nmo:lastSuccessfulMessageDate:graph" INTEGER, +"nmo:lastSuccessfulMessageDate:localDate" INTEGER, +"nmo:lastSuccessfulMessageDate:localTime" INTEGER); +CREATE TABLE "nmo:CommunicationChannel_nmo:hasParticipant" (ID INTEGER +NOT NULL, "nmo:hasParticipant" INTEGER NOT NULL, +"nmo:hasParticipant:graph" INTEGER); +CREATE TABLE "nmo:Conversation" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmo:DeliveryStatus" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmo:Email" (ID INTEGER NOT NULL PRIMARY KEY, +"nmo:hasContent" INTEGER, "nmo:hasContent:graph" INTEGER, +"nmo:isFlagged" INTEGER, "nmo:isFlagged:graph" INTEGER, "nmo:isRecent" +INTEGER, "nmo:isRecent:graph" INTEGER, "nmo:status" TEXT COLLATE +NOCASE, "nmo:status:graph" INTEGER, "nmo:responseType" TEXT COLLATE +NOCASE, "nmo:responseType:graph" INTEGER); +CREATE TABLE "nmo:Email_nmo:contentMimeType" (ID INTEGER NOT NULL, +"nmo:contentMimeType" TEXT NOT NULL, "nmo:contentMimeType:graph" +INTEGER); +CREATE TABLE "nmo:IMMessage" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmo:MMSMessage" (ID INTEGER NOT NULL PRIMARY KEY, +"nmo:mmsHasContent" INTEGER, "nmo:mmsHasContent:graph" INTEGER); +CREATE TABLE "nmo:MailAccount" (ID INTEGER NOT NULL PRIMARY KEY, +"nmo:accountName" TEXT COLLATE NOCASE, "nmo:accountName:graph" +INTEGER, "nmo:accountDisplayName" TEXT COLLATE NOCASE, +"nmo:accountDisplayName:graph" INTEGER, "nmo:fromAddress" INTEGER, +"nmo:fromAddress:graph" INTEGER, "nmo:signature" TEXT COLLATE NOCASE, +"nmo:signature:graph" INTEGER); +CREATE TABLE "nmo:MailFolder" (ID INTEGER NOT NULL PRIMARY KEY, +"nmo:folderName" TEXT COLLATE NOCASE, "nmo:folderName:graph" INTEGER, +"nmo:serverCount" INTEGER, "nmo:serverCount:graph" INTEGER, +"nmo:serverUnreadCount" INTEGER, "nmo:serverUnreadCount:graph" +INTEGER); +CREATE TABLE "nmo:MailboxDataObject" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmo:Message" (ID INTEGER NOT NULL PRIMARY KEY, +"nmo:sentDate" INTEGER, "nmo:sentDate:graph" INTEGER, +"nmo:sentDate:localDate" INTEGER, "nmo:sentDate:localTime" INTEGER, +"nmo:from" INTEGER, "nmo:from:graph" INTEGER, "nmo:isAnswered" +INTEGER, "nmo:isAnswered:graph" INTEGER, "nmo:isDeleted" INTEGER, +"nmo:isDeleted:graph" INTEGER, "nmo:isDraft" INTEGER, +"nmo:isDraft:graph" INTEGER, "nmo:isRead" INTEGER, "nmo:isRead:graph" +INTEGER, "nmo:isSent" INTEGER, "nmo:isSent:graph" INTEGER, +"nmo:isEmergency" INTEGER, "nmo:isEmergency:graph" INTEGER, +"nmo:htmlMessageContent" TEXT COLLATE NOCASE, +"nmo:htmlMessageContent:graph" INTEGER, "nmo:messageId" TEXT COLLATE +NOCASE, "nmo:messageId:graph" INTEGER, "nmo:messageSubject" TEXT +COLLATE NOCASE, "nmo:messageSubject:graph" INTEGER, +"nmo:receivedDate" INTEGER, "nmo:receivedDate:graph" INTEGER, +"nmo:receivedDate:localDate" INTEGER, "nmo:receivedDate:localTime" +INTEGER, "nmo:replyTo" INTEGER, "nmo:replyTo:graph" INTEGER, +"nmo:sender" INTEGER, "nmo:sender:graph" INTEGER, "nmo:conversation" +INTEGER, "nmo:conversation:graph" INTEGER, "nmo:communicationChannel" +INTEGER, "nmo:communicationChannel:graph" INTEGER, +"nmo:deliveryStatus" INTEGER, "nmo:deliveryStatus:graph" INTEGER, +"nmo:reportDelivery" INTEGER, "nmo:reportDelivery:graph" INTEGER, +"nmo:sentWithReportRead" INTEGER, "nmo:sentWithReportRead:graph" +INTEGER, "nmo:reportReadStatus" INTEGER, "nmo:reportReadStatus:graph" +INTEGER, "nmo:mustAnswerReportRead" INTEGER, +"nmo:mustAnswerReportRead:graph" INTEGER, "nmo:mmsId" TEXT COLLATE +NOCASE, "nmo:mmsId:graph" INTEGER); +CREATE TABLE "nmo:MessageHeader" (ID INTEGER NOT NULL PRIMARY KEY, +"nmo:headerName" TEXT COLLATE NOCASE, "nmo:headerName:graph" INTEGER, +"nmo:headerValue" TEXT COLLATE NOCASE, "nmo:headerValue:graph" +INTEGER); +CREATE TABLE "nmo:Message_nmo:bcc" (ID INTEGER NOT NULL, "nmo:bcc" +INTEGER NOT NULL, "nmo:bcc:graph" INTEGER); +CREATE TABLE "nmo:Message_nmo:cc" (ID INTEGER NOT NULL, "nmo:cc" +INTEGER NOT NULL, "nmo:cc:graph" INTEGER); +CREATE TABLE "nmo:Message_nmo:hasAttachment" (ID INTEGER NOT NULL, +"nmo:hasAttachment" INTEGER NOT NULL, "nmo:hasAttachment:graph" +INTEGER); +CREATE TABLE "nmo:Message_nmo:inReplyTo" (ID INTEGER NOT NULL, +"nmo:inReplyTo" INTEGER NOT NULL, "nmo:inReplyTo:graph" INTEGER); +CREATE TABLE "nmo:Message_nmo:messageHeader" (ID INTEGER NOT NULL, +"nmo:messageHeader" INTEGER NOT NULL, "nmo:messageHeader:graph" +INTEGER); +CREATE TABLE "nmo:Message_nmo:recipient" (ID INTEGER NOT NULL, +"nmo:recipient" INTEGER NOT NULL, "nmo:recipient:graph" INTEGER); +CREATE TABLE "nmo:Message_nmo:references" (ID INTEGER NOT NULL, +"nmo:references" INTEGER NOT NULL, "nmo:references:graph" INTEGER); +CREATE TABLE "nmo:Message_nmo:to" (ID INTEGER NOT NULL, "nmo:to" +INTEGER NOT NULL, "nmo:to:graph" INTEGER); +CREATE TABLE "nmo:MimePart" (ID INTEGER NOT NULL PRIMARY KEY, +"nmo:charSet" TEXT COLLATE NOCASE, "nmo:charSet:graph" INTEGER, +"nmo:contentId" TEXT COLLATE NOCASE, "nmo:contentId:graph" INTEGER, +"nmo:contentTransferEncoding" TEXT COLLATE NOCASE, +"nmo:contentTransferEncoding:graph" INTEGER, "nmo:contentDescription" +TEXT COLLATE NOCASE, "nmo:contentDescription:graph" INTEGER, +"nmo:contentDisposition" TEXT COLLATE NOCASE, +"nmo:contentDisposition:graph" INTEGER); +CREATE TABLE "nmo:MimePart_nmo:mimeHeader" (ID INTEGER NOT NULL, +"nmo:mimeHeader" INTEGER NOT NULL, "nmo:mimeHeader:graph" INTEGER); +CREATE TABLE "nmo:Multipart" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmo:Multipart_nmo:partBoundary" (ID INTEGER NOT NULL, +"nmo:partBoundary" TEXT NOT NULL, "nmo:partBoundary:graph" INTEGER); +CREATE TABLE "nmo:PermanentChannel" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmo:PhoneMessage" (ID INTEGER NOT NULL PRIMARY KEY, +"nmo:fromVCard" INTEGER, "nmo:fromVCard:graph" INTEGER, "nmo:encoding" +TEXT COLLATE NOCASE, "nmo:encoding:graph" INTEGER, +"nmo:phoneMessageId" INTEGER, "nmo:phoneMessageId:graph" INTEGER, +"nmo:validityPeriod" INTEGER, "nmo:validityPeriod:graph" INTEGER); +CREATE TABLE "nmo:PhoneMessageFolder" (ID INTEGER NOT NULL PRIMARY +KEY, "nmo:phoneMessageFolderId" TEXT COLLATE NOCASE, +"nmo:phoneMessageFolderId:graph" INTEGER); +CREATE TABLE "nmo:PhoneMessageFolder_nmo:containsPhoneMessage" (ID +INTEGER NOT NULL, "nmo:containsPhoneMessage" INTEGER NOT NULL, +"nmo:containsPhoneMessage:graph" INTEGER); +CREATE TABLE "nmo:PhoneMessageFolder_nmo:containsPhoneMessageFolder" +(ID INTEGER NOT NULL, "nmo:containsPhoneMessageFolder" INTEGER NOT +NULL, "nmo:containsPhoneMessageFolder:graph" INTEGER); +CREATE TABLE "nmo:PhoneMessage_nmo:toVCard" (ID INTEGER NOT NULL, +"nmo:toVCard" INTEGER NOT NULL, "nmo:toVCard:graph" INTEGER); +CREATE TABLE "nmo:ReportReadStatus" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmo:SMSMessage" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmo:TransientChannel" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmo:VOIPCall" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nrl:InverseFunctionalProperty" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "osinfo:Installer" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "poi:ObjectOfInterest" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "rdf:Property" (ID INTEGER NOT NULL PRIMARY KEY, +"rdfs:domain" INTEGER, "rdfs:domain:graph" INTEGER, "rdfs:range" +INTEGER, "rdfs:range:graph" INTEGER, "tracker:indexed" INTEGER, +"tracker:indexed:graph" INTEGER, "tracker:secondaryIndex" INTEGER, +"tracker:secondaryIndex:graph" INTEGER, "tracker:fulltextIndexed" +INTEGER, "tracker:fulltextIndexed:graph" INTEGER, +"tracker:fulltextNoLimit" INTEGER, "tracker:fulltextNoLimit:graph" +INTEGER, "tracker:transient" INTEGER, "tracker:transient:graph" +INTEGER, "tracker:weight" INTEGER, "tracker:weight:graph" INTEGER, +"tracker:defaultValue" TEXT COLLATE NOCASE, +"tracker:defaultValue:graph" INTEGER, "nrl:maxCardinality" INTEGER, +"nrl:maxCardinality:graph" INTEGER, "tracker:writeback" INTEGER, +"tracker:writeback:graph" INTEGER, "tracker:forceJournal" INTEGER, +"tracker:forceJournal:graph" INTEGER); +CREATE TABLE "rdf:Property_rdfs:subPropertyOf" (ID INTEGER NOT NULL, +"rdfs:subPropertyOf" INTEGER NOT NULL, "rdfs:subPropertyOf:graph" +INTEGER); +CREATE TABLE "rdfs:Class" (ID INTEGER NOT NULL PRIMARY KEY, +"tracker:notify" INTEGER, "tracker:notify:graph" INTEGER); +CREATE TABLE "rdfs:Class_rdfs:subClassOf" (ID INTEGER NOT NULL, +"rdfs:subClassOf" INTEGER NOT NULL, "rdfs:subClassOf:graph" INTEGER); +CREATE TABLE "rdfs:Class_tracker:domainIndex" (ID INTEGER NOT NULL, +"tracker:domainIndex" INTEGER NOT NULL, "tracker:domainIndex:graph" +INTEGER); +CREATE TABLE "rdfs:Literal" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "rdfs:Resource" (ID INTEGER NOT NULL PRIMARY KEY, +Available INTEGER NOT NULL, "rdfs:comment" TEXT COLLATE NOCASE, +"rdfs:comment:graph" INTEGER, "rdfs:label" TEXT COLLATE NOCASE, +"rdfs:label:graph" INTEGER, "tracker:added" INTEGER, +"tracker:added:graph" INTEGER, "tracker:added:localDate" INTEGER, +"tracker:added:localTime" INTEGER, "tracker:modified" INTEGER, +"tracker:modified:graph" INTEGER, "tracker:damaged" INTEGER, +"tracker:damaged:graph" INTEGER, "dc:title" TEXT COLLATE NOCASE, +"dc:title:graph" INTEGER, "dc:creator" TEXT COLLATE NOCASE, +"dc:creator:graph" INTEGER, "dc:subject" TEXT COLLATE NOCASE, +"dc:subject:graph" INTEGER, "dc:description" TEXT COLLATE NOCASE, +"dc:description:graph" INTEGER, "dc:publisher" TEXT COLLATE NOCASE, +"dc:publisher:graph" INTEGER, "dc:type" TEXT COLLATE NOCASE, +"dc:type:graph" INTEGER, "dc:format" TEXT COLLATE NOCASE, +"dc:format:graph" INTEGER, "dc:identifier" TEXT COLLATE NOCASE, +"dc:identifier:graph" INTEGER, "dc:language" TEXT COLLATE NOCASE, +"dc:language:graph" INTEGER, "dc:coverage" TEXT COLLATE NOCASE, +"dc:coverage:graph" INTEGER, "dc:rights" TEXT COLLATE NOCASE, +"dc:rights:graph" INTEGER, "nao:identifier" TEXT COLLATE NOCASE, +"nao:identifier:graph" INTEGER, "nao:numericRating" REAL, +"nao:numericRating:graph" INTEGER, "nao:lastModified" INTEGER, +"nao:lastModified:graph" INTEGER, "nao:lastModified:localDate" +INTEGER, "nao:lastModified:localTime" INTEGER); +CREATE TABLE "rdfs:Resource_dc:contributor" (ID INTEGER NOT NULL, +"dc:contributor" TEXT NOT NULL, "dc:contributor:graph" INTEGER); +CREATE TABLE "rdfs:Resource_dc:date" (ID INTEGER NOT NULL, "dc:date" +INTEGER NOT NULL, "dc:date:graph" INTEGER, "dc:date:localDate" INTEGER +NOT NULL, "dc:date:localTime" INTEGER NOT NULL); +CREATE TABLE "rdfs:Resource_dc:relation" (ID INTEGER NOT NULL, +"dc:relation" TEXT NOT NULL, "dc:relation:graph" INTEGER); +CREATE TABLE "rdfs:Resource_dc:source" (ID INTEGER NOT NULL, +"dc:source" INTEGER NOT NULL, "dc:source:graph" INTEGER); +CREATE TABLE "rdfs:Resource_nao:deprecated" (ID INTEGER NOT NULL, +"nao:deprecated" INTEGER NOT NULL, "nao:deprecated:graph" INTEGER); +CREATE TABLE "rdfs:Resource_nao:hasTag" (ID INTEGER NOT NULL, +"nao:hasTag" INTEGER NOT NULL, "nao:hasTag:graph" INTEGER); +CREATE TABLE "rdfs:Resource_nao:isRelated" (ID INTEGER NOT NULL, +"nao:isRelated" INTEGER NOT NULL, "nao:isRelated:graph" INTEGER); +CREATE TABLE "rdfs:Resource_rdf:type" (ID INTEGER NOT NULL, "rdf:type" +INTEGER NOT NULL, "rdf:type:graph" INTEGER); +CREATE TABLE "scal:AccessLevel" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "scal:AttendanceStatus" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "scal:Attendee" (ID INTEGER NOT NULL PRIMARY KEY, +"scal:attendanceStatus" INTEGER, "scal:attendanceStatus:graph" +INTEGER, "scal:attendeeRole" INTEGER, "scal:attendeeRole:graph" +INTEGER, "scal:attendeeContact" INTEGER, "scal:attendeeContact:graph" +INTEGER, "scal:rsvp" INTEGER, "scal:rsvp:graph" INTEGER, +"scal:calendarUserType" INTEGER, "scal:calendarUserType:graph" +INTEGER); +CREATE TABLE "scal:AttendeeRole" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "scal:Attendee_scal:delegated-from" (ID INTEGER NOT NULL, +"scal:delegated-from" INTEGER NOT NULL, "scal:delegated-from:graph" +INTEGER); +CREATE TABLE "scal:Attendee_scal:delegated-to" (ID INTEGER NOT NULL, +"scal:delegated-to" INTEGER NOT NULL, "scal:delegated-to:graph" +INTEGER); +CREATE TABLE "scal:Attendee_scal:member" (ID INTEGER NOT NULL, +"scal:member" INTEGER NOT NULL, "scal:member:graph" INTEGER); +CREATE TABLE "scal:Attendee_scal:sent-by" (ID INTEGER NOT NULL, +"scal:sent-by" INTEGER NOT NULL, "scal:sent-by:graph" INTEGER); +CREATE TABLE "scal:Calendar" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "scal:CalendarAlarm" (ID INTEGER NOT NULL PRIMARY KEY, +"scal:alarmOffset" INTEGER, "scal:alarmOffset:graph" INTEGER); +CREATE TABLE "scal:CalendarAlarm_scal:alarmAttendee" (ID INTEGER NOT +NULL, "scal:alarmAttendee" INTEGER NOT NULL, +"scal:alarmAttendee:graph" INTEGER); +CREATE TABLE "scal:CalendarItem" (ID INTEGER NOT NULL PRIMARY KEY, +"scal:textLocation" INTEGER, "scal:textLocation:graph" INTEGER, +"scal:resources" TEXT COLLATE NOCASE, "scal:resources:graph" INTEGER, +"scal:transparency" INTEGER, "scal:transparency:graph" INTEGER, +"scal:calendarItemAlarm" INTEGER, "scal:calendarItemAlarm:graph" +INTEGER, "scal:start" INTEGER, "scal:start:graph" INTEGER, "scal:end" +INTEGER, "scal:end:graph" INTEGER, "scal:isAllDay" INTEGER, +"scal:isAllDay:graph" INTEGER, "scal:priority" INTEGER, +"scal:priority:graph" INTEGER, "scal:rdate" INTEGER, +"scal:rdate:graph" INTEGER, "scal:exceptionRDate" INTEGER, +"scal:exceptionRDate:graph" INTEGER); +CREATE TABLE "scal:CalendarItem_scal:access" (ID INTEGER NOT NULL, +"scal:access" INTEGER NOT NULL, "scal:access:graph" INTEGER); +CREATE TABLE "scal:CalendarItem_scal:attachment" (ID INTEGER NOT NULL, +"scal:attachment" INTEGER NOT NULL, "scal:attachment:graph" INTEGER); +CREATE TABLE "scal:CalendarItem_scal:attendee" (ID INTEGER NOT NULL, +"scal:attendee" INTEGER NOT NULL, "scal:attendee:graph" INTEGER); +CREATE TABLE "scal:CalendarItem_scal:belongsToCalendar" (ID INTEGER +NOT NULL, "scal:belongsToCalendar" INTEGER NOT NULL, +"scal:belongsToCalendar:graph" INTEGER); +CREATE TABLE "scal:CalendarItem_scal:contact" (ID INTEGER NOT NULL, +"scal:contact" INTEGER NOT NULL, "scal:contact:graph" INTEGER); +CREATE TABLE "scal:CalendarItem_scal:rrule" (ID INTEGER NOT NULL, +"scal:rrule" INTEGER NOT NULL, "scal:rrule:graph" INTEGER); +CREATE TABLE "scal:CalendarUserType" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "scal:Event" (ID INTEGER NOT NULL PRIMARY KEY, +"scal:eventStatus" INTEGER, "scal:eventStatus:graph" INTEGER); +CREATE TABLE "scal:EventStatus" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "scal:Journal" (ID INTEGER NOT NULL PRIMARY KEY, +"scal:journalStatus" INTEGER, "scal:journalStatus:graph" INTEGER); +CREATE TABLE "scal:JournalStatus" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "scal:RSVPValues" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "scal:RecurrenceRule" (ID INTEGER NOT NULL PRIMARY KEY, +"scal:recurrencePattern" TEXT COLLATE NOCASE, +"scal:recurrencePattern:graph" INTEGER, "scal:recurrenceStartDate" +INTEGER, "scal:recurrenceStartDate:graph" INTEGER, "scal:exception" +INTEGER, "scal:exception:graph" INTEGER); +CREATE TABLE "scal:TimePoint" (ID INTEGER NOT NULL PRIMARY KEY, +"scal:dateTime" INTEGER, "scal:dateTime:graph" INTEGER, +"scal:dateTime:localDate" INTEGER, "scal:dateTime:localTime" INTEGER, +"scal:TimeZone" TEXT COLLATE NOCASE, "scal:TimeZone:graph" INTEGER); +CREATE TABLE "scal:Todo" (ID INTEGER NOT NULL PRIMARY KEY, +"scal:todoStatus" INTEGER, "scal:todoStatus:graph" INTEGER, "scal:due" +INTEGER, "scal:due:graph" INTEGER, "scal:completed" INTEGER, +"scal:completed:graph" INTEGER, "scal:percentComplete" INTEGER, +"scal:percentComplete:graph" INTEGER); +CREATE TABLE "scal:TodoStatus" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "scal:TransparencyValues" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "slo:GeoLocation" (ID INTEGER NOT NULL PRIMARY KEY, +"slo:latitude" REAL, "slo:latitude:graph" INTEGER, "slo:longitude" +REAL, "slo:longitude:graph" INTEGER, "slo:verticalAccuracy" REAL, +"slo:verticalAccuracy:graph" INTEGER, "slo:horizontalAccuracy" REAL, +"slo:horizontalAccuracy:graph" INTEGER, "slo:altitude" REAL, +"slo:altitude:graph" INTEGER, "slo:boundingLatitudeMin" REAL, +"slo:boundingLatitudeMin:graph" INTEGER, "slo:boundingLatitudeMax" +REAL, "slo:boundingLatitudeMax:graph" INTEGER, +"slo:boundingLongitudeMin" REAL, "slo:boundingLongitudeMin:graph" +INTEGER, "slo:boundingLongitudeMax" REAL, +"slo:boundingLongitudeMax:graph" INTEGER, "slo:radius" REAL, +"slo:radius:graph" INTEGER, "slo:timestamp" INTEGER, +"slo:timestamp:graph" INTEGER, "slo:timestamp:localDate" INTEGER, +"slo:timestamp:localTime" INTEGER, "slo:postalAddress" INTEGER, +"slo:postalAddress:graph" INTEGER); +CREATE TABLE "slo:Landmark" (ID INTEGER NOT NULL PRIMARY KEY, +"slo:iconUrl" INTEGER, "slo:iconUrl:graph" INTEGER); +CREATE TABLE "slo:LandmarkCategory" (ID INTEGER NOT NULL PRIMARY KEY, +"slo:isRemovable" INTEGER, "slo:isRemovable:graph" INTEGER, +"slo:categoryIconUrl" INTEGER, "slo:categoryIconUrl:graph" INTEGER); +CREATE TABLE "slo:Landmark_slo:belongsToCategory" (ID INTEGER NOT +NULL, "slo:belongsToCategory" INTEGER NOT NULL, +"slo:belongsToCategory:graph" INTEGER); +CREATE TABLE "slo:Landmark_slo:hasContact" (ID INTEGER NOT NULL, +"slo:hasContact" INTEGER NOT NULL, "slo:hasContact:graph" INTEGER); +CREATE TABLE "slo:Route" (ID INTEGER NOT NULL PRIMARY KEY, +"slo:startTime" INTEGER, "slo:startTime:graph" INTEGER, +"slo:startTime:localDate" INTEGER, "slo:startTime:localTime" INTEGER, +"slo:endTime" INTEGER, "slo:endTime:graph" INTEGER, +"slo:endTime:localDate" INTEGER, "slo:endTime:localTime" INTEGER); +CREATE TABLE "slo:Route_slo:routeDetails" (ID INTEGER NOT NULL, +"slo:routeDetails" TEXT NOT NULL, "slo:routeDetails:graph" INTEGER); +CREATE TABLE "tracker:Namespace" (ID INTEGER NOT NULL PRIMARY KEY, +"tracker:prefix" TEXT COLLATE NOCASE, "tracker:prefix:graph" +INTEGER); +CREATE TABLE "tracker:Ontology" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "tracker:Volume" (ID INTEGER NOT NULL PRIMARY KEY, +"tracker:isMounted" INTEGER, "tracker:isMounted:graph" INTEGER, +"tracker:unmountDate" INTEGER, "tracker:unmountDate:graph" INTEGER, +"tracker:unmountDate:localDate" INTEGER, +"tracker:unmountDate:localTime" INTEGER, "tracker:mountPoint" INTEGER, +"tracker:mountPoint:graph" INTEGER, "tracker:isRemovable" INTEGER, +"tracker:isRemovable:graph" INTEGER, "tracker:isOptical" INTEGER, +"tracker:isOptical:graph" INTEGER); +CREATE UNIQUE INDEX "mfo:FeedMessage_mfo:enclosureList_ID_ID" ON +"mfo:FeedMessage_mfo:enclosureList" (ID, "mfo:enclosureList"); +CREATE UNIQUE INDEX "mlo:GeoBoundingBox_mlo:bbNorthWest_ID_ID" ON +"mlo:GeoBoundingBox_mlo:bbNorthWest" (ID, "mlo:bbNorthWest"); +CREATE UNIQUE INDEX "mlo:GeoBoundingBox_mlo:bbSouthEast_ID_ID" ON +"mlo:GeoBoundingBox_mlo:bbSouthEast" (ID, "mlo:bbSouthEast"); +CREATE INDEX "mlo:GeoLocation_mlo:asBoundingBox_ID" ON +"mlo:GeoLocation_mlo:asBoundingBox" (ID); +CREATE UNIQUE INDEX "mlo:GeoLocation_mlo:asBoundingBox_ID_ID" ON +"mlo:GeoLocation_mlo:asBoundingBox" ("mlo:asBoundingBox", ID); +CREATE INDEX "mlo:GeoLocation_mlo:asGeoPoint_ID" ON +"mlo:GeoLocation_mlo:asGeoPoint" (ID); +CREATE UNIQUE INDEX "mlo:GeoLocation_mlo:asGeoPoint_ID_ID" ON +"mlo:GeoLocation_mlo:asGeoPoint" ("mlo:asGeoPoint", ID); +CREATE INDEX "mlo:GeoLocation_mlo:asPostalAddress_ID" ON +"mlo:GeoLocation_mlo:asPostalAddress" (ID); +CREATE UNIQUE INDEX "mlo:GeoLocation_mlo:asPostalAddress_ID_ID" ON +"mlo:GeoLocation_mlo:asPostalAddress" ("mlo:asPostalAddress", ID); +CREATE UNIQUE INDEX "mlo:GeoPoint_mlo:address_ID_ID" ON +"mlo:GeoPoint_mlo:address" (ID, "mlo:address"); +CREATE UNIQUE INDEX "mlo:GeoPoint_mlo:altitude_ID_ID" ON +"mlo:GeoPoint_mlo:altitude" (ID, "mlo:altitude"); +CREATE UNIQUE INDEX "mlo:GeoPoint_mlo:city_ID_ID" ON +"mlo:GeoPoint_mlo:city" (ID, "mlo:city"); +CREATE UNIQUE INDEX "mlo:GeoPoint_mlo:country_ID_ID" ON +"mlo:GeoPoint_mlo:country" (ID, "mlo:country"); +CREATE UNIQUE INDEX "mlo:GeoPoint_mlo:latitude_ID_ID" ON +"mlo:GeoPoint_mlo:latitude" (ID, "mlo:latitude"); +CREATE UNIQUE INDEX "mlo:GeoPoint_mlo:longitude_ID_ID" ON +"mlo:GeoPoint_mlo:longitude" (ID, "mlo:longitude"); +CREATE UNIQUE INDEX "mlo:GeoPoint_mlo:state_ID_ID" ON +"mlo:GeoPoint_mlo:state" (ID, "mlo:state"); +CREATE UNIQUE INDEX "mlo:GeoPoint_mlo:timestamp_ID_ID" ON +"mlo:GeoPoint_mlo:timestamp" (ID, "mlo:timestamp"); +CREATE UNIQUE INDEX "mlo:GeoSphere_mlo:radius_ID_ID" ON +"mlo:GeoSphere_mlo:radius" (ID, "mlo:radius"); +CREATE UNIQUE INDEX "mlo:LandmarkCategory_mlo:isRemovable_ID_ID" ON +"mlo:LandmarkCategory_mlo:isRemovable" (ID, "mlo:isRemovable"); +CREATE UNIQUE INDEX "mlo:Landmark_mlo:belongsToCategory_ID_ID" ON +"mlo:Landmark_mlo:belongsToCategory" (ID, "mlo:belongsToCategory"); +CREATE UNIQUE INDEX "mlo:Landmark_mlo:poiLocation_ID_ID" ON +"mlo:Landmark_mlo:poiLocation" (ID, "mlo:poiLocation"); +CREATE UNIQUE INDEX "mlo:LocationBoundingBox_mlo:boxEastLimit_ID_ID" +ON "mlo:LocationBoundingBox_mlo:boxEastLimit" (ID, +"mlo:boxEastLimit"); +CREATE UNIQUE INDEX "mlo:LocationBoundingBox_mlo:boxNorthLimit_ID_ID" +ON "mlo:LocationBoundingBox_mlo:boxNorthLimit" (ID, +"mlo:boxNorthLimit"); +CREATE UNIQUE INDEX +"mlo:LocationBoundingBox_mlo:boxSouthWestCorner_ID_ID" ON +"mlo:LocationBoundingBox_mlo:boxSouthWestCorner" (ID, +"mlo:boxSouthWestCorner"); +CREATE UNIQUE INDEX +"mlo:LocationBoundingBox_mlo:boxVerticalLimit_ID_ID" ON +"mlo:LocationBoundingBox_mlo:boxVerticalLimit" (ID, +"mlo:boxVerticalLimit"); +CREATE UNIQUE INDEX "mlo:Route_mlo:endTime_ID_ID" ON +"mlo:Route_mlo:endTime" (ID, "mlo:endTime"); +CREATE UNIQUE INDEX "mlo:Route_mlo:routeDetails_ID_ID" ON +"mlo:Route_mlo:routeDetails" (ID, "mlo:routeDetails"); +CREATE UNIQUE INDEX "mlo:Route_mlo:startTime_ID_ID" ON +"mlo:Route_mlo:startTime" (ID, "mlo:startTime"); +CREATE UNIQUE INDEX "mto:Transfer_mto:transferList_ID_ID" ON +"mto:Transfer_mto:transferList" (ID, "mto:transferList"); +CREATE UNIQUE INDEX "mto:Transfer_mto:transferPrivacyLevel_ID_ID" ON +"mto:Transfer_mto:transferPrivacyLevel" (ID, +"mto:transferPrivacyLevel"); +CREATE UNIQUE INDEX "mto:UploadTransfer_mto:transferCategory_ID_ID" ON +"mto:UploadTransfer_mto:transferCategory" (ID, +"mto:transferCategory"); +CREATE UNIQUE INDEX "nao:Tag_tracker:isDefaultTag_ID_ID" ON +"nao:Tag_tracker:isDefaultTag" (ID, "tracker:isDefaultTag"); +CREATE UNIQUE INDEX "nao:Tag_tracker:tagRelatedTo_ID_ID" ON +"nao:Tag_tracker:tagRelatedTo" (ID, "tracker:tagRelatedTo"); +CREATE UNIQUE INDEX "ncal:Alarm_ncal:action_ID_ID" ON +"ncal:Alarm_ncal:action" (ID, "ncal:action"); +CREATE UNIQUE INDEX "ncal:BydayRulePart_ncal:bydayModifier_ID_ID" ON +"ncal:BydayRulePart_ncal:bydayModifier" (ID, "ncal:bydayModifier"); +CREATE UNIQUE INDEX "ncal:BydayRulePart_ncal:bydayWeekday_ID_ID" ON +"ncal:BydayRulePart_ncal:bydayWeekday" (ID, "ncal:bydayWeekday"); +CREATE UNIQUE INDEX "ncal:Calendar_ncal:component_ID_ID" ON +"ncal:Calendar_ncal:component" (ID, "ncal:component"); +CREATE UNIQUE INDEX "ncal:Freebusy_ncal:freebusy_ID_ID" ON +"ncal:Freebusy_ncal:freebusy" (ID, "ncal:freebusy"); +CREATE UNIQUE INDEX "ncal:RecurrenceRule_ncal:byday_ID_ID" ON +"ncal:RecurrenceRule_ncal:byday" (ID, "ncal:byday"); +CREATE UNIQUE INDEX "ncal:RecurrenceRule_ncal:byhour_ID_ID" ON +"ncal:RecurrenceRule_ncal:byhour" (ID, "ncal:byhour"); +CREATE UNIQUE INDEX "ncal:RecurrenceRule_ncal:byminute_ID_ID" ON +"ncal:RecurrenceRule_ncal:byminute" (ID, "ncal:byminute"); +CREATE UNIQUE INDEX "ncal:RecurrenceRule_ncal:bymonth_ID_ID" ON +"ncal:RecurrenceRule_ncal:bymonth" (ID, "ncal:bymonth"); +CREATE UNIQUE INDEX "ncal:RecurrenceRule_ncal:bymonthday_ID_ID" ON +"ncal:RecurrenceRule_ncal:bymonthday" (ID, "ncal:bymonthday"); +CREATE UNIQUE INDEX "ncal:RecurrenceRule_ncal:bysecond_ID_ID" ON +"ncal:RecurrenceRule_ncal:bysecond" (ID, "ncal:bysecond"); +CREATE UNIQUE INDEX "ncal:RecurrenceRule_ncal:bysetpos_ID_ID" ON +"ncal:RecurrenceRule_ncal:bysetpos" (ID, "ncal:bysetpos"); +CREATE UNIQUE INDEX "ncal:RecurrenceRule_ncal:byweekno_ID_ID" ON +"ncal:RecurrenceRule_ncal:byweekno" (ID, "ncal:byweekno"); +CREATE UNIQUE INDEX "ncal:RecurrenceRule_ncal:byyearday_ID_ID" ON +"ncal:RecurrenceRule_ncal:byyearday" (ID, "ncal:byyearday"); +CREATE UNIQUE INDEX "ncal:UnionParentClass_ncal:attach_ID_ID" ON +"ncal:UnionParentClass_ncal:attach" (ID, "ncal:attach"); +CREATE UNIQUE INDEX "ncal:UnionParentClass_ncal:attendee_ID_ID" ON +"ncal:UnionParentClass_ncal:attendee" (ID, "ncal:attendee"); +CREATE UNIQUE INDEX "ncal:UnionParentClass_ncal:categories_ID_ID" ON +"ncal:UnionParentClass_ncal:categories" (ID, "ncal:categories"); +CREATE UNIQUE INDEX "ncal:UnionParentClass_ncal:exdate_ID_ID" ON +"ncal:UnionParentClass_ncal:exdate" (ID, "ncal:exdate"); +CREATE UNIQUE INDEX "ncal:UnionParentClass_ncal:exrule_ID_ID" ON +"ncal:UnionParentClass_ncal:exrule" (ID, "ncal:exrule"); +CREATE UNIQUE INDEX "ncal:UnionParentClass_ncal:hasAlarm_ID_ID" ON +"ncal:UnionParentClass_ncal:hasAlarm" (ID, "ncal:hasAlarm"); +CREATE UNIQUE INDEX "ncal:UnionParentClass_ncal:ncalRelation_ID_ID" ON +"ncal:UnionParentClass_ncal:ncalRelation" (ID, "ncal:ncalRelation"); +CREATE UNIQUE INDEX "ncal:UnionParentClass_ncal:rdate_ID_ID" ON +"ncal:UnionParentClass_ncal:rdate" (ID, "ncal:rdate"); +CREATE UNIQUE INDEX "ncal:UnionParentClass_ncal:relatedToChild_ID_ID" +ON "ncal:UnionParentClass_ncal:relatedToChild" (ID, +"ncal:relatedToChild"); +CREATE UNIQUE INDEX "ncal:UnionParentClass_ncal:relatedToParent_ID_ID" +ON "ncal:UnionParentClass_ncal:relatedToParent" (ID, +"ncal:relatedToParent"); +CREATE UNIQUE INDEX "ncal:UnionParentClass_ncal:resources_ID_ID" ON +"ncal:UnionParentClass_ncal:resources" (ID, "ncal:resources"); +CREATE UNIQUE INDEX "ncal:UnionParentClass_ncal:rrule_ID_ID" ON +"ncal:UnionParentClass_ncal:rrule" (ID, "ncal:rrule"); +CREATE UNIQUE INDEX "nco:Affiliation_nco:title_ID_ID" ON +"nco:Affiliation_nco:title" (ID, "nco:title"); +CREATE UNIQUE INDEX "nco:ContactList_nco:containsContact_ID_ID" ON +"nco:ContactList_nco:containsContact" (ID, "nco:containsContact"); +CREATE UNIQUE INDEX "nco:Contact_ncal:anniversary_ID_ID" ON +"nco:Contact_ncal:anniversary" (ID, "ncal:anniversary"); +CREATE UNIQUE INDEX "nco:Contact_ncal:birthday_ID_ID" ON +"nco:Contact_ncal:birthday" (ID, "ncal:birthday"); +CREATE UNIQUE INDEX "nco:Contact_nco:belongsToGroup_ID_ID" ON +"nco:Contact_nco:belongsToGroup" (ID, "nco:belongsToGroup"); +CREATE UNIQUE INDEX "nco:Contact_nco:note_ID_ID" ON +"nco:Contact_nco:note" (ID, "nco:note"); +CREATE UNIQUE INDEX "nco:Contact_scal:anniversary_ID_ID" ON +"nco:Contact_scal:anniversary" (ID, "scal:anniversary"); +CREATE UNIQUE INDEX "nco:Contact_scal:birthday_ID_ID" ON +"nco:Contact_scal:birthday" (ID, "scal:birthday"); +CREATE UNIQUE INDEX "nco:IMAccount_nco:hasIMContact_ID_ID" ON +"nco:IMAccount_nco:hasIMContact" (ID, "nco:hasIMContact"); +CREATE UNIQUE INDEX "nco:IMAddress_nco:imCapability_ID_ID" ON +"nco:IMAddress_nco:imCapability" (ID, "nco:imCapability"); +CREATE UNIQUE INDEX "nco:PersonContact_nco:hasAffiliation_ID_ID" ON +"nco:PersonContact_nco:hasAffiliation" (ID, "nco:hasAffiliation"); +CREATE INDEX "nco:PersonContact_nco:nameFamily" ON "nco:PersonContact" +("nco:nameFamily"); +CREATE INDEX "nco:PhoneNumber_nco:phoneNumber" ON "nco:PhoneNumber" +("nco:phoneNumber"); +CREATE UNIQUE INDEX "nco:Role_nco:blogUrl_ID_ID" ON +"nco:Role_nco:blogUrl" (ID, "nco:blogUrl"); +CREATE UNIQUE INDEX "nco:Role_nco:foafUrl_ID_ID" ON +"nco:Role_nco:foafUrl" (ID, "nco:foafUrl"); +CREATE UNIQUE INDEX "nco:Role_nco:hasContactMedium_ID_ID" ON +"nco:Role_nco:hasContactMedium" (ID, "nco:hasContactMedium"); +CREATE INDEX "nco:Role_nco:hasEmailAddress_ID" ON +"nco:Role_nco:hasEmailAddress" (ID); +CREATE UNIQUE INDEX "nco:Role_nco:hasEmailAddress_ID_ID" ON +"nco:Role_nco:hasEmailAddress" ("nco:hasEmailAddress", ID); +CREATE UNIQUE INDEX "nco:Role_nco:hasIMAddress_ID_ID" ON +"nco:Role_nco:hasIMAddress" (ID, "nco:hasIMAddress"); +CREATE UNIQUE INDEX "nco:Role_nco:hasPhoneNumber_ID_ID" ON +"nco:Role_nco:hasPhoneNumber" (ID, "nco:hasPhoneNumber"); +CREATE INDEX "nco:Role_nco:hasPostalAddress_ID" ON +"nco:Role_nco:hasPostalAddress" (ID); +CREATE UNIQUE INDEX "nco:Role_nco:hasPostalAddress_ID_ID" ON +"nco:Role_nco:hasPostalAddress" ("nco:hasPostalAddress", ID); +CREATE UNIQUE INDEX "nco:Role_nco:url_ID_ID" ON "nco:Role_nco:url" +(ID, "nco:url"); +CREATE UNIQUE INDEX "nco:Role_nco:websiteUrl_ID_ID" ON +"nco:Role_nco:websiteUrl" (ID, "nco:websiteUrl"); +CREATE UNIQUE INDEX +"nfo:BookmarkFolder_nfo:containsBookmarkFolder_ID_ID" ON +"nfo:BookmarkFolder_nfo:containsBookmarkFolder" (ID, +"nfo:containsBookmarkFolder"); +CREATE UNIQUE INDEX "nfo:BookmarkFolder_nfo:containsBookmark_ID_ID" ON +"nfo:BookmarkFolder_nfo:containsBookmark" (ID, +"nfo:containsBookmark"); +CREATE INDEX "nfo:FileDataObject_nfo:fileLastModified" ON +"nfo:FileDataObject" ("nfo:fileLastModified"); +CREATE UNIQUE INDEX "nfo:Image_nfo:depicts_ID_ID" ON +"nfo:Image_nfo:depicts" (ID, "nfo:depicts"); +CREATE UNIQUE INDEX "nfo:Image_nfo:hasRegionOfInterest_ID_ID" ON +"nfo:Image_nfo:hasRegionOfInterest" (ID, "nfo:hasRegionOfInterest"); +CREATE UNIQUE INDEX "nfo:MediaList_nfo:hasMediaFileListEntry_ID_ID" ON +"nfo:MediaList_nfo:hasMediaFileListEntry" (ID, +"nfo:hasMediaFileListEntry"); +CREATE UNIQUE INDEX "nfo:MediaList_nfo:mediaListEntry_ID_ID" ON +"nfo:MediaList_nfo:mediaListEntry" (ID, "nfo:mediaListEntry"); +CREATE UNIQUE INDEX "nfo:Media_mtp:hidden_ID_ID" ON +"nfo:Media_mtp:hidden" (ID, "mtp:hidden"); +CREATE UNIQUE INDEX "nfo:Media_nmm:alternativeMedia_ID_ID" ON +"nfo:Media_nmm:alternativeMedia" (ID, "nmm:alternativeMedia"); +CREATE INDEX "nfo:Visual_nie:contentCreated" ON "nfo:Visual" +("nie:contentCreated"); +CREATE UNIQUE INDEX "nid3:ID3Audio_nid3:leadArtist_ID_ID" ON +"nid3:ID3Audio_nid3:leadArtist" (ID, "nid3:leadArtist"); +CREATE UNIQUE INDEX "nie:DataObject_nie:dataSource_ID_ID" ON +"nie:DataObject_nie:dataSource" (ID, "nie:dataSource"); +CREATE UNIQUE INDEX "nie:DataObject_nie:isPartOf_ID_ID" ON +"nie:DataObject_nie:isPartOf" (ID, "nie:isPartOf"); +CREATE INDEX "nie:DataObject_nie:url" ON "nie:DataObject" ("nie:url"); +CREATE INDEX "nie:InformationElement_mlo:location_ID" ON +"nie:InformationElement_mlo:location" (ID); +CREATE UNIQUE INDEX "nie:InformationElement_mlo:location_ID_ID" ON +"nie:InformationElement_mlo:location" ("mlo:location", ID); +CREATE UNIQUE INDEX "nie:InformationElement_nao:hasProperty_ID_ID" ON +"nie:InformationElement_nao:hasProperty" (ID, "nao:hasProperty"); +CREATE UNIQUE INDEX "nie:InformationElement_nco:contributor_ID_ID" ON +"nie:InformationElement_nco:contributor" (ID, "nco:contributor"); +CREATE UNIQUE INDEX "nie:InformationElement_nco:creator_ID_ID" ON +"nie:InformationElement_nco:creator" (ID, "nco:creator"); +CREATE UNIQUE INDEX "nie:InformationElement_nie:hasLogicalPart_ID_ID" +ON "nie:InformationElement_nie:hasLogicalPart" (ID, +"nie:hasLogicalPart"); +CREATE UNIQUE INDEX "nie:InformationElement_nie:hasPart_ID_ID" ON +"nie:InformationElement_nie:hasPart" (ID, "nie:hasPart"); +CREATE UNIQUE INDEX +"nie:InformationElement_nie:informationElementDate_ID_ID" ON +"nie:InformationElement_nie:informationElementDate" (ID, +"nie:informationElementDate"); +CREATE UNIQUE INDEX "nie:InformationElement_nie:isLogicalPartOf_ID_ID" +ON "nie:InformationElement_nie:isLogicalPartOf" (ID, +"nie:isLogicalPartOf"); +CREATE UNIQUE INDEX "nie:InformationElement_nie:keyword_ID_ID" ON +"nie:InformationElement_nie:keyword" (ID, "nie:keyword"); +CREATE UNIQUE INDEX "nie:InformationElement_nie:relatedTo_ID_ID" ON +"nie:InformationElement_nie:relatedTo" (ID, "nie:relatedTo"); +CREATE INDEX "nie:InformationElement_slo:location" ON +"nie:InformationElement" ("slo:location"); +CREATE INDEX "nmm:Artist_nmm:artistName" ON "nmm:Artist" ("nmm:artistName"); +CREATE INDEX "nmm:MusicAlbum_nie:title" ON "nmm:MusicAlbum" ("nie:title"); +CREATE UNIQUE INDEX "nmm:MusicAlbum_nmm:albumArtist_ID_ID" ON +"nmm:MusicAlbum_nmm:albumArtist" (ID, "nmm:albumArtist"); +CREATE INDEX "nmm:MusicPiece_nie:title" ON "nmm:MusicPiece" ("nie:title"); +CREATE UNIQUE INDEX "nmm:MusicPiece_nmm:lyrics_ID_ID" ON +"nmm:MusicPiece_nmm:lyrics" (ID, "nmm:lyrics"); +CREATE INDEX "nmm:MusicPiece_nmm:musicAlbum" ON "nmm:MusicPiece" +("nmm:musicAlbum"); +CREATE INDEX "nmm:MusicPiece_nmm:performer" ON "nmm:MusicPiece" +("nmm:performer"); +CREATE UNIQUE INDEX "nmm:RadioStation_nmm:carrier_ID_ID" ON +"nmm:RadioStation_nmm:carrier" (ID, "nmm:carrier"); +CREATE UNIQUE INDEX "nmm:Video_mtp:scantype_ID_ID" ON +"nmm:Video_mtp:scantype" (ID, "mtp:scantype"); +CREATE UNIQUE INDEX "nmm:Video_nmm:director_ID_ID" ON +"nmm:Video_nmm:director" (ID, "nmm:director"); +CREATE UNIQUE INDEX "nmm:Video_nmm:leadActor_ID_ID" ON +"nmm:Video_nmm:leadActor" (ID, "nmm:leadActor"); +CREATE UNIQUE INDEX "nmm:Video_nmm:subtitle_ID_ID" ON +"nmm:Video_nmm:subtitle" (ID, "nmm:subtitle"); +CREATE INDEX "nmo:Call_nmo:sentDate" ON "nmo:Call" ("nmo:sentDate"); +CREATE INDEX "nmo:CommunicationChannel_nmo:hasParticipant_ID" ON +"nmo:CommunicationChannel_nmo:hasParticipant" (ID); +CREATE UNIQUE INDEX +"nmo:CommunicationChannel_nmo:hasParticipant_ID_ID" ON +"nmo:CommunicationChannel_nmo:hasParticipant" ("nmo:hasParticipant", +ID); +CREATE INDEX "nmo:CommunicationChannel_nmo:lastMessageDate" ON +"nmo:CommunicationChannel" ("nmo:lastMessageDate"); +CREATE UNIQUE INDEX "nmo:Email_nmo:contentMimeType_ID_ID" ON +"nmo:Email_nmo:contentMimeType" (ID, "nmo:contentMimeType"); +CREATE UNIQUE INDEX "nmo:Message_nmo:bcc_ID_ID" ON +"nmo:Message_nmo:bcc" (ID, "nmo:bcc"); +CREATE UNIQUE INDEX "nmo:Message_nmo:cc_ID_ID" ON "nmo:Message_nmo:cc" +(ID, "nmo:cc"); +CREATE INDEX "nmo:Message_nmo:communicationChannel" ON "nmo:Message" +("nmo:communicationChannel", "nmo:receivedDate"); +CREATE INDEX "nmo:Message_nmo:conversation" ON "nmo:Message" +("nmo:conversation"); +CREATE INDEX "nmo:Message_nmo:from" ON "nmo:Message" ("nmo:from"); +CREATE UNIQUE INDEX "nmo:Message_nmo:hasAttachment_ID_ID" ON +"nmo:Message_nmo:hasAttachment" (ID, "nmo:hasAttachment"); +CREATE UNIQUE INDEX "nmo:Message_nmo:inReplyTo_ID_ID" ON +"nmo:Message_nmo:inReplyTo" (ID, "nmo:inReplyTo"); +CREATE UNIQUE INDEX "nmo:Message_nmo:messageHeader_ID_ID" ON +"nmo:Message_nmo:messageHeader" (ID, "nmo:messageHeader"); +CREATE UNIQUE INDEX "nmo:Message_nmo:recipient_ID_ID" ON +"nmo:Message_nmo:recipient" (ID, "nmo:recipient"); +CREATE UNIQUE INDEX "nmo:Message_nmo:references_ID_ID" ON +"nmo:Message_nmo:references" (ID, "nmo:references"); +CREATE INDEX "nmo:Message_nmo:sender" ON "nmo:Message" ("nmo:sender"); +CREATE INDEX "nmo:Message_nmo:sentDate" ON "nmo:Message" ("nmo:sentDate"); +CREATE INDEX "nmo:Message_nmo:to_ID" ON "nmo:Message_nmo:to" (ID); +CREATE UNIQUE INDEX "nmo:Message_nmo:to_ID_ID" ON "nmo:Message_nmo:to" +("nmo:to", ID); +CREATE UNIQUE INDEX "nmo:MimePart_nmo:mimeHeader_ID_ID" ON +"nmo:MimePart_nmo:mimeHeader" (ID, "nmo:mimeHeader"); +CREATE UNIQUE INDEX "nmo:Multipart_nmo:partBoundary_ID_ID" ON +"nmo:Multipart_nmo:partBoundary" (ID, "nmo:partBoundary"); +CREATE UNIQUE INDEX +"nmo:PhoneMessageFolder_nmo:containsPhoneMessageFolder_ID_ID" ON +"nmo:PhoneMessageFolder_nmo:containsPhoneMessageFolder" (ID, +"nmo:containsPhoneMessageFolder"); +CREATE UNIQUE INDEX +"nmo:PhoneMessageFolder_nmo:containsPhoneMessage_ID_ID" ON +"nmo:PhoneMessageFolder_nmo:containsPhoneMessage" (ID, +"nmo:containsPhoneMessage"); +CREATE UNIQUE INDEX "nmo:PhoneMessage_nmo:toVCard_ID_ID" ON +"nmo:PhoneMessage_nmo:toVCard" (ID, "nmo:toVCard"); +CREATE UNIQUE INDEX "rdf:Property_rdfs:subPropertyOf_ID_ID" ON +"rdf:Property_rdfs:subPropertyOf" (ID, "rdfs:subPropertyOf"); +CREATE UNIQUE INDEX "rdfs:Class_rdfs:subClassOf_ID_ID" ON +"rdfs:Class_rdfs:subClassOf" (ID, "rdfs:subClassOf"); +CREATE UNIQUE INDEX "rdfs:Class_tracker:domainIndex_ID_ID" ON +"rdfs:Class_tracker:domainIndex" (ID, "tracker:domainIndex"); +CREATE UNIQUE INDEX "rdfs:Resource_dc:contributor_ID_ID" ON +"rdfs:Resource_dc:contributor" (ID, "dc:contributor"); +CREATE UNIQUE INDEX "rdfs:Resource_dc:date_ID_ID" ON +"rdfs:Resource_dc:date" (ID, "dc:date"); +CREATE UNIQUE INDEX "rdfs:Resource_dc:relation_ID_ID" ON +"rdfs:Resource_dc:relation" (ID, "dc:relation"); +CREATE UNIQUE INDEX "rdfs:Resource_dc:source_ID_ID" ON +"rdfs:Resource_dc:source" (ID, "dc:source"); +CREATE UNIQUE INDEX "rdfs:Resource_nao:deprecated_ID_ID" ON +"rdfs:Resource_nao:deprecated" (ID, "nao:deprecated"); +CREATE INDEX "rdfs:Resource_nao:hasTag_ID" ON "rdfs:Resource_nao:hasTag" (ID); +CREATE UNIQUE INDEX "rdfs:Resource_nao:hasTag_ID_ID" ON +"rdfs:Resource_nao:hasTag" ("nao:hasTag", ID); +CREATE UNIQUE INDEX "rdfs:Resource_nao:isRelated_ID_ID" ON +"rdfs:Resource_nao:isRelated" (ID, "nao:isRelated"); +CREATE UNIQUE INDEX "rdfs:Resource_rdf:type_ID_ID" ON +"rdfs:Resource_rdf:type" (ID, "rdf:type"); +CREATE INDEX "rdfs:Resource_tracker:added" ON "rdfs:Resource" ("tracker:added"); +CREATE UNIQUE INDEX "scal:Attendee_scal:delegated-from_ID_ID" ON +"scal:Attendee_scal:delegated-from" (ID, "scal:delegated-from"); +CREATE UNIQUE INDEX "scal:Attendee_scal:delegated-to_ID_ID" ON +"scal:Attendee_scal:delegated-to" (ID, "scal:delegated-to"); +CREATE UNIQUE INDEX "scal:Attendee_scal:member_ID_ID" ON +"scal:Attendee_scal:member" (ID, "scal:member"); +CREATE UNIQUE INDEX "scal:Attendee_scal:sent-by_ID_ID" ON +"scal:Attendee_scal:sent-by" (ID, "scal:sent-by"); +CREATE UNIQUE INDEX "scal:CalendarAlarm_scal:alarmAttendee_ID_ID" ON +"scal:CalendarAlarm_scal:alarmAttendee" (ID, "scal:alarmAttendee"); +CREATE UNIQUE INDEX "scal:CalendarItem_scal:access_ID_ID" ON +"scal:CalendarItem_scal:access" (ID, "scal:access"); +CREATE UNIQUE INDEX "scal:CalendarItem_scal:attachment_ID_ID" ON +"scal:CalendarItem_scal:attachment" (ID, "scal:attachment"); +CREATE UNIQUE INDEX "scal:CalendarItem_scal:attendee_ID_ID" ON +"scal:CalendarItem_scal:attendee" (ID, "scal:attendee"); +CREATE UNIQUE INDEX "scal:CalendarItem_scal:belongsToCalendar_ID_ID" +ON "scal:CalendarItem_scal:belongsToCalendar" (ID, +"scal:belongsToCalendar"); +CREATE UNIQUE INDEX "scal:CalendarItem_scal:contact_ID_ID" ON +"scal:CalendarItem_scal:contact" (ID, "scal:contact"); +CREATE UNIQUE INDEX "scal:CalendarItem_scal:rrule_ID_ID" ON +"scal:CalendarItem_scal:rrule" (ID, "scal:rrule"); +CREATE INDEX "slo:GeoLocation_slo:postalAddress" ON "slo:GeoLocation" +("slo:postalAddress"); +CREATE UNIQUE INDEX "slo:Landmark_slo:belongsToCategory_ID_ID" ON +"slo:Landmark_slo:belongsToCategory" (ID, "slo:belongsToCategory"); +CREATE UNIQUE INDEX "slo:Landmark_slo:hasContact_ID_ID" ON +"slo:Landmark_slo:hasContact" (ID, "slo:hasContact"); +CREATE UNIQUE INDEX "slo:Route_slo:routeDetails_ID_ID" ON +"slo:Route_slo:routeDetails" (ID, "slo:routeDetails"); + +EXPLAIN SELECT "1_u", (SELECT "nco:fullname" FROM "nco:Contact" WHERE +ID = "1_u") COLLATE NOCASE, (SELECT "nco:nameFamily" FROM +"nco:PersonContact" WHERE ID = "1_u") COLLATE NOCASE, (SELECT +"nco:nameGiven" FROM "nco:PersonContact" WHERE ID = "1_u") +COLLATE NOCASE, (SELECT "nco:nameAdditional" FROM +"nco:PersonContact" WHERE ID = "1_u") COLLATE NOCASE, (SELECT +"nco:nameHonorificPrefix" FROM "nco:PersonContact" WHERE ID = +"1_u") COLLATE NOCASE, (SELECT "nco:nameHonorificSuffix" FROM +"nco:PersonContact" WHERE ID = "1_u") COLLATE NOCASE, (SELECT +"nco:nickname" FROM "nco:Contact" WHERE ID = "1_u") COLLATE +NOCASE, strftime("%s",(SELECT "nco:birthDate" FROM +"nco:Contact" WHERE ID = "1_u")), (SELECT "nie:url" FROM +"nie:DataObject" WHERE ID = (SELECT "nco:photo" FROM +"nco:Contact" WHERE ID = "1_u")) COLLATE NOCASE, (SELECT +GROUP_CONCAT("2_u"||? COLLATE NOCASE||COALESCE((SELECT +"nco:imProtocol" FROM "nco:IMAddress" WHERE ID = "3_u") COLLATE +NOCASE, ? COLLATE NOCASE)||? COLLATE NOCASE||COALESCE((SELECT +"nco:imID" FROM "nco:IMAddress" WHERE ID = "3_u") COLLATE +NOCASE, ? COLLATE NOCASE)||? COLLATE NOCASE||COALESCE((SELECT +"nco:imNickname" FROM "nco:IMAddress" WHERE ID = "3_u") COLLATE +NOCASE, ? COLLATE NOCASE), '\n') FROM (SELECT +"nco:PersonContact_nco:hasAffiliation2"."nco:hasAffiliation" AS +"2_u", "nco:Role_nco:hasIMAddress3"."nco:hasIMAddress" AS +"3_u" FROM "nco:PersonContact_nco:hasAffiliation" AS +"nco:PersonContact_nco:hasAffiliation2", +"nco:Role_nco:hasIMAddress" AS "nco:Role_nco:hasIMAddress3" WHERE +"1_u" = "nco:PersonContact_nco:hasAffiliation2"."ID" AND +"nco:PersonContact_nco:hasAffiliation2"."nco:hasAffiliation" = +"nco:Role_nco:hasIMAddress3"."ID")), (SELECT +GROUP_CONCAT("2_u"||? COLLATE NOCASE||(SELECT "nco:phoneNumber" +FROM "nco:PhoneNumber" WHERE ID = "4_u") COLLATE NOCASE, '\n') +FROM (SELECT "nco:PersonContact_nco:hasAffiliation4"."nco:hasAffiliation" +AS "2_u", "nco:Role_nco:hasPhoneNumber5"."nco:hasPhoneNumber" AS +"4_u" FROM "nco:PersonContact_nco:hasAffiliation" AS +"nco:PersonContact_nco:hasAffiliation4", +"nco:Role_nco:hasPhoneNumber" AS "nco:Role_nco:hasPhoneNumber5" +WHERE "1_u" = "nco:PersonContact_nco:hasAffiliation4"."ID" AND +"nco:PersonContact_nco:hasAffiliation4"."nco:hasAffiliation" = +"nco:Role_nco:hasPhoneNumber5"."ID")), (SELECT +GROUP_CONCAT("2_u"||? COLLATE NOCASE||(SELECT "nco:emailAddress" +FROM "nco:EmailAddress" WHERE ID = "5_u") COLLATE NOCASE, ',') +FROM (SELECT "nco:PersonContact_nco:hasAffiliation6"."nco:hasAffiliation" +AS "2_u", "nco:Role_nco:hasEmailAddress7"."nco:hasEmailAddress" +AS "5_u" FROM "nco:PersonContact_nco:hasAffiliation" AS +"nco:PersonContact_nco:hasAffiliation6", +"nco:Role_nco:hasEmailAddress" AS "nco:Role_nco:hasEmailAddress7" +WHERE "1_u" = "nco:PersonContact_nco:hasAffiliation6"."ID" AND +"nco:PersonContact_nco:hasAffiliation6"."nco:hasAffiliation" = +"nco:Role_nco:hasEmailAddress7"."ID")), (SELECT +GROUP_CONCAT("2_u"||? COLLATE NOCASE||COALESCE((SELECT +GROUP_CONCAT((SELECT Uri FROM Resource WHERE ID = +"nco:blogUrl"),',') FROM "nco:Role_nco:blogUrl" WHERE ID = +"2_u"), ? COLLATE NOCASE)||? COLLATE NOCASE||COALESCE((SELECT +GROUP_CONCAT((SELECT Uri FROM Resource WHERE ID = +"nco:websiteUrl"),',') FROM "nco:Role_nco:websiteUrl" WHERE ID = +"2_u"), ? COLLATE NOCASE)||? COLLATE NOCASE||COALESCE((SELECT +GROUP_CONCAT((SELECT Uri FROM Resource WHERE ID = "nco:url"),',') +FROM "nco:Role_nco:url" WHERE ID = "2_u"), ? COLLATE NOCASE), +'\n') FROM (SELECT +"nco:PersonContact_nco:hasAffiliation8"."nco:hasAffiliation" AS +"2_u" FROM "nco:PersonContact_nco:hasAffiliation" AS +"nco:PersonContact_nco:hasAffiliation8" WHERE "1_u" = +"nco:PersonContact_nco:hasAffiliation8"."ID")), (SELECT +GROUP_CONCAT("6_u", ',') FROM (SELECT +"rdfs:Resource_nao:hasTag9"."nao:hasTag" AS "6_u" FROM +"rdfs:Resource_nao:hasTag" AS "rdfs:Resource_nao:hasTag9" WHERE +"1_u" = "rdfs:Resource_nao:hasTag9"."ID")), (SELECT Uri FROM +Resource WHERE ID = "1_u"), (SELECT GROUP_CONCAT("2_u"||? COLLATE +NOCASE||COALESCE((SELECT "nco:role" FROM "nco:Affiliation" WHERE +ID = "2_u") COLLATE NOCASE, ? COLLATE NOCASE)||? COLLATE +NOCASE||COALESCE((SELECT "nco:department" FROM "nco:Affiliation" +WHERE ID = "2_u") COLLATE NOCASE, ? COLLATE NOCASE)||? COLLATE +NOCASE||COALESCE((SELECT GROUP_CONCAT("nco:title",',') FROM +"nco:Affiliation_nco:title" WHERE ID = "2_u"), ? COLLATE NOCASE), +'\n') FROM (SELECT +"nco:PersonContact_nco:hasAffiliation10"."nco:hasAffiliation" AS +"2_u" FROM "nco:PersonContact_nco:hasAffiliation" AS +"nco:PersonContact_nco:hasAffiliation10" WHERE "1_u" = +"nco:PersonContact_nco:hasAffiliation10"."ID")), (SELECT +GROUP_CONCAT("nco:note",',') FROM "nco:Contact_nco:note" WHERE ID += "1_u"), (SELECT "nco:gender" FROM "nco:PersonContact" WHERE ID += "1_u"), (SELECT GROUP_CONCAT("2_u"||? COLLATE +NOCASE||COALESCE((SELECT "nco:pobox" FROM "nco:PostalAddress" +WHERE ID = "7_u") COLLATE NOCASE, ? COLLATE NOCASE)||? COLLATE +NOCASE||COALESCE((SELECT "nco:district" FROM "nco:PostalAddress" +WHERE ID = "7_u") COLLATE NOCASE, ? COLLATE NOCASE)||? COLLATE +NOCASE||COALESCE((SELECT "nco:county" FROM "nco:PostalAddress" +WHERE ID = "7_u") COLLATE NOCASE, ? COLLATE NOCASE)||? COLLATE +NOCASE||COALESCE((SELECT "nco:locality" FROM "nco:PostalAddress" +WHERE ID = "7_u") COLLATE NOCASE, ? COLLATE NOCASE)||? COLLATE +NOCASE||COALESCE((SELECT "nco:postalcode" FROM +"nco:PostalAddress" WHERE ID = "7_u") COLLATE NOCASE, ? COLLATE +NOCASE)||? COLLATE NOCASE||COALESCE((SELECT "nco:streetAddress" +FROM "nco:PostalAddress" WHERE ID = "7_u") COLLATE NOCASE, ? +COLLATE NOCASE)||? COLLATE NOCASE||COALESCE((SELECT Uri FROM +Resource WHERE ID = (SELECT "nco:addressLocation" FROM +"nco:PostalAddress" WHERE ID = "7_u")), ? COLLATE NOCASE)||? +COLLATE NOCASE||COALESCE((SELECT "nco:extendedAddress" FROM +"nco:PostalAddress" WHERE ID = "7_u") COLLATE NOCASE, ? COLLATE +NOCASE)||? COLLATE NOCASE||COALESCE((SELECT "nco:country" FROM +"nco:PostalAddress" WHERE ID = "7_u") COLLATE NOCASE, ? COLLATE +NOCASE)||? COLLATE NOCASE||COALESCE((SELECT "nco:region" FROM +"nco:PostalAddress" WHERE ID = "7_u") COLLATE NOCASE, ? COLLATE +NOCASE), '\n') FROM (SELECT +"nco:PersonContact_nco:hasAffiliation11"."nco:hasAffiliation" AS +"2_u", "nco:Role_nco:hasPostalAddress12"."nco:hasPostalAddress" +AS "7_u" FROM "nco:PersonContact_nco:hasAffiliation" AS +"nco:PersonContact_nco:hasAffiliation11", +"nco:Role_nco:hasPostalAddress" AS +"nco:Role_nco:hasPostalAddress12" WHERE "1_u" = +"nco:PersonContact_nco:hasAffiliation11"."ID" AND +"nco:PersonContact_nco:hasAffiliation11"."nco:hasAffiliation" = +"nco:Role_nco:hasPostalAddress12"."ID")), (SELECT +GROUP_CONCAT("10_u" COLLATE NOCASE, ',') FROM (SELECT +"nie:InformationElement_nao:hasProperty13"."nao:hasProperty" AS +"8_u", "nao:Property14"."nao:propertyName" AS "9_u", +"nao:Property14"."nao:propertyValue" AS "10_u" FROM +"nie:InformationElement_nao:hasProperty" AS +"nie:InformationElement_nao:hasProperty13", "nao:Property" AS +"nao:Property14" WHERE "1_u" = +"nie:InformationElement_nao:hasProperty13"."ID" AND +"nie:InformationElement_nao:hasProperty13"."nao:hasProperty" = +"nao:Property14"."ID" AND "9_u" IS NOT NULL AND "10_u" IS NOT +NULL AND ("9_u" COLLATE NOCASE = ? COLLATE NOCASE))) FROM (SELECT +"nco:PersonContact1"."ID" AS "1_u" FROM "nco:PersonContact" AS +"nco:PersonContact1") ORDER BY "1_u"; + } +} {/.* Goto .*/} + +# Crash reported by OSS-FUZZ on 2016-11-10 +do_catchsql_test fuzz-oss1-detach { + DETACH x IS #1; +} {1 {near "#1": syntax error}} + +finish_test diff --git a/test/fuzz.test b/test/fuzz.test new file mode 100644 index 0000000..83dc79b --- /dev/null +++ b/test/fuzz.test @@ -0,0 +1,379 @@ +# 2007 May 10 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is generating semi-random strings of SQL +# (a.k.a. "fuzz") and sending it into the parser to try to +# generate errors. +# +# The tests in this file are really about testing fuzzily generated +# SQL parse-trees. The majority of the fuzzily generated SQL is +# valid as far as the parser is concerned. +# +# The most complicated trees are for SELECT statements. +# +# $Id: fuzz.test,v 1.19 2009/04/28 11:10:39 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +set ::REPEATS 5000 + +# If running quick.test, don't do so many iterations. +if {[info exists ::G(isquick)]} { + if {$::G(isquick)} { set ::REPEATS 20 } +} + +source $testdir/fuzz_common.tcl +expr srand(0) + +#---------------------------------------------------------------- +# These tests caused errors that were first caught by the tests +# in this file. They are still here. +do_test fuzz-1.1 { + execsql { + SELECT 'abc' LIKE X'ABCD'; + } +} {0} +do_test fuzz-1.2 { + execsql { + SELECT 'abc' LIKE zeroblob(10); + } +} {0} +do_test fuzz-1.3 { + execsql { + SELECT zeroblob(10) LIKE 'abc'; + } +} {0} +do_test fuzz-1.4 { + execsql { + SELECT (- -21) % NOT (456 LIKE zeroblob(10)); + } +} {0} +do_test fuzz-1.5 { + execsql { + SELECT (SELECT ( + SELECT (SELECT -2147483648) FROM (SELECT 1) ORDER BY 1 + )) + } +} {-2147483648} +do_test fuzz-1.6 { + execsql { + SELECT 'abc', zeroblob(1) FROM (SELECT 1) ORDER BY 1 + } +} [execsql {SELECT 'abc', zeroblob(1)}] + +do_test fuzz-1.7 { + execsql { + SELECT ( SELECT zeroblob(1000) FROM ( + SELECT * FROM (SELECT 'first') ORDER BY NOT 'in') + ) + } +} [execsql {SELECT zeroblob(1000)}] + +do_test fuzz-1.8 { + # Problems with opcode OP_ToText (did not account for MEM_Zero). + # Also MemExpandBlob() was marking expanded blobs as nul-terminated. + # They are not. + execsql { + SELECT CAST(zeroblob(1000) AS text); + } +} {{}} + +do_test fuzz-1.9 { + # This was causing a NULL pointer dereference of Expr.pList. + execsql { + SELECT 1 FROM (SELECT * FROM sqlite_master WHERE random()) + } +} {} + +do_test fuzz-1.10 { + # Bug in calculation of Parse.ckOffset causing an assert() + # to fail. Probably harmless. + execsql { + SELECT coalesce(1, substr( 1, 2, length('in' IN (SELECT 1)))) + } +} {1} + +do_test fuzz-1.11 { + # The literals (A, B, C, D) are not important, they are just used + # to make the EXPLAIN output easier to read. + # + # The problem here is that the EXISTS(...) expression leaves an + # extra value on the VDBE stack. This is confusing the parent and + # leads to an assert() failure when OP_Insert encounters an integer + # when it expects a record blob. + # + # Update: Any query with (LIMIT 0) was leaking stack. + # + execsql { + SELECT 'A' FROM (SELECT 'B') ORDER BY EXISTS ( + SELECT 'C' FROM (SELECT 'D' LIMIT 0) + ) + } +} {A} + +do_test fuzz-1.12.1 { + # Create a table with a single row. + execsql { + CREATE TABLE abc(b); + INSERT INTO abc VALUES('ABCDE'); + } + + # The following query was crashing. The later subquery (in the FROM) + # clause was flattened into the parent, but the code was not repairng + # the "b" reference in the other sub-query. When the query was executed, + # that "b" refered to a non-existant vdbe table-cursor. + # + execsql { + SELECT 1 IN ( SELECT b UNION SELECT 1 ) FROM (SELECT b FROM abc); + } +} {1} +do_test fuzz-1.12.2 { + # Clean up after the previous query. + execsql { + DROP TABLE abc; + } +} {} + + +do_test fuzz-1.13 { + # The problem here was that when there were more expressions in + # the ORDER BY list than the result-set list. The temporary b-tree + # used for sorting was being misconfigured in this case. + # + execsql { + SELECT 'abcd' UNION SELECT 'efgh' ORDER BY 1 ASC, 1 ASC; + } +} {abcd efgh} + +do_test fuzz-1.14.1 { + execsql { + CREATE TABLE abc(a, b, c); + INSERT INTO abc VALUES(123, 456, 789); + } + + # The [a] reference in the sub-select was causing a problem. Because + # the internal walkSelectExpr() function was not considering compound + # SELECT operators. + execsql { + SELECT 1 FROM abc + GROUP BY c HAVING EXISTS (SELECT a UNION SELECT 123); + } +} {1} +do_test fuzz-1.14.2 { + execsql { + DROP TABLE abc; + } +} {} + +# Making sure previously discovered errors have been fixed. +# +do_test fuzz-1.15 { + execsql { + SELECT hex(CAST(zeroblob(1000) AS integer)) + } +} {30} + +do_test fuzz-1.16.1 { + execsql { + CREATE TABLE abc(a, b, c); + CREATE TABLE def(a, b, c); + CREATE TABLE ghi(a, b, c); + } +} {} +do_test fuzz-1.16.2 { + catchsql { + SELECT DISTINCT EXISTS( + SELECT 1 + FROM ( + SELECT C FROM (SELECT 1) + ) + WHERE (SELECT c) + ) + FROM abc + } +} {0 {}} +do_test fuzz-1.16.3 { + catchsql { + SELECT DISTINCT substr(-456 ISNULL,zeroblob(1000), EXISTS( + SELECT DISTINCT EXISTS( + SELECT DISTINCT b FROM abc + ORDER BY EXISTS ( + SELECT DISTINCT 2147483647 UNION ALL SELECT -2147483648 + ) ASC + ) + FROM ( + SELECT c, c FROM ( + SELECT 456, 'injection' ORDER BY 56.1 ASC, -56.1 DESC + ) + ) + GROUP BY (SELECT ALL (SELECT DISTINCT 'hardware')) + HAVING ( + SELECT DISTINCT c + FROM ( + SELECT ALL -2147483648, 'experiments' + ORDER BY -56.1 ASC, -56.1 DESC + ) + GROUP BY (SELECT DISTINCT 456) IN + (SELECT DISTINCT 'injection') NOT IN (SELECT ALL -456) + HAVING EXISTS ( + SELECT ALL 'injection' + ) + ) + UNION ALL + SELECT a IN ( + SELECT -2147483647 + UNION ALL + SELECT ALL 'injection' + ) + FROM sqlite_master + ) -- end EXISTS + ) /* end SUBSTR() */, c NOTNULL ISNULL + FROM abc + ORDER BY CAST(-56.1 AS blob) ASC + } +} {0 {}} +do_test fuzz-1.16.4 { + execsql { + DROP TABLE abc; DROP TABLE def; DROP TABLE ghi; + } +} {} + +do_test fuzz-1.17 { + catchsql { + SELECT 'hardware', 56.1 NOTNULL, random()&0 + FROM ( + SELECT ALL lower(~ EXISTS ( + SELECT 1 NOT IN (SELECT ALL 1) + )), CAST(456 AS integer), -2147483647 + FROM ( + SELECT DISTINCT -456, CAST(1 AS integer) ISNULL + FROM (SELECT ALL 2147483647, typeof(2147483649)) + ) + ) + GROUP BY CAST(CAST('experiments' AS blob) AS blob) + HAVING random() + } +} {0 {hardware 1 0}} + +do_test fuzz-1.18 { + catchsql { + SELECT -2147483649 << upper('fault' NOT IN ( + SELECT ALL ( + SELECT ALL -1 + ORDER BY -2147483649 + LIMIT ( + SELECT ALL ( + SELECT 0 EXCEPT SELECT DISTINCT 'experiments' ORDER BY 1 ASC + ) + ) + OFFSET EXISTS ( + SELECT ALL + (SELECT ALL -2147483648) NOT IN ( + SELECT ALL 123456789.1234567899 + ) IN (SELECT 2147483649) + FROM sqlite_master + ) NOT IN (SELECT ALL 'The') + ) + )) + } +} {0 {{}}} + +# At one point the following INSERT statement caused an assert() to fail. +# +do_test fuzz-1.19 { + execsql { CREATE TABLE t1(a) } + catchsql { + INSERT INTO t1 VALUES( + CASE WHEN NULL THEN NULL ELSE ( SELECT 0 ORDER BY 456 ) END + ) + } +} {1 {1st ORDER BY term out of range - should be between 1 and 1}} +do_test fuzz-1.20 { + execsql { DROP TABLE t1 } +} {} + +#---------------------------------------------------------------- +# Test some fuzzily generated expressions. +# +do_fuzzy_test fuzz-2 -template { SELECT [Expr] } + +do_test fuzz-3.1 { + execsql { + CREATE TABLE abc(a, b, c); + CREATE TABLE def(a, b, c); + CREATE TABLE ghi(a, b, c); + } +} {} +set ::TableList [list abc def ghi] + +#---------------------------------------------------------------- +# Test some fuzzily generated SELECT statements. +# +do_fuzzy_test fuzz-3.2 -template {[Select]} + +#---------------------------------------------------------------- +# Insert a small amount of data into the database and then run +# some more generated SELECT statements. +# +do_test fuzz-4.1 { + execsql { + INSERT INTO abc VALUES(1, 2, 3); + INSERT INTO abc VALUES(4, 5, 6); + INSERT INTO abc VALUES(7, 8, 9); + INSERT INTO def VALUES(1, 2, 3); + INSERT INTO def VALUES(4, 5, 6); + INSERT INTO def VALUES(7, 8, 9); + INSERT INTO ghi VALUES(1, 2, 3); + INSERT INTO ghi VALUES(4, 5, 6); + INSERT INTO ghi VALUES(7, 8, 9); + CREATE INDEX abc_i ON abc(a, b, c); + CREATE INDEX def_i ON def(c, a, b); + CREATE INDEX ghi_i ON ghi(b, c, a); + } +} {} +do_fuzzy_test fuzz-4.2 -template {[Select]} + +#---------------------------------------------------------------- +# Test some fuzzy INSERT statements: +# +do_test fuzz-5.1 {execsql BEGIN} {} +do_fuzzy_test fuzz-5.2 -template {[Insert]} -errorlist table +integrity_check fuzz-5.2.integrity +do_test fuzz-5.3 {execsql COMMIT} {} +integrity_check fuzz-5.4.integrity + +#---------------------------------------------------------------- +# Now that there is data in the database, run some more SELECT +# statements +# +set ::ColumnList [list a b c] +set E {{no such col} {ambiguous column name}} +do_fuzzy_test fuzz-6.1 -template {[Select]} -errorlist $E + +#---------------------------------------------------------------- +# Run some SELECTs, INSERTs, UPDATEs and DELETEs in a transaction. +# +set E {{no such col} {ambiguous column name} {table}} +do_test fuzz-7.1 {execsql BEGIN} {} +do_fuzzy_test fuzz-7.2 -template {[Statement]} -errorlist $E +integrity_check fuzz-7.3.integrity +do_test fuzz-7.4 {execsql COMMIT} {} +integrity_check fuzz-7.5.integrity + +#---------------------------------------------------------------- +# Many CREATE and DROP TABLE statements: +# +set E [list table view duplicate {no such col} {ambiguous column name} {use DROP}] +do_fuzzy_test fuzz-8.1 -template {[CreateOrDropTableOrView]} -errorlist $E + +close $::log +finish_test diff --git a/test/fuzz2.test b/test/fuzz2.test new file mode 100644 index 0000000..51dfce1 --- /dev/null +++ b/test/fuzz2.test @@ -0,0 +1,139 @@ +# 2007 May 10 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file checks error recovery from malformed SQL strings. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + + +proc fuzzcatch {sql} { + return [lindex [catchsql $sql] 0] +} + +do_test fuzz2-1.1 { + fuzzcatch {SELECT ALL "AAAAAA" . * GROUP BY LIMIT round(1), #12} +} {1} +do_test fuzz2-2.0 { + fuzzcatch {SELECT + #100} +} {1} +do_test fuzz2-2.1 { + fuzzcatch {SELECT 1 WHERE ( #61 NOT MATCH ROUND( 1 ) )} +} {1} +do_test fuzz2-2.2 { + fuzzcatch {SELECT 1 LIMIT NOT #59 COLLATE AAAAAA NOT IN + ( "AAAAAA" NOTNULL <= x'414141414141' IS NULL , ( ROUND ( 1.0 ) ) )} +} {1} +do_test fuzz2-2.3 { + fuzzcatch {INSERT OR REPLACE INTO AAAAAA . "AAAAAA" ( "AAAAAA" ) SELECT DISTINCT * , ( SELECT #252 IN ( SELECT DISTINCT AAAAAA . * ) )} +} {1} +do_test fuzz2-2.4 { + fuzzcatch {SELECT 1 LIMIT NOT #59 COLLATE AAAAAA NOT IN round(1.0)} +} {1} +do_test fuzz2-2.5 { + fuzzcatch {SELECT( #239 )} +} {1} +do_test fuzz2-2.6 { + fuzzcatch {DELETE FROM AAAAAA WHERE #65 NOT NULL} +} {1} +do_test fuzz2-2.7 { + fuzzcatch {ATTACH ROUND( 1.0 ) in AAAAAA . "AAAAAA" AS #122 ISNULL} +} {1} +do_test fuzz2-2.8 { + fuzzcatch {SELECT 1 LIMIT #122 ISNULL} +} {1} +do_test fuzz2-2.9 { + fuzzcatch {CREATE VIEW AAAAAA . "AAAAAA" AS SELECT DISTINCT #162 IS NULL "AAAAAA"} +} {1} +do_test fuzz2-2.10 { + fuzzcatch {DELETE FROM AAAAAA WHERE #202 IS NOT NULL ISNULL} +} {1} +do_test fuzz2-2.11 { + fuzzcatch {UPDATE OR IGNORE "AAAAAA" . "AAAAAA" SET "AAAAAA" = NOT #96} +} {1} +do_test fuzz2-2.12 { + fuzzcatch {SELECT - #196} +} {1} + +ifcapable {trigger} { # Only do the following tests if triggers are enabled + +do_test fuzz2-3.0 { + fuzzcatch {CREATE TRIGGER "AAAAAA" . "AAAAAA" AFTER UPDATE OF "AAAAAA" , "AAAAAA" ON "AAAAAA" . "AAAAAA" FOR EACH ROW BEGIN UPDATE AAAAAA SET "AAAAAA" = #162; END} +} {1} +do_test fuzz2-3.1 { + fuzzcatch {CREATE TRIGGER IF NOT EXISTS "AAAAAA" UPDATE ON "AAAAAA" . AAAAAA FOR EACH ROW BEGIN DELETE FROM "AAAAAA" ; INSERT INTO AAAAAA ( "AAAAAA" ) SELECT DISTINCT "AAAAAA" "AAAAAA" , #167 AAAAAA , "AAAAAA" . * ORDER BY "AAAAAA" ASC , x'414141414141' BETWEEN RAISE ( FAIL , "AAAAAA" ) AND AAAAAA ( * ) NOT NULL DESC LIMIT AAAAAA ; REPLACE INTO AAAAAA ( AAAAAA ) VALUES ( AAAAAA ( * ) ) ; END} +} {1} +do_test fuzz2-3.2 { + fuzzcatch {CREATE TEMP TRIGGER IF NOT EXISTS AAAAAA . "AAAAAA" BEFORE UPDATE OF "AAAAAA" ON AAAAAA . "AAAAAA" BEGIN SELECT ALL * , #175 "AAAAAA" FROM "AAAAAA" . AAAAAA; END} +} {1} + +} ;# End of ifcapable {trigger} + +do_test fuzz2-4.0 { + fuzzcatch {ATTACH DATABASE #168 AS whatever} +} {1} +do_test fuzz2-4.1 { + fuzzcatch {DETACH #133} +} {1} +do_test fuzz2-5.0 { + fuzzcatch {SELECT 1 LIMIT ( SELECT DISTINCT * , AAAAAA , * , AAAAAA , "AAAAAA" . * FROM "AAAAAA" ON ROUND( 1 ) COLLATE AAAAAA OR "AAAAAA" USING ( AAAAAA , "AAAAAA" ) WHERE ROUND( 1 ) GROUP BY ORDER BY #84 ASC , #44 DESC , ( SELECT "AAAAAA" . * , "AAAAAA" . * FROM , ( ) "AAAAAA" USING ( )} +} {1} +do_test fuzz2-5.1 { + fuzzcatch {SELECT 1 WHERE 1 == AAAAAA ( * ) BETWEEN + - ~ + "AAAAAA" . AAAAAA | RAISE ( IGNORE ) COLLATE AAAAAA NOT IN ( SELECT DISTINCT "AAAAAA" . * , * , * WHERE ( SELECT ALL AAAAAA AS "AAAAAA" HAVING CAST ( "AAAAAA" . "AAAAAA" . "AAAAAA" AS AAAAAA ) ORDER BY , , IS NULL ASC , ~ AND DESC LIMIT ( ( "AAAAAA" ) NOT BETWEEN ( ) NOT IN ( ) AND AAAAAA ( ) IS NOT NULL ) OFFSET AAAAAA ( ALL , , ) ) GROUP BY ORDER BY "AAAAAA" . AAAAAA ASC , NULL IN ( SELECT UNION ALL SELECT ALL WHERE HAVING ORDER BY LIMIT UNION SELECT DISTINCT FROM ( ) WHERE + HAVING >> ORDER BY LIMIT . . , "AAAAAA" ) , CAST ( ~ "AAAAAA" . AAAAAA AS "AAAAAA" AAAAAA "AAAAAA" ( + 4294967295 , - 4294967296.0 ) ) ASC LIMIT AAAAAA INTERSECT SELECT ALL * GROUP BY , AAAAAA ( DISTINCT , ) != #241 NOT IN ( , , ) , , CTIME_KW HAVING AAAAAA ORDER BY #103 DESC , #81 ASC LIMIT AAAAAA OFFSET ~ AAAAAA ( ALL AAAAAA . AAAAAA >= AAAAAA . "AAAAAA" . "AAAAAA" ) ) NOTNULL NOT NULL} +} {1} +do_test fuzz2-5.2 { + fuzzcatch {SELECT 1 WHERE 1 == AAAAAA ( * ) BETWEEN + - ~ + "AAAAAA" . AAAAAA | RAISE ( IGNORE ) COLLATE AAAAAA NOT IN ( SELECT DISTINCT "AAAAAA" . * , * , * WHERE ( SELECT ALL AAAAAA AS "AAAAAA" HAVING CAST ( "AAAAAA" . "AAAAAA" . "AAAAAA" AS AAAAAA ) ORDER BY , , IS NULL ASC , ~ AND DESC LIMIT ( ( "AAAAAA" ) NOT BETWEEN ( ) NOT IN ( ) AND AAAAAA ( ) IS NOT NULL ) OFFSET AAAAAA ( ALL , , ) ) GROUP BY ORDER BY "AAAAAA" . AAAAAA ASC , NULL IN ( SELECT UNION ALL SELECT ALL WHERE HAVING ORDER BY LIMIT UNION SELECT DISTINCT FROM ( ) WHERE + HAVING >> ORDER BY LIMIT . . , "AAAAAA" ) , CAST ( ~ "AAAAAA" . AAAAAA AS "AAAAAA" AAAAAA "AAAAAA" ( + 4294967295 , - 4294967296.0 ) ) ASC LIMIT AAAAAA INTERSECT SELECT ALL * GROUP BY , AAAAAA ( DISTINCT , ) != #241 NOT IN ( , , ) , , CTIME_KW HAVING AAAAAA ORDER BY #103 DESC , #81 ASC LIMIT AAAAAA OFFSET ~ AAAAAA ( ALL AAAAAA . AAAAAA >= AAAAAA . "AAAAAA" . "AAAAAA" ) ) NOTNULL NOT NULL} +} {1} +do_test fuzz2-5.3 { + fuzzcatch {UPDATE "AAAAAA" SET "AAAAAA" = - EXISTS ( SELECT DISTINCT * , * ORDER BY #202 ASC , #147 , ~ AAAAAA . "AAAAAA" ASC LIMIT AAAAAA . "AAAAAA" , RAISE ( ABORT , AAAAAA ) UNION ALL SELECT DISTINCT AAAAAA . * , * FROM ( SELECT DISTINCT} +} {1} +do_test fuzz2-5.4 { + fuzzcatch {REPLACE INTO AAAAAA SELECT DISTINCT "AAAAAA" . * WHERE AAAAAA ( AAAAAA ( ) ) GROUP BY AAAAAA . AAAAAA . "AAAAAA" IN "AAAAAA" | AAAAAA ( ALL , ) ORDER BY #238, #92 DESC LIMIT 0 OFFSET - RAISE ( IGNORE ) NOT NULL > RAISE ( IGNORE ) IS NULL} +} {1} +do_test fuzz2-5.5 { + fuzzcatch {SELECT ALL * GROUP BY EXISTS ( SELECT "AAAAAA" . * , AAAAAA ( * ) AS AAAAAA FROM "AAAAAA" . "AAAAAA" AS "AAAAAA" USING ( AAAAAA , "AAAAAA" , "AAAAAA" ) WHERE AAAAAA ( DISTINCT ) - RAISE ( FAIL , "AAAAAA" ) HAVING "AAAAAA" . "AAAAAA" . AAAAAA ORDER BY #182 , #55 ) BETWEEN EXISTS ( SELECT ALL * FROM ( ( } +} {1} + +# Test cases discovered by Michal Zalewski on 2015-01-03 and reported on the +# sqlite-users mailing list. All of these cases cause segfaults in +# SQLite 3.8.7.4 and earlier. +# +do_test fuzz2-6.1 { + catchsql {SELECT n()AND+#0;} +} {1 {near "#0": syntax error}} +do_test fuzz2-6.2 { + catchsql {SELECT strftime()} +} {0 {{}}} +do_test fuzz2-6.3 { + catchsql {DETACH(SELECT group_concat(q));} +} {1 {no such column: q}} +do_test fuzz2-6.4a { + db eval {DROP TABLE IF EXISTS t0; CREATE TABLE t0(t);} + catchsql {INSERT INTO t0 SELECT strftime();} +} {0 {}} +do_test fuzz2-6.4b { + db eval {SELECT quote(t) FROM t0} +} {NULL} + +# Another test case discovered by Michal Zalewski, this on on 2015-01-22. +# Ticket 32b63d542433ca6757cd695aca42addf8ed67aa6 +# +do_test fuzz2-7.1 { + catchsql {select e.*,0 from(s,(L))e;} +} {1 {no such table: s}} +do_test fuzz2-7.2 { + catchsql {SELECT c.* FROM (a,b) AS c} +} {1 {no such table: a}} + + +finish_test diff --git a/test/fuzz3.test b/test/fuzz3.test new file mode 100644 index 0000000..bf778ed --- /dev/null +++ b/test/fuzz3.test @@ -0,0 +1,175 @@ +# 2007 May 10 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The focus +# of this file is checking the libraries response to subtly corrupting +# the database file by changing the values of pseudo-randomly selected +# bytes. +# +# $Id: fuzz3.test,v 1.3 2009/01/05 17:19:03 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# These tests deal with corrupt database files +# +database_may_be_corrupt +test_set_config_pagecache 0 0 + + +expr srand(123) + +proc rstring {n} { + set str s + while {[string length $str] < $n} { + append str [expr rand()] + } + return [string range $str 0 $n] +} + +# Return a randomly generated SQL literal. +# +proc rvalue {} { + switch -- [expr int(rand()*5)] { + 0 { # SQL NULL value. + return NULL + } + 1 { # Integer value. + return [expr int(rand()*1024)] + } + 2 { # Real value. + return [expr rand()] + } + 3 { # String value. + set n [expr int(rand()*2500)] + return "'[rstring $n]'" + } + 4 { # Blob value. + set n [expr int(rand()*2500)] + return "CAST('[rstring $n]' AS BLOB)" + } + } +} + +proc db_checksum {} { + set cksum [execsql { SELECT md5sum(a, b, c) FROM t1 }] + append cksum [execsql { SELECT md5sum(d, e, f) FROM t2 }] + set cksum +} + +# Modify a single byte in the file 'test.db' using tcl IO commands. The +# argument value, which must be an integer, determines both the offset of +# the byte that is modified, and the value that it is set to. The lower +# 8 bits of iMod determine the new byte value. The offset of the byte +# modified is the value of ($iMod >> 8). +# +# The return value is the iMod value required to restore the file +# to its original state. The command: +# +# modify_database [modify_database $x] +# +# leaves the file in the same state as it was in at the start of the +# command (assuming that the file is at least ($x>>8) bytes in size). +# +proc modify_database {iMod} { + set blob [binary format c [expr {$iMod&0xFF}]] + set offset [expr {$iMod>>8}] + + set fd [open test.db r+] + fconfigure $fd -encoding binary -translation binary + seek $fd $offset + set old_blob [read $fd 1] + seek $fd $offset + puts -nonewline $fd $blob + close $fd + + binary scan $old_blob c iOld + return [expr {($offset<<8) + ($iOld&0xFF)}] +} + +proc purge_pcache {} { + ifcapable !memorymanage { + db close + sqlite3 db test.db + } else { + sqlite3_release_memory 10000000 + } + if {[lindex [pcache_stats] 1] != 0} { + error "purge_pcache failed: [pcache_stats]" + } +} + +# This block creates a database to work with. +# +do_test fuzz3-1 { + execsql { + BEGIN; + CREATE TABLE t1(a, b, c); + CREATE TABLE t2(d, e, f); + CREATE INDEX i1 ON t1(a, b, c); + CREATE INDEX i2 ON t2(d, e, f); + } + for {set i 0} {$i < 50} {incr i} { + execsql "INSERT INTO t1 VALUES([rvalue], [rvalue], [rvalue])" + execsql "INSERT INTO t2 VALUES([rvalue], [rvalue], [rvalue])" + } + execsql COMMIT +} {} + +set ::cksum [db_checksum] +do_test fuzz3-2 { + db_checksum +} $::cksum + +for {set ii 0} {$ii < 5000} {incr ii} { + purge_pcache + + # Randomly modify a single byte of the database file somewhere within + # the first 100KB of the file. + set iNew [expr int(rand()*5*1024*256)] + set iOld [modify_database $iNew] + + set iTest 0 + foreach sql { + {SELECT * FROM t2 ORDER BY d} + {SELECT * FROM t1} + {SELECT * FROM t2} + {SELECT * FROM t1 ORDER BY a} + {SELECT * FROM t1 WHERE a = (SELECT a FROM t1 WHERE rowid=25)} + {SELECT * FROM t2 WHERE d = (SELECT d FROM t2 WHERE rowid=1)} + {SELECT * FROM t2 WHERE d = (SELECT d FROM t2 WHERE rowid=50)} + {PRAGMA integrity_check} + } { + do_test fuzz3-$ii.$iNew.[incr iTest] { + foreach {rc msg} [catchsql $sql] {} + if {$rc == 0 + || $msg eq "database or disk is full" + || $msg eq "database disk image is malformed" + || $msg eq "file is not a database" + || [string match "malformed database schema*" $msg] + } { + set msg ok + } + set msg + } {ok} + } + + # Restore the original database file content. Test that the correct + # checksum is now returned. + # + purge_pcache + modify_database $iOld + do_test fuzz3-$ii.$iNew.[incr iTest] { + db_checksum + } $::cksum +} + +test_restore_config_pagecache +finish_test diff --git a/test/fuzz4.test b/test/fuzz4.test new file mode 100644 index 0000000..821cd16 --- /dev/null +++ b/test/fuzz4.test @@ -0,0 +1,82 @@ +# 2018-12-12 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Test cases found by Matthew Denton's fuzzer at Chrome. +# + + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +do_execsql_test fuzz4-100 { + CREATE TABLE Table0 (Col0 NOT NULL DEFAULT (CURRENT_TIME IS 1 > 1)); + INSERT OR REPLACE INTO Table0 DEFAULT VALUES ; + SELECT * FROM Table0; +} {0} + +do_execsql_test fuzz4-110 { + CREATE TABLE Table1( + Col0 TEXT DEFAULT (CASE WHEN 1 IS 3530822107858468864 + THEN 1 ELSE quote(1) IS 3530822107858468864 END) + ); + INSERT INTO Table1 DEFAULT VALUES; + SELECT * FROM Table1; +} {0} + +do_execsql_test fuzz4-200 { + CREATE TABLE Table2a( + Col0 NOT NULL DEFAULT (CURRENT_TIME IS 1 IS NOT 1 > 1) + ); + INSERT OR REPLACE INTO Table2a DEFAULT VALUES; + SELECT * FROM Table2a; +} {0} + +do_execsql_test fuzz4-210 { + CREATE TABLE Table2b (Col0 NOT NULL DEFAULT (CURRENT_TIME IS NOT FALSE)) ; + INSERT OR REPLACE INTO Table2b DEFAULT VALUES ; + SELECT * FROM Table2b; +} {1} + +do_execsql_test fuzz4-300 { + CREATE TABLE Table3 (Col0 DEFAULT (CURRENT_TIMESTAMP BETWEEN 1 AND 1)); + INSERT INTO Table3 DEFAULT VALUES; + SELECT * FROM Table3; +} {0} + +do_execsql_test fuzz4-400 { + CREATE TABLE Table4 (Col0 DEFAULT (1 BETWEEN CURRENT_TIMESTAMP AND 1)); + INSERT INTO Table4 DEFAULT VALUES; + SELECT * FROM Table4; +} {0} + +do_execsql_test fuzz4-500 { + CREATE TABLE Table5 (Col0 DEFAULT (1 BETWEEN 1 AND CURRENT_TIMESTAMP)); + INSERT INTO Table5 DEFAULT VALUES; + SELECT * FROM Table5; +} {1} + +do_execsql_test fuzz4-600 { + CREATE TEMPORARY TABLE Table6( + Col0 DEFAULT (CASE x'5d' WHEN 1 THEN + CASE CURRENT_TIMESTAMP WHEN 1 THEN 1 ELSE 1 END + ELSE CASE WHEN 1 THEN FALSE END END ) + ); + INSERT INTO temp.Table6 DEFAULT VALUES ; + SELECT * FROM Table6; +} {0} +do_execsql_test fuzz4-610 { + WITH TableX AS (SELECT DISTINCT * ORDER BY 1 , 1 COLLATE RTRIM) + DELETE FROM Table6 WHERE Col0 || +8388608 ; + SELECT * FROM Table6; +} {} + + +finish_test diff --git a/test/fuzz_common.tcl b/test/fuzz_common.tcl new file mode 100644 index 0000000..520555b --- /dev/null +++ b/test/fuzz_common.tcl @@ -0,0 +1,392 @@ +# 2007 May 10 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# $Id: fuzz_common.tcl,v 1.2 2009/01/05 19:36:30 drh Exp $ + +proc fuzz {TemplateList} { + set n [llength $TemplateList] + set i [expr {int(rand()*$n)}] + set r [uplevel 1 subst -novar [list [lindex $TemplateList $i]]] + + string map {"\n" " "} $r +} + +# Fuzzy generation primitives: +# +# Literal +# UnaryOp +# BinaryOp +# Expr +# Table +# Select +# Insert +# + +# Returns a string representing an SQL literal. +# +proc Literal {} { + set TemplateList { + 456 0 -456 1 -1 + 2147483648 2147483647 2147483649 -2147483647 -2147483648 -2147483649 + 'The' 'first' 'experiments' 'in' 'hardware' 'fault' 'injection' + zeroblob(1000) + NULL + 56.1 -56.1 + 123456789.1234567899 + } + fuzz $TemplateList +} + +# Returns a string containing an SQL unary operator (e.g. "+" or "NOT"). +# +proc UnaryOp {} { + set TemplateList {+ - NOT ~} + fuzz $TemplateList +} + +# Returns a string containing an SQL binary operator (e.g. "*" or "/"). +# +proc BinaryOp {} { + set TemplateList { + || * / % + - << >> & | < <= > >= = == != <> AND OR + LIKE GLOB {NOT LIKE} + } + fuzz $TemplateList +} + +# Return the complete text of an SQL expression. +# +set ::ExprDepth 0 +proc Expr { {c {}} } { + incr ::ExprDepth + + set TemplateList [concat $c $c $c {[Literal]}] + if {$::ExprDepth < 3} { + lappend TemplateList \ + {[Expr $c] [BinaryOp] [Expr $c]} \ + {[UnaryOp] [Expr $c]} \ + {[Expr $c] ISNULL} \ + {[Expr $c] NOTNULL} \ + {CAST([Expr $c] AS blob)} \ + {CAST([Expr $c] AS text)} \ + {CAST([Expr $c] AS integer)} \ + {CAST([Expr $c] AS real)} \ + {abs([Expr])} \ + {coalesce([Expr], [Expr])} \ + {hex([Expr])} \ + {length([Expr])} \ + {lower([Expr])} \ + {upper([Expr])} \ + {quote([Expr])} \ + {random()} \ + {randomblob(min(max([Expr],1), 500))} \ + {typeof([Expr])} \ + {substr([Expr],[Expr],[Expr])} \ + {CASE WHEN [Expr $c] THEN [Expr $c] ELSE [Expr $c] END} \ + {[Literal]} {[Literal]} {[Literal]} \ + {[Literal]} {[Literal]} {[Literal]} \ + {[Literal]} {[Literal]} {[Literal]} \ + {[Literal]} {[Literal]} {[Literal]} + } + if {$::SelectDepth < 4} { + lappend TemplateList \ + {([Select 1])} \ + {[Expr $c] IN ([Select 1])} \ + {[Expr $c] NOT IN ([Select 1])} \ + {EXISTS ([Select 1])} \ + } + set res [fuzz $TemplateList] + incr ::ExprDepth -1 + return $res +} + +# Return a valid table name. +# +set ::TableList [list] +proc Table {} { + set TemplateList [concat sqlite_master $::TableList] + fuzz $TemplateList +} + +# Return one of: +# +# "SELECT DISTINCT", "SELECT ALL" or "SELECT" +# +proc SelectKw {} { + set TemplateList { + "SELECT DISTINCT" + "SELECT ALL" + "SELECT" + } + fuzz $TemplateList +} + +# Return a result set for a SELECT statement. +# +proc ResultSet {{nRes 0} {c ""}} { + if {$nRes == 0} { + set nRes [expr {rand()*2 + 1}] + } + + set aRes [list] + for {set ii 0} {$ii < $nRes} {incr ii} { + lappend aRes [Expr $c] + } + + join $aRes ", " +} + +set ::SelectDepth 0 +set ::ColumnList [list] +proc SimpleSelect {{nRes 0}} { + + set TemplateList { + {[SelectKw] [ResultSet $nRes]} + } + + # The ::SelectDepth variable contains the number of ancestor SELECT + # statements (i.e. for a top level SELECT it is set to 0, for a + # sub-select 1, for a sub-select of a sub-select 2 etc.). + # + # If this is already greater than 3, do not generate a complicated + # SELECT statement. This tends to cause parser stack overflow (too + # boring to bother with). + # + if {$::SelectDepth < 4} { + lappend TemplateList \ + {[SelectKw] [ResultSet $nRes $::ColumnList] FROM ([Select])} \ + {[SelectKw] [ResultSet $nRes] FROM ([Select])} \ + {[SelectKw] [ResultSet $nRes $::ColumnList] FROM [Table]} \ + { + [SelectKw] [ResultSet $nRes $::ColumnList] + FROM ([Select]) + GROUP BY [Expr] + HAVING [Expr] + } \ + + if {0 == $nRes} { + lappend TemplateList \ + {[SelectKw] * FROM ([Select])} \ + {[SelectKw] * FROM [Table]} \ + {[SelectKw] * FROM [Table] WHERE [Expr $::ColumnList]} \ + { + [SelectKw] * + FROM [Table],[Table] AS t2 + WHERE [Expr $::ColumnList] + } { + [SelectKw] * + FROM [Table] LEFT OUTER JOIN [Table] AS t2 + ON [Expr $::ColumnList] + WHERE [Expr $::ColumnList] + } + } + } + + fuzz $TemplateList +} + +# Return a SELECT statement. +# +# If boolean parameter $isExpr is set to true, make sure the +# returned SELECT statement returns a single column of data. +# +proc Select {{nMulti 0}} { + set TemplateList { + {[SimpleSelect $nMulti]} {[SimpleSelect $nMulti]} {[SimpleSelect $nMulti]} + {[SimpleSelect $nMulti]} {[SimpleSelect $nMulti]} {[SimpleSelect $nMulti]} + {[SimpleSelect $nMulti]} {[SimpleSelect $nMulti]} {[SimpleSelect $nMulti]} + {[SimpleSelect $nMulti]} {[SimpleSelect $nMulti]} {[SimpleSelect $nMulti]} + {[SimpleSelect $nMulti] ORDER BY [Expr] DESC} + {[SimpleSelect $nMulti] ORDER BY [Expr] ASC} + {[SimpleSelect $nMulti] ORDER BY [Expr] ASC, [Expr] DESC} + {[SimpleSelect $nMulti] ORDER BY [Expr] LIMIT [Expr] OFFSET [Expr]} + } + + if {$::SelectDepth < 4} { + if {$nMulti == 0} { + set nMulti [expr {(rand()*2)+1}] + } + lappend TemplateList \ + {[SimpleSelect $nMulti] UNION [Select $nMulti]} \ + {[SimpleSelect $nMulti] UNION ALL [Select $nMulti]} \ + {[SimpleSelect $nMulti] EXCEPT [Select $nMulti]} \ + {[SimpleSelect $nMulti] INTERSECT [Select $nMulti]} + } + + incr ::SelectDepth + set res [fuzz $TemplateList] + incr ::SelectDepth -1 + set res +} + +# Generate and return a fuzzy INSERT statement. +# +proc Insert {} { + set TemplateList { + {INSERT INTO [Table] VALUES([Expr], [Expr], [Expr]);} + {INSERT INTO [Table] VALUES([Expr], [Expr], [Expr], [Expr]);} + {INSERT INTO [Table] VALUES([Expr], [Expr]);} + } + fuzz $TemplateList +} + +proc Column {} { + fuzz $::ColumnList +} + +# Generate and return a fuzzy UPDATE statement. +# +proc Update {} { + set TemplateList { + {UPDATE [Table] + SET [Column] = [Expr $::ColumnList] + WHERE [Expr $::ColumnList]} + } + fuzz $TemplateList +} + +proc Delete {} { + set TemplateList { + {DELETE FROM [Table] WHERE [Expr $::ColumnList]} + } + fuzz $TemplateList +} + +proc Statement {} { + set TemplateList { + {[Update]} + {[Insert]} + {[Select]} + {[Delete]} + } + fuzz $TemplateList +} + +# Return an identifier. This just chooses randomly from a fixed set +# of strings. +proc Identifier {} { + set TemplateList { + This just chooses randomly a fixed + We would also thank the developers + for their analysis Samba + } + fuzz $TemplateList +} + +proc Check {} { + # Use a large value for $::SelectDepth, because sub-selects are + # not allowed in expressions used by CHECK constraints. + # + set sd $::SelectDepth + set ::SelectDepth 500 + set TemplateList { + {} + {CHECK ([Expr])} + } + set res [fuzz $TemplateList] + set ::SelectDepth $sd + set res +} + +proc Coltype {} { + set TemplateList { + {INTEGER PRIMARY KEY} + {VARCHAR [Check]} + {PRIMARY KEY} + } + fuzz $TemplateList +} + +proc DropTable {} { + set TemplateList { + {DROP TABLE IF EXISTS [Identifier]} + } + fuzz $TemplateList +} + +proc CreateView {} { + set TemplateList { + {CREATE VIEW [Identifier] AS [Select]} + } + fuzz $TemplateList +} +proc DropView {} { + set TemplateList { + {DROP VIEW IF EXISTS [Identifier]} + } + fuzz $TemplateList +} + +proc CreateTable {} { + set TemplateList { + {CREATE TABLE [Identifier]([Identifier] [Coltype], [Identifier] [Coltype])} + {CREATE TEMP TABLE [Identifier]([Identifier] [Coltype])} + } + fuzz $TemplateList +} + +proc CreateOrDropTableOrView {} { + set TemplateList { + {[CreateTable]} + {[DropTable]} + {[CreateView]} + {[DropView]} + } + fuzz $TemplateList +} + +######################################################################## + +set ::log [open fuzzy.log w] + +# +# Usage: do_fuzzy_test ?? +# +# -template +# -errorlist +# -repeats +# +proc do_fuzzy_test {testname args} { + set ::fuzzyopts(-errorlist) [list] + set ::fuzzyopts(-repeats) $::REPEATS + array set ::fuzzyopts $args + + lappend ::fuzzyopts(-errorlist) {parser stack overflow} + lappend ::fuzzyopts(-errorlist) {ORDER BY} + lappend ::fuzzyopts(-errorlist) {GROUP BY} + lappend ::fuzzyopts(-errorlist) {datatype mismatch} + lappend ::fuzzyopts(-errorlist) {non-deterministic functions prohibited} + + for {set ii 0} {$ii < $::fuzzyopts(-repeats)} {incr ii} { + do_test ${testname}.$ii { + set ::sql [subst $::fuzzyopts(-template)] + puts $::log $::sql + flush $::log + set rc [catch {execsql $::sql} msg] + set e 1 + if {$rc} { + set e 0 + foreach error $::fuzzyopts(-errorlist) { + if {[string first $error $msg]>=0} { + set e 1 + break + } + } + } + if {$e == 0} { + puts "" + puts $::sql + puts $msg + } + set e + } {1} + } +} diff --git a/test/fuzz_malloc.test b/test/fuzz_malloc.test new file mode 100644 index 0000000..4449ea8 --- /dev/null +++ b/test/fuzz_malloc.test @@ -0,0 +1,100 @@ +# +# 2007 May 10 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file tests malloc failures in concert with fuzzy SQL generation. +# +# $Id: fuzz_malloc.test,v 1.10 2008/08/20 16:35:10 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +source $testdir/malloc_common.tcl +source $testdir/fuzz_common.tcl + +if {[info exists G(isquick)]} { + set ::REPEATS 20 +} elseif {[info exists G(issoak)]} { + set ::REPEATS 100 +} else { + set ::REPEATS 40 +} + +# +# Usage: do_fuzzy_malloc_test ?? +# +# -template +# -sqlprep +# -repeats +# +proc do_fuzzy_malloc_test {testname args} { + set ::fuzzyopts(-repeats) $::REPEATS + set ::fuzzyopts(-sqlprep) {} + array set ::fuzzyopts $args + + sqlite3_memdebug_fail -1 + db close + delete_file test.db test.db-journal + sqlite3 db test.db + set ::prep $::fuzzyopts(-sqlprep) + execsql $::prep + set jj 0 + for {set ii 0} {$ii < $::fuzzyopts(-repeats)} {incr ii} { + expr srand($jj) + incr jj + set ::sql [subst $::fuzzyopts(-template)] + # puts fuzyy-sql=\[$::sql\]; flush stdout + foreach {rc ::fmtres} [catchsql "$::sql"] {} + if {$rc==0} { + set nErr1 [set_test_counter errors] + do_faultsim_test $testname-$ii -faults oom* -body { + execsql $::sql + } -test { + if {$testrc && $testresult!="datatype mismatch"} { + faultsim_test_result {0 {}} + } + } + if {[set_test_counter errors]>$nErr1} { + puts "Previous fuzzy-sql=\[$::sql\]" + flush stdout + } + } else { + incr ii -1 + } + } +} + +#---------------------------------------------------------------- +# Test malloc failure during parsing (and execution) of a fuzzily +# generated expressions. +# +do_fuzzy_malloc_test fuzzy_malloc-1 -template {Select [Expr]} +do_fuzzy_malloc_test fuzzy_malloc-2 -template {[Select]} + +set ::SQLPREP { + BEGIN; + CREATE TABLE abc(a, b, c); + CREATE TABLE def(a, b, c); + CREATE TABLE ghi(a, b, c); + INSERT INTO abc VALUES(1.5, 3, 'a short string'); + INSERT INTO def VALUES(NULL, X'ABCDEF', + 'a longer string. Long enough that it doesn''t fit in Mem.zShort'); + INSERT INTO ghi VALUES(zeroblob(1000), 'hello world', -1257900987654321); + COMMIT; +} +set ::TableList [list abc def ghi] +set ::ColumnList [list a b c] + +do_fuzzy_malloc_test fuzzy_malloc-3 \ + -template {[Select]} \ + -sqlprep $::SQLPREP + +finish_test diff --git a/test/fuzzcheck.c b/test/fuzzcheck.c new file mode 100644 index 0000000..dd49120 --- /dev/null +++ b/test/fuzzcheck.c @@ -0,0 +1,2557 @@ +/* +** 2015-05-25 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +************************************************************************* +** +** This is a utility program designed to aid running regressions tests on +** the SQLite library using data from external fuzzers. +** +** This program reads content from an SQLite database file with the following +** schema: +** +** CREATE TABLE db( +** dbid INTEGER PRIMARY KEY, -- database id +** dbcontent BLOB -- database disk file image +** ); +** CREATE TABLE xsql( +** sqlid INTEGER PRIMARY KEY, -- SQL script id +** sqltext TEXT -- Text of SQL statements to run +** ); +** CREATE TABLE IF NOT EXISTS readme( +** msg TEXT -- Human-readable description of this test collection +** ); +** +** For each database file in the DB table, the SQL text in the XSQL table +** is run against that database. All README.MSG values are printed prior +** to the start of the test (unless the --quiet option is used). If the +** DB table is empty, then all entries in XSQL are run against an empty +** in-memory database. +** +** This program is looking for crashes, assertion faults, and/or memory leaks. +** No attempt is made to verify the output. The assumption is that either all +** of the database files or all of the SQL statements are malformed inputs, +** generated by a fuzzer, that need to be checked to make sure they do not +** present a security risk. +** +** This program also includes some command-line options to help with +** creation and maintenance of the source content database. The command +** +** ./fuzzcheck database.db --load-sql FILE... +** +** Loads all FILE... arguments into the XSQL table. The --load-db option +** works the same but loads the files into the DB table. The -m option can +** be used to initialize the README table. The "database.db" file is created +** if it does not previously exist. Example: +** +** ./fuzzcheck new.db --load-sql *.sql +** ./fuzzcheck new.db --load-db *.db +** ./fuzzcheck new.db -m 'New test cases' +** +** The three commands above will create the "new.db" file and initialize all +** tables. Then do "./fuzzcheck new.db" to run the tests. +** +** DEBUGGING HINTS: +** +** If fuzzcheck does crash, it can be run in the debugger and the content +** of the global variable g.zTextName[] will identify the specific XSQL and +** DB values that were running when the crash occurred. +** +** DBSQLFUZZ: (Added 2020-02-25) +** +** The dbsqlfuzz fuzzer includes both a database file and SQL to run against +** that database in its input. This utility can now process dbsqlfuzz +** input files. Load such files using the "--load-dbsql FILE ..." command-line +** option. +** +** Dbsqlfuzz inputs are ordinary text. The first part of the file is text +** that describes the content of the database (using a lot of hexadecimal), +** then there is a divider line followed by the SQL to run against the +** database. Because they are ordinary text, dbsqlfuzz inputs are stored +** in the XSQL table, as if they were ordinary SQL inputs. The isDbSql() +** function can look at a text string and determine whether or not it is +** a valid dbsqlfuzz input. +*/ +#include +#include +#include +#include +#include +#include +#include "sqlite3.h" +#include "sqlite3recover.h" +#define ISSPACE(X) isspace((unsigned char)(X)) +#define ISDIGIT(X) isdigit((unsigned char)(X)) + + +#ifdef __unix__ +# include +# include +#endif + +#include +#if !defined(_MSC_VER) +# include +#endif + +#if defined(_MSC_VER) +typedef unsigned char uint8_t; +#endif + +/* +** Files in the virtual file system. +*/ +typedef struct VFile VFile; +struct VFile { + char *zFilename; /* Filename. NULL for delete-on-close. From malloc() */ + int sz; /* Size of the file in bytes */ + int nRef; /* Number of references to this file */ + unsigned char *a; /* Content of the file. From malloc() */ +}; +typedef struct VHandle VHandle; +struct VHandle { + sqlite3_file base; /* Base class. Must be first */ + VFile *pVFile; /* The underlying file */ +}; + +/* +** The value of a database file template, or of an SQL script +*/ +typedef struct Blob Blob; +struct Blob { + Blob *pNext; /* Next in a list */ + int id; /* Id of this Blob */ + int seq; /* Sequence number */ + int sz; /* Size of this Blob in bytes */ + unsigned char a[1]; /* Blob content. Extra space allocated as needed. */ +}; + +/* +** Maximum number of files in the in-memory virtual filesystem. +*/ +#define MX_FILE 10 + +/* +** Maximum allowed file size +*/ +#define MX_FILE_SZ 10000000 + +/* +** All global variables are gathered into the "g" singleton. +*/ +static struct GlobalVars { + const char *zArgv0; /* Name of program */ + const char *zDbFile; /* Name of database file */ + VFile aFile[MX_FILE]; /* The virtual filesystem */ + int nDb; /* Number of template databases */ + Blob *pFirstDb; /* Content of first template database */ + int nSql; /* Number of SQL scripts */ + Blob *pFirstSql; /* First SQL script */ + unsigned int uRandom; /* Seed for the SQLite PRNG */ + unsigned int nInvariant; /* Number of invariant checks run */ + char zTestName[100]; /* Name of current test */ +} g; + +/* +** Include the external vt02.c and randomjson.c modules. +*/ +extern int sqlite3_vt02_init(sqlite3*,char***,void*); +extern int sqlite3_randomjson_init(sqlite3*,char***,void*); + + +/* +** Print an error message and quit. +*/ +static void fatalError(const char *zFormat, ...){ + va_list ap; + fprintf(stderr, "%s", g.zArgv0); + if( g.zDbFile ) fprintf(stderr, " %s", g.zDbFile); + if( g.zTestName[0] ) fprintf(stderr, " (%s)", g.zTestName); + fprintf(stderr, ": "); + va_start(ap, zFormat); + vfprintf(stderr, zFormat, ap); + va_end(ap); + fprintf(stderr, "\n"); + exit(1); +} + +/* +** signal handler +*/ +#ifdef __unix__ +static void signalHandler(int signum){ + const char *zSig; + if( signum==SIGABRT ){ + zSig = "abort"; + }else if( signum==SIGALRM ){ + zSig = "timeout"; + }else if( signum==SIGSEGV ){ + zSig = "segfault"; + }else{ + zSig = "signal"; + } + fatalError(zSig); +} +#endif + +/* +** Set the an alarm to go off after N seconds. Disable the alarm +** if N==0 +*/ +static void setAlarm(int N){ +#ifdef __unix__ + alarm(N); +#else + (void)N; +#endif +} + +#ifndef SQLITE_OMIT_PROGRESS_CALLBACK +/* +** This an SQL progress handler. After an SQL statement has run for +** many steps, we want to interrupt it. This guards against infinite +** loops from recursive common table expressions. +** +** *pVdbeLimitFlag is true if the --limit-vdbe command-line option is used. +** In that case, hitting the progress handler is a fatal error. +*/ +static int progressHandler(void *pVdbeLimitFlag){ + if( *(int*)pVdbeLimitFlag ) fatalError("too many VDBE cycles"); + return 1; +} +#endif + +/* +** Reallocate memory. Show an error and quit if unable. +*/ +static void *safe_realloc(void *pOld, int szNew){ + void *pNew = realloc(pOld, szNew<=0 ? 1 : szNew); + if( pNew==0 ) fatalError("unable to realloc for %d bytes", szNew); + return pNew; +} + +/* +** Initialize the virtual file system. +*/ +static void formatVfs(void){ + int i; + for(i=0; i0 ){ + fatalError("file %d still open. nRef=%d", i, g.aFile[i].nRef); + } + g.aFile[i].sz = -1; + free(g.aFile[i].a); + g.aFile[i].a = 0; + g.aFile[i].nRef = 0; + } +} + +/* +** Find a VFile by name +*/ +static VFile *findVFile(const char *zName){ + int i; + if( zName==0 ) return 0; + for(i=0; i=0; i++){} + if( i>=MX_FILE ) return 0; + pNew = &g.aFile[i]; + if( zName ){ + int nName = (int)strlen(zName)+1; + pNew->zFilename = safe_realloc(0, nName); + memcpy(pNew->zFilename, zName, nName); + }else{ + pNew->zFilename = 0; + } + pNew->nRef = 0; + pNew->sz = sz; + pNew->a = safe_realloc(0, sz); + if( sz>0 ) memcpy(pNew->a, pData, sz); + return pNew; +} + +/* Return true if the line is all zeros */ +static int allZero(unsigned char *aLine){ + int i; + for(i=0; i<16 && aLine[i]==0; i++){} + return i==16; +} + +/* +** Render a database and query as text that can be input into +** the CLI. +*/ +static void renderDbSqlForCLI( + FILE *out, /* Write to this file */ + const char *zFile, /* Name of the database file */ + unsigned char *aDb, /* Database content */ + int nDb, /* Number of bytes in aDb[] */ + unsigned char *zSql, /* SQL content */ + int nSql /* Bytes of SQL */ +){ + fprintf(out, ".print ******* %s *******\n", zFile); + if( nDb>100 ){ + int i, j; /* Loop counters */ + int pgsz; /* Size of each page */ + int lastPage = 0; /* Last page number shown */ + int iPage; /* Current page number */ + unsigned char *aLine; /* Single line to display */ + unsigned char buf[16]; /* Fake line */ + unsigned char bShow[256]; /* Characters ok to display */ + + memset(bShow, '.', sizeof(bShow)); + for(i=' '; i<='~'; i++){ + if( i!='{' && i!='}' && i!='"' && i!='\\' ) bShow[i] = i; + } + pgsz = (aDb[16]<<8) | aDb[17]; + if( pgsz==0 ) pgsz = 65536; + if( pgsz<512 || (pgsz&(pgsz-1))!=0 ) pgsz = 4096; + fprintf(out,".open --hexdb\n"); + fprintf(out,"| size %d pagesize %d filename %s\n",nDb,pgsz,zFile); + for(i=0; inDb ){ + memset(buf, 0, sizeof(buf)); + memcpy(buf, aDb+i, nDb-i); + aLine = buf; + }else{ + aLine = aDb + i; + } + if( allZero(aLine) ) continue; + iPage = i/pgsz + 1; + if( lastPage!=iPage ){ + fprintf(out,"| page %d offset %d\n", iPage, (iPage-1)*pgsz); + lastPage = iPage; + } + fprintf(out,"| %5d:", i-(iPage-1)*pgsz); + for(j=0; j<16; j++) fprintf(out," %02x", aLine[j]); + fprintf(out," "); + for(j=0; j<16; j++){ + unsigned char c = (unsigned char)aLine[j]; + fputc( bShow[c], stdout); + } + fputc('\n', stdout); + } + fprintf(out,"| end %s\n", zFile); + }else{ + fprintf(out,".open :memory:\n"); + } + fprintf(out,".testctrl prng_seed 1 db\n"); + fprintf(out,".testctrl internal_functions\n"); + fprintf(out,"%.*s", nSql, zSql); + if( nSql>0 && zSql[nSql-1]!='\n' ) fprintf(out, "\n"); +} + +/* +** Read the complete content of a file into memory. Add a 0x00 terminator +** and return a pointer to the result. +** +** The file content is held in memory obtained from sqlite_malloc64() which +** should be freed by the caller. +*/ +static char *readFile(const char *zFilename, long *sz){ + FILE *in; + long nIn; + unsigned char *pBuf; + + *sz = 0; + if( zFilename==0 ) return 0; + in = fopen(zFilename, "rb"); + if( in==0 ) return 0; + fseek(in, 0, SEEK_END); + *sz = nIn = ftell(in); + rewind(in); + pBuf = sqlite3_malloc64( nIn+1 ); + if( pBuf && 1==fread(pBuf, nIn, 1, in) ){ + pBuf[nIn] = 0; + fclose(in); + return (char*)pBuf; + } + sqlite3_free(pBuf); + *sz = 0; + fclose(in); + return 0; +} + + +/* +** Implementation of the "readfile(X)" SQL function. The entire content +** of the file named X is read and returned as a BLOB. NULL is returned +** if the file does not exist or is unreadable. +*/ +static void readfileFunc( + sqlite3_context *context, + int argc, + sqlite3_value **argv +){ + long nIn; + void *pBuf; + const char *zName = (const char*)sqlite3_value_text(argv[0]); + + if( zName==0 ) return; + pBuf = readFile(zName, &nIn); + if( pBuf ){ + sqlite3_result_blob(context, pBuf, nIn, sqlite3_free); + } +} + +/* +** Implementation of the "readtextfile(X)" SQL function. The text content +** of the file named X through the end of the file or to the first \000 +** character, whichever comes first, is read and returned as TEXT. NULL +** is returned if the file does not exist or is unreadable. +*/ +static void readtextfileFunc( + sqlite3_context *context, + int argc, + sqlite3_value **argv +){ + const char *zName; + FILE *in; + long nIn; + char *pBuf; + + zName = (const char*)sqlite3_value_text(argv[0]); + if( zName==0 ) return; + in = fopen(zName, "rb"); + if( in==0 ) return; + fseek(in, 0, SEEK_END); + nIn = ftell(in); + rewind(in); + pBuf = sqlite3_malloc64( nIn+1 ); + if( pBuf && 1==fread(pBuf, nIn, 1, in) ){ + pBuf[nIn] = 0; + sqlite3_result_text(context, pBuf, -1, sqlite3_free); + }else{ + sqlite3_free(pBuf); + } + fclose(in); +} + +/* +** Implementation of the "writefile(X,Y)" SQL function. The argument Y +** is written into file X. The number of bytes written is returned. Or +** NULL is returned if something goes wrong, such as being unable to open +** file X for writing. +*/ +static void writefileFunc( + sqlite3_context *context, + int argc, + sqlite3_value **argv +){ + FILE *out; + const char *z; + sqlite3_int64 rc; + const char *zFile; + + (void)argc; + zFile = (const char*)sqlite3_value_text(argv[0]); + if( zFile==0 ) return; + out = fopen(zFile, "wb"); + if( out==0 ) return; + z = (const char*)sqlite3_value_blob(argv[1]); + if( z==0 ){ + rc = 0; + }else{ + rc = fwrite(z, 1, sqlite3_value_bytes(argv[1]), out); + } + fclose(out); + sqlite3_result_int64(context, rc); +} + + +/* +** Load a list of Blob objects from the database +*/ +static void blobListLoadFromDb( + sqlite3 *db, /* Read from this database */ + const char *zSql, /* Query used to extract the blobs */ + int onlyId, /* Only load where id is this value */ + int *pN, /* OUT: Write number of blobs loaded here */ + Blob **ppList /* OUT: Write the head of the blob list here */ +){ + Blob head; + Blob *p; + sqlite3_stmt *pStmt; + int n = 0; + int rc; + char *z2; + + if( onlyId>0 ){ + z2 = sqlite3_mprintf("%s WHERE rowid=%d", zSql, onlyId); + }else{ + z2 = sqlite3_mprintf("%s", zSql); + } + rc = sqlite3_prepare_v2(db, z2, -1, &pStmt, 0); + sqlite3_free(z2); + if( rc ) fatalError("%s", sqlite3_errmsg(db)); + head.pNext = 0; + p = &head; + while( SQLITE_ROW==sqlite3_step(pStmt) ){ + int sz = sqlite3_column_bytes(pStmt, 1); + Blob *pNew = safe_realloc(0, sizeof(*pNew)+sz ); + pNew->id = sqlite3_column_int(pStmt, 0); + pNew->sz = sz; + pNew->seq = n++; + pNew->pNext = 0; + memcpy(pNew->a, sqlite3_column_blob(pStmt,1), sz); + pNew->a[sz] = 0; + p->pNext = pNew; + p = pNew; + } + sqlite3_finalize(pStmt); + *pN = n; + *ppList = head.pNext; +} + +/* +** Free a list of Blob objects +*/ +static void blobListFree(Blob *p){ + Blob *pNext; + while( p ){ + pNext = p->pNext; + free(p); + p = pNext; + } +} + +/* Return the current wall-clock time +** +** The number of milliseconds since the julian epoch. +** 1907-01-01 00:00:00 -> 210866716800000 +** 2021-01-01 00:00:00 -> 212476176000000 +*/ +static sqlite3_int64 timeOfDay(void){ + static sqlite3_vfs *clockVfs = 0; + sqlite3_int64 t; + if( clockVfs==0 ){ + clockVfs = sqlite3_vfs_find(0); + if( clockVfs==0 ) return 0; + } + if( clockVfs->iVersion>=1 && clockVfs->xCurrentTimeInt64!=0 ){ + clockVfs->xCurrentTimeInt64(clockVfs, &t); + }else{ + double r; + clockVfs->xCurrentTime(clockVfs, &r); + t = (sqlite3_int64)(r*86400000.0); + } + return t; +} + +/*************************************************************************** +** Code to process combined database+SQL scripts generated by the +** dbsqlfuzz fuzzer. +*/ + +/* An instance of the following object is passed by pointer as the +** client data to various callbacks. +*/ +typedef struct FuzzCtx { + sqlite3 *db; /* The database connection */ + sqlite3_int64 iCutoffTime; /* Stop processing at this time. */ + sqlite3_int64 iLastCb; /* Time recorded for previous progress callback */ + sqlite3_int64 mxInterval; /* Longest interval between two progress calls */ + unsigned nCb; /* Number of progress callbacks */ + unsigned mxCb; /* Maximum number of progress callbacks allowed */ + unsigned execCnt; /* Number of calls to the sqlite3_exec callback */ + int timeoutHit; /* True when reaching a timeout */ +} FuzzCtx; + +/* Verbosity level for the dbsqlfuzz test runner */ +static int eVerbosity = 0; + +/* True to activate PRAGMA vdbe_debug=on */ +static int bVdbeDebug = 0; + +/* Timeout for each fuzzing attempt, in milliseconds */ +static int giTimeout = 10000; /* Defaults to 10 seconds */ + +/* Maximum number of progress handler callbacks */ +static unsigned int mxProgressCb = 2000; + +/* Maximum string length in SQLite */ +static int lengthLimit = 1000000; + +/* Maximum expression depth */ +static int depthLimit = 500; + +/* Limit on the amount of heap memory that can be used */ +static sqlite3_int64 heapLimit = 100000000; + +/* Maximum byte-code program length in SQLite */ +static int vdbeOpLimit = 25000; + +/* Maximum size of the in-memory database */ +static sqlite3_int64 maxDbSize = 104857600; +/* OOM simulation parameters */ +static unsigned int oomCounter = 0; /* Simulate OOM when equals 1 */ +static unsigned int oomRepeat = 0; /* Number of OOMs in a row */ +static void*(*defaultMalloc)(int) = 0; /* The low-level malloc routine */ + +/* Enable recovery */ +static int bNoRecover = 0; + +/* This routine is called when a simulated OOM occurs. It is broken +** out as a separate routine to make it easy to set a breakpoint on +** the OOM +*/ +void oomFault(void){ + if( eVerbosity ){ + printf("Simulated OOM fault\n"); + } + if( oomRepeat>0 ){ + oomRepeat--; + }else{ + oomCounter--; + } +} + +/* This routine is a replacement malloc() that is used to simulate +** Out-Of-Memory (OOM) errors for testing purposes. +*/ +static void *oomMalloc(int nByte){ + if( oomCounter ){ + if( oomCounter==1 ){ + oomFault(); + return 0; + }else{ + oomCounter--; + } + } + return defaultMalloc(nByte); +} + +/* Register the OOM simulator. This must occur before any memory +** allocations */ +static void registerOomSimulator(void){ + sqlite3_mem_methods mem; + sqlite3_shutdown(); + sqlite3_config(SQLITE_CONFIG_GETMALLOC, &mem); + defaultMalloc = mem.xMalloc; + mem.xMalloc = oomMalloc; + sqlite3_config(SQLITE_CONFIG_MALLOC, &mem); +} + +/* Turn off any pending OOM simulation */ +static void disableOom(void){ + oomCounter = 0; + oomRepeat = 0; +} + +/* +** Translate a single byte of Hex into an integer. +** This routine only works if h really is a valid hexadecimal +** character: 0..9a..fA..F +*/ +static unsigned char hexToInt(unsigned int h){ +#ifdef SQLITE_EBCDIC + h += 9*(1&~(h>>4)); /* EBCDIC */ +#else + h += 9*(1&(h>>6)); /* ASCII */ +#endif + return h & 0xf; +} + +/* +** The first character of buffer zIn[0..nIn-1] is a '['. This routine +** checked to see if the buffer holds "[NNNN]" or "[+NNNN]" and if it +** does it makes corresponding changes to the *pK value and *pI value +** and returns true. If the input buffer does not match the patterns, +** no changes are made to either *pK or *pI and this routine returns false. +*/ +static int isOffset( + const unsigned char *zIn, /* Text input */ + int nIn, /* Bytes of input */ + unsigned int *pK, /* half-byte cursor to adjust */ + unsigned int *pI /* Input index to adjust */ +){ + int i; + unsigned int k = 0; + unsigned char c; + for(i=1; i=nAlloc ){ + sqlite3_uint64 newSize; + if( nAlloc==MX_FILE_SZ || j>=MX_FILE_SZ ){ + if( eVerbosity ){ + fprintf(stderr, "Input database too big: max %d bytes\n", + MX_FILE_SZ); + } + sqlite3_free(a); + return -1; + } + newSize = nAlloc*2; + if( newSize<=j ){ + newSize = (j+4096)&~4095; + } + if( newSize>MX_FILE_SZ ){ + if( j>=MX_FILE_SZ ){ + sqlite3_free(a); + return -1; + } + newSize = MX_FILE_SZ; + } + aNew = sqlite3_realloc64( a, newSize ); + if( aNew==0 ){ + sqlite3_free(a); + return -1; + } + a = aNew; + assert( newSize > nAlloc ); + memset(a+nAlloc, 0, (size_t)(newSize - nAlloc)); + nAlloc = newSize; + } + if( j>=(unsigned)mx ){ + mx = (j + 4095)&~4095; + if( mx>MX_FILE_SZ ) mx = MX_FILE_SZ; + } + assert( j=p->iCutoffTime; + sqlite3_int64 iDiff = iNow - p->iLastCb; + /* printf("time-remaining: %lld\n", p->iCutoffTime - iNow); */ + if( iDiff > p->mxInterval ) p->mxInterval = iDiff; + p->nCb++; + if( rc==0 && p->mxCb>0 && p->mxCb<=p->nCb ) rc = 1; + if( rc && !p->timeoutHit && eVerbosity>=2 ){ + printf("Timeout on progress callback %d\n", p->nCb); + fflush(stdout); + p->timeoutHit = 1; + } + return rc; +} + +/* +** Flag bits set by block_troublesome_sql() +*/ +#define BTS_SELECT 0x000001 +#define BTS_NONSELECT 0x000002 +#define BTS_BADFUNC 0x000004 +#define BTS_BADPRAGMA 0x000008 /* Sticky for rest of the script */ + +/* +** Disallow debugging pragmas such as "PRAGMA vdbe_debug" and +** "PRAGMA parser_trace" since they can dramatically increase the +** amount of output without actually testing anything useful. +** +** Also block ATTACH if attaching a file from the filesystem. +*/ +static int block_troublesome_sql( + void *pClientData, + int eCode, + const char *zArg1, + const char *zArg2, + const char *zArg3, + const char *zArg4 +){ + unsigned int *pBtsFlags = (unsigned int*)pClientData; + + (void)zArg3; + (void)zArg4; + switch( eCode ){ + case SQLITE_PRAGMA: { + if( sqlite3_stricmp("busy_timeout",zArg1)==0 + && (zArg2==0 || strtoll(zArg2,0,0)>100 || strtoll(zArg2,0,10)>100) + ){ + return SQLITE_DENY; + }else if( sqlite3_stricmp("hard_heap_limit", zArg1)==0 + || sqlite3_stricmp("reverse_unordered_selects", zArg1)==0 + ){ + /* BTS_BADPRAGMA is sticky. A hard_heap_limit or + ** revert_unordered_selects should inhibit all future attempts + ** at verifying query invariants */ + *pBtsFlags |= BTS_BADPRAGMA; + }else if( eVerbosity==0 ){ + if( sqlite3_strnicmp("vdbe_", zArg1, 5)==0 + || sqlite3_stricmp("parser_trace", zArg1)==0 + || sqlite3_stricmp("temp_store_directory", zArg1)==0 + ){ + return SQLITE_DENY; + } + }else if( sqlite3_stricmp("oom",zArg1)==0 + && zArg2!=0 && zArg2[0]!=0 ){ + oomCounter = atoi(zArg2); + } + *pBtsFlags |= BTS_NONSELECT; + break; + } + case SQLITE_ATTACH: { + /* Deny the ATTACH if it is attaching anything other than an in-memory + ** database. */ + *pBtsFlags |= BTS_NONSELECT; + if( zArg1==0 ) return SQLITE_DENY; + if( strcmp(zArg1,":memory:")==0 ) return SQLITE_OK; + if( sqlite3_strglob("file:*[?]vfs=memdb", zArg1)==0 + && sqlite3_strglob("file:*[^/a-zA-Z0-9_.]*[?]vfs=memdb", zArg1)!=0 + ){ + return SQLITE_OK; + } + return SQLITE_DENY; + } + case SQLITE_SELECT: { + *pBtsFlags |= BTS_SELECT; + break; + } + case SQLITE_FUNCTION: { + static const char *azBadFuncs[] = { + "avg", + "count", + "cume_dist", + "current_date", + "current_time", + "current_timestamp", + "date", + "datetime", + "decimal_sum", + "dense_rank", + "first_value", + "geopoly_group_bbox", + "group_concat", + "implies_nonnull_row", + "json_group_array", + "json_group_object", + "julianday", + "lag", + "last_value", + "lead", + "max", + "min", + "nth_value", + "ntile", + "percent_rank", + "random", + "randomblob", + "rank", + "row_number", + "sqlite_offset", + "strftime", + "sum", + "time", + "total", + "unixepoch", + }; + int first, last; + first = 0; + last = sizeof(azBadFuncs)/sizeof(azBadFuncs[0]) - 1; + do{ + int mid = (first+last)/2; + int c = sqlite3_stricmp(azBadFuncs[mid], zArg2); + if( c<0 ){ + first = mid+1; + }else if( c>0 ){ + last = mid-1; + }else{ + *pBtsFlags |= BTS_BADFUNC; + break; + } + }while( first<=last ); + break; + } + case SQLITE_READ: { + /* Benign */ + break; + } + default: { + *pBtsFlags |= BTS_NONSELECT; + } + } + return SQLITE_OK; +} + +/* Implementation found in fuzzinvariant.c */ +extern int fuzz_invariant( + sqlite3 *db, /* The database connection */ + sqlite3_stmt *pStmt, /* Test statement stopped on an SQLITE_ROW */ + int iCnt, /* Invariant sequence number, starting at 0 */ + int iRow, /* The row number for pStmt */ + int nRow, /* Total number of output rows */ + int *pbCorrupt, /* IN/OUT: Flag indicating a corrupt database file */ + int eVerbosity /* How much debugging output */ +); + +/* Implementation of sqlite_dbdata and sqlite_dbptr */ +extern int sqlite3_dbdata_init(sqlite3*,const char**,void*); + + +/* +** This function is used as a callback by the recover extension. Simply +** print the supplied SQL statement to stdout. +*/ +static int recoverSqlCb(void *pCtx, const char *zSql){ + if( eVerbosity>=2 ){ + printf("%s\n", zSql); + } + return SQLITE_OK; +} + +/* +** This function is called to recover data from the database. +*/ +static int recoverDatabase(sqlite3 *db){ + int rc; /* Return code from this routine */ + const char *zRecoveryDb = ""; /* Name of "recovery" database */ + const char *zLAF = "lost_and_found"; /* Name of "lost_and_found" table */ + int bFreelist = 1; /* True to scan the freelist */ + int bRowids = 1; /* True to restore ROWID values */ + sqlite3_recover *p = 0; /* The recovery object */ + + p = sqlite3_recover_init_sql(db, "main", recoverSqlCb, 0); + sqlite3_recover_config(p, 789, (void*)zRecoveryDb); + sqlite3_recover_config(p, SQLITE_RECOVER_LOST_AND_FOUND, (void*)zLAF); + sqlite3_recover_config(p, SQLITE_RECOVER_ROWIDS, (void*)&bRowids); + sqlite3_recover_config(p, SQLITE_RECOVER_FREELIST_CORRUPT,(void*)&bFreelist); + sqlite3_recover_run(p); + if( sqlite3_recover_errcode(p)!=SQLITE_OK ){ + const char *zErr = sqlite3_recover_errmsg(p); + int errCode = sqlite3_recover_errcode(p); + if( eVerbosity>0 ){ + printf("recovery error: %s (%d)\n", zErr, errCode); + } + } + rc = sqlite3_recover_finish(p); + if( eVerbosity>0 && rc ){ + printf("recovery returns error code %d\n", rc); + } + return rc; +} + +/* +** Run the SQL text +*/ +static int runDbSql(sqlite3 *db, const char *zSql, unsigned int *pBtsFlags){ + int rc; + sqlite3_stmt *pStmt; + int bCorrupt = 0; + while( isspace(zSql[0]&0x7f) ) zSql++; + if( zSql[0]==0 ) return SQLITE_OK; + if( eVerbosity>=4 ){ + printf("RUNNING-SQL: [%s]\n", zSql); + fflush(stdout); + } + (*pBtsFlags) &= BTS_BADPRAGMA; + rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0); + if( rc==SQLITE_OK ){ + int nRow = 0; + while( (rc = sqlite3_step(pStmt))==SQLITE_ROW ){ + nRow++; + if( eVerbosity>=4 ){ + int j; + for(j=0; j=5 ) */ + } /* End while( SQLITE_ROW */ + if( rc==SQLITE_DONE ){ + if( (*pBtsFlags)==BTS_SELECT + && !sqlite3_stmt_isexplain(pStmt) + && nRow>0 + ){ + int iRow = 0; + sqlite3_reset(pStmt); + while( sqlite3_step(pStmt)==SQLITE_ROW ){ + int iCnt = 0; + iRow++; + for(iCnt=0; iCnt<99999; iCnt++){ + rc = fuzz_invariant(db, pStmt, iCnt, iRow, nRow, + &bCorrupt, eVerbosity); + if( rc==SQLITE_DONE ) break; + if( rc!=SQLITE_ERROR ) g.nInvariant++; + if( eVerbosity>0 ){ + if( rc==SQLITE_OK ){ + printf("invariant-check: ok\n"); + }else if( rc==SQLITE_CORRUPT ){ + printf("invariant-check: failed due to database corruption\n"); + } + } + } + } + } + }else if( eVerbosity>=4 ){ + printf("SQL-ERROR: (%d) %s\n", rc, sqlite3_errmsg(db)); + fflush(stdout); + } + }else if( eVerbosity>=4 ){ + printf("SQL-ERROR (%d): %s\n", rc, sqlite3_errmsg(db)); + fflush(stdout); + } /* End if( SQLITE_OK ) */ + return sqlite3_finalize(pStmt); +} + +/* Mappings into dbconfig settings for bits taken from bytes 72..75 of +** the input database. +** +** This should be the same as in dbsqlfuzz.c. Make sure those codes stay +** in sync. +*/ +static const struct { + unsigned int mask; + int iSetting; + char *zName; +} aDbConfigSettings[] = { + { 0x0001, SQLITE_DBCONFIG_ENABLE_FKEY, "enable_fkey" }, + { 0x0002, SQLITE_DBCONFIG_ENABLE_TRIGGER, "enable_trigger" }, + { 0x0004, SQLITE_DBCONFIG_ENABLE_VIEW, "enable_view" }, + { 0x0008, SQLITE_DBCONFIG_ENABLE_QPSG, "enable_qpsg" }, + { 0x0010, SQLITE_DBCONFIG_TRIGGER_EQP, "trigger_eqp" }, + { 0x0020, SQLITE_DBCONFIG_DEFENSIVE, "defensive" }, + { 0x0040, SQLITE_DBCONFIG_WRITABLE_SCHEMA, "writable_schema" }, + { 0x0080, SQLITE_DBCONFIG_LEGACY_ALTER_TABLE, "legacy_alter_table" }, + { 0x0100, SQLITE_DBCONFIG_STMT_SCANSTATUS, "stmt_scanstatus" }, + { 0x0200, SQLITE_DBCONFIG_REVERSE_SCANORDER, "reverse_scanorder" }, +#ifdef SQLITE_DBCONFIG_STRICT_AGGREGATE + { 0x0400, SQLITE_DBCONFIG_STRICT_AGGREGATE, "strict_aggregate" }, +#endif + { 0x0800, SQLITE_DBCONFIG_DQS_DML, "dqs_dml" }, + { 0x1000, SQLITE_DBCONFIG_DQS_DDL, "dqs_ddl" }, + { 0x2000, SQLITE_DBCONFIG_TRUSTED_SCHEMA, "trusted_schema" }, +}; + +/* Toggle a dbconfig setting +*/ +static void toggleDbConfig(sqlite3 *db, int iSetting){ + int v = 0; + sqlite3_db_config(db, iSetting, -1, &v); + v = !v; + sqlite3_db_config(db, iSetting, v, 0); +} + +/* Invoke this routine to run a single test case */ +int runCombinedDbSqlInput( + const uint8_t *aData, /* Combined DB+SQL content */ + size_t nByte, /* Size of aData in bytes */ + int iTimeout, /* Use this timeout */ + int bScript, /* If true, just render CLI output */ + int iSqlId /* SQL identifier */ +){ + int rc; /* SQLite API return value */ + int iSql; /* Index in aData[] of start of SQL */ + unsigned char *aDb = 0; /* Decoded database content */ + int nDb = 0; /* Size of the decoded database */ + int i; /* Loop counter */ + int j; /* Start of current SQL statement */ + char *zSql = 0; /* SQL text to run */ + int nSql; /* Bytes of SQL text */ + FuzzCtx cx; /* Fuzzing context */ + unsigned int btsFlags = 0; /* Parsing flags */ + unsigned int dbFlags = 0; /* Flag values from db offset 72..75 */ + unsigned int dbOpt = 0; /* Flag values from db offset 76..79 */ + + + if( nByte<10 ) return 0; + if( sqlite3_initialize() ) return 0; + if( sqlite3_memory_used()!=0 ){ + int nAlloc = 0; + int nNotUsed = 0; + sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &nAlloc, &nNotUsed, 0); + fprintf(stderr,"memory leak prior to test start:" + " %lld bytes in %d allocations\n", + sqlite3_memory_used(), nAlloc); + exit(1); + } + memset(&cx, 0, sizeof(cx)); + iSql = decodeDatabase((unsigned char*)aData, (int)nByte, &aDb, &nDb); + if( iSql<0 ) return 0; + if( nDb>=75 ){ + dbFlags = ((unsigned int)aDb[72]<<24) + ((unsigned int)aDb[73]<<16) + + ((unsigned int)aDb[74]<<8) + (unsigned int)aDb[75]; + } + if( nDb>=79 ){ + dbOpt = ((unsigned int)aDb[76]<<24) + ((unsigned int)aDb[77]<<16) + + ((unsigned int)aDb[78]<<8) + (unsigned int)aDb[79]; + } + nSql = (int)(nByte - iSql); + if( bScript ){ + char zName[100]; + sqlite3_snprintf(sizeof(zName),zName,"dbsql%06d.db",iSqlId); + renderDbSqlForCLI(stdout, zName, aDb, nDb, + (unsigned char*)(aData+iSql), nSql); + sqlite3_free(aDb); + return 0; + } + if( eVerbosity>=3 ){ + printf( + "****** %d-byte input, %d-byte database, %d-byte script " + "******\n", (int)nByte, nDb, nSql); + fflush(stdout); + } + rc = sqlite3_open(0, &cx.db); + if( rc ){ + sqlite3_free(aDb); + return 1; + } + sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS, cx.db, dbOpt); + for(i=0; i0 ){ + sqlite3_limit(cx.db, SQLITE_LIMIT_VDBE_OP, vdbeOpLimit); + } + if( lengthLimit>0 ){ + sqlite3_limit(cx.db, SQLITE_LIMIT_LENGTH, lengthLimit); + } + if( depthLimit>0 ){ + sqlite3_limit(cx.db, SQLITE_LIMIT_EXPR_DEPTH, depthLimit); + } + sqlite3_limit(cx.db, SQLITE_LIMIT_LIKE_PATTERN_LENGTH, 100); + sqlite3_hard_heap_limit64(heapLimit); + rc = 1; + sqlite3_test_control(SQLITE_TESTCTRL_JSON_SELFCHECK, &rc); + + if( nDb>=20 && aDb[18]==2 && aDb[19]==2 ){ + aDb[18] = aDb[19] = 1; + } + rc = sqlite3_deserialize(cx.db, "main", aDb, nDb, nDb, + SQLITE_DESERIALIZE_RESIZEABLE | + SQLITE_DESERIALIZE_FREEONCLOSE); + if( rc ){ + fprintf(stderr, "sqlite3_deserialize() failed with %d\n", rc); + goto testrun_finished; + } + if( maxDbSize>0 ){ + sqlite3_int64 x = maxDbSize; + sqlite3_file_control(cx.db, "main", SQLITE_FCNTL_SIZE_LIMIT, &x); + } + + /* For high debugging levels, turn on debug mode */ + if( eVerbosity>=5 ){ + sqlite3_exec(cx.db, "PRAGMA vdbe_debug=ON;", 0, 0, 0); + } + + /* Block debug pragmas and ATTACH/DETACH. But wait until after + ** deserialize to do this because deserialize depends on ATTACH */ + sqlite3_set_authorizer(cx.db, block_troublesome_sql, &btsFlags); + + /* Add the vt02 virtual table */ + sqlite3_vt02_init(cx.db, 0, 0); + + /* Add the random_json() and random_json5() functions */ + sqlite3_randomjson_init(cx.db, 0, 0); + + /* Add support for sqlite_dbdata and sqlite_dbptr virtual tables used + ** by the recovery API */ + sqlite3_dbdata_init(cx.db, 0, 0); + + /* Consistent PRNG seed */ +#ifdef SQLITE_TESTCTRL_PRNG_SEED + sqlite3_table_column_metadata(cx.db, 0, "x", 0, 0, 0, 0, 0, 0); + sqlite3_test_control(SQLITE_TESTCTRL_PRNG_SEED, 1, cx.db); +#else + sqlite3_randomness(0,0); +#endif + + /* Run recovery on the initial database, just to make sure recovery + ** works. */ + if( !bNoRecover ){ + recoverDatabase(cx.db); + } + + zSql = sqlite3_malloc( nSql + 1 ); + if( zSql==0 ){ + fprintf(stderr, "Out of memory!\n"); + }else{ + memcpy(zSql, aData+iSql, nSql); + zSql[nSql] = 0; + for(i=j=0; zSql[i]; i++){ + if( zSql[i]==';' ){ + char cSaved = zSql[i+1]; + zSql[i+1] = 0; + if( sqlite3_complete(zSql+j) ){ + rc = runDbSql(cx.db, zSql+j, &btsFlags); + j = i+1; + } + zSql[i+1] = cSaved; + if( rc==SQLITE_INTERRUPT || progress_handler(&cx) ){ + goto testrun_finished; + } + } + } + if( j=2 && !bScript ){ + fprintf(stdout, "Peak memory usages: %f MB\n", + sqlite3_memory_highwater(1) / 1000000.0); + } + if( sqlite3_memory_used()!=0 ){ + int nAlloc = 0; + int nNotUsed = 0; + sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &nAlloc, &nNotUsed, 0); + fprintf(stderr,"Memory leak: %lld bytes in %d allocations\n", + sqlite3_memory_used(), nAlloc); + exit(1); + } + sqlite3_hard_heap_limit64(0); + sqlite3_soft_heap_limit64(0); + return 0; +} + +/* +** END of the dbsqlfuzz code +***************************************************************************/ + +/* Look at a SQL text and try to determine if it begins with a database +** description, such as would be found in a dbsqlfuzz test case. Return +** true if this does appear to be a dbsqlfuzz test case and false otherwise. +*/ +static int isDbSql(unsigned char *a, int n){ + unsigned char buf[12]; + int i; + if( n>4 && memcmp(a,"\n--\n",4)==0 ) return 1; + while( n>0 && isspace(a[0]) ){ a++; n--; } + for(i=0; n>0 && i<8; n--, a++){ + if( isxdigit(a[0]) ) buf[i++] = a[0]; + } + if( i==8 && memcmp(buf,"53514c69",8)==0 ) return 1; + return 0; +} + +/* Implementation of the isdbsql(TEXT) SQL function. +*/ +static void isDbSqlFunc( + sqlite3_context *context, + int argc, + sqlite3_value **argv +){ + int n = sqlite3_value_bytes(argv[0]); + unsigned char *a = (unsigned char*)sqlite3_value_blob(argv[0]); + sqlite3_result_int(context, a!=0 && n>0 && isDbSql(a,n)); +} + +/* Methods for the VHandle object +*/ +static int inmemClose(sqlite3_file *pFile){ + VHandle *p = (VHandle*)pFile; + VFile *pVFile = p->pVFile; + pVFile->nRef--; + if( pVFile->nRef==0 && pVFile->zFilename==0 ){ + pVFile->sz = -1; + free(pVFile->a); + pVFile->a = 0; + } + return SQLITE_OK; +} +static int inmemRead( + sqlite3_file *pFile, /* Read from this open file */ + void *pData, /* Store content in this buffer */ + int iAmt, /* Bytes of content */ + sqlite3_int64 iOfst /* Start reading here */ +){ + VHandle *pHandle = (VHandle*)pFile; + VFile *pVFile = pHandle->pVFile; + if( iOfst<0 || iOfst>=pVFile->sz ){ + memset(pData, 0, iAmt); + return SQLITE_IOERR_SHORT_READ; + } + if( iOfst+iAmt>pVFile->sz ){ + memset(pData, 0, iAmt); + iAmt = (int)(pVFile->sz - iOfst); + memcpy(pData, pVFile->a + iOfst, iAmt); + return SQLITE_IOERR_SHORT_READ; + } + memcpy(pData, pVFile->a + iOfst, iAmt); + return SQLITE_OK; +} +static int inmemWrite( + sqlite3_file *pFile, /* Write to this file */ + const void *pData, /* Content to write */ + int iAmt, /* bytes to write */ + sqlite3_int64 iOfst /* Start writing here */ +){ + VHandle *pHandle = (VHandle*)pFile; + VFile *pVFile = pHandle->pVFile; + if( iOfst+iAmt > pVFile->sz ){ + if( iOfst+iAmt >= MX_FILE_SZ ){ + return SQLITE_FULL; + } + pVFile->a = safe_realloc(pVFile->a, (int)(iOfst+iAmt)); + if( iOfst > pVFile->sz ){ + memset(pVFile->a + pVFile->sz, 0, (int)(iOfst - pVFile->sz)); + } + pVFile->sz = (int)(iOfst + iAmt); + } + memcpy(pVFile->a + iOfst, pData, iAmt); + return SQLITE_OK; +} +static int inmemTruncate(sqlite3_file *pFile, sqlite3_int64 iSize){ + VHandle *pHandle = (VHandle*)pFile; + VFile *pVFile = pHandle->pVFile; + if( pVFile->sz>iSize && iSize>=0 ) pVFile->sz = (int)iSize; + return SQLITE_OK; +} +static int inmemSync(sqlite3_file *pFile, int flags){ + return SQLITE_OK; +} +static int inmemFileSize(sqlite3_file *pFile, sqlite3_int64 *pSize){ + *pSize = ((VHandle*)pFile)->pVFile->sz; + return SQLITE_OK; +} +static int inmemLock(sqlite3_file *pFile, int type){ + return SQLITE_OK; +} +static int inmemUnlock(sqlite3_file *pFile, int type){ + return SQLITE_OK; +} +static int inmemCheckReservedLock(sqlite3_file *pFile, int *pOut){ + *pOut = 0; + return SQLITE_OK; +} +static int inmemFileControl(sqlite3_file *pFile, int op, void *pArg){ + return SQLITE_NOTFOUND; +} +static int inmemSectorSize(sqlite3_file *pFile){ + return 512; +} +static int inmemDeviceCharacteristics(sqlite3_file *pFile){ + return + SQLITE_IOCAP_SAFE_APPEND | + SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN | + SQLITE_IOCAP_POWERSAFE_OVERWRITE; +} + + +/* Method table for VHandle +*/ +static sqlite3_io_methods VHandleMethods = { + /* iVersion */ 1, + /* xClose */ inmemClose, + /* xRead */ inmemRead, + /* xWrite */ inmemWrite, + /* xTruncate */ inmemTruncate, + /* xSync */ inmemSync, + /* xFileSize */ inmemFileSize, + /* xLock */ inmemLock, + /* xUnlock */ inmemUnlock, + /* xCheck... */ inmemCheckReservedLock, + /* xFileCtrl */ inmemFileControl, + /* xSectorSz */ inmemSectorSize, + /* xDevchar */ inmemDeviceCharacteristics, + /* xShmMap */ 0, + /* xShmLock */ 0, + /* xShmBarrier */ 0, + /* xShmUnmap */ 0, + /* xFetch */ 0, + /* xUnfetch */ 0 +}; + +/* +** Open a new file in the inmem VFS. All files are anonymous and are +** delete-on-close. +*/ +static int inmemOpen( + sqlite3_vfs *pVfs, + const char *zFilename, + sqlite3_file *pFile, + int openFlags, + int *pOutFlags +){ + VFile *pVFile = createVFile(zFilename, 0, (unsigned char*)""); + VHandle *pHandle = (VHandle*)pFile; + if( pVFile==0 ){ + return SQLITE_FULL; + } + pHandle->pVFile = pVFile; + pVFile->nRef++; + pFile->pMethods = &VHandleMethods; + if( pOutFlags ) *pOutFlags = openFlags; + return SQLITE_OK; +} + +/* +** Delete a file by name +*/ +static int inmemDelete( + sqlite3_vfs *pVfs, + const char *zFilename, + int syncdir +){ + VFile *pVFile = findVFile(zFilename); + if( pVFile==0 ) return SQLITE_OK; + if( pVFile->nRef==0 ){ + free(pVFile->zFilename); + pVFile->zFilename = 0; + pVFile->sz = -1; + free(pVFile->a); + pVFile->a = 0; + return SQLITE_OK; + } + return SQLITE_IOERR_DELETE; +} + +/* Check for the existance of a file +*/ +static int inmemAccess( + sqlite3_vfs *pVfs, + const char *zFilename, + int flags, + int *pResOut +){ + VFile *pVFile = findVFile(zFilename); + *pResOut = pVFile!=0; + return SQLITE_OK; +} + +/* Get the canonical pathname for a file +*/ +static int inmemFullPathname( + sqlite3_vfs *pVfs, + const char *zFilename, + int nOut, + char *zOut +){ + sqlite3_snprintf(nOut, zOut, "%s", zFilename); + return SQLITE_OK; +} + +/* Always use the same random see, for repeatability. +*/ +static int inmemRandomness(sqlite3_vfs *NotUsed, int nBuf, char *zBuf){ + memset(zBuf, 0, nBuf); + memcpy(zBuf, &g.uRandom, nBufxSleep; + inmemVfs.xCurrentTimeInt64 = pDefault->xCurrentTimeInt64; + sqlite3_vfs_register(&inmemVfs, makeDefault); +}; + +/* +** Allowed values for the runFlags parameter to runSql() +*/ +#define SQL_TRACE 0x0001 /* Print each SQL statement as it is prepared */ +#define SQL_OUTPUT 0x0002 /* Show the SQL output */ + +/* +** Run multiple commands of SQL. Similar to sqlite3_exec(), but does not +** stop if an error is encountered. +*/ +static void runSql(sqlite3 *db, const char *zSql, unsigned runFlags){ + const char *zMore; + sqlite3_stmt *pStmt; + + while( zSql && zSql[0] ){ + zMore = 0; + pStmt = 0; + sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zMore); + if( zMore==zSql ) break; + if( runFlags & SQL_TRACE ){ + const char *z = zSql; + int n; + while( z0 && ISSPACE(z[n-1]) ) n--; + if( n==0 ) break; + if( pStmt==0 ){ + printf("TRACE: %.*s (error: %s)\n", n, z, sqlite3_errmsg(db)); + }else{ + printf("TRACE: %.*s\n", n, z); + } + } + zSql = zMore; + if( pStmt ){ + if( (runFlags & SQL_OUTPUT)==0 ){ + while( SQLITE_ROW==sqlite3_step(pStmt) ){} + }else{ + int nCol = -1; + while( SQLITE_ROW==sqlite3_step(pStmt) ){ + int i; + if( nCol<0 ){ + nCol = sqlite3_column_count(pStmt); + }else if( nCol>0 ){ + printf("--------------------------------------------\n"); + } + for(i=0; i='0' && c<='9' ) return c - '0'; + if( c>='a' && c<='f' ) return c - 'a' + 10; + if( c>='A' && c<='F' ) return c - 'A' + 10; + return -1; +} + +/* +** Interpret zArg as an integer value, possibly with suffixes. +*/ +static int integerValue(const char *zArg){ + sqlite3_int64 v = 0; + static const struct { char *zSuffix; int iMult; } aMult[] = { + { "KiB", 1024 }, + { "MiB", 1024*1024 }, + { "GiB", 1024*1024*1024 }, + { "KB", 1000 }, + { "MB", 1000000 }, + { "GB", 1000000000 }, + { "K", 1000 }, + { "M", 1000000 }, + { "G", 1000000000 }, + }; + int i; + int isNeg = 0; + if( zArg[0]=='-' ){ + isNeg = 1; + zArg++; + }else if( zArg[0]=='+' ){ + zArg++; + } + if( zArg[0]=='0' && zArg[1]=='x' ){ + int x; + zArg += 2; + while( (x = hexDigitValue(zArg[0]))>=0 ){ + v = (v<<4) + x; + zArg++; + } + }else{ + while( ISDIGIT(zArg[0]) ){ + v = v*10 + zArg[0] - '0'; + zArg++; + } + } + for(i=0; i0x7fffffff ) fatalError("parameter too large - max 2147483648"); + return (int)(isNeg? -v : v); +} + +/* +** Return the number of "v" characters in a string. Return 0 if there +** are any characters in the string other than "v". +*/ +static int numberOfVChar(const char *z){ + int N = 0; + while( z[0] && z[0]=='v' ){ + z++; + N++; + } + return z[0]==0 ? N : 0; +} + +/* +** Print sketchy documentation for this utility program +*/ +static void showHelp(void){ + printf("Usage: %s [options] SOURCE-DB ?ARGS...?\n", g.zArgv0); + printf( +"Read databases and SQL scripts from SOURCE-DB and execute each script against\n" +"each database, checking for crashes and memory leaks.\n" +"Options:\n" +" --cell-size-check Set the PRAGMA cell_size_check=ON\n" +" --dbid N Use only the database where dbid=N\n" +" --export-db DIR Write databases to files(s) in DIR. Works with --dbid\n" +" --export-sql DIR Write SQL to file(s) in DIR. Also works with --sqlid\n" +" --help Show this help text\n" +" --info Show information about SOURCE-DB w/o running tests\n" +" --limit-depth N Limit expression depth to N. Default: 500\n" +" --limit-heap N Limit heap memory to N. Default: 100M\n" +" --limit-mem N Limit memory used by test SQLite instance to N bytes\n" +" --limit-vdbe Panic if any test runs for more than 100,000 cycles\n" +" --load-sql FILE.. Load SQL scripts fron files into SOURCE-DB\n" +" --load-db FILE.. Load template databases from files into SOURCE_DB\n" +" --load-dbsql FILE.. Load dbsqlfuzz outputs into the xsql table\n" +" ^^^^------ Use \"-\" for FILE to read filenames from stdin\n" +" -m TEXT Add a description to the database\n" +" --native-vfs Use the native VFS for initially empty database files\n" +" --native-malloc Turn off MEMSYS3/5 and Lookaside\n" +" --no-recover Do not run recovery on dbsqlfuzz databases\n" +" --oss-fuzz Enable OSS-FUZZ testing\n" +" --prng-seed N Seed value for the PRGN inside of SQLite\n" +" -q|--quiet Reduced output\n" +" --rebuild Rebuild and vacuum the database file\n" +" --result-trace Show the results of each SQL command\n" +" --script Output CLI script instead of running tests\n" +" --skip N Skip the first N test cases\n" +" --spinner Use a spinner to show progress\n" +" --sqlid N Use only SQL where sqlid=N\n" +" --timeout N Maximum time for any one test in N millseconds\n" +" -v|--verbose Increased output. Repeat for more output.\n" +" --vdbe-debug Activate VDBE debugging.\n" +" --wait N Wait N seconds before continuing - useful for\n" +" attaching an MSVC debugging.\n" + ); +} + +int main(int argc, char **argv){ + sqlite3_int64 iBegin; /* Start time of this program */ + int quietFlag = 0; /* True if --quiet or -q */ + int verboseFlag = 0; /* True if --verbose or -v */ + char *zInsSql = 0; /* SQL statement for --load-db or --load-sql */ + int iFirstInsArg = 0; /* First argv[] for --load-db or --load-sql */ + sqlite3 *db = 0; /* The open database connection */ + sqlite3_stmt *pStmt; /* A prepared statement */ + int rc; /* Result code from SQLite interface calls */ + Blob *pSql; /* For looping over SQL scripts */ + Blob *pDb; /* For looping over template databases */ + int i; /* Loop index for the argv[] loop */ + int dbSqlOnly = 0; /* Only use scripts that are dbsqlfuzz */ + int onlySqlid = -1; /* --sqlid */ + int onlyDbid = -1; /* --dbid */ + int nativeFlag = 0; /* --native-vfs */ + int rebuildFlag = 0; /* --rebuild */ + int vdbeLimitFlag = 0; /* --limit-vdbe */ + int infoFlag = 0; /* --info */ + int nSkip = 0; /* --skip */ + int bScript = 0; /* --script */ + int bSpinner = 0; /* True for --spinner */ + int timeoutTest = 0; /* undocumented --timeout-test flag */ + int runFlags = 0; /* Flags sent to runSql() */ + char *zMsg = 0; /* Add this message */ + int nSrcDb = 0; /* Number of source databases */ + char **azSrcDb = 0; /* Array of source database names */ + int iSrcDb; /* Loop over all source databases */ + int nTest = 0; /* Total number of tests performed */ + char *zDbName = ""; /* Appreviated name of a source database */ + const char *zFailCode = 0; /* Value of the TEST_FAILURE env variable */ + int cellSzCkFlag = 0; /* --cell-size-check */ + int sqlFuzz = 0; /* True for SQL fuzz. False for DB fuzz */ + int iTimeout = 120000; /* Default 120-second timeout */ + int nMem = 0; /* Memory limit override */ + int nMemThisDb = 0; /* Memory limit set by the CONFIG table */ + char *zExpDb = 0; /* Write Databases to files in this directory */ + char *zExpSql = 0; /* Write SQL to files in this directory */ + void *pHeap = 0; /* Heap for use by SQLite */ + int ossFuzz = 0; /* enable OSS-FUZZ testing */ + int ossFuzzThisDb = 0; /* ossFuzz value for this particular database */ + int nativeMalloc = 0; /* Turn off MEMSYS3/5 and lookaside if true */ + sqlite3_vfs *pDfltVfs; /* The default VFS */ + int openFlags4Data; /* Flags for sqlite3_open_v2() */ + int bTimer = 0; /* Show elapse time for each test */ + int nV; /* How much to increase verbosity with -vvvv */ + sqlite3_int64 tmStart; /* Start of each test */ + + sqlite3_config(SQLITE_CONFIG_URI,1); + registerOomSimulator(); + sqlite3_initialize(); + iBegin = timeOfDay(); +#ifdef __unix__ + signal(SIGALRM, signalHandler); + signal(SIGSEGV, signalHandler); + signal(SIGABRT, signalHandler); +#endif + g.zArgv0 = argv[0]; + openFlags4Data = SQLITE_OPEN_READONLY; + zFailCode = getenv("TEST_FAILURE"); + pDfltVfs = sqlite3_vfs_find(0); + inmemVfsRegister(1); + for(i=1; i=argc-1 ) fatalError("missing arguments on %s", argv[i]); + onlyDbid = integerValue(argv[++i]); + }else + if( strcmp(z,"export-db")==0 ){ + if( i>=argc-1 ) fatalError("missing arguments on %s", argv[i]); + zExpDb = argv[++i]; + }else + if( strcmp(z,"export-sql")==0 || strcmp(z,"export-dbsql")==0 ){ + if( i>=argc-1 ) fatalError("missing arguments on %s", argv[i]); + zExpSql = argv[++i]; + }else + if( strcmp(z,"help")==0 ){ + showHelp(); + return 0; + }else + if( strcmp(z,"info")==0 ){ + infoFlag = 1; + }else + if( strcmp(z,"limit-depth")==0 ){ + if( i>=argc-1 ) fatalError("missing arguments on %s", argv[i]); + depthLimit = integerValue(argv[++i]); + }else + if( strcmp(z,"limit-heap")==0 ){ + if( i>=argc-1 ) fatalError("missing arguments on %s", argv[i]); + heapLimit = integerValue(argv[++i]); + }else + if( strcmp(z,"limit-mem")==0 ){ + if( i>=argc-1 ) fatalError("missing arguments on %s", argv[i]); + nMem = integerValue(argv[++i]); + }else + if( strcmp(z,"limit-vdbe")==0 ){ + vdbeLimitFlag = 1; + }else + if( strcmp(z,"load-sql")==0 ){ + zInsSql = "INSERT INTO xsql(sqltext)" + "VALUES(CAST(readtextfile(?1) AS text))"; + iFirstInsArg = i+1; + openFlags4Data = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE; + break; + }else + if( strcmp(z,"load-db")==0 ){ + zInsSql = "INSERT INTO db(dbcontent) VALUES(readfile(?1))"; + iFirstInsArg = i+1; + openFlags4Data = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE; + break; + }else + if( strcmp(z,"load-dbsql")==0 ){ + zInsSql = "INSERT INTO xsql(sqltext)" + "VALUES(readfile(?1))"; + iFirstInsArg = i+1; + openFlags4Data = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE; + dbSqlOnly = 1; + break; + }else + if( strcmp(z,"m")==0 ){ + if( i>=argc-1 ) fatalError("missing arguments on %s", argv[i]); + zMsg = argv[++i]; + openFlags4Data = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE; + }else + if( strcmp(z,"native-malloc")==0 ){ + nativeMalloc = 1; + }else + if( strcmp(z,"native-vfs")==0 ){ + nativeFlag = 1; + }else + if( strcmp(z,"no-recover")==0 ){ + bNoRecover = 1; + }else + if( strcmp(z,"oss-fuzz")==0 ){ + ossFuzz = 1; + }else + if( strcmp(z,"prng-seed")==0 ){ + if( i>=argc-1 ) fatalError("missing arguments on %s", argv[i]); + g.uRandom = atoi(argv[++i]); + }else + if( strcmp(z,"quiet")==0 || strcmp(z,"q")==0 ){ + quietFlag = 1; + verboseFlag = 0; + eVerbosity = 0; + }else + if( strcmp(z,"rebuild")==0 ){ + rebuildFlag = 1; + openFlags4Data = SQLITE_OPEN_READWRITE; + }else + if( strcmp(z,"result-trace")==0 ){ + runFlags |= SQL_OUTPUT; + }else + if( strcmp(z,"script")==0 ){ + bScript = 1; + }else + if( strcmp(z,"skip")==0 ){ + if( i>=argc-1 ) fatalError("missing arguments on %s", argv[i]); + nSkip = atoi(argv[++i]); + }else + if( strcmp(z,"spinner")==0 ){ + bSpinner = 1; + }else + if( strcmp(z,"timer")==0 ){ + bTimer = 1; + }else + if( strcmp(z,"sqlid")==0 ){ + if( i>=argc-1 ) fatalError("missing arguments on %s", argv[i]); + onlySqlid = integerValue(argv[++i]); + }else + if( strcmp(z,"timeout")==0 ){ + if( i>=argc-1 ) fatalError("missing arguments on %s", argv[i]); + iTimeout = integerValue(argv[++i]); + }else + if( strcmp(z,"timeout-test")==0 ){ + timeoutTest = 1; +#ifndef __unix__ + fatalError("timeout is not available on non-unix systems"); +#endif + }else + if( strcmp(z,"vdbe-debug")==0 ){ + bVdbeDebug = 1; + }else + if( strcmp(z,"verbose")==0 ){ + quietFlag = 0; + verboseFlag++; + eVerbosity++; + if( verboseFlag>2 ) runFlags |= SQL_TRACE; + }else + if( (nV = numberOfVChar(z))>=1 ){ + quietFlag = 0; + verboseFlag += nV; + eVerbosity += nV; + if( verboseFlag>2 ) runFlags |= SQL_TRACE; + }else + if( strcmp(z,"version")==0 ){ + int ii; + const char *zz; + printf("SQLite %s %s (%d-bit)\n", + sqlite3_libversion(), sqlite3_sourceid(), + 8*(int)sizeof(char*)); + for(ii=0; (zz = sqlite3_compileoption_get(ii))!=0; ii++){ + printf("%s\n", zz); + } + return 0; + }else + if( strcmp(z,"wait")==0 ){ + int iDelay; + if( i>=argc-1 ) fatalError("missing arguments on %s", argv[i]); + iDelay = integerValue(argv[++i]); + printf("Waiting %d seconds:", iDelay); + fflush(stdout); + while( 1 /*exit-by-break*/ ){ + sqlite3_sleep(1000); + iDelay--; + if( iDelay<=0 ) break; + printf(" %d", iDelay); + fflush(stdout); + } + printf("\n"); + fflush(stdout); + }else + if( strcmp(z,"is-dbsql")==0 ){ + i++; + for(i++; i1 ){ + if( zMsg ){ + fatalError("cannot change the description of more than one database"); + } + if( zInsSql ){ + fatalError("cannot import into more than one database"); + } + } + + /* Process each source database separately */ + for(iSrcDb=0; iSrcDbzName); + if( rc==SQLITE_OK ){ + rc = sqlite3_exec(db, "SELECT count(*) FROM sqlite_schema", 0, 0, 0); + } + if( rc ){ + sqlite3_close(db); + zRawData = readFile(azSrcDb[iSrcDb], &nRawData); + if( zRawData==0 ){ + fatalError("input file \"%s\" is not recognized\n", azSrcDb[iSrcDb]); + } + sqlite3_open(":memory:", &db); + } + + /* Print the description, if there is one */ + if( infoFlag ){ + int n; + zDbName = azSrcDb[iSrcDb]; + i = (int)strlen(zDbName) - 1; + while( i>0 && zDbName[i-1]!='/' && zDbName[i-1]!='\\' ){ i--; } + zDbName += i; + sqlite3_prepare_v2(db, "SELECT msg FROM readme", -1, &pStmt, 0); + if( pStmt && sqlite3_step(pStmt)==SQLITE_ROW ){ + printf("%s: %s", zDbName, sqlite3_column_text(pStmt,0)); + }else{ + printf("%s: (empty \"readme\")", zDbName); + } + sqlite3_finalize(pStmt); + sqlite3_prepare_v2(db, "SELECT count(*) FROM db", -1, &pStmt, 0); + if( pStmt + && sqlite3_step(pStmt)==SQLITE_ROW + && (n = sqlite3_column_int(pStmt,0))>0 + ){ + printf(" - %d DBs", n); + } + sqlite3_finalize(pStmt); + sqlite3_prepare_v2(db, "SELECT count(*) FROM xsql", -1, &pStmt, 0); + if( pStmt + && sqlite3_step(pStmt)==SQLITE_ROW + && (n = sqlite3_column_int(pStmt,0))>0 + ){ + printf(" - %d scripts", n); + } + sqlite3_finalize(pStmt); + printf("\n"); + sqlite3_close(db); + sqlite3_free(zRawData); + continue; + } + + rc = sqlite3_exec(db, + "CREATE TABLE IF NOT EXISTS db(\n" + " dbid INTEGER PRIMARY KEY, -- database id\n" + " dbcontent BLOB -- database disk file image\n" + ");\n" + "CREATE TABLE IF NOT EXISTS xsql(\n" + " sqlid INTEGER PRIMARY KEY, -- SQL script id\n" + " sqltext TEXT -- Text of SQL statements to run\n" + ");" + "CREATE TABLE IF NOT EXISTS readme(\n" + " msg TEXT -- Human-readable description of this file\n" + ");", 0, 0, 0); + if( rc ) fatalError("cannot create schema: %s", sqlite3_errmsg(db)); + if( zMsg ){ + char *zSql; + zSql = sqlite3_mprintf( + "DELETE FROM readme; INSERT INTO readme(msg) VALUES(%Q)", zMsg); + rc = sqlite3_exec(db, zSql, 0, 0, 0); + sqlite3_free(zSql); + if( rc ) fatalError("cannot change description: %s", sqlite3_errmsg(db)); + } + if( zRawData ){ + zInsSql = "INSERT INTO xsql(sqltext) VALUES(?1)"; + rc = sqlite3_prepare_v2(db, zInsSql, -1, &pStmt, 0); + if( rc ) fatalError("cannot prepare statement [%s]: %s", + zInsSql, sqlite3_errmsg(db)); + sqlite3_bind_text(pStmt, 1, zRawData, nRawData, SQLITE_STATIC); + sqlite3_step(pStmt); + rc = sqlite3_reset(pStmt); + if( rc ) fatalError("insert failed for %s", argv[i]); + sqlite3_finalize(pStmt); + rebuild_database(db, dbSqlOnly); + zInsSql = 0; + sqlite3_free(zRawData); + zRawData = 0; + } + ossFuzzThisDb = ossFuzz; + + /* If the CONFIG(name,value) table exists, read db-specific settings + ** from that table */ + if( sqlite3_table_column_metadata(db,0,"config",0,0,0,0,0,0)==SQLITE_OK ){ + rc = sqlite3_prepare_v2(db, "SELECT name, value FROM config", + -1, &pStmt, 0); + if( rc ) fatalError("cannot prepare query of CONFIG table: %s", + sqlite3_errmsg(db)); + while( SQLITE_ROW==sqlite3_step(pStmt) ){ + const char *zName = (const char *)sqlite3_column_text(pStmt,0); + if( zName==0 ) continue; + if( strcmp(zName, "oss-fuzz")==0 ){ + ossFuzzThisDb = sqlite3_column_int(pStmt,1); + if( verboseFlag>1 ) printf("Config: oss-fuzz=%d\n", ossFuzzThisDb); + } + if( strcmp(zName, "limit-mem")==0 ){ + nMemThisDb = sqlite3_column_int(pStmt,1); + if( verboseFlag>1 ) printf("Config: limit-mem=%d\n", nMemThisDb); + } + } + sqlite3_finalize(pStmt); + } + + if( zInsSql ){ + sqlite3_create_function(db, "readfile", 1, SQLITE_UTF8, 0, + readfileFunc, 0, 0); + sqlite3_create_function(db, "readtextfile", 1, SQLITE_UTF8, 0, + readtextfileFunc, 0, 0); + sqlite3_create_function(db, "isdbsql", 1, SQLITE_UTF8, 0, + isDbSqlFunc, 0, 0); + rc = sqlite3_prepare_v2(db, zInsSql, -1, &pStmt, 0); + if( rc ) fatalError("cannot prepare statement [%s]: %s", + zInsSql, sqlite3_errmsg(db)); + rc = sqlite3_exec(db, "BEGIN", 0, 0, 0); + if( rc ) fatalError("cannot start a transaction"); + for(i=iFirstInsArg; i0 && zLine[kk-1]<=' ' ) kk--; + sqlite3_bind_text(pStmt, 1, zLine, (int)kk, SQLITE_STATIC); + if( verboseFlag>1 ) printf("loading %.*s\n", (int)kk, zLine); + sqlite3_step(pStmt); + rc = sqlite3_reset(pStmt); + if( rc ) fatalError("insert failed for %s", zLine); + } + }else{ + sqlite3_bind_text(pStmt, 1, argv[i], -1, SQLITE_STATIC); + if( verboseFlag>1 ) printf("loading %s\n", argv[i]); + sqlite3_step(pStmt); + rc = sqlite3_reset(pStmt); + if( rc ) fatalError("insert failed for %s", argv[i]); + } + } + sqlite3_finalize(pStmt); + rc = sqlite3_exec(db, "COMMIT", 0, 0, 0); + if( rc ) fatalError("cannot commit the transaction: %s", + sqlite3_errmsg(db)); + rebuild_database(db, dbSqlOnly); + sqlite3_close(db); + return 0; + } + rc = sqlite3_exec(db, "PRAGMA query_only=1;", 0, 0, 0); + if( rc ) fatalError("cannot set database to query-only"); + if( zExpDb!=0 || zExpSql!=0 ){ + sqlite3_create_function(db, "writefile", 2, SQLITE_UTF8, 0, + writefileFunc, 0, 0); + if( zExpDb!=0 ){ + const char *zExDb = + "SELECT writefile(printf('%s/db%06d.db',?1,dbid),dbcontent)," + " dbid, printf('%s/db%06d.db',?1,dbid), length(dbcontent)" + " FROM db WHERE ?2<0 OR dbid=?2;"; + rc = sqlite3_prepare_v2(db, zExDb, -1, &pStmt, 0); + if( rc ) fatalError("cannot prepare statement [%s]: %s", + zExDb, sqlite3_errmsg(db)); + sqlite3_bind_text64(pStmt, 1, zExpDb, strlen(zExpDb), + SQLITE_STATIC, SQLITE_UTF8); + sqlite3_bind_int(pStmt, 2, onlyDbid); + while( sqlite3_step(pStmt)==SQLITE_ROW ){ + printf("write db-%d (%d bytes) into %s\n", + sqlite3_column_int(pStmt,1), + sqlite3_column_int(pStmt,3), + sqlite3_column_text(pStmt,2)); + } + sqlite3_finalize(pStmt); + } + if( zExpSql!=0 ){ + const char *zExSql = + "SELECT writefile(printf('%s/sql%06d.txt',?1,sqlid),sqltext)," + " sqlid, printf('%s/sql%06d.txt',?1,sqlid), length(sqltext)" + " FROM xsql WHERE ?2<0 OR sqlid=?2;"; + rc = sqlite3_prepare_v2(db, zExSql, -1, &pStmt, 0); + if( rc ) fatalError("cannot prepare statement [%s]: %s", + zExSql, sqlite3_errmsg(db)); + sqlite3_bind_text64(pStmt, 1, zExpSql, strlen(zExpSql), + SQLITE_STATIC, SQLITE_UTF8); + sqlite3_bind_int(pStmt, 2, onlySqlid); + while( sqlite3_step(pStmt)==SQLITE_ROW ){ + printf("write sql-%d (%d bytes) into %s\n", + sqlite3_column_int(pStmt,1), + sqlite3_column_int(pStmt,3), + sqlite3_column_text(pStmt,2)); + } + sqlite3_finalize(pStmt); + } + sqlite3_close(db); + return 0; + } + + /* Load all SQL script content and all initial database images from the + ** source db + */ + blobListLoadFromDb(db, "SELECT sqlid, sqltext FROM xsql", onlySqlid, + &g.nSql, &g.pFirstSql); + if( g.nSql==0 ) fatalError("need at least one SQL script"); + blobListLoadFromDb(db, "SELECT dbid, dbcontent FROM db", onlyDbid, + &g.nDb, &g.pFirstDb); + if( g.nDb==0 ){ + g.pFirstDb = safe_realloc(0, sizeof(Blob)); + memset(g.pFirstDb, 0, sizeof(Blob)); + g.pFirstDb->id = 1; + g.pFirstDb->seq = 0; + g.nDb = 1; + sqlFuzz = 1; + } + + /* Print the description, if there is one */ + if( !quietFlag && !bScript ){ + zDbName = azSrcDb[iSrcDb]; + i = (int)strlen(zDbName) - 1; + while( i>0 && zDbName[i-1]!='/' && zDbName[i-1]!='\\' ){ i--; } + zDbName += i; + if( verboseFlag ){ + sqlite3_prepare_v2(db, "SELECT msg FROM readme", -1, &pStmt, 0); + if( pStmt && sqlite3_step(pStmt)==SQLITE_ROW ){ + printf("%s: %s\n", zDbName, sqlite3_column_text(pStmt,0)); + } + sqlite3_finalize(pStmt); + } + } + + /* Rebuild the database, if requested */ + if( rebuildFlag ){ + if( !quietFlag ){ + printf("%s: rebuilding... ", zDbName); + fflush(stdout); + } + rebuild_database(db, 0); + if( !quietFlag ) printf("done\n"); + } + + /* Close the source database. Verify that no SQLite memory allocations are + ** outstanding. + */ + sqlite3_close(db); + if( sqlite3_memory_used()>0 ){ + fatalError("SQLite has memory in use before the start of testing"); + } + + /* Limit available memory, if requested */ + sqlite3_shutdown(); + + if( nMemThisDb>0 && nMem==0 ){ + if( !nativeMalloc ){ + pHeap = realloc(pHeap, nMemThisDb); + if( pHeap==0 ){ + fatalError("failed to allocate %d bytes of heap memory", nMem); + } + sqlite3_config(SQLITE_CONFIG_HEAP, pHeap, nMemThisDb, 128); + }else{ + sqlite3_hard_heap_limit64((sqlite3_int64)nMemThisDb); + } + }else{ + sqlite3_hard_heap_limit64(0); + } + + /* Disable lookaside with the --native-malloc option */ + if( nativeMalloc ){ + sqlite3_config(SQLITE_CONFIG_LOOKASIDE, 0, 0); + } + + /* Reset the in-memory virtual filesystem */ + formatVfs(); + + /* Run a test using each SQL script against each database. + */ + if( verboseFlag<2 && !quietFlag && !bSpinner && !bScript ){ + printf("%s:", zDbName); + } + for(pSql=g.pFirstSql; pSql; pSql=pSql->pNext){ + tmStart = timeOfDay(); + if( isDbSql(pSql->a, pSql->sz) ){ + sqlite3_snprintf(sizeof(g.zTestName), g.zTestName, "sqlid=%d",pSql->id); + if( bScript ){ + /* No progress output */ + }else if( bSpinner ){ + int nTotal =g.nSql; + int idx = pSql->seq; + printf("\r%s: %d/%d ", zDbName, idx, nTotal); + fflush(stdout); + }else if( verboseFlag>1 ){ + printf("%s\n", g.zTestName); + fflush(stdout); + }else if( !quietFlag ){ + static int prevAmt = -1; + int idx = pSql->seq; + int amt = idx*10/(g.nSql); + if( amt!=prevAmt ){ + printf(" %d%%", amt*10); + fflush(stdout); + prevAmt = amt; + } + } + if( nSkip>0 ){ + nSkip--; + }else{ + runCombinedDbSqlInput(pSql->a, pSql->sz, iTimeout, bScript, pSql->id); + } + nTest++; + if( bTimer && !bScript ){ + sqlite3_int64 tmEnd = timeOfDay(); + printf("%lld %s\n", tmEnd - tmStart, g.zTestName); + } + g.zTestName[0] = 0; + disableOom(); + continue; + } + for(pDb=g.pFirstDb; pDb; pDb=pDb->pNext){ + int openFlags; + const char *zVfs = "inmem"; + sqlite3_snprintf(sizeof(g.zTestName), g.zTestName, "sqlid=%d,dbid=%d", + pSql->id, pDb->id); + if( bScript ){ + /* No progress output */ + }else if( bSpinner ){ + int nTotal = g.nDb*g.nSql; + int idx = pSql->seq*g.nDb + pDb->id - 1; + printf("\r%s: %d/%d ", zDbName, idx, nTotal); + fflush(stdout); + }else if( verboseFlag>1 ){ + printf("%s\n", g.zTestName); + fflush(stdout); + }else if( !quietFlag ){ + static int prevAmt = -1; + int idx = pSql->seq*g.nDb + pDb->id - 1; + int amt = idx*10/(g.nDb*g.nSql); + if( amt!=prevAmt ){ + printf(" %d%%", amt*10); + fflush(stdout); + prevAmt = amt; + } + } + if( nSkip>0 ){ + nSkip--; + continue; + } + if( bScript ){ + char zName[100]; + sqlite3_snprintf(sizeof(zName), zName, "db%06d.db", + pDb->id>1 ? pDb->id : pSql->id); + renderDbSqlForCLI(stdout, zName, + pDb->a, pDb->sz, pSql->a, pSql->sz); + continue; + } + createVFile("main.db", pDb->sz, pDb->a); + sqlite3_randomness(0,0); + if( ossFuzzThisDb ){ +#ifndef SQLITE_OSS_FUZZ + fatalError("--oss-fuzz not supported: recompile" + " with -DSQLITE_OSS_FUZZ"); +#else + extern int LLVMFuzzerTestOneInput(const uint8_t*, size_t); + LLVMFuzzerTestOneInput((const uint8_t*)pSql->a, (size_t)pSql->sz); +#endif + }else{ + openFlags = SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE; + if( nativeFlag && pDb->sz==0 ){ + openFlags |= SQLITE_OPEN_MEMORY; + zVfs = 0; + } + rc = sqlite3_open_v2("main.db", &db, openFlags, zVfs); + if( rc ) fatalError("cannot open inmem database"); + sqlite3_limit(db, SQLITE_LIMIT_LENGTH, 100000000); + sqlite3_limit(db, SQLITE_LIMIT_LIKE_PATTERN_LENGTH, 50); + if( cellSzCkFlag ) runSql(db, "PRAGMA cell_size_check=ON", runFlags); + setAlarm((iTimeout+999)/1000); + /* Enable test functions */ + sqlite3_test_control(SQLITE_TESTCTRL_INTERNAL_FUNCTIONS, db); +#ifndef SQLITE_OMIT_PROGRESS_CALLBACK + if( sqlFuzz || vdbeLimitFlag ){ + sqlite3_progress_handler(db, 100000, progressHandler, + &vdbeLimitFlag); + } +#endif +#ifdef SQLITE_TESTCTRL_PRNG_SEED + sqlite3_test_control(SQLITE_TESTCTRL_PRNG_SEED, 1, db); +#endif + if( bVdbeDebug ){ + sqlite3_exec(db, "PRAGMA vdbe_debug=ON", 0, 0, 0); + } + do{ + runSql(db, (char*)pSql->a, runFlags); + }while( timeoutTest ); + setAlarm(0); + sqlite3_exec(db, "PRAGMA temp_store_directory=''", 0, 0, 0); + sqlite3_close(db); + } + if( sqlite3_memory_used()>0 ){ + fatalError("memory leak: %lld bytes outstanding", + sqlite3_memory_used()); + } + reformatVfs(); + nTest++; + if( bTimer ){ + sqlite3_int64 tmEnd = timeOfDay(); + printf("%lld %s\n", tmEnd - tmStart, g.zTestName); + } + g.zTestName[0] = 0; + + /* Simulate an error if the TEST_FAILURE environment variable is "5". + ** This is used to verify that automated test script really do spot + ** errors that occur in this test program. + */ + if( zFailCode ){ + if( zFailCode[0]=='5' && zFailCode[1]==0 ){ + fatalError("simulated failure"); + }else if( zFailCode[0]!=0 ){ + /* If TEST_FAILURE is something other than 5, just exit the test + ** early */ + printf("\nExit early due to TEST_FAILURE being set\n"); + iSrcDb = nSrcDb-1; + goto sourcedb_cleanup; + } + } + } + } + if( bScript ){ + /* No progress output */ + }else if( bSpinner ){ + int nTotal = g.nDb*g.nSql; + printf("\r%s: %d/%d \n", zDbName, nTotal, nTotal); + }else if( !quietFlag && verboseFlag<2 ){ + printf(" 100%% - %d tests\n", g.nDb*g.nSql); + } + + /* Clean up at the end of processing a single source database + */ + sourcedb_cleanup: + blobListFree(g.pFirstSql); + blobListFree(g.pFirstDb); + reformatVfs(); + + } /* End loop over all source databases */ + + if( !quietFlag && !bScript ){ + sqlite3_int64 iElapse = timeOfDay() - iBegin; + if( g.nInvariant ){ + printf("fuzzcheck: %u query invariants checked\n", g.nInvariant); + } + printf("fuzzcheck: 0 errors out of %d tests in %d.%03d seconds\n" + "SQLite %s %s (%d-bit)\n", + nTest, (int)(iElapse/1000), (int)(iElapse%1000), + sqlite3_libversion(), sqlite3_sourceid(), + 8*(int)sizeof(char*)); + } + free(azSrcDb); + free(pHeap); + return 0; +} diff --git a/test/fuzzdata1.db b/test/fuzzdata1.db new file mode 100644 index 0000000..11a9174 Binary files /dev/null and b/test/fuzzdata1.db differ diff --git a/test/fuzzdata2.db b/test/fuzzdata2.db new file mode 100644 index 0000000..7682790 Binary files /dev/null and b/test/fuzzdata2.db differ diff --git a/test/fuzzdata3.db b/test/fuzzdata3.db new file mode 100644 index 0000000..0a41fd6 Binary files /dev/null and b/test/fuzzdata3.db differ diff --git a/test/fuzzdata4.db b/test/fuzzdata4.db new file mode 100644 index 0000000..254bf83 Binary files /dev/null and b/test/fuzzdata4.db differ diff --git a/test/fuzzdata5.db b/test/fuzzdata5.db new file mode 100644 index 0000000..cfb0ebe Binary files /dev/null and b/test/fuzzdata5.db differ diff --git a/test/fuzzdata6.db b/test/fuzzdata6.db new file mode 100644 index 0000000..67076d0 Binary files /dev/null and b/test/fuzzdata6.db differ diff --git a/test/fuzzdata7.db b/test/fuzzdata7.db new file mode 100644 index 0000000..99daab1 Binary files /dev/null and b/test/fuzzdata7.db differ diff --git a/test/fuzzdata8.db b/test/fuzzdata8.db new file mode 100644 index 0000000..3e34180 Binary files /dev/null and b/test/fuzzdata8.db differ diff --git a/test/fuzzer1.test b/test/fuzzer1.test new file mode 100644 index 0000000..5e361e9 --- /dev/null +++ b/test/fuzzer1.test @@ -0,0 +1,1820 @@ +# 2011 March 25 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for TCL interface to the +# SQLite library. +# +# The focus of the tests is the word-fuzzer virtual table. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !vtab { + finish_test + return +} + +set ::testprefix fuzzer1 +load_static_extension db fuzzer + +# Check configuration errors. +# +do_catchsql_test fuzzer1-1.1 { + CREATE VIRTUAL TABLE f USING fuzzer; +} {1 {fuzzer: wrong number of CREATE VIRTUAL TABLE arguments}} + +do_catchsql_test fuzzer1-1.2 { + CREATE VIRTUAL TABLE f USING fuzzer(one, two); +} {1 {fuzzer: wrong number of CREATE VIRTUAL TABLE arguments}} + +do_catchsql_test fuzzer1-1.3 { + CREATE VIRTUAL TABLE f USING fuzzer(nosuchtable); +} {1 {fuzzer: no such table: main.nosuchtable}} + +do_catchsql_test fuzzer1-1.4 { + CREATE TEMP TABLE nosuchtable(a, b, c, d); + CREATE VIRTUAL TABLE f USING fuzzer(nosuchtable); +} {1 {fuzzer: no such table: main.nosuchtable}} + +do_catchsql_test fuzzer1-1.5 { + DROP TABLE temp.nosuchtable; + CREATE TABLE nosuchtable(a, b, c, d); + CREATE VIRTUAL TABLE temp.f USING fuzzer(nosuchtable); +} {1 {fuzzer: no such table: temp.nosuchtable}} + +do_catchsql_test fuzzer1-1.6 { + DROP TABLE IF EXISTS f_rules; + CREATE TABLE f_rules(a, b, c); + CREATE VIRTUAL TABLE f USING fuzzer(f_rules); +} {1 {fuzzer: f_rules has 3 columns, expected 4}} + +do_catchsql_test fuzzer1-1.7 { + DROP TABLE IF EXISTS f_rules; + CREATE TABLE f_rules(a, b, c, d, e); + CREATE VIRTUAL TABLE f USING fuzzer(f_rules); +} {1 {fuzzer: f_rules has 5 columns, expected 4}} + + +do_execsql_test fuzzer1-2.1 { + CREATE TABLE f1_rules(ruleset DEFAULT 0, cfrom, cto, cost); + INSERT INTO f1_rules(cfrom, cto, cost) VALUES('e','a',1); + INSERT INTO f1_rules(cfrom, cto, cost) VALUES('a','e',10); + INSERT INTO f1_rules(cfrom, cto, cost) VALUES('e','o',100); + + CREATE VIRTUAL TABLE f1 USING fuzzer(f1_rules); +} {} + +do_execsql_test fuzzer1-2.1 { + SELECT word, distance FROM f1 WHERE word MATCH 'abcde' +} { + abcde 0 abcda 1 ebcde 10 + ebcda 11 abcdo 100 ebcdo 110 + obcde 110 obcda 111 obcdo 210 +} + +do_execsql_test fuzzer1-2.4 { + INSERT INTO f1_rules(ruleset, cfrom, cto, cost) VALUES(1,'b','x',1); + INSERT INTO f1_rules(ruleset, cfrom, cto, cost) VALUES(1,'d','y',10); + INSERT INTO f1_rules(ruleset, cfrom, cto, cost) VALUES(1,'y','z',100); + + DROP TABLE f1; + CREATE VIRTUAL TABLE f1 USING fuzzer(f1_rules); +} {} + +do_execsql_test fuzzer1-2.5 { + SELECT word, distance FROM f1 WHERE word MATCH 'abcde' +} { + abcde 0 abcda 1 ebcde 10 + ebcda 11 abcdo 100 ebcdo 110 + obcde 110 obcda 111 obcdo 210 +} + +do_execsql_test fuzzer1-2.6 { + SELECT word, distance FROM f1 WHERE word MATCH 'abcde' AND ruleset=0 +} { + abcde 0 abcda 1 ebcde 10 + ebcda 11 abcdo 100 ebcdo 110 + obcde 110 obcda 111 obcdo 210 +} + +do_execsql_test fuzzer1-2.7 { + SELECT word, distance FROM f1 WHERE word MATCH 'abcde' AND ruleset=1 +} { + abcde 0 axcde 1 abcye 10 + axcye 11 abcze 110 axcze 111 +} + +do_test fuzzer1-1.8 { + db eval { + SELECT word, distance FROM f1 WHERE word MATCH 'abcde' AND distance<100 + } +} {abcde 0 abcda 1 ebcde 10 ebcda 11} +do_test fuzzer1-1.9 { + db eval { + SELECT word, distance FROM f1 WHERE word MATCH 'abcde' AND distance<=100 + } +} {abcde 0 abcda 1 ebcde 10 ebcda 11 abcdo 100} +do_test fuzzer1-1.10 { + db eval { + SELECT word, distance FROM f1 + WHERE word MATCH 'abcde' AND distance<100 AND ruleset=0 + } +} {abcde 0 abcda 1 ebcde 10 ebcda 11} +do_test fuzzer1-1.11 { + db eval { + SELECT word, distance FROM f1 + WHERE word MATCH 'abcde' AND distance<=100 AND ruleset=0 + } +} {abcde 0 abcda 1 ebcde 10 ebcda 11 abcdo 100} +do_test fuzzer1-1.12 { + db eval { + SELECT word, distance FROM f1 + WHERE word MATCH 'abcde' AND distance<11 AND ruleset=1 + } +} {abcde 0 axcde 1 abcye 10} +do_test fuzzer1-1.13 { + db eval { + SELECT word, distance FROM f1 + WHERE word MATCH 'abcde' AND distance<=11 AND ruleset=1 + } +} {abcde 0 axcde 1 abcye 10 axcye 11} +do_test fuzzer1-1.14 { + catchsql {INSERT INTO f1 VALUES(1)} +} {1 {table f1 may not be modified}} +do_test fuzzer1-1.15 { + catchsql {DELETE FROM f1} +} {1 {table f1 may not be modified}} +do_test fuzzer1-1.16 { + catchsql {UPDATE f1 SET rowid=rowid+10000} +} {1 {table f1 may not be modified}} + + +do_test fuzzer1-2.0 { + execsql { + -- costs based on English letter frequencies + CREATE TEMP TABLE f2_rules(ruleset DEFAULT 0, cFrom, cTo, cost); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('a','e',24); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('a','o',47); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('a','u',50); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('e','a',23); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('e','i',33); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('e','o',37); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('i','e',33); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('i','y',33); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('o','a',41); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('o','e',46); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('o','u',57); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('u','o',58); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('y','i',33); + + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('t','th',70); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('th','t',66); + + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('a','',84); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','b',106); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('b','',106); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','c',94); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('c','',94); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','d',89); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('d','',89); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','e',83); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('e','',83); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','f',97); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('f','',97); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','g',99); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('g','',99); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','h',86); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('h','',86); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','i',85); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('i','',85); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','j',120); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('j','',120); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','k',120); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('k','',120); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','l',89); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('l','',89); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','m',96); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('m','',96); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','n',85); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('n','',85); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','o',85); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('o','',85); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','p',100); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('p','',100); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','q',120); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('q','',120); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','r',86); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('r','',86); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','s',86); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('s','',86); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','t',84); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('t','',84); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','u',94); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('u','',94); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','v',120); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('v','',120); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','w',96); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('w','',96); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','x',120); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('x','',120); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','y',100); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('y','',100); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','z',120); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('z','',120); + INSERT INTO f2_rules(ruleset,cFrom,cTo,cost) + SELECT 1, cFrom, cTo, 100 FROM f2_rules WHERE ruleset=0; + INSERT INTO f2_rules(ruleset,cFrom,cTo,cost) + SELECT 2, cFrom, cTo, 200-cost FROM f2_rules WHERE ruleset=0; + INSERT INTO f2_rules(ruleset,cFrom,cTo,cost) + SELECT 3, cFrom, cTo, cost FROM f2_rules WHERE ruleset=0; + INSERT INTO f2_rules(ruleset,cFrom,cTo,cost) + VALUES(3, 'mallard','duck',50), + (3, 'duck', 'mallard', 50), + (3, 'rock', 'stone', 50), + (3, 'stone', 'rock', 50); + + + CREATE VIRTUAL TABLE temp.f2 USING fuzzer(f2_rules); + + -- Street names for the 28269 ZIPCODE. + -- + CREATE TEMP TABLE streetname(n TEXT UNIQUE); + INSERT INTO streetname VALUES('abbotsinch'); + INSERT INTO streetname VALUES('abbottsgate'); + INSERT INTO streetname VALUES('abbywood'); + INSERT INTO streetname VALUES('abner'); + INSERT INTO streetname VALUES('acacia ridge'); + INSERT INTO streetname VALUES('acorn creek'); + INSERT INTO streetname VALUES('acorn forest'); + INSERT INTO streetname VALUES('adel'); + INSERT INTO streetname VALUES('ainslie'); + INSERT INTO streetname VALUES('airways'); + INSERT INTO streetname VALUES('alabaster'); + INSERT INTO streetname VALUES('alba'); + INSERT INTO streetname VALUES('albertine'); + INSERT INTO streetname VALUES('alden glen'); + INSERT INTO streetname VALUES('alderson'); + INSERT INTO streetname VALUES('allen'); + INSERT INTO streetname VALUES('allen a brown'); + INSERT INTO streetname VALUES('allness glen'); + INSERT INTO streetname VALUES('aloysia'); + INSERT INTO streetname VALUES('alpine'); + INSERT INTO streetname VALUES('alwyn'); + INSERT INTO streetname VALUES('amaranthus'); + INSERT INTO streetname VALUES('amber glen'); + INSERT INTO streetname VALUES('amber leigh way'); + INSERT INTO streetname VALUES('amber meadows'); + INSERT INTO streetname VALUES('amberway'); + INSERT INTO streetname VALUES('ame'); + INSERT INTO streetname VALUES('amesbury hill'); + INSERT INTO streetname VALUES('anderson'); + INSERT INTO streetname VALUES('andrew thomas'); + INSERT INTO streetname VALUES('anduin falls'); + INSERT INTO streetname VALUES('ankeny'); + INSERT INTO streetname VALUES('annandale'); + INSERT INTO streetname VALUES('annbick'); + INSERT INTO streetname VALUES('antelope'); + INSERT INTO streetname VALUES('anzack'); + INSERT INTO streetname VALUES('apple glen'); + INSERT INTO streetname VALUES('applevalley'); + INSERT INTO streetname VALUES('appley mead'); + INSERT INTO streetname VALUES('aragorn'); + INSERT INTO streetname VALUES('arbor creek'); + INSERT INTO streetname VALUES('arbor day'); + INSERT INTO streetname VALUES('arbor meadows'); + INSERT INTO streetname VALUES('arbor spring'); + INSERT INTO streetname VALUES('arborview'); + INSERT INTO streetname VALUES('arklow'); + INSERT INTO streetname VALUES('armitage'); + INSERT INTO streetname VALUES('arvin'); + INSERT INTO streetname VALUES('ash cove'); + INSERT INTO streetname VALUES('ashford leigh'); + INSERT INTO streetname VALUES('ashmont'); + INSERT INTO streetname VALUES('atlas'); + INSERT INTO streetname VALUES('atwater'); + INSERT INTO streetname VALUES('auburn hill'); + INSERT INTO streetname VALUES('aulton link'); + INSERT INTO streetname VALUES('austin dekota'); + INSERT INTO streetname VALUES('austin knoll'); + INSERT INTO streetname VALUES('auten'); + INSERT INTO streetname VALUES('autumn harvest'); + INSERT INTO streetname VALUES('autumn oak'); + INSERT INTO streetname VALUES('autumn ridge'); + INSERT INTO streetname VALUES('avalon forest'); + INSERT INTO streetname VALUES('avalon loop'); + INSERT INTO streetname VALUES('avon farm'); + INSERT INTO streetname VALUES('avonhurst'); + INSERT INTO streetname VALUES('avonlea'); + INSERT INTO streetname VALUES('aynrand'); + INSERT INTO streetname VALUES('azure valley'); + INSERT INTO streetname VALUES('baberton'); + INSERT INTO streetname VALUES('baffin'); + INSERT INTO streetname VALUES('baggins'); + INSERT INTO streetname VALUES('balata'); + INSERT INTO streetname VALUES('ballantray'); + INSERT INTO streetname VALUES('ballston'); + INSERT INTO streetname VALUES('balsam tree'); + INSERT INTO streetname VALUES('bambi'); + INSERT INTO streetname VALUES('banwell'); + INSERT INTO streetname VALUES('barbee'); + INSERT INTO streetname VALUES('barefoot forest'); + INSERT INTO streetname VALUES('barnview'); + INSERT INTO streetname VALUES('baroda'); + INSERT INTO streetname VALUES('barson'); + INSERT INTO streetname VALUES('baskerville'); + INSERT INTO streetname VALUES('battle creek'); + INSERT INTO streetname VALUES('baucom'); + INSERT INTO streetname VALUES('bay pines'); + INSERT INTO streetname VALUES('beaker'); + INSERT INTO streetname VALUES('beard'); + INSERT INTO streetname VALUES('beardsley'); + INSERT INTO streetname VALUES('bearoak'); + INSERT INTO streetname VALUES('beauvista'); + INSERT INTO streetname VALUES('beaver creek'); + INSERT INTO streetname VALUES('beaver hollow'); + INSERT INTO streetname VALUES('bedlington'); + INSERT INTO streetname VALUES('beech cove'); + INSERT INTO streetname VALUES('beech crest'); + INSERT INTO streetname VALUES('beith'); + INSERT INTO streetname VALUES('bell glen'); + INSERT INTO streetname VALUES('bellmore'); + INSERT INTO streetname VALUES('bells mill'); + INSERT INTO streetname VALUES('bellville'); + INSERT INTO streetname VALUES('belmar place'); + INSERT INTO streetname VALUES('bembridge'); + INSERT INTO streetname VALUES('bennett neely'); + INSERT INTO streetname VALUES('bentgrass run'); + INSERT INTO streetname VALUES('benthaven'); + INSERT INTO streetname VALUES('bernardy'); + INSERT INTO streetname VALUES('bernbrook shadow'); + INSERT INTO streetname VALUES('berrybrook'); + INSERT INTO streetname VALUES('berrybush'); + INSERT INTO streetname VALUES('berwick'); + INSERT INTO streetname VALUES('betterton'); + INSERT INTO streetname VALUES('bickham'); + INSERT INTO streetname VALUES('billingham'); + INSERT INTO streetname VALUES('birchcroft'); + INSERT INTO streetname VALUES('birchstone'); + INSERT INTO streetname VALUES('birdwell'); + INSERT INTO streetname VALUES('bisaner'); + INSERT INTO streetname VALUES('bitterbush'); + INSERT INTO streetname VALUES('bitterroot'); + INSERT INTO streetname VALUES('black fox'); + INSERT INTO streetname VALUES('black maple'); + INSERT INTO streetname VALUES('black trail'); + INSERT INTO streetname VALUES('blackbird'); + INSERT INTO streetname VALUES('blake a dare'); + INSERT INTO streetname VALUES('blasdell'); + INSERT INTO streetname VALUES('blue aster'); + INSERT INTO streetname VALUES('blue finch'); + INSERT INTO streetname VALUES('blue lilac'); + INSERT INTO streetname VALUES('blue sky'); + INSERT INTO streetname VALUES('blue tick'); + INSERT INTO streetname VALUES('bob beatty'); + INSERT INTO streetname VALUES('bobcat'); + INSERT INTO streetname VALUES('bolton'); + INSERT INTO streetname VALUES('boomerang'); + INSERT INTO streetname VALUES('boulder'); + INSERT INTO streetname VALUES('boxer'); + INSERT INTO streetname VALUES('boxmeer'); + INSERT INTO streetname VALUES('brachnell view'); + INSERT INTO streetname VALUES('bradford lake'); + INSERT INTO streetname VALUES('bradwell'); + INSERT INTO streetname VALUES('brady'); + INSERT INTO streetname VALUES('braids bend'); + INSERT INTO streetname VALUES('bralers'); + INSERT INTO streetname VALUES('brandie glen'); + INSERT INTO streetname VALUES('brandy ridge'); + INSERT INTO streetname VALUES('brandybuck'); + INSERT INTO streetname VALUES('branthurst'); + INSERT INTO streetname VALUES('brassy creek'); + INSERT INTO streetname VALUES('brathay'); + INSERT INTO streetname VALUES('brawer farm'); + INSERT INTO streetname VALUES('breezy morn'); + INSERT INTO streetname VALUES('brenda'); + INSERT INTO streetname VALUES('brenly'); + INSERT INTO streetname VALUES('brenock'); + INSERT INTO streetname VALUES('brianwood'); + INSERT INTO streetname VALUES('briar rose'); + INSERT INTO streetname VALUES('briarcrest'); + INSERT INTO streetname VALUES('briarthorne'); + INSERT INTO streetname VALUES('brick dust'); + INSERT INTO streetname VALUES('bridgepath'); + INSERT INTO streetname VALUES('bridle ridge'); + INSERT INTO streetname VALUES('briggs'); + INSERT INTO streetname VALUES('brightleaf'); + INSERT INTO streetname VALUES('brigstock'); + INSERT INTO streetname VALUES('broad ridge'); + INSERT INTO streetname VALUES('brock'); + INSERT INTO streetname VALUES('brockhampton'); + INSERT INTO streetname VALUES('broken pine'); + INSERT INTO streetname VALUES('brompton'); + INSERT INTO streetname VALUES('brook falls'); + INSERT INTO streetname VALUES('brookings'); + INSERT INTO streetname VALUES('browne'); + INSERT INTO streetname VALUES('brownes creek'); + INSERT INTO streetname VALUES('brownes ferry'); + INSERT INTO streetname VALUES('brownestone view'); + INSERT INTO streetname VALUES('brumit'); + INSERT INTO streetname VALUES('bryn athyn'); + INSERT INTO streetname VALUES('buck'); + INSERT INTO streetname VALUES('bucklebury'); + INSERT INTO streetname VALUES('buckminister'); + INSERT INTO streetname VALUES('buckspring'); + INSERT INTO streetname VALUES('burch'); + INSERT INTO streetname VALUES('burch shire'); + INSERT INTO streetname VALUES('burkston'); + INSERT INTO streetname VALUES('burmith'); + INSERT INTO streetname VALUES('burnaby'); + INSERT INTO streetname VALUES('butterfly'); + INSERT INTO streetname VALUES('cabin creek'); + INSERT INTO streetname VALUES('cairns mill'); + INSERT INTO streetname VALUES('callender'); + INSERT INTO streetname VALUES('cambellton'); + INSERT INTO streetname VALUES('cambridge bay'); + INSERT INTO streetname VALUES('canary'); + INSERT INTO streetname VALUES('canbury'); + INSERT INTO streetname VALUES('candle leaf'); + INSERT INTO streetname VALUES('canipe'); + INSERT INTO streetname VALUES('canipe farm'); + INSERT INTO streetname VALUES('cannon'); + INSERT INTO streetname VALUES('canopy'); + INSERT INTO streetname VALUES('canso'); + INSERT INTO streetname VALUES('canterbrook'); + INSERT INTO streetname VALUES('cardinal glen'); + INSERT INTO streetname VALUES('cardinal point'); + INSERT INTO streetname VALUES('cardinals nest'); + INSERT INTO streetname VALUES('carlota'); + INSERT INTO streetname VALUES('carmathen'); + INSERT INTO streetname VALUES('carver'); + INSERT INTO streetname VALUES('carver pond'); + INSERT INTO streetname VALUES('casa loma'); + INSERT INTO streetname VALUES('caselton'); + INSERT INTO streetname VALUES('castello'); + INSERT INTO streetname VALUES('castle ridge'); + INSERT INTO streetname VALUES('castleglen'); + INSERT INTO streetname VALUES('castlemaine'); + INSERT INTO streetname VALUES('cavett'); + INSERT INTO streetname VALUES('caymus'); + INSERT INTO streetname VALUES('cedardale ridge'); + INSERT INTO streetname VALUES('cedarhurst'); + INSERT INTO streetname VALUES('cemkey way'); + INSERT INTO streetname VALUES('cerise'); + INSERT INTO streetname VALUES('chaceview'); + INSERT INTO streetname VALUES('chadsworth'); + INSERT INTO streetname VALUES('chadwell'); + INSERT INTO streetname VALUES('champions crest'); + INSERT INTO streetname VALUES('chandler haven'); + INSERT INTO streetname VALUES('chapel crossing'); + INSERT INTO streetname VALUES('chapel ridge'); + INSERT INTO streetname VALUES('charles crawford'); + INSERT INTO streetname VALUES('charminster'); + INSERT INTO streetname VALUES('chasewind'); + INSERT INTO streetname VALUES('chavel'); + INSERT INTO streetname VALUES('chelsea jade'); + INSERT INTO streetname VALUES('chestnut knoll'); + INSERT INTO streetname VALUES('cheviot'); + INSERT INTO streetname VALUES('chickadee'); + INSERT INTO streetname VALUES('chidley'); + INSERT INTO streetname VALUES('chimney ridge'); + INSERT INTO streetname VALUES('chimney springs'); + INSERT INTO streetname VALUES('chinaberry'); + INSERT INTO streetname VALUES('chinemist'); + INSERT INTO streetname VALUES('chinquapin'); + INSERT INTO streetname VALUES('chiswell'); + INSERT INTO streetname VALUES('christenbury'); + INSERT INTO streetname VALUES('christenbury hills'); + INSERT INTO streetname VALUES('churchill'); + INSERT INTO streetname VALUES('cindy'); + INSERT INTO streetname VALUES('cinnamon teal'); + INSERT INTO streetname VALUES('citadel'); + INSERT INTO streetname VALUES('clare olivia'); + INSERT INTO streetname VALUES('clarke creek'); + INSERT INTO streetname VALUES('clarke ridge'); + INSERT INTO streetname VALUES('clear day'); + INSERT INTO streetname VALUES('clear stream'); + INSERT INTO streetname VALUES('cleve brown'); + INSERT INTO streetname VALUES('cliff cameron'); + INSERT INTO streetname VALUES('cliffvale'); + INSERT INTO streetname VALUES('cloverside'); + INSERT INTO streetname VALUES('clymer'); + INSERT INTO streetname VALUES('coatbridge'); + INSERT INTO streetname VALUES('cobble glen'); + INSERT INTO streetname VALUES('cochran farm'); + INSERT INTO streetname VALUES('cochrane'); + INSERT INTO streetname VALUES('coleridge'); + INSERT INTO streetname VALUES('coleshire'); + INSERT INTO streetname VALUES('collins'); + INSERT INTO streetname VALUES('colvard'); + INSERT INTO streetname VALUES('colvard park'); + INSERT INTO streetname VALUES('condor'); + INSERT INTO streetname VALUES('conner ridge'); + INSERT INTO streetname VALUES('connery'); + INSERT INTO streetname VALUES('cooper run'); + INSERT INTO streetname VALUES('coopers ridge'); + INSERT INTO streetname VALUES('copper hill'); + INSERT INTO streetname VALUES('coppermine'); + INSERT INTO streetname VALUES('cornelia'); + INSERT INTO streetname VALUES('corner'); + INSERT INTO streetname VALUES('cornerstone'); + INSERT INTO streetname VALUES('cottage oaks'); + INSERT INTO streetname VALUES('cougar'); + INSERT INTO streetname VALUES('coves end'); + INSERT INTO streetname VALUES('cragland'); + INSERT INTO streetname VALUES('crail'); + INSERT INTO streetname VALUES('cranberry nook'); + INSERT INTO streetname VALUES('crawford brook'); + INSERT INTO streetname VALUES('crayton'); + INSERT INTO streetname VALUES('creek breeze'); + INSERT INTO streetname VALUES('crescent ridge'); + INSERT INTO streetname VALUES('crescent view'); + INSERT INTO streetname VALUES('cresta'); + INSERT INTO streetname VALUES('crestfield'); + INSERT INTO streetname VALUES('crestland'); + INSERT INTO streetname VALUES('crestwick'); + INSERT INTO streetname VALUES('crisfield'); + INSERT INTO streetname VALUES('crisp wood'); + INSERT INTO streetname VALUES('croft haven'); + INSERT INTO streetname VALUES('crofton springs'); + INSERT INTO streetname VALUES('cross'); + INSERT INTO streetname VALUES('crosspoint center'); + INSERT INTO streetname VALUES('crownvista'); + INSERT INTO streetname VALUES('crystal arms'); + INSERT INTO streetname VALUES('crystal crest'); + INSERT INTO streetname VALUES('crystal leaf'); + INSERT INTO streetname VALUES('cunningham park'); + INSERT INTO streetname VALUES('cypress pond'); + INSERT INTO streetname VALUES('daffodil'); + INSERT INTO streetname VALUES('daisyfield'); + INSERT INTO streetname VALUES('dalecrest'); + INSERT INTO streetname VALUES('dannelly park'); + INSERT INTO streetname VALUES('daphne'); + INSERT INTO streetname VALUES('daria'); + INSERT INTO streetname VALUES('dartmouth'); + INSERT INTO streetname VALUES('datha'); + INSERT INTO streetname VALUES('david cox'); + INSERT INTO streetname VALUES('davis'); + INSERT INTO streetname VALUES('davis crossing'); + INSERT INTO streetname VALUES('davis lake'); + INSERT INTO streetname VALUES('davis ridge'); + INSERT INTO streetname VALUES('dawnmist'); + INSERT INTO streetname VALUES('daybreak'); + INSERT INTO streetname VALUES('dearmon'); + INSERT INTO streetname VALUES('dearview'); + INSERT INTO streetname VALUES('deaton hill'); + INSERT INTO streetname VALUES('deer cross'); + INSERT INTO streetname VALUES('deerton'); + INSERT INTO streetname VALUES('degrasse'); + INSERT INTO streetname VALUES('delamere'); + INSERT INTO streetname VALUES('dellfield'); + INSERT INTO streetname VALUES('dellinger'); + INSERT INTO streetname VALUES('demington'); + INSERT INTO streetname VALUES('denmeade'); + INSERT INTO streetname VALUES('derita'); + INSERT INTO streetname VALUES('derita woods'); + INSERT INTO streetname VALUES('deruyter'); + INSERT INTO streetname VALUES('dervish'); + INSERT INTO streetname VALUES('devas'); + INSERT INTO streetname VALUES('devon croft'); + INSERT INTO streetname VALUES('devonbridge'); + INSERT INTO streetname VALUES('devongate'); + INSERT INTO streetname VALUES('devonhill'); + INSERT INTO streetname VALUES('dewmorn'); + INSERT INTO streetname VALUES('distribution center'); + INSERT INTO streetname VALUES('dominion crest'); + INSERT INTO streetname VALUES('dominion green'); + INSERT INTO streetname VALUES('dominion village'); + INSERT INTO streetname VALUES('dorshire'); + INSERT INTO streetname VALUES('double creek crossing'); + INSERT INTO streetname VALUES('dow'); + INSERT INTO streetname VALUES('downfield wood'); + INSERT INTO streetname VALUES('downing creek'); + INSERT INTO streetname VALUES('driscol'); + INSERT INTO streetname VALUES('driwood'); + INSERT INTO streetname VALUES('dry brook'); + INSERT INTO streetname VALUES('dumont'); + INSERT INTO streetname VALUES('dunblane'); + INSERT INTO streetname VALUES('dunfield'); + INSERT INTO streetname VALUES('dunoon'); + INSERT INTO streetname VALUES('dunslow'); + INSERT INTO streetname VALUES('dunstaff'); + INSERT INTO streetname VALUES('durham'); + INSERT INTO streetname VALUES('durston'); + INSERT INTO streetname VALUES('dusty cedar'); + INSERT INTO streetname VALUES('dusty trail'); + INSERT INTO streetname VALUES('dutchess'); + INSERT INTO streetname VALUES('duxford'); + INSERT INTO streetname VALUES('eagle creek'); + INSERT INTO streetname VALUES('eagles field'); + INSERT INTO streetname VALUES('eargle'); + INSERT INTO streetname VALUES('earlswood'); + INSERT INTO streetname VALUES('early mist'); + INSERT INTO streetname VALUES('earthenware'); + INSERT INTO streetname VALUES('eastfield park'); + INSERT INTO streetname VALUES('eastfield village'); + INSERT INTO streetname VALUES('easy'); + INSERT INTO streetname VALUES('eben'); + INSERT INTO streetname VALUES('edgepine'); + INSERT INTO streetname VALUES('edgewier'); + INSERT INTO streetname VALUES('edinburgh'); + INSERT INTO streetname VALUES('edinmeadow'); + INSERT INTO streetname VALUES('edmonton'); + INSERT INTO streetname VALUES('edwin jones'); + INSERT INTO streetname VALUES('elberon'); + INSERT INTO streetname VALUES('elderslie'); + INSERT INTO streetname VALUES('elementary view'); + INSERT INTO streetname VALUES('elendil'); + INSERT INTO streetname VALUES('elizabeth'); + INSERT INTO streetname VALUES('elm cove'); + INSERT INTO streetname VALUES('elrond'); + INSERT INTO streetname VALUES('elsenham'); + INSERT INTO streetname VALUES('elven'); + INSERT INTO streetname VALUES('emma lynn'); + INSERT INTO streetname VALUES('english setter'); + INSERT INTO streetname VALUES('enoch'); + INSERT INTO streetname VALUES('equipment'); + INSERT INTO streetname VALUES('ernest russell'); + INSERT INTO streetname VALUES('ernie'); + INSERT INTO streetname VALUES('esmeralda'); + INSERT INTO streetname VALUES('evergreen hollow'); + INSERT INTO streetname VALUES('eversfield'); + INSERT INTO streetname VALUES('ewen'); + INSERT INTO streetname VALUES('ewert cut'); + INSERT INTO streetname VALUES('exbury'); + INSERT INTO streetname VALUES('fair grounds park'); + INSERT INTO streetname VALUES('fairbourne'); + INSERT INTO streetname VALUES('fairchase'); + INSERT INTO streetname VALUES('faircreek'); + INSERT INTO streetname VALUES('fairglen'); + INSERT INTO streetname VALUES('fairlea'); + INSERT INTO streetname VALUES('fairmead'); + INSERT INTO streetname VALUES('fairmeadows'); + INSERT INTO streetname VALUES('fairstone'); + INSERT INTO streetname VALUES('fairvista'); + INSERT INTO streetname VALUES('fairway point'); + INSERT INTO streetname VALUES('falconcrest'); + INSERT INTO streetname VALUES('falls ridge'); + INSERT INTO streetname VALUES('falmouth'); + INSERT INTO streetname VALUES('far west'); + INSERT INTO streetname VALUES('farlow'); + INSERT INTO streetname VALUES('farris wheel'); + INSERT INTO streetname VALUES('fawndale'); + INSERT INTO streetname VALUES('feather bend'); + INSERT INTO streetname VALUES('fernledge'); + INSERT INTO streetname VALUES('fernmoss'); + INSERT INTO streetname VALUES('ferrell commons'); + INSERT INTO streetname VALUES('fieldstone'); + INSERT INTO streetname VALUES('fillian'); + INSERT INTO streetname VALUES('fincher'); + INSERT INTO streetname VALUES('foggy meadow'); + INSERT INTO streetname VALUES('fordyce'); + INSERT INTO streetname VALUES('forest grove'); + INSERT INTO streetname VALUES('forest path'); + INSERT INTO streetname VALUES('forestridge commons'); + INSERT INTO streetname VALUES('forestrock'); + INSERT INTO streetname VALUES('fortunes ridge'); + INSERT INTO streetname VALUES('founders club'); + INSERT INTO streetname VALUES('fountaingrass'); + INSERT INTO streetname VALUES('fox chase'); + INSERT INTO streetname VALUES('fox glen'); + INSERT INTO streetname VALUES('fox hill'); + INSERT INTO streetname VALUES('fox point'); + INSERT INTO streetname VALUES('fox trot'); + INSERT INTO streetname VALUES('foxbriar'); + INSERT INTO streetname VALUES('frank little'); + INSERT INTO streetname VALUES('franzia'); + INSERT INTO streetname VALUES('french woods'); + INSERT INTO streetname VALUES('frostmoor'); + INSERT INTO streetname VALUES('frye'); + INSERT INTO streetname VALUES('furlong'); + INSERT INTO streetname VALUES('galena view'); + INSERT INTO streetname VALUES('gallery pointe'); + INSERT INTO streetname VALUES('gammon'); + INSERT INTO streetname VALUES('garden grove'); + INSERT INTO streetname VALUES('gardendale'); + INSERT INTO streetname VALUES('garganey'); + INSERT INTO streetname VALUES('garnet field'); + INSERT INTO streetname VALUES('garrison'); + INSERT INTO streetname VALUES('garvin'); + INSERT INTO streetname VALUES('garvis'); + INSERT INTO streetname VALUES('gaskill'); + INSERT INTO streetname VALUES('gemstone'); + INSERT INTO streetname VALUES('gibbon'); + INSERT INTO streetname VALUES('gibbon terrace'); + INSERT INTO streetname VALUES('gibbons link'); + INSERT INTO streetname VALUES('gillman'); + INSERT INTO streetname VALUES('gladwood'); + INSERT INTO streetname VALUES('gladwyne'); + INSERT INTO streetname VALUES('glamorgan'); + INSERT INTO streetname VALUES('glaze'); + INSERT INTO streetname VALUES('glen brook'); + INSERT INTO streetname VALUES('glen cove'); + INSERT INTO streetname VALUES('glen hope'); + INSERT INTO streetname VALUES('glen manor'); + INSERT INTO streetname VALUES('glen olden'); + INSERT INTO streetname VALUES('glencairn'); + INSERT INTO streetname VALUES('glendock'); + INSERT INTO streetname VALUES('glenolden'); + INSERT INTO streetname VALUES('glenover'); + INSERT INTO streetname VALUES('glenshire'); + INSERT INTO streetname VALUES('glenstone'); + INSERT INTO streetname VALUES('gold dust'); + INSERT INTO streetname VALUES('golden pond'); + INSERT INTO streetname VALUES('goldenblush'); + INSERT INTO streetname VALUES('goldenfield'); + INSERT INTO streetname VALUES('goose landing'); + INSERT INTO streetname VALUES('gorham gate'); + INSERT INTO streetname VALUES('grabill'); + INSERT INTO streetname VALUES('graburns ford'); + INSERT INTO streetname VALUES('graham'); + INSERT INTO streetname VALUES('grahamson'); + INSERT INTO streetname VALUES('granard'); + INSERT INTO streetname VALUES('grand teton'); + INSERT INTO streetname VALUES('grande heights'); + INSERT INTO streetname VALUES('grandeur'); + INSERT INTO streetname VALUES('granite creek'); + INSERT INTO streetname VALUES('grasset'); + INSERT INTO streetname VALUES('graypark'); + INSERT INTO streetname VALUES('grays ridge'); + INSERT INTO streetname VALUES('great bear'); + INSERT INTO streetname VALUES('green clover'); + INSERT INTO streetname VALUES('green hedge'); + INSERT INTO streetname VALUES('green meadow'); + INSERT INTO streetname VALUES('green pasture'); + INSERT INTO streetname VALUES('greene'); + INSERT INTO streetname VALUES('greenloch'); + INSERT INTO streetname VALUES('greenock ridge'); + INSERT INTO streetname VALUES('greenware'); + INSERT INTO streetname VALUES('greenway village'); + INSERT INTO streetname VALUES('grenelefe village'); + INSERT INTO streetname VALUES('grey dogwood'); + INSERT INTO streetname VALUES('greyhound'); + INSERT INTO streetname VALUES('greylock ridge'); + INSERT INTO streetname VALUES('grosbeak'); + INSERT INTO streetname VALUES('grove'); + INSERT INTO streetname VALUES('groveton'); + INSERT INTO streetname VALUES('groveview'); + INSERT INTO streetname VALUES('hackberry creek'); + INSERT INTO streetname VALUES('hackberry grove'); + INSERT INTO streetname VALUES('hackett'); + INSERT INTO streetname VALUES('haddington'); + INSERT INTO streetname VALUES('hagler'); + INSERT INTO streetname VALUES('halcott'); + INSERT INTO streetname VALUES('half dome'); + INSERT INTO streetname VALUES('hallam'); + INSERT INTO streetname VALUES('hamilton russell'); + INSERT INTO streetname VALUES('hampton place'); + INSERT INTO streetname VALUES('hankins'); + INSERT INTO streetname VALUES('harburn forest'); + INSERT INTO streetname VALUES('harringham'); + INSERT INTO streetname VALUES('harrington woods'); + INSERT INTO streetname VALUES('harris corners'); + INSERT INTO streetname VALUES('harris cove'); + INSERT INTO streetname VALUES('harris glen'); + INSERT INTO streetname VALUES('harris hill'); + INSERT INTO streetname VALUES('harris oak'); + INSERT INTO streetname VALUES('harris pointe'); + INSERT INTO streetname VALUES('harris pond'); + INSERT INTO streetname VALUES('harris ridge'); + INSERT INTO streetname VALUES('harris technology'); + INSERT INTO streetname VALUES('harris woods'); + INSERT INTO streetname VALUES('hartfield downs'); + INSERT INTO streetname VALUES('hattie little'); + INSERT INTO streetname VALUES('hatwynn'); + INSERT INTO streetname VALUES('hawkins'); + INSERT INTO streetname VALUES('hawksnest'); + INSERT INTO streetname VALUES('haybridge'); + INSERT INTO streetname VALUES('hayden'); + INSERT INTO streetname VALUES('hazelcroft'); + INSERT INTO streetname VALUES('hazlitt'); + INSERT INTO streetname VALUES('hazy valley'); + INSERT INTO streetname VALUES('hearst'); + INSERT INTO streetname VALUES('heathcrest'); + INSERT INTO streetname VALUES('heathcroft'); + INSERT INTO streetname VALUES('hedge maple'); + INSERT INTO streetname VALUES('hedgecrest'); + INSERT INTO streetname VALUES('hedingham'); + INSERT INTO streetname VALUES('heman'); + INSERT INTO streetname VALUES('henderson'); + INSERT INTO streetname VALUES('henderson oaks'); + INSERT INTO streetname VALUES('henderson valley'); + INSERT INTO streetname VALUES('hendry'); + INSERT INTO streetname VALUES('heritage hills'); + INSERT INTO streetname VALUES('heritage woods'); + INSERT INTO streetname VALUES('heron cove'); + INSERT INTO streetname VALUES('heron glen'); + INSERT INTO streetname VALUES('hewitt'); + INSERT INTO streetname VALUES('hey rock'); + INSERT INTO streetname VALUES('heysham'); + INSERT INTO streetname VALUES('hickory cove'); + INSERT INTO streetname VALUES('hidden meadow'); + INSERT INTO streetname VALUES('high glen'); + INSERT INTO streetname VALUES('high laurel'); + INSERT INTO streetname VALUES('high valley'); + INSERT INTO streetname VALUES('highcroft'); + INSERT INTO streetname VALUES('highland'); + INSERT INTO streetname VALUES('highland commons'); + INSERT INTO streetname VALUES('highland creek'); + INSERT INTO streetname VALUES('highland glen'); + INSERT INTO streetname VALUES('highland park'); + INSERT INTO streetname VALUES('highlander'); + INSERT INTO streetname VALUES('highstream'); + INSERT INTO streetname VALUES('hilltop'); + INSERT INTO streetname VALUES('hobbitshire'); + INSERT INTO streetname VALUES('hoffman'); + INSERT INTO streetname VALUES('hogans way'); + INSERT INTO streetname VALUES('holbert'); + INSERT INTO streetname VALUES('hollow ridge'); + INSERT INTO streetname VALUES('holly vista'); + INSERT INTO streetname VALUES('hollywood'); + INSERT INTO streetname VALUES('hoover'); + INSERT INTO streetname VALUES('hopkins'); + INSERT INTO streetname VALUES('horace mann'); + INSERT INTO streetname VALUES('hornbeam'); + INSERT INTO streetname VALUES('horse pasture'); + INSERT INTO streetname VALUES('hosta'); + INSERT INTO streetname VALUES('howard'); + INSERT INTO streetname VALUES('hubbard'); + INSERT INTO streetname VALUES('hubbard falls'); + INSERT INTO streetname VALUES('hubbard woods'); + INSERT INTO streetname VALUES('hucks'); + INSERT INTO streetname VALUES('hunters creek'); + INSERT INTO streetname VALUES('hunters pointe'); + INSERT INTO streetname VALUES('hunters spring'); + INSERT INTO streetname VALUES('hunters whip'); + INSERT INTO streetname VALUES('huntmeadow'); + INSERT INTO streetname VALUES('hutchison mcdonald'); + INSERT INTO streetname VALUES('ingleton'); + INSERT INTO streetname VALUES('insdale'); + INSERT INTO streetname VALUES('interstate 85 service'); + INSERT INTO streetname VALUES('iola'); + INSERT INTO streetname VALUES('iredell'); + INSERT INTO streetname VALUES('iron brigade'); + INSERT INTO streetname VALUES('irwin valley'); + INSERT INTO streetname VALUES('irwin wood'); + INSERT INTO streetname VALUES('ivy brook'); + INSERT INTO streetname VALUES('ivy ridge'); + INSERT INTO streetname VALUES('jack russell'); + INSERT INTO streetname VALUES('jackson'); + INSERT INTO streetname VALUES('jacob martin'); + INSERT INTO streetname VALUES('jamison'); + INSERT INTO streetname VALUES('jane'); + INSERT INTO streetname VALUES('jaspar crest'); + INSERT INTO streetname VALUES('jessica'); + INSERT INTO streetname VALUES('jimmy oehler'); + INSERT INTO streetname VALUES('jocelyn'); + INSERT INTO streetname VALUES('johnston mill'); + INSERT INTO streetname VALUES('johnston oehler'); + INSERT INTO streetname VALUES('judal'); + INSERT INTO streetname VALUES('junipeous'); + INSERT INTO streetname VALUES('juniper'); + INSERT INTO streetname VALUES('juniperus'); + INSERT INTO streetname VALUES('kalispell'); + INSERT INTO streetname VALUES('karylsturn'); + INSERT INTO streetname VALUES('katelyn'); + INSERT INTO streetname VALUES('kayron'); + INSERT INTO streetname VALUES('keaton'); + INSERT INTO streetname VALUES('keble'); + INSERT INTO streetname VALUES('keels'); + INSERT INTO streetname VALUES('keith'); + INSERT INTO streetname VALUES('keithwood'); + INSERT INTO streetname VALUES('kelden walker'); + INSERT INTO streetname VALUES('kelsey emma'); + INSERT INTO streetname VALUES('kendrick'); + INSERT INTO streetname VALUES('kenmont'); + INSERT INTO streetname VALUES('kennerly cove'); + INSERT INTO streetname VALUES('kenninghall'); + INSERT INTO streetname VALUES('kent village'); + INSERT INTO streetname VALUES('kestral ridge'); + INSERT INTO streetname VALUES('kestrel'); + INSERT INTO streetname VALUES('kilmartin'); + INSERT INTO streetname VALUES('kilty'); + INSERT INTO streetname VALUES('kinglet'); + INSERT INTO streetname VALUES('kingsland'); + INSERT INTO streetname VALUES('kingsnorth'); + INSERT INTO streetname VALUES('kinsmore'); + INSERT INTO streetname VALUES('kirkgard'); + INSERT INTO streetname VALUES('kirkmont'); + INSERT INTO streetname VALUES('knightsgate'); + INSERT INTO streetname VALUES('kobuk'); + INSERT INTO streetname VALUES('kotlik'); + INSERT INTO streetname VALUES('kotz'); + INSERT INTO streetname VALUES('kyndall walk'); + INSERT INTO streetname VALUES('laborde'); + INSERT INTO streetname VALUES('lady bank'); + INSERT INTO streetname VALUES('lagrande'); + INSERT INTO streetname VALUES('lake'); + INSERT INTO streetname VALUES('lakeridge commons'); + INSERT INTO streetname VALUES('lakeview'); + INSERT INTO streetname VALUES('lakewood edge'); + INSERT INTO streetname VALUES('lakota'); + INSERT INTO streetname VALUES('lambrook'); + INSERT INTO streetname VALUES('lampkin'); + INSERT INTO streetname VALUES('lampkin park'); + INSERT INTO streetname VALUES('langham'); + INSERT INTO streetname VALUES('lanzerac manor'); + INSERT INTO streetname VALUES('larkmead forest'); + INSERT INTO streetname VALUES('lattice'); + INSERT INTO streetname VALUES('laurel crest'); + INSERT INTO streetname VALUES('laurel ridge'); + INSERT INTO streetname VALUES('laurel run'); + INSERT INTO streetname VALUES('laurenfield'); + INSERT INTO streetname VALUES('laveta'); + INSERT INTO streetname VALUES('lazy day'); + INSERT INTO streetname VALUES('leawood run'); + INSERT INTO streetname VALUES('lee marie'); + INSERT INTO streetname VALUES('legacy lake'); + INSERT INTO streetname VALUES('legacy park'); + INSERT INTO streetname VALUES('legato'); + INSERT INTO streetname VALUES('legolas'); + INSERT INTO streetname VALUES('leigh glen'); + INSERT INTO streetname VALUES('lence'); + INSERT INTO streetname VALUES('lenox hill'); + INSERT INTO streetname VALUES('leonine'); + INSERT INTO streetname VALUES('leslie'); + INSERT INTO streetname VALUES('lester hill'); + INSERT INTO streetname VALUES('levisey'); + INSERT INTO streetname VALUES('liberty bell'); + INSERT INTO streetname VALUES('linden berry'); + INSERT INTO streetname VALUES('lisbon'); + INSERT INTO streetname VALUES('little stoney'); + INSERT INTO streetname VALUES('livengood'); + INSERT INTO streetname VALUES('lochway'); + INSERT INTO streetname VALUES('lockman'); + INSERT INTO streetname VALUES('loganville'); + INSERT INTO streetname VALUES('lone tree'); + INSERT INTO streetname VALUES('long creek park'); + INSERT INTO streetname VALUES('long forest'); + INSERT INTO streetname VALUES('looking glass'); + INSERT INTO streetname VALUES('lookout point'); + INSERT INTO streetname VALUES('lowen'); + INSERT INTO streetname VALUES('lusby'); + INSERT INTO streetname VALUES('lyleton'); + INSERT INTO streetname VALUES('lynn lee'); + INSERT INTO streetname VALUES('lynnewood glen'); + INSERT INTO streetname VALUES('machrie'); + INSERT INTO streetname VALUES('mackinac'); + INSERT INTO streetname VALUES('maddox'); + INSERT INTO streetname VALUES('madison park'); + INSERT INTO streetname VALUES('mallard'); + INSERT INTO streetname VALUES('mallard cove'); + INSERT INTO streetname VALUES('mallard forest'); + INSERT INTO streetname VALUES('mallard grove'); + INSERT INTO streetname VALUES('mallard hill'); + INSERT INTO streetname VALUES('mallard park'); + INSERT INTO streetname VALUES('mallard ridge'); + INSERT INTO streetname VALUES('mallard view'); + INSERT INTO streetname VALUES('manbey'); + INSERT INTO streetname VALUES('manning'); + INSERT INTO streetname VALUES('mantario'); + INSERT INTO streetname VALUES('maple'); + INSERT INTO streetname VALUES('maple cove'); + INSERT INTO streetname VALUES('maple park'); + INSERT INTO streetname VALUES('marathon hill'); + INSERT INTO streetname VALUES('marbury'); + INSERT INTO streetname VALUES('marett'); + INSERT INTO streetname VALUES('marigold'); + INSERT INTO streetname VALUES('marionwood'); + INSERT INTO streetname VALUES('marshbank'); + INSERT INTO streetname VALUES('mason'); + INSERT INTO streetname VALUES('mayapple'); + INSERT INTO streetname VALUES('maylandia'); + INSERT INTO streetname VALUES('mayspring'); + INSERT INTO streetname VALUES('mcadam'); + INSERT INTO streetname VALUES('mcchesney'); + INSERT INTO streetname VALUES('mccurdy'); + INSERT INTO streetname VALUES('mcgrath'); + INSERT INTO streetname VALUES('mckendree'); + INSERT INTO streetname VALUES('mclaughlin'); + INSERT INTO streetname VALUES('mctaggart'); + INSERT INTO streetname VALUES('meadow green'); + INSERT INTO streetname VALUES('meadow knoll'); + INSERT INTO streetname VALUES('meadow post'); + INSERT INTO streetname VALUES('meadowmont'); + INSERT INTO streetname VALUES('meadowmont view'); + INSERT INTO streetname VALUES('meadowview hills'); + INSERT INTO streetname VALUES('melshire'); + INSERT INTO streetname VALUES('melstrand'); + INSERT INTO streetname VALUES('mentone'); + INSERT INTO streetname VALUES('meridale crossing'); + INSERT INTO streetname VALUES('merion hills'); + INSERT INTO streetname VALUES('merlot'); + INSERT INTO streetname VALUES('mersham'); + INSERT INTO streetname VALUES('metromont'); + INSERT INTO streetname VALUES('metromont industrial'); + INSERT INTO streetname VALUES('michaw'); + INSERT INTO streetname VALUES('milhaven'); + INSERT INTO streetname VALUES('milhof'); + INSERT INTO streetname VALUES('millstream ridge'); + INSERT INTO streetname VALUES('mineral ridge'); + INSERT INTO streetname VALUES('mint thistle'); + INSERT INTO streetname VALUES('mintleaf'); + INSERT INTO streetname VALUES('mintvale'); + INSERT INTO streetname VALUES('misty'); + INSERT INTO streetname VALUES('misty arbor'); + INSERT INTO streetname VALUES('misty creek'); + INSERT INTO streetname VALUES('misty oaks'); + INSERT INTO streetname VALUES('misty wood'); + INSERT INTO streetname VALUES('mitzi deborah'); + INSERT INTO streetname VALUES('mobile'); + INSERT INTO streetname VALUES('molly elizabeth'); + INSERT INTO streetname VALUES('monmouth'); + INSERT INTO streetname VALUES('montrose'); + INSERT INTO streetname VALUES('moonlight'); + INSERT INTO streetname VALUES('moose'); + INSERT INTO streetname VALUES('morning dew'); + INSERT INTO streetname VALUES('morningsong'); + INSERT INTO streetname VALUES('morningview'); + INSERT INTO streetname VALUES('morsey'); + INSERT INTO streetname VALUES('moss glen'); + INSERT INTO streetname VALUES('mossy bank'); + INSERT INTO streetname VALUES('motor sport'); + INSERT INTO streetname VALUES('mountain laurel'); + INSERT INTO streetname VALUES('mourning dove'); + INSERT INTO streetname VALUES('mozart'); + INSERT INTO streetname VALUES('munsing'); + INSERT INTO streetname VALUES('murray'); + INSERT INTO streetname VALUES('nathan'); + INSERT INTO streetname VALUES('netherhall'); + INSERT INTO streetname VALUES('netherton'); + INSERT INTO streetname VALUES('neuhoff'); + INSERT INTO streetname VALUES('nevin'); + INSERT INTO streetname VALUES('nevin brook'); + INSERT INTO streetname VALUES('nevin glen'); + INSERT INTO streetname VALUES('nevin place'); + INSERT INTO streetname VALUES('new england'); + INSERT INTO streetname VALUES('new house'); + INSERT INTO streetname VALUES('newbary'); + INSERT INTO streetname VALUES('newchurch'); + INSERT INTO streetname VALUES('newfane'); + INSERT INTO streetname VALUES('newgard'); + INSERT INTO streetname VALUES('nicholas'); + INSERT INTO streetname VALUES('nicole'); + INSERT INTO streetname VALUES('nobility'); + INSERT INTO streetname VALUES('norcroft'); + INSERT INTO streetname VALUES('northridge'); + INSERT INTO streetname VALUES('northside'); + INSERT INTO streetname VALUES('northwoods business'); + INSERT INTO streetname VALUES('norway'); + INSERT INTO streetname VALUES('nottinghill'); + INSERT INTO streetname VALUES('numenore'); + INSERT INTO streetname VALUES('nyewood'); + INSERT INTO streetname VALUES('oak'); + INSERT INTO streetname VALUES('oak cove'); + INSERT INTO streetname VALUES('oak pasture'); + INSERT INTO streetname VALUES('oakburn'); + INSERT INTO streetname VALUES('oakwinds'); + INSERT INTO streetname VALUES('oakwood'); + INSERT INTO streetname VALUES('obrien'); + INSERT INTO streetname VALUES('ocala'); + INSERT INTO streetname VALUES('old bridge'); + INSERT INTO streetname VALUES('old fox'); + INSERT INTO streetname VALUES('old potters'); + INSERT INTO streetname VALUES('old statesville'); + INSERT INTO streetname VALUES('old steine'); + INSERT INTO streetname VALUES('old stoney creek'); + INSERT INTO streetname VALUES('old sugar creek'); + INSERT INTO streetname VALUES('old timber'); + INSERT INTO streetname VALUES('old wagon'); + INSERT INTO streetname VALUES('old willow'); + INSERT INTO streetname VALUES('oldenway'); + INSERT INTO streetname VALUES('oneida'); + INSERT INTO streetname VALUES('ontario'); + INSERT INTO streetname VALUES('oriole'); + INSERT INTO streetname VALUES('orofino'); + INSERT INTO streetname VALUES('orr'); + INSERT INTO streetname VALUES('osage'); + INSERT INTO streetname VALUES('osceola'); + INSERT INTO streetname VALUES('osprey knoll'); + INSERT INTO streetname VALUES('oxford hill'); + INSERT INTO streetname VALUES('painted fern'); + INSERT INTO streetname VALUES('painted pony'); + INSERT INTO streetname VALUES('paisley'); + INSERT INTO streetname VALUES('pale moss'); + INSERT INTO streetname VALUES('palladium'); + INSERT INTO streetname VALUES('palmutum'); + INSERT INTO streetname VALUES('palustris'); + INSERT INTO streetname VALUES('panglemont'); + INSERT INTO streetname VALUES('panther'); + INSERT INTO streetname VALUES('panthersville'); + INSERT INTO streetname VALUES('paper whites'); + INSERT INTO streetname VALUES('park'); + INSERT INTO streetname VALUES('parker green'); + INSERT INTO streetname VALUES('parkhouse'); + INSERT INTO streetname VALUES('passour ridge'); + INSERT INTO streetname VALUES('pasture view'); + INSERT INTO streetname VALUES('patricia ann'); + INSERT INTO streetname VALUES('patton'); + INSERT INTO streetname VALUES('patton ridge'); + INSERT INTO streetname VALUES('pawpaw'); + INSERT INTO streetname VALUES('peach'); + INSERT INTO streetname VALUES('peakwood'); + INSERT INTO streetname VALUES('pebble creek'); + INSERT INTO streetname VALUES('pecan cove'); + INSERT INTO streetname VALUES('pedigree'); + INSERT INTO streetname VALUES('pelorus'); + INSERT INTO streetname VALUES('penmore'); + INSERT INTO streetname VALUES('pensfold'); + INSERT INTO streetname VALUES('pepperstone'); + INSERT INTO streetname VALUES('peregrine'); + INSERT INTO streetname VALUES('periwinkle'); + INSERT INTO streetname VALUES('perkins'); + INSERT INTO streetname VALUES('pete brown'); + INSERT INTO streetname VALUES('phillips'); + INSERT INTO streetname VALUES('pickway'); + INSERT INTO streetname VALUES('piercy woods'); + INSERT INTO streetname VALUES('pierpoint'); + INSERT INTO streetname VALUES('pine'); + INSERT INTO streetname VALUES('pine branch'); + INSERT INTO streetname VALUES('pine meadow'); + INSERT INTO streetname VALUES('pineleaf'); + INSERT INTO streetname VALUES('pinewood'); + INSERT INTO streetname VALUES('pintail'); + INSERT INTO streetname VALUES('pipestone'); + INSERT INTO streetname VALUES('placer maple'); + INSERT INTO streetname VALUES('plover'); + INSERT INTO streetname VALUES('plum'); + INSERT INTO streetname VALUES('po box'); + INSERT INTO streetname VALUES('pochard'); + INSERT INTO streetname VALUES('pointview'); + INSERT INTO streetname VALUES('polk and white'); + INSERT INTO streetname VALUES('pond valley'); + INSERT INTO streetname VALUES('pondridge'); + INSERT INTO streetname VALUES('pope farm'); + INSERT INTO streetname VALUES('poplar grove'); + INSERT INTO streetname VALUES('poplar springs'); + INSERT INTO streetname VALUES('portola'); + INSERT INTO streetname VALUES('potters glen'); + INSERT INTO streetname VALUES('powatan'); + INSERT INTO streetname VALUES('prairie valley'); + INSERT INTO streetname VALUES('prescott'); + INSERT INTO streetname VALUES('presmann'); + INSERT INTO streetname VALUES('prestigious'); + INSERT INTO streetname VALUES('princess'); + INSERT INTO streetname VALUES('prosperity'); + INSERT INTO streetname VALUES('prosperity church'); + INSERT INTO streetname VALUES('prosperity commons'); + INSERT INTO streetname VALUES('prosperity park'); + INSERT INTO streetname VALUES('prosperity point'); + INSERT INTO streetname VALUES('prosperity ridge'); + INSERT INTO streetname VALUES('prosperity view'); + INSERT INTO streetname VALUES('purple finch'); + INSERT INTO streetname VALUES('quail'); + INSERT INTO streetname VALUES('queensbury'); + INSERT INTO streetname VALUES('quinn'); + INSERT INTO streetname VALUES('racine'); + INSERT INTO streetname VALUES('radbourne'); + INSERT INTO streetname VALUES('raddington'); + INSERT INTO streetname VALUES('raku'); + INSERT INTO streetname VALUES('rancliffe'); + INSERT INTO streetname VALUES('ravencrest'); + INSERT INTO streetname VALUES('reames'); + INSERT INTO streetname VALUES('rebecca run'); + INSERT INTO streetname VALUES('red bluff'); + INSERT INTO streetname VALUES('red clay'); + INSERT INTO streetname VALUES('red clover'); + INSERT INTO streetname VALUES('red rose'); + INSERT INTO streetname VALUES('red shed'); + INSERT INTO streetname VALUES('red tail'); + INSERT INTO streetname VALUES('redbridge'); + INSERT INTO streetname VALUES('redstart'); + INSERT INTO streetname VALUES('redstone view'); + INSERT INTO streetname VALUES('reedmont'); + INSERT INTO streetname VALUES('reeves'); + INSERT INTO streetname VALUES('regal'); + INSERT INTO streetname VALUES('reinbeck'); + INSERT INTO streetname VALUES('retriever'); + INSERT INTO streetname VALUES('ribbonwalk'); + INSERT INTO streetname VALUES('richardson park'); + INSERT INTO streetname VALUES('richfield'); + INSERT INTO streetname VALUES('riddings'); + INSERT INTO streetname VALUES('ridge'); + INSERT INTO streetname VALUES('ridge cliff'); + INSERT INTO streetname VALUES('ridge path'); + INSERT INTO streetname VALUES('ridge peak'); + INSERT INTO streetname VALUES('ridgefield'); + INSERT INTO streetname VALUES('ridgeline'); + INSERT INTO streetname VALUES('ridgeview commons'); + INSERT INTO streetname VALUES('riley'); + INSERT INTO streetname VALUES('riley woods'); + INSERT INTO streetname VALUES('rillet'); + INSERT INTO streetname VALUES('rindle'); + INSERT INTO streetname VALUES('rivendell'); + INSERT INTO streetname VALUES('robin'); + INSERT INTO streetname VALUES('robins nest'); + INSERT INTO streetname VALUES('robur'); + INSERT INTO streetname VALUES('robyns glen'); + INSERT INTO streetname VALUES('rock stream'); + INSERT INTO streetname VALUES('rockwell'); + INSERT INTO streetname VALUES('rockwell church'); + INSERT INTO streetname VALUES('rocky brook'); + INSERT INTO streetname VALUES('rocky ford club'); + INSERT INTO streetname VALUES('rotary'); + INSERT INTO streetname VALUES('rouda'); + INSERT INTO streetname VALUES('royal bluff'); + INSERT INTO streetname VALUES('royal celadon'); + INSERT INTO streetname VALUES('rubin lura'); + INSERT INTO streetname VALUES('runswyck'); + INSERT INTO streetname VALUES('ruth ferrell'); + INSERT INTO streetname VALUES('ruth polk'); + INSERT INTO streetname VALUES('ryan jay'); + INSERT INTO streetname VALUES('sackett'); + INSERT INTO streetname VALUES('saddle pace'); + INSERT INTO streetname VALUES('saddle run'); + INSERT INTO streetname VALUES('saddle trail'); + INSERT INTO streetname VALUES('saguaro'); + INSERT INTO streetname VALUES('saint audrey'); + INSERT INTO streetname VALUES('saint bernard'); + INSERT INTO streetname VALUES('saint frances'); + INSERT INTO streetname VALUES('sam roper'); + INSERT INTO streetname VALUES('samara'); + INSERT INTO streetname VALUES('sanders creek'); + INSERT INTO streetname VALUES('saquache'); + INSERT INTO streetname VALUES('sarnia'); + INSERT INTO streetname VALUES('savannah springs'); + INSERT INTO streetname VALUES('sawgrass ridge'); + INSERT INTO streetname VALUES('saxonbury'); + INSERT INTO streetname VALUES('scotch moss'); + INSERT INTO streetname VALUES('seasons'); + INSERT INTO streetname VALUES('serenity'); + INSERT INTO streetname VALUES('seths'); + INSERT INTO streetname VALUES('shadow lawn'); + INSERT INTO streetname VALUES('shadow oaks'); + INSERT INTO streetname VALUES('shadow pine'); + INSERT INTO streetname VALUES('shadyside'); + INSERT INTO streetname VALUES('shallow oak'); + INSERT INTO streetname VALUES('shelley'); + INSERT INTO streetname VALUES('shining oak'); + INSERT INTO streetname VALUES('ship'); + INSERT INTO streetname VALUES('shore haven'); + INSERT INTO streetname VALUES('shuman'); + INSERT INTO streetname VALUES('sidney'); + INSERT INTO streetname VALUES('silver birch'); + INSERT INTO streetname VALUES('silvermere'); + INSERT INTO streetname VALUES('simonton'); + INSERT INTO streetname VALUES('singing hills'); + INSERT INTO streetname VALUES('singing oak'); + INSERT INTO streetname VALUES('sipes'); + INSERT INTO streetname VALUES('six point'); + INSERT INTO streetname VALUES('skycrest'); + INSERT INTO streetname VALUES('skyline'); + INSERT INTO streetname VALUES('small'); + INSERT INTO streetname VALUES('smith corners'); + INSERT INTO streetname VALUES('smithwood'); + INSERT INTO streetname VALUES('snow hill'); + INSERT INTO streetname VALUES('soapstone'); + INSERT INTO streetname VALUES('sobeck'); + INSERT INTO streetname VALUES('socata'); + INSERT INTO streetname VALUES('solace'); + INSERT INTO streetname VALUES('solway'); + INSERT INTO streetname VALUES('song sparrow'); + INSERT INTO streetname VALUES('sorrento'); + INSERT INTO streetname VALUES('spector'); + INSERT INTO streetname VALUES('spin drift'); + INSERT INTO streetname VALUES('spring crest'); + INSERT INTO streetname VALUES('spring lee'); + INSERT INTO streetname VALUES('spring park'); + INSERT INTO streetname VALUES('spring terrace'); + INSERT INTO streetname VALUES('spring trace'); + INSERT INTO streetname VALUES('springhaven'); + INSERT INTO streetname VALUES('squirrel trail'); + INSERT INTO streetname VALUES('stardust'); + INSERT INTO streetname VALUES('stargaze'); + INSERT INTO streetname VALUES('starita'); + INSERT INTO streetname VALUES('starmount'); + INSERT INTO streetname VALUES('statesville'); + INSERT INTO streetname VALUES('steed'); + INSERT INTO streetname VALUES('steelewood'); + INSERT INTO streetname VALUES('steepleglen'); + INSERT INTO streetname VALUES('stephens farm'); + INSERT INTO streetname VALUES('stewarton'); + INSERT INTO streetname VALUES('stone park'); + INSERT INTO streetname VALUES('stonebrook'); + INSERT INTO streetname VALUES('stonefield'); + INSERT INTO streetname VALUES('stoneglen'); + INSERT INTO streetname VALUES('stonemarsh'); + INSERT INTO streetname VALUES('stoney garden'); + INSERT INTO streetname VALUES('stoney run'); + INSERT INTO streetname VALUES('stoney valley'); + INSERT INTO streetname VALUES('stoneykirk'); + INSERT INTO streetname VALUES('stream bank'); + INSERT INTO streetname VALUES('stream ridge'); + INSERT INTO streetname VALUES('suburban'); + INSERT INTO streetname VALUES('suffield'); + INSERT INTO streetname VALUES('sugar creek'); + INSERT INTO streetname VALUES('sugarberry'); + INSERT INTO streetname VALUES('sugarstone'); + INSERT INTO streetname VALUES('summer creek'); + INSERT INTO streetname VALUES('summer valley'); + INSERT INTO streetname VALUES('summercrest'); + INSERT INTO streetname VALUES('summercroft'); + INSERT INTO streetname VALUES('summerford'); + INSERT INTO streetname VALUES('summergold'); + INSERT INTO streetname VALUES('sunbeam'); + INSERT INTO streetname VALUES('sunbridge'); + INSERT INTO streetname VALUES('sunpath'); + INSERT INTO streetname VALUES('sunset'); + INSERT INTO streetname VALUES('sunset ridge'); + INSERT INTO streetname VALUES('sunstone'); + INSERT INTO streetname VALUES('suntrace'); + INSERT INTO streetname VALUES('sunwalk'); + INSERT INTO streetname VALUES('sutters hill'); + INSERT INTO streetname VALUES('suttonview'); + INSERT INTO streetname VALUES('swallow tail'); + INSERT INTO streetname VALUES('swanston'); + INSERT INTO streetname VALUES('sweet grove'); + INSERT INTO streetname VALUES('sweet rose'); + INSERT INTO streetname VALUES('sweetbriar ridge'); + INSERT INTO streetname VALUES('sweetfield'); + INSERT INTO streetname VALUES('sydney overlook'); + INSERT INTO streetname VALUES('sylvan'); + INSERT INTO streetname VALUES('symphony woods'); + INSERT INTO streetname VALUES('tallia'); + INSERT INTO streetname VALUES('tallu'); + INSERT INTO streetname VALUES('talwyn'); + INSERT INTO streetname VALUES('tanager'); + INSERT INTO streetname VALUES('tanager park'); + INSERT INTO streetname VALUES('tangley'); + INSERT INTO streetname VALUES('taranasay'); + INSERT INTO streetname VALUES('tarby'); + INSERT INTO streetname VALUES('tarland'); + INSERT INTO streetname VALUES('tarpway'); + INSERT INTO streetname VALUES('tauten'); + INSERT INTO streetname VALUES('taymouth'); + INSERT INTO streetname VALUES('ten trees'); + INSERT INTO streetname VALUES('terrace view'); + INSERT INTO streetname VALUES('terrier'); + INSERT INTO streetname VALUES('tesh'); + INSERT INTO streetname VALUES('teton'); + INSERT INTO streetname VALUES('tewkesbury'); + INSERT INTO streetname VALUES('thelema'); + INSERT INTO streetname VALUES('thistle bloom'); + INSERT INTO streetname VALUES('thistledown'); + INSERT INTO streetname VALUES('thomas ridge'); + INSERT INTO streetname VALUES('thornbrook'); + INSERT INTO streetname VALUES('tifton grass'); + INSERT INTO streetname VALUES('tigerton'); + INSERT INTO streetname VALUES('tomsie efird'); + INSERT INTO streetname VALUES('tor'); + INSERT INTO streetname VALUES('torphin'); + INSERT INTO streetname VALUES('torrence'); + INSERT INTO streetname VALUES('towering pine'); + INSERT INTO streetname VALUES('towhee'); + INSERT INTO streetname VALUES('toxaway'); + INSERT INTO streetname VALUES('tracy glenn'); + INSERT INTO streetname VALUES('tradition view'); + INSERT INTO streetname VALUES('trailer'); + INSERT INTO streetname VALUES('transport'); + INSERT INTO streetname VALUES('trehurst'); + INSERT INTO streetname VALUES('trexler'); + INSERT INTO streetname VALUES('trillium fields'); + INSERT INTO streetname VALUES('trimbach'); + INSERT INTO streetname VALUES('tucker'); + INSERT INTO streetname VALUES('tullamore'); + INSERT INTO streetname VALUES('tullock creek'); + INSERT INTO streetname VALUES('tunston'); + INSERT INTO streetname VALUES('tupelo'); + INSERT INTO streetname VALUES('turnabout'); + INSERT INTO streetname VALUES('turney'); + INSERT INTO streetname VALUES('turtle cross'); + INSERT INTO streetname VALUES('turtleback'); + INSERT INTO streetname VALUES('twelvestone'); + INSERT INTO streetname VALUES('twin'); + INSERT INTO streetname VALUES('twin brook'); + INSERT INTO streetname VALUES('twin lakes'); + INSERT INTO streetname VALUES('twisted pine'); + INSERT INTO streetname VALUES('tyler finley'); + INSERT INTO streetname VALUES('university station'); + INSERT INTO streetname VALUES('uphill'); + INSERT INTO streetname VALUES('valeview'); + INSERT INTO streetname VALUES('valhalla'); + INSERT INTO streetname VALUES('van'); + INSERT INTO streetname VALUES('vance davis'); + INSERT INTO streetname VALUES('vanhoy'); + INSERT INTO streetname VALUES('veckman'); + INSERT INTO streetname VALUES('victoria'); + INSERT INTO streetname VALUES('victory'); + INSERT INTO streetname VALUES('village glen'); + INSERT INTO streetname VALUES('vireo'); + INSERT INTO streetname VALUES('viscount'); + INSERT INTO streetname VALUES('voeltz'); + INSERT INTO streetname VALUES('wade e morgan'); + INSERT INTO streetname VALUES('wake'); + INSERT INTO streetname VALUES('wales'); + INSERT INTO streetname VALUES('wallace ridge'); + INSERT INTO streetname VALUES('waltham'); + INSERT INTO streetname VALUES('wanamassa'); + INSERT INTO streetname VALUES('warbler wood'); + INSERT INTO streetname VALUES('washington'); + INSERT INTO streetname VALUES('water'); + INSERT INTO streetname VALUES('waterelm'); + INSERT INTO streetname VALUES('waterford hills'); + INSERT INTO streetname VALUES('waterford valley'); + INSERT INTO streetname VALUES('waterloo'); + INSERT INTO streetname VALUES('waterton leas'); + INSERT INTO streetname VALUES('waverly lynn'); + INSERT INTO streetname VALUES('waverlyglen'); + INSERT INTO streetname VALUES('wayside'); + INSERT INTO streetname VALUES('westbury lake'); + INSERT INTO streetname VALUES('westray'); + INSERT INTO streetname VALUES('whistlers chase'); + INSERT INTO streetname VALUES('whistley green'); + INSERT INTO streetname VALUES('whistling oak'); + INSERT INTO streetname VALUES('whitcomb'); + INSERT INTO streetname VALUES('white aspen'); + INSERT INTO streetname VALUES('white cascade'); + INSERT INTO streetname VALUES('white mist'); + INSERT INTO streetname VALUES('white rock'); + INSERT INTO streetname VALUES('white stag'); + INSERT INTO streetname VALUES('whitegate'); + INSERT INTO streetname VALUES('whitehill'); + INSERT INTO streetname VALUES('whitetail'); + INSERT INTO streetname VALUES('whitewood'); + INSERT INTO streetname VALUES('wilburn park'); + INSERT INTO streetname VALUES('wild garden'); + INSERT INTO streetname VALUES('wild rose'); + INSERT INTO streetname VALUES('wilkins terrace'); + INSERT INTO streetname VALUES('william ficklen'); + INSERT INTO streetname VALUES('wiltshire ridge'); + INSERT INTO streetname VALUES('windchase'); + INSERT INTO streetname VALUES('winding jordan'); + INSERT INTO streetname VALUES('windy meadow'); + INSERT INTO streetname VALUES('winghaven'); + INSERT INTO streetname VALUES('wingmont'); + INSERT INTO streetname VALUES('winslow'); + INSERT INTO streetname VALUES('winter pine'); + INSERT INTO streetname VALUES('winter view'); + INSERT INTO streetname VALUES('wolf creek'); + INSERT INTO streetname VALUES('wondering oak'); + INSERT INTO streetname VALUES('woodard'); + INSERT INTO streetname VALUES('woodfire'); + INSERT INTO streetname VALUES('woodland commons'); + INSERT INTO streetname VALUES('woodland hills'); + INSERT INTO streetname VALUES('woodnotch'); + INSERT INTO streetname VALUES('woodstone'); + INSERT INTO streetname VALUES('worsley'); + INSERT INTO streetname VALUES('wren creek'); + INSERT INTO streetname VALUES('wrens nest'); + INSERT INTO streetname VALUES('wrexham'); + INSERT INTO streetname VALUES('wt harris'); + INSERT INTO streetname VALUES('wylie meadow'); + INSERT INTO streetname VALUES('wynborough'); + INSERT INTO streetname VALUES('wynbrook'); + INSERT INTO streetname VALUES('wyndham hill'); + INSERT INTO streetname VALUES('yandem'); + INSERT INTO streetname VALUES('yellow rose'); + INSERT INTO streetname VALUES('yellow spaniel'); + INSERT INTO streetname VALUES('yorkford'); + INSERT INTO streetname VALUES('ziegler'); + INSERT INTO streetname VALUES('zion renaissance'); + + SELECT count(*) FROM streetname; + } +} {1228} + +do_test fuzzer1-2.1 { + execsql { + SELECT n, distance FROM f2, streetname + WHERE f2.word MATCH 'wersley' + AND f2.distance<=150 + AND f2.word=streetname.n + } +} {worsley 37} +do_test fuzzer1-2.2 { + execsql { + SELECT n, distance FROM f2, streetname + WHERE f2.word MATCH 'testledown' + AND f2.distance<=150 + AND f2.word=streetname.n + } +} {thistledown 103} +do_test fuzzer1-2.3 { + execsql { + SELECT DISTINCT streetname.n FROM f2, streetname + WHERE f2.word MATCH 'tayle' + AND f2.distance<=200 + AND streetname.n>=f2.word AND streetname.n<=(f2.word || x'F7BFBFBF') + } +} {{tyler finley} trailer taymouth steelewood tallia tallu talwyn thelema} +do_test fuzzer1-2.4 { + execsql { + SELECT DISTINCT streetname.n + FROM f2 JOIN streetname + ON (streetname.n>=f2.word AND streetname.n<=(f2.word || 'zzzzzz')) + WHERE f2.word MATCH 'duck' + AND f2.distance<150 + AND f2.ruleset=3 + ORDER BY 1 + } +} {mallard {mallard cove} {mallard forest} {mallard grove} {mallard hill} {mallard park} {mallard ridge} {mallard view}} +do_test fuzzer1-2.5 { + execsql { + SELECT DISTINCT streetname.n + FROM f2 JOIN streetname + ON (streetname.n>=f2.word AND streetname.n<=(f2.word || 'zzzzzz')) + WHERE f2.word MATCH 'duck' + AND f2.distance<150 + AND f2.ruleset=2 + ORDER BY 1 + } +} {} + +forcedelete test.db2 +do_execsql_test fuzzer1-4.1 { + ATTACH 'test.db2' AS aux; + CREATE TABLE aux.f3_rules(ruleset, cfrom, cto, cost); + INSERT INTO f3_rules(ruleset, cfrom, cto, cost) VALUES(0, 'x','y', 10); + INSERT INTO f3_rules(ruleset, cfrom, cto, cost) VALUES(1, 'a','b', 10); + CREATE VIRTUAL TABLE aux.f3 USING fuzzer(f3_rules); + SELECT word FROM f3 WHERE word MATCH 'ax' +} {ax ay} + +#------------------------------------------------------------------------- +# +# 1.5.1 - Check things work with a fuzzer data table name that requires +# quoting. Also that NULL entries in the "from" column of the +# data table are treated as zero length strings (''). +# +# 1.5.2 - Check that no-op rules (i.e. C->C) are ignored. Test NULL in +# the "to" column of a fuzzer data table. +# +# 1.5.3 - Test out-of-range values for the cost field of the data table. +# +# 1.5.4 - Test out-of-range values for the string fields of the data table. +# +# 1.5.5 - Test out-of-range values for the ruleset field of the data table. +# +do_execsql_test 5.1 { + CREATE TABLE "fuzzer [x] rules table"(a, b, c, d); + INSERT INTO "fuzzer [x] rules table" VALUES(0, NULL, 'abc', 10); + CREATE VIRTUAL TABLE x USING fuzzer('fuzzer [x] rules table'); + SELECT word, distance FROM x WHERE word MATCH '123' LIMIT 4; +} {123 0 abc123 10 1abc23 10 12abc3 10} + +do_execsql_test 5.2 { + DELETE FROM "fuzzer [x] rules table"; + INSERT INTO "fuzzer [x] rules table" VALUES(0, 'x', NULL, 20); + INSERT INTO "fuzzer [x] rules table" VALUES(0, NULL, NULL, 10); + INSERT INTO "fuzzer [x] rules table" VALUES(0, 'x', 'x', 10); + + DROP TABLE x; + CREATE VIRTUAL TABLE x USING fuzzer('fuzzer [x] rules table'); + + SELECT word, distance FROM x WHERE word MATCH 'xx'; +} {xx 0 x 20 {} 40} + +do_execsql_test 5.3.1 { + DROP TABLE IF EXISTS x; + INSERT INTO "fuzzer [x] rules table" VALUES(0, 'c', 'd', 1001); +} +do_catchsql_test 5.3.2 { + CREATE VIRTUAL TABLE x USING fuzzer('fuzzer [x] rules table'); +} {1 {fuzzer: cost must be between 1 and 1000}} + +do_execsql_test 5.3.3 { + DROP TABLE IF EXISTS x; + DELETE FROM "fuzzer [x] rules table"; + INSERT INTO "fuzzer [x] rules table" VALUES(0, 'd', 'c', 0); +} +do_catchsql_test 5.3.4 { + CREATE VIRTUAL TABLE x USING fuzzer('fuzzer [x] rules table'); +} {1 {fuzzer: cost must be between 1 and 1000}} + +do_execsql_test 5.3.5 { + DROP TABLE IF EXISTS x; + DELETE FROM "fuzzer [x] rules table"; + INSERT INTO "fuzzer [x] rules table" VALUES(0, 'd', 'c', -20); +} +do_catchsql_test 5.3.6 { + CREATE VIRTUAL TABLE x USING fuzzer('fuzzer [x] rules table'); +} {1 {fuzzer: cost must be between 1 and 1000}} + +do_execsql_test 5.4.1 { + DROP TABLE IF EXISTS x; + DELETE FROM "fuzzer [x] rules table"; + INSERT INTO "fuzzer [x] rules table" VALUES( + 0, 'x', '12345678901234567890123456789012345678901234567890', 2 + ); + CREATE VIRTUAL TABLE x USING fuzzer('fuzzer [x] rules table'); + SELECT word FROM x WHERE word MATCH 'x'; +} {x 12345678901234567890123456789012345678901234567890} + +do_execsql_test 5.4.2 { + DROP TABLE IF EXISTS x; + DELETE FROM "fuzzer [x] rules table"; + INSERT INTO "fuzzer [x] rules table" VALUES( + 0, 'x', '123456789012345678901234567890123456789012345678901', 2 + ); +} +do_catchsql_test 5.4.3 { + CREATE VIRTUAL TABLE x USING fuzzer('fuzzer [x] rules table'); +} {1 {fuzzer: maximum string length is 50}} + +do_execsql_test 5.4.4 { + DROP TABLE IF EXISTS x; + DELETE FROM "fuzzer [x] rules table"; + INSERT INTO "fuzzer [x] rules table" VALUES( + 0, '123456789012345678901234567890123456789012345678901', 'x', 2 + ); +} +do_catchsql_test 5.4.5 { + CREATE VIRTUAL TABLE x USING fuzzer('fuzzer [x] rules table'); +} {1 {fuzzer: maximum string length is 50}} + +do_execsql_test 5.5.1 { + DROP TABLE IF EXISTS x; + DELETE FROM "fuzzer [x] rules table"; + INSERT INTO "fuzzer [x] rules table" VALUES(-1, 'x', 'y', 2); +} +do_catchsql_test 5.5.2 { + CREATE VIRTUAL TABLE x USING fuzzer('fuzzer [x] rules table'); +} {1 {fuzzer: ruleset must be between 0 and 2147483647}} + +do_execsql_test 5.5.3 { + DROP TABLE IF EXISTS x; + DELETE FROM "fuzzer [x] rules table"; + INSERT INTO "fuzzer [x] rules table" VALUES((1<<32)+100, 'x', 'y', 2); +} +do_catchsql_test 5.5.4 { + CREATE VIRTUAL TABLE x USING fuzzer('fuzzer [x] rules table'); +} {1 {fuzzer: ruleset must be between 0 and 2147483647}} + +#------------------------------------------------------------------------- +# Test using different types of quotes with CREATE VIRTUAL TABLE +# arguments. +# +do_execsql_test 7.1 { + CREATE TABLE [x2 "rules] (a, b, c, d); + INSERT INTO [x2 "rules] VALUES(0, 'a', 'b', 5); +} +foreach {tn sql} { + 1 { CREATE VIRTUAL TABLE x2 USING fuzzer( [x2 "rules] ) } + 2 { CREATE VIRTUAL TABLE x2 USING fuzzer( "x2 ""rules" ) } + 3 { CREATE VIRTUAL TABLE x2 USING fuzzer( 'x2 "rules' ) } + 4 { CREATE VIRTUAL TABLE x2 USING fuzzer( `x2 "rules` ) } +} { + do_execsql_test 7.2.$tn.1 { DROP TABLE IF EXISTS x2 } + do_execsql_test 7.2.$tn.2 $sql + do_execsql_test 7.2.$tn.3 { + SELECT word FROM x2 WHERE word MATCH 'aaa' + } {aaa baa aba aab bab abb bba bbb} +} + +#------------------------------------------------------------------------- +# Test using a fuzzer table in different contexts. +# +do_execsql_test 8.1 { + CREATE TABLE x3_rules(rule_set, cFrom, cTo, cost); + INSERT INTO x3_rules VALUES(2, 'a', 'x', 10); + INSERT INTO x3_rules VALUES(2, 'a', 'y', 9); + INSERT INTO x3_rules VALUES(2, 'a', 'z', 8); + CREATE VIRTUAL TABLE x3 USING fuzzer(x3_rules); +} + +do_execsql_test 8.2.1 { + SELECT cFrom, cTo, word + FROM x3_rules CROSS JOIN x3 + WHERE word MATCH 'a' AND cost=distance AND ruleset=2 + ORDER BY +cTo; +} {a x x a y y a z z} + +do_execsql_test 8.2.2 { + SELECT cFrom, cTo, word + FROM x3 CROSS JOIN x3_rules + WHERE word MATCH 'a' AND cost=distance AND ruleset=2 + ORDER BY +cTo DESC +} {a z z a y y a x x} + +do_execsql_test 8.2.3 { + SELECT cFrom, cTo, word + FROM x3_rules, x3 + WHERE word MATCH 'a' AND cost=distance AND ruleset=2 + ORDER BY +cTo DESC; +} {a z z a y y a x x} + +do_execsql_test 8.2.4 { + SELECT cFrom, cTo, word + FROM x3, x3_rules + WHERE word MATCH 'a' AND cost=distance AND ruleset=2 + ORDER BY +cTo DESC; +} {a z z a y y a x x} + +do_execsql_test 8.2.5 { + CREATE INDEX i1 ON x3_rules(cost); + SELECT cFrom, cTo, word + FROM x3_rules, x3 + WHERE word MATCH 'a' AND cost=distance AND ruleset=2 + ORDER BY +cTo DESC; +} {a z z a y y a x x} + +do_execsql_test 8.2.5 { + SELECT word FROM x3_rules, x3 WHERE word MATCH x3_rules.cFrom AND ruleset=2 +} {a z y x a z y x a z y x} + +do_execsql_test 8.2.6 { + SELECT word FROM x3_rules, x3 + WHERE word MATCH x3_rules.cFrom + AND ruleset=2 + AND x3_rules.cost=8; +} {a z y x} + +do_execsql_test 8.2.7 { + CREATE TABLE t1(a, b); + CREATE INDEX i2 ON t1(b); + SELECT word, distance FROM x3, t1 + WHERE x3.word MATCH t1.a AND ruleset=2 AND distance=t1.b; +} {} + +do_execsql_test 8.2.8 { + INSERT INTO x3_rules VALUES(1, 'a', 't', 5); + INSERT INTO x3_rules VALUES(1, 'a', 'u', 4); + INSERT INTO x3_rules VALUES(1, 'a', 'v', 3); + DROP TABLE x3; + CREATE VIRTUAL TABLE x3 USING fuzzer(x3_rules); + SELECT * FROM x3_rules; +} { + 2 a x 10 + 2 a y 9 + 2 a z 8 + 1 a t 5 + 1 a u 4 + 1 a v 3 +} + +do_catchsql_test 8.2.9 { + SELECT word FROM x3 WHERE ruleset=2 AND word MATCH 'a' AND WORD MATCH 'b'; +} {1 {unable to use function MATCH in the requested context}} + +do_execsql_test 8.2.10 { + SELECT word FROM x3 WHERE ruleset=1 AND word MATCH 'a' +} {a v u t} + +# The term "ruleset<=1" is not handled by the fuzzer module. Instead, it +# is handled by SQLite, which assumes that all rows have a NULL value in +# the ruleset column. Since NULL<=1 is never true, this query returns +# no rows. +do_execsql_test 8.2.11 { + SELECT word FROM x3 WHERE ruleset<=1 AND word MATCH 'a' +} {} + +do_execsql_test 8.2.12 { + SELECT word FROM x3 WHERE ruleset=1 AND word MATCH 'a' ORDER BY distance ASC; +} {a v u t} + +do_execsql_test 8.2.13 { + SELECT word FROM x3 WHERE ruleset=1 AND word MATCH 'a' ORDER BY distance DESC; +} {t u v a} + +do_execsql_test 8.2.13 { + SELECT word FROM x3 WHERE ruleset=1 AND word MATCH 'a' ORDER BY word ASC; +} {a t u v} + +do_execsql_test 8.2.14 { + SELECT word FROM x3 WHERE ruleset=1 AND word MATCH 'a' ORDER BY word DESC; +} {v u t a} + +#------------------------------------------------------------------------- +# +do_execsql_test 9.1 { + CREATE TABLE x4_rules(a, b, c, d); + INSERT INTO x4_rules VALUES(0, 'a', 'b', 10); + INSERT INTO x4_rules VALUES(0, 'a', 'c', 11); + INSERT INTO x4_rules VALUES(0, 'bx', 'zz', 20); + INSERT INTO x4_rules VALUES(0, 'cx', 'yy', 15); + INSERT INTO x4_rules VALUES(0, 'zz', '!!', 50); + CREATE VIRTUAL TABLE x4 USING fuzzer(x4_rules); +} + +do_execsql_test 9.2 { + SELECT word, distance FROM x4 WHERE word MATCH 'ax'; +} {ax 0 bx 10 cx 11 yy 26 zz 30 !! 80} + + +do_execsql_test 10.1 { + CREATE TABLE x5_rules(a, b, c, d); + CREATE VIRTUAL TABLE x5 USING fuzzer(x5_rules); +} + +do_execsql_test 10.2 { + SELECT word, distance FROM x5 WHERE word MATCH + 'aaaaaaaaaXaaaaaaaaaXaaaaaaaaaXaaaaaaaaaXaaaaaaaaa' || + 'aaaaaaaaaXaaaaaaaaaXaaaaaaaaaXaaaaaaaaaXaaaaaaaaa' || + 'aaaaaaaaaXaaaaaaaaaXaaaaaaaaaXaaaaaaaaaXaaaaaaaaa' +} {} + +do_execsql_test 10.3 { + INSERT INTO x5_rules VALUES(0, 'a', '0.1.2.3.4.5.6.7.8.9.a', 1); + DROP TABLE x5; + CREATE VIRTUAL TABLE x5 USING fuzzer(x5_rules); + SELECT length(word) FROM x5 WHERE word MATCH 'a' LIMIT 50; +} {1 21 41 61 81} + +finish_test diff --git a/test/fuzzer2.test b/test/fuzzer2.test new file mode 100644 index 0000000..44ee9e3 --- /dev/null +++ b/test/fuzzer2.test @@ -0,0 +1,72 @@ +# 2016 February 4 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# The focus of the tests is the word-fuzzer virtual table. The tests +# in this file are slower than those in fuzzer1.test. So this file does +# not run as part of veryquick.test etc. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !vtab { + finish_test + return +} + +set ::testprefix fuzzer2 +load_static_extension db fuzzer + +#------------------------------------------------------------------------- +# This test uses a fuzzer table with many rules. There is one rule to +# map each possible two character string, where characters are lower-case +# letters used in the English language, to all other possible two character +# strings. In total, (26^4)-(26^2) mappings (the subtracted term represents +# the no-op mappings discarded automatically by the fuzzer). +# +# +do_execsql_test 1.1.1 { + DROP TABLE IF EXISTS x1; + DROP TABLE IF EXISTS x1_rules; + CREATE TABLE x1_rules(ruleset, cFrom, cTo, cost); +} +puts "This test is slow - perhaps around 7 seconds on an average pc" +do_test 1.1.2 { + set LETTERS {a b c d e f g h i j k l m n o p q r s t u v w x y z} + set cost 1 + db transaction { + foreach c1 $LETTERS { + foreach c2 $LETTERS { + foreach c3 $LETTERS { + foreach c4 $LETTERS { + db eval {INSERT INTO x1_rules VALUES(0, $c1||$c2, $c3||$c4, $cost)} + set cost [expr ($cost%1000) + 1] + } + } + } + } + db eval {UPDATE x1_rules SET cost = 20 WHERE cost<20 AND cFrom!='xx'} + } +} {} + +do_execsql_test 1.2 { + SELECT count(*) FROM x1_rules WHERE cTo!=cFrom; +} [expr 26*26*26*26 - 26*26] + +do_execsql_test 1.2.1 { + CREATE VIRTUAL TABLE x1 USING fuzzer(x1_rules); + SELECT word FROM x1 WHERE word MATCH 'xx' LIMIT 10; +} {xx hw hx hy hz ia ib ic id ie} +do_execsql_test 1.2.2 { + SELECT cTo FROM x1_rules WHERE cFrom='xx' + ORDER BY cost asc, rowid asc LIMIT 9; +} {hw hx hy hz ia ib ic id ie} + +finish_test diff --git a/test/fuzzerfault.test b/test/fuzzerfault.test new file mode 100644 index 0000000..e281cb5 --- /dev/null +++ b/test/fuzzerfault.test @@ -0,0 +1,111 @@ +# 2012 February 21 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for TCL interface to the +# SQLite library. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +ifcapable !vtab { finish_test ; return } +set ::testprefix fuzzerfault + +load_static_extension db fuzzer + +do_test 1-pre1 { + execsql { + CREATE TABLE x1_rules(ruleset, cFrom, cTo, cost); + INSERT INTO x1_rules VALUES(0, 'a', 'b', 1); + INSERT INTO x1_rules VALUES(0, 'a', 'c', 2); + INSERT INTO x1_rules VALUES(0, 'a', 'd', 3); + } + faultsim_save_and_close +} {} +do_faultsim_test 1 -prep { + faultsim_restore_and_reopen + load_static_extension db fuzzer +} -body { + execsql { + CREATE VIRTUAL TABLE x1 USING fuzzer(x1_rules); + SELECT word FROM x1 WHERE word MATCH 'xax'; + } +} -test { + faultsim_test_result {0 {xax xbx xcx xdx}} \ + {1 {vtable constructor failed: x1}} +} + +do_test 2-pre1 { + faultsim_delete_and_reopen + load_static_extension db fuzzer + execsql { + CREATE TABLE x2_rules(ruleset, cFrom, cTo, cost); + INSERT INTO x2_rules VALUES(0, 'a', 'x', 1); + INSERT INTO x2_rules VALUES(0, 'b', 'x', 2); + INSERT INTO x2_rules VALUES(0, 'c', 'x', 3); + CREATE VIRTUAL TABLE x2 USING fuzzer(x2_rules); + } + faultsim_save_and_close +} {} + +do_faultsim_test 2 -prep { + faultsim_restore_and_reopen + load_static_extension db fuzzer +} -body { + execsql { + SELECT count(*) FROM x2 WHERE word MATCH 'abc'; + } +} -test { + faultsim_test_result {0 8} {1 {vtable constructor failed: x2}} +} + +do_test 3-pre1 { + faultsim_delete_and_reopen + execsql { + CREATE TABLE x1_rules(ruleset, cFrom, cTo, cost); + INSERT INTO x1_rules VALUES(0, 'a', + '123456789012345678901234567890a1234567890123456789', 10 + ); + } + faultsim_save_and_close +} {} + +do_faultsim_test 3 -prep { + faultsim_restore_and_reopen + load_static_extension db fuzzer +} -body { + execsql { + CREATE VIRTUAL TABLE x1 USING fuzzer(x1_rules); + SELECT count(*) FROM (SELECT * FROM x1 WHERE word MATCH 'a' LIMIT 2); + } +} -test { + faultsim_test_result {0 2} {1 {vtable constructor failed: x1}} +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 4.0 { + CREATE TABLE t1_a(a INTEFDR PRIMARY KEY, b TEXT); + CREATE TABLE t3_a(k FnTEGER PRIMARY KEY, v TEXT); + CREATE TABLE t3_b(k INTEÀ5R PRIMARY KEY, v TEXT); + CREATE VIEW t3 AS SELECT * FROM t3_a UNION ALL SELECT * FROM t3_b; +} +faultsim_save_and_close + +do_faultsim_test 4 -faults oom-t* -prep { + faultsim_restore_and_reopen +} -body { + execsql { + SELECT 1 FROM t1_a LEFT JOIN t3 ON ((1+1) AND k=1) + } +} -test { + faultsim_test_result {0 {}} +} + +finish_test diff --git a/test/fuzzinvariants.c b/test/fuzzinvariants.c new file mode 100644 index 0000000..5d473f1 --- /dev/null +++ b/test/fuzzinvariants.c @@ -0,0 +1,510 @@ +/* +** 2022-06-14 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +************************************************************************* +** +** This library is used by fuzzcheck to test query invariants. +** +** An sqlite3_stmt is passed in that has just returned SQLITE_ROW. This +** routine does: +** +** * Record the output of the current row +** * Construct an alternative query that should return the same row +** * Run the alternative query and verify that it does in fact return +** the same row +** +*/ +#include "sqlite3.h" +#include +#include +#include +#include + +/* Forward references */ +static char *fuzz_invariant_sql(sqlite3_stmt*, int); +static int sameValue(sqlite3_stmt*,int,sqlite3_stmt*,int,sqlite3_stmt*); +static void reportInvariantFailed(sqlite3_stmt*,sqlite3_stmt*,int); + +/* +** Do an invariant check on pStmt. iCnt determines which invariant check to +** perform. The first check is iCnt==0. +** +** *pbCorrupt is a flag that, if true, indicates that the database file +** is known to be corrupt. A value of non-zero means "yes, the database +** is corrupt". A zero value means "we do not know whether or not the +** database is corrupt". The value might be set prior to entry, or this +** routine might set the value. +** +** Return values: +** +** SQLITE_OK This check was successful. +** +** SQLITE_DONE iCnt is out of range. The caller typically sets +** up a loop on iCnt starting with zero, and increments +** iCnt until this code is returned. +** +** SQLITE_CORRUPT The invariant failed, but the underlying database +** file is indicating that it is corrupt, which might +** be the cause of the malfunction. The *pCorrupt +** value will also be set. +** +** SQLITE_INTERNAL The invariant failed, and the database file is not +** corrupt. (This never happens because this function +** will call abort() following an invariant failure.) +** +** (other) Some other kind of error occurred. +*/ +int fuzz_invariant( + sqlite3 *db, /* The database connection */ + sqlite3_stmt *pStmt, /* Test statement stopped on an SQLITE_ROW */ + int iCnt, /* Invariant sequence number, starting at 0 */ + int iRow, /* Current row number */ + int nRow, /* Number of output rows from pStmt */ + int *pbCorrupt, /* IN/OUT: Flag indicating a corrupt database file */ + int eVerbosity /* How much debugging output */ +){ + char *zTest; + sqlite3_stmt *pTestStmt = 0; + int rc; + int i; + int nCol; + int nParam; + + if( *pbCorrupt ) return SQLITE_DONE; + nParam = sqlite3_bind_parameter_count(pStmt); + if( nParam>100 ) return SQLITE_DONE; + zTest = fuzz_invariant_sql(pStmt, iCnt); + if( zTest==0 ) return SQLITE_DONE; + rc = sqlite3_prepare_v2(db, zTest, -1, &pTestStmt, 0); + if( rc ){ + if( eVerbosity ){ + printf("invariant compile failed: %s\n%s\n", + sqlite3_errmsg(db), zTest); + } + sqlite3_free(zTest); + sqlite3_finalize(pTestStmt); + return rc; + } + sqlite3_free(zTest); + nCol = sqlite3_column_count(pStmt); + for(i=0; i=2 ){ + char *zSql = sqlite3_expanded_sql(pTestStmt); + printf("invariant-sql row=%d #%d:\n%s\n", iRow, iCnt, zSql); + sqlite3_free(zSql); + } + while( (rc = sqlite3_step(pTestStmt))==SQLITE_ROW ){ + for(i=0; i=nCol ) break; + } + if( rc==SQLITE_DONE ){ + /* No matching output row found */ + sqlite3_stmt *pCk = 0; + int iOrigRSO; + + + /* This is not a fault if the database file is corrupt, because anything + ** can happen with a corrupt database file */ + rc = sqlite3_prepare_v2(db, "PRAGMA integrity_check", -1, &pCk, 0); + if( rc ){ + sqlite3_finalize(pCk); + sqlite3_finalize(pTestStmt); + return rc; + } + if( eVerbosity>=2 ){ + char *zSql = sqlite3_expanded_sql(pCk); + printf("invariant-validity-check #1:\n%s\n", zSql); + sqlite3_free(zSql); + } + + rc = sqlite3_step(pCk); + if( rc!=SQLITE_ROW + || sqlite3_column_text(pCk, 0)==0 + || strcmp((const char*)sqlite3_column_text(pCk,0),"ok")!=0 + ){ + *pbCorrupt = 1; + sqlite3_finalize(pCk); + sqlite3_finalize(pTestStmt); + return SQLITE_CORRUPT; + } + sqlite3_finalize(pCk); + + /* + ** If inverting the scan order also results in a miss, assume that the + ** query is ambiguous and do not report a fault. + */ + sqlite3_db_config(db, SQLITE_DBCONFIG_REVERSE_SCANORDER, -1, &iOrigRSO); + sqlite3_db_config(db, SQLITE_DBCONFIG_REVERSE_SCANORDER, !iOrigRSO, 0); + sqlite3_prepare_v2(db, sqlite3_sql(pStmt), -1, &pCk, 0); + sqlite3_db_config(db, SQLITE_DBCONFIG_REVERSE_SCANORDER, iOrigRSO, 0); + if( eVerbosity>=2 ){ + char *zSql = sqlite3_expanded_sql(pCk); + printf("invariant-validity-check #2:\n%s\n", zSql); + sqlite3_free(zSql); + } + while( (rc = sqlite3_step(pCk))==SQLITE_ROW ){ + for(i=0; i=nCol ) break; + } + sqlite3_finalize(pCk); + if( rc==SQLITE_DONE ){ + sqlite3_finalize(pTestStmt); + return SQLITE_DONE; + } + + /* The original sameValue() comparison assumed a collating sequence + ** of "binary". It can sometimes get an incorrect result for different + ** collating sequences. So rerun the test with no assumptions about + ** collations. + */ + rc = sqlite3_prepare_v2(db, + "SELECT ?1=?2 OR ?1=?2 COLLATE nocase OR ?1=?2 COLLATE rtrim", + -1, &pCk, 0); + if( rc==SQLITE_OK ){ + if( eVerbosity>=2 ){ + char *zSql = sqlite3_expanded_sql(pCk); + printf("invariant-validity-check #3:\n%s\n", zSql); + sqlite3_free(zSql); + } + + sqlite3_reset(pTestStmt); + while( (rc = sqlite3_step(pTestStmt))==SQLITE_ROW ){ + for(i=0; i=nCol ){ + sqlite3_finalize(pCk); + goto not_a_fault; + } + } + } + sqlite3_finalize(pCk); + + /* Invariants do not necessarily work if there are virtual tables + ** involved in the query */ + rc = sqlite3_prepare_v2(db, + "SELECT 1 FROM bytecode(?1) WHERE opcode='VOpen'", -1, &pCk, 0); + if( rc==SQLITE_OK ){ + if( eVerbosity>=2 ){ + char *zSql = sqlite3_expanded_sql(pCk); + printf("invariant-validity-check #4:\n%s\n", zSql); + sqlite3_free(zSql); + } + sqlite3_bind_pointer(pCk, 1, pStmt, "stmt-pointer", 0); + rc = sqlite3_step(pCk); + } + sqlite3_finalize(pCk); + if( rc==SQLITE_DONE ){ + reportInvariantFailed(pStmt, pTestStmt, iRow); + return SQLITE_INTERNAL; + }else if( eVerbosity>0 ){ + printf("invariant-error ignored due to the use of virtual tables\n"); + } + } +not_a_fault: + sqlite3_finalize(pTestStmt); + return SQLITE_OK; +} + + +/* +** Generate SQL used to test a statement invariant. +** +** Return 0 if the iCnt is out of range. +** +** iCnt meanings: +** +** 0 SELECT * FROM () +** 1 SELECT DISTINCT * FROM () +** 2 SELECT * FROM () WHERE ORDER BY 1 +** 3 SELECT DISTINCT * FROM () ORDER BY 1 +** 4 SELECT * FROM () WHERE = +** 5 SELECT DISTINCT * FROM () WHERE ) WHERE = ORDER BY 1 +** 7 SELECT DISTINCT * FROM () WHERE = +** ORDER BY 1 +** N+0 SELECT * FROM () WHERE = +** N+1 SELECT DISTINCT * FROM () WHERE = +** N+2 SELECT * FROM () WHERE = ORDER BY 1 +** N+3 SELECT DISTINCT * FROM () WHERE = +** ORDER BY N +** +*/ +static char *fuzz_invariant_sql(sqlite3_stmt *pStmt, int iCnt){ + const char *zIn; + size_t nIn; + const char *zAnd = "WHERE"; + int i, j; + sqlite3_str *pTest; + sqlite3_stmt *pBase = 0; + sqlite3 *db = sqlite3_db_handle(pStmt); + int rc; + int nCol = sqlite3_column_count(pStmt); + int mxCnt; + int bDistinct = 0; + int bOrderBy = 0; + int nParam = sqlite3_bind_parameter_count(pStmt); + + switch( iCnt % 4 ){ + case 1: bDistinct = 1; break; + case 2: bOrderBy = 1; break; + case 3: bDistinct = bOrderBy = 1; break; + } + iCnt /= 4; + mxCnt = nCol; + if( iCnt<0 || iCnt>mxCnt ) return 0; + zIn = sqlite3_sql(pStmt); + if( zIn==0 ) return 0; + nIn = strlen(zIn); + while( nIn>0 && (isspace(zIn[nIn-1]) || zIn[nIn-1]==';') ) nIn--; + if( strchr(zIn, '?') ) return 0; + pTest = sqlite3_str_new(0); + sqlite3_str_appendf(pTest, "SELECT %s* FROM (", + bDistinct ? "DISTINCT " : ""); + sqlite3_str_append(pTest, zIn, (int)nIn); + sqlite3_str_append(pTest, ")", 1); + rc = sqlite3_prepare_v2(db, sqlite3_str_value(pTest), -1, &pBase, 0); + if( rc ){ + sqlite3_finalize(pBase); + pBase = pStmt; + } + for(i=0; i'3' || isdigit(zSuffix[2])) + ){ + /* This is a randomized column name and so cannot be used in the + ** WHERE clause. */ + continue; + } + for(j=0; j1 && i+2!=iCnt ) continue; + if( zColName==0 ) continue; + if( sqlite3_column_type(pStmt, i)==SQLITE_NULL ){ + sqlite3_str_appendf(pTest, " %s \"%w\" ISNULL", zAnd, zColName); + }else{ + sqlite3_str_appendf(pTest, " %s \"%w\"=?%d", zAnd, zColName, + i+1+nParam); + } + zAnd = "AND"; + } + if( pBase!=pStmt ) sqlite3_finalize(pBase); + if( bOrderBy ){ + sqlite3_str_appendf(pTest, " ORDER BY %d", iCnt>2 ? iCnt-1 : 1); + } + return sqlite3_str_finish(pTest); +} + +/* +** Return true if and only if v1 and is the same as v2. +*/ +static int sameValue( + sqlite3_stmt *pS1, int i1, /* Value to text on the left */ + sqlite3_stmt *pS2, int i2, /* Value to test on the right */ + sqlite3_stmt *pTestCompare /* COLLATE comparison statement or NULL */ +){ + int x = 1; + int t1 = sqlite3_column_type(pS1,i1); + int t2 = sqlite3_column_type(pS2,i2); + if( t1!=t2 ){ + if( (t1==SQLITE_INTEGER && t2==SQLITE_FLOAT) + || (t1==SQLITE_FLOAT && t2==SQLITE_INTEGER) + ){ + /* Comparison of numerics is ok */ + }else{ + return 0; + } + } + switch( sqlite3_column_type(pS1,i1) ){ + case SQLITE_INTEGER: { + x = sqlite3_column_int64(pS1,i1)==sqlite3_column_int64(pS2,i2); + break; + } + case SQLITE_FLOAT: { + x = sqlite3_column_double(pS1,i1)==sqlite3_column_double(pS2,i2); + break; + } + case SQLITE_TEXT: { + int e1 = sqlite3_value_encoding(sqlite3_column_value(pS1,i1)); + int e2 = sqlite3_value_encoding(sqlite3_column_value(pS2,i2)); + if( e1!=e2 ){ + const char *z1 = (const char*)sqlite3_column_text(pS1,i1); + const char *z2 = (const char*)sqlite3_column_text(pS2,i2); + x = ((z1==0 && z2==0) || (z1!=0 && z2!=0 && strcmp(z1,z1)==0)); + printf("Encodings differ. %d on left and %d on right\n", e1, e2); + abort(); + } + if( pTestCompare ){ + sqlite3_bind_value(pTestCompare, 1, sqlite3_column_value(pS1,i1)); + sqlite3_bind_value(pTestCompare, 2, sqlite3_column_value(pS2,i2)); + x = sqlite3_step(pTestCompare)==SQLITE_ROW + && sqlite3_column_int(pTestCompare,0)!=0; + sqlite3_reset(pTestCompare); + break; + } + if( e1!=SQLITE_UTF8 ){ + int len1 = sqlite3_column_bytes16(pS1,i1); + const unsigned char *b1 = sqlite3_column_blob(pS1,i1); + int len2 = sqlite3_column_bytes16(pS2,i2); + const unsigned char *b2 = sqlite3_column_blob(pS2,i2); + if( len1!=len2 ){ + x = 0; + }else if( len1==0 ){ + x = 1; + }else{ + x = (b1!=0 && b2!=0 && memcmp(b1,b2,len1)==0); + } + break; + } + /* Fall through into the SQLITE_BLOB case */ + } + case SQLITE_BLOB: { + int len1 = sqlite3_column_bytes(pS1,i1); + const unsigned char *b1 = sqlite3_column_blob(pS1,i1); + int len2 = sqlite3_column_bytes(pS2,i2); + const unsigned char *b2 = sqlite3_column_blob(pS2,i2); + if( len1!=len2 ){ + x = 0; + }else if( len1==0 ){ + x = 1; + }else{ + x = (b1!=0 && b2!=0 && memcmp(b1,b2,len1)==0); + } + break; + } + } + return x; +} + +/* +** Print binary data as hex +*/ +static void printHex(const unsigned char *a, int n, int mx){ + int j; + for(j=0; j'blank'), + b TEXT, + y TEXT AS (substr(b,m/2,m/2+2)) STORED, + c ANY, + PRIMARY KEY(b,a) + ) WITHOUT ROWID; + } +} { + catch {db close} + sqlite3 db :memory: + db eval $schema + do_execsql_test gencol1-2.$tn.100 { + INSERT INTO t1(a,b,c) VALUES(1,'abcdef',5.5),(3,'cantaloupe',NULL); + SELECT w, x, y, '|' FROM t1 ORDER BY a; + } {10 real abc | 30 null ntalo |} + do_execsql_test gencol1-2.$tn.101 { + SELECT w, x, y, '|' FROM t1 ORDER BY w; + } {10 real abc | 30 null ntalo |} + do_execsql_test gencol1-2.$tn.102 { + SELECT a FROM t1 WHERE w=30; + } {3} + do_execsql_test gencol1-2.$tn.103 { + SELECT a FROM t1 WHERE x='real'; + } {1} + do_execsql_test gencol1-2.$tn.104 { + SELECT a FROM t1 WHERE y LIKE '%tal%' OR x='real' ORDER BY b; + } {1 3} + do_execsql_test gencol1-2.$tn.110 { + CREATE INDEX t1w ON t1(w); + SELECT a FROM t1 WHERE w=10; + } {1} + do_execsql_test gencol1-2.$tn.120 { + CREATE INDEX t1x ON t1(x) WHERE w BETWEEN 20 AND 40; + SELECT a FROM t1 WHERE x='null' AND w BETWEEN 20 AND 40; + } {3} + do_execsql_test gencol1-2.$tn.121 { + SELECT a FROM t1 WHERE x='real'; + } {1} + do_execsql_test gencol1-2.$tn.130 { + VACUUM; + PRAGMA integrity_check; + } {ok} + do_execsql_test gencol1-2.$tn.140 { + UPDATE t1 SET a=a+100 WHERE w<20; + SELECT a, w, '|' FROM t1 ORDER BY w; + } {3 30 | 101 1010 |} + do_execsql_test gencol1-2.$tn.150 { + INSERT INTO t1 VALUES(4,'jambalaya','Chef John'),(15,87719874135,0); + SELECT w, x, y, '|' FROM t1 ORDER BY w; + } {30 null ntalo | 40 text balaya | 150 integer {} | 1010 real {} |} +} + +# 2019-10-31 ticket b9befa4b83a660cc +db close +sqlite3 db :memory: +do_execsql_test gencol1-3.100 { + PRAGMA foreign_keys = true; + CREATE TABLE t0(c0 PRIMARY KEY, c1, c2 AS (c0+c1-c3) REFERENCES t0, c3); + INSERT INTO t0 VALUES (0, 0, 0), (11, 5, 5); + UPDATE t0 SET c1 = c0, c3 = c0; + SELECT *, '|' FROM t0 ORDER BY +c0; +} {0 0 0 0 | 11 11 11 11 |} +do_catchsql_test gencol1-3.110 { + UPDATE t0 SET c1 = c0, c3 = c0+1; +} {1 {FOREIGN KEY constraint failed}} + +# 2019-11-01 ticket c28a01da72f8957c +db close +sqlite3 db :memory: +do_execsql_test gencol1-4.100 { + CREATE TABLE t0 ( + c0, + c1 a UNIQUE AS (1), + c2, + c3 REFERENCES t0(c1) + ); + PRAGMA foreign_keys = true; + INSERT INTO t0(c0,c2,c3) VALUES(0,0,1); +} {} +do_catchsql_test gencol1-4.110 { + REPLACE INTO t0(c0,c2,c3) VALUES(0,0,0),(0,0,0); +} {1 {FOREIGN KEY constraint failed}} + +# 2019-11-01 Problem found while adding new foreign key test cases in TH3. +db close +sqlite3 db :memory: +do_execsql_test gencol1-5.100 { + PRAGMA foreign_keys=ON; + CREATE TABLE t1( + gcb AS (b*1), + a INTEGER PRIMARY KEY, + gcc AS (c+0), + b UNIQUE, + gca AS (1*a+0), + c UNIQUE + ) WITHOUT ROWID; + INSERT INTO t1 VALUES(1,2,3); + INSERT INTO t1 VALUES(4,5,6); + INSERT INTO t1 VALUES(7,8,9); + CREATE TABLE t1a( + gcx AS (x+0) REFERENCES t1(a) ON DELETE CASCADE, + id, + x, + gcid AS (1*id) + ); + INSERT INTO t1a VALUES(1, 1); + INSERT INTO t1a VALUES(2, 4); + INSERT INTO t1a VALUES(3, 7); + DELETE FROM t1 WHERE b=5; + SELECT id,x,'|' FROM t1a ORDER BY id; +} {1 1 | 3 7 |} + +do_catchsql_test gencol1-6.10 { + DROP TABLE IF EXISTS t0; + CREATE TABLE t0(c0 NOT NULL AS(c1), c1); + REPLACE INTO t0(c1) VALUES(NULL); +} {1 {NOT NULL constraint failed: t0.c0}} + +# 2019-11-06 ticket https://www.sqlite.org/src/info/2399f5986134f79c +# 2019-12-27 ticket https://www.sqlite.org/src/info/5fbc159eeb092130 +# 2019-12-27 ticket https://www.sqlite.org/src/info/37823501c68a09f9 +# +# All of the above tickets deal with NOT NULL ON CONFLICT REPLACE +# constraints on tables that have generated columns. +# +reset_db +do_execsql_test gencol1-7.10 { + CREATE TABLE t0 (c0 GENERATED ALWAYS AS (1), c1 UNIQUE, c2 UNIQUE); + INSERT INTO t0(c1) VALUES (1); + SELECT quote(0 = t0.c2 OR t0.c1 BETWEEN t0.c2 AND 1) FROM t0; +} {NULL} +do_execsql_test gencol1-7.11 { + DROP TABLE t0; + CREATE TABLE t0(c0 NOT NULL DEFAULT 'xyz', c1 AS(c0) NOT NULL); + REPLACE INTO t0(c0) VALUES(NULL); + SELECT * FROM t0; +} {xyz xyz} +do_execsql_test gencol1-7.12 { + DROP TABLE t0; + CREATE TABLE t0(c0 NOT NULL DEFAULT 'xyz', c1 AS(c0) STORED NOT NULL); + REPLACE INTO t0(c0) VALUES(NULL); + SELECT * FROM t0; +} {xyz xyz} +do_execsql_test gencol1-7.20 { + CREATE TABLE t1( + a NOT NULL DEFAULT 'aaa', + b AS(c) NOT NULL, + c NOT NULL DEFAULT 'ccc'); + REPLACE INTO t1(a,c) VALUES(NULL,NULL); + SELECT * FROM t1; +} {aaa ccc ccc} +do_execsql_test gencol1-7.21 { + DROP TABLE t1; + CREATE TABLE t1( + a NOT NULL DEFAULT 'aaa', + b AS(c) STORED NOT NULL, + c NOT NULL DEFAULT 'ccc'); + REPLACE INTO t1(a,c) VALUES(NULL,NULL); + SELECT * FROM t1; +} {aaa ccc ccc} +do_execsql_test gencol1-7.30 { + CREATE TABLE t2( + a NOT NULL DEFAULT 'aaa', + b AS(a) NOT NULL, + c NOT NULL DEFAULT 'ccc'); + REPLACE INTO t2(a,c) VALUES(NULL,NULL); + SELECT * FROM t2; +} {aaa aaa ccc} +do_execsql_test gencol1-7.31 { + DROP TABLE t2; + CREATE TABLE t2( + a NOT NULL DEFAULT 'aaa', + b AS(a) STORED NOT NULL, + c NOT NULL DEFAULT 'ccc'); + REPLACE INTO t2(a,c) VALUES(NULL,NULL); + SELECT * FROM t2; +} {aaa aaa ccc} +do_execsql_test gencol1-7.40 { + CREATE TABLE t3(a NOT NULL DEFAULT 123, b AS(a) UNIQUE); + REPLACE INTO t3 VALUES(NULL); + SELECT * FROM t3; +} {123 123} +do_execsql_test gencol1-7.41 { + SELECT * FROM t3 WHERE b=123; +} {123 123} +do_execsql_test gencol1-7.50 { + CREATE TABLE t4(a NOT NULL DEFAULT 123, b AS(a*10+4) STORED UNIQUE); + REPLACE INTO t4 VALUES(NULL); + SELECT * FROM t4; +} {123 1234} +do_execsql_test gencol1-7.51 { + SELECT * FROM t4 WHERE b=1234; +} {123 1234} + +# 2019-11-06 ticket 4fc08501f4e56692 +do_execsql_test gencol1-8.10 { + DROP TABLE IF EXISTS t0; + CREATE TABLE t0( + c0 AS (('a', 9) < ('b', c1)), + c1 AS (1), + c2 CHECK (1 = c1) + ); + INSERT INTO t0 VALUES (0),(99); + SELECT * FROM t0; +} {1 1 0 1 1 99} +do_catchsql_test gencol1-8.20 { + DROP TABLE IF EXISTS t0; + CREATE TABLE t0( + c0, + c1 AS(c0 + c2), + c2 AS(c1) CHECK(c2) + ); + UPDATE t0 SET c0 = NULL; +} {1 {generated column loop on "c2"}} + +# 2019-11-21 Problems in the new generated column logic +# reported by Yongheng Chen and Rui Zhong +reset_db +do_execsql_test gencol1-9.10 { + PRAGMA foreign_keys=OFF; + CREATE TABLE t1(aa , bb AS (17) UNIQUE); + INSERT INTO t1 VALUES(17); + CREATE TABLE t2(cc); + INSERT INTO t2 VALUES(41); + SELECT * FROM t2 JOIN t1 WHERE t1.bb=t1.aa AND t1.bb=17; +} {41 17 17} +do_execsql_test gencol1-9.20 { + CREATE TABLE t3(aa INT PRIMARY KEY, bb UNIQUE AS(aa)); + INSERT INTO t3 VALUES(1); + SELECT 100, * FROM t3; + DELETE FROM t3 WHERE (SELECT bb FROM t3); + SELECT 200, * FROM t3; +} {100 1 1} + +# 2019-12-04 Generated column in a CREATE TABLE IF NOT EXISTS that +# does already exist. +# +sqlite3 db :memory: +do_execsql_test gencol1-10.10 { + CREATE TABLE t1(aa,bb); + CREATE TABLE IF NOT EXISTS t1(aa, bb AS (aa+1)); + PRAGMA integrity_check; +} {ok} + +# 2019-12-06 Found by mrigger +# +sqlite3 db :memory: +do_execsql_test gencol1-11.10 { + PRAGMA foreign_keys = true; + CREATE TABLE t0( + c0, + c1 INTEGER PRIMARY KEY, + c2 BLOB UNIQUE DEFAULT x'00', + c3 BLOB GENERATED ALWAYS AS (1), + FOREIGN KEY(c1) REFERENCES t0(c2) + ); +} +do_catchsql_test gencol1-11.20 { + INSERT OR REPLACE INTO t0(c0, c1) VALUES (2, 1), (1, 0) +} {1 {FOREIGN KEY constraint failed}} +do_execsql_test gencol1-11.30 { + DROP TABLE t0; + CREATE TABLE t0( + c0, + c1 INTEGER PRIMARY KEY, + c3 BLOB GENERATED ALWAYS AS (1), + c2 BLOB UNIQUE DEFAULT x'00', + FOREIGN KEY(c1) REFERENCES t0(c2) + ); +} +do_catchsql_test gencol1-11.40 { + INSERT OR REPLACE INTO t0(c0, c1) VALUES (2, 1), (1, 0) +} {1 {FOREIGN KEY constraint failed}} +do_execsql_test gencol1-11.50 { + DROP TABLE t0; + CREATE TABLE t0( + c0, + c3 BLOB GENERATED ALWAYS AS (1), + c1 INTEGER PRIMARY KEY, + c2 BLOB UNIQUE DEFAULT x'00', + FOREIGN KEY(c1) REFERENCES t0(c2) + ); +} +do_catchsql_test gencol1-11.60 { + INSERT OR REPLACE INTO t0(c0, c1) VALUES (2, 1), (1, 0) +} {1 {FOREIGN KEY constraint failed}} +do_execsql_test gencol1-11.70 { + DROP TABLE t0; + CREATE TABLE t0( + c3 BLOB GENERATED ALWAYS AS (1), + c0, + c1 INTEGER PRIMARY KEY, + c2 BLOB UNIQUE DEFAULT x'00', + FOREIGN KEY(c1) REFERENCES t0(c2) + ); +} +do_catchsql_test gencol1-11.80 { + INSERT OR REPLACE INTO t0(c0, c1) VALUES (2, 1), (1, 0) +} {1 {FOREIGN KEY constraint failed}} + +# 2019-12-09 ticket bd8c280671ba44a7 +# With generated columns, the sqlite3ExprGetColumnOfTable() routine might +# generate a code sequence that does not end with OP_Column. So check to +# make sure that the last instruction generated is an OP_column prior to +# applying the OPFLAG_TYPEOFARG optimization to NOT NULL checks in the +# PRAGMA integrity_check code. +# +sqlite3 db :memory: +do_execsql_test gencol1-12.10 { + CREATE TABLE t0 (c0, c1 NOT NULL AS (c0==0)); + INSERT INTO t0(c0) VALUES (0); + PRAGMA integrity_check; +} {ok} + +# 2019-12-09 bug report from Yongheng Chen +# Ensure that the SrcList_item.colUsed field is set correctly when a +# generated column appears in the USING clause of a join. +# +do_execsql_test gencol1-13.10 { + CREATE TABLE t1(x, y AS(x+1)); + INSERT INTO t1 VALUES(10); + SELECT y FROM t1 JOIN t1 USING (y,y); +} {11} +do_execsql_test gencol1-13.11 { + SELECT 123 FROM t1 JOIN t1 USING (x); +} {123} +do_execsql_test gencol1-13.11 { + SELECT 456 FROM t1 JOIN t1 USING (x,x); +} {456} +do_execsql_test gencol1-13.20 { + CREATE INDEX t1y ON t1(y); + SELECT y FROM t1 JOIN t1 USING (y,y); +} {11} +do_execsql_test gencol1-13.21 { + CREATE INDEX t1x ON t1(x); + SELECT 123 FROM t1 JOIN t1 USING (x); +} {123} +do_execsql_test gencol1-13.22 { + SELECT 456 FROM t1 JOIN t1 USING (x,x); +} {456} + +# 2019-12-14 ticket b439bfcfb7deedc6 +# +sqlite3 db :memory: +do_execsql_test gencol1-14.10 { + CREATE TABLE t0(c0 AS(1 >= 1), c1 UNIQUE AS(TYPEOF(c0)), c2); + INSERT INTO t0 VALUES(0); + REINDEX; + SELECT * FROM t0; +} {1 integer 0} +do_catchsql_test gencol1-14.10 { + INSERT INTO t0 VALUES(2); +} {1 {UNIQUE constraint failed: t0.c1}} + +# 2019-12-14 gramfuzz1 find +# The schema is malformed in that it has a subquery on a generated +# column expression. This will be loaded if writable_schema=ON. SQLite +# must not use such an expression during code generation as the code generator +# will add bits of content to the expression tree that might be allocated +# from lookaside. But the schema is not tied to a particular database +# connection, so the use of lookaside memory is prohibited. The fix +# is to change the generated column expression to NULL before adding it +# to the schema. +# +reset_db +do_test gencol1-15.10 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 8192 pagesize 4096 filename c27.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 01 00 00 00 02 .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ +| 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 ................ +| 96: 00 2e 3f d8 0d 00 00 00 01 0f ba 00 0f ba 00 00 ..?............. +| 4016: 00 00 00 00 00 00 00 00 00 00 44 01 06 17 11 11 ..........D..... +| 4032: 01 75 74 61 62 6c 65 74 31 74 31 02 43 52 45 41 .utablet1t1.CREA +| 4048: 54 45 20 54 41 42 4c 45 20 74 31 28 61 20 49 4e TE TABLE t1(a IN +| 4064: 54 2c 20 62 20 41 53 28 28 56 41 4c 55 45 53 28 T, b AS((VALUES( +| 4080: 31 29 29 20 49 53 20 75 6e 6b 6e 6f 77 6e 29 29 1)) IS unknown)) +| page 2 offset 4096 +| 0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................ +| end c27.db +}]} {} +do_execsql_test gencol1-15.20 { + PRAGMA writable_schema=ON; + REPLACE INTO t1 VALUES(9); + SELECT a, quote(b) FROM t1 +} {9 NULL} + +# 2019-12-16 ticket 3b84b42943644d6f +# When a table is the right table of a LEFT JOIN and the ON clause is +# false, make sure any generated columns evaluate to NULL. +reset_db +do_execsql_test gencol1-16.10 { + CREATE TABLE t0(c0); + CREATE TABLE t1(c1, c2 AS(1)); + INSERT INTO t0 VALUES(0); + SELECT c0, c1, c2 FROM t0 LEFT JOIN t1; +} {0 {} {}} +do_execsql_test gencol1-16.20 { + DROP TABLE t1; + CREATE TABLE t1(c1, c2 AS (c1 ISNULL)); + SELECT c0, c1, c2 FROM t0 LEFT JOIN t1; +} {0 {} {}} +do_execsql_test gencol1-16.30 { + INSERT INTO t1(c1) VALUES(1),(NULL); + SELECT * FROM t1; +} {1 0 {} 1} +do_execsql_test gencol1-16.40 { + SELECT c0, c1, c2 FROM t0 LEFT JOIN t1 ON c0=c1; +} {0 {} {}} + +# 2019-12-20 ticket e0a8120553f4b082 +# Generated columns with REAL affinity need to have an OP_RealAffinity +# opcode applied, even when the column value is extracted from an index. +# +reset_db +do_execsql_test gencol1-17.10 { + CREATE TABLE t0(c0 REAL AS(1) UNIQUE, c1 INT); + INSERT INTO t0 VALUES(''); + SELECT quote(c0), quote(c1) from t0; +} {1.0 ''} +do_execsql_test gencol1-17.20 { + SELECT *, (1 BETWEEN CAST(t0.c0 AS TEXT) AND t0.c0) FROM t0; +} {1.0 {} 0} +do_execsql_test gencol1-17.30 { + SELECT * FROM t0 WHERE (1 BETWEEN CAST(t0.c0 AS TEXT) AND t0.c0); +} {} +do_execsql_test gencol1-17.40 { + CREATE TABLE t1(a TEXT AS(b) COLLATE nocase, b TEXT, c INT, d DEFAULT 1); + INSERT INTO t1(b,c) VALUES('abc',11),('DEF',22),('ghi',33); + SELECT a FROM t1 WHERE b='DEF' AND a='def'; +} {DEF} +do_execsql_test gencol1-17.50 { + CREATE INDEX t1bca ON t1(b,c,a); + SELECT a FROM t1 WHERE b='DEF' AND a='def'; +} {DEF} + +# 2019-12-26 ticket ec8abb025e78f40c +# An index on a virtual column with a constant value (why would anybody +# ever do such a thing?) can cause problems for a one-pass DELETE. +# +reset_db +do_execsql_test gencol1-18.10 { + CREATE TABLE t0(c0 UNIQUE AS(0), c1, c2); + INSERT INTO t0(c1) VALUES(0); + SELECT * FROM t0; +} {0 0 {}} +do_execsql_test gencol1-18.20 { + UPDATE t0 SET c1=0, c2=0 WHERE c0>=0; + SELECT * FROM t0; +} {0 0 0} + +# 2019-12-27 ticket de4b04149b9fdeae +# +reset_db +do_catchsql_test gencol1-19.10 { + CREATE TABLE t0( + c0 INT AS(2) UNIQUE, + c1 TEXT UNIQUE, + FOREIGN KEY(c0) REFERENCES t0(c1) + ); + INSERT INTO t0(c1) VALUES(0.16334143182538696), (0); +} {1 {UNIQUE constraint failed: t0.c0}} + +# 2020-06-29 forum bug report. +# https://sqlite.org/forum/forumpost/73b9a8ccfb +# +do_execsql_test gencol1-20.1 { + CREATE TEMPORARY TABLE tab ( + prim DATE PRIMARY KEY, + a INTEGER, + comp INTEGER AS (a), + b INTEGER, + x INTEGER + ); + -- Add some data + INSERT INTO tab (prim, a, b) VALUES ('2001-01-01', 0, 0); + -- Check that each column is 0 like I expect + SELECT * FROM tab; +} {2001-01-01 0 0 0 {}} +do_execsql_test gencol1-20.2 { + -- Do an UPSERT on the b column + INSERT INTO tab (prim, b) + VALUES ('2001-01-01',5) + ON CONFLICT(prim) DO UPDATE SET b=excluded.b; + -- Now b is NULL rather than 5 + SELECT * FROM tab; +} {2001-01-01 0 0 5 {}} + +# 2021-07-30 forum https://sqlite.org/forum/forumpost/ff3ffe09251c105b?t=h +# +ifcapable vtab { +reset_db + do_execsql_test gencol1-21.1 { + CREATE TABLE t1( + a integer primary key, + b int generated always as (a+5), + c text GENERATED ALWAYS as (printf('%08x',a)), + d Generated + Always + AS ('xyzzy'), + e int Always default(5) + ); + INSERT INTO t1(a) VALUES(5); + SELECT name, type FROM pragma_table_xinfo('t1'); + } {a INTEGER b INT c TEXT d {} e INT} +} + +# 2021-09-07 forum https://sqlite.org/forum/forumpost/699b44b3ee +# +reset_db +do_execsql_test gencol1-22.1 { + CREATE TABLE t0(a PRIMARY KEY,b TEXT AS ('2') UNIQUE); + INSERT INTO t0(a) VALUES(2); + SELECT * FROM t0 AS x JOIN t0 AS y + WHERE x.b='2' + AND (y.a=2 OR (x.b LIKE '2*' AND y.a=x.b)); +} {2 2 2 2} + + +# 2023-03-02 dbsqlfuzz 65f5eb57f8859344d5f1f33e08c77ee12960ed83 +# +set typelist {ANY INT REAL BLOB TEXT {}} +set cnt 0 +foreach t1 $typelist { + foreach t2 $typelist { + incr cnt + db eval " + DROP TABLE IF EXISTS t1; + CREATE TABLE t1( + x $t1, + a $t2 AS (x) VIRTUAL, + b BLOB AS (x) VIRTUAL + ); + CREATE INDEX x2 ON t1(a); + INSERT INTO t1(x) VALUES(NULL),('1'),(2),(3.5),('xyz'); + " + set x1 [lsort [db eval {SELECT typeof(b) FROM t1}]] + do_test gencol1-23.1.$cnt { + lsort [db eval {SELECT typeof(b) FROM t1 INDEXED BY x2}] + } $x1 + } +} +do_execsql_test gencol1-23.2 { + DROP TABLE t1; + CREATE TABLE t1( + x, + a INT AS (x) VIRTUAL, + b BLOB AS (x) VIRTUAL + ); + CREATE INDEX x2 ON t1(a); + INSERT INTO t1(x) VALUES(NULL),('1'),('xyz'),(2),(3.5); + SELECT quote(a) FROM t1 INDEXED BY x2; +} {NULL 1 2 3.5 'xyz'} +do_execsql_test gencol1-23.3 { + EXPLAIN SELECT a FROM t1 INDEXED BY x2; +} {~/Column 0/} +# ^^^^^^^^---- verfies that x2 acts like a covering index +do_execsql_test gencol1-23.4 { + EXPLAIN SELECT b FROM t1 INDEXED BY x2; +} {/Column 0/} +# ^^^^^^^^^^--- Must reference the original table in this case because +# of the different datatype on column b. + +# 2023-03-07 https://sqlite.org/forum/forumpost/b312e075b5 +# +do_catchsql_test gencol1-23.5 { + CREATE TABLE v0(c1 INT, c2 AS (RAISE(IGNORE))); +} {1 {RAISE() may only be used within a trigger-program}} + +finish_test diff --git a/test/genesis.tcl b/test/genesis.tcl new file mode 100644 index 0000000..4ba4c8e --- /dev/null +++ b/test/genesis.tcl @@ -0,0 +1,1560 @@ +# 2010 February 02 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements a TCL function that fills an FTS table with +# lots of content useful for testing. This routine is broken out into +# a separate file to facilitate its use by multiple test scripts. +# + +# The fts_kjv_genesis routine is already loaded. This script is a no-op. +if {[lsearch [info procs] fts_kjv_genesis]>=0} return + +# This procedure fills an existing FTS3/FTS4 table with many entries. +# The table needs to have a single column (other than docid) named "words". +# +proc fts_kjv_genesis {} { +db eval { +BEGIN TRANSACTION; +INSERT INTO t1(docid,words) VALUES(1001001,'In the beginning God created the heaven and the earth.'); +INSERT INTO t1(docid,words) VALUES(1001002,'And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters.'); +INSERT INTO t1(docid,words) VALUES(1001003,'And God said, Let there be light: and there was light.'); +INSERT INTO t1(docid,words) VALUES(1001004,'And God saw the light, that it was good: and God divided the light from the darkness.'); +INSERT INTO t1(docid,words) VALUES(1001005,'And God called the light Day, and the darkness he called Night. And the evening and the morning were the first day.'); +INSERT INTO t1(docid,words) VALUES(1001006,'And God said, Let there be a firmament in the midst of the waters, and let it divide the waters from the waters.'); +INSERT INTO t1(docid,words) VALUES(1001007,'And God made the firmament, and divided the waters which were under the firmament from the waters which were above the firmament: and it was so.'); +INSERT INTO t1(docid,words) VALUES(1001008,'And God called the firmament Heaven. And the evening and the morning were the second day.'); +INSERT INTO t1(docid,words) VALUES(1001009,'And God said, Let the waters under the heaven be gathered together unto one place, and let the dry land appear: and it was so.'); +INSERT INTO t1(docid,words) VALUES(1001010,'And God called the dry land Earth; and the gathering together of the waters called he Seas: and God saw that it was good.'); +INSERT INTO t1(docid,words) VALUES(1001011,'And God said, Let the earth bring forth grass, the herb yielding seed, and the fruit tree yielding fruit after his kind, whose seed is in itself, upon the earth: and it was so.'); +INSERT INTO t1(docid,words) VALUES(1001012,'And the earth brought forth grass, and herb yielding seed after his kind, and the tree yielding fruit, whose seed was in itself, after his kind: and God saw that it was good.'); +INSERT INTO t1(docid,words) VALUES(1001013,'And the evening and the morning were the third day.'); +INSERT INTO t1(docid,words) VALUES(1001014,'And God said, Let there be lights in the firmament of the heaven to divide the day from the night; and let them be for signs, and for seasons, and for days, and years:'); +INSERT INTO t1(docid,words) VALUES(1001015,'And let them be for lights in the firmament of the heaven to give light upon the earth: and it was so.'); +INSERT INTO t1(docid,words) VALUES(1001016,'And God made two great lights; the greater light to rule the day, and the lesser light to rule the night: he made the stars also.'); +INSERT INTO t1(docid,words) VALUES(1001017,'And God set them in the firmament of the heaven to give light upon the earth,'); +INSERT INTO t1(docid,words) VALUES(1001018,'And to rule over the day and over the night, and to divide the light from the darkness: and God saw that it was good.'); +INSERT INTO t1(docid,words) VALUES(1001019,'And the evening and the morning were the fourth day.'); +INSERT INTO t1(docid,words) VALUES(1001020,'And God said, Let the waters bring forth abundantly the moving creature that hath life, and fowl that may fly above the earth in the open firmament of heaven.'); +INSERT INTO t1(docid,words) VALUES(1001021,'And God created great whales, and every living creature that moveth, which the waters brought forth abundantly, after their kind, and every winged fowl after his kind: and God saw that it was good.'); +INSERT INTO t1(docid,words) VALUES(1001022,'And God blessed them, saying, Be fruitful, and multiply, and fill the waters in the seas, and let fowl multiply in the earth.'); +INSERT INTO t1(docid,words) VALUES(1001023,'And the evening and the morning were the fifth day.'); +INSERT INTO t1(docid,words) VALUES(1001024,'And God said, Let the earth bring forth the living creature after his kind, cattle, and creeping thing, and beast of the earth after his kind: and it was so.'); +INSERT INTO t1(docid,words) VALUES(1001025,'And God made the beast of the earth after his kind, and cattle after their kind, and every thing that creepeth upon the earth after his kind: and God saw that it was good.'); +INSERT INTO t1(docid,words) VALUES(1001026,'And God said, Let us make man in our image, after our likeness: and let them have dominion over the fish of the sea, and over the fowl of the air, and over the cattle, and over all the earth, and over every creeping thing that creepeth upon the earth.'); +INSERT INTO t1(docid,words) VALUES(1001027,'So God created man in his own image, in the image of God created he him; male and female created he them.'); +INSERT INTO t1(docid,words) VALUES(1001028,'And God blessed them, and God said unto them, Be fruitful, and multiply, and replenish the earth, and subdue it: and have dominion over the fish of the sea, and over the fowl of the air, and over every living thing that moveth upon the earth.'); +INSERT INTO t1(docid,words) VALUES(1001029,'And God said, Behold, I have given you every herb bearing seed, which is upon the face of all the earth, and every tree, in the which is the fruit of a tree yielding seed; to you it shall be for meat.'); +INSERT INTO t1(docid,words) VALUES(1001030,'And to every beast of the earth, and to every fowl of the air, and to every thing that creepeth upon the earth, wherein there is life, I have given every green herb for meat: and it was so.'); +INSERT INTO t1(docid,words) VALUES(1001031,'And God saw every thing that he had made, and, behold, it was very good. And the evening and the morning were the sixth day.'); +INSERT INTO t1(docid,words) VALUES(1002001,'Thus the heavens and the earth were finished, and all the host of them.'); +INSERT INTO t1(docid,words) VALUES(1002002,'And on the seventh day God ended his work which he had made; and he rested on the seventh day from all his work which he had made.'); +INSERT INTO t1(docid,words) VALUES(1002003,'And God blessed the seventh day, and sanctified it: because that in it he had rested from all his work which God created and made.'); +INSERT INTO t1(docid,words) VALUES(1002004,'These are the generations of the heavens and of the earth when they were created, in the day that the LORD God made the earth and the heavens,'); +INSERT INTO t1(docid,words) VALUES(1002005,'And every plant of the field before it was in the earth, and every herb of the field before it grew: for the LORD God had not caused it to rain upon the earth, and there was not a man to till the ground.'); +INSERT INTO t1(docid,words) VALUES(1002006,'But there went up a mist from the earth, and watered the whole face of the ground.'); +INSERT INTO t1(docid,words) VALUES(1002007,'And the LORD God formed man of the dust of the ground, and breathed into his nostrils the breath of life; and man became a living soul.'); +INSERT INTO t1(docid,words) VALUES(1002008,'And the LORD God planted a garden eastward in Eden; and there he put the man whom he had formed.'); +INSERT INTO t1(docid,words) VALUES(1002009,'And out of the ground made the LORD God to grow every tree that is pleasant to the sight, and good for food; the tree of life also in the midst of the garden, and the tree of knowledge of good and evil.'); +INSERT INTO t1(docid,words) VALUES(1002010,'And a river went out of Eden to water the garden; and from thence it was parted, and became into four heads.'); +INSERT INTO t1(docid,words) VALUES(1002011,'The name of the first is Pison: that is it which compasseth the whole land of Havilah, where there is gold;'); +INSERT INTO t1(docid,words) VALUES(1002012,'And the gold of that land is good: there is bdellium and the onyx stone.'); +INSERT INTO t1(docid,words) VALUES(1002013,'And the name of the second river is Gihon: the same is it that compasseth the whole land of Ethiopia.'); +INSERT INTO t1(docid,words) VALUES(1002014,'And the name of the third river is Hiddekel: that is it which goeth toward the east of Assyria. And the fourth river is Euphrates.'); +INSERT INTO t1(docid,words) VALUES(1002015,'And the LORD God took the man, and put him into the garden of Eden to dress it and to keep it.'); +INSERT INTO t1(docid,words) VALUES(1002016,'And the LORD God commanded the man, saying, Of every tree of the garden thou mayest freely eat:'); +INSERT INTO t1(docid,words) VALUES(1002017,'But of the tree of the knowledge of good and evil, thou shalt not eat of it: for in the day that thou eatest thereof thou shalt surely die.'); +INSERT INTO t1(docid,words) VALUES(1002018,'And the LORD God said, It is not good that the man should be alone; I will make him an help meet for him.'); +INSERT INTO t1(docid,words) VALUES(1002019,'And out of the ground the LORD God formed every beast of the field, and every fowl of the air; and brought them unto Adam to see what he would call them: and whatsoever Adam called every living creature, that was the name thereof.'); +INSERT INTO t1(docid,words) VALUES(1002020,'And Adam gave names to all cattle, and to the fowl of the air, and to every beast of the field; but for Adam there was not found an help meet for him.'); +INSERT INTO t1(docid,words) VALUES(1002021,'And the LORD God caused a deep sleep to fall upon Adam, and he slept: and he took one of his ribs, and closed up the flesh instead thereof;'); +INSERT INTO t1(docid,words) VALUES(1002022,'And the rib, which the LORD God had taken from man, made he a woman, and brought her unto the man.'); +INSERT INTO t1(docid,words) VALUES(1002023,'And Adam said, This is now bone of my bones, and flesh of my flesh: she shall be called Woman, because she was taken out of Man.'); +INSERT INTO t1(docid,words) VALUES(1002024,'Therefore shall a man leave his father and his mother, and shall cleave unto his wife: and they shall be one flesh.'); +INSERT INTO t1(docid,words) VALUES(1002025,'And they were both naked, the man and his wife, and were not ashamed.'); +INSERT INTO t1(docid,words) VALUES(1003001,'Now the serpent was more subtil than any beast of the field which the LORD God had made. And he said unto the woman, Yea, hath God said, Ye shall not eat of every tree of the garden?'); +INSERT INTO t1(docid,words) VALUES(1003002,'And the woman said unto the serpent, We may eat of the fruit of the trees of the garden:'); +INSERT INTO t1(docid,words) VALUES(1003003,'But of the fruit of the tree which is in the midst of the garden, God hath said, Ye shall not eat of it, neither shall ye touch it, lest ye die.'); +INSERT INTO t1(docid,words) VALUES(1003004,'And the serpent said unto the woman, Ye shall not surely die:'); +INSERT INTO t1(docid,words) VALUES(1003005,'For God doth know that in the day ye eat thereof, then your eyes shall be opened, and ye shall be as gods, knowing good and evil.'); +INSERT INTO t1(docid,words) VALUES(1003006,'And when the woman saw that the tree was good for food, and that it was pleasant to the eyes, and a tree to be desired to make one wise, she took of the fruit thereof, and did eat, and gave also unto her husband with her; and he did eat.'); +INSERT INTO t1(docid,words) VALUES(1003007,'And the eyes of them both were opened, and they knew that they were naked; and they sewed fig leaves together, and made themselves aprons.'); +INSERT INTO t1(docid,words) VALUES(1003008,'And they heard the voice of the LORD God walking in the garden in the cool of the day: and Adam and his wife hid themselves from the presence of the LORD God amongst the trees of the garden.'); +INSERT INTO t1(docid,words) VALUES(1003009,'And the LORD God called unto Adam, and said unto him, Where art thou?'); +INSERT INTO t1(docid,words) VALUES(1003010,'And he said, I heard thy voice in the garden, and I was afraid, because I was naked; and I hid myself.'); +INSERT INTO t1(docid,words) VALUES(1003011,'And he said, Who told thee that thou wast naked? Hast thou eaten of the tree, whereof I commanded thee that thou shouldest not eat?'); +INSERT INTO t1(docid,words) VALUES(1003012,'And the man said, The woman whom thou gavest to be with me, she gave me of the tree, and I did eat.'); +INSERT INTO t1(docid,words) VALUES(1003013,'And the LORD God said unto the woman, What is this that thou hast done? And the woman said, The serpent beguiled me, and I did eat.'); +INSERT INTO t1(docid,words) VALUES(1003014,'And the LORD God said unto the serpent, Because thou hast done this, thou art cursed above all cattle, and above every beast of the field; upon thy belly shalt thou go, and dust shalt thou eat all the days of thy life:'); +INSERT INTO t1(docid,words) VALUES(1003015,'And I will put enmity between thee and the woman, and between thy seed and her seed; it shall bruise thy head, and thou shalt bruise his heel.'); +INSERT INTO t1(docid,words) VALUES(1003016,'Unto the woman he said, I will greatly multiply thy sorrow and thy conception; in sorrow thou shalt bring forth children; and thy desire shall be to thy husband, and he shall rule over thee.'); +INSERT INTO t1(docid,words) VALUES(1003017,'And unto Adam he said, Because thou hast hearkened unto the voice of thy wife, and hast eaten of the tree, of which I commanded thee, saying, Thou shalt not eat of it: cursed is the ground for thy sake; in sorrow shalt thou eat of it all the days of thy life;'); +INSERT INTO t1(docid,words) VALUES(1003018,'Thorns also and thistles shall it bring forth to thee; and thou shalt eat the herb of the field;'); +INSERT INTO t1(docid,words) VALUES(1003019,'In the sweat of thy face shalt thou eat bread, till thou return unto the ground; for out of it wast thou taken: for dust thou art, and unto dust shalt thou return.'); +INSERT INTO t1(docid,words) VALUES(1003020,'And Adam called his wife''s name Eve; because she was the mother of all living.'); +INSERT INTO t1(docid,words) VALUES(1003021,'Unto Adam also and to his wife did the LORD God make coats of skins, and clothed them.'); +INSERT INTO t1(docid,words) VALUES(1003022,'And the LORD God said, Behold, the man is become as one of us, to know good and evil: and now, lest he put forth his hand, and take also of the tree of life, and eat, and live for ever:'); +INSERT INTO t1(docid,words) VALUES(1003023,'Therefore the LORD God sent him forth from the garden of Eden, to till the ground from whence he was taken.'); +INSERT INTO t1(docid,words) VALUES(1003024,'So he drove out the man; and he placed at the east of the garden of Eden Cherubims, and a flaming sword which turned every way, to keep the way of the tree of life.'); +INSERT INTO t1(docid,words) VALUES(1004001,'And Adam knew Eve his wife; and she conceived, and bare Cain, and said, I have gotten a man from the LORD.'); +INSERT INTO t1(docid,words) VALUES(1004002,'And she again bare his brother Abel. And Abel was a keeper of sheep, but Cain was a tiller of the ground.'); +INSERT INTO t1(docid,words) VALUES(1004003,'And in process of time it came to pass, that Cain brought of the fruit of the ground an offering unto the LORD.'); +INSERT INTO t1(docid,words) VALUES(1004004,'And Abel, he also brought of the firstlings of his flock and of the fat thereof. And the LORD had respect unto Abel and to his offering:'); +INSERT INTO t1(docid,words) VALUES(1004005,'But unto Cain and to his offering he had not respect. And Cain was very wroth, and his countenance fell.'); +INSERT INTO t1(docid,words) VALUES(1004006,'And the LORD said unto Cain, Why art thou wroth? and why is thy countenance fallen?'); +INSERT INTO t1(docid,words) VALUES(1004007,'If thou doest well, shalt thou not be accepted? and if thou doest not well, sin lieth at the door. And unto thee shall be his desire, and thou shalt rule over him.'); +INSERT INTO t1(docid,words) VALUES(1004008,'And Cain talked with Abel his brother: and it came to pass, when they were in the field, that Cain rose up against Abel his brother, and slew him.'); +INSERT INTO t1(docid,words) VALUES(1004009,'And the LORD said unto Cain, Where is Abel thy brother? And he said, I know not: Am I my brother''s keeper?'); +INSERT INTO t1(docid,words) VALUES(1004010,'And he said, What hast thou done? the voice of thy brother''s blood crieth unto me from the ground.'); +INSERT INTO t1(docid,words) VALUES(1004011,'And now art thou cursed from the earth, which hath opened her mouth to receive thy brother''s blood from thy hand;'); +INSERT INTO t1(docid,words) VALUES(1004012,'When thou tillest the ground, it shall not henceforth yield unto thee her strength; a fugitive and a vagabond shalt thou be in the earth.'); +INSERT INTO t1(docid,words) VALUES(1004013,'And Cain said unto the LORD, My punishment is greater than I can bear.'); +INSERT INTO t1(docid,words) VALUES(1004014,'Behold, thou hast driven me out this day from the face of the earth; and from thy face shall I be hid; and I shall be a fugitive and a vagabond in the earth; and it shall come to pass, that every one that findeth me shall slay me.'); +INSERT INTO t1(docid,words) VALUES(1004015,'And the LORD said unto him, Therefore whosoever slayeth Cain, vengeance shall be taken on him sevenfold. And the LORD set a mark upon Cain, lest any finding him should kill him.'); +INSERT INTO t1(docid,words) VALUES(1004016,'And Cain went out from the presence of the LORD, and dwelt in the land of Nod, on the east of Eden.'); +INSERT INTO t1(docid,words) VALUES(1004017,'And Cain knew his wife; and she conceived, and bare Enoch: and he builded a city, and called the name of the city, after the name of his son, Enoch.'); +INSERT INTO t1(docid,words) VALUES(1004018,'And unto Enoch was born Irad: and Irad begat Mehujael: and Mehujael begat Methusael: and Methusael begat Lamech.'); +INSERT INTO t1(docid,words) VALUES(1004019,'And Lamech took unto him two wives: the name of the one was Adah, and the name of the other Zillah.'); +INSERT INTO t1(docid,words) VALUES(1004020,'And Adah bare Jabal: he was the father of such as dwell in tents, and of such as have cattle.'); +INSERT INTO t1(docid,words) VALUES(1004021,'And his brother''s name was Jubal: he was the father of all such as handle the harp and organ.'); +INSERT INTO t1(docid,words) VALUES(1004022,'And Zillah, she also bare Tubalcain, an instructer of every artificer in brass and iron: and the sister of Tubalcain was Naamah.'); +INSERT INTO t1(docid,words) VALUES(1004023,'And Lamech said unto his wives, Adah and Zillah, Hear my voice; ye wives of Lamech, hearken unto my speech: for I have slain a man to my wounding, and a young man to my hurt.'); +INSERT INTO t1(docid,words) VALUES(1004024,'If Cain shall be avenged sevenfold, truly Lamech seventy and sevenfold.'); +INSERT INTO t1(docid,words) VALUES(1004025,'And Adam knew his wife again; and she bare a son, and called his name Seth: For God, said she, hath appointed me another seed instead of Abel, whom Cain slew.'); +INSERT INTO t1(docid,words) VALUES(1004026,'And to Seth, to him also there was born a son; and he called his name Enos: then began men to call upon the name of the LORD.'); +INSERT INTO t1(docid,words) VALUES(1005001,'This is the book of the generations of Adam. In the day that God created man, in the likeness of God made he him;'); +INSERT INTO t1(docid,words) VALUES(1005002,'Male and female created he them; and blessed them, and called their name Adam, in the day when they were created.'); +INSERT INTO t1(docid,words) VALUES(1005003,'And Adam lived an hundred and thirty years, and begat a son in his own likeness, and after his image; and called his name Seth:'); +INSERT INTO t1(docid,words) VALUES(1005004,'And the days of Adam after he had begotten Seth were eight hundred years: and he begat sons and daughters:'); +INSERT INTO t1(docid,words) VALUES(1005005,'And all the days that Adam lived were nine hundred and thirty years: and he died.'); +INSERT INTO t1(docid,words) VALUES(1005006,'And Seth lived an hundred and five years, and begat Enos:'); +INSERT INTO t1(docid,words) VALUES(1005007,'And Seth lived after he begat Enos eight hundred and seven years, and begat sons and daughters:'); +INSERT INTO t1(docid,words) VALUES(1005008,'And all the days of Seth were nine hundred and twelve years: and he died.'); +INSERT INTO t1(docid,words) VALUES(1005009,'And Enos lived ninety years, and begat Cainan:'); +INSERT INTO t1(docid,words) VALUES(1005010,'And Enos lived after he begat Cainan eight hundred and fifteen years, and begat sons and daughters:'); +INSERT INTO t1(docid,words) VALUES(1005011,'And all the days of Enos were nine hundred and five years: and he died.'); +INSERT INTO t1(docid,words) VALUES(1005012,'And Cainan lived seventy years and begat Mahalaleel:'); +INSERT INTO t1(docid,words) VALUES(1005013,'And Cainan lived after he begat Mahalaleel eight hundred and forty years, and begat sons and daughters:'); +INSERT INTO t1(docid,words) VALUES(1005014,'And all the days of Cainan were nine hundred and ten years: and he died.'); +INSERT INTO t1(docid,words) VALUES(1005015,'And Mahalaleel lived sixty and five years, and begat Jared:'); +INSERT INTO t1(docid,words) VALUES(1005016,'And Mahalaleel lived after he begat Jared eight hundred and thirty years, and begat sons and daughters:'); +INSERT INTO t1(docid,words) VALUES(1005017,'And all the days of Mahalaleel were eight hundred ninety and five years: and he died.'); +INSERT INTO t1(docid,words) VALUES(1005018,'And Jared lived an hundred sixty and two years, and he begat Enoch:'); +INSERT INTO t1(docid,words) VALUES(1005019,'And Jared lived after he begat Enoch eight hundred years, and begat sons and daughters:'); +INSERT INTO t1(docid,words) VALUES(1005020,'And all the days of Jared were nine hundred sixty and two years: and he died.'); +INSERT INTO t1(docid,words) VALUES(1005021,'And Enoch lived sixty and five years, and begat Methuselah:'); +INSERT INTO t1(docid,words) VALUES(1005022,'And Enoch walked with God after he begat Methuselah three hundred years, and begat sons and daughters:'); +INSERT INTO t1(docid,words) VALUES(1005023,'And all the days of Enoch were three hundred sixty and five years:'); +INSERT INTO t1(docid,words) VALUES(1005024,'And Enoch walked with God: and he was not; for God took him.'); +INSERT INTO t1(docid,words) VALUES(1005025,'And Methuselah lived an hundred eighty and seven years, and begat Lamech.'); +INSERT INTO t1(docid,words) VALUES(1005026,'And Methuselah lived after he begat Lamech seven hundred eighty and two years, and begat sons and daughters:'); +INSERT INTO t1(docid,words) VALUES(1005027,'And all the days of Methuselah were nine hundred sixty and nine years: and he died.'); +INSERT INTO t1(docid,words) VALUES(1005028,'And Lamech lived an hundred eighty and two years, and begat a son:'); +INSERT INTO t1(docid,words) VALUES(1005029,'And he called his name Noah, saying, This same shall comfort us concerning our work and toil of our hands, because of the ground which the LORD hath cursed.'); +INSERT INTO t1(docid,words) VALUES(1005030,'And Lamech lived after he begat Noah five hundred ninety and five years, and begat sons and daughters:'); +INSERT INTO t1(docid,words) VALUES(1005031,'And all the days of Lamech were seven hundred seventy and seven years: and he died.'); +INSERT INTO t1(docid,words) VALUES(1005032,'And Noah was five hundred years old: and Noah begat Shem, Ham, and Japheth.'); +INSERT INTO t1(docid,words) VALUES(1006001,'And it came to pass, when men began to multiply on the face of the earth, and daughters were born unto them,'); +INSERT INTO t1(docid,words) VALUES(1006002,'That the sons of God saw the daughters of men that they were fair; and they took them wives of all which they chose.'); +INSERT INTO t1(docid,words) VALUES(1006003,'And the LORD said, My spirit shall not always strive with man, for that he also is flesh: yet his days shall be an hundred and twenty years.'); +INSERT INTO t1(docid,words) VALUES(1006004,'There were giants in the earth in those days; and also after that, when the sons of God came in unto the daughters of men, and they bare children to them, the same became mighty men which were of old, men of renown.'); +INSERT INTO t1(docid,words) VALUES(1006005,'And God saw that the wickedness of man was great in the earth, and that every imagination of the thoughts of his heart was only evil continually.'); +INSERT INTO t1(docid,words) VALUES(1006006,'And it repented the LORD that he had made man on the earth, and it grieved him at his heart.'); +INSERT INTO t1(docid,words) VALUES(1006007,'And the LORD said, I will destroy man whom I have created from the face of the earth; both man, and beast, and the creeping thing, and the fowls of the air; for it repenteth me that I have made them.'); +INSERT INTO t1(docid,words) VALUES(1006008,'But Noah found grace in the eyes of the LORD.'); +INSERT INTO t1(docid,words) VALUES(1006009,'These are the generations of Noah: Noah was a just man and perfect in his generations, and Noah walked with God.'); +INSERT INTO t1(docid,words) VALUES(1006010,'And Noah begat three sons, Shem, Ham, and Japheth.'); +INSERT INTO t1(docid,words) VALUES(1006011,'The earth also was corrupt before God, and the earth was filled with violence.'); +INSERT INTO t1(docid,words) VALUES(1006012,'And God looked upon the earth, and, behold, it was corrupt; for all flesh had corrupted his way upon the earth.'); +INSERT INTO t1(docid,words) VALUES(1006013,'And God said unto Noah, The end of all flesh is come before me; for the earth is filled with violence through them; and, behold, I will destroy them with the earth.'); +INSERT INTO t1(docid,words) VALUES(1006014,'Make thee an ark of gopher wood; rooms shalt thou make in the ark, and shalt pitch it within and without with pitch.'); +INSERT INTO t1(docid,words) VALUES(1006015,'And this is the fashion which thou shalt make it of: The length of the ark shall be three hundred cubits, the breadth of it fifty cubits, and the height of it thirty cubits.'); +INSERT INTO t1(docid,words) VALUES(1006016,'A window shalt thou make to the ark, and in a cubit shalt thou finish it above; and the door of the ark shalt thou set in the side thereof; with lower, second, and third stories shalt thou make it.'); +INSERT INTO t1(docid,words) VALUES(1006017,'And, behold, I, even I, do bring a flood of waters upon the earth, to destroy all flesh, wherein is the breath of life, from under heaven; and every thing that is in the earth shall die.'); +INSERT INTO t1(docid,words) VALUES(1006018,'But with thee will I establish my covenant; and thou shalt come into the ark, thou, and thy sons, and thy wife, and thy sons'' wives with thee.'); +INSERT INTO t1(docid,words) VALUES(1006019,'And of every living thing of all flesh, two of every sort shalt thou bring into the ark, to keep them alive with thee; they shall be male and female.'); +INSERT INTO t1(docid,words) VALUES(1006020,'Of fowls after their kind, and of cattle after their kind, of every creeping thing of the earth after his kind, two of every sort shall come unto thee, to keep them alive.'); +INSERT INTO t1(docid,words) VALUES(1006021,'And take thou unto thee of all food that is eaten, and thou shalt gather it to thee; and it shall be for food for thee, and for them.'); +INSERT INTO t1(docid,words) VALUES(1006022,'Thus did Noah; according to all that God commanded him, so did he.'); +INSERT INTO t1(docid,words) VALUES(1007001,'And the LORD said unto Noah, Come thou and all thy house into the ark; for thee have I seen righteous before me in this generation.'); +INSERT INTO t1(docid,words) VALUES(1007002,'Of every clean beast thou shalt take to thee by sevens, the male and his female: and of beasts that are not clean by two, the male and his female.'); +INSERT INTO t1(docid,words) VALUES(1007003,'Of fowls also of the air by sevens, the male and the female; to keep seed alive upon the face of all the earth.'); +INSERT INTO t1(docid,words) VALUES(1007004,'For yet seven days, and I will cause it to rain upon the earth forty days and forty nights; and every living substance that I have made will I destroy from off the face of the earth.'); +INSERT INTO t1(docid,words) VALUES(1007005,'And Noah did according unto all that the LORD commanded him.'); +INSERT INTO t1(docid,words) VALUES(1007006,'And Noah was six hundred years old when the flood of waters was upon the earth.'); +INSERT INTO t1(docid,words) VALUES(1007007,'And Noah went in, and his sons, and his wife, and his sons'' wives with him, into the ark, because of the waters of the flood.'); +INSERT INTO t1(docid,words) VALUES(1007008,'Of clean beasts, and of beasts that are not clean, and of fowls, and of every thing that creepeth upon the earth,'); +INSERT INTO t1(docid,words) VALUES(1007009,'There went in two and two unto Noah into the ark, the male and the female, as God had commanded Noah.'); +INSERT INTO t1(docid,words) VALUES(1007010,'And it came to pass after seven days, that the waters of the flood were upon the earth.'); +INSERT INTO t1(docid,words) VALUES(1007011,'In the six hundredth year of Noah''s life, in the second month, the seventeenth day of the month, the same day were all the fountains of the great deep broken up, and the windows of heaven were opened.'); +INSERT INTO t1(docid,words) VALUES(1007012,'And the rain was upon the earth forty days and forty nights.'); +INSERT INTO t1(docid,words) VALUES(1007013,'In the selfsame day entered Noah, and Shem, and Ham, and Japheth, the sons of Noah, and Noah''s wife, and the three wives of his sons with them, into the ark;'); +INSERT INTO t1(docid,words) VALUES(1007014,'They, and every beast after his kind, and all the cattle after their kind, and every creeping thing that creepeth upon the earth after his kind, and every fowl after his kind, every bird of every sort.'); +INSERT INTO t1(docid,words) VALUES(1007015,'And they went in unto Noah into the ark, two and two of all flesh, wherein is the breath of life.'); +INSERT INTO t1(docid,words) VALUES(1007016,'And they that went in, went in male and female of all flesh, as God had commanded him: and the LORD shut him in.'); +INSERT INTO t1(docid,words) VALUES(1007017,'And the flood was forty days upon the earth; and the waters increased, and bare up the ark, and it was lift up above the earth.'); +INSERT INTO t1(docid,words) VALUES(1007018,'And the waters prevailed, and were increased greatly upon the earth; and the ark went upon the face of the waters.'); +INSERT INTO t1(docid,words) VALUES(1007019,'And the waters prevailed exceedingly upon the earth; and all the high hills, that were under the whole heaven, were covered.'); +INSERT INTO t1(docid,words) VALUES(1007020,'Fifteen cubits upward did the waters prevail; and the mountains were covered.'); +INSERT INTO t1(docid,words) VALUES(1007021,'And all flesh died that moved upon the earth, both of fowl, and of cattle, and of beast, and of every creeping thing that creepeth upon the earth, and every man:'); +INSERT INTO t1(docid,words) VALUES(1007022,'All in whose nostrils was the breath of life, of all that was in the dry land, died.'); +INSERT INTO t1(docid,words) VALUES(1007023,'And every living substance was destroyed which was upon the face of the ground, both man, and cattle, and the creeping things, and the fowl of the heaven; and they were destroyed from the earth: and Noah only remained alive, and they that were with him in the ark.'); +INSERT INTO t1(docid,words) VALUES(1007024,'And the waters prevailed upon the earth an hundred and fifty days.'); +INSERT INTO t1(docid,words) VALUES(1008001,'And God remembered Noah, and every living thing, and all the cattle that was with him in the ark: and God made a wind to pass over the earth, and the waters asswaged;'); +INSERT INTO t1(docid,words) VALUES(1008002,'The fountains also of the deep and the windows of heaven were stopped, and the rain from heaven was restrained;'); +INSERT INTO t1(docid,words) VALUES(1008003,'And the waters returned from off the earth continually: and after the end of the hundred and fifty days the waters were abated.'); +INSERT INTO t1(docid,words) VALUES(1008004,'And the ark rested in the seventh month, on the seventeenth day of the month, upon the mountains of Ararat.'); +INSERT INTO t1(docid,words) VALUES(1008005,'And the waters decreased continually until the tenth month: in the tenth month, on the first day of the month, were the tops of the mountains seen.'); +INSERT INTO t1(docid,words) VALUES(1008006,'And it came to pass at the end of forty days, that Noah opened the window of the ark which he had made:'); +INSERT INTO t1(docid,words) VALUES(1008007,'And he sent forth a raven, which went forth to and fro, until the waters were dried up from off the earth.'); +INSERT INTO t1(docid,words) VALUES(1008008,'Also he sent forth a dove from him, to see if the waters were abated from off the face of the ground;'); +INSERT INTO t1(docid,words) VALUES(1008009,'But the dove found no rest for the sole of her foot, and she returned unto him into the ark, for the waters were on the face of the whole earth: then he put forth his hand, and took her, and pulled her in unto him into the ark.'); +INSERT INTO t1(docid,words) VALUES(1008010,'And he stayed yet other seven days; and again he sent forth the dove out of the ark;'); +INSERT INTO t1(docid,words) VALUES(1008011,'And the dove came in to him in the evening; and, lo, in her mouth was an olive leaf pluckt off: so Noah knew that the waters were abated from off the earth.'); +INSERT INTO t1(docid,words) VALUES(1008012,'And he stayed yet other seven days; and sent forth the dove; which returned not again unto him any more.'); +INSERT INTO t1(docid,words) VALUES(1008013,'And it came to pass in the six hundredth and first year, in the first month, the first day of the month, the waters were dried up from off the earth: and Noah removed the covering of the ark, and looked, and, behold, the face of the ground was dry.'); +INSERT INTO t1(docid,words) VALUES(1008014,'And in the second month, on the seven and twentieth day of the month, was the earth dried.'); +INSERT INTO t1(docid,words) VALUES(1008015,'And God spake unto Noah, saying,'); +INSERT INTO t1(docid,words) VALUES(1008016,'Go forth of the ark, thou, and thy wife, and thy sons, and thy sons'' wives with thee.'); +INSERT INTO t1(docid,words) VALUES(1008017,'Bring forth with thee every living thing that is with thee, of all flesh, both of fowl, and of cattle, and of every creeping thing that creepeth upon the earth; that they may breed abundantly in the earth, and be fruitful, and multiply upon the earth.'); +INSERT INTO t1(docid,words) VALUES(1008018,'And Noah went forth, and his sons, and his wife, and his sons'' wives with him:'); +INSERT INTO t1(docid,words) VALUES(1008019,'Every beast, every creeping thing, and every fowl, and whatsoever creepeth upon the earth, after their kinds, went forth out of the ark.'); +INSERT INTO t1(docid,words) VALUES(1008020,'And Noah builded an altar unto the LORD; and took of every clean beast, and of every clean fowl, and offered burnt offerings on the altar.'); +INSERT INTO t1(docid,words) VALUES(1008021,'And the LORD smelled a sweet savour; and the LORD said in his heart, I will not again curse the ground any more for man''s sake; for the imagination of man''s heart is evil from his youth; neither will I again smite any more every thing living, as I have done.'); +INSERT INTO t1(docid,words) VALUES(1008022,'While the earth remaineth, seedtime and harvest, and cold and heat, and summer and winter, and day and night shall not cease.'); +INSERT INTO t1(docid,words) VALUES(1009001,'And God blessed Noah and his sons, and said unto them, Be fruitful, and multiply, and replenish the earth.'); +INSERT INTO t1(docid,words) VALUES(1009002,'And the fear of you and the dread of you shall be upon every beast of the earth, and upon every fowl of the air, upon all that moveth upon the earth, and upon all the fishes of the sea; into your hand are they delivered.'); +INSERT INTO t1(docid,words) VALUES(1009003,'Every moving thing that liveth shall be meat for you; even as the green herb have I given you all things.'); +INSERT INTO t1(docid,words) VALUES(1009004,'But flesh with the life thereof, which is the blood thereof, shall ye not eat.'); +INSERT INTO t1(docid,words) VALUES(1009005,'And surely your blood of your lives will I require; at the hand of every beast will I require it, and at the hand of man; at the hand of every man''s brother will I require the life of man.'); +INSERT INTO t1(docid,words) VALUES(1009006,'Whoso sheddeth man''s blood, by man shall his blood be shed: for in the image of God made he man.'); +INSERT INTO t1(docid,words) VALUES(1009007,'And you, be ye fruitful, and multiply; bring forth abundantly in the earth, and multiply therein.'); +INSERT INTO t1(docid,words) VALUES(1009008,'And God spake unto Noah, and to his sons with him, saying,'); +INSERT INTO t1(docid,words) VALUES(1009009,'And I, behold, I establish my covenant with you, and with your seed after you;'); +INSERT INTO t1(docid,words) VALUES(1009010,'And with every living creature that is with you, of the fowl, of the cattle, and of every beast of the earth with you; from all that go out of the ark, to every beast of the earth.'); +INSERT INTO t1(docid,words) VALUES(1009011,'And I will establish my covenant with you, neither shall all flesh be cut off any more by the waters of a flood; neither shall there any more be a flood to destroy the earth.'); +INSERT INTO t1(docid,words) VALUES(1009012,'And God said, This is the token of the covenant which I make between me and you and every living creature that is with you, for perpetual generations:'); +INSERT INTO t1(docid,words) VALUES(1009013,'I do set my bow in the cloud, and it shall be for a token of a covenant between me and the earth.'); +INSERT INTO t1(docid,words) VALUES(1009014,'And it shall come to pass, when I bring a cloud over the earth, that the bow shall be seen in the cloud:'); +INSERT INTO t1(docid,words) VALUES(1009015,'And I will remember my covenant, which is between me and you and every living creature of all flesh; and the waters shall no more become a flood to destroy all flesh.'); +INSERT INTO t1(docid,words) VALUES(1009016,'And the bow shall be in the cloud; and I will look upon it, that I may remember the everlasting covenant between God and every living creature of all flesh that is upon the earth.'); +INSERT INTO t1(docid,words) VALUES(1009017,'And God said unto Noah, This is the token of the covenant, which I have established between me and all flesh that is upon the earth.'); +INSERT INTO t1(docid,words) VALUES(1009018,'And the sons of Noah, that went forth of the ark, were Shem, and Ham, and Japheth: and Ham is the father of Canaan.'); +INSERT INTO t1(docid,words) VALUES(1009019,'These are the three sons of Noah: and of them was the whole earth overspread.'); +INSERT INTO t1(docid,words) VALUES(1009020,'And Noah began to be an husbandman, and he planted a vineyard:'); +INSERT INTO t1(docid,words) VALUES(1009021,'And he drank of the wine, and was drunken; and he was uncovered within his tent.'); +INSERT INTO t1(docid,words) VALUES(1009022,'And Ham, the father of Canaan, saw the nakedness of his father, and told his two brethren without.'); +INSERT INTO t1(docid,words) VALUES(1009023,'And Shem and Japheth took a garment, and laid it upon both their shoulders, and went backward, and covered the nakedness of their father; and their faces were backward, and they saw not their father''s nakedness.'); +INSERT INTO t1(docid,words) VALUES(1009024,'And Noah awoke from his wine, and knew what his younger son had done unto him.'); +INSERT INTO t1(docid,words) VALUES(1009025,'And he said, Cursed be Canaan; a servant of servants shall he be unto his brethren.'); +INSERT INTO t1(docid,words) VALUES(1009026,'And he said, Blessed be the LORD God of Shem; and Canaan shall be his servant.'); +INSERT INTO t1(docid,words) VALUES(1009027,'God shall enlarge Japheth, and he shall dwell in the tents of Shem; and Canaan shall be his servant.'); +INSERT INTO t1(docid,words) VALUES(1009028,'And Noah lived after the flood three hundred and fifty years.'); +INSERT INTO t1(docid,words) VALUES(1009029,'And all the days of Noah were nine hundred and fifty years: and he died.'); +INSERT INTO t1(docid,words) VALUES(1010001,'Now these are the generations of the sons of Noah, Shem, Ham, and Japheth: and unto them were sons born after the flood.'); +INSERT INTO t1(docid,words) VALUES(1010002,'The sons of Japheth; Gomer, and Magog, and Madai, and Javan, and Tubal, and Meshech, and Tiras.'); +INSERT INTO t1(docid,words) VALUES(1010003,'And the sons of Gomer; Ashkenaz, and Riphath, and Togarmah.'); +INSERT INTO t1(docid,words) VALUES(1010004,'And the sons of Javan; Elishah, and Tarshish, Kittim, and Dodanim.'); +INSERT INTO t1(docid,words) VALUES(1010005,'By these were the isles of the Gentiles divided in their lands; every one after his tongue, after their families, in their nations.'); +INSERT INTO t1(docid,words) VALUES(1010006,'And the sons of Ham; Cush, and Mizraim, and Phut, and Canaan.'); +INSERT INTO t1(docid,words) VALUES(1010007,'And the sons of Cush; Seba, and Havilah, and Sabtah, and Raamah, and Sabtechah: and the sons of Raamah; Sheba, and Dedan.'); +INSERT INTO t1(docid,words) VALUES(1010008,'And Cush begat Nimrod: he began to be a mighty one in the earth.'); +INSERT INTO t1(docid,words) VALUES(1010009,'He was a mighty hunter before the LORD: wherefore it is said, Even as Nimrod the mighty hunter before the LORD.'); +INSERT INTO t1(docid,words) VALUES(1010010,'And the beginning of his kingdom was Babel, and Erech, and Accad, and Calneh, in the land of Shinar.'); +INSERT INTO t1(docid,words) VALUES(1010011,'Out of that land went forth Asshur, and builded Nineveh, and the city Rehoboth, and Calah,'); +INSERT INTO t1(docid,words) VALUES(1010012,'And Resen between Nineveh and Calah: the same is a great city.'); +INSERT INTO t1(docid,words) VALUES(1010013,'And Mizraim begat Ludim, and Anamim, and Lehabim, and Naphtuhim,'); +INSERT INTO t1(docid,words) VALUES(1010014,'And Pathrusim, and Casluhim, (out of whom came Philistim,) and Caphtorim.'); +INSERT INTO t1(docid,words) VALUES(1010015,'And Canaan begat Sidon his first born, and Heth,'); +INSERT INTO t1(docid,words) VALUES(1010016,'And the Jebusite, and the Amorite, and the Girgasite,'); +INSERT INTO t1(docid,words) VALUES(1010017,'And the Hivite, and the Arkite, and the Sinite,'); +INSERT INTO t1(docid,words) VALUES(1010018,'And the Arvadite, and the Zemarite, and the Hamathite: and afterward were the families of the Canaanites spread abroad.'); +INSERT INTO t1(docid,words) VALUES(1010019,'And the border of the Canaanites was from Sidon, as thou comest to Gerar, unto Gaza; as thou goest, unto Sodom, and Gomorrah, and Admah, and Zeboim, even unto Lasha.'); +INSERT INTO t1(docid,words) VALUES(1010020,'These are the sons of Ham, after their families, after their tongues, in their countries, and in their nations.'); +INSERT INTO t1(docid,words) VALUES(1010021,'Unto Shem also, the father of all the children of Eber, the brother of Japheth the elder, even to him were children born.'); +INSERT INTO t1(docid,words) VALUES(1010022,'The children of Shem; Elam, and Asshur, and Arphaxad, and Lud, and Aram.'); +INSERT INTO t1(docid,words) VALUES(1010023,'And the children of Aram; Uz, and Hul, and Gether, and Mash.'); +INSERT INTO t1(docid,words) VALUES(1010024,'And Arphaxad begat Salah; and Salah begat Eber.'); +INSERT INTO t1(docid,words) VALUES(1010025,'And unto Eber were born two sons: the name of one was Peleg; for in his days was the earth divided; and his brother''s name was Joktan.'); +INSERT INTO t1(docid,words) VALUES(1010026,'And Joktan begat Almodad, and Sheleph, and Hazarmaveth, and Jerah,'); +INSERT INTO t1(docid,words) VALUES(1010027,'And Hadoram, and Uzal, and Diklah,'); +INSERT INTO t1(docid,words) VALUES(1010028,'And Obal, and Abimael, and Sheba,'); +INSERT INTO t1(docid,words) VALUES(1010029,'And Ophir, and Havilah, and Jobab: all these were the sons of Joktan.'); +INSERT INTO t1(docid,words) VALUES(1010030,'And their dwelling was from Mesha, as thou goest unto Sephar a mount of the east.'); +INSERT INTO t1(docid,words) VALUES(1010031,'These are the sons of Shem, after their families, after their tongues, in their lands, after their nations.'); +INSERT INTO t1(docid,words) VALUES(1010032,'These are the families of the sons of Noah, after their generations, in their nations: and by these were the nations divided in the earth after the flood.'); +INSERT INTO t1(docid,words) VALUES(1011001,'And the whole earth was of one language, and of one speech.'); +INSERT INTO t1(docid,words) VALUES(1011002,'And it came to pass, as they journeyed from the east, that they found a plain in the land of Shinar; and they dwelt there.'); +INSERT INTO t1(docid,words) VALUES(1011003,'And they said one to another, Go to, let us make brick, and burn them thoroughly. And they had brick for stone, and slime had they for morter.'); +INSERT INTO t1(docid,words) VALUES(1011004,'And they said, Go to, let us build us a city and a tower, whose top may reach unto heaven; and let us make us a name, lest we be scattered abroad upon the face of the whole earth.'); +INSERT INTO t1(docid,words) VALUES(1011005,'And the LORD came down to see the city and the tower, which the children of men builded.'); +INSERT INTO t1(docid,words) VALUES(1011006,'And the LORD said, Behold, the people is one, and they have all one language; and this they begin to do: and now nothing will be restrained from them, which they have imagined to do.'); +INSERT INTO t1(docid,words) VALUES(1011007,'Go to, let us go down, and there confound their language, that they may not understand one another''s speech.'); +INSERT INTO t1(docid,words) VALUES(1011008,'So the LORD scattered them abroad from thence upon the face of all the earth: and they left off to build the city.'); +INSERT INTO t1(docid,words) VALUES(1011009,'Therefore is the name of it called Babel; because the LORD did there confound the language of all the earth: and from thence did the LORD scatter them abroad upon the face of all the earth.'); +INSERT INTO t1(docid,words) VALUES(1011010,'These are the generations of Shem: Shem was an hundred years old, and begat Arphaxad two years after the flood:'); +INSERT INTO t1(docid,words) VALUES(1011011,'And Shem lived after he begat Arphaxad five hundred years, and begat sons and daughters.'); +INSERT INTO t1(docid,words) VALUES(1011012,'And Arphaxad lived five and thirty years, and begat Salah:'); +INSERT INTO t1(docid,words) VALUES(1011013,'And Arphaxad lived after he begat Salah four hundred and three years, and begat sons and daughters.'); +INSERT INTO t1(docid,words) VALUES(1011014,'And Salah lived thirty years, and begat Eber:'); +INSERT INTO t1(docid,words) VALUES(1011015,'And Salah lived after he begat Eber four hundred and three years, and begat sons and daughters.'); +INSERT INTO t1(docid,words) VALUES(1011016,'And Eber lived four and thirty years, and begat Peleg:'); +INSERT INTO t1(docid,words) VALUES(1011017,'And Eber lived after he begat Peleg four hundred and thirty years, and begat sons and daughters.'); +INSERT INTO t1(docid,words) VALUES(1011018,'And Peleg lived thirty years, and begat Reu:'); +INSERT INTO t1(docid,words) VALUES(1011019,'And Peleg lived after he begat Reu two hundred and nine years, and begat sons and daughters.'); +INSERT INTO t1(docid,words) VALUES(1011020,'And Reu lived two and thirty years, and begat Serug:'); +INSERT INTO t1(docid,words) VALUES(1011021,'And Reu lived after he begat Serug two hundred and seven years, and begat sons and daughters.'); +INSERT INTO t1(docid,words) VALUES(1011022,'And Serug lived thirty years, and begat Nahor:'); +INSERT INTO t1(docid,words) VALUES(1011023,'And Serug lived after he begat Nahor two hundred years, and begat sons and daughters.'); +INSERT INTO t1(docid,words) VALUES(1011024,'And Nahor lived nine and twenty years, and begat Terah:'); +INSERT INTO t1(docid,words) VALUES(1011025,'And Nahor lived after he begat Terah an hundred and nineteen years, and begat sons and daughters.'); +INSERT INTO t1(docid,words) VALUES(1011026,'And Terah lived seventy years, and begat Abram, Nahor, and Haran.'); +INSERT INTO t1(docid,words) VALUES(1011027,'Now these are the generations of Terah: Terah begat Abram, Nahor, and Haran; and Haran begat Lot.'); +INSERT INTO t1(docid,words) VALUES(1011028,'And Haran died before his father Terah in the land of his nativity, in Ur of the Chaldees.'); +INSERT INTO t1(docid,words) VALUES(1011029,'And Abram and Nahor took them wives: the name of Abram''s wife was Sarai; and the name of Nahor''s wife, Milcah, the daughter of Haran, the father of Milcah, and the father of Iscah.'); +INSERT INTO t1(docid,words) VALUES(1011030,'But Sarai was barren; she had no child.'); +INSERT INTO t1(docid,words) VALUES(1011031,'And Terah took Abram his son, and Lot the son of Haran his son''s son, and Sarai his daughter in law, his son Abram''s wife; and they went forth with them from Ur of the Chaldees, to go into the land of Canaan; and they came unto Haran, and dwelt there.'); +INSERT INTO t1(docid,words) VALUES(1011032,'And the days of Terah were two hundred and five years: and Terah died in Haran.'); +INSERT INTO t1(docid,words) VALUES(1012001,'Now the LORD had said unto Abram, Get thee out of thy country, and from thy kindred, and from thy father''s house, unto a land that I will shew thee:'); +INSERT INTO t1(docid,words) VALUES(1012002,'And I will make of thee a great nation, and I will bless thee, and make thy name great; and thou shalt be a blessing:'); +INSERT INTO t1(docid,words) VALUES(1012003,'And I will bless them that bless thee, and curse him that curseth thee: and in thee shall all families of the earth be blessed.'); +INSERT INTO t1(docid,words) VALUES(1012004,'So Abram departed, as the LORD had spoken unto him; and Lot went with him: and Abram was seventy and five years old when he departed out of Haran.'); +INSERT INTO t1(docid,words) VALUES(1012005,'And Abram took Sarai his wife, and Lot his brother''s son, and all their substance that they had gathered, and the souls that they had gotten in Haran; and they went forth to go into the land of Canaan; and into the land of Canaan they came.'); +INSERT INTO t1(docid,words) VALUES(1012006,'And Abram passed through the land unto the place of Sichem, unto the plain of Moreh. And the Canaanite was then in the land.'); +INSERT INTO t1(docid,words) VALUES(1012007,'And the LORD appeared unto Abram, and said, Unto thy seed will I give this land: and there builded he an altar unto the LORD, who appeared unto him.'); +INSERT INTO t1(docid,words) VALUES(1012008,'And he removed from thence unto a mountain on the east of Bethel, and pitched his tent, having Bethel on the west, and Hai on the east: and there he builded an altar unto the LORD, and called upon the name of the LORD.'); +INSERT INTO t1(docid,words) VALUES(1012009,'And Abram journeyed, going on still toward the south.'); +INSERT INTO t1(docid,words) VALUES(1012010,'And there was a famine in the land: and Abram went down into Egypt to sojourn there; for the famine was grievous in the land.'); +INSERT INTO t1(docid,words) VALUES(1012011,'And it came to pass, when he was come near to enter into Egypt, that he said unto Sarai his wife, Behold now, I know that thou art a fair woman to look upon:'); +INSERT INTO t1(docid,words) VALUES(1012012,'Therefore it shall come to pass, when the Egyptians shall see thee, that they shall say, This is his wife: and they will kill me, but they will save thee alive.'); +INSERT INTO t1(docid,words) VALUES(1012013,'Say, I pray thee, thou art my sister: that it may be well with me for thy sake; and my soul shall live because of thee.'); +INSERT INTO t1(docid,words) VALUES(1012014,'And it came to pass, that, when Abram was come into Egypt, the Egyptians beheld the woman that she was very fair.'); +INSERT INTO t1(docid,words) VALUES(1012015,'The princes also of Pharaoh saw her, and commended her before Pharaoh: and the woman was taken into Pharaoh''s house.'); +INSERT INTO t1(docid,words) VALUES(1012016,'And he entreated Abram well for her sake: and he had sheep, and oxen, and he asses, and menservants, and maidservants, and she asses, and camels.'); +INSERT INTO t1(docid,words) VALUES(1012017,'And the LORD plagued Pharaoh and his house with great plagues because of Sarai Abram''s wife.'); +INSERT INTO t1(docid,words) VALUES(1012018,'And Pharaoh called Abram and said, What is this that thou hast done unto me? why didst thou not tell me that she was thy wife?'); +INSERT INTO t1(docid,words) VALUES(1012019,'Why saidst thou, She is my sister? so I might have taken her to me to wife: now therefore behold thy wife, take her, and go thy way.'); +INSERT INTO t1(docid,words) VALUES(1012020,'And Pharaoh commanded his men concerning him: and they sent him away, and his wife, and all that he had.'); +INSERT INTO t1(docid,words) VALUES(1013001,'And Abram went up out of Egypt, he, and his wife, and all that he had, and Lot with him, into the south.'); +INSERT INTO t1(docid,words) VALUES(1013002,'And Abram was very rich in cattle, in silver, and in gold.'); +INSERT INTO t1(docid,words) VALUES(1013003,'And he went on his journeys from the south even to Bethel, unto the place where his tent had been at the beginning, between Bethel and Hai;'); +INSERT INTO t1(docid,words) VALUES(1013004,'Unto the place of the altar, which he had make there at the first: and there Abram called on the name of the LORD.'); +INSERT INTO t1(docid,words) VALUES(1013005,'And Lot also, which went with Abram, had flocks, and herds, and tents.'); +INSERT INTO t1(docid,words) VALUES(1013006,'And the land was not able to bear them, that they might dwell together: for their substance was great, so that they could not dwell together.'); +INSERT INTO t1(docid,words) VALUES(1013007,'And there was a strife between the herdmen of Abram''s cattle and the herdmen of Lot''s cattle: and the Canaanite and the Perizzite dwelled then in the land.'); +INSERT INTO t1(docid,words) VALUES(1013008,'And Abram said unto Lot, Let there be no strife, I pray thee, between me and thee, and between my herdmen and thy herdmen; for we be brethren.'); +INSERT INTO t1(docid,words) VALUES(1013009,'Is not the whole land before thee? separate thyself, I pray thee, from me: if thou wilt take the left hand, then I will go to the right; or if thou depart to the right hand, then I will go to the left.'); +INSERT INTO t1(docid,words) VALUES(1013010,'And Lot lifted up his eyes, and beheld all the plain of Jordan, that it was well watered every where, before the LORD destroyed Sodom and Gomorrah, even as the garden of the LORD, like the land of Egypt, as thou comest unto Zoar.'); +INSERT INTO t1(docid,words) VALUES(1013011,'Then Lot chose him all the plain of Jordan; and Lot journeyed east: and they separated themselves the one from the other.'); +INSERT INTO t1(docid,words) VALUES(1013012,'Abram dwelled in the land of Canaan, and Lot dwelled in the cities of the plain, and pitched his tent toward Sodom.'); +INSERT INTO t1(docid,words) VALUES(1013013,'But the men of Sodom were wicked and sinners before the LORD exceedingly.'); +INSERT INTO t1(docid,words) VALUES(1013014,'And the LORD said unto Abram, after that Lot was separated from him, Lift up now thine eyes, and look from the place where thou art northward, and southward, and eastward, and westward:'); +INSERT INTO t1(docid,words) VALUES(1013015,'For all the land which thou seest, to thee will I give it, and to thy seed for ever.'); +INSERT INTO t1(docid,words) VALUES(1013016,'And I will make thy seed as the dust of the earth: so that if a man can number the dust of the earth, then shall thy seed also be numbered.'); +INSERT INTO t1(docid,words) VALUES(1013017,'Arise, walk through the land in the length of it and in the breadth of it; for I will give it unto thee.'); +INSERT INTO t1(docid,words) VALUES(1013018,'Then Abram removed his tent, and came and dwelt in the plain of Mamre, which is in Hebron, and built there an altar unto the LORD.'); +INSERT INTO t1(docid,words) VALUES(1014001,'And it came to pass in the days of Amraphel king of Shinar, Arioch king of Ellasar, Chedorlaomer king of Elam, and Tidal king of nations;'); +INSERT INTO t1(docid,words) VALUES(1014002,'That these made war with Bera king of Sodom, and with Birsha king of Gomorrah, Shinab king of Admah, and Shemeber king of Zeboiim, and the king of Bela, which is Zoar.'); +INSERT INTO t1(docid,words) VALUES(1014003,'All these were joined together in the vale of Siddim, which is the salt sea.'); +INSERT INTO t1(docid,words) VALUES(1014004,'Twelve years they served Chedorlaomer, and in the thirteenth year they rebelled.'); +INSERT INTO t1(docid,words) VALUES(1014005,'And in the fourteenth year came Chedorlaomer, and the kings that were with him, and smote the Rephaims in Ashteroth Karnaim, and the Zuzims in Ham, and the Emins in Shaveh Kiriathaim,'); +INSERT INTO t1(docid,words) VALUES(1014006,'And the Horites in their mount Seir, unto Elparan, which is by the wilderness.'); +INSERT INTO t1(docid,words) VALUES(1014007,'And they returned, and came to Enmishpat, which is Kadesh, and smote all the country of the Amalekites, and also the Amorites, that dwelt in Hazezontamar.'); +INSERT INTO t1(docid,words) VALUES(1014008,'And there went out the king of Sodom, and the king of Gomorrah, and the king of Admah, and the king of Zeboiim, and the king of Bela (the same is Zoar;) and they joined battle with them in the vale of Siddim;'); +INSERT INTO t1(docid,words) VALUES(1014009,'With Chedorlaomer the king of Elam, and with Tidal king of nations, and Amraphel king of Shinar, and Arioch king of Ellasar; four kings with five.'); +INSERT INTO t1(docid,words) VALUES(1014010,'And the vale of Siddim was full of slimepits; and the kings of Sodom and Gomorrah fled, and fell there; and they that remained fled to the mountain.'); +INSERT INTO t1(docid,words) VALUES(1014011,'And they took all the goods of Sodom and Gomorrah, and all their victuals, and went their way.'); +INSERT INTO t1(docid,words) VALUES(1014012,'And they took Lot, Abram''s brother''s son, who dwelt in Sodom, and his goods, and departed.'); +INSERT INTO t1(docid,words) VALUES(1014013,'And there came one that had escaped, and told Abram the Hebrew; for he dwelt in the plain of Mamre the Amorite, brother of Eshcol, and brother of Aner: and these were confederate with Abram.'); +INSERT INTO t1(docid,words) VALUES(1014014,'And when Abram heard that his brother was taken captive, he armed his trained servants, born in his own house, three hundred and eighteen, and pursued them unto Dan.'); +INSERT INTO t1(docid,words) VALUES(1014015,'And he divided himself against them, he and his servants, by night, and smote them, and pursued them unto Hobah, which is on the left hand of Damascus.'); +INSERT INTO t1(docid,words) VALUES(1014016,'And he brought back all the goods, and also brought again his brother Lot, and his goods, and the women also, and the people.'); +INSERT INTO t1(docid,words) VALUES(1014017,'And the king of Sodom went out to meet him after his return from the slaughter of Chedorlaomer, and of the kings that were with him, at the valley of Shaveh, which is the king''s dale.'); +INSERT INTO t1(docid,words) VALUES(1014018,'And Melchizedek king of Salem brought forth bread and wine: and he was the priest of the most high God.'); +INSERT INTO t1(docid,words) VALUES(1014019,'And he blessed him, and said, Blessed be Abram of the most high God, possessor of heaven and earth:'); +INSERT INTO t1(docid,words) VALUES(1014020,'And blessed be the most high God, which hath delivered thine enemies into thy hand. And he gave him tithes of all.'); +INSERT INTO t1(docid,words) VALUES(1014021,'And the king of Sodom said unto Abram, Give me the persons, and take the goods to thyself.'); +INSERT INTO t1(docid,words) VALUES(1014022,'And Abram said to the king of Sodom, I have lift up mine hand unto the LORD, the most high God, the possessor of heaven and earth,'); +INSERT INTO t1(docid,words) VALUES(1014023,'That I will not take from a thread even to a shoelatchet, and that I will not take any thing that is thine, lest thou shouldest say, I have made Abram rich:'); +INSERT INTO t1(docid,words) VALUES(1014024,'Save only that which the young men have eaten, and the portion of the men which went with me, Aner, Eshcol, and Mamre; let them take their portion.'); +INSERT INTO t1(docid,words) VALUES(1015001,'After these things the word of the LORD came unto Abram in a vision, saying, Fear not, Abram: I am thy shield, and thy exceeding great reward.'); +INSERT INTO t1(docid,words) VALUES(1015002,'And Abram said, LORD God, what wilt thou give me, seeing I go childless, and the steward of my house is this Eliezer of Damascus?'); +INSERT INTO t1(docid,words) VALUES(1015003,'And Abram said, Behold, to me thou hast given no seed: and, lo, one born in my house is mine heir.'); +INSERT INTO t1(docid,words) VALUES(1015004,'And, behold, the word of the LORD came unto him, saying, This shall not be thine heir; but he that shall come forth out of thine own bowels shall be thine heir.'); +INSERT INTO t1(docid,words) VALUES(1015005,'And he brought him forth abroad, and said, Look now toward heaven, and tell the stars, if thou be able to number them: and he said unto him, So shall thy seed be.'); +INSERT INTO t1(docid,words) VALUES(1015006,'And he believed in the LORD; and he counted it to him for righteousness.'); +INSERT INTO t1(docid,words) VALUES(1015007,'And he said unto him, I am the LORD that brought thee out of Ur of the Chaldees, to give thee this land to inherit it.'); +INSERT INTO t1(docid,words) VALUES(1015008,'And he said, LORD God, whereby shall I know that I shall inherit it?'); +INSERT INTO t1(docid,words) VALUES(1015009,'And he said unto him, Take me an heifer of three years old, and a she goat of three years old, and a ram of three years old, and a turtledove, and a young pigeon.'); +INSERT INTO t1(docid,words) VALUES(1015010,'And he took unto him all these, and divided them in the midst, and laid each piece one against another: but the birds divided he not.'); +INSERT INTO t1(docid,words) VALUES(1015011,'And when the fowls came down upon the carcases, Abram drove them away.'); +INSERT INTO t1(docid,words) VALUES(1015012,'And when the sun was going down, a deep sleep fell upon Abram; and, lo, an horror of great darkness fell upon him.'); +INSERT INTO t1(docid,words) VALUES(1015013,'And he said unto Abram, Know of a surety that thy seed shall be a stranger in a land that is not their''s, and shall serve them; and they shall afflict them four hundred years;'); +INSERT INTO t1(docid,words) VALUES(1015014,'And also that nation, whom they shall serve, will I judge: and afterward shall they come out with great substance.'); +INSERT INTO t1(docid,words) VALUES(1015015,'And thou shalt go to thy fathers in peace; thou shalt be buried in a good old age.'); +INSERT INTO t1(docid,words) VALUES(1015016,'But in the fourth generation they shall come hither again: for the iniquity of the Amorites is not yet full.'); +INSERT INTO t1(docid,words) VALUES(1015017,'And it came to pass, that, when the sun went down, and it was dark, behold a smoking furnace, and a burning lamp that passed between those pieces.'); +INSERT INTO t1(docid,words) VALUES(1015018,'In the same day the LORD made a covenant with Abram, saying, Unto thy seed have I given this land, from the river of Egypt unto the great river, the river Euphrates:'); +INSERT INTO t1(docid,words) VALUES(1015019,'The Kenites, and the Kenizzites, and the Kadmonites,'); +INSERT INTO t1(docid,words) VALUES(1015020,'And the Hittites, and the Perizzites, and the Rephaims,'); +INSERT INTO t1(docid,words) VALUES(1015021,'And the Amorites, and the Canaanites, and the Girgashites, and the Jebusites.'); +INSERT INTO t1(docid,words) VALUES(1016001,'Now Sarai Abram''s wife bare him no children: and she had an handmaid, an Egyptian, whose name was Hagar.'); +INSERT INTO t1(docid,words) VALUES(1016002,'And Sarai said unto Abram, Behold now, the LORD hath restrained me from bearing: I pray thee, go in unto my maid; it may be that I may obtain children by her. And Abram hearkened to the voice of Sarai.'); +INSERT INTO t1(docid,words) VALUES(1016003,'And Sarai Abram''s wife took Hagar her maid the Egyptian, after Abram had dwelt ten years in the land of Canaan, and gave her to her husband Abram to be his wife.'); +INSERT INTO t1(docid,words) VALUES(1016004,'And he went in unto Hagar, and she conceived: and when she saw that she had conceived, her mistress was despised in her eyes.'); +INSERT INTO t1(docid,words) VALUES(1016005,'And Sarai said unto Abram, My wrong be upon thee: I have given my maid into thy bosom; and when she saw that she had conceived, I was despised in her eyes: the LORD judge between me and thee.'); +INSERT INTO t1(docid,words) VALUES(1016006,'But Abram said unto Sarai, Behold, thy maid is in thine hand; do to her as it pleaseth thee. And when Sarai dealt hardly with her, she fled from her face.'); +INSERT INTO t1(docid,words) VALUES(1016007,'And the angel of the LORD found her by a fountain of water in the wilderness, by the fountain in the way to Shur.'); +INSERT INTO t1(docid,words) VALUES(1016008,'And he said, Hagar, Sarai''s maid, whence camest thou? and whither wilt thou go? And she said, I flee from the face of my mistress Sarai.'); +INSERT INTO t1(docid,words) VALUES(1016009,'And the angel of the LORD said unto her, Return to thy mistress, and submit thyself under her hands.'); +INSERT INTO t1(docid,words) VALUES(1016010,'And the angel of the LORD said unto her, I will multiply thy seed exceedingly, that it shall not be numbered for multitude.'); +INSERT INTO t1(docid,words) VALUES(1016011,'And the angel of the LORD said unto her, Behold, thou art with child and shalt bear a son, and shalt call his name Ishmael; because the LORD hath heard thy affliction.'); +INSERT INTO t1(docid,words) VALUES(1016012,'And he will be a wild man; his hand will be against every man, and every man''s hand against him; and he shall dwell in the presence of all his brethren.'); +INSERT INTO t1(docid,words) VALUES(1016013,'And she called the name of the LORD that spake unto her, Thou God seest me: for she said, Have I also here looked after him that seeth me?'); +INSERT INTO t1(docid,words) VALUES(1016014,'Wherefore the well was called Beerlahairoi; behold, it is between Kadesh and Bered.'); +INSERT INTO t1(docid,words) VALUES(1016015,'And Hagar bare Abram a son: and Abram called his son''s name, which Hagar bare, Ishmael.'); +INSERT INTO t1(docid,words) VALUES(1016016,'And Abram was fourscore and six years old, when Hagar bare Ishmael to Abram.'); +INSERT INTO t1(docid,words) VALUES(1017001,'And when Abram was ninety years old and nine, the LORD appeared to Abram, and said unto him, I am the Almighty God; walk before me, and be thou perfect.'); +INSERT INTO t1(docid,words) VALUES(1017002,'And I will make my covenant between me and thee, and will multiply thee exceedingly.'); +INSERT INTO t1(docid,words) VALUES(1017003,'And Abram fell on his face: and God talked with him, saying,'); +INSERT INTO t1(docid,words) VALUES(1017004,'As for me, behold, my covenant is with thee, and thou shalt be a father of many nations.'); +INSERT INTO t1(docid,words) VALUES(1017005,'Neither shall thy name any more be called Abram, but thy name shall be Abraham; for a father of many nations have I made thee.'); +INSERT INTO t1(docid,words) VALUES(1017006,'And I will make thee exceeding fruitful, and I will make nations of thee, and kings shall come out of thee.'); +INSERT INTO t1(docid,words) VALUES(1017007,'And I will establish my covenant between me and thee and thy seed after thee in their generations for an everlasting covenant, to be a God unto thee, and to thy seed after thee.'); +INSERT INTO t1(docid,words) VALUES(1017008,'And I will give unto thee, and to thy seed after thee, the land wherein thou art a stranger, all the land of Canaan, for an everlasting possession; and I will be their God.'); +INSERT INTO t1(docid,words) VALUES(1017009,'And God said unto Abraham, Thou shalt keep my covenant therefore, thou, and thy seed after thee in their generations.'); +INSERT INTO t1(docid,words) VALUES(1017010,'This is my covenant, which ye shall keep, between me and you and thy seed after thee; Every man child among you shall be circumcised.'); +INSERT INTO t1(docid,words) VALUES(1017011,'And ye shall circumcise the flesh of your foreskin; and it shall be a token of the covenant betwixt me and you.'); +INSERT INTO t1(docid,words) VALUES(1017012,'And he that is eight days old shall be circumcised among you, every man child in your generations, he that is born in the house, or bought with money of any stranger, which is not of thy seed.'); +INSERT INTO t1(docid,words) VALUES(1017013,'He that is born in thy house, and he that is bought with thy money, must needs be circumcised: and my covenant shall be in your flesh for an everlasting covenant.'); +INSERT INTO t1(docid,words) VALUES(1017014,'And the uncircumcised man child whose flesh of his foreskin is not circumcised, that soul shall be cut off from his people; he hath broken my covenant.'); +INSERT INTO t1(docid,words) VALUES(1017015,'And God said unto Abraham, As for Sarai thy wife, thou shalt not call her name Sarai, but Sarah shall her name be.'); +INSERT INTO t1(docid,words) VALUES(1017016,'And I will bless her, and give thee a son also of her: yea, I will bless her, and she shall be a mother of nations; kings of people shall be of her.'); +INSERT INTO t1(docid,words) VALUES(1017017,'Then Abraham fell upon his face, and laughed, and said in his heart, Shall a child be born unto him that is an hundred years old? and shall Sarah, that is ninety years old, bear?'); +INSERT INTO t1(docid,words) VALUES(1017018,'And Abraham said unto God, O that Ishmael might live before thee!'); +INSERT INTO t1(docid,words) VALUES(1017019,'And God said, Sarah thy wife shall bear thee a son indeed; and thou shalt call his name Isaac: and I will establish my covenant with him for an everlasting covenant, and with his seed after him.'); +INSERT INTO t1(docid,words) VALUES(1017020,'And as for Ishmael, I have heard thee: Behold, I have blessed him, and will make him fruitful, and will multiply him exceedingly; twelve princes shall he beget, and I will make him a great nation.'); +INSERT INTO t1(docid,words) VALUES(1017021,'But my covenant will I establish with Isaac, which Sarah shall bear unto thee at this set time in the next year.'); +INSERT INTO t1(docid,words) VALUES(1017022,'And he left off talking with him, and God went up from Abraham.'); +INSERT INTO t1(docid,words) VALUES(1017023,'And Abraham took Ishmael his son, and all that were born in his house, and all that were bought with his money, every male among the men of Abraham''s house; and circumcised the flesh of their foreskin in the selfsame day, as God had said unto him.'); +INSERT INTO t1(docid,words) VALUES(1017024,'And Abraham was ninety years old and nine, when he was circumcised in the flesh of his foreskin.'); +INSERT INTO t1(docid,words) VALUES(1017025,'And Ishmael his son was thirteen years old, when he was circumcised in the flesh of his foreskin.'); +INSERT INTO t1(docid,words) VALUES(1017026,'In the selfsame day was Abraham circumcised, and Ishmael his son.'); +INSERT INTO t1(docid,words) VALUES(1017027,'And all the men of his house, born in the house, and bought with money of the stranger, were circumcised with him.'); +INSERT INTO t1(docid,words) VALUES(1018001,'And the LORD appeared unto him in the plains of Mamre: and he sat in the tent door in the heat of the day;'); +INSERT INTO t1(docid,words) VALUES(1018002,'And he lift up his eyes and looked, and, lo, three men stood by him: and when he saw them, he ran to meet them from the tent door, and bowed himself toward the ground,'); +INSERT INTO t1(docid,words) VALUES(1018003,'And said, My LORD, if now I have found favour in thy sight, pass not away, I pray thee, from thy servant:'); +INSERT INTO t1(docid,words) VALUES(1018004,'Let a little water, I pray you, be fetched, and wash your feet, and rest yourselves under the tree:'); +INSERT INTO t1(docid,words) VALUES(1018005,'And I will fetch a morsel of bread, and comfort ye your hearts; after that ye shall pass on: for therefore are ye come to your servant. And they said, So do, as thou hast said.'); +INSERT INTO t1(docid,words) VALUES(1018006,'And Abraham hastened into the tent unto Sarah, and said, Make ready quickly three measures of fine meal, knead it, and make cakes upon the hearth.'); +INSERT INTO t1(docid,words) VALUES(1018007,'And Abraham ran unto the herd, and fetcht a calf tender and good, and gave it unto a young man; and he hasted to dress it.'); +INSERT INTO t1(docid,words) VALUES(1018008,'And he took butter, and milk, and the calf which he had dressed, and set it before them; and he stood by them under the tree, and they did eat.'); +INSERT INTO t1(docid,words) VALUES(1018009,'And they said unto him, Where is Sarah thy wife? And he said, Behold, in the tent.'); +INSERT INTO t1(docid,words) VALUES(1018010,'And he said, I will certainly return unto thee according to the time of life; and, lo, Sarah thy wife shall have a son. And Sarah heard it in the tent door, which was behind him.'); +INSERT INTO t1(docid,words) VALUES(1018011,'Now Abraham and Sarah were old and well stricken in age; and it ceased to be with Sarah after the manner of women.'); +INSERT INTO t1(docid,words) VALUES(1018012,'Therefore Sarah laughed within herself, saying, After I am waxed old shall I have pleasure, my lord being old also?'); +INSERT INTO t1(docid,words) VALUES(1018013,'And the LORD said unto Abraham, Wherefore did Sarah laugh, saying, Shall I of a surety bear a child, which am old?'); +INSERT INTO t1(docid,words) VALUES(1018014,'Is any thing too hard for the LORD? At the time appointed I will return unto thee, according to the time of life, and Sarah shall have a son.'); +INSERT INTO t1(docid,words) VALUES(1018015,'Then Sarah denied, saying, I laughed not; for she was afraid. And he said, Nay; but thou didst laugh.'); +INSERT INTO t1(docid,words) VALUES(1018016,'And the men rose up from thence, and looked toward Sodom: and Abraham went with them to bring them on the way.'); +INSERT INTO t1(docid,words) VALUES(1018017,'And the LORD said, Shall I hide from Abraham that thing which I do;'); +INSERT INTO t1(docid,words) VALUES(1018018,'Seeing that Abraham shall surely become a great and mighty nation, and all the nations of the earth shall be blessed in him?'); +INSERT INTO t1(docid,words) VALUES(1018019,'For I know him, that he will command his children and his household after him, and they shall keep the way of the LORD, to do justice and judgment; that the LORD may bring upon Abraham that which he hath spoken of him.'); +INSERT INTO t1(docid,words) VALUES(1018020,'And the LORD said, Because the cry of Sodom and Gomorrah is great, and because their sin is very grievous;'); +INSERT INTO t1(docid,words) VALUES(1018021,'I will go down now, and see whether they have done altogether according to the cry of it, which is come unto me; and if not, I will know.'); +INSERT INTO t1(docid,words) VALUES(1018022,'And the men turned their faces from thence, and went toward Sodom: but Abraham stood yet before the LORD.'); +INSERT INTO t1(docid,words) VALUES(1018023,'And Abraham drew near, and said, Wilt thou also destroy the righteous with the wicked?'); +INSERT INTO t1(docid,words) VALUES(1018024,'Peradventure there be fifty righteous within the city: wilt thou also destroy and not spare the place for the fifty righteous that are therein?'); +INSERT INTO t1(docid,words) VALUES(1018025,'That be far from thee to do after this manner, to slay the righteous with the wicked: and that the righteous should be as the wicked, that be far from thee: Shall not the Judge of all the earth do right?'); +INSERT INTO t1(docid,words) VALUES(1018026,'And the LORD said, If I find in Sodom fifty righteous within the city, then I will spare all the place for their sakes.'); +INSERT INTO t1(docid,words) VALUES(1018027,'And Abraham answered and said, Behold now, I have taken upon me to speak unto the LORD, which am but dust and ashes:'); +INSERT INTO t1(docid,words) VALUES(1018028,'Peradventure there shall lack five of the fifty righteous: wilt thou destroy all the city for lack of five? And he said, If I find there forty and five, I will not destroy it.'); +INSERT INTO t1(docid,words) VALUES(1018029,'And he spake unto him yet again, and said, Peradventure there shall be forty found there. And he said, I will not do it for forty''s sake.'); +INSERT INTO t1(docid,words) VALUES(1018030,'And he said unto him, Oh let not the LORD be angry, and I will speak: Peradventure there shall thirty be found there. And he said, I will not do it, if I find thirty there.'); +INSERT INTO t1(docid,words) VALUES(1018031,'And he said, Behold now, I have taken upon me to speak unto the LORD: Peradventure there shall be twenty found there. And he said, I will not destroy it for twenty''s sake.'); +INSERT INTO t1(docid,words) VALUES(1018032,'And he said, Oh let not the LORD be angry, and I will speak yet but this once: Peradventure ten shall be found there. And he said, I will not destroy it for ten''s sake.'); +INSERT INTO t1(docid,words) VALUES(1018033,'And the LORD went his way, as soon as he had left communing with Abraham: and Abraham returned unto his place.'); +INSERT INTO t1(docid,words) VALUES(1019001,'And there came two angels to Sodom at even; and Lot sat in the gate of Sodom: and Lot seeing them rose up to meet them; and he bowed himself with his face toward the ground;'); +INSERT INTO t1(docid,words) VALUES(1019002,'And he said, Behold now, my lords, turn in, I pray you, into your servant''s house, and tarry all night, and wash your feet, and ye shall rise up early, and go on your ways. And they said, Nay; but we will abide in the street all night.'); +INSERT INTO t1(docid,words) VALUES(1019003,'And he pressed upon them greatly; and they turned in unto him, and entered into his house; and he made them a feast, and did bake unleavened bread, and they did eat.'); +INSERT INTO t1(docid,words) VALUES(1019004,'But before they lay down, the men of the city, even the men of Sodom, compassed the house round, both old and young, all the people from every quarter:'); +INSERT INTO t1(docid,words) VALUES(1019005,'And they called unto Lot, and said unto him, Where are the men which came in to thee this night? bring them out unto us, that we may know them.'); +INSERT INTO t1(docid,words) VALUES(1019006,'And Lot went out at the door unto them, and shut the door after him,'); +INSERT INTO t1(docid,words) VALUES(1019007,'And said, I pray you, brethren, do not so wickedly.'); +INSERT INTO t1(docid,words) VALUES(1019008,'Behold now, I have two daughters which have not known man; let me, I pray you, bring them out unto you, and do ye to them as is good in your eyes: only unto these men do nothing; for therefore came they under the shadow of my roof.'); +INSERT INTO t1(docid,words) VALUES(1019009,'And they said, Stand back. And they said again, This one fellow came in to sojourn, and he will needs be a judge: now will we deal worse with thee, than with them. And they pressed sore upon the man, even Lot, and came near to break the door.'); +INSERT INTO t1(docid,words) VALUES(1019010,'But the men put forth their hand, and pulled Lot into the house to them, and shut to the door.'); +INSERT INTO t1(docid,words) VALUES(1019011,'And they smote the men that were at the door of the house with blindness, both small and great: so that they wearied themselves to find the door.'); +INSERT INTO t1(docid,words) VALUES(1019012,'And the men said unto Lot, Hast thou here any besides? son in law, and thy sons, and thy daughters, and whatsoever thou hast in the city, bring them out of this place:'); +INSERT INTO t1(docid,words) VALUES(1019013,'For we will destroy this place, because the cry of them is waxen great before the face of the LORD; and the LORD hath sent us to destroy it.'); +INSERT INTO t1(docid,words) VALUES(1019014,'And Lot went out, and spake unto his sons in law, which married his daughters, and said, Up, get you out of this place; for the LORD will destroy this city. But he seemed as one that mocked unto his sons in law.'); +INSERT INTO t1(docid,words) VALUES(1019015,'And when the morning arose, then the angels hastened Lot, saying, Arise, take thy wife, and thy two daughters, which are here; lest thou be consumed in the iniquity of the city.'); +INSERT INTO t1(docid,words) VALUES(1019016,'And while he lingered, the men laid hold upon his hand, and upon the hand of his wife, and upon the hand of his two daughters; the LORD being merciful unto him: and they brought him forth, and set him without the city.'); +INSERT INTO t1(docid,words) VALUES(1019017,'And it came to pass, when they had brought them forth abroad, that he said, Escape for thy life; look not behind thee, neither stay thou in all the plain; escape to the mountain, lest thou be consumed.'); +INSERT INTO t1(docid,words) VALUES(1019018,'And Lot said unto them, Oh, not so, my LORD:'); +INSERT INTO t1(docid,words) VALUES(1019019,'Behold now, thy servant hath found grace in thy sight, and thou hast magnified thy mercy, which thou hast shewed unto me in saving my life; and I cannot escape to the mountain, lest some evil take me, and I die:'); +INSERT INTO t1(docid,words) VALUES(1019020,'Behold now, this city is near to flee unto, and it is a little one: Oh, let me escape thither, (is it not a little one?) and my soul shall live.'); +INSERT INTO t1(docid,words) VALUES(1019021,'And he said unto him, See, I have accepted thee concerning this thing also, that I will not overthrow this city, for the which thou hast spoken.'); +INSERT INTO t1(docid,words) VALUES(1019022,'Haste thee, escape thither; for I cannot do anything till thou be come thither. Therefore the name of the city was called Zoar.'); +INSERT INTO t1(docid,words) VALUES(1019023,'The sun was risen upon the earth when Lot entered into Zoar.'); +INSERT INTO t1(docid,words) VALUES(1019024,'Then the LORD rained upon Sodom and upon Gomorrah brimstone and fire from the LORD out of heaven;'); +INSERT INTO t1(docid,words) VALUES(1019025,'And he overthrew those cities, and all the plain, and all the inhabitants of the cities, and that which grew upon the ground.'); +INSERT INTO t1(docid,words) VALUES(1019026,'But his wife looked back from behind him, and she became a pillar of salt.'); +INSERT INTO t1(docid,words) VALUES(1019027,'And Abraham gat up early in the morning to the place where he stood before the LORD:'); +INSERT INTO t1(docid,words) VALUES(1019028,'And he looked toward Sodom and Gomorrah, and toward all the land of the plain, and beheld, and, lo, the smoke of the country went up as the smoke of a furnace.'); +INSERT INTO t1(docid,words) VALUES(1019029,'And it came to pass, when God destroyed the cities of the plain, that God remembered Abraham, and sent Lot out of the midst of the overthrow, when he overthrew the cities in the which Lot dwelt.'); +INSERT INTO t1(docid,words) VALUES(1019030,'And Lot went up out of Zoar, and dwelt in the mountain, and his two daughters with him; for he feared to dwell in Zoar: and he dwelt in a cave, he and his two daughters.'); +INSERT INTO t1(docid,words) VALUES(1019031,'And the firstborn said unto the younger, Our father is old, and there is not a man in the earth to come in unto us after the manner of all the earth:'); +INSERT INTO t1(docid,words) VALUES(1019032,'Come, let us make our father drink wine, and we will lie with him, that we may preserve seed of our father.'); +INSERT INTO t1(docid,words) VALUES(1019033,'And they made their father drink wine that night: and the firstborn went in, and lay with her father; and he perceived not when she lay down, nor when she arose.'); +INSERT INTO t1(docid,words) VALUES(1019034,'And it came to pass on the morrow, that the firstborn said unto the younger, Behold, I lay yesternight with my father: let us make him drink wine this night also; and go thou in, and lie with him, that we may preserve seed of our father.'); +INSERT INTO t1(docid,words) VALUES(1019035,'And they made their father drink wine that night also: and the younger arose, and lay with him; and he perceived not when she lay down, nor when she arose.'); +INSERT INTO t1(docid,words) VALUES(1019036,'Thus were both the daughters of Lot with child by their father.'); +INSERT INTO t1(docid,words) VALUES(1019037,'And the first born bare a son, and called his name Moab: the same is the father of the Moabites unto this day.'); +INSERT INTO t1(docid,words) VALUES(1019038,'And the younger, she also bare a son, and called his name Benammi: the same is the father of the children of Ammon unto this day.'); +INSERT INTO t1(docid,words) VALUES(1020001,'And Abraham journeyed from thence toward the south country, and dwelled between Kadesh and Shur, and sojourned in Gerar.'); +INSERT INTO t1(docid,words) VALUES(1020002,'And Abraham said of Sarah his wife, She is my sister: and Abimelech king of Gerar sent, and took Sarah.'); +INSERT INTO t1(docid,words) VALUES(1020003,'But God came to Abimelech in a dream by night, and said to him, Behold, thou art but a dead man, for the woman which thou hast taken; for she is a man''s wife.'); +INSERT INTO t1(docid,words) VALUES(1020004,'But Abimelech had not come near her: and he said, LORD, wilt thou slay also a righteous nation?'); +INSERT INTO t1(docid,words) VALUES(1020005,'Said he not unto me, She is my sister? and she, even she herself said, He is my brother: in the integrity of my heart and innocency of my hands have I done this.'); +INSERT INTO t1(docid,words) VALUES(1020006,'And God said unto him in a dream, Yea, I know that thou didst this in the integrity of thy heart; for I also withheld thee from sinning against me: therefore suffered I thee not to touch her.'); +INSERT INTO t1(docid,words) VALUES(1020007,'Now therefore restore the man his wife; for he is a prophet, and he shall pray for thee, and thou shalt live: and if thou restore her not, know thou that thou shalt surely die, thou, and all that are thine.'); +INSERT INTO t1(docid,words) VALUES(1020008,'Therefore Abimelech rose early in the morning, and called all his servants, and told all these things in their ears: and the men were sore afraid.'); +INSERT INTO t1(docid,words) VALUES(1020009,'Then Abimelech called Abraham, and said unto him, What hast thou done unto us? and what have I offended thee, that thou hast brought on me and on my kingdom a great sin? thou hast done deeds unto me that ought not to be done.'); +INSERT INTO t1(docid,words) VALUES(1020010,'And Abimelech said unto Abraham, What sawest thou, that thou hast done this thing?'); +INSERT INTO t1(docid,words) VALUES(1020011,'And Abraham said, Because I thought, Surely the fear of God is not in this place; and they will slay me for my wife''s sake.'); +INSERT INTO t1(docid,words) VALUES(1020012,'And yet indeed she is my sister; she is the daughter of my father, but not the daughter of my mother; and she became my wife.'); +INSERT INTO t1(docid,words) VALUES(1020013,'And it came to pass, when God caused me to wander from my father''s house, that I said unto her, This is thy kindness which thou shalt shew unto me; at every place whither we shall come, say of me, He is my brother.'); +INSERT INTO t1(docid,words) VALUES(1020014,'And Abimelech took sheep, and oxen, and menservants, and womenservants, and gave them unto Abraham, and restored him Sarah his wife.'); +INSERT INTO t1(docid,words) VALUES(1020015,'And Abimelech said, Behold, my land is before thee: dwell where it pleaseth thee.'); +INSERT INTO t1(docid,words) VALUES(1020016,'And unto Sarah he said, Behold, I have given thy brother a thousand pieces of silver: behold, he is to thee a covering of the eyes, unto all that are with thee, and with all other: thus she was reproved.'); +INSERT INTO t1(docid,words) VALUES(1020017,'So Abraham prayed unto God: and God healed Abimelech, and his wife, and his maidservants; and they bare children.'); +INSERT INTO t1(docid,words) VALUES(1020018,'For the LORD had fast closed up all the wombs of the house of Abimelech, because of Sarah Abraham''s wife.'); +INSERT INTO t1(docid,words) VALUES(1021001,'And the LORD visited Sarah as he had said, and the LORD did unto Sarah as he had spoken.'); +INSERT INTO t1(docid,words) VALUES(1021002,'For Sarah conceived, and bare Abraham a son in his old age, at the set time of which God had spoken to him.'); +INSERT INTO t1(docid,words) VALUES(1021003,'And Abraham called the name of his son that was born unto him, whom Sarah bare to him, Isaac.'); +INSERT INTO t1(docid,words) VALUES(1021004,'And Abraham circumcised his son Isaac being eight days old, as God had commanded him.'); +INSERT INTO t1(docid,words) VALUES(1021005,'And Abraham was an hundred years old, when his son Isaac was born unto him.'); +INSERT INTO t1(docid,words) VALUES(1021006,'And Sarah said, God hath made me to laugh, so that all that hear will laugh with me.'); +INSERT INTO t1(docid,words) VALUES(1021007,'And she said, Who would have said unto Abraham, that Sarah should have given children suck? for I have born him a son in his old age.'); +INSERT INTO t1(docid,words) VALUES(1021008,'And the child grew, and was weaned: and Abraham made a great feast the same day that Isaac was weaned.'); +INSERT INTO t1(docid,words) VALUES(1021009,'And Sarah saw the son of Hagar the Egyptian, which she had born unto Abraham, mocking.'); +INSERT INTO t1(docid,words) VALUES(1021010,'Wherefore she said unto Abraham, Cast out this bondwoman and her son: for the son of this bondwoman shall not be heir with my son, even with Isaac.'); +INSERT INTO t1(docid,words) VALUES(1021011,'And the thing was very grievous in Abraham''s sight because of his son.'); +INSERT INTO t1(docid,words) VALUES(1021012,'And God said unto Abraham, Let it not be grievous in thy sight because of the lad, and because of thy bondwoman; in all that Sarah hath said unto thee, hearken unto her voice; for in Isaac shall thy seed be called.'); +INSERT INTO t1(docid,words) VALUES(1021013,'And also of the son of the bondwoman will I make a nation, because he is thy seed.'); +INSERT INTO t1(docid,words) VALUES(1021014,'And Abraham rose up early in the morning, and took bread, and a bottle of water, and gave it unto Hagar, putting it on her shoulder, and the child, and sent her away: and she departed, and wandered in the wilderness of Beersheba.'); +INSERT INTO t1(docid,words) VALUES(1021015,'And the water was spent in the bottle, and she cast the child under one of the shrubs.'); +INSERT INTO t1(docid,words) VALUES(1021016,'And she went, and sat her down over against him a good way off, as it were a bow shot: for she said, Let me not see the death of the child. And she sat over against him, and lift up her voice, and wept.'); +INSERT INTO t1(docid,words) VALUES(1021017,'And God heard the voice of the lad; and the angel of God called to Hagar out of heaven, and said unto her, What aileth thee, Hagar? fear not; for God hath heard the voice of the lad where he is.'); +INSERT INTO t1(docid,words) VALUES(1021018,'Arise, lift up the lad, and hold him in thine hand; for I will make him a great nation.'); +INSERT INTO t1(docid,words) VALUES(1021019,'And God opened her eyes, and she saw a well of water; and she went, and filled the bottle with water, and gave the lad drink.'); +INSERT INTO t1(docid,words) VALUES(1021020,'And God was with the lad; and he grew, and dwelt in the wilderness, and became an archer.'); +INSERT INTO t1(docid,words) VALUES(1021021,'And he dwelt in the wilderness of Paran: and his mother took him a wife out of the land of Egypt.'); +INSERT INTO t1(docid,words) VALUES(1021022,'And it came to pass at that time, that Abimelech and Phichol the chief captain of his host spake unto Abraham, saying, God is with thee in all that thou doest:'); +INSERT INTO t1(docid,words) VALUES(1021023,'Now therefore swear unto me here by God that thou wilt not deal falsely with me, nor with my son, nor with my son''s son: but according to the kindness that I have done unto thee, thou shalt do unto me, and to the land wherein thou hast sojourned.'); +INSERT INTO t1(docid,words) VALUES(1021024,'And Abraham said, I will swear.'); +INSERT INTO t1(docid,words) VALUES(1021025,'And Abraham reproved Abimelech because of a well of water, which Abimelech''s servants had violently taken away.'); +INSERT INTO t1(docid,words) VALUES(1021026,'And Abimelech said, I wot not who hath done this thing; neither didst thou tell me, neither yet heard I of it, but to day.'); +INSERT INTO t1(docid,words) VALUES(1021027,'And Abraham took sheep and oxen, and gave them unto Abimelech; and both of them made a covenant.'); +INSERT INTO t1(docid,words) VALUES(1021028,'And Abraham set seven ewe lambs of the flock by themselves.'); +INSERT INTO t1(docid,words) VALUES(1021029,'And Abimelech said unto Abraham, What mean these seven ewe lambs which thou hast set by themselves?'); +INSERT INTO t1(docid,words) VALUES(1021030,'And he said, For these seven ewe lambs shalt thou take of my hand, that they may be a witness unto me, that I have digged this well.'); +INSERT INTO t1(docid,words) VALUES(1021031,'Wherefore he called that place Beersheba; because there they sware both of them.'); +INSERT INTO t1(docid,words) VALUES(1021032,'Thus they made a covenant at Beersheba: then Abimelech rose up, and Phichol the chief captain of his host, and they returned into the land of the Philistines.'); +INSERT INTO t1(docid,words) VALUES(1021033,'And Abraham planted a grove in Beersheba, and called there on the name of the LORD, the everlasting God.'); +INSERT INTO t1(docid,words) VALUES(1021034,'And Abraham sojourned in the Philistines'' land many days.'); +INSERT INTO t1(docid,words) VALUES(1022001,'And it came to pass after these things, that God did tempt Abraham, and said unto him, Abraham: and he said, Behold, here I am.'); +INSERT INTO t1(docid,words) VALUES(1022002,'And he said, Take now thy son, thine only son Isaac, whom thou lovest, and get thee into the land of Moriah; and offer him there for a burnt offering upon one of the mountains which I will tell thee of.'); +INSERT INTO t1(docid,words) VALUES(1022003,'And Abraham rose up early in the morning, and saddled his ass, and took two of his young men with him, and Isaac his son, and clave the wood for the burnt offering, and rose up, and went unto the place of which God had told him.'); +INSERT INTO t1(docid,words) VALUES(1022004,'Then on the third day Abraham lifted up his eyes, and saw the place afar off.'); +INSERT INTO t1(docid,words) VALUES(1022005,'And Abraham said unto his young men, Abide ye here with the ass; and I and the lad will go yonder and worship, and come again to you.'); +INSERT INTO t1(docid,words) VALUES(1022006,'And Abraham took the wood of the burnt offering, and laid it upon Isaac his son; and he took the fire in his hand, and a knife; and they went both of them together.'); +INSERT INTO t1(docid,words) VALUES(1022007,'And Isaac spake unto Abraham his father, and said, My father: and he said, Here am I, my son. And he said, Behold the fire and the wood: but where is the lamb for a burnt offering?'); +INSERT INTO t1(docid,words) VALUES(1022008,'And Abraham said, My son, God will provide himself a lamb for a burnt offering: so they went both of them together.'); +INSERT INTO t1(docid,words) VALUES(1022009,'And they came to the place which God had told him of; and Abraham built an altar there, and laid the wood in order, and bound Isaac his son, and laid him on the altar upon the wood.'); +INSERT INTO t1(docid,words) VALUES(1022010,'And Abraham stretched forth his hand, and took the knife to slay his son.'); +INSERT INTO t1(docid,words) VALUES(1022011,'And the angel of the LORD called unto him out of heaven, and said, Abraham, Abraham: and he said, Here am I.'); +INSERT INTO t1(docid,words) VALUES(1022012,'And he said, Lay not thine hand upon the lad, neither do thou any thing unto him: for now I know that thou fearest God, seeing thou hast not withheld thy son, thine only son from me.'); +INSERT INTO t1(docid,words) VALUES(1022013,'And Abraham lifted up his eyes, and looked, and behold behind him a ram caught in a thicket by his horns: and Abraham went and took the ram, and offered him up for a burnt offering in the stead of his son.'); +INSERT INTO t1(docid,words) VALUES(1022014,'And Abraham called the name of that place Jehovahjireh: as it is said to this day, In the mount of the LORD it shall be seen.'); +INSERT INTO t1(docid,words) VALUES(1022015,'And the angel of the LORD called unto Abraham out of heaven the second time,'); +INSERT INTO t1(docid,words) VALUES(1022016,'And said, By myself have I sworn, saith the LORD, for because thou hast done this thing, and hast not withheld thy son, thine only son:'); +INSERT INTO t1(docid,words) VALUES(1022017,'That in blessing I will bless thee, and in multiplying I will multiply thy seed as the stars of the heaven, and as the sand which is upon the sea shore; and thy seed shall possess the gate of his enemies;'); +INSERT INTO t1(docid,words) VALUES(1022018,'And in thy seed shall all the nations of the earth be blessed; because thou hast obeyed my voice.'); +INSERT INTO t1(docid,words) VALUES(1022019,'So Abraham returned unto his young men, and they rose up and went together to Beersheba; and Abraham dwelt at Beersheba.'); +INSERT INTO t1(docid,words) VALUES(1022020,'And it came to pass after these things, that it was told Abraham, saying, Behold, Milcah, she hath also born children unto thy brother Nahor;'); +INSERT INTO t1(docid,words) VALUES(1022021,'Huz his firstborn, and Buz his brother, and Kemuel the father of Aram,'); +INSERT INTO t1(docid,words) VALUES(1022022,'And Chesed, and Hazo, and Pildash, and Jidlaph, and Bethuel.'); +INSERT INTO t1(docid,words) VALUES(1022023,'And Bethuel begat Rebekah: these eight Milcah did bear to Nahor, Abraham''s brother.'); +INSERT INTO t1(docid,words) VALUES(1022024,'And his concubine, whose name was Reumah, she bare also Tebah, and Gaham, and Thahash, and Maachah.'); +INSERT INTO t1(docid,words) VALUES(1023001,'And Sarah was an hundred and seven and twenty years old: these were the years of the life of Sarah.'); +INSERT INTO t1(docid,words) VALUES(1023002,'And Sarah died in Kirjatharba; the same is Hebron in the land of Canaan: and Abraham came to mourn for Sarah, and to weep for her.'); +INSERT INTO t1(docid,words) VALUES(1023003,'And Abraham stood up from before his dead, and spake unto the sons of Heth, saying,'); +INSERT INTO t1(docid,words) VALUES(1023004,'I am a stranger and a sojourner with you: give me a possession of a buryingplace with you, that I may bury my dead out of my sight.'); +INSERT INTO t1(docid,words) VALUES(1023005,'And the children of Heth answered Abraham, saying unto him,'); +INSERT INTO t1(docid,words) VALUES(1023006,'Hear us, my lord: thou art a mighty prince among us: in the choice of our sepulchres bury thy dead; none of us shall withhold from thee his sepulchre, but that thou mayest bury thy dead.'); +INSERT INTO t1(docid,words) VALUES(1023007,'And Abraham stood up, and bowed himself to the people of the land, even to the children of Heth.'); +INSERT INTO t1(docid,words) VALUES(1023008,'And he communed with them, saying, If it be your mind that I should bury my dead out of my sight; hear me, and intreat for me to Ephron the son of Zohar,'); +INSERT INTO t1(docid,words) VALUES(1023009,'That he may give me the cave of Machpelah, which he hath, which is in the end of his field; for as much money as it is worth he shall give it me for a possession of a buryingplace amongst you.'); +INSERT INTO t1(docid,words) VALUES(1023010,'And Ephron dwelt among the children of Heth: and Ephron the Hittite answered Abraham in the audience of the children of Heth, even of all that went in at the gate of his city, saying,'); +INSERT INTO t1(docid,words) VALUES(1023011,'Nay, my lord, hear me: the field give I thee, and the cave that is therein, I give it thee; in the presence of the sons of my people give I it thee: bury thy dead.'); +INSERT INTO t1(docid,words) VALUES(1023012,'And Abraham bowed down himself before the people of the land.'); +INSERT INTO t1(docid,words) VALUES(1023013,'And he spake unto Ephron in the audience of the people of the land, saying, But if thou wilt give it, I pray thee, hear me: I will give thee money for the field; take it of me, and I will bury my dead there.'); +INSERT INTO t1(docid,words) VALUES(1023014,'And Ephron answered Abraham, saying unto him,'); +INSERT INTO t1(docid,words) VALUES(1023015,'My lord, hearken unto me: the land is worth four hundred shekels of silver; what is that betwixt me and thee? bury therefore thy dead.'); +INSERT INTO t1(docid,words) VALUES(1023016,'And Abraham hearkened unto Ephron; and Abraham weighed to Ephron the silver, which he had named in the audience of the sons of Heth, four hundred shekels of silver, current money with the merchant.'); +INSERT INTO t1(docid,words) VALUES(1023017,'And the field of Ephron which was in Machpelah, which was before Mamre, the field, and the cave which was therein, and all the trees that were in the field, that were in all the borders round about, were made sure'); +INSERT INTO t1(docid,words) VALUES(1023018,'Unto Abraham for a possession in the presence of the children of Heth, before all that went in at the gate of his city.'); +INSERT INTO t1(docid,words) VALUES(1023019,'And after this, Abraham buried Sarah his wife in the cave of the field of Machpelah before Mamre: the same is Hebron in the land of Canaan.'); +INSERT INTO t1(docid,words) VALUES(1023020,'And the field, and the cave that is therein, were made sure unto Abraham for a possession of a buryingplace by the sons of Heth.'); +INSERT INTO t1(docid,words) VALUES(1024001,'And Abraham was old, and well stricken in age: and the LORD had blessed Abraham in all things.'); +INSERT INTO t1(docid,words) VALUES(1024002,'And Abraham said unto his eldest servant of his house, that ruled over all that he had, Put, I pray thee, thy hand under my thigh:'); +INSERT INTO t1(docid,words) VALUES(1024003,'And I will make thee swear by the LORD, the God of heaven, and the God of the earth, that thou shalt not take a wife unto my son of the daughters of the Canaanites, among whom I dwell:'); +INSERT INTO t1(docid,words) VALUES(1024004,'But thou shalt go unto my country, and to my kindred, and take a wife unto my son Isaac.'); +INSERT INTO t1(docid,words) VALUES(1024005,'And the servant said unto him, Peradventure the woman will not be willing to follow me unto this land: must I needs bring thy son again unto the land from whence thou camest?'); +INSERT INTO t1(docid,words) VALUES(1024006,'And Abraham said unto him, Beware thou that thou bring not my son thither again.'); +INSERT INTO t1(docid,words) VALUES(1024007,'The LORD God of heaven, which took me from my father''s house, and from the land of my kindred, and which spake unto me, and that sware unto me, saying, Unto thy seed will I give this land; he shall send his angel before thee, and thou shalt take a wife unto my son from thence.'); +INSERT INTO t1(docid,words) VALUES(1024008,'And if the woman will not be willing to follow thee, then thou shalt be clear from this my oath: only bring not my son thither again.'); +INSERT INTO t1(docid,words) VALUES(1024009,'And the servant put his hand under the thigh of Abraham his master, and sware to him concerning that matter.'); +INSERT INTO t1(docid,words) VALUES(1024010,'And the servant took ten camels of the camels of his master, and departed; for all the goods of his master were in his hand: and he arose, and went to Mesopotamia, unto the city of Nahor.'); +INSERT INTO t1(docid,words) VALUES(1024011,'And he made his camels to kneel down without the city by a well of water at the time of the evening, even the time that women go out to draw water.'); +INSERT INTO t1(docid,words) VALUES(1024012,'And he said O LORD God of my master Abraham, I pray thee, send me good speed this day, and shew kindness unto my master Abraham.'); +INSERT INTO t1(docid,words) VALUES(1024013,'Behold, I stand here by the well of water; and the daughters of the men of the city come out to draw water:'); +INSERT INTO t1(docid,words) VALUES(1024014,'And let it come to pass, that the damsel to whom I shall say, Let down thy pitcher, I pray thee, that I may drink; and she shall say, Drink, and I will give thy camels drink also: let the same be she that thou hast appointed for thy servant Isaac; and thereby shall I know that thou hast shewed kindness unto my master.'); +INSERT INTO t1(docid,words) VALUES(1024015,'And it came to pass, before he had done speaking, that, behold, Rebekah came out, who was born to Bethuel, son of Milcah, the wife of Nahor, Abraham''s brother, with her pitcher upon her shoulder.'); +INSERT INTO t1(docid,words) VALUES(1024016,'And the damsel was very fair to look upon, a virgin, neither had any man known her: and she went down to the well, and filled her pitcher, and came up.'); +INSERT INTO t1(docid,words) VALUES(1024017,'And the servant ran to meet her, and said, Let me, I pray thee, drink a little water of thy pitcher.'); +INSERT INTO t1(docid,words) VALUES(1024018,'And she said, Drink, my lord: and she hasted, and let down her pitcher upon her hand, and gave him drink.'); +INSERT INTO t1(docid,words) VALUES(1024019,'And when she had done giving him drink, she said, I will draw water for thy camels also, until they have done drinking.'); +INSERT INTO t1(docid,words) VALUES(1024020,'And she hasted, and emptied her pitcher into the trough, and ran again unto the well to draw water, and drew for all his camels.'); +INSERT INTO t1(docid,words) VALUES(1024021,'And the man wondering at her held his peace, to wit whether the LORD had made his journey prosperous or not.'); +INSERT INTO t1(docid,words) VALUES(1024022,'And it came to pass, as the camels had done drinking, that the man took a golden earring of half a shekel weight, and two bracelets for her hands of ten shekels weight of gold;'); +INSERT INTO t1(docid,words) VALUES(1024023,'And said, Whose daughter art thou? tell me, I pray thee: is there room in thy father''s house for us to lodge in?'); +INSERT INTO t1(docid,words) VALUES(1024024,'And she said unto him, I am the daughter of Bethuel the son of Milcah, which she bare unto Nahor.'); +INSERT INTO t1(docid,words) VALUES(1024025,'She said moreover unto him, We have both straw and provender enough, and room to lodge in.'); +INSERT INTO t1(docid,words) VALUES(1024026,'And the man bowed down his head, and worshipped the LORD.'); +INSERT INTO t1(docid,words) VALUES(1024027,'And he said, Blessed be the LORD God of my master Abraham, who hath not left destitute my master of his mercy and his truth: I being in the way, the LORD led me to the house of my master''s brethren.'); +INSERT INTO t1(docid,words) VALUES(1024028,'And the damsel ran, and told them of her mother''s house these things.'); +INSERT INTO t1(docid,words) VALUES(1024029,'And Rebekah had a brother, and his name was Laban: and Laban ran out unto the man, unto the well.'); +INSERT INTO t1(docid,words) VALUES(1024030,'And it came to pass, when he saw the earring and bracelets upon his sister''s hands, and when he heard the words of Rebekah his sister, saying, Thus spake the man unto me; that he came unto the man; and, behold, he stood by the camels at the well.'); +INSERT INTO t1(docid,words) VALUES(1024031,'And he said, Come in, thou blessed of the LORD; wherefore standest thou without? for I have prepared the house, and room for the camels.'); +INSERT INTO t1(docid,words) VALUES(1024032,'And the man came into the house: and he ungirded his camels, and gave straw and provender for the camels, and water to wash his feet, and the men''s feet that were with him.'); +INSERT INTO t1(docid,words) VALUES(1024033,'And there was set meat before him to eat: but he said, I will not eat, until I have told mine errand. And he said, Speak on.'); +INSERT INTO t1(docid,words) VALUES(1024034,'And he said, I am Abraham''s servant.'); +INSERT INTO t1(docid,words) VALUES(1024035,'And the LORD hath blessed my master greatly; and he is become great: and he hath given him flocks, and herds, and silver, and gold, and menservants, and maidservants, and camels, and asses.'); +INSERT INTO t1(docid,words) VALUES(1024036,'And Sarah my master''s wife bare a son to my master when she was old: and unto him hath he given all that he hath.'); +INSERT INTO t1(docid,words) VALUES(1024037,'And my master made me swear, saying, Thou shalt not take a wife to my son of the daughters of the Canaanites, in whose land I dwell:'); +INSERT INTO t1(docid,words) VALUES(1024038,'But thou shalt go unto my father''s house, and to my kindred, and take a wife unto my son.'); +INSERT INTO t1(docid,words) VALUES(1024039,'And I said unto my master, Peradventure the woman will not follow me.'); +INSERT INTO t1(docid,words) VALUES(1024040,'And he said unto me, The LORD, before whom I walk, will send his angel with thee, and prosper thy way; and thou shalt take a wife for my son of my kindred, and of my father''s house:'); +INSERT INTO t1(docid,words) VALUES(1024041,'Then shalt thou be clear from this my oath, when thou comest to my kindred; and if they give not thee one, thou shalt be clear from my oath.'); +INSERT INTO t1(docid,words) VALUES(1024042,'And I came this day unto the well, and said, O LORD God of my master Abraham, if now thou do prosper my way which I go:'); +INSERT INTO t1(docid,words) VALUES(1024043,'Behold, I stand by the well of water; and it shall come to pass, that when the virgin cometh forth to draw water, and I say to her, Give me, I pray thee, a little water of thy pitcher to drink;'); +INSERT INTO t1(docid,words) VALUES(1024044,'And she say to me, Both drink thou, and I will also draw for thy camels: let the same be the woman whom the LORD hath appointed out for my master''s son.'); +INSERT INTO t1(docid,words) VALUES(1024045,'And before I had done speaking in mine heart, behold, Rebekah came forth with her pitcher on her shoulder; and she went down unto the well, and drew water: and I said unto her, Let me drink, I pray thee.'); +INSERT INTO t1(docid,words) VALUES(1024046,'And she made haste, and let down her pitcher from her shoulder, and said, Drink, and I will give thy camels drink also: so I drank, and she made the camels drink also.'); +INSERT INTO t1(docid,words) VALUES(1024047,'And I asked her, and said, Whose daughter art thou? And she said, the daughter of Bethuel, Nahor''s son, whom Milcah bare unto him: and I put the earring upon her face, and the bracelets upon her hands.'); +INSERT INTO t1(docid,words) VALUES(1024048,'And I bowed down my head, and worshipped the LORD, and blessed the LORD God of my master Abraham, which had led me in the right way to take my master''s brother''s daughter unto his son.'); +INSERT INTO t1(docid,words) VALUES(1024049,'And now if ye will deal kindly and truly with my master, tell me: and if not, tell me; that I may turn to the right hand, or to the left.'); +INSERT INTO t1(docid,words) VALUES(1024050,'Then Laban and Bethuel answered and said, The thing proceedeth from the LORD: we cannot speak unto thee bad or good.'); +INSERT INTO t1(docid,words) VALUES(1024051,'Behold, Rebekah is before thee, take her, and go, and let her be thy master''s son''s wife, as the LORD hath spoken.'); +INSERT INTO t1(docid,words) VALUES(1024052,'And it came to pass, that, when Abraham''s servant heard their words, he worshipped the LORD, bowing himself to the earth.'); +INSERT INTO t1(docid,words) VALUES(1024053,'And the servant brought forth jewels of silver, and jewels of gold, and raiment, and gave them to Rebekah: he gave also to her brother and to her mother precious things.'); +INSERT INTO t1(docid,words) VALUES(1024054,'And they did eat and drink, he and the men that were with him, and tarried all night; and they rose up in the morning, and he said, Send me away unto my master.'); +INSERT INTO t1(docid,words) VALUES(1024055,'And her brother and her mother said, Let the damsel abide with us a few days, at the least ten; after that she shall go.'); +INSERT INTO t1(docid,words) VALUES(1024056,'And he said unto them, Hinder me not, seeing the LORD hath prospered my way; send me away that I may go to my master.'); +INSERT INTO t1(docid,words) VALUES(1024057,'And they said, We will call the damsel, and enquire at her mouth.'); +INSERT INTO t1(docid,words) VALUES(1024058,'And they called Rebekah, and said unto her, Wilt thou go with this man? And she said, I will go.'); +INSERT INTO t1(docid,words) VALUES(1024059,'And they sent away Rebekah their sister, and her nurse, and Abraham''s servant, and his men.'); +INSERT INTO t1(docid,words) VALUES(1024060,'And they blessed Rebekah, and said unto her, Thou art our sister, be thou the mother of thousands of millions, and let thy seed possess the gate of those which hate them.'); +INSERT INTO t1(docid,words) VALUES(1024061,'And Rebekah arose, and her damsels, and they rode upon the camels, and followed the man: and the servant took Rebekah, and went his way.'); +INSERT INTO t1(docid,words) VALUES(1024062,'And Isaac came from the way of the well Lahairoi; for he dwelt in the south country.'); +INSERT INTO t1(docid,words) VALUES(1024063,'And Isaac went out to meditate in the field at the eventide: and he lifted up his eyes, and saw, and, behold, the camels were coming.'); +INSERT INTO t1(docid,words) VALUES(1024064,'And Rebekah lifted up her eyes, and when she saw Isaac, she lighted off the camel.'); +INSERT INTO t1(docid,words) VALUES(1024065,'For she had said unto the servant, What man is this that walketh in the field to meet us? And the servant had said, It is my master: therefore she took a vail, and covered herself.'); +INSERT INTO t1(docid,words) VALUES(1024066,'And the servant told Isaac all things that he had done.'); +INSERT INTO t1(docid,words) VALUES(1024067,'And Isaac brought her into his mother Sarah''s tent, and took Rebekah, and she became his wife; and he loved her: and Isaac was comforted after his mother''s death.'); +INSERT INTO t1(docid,words) VALUES(1025001,'Then again Abraham took a wife, and her name was Keturah.'); +INSERT INTO t1(docid,words) VALUES(1025002,'And she bare him Zimran, and Jokshan, and Medan, and Midian, and Ishbak, and Shuah.'); +INSERT INTO t1(docid,words) VALUES(1025003,'And Jokshan begat Sheba, and Dedan. And the sons of Dedan were Asshurim, and Letushim, and Leummim.'); +INSERT INTO t1(docid,words) VALUES(1025004,'And the sons of Midian; Ephah, and Epher, and Hanoch, and Abidah, and Eldaah. All these were the children of Keturah.'); +INSERT INTO t1(docid,words) VALUES(1025005,'And Abraham gave all that he had unto Isaac.'); +INSERT INTO t1(docid,words) VALUES(1025006,'But unto the sons of the concubines, which Abraham had, Abraham gave gifts, and sent them away from Isaac his son, while he yet lived, eastward, unto the east country.'); +INSERT INTO t1(docid,words) VALUES(1025007,'And these are the days of the years of Abraham''s life which he lived, an hundred threescore and fifteen years.'); +INSERT INTO t1(docid,words) VALUES(1025008,'Then Abraham gave up the ghost, and died in a good old age, an old man, and full of years; and was gathered to his people.'); +INSERT INTO t1(docid,words) VALUES(1025009,'And his sons Isaac and Ishmael buried him in the cave of Machpelah, in the field of Ephron the son of Zohar the Hittite, which is before Mamre;'); +INSERT INTO t1(docid,words) VALUES(1025010,'The field which Abraham purchased of the sons of Heth: there was Abraham buried, and Sarah his wife.'); +INSERT INTO t1(docid,words) VALUES(1025011,'And it came to pass after the death of Abraham, that God blessed his son Isaac; and Isaac dwelt by the well Lahairoi.'); +INSERT INTO t1(docid,words) VALUES(1025012,'Now these are the generations of Ishmael, Abraham''s son, whom Hagar the Egyptian, Sarah''s handmaid, bare unto Abraham:'); +INSERT INTO t1(docid,words) VALUES(1025013,'And these are the names of the sons of Ishmael, by their names, according to their generations: the firstborn of Ishmael, Nebajoth; and Kedar, and Adbeel, and Mibsam,'); +INSERT INTO t1(docid,words) VALUES(1025014,'And Mishma, and Dumah, and Massa,'); +INSERT INTO t1(docid,words) VALUES(1025015,'Hadar, and Tema, Jetur, Naphish, and Kedemah:'); +INSERT INTO t1(docid,words) VALUES(1025016,'These are the sons of Ishmael, and these are their names, by their towns, and by their castles; twelve princes according to their nations.'); +INSERT INTO t1(docid,words) VALUES(1025017,'And these are the years of the life of Ishmael, an hundred and thirty and seven years: and he gave up the ghost and died; and was gathered unto his people.'); +INSERT INTO t1(docid,words) VALUES(1025018,'And they dwelt from Havilah unto Shur, that is before Egypt, as thou goest toward Assyria: and he died in the presence of all his brethren.'); +INSERT INTO t1(docid,words) VALUES(1025019,'And these are the generations of Isaac, Abraham''s son: Abraham begat Isaac:'); +INSERT INTO t1(docid,words) VALUES(1025020,'And Isaac was forty years old when he took Rebekah to wife, the daughter of Bethuel the Syrian of Padanaram, the sister to Laban the Syrian.'); +INSERT INTO t1(docid,words) VALUES(1025021,'And Isaac intreated the LORD for his wife, because she was barren: and the LORD was intreated of him, and Rebekah his wife conceived.'); +INSERT INTO t1(docid,words) VALUES(1025022,'And the children struggled together within her; and she said, If it be so, why am I thus? And she went to enquire of the LORD.'); +INSERT INTO t1(docid,words) VALUES(1025023,'And the LORD said unto her, Two nations are in thy womb, and two manner of people shall be separated from thy bowels; and the one people shall be stronger than the other people; and the elder shall serve the younger.'); +INSERT INTO t1(docid,words) VALUES(1025024,'And when her days to be delivered were fulfilled, behold, there were twins in her womb.'); +INSERT INTO t1(docid,words) VALUES(1025025,'And the first came out red, all over like an hairy garment; and they called his name Esau.'); +INSERT INTO t1(docid,words) VALUES(1025026,'And after that came his brother out, and his hand took hold on Esau''s heel; and his name was called Jacob: and Isaac was threescore years old when she bare them.'); +INSERT INTO t1(docid,words) VALUES(1025027,'And the boys grew: and Esau was a cunning hunter, a man of the field; and Jacob was a plain man, dwelling in tents.'); +INSERT INTO t1(docid,words) VALUES(1025028,'And Isaac loved Esau, because he did eat of his venison: but Rebekah loved Jacob.'); +INSERT INTO t1(docid,words) VALUES(1025029,'And Jacob sod pottage: and Esau came from the field, and he was faint:'); +INSERT INTO t1(docid,words) VALUES(1025030,'And Esau said to Jacob, Feed me, I pray thee, with that same red pottage; for I am faint: therefore was his name called Edom.'); +INSERT INTO t1(docid,words) VALUES(1025031,'And Jacob said, Sell me this day thy birthright.'); +INSERT INTO t1(docid,words) VALUES(1025032,'And Esau said, Behold, I am at the point to die: and what profit shall this birthright do to me?'); +INSERT INTO t1(docid,words) VALUES(1025033,'And Jacob said, Swear to me this day; and he sware unto him: and he sold his birthright unto Jacob.'); +INSERT INTO t1(docid,words) VALUES(1025034,'Then Jacob gave Esau bread and pottage of lentiles; and he did eat and drink, and rose up, and went his way: thus Esau despised his birthright.'); +INSERT INTO t1(docid,words) VALUES(1026001,'And there was a famine in the land, beside the first famine that was in the days of Abraham. And Isaac went unto Abimelech king of the Philistines unto Gerar.'); +INSERT INTO t1(docid,words) VALUES(1026002,'And the LORD appeared unto him, and said, Go not down into Egypt; dwell in the land which I shall tell thee of:'); +INSERT INTO t1(docid,words) VALUES(1026003,'Sojourn in this land, and I will be with thee, and will bless thee; for unto thee, and unto thy seed, I will give all these countries, and I will perform the oath which I sware unto Abraham thy father;'); +INSERT INTO t1(docid,words) VALUES(1026004,'And I will make thy seed to multiply as the stars of heaven, and will give unto thy seed all these countries; and in thy seed shall all the nations of the earth be blessed;'); +INSERT INTO t1(docid,words) VALUES(1026005,'Because that Abraham obeyed my voice, and kept my charge, my commandments, my statutes, and my laws.'); +INSERT INTO t1(docid,words) VALUES(1026006,'And Isaac dwelt in Gerar:'); +INSERT INTO t1(docid,words) VALUES(1026007,'And the men of the place asked him of his wife; and he said, She is my sister: for he feared to say, She is my wife; lest, said he, the men of the place should kill me for Rebekah; because she was fair to look upon.'); +INSERT INTO t1(docid,words) VALUES(1026008,'And it came to pass, when he had been there a long time, that Abimelech king of the Philistines looked out at a window, and saw, and, behold, Isaac was sporting with Rebekah his wife.'); +INSERT INTO t1(docid,words) VALUES(1026009,'And Abimelech called Isaac, and said, Behold, of a surety she is thy wife; and how saidst thou, She is my sister? And Isaac said unto him, Because I said, Lest I die for her.'); +INSERT INTO t1(docid,words) VALUES(1026010,'And Abimelech said, What is this thou hast done unto us? one of the people might lightly have lien with thy wife, and thou shouldest have brought guiltiness upon us.'); +INSERT INTO t1(docid,words) VALUES(1026011,'And Abimelech charged all his people, saying, He that toucheth this man or his wife shall surely be put to death.'); +INSERT INTO t1(docid,words) VALUES(1026012,'Then Isaac sowed in that land, and received in the same year an hundredfold: and the LORD blessed him.'); +INSERT INTO t1(docid,words) VALUES(1026013,'And the man waxed great, and went forward, and grew until he became very great:'); +INSERT INTO t1(docid,words) VALUES(1026014,'For he had possession of flocks, and possession of herds, and great store of servants: and the Philistines envied him.'); +INSERT INTO t1(docid,words) VALUES(1026015,'For all the wells which his father''s servants had digged in the days of Abraham his father, the Philistines had stopped them, and filled them with earth.'); +INSERT INTO t1(docid,words) VALUES(1026016,'And Abimelech said unto Isaac, Go from us; for thou art much mightier than we.'); +INSERT INTO t1(docid,words) VALUES(1026017,'And Isaac departed thence, and pitched his tent in the valley of Gerar, and dwelt there.'); +INSERT INTO t1(docid,words) VALUES(1026018,'And Isaac digged again the wells of water, which they had digged in the days of Abraham his father; for the Philistines had stopped them after the death of Abraham: and he called their names after the names by which his father had called them.'); +INSERT INTO t1(docid,words) VALUES(1026019,'And Isaac''s servants digged in the valley, and found there a well of springing water.'); +INSERT INTO t1(docid,words) VALUES(1026020,'And the herdmen of Gerar did strive with Isaac''s herdmen, saying, The water is ours: and he called the name of the well Esek; because they strove with him.'); +INSERT INTO t1(docid,words) VALUES(1026021,'And they digged another well, and strove for that also: and he called the name of it Sitnah.'); +INSERT INTO t1(docid,words) VALUES(1026022,'And he removed from thence, and digged another well; and for that they strove not: and he called the name of it Rehoboth; and he said, For now the LORD hath made room for us, and we shall be fruitful in the land.'); +INSERT INTO t1(docid,words) VALUES(1026023,'And he went up from thence to Beersheba.'); +INSERT INTO t1(docid,words) VALUES(1026024,'And the LORD appeared unto him the same night, and said, I am the God of Abraham thy father: fear not, for I am with thee, and will bless thee, and multiply thy seed for my servant Abraham''s sake.'); +INSERT INTO t1(docid,words) VALUES(1026025,'And he builded an altar there, and called upon the name of the LORD, and pitched his tent there: and there Isaac''s servants digged a well.'); +INSERT INTO t1(docid,words) VALUES(1026026,'Then Abimelech went to him from Gerar, and Ahuzzath one of his friends, and Phichol the chief captain of his army.'); +INSERT INTO t1(docid,words) VALUES(1026027,'And Isaac said unto them, Wherefore come ye to me, seeing ye hate me, and have sent me away from you?'); +INSERT INTO t1(docid,words) VALUES(1026028,'And they said, We saw certainly that the LORD was with thee: and we said, Let there be now an oath betwixt us, even betwixt us and thee, and let us make a covenant with thee;'); +INSERT INTO t1(docid,words) VALUES(1026029,'That thou wilt do us no hurt, as we have not touched thee, and as we have done unto thee nothing but good, and have sent thee away in peace: thou art now the blessed of the LORD.'); +INSERT INTO t1(docid,words) VALUES(1026030,'And he made them a feast, and they did eat and drink.'); +INSERT INTO t1(docid,words) VALUES(1026031,'And they rose up betimes in the morning, and sware one to another: and Isaac sent them away, and they departed from him in peace.'); +INSERT INTO t1(docid,words) VALUES(1026032,'And it came to pass the same day, that Isaac''s servants came, and told him concerning the well which they had digged, and said unto him, We have found water.'); +INSERT INTO t1(docid,words) VALUES(1026033,'And he called it Shebah: therefore the name of the city is Beersheba unto this day.'); +INSERT INTO t1(docid,words) VALUES(1026034,'And Esau was forty years old when he took to wife Judith the daughter of Beeri the Hittite, and Bashemath the daughter of Elon the Hittite:'); +INSERT INTO t1(docid,words) VALUES(1026035,'Which were a grief of mind unto Isaac and to Rebekah.'); +INSERT INTO t1(docid,words) VALUES(1027001,'And it came to pass, that when Isaac was old, and his eyes were dim, so that he could not see, he called Esau his eldest son, and said unto him, My son: and he said unto him, Behold, here am I.'); +INSERT INTO t1(docid,words) VALUES(1027002,'And he said, Behold now, I am old, I know not the day of my death:'); +INSERT INTO t1(docid,words) VALUES(1027003,'Now therefore take, I pray thee, thy weapons, thy quiver and thy bow, and go out to the field, and take me some venison;'); +INSERT INTO t1(docid,words) VALUES(1027004,'And make me savoury meat, such as I love, and bring it to me, that I may eat; that my soul may bless thee before I die.'); +INSERT INTO t1(docid,words) VALUES(1027005,'And Rebekah heard when Isaac spake to Esau his son. And Esau went to the field to hunt for venison, and to bring it.'); +INSERT INTO t1(docid,words) VALUES(1027006,'And Rebekah spake unto Jacob her son, saying, Behold, I heard thy father speak unto Esau thy brother, saying,'); +INSERT INTO t1(docid,words) VALUES(1027007,'Bring me venison, and make me savoury meat, that I may eat, and bless thee before the LORD before my death.'); +INSERT INTO t1(docid,words) VALUES(1027008,'Now therefore, my son, obey my voice according to that which I command thee.'); +INSERT INTO t1(docid,words) VALUES(1027009,'Go now to the flock, and fetch me from thence two good kids of the goats; and I will make them savoury meat for thy father, such as he loveth:'); +INSERT INTO t1(docid,words) VALUES(1027010,'And thou shalt bring it to thy father, that he may eat, and that he may bless thee before his death.'); +INSERT INTO t1(docid,words) VALUES(1027011,'And Jacob said to Rebekah his mother, Behold, Esau my brother is a hairy man, and I am a smooth man:'); +INSERT INTO t1(docid,words) VALUES(1027012,'My father peradventure will feel me, and I shall seem to him as a deceiver; and I shall bring a curse upon me, and not a blessing.'); +INSERT INTO t1(docid,words) VALUES(1027013,'And his mother said unto him, Upon me be thy curse, my son: only obey my voice, and go fetch me them.'); +INSERT INTO t1(docid,words) VALUES(1027014,'And he went, and fetched, and brought them to his mother: and his mother made savoury meat, such as his father loved.'); +INSERT INTO t1(docid,words) VALUES(1027015,'And Rebekah took goodly raiment of her eldest son Esau, which were with her in the house, and put them upon Jacob her younger son:'); +INSERT INTO t1(docid,words) VALUES(1027016,'And she put the skins of the kids of the goats upon his hands, and upon the smooth of his neck:'); +INSERT INTO t1(docid,words) VALUES(1027017,'And she gave the savoury meat and the bread, which she had prepared, into the hand of her son Jacob.'); +INSERT INTO t1(docid,words) VALUES(1027018,'And he came unto his father, and said, My father: and he said, Here am I; who art thou, my son?'); +INSERT INTO t1(docid,words) VALUES(1027019,'And Jacob said unto his father, I am Esau thy first born; I have done according as thou badest me: arise, I pray thee, sit and eat of my venison, that thy soul may bless me.'); +INSERT INTO t1(docid,words) VALUES(1027020,'And Isaac said unto his son, How is it that thou hast found it so quickly, my son? And he said, Because the LORD thy God brought it to me.'); +INSERT INTO t1(docid,words) VALUES(1027021,'And Isaac said unto Jacob, Come near, I pray thee, that I may feel thee, my son, whether thou be my very son Esau or not.'); +INSERT INTO t1(docid,words) VALUES(1027022,'And Jacob went near unto Isaac his father; and he felt him, and said, The voice is Jacob''s voice, but the hands are the hands of Esau.'); +INSERT INTO t1(docid,words) VALUES(1027023,'And he discerned him not, because his hands were hairy, as his brother Esau''s hands: so he blessed him.'); +INSERT INTO t1(docid,words) VALUES(1027024,'And he said, Art thou my very son Esau? And he said, I am.'); +INSERT INTO t1(docid,words) VALUES(1027025,'And he said, Bring it near to me, and I will eat of my son''s venison, that my soul may bless thee. And he brought it near to him, and he did eat: and he brought him wine and he drank.'); +INSERT INTO t1(docid,words) VALUES(1027026,'And his father Isaac said unto him, Come near now, and kiss me, my son.'); +INSERT INTO t1(docid,words) VALUES(1027027,'And he came near, and kissed him: and he smelled the smell of his raiment, and blessed him, and said, See, the smell of my son is as the smell of a field which the LORD hath blessed:'); +INSERT INTO t1(docid,words) VALUES(1027028,'Therefore God give thee of the dew of heaven, and the fatness of the earth, and plenty of corn and wine:'); +INSERT INTO t1(docid,words) VALUES(1027029,'Let people serve thee, and nations bow down to thee: be lord over thy brethren, and let thy mother''s sons bow down to thee: cursed be every one that curseth thee, and blessed be he that blesseth thee.'); +INSERT INTO t1(docid,words) VALUES(1027030,'And it came to pass, as soon as Isaac had made an end of blessing Jacob, and Jacob was yet scarce gone out from the presence of Isaac his father, that Esau his brother came in from his hunting.'); +INSERT INTO t1(docid,words) VALUES(1027031,'And he also had made savoury meat, and brought it unto his father, and said unto his father, Let my father arise, and eat of his son''s venison, that thy soul may bless me.'); +INSERT INTO t1(docid,words) VALUES(1027032,'And Isaac his father said unto him, Who art thou? And he said, I am thy son, thy firstborn Esau.'); +INSERT INTO t1(docid,words) VALUES(1027033,'And Isaac trembled very exceedingly, and said, Who? where is he that hath taken venison, and brought it me, and I have eaten of all before thou camest, and have blessed him? yea, and he shall be blessed.'); +INSERT INTO t1(docid,words) VALUES(1027034,'And when Esau heard the words of his father, he cried with a great and exceeding bitter cry, and said unto his father, Bless me, even me also, O my father.'); +INSERT INTO t1(docid,words) VALUES(1027035,'And he said, Thy brother came with subtilty, and hath taken away thy blessing.'); +INSERT INTO t1(docid,words) VALUES(1027036,'And he said, Is not he rightly named Jacob? for he hath supplanted me these two times: he took away my birthright; and, behold, now he hath taken away my blessing. And he said, Hast thou not reserved a blessing for me?'); +INSERT INTO t1(docid,words) VALUES(1027037,'And Isaac answered and said unto Esau, Behold, I have made him thy lord, and all his brethren have I given to him for servants; and with corn and wine have I sustained him: and what shall I do now unto thee, my son?'); +INSERT INTO t1(docid,words) VALUES(1027038,'And Esau said unto his father, Hast thou but one blessing, my father? bless me, even me also, O my father. And Esau lifted up his voice, and wept.'); +INSERT INTO t1(docid,words) VALUES(1027039,'And Isaac his father answered and said unto him, Behold, thy dwelling shall be the fatness of the earth, and of the dew of heaven from above;'); +INSERT INTO t1(docid,words) VALUES(1027040,'And by thy sword shalt thou live, and shalt serve thy brother; and it shall come to pass when thou shalt have the dominion, that thou shalt break his yoke from off thy neck.'); +INSERT INTO t1(docid,words) VALUES(1027041,'And Esau hated Jacob because of the blessing wherewith his father blessed him: and Esau said in his heart, The days of mourning for my father are at hand; then will I slay my brother Jacob.'); +INSERT INTO t1(docid,words) VALUES(1027042,'And these words of Esau her elder son were told to Rebekah: and she sent and called Jacob her younger son, and said unto him, Behold, thy brother Esau, as touching thee, doth comfort himself, purposing to kill thee.'); +INSERT INTO t1(docid,words) VALUES(1027043,'Now therefore, my son, obey my voice; arise, flee thou to Laban my brother to Haran;'); +INSERT INTO t1(docid,words) VALUES(1027044,'And tarry with him a few days, until thy brother''s fury turn away;'); +INSERT INTO t1(docid,words) VALUES(1027045,'Until thy brother''s anger turn away from thee, and he forget that which thou hast done to him: then I will send, and fetch thee from thence: why should I be deprived also of you both in one day?'); +INSERT INTO t1(docid,words) VALUES(1027046,'And Rebekah said to Isaac, I am weary of my life because of the daughters of Heth: if Jacob take a wife of the daughters of Heth, such as these which are of the daughters of the land, what good shall my life do me?'); +INSERT INTO t1(docid,words) VALUES(1028001,'And Isaac called Jacob, and blessed him, and charged him, and said unto him, Thou shalt not take a wife of the daughters of Canaan.'); +INSERT INTO t1(docid,words) VALUES(1028002,'Arise, go to Padanaram, to the house of Bethuel thy mother''s father; and take thee a wife from thence of the daughers of Laban thy mother''s brother.'); +INSERT INTO t1(docid,words) VALUES(1028003,'And God Almighty bless thee, and make thee fruitful, and multiply thee, that thou mayest be a multitude of people;'); +INSERT INTO t1(docid,words) VALUES(1028004,'And give thee the blessing of Abraham, to thee, and to thy seed with thee; that thou mayest inherit the land wherein thou art a stranger, which God gave unto Abraham.'); +INSERT INTO t1(docid,words) VALUES(1028005,'And Isaac sent away Jacob: and he went to Padanaram unto Laban, son of Bethuel the Syrian, the brother of Rebekah, Jacob''s and Esau''s mother.'); +INSERT INTO t1(docid,words) VALUES(1028006,'When Esau saw that Isaac had blessed Jacob, and sent him away to Padanaram, to take him a wife from thence; and that as he blessed him he gave him a charge, saying, Thou shalt not take a wife of the daughers of Canaan;'); +INSERT INTO t1(docid,words) VALUES(1028007,'And that Jacob obeyed his father and his mother, and was gone to Padanaram;'); +INSERT INTO t1(docid,words) VALUES(1028008,'And Esau seeing that the daughters of Canaan pleased not Isaac his father;'); +INSERT INTO t1(docid,words) VALUES(1028009,'Then went Esau unto Ishmael, and took unto the wives which he had Mahalath the daughter of Ishmael Abraham''s son, the sister of Nebajoth, to be his wife.'); +INSERT INTO t1(docid,words) VALUES(1028010,'And Jacob went out from Beersheba, and went toward Haran.'); +INSERT INTO t1(docid,words) VALUES(1028011,'And he lighted upon a certain place, and tarried there all night, because the sun was set; and he took of the stones of that place, and put them for his pillows, and lay down in that place to sleep.'); +INSERT INTO t1(docid,words) VALUES(1028012,'And he dreamed, and behold a ladder set up on the earth, and the top of it reached to heaven: and behold the angels of God ascending and descending on it.'); +INSERT INTO t1(docid,words) VALUES(1028013,'And, behold, the LORD stood above it, and said, I am the LORD God of Abraham thy father, and the God of Isaac: the land whereon thou liest, to thee will I give it, and to thy seed;'); +INSERT INTO t1(docid,words) VALUES(1028014,'And thy seed shall be as the dust of the earth, and thou shalt spread abroad to the west, and to the east, and to the north, and to the south: and in thee and in thy seed shall all the families of the earth be blessed.'); +INSERT INTO t1(docid,words) VALUES(1028015,'And, behold, I am with thee, and will keep thee in all places whither thou goest, and will bring thee again into this land; for I will not leave thee, until I have done that which I have spoken to thee of.'); +INSERT INTO t1(docid,words) VALUES(1028016,'And Jacob awaked out of his sleep, and he said, Surely the LORD is in this place; and I knew it not.'); +INSERT INTO t1(docid,words) VALUES(1028017,'And he was afraid, and said, How dreadful is this place! this is none other but the house of God, and this is the gate of heaven.'); +INSERT INTO t1(docid,words) VALUES(1028018,'And Jacob rose up early in the morning, and took the stone that he had put for his pillows, and set it up for a pillar, and poured oil upon the top of it.'); +INSERT INTO t1(docid,words) VALUES(1028019,'And he called the name of that place Bethel: but the name of that city was called Luz at the first.'); +INSERT INTO t1(docid,words) VALUES(1028020,'And Jacob vowed a vow, saying, If God will be with me, and will keep me in this way that I go, and will give me bread to eat, and raiment to put on,'); +INSERT INTO t1(docid,words) VALUES(1028021,'So that I come again to my father''s house in peace; then shall the LORD be my God:'); +INSERT INTO t1(docid,words) VALUES(1028022,'And this stone, which I have set for a pillar, shall be God''s house: and of all that thou shalt give me I will surely give the tenth unto thee.'); +INSERT INTO t1(docid,words) VALUES(1029001,'Then Jacob went on his journey, and came into the land of the people of the east.'); +INSERT INTO t1(docid,words) VALUES(1029002,'And he looked, and behold a well in the field, and, lo, there were three flocks of sheep lying by it; for out of that well they watered the flocks: and a great stone was upon the well''s mouth.'); +INSERT INTO t1(docid,words) VALUES(1029003,'And thither were all the flocks gathered: and they rolled the stone from the well''s mouth, and watered the sheep, and put the stone again upon the well''s mouth in his place.'); +INSERT INTO t1(docid,words) VALUES(1029004,'And Jacob said unto them, My brethren, whence be ye? And they said, Of Haran are we.'); +INSERT INTO t1(docid,words) VALUES(1029005,'And he said unto them, Know ye Laban the son of Nahor? And they said, We know him.'); +INSERT INTO t1(docid,words) VALUES(1029006,'And he said unto them, Is he well? And they said, He is well: and, behold, Rachel his daughter cometh with the sheep.'); +INSERT INTO t1(docid,words) VALUES(1029007,'And he said, Lo, it is yet high day, neither is it time that the cattle should be gathered together: water ye the sheep, and go and feed them.'); +INSERT INTO t1(docid,words) VALUES(1029008,'And they said, We cannot, until all the flocks be gathered together, and till they roll the stone from the well''s mouth; then we water the sheep.'); +INSERT INTO t1(docid,words) VALUES(1029009,'And while he yet spake with them, Rachel came with her father''s sheep; for she kept them.'); +INSERT INTO t1(docid,words) VALUES(1029010,'And it came to pass, when Jacob saw Rachel the daughter of Laban his mother''s brother, and the sheep of Laban his mother''s brother, that Jacob went near, and rolled the stone from the well''s mouth, and watered the flock of Laban his mother''s brother.'); +INSERT INTO t1(docid,words) VALUES(1029011,'And Jacob kissed Rachel, and lifted up his voice, and wept.'); +INSERT INTO t1(docid,words) VALUES(1029012,'And Jacob told Rachel that he was her father''s brother, and that he was Rebekah''s son: and she ran and told her father.'); +INSERT INTO t1(docid,words) VALUES(1029013,'And it came to pass, when Laban heard the tidings of Jacob his sister''s son, that he ran to meet him, and embraced him, and kissed him, and brought him to his house. And he told Laban all these things.'); +INSERT INTO t1(docid,words) VALUES(1029014,'And Laban said to him, Surely thou art my bone and my flesh. And he abode with him the space of a month.'); +INSERT INTO t1(docid,words) VALUES(1029015,'And Laban said unto Jacob, Because thou art my brother, shouldest thou therefore serve me for nought? tell me, what shall thy wages be?'); +INSERT INTO t1(docid,words) VALUES(1029016,'And Laban had two daughters: the name of the elder was Leah, and the name of the younger was Rachel.'); +INSERT INTO t1(docid,words) VALUES(1029017,'Leah was tender eyed; but Rachel was beautiful and well favoured.'); +INSERT INTO t1(docid,words) VALUES(1029018,'And Jacob loved Rachel; and said, I will serve thee seven years for Rachel thy younger daughter.'); +INSERT INTO t1(docid,words) VALUES(1029019,'And Laban said, It is better that I give her to thee, than that I should give her to another man: abide with me.'); +INSERT INTO t1(docid,words) VALUES(1029020,'And Jacob served seven years for Rachel; and they seemed unto him but a few days, for the love he had to her.'); +INSERT INTO t1(docid,words) VALUES(1029021,'And Jacob said unto Laban, Give me my wife, for my days are fulfilled, that I may go in unto her.'); +INSERT INTO t1(docid,words) VALUES(1029022,'And Laban gathered together all the men of the place, and made a feast.'); +INSERT INTO t1(docid,words) VALUES(1029023,'And it came to pass in the evening, that he took Leah his daughter, and brought her to him; and he went in unto her.'); +INSERT INTO t1(docid,words) VALUES(1029024,'And Laban gave unto his daughter Leah Zilpah his maid for an handmaid.'); +INSERT INTO t1(docid,words) VALUES(1029025,'And it came to pass, that in the morning, behold, it was Leah: and he said to Laban, What is this thou hast done unto me? did not I serve with thee for Rachel? wherefore then hast thou beguiled me?'); +INSERT INTO t1(docid,words) VALUES(1029026,'And Laban said, It must not be so done in our country, to give the younger before the firstborn.'); +INSERT INTO t1(docid,words) VALUES(1029027,'Fulfil her week, and we will give thee this also for the service which thou shalt serve with me yet seven other years.'); +INSERT INTO t1(docid,words) VALUES(1029028,'And Jacob did so, and fulfilled her week: and he gave him Rachel his daughter to wife also.'); +INSERT INTO t1(docid,words) VALUES(1029029,'And Laban gave to Rachel his daughter Bilhah his handmaid to be her maid.'); +INSERT INTO t1(docid,words) VALUES(1029030,'And he went in also unto Rachel, and he loved also Rachel more than Leah, and served with him yet seven other years.'); +INSERT INTO t1(docid,words) VALUES(1029031,'And when the LORD saw that Leah was hated, he opened her womb: but Rachel was barren.'); +INSERT INTO t1(docid,words) VALUES(1029032,'And Leah conceived, and bare a son, and she called his name Reuben: for she said, Surely the LORD hath looked upon my affliction; now therefore my husband will love me.'); +INSERT INTO t1(docid,words) VALUES(1029033,'And she conceived again, and bare a son; and said, Because the LORD hath heard I was hated, he hath therefore given me this son also: and she called his name Simeon.'); +INSERT INTO t1(docid,words) VALUES(1029034,'And she conceived again, and bare a son; and said, Now this time will my husband be joined unto me, because I have born him three sons: therefore was his name called Levi.'); +INSERT INTO t1(docid,words) VALUES(1029035,'And she conceived again, and bare a son: and she said, Now will I praise the LORD: therefore she called his name Judah; and left bearing.'); +INSERT INTO t1(docid,words) VALUES(1030001,'And when Rachel saw that she bare Jacob no children, Rachel envied her sister; and said unto Jacob, Give me children, or else I die.'); +INSERT INTO t1(docid,words) VALUES(1030002,'And Jacob''s anger was kindled against Rachel: and he said, Am I in God''s stead, who hath withheld from thee the fruit of the womb?'); +INSERT INTO t1(docid,words) VALUES(1030003,'And she said, Behold my maid Bilhah, go in unto her; and she shall bear upon my knees, that I may also have children by her.'); +INSERT INTO t1(docid,words) VALUES(1030004,'And she gave him Bilhah her handmaid to wife: and Jacob went in unto her.'); +INSERT INTO t1(docid,words) VALUES(1030005,'And Bilhah conceived, and bare Jacob a son.'); +INSERT INTO t1(docid,words) VALUES(1030006,'And Rachel said, God hath judged me, and hath also heard my voice, and hath given me a son: therefore called she his name Dan.'); +INSERT INTO t1(docid,words) VALUES(1030007,'And Bilhah Rachel''s maid conceived again, and bare Jacob a second son.'); +INSERT INTO t1(docid,words) VALUES(1030008,'And Rachel said, With great wrestlings have I wrestled with my sister, and I have prevailed: and she called his name Naphtali.'); +INSERT INTO t1(docid,words) VALUES(1030009,'When Leah saw that she had left bearing, she took Zilpah her maid, and gave her Jacob to wife.'); +INSERT INTO t1(docid,words) VALUES(1030010,'And Zilpah Leah''s maid bare Jacob a son.'); +INSERT INTO t1(docid,words) VALUES(1030011,'And Leah said, A troop cometh: and she called his name Gad.'); +INSERT INTO t1(docid,words) VALUES(1030012,'And Zilpah Leah''s maid bare Jacob a second son.'); +INSERT INTO t1(docid,words) VALUES(1030013,'And Leah said, Happy am I, for the daughters will call me blessed: and she called his name Asher.'); +INSERT INTO t1(docid,words) VALUES(1030014,'And Reuben went in the days of wheat harvest, and found mandrakes in the field, and brought them unto his mother Leah. Then Rachel said to Leah, Give me, I pray thee, of thy son''s mandrakes.'); +INSERT INTO t1(docid,words) VALUES(1030015,'And she said unto her, Is it a small matter that thou hast taken my husband? and wouldest thou take away my son''s mandrakes also? And Rachel said, Therefore he shall lie with thee to night for thy son''s mandrakes.'); +INSERT INTO t1(docid,words) VALUES(1030016,'And Jacob came out of the field in the evening, and Leah went out to meet him, and said, Thou must come in unto me; for surely I have hired thee with my son''s mandrakes. And he lay with her that night.'); +INSERT INTO t1(docid,words) VALUES(1030017,'And God hearkened unto Leah, and she conceived, and bare Jacob the fifth son.'); +INSERT INTO t1(docid,words) VALUES(1030018,'And Leah said, God hath given me my hire, because I have given my maiden to my husband: and she called his name Issachar.'); +INSERT INTO t1(docid,words) VALUES(1030019,'And Leah conceived again, and bare Jacob the sixth son.'); +INSERT INTO t1(docid,words) VALUES(1030020,'And Leah said, God hath endued me with a good dowry; now will my husband dwell with me, because I have born him six sons: and she called his name Zebulun.'); +INSERT INTO t1(docid,words) VALUES(1030021,'And afterwards she bare a daughter, and called her name Dinah.'); +INSERT INTO t1(docid,words) VALUES(1030022,'And God remembered Rachel, and God hearkened to her, and opened her womb.'); +INSERT INTO t1(docid,words) VALUES(1030023,'And she conceived, and bare a son; and said, God hath taken away my reproach:'); +INSERT INTO t1(docid,words) VALUES(1030024,'And she called his name Joseph; and said, The LORD shall add to me another son.'); +INSERT INTO t1(docid,words) VALUES(1030025,'And it came to pass, when Rachel had born Joseph, that Jacob said unto Laban, Send me away, that I may go unto mine own place, and to my country.'); +INSERT INTO t1(docid,words) VALUES(1030026,'Give me my wives and my children, for whom I have served thee, and let me go: for thou knowest my service which I have done thee.'); +INSERT INTO t1(docid,words) VALUES(1030027,'And Laban said unto him, I pray thee, if I have found favour in thine eyes, tarry: for I have learned by experience that the LORD hath blessed me for thy sake.'); +INSERT INTO t1(docid,words) VALUES(1030028,'And he said, Appoint me thy wages, and I will give it.'); +INSERT INTO t1(docid,words) VALUES(1030029,'And he said unto him, Thou knowest how I have served thee, and how thy cattle was with me.'); +INSERT INTO t1(docid,words) VALUES(1030030,'For it was little which thou hadst before I came, and it is now increased unto a multitude; and the LORD hath blessed thee since my coming: and now when shall I provide for mine own house also?'); +INSERT INTO t1(docid,words) VALUES(1030031,'And he said, What shall I give thee? And Jacob said, Thou shalt not give me any thing: if thou wilt do this thing for me, I will again feed and keep thy flock.'); +INSERT INTO t1(docid,words) VALUES(1030032,'I will pass through all thy flock to day, removing from thence all the speckled and spotted cattle, and all the brown cattle among the sheep, and the spotted and speckled among the goats: and of such shall be my hire.'); +INSERT INTO t1(docid,words) VALUES(1030033,'So shall my righteousness answer for me in time to come, when it shall come for my hire before thy face: every one that is not speckled and spotted among the goats, and brown among the sheep, that shall be counted stolen with me.'); +INSERT INTO t1(docid,words) VALUES(1030034,'And Laban said, Behold, I would it might be according to thy word.'); +INSERT INTO t1(docid,words) VALUES(1030035,'And he removed that day the he goats that were ringstraked and spotted, and all the she goats that were speckled and spotted, and every one that had some white in it, and all the brown among the sheep, and gave them into the hand of his sons.'); +INSERT INTO t1(docid,words) VALUES(1030036,'And he set three days'' journey betwixt himself and Jacob: and Jacob fed the rest of Laban''s flocks.'); +INSERT INTO t1(docid,words) VALUES(1030037,'And Jacob took him rods of green poplar, and of the hazel and chesnut tree; and pilled white strakes in them, and made the white appear which was in the rods.'); +INSERT INTO t1(docid,words) VALUES(1030038,'And he set the rods which he had pilled before the flocks in the gutters in the watering troughs when the flocks came to drink, that they should conceive when they came to drink.'); +INSERT INTO t1(docid,words) VALUES(1030039,'And the flocks conceived before the rods, and brought forth cattle ringstraked, speckled, and spotted.'); +INSERT INTO t1(docid,words) VALUES(1030040,'And Jacob did separate the lambs, and set the faces of the flocks toward the ringstraked, and all the brown in the flock of Laban; and he put his own flocks by themselves, and put them not unto Laban''s cattle.'); +INSERT INTO t1(docid,words) VALUES(1030041,'And it came to pass, whensoever the stronger cattle did conceive, that Jacob laid the rods before the eyes of the cattle in the gutters, that they might conceive among the rods.'); +INSERT INTO t1(docid,words) VALUES(1030042,'But when the cattle were feeble, he put them not in: so the feebler were Laban''s, and the stronger Jacob''s.'); +INSERT INTO t1(docid,words) VALUES(1030043,'And the man increased exceedingly, and had much cattle, and maidservants, and menservants, and camels, and asses.'); +INSERT INTO t1(docid,words) VALUES(1031001,'And he heard the words of Laban''s sons, saying, Jacob hath taken away all that was our father''s; and of that which was our father''s hath he gotten all this glory.'); +INSERT INTO t1(docid,words) VALUES(1031002,'And Jacob beheld the countenance of Laban, and, behold, it was not toward him as before.'); +INSERT INTO t1(docid,words) VALUES(1031003,'And the LORD said unto Jacob, Return unto the land of thy fathers, and to thy kindred; and I will be with thee.'); +INSERT INTO t1(docid,words) VALUES(1031004,'And Jacob sent and called Rachel and Leah to the field unto his flock,'); +INSERT INTO t1(docid,words) VALUES(1031005,'And said unto them, I see your father''s countenance, that it is not toward me as before; but the God of my father hath been with me.'); +INSERT INTO t1(docid,words) VALUES(1031006,'And ye know that with all my power I have served your father.'); +INSERT INTO t1(docid,words) VALUES(1031007,'And your father hath deceived me, and changed my wages ten times; but God suffered him not to hurt me.'); +INSERT INTO t1(docid,words) VALUES(1031008,'If he said thus, The speckled shall be thy wages; then all the cattle bare speckled: and if he said thus, The ringstraked shall be thy hire; then bare all the cattle ringstraked.'); +INSERT INTO t1(docid,words) VALUES(1031009,'Thus God hath taken away the cattle of your father, and given them to me.'); +INSERT INTO t1(docid,words) VALUES(1031010,'And it came to pass at the time that the cattle conceived, that I lifted up mine eyes, and saw in a dream, and, behold, the rams which leaped upon the cattle were ringstraked, speckled, and grisled.'); +INSERT INTO t1(docid,words) VALUES(1031011,'And the angel of God spake unto me in a dream, saying, Jacob: And I said, Here am I.'); +INSERT INTO t1(docid,words) VALUES(1031012,'And he said, Lift up now thine eyes, and see, all the rams which leap upon the cattle are ringstraked, speckled, and grisled: for I have seen all that Laban doeth unto thee.'); +INSERT INTO t1(docid,words) VALUES(1031013,'I am the God of Bethel, where thou anointedst the pillar, and where thou vowedst a vow unto me: now arise, get thee out from this land, and return unto the land of thy kindred.'); +INSERT INTO t1(docid,words) VALUES(1031014,'And Rachel and Leah answered and said unto him, Is there yet any portion or inheritance for us in our father''s house?'); +INSERT INTO t1(docid,words) VALUES(1031015,'Are we not counted of him strangers? for he hath sold us, and hath quite devoured also our money.'); +INSERT INTO t1(docid,words) VALUES(1031016,'For all the riches which God hath taken from our father, that is ours, and our children''s: now then, whatsoever God hath said unto thee, do.'); +INSERT INTO t1(docid,words) VALUES(1031017,'Then Jacob rose up, and set his sons and his wives upon camels;'); +INSERT INTO t1(docid,words) VALUES(1031018,'And he carried away all his cattle, and all his goods which he had gotten, the cattle of his getting, which he had gotten in Padanaram, for to go to Isaac his father in the land of Canaan.'); +INSERT INTO t1(docid,words) VALUES(1031019,'And Laban went to shear his sheep: and Rachel had stolen the images that were her father''s.'); +INSERT INTO t1(docid,words) VALUES(1031020,'And Jacob stole away unawares to Laban the Syrian, in that he told him not that he fled.'); +INSERT INTO t1(docid,words) VALUES(1031021,'So he fled with all that he had; and he rose up, and passed over the river, and set his face toward the mount Gilead.'); +INSERT INTO t1(docid,words) VALUES(1031022,'And it was told Laban on the third day that Jacob was fled.'); +INSERT INTO t1(docid,words) VALUES(1031023,'And he took his brethren with him, and pursued after him seven days'' journey; and they overtook him in the mount Gilead.'); +INSERT INTO t1(docid,words) VALUES(1031024,'And God came to Laban the Syrian in a dream by night, and said unto him, Take heed that thou speak not to Jacob either good or bad.'); +INSERT INTO t1(docid,words) VALUES(1031025,'Then Laban overtook Jacob. Now Jacob had pitched his tent in the mount: and Laban with his brethren pitched in the mount of Gilead.'); +INSERT INTO t1(docid,words) VALUES(1031026,'And Laban said to Jacob, What hast thou done, that thou hast stolen away unawares to me, and carried away my daughters, as captives taken with the sword?'); +INSERT INTO t1(docid,words) VALUES(1031027,'Wherefore didst thou flee away secretly, and steal away from me; and didst not tell me, that I might have sent thee away with mirth, and with songs, with tabret, and with harp?'); +INSERT INTO t1(docid,words) VALUES(1031028,'And hast not suffered me to kiss my sons and my daughters? thou hast now done foolishly in so doing.'); +INSERT INTO t1(docid,words) VALUES(1031029,'It is in the power of my hand to do you hurt: but the God of your father spake unto me yesternight, saying, Take thou heed that thou speak not to Jacob either good or bad.'); +INSERT INTO t1(docid,words) VALUES(1031030,'And now, though thou wouldest needs be gone, because thou sore longedst after thy father''s house, yet wherefore hast thou stolen my gods?'); +INSERT INTO t1(docid,words) VALUES(1031031,'And Jacob answered and said to Laban, Because I was afraid: for I said, Peradventure thou wouldest take by force thy daughters from me.'); +INSERT INTO t1(docid,words) VALUES(1031032,'With whomsoever thou findest thy gods, let him not live: before our brethren discern thou what is thine with me, and take it to thee. For Jacob knew not that Rachel had stolen them.'); +INSERT INTO t1(docid,words) VALUES(1031033,'And Laban went into Jacob''s tent, and into Leah''s tent, and into the two maidservants'' tents; but he found them not. Then went he out of Leah''s tent, and entered into Rachel''s tent.'); +INSERT INTO t1(docid,words) VALUES(1031034,'Now Rachel had taken the images, and put them in the camel''s furniture, and sat upon them. And Laban searched all the tent, but found them not.'); +INSERT INTO t1(docid,words) VALUES(1031035,'And she said to her father, Let it not displease my lord that I cannot rise up before thee; for the custom of women is upon me. And he searched but found not the images.'); +INSERT INTO t1(docid,words) VALUES(1031036,'And Jacob was wroth, and chode with Laban: and Jacob answered and said to Laban, What is my trespass? what is my sin, that thou hast so hotly pursued after me?'); +INSERT INTO t1(docid,words) VALUES(1031037,'Whereas thou hast searched all my stuff, what hast thou found of all thy household stuff? set it here before my brethren and thy brethren, that they may judge betwixt us both.'); +INSERT INTO t1(docid,words) VALUES(1031038,'This twenty years have I been with thee; thy ewes and thy she goats have not cast their young, and the rams of thy flock have I not eaten.'); +INSERT INTO t1(docid,words) VALUES(1031039,'That which was torn of beasts I brought not unto thee; I bare the loss of it; of my hand didst thou require it, whether stolen by day, or stolen by night.'); +INSERT INTO t1(docid,words) VALUES(1031040,'Thus I was; in the day the drought consumed me, and the frost by night; and my sleep departed from mine eyes.'); +INSERT INTO t1(docid,words) VALUES(1031041,'Thus have I been twenty years in thy house; I served thee fourteen years for thy two daughters, and six years for thy cattle: and thou hast changed my wages ten times.'); +INSERT INTO t1(docid,words) VALUES(1031042,'Except the God of my father, the God of Abraham, and the fear of Isaac, had been with me, surely thou hadst sent me away now empty. God hath seen mine affliction and the labour of my hands, and rebuked thee yesternight.'); +INSERT INTO t1(docid,words) VALUES(1031043,'And Laban answered and said unto Jacob, These daughters are my daughters, and these children are my children, and these cattle are my cattle, and all that thou seest is mine: and what can I do this day unto these my daughters, or unto their children which they have born?'); +INSERT INTO t1(docid,words) VALUES(1031044,'Now therefore come thou, let us make a covenant, I and thou; and let it be for a witness between me and thee.'); +INSERT INTO t1(docid,words) VALUES(1031045,'And Jacob took a stone, and set it up for a pillar.'); +INSERT INTO t1(docid,words) VALUES(1031046,'And Jacob said unto his brethren, Gather stones; and they took stones, and made an heap: and they did eat there upon the heap.'); +INSERT INTO t1(docid,words) VALUES(1031047,'And Laban called it Jegarsahadutha: but Jacob called it Galeed.'); +INSERT INTO t1(docid,words) VALUES(1031048,'And Laban said, This heap is a witness between me and thee this day. Therefore was the name of it called Galeed;'); +INSERT INTO t1(docid,words) VALUES(1031049,'And Mizpah; for he said, The LORD watch between me and thee, when we are absent one from another.'); +INSERT INTO t1(docid,words) VALUES(1031050,'If thou shalt afflict my daughters, or if thou shalt take other wives beside my daughters, no man is with us; see, God is witness betwixt me and thee.'); +INSERT INTO t1(docid,words) VALUES(1031051,'And Laban said to Jacob, Behold this heap, and behold this pillar, which I have cast betwixt me and thee:'); +INSERT INTO t1(docid,words) VALUES(1031052,'This heap be witness, and this pillar be witness, that I will not pass over this heap to thee, and that thou shalt not pass over this heap and this pillar unto me, for harm.'); +INSERT INTO t1(docid,words) VALUES(1031053,'The God of Abraham, and the God of Nahor, the God of their father, judge betwixt us. And Jacob sware by the fear of his father Isaac.'); +INSERT INTO t1(docid,words) VALUES(1031054,'Then Jacob offered sacrifice upon the mount, and called his brethren to eat bread: and they did eat bread, and tarried all night in the mount.'); +INSERT INTO t1(docid,words) VALUES(1031055,'And early in the morning Laban rose up, and kissed his sons and his daughters, and blessed them: and Laban departed, and returned unto his place.'); +INSERT INTO t1(docid,words) VALUES(1032001,'And Jacob went on his way, and the angels of God met him.'); +INSERT INTO t1(docid,words) VALUES(1032002,'And when Jacob saw them, he said, This is God''s host: and he called the name of that place Mahanaim.'); +INSERT INTO t1(docid,words) VALUES(1032003,'And Jacob sent messengers before him to Esau his brother unto the land of Seir, the country of Edom.'); +INSERT INTO t1(docid,words) VALUES(1032004,'And he commanded them, saying, Thus shall ye speak unto my lord Esau; Thy servant Jacob saith thus, I have sojourned with Laban, and stayed there until now:'); +INSERT INTO t1(docid,words) VALUES(1032005,'And I have oxen, and asses, flocks, and menservants, and womenservants: and I have sent to tell my lord, that I may find grace in thy sight.'); +INSERT INTO t1(docid,words) VALUES(1032006,'And the messengers returned to Jacob, saying, We came to thy brother Esau, and also he cometh to meet thee, and four hundred men with him.'); +INSERT INTO t1(docid,words) VALUES(1032007,'Then Jacob was greatly afraid and distressed: and he divided the people that was with him, and the flocks, and herds, and the camels, into two bands;'); +INSERT INTO t1(docid,words) VALUES(1032008,'And said, If Esau come to the one company, and smite it, then the other company which is left shall escape.'); +INSERT INTO t1(docid,words) VALUES(1032009,'And Jacob said, O God of my father Abraham, and God of my father Isaac, the LORD which saidst unto me, Return unto thy country, and to thy kindred, and I will deal well with thee:'); +INSERT INTO t1(docid,words) VALUES(1032010,'I am not worthy of the least of all the mercies, and of all the truth, which thou hast shewed unto thy servant; for with my staff I passed over this Jordan; and now I am become two bands.'); +INSERT INTO t1(docid,words) VALUES(1032011,'Deliver me, I pray thee, from the hand of my brother, from the hand of Esau: for I fear him, lest he will come and smite me, and the mother with the children.'); +INSERT INTO t1(docid,words) VALUES(1032012,'And thou saidst, I will surely do thee good, and make thy seed as the sand of the sea, which cannot be numbered for multitude.'); +INSERT INTO t1(docid,words) VALUES(1032013,'And he lodged there that same night; and took of that which came to his hand a present for Esau his brother;'); +INSERT INTO t1(docid,words) VALUES(1032014,'Two hundred she goats, and twenty he goats, two hundred ewes, and twenty rams,'); +INSERT INTO t1(docid,words) VALUES(1032015,'Thirty milch camels with their colts, forty kine, and ten bulls, twenty she asses, and ten foals.'); +INSERT INTO t1(docid,words) VALUES(1032016,'And he delivered them into the hand of his servants, every drove by themselves; and said unto his servants, Pass over before me, and put a space betwixt drove and drove.'); +INSERT INTO t1(docid,words) VALUES(1032017,'And he commanded the foremost, saying, When Esau my brother meeteth thee, and asketh thee, saying, Whose art thou? and whither goest thou? and whose are these before thee?'); +INSERT INTO t1(docid,words) VALUES(1032018,'Then thou shalt say, They be thy servant Jacob''s; it is a present sent unto my lord Esau: and, behold, also he is behind us.'); +INSERT INTO t1(docid,words) VALUES(1032019,'And so commanded he the second, and the third, and all that followed the droves, saying, On this manner shall ye speak unto Esau, when ye find him.'); +INSERT INTO t1(docid,words) VALUES(1032020,'And say ye moreover, Behold, thy servant Jacob is behind us. For he said, I will appease him with the present that goeth before me, and afterward I will see his face; peradventure he will accept of me.'); +INSERT INTO t1(docid,words) VALUES(1032021,'So went the present over before him: and himself lodged that night in the company.'); +INSERT INTO t1(docid,words) VALUES(1032022,'And he rose up that night, and took his two wives, and his two womenservants, and his eleven sons, and passed over the ford Jabbok.'); +INSERT INTO t1(docid,words) VALUES(1032023,'And he took them, and sent them over the brook, and sent over that he had.'); +INSERT INTO t1(docid,words) VALUES(1032024,'And Jacob was left alone; and there wrestled a man with him until the breaking of the day.'); +INSERT INTO t1(docid,words) VALUES(1032025,'And when he saw that he prevailed not against him, he touched the hollow of his thigh; and the hollow of Jacob''s thigh was out of joint, as he wrestled with him.'); +INSERT INTO t1(docid,words) VALUES(1032026,'And he said, Let me go, for the day breaketh. And he said, I will not let thee go, except thou bless me.'); +INSERT INTO t1(docid,words) VALUES(1032027,'And he said unto him, What is thy name? And he said, Jacob.'); +INSERT INTO t1(docid,words) VALUES(1032028,'And he said, Thy name shall be called no more Jacob, but Israel: for as a prince hast thou power with God and with men, and hast prevailed.'); +INSERT INTO t1(docid,words) VALUES(1032029,'And Jacob asked him, and said, Tell me, I pray thee, thy name. And he said, Wherefore is it that thou dost ask after my name? And he blessed him there.'); +INSERT INTO t1(docid,words) VALUES(1032030,'And Jacob called the name of the place Peniel: for I have seen God face to face, and my life is preserved.'); +INSERT INTO t1(docid,words) VALUES(1032031,'And as he passed over Penuel the sun rose upon him, and he halted upon his thigh.'); +INSERT INTO t1(docid,words) VALUES(1032032,'Therefore the children of Israel eat not of the sinew which shrank, which is upon the hollow of the thigh, unto this day: because he touched the hollow of Jacob''s thigh in the sinew that shrank.'); +INSERT INTO t1(docid,words) VALUES(1033001,'And Jacob lifted up his eyes, and looked, and, behold, Esau came, and with him four hundred men. And he divided the children unto Leah, and unto Rachel, and unto the two handmaids.'); +INSERT INTO t1(docid,words) VALUES(1033002,'And he put the handmaids and their children foremost, and Leah and her children after, and Rachel and Joseph hindermost.'); +INSERT INTO t1(docid,words) VALUES(1033003,'And he passed over before them, and bowed himself to the ground seven times, until he came near to his brother.'); +INSERT INTO t1(docid,words) VALUES(1033004,'And Esau ran to meet him, and embraced him, and fell on his neck, and kissed him: and they wept.'); +INSERT INTO t1(docid,words) VALUES(1033005,'And he lifted up his eyes, and saw the women and the children; and said, Who are those with thee? And he said, The children which God hath graciously given thy servant.'); +INSERT INTO t1(docid,words) VALUES(1033006,'Then the handmaidens came near, they and their children, and they bowed themselves.'); +INSERT INTO t1(docid,words) VALUES(1033007,'And Leah also with her children came near, and bowed themselves: and after came Joseph near and Rachel, and they bowed themselves.'); +INSERT INTO t1(docid,words) VALUES(1033008,'And he said, What meanest thou by all this drove which I met? And he said, These are to find grace in the sight of my lord.'); +INSERT INTO t1(docid,words) VALUES(1033009,'And Esau said, I have enough, my brother; keep that thou hast unto thyself.'); +INSERT INTO t1(docid,words) VALUES(1033010,'And Jacob said, Nay, I pray thee, if now I have found grace in thy sight, then receive my present at my hand: for therefore I have seen thy face, as though I had seen the face of God, and thou wast pleased with me.'); +INSERT INTO t1(docid,words) VALUES(1033011,'Take, I pray thee, my blessing that is brought to thee; because God hath dealt graciously with me, and because I have enough. And he urged him, and he took it.'); +INSERT INTO t1(docid,words) VALUES(1033012,'And he said, Let us take our journey, and let us go, and I will go before thee.'); +INSERT INTO t1(docid,words) VALUES(1033013,'And he said unto him, My lord knoweth that the children are tender, and the flocks and herds with young are with me: and if men should overdrive them one day, all the flock will die.'); +INSERT INTO t1(docid,words) VALUES(1033014,'Let my lord, I pray thee, pass over before his servant: and I will lead on softly, according as the cattle that goeth before me and the children be able to endure, until I come unto my lord unto Seir.'); +INSERT INTO t1(docid,words) VALUES(1033015,'And Esau said, Let me now leave with thee some of the folk that are with me. And he said, What needeth it? let me find grace in the sight of my lord.'); +INSERT INTO t1(docid,words) VALUES(1033016,'So Esau returned that day on his way unto Seir.'); +INSERT INTO t1(docid,words) VALUES(1033017,'And Jacob journeyed to Succoth, and built him an house, and made booths for his cattle: therefore the name of the place is called Succoth.'); +INSERT INTO t1(docid,words) VALUES(1033018,'And Jacob came to Shalem, a city of Shechem, which is in the land of Canaan, when he came from Padanaram; and pitched his tent before the city.'); +INSERT INTO t1(docid,words) VALUES(1033019,'And he bought a parcel of a field, where he had spread his tent, at the hand of the children of Hamor, Shechem''s father, for an hundred pieces of money.'); +INSERT INTO t1(docid,words) VALUES(1033020,'And he erected there an altar, and called it EleloheIsrael.'); +INSERT INTO t1(docid,words) VALUES(1034001,'And Dinah the daughter of Leah, which she bare unto Jacob, went out to see the daughters of the land.'); +INSERT INTO t1(docid,words) VALUES(1034002,'And when Shechem the son of Hamor the Hivite, prince of the country, saw her, he took her, and lay with her, and defiled her.'); +INSERT INTO t1(docid,words) VALUES(1034003,'And his soul clave unto Dinah the daughter of Jacob, and he loved the damsel, and spake kindly unto the damsel.'); +INSERT INTO t1(docid,words) VALUES(1034004,'And Shechem spake unto his father Hamor, saying, Get me this damsel to wife.'); +INSERT INTO t1(docid,words) VALUES(1034005,'And Jacob heard that he had defiled Dinah his daughter: now his sons were with his cattle in the field: and Jacob held his peace until they were come.'); +INSERT INTO t1(docid,words) VALUES(1034006,'And Hamor the father of Shechem went out unto Jacob to commune with him.'); +INSERT INTO t1(docid,words) VALUES(1034007,'And the sons of Jacob came out of the field when they heard it: and the men were grieved, and they were very wroth, because he had wrought folly in Israel in lying with Jacob''s daughter: which thing ought not to be done.'); +INSERT INTO t1(docid,words) VALUES(1034008,'And Hamor communed with them, saying, The soul of my son Shechem longeth for your daughter: I pray you give her him to wife.'); +INSERT INTO t1(docid,words) VALUES(1034009,'And make ye marriages with us, and give your daughters unto us, and take our daughters unto you.'); +INSERT INTO t1(docid,words) VALUES(1034010,'And ye shall dwell with us: and the land shall be before you; dwell and trade ye therein, and get you possessions therein.'); +INSERT INTO t1(docid,words) VALUES(1034011,'And Shechem said unto her father and unto her brethren, Let me find grace in your eyes, and what ye shall say unto me I will give.'); +INSERT INTO t1(docid,words) VALUES(1034012,'Ask me never so much dowry and gift, and I will give according as ye shall say unto me: but give me the damsel to wife.'); +INSERT INTO t1(docid,words) VALUES(1034013,'And the sons of Jacob answered Shechem and Hamor his father deceitfully, and said, because he had defiled Dinah their sister:'); +INSERT INTO t1(docid,words) VALUES(1034014,'And they said unto them, We cannot do this thing, to give our sister to one that is uncircumcised; for that were a reproach unto us:'); +INSERT INTO t1(docid,words) VALUES(1034015,'But in this will we consent unto you: If ye will be as we be, that every male of you be circumcised;'); +INSERT INTO t1(docid,words) VALUES(1034016,'Then will we give our daughters unto you, and we will take your daughters to us, and we will dwell with you, and we will become one people.'); +INSERT INTO t1(docid,words) VALUES(1034017,'But if ye will not hearken unto us, to be circumcised; then will we take our daughter, and we will be gone.'); +INSERT INTO t1(docid,words) VALUES(1034018,'And their words pleased Hamor, and Shechem Hamor''s son.'); +INSERT INTO t1(docid,words) VALUES(1034019,'And the young man deferred not to do the thing, because he had delight in Jacob''s daughter: and he was more honourable than all the house of his father.'); +INSERT INTO t1(docid,words) VALUES(1034020,'And Hamor and Shechem his son came unto the gate of their city, and communed with the men of their city, saying,'); +INSERT INTO t1(docid,words) VALUES(1034021,'These men are peaceable with us; therefore let them dwell in the land, and trade therein; for the land, behold, it is large enough for them; let us take their daughters to us for wives, and let us give them our daughters.'); +INSERT INTO t1(docid,words) VALUES(1034022,'Only herein will the men consent unto us for to dwell with us, to be one people, if every male among us be circumcised, as they are circumcised.'); +INSERT INTO t1(docid,words) VALUES(1034023,'Shall not their cattle and their substance and every beast of their''s be our''s? only let us consent unto them, and they will dwell with us.'); +INSERT INTO t1(docid,words) VALUES(1034024,'And unto Hamor and unto Shechem his son hearkened all that went out of the gate of his city; and every male was circumcised, all that went out of the gate of his city.'); +INSERT INTO t1(docid,words) VALUES(1034025,'And it came to pass on the third day, when they were sore, that two of the sons of Jacob, Simeon and Levi, Dinah''s brethren, took each man his sword, and came upon the city boldly, and slew all the males.'); +INSERT INTO t1(docid,words) VALUES(1034026,'And they slew Hamor and Shechem his son with the edge of the sword, and took Dinah out of Shechem''s house, and went out.'); +INSERT INTO t1(docid,words) VALUES(1034027,'The sons of Jacob came upon the slain, and spoiled the city, because they had defiled their sister.'); +INSERT INTO t1(docid,words) VALUES(1034028,'They took their sheep, and their oxen, and their asses, and that which was in the city, and that which was in the field,'); +INSERT INTO t1(docid,words) VALUES(1034029,'And all their wealth, and all their little ones, and their wives took they captive, and spoiled even all that was in the house.'); +INSERT INTO t1(docid,words) VALUES(1034030,'And Jacob said to Simeon and Levi, Ye have troubled me to make me to stink among the inhabitants of the land, among the Canaanites and the Perizzites: and I being few in number, they shall gather themselves together against me, and slay me; and I shall be destroyed, I and my house.'); +INSERT INTO t1(docid,words) VALUES(1034031,'And they said, Should he deal with our sister as with an harlot?'); +INSERT INTO t1(docid,words) VALUES(1035001,'And God said unto Jacob, Arise, go up to Bethel, and dwell there: and make there an altar unto God, that appeared unto thee when thou fleddest from the face of Esau thy brother.'); +INSERT INTO t1(docid,words) VALUES(1035002,'Then Jacob said unto his household, and to all that were with him, Put away the strange gods that are among you, and be clean, and change your garments:'); +INSERT INTO t1(docid,words) VALUES(1035003,'And let us arise, and go up to Bethel; and I will make there an altar unto God, who answered me in the day of my distress, and was with me in the way which I went.'); +INSERT INTO t1(docid,words) VALUES(1035004,'And they gave unto Jacob all the strange gods which were in their hand, and all their earrings which were in their ears; and Jacob hid them under the oak which was by Shechem.'); +INSERT INTO t1(docid,words) VALUES(1035005,'And they journeyed: and the terror of God was upon the cities that were round about them, and they did not pursue after the sons of Jacob.'); +INSERT INTO t1(docid,words) VALUES(1035006,'So Jacob came to Luz, which is in the land of Canaan, that is, Bethel, he and all the people that were with him.'); +INSERT INTO t1(docid,words) VALUES(1035007,'And he built there an altar, and called the place Elbethel: because there God appeared unto him, when he fled from the face of his brother.'); +INSERT INTO t1(docid,words) VALUES(1035008,'But Deborah Rebekah''s nurse died, and she was buried beneath Bethel under an oak: and the name of it was called Allonbachuth.'); +INSERT INTO t1(docid,words) VALUES(1035009,'And God appeared unto Jacob again, when he came out of Padanaram, and blessed him.'); +INSERT INTO t1(docid,words) VALUES(1035010,'And God said unto him, Thy name is Jacob: thy name shall not be called any more Jacob, but Israel shall be thy name: and he called his name Israel.'); +INSERT INTO t1(docid,words) VALUES(1035011,'And God said unto him, I am God Almighty: be fruitful and multiply; a nation and a company of nations shall be of thee, and kings shall come out of thy loins;'); +INSERT INTO t1(docid,words) VALUES(1035012,'And the land which I gave Abraham and Isaac, to thee I will give it, and to thy seed after thee will I give the land.'); +INSERT INTO t1(docid,words) VALUES(1035013,'And God went up from him in the place where he talked with him.'); +INSERT INTO t1(docid,words) VALUES(1035014,'And Jacob set up a pillar in the place where he talked with him, even a pillar of stone: and he poured a drink offering thereon, and he poured oil thereon.'); +INSERT INTO t1(docid,words) VALUES(1035015,'And Jacob called the name of the place where God spake with him, Bethel.'); +INSERT INTO t1(docid,words) VALUES(1035016,'And they journeyed from Bethel; and there was but a little way to come to Ephrath: and Rachel travailed, and she had hard labour.'); +INSERT INTO t1(docid,words) VALUES(1035017,'And it came to pass, when she was in hard labour, that the midwife said unto her, Fear not; thou shalt have this son also.'); +INSERT INTO t1(docid,words) VALUES(1035018,'And it came to pass, as her soul was in departing, (for she died) that she called his name Benoni: but his father called him Benjamin.'); +INSERT INTO t1(docid,words) VALUES(1035019,'And Rachel died, and was buried in the way to Ephrath, which is Bethlehem.'); +INSERT INTO t1(docid,words) VALUES(1035020,'And Jacob set a pillar upon her grave: that is the pillar of Rachel''s grave unto this day.'); +INSERT INTO t1(docid,words) VALUES(1035021,'And Israel journeyed, and spread his tent beyond the tower of Edar.'); +INSERT INTO t1(docid,words) VALUES(1035022,'And it came to pass, when Israel dwelt in that land, that Reuben went and lay with Bilhah his father''s concubine: and Israel heard it. Now the sons of Jacob were twelve:'); +INSERT INTO t1(docid,words) VALUES(1035023,'The sons of Leah; Reuben, Jacob''s firstborn, and Simeon, and Levi, and Judah, and Issachar, and Zebulun:'); +INSERT INTO t1(docid,words) VALUES(1035024,'The sons of Rachel; Joseph, and Benjamin:'); +INSERT INTO t1(docid,words) VALUES(1035025,'And the sons of Bilhah, Rachel''s handmaid; Dan, and Naphtali:'); +INSERT INTO t1(docid,words) VALUES(1035026,'And the sons of Zilpah, Leah''s handmaid: Gad, and Asher: these are the sons of Jacob, which were born to him in Padanaram.'); +INSERT INTO t1(docid,words) VALUES(1035027,'And Jacob came unto Isaac his father unto Mamre, unto the city of Arbah, which is Hebron, where Abraham and Isaac sojourned.'); +INSERT INTO t1(docid,words) VALUES(1035028,'And the days of Isaac were an hundred and fourscore years.'); +INSERT INTO t1(docid,words) VALUES(1035029,'And Isaac gave up the ghost, and died, and was gathered unto his people, being old and full of days: and his sons Esau and Jacob buried him.'); +INSERT INTO t1(docid,words) VALUES(1036001,'Now these are the generations of Esau, who is Edom.'); +INSERT INTO t1(docid,words) VALUES(1036002,'Esau took his wives of the daughters of Canaan; Adah the daughter of Elon the Hittite, and Aholibamah the daughter of Anah the daughter of Zibeon the Hivite;'); +INSERT INTO t1(docid,words) VALUES(1036003,'And Bashemath Ishmael''s daughter, sister of Nebajoth.'); +INSERT INTO t1(docid,words) VALUES(1036004,'And Adah bare to Esau Eliphaz; and Bashemath bare Reuel;'); +INSERT INTO t1(docid,words) VALUES(1036005,'And Aholibamah bare Jeush, and Jaalam, and Korah: these are the sons of Esau, which were born unto him in the land of Canaan.'); +INSERT INTO t1(docid,words) VALUES(1036006,'And Esau took his wives, and his sons, and his daughters, and all the persons of his house, and his cattle, and all his beasts, and all his substance, which he had got in the land of Canaan; and went into the country from the face of his brother Jacob.'); +INSERT INTO t1(docid,words) VALUES(1036007,'For their riches were more than that they might dwell together; and the land wherein they were strangers could not bear them because of their cattle.'); +INSERT INTO t1(docid,words) VALUES(1036008,'Thus dwelt Esau in mount Seir: Esau is Edom.'); +INSERT INTO t1(docid,words) VALUES(1036009,'And these are the generations of Esau the father of the Edomites in mount Seir:'); +INSERT INTO t1(docid,words) VALUES(1036010,'These are the names of Esau''s sons; Eliphaz the son of Adah the wife of Esau, Reuel the son of Bashemath the wife of Esau.'); +INSERT INTO t1(docid,words) VALUES(1036011,'And the sons of Eliphaz were Teman, Omar, Zepho, and Gatam, and Kenaz.'); +INSERT INTO t1(docid,words) VALUES(1036012,'And Timna was concubine to Eliphaz Esau''s son; and she bare to Eliphaz Amalek: these were the sons of Adah Esau''s wife.'); +INSERT INTO t1(docid,words) VALUES(1036013,'And these are the sons of Reuel; Nahath, and Zerah, Shammah, and Mizzah: these were the sons of Bashemath Esau''s wife.'); +INSERT INTO t1(docid,words) VALUES(1036014,'And these were the sons of Aholibamah, the daughter of Anah the daughter of Zibeon, Esau''s wife: and she bare to Esau Jeush, and Jaalam, and Korah.'); +INSERT INTO t1(docid,words) VALUES(1036015,'These were dukes of the sons of Esau: the sons of Eliphaz the firstborn son of Esau; duke Teman, duke Omar, duke Zepho, duke Kenaz,'); +INSERT INTO t1(docid,words) VALUES(1036016,'Duke Korah, duke Gatam, and duke Amalek: these are the dukes that came of Eliphaz in the land of Edom; these were the sons of Adah.'); +INSERT INTO t1(docid,words) VALUES(1036017,'And these are the sons of Reuel Esau''s son; duke Nahath, duke Zerah, duke Shammah, duke Mizzah: these are the dukes that came of Reuel in the land of Edom; these are the sons of Bashemath Esau''s wife.'); +INSERT INTO t1(docid,words) VALUES(1036018,'And these are the sons of Aholibamah Esau''s wife; duke Jeush, duke Jaalam, duke Korah: these were the dukes that came of Aholibamah the daughter of Anah, Esau''s wife.'); +INSERT INTO t1(docid,words) VALUES(1036019,'These are the sons of Esau, who is Edom, and these are their dukes.'); +INSERT INTO t1(docid,words) VALUES(1036020,'These are the sons of Seir the Horite, who inhabited the land; Lotan, and Shobal, and Zibeon, and Anah,'); +INSERT INTO t1(docid,words) VALUES(1036021,'And Dishon, and Ezer, and Dishan: these are the dukes of the Horites, the children of Seir in the land of Edom.'); +INSERT INTO t1(docid,words) VALUES(1036022,'And the children of Lotan were Hori and Hemam; and Lotan''s sister was Timna.'); +INSERT INTO t1(docid,words) VALUES(1036023,'And the children of Shobal were these; Alvan, and Manahath, and Ebal, Shepho, and Onam.'); +INSERT INTO t1(docid,words) VALUES(1036024,'And these are the children of Zibeon; both Ajah, and Anah: this was that Anah that found the mules in the wilderness, as he fed the asses of Zibeon his father.'); +INSERT INTO t1(docid,words) VALUES(1036025,'And the children of Anah were these; Dishon, and Aholibamah the daughter of Anah.'); +INSERT INTO t1(docid,words) VALUES(1036026,'And these are the children of Dishon; Hemdan, and Eshban, and Ithran, and Cheran.'); +INSERT INTO t1(docid,words) VALUES(1036027,'The children of Ezer are these; Bilhan, and Zaavan, and Akan.'); +INSERT INTO t1(docid,words) VALUES(1036028,'The children of Dishan are these; Uz, and Aran.'); +INSERT INTO t1(docid,words) VALUES(1036029,'These are the dukes that came of the Horites; duke Lotan, duke Shobal, duke Zibeon, duke Anah,'); +INSERT INTO t1(docid,words) VALUES(1036030,'Duke Dishon, duke Ezer, duke Dishan: these are the dukes that came of Hori, among their dukes in the land of Seir.'); +INSERT INTO t1(docid,words) VALUES(1036031,'And these are the kings that reigned in the land of Edom, before there reigned any king over the children of Israel.'); +INSERT INTO t1(docid,words) VALUES(1036032,'And Bela the son of Beor reigned in Edom: and the name of his city was Dinhabah.'); +INSERT INTO t1(docid,words) VALUES(1036033,'And Bela died, and Jobab the son of Zerah of Bozrah reigned in his stead.'); +INSERT INTO t1(docid,words) VALUES(1036034,'And Jobab died, and Husham of the land of Temani reigned in his stead.'); +INSERT INTO t1(docid,words) VALUES(1036035,'And Husham died, and Hadad the son of Bedad, who smote Midian in the field of Moab, reigned in his stead: and the name of his city was Avith.'); +INSERT INTO t1(docid,words) VALUES(1036036,'And Hadad died, and Samlah of Masrekah reigned in his stead.'); +INSERT INTO t1(docid,words) VALUES(1036037,'And Samlah died, and Saul of Rehoboth by the river reigned in his stead.'); +INSERT INTO t1(docid,words) VALUES(1036038,'And Saul died, and Baalhanan the son of Achbor reigned in his stead.'); +INSERT INTO t1(docid,words) VALUES(1036039,'And Baalhanan the son of Achbor died, and Hadar reigned in his stead: and the name of his city was Pau; and his wife''s name was Mehetabel, the daughter of Matred, the daughter of Mezahab.'); +INSERT INTO t1(docid,words) VALUES(1036040,'And these are the names of the dukes that came of Esau, according to their families, after their places, by their names; duke Timnah, duke Alvah, duke Jetheth,'); +INSERT INTO t1(docid,words) VALUES(1036041,'Duke Aholibamah, duke Elah, duke Pinon,'); +INSERT INTO t1(docid,words) VALUES(1036042,'Duke Kenaz, duke Teman, duke Mibzar,'); +INSERT INTO t1(docid,words) VALUES(1036043,'Duke Magdiel, duke Iram: these be the dukes of Edom, according to their habitations in the land of their possession: he is Esau the father of the Edomites.'); +INSERT INTO t1(docid,words) VALUES(1037001,'And Jacob dwelt in the land wherein his father was a stranger, in the land of Canaan.'); +INSERT INTO t1(docid,words) VALUES(1037002,'These are the generations of Jacob. Joseph, being seventeen years old, was feeding the flock with his brethren; and the lad was with the sons of Bilhah, and with the sons of Zilpah, his father''s wives: and Joseph brought unto his father their evil report.'); +INSERT INTO t1(docid,words) VALUES(1037003,'Now Israel loved Joseph more than all his children, because he was the son of his old age: and he made him a coat of many colours.'); +INSERT INTO t1(docid,words) VALUES(1037004,'And when his brethren saw that their father loved him more than all his brethren, they hated him, and could not speak peaceably unto him.'); +INSERT INTO t1(docid,words) VALUES(1037005,'And Joseph dreamed a dream, and he told it his brethren: and they hated him yet the more.'); +INSERT INTO t1(docid,words) VALUES(1037006,'And he said unto them, Hear, I pray you, this dream which I have dreamed:'); +INSERT INTO t1(docid,words) VALUES(1037007,'For, behold, we were binding sheaves in the field, and, lo, my sheaf arose, and also stood upright; and, behold, your sheaves stood round about, and made obeisance to my sheaf.'); +INSERT INTO t1(docid,words) VALUES(1037008,'And his brethren said to him, Shalt thou indeed reign over us? or shalt thou indeed have dominion over us? And they hated him yet the more for his dreams, and for his words.'); +INSERT INTO t1(docid,words) VALUES(1037009,'And he dreamed yet another dream, and told it his brethren, and said, Behold, I have dreamed a dream more; and, behold, the sun and the moon and the eleven stars made obeisance to me.'); +INSERT INTO t1(docid,words) VALUES(1037010,'And he told it to his father, and to his brethren: and his father rebuked him, and said unto him, What is this dream that thou hast dreamed? Shall I and thy mother and thy brethren indeed come to bow down ourselves to thee to the earth?'); +INSERT INTO t1(docid,words) VALUES(1037011,'And his brethren envied him; but his father observed the saying.'); +INSERT INTO t1(docid,words) VALUES(1037012,'And his brethren went to feed their father''s flock in Shechem.'); +INSERT INTO t1(docid,words) VALUES(1037013,'And Israel said unto Joseph, Do not thy brethren feed the flock in Shechem? come, and I will send thee unto them. And he said to him, Here am I.'); +INSERT INTO t1(docid,words) VALUES(1037014,'And he said to him, Go, I pray thee, see whether it be well with thy brethren, and well with the flocks; and bring me word again. So he sent him out of the vale of Hebron, and he came to Shechem.'); +INSERT INTO t1(docid,words) VALUES(1037015,'And a certain man found him, and, behold, he was wandering in the field: and the man asked him, saying, What seekest thou?'); +INSERT INTO t1(docid,words) VALUES(1037016,'And he said, I seek my brethren: tell me, I pray thee, where they feed their flocks.'); +INSERT INTO t1(docid,words) VALUES(1037017,'And the man said, They are departed hence; for I heard them say, Let us go to Dothan. And Joseph went after his brethren, and found them in Dothan.'); +INSERT INTO t1(docid,words) VALUES(1037018,'And when they saw him afar off, even before he came near unto them, they conspired against him to slay him.'); +INSERT INTO t1(docid,words) VALUES(1037019,'And they said one to another, Behold, this dreamer cometh.'); +INSERT INTO t1(docid,words) VALUES(1037020,'Come now therefore, and let us slay him, and cast him into some pit, and we will say, Some evil beast hath devoured him: and we shall see what will become of his dreams.'); +INSERT INTO t1(docid,words) VALUES(1037021,'And Reuben heard it, and he delivered him out of their hands; and said, Let us not kill him.'); +INSERT INTO t1(docid,words) VALUES(1037022,'And Reuben said unto them, Shed no blood, but cast him into this pit that is in the wilderness, and lay no hand upon him; that he might rid him out of their hands, to deliver him to his father again.'); +INSERT INTO t1(docid,words) VALUES(1037023,'And it came to pass, when Joseph was come unto his brethren, that they stript Joseph out of his coat, his coat of many colours that was on him;'); +INSERT INTO t1(docid,words) VALUES(1037024,'And they took him, and cast him into a pit: and the pit was empty, there was no water in it.'); +INSERT INTO t1(docid,words) VALUES(1037025,'And they sat down to eat bread: and they lifted up their eyes and looked, and, behold, a company of Ishmeelites came from Gilead with their camels bearing spicery and balm and myrrh, going to carry it down to Egypt.'); +INSERT INTO t1(docid,words) VALUES(1037026,'And Judah said unto his brethren, What profit is it if we slay our brother, and conceal his blood?'); +INSERT INTO t1(docid,words) VALUES(1037027,'Come, and let us sell him to the Ishmeelites, and let not our hand be upon him; for he is our brother and our flesh. And his brethren were content.'); +INSERT INTO t1(docid,words) VALUES(1037028,'Then there passed by Midianites merchantmen; and they drew and lifted up Joseph out of the pit, and sold Joseph to the Ishmeelites for twenty pieces of silver: and they brought Joseph into Egypt.'); +INSERT INTO t1(docid,words) VALUES(1037029,'And Reuben returned unto the pit; and, behold, Joseph was not in the pit; and he rent his clothes.'); +INSERT INTO t1(docid,words) VALUES(1037030,'And he returned unto his brethren, and said, The child is not; and I, whither shall I go?'); +INSERT INTO t1(docid,words) VALUES(1037031,'And they took Joseph''s coat, and killed a kid of the goats, and dipped the coat in the blood;'); +INSERT INTO t1(docid,words) VALUES(1037032,'And they sent the coat of many colours, and they brought it to their father; and said, This have we found: know now whether it be thy son''s coat or no.'); +INSERT INTO t1(docid,words) VALUES(1037033,'And he knew it, and said, It is my son''s coat; an evil beast hath devoured him; Joseph is without doubt rent in pieces.'); +INSERT INTO t1(docid,words) VALUES(1037034,'And Jacob rent his clothes, and put sackcloth upon his loins, and mourned for his son many days.'); +INSERT INTO t1(docid,words) VALUES(1037035,'And all his sons and all his daughters rose up to comfort him; but he refused to be comforted; and he said, For I will go down into the grave unto my son mourning. Thus his father wept for him.'); +INSERT INTO t1(docid,words) VALUES(1037036,'And the Midianites sold him into Egypt unto Potiphar, an officer of Pharaoh''s, and captain of the guard.'); +INSERT INTO t1(docid,words) VALUES(1038001,'And it came to pass at that time, that Judah went down from his brethren, and turned in to a certain Adullamite, whose name was Hirah.'); +INSERT INTO t1(docid,words) VALUES(1038002,'And Judah saw there a daughter of a certain Canaanite, whose name was Shuah; and he took her, and went in unto her.'); +INSERT INTO t1(docid,words) VALUES(1038003,'And she conceived, and bare a son; and he called his name Er.'); +INSERT INTO t1(docid,words) VALUES(1038004,'And she conceived again, and bare a son; and she called his name Onan.'); +INSERT INTO t1(docid,words) VALUES(1038005,'And she yet again conceived, and bare a son; and called his name Shelah: and he was at Chezib, when she bare him.'); +INSERT INTO t1(docid,words) VALUES(1038006,'And Judah took a wife for Er his firstborn, whose name was Tamar.'); +INSERT INTO t1(docid,words) VALUES(1038007,'And Er, Judah''s firstborn, was wicked in the sight of the LORD; and the LORD slew him.'); +INSERT INTO t1(docid,words) VALUES(1038008,'And Judah said unto Onan, Go in unto thy brother''s wife, and marry her, and raise up seed to thy brother.'); +INSERT INTO t1(docid,words) VALUES(1038009,'And Onan knew that the seed should not be his; and it came to pass, when he went in unto his brother''s wife, that he spilled it on the ground, lest that he should give seed to his brother.'); +INSERT INTO t1(docid,words) VALUES(1038010,'And the thing which he did displeased the LORD: wherefore he slew him also.'); +INSERT INTO t1(docid,words) VALUES(1038011,'Then said Judah to Tamar his daughter in law, Remain a widow at thy father''s house, till Shelah my son be grown: for he said, Lest peradventure he die also, as his brethren did. And Tamar went and dwelt in her father''s house.'); +INSERT INTO t1(docid,words) VALUES(1038012,'And in process of time the daughter of Shuah Judah''s wife died; and Judah was comforted, and went up unto his sheepshearers to Timnath, he and his friend Hirah the Adullamite.'); +INSERT INTO t1(docid,words) VALUES(1038013,'And it was told Tamar, saying, Behold thy father in law goeth up to Timnath to shear his sheep.'); +INSERT INTO t1(docid,words) VALUES(1038014,'And she put her widow''s garments off from her, and covered her with a vail, and wrapped herself, and sat in an open place, which is by the way to Timnath; for she saw that Shelah was grown, and she was not given unto him to wife.'); +INSERT INTO t1(docid,words) VALUES(1038015,'When Judah saw her, he thought her to be an harlot; because she had covered her face.'); +INSERT INTO t1(docid,words) VALUES(1038016,'And he turned unto her by the way, and said, Go to, I pray thee, let me come in unto thee; (for he knew not that she was his daughter in law.) And she said, What wilt thou give me, that thou mayest come in unto me?'); +INSERT INTO t1(docid,words) VALUES(1038017,'And he said, I will send thee a kid from the flock. And she said, Wilt thou give me a pledge, till thou send it?'); +INSERT INTO t1(docid,words) VALUES(1038018,'And he said, What pledge shall I give thee? And she said, Thy signet, and thy bracelets, and thy staff that is in thine hand. And he gave it her, and came in unto her, and she conceived by him.'); +INSERT INTO t1(docid,words) VALUES(1038019,'And she arose, and went away, and laid by her vail from her, and put on the garments of her widowhood.'); +INSERT INTO t1(docid,words) VALUES(1038020,'And Judah sent the kid by the hand of his friend the Adullamite, to receive his pledge from the woman''s hand: but he found her not.'); +INSERT INTO t1(docid,words) VALUES(1038021,'Then he asked the men of that place, saying, Where is the harlot, that was openly by the way side? And they said, There was no harlot in this place.'); +INSERT INTO t1(docid,words) VALUES(1038022,'And he returned to Judah, and said, I cannot find her; and also the men of the place said, that there was no harlot in this place.'); +INSERT INTO t1(docid,words) VALUES(1038023,'And Judah said, Let her take it to her, lest we be shamed: behold, I sent this kid, and thou hast not found her.'); +INSERT INTO t1(docid,words) VALUES(1038024,'And it came to pass about three months after, that it was told Judah, saying, Tamar thy daughter in law hath played the harlot; and also, behold, she is with child by whoredom. And Judah said, Bring her forth, and let her be burnt.'); +INSERT INTO t1(docid,words) VALUES(1038025,'When she was brought forth, she sent to her father in law, saying, By the man, whose these are, am I with child: and she said, Discern, I pray thee, whose are these, the signet, and bracelets, and staff.'); +INSERT INTO t1(docid,words) VALUES(1038026,'And Judah acknowledged them, and said, She hath been more righteous than I; because that I gave her not to Shelah my son. And he knew her again no more.'); +INSERT INTO t1(docid,words) VALUES(1038027,'And it came to pass in the time of her travail, that, behold, twins were in her womb.'); +INSERT INTO t1(docid,words) VALUES(1038028,'And it came to pass, when she travailed, that the one put out his hand: and the midwife took and bound upon his hand a scarlet thread, saying, This came out first.'); +INSERT INTO t1(docid,words) VALUES(1038029,'And it came to pass, as he drew back his hand, that, behold, his brother came out: and she said, How hast thou broken forth? this breach be upon thee: therefore his name was called Pharez.'); +INSERT INTO t1(docid,words) VALUES(1038030,'And afterward came out his brother, that had the scarlet thread upon his hand: and his name was called Zarah.'); +INSERT INTO t1(docid,words) VALUES(1039001,'And Joseph was brought down to Egypt; and Potiphar, an officer of Pharaoh, captain of the guard, an Egyptian, bought him of the hands of the Ishmeelites, which had brought him down thither.'); +INSERT INTO t1(docid,words) VALUES(1039002,'And the LORD was with Joseph, and he was a prosperous man; and he was in the house of his master the Egyptian.'); +INSERT INTO t1(docid,words) VALUES(1039003,'And his master saw that the LORD was with him, and that the LORD made all that he did to prosper in his hand.'); +INSERT INTO t1(docid,words) VALUES(1039004,'And Joseph found grace in his sight, and he served him: and he made him overseer over his house, and all that he had he put into his hand.'); +INSERT INTO t1(docid,words) VALUES(1039005,'And it came to pass from the time that he had made him overseer in his house, and over all that he had, that the LORD blessed the Egyptian''s house for Joseph''s sake; and the blessing of the LORD was upon all that he had in the house, and in the field.'); +INSERT INTO t1(docid,words) VALUES(1039006,'And he left all that he had in Joseph''s hand; and he knew not ought he had, save the bread which he did eat. And Joseph was a goodly person, and well favoured.'); +INSERT INTO t1(docid,words) VALUES(1039007,'And it came to pass after these things, that his master''s wife cast her eyes upon Joseph; and she said, Lie with me.'); +INSERT INTO t1(docid,words) VALUES(1039008,'But he refused, and said unto his master''s wife, Behold, my master wotteth not what is with me in the house, and he hath committed all that he hath to my hand;'); +INSERT INTO t1(docid,words) VALUES(1039009,'There is none greater in this house than I; neither hath he kept back any thing from me but thee, because thou art his wife: how then can I do this great wickedness, and sin against God?'); +INSERT INTO t1(docid,words) VALUES(1039010,'And it came to pass, as she spake to Joseph day by day, that he hearkened not unto her, to lie by her, or to be with her.'); +INSERT INTO t1(docid,words) VALUES(1039011,'And it came to pass about this time, that Joseph went into the house to do his business; and there was none of the men of the house there within.'); +INSERT INTO t1(docid,words) VALUES(1039012,'And she caught him by his garment, saying, Lie with me: and he left his garment in her hand, and fled, and got him out.'); +INSERT INTO t1(docid,words) VALUES(1039013,'And it came to pass, when she saw that he had left his garment in her hand, and was fled forth,'); +INSERT INTO t1(docid,words) VALUES(1039014,'That she called unto the men of her house, and spake unto them, saying, See, he hath brought in an Hebrew unto us to mock us; he came in unto me to lie with me, and I cried with a loud voice:'); +INSERT INTO t1(docid,words) VALUES(1039015,'And it came to pass, when he heard that I lifted up my voice and cried, that he left his garment with me, and fled, and got him out.'); +INSERT INTO t1(docid,words) VALUES(1039016,'And she laid up his garment by her, until his lord came home.'); +INSERT INTO t1(docid,words) VALUES(1039017,'And she spake unto him according to these words, saying, The Hebrew servant, which thou hast brought unto us, came in unto me to mock me:'); +INSERT INTO t1(docid,words) VALUES(1039018,'And it came to pass, as I lifted up my voice and cried, that he left his garment with me, and fled out.'); +INSERT INTO t1(docid,words) VALUES(1039019,'And it came to pass, when his master heard the words of his wife, which she spake unto him, saying, After this manner did thy servant to me; that his wrath was kindled.'); +INSERT INTO t1(docid,words) VALUES(1039020,'And Joseph''s master took him, and put him into the prison, a place where the king''s prisoners were bound: and he was there in the prison.'); +INSERT INTO t1(docid,words) VALUES(1039021,'But the LORD was with Joseph, and shewed him mercy, and gave him favour in the sight of the keeper of the prison.'); +INSERT INTO t1(docid,words) VALUES(1039022,'And the keeper of the prison committed to Joseph''s hand all the prisoners that were in the prison; and whatsoever they did there, he was the doer of it.'); +INSERT INTO t1(docid,words) VALUES(1039023,'The keeper of the prison looked not to any thing that was under his hand; because the LORD was with him, and that which he did, the LORD made it to prosper.'); +INSERT INTO t1(docid,words) VALUES(1040001,'And it came to pass after these things, that the butler of the king of Egypt and his baker had offended their lord the king of Egypt.'); +INSERT INTO t1(docid,words) VALUES(1040002,'And Pharaoh was wroth against two of his officers, against the chief of the butlers, and against the chief of the bakers.'); +INSERT INTO t1(docid,words) VALUES(1040003,'And he put them in ward in the house of the captain of the guard, into the prison, the place where Joseph was bound.'); +INSERT INTO t1(docid,words) VALUES(1040004,'And the captain of the guard charged Joseph with them, and he served them: and they continued a season in ward.'); +INSERT INTO t1(docid,words) VALUES(1040005,'And they dreamed a dream both of them, each man his dream in one night, each man according to the interpretation of his dream, the butler and the baker of the king of Egypt, which were bound in the prison.'); +INSERT INTO t1(docid,words) VALUES(1040006,'And Joseph came in unto them in the morning, and looked upon them, and, behold, they were sad.'); +INSERT INTO t1(docid,words) VALUES(1040007,'And he asked Pharaoh''s officers that were with him in the ward of his lord''s house, saying, Wherefore look ye so sadly to day?'); +INSERT INTO t1(docid,words) VALUES(1040008,'And they said unto him, We have dreamed a dream, and there is no interpreter of it. And Joseph said unto them, Do not interpretations belong to God? tell me them, I pray you.'); +INSERT INTO t1(docid,words) VALUES(1040009,'And the chief butler told his dream to Joseph, and said to him, In my dream, behold, a vine was before me;'); +INSERT INTO t1(docid,words) VALUES(1040010,'And in the vine were three branches: and it was as though it budded, and her blossoms shot forth; and the clusters thereof brought forth ripe grapes:'); +INSERT INTO t1(docid,words) VALUES(1040011,'And Pharaoh''s cup was in my hand: and I took the grapes, and pressed them into Pharaoh''s cup, and I gave the cup into Pharaoh''s hand.'); +INSERT INTO t1(docid,words) VALUES(1040012,'And Joseph said unto him, This is the interpretation of it: The three branches are three days:'); +INSERT INTO t1(docid,words) VALUES(1040013,'Yet within three days shall Pharaoh lift up thine head, and restore thee unto thy place: and thou shalt deliver Pharaoh''s cup into his hand, after the former manner when thou wast his butler.'); +INSERT INTO t1(docid,words) VALUES(1040014,'But think on me when it shall be well with thee, and shew kindness, I pray thee, unto me, and make mention of me unto Pharaoh, and bring me out of this house:'); +INSERT INTO t1(docid,words) VALUES(1040015,'For indeed I was stolen away out of the land of the Hebrews: and here also have I done nothing that they should put me into the dungeon.'); +INSERT INTO t1(docid,words) VALUES(1040016,'When the chief baker saw that the interpretation was good, he said unto Joseph, I also was in my dream, and, behold, I had three white baskets on my head:'); +INSERT INTO t1(docid,words) VALUES(1040017,'And in the uppermost basket there was of all manner of bakemeats for Pharaoh; and the birds did eat them out of the basket upon my head.'); +INSERT INTO t1(docid,words) VALUES(1040018,'And Joseph answered and said, This is the interpretation thereof: The three baskets are three days:'); +INSERT INTO t1(docid,words) VALUES(1040019,'Yet within three days shall Pharaoh lift up thy head from off thee, and shall hang thee on a tree; and the birds shall eat thy flesh from off thee.'); +INSERT INTO t1(docid,words) VALUES(1040020,'And it came to pass the third day, which was Pharaoh''s birthday, that he made a feast unto all his servants: and he lifted up the head of the chief butler and of the chief baker among his servants.'); +INSERT INTO t1(docid,words) VALUES(1040021,'And he restored the chief butler unto his butlership again; and he gave the cup into Pharaoh''s hand:'); +INSERT INTO t1(docid,words) VALUES(1040022,'But he hanged the chief baker: as Joseph had interpreted to them.'); +INSERT INTO t1(docid,words) VALUES(1040023,'Yet did not the chief butler remember Joseph, but forgat him.'); +INSERT INTO t1(docid,words) VALUES(1041001,'And it came to pass at the end of two full years, that Pharaoh dreamed: and, behold, he stood by the river.'); +INSERT INTO t1(docid,words) VALUES(1041002,'And, behold, there came up out of the river seven well favoured kine and fatfleshed; and they fed in a meadow.'); +INSERT INTO t1(docid,words) VALUES(1041003,'And, behold, seven other kine came up after them out of the river, ill favoured and leanfleshed; and stood by the other kine upon the brink of the river.'); +INSERT INTO t1(docid,words) VALUES(1041004,'And the ill favoured and leanfleshed kine did eat up the seven well favoured and fat kine. So Pharaoh awoke.'); +INSERT INTO t1(docid,words) VALUES(1041005,'And he slept and dreamed the second time: and, behold, seven ears of corn came up upon one stalk, rank and good.'); +INSERT INTO t1(docid,words) VALUES(1041006,'And, behold, seven thin ears and blasted with the east wind sprung up after them.'); +INSERT INTO t1(docid,words) VALUES(1041007,'And the seven thin ears devoured the seven rank and full ears. And Pharaoh awoke, and, behold, it was a dream.'); +INSERT INTO t1(docid,words) VALUES(1041008,'And it came to pass in the morning that his spirit was troubled; and he sent and called for all the magicians of Egypt, and all the wise men thereof: and Pharaoh told them his dream; but there was none that could interpret them unto Pharaoh.'); +INSERT INTO t1(docid,words) VALUES(1041009,'Then spake the chief butler unto Pharaoh, saying, I do remember my faults this day:'); +INSERT INTO t1(docid,words) VALUES(1041010,'Pharaoh was wroth with his servants, and put me in ward in the captain of the guard''s house, both me and the chief baker:'); +INSERT INTO t1(docid,words) VALUES(1041011,'And we dreamed a dream in one night, I and he; we dreamed each man according to the interpretation of his dream.'); +INSERT INTO t1(docid,words) VALUES(1041012,'And there was there with us a young man, an Hebrew, servant to the captain of the guard; and we told him, and he interpreted to us our dreams; to each man according to his dream he did interpret.'); +INSERT INTO t1(docid,words) VALUES(1041013,'And it came to pass, as he interpreted to us, so it was; me he restored unto mine office, and him he hanged.'); +INSERT INTO t1(docid,words) VALUES(1041014,'Then Pharaoh sent and called Joseph, and they brought him hastily out of the dungeon: and he shaved himself, and changed his raiment, and came in unto Pharaoh.'); +INSERT INTO t1(docid,words) VALUES(1041015,'And Pharaoh said unto Joseph, I have dreamed a dream, and there is none that can interpret it: and I have heard say of thee, that thou canst understand a dream to interpret it.'); +INSERT INTO t1(docid,words) VALUES(1041016,'And Joseph answered Pharaoh, saying, It is not in me: God shall give Pharaoh an answer of peace.'); +INSERT INTO t1(docid,words) VALUES(1041017,'And Pharaoh said unto Joseph, In my dream, behold, I stood upon the bank of the river:'); +INSERT INTO t1(docid,words) VALUES(1041018,'And, behold, there came up out of the river seven kine, fatfleshed and well favoured; and they fed in a meadow:'); +INSERT INTO t1(docid,words) VALUES(1041019,'And, behold, seven other kine came up after them, poor and very ill favoured and leanfleshed, such as I never saw in all the land of Egypt for badness:'); +INSERT INTO t1(docid,words) VALUES(1041020,'And the lean and the ill favoured kine did eat up the first seven fat kine:'); +INSERT INTO t1(docid,words) VALUES(1041021,'And when they had eaten them up, it could not be known that they had eaten them; but they were still ill favoured, as at the beginning. So I awoke.'); +INSERT INTO t1(docid,words) VALUES(1041022,'And I saw in my dream, and, behold, seven ears came up in one stalk, full and good:'); +INSERT INTO t1(docid,words) VALUES(1041023,'And, behold, seven ears, withered, thin, and blasted with the east wind, sprung up after them:'); +INSERT INTO t1(docid,words) VALUES(1041024,'And the thin ears devoured the seven good ears: and I told this unto the magicians; but there was none that could declare it to me.'); +INSERT INTO t1(docid,words) VALUES(1041025,'And Joseph said unto Pharaoh, The dream of Pharaoh is one: God hath shewed Pharaoh what he is about to do.'); +INSERT INTO t1(docid,words) VALUES(1041026,'The seven good kine are seven years; and the seven good ears are seven years: the dream is one.'); +INSERT INTO t1(docid,words) VALUES(1041027,'And the seven thin and ill favoured kine that came up after them are seven years; and the seven empty ears blasted with the east wind shall be seven years of famine.'); +INSERT INTO t1(docid,words) VALUES(1041028,'This is the thing which I have spoken unto Pharaoh: What God is about to do he sheweth unto Pharaoh.'); +INSERT INTO t1(docid,words) VALUES(1041029,'Behold, there come seven years of great plenty throughout all the land of Egypt:'); +INSERT INTO t1(docid,words) VALUES(1041030,'And there shall arise after them seven years of famine; and all the plenty shall be forgotten in the land of Egypt; and the famine shall consume the land;'); +INSERT INTO t1(docid,words) VALUES(1041031,'And the plenty shall not be known in the land by reason of that famine following; for it shall be very grievous.'); +INSERT INTO t1(docid,words) VALUES(1041032,'And for that the dream was doubled unto Pharaoh twice; it is because the thing is established by God, and God will shortly bring it to pass.'); +INSERT INTO t1(docid,words) VALUES(1041033,'Now therefore let Pharaoh look out a man discreet and wise, and set him over the land of Egypt.'); +INSERT INTO t1(docid,words) VALUES(1041034,'Let Pharaoh do this, and let him appoint officers over the land, and take up the fifth part of the land of Egypt in the seven plenteous years.'); +INSERT INTO t1(docid,words) VALUES(1041035,'And let them gather all the food of those good years that come, and lay up corn under the hand of Pharaoh, and let them keep food in the cities.'); +INSERT INTO t1(docid,words) VALUES(1041036,'And that food shall be for store to the land against the seven years of famine, which shall be in the land of Egypt; that the land perish not through the famine.'); +INSERT INTO t1(docid,words) VALUES(1041037,'And the thing was good in the eyes of Pharaoh, and in the eyes of all his servants.'); +INSERT INTO t1(docid,words) VALUES(1041038,'And Pharaoh said unto his servants, Can we find such a one as this is, a man in whom the Spirit of God is?'); +INSERT INTO t1(docid,words) VALUES(1041039,'And Pharaoh said unto Joseph, Forasmuch as God hath shewed thee all this, there is none so discreet and wise as thou art:'); +INSERT INTO t1(docid,words) VALUES(1041040,'Thou shalt be over my house, and according unto thy word shall all my people be ruled: only in the throne will I be greater than thou.'); +INSERT INTO t1(docid,words) VALUES(1041041,'And Pharaoh said unto Joseph, See, I have set thee over all the land of Egypt.'); +INSERT INTO t1(docid,words) VALUES(1041042,'And Pharaoh took off his ring from his hand, and put it upon Joseph''s hand, and arrayed him in vestures of fine linen, and put a gold chain about his neck;'); +INSERT INTO t1(docid,words) VALUES(1041043,'And he made him to ride in the second chariot which he had; and they cried before him, Bow the knee: and he made him ruler over all the land of Egypt.'); +INSERT INTO t1(docid,words) VALUES(1041044,'And Pharaoh said unto Joseph, I am Pharaoh, and without thee shall no man lift up his hand or foot in all the land of Egypt.'); +INSERT INTO t1(docid,words) VALUES(1041045,'And Pharaoh called Joseph''s name Zaphnathpaaneah; and he gave him to wife Asenath the daughter of Potipherah priest of On. And Joseph went out over all the land of Egypt.'); +INSERT INTO t1(docid,words) VALUES(1041046,'And Joseph was thirty years old when he stood before Pharaoh king of Egypt. And Joseph went out from the presence of Pharaoh, and went throughout all the land of Egypt.'); +INSERT INTO t1(docid,words) VALUES(1041047,'And in the seven plenteous years the earth brought forth by handfuls.'); +INSERT INTO t1(docid,words) VALUES(1041048,'And he gathered up all the food of the seven years, which were in the land of Egypt, and laid up the food in the cities: the food of the field, which was round about every city, laid he up in the same.'); +INSERT INTO t1(docid,words) VALUES(1041049,'And Joseph gathered corn as the sand of the sea, very much, until he left numbering; for it was without number.'); +INSERT INTO t1(docid,words) VALUES(1041050,'And unto Joseph were born two sons before the years of famine came, which Asenath the daughter of Potipherah priest of On bare unto him.'); +INSERT INTO t1(docid,words) VALUES(1041051,'And Joseph called the name of the firstborn Manasseh: For God, said he, hath made me forget all my toil, and all my father''s house.'); +INSERT INTO t1(docid,words) VALUES(1041052,'And the name of the second called he Ephraim: For God hath caused me to be fruitful in the land of my affliction.'); +INSERT INTO t1(docid,words) VALUES(1041053,'And the seven years of plenteousness, that was in the land of Egypt, were ended.'); +INSERT INTO t1(docid,words) VALUES(1041054,'And the seven years of dearth began to come, according as Joseph had said: and the dearth was in all lands; but in all the land of Egypt there was bread.'); +INSERT INTO t1(docid,words) VALUES(1041055,'And when all the land of Egypt was famished, the people cried to Pharaoh for bread: and Pharaoh said unto all the Egyptians, Go unto Joseph; what he saith to you, do.'); +INSERT INTO t1(docid,words) VALUES(1041056,'And the famine was over all the face of the earth: and Joseph opened all the storehouses, and sold unto the Egyptians; and the famine waxed sore in the land of Egypt.'); +INSERT INTO t1(docid,words) VALUES(1041057,'And all countries came into Egypt to Joseph for to buy corn; because that the famine was so sore in all lands.'); +INSERT INTO t1(docid,words) VALUES(1042001,'Now when Jacob saw that there was corn in Egypt, Jacob said unto his sons, Why do ye look one upon another?'); +INSERT INTO t1(docid,words) VALUES(1042002,'And he said, Behold, I have heard that there is corn in Egypt: get you down thither, and buy for us from thence; that we may live, and not die.'); +INSERT INTO t1(docid,words) VALUES(1042003,'And Joseph''s ten brethren went down to buy corn in Egypt.'); +INSERT INTO t1(docid,words) VALUES(1042004,'But Benjamin, Joseph''s brother, Jacob sent not with his brethren; for he said, Lest peradventure mischief befall him.'); +INSERT INTO t1(docid,words) VALUES(1042005,'And the sons of Israel came to buy corn among those that came: for the famine was in the land of Canaan.'); +INSERT INTO t1(docid,words) VALUES(1042006,'And Joseph was the governor over the land, and he it was that sold to all the people of the land: and Joseph''s brethren came, and bowed down themselves before him with their faces to the earth.'); +INSERT INTO t1(docid,words) VALUES(1042007,'And Joseph saw his brethren, and he knew them, but made himself strange unto them, and spake roughly unto them; and he said unto them, Whence come ye? And they said, From the land of Canaan to buy food.'); +INSERT INTO t1(docid,words) VALUES(1042008,'And Joseph knew his brethren, but they knew not him.'); +INSERT INTO t1(docid,words) VALUES(1042009,'And Joseph remembered the dreams which he dreamed of them, and said unto them, Ye are spies; to see the nakedness of the land ye are come.'); +INSERT INTO t1(docid,words) VALUES(1042010,'And they said unto him, Nay, my lord, but to buy food are thy servants come.'); +INSERT INTO t1(docid,words) VALUES(1042011,'We are all one man''s sons; we are true men, thy servants are no spies.'); +INSERT INTO t1(docid,words) VALUES(1042012,'And he said unto them, Nay, but to see the nakedness of the land ye are come.'); +INSERT INTO t1(docid,words) VALUES(1042013,'And they said, Thy servants are twelve brethren, the sons of one man in the land of Canaan; and, behold, the youngest is this day with our father, and one is not.'); +INSERT INTO t1(docid,words) VALUES(1042014,'And Joseph said unto them, That is it that I spake unto you, saying, Ye are spies:'); +INSERT INTO t1(docid,words) VALUES(1042015,'Hereby ye shall be proved: By the life of Pharaoh ye shall not go forth hence, except your youngest brother come hither.'); +INSERT INTO t1(docid,words) VALUES(1042016,'Send one of you, and let him fetch your brother, and ye shall be kept in prison, that your words may be proved, whether there be any truth in you: or else by the life of Pharaoh surely ye are spies.'); +INSERT INTO t1(docid,words) VALUES(1042017,'And he put them all together into ward three days.'); +INSERT INTO t1(docid,words) VALUES(1042018,'And Joseph said unto them the third day, This do, and live; for I fear God:'); +INSERT INTO t1(docid,words) VALUES(1042019,'If ye be true men, let one of your brethren be bound in the house of your prison: go ye, carry corn for the famine of your houses:'); +INSERT INTO t1(docid,words) VALUES(1042020,'But bring your youngest brother unto me; so shall your words be verified, and ye shall not die. And they did so.'); +INSERT INTO t1(docid,words) VALUES(1042021,'And they said one to another, We are verily guilty concerning our brother, in that we saw the anguish of his soul, when he besought us, and we would not hear; therefore is this distress come upon us.'); +INSERT INTO t1(docid,words) VALUES(1042022,'And Reuben answered them, saying, Spake I not unto you, saying, Do not sin against the child; and ye would not hear? therefore, behold, also his blood is required.'); +INSERT INTO t1(docid,words) VALUES(1042023,'And they knew not that Joseph understood them; for he spake unto them by an interpreter.'); +INSERT INTO t1(docid,words) VALUES(1042024,'And he turned himself about from them, and wept; and returned to them again, and communed with them, and took from them Simeon, and bound him before their eyes.'); +INSERT INTO t1(docid,words) VALUES(1042025,'Then Joseph commanded to fill their sacks with corn, and to restore every man''s money into his sack, and to give them provision for the way: and thus did he unto them.'); +INSERT INTO t1(docid,words) VALUES(1042026,'And they laded their asses with the corn, and departed thence.'); +INSERT INTO t1(docid,words) VALUES(1042027,'And as one of them opened his sack to give his ass provender in the inn, he espied his money; for, behold, it was in his sack''s mouth.'); +INSERT INTO t1(docid,words) VALUES(1042028,'And he said unto his brethren, My money is restored; and, lo, it is even in my sack: and their heart failed them, and they were afraid, saying one to another, What is this that God hath done unto us?'); +INSERT INTO t1(docid,words) VALUES(1042029,'And they came unto Jacob their father unto the land of Canaan, and told him all that befell unto them; saying,'); +INSERT INTO t1(docid,words) VALUES(1042030,'The man, who is the lord of the land, spake roughly to us, and took us for spies of the country.'); +INSERT INTO t1(docid,words) VALUES(1042031,'And we said unto him, We are true men; we are no spies:'); +INSERT INTO t1(docid,words) VALUES(1042032,'We be twelve brethren, sons of our father; one is not, and the youngest is this day with our father in the land of Canaan.'); +INSERT INTO t1(docid,words) VALUES(1042033,'And the man, the lord of the country, said unto us, Hereby shall I know that ye are true men; leave one of your brethren here with me, and take food for the famine of your households, and be gone:'); +INSERT INTO t1(docid,words) VALUES(1042034,'And bring your youngest brother unto me: then shall I know that ye are no spies, but that ye are true men: so will I deliver you your brother, and ye shall traffick in the land.'); +INSERT INTO t1(docid,words) VALUES(1042035,'And it came to pass as they emptied their sacks, that, behold, every man''s bundle of money was in his sack: and when both they and their father saw the bundles of money, they were afraid.'); +INSERT INTO t1(docid,words) VALUES(1042036,'And Jacob their father said unto them, Me have ye bereaved of my children: Joseph is not, and Simeon is not, and ye will take Benjamin away: all these things are against me.'); +INSERT INTO t1(docid,words) VALUES(1042037,'And Reuben spake unto his father, saying, Slay my two sons, if I bring him not to thee: deliver him into my hand, and I will bring him to thee again.'); +INSERT INTO t1(docid,words) VALUES(1042038,'And he said, My son shall not go down with you; for his brother is dead, and he is left alone: if mischief befall him by the way in the which ye go, then shall ye bring down my gray hairs with sorrow to the grave.'); +INSERT INTO t1(docid,words) VALUES(1043001,'And the famine was sore in the land.'); +INSERT INTO t1(docid,words) VALUES(1043002,'And it came to pass, when they had eaten up the corn which they had brought out of Egypt, their father said unto them, Go again, buy us a little food.'); +INSERT INTO t1(docid,words) VALUES(1043003,'And Judah spake unto him, saying, The man did solemnly protest unto us, saying, Ye shall not see my face, except your brother be with you.'); +INSERT INTO t1(docid,words) VALUES(1043004,'If thou wilt send our brother with us, we will go down and buy thee food:'); +INSERT INTO t1(docid,words) VALUES(1043005,'But if thou wilt not send him, we will not go down: for the man said unto us, Ye shall not see my face, except your brother be with you.'); +INSERT INTO t1(docid,words) VALUES(1043006,'And Israel said, Wherefore dealt ye so ill with me, as to tell the man whether ye had yet a brother?'); +INSERT INTO t1(docid,words) VALUES(1043007,'And they said, The man asked us straitly of our state, and of our kindred, saying, Is your father yet alive? have ye another brother? and we told him according to the tenor of these words: could we certainly know that he would say, Bring your brother down?'); +INSERT INTO t1(docid,words) VALUES(1043008,'And Judah said unto Israel his father, Send the lad with me, and we will arise and go; that we may live, and not die, both we, and thou, and also our little ones.'); +INSERT INTO t1(docid,words) VALUES(1043009,'I will be surety for him; of my hand shalt thou require him: if I bring him not unto thee, and set him before thee, then let me bear the blame for ever:'); +INSERT INTO t1(docid,words) VALUES(1043010,'For except we had lingered, surely now we had returned this second time.'); +INSERT INTO t1(docid,words) VALUES(1043011,'And their father Israel said unto them, If it must be so now, do this; take of the best fruits in the land in your vessels, and carry down the man a present, a little balm, and a little honey, spices, and myrrh, nuts, and almonds:'); +INSERT INTO t1(docid,words) VALUES(1043012,'And take double money in your hand; and the money that was brought again in the mouth of your sacks, carry it again in your hand; peradventure it was an oversight:'); +INSERT INTO t1(docid,words) VALUES(1043013,'Take also your brother, and arise, go again unto the man:'); +INSERT INTO t1(docid,words) VALUES(1043014,'And God Almighty give you mercy before the man, that he may send away your other brother, and Benjamin. If I be bereaved of my children, I am bereaved.'); +INSERT INTO t1(docid,words) VALUES(1043015,'And the men took that present, and they took double money in their hand and Benjamin; and rose up, and went down to Egypt, and stood before Joseph.'); +INSERT INTO t1(docid,words) VALUES(1043016,'And when Joseph saw Benjamin with them, he said to the ruler of his house, Bring these men home, and slay, and make ready; for these men shall dine with me at noon.'); +INSERT INTO t1(docid,words) VALUES(1043017,'And the man did as Joseph bade; and the man brought the men into Joseph''s house.'); +INSERT INTO t1(docid,words) VALUES(1043018,'And the men were afraid, because they were brought into Joseph''s house; and they said, Because of the money that was returned in our sacks at the first time are we brought in; that he may seek occasion against us, and fall upon us, and take us for bondmen, and our asses.'); +INSERT INTO t1(docid,words) VALUES(1043019,'And they came near to the steward of Joseph''s house, and they communed with him at the door of the house,'); +INSERT INTO t1(docid,words) VALUES(1043020,'And said, O sir, we came indeed down at the first time to buy food:'); +INSERT INTO t1(docid,words) VALUES(1043021,'And it came to pass, when we came to the inn, that we opened our sacks, and, behold, every man''s money was in the mouth of his sack, our money in full weight: and we have brought it again in our hand.'); +INSERT INTO t1(docid,words) VALUES(1043022,'And other money have we brought down in our hands to buy food: we cannot tell who put our money in our sacks.'); +INSERT INTO t1(docid,words) VALUES(1043023,'And he said, Peace be to you, fear not: your God, and the God of your father, hath given you treasure in your sacks: I had your money. And he brought Simeon out unto them.'); +INSERT INTO t1(docid,words) VALUES(1043024,'And the man brought the men into Joseph''s house, and gave them water, and they washed their feet; and he gave their asses provender.'); +INSERT INTO t1(docid,words) VALUES(1043025,'And they made ready the present against Joseph came at noon: for they heard that they should eat bread there.'); +INSERT INTO t1(docid,words) VALUES(1043026,'And when Joseph came home, they brought him the present which was in their hand into the house, and bowed themselves to him to the earth.'); +INSERT INTO t1(docid,words) VALUES(1043027,'And he asked them of their welfare, and said, Is your father well, the old man of whom ye spake? Is he yet alive?'); +INSERT INTO t1(docid,words) VALUES(1043028,'And they answered, Thy servant our father is in good health, he is yet alive. And they bowed down their heads, and made obeisance.'); +INSERT INTO t1(docid,words) VALUES(1043029,'And he lifted up his eyes, and saw his brother Benjamin, his mother''s son, and said, Is this your younger brother, of whom ye spake unto me? And he said, God be gracious unto thee, my son.'); +INSERT INTO t1(docid,words) VALUES(1043030,'And Joseph made haste; for his bowels did yearn upon his brother: and he sought where to weep; and he entered into his chamber, and wept there.'); +INSERT INTO t1(docid,words) VALUES(1043031,'And he washed his face, and went out, and refrained himself, and said, Set on bread.'); +INSERT INTO t1(docid,words) VALUES(1043032,'And they set on for him by himself, and for them by themselves, and for the Egyptians, which did eat with him, by themselves: because the Egyptians might not eat bread with the Hebrews; for that is an abomination unto the Egyptians.'); +INSERT INTO t1(docid,words) VALUES(1043033,'And they sat before him, the firstborn according to his birthright, and the youngest according to his youth: and the men marvelled one at another.'); +INSERT INTO t1(docid,words) VALUES(1043034,'And he took and sent messes unto them from before him: but Benjamin''s mess was five times so much as any of their''s. And they drank, and were merry with him.'); +INSERT INTO t1(docid,words) VALUES(1044001,'And he commanded the steward of his house, saying, Fill the men''s sacks with food, as much as they can carry, and put every man''s money in his sack''s mouth.'); +INSERT INTO t1(docid,words) VALUES(1044002,'And put my cup, the silver cup, in the sack''s mouth of the youngest, and his corn money. And he did according to the word that Joseph had spoken.'); +INSERT INTO t1(docid,words) VALUES(1044003,'As soon as the morning was light, the men were sent away, they and their asses.'); +INSERT INTO t1(docid,words) VALUES(1044004,'And when they were gone out of the city, and not yet far off, Joseph said unto his steward, Up, follow after the men; and when thou dost overtake them, say unto them, Wherefore have ye rewarded evil for good?'); +INSERT INTO t1(docid,words) VALUES(1044005,'Is not this it in which my lord drinketh, and whereby indeed he divineth? ye have done evil in so doing.'); +INSERT INTO t1(docid,words) VALUES(1044006,'And he overtook them, and he spake unto them these same words.'); +INSERT INTO t1(docid,words) VALUES(1044007,'And they said unto him, Wherefore saith my lord these words? God forbid that thy servants should do according to this thing:'); +INSERT INTO t1(docid,words) VALUES(1044008,'Behold, the money, which we found in our sacks'' mouths, we brought again unto thee out of the land of Canaan: how then should we steal out of thy lord''s house silver or gold?'); +INSERT INTO t1(docid,words) VALUES(1044009,'With whomsoever of thy servants it be found, both let him die, and we also will be my lord''s bondmen.'); +INSERT INTO t1(docid,words) VALUES(1044010,'And he said, Now also let it be according unto your words: he with whom it is found shall be my servant; and ye shall be blameless.'); +INSERT INTO t1(docid,words) VALUES(1044011,'Then they speedily took down every man his sack to the ground, and opened every man his sack.'); +INSERT INTO t1(docid,words) VALUES(1044012,'And he searched, and began at the eldest, and left at the youngest: and the cup was found in Benjamin''s sack.'); +INSERT INTO t1(docid,words) VALUES(1044013,'Then they rent their clothes, and laded every man his ass, and returned to the city.'); +INSERT INTO t1(docid,words) VALUES(1044014,'And Judah and his brethren came to Joseph''s house; for he was yet there: and they fell before him on the ground.'); +INSERT INTO t1(docid,words) VALUES(1044015,'And Joseph said unto them, What deed is this that ye have done? wot ye not that such a man as I can certainly divine?'); +INSERT INTO t1(docid,words) VALUES(1044016,'And Judah said, What shall we say unto my lord? what shall we speak? or how shall we clear ourselves? God hath found out the iniquity of thy servants: behold, we are my lord''s servants, both we, and he also with whom the cup is found.'); +INSERT INTO t1(docid,words) VALUES(1044017,'And he said, God forbid that I should do so: but the man in whose hand the cup is found, he shall be my servant; and as for you, get you up in peace unto your father.'); +INSERT INTO t1(docid,words) VALUES(1044018,'Then Judah came near unto him, and said, Oh my lord, let thy servant, I pray thee, speak a word in my lord''s ears, and let not thine anger burn against thy servant: for thou art even as Pharaoh.'); +INSERT INTO t1(docid,words) VALUES(1044019,'My lord asked his servants, saying, Have ye a father, or a brother?'); +INSERT INTO t1(docid,words) VALUES(1044020,'And we said unto my lord, We have a father, an old man, and a child of his old age, a little one; and his brother is dead, and he alone is left of his mother, and his father loveth him.'); +INSERT INTO t1(docid,words) VALUES(1044021,'And thou saidst unto thy servants, Bring him down unto me, that I may set mine eyes upon him.'); +INSERT INTO t1(docid,words) VALUES(1044022,'And we said unto my lord, The lad cannot leave his father: for if he should leave his father, his father would die.'); +INSERT INTO t1(docid,words) VALUES(1044023,'And thou saidst unto thy servants, Except your youngest brother come down with you, ye shall see my face no more.'); +INSERT INTO t1(docid,words) VALUES(1044024,'And it came to pass when we came up unto thy servant my father, we told him the words of my lord.'); +INSERT INTO t1(docid,words) VALUES(1044025,'And our father said, Go again, and buy us a little food.'); +INSERT INTO t1(docid,words) VALUES(1044026,'And we said, We cannot go down: if our youngest brother be with us, then will we go down: for we may not see the man''s face, except our youngest brother be with us.'); +INSERT INTO t1(docid,words) VALUES(1044027,'And thy servant my father said unto us, Ye know that my wife bare me two sons:'); +INSERT INTO t1(docid,words) VALUES(1044028,'And the one went out from me, and I said, Surely he is torn in pieces; and I saw him not since:'); +INSERT INTO t1(docid,words) VALUES(1044029,'And if ye take this also from me, and mischief befall him, ye shall bring down my gray hairs with sorrow to the grave.'); +INSERT INTO t1(docid,words) VALUES(1044030,'Now therefore when I come to thy servant my father, and the lad be not with us; seeing that his life is bound up in the lad''s life;'); +INSERT INTO t1(docid,words) VALUES(1044031,'It shall come to pass, when he seeth that the lad is not with us, that he will die: and thy servants shall bring down the gray hairs of thy servant our father with sorrow to the grave.'); +INSERT INTO t1(docid,words) VALUES(1044032,'For thy servant became surety for the lad unto my father, saying, If I bring him not unto thee, then I shall bear the blame to my father for ever.'); +INSERT INTO t1(docid,words) VALUES(1044033,'Now therefore, I pray thee, let thy servant abide instead of the lad a bondman to my lord; and let the lad go up with his brethren.'); +INSERT INTO t1(docid,words) VALUES(1044034,'For how shall I go up to my father, and the lad be not with me? lest peradventure I see the evil that shall come on my father.'); +INSERT INTO t1(docid,words) VALUES(1045001,'Then Joseph could not refrain himself before all them that stood by him; and he cried, Cause every man to go out from me. And there stood no man with him, while Joseph made himself known unto his brethren.'); +INSERT INTO t1(docid,words) VALUES(1045002,'And he wept aloud: and the Egyptians and the house of Pharaoh heard.'); +INSERT INTO t1(docid,words) VALUES(1045003,'And Joseph said unto his brethren, I am Joseph; doth my father yet live? And his brethren could not answer him; for they were troubled at his presence.'); +INSERT INTO t1(docid,words) VALUES(1045004,'And Joseph said unto his brethren, Come near to me, I pray you. And they came near. And he said, I am Joseph your brother, whom ye sold into Egypt.'); +INSERT INTO t1(docid,words) VALUES(1045005,'Now therefore be not grieved, nor angry with yourselves, that ye sold me hither: for God did send me before you to preserve life.'); +INSERT INTO t1(docid,words) VALUES(1045006,'For these two years hath the famine been in the land: and yet there are five years, in the which there shall neither be earing nor harvest.'); +INSERT INTO t1(docid,words) VALUES(1045007,'And God sent me before you to preserve you a posterity in the earth, and to save your lives by a great deliverance.'); +INSERT INTO t1(docid,words) VALUES(1045008,'So now it was not you that sent me hither, but God: and he hath made me a father to Pharaoh, and lord of all his house, and a ruler throughout all the land of Egypt.'); +INSERT INTO t1(docid,words) VALUES(1045009,'Haste ye, and go up to my father, and say unto him, Thus saith thy son Joseph, God hath made me lord of all Egypt: come down unto me, tarry not:'); +INSERT INTO t1(docid,words) VALUES(1045010,'And thou shalt dwell in the land of Goshen, and thou shalt be near unto me, thou, and thy children, and thy children''s children, and thy flocks, and thy herds, and all that thou hast:'); +INSERT INTO t1(docid,words) VALUES(1045011,'And there will I nourish thee; for yet there are five years of famine; lest thou, and thy household, and all that thou hast, come to poverty.'); +INSERT INTO t1(docid,words) VALUES(1045012,'And, behold, your eyes see, and the eyes of my brother Benjamin, that it is my mouth that speaketh unto you.'); +INSERT INTO t1(docid,words) VALUES(1045013,'And ye shall tell my father of all my glory in Egypt, and of all that ye have seen; and ye shall haste and bring down my father hither.'); +INSERT INTO t1(docid,words) VALUES(1045014,'And he fell upon his brother Benjamin''s neck, and wept; and Benjamin wept upon his neck.'); +INSERT INTO t1(docid,words) VALUES(1045015,'Moreover he kissed all his brethren, and wept upon them: and after that his brethren talked with him.'); +INSERT INTO t1(docid,words) VALUES(1045016,'And the fame thereof was heard in Pharaoh''s house, saying, Joseph''s brethren are come: and it pleased Pharaoh well, and his servants.'); +INSERT INTO t1(docid,words) VALUES(1045017,'And Pharaoh said unto Joseph, Say unto thy brethren, This do ye; lade your beasts, and go, get you unto the land of Canaan;'); +INSERT INTO t1(docid,words) VALUES(1045018,'And take your father and your households, and come unto me: and I will give you the good of the land of Egypt, and ye shall eat the fat of the land.'); +INSERT INTO t1(docid,words) VALUES(1045019,'Now thou art commanded, this do ye; take you wagons out of the land of Egypt for your little ones, and for your wives, and bring your father, and come.'); +INSERT INTO t1(docid,words) VALUES(1045020,'Also regard not your stuff; for the good of all the land of Egypt is your''s.'); +INSERT INTO t1(docid,words) VALUES(1045021,'And the children of Israel did so: and Joseph gave them wagons, according to the commandment of Pharaoh, and gave them provision for the way.'); +INSERT INTO t1(docid,words) VALUES(1045022,'To all of them he gave each man changes of raiment; but to Benjamin he gave three hundred pieces of silver, and five changes of raiment.'); +INSERT INTO t1(docid,words) VALUES(1045023,'And to his father he sent after this manner; ten asses laden with the good things of Egypt, and ten she asses laden with corn and bread and meat for his father by the way.'); +INSERT INTO t1(docid,words) VALUES(1045024,'So he sent his brethren away, and they departed: and he said unto them, See that ye fall not out by the way.'); +INSERT INTO t1(docid,words) VALUES(1045025,'And they went up out of Egypt, and came into the land of Canaan unto Jacob their father,'); +INSERT INTO t1(docid,words) VALUES(1045026,'And told him, saying, Joseph is yet alive, and he is governor over all the land of Egypt. And Jacob''s heart fainted, for he believed them not.'); +INSERT INTO t1(docid,words) VALUES(1045027,'And they told him all the words of Joseph, which he had said unto them: and when he saw the wagons which Joseph had sent to carry him, the spirit of Jacob their father revived:'); +INSERT INTO t1(docid,words) VALUES(1045028,'And Israel said, It is enough; Joseph my son is yet alive: I will go and see him before I die.'); +INSERT INTO t1(docid,words) VALUES(1046001,'And Israel took his journey with all that he had, and came to Beersheba, and offered sacrifices unto the God of his father Isaac.'); +INSERT INTO t1(docid,words) VALUES(1046002,'And God spake unto Israel in the visions of the night, and said, Jacob, Jacob. And he said, Here am I.'); +INSERT INTO t1(docid,words) VALUES(1046003,'And he said, I am God, the God of thy father: fear not to go down into Egypt; for I will there make of thee a great nation:'); +INSERT INTO t1(docid,words) VALUES(1046004,'I will go down with thee into Egypt; and I will also surely bring thee up again: and Joseph shall put his hand upon thine eyes.'); +INSERT INTO t1(docid,words) VALUES(1046005,'And Jacob rose up from Beersheba: and the sons of Israel carried Jacob their father, and their little ones, and their wives, in the wagons which Pharaoh had sent to carry him.'); +INSERT INTO t1(docid,words) VALUES(1046006,'And they took their cattle, and their goods, which they had gotten in the land of Canaan, and came into Egypt, Jacob, and all his seed with him:'); +INSERT INTO t1(docid,words) VALUES(1046007,'His sons, and his sons'' sons with him, his daughters, and his sons'' daughters, and all his seed brought he with him into Egypt.'); +INSERT INTO t1(docid,words) VALUES(1046008,'And these are the names of the children of Israel, which came into Egypt, Jacob and his sons: Reuben, Jacob''s firstborn.'); +INSERT INTO t1(docid,words) VALUES(1046009,'And the sons of Reuben; Hanoch, and Phallu, and Hezron, and Carmi.'); +INSERT INTO t1(docid,words) VALUES(1046010,'And the sons of Simeon; Jemuel, and Jamin, and Ohad, and Jachin, and Zohar, and Shaul the son of a Canaanitish woman.'); +INSERT INTO t1(docid,words) VALUES(1046011,'And the sons of Levi; Gershon, Kohath, and Merari.'); +INSERT INTO t1(docid,words) VALUES(1046012,'And the sons of Judah; Er, and Onan, and Shelah, and Pharez, and Zarah: but Er and Onan died in the land of Canaan. And the sons of Pharez were Hezron and Hamul.'); +INSERT INTO t1(docid,words) VALUES(1046013,'And the sons of Issachar; Tola, and Phuvah, and Job, and Shimron.'); +INSERT INTO t1(docid,words) VALUES(1046014,'And the sons of Zebulun; Sered, and Elon, and Jahleel.'); +INSERT INTO t1(docid,words) VALUES(1046015,'These be the sons of Leah, which she bare unto Jacob in Padanaram, with his daughter Dinah: all the souls of his sons and his daughters were thirty and three.'); +INSERT INTO t1(docid,words) VALUES(1046016,'And the sons of Gad; Ziphion, and Haggi, Shuni, and Ezbon, Eri, and Arodi, and Areli.'); +INSERT INTO t1(docid,words) VALUES(1046017,'And the sons of Asher; Jimnah, and Ishuah, and Isui, and Beriah, and Serah their sister: and the sons of Beriah; Heber, and Malchiel.'); +INSERT INTO t1(docid,words) VALUES(1046018,'These are the sons of Zilpah, whom Laban gave to Leah his daughter, and these she bare unto Jacob, even sixteen souls.'); +INSERT INTO t1(docid,words) VALUES(1046019,'The sons of Rachel Jacob''s wife; Joseph, and Benjamin.'); +INSERT INTO t1(docid,words) VALUES(1046020,'And unto Joseph in the land of Egypt were born Manasseh and Ephraim, which Asenath the daughter of Potipherah priest of On bare unto him.'); +INSERT INTO t1(docid,words) VALUES(1046021,'And the sons of Benjamin were Belah, and Becher, and Ashbel, Gera, and Naaman, Ehi, and Rosh, Muppim, and Huppim, and Ard.'); +INSERT INTO t1(docid,words) VALUES(1046022,'These are the sons of Rachel, which were born to Jacob: all the souls were fourteen.'); +INSERT INTO t1(docid,words) VALUES(1046023,'And the sons of Dan; Hushim.'); +INSERT INTO t1(docid,words) VALUES(1046024,'And the sons of Naphtali; Jahzeel, and Guni, and Jezer, and Shillem.'); +INSERT INTO t1(docid,words) VALUES(1046025,'These are the sons of Bilhah, which Laban gave unto Rachel his daughter, and she bare these unto Jacob: all the souls were seven.'); +INSERT INTO t1(docid,words) VALUES(1046026,'All the souls that came with Jacob into Egypt, which came out of his loins, besides Jacob''s sons'' wives, all the souls were threescore and six;'); +INSERT INTO t1(docid,words) VALUES(1046027,'And the sons of Joseph, which were born him in Egypt, were two souls: all the souls of the house of Jacob, which came into Egypt, were threescore and ten.'); +INSERT INTO t1(docid,words) VALUES(1046028,'And he sent Judah before him unto Joseph, to direct his face unto Goshen; and they came into the land of Goshen.'); +INSERT INTO t1(docid,words) VALUES(1046029,'And Joseph made ready his chariot, and went up to meet Israel his father, to Goshen, and presented himself unto him; and he fell on his neck, and wept on his neck a good while.'); +INSERT INTO t1(docid,words) VALUES(1046030,'And Israel said unto Joseph, Now let me die, since I have seen thy face, because thou art yet alive.'); +INSERT INTO t1(docid,words) VALUES(1046031,'And Joseph said unto his brethren, and unto his father''s house, I will go up, and shew Pharaoh, and say unto him, My brethren, and my father''s house, which were in the land of Canaan, are come unto me;'); +INSERT INTO t1(docid,words) VALUES(1046032,'And the men are shepherds, for their trade hath been to feed cattle; and they have brought their flocks, and their herds, and all that they have.'); +INSERT INTO t1(docid,words) VALUES(1046033,'And it shall come to pass, when Pharaoh shall call you, and shall say, What is your occupation?'); +INSERT INTO t1(docid,words) VALUES(1046034,'That ye shall say, Thy servants'' trade hath been about cattle from our youth even until now, both we, and also our fathers: that ye may dwell in the land of Goshen; for every shepherd is an abomination unto the Egyptians.'); +INSERT INTO t1(docid,words) VALUES(1047001,'Then Joseph came and told Pharaoh, and said, My father and my brethren, and their flocks, and their herds, and all that they have, are come out of the land of Canaan; and, behold, they are in the land of Goshen.'); +INSERT INTO t1(docid,words) VALUES(1047002,'And he took some of his brethren, even five men, and presented them unto Pharaoh.'); +INSERT INTO t1(docid,words) VALUES(1047003,'And Pharaoh said unto his brethren, What is your occupation? And they said unto Pharaoh, Thy servants are shepherds, both we, and also our fathers.'); +INSERT INTO t1(docid,words) VALUES(1047004,'They said morever unto Pharaoh, For to sojourn in the land are we come; for thy servants have no pasture for their flocks; for the famine is sore in the land of Canaan: now therefore, we pray thee, let thy servants dwell in the land of Goshen.'); +INSERT INTO t1(docid,words) VALUES(1047005,'And Pharaoh spake unto Joseph, saying, Thy father and thy brethren are come unto thee:'); +INSERT INTO t1(docid,words) VALUES(1047006,'The land of Egypt is before thee; in the best of the land make thy father and brethren to dwell; in the land of Goshen let them dwell: and if thou knowest any men of activity among them, then make them rulers over my cattle.'); +INSERT INTO t1(docid,words) VALUES(1047007,'And Joseph brought in Jacob his father, and set him before Pharaoh: and Jacob blessed Pharaoh.'); +INSERT INTO t1(docid,words) VALUES(1047008,'And Pharaoh said unto Jacob, How old art thou?'); +INSERT INTO t1(docid,words) VALUES(1047009,'And Jacob said unto Pharaoh, The days of the years of my pilgrimage are an hundred and thirty years: few and evil have the days of the years of my life been, and have not attained unto the days of the years of the life of my fathers in the days of their pilgrimage.'); +INSERT INTO t1(docid,words) VALUES(1047010,'And Jacob blessed Pharaoh, and went out from before Pharaoh.'); +INSERT INTO t1(docid,words) VALUES(1047011,'And Joseph placed his father and his brethren, and gave them a possession in the land of Egypt, in the best of the land, in the land of Rameses, as Pharaoh had commanded.'); +INSERT INTO t1(docid,words) VALUES(1047012,'And Joseph nourished his father, and his brethren, and all his father''s household, with bread, according to their families.'); +INSERT INTO t1(docid,words) VALUES(1047013,'And there was no bread in all the land; for the famine was very sore, so that the land of Egypt and all the land of Canaan fainted by reason of the famine.'); +INSERT INTO t1(docid,words) VALUES(1047014,'And Joseph gathered up all the money that was found in the land of Egypt, and in the land of Canaan, for the corn which they bought: and Joseph brought the money into Pharaoh''s house.'); +INSERT INTO t1(docid,words) VALUES(1047015,'And when money failed in the land of Egypt, and in the land of Canaan, all the Egyptians came unto Joseph, and said, Give us bread: for why should we die in thy presence? for the money faileth.'); +INSERT INTO t1(docid,words) VALUES(1047016,'And Joseph said, Give your cattle; and I will give you for your cattle, if money fail.'); +INSERT INTO t1(docid,words) VALUES(1047017,'And they brought their cattle unto Joseph: and Joseph gave them bread in exchange for horses, and for the flocks, and for the cattle of the herds, and for the asses: and he fed them with bread for all their cattle for that year.'); +INSERT INTO t1(docid,words) VALUES(1047018,'When that year was ended, they came unto him the second year, and said unto him, We will not hide it from my lord, how that our money is spent; my lord also hath our herds of cattle; there is not ought left in the sight of my lord, but our bodies, and our lands:'); +INSERT INTO t1(docid,words) VALUES(1047019,'Wherefore shall we die before thine eyes, both we and our land? buy us and our land for bread, and we and our land will be servants unto Pharaoh: and give us seed, that we may live, and not die, that the land be not desolate.'); +INSERT INTO t1(docid,words) VALUES(1047020,'And Joseph bought all the land of Egypt for Pharaoh; for the Egyptians sold every man his field, because the famine prevailed over them: so the land became Pharaoh''s.'); +INSERT INTO t1(docid,words) VALUES(1047021,'And as for the people, he removed them to cities from one end of the borders of Egypt even to the other end thereof.'); +INSERT INTO t1(docid,words) VALUES(1047022,'Only the land of the priests bought he not; for the priests had a portion assigned them of Pharaoh, and did eat their portion which Pharaoh gave them: wherefore they sold not their lands.'); +INSERT INTO t1(docid,words) VALUES(1047023,'Then Joseph said unto the people, Behold, I have bought you this day and your land for Pharaoh: lo, here is seed for you, and ye shall sow the land.'); +INSERT INTO t1(docid,words) VALUES(1047024,'And it shall come to pass in the increase, that ye shall give the fifth part unto Pharaoh, and four parts shall be your own, for seed of the field, and for your food, and for them of your households, and for food for your little ones.'); +INSERT INTO t1(docid,words) VALUES(1047025,'And they said, Thou hast saved our lives: let us find grace in the sight of my lord, and we will be Pharaoh''s servants.'); +INSERT INTO t1(docid,words) VALUES(1047026,'And Joseph made it a law over the land of Egypt unto this day, that Pharaoh should have the fifth part, except the land of the priests only, which became not Pharaoh''s.'); +INSERT INTO t1(docid,words) VALUES(1047027,'And Israel dwelt in the land of Egypt, in the country of Goshen; and they had possessions therein, and grew, and multiplied exceedingly.'); +INSERT INTO t1(docid,words) VALUES(1047028,'And Jacob lived in the land of Egypt seventeen years: so the whole age of Jacob was an hundred forty and seven years.'); +INSERT INTO t1(docid,words) VALUES(1047029,'And the time drew nigh that Israel must die: and he called his son Joseph, and said unto him, If now I have found grace in thy sight, put, I pray thee, thy hand under my thigh, and deal kindly and truly with me; bury me not, I pray thee, in Egypt:'); +INSERT INTO t1(docid,words) VALUES(1047030,'But I will lie with my fathers, and thou shalt carry me out of Egypt, and bury me in their buryingplace. And he said, I will do as thou hast said.'); +INSERT INTO t1(docid,words) VALUES(1047031,'And he said, Swear unto me. And he sware unto him. And Israel bowed himself upon the bed''s head.'); +INSERT INTO t1(docid,words) VALUES(1048001,'And it came to pass after these things, that one told Joseph, Behold, thy father is sick: and he took with him his two sons, Manasseh and Ephraim.'); +INSERT INTO t1(docid,words) VALUES(1048002,'And one told Jacob, and said, Behold, thy son Joseph cometh unto thee: and Israel strengthened himself, and sat upon the bed.'); +INSERT INTO t1(docid,words) VALUES(1048003,'And Jacob said unto Joseph, God Almighty appeared unto me at Luz in the land of Canaan, and blessed me,'); +INSERT INTO t1(docid,words) VALUES(1048004,'And said unto me, Behold, I will make thee fruitful, and multiply thee, and I will make of thee a multitude of people; and will give this land to thy seed after thee for an everlasting possession.'); +INSERT INTO t1(docid,words) VALUES(1048005,'And now thy two sons, Ephraim and Manasseh, which were born unto thee in the land of Egypt before I came unto thee into Egypt, are mine; as Reuben and Simeon, they shall be mine.'); +INSERT INTO t1(docid,words) VALUES(1048006,'And thy issue, which thou begettest after them, shall be thine, and shall be called after the name of their brethren in their inheritance.'); +INSERT INTO t1(docid,words) VALUES(1048007,'And as for me, when I came from Padan, Rachel died by me in the land of Canaan in the way, when yet there was but a little way to come unto Ephrath: and I buried her there in the way of Ephrath; the same is Bethlehem.'); +INSERT INTO t1(docid,words) VALUES(1048008,'And Israel beheld Joseph''s sons, and said, Who are these?'); +INSERT INTO t1(docid,words) VALUES(1048009,'And Joseph said unto his father, They are my sons, whom God hath given me in this place. And he said, Bring them, I pray thee, unto me, and I will bless them.'); +INSERT INTO t1(docid,words) VALUES(1048010,'Now the eyes of Israel were dim for age, so that he could not see. And he brought them near unto him; and he kissed them, and embraced them.'); +INSERT INTO t1(docid,words) VALUES(1048011,'And Israel said unto Joseph, I had not thought to see thy face: and, lo, God hath shewed me also thy seed.'); +INSERT INTO t1(docid,words) VALUES(1048012,'And Joseph brought them out from between his knees, and he bowed himself with his face to the earth.'); +INSERT INTO t1(docid,words) VALUES(1048013,'And Joseph took them both, Ephraim in his right hand toward Israel''s left hand, and Manasseh in his left hand toward Israel''s right hand, and brought them near unto him.'); +INSERT INTO t1(docid,words) VALUES(1048014,'And Israel stretched out his right hand, and laid it upon Ephraim''s head, who was the younger, and his left hand upon Manasseh''s head, guiding his hands wittingly; for Manasseh was the firstborn.'); +INSERT INTO t1(docid,words) VALUES(1048015,'And he blessed Joseph, and said, God, before whom my fathers Abraham and Isaac did walk, the God which fed me all my life long unto this day,'); +INSERT INTO t1(docid,words) VALUES(1048016,'The Angel which redeemed me from all evil, bless the lads; and let my name be named on them, and the name of my fathers Abraham and Isaac; and let them grow into a multitude in the midst of the earth.'); +INSERT INTO t1(docid,words) VALUES(1048017,'And when Joseph saw that his father laid his right hand upon the head of Ephraim, it displeased him: and he held up his father''s hand, to remove it from Ephraim''s head unto Manasseh''s head.'); +INSERT INTO t1(docid,words) VALUES(1048018,'And Joseph said unto his father, Not so, my father: for this is the firstborn; put thy right hand upon his head.'); +INSERT INTO t1(docid,words) VALUES(1048019,'And his father refused, and said, I know it, my son, I know it: he also shall become a people, and he also shall be great: but truly his younger brother shall be greater than he, and his seed shall become a multitude of nations.'); +INSERT INTO t1(docid,words) VALUES(1048020,'And he blessed them that day, saying, In thee shall Israel bless, saying, God make thee as Ephraim and as Manasseh: and he set Ephraim before Manasseh.'); +INSERT INTO t1(docid,words) VALUES(1048021,'And Israel said unto Joseph, Behold, I die: but God shall be with you, and bring you again unto the land of your fathers.'); +INSERT INTO t1(docid,words) VALUES(1048022,'Moreover I have given to thee one portion above thy brethren, which I took out of the hand of the Amorite with my sword and with my bow.'); +INSERT INTO t1(docid,words) VALUES(1049001,'And Jacob called unto his sons, and said, Gather yourselves together, that I may tell you that which shall befall you in the last days.'); +INSERT INTO t1(docid,words) VALUES(1049002,'Gather yourselves together, and hear, ye sons of Jacob; and hearken unto Israel your father.'); +INSERT INTO t1(docid,words) VALUES(1049003,'Reuben, thou art my firstborn, my might, and the beginning of my strength, the excellency of dignity, and the excellency of power:'); +INSERT INTO t1(docid,words) VALUES(1049004,'Unstable as water, thou shalt not excel; because thou wentest up to thy father''s bed; then defiledst thou it: he went up to my couch.'); +INSERT INTO t1(docid,words) VALUES(1049005,'Simeon and Levi are brethren; instruments of cruelty are in their habitations.'); +INSERT INTO t1(docid,words) VALUES(1049006,'O my soul, come not thou into their secret; unto their assembly, mine honour, be not thou united: for in their anger they slew a man, and in their selfwill they digged down a wall.'); +INSERT INTO t1(docid,words) VALUES(1049007,'Cursed be their anger, for it was fierce; and their wrath, for it was cruel: I will divide them in Jacob, and scatter them in Israel.'); +INSERT INTO t1(docid,words) VALUES(1049008,'Judah, thou art he whom thy brethren shall praise: thy hand shall be in the neck of thine enemies; thy father''s children shall bow down before thee.'); +INSERT INTO t1(docid,words) VALUES(1049009,'Judah is a lion''s whelp: from the prey, my son, thou art gone up: he stooped down, he couched as a lion, and as an old lion; who shall rouse him up?'); +INSERT INTO t1(docid,words) VALUES(1049010,'The sceptre shall not depart from Judah, nor a lawgiver from between his feet, until Shiloh come; and unto him shall the gathering of the people be.'); +INSERT INTO t1(docid,words) VALUES(1049011,'Binding his foal unto the vine, and his ass''s colt unto the choice vine; he washed his garments in wine, and his clothes in the blood of grapes:'); +INSERT INTO t1(docid,words) VALUES(1049012,'His eyes shall be red with wine, and his teeth white with milk.'); +INSERT INTO t1(docid,words) VALUES(1049013,'Zebulun shall dwell at the haven of the sea; and he shall be for an haven of ships; and his border shall be unto Zidon.'); +INSERT INTO t1(docid,words) VALUES(1049014,'Issachar is a strong ass couching down between two burdens:'); +INSERT INTO t1(docid,words) VALUES(1049015,'And he saw that rest was good, and the land that it was pleasant; and bowed his shoulder to bear, and became a servant unto tribute.'); +INSERT INTO t1(docid,words) VALUES(1049016,'Dan shall judge his people, as one of the tribes of Israel.'); +INSERT INTO t1(docid,words) VALUES(1049017,'Dan shall be a serpent by the way, an adder in the path, that biteth the horse heels, so that his rider shall fall backward.'); +INSERT INTO t1(docid,words) VALUES(1049018,'I have waited for thy salvation, O LORD.'); +INSERT INTO t1(docid,words) VALUES(1049019,'Gad, a troop shall overcome him: but he shall overcome at the last.'); +INSERT INTO t1(docid,words) VALUES(1049020,'Out of Asher his bread shall be fat, and he shall yield royal dainties.'); +INSERT INTO t1(docid,words) VALUES(1049021,'Naphtali is a hind let loose: he giveth goodly words.'); +INSERT INTO t1(docid,words) VALUES(1049022,'Joseph is a fruitful bough, even a fruitful bough by a well; whose branches run over the wall:'); +INSERT INTO t1(docid,words) VALUES(1049023,'The archers have sorely grieved him, and shot at him, and hated him:'); +INSERT INTO t1(docid,words) VALUES(1049024,'But his bow abode in strength, and the arms of his hands were made strong by the hands of the mighty God of Jacob; (from thence is the shepherd, the stone of Israel:)'); +INSERT INTO t1(docid,words) VALUES(1049025,'Even by the God of thy father, who shall help thee; and by the Almighty, who shall bless thee with blessings of heaven above, blessings of the deep that lieth under, blessings of the breasts, and of the womb:'); +INSERT INTO t1(docid,words) VALUES(1049026,'The blessings of thy father have prevailed above the blessings of my progenitors unto the utmost bound of the everlasting hills: they shall be on the head of Joseph, and on the crown of the head of him that was separate from his brethren.'); +INSERT INTO t1(docid,words) VALUES(1049027,'Benjamin shall ravin as a wolf: in the morning he shall devour the prey, and at night he shall divide the spoil.'); +INSERT INTO t1(docid,words) VALUES(1049028,'All these are the twelve tribes of Israel: and this is it that their father spake unto them, and blessed them; every one according to his blessing he blessed them.'); +INSERT INTO t1(docid,words) VALUES(1049029,'And he charged them, and said unto them, I am to be gathered unto my people: bury me with my fathers in the cave that is in the field of Ephron the Hittite,'); +INSERT INTO t1(docid,words) VALUES(1049030,'In the cave that is in the field of Machpelah, which is before Mamre, in the land of Canaan, which Abraham bought with the field of Ephron the Hittite for a possession of a buryingplace.'); +INSERT INTO t1(docid,words) VALUES(1049031,'There they buried Abraham and Sarah his wife; there they buried Isaac and Rebekah his wife; and there I buried Leah.'); +INSERT INTO t1(docid,words) VALUES(1049032,'The purchase of the field and of the cave that is therein was from the children of Heth.'); +INSERT INTO t1(docid,words) VALUES(1049033,'And when Jacob had made an end of commanding his sons, he gathered up his feet into the bed, and yielded up the ghost, and was gathered unto his people.'); +INSERT INTO t1(docid,words) VALUES(1050001,'And Joseph fell upon his father''s face, and wept upon him, and kissed him.'); +INSERT INTO t1(docid,words) VALUES(1050002,'And Joseph commanded his servants the physicians to embalm his father: and the physicians embalmed Israel.'); +INSERT INTO t1(docid,words) VALUES(1050003,'And forty days were fulfilled for him; for so are fulfilled the days of those which are embalmed: and the Egyptians mourned for him threescore and ten days.'); +INSERT INTO t1(docid,words) VALUES(1050004,'And when the days of his mourning were past, Joseph spake unto the house of Pharaoh, saying, If now I have found grace in your eyes, speak, I pray you, in the ears of Pharaoh, saying,'); +INSERT INTO t1(docid,words) VALUES(1050005,'My father made me swear, saying, Lo, I die: in my grave which I have digged for me in the land of Canaan, there shalt thou bury me. Now therefore let me go up, I pray thee, and bury my father, and I will come again.'); +INSERT INTO t1(docid,words) VALUES(1050006,'And Pharaoh said, Go up, and bury thy father, according as he made thee swear.'); +INSERT INTO t1(docid,words) VALUES(1050007,'And Joseph went up to bury his father: and with him went up all the servants of Pharaoh, the elders of his house, and all the elders of the land of Egypt,'); +INSERT INTO t1(docid,words) VALUES(1050008,'And all the house of Joseph, and his brethren, and his father''s house: only their little ones, and their flocks, and their herds, they left in the land of Goshen.'); +INSERT INTO t1(docid,words) VALUES(1050009,'And there went up with him both chariots and horsemen: and it was a very great company.'); +INSERT INTO t1(docid,words) VALUES(1050010,'And they came to the threshingfloor of Atad, which is beyond Jordan, and there they mourned with a great and very sore lamentation: and he made a mourning for his father seven days.'); +INSERT INTO t1(docid,words) VALUES(1050011,'And when the inhabitants of the land, the Canaanites, saw the mourning in the floor of Atad, they said, This is a grievous mourning to the Egyptians: wherefore the name of it was called Abelmizraim, which is beyond Jordan.'); +INSERT INTO t1(docid,words) VALUES(1050012,'And his sons did unto him according as he commanded them:'); +INSERT INTO t1(docid,words) VALUES(1050013,'For his sons carried him into the land of Canaan, and buried him in the cave of the field of Machpelah, which Abraham bought with the field for a possession of a buryingplace of Ephron the Hittite, before Mamre.'); +INSERT INTO t1(docid,words) VALUES(1050014,'And Joseph returned into Egypt, he, and his brethren, and all that went up with him to bury his father, after he had buried his father.'); +INSERT INTO t1(docid,words) VALUES(1050015,'And when Joseph''s brethren saw that their father was dead, they said, Joseph will peradventure hate us, and will certainly requite us all the evil which we did unto him.'); +INSERT INTO t1(docid,words) VALUES(1050016,'And they sent a messenger unto Joseph, saying, Thy father did command before he died, saying,'); +INSERT INTO t1(docid,words) VALUES(1050017,'So shall ye say unto Joseph, Forgive, I pray thee now, the trespass of thy brethren, and their sin; for they did unto thee evil: and now, we pray thee, forgive the trespass of the servants of the God of thy father. And Joseph wept when they spake unto him.'); +INSERT INTO t1(docid,words) VALUES(1050018,'And his brethren also went and fell down before his face; and they said, Behold, we be thy servants.'); +INSERT INTO t1(docid,words) VALUES(1050019,'And Joseph said unto them, Fear not: for am I in the place of God?'); +INSERT INTO t1(docid,words) VALUES(1050020,'But as for you, ye thought evil against me; but God meant it unto good, to bring to pass, as it is this day, to save much people alive.'); +INSERT INTO t1(docid,words) VALUES(1050021,'Now therefore fear ye not: I will nourish you, and your little ones. And he comforted them, and spake kindly unto them.'); +INSERT INTO t1(docid,words) VALUES(1050022,'And Joseph dwelt in Egypt, he, and his father''s house: and Joseph lived an hundred and ten years.'); +INSERT INTO t1(docid,words) VALUES(1050023,'And Joseph saw Ephraim''s children of the third generation: the children also of Machir the son of Manasseh were brought up upon Joseph''s knees.'); +INSERT INTO t1(docid,words) VALUES(1050024,'And Joseph said unto his brethren, I die: and God will surely visit you, and bring you out of this land unto the land which he sware to Abraham, to Isaac, and to Jacob.'); +INSERT INTO t1(docid,words) VALUES(1050025,'And Joseph took an oath of the children of Israel, saying, God will surely visit you, and ye shall carry up my bones from hence.'); +INSERT INTO t1(docid,words) VALUES(1050026,'So Joseph died, being an hundred and ten years old: and they embalmed him, and he was put in a coffin in Egypt.'); +COMMIT; +} +} diff --git a/test/having.test b/test/having.test new file mode 100644 index 0000000..3bfa812 --- /dev/null +++ b/test/having.test @@ -0,0 +1,191 @@ +# 2017 April 30 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Test the HAVING->WHERE optimization. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix having + +do_execsql_test 1.0 { + CREATE TABLE t2(c, d); + + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 1); + INSERT INTO t1 VALUES(2, 2); + INSERT INTO t1 VALUES(1, 3); + INSERT INTO t1 VALUES(2, 4); + INSERT INTO t1 VALUES(1, 5); + INSERT INTO t1 VALUES(2, 6); +} {} + +foreach {tn sql res} { + 1 "SELECT a, sum(b) FROM t1 GROUP BY a HAVING a=2" {2 12} + 2 "SELECT a, sum(b) FROM t1 GROUP BY a HAVING a=2 AND sum(b)>10" {2 12} + 3 "SELECT a, sum(b) FROM t1 GROUP BY a HAVING sum(b)>12" {} +} { + do_execsql_test 1.$tn $sql $res +} + +# Run an EXPLAIN command for both SQL statements. Return true if +# the outputs are identical, or false otherwise. +# +proc compare_vdbe {sql1 sql2} { + set r1 [list] + set r2 [list] + db eval "explain $sql1" { lappend r1 $opcode $p1 $p2 $p3 $p4 $p5} + db eval "explain $sql2" { lappend r2 $opcode $p1 $p2 $p3 $p4 $p5} + return [expr {$r1==$r2}] +} + +proc do_compare_vdbe_test {tn sql1 sql2 res} { + uplevel [list do_test $tn [list compare_vdbe $sql1 $sql2] $res] +} + +#------------------------------------------------------------------------- +# Test that various statements that are eligible for the optimization +# produce the same VDBE code as optimizing by hand does. +# +foreach {tn sql1 sql2} { + 1 "SELECT a, sum(b) FROM t1 GROUP BY a HAVING a=2" + "SELECT a, sum(b) FROM t1 WHERE a=2 GROUP BY a" + + 2 "SELECT a, sum(b) FROM t1 GROUP BY a HAVING sum(b)>5 AND a=2" + "SELECT a, sum(b) FROM t1 WHERE a=2 GROUP BY a HAVING sum(b)>5" + + 3 "SELECT a, sum(b) FROM t1 GROUP BY a COLLATE binary HAVING a=2" + "SELECT a, sum(b) FROM t1 WHERE a=2 GROUP BY a COLLATE binary" + + 5 "SELECT a, sum(b) FROM t1 GROUP BY a COLLATE binary HAVING 1" + "SELECT a, sum(b) FROM t1 WHERE 1 GROUP BY a COLLATE binary" + + 6 "SELECT count(*) FROM t1,t2 WHERE a=c GROUP BY b, d HAVING b=d" + "SELECT count(*) FROM t1,t2 WHERE a=c AND b=d GROUP BY b, d" + + 7 { + SELECT count(*) FROM t1,t2 WHERE a=c GROUP BY b, d + HAVING b=d COLLATE nocase + } { + SELECT count(*) FROM t1,t2 WHERE a=c AND b=d COLLATE nocase + GROUP BY b, d + } + + 8 "SELECT a, sum(b) FROM t1 GROUP BY a||b HAVING substr(a||b, 1, 1)='a'" + "SELECT a, sum(b) FROM t1 WHERE substr(a||b, 1, 1)='a' GROUP BY a||b" +} { + do_compare_vdbe_test 2.$tn $sql1 $sql2 1 +} + +# The (4) test in the above set used to generate identical bytecode, but +# that is no longer the case. The byte code is equivalent, though. +# +do_execsql_test 2.4a { + SELECT x,y FROM ( + SELECT a AS x, sum(b) AS y FROM t1 + GROUP BY a + ) WHERE x BETWEEN 2 AND 9999 +} {2 12} +do_execsql_test 2.4b { + SELECT x,y FROM ( + SELECT a AS x, sum(b) AS y FROM t1 + WHERE x BETWEEN 2 AND 9999 + GROUP BY a + ) +} {2 12} + + +#------------------------------------------------------------------------- +# 1: Test that the optimization is only applied if the GROUP BY term +# uses BINARY collation. +# +# 2: Not applied if there is a non-deterministic function in the HAVING +# term. +# +foreach {tn sql1 sql2} { + 1 "SELECT a, sum(b) FROM t1 GROUP BY a COLLATE nocase HAVING a=2" + "SELECT a, sum(b) FROM t1 WHERE a=2 GROUP BY a COLLATE nocase" + + 2 "SELECT a, sum(b) FROM t1 GROUP BY a HAVING randomblob(a)